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