Fix fatal bug in wxGetWindowFromHWND() for radio buttons.
[wxWidgets.git] / src / msw / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/window.cpp
3 // Purpose: wxWindowMSW
4 // Author: Julian Smart
5 // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation
6 // Created: 04/01/98
7 // RCS-ID: $Id$
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 #include "wx/window.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/msw/wrapwin.h"
31 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/msw/missing.h"
33 #include "wx/accel.h"
34 #include "wx/menu.h"
35 #include "wx/dc.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcmemory.h"
38 #include "wx/utils.h"
39 #include "wx/app.h"
40 #include "wx/layout.h"
41 #include "wx/dialog.h"
42 #include "wx/frame.h"
43 #include "wx/listbox.h"
44 #include "wx/button.h"
45 #include "wx/msgdlg.h"
46 #include "wx/settings.h"
47 #include "wx/statbox.h"
48 #include "wx/sizer.h"
49 #include "wx/intl.h"
50 #include "wx/log.h"
51 #include "wx/textctrl.h"
52 #include "wx/menuitem.h"
53 #include "wx/module.h"
54 #endif
55
56 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
57 #include "wx/ownerdrw.h"
58 #endif
59
60 #include "wx/hashmap.h"
61 #include "wx/evtloop.h"
62 #include "wx/power.h"
63 #include "wx/sysopt.h"
64
65 #if wxUSE_DRAG_AND_DROP
66 #include "wx/dnd.h"
67 #endif
68
69 #if wxUSE_ACCESSIBILITY
70 #include "wx/access.h"
71 #include <ole2.h>
72 #include <oleacc.h>
73 #ifndef WM_GETOBJECT
74 #define WM_GETOBJECT 0x003D
75 #endif
76 #ifndef OBJID_CLIENT
77 #define OBJID_CLIENT 0xFFFFFFFC
78 #endif
79 #endif
80
81 #include "wx/msw/private.h"
82 #include "wx/msw/private/keyboard.h"
83 #include "wx/msw/dcclient.h"
84
85 #if wxUSE_TOOLTIPS
86 #include "wx/tooltip.h"
87 #endif
88
89 #if wxUSE_CARET
90 #include "wx/caret.h"
91 #endif // wxUSE_CARET
92
93 #if wxUSE_RADIOBOX
94 #include "wx/radiobox.h"
95 #endif // wxUSE_RADIOBOX
96
97 #if wxUSE_SPINCTRL
98 #include "wx/spinctrl.h"
99 #endif // wxUSE_SPINCTRL
100
101 #include "wx/notebook.h"
102 #include "wx/listctrl.h"
103 #include "wx/dynlib.h"
104
105 #include <string.h>
106
107 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
108 #include <shellapi.h>
109 #include <mmsystem.h>
110 #endif
111
112 #ifdef __WIN32__
113 #include <windowsx.h>
114 #endif
115
116 #if !defined __WXWINCE__ && !defined NEED_PBT_H
117 #include <pbt.h>
118 #endif
119
120 #if defined(__WXWINCE__)
121 #include "wx/msw/wince/missing.h"
122 #ifdef __POCKETPC__
123 #include <windows.h>
124 #include <shellapi.h>
125 #include <ole2.h>
126 #include <aygshell.h>
127 #endif
128 #endif
129
130 #if wxUSE_UXTHEME
131 #include "wx/msw/uxtheme.h"
132 #define EP_EDITTEXT 1
133 #define ETS_NORMAL 1
134 #define ETS_HOT 2
135 #define ETS_SELECTED 3
136 #define ETS_DISABLED 4
137 #define ETS_FOCUSED 5
138 #define ETS_READONLY 6
139 #define ETS_ASSIST 7
140 #endif
141
142 // define the constants used by AnimateWindow() if our SDK doesn't have them
143 #ifndef AW_CENTER
144 #define AW_HOR_POSITIVE 0x00000001
145 #define AW_HOR_NEGATIVE 0x00000002
146 #define AW_VER_POSITIVE 0x00000004
147 #define AW_VER_NEGATIVE 0x00000008
148 #define AW_CENTER 0x00000010
149 #define AW_HIDE 0x00010000
150 #define AW_ACTIVATE 0x00020000
151 #define AW_SLIDE 0x00040000
152 #define AW_BLEND 0x00080000
153 #endif
154
155 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS
156 #define HAVE_TRACKMOUSEEVENT
157 #endif // everything needed for TrackMouseEvent()
158
159 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
160 // when mouse position didnd't change
161 #ifdef __WXWINCE__
162 #define wxUSE_MOUSEEVENT_HACK 0
163 #else
164 #define wxUSE_MOUSEEVENT_HACK 1
165 #endif
166
167 // not all compilers/platforms have X button related declarations (notably
168 // Windows CE doesn't, and probably some old SDKs don't neither)
169 #ifdef WM_XBUTTONDOWN
170 #define wxHAS_XBUTTON
171 #endif
172
173 #ifndef MAPVK_VK_TO_CHAR
174 #define MAPVK_VK_TO_CHAR 2
175 #endif
176
177 // ---------------------------------------------------------------------------
178 // global variables
179 // ---------------------------------------------------------------------------
180
181 #if wxUSE_MENUS_NATIVE
182 extern wxMenu *wxCurrentPopupMenu;
183 #endif
184
185 namespace
186 {
187
188 // true if we had already created the std colour map, used by
189 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
190 bool gs_hasStdCmap = false;
191
192 // last mouse event information we need to filter out the duplicates
193 #if wxUSE_MOUSEEVENT_HACK
194 struct MouseEventInfoDummy
195 {
196 // mouse position (in screen coordinates)
197 wxPoint pos;
198
199 // last mouse event type
200 wxEventType type;
201 } gs_lastMouseEvent;
202 #endif // wxUSE_MOUSEEVENT_HACK
203
204 // hash containing the registered handlers for the custom messages
205 WX_DECLARE_HASH_MAP(int, wxWindow::MSWMessageHandler,
206 wxIntegerHash, wxIntegerEqual,
207 MSWMessageHandlers);
208
209 MSWMessageHandlers gs_messageHandlers;
210
211 // hash containing all our windows, it uses HWND keys and wxWindow* values
212 WX_DECLARE_HASH_MAP(HWND, wxWindow *,
213 wxPointerHash, wxPointerEqual,
214 WindowHandles);
215
216 WindowHandles gs_windowHandles;
217
218 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
219
220 // temporary override for WM_ERASEBKGND processing: we don't store this in
221 // wxWindow itself as we don't need it during most of the time so don't
222 // increase the size of all window objects unnecessarily
223 WX_DECLARE_HASH_MAP(wxWindow *, wxWindow *,
224 wxPointerHash, wxPointerEqual,
225 EraseBgHooks);
226
227 EraseBgHooks gs_eraseBgHooks;
228
229 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
230
231 } // anonymous namespace
232
233 // ---------------------------------------------------------------------------
234 // private functions
235 // ---------------------------------------------------------------------------
236
237 // the window proc for all our windows
238 LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
239 WPARAM wParam, LPARAM lParam);
240
241
242 #if wxDEBUG_LEVEL >= 2
243 const wxChar *wxGetMessageName(int message);
244 #endif // wxDEBUG_LEVEL >= 2
245
246 void wxRemoveHandleAssociation(wxWindowMSW *win);
247 extern void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win);
248
249 // get the text metrics for the current font
250 static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win);
251
252 #ifdef __WXWINCE__
253 // find the window for the mouse event at the specified position
254 static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y);
255 #endif // __WXWINCE__
256
257 // wrapper around BringWindowToTop() API
258 static inline void wxBringWindowToTop(HWND hwnd)
259 {
260 #ifdef __WXMICROWIN__
261 // It seems that MicroWindows brings the _parent_ of the window to the top,
262 // which can be the wrong one.
263
264 // activate (set focus to) specified window
265 ::SetFocus(hwnd);
266 #endif
267
268 // raise top level parent to top of z order
269 if (!::SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE))
270 {
271 wxLogLastError(wxT("SetWindowPos"));
272 }
273 }
274
275 #ifndef __WXWINCE__
276
277 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
278 static void EnsureParentHasControlParentStyle(wxWindow *parent)
279 {
280 /*
281 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
282 parent as well as otherwise several Win32 functions using
283 GetNextDlgTabItem() to iterate over all controls such as
284 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
285 all of them iterate over all the controls starting from the currently
286 focused one and stop iterating when they get back to the focus but
287 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
288 get back to the initial (focused) window: as we do have this style,
289 GetNextDlgTabItem() will leave this window and continue in its parent,
290 but if the parent doesn't have it, it wouldn't recurse inside it later
291 on and so wouldn't have a chance of getting back to this window either.
292 */
293 while ( parent && !parent->IsTopLevel() )
294 {
295 LONG exStyle = wxGetWindowExStyle(parent);
296 if ( !(exStyle & WS_EX_CONTROLPARENT) )
297 {
298 // force the parent to have this style
299 wxSetWindowExStyle(parent, exStyle | WS_EX_CONTROLPARENT);
300 }
301
302 parent = parent->GetParent();
303 }
304 }
305
306 #endif // !__WXWINCE__
307
308 #ifdef __WXWINCE__
309 // On Windows CE, GetCursorPos can return an error, so use this function
310 // instead
311 bool GetCursorPosWinCE(POINT* pt)
312 {
313 if (!GetCursorPos(pt))
314 {
315 DWORD pos = GetMessagePos();
316 pt->x = LOWORD(pos);
317 pt->y = HIWORD(pos);
318 }
319 return true;
320 }
321 #endif
322
323 // ---------------------------------------------------------------------------
324 // event tables
325 // ---------------------------------------------------------------------------
326
327 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
328 // method
329 #ifdef __WXUNIVERSAL__
330 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW, wxWindowBase)
331 #else // __WXMSW__
332 #if wxUSE_EXTENDED_RTTI
333
334 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
335 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
336 // windows with negative ids never can be recreated anyway
337
338 bool wxWindowStreamingCallback( const wxObject *object, wxWriter * , wxPersister * , wxxVariantArray & )
339 {
340 const wxWindow * win = dynamic_cast<const wxWindow*>(object) ;
341 if ( win && win->GetId() < 0 )
342 return false ;
343 return true ;
344 }
345
346 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow, wxWindowBase,"wx/window.h", wxWindowStreamingCallback)
347
348 // make wxWindowList known before the property is used
349
350 wxCOLLECTION_TYPE_INFO( wxWindow* , wxWindowList ) ;
351
352 template<> void wxCollectionToVariantArray( wxWindowList const &theList, wxxVariantArray &value)
353 {
354 wxListCollectionToVariantArray<wxWindowList::compatibility_iterator>( theList , value ) ;
355 }
356
357 WX_DEFINE_FLAGS( wxWindowStyle )
358
359 wxBEGIN_FLAGS( wxWindowStyle )
360 // new style border flags, we put them first to
361 // use them for streaming out
362
363 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
364 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
365 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
366 wxFLAGS_MEMBER(wxBORDER_RAISED)
367 wxFLAGS_MEMBER(wxBORDER_STATIC)
368 wxFLAGS_MEMBER(wxBORDER_NONE)
369
370 // old style border flags
371 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
372 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
373 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
374 wxFLAGS_MEMBER(wxRAISED_BORDER)
375 wxFLAGS_MEMBER(wxSTATIC_BORDER)
376 wxFLAGS_MEMBER(wxBORDER)
377
378 // standard window styles
379 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
380 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
381 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
382 wxFLAGS_MEMBER(wxWANTS_CHARS)
383 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
384 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
385 wxFLAGS_MEMBER(wxVSCROLL)
386 wxFLAGS_MEMBER(wxHSCROLL)
387
388 wxEND_FLAGS( wxWindowStyle )
389
390 wxBEGIN_PROPERTIES_TABLE(wxWindow)
391 wxEVENT_PROPERTY( Close , wxEVT_CLOSE_WINDOW , wxCloseEvent)
392 wxEVENT_PROPERTY( Create , wxEVT_CREATE , wxWindowCreateEvent )
393 wxEVENT_PROPERTY( Destroy , wxEVT_DESTROY , wxWindowDestroyEvent )
394 // Always constructor Properties first
395
396 wxREADONLY_PROPERTY( Parent,wxWindow*, GetParent, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
397 wxPROPERTY( Id,wxWindowID, SetId, GetId, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
398 wxPROPERTY( Position,wxPoint, SetPosition , GetPosition, wxDefaultPosition , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
399 wxPROPERTY( Size,wxSize, SetSize, GetSize, wxDefaultSize , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
400 wxPROPERTY( WindowStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
401
402 // Then all relations of the object graph
403
404 wxREADONLY_PROPERTY_COLLECTION( Children , wxWindowList , wxWindowBase* , GetWindowChildren , wxPROP_OBJECT_GRAPH /*flags*/ , wxT("Helpstring") , wxT("group"))
405
406 // and finally all other properties
407
408 wxPROPERTY( ExtraStyle , long , SetExtraStyle , GetExtraStyle , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
409 wxPROPERTY( BackgroundColour , wxColour , SetBackgroundColour , GetBackgroundColour , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
410 wxPROPERTY( ForegroundColour , wxColour , SetForegroundColour , GetForegroundColour , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
411 wxPROPERTY( Enabled , bool , Enable , IsEnabled , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
412 wxPROPERTY( Shown , bool , Show , IsShown , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
413 #if 0
414 // possible property candidates (not in xrc) or not valid in all subclasses
415 wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxEmptyString )
416 wxPROPERTY( Font , wxFont , SetFont , GetWindowFont , )
417 wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxEmptyString )
418 // MaxHeight, Width , MinHeight , Width
419 // TODO switch label to control and title to toplevels
420
421 wxPROPERTY( ThemeEnabled , bool , SetThemeEnabled , GetThemeEnabled , )
422 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
423 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
424 wxPROPERTY( AutoLayout , bool , SetAutoLayout , GetAutoLayout , )
425
426
427
428 #endif
429 wxEND_PROPERTIES_TABLE()
430
431 wxBEGIN_HANDLERS_TABLE(wxWindow)
432 wxEND_HANDLERS_TABLE()
433
434 wxCONSTRUCTOR_DUMMY(wxWindow)
435
436 #else
437 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
438 #endif
439 #endif // __WXUNIVERSAL__/__WXMSW__
440
441 BEGIN_EVENT_TABLE(wxWindowMSW, wxWindowBase)
442 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged)
443 #ifdef __WXWINCE__
444 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog)
445 #endif
446 END_EVENT_TABLE()
447
448 // ===========================================================================
449 // implementation
450 // ===========================================================================
451
452 // ---------------------------------------------------------------------------
453 // wxWindow utility functions
454 // ---------------------------------------------------------------------------
455
456 // Find an item given the MS Windows id
457 wxWindow *wxWindowMSW::FindItem(long id) const
458 {
459 #if wxUSE_CONTROLS
460 wxControl *item = wxDynamicCastThis(wxControl);
461 if ( item )
462 {
463 // is it us or one of our "internal" children?
464 if ( item->GetId() == id
465 #ifndef __WXUNIVERSAL__
466 || (item->GetSubcontrols().Index(id) != wxNOT_FOUND)
467 #endif // __WXUNIVERSAL__
468 )
469 {
470 return item;
471 }
472 }
473 #endif // wxUSE_CONTROLS
474
475 wxWindowList::compatibility_iterator current = GetChildren().GetFirst();
476 while (current)
477 {
478 wxWindow *childWin = current->GetData();
479
480 wxWindow *wnd = childWin->FindItem(id);
481 if ( wnd )
482 return wnd;
483
484 current = current->GetNext();
485 }
486
487 return NULL;
488 }
489
490 // Find an item given the MS Windows handle
491 wxWindow *wxWindowMSW::FindItemByHWND(WXHWND hWnd, bool controlOnly) const
492 {
493 wxWindowList::compatibility_iterator current = GetChildren().GetFirst();
494 while (current)
495 {
496 wxWindow *parent = current->GetData();
497
498 // Do a recursive search.
499 wxWindow *wnd = parent->FindItemByHWND(hWnd);
500 if ( wnd )
501 return wnd;
502
503 if ( !controlOnly
504 #if wxUSE_CONTROLS
505 || parent->IsKindOf(CLASSINFO(wxControl))
506 #endif // wxUSE_CONTROLS
507 )
508 {
509 wxWindow *item = current->GetData();
510 if ( item->GetHWND() == hWnd )
511 return item;
512 else
513 {
514 if ( item->ContainsHWND(hWnd) )
515 return item;
516 }
517 }
518
519 current = current->GetNext();
520 }
521 return NULL;
522 }
523
524 // Default command handler
525 bool wxWindowMSW::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
526 {
527 return false;
528 }
529
530 // ----------------------------------------------------------------------------
531 // constructors and such
532 // ----------------------------------------------------------------------------
533
534 void wxWindowMSW::Init()
535 {
536 // MSW specific
537 m_oldWndProc = NULL;
538 m_mouseInWindow = false;
539 m_lastKeydownProcessed = false;
540
541 m_hWnd = 0;
542
543 m_xThumbSize = 0;
544 m_yThumbSize = 0;
545
546 #if wxUSE_DEFERRED_SIZING
547 m_hDWP = 0;
548 m_pendingPosition = wxDefaultPosition;
549 m_pendingSize = wxDefaultSize;
550 #endif // wxUSE_DEFERRED_SIZING
551
552 #ifdef __POCKETPC__
553 m_contextMenuEnabled = false;
554 #endif
555 }
556
557 // Destructor
558 wxWindowMSW::~wxWindowMSW()
559 {
560 SendDestroyEvent();
561
562 #ifndef __WXUNIVERSAL__
563 // VS: make sure there's no wxFrame with last focus set to us:
564 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
565 {
566 wxTopLevelWindow *frame = wxDynamicCast(win, wxTopLevelWindow);
567 if ( frame )
568 {
569 if ( frame->GetLastFocus() == this )
570 {
571 frame->SetLastFocus(NULL);
572 }
573
574 // apparently sometimes we can end up with our grand parent
575 // pointing to us as well: this is surely a bug in focus handling
576 // code but it's not clear where it happens so for now just try to
577 // fix it here by not breaking out of the loop
578 //break;
579 }
580 }
581 #endif // __WXUNIVERSAL__
582
583 // VS: destroy children first and _then_ detach *this from its parent.
584 // If we did it the other way around, children wouldn't be able
585 // find their parent frame (see above).
586 DestroyChildren();
587
588 if ( m_hWnd )
589 {
590 // VZ: test temp removed to understand what really happens here
591 //if (::IsWindow(GetHwnd()))
592 {
593 if ( !::DestroyWindow(GetHwnd()) )
594 {
595 wxLogLastError(wxT("DestroyWindow"));
596 }
597 }
598
599 // remove hWnd <-> wxWindow association
600 wxRemoveHandleAssociation(this);
601 }
602
603 }
604
605 /* static */
606 const wxChar *wxWindowMSW::MSWGetRegisteredClassName()
607 {
608 return wxApp::GetRegisteredClassName(wxT("wxWindow"), COLOR_BTNFACE);
609 }
610
611 // real construction (Init() must have been called before!)
612 bool wxWindowMSW::Create(wxWindow *parent,
613 wxWindowID id,
614 const wxPoint& pos,
615 const wxSize& size,
616 long style,
617 const wxString& name)
618 {
619 wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") );
620
621 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
622 return false;
623
624 parent->AddChild(this);
625
626 WXDWORD exstyle;
627 DWORD msflags = MSWGetCreateWindowFlags(&exstyle);
628
629 #ifdef __WXUNIVERSAL__
630 // no borders, we draw them ourselves
631 exstyle &= ~(WS_EX_DLGMODALFRAME |
632 WS_EX_STATICEDGE |
633 WS_EX_CLIENTEDGE |
634 WS_EX_WINDOWEDGE);
635 msflags &= ~WS_BORDER;
636 #endif // wxUniversal
637
638 if ( IsShown() )
639 {
640 msflags |= WS_VISIBLE;
641 }
642
643 if ( !MSWCreate(MSWGetRegisteredClassName(),
644 NULL, pos, size, msflags, exstyle) )
645 return false;
646
647 InheritAttributes();
648
649 return true;
650 }
651
652 // ---------------------------------------------------------------------------
653 // basic operations
654 // ---------------------------------------------------------------------------
655
656 void wxWindowMSW::SetFocus()
657 {
658 HWND hWnd = GetHwnd();
659 wxCHECK_RET( hWnd, wxT("can't set focus to invalid window") );
660
661 #if !defined(__WXWINCE__)
662 ::SetLastError(0);
663 #endif
664
665 if ( !::SetFocus(hWnd) )
666 {
667 // was there really an error?
668 DWORD dwRes = ::GetLastError();
669 if ( dwRes )
670 {
671 HWND hwndFocus = ::GetFocus();
672 if ( hwndFocus != hWnd )
673 {
674 wxLogApiError(wxT("SetFocus"), dwRes);
675 }
676 }
677 }
678 }
679
680 void wxWindowMSW::SetFocusFromKbd()
681 {
682 // when the focus is given to the control with DLGC_HASSETSEL style from
683 // keyboard its contents should be entirely selected: this is what
684 // ::IsDialogMessage() does and so we should do it as well to provide the
685 // same LNF as the native programs
686 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE, 0, 0) & DLGC_HASSETSEL )
687 {
688 ::SendMessage(GetHwnd(), EM_SETSEL, 0, -1);
689 }
690
691 // do this after (maybe) setting the selection as like this when
692 // wxEVT_SET_FOCUS handler is called, the selection would have been already
693 // set correctly -- this may be important
694 wxWindowBase::SetFocusFromKbd();
695 }
696
697 // Get the window with the focus
698 wxWindow *wxWindowBase::DoFindFocus()
699 {
700 HWND hWnd = ::GetFocus();
701 if ( hWnd )
702 {
703 return wxGetWindowFromHWND((WXHWND)hWnd);
704 }
705
706 return NULL;
707 }
708
709 void wxWindowMSW::DoEnable( bool enable )
710 {
711 MSWEnableHWND(GetHwnd(), enable);
712 }
713
714 bool wxWindowMSW::MSWEnableHWND(WXHWND hWnd, bool enable)
715 {
716 if ( !hWnd )
717 return false;
718
719 // If disabling focused control, we move focus to the next one, as if the
720 // user pressed Tab. That's because we can't keep focus on a disabled
721 // control, Tab-navigation would stop working then.
722 if ( !enable && ::GetFocus() == hWnd )
723 Navigate();
724
725 return ::EnableWindow(hWnd, (BOOL)enable) != 0;
726 }
727
728 bool wxWindowMSW::Show(bool show)
729 {
730 if ( !wxWindowBase::Show(show) )
731 return false;
732
733 HWND hWnd = GetHwnd();
734
735 // we could be called before the underlying window is created (this is
736 // actually useful to prevent it from being initially shown), e.g.
737 //
738 // wxFoo *foo = new wxFoo;
739 // foo->Hide();
740 // foo->Create(parent, ...);
741 //
742 // should work without errors
743 if ( hWnd )
744 {
745 ::ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE);
746 }
747
748 if ( IsFrozen() )
749 {
750 // DoFreeze/DoThaw don't do anything if the window is not shown, so
751 // we have to call them from here now
752 if ( show )
753 DoFreeze();
754 else
755 DoThaw();
756 }
757
758 return true;
759 }
760
761 bool
762 wxWindowMSW::MSWShowWithEffect(bool show,
763 wxShowEffect effect,
764 unsigned timeout)
765 {
766 if ( effect == wxSHOW_EFFECT_NONE )
767 return Show(show);
768
769 if ( !wxWindowBase::Show(show) )
770 return false;
771
772 typedef BOOL (WINAPI *AnimateWindow_t)(HWND, DWORD, DWORD);
773
774 static AnimateWindow_t s_pfnAnimateWindow = NULL;
775 static bool s_initDone = false;
776 if ( !s_initDone )
777 {
778 wxDynamicLibrary dllUser32(wxT("user32.dll"), wxDL_VERBATIM | wxDL_QUIET);
779 wxDL_INIT_FUNC(s_pfn, AnimateWindow, dllUser32);
780
781 s_initDone = true;
782
783 // notice that it's ok to unload user32.dll here as it won't be really
784 // unloaded, being still in use because we link to it statically too
785 }
786
787 if ( !s_pfnAnimateWindow )
788 return Show(show);
789
790 // Show() has a side effect of sending a WM_SIZE to the window, which helps
791 // ensuring that it's laid out correctly, but AnimateWindow() doesn't do
792 // this so send the event ourselves
793 SendSizeEvent();
794
795 // prepare to use AnimateWindow()
796
797 if ( !timeout )
798 timeout = 200; // this is the default animation timeout, per MSDN
799
800 DWORD dwFlags = show ? 0 : AW_HIDE;
801
802 switch ( effect )
803 {
804 case wxSHOW_EFFECT_ROLL_TO_LEFT:
805 dwFlags |= AW_HOR_NEGATIVE;
806 break;
807
808 case wxSHOW_EFFECT_ROLL_TO_RIGHT:
809 dwFlags |= AW_HOR_POSITIVE;
810 break;
811
812 case wxSHOW_EFFECT_ROLL_TO_TOP:
813 dwFlags |= AW_VER_NEGATIVE;
814 break;
815
816 case wxSHOW_EFFECT_ROLL_TO_BOTTOM:
817 dwFlags |= AW_VER_POSITIVE;
818 break;
819
820 case wxSHOW_EFFECT_SLIDE_TO_LEFT:
821 dwFlags |= AW_SLIDE | AW_HOR_NEGATIVE;
822 break;
823
824 case wxSHOW_EFFECT_SLIDE_TO_RIGHT:
825 dwFlags |= AW_SLIDE | AW_HOR_POSITIVE;
826 break;
827
828 case wxSHOW_EFFECT_SLIDE_TO_TOP:
829 dwFlags |= AW_SLIDE | AW_VER_NEGATIVE;
830 break;
831
832 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM:
833 dwFlags |= AW_SLIDE | AW_VER_POSITIVE;
834 break;
835
836 case wxSHOW_EFFECT_BLEND:
837 dwFlags |= AW_BLEND;
838 break;
839
840 case wxSHOW_EFFECT_EXPAND:
841 dwFlags |= AW_CENTER;
842 break;
843
844
845 case wxSHOW_EFFECT_MAX:
846 wxFAIL_MSG( wxT("invalid window show effect") );
847 return false;
848
849 default:
850 wxFAIL_MSG( wxT("unknown window show effect") );
851 return false;
852 }
853
854 if ( !(*s_pfnAnimateWindow)(GetHwnd(), timeout, dwFlags) )
855 {
856 wxLogLastError(wxT("AnimateWindow"));
857
858 return false;
859 }
860
861 return true;
862 }
863
864 // Raise the window to the top of the Z order
865 void wxWindowMSW::Raise()
866 {
867 wxBringWindowToTop(GetHwnd());
868 }
869
870 // Lower the window to the bottom of the Z order
871 void wxWindowMSW::Lower()
872 {
873 ::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0,
874 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
875 }
876
877 void wxWindowMSW::DoCaptureMouse()
878 {
879 HWND hWnd = GetHwnd();
880 if ( hWnd )
881 {
882 ::SetCapture(hWnd);
883 }
884 }
885
886 void wxWindowMSW::DoReleaseMouse()
887 {
888 if ( !::ReleaseCapture() )
889 {
890 wxLogLastError(wxT("ReleaseCapture"));
891 }
892 }
893
894 /* static */ wxWindow *wxWindowBase::GetCapture()
895 {
896 HWND hwnd = ::GetCapture();
897 return hwnd ? wxFindWinFromHandle(hwnd) : NULL;
898 }
899
900 bool wxWindowMSW::SetFont(const wxFont& font)
901 {
902 if ( !wxWindowBase::SetFont(font) )
903 {
904 // nothing to do
905 return false;
906 }
907
908 HWND hWnd = GetHwnd();
909 if ( hWnd != 0 )
910 {
911 // note the use of GetFont() instead of m_font: our own font could have
912 // just been reset and in this case we need to change the font used by
913 // the native window to the default for this class, i.e. exactly what
914 // GetFont() returns
915 WXHANDLE hFont = GetFont().GetResourceHandle();
916
917 wxASSERT_MSG( hFont, wxT("should have valid font") );
918
919 ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
920 }
921
922 return true;
923 }
924 bool wxWindowMSW::SetCursor(const wxCursor& cursor)
925 {
926 if ( !wxWindowBase::SetCursor(cursor) )
927 {
928 // no change
929 return false;
930 }
931
932 // don't "overwrite" busy cursor
933 if ( m_cursor.Ok() && !wxIsBusy() )
934 {
935 // normally we should change the cursor only if it's over this window
936 // but we should do it always if we capture the mouse currently
937 bool set = HasCapture();
938 if ( !set )
939 {
940 HWND hWnd = GetHwnd();
941
942 POINT point;
943 #ifdef __WXWINCE__
944 ::GetCursorPosWinCE(&point);
945 #else
946 ::GetCursorPos(&point);
947 #endif
948
949 RECT rect = wxGetWindowRect(hWnd);
950
951 set = ::PtInRect(&rect, point) != 0;
952 }
953
954 if ( set )
955 {
956 ::SetCursor(GetHcursorOf(m_cursor));
957 }
958 //else: will be set later when the mouse enters this window
959 }
960
961 return true;
962 }
963
964 void wxWindowMSW::WarpPointer(int x, int y)
965 {
966 ClientToScreen(&x, &y);
967
968 if ( !::SetCursorPos(x, y) )
969 {
970 wxLogLastError(wxT("SetCursorPos"));
971 }
972 }
973
974 void wxWindowMSW::MSWUpdateUIState(int action, int state)
975 {
976 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
977 // to use it on older systems -- and could possibly do some harm
978 static int s_needToUpdate = -1;
979 if ( s_needToUpdate == -1 )
980 {
981 int verMaj, verMin;
982 s_needToUpdate = wxGetOsVersion(&verMaj, &verMin) == wxOS_WINDOWS_NT &&
983 verMaj >= 5;
984 }
985
986 if ( s_needToUpdate )
987 {
988 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
989 // won't send WM_UPDATEUISTATE
990 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE, MAKEWPARAM(action, state), 0);
991 }
992 }
993
994 // ---------------------------------------------------------------------------
995 // scrolling stuff
996 // ---------------------------------------------------------------------------
997
998 namespace
999 {
1000
1001 inline int GetScrollPosition(HWND hWnd, int wOrient)
1002 {
1003 #ifdef __WXMICROWIN__
1004 return ::GetScrollPosWX(hWnd, wOrient);
1005 #else
1006 WinStruct<SCROLLINFO> scrollInfo;
1007 scrollInfo.cbSize = sizeof(SCROLLINFO);
1008 scrollInfo.fMask = SIF_POS;
1009 ::GetScrollInfo(hWnd, wOrient, &scrollInfo );
1010
1011 return scrollInfo.nPos;
1012
1013 #endif
1014 }
1015
1016 inline UINT WXOrientToSB(int orient)
1017 {
1018 return orient == wxHORIZONTAL ? SB_HORZ : SB_VERT;
1019 }
1020
1021 } // anonymous namespace
1022
1023 int wxWindowMSW::GetScrollPos(int orient) const
1024 {
1025 HWND hWnd = GetHwnd();
1026 wxCHECK_MSG( hWnd, 0, wxT("no HWND in GetScrollPos") );
1027
1028 return GetScrollPosition(hWnd, WXOrientToSB(orient));
1029 }
1030
1031 // This now returns the whole range, not just the number
1032 // of positions that we can scroll.
1033 int wxWindowMSW::GetScrollRange(int orient) const
1034 {
1035 int maxPos;
1036 HWND hWnd = GetHwnd();
1037 if ( !hWnd )
1038 return 0;
1039 WinStruct<SCROLLINFO> scrollInfo;
1040 scrollInfo.fMask = SIF_RANGE;
1041 if ( !::GetScrollInfo(hWnd, WXOrientToSB(orient), &scrollInfo) )
1042 {
1043 // Most of the time this is not really an error, since the return
1044 // value can also be zero when there is no scrollbar yet.
1045 // wxLogLastError(wxT("GetScrollInfo"));
1046 }
1047 maxPos = scrollInfo.nMax;
1048
1049 // undo "range - 1" done in SetScrollbar()
1050 return maxPos + 1;
1051 }
1052
1053 int wxWindowMSW::GetScrollThumb(int orient) const
1054 {
1055 return orient == wxHORIZONTAL ? m_xThumbSize : m_yThumbSize;
1056 }
1057
1058 void wxWindowMSW::SetScrollPos(int orient, int pos, bool refresh)
1059 {
1060 HWND hWnd = GetHwnd();
1061 wxCHECK_RET( hWnd, wxT("SetScrollPos: no HWND") );
1062
1063 WinStruct<SCROLLINFO> info;
1064 info.nPage = 0;
1065 info.nMin = 0;
1066 info.nPos = pos;
1067 info.fMask = SIF_POS;
1068 if ( HasFlag(wxALWAYS_SHOW_SB) )
1069 {
1070 // disable scrollbar instead of removing it then
1071 info.fMask |= SIF_DISABLENOSCROLL;
1072 }
1073
1074 ::SetScrollInfo(hWnd, WXOrientToSB(orient), &info, refresh);
1075 }
1076
1077 // New function that will replace some of the above.
1078 void wxWindowMSW::SetScrollbar(int orient,
1079 int pos,
1080 int pageSize,
1081 int range,
1082 bool refresh)
1083 {
1084 // We have to set the variables here to make them valid in events
1085 // triggered by ::SetScrollInfo()
1086 *(orient == wxHORIZONTAL ? &m_xThumbSize : &m_yThumbSize) = pageSize;
1087
1088 HWND hwnd = GetHwnd();
1089 if ( !hwnd )
1090 return;
1091
1092 WinStruct<SCROLLINFO> info;
1093 if ( range != -1 )
1094 {
1095 info.nPage = pageSize;
1096 info.nMin = 0; // range is nMax - nMin + 1
1097 info.nMax = range - 1; // as both nMax and nMax are inclusive
1098 info.nPos = pos;
1099
1100 // We normally also reenable scrollbar in case it had been previously
1101 // disabled by specifying SIF_DISABLENOSCROLL below but we should only
1102 // do this if it has valid range, otherwise it would be enabled but not
1103 // do anything.
1104 if ( range >= pageSize )
1105 {
1106 ::EnableScrollBar(hwnd, WXOrientToSB(orient), ESB_ENABLE_BOTH);
1107 }
1108 }
1109 //else: leave all the fields to be 0
1110
1111 info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
1112 if ( HasFlag(wxALWAYS_SHOW_SB) || range == -1 )
1113 {
1114 // disable scrollbar instead of removing it then
1115 info.fMask |= SIF_DISABLENOSCROLL;
1116 }
1117
1118 ::SetScrollInfo(hwnd, WXOrientToSB(orient), &info, refresh);
1119 }
1120
1121 void wxWindowMSW::ScrollWindow(int dx, int dy, const wxRect *prect)
1122 {
1123 RECT rect;
1124 RECT *pr;
1125 if ( prect )
1126 {
1127 wxCopyRectToRECT(*prect, rect);
1128 pr = &rect;
1129 }
1130 else
1131 {
1132 pr = NULL;
1133
1134 }
1135
1136 #ifdef __WXWINCE__
1137 // FIXME: is this the exact equivalent of the line below?
1138 ::ScrollWindowEx(GetHwnd(), dx, dy, pr, pr, 0, 0, SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
1139 #else
1140 ::ScrollWindow(GetHwnd(), dx, dy, pr, pr);
1141 #endif
1142 }
1143
1144 static bool ScrollVertically(HWND hwnd, int kind, int count)
1145 {
1146 int posStart = GetScrollPosition(hwnd, SB_VERT);
1147
1148 int pos = posStart;
1149 for ( int n = 0; n < count; n++ )
1150 {
1151 ::SendMessage(hwnd, WM_VSCROLL, kind, 0);
1152
1153 int posNew = GetScrollPosition(hwnd, SB_VERT);
1154 if ( posNew == pos )
1155 {
1156 // don't bother to continue, we're already at top/bottom
1157 break;
1158 }
1159
1160 pos = posNew;
1161 }
1162
1163 return pos != posStart;
1164 }
1165
1166 bool wxWindowMSW::ScrollLines(int lines)
1167 {
1168 bool down = lines > 0;
1169
1170 return ScrollVertically(GetHwnd(),
1171 down ? SB_LINEDOWN : SB_LINEUP,
1172 down ? lines : -lines);
1173 }
1174
1175 bool wxWindowMSW::ScrollPages(int pages)
1176 {
1177 bool down = pages > 0;
1178
1179 return ScrollVertically(GetHwnd(),
1180 down ? SB_PAGEDOWN : SB_PAGEUP,
1181 down ? pages : -pages);
1182 }
1183
1184 // ----------------------------------------------------------------------------
1185 // RTL support
1186 // ----------------------------------------------------------------------------
1187
1188 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir)
1189 {
1190 #ifdef __WXWINCE__
1191 wxUnusedVar(dir);
1192 #else
1193 wxCHECK_RET( GetHwnd(),
1194 wxT("layout direction must be set after window creation") );
1195
1196 LONG styleOld = wxGetWindowExStyle(this);
1197
1198 LONG styleNew = styleOld;
1199 switch ( dir )
1200 {
1201 case wxLayout_LeftToRight:
1202 styleNew &= ~WS_EX_LAYOUTRTL;
1203 break;
1204
1205 case wxLayout_RightToLeft:
1206 styleNew |= WS_EX_LAYOUTRTL;
1207 break;
1208
1209 default:
1210 wxFAIL_MSG(wxT("unsupported layout direction"));
1211 break;
1212 }
1213
1214 if ( styleNew != styleOld )
1215 {
1216 wxSetWindowExStyle(this, styleNew);
1217 }
1218 #endif
1219 }
1220
1221 wxLayoutDirection wxWindowMSW::GetLayoutDirection() const
1222 {
1223 #ifdef __WXWINCE__
1224 return wxLayout_Default;
1225 #else
1226 wxCHECK_MSG( GetHwnd(), wxLayout_Default, wxT("invalid window") );
1227
1228 return wxHasWindowExStyle(this, WS_EX_LAYOUTRTL) ? wxLayout_RightToLeft
1229 : wxLayout_LeftToRight;
1230 #endif
1231 }
1232
1233 wxCoord
1234 wxWindowMSW::AdjustForLayoutDirection(wxCoord x,
1235 wxCoord WXUNUSED(width),
1236 wxCoord WXUNUSED(widthTotal)) const
1237 {
1238 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1239 // redo it ourselves
1240 return x;
1241 }
1242
1243 // ---------------------------------------------------------------------------
1244 // subclassing
1245 // ---------------------------------------------------------------------------
1246
1247 void wxWindowMSW::SubclassWin(WXHWND hWnd)
1248 {
1249 wxASSERT_MSG( !m_oldWndProc, wxT("subclassing window twice?") );
1250
1251 HWND hwnd = (HWND)hWnd;
1252 wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in SubclassWin") );
1253
1254 SetHWND(hWnd);
1255
1256 wxAssociateWinWithHandle(hwnd, this);
1257
1258 m_oldWndProc = (WXFARPROC)wxGetWindowProc((HWND)hWnd);
1259
1260 // we don't need to subclass the window of our own class (in the Windows
1261 // sense of the word)
1262 if ( !wxCheckWindowWndProc(hWnd, (WXFARPROC)wxWndProc) )
1263 {
1264 wxSetWindowProc(hwnd, wxWndProc);
1265 }
1266 else
1267 {
1268 // don't bother restoring it either: this also makes it easy to
1269 // implement IsOfStandardClass() method which returns true for the
1270 // standard controls and false for the wxWidgets own windows as it can
1271 // simply check m_oldWndProc
1272 m_oldWndProc = NULL;
1273 }
1274
1275 // we're officially created now, send the event
1276 wxWindowCreateEvent event((wxWindow *)this);
1277 (void)HandleWindowEvent(event);
1278 }
1279
1280 void wxWindowMSW::UnsubclassWin()
1281 {
1282 wxRemoveHandleAssociation(this);
1283
1284 // Restore old Window proc
1285 HWND hwnd = GetHwnd();
1286 if ( hwnd )
1287 {
1288 SetHWND(0);
1289
1290 wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in UnsubclassWin") );
1291
1292 if ( m_oldWndProc )
1293 {
1294 if ( !wxCheckWindowWndProc((WXHWND)hwnd, m_oldWndProc) )
1295 {
1296 wxSetWindowProc(hwnd, (WNDPROC)m_oldWndProc);
1297 }
1298
1299 m_oldWndProc = NULL;
1300 }
1301 }
1302 }
1303
1304 void wxWindowMSW::AssociateHandle(WXWidget handle)
1305 {
1306 if ( m_hWnd )
1307 {
1308 if ( !::DestroyWindow(GetHwnd()) )
1309 {
1310 wxLogLastError(wxT("DestroyWindow"));
1311 }
1312 }
1313
1314 WXHWND wxhwnd = (WXHWND)handle;
1315
1316 // this also calls SetHWND(wxhwnd)
1317 SubclassWin(wxhwnd);
1318 }
1319
1320 void wxWindowMSW::DissociateHandle()
1321 {
1322 // this also calls SetHWND(0) for us
1323 UnsubclassWin();
1324 }
1325
1326
1327 bool wxCheckWindowWndProc(WXHWND hWnd,
1328 WXFARPROC WXUNUSED(wndProc))
1329 {
1330 const wxString str(wxGetWindowClass(hWnd));
1331
1332 // TODO: get rid of wxTLWHiddenParent special case (currently it's not
1333 // registered by wxApp but using ad hoc code in msw/toplevel.cpp);
1334 // there is also a hidden window class used by sockets &c
1335 return wxApp::IsRegisteredClassName(str) || str == wxT("wxTLWHiddenParent");
1336 }
1337
1338 // ----------------------------------------------------------------------------
1339 // Style handling
1340 // ----------------------------------------------------------------------------
1341
1342 void wxWindowMSW::SetWindowStyleFlag(long flags)
1343 {
1344 long flagsOld = GetWindowStyleFlag();
1345 if ( flags == flagsOld )
1346 return;
1347
1348 // update the internal variable
1349 wxWindowBase::SetWindowStyleFlag(flags);
1350
1351 // and the real window flags
1352 MSWUpdateStyle(flagsOld, GetExtraStyle());
1353 }
1354
1355 void wxWindowMSW::SetExtraStyle(long exflags)
1356 {
1357 long exflagsOld = GetExtraStyle();
1358 if ( exflags == exflagsOld )
1359 return;
1360
1361 // update the internal variable
1362 wxWindowBase::SetExtraStyle(exflags);
1363
1364 // and the real window flags
1365 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld);
1366 }
1367
1368 void wxWindowMSW::MSWUpdateStyle(long flagsOld, long exflagsOld)
1369 {
1370 // now update the Windows style as well if needed - and if the window had
1371 // been already created
1372 if ( !GetHwnd() )
1373 return;
1374
1375 // we may need to call SetWindowPos() when we change some styles
1376 bool callSWP = false;
1377
1378 WXDWORD exstyle;
1379 long style = MSWGetStyle(GetWindowStyleFlag(), &exstyle);
1380
1381 // this is quite a horrible hack but we need it because MSWGetStyle()
1382 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1383 // and so we have to modify the window exflags temporarily to get the
1384 // correct exstyleOld
1385 long exflagsNew = GetExtraStyle();
1386 wxWindowBase::SetExtraStyle(exflagsOld);
1387
1388 WXDWORD exstyleOld;
1389 long styleOld = MSWGetStyle(flagsOld, &exstyleOld);
1390
1391 wxWindowBase::SetExtraStyle(exflagsNew);
1392
1393
1394 if ( style != styleOld )
1395 {
1396 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1397 // this function so instead of simply setting the style to the new
1398 // value we clear the bits which were set in styleOld but are set in
1399 // the new one and set the ones which were not set before
1400 long styleReal = ::GetWindowLong(GetHwnd(), GWL_STYLE);
1401 styleReal &= ~styleOld;
1402 styleReal |= style;
1403
1404 ::SetWindowLong(GetHwnd(), GWL_STYLE, styleReal);
1405
1406 // we need to call SetWindowPos() if any of the styles affecting the
1407 // frame appearance have changed
1408 callSWP = ((styleOld ^ style ) & (WS_BORDER |
1409 WS_THICKFRAME |
1410 WS_CAPTION |
1411 WS_DLGFRAME |
1412 WS_MAXIMIZEBOX |
1413 WS_MINIMIZEBOX |
1414 WS_SYSMENU) ) != 0;
1415 }
1416
1417 // and the extended style
1418 long exstyleReal = wxGetWindowExStyle(this);
1419
1420 if ( exstyle != exstyleOld )
1421 {
1422 exstyleReal &= ~exstyleOld;
1423 exstyleReal |= exstyle;
1424
1425 wxSetWindowExStyle(this, exstyleReal);
1426
1427 // ex style changes don't take effect without calling SetWindowPos
1428 callSWP = true;
1429 }
1430
1431 if ( callSWP )
1432 {
1433 // we must call SetWindowPos() to flush the cached extended style and
1434 // also to make the change to wxSTAY_ON_TOP style take effect: just
1435 // setting the style simply doesn't work
1436 if ( !::SetWindowPos(GetHwnd(),
1437 exstyleReal & WS_EX_TOPMOST ? HWND_TOPMOST
1438 : HWND_NOTOPMOST,
1439 0, 0, 0, 0,
1440 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
1441 SWP_FRAMECHANGED) )
1442 {
1443 wxLogLastError(wxT("SetWindowPos"));
1444 }
1445 }
1446 }
1447
1448 wxBorder wxWindowMSW::GetDefaultBorderForControl() const
1449 {
1450 return wxBORDER_THEME;
1451 }
1452
1453 wxBorder wxWindowMSW::GetDefaultBorder() const
1454 {
1455 return wxWindowBase::GetDefaultBorder();
1456 }
1457
1458 // Translate wxBORDER_THEME (and other border styles if necessary) to the value
1459 // that makes most sense for this Windows environment
1460 wxBorder wxWindowMSW::TranslateBorder(wxBorder border) const
1461 {
1462 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
1463 if (border == wxBORDER_THEME || border == wxBORDER_SUNKEN || border == wxBORDER_SIMPLE)
1464 return wxBORDER_SIMPLE;
1465 else
1466 return wxBORDER_NONE;
1467 #else
1468 #if wxUSE_UXTHEME
1469 if (border == wxBORDER_THEME)
1470 {
1471 if (CanApplyThemeBorder())
1472 {
1473 wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive();
1474 if (theme)
1475 return wxBORDER_THEME;
1476 }
1477 return wxBORDER_SUNKEN;
1478 }
1479 #endif
1480 return border;
1481 #endif
1482 }
1483
1484
1485 WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const
1486 {
1487 // translate common wxWidgets styles to Windows ones
1488
1489 // most of windows are child ones, those which are not (such as
1490 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1491 WXDWORD style = WS_CHILD;
1492
1493 // using this flag results in very significant reduction in flicker,
1494 // especially with controls inside the static boxes (as the interior of the
1495 // box is not redrawn twice), but sometimes results in redraw problems, so
1496 // optionally allow the old code to continue to use it provided a special
1497 // system option is turned on
1498 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1499 || (flags & wxCLIP_CHILDREN) )
1500 style |= WS_CLIPCHILDREN;
1501
1502 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1503 // don't support overlapping windows and it only makes sense for them and,
1504 // presumably, gives the system some extra work (to manage more clipping
1505 // regions), so avoid it alltogether
1506
1507
1508 if ( flags & wxVSCROLL )
1509 style |= WS_VSCROLL;
1510
1511 if ( flags & wxHSCROLL )
1512 style |= WS_HSCROLL;
1513
1514 const wxBorder border = TranslateBorder(GetBorder(flags));
1515
1516 // After translation, border is now optimized for the specific version of Windows
1517 // and theme engine presence.
1518
1519 // WS_BORDER is only required for wxBORDER_SIMPLE
1520 if ( border == wxBORDER_SIMPLE )
1521 style |= WS_BORDER;
1522
1523 // now deal with ext style if the caller wants it
1524 if ( exstyle )
1525 {
1526 *exstyle = 0;
1527
1528 #ifndef __WXWINCE__
1529 if ( flags & wxTRANSPARENT_WINDOW )
1530 *exstyle |= WS_EX_TRANSPARENT;
1531 #endif
1532
1533 switch ( border )
1534 {
1535 default:
1536 case wxBORDER_DEFAULT:
1537 wxFAIL_MSG( wxT("unknown border style") );
1538 // fall through
1539
1540 case wxBORDER_NONE:
1541 case wxBORDER_SIMPLE:
1542 case wxBORDER_THEME:
1543 break;
1544
1545 case wxBORDER_STATIC:
1546 *exstyle |= WS_EX_STATICEDGE;
1547 break;
1548
1549 case wxBORDER_RAISED:
1550 *exstyle |= WS_EX_DLGMODALFRAME;
1551 break;
1552
1553 case wxBORDER_SUNKEN:
1554 *exstyle |= WS_EX_CLIENTEDGE;
1555 style &= ~WS_BORDER;
1556 break;
1557
1558 // case wxBORDER_DOUBLE:
1559 // *exstyle |= WS_EX_DLGMODALFRAME;
1560 // break;
1561 }
1562
1563 // wxUniv doesn't use Windows dialog navigation functions at all
1564 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1565 // to make the dialog navigation work with the nested panels we must
1566 // use this style (top level windows such as dialogs don't need it)
1567 if ( (flags & wxTAB_TRAVERSAL) && !IsTopLevel() )
1568 {
1569 *exstyle |= WS_EX_CONTROLPARENT;
1570 }
1571 #endif // __WXUNIVERSAL__
1572 }
1573
1574 return style;
1575 }
1576
1577 // Setup background and foreground colours correctly
1578 void wxWindowMSW::SetupColours()
1579 {
1580 if ( GetParent() )
1581 SetBackgroundColour(GetParent()->GetBackgroundColour());
1582 }
1583
1584 bool wxWindowMSW::IsMouseInWindow() const
1585 {
1586 // get the mouse position
1587 POINT pt;
1588 #ifdef __WXWINCE__
1589 ::GetCursorPosWinCE(&pt);
1590 #else
1591 ::GetCursorPos(&pt);
1592 #endif
1593
1594 // find the window which currently has the cursor and go up the window
1595 // chain until we find this window - or exhaust it
1596 HWND hwnd = ::WindowFromPoint(pt);
1597 while ( hwnd && (hwnd != GetHwnd()) )
1598 hwnd = ::GetParent(hwnd);
1599
1600 return hwnd != NULL;
1601 }
1602
1603 void wxWindowMSW::OnInternalIdle()
1604 {
1605 #ifndef HAVE_TRACKMOUSEEVENT
1606 // Check if we need to send a LEAVE event
1607 if ( m_mouseInWindow )
1608 {
1609 // note that we should generate the leave event whether the window has
1610 // or doesn't have mouse capture
1611 if ( !IsMouseInWindow() )
1612 {
1613 GenerateMouseLeave();
1614 }
1615 }
1616 #endif // !HAVE_TRACKMOUSEEVENT
1617
1618 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1619 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
1620 }
1621
1622 // Set this window to be the child of 'parent'.
1623 bool wxWindowMSW::Reparent(wxWindowBase *parent)
1624 {
1625 if ( !wxWindowBase::Reparent(parent) )
1626 return false;
1627
1628 HWND hWndChild = GetHwnd();
1629 HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
1630
1631 ::SetParent(hWndChild, hWndParent);
1632
1633 #ifndef __WXWINCE__
1634 if ( wxHasWindowExStyle(this, WS_EX_CONTROLPARENT) )
1635 {
1636 EnsureParentHasControlParentStyle(GetParent());
1637 }
1638 #endif // !__WXWINCE__
1639
1640 return true;
1641 }
1642
1643 static inline void SendSetRedraw(HWND hwnd, bool on)
1644 {
1645 #ifndef __WXMICROWIN__
1646 ::SendMessage(hwnd, WM_SETREDRAW, (WPARAM)on, 0);
1647 #endif
1648 }
1649
1650 void wxWindowMSW::DoFreeze()
1651 {
1652 if ( !IsShown() )
1653 return; // no point in freezing hidden window
1654
1655 SendSetRedraw(GetHwnd(), false);
1656 }
1657
1658 void wxWindowMSW::DoThaw()
1659 {
1660 if ( !IsShown() )
1661 return; // hidden windows aren't frozen by DoFreeze
1662
1663 SendSetRedraw(GetHwnd(), true);
1664
1665 // we need to refresh everything or otherwise the invalidated area
1666 // is not going to be repainted
1667 Refresh();
1668 }
1669
1670 void wxWindowMSW::Refresh(bool eraseBack, const wxRect *rect)
1671 {
1672 HWND hWnd = GetHwnd();
1673 if ( hWnd )
1674 {
1675 RECT mswRect;
1676 const RECT *pRect;
1677 if ( rect )
1678 {
1679 wxCopyRectToRECT(*rect, mswRect);
1680 pRect = &mswRect;
1681 }
1682 else
1683 {
1684 pRect = NULL;
1685 }
1686
1687 // RedrawWindow not available on SmartPhone or eVC++ 3
1688 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1689 UINT flags = RDW_INVALIDATE | RDW_ALLCHILDREN;
1690 if ( eraseBack )
1691 flags |= RDW_ERASE;
1692
1693 ::RedrawWindow(hWnd, pRect, NULL, flags);
1694 #else
1695 ::InvalidateRect(hWnd, pRect, eraseBack);
1696 #endif
1697 }
1698 }
1699
1700 void wxWindowMSW::Update()
1701 {
1702 if ( !::UpdateWindow(GetHwnd()) )
1703 {
1704 wxLogLastError(wxT("UpdateWindow"));
1705 }
1706
1707 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1708 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1709 // handler needs to be really drawn right now
1710 (void)::GdiFlush();
1711 #endif // __WIN32__
1712 }
1713
1714 // ---------------------------------------------------------------------------
1715 // drag and drop
1716 // ---------------------------------------------------------------------------
1717
1718 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1719
1720 #if wxUSE_STATBOX
1721
1722 // we need to lower the sibling static boxes so controls contained within can be
1723 // a drop target
1724 static void AdjustStaticBoxZOrder(wxWindow *parent)
1725 {
1726 // no sibling static boxes if we have no parent (ie TLW)
1727 if ( !parent )
1728 return;
1729
1730 for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
1731 node;
1732 node = node->GetNext() )
1733 {
1734 wxStaticBox *statbox = wxDynamicCast(node->GetData(), wxStaticBox);
1735 if ( statbox )
1736 {
1737 ::SetWindowPos(GetHwndOf(statbox), HWND_BOTTOM, 0, 0, 0, 0,
1738 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
1739 }
1740 }
1741 }
1742
1743 #else // !wxUSE_STATBOX
1744
1745 static inline void AdjustStaticBoxZOrder(wxWindow * WXUNUSED(parent))
1746 {
1747 }
1748
1749 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1750
1751 #endif // drag and drop is used
1752
1753 #if wxUSE_DRAG_AND_DROP
1754 void wxWindowMSW::SetDropTarget(wxDropTarget *pDropTarget)
1755 {
1756 if ( m_dropTarget != 0 ) {
1757 m_dropTarget->Revoke(m_hWnd);
1758 delete m_dropTarget;
1759 }
1760
1761 m_dropTarget = pDropTarget;
1762 if ( m_dropTarget != 0 )
1763 {
1764 AdjustStaticBoxZOrder(GetParent());
1765 m_dropTarget->Register(m_hWnd);
1766 }
1767 }
1768 #endif // wxUSE_DRAG_AND_DROP
1769
1770 // old-style file manager drag&drop support: we retain the old-style
1771 // DragAcceptFiles in parallel with SetDropTarget.
1772 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept))
1773 {
1774 #ifndef __WXWINCE__
1775 HWND hWnd = GetHwnd();
1776 if ( hWnd )
1777 {
1778 AdjustStaticBoxZOrder(GetParent());
1779 ::DragAcceptFiles(hWnd, (BOOL)accept);
1780 }
1781 #endif
1782 }
1783
1784 // ----------------------------------------------------------------------------
1785 // tooltips
1786 // ----------------------------------------------------------------------------
1787
1788 #if wxUSE_TOOLTIPS
1789
1790 void wxWindowMSW::DoSetToolTip(wxToolTip *tooltip)
1791 {
1792 wxWindowBase::DoSetToolTip(tooltip);
1793
1794 if ( m_tooltip )
1795 m_tooltip->SetWindow((wxWindow *)this);
1796 }
1797
1798 #endif // wxUSE_TOOLTIPS
1799
1800 // ---------------------------------------------------------------------------
1801 // moving and resizing
1802 // ---------------------------------------------------------------------------
1803
1804 bool wxWindowMSW::IsSizeDeferred() const
1805 {
1806 #if wxUSE_DEFERRED_SIZING
1807 if ( m_pendingPosition != wxDefaultPosition ||
1808 m_pendingSize != wxDefaultSize )
1809 return true;
1810 #endif // wxUSE_DEFERRED_SIZING
1811
1812 return false;
1813 }
1814
1815 // Get total size
1816 void wxWindowMSW::DoGetSize(int *x, int *y) const
1817 {
1818 #if wxUSE_DEFERRED_SIZING
1819 // if SetSize() had been called at wx level but not realized at Windows
1820 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1821 // the new and not the old position to the other wx code
1822 if ( m_pendingSize != wxDefaultSize )
1823 {
1824 if ( x )
1825 *x = m_pendingSize.x;
1826 if ( y )
1827 *y = m_pendingSize.y;
1828 }
1829 else // use current size
1830 #endif // wxUSE_DEFERRED_SIZING
1831 {
1832 RECT rect = wxGetWindowRect(GetHwnd());
1833
1834 if ( x )
1835 *x = rect.right - rect.left;
1836 if ( y )
1837 *y = rect.bottom - rect.top;
1838 }
1839 }
1840
1841 // Get size *available for subwindows* i.e. excluding menu bar etc.
1842 void wxWindowMSW::DoGetClientSize(int *x, int *y) const
1843 {
1844 #if wxUSE_DEFERRED_SIZING
1845 if ( m_pendingSize != wxDefaultSize )
1846 {
1847 // we need to calculate the client size corresponding to pending size
1848 //
1849 // FIXME: Unfortunately this doesn't work correctly for the maximized
1850 // top level windows, the returned values are too small (e.g.
1851 // under Windows 7 on a 1600*1200 screen with task bar on the
1852 // right the pending size for a maximized window is 1538*1200
1853 // and WM_NCCALCSIZE returns 1528*1172 even though the correct
1854 // client size of such window is 1538*1182). No idea how to fix
1855 // it though, setting WS_MAXIMIZE in GWL_STYLE before calling
1856 // WM_NCCALCSIZE doesn't help and AdjustWindowRectEx() doesn't
1857 // work in this direction neither. So we just have to live with
1858 // the slightly wrong results and relayout the window when it
1859 // gets finally shown in its maximized state (see #11762).
1860 RECT rect;
1861 rect.left = m_pendingPosition.x;
1862 rect.top = m_pendingPosition.y;
1863 rect.right = rect.left + m_pendingSize.x;
1864 rect.bottom = rect.top + m_pendingSize.y;
1865
1866 ::SendMessage(GetHwnd(), WM_NCCALCSIZE, FALSE, (LPARAM)&rect);
1867
1868 if ( x )
1869 *x = rect.right - rect.left;
1870 if ( y )
1871 *y = rect.bottom - rect.top;
1872 }
1873 else
1874 #endif // wxUSE_DEFERRED_SIZING
1875 {
1876 RECT rect = wxGetClientRect(GetHwnd());
1877
1878 if ( x )
1879 *x = rect.right;
1880 if ( y )
1881 *y = rect.bottom;
1882 }
1883 }
1884
1885 void wxWindowMSW::DoGetPosition(int *x, int *y) const
1886 {
1887 wxWindow * const parent = GetParent();
1888
1889 wxPoint pos;
1890 #if wxUSE_DEFERRED_SIZING
1891 if ( m_pendingPosition != wxDefaultPosition )
1892 {
1893 pos = m_pendingPosition;
1894 }
1895 else // use current position
1896 #endif // wxUSE_DEFERRED_SIZING
1897 {
1898 RECT rect = wxGetWindowRect(GetHwnd());
1899
1900 POINT point;
1901 point.x = rect.left;
1902 point.y = rect.top;
1903
1904 // we do the adjustments with respect to the parent only for the "real"
1905 // children, not for the dialogs/frames
1906 if ( !IsTopLevel() )
1907 {
1908 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
1909 {
1910 // In RTL mode, we want the logical left x-coordinate,
1911 // which would be the physical right x-coordinate.
1912 point.x = rect.right;
1913 }
1914
1915 // Since we now have the absolute screen coords, if there's a
1916 // parent we must subtract its top left corner
1917 if ( parent )
1918 {
1919 ::ScreenToClient(GetHwndOf(parent), &point);
1920 }
1921 }
1922
1923 pos.x = point.x;
1924 pos.y = point.y;
1925 }
1926
1927 // we also must adjust by the client area offset: a control which is just
1928 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1929 if ( parent && !IsTopLevel() )
1930 {
1931 const wxPoint pt(parent->GetClientAreaOrigin());
1932 pos.x -= pt.x;
1933 pos.y -= pt.y;
1934 }
1935
1936 if ( x )
1937 *x = pos.x;
1938 if ( y )
1939 *y = pos.y;
1940 }
1941
1942 void wxWindowMSW::DoScreenToClient(int *x, int *y) const
1943 {
1944 POINT pt;
1945 if ( x )
1946 pt.x = *x;
1947 if ( y )
1948 pt.y = *y;
1949
1950 ::ScreenToClient(GetHwnd(), &pt);
1951
1952 if ( x )
1953 *x = pt.x;
1954 if ( y )
1955 *y = pt.y;
1956 }
1957
1958 void wxWindowMSW::DoClientToScreen(int *x, int *y) const
1959 {
1960 POINT pt;
1961 if ( x )
1962 pt.x = *x;
1963 if ( y )
1964 pt.y = *y;
1965
1966 ::ClientToScreen(GetHwnd(), &pt);
1967
1968 if ( x )
1969 *x = pt.x;
1970 if ( y )
1971 *y = pt.y;
1972 }
1973
1974 bool
1975 wxWindowMSW::DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height)
1976 {
1977 #if wxUSE_DEFERRED_SIZING
1978 // if our parent had prepared a defer window handle for us, use it (unless
1979 // we are a top level window)
1980 wxWindowMSW * const parent = IsTopLevel() ? NULL : GetParent();
1981
1982 HDWP hdwp = parent ? (HDWP)parent->m_hDWP : NULL;
1983 if ( hdwp )
1984 {
1985 hdwp = ::DeferWindowPos(hdwp, (HWND)hwnd, NULL, x, y, width, height,
1986 SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
1987 if ( !hdwp )
1988 {
1989 wxLogLastError(wxT("DeferWindowPos"));
1990 }
1991 }
1992
1993 if ( parent )
1994 {
1995 // hdwp must be updated as it may have been changed
1996 parent->m_hDWP = (WXHANDLE)hdwp;
1997 }
1998
1999 if ( hdwp )
2000 {
2001 // did deferred move, remember new coordinates of the window as they're
2002 // different from what Windows would return for it
2003 return true;
2004 }
2005
2006 // otherwise (or if deferring failed) move the window in place immediately
2007 #endif // wxUSE_DEFERRED_SIZING
2008 if ( !::MoveWindow((HWND)hwnd, x, y, width, height, IsShown()) )
2009 {
2010 wxLogLastError(wxT("MoveWindow"));
2011 }
2012
2013 // if wxUSE_DEFERRED_SIZING, indicates that we didn't use deferred move,
2014 // ignored otherwise
2015 return false;
2016 }
2017
2018 void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height)
2019 {
2020 // TODO: is this consistent with other platforms?
2021 // Still, negative width or height shouldn't be allowed
2022 if (width < 0)
2023 width = 0;
2024 if (height < 0)
2025 height = 0;
2026
2027 if ( DoMoveSibling(m_hWnd, x, y, width, height) )
2028 {
2029 #if wxUSE_DEFERRED_SIZING
2030 m_pendingPosition = wxPoint(x, y);
2031 m_pendingSize = wxSize(width, height);
2032 }
2033 else // window was moved immediately, without deferring it
2034 {
2035 m_pendingPosition = wxDefaultPosition;
2036 m_pendingSize = wxDefaultSize;
2037 #endif // wxUSE_DEFERRED_SIZING
2038 }
2039 }
2040
2041 // set the size of the window: if the dimensions are positive, just use them,
2042 // but if any of them is equal to -1, it means that we must find the value for
2043 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
2044 // which case -1 is a valid value for x and y)
2045 //
2046 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
2047 // the width/height to best suit our contents, otherwise we reuse the current
2048 // width/height
2049 void wxWindowMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
2050 {
2051 // get the current size and position...
2052 int currentX, currentY;
2053 int currentW, currentH;
2054
2055 GetPosition(&currentX, &currentY);
2056 GetSize(&currentW, &currentH);
2057
2058 // ... and don't do anything (avoiding flicker) if it's already ok unless
2059 // we're forced to resize the window
2060 if ( x == currentX && y == currentY &&
2061 width == currentW && height == currentH &&
2062 !(sizeFlags & wxSIZE_FORCE) )
2063 {
2064 if (sizeFlags & wxSIZE_FORCE_EVENT)
2065 {
2066 wxSizeEvent event( wxSize(width,height), GetId() );
2067 event.SetEventObject( this );
2068 HandleWindowEvent( event );
2069 }
2070 return;
2071 }
2072
2073 if ( x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
2074 x = currentX;
2075 if ( y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
2076 y = currentY;
2077
2078 AdjustForParentClientOrigin(x, y, sizeFlags);
2079
2080 wxSize size = wxDefaultSize;
2081 if ( width == wxDefaultCoord )
2082 {
2083 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
2084 {
2085 size = GetBestSize();
2086 width = size.x;
2087 }
2088 else
2089 {
2090 // just take the current one
2091 width = currentW;
2092 }
2093 }
2094
2095 if ( height == wxDefaultCoord )
2096 {
2097 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
2098 {
2099 if ( size.x == wxDefaultCoord )
2100 {
2101 size = GetBestSize();
2102 }
2103 //else: already called GetBestSize() above
2104
2105 height = size.y;
2106 }
2107 else
2108 {
2109 // just take the current one
2110 height = currentH;
2111 }
2112 }
2113
2114 DoMoveWindow(x, y, width, height);
2115 }
2116
2117 void wxWindowMSW::DoSetClientSize(int width, int height)
2118 {
2119 // setting the client size is less obvious than it could have been
2120 // because in the result of changing the total size the window scrollbar
2121 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
2122 // doesn't take neither into account) and so the client size will not be
2123 // correct as the difference between the total and client size changes --
2124 // so we keep changing it until we get it right
2125 //
2126 // normally this loop shouldn't take more than 3 iterations (usually 1 but
2127 // if scrollbars [dis]appear as the result of the first call, then 2 and it
2128 // may become 3 if the window had 0 size originally and so we didn't
2129 // calculate the scrollbar correction correctly during the first iteration)
2130 // but just to be on the safe side we check for it instead of making it an
2131 // "infinite" loop (i.e. leaving break inside as the only way to get out)
2132 for ( int i = 0; i < 4; i++ )
2133 {
2134 RECT rectClient;
2135 ::GetClientRect(GetHwnd(), &rectClient);
2136
2137 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
2138 if ( (rectClient.right == width || width == wxDefaultCoord) &&
2139 (rectClient.bottom == height || height == wxDefaultCoord) )
2140 {
2141 break;
2142 }
2143
2144 // Find the difference between the entire window (title bar and all)
2145 // and the client area; add this to the new client size to move the
2146 // window
2147 RECT rectWin;
2148 ::GetWindowRect(GetHwnd(), &rectWin);
2149
2150 const int widthWin = rectWin.right - rectWin.left,
2151 heightWin = rectWin.bottom - rectWin.top;
2152
2153 // MoveWindow positions the child windows relative to the parent, so
2154 // adjust if necessary
2155 if ( !IsTopLevel() )
2156 {
2157 wxWindow *parent = GetParent();
2158 if ( parent )
2159 {
2160 ::ScreenToClient(GetHwndOf(parent), (POINT *)&rectWin);
2161 }
2162 }
2163
2164 // don't call DoMoveWindow() because we want to move window immediately
2165 // and not defer it here as otherwise the value returned by
2166 // GetClient/WindowRect() wouldn't change as the window wouldn't be
2167 // really resized
2168 if ( !::MoveWindow(GetHwnd(),
2169 rectWin.left,
2170 rectWin.top,
2171 width + widthWin - rectClient.right,
2172 height + heightWin - rectClient.bottom,
2173 TRUE) )
2174 {
2175 wxLogLastError(wxT("MoveWindow"));
2176 }
2177 }
2178 }
2179
2180 wxSize wxWindowMSW::DoGetBorderSize() const
2181 {
2182 wxCoord border;
2183 switch ( GetBorder() )
2184 {
2185 case wxBORDER_STATIC:
2186 case wxBORDER_SIMPLE:
2187 border = 1;
2188 break;
2189
2190 case wxBORDER_SUNKEN:
2191 border = 2;
2192 break;
2193
2194 case wxBORDER_RAISED:
2195 case wxBORDER_DOUBLE:
2196 border = 3;
2197 break;
2198
2199 default:
2200 wxFAIL_MSG( wxT("unknown border style") );
2201 // fall through
2202
2203 case wxBORDER_NONE:
2204 border = 0;
2205 }
2206
2207 return 2*wxSize(border, border);
2208 }
2209
2210 // ---------------------------------------------------------------------------
2211 // text metrics
2212 // ---------------------------------------------------------------------------
2213
2214 int wxWindowMSW::GetCharHeight() const
2215 {
2216 return wxGetTextMetrics(this).tmHeight;
2217 }
2218
2219 int wxWindowMSW::GetCharWidth() const
2220 {
2221 // +1 is needed because Windows apparently adds it when calculating the
2222 // dialog units size in pixels
2223 #if wxDIALOG_UNIT_COMPATIBILITY
2224 return wxGetTextMetrics(this).tmAveCharWidth;
2225 #else
2226 return wxGetTextMetrics(this).tmAveCharWidth + 1;
2227 #endif
2228 }
2229
2230 void wxWindowMSW::DoGetTextExtent(const wxString& string,
2231 int *x, int *y,
2232 int *descent,
2233 int *externalLeading,
2234 const wxFont *fontToUse) const
2235 {
2236 wxASSERT_MSG( !fontToUse || fontToUse->Ok(),
2237 wxT("invalid font in GetTextExtent()") );
2238
2239 HFONT hfontToUse;
2240 if ( fontToUse )
2241 hfontToUse = GetHfontOf(*fontToUse);
2242 else
2243 hfontToUse = GetHfontOf(GetFont());
2244
2245 WindowHDC hdc(GetHwnd());
2246 SelectInHDC selectFont(hdc, hfontToUse);
2247
2248 SIZE sizeRect;
2249 TEXTMETRIC tm;
2250 ::GetTextExtentPoint32(hdc, string.wx_str(), string.length(), &sizeRect);
2251 GetTextMetrics(hdc, &tm);
2252
2253 if ( x )
2254 *x = sizeRect.cx;
2255 if ( y )
2256 *y = sizeRect.cy;
2257 if ( descent )
2258 *descent = tm.tmDescent;
2259 if ( externalLeading )
2260 *externalLeading = tm.tmExternalLeading;
2261 }
2262
2263 // ---------------------------------------------------------------------------
2264 // popup menu
2265 // ---------------------------------------------------------------------------
2266
2267 #if wxUSE_MENUS_NATIVE
2268
2269 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2270 // immediately, without waiting for the next event loop iteration
2271 //
2272 // NB: this function should probably be made public later as it can almost
2273 // surely replace wxYield() elsewhere as well
2274 static void wxYieldForCommandsOnly()
2275 {
2276 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2277 // want to process it here)
2278 MSG msg;
2279 while ( ::PeekMessage(&msg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE) )
2280 {
2281 if ( msg.message == WM_QUIT )
2282 {
2283 // if we retrieved a WM_QUIT, insert back into the message queue.
2284 ::PostQuitMessage(0);
2285 break;
2286 }
2287
2288 // luckily (as we don't have access to wxEventLoopImpl method from here
2289 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2290 // immediately
2291 ::TranslateMessage(&msg);
2292 ::DispatchMessage(&msg);
2293 }
2294 }
2295
2296 bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y)
2297 {
2298 menu->UpdateUI();
2299
2300 if ( x == wxDefaultCoord && y == wxDefaultCoord )
2301 {
2302 wxPoint mouse = ScreenToClient(wxGetMousePosition());
2303 x = mouse.x; y = mouse.y;
2304 }
2305
2306 HWND hWnd = GetHwnd();
2307 HMENU hMenu = GetHmenuOf(menu);
2308 POINT point;
2309 point.x = x;
2310 point.y = y;
2311 ::ClientToScreen(hWnd, &point);
2312 #if defined(__WXWINCE__)
2313 static const UINT flags = 0;
2314 #else // !__WXWINCE__
2315 UINT flags = TPM_RIGHTBUTTON;
2316 // NT4 doesn't support TPM_RECURSE and simply doesn't show the menu at all
2317 // when it's use, I'm not sure about Win95/98 but prefer to err on the safe
2318 // side and not to use it there neither -- modify the test if it does work
2319 // on these systems
2320 if ( wxGetWinVersion() >= wxWinVersion_5 )
2321 {
2322 // using TPM_RECURSE allows us to show a popup menu while another menu
2323 // is opened which can be useful and is supported by the other
2324 // platforms, so allow it under Windows too
2325 flags |= TPM_RECURSE;
2326 }
2327 #endif // __WXWINCE__/!__WXWINCE__
2328
2329 ::TrackPopupMenu(hMenu, flags, point.x, point.y, 0, hWnd, NULL);
2330
2331 // we need to do it right now as otherwise the events are never going to be
2332 // sent to wxCurrentPopupMenu from HandleCommand()
2333 //
2334 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2335 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2336 // destroyed as soon as we return (it can be a local variable in the caller
2337 // for example) and so we do need to process the event immediately
2338 wxYieldForCommandsOnly();
2339
2340 return true;
2341 }
2342
2343 #endif // wxUSE_MENUS_NATIVE
2344
2345 // ===========================================================================
2346 // pre/post message processing
2347 // ===========================================================================
2348
2349 WXLRESULT wxWindowMSW::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
2350 {
2351 if ( m_oldWndProc )
2352 return ::CallWindowProc(CASTWNDPROC m_oldWndProc, GetHwnd(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
2353 else
2354 return ::DefWindowProc(GetHwnd(), nMsg, wParam, lParam);
2355 }
2356
2357 bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
2358 {
2359 // wxUniversal implements tab traversal itself
2360 #ifndef __WXUNIVERSAL__
2361 if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) )
2362 {
2363 // intercept dialog navigation keys
2364 MSG *msg = (MSG *)pMsg;
2365
2366 // here we try to do all the job which ::IsDialogMessage() usually does
2367 // internally
2368 if ( msg->message == WM_KEYDOWN )
2369 {
2370 bool bCtrlDown = wxIsCtrlDown();
2371 bool bShiftDown = wxIsShiftDown();
2372
2373 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2374 // don't process it if it's the case (except for Ctrl-Tab/Enter
2375 // combinations which are always processed)
2376 LONG lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0);
2377
2378 // surprisingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2379 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2380 // it, of course, implies them
2381 if ( lDlgCode & DLGC_WANTALLKEYS )
2382 {
2383 lDlgCode |= DLGC_WANTTAB | DLGC_WANTARROWS;
2384 }
2385
2386 bool bForward = true,
2387 bWindowChange = false,
2388 bFromTab = false;
2389
2390 // should we process this message specially?
2391 bool bProcess = true;
2392 switch ( msg->wParam )
2393 {
2394 case VK_TAB:
2395 if ( (lDlgCode & DLGC_WANTTAB) && !bCtrlDown )
2396 {
2397 // let the control have the TAB
2398 bProcess = false;
2399 }
2400 else // use it for navigation
2401 {
2402 // Ctrl-Tab cycles thru notebook pages
2403 bWindowChange = bCtrlDown;
2404 bForward = !bShiftDown;
2405 bFromTab = true;
2406 }
2407 break;
2408
2409 case VK_UP:
2410 case VK_LEFT:
2411 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
2412 bProcess = false;
2413 else
2414 bForward = false;
2415 break;
2416
2417 case VK_DOWN:
2418 case VK_RIGHT:
2419 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
2420 bProcess = false;
2421 break;
2422
2423 case VK_PRIOR:
2424 bForward = false;
2425 // fall through
2426
2427 case VK_NEXT:
2428 // we treat PageUp/Dn as arrows because chances are that
2429 // a control which needs arrows also needs them for
2430 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2431 if ( (lDlgCode & DLGC_WANTARROWS) && !bCtrlDown )
2432 bProcess = false;
2433 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
2434 bWindowChange = true;
2435 break;
2436
2437 case VK_RETURN:
2438 {
2439 #if wxUSE_BUTTON
2440 // currently active button should get enter press even
2441 // if there is a default button elsewhere so check if
2442 // this window is a button first
2443 wxWindow *btn = NULL;
2444 if ( lDlgCode & DLGC_DEFPUSHBUTTON )
2445 {
2446 // let IsDialogMessage() handle this for all
2447 // buttons except the owner-drawn ones which it
2448 // just seems to ignore
2449 long style = ::GetWindowLong(msg->hwnd, GWL_STYLE);
2450 if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW )
2451 {
2452 // emulate the button click
2453 btn = wxFindWinFromHandle(msg->hwnd);
2454 }
2455
2456 bProcess = false;
2457 }
2458 else // not a button itself, do we have default button?
2459 {
2460 // check if this window or any of its ancestors
2461 // wants the message for itself (we always reserve
2462 // Ctrl-Enter for dialog navigation though)
2463 wxWindow *win = this;
2464 if ( !bCtrlDown )
2465 {
2466 // this will contain the dialog code of this
2467 // window and all of its parent windows in turn
2468 LONG lDlgCode2 = lDlgCode;
2469
2470 while ( win )
2471 {
2472 if ( lDlgCode2 & DLGC_WANTMESSAGE )
2473 {
2474 // as it wants to process Enter itself,
2475 // don't call IsDialogMessage() which
2476 // would consume it
2477 return false;
2478 }
2479
2480 // don't propagate keyboard messages beyond
2481 // the first top level window parent
2482 if ( win->IsTopLevel() )
2483 break;
2484
2485 win = win->GetParent();
2486
2487 lDlgCode2 = ::SendMessage
2488 (
2489 GetHwndOf(win),
2490 WM_GETDLGCODE,
2491 0,
2492 0
2493 );
2494 }
2495 }
2496 else // bCtrlDown
2497 {
2498 win = wxGetTopLevelParent(win);
2499 }
2500
2501 wxTopLevelWindow * const
2502 tlw = wxDynamicCast(win, wxTopLevelWindow);
2503 if ( tlw )
2504 {
2505 btn = wxDynamicCast(tlw->GetDefaultItem(),
2506 wxButton);
2507 }
2508 }
2509
2510 if ( btn && btn->IsEnabled() )
2511 {
2512 btn->MSWCommand(BN_CLICKED, 0 /* unused */);
2513 return true;
2514 }
2515
2516 #endif // wxUSE_BUTTON
2517
2518 #ifdef __WXWINCE__
2519 // map Enter presses into button presses on PDAs
2520 wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN);
2521 event.SetEventObject(this);
2522 if ( HandleWindowEvent(event) )
2523 return true;
2524 #endif // __WXWINCE__
2525 }
2526 break;
2527
2528 default:
2529 bProcess = false;
2530 }
2531
2532 if ( bProcess )
2533 {
2534 wxNavigationKeyEvent event;
2535 event.SetDirection(bForward);
2536 event.SetWindowChange(bWindowChange);
2537 event.SetFromTab(bFromTab);
2538 event.SetEventObject(this);
2539
2540 if ( HandleWindowEvent(event) )
2541 {
2542 // as we don't call IsDialogMessage(), which would take of
2543 // this by default, we need to manually send this message
2544 // so that controls can change their UI state if needed
2545 MSWUpdateUIState(UIS_CLEAR, UISF_HIDEFOCUS);
2546
2547 return true;
2548 }
2549 }
2550 }
2551
2552 if ( ::IsDialogMessage(GetHwnd(), msg) )
2553 {
2554 // IsDialogMessage() did something...
2555 return true;
2556 }
2557 }
2558 #endif // __WXUNIVERSAL__
2559
2560 #if wxUSE_TOOLTIPS
2561 if ( m_tooltip )
2562 {
2563 // relay mouse move events to the tooltip control
2564 MSG *msg = (MSG *)pMsg;
2565 if ( msg->message == WM_MOUSEMOVE )
2566 wxToolTip::RelayEvent(pMsg);
2567 }
2568 #endif // wxUSE_TOOLTIPS
2569
2570 return false;
2571 }
2572
2573 bool wxWindowMSW::MSWTranslateMessage(WXMSG* pMsg)
2574 {
2575 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2576 return m_acceleratorTable.Translate(this, pMsg);
2577 #else
2578 (void) pMsg;
2579 return false;
2580 #endif // wxUSE_ACCEL
2581 }
2582
2583 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG* msg)
2584 {
2585 // all tests below have to deal with various bugs/misfeatures of
2586 // IsDialogMessage(): we have to prevent it from being called from our
2587 // MSWProcessMessage() in some situations
2588
2589 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2590 // message even when there is no cancel button and when the message is
2591 // needed by the control itself: in particular, it prevents the tree in
2592 // place edit control from being closed with Escape in a dialog
2593 if ( msg->message == WM_KEYDOWN && msg->wParam == VK_ESCAPE )
2594 {
2595 return false;
2596 }
2597
2598 // ::IsDialogMessage() is broken and may sometimes hang the application by
2599 // going into an infinite loop when it tries to find the control to give
2600 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2601 // situations when this may happen and not call it then
2602 if ( msg->message != WM_SYSCHAR )
2603 return true;
2604
2605 // assume we can call it by default
2606 bool canSafelyCallIsDlgMsg = true;
2607
2608 HWND hwndFocus = ::GetFocus();
2609
2610 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2611 // ::IsDialogMessage() will also enter an infinite loop, because it will
2612 // recursively check the child windows but not the window itself and so if
2613 // none of the children accepts focus it loops forever (as it only stops
2614 // when it gets back to the window it started from)
2615 //
2616 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2617 // style has the focus, it can happen. One such possibility is if
2618 // all windows are either toplevel, wxDialog, wxPanel or static
2619 // controls and no window can actually accept keyboard input.
2620 #if !defined(__WXWINCE__)
2621 if ( ::GetWindowLong(hwndFocus, GWL_EXSTYLE) & WS_EX_CONTROLPARENT )
2622 {
2623 // pessimistic by default
2624 canSafelyCallIsDlgMsg = false;
2625 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2626 node;
2627 node = node->GetNext() )
2628 {
2629 wxWindow * const win = node->GetData();
2630 if ( win->CanAcceptFocus() &&
2631 !wxHasWindowExStyle(win, WS_EX_CONTROLPARENT) )
2632 {
2633 // it shouldn't hang...
2634 canSafelyCallIsDlgMsg = true;
2635
2636 break;
2637 }
2638 }
2639 }
2640 #endif // !__WXWINCE__
2641
2642 if ( canSafelyCallIsDlgMsg )
2643 {
2644 // ::IsDialogMessage() can enter in an infinite loop when the
2645 // currently focused window is disabled or hidden and its
2646 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2647 // this case
2648 while ( hwndFocus )
2649 {
2650 if ( !::IsWindowEnabled(hwndFocus) ||
2651 !::IsWindowVisible(hwndFocus) )
2652 {
2653 // it would enter an infinite loop if we do this!
2654 canSafelyCallIsDlgMsg = false;
2655
2656 break;
2657 }
2658
2659 if ( !(::GetWindowLong(hwndFocus, GWL_STYLE) & WS_CHILD) )
2660 {
2661 // it's a top level window, don't go further -- e.g. even
2662 // if the parent of a dialog is disabled, this doesn't
2663 // break navigation inside the dialog
2664 break;
2665 }
2666
2667 hwndFocus = ::GetParent(hwndFocus);
2668 }
2669 }
2670
2671 return canSafelyCallIsDlgMsg;
2672 }
2673
2674 // ---------------------------------------------------------------------------
2675 // message params unpackers
2676 // ---------------------------------------------------------------------------
2677
2678 void wxWindowMSW::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
2679 WORD *id, WXHWND *hwnd, WORD *cmd)
2680 {
2681 *id = LOWORD(wParam);
2682 *hwnd = (WXHWND)lParam;
2683 *cmd = HIWORD(wParam);
2684 }
2685
2686 void wxWindowMSW::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
2687 WXWORD *state, WXWORD *minimized, WXHWND *hwnd)
2688 {
2689 *state = LOWORD(wParam);
2690 *minimized = HIWORD(wParam);
2691 *hwnd = (WXHWND)lParam;
2692 }
2693
2694 void wxWindowMSW::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
2695 WXWORD *code, WXWORD *pos, WXHWND *hwnd)
2696 {
2697 *code = LOWORD(wParam);
2698 *pos = HIWORD(wParam);
2699 *hwnd = (WXHWND)lParam;
2700 }
2701
2702 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
2703 WXHDC *hdc, WXHWND *hwnd)
2704 {
2705 *hwnd = (WXHWND)lParam;
2706 *hdc = (WXHDC)wParam;
2707 }
2708
2709 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
2710 WXWORD *item, WXWORD *flags, WXHMENU *hmenu)
2711 {
2712 *item = (WXWORD)wParam;
2713 *flags = HIWORD(wParam);
2714 *hmenu = (WXHMENU)lParam;
2715 }
2716
2717 // ---------------------------------------------------------------------------
2718 // Main wxWidgets window proc and the window proc for wxWindow
2719 // ---------------------------------------------------------------------------
2720
2721 // Hook for new window just as it's being created, when the window isn't yet
2722 // associated with the handle
2723 static wxWindowMSW *gs_winBeingCreated = NULL;
2724
2725 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2726 // window being created and insures that it's always unset back later
2727 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW *winBeingCreated)
2728 {
2729 gs_winBeingCreated = winBeingCreated;
2730 }
2731
2732 wxWindowCreationHook::~wxWindowCreationHook()
2733 {
2734 gs_winBeingCreated = NULL;
2735 }
2736
2737 // Main window proc
2738 LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
2739 {
2740 // trace all messages: useful for the debugging but noticeably slows down
2741 // the code so don't do it by default
2742 #if wxDEBUG_LEVEL >= 2
2743 // notice that we cast wParam and lParam to long to avoid mismatch with
2744 // format specifiers in 64 bit builds where they are both int64 quantities
2745 //
2746 // casting like this loses information, of course, but it shouldn't matter
2747 // much for this diagnostic code and it keeps the code simple
2748 wxLogTrace("winmsg",
2749 wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"),
2750 wxGetMessageName(message), hWnd, (long)wParam, (long)lParam);
2751 #endif // wxDEBUG_LEVEL >= 2
2752
2753 wxWindowMSW *wnd = wxFindWinFromHandle(hWnd);
2754
2755 // when we get the first message for the HWND we just created, we associate
2756 // it with wxWindow stored in gs_winBeingCreated
2757 if ( !wnd && gs_winBeingCreated )
2758 {
2759 wxAssociateWinWithHandle(hWnd, gs_winBeingCreated);
2760 wnd = gs_winBeingCreated;
2761 gs_winBeingCreated = NULL;
2762 wnd->SetHWND((WXHWND)hWnd);
2763 }
2764
2765 LRESULT rc;
2766
2767 if ( wnd && wxGUIEventLoop::AllowProcessing(wnd) )
2768 rc = wnd->MSWWindowProc(message, wParam, lParam);
2769 else
2770 rc = ::DefWindowProc(hWnd, message, wParam, lParam);
2771
2772 return rc;
2773 }
2774
2775 WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
2776 {
2777 // did we process the message?
2778 bool processed = false;
2779
2780 // the return value
2781 union
2782 {
2783 bool allow;
2784 WXLRESULT result;
2785 WXHBRUSH hBrush;
2786 } rc;
2787
2788 // for most messages we should return 0 when we do process the message
2789 rc.result = 0;
2790
2791 switch ( message )
2792 {
2793 case WM_CREATE:
2794 {
2795 bool mayCreate;
2796 processed = HandleCreate((WXLPCREATESTRUCT)lParam, &mayCreate);
2797 if ( processed )
2798 {
2799 // return 0 to allow window creation
2800 rc.result = mayCreate ? 0 : -1;
2801 }
2802 }
2803 break;
2804
2805 case WM_DESTROY:
2806 // never set processed to true and *always* pass WM_DESTROY to
2807 // DefWindowProc() as Windows may do some internal cleanup when
2808 // processing it and failing to pass the message along may cause
2809 // memory and resource leaks!
2810 (void)HandleDestroy();
2811 break;
2812
2813 case WM_SIZE:
2814 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
2815 break;
2816
2817 case WM_MOVE:
2818 processed = HandleMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
2819 break;
2820
2821 #if !defined(__WXWINCE__)
2822 case WM_MOVING:
2823 {
2824 LPRECT pRect = (LPRECT)lParam;
2825 wxRect rc;
2826 rc.SetLeft(pRect->left);
2827 rc.SetTop(pRect->top);
2828 rc.SetRight(pRect->right);
2829 rc.SetBottom(pRect->bottom);
2830 processed = HandleMoving(rc);
2831 if (processed) {
2832 pRect->left = rc.GetLeft();
2833 pRect->top = rc.GetTop();
2834 pRect->right = rc.GetRight();
2835 pRect->bottom = rc.GetBottom();
2836 }
2837 }
2838 break;
2839 #if 0
2840 case WM_ENTERSIZEMOVE:
2841 {
2842 processed = HandleEnterSizeMove();
2843 }
2844 break;
2845
2846 case WM_EXITSIZEMOVE:
2847 {
2848 processed = HandleExitSizeMove();
2849 }
2850 break;
2851 #endif
2852 case WM_SIZING:
2853 {
2854 LPRECT pRect = (LPRECT)lParam;
2855 wxRect rc;
2856 rc.SetLeft(pRect->left);
2857 rc.SetTop(pRect->top);
2858 rc.SetRight(pRect->right);
2859 rc.SetBottom(pRect->bottom);
2860 processed = HandleSizing(rc);
2861 if (processed) {
2862 pRect->left = rc.GetLeft();
2863 pRect->top = rc.GetTop();
2864 pRect->right = rc.GetRight();
2865 pRect->bottom = rc.GetBottom();
2866 }
2867 }
2868 break;
2869 #endif // !__WXWINCE__
2870
2871 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2872 case WM_ACTIVATEAPP:
2873 // This implicitly sends a wxEVT_ACTIVATE_APP event
2874 wxTheApp->SetActive(wParam != 0, FindFocus());
2875 break;
2876 #endif
2877
2878 case WM_ACTIVATE:
2879 {
2880 WXWORD state, minimized;
2881 WXHWND hwnd;
2882 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
2883
2884 processed = HandleActivate(state, minimized != 0, (WXHWND)hwnd);
2885 }
2886 break;
2887
2888 case WM_SETFOCUS:
2889 processed = HandleSetFocus((WXHWND)wParam);
2890 break;
2891
2892 case WM_KILLFOCUS:
2893 processed = HandleKillFocus((WXHWND)wParam);
2894 break;
2895
2896 case WM_PRINTCLIENT:
2897 processed = HandlePrintClient((WXHDC)wParam);
2898 break;
2899
2900 case WM_PAINT:
2901 if ( wParam )
2902 {
2903 wxPaintDCEx dc((wxWindow *)this, (WXHDC)wParam);
2904
2905 processed = HandlePaint();
2906 }
2907 else // no DC given
2908 {
2909 processed = HandlePaint();
2910 }
2911 break;
2912
2913 case WM_CLOSE:
2914 #ifdef __WXUNIVERSAL__
2915 // Universal uses its own wxFrame/wxDialog, so we don't receive
2916 // close events unless we have this.
2917 Close();
2918 #endif // __WXUNIVERSAL__
2919
2920 // don't let the DefWindowProc() destroy our window - we'll do it
2921 // ourselves in ~wxWindow
2922 processed = true;
2923 rc.result = TRUE;
2924 break;
2925
2926 case WM_SHOWWINDOW:
2927 processed = HandleShow(wParam != 0, (int)lParam);
2928 break;
2929
2930 case WM_MOUSEMOVE:
2931 processed = HandleMouseMove(GET_X_LPARAM(lParam),
2932 GET_Y_LPARAM(lParam),
2933 wParam);
2934 break;
2935
2936 #ifdef HAVE_TRACKMOUSEEVENT
2937 case WM_MOUSELEAVE:
2938 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2939 // (on XP at least)
2940 if ( m_mouseInWindow )
2941 {
2942 GenerateMouseLeave();
2943 }
2944
2945 // always pass processed back as false, this allows the window
2946 // manager to process the message too. This is needed to
2947 // ensure windows XP themes work properly as the mouse moves
2948 // over widgets like buttons. So don't set processed to true here.
2949 break;
2950 #endif // HAVE_TRACKMOUSEEVENT
2951
2952 #if wxUSE_MOUSEWHEEL
2953 case WM_MOUSEWHEEL:
2954 processed = HandleMouseWheel(wParam, lParam);
2955 break;
2956 #endif
2957
2958 case WM_LBUTTONDOWN:
2959 case WM_LBUTTONUP:
2960 case WM_LBUTTONDBLCLK:
2961 case WM_RBUTTONDOWN:
2962 case WM_RBUTTONUP:
2963 case WM_RBUTTONDBLCLK:
2964 case WM_MBUTTONDOWN:
2965 case WM_MBUTTONUP:
2966 case WM_MBUTTONDBLCLK:
2967 #ifdef wxHAS_XBUTTON
2968 case WM_XBUTTONDOWN:
2969 case WM_XBUTTONUP:
2970 case WM_XBUTTONDBLCLK:
2971 #endif // wxHAS_XBUTTON
2972 {
2973 #ifdef __WXMICROWIN__
2974 // MicroWindows seems to ignore the fact that a window is
2975 // disabled. So catch mouse events and throw them away if
2976 // necessary.
2977 wxWindowMSW* win = this;
2978 for ( ;; )
2979 {
2980 if (!win->IsEnabled())
2981 {
2982 processed = true;
2983 break;
2984 }
2985
2986 win = win->GetParent();
2987 if ( !win || win->IsTopLevel() )
2988 break;
2989 }
2990
2991 if ( processed )
2992 break;
2993
2994 #endif // __WXMICROWIN__
2995 int x = GET_X_LPARAM(lParam),
2996 y = GET_Y_LPARAM(lParam);
2997
2998 #ifdef __WXWINCE__
2999 // redirect the event to a static control if necessary by
3000 // finding one under mouse because under CE the static controls
3001 // don't generate mouse events (even with SS_NOTIFY)
3002 wxWindowMSW *win;
3003 if ( GetCapture() == this )
3004 {
3005 // but don't do it if the mouse is captured by this window
3006 // because then it should really get this event itself
3007 win = this;
3008 }
3009 else
3010 {
3011 win = FindWindowForMouseEvent(this, &x, &y);
3012
3013 // this should never happen
3014 wxCHECK_MSG( win, 0,
3015 wxT("FindWindowForMouseEvent() returned NULL") );
3016 }
3017 #ifdef __POCKETPC__
3018 if (IsContextMenuEnabled() && message == WM_LBUTTONDOWN)
3019 {
3020 SHRGINFO shrgi = {0};
3021
3022 shrgi.cbSize = sizeof(SHRGINFO);
3023 shrgi.hwndClient = (HWND) GetHWND();
3024 shrgi.ptDown.x = x;
3025 shrgi.ptDown.y = y;
3026
3027 shrgi.dwFlags = SHRG_RETURNCMD;
3028 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
3029
3030 if (GN_CONTEXTMENU == ::SHRecognizeGesture(&shrgi))
3031 {
3032 wxPoint pt(x, y);
3033 pt = ClientToScreen(pt);
3034
3035 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt);
3036
3037 evtCtx.SetEventObject(this);
3038 if (HandleWindowEvent(evtCtx))
3039 {
3040 processed = true;
3041 return true;
3042 }
3043 }
3044 }
3045 #endif
3046
3047 #else // !__WXWINCE__
3048 wxWindowMSW *win = this;
3049 #endif // __WXWINCE__/!__WXWINCE__
3050
3051 processed = win->HandleMouseEvent(message, x, y, wParam);
3052
3053 // if the app didn't eat the event, handle it in the default
3054 // way, that is by giving this window the focus
3055 if ( !processed )
3056 {
3057 // for the standard classes their WndProc sets the focus to
3058 // them anyhow and doing it from here results in some weird
3059 // problems, so don't do it for them (unnecessary anyhow)
3060 if ( !win->IsOfStandardClass() )
3061 {
3062 if ( message == WM_LBUTTONDOWN && win->IsFocusable() )
3063 win->SetFocus();
3064 }
3065 }
3066 }
3067 break;
3068
3069 #ifdef MM_JOY1MOVE
3070 case MM_JOY1MOVE:
3071 case MM_JOY2MOVE:
3072 case MM_JOY1ZMOVE:
3073 case MM_JOY2ZMOVE:
3074 case MM_JOY1BUTTONDOWN:
3075 case MM_JOY2BUTTONDOWN:
3076 case MM_JOY1BUTTONUP:
3077 case MM_JOY2BUTTONUP:
3078 processed = HandleJoystickEvent(message,
3079 GET_X_LPARAM(lParam),
3080 GET_Y_LPARAM(lParam),
3081 wParam);
3082 break;
3083 #endif // __WXMICROWIN__
3084
3085 case WM_COMMAND:
3086 {
3087 WORD id, cmd;
3088 WXHWND hwnd;
3089 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
3090
3091 processed = HandleCommand(id, cmd, hwnd);
3092 }
3093 break;
3094
3095 case WM_NOTIFY:
3096 processed = HandleNotify((int)wParam, lParam, &rc.result);
3097 break;
3098
3099 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
3100 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
3101 // apparently doesn't always behave properly and needs some help
3102 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
3103 case WM_NOTIFYFORMAT:
3104 if ( lParam == NF_QUERY )
3105 {
3106 processed = true;
3107 rc.result = NFR_UNICODE;
3108 }
3109 break;
3110 #endif // wxUSE_UNICODE_MSLU
3111
3112 // for these messages we must return true if process the message
3113 #ifdef WM_DRAWITEM
3114 case WM_DRAWITEM:
3115 processed = MSWOnDrawItem(wParam, (WXDRAWITEMSTRUCT *)lParam);
3116 if ( processed )
3117 rc.result = TRUE;
3118 break;
3119
3120 case WM_MEASUREITEM:
3121 processed = MSWOnMeasureItem(wParam, (WXMEASUREITEMSTRUCT *)lParam);
3122 if ( processed )
3123 rc.result = TRUE;
3124 break;
3125 #endif // defined(WM_DRAWITEM)
3126
3127 case WM_GETDLGCODE:
3128 if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS) )
3129 {
3130 // we always want to get the char events
3131 rc.result = DLGC_WANTCHARS;
3132
3133 if ( HasFlag(wxWANTS_CHARS) )
3134 {
3135 // in fact, we want everything
3136 rc.result |= DLGC_WANTARROWS |
3137 DLGC_WANTTAB |
3138 DLGC_WANTALLKEYS;
3139 }
3140
3141 processed = true;
3142 }
3143 //else: get the dlg code from the DefWindowProc()
3144 break;
3145
3146 case WM_SYSKEYDOWN:
3147 case WM_KEYDOWN:
3148 // Generate the key down event in any case.
3149 m_lastKeydownProcessed = HandleKeyDown((WORD) wParam, lParam);
3150 if ( m_lastKeydownProcessed )
3151 {
3152 // If it was processed by an event handler, we stop here,
3153 // notably we intentionally don't generate char event then.
3154 processed = true;
3155 }
3156 else // key down event not handled
3157 {
3158 // Examine the event to decide whether we need to generate a
3159 // char event for it ourselves or let Windows do it. Window
3160 // mostly only does it for the keys which produce printable
3161 // characters (although there are exceptions, e.g. VK_ESCAPE or
3162 // VK_BACK (but not VK_DELETE)) while we do it for all keys
3163 // except the modifier ones (the wisdom of this is debatable
3164 // but by now this decision is enshrined forever due to
3165 // backwards compatibility).
3166 switch ( wParam )
3167 {
3168 // No wxEVT_CHAR events are generated for these keys at all.
3169 case VK_SHIFT:
3170 case VK_CONTROL:
3171 case VK_MENU:
3172 case VK_CAPITAL:
3173 case VK_NUMLOCK:
3174 case VK_SCROLL:
3175
3176 // Windows will send us WM_CHAR for these ones so we'll
3177 // generate wxEVT_CHAR for them later when we get it.
3178 case VK_ESCAPE:
3179 case VK_SPACE:
3180 case VK_RETURN:
3181 case VK_BACK:
3182 case VK_TAB:
3183 case VK_ADD:
3184 case VK_SUBTRACT:
3185 case VK_MULTIPLY:
3186 case VK_DIVIDE:
3187 case VK_DECIMAL:
3188 case VK_NUMPAD0:
3189 case VK_NUMPAD1:
3190 case VK_NUMPAD2:
3191 case VK_NUMPAD3:
3192 case VK_NUMPAD4:
3193 case VK_NUMPAD5:
3194 case VK_NUMPAD6:
3195 case VK_NUMPAD7:
3196 case VK_NUMPAD8:
3197 case VK_NUMPAD9:
3198 case VK_OEM_1:
3199 case VK_OEM_2:
3200 case VK_OEM_3:
3201 case VK_OEM_4:
3202 case VK_OEM_5:
3203 case VK_OEM_6:
3204 case VK_OEM_7:
3205 case VK_OEM_PLUS:
3206 case VK_OEM_COMMA:
3207 case VK_OEM_MINUS:
3208 case VK_OEM_PERIOD:
3209 break;
3210
3211 #ifdef VK_APPS
3212 // special case of VK_APPS: treat it the same as right mouse
3213 // click because both usually pop up a context menu
3214 case VK_APPS:
3215 processed = HandleMouseEvent(WM_RBUTTONDOWN, -1, -1, 0);
3216 break;
3217 #endif // VK_APPS
3218
3219 default:
3220 if ( (wParam >= '0' && wParam <= '9') ||
3221 (wParam >= 'A' && wParam <= 'Z') )
3222 {
3223 // We'll get WM_CHAR for those later too.
3224 break;
3225 }
3226
3227 // But for the rest we won't get WM_CHAR later so we do
3228 // need to generate the event right now.
3229 wxKeyEvent event(wxEVT_CHAR);
3230 InitAnyKeyEvent(event, wParam, lParam);
3231
3232 // Set the "extended" bit in lParam because we want to
3233 // generate CHAR events with WXK_HOME and not
3234 // WXK_NUMPAD_HOME even if the "Home" key on numpad was
3235 // pressed.
3236 event.m_keyCode = wxMSWKeyboard::VKToWX
3237 (
3238 wParam,
3239 lParam | (KF_EXTENDED << 16)
3240 );
3241
3242 // Don't produce events without any valid character
3243 // code (even if this shouldn't normally happen...).
3244 if ( event.m_keyCode != WXK_NONE )
3245 processed = HandleWindowEvent(event);
3246 }
3247 }
3248 if (message == WM_SYSKEYDOWN) // Let Windows still handle the SYSKEYs
3249 processed = false;
3250 break;
3251
3252 case WM_SYSKEYUP:
3253 case WM_KEYUP:
3254 #ifdef VK_APPS
3255 // special case of VK_APPS: treat it the same as right mouse button
3256 if ( wParam == VK_APPS )
3257 {
3258 processed = HandleMouseEvent(WM_RBUTTONUP, -1, -1, 0);
3259 }
3260 else
3261 #endif // VK_APPS
3262 {
3263 processed = HandleKeyUp((WORD) wParam, lParam);
3264 }
3265 break;
3266
3267 case WM_SYSCHAR:
3268 case WM_CHAR: // Always an ASCII character
3269 if ( m_lastKeydownProcessed )
3270 {
3271 // The key was handled in the EVT_KEY_DOWN and handling
3272 // a key in an EVT_KEY_DOWN handler is meant, by
3273 // design, to prevent EVT_CHARs from happening
3274 m_lastKeydownProcessed = false;
3275 processed = true;
3276 }
3277 else
3278 {
3279 processed = HandleChar((WORD)wParam, lParam);
3280 }
3281 break;
3282
3283 #if wxUSE_HOTKEY
3284 case WM_HOTKEY:
3285 processed = HandleHotKey((WORD)wParam, lParam);
3286 break;
3287 #endif // wxUSE_HOTKEY
3288
3289 case WM_CUT:
3290 case WM_COPY:
3291 case WM_PASTE:
3292 processed = HandleClipboardEvent(message);
3293 break;
3294
3295 case WM_HSCROLL:
3296 case WM_VSCROLL:
3297 {
3298 WXWORD code, pos;
3299 WXHWND hwnd;
3300 UnpackScroll(wParam, lParam, &code, &pos, &hwnd);
3301
3302 processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL
3303 : wxVERTICAL,
3304 code, pos, hwnd);
3305 }
3306 break;
3307
3308 // CTLCOLOR messages are sent by children to query the parent for their
3309 // colors
3310 #ifndef __WXMICROWIN__
3311 case WM_CTLCOLORMSGBOX:
3312 case WM_CTLCOLOREDIT:
3313 case WM_CTLCOLORLISTBOX:
3314 case WM_CTLCOLORBTN:
3315 case WM_CTLCOLORDLG:
3316 case WM_CTLCOLORSCROLLBAR:
3317 case WM_CTLCOLORSTATIC:
3318 {
3319 WXHDC hdc;
3320 WXHWND hwnd;
3321 UnpackCtlColor(wParam, lParam, &hdc, &hwnd);
3322
3323 processed = HandleCtlColor(&rc.hBrush, (WXHDC)hdc, (WXHWND)hwnd);
3324 }
3325 break;
3326 #endif // !__WXMICROWIN__
3327
3328 case WM_SYSCOLORCHANGE:
3329 // the return value for this message is ignored
3330 processed = HandleSysColorChange();
3331 break;
3332
3333 #if !defined(__WXWINCE__)
3334 case WM_DISPLAYCHANGE:
3335 processed = HandleDisplayChange();
3336 break;
3337 #endif
3338
3339 case WM_PALETTECHANGED:
3340 processed = HandlePaletteChanged((WXHWND)wParam);
3341 break;
3342
3343 case WM_CAPTURECHANGED:
3344 processed = HandleCaptureChanged((WXHWND)lParam);
3345 break;
3346
3347 case WM_SETTINGCHANGE:
3348 processed = HandleSettingChange(wParam, lParam);
3349 break;
3350
3351 case WM_QUERYNEWPALETTE:
3352 processed = HandleQueryNewPalette();
3353 break;
3354
3355 case WM_ERASEBKGND:
3356 {
3357 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
3358 // check if an override was configured for this window
3359 EraseBgHooks::const_iterator it = gs_eraseBgHooks.find(this);
3360 if ( it != gs_eraseBgHooks.end() )
3361 processed = it->second->MSWEraseBgHook((WXHDC)wParam);
3362 else
3363 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
3364 processed = HandleEraseBkgnd((WXHDC)wParam);
3365 }
3366
3367 if ( processed )
3368 {
3369 // we processed the message, i.e. erased the background
3370 rc.result = TRUE;
3371 }
3372 break;
3373
3374 #if !defined(__WXWINCE__)
3375 case WM_DROPFILES:
3376 processed = HandleDropFiles(wParam);
3377 break;
3378 #endif
3379
3380 case WM_INITDIALOG:
3381 processed = HandleInitDialog((WXHWND)wParam);
3382
3383 if ( processed )
3384 {
3385 // we never set focus from here
3386 rc.result = FALSE;
3387 }
3388 break;
3389
3390 #if !defined(__WXWINCE__)
3391 case WM_QUERYENDSESSION:
3392 processed = HandleQueryEndSession(lParam, &rc.allow);
3393 break;
3394
3395 case WM_ENDSESSION:
3396 processed = HandleEndSession(wParam != 0, lParam);
3397 break;
3398
3399 case WM_GETMINMAXINFO:
3400 processed = HandleGetMinMaxInfo((MINMAXINFO*)lParam);
3401 break;
3402 #endif
3403
3404 case WM_SETCURSOR:
3405 processed = HandleSetCursor((WXHWND)wParam,
3406 LOWORD(lParam), // hit test
3407 HIWORD(lParam)); // mouse msg
3408
3409 if ( processed )
3410 {
3411 // returning TRUE stops the DefWindowProc() from further
3412 // processing this message - exactly what we need because we've
3413 // just set the cursor.
3414 rc.result = TRUE;
3415 }
3416 break;
3417
3418 #if wxUSE_ACCESSIBILITY
3419 case WM_GETOBJECT:
3420 {
3421 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3422 LPARAM dwObjId = (LPARAM) (DWORD) lParam;
3423
3424 if (dwObjId == (LPARAM)OBJID_CLIENT && GetOrCreateAccessible())
3425 {
3426 return LresultFromObject(IID_IAccessible, wParam, (IUnknown*) GetAccessible()->GetIAccessible());
3427 }
3428 break;
3429 }
3430 #endif
3431
3432 #if defined(WM_HELP)
3433 case WM_HELP:
3434 {
3435 // by default, WM_HELP is propagated by DefWindowProc() upwards
3436 // to the window parent but as we do it ourselves already
3437 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3438 // to get the other events if we process this message at all
3439 processed = true;
3440
3441 // WM_HELP doesn't use lParam under CE
3442 #ifndef __WXWINCE__
3443 HELPINFO* info = (HELPINFO*) lParam;
3444 if ( info->iContextType == HELPINFO_WINDOW )
3445 {
3446 #endif // !__WXWINCE__
3447 wxHelpEvent helpEvent
3448 (
3449 wxEVT_HELP,
3450 GetId(),
3451 #ifdef __WXWINCE__
3452 wxGetMousePosition() // what else?
3453 #else
3454 wxPoint(info->MousePos.x, info->MousePos.y)
3455 #endif
3456 );
3457
3458 helpEvent.SetEventObject(this);
3459 HandleWindowEvent(helpEvent);
3460 #ifndef __WXWINCE__
3461 }
3462 else if ( info->iContextType == HELPINFO_MENUITEM )
3463 {
3464 wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
3465 helpEvent.SetEventObject(this);
3466 HandleWindowEvent(helpEvent);
3467
3468 }
3469 else // unknown help event?
3470 {
3471 processed = false;
3472 }
3473 #endif // !__WXWINCE__
3474 }
3475 break;
3476 #endif // WM_HELP
3477
3478 #if !defined(__WXWINCE__)
3479 case WM_CONTEXTMENU:
3480 {
3481 // we don't convert from screen to client coordinates as
3482 // the event may be handled by a parent window
3483 wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
3484
3485 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt);
3486
3487 // we could have got an event from our child, reflect it back
3488 // to it if this is the case
3489 wxWindowMSW *win = NULL;
3490 WXHWND hWnd = (WXHWND)wParam;
3491 if ( hWnd != m_hWnd )
3492 {
3493 win = FindItemByHWND(hWnd);
3494 }
3495
3496 if ( !win )
3497 win = this;
3498
3499 evtCtx.SetEventObject(win);
3500 processed = win->HandleWindowEvent(evtCtx);
3501 }
3502 break;
3503 #endif
3504
3505 #if wxUSE_MENUS
3506 case WM_MENUCHAR:
3507 // we're only interested in our own menus, not MF_SYSMENU
3508 if ( HIWORD(wParam) == MF_POPUP )
3509 {
3510 // handle menu chars for ownerdrawn menu items
3511 int i = HandleMenuChar(toupper(LOWORD(wParam)), lParam);
3512 if ( i != wxNOT_FOUND )
3513 {
3514 rc.result = MAKELRESULT(i, MNC_EXECUTE);
3515 processed = true;
3516 }
3517 }
3518 break;
3519 #endif // wxUSE_MENUS
3520
3521 #ifndef __WXWINCE__
3522 case WM_POWERBROADCAST:
3523 {
3524 bool vetoed;
3525 processed = HandlePower(wParam, lParam, &vetoed);
3526 rc.result = processed && vetoed ? BROADCAST_QUERY_DENY : TRUE;
3527 }
3528 break;
3529 #endif // __WXWINCE__
3530
3531 #if wxUSE_UXTHEME
3532 // If we want the default themed border then we need to draw it ourselves
3533 case WM_NCCALCSIZE:
3534 {
3535 wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive();
3536 const wxBorder border = TranslateBorder(GetBorder());
3537 if (theme && border == wxBORDER_THEME)
3538 {
3539 // first ask the widget to calculate the border size
3540 rc.result = MSWDefWindowProc(message, wParam, lParam);
3541 processed = true;
3542
3543 // now alter the client size making room for drawing a
3544 // themed border
3545 RECT *rect;
3546 NCCALCSIZE_PARAMS *csparam = NULL;
3547 if ( wParam )
3548 {
3549 csparam = (NCCALCSIZE_PARAMS *)lParam;
3550 rect = &csparam->rgrc[0];
3551 }
3552 else
3553 {
3554 rect = (RECT *)lParam;
3555 }
3556
3557 wxUxThemeHandle hTheme((const wxWindow *)this, L"EDIT");
3558 RECT rcClient = { 0, 0, 0, 0 };
3559 wxClientDC dc((wxWindow *)this);
3560 wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
3561
3562 if ( theme->GetThemeBackgroundContentRect
3563 (
3564 hTheme,
3565 GetHdcOf(*impl),
3566 EP_EDITTEXT,
3567 ETS_NORMAL,
3568 rect,
3569 &rcClient) == S_OK )
3570 {
3571 InflateRect(&rcClient, -1, -1);
3572 if (wParam)
3573 csparam->rgrc[0] = rcClient;
3574 else
3575 *((RECT*)lParam) = rcClient;
3576
3577 // WVR_REDRAW triggers a bug whereby child windows are moved up and left,
3578 // so don't use.
3579 // rc.result = WVR_REDRAW;
3580 }
3581 }
3582 }
3583 break;
3584
3585 case WM_NCPAINT:
3586 {
3587 wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive();
3588 const wxBorder border = TranslateBorder(GetBorder());
3589 if (theme && border == wxBORDER_THEME)
3590 {
3591 // first ask the widget to paint its non-client area, such as scrollbars, etc.
3592 rc.result = MSWDefWindowProc(message, wParam, lParam);
3593 processed = true;
3594
3595 wxUxThemeHandle hTheme((const wxWindow *)this, L"EDIT");
3596 wxWindowDC dc((wxWindow *)this);
3597 wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
3598
3599 // Clip the DC so that you only draw on the non-client area
3600 RECT rcBorder;
3601 wxCopyRectToRECT(GetSize(), rcBorder);
3602
3603 RECT rcClient;
3604 theme->GetThemeBackgroundContentRect(
3605 hTheme, GetHdcOf(*impl), EP_EDITTEXT, ETS_NORMAL, &rcBorder, &rcClient);
3606 InflateRect(&rcClient, -1, -1);
3607
3608 ::ExcludeClipRect(GetHdcOf(*impl), rcClient.left, rcClient.top,
3609 rcClient.right, rcClient.bottom);
3610
3611 // Make sure the background is in a proper state
3612 if (theme->IsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL))
3613 {
3614 theme->DrawThemeParentBackground(GetHwnd(), GetHdcOf(*impl), &rcBorder);
3615 }
3616
3617 // Draw the border
3618 int nState;
3619 if ( !IsEnabled() )
3620 nState = ETS_DISABLED;
3621 // should we check this?
3622 //else if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & ES_READONLY)
3623 // nState = ETS_READONLY;
3624 else
3625 nState = ETS_NORMAL;
3626 theme->DrawThemeBackground(hTheme, GetHdcOf(*impl), EP_EDITTEXT, nState, &rcBorder, NULL);
3627 }
3628 }
3629 break;
3630
3631 #endif // wxUSE_UXTHEME
3632
3633 default:
3634 // try a custom message handler
3635 const MSWMessageHandlers::const_iterator
3636 i = gs_messageHandlers.find(message);
3637 if ( i != gs_messageHandlers.end() )
3638 {
3639 processed = (*i->second)(this, message, wParam, lParam);
3640 }
3641 }
3642
3643 if ( !processed )
3644 {
3645 #if wxDEBUG_LEVEL >= 2
3646 wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."),
3647 wxGetMessageName(message));
3648 #endif // wxDEBUG_LEVEL >= 2
3649 rc.result = MSWDefWindowProc(message, wParam, lParam);
3650 }
3651
3652 return rc.result;
3653 }
3654
3655 // ----------------------------------------------------------------------------
3656 // wxWindow <-> HWND map
3657 // ----------------------------------------------------------------------------
3658
3659 wxWindow *wxFindWinFromHandle(HWND hwnd)
3660 {
3661 WindowHandles::const_iterator i = gs_windowHandles.find(hwnd);
3662 return i == gs_windowHandles.end() ? NULL : i->second;
3663 }
3664
3665 void wxAssociateWinWithHandle(HWND hwnd, wxWindowMSW *win)
3666 {
3667 // adding NULL hwnd is (first) surely a result of an error and
3668 // (secondly) breaks menu command processing
3669 wxCHECK_RET( hwnd != (HWND)NULL,
3670 wxT("attempt to add a NULL hwnd to window list ignored") );
3671
3672 #if wxDEBUG_LEVEL
3673 WindowHandles::const_iterator i = gs_windowHandles.find(hwnd);
3674 if ( i != gs_windowHandles.end() )
3675 {
3676 if ( i->second != win )
3677 {
3678 wxFAIL_MSG(
3679 wxString::Format(
3680 wxT("HWND %p already associated with another window (%s)"),
3681 hwnd, win->GetClassInfo()->GetClassName()
3682 )
3683 );
3684 }
3685 //else: this actually happens currently because we associate the window
3686 // with its HWND during creation (if we create it) and also when
3687 // SubclassWin() is called later, this is ok
3688 }
3689 #endif // wxDEBUG_LEVEL
3690
3691 gs_windowHandles[hwnd] = (wxWindow *)win;
3692 }
3693
3694 void wxRemoveHandleAssociation(wxWindowMSW *win)
3695 {
3696 gs_windowHandles.erase(GetHwndOf(win));
3697 }
3698
3699 // ----------------------------------------------------------------------------
3700 // various MSW speciic class dependent functions
3701 // ----------------------------------------------------------------------------
3702
3703 // Default destroyer - override if you destroy it in some other way
3704 // (e.g. with MDI child windows)
3705 void wxWindowMSW::MSWDestroyWindow()
3706 {
3707 }
3708
3709 void wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos,
3710 const wxSize& size,
3711 int& x, int& y,
3712 int& w, int& h) const
3713 {
3714 // CW_USEDEFAULT can't be used for child windows so just position them at
3715 // the origin by default
3716 x = pos.x == wxDefaultCoord ? 0 : pos.x;
3717 y = pos.y == wxDefaultCoord ? 0 : pos.y;
3718
3719 AdjustForParentClientOrigin(x, y);
3720
3721 // We don't have any clearly good choice for the size by default neither
3722 // but we must use something non-zero.
3723 w = WidthDefault(size.x);
3724 h = HeightDefault(size.y);
3725
3726 /*
3727 NB: there used to be some code here which set the initial size of the
3728 window to the client size of the parent if no explicit size was
3729 specified. This was wrong because wxWidgets programs often assume
3730 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3731 it. To see why, you should understand that Windows sends WM_SIZE from
3732 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3733 from some base class ctor and so this WM_SIZE is not processed in the
3734 real class' OnSize() (because it's not fully constructed yet and the
3735 event goes to some base class OnSize() instead). So the WM_SIZE we
3736 rely on is the one sent when the parent frame resizes its children
3737 but here is the problem: if the child already has just the right
3738 size, nothing will happen as both wxWidgets and Windows check for
3739 this and ignore any attempts to change the window size to the size it
3740 already has - so no WM_SIZE would be sent.
3741 */
3742 }
3743
3744 WXHWND wxWindowMSW::MSWGetParent() const
3745 {
3746 return m_parent ? m_parent->GetHWND() : WXHWND(NULL);
3747 }
3748
3749 bool wxWindowMSW::MSWCreate(const wxChar *wclass,
3750 const wxChar *title,
3751 const wxPoint& pos,
3752 const wxSize& size,
3753 WXDWORD style,
3754 WXDWORD extendedStyle)
3755 {
3756 // check a common bug in the user code: if the window is created with a
3757 // non-default ctor and Create() is called too, we'd create 2 HWND for a
3758 // single wxWindow object and this results in all sorts of trouble,
3759 // especially for wxTLWs
3760 wxCHECK_MSG( !m_hWnd, true, "window can't be recreated" );
3761
3762 // this can happen if this function is called using the return value of
3763 // wxApp::GetRegisteredClassName() which failed
3764 wxCHECK_MSG( wclass, false, "failed to register window class?" );
3765
3766
3767 // choose the position/size for the new window
3768 int x, y, w, h;
3769 (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h);
3770
3771 // controlId is menu handle for the top level windows, so set it to 0
3772 // unless we're creating a child window
3773 int controlId = style & WS_CHILD ? GetId() : 0;
3774
3775 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3776 // which is the same but without CS_[HV]REDRAW class styles so using it
3777 // ensures that the window is not fully repainted on each resize
3778 wxString className(wclass);
3779 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) )
3780 {
3781 className += wxApp::GetNoRedrawClassSuffix();
3782 }
3783
3784 // do create the window
3785 wxWindowCreationHook hook(this);
3786
3787 m_hWnd = (WXHWND)::CreateWindowEx
3788 (
3789 extendedStyle,
3790 className.wx_str(),
3791 title ? title : m_windowName.wx_str(),
3792 style,
3793 x, y, w, h,
3794 (HWND)MSWGetParent(),
3795 (HMENU)wxUIntToPtr(controlId),
3796 wxGetInstance(),
3797 NULL // no extra data
3798 );
3799
3800 if ( !m_hWnd )
3801 {
3802 wxLogSysError(_("Can't create window of class %s"), className.c_str());
3803
3804 return false;
3805 }
3806
3807 SubclassWin(m_hWnd);
3808
3809 return true;
3810 }
3811
3812 // ===========================================================================
3813 // MSW message handlers
3814 // ===========================================================================
3815
3816 // ---------------------------------------------------------------------------
3817 // WM_NOTIFY
3818 // ---------------------------------------------------------------------------
3819
3820 bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
3821 {
3822 #ifndef __WXMICROWIN__
3823 LPNMHDR hdr = (LPNMHDR)lParam;
3824 HWND hWnd = hdr->hwndFrom;
3825 wxWindow *win = wxFindWinFromHandle(hWnd);
3826
3827 // if the control is one of our windows, let it handle the message itself
3828 if ( win )
3829 {
3830 return win->MSWOnNotify(idCtrl, lParam, result);
3831 }
3832
3833 // VZ: why did we do it? normally this is unnecessary and, besides, it
3834 // breaks the message processing for the toolbars because the tooltip
3835 // notifications were being forwarded to the toolbar child controls
3836 // (if it had any) before being passed to the toolbar itself, so in my
3837 // example the tooltip for the combobox was always shown instead of the
3838 // correct button tooltips
3839 #if 0
3840 // try all our children
3841 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
3842 while ( node )
3843 {
3844 wxWindow *child = node->GetData();
3845 if ( child->MSWOnNotify(idCtrl, lParam, result) )
3846 {
3847 return true;
3848 }
3849
3850 node = node->GetNext();
3851 }
3852 #endif // 0
3853
3854 // by default, handle it ourselves
3855 return MSWOnNotify(idCtrl, lParam, result);
3856 #else // __WXMICROWIN__
3857 return false;
3858 #endif
3859 }
3860
3861 #if wxUSE_TOOLTIPS
3862
3863 bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
3864 WXLPARAM lParam,
3865 const wxString& ttip)
3866 {
3867 // I don't know why it happens, but the versions of comctl32.dll starting
3868 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3869 // this message is supposed to be sent to Unicode programs only) -- hence
3870 // we need to handle it as well, otherwise no tooltips will be shown in
3871 // this case
3872 #ifndef __WXWINCE__
3873 if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW)
3874 || ttip.empty() )
3875 {
3876 // not a tooltip message or no tooltip to show anyhow
3877 return false;
3878 }
3879 #endif
3880
3881 LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
3882
3883 // We don't want to use the szText buffer because it has a limit of 80
3884 // bytes and this is not enough, especially for Unicode build where it
3885 // limits the tooltip string length to only 40 characters
3886 //
3887 // The best would be, of course, to not impose any length limitations at
3888 // all but then the buffer would have to be dynamic and someone would have
3889 // to free it and we don't have the tooltip owner object here any more, so
3890 // for now use our own static buffer with a higher fixed max length.
3891 //
3892 // Note that using a static buffer should not be a problem as only a single
3893 // tooltip can be shown at the same time anyhow.
3894 #if !wxUSE_UNICODE
3895 if ( code == (WXUINT) TTN_NEEDTEXTW )
3896 {
3897 // We need to convert tooltip from multi byte to Unicode on the fly.
3898 static wchar_t buf[513];
3899
3900 // Truncate tooltip length if needed as otherwise we might not have
3901 // enough space for it in the buffer and MultiByteToWideChar() would
3902 // return an error
3903 size_t tipLength = wxMin(ttip.length(), WXSIZEOF(buf) - 1);
3904
3905 // Convert to WideChar without adding the NULL character. The NULL
3906 // character is added afterwards (this is more efficient).
3907 int len = ::MultiByteToWideChar
3908 (
3909 CP_ACP,
3910 0, // no flags
3911 ttip.wx_str(),
3912 tipLength,
3913 buf,
3914 WXSIZEOF(buf) - 1
3915 );
3916
3917 if ( !len )
3918 {
3919 wxLogLastError(wxT("MultiByteToWideChar()"));
3920 }
3921
3922 buf[len] = L'\0';
3923 ttText->lpszText = (LPSTR) buf;
3924 }
3925 else // TTN_NEEDTEXTA
3926 #endif // !wxUSE_UNICODE
3927 {
3928 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3929 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3930 // to copy the string we have into the buffer
3931 static wxChar buf[513];
3932 wxStrlcpy(buf, ttip.c_str(), WXSIZEOF(buf));
3933 ttText->lpszText = buf;
3934 }
3935
3936 return true;
3937 }
3938
3939 #endif // wxUSE_TOOLTIPS
3940
3941 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl),
3942 WXLPARAM lParam,
3943 WXLPARAM* WXUNUSED(result))
3944 {
3945 #if wxUSE_TOOLTIPS
3946 if ( m_tooltip )
3947 {
3948 NMHDR* hdr = (NMHDR *)lParam;
3949 if ( HandleTooltipNotify(hdr->code, lParam, m_tooltip->GetTip()))
3950 {
3951 // processed
3952 return true;
3953 }
3954 }
3955 #else
3956 wxUnusedVar(lParam);
3957 #endif // wxUSE_TOOLTIPS
3958
3959 return false;
3960 }
3961
3962 // ---------------------------------------------------------------------------
3963 // end session messages
3964 // ---------------------------------------------------------------------------
3965
3966 bool wxWindowMSW::HandleQueryEndSession(long logOff, bool *mayEnd)
3967 {
3968 #ifdef ENDSESSION_LOGOFF
3969 wxCloseEvent event(wxEVT_QUERY_END_SESSION, wxID_ANY);
3970 event.SetEventObject(wxTheApp);
3971 event.SetCanVeto(true);
3972 event.SetLoggingOff(logOff == (long)ENDSESSION_LOGOFF);
3973
3974 bool rc = wxTheApp->ProcessEvent(event);
3975
3976 if ( rc )
3977 {
3978 // we may end only if the app didn't veto session closing (double
3979 // negation...)
3980 *mayEnd = !event.GetVeto();
3981 }
3982
3983 return rc;
3984 #else
3985 wxUnusedVar(logOff);
3986 wxUnusedVar(mayEnd);
3987 return false;
3988 #endif
3989 }
3990
3991 bool wxWindowMSW::HandleEndSession(bool endSession, long logOff)
3992 {
3993 #ifdef ENDSESSION_LOGOFF
3994 // do nothing if the session isn't ending
3995 if ( !endSession )
3996 return false;
3997
3998 // only send once
3999 if ( (this != wxTheApp->GetTopWindow()) )
4000 return false;
4001
4002 wxCloseEvent event(wxEVT_END_SESSION, wxID_ANY);
4003 event.SetEventObject(wxTheApp);
4004 event.SetCanVeto(false);
4005 event.SetLoggingOff((logOff & ENDSESSION_LOGOFF) != 0);
4006
4007 return wxTheApp->ProcessEvent(event);
4008 #else
4009 wxUnusedVar(endSession);
4010 wxUnusedVar(logOff);
4011 return false;
4012 #endif
4013 }
4014
4015 // ---------------------------------------------------------------------------
4016 // window creation/destruction
4017 // ---------------------------------------------------------------------------
4018
4019 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT WXUNUSED_IN_WINCE(cs),
4020 bool *mayCreate)
4021 {
4022 // VZ: why is this commented out for WinCE? If it doesn't support
4023 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
4024 // not with multiple #ifdef's!
4025 #ifndef __WXWINCE__
4026 if ( ((CREATESTRUCT *)cs)->dwExStyle & WS_EX_CONTROLPARENT )
4027 EnsureParentHasControlParentStyle(GetParent());
4028 #endif // !__WXWINCE__
4029
4030 *mayCreate = true;
4031
4032 return true;
4033 }
4034
4035 bool wxWindowMSW::HandleDestroy()
4036 {
4037 // delete our drop target if we've got one
4038 #if wxUSE_DRAG_AND_DROP
4039 if ( m_dropTarget != NULL )
4040 {
4041 m_dropTarget->Revoke(m_hWnd);
4042
4043 wxDELETE(m_dropTarget);
4044 }
4045 #endif // wxUSE_DRAG_AND_DROP
4046
4047 // WM_DESTROY handled
4048 return true;
4049 }
4050
4051 // ---------------------------------------------------------------------------
4052 // activation/focus
4053 // ---------------------------------------------------------------------------
4054
4055 bool wxWindowMSW::HandleActivate(int state,
4056 bool WXUNUSED(minimized),
4057 WXHWND WXUNUSED(activate))
4058 {
4059 wxActivateEvent event(wxEVT_ACTIVATE,
4060 (state == WA_ACTIVE) || (state == WA_CLICKACTIVE),
4061 m_windowId);
4062 event.SetEventObject(this);
4063
4064 return HandleWindowEvent(event);
4065 }
4066
4067 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd)
4068 {
4069 // Strangly enough, some controls get set focus events when they are being
4070 // deleted, even if they already had focus before.
4071 if ( m_isBeingDeleted )
4072 {
4073 return false;
4074 }
4075
4076 // notify the parent keeping track of focus for the kbd navigation
4077 // purposes that we got it
4078 wxChildFocusEvent eventFocus((wxWindow *)this);
4079 (void)HandleWindowEvent(eventFocus);
4080
4081 #if wxUSE_CARET
4082 // Deal with caret
4083 if ( m_caret )
4084 {
4085 m_caret->OnSetFocus();
4086 }
4087 #endif // wxUSE_CARET
4088
4089 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
4090 event.SetEventObject(this);
4091
4092 // wxFindWinFromHandle() may return NULL, it is ok
4093 event.SetWindow(wxFindWinFromHandle(hwnd));
4094
4095 return HandleWindowEvent(event);
4096 }
4097
4098 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd)
4099 {
4100 #if wxUSE_CARET
4101 // Deal with caret
4102 if ( m_caret )
4103 {
4104 m_caret->OnKillFocus();
4105 }
4106 #endif // wxUSE_CARET
4107
4108 // Don't send the event when in the process of being deleted. This can
4109 // only cause problems if the event handler tries to access the object.
4110 if ( m_isBeingDeleted )
4111 {
4112 return false;
4113 }
4114
4115 wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId);
4116 event.SetEventObject(this);
4117
4118 // wxFindWinFromHandle() may return NULL, it is ok
4119 event.SetWindow(wxFindWinFromHandle(hwnd));
4120
4121 return HandleWindowEvent(event);
4122 }
4123
4124 // ---------------------------------------------------------------------------
4125 // labels
4126 // ---------------------------------------------------------------------------
4127
4128 void wxWindowMSW::SetLabel( const wxString& label)
4129 {
4130 SetWindowText(GetHwnd(), label.c_str());
4131 }
4132
4133 wxString wxWindowMSW::GetLabel() const
4134 {
4135 return wxGetWindowText(GetHWND());
4136 }
4137
4138 // ---------------------------------------------------------------------------
4139 // miscellaneous
4140 // ---------------------------------------------------------------------------
4141
4142 bool wxWindowMSW::HandleShow(bool show, int WXUNUSED(status))
4143 {
4144 wxShowEvent event(GetId(), show);
4145 event.SetEventObject(this);
4146
4147 return HandleWindowEvent(event);
4148 }
4149
4150 bool wxWindowMSW::HandleInitDialog(WXHWND WXUNUSED(hWndFocus))
4151 {
4152 wxInitDialogEvent event(GetId());
4153 event.SetEventObject(this);
4154
4155 return HandleWindowEvent(event);
4156 }
4157
4158 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam)
4159 {
4160 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
4161 wxUnusedVar(wParam);
4162 return false;
4163 #else // __WXMICROWIN__
4164 HDROP hFilesInfo = (HDROP) wParam;
4165
4166 // Get the total number of files dropped
4167 UINT gwFilesDropped = ::DragQueryFile
4168 (
4169 (HDROP)hFilesInfo,
4170 (UINT)-1,
4171 (LPTSTR)0,
4172 (UINT)0
4173 );
4174
4175 wxString *files = new wxString[gwFilesDropped];
4176 for ( UINT wIndex = 0; wIndex < gwFilesDropped; wIndex++ )
4177 {
4178 // first get the needed buffer length (+1 for terminating NUL)
4179 size_t len = ::DragQueryFile(hFilesInfo, wIndex, NULL, 0) + 1;
4180
4181 // and now get the file name
4182 ::DragQueryFile(hFilesInfo, wIndex,
4183 wxStringBuffer(files[wIndex], len), len);
4184 }
4185
4186 wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files);
4187 event.SetEventObject(this);
4188
4189 POINT dropPoint;
4190 DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
4191 event.m_pos.x = dropPoint.x;
4192 event.m_pos.y = dropPoint.y;
4193
4194 DragFinish(hFilesInfo);
4195
4196 return HandleWindowEvent(event);
4197 #endif
4198 }
4199
4200
4201 bool wxWindowMSW::HandleSetCursor(WXHWND WXUNUSED(hWnd),
4202 short nHitTest,
4203 int WXUNUSED(mouseMsg))
4204 {
4205 #ifndef __WXMICROWIN__
4206 // the logic is as follows:
4207 // 0. if we're busy, set the busy cursor (even for non client elements)
4208 // 1. don't set custom cursor for non client area of enabled windows
4209 // 2. ask user EVT_SET_CURSOR handler for the cursor
4210 // 3. if still no cursor but we're in a TLW, set the global cursor
4211
4212 HCURSOR hcursor = 0;
4213 if ( wxIsBusy() )
4214 {
4215 hcursor = wxGetCurrentBusyCursor();
4216 }
4217 else // not busy
4218 {
4219 if ( nHitTest != HTCLIENT )
4220 return false;
4221
4222 // first ask the user code - it may wish to set the cursor in some very
4223 // specific way (for example, depending on the current position)
4224 POINT pt;
4225 #ifdef __WXWINCE__
4226 if ( !::GetCursorPosWinCE(&pt))
4227 #else
4228 if ( !::GetCursorPos(&pt) )
4229 #endif
4230 {
4231 wxLogLastError(wxT("GetCursorPos"));
4232 }
4233
4234 int x = pt.x,
4235 y = pt.y;
4236 ScreenToClient(&x, &y);
4237 wxSetCursorEvent event(x, y);
4238 event.SetId(GetId());
4239 event.SetEventObject(this);
4240
4241 bool processedEvtSetCursor = HandleWindowEvent(event);
4242 if ( processedEvtSetCursor && event.HasCursor() )
4243 {
4244 hcursor = GetHcursorOf(event.GetCursor());
4245 }
4246
4247 if ( !hcursor )
4248 {
4249 // the test for processedEvtSetCursor is here to prevent using
4250 // m_cursor if the user code caught EVT_SET_CURSOR() and returned
4251 // nothing from it - this is a way to say that our cursor shouldn't
4252 // be used for this point
4253 if ( !processedEvtSetCursor && m_cursor.Ok() )
4254 {
4255 hcursor = GetHcursorOf(m_cursor);
4256 }
4257
4258 if ( !hcursor && !GetParent() )
4259 {
4260 const wxCursor *cursor = wxGetGlobalCursor();
4261 if ( cursor && cursor->Ok() )
4262 {
4263 hcursor = GetHcursorOf(*cursor);
4264 }
4265 }
4266 }
4267 }
4268
4269
4270 if ( hcursor )
4271 {
4272 ::SetCursor(hcursor);
4273
4274 // cursor set, stop here
4275 return true;
4276 }
4277 #endif // __WXMICROWIN__
4278
4279 // pass up the window chain
4280 return false;
4281 }
4282
4283 bool wxWindowMSW::HandlePower(WXWPARAM WXUNUSED_IN_WINCE(wParam),
4284 WXLPARAM WXUNUSED(lParam),
4285 bool *WXUNUSED_IN_WINCE(vetoed))
4286 {
4287 #ifdef __WXWINCE__
4288 // FIXME
4289 return false;
4290 #else
4291 wxEventType evtType;
4292 switch ( wParam )
4293 {
4294 case PBT_APMQUERYSUSPEND:
4295 evtType = wxEVT_POWER_SUSPENDING;
4296 break;
4297
4298 case PBT_APMQUERYSUSPENDFAILED:
4299 evtType = wxEVT_POWER_SUSPEND_CANCEL;
4300 break;
4301
4302 case PBT_APMSUSPEND:
4303 evtType = wxEVT_POWER_SUSPENDED;
4304 break;
4305
4306 case PBT_APMRESUMESUSPEND:
4307 evtType = wxEVT_POWER_RESUME;
4308 break;
4309
4310 default:
4311 wxLogDebug(wxT("Unknown WM_POWERBROADCAST(%d) event"), wParam);
4312 // fall through
4313
4314 // these messages are currently not mapped to wx events
4315 case PBT_APMQUERYSTANDBY:
4316 case PBT_APMQUERYSTANDBYFAILED:
4317 case PBT_APMSTANDBY:
4318 case PBT_APMRESUMESTANDBY:
4319 case PBT_APMBATTERYLOW:
4320 case PBT_APMPOWERSTATUSCHANGE:
4321 case PBT_APMOEMEVENT:
4322 case PBT_APMRESUMECRITICAL:
4323 #ifdef PBT_APMRESUMEAUTOMATIC
4324 case PBT_APMRESUMEAUTOMATIC:
4325 #endif
4326 evtType = wxEVT_NULL;
4327 break;
4328 }
4329
4330 // don't handle unknown messages
4331 if ( evtType == wxEVT_NULL )
4332 return false;
4333
4334 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
4335
4336 wxPowerEvent event(evtType);
4337 if ( !HandleWindowEvent(event) )
4338 return false;
4339
4340 *vetoed = event.IsVetoed();
4341
4342 return true;
4343 #endif
4344 }
4345
4346 bool wxWindowMSW::IsDoubleBuffered() const
4347 {
4348 for ( const wxWindowMSW *win = this; win; win = win->GetParent() )
4349 {
4350 if ( wxHasWindowExStyle(win, WS_EX_COMPOSITED) )
4351 return true;
4352
4353 if ( win->IsTopLevel() )
4354 break;
4355 }
4356
4357 return false;
4358 }
4359
4360 void wxWindowMSW::SetDoubleBuffered(bool on)
4361 {
4362 // Get the current extended style bits
4363 long exstyle = wxGetWindowExStyle(this);
4364
4365 // Twiddle the bit as needed
4366 if ( on )
4367 exstyle |= WS_EX_COMPOSITED;
4368 else
4369 exstyle &= ~WS_EX_COMPOSITED;
4370
4371 // put it back
4372 wxSetWindowExStyle(this, exstyle);
4373 }
4374
4375 // ---------------------------------------------------------------------------
4376 // owner drawn stuff
4377 // ---------------------------------------------------------------------------
4378
4379 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
4380 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
4381 #define WXUNUSED_UNLESS_ODRAWN(param) param
4382 #else
4383 #define WXUNUSED_UNLESS_ODRAWN(param)
4384 #endif
4385
4386 bool
4387 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id),
4388 WXDRAWITEMSTRUCT * WXUNUSED_UNLESS_ODRAWN(itemStruct))
4389 {
4390 #if wxUSE_OWNER_DRAWN
4391
4392 #if wxUSE_MENUS_NATIVE
4393 // is it a menu item?
4394 DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
4395 if ( id == 0 && pDrawStruct->CtlType == ODT_MENU )
4396 {
4397 wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData);
4398
4399 // see comment before the same test in MSWOnMeasureItem() below
4400 if ( !pMenuItem )
4401 return false;
4402
4403 wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem),
4404 false, wxT("MSWOnDrawItem: bad wxMenuItem pointer") );
4405
4406 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4407 // the DC from being released
4408 wxDCTemp dc((WXHDC)pDrawStruct->hDC);
4409 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
4410 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
4411 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
4412
4413 return pMenuItem->OnDrawItem
4414 (
4415 dc,
4416 rect,
4417 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
4418 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
4419 );
4420 }
4421 #endif // wxUSE_MENUS_NATIVE
4422
4423 #endif // USE_OWNER_DRAWN
4424
4425 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4426
4427 #if wxUSE_OWNER_DRAWN
4428 wxControl *item = wxDynamicCast(FindItem(id), wxControl);
4429 #else // !wxUSE_OWNER_DRAWN
4430 // we may still have owner-drawn buttons internally because we have to make
4431 // them owner-drawn to support colour change
4432 wxControl *item =
4433 # if wxUSE_BUTTON
4434 wxDynamicCast(FindItem(id), wxButton)
4435 # else
4436 NULL
4437 # endif
4438 ;
4439 #endif // USE_OWNER_DRAWN
4440
4441 if ( item )
4442 {
4443 return item->MSWOnDraw(itemStruct);
4444 }
4445
4446 #endif // wxUSE_CONTROLS
4447
4448 return false;
4449 }
4450
4451 bool
4452 wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
4453 {
4454 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4455 // is it a menu item?
4456 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
4457 if ( id == 0 && pMeasureStruct->CtlType == ODT_MENU )
4458 {
4459 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
4460
4461 // according to Carsten Fuchs the pointer may be NULL under XP if an
4462 // MDI child frame is initially maximized, see this for more info:
4463 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4464 //
4465 // so silently ignore it instead of asserting
4466 if ( !pMenuItem )
4467 return false;
4468
4469 wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem),
4470 false, wxT("MSWOnMeasureItem: bad wxMenuItem pointer") );
4471
4472 size_t w, h;
4473 bool rc = pMenuItem->OnMeasureItem(&w, &h);
4474
4475 pMeasureStruct->itemWidth = w;
4476 pMeasureStruct->itemHeight = h;
4477
4478 return rc;
4479 }
4480
4481 wxControl *item = wxDynamicCast(FindItem(id), wxControl);
4482 if ( item )
4483 {
4484 return item->MSWOnMeasure(itemStruct);
4485 }
4486 #else
4487 wxUnusedVar(id);
4488 wxUnusedVar(itemStruct);
4489 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4490
4491 return false;
4492 }
4493
4494 // ---------------------------------------------------------------------------
4495 // colours and palettes
4496 // ---------------------------------------------------------------------------
4497
4498 bool wxWindowMSW::HandleSysColorChange()
4499 {
4500 wxSysColourChangedEvent event;
4501 event.SetEventObject(this);
4502
4503 (void)HandleWindowEvent(event);
4504
4505 // always let the system carry on the default processing to allow the
4506 // native controls to react to the colours update
4507 return false;
4508 }
4509
4510 bool wxWindowMSW::HandleDisplayChange()
4511 {
4512 wxDisplayChangedEvent event;
4513 event.SetEventObject(this);
4514
4515 return HandleWindowEvent(event);
4516 }
4517
4518 #ifndef __WXMICROWIN__
4519
4520 bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush, WXHDC hDC, WXHWND hWnd)
4521 {
4522 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4523 wxUnusedVar(hDC);
4524 wxUnusedVar(hWnd);
4525 #else
4526 wxControl *item = wxDynamicCast(FindItemByHWND(hWnd, true), wxControl);
4527
4528 if ( item )
4529 *brush = item->MSWControlColor(hDC, hWnd);
4530 else
4531 #endif // wxUSE_CONTROLS
4532 *brush = NULL;
4533
4534 return *brush != NULL;
4535 }
4536
4537 #endif // __WXMICROWIN__
4538
4539 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange)
4540 {
4541 #if wxUSE_PALETTE
4542 // same as below except we don't respond to our own messages
4543 if ( hWndPalChange != GetHWND() )
4544 {
4545 // check to see if we our our parents have a custom palette
4546 wxWindowMSW *win = this;
4547 while ( win && !win->HasCustomPalette() )
4548 {
4549 win = win->GetParent();
4550 }
4551
4552 if ( win && win->HasCustomPalette() )
4553 {
4554 // realize the palette to see whether redrawing is needed
4555 HDC hdc = ::GetDC((HWND) hWndPalChange);
4556 win->m_palette.SetHPALETTE((WXHPALETTE)
4557 ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
4558
4559 int result = ::RealizePalette(hdc);
4560
4561 // restore the palette (before releasing the DC)
4562 win->m_palette.SetHPALETTE((WXHPALETTE)
4563 ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
4564 ::RealizePalette(hdc);
4565 ::ReleaseDC((HWND) hWndPalChange, hdc);
4566
4567 // now check for the need to redraw
4568 if (result > 0)
4569 ::InvalidateRect((HWND) hWndPalChange, NULL, TRUE);
4570 }
4571
4572 }
4573 #endif // wxUSE_PALETTE
4574
4575 wxPaletteChangedEvent event(GetId());
4576 event.SetEventObject(this);
4577 event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
4578
4579 return HandleWindowEvent(event);
4580 }
4581
4582 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture)
4583 {
4584 // notify windows on the capture stack about lost capture
4585 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4586 wxWindowBase::NotifyCaptureLost();
4587
4588 wxWindow *win = wxFindWinFromHandle(hWndGainedCapture);
4589 wxMouseCaptureChangedEvent event(GetId(), win);
4590 event.SetEventObject(this);
4591 return HandleWindowEvent(event);
4592 }
4593
4594 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam)
4595 {
4596 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4597 // we need to send this to child windows (it is only sent to top-level
4598 // windows) so {list,tree}ctrls can adjust their font size if necessary
4599 // this is exactly how explorer does it to enable the font size changes
4600
4601 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
4602 while ( node )
4603 {
4604 // top-level windows already get this message from the system
4605 wxWindow *win = node->GetData();
4606 if ( !win->IsTopLevel() )
4607 {
4608 ::SendMessage(GetHwndOf(win), WM_SETTINGCHANGE, wParam, lParam);
4609 }
4610
4611 node = node->GetNext();
4612 }
4613
4614 // let the system handle it
4615 return false;
4616 }
4617
4618 bool wxWindowMSW::HandleQueryNewPalette()
4619 {
4620
4621 #if wxUSE_PALETTE
4622 // check to see if we our our parents have a custom palette
4623 wxWindowMSW *win = this;
4624 while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent();
4625 if (win->HasCustomPalette()) {
4626 /* realize the palette to see whether redrawing is needed */
4627 HDC hdc = ::GetDC((HWND) GetHWND());
4628 win->m_palette.SetHPALETTE( (WXHPALETTE)
4629 ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), FALSE) );
4630
4631 int result = ::RealizePalette(hdc);
4632 /* restore the palette (before releasing the DC) */
4633 win->m_palette.SetHPALETTE( (WXHPALETTE)
4634 ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), TRUE) );
4635 ::RealizePalette(hdc);
4636 ::ReleaseDC((HWND) GetHWND(), hdc);
4637 /* now check for the need to redraw */
4638 if (result > 0)
4639 ::InvalidateRect((HWND) GetHWND(), NULL, TRUE);
4640 }
4641 #endif // wxUSE_PALETTE
4642
4643 wxQueryNewPaletteEvent event(GetId());
4644 event.SetEventObject(this);
4645
4646 return HandleWindowEvent(event) && event.GetPaletteRealized();
4647 }
4648
4649 // Responds to colour changes: passes event on to children.
4650 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
4651 {
4652 // the top level window also reset the standard colour map as it might have
4653 // changed (there is no need to do it for the non top level windows as we
4654 // only have to do it once)
4655 if ( IsTopLevel() )
4656 {
4657 // FIXME-MT
4658 gs_hasStdCmap = false;
4659 }
4660 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
4661 while ( node )
4662 {
4663 // Only propagate to non-top-level windows because Windows already
4664 // sends this event to all top-level ones
4665 wxWindow *win = node->GetData();
4666 if ( !win->IsTopLevel() )
4667 {
4668 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4669 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4670 // the standard controls
4671 ::SendMessage(GetHwndOf(win), WM_SYSCOLORCHANGE, 0, 0);
4672 }
4673
4674 node = node->GetNext();
4675 }
4676 }
4677
4678 extern wxCOLORMAP *wxGetStdColourMap()
4679 {
4680 static COLORREF s_stdColours[wxSTD_COL_MAX];
4681 static wxCOLORMAP s_cmap[wxSTD_COL_MAX];
4682
4683 if ( !gs_hasStdCmap )
4684 {
4685 static bool s_coloursInit = false;
4686
4687 if ( !s_coloursInit )
4688 {
4689 // When a bitmap is loaded, the RGB values can change (apparently
4690 // because Windows adjusts them to care for the old programs always
4691 // using 0xc0c0c0 while the transparent colour for the new Windows
4692 // versions is different). But we do this adjustment ourselves so
4693 // we want to avoid Windows' "help" and for this we need to have a
4694 // reference bitmap which can tell us what the RGB values change
4695 // to.
4696 wxLogNull logNo; // suppress error if we couldn't load the bitmap
4697 wxBitmap stdColourBitmap(wxT("wxBITMAP_STD_COLOURS"));
4698 if ( stdColourBitmap.Ok() )
4699 {
4700 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4701 wxASSERT_MSG( stdColourBitmap.GetWidth() == wxSTD_COL_MAX,
4702 wxT("forgot to update wxBITMAP_STD_COLOURS!") );
4703
4704 wxMemoryDC memDC;
4705 memDC.SelectObject(stdColourBitmap);
4706
4707 wxColour colour;
4708 for ( size_t i = 0; i < WXSIZEOF(s_stdColours); i++ )
4709 {
4710 memDC.GetPixel(i, 0, &colour);
4711 s_stdColours[i] = wxColourToRGB(colour);
4712 }
4713 }
4714 else // wxBITMAP_STD_COLOURS couldn't be loaded
4715 {
4716 s_stdColours[0] = RGB(000,000,000); // black
4717 s_stdColours[1] = RGB(128,128,128); // dark grey
4718 s_stdColours[2] = RGB(192,192,192); // light grey
4719 s_stdColours[3] = RGB(255,255,255); // white
4720 //s_stdColours[4] = RGB(000,000,255); // blue
4721 //s_stdColours[5] = RGB(255,000,255); // magenta
4722 }
4723
4724 s_coloursInit = true;
4725 }
4726
4727 gs_hasStdCmap = true;
4728
4729 // create the colour map
4730 #define INIT_CMAP_ENTRY(col) \
4731 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4732 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4733
4734 INIT_CMAP_ENTRY(BTNTEXT);
4735 INIT_CMAP_ENTRY(BTNSHADOW);
4736 INIT_CMAP_ENTRY(BTNFACE);
4737 INIT_CMAP_ENTRY(BTNHIGHLIGHT);
4738
4739 #undef INIT_CMAP_ENTRY
4740 }
4741
4742 return s_cmap;
4743 }
4744
4745 #if wxUSE_UXTHEME && !defined(TMT_FILLCOLOR)
4746 #define TMT_FILLCOLOR 3802
4747 #define TMT_TEXTCOLOR 3803
4748 #define TMT_BORDERCOLOR 3801
4749 #endif
4750
4751 wxColour wxWindowMSW::MSWGetThemeColour(const wchar_t *themeName,
4752 int themePart,
4753 int themeState,
4754 MSWThemeColour themeColour,
4755 wxSystemColour fallback) const
4756 {
4757 #if wxUSE_UXTHEME
4758 const wxUxThemeEngine* theme = wxUxThemeEngine::GetIfActive();
4759 if ( theme )
4760 {
4761 int themeProperty = 0;
4762
4763 // TODO: Convert this into a table? Sure would be faster.
4764 switch ( themeColour )
4765 {
4766 case ThemeColourBackground:
4767 themeProperty = TMT_FILLCOLOR;
4768 break;
4769 case ThemeColourText:
4770 themeProperty = TMT_TEXTCOLOR;
4771 break;
4772 case ThemeColourBorder:
4773 themeProperty = TMT_BORDERCOLOR;
4774 break;
4775 default:
4776 wxFAIL_MSG(wxT("unsupported theme colour"));
4777 };
4778
4779 wxUxThemeHandle hTheme((const wxWindow *)this, themeName);
4780 COLORREF col;
4781 HRESULT hr = theme->GetThemeColor
4782 (
4783 hTheme,
4784 themePart,
4785 themeState,
4786 themeProperty,
4787 &col
4788 );
4789
4790 if ( SUCCEEDED(hr) )
4791 return wxRGBToColour(col);
4792
4793 wxLogApiError(
4794 wxString::Format(
4795 "GetThemeColor(%s, %i, %i, %i)",
4796 themeName, themePart, themeState, themeProperty),
4797 hr);
4798 }
4799 #else
4800 wxUnusedVar(themeName);
4801 wxUnusedVar(themePart);
4802 wxUnusedVar(themeState);
4803 wxUnusedVar(themeColour);
4804 #endif
4805 return wxSystemSettings::GetColour(fallback);
4806 }
4807
4808 // ---------------------------------------------------------------------------
4809 // painting
4810 // ---------------------------------------------------------------------------
4811
4812 // this variable is used to check that a paint event handler which processed
4813 // the event did create a wxPaintDC inside its code and called BeginPaint() to
4814 // validate the invalidated window area as otherwise we'd keep getting an
4815 // endless stream of WM_PAINT messages for this window resulting in a lot of
4816 // difficult to debug problems (e.g. impossibility to repaint other windows,
4817 // lack of timer and idle events and so on)
4818 extern bool wxDidCreatePaintDC;
4819 bool wxDidCreatePaintDC = false;
4820
4821 bool wxWindowMSW::HandlePaint()
4822 {
4823 HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4824 if ( !hRegion )
4825 {
4826 wxLogLastError(wxT("CreateRectRgn"));
4827 }
4828 if ( ::GetUpdateRgn(GetHwnd(), hRegion, FALSE) == ERROR )
4829 {
4830 wxLogLastError(wxT("GetUpdateRgn"));
4831 }
4832
4833 m_updateRegion = wxRegion((WXHRGN) hRegion);
4834
4835 wxDidCreatePaintDC = false;
4836
4837 wxPaintEvent event(m_windowId);
4838 event.SetEventObject(this);
4839
4840 bool processed = HandleWindowEvent(event);
4841
4842 if ( processed && !wxDidCreatePaintDC )
4843 {
4844 // do call MSWDefWindowProc() to validate the update region to avoid
4845 // the problems mentioned above
4846 processed = false;
4847 }
4848
4849 // note that we must generate NC event after the normal one as otherwise
4850 // BeginPaint() will happily overwrite our decorations with the background
4851 // colour
4852 wxNcPaintEvent eventNc(m_windowId);
4853 eventNc.SetEventObject(this);
4854 HandleWindowEvent(eventNc);
4855
4856 // don't keep an HRGN we don't need any longer (GetUpdateRegion() can only
4857 // be called from inside the event handlers called above)
4858 m_updateRegion.Clear();
4859
4860 return processed;
4861 }
4862
4863 // Can be called from an application's OnPaint handler
4864 void wxWindowMSW::OnPaint(wxPaintEvent& event)
4865 {
4866 #ifdef __WXUNIVERSAL__
4867 event.Skip();
4868 #else
4869 HDC hDC = (HDC) wxPaintDCImpl::FindDCInCache((wxWindow*) event.GetEventObject());
4870 if (hDC != 0)
4871 {
4872 MSWDefWindowProc(WM_PAINT, (WPARAM) hDC, 0);
4873 }
4874 #endif
4875 }
4876
4877 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc)
4878 {
4879 switch ( GetBackgroundStyle() )
4880 {
4881 case wxBG_STYLE_ERASE:
4882 case wxBG_STYLE_COLOUR:
4883 // we need to generate an erase background event
4884 {
4885 wxDCTemp dc(hdc, GetClientSize());
4886 wxDCTempImpl *impl = (wxDCTempImpl*) dc.GetImpl();
4887
4888 impl->SetHDC(hdc);
4889 impl->SetWindow((wxWindow *)this);
4890
4891 wxEraseEvent event(m_windowId, &dc);
4892 event.SetEventObject(this);
4893 bool rc = HandleWindowEvent(event);
4894
4895 // must be called manually as ~wxDC doesn't do anything for
4896 // wxDCTemp
4897 impl->SelectOldObjects(hdc);
4898
4899 if ( rc )
4900 {
4901 // background erased by the user-defined handler
4902 return true;
4903 }
4904 }
4905 // fall through
4906
4907 case wxBG_STYLE_SYSTEM:
4908 if ( !DoEraseBackground(hdc) )
4909 {
4910 // let the default processing to take place if we didn't erase
4911 // the background ourselves
4912 return false;
4913 }
4914 break;
4915
4916 case wxBG_STYLE_PAINT:
4917 case wxBG_STYLE_TRANSPARENT:
4918 // no need to do anything here at all, background will be entirely
4919 // redrawn in WM_PAINT handler
4920 break;
4921
4922 default:
4923 wxFAIL_MSG( "unknown background style" );
4924 }
4925
4926 return true;
4927 }
4928
4929 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
4930
4931 bool wxWindowMSW::MSWHasEraseBgHook() const
4932 {
4933 return gs_eraseBgHooks.find(const_cast<wxWindowMSW *>(this))
4934 != gs_eraseBgHooks.end();
4935 }
4936
4937 void wxWindowMSW::MSWSetEraseBgHook(wxWindow *child)
4938 {
4939 if ( child )
4940 {
4941 if ( !gs_eraseBgHooks.insert(
4942 EraseBgHooks::value_type(this, child)).second )
4943 {
4944 wxFAIL_MSG( wxT("Setting erase background hook twice?") );
4945 }
4946 }
4947 else // reset the hook
4948 {
4949 if ( gs_eraseBgHooks.erase(this) != 1 )
4950 {
4951 wxFAIL_MSG( wxT("Resetting erase background which was not set?") );
4952 }
4953 }
4954 }
4955
4956 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
4957
4958 bool wxWindowMSW::DoEraseBackground(WXHDC hDC)
4959 {
4960 HBRUSH hbr = (HBRUSH)MSWGetBgBrush(hDC);
4961 if ( !hbr )
4962 return false;
4963
4964 // erase just the client area of the window, this is important for the
4965 // frames to avoid drawing over the toolbar part of the window (you might
4966 // think using WS_CLIPCHILDREN would prevent this from happening, but it
4967 // clearly doesn't)
4968 RECT rc;
4969 wxCopyRectToRECT(GetClientRect(), rc);
4970 ::FillRect((HDC)hDC, &rc, hbr);
4971
4972 return true;
4973 }
4974
4975 WXHBRUSH
4976 wxWindowMSW::MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC),
4977 wxWindowMSW * WXUNUSED(child))
4978 {
4979 if ( m_hasBgCol )
4980 {
4981 wxBrush *
4982 brush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour());
4983
4984 return (WXHBRUSH)GetHbrushOf(*brush);
4985 }
4986
4987 return 0;
4988 }
4989
4990 WXHBRUSH wxWindowMSW::MSWGetBgBrush(WXHDC hDC)
4991 {
4992 for ( wxWindowMSW *win = this; win; win = win->GetParent() )
4993 {
4994 WXHBRUSH hBrush = win->MSWGetBgBrushForChild(hDC, this);
4995 if ( hBrush )
4996 return hBrush;
4997
4998 // don't use the parent background if we're not transparent
4999 if ( !win->HasTransparentBackground() )
5000 break;
5001
5002 // background is not inherited beyond top level windows
5003 if ( win->IsTopLevel() )
5004 break;
5005 }
5006
5007 return 0;
5008 }
5009
5010 bool wxWindowMSW::HandlePrintClient(WXHDC hDC)
5011 {
5012 // we receive this message when DrawThemeParentBackground() is
5013 // called from def window proc of several controls under XP and we
5014 // must draw properly themed background here
5015 //
5016 // note that naively I'd expect filling the client rect with the
5017 // brush returned by MSWGetBgBrush() work -- but for some reason it
5018 // doesn't and we have to call parents MSWPrintChild() which is
5019 // supposed to call DrawThemeBackground() with appropriate params
5020 //
5021 // also note that in this case lParam == PRF_CLIENT but we're
5022 // clearly expected to paint the background and nothing else!
5023
5024 if ( IsTopLevel() || InheritsBackgroundColour() )
5025 return false;
5026
5027 // sometimes we don't want the parent to handle it at all, instead
5028 // return whatever value this window wants
5029 if ( !MSWShouldPropagatePrintChild() )
5030 return MSWPrintChild(hDC, (wxWindow *)this);
5031
5032 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
5033 {
5034 if ( win->MSWPrintChild(hDC, (wxWindow *)this) )
5035 return true;
5036
5037 if ( win->IsTopLevel() || win->InheritsBackgroundColour() )
5038 break;
5039 }
5040
5041 return false;
5042 }
5043
5044 // ---------------------------------------------------------------------------
5045 // moving and resizing
5046 // ---------------------------------------------------------------------------
5047
5048 bool wxWindowMSW::HandleMinimize()
5049 {
5050 wxIconizeEvent event(m_windowId);
5051 event.SetEventObject(this);
5052
5053 return HandleWindowEvent(event);
5054 }
5055
5056 bool wxWindowMSW::HandleMaximize()
5057 {
5058 wxMaximizeEvent event(m_windowId);
5059 event.SetEventObject(this);
5060
5061 return HandleWindowEvent(event);
5062 }
5063
5064 bool wxWindowMSW::HandleMove(int x, int y)
5065 {
5066 wxPoint point(x,y);
5067 wxMoveEvent event(point, m_windowId);
5068 event.SetEventObject(this);
5069
5070 return HandleWindowEvent(event);
5071 }
5072
5073 bool wxWindowMSW::HandleMoving(wxRect& rect)
5074 {
5075 wxMoveEvent event(rect, m_windowId);
5076 event.SetEventObject(this);
5077
5078 bool rc = HandleWindowEvent(event);
5079 if (rc)
5080 rect = event.GetRect();
5081 return rc;
5082 }
5083
5084 bool wxWindowMSW::HandleEnterSizeMove()
5085 {
5086 wxMoveEvent event(wxPoint(0,0), m_windowId);
5087 event.SetEventType(wxEVT_MOVE_START);
5088 event.SetEventObject(this);
5089
5090 return HandleWindowEvent(event);
5091 }
5092
5093 bool wxWindowMSW::HandleExitSizeMove()
5094 {
5095 wxMoveEvent event(wxPoint(0,0), m_windowId);
5096 event.SetEventType(wxEVT_MOVE_END);
5097 event.SetEventObject(this);
5098
5099 return HandleWindowEvent(event);
5100 }
5101
5102 bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam)
5103 {
5104 #if wxUSE_DEFERRED_SIZING
5105 // when we resize this window, its children are probably going to be
5106 // repositioned as well, prepare to use DeferWindowPos() for them
5107 int numChildren = 0;
5108 for ( HWND child = ::GetWindow(GetHwndOf(this), GW_CHILD);
5109 child;
5110 child = ::GetWindow(child, GW_HWNDNEXT) )
5111 {
5112 numChildren ++;
5113 }
5114
5115 // Protect against valid m_hDWP being overwritten
5116 bool useDefer = false;
5117
5118 if ( numChildren > 1 )
5119 {
5120 if (!m_hDWP)
5121 {
5122 m_hDWP = (WXHANDLE)::BeginDeferWindowPos(numChildren);
5123 if ( !m_hDWP )
5124 {
5125 wxLogLastError(wxT("BeginDeferWindowPos"));
5126 }
5127 if (m_hDWP)
5128 useDefer = true;
5129 }
5130 }
5131 #endif // wxUSE_DEFERRED_SIZING
5132
5133 // update this window size
5134 bool processed = false;
5135 switch ( wParam )
5136 {
5137 default:
5138 wxFAIL_MSG( wxT("unexpected WM_SIZE parameter") );
5139 // fall through nevertheless
5140
5141 case SIZE_MAXHIDE:
5142 case SIZE_MAXSHOW:
5143 // we're not interested in these messages at all
5144 break;
5145
5146 case SIZE_MINIMIZED:
5147 processed = HandleMinimize();
5148 break;
5149
5150 case SIZE_MAXIMIZED:
5151 /* processed = */ HandleMaximize();
5152 // fall through to send a normal size event as well
5153
5154 case SIZE_RESTORED:
5155 // don't use w and h parameters as they specify the client size
5156 // while according to the docs EVT_SIZE handler is supposed to
5157 // receive the total size
5158 wxSizeEvent event(GetSize(), m_windowId);
5159 event.SetEventObject(this);
5160
5161 processed = HandleWindowEvent(event);
5162 }
5163
5164 #if wxUSE_DEFERRED_SIZING
5165 // and finally change the positions of all child windows at once
5166 if ( useDefer && m_hDWP )
5167 {
5168 // reset m_hDWP to NULL so that child windows don't try to use our
5169 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
5170 // happen anyhow normally but who knows what weird flow of control we
5171 // may have depending on what the users EVT_SIZE handler does...)
5172 HDWP hDWP = (HDWP)m_hDWP;
5173 m_hDWP = NULL;
5174
5175 // do put all child controls in place at once
5176 if ( !::EndDeferWindowPos(hDWP) )
5177 {
5178 wxLogLastError(wxT("EndDeferWindowPos"));
5179 }
5180
5181 // Reset our children's pending pos/size values.
5182 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
5183 node;
5184 node = node->GetNext() )
5185 {
5186 wxWindowMSW * const child = node->GetData();
5187 child->MSWEndDeferWindowPos();
5188 }
5189 }
5190 #endif // wxUSE_DEFERRED_SIZING
5191
5192 return processed;
5193 }
5194
5195 bool wxWindowMSW::HandleSizing(wxRect& rect)
5196 {
5197 wxSizeEvent event(rect, m_windowId);
5198 event.SetEventObject(this);
5199
5200 bool rc = HandleWindowEvent(event);
5201 if (rc)
5202 rect = event.GetRect();
5203 return rc;
5204 }
5205
5206 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo))
5207 {
5208 #ifdef __WXWINCE__
5209 return false;
5210 #else
5211 MINMAXINFO *info = (MINMAXINFO *)mmInfo;
5212
5213 bool rc = false;
5214
5215 int minWidth = GetMinWidth(),
5216 minHeight = GetMinHeight(),
5217 maxWidth = GetMaxWidth(),
5218 maxHeight = GetMaxHeight();
5219
5220 if ( minWidth != wxDefaultCoord )
5221 {
5222 info->ptMinTrackSize.x = minWidth;
5223 rc = true;
5224 }
5225
5226 if ( minHeight != wxDefaultCoord )
5227 {
5228 info->ptMinTrackSize.y = minHeight;
5229 rc = true;
5230 }
5231
5232 if ( maxWidth != wxDefaultCoord )
5233 {
5234 info->ptMaxTrackSize.x = maxWidth;
5235 rc = true;
5236 }
5237
5238 if ( maxHeight != wxDefaultCoord )
5239 {
5240 info->ptMaxTrackSize.y = maxHeight;
5241 rc = true;
5242 }
5243
5244 return rc;
5245 #endif
5246 }
5247
5248 // ---------------------------------------------------------------------------
5249 // command messages
5250 // ---------------------------------------------------------------------------
5251
5252 bool wxWindowMSW::HandleCommand(WXWORD id_, WXWORD cmd, WXHWND control)
5253 {
5254 // sign extend to int from short before comparing with the other int ids
5255 int id = (signed short)id_;
5256
5257 #if wxUSE_MENUS_NATIVE
5258 if ( !cmd && wxCurrentPopupMenu )
5259 {
5260 wxMenu *popupMenu = wxCurrentPopupMenu;
5261 wxCurrentPopupMenu = NULL;
5262
5263 return popupMenu->MSWCommand(cmd, id);
5264 }
5265 #endif // wxUSE_MENUS_NATIVE
5266
5267 wxWindow *win = NULL;
5268
5269 // first try to find it from HWND - this works even with the broken
5270 // programs using the same ids for different controls
5271 if ( control )
5272 {
5273 win = wxFindWinFromHandle(control);
5274 }
5275
5276 // try the id
5277 if ( !win )
5278 {
5279 win = FindItem(id);
5280 }
5281
5282 if ( win )
5283 {
5284 return win->MSWCommand(cmd, id);
5285 }
5286
5287 // the messages sent from the in-place edit control used by the treectrl
5288 // for label editing have id == 0, but they should _not_ be treated as menu
5289 // messages (they are EN_XXX ones, in fact) so don't translate anything
5290 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
5291 if ( !control )
5292 {
5293 wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, id);
5294 event.SetEventObject(this);
5295 event.SetInt(id);
5296
5297 return HandleWindowEvent(event);
5298 }
5299 else
5300 {
5301 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5302 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
5303 // notifications to its parent which we want to reflect back to
5304 // wxSpinCtrl
5305 wxSpinCtrl *spin = wxSpinCtrl::GetSpinForTextCtrl(control);
5306 if ( spin && spin->ProcessTextCommand(cmd, id) )
5307 return true;
5308 #endif // wxUSE_SPINCTRL
5309
5310 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
5311 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
5312 // notifications to its parent which we want to reflect back to
5313 // wxChoice
5314 wxChoice *choice = wxChoice::GetChoiceForListBox(control);
5315 if ( choice && choice->MSWCommand(cmd, id) )
5316 return true;
5317 #endif
5318 }
5319
5320 return false;
5321 }
5322
5323 // ---------------------------------------------------------------------------
5324 // mouse events
5325 // ---------------------------------------------------------------------------
5326
5327 void wxWindowMSW::InitMouseEvent(wxMouseEvent& event,
5328 int x, int y,
5329 WXUINT flags)
5330 {
5331 // our client coords are not quite the same as Windows ones
5332 wxPoint pt = GetClientAreaOrigin();
5333 event.m_x = x - pt.x;
5334 event.m_y = y - pt.y;
5335
5336 event.m_shiftDown = (flags & MK_SHIFT) != 0;
5337 event.m_controlDown = (flags & MK_CONTROL) != 0;
5338 event.m_leftDown = (flags & MK_LBUTTON) != 0;
5339 event.m_middleDown = (flags & MK_MBUTTON) != 0;
5340 event.m_rightDown = (flags & MK_RBUTTON) != 0;
5341 #ifdef wxHAS_XBUTTON
5342 event.m_aux1Down = (flags & MK_XBUTTON1) != 0;
5343 event.m_aux2Down = (flags & MK_XBUTTON2) != 0;
5344 #endif // wxHAS_XBUTTON
5345 event.m_altDown = ::wxIsAltDown();
5346
5347 #ifndef __WXWINCE__
5348 event.SetTimestamp(::GetMessageTime());
5349 #endif
5350
5351 event.SetEventObject(this);
5352 event.SetId(GetId());
5353
5354 #if wxUSE_MOUSEEVENT_HACK
5355 gs_lastMouseEvent.pos = ClientToScreen(wxPoint(x, y));
5356 gs_lastMouseEvent.type = event.GetEventType();
5357 #endif // wxUSE_MOUSEEVENT_HACK
5358 }
5359
5360 #ifdef __WXWINCE__
5361 // Windows doesn't send the mouse events to the static controls (which are
5362 // transparent in the sense that their WM_NCHITTEST handler returns
5363 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
5364 // and so we manually check if we don't have a child window under mouse and if
5365 // we do, send the event to it instead of the window Windows had sent WM_XXX
5366 // to.
5367 //
5368 // Notice that this is not done for the mouse move events because this could
5369 // (would?) be too slow, but only for clicks which means that the static texts
5370 // still don't get move, enter nor leave events.
5371 static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y)
5372 {
5373 wxCHECK_MSG( x && y, win, wxT("NULL pointer in FindWindowForMouseEvent") );
5374
5375 // first try to find a non transparent child: this allows us to send events
5376 // to a static text which is inside a static box, for example
5377 POINT pt = { *x, *y };
5378 HWND hwnd = GetHwndOf(win),
5379 hwndUnderMouse;
5380
5381 #ifdef __WXWINCE__
5382 hwndUnderMouse = ::ChildWindowFromPoint
5383 (
5384 hwnd,
5385 pt
5386 );
5387 #else
5388 hwndUnderMouse = ::ChildWindowFromPointEx
5389 (
5390 hwnd,
5391 pt,
5392 CWP_SKIPINVISIBLE |
5393 CWP_SKIPDISABLED |
5394 CWP_SKIPTRANSPARENT
5395 );
5396 #endif
5397
5398 if ( !hwndUnderMouse || hwndUnderMouse == hwnd )
5399 {
5400 // now try any child window at all
5401 hwndUnderMouse = ::ChildWindowFromPoint(hwnd, pt);
5402 }
5403
5404 // check that we have a child window which is susceptible to receive mouse
5405 // events: for this it must be shown and enabled
5406 if ( hwndUnderMouse &&
5407 hwndUnderMouse != hwnd &&
5408 ::IsWindowVisible(hwndUnderMouse) &&
5409 ::IsWindowEnabled(hwndUnderMouse) )
5410 {
5411 wxWindow *winUnderMouse = wxFindWinFromHandle(hwndUnderMouse);
5412 if ( winUnderMouse )
5413 {
5414 // translate the mouse coords to the other window coords
5415 win->ClientToScreen(x, y);
5416 winUnderMouse->ScreenToClient(x, y);
5417
5418 win = winUnderMouse;
5419 }
5420 }
5421
5422 return win;
5423 }
5424 #endif // __WXWINCE__
5425
5426 bool wxWindowMSW::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags)
5427 {
5428 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
5429 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
5430 // from the message id and take the value in the table to get wxWin event
5431 // id
5432 static const wxEventType eventsMouse[] =
5433 {
5434 wxEVT_MOTION,
5435 wxEVT_LEFT_DOWN,
5436 wxEVT_LEFT_UP,
5437 wxEVT_LEFT_DCLICK,
5438 wxEVT_RIGHT_DOWN,
5439 wxEVT_RIGHT_UP,
5440 wxEVT_RIGHT_DCLICK,
5441 wxEVT_MIDDLE_DOWN,
5442 wxEVT_MIDDLE_UP,
5443 wxEVT_MIDDLE_DCLICK,
5444 0, // this one is for wxEVT_MOTION which is not used here
5445 wxEVT_AUX1_DOWN,
5446 wxEVT_AUX1_UP,
5447 wxEVT_AUX1_DCLICK,
5448 wxEVT_AUX2_DOWN,
5449 wxEVT_AUX2_UP,
5450 wxEVT_AUX2_DCLICK
5451 };
5452
5453 #ifdef wxHAS_XBUTTON
5454 // the same messages are used for both auxillary mouse buttons so we need
5455 // to adjust the index manually
5456 switch ( msg )
5457 {
5458 case WM_XBUTTONDOWN:
5459 case WM_XBUTTONUP:
5460 case WM_XBUTTONDBLCLK:
5461 if ( flags & MK_XBUTTON2 )
5462 msg += wxEVT_AUX2_DOWN - wxEVT_AUX1_DOWN;
5463 }
5464 #endif // wxHAS_XBUTTON
5465
5466 wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]);
5467 InitMouseEvent(event, x, y, flags);
5468
5469 return HandleWindowEvent(event);
5470 }
5471
5472 bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags)
5473 {
5474 if ( !m_mouseInWindow )
5475 {
5476 // it would be wrong to assume that just because we get a mouse move
5477 // event that the mouse is inside the window: although this is usually
5478 // true, it is not if we had captured the mouse, so we need to check
5479 // the mouse coordinates here
5480 if ( !HasCapture() || IsMouseInWindow() )
5481 {
5482 // Generate an ENTER event
5483 m_mouseInWindow = true;
5484
5485 #ifdef HAVE_TRACKMOUSEEVENT
5486 typedef BOOL (WINAPI *_TrackMouseEvent_t)(LPTRACKMOUSEEVENT);
5487 #ifdef __WXWINCE__
5488 static const _TrackMouseEvent_t
5489 s_pfn_TrackMouseEvent = _TrackMouseEvent;
5490 #else // !__WXWINCE__
5491 static _TrackMouseEvent_t s_pfn_TrackMouseEvent;
5492 static bool s_initDone = false;
5493 if ( !s_initDone )
5494 {
5495 // see comment in wxApp::GetComCtl32Version() explaining the
5496 // use of wxLoadedDLL
5497 wxLoadedDLL dllComCtl32(wxT("comctl32.dll"));
5498 if ( dllComCtl32.IsLoaded() )
5499 {
5500 s_pfn_TrackMouseEvent = (_TrackMouseEvent_t)
5501 dllComCtl32.RawGetSymbol(wxT("_TrackMouseEvent"));
5502 }
5503
5504 s_initDone = true;
5505 }
5506
5507 if ( s_pfn_TrackMouseEvent )
5508 #endif // __WXWINCE__/!__WXWINCE__
5509 {
5510 WinStruct<TRACKMOUSEEVENT> trackinfo;
5511
5512 trackinfo.dwFlags = TME_LEAVE;
5513 trackinfo.hwndTrack = GetHwnd();
5514
5515 (*s_pfn_TrackMouseEvent)(&trackinfo);
5516 }
5517 #endif // HAVE_TRACKMOUSEEVENT
5518
5519 wxMouseEvent event(wxEVT_ENTER_WINDOW);
5520 InitMouseEvent(event, x, y, flags);
5521
5522 (void)HandleWindowEvent(event);
5523 }
5524 }
5525 #ifdef HAVE_TRACKMOUSEEVENT
5526 else // mouse not in window
5527 {
5528 // Check if we need to send a LEAVE event
5529 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
5530 // send it here if we are using native mouse leave tracking
5531 if ( HasCapture() && !IsMouseInWindow() )
5532 {
5533 GenerateMouseLeave();
5534 }
5535 }
5536 #endif // HAVE_TRACKMOUSEEVENT
5537
5538 #if wxUSE_MOUSEEVENT_HACK
5539 // Windows often generates mouse events even if mouse position hasn't
5540 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
5541 //
5542 // Filter this out as it can result in unexpected behaviour compared to
5543 // other platforms
5544 if ( gs_lastMouseEvent.type == wxEVT_RIGHT_DOWN ||
5545 gs_lastMouseEvent.type == wxEVT_LEFT_DOWN ||
5546 gs_lastMouseEvent.type == wxEVT_MIDDLE_DOWN ||
5547 gs_lastMouseEvent.type == wxEVT_MOTION )
5548 {
5549 if ( ClientToScreen(wxPoint(x, y)) == gs_lastMouseEvent.pos )
5550 {
5551 gs_lastMouseEvent.type = wxEVT_MOTION;
5552
5553 return false;
5554 }
5555 }
5556 #endif // wxUSE_MOUSEEVENT_HACK
5557
5558 return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags);
5559 }
5560
5561
5562 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam)
5563 {
5564 #if wxUSE_MOUSEWHEEL
5565 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5566 // forwarded up to the parent by DefWindowProc()) and not in the client
5567 // ones as all the other messages, translate them to the client coords for
5568 // consistency
5569 const wxPoint
5570 pt = ScreenToClient(wxPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
5571 wxMouseEvent event(wxEVT_MOUSEWHEEL);
5572 InitMouseEvent(event, pt.x, pt.y, LOWORD(wParam));
5573 event.m_wheelRotation = (short)HIWORD(wParam);
5574 event.m_wheelDelta = WHEEL_DELTA;
5575
5576 static int s_linesPerRotation = -1;
5577 if ( s_linesPerRotation == -1 )
5578 {
5579 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
5580 &s_linesPerRotation, 0))
5581 {
5582 // this is not supposed to happen
5583 wxLogLastError(wxT("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5584
5585 // the default is 3, so use it if SystemParametersInfo() failed
5586 s_linesPerRotation = 3;
5587 }
5588 }
5589
5590 event.m_linesPerAction = s_linesPerRotation;
5591 return HandleWindowEvent(event);
5592
5593 #else // !wxUSE_MOUSEWHEEL
5594 wxUnusedVar(wParam);
5595 wxUnusedVar(lParam);
5596
5597 return false;
5598 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5599 }
5600
5601 void wxWindowMSW::GenerateMouseLeave()
5602 {
5603 m_mouseInWindow = false;
5604
5605 int state = 0;
5606 if ( wxIsShiftDown() )
5607 state |= MK_SHIFT;
5608 if ( wxIsCtrlDown() )
5609 state |= MK_CONTROL;
5610
5611 // Only the high-order bit should be tested
5612 if ( GetKeyState( VK_LBUTTON ) & (1<<15) )
5613 state |= MK_LBUTTON;
5614 if ( GetKeyState( VK_MBUTTON ) & (1<<15) )
5615 state |= MK_MBUTTON;
5616 if ( GetKeyState( VK_RBUTTON ) & (1<<15) )
5617 state |= MK_RBUTTON;
5618
5619 POINT pt;
5620 #ifdef __WXWINCE__
5621 if ( !::GetCursorPosWinCE(&pt) )
5622 #else
5623 if ( !::GetCursorPos(&pt) )
5624 #endif
5625 {
5626 wxLogLastError(wxT("GetCursorPos"));
5627 }
5628
5629 // we need to have client coordinates here for symmetry with
5630 // wxEVT_ENTER_WINDOW
5631 RECT rect = wxGetWindowRect(GetHwnd());
5632 pt.x -= rect.left;
5633 pt.y -= rect.top;
5634
5635 wxMouseEvent event(wxEVT_LEAVE_WINDOW);
5636 InitMouseEvent(event, pt.x, pt.y, state);
5637
5638 (void)HandleWindowEvent(event);
5639 }
5640
5641 // ---------------------------------------------------------------------------
5642 // keyboard handling
5643 // ---------------------------------------------------------------------------
5644
5645 namespace
5646 {
5647
5648 // Implementation of InitAnyKeyEvent() which can also be used when there is no
5649 // associated window: this can happen for the wxEVT_CHAR_HOOK events created by
5650 // the global keyboard hook (e.g. the event might have happened in a non-wx
5651 // window).
5652 void
5653 MSWInitAnyKeyEvent(wxKeyEvent& event,
5654 WXWPARAM wParam,
5655 WXLPARAM lParam,
5656 const wxWindowBase *win /* may be NULL */)
5657 {
5658 if ( win )
5659 {
5660 event.SetId(win->GetId());
5661 event.SetEventObject(const_cast<wxWindowBase *>(win));
5662 }
5663 else // No associated window.
5664 {
5665 // Use wxID_ANY for compatibility with the old code even if wxID_NONE
5666 // would arguably make more sense.
5667 event.SetId(wxID_ANY);
5668 }
5669
5670 event.m_shiftDown = wxIsShiftDown();
5671 event.m_controlDown = wxIsCtrlDown();
5672 event.m_altDown = (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN;
5673
5674 event.m_rawCode = (wxUint32) wParam;
5675 event.m_rawFlags = (wxUint32) lParam;
5676 #ifndef __WXWINCE__
5677 event.SetTimestamp(::GetMessageTime());
5678 #endif
5679
5680 // Event coordinates must be in window client coordinates system which
5681 // doesn't make sense if there is no window.
5682 //
5683 // We could use screen coordinates for such events but this would make the
5684 // logic of the event handlers more complicated: you'd need to test for the
5685 // event object and interpret the coordinates differently according to
5686 // whether it's NULL or not so unless somebody really asks for this let's
5687 // just avoid the issue.
5688 if ( win )
5689 {
5690 const wxPoint mousePos = win->ScreenToClient(wxGetMousePosition());
5691 event.m_x = mousePos.x;
5692 event.m_y = mousePos.y;
5693 }
5694 }
5695
5696 } // anonymous namespace
5697
5698 void
5699 wxWindowMSW::InitAnyKeyEvent(wxKeyEvent& event,
5700 WXWPARAM wParam,
5701 WXLPARAM lParam) const
5702 {
5703 MSWInitAnyKeyEvent(event, wParam, lParam, this);
5704 }
5705
5706 wxKeyEvent
5707 wxWindowMSW::CreateKeyEvent(wxEventType evType,
5708 WXWPARAM wParam,
5709 WXLPARAM lParam) const
5710 {
5711 // Catch any attempts to use this with WM_CHAR, it wouldn't work because
5712 // wParam is supposed to be a virtual key and not a character here.
5713 wxASSERT_MSG( evType != wxEVT_CHAR && evType != wxEVT_CHAR_HOOK,
5714 "CreateKeyEvent() can't be used for char events" );
5715
5716 wxKeyEvent event(evType);
5717 InitAnyKeyEvent(event, wParam, lParam);
5718
5719 event.m_keyCode = wxMSWKeyboard::VKToWX
5720 (
5721 wParam,
5722 lParam
5723 #if wxUSE_UNICODE
5724 , &event.m_uniChar
5725 #endif // wxUSE_UNICODE
5726 );
5727
5728 return event;
5729 }
5730
5731 // isASCII is true only when we're called from WM_CHAR handler and not from
5732 // WM_KEYDOWN one
5733 bool wxWindowMSW::HandleChar(WXWPARAM wParam, WXLPARAM lParam)
5734 {
5735 wxKeyEvent event(wxEVT_CHAR);
5736 InitAnyKeyEvent(event, wParam, lParam);
5737
5738 #if wxUSE_UNICODE
5739 // TODO: wParam uses UTF-16 so this is incorrect for characters outside of
5740 // the BMP, we should use WM_UNICHAR to handle them.
5741 event.m_uniChar = wParam;
5742 #endif // wxUSE_UNICODE
5743
5744 // Set non-Unicode key code too for compatibility if possible.
5745 if ( wParam < 0x80 )
5746 {
5747 // It's an ASCII character, no need to translate it.
5748 event.m_keyCode = wParam;
5749 }
5750 else
5751 {
5752 // Check if this key can be represented (as a single character) in the
5753 // current locale.
5754 const wchar_t wc = wParam;
5755 char ch;
5756 if ( wxConvLibc.FromWChar(&ch, 1, &wc, 1) != wxCONV_FAILED )
5757 {
5758 // For compatibility continue to provide the key code in this field
5759 // even though using GetUnicodeKey() is recommended now.
5760 event.m_keyCode = static_cast<unsigned char>(ch);
5761 }
5762 //else: Key can't be represented in the current locale, leave m_keyCode
5763 // as WXK_NONE and use GetUnicodeKey() to access the character.
5764 }
5765
5766 // the alphanumeric keys produced by pressing AltGr+something on European
5767 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5768 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5769 // alphanumeric, so pretend that there are no modifiers at all (the
5770 // KEY_DOWN event would still have the correct modifiers if they're really
5771 // needed)
5772 if ( event.m_controlDown && event.m_altDown &&
5773 (event.m_keyCode >= 32 && event.m_keyCode < 256) )
5774 {
5775 event.m_controlDown =
5776 event.m_altDown = false;
5777 }
5778
5779 return HandleWindowEvent(event);
5780 }
5781
5782 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam)
5783 {
5784 wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, wParam, lParam));
5785 return HandleWindowEvent(event);
5786 }
5787
5788 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam)
5789 {
5790 wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_UP, wParam, lParam));
5791 return HandleWindowEvent(event);
5792 }
5793
5794 #if wxUSE_MENUS
5795 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel),
5796 WXLPARAM WXUNUSED_IN_WINCE(lParam))
5797 {
5798 // FIXME: implement GetMenuItemCount for WinCE, possibly
5799 // in terms of GetMenuItemInfo
5800 #ifndef __WXWINCE__
5801 const HMENU hmenu = (HMENU)lParam;
5802
5803 MENUITEMINFO mii;
5804 wxZeroMemory(mii);
5805 mii.cbSize = sizeof(MENUITEMINFO);
5806
5807 // we could use MIIM_FTYPE here as we only need to know if the item is
5808 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5809 // MIIM_FTYPE is not supported under Win95
5810 mii.fMask = MIIM_TYPE | MIIM_DATA;
5811
5812 // find if we have this letter in any owner drawn item
5813 const int count = ::GetMenuItemCount(hmenu);
5814 for ( int i = 0; i < count; i++ )
5815 {
5816 // previous loop iteration could modify it, reset it back before
5817 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5818 mii.cch = 0;
5819
5820 if ( ::GetMenuItemInfo(hmenu, i, TRUE, &mii) )
5821 {
5822 if ( mii.fType == MFT_OWNERDRAW )
5823 {
5824 // dwItemData member of the MENUITEMINFO is a
5825 // pointer to the associated wxMenuItem -- see the
5826 // menu creation code
5827 wxMenuItem *item = (wxMenuItem*)mii.dwItemData;
5828
5829 const wxString label(item->GetItemLabel());
5830 const wxChar *p = wxStrchr(label.wx_str(), wxT('&'));
5831 while ( p++ )
5832 {
5833 if ( *p == wxT('&') )
5834 {
5835 // this is not the accel char, find the real one
5836 p = wxStrchr(p + 1, wxT('&'));
5837 }
5838 else // got the accel char
5839 {
5840 // FIXME-UNICODE: this comparison doesn't risk to work
5841 // for non ASCII accelerator characters I'm afraid, but
5842 // what can we do?
5843 if ( (wchar_t)wxToupper(*p) == (wchar_t)chAccel )
5844 {
5845 return i;
5846 }
5847 else
5848 {
5849 // this one doesn't match
5850 break;
5851 }
5852 }
5853 }
5854 }
5855 }
5856 else // failed to get the menu text?
5857 {
5858 // it's not fatal, so don't show error, but still log it
5859 wxLogLastError(wxT("GetMenuItemInfo"));
5860 }
5861 }
5862 #endif
5863 return wxNOT_FOUND;
5864 }
5865
5866 #endif // wxUSE_MENUS
5867
5868 bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg)
5869 {
5870 const wxEventType type = nMsg == WM_CUT ? wxEVT_COMMAND_TEXT_CUT
5871 : nMsg == WM_COPY ? wxEVT_COMMAND_TEXT_COPY
5872 : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE;
5873 wxClipboardTextEvent evt(type, GetId());
5874
5875 evt.SetEventObject(this);
5876
5877 return HandleWindowEvent(evt);
5878 }
5879
5880 // ---------------------------------------------------------------------------
5881 // joystick
5882 // ---------------------------------------------------------------------------
5883
5884 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
5885 {
5886 #ifdef JOY_BUTTON1
5887 int change = 0;
5888 if ( flags & JOY_BUTTON1CHG )
5889 change = wxJOY_BUTTON1;
5890 if ( flags & JOY_BUTTON2CHG )
5891 change = wxJOY_BUTTON2;
5892 if ( flags & JOY_BUTTON3CHG )
5893 change = wxJOY_BUTTON3;
5894 if ( flags & JOY_BUTTON4CHG )
5895 change = wxJOY_BUTTON4;
5896
5897 int buttons = 0;
5898 if ( flags & JOY_BUTTON1 )
5899 buttons |= wxJOY_BUTTON1;
5900 if ( flags & JOY_BUTTON2 )
5901 buttons |= wxJOY_BUTTON2;
5902 if ( flags & JOY_BUTTON3 )
5903 buttons |= wxJOY_BUTTON3;
5904 if ( flags & JOY_BUTTON4 )
5905 buttons |= wxJOY_BUTTON4;
5906
5907 // the event ids aren't consecutive so we can't use table based lookup
5908 int joystick;
5909 wxEventType eventType;
5910 switch ( msg )
5911 {
5912 case MM_JOY1MOVE:
5913 joystick = 1;
5914 eventType = wxEVT_JOY_MOVE;
5915 break;
5916
5917 case MM_JOY2MOVE:
5918 joystick = 2;
5919 eventType = wxEVT_JOY_MOVE;
5920 break;
5921
5922 case MM_JOY1ZMOVE:
5923 joystick = 1;
5924 eventType = wxEVT_JOY_ZMOVE;
5925 break;
5926
5927 case MM_JOY2ZMOVE:
5928 joystick = 2;
5929 eventType = wxEVT_JOY_ZMOVE;
5930 break;
5931
5932 case MM_JOY1BUTTONDOWN:
5933 joystick = 1;
5934 eventType = wxEVT_JOY_BUTTON_DOWN;
5935 break;
5936
5937 case MM_JOY2BUTTONDOWN:
5938 joystick = 2;
5939 eventType = wxEVT_JOY_BUTTON_DOWN;
5940 break;
5941
5942 case MM_JOY1BUTTONUP:
5943 joystick = 1;
5944 eventType = wxEVT_JOY_BUTTON_UP;
5945 break;
5946
5947 case MM_JOY2BUTTONUP:
5948 joystick = 2;
5949 eventType = wxEVT_JOY_BUTTON_UP;
5950 break;
5951
5952 default:
5953 wxFAIL_MSG(wxT("no such joystick event"));
5954
5955 return false;
5956 }
5957
5958 wxJoystickEvent event(eventType, buttons, joystick, change);
5959 event.SetPosition(wxPoint(x, y));
5960 event.SetEventObject(this);
5961
5962 return HandleWindowEvent(event);
5963 #else
5964 wxUnusedVar(msg);
5965 wxUnusedVar(x);
5966 wxUnusedVar(y);
5967 wxUnusedVar(flags);
5968 return false;
5969 #endif
5970 }
5971
5972 // ---------------------------------------------------------------------------
5973 // scrolling
5974 // ---------------------------------------------------------------------------
5975
5976 bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam,
5977 WXWORD pos, WXHWND control)
5978 {
5979 if ( control && control != m_hWnd ) // Prevent infinite recursion
5980 {
5981 wxWindow *child = wxFindWinFromHandle(control);
5982 if ( child )
5983 return child->MSWOnScroll(orientation, wParam, pos, control);
5984 }
5985
5986 wxScrollWinEvent event;
5987 event.SetPosition(pos);
5988 event.SetOrientation(orientation);
5989 event.SetEventObject(this);
5990
5991 switch ( wParam )
5992 {
5993 case SB_TOP:
5994 event.SetEventType(wxEVT_SCROLLWIN_TOP);
5995 break;
5996
5997 case SB_BOTTOM:
5998 event.SetEventType(wxEVT_SCROLLWIN_BOTTOM);
5999 break;
6000
6001 case SB_LINEUP:
6002 event.SetEventType(wxEVT_SCROLLWIN_LINEUP);
6003 break;
6004
6005 case SB_LINEDOWN:
6006 event.SetEventType(wxEVT_SCROLLWIN_LINEDOWN);
6007 break;
6008
6009 case SB_PAGEUP:
6010 event.SetEventType(wxEVT_SCROLLWIN_PAGEUP);
6011 break;
6012
6013 case SB_PAGEDOWN:
6014 event.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN);
6015 break;
6016
6017 case SB_THUMBPOSITION:
6018 case SB_THUMBTRACK:
6019 // under Win32, the scrollbar range and position are 32 bit integers,
6020 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
6021 // explicitly query the scrollbar for the correct position (this must
6022 // be done only for these two SB_ events as they are the only one
6023 // carrying the scrollbar position)
6024 {
6025 WinStruct<SCROLLINFO> scrollInfo;
6026 scrollInfo.fMask = SIF_TRACKPOS;
6027
6028 if ( !::GetScrollInfo(GetHwnd(),
6029 WXOrientToSB(orientation),
6030 &scrollInfo) )
6031 {
6032 // Not necessarily an error, if there are no scrollbars yet.
6033 // wxLogLastError(wxT("GetScrollInfo"));
6034 }
6035
6036 event.SetPosition(scrollInfo.nTrackPos);
6037 }
6038
6039 event.SetEventType( wParam == SB_THUMBPOSITION
6040 ? wxEVT_SCROLLWIN_THUMBRELEASE
6041 : wxEVT_SCROLLWIN_THUMBTRACK );
6042 break;
6043
6044 default:
6045 return false;
6046 }
6047
6048 return HandleWindowEvent(event);
6049 }
6050
6051 // ----------------------------------------------------------------------------
6052 // custom message handlers
6053 // ----------------------------------------------------------------------------
6054
6055 /* static */ bool
6056 wxWindowMSW::MSWRegisterMessageHandler(int msg, MSWMessageHandler handler)
6057 {
6058 wxCHECK_MSG( gs_messageHandlers.find(msg) == gs_messageHandlers.end(),
6059 false, wxT("registering handler for the same message twice") );
6060
6061 gs_messageHandlers[msg] = handler;
6062 return true;
6063 }
6064
6065 /* static */ void
6066 wxWindowMSW::MSWUnregisterMessageHandler(int msg, MSWMessageHandler handler)
6067 {
6068 const MSWMessageHandlers::iterator i = gs_messageHandlers.find(msg);
6069 wxCHECK_RET( i != gs_messageHandlers.end() && i->second == handler,
6070 wxT("unregistering non-registered handler?") );
6071
6072 gs_messageHandlers.erase(i);
6073 }
6074
6075 // ===========================================================================
6076 // global functions
6077 // ===========================================================================
6078
6079 void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font)
6080 {
6081 TEXTMETRIC tm;
6082 HDC dc = ::GetDC((HWND) wnd);
6083 HFONT was = 0;
6084
6085 // the_font.UseResource();
6086 // the_font.RealizeResource();
6087 HFONT fnt = (HFONT)the_font.GetResourceHandle(); // const_cast
6088 if ( fnt )
6089 was = (HFONT) SelectObject(dc,fnt);
6090
6091 GetTextMetrics(dc, &tm);
6092 if ( fnt && was )
6093 {
6094 SelectObject(dc,was);
6095 }
6096 ReleaseDC((HWND)wnd, dc);
6097
6098 if ( x )
6099 *x = tm.tmAveCharWidth;
6100 if ( y )
6101 *y = tm.tmHeight + tm.tmExternalLeading;
6102
6103 // the_font.ReleaseResource();
6104 }
6105
6106 // ----------------------------------------------------------------------------
6107 // keyboard codes
6108 // ----------------------------------------------------------------------------
6109
6110 namespace wxMSWKeyboard
6111 {
6112
6113 namespace
6114 {
6115
6116 // use the "extended" bit of lParam to distinguish extended keys from normal
6117 // keys as the same virtual key code is sent for both by Windows
6118 inline
6119 int ChooseNormalOrExtended(int lParam, int keyNormal, int keyExtended)
6120 {
6121 // except that if lParam is 0, it means we don't have real lParam from
6122 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
6123 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
6124 // non-numpad (hence extended) key as this is a more common case
6125 return !lParam || (HIWORD(lParam) & KF_EXTENDED) ? keyExtended : keyNormal;
6126 }
6127
6128 // this array contains the Windows virtual key codes which map one to one to
6129 // WXK_xxx constants and is used in wxMSWKeyboard::VKToWX/WXToVK() below
6130 //
6131 // note that keys having a normal and numpad version (e.g. WXK_HOME and
6132 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
6133 const struct wxKeyMapping
6134 {
6135 int vk;
6136 wxKeyCode wxk;
6137 } gs_specialKeys[] =
6138 {
6139 { VK_CANCEL, WXK_CANCEL },
6140 { VK_BACK, WXK_BACK },
6141 { VK_TAB, WXK_TAB },
6142 { VK_CLEAR, WXK_CLEAR },
6143 { VK_SHIFT, WXK_SHIFT },
6144 { VK_CONTROL, WXK_CONTROL },
6145 { VK_MENU , WXK_ALT },
6146 { VK_PAUSE, WXK_PAUSE },
6147 { VK_CAPITAL, WXK_CAPITAL },
6148 { VK_SPACE, WXK_SPACE },
6149 { VK_ESCAPE, WXK_ESCAPE },
6150 { VK_SELECT, WXK_SELECT },
6151 { VK_PRINT, WXK_PRINT },
6152 { VK_EXECUTE, WXK_EXECUTE },
6153 { VK_SNAPSHOT, WXK_SNAPSHOT },
6154 { VK_HELP, WXK_HELP },
6155
6156 { VK_NUMPAD0, WXK_NUMPAD0 },
6157 { VK_NUMPAD1, WXK_NUMPAD1 },
6158 { VK_NUMPAD2, WXK_NUMPAD2 },
6159 { VK_NUMPAD3, WXK_NUMPAD3 },
6160 { VK_NUMPAD4, WXK_NUMPAD4 },
6161 { VK_NUMPAD5, WXK_NUMPAD5 },
6162 { VK_NUMPAD6, WXK_NUMPAD6 },
6163 { VK_NUMPAD7, WXK_NUMPAD7 },
6164 { VK_NUMPAD8, WXK_NUMPAD8 },
6165 { VK_NUMPAD9, WXK_NUMPAD9 },
6166 { VK_MULTIPLY, WXK_NUMPAD_MULTIPLY },
6167 { VK_ADD, WXK_NUMPAD_ADD },
6168 { VK_SUBTRACT, WXK_NUMPAD_SUBTRACT },
6169 { VK_DECIMAL, WXK_NUMPAD_DECIMAL },
6170 { VK_DIVIDE, WXK_NUMPAD_DIVIDE },
6171
6172 { VK_F1, WXK_F1 },
6173 { VK_F2, WXK_F2 },
6174 { VK_F3, WXK_F3 },
6175 { VK_F4, WXK_F4 },
6176 { VK_F5, WXK_F5 },
6177 { VK_F6, WXK_F6 },
6178 { VK_F7, WXK_F7 },
6179 { VK_F8, WXK_F8 },
6180 { VK_F9, WXK_F9 },
6181 { VK_F10, WXK_F10 },
6182 { VK_F11, WXK_F11 },
6183 { VK_F12, WXK_F12 },
6184 { VK_F13, WXK_F13 },
6185 { VK_F14, WXK_F14 },
6186 { VK_F15, WXK_F15 },
6187 { VK_F16, WXK_F16 },
6188 { VK_F17, WXK_F17 },
6189 { VK_F18, WXK_F18 },
6190 { VK_F19, WXK_F19 },
6191 { VK_F20, WXK_F20 },
6192 { VK_F21, WXK_F21 },
6193 { VK_F22, WXK_F22 },
6194 { VK_F23, WXK_F23 },
6195 { VK_F24, WXK_F24 },
6196
6197 { VK_NUMLOCK, WXK_NUMLOCK },
6198 { VK_SCROLL, WXK_SCROLL },
6199
6200 #ifdef VK_APPS
6201 { VK_LWIN, WXK_WINDOWS_LEFT },
6202 { VK_RWIN, WXK_WINDOWS_RIGHT },
6203 { VK_APPS, WXK_WINDOWS_MENU },
6204 #endif // VK_APPS defined
6205 };
6206
6207 } // anonymous namespace
6208
6209 int VKToWX(WXWORD vk, WXLPARAM lParam, wchar_t *uc)
6210 {
6211 int wxk;
6212
6213 // check the table first
6214 for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ )
6215 {
6216 if ( gs_specialKeys[n].vk == vk )
6217 {
6218 wxk = gs_specialKeys[n].wxk;
6219 if ( wxk < WXK_START )
6220 {
6221 // Unicode code for this key is the same as its ASCII code.
6222 if ( uc )
6223 *uc = wxk;
6224 }
6225
6226 return wxk;
6227 }
6228 }
6229
6230 // keys requiring special handling
6231 switch ( vk )
6232 {
6233 case VK_OEM_1:
6234 case VK_OEM_PLUS:
6235 case VK_OEM_COMMA:
6236 case VK_OEM_MINUS:
6237 case VK_OEM_PERIOD:
6238 case VK_OEM_2:
6239 case VK_OEM_3:
6240 case VK_OEM_4:
6241 case VK_OEM_5:
6242 case VK_OEM_6:
6243 case VK_OEM_7:
6244 // MapVirtualKey() returns 0 if it fails to convert the virtual
6245 // key which nicely corresponds to our WXK_NONE.
6246 wxk = ::MapVirtualKey(vk, MAPVK_VK_TO_CHAR);
6247
6248 if ( HIWORD(wxk) & 0x8000 )
6249 {
6250 // It's a dead key and we don't return anything at all for them
6251 // as we simply don't have any way to indicate the difference
6252 // between e.g. a normal "'" and "'" as a dead key -- and
6253 // generating the same events for them just doesn't seem like a
6254 // good idea.
6255 wxk = WXK_NONE;
6256 }
6257
6258 // In any case return this as a Unicode character value.
6259 if ( uc )
6260 *uc = wxk;
6261
6262 // For compatibility with the old non-Unicode code we continue
6263 // returning key codes for Latin-1 characters directly
6264 // (normally it would really only make sense to do it for the
6265 // ASCII characters, not Latin-1 ones).
6266 if ( wxk > 255 )
6267 {
6268 // But for anything beyond this we can only return the key
6269 // value as a real Unicode character, not a wxKeyCode
6270 // because this enum values clash with Unicode characters
6271 // (e.g. WXK_LBUTTON also happens to be U+012C a.k.a.
6272 // "LATIN CAPITAL LETTER I WITH BREVE").
6273 wxk = WXK_NONE;
6274 }
6275 break;
6276
6277 // handle extended keys
6278 case VK_PRIOR:
6279 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PAGEUP, WXK_PAGEUP);
6280 break;
6281
6282 case VK_NEXT:
6283 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PAGEDOWN, WXK_PAGEDOWN);
6284 break;
6285
6286 case VK_END:
6287 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_END, WXK_END);
6288 break;
6289
6290 case VK_HOME:
6291 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_HOME, WXK_HOME);
6292 break;
6293
6294 case VK_LEFT:
6295 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_LEFT, WXK_LEFT);
6296 break;
6297
6298 case VK_UP:
6299 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_UP, WXK_UP);
6300 break;
6301
6302 case VK_RIGHT:
6303 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_RIGHT, WXK_RIGHT);
6304 break;
6305
6306 case VK_DOWN:
6307 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_DOWN, WXK_DOWN);
6308 break;
6309
6310 case VK_INSERT:
6311 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_INSERT, WXK_INSERT);
6312 break;
6313
6314 case VK_DELETE:
6315 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_DELETE, WXK_DELETE);
6316 break;
6317
6318 case VK_RETURN:
6319 // don't use ChooseNormalOrExtended() here as the keys are reversed
6320 // here: numpad enter is the extended one
6321 wxk = HIWORD(lParam) & KF_EXTENDED ? WXK_NUMPAD_ENTER : WXK_RETURN;
6322 break;
6323
6324 default:
6325 if ( (vk >= '0' && vk <= '9') || (vk >= 'A' && vk <= 'Z') )
6326 {
6327 // A simple alphanumeric key and the values of them coincide in
6328 // Windows and wx for both ASCII and Unicode codes.
6329 wxk = vk;
6330 }
6331 else // Something we simply don't know about at all.
6332 {
6333 wxk = WXK_NONE;
6334 }
6335
6336 if ( uc )
6337 *uc = vk;
6338 }
6339
6340 return wxk;
6341 }
6342
6343 WXWORD WXToVK(int wxk, bool *isExtended)
6344 {
6345 // check the table first
6346 for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ )
6347 {
6348 if ( gs_specialKeys[n].wxk == wxk )
6349 {
6350 // All extended keys (i.e. non-numpad versions of the keys that
6351 // exist both in the numpad and outside of it) are dealt with
6352 // below.
6353 if ( isExtended )
6354 *isExtended = false;
6355
6356 return gs_specialKeys[n].vk;
6357 }
6358 }
6359
6360 // and then check for special keys not included in the table
6361 bool extended = false;
6362 WXWORD vk;
6363 switch ( wxk )
6364 {
6365 case WXK_PAGEUP:
6366 extended = true;
6367 case WXK_NUMPAD_PAGEUP:
6368 vk = VK_PRIOR;
6369 break;
6370
6371 case WXK_PAGEDOWN:
6372 extended = true;
6373 case WXK_NUMPAD_PAGEDOWN:
6374 vk = VK_NEXT;
6375 break;
6376
6377 case WXK_END:
6378 extended = true;
6379 case WXK_NUMPAD_END:
6380 vk = VK_END;
6381 break;
6382
6383 case WXK_HOME:
6384 extended = true;
6385 case WXK_NUMPAD_HOME:
6386 vk = VK_HOME;
6387 break;
6388
6389 case WXK_LEFT:
6390 extended = true;
6391 case WXK_NUMPAD_LEFT:
6392 vk = VK_LEFT;
6393 break;
6394
6395 case WXK_UP:
6396 extended = true;
6397 case WXK_NUMPAD_UP:
6398 vk = VK_UP;
6399 break;
6400
6401 case WXK_RIGHT:
6402 extended = true;
6403 case WXK_NUMPAD_RIGHT:
6404 vk = VK_RIGHT;
6405 break;
6406
6407 case WXK_DOWN:
6408 extended = true;
6409 case WXK_NUMPAD_DOWN:
6410 vk = VK_DOWN;
6411 break;
6412
6413 case WXK_INSERT:
6414 extended = true;
6415 case WXK_NUMPAD_INSERT:
6416 vk = VK_INSERT;
6417 break;
6418
6419 case WXK_DELETE:
6420 extended = true;
6421 case WXK_NUMPAD_DELETE:
6422 vk = VK_DELETE;
6423 break;
6424
6425 default:
6426 // no VkKeyScan() under CE unfortunately, we need to test how does
6427 // it handle OEM keys
6428 #ifndef __WXWINCE__
6429 // check to see if its one of the OEM key codes.
6430 BYTE vks = LOBYTE(VkKeyScan(wxk));
6431 if ( vks != 0xff )
6432 {
6433 vk = vks;
6434 }
6435 else
6436 #endif // !__WXWINCE__
6437 {
6438 vk = (WXWORD)wxk;
6439 }
6440 }
6441
6442 if ( isExtended )
6443 *isExtended = extended;
6444
6445 return vk;
6446 }
6447
6448 } // namespace wxMSWKeyboard
6449
6450 // small helper for wxGetKeyState() and wxGetMouseState()
6451 static inline bool wxIsKeyDown(WXWORD vk)
6452 {
6453 // SM_SWAPBUTTON is not available under CE, so don't swap buttons there
6454 #ifdef SM_SWAPBUTTON
6455 if ( vk == VK_LBUTTON || vk == VK_RBUTTON )
6456 {
6457 if ( ::GetSystemMetrics(SM_SWAPBUTTON) )
6458 {
6459 if ( vk == VK_LBUTTON )
6460 vk = VK_RBUTTON;
6461 else // vk == VK_RBUTTON
6462 vk = VK_LBUTTON;
6463 }
6464 }
6465 #endif // SM_SWAPBUTTON
6466
6467 // the low order bit indicates whether the key was pressed since the last
6468 // call and the high order one indicates whether it is down right now and
6469 // we only want that one
6470 return (GetAsyncKeyState(vk) & (1<<15)) != 0;
6471 }
6472
6473 bool wxGetKeyState(wxKeyCode key)
6474 {
6475 // although this does work under Windows, it is not supported under other
6476 // platforms so don't allow it, you must use wxGetMouseState() instead
6477 wxASSERT_MSG( key != VK_LBUTTON &&
6478 key != VK_RBUTTON &&
6479 key != VK_MBUTTON,
6480 wxT("can't use wxGetKeyState() for mouse buttons") );
6481
6482 const WXWORD vk = wxMSWKeyboard::WXToVK(key);
6483
6484 // if the requested key is a LED key, return true if the led is pressed
6485 if ( key == WXK_NUMLOCK || key == WXK_CAPITAL || key == WXK_SCROLL )
6486 {
6487 // low order bit means LED is highlighted and high order one means the
6488 // key is down; for compatibility with the other ports return true if
6489 // either one is set
6490 return GetKeyState(vk) != 0;
6491
6492 }
6493 else // normal key
6494 {
6495 return wxIsKeyDown(vk);
6496 }
6497 }
6498
6499
6500 wxMouseState wxGetMouseState()
6501 {
6502 wxMouseState ms;
6503 POINT pt;
6504 GetCursorPos( &pt );
6505
6506 ms.SetX(pt.x);
6507 ms.SetY(pt.y);
6508 ms.SetLeftDown(wxIsKeyDown(VK_LBUTTON));
6509 ms.SetMiddleDown(wxIsKeyDown(VK_MBUTTON));
6510 ms.SetRightDown(wxIsKeyDown(VK_RBUTTON));
6511 #ifdef wxHAS_XBUTTON
6512 ms.SetAux1Down(wxIsKeyDown(VK_XBUTTON1));
6513 ms.SetAux2Down(wxIsKeyDown(VK_XBUTTON2));
6514 #endif // wxHAS_XBUTTON
6515
6516 ms.SetControlDown(wxIsCtrlDown ());
6517 ms.SetShiftDown (wxIsShiftDown());
6518 ms.SetAltDown (wxIsAltDown ());
6519 // ms.SetMetaDown();
6520
6521 return ms;
6522 }
6523
6524
6525 wxWindow *wxGetActiveWindow()
6526 {
6527 HWND hWnd = GetActiveWindow();
6528 if ( hWnd != 0 )
6529 {
6530 return wxFindWinFromHandle(hWnd);
6531 }
6532 return NULL;
6533 }
6534
6535 extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
6536 {
6537 HWND hwnd = (HWND)hWnd;
6538
6539 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
6540 // by code in msw/radiobox.cpp), for all the others we just search up the
6541 // window hierarchy
6542 wxWindow *win = NULL;
6543 if ( hwnd )
6544 {
6545 win = wxFindWinFromHandle(hwnd);
6546 if ( !win )
6547 {
6548 #if wxUSE_RADIOBOX
6549 // native radiobuttons return DLGC_RADIOBUTTON here and for any
6550 // wxWindow class which overrides WM_GETDLGCODE processing to
6551 // do it as well, win would be already non NULL
6552 if ( ::SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_RADIOBUTTON )
6553 {
6554 win = wxRadioBox::GetFromRadioButtonHWND(hwnd);
6555 }
6556 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
6557 #endif // wxUSE_RADIOBOX
6558
6559 // spin control text buddy window should be mapped to spin ctrl
6560 // itself so try it too
6561 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
6562 if ( !win )
6563 {
6564 win = wxSpinCtrl::GetSpinForTextCtrl((WXHWND)hwnd);
6565 }
6566 #endif // wxUSE_SPINCTRL
6567 }
6568 }
6569
6570 while ( hwnd && !win )
6571 {
6572 // this is a really ugly hack needed to avoid mistakenly returning the
6573 // parent frame wxWindow for the find/replace modeless dialog HWND -
6574 // this, in turn, is needed to call IsDialogMessage() from
6575 // wxApp::ProcessMessage() as for this we must return NULL from here
6576 //
6577 // FIXME: this is clearly not the best way to do it but I think we'll
6578 // need to change HWND <-> wxWindow code more heavily than I can
6579 // do it now to fix it
6580 #ifndef __WXMICROWIN__
6581 if ( ::GetWindow(hwnd, GW_OWNER) )
6582 {
6583 // it's a dialog box, don't go upwards
6584 break;
6585 }
6586 #endif
6587
6588 hwnd = ::GetParent(hwnd);
6589 win = wxFindWinFromHandle(hwnd);
6590 }
6591
6592 return win;
6593 }
6594
6595 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
6596
6597 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
6598 // in active frames and dialogs, regardless of where the focus is.
6599 static HHOOK wxTheKeyboardHook = 0;
6600
6601 int APIENTRY
6602 wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
6603 {
6604 DWORD hiWord = HIWORD(lParam);
6605 if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) )
6606 {
6607 wchar_t uc;
6608 int id = wxMSWKeyboard::VKToWX(wParam, lParam, &uc);
6609 if ( id != WXK_NONE
6610 #if wxUSE_UNICODE
6611 || static_cast<int>(uc) != WXK_NONE
6612 #endif // wxUSE_UNICODE
6613 )
6614 {
6615 const wxWindow * const win = wxGetActiveWindow();
6616
6617 wxKeyEvent event(wxEVT_CHAR_HOOK);
6618 MSWInitAnyKeyEvent(event, wParam, lParam, win);
6619
6620 event.m_keyCode = id;
6621 #if wxUSE_UNICODE
6622 event.m_uniChar = uc;
6623 #endif // wxUSE_UNICODE
6624
6625 wxEvtHandler * const handler = win ? win->GetEventHandler()
6626 : wxTheApp;
6627
6628 if ( handler && handler->ProcessEvent(event) )
6629 {
6630 // processed
6631 return 1;
6632 }
6633 }
6634 }
6635
6636 return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam);
6637 }
6638
6639 void wxSetKeyboardHook(bool doIt)
6640 {
6641 if ( doIt )
6642 {
6643 wxTheKeyboardHook = ::SetWindowsHookEx
6644 (
6645 WH_KEYBOARD,
6646 (HOOKPROC)wxKeyboardHook,
6647 NULL, // must be NULL for process hook
6648 ::GetCurrentThreadId()
6649 );
6650 if ( !wxTheKeyboardHook )
6651 {
6652 wxLogLastError(wxT("SetWindowsHookEx(wxKeyboardHook)"));
6653 }
6654 }
6655 else // uninstall
6656 {
6657 if ( wxTheKeyboardHook )
6658 ::UnhookWindowsHookEx(wxTheKeyboardHook);
6659 }
6660 }
6661
6662 #endif // !__WXMICROWIN__
6663
6664 #if wxDEBUG_LEVEL >= 2
6665 const wxChar *wxGetMessageName(int message)
6666 {
6667 switch ( message )
6668 {
6669 case 0x0000: return wxT("WM_NULL");
6670 case 0x0001: return wxT("WM_CREATE");
6671 case 0x0002: return wxT("WM_DESTROY");
6672 case 0x0003: return wxT("WM_MOVE");
6673 case 0x0005: return wxT("WM_SIZE");
6674 case 0x0006: return wxT("WM_ACTIVATE");
6675 case 0x0007: return wxT("WM_SETFOCUS");
6676 case 0x0008: return wxT("WM_KILLFOCUS");
6677 case 0x000A: return wxT("WM_ENABLE");
6678 case 0x000B: return wxT("WM_SETREDRAW");
6679 case 0x000C: return wxT("WM_SETTEXT");
6680 case 0x000D: return wxT("WM_GETTEXT");
6681 case 0x000E: return wxT("WM_GETTEXTLENGTH");
6682 case 0x000F: return wxT("WM_PAINT");
6683 case 0x0010: return wxT("WM_CLOSE");
6684 case 0x0011: return wxT("WM_QUERYENDSESSION");
6685 case 0x0012: return wxT("WM_QUIT");
6686 case 0x0013: return wxT("WM_QUERYOPEN");
6687 case 0x0014: return wxT("WM_ERASEBKGND");
6688 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
6689 case 0x0016: return wxT("WM_ENDSESSION");
6690 case 0x0017: return wxT("WM_SYSTEMERROR");
6691 case 0x0018: return wxT("WM_SHOWWINDOW");
6692 case 0x0019: return wxT("WM_CTLCOLOR");
6693 case 0x001A: return wxT("WM_WININICHANGE");
6694 case 0x001B: return wxT("WM_DEVMODECHANGE");
6695 case 0x001C: return wxT("WM_ACTIVATEAPP");
6696 case 0x001D: return wxT("WM_FONTCHANGE");
6697 case 0x001E: return wxT("WM_TIMECHANGE");
6698 case 0x001F: return wxT("WM_CANCELMODE");
6699 case 0x0020: return wxT("WM_SETCURSOR");
6700 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6701 case 0x0022: return wxT("WM_CHILDACTIVATE");
6702 case 0x0023: return wxT("WM_QUEUESYNC");
6703 case 0x0024: return wxT("WM_GETMINMAXINFO");
6704 case 0x0026: return wxT("WM_PAINTICON");
6705 case 0x0027: return wxT("WM_ICONERASEBKGND");
6706 case 0x0028: return wxT("WM_NEXTDLGCTL");
6707 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6708 case 0x002B: return wxT("WM_DRAWITEM");
6709 case 0x002C: return wxT("WM_MEASUREITEM");
6710 case 0x002D: return wxT("WM_DELETEITEM");
6711 case 0x002E: return wxT("WM_VKEYTOITEM");
6712 case 0x002F: return wxT("WM_CHARTOITEM");
6713 case 0x0030: return wxT("WM_SETFONT");
6714 case 0x0031: return wxT("WM_GETFONT");
6715 case 0x0037: return wxT("WM_QUERYDRAGICON");
6716 case 0x0039: return wxT("WM_COMPAREITEM");
6717 case 0x0041: return wxT("WM_COMPACTING");
6718 case 0x0044: return wxT("WM_COMMNOTIFY");
6719 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6720 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6721 case 0x0048: return wxT("WM_POWER");
6722
6723 case 0x004A: return wxT("WM_COPYDATA");
6724 case 0x004B: return wxT("WM_CANCELJOURNAL");
6725 case 0x004E: return wxT("WM_NOTIFY");
6726 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6727 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6728 case 0x0052: return wxT("WM_TCARD");
6729 case 0x0053: return wxT("WM_HELP");
6730 case 0x0054: return wxT("WM_USERCHANGED");
6731 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6732 case 0x007B: return wxT("WM_CONTEXTMENU");
6733 case 0x007C: return wxT("WM_STYLECHANGING");
6734 case 0x007D: return wxT("WM_STYLECHANGED");
6735 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6736 case 0x007F: return wxT("WM_GETICON");
6737 case 0x0080: return wxT("WM_SETICON");
6738
6739 case 0x0081: return wxT("WM_NCCREATE");
6740 case 0x0082: return wxT("WM_NCDESTROY");
6741 case 0x0083: return wxT("WM_NCCALCSIZE");
6742 case 0x0084: return wxT("WM_NCHITTEST");
6743 case 0x0085: return wxT("WM_NCPAINT");
6744 case 0x0086: return wxT("WM_NCACTIVATE");
6745 case 0x0087: return wxT("WM_GETDLGCODE");
6746 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6747 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6748 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6749 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6750 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6751 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6752 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6753 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6754 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6755 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6756
6757 case 0x00B0: return wxT("EM_GETSEL");
6758 case 0x00B1: return wxT("EM_SETSEL");
6759 case 0x00B2: return wxT("EM_GETRECT");
6760 case 0x00B3: return wxT("EM_SETRECT");
6761 case 0x00B4: return wxT("EM_SETRECTNP");
6762 case 0x00B5: return wxT("EM_SCROLL");
6763 case 0x00B6: return wxT("EM_LINESCROLL");
6764 case 0x00B7: return wxT("EM_SCROLLCARET");
6765 case 0x00B8: return wxT("EM_GETMODIFY");
6766 case 0x00B9: return wxT("EM_SETMODIFY");
6767 case 0x00BA: return wxT("EM_GETLINECOUNT");
6768 case 0x00BB: return wxT("EM_LINEINDEX");
6769 case 0x00BC: return wxT("EM_SETHANDLE");
6770 case 0x00BD: return wxT("EM_GETHANDLE");
6771 case 0x00BE: return wxT("EM_GETTHUMB");
6772 case 0x00C1: return wxT("EM_LINELENGTH");
6773 case 0x00C2: return wxT("EM_REPLACESEL");
6774 case 0x00C4: return wxT("EM_GETLINE");
6775 case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */
6776 case 0x00C6: return wxT("EM_CANUNDO");
6777 case 0x00C7: return wxT("EM_UNDO");
6778 case 0x00C8: return wxT("EM_FMTLINES");
6779 case 0x00C9: return wxT("EM_LINEFROMCHAR");
6780 case 0x00CB: return wxT("EM_SETTABSTOPS");
6781 case 0x00CC: return wxT("EM_SETPASSWORDCHAR");
6782 case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER");
6783 case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE");
6784 case 0x00CF: return wxT("EM_SETREADONLY");
6785 case 0x00D0: return wxT("EM_SETWORDBREAKPROC");
6786 case 0x00D1: return wxT("EM_GETWORDBREAKPROC");
6787 case 0x00D2: return wxT("EM_GETPASSWORDCHAR");
6788 case 0x00D3: return wxT("EM_SETMARGINS");
6789 case 0x00D4: return wxT("EM_GETMARGINS");
6790 case 0x00D5: return wxT("EM_GETLIMITTEXT");
6791 case 0x00D6: return wxT("EM_POSFROMCHAR");
6792 case 0x00D7: return wxT("EM_CHARFROMPOS");
6793 case 0x00D8: return wxT("EM_SETIMESTATUS");
6794 case 0x00D9: return wxT("EM_GETIMESTATUS");
6795
6796 case 0x0100: return wxT("WM_KEYDOWN");
6797 case 0x0101: return wxT("WM_KEYUP");
6798 case 0x0102: return wxT("WM_CHAR");
6799 case 0x0103: return wxT("WM_DEADCHAR");
6800 case 0x0104: return wxT("WM_SYSKEYDOWN");
6801 case 0x0105: return wxT("WM_SYSKEYUP");
6802 case 0x0106: return wxT("WM_SYSCHAR");
6803 case 0x0107: return wxT("WM_SYSDEADCHAR");
6804 case 0x0108: return wxT("WM_KEYLAST");
6805
6806 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6807 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6808 case 0x010F: return wxT("WM_IME_COMPOSITION");
6809
6810 case 0x0110: return wxT("WM_INITDIALOG");
6811 case 0x0111: return wxT("WM_COMMAND");
6812 case 0x0112: return wxT("WM_SYSCOMMAND");
6813 case 0x0113: return wxT("WM_TIMER");
6814 case 0x0114: return wxT("WM_HSCROLL");
6815 case 0x0115: return wxT("WM_VSCROLL");
6816 case 0x0116: return wxT("WM_INITMENU");
6817 case 0x0117: return wxT("WM_INITMENUPOPUP");
6818 case 0x011F: return wxT("WM_MENUSELECT");
6819 case 0x0120: return wxT("WM_MENUCHAR");
6820 case 0x0121: return wxT("WM_ENTERIDLE");
6821
6822 case 0x0127: return wxT("WM_CHANGEUISTATE");
6823 case 0x0128: return wxT("WM_UPDATEUISTATE");
6824 case 0x0129: return wxT("WM_QUERYUISTATE");
6825
6826 case 0x0132: return wxT("WM_CTLCOLORMSGBOX");
6827 case 0x0133: return wxT("WM_CTLCOLOREDIT");
6828 case 0x0134: return wxT("WM_CTLCOLORLISTBOX");
6829 case 0x0135: return wxT("WM_CTLCOLORBTN");
6830 case 0x0136: return wxT("WM_CTLCOLORDLG");
6831 case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR");
6832 case 0x0138: return wxT("WM_CTLCOLORSTATIC");
6833 case 0x01E1: return wxT("MN_GETHMENU");
6834
6835 case 0x0200: return wxT("WM_MOUSEMOVE");
6836 case 0x0201: return wxT("WM_LBUTTONDOWN");
6837 case 0x0202: return wxT("WM_LBUTTONUP");
6838 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6839 case 0x0204: return wxT("WM_RBUTTONDOWN");
6840 case 0x0205: return wxT("WM_RBUTTONUP");
6841 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6842 case 0x0207: return wxT("WM_MBUTTONDOWN");
6843 case 0x0208: return wxT("WM_MBUTTONUP");
6844 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6845 case 0x020A: return wxT("WM_MOUSEWHEEL");
6846 case 0x020B: return wxT("WM_XBUTTONDOWN");
6847 case 0x020C: return wxT("WM_XBUTTONUP");
6848 case 0x020D: return wxT("WM_XBUTTONDBLCLK");
6849 case 0x0210: return wxT("WM_PARENTNOTIFY");
6850 case 0x0211: return wxT("WM_ENTERMENULOOP");
6851 case 0x0212: return wxT("WM_EXITMENULOOP");
6852
6853 case 0x0213: return wxT("WM_NEXTMENU");
6854 case 0x0214: return wxT("WM_SIZING");
6855 case 0x0215: return wxT("WM_CAPTURECHANGED");
6856 case 0x0216: return wxT("WM_MOVING");
6857 case 0x0218: return wxT("WM_POWERBROADCAST");
6858 case 0x0219: return wxT("WM_DEVICECHANGE");
6859
6860 case 0x0220: return wxT("WM_MDICREATE");
6861 case 0x0221: return wxT("WM_MDIDESTROY");
6862 case 0x0222: return wxT("WM_MDIACTIVATE");
6863 case 0x0223: return wxT("WM_MDIRESTORE");
6864 case 0x0224: return wxT("WM_MDINEXT");
6865 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6866 case 0x0226: return wxT("WM_MDITILE");
6867 case 0x0227: return wxT("WM_MDICASCADE");
6868 case 0x0228: return wxT("WM_MDIICONARRANGE");
6869 case 0x0229: return wxT("WM_MDIGETACTIVE");
6870 case 0x0230: return wxT("WM_MDISETMENU");
6871 case 0x0233: return wxT("WM_DROPFILES");
6872
6873 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6874 case 0x0282: return wxT("WM_IME_NOTIFY");
6875 case 0x0283: return wxT("WM_IME_CONTROL");
6876 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6877 case 0x0285: return wxT("WM_IME_SELECT");
6878 case 0x0286: return wxT("WM_IME_CHAR");
6879 case 0x0290: return wxT("WM_IME_KEYDOWN");
6880 case 0x0291: return wxT("WM_IME_KEYUP");
6881
6882 case 0x02A0: return wxT("WM_NCMOUSEHOVER");
6883 case 0x02A1: return wxT("WM_MOUSEHOVER");
6884 case 0x02A2: return wxT("WM_NCMOUSELEAVE");
6885 case 0x02A3: return wxT("WM_MOUSELEAVE");
6886
6887 case 0x0300: return wxT("WM_CUT");
6888 case 0x0301: return wxT("WM_COPY");
6889 case 0x0302: return wxT("WM_PASTE");
6890 case 0x0303: return wxT("WM_CLEAR");
6891 case 0x0304: return wxT("WM_UNDO");
6892 case 0x0305: return wxT("WM_RENDERFORMAT");
6893 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6894 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6895 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6896 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6897 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6898 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6899 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6900 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6901 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6902 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6903 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6904 case 0x0311: return wxT("WM_PALETTECHANGED");
6905 case 0x0312: return wxT("WM_HOTKEY");
6906
6907 case 0x0317: return wxT("WM_PRINT");
6908 case 0x0318: return wxT("WM_PRINTCLIENT");
6909
6910 // common controls messages - although they're not strictly speaking
6911 // standard, it's nice to decode them nevertheless
6912
6913 // listview
6914 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6915 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6916 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6917 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6918 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6919 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6920 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6921 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6922 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6923 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6924 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6925 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6926 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6927 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6928 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6929 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6930 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6931 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6932 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6933 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6934 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6935 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6936 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6937 case 0x1000 + 18: return wxT("LVM_HITTEST");
6938 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6939 case 0x1000 + 20: return wxT("LVM_SCROLL");
6940 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6941 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6942 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6943 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6944 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6945 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6946 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6947 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6948 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6949 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6950 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6951 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6952 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6953 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6954 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6955 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6956 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6957 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6958 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6959 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6960 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6961 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6962 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6963 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6964 case 0x1000 + 42: return wxT("LVM_UPDATE");
6965 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6966 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6967 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6968 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6969 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6970 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6971 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6972 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6973 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6974 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6975 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6976 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6977 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6978 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6979 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6980 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6981 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6982 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6983 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6984 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6985 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6986 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6987 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6988 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6989 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6990 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6991
6992 // tree view
6993 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6994 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6995 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6996 case 0x1100 + 2: return wxT("TVM_EXPAND");
6997 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6998 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6999 case 0x1100 + 6: return wxT("TVM_GETINDENT");
7000 case 0x1100 + 7: return wxT("TVM_SETINDENT");
7001 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
7002 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
7003 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
7004 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
7005 case 0x1100 + 12: return wxT("TVM_GETITEMA");
7006 case 0x1100 + 62: return wxT("TVM_GETITEMW");
7007 case 0x1100 + 13: return wxT("TVM_SETITEMA");
7008 case 0x1100 + 63: return wxT("TVM_SETITEMW");
7009 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
7010 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
7011 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
7012 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
7013 case 0x1100 + 17: return wxT("TVM_HITTEST");
7014 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
7015 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
7016 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
7017 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
7018 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
7019 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
7020 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
7021 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
7022 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
7023
7024 // header
7025 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
7026 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
7027 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
7028 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
7029 case 0x1200 + 3: return wxT("HDM_GETITEMA");
7030 case 0x1200 + 11: return wxT("HDM_GETITEMW");
7031 case 0x1200 + 4: return wxT("HDM_SETITEMA");
7032 case 0x1200 + 12: return wxT("HDM_SETITEMW");
7033 case 0x1200 + 5: return wxT("HDM_LAYOUT");
7034 case 0x1200 + 6: return wxT("HDM_HITTEST");
7035 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
7036 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
7037 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
7038 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
7039 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
7040 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
7041 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
7042 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
7043
7044 // tab control
7045 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
7046 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
7047 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
7048 case 0x1300 + 5: return wxT("TCM_GETITEMA");
7049 case 0x1300 + 60: return wxT("TCM_GETITEMW");
7050 case 0x1300 + 6: return wxT("TCM_SETITEMA");
7051 case 0x1300 + 61: return wxT("TCM_SETITEMW");
7052 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
7053 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
7054 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
7055 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
7056 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
7057 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
7058 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
7059 case 0x1300 + 13: return wxT("TCM_HITTEST");
7060 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
7061 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
7062 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
7063 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
7064 case 0x1300 + 43: return wxT("TCM_SETPADDING");
7065 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
7066 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
7067 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
7068 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
7069 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
7070 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
7071 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
7072
7073 // toolbar
7074 case WM_USER+1: return wxT("TB_ENABLEBUTTON");
7075 case WM_USER+2: return wxT("TB_CHECKBUTTON");
7076 case WM_USER+3: return wxT("TB_PRESSBUTTON");
7077 case WM_USER+4: return wxT("TB_HIDEBUTTON");
7078 case WM_USER+5: return wxT("TB_INDETERMINATE");
7079 case WM_USER+9: return wxT("TB_ISBUTTONENABLED");
7080 case WM_USER+10: return wxT("TB_ISBUTTONCHECKED");
7081 case WM_USER+11: return wxT("TB_ISBUTTONPRESSED");
7082 case WM_USER+12: return wxT("TB_ISBUTTONHIDDEN");
7083 case WM_USER+13: return wxT("TB_ISBUTTONINDETERMINATE");
7084 case WM_USER+17: return wxT("TB_SETSTATE");
7085 case WM_USER+18: return wxT("TB_GETSTATE");
7086 case WM_USER+19: return wxT("TB_ADDBITMAP");
7087 case WM_USER+20: return wxT("TB_ADDBUTTONS");
7088 case WM_USER+21: return wxT("TB_INSERTBUTTON");
7089 case WM_USER+22: return wxT("TB_DELETEBUTTON");
7090 case WM_USER+23: return wxT("TB_GETBUTTON");
7091 case WM_USER+24: return wxT("TB_BUTTONCOUNT");
7092 case WM_USER+25: return wxT("TB_COMMANDTOINDEX");
7093 case WM_USER+26: return wxT("TB_SAVERESTOREA");
7094 case WM_USER+76: return wxT("TB_SAVERESTOREW");
7095 case WM_USER+27: return wxT("TB_CUSTOMIZE");
7096 case WM_USER+28: return wxT("TB_ADDSTRINGA");
7097 case WM_USER+77: return wxT("TB_ADDSTRINGW");
7098 case WM_USER+29: return wxT("TB_GETITEMRECT");
7099 case WM_USER+30: return wxT("TB_BUTTONSTRUCTSIZE");
7100 case WM_USER+31: return wxT("TB_SETBUTTONSIZE");
7101 case WM_USER+32: return wxT("TB_SETBITMAPSIZE");
7102 case WM_USER+33: return wxT("TB_AUTOSIZE");
7103 case WM_USER+35: return wxT("TB_GETTOOLTIPS");
7104 case WM_USER+36: return wxT("TB_SETTOOLTIPS");
7105 case WM_USER+37: return wxT("TB_SETPARENT");
7106 case WM_USER+39: return wxT("TB_SETROWS");
7107 case WM_USER+40: return wxT("TB_GETROWS");
7108 case WM_USER+42: return wxT("TB_SETCMDID");
7109 case WM_USER+43: return wxT("TB_CHANGEBITMAP");
7110 case WM_USER+44: return wxT("TB_GETBITMAP");
7111 case WM_USER+45: return wxT("TB_GETBUTTONTEXTA");
7112 case WM_USER+75: return wxT("TB_GETBUTTONTEXTW");
7113 case WM_USER+46: return wxT("TB_REPLACEBITMAP");
7114 case WM_USER+47: return wxT("TB_SETINDENT");
7115 case WM_USER+48: return wxT("TB_SETIMAGELIST");
7116 case WM_USER+49: return wxT("TB_GETIMAGELIST");
7117 case WM_USER+50: return wxT("TB_LOADIMAGES");
7118 case WM_USER+51: return wxT("TB_GETRECT");
7119 case WM_USER+52: return wxT("TB_SETHOTIMAGELIST");
7120 case WM_USER+53: return wxT("TB_GETHOTIMAGELIST");
7121 case WM_USER+54: return wxT("TB_SETDISABLEDIMAGELIST");
7122 case WM_USER+55: return wxT("TB_GETDISABLEDIMAGELIST");
7123 case WM_USER+56: return wxT("TB_SETSTYLE");
7124 case WM_USER+57: return wxT("TB_GETSTYLE");
7125 case WM_USER+58: return wxT("TB_GETBUTTONSIZE");
7126 case WM_USER+59: return wxT("TB_SETBUTTONWIDTH");
7127 case WM_USER+60: return wxT("TB_SETMAXTEXTROWS");
7128 case WM_USER+61: return wxT("TB_GETTEXTROWS");
7129 case WM_USER+41: return wxT("TB_GETBITMAPFLAGS");
7130
7131 default:
7132 static wxString s_szBuf;
7133 s_szBuf.Printf(wxT("<unknown message = %d>"), message);
7134 return s_szBuf.c_str();
7135 }
7136 }
7137 #endif // wxDEBUG_LEVEL >= 2
7138
7139 static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win)
7140 {
7141 // prepare the DC
7142 TEXTMETRIC tm;
7143 HWND hwnd = GetHwndOf(win);
7144 HDC hdc = ::GetDC(hwnd);
7145
7146 #if !wxDIALOG_UNIT_COMPATIBILITY
7147 // and select the current font into it
7148 HFONT hfont = GetHfontOf(win->GetFont());
7149 if ( hfont )
7150 {
7151 hfont = (HFONT)::SelectObject(hdc, hfont);
7152 }
7153 #endif
7154
7155 // finally retrieve the text metrics from it
7156 GetTextMetrics(hdc, &tm);
7157
7158 #if !wxDIALOG_UNIT_COMPATIBILITY
7159 // and clean up
7160 if ( hfont )
7161 {
7162 (void)::SelectObject(hdc, hfont);
7163 }
7164 #endif
7165
7166 ::ReleaseDC(hwnd, hdc);
7167
7168 return tm;
7169 }
7170
7171 // Find the wxWindow at the current mouse position, returning the mouse
7172 // position.
7173 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
7174 {
7175 pt = wxGetMousePosition();
7176 return wxFindWindowAtPoint(pt);
7177 }
7178
7179 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
7180 {
7181 POINT pt2;
7182 pt2.x = pt.x;
7183 pt2.y = pt.y;
7184
7185 HWND hWnd = ::WindowFromPoint(pt2);
7186
7187 return wxGetWindowFromHWND((WXHWND)hWnd);
7188 }
7189
7190 // Get the current mouse position.
7191 wxPoint wxGetMousePosition()
7192 {
7193 POINT pt;
7194 #ifdef __WXWINCE__
7195 GetCursorPosWinCE(&pt);
7196 #else
7197 GetCursorPos( & pt );
7198 #endif
7199
7200 return wxPoint(pt.x, pt.y);
7201 }
7202
7203 #if wxUSE_HOTKEY
7204
7205 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7206 static void WinCEUnregisterHotKey(int modifiers, int id)
7207 {
7208 // Register hotkeys for the hardware buttons
7209 HINSTANCE hCoreDll;
7210 typedef BOOL (WINAPI *UnregisterFunc1Proc)(UINT, UINT);
7211
7212 UnregisterFunc1Proc procUnregisterFunc;
7213 hCoreDll = LoadLibrary(wxT("coredll.dll"));
7214 if (hCoreDll)
7215 {
7216 procUnregisterFunc = (UnregisterFunc1Proc)GetProcAddress(hCoreDll, wxT("UnregisterFunc1"));
7217 if (procUnregisterFunc)
7218 procUnregisterFunc(modifiers, id);
7219 FreeLibrary(hCoreDll);
7220 }
7221 }
7222 #endif
7223
7224 bool wxWindowMSW::RegisterHotKey(int hotkeyId, int modifiers, int keycode)
7225 {
7226 UINT win_modifiers=0;
7227 if ( modifiers & wxMOD_ALT )
7228 win_modifiers |= MOD_ALT;
7229 if ( modifiers & wxMOD_SHIFT )
7230 win_modifiers |= MOD_SHIFT;
7231 if ( modifiers & wxMOD_CONTROL )
7232 win_modifiers |= MOD_CONTROL;
7233 if ( modifiers & wxMOD_WIN )
7234 win_modifiers |= MOD_WIN;
7235
7236 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7237 // Required for PPC and Smartphone hardware buttons
7238 if (keycode >= WXK_SPECIAL1 && keycode <= WXK_SPECIAL20)
7239 WinCEUnregisterHotKey(win_modifiers, hotkeyId);
7240 #endif
7241
7242 if ( !::RegisterHotKey(GetHwnd(), hotkeyId, win_modifiers, keycode) )
7243 {
7244 wxLogLastError(wxT("RegisterHotKey"));
7245
7246 return false;
7247 }
7248
7249 return true;
7250 }
7251
7252 bool wxWindowMSW::UnregisterHotKey(int hotkeyId)
7253 {
7254 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7255 WinCEUnregisterHotKey(MOD_WIN, hotkeyId);
7256 #endif
7257
7258 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId) )
7259 {
7260 wxLogLastError(wxT("UnregisterHotKey"));
7261
7262 return false;
7263 }
7264
7265 return true;
7266 }
7267
7268 #if wxUSE_ACCEL
7269
7270 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam, WXLPARAM lParam)
7271 {
7272 int win_modifiers = LOWORD(lParam);
7273
7274 wxKeyEvent event(CreateKeyEvent(wxEVT_HOTKEY, HIWORD(lParam)));
7275 event.SetId(wParam);
7276 event.m_shiftDown = (win_modifiers & MOD_SHIFT) != 0;
7277 event.m_controlDown = (win_modifiers & MOD_CONTROL) != 0;
7278 event.m_altDown = (win_modifiers & MOD_ALT) != 0;
7279 event.m_metaDown = (win_modifiers & MOD_WIN) != 0;
7280
7281 return HandleWindowEvent(event);
7282 }
7283
7284 #endif // wxUSE_ACCEL
7285
7286 #endif // wxUSE_HOTKEY
7287
7288 // Not tested under WinCE
7289 #ifndef __WXWINCE__
7290
7291 // this class installs a message hook which really wakes up our idle processing
7292 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
7293 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
7294 // being dragged or even inside ::MessageBox()) and so don't control message
7295 // dispatching otherwise
7296 class wxIdleWakeUpModule : public wxModule
7297 {
7298 public:
7299 virtual bool OnInit()
7300 {
7301 ms_hMsgHookProc = ::SetWindowsHookEx
7302 (
7303 WH_GETMESSAGE,
7304 &wxIdleWakeUpModule::MsgHookProc,
7305 NULL,
7306 GetCurrentThreadId()
7307 );
7308
7309 if ( !ms_hMsgHookProc )
7310 {
7311 wxLogLastError(wxT("SetWindowsHookEx(WH_GETMESSAGE)"));
7312
7313 return false;
7314 }
7315
7316 return true;
7317 }
7318
7319 virtual void OnExit()
7320 {
7321 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc);
7322 }
7323
7324 static LRESULT CALLBACK MsgHookProc(int nCode, WPARAM wParam, LPARAM lParam)
7325 {
7326 MSG *msg = (MSG*)lParam;
7327
7328 // only process the message if it is actually going to be removed from
7329 // the message queue, this prevents that the same event from being
7330 // processed multiple times if now someone just called PeekMessage()
7331 if ( msg->message == WM_NULL && wParam == PM_REMOVE )
7332 {
7333 wxTheApp->ProcessPendingEvents();
7334 }
7335
7336 return CallNextHookEx(ms_hMsgHookProc, nCode, wParam, lParam);
7337 }
7338
7339 private:
7340 static HHOOK ms_hMsgHookProc;
7341
7342 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule)
7343 };
7344
7345 HHOOK wxIdleWakeUpModule::ms_hMsgHookProc = 0;
7346
7347 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule, wxModule)
7348
7349 #endif // __WXWINCE__
7350
7351 #ifdef __WXWINCE__
7352
7353 #if wxUSE_STATBOX
7354 static void wxAdjustZOrder(wxWindow* parent)
7355 {
7356 if (parent->IsKindOf(CLASSINFO(wxStaticBox)))
7357 {
7358 // Set the z-order correctly
7359 SetWindowPos((HWND) parent->GetHWND(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
7360 }
7361
7362 wxWindowList::compatibility_iterator current = parent->GetChildren().GetFirst();
7363 while (current)
7364 {
7365 wxWindow *childWin = current->GetData();
7366 wxAdjustZOrder(childWin);
7367 current = current->GetNext();
7368 }
7369 }
7370 #endif
7371
7372 // We need to adjust the z-order of static boxes in WinCE, to
7373 // make 'contained' controls visible
7374 void wxWindowMSW::OnInitDialog( wxInitDialogEvent& event )
7375 {
7376 #if wxUSE_STATBOX
7377 wxAdjustZOrder(this);
7378 #endif
7379
7380 event.Skip();
7381 }
7382 #endif