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