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