Does anyone know how to fix this annoying events problem in the GUI Library?

 

In many projects I've come a cross this issue where the events start playing up if you introduce more than one panel. 

In some cases I would like a dialog popup to change some settings/get user input/display detailed info etc.

Please does anyone know the fix for this?

Here is a test panel, test env included...




class Main: public CAppDialog {
   private:
      CButton _btn1;
      CButton _btn2;
      
      PopupWindow _popupWind;
      
      bool CreateMainWnd();
      bool CreateBtns();
      bool CreatePopupWnd();
      
      void OnBtn1Click();
      void OnBtn2Click();
      
   public:
      Main();
      ~Main();
      
      bool Create(const string title);
      void Destroy(const int reason) override;
      
      bool OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam) override;
      
      void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
      
      void OnTicketDialogSubmit();
      
};
//+------------------------------------------------------------------+

Main::Main(
   
) : CAppDialog() {

}


Main::~Main() {  
   
}


void Main::Destroy(const int reason) override {   
   _popupWind.Destroy(reason);
   CAppDialog::Destroy(reason);   
}



void Main::OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) {
    ChartEvent(id, lparam, dparam, sparam);
    _popupWind.OnEvent(id, lparam, dparam, sparam);   
}



EVENT_MAP_BEGIN(Main)
   ON_EVENT(ON_CLICK,_btn1,OnBtn1Click)
   ON_EVENT(ON_CLICK,_btn2,OnBtn2Click)
EVENT_MAP_END(CAppDialog)


//+------------------------------------------------------------------+


bool Main::Create(const string title) {   
   
   int x = 50, y = x;
   
   if( !CAppDialog::Create(0, title, 0, 
      50,
      50,
      x + 500,
      y + 500
   )) { 
      printf("Failed to create App Dialog window");
      return false;
   }
   
   
   if( !CreateBtns() ) { 
      printf("Failed to create test btns");
      return false;
   }
   
   
   if( !CreatePopupWnd() ) {
      return false;
   }
   
   return true;
}



bool Main::CreateBtns() {
   const int btnWidth = 120;
   const int btnHeight = 30;
   
   bool result = true;
   result &= _btn1.Create(0, "test_btn_1", 0, 
      10,
      20,
      10 + btnWidth,
      20 + btnHeight
   );
   
   _btn1.Text("Open Dialog");
   
   Add(_btn1);
   
   result &= _btn2.Create(0, "test_btn_2", 0, 
      ( _btn1.Right() - ClientAreaLeft() ) + 10,
      20,
      ( _btn1.Right() - ClientAreaLeft() ) + 10 + btnWidth,
      20 + btnHeight
   );
   
   _btn2.Text("Btn 2");
   
   Add(_btn2);
   
   return result;
}


bool Main::CreatePopupWnd() {

   int width = 500;
   int height = 300;
   
   int screenw = (int) ChartGetInteger(0,CHART_WIDTH_IN_PIXELS);
   int screenh = (int) ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS);
   
   int x = (screenw/2) - (width/2);
   int y = (screenh/2) - (height/2);
   
   if( screenw < width || screenh < height ) {
      x = 10;
      y = 10;
   }
   
   bool result = _popupWind.Create(0, "Popup_wnd_dialog", 0,
      x, y,
      x+width,
      y+height
   );
   
   _popupWind.Caption("Popup window with event problem");
   return result;
}



void Main::OnBtn1Click() {
   _popupWind.Show();
}



void Main::OnBtn2Click() {
   Alert("Btn 2 clicked");
}


void Main::OnTicketDialogSubmit() {

   Alert("Ticket Dialog Submitted");
}


The rest of the code you can find in the zip file attached ready to go to test in mt5.

Files:
UI_Problem.zip  236 kb