#pragma once

namespace Image_Segmentation_on_GPU {

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

	/// <summary>
	/// Summary for MyFormError
	/// </summary>
	public ref class MyFormError : public System::Windows::Forms::Form
	{

	public:
		MyFormError(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

		//
		// Customization properties of ErrorBox
		//
		// setting title
		property System::String^ titleText
		{
			void set(System::String^ text)
			{
				Form::Text = text;
			}
		}

		// setting description text
		property System::String^ descriptionText
		{
			void set(System::String^ text)
			{
				this->textBox_Description->Text = text;
			}
		}

		// set exception text in textBox visible after clicking details
		property System::String^ exceptionText
		{
			void set(System::String^ text)
			{
				this->textBox_Exception->Text = text;
			}
		}

		// set icon
		property Bitmap^ dlgIcon
		{
			void set(Bitmap^ icon)
			{
				this->pictureBox_Icon->Image = icon;
			}
		}

		// set buttons of errorBox 
		property System::Windows::Forms::MessageBoxButtons Buttons
		{
			void set(System::Windows::Forms::MessageBoxButtons btn)
			{
				switch (btn)
				{
				case System::Windows::Forms::MessageBoxButtons::OK:
					this->button_1->Visible = true;
					this->button_1->DialogResult = System::Windows::Forms::DialogResult::OK;
					this->button_1->Text = this->button_1->DialogResult.ToString();
					this->button_2->Visible = false;
					this->button_3->Visible = false;
					break;
				case System::Windows::Forms::MessageBoxButtons::OKCancel:
					this->button_1->Visible = true;
					this->button_1->DialogResult = System::Windows::Forms::DialogResult::Cancel;
					this->button_1->Text = this->button_1->DialogResult.ToString();
					this->button_2->Visible = true;
					this->button_2->DialogResult = System::Windows::Forms::DialogResult::OK;
					this->button_2->Text = this->button_2->DialogResult.ToString();
					this->button_3->Visible = false;
					break;
				case System::Windows::Forms::MessageBoxButtons::AbortRetryIgnore:
					this->button_1->Visible = true;
					this->button_1->DialogResult = System::Windows::Forms::DialogResult::Ignore;
					this->button_1->Text = this->button_1->DialogResult.ToString();
					this->button_2->Visible = true;
					this->button_2->DialogResult = System::Windows::Forms::DialogResult::Retry;
					this->button_2->Text = this->button_2->DialogResult.ToString();
					this->button_3->Visible = true;
					this->button_3->DialogResult = System::Windows::Forms::DialogResult::Abort;
					this->button_3->Text = this->button_3->DialogResult.ToString();
					break;
				case System::Windows::Forms::MessageBoxButtons::YesNoCancel:
					this->button_1->Visible = true;
					this->button_1->DialogResult = System::Windows::Forms::DialogResult::Cancel;
					this->button_1->Text = this->button_1->DialogResult.ToString();
					this->button_2->Visible = true;
					this->button_2->DialogResult = System::Windows::Forms::DialogResult::No;
					this->button_2->Text = this->button_2->DialogResult.ToString();
					this->button_3->Visible = true;
					this->button_3->DialogResult = System::Windows::Forms::DialogResult::Yes;
					this->button_3->Text = this->button_3->DialogResult.ToString();
					break;
				case System::Windows::Forms::MessageBoxButtons::YesNo:
					this->button_1->Visible = true;
					this->button_1->DialogResult = System::Windows::Forms::DialogResult::No;
					this->button_1->Text = this->button_1->DialogResult.ToString();
					this->button_2->Visible = true;
					this->button_2->DialogResult = System::Windows::Forms::DialogResult::Yes;
					this->button_2->Text = this->button_2->DialogResult.ToString();
					this->button_3->Visible = false;
					break;
				case System::Windows::Forms::MessageBoxButtons::RetryCancel:
					this->button_1->Visible = true;
					this->button_1->DialogResult = System::Windows::Forms::DialogResult::Cancel;
					this->button_1->Text = this->button_1->DialogResult.ToString();
					this->button_2->Visible = true;
					this->button_2->DialogResult = System::Windows::Forms::DialogResult::Retry;
					this->button_2->Text = this->button_2->DialogResult.ToString();
					this->button_3->Visible = false;
					break;
				default:
					break;
				}
			}
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~MyFormError()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::TextBox^  textBox_Exception;
	protected:

	protected:
	private: System::Windows::Forms::Button^  button_Details;
	private: System::Windows::Forms::Button^  button_1;
	private: System::Windows::Forms::Button^  button_2;


	private: System::Windows::Forms::PictureBox^  pictureBox_Icon;
	private: System::Windows::Forms::Label^  textBox_Description;
	private: System::Windows::Forms::Button^  button_3;




	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->textBox_Exception = (gcnew System::Windows::Forms::TextBox());
			this->button_Details = (gcnew System::Windows::Forms::Button());
			this->button_1 = (gcnew System::Windows::Forms::Button());
			this->button_2 = (gcnew System::Windows::Forms::Button());
			this->pictureBox_Icon = (gcnew System::Windows::Forms::PictureBox());
			this->textBox_Description = (gcnew System::Windows::Forms::Label());
			this->button_3 = (gcnew System::Windows::Forms::Button());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox_Icon))->BeginInit();
			this->SuspendLayout();
			// 
			// textBox_Exception
			// 
			this->textBox_Exception->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left)
				| System::Windows::Forms::AnchorStyles::Right));
			this->textBox_Exception->Location = System::Drawing::Point(13, 97);
			this->textBox_Exception->Multiline = true;
			this->textBox_Exception->Name = L"textBox_Exception";
			this->textBox_Exception->ReadOnly = true;
			this->textBox_Exception->ScrollBars = System::Windows::Forms::ScrollBars::Both;
			this->textBox_Exception->Size = System::Drawing::Size(359, 102);
			this->textBox_Exception->TabIndex = 0;
			this->textBox_Exception->Visible = false;
			// 
			// button_Details
			// 
			this->button_Details->Location = System::Drawing::Point(12, 69);
			this->button_Details->Name = L"button_Details";
			this->button_Details->Size = System::Drawing::Size(75, 22);
			this->button_Details->TabIndex = 1;
			this->button_Details->Text = L"Details";
			this->button_Details->TextImageRelation = System::Windows::Forms::TextImageRelation::ImageBeforeText;
			this->button_Details->UseVisualStyleBackColor = true;
			this->button_Details->Click += gcnew System::EventHandler(this, &MyFormError::button_Details_Click);
			// 
			// button_1
			// 
			this->button_1->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
			this->button_1->Location = System::Drawing::Point(297, 69);
			this->button_1->Name = L"button_1";
			this->button_1->Size = System::Drawing::Size(75, 22);
			this->button_1->TabIndex = 2;
			this->button_1->Text = L"1";
			this->button_1->UseVisualStyleBackColor = true;
			this->button_1->Visible = false;
			// 
			// button_2
			// 
			this->button_2->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
			this->button_2->Location = System::Drawing::Point(216, 69);
			this->button_2->Name = L"button_2";
			this->button_2->Size = System::Drawing::Size(75, 22);
			this->button_2->TabIndex = 3;
			this->button_2->Text = L"2";
			this->button_2->UseVisualStyleBackColor = true;
			this->button_2->Visible = false;
			// 
			// pictureBox_Icon
			// 
			this->pictureBox_Icon->Location = System::Drawing::Point(12, 22);
			this->pictureBox_Icon->Name = L"pictureBox_Icon";
			this->pictureBox_Icon->Size = System::Drawing::Size(32, 32);
			this->pictureBox_Icon->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
			this->pictureBox_Icon->TabIndex = 5;
			this->pictureBox_Icon->TabStop = false;
			// 
			// textBox_Description
			// 
			this->textBox_Description->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left)
				| System::Windows::Forms::AnchorStyles::Right));
			this->textBox_Description->Location = System::Drawing::Point(51, 12);
			this->textBox_Description->Name = L"textBox_Description";
			this->textBox_Description->Size = System::Drawing::Size(321, 54);
			this->textBox_Description->TabIndex = 6;
			this->textBox_Description->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
			// 
			// button_3
			// 
			this->button_3->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Right));
			this->button_3->Location = System::Drawing::Point(135, 69);
			this->button_3->Name = L"button_3";
			this->button_3->Size = System::Drawing::Size(75, 22);
			this->button_3->TabIndex = 7;
			this->button_3->Text = L"3";
			this->button_3->UseVisualStyleBackColor = true;
			this->button_3->Visible = false;
			// 
			// MyFormError
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(384, 101);
			this->Controls->Add(this->button_3);
			this->Controls->Add(this->textBox_Description);
			this->Controls->Add(this->pictureBox_Icon);
			this->Controls->Add(this->button_2);
			this->Controls->Add(this->button_1);
			this->Controls->Add(this->button_Details);
			this->Controls->Add(this->textBox_Exception);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
			this->MaximizeBox = false;
			this->MaximumSize = System::Drawing::Size(500, 250);
			this->MinimizeBox = false;
			this->MinimumSize = System::Drawing::Size(277, 140);
			this->Name = L"MyFormError";
			this->ShowIcon = false;
			this->ShowInTaskbar = false;
			this->StartPosition = System::Windows::Forms::FormStartPosition::CenterParent;
			this->Text = L"MyFormError";
			this->Load += gcnew System::EventHandler(this, &MyFormError::MyFormError_Load);
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox_Icon))->EndInit();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
private: System::Void MyFormError_Load(System::Object^  sender, System::EventArgs^  e) 
{
	// hiding space of exception textbox
	Form::Size = System::Drawing::Size(Form::Size.Width, 140);

	// check for icon, if there is none move textbox to the right side of form
	if (pictureBox_Icon->Image == nullptr)
	{
		textBox_Description->Location = System::Drawing::Point(8,textBox_Description->Location.Y);
	}
	// check if there is exception, otherwise hide details button
	if (String::IsNullOrEmpty(textBox_Exception->Text))
	{
		button_Details->Visible = false;
	}
}
private: System::Void button_Details_Click(System::Object^  sender, System::EventArgs^  e) 
{
	// show/hide exception textbox
	if (this->textBox_Exception->Visible == true)
	{
		this->textBox_Exception->Visible = false;
		Form::Size = System::Drawing::Size(Form::Size.Width, 140);
	}
	else
	{
		this->textBox_Exception->Visible = true;
		Form::Size = System::Drawing::Size(Form::Size.Width, 250);
	}
}
};
}
