//+------------------------------------------------------------------+ //| RadioGroup.mqh | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #include "WndClient.mqh" #include "RadioButton.mqh" #include #include //+------------------------------------------------------------------+ //| Class CRadioGroup | //| Usage: view and edit radio buttons | //+------------------------------------------------------------------+ class CRadioGroup : public CWndClient { private: //--- dependent controls CRadioButton 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 int m_current; // index of current row in array of rows public: CRadioGroup(void); ~CRadioGroup(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 { return(m_values.At(m_current)); } bool Value(const long value); bool ValueCheck(long value) const; //--- 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(const 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); void Select(const int index); }; //+------------------------------------------------------------------+ //| Common handler of chart events | //+------------------------------------------------------------------+ EVENT_MAP_BEGIN(CRadioGroup) ON_INDEXED_EVENT(ON_CHANGE,m_rows,OnChangeItem) EVENT_MAP_END(CWndClient) //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CRadioGroup::CRadioGroup(void) : m_offset(0), m_total_view(0), m_item_height(CONTROLS_LIST_ITEM_HEIGHT), m_current(CONTROLS_INVALID_INDEX) { } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CRadioGroup::~CRadioGroup(void) { } //+------------------------------------------------------------------+ //| Create a control | //+------------------------------------------------------------------+ bool CRadioGroup::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_RADIOGROUP_COLOR_BG)) return(false); if(!m_background.ColorBorder(CONTROLS_RADIOGROUP_COLOR_BORDER)) return(false); //--- create dependent controls ArrayResize(m_rows,m_total_view); for(int i=0;i=ArraySize(m_rows)) return(true); //--- change state return(m_rows[index].State(select)); } //+------------------------------------------------------------------+ //| Handler of the "Show vertical scrollbar" event | //+------------------------------------------------------------------+ bool CRadioGroup::OnVScrollShow(void) { //--- loop by "rows" for(int i=0;i