]>
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
)
46 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS
);
52 void PropEditCtrlTxt::ReadValue()
54 m_TextCtrl
->SetValue(XmlReadValue(GetNode(), m_PropInfo
->Name
));
59 void PropEditCtrlTxt::WriteValue()
61 wxString newv
= m_TextCtrl
->GetValue();
62 XmlWriteValue(GetNode(), m_PropInfo
->Name
, newv
);
63 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
68 wxWindow
*PropEditCtrlInt::CreateEditCtrl()
70 PropEditCtrlTxt::CreateEditCtrl();
71 m_TextCtrl
->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
81 BEGIN_EVENT_TABLE(PropEditCtrlBool
, PropEditCtrl
)
82 EVT_CHOICE(-1, PropEditCtrlBool::OnChoice
)
85 wxWindow
*PropEditCtrlBool::CreateEditCtrl()
87 m_Choice
= new wxChoice(this, -1);
88 m_Choice
->Append(_T("false"));
89 m_Choice
->Append(_T("true"));
95 void PropEditCtrlBool::ReadValue()
98 if (XmlReadValue(GetNode(), m_PropInfo
->Name
) == _T("0")) sel
= 0;
100 m_Choice
->SetSelection(sel
);
105 void PropEditCtrlBool::WriteValue()
107 wxString newv
= m_Choice
->GetSelection() == 0 ? _T("0") : _T("1");
109 XmlWriteValue(GetNode(), m_PropInfo
->Name
, newv
);
110 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
115 wxString
PropEditCtrlBool::GetValueAsText(wxTreeItemId ti
)
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");
126 void PropEditCtrlBool::OnChoice(wxCommandEvent
& event
)
131 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS
);
138 // --------------------------- PropEditCtrlCoord -----------------------
140 class PropEditCtrlCoordXY
: public PropEditCtrlInt
143 PropEditCtrlCoordXY(PropertiesFrame
*propFrame
, int which
)
144 : PropEditCtrlInt(propFrame
), m_which(which
) {}
146 virtual void ReadValue()
148 wxString s
= XmlReadValue(GetNode(), m_PropInfo
->Name
);
151 m_c
[0] = m_c
[1] = _T("-1");
155 wxStringTokenizer
tkn(s
.BeforeFirst(_T('d')), _T(","));
156 m_c
[0] = tkn
.GetNextToken();
157 m_c
[1] = tkn
.GetNextToken();
159 m_TextCtrl
->SetValue(m_c
[m_which
]);
162 virtual void WriteValue()
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");
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
);
174 virtual wxString
GetValueAsText(wxTreeItemId ti
)
176 PropertyInfo
*pi
= &(((PETreeData
*)m_TreeCtrl
->GetItemData(ti
))->PropInfo
);
177 wxString s
= XmlReadValue(GetNode(), pi
->Name
);
180 m_c
[0] = m_c
[1] = _T("-1");
184 wxStringTokenizer
tkn(s
.BeforeFirst(_T('d')), _T(","));
185 m_c
[0] = tkn
.GetNextToken();
186 m_c
[1] = tkn
.GetNextToken();
191 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
193 if (m_which
== 0) return _T("x"); else return _T("y");
196 virtual bool HasClearButton() { return FALSE
; }
197 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
207 class PropEditCtrlCoordDlg
: public PropEditCtrlBool
210 PropEditCtrlCoordDlg(PropertiesFrame
*propFrame
)
211 : PropEditCtrlBool(propFrame
) {}
213 virtual void ReadValue()
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);
220 m_Choice
->SetSelection(0);
223 virtual void WriteValue()
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
);
231 virtual wxString
GetValueAsText(wxTreeItemId ti
)
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'))
241 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
246 virtual bool HasClearButton() { return FALSE
; }
247 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
253 PropEditCtrlCoord::PropEditCtrlCoord(PropertiesFrame
*propFrame
)
254 : PropEditCtrlTxt(propFrame
)
256 m_CtrlX
= new PropEditCtrlCoordXY(propFrame
, 0);
257 m_CtrlY
= new PropEditCtrlCoordXY(propFrame
, 1);
258 m_CtrlDlg
= new PropEditCtrlCoordDlg(propFrame
);
261 PropEditCtrlCoord::~PropEditCtrlCoord()
270 wxTreeItemId
PropEditCtrlCoord::CreateTreeEntry(wxTreeItemId parent
, const PropertyInfo
& pinfo
)
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("")));
284 // --------------------------- PropEditCtrlDim -----------------------
286 class PropEditCtrlDimX
: public PropEditCtrlInt
289 PropEditCtrlDimX(PropertiesFrame
*propFrame
)
290 : PropEditCtrlInt(propFrame
){}
292 virtual void ReadValue()
294 wxString s
= XmlReadValue(GetNode(), m_PropInfo
->Name
);
295 m_c
= s
.BeforeFirst(_T('d'));
296 m_TextCtrl
->SetValue(m_c
);
299 virtual void WriteValue()
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();
305 if (dlg
) s
<< _T('d');
306 XmlWriteValue(GetNode(), m_PropInfo
->Name
, s
);
307 m_TreeCtrl
->SetItemBold(m_TreeCtrl
->GetParent(m_TreeItem
), TRUE
);
310 virtual wxString
GetValueAsText(wxTreeItemId ti
)
312 PropertyInfo
*pi
= &(((PETreeData
*)m_TreeCtrl
->GetItemData(ti
))->PropInfo
);
313 return XmlReadValue(GetNode(), pi
->Name
).BeforeFirst(_T('d'));
316 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
321 virtual bool HasClearButton() { return FALSE
; }
322 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
331 PropEditCtrlDim::PropEditCtrlDim(PropertiesFrame
*propFrame
)
332 : PropEditCtrlTxt(propFrame
)
334 m_CtrlX
= new PropEditCtrlDimX(propFrame
);
335 m_CtrlDlg
= new PropEditCtrlCoordDlg(propFrame
);
338 PropEditCtrlDim::~PropEditCtrlDim()
346 wxTreeItemId
PropEditCtrlDim::CreateTreeEntry(wxTreeItemId parent
, const PropertyInfo
& pinfo
)
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("")));
357 // --------------------- PropEditCtrlXMLID -----------------------------
360 void PropEditCtrlXMLID::ReadValue()
362 m_TextCtrl
->SetValue(GetNode()->GetPropVal(_T("name"), wxEmptyString
));
367 void PropEditCtrlXMLID::WriteValue()
369 wxString s
=m_TextCtrl
->GetValue();
370 if (s
.IsEmpty()) s
= _T("-1");
372 GetNode()->DeleteProperty(_T("name"));
373 GetNode()->AddProperty(_T("name"), s
);
375 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
376 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED
);
381 void PropEditCtrlXMLID::Clear()
384 GetNode()->DeleteProperty(_T("name"));
385 m_TreeCtrl
->SetItemBold(m_TreeItem
, FALSE
);
386 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED
);
391 void PropEditCtrlXMLID::OnDetails()
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
)
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
)
416 wxGetSingleChoice(_("Choose from predefined IDs:"), _("XMLID"),
417 38/*sizeof choices*/, choices
);
419 m_TextCtrl
->SetValue(s
);
421 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS
);
426 wxString
PropEditCtrlXMLID::GetValueAsText(wxTreeItemId ti
)
428 return GetNode()->GetPropVal(_T("name"), wxEmptyString
);
433 bool PropEditCtrlXMLID::IsPresent(const PropertyInfo
& pinfo
)
435 return GetNode()->HasProp(_T("name"));