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