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