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