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