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