Creating new revision to retag with WX_2_6_0
[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 wxCHECK_MSG( pMenuItem && pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)),
3605 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
3606
3607 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
3608 // the DC from being released
3609 wxDCTemp dc((WXHDC)pDrawStruct->hDC);
3610 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
3611 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
3612 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
3613
3614 return pMenuItem->OnDrawItem
3615 (
3616 dc,
3617 rect,
3618 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
3619 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
3620 );
3621 }
3622 #endif // wxUSE_MENUS_NATIVE
3623
3624 #endif // USE_OWNER_DRAWN
3625
3626 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
3627
3628 #if wxUSE_OWNER_DRAWN
3629 wxControl *item = wxDynamicCast(FindItem(id), wxControl);
3630 #else // !wxUSE_OWNER_DRAWN
3631 // we may still have owner-drawn buttons internally because we have to make
3632 // them owner-drawn to support colour change
3633 wxControl *item =
3634 # if wxUSE_BUTTON
3635 wxDynamicCast(FindItem(id), wxButton)
3636 # else
3637 NULL
3638 # endif
3639 ;
3640 #endif // USE_OWNER_DRAWN
3641
3642 if ( item )
3643 {
3644 return item->MSWOnDraw(itemStruct);
3645 }
3646
3647 #endif // wxUSE_CONTROLS
3648
3649 return false;
3650 }
3651
3652 bool
3653 wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
3654 {
3655 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
3656 // is it a menu item?
3657 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
3658 if ( id == 0 && pMeasureStruct->CtlType == ODT_MENU )
3659 {
3660 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
3661
3662 // according to Carsten Fuchs the pointer may be NULL under XP if an
3663 // MDI child frame is initially maximized, see this for more info:
3664 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
3665 //
3666 // so silently ignore it instead of asserting
3667 if ( !pMenuItem )
3668 return false;
3669
3670 wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem),
3671 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
3672
3673 size_t w, h;
3674 bool rc = pMenuItem->OnMeasureItem(&w, &h);
3675
3676 pMeasureStruct->itemWidth = w;
3677 pMeasureStruct->itemHeight = h;
3678
3679 return rc;
3680 }
3681
3682 wxControl *item = wxDynamicCast(FindItem(id), wxControl);
3683 if ( item )
3684 {
3685 return item->MSWOnMeasure(itemStruct);
3686 }
3687 #else
3688 wxUnusedVar(id);
3689 wxUnusedVar(itemStruct);
3690 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
3691
3692 return false;
3693 }
3694
3695 // ---------------------------------------------------------------------------
3696 // colours and palettes
3697 // ---------------------------------------------------------------------------
3698
3699 bool wxWindowMSW::HandleSysColorChange()
3700 {
3701 wxSysColourChangedEvent event;
3702 event.SetEventObject(this);
3703
3704 (void)GetEventHandler()->ProcessEvent(event);
3705
3706 // always let the system carry on the default processing to allow the
3707 // native controls to react to the colours update
3708 return false;
3709 }
3710
3711 bool wxWindowMSW::HandleDisplayChange()
3712 {
3713 wxDisplayChangedEvent event;
3714 event.SetEventObject(this);
3715
3716 return GetEventHandler()->ProcessEvent(event);
3717 }
3718
3719 #ifndef __WXMICROWIN__
3720
3721 bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush, WXHDC hDC, WXHWND hWnd)
3722 {
3723 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
3724 wxUnusedVar(hDC);
3725 wxUnusedVar(hWnd);
3726 #else
3727 wxControl *item = wxDynamicCast(FindItemByHWND(hWnd, true), wxControl);
3728
3729 if ( item )
3730 *brush = item->MSWControlColor(hDC, hWnd);
3731 else
3732 #endif // wxUSE_CONTROLS
3733 *brush = NULL;
3734
3735 return *brush != NULL;
3736 }
3737
3738 #endif // __WXMICROWIN__
3739
3740 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange)
3741 {
3742 #if wxUSE_PALETTE
3743 // same as below except we don't respond to our own messages
3744 if ( hWndPalChange != GetHWND() )
3745 {
3746 // check to see if we our our parents have a custom palette
3747 wxWindowMSW *win = this;
3748 while ( win && !win->HasCustomPalette() )
3749 {
3750 win = win->GetParent();
3751 }
3752
3753 if ( win && win->HasCustomPalette() )
3754 {
3755 // realize the palette to see whether redrawing is needed
3756 HDC hdc = ::GetDC((HWND) hWndPalChange);
3757 win->m_palette.SetHPALETTE((WXHPALETTE)
3758 ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
3759
3760 int result = ::RealizePalette(hdc);
3761
3762 // restore the palette (before releasing the DC)
3763 win->m_palette.SetHPALETTE((WXHPALETTE)
3764 ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
3765 ::RealizePalette(hdc);
3766 ::ReleaseDC((HWND) hWndPalChange, hdc);
3767
3768 // now check for the need to redraw
3769 if (result > 0)
3770 ::InvalidateRect((HWND) hWndPalChange, NULL, TRUE);
3771 }
3772
3773 }
3774 #endif // wxUSE_PALETTE
3775
3776 wxPaletteChangedEvent event(GetId());
3777 event.SetEventObject(this);
3778 event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
3779
3780 return GetEventHandler()->ProcessEvent(event);
3781 }
3782
3783 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture)
3784 {
3785 wxMouseCaptureChangedEvent event(GetId(), wxFindWinFromHandle(hWndGainedCapture));
3786 event.SetEventObject(this);
3787
3788 return GetEventHandler()->ProcessEvent(event);
3789 }
3790
3791 bool wxWindowMSW::HandleQueryNewPalette()
3792 {
3793
3794 #if wxUSE_PALETTE
3795 // check to see if we our our parents have a custom palette
3796 wxWindowMSW *win = this;
3797 while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent();
3798 if (win->HasCustomPalette()) {
3799 /* realize the palette to see whether redrawing is needed */
3800 HDC hdc = ::GetDC((HWND) GetHWND());
3801 win->m_palette.SetHPALETTE( (WXHPALETTE)
3802 ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), FALSE) );
3803
3804 int result = ::RealizePalette(hdc);
3805 /* restore the palette (before releasing the DC) */
3806 win->m_palette.SetHPALETTE( (WXHPALETTE)
3807 ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), TRUE) );
3808 ::RealizePalette(hdc);
3809 ::ReleaseDC((HWND) GetHWND(), hdc);
3810 /* now check for the need to redraw */
3811 if (result > 0)
3812 ::InvalidateRect((HWND) GetHWND(), NULL, TRUE);
3813 }
3814 #endif // wxUSE_PALETTE
3815
3816 wxQueryNewPaletteEvent event(GetId());
3817 event.SetEventObject(this);
3818
3819 return GetEventHandler()->ProcessEvent(event) && event.GetPaletteRealized();
3820 }
3821
3822 // Responds to colour changes: passes event on to children.
3823 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
3824 {
3825 // the top level window also reset the standard colour map as it might have
3826 // changed (there is no need to do it for the non top level windows as we
3827 // only have to do it once)
3828 if ( IsTopLevel() )
3829 {
3830 // FIXME-MT
3831 gs_hasStdCmap = false;
3832 }
3833 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
3834 while ( node )
3835 {
3836 // Only propagate to non-top-level windows because Windows already
3837 // sends this event to all top-level ones
3838 wxWindow *win = node->GetData();
3839 if ( !win->IsTopLevel() )
3840 {
3841 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
3842 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
3843 // the standard controls
3844 ::SendMessage(GetHwndOf(win), WM_SYSCOLORCHANGE, 0, 0);
3845 }
3846
3847 node = node->GetNext();
3848 }
3849 }
3850
3851 extern wxCOLORMAP *wxGetStdColourMap()
3852 {
3853 static COLORREF s_stdColours[wxSTD_COL_MAX];
3854 static wxCOLORMAP s_cmap[wxSTD_COL_MAX];
3855
3856 if ( !gs_hasStdCmap )
3857 {
3858 static bool s_coloursInit = false;
3859
3860 if ( !s_coloursInit )
3861 {
3862 // When a bitmap is loaded, the RGB values can change (apparently
3863 // because Windows adjusts them to care for the old programs always
3864 // using 0xc0c0c0 while the transparent colour for the new Windows
3865 // versions is different). But we do this adjustment ourselves so
3866 // we want to avoid Windows' "help" and for this we need to have a
3867 // reference bitmap which can tell us what the RGB values change
3868 // to.
3869 wxBitmap stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
3870 if ( stdColourBitmap.Ok() )
3871 {
3872 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
3873 wxASSERT_MSG( stdColourBitmap.GetWidth() == wxSTD_COL_MAX,
3874 _T("forgot to update wxBITMAP_STD_COLOURS!") );
3875
3876 wxMemoryDC memDC;
3877 memDC.SelectObject(stdColourBitmap);
3878
3879 wxColour colour;
3880 for ( size_t i = 0; i < WXSIZEOF(s_stdColours); i++ )
3881 {
3882 memDC.GetPixel(i, 0, &colour);
3883 s_stdColours[i] = wxColourToRGB(colour);
3884 }
3885 }
3886 else // wxBITMAP_STD_COLOURS couldn't be loaded
3887 {
3888 s_stdColours[0] = RGB(000,000,000); // black
3889 s_stdColours[1] = RGB(128,128,128); // dark grey
3890 s_stdColours[2] = RGB(192,192,192); // light grey
3891 s_stdColours[3] = RGB(255,255,255); // white
3892 //s_stdColours[4] = RGB(000,000,255); // blue
3893 //s_stdColours[5] = RGB(255,000,255); // magenta
3894 }
3895
3896 s_coloursInit = true;
3897 }
3898
3899 gs_hasStdCmap = true;
3900
3901 // create the colour map
3902 #define INIT_CMAP_ENTRY(col) \
3903 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
3904 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
3905
3906 INIT_CMAP_ENTRY(BTNTEXT);
3907 INIT_CMAP_ENTRY(BTNSHADOW);
3908 INIT_CMAP_ENTRY(BTNFACE);
3909 INIT_CMAP_ENTRY(BTNHIGHLIGHT);
3910
3911 #undef INIT_CMAP_ENTRY
3912 }
3913
3914 return s_cmap;
3915 }
3916
3917 // ---------------------------------------------------------------------------
3918 // painting
3919 // ---------------------------------------------------------------------------
3920
3921 bool wxWindowMSW::HandlePaint()
3922 {
3923 HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
3924 if ( !hRegion )
3925 wxLogLastError(wxT("CreateRectRgn"));
3926 if ( ::GetUpdateRgn(GetHwnd(), hRegion, FALSE) == ERROR )
3927 wxLogLastError(wxT("GetUpdateRgn"));
3928
3929 m_updateRegion = wxRegion((WXHRGN) hRegion);
3930
3931 wxPaintEvent event(m_windowId);
3932 event.SetEventObject(this);
3933
3934 bool processed = GetEventHandler()->ProcessEvent(event);
3935
3936 // note that we must generate NC event after the normal one as otherwise
3937 // BeginPaint() will happily overwrite our decorations with the background
3938 // colour
3939 wxNcPaintEvent eventNc(m_windowId);
3940 eventNc.SetEventObject(this);
3941 GetEventHandler()->ProcessEvent(eventNc);
3942
3943 return processed;
3944 }
3945
3946 // Can be called from an application's OnPaint handler
3947 void wxWindowMSW::OnPaint(wxPaintEvent& event)
3948 {
3949 #ifdef __WXUNIVERSAL__
3950 event.Skip();
3951 #else
3952 HDC hDC = (HDC) wxPaintDC::FindDCInCache((wxWindow*) event.GetEventObject());
3953 if (hDC != 0)
3954 {
3955 MSWDefWindowProc(WM_PAINT, (WPARAM) hDC, 0);
3956 }
3957 #endif
3958 }
3959
3960 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc)
3961 {
3962 wxDCTemp dc(hdc);
3963
3964 dc.SetHDC(hdc);
3965 dc.SetWindow((wxWindow *)this);
3966 dc.BeginDrawing();
3967
3968 wxEraseEvent event(m_windowId, &dc);
3969 event.SetEventObject(this);
3970 bool rc = GetEventHandler()->ProcessEvent(event);
3971
3972 dc.EndDrawing();
3973
3974 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
3975 dc.SelectOldObjects(hdc);
3976
3977 return rc;
3978 }
3979
3980 void wxWindowMSW::OnEraseBackground(wxEraseEvent& event)
3981 {
3982 // standard non top level controls (i.e. except the dialogs) always erase
3983 // their background themselves in HandleCtlColor() or have some control-
3984 // specific ways to set the colours (common controls)
3985 if ( IsOfStandardClass() && !IsTopLevel() )
3986 {
3987 event.Skip();
3988 return;
3989 }
3990
3991 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM )
3992 {
3993 // don't skip the event here, custom background means that the app
3994 // is drawing it itself in its OnPaint(), so don't draw it at all
3995 // now to avoid flicker
3996 return;
3997 }
3998
3999
4000 // do default background painting
4001 if ( !DoEraseBackground(GetHdcOf(*event.GetDC())) )
4002 {
4003 // let the system paint the background
4004 event.Skip();
4005 }
4006 }
4007
4008 bool wxWindowMSW::DoEraseBackground(WXHDC hDC)
4009 {
4010 HBRUSH hbr = (HBRUSH)MSWGetBgBrush(hDC);
4011 if ( !hbr )
4012 return false;
4013
4014 wxFillRect(GetHwnd(), (HDC)hDC, hbr);
4015
4016 return true;
4017 }
4018
4019 WXHBRUSH
4020 wxWindowMSW::MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC), WXHWND hWnd)
4021 {
4022 if ( m_hasBgCol )
4023 {
4024 // our background colour applies to:
4025 // 1. this window itself, always
4026 // 2. all children unless the colour is "not inheritable"
4027 // 3. even if it is not inheritable, our immediate transparent
4028 // children should still inherit it -- but not any transparent
4029 // children because it would look wrong if a child of non
4030 // transparent child would show our bg colour when the child itself
4031 // does not
4032 wxWindow *win = wxFindWinFromHandle(hWnd);
4033 if ( win == this ||
4034 m_inheritBgCol ||
4035 (win && win->HasTransparentBackground() &&
4036 win->GetParent() == this) )
4037 {
4038 // draw children with the same colour as the parent
4039 wxBrush *
4040 brush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour());
4041
4042 return (WXHBRUSH)GetHbrushOf(*brush);
4043 }
4044 }
4045
4046 return 0;
4047 }
4048
4049 WXHBRUSH wxWindowMSW::MSWGetBgBrush(WXHDC hDC, WXHWND hWndToPaint)
4050 {
4051 if ( !hWndToPaint )
4052 hWndToPaint = GetHWND();
4053
4054 for ( wxWindowMSW *win = this; win; win = win->GetParent() )
4055 {
4056 WXHBRUSH hBrush = win->MSWGetBgBrushForChild(hDC, hWndToPaint);
4057 if ( hBrush )
4058 return hBrush;
4059
4060 // background is not inherited beyond top level windows
4061 if ( win->IsTopLevel() )
4062 break;
4063 }
4064
4065 return 0;
4066 }
4067
4068 bool wxWindowMSW::HandlePrintClient(WXHDC hDC)
4069 {
4070 // we receive this message when DrawThemeParentBackground() is
4071 // called from def window proc of several controls under XP and we
4072 // must draw properly themed background here
4073 //
4074 // note that naively I'd expect filling the client rect with the
4075 // brush returned by MSWGetBgBrush() work -- but for some reason it
4076 // doesn't and we have to call parents MSWPrintChild() which is
4077 // supposed to call DrawThemeBackground() with appropriate params
4078 //
4079 // also note that in this case lParam == PRF_CLIENT but we're
4080 // clearly expected to paint the background and nothing else!
4081 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
4082 {
4083 if ( win->MSWPrintChild(hDC, (wxWindow *)this) )
4084 return true;
4085
4086 if ( win->IsTopLevel() || win->InheritsBackgroundColour() )
4087 break;
4088 }
4089
4090 return false;
4091 }
4092
4093 // ---------------------------------------------------------------------------
4094 // moving and resizing
4095 // ---------------------------------------------------------------------------
4096
4097 bool wxWindowMSW::HandleMinimize()
4098 {
4099 wxIconizeEvent event(m_windowId);
4100 event.SetEventObject(this);
4101
4102 return GetEventHandler()->ProcessEvent(event);
4103 }
4104
4105 bool wxWindowMSW::HandleMaximize()
4106 {
4107 wxMaximizeEvent event(m_windowId);
4108 event.SetEventObject(this);
4109
4110 return GetEventHandler()->ProcessEvent(event);
4111 }
4112
4113 bool wxWindowMSW::HandleMove(int x, int y)
4114 {
4115 wxPoint point(x,y);
4116 wxMoveEvent event(point, m_windowId);
4117 event.SetEventObject(this);
4118
4119 return GetEventHandler()->ProcessEvent(event);
4120 }
4121
4122 bool wxWindowMSW::HandleMoving(wxRect& rect)
4123 {
4124 wxMoveEvent event(rect, m_windowId);
4125 event.SetEventObject(this);
4126
4127 bool rc = GetEventHandler()->ProcessEvent(event);
4128 if (rc)
4129 rect = event.GetRect();
4130 return rc;
4131 }
4132
4133 bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam)
4134 {
4135 // when we resize this window, its children are probably going to be
4136 // repositioned as well, prepare to use DeferWindowPos() for them
4137 const int numChildren = GetChildren().GetCount();
4138 if ( numChildren > 1 )
4139 {
4140 m_hDWP = (WXHANDLE)::BeginDeferWindowPos(numChildren);
4141 if ( !m_hDWP )
4142 {
4143 wxLogLastError(_T("BeginDeferWindowPos"));
4144 }
4145 }
4146
4147 // update this window size
4148 bool processed = false;
4149 switch ( wParam )
4150 {
4151 default:
4152 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4153 // fall through nevertheless
4154
4155 case SIZE_MAXHIDE:
4156 case SIZE_MAXSHOW:
4157 // we're not interested in these messages at all
4158 break;
4159
4160 case SIZE_MINIMIZED:
4161 processed = HandleMinimize();
4162 break;
4163
4164 case SIZE_MAXIMIZED:
4165 /* processed = */ HandleMaximize();
4166 // fall through to send a normal size event as well
4167
4168 case SIZE_RESTORED:
4169 // don't use w and h parameters as they specify the client size
4170 // while according to the docs EVT_SIZE handler is supposed to
4171 // receive the total size
4172 wxSizeEvent event(GetSize(), m_windowId);
4173 event.SetEventObject(this);
4174
4175 processed = GetEventHandler()->ProcessEvent(event);
4176 }
4177
4178 // and finally change the positions of all child windows at once
4179 if ( m_hDWP )
4180 {
4181 // reset m_hDWP to NULL so that child windows don't try to use our
4182 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4183 // happen anyhow normally but who knows what weird flow of control we
4184 // may have depending on what the users EVT_SIZE handler does...)
4185 HDWP hDWP = (HDWP)m_hDWP;
4186 m_hDWP = NULL;
4187
4188 // do put all child controls in place at once
4189 if ( !::EndDeferWindowPos(hDWP) )
4190 {
4191 wxLogLastError(_T("EndDeferWindowPos"));
4192 }
4193 }
4194
4195 return processed;
4196 }
4197
4198 bool wxWindowMSW::HandleSizing(wxRect& rect)
4199 {
4200 wxSizeEvent event(rect, m_windowId);
4201 event.SetEventObject(this);
4202
4203 bool rc = GetEventHandler()->ProcessEvent(event);
4204 if (rc)
4205 rect = event.GetRect();
4206 return rc;
4207 }
4208
4209 bool wxWindowMSW::HandleGetMinMaxInfo(void *mmInfo)
4210 {
4211 #ifdef __WXWINCE__
4212 wxUnusedVar(mmInfo);
4213 return false;
4214 #else
4215 MINMAXINFO *info = (MINMAXINFO *)mmInfo;
4216
4217 bool rc = false;
4218
4219 int minWidth = GetMinWidth(),
4220 minHeight = GetMinHeight(),
4221 maxWidth = GetMaxWidth(),
4222 maxHeight = GetMaxHeight();
4223
4224 if ( minWidth != wxDefaultCoord )
4225 {
4226 info->ptMinTrackSize.x = minWidth;
4227 rc = true;
4228 }
4229
4230 if ( minHeight != wxDefaultCoord )
4231 {
4232 info->ptMinTrackSize.y = minHeight;
4233 rc = true;
4234 }
4235
4236 if ( maxWidth != wxDefaultCoord )
4237 {
4238 info->ptMaxTrackSize.x = maxWidth;
4239 rc = true;
4240 }
4241
4242 if ( maxHeight != wxDefaultCoord )
4243 {
4244 info->ptMaxTrackSize.y = maxHeight;
4245 rc = true;
4246 }
4247
4248 return rc;
4249 #endif
4250 }
4251
4252 // ---------------------------------------------------------------------------
4253 // command messages
4254 // ---------------------------------------------------------------------------
4255
4256 bool wxWindowMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
4257 {
4258 #if wxUSE_MENUS_NATIVE
4259 if ( !cmd && wxCurrentPopupMenu )
4260 {
4261 wxMenu *popupMenu = wxCurrentPopupMenu;
4262 wxCurrentPopupMenu = NULL;
4263
4264 return popupMenu->MSWCommand(cmd, id);
4265 }
4266 #endif // wxUSE_MENUS_NATIVE
4267
4268 wxWindow *win = NULL;
4269
4270 // first try to find it from HWND - this works even with the broken
4271 // programs using the same ids for different controls
4272 if ( control )
4273 {
4274 win = wxFindWinFromHandle(control);
4275 }
4276
4277 // try the id
4278 if ( !win )
4279 {
4280 // must cast to a signed type before comparing with other ids!
4281 win = FindItem((signed short)id);
4282 }
4283
4284 if ( win )
4285 {
4286 return win->MSWCommand(cmd, id);
4287 }
4288
4289 // the messages sent from the in-place edit control used by the treectrl
4290 // for label editing have id == 0, but they should _not_ be treated as menu
4291 // messages (they are EN_XXX ones, in fact) so don't translate anything
4292 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4293 if ( !control )
4294 {
4295 // If no child window, it may be an accelerator, e.g. for a popup menu
4296 // command
4297
4298 wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED);
4299 event.SetEventObject(this);
4300 event.SetId(id);
4301 event.SetInt(id);
4302
4303 return GetEventHandler()->ProcessEvent(event);
4304 }
4305 else
4306 {
4307 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4308 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4309 // notifications to its parent which we want to reflect back to
4310 // wxSpinCtrl
4311 wxSpinCtrl *spin = wxSpinCtrl::GetSpinForTextCtrl(control);
4312 if ( spin && spin->ProcessTextCommand(cmd, id) )
4313 return true;
4314 #endif // wxUSE_SPINCTRL
4315
4316 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
4317 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
4318 // notifications to its parent which we want to reflect back to
4319 // wxChoice
4320 wxChoice *choice = wxChoice::GetChoiceForListBox(control);
4321 if ( choice && choice->MSWCommand(cmd, id) )
4322 return true;
4323 #endif
4324 }
4325
4326 return false;
4327 }
4328
4329 // ---------------------------------------------------------------------------
4330 // mouse events
4331 // ---------------------------------------------------------------------------
4332
4333 void wxWindowMSW::InitMouseEvent(wxMouseEvent& event,
4334 int x, int y,
4335 WXUINT flags)
4336 {
4337 // our client coords are not quite the same as Windows ones
4338 wxPoint pt = GetClientAreaOrigin();
4339 event.m_x = x - pt.x;
4340 event.m_y = y - pt.y;
4341
4342 event.m_shiftDown = (flags & MK_SHIFT) != 0;
4343 event.m_controlDown = (flags & MK_CONTROL) != 0;
4344 event.m_leftDown = (flags & MK_LBUTTON) != 0;
4345 event.m_middleDown = (flags & MK_MBUTTON) != 0;
4346 event.m_rightDown = (flags & MK_RBUTTON) != 0;
4347 event.m_altDown = ::GetKeyState(VK_MENU) < 0;
4348
4349 #ifndef __WXWINCE__
4350 event.SetTimestamp(::GetMessageTime());
4351 #endif
4352
4353 event.SetEventObject(this);
4354 event.SetId(GetId());
4355
4356 #if wxUSE_MOUSEEVENT_HACK
4357 m_lastMouseX = x;
4358 m_lastMouseY = y;
4359 m_lastMouseEvent = event.GetEventType();
4360 #endif // wxUSE_MOUSEEVENT_HACK
4361 }
4362
4363 // Windows doesn't send the mouse events to the static controls (which are
4364 // transparent in the sense that their WM_NCHITTEST handler returns
4365 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4366 // and so we manually check if we don't have a child window under mouse and if
4367 // we do, send the event to it instead of the window Windows had sent WM_XXX
4368 // to.
4369 //
4370 // Notice that this is not done for the mouse move events because this could
4371 // (would?) be too slow, but only for clicks which means that the static texts
4372 // still don't get move, enter nor leave events.
4373 static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y) //TW:REQ:Univ
4374 {
4375 wxCHECK_MSG( x && y, win, _T("NULL pointer in FindWindowForMouseEvent") );
4376
4377 // first try to find a non transparent child: this allows us to send events
4378 // to a static text which is inside a static box, for example
4379 POINT pt = { *x, *y };
4380 HWND hwnd = GetHwndOf(win),
4381 hwndUnderMouse;
4382
4383 #ifdef __WXWINCE__
4384 hwndUnderMouse = ::ChildWindowFromPoint
4385 (
4386 hwnd,
4387 pt
4388 );
4389 #else
4390 hwndUnderMouse = ::ChildWindowFromPointEx
4391 (
4392 hwnd,
4393 pt,
4394 CWP_SKIPINVISIBLE |
4395 CWP_SKIPDISABLED |
4396 CWP_SKIPTRANSPARENT
4397 );
4398 #endif
4399
4400 if ( !hwndUnderMouse || hwndUnderMouse == hwnd )
4401 {
4402 // now try any child window at all
4403 hwndUnderMouse = ::ChildWindowFromPoint(hwnd, pt);
4404 }
4405
4406 // check that we have a child window which is susceptible to receive mouse
4407 // events: for this it must be shown and enabled
4408 if ( hwndUnderMouse &&
4409 hwndUnderMouse != hwnd &&
4410 ::IsWindowVisible(hwndUnderMouse) &&
4411 ::IsWindowEnabled(hwndUnderMouse) )
4412 {
4413 wxWindow *winUnderMouse = wxFindWinFromHandle((WXHWND)hwndUnderMouse);
4414 if ( winUnderMouse )
4415 {
4416 // translate the mouse coords to the other window coords
4417 win->ClientToScreen(x, y);
4418 winUnderMouse->ScreenToClient(x, y);
4419
4420 win = winUnderMouse;
4421 }
4422 }
4423
4424 return win;
4425 }
4426
4427 bool wxWindowMSW::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags)
4428 {
4429 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4430 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
4431 // from the message id and take the value in the table to get wxWin event
4432 // id
4433 static const wxEventType eventsMouse[] =
4434 {
4435 wxEVT_MOTION,
4436 wxEVT_LEFT_DOWN,
4437 wxEVT_LEFT_UP,
4438 wxEVT_LEFT_DCLICK,
4439 wxEVT_RIGHT_DOWN,
4440 wxEVT_RIGHT_UP,
4441 wxEVT_RIGHT_DCLICK,
4442 wxEVT_MIDDLE_DOWN,
4443 wxEVT_MIDDLE_UP,
4444 wxEVT_MIDDLE_DCLICK
4445 };
4446
4447 wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]);
4448 InitMouseEvent(event, x, y, flags);
4449
4450 return GetEventHandler()->ProcessEvent(event);
4451 }
4452
4453 bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags)
4454 {
4455 if ( !m_mouseInWindow )
4456 {
4457 // it would be wrong to assume that just because we get a mouse move
4458 // event that the mouse is inside the window: although this is usually
4459 // true, it is not if we had captured the mouse, so we need to check
4460 // the mouse coordinates here
4461 if ( !HasCapture() || IsMouseInWindow() )
4462 {
4463 // Generate an ENTER event
4464 m_mouseInWindow = true;
4465
4466 #ifdef HAVE_TRACKMOUSEEVENT
4467 WinStruct<TRACKMOUSEEVENT> trackinfo;
4468
4469 trackinfo.dwFlags = TME_LEAVE;
4470 trackinfo.hwndTrack = GetHwnd();
4471
4472 // Use the commctrl.h _TrackMouseEvent(), which will call the real
4473 // TrackMouseEvent() if available or emulate it
4474 _TrackMouseEvent(&trackinfo);
4475 #endif // HAVE_TRACKMOUSEEVENT
4476
4477 wxMouseEvent event(wxEVT_ENTER_WINDOW);
4478 InitMouseEvent(event, x, y, flags);
4479
4480 (void)GetEventHandler()->ProcessEvent(event);
4481 }
4482 }
4483
4484 #if wxUSE_MOUSEEVENT_HACK
4485 // Window gets a click down message followed by a mouse move message even
4486 // if position isn't changed! We want to discard the trailing move event
4487 // if x and y are the same.
4488 if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN ||
4489 m_lastMouseEvent == wxEVT_LEFT_DOWN ||
4490 m_lastMouseEvent == wxEVT_MIDDLE_DOWN) &&
4491 (m_lastMouseX == x && m_lastMouseY == y) )
4492 {
4493 m_lastMouseEvent = wxEVT_MOTION;
4494
4495 return false;
4496 }
4497 #endif // wxUSE_MOUSEEVENT_HACK
4498
4499 return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags);
4500 }
4501
4502
4503 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam)
4504 {
4505 #if wxUSE_MOUSEWHEEL
4506 wxMouseEvent event(wxEVT_MOUSEWHEEL);
4507 InitMouseEvent(event,
4508 GET_X_LPARAM(lParam),
4509 GET_Y_LPARAM(lParam),
4510 LOWORD(wParam));
4511 event.m_wheelRotation = (short)HIWORD(wParam);
4512 event.m_wheelDelta = WHEEL_DELTA;
4513
4514 static int s_linesPerRotation = -1;
4515 if ( s_linesPerRotation == -1 )
4516 {
4517 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
4518 &s_linesPerRotation, 0))
4519 {
4520 // this is not supposed to happen
4521 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
4522
4523 // the default is 3, so use it if SystemParametersInfo() failed
4524 s_linesPerRotation = 3;
4525 }
4526 }
4527
4528 event.m_linesPerAction = s_linesPerRotation;
4529 return GetEventHandler()->ProcessEvent(event);
4530
4531 #else // !wxUSE_MOUSEWHEEL
4532 wxUnusedVar(wParam);
4533 wxUnusedVar(lParam);
4534
4535 return false;
4536 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
4537 }
4538
4539 void wxWindowMSW::GenerateMouseLeave()
4540 {
4541 m_mouseInWindow = false;
4542
4543 int state = 0;
4544 if ( wxIsShiftDown() )
4545 state |= MK_SHIFT;
4546 if ( wxIsCtrlDown() )
4547 state |= MK_CONTROL;
4548
4549 // Only the high-order bit should be tested
4550 if ( GetKeyState( VK_LBUTTON ) & (1<<15) )
4551 state |= MK_LBUTTON;
4552 if ( GetKeyState( VK_MBUTTON ) & (1<<15) )
4553 state |= MK_MBUTTON;
4554 if ( GetKeyState( VK_RBUTTON ) & (1<<15) )
4555 state |= MK_RBUTTON;
4556
4557 POINT pt;
4558 #ifdef __WXWINCE__
4559 if ( !::GetCursorPosWinCE(&pt) )
4560 #else
4561 if ( !::GetCursorPos(&pt) )
4562 #endif
4563 {
4564 wxLogLastError(_T("GetCursorPos"));
4565 }
4566
4567 // we need to have client coordinates here for symmetry with
4568 // wxEVT_ENTER_WINDOW
4569 RECT rect = wxGetWindowRect(GetHwnd());
4570 pt.x -= rect.left;
4571 pt.y -= rect.top;
4572
4573 wxMouseEvent event(wxEVT_LEAVE_WINDOW);
4574 InitMouseEvent(event, pt.x, pt.y, state);
4575
4576 (void)GetEventHandler()->ProcessEvent(event);
4577 }
4578
4579 // ---------------------------------------------------------------------------
4580 // keyboard handling
4581 // ---------------------------------------------------------------------------
4582
4583 // create the key event of the given type for the given key - used by
4584 // HandleChar and HandleKeyDown/Up
4585 wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType,
4586 int id,
4587 WXLPARAM lParam,
4588 WXWPARAM wParam) const
4589 {
4590 wxKeyEvent event(evType);
4591 event.SetId(GetId());
4592 event.m_shiftDown = wxIsShiftDown();
4593 event.m_controlDown = wxIsCtrlDown();
4594 event.m_altDown = (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN;
4595
4596 event.SetEventObject((wxWindow *)this); // const_cast
4597 event.m_keyCode = id;
4598 #if wxUSE_UNICODE
4599 event.m_uniChar = (wxChar) wParam;
4600 #endif
4601 event.m_rawCode = (wxUint32) wParam;
4602 event.m_rawFlags = (wxUint32) lParam;
4603 #ifndef __WXWINCE__
4604 event.SetTimestamp(::GetMessageTime());
4605 #endif
4606
4607 // translate the position to client coords
4608 POINT pt;
4609 #ifdef __WXWINCE__
4610 GetCursorPosWinCE(&pt);
4611 #else
4612 GetCursorPos(&pt);
4613 #endif
4614 RECT rect;
4615 GetWindowRect(GetHwnd(),&rect);
4616 pt.x -= rect.left;
4617 pt.y -= rect.top;
4618
4619 event.m_x = pt.x;
4620 event.m_y = pt.y;
4621
4622 return event;
4623 }
4624
4625 // isASCII is true only when we're called from WM_CHAR handler and not from
4626 // WM_KEYDOWN one
4627 bool wxWindowMSW::HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII)
4628 {
4629 int id;
4630 if ( isASCII )
4631 {
4632 // If 1 -> 26, translate to either special keycode or just set
4633 // ctrlDown. IOW, Ctrl-C should result in keycode == 3 and
4634 // ControlDown() == true.
4635 id = wParam;
4636 if ( (id > 0) && (id < 27) )
4637 {
4638 switch (id)
4639 {
4640 case 13:
4641 id = WXK_RETURN;
4642 break;
4643
4644 case 8:
4645 id = WXK_BACK;
4646 break;
4647
4648 case 9:
4649 id = WXK_TAB;
4650 break;
4651
4652 default:
4653 //ctrlDown = true;
4654 break;
4655 }
4656 }
4657 }
4658 else // we're called from WM_KEYDOWN
4659 {
4660 id = wxCharCodeMSWToWX(wParam, lParam);
4661 if ( id == 0 )
4662 {
4663 // it's ASCII and will be processed here only when called from
4664 // WM_CHAR (i.e. when isASCII = true), don't process it now
4665 return false;
4666 }
4667 }
4668
4669 wxKeyEvent event(CreateKeyEvent(wxEVT_CHAR, id, lParam, wParam));
4670
4671 // the alphanumeric keys produced by pressing AltGr+something on European
4672 // keyboards have both Ctrl and Alt modifiers which may confuse the user
4673 // code as, normally, keys with Ctrl and/or Alt don't result in anything
4674 // alphanumeric, so pretend that there are no modifiers at all (the
4675 // KEY_DOWN event would still have the correct modifiers if they're really
4676 // needed)
4677 if ( event.m_controlDown && event.m_altDown &&
4678 (id >= 32 && id < 256) )
4679 {
4680 event.m_controlDown =
4681 event.m_altDown = false;
4682 }
4683
4684 return GetEventHandler()->ProcessEvent(event);
4685 }
4686
4687 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam)
4688 {
4689 int id = wxCharCodeMSWToWX(wParam, lParam);
4690
4691 if ( !id )
4692 {
4693 // normal ASCII char
4694 id = wParam;
4695 }
4696
4697 if ( id != -1 ) // VZ: does this ever happen (FIXME)?
4698 {
4699 wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, id, lParam, wParam));
4700 if ( GetEventHandler()->ProcessEvent(event) )
4701 {
4702 return true;
4703 }
4704 }
4705
4706 return false;
4707 }
4708
4709 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam)
4710 {
4711 int id = wxCharCodeMSWToWX(wParam, lParam);
4712
4713 if ( !id )
4714 {
4715 // normal ASCII char
4716 id = wParam;
4717 }
4718
4719 if ( id != -1 ) // VZ: does this ever happen (FIXME)?
4720 {
4721 wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_UP, id, lParam, wParam));
4722 if ( GetEventHandler()->ProcessEvent(event) )
4723 return true;
4724 }
4725
4726 return false;
4727 }
4728
4729 int wxWindowMSW::HandleMenuChar(int chAccel, WXLPARAM lParam)
4730 {
4731 // FIXME: implement GetMenuItemCount for WinCE, possibly
4732 // in terms of GetMenuItemInfo
4733 #ifndef __WXWINCE__
4734 const HMENU hmenu = (HMENU)lParam;
4735
4736 MENUITEMINFO mii;
4737 wxZeroMemory(mii);
4738 mii.cbSize = sizeof(MENUITEMINFO);
4739 mii.fMask = MIIM_TYPE | MIIM_DATA;
4740
4741 // find if we have this letter in any owner drawn item
4742 const int count = ::GetMenuItemCount(hmenu);
4743 for ( int i = 0; i < count; i++ )
4744 {
4745 if ( ::GetMenuItemInfo(hmenu, i, TRUE, &mii) )
4746 {
4747 if ( mii.fType == MFT_OWNERDRAW )
4748 {
4749 // dwItemData member of the MENUITEMINFO is a
4750 // pointer to the associated wxMenuItem -- see the
4751 // menu creation code
4752 wxMenuItem *item = (wxMenuItem*)mii.dwItemData;
4753
4754 const wxChar *p = wxStrchr(item->GetText(), _T('&'));
4755 while ( p++ )
4756 {
4757 if ( *p == _T('&') )
4758 {
4759 // this is not the accel char, find the real one
4760 p = wxStrchr(p + 1, _T('&'));
4761 }
4762 else // got the accel char
4763 {
4764 // FIXME-UNICODE: this comparison doesn't risk to work
4765 // for non ASCII accelerator characters I'm afraid, but
4766 // what can we do?
4767 if ( (wchar_t)wxToupper(*p) == (wchar_t)chAccel )
4768 {
4769 return i;
4770 }
4771 else
4772 {
4773 // this one doesn't match
4774 break;
4775 }
4776 }
4777 }
4778 }
4779 }
4780 else // failed to get the menu text?
4781 {
4782 // it's not fatal, so don't show error, but still log
4783 // it
4784 wxLogLastError(_T("GetMenuItemInfo"));
4785 }
4786 }
4787 #else
4788 wxUnusedVar(chAccel);
4789 wxUnusedVar(lParam);
4790 #endif
4791 return wxNOT_FOUND;
4792 }
4793
4794 // ---------------------------------------------------------------------------
4795 // joystick
4796 // ---------------------------------------------------------------------------
4797
4798 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
4799 {
4800 #ifdef JOY_BUTTON1
4801 int change = 0;
4802 if ( flags & JOY_BUTTON1CHG )
4803 change = wxJOY_BUTTON1;
4804 if ( flags & JOY_BUTTON2CHG )
4805 change = wxJOY_BUTTON2;
4806 if ( flags & JOY_BUTTON3CHG )
4807 change = wxJOY_BUTTON3;
4808 if ( flags & JOY_BUTTON4CHG )
4809 change = wxJOY_BUTTON4;
4810
4811 int buttons = 0;
4812 if ( flags & JOY_BUTTON1 )
4813 buttons |= wxJOY_BUTTON1;
4814 if ( flags & JOY_BUTTON2 )
4815 buttons |= wxJOY_BUTTON2;
4816 if ( flags & JOY_BUTTON3 )
4817 buttons |= wxJOY_BUTTON3;
4818 if ( flags & JOY_BUTTON4 )
4819 buttons |= wxJOY_BUTTON4;
4820
4821 // the event ids aren't consecutive so we can't use table based lookup
4822 int joystick;
4823 wxEventType eventType;
4824 switch ( msg )
4825 {
4826 case MM_JOY1MOVE:
4827 joystick = 1;
4828 eventType = wxEVT_JOY_MOVE;
4829 break;
4830
4831 case MM_JOY2MOVE:
4832 joystick = 2;
4833 eventType = wxEVT_JOY_MOVE;
4834 break;
4835
4836 case MM_JOY1ZMOVE:
4837 joystick = 1;
4838 eventType = wxEVT_JOY_ZMOVE;
4839 break;
4840
4841 case MM_JOY2ZMOVE:
4842 joystick = 2;
4843 eventType = wxEVT_JOY_ZMOVE;
4844 break;
4845
4846 case MM_JOY1BUTTONDOWN:
4847 joystick = 1;
4848 eventType = wxEVT_JOY_BUTTON_DOWN;
4849 break;
4850
4851 case MM_JOY2BUTTONDOWN:
4852 joystick = 2;
4853 eventType = wxEVT_JOY_BUTTON_DOWN;
4854 break;
4855
4856 case MM_JOY1BUTTONUP:
4857 joystick = 1;
4858 eventType = wxEVT_JOY_BUTTON_UP;
4859 break;
4860
4861 case MM_JOY2BUTTONUP:
4862 joystick = 2;
4863 eventType = wxEVT_JOY_BUTTON_UP;
4864 break;
4865
4866 default:
4867 wxFAIL_MSG(wxT("no such joystick event"));
4868
4869 return false;
4870 }
4871
4872 wxJoystickEvent event(eventType, buttons, joystick, change);
4873 event.SetPosition(wxPoint(x, y));
4874 event.SetEventObject(this);
4875
4876 return GetEventHandler()->ProcessEvent(event);
4877 #else
4878 wxUnusedVar(msg);
4879 wxUnusedVar(x);
4880 wxUnusedVar(y);
4881 wxUnusedVar(flags);
4882 return false;
4883 #endif
4884 }
4885
4886 // ---------------------------------------------------------------------------
4887 // scrolling
4888 // ---------------------------------------------------------------------------
4889
4890 bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam,
4891 WXWORD pos, WXHWND control)
4892 {
4893 if ( control && control != m_hWnd ) // Prevent infinite recursion
4894 {
4895 wxWindow *child = wxFindWinFromHandle(control);
4896 if ( child )
4897 return child->MSWOnScroll(orientation, wParam, pos, control);
4898 }
4899
4900 wxScrollWinEvent event;
4901 event.SetPosition(pos);
4902 event.SetOrientation(orientation);
4903 event.SetEventObject(this);
4904
4905 switch ( wParam )
4906 {
4907 case SB_TOP:
4908 event.SetEventType(wxEVT_SCROLLWIN_TOP);
4909 break;
4910
4911 case SB_BOTTOM:
4912 event.SetEventType(wxEVT_SCROLLWIN_BOTTOM);
4913 break;
4914
4915 case SB_LINEUP:
4916 event.SetEventType(wxEVT_SCROLLWIN_LINEUP);
4917 break;
4918
4919 case SB_LINEDOWN:
4920 event.SetEventType(wxEVT_SCROLLWIN_LINEDOWN);
4921 break;
4922
4923 case SB_PAGEUP:
4924 event.SetEventType(wxEVT_SCROLLWIN_PAGEUP);
4925 break;
4926
4927 case SB_PAGEDOWN:
4928 event.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN);
4929 break;
4930
4931 case SB_THUMBPOSITION:
4932 case SB_THUMBTRACK:
4933 // under Win32, the scrollbar range and position are 32 bit integers,
4934 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
4935 // explicitly query the scrollbar for the correct position (this must
4936 // be done only for these two SB_ events as they are the only one
4937 // carrying the scrollbar position)
4938 {
4939 WinStruct<SCROLLINFO> scrollInfo;
4940 scrollInfo.fMask = SIF_TRACKPOS;
4941
4942 if ( !::GetScrollInfo(GetHwnd(),
4943 orientation == wxHORIZONTAL ? SB_HORZ
4944 : SB_VERT,
4945 &scrollInfo) )
4946 {
4947 // Not neccessarily an error, if there are no scrollbars yet.
4948 // wxLogLastError(_T("GetScrollInfo"));
4949 }
4950
4951 event.SetPosition(scrollInfo.nTrackPos);
4952 }
4953
4954 event.SetEventType( wParam == SB_THUMBPOSITION
4955 ? wxEVT_SCROLLWIN_THUMBRELEASE
4956 : wxEVT_SCROLLWIN_THUMBTRACK );
4957 break;
4958
4959 default:
4960 return false;
4961 }
4962
4963 return GetEventHandler()->ProcessEvent(event);
4964 }
4965
4966 // ===========================================================================
4967 // global functions
4968 // ===========================================================================
4969
4970 void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font)
4971 {
4972 TEXTMETRIC tm;
4973 HDC dc = ::GetDC((HWND) wnd);
4974 HFONT was = 0;
4975
4976 // the_font.UseResource();
4977 // the_font.RealizeResource();
4978 HFONT fnt = (HFONT)the_font.GetResourceHandle(); // const_cast
4979 if ( fnt )
4980 was = (HFONT) SelectObject(dc,fnt);
4981
4982 GetTextMetrics(dc, &tm);
4983 if ( fnt && was )
4984 {
4985 SelectObject(dc,was);
4986 }
4987 ReleaseDC((HWND)wnd, dc);
4988
4989 if ( x )
4990 *x = tm.tmAveCharWidth;
4991 if ( y )
4992 *y = tm.tmHeight + tm.tmExternalLeading;
4993
4994 // the_font.ReleaseResource();
4995 }
4996
4997 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
4998 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
4999 int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam)
5000 {
5001 int id;
5002 switch (keySym)
5003 {
5004 case VK_CANCEL: id = WXK_CANCEL; break;
5005 case VK_BACK: id = WXK_BACK; break;
5006 case VK_TAB: id = WXK_TAB; break;
5007 case VK_CLEAR: id = WXK_CLEAR; break;
5008 case VK_SHIFT: id = WXK_SHIFT; break;
5009 case VK_CONTROL: id = WXK_CONTROL; break;
5010 case VK_MENU : id = WXK_ALT; break;
5011 case VK_PAUSE: id = WXK_PAUSE; break;
5012 case VK_CAPITAL: id = WXK_CAPITAL; break;
5013 case VK_SPACE: id = WXK_SPACE; break;
5014 case VK_ESCAPE: id = WXK_ESCAPE; break;
5015 case VK_PRIOR: id = WXK_PRIOR; break;
5016 case VK_NEXT : id = WXK_NEXT; break;
5017 case VK_END: id = WXK_END; break;
5018 case VK_HOME : id = WXK_HOME; break;
5019 case VK_LEFT : id = WXK_LEFT; break;
5020 case VK_UP: id = WXK_UP; break;
5021 case VK_RIGHT: id = WXK_RIGHT; break;
5022 case VK_DOWN : id = WXK_DOWN; break;
5023 case VK_SELECT: id = WXK_SELECT; break;
5024 case VK_PRINT: id = WXK_PRINT; break;
5025 case VK_EXECUTE: id = WXK_EXECUTE; break;
5026 case VK_INSERT: id = WXK_INSERT; break;
5027 case VK_DELETE: id = WXK_DELETE; break;
5028 case VK_HELP : id = WXK_HELP; break;
5029 case VK_NUMPAD0: id = WXK_NUMPAD0; break;
5030 case VK_NUMPAD1: id = WXK_NUMPAD1; break;
5031 case VK_NUMPAD2: id = WXK_NUMPAD2; break;
5032 case VK_NUMPAD3: id = WXK_NUMPAD3; break;
5033 case VK_NUMPAD4: id = WXK_NUMPAD4; break;
5034 case VK_NUMPAD5: id = WXK_NUMPAD5; break;
5035 case VK_NUMPAD6: id = WXK_NUMPAD6; break;
5036 case VK_NUMPAD7: id = WXK_NUMPAD7; break;
5037 case VK_NUMPAD8: id = WXK_NUMPAD8; break;
5038 case VK_NUMPAD9: id = WXK_NUMPAD9; break;
5039 case VK_MULTIPLY: id = WXK_NUMPAD_MULTIPLY; break;
5040 case VK_ADD: id = WXK_NUMPAD_ADD; break;
5041 case VK_SUBTRACT: id = WXK_NUMPAD_SUBTRACT; break;
5042 case VK_DECIMAL: id = WXK_NUMPAD_DECIMAL; break;
5043 case VK_DIVIDE: id = WXK_NUMPAD_DIVIDE; break;
5044 case VK_F1: id = WXK_F1; break;
5045 case VK_F2: id = WXK_F2; break;
5046 case VK_F3: id = WXK_F3; break;
5047 case VK_F4: id = WXK_F4; break;
5048 case VK_F5: id = WXK_F5; break;
5049 case VK_F6: id = WXK_F6; break;
5050 case VK_F7: id = WXK_F7; break;
5051 case VK_F8: id = WXK_F8; break;
5052 case VK_F9: id = WXK_F9; break;
5053 case VK_F10: id = WXK_F10; break;
5054 case VK_F11: id = WXK_F11; break;
5055 case VK_F12: id = WXK_F12; break;
5056 case VK_F13: id = WXK_F13; break;
5057 case VK_F14: id = WXK_F14; break;
5058 case VK_F15: id = WXK_F15; break;
5059 case VK_F16: id = WXK_F16; break;
5060 case VK_F17: id = WXK_F17; break;
5061 case VK_F18: id = WXK_F18; break;
5062 case VK_F19: id = WXK_F19; break;
5063 case VK_F20: id = WXK_F20; break;
5064 case VK_F21: id = WXK_F21; break;
5065 case VK_F22: id = WXK_F22; break;
5066 case VK_F23: id = WXK_F23; break;
5067 case VK_F24: id = WXK_F24; break;
5068 case VK_NUMLOCK: id = WXK_NUMLOCK; break;
5069 case VK_SCROLL: id = WXK_SCROLL; break;
5070
5071 // the mapping for these keys may be incorrect on non-US keyboards so
5072 // maybe we shouldn't map them to ASCII values at all
5073 case VK_OEM_1: id = ';'; break;
5074 case VK_OEM_PLUS: id = '+'; break;
5075 case VK_OEM_COMMA: id = ','; break;
5076 case VK_OEM_MINUS: id = '-'; break;
5077 case VK_OEM_PERIOD: id = '.'; break;
5078 case VK_OEM_2: id = '/'; break;
5079 case VK_OEM_3: id = '~'; break;
5080 case VK_OEM_4: id = '['; break;
5081 case VK_OEM_5: id = '\\'; break;
5082 case VK_OEM_6: id = ']'; break;
5083 case VK_OEM_7: id = '\''; break;
5084
5085 #ifdef VK_APPS
5086 case VK_LWIN: id = WXK_WINDOWS_LEFT; break;
5087 case VK_RWIN: id = WXK_WINDOWS_RIGHT; break;
5088 case VK_APPS: id = WXK_WINDOWS_MENU; break;
5089 #endif // VK_APPS defined
5090
5091 case VK_RETURN:
5092 // the same key is sent for both the "return" key on the main
5093 // keyboard and the numeric keypad but we want to distinguish
5094 // between them: we do this using the "extended" bit (24) of lParam
5095 id = lParam & (1 << 24) ? WXK_NUMPAD_ENTER : WXK_RETURN;
5096 break;
5097
5098 default:
5099 id = 0;
5100 }
5101
5102 return id;
5103 }
5104
5105 WXWORD wxCharCodeWXToMSW(int id, bool *isVirtual)
5106 {
5107 *isVirtual = true;
5108 WXWORD keySym;
5109 switch (id)
5110 {
5111 case WXK_CANCEL: keySym = VK_CANCEL; break;
5112 case WXK_CLEAR: keySym = VK_CLEAR; break;
5113 case WXK_SHIFT: keySym = VK_SHIFT; break;
5114 case WXK_CONTROL: keySym = VK_CONTROL; break;
5115 case WXK_ALT: keySym = VK_MENU; break;
5116 case WXK_PAUSE: keySym = VK_PAUSE; break;
5117 case WXK_CAPITAL: keySym = VK_CAPITAL; break;
5118 case WXK_PRIOR: keySym = VK_PRIOR; break;
5119 case WXK_NEXT : keySym = VK_NEXT; break;
5120 case WXK_END: keySym = VK_END; break;
5121 case WXK_HOME : keySym = VK_HOME; break;
5122 case WXK_LEFT : keySym = VK_LEFT; break;
5123 case WXK_UP: keySym = VK_UP; break;
5124 case WXK_RIGHT: keySym = VK_RIGHT; break;
5125 case WXK_DOWN : keySym = VK_DOWN; break;
5126 case WXK_SELECT: keySym = VK_SELECT; break;
5127 case WXK_PRINT: keySym = VK_PRINT; break;
5128 case WXK_EXECUTE: keySym = VK_EXECUTE; break;
5129 case WXK_INSERT: keySym = VK_INSERT; break;
5130 case WXK_DELETE: keySym = VK_DELETE; break;
5131 case WXK_HELP : keySym = VK_HELP; break;
5132 case WXK_NUMPAD0: keySym = VK_NUMPAD0; break;
5133 case WXK_NUMPAD1: keySym = VK_NUMPAD1; break;
5134 case WXK_NUMPAD2: keySym = VK_NUMPAD2; break;
5135 case WXK_NUMPAD3: keySym = VK_NUMPAD3; break;
5136 case WXK_NUMPAD4: keySym = VK_NUMPAD4; break;
5137 case WXK_NUMPAD5: keySym = VK_NUMPAD5; break;
5138 case WXK_NUMPAD6: keySym = VK_NUMPAD6; break;
5139 case WXK_NUMPAD7: keySym = VK_NUMPAD7; break;
5140 case WXK_NUMPAD8: keySym = VK_NUMPAD8; break;
5141 case WXK_NUMPAD9: keySym = VK_NUMPAD9; break;
5142 case WXK_NUMPAD_MULTIPLY: keySym = VK_MULTIPLY; break;
5143 case WXK_NUMPAD_ADD: keySym = VK_ADD; break;
5144 case WXK_NUMPAD_SUBTRACT: keySym = VK_SUBTRACT; break;
5145 case WXK_NUMPAD_DECIMAL: keySym = VK_DECIMAL; break;
5146 case WXK_NUMPAD_DIVIDE: keySym = VK_DIVIDE; break;
5147 case WXK_F1: keySym = VK_F1; break;
5148 case WXK_F2: keySym = VK_F2; break;
5149 case WXK_F3: keySym = VK_F3; break;
5150 case WXK_F4: keySym = VK_F4; break;
5151 case WXK_F5: keySym = VK_F5; break;
5152 case WXK_F6: keySym = VK_F6; break;
5153 case WXK_F7: keySym = VK_F7; break;
5154 case WXK_F8: keySym = VK_F8; break;
5155 case WXK_F9: keySym = VK_F9; break;
5156 case WXK_F10: keySym = VK_F10; break;
5157 case WXK_F11: keySym = VK_F11; break;
5158 case WXK_F12: keySym = VK_F12; break;
5159 case WXK_F13: keySym = VK_F13; break;
5160 case WXK_F14: keySym = VK_F14; break;
5161 case WXK_F15: keySym = VK_F15; break;
5162 case WXK_F16: keySym = VK_F16; break;
5163 case WXK_F17: keySym = VK_F17; break;
5164 case WXK_F18: keySym = VK_F18; break;
5165 case WXK_F19: keySym = VK_F19; break;
5166 case WXK_F20: keySym = VK_F20; break;
5167 case WXK_F21: keySym = VK_F21; break;
5168 case WXK_F22: keySym = VK_F22; break;
5169 case WXK_F23: keySym = VK_F23; break;
5170 case WXK_F24: keySym = VK_F24; break;
5171 case WXK_NUMLOCK: keySym = VK_NUMLOCK; break;
5172 case WXK_SCROLL: keySym = VK_SCROLL; break;
5173 default:
5174 {
5175 *isVirtual = false;
5176 keySym = (WORD)id;
5177 break;
5178 }
5179 }
5180 return keySym;
5181 }
5182
5183 bool wxGetKeyState(wxKeyCode key)
5184 {
5185 bool bVirtual;
5186
5187 wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key !=
5188 WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons"));
5189
5190 //High order with GetAsyncKeyState only available on WIN32
5191 #ifdef __WIN32__
5192 //If the requested key is a LED key, return
5193 //true if the led is pressed
5194 if (key == WXK_NUMLOCK ||
5195 key == WXK_CAPITAL ||
5196 key == WXK_SCROLL)
5197 {
5198 #endif
5199 //low order bit means LED is highlighted,
5200 //high order means key is down
5201 //Here, for compat with other ports we want both
5202 return GetKeyState( wxCharCodeWXToMSW(key, &bVirtual) ) != 0;
5203
5204 #ifdef __WIN32__
5205 }
5206 else
5207 {
5208 //normal key
5209 //low order bit means key pressed since last call
5210 //high order means key is down
5211 //We want only the high order bit - the key may not be down if only low order
5212 return ( GetAsyncKeyState( wxCharCodeWXToMSW(key, &bVirtual) ) & (1<<15) ) != 0;
5213 }
5214 #endif
5215 }
5216
5217 wxWindow *wxGetActiveWindow()
5218 {
5219 HWND hWnd = GetActiveWindow();
5220 if ( hWnd != 0 )
5221 {
5222 return wxFindWinFromHandle((WXHWND) hWnd);
5223 }
5224 return NULL;
5225 }
5226
5227 extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
5228 {
5229 HWND hwnd = (HWND)hWnd;
5230
5231 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
5232 // by code in msw/radiobox.cpp), for all the others we just search up the
5233 // window hierarchy
5234 wxWindow *win = (wxWindow *)NULL;
5235 if ( hwnd )
5236 {
5237 win = wxFindWinFromHandle((WXHWND)hwnd);
5238 if ( !win )
5239 {
5240 #if wxUSE_RADIOBOX
5241 // native radiobuttons return DLGC_RADIOBUTTON here and for any
5242 // wxWindow class which overrides WM_GETDLGCODE processing to
5243 // do it as well, win would be already non NULL
5244 if ( ::SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_RADIOBUTTON )
5245 {
5246 win = (wxWindow *)wxGetWindowUserData(hwnd);
5247 }
5248 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
5249 #endif // wxUSE_RADIOBOX
5250
5251 // spin control text buddy window should be mapped to spin ctrl
5252 // itself so try it too
5253 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5254 if ( !win )
5255 {
5256 win = wxSpinCtrl::GetSpinForTextCtrl((WXHWND)hwnd);
5257 }
5258 #endif // wxUSE_SPINCTRL
5259 }
5260 }
5261
5262 while ( hwnd && !win )
5263 {
5264 // this is a really ugly hack needed to avoid mistakenly returning the
5265 // parent frame wxWindow for the find/replace modeless dialog HWND -
5266 // this, in turn, is needed to call IsDialogMessage() from
5267 // wxApp::ProcessMessage() as for this we must return NULL from here
5268 //
5269 // FIXME: this is clearly not the best way to do it but I think we'll
5270 // need to change HWND <-> wxWindow code more heavily than I can
5271 // do it now to fix it
5272 #ifndef __WXMICROWIN__
5273 if ( ::GetWindow(hwnd, GW_OWNER) )
5274 {
5275 // it's a dialog box, don't go upwards
5276 break;
5277 }
5278 #endif
5279
5280 hwnd = ::GetParent(hwnd);
5281 win = wxFindWinFromHandle((WXHWND)hwnd);
5282 }
5283
5284 return win;
5285 }
5286
5287 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
5288
5289 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
5290 // in active frames and dialogs, regardless of where the focus is.
5291 static HHOOK wxTheKeyboardHook = 0;
5292 static FARPROC wxTheKeyboardHookProc = 0;
5293 int APIENTRY _EXPORT
5294 wxKeyboardHook(int nCode, WORD wParam, DWORD lParam);
5295
5296 void wxSetKeyboardHook(bool doIt)
5297 {
5298 if ( doIt )
5299 {
5300 wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance());
5301 wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
5302
5303 GetCurrentThreadId()
5304 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
5305 );
5306 }
5307 else
5308 {
5309 UnhookWindowsHookEx(wxTheKeyboardHook);
5310 }
5311 }
5312
5313 int APIENTRY _EXPORT
5314 wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
5315 {
5316 DWORD hiWord = HIWORD(lParam);
5317 if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) )
5318 {
5319 int id = wxCharCodeMSWToWX(wParam, lParam);
5320 if ( id != 0 )
5321 {
5322 wxKeyEvent event(wxEVT_CHAR_HOOK);
5323 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
5324 event.m_altDown = true;
5325
5326 event.SetEventObject(NULL);
5327 event.m_keyCode = id;
5328 event.m_shiftDown = wxIsShiftDown();
5329 event.m_controlDown = wxIsCtrlDown();
5330 #ifndef __WXWINCE__
5331 event.SetTimestamp(::GetMessageTime());
5332 #endif
5333 wxWindow *win = wxGetActiveWindow();
5334 wxEvtHandler *handler;
5335 if ( win )
5336 {
5337 handler = win->GetEventHandler();
5338 event.SetId(win->GetId());
5339 }
5340 else
5341 {
5342 handler = wxTheApp;
5343 event.SetId(wxID_ANY);
5344 }
5345
5346 if ( handler && handler->ProcessEvent(event) )
5347 {
5348 // processed
5349 return 1;
5350 }
5351 }
5352 }
5353
5354 return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam);
5355 }
5356
5357 #endif // !__WXMICROWIN__
5358
5359 #ifdef __WXDEBUG__
5360 const char *wxGetMessageName(int message)
5361 {
5362 switch ( message )
5363 {
5364 case 0x0000: return "WM_NULL";
5365 case 0x0001: return "WM_CREATE";
5366 case 0x0002: return "WM_DESTROY";
5367 case 0x0003: return "WM_MOVE";
5368 case 0x0005: return "WM_SIZE";
5369 case 0x0006: return "WM_ACTIVATE";
5370 case 0x0007: return "WM_SETFOCUS";
5371 case 0x0008: return "WM_KILLFOCUS";
5372 case 0x000A: return "WM_ENABLE";
5373 case 0x000B: return "WM_SETREDRAW";
5374 case 0x000C: return "WM_SETTEXT";
5375 case 0x000D: return "WM_GETTEXT";
5376 case 0x000E: return "WM_GETTEXTLENGTH";
5377 case 0x000F: return "WM_PAINT";
5378 case 0x0010: return "WM_CLOSE";
5379 case 0x0011: return "WM_QUERYENDSESSION";
5380 case 0x0012: return "WM_QUIT";
5381 case 0x0013: return "WM_QUERYOPEN";
5382 case 0x0014: return "WM_ERASEBKGND";
5383 case 0x0015: return "WM_SYSCOLORCHANGE";
5384 case 0x0016: return "WM_ENDSESSION";
5385 case 0x0017: return "WM_SYSTEMERROR";
5386 case 0x0018: return "WM_SHOWWINDOW";
5387 case 0x0019: return "WM_CTLCOLOR";
5388 case 0x001A: return "WM_WININICHANGE";
5389 case 0x001B: return "WM_DEVMODECHANGE";
5390 case 0x001C: return "WM_ACTIVATEAPP";
5391 case 0x001D: return "WM_FONTCHANGE";
5392 case 0x001E: return "WM_TIMECHANGE";
5393 case 0x001F: return "WM_CANCELMODE";
5394 case 0x0020: return "WM_SETCURSOR";
5395 case 0x0021: return "WM_MOUSEACTIVATE";
5396 case 0x0022: return "WM_CHILDACTIVATE";
5397 case 0x0023: return "WM_QUEUESYNC";
5398 case 0x0024: return "WM_GETMINMAXINFO";
5399 case 0x0026: return "WM_PAINTICON";
5400 case 0x0027: return "WM_ICONERASEBKGND";
5401 case 0x0028: return "WM_NEXTDLGCTL";
5402 case 0x002A: return "WM_SPOOLERSTATUS";
5403 case 0x002B: return "WM_DRAWITEM";
5404 case 0x002C: return "WM_MEASUREITEM";
5405 case 0x002D: return "WM_DELETEITEM";
5406 case 0x002E: return "WM_VKEYTOITEM";
5407 case 0x002F: return "WM_CHARTOITEM";
5408 case 0x0030: return "WM_SETFONT";
5409 case 0x0031: return "WM_GETFONT";
5410 case 0x0037: return "WM_QUERYDRAGICON";
5411 case 0x0039: return "WM_COMPAREITEM";
5412 case 0x0041: return "WM_COMPACTING";
5413 case 0x0044: return "WM_COMMNOTIFY";
5414 case 0x0046: return "WM_WINDOWPOSCHANGING";
5415 case 0x0047: return "WM_WINDOWPOSCHANGED";
5416 case 0x0048: return "WM_POWER";
5417
5418 case 0x004A: return "WM_COPYDATA";
5419 case 0x004B: return "WM_CANCELJOURNAL";
5420 case 0x004E: return "WM_NOTIFY";
5421 case 0x0050: return "WM_INPUTLANGCHANGEREQUEST";
5422 case 0x0051: return "WM_INPUTLANGCHANGE";
5423 case 0x0052: return "WM_TCARD";
5424 case 0x0053: return "WM_HELP";
5425 case 0x0054: return "WM_USERCHANGED";
5426 case 0x0055: return "WM_NOTIFYFORMAT";
5427 case 0x007B: return "WM_CONTEXTMENU";
5428 case 0x007C: return "WM_STYLECHANGING";
5429 case 0x007D: return "WM_STYLECHANGED";
5430 case 0x007E: return "WM_DISPLAYCHANGE";
5431 case 0x007F: return "WM_GETICON";
5432 case 0x0080: return "WM_SETICON";
5433
5434 case 0x0081: return "WM_NCCREATE";
5435 case 0x0082: return "WM_NCDESTROY";
5436 case 0x0083: return "WM_NCCALCSIZE";
5437 case 0x0084: return "WM_NCHITTEST";
5438 case 0x0085: return "WM_NCPAINT";
5439 case 0x0086: return "WM_NCACTIVATE";
5440 case 0x0087: return "WM_GETDLGCODE";
5441 case 0x00A0: return "WM_NCMOUSEMOVE";
5442 case 0x00A1: return "WM_NCLBUTTONDOWN";
5443 case 0x00A2: return "WM_NCLBUTTONUP";
5444 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
5445 case 0x00A4: return "WM_NCRBUTTONDOWN";
5446 case 0x00A5: return "WM_NCRBUTTONUP";
5447 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
5448 case 0x00A7: return "WM_NCMBUTTONDOWN";
5449 case 0x00A8: return "WM_NCMBUTTONUP";
5450 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
5451 case 0x0100: return "WM_KEYDOWN";
5452 case 0x0101: return "WM_KEYUP";
5453 case 0x0102: return "WM_CHAR";
5454 case 0x0103: return "WM_DEADCHAR";
5455 case 0x0104: return "WM_SYSKEYDOWN";
5456 case 0x0105: return "WM_SYSKEYUP";
5457 case 0x0106: return "WM_SYSCHAR";
5458 case 0x0107: return "WM_SYSDEADCHAR";
5459 case 0x0108: return "WM_KEYLAST";
5460
5461 case 0x010D: return "WM_IME_STARTCOMPOSITION";
5462 case 0x010E: return "WM_IME_ENDCOMPOSITION";
5463 case 0x010F: return "WM_IME_COMPOSITION";
5464
5465 case 0x0110: return "WM_INITDIALOG";
5466 case 0x0111: return "WM_COMMAND";
5467 case 0x0112: return "WM_SYSCOMMAND";
5468 case 0x0113: return "WM_TIMER";
5469 case 0x0114: return "WM_HSCROLL";
5470 case 0x0115: return "WM_VSCROLL";
5471 case 0x0116: return "WM_INITMENU";
5472 case 0x0117: return "WM_INITMENUPOPUP";
5473 case 0x011F: return "WM_MENUSELECT";
5474 case 0x0120: return "WM_MENUCHAR";
5475 case 0x0121: return "WM_ENTERIDLE";
5476 case 0x0200: return "WM_MOUSEMOVE";
5477 case 0x0201: return "WM_LBUTTONDOWN";
5478 case 0x0202: return "WM_LBUTTONUP";
5479 case 0x0203: return "WM_LBUTTONDBLCLK";
5480 case 0x0204: return "WM_RBUTTONDOWN";
5481 case 0x0205: return "WM_RBUTTONUP";
5482 case 0x0206: return "WM_RBUTTONDBLCLK";
5483 case 0x0207: return "WM_MBUTTONDOWN";
5484 case 0x0208: return "WM_MBUTTONUP";
5485 case 0x0209: return "WM_MBUTTONDBLCLK";
5486 case 0x020A: return "WM_MOUSEWHEEL";
5487 case 0x0210: return "WM_PARENTNOTIFY";
5488 case 0x0211: return "WM_ENTERMENULOOP";
5489 case 0x0212: return "WM_EXITMENULOOP";
5490
5491 case 0x0213: return "WM_NEXTMENU";
5492 case 0x0214: return "WM_SIZING";
5493 case 0x0215: return "WM_CAPTURECHANGED";
5494 case 0x0216: return "WM_MOVING";
5495 case 0x0218: return "WM_POWERBROADCAST";
5496 case 0x0219: return "WM_DEVICECHANGE";
5497
5498 case 0x0220: return "WM_MDICREATE";
5499 case 0x0221: return "WM_MDIDESTROY";
5500 case 0x0222: return "WM_MDIACTIVATE";
5501 case 0x0223: return "WM_MDIRESTORE";
5502 case 0x0224: return "WM_MDINEXT";
5503 case 0x0225: return "WM_MDIMAXIMIZE";
5504 case 0x0226: return "WM_MDITILE";
5505 case 0x0227: return "WM_MDICASCADE";
5506 case 0x0228: return "WM_MDIICONARRANGE";
5507 case 0x0229: return "WM_MDIGETACTIVE";
5508 case 0x0230: return "WM_MDISETMENU";
5509 case 0x0233: return "WM_DROPFILES";
5510
5511 case 0x0281: return "WM_IME_SETCONTEXT";
5512 case 0x0282: return "WM_IME_NOTIFY";
5513 case 0x0283: return "WM_IME_CONTROL";
5514 case 0x0284: return "WM_IME_COMPOSITIONFULL";
5515 case 0x0285: return "WM_IME_SELECT";
5516 case 0x0286: return "WM_IME_CHAR";
5517 case 0x0290: return "WM_IME_KEYDOWN";
5518 case 0x0291: return "WM_IME_KEYUP";
5519
5520 case 0x0300: return "WM_CUT";
5521 case 0x0301: return "WM_COPY";
5522 case 0x0302: return "WM_PASTE";
5523 case 0x0303: return "WM_CLEAR";
5524 case 0x0304: return "WM_UNDO";
5525 case 0x0305: return "WM_RENDERFORMAT";
5526 case 0x0306: return "WM_RENDERALLFORMATS";
5527 case 0x0307: return "WM_DESTROYCLIPBOARD";
5528 case 0x0308: return "WM_DRAWCLIPBOARD";
5529 case 0x0309: return "WM_PAINTCLIPBOARD";
5530 case 0x030A: return "WM_VSCROLLCLIPBOARD";
5531 case 0x030B: return "WM_SIZECLIPBOARD";
5532 case 0x030C: return "WM_ASKCBFORMATNAME";
5533 case 0x030D: return "WM_CHANGECBCHAIN";
5534 case 0x030E: return "WM_HSCROLLCLIPBOARD";
5535 case 0x030F: return "WM_QUERYNEWPALETTE";
5536 case 0x0310: return "WM_PALETTEISCHANGING";
5537 case 0x0311: return "WM_PALETTECHANGED";
5538 #if wxUSE_HOTKEY
5539 case 0x0312: return "WM_HOTKEY";
5540 #endif
5541
5542 // common controls messages - although they're not strictly speaking
5543 // standard, it's nice to decode them nevertheless
5544
5545 // listview
5546 case 0x1000 + 0: return "LVM_GETBKCOLOR";
5547 case 0x1000 + 1: return "LVM_SETBKCOLOR";
5548 case 0x1000 + 2: return "LVM_GETIMAGELIST";
5549 case 0x1000 + 3: return "LVM_SETIMAGELIST";
5550 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
5551 case 0x1000 + 5: return "LVM_GETITEMA";
5552 case 0x1000 + 75: return "LVM_GETITEMW";
5553 case 0x1000 + 6: return "LVM_SETITEMA";
5554 case 0x1000 + 76: return "LVM_SETITEMW";
5555 case 0x1000 + 7: return "LVM_INSERTITEMA";
5556 case 0x1000 + 77: return "LVM_INSERTITEMW";
5557 case 0x1000 + 8: return "LVM_DELETEITEM";
5558 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
5559 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
5560 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
5561 case 0x1000 + 12: return "LVM_GETNEXTITEM";
5562 case 0x1000 + 13: return "LVM_FINDITEMA";
5563 case 0x1000 + 83: return "LVM_FINDITEMW";
5564 case 0x1000 + 14: return "LVM_GETITEMRECT";
5565 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
5566 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
5567 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
5568 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
5569 case 0x1000 + 18: return "LVM_HITTEST";
5570 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
5571 case 0x1000 + 20: return "LVM_SCROLL";
5572 case 0x1000 + 21: return "LVM_REDRAWITEMS";
5573 case 0x1000 + 22: return "LVM_ARRANGE";
5574 case 0x1000 + 23: return "LVM_EDITLABELA";
5575 case 0x1000 + 118: return "LVM_EDITLABELW";
5576 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
5577 case 0x1000 + 25: return "LVM_GETCOLUMNA";
5578 case 0x1000 + 95: return "LVM_GETCOLUMNW";
5579 case 0x1000 + 26: return "LVM_SETCOLUMNA";
5580 case 0x1000 + 96: return "LVM_SETCOLUMNW";
5581 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
5582 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
5583 case 0x1000 + 28: return "LVM_DELETECOLUMN";
5584 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
5585 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
5586 case 0x1000 + 31: return "LVM_GETHEADER";
5587 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
5588 case 0x1000 + 34: return "LVM_GETVIEWRECT";
5589 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
5590 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
5591 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
5592 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
5593 case 0x1000 + 39: return "LVM_GETTOPINDEX";
5594 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
5595 case 0x1000 + 41: return "LVM_GETORIGIN";
5596 case 0x1000 + 42: return "LVM_UPDATE";
5597 case 0x1000 + 43: return "LVM_SETITEMSTATE";
5598 case 0x1000 + 44: return "LVM_GETITEMSTATE";
5599 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
5600 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
5601 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
5602 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
5603 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
5604 case 0x1000 + 48: return "LVM_SORTITEMS";
5605 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
5606 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
5607 case 0x1000 + 51: return "LVM_GETITEMSPACING";
5608 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
5609 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
5610 case 0x1000 + 53: return "LVM_SETICONSPACING";
5611 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
5612 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
5613 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
5614 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
5615 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
5616 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
5617 case 0x1000 + 60: return "LVM_SETHOTITEM";
5618 case 0x1000 + 61: return "LVM_GETHOTITEM";
5619 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
5620 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
5621 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
5622 case 0x1000 + 65: return "LVM_SETWORKAREA";
5623
5624 // tree view
5625 case 0x1100 + 0: return "TVM_INSERTITEMA";
5626 case 0x1100 + 50: return "TVM_INSERTITEMW";
5627 case 0x1100 + 1: return "TVM_DELETEITEM";
5628 case 0x1100 + 2: return "TVM_EXPAND";
5629 case 0x1100 + 4: return "TVM_GETITEMRECT";
5630 case 0x1100 + 5: return "TVM_GETCOUNT";
5631 case 0x1100 + 6: return "TVM_GETINDENT";
5632 case 0x1100 + 7: return "TVM_SETINDENT";
5633 case 0x1100 + 8: return "TVM_GETIMAGELIST";
5634 case 0x1100 + 9: return "TVM_SETIMAGELIST";
5635 case 0x1100 + 10: return "TVM_GETNEXTITEM";
5636 case 0x1100 + 11: return "TVM_SELECTITEM";
5637 case 0x1100 + 12: return "TVM_GETITEMA";
5638 case 0x1100 + 62: return "TVM_GETITEMW";
5639 case 0x1100 + 13: return "TVM_SETITEMA";
5640 case 0x1100 + 63: return "TVM_SETITEMW";
5641 case 0x1100 + 14: return "TVM_EDITLABELA";
5642 case 0x1100 + 65: return "TVM_EDITLABELW";
5643 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
5644 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
5645 case 0x1100 + 17: return "TVM_HITTEST";
5646 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
5647 case 0x1100 + 19: return "TVM_SORTCHILDREN";
5648 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
5649 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
5650 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
5651 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
5652 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
5653 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
5654 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
5655
5656 // header
5657 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
5658 case 0x1200 + 1: return "HDM_INSERTITEMA";
5659 case 0x1200 + 10: return "HDM_INSERTITEMW";
5660 case 0x1200 + 2: return "HDM_DELETEITEM";
5661 case 0x1200 + 3: return "HDM_GETITEMA";
5662 case 0x1200 + 11: return "HDM_GETITEMW";
5663 case 0x1200 + 4: return "HDM_SETITEMA";
5664 case 0x1200 + 12: return "HDM_SETITEMW";
5665 case 0x1200 + 5: return "HDM_LAYOUT";
5666 case 0x1200 + 6: return "HDM_HITTEST";
5667 case 0x1200 + 7: return "HDM_GETITEMRECT";
5668 case 0x1200 + 8: return "HDM_SETIMAGELIST";
5669 case 0x1200 + 9: return "HDM_GETIMAGELIST";
5670 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
5671 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
5672 case 0x1200 + 17: return "HDM_GETORDERARRAY";
5673 case 0x1200 + 18: return "HDM_SETORDERARRAY";
5674 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
5675
5676 // tab control
5677 case 0x1300 + 2: return "TCM_GETIMAGELIST";
5678 case 0x1300 + 3: return "TCM_SETIMAGELIST";
5679 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
5680 case 0x1300 + 5: return "TCM_GETITEMA";
5681 case 0x1300 + 60: return "TCM_GETITEMW";
5682 case 0x1300 + 6: return "TCM_SETITEMA";
5683 case 0x1300 + 61: return "TCM_SETITEMW";
5684 case 0x1300 + 7: return "TCM_INSERTITEMA";
5685 case 0x1300 + 62: return "TCM_INSERTITEMW";
5686 case 0x1300 + 8: return "TCM_DELETEITEM";
5687 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
5688 case 0x1300 + 10: return "TCM_GETITEMRECT";
5689 case 0x1300 + 11: return "TCM_GETCURSEL";
5690 case 0x1300 + 12: return "TCM_SETCURSEL";
5691 case 0x1300 + 13: return "TCM_HITTEST";
5692 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
5693 case 0x1300 + 40: return "TCM_ADJUSTRECT";
5694 case 0x1300 + 41: return "TCM_SETITEMSIZE";
5695 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
5696 case 0x1300 + 43: return "TCM_SETPADDING";
5697 case 0x1300 + 44: return "TCM_GETROWCOUNT";
5698 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
5699 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
5700 case 0x1300 + 47: return "TCM_GETCURFOCUS";
5701 case 0x1300 + 48: return "TCM_SETCURFOCUS";
5702 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
5703 case 0x1300 + 50: return "TCM_DESELECTALL";
5704
5705 // toolbar
5706 case WM_USER+1: return "TB_ENABLEBUTTON";
5707 case WM_USER+2: return "TB_CHECKBUTTON";
5708 case WM_USER+3: return "TB_PRESSBUTTON";
5709 case WM_USER+4: return "TB_HIDEBUTTON";
5710 case WM_USER+5: return "TB_INDETERMINATE";
5711 case WM_USER+9: return "TB_ISBUTTONENABLED";
5712 case WM_USER+10: return "TB_ISBUTTONCHECKED";
5713 case WM_USER+11: return "TB_ISBUTTONPRESSED";
5714 case WM_USER+12: return "TB_ISBUTTONHIDDEN";
5715 case WM_USER+13: return "TB_ISBUTTONINDETERMINATE";
5716 case WM_USER+17: return "TB_SETSTATE";
5717 case WM_USER+18: return "TB_GETSTATE";
5718 case WM_USER+19: return "TB_ADDBITMAP";
5719 case WM_USER+20: return "TB_ADDBUTTONS";
5720 case WM_USER+21: return "TB_INSERTBUTTON";
5721 case WM_USER+22: return "TB_DELETEBUTTON";
5722 case WM_USER+23: return "TB_GETBUTTON";
5723 case WM_USER+24: return "TB_BUTTONCOUNT";
5724 case WM_USER+25: return "TB_COMMANDTOINDEX";
5725 case WM_USER+26: return "TB_SAVERESTOREA";
5726 case WM_USER+76: return "TB_SAVERESTOREW";
5727 case WM_USER+27: return "TB_CUSTOMIZE";
5728 case WM_USER+28: return "TB_ADDSTRINGA";
5729 case WM_USER+77: return "TB_ADDSTRINGW";
5730 case WM_USER+29: return "TB_GETITEMRECT";
5731 case WM_USER+30: return "TB_BUTTONSTRUCTSIZE";
5732 case WM_USER+31: return "TB_SETBUTTONSIZE";
5733 case WM_USER+32: return "TB_SETBITMAPSIZE";
5734 case WM_USER+33: return "TB_AUTOSIZE";
5735 case WM_USER+35: return "TB_GETTOOLTIPS";
5736 case WM_USER+36: return "TB_SETTOOLTIPS";
5737 case WM_USER+37: return "TB_SETPARENT";
5738 case WM_USER+39: return "TB_SETROWS";
5739 case WM_USER+40: return "TB_GETROWS";
5740 case WM_USER+42: return "TB_SETCMDID";
5741 case WM_USER+43: return "TB_CHANGEBITMAP";
5742 case WM_USER+44: return "TB_GETBITMAP";
5743 case WM_USER+45: return "TB_GETBUTTONTEXTA";
5744 case WM_USER+75: return "TB_GETBUTTONTEXTW";
5745 case WM_USER+46: return "TB_REPLACEBITMAP";
5746 case WM_USER+47: return "TB_SETINDENT";
5747 case WM_USER+48: return "TB_SETIMAGELIST";
5748 case WM_USER+49: return "TB_GETIMAGELIST";
5749 case WM_USER+50: return "TB_LOADIMAGES";
5750 case WM_USER+51: return "TB_GETRECT";
5751 case WM_USER+52: return "TB_SETHOTIMAGELIST";
5752 case WM_USER+53: return "TB_GETHOTIMAGELIST";
5753 case WM_USER+54: return "TB_SETDISABLEDIMAGELIST";
5754 case WM_USER+55: return "TB_GETDISABLEDIMAGELIST";
5755 case WM_USER+56: return "TB_SETSTYLE";
5756 case WM_USER+57: return "TB_GETSTYLE";
5757 case WM_USER+58: return "TB_GETBUTTONSIZE";
5758 case WM_USER+59: return "TB_SETBUTTONWIDTH";
5759 case WM_USER+60: return "TB_SETMAXTEXTROWS";
5760 case WM_USER+61: return "TB_GETTEXTROWS";
5761 case WM_USER+41: return "TB_GETBITMAPFLAGS";
5762
5763 default:
5764 static char s_szBuf[128];
5765 sprintf(s_szBuf, "<unknown message = %d>", message);
5766 return s_szBuf;
5767 }
5768 }
5769 #endif //__WXDEBUG__
5770
5771 static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win)
5772 {
5773 // prepare the DC
5774 TEXTMETRIC tm;
5775 HWND hwnd = GetHwndOf(win);
5776 HDC hdc = ::GetDC(hwnd);
5777
5778 #if !wxDIALOG_UNIT_COMPATIBILITY
5779 // and select the current font into it
5780 HFONT hfont = GetHfontOf(win->GetFont());
5781 if ( hfont )
5782 {
5783 hfont = (HFONT)::SelectObject(hdc, hfont);
5784 }
5785 #endif
5786
5787 // finally retrieve the text metrics from it
5788 GetTextMetrics(hdc, &tm);
5789
5790 #if !wxDIALOG_UNIT_COMPATIBILITY
5791 // and clean up
5792 if ( hfont )
5793 {
5794 (void)::SelectObject(hdc, hfont);
5795 }
5796 #endif
5797
5798 ::ReleaseDC(hwnd, hdc);
5799
5800 return tm;
5801 }
5802
5803 // Find the wxWindow at the current mouse position, returning the mouse
5804 // position.
5805 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
5806 {
5807 pt = wxGetMousePosition();
5808 return wxFindWindowAtPoint(pt);
5809 }
5810
5811 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
5812 {
5813 POINT pt2;
5814 pt2.x = pt.x;
5815 pt2.y = pt.y;
5816 HWND hWndHit = ::WindowFromPoint(pt2);
5817
5818 wxWindow* win = wxFindWinFromHandle((WXHWND) hWndHit) ;
5819 HWND hWnd = hWndHit;
5820
5821 // Try to find a window with a wxWindow associated with it
5822 while (!win && (hWnd != 0))
5823 {
5824 hWnd = ::GetParent(hWnd);
5825 win = wxFindWinFromHandle((WXHWND) hWnd) ;
5826 }
5827 return win;
5828 }
5829
5830 // Get the current mouse position.
5831 wxPoint wxGetMousePosition()
5832 {
5833 POINT pt;
5834 #ifdef __WXWINCE__
5835 GetCursorPosWinCE(&pt);
5836 #else
5837 GetCursorPos( & pt );
5838 #endif
5839
5840 return wxPoint(pt.x, pt.y);
5841 }
5842
5843 #if wxUSE_HOTKEY
5844
5845 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
5846 static void WinCEUnregisterHotKey(int modifiers, int id)
5847 {
5848 // Register hotkeys for the hardware buttons
5849 HINSTANCE hCoreDll;
5850 typedef BOOL (WINAPI *UnregisterFunc1Proc)(UINT, UINT);
5851
5852 UnregisterFunc1Proc procUnregisterFunc;
5853 hCoreDll = LoadLibrary(_T("coredll.dll"));
5854 if (hCoreDll)
5855 {
5856 procUnregisterFunc = (UnregisterFunc1Proc)GetProcAddress(hCoreDll, _T("UnregisterFunc1"));
5857 if (procUnregisterFunc)
5858 procUnregisterFunc(modifiers, id);
5859 FreeLibrary(hCoreDll);
5860 }
5861 }
5862 #endif
5863
5864 bool wxWindowMSW::RegisterHotKey(int hotkeyId, int modifiers, int keycode)
5865 {
5866 UINT win_modifiers=0;
5867 if ( modifiers & wxMOD_ALT )
5868 win_modifiers |= MOD_ALT;
5869 if ( modifiers & wxMOD_SHIFT )
5870 win_modifiers |= MOD_SHIFT;
5871 if ( modifiers & wxMOD_CONTROL )
5872 win_modifiers |= MOD_CONTROL;
5873 if ( modifiers & wxMOD_WIN )
5874 win_modifiers |= MOD_WIN;
5875
5876 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
5877 // Required for PPC and Smartphone hardware buttons
5878 if (keycode >= WXK_SPECIAL1 && keycode <= WXK_SPECIAL20)
5879 WinCEUnregisterHotKey(win_modifiers, hotkeyId);
5880 #endif
5881
5882 if ( !::RegisterHotKey(GetHwnd(), hotkeyId, win_modifiers, keycode) )
5883 {
5884 wxLogLastError(_T("RegisterHotKey"));
5885
5886 return false;
5887 }
5888
5889 return true;
5890 }
5891
5892 bool wxWindowMSW::UnregisterHotKey(int hotkeyId)
5893 {
5894 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
5895 WinCEUnregisterHotKey(MOD_WIN, hotkeyId);
5896 #endif
5897
5898 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId) )
5899 {
5900 wxLogLastError(_T("UnregisterHotKey"));
5901
5902 return false;
5903 }
5904
5905 return true;
5906 }
5907
5908 #if wxUSE_ACCEL
5909
5910 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam, WXLPARAM lParam)
5911 {
5912 int hotkeyId = wParam;
5913 int virtualKey = HIWORD(lParam);
5914 int win_modifiers = LOWORD(lParam);
5915
5916 wxKeyEvent event(CreateKeyEvent(wxEVT_HOTKEY, virtualKey, wParam, lParam));
5917 event.SetId(hotkeyId);
5918 event.m_shiftDown = (win_modifiers & MOD_SHIFT) != 0;
5919 event.m_controlDown = (win_modifiers & MOD_CONTROL) != 0;
5920 event.m_altDown = (win_modifiers & MOD_ALT) != 0;
5921 event.m_metaDown = (win_modifiers & MOD_WIN) != 0;
5922
5923 return GetEventHandler()->ProcessEvent(event);
5924 }
5925
5926 #endif // wxUSE_ACCEL
5927
5928 #endif // wxUSE_HOTKEY
5929
5930 // Not tested under WinCE
5931 #ifndef __WXWINCE__
5932
5933 // this class installs a message hook which really wakes up our idle processing
5934 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
5935 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
5936 // being dragged or even inside ::MessageBox()) and so don't control message
5937 // dispatching otherwise
5938 class wxIdleWakeUpModule : public wxModule
5939 {
5940 public:
5941 virtual bool OnInit()
5942 {
5943 ms_hMsgHookProc = ::SetWindowsHookEx
5944 (
5945 WH_GETMESSAGE,
5946 &wxIdleWakeUpModule::MsgHookProc,
5947 NULL,
5948 GetCurrentThreadId()
5949 );
5950
5951 if ( !ms_hMsgHookProc )
5952 {
5953 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
5954
5955 return false;
5956 }
5957
5958 return true;
5959 }
5960
5961 virtual void OnExit()
5962 {
5963 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc);
5964 }
5965
5966 static LRESULT CALLBACK MsgHookProc(int nCode, WPARAM wParam, LPARAM lParam)
5967 {
5968 MSG *msg = (MSG*)lParam;
5969
5970 // only process the message if it is actually going to be removed from
5971 // the message queue, this prevents that the same event from being
5972 // processed multiple times if now someone just called PeekMessage()
5973 if ( msg->message == WM_NULL && wParam == PM_REMOVE )
5974 {
5975 wxTheApp->ProcessPendingEvents();
5976 }
5977
5978 return CallNextHookEx(ms_hMsgHookProc, nCode, wParam, lParam);
5979 };
5980
5981 private:
5982 static HHOOK ms_hMsgHookProc;
5983
5984 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule)
5985 };
5986
5987 HHOOK wxIdleWakeUpModule::ms_hMsgHookProc = 0;
5988
5989 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule, wxModule)
5990
5991 #endif // __WXWINCE__
5992
5993 #ifdef __WXWINCE__
5994
5995 #if wxUSE_STATBOX
5996 static void wxAdjustZOrder(wxWindow* parent)
5997 {
5998 if (parent->IsKindOf(CLASSINFO(wxStaticBox)))
5999 {
6000 // Set the z-order correctly
6001 SetWindowPos((HWND) parent->GetHWND(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
6002 }
6003
6004 wxWindowList::compatibility_iterator current = parent->GetChildren().GetFirst();
6005 while (current)
6006 {
6007 wxWindow *childWin = current->GetData();
6008 wxAdjustZOrder(childWin);
6009 current = current->GetNext();
6010 }
6011 }
6012 #endif
6013
6014 // We need to adjust the z-order of static boxes in WinCE, to
6015 // make 'contained' controls visible
6016 void wxWindowMSW::OnInitDialog( wxInitDialogEvent& event )
6017 {
6018 #if wxUSE_STATBOX
6019 wxAdjustZOrder(this);
6020 #endif
6021
6022 event.Skip();
6023 }
6024 #endif
6025