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