]>
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"
30 BEGIN_EVENT_TABLE(PropEditCtrlTxt
, PropEditCtrl
)
31 EVT_TEXT(-1, PropEditCtrlTxt::OnText
)
35 wxWindow
*PropEditCtrlTxt::CreateEditCtrl()
37 return (m_TextCtrl
= new wxTextCtrl(this, -1));
42 void PropEditCtrlTxt::OnText(wxCommandEvent
& event
)
47 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS
);
53 void PropEditCtrlTxt::ReadValue()
55 m_TextCtrl
->SetValue(XmlReadValue(GetNode(), m_PropInfo
->Name
));
60 void PropEditCtrlTxt::WriteValue()
62 wxString newv
= m_TextCtrl
->GetValue();
63 XmlWriteValue(GetNode(), m_PropInfo
->Name
, newv
);
64 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
69 wxWindow
*PropEditCtrlInt::CreateEditCtrl()
71 PropEditCtrlTxt::CreateEditCtrl();
72 m_TextCtrl
->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
82 BEGIN_EVENT_TABLE(PropEditCtrlBool
, PropEditCtrl
)
83 EVT_CHOICE(-1, PropEditCtrlBool::OnChoice
)
86 wxWindow
*PropEditCtrlBool::CreateEditCtrl()
88 m_Choice
= new wxChoice(this, -1);
89 m_Choice
->Append(_T("false"));
90 m_Choice
->Append(_T("true"));
96 void PropEditCtrlBool::ReadValue()
99 if (XmlReadValue(GetNode(), m_PropInfo
->Name
) == _T("0")) sel
= 0;
101 m_Choice
->SetSelection(sel
);
106 void PropEditCtrlBool::WriteValue()
108 wxString newv
= m_Choice
->GetSelection() == 0 ? _T("0") : _T("1");
110 XmlWriteValue(GetNode(), m_PropInfo
->Name
, newv
);
111 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
116 wxString
PropEditCtrlBool::GetValueAsText(wxTreeItemId ti
)
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");
127 void PropEditCtrlBool::OnChoice(wxCommandEvent
& event
)
132 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS
);
139 // --------------------------- PropEditCtrlCoord -----------------------
141 class PropEditCtrlCoordXY
: public PropEditCtrlInt
144 PropEditCtrlCoordXY(PropertiesFrame
*propFrame
, int which
)
145 : PropEditCtrlInt(propFrame
), m_which(which
) {}
147 virtual void ReadValue()
149 wxString s
= XmlReadValue(GetNode(), m_PropInfo
->Name
);
152 m_c
[0] = m_c
[1] = _T("-1");
156 wxStringTokenizer
tkn(s
.BeforeFirst(_T('d')), _T(","));
157 m_c
[0] = tkn
.GetNextToken();
158 m_c
[1] = tkn
.GetNextToken();
160 m_TextCtrl
->SetValue(m_c
[m_which
]);
163 virtual void WriteValue()
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");
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
);
176 virtual wxString
GetValueAsText(wxTreeItemId ti
)
178 PropertyInfo
*pi
= &(((PETreeData
*)m_TreeCtrl
->GetItemData(ti
))->PropInfo
);
179 wxString s
= XmlReadValue(GetNode(), pi
->Name
);
182 m_c
[0] = m_c
[1] = _T("-1");
186 wxStringTokenizer
tkn(s
.BeforeFirst(_T('d')), _T(","));
187 m_c
[0] = tkn
.GetNextToken();
188 m_c
[1] = tkn
.GetNextToken();
193 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
195 if (m_which
== 0) return _T("x"); else return _T("y");
198 virtual bool HasClearButton() { return FALSE
; }
199 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
208 class PropEditCtrlCoordDlg
: public PropEditCtrlBool
211 PropEditCtrlCoordDlg(PropertiesFrame
*propFrame
)
212 : PropEditCtrlBool(propFrame
) {}
214 virtual void ReadValue()
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);
221 m_Choice
->SetSelection(0);
224 virtual void WriteValue()
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
);
232 virtual wxString
GetValueAsText(wxTreeItemId ti
)
234 PropertyInfo
*pi
= &(((PETreeData
*)m_TreeCtrl
->GetItemData(ti
))->PropInfo
);
235 wxString s
= XmlReadValue(GetNode(), pi
->Name
);
238 else if (s
[s
.Length()-1] != _T('d'))
244 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
249 virtual bool HasClearButton() { return FALSE
; }
250 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
256 PropEditCtrlCoord::PropEditCtrlCoord(PropertiesFrame
*propFrame
)
257 : PropEditCtrlTxt(propFrame
)
259 m_CtrlX
= new PropEditCtrlCoordXY(propFrame
, 0);
260 m_CtrlY
= new PropEditCtrlCoordXY(propFrame
, 1);
261 m_CtrlDlg
= new PropEditCtrlCoordDlg(propFrame
);
264 PropEditCtrlCoord::~PropEditCtrlCoord()
273 wxTreeItemId
PropEditCtrlCoord::CreateTreeEntry(wxTreeItemId parent
, const PropertyInfo
& pinfo
)
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("")));
287 // --------------------------- PropEditCtrlDim -----------------------
289 class PropEditCtrlDimX
: public PropEditCtrlInt
292 PropEditCtrlDimX(PropertiesFrame
*propFrame
)
293 : PropEditCtrlInt(propFrame
){}
295 virtual void ReadValue()
297 wxString s
= XmlReadValue(GetNode(), m_PropInfo
->Name
);
298 m_c
= s
.BeforeFirst(_T('d'));
299 m_TextCtrl
->SetValue(m_c
);
302 virtual void WriteValue()
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();
308 if (dlg
) s
<< _T('d');
309 XmlWriteValue(GetNode(), m_PropInfo
->Name
, s
);
310 m_TreeCtrl
->SetItemBold(m_TreeCtrl
->GetParent(m_TreeItem
), TRUE
);
313 virtual wxString
GetValueAsText(wxTreeItemId ti
)
315 PropertyInfo
*pi
= &(((PETreeData
*)m_TreeCtrl
->GetItemData(ti
))->PropInfo
);
316 return XmlReadValue(GetNode(), pi
->Name
).BeforeFirst(_T('d'));
319 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
324 virtual bool HasClearButton() { return FALSE
; }
325 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
334 PropEditCtrlDim::PropEditCtrlDim(PropertiesFrame
*propFrame
)
335 : PropEditCtrlTxt(propFrame
)
337 m_CtrlX
= new PropEditCtrlDimX(propFrame
);
338 m_CtrlDlg
= new PropEditCtrlCoordDlg(propFrame
);
341 PropEditCtrlDim::~PropEditCtrlDim()
349 wxTreeItemId
PropEditCtrlDim::CreateTreeEntry(wxTreeItemId parent
, const PropertyInfo
& pinfo
)
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("")));
360 // --------------------- PropEditCtrlXMLID -----------------------------
362 #define REAL_NODE (NodeHandler::Find(GetNode())->GetRealNode(GetNode()))
365 void PropEditCtrlXMLID::ReadValue()
367 m_TextCtrl
->SetValue(REAL_NODE
->GetPropVal(_T("name"), wxEmptyString
));
372 void PropEditCtrlXMLID::WriteValue()
374 wxString s
=m_TextCtrl
->GetValue();
375 if (s
.IsEmpty()) s
= _T("-1");
377 REAL_NODE
->DeleteProperty(_T("name"));
378 REAL_NODE
->AddProperty(_T("name"), s
);
380 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
381 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED
);
386 void PropEditCtrlXMLID::Clear()
389 REAL_NODE
->DeleteProperty(_T("name"));
390 m_TreeCtrl
->SetItemBold(m_TreeItem
, FALSE
);
391 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED
);
396 void PropEditCtrlXMLID::OnDetails()
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
)
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
)
421 wxGetSingleChoice(_("Choose from predefined IDs:"), _("XMLID"),
422 38/*sizeof choices*/, choices
);
424 m_TextCtrl
->SetValue(s
);
426 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS
);
431 wxString
PropEditCtrlXMLID::GetValueAsText(wxTreeItemId ti
)
433 return REAL_NODE
->GetPropVal(_T("name"), wxEmptyString
);
438 bool PropEditCtrlXMLID::IsPresent(const PropertyInfo
& pinfo
)
440 return REAL_NODE
->HasProp(_T("name"));