Objects Panel

Author: Copyright © 2021, Vladimir Karputov
0 Views
0 Downloads
0 Favorites
Objects Panel
ÿþ//+------------------------------------------------------------------+

//|                                                Objects Panel.mq5 |

//|                              Copyright © 2021, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43161 |

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

#property copyright "Copyright © 2021, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43161"

#property version   "1.000"

#property indicator_chart_window

#property indicator_buffers 0

#property indicator_plots   0

//--

#include <Controls\Dialog.mqh>

#include <Controls\Picture.mqh>

#include <Controls\CheckBox.mqh>

#include <Arrays\ArrayObj.mqh>

//---

string m_description_array[44][2]= {{"Vertical Line","vertical_line.bmp"},

     {"Horizontal Line","horizonal_line.bmp"},

     {"Trend Line","trend_line.bmp"},

     {"Trend Line By Angle","trend_line)by_angle.bmp"},

     {"Cycle Lines","cycle_lines.bmp"},

     {"Arrowed Line","arrowed_line.bmp"},

     {"Equidistant Channel","equidistance_channel.bmp"},

     {"Standard Deviation Channel","stddeviation_channel.bmp"},

     {"Linear Regression Channel","regression_channel.bmp"},

     {"Andrews  Pitchfork","andrewspitchfork.bmp"},

     {"Gann Line","gann_line.bmp"},

     {"Gann Fan","gann_fan.bmp"},

     {"Gann Grid","gann_grid.bmp"},

     {"Fibonacci Retracement","fibonacci_levels.bmp"},

     {"Fibonacci Time Zones","fibonacci_time_zones.bmp"},

     {"Fibonacci Fan","fibo_fan.bmp"},

     {"Fibonacci Arcs","fibo_arc.bmp"},

     {"Fibonacci Channel","fibo_channel.bmp"},

     {"Fibonacci Expansion","fibo_expansion.bmp"},

     {"Elliott Motive Wave","elliot_impuls.bmp"},

     {"Elliott Correction Wave","elliot_correction.bmp"},

     {"Rectangle","rectangle.bmp"},

     {"Triangle","triangle.bmp"},

     {"Ellipse","ellipse.bmp"},

     {"Thumbs Up","thumb_up.bmp"},

     {"Thumbs Down","thumb_down.bmp"},

     {"Arrow Up","arrow_up.bmp"},

     {"Arrow Down","arrow_down.bmp"},

     {"Stop Sign","stop_signal.bmp"},

     {"Check Sign","check_signal.bmp"},

     {"Left Price Label","left_price_label.bmp"},

     {"Right Price Label","right_price_label.bmp"},

     {"Buy Sign","buy_sign_icon.bmp"},

     {"Sell Sign","sell_sign_icon.bmp"},

     {"Arrow","arrow_symbol.bmp"},

     {"Text","text_object.bmp"},

     {"Label","label_object.bmp"},

     {"Button","button_object.bmp"},

     {"Chart","chart_object.bmp"},

     {"Bitmap","picture_object.bmp"},

     {"Bitmap Label","bitmap_object.bmp"},

     {"Edit","edit_object.bmp"},

     {"Event object","obj_event.bmp"},

     {"Rectangle label","rectangle_label.bmp"}

  };

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

//| defines                                                          |

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

//--- indents and gaps

#define INDENT_LEFT                         (11)      // indent from left (with allowance for border width)

#define INDENT_TOP                          (11)      // indent from top (with allowance for border width)

#define CONTROLS_GAP_X                      (5)       // gap by X coordinate

#define CONTROLS_GAP_Y                      (5)       // gap by Y coordinate

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

//| Class CControlsDialog                                            |

//| Usage: main dialog of the Controls application                   |

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

class CControlsDialog : public CAppDialog

  {

private:

   CArrayObj         m_array_check_box_obj;

   CArrayObj         m_array_picture_obj;

   CCheckBox         *m_check_box;

   CPicture          *m_picture;





public:

                     CControlsDialog(void);

                    ~CControlsDialog(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);

   //--- chart event handler

   virtual bool      OnEvent(const int id,const long &lparam,const double &dparam,const string &sparam);



protected:

   //--- create dependent controls

   bool              CreateCheckBox(CCheckBox &check_box,const string name,const int x1,const int y1,const int x2,const int y2);

   bool              CreatePicture(CPicture &picture,const string name,const string picture_name,const int x1,const int y1,const int x2,const int y2);

   //--- handlers of the dependent controls events

   void              OnChangeCheckBox(CCheckBox &check_box);

  };

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

//| Event Handling                                                   |

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

bool CControlsDialog::OnEvent(const int id,const long& lparam,const double& dparam,const string& sparam)

  {

   if(id==(ON_CHANGE+CHARTEVENT_CUSTOM))

     {

      int size=m_array_check_box_obj.Total();

      for(int i=0; i<size; i++)

        {

         m_check_box=m_array_check_box_obj.At(i);

         if(lparam==m_check_box.Id())

           {

            OnChangeCheckBox(m_check_box);

            return(true);

           }

        }

     }

   return(CAppDialog::OnEvent(id,lparam,dparam,sparam));

  }

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

//| Constructor                                                      |

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

CControlsDialog::CControlsDialog(void)

  {

  }

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

//| Destructor                                                       |

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

CControlsDialog::~CControlsDialog(void)

  {

  }

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

//| Create                                                           |

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

bool CControlsDialog::Create(const long chart,const string name,const int subwin,const int x1,const int y1,const int x2,const int y2)

  {

   if(!CAppDialog::Create(chart,name,subwin,x1,y1,x2,y2))

      return(false);

//--- create dependent controls

   int obj_x1=0,obj_y1=0,obj_x2=0,obj_y2=0,row=1;

   for(int i=0; i<44; i++)

     {

      m_check_box=new CCheckBox;

      m_picture=new CPicture;

      if(m_check_box==NULL || m_picture==NULL)

        {

         printf("Object create error");

         return(false);

        }

      obj_x1=INDENT_LEFT;

      obj_y1=INDENT_TOP;

      //---

      int k=i%11;

      if(k==0)

         row++;

      obj_x1=INDENT_LEFT+k*70;

      obj_y1=INDENT_TOP+(row-2)*20;

      obj_x2=obj_x1+20;

      obj_y2=obj_y1+20;

      //---

      if(!CreateCheckBox(m_check_box,m_description_array[i][0],obj_x1,obj_y1,obj_x2,obj_y2))

         return(false);

      if(!CreatePicture(m_picture,m_description_array[i][0],m_description_array[i][1],obj_x1+25,obj_y1,obj_x2,obj_y2))

         return(false);

      m_array_check_box_obj.Add(m_check_box);

      m_array_picture_obj.Add(m_picture);

     }

//--- succeed

   return(true);

  }

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

//| Create the "CheckBox" element                                    |

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

bool CControlsDialog::CreateCheckBox(CCheckBox &check_box,const string name,const int x1,const int y1,const int x2,const int y2)

  {

//--- create

   if(!check_box.Create(m_chart_id,m_name+name,m_subwin,x1,y1,x2,y2))

      return(false);

   if(!check_box.Text(name))

      return(false);

   if(!check_box.Color(clrBlue))

      return(false);

   if(!Add(check_box))

      return(false);

//--- succeed

   return(true);

  }

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

//| Create the "Picture" element                                     |

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

bool CControlsDialog::CreatePicture(CPicture &picture,const string name,const string picture_name,const int x1,const int y1,const int x2,const int y2)

  {

//--- create

   if(!picture.Create(m_chart_id,m_name+name,m_subwin,x1,y1,x2,y2))

      return(false);

//--- sets the name of bmp file of the control CBmpButton

   picture.BmpName("\\Images\\Object Types\\"+picture_name);

   if(!Add(picture))

      return(false);

//--- succeed

   return(true);

  }

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

//| Event handler                                                    |

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

void CControlsDialog::OnChangeCheckBox(CCheckBox &check_box)

  {

   Comment(__FUNCTION__+" "+check_box.Name()+" : Checked="+IntegerToString(check_box.Checked()));

  }

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

//| Global Variables                                                 |

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

CControlsDialog ExtDialog;

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

//--- create application dialog

   if(!ExtDialog.Create(0,"Object Types",0,40,40,827,169))

      return(INIT_FAILED);

//--- run application

   ExtDialog.Run();

//---

   return(INIT_SUCCEEDED);

  }

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

//| Custom indicator deinitialization function                       |

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

void OnDeinit(const int reason)

  {

//---

   Comment("");

//--- destroy dialog

   ExtDialog.Destroy(reason);

  }

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

//| Custom indicator iteration function                              |

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

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//---

//--- return value of prev_calculated for next call

   return(rates_total);

  }

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

//| Custom indicator chart event function                                      |

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

void OnChartEvent(const int id,         // event ID

                  const long& lparam,   // event parameter of the long type

                  const double& dparam, // event parameter of the double type

                  const string& sparam) // event parameter of the string type

  {

   ExtDialog.ChartEvent(id,lparam,dparam,sparam);

  }

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



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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---