//+------------------------------------------------------------------+ //| CheckGroup.mqh | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #include "WndClient.mqh" #include "CheckBox.mqh" #include #include #include //+------------------------------------------------------------------+ //| Class CCheckGroup | //| Usage: view and edit group of flags | //+------------------------------------------------------------------+ class CCheckGroup : public CWndClient { private: //--- dependent controls CCheckBox m_rows[]; // array of the row objects //--- set up int m_offset; // index of first visible row in array of rows int m_total_view; // number of visible rows int m_item_height; // height of visible row //--- data CArrayString m_strings; // array of rows CArrayLong m_values; // array of values CArrayInt m_states; // array of states long m_value; // current value int m_current; // index of current row in array of rows public: CCheckGroup(void); ~CCheckGroup(void); //--- create virtual bool Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2); virtual void Destroy(const int reason=0); //--- chart event handler virtual bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam); //--- fill virtual bool AddItem(const string item,const long value=0); //--- data long Value(void) const; bool Value(const long value); int Check(const int idx) const; bool Check(const int idx,const int value); //--- state virtual bool Show(void); //--- methods for working with files virtual bool Save(const int file_handle); virtual bool Load(const int file_handle); protected: //--- create dependent controls bool CreateButton(int index); //--- handlers of the dependent controls events virtual bool OnVScrollShow(void); virtual bool OnVScrollHide(void); virtual bool OnScrollLineDown(void); virtual bool OnScrollLineUp(void); virtual bool OnChangeItem(const int row_index); //--- redraw bool Redraw(void); bool RowState(const int index,const bool select); }; //+------------------------------------------------------------------+ //| Common handler of chart events | //+------------------------------------------------------------------+ EVENT_MAP_BEGIN(CCheckGroup) ON_INDEXED_EVENT(ON_CHANGE,m_rows,OnChangeItem) EVENT_MAP_END(CWndClient) //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CCheckGroup::CCheckGroup(void) : m_offset(0), m_total_view(0), m_item_height(CONTROLS_LIST_ITEM_HEIGHT), m_current(CONTROLS_INVALID_INDEX), m_value(0) { } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CCheckGroup::~CCheckGroup(void) { } //+------------------------------------------------------------------+ //| Create a control | //+------------------------------------------------------------------+ bool CCheckGroup::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2) { //--- determine the number of visible rows m_total_view=(y2-y1)/m_item_height; //--- check the number of visible rows if(m_total_view<1) return(false); //--- call method of the parent class if(!CWndClient::Create(chart,name,subwin,x1,y1,x2,y2)) return(false); //--- set up if(!m_background.ColorBackground(CONTROLS_CHECKGROUP_COLOR_BG)) return(false); if(!m_background.ColorBorder(CONTROLS_CHECKGROUP_COLOR_BORDER)) return(false); //--- create dependent controls ArrayResize(m_rows,m_total_view); for(int i=0;i=m_values.Total()) return(0); //--- return(m_states[idx]); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool CCheckGroup::Check(const int idx,const int value) { //--- check if(idx>=m_values.Total()) return(false); //--- bool res=(m_states.Update(idx,value) && Redraw()); //--- change value if(res && idx<64) { if(m_rows[idx].Checked()) Value(m_value|m_values.At(idx)); else Value(m_value&(~m_values.At(idx))); } //--- return(res); } //+------------------------------------------------------------------+ //| Makes the group visible | //+------------------------------------------------------------------+ bool CCheckGroup::Show(void) { //--- call of the method of the parent class if(!CWndClient::Show()) return(false); //--- loop by rows int total=m_values.Total(); for(int i=total;i=ArraySize(m_rows)) return(true); //--- change state return(m_rows[index].Checked(select)); } //+------------------------------------------------------------------+ //| Handler of the "Show vertical scrollbar" event | //+------------------------------------------------------------------+ bool CCheckGroup::OnVScrollShow(void) { //--- loop by "rows" for(int i=0;i