EasyAndFastMod/Controls/CheckBox.mqh

195 lines
16 KiB
MQL5
Raw Permalink Normal View History

2026-01-15 07:23:17 -05:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| CheckBox.mqh |
//| Copyright 2015, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#include "..\Element.mqh"
//+------------------------------------------------------------------+
//| ;0AA 4;O A>740=8O G5:-1>:A0 |
//+------------------------------------------------------------------+
class CCheckBox : public CElement
{
public:
CCheckBox(void);
~CCheckBox(void);
//--- 5B>4K 4;O A>740=8O G5:-1>:A0
bool CreateCheckBox(const string text,const int x_gap,const int y_gap);
//---
private:
void InitializeProperties(const string text,const int x_gap,const int y_gap);
bool CreateCanvas(void);
//---
public:
//--- !>AB>O=85 :=>?:8 (=060B0/>B60B0)
bool IsPressed(void) const { return(m_is_pressed); }
void IsPressed(const bool state);
//---
public:
//--- 1@01>BG8: A>1KB89 3@0D8:0
virtual void OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
//--- 8AC5B M;5<5=B
virtual void Draw(void);
//---
private:
//--- 1@01>B:0 =060B8O =0 M;5<5=B
bool OnClickCheckbox(const string pressed_object);
//--- 8AC5B :0@B8=:C
virtual void DrawImage(void);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CCheckBox::CCheckBox(void)
{
//--- !>E@0=8< 8<O :;0AA0 M;5<5=B0 2 107>2>< :;0AA5
CElementBase::ClassName(CLASS_NAME);
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CCheckBox::~CCheckBox(void)
{
}
//+------------------------------------------------------------------+
//| 1@01>B:0 A>1KB89 |
//+------------------------------------------------------------------+
void CCheckBox::OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
{
//--- 1@01>B:0 A>1KB8O ?5@5<5I5=8O :C@A>@0
if(id==CHARTEVENT_MOUSE_MOVE)
{
//--- 5@5@8A>20BL M;5<5=B
if(CheckCrossingBorder())
Update(true);
//---
return;
}
//--- 1@01>B:0 A>1KB8O =060B8O ;52>9 :=>?:8 <KH8 =0 >1J5:B5
if(id==CHARTEVENT_OBJECT_CLICK)
{
//--- 060B85 =0 G5:-1>:A5
if(OnClickCheckbox(sparam))
return;
}
}
//+------------------------------------------------------------------+
//| !>740QB 3@C??C >1J5:B>2 G5:1>:A |
//+------------------------------------------------------------------+
bool CCheckBox::CreateCheckBox(const string text,const int x_gap,const int y_gap)
{
//--- K9B8, 5A;8 =5B C:070B5;O =0 3;02=K9 M;5<5=B
if(!CElement::CheckMainPointer())
return(false);
//--- =8F80;870F8O A2>9AB2
InitializeProperties(text,x_gap,y_gap);
//--- !>740=85 M;5<5=B0
if(!CreateCanvas())
return(false);
//---
return(true);
}
//+------------------------------------------------------------------+
//| =8F80;870F8O A2>9AB2 |
//+------------------------------------------------------------------+
void CCheckBox::InitializeProperties(const string text,const int x_gap,const int y_gap)
{
m_x =CElement::CalculateX(x_gap);
m_y =CElement::CalculateY(y_gap);
m_x_size =(m_x_size<1)? 100 : m_x_size;
m_y_size =(m_y_size<1)? 14 : m_y_size;
m_label_text =text;
//--- &25B D>=0 ?> C<>;G0=8N
m_back_color=(m_back_color!=clrNONE)? m_back_color : m_main.BackColor();
//--- BABC?K 8 F25B B5:AB>2>9 <5B:8
m_label_x_gap =(m_label_x_gap!=WRONG_VALUE)? m_label_x_gap : 18;
m_label_y_gap =(m_label_y_gap!=WRONG_VALUE)? m_label_y_gap : 0;
m_label_color =(m_label_color!=clrNONE)? m_label_color : clrBlack;
m_label_color_hover =(m_label_color_hover!=clrNONE)? m_label_color_hover : C'0,120,215';
m_label_color_locked =(m_label_color_locked!=clrNONE)? m_label_color_locked : clrSilver;
m_label_color_pressed =(m_label_color_pressed!=clrNONE)? m_label_color_pressed : clrBlack;
//--- BABC?K >B :@09=59 B>G:8
CElementBase::XGap(x_gap);
CElementBase::YGap(y_gap);
}
//+------------------------------------------------------------------+
//| !>740QB >1J5:B 4;O @8A>20=8O |
//+------------------------------------------------------------------+
bool CCheckBox::CreateCanvas(void)
{
//--- $>@<8@>20=85 8<5=8 >1J5:B0
string name=CElementBase::ElementName("checkbox");
//--- #AB0=>2:0 87>1@065=89
IconFile(RESOURCE_CHECKBOX_OFF);
IconFileLocked(RESOURCE_CHECKBOX_OFF_LOCKED);
IconFilePressed(RESOURCE_CHECKBOX_ON);
IconFilePressedLocked(RESOURCE_CHECKBOX_ON_LOCKED);
//--- !>740=85 >1J5:B0
if(!CElement::CreateCanvas(name,m_x,m_y,m_x_size,m_y_size))
return(false);
//---
return(true);
}
//+------------------------------------------------------------------+
//| #AB0=>2:0 A>AB>O=8O M;5<5=B0 (=060B/>B60B) |
//+------------------------------------------------------------------+
void CCheckBox::IsPressed(const bool state)
{
//--- K9B8, 5A;8 (1) M;5<5=B 701;>:8@>20= 8;8 (2) M;5<5=B C65 2 B0:>< A>AB>O=88
if(CElementBase::IsLocked() || m_is_pressed==state)
return;
//--- #AB0=>2:0 A>AB>O=8O
m_is_pressed=state;
//--- #AB0=>28BL A>>B25BAB2CNICN :0@B8=:C
CElement::ChangeImage(0,!m_is_pressed? 0 : 2);
}
//+------------------------------------------------------------------+
//| 060B85 =0 M;5<5=B0 |
//+------------------------------------------------------------------+
bool CCheckBox::OnClickCheckbox(const string pressed_object)
{
//--- K945<, 5A;8 (1) GC6>5 8<O >1J5:B0 8;8 (2) M;5<5=B 701;>:8@>20=
if(m_canvas.ChartObjectName()!=pressed_object || CElementBase::IsLocked())
return(false);
//--- 5@5:;NG8BL =0 ?@>B82>?>;>6=>5 A>AB>O=85
IsPressed(!(IsPressed()));
//--- 5@5@8A>20BL M;5<5=B
Update(true);
//--- B?@028< A>>1I5=85 >1 MB><
::EventChartCustom(m_chart_id,ON_CLICK_CHECKBOX,CElementBase::Id(),0,m_label_text);
return(true);
}
//+------------------------------------------------------------------+
//| 8AC5B M;5<5=B |
//+------------------------------------------------------------------+
void CCheckBox::Draw(void)
{
//--- 0@8A>20BL D>=
CElement::DrawBackground();
//--- 0@8A>20BL :0@B8=:C
CCheckBox::DrawImage();
//--- 0@8A>20BL B5:AB
CElement::DrawText();
}
//+------------------------------------------------------------------+
//| 8AC5B :0@B8=:C |
//+------------------------------------------------------------------+
void CCheckBox::DrawImage(void)
{
//--- ?@545;8< 8=45:A
uint image_index=(m_is_pressed)? 2 : 0;
//--- A;8 M;5<5=B =5 701;>:8@>20=
if(!CElementBase::IsLocked())
{
if(CElementBase::MouseFocus())
image_index=(m_is_pressed)? 2 : 0;
}
else
image_index=(m_is_pressed)? 3 : 1;
//--- #AB0=>28BL A>>B25BAB2CNICN :0@B8=:C
CElement::ChangeImage(0,image_index);
//--- 8AC5< :0@B8=:C
CElement::DrawImage();
}
//+------------------------------------------------------------------+