]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/pe_basic.cpp
reworked the editor
[wxWidgets.git] / contrib / utils / wxrcedit / pe_basic.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Author: Vaclav Slavik
3 // Created: 2000/05/05
4 // RCS-ID: $Id$
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #ifdef __GNUG__
10 #pragma implementation "pe_basic.h"
11 #endif
12
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 #include "wx/wx.h"
21 #include "wx/xml/xml.h"
22 #include "wx/tokenzr.h"
23 #include "pe_basic.h"
24 #include "xmlhelpr.h"
25 #include "editor.h"
26 #include "preview.h"
27
28
29 BEGIN_EVENT_TABLE(PropEditCtrlTxt, PropEditCtrl)
30 EVT_TEXT(-1, PropEditCtrlTxt::OnText)
31 END_EVENT_TABLE()
32
33
34 wxWindow *PropEditCtrlTxt::CreateEditCtrl()
35 {
36 return (m_TextCtrl = new wxTextCtrl(this, -1));
37 }
38
39
40
41 void PropEditCtrlTxt::OnText(wxCommandEvent& event)
42 {
43 if (CanSave()) WriteValue();
44 }
45
46
47
48 void PropEditCtrlTxt::ReadValue()
49 {
50 m_TextCtrl->SetValue(XmlReadValue(GetNode(), m_PropInfo->Name));
51 }
52
53
54
55 void PropEditCtrlTxt::WriteValue()
56 {
57 wxString newv = m_TextCtrl->GetValue();
58 XmlWriteValue(GetNode(), m_PropInfo->Name, newv);
59 m_TreeCtrl->SetItemBold(m_TreeItem, TRUE);
60 }
61
62
63
64 wxWindow *PropEditCtrlInt::CreateEditCtrl()
65 {
66 PropEditCtrlTxt::CreateEditCtrl();
67 m_TextCtrl->SetValidator(wxTextValidator(wxFILTER_NUMERIC));
68 return m_TextCtrl;
69 }
70
71
72
73
74
75
76
77 BEGIN_EVENT_TABLE(PropEditCtrlBool, PropEditCtrl)
78 EVT_CHOICE(-1, PropEditCtrlBool::OnChoice)
79 END_EVENT_TABLE()
80
81 wxWindow *PropEditCtrlBool::CreateEditCtrl()
82 {
83 m_Choice = new wxChoice(this, -1);
84 m_Choice->Append(_T("false"));
85 m_Choice->Append(_T("true"));
86 return m_Choice;
87 }
88
89
90
91 void PropEditCtrlBool::ReadValue()
92 {
93 int sel;
94 if (XmlReadValue(GetNode(), m_PropInfo->Name) == _T("0")) sel = 0;
95 else sel = 1;
96 m_Choice->SetSelection(sel);
97 }
98
99
100
101 void PropEditCtrlBool::WriteValue()
102 {
103 wxString newv = m_Choice->GetSelection() == 0 ? _T("0") : _T("1");
104
105 XmlWriteValue(GetNode(), m_PropInfo->Name, newv);
106 m_TreeCtrl->SetItemBold(m_TreeItem, TRUE);
107 }
108
109
110
111 wxString PropEditCtrlBool::GetValueAsText(wxTreeItemId ti)
112 {
113 PropertyInfo& pir = ((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo;
114 wxString x = XmlReadValue(GetNode(), pir.Name);
115 if (x == _T("1")) x = _T("true");
116 else if (x == _T("0")) x = _T("false");
117 return x;
118 }
119
120
121
122 void PropEditCtrlBool::OnChoice(wxCommandEvent& event)
123 {
124 if (CanSave()) WriteValue();
125 }
126
127
128
129
130 // --------------------------- PropEditCtrlCoord -----------------------
131
132 class PropEditCtrlCoordXY : public PropEditCtrlInt
133 {
134 public:
135 PropEditCtrlCoordXY(PropertiesFrame *propFrame, int which)
136 : PropEditCtrlInt(propFrame), m_which(which) {}
137
138 virtual void ReadValue()
139 {
140 wxString s = XmlReadValue(GetNode(), m_PropInfo->Name);
141 if (s.IsEmpty())
142 {
143 m_c[0] = m_c[1] = _T("-1");
144 }
145 else
146 {
147 wxStringTokenizer tkn(s.BeforeFirst(_T('d')), _T(","));
148 m_c[0] = tkn.GetNextToken();
149 m_c[1] = tkn.GetNextToken();
150 }
151 m_TextCtrl->SetValue(m_c[m_which]);
152 }
153
154 virtual void WriteValue()
155 {
156 m_c[m_which] = m_TextCtrl->GetValue();
157 if (m_c[0].IsEmpty()) m_c[0] = _T("-1");
158 if (m_c[1].IsEmpty()) m_c[1] = _T("-1");
159 wxString s;
160 s << m_c[0] << _T(',') << m_c[1];
161 if (m_dlg) s << _T('d');
162 XmlWriteValue(GetNode(), m_PropInfo->Name, s);
163 m_TreeCtrl->SetItemBold(m_TreeCtrl->GetParent(m_TreeItem), TRUE);
164 }
165
166 virtual wxString GetValueAsText(wxTreeItemId ti)
167 {
168 PropertyInfo *pi = &(((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo);
169 wxString s = XmlReadValue(GetNode(), pi->Name);
170 if (s.IsEmpty())
171 {
172 m_c[0] = m_c[1] = _T("-1");
173 }
174 else
175 {
176 wxStringTokenizer tkn(s.BeforeFirst(_T('d')), _T(","));
177 m_c[0] = tkn.GetNextToken();
178 m_c[1] = tkn.GetNextToken();
179 }
180 return m_c[m_which];
181 }
182
183 virtual wxString GetPropName(const PropertyInfo& pinfo)
184 {
185 if (m_which == 0) return _T("x"); else return _T("y");
186 }
187
188 virtual bool HasClearButton() { return FALSE; }
189 virtual bool IsPresent(const PropertyInfo& pinfo) { return FALSE; }
190
191
192 protected:
193 wxString m_c[2];
194 bool m_dlg;
195 int m_which;
196 };
197
198
199 class PropEditCtrlCoordDlg : public PropEditCtrlBool
200 {
201 public:
202 PropEditCtrlCoordDlg(PropertiesFrame *propFrame)
203 : PropEditCtrlBool(propFrame) {}
204
205 virtual void ReadValue()
206 {
207 wxString s = XmlReadValue(GetNode(), m_PropInfo->Name);
208 if (s.IsEmpty()) m_Choice->SetSelection(0);
209 else if (s[s.Length()-1] == _T('d'))
210 m_Choice->SetSelection(1);
211 else
212 m_Choice->SetSelection(0);
213 }
214
215 virtual void WriteValue()
216 {
217 wxString s = XmlReadValue(GetNode(), m_PropInfo->Name).BeforeFirst(_T('d'));
218 if (m_Choice->GetSelection() == 1) s << _T('d');
219 XmlWriteValue(GetNode(), m_PropInfo->Name, s);
220 m_TreeCtrl->SetItemBold(m_TreeCtrl->GetParent(m_TreeItem), TRUE);
221 }
222
223 virtual wxString GetValueAsText(wxTreeItemId ti)
224 {
225 PropertyInfo *pi = &(((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo);
226 wxString s = XmlReadValue(GetNode(), pi->Name);
227 if (s.IsEmpty() || s[s.Length()-1] != _T('d'))
228 return _("false");
229 else
230 return _("true");
231 }
232
233 virtual wxString GetPropName(const PropertyInfo& pinfo)
234 {
235 return _T("dlg");
236 }
237
238 virtual bool HasClearButton() { return FALSE; }
239 virtual bool IsPresent(const PropertyInfo& pinfo) { return FALSE; }
240 };
241
242
243
244
245 PropEditCtrlCoord::PropEditCtrlCoord(PropertiesFrame *propFrame)
246 : PropEditCtrlTxt(propFrame)
247 {
248 m_CtrlX = new PropEditCtrlCoordXY(propFrame, 0);
249 m_CtrlY = new PropEditCtrlCoordXY(propFrame, 1);
250 m_CtrlDlg = new PropEditCtrlCoordDlg(propFrame);
251 }
252
253 PropEditCtrlCoord::~PropEditCtrlCoord()
254 {
255 delete m_CtrlX;
256 delete m_CtrlY;
257 delete m_CtrlDlg;
258 }
259
260
261
262 wxTreeItemId PropEditCtrlCoord::CreateTreeEntry(wxTreeItemId parent, const PropertyInfo& pinfo)
263 {
264 wxTreeItemId id = PropEditCtrlTxt::CreateTreeEntry(parent, pinfo);
265 m_CtrlX->CreateTreeEntry(id, PropertyInfo(_T("text"), pinfo.Name, _T("")));
266 m_CtrlY->CreateTreeEntry(id, PropertyInfo(_T("text"), pinfo.Name, _T("")));
267 m_CtrlDlg->CreateTreeEntry(id, PropertyInfo(_T("bool"), pinfo.Name, _T("")));
268 return id;
269 }
270
271
272
273
274
275
276 // --------------------------- PropEditCtrlDim -----------------------
277
278 class PropEditCtrlDimX : public PropEditCtrlInt
279 {
280 public:
281 PropEditCtrlDimX(PropertiesFrame *propFrame)
282 : PropEditCtrlInt(propFrame){}
283
284 virtual void ReadValue()
285 {
286 wxString s = XmlReadValue(GetNode(), m_PropInfo->Name);
287 m_c = s.BeforeFirst(_T('d'));
288 m_TextCtrl->SetValue(m_c);
289 }
290
291 virtual void WriteValue()
292 {
293 wxString s = XmlReadValue(GetNode(), m_PropInfo->Name);
294 bool dlg = !s.IsEmpty() && s[s.Length()-1] == _T('d');
295 m_c = m_TextCtrl->GetValue();
296 s = m_c;
297 if (dlg) s << _T('d');
298 XmlWriteValue(GetNode(), m_PropInfo->Name, s);
299 m_TreeCtrl->SetItemBold(m_TreeCtrl->GetParent(m_TreeItem), TRUE);
300 }
301
302 virtual wxString GetValueAsText(wxTreeItemId ti)
303 {
304 PropertyInfo *pi = &(((PETreeData*)m_TreeCtrl->GetItemData(ti))->PropInfo);
305 return XmlReadValue(GetNode(), pi->Name).BeforeFirst(_T('d'));
306 }
307
308 virtual wxString GetPropName(const PropertyInfo& pinfo)
309 {
310 return _T("val");
311 }
312
313 virtual bool HasClearButton() { return FALSE; }
314 virtual bool IsPresent(const PropertyInfo& pinfo) { return FALSE; }
315
316
317 protected:
318 wxString m_c;
319 };
320
321
322
323 PropEditCtrlDim::PropEditCtrlDim(PropertiesFrame *propFrame)
324 : PropEditCtrlTxt(propFrame)
325 {
326 m_CtrlX = new PropEditCtrlDimX(propFrame);
327 m_CtrlDlg = new PropEditCtrlCoordDlg(propFrame);
328 }
329
330 PropEditCtrlDim::~PropEditCtrlDim()
331 {
332 delete m_CtrlX;
333 delete m_CtrlDlg;
334 }
335
336
337
338 wxTreeItemId PropEditCtrlDim::CreateTreeEntry(wxTreeItemId parent, const PropertyInfo& pinfo)
339 {
340 wxTreeItemId id = PropEditCtrlTxt::CreateTreeEntry(parent, pinfo);
341 m_CtrlX->CreateTreeEntry(id, PropertyInfo(_T("text"), pinfo.Name, _T("")));
342 m_CtrlDlg->CreateTreeEntry(id, PropertyInfo(_T("bool"), pinfo.Name, _T("")));
343 return id;
344 }
345
346
347
348
349 // --------------------- PropEditCtrlXMLID -----------------------------
350
351
352 void PropEditCtrlXMLID::ReadValue()
353 {
354 m_TextCtrl->SetValue(GetNode()->GetPropVal(_T("name"), wxEmptyString));
355 }
356
357
358
359 void PropEditCtrlXMLID::WriteValue()
360 {
361 wxString s =m_TextCtrl->GetValue();
362 if (s.IsEmpty()) s = _T("-1");
363
364 GetNode()->DeleteProperty(_T("name"));
365 GetNode()->AddProperty(_T("name"), s);
366
367 m_TreeCtrl->SetItemBold(m_TreeItem, TRUE);
368 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED);
369 }
370
371
372
373 void PropEditCtrlXMLID::Clear()
374 {
375 EndEdit();
376 GetNode()->DeleteProperty(_T("name"));
377 m_TreeCtrl->SetItemBold(m_TreeItem, FALSE);
378 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED);
379 }
380
381
382
383 void PropEditCtrlXMLID::OnDetails()
384 {
385 wxString choices[] = {wxString(_T("-1"))
386 #define stdID(id) , wxString(#id)
387 stdID(wxID_OK) stdID(wxID_CANCEL)
388 stdID(wxID_YES) stdID(wxID_NO)
389 stdID(wxID_APPLY) stdID(wxID_HELP)
390 stdID(wxID_HELP_CONTEXT)
391
392 stdID(wxID_OPEN) stdID(wxID_CLOSE) stdID(wxID_NEW)
393 stdID(wxID_SAVE) stdID(wxID_SAVEAS) stdID(wxID_REVERT)
394 stdID(wxID_EXIT) stdID(wxID_UNDO) stdID(wxID_REDO)
395 stdID(wxID_PRINT) stdID(wxID_PRINT_SETUP)
396 stdID(wxID_PREVIEW) stdID(wxID_ABOUT) stdID(wxID_HELP_CONTENTS)
397 stdID(wxID_HELP_COMMANDS) stdID(wxID_HELP_PROCEDURES)
398 stdID(wxID_CUT) stdID(wxID_COPY) stdID(wxID_PASTE)
399 stdID(wxID_CLEAR) stdID(wxID_FIND) stdID(wxID_DUPLICATE)
400 stdID(wxID_SELECTALL)
401 stdID(wxID_STATIC) stdID(wxID_FORWARD) stdID(wxID_BACKWARD)
402 stdID(wxID_DEFAULT) stdID(wxID_MORE) stdID(wxID_SETUP)
403 stdID(wxID_RESET)
404 #undef stdID
405 };
406
407 wxString s =
408 wxGetSingleChoice(_("Choose from predefined IDs:"), _("XMLID"),
409 38/*sizeof choices*/, choices);
410 if (!s) return;
411 m_TextCtrl->SetValue(s);
412 WriteValue();
413 }
414
415
416
417 wxString PropEditCtrlXMLID::GetValueAsText(wxTreeItemId ti)
418 {
419 return GetNode()->GetPropVal(_T("name"), wxEmptyString);
420 }
421
422
423
424 bool PropEditCtrlXMLID::IsPresent(const PropertyInfo& pinfo)
425 {
426 return GetNode()->HasProp(_T("name"));
427 }
428
429
430
431