EasyAndFastMod/Controls/TreeItem.mqh

225 lines
19 KiB
MQL5
Raw Permalink Normal View History

2026-01-15 07:23:17 -05:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| TreeItem.mqh |
//| Copyright 2015, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#include "..\Element.mqh"
#include "Button.mqh"
//+------------------------------------------------------------------+
//| ;0AA 4;O A>740=8O ?C=:B0 4@52>284=>3> A?8A:0 |
//+------------------------------------------------------------------+
class CTreeItem : public CButton
{
private:
//--- BABC? 4;O AB@5;:8 (?@87=0:0 =0;8G8O A?8A:0)
int m_arrow_x_gap;
//--- "8? ?C=:B0
ENUM_TYPE_TREE_ITEM m_item_type;
//--- =45:A ?C=:B0 2 >1I5< A?8A:5
int m_list_index;
//--- #@>25=L C7;0
int m_node_level;
//--- B>1@0605<K9 B5:AB ?C=:B0
string m_item_text;
//--- !>AB>O=85 A?8A:0 ?C=:B0 (>B:@KB/A2Q@=CB)
bool m_item_state;
//---
public:
CTreeItem(void);
~CTreeItem(void);
//--- 5B>4K 4;O A>740=8O ?C=:B0 4@52>284=>3> A?8A:0
bool CreateTreeItem(const int x_gap,const int y_gap,const ENUM_TYPE_TREE_ITEM type,
const int list_index,const int node_level,const string text,const bool item_state);
//---
private:
void InitializeProperties(const int x_gap,const int y_gap,const ENUM_TYPE_TREE_ITEM type,
const int list_index,const int node_level,const string text,const bool item_state);
//---
public:
//--- (1) !>AB>O=85 ?C=:B0 (A2Q@=CB/@072Q@=CB), (2) B8? ?C=:B0
void ItemState(const int state);
bool ItemState(void) const { return(m_item_state); }
ENUM_TYPE_TREE_ITEM Type(void) const { return(m_item_type); }
//--- BABC? 4;O AB@5;:8
int ArrowXGap(const int node_level);
int ArrowXGap(void) const { return(m_arrow_x_gap); }
//--- 1=>2;5=85 :>>@48=0B 8 H8@8=K
void UpdateX(const int x);
void UpdateY(const int y);
void UpdateWidth(const int width);
//---
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:
//--- 8AC5B :0@B8=:C
virtual void DrawImage(void);
};
//+------------------------------------------------------------------+
//| Constructor |
//+------------------------------------------------------------------+
CTreeItem::CTreeItem(void) : m_node_level(0),
m_arrow_x_gap(5),
m_item_type(TI_SIMPLE)
{
//--- !>E@0=8< 8<O :;0AA0 M;5<5=B0 2 107>2>< :;0AA5
CElementBase::ClassName(CLASS_NAME);
//--- C=:B 1C45B 2K?0;0NI8< M;5<5=B><
CElementBase::IsDropdown(true);
}
//+------------------------------------------------------------------+
//| Destructor |
//+------------------------------------------------------------------+
CTreeItem::~CTreeItem(void)
{
}
//+------------------------------------------------------------------+
//| 1@01>BG8: A>1KB89 |
//+------------------------------------------------------------------+
void CTreeItem::OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
{
//--- K9B8, 5A;8 3;02=K9 M;5<5=B =54>ABC?5=
if(!m_main.CElementBase::IsAvailable())
return;
//--- 1@01>B0BL A>1KB85 2 107>2>< :;0AA5
CButton::OnEvent(id,lparam,dparam,sparam);
}
//+------------------------------------------------------------------+
//| !>740QB ?C=:B 4@52>284=>3> A?8A:0 |
//+------------------------------------------------------------------+
bool CTreeItem::CreateTreeItem(const int x_gap,const int y_gap,const ENUM_TYPE_TREE_ITEM type,
const int list_index,const int node_level,const string text,const bool item_state)
{
//--- 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(x_gap,y_gap,type,list_index,node_level,text,item_state);
//--- #AB0=>28BL :0@B8=:8, 5A;8 ?C=:B 8<55B 2K?040NI89 A?8A>:
if(m_item_type==TI_HAS_ITEMS)
{
CElement::AddImagesGroup(m_arrow_x_gap,2);
CElement::AddImage(1,RESOURCE_DOWN_THICK_BLACK);
CElement::AddImage(1,RESOURCE_RIGHT_THICK_BLACK);
//--- K1@0BL A>>B25BAB2CNI55 87>1@065=85
CButton::ChangeImage(1,(m_item_state)? 1 : 0);
}
//--- !2>9AB20
CButton::TwoState(true);
//--- !>74048< M;5<5=B C?@02;5=8O
if(!CButton::CreateButton(text,x_gap,y_gap))
return(false);
//---
return(true);
}
//+------------------------------------------------------------------+
//| =8F80;870F8O A2>9AB2 |
//+------------------------------------------------------------------+
void CTreeItem::InitializeProperties(const int x_gap,const int y_gap,const ENUM_TYPE_TREE_ITEM type,
const int list_index,const int node_level,const string text,const bool item_state)
{
m_x =CElement::CalculateX(x_gap);
m_y =CElement::CalculateY(y_gap);
m_item_type =type;
m_list_index =list_index;
m_node_level =node_level;
m_item_text =text;
m_item_state =item_state;
m_label_text =text;
//--- !2>9AB20 ?> C<>;G0=8N
m_back_color =m_main.BackColor();
m_back_color_hover =C'229,243,255';
m_back_color_pressed =C'204,232,255';
m_border_color =m_main.BackColor();
m_border_color_hover =m_back_color_hover;
m_border_color_pressed =C'153,209,255';
m_label_color =clrBlack;
m_label_color_hover =clrBlack;
m_label_color_pressed =clrBlack;
m_label_x_gap =(m_label_x_gap!=WRONG_VALUE)? m_icon_x_gap+m_label_x_gap : m_icon_x_gap+22;
m_label_y_gap =4;
//--- BABC?K >B :@09=59 B>G:8
CElementBase::XGap(x_gap);
CElementBase::YGap(y_gap);
}
//+------------------------------------------------------------------+
//| #AB0=>2:0 A>AB>O=8O ?C=:B0 (A2Q@=CB/@072Q@=CB) |
//+------------------------------------------------------------------+
void CTreeItem::ItemState(const int state)
{
m_item_state=state;
}
//+------------------------------------------------------------------+
//| BABC? 4;O AB@5;:8 |
//+------------------------------------------------------------------+
int CTreeItem::ArrowXGap(const int node_level)
{
return((m_arrow_x_gap=(node_level>0)? (12*node_level)+5 : 5));
}
//+------------------------------------------------------------------+
//| 1=>2;5=85 :>>@48=0BK X |
//+------------------------------------------------------------------+
void CTreeItem::UpdateX(const int x)
{
//--- 1=>2;5=85 >1I8E :>>@48=0B 8 >BABC?0 >B :@09=59 B>G:8
CElementBase::X(CElement::CalculateX(x));
CElementBase::XGap(x);
//--- >>@48=0BK 8 >BABC?
m_canvas.X(x);
m_canvas.XGap(x);
}
//+------------------------------------------------------------------+
//| 1=>2;5=85 :>>@48=0BK Y |
//+------------------------------------------------------------------+
void CTreeItem::UpdateY(const int y)
{
//--- 1=>2;5=85 >1I8E :>>@48=0B 8 >BABC?0 >B :@09=59 B>G:8
CElementBase::Y(CElement::CalculateY(y));
CElementBase::YGap(y);
//--- >>@48=0BK 8 >BABC?
m_canvas.Y(y);
m_canvas.YGap(y);
}
//+------------------------------------------------------------------+
//| 1=>2;5=85 H8@8=K |
//+------------------------------------------------------------------+
void CTreeItem::UpdateWidth(const int width)
{
//--- (8@8=0 D>=0
CElementBase::XSize(width);
m_canvas.XSize(width);
m_canvas.Resize(width,m_y_size);
}
//+------------------------------------------------------------------+
//| 8AC5B M;5<5=B |
//+------------------------------------------------------------------+
void CTreeItem::Draw(void)
{
//--- 0@8A>20BL D>=
CButton::DrawBackground();
//--- 0@8A>20BL :0@B8=:C
if(m_item_type==TI_HAS_ITEMS)
CTreeItem::DrawImage();
else
CButton::DrawImage();
//--- 0@8A>20BL B5:AB
CElement::DrawText();
}
//+------------------------------------------------------------------+
//| 8AC5B :0@B8=:C |
//+------------------------------------------------------------------+
void CTreeItem::DrawImage(void)
{
//--- ?@545;8< 8=45:A
uint image_index=(m_item_state)? 0 : 1;
//--- !>E@0=8BL 8=45:A 2K1@0==>3> 87>1@065=8O
CElement::ChangeImage(1,image_index);
//--- 8AC5< :0@B8=:C
CElement::DrawImage();
}
//+------------------------------------------------------------------+