-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommon.cs
208 lines (192 loc) · 4.27 KB
/
Common.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
* Creato da SharpDevelop.
* Utente: michele
* Data: 13/01/2009
* Ora: 12.23
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;
namespace mkdb
{
public class Common
{
private static Common _instance;
private IWDBBase _cur_element;
private wx.Window _cur_window;
private CommandFlags _cur_action;
private TreeView _obj_tree;
private PropertyGrid _obj_props_panel;
private ImageList _obj_tree_il;
private Python.PyFileEditor _py_editor;
private Panel _canvas;
// private Properties.WidgetPropsManager _prop_man;
// Constructor is 'protected'
protected Common()
{
_cur_element = null;
_cur_window = null;
_obj_props_panel = null;
_cur_action = CommandFlags.TB_NONE;
_obj_tree_il = null;
_py_editor = new mkdb.Python.PyFileEditor();
// _prop_man = new mkdb.Properties.WidgetPropsManager();
}
public static Common Instance()
{
// Uses lazy initialization.
// Note: this is not thread safe.
if (_instance == null)
{
_instance = new Common();
}
return _instance;
}
public wx.Window CurrentWindow
{
get { return _cur_window; }
set { _cur_window = value; }
}
public IWDBBase CurrentElement
{
get { return _cur_element; }
set { _cur_element = value; }
}
public CommandFlags CurrentAction
{
get { return _cur_action; }
set { _cur_action = value; }
}
public PropertyGrid ObjPropsPanel
{
get { return _obj_props_panel; }
set { _obj_props_panel = value; }
}
public TreeView ObjTree
{
get { return _obj_tree; }
set { _obj_tree = value; }
}
public ImageList ObjTreeImageList
{
get { return _obj_tree_il; }
set { _obj_tree_il = value; }
}
public Python.PyFileEditor PyEditor
{
get { return _py_editor; }
}
public void ChangeCurrentWindow(WidgetTreeNode neww)
{
if (neww.Widget.WidgetType == (int)StandardWidgetType.WID_APP)
{
// Hide, when we select the application.
if (_cur_window != null)
_cur_window.Hide();
}
IWDBBase _cur = FindTopMostFrame(neww);
if (_cur != null)
{
if (_cur_window != null)
_cur_window.Hide();
_cur_window = (wx.Window)_cur;
_cur_window.Show();
}
}
public IWDBBase FindTopMostFrame(WidgetTreeNode node)
{
if (node.Level == 1)
{
if (node.Widget.WidgetType == (int)StandardWidgetType.WID_FRAME)
{
return node.Widget;
}
else
{
return null;
}
}
if (node.Parent != null)
{
return FindTopMostFrame((WidgetTreeNode)node.Parent);
}
return null;
}
public WidgetTreeNode FindBestParentContainer(WidgetTreeNode curNode, bool sizerIsAsking)
{
if (sizerIsAsking == false)
{
return null;
}
if (curNode.Widget.IsSizer == false)
{
if (curNode.Widget.CanAcceptChildren())
{
return curNode;
} else
{
return null;
}
} else
{
if (curNode.Parent == null)
{
return null;
} else
{
return FindBestParentContainer((WidgetTreeNode)curNode.Parent, true);
}
}
}
public WidgetTreeNode FindBestParentSizer(WidgetTreeNode curNode, bool sizerIsAsking)
{
if (curNode.Widget.IsSizer == false)
{
return null;
}
if (curNode.Widget.CanAcceptChildren())
{
return curNode;
} else
{
if (curNode.Parent == null)
{
return null;
} else
{
return FindBestParentSizer((WidgetTreeNode)curNode.Parent, false);
}
}
}
public void CheckParentForSizer(WidgetTreeNode _c, WidgetTreeNode _s, out wx.Window _rc, out wx.Sizer _rs)
{
_rc = null;
_rs = null;
if (_c != null) _rc = (wx.Window)_c.Widget;
if (_s != null)
{
_rs = (wx.Sizer)_s.Widget;
_rc = _s.Widget.ParentContainer;
}
}
public void CheckParentForWidget(WidgetTreeNode _c, WidgetTreeNode _s, out wx.Window _rc)
{
_rc = null;
if (_c == null)
{
_rc = (wx.Window)_s.Widget.ParentContainer;
} else
{
_rc = (wx.Window)_c.Widget;
}
}
public Panel Canvas
{
get { return _canvas; }
set { _canvas = value; }
}
}
}