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