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