]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/winstyle.cpp
reverted Julian's unintentional breakage of wxChoice
[wxWidgets.git] / utils / dialoged / src / winstyle.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: winstyle.cpp
3 // Purpose: Window styles
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "winstyle.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/listctrl.h"
28 #include "wx/treectrl.h"
29
30 #include <ctype.h>
31 #include <stdlib.h>
32 #include <math.h>
33 #include <string.h>
34
35 #include "winstyle.h"
36
37 /*
38 * Styles
39 */
40
41 /* wxListBox */
42 static wxWindowStylePair g_WindowStylesListBox[] = {
43 { "wxLB_SINGLE", wxLB_SINGLE },
44 { "wxLB_MULTIPLE", wxLB_MULTIPLE },
45 { "wxLB_EXTENDED", wxLB_EXTENDED },
46 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB },
47 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB },
48 { "wxLB_SORT", wxLB_SORT },
49 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW },
50 { "wxLB_HSCROLL", wxLB_HSCROLL }
51 };
52
53 int g_WindowStylesListBoxCount = sizeof(g_WindowStylesListBox)/sizeof(wxWindowStylePair) ;
54
55 /* wxComboxBox */
56 static wxWindowStylePair g_WindowStylesComboBox[] = {
57 { "wxCB_SIMPLE", wxCB_SIMPLE },
58 { "wxCB_DROPDOWN", wxCB_DROPDOWN },
59 { "wxCB_READONLY", wxCB_READONLY },
60 { "wxCB_SORT", wxCB_SORT }
61 };
62
63 int g_WindowStylesComboBoxCount = sizeof(g_WindowStylesComboBox)/sizeof(wxWindowStylePair) ;
64
65 #if 0
66 /* wxChoice */
67 static wxWindowStylePair g_WindowStylesChoice[] = {
68 };
69
70 int g_WindowStylesChoiceCount = sizeof(g_WindowStylesChoice)/sizeof(wxWindowStylePair) ;
71 #endif
72
73 /* wxGauge */
74 static wxWindowStylePair g_WindowStylesGauge[] = {
75 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR },
76 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL },
77 { "wxGA_VERTICAL", wxGA_VERTICAL }
78 };
79
80 int g_WindowStylesGaugeCount = sizeof(g_WindowStylesGauge)/sizeof(wxWindowStylePair) ;
81
82 /* wxTextCtrl */
83 static wxWindowStylePair g_WindowStylesTextCtrl[] = {
84 // { "wxPASSWORD", wxPASSWORD},
85 // { "wxPROCESS_ENTER", wxPROCESS_ENTER},
86 { "wxTE_PASSWORD", wxTE_PASSWORD},
87 { "wxTE_READONLY", wxTE_READONLY},
88 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER},
89 { "wxTE_MULTILINE", wxTE_MULTILINE}
90 };
91
92 int g_WindowStylesTextCtrlCount = sizeof(g_WindowStylesTextCtrl)/sizeof(wxWindowStylePair) ;
93
94 /* wxRadioButton */
95 static wxWindowStylePair g_WindowStylesRadioButton[] = {
96 { "wxRB_GROUP", wxRB_GROUP }
97 };
98
99 int g_WindowStylesRadioButtonCount = sizeof(g_WindowStylesRadioButton)/sizeof(wxWindowStylePair) ;
100
101 /* wxRadioBox */
102 static wxWindowStylePair g_WindowStylesRadioBox[] = {
103 { "wxRA_SPECIFY_COLS", wxRA_SPECIFY_COLS },
104 { "wxRA_SPECIFY_ROWS", wxRA_SPECIFY_ROWS }
105 /*
106 ,
107 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL },
108 { "wxRA_VERTICAL", wxRA_VERTICAL }
109 */
110 };
111
112 int g_WindowStylesRadioBoxCount = sizeof(g_WindowStylesRadioBox)/sizeof(wxWindowStylePair) ;
113
114 /* wxSlider */
115 static wxWindowStylePair g_WindowStylesSlider[] = {
116 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL },
117 { "wxSL_VERTICAL", wxSL_VERTICAL },
118 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS },
119 { "wxSL_LABELS", wxSL_LABELS },
120 { "wxSL_LEFT", wxSL_LEFT },
121 { "wxSL_TOP", wxSL_TOP },
122 { "wxSL_RIGHT", wxSL_RIGHT },
123 { "wxSL_BOTTOM", wxSL_BOTTOM },
124 { "wxSL_BOTH", wxSL_BOTH },
125 { "wxSL_SELRANGE", wxSL_SELRANGE }
126 };
127
128 int g_WindowStylesSliderCount = sizeof(g_WindowStylesSlider)/sizeof(wxWindowStylePair) ;
129
130 /* wxScrollBar */
131 static wxWindowStylePair g_WindowStylesScrollBar[] = {
132 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL },
133 { "wxSB_VERTICAL", wxSB_VERTICAL }
134 };
135
136 int g_WindowStylesScrollBarCount = sizeof(g_WindowStylesScrollBar)/sizeof(wxWindowStylePair) ;
137
138 /* wxButton */
139 static wxWindowStylePair g_WindowStylesButton[] = {
140 { "wxBU_AUTODRAW", wxBU_AUTODRAW },
141 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW }
142 };
143
144 int g_WindowStylesButtonCount = sizeof(g_WindowStylesButton)/sizeof(wxWindowStylePair) ;
145
146 /* wxTreeCtrl */
147 static wxWindowStylePair g_WindowStylesTreeCtrl[] = {
148 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS },
149 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS },
150 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT }
151 };
152
153 int g_WindowStylesTreeCtrlCount = sizeof(g_WindowStylesTreeCtrl)/sizeof(wxWindowStylePair) ;
154
155 /* wxListCtrl */
156 static wxWindowStylePair g_WindowStylesListCtrl[] = {
157 { "wxLC_ICON", wxLC_ICON },
158 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON },
159 { "wxLC_LIST", wxLC_LIST },
160 { "wxLC_REPORT", wxLC_REPORT },
161 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP },
162 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT },
163 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE },
164 { "wxLC_USER_TEXT", wxLC_USER_TEXT },
165 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS },
166 { "wxLC_NO_HEADER", wxLC_NO_HEADER },
167 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER },
168 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL },
169 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING },
170 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING }
171 };
172
173 int g_WindowStylesListCtrlCount = sizeof(g_WindowStylesListCtrl)/sizeof(wxWindowStylePair) ;
174
175 /* wxSpinButton */
176 static wxWindowStylePair g_WindowStylesSpinButton[] = {
177 { "wxSP_VERTICAL", wxSP_VERTICAL},
178 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL},
179 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS},
180 { "wxSP_WRAP", wxSP_WRAP}
181 };
182
183 int g_WindowStylesSpinButtonCount = sizeof(g_WindowStylesSpinButton)/sizeof(wxWindowStylePair) ;
184
185 /* wxSplitterWindow */
186 static wxWindowStylePair g_WindowStylesSplitterWindow[] = {
187 { "wxSP_NOBORDER", wxSP_NOBORDER},
188 { "wxSP_3D", wxSP_3D},
189 { "wxSP_BORDER", wxSP_BORDER}
190 };
191
192 int g_WindowStylesSplitterWindowCount = sizeof(g_WindowStylesSplitterWindow)/sizeof(wxWindowStylePair) ;
193
194 /* wxTabCtrl */
195 static wxWindowStylePair g_WindowStylesTabCtrl[] = {
196 { "wxTC_MULTILINE", wxTC_MULTILINE},
197 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY},
198 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH},
199 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW}
200 };
201
202 int g_WindowStylesTabCtrlCount = sizeof(g_WindowStylesTabCtrl)/sizeof(wxWindowStylePair) ;
203
204 /* wxStatusBar95 */
205 static wxWindowStylePair g_WindowStylesStatusBar[] = {
206 { "wxST_SIZEGRIP", wxST_SIZEGRIP}
207 };
208
209 int g_WindowStylesStatusBarCount = sizeof(g_WindowStylesStatusBar)/sizeof(wxWindowStylePair) ;
210
211 /* wxControl */
212 static wxWindowStylePair g_WindowStylesControl[] = {
213 { "wxFIXED_LENGTH", wxFIXED_LENGTH},
214 { "wxALIGN_LEFT", wxALIGN_LEFT},
215 { "wxALIGN_CENTRE", wxALIGN_CENTRE},
216 { "wxALIGN_RIGHT", wxALIGN_RIGHT},
217 { "wxCOLOURED", wxCOLOURED}
218 };
219
220 int g_WindowStylesControlCount = sizeof(g_WindowStylesControl)/sizeof(wxWindowStylePair) ;
221
222 /* wxToolBar */
223 static wxWindowStylePair g_WindowStylesToolBar[] = {
224 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS},
225 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL},
226 { "wxTB_VERTICAL", wxTB_VERTICAL},
227 { "wxTB_FLAT", wxTB_FLAT}
228 };
229
230 int g_WindowStylesToolBarCount = sizeof(g_WindowStylesToolBar)/sizeof(wxWindowStylePair) ;
231
232 /* Frame/dialog */
233 static wxWindowStylePair g_WindowStylesDialog[] = {
234 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP},
235 { "wxCAPTION", wxCAPTION},
236 { "wxICONIZE", wxICONIZE},
237 { "wxMINIMIZE", wxICONIZE},
238 { "wxMAXIMIZE", wxMAXIMIZE},
239 { "wxTHICK_FRAME", wxTHICK_FRAME},
240 { "wxRESIZE_BORDER", wxRESIZE_BORDER},
241 { "wxSYSTEM_MENU", wxSYSTEM_MENU},
242 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX},
243 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX},
244 { "wxDIALOG_MODAL", wxDIALOG_MODAL},
245 { "wxRESIZE_BOX", wxRESIZE_BOX}
246 };
247
248 int g_WindowStylesDialogCount = sizeof(g_WindowStylesDialog)/sizeof(wxWindowStylePair) ;
249
250 /* Generic */
251 static wxWindowStylePair g_WindowStylesWindow[] = {
252 { "wxBORDER", wxBORDER},
253 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER},
254 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER},
255 { "wxRAISED_BORDER", wxRAISED_BORDER},
256 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER},
257 { "wxSTATIC_BORDER", wxSTATIC_BORDER},
258 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW},
259 { "wxNO_BORDER", wxNO_BORDER},
260 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN}
261
262 /* Would be duplicated with e.g. wxLB_HSCROLL
263 { "wxVSCROLL", wxVSCROLL },
264 { "wxHSCROLL", wxHSCROLL }
265 */
266 };
267
268 int g_WindowStylesWindowCount = sizeof(g_WindowStylesWindow)/sizeof(wxWindowStylePair) ;
269
270 /*
271 * A table holding all class style objects
272 */
273
274
275 wxWindowStyleTable::wxWindowStyleTable():
276 m_classes(wxKEY_STRING)
277 {
278 }
279
280 wxWindowStyleTable::~wxWindowStyleTable()
281 {
282 ClearTable();
283 }
284
285 void wxWindowStyleTable::Init()
286 {
287 AddStyles("wxWindow", g_WindowStylesWindowCount, g_WindowStylesWindow);
288 AddStyles("wxDialog", g_WindowStylesDialogCount, g_WindowStylesDialog);
289 AddStyles("wxButton", g_WindowStylesButtonCount, g_WindowStylesButton);
290 AddStyles("wxTextCtrl", g_WindowStylesTextCtrlCount, g_WindowStylesTextCtrl);
291 AddStyles("wxSpinButton", g_WindowStylesSpinButtonCount, g_WindowStylesSpinButton);
292 AddStyles("wxListBox", g_WindowStylesListBoxCount, g_WindowStylesListBox);
293 AddStyles("wxRadioButton", g_WindowStylesRadioButtonCount, g_WindowStylesRadioButton);
294 AddStyles("wxRadioBox", g_WindowStylesRadioBoxCount, g_WindowStylesRadioBox);
295 AddStyles("wxControl", g_WindowStylesControlCount, g_WindowStylesControl);
296 AddStyles("wxListCtrl", g_WindowStylesListCtrlCount, g_WindowStylesListCtrl);
297 AddStyles("wxTreeCtrl", g_WindowStylesTreeCtrlCount, g_WindowStylesTreeCtrl);
298 AddStyles("wxSlider", g_WindowStylesSliderCount, g_WindowStylesSlider);
299 AddStyles("wxGauge", g_WindowStylesGaugeCount, g_WindowStylesGauge);
300 AddStyles("wxComboBox", g_WindowStylesComboBoxCount, g_WindowStylesComboBox);
301 // AddStyles("wxChoice", g_WindowStylesChoice, g_WindowStylesChoice);
302 AddStyles("wxScrollBar", g_WindowStylesScrollBarCount, g_WindowStylesScrollBar);
303 }
304
305 // Operations
306 void wxWindowStyleTable::ClearTable()
307 {
308 wxNode* node = m_classes.First();
309 while (node)
310 {
311 wxWindowStyleClass* styleClass = (wxWindowStyleClass*) node->Data();
312 delete styleClass;
313 node = node->Next();
314 }
315 m_classes.Clear();
316 }
317
318 void wxWindowStyleTable::AddStyles(const wxString& className, int n, wxWindowStylePair *styles)
319 {
320 wxWindowStyleClass* styleClass = new wxWindowStyleClass(n, styles);
321 m_classes.Append(className, styleClass);
322 }
323
324 wxWindowStyleClass* wxWindowStyleTable::FindClass(const wxString& className)
325 {
326 wxNode* node = m_classes.Find(className);
327 if (node)
328 {
329 wxWindowStyleClass* styleClass = (wxWindowStyleClass*) node->Data();
330 return styleClass;
331 }
332 else
333 return NULL;
334 }
335
336 bool wxWindowStyleTable::GenerateStyleStrings(const wxString& className, long windowStyle, char *buf)
337 {
338 wxWindowStyleClass* styleClass = FindClass(className);
339 if (!styleClass)
340 return FALSE;
341
342 styleClass->GenerateStyleStrings(windowStyle, buf);
343 return TRUE;
344 }
345
346 /*
347 * Holds all the styles for a particular class
348 */
349
350 wxWindowStyleClass::wxWindowStyleClass(int n, wxWindowStylePair *styles)
351 {
352 m_styleCount = n;
353 m_styles = styles;
354 /*
355 m_styles = new wxWindowStylePair[n];
356 int i;
357 for (i = 0; i < n; i++)
358 m_styles[i] = styles[i];
359 */
360 }
361
362 wxWindowStyleClass::~wxWindowStyleClass()
363 {
364 }
365
366 void wxWindowStyleClass::GenerateStyleStrings(long windowStyle, char *buf)
367 {
368 int i;
369 for (i = 0; i < m_styleCount; i++)
370 GenerateStyle(buf, windowStyle, m_styles[i].m_styleId, m_styles[i].m_styleName);
371 }
372
373 bool wxWindowStyleClass::GenerateStyle(char *buf, long windowStyle, long flag, const wxString& strStyle)
374 {
375 // Ignore zero flags
376 if (flag == 0)
377 return TRUE;
378
379 if ((windowStyle & flag) == flag)
380 {
381 if (strlen(buf) > 0)
382 strcat(buf, " | ");
383 strcat(buf, (const char*) strStyle);
384 return TRUE;
385 }
386 else
387 return FALSE;
388 }
389