Guest User

SimpleDialog.mqh

a guest
Mar 5th, 2015
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.42 KB | None | 0 0
  1. //+------------------------------------------------------------------+
  2. //|                                                  PanelDialog.mqh |
  3. //|                   Copyright 2009-2014, MetaQuotes Software Corp. |
  4. //|                                              http://www.mql5.com |
  5. //+------------------------------------------------------------------+
  6. #include <Controls\Dialog.mqh>
  7. #include <Controls\Button.mqh>
  8. #include <Controls\Edit.mqh>
  9. #include <Controls\ListView.mqh>
  10. #include <Controls\ComboBox.mqh>
  11. #include <Controls\SpinEdit.mqh>
  12. #include <Controls\RadioGroup.mqh>
  13. #include <Controls\CheckGroup.mqh>
  14. //+------------------------------------------------------------------+
  15. //| defines                                                          |
  16. //+------------------------------------------------------------------+
  17. //--- indents and gaps
  18. #define INDENT_LEFT                         (11)      // indent from left (with allowance for border width)
  19. #define INDENT_TOP                          (11)      // indent from top (with allowance for border width)
  20. #define INDENT_RIGHT                        (11)      // indent from right (with allowance for border width)
  21. #define INDENT_BOTTOM                       (11)      // indent from bottom (with allowance for border width)
  22. #define CONTROLS_GAP_X                      (10)      // gap by X coordinate
  23. #define CONTROLS_GAP_Y                      (10)      // gap by Y coordinate
  24. //--- for buttons
  25. #define BUTTON_WIDTH                        (100)     // size by X coordinate
  26. #define BUTTON_HEIGHT                       (20)      // size by Y coordinate
  27. //--- for the indication area
  28. #define EDIT_HEIGHT                         (20)      // size by Y coordinate
  29. //+------------------------------------------------------------------+
  30. //| Class CPanelDialog                                               |
  31. //| Usage: main dialog of the SimplePanel application                |
  32. //+------------------------------------------------------------------+
  33. class CPanelDialog : public CAppDialog
  34.   {
  35. private:
  36.    CEdit             m_edit;                          // the display field object
  37.    CButton           m_button1;                       // the button object
  38.    CButton           m_button2;                       // the button object
  39.    CButton           m_button3;                       // the fixed button object
  40.    CListView         m_list_view;                     // the list object
  41.    CRadioGroup       m_radio_group;                   // the radio buttons group object
  42.    CCheckGroup       m_check_group;                   // the check box group object
  43.  
  44. public:
  45.                      CPanelDialog(void);
  46.                     ~CPanelDialog(void);
  47.    //--- create
  48.    virtual bool      Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2);
  49.    //--- chart event handler
  50.    virtual bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);
  51.  
  52. protected:
  53.    //--- create dependent controls
  54.    bool              CreateEdit(void);
  55.    bool              CreateButton1(void);
  56.    bool              CreateButton2(void);
  57.    bool              CreateButton3(void);
  58.    bool              CreateRadioGroup(void);
  59.    bool              CreateCheckGroup(void);
  60.    bool              CreateListView(void);
  61.    //--- internal event handlers
  62.    virtual bool      OnResize(void);
  63.    //--- handlers of the dependent controls events
  64.    void              OnClickButton1(void);
  65.    void              OnClickButton2(void);
  66.    void              OnClickButton3(void);
  67.    void              OnChangeRadioGroup(void);
  68.    void              OnChangeCheckGroup(void);
  69.    void              OnChangeListView(void);
  70.   };
  71. //+------------------------------------------------------------------+
  72. //| Event Handling                                                   |
  73. //+------------------------------------------------------------------+
  74. EVENT_MAP_BEGIN(CPanelDialog)
  75.    ON_EVENT(ON_CLICK,m_button1,OnClickButton1)
  76.    ON_EVENT(ON_CLICK,m_button2,OnClickButton2)
  77.    ON_EVENT(ON_CLICK,m_button3,OnClickButton3)
  78.    ON_EVENT(ON_CHANGE,m_radio_group,OnChangeRadioGroup)
  79.    ON_EVENT(ON_CHANGE,m_check_group,OnChangeCheckGroup)
  80.    ON_EVENT(ON_CHANGE,m_list_view,OnChangeListView)
  81. EVENT_MAP_END(CAppDialog)
  82. //+------------------------------------------------------------------+
  83. //| Constructor                                                      |
  84. //+------------------------------------------------------------------+
  85. CPanelDialog::CPanelDialog(void)
  86.   {
  87.   }
  88. //+------------------------------------------------------------------+
  89. //| Destructor                                                       |
  90. //+------------------------------------------------------------------+
  91. CPanelDialog::~CPanelDialog(void)
  92.   {
  93.   }
  94. //+------------------------------------------------------------------+
  95. //| Create                                                           |
  96. //+------------------------------------------------------------------+
  97. bool CPanelDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)
  98.   {
  99.    if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))
  100.       return(false);
  101. //--- create dependent controls
  102.    if(!CreateEdit())
  103.       return(false);
  104.    if(!CreateButton1())
  105.       return(false);
  106.    if(!CreateButton2())
  107.       return(false);
  108.    if(!CreateButton3())
  109.       return(false);
  110.    if(!CreateRadioGroup())
  111.       return(false);
  112.    if(!CreateCheckGroup())
  113.       return(false);
  114.    if(!CreateListView())
  115.       return(false);
  116. //--- succeed
  117.    return(true);
  118.   }
  119. //+------------------------------------------------------------------+
  120. //| Create the display field                                         |
  121. //+------------------------------------------------------------------+
  122. bool CPanelDialog::CreateEdit(void)
  123.   {
  124. //--- coordinates
  125.    int x1=INDENT_LEFT;
  126.    int y1=INDENT_TOP;
  127.    int x2=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
  128.    int y2=y1+EDIT_HEIGHT;
  129. //--- create
  130.    if(!m_edit.Create(m_chart_id,m_name+"Edit",m_subwin,x1,y1,x2,y2))
  131.       return(false);
  132.    if(!m_edit.ReadOnly(true))
  133.       return(false);
  134.    if(!Add(m_edit))
  135.       return(false);
  136.    m_edit.Alignment(WND_ALIGN_WIDTH,INDENT_LEFT,0,INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X,0);
  137. //--- succeed
  138.    return(true);
  139.   }
  140. //+------------------------------------------------------------------+
  141. //| Create the "Button1" button                                      |
  142. //+------------------------------------------------------------------+
  143. bool CPanelDialog::CreateButton1(void)
  144.   {
  145. //--- coordinates
  146.    int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH);
  147.    int y1=INDENT_TOP;
  148.    int x2=x1+BUTTON_WIDTH;
  149.    int y2=y1+BUTTON_HEIGHT;
  150. //--- create
  151.    if(!m_button1.Create(m_chart_id,m_name+"Button1",m_subwin,x1,y1,x2,y2))
  152.       return(false);
  153.    if(!m_button1.Text("Button1"))
  154.       return(false);
  155.    if(!Add(m_button1))
  156.       return(false);
  157.    m_button1.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
  158. //--- succeed
  159.    return(true);
  160.   }
  161. //+------------------------------------------------------------------+
  162. //| Create the "Button2" button                                      |
  163. //+------------------------------------------------------------------+
  164. bool CPanelDialog::CreateButton2(void)
  165.   {
  166. //--- coordinates
  167.    int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH);
  168.    int y1=INDENT_TOP+BUTTON_HEIGHT+CONTROLS_GAP_Y;
  169.    int x2=x1+BUTTON_WIDTH;
  170.    int y2=y1+BUTTON_HEIGHT;
  171. //--- create
  172.    if(!m_button2.Create(m_chart_id,m_name+"Button2",m_subwin,x1,y1,x2,y2))
  173.       return(false);
  174.    if(!m_button2.Text("Button2"))
  175.       return(false);
  176.    if(!Add(m_button2))
  177.       return(false);
  178.    m_button2.Alignment(WND_ALIGN_RIGHT,0,0,INDENT_RIGHT,0);
  179. //--- succeed
  180.    return(true);
  181.   }
  182. //+------------------------------------------------------------------+
  183. //| Create the "Button3" fixed button                                |
  184. //+------------------------------------------------------------------+
  185. bool CPanelDialog::CreateButton3(void)
  186.   {
  187. //--- coordinates
  188.    int x1=ClientAreaWidth()-(INDENT_RIGHT+BUTTON_WIDTH);
  189.    int y1=ClientAreaHeight()-(INDENT_BOTTOM+BUTTON_HEIGHT);
  190.    int x2=x1+BUTTON_WIDTH;
  191.    int y2=y1+BUTTON_HEIGHT;
  192. //--- create
  193.    if(!m_button3.Create(m_chart_id,m_name+"Button3",m_subwin,x1,y1,x2,y2))
  194.       return(false);
  195.    if(!m_button3.Text("Locked"))
  196.       return(false);
  197.    if(!Add(m_button3))
  198.       return(false);
  199.    m_button3.Locking(true);
  200.    m_button3.Alignment(WND_ALIGN_RIGHT|WND_ALIGN_BOTTOM,0,0,INDENT_RIGHT,INDENT_BOTTOM);
  201. //--- succeed
  202.    return(true);
  203.   }
  204. //+------------------------------------------------------------------+
  205. //| Create the "RadioGroup" element                                  |
  206. //+------------------------------------------------------------------+
  207. bool CPanelDialog::CreateRadioGroup(void)
  208.   {
  209.    int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
  210. //--- coordinates
  211.    int x1=INDENT_LEFT;
  212.    int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
  213.    int x2=x1+sx;
  214.    int y2=ClientAreaHeight()-INDENT_BOTTOM;
  215. //--- create
  216.    if(!m_radio_group.Create(m_chart_id,m_name+"RadioGroup",m_subwin,x1,y1,x2,y2))
  217.       return(false);
  218.    if(!Add(m_radio_group))
  219.       return(false);
  220.    m_radio_group.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
  221. //--- fill out with strings
  222.    for(int i=0;i<4;i++)
  223.       if(!m_radio_group.AddItem("Item "+IntegerToString(i),1<<i))
  224.          return(false);
  225. //--- succeed
  226.    return(true);
  227.   }
  228. //+------------------------------------------------------------------+
  229. //| Create the "CheckGroup" element                                  |
  230. //+------------------------------------------------------------------+
  231. bool CPanelDialog::CreateCheckGroup(void)
  232.   {
  233.    int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
  234. //--- coordinates
  235.    int x1=INDENT_LEFT+sx+CONTROLS_GAP_X;
  236.    int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
  237.    int x2=x1+sx;
  238.    int y2=ClientAreaHeight()-INDENT_BOTTOM;
  239. //--- create
  240.    if(!m_check_group.Create(m_chart_id,m_name+"CheckGroup",m_subwin,x1,y1,x2,y2))
  241.       return(false);
  242.    if(!Add(m_check_group))
  243.       return(false);
  244.    m_check_group.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
  245. //--- fill out with strings
  246.    for(int i=0;i<4;i++)
  247.       if(!m_check_group.AddItem("Item "+IntegerToString(i),1<<i))
  248.          return(false);
  249. //--- succeed
  250.    return(true);
  251.   }
  252. //+------------------------------------------------------------------+
  253. //| Create the "ListView" element                                    |
  254. //+------------------------------------------------------------------+
  255. bool CPanelDialog::CreateListView(void)
  256.   {
  257.    int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
  258. //--- coordinates
  259.    int x1=ClientAreaWidth()-(sx+INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
  260.    int y1=INDENT_TOP+EDIT_HEIGHT+CONTROLS_GAP_Y;
  261.    int x2=x1+sx;
  262.    int y2=ClientAreaHeight()-INDENT_BOTTOM;
  263. //--- create
  264.    if(!m_list_view.Create(m_chart_id,m_name+"ListView",m_subwin,x1,y1,x2,y2))
  265.       return(false);
  266.    if(!Add(m_list_view))
  267.       return(false);
  268.    m_list_view.Alignment(WND_ALIGN_HEIGHT,0,y1,0,INDENT_BOTTOM);
  269. //--- fill out with strings
  270.    for(int i=0;i<16;i++)
  271.       if(!m_list_view.ItemAdd("Item "+IntegerToString(i)))
  272.          return(false);
  273. //--- succeed
  274.    return(true);
  275.   }
  276. //+------------------------------------------------------------------+
  277. //| Handler of resizing                                              |
  278. //+------------------------------------------------------------------+
  279. bool CPanelDialog::OnResize(void)
  280.   {
  281. //--- call method of parent class
  282.    if(!CAppDialog::OnResize()) return(false);
  283. //--- coordinates
  284.    int x=ClientAreaLeft()+INDENT_LEFT;
  285.    int y=m_radio_group.Top();
  286.    int sx=(ClientAreaWidth()-(INDENT_LEFT+INDENT_RIGHT+BUTTON_WIDTH))/3-CONTROLS_GAP_X;
  287. //--- move and resize the "RadioGroup" element
  288.    m_radio_group.Move(x,y);
  289.    m_radio_group.Width(sx);
  290. //--- move and resize the "CheckGroup" element
  291.    x=ClientAreaLeft()+INDENT_LEFT+sx+CONTROLS_GAP_X;
  292.    m_check_group.Move(x,y);
  293.    m_check_group.Width(sx);
  294. //--- move and resize the "ListView" element
  295.    x=ClientAreaLeft()+ClientAreaWidth()-(sx+INDENT_RIGHT+BUTTON_WIDTH+CONTROLS_GAP_X);
  296.    m_list_view.Move(x,y);
  297.    m_list_view.Width(sx);
  298. //--- succeed
  299.    return(true);
  300.   }
  301. //+------------------------------------------------------------------+
  302. //| Event handler                                                    |
  303. //+------------------------------------------------------------------+
  304. void CPanelDialog::OnClickButton1(void)
  305.   {
  306.    m_edit.Text(__FUNCTION__);
  307.   }
  308. //+------------------------------------------------------------------+
  309. //| Event handler                                                    |
  310. //+------------------------------------------------------------------+
  311. void CPanelDialog::OnClickButton2(void)
  312.   {
  313.    m_edit.Text(__FUNCTION__);
  314.   }
  315. //+------------------------------------------------------------------+
  316. //| Event handler                                                    |
  317. //+------------------------------------------------------------------+
  318. void CPanelDialog::OnClickButton3(void)
  319.   {
  320.    if(m_button3.Pressed())
  321.       m_edit.Text(__FUNCTION__+"On");
  322.    else
  323.       m_edit.Text(__FUNCTION__+"Off");
  324.   }
  325. //+------------------------------------------------------------------+
  326. //| Event handler                                                    |
  327. //+------------------------------------------------------------------+
  328. void CPanelDialog::OnChangeListView(void)
  329.   {
  330.    m_edit.Text(__FUNCTION__+" \""+m_list_view.Select()+"\"");
  331.   }
  332. //+------------------------------------------------------------------+
  333. //| Event handler                                                    |
  334. //+------------------------------------------------------------------+
  335. void CPanelDialog::OnChangeRadioGroup(void)
  336.   {
  337.    m_edit.Text(__FUNCTION__+" : Value="+IntegerToString(m_radio_group.Value()));
  338.   }
  339. //+------------------------------------------------------------------+
  340. //| Event handler                                                    |
  341. //+------------------------------------------------------------------+
  342. void CPanelDialog::OnChangeCheckGroup(void)
  343.   {
  344.    m_edit.Text(__FUNCTION__+" : Value="+IntegerToString(m_check_group.Value()));
  345.   }
  346. //+------------------------------------------------------------------+
Advertisement
Add Comment
Please, Sign In to add comment