]>
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/xrc/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();
73 m_TextCtrl
->SetValidator(wxTextValidator(wxFILTER_NUMERIC
));
84 BEGIN_EVENT_TABLE(PropEditCtrlBool
, PropEditCtrl
)
85 EVT_CHOICE(-1, PropEditCtrlBool::OnChoice
)
88 wxWindow
*PropEditCtrlBool::CreateEditCtrl()
90 m_Choice
= new wxChoice(this, -1);
91 m_Choice
->Append(_T("false"));
92 m_Choice
->Append(_T("true"));
98 void PropEditCtrlBool::ReadValue()
101 if (XmlReadValue(GetNode(), m_PropInfo
->Name
) == _T("0")) sel
= 0;
103 m_Choice
->SetSelection(sel
);
108 void PropEditCtrlBool::WriteValue()
110 wxString newv
= m_Choice
->GetSelection() == 0 ? _T("0") : _T("1");
112 XmlWriteValue(GetNode(), m_PropInfo
->Name
, newv
);
113 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
118 wxString
PropEditCtrlBool::GetValueAsText(wxTreeItemId ti
)
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");
129 void PropEditCtrlBool::OnChoice(wxCommandEvent
& event
)
134 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS
);
141 // --------------------------- PropEditCtrlCoord -----------------------
143 class PropEditCtrlCoordXY
: public PropEditCtrlInt
146 PropEditCtrlCoordXY(PropertiesFrame
*propFrame
, int which
)
147 : PropEditCtrlInt(propFrame
), m_which(which
) {}
149 virtual void ReadValue()
151 wxString s
= XmlReadValue(GetNode(), m_PropInfo
->Name
);
154 m_c
[0] = m_c
[1] = _T("-1");
158 wxStringTokenizer
tkn(s
.BeforeFirst(_T('d')), _T(","));
159 m_c
[0] = tkn
.GetNextToken();
160 m_c
[1] = tkn
.GetNextToken();
162 m_TextCtrl
->SetValue(m_c
[m_which
]);
165 virtual void WriteValue()
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");
171 s
<< m_c
[0] << _T(',') << m_c
[1];
172 wxString prev
= XmlReadValue(GetNode(), m_PropInfo
->Name
);
173 if (prev
[prev
.Len()-1] == _T('d')) s
<< _T('d');
174 XmlWriteValue(GetNode(), m_PropInfo
->Name
, s
);
175 m_TreeCtrl
->SetItemBold(m_TreeCtrl
->GetParent(m_TreeItem
), TRUE
);
178 virtual wxString
GetValueAsText(wxTreeItemId ti
)
180 PropertyInfo
*pi
= &(((PETreeData
*)m_TreeCtrl
->GetItemData(ti
))->PropInfo
);
181 wxString s
= XmlReadValue(GetNode(), pi
->Name
);
184 m_c
[0] = m_c
[1] = _T("-1");
188 wxStringTokenizer
tkn(s
.BeforeFirst(_T('d')), _T(","));
189 m_c
[0] = tkn
.GetNextToken();
190 m_c
[1] = tkn
.GetNextToken();
195 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
197 if (m_which
== 0) return _T("x"); else return _T("y");
200 virtual bool HasClearButton() { return FALSE
; }
201 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
210 class PropEditCtrlCoordDlg
: public PropEditCtrlBool
213 PropEditCtrlCoordDlg(PropertiesFrame
*propFrame
)
214 : PropEditCtrlBool(propFrame
) {}
216 virtual void ReadValue()
218 wxString s
= XmlReadValue(GetNode(), m_PropInfo
->Name
);
219 if (s
.IsEmpty()) m_Choice
->SetSelection(1);
220 else if (s
[s
.Length()-1] == _T('d'))
221 m_Choice
->SetSelection(1);
223 m_Choice
->SetSelection(0);
226 virtual void WriteValue()
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
);
231 m_TreeCtrl
->SetItemBold(m_TreeCtrl
->GetParent(m_TreeItem
), TRUE
);
234 virtual wxString
GetValueAsText(wxTreeItemId ti
)
236 PropertyInfo
*pi
= &(((PETreeData
*)m_TreeCtrl
->GetItemData(ti
))->PropInfo
);
237 wxString s
= XmlReadValue(GetNode(), pi
->Name
);
240 else if (s
[s
.Length()-1] != _T('d'))
246 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
251 virtual bool HasClearButton() { return FALSE
; }
252 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
258 PropEditCtrlCoord::PropEditCtrlCoord(PropertiesFrame
*propFrame
)
259 : PropEditCtrlTxt(propFrame
)
261 m_CtrlX
= new PropEditCtrlCoordXY(propFrame
, 0);
262 m_CtrlY
= new PropEditCtrlCoordXY(propFrame
, 1);
263 m_CtrlDlg
= new PropEditCtrlCoordDlg(propFrame
);
266 PropEditCtrlCoord::~PropEditCtrlCoord()
275 wxTreeItemId
PropEditCtrlCoord::CreateTreeEntry(wxTreeItemId parent
, const PropertyInfo
& pinfo
)
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("")));
289 // --------------------------- PropEditCtrlDim -----------------------
291 class PropEditCtrlDimX
: public PropEditCtrlInt
294 PropEditCtrlDimX(PropertiesFrame
*propFrame
)
295 : PropEditCtrlInt(propFrame
){}
297 virtual void ReadValue()
299 wxString s
= XmlReadValue(GetNode(), m_PropInfo
->Name
);
300 m_c
= s
.BeforeFirst(_T('d'));
301 m_TextCtrl
->SetValue(m_c
);
304 virtual void WriteValue()
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();
310 if (dlg
) s
<< _T('d');
311 XmlWriteValue(GetNode(), m_PropInfo
->Name
, s
);
312 m_TreeCtrl
->SetItemBold(m_TreeCtrl
->GetParent(m_TreeItem
), TRUE
);
315 virtual wxString
GetValueAsText(wxTreeItemId ti
)
317 PropertyInfo
*pi
= &(((PETreeData
*)m_TreeCtrl
->GetItemData(ti
))->PropInfo
);
318 return XmlReadValue(GetNode(), pi
->Name
).BeforeFirst(_T('d'));
321 virtual wxString
GetPropName(const PropertyInfo
& pinfo
)
326 virtual bool HasClearButton() { return FALSE
; }
327 virtual bool IsPresent(const PropertyInfo
& pinfo
) { return FALSE
; }
336 PropEditCtrlDim::PropEditCtrlDim(PropertiesFrame
*propFrame
)
337 : PropEditCtrlTxt(propFrame
)
339 m_CtrlX
= new PropEditCtrlDimX(propFrame
);
340 m_CtrlDlg
= new PropEditCtrlCoordDlg(propFrame
);
343 PropEditCtrlDim::~PropEditCtrlDim()
351 wxTreeItemId
PropEditCtrlDim::CreateTreeEntry(wxTreeItemId parent
, const PropertyInfo
& pinfo
)
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("")));
362 // --------------------- PropEditCtrlXRCID -----------------------------
364 #define REAL_NODE (NodeHandler::Find(GetNode())->GetRealNode(GetNode()))
367 void PropEditCtrlXRCID::ReadValue()
369 m_TextCtrl
->SetValue(REAL_NODE
->GetPropVal(_T("name"), wxEmptyString
));
374 void PropEditCtrlXRCID::WriteValue()
376 wxString s
=m_TextCtrl
->GetValue();
377 if (s
.IsEmpty()) s
= _T("-1");
379 REAL_NODE
->DeleteProperty(_T("name"));
380 REAL_NODE
->AddProperty(_T("name"), s
);
382 m_TreeCtrl
->SetItemBold(m_TreeItem
, TRUE
);
383 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED
);
388 void PropEditCtrlXRCID::Clear()
391 REAL_NODE
->DeleteProperty(_T("name"));
392 m_TreeCtrl
->SetItemBold(m_TreeItem
, FALSE
);
393 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED
);
398 void PropEditCtrlXRCID::OnDetails()
400 wxString choices
[] = {wxString(_T("-1"))
401 #define stdID(id) , wxString(#id)
402 stdID(wxID_OK
) stdID(wxID_CANCEL
)
403 stdID(wxID_YES
) stdID(wxID_NO
)
404 stdID(wxID_APPLY
) stdID(wxID_HELP
)
405 stdID(wxID_HELP_CONTEXT
)
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
)
415 stdID(wxID_SELECTALL
)
416 stdID(wxID_STATIC
) stdID(wxID_FORWARD
) stdID(wxID_BACKWARD
)
417 stdID(wxID_DEFAULT
) stdID(wxID_MORE
) stdID(wxID_SETUP
)
423 wxGetSingleChoice(_("Choose from predefined IDs:"), _("XRCID"),
424 38/*sizeof choices*/, choices
);
426 m_TextCtrl
->SetValue(s
);
428 EditorFrame::Get()->NotifyChanged(CHANGED_PROPS
);
433 wxString
PropEditCtrlXRCID::GetValueAsText(wxTreeItemId ti
)
435 return REAL_NODE
->GetPropVal(_T("name"), wxEmptyString
);
440 bool PropEditCtrlXRCID::IsPresent(const PropertyInfo
& pinfo
)
442 return REAL_NODE
->HasProp(_T("name"));