#pragma once
#include "FontFormatUtility.h"
#include "FormFormat.h"
#include "FormApropos.h"

namespace CLIMulticube {


	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::Windows::Forms;

	using namespace CLITableur;

	/// <summary>
	/// Description résumée de Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: ajoutez ici le code du constructeur
			//
		}

	protected:
		/// <summary>
		/// Nettoyage des ressources utilisées.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::MenuStrip^  menuStrip1;
	protected: 
	private: System::Windows::Forms::ToolStripMenuItem^  fichierToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  nouveauToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  enregistrerToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  enregistrerSousToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  exporterExcelToolStripMenuItem;
	private: System::Windows::Forms::ToolStripSeparator^  toolStripMenuItem1;
	private: System::Windows::Forms::ToolStripMenuItem^  quitterToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  toolStripMenuItem2;
	private: System::Windows::Forms::ToolStripMenuItem^  aProposDeMulticubeToolStripMenuItem;
	private: System::Windows::Forms::ToolStrip^  toolStrip1;
	private: System::Windows::Forms::ToolStripLabel^  toolStripLabel1;
	private: System::Windows::Forms::ToolStripTextBox^  txt_cell_value;

	private: System::Windows::Forms::StatusStrip^  statusStrip1;
	private: System::Windows::Forms::DataGridView^  dg;
	private: System::Windows::Forms::ToolStrip^  toolStrip2;
	private: System::Windows::Forms::ToolStripButton^  nouveauToolStripButton;
	private: System::Windows::Forms::ToolStripButton^  ouvrirToolStripButton;
	private: System::Windows::Forms::ToolStripButton^  enregistrerToolStripButton;
	private: System::Windows::Forms::ToolStripButton^  imprimerToolStripButton;
	private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator;
	private: System::Windows::Forms::ToolStripButton^  couperToolStripButton;
	private: System::Windows::Forms::ToolStripButton^  copierToolStripButton;
	private: System::Windows::Forms::ToolStripButton^  collerToolStripButton;
	private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator1;
	private: System::Windows::Forms::ToolStripComboBox^  cb_font_name;
	private: System::Windows::Forms::ToolStripComboBox^  cb_font_size;



	private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator2;
	private: System::Windows::Forms::ToolStripButton^  cmd_bold;
	private: System::Windows::Forms::ToolStripButton^  cmd_italic;
	private: System::Windows::Forms::ToolStripButton^  cmd_underline;
	private: System::Windows::Forms::ToolStripButton^  cmd_align_left;
	private: System::Windows::Forms::ToolStripButton^  cmd_align_center;
	private: System::Windows::Forms::ToolStripButton^  cmd_align_right;
	private: System::Windows::Forms::ToolStripButton^  cmd_forecolor;
	private: System::Windows::Forms::ToolStripButton^  cmd_background_color;








	private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator3;
	private: System::Windows::Forms::ToolStripComboBox^  cb_format;
	private: System::Windows::Forms::OpenFileDialog^  open_dlg;
	private: System::Windows::Forms::SaveFileDialog^  save_dlg;
	private: System::Windows::Forms::SaveFileDialog^  save_excel_dlg;
	private: System::Windows::Forms::FontDialog^  font_dlg;
	private: System::Windows::Forms::ColorDialog^  color_dlg;
	private: System::Windows::Forms::ToolStripMenuItem^  ouvrirToolStripMenuItem;



	private:
		/// <summary>
		/// Variable nécessaire au concepteur.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
		/// le contenu de cette méthode avec l'éditeur de code.
		/// </summary>
		void InitializeComponent(void)
		{
			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
			this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
			this->fichierToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->nouveauToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->ouvrirToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->enregistrerToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->enregistrerSousToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->exporterExcelToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->toolStripMenuItem1 = (gcnew System::Windows::Forms::ToolStripSeparator());
			this->quitterToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->toolStripMenuItem2 = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->aProposDeMulticubeToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
			this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
			this->toolStripLabel1 = (gcnew System::Windows::Forms::ToolStripLabel());
			this->txt_cell_value = (gcnew System::Windows::Forms::ToolStripTextBox());
			this->statusStrip1 = (gcnew System::Windows::Forms::StatusStrip());
			this->dg = (gcnew System::Windows::Forms::DataGridView());
			this->toolStrip2 = (gcnew System::Windows::Forms::ToolStrip());
			this->nouveauToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->ouvrirToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->enregistrerToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->imprimerToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->toolStripSeparator = (gcnew System::Windows::Forms::ToolStripSeparator());
			this->couperToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->copierToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->collerToolStripButton = (gcnew System::Windows::Forms::ToolStripButton());
			this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
			this->cb_font_name = (gcnew System::Windows::Forms::ToolStripComboBox());
			this->cb_font_size = (gcnew System::Windows::Forms::ToolStripComboBox());
			this->toolStripSeparator2 = (gcnew System::Windows::Forms::ToolStripSeparator());
			this->cmd_bold = (gcnew System::Windows::Forms::ToolStripButton());
			this->cmd_italic = (gcnew System::Windows::Forms::ToolStripButton());
			this->cmd_underline = (gcnew System::Windows::Forms::ToolStripButton());
			this->cmd_align_left = (gcnew System::Windows::Forms::ToolStripButton());
			this->cmd_align_center = (gcnew System::Windows::Forms::ToolStripButton());
			this->cmd_align_right = (gcnew System::Windows::Forms::ToolStripButton());
			this->cmd_forecolor = (gcnew System::Windows::Forms::ToolStripButton());
			this->cmd_background_color = (gcnew System::Windows::Forms::ToolStripButton());
			this->toolStripSeparator3 = (gcnew System::Windows::Forms::ToolStripSeparator());
			this->cb_format = (gcnew System::Windows::Forms::ToolStripComboBox());
			this->open_dlg = (gcnew System::Windows::Forms::OpenFileDialog());
			this->save_dlg = (gcnew System::Windows::Forms::SaveFileDialog());
			this->save_excel_dlg = (gcnew System::Windows::Forms::SaveFileDialog());
			this->font_dlg = (gcnew System::Windows::Forms::FontDialog());
			this->color_dlg = (gcnew System::Windows::Forms::ColorDialog());
			this->menuStrip1->SuspendLayout();
			this->toolStrip1->SuspendLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dg))->BeginInit();
			this->toolStrip2->SuspendLayout();
			this->SuspendLayout();
			// 
			// menuStrip1
			// 
			this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->fichierToolStripMenuItem, 
				this->toolStripMenuItem2});
			this->menuStrip1->Location = System::Drawing::Point(0, 0);
			this->menuStrip1->Name = L"menuStrip1";
			this->menuStrip1->Size = System::Drawing::Size(721, 24);
			this->menuStrip1->TabIndex = 0;
			this->menuStrip1->Text = L"menuStrip1";
			// 
			// fichierToolStripMenuItem
			// 
			this->fichierToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(7) {this->nouveauToolStripMenuItem, 
				this->ouvrirToolStripMenuItem, this->enregistrerToolStripMenuItem, this->enregistrerSousToolStripMenuItem, this->exporterExcelToolStripMenuItem, 
				this->toolStripMenuItem1, this->quitterToolStripMenuItem});
			this->fichierToolStripMenuItem->Name = L"fichierToolStripMenuItem";
			this->fichierToolStripMenuItem->Size = System::Drawing::Size(50, 20);
			this->fichierToolStripMenuItem->Text = L"&Fichier";
			// 
			// nouveauToolStripMenuItem
			// 
			this->nouveauToolStripMenuItem->Name = L"nouveauToolStripMenuItem";
			this->nouveauToolStripMenuItem->Size = System::Drawing::Size(163, 22);
			this->nouveauToolStripMenuItem->Text = L"&Nouveau";
			this->nouveauToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::orb_menu_new_Click);
			// 
			// ouvrirToolStripMenuItem
			// 
			this->ouvrirToolStripMenuItem->Name = L"ouvrirToolStripMenuItem";
			this->ouvrirToolStripMenuItem->Size = System::Drawing::Size(163, 22);
			this->ouvrirToolStripMenuItem->Text = L"&Ouvrir";
			this->ouvrirToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::orb_menu_open_Click);
			// 
			// enregistrerToolStripMenuItem
			// 
			this->enregistrerToolStripMenuItem->Name = L"enregistrerToolStripMenuItem";
			this->enregistrerToolStripMenuItem->Size = System::Drawing::Size(163, 22);
			this->enregistrerToolStripMenuItem->Text = L"&Enregistrer";
			this->enregistrerToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::orb_menu_save_Click);
			// 
			// enregistrerSousToolStripMenuItem
			// 
			this->enregistrerSousToolStripMenuItem->Name = L"enregistrerSousToolStripMenuItem";
			this->enregistrerSousToolStripMenuItem->Size = System::Drawing::Size(163, 22);
			this->enregistrerSousToolStripMenuItem->Text = L"&Enregistrer sous";
			this->enregistrerSousToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::orb_menu_save_as_Click);
			// 
			// exporterExcelToolStripMenuItem
			// 
			this->exporterExcelToolStripMenuItem->Name = L"exporterExcelToolStripMenuItem";
			this->exporterExcelToolStripMenuItem->Size = System::Drawing::Size(163, 22);
			this->exporterExcelToolStripMenuItem->Text = L"Exporter E&xcel";
			this->exporterExcelToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::orb_save_copy_excel_Click);
			// 
			// toolStripMenuItem1
			// 
			this->toolStripMenuItem1->Name = L"toolStripMenuItem1";
			this->toolStripMenuItem1->Size = System::Drawing::Size(160, 6);
			// 
			// quitterToolStripMenuItem
			// 
			this->quitterToolStripMenuItem->Name = L"quitterToolStripMenuItem";
			this->quitterToolStripMenuItem->Size = System::Drawing::Size(163, 22);
			this->quitterToolStripMenuItem->Text = L"Quitter";
			this->quitterToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::quitterToolStripMenuItem_Click);
			// 
			// toolStripMenuItem2
			// 
			this->toolStripMenuItem2->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->aProposDeMulticubeToolStripMenuItem});
			this->toolStripMenuItem2->Name = L"toolStripMenuItem2";
			this->toolStripMenuItem2->Size = System::Drawing::Size(24, 20);
			this->toolStripMenuItem2->Text = L"\?";
			// 
			// aProposDeMulticubeToolStripMenuItem
			// 
			this->aProposDeMulticubeToolStripMenuItem->Name = L"aProposDeMulticubeToolStripMenuItem";
			this->aProposDeMulticubeToolStripMenuItem->Size = System::Drawing::Size(191, 22);
			this->aProposDeMulticubeToolStripMenuItem->Text = L"&A propos de Multicube";
			this->aProposDeMulticubeToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::aProposDeMulticubeToolStripMenuItem_Click);
			// 
			// toolStrip1
			// 
			this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {this->toolStripLabel1, 
				this->txt_cell_value});
			this->toolStrip1->Location = System::Drawing::Point(0, 49);
			this->toolStrip1->Name = L"toolStrip1";
			this->toolStrip1->Size = System::Drawing::Size(721, 25);
			this->toolStrip1->TabIndex = 1;
			this->toolStrip1->Text = L"toolStrip1";
			// 
			// toolStripLabel1
			// 
			this->toolStripLabel1->Name = L"toolStripLabel1";
			this->toolStripLabel1->Size = System::Drawing::Size(17, 22);
			this->toolStripLabel1->Text = L"fx";
			// 
			// txt_cell_value
			// 
			this->txt_cell_value->Name = L"txt_cell_value";
			this->txt_cell_value->Size = System::Drawing::Size(300, 25);
			this->txt_cell_value->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form1::txt_cell_value_KeyPress);
			// 
			// statusStrip1
			// 
			this->statusStrip1->Location = System::Drawing::Point(0, 431);
			this->statusStrip1->Name = L"statusStrip1";
			this->statusStrip1->Size = System::Drawing::Size(721, 22);
			this->statusStrip1->TabIndex = 2;
			this->statusStrip1->Text = L"statusStrip1";
			// 
			// dg
			// 
			this->dg->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
			this->dg->Dock = System::Windows::Forms::DockStyle::Fill;
			this->dg->Location = System::Drawing::Point(0, 74);
			this->dg->Name = L"dg";
			this->dg->Size = System::Drawing::Size(721, 357);
			this->dg->TabIndex = 3;
			this->dg->CellEnter += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &Form1::dg_CellEnter);
			this->dg->CellValueChanged += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &Form1::dg_CellValueChanged);
			// 
			// toolStrip2
			// 
			this->toolStrip2->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(22) {this->nouveauToolStripButton, 
				this->ouvrirToolStripButton, this->enregistrerToolStripButton, this->imprimerToolStripButton, this->toolStripSeparator, this->couperToolStripButton, 
				this->copierToolStripButton, this->collerToolStripButton, this->toolStripSeparator1, this->cb_font_name, this->cb_font_size, 
				this->toolStripSeparator2, this->cmd_bold, this->cmd_italic, this->cmd_underline, this->cmd_align_left, this->cmd_align_center, 
				this->cmd_align_right, this->cmd_forecolor, this->cmd_background_color, this->toolStripSeparator3, this->cb_format});
			this->toolStrip2->Location = System::Drawing::Point(0, 24);
			this->toolStrip2->Name = L"toolStrip2";
			this->toolStrip2->Size = System::Drawing::Size(721, 25);
			this->toolStrip2->TabIndex = 4;
			this->toolStrip2->Text = L"toolStrip2";
			// 
			// nouveauToolStripButton
			// 
			this->nouveauToolStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->nouveauToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"nouveauToolStripButton.Image")));
			this->nouveauToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->nouveauToolStripButton->Name = L"nouveauToolStripButton";
			this->nouveauToolStripButton->Size = System::Drawing::Size(23, 22);
			this->nouveauToolStripButton->Text = L"&Nouveau";
			this->nouveauToolStripButton->Click += gcnew System::EventHandler(this, &Form1::orb_menu_new_Click);
			// 
			// ouvrirToolStripButton
			// 
			this->ouvrirToolStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->ouvrirToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"ouvrirToolStripButton.Image")));
			this->ouvrirToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->ouvrirToolStripButton->Name = L"ouvrirToolStripButton";
			this->ouvrirToolStripButton->Size = System::Drawing::Size(23, 22);
			this->ouvrirToolStripButton->Text = L"&Ouvrir";
			this->ouvrirToolStripButton->Click += gcnew System::EventHandler(this, &Form1::orb_menu_open_Click);
			// 
			// enregistrerToolStripButton
			// 
			this->enregistrerToolStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->enregistrerToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"enregistrerToolStripButton.Image")));
			this->enregistrerToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->enregistrerToolStripButton->Name = L"enregistrerToolStripButton";
			this->enregistrerToolStripButton->Size = System::Drawing::Size(23, 22);
			this->enregistrerToolStripButton->Text = L"&Enregistrer";
			this->enregistrerToolStripButton->Click += gcnew System::EventHandler(this, &Form1::orb_menu_save_Click);
			// 
			// imprimerToolStripButton
			// 
			this->imprimerToolStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->imprimerToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"imprimerToolStripButton.Image")));
			this->imprimerToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->imprimerToolStripButton->Name = L"imprimerToolStripButton";
			this->imprimerToolStripButton->Size = System::Drawing::Size(23, 22);
			this->imprimerToolStripButton->Text = L"&Imprimer";
			// 
			// toolStripSeparator
			// 
			this->toolStripSeparator->Name = L"toolStripSeparator";
			this->toolStripSeparator->Size = System::Drawing::Size(6, 25);
			// 
			// couperToolStripButton
			// 
			this->couperToolStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->couperToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"couperToolStripButton.Image")));
			this->couperToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->couperToolStripButton->Name = L"couperToolStripButton";
			this->couperToolStripButton->Size = System::Drawing::Size(23, 22);
			this->couperToolStripButton->Text = L"C&ouper";
			// 
			// copierToolStripButton
			// 
			this->copierToolStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->copierToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"copierToolStripButton.Image")));
			this->copierToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->copierToolStripButton->Name = L"copierToolStripButton";
			this->copierToolStripButton->Size = System::Drawing::Size(23, 22);
			this->copierToolStripButton->Text = L"Co&pier";
			// 
			// collerToolStripButton
			// 
			this->collerToolStripButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->collerToolStripButton->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"collerToolStripButton.Image")));
			this->collerToolStripButton->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->collerToolStripButton->Name = L"collerToolStripButton";
			this->collerToolStripButton->Size = System::Drawing::Size(23, 22);
			this->collerToolStripButton->Text = L"Co&ller";
			// 
			// toolStripSeparator1
			// 
			this->toolStripSeparator1->Name = L"toolStripSeparator1";
			this->toolStripSeparator1->Size = System::Drawing::Size(6, 25);
			// 
			// cb_font_name
			// 
			this->cb_font_name->Name = L"cb_font_name";
			this->cb_font_name->Size = System::Drawing::Size(121, 25);
			this->cb_font_name->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::cb_font_name_SelectedIndexChanged);
			// 
			// cb_font_size
			// 
			this->cb_font_size->Name = L"cb_font_size";
			this->cb_font_size->Size = System::Drawing::Size(75, 25);
			this->cb_font_size->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::cb_font_size_SelectedIndexChanged);
			// 
			// toolStripSeparator2
			// 
			this->toolStripSeparator2->Name = L"toolStripSeparator2";
			this->toolStripSeparator2->Size = System::Drawing::Size(6, 25);
			// 
			// cmd_bold
			// 
			this->cmd_bold->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->cmd_bold->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"cmd_bold.Image")));
			this->cmd_bold->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->cmd_bold->Name = L"cmd_bold";
			this->cmd_bold->Size = System::Drawing::Size(23, 22);
			this->cmd_bold->Text = L"Gras";
			this->cmd_bold->Click += gcnew System::EventHandler(this, &Form1::cmd_bold_Click);
			// 
			// cmd_italic
			// 
			this->cmd_italic->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->cmd_italic->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"cmd_italic.Image")));
			this->cmd_italic->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->cmd_italic->Name = L"cmd_italic";
			this->cmd_italic->Size = System::Drawing::Size(23, 22);
			this->cmd_italic->Text = L"Italique";
			this->cmd_italic->Click += gcnew System::EventHandler(this, &Form1::cmd_italic_Click);
			// 
			// cmd_underline
			// 
			this->cmd_underline->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->cmd_underline->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"cmd_underline.Image")));
			this->cmd_underline->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->cmd_underline->Name = L"cmd_underline";
			this->cmd_underline->Size = System::Drawing::Size(23, 22);
			this->cmd_underline->Text = L"Souligné";
			this->cmd_underline->Click += gcnew System::EventHandler(this, &Form1::cmd_underline_Click);
			// 
			// cmd_align_left
			// 
			this->cmd_align_left->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->cmd_align_left->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"cmd_align_left.Image")));
			this->cmd_align_left->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->cmd_align_left->Name = L"cmd_align_left";
			this->cmd_align_left->Size = System::Drawing::Size(23, 22);
			this->cmd_align_left->Text = L"Gauche";
			// 
			// cmd_align_center
			// 
			this->cmd_align_center->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->cmd_align_center->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"cmd_align_center.Image")));
			this->cmd_align_center->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->cmd_align_center->Name = L"cmd_align_center";
			this->cmd_align_center->Size = System::Drawing::Size(23, 22);
			this->cmd_align_center->Text = L"Centré";
			// 
			// cmd_align_right
			// 
			this->cmd_align_right->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->cmd_align_right->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"cmd_align_right.Image")));
			this->cmd_align_right->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->cmd_align_right->Name = L"cmd_align_right";
			this->cmd_align_right->Size = System::Drawing::Size(23, 22);
			this->cmd_align_right->Text = L"Droite";
			// 
			// cmd_forecolor
			// 
			this->cmd_forecolor->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->cmd_forecolor->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"cmd_forecolor.Image")));
			this->cmd_forecolor->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->cmd_forecolor->Name = L"cmd_forecolor";
			this->cmd_forecolor->Size = System::Drawing::Size(23, 22);
			this->cmd_forecolor->Text = L"Couleur du texte";
			this->cmd_forecolor->Click += gcnew System::EventHandler(this, &Form1::cmd_color_fore_Click);
			// 
			// cmd_background_color
			// 
			this->cmd_background_color->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
			this->cmd_background_color->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"cmd_background_color.Image")));
			this->cmd_background_color->ImageTransparentColor = System::Drawing::Color::Magenta;
			this->cmd_background_color->Name = L"cmd_background_color";
			this->cmd_background_color->Size = System::Drawing::Size(23, 22);
			this->cmd_background_color->Text = L"Couleur de fond";
			this->cmd_background_color->Click += gcnew System::EventHandler(this, &Form1::cmd_color_background_Click);
			// 
			// toolStripSeparator3
			// 
			this->toolStripSeparator3->Name = L"toolStripSeparator3";
			this->toolStripSeparator3->Size = System::Drawing::Size(6, 25);
			// 
			// cb_format
			// 
			this->cb_format->Name = L"cb_format";
			this->cb_format->Size = System::Drawing::Size(121, 25);
			this->cb_format->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::cb_format_SelectedIndexChanged);
			// 
			// open_dlg
			// 
			this->open_dlg->DefaultExt = L"mcb";
			this->open_dlg->FileName = L"Tableau1";
			this->open_dlg->Filter = L"Fichier Multicube (*.mcb)|*.mcb|Tous les fichiers|*.*";
			this->open_dlg->Title = L"Ouvrir un tableau";
			// 
			// save_dlg
			// 
			this->save_dlg->DefaultExt = L"mcb";
			this->save_dlg->FileName = L"Tableau1";
			this->save_dlg->Filter = L"Fichier Multicube (*.mcb)|*.mcb|Tous les fichiers|*.*";
			this->save_dlg->Title = L"Enregistrer un tableau";
			// 
			// save_excel_dlg
			// 
			this->save_excel_dlg->DefaultExt = L"mcb";
			this->save_excel_dlg->FileName = L"Tableau1";
			this->save_excel_dlg->Filter = L"Fichier Excel (*.xlsx)|*.mcb|Tous les fichiers|*.xlsx";
			this->save_excel_dlg->Title = L"Enregistrer un tableau";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(721, 453);
			this->Controls->Add(this->dg);
			this->Controls->Add(this->toolStrip1);
			this->Controls->Add(this->toolStrip2);
			this->Controls->Add(this->statusStrip1);
			this->Controls->Add(this->menuStrip1);
			this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
			this->MainMenuStrip = this->menuStrip1;
			this->Name = L"Form1";
			this->Text = L"Multicube";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->menuStrip1->ResumeLayout(false);
			this->menuStrip1->PerformLayout();
			this->toolStrip1->ResumeLayout(false);
			this->toolStrip1->PerformLayout();
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dg))->EndInit();
			this->toolStrip2->ResumeLayout(false);
			this->toolStrip2->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion

		Feuille^ sheet;

		#pragma region init_combo
        void init_combo()
        {            
            for each (String^ s in FontFormatUtility::GetFontNames())
            {
                cb_font_name->Items->Add(s);
            }

            for each (String^ s in FontFormatUtility::GetFontSizes())
            {
                cb_font_size->Items->Add(s);
            }

            for each (String^ s in FontFormatUtility::GetFormats())
            {
                cb_format->Items->Add(s);
            }
            
        }

		#pragma region cmd_format_Click
        void cmd_format_Click(String^ format)
        {             
            String^ fu = format->ToUpper();
            if(fu == "AUTOMATIQUE")
			{
                sheet->Cells(CurrentCol, CurrentRow)->Format = Cellule::FormatType::AUTOMATIQUE;
			}

            else if(fu == "NOMBRE")
			{
		        sheet->Cells(CurrentCol, CurrentRow)->Format = Cellule::FormatType::NOMBRE;
			}

            else if(fu == "POURCENTAGE")
			{
                sheet->Cells(CurrentCol, CurrentRow)->Format = Cellule::FormatType::POURCENTAGE;
			}

			else
			{
                FormFormat^ f = gcnew FormFormat();                    
                f->FormatString = sheet->Cells(CurrentCol, CurrentRow)->FormatString;

                if (f->ShowDialog() == System::Windows::Forms::DialogResult::Cancel)
                    return;

                sheet->Cells(CurrentCol, CurrentRow)->Format = Cellule::FormatType::PERSONNALISE;
                sheet->Cells(CurrentCol, CurrentRow)->FormatString = f->FormatString;                    
            }

            dg->Rows[CurrentRow]->Cells[CurrentCol]->Value = 
				sheet->Cells(CurrentCol,CurrentRow)->FormattedValue;
        }
		#pragma endregion

        #pragma region cmd_font_size_Click
        void cmd_font_size_Click(String^ size)
        {            
            System::Drawing::Font^ f = dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font;
            System::Drawing::Font^ nf = gcnew System::Drawing::Font(
				f->FontFamily, System::Single::Parse(size),
				(FontStyle)(
                (f->Bold ? (int)FontStyle::Bold : 0) |
                (f->Italic ? (int)FontStyle::Italic : 0) |
                (f->Underline ? (int)FontStyle::Underline : 0)));

            dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font = nf;
            sheet->Cells(CurrentCol, CurrentRow)->FontSize = nf->Size;
        } 
        #pragma endregion

        #pragma region cmd_font_Click
        void cmd_font_family_Click(String^ family)
        {            
            System::Drawing::Font^ f = dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font;
            System::Drawing::Font^ nf = gcnew System::Drawing::Font(
				family, f->Size,
                (FontStyle)(
					(f->Bold ? (int)FontStyle::Bold : 0) |
					(f->Italic ? (int)FontStyle::Italic : 0) |
					(f->Underline ? (int)FontStyle::Underline : 0)));

            dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font = nf;
            sheet->Cells(CurrentCol, CurrentRow)->FontName = nf->FontFamily->Name;
        } 
        #pragma endregion
		
        #pragma endregion

		#pragma region Alignement et police
        void cmd_align_left_Click(Object^ sender, EventArgs^ e)
        {
            DataGridViewContentAlignment alignement = DataGridViewContentAlignment::MiddleLeft;
            dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Alignment = alignement;

            sheet->Cells(CurrentRow, CurrentCol)->Alignment = alignement;
        }

        void cmd_align_center_Click(Object^ sender, EventArgs^ e)
        {
            DataGridViewContentAlignment alignement = DataGridViewContentAlignment::MiddleCenter;
            dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Alignment = alignement;

            sheet->Cells(CurrentRow, CurrentCol)->Alignment = alignement;
        }

        void cmd_align_right_Click(Object^ sender, EventArgs^ e)
        {
            DataGridViewContentAlignment alignement = DataGridViewContentAlignment::MiddleRight;
            dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Alignment = alignement;

            sheet->Cells(CurrentRow, CurrentCol)->Alignment = alignement;
        }

        void cmd_bold_Click(Object^ sender, EventArgs^ e)
        {
            System::Drawing::Font^ p = dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font;
            System::Drawing::Font^ f = FontFormatUtility::ToggleFontBold(p);

            dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font = f;
            cmd_bold->Checked = f->Bold;

            sheet->Cells(CurrentCol, CurrentRow)->IsBold = f->Bold;
        }

        void cmd_italic_Click(Object^ sender, EventArgs^ e)
        {
            System::Drawing::Font^ p = dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font;
            System::Drawing::Font^ f = FontFormatUtility::ToggleFontItalic(p);

            dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font = f;
            cmd_italic->Checked = f->Italic;

            sheet->Cells(CurrentCol, CurrentRow)->IsItalic = f->Italic;
        }

        void cmd_underline_Click(Object^ sender, EventArgs^ e)
        {
            System::Drawing::Font^ p = dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font;
            System::Drawing::Font^ f = FontFormatUtility::ToggleFontUnderline(p);

			dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font = f;
            cmd_underline->Checked = f->Underline;

            sheet->Cells(CurrentCol, CurrentRow)->IsUnderlined = f->Underline;
        }

        void cmd_color_fore_Click(Object^ sender, EventArgs^ e)
        {
            if (color_dlg->ShowDialog() == System::Windows::Forms::DialogResult::Cancel)
                return;

            dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->ForeColor = color_dlg->Color;
            sheet->Cells(CurrentCol, CurrentRow)->ForeColor = color_dlg->Color;
        }

        void cmd_color_background_Click(Object^ sender, EventArgs^ e)
        {
            if (color_dlg->ShowDialog() == System::Windows::Forms::DialogResult::Cancel)
                return;

            dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->BackColor = color_dlg->Color;
            sheet->Cells(CurrentCol, CurrentRow)->BackgroundColor = color_dlg->Color;
        }
        #pragma endregion

        #pragma region SetCellValueHandler
        void SetCellValueHandler(bool handle)
        {
            if (handle)
                this->dg->CellValueChanged += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this,&Form1::dg_CellValueChanged);
            else
                this->dg->CellValueChanged -= gcnew System::Windows::Forms::DataGridViewCellEventHandler(this,&Form1::dg_CellValueChanged);
        } 
        #pragma endregion

        #pragma region sheet_OnCellUpdated
        void sheet_OnCellUpdated(int col, int row, String^ value)
        {
            SetCellValueHandler(false); // évite les mises à jour récursives           
            dg->Rows[row]->Cells[col]->Value = sheet->Cells(col, row)->FormattedValue;

            SetCellValueHandler(true);
        } 
        #pragma endregion

		#pragma region sheet_OnCellStyleUpdated
		void sheet_OnCellStyleUpdated(int col, int row)
        {
            Cellule^ c = sheet->Cells(col,row);

            dg->Rows[row]->Cells[col]->Style->Alignment = c->Alignment;

            System::Drawing::Font^ f = gcnew System::Drawing::Font(c->FontName,
                c->FontSize,
				(FontStyle)
                ((c->IsBold?(int)FontStyle::Bold:0)|
                (c->IsItalic?(int)FontStyle::Italic:0)|
                (c->IsUnderlined?(int)FontStyle::Underline:0)
                ));

            dg->Rows[row]->Cells[col]->Style->Font = f;            
            dg->Rows[row]->Cells[col]->Style->ForeColor = c->ForeColor;
            dg->Rows[row]->Cells[col]->Style->BackColor = c->BackgroundColor;                    
        } 
		#pragma endregion

        #pragma region init_grid
        void init_grid()
        {
            for (int c = 0; c < 52; c++)
            {
                String^ header = "";
                int h1 = ((int)'A') + (c / 26) - 1;
                int h2 = ((int)'A') + (c % 26);

                if (c >= 26)
                    header = String::Format("{0}{1}", (wchar_t)h1, (wchar_t)h2);
                else
                    header = String::Format("{0}", (wchar_t)h2);

                int cx = dg->Columns->Add("C" + c, header);
                dg->Columns[cx]->DefaultCellStyle->Alignment = DataGridViewContentAlignment::MiddleRight;
            }

            dg->RowHeadersDefaultCellStyle->Alignment = DataGridViewContentAlignment::MiddleRight;

            for (int l = 1; l <= 100; l++)
            {
                String^ header = "";
                header = String::Format("{0:000}", l);
                DataGridViewRow^ row = gcnew DataGridViewRow();
                row->HeaderCell = gcnew DataGridViewRowHeaderCell();
                row->HeaderCell->ToolTipText = header;
                row->HeaderCell->Value = header;

                dg->Rows->Add(row);
            }

            sheet = gcnew Feuille();
            SetCellValueHandler(true);
            sheet->OnCellUpdated += gcnew Feuille::del_cellUpdated(this,&Form1::sheet_OnCellUpdated);
            sheet->OnCellStyleUpdated += gcnew Feuille::del_cellStyleUpdated(this,&Form1::sheet_OnCellStyleUpdated);
        } 
        #pragma endregion

        #pragma region cmd_update_Click
        /// <summary>
        /// Actualise l'affichage
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void cmd_update_Click(Object^ sender, EventArgs^ e)
        {
            sheet->recalc();
        } 
        #pragma endregion

        #pragma region dg_CellValueChanged
        void dg_CellValueChanged(Object^ sender, DataGridViewCellEventArgs^ e)
        {            
            Object^ vo = dg->Rows[e->RowIndex]->Cells[e->ColumnIndex]->Value;
            String^ value = vo != nullptr ? vo->ToString() : "";

            if (value->StartsWith("="))
                sheet->Cells(e->ColumnIndex, e->RowIndex)->Formula = value;
            else            
            {                            
                sheet->Cells(e->ColumnIndex, e->RowIndex)->FormattedValue = value;
            }
            
            // il faut recalculer puisque les valeurs ont changé            
            sheet->recalc();            
        } 
        #pragma endregion

        #pragma region CurrentCol
        property int CurrentCol
        {
            int get()
			{ 
				return dg->CurrentCell->ColumnIndex; 
			}
        } 
        #pragma endregion

        #pragma region CurrentRow
        property int CurrentRow
        {
            int get()
			{ 
				return dg->CurrentRow->Index; 
			}
        } 
        #pragma endregion

        #pragma region txt_cell_value_KeyPress
        void txt_cell_value_KeyPress(Object^ sender, KeyPressEventArgs^ e)
        {
            switch (e->KeyChar)
            {
                case '\r':
                    String^ fx = txt_cell_value->Text;
                    if (fx->StartsWith("="))
                    {
                        sheet->Cells(CurrentCol, CurrentRow)->Formula = fx;
                    }
                    else
                    {                        
                        sheet->Cells(CurrentCol, CurrentRow)->FormattedValue = fx;
                        sheet_OnCellUpdated(CurrentCol, CurrentRow, fx);
                    }
                    sheet->recalc();
                    break;
            }
        } 
        #pragma endregion

		#pragma region dg_CellEnter
        void dg_CellEnter(Object^ sender, DataGridViewCellEventArgs^ e)
        {
            if (sheet == nullptr)
                return;

            String^ fx = sheet->Cells(CurrentCol, CurrentRow)->Formula;
            if (fx == nullptr || fx == "")
            {                
                fx = sheet->Cells(CurrentCol, CurrentRow)->FormattedValue;
            }

            txt_cell_value->Text = fx;

            // format            
            String^ fmt = "";
            switch (sheet->Cells(CurrentCol, CurrentRow)->Format)
            {
			case Cellule::FormatType::AUTOMATIQUE:
                    fmt = "Automatique";
                    break;

			case Cellule::FormatType::NOMBRE:
                    fmt = "Nombre";
                    break;

			case Cellule::FormatType::POURCENTAGE:
                    fmt = "Pourcentage";
                    break;

			case Cellule::FormatType::DATE:
                    fmt = "Date";
                    break;

			case Cellule::FormatType::TEXT:
                    fmt = "Texte";
                    break;

			case Cellule::FormatType::PERSONNALISE:
                    fmt = "Personnalisé";
                    break;
            }

            cb_format->Text = fmt;            

            // vérifie le style
            cmd_bold->Checked = false;
            cmd_italic->Checked = false;
            cmd_underline->Checked = false;

            DataGridViewCellStyle^ s =
                dg->Rows[CurrentRow]->Cells[CurrentCol]->Style;

            if (s == nullptr || s->Font==nullptr)
                return;

            if (s->Font->Bold)
                cmd_bold->Checked = true;

            if (s->Font->Italic)
                cmd_italic->Checked = true;

            if (s->Font->Underline)
                cmd_underline->Checked = true;

            cb_font_name->Text = dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font->FontFamily->Name;			
            cb_font_size->Text = "" + dg->Rows[CurrentRow]->Cells[CurrentCol]->Style->Font->Size;            
        } 
        #pragma endregion

		#pragma region Menu Fichier
        #pragma region orb_menu_save_Click
        void orb_menu_save_Click(Object^ sender, EventArgs^ e)
        {
            if (sheet->Fileshortname == nullptr || sheet->Fileshortname == "")
            {
                orb_menu_save_as_Click(sender, e);
                return;
            }

            sheet->Save();
        } 
        #pragma endregion

        #pragma region orb_menu_open_Click
        void orb_menu_open_Click(Object^ sender, EventArgs^ e)
        {
            if (open_dlg->ShowDialog() == System::Windows::Forms::DialogResult::Cancel)
                return;

            InitGrid();
            sheet->Load(open_dlg->FileName);
        } 
        #pragma endregion

        #pragma region orb_menu_quitter_Click
        void orb_menu_quitter_Click(Object^ sender, EventArgs^ e)
        {
            Close();
        } 
        #pragma endregion

        #pragma region orb_menu_save_as_Click
        void orb_menu_save_as_Click(Object^ sender, EventArgs^ e)
        {
            if (save_dlg->ShowDialog() == System::Windows::Forms::DialogResult::Cancel)
                return;

            sheet->Save(save_dlg->FileName);
        } 
        #pragma endregion

        #pragma region orb_menu_new_Click
        void orb_menu_new_Click(Object^ sender, EventArgs^ e)
        {
            InitGrid();
        } 
        #pragma endregion

        #pragma region InitGrid
        void InitGrid()
        {
            dg->Rows->Clear();
            dg->Columns->Clear();
            init_grid();
        }
        #pragma endregion

        #pragma region orb_save_copy_excel_Click
        void orb_save_copy_excel_Click(Object^ sender, EventArgs^ e)
        {
            if (save_excel_dlg->ShowDialog() == System::Windows::Forms::DialogResult::Cancel)
                return;

            sheet->SaveCopyExcel(save_excel_dlg->FileName);
        }
        #pragma endregion
        #pragma endregion


	private: System::Void quitterToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
				 Close();
			 }
private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			 init_grid();
			 init_combo();
		 }
private: System::Void cb_font_name_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 Object^ o = cb_font_name->SelectedItem;
			 if(o==nullptr)
				 return;

			 String^ family = o->ToString();
			 if(family==nullptr || family =="")
				 return;
			 
			 cmd_font_family_Click(family);
		 }
private: System::Void cb_font_size_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {			 
			 Object^ o = cb_font_size->SelectedItem;
			 if(o==nullptr)
				 return;

			 String^ size = o->ToString();
			 if(size==nullptr || size =="")
				 return;
			 
			 cmd_font_size_Click(size);
		 }
private: System::Void cb_format_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 Object^ o = cb_format->SelectedItem;
			 if(o==nullptr)
				 return;

			 String^ format = o->ToString();
			 if(format==nullptr || format =="")
				 return;
			 
			 cmd_format_Click(format);
		 }

private: System::Void aProposDeMulticubeToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 FormApropos^ f = gcnew FormApropos();
			 f->ShowDialog();			 
		 }
};
}

