]> git.saurik.com Git - wxWidgets.git/blame - contrib/utils/wxrcedit/prophnd.cpp
added 'centered' property to wxDialog handler
[wxWidgets.git] / contrib / utils / wxrcedit / prophnd.cpp
CommitLineData
56d2f750
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 "prophnd.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 "prophnd.h"
21#include "wx/xml/xml.h"
22#include "wx/wx.h"
23#include "wx/arrimpl.cpp"
24#include "wx/valtext.h"
25#include "wx/tokenzr.h"
26#include "wx/checklst.h"
fccd6cdc 27#include "wx/listctrl.h"
56d2f750
VS
28#include "xmlhelpr.h"
29#include "editor.h"
30
31
32WX_DEFINE_OBJARRAY(PropertyInfoArray);
33
34
35enum
36{
37 ID_EDITCTRL = wxID_HIGHEST + 1000,
38 ID_XEDIT,
39 ID_YEDIT,
40 ID_USEDLG,
41 ID_BOOLVAL,
42 ID_CHECKLIST
43};
44
45
46
47class PropertyPanel : public wxPanel
48{
49 public:
50 PropertyPanel(wxWindow *parent, PropertyHandler *hnd, PropsListInfo *pli)
51 : wxPanel(parent, -1), m_Handler(hnd), m_PLI(pli) {}
52
53 void Update(const wxString& value)
54 {
55 XmlWriteValue(m_PLI->m_Node, m_PLI->m_PropInfo->Name, value);
56 m_PLI->m_ListCtrl->SetItemImage(m_PLI->m_Index, 1, 1);
57 m_PLI->m_ListCtrl->SetItem(m_PLI->m_Index, 1,
58 m_Handler->GetBriefValue(m_PLI->m_Node, m_PLI->m_PropInfo));
59 }
60
61 protected:
62 PropertyHandler *m_Handler;
63 PropsListInfo *m_PLI;
64};
65
66
67
68
69
70int PropertyHandler::CreateListItem(wxListCtrl *listctrl, wxXmlNode *node, PropertyInfo *pi)
71{
72 wxString name, value;
73 int iconnum;
74
75 if (XmlFindNode(node, pi->Name) == NULL) iconnum = 0; else iconnum = 1;
76 name = pi->Name;
77 value = GetBriefValue(node, pi);
78
79 long pos = listctrl->GetItemCount();
80 listctrl->InsertItem(pos, name, iconnum);
81 listctrl->SetItem(pos, 1, value);
82 return pos;
83}
84
85
86
87wxString PropertyHandler::GetBriefValue(wxXmlNode *node, PropertyInfo *pi)
88{
89 return XmlReadValue(node, pi->Name);
90}
91
92
93
94
95
96
97class TextPropPanel : public PropertyPanel
98{
99 public:
100 TextPropPanel(wxWindow *parent, PropertyHandler *hnd, PropsListInfo *pli) : PropertyPanel(parent, hnd, pli)
101 {
102 wxSizer *sz = new wxBoxSizer(wxVERTICAL);
103 wxTextCtrl *tc;
104
105 sz->Add(new wxStaticText(this, -1, _("Value:")), 0, wxLEFT, 5);
106 sz->Add(tc = new wxTextCtrl(this, ID_EDITCTRL, XmlReadValue(pli->m_Node, pli->m_PropInfo->Name)), 0, wxALL|wxEXPAND, 5);
107 tc->SetFocus();
108
109 SetAutoLayout(TRUE);
110 SetSizer(sz);
111 Layout();
112 }
113
114 void OnEdit(wxCommandEvent &event)
115 {
116 Update(((wxTextCtrl*)event.GetEventObject())->GetValue());
117 }
118
119 DECLARE_EVENT_TABLE()
120};
121
122BEGIN_EVENT_TABLE(TextPropPanel, PropertyPanel)
123 EVT_TEXT(ID_EDITCTRL, TextPropPanel::OnEdit)
124END_EVENT_TABLE()
125
126
127wxPanel *TextPropertyHandler::CreateEditPanel(wxWindow *parent, PropsListInfo *pli)
128{
129 return new TextPropPanel(parent, this, pli);
130}
131
132
133
134
135
136
137
138
139
140
141
142class CoordPropPanel : public PropertyPanel
143{
144 public:
145 CoordPropPanel(wxWindow *parent, PropertyHandler *hnd, PropsListInfo *pli) : PropertyPanel(parent, hnd, pli)
146 {
147 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
148 wxSizer *sz = new wxBoxSizer(wxHORIZONTAL);
149 m_ed1 = m_ed2 = NULL; m_chb = NULL;
150
151 sz->Add(new wxStaticText(this, -1, _("X:")), 0, wxLEFT|wxRIGHT|wxALIGN_CENTER, 5);
152 sz->Add(m_ed1 = new wxTextCtrl(this, ID_XEDIT, "",
153 wxDefaultPosition, wxDefaultSize, 0,
154 wxTextValidator(wxFILTER_NUMERIC)),
155 1, wxRIGHT, 5);
156 m_ed1->SetFocus();
157
158 sz->Add(new wxStaticText(this, -1, _("Y:")), 0, wxLEFT|wxRIGHT|wxALIGN_CENTER, 5);
159 sz->Add(m_ed2 = new wxTextCtrl(this, ID_YEDIT, "",
160 wxDefaultPosition, wxDefaultSize, 0,
161 wxTextValidator(wxFILTER_NUMERIC)),
162 1, wxRIGHT, 5);
163 sizer->Add(sz, 0, wxEXPAND|wxTOP, 5);
164
165 sizer->Add(m_chb = new wxCheckBox(this, ID_USEDLG, _("Use dialog units")), 0, wxLEFT|wxTOP, 5);
166
167 SetAutoLayout(TRUE);
168 SetSizer(sizer);
169 Layout();
170
171 wxString val = XmlReadValue(pli->m_Node, pli->m_PropInfo->Name);
172 m_chb->SetValue(val.Len()==0 || val[val.Len()-1] == 'd');
173 m_ed1->SetValue(val.BeforeFirst(','));
174 m_ed2->SetValue(val.AfterFirst(',').BeforeFirst('d'));
175 }
176
177 void OnEdit(wxCommandEvent &event)
178 {
179 wxString val, v1, v2;
180
181 if (m_ed1 == NULL || m_ed2 == NULL || m_chb == NULL) return;
182
183 v1 = m_ed1->GetValue();
184 v2 = m_ed2->GetValue();
185 if (v1.IsEmpty() || v2.IsEmpty()) return;
186 val = v1 + "," + v2;
187 if (m_chb->GetValue()) val << 'd';
188 Update(val);
189 }
190
191 wxTextCtrl *m_ed1, *m_ed2;
192 wxCheckBox *m_chb;
193
194 DECLARE_EVENT_TABLE()
195};
196
197BEGIN_EVENT_TABLE(CoordPropPanel, PropertyPanel)
198 EVT_TEXT(ID_XEDIT, CoordPropPanel::OnEdit)
199 EVT_TEXT(ID_YEDIT, CoordPropPanel::OnEdit)
200 EVT_CHECKBOX(ID_USEDLG, CoordPropPanel::OnEdit)
201END_EVENT_TABLE()
202
203wxPanel *CoordPropertyHandler::CreateEditPanel(wxWindow *parent, PropsListInfo *pli)
204{
205 return new CoordPropPanel(parent, this, pli);
206}
207
208
209
210
211
212
213
214
215class BoolPropPanel : public PropertyPanel
216{
217 public:
218 BoolPropPanel(wxWindow *parent, PropertyHandler *hnd, PropsListInfo *pli) : PropertyPanel(parent, hnd, pli)
219 {
220 m_chb = NULL;
221 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
222 sizer->Add(m_chb = new wxCheckBox(this, ID_BOOLVAL, _("On/Yes/True")), 0, wxLEFT|wxTOP, 5);
223 SetAutoLayout(TRUE);
224 SetSizer(sizer);
225 Layout();
226 m_chb->SetValue(XmlReadValue(pli->m_Node, pli->m_PropInfo->Name) == "1");
227 }
228
229 void OnEdit(wxCommandEvent &event)
230 {
231 if (m_chb == NULL) return;
232 if (m_chb->GetValue()) Update("1");
233 else Update("0");
234 }
235
236 wxCheckBox *m_chb;
237
238 DECLARE_EVENT_TABLE()
239};
240
241BEGIN_EVENT_TABLE(BoolPropPanel, PropertyPanel)
242 EVT_CHECKBOX(ID_BOOLVAL, BoolPropPanel::OnEdit)
243END_EVENT_TABLE()
244
245wxPanel *BoolPropertyHandler::CreateEditPanel(wxWindow *parent, PropsListInfo *pli)
246{
247 return new BoolPropPanel(parent, this, pli);
248}
249
250wxString BoolPropertyHandler::GetBriefValue(wxXmlNode *node, PropertyInfo *pi)
251{
252 wxString v = XmlReadValue(node, pi->Name);
253 if (v.IsEmpty()) return wxEmptyString;
254 else if (v == "1") return "true";
255 else return "false";
256}
257
258
259
260
261
262
263
264
265class FlagsPropPanel : public PropertyPanel
266{
267 public:
268 FlagsPropPanel(wxWindow *parent, PropertyHandler *hnd, PropsListInfo *pli) : PropertyPanel(parent, hnd, pli)
269 {
270 m_chl = NULL;
271 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
272 sizer->Add(m_chl = new wxCheckListBox(this, ID_CHECKLIST), 1, wxEXPAND|wxALL, 5);
273 SetAutoLayout(TRUE);
274 SetSizer(sizer);
275 Layout();
276
277 {
278 wxStringTokenizer tkn(pli->m_PropInfo->MoreInfo, ",");
279 wxString s;
280 while (tkn.HasMoreTokens())
281 {
282 s = tkn.GetNextToken();
283 m_chl->Append(s);
284 m_flags.Add(s);
285 }
286 }
287
288 {
289 wxStringTokenizer tkn(XmlReadValue(pli->m_Node, pli->m_PropInfo->Name), "| ");
290 int index;
291 while (tkn.HasMoreTokens())
292 {
293 index = m_flags.Index(tkn.GetNextToken());
294 if (index != wxNOT_FOUND)
295 m_chl->Check(index);
296 }
297 }
298 }
299
300 void OnEdit(wxCommandEvent &event)
301 {
302 wxString s;
303 bool first = TRUE;
304
305 for (size_t i = 0; i < m_flags.GetCount(); i++)
306 {
307 if (m_chl->IsChecked(i))
308 {
309 if (!first) s << '|';
310 s << m_flags[i];
311 first = FALSE;
312 }
313 }
314 Update(s);
315 if (m_PLI->m_PropInfo->Name == "orient")
316 // FIXME - dirty hack related to sizers
317 EditorFrame::Get()->NotifyChanged(CHANGED_TREE_SELECTED_ICON);
318 }
319
320 wxCheckListBox *m_chl;
321 wxArrayString m_flags;
322
323 DECLARE_EVENT_TABLE()
324};
325
326BEGIN_EVENT_TABLE(FlagsPropPanel, PropertyPanel)
327 EVT_CHECKLISTBOX(ID_CHECKLIST, FlagsPropPanel::OnEdit)
328END_EVENT_TABLE()
329
330wxPanel *FlagsPropertyHandler::CreateEditPanel(wxWindow *parent, PropsListInfo *pli)
331{
332 return new FlagsPropPanel(parent, this, pli);
333}
ab13d1c5
VS
334
335
336
337
338wxPanel *NotImplPropertyHandler::CreateEditPanel(wxWindow *parent, PropsListInfo *pli)
339{
340 wxPanel *p = new wxPanel(parent);
341 wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
342 sizer->Add(new wxStaticText(p, -1, _("Sorry, this is not supported.\nYou have to edit XML code directly.")), 1, wxEXPAND|wxALL, 5);
343 p->SetAutoLayout(TRUE);
344 p->SetSizer(sizer);
345 p->Layout();
346 return p;
347}