]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/wxrcedit/pe_basic.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Author: Vaclav Slavik
5 // Copyright: (c) 2000 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation "pe_basic.h"
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
21 #include "wx/xml/xml.h"
22 #include "wx/tokenzr.h"
29 BEGIN_EVENT_TABLE(PropEditCtrlTxt
, PropEditCtrl
)
30 EVT_TEXT(-1, PropEditCtrlTxt::OnText
)
34 wxWindow
*PropEditCtrlTxt::CreateEditCtrl()
36 return (m_TextCtrl
= new wxTextCtrl(this, -1));
41 void PropEditCtrlTxt::OnText(wxCommandEvent
& event
)
43 if (CanSave()) WriteValue();
48 void PropEditCtrlTxt::ReadValue()
50 m_TextCtrl
->SetValue(XmlReadValue(GetNode(), m_PropInfo
->Name
));
55 void PropEditCtrlTxt::WriteValue()
57 wxString newv
= m_TextCtrl
->GetValue();
58 XmlWriteValue(GetNode(), m_PropInfo
->Name
, newv
);
59 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
64 wxWindow
*PropEditCtrlInt::CreateEditCtrl()
66 PropEditCtrlTxt::CreateEditCtrl();
67 m_TextCtrl
->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
77 BEGIN_EVENT_TABLE(PropEditCtrlBool
, PropEditCtrl
)
78 EVT_CHOICE(-1, PropEditCtrlBool::OnChoice
)
81 wxWindow
*PropEditCtrlBool::CreateEditCtrl()
83 m_Choice
= new wxChoice(this, -1);
84 m_Choice
->Append(_T("false"));
85 m_Choice
->Append(_T("true"));
91 void PropEditCtrlBool::ReadValue()
94 if (XmlReadValue(GetNode(), m_PropInfo
->Name
) == _T("0")) sel
= 0;
96 m_Choice
->SetSelection(sel
);
101 void PropEditCtrlBool::WriteValue()
103 wxString newv
= m_Choice
->GetSelection() == 0 ? _T("0") : _T("1");
105 XmlWriteValue(GetNode(), m_PropInfo
->Name
, newv
);
106 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
111 wxString
PropEditCtrlBool::GetValueAsText(wxTreeItemId ti
)
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");
122 void PropEditCtrlBool::OnChoice(wxCommandEvent
& event
)
124 if (CanSave()) WriteValue();
130 // --------------------------- PropEditCtrlCoord -----------------------
132 class PropEditCtrlCoordXY
: public PropEditCtrlInt
135 PropEditCtrlCoordXY(PropertiesFrame
*propFrame
, int which
)
136 : PropEditCtrlInt(propFrame
), m_which(which
) {}
138 virtual void ReadValue()
140 wxString s
= XmlReadValue(GetNode(), m_PropInfo
->Name
);
143 m_c
[0] = m_c
[1] = _T("-1");
147 wxStringTokenizer
tkn(s
.BeforeFirst(_T('d')), _T(","));
148 m_c
[0] = tkn
.GetNextToken();
149 m_c
[1] = tkn
.GetNextToken();
151 m_TextCtrl
->SetValue(m_c
[m_which
]);
154 virtual void WriteValue()
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");
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
);
166 virtual wxString
GetValueAsText(wxTreeItemId ti
)
168 PropertyInfo
*pi
= &(((PETreeData
*)m_TreeCtrl
->GetItemData(ti
))->PropInfo
);
169 wxString s
= XmlReadValue(GetNode(), pi
->Name
);
172 m_c
[0] = m_c
[1] = _T("-1");
176 wxStringTokenizer
tkn(s
.BeforeFirst(_T('d')), _T(","));
177 m_c
[0] = tkn
.GetNextToken();
178 m_c
[1] = tkn
.GetNextToken();
183 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
185 if (m_which
== 0) return _T("x"); else return _T("y");
188 virtual bool HasClearButton() { return FALSE
; }
189 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
199 class PropEditCtrlCoordDlg
: public PropEditCtrlBool
202 PropEditCtrlCoordDlg(PropertiesFrame
*propFrame
)
203 : PropEditCtrlBool(propFrame
) {}
205 virtual void ReadValue()
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);
212 m_Choice
->SetSelection(0);
215 virtual void WriteValue()
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
);
223 virtual wxString
GetValueAsText(wxTreeItemId ti
)
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'))
233 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
238 virtual bool HasClearButton() { return FALSE
; }
239 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
245 PropEditCtrlCoord::PropEditCtrlCoord(PropertiesFrame
*propFrame
)
246 : PropEditCtrlTxt(propFrame
)
248 m_CtrlX
= new PropEditCtrlCoordXY(propFrame
, 0);
249 m_CtrlY
= new PropEditCtrlCoordXY(propFrame
, 1);
250 m_CtrlDlg
= new PropEditCtrlCoordDlg(propFrame
);
253 PropEditCtrlCoord::~PropEditCtrlCoord()
262 wxTreeItemId
PropEditCtrlCoord::CreateTreeEntry(wxTreeItemId parent
, const PropertyInfo
& pinfo
)
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("")));
276 // --------------------------- PropEditCtrlDim -----------------------
278 class PropEditCtrlDimX
: public PropEditCtrlInt
281 PropEditCtrlDimX(PropertiesFrame
*propFrame
)
282 : PropEditCtrlInt(propFrame
){}
284 virtual void ReadValue()
286 wxString s
= XmlReadValue(GetNode(), m_PropInfo
->Name
);
287 m_c
= s
.BeforeFirst(_T('d'));
288 m_TextCtrl
->SetValue(m_c
);
291 virtual void WriteValue()
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();
297 if (dlg
) s
<< _T('d');
298 XmlWriteValue(GetNode(), m_PropInfo
->Name
, s
);
299 m_TreeCtrl
->SetItemBold(m_TreeCtrl
->GetParent(m_TreeItem
), TRUE
);
302 virtual wxString
GetValueAsText(wxTreeItemId ti
)
304 PropertyInfo
*pi
= &(((PETreeData
*)m_TreeCtrl
->GetItemData(ti
))->PropInfo
);
305 return XmlReadValue(GetNode(), pi
->Name
).BeforeFirst(_T('d'));
308 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
313 virtual bool HasClearButton() { return FALSE
; }
314 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
323 PropEditCtrlDim::PropEditCtrlDim(PropertiesFrame
*propFrame
)
324 : PropEditCtrlTxt(propFrame
)
326 m_CtrlX
= new PropEditCtrlDimX(propFrame
);
327 m_CtrlDlg
= new PropEditCtrlCoordDlg(propFrame
);
330 PropEditCtrlDim::~PropEditCtrlDim()
338 wxTreeItemId
PropEditCtrlDim::CreateTreeEntry(wxTreeItemId parent
, const PropertyInfo
& pinfo
)
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("")));
349 // --------------------- PropEditCtrlXMLID -----------------------------
352 void PropEditCtrlXMLID::ReadValue()
354 m_TextCtrl
->SetValue(GetNode()->GetPropVal(_T("name"), wxEmptyString
));
359 void PropEditCtrlXMLID::WriteValue()
361 wxString s
=m_TextCtrl
->GetValue();
362 if (s
.IsEmpty()) s
= _T("-1");
364 GetNode()->DeleteProperty(_T("name"));
365 GetNode()->AddProperty(_T("name"), s
);
367 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
368 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED
);
373 void PropEditCtrlXMLID::Clear()
376 GetNode()->DeleteProperty(_T("name"));
377 m_TreeCtrl
->SetItemBold(m_TreeItem
, FALSE
);
378 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED
);
383 void PropEditCtrlXMLID::OnDetails()
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
)
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
)
408 wxGetSingleChoice(_("Choose from predefined IDs:"), _("XMLID"),
409 38/*sizeof choices*/, choices
);
411 m_TextCtrl
->SetValue(s
);
417 wxString
PropEditCtrlXMLID::GetValueAsText(wxTreeItemId ti
)
419 return GetNode()->GetPropVal(_T("name"), wxEmptyString
);
424 bool PropEditCtrlXMLID::IsPresent(const PropertyInfo
& pinfo
)
426 return GetNode()->HasProp(_T("name"));