]> git.saurik.com Git - wxWidgets.git/blame - utils/dialoged/src/winstyle.cpp
Added static wxBuffer
[wxWidgets.git] / utils / dialoged / src / winstyle.cpp
CommitLineData
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"
5638d705
JS
25#endif
26
0f02d3d0 27#include "wx/listctrl.h"
7d12127f 28#include "wx/treectrl.h"
7c23a0b0
JS
29
30#include <ctype.h>
31#include <stdlib.h>
32#include <math.h>
33#include <string.h>
34
35#include "winstyle.h"
36
37/*
f6bcfd97
BP
38* Styles
39*/
7c23a0b0 40
f6bcfd97 41/* wxListBox */
7c23a0b0 42static wxWindowStylePair g_WindowStylesListBox[] = {
f6bcfd97
BP
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 }
7c23a0b0
JS
51};
52
53int g_WindowStylesListBoxCount = sizeof(g_WindowStylesListBox)/sizeof(wxWindowStylePair) ;
f6bcfd97
BP
54
55/* wxComboxBox */
7c23a0b0 56static wxWindowStylePair g_WindowStylesComboBox[] = {
f6bcfd97
BP
57 { "wxCB_SIMPLE", wxCB_SIMPLE },
58 { "wxCB_DROPDOWN", wxCB_DROPDOWN },
59 { "wxCB_READONLY", wxCB_READONLY },
60 { "wxCB_SORT", wxCB_SORT }
7c23a0b0
JS
61};
62
63int g_WindowStylesComboBoxCount = sizeof(g_WindowStylesComboBox)/sizeof(wxWindowStylePair) ;
64
65#if 0
f6bcfd97 66/* wxChoice */
7c23a0b0
JS
67static wxWindowStylePair g_WindowStylesChoice[] = {
68};
69
70int g_WindowStylesChoiceCount = sizeof(g_WindowStylesChoice)/sizeof(wxWindowStylePair) ;
71#endif
f6bcfd97
BP
72
73/* wxGauge */
7c23a0b0 74static wxWindowStylePair g_WindowStylesGauge[] = {
f6bcfd97
BP
75 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR },
76 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL },
77 { "wxGA_VERTICAL", wxGA_VERTICAL }
7c23a0b0
JS
78};
79
80int g_WindowStylesGaugeCount = sizeof(g_WindowStylesGauge)/sizeof(wxWindowStylePair) ;
81
f6bcfd97 82/* wxTextCtrl */
7c23a0b0 83static wxWindowStylePair g_WindowStylesTextCtrl[] = {
f6bcfd97
BP
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}
7c23a0b0
JS
90};
91
92int g_WindowStylesTextCtrlCount = sizeof(g_WindowStylesTextCtrl)/sizeof(wxWindowStylePair) ;
93
f6bcfd97 94/* wxRadioButton */
7c23a0b0 95static wxWindowStylePair g_WindowStylesRadioButton[] = {
f6bcfd97 96 { "wxRB_GROUP", wxRB_GROUP }
7c23a0b0
JS
97};
98
99int g_WindowStylesRadioButtonCount = sizeof(g_WindowStylesRadioButton)/sizeof(wxWindowStylePair) ;
100
f6bcfd97 101/* wxRadioBox */
7c23a0b0 102static wxWindowStylePair g_WindowStylesRadioBox[] = {
f6bcfd97
BP
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 */
7c23a0b0
JS
110};
111
112int g_WindowStylesRadioBoxCount = sizeof(g_WindowStylesRadioBox)/sizeof(wxWindowStylePair) ;
113
f6bcfd97 114/* wxSlider */
7c23a0b0 115static wxWindowStylePair g_WindowStylesSlider[] = {
f6bcfd97
BP
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 }
7c23a0b0
JS
126};
127
128int g_WindowStylesSliderCount = sizeof(g_WindowStylesSlider)/sizeof(wxWindowStylePair) ;
129
f6bcfd97 130/* wxScrollBar */
7c23a0b0 131static wxWindowStylePair g_WindowStylesScrollBar[] = {
f6bcfd97
BP
132 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL },
133 { "wxSB_VERTICAL", wxSB_VERTICAL }
7c23a0b0
JS
134};
135
136int g_WindowStylesScrollBarCount = sizeof(g_WindowStylesScrollBar)/sizeof(wxWindowStylePair) ;
137
f6bcfd97 138/* wxButton */
7c23a0b0 139static wxWindowStylePair g_WindowStylesButton[] = {
f6bcfd97
BP
140 { "wxBU_AUTODRAW", wxBU_AUTODRAW },
141 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW }
7c23a0b0
JS
142};
143
144int g_WindowStylesButtonCount = sizeof(g_WindowStylesButton)/sizeof(wxWindowStylePair) ;
145
f6bcfd97 146/* wxTreeCtrl */
7c23a0b0 147static wxWindowStylePair g_WindowStylesTreeCtrl[] = {
f6bcfd97
BP
148 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS },
149 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS },
150 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT }
7c23a0b0
JS
151};
152
153int g_WindowStylesTreeCtrlCount = sizeof(g_WindowStylesTreeCtrl)/sizeof(wxWindowStylePair) ;
154
f6bcfd97 155/* wxListCtrl */
7c23a0b0 156static wxWindowStylePair g_WindowStylesListCtrl[] = {
f6bcfd97
BP
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 }
7c23a0b0
JS
171};
172
173int g_WindowStylesListCtrlCount = sizeof(g_WindowStylesListCtrl)/sizeof(wxWindowStylePair) ;
174
f6bcfd97 175/* wxSpinButton */
7c23a0b0 176static wxWindowStylePair g_WindowStylesSpinButton[] = {
f6bcfd97
BP
177 { "wxSP_VERTICAL", wxSP_VERTICAL},
178 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL},
179 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS},
180 { "wxSP_WRAP", wxSP_WRAP}
7c23a0b0
JS
181};
182
183int g_WindowStylesSpinButtonCount = sizeof(g_WindowStylesSpinButton)/sizeof(wxWindowStylePair) ;
184
f6bcfd97 185/* wxSplitterWindow */
7c23a0b0 186static wxWindowStylePair g_WindowStylesSplitterWindow[] = {
f6bcfd97
BP
187 { "wxSP_NOBORDER", wxSP_NOBORDER},
188 { "wxSP_3D", wxSP_3D},
189 { "wxSP_BORDER", wxSP_BORDER}
7c23a0b0
JS
190};
191
192int g_WindowStylesSplitterWindowCount = sizeof(g_WindowStylesSplitterWindow)/sizeof(wxWindowStylePair) ;
193
f6bcfd97 194/* wxTabCtrl */
7c23a0b0 195static wxWindowStylePair g_WindowStylesTabCtrl[] = {
f6bcfd97
BP
196 { "wxTC_MULTILINE", wxTC_MULTILINE},
197 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY},
198 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH},
199 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW}
7c23a0b0
JS
200};
201
202int g_WindowStylesTabCtrlCount = sizeof(g_WindowStylesTabCtrl)/sizeof(wxWindowStylePair) ;
203
f6bcfd97 204/* wxStatusBar95 */
7c23a0b0 205static wxWindowStylePair g_WindowStylesStatusBar[] = {
f6bcfd97 206 { "wxST_SIZEGRIP", wxST_SIZEGRIP}
7c23a0b0
JS
207};
208
209int g_WindowStylesStatusBarCount = sizeof(g_WindowStylesStatusBar)/sizeof(wxWindowStylePair) ;
210
f6bcfd97 211/* wxControl */
7c23a0b0 212static wxWindowStylePair g_WindowStylesControl[] = {
f6bcfd97
BP
213 { "wxFIXED_LENGTH", wxFIXED_LENGTH},
214 { "wxALIGN_LEFT", wxALIGN_LEFT},
215 { "wxALIGN_CENTRE", wxALIGN_CENTRE},
216 { "wxALIGN_RIGHT", wxALIGN_RIGHT},
217 { "wxCOLOURED", wxCOLOURED}
7c23a0b0
JS
218};
219
220int g_WindowStylesControlCount = sizeof(g_WindowStylesControl)/sizeof(wxWindowStylePair) ;
f6bcfd97
BP
221
222/* wxToolBar */
7c23a0b0 223static wxWindowStylePair g_WindowStylesToolBar[] = {
f6bcfd97
BP
224 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS},
225 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL},
226 { "wxTB_VERTICAL", wxTB_VERTICAL},
227 { "wxTB_FLAT", wxTB_FLAT}
7c23a0b0
JS
228};
229
230int g_WindowStylesToolBarCount = sizeof(g_WindowStylesToolBar)/sizeof(wxWindowStylePair) ;
231
f6bcfd97 232/* Frame/dialog */
7c23a0b0 233static wxWindowStylePair g_WindowStylesDialog[] = {
f6bcfd97
BP
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}
7c23a0b0
JS
246};
247
248int g_WindowStylesDialogCount = sizeof(g_WindowStylesDialog)/sizeof(wxWindowStylePair) ;
249
f6bcfd97 250/* Generic */
7c23a0b0 251static wxWindowStylePair g_WindowStylesWindow[] = {
f6bcfd97
BP
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 */
7c23a0b0
JS
266};
267
268int g_WindowStylesWindowCount = sizeof(g_WindowStylesWindow)/sizeof(wxWindowStylePair) ;
269
270/*
f6bcfd97
BP
271* A table holding all class style objects
272*/
7c23a0b0
JS
273
274
275wxWindowStyleTable::wxWindowStyleTable():
f6bcfd97 276m_classes(wxKEY_STRING)
7c23a0b0
JS
277{
278}
279
280wxWindowStyleTable::~wxWindowStyleTable()
281{
282 ClearTable();
283}
284
285void 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);
f6bcfd97 301 // AddStyles("wxChoice", g_WindowStylesChoice, g_WindowStylesChoice);
7c23a0b0
JS
302 AddStyles("wxScrollBar", g_WindowStylesScrollBarCount, g_WindowStylesScrollBar);
303}
304
305// Operations
306void 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
318void 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
324wxWindowStyleClass* 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
336bool wxWindowStyleTable::GenerateStyleStrings(const wxString& className, long windowStyle, char *buf)
337{
338 wxWindowStyleClass* styleClass = FindClass(className);
339 if (!styleClass)
340 return FALSE;
f6bcfd97 341
7c23a0b0
JS
342 styleClass->GenerateStyleStrings(windowStyle, buf);
343 return TRUE;
344}
345
346/*
f6bcfd97
BP
347* Holds all the styles for a particular class
348*/
7c23a0b0
JS
349
350wxWindowStyleClass::wxWindowStyleClass(int n, wxWindowStylePair *styles)
351{
352 m_styleCount = n;
353 m_styles = styles;
f6bcfd97 354 /*
7c23a0b0
JS
355 m_styles = new wxWindowStylePair[n];
356 int i;
357 for (i = 0; i < n; i++)
f6bcfd97
BP
358 m_styles[i] = styles[i];
359 */
7c23a0b0
JS
360}
361
362wxWindowStyleClass::~wxWindowStyleClass()
363{
364}
365
366void 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
373bool wxWindowStyleClass::GenerateStyle(char *buf, long windowStyle, long flag, const wxString& strStyle)
374{
375 // Ignore zero flags
376 if (flag == 0)
377 return TRUE;
f6bcfd97
BP
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;
7c23a0b0
JS
388}
389