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