EA-Setka-2/Libs/MQL5Trace/View/PropertyView.mqh

183 lines
15 KiB
MQL5
Raw Permalink Normal View History

2025-05-30 14:50:44 +02:00
<EFBFBD><EFBFBD>//+------------------------------------------------------------------+
//| PropertyView |
//| Copyright 2006-2011, www.FXmaster.de |
//| www.FXmaster.de |
//+------------------------------------------------------------------+
#property copyright "Copyright 2006-2011, www.FXmaster.de"
#property link "www.FXmaster.de"
#property version "1.00"
#include "TreeView.mqh"
#ifndef REPORT_BROWSER
#import "shell32.dll"
int ShellExecuteW(int hwnd, string &lpOperation, string &lpFile, string &lpParameters, string &lpDirectory, int nShowCmd);
#import
#endif
#define SW_SHOWNORMAL 1
#define SW_SHOWMINIMIZED 2
#define ERROR_BAD_FORMAT 11
#define ERROR_FILE_NOT_FOUND 2
#define ERROR_PATH_NOT_FOUND 3
//------------------------------------------------------------------ class CPropertyView
class CPropertyView: public CTreeView
{
//--- 107>2K5 DC=:F88
public:
CPropertyView(); // :>=AB@C:B>@
~CPropertyView(); // 45AB@C:B>@
virtual void Create(long chart, string name, int wnd, color clr, color bgclr, color selclr, int x, int y, int dx, int dy, int corn=0, int fontsize=8, string font="Arial");
//--- DC=:F88 >1@01>B:8 A>AB>O=8O
public:
virtual int OnClick(string name); // >1@01>B:0 A>1KB8O :;8:0 =0 >1J5:B5
//--- DC=:F88 >B>1@065=8O
public:
virtual void Draw(); // >1=>28BL 284
virtual void DrawTree(CNode *root, int xpos, int &ypos, int &up, int &dn);
virtual void DrawNode(CNode *node, int x, int y); // >B@8A>20BL C75;
virtual void DeleteView(CNode *root=NULL, bool delparent=true); // C40;O5< >B>1@065=85
};
//------------------------------------------------------------------ CPropertyView
void CPropertyView::CPropertyView() { }
//------------------------------------------------------------------ ~CPropertyView
void CPropertyView::~CPropertyView()
{
ObjectDelete(m_chart, m_name+".open");
DeleteView();
}
//------------------------------------------------------------------ Create
void CPropertyView::Create(long achart, string name, int wnd, color clr, color bgclr, color selclr, int x, int y, int dx, int dy, int corn=0, int fontsize=8, string font="Arial")
{
CTreeView::Create(achart, name, wnd, clr, bgclr, selclr, x, y, dx, dy, corn, fontsize, font);
}
//------------------------------------------------------------------ OnClick
int CPropertyView::OnClick(string name) // 8<O >1J5:B0 =0 :>B>@K9 :;8:=C;8
{
int start=StringLen(m_name); int len=StringFind(name, ".")-start;
int id=(int)StringToInteger(StringSubstr(name, start, len));
if (StringFind(name, ".open")>=0)
{
ObjectSetInteger(m_chart, name, OBJPROP_STATE, false);
string path=m_tree.m_root.m_path;
string cmd="open"; string nil="";
int hWnd=(int)ChartGetInteger(m_chart, CHART_WINDOW_HANDLE);
int rez=ShellExecuteW(hWnd, cmd, path, nil, nil, SW_SHOWNORMAL);
if (rez==0) MessageBox("5E20B05B @5AC@A>2 4;O >B:@KB8O \n"+path);
else if (rez==ERROR_BAD_FORMAT) MessageBox("5 \'exe\' D09; ");
else if (rez==ERROR_FILE_NOT_FOUND) MessageBox("$09; =5 =0945= \n"+path);
else if (rez==ERROR_PATH_NOT_FOUND) MessageBox("CBL =5 =0945= \n"+path);
else if (rez<=31) MessageBox("H81:0 70?CA:0 \n"+path);
return(BTN_OPEN);
}
else return(CTreeView::OnClick(name));
}
//------------------------------------------------------------------ Draw
void CPropertyView::Draw()
{
if (!IsOpenView()) return; // 5A;8 =5 A>740= ?@>A<>B@, B> 2KE>48<
SetRectLbl(m_chart, m_name+".rect", m_wnd, "", m_clr, m_bgclr, m_x, m_y, m_dx, m_dy, m_corn, m_fontsize, m_font, true);
int ax=int(m_x+m_dx-1.5*m_bdx); int adx=int(1.2*m_bdx); int i=-1;
i++; SetButton(m_chart, m_name+".collaps", 0, "-", m_bgclr, m_selclr, ax-i*adx, int(m_y+0.5*m_bdy), m_bdx, m_bdy, 0, 7, "Tahoma", false);
i++; SetButton(m_chart, m_name+".expand", 0, "+", m_bgclr, m_selclr, ax-i*adx, int(m_y+0.5*m_bdy), m_bdx, m_bdy, 0, 7, "Tahoma", false);
i++; SetButton(m_chart, m_name+".open", 0, "...", m_bgclr, clrDarkOliveGreen, ax-i*adx, int(m_y+0.5*m_bdy), m_bdx, m_bdy, 0, 7, "Tahoma", false);
int show=0, up=0, dn=0;
DrawTree(m_tree.m_root, 1, show, up, dn); // =0@8A>20;8 45@52>
if (up<=0 && dn<=0) m_scroll.DeleteView(); // C1@0;8 ?>;>AC ?@>:@CB:8 4;O ?5@5@8A>2:8
else
{
m_scroll.m_max=up+dn; m_scroll.m_value=up;
m_scroll.m_x=m_x+m_dx-20; m_scroll.m_dx=16;
m_scroll.m_y=m_y+2*m_bdy; m_scroll.m_dy=m_dy-3*m_bdy+8;
m_scroll.Draw(); // >B@8A>20;8 ?>;>AC ?@>:@CB:8
}
}
//------------------------------------------------------------------ DrawTree
void CPropertyView::DrawTree(CNode *root, int xpos, int &ypos, int &up, int &dn)
{
if (xpos==1) { root=m_tree.m_root; ypos=0; } // 5A;8 =0G0;8 A ?5@2>3> M;5<5=B0, B> 15@5< :>@5=L 8 ;52>5 ?>;>65=85
if (root==NULL) { root=m_tree.m_root; xpos=1; } // 5A;8 =5 C:070= ?5@2K9 C75;, B> 15@5< :>@5=L 8 25@E=55 ?>;>65=85
if (NIL(root)) return; // ?@028;L=>ABL C:070B5;O
string name=m_name+string(root.m_id);
if (!IsOpenView()) return; // 5A;8 =5 A>740= ?@>A<>B@, B> 2KE>48<
int x=m_x0+m_x+5+(xpos-1)*m_bdx;
int y=m_y0+m_y+5+ypos*m_ndy;
bool ishide=(y<=m_y || y>=m_y+m_dy-m_ndy);
if (root.m_break && ishide)
{
while (y<m_y) { m_y0+=m_ndy; y=m_y0+m_y+5+ypos*m_ndy; }// ?>428=C;8 2=87
while (y>m_y+m_dy-m_ndy) { m_y0-=m_ndy; y=m_y0+m_y+5+ypos*m_ndy; }// ?>428=C;8 225@E
up=0; dn=0;
DrawTree(m_tree.m_root, 1, ypos, up, dn); // >B@8A>20;8 A=>20 2A5 45@52>
}
if (!ishide) DrawNode(root, x, y); // 5A;8 =5 CE>48B 70 >1;0ABL 2848<>AB8
else
{
ObjectDelete(m_chart, name+".lbl"); ObjectDelete(m_chart, name+".btn");
ObjectDelete(m_chart, name+".prop");
if (y<m_y) up++; else dn++;
}
if (!root.m_expand) return; // 5A;8 =5 @0A:@KB, B> ?@>?CA:05<
for (int i=0; i<ArraySize(root.m_next); i++)
{
if (NIL(root.m_next[i])) continue;
ypos++; // C25;8G8;8 ?>;>65=85
DrawTree(root.m_next[i], xpos+1, ypos, up, dn); // >B@8A>20;8 A;54CNICN 25B:C
}
}
//------------------------------------------------------------------ DrawNode
void CPropertyView::DrawNode(CNode *node, int x, int y)
{
if (NIL(node)) return;
int ndx=m_ndx-m_bdx;
string name=m_name+string(node.m_id);
string txt=node.m_text;
// >?@545;O5< F25B
bool bgroup=false;
if (!NIL(node.m_prev)) if (node.m_prev.m_id==0) bgroup=true;
color clr=bgroup ? m_selclr : m_clr;
clr=node.m_id==0 ? clrDarkOliveGreen : clr;
// 2K2>48< B5:AB 4;O C7;0
SetLabel(m_chart, name+".lbl", m_wnd, txt, clr, x+ndx, y-1, m_corn, m_fontsize, m_font);
if (node.m_desc=="" || node.m_id==0 || !node.m_expand)
ObjectDelete(m_chart, name+".prop");
else
{
if (node.m_edit) SetEdit(m_chart, name+".prop", m_wnd, node.m_desc, clr, m_bgclr, int(m_x+150), y, m_ndx*2, m_ndy+1, m_corn, m_fontsize, m_font, false);
else SetLabel(m_chart, name+".prop", m_wnd, node.m_desc, clr, int(m_x+150), y, m_corn, m_fontsize, m_font);
}
// :=>?:C @0A:@KB>AB8 C7;0
string state=node.m_expand ? "-" : "+";
if (ArraySize(node.m_next)>0) // 5A;8 5ABL ?>4<0AA82, B> AB028< @0A:@KB85
SetButton(m_chart, name+".btn", m_wnd, state, m_clr, m_bgclr, x, y, m_bdx, m_bdy, m_corn, m_fontsize, m_font, node.m_expand);
else ObjectDelete(m_chart, name+".btn");
}
//------------------------------------------------------------------ DeleteView
void CPropertyView::DeleteView(CNode *root=NULL, bool delparent=true)
{
CTreeView::DeleteView(root, delparent); // <5B>4 107>2>3>
if (root==NULL) root=m_tree.m_root; if (NIL(root)) return;
if(delparent) // C40;O5< C75; @>48B5;O
ObjectDelete(m_chart, m_name+string(root.m_id)+".prop");
for (int i=0; i<ArraySize(root.m_next); i++)
if (!NIL(root.m_next[i])) DeleteView(root.m_next[i], true);
}