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