//+------------------------------------------------------------------+ //| WndContainer.mqh | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #include "Wnd.mqh" #include //+------------------------------------------------------------------+ //| Class CWndContainer | //| Usage: base class of the combined control | //+------------------------------------------------------------------+ class CWndContainer : public CWnd { private: CArrayObj m_controls; // container of the control public: CWndContainer(void); ~CWndContainer(void); //--- release memory 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); virtual bool OnMouseEvent(const int x,const int y,const int flags); //--- access the contents of container int ControlsTotal(void) const { return(m_controls.Total()); } CWnd* Control(const int ind) const { return(dynamic_cast(m_controls.At(ind))); } virtual CWnd* ControlFind(const long id); //--- for mouse cursor focus virtual bool MouseFocusKill(const long id=-1); //--- fill bool Add(CWnd *control); bool Add(CWnd &control); //--- underflowing bool Delete(CWnd *control); bool Delete(CWnd &control); //--- geometry virtual bool Move(const int x,const int y); virtual bool Move(const CPoint &point); virtual bool Shift(const int dx,const int dy); //--- ID virtual long Id(const long id); long Id(void) const { return(CWnd::Id()); } //--- state virtual bool Enable(void); virtual bool Disable(void); virtual bool Show(void); virtual bool Hide(void); //--- methods for working with files virtual bool Save(const int file_handle); virtual bool Load(const int file_handle); protected: //--- internal event handlers virtual bool OnResize(void); virtual bool OnActivate(void); virtual bool OnDeactivate(void); }; //+------------------------------------------------------------------+ //| Common handler of chart events | //+------------------------------------------------------------------+ bool CWndContainer::OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam) { //--- if an object is being dragged, pass control to the special drag object if(m_drag_object!=NULL && m_drag_object.OnEvent(id,lparam,dparam,sparam)) return(true); //--- loop by elements of group int total=m_controls.Total(); for(int i=total-1;i>=0;i--) { CWnd *control=Control(i); //--- check of pointer if(control==NULL) continue; if(control.OnEvent(id,lparam,dparam,sparam)) return(true); } //--- not handled return(false); } //+------------------------------------------------------------------+ //| Common handler of mouse events | //+------------------------------------------------------------------+ bool CWndContainer::OnMouseEvent(const int x,const int y,const int flags) { if(!IS_VISIBLE) return(false); //--- if an object is being dragged, pass control to the special drag object if(m_drag_object!=NULL && m_drag_object.OnMouseEvent(x,y,flags)) return(true); //--- loop by elements of group int total=m_controls.Total(); for(int i=total-1;i>=0;i--) { CWnd *control=Control(i); //--- check of pointer if(control==NULL) continue; if(control.OnMouseEvent(x,y,flags)) return(true); } //--- call of the method of the parent class return(CWnd::OnMouseEvent(x,y,flags)); } //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ CWndContainer::CWndContainer(void) { } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ CWndContainer::~CWndContainer(void) { } //+------------------------------------------------------------------+ //| Delete group of controls | //+------------------------------------------------------------------+ void CWndContainer::Destroy(const int reason) { //--- loop by elements of group int total=m_controls.Total(); for(int i=0;i