/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/control.cpp
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/control.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (9 years, 11 months ago) by william
File size: 15075 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/control.cpp
3 // Purpose: wxControl class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id: control.cpp 54424 2008-06-29 21:46:29Z VZ $
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_CONTROLS
28
29 #include "wx/control.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
33 #include "wx/event.h"
34 #include "wx/app.h"
35 #include "wx/dcclient.h"
36 #include "wx/log.h"
37 #include "wx/settings.h"
38 #endif
39
40 #if wxUSE_LISTCTRL
41 #include "wx/listctrl.h"
42 #endif // wxUSE_LISTCTRL
43
44 #if wxUSE_TREECTRL
45 #include "wx/treectrl.h"
46 #endif // wxUSE_TREECTRL
47
48 #include "wx/msw/private.h"
49 #include "wx/msw/uxtheme.h"
50
51 // ----------------------------------------------------------------------------
52 // wxWin macros
53 // ----------------------------------------------------------------------------
54
55 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
56
57 // ============================================================================
58 // wxControl implementation
59 // ============================================================================
60
61 // ----------------------------------------------------------------------------
62 // wxControl ctor/dtor
63 // ----------------------------------------------------------------------------
64
65 wxControl::~wxControl()
66 {
67 m_isBeingDeleted = true;
68 }
69
70 // ----------------------------------------------------------------------------
71 // control window creation
72 // ----------------------------------------------------------------------------
73
74 bool wxControl::Create(wxWindow *parent,
75 wxWindowID id,
76 const wxPoint& pos,
77 const wxSize& size,
78 long style,
79 const wxValidator& wxVALIDATOR_PARAM(validator),
80 const wxString& name)
81 {
82 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
83 return false;
84
85 #if wxUSE_VALIDATORS
86 SetValidator(validator);
87 #endif
88
89 return true;
90 }
91
92 bool wxControl::MSWCreateControl(const wxChar *classname,
93 const wxString& label,
94 const wxPoint& pos,
95 const wxSize& size)
96 {
97 WXDWORD exstyle;
98 WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), &exstyle);
99
100 return MSWCreateControl(classname, msStyle, pos, size, label, exstyle);
101 }
102
103 bool wxControl::MSWCreateControl(const wxChar *classname,
104 WXDWORD style,
105 const wxPoint& pos,
106 const wxSize& size,
107 const wxString& label,
108 WXDWORD exstyle)
109 {
110 // if no extended style given, determine it ourselves
111 if ( exstyle == (WXDWORD)-1 )
112 {
113 exstyle = 0;
114 (void) MSWGetStyle(GetWindowStyle(), &exstyle);
115 }
116
117 // all controls should have this style
118 style |= WS_CHILD;
119
120 // create the control visible if it's currently shown for wxWidgets
121 if ( m_isShown )
122 {
123 style |= WS_VISIBLE;
124 }
125
126 // choose the position for the control: we have a problem with default size
127 // here as we can't calculate the best size before the control exists
128 // (DoGetBestSize() may need to use m_hWnd), so just choose the minimal
129 // possible but non 0 size because 0 window width/height result in problems
130 // elsewhere
131 int x = pos.x == wxDefaultCoord ? 0 : pos.x,
132 y = pos.y == wxDefaultCoord ? 0 : pos.y,
133 w = size.x == wxDefaultCoord ? 1 : size.x,
134 h = size.y == wxDefaultCoord ? 1 : size.y;
135
136 // ... and adjust it to account for a possible parent frames toolbar
137 AdjustForParentClientOrigin(x, y);
138
139 m_hWnd = (WXHWND)::CreateWindowEx
140 (
141 exstyle, // extended style
142 classname, // the kind of control to create
143 label, // the window name
144 style, // the window style
145 x, y, w, h, // the window position and size
146 GetHwndOf(GetParent()), // parent
147 (HMENU)GetId(), // child id
148 wxGetInstance(), // app instance
149 NULL // creation parameters
150 );
151
152 if ( !m_hWnd )
153 {
154 #ifdef __WXDEBUG__
155 wxFAIL_MSG(wxString::Format
156 (
157 _T("CreateWindowEx(\"%s\", flags=%08x, ex=%08x) failed"),
158 classname, (unsigned int)style, (unsigned int)exstyle
159 ));
160 #endif // __WXDEBUG__
161
162 return false;
163 }
164
165 #if !wxUSE_UNICODE
166 // Text labels starting with the character 0xff (which is a valid character
167 // in many code pages) don't appear correctly as CreateWindowEx() has some
168 // special treatment for this case, apparently the strings starting with -1
169 // are not really strings but something called "ordinals". There is no
170 // documentation about it but the fact is that the label gets mangled or
171 // not displayed at all if we don't do this, see #9572.
172 //
173 // Notice that 0xffff is not a valid Unicode character so the problem
174 // doesn't arise in Unicode build.
175 if ( !label.empty() && label[0] == -1 )
176 ::SetWindowText(GetHwnd(), label.c_str());
177 #endif // !wxUSE_UNICODE
178
179 // install wxWidgets window proc for this window
180 SubclassWin(m_hWnd);
181
182 // set up fonts and colours
183 InheritAttributes();
184 if ( !m_hasFont )
185 {
186 bool setFont = true;
187
188 wxFont font = GetDefaultAttributes().font;
189
190 // if we set a font for {list,tree}ctrls and the font size is changed in
191 // the display properties then the font size for these controls doesn't
192 // automatically adjust when they receive WM_SETTINGCHANGE
193
194 // FIXME: replace the dynamic casts with virtual function calls!!
195 #if wxUSE_LISTCTRL || wxUSE_TREECTRL
196 bool testFont = false;
197 #if wxUSE_LISTCTRL
198 if ( wxDynamicCastThis(wxListCtrl) )
199 testFont = true;
200 #endif // wxUSE_LISTCTRL
201 #if wxUSE_TREECTRL
202 if ( wxDynamicCastThis(wxTreeCtrl) )
203 testFont = true;
204 #endif // wxUSE_TREECTRL
205
206 if ( testFont )
207 {
208 // not sure if we need to explicitly set the font here for Win95/NT4
209 // but we definitely can't do it for any newer version
210 // see wxGetCCDefaultFont() in src/msw/settings.cpp for explanation
211 // of why this test works
212
213 // TODO: test Win95/NT4 to see if this is needed or breaks the
214 // font resizing as it does on newer versions
215 if ( font != wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) )
216 {
217 setFont = false;
218 }
219 }
220 #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL
221
222 if ( setFont )
223 {
224 SetFont(GetDefaultAttributes().font);
225 }
226 }
227
228 // set the size now if no initial size specified
229 SetInitialSize(size);
230
231 return true;
232 }
233
234 // ----------------------------------------------------------------------------
235 // various accessors
236 // ----------------------------------------------------------------------------
237
238 wxBorder wxControl::GetDefaultBorder() const
239 {
240 // we want to automatically give controls a sunken style (confusingly,
241 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
242 // which is not sunken at all under Windows XP -- rather, just the default)
243 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
244 return wxBORDER_SIMPLE;
245 #else
246 return wxBORDER_SUNKEN;
247 #endif
248 }
249
250 WXDWORD wxControl::MSWGetStyle(long style, WXDWORD *exstyle) const
251 {
252 long msStyle = wxWindow::MSWGetStyle(style, exstyle);
253
254 if ( AcceptsFocus() )
255 {
256 msStyle |= WS_TABSTOP;
257 }
258
259 return msStyle;
260 }
261
262 wxSize wxControl::DoGetBestSize() const
263 {
264 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
265 }
266
267 // This is a helper for all wxControls made with UPDOWN native control.
268 // In wxMSW it was only wxSpinCtrl derived from wxSpinButton but in
269 // WinCE of Smartphones this happens also for native wxTextCtrl,
270 // wxChoice and others.
271 wxSize wxControl::GetBestSpinnerSize(const bool is_vertical) const
272 {
273 // take size according to layout
274 wxSize bestSize(
275 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
276 0,GetCharHeight()
277 #else
278 ::GetSystemMetrics(is_vertical ? SM_CXVSCROLL : SM_CXHSCROLL),
279 ::GetSystemMetrics(is_vertical ? SM_CYVSCROLL : SM_CYHSCROLL)
280 #endif
281 );
282
283 // correct size as for undocumented MSW variants cases (WinCE and perhaps others)
284 if (bestSize.x==0)
285 bestSize.x = bestSize.y;
286 if (bestSize.y==0)
287 bestSize.y = bestSize.x;
288
289 // double size according to layout
290 if (is_vertical)
291 bestSize.y *= 2;
292 else
293 bestSize.x *= 2;
294
295 return bestSize;
296 }
297
298 /* static */ wxVisualAttributes
299 wxControl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
300 {
301 wxVisualAttributes attrs;
302
303 // old school (i.e. not "common") controls use the standard dialog font
304 // by default
305 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
306
307 // most, or at least many, of the controls use the same colours as the
308 // buttons -- others will have to override this (and possibly simply call
309 // GetCompositeControlsDefaultAttributes() from their versions)
310 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT);
311 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
312
313 return attrs;
314 }
315
316 // another version for the "composite", i.e. non simple controls
317 /* static */ wxVisualAttributes
318 wxControl::GetCompositeControlsDefaultAttributes(wxWindowVariant WXUNUSED(variant))
319 {
320 wxVisualAttributes attrs;
321 attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
322 attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
323 attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
324
325 return attrs;
326 }
327
328 // ----------------------------------------------------------------------------
329 // message handling
330 // ----------------------------------------------------------------------------
331
332 bool wxControl::ProcessCommand(wxCommandEvent& event)
333 {
334 return GetEventHandler()->ProcessEvent(event);
335 }
336
337 bool wxControl::MSWOnNotify(int idCtrl,
338 WXLPARAM lParam,
339 WXLPARAM* result)
340 {
341 wxEventType eventType wxDUMMY_INITIALIZE(wxEVT_NULL);
342
343 NMHDR *hdr = (NMHDR*) lParam;
344 switch ( hdr->code )
345 {
346 case NM_CLICK:
347 eventType = wxEVT_COMMAND_LEFT_CLICK;
348 break;
349
350 case NM_DBLCLK:
351 eventType = wxEVT_COMMAND_LEFT_DCLICK;
352 break;
353
354 case NM_RCLICK:
355 eventType = wxEVT_COMMAND_RIGHT_CLICK;
356 break;
357
358 case NM_RDBLCLK:
359 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
360 break;
361
362 case NM_SETFOCUS:
363 eventType = wxEVT_COMMAND_SET_FOCUS;
364 break;
365
366 case NM_KILLFOCUS:
367 eventType = wxEVT_COMMAND_KILL_FOCUS;
368 break;
369
370 case NM_RETURN:
371 eventType = wxEVT_COMMAND_ENTER;
372 break;
373
374 default:
375 return wxWindow::MSWOnNotify(idCtrl, lParam, result);
376 }
377
378 wxCommandEvent event(wxEVT_NULL, m_windowId);
379 event.SetEventType(eventType);
380 event.SetEventObject(this);
381
382 return GetEventHandler()->ProcessEvent(event);
383 }
384
385 WXHBRUSH wxControl::DoMSWControlColor(WXHDC pDC, wxColour colBg, WXHWND hWnd)
386 {
387 HDC hdc = (HDC)pDC;
388 if ( m_hasFgCol )
389 {
390 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
391 }
392
393 WXHBRUSH hbr = 0;
394 if ( !colBg.Ok() )
395 {
396 hbr = MSWGetBgBrush(pDC, hWnd);
397
398 // if the control doesn't have any bg colour, foreground colour will be
399 // ignored as the return value would be 0 -- so forcefully give it a
400 // non default background brush in this case
401 if ( !hbr && m_hasFgCol )
402 colBg = GetBackgroundColour();
403 }
404
405 // use the background colour override if a valid colour is given
406 if ( colBg.Ok() )
407 {
408 ::SetBkColor(hdc, wxColourToRGB(colBg));
409
410 // draw children with the same colour as the parent
411 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBg, wxSOLID);
412
413 hbr = (WXHBRUSH)brush->GetResourceHandle();
414
415 }
416
417 // if we use custom background, we should set foreground ourselves too
418 if ( hbr && !m_hasFgCol )
419 {
420 ::SetTextColor(hdc, ::GetSysColor(COLOR_WINDOWTEXT));
421 }
422 //else: already set above
423
424 return hbr;
425 }
426
427 WXHBRUSH wxControl::MSWControlColor(WXHDC pDC, WXHWND hWnd)
428 {
429 wxColour colBg;
430
431 if ( HasTransparentBackground() )
432 ::SetBkMode((HDC)pDC, TRANSPARENT);
433 else // if the control is opaque it shouldn't use the parents background
434 colBg = GetBackgroundColour();
435
436 return DoMSWControlColor(pDC, colBg, hWnd);
437 }
438
439 WXHBRUSH wxControl::MSWControlColorDisabled(WXHDC pDC)
440 {
441 return DoMSWControlColor(pDC,
442 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE),
443 GetHWND());
444 }
445
446 // ---------------------------------------------------------------------------
447 // global functions
448 // ---------------------------------------------------------------------------
449
450 // this is used in radiobox.cpp and slider95.cpp and should be removed as soon
451 // as it is not needed there any more!
452 //
453 // Call this repeatedly for several wnds to find the overall size
454 // of the widget.
455 // Call it initially with wxDefaultCoord for all values in rect.
456 // Keep calling for other widgets, and rect will be modified
457 // to calculate largest bounding rectangle.
458 void wxFindMaxSize(WXHWND wnd, RECT *rect)
459 {
460 int left = rect->left;
461 int right = rect->right;
462 int top = rect->top;
463 int bottom = rect->bottom;
464
465 GetWindowRect((HWND) wnd, rect);
466
467 if (left < 0)
468 return;
469
470 if (left < rect->left)
471 rect->left = left;
472
473 if (right > rect->right)
474 rect->right = right;
475
476 if (top < rect->top)
477 rect->top = top;
478
479 if (bottom > rect->bottom)
480 rect->bottom = bottom;
481 }
482
483 #endif // wxUSE_CONTROLS

  ViewVC Help
Powered by ViewVC 1.1.22