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