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