EasyAndFastMod/Controls/TimeEdit.mqh

290 lines
23 KiB
MQL5
Raw Permalink Normal View History

2026-01-15 07:23:17 -05:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| TimeEdit.mqh |
//| Copyright 2016, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#include "..\Element.mqh"
#include "TextEdit.mqh"
//+------------------------------------------------------------------+
//| ;0AA 4;O A>740=8O M;5<5=B0 "@5<O" |
//+------------------------------------------------------------------+
class CTimeEdit : public CElement
{
private:
//--- 1J5:BK 4;O A>740=8O M;5<5=B0
CTextEdit m_hours;
CTextEdit m_minutes;
//--- 568< A1@>A0 7=0G5=8O
bool m_reset_mode;
//--- 568< M;5<5=B0 A G5:-1>:A><
bool m_checkbox_mode;
//---
public:
CTimeEdit(void);
~CTimeEdit(void);
//--- 5B>4K 4;O A>740=8O M;5<5=B0
bool CreateTimeEdit(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);
bool CreateSpinEdit(CTextEdit &edit_obj,const int index);
//---
public:
//--- (1) >72@0I05B C:070B5;8 ?>;59 22>40, (2) 2>72@0I5=85/CAB0=>2:0 A>AB>O=8O 4>ABC?=>AB8 M;5<5=B0
CTextEdit *GetHoursEditPointer(void) { return(::GetPointer(m_hours)); }
CTextEdit *GetMinutesEditPointer(void) { return(::GetPointer(m_minutes)); }
//--- (1) 568< A1@>A0 ?@8 =060B88 =0 B5:AB>2>9 <5B:5, (2) @568< M;5<5=B0 A G5:-1>:A><
bool ResetMode(void) { return(m_reset_mode); }
void ResetMode(const bool mode) { m_reset_mode=mode; }
void CheckBoxMode(const bool state) { m_checkbox_mode=state; }
//--- >72@0I5=85 8 CAB0=>2:0 7=0G5=89 ?>;59 22>40
int GetHours(void) { return((int)m_hours.GetValue()); }
int GetMinutes(void) { return((int)m_minutes.GetValue()); }
void SetHours(const uint value) { m_hours.SetValue((string)value); }
void SetMinutes(const uint value) { m_minutes.SetValue((string)value); }
//--- !>AB>O=85 M;5<5=B0 (=060B/>B60B)
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);
//--- ;>:8@>2:0
virtual void IsLocked(const bool state);
//--- 8AC5B M;5<5=B
virtual void Draw(void);
//---
private:
//--- 1@01>B:0 =060B8O =0 M;5<5=B5
bool OnClickElement(const string clicked_object);
//--- 8AC5B :0@B8=:C
virtual void DrawImage(void);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CTimeEdit::CTimeEdit(void) : m_reset_mode(false)
{
//--- !>E@0=8< 8<O :;0AA0 M;5<5=B0 2 107>2>< :;0AA5
CElementBase::ClassName(CLASS_NAME);
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CTimeEdit::~CTimeEdit(void)
{
}
//+------------------------------------------------------------------+
//| 1@01>B:0 A>1KB89 |
//+------------------------------------------------------------------+
void CTimeEdit::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 M;5<5=B5
if(id==CHARTEVENT_OBJECT_CLICK)
{
if(OnClickElement(sparam))
return;
//---
return;
}
}
//+------------------------------------------------------------------+
//| !>740QB M;5<5=B C?@02;5=8O "@5<O" |
//+------------------------------------------------------------------+
bool CTimeEdit::CreateTimeEdit(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);
if(!CreateSpinEdit(m_minutes,0))
return(false);
if(!CreateSpinEdit(m_hours,1))
return(false);
//---
return(true);
}
//+------------------------------------------------------------------+
//| =8F80;870F8O A2>9AB2 |
//+------------------------------------------------------------------+
void CTimeEdit::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)? 20 : 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();
m_icon_y_gap =(m_icon_y_gap!=WRONG_VALUE)? m_icon_y_gap : 4;
//--- BABC?K 8 F25B B5:AB>2>9 <5B:8
m_label_x_gap =(m_label_x_gap!=WRONG_VALUE)? m_label_x_gap : 0;
m_label_y_gap =(m_label_y_gap!=WRONG_VALUE)? m_label_y_gap : 3;
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 CTimeEdit::CreateCanvas(void)
{
//--- $>@<8@>20=85 8<5=8 >1J5:B0
string name=CElementBase::ElementName("time_edit");
//--- A;8 =C65= M;5<5=B A G5:-1>:A><
if(m_checkbox_mode)
{
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);
}
//+------------------------------------------------------------------+
//| !>740QB ?>;O 22>40 4;O G0A>2 8 <8=CB |
//+------------------------------------------------------------------+
bool CTimeEdit::CreateSpinEdit(CTextEdit &edit_obj,const int index)
{
//--- !>E@0=8< C:070B5;L =0 3;02=K9 M;5<5=B
edit_obj.MainPointer(this);
//--- >>@48=0BK
int x=0,y=0;
//--- 07<5@K
int x_size=40;
//--- >;5 22>40 4;O <8=CB
if(index==0)
{
x=x_size;
//--- 0:A8<0;L=>5 7=0G5=85
edit_obj.MaxValue(59);
//--- =45:A M;5<5=B0
edit_obj.Index(0);
}
//--- >;5 22>40 4;O G0A>2
else
{
x=x_size*2;
//--- 0:A8<0;L=>5 7=0G5=85
edit_obj.MaxValue(23);
//--- =45:A M;5<5=B0
edit_obj.Index(1);
}
//--- #AB0=>28< A2>9AB20 ?5@54 A>740=85<
edit_obj.XSize(x_size);
edit_obj.YSize(m_y_size);
edit_obj.MinValue(0);
edit_obj.StepValue(1);
edit_obj.SpinEditMode(true);
edit_obj.AnchorRightWindowSide(true);
edit_obj.GetTextBoxPointer().XGap(1);
edit_obj.GetTextBoxPointer().XSize(x_size-1);
edit_obj.IsDropdown(CElementBase::IsDropdown());
//--- !>74048< M;5<5=B C?@02;5=8O
if(!edit_obj.CreateTextEdit("",x,y))
return(false);
//--- >1028BL M;5<5=B 2 <0AA82
CElement::AddToArray(edit_obj);
return(true);
}
//+------------------------------------------------------------------+
//| >:070BL M;5<5=B |
//+------------------------------------------------------------------+
void CTimeEdit::IsLocked(const bool state)
{
CElement::IsLocked(state);
//--- #AB0=>28BL A>>B25BAB2CNICN :0@B8=:C
CElement::ChangeImage(0,(m_is_locked)? !m_is_pressed? 1 : 3 : !m_is_pressed? 0 : 2);
}
//+------------------------------------------------------------------+
//| #AB0=>2:0 A>AB>O=8O M;5<5=B0 (=060B/>B60B) |
//+------------------------------------------------------------------+
void CTimeEdit::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);
}
//+------------------------------------------------------------------+
//| 1@01>B:0 =060B8O =0 M;5<5=B5 |
//+------------------------------------------------------------------+
bool CTimeEdit::OnClickElement(const string clicked_object)
{
//--- K945<, 5A;8 (1) M;5<5=B 701;>:8@>20= 8;8 (2) GC6>5 8<O >1J5:B0
if(CElementBase::IsLocked() || m_canvas.ChartObjectName()!=clicked_object)
return(false);
//--- A;8 G5:-1>:A =5 8A?>;L7C5BAO
if(!m_checkbox_mode)
return(true);
//--- 5@5:;NG8BL =0 ?@>B82>?>;>6=K9 @568<
IsPressed(!(IsPressed()));
//--- 0@8A>20BL M;5<5=B
Update(true);
//--- B?@028< A>>1I5=85 >1 MB><
::EventChartCustom(m_chart_id,ON_CLICK_CHECKBOX,CElementBase::Id(),CElementBase::Index(),"");
return(true);
}
//+------------------------------------------------------------------+
//| 8AC5B M;5<5=B |
//+------------------------------------------------------------------+
void CTimeEdit::Draw(void)
{
//--- 0@8A>20BL D>=
CElement::DrawBackground();
//--- 0@8A>20BL :0@B8=:C
CTimeEdit::DrawImage();
//--- 0@8A>20BL B5:AB
CElement::DrawText();
}
//+------------------------------------------------------------------+
//| 8AC5B :0@B8=:C |
//+------------------------------------------------------------------+
void CTimeEdit::DrawImage(void)
{
//--- K9B8, 5A;8 (1) G5:-1>:A =5 =C65= 8;8 (2) :0@B8=:0 =5 >?@545;5=0
if(!m_checkbox_mode || CElement::IconFile()=="")
return;
//--- ?@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();
}
//+------------------------------------------------------------------+