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
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/window.h"
30 #include "wx/msw/wrapwin.h"
31 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/msw/missing.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcmemory.h"
40 #include "wx/layout.h"
41 #include "wx/dialog.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"
51 #include "wx/textctrl.h"
52 #include "wx/menuitem.h"
53 #include "wx/module.h"
56 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
57 #include "wx/ownerdrw.h"
60 #include "wx/hashmap.h"
61 #include "wx/evtloop.h"
63 #include "wx/sysopt.h"
65 #if wxUSE_DRAG_AND_DROP
69 #if wxUSE_ACCESSIBILITY
70 #include "wx/access.h"
74 #define WM_GETOBJECT 0x003D
77 #define OBJID_CLIENT 0xFFFFFFFC
81 #include "wx/msw/private.h"
82 #include "wx/msw/private/keyboard.h"
83 #include "wx/msw/dcclient.h"
86 #include "wx/tooltip.h"
94 #include "wx/spinctrl.h"
95 #endif // wxUSE_SPINCTRL
97 #include "wx/notebook.h"
98 #include "wx/listctrl.h"
99 #include "wx/dynlib.h"
103 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
104 #include <shellapi.h>
105 #include <mmsystem.h>
109 #include <windowsx.h>
112 #if !defined __WXWINCE__ && !defined NEED_PBT_H
116 #if defined(__WXWINCE__)
117 #include "wx/msw/wince/missing.h"
120 #include <shellapi.h>
122 #include <aygshell.h>
127 #include "wx/msw/uxtheme.h"
128 #define EP_EDITTEXT 1
131 #define ETS_SELECTED 3
132 #define ETS_DISABLED 4
133 #define ETS_FOCUSED 5
134 #define ETS_READONLY 6
138 // define the constants used by AnimateWindow() if our SDK doesn't have them
140 #define AW_HOR_POSITIVE 0x00000001
141 #define AW_HOR_NEGATIVE 0x00000002
142 #define AW_VER_POSITIVE 0x00000004
143 #define AW_VER_NEGATIVE 0x00000008
144 #define AW_CENTER 0x00000010
145 #define AW_HIDE 0x00010000
146 #define AW_ACTIVATE 0x00020000
147 #define AW_SLIDE 0x00040000
148 #define AW_BLEND 0x00080000
151 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS
152 #define HAVE_TRACKMOUSEEVENT
153 #endif // everything needed for TrackMouseEvent()
155 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
156 // when mouse position didnd't change
158 #define wxUSE_MOUSEEVENT_HACK 0
160 #define wxUSE_MOUSEEVENT_HACK 1
163 // not all compilers/platforms have X button related declarations (notably
164 // Windows CE doesn't, and probably some old SDKs don't neither)
165 #ifdef WM_XBUTTONDOWN
166 #define wxHAS_XBUTTON
169 // ---------------------------------------------------------------------------
171 // ---------------------------------------------------------------------------
173 #if wxUSE_MENUS_NATIVE
174 extern wxMenu
*wxCurrentPopupMenu
;
180 // true if we had already created the std colour map, used by
181 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
182 bool gs_hasStdCmap
= false;
184 // last mouse event information we need to filter out the duplicates
185 #if wxUSE_MOUSEEVENT_HACK
186 struct MouseEventInfoDummy
188 // mouse position (in screen coordinates)
191 // last mouse event type
194 #endif // wxUSE_MOUSEEVENT_HACK
196 // hash containing the registered handlers for the custom messages
197 WX_DECLARE_HASH_MAP(int, wxWindow::MSWMessageHandler
,
198 wxIntegerHash
, wxIntegerEqual
,
201 MSWMessageHandlers gs_messageHandlers
;
203 // hash containing all our windows, it uses HWND keys and wxWindow* values
204 WX_DECLARE_HASH_MAP(HWND
, wxWindow
*,
205 wxPointerHash
, wxPointerEqual
,
208 WindowHandles gs_windowHandles
;
210 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
212 // temporary override for WM_ERASEBKGND processing: we don't store this in
213 // wxWindow itself as we don't need it during most of the time so don't
214 // increase the size of all window objects unnecessarily
215 WX_DECLARE_HASH_MAP(wxWindow
*, wxWindow
*,
216 wxPointerHash
, wxPointerEqual
,
219 EraseBgHooks gs_eraseBgHooks
;
221 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
223 } // anonymous namespace
225 // ---------------------------------------------------------------------------
227 // ---------------------------------------------------------------------------
229 // the window proc for all our windows
230 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
231 WPARAM wParam
, LPARAM lParam
);
234 #if wxDEBUG_LEVEL >= 2
235 const wxChar
*wxGetMessageName(int message
);
236 #endif // wxDEBUG_LEVEL >= 2
238 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
239 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
241 // get the text metrics for the current font
242 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
245 // find the window for the mouse event at the specified position
246 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
247 #endif // __WXWINCE__
249 // wrapper around BringWindowToTop() API
250 static inline void wxBringWindowToTop(HWND hwnd
)
252 #ifdef __WXMICROWIN__
253 // It seems that MicroWindows brings the _parent_ of the window to the top,
254 // which can be the wrong one.
256 // activate (set focus to) specified window
260 // raise top level parent to top of z order
261 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
263 wxLogLastError(wxT("SetWindowPos"));
269 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
270 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
273 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
274 parent as well as otherwise several Win32 functions using
275 GetNextDlgTabItem() to iterate over all controls such as
276 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
277 all of them iterate over all the controls starting from the currently
278 focused one and stop iterating when they get back to the focus but
279 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
280 get back to the initial (focused) window: as we do have this style,
281 GetNextDlgTabItem() will leave this window and continue in its parent,
282 but if the parent doesn't have it, it wouldn't recurse inside it later
283 on and so wouldn't have a chance of getting back to this window either.
285 while ( parent
&& !parent
->IsTopLevel() )
287 LONG exStyle
= wxGetWindowExStyle(parent
);
288 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
290 // force the parent to have this style
291 wxSetWindowExStyle(parent
, exStyle
| WS_EX_CONTROLPARENT
);
294 parent
= parent
->GetParent();
298 #endif // !__WXWINCE__
301 // On Windows CE, GetCursorPos can return an error, so use this function
303 bool GetCursorPosWinCE(POINT
* pt
)
305 if (!GetCursorPos(pt
))
307 DWORD pos
= GetMessagePos();
315 // ---------------------------------------------------------------------------
317 // ---------------------------------------------------------------------------
319 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
321 #ifdef __WXUNIVERSAL__
322 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
324 #if wxUSE_EXTENDED_RTTI
326 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
327 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
328 // windows with negative ids never can be recreated anyway
330 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
332 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
333 if ( win
&& win
->GetId() < 0 )
338 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
340 // make wxWindowList known before the property is used
342 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
344 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
346 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
349 WX_DEFINE_FLAGS( wxWindowStyle
)
351 wxBEGIN_FLAGS( wxWindowStyle
)
352 // new style border flags, we put them first to
353 // use them for streaming out
355 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
356 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
357 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
358 wxFLAGS_MEMBER(wxBORDER_RAISED
)
359 wxFLAGS_MEMBER(wxBORDER_STATIC
)
360 wxFLAGS_MEMBER(wxBORDER_NONE
)
362 // old style border flags
363 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
364 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
365 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
366 wxFLAGS_MEMBER(wxRAISED_BORDER
)
367 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
368 wxFLAGS_MEMBER(wxBORDER
)
370 // standard window styles
371 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
372 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
373 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
374 wxFLAGS_MEMBER(wxWANTS_CHARS
)
375 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
376 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
377 wxFLAGS_MEMBER(wxVSCROLL
)
378 wxFLAGS_MEMBER(wxHSCROLL
)
380 wxEND_FLAGS( wxWindowStyle
)
382 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
383 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
384 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
385 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
386 // Always constructor Properties first
388 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
389 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
390 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
391 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
392 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
394 // Then all relations of the object graph
396 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
398 // and finally all other properties
400 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
401 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
402 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
403 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
404 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
406 // possible property candidates (not in xrc) or not valid in all subclasses
407 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
408 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
409 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
410 // MaxHeight, Width , MinHeight , Width
411 // TODO switch label to control and title to toplevels
413 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
414 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
415 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
416 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
421 wxEND_PROPERTIES_TABLE()
423 wxBEGIN_HANDLERS_TABLE(wxWindow
)
424 wxEND_HANDLERS_TABLE()
426 wxCONSTRUCTOR_DUMMY(wxWindow
)
429 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
431 #endif // __WXUNIVERSAL__/__WXMSW__
433 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
434 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
436 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
440 // ===========================================================================
442 // ===========================================================================
444 // ---------------------------------------------------------------------------
445 // wxWindow utility functions
446 // ---------------------------------------------------------------------------
448 // Find an item given the MS Windows id
449 wxWindow
*wxWindowMSW::FindItem(long id
) const
452 wxControl
*item
= wxDynamicCastThis(wxControl
);
455 // is it us or one of our "internal" children?
456 if ( item
->GetId() == id
457 #ifndef __WXUNIVERSAL__
458 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
459 #endif // __WXUNIVERSAL__
465 #endif // wxUSE_CONTROLS
467 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
470 wxWindow
*childWin
= current
->GetData();
472 wxWindow
*wnd
= childWin
->FindItem(id
);
476 current
= current
->GetNext();
482 // Find an item given the MS Windows handle
483 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
485 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
488 wxWindow
*parent
= current
->GetData();
490 // Do a recursive search.
491 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
497 || parent
->IsKindOf(CLASSINFO(wxControl
))
498 #endif // wxUSE_CONTROLS
501 wxWindow
*item
= current
->GetData();
502 if ( item
->GetHWND() == hWnd
)
506 if ( item
->ContainsHWND(hWnd
) )
511 current
= current
->GetNext();
516 // Default command handler
517 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
522 // ----------------------------------------------------------------------------
523 // constructors and such
524 // ----------------------------------------------------------------------------
526 void wxWindowMSW::Init()
530 m_mouseInWindow
= false;
531 m_lastKeydownProcessed
= false;
538 #if wxUSE_DEFERRED_SIZING
540 m_pendingPosition
= wxDefaultPosition
;
541 m_pendingSize
= wxDefaultSize
;
542 #endif // wxUSE_DEFERRED_SIZING
545 m_contextMenuEnabled
= false;
550 wxWindowMSW::~wxWindowMSW()
554 #ifndef __WXUNIVERSAL__
555 // VS: make sure there's no wxFrame with last focus set to us:
556 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
558 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
561 if ( frame
->GetLastFocus() == this )
563 frame
->SetLastFocus(NULL
);
566 // apparently sometimes we can end up with our grand parent
567 // pointing to us as well: this is surely a bug in focus handling
568 // code but it's not clear where it happens so for now just try to
569 // fix it here by not breaking out of the loop
573 #endif // __WXUNIVERSAL__
575 // VS: destroy children first and _then_ detach *this from its parent.
576 // If we did it the other way around, children wouldn't be able
577 // find their parent frame (see above).
582 // VZ: test temp removed to understand what really happens here
583 //if (::IsWindow(GetHwnd()))
585 if ( !::DestroyWindow(GetHwnd()) )
587 wxLogLastError(wxT("DestroyWindow"));
591 // remove hWnd <-> wxWindow association
592 wxRemoveHandleAssociation(this);
598 const wxChar
*wxWindowMSW::MSWGetRegisteredClassName()
600 return wxApp::GetRegisteredClassName(wxT("wxWindow"), COLOR_BTNFACE
);
603 // real construction (Init() must have been called before!)
604 bool wxWindowMSW::Create(wxWindow
*parent
,
609 const wxString
& name
)
611 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
613 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
616 parent
->AddChild(this);
619 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
621 #ifdef __WXUNIVERSAL__
622 // no borders, we draw them ourselves
623 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
627 msflags
&= ~WS_BORDER
;
628 #endif // wxUniversal
632 msflags
|= WS_VISIBLE
;
635 if ( !MSWCreate(MSWGetRegisteredClassName(),
636 NULL
, pos
, size
, msflags
, exstyle
) )
644 // ---------------------------------------------------------------------------
646 // ---------------------------------------------------------------------------
648 void wxWindowMSW::SetFocus()
650 HWND hWnd
= GetHwnd();
651 wxCHECK_RET( hWnd
, wxT("can't set focus to invalid window") );
653 #if !defined(__WXWINCE__)
657 if ( !::SetFocus(hWnd
) )
659 // was there really an error?
660 DWORD dwRes
= ::GetLastError();
663 HWND hwndFocus
= ::GetFocus();
664 if ( hwndFocus
!= hWnd
)
666 wxLogApiError(wxT("SetFocus"), dwRes
);
672 void wxWindowMSW::SetFocusFromKbd()
674 // when the focus is given to the control with DLGC_HASSETSEL style from
675 // keyboard its contents should be entirely selected: this is what
676 // ::IsDialogMessage() does and so we should do it as well to provide the
677 // same LNF as the native programs
678 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
680 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
683 // do this after (maybe) setting the selection as like this when
684 // wxEVT_SET_FOCUS handler is called, the selection would have been already
685 // set correctly -- this may be important
686 wxWindowBase::SetFocusFromKbd();
689 // Get the window with the focus
690 wxWindow
*wxWindowBase::DoFindFocus()
692 HWND hWnd
= ::GetFocus();
695 return wxGetWindowFromHWND((WXHWND
)hWnd
);
701 void wxWindowMSW::DoEnable( bool enable
)
703 MSWEnableHWND(GetHwnd(), enable
);
706 bool wxWindowMSW::MSWEnableHWND(WXHWND hWnd
, bool enable
)
711 // If disabling focused control, we move focus to the next one, as if the
712 // user pressed Tab. That's because we can't keep focus on a disabled
713 // control, Tab-navigation would stop working then.
714 if ( !enable
&& ::GetFocus() == hWnd
)
717 return ::EnableWindow(hWnd
, (BOOL
)enable
) != 0;
720 bool wxWindowMSW::Show(bool show
)
722 if ( !wxWindowBase::Show(show
) )
725 HWND hWnd
= GetHwnd();
727 // we could be called before the underlying window is created (this is
728 // actually useful to prevent it from being initially shown), e.g.
730 // wxFoo *foo = new wxFoo;
732 // foo->Create(parent, ...);
734 // should work without errors
737 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
742 // DoFreeze/DoThaw don't do anything if the window is not shown, so
743 // we have to call them from here now
754 wxWindowMSW::MSWShowWithEffect(bool show
,
758 if ( effect
== wxSHOW_EFFECT_NONE
)
761 if ( !wxWindowBase::Show(show
) )
764 typedef BOOL (WINAPI
*AnimateWindow_t
)(HWND
, DWORD
, DWORD
);
766 static AnimateWindow_t s_pfnAnimateWindow
= NULL
;
767 static bool s_initDone
= false;
770 wxDynamicLibrary
dllUser32(wxT("user32.dll"), wxDL_VERBATIM
| wxDL_QUIET
);
771 wxDL_INIT_FUNC(s_pfn
, AnimateWindow
, dllUser32
);
775 // notice that it's ok to unload user32.dll here as it won't be really
776 // unloaded, being still in use because we link to it statically too
779 if ( !s_pfnAnimateWindow
)
782 // Show() has a side effect of sending a WM_SIZE to the window, which helps
783 // ensuring that it's laid out correctly, but AnimateWindow() doesn't do
784 // this so send the event ourselves
787 // prepare to use AnimateWindow()
790 timeout
= 200; // this is the default animation timeout, per MSDN
792 DWORD dwFlags
= show
? 0 : AW_HIDE
;
796 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
797 dwFlags
|= AW_HOR_NEGATIVE
;
800 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
801 dwFlags
|= AW_HOR_POSITIVE
;
804 case wxSHOW_EFFECT_ROLL_TO_TOP
:
805 dwFlags
|= AW_VER_NEGATIVE
;
808 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
809 dwFlags
|= AW_VER_POSITIVE
;
812 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
813 dwFlags
|= AW_SLIDE
| AW_HOR_NEGATIVE
;
816 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
817 dwFlags
|= AW_SLIDE
| AW_HOR_POSITIVE
;
820 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
821 dwFlags
|= AW_SLIDE
| AW_VER_NEGATIVE
;
824 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
825 dwFlags
|= AW_SLIDE
| AW_VER_POSITIVE
;
828 case wxSHOW_EFFECT_BLEND
:
832 case wxSHOW_EFFECT_EXPAND
:
833 dwFlags
|= AW_CENTER
;
837 case wxSHOW_EFFECT_MAX
:
838 wxFAIL_MSG( wxT("invalid window show effect") );
842 wxFAIL_MSG( wxT("unknown window show effect") );
846 if ( !(*s_pfnAnimateWindow
)(GetHwnd(), timeout
, dwFlags
) )
848 wxLogLastError(wxT("AnimateWindow"));
856 // Raise the window to the top of the Z order
857 void wxWindowMSW::Raise()
859 wxBringWindowToTop(GetHwnd());
862 // Lower the window to the bottom of the Z order
863 void wxWindowMSW::Lower()
865 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
866 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
869 void wxWindowMSW::DoCaptureMouse()
871 HWND hWnd
= GetHwnd();
878 void wxWindowMSW::DoReleaseMouse()
880 if ( !::ReleaseCapture() )
882 wxLogLastError(wxT("ReleaseCapture"));
886 /* static */ wxWindow
*wxWindowBase::GetCapture()
888 HWND hwnd
= ::GetCapture();
889 return hwnd
? wxFindWinFromHandle(hwnd
) : NULL
;
892 bool wxWindowMSW::SetFont(const wxFont
& font
)
894 if ( !wxWindowBase::SetFont(font
) )
900 HWND hWnd
= GetHwnd();
903 // note the use of GetFont() instead of m_font: our own font could have
904 // just been reset and in this case we need to change the font used by
905 // the native window to the default for this class, i.e. exactly what
907 WXHANDLE hFont
= GetFont().GetResourceHandle();
909 wxASSERT_MSG( hFont
, wxT("should have valid font") );
911 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
916 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
918 if ( !wxWindowBase::SetCursor(cursor
) )
924 // don't "overwrite" busy cursor
925 if ( m_cursor
.Ok() && !wxIsBusy() )
927 // normally we should change the cursor only if it's over this window
928 // but we should do it always if we capture the mouse currently
929 bool set
= HasCapture();
932 HWND hWnd
= GetHwnd();
936 ::GetCursorPosWinCE(&point
);
938 ::GetCursorPos(&point
);
941 RECT rect
= wxGetWindowRect(hWnd
);
943 set
= ::PtInRect(&rect
, point
) != 0;
948 ::SetCursor(GetHcursorOf(m_cursor
));
950 //else: will be set later when the mouse enters this window
956 void wxWindowMSW::WarpPointer(int x
, int y
)
958 ClientToScreen(&x
, &y
);
960 if ( !::SetCursorPos(x
, y
) )
962 wxLogLastError(wxT("SetCursorPos"));
966 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
968 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
969 // to use it on older systems -- and could possibly do some harm
970 static int s_needToUpdate
= -1;
971 if ( s_needToUpdate
== -1 )
974 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
978 if ( s_needToUpdate
)
980 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
981 // won't send WM_UPDATEUISTATE
982 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
986 // ---------------------------------------------------------------------------
988 // ---------------------------------------------------------------------------
993 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
995 #ifdef __WXMICROWIN__
996 return ::GetScrollPosWX(hWnd
, wOrient
);
998 WinStruct
<SCROLLINFO
> scrollInfo
;
999 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
1000 scrollInfo
.fMask
= SIF_POS
;
1001 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
1003 return scrollInfo
.nPos
;
1008 inline UINT
WXOrientToSB(int orient
)
1010 return orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
;
1013 } // anonymous namespace
1015 int wxWindowMSW::GetScrollPos(int orient
) const
1017 HWND hWnd
= GetHwnd();
1018 wxCHECK_MSG( hWnd
, 0, wxT("no HWND in GetScrollPos") );
1020 return GetScrollPosition(hWnd
, WXOrientToSB(orient
));
1023 // This now returns the whole range, not just the number
1024 // of positions that we can scroll.
1025 int wxWindowMSW::GetScrollRange(int orient
) const
1028 HWND hWnd
= GetHwnd();
1031 WinStruct
<SCROLLINFO
> scrollInfo
;
1032 scrollInfo
.fMask
= SIF_RANGE
;
1033 if ( !::GetScrollInfo(hWnd
, WXOrientToSB(orient
), &scrollInfo
) )
1035 // Most of the time this is not really an error, since the return
1036 // value can also be zero when there is no scrollbar yet.
1037 // wxLogLastError(wxT("GetScrollInfo"));
1039 maxPos
= scrollInfo
.nMax
;
1041 // undo "range - 1" done in SetScrollbar()
1045 int wxWindowMSW::GetScrollThumb(int orient
) const
1047 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
1050 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
1052 HWND hWnd
= GetHwnd();
1053 wxCHECK_RET( hWnd
, wxT("SetScrollPos: no HWND") );
1055 WinStruct
<SCROLLINFO
> info
;
1059 info
.fMask
= SIF_POS
;
1060 if ( HasFlag(wxALWAYS_SHOW_SB
) )
1062 // disable scrollbar instead of removing it then
1063 info
.fMask
|= SIF_DISABLENOSCROLL
;
1066 ::SetScrollInfo(hWnd
, WXOrientToSB(orient
), &info
, refresh
);
1069 // New function that will replace some of the above.
1070 void wxWindowMSW::SetScrollbar(int orient
,
1076 // We have to set the variables here to make them valid in events
1077 // triggered by ::SetScrollInfo()
1078 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
1080 HWND hwnd
= GetHwnd();
1084 WinStruct
<SCROLLINFO
> info
;
1087 info
.nPage
= pageSize
;
1088 info
.nMin
= 0; // range is nMax - nMin + 1
1089 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
1092 // We normally also reenable scrollbar in case it had been previously
1093 // disabled by specifying SIF_DISABLENOSCROLL below but we should only
1094 // do this if it has valid range, otherwise it would be enabled but not
1096 if ( range
>= pageSize
)
1098 ::EnableScrollBar(hwnd
, WXOrientToSB(orient
), ESB_ENABLE_BOTH
);
1101 //else: leave all the fields to be 0
1103 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
1104 if ( HasFlag(wxALWAYS_SHOW_SB
) || range
== -1 )
1106 // disable scrollbar instead of removing it then
1107 info
.fMask
|= SIF_DISABLENOSCROLL
;
1110 ::SetScrollInfo(hwnd
, WXOrientToSB(orient
), &info
, refresh
);
1113 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
1119 wxCopyRectToRECT(*prect
, rect
);
1129 // FIXME: is this the exact equivalent of the line below?
1130 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
1132 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
1136 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
1138 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
1141 for ( int n
= 0; n
< count
; n
++ )
1143 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
1145 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
1146 if ( posNew
== pos
)
1148 // don't bother to continue, we're already at top/bottom
1155 return pos
!= posStart
;
1158 bool wxWindowMSW::ScrollLines(int lines
)
1160 bool down
= lines
> 0;
1162 return ScrollVertically(GetHwnd(),
1163 down
? SB_LINEDOWN
: SB_LINEUP
,
1164 down
? lines
: -lines
);
1167 bool wxWindowMSW::ScrollPages(int pages
)
1169 bool down
= pages
> 0;
1171 return ScrollVertically(GetHwnd(),
1172 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1173 down
? pages
: -pages
);
1176 // ----------------------------------------------------------------------------
1178 // ----------------------------------------------------------------------------
1180 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
1185 wxCHECK_RET( GetHwnd(),
1186 wxT("layout direction must be set after window creation") );
1188 LONG styleOld
= wxGetWindowExStyle(this);
1190 LONG styleNew
= styleOld
;
1193 case wxLayout_LeftToRight
:
1194 styleNew
&= ~WS_EX_LAYOUTRTL
;
1197 case wxLayout_RightToLeft
:
1198 styleNew
|= WS_EX_LAYOUTRTL
;
1202 wxFAIL_MSG(wxT("unsupported layout direction"));
1206 if ( styleNew
!= styleOld
)
1208 wxSetWindowExStyle(this, styleNew
);
1213 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1216 return wxLayout_Default
;
1218 wxCHECK_MSG( GetHwnd(), wxLayout_Default
, wxT("invalid window") );
1220 return wxHasWindowExStyle(this, WS_EX_LAYOUTRTL
) ? wxLayout_RightToLeft
1221 : wxLayout_LeftToRight
;
1226 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1227 wxCoord
WXUNUSED(width
),
1228 wxCoord
WXUNUSED(widthTotal
)) const
1230 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1231 // redo it ourselves
1235 // ---------------------------------------------------------------------------
1237 // ---------------------------------------------------------------------------
1239 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1241 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1243 HWND hwnd
= (HWND
)hWnd
;
1244 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1248 wxAssociateWinWithHandle(hwnd
, this);
1250 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1252 // we don't need to subclass the window of our own class (in the Windows
1253 // sense of the word)
1254 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1256 wxSetWindowProc(hwnd
, wxWndProc
);
1260 // don't bother restoring it either: this also makes it easy to
1261 // implement IsOfStandardClass() method which returns true for the
1262 // standard controls and false for the wxWidgets own windows as it can
1263 // simply check m_oldWndProc
1264 m_oldWndProc
= NULL
;
1267 // we're officially created now, send the event
1268 wxWindowCreateEvent
event((wxWindow
*)this);
1269 (void)HandleWindowEvent(event
);
1272 void wxWindowMSW::UnsubclassWin()
1274 wxRemoveHandleAssociation(this);
1276 // Restore old Window proc
1277 HWND hwnd
= GetHwnd();
1282 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1286 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1288 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1291 m_oldWndProc
= NULL
;
1296 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1300 if ( !::DestroyWindow(GetHwnd()) )
1302 wxLogLastError(wxT("DestroyWindow"));
1306 WXHWND wxhwnd
= (WXHWND
)handle
;
1308 // this also calls SetHWND(wxhwnd)
1309 SubclassWin(wxhwnd
);
1312 void wxWindowMSW::DissociateHandle()
1314 // this also calls SetHWND(0) for us
1319 bool wxCheckWindowWndProc(WXHWND hWnd
,
1320 WXFARPROC
WXUNUSED(wndProc
))
1322 const wxString
str(wxGetWindowClass(hWnd
));
1324 // TODO: get rid of wxTLWHiddenParent special case (currently it's not
1325 // registered by wxApp but using ad hoc code in msw/toplevel.cpp);
1326 // there is also a hidden window class used by sockets &c
1327 return wxApp::IsRegisteredClassName(str
) || str
== wxT("wxTLWHiddenParent");
1330 // ----------------------------------------------------------------------------
1332 // ----------------------------------------------------------------------------
1334 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1336 long flagsOld
= GetWindowStyleFlag();
1337 if ( flags
== flagsOld
)
1340 // update the internal variable
1341 wxWindowBase::SetWindowStyleFlag(flags
);
1343 // and the real window flags
1344 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1347 void wxWindowMSW::SetExtraStyle(long exflags
)
1349 long exflagsOld
= GetExtraStyle();
1350 if ( exflags
== exflagsOld
)
1353 // update the internal variable
1354 wxWindowBase::SetExtraStyle(exflags
);
1356 // and the real window flags
1357 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1360 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1362 // now update the Windows style as well if needed - and if the window had
1363 // been already created
1367 // we may need to call SetWindowPos() when we change some styles
1368 bool callSWP
= false;
1371 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1373 // this is quite a horrible hack but we need it because MSWGetStyle()
1374 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1375 // and so we have to modify the window exflags temporarily to get the
1376 // correct exstyleOld
1377 long exflagsNew
= GetExtraStyle();
1378 wxWindowBase::SetExtraStyle(exflagsOld
);
1381 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1383 wxWindowBase::SetExtraStyle(exflagsNew
);
1386 if ( style
!= styleOld
)
1388 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1389 // this function so instead of simply setting the style to the new
1390 // value we clear the bits which were set in styleOld but are set in
1391 // the new one and set the ones which were not set before
1392 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1393 styleReal
&= ~styleOld
;
1396 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1398 // we need to call SetWindowPos() if any of the styles affecting the
1399 // frame appearance have changed
1400 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1409 // and the extended style
1410 long exstyleReal
= wxGetWindowExStyle(this);
1412 if ( exstyle
!= exstyleOld
)
1414 exstyleReal
&= ~exstyleOld
;
1415 exstyleReal
|= exstyle
;
1417 wxSetWindowExStyle(this, exstyleReal
);
1419 // ex style changes don't take effect without calling SetWindowPos
1425 // we must call SetWindowPos() to flush the cached extended style and
1426 // also to make the change to wxSTAY_ON_TOP style take effect: just
1427 // setting the style simply doesn't work
1428 if ( !::SetWindowPos(GetHwnd(),
1429 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1432 SWP_NOMOVE
| SWP_NOSIZE
| SWP_FRAMECHANGED
) )
1434 wxLogLastError(wxT("SetWindowPos"));
1439 wxBorder
wxWindowMSW::GetDefaultBorderForControl() const
1441 return wxBORDER_THEME
;
1444 wxBorder
wxWindowMSW::GetDefaultBorder() const
1446 return wxWindowBase::GetDefaultBorder();
1449 // Translate wxBORDER_THEME (and other border styles if necessary) to the value
1450 // that makes most sense for this Windows environment
1451 wxBorder
wxWindowMSW::TranslateBorder(wxBorder border
) const
1453 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
1454 if (border
== wxBORDER_THEME
|| border
== wxBORDER_SUNKEN
|| border
== wxBORDER_SIMPLE
)
1455 return wxBORDER_SIMPLE
;
1457 return wxBORDER_NONE
;
1460 if (border
== wxBORDER_THEME
)
1462 if (CanApplyThemeBorder())
1464 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
1466 return wxBORDER_THEME
;
1468 return wxBORDER_SUNKEN
;
1476 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1478 // translate common wxWidgets styles to Windows ones
1480 // most of windows are child ones, those which are not (such as
1481 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1482 WXDWORD style
= WS_CHILD
;
1484 // using this flag results in very significant reduction in flicker,
1485 // especially with controls inside the static boxes (as the interior of the
1486 // box is not redrawn twice), but sometimes results in redraw problems, so
1487 // optionally allow the old code to continue to use it provided a special
1488 // system option is turned on
1489 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1490 || (flags
& wxCLIP_CHILDREN
) )
1491 style
|= WS_CLIPCHILDREN
;
1493 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1494 // don't support overlapping windows and it only makes sense for them and,
1495 // presumably, gives the system some extra work (to manage more clipping
1496 // regions), so avoid it alltogether
1499 if ( flags
& wxVSCROLL
)
1500 style
|= WS_VSCROLL
;
1502 if ( flags
& wxHSCROLL
)
1503 style
|= WS_HSCROLL
;
1505 const wxBorder border
= TranslateBorder(GetBorder(flags
));
1507 // After translation, border is now optimized for the specific version of Windows
1508 // and theme engine presence.
1510 // WS_BORDER is only required for wxBORDER_SIMPLE
1511 if ( border
== wxBORDER_SIMPLE
)
1514 // now deal with ext style if the caller wants it
1520 if ( flags
& wxTRANSPARENT_WINDOW
)
1521 *exstyle
|= WS_EX_TRANSPARENT
;
1527 case wxBORDER_DEFAULT
:
1528 wxFAIL_MSG( wxT("unknown border style") );
1532 case wxBORDER_SIMPLE
:
1533 case wxBORDER_THEME
:
1536 case wxBORDER_STATIC
:
1537 *exstyle
|= WS_EX_STATICEDGE
;
1540 case wxBORDER_RAISED
:
1541 *exstyle
|= WS_EX_DLGMODALFRAME
;
1544 case wxBORDER_SUNKEN
:
1545 *exstyle
|= WS_EX_CLIENTEDGE
;
1546 style
&= ~WS_BORDER
;
1549 // case wxBORDER_DOUBLE:
1550 // *exstyle |= WS_EX_DLGMODALFRAME;
1554 // wxUniv doesn't use Windows dialog navigation functions at all
1555 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1556 // to make the dialog navigation work with the nested panels we must
1557 // use this style (top level windows such as dialogs don't need it)
1558 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1560 *exstyle
|= WS_EX_CONTROLPARENT
;
1562 #endif // __WXUNIVERSAL__
1568 // Setup background and foreground colours correctly
1569 void wxWindowMSW::SetupColours()
1572 SetBackgroundColour(GetParent()->GetBackgroundColour());
1575 bool wxWindowMSW::IsMouseInWindow() const
1577 // get the mouse position
1580 ::GetCursorPosWinCE(&pt
);
1582 ::GetCursorPos(&pt
);
1585 // find the window which currently has the cursor and go up the window
1586 // chain until we find this window - or exhaust it
1587 HWND hwnd
= ::WindowFromPoint(pt
);
1588 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1589 hwnd
= ::GetParent(hwnd
);
1591 return hwnd
!= NULL
;
1594 void wxWindowMSW::OnInternalIdle()
1596 #ifndef HAVE_TRACKMOUSEEVENT
1597 // Check if we need to send a LEAVE event
1598 if ( m_mouseInWindow
)
1600 // note that we should generate the leave event whether the window has
1601 // or doesn't have mouse capture
1602 if ( !IsMouseInWindow() )
1604 GenerateMouseLeave();
1607 #endif // !HAVE_TRACKMOUSEEVENT
1609 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1610 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1613 // Set this window to be the child of 'parent'.
1614 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1616 if ( !wxWindowBase::Reparent(parent
) )
1619 HWND hWndChild
= GetHwnd();
1620 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1622 ::SetParent(hWndChild
, hWndParent
);
1625 if ( wxHasWindowExStyle(this, WS_EX_CONTROLPARENT
) )
1627 EnsureParentHasControlParentStyle(GetParent());
1629 #endif // !__WXWINCE__
1634 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1636 #ifndef __WXMICROWIN__
1637 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1641 void wxWindowMSW::DoFreeze()
1644 return; // no point in freezing hidden window
1646 SendSetRedraw(GetHwnd(), false);
1649 void wxWindowMSW::DoThaw()
1652 return; // hidden windows aren't frozen by DoFreeze
1654 SendSetRedraw(GetHwnd(), true);
1656 // we need to refresh everything or otherwise the invalidated area
1657 // is not going to be repainted
1661 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1663 HWND hWnd
= GetHwnd();
1670 wxCopyRectToRECT(*rect
, mswRect
);
1678 // RedrawWindow not available on SmartPhone or eVC++ 3
1679 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1680 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1684 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1686 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1691 void wxWindowMSW::Update()
1693 if ( !::UpdateWindow(GetHwnd()) )
1695 wxLogLastError(wxT("UpdateWindow"));
1698 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1699 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1700 // handler needs to be really drawn right now
1705 // ---------------------------------------------------------------------------
1707 // ---------------------------------------------------------------------------
1709 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1713 // we need to lower the sibling static boxes so controls contained within can be
1715 static void AdjustStaticBoxZOrder(wxWindow
*parent
)
1717 // no sibling static boxes if we have no parent (ie TLW)
1721 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1723 node
= node
->GetNext() )
1725 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1728 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1729 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1734 #else // !wxUSE_STATBOX
1736 static inline void AdjustStaticBoxZOrder(wxWindow
* WXUNUSED(parent
))
1740 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1742 #endif // drag and drop is used
1744 #if wxUSE_DRAG_AND_DROP
1745 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1747 if ( m_dropTarget
!= 0 ) {
1748 m_dropTarget
->Revoke(m_hWnd
);
1749 delete m_dropTarget
;
1752 m_dropTarget
= pDropTarget
;
1753 if ( m_dropTarget
!= 0 )
1755 AdjustStaticBoxZOrder(GetParent());
1756 m_dropTarget
->Register(m_hWnd
);
1759 #endif // wxUSE_DRAG_AND_DROP
1761 // old-style file manager drag&drop support: we retain the old-style
1762 // DragAcceptFiles in parallel with SetDropTarget.
1763 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1766 HWND hWnd
= GetHwnd();
1769 AdjustStaticBoxZOrder(GetParent());
1770 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1775 // ----------------------------------------------------------------------------
1777 // ----------------------------------------------------------------------------
1781 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1783 wxWindowBase::DoSetToolTip(tooltip
);
1786 m_tooltip
->SetWindow((wxWindow
*)this);
1789 #endif // wxUSE_TOOLTIPS
1791 // ---------------------------------------------------------------------------
1792 // moving and resizing
1793 // ---------------------------------------------------------------------------
1795 bool wxWindowMSW::IsSizeDeferred() const
1797 #if wxUSE_DEFERRED_SIZING
1798 if ( m_pendingPosition
!= wxDefaultPosition
||
1799 m_pendingSize
!= wxDefaultSize
)
1801 #endif // wxUSE_DEFERRED_SIZING
1807 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1809 #if wxUSE_DEFERRED_SIZING
1810 // if SetSize() had been called at wx level but not realized at Windows
1811 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1812 // the new and not the old position to the other wx code
1813 if ( m_pendingSize
!= wxDefaultSize
)
1816 *x
= m_pendingSize
.x
;
1818 *y
= m_pendingSize
.y
;
1820 else // use current size
1821 #endif // wxUSE_DEFERRED_SIZING
1823 RECT rect
= wxGetWindowRect(GetHwnd());
1826 *x
= rect
.right
- rect
.left
;
1828 *y
= rect
.bottom
- rect
.top
;
1832 // Get size *available for subwindows* i.e. excluding menu bar etc.
1833 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1835 #if wxUSE_DEFERRED_SIZING
1836 if ( m_pendingSize
!= wxDefaultSize
)
1838 // we need to calculate the client size corresponding to pending size
1840 // FIXME: Unfortunately this doesn't work correctly for the maximized
1841 // top level windows, the returned values are too small (e.g.
1842 // under Windows 7 on a 1600*1200 screen with task bar on the
1843 // right the pending size for a maximized window is 1538*1200
1844 // and WM_NCCALCSIZE returns 1528*1172 even though the correct
1845 // client size of such window is 1538*1182). No idea how to fix
1846 // it though, setting WS_MAXIMIZE in GWL_STYLE before calling
1847 // WM_NCCALCSIZE doesn't help and AdjustWindowRectEx() doesn't
1848 // work in this direction neither. So we just have to live with
1849 // the slightly wrong results and relayout the window when it
1850 // gets finally shown in its maximized state (see #11762).
1852 rect
.left
= m_pendingPosition
.x
;
1853 rect
.top
= m_pendingPosition
.y
;
1854 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1855 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1857 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1860 *x
= rect
.right
- rect
.left
;
1862 *y
= rect
.bottom
- rect
.top
;
1865 #endif // wxUSE_DEFERRED_SIZING
1867 RECT rect
= wxGetClientRect(GetHwnd());
1876 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1878 wxWindow
* const parent
= GetParent();
1881 #if wxUSE_DEFERRED_SIZING
1882 if ( m_pendingPosition
!= wxDefaultPosition
)
1884 pos
= m_pendingPosition
;
1886 else // use current position
1887 #endif // wxUSE_DEFERRED_SIZING
1889 RECT rect
= wxGetWindowRect(GetHwnd());
1892 point
.x
= rect
.left
;
1895 // we do the adjustments with respect to the parent only for the "real"
1896 // children, not for the dialogs/frames
1897 if ( !IsTopLevel() )
1899 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
1901 // In RTL mode, we want the logical left x-coordinate,
1902 // which would be the physical right x-coordinate.
1903 point
.x
= rect
.right
;
1906 // Since we now have the absolute screen coords, if there's a
1907 // parent we must subtract its top left corner
1910 ::ScreenToClient(GetHwndOf(parent
), &point
);
1918 // we also must adjust by the client area offset: a control which is just
1919 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1920 if ( parent
&& !IsTopLevel() )
1922 const wxPoint
pt(parent
->GetClientAreaOrigin());
1933 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1941 ::ScreenToClient(GetHwnd(), &pt
);
1949 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1957 ::ClientToScreen(GetHwnd(), &pt
);
1966 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1968 #if wxUSE_DEFERRED_SIZING
1969 // if our parent had prepared a defer window handle for us, use it (unless
1970 // we are a top level window)
1971 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1973 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1976 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1977 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1980 wxLogLastError(wxT("DeferWindowPos"));
1986 // hdwp must be updated as it may have been changed
1987 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1992 // did deferred move, remember new coordinates of the window as they're
1993 // different from what Windows would return for it
1997 // otherwise (or if deferring failed) move the window in place immediately
1998 #endif // wxUSE_DEFERRED_SIZING
1999 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
2001 wxLogLastError(wxT("MoveWindow"));
2004 // if wxUSE_DEFERRED_SIZING, indicates that we didn't use deferred move,
2005 // ignored otherwise
2009 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
2011 // TODO: is this consistent with other platforms?
2012 // Still, negative width or height shouldn't be allowed
2018 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
2020 #if wxUSE_DEFERRED_SIZING
2021 m_pendingPosition
= wxPoint(x
, y
);
2022 m_pendingSize
= wxSize(width
, height
);
2024 else // window was moved immediately, without deferring it
2026 m_pendingPosition
= wxDefaultPosition
;
2027 m_pendingSize
= wxDefaultSize
;
2028 #endif // wxUSE_DEFERRED_SIZING
2032 // set the size of the window: if the dimensions are positive, just use them,
2033 // but if any of them is equal to -1, it means that we must find the value for
2034 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
2035 // which case -1 is a valid value for x and y)
2037 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
2038 // the width/height to best suit our contents, otherwise we reuse the current
2040 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
2042 // get the current size and position...
2043 int currentX
, currentY
;
2044 int currentW
, currentH
;
2046 GetPosition(¤tX
, ¤tY
);
2047 GetSize(¤tW
, ¤tH
);
2049 // ... and don't do anything (avoiding flicker) if it's already ok unless
2050 // we're forced to resize the window
2051 if ( x
== currentX
&& y
== currentY
&&
2052 width
== currentW
&& height
== currentH
&&
2053 !(sizeFlags
& wxSIZE_FORCE
) )
2055 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
2057 wxSizeEvent
event( wxSize(width
,height
), GetId() );
2058 event
.SetEventObject( this );
2059 HandleWindowEvent( event
);
2064 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2066 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2069 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2071 wxSize size
= wxDefaultSize
;
2072 if ( width
== wxDefaultCoord
)
2074 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2076 size
= GetBestSize();
2081 // just take the current one
2086 if ( height
== wxDefaultCoord
)
2088 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2090 if ( size
.x
== wxDefaultCoord
)
2092 size
= GetBestSize();
2094 //else: already called GetBestSize() above
2100 // just take the current one
2105 DoMoveWindow(x
, y
, width
, height
);
2108 void wxWindowMSW::DoSetClientSize(int width
, int height
)
2110 // setting the client size is less obvious than it could have been
2111 // because in the result of changing the total size the window scrollbar
2112 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
2113 // doesn't take neither into account) and so the client size will not be
2114 // correct as the difference between the total and client size changes --
2115 // so we keep changing it until we get it right
2117 // normally this loop shouldn't take more than 3 iterations (usually 1 but
2118 // if scrollbars [dis]appear as the result of the first call, then 2 and it
2119 // may become 3 if the window had 0 size originally and so we didn't
2120 // calculate the scrollbar correction correctly during the first iteration)
2121 // but just to be on the safe side we check for it instead of making it an
2122 // "infinite" loop (i.e. leaving break inside as the only way to get out)
2123 for ( int i
= 0; i
< 4; i
++ )
2126 ::GetClientRect(GetHwnd(), &rectClient
);
2128 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
2129 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
2130 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
2135 // Find the difference between the entire window (title bar and all)
2136 // and the client area; add this to the new client size to move the
2139 ::GetWindowRect(GetHwnd(), &rectWin
);
2141 const int widthWin
= rectWin
.right
- rectWin
.left
,
2142 heightWin
= rectWin
.bottom
- rectWin
.top
;
2144 // MoveWindow positions the child windows relative to the parent, so
2145 // adjust if necessary
2146 if ( !IsTopLevel() )
2148 wxWindow
*parent
= GetParent();
2151 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
2155 // don't call DoMoveWindow() because we want to move window immediately
2156 // and not defer it here as otherwise the value returned by
2157 // GetClient/WindowRect() wouldn't change as the window wouldn't be
2159 if ( !::MoveWindow(GetHwnd(),
2162 width
+ widthWin
- rectClient
.right
,
2163 height
+ heightWin
- rectClient
.bottom
,
2166 wxLogLastError(wxT("MoveWindow"));
2171 wxSize
wxWindowMSW::DoGetBorderSize() const
2174 switch ( GetBorder() )
2176 case wxBORDER_STATIC
:
2177 case wxBORDER_SIMPLE
:
2181 case wxBORDER_SUNKEN
:
2185 case wxBORDER_RAISED
:
2186 case wxBORDER_DOUBLE
:
2191 wxFAIL_MSG( wxT("unknown border style") );
2198 return 2*wxSize(border
, border
);
2201 // ---------------------------------------------------------------------------
2203 // ---------------------------------------------------------------------------
2205 int wxWindowMSW::GetCharHeight() const
2207 return wxGetTextMetrics(this).tmHeight
;
2210 int wxWindowMSW::GetCharWidth() const
2212 // +1 is needed because Windows apparently adds it when calculating the
2213 // dialog units size in pixels
2214 #if wxDIALOG_UNIT_COMPATIBILITY
2215 return wxGetTextMetrics(this).tmAveCharWidth
;
2217 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
2221 void wxWindowMSW::DoGetTextExtent(const wxString
& string
,
2224 int *externalLeading
,
2225 const wxFont
*fontToUse
) const
2227 wxASSERT_MSG( !fontToUse
|| fontToUse
->Ok(),
2228 wxT("invalid font in GetTextExtent()") );
2232 hfontToUse
= GetHfontOf(*fontToUse
);
2234 hfontToUse
= GetHfontOf(GetFont());
2236 WindowHDC
hdc(GetHwnd());
2237 SelectInHDC
selectFont(hdc
, hfontToUse
);
2241 ::GetTextExtentPoint32(hdc
, string
.wx_str(), string
.length(), &sizeRect
);
2242 GetTextMetrics(hdc
, &tm
);
2249 *descent
= tm
.tmDescent
;
2250 if ( externalLeading
)
2251 *externalLeading
= tm
.tmExternalLeading
;
2254 // ---------------------------------------------------------------------------
2256 // ---------------------------------------------------------------------------
2258 #if wxUSE_MENUS_NATIVE
2260 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2261 // immediately, without waiting for the next event loop iteration
2263 // NB: this function should probably be made public later as it can almost
2264 // surely replace wxYield() elsewhere as well
2265 static void wxYieldForCommandsOnly()
2267 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2268 // want to process it here)
2270 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2272 if ( msg
.message
== WM_QUIT
)
2274 // if we retrieved a WM_QUIT, insert back into the message queue.
2275 ::PostQuitMessage(0);
2279 // luckily (as we don't have access to wxEventLoopImpl method from here
2280 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2282 ::TranslateMessage(&msg
);
2283 ::DispatchMessage(&msg
);
2287 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2291 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2293 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2294 x
= mouse
.x
; y
= mouse
.y
;
2297 HWND hWnd
= GetHwnd();
2298 HMENU hMenu
= GetHmenuOf(menu
);
2302 ::ClientToScreen(hWnd
, &point
);
2303 #if defined(__WXWINCE__)
2304 static const UINT flags
= 0;
2305 #else // !__WXWINCE__
2306 UINT flags
= TPM_RIGHTBUTTON
;
2307 // NT4 doesn't support TPM_RECURSE and simply doesn't show the menu at all
2308 // when it's use, I'm not sure about Win95/98 but prefer to err on the safe
2309 // side and not to use it there neither -- modify the test if it does work
2311 if ( wxGetWinVersion() >= wxWinVersion_5
)
2313 // using TPM_RECURSE allows us to show a popup menu while another menu
2314 // is opened which can be useful and is supported by the other
2315 // platforms, so allow it under Windows too
2316 flags
|= TPM_RECURSE
;
2318 #endif // __WXWINCE__/!__WXWINCE__
2320 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2322 // we need to do it right now as otherwise the events are never going to be
2323 // sent to wxCurrentPopupMenu from HandleCommand()
2325 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2326 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2327 // destroyed as soon as we return (it can be a local variable in the caller
2328 // for example) and so we do need to process the event immediately
2329 wxYieldForCommandsOnly();
2334 #endif // wxUSE_MENUS_NATIVE
2336 // ===========================================================================
2337 // pre/post message processing
2338 // ===========================================================================
2340 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2343 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2345 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2348 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2350 // wxUniversal implements tab traversal itself
2351 #ifndef __WXUNIVERSAL__
2352 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2354 // intercept dialog navigation keys
2355 MSG
*msg
= (MSG
*)pMsg
;
2357 // here we try to do all the job which ::IsDialogMessage() usually does
2359 if ( msg
->message
== WM_KEYDOWN
)
2361 bool bCtrlDown
= wxIsCtrlDown();
2362 bool bShiftDown
= wxIsShiftDown();
2364 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2365 // don't process it if it's the case (except for Ctrl-Tab/Enter
2366 // combinations which are always processed)
2367 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2369 // surprisingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2370 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2371 // it, of course, implies them
2372 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2374 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2377 bool bForward
= true,
2378 bWindowChange
= false,
2381 // should we process this message specially?
2382 bool bProcess
= true;
2383 switch ( msg
->wParam
)
2386 if ( (lDlgCode
& DLGC_WANTTAB
) && !bCtrlDown
)
2388 // let the control have the TAB
2391 else // use it for navigation
2393 // Ctrl-Tab cycles thru notebook pages
2394 bWindowChange
= bCtrlDown
;
2395 bForward
= !bShiftDown
;
2402 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2410 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2419 // we treat PageUp/Dn as arrows because chances are that
2420 // a control which needs arrows also needs them for
2421 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2422 if ( (lDlgCode
& DLGC_WANTARROWS
) && !bCtrlDown
)
2424 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
2425 bWindowChange
= true;
2431 // currently active button should get enter press even
2432 // if there is a default button elsewhere so check if
2433 // this window is a button first
2434 wxWindow
*btn
= NULL
;
2435 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2437 // let IsDialogMessage() handle this for all
2438 // buttons except the owner-drawn ones which it
2439 // just seems to ignore
2440 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2441 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2443 // emulate the button click
2444 btn
= wxFindWinFromHandle(msg
->hwnd
);
2449 else // not a button itself, do we have default button?
2451 // check if this window or any of its ancestors
2452 // wants the message for itself (we always reserve
2453 // Ctrl-Enter for dialog navigation though)
2454 wxWindow
*win
= this;
2457 // this will contain the dialog code of this
2458 // window and all of its parent windows in turn
2459 LONG lDlgCode2
= lDlgCode
;
2463 if ( lDlgCode2
& DLGC_WANTMESSAGE
)
2465 // as it wants to process Enter itself,
2466 // don't call IsDialogMessage() which
2471 // don't propagate keyboard messages beyond
2472 // the first top level window parent
2473 if ( win
->IsTopLevel() )
2476 win
= win
->GetParent();
2478 lDlgCode2
= ::SendMessage
2489 win
= wxGetTopLevelParent(win
);
2492 wxTopLevelWindow
* const
2493 tlw
= wxDynamicCast(win
, wxTopLevelWindow
);
2496 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2501 if ( btn
&& btn
->IsEnabled() )
2503 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2507 #endif // wxUSE_BUTTON
2510 // map Enter presses into button presses on PDAs
2511 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2512 event
.SetEventObject(this);
2513 if ( HandleWindowEvent(event
) )
2515 #endif // __WXWINCE__
2525 wxNavigationKeyEvent event
;
2526 event
.SetDirection(bForward
);
2527 event
.SetWindowChange(bWindowChange
);
2528 event
.SetFromTab(bFromTab
);
2529 event
.SetEventObject(this);
2531 if ( HandleWindowEvent(event
) )
2533 // as we don't call IsDialogMessage(), which would take of
2534 // this by default, we need to manually send this message
2535 // so that controls can change their UI state if needed
2536 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2543 if ( ::IsDialogMessage(GetHwnd(), msg
) )
2545 // IsDialogMessage() did something...
2549 #endif // __WXUNIVERSAL__
2554 // relay mouse move events to the tooltip control
2555 MSG
*msg
= (MSG
*)pMsg
;
2556 if ( msg
->message
== WM_MOUSEMOVE
)
2557 wxToolTip::RelayEvent(pMsg
);
2559 #endif // wxUSE_TOOLTIPS
2564 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2566 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2567 return m_acceleratorTable
.Translate(this, pMsg
);
2571 #endif // wxUSE_ACCEL
2574 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* msg
)
2576 // all tests below have to deal with various bugs/misfeatures of
2577 // IsDialogMessage(): we have to prevent it from being called from our
2578 // MSWProcessMessage() in some situations
2580 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2581 // message even when there is no cancel button and when the message is
2582 // needed by the control itself: in particular, it prevents the tree in
2583 // place edit control from being closed with Escape in a dialog
2584 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_ESCAPE
)
2589 // ::IsDialogMessage() is broken and may sometimes hang the application by
2590 // going into an infinite loop when it tries to find the control to give
2591 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2592 // situations when this may happen and not call it then
2593 if ( msg
->message
!= WM_SYSCHAR
)
2596 // assume we can call it by default
2597 bool canSafelyCallIsDlgMsg
= true;
2599 HWND hwndFocus
= ::GetFocus();
2601 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2602 // ::IsDialogMessage() will also enter an infinite loop, because it will
2603 // recursively check the child windows but not the window itself and so if
2604 // none of the children accepts focus it loops forever (as it only stops
2605 // when it gets back to the window it started from)
2607 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2608 // style has the focus, it can happen. One such possibility is if
2609 // all windows are either toplevel, wxDialog, wxPanel or static
2610 // controls and no window can actually accept keyboard input.
2611 #if !defined(__WXWINCE__)
2612 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2614 // pessimistic by default
2615 canSafelyCallIsDlgMsg
= false;
2616 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2618 node
= node
->GetNext() )
2620 wxWindow
* const win
= node
->GetData();
2621 if ( win
->CanAcceptFocus() &&
2622 !wxHasWindowExStyle(win
, WS_EX_CONTROLPARENT
) )
2624 // it shouldn't hang...
2625 canSafelyCallIsDlgMsg
= true;
2631 #endif // !__WXWINCE__
2633 if ( canSafelyCallIsDlgMsg
)
2635 // ::IsDialogMessage() can enter in an infinite loop when the
2636 // currently focused window is disabled or hidden and its
2637 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2641 if ( !::IsWindowEnabled(hwndFocus
) ||
2642 !::IsWindowVisible(hwndFocus
) )
2644 // it would enter an infinite loop if we do this!
2645 canSafelyCallIsDlgMsg
= false;
2650 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2652 // it's a top level window, don't go further -- e.g. even
2653 // if the parent of a dialog is disabled, this doesn't
2654 // break navigation inside the dialog
2658 hwndFocus
= ::GetParent(hwndFocus
);
2662 return canSafelyCallIsDlgMsg
;
2665 // ---------------------------------------------------------------------------
2666 // message params unpackers
2667 // ---------------------------------------------------------------------------
2669 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2670 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2672 *id
= LOWORD(wParam
);
2673 *hwnd
= (WXHWND
)lParam
;
2674 *cmd
= HIWORD(wParam
);
2677 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2678 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2680 *state
= LOWORD(wParam
);
2681 *minimized
= HIWORD(wParam
);
2682 *hwnd
= (WXHWND
)lParam
;
2685 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2686 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2688 *code
= LOWORD(wParam
);
2689 *pos
= HIWORD(wParam
);
2690 *hwnd
= (WXHWND
)lParam
;
2693 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2694 WXHDC
*hdc
, WXHWND
*hwnd
)
2696 *hwnd
= (WXHWND
)lParam
;
2697 *hdc
= (WXHDC
)wParam
;
2700 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2701 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2703 *item
= (WXWORD
)wParam
;
2704 *flags
= HIWORD(wParam
);
2705 *hmenu
= (WXHMENU
)lParam
;
2708 // ---------------------------------------------------------------------------
2709 // Main wxWidgets window proc and the window proc for wxWindow
2710 // ---------------------------------------------------------------------------
2712 // Hook for new window just as it's being created, when the window isn't yet
2713 // associated with the handle
2714 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2716 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2717 // window being created and insures that it's always unset back later
2718 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2720 gs_winBeingCreated
= winBeingCreated
;
2723 wxWindowCreationHook::~wxWindowCreationHook()
2725 gs_winBeingCreated
= NULL
;
2729 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2731 // trace all messages: useful for the debugging but noticeably slows down
2732 // the code so don't do it by default
2733 #if wxDEBUG_LEVEL >= 2
2734 // notice that we cast wParam and lParam to long to avoid mismatch with
2735 // format specifiers in 64 bit builds where they are both int64 quantities
2737 // casting like this loses information, of course, but it shouldn't matter
2738 // much for this diagnostic code and it keeps the code simple
2739 wxLogTrace("winmsg",
2740 wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"),
2741 wxGetMessageName(message
), hWnd
, (long)wParam
, (long)lParam
);
2742 #endif // wxDEBUG_LEVEL >= 2
2744 wxWindowMSW
*wnd
= wxFindWinFromHandle(hWnd
);
2746 // when we get the first message for the HWND we just created, we associate
2747 // it with wxWindow stored in gs_winBeingCreated
2748 if ( !wnd
&& gs_winBeingCreated
)
2750 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2751 wnd
= gs_winBeingCreated
;
2752 gs_winBeingCreated
= NULL
;
2753 wnd
->SetHWND((WXHWND
)hWnd
);
2758 if ( wnd
&& wxGUIEventLoop::AllowProcessing(wnd
) )
2759 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2761 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2766 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2768 // did we process the message?
2769 bool processed
= false;
2779 // for most messages we should return 0 when we do process the message
2787 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2790 // return 0 to allow window creation
2791 rc
.result
= mayCreate
? 0 : -1;
2797 // never set processed to true and *always* pass WM_DESTROY to
2798 // DefWindowProc() as Windows may do some internal cleanup when
2799 // processing it and failing to pass the message along may cause
2800 // memory and resource leaks!
2801 (void)HandleDestroy();
2805 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2809 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2812 #if !defined(__WXWINCE__)
2815 LPRECT pRect
= (LPRECT
)lParam
;
2817 rc
.SetLeft(pRect
->left
);
2818 rc
.SetTop(pRect
->top
);
2819 rc
.SetRight(pRect
->right
);
2820 rc
.SetBottom(pRect
->bottom
);
2821 processed
= HandleMoving(rc
);
2823 pRect
->left
= rc
.GetLeft();
2824 pRect
->top
= rc
.GetTop();
2825 pRect
->right
= rc
.GetRight();
2826 pRect
->bottom
= rc
.GetBottom();
2831 case WM_ENTERSIZEMOVE
:
2833 processed
= HandleEnterSizeMove();
2837 case WM_EXITSIZEMOVE
:
2839 processed
= HandleExitSizeMove();
2845 LPRECT pRect
= (LPRECT
)lParam
;
2847 rc
.SetLeft(pRect
->left
);
2848 rc
.SetTop(pRect
->top
);
2849 rc
.SetRight(pRect
->right
);
2850 rc
.SetBottom(pRect
->bottom
);
2851 processed
= HandleSizing(rc
);
2853 pRect
->left
= rc
.GetLeft();
2854 pRect
->top
= rc
.GetTop();
2855 pRect
->right
= rc
.GetRight();
2856 pRect
->bottom
= rc
.GetBottom();
2860 #endif // !__WXWINCE__
2862 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2863 case WM_ACTIVATEAPP
:
2864 // This implicitly sends a wxEVT_ACTIVATE_APP event
2865 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2871 WXWORD state
, minimized
;
2873 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2875 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2880 processed
= HandleSetFocus((WXHWND
)wParam
);
2884 processed
= HandleKillFocus((WXHWND
)wParam
);
2887 case WM_PRINTCLIENT
:
2888 processed
= HandlePrintClient((WXHDC
)wParam
);
2894 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2896 processed
= HandlePaint();
2900 processed
= HandlePaint();
2905 #ifdef __WXUNIVERSAL__
2906 // Universal uses its own wxFrame/wxDialog, so we don't receive
2907 // close events unless we have this.
2909 #endif // __WXUNIVERSAL__
2911 // don't let the DefWindowProc() destroy our window - we'll do it
2912 // ourselves in ~wxWindow
2918 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2922 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2923 GET_Y_LPARAM(lParam
),
2927 #ifdef HAVE_TRACKMOUSEEVENT
2929 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2931 if ( m_mouseInWindow
)
2933 GenerateMouseLeave();
2936 // always pass processed back as false, this allows the window
2937 // manager to process the message too. This is needed to
2938 // ensure windows XP themes work properly as the mouse moves
2939 // over widgets like buttons. So don't set processed to true here.
2941 #endif // HAVE_TRACKMOUSEEVENT
2943 #if wxUSE_MOUSEWHEEL
2945 processed
= HandleMouseWheel(wParam
, lParam
);
2949 case WM_LBUTTONDOWN
:
2951 case WM_LBUTTONDBLCLK
:
2952 case WM_RBUTTONDOWN
:
2954 case WM_RBUTTONDBLCLK
:
2955 case WM_MBUTTONDOWN
:
2957 case WM_MBUTTONDBLCLK
:
2958 #ifdef wxHAS_XBUTTON
2959 case WM_XBUTTONDOWN
:
2961 case WM_XBUTTONDBLCLK
:
2962 #endif // wxHAS_XBUTTON
2964 #ifdef __WXMICROWIN__
2965 // MicroWindows seems to ignore the fact that a window is
2966 // disabled. So catch mouse events and throw them away if
2968 wxWindowMSW
* win
= this;
2971 if (!win
->IsEnabled())
2977 win
= win
->GetParent();
2978 if ( !win
|| win
->IsTopLevel() )
2985 #endif // __WXMICROWIN__
2986 int x
= GET_X_LPARAM(lParam
),
2987 y
= GET_Y_LPARAM(lParam
);
2990 // redirect the event to a static control if necessary by
2991 // finding one under mouse because under CE the static controls
2992 // don't generate mouse events (even with SS_NOTIFY)
2994 if ( GetCapture() == this )
2996 // but don't do it if the mouse is captured by this window
2997 // because then it should really get this event itself
3002 win
= FindWindowForMouseEvent(this, &x
, &y
);
3004 // this should never happen
3005 wxCHECK_MSG( win
, 0,
3006 wxT("FindWindowForMouseEvent() returned NULL") );
3009 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
3011 SHRGINFO shrgi
= {0};
3013 shrgi
.cbSize
= sizeof(SHRGINFO
);
3014 shrgi
.hwndClient
= (HWND
) GetHWND();
3018 shrgi
.dwFlags
= SHRG_RETURNCMD
;
3019 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
3021 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
3024 pt
= ClientToScreen(pt
);
3026 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3028 evtCtx
.SetEventObject(this);
3029 if (HandleWindowEvent(evtCtx
))
3038 #else // !__WXWINCE__
3039 wxWindowMSW
*win
= this;
3040 #endif // __WXWINCE__/!__WXWINCE__
3042 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
3044 // if the app didn't eat the event, handle it in the default
3045 // way, that is by giving this window the focus
3048 // for the standard classes their WndProc sets the focus to
3049 // them anyhow and doing it from here results in some weird
3050 // problems, so don't do it for them (unnecessary anyhow)
3051 if ( !win
->IsOfStandardClass() )
3053 if ( message
== WM_LBUTTONDOWN
&& win
->IsFocusable() )
3065 case MM_JOY1BUTTONDOWN
:
3066 case MM_JOY2BUTTONDOWN
:
3067 case MM_JOY1BUTTONUP
:
3068 case MM_JOY2BUTTONUP
:
3069 processed
= HandleJoystickEvent(message
,
3070 GET_X_LPARAM(lParam
),
3071 GET_Y_LPARAM(lParam
),
3074 #endif // __WXMICROWIN__
3080 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
3082 processed
= HandleCommand(id
, cmd
, hwnd
);
3087 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
3090 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
3091 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
3092 // apparently doesn't always behave properly and needs some help
3093 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
3094 case WM_NOTIFYFORMAT
:
3095 if ( lParam
== NF_QUERY
)
3098 rc
.result
= NFR_UNICODE
;
3101 #endif // wxUSE_UNICODE_MSLU
3103 // for these messages we must return true if process the message
3106 processed
= MSWOnDrawItem(wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
3111 case WM_MEASUREITEM
:
3112 processed
= MSWOnMeasureItem(wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
3116 #endif // defined(WM_DRAWITEM)
3119 if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS
) )
3121 // we always want to get the char events
3122 rc
.result
= DLGC_WANTCHARS
;
3124 if ( HasFlag(wxWANTS_CHARS
) )
3126 // in fact, we want everything
3127 rc
.result
|= DLGC_WANTARROWS
|
3134 //else: get the dlg code from the DefWindowProc()
3139 // Generate the key down event in any case.
3140 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
3141 if ( m_lastKeydownProcessed
)
3143 // If it was processed by an event handler, we stop here,
3144 // notably we intentionally don't generate char event then.
3147 else // key down event not handled
3149 // Examine the event to decide whether we need to generate a
3150 // char event for it ourselves or let Windows do it. Window
3151 // mostly only does it for the keys which produce printable
3152 // characters (although there are exceptions, e.g. VK_ESCAPE or
3153 // VK_BACK (but not VK_DELETE)) while we do it for all keys
3154 // except the modifier ones (the wisdom of this is debatable
3155 // but by now this decision is enshrined forever due to
3156 // backwards compatibility).
3159 // No wxEVT_CHAR events are generated for these keys at all.
3167 // Windows will send us WM_CHAR for these ones so we'll
3168 // generate wxEVT_CHAR for them later when we get it.
3203 // special case of VK_APPS: treat it the same as right mouse
3204 // click because both usually pop up a context menu
3206 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
3211 if ( (wParam
>= '0' && wParam
<= '9') ||
3212 (wParam
>= 'A' && wParam
<= 'Z') )
3214 // We'll get WM_CHAR for those later too.
3218 // But for the rest we won't get WM_CHAR later so we do
3219 // need to generate the event right now.
3220 wxKeyEvent
event(wxEVT_CHAR
);
3221 InitAnyKeyEvent(event
, wParam
, lParam
);
3223 // Set the "extended" bit in lParam because we want to
3224 // generate CHAR events with WXK_HOME and not
3225 // WXK_NUMPAD_HOME even if the "Home" key on numpad was
3227 event
.m_keyCode
= wxMSWKeyboard::VKToWX
3230 lParam
| (KF_EXTENDED
<< 16)
3232 processed
= HandleWindowEvent(event
);
3235 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
3242 // special case of VK_APPS: treat it the same as right mouse button
3243 if ( wParam
== VK_APPS
)
3245 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
3250 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
3255 case WM_CHAR
: // Always an ASCII character
3256 if ( m_lastKeydownProcessed
)
3258 // The key was handled in the EVT_KEY_DOWN and handling
3259 // a key in an EVT_KEY_DOWN handler is meant, by
3260 // design, to prevent EVT_CHARs from happening
3261 m_lastKeydownProcessed
= false;
3266 processed
= HandleChar((WORD
)wParam
, lParam
);
3272 processed
= HandleHotKey((WORD
)wParam
, lParam
);
3274 #endif // wxUSE_HOTKEY
3279 processed
= HandleClipboardEvent(message
);
3287 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
3289 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
3295 // CTLCOLOR messages are sent by children to query the parent for their
3297 #ifndef __WXMICROWIN__
3298 case WM_CTLCOLORMSGBOX
:
3299 case WM_CTLCOLOREDIT
:
3300 case WM_CTLCOLORLISTBOX
:
3301 case WM_CTLCOLORBTN
:
3302 case WM_CTLCOLORDLG
:
3303 case WM_CTLCOLORSCROLLBAR
:
3304 case WM_CTLCOLORSTATIC
:
3308 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
3310 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
3313 #endif // !__WXMICROWIN__
3315 case WM_SYSCOLORCHANGE
:
3316 // the return value for this message is ignored
3317 processed
= HandleSysColorChange();
3320 #if !defined(__WXWINCE__)
3321 case WM_DISPLAYCHANGE
:
3322 processed
= HandleDisplayChange();
3326 case WM_PALETTECHANGED
:
3327 processed
= HandlePaletteChanged((WXHWND
)wParam
);
3330 case WM_CAPTURECHANGED
:
3331 processed
= HandleCaptureChanged((WXHWND
)lParam
);
3334 case WM_SETTINGCHANGE
:
3335 processed
= HandleSettingChange(wParam
, lParam
);
3338 case WM_QUERYNEWPALETTE
:
3339 processed
= HandleQueryNewPalette();
3344 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
3345 // check if an override was configured for this window
3346 EraseBgHooks::const_iterator it
= gs_eraseBgHooks
.find(this);
3347 if ( it
!= gs_eraseBgHooks
.end() )
3348 processed
= it
->second
->MSWEraseBgHook((WXHDC
)wParam
);
3350 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
3351 processed
= HandleEraseBkgnd((WXHDC
)wParam
);
3356 // we processed the message, i.e. erased the background
3361 #if !defined(__WXWINCE__)
3363 processed
= HandleDropFiles(wParam
);
3368 processed
= HandleInitDialog((WXHWND
)wParam
);
3372 // we never set focus from here
3377 #if !defined(__WXWINCE__)
3378 case WM_QUERYENDSESSION
:
3379 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3383 processed
= HandleEndSession(wParam
!= 0, lParam
);
3386 case WM_GETMINMAXINFO
:
3387 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3392 processed
= HandleSetCursor((WXHWND
)wParam
,
3393 LOWORD(lParam
), // hit test
3394 HIWORD(lParam
)); // mouse msg
3398 // returning TRUE stops the DefWindowProc() from further
3399 // processing this message - exactly what we need because we've
3400 // just set the cursor.
3405 #if wxUSE_ACCESSIBILITY
3408 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3409 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3411 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3413 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3419 #if defined(WM_HELP)
3422 // by default, WM_HELP is propagated by DefWindowProc() upwards
3423 // to the window parent but as we do it ourselves already
3424 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3425 // to get the other events if we process this message at all
3428 // WM_HELP doesn't use lParam under CE
3430 HELPINFO
* info
= (HELPINFO
*) lParam
;
3431 if ( info
->iContextType
== HELPINFO_WINDOW
)
3433 #endif // !__WXWINCE__
3434 wxHelpEvent helpEvent
3439 wxGetMousePosition() // what else?
3441 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3445 helpEvent
.SetEventObject(this);
3446 HandleWindowEvent(helpEvent
);
3449 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3451 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3452 helpEvent
.SetEventObject(this);
3453 HandleWindowEvent(helpEvent
);
3456 else // unknown help event?
3460 #endif // !__WXWINCE__
3465 #if !defined(__WXWINCE__)
3466 case WM_CONTEXTMENU
:
3468 // we don't convert from screen to client coordinates as
3469 // the event may be handled by a parent window
3470 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3472 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3474 // we could have got an event from our child, reflect it back
3475 // to it if this is the case
3476 wxWindowMSW
*win
= NULL
;
3477 WXHWND hWnd
= (WXHWND
)wParam
;
3478 if ( hWnd
!= m_hWnd
)
3480 win
= FindItemByHWND(hWnd
);
3486 evtCtx
.SetEventObject(win
);
3487 processed
= win
->HandleWindowEvent(evtCtx
);
3494 // we're only interested in our own menus, not MF_SYSMENU
3495 if ( HIWORD(wParam
) == MF_POPUP
)
3497 // handle menu chars for ownerdrawn menu items
3498 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3499 if ( i
!= wxNOT_FOUND
)
3501 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3506 #endif // wxUSE_MENUS
3509 case WM_POWERBROADCAST
:
3512 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3513 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3516 #endif // __WXWINCE__
3519 // If we want the default themed border then we need to draw it ourselves
3522 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3523 const wxBorder border
= TranslateBorder(GetBorder());
3524 if (theme
&& border
== wxBORDER_THEME
)
3526 // first ask the widget to calculate the border size
3527 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3530 // now alter the client size making room for drawing a
3533 NCCALCSIZE_PARAMS
*csparam
= NULL
;
3536 csparam
= (NCCALCSIZE_PARAMS
*)lParam
;
3537 rect
= &csparam
->rgrc
[0];
3541 rect
= (RECT
*)lParam
;
3544 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3545 RECT rcClient
= { 0, 0, 0, 0 };
3546 wxClientDC
dc((wxWindow
*)this);
3547 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3549 if ( theme
->GetThemeBackgroundContentRect
3556 &rcClient
) == S_OK
)
3558 InflateRect(&rcClient
, -1, -1);
3560 csparam
->rgrc
[0] = rcClient
;
3562 *((RECT
*)lParam
) = rcClient
;
3564 // WVR_REDRAW triggers a bug whereby child windows are moved up and left,
3566 // rc.result = WVR_REDRAW;
3574 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3575 const wxBorder border
= TranslateBorder(GetBorder());
3576 if (theme
&& border
== wxBORDER_THEME
)
3578 // first ask the widget to paint its non-client area, such as scrollbars, etc.
3579 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3582 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3583 wxWindowDC
dc((wxWindow
*)this);
3584 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3586 // Clip the DC so that you only draw on the non-client area
3588 wxCopyRectToRECT(GetSize(), rcBorder
);
3591 theme
->GetThemeBackgroundContentRect(
3592 hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, ETS_NORMAL
, &rcBorder
, &rcClient
);
3593 InflateRect(&rcClient
, -1, -1);
3595 ::ExcludeClipRect(GetHdcOf(*impl
), rcClient
.left
, rcClient
.top
,
3596 rcClient
.right
, rcClient
.bottom
);
3598 // Make sure the background is in a proper state
3599 if (theme
->IsThemeBackgroundPartiallyTransparent(hTheme
, EP_EDITTEXT
, ETS_NORMAL
))
3601 theme
->DrawThemeParentBackground(GetHwnd(), GetHdcOf(*impl
), &rcBorder
);
3607 nState
= ETS_DISABLED
;
3608 // should we check this?
3609 //else if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & ES_READONLY)
3610 // nState = ETS_READONLY;
3612 nState
= ETS_NORMAL
;
3613 theme
->DrawThemeBackground(hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, nState
, &rcBorder
, NULL
);
3618 #endif // wxUSE_UXTHEME
3621 // try a custom message handler
3622 const MSWMessageHandlers::const_iterator
3623 i
= gs_messageHandlers
.find(message
);
3624 if ( i
!= gs_messageHandlers
.end() )
3626 processed
= (*i
->second
)(this, message
, wParam
, lParam
);
3632 #if wxDEBUG_LEVEL >= 2
3633 wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."),
3634 wxGetMessageName(message
));
3635 #endif // wxDEBUG_LEVEL >= 2
3636 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3642 // ----------------------------------------------------------------------------
3643 // wxWindow <-> HWND map
3644 // ----------------------------------------------------------------------------
3646 wxWindow
*wxFindWinFromHandle(HWND hwnd
)
3648 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3649 return i
== gs_windowHandles
.end() ? NULL
: i
->second
;
3652 void wxAssociateWinWithHandle(HWND hwnd
, wxWindowMSW
*win
)
3654 // adding NULL hwnd is (first) surely a result of an error and
3655 // (secondly) breaks menu command processing
3656 wxCHECK_RET( hwnd
!= (HWND
)NULL
,
3657 wxT("attempt to add a NULL hwnd to window list ignored") );
3660 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3661 if ( i
!= gs_windowHandles
.end() )
3663 if ( i
->second
!= win
)
3667 wxT("HWND %p already associated with another window (%s)"),
3668 hwnd
, win
->GetClassInfo()->GetClassName()
3672 //else: this actually happens currently because we associate the window
3673 // with its HWND during creation (if we create it) and also when
3674 // SubclassWin() is called later, this is ok
3676 #endif // wxDEBUG_LEVEL
3678 gs_windowHandles
[hwnd
] = (wxWindow
*)win
;
3681 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3683 gs_windowHandles
.erase(GetHwndOf(win
));
3686 // ----------------------------------------------------------------------------
3687 // various MSW speciic class dependent functions
3688 // ----------------------------------------------------------------------------
3690 // Default destroyer - override if you destroy it in some other way
3691 // (e.g. with MDI child windows)
3692 void wxWindowMSW::MSWDestroyWindow()
3696 void wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3699 int& w
, int& h
) const
3701 // CW_USEDEFAULT can't be used for child windows so just position them at
3702 // the origin by default
3703 x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
;
3704 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
;
3706 AdjustForParentClientOrigin(x
, y
);
3708 // We don't have any clearly good choice for the size by default neither
3709 // but we must use something non-zero.
3710 w
= WidthDefault(size
.x
);
3711 h
= HeightDefault(size
.y
);
3714 NB: there used to be some code here which set the initial size of the
3715 window to the client size of the parent if no explicit size was
3716 specified. This was wrong because wxWidgets programs often assume
3717 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3718 it. To see why, you should understand that Windows sends WM_SIZE from
3719 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3720 from some base class ctor and so this WM_SIZE is not processed in the
3721 real class' OnSize() (because it's not fully constructed yet and the
3722 event goes to some base class OnSize() instead). So the WM_SIZE we
3723 rely on is the one sent when the parent frame resizes its children
3724 but here is the problem: if the child already has just the right
3725 size, nothing will happen as both wxWidgets and Windows check for
3726 this and ignore any attempts to change the window size to the size it
3727 already has - so no WM_SIZE would be sent.
3731 WXHWND
wxWindowMSW::MSWGetParent() const
3733 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3736 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3737 const wxChar
*title
,
3741 WXDWORD extendedStyle
)
3743 // check a common bug in the user code: if the window is created with a
3744 // non-default ctor and Create() is called too, we'd create 2 HWND for a
3745 // single wxWindow object and this results in all sorts of trouble,
3746 // especially for wxTLWs
3747 wxCHECK_MSG( !m_hWnd
, true, "window can't be recreated" );
3749 // this can happen if this function is called using the return value of
3750 // wxApp::GetRegisteredClassName() which failed
3751 wxCHECK_MSG( wclass
, false, "failed to register window class?" );
3754 // choose the position/size for the new window
3756 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3758 // controlId is menu handle for the top level windows, so set it to 0
3759 // unless we're creating a child window
3760 int controlId
= style
& WS_CHILD
? GetId() : 0;
3762 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3763 // which is the same but without CS_[HV]REDRAW class styles so using it
3764 // ensures that the window is not fully repainted on each resize
3765 wxString
className(wclass
);
3766 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3768 className
+= wxApp::GetNoRedrawClassSuffix();
3771 // do create the window
3772 wxWindowCreationHook
hook(this);
3774 m_hWnd
= (WXHWND
)::CreateWindowEx
3778 title
? title
: m_windowName
.wx_str(),
3781 (HWND
)MSWGetParent(),
3782 (HMENU
)wxUIntToPtr(controlId
),
3784 NULL
// no extra data
3789 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3794 SubclassWin(m_hWnd
);
3799 // ===========================================================================
3800 // MSW message handlers
3801 // ===========================================================================
3803 // ---------------------------------------------------------------------------
3805 // ---------------------------------------------------------------------------
3807 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3809 #ifndef __WXMICROWIN__
3810 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3811 HWND hWnd
= hdr
->hwndFrom
;
3812 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
3814 // if the control is one of our windows, let it handle the message itself
3817 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3820 // VZ: why did we do it? normally this is unnecessary and, besides, it
3821 // breaks the message processing for the toolbars because the tooltip
3822 // notifications were being forwarded to the toolbar child controls
3823 // (if it had any) before being passed to the toolbar itself, so in my
3824 // example the tooltip for the combobox was always shown instead of the
3825 // correct button tooltips
3827 // try all our children
3828 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3831 wxWindow
*child
= node
->GetData();
3832 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3837 node
= node
->GetNext();
3841 // by default, handle it ourselves
3842 return MSWOnNotify(idCtrl
, lParam
, result
);
3843 #else // __WXMICROWIN__
3850 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3852 const wxString
& ttip
)
3854 // I don't know why it happens, but the versions of comctl32.dll starting
3855 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3856 // this message is supposed to be sent to Unicode programs only) -- hence
3857 // we need to handle it as well, otherwise no tooltips will be shown in
3860 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3863 // not a tooltip message or no tooltip to show anyhow
3868 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3870 // We don't want to use the szText buffer because it has a limit of 80
3871 // bytes and this is not enough, especially for Unicode build where it
3872 // limits the tooltip string length to only 40 characters
3874 // The best would be, of course, to not impose any length limitations at
3875 // all but then the buffer would have to be dynamic and someone would have
3876 // to free it and we don't have the tooltip owner object here any more, so
3877 // for now use our own static buffer with a higher fixed max length.
3879 // Note that using a static buffer should not be a problem as only a single
3880 // tooltip can be shown at the same time anyhow.
3882 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3884 // We need to convert tooltip from multi byte to Unicode on the fly.
3885 static wchar_t buf
[513];
3887 // Truncate tooltip length if needed as otherwise we might not have
3888 // enough space for it in the buffer and MultiByteToWideChar() would
3890 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3892 // Convert to WideChar without adding the NULL character. The NULL
3893 // character is added afterwards (this is more efficient).
3894 int len
= ::MultiByteToWideChar
3906 wxLogLastError(wxT("MultiByteToWideChar()"));
3910 ttText
->lpszText
= (LPSTR
) buf
;
3912 else // TTN_NEEDTEXTA
3913 #endif // !wxUSE_UNICODE
3915 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3916 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3917 // to copy the string we have into the buffer
3918 static wxChar buf
[513];
3919 wxStrlcpy(buf
, ttip
.c_str(), WXSIZEOF(buf
));
3920 ttText
->lpszText
= buf
;
3926 #endif // wxUSE_TOOLTIPS
3928 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3930 WXLPARAM
* WXUNUSED(result
))
3935 NMHDR
* hdr
= (NMHDR
*)lParam
;
3936 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3943 wxUnusedVar(lParam
);
3944 #endif // wxUSE_TOOLTIPS
3949 // ---------------------------------------------------------------------------
3950 // end session messages
3951 // ---------------------------------------------------------------------------
3953 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3955 #ifdef ENDSESSION_LOGOFF
3956 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3957 event
.SetEventObject(wxTheApp
);
3958 event
.SetCanVeto(true);
3959 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3961 bool rc
= wxTheApp
->ProcessEvent(event
);
3965 // we may end only if the app didn't veto session closing (double
3967 *mayEnd
= !event
.GetVeto();
3972 wxUnusedVar(logOff
);
3973 wxUnusedVar(mayEnd
);
3978 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3980 #ifdef ENDSESSION_LOGOFF
3981 // do nothing if the session isn't ending
3986 if ( (this != wxTheApp
->GetTopWindow()) )
3989 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3990 event
.SetEventObject(wxTheApp
);
3991 event
.SetCanVeto(false);
3992 event
.SetLoggingOff((logOff
& ENDSESSION_LOGOFF
) != 0);
3994 return wxTheApp
->ProcessEvent(event
);
3996 wxUnusedVar(endSession
);
3997 wxUnusedVar(logOff
);
4002 // ---------------------------------------------------------------------------
4003 // window creation/destruction
4004 // ---------------------------------------------------------------------------
4006 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
4009 // VZ: why is this commented out for WinCE? If it doesn't support
4010 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
4011 // not with multiple #ifdef's!
4013 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
4014 EnsureParentHasControlParentStyle(GetParent());
4015 #endif // !__WXWINCE__
4022 bool wxWindowMSW::HandleDestroy()
4024 // delete our drop target if we've got one
4025 #if wxUSE_DRAG_AND_DROP
4026 if ( m_dropTarget
!= NULL
)
4028 m_dropTarget
->Revoke(m_hWnd
);
4030 wxDELETE(m_dropTarget
);
4032 #endif // wxUSE_DRAG_AND_DROP
4034 // WM_DESTROY handled
4038 // ---------------------------------------------------------------------------
4040 // ---------------------------------------------------------------------------
4042 bool wxWindowMSW::HandleActivate(int state
,
4043 bool WXUNUSED(minimized
),
4044 WXHWND
WXUNUSED(activate
))
4046 wxActivateEvent
event(wxEVT_ACTIVATE
,
4047 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
4049 event
.SetEventObject(this);
4051 return HandleWindowEvent(event
);
4054 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
4056 // Strangly enough, some controls get set focus events when they are being
4057 // deleted, even if they already had focus before.
4058 if ( m_isBeingDeleted
)
4063 // notify the parent keeping track of focus for the kbd navigation
4064 // purposes that we got it
4065 wxChildFocusEvent
eventFocus((wxWindow
*)this);
4066 (void)HandleWindowEvent(eventFocus
);
4072 m_caret
->OnSetFocus();
4074 #endif // wxUSE_CARET
4076 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
4077 event
.SetEventObject(this);
4079 // wxFindWinFromHandle() may return NULL, it is ok
4080 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4082 return HandleWindowEvent(event
);
4085 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
4091 m_caret
->OnKillFocus();
4093 #endif // wxUSE_CARET
4095 // Don't send the event when in the process of being deleted. This can
4096 // only cause problems if the event handler tries to access the object.
4097 if ( m_isBeingDeleted
)
4102 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
4103 event
.SetEventObject(this);
4105 // wxFindWinFromHandle() may return NULL, it is ok
4106 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4108 return HandleWindowEvent(event
);
4111 // ---------------------------------------------------------------------------
4113 // ---------------------------------------------------------------------------
4115 void wxWindowMSW::SetLabel( const wxString
& label
)
4117 SetWindowText(GetHwnd(), label
.c_str());
4120 wxString
wxWindowMSW::GetLabel() const
4122 return wxGetWindowText(GetHWND());
4125 // ---------------------------------------------------------------------------
4127 // ---------------------------------------------------------------------------
4129 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
4131 wxShowEvent
event(GetId(), show
);
4132 event
.SetEventObject(this);
4134 return HandleWindowEvent(event
);
4137 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
4139 wxInitDialogEvent
event(GetId());
4140 event
.SetEventObject(this);
4142 return HandleWindowEvent(event
);
4145 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
4147 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
4148 wxUnusedVar(wParam
);
4150 #else // __WXMICROWIN__
4151 HDROP hFilesInfo
= (HDROP
) wParam
;
4153 // Get the total number of files dropped
4154 UINT gwFilesDropped
= ::DragQueryFile
4162 wxString
*files
= new wxString
[gwFilesDropped
];
4163 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
4165 // first get the needed buffer length (+1 for terminating NUL)
4166 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
4168 // and now get the file name
4169 ::DragQueryFile(hFilesInfo
, wIndex
,
4170 wxStringBuffer(files
[wIndex
], len
), len
);
4173 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
4174 event
.SetEventObject(this);
4177 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
4178 event
.m_pos
.x
= dropPoint
.x
;
4179 event
.m_pos
.y
= dropPoint
.y
;
4181 DragFinish(hFilesInfo
);
4183 return HandleWindowEvent(event
);
4188 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
4190 int WXUNUSED(mouseMsg
))
4192 #ifndef __WXMICROWIN__
4193 // the logic is as follows:
4194 // 0. if we're busy, set the busy cursor (even for non client elements)
4195 // 1. don't set custom cursor for non client area of enabled windows
4196 // 2. ask user EVT_SET_CURSOR handler for the cursor
4197 // 3. if still no cursor but we're in a TLW, set the global cursor
4199 HCURSOR hcursor
= 0;
4202 hcursor
= wxGetCurrentBusyCursor();
4206 if ( nHitTest
!= HTCLIENT
)
4209 // first ask the user code - it may wish to set the cursor in some very
4210 // specific way (for example, depending on the current position)
4213 if ( !::GetCursorPosWinCE(&pt
))
4215 if ( !::GetCursorPos(&pt
) )
4218 wxLogLastError(wxT("GetCursorPos"));
4223 ScreenToClient(&x
, &y
);
4224 wxSetCursorEvent
event(x
, y
);
4225 event
.SetId(GetId());
4226 event
.SetEventObject(this);
4228 bool processedEvtSetCursor
= HandleWindowEvent(event
);
4229 if ( processedEvtSetCursor
&& event
.HasCursor() )
4231 hcursor
= GetHcursorOf(event
.GetCursor());
4236 // the test for processedEvtSetCursor is here to prevent using
4237 // m_cursor if the user code caught EVT_SET_CURSOR() and returned
4238 // nothing from it - this is a way to say that our cursor shouldn't
4239 // be used for this point
4240 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
4242 hcursor
= GetHcursorOf(m_cursor
);
4245 if ( !hcursor
&& !GetParent() )
4247 const wxCursor
*cursor
= wxGetGlobalCursor();
4248 if ( cursor
&& cursor
->Ok() )
4250 hcursor
= GetHcursorOf(*cursor
);
4259 ::SetCursor(hcursor
);
4261 // cursor set, stop here
4264 #endif // __WXMICROWIN__
4266 // pass up the window chain
4270 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
4271 WXLPARAM
WXUNUSED(lParam
),
4272 bool *WXUNUSED_IN_WINCE(vetoed
))
4278 wxEventType evtType
;
4281 case PBT_APMQUERYSUSPEND
:
4282 evtType
= wxEVT_POWER_SUSPENDING
;
4285 case PBT_APMQUERYSUSPENDFAILED
:
4286 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
4289 case PBT_APMSUSPEND
:
4290 evtType
= wxEVT_POWER_SUSPENDED
;
4293 case PBT_APMRESUMESUSPEND
:
4294 evtType
= wxEVT_POWER_RESUME
;
4298 wxLogDebug(wxT("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
4301 // these messages are currently not mapped to wx events
4302 case PBT_APMQUERYSTANDBY
:
4303 case PBT_APMQUERYSTANDBYFAILED
:
4304 case PBT_APMSTANDBY
:
4305 case PBT_APMRESUMESTANDBY
:
4306 case PBT_APMBATTERYLOW
:
4307 case PBT_APMPOWERSTATUSCHANGE
:
4308 case PBT_APMOEMEVENT
:
4309 case PBT_APMRESUMECRITICAL
:
4310 #ifdef PBT_APMRESUMEAUTOMATIC
4311 case PBT_APMRESUMEAUTOMATIC
:
4313 evtType
= wxEVT_NULL
;
4317 // don't handle unknown messages
4318 if ( evtType
== wxEVT_NULL
)
4321 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
4323 wxPowerEvent
event(evtType
);
4324 if ( !HandleWindowEvent(event
) )
4327 *vetoed
= event
.IsVetoed();
4333 bool wxWindowMSW::IsDoubleBuffered() const
4335 for ( const wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4337 if ( wxHasWindowExStyle(win
, WS_EX_COMPOSITED
) )
4340 if ( win
->IsTopLevel() )
4347 void wxWindowMSW::SetDoubleBuffered(bool on
)
4349 // Get the current extended style bits
4350 long exstyle
= wxGetWindowExStyle(this);
4352 // Twiddle the bit as needed
4354 exstyle
|= WS_EX_COMPOSITED
;
4356 exstyle
&= ~WS_EX_COMPOSITED
;
4359 wxSetWindowExStyle(this, exstyle
);
4362 // ---------------------------------------------------------------------------
4363 // owner drawn stuff
4364 // ---------------------------------------------------------------------------
4366 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
4367 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
4368 #define WXUNUSED_UNLESS_ODRAWN(param) param
4370 #define WXUNUSED_UNLESS_ODRAWN(param)
4374 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
4375 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
4377 #if wxUSE_OWNER_DRAWN
4379 #if wxUSE_MENUS_NATIVE
4380 // is it a menu item?
4381 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
4382 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
4384 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
4386 // see comment before the same test in MSWOnMeasureItem() below
4390 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4391 false, wxT("MSWOnDrawItem: bad wxMenuItem pointer") );
4393 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4394 // the DC from being released
4395 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
4396 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
4397 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
4398 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
4400 return pMenuItem
->OnDrawItem
4404 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
4405 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
4408 #endif // wxUSE_MENUS_NATIVE
4410 #endif // USE_OWNER_DRAWN
4412 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4414 #if wxUSE_OWNER_DRAWN
4415 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4416 #else // !wxUSE_OWNER_DRAWN
4417 // we may still have owner-drawn buttons internally because we have to make
4418 // them owner-drawn to support colour change
4421 wxDynamicCast(FindItem(id
), wxButton
)
4426 #endif // USE_OWNER_DRAWN
4430 return item
->MSWOnDraw(itemStruct
);
4433 #endif // wxUSE_CONTROLS
4439 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4441 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4442 // is it a menu item?
4443 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4444 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4446 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4448 // according to Carsten Fuchs the pointer may be NULL under XP if an
4449 // MDI child frame is initially maximized, see this for more info:
4450 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4452 // so silently ignore it instead of asserting
4456 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4457 false, wxT("MSWOnMeasureItem: bad wxMenuItem pointer") );
4460 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4462 pMeasureStruct
->itemWidth
= w
;
4463 pMeasureStruct
->itemHeight
= h
;
4468 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4471 return item
->MSWOnMeasure(itemStruct
);
4475 wxUnusedVar(itemStruct
);
4476 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4481 // ---------------------------------------------------------------------------
4482 // colours and palettes
4483 // ---------------------------------------------------------------------------
4485 bool wxWindowMSW::HandleSysColorChange()
4487 wxSysColourChangedEvent event
;
4488 event
.SetEventObject(this);
4490 (void)HandleWindowEvent(event
);
4492 // always let the system carry on the default processing to allow the
4493 // native controls to react to the colours update
4497 bool wxWindowMSW::HandleDisplayChange()
4499 wxDisplayChangedEvent event
;
4500 event
.SetEventObject(this);
4502 return HandleWindowEvent(event
);
4505 #ifndef __WXMICROWIN__
4507 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4509 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4513 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4516 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4518 #endif // wxUSE_CONTROLS
4521 return *brush
!= NULL
;
4524 #endif // __WXMICROWIN__
4526 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4529 // same as below except we don't respond to our own messages
4530 if ( hWndPalChange
!= GetHWND() )
4532 // check to see if we our our parents have a custom palette
4533 wxWindowMSW
*win
= this;
4534 while ( win
&& !win
->HasCustomPalette() )
4536 win
= win
->GetParent();
4539 if ( win
&& win
->HasCustomPalette() )
4541 // realize the palette to see whether redrawing is needed
4542 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4543 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4544 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4546 int result
= ::RealizePalette(hdc
);
4548 // restore the palette (before releasing the DC)
4549 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4550 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4551 ::RealizePalette(hdc
);
4552 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4554 // now check for the need to redraw
4556 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4560 #endif // wxUSE_PALETTE
4562 wxPaletteChangedEvent
event(GetId());
4563 event
.SetEventObject(this);
4564 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4566 return HandleWindowEvent(event
);
4569 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4571 // notify windows on the capture stack about lost capture
4572 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4573 wxWindowBase::NotifyCaptureLost();
4575 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4576 wxMouseCaptureChangedEvent
event(GetId(), win
);
4577 event
.SetEventObject(this);
4578 return HandleWindowEvent(event
);
4581 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4583 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4584 // we need to send this to child windows (it is only sent to top-level
4585 // windows) so {list,tree}ctrls can adjust their font size if necessary
4586 // this is exactly how explorer does it to enable the font size changes
4588 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4591 // top-level windows already get this message from the system
4592 wxWindow
*win
= node
->GetData();
4593 if ( !win
->IsTopLevel() )
4595 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4598 node
= node
->GetNext();
4601 // let the system handle it
4605 bool wxWindowMSW::HandleQueryNewPalette()
4609 // check to see if we our our parents have a custom palette
4610 wxWindowMSW
*win
= this;
4611 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4612 if (win
->HasCustomPalette()) {
4613 /* realize the palette to see whether redrawing is needed */
4614 HDC hdc
= ::GetDC((HWND
) GetHWND());
4615 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4616 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4618 int result
= ::RealizePalette(hdc
);
4619 /* restore the palette (before releasing the DC) */
4620 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4621 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4622 ::RealizePalette(hdc
);
4623 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4624 /* now check for the need to redraw */
4626 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4628 #endif // wxUSE_PALETTE
4630 wxQueryNewPaletteEvent
event(GetId());
4631 event
.SetEventObject(this);
4633 return HandleWindowEvent(event
) && event
.GetPaletteRealized();
4636 // Responds to colour changes: passes event on to children.
4637 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4639 // the top level window also reset the standard colour map as it might have
4640 // changed (there is no need to do it for the non top level windows as we
4641 // only have to do it once)
4645 gs_hasStdCmap
= false;
4647 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4650 // Only propagate to non-top-level windows because Windows already
4651 // sends this event to all top-level ones
4652 wxWindow
*win
= node
->GetData();
4653 if ( !win
->IsTopLevel() )
4655 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4656 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4657 // the standard controls
4658 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4661 node
= node
->GetNext();
4665 extern wxCOLORMAP
*wxGetStdColourMap()
4667 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4668 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4670 if ( !gs_hasStdCmap
)
4672 static bool s_coloursInit
= false;
4674 if ( !s_coloursInit
)
4676 // When a bitmap is loaded, the RGB values can change (apparently
4677 // because Windows adjusts them to care for the old programs always
4678 // using 0xc0c0c0 while the transparent colour for the new Windows
4679 // versions is different). But we do this adjustment ourselves so
4680 // we want to avoid Windows' "help" and for this we need to have a
4681 // reference bitmap which can tell us what the RGB values change
4683 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4684 wxBitmap
stdColourBitmap(wxT("wxBITMAP_STD_COLOURS"));
4685 if ( stdColourBitmap
.Ok() )
4687 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4688 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4689 wxT("forgot to update wxBITMAP_STD_COLOURS!") );
4692 memDC
.SelectObject(stdColourBitmap
);
4695 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4697 memDC
.GetPixel(i
, 0, &colour
);
4698 s_stdColours
[i
] = wxColourToRGB(colour
);
4701 else // wxBITMAP_STD_COLOURS couldn't be loaded
4703 s_stdColours
[0] = RGB(000,000,000); // black
4704 s_stdColours
[1] = RGB(128,128,128); // dark grey
4705 s_stdColours
[2] = RGB(192,192,192); // light grey
4706 s_stdColours
[3] = RGB(255,255,255); // white
4707 //s_stdColours[4] = RGB(000,000,255); // blue
4708 //s_stdColours[5] = RGB(255,000,255); // magenta
4711 s_coloursInit
= true;
4714 gs_hasStdCmap
= true;
4716 // create the colour map
4717 #define INIT_CMAP_ENTRY(col) \
4718 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4719 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4721 INIT_CMAP_ENTRY(BTNTEXT
);
4722 INIT_CMAP_ENTRY(BTNSHADOW
);
4723 INIT_CMAP_ENTRY(BTNFACE
);
4724 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4726 #undef INIT_CMAP_ENTRY
4732 #if wxUSE_UXTHEME && !defined(TMT_FILLCOLOR)
4733 #define TMT_FILLCOLOR 3802
4734 #define TMT_TEXTCOLOR 3803
4735 #define TMT_BORDERCOLOR 3801
4738 wxColour
wxWindowMSW::MSWGetThemeColour(const wchar_t *themeName
,
4741 MSWThemeColour themeColour
,
4742 wxSystemColour fallback
) const
4745 const wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
4748 int themeProperty
= 0;
4750 // TODO: Convert this into a table? Sure would be faster.
4751 switch ( themeColour
)
4753 case ThemeColourBackground
:
4754 themeProperty
= TMT_FILLCOLOR
;
4756 case ThemeColourText
:
4757 themeProperty
= TMT_TEXTCOLOR
;
4759 case ThemeColourBorder
:
4760 themeProperty
= TMT_BORDERCOLOR
;
4763 wxFAIL_MSG(wxT("unsupported theme colour"));
4766 wxUxThemeHandle
hTheme((const wxWindow
*)this, themeName
);
4768 HRESULT hr
= theme
->GetThemeColor
4777 if ( SUCCEEDED(hr
) )
4778 return wxRGBToColour(col
);
4782 "GetThemeColor(%s, %i, %i, %i)",
4783 themeName
, themePart
, themeState
, themeProperty
),
4787 wxUnusedVar(themeName
);
4788 wxUnusedVar(themePart
);
4789 wxUnusedVar(themeState
);
4790 wxUnusedVar(themeColour
);
4792 return wxSystemSettings::GetColour(fallback
);
4795 // ---------------------------------------------------------------------------
4797 // ---------------------------------------------------------------------------
4799 // this variable is used to check that a paint event handler which processed
4800 // the event did create a wxPaintDC inside its code and called BeginPaint() to
4801 // validate the invalidated window area as otherwise we'd keep getting an
4802 // endless stream of WM_PAINT messages for this window resulting in a lot of
4803 // difficult to debug problems (e.g. impossibility to repaint other windows,
4804 // lack of timer and idle events and so on)
4805 extern bool wxDidCreatePaintDC
;
4806 bool wxDidCreatePaintDC
= false;
4808 bool wxWindowMSW::HandlePaint()
4810 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4813 wxLogLastError(wxT("CreateRectRgn"));
4815 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4817 wxLogLastError(wxT("GetUpdateRgn"));
4820 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4822 wxDidCreatePaintDC
= false;
4824 wxPaintEvent
event(m_windowId
);
4825 event
.SetEventObject(this);
4827 bool processed
= HandleWindowEvent(event
);
4829 if ( processed
&& !wxDidCreatePaintDC
)
4831 // do call MSWDefWindowProc() to validate the update region to avoid
4832 // the problems mentioned above
4836 // note that we must generate NC event after the normal one as otherwise
4837 // BeginPaint() will happily overwrite our decorations with the background
4839 wxNcPaintEvent
eventNc(m_windowId
);
4840 eventNc
.SetEventObject(this);
4841 HandleWindowEvent(eventNc
);
4843 // don't keep an HRGN we don't need any longer (GetUpdateRegion() can only
4844 // be called from inside the event handlers called above)
4845 m_updateRegion
.Clear();
4850 // Can be called from an application's OnPaint handler
4851 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4853 #ifdef __WXUNIVERSAL__
4856 HDC hDC
= (HDC
) wxPaintDCImpl::FindDCInCache((wxWindow
*) event
.GetEventObject());
4859 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4864 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4866 switch ( GetBackgroundStyle() )
4868 case wxBG_STYLE_ERASE
:
4869 case wxBG_STYLE_COLOUR
:
4870 // we need to generate an erase background event
4872 wxDCTemp
dc(hdc
, GetClientSize());
4873 wxDCTempImpl
*impl
= (wxDCTempImpl
*) dc
.GetImpl();
4876 impl
->SetWindow((wxWindow
*)this);
4878 wxEraseEvent
event(m_windowId
, &dc
);
4879 event
.SetEventObject(this);
4880 bool rc
= HandleWindowEvent(event
);
4882 // must be called manually as ~wxDC doesn't do anything for
4884 impl
->SelectOldObjects(hdc
);
4888 // background erased by the user-defined handler
4894 case wxBG_STYLE_SYSTEM
:
4895 if ( !DoEraseBackground(hdc
) )
4897 // let the default processing to take place if we didn't erase
4898 // the background ourselves
4903 case wxBG_STYLE_PAINT
:
4904 case wxBG_STYLE_TRANSPARENT
:
4905 // no need to do anything here at all, background will be entirely
4906 // redrawn in WM_PAINT handler
4910 wxFAIL_MSG( "unknown background style" );
4916 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
4918 bool wxWindowMSW::MSWHasEraseBgHook() const
4920 return gs_eraseBgHooks
.find(this) != gs_eraseBgHooks
.end();
4923 void wxWindowMSW::MSWSetEraseBgHook(wxWindow
*child
)
4927 if ( !gs_eraseBgHooks
.insert(
4928 EraseBgHooks::value_type(this, child
)).second
)
4930 wxFAIL_MSG( wxT("Setting erase background hook twice?") );
4933 else // reset the hook
4935 if ( gs_eraseBgHooks
.erase(this) != 1 )
4937 wxFAIL_MSG( wxT("Resetting erase background which was not set?") );
4942 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
4944 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4946 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4950 // erase just the client area of the window, this is important for the
4951 // frames to avoid drawing over the toolbar part of the window (you might
4952 // think using WS_CLIPCHILDREN would prevent this from happening, but it
4955 wxCopyRectToRECT(GetClientRect(), rc
);
4956 ::FillRect((HDC
)hDC
, &rc
, hbr
);
4962 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
),
4963 wxWindowMSW
* WXUNUSED(child
))
4968 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4970 return (WXHBRUSH
)GetHbrushOf(*brush
);
4976 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
)
4978 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4980 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, this);
4984 // don't use the parent background if we're not transparent
4985 if ( !win
->HasTransparentBackground() )
4988 // background is not inherited beyond top level windows
4989 if ( win
->IsTopLevel() )
4996 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4998 // we receive this message when DrawThemeParentBackground() is
4999 // called from def window proc of several controls under XP and we
5000 // must draw properly themed background here
5002 // note that naively I'd expect filling the client rect with the
5003 // brush returned by MSWGetBgBrush() work -- but for some reason it
5004 // doesn't and we have to call parents MSWPrintChild() which is
5005 // supposed to call DrawThemeBackground() with appropriate params
5007 // also note that in this case lParam == PRF_CLIENT but we're
5008 // clearly expected to paint the background and nothing else!
5010 if ( IsTopLevel() || InheritsBackgroundColour() )
5013 // sometimes we don't want the parent to handle it at all, instead
5014 // return whatever value this window wants
5015 if ( !MSWShouldPropagatePrintChild() )
5016 return MSWPrintChild(hDC
, (wxWindow
*)this);
5018 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
5020 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
5023 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
5030 // ---------------------------------------------------------------------------
5031 // moving and resizing
5032 // ---------------------------------------------------------------------------
5034 bool wxWindowMSW::HandleMinimize()
5036 wxIconizeEvent
event(m_windowId
);
5037 event
.SetEventObject(this);
5039 return HandleWindowEvent(event
);
5042 bool wxWindowMSW::HandleMaximize()
5044 wxMaximizeEvent
event(m_windowId
);
5045 event
.SetEventObject(this);
5047 return HandleWindowEvent(event
);
5050 bool wxWindowMSW::HandleMove(int x
, int y
)
5053 wxMoveEvent
event(point
, m_windowId
);
5054 event
.SetEventObject(this);
5056 return HandleWindowEvent(event
);
5059 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
5061 wxMoveEvent
event(rect
, m_windowId
);
5062 event
.SetEventObject(this);
5064 bool rc
= HandleWindowEvent(event
);
5066 rect
= event
.GetRect();
5070 bool wxWindowMSW::HandleEnterSizeMove()
5072 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5073 event
.SetEventType(wxEVT_MOVE_START
);
5074 event
.SetEventObject(this);
5076 return HandleWindowEvent(event
);
5079 bool wxWindowMSW::HandleExitSizeMove()
5081 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5082 event
.SetEventType(wxEVT_MOVE_END
);
5083 event
.SetEventObject(this);
5085 return HandleWindowEvent(event
);
5088 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
5090 #if wxUSE_DEFERRED_SIZING
5091 // when we resize this window, its children are probably going to be
5092 // repositioned as well, prepare to use DeferWindowPos() for them
5093 int numChildren
= 0;
5094 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
5096 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
5101 // Protect against valid m_hDWP being overwritten
5102 bool useDefer
= false;
5104 if ( numChildren
> 1 )
5108 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
5111 wxLogLastError(wxT("BeginDeferWindowPos"));
5117 #endif // wxUSE_DEFERRED_SIZING
5119 // update this window size
5120 bool processed
= false;
5124 wxFAIL_MSG( wxT("unexpected WM_SIZE parameter") );
5125 // fall through nevertheless
5129 // we're not interested in these messages at all
5132 case SIZE_MINIMIZED
:
5133 processed
= HandleMinimize();
5136 case SIZE_MAXIMIZED
:
5137 /* processed = */ HandleMaximize();
5138 // fall through to send a normal size event as well
5141 // don't use w and h parameters as they specify the client size
5142 // while according to the docs EVT_SIZE handler is supposed to
5143 // receive the total size
5144 wxSizeEvent
event(GetSize(), m_windowId
);
5145 event
.SetEventObject(this);
5147 processed
= HandleWindowEvent(event
);
5150 #if wxUSE_DEFERRED_SIZING
5151 // and finally change the positions of all child windows at once
5152 if ( useDefer
&& m_hDWP
)
5154 // reset m_hDWP to NULL so that child windows don't try to use our
5155 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
5156 // happen anyhow normally but who knows what weird flow of control we
5157 // may have depending on what the users EVT_SIZE handler does...)
5158 HDWP hDWP
= (HDWP
)m_hDWP
;
5161 // do put all child controls in place at once
5162 if ( !::EndDeferWindowPos(hDWP
) )
5164 wxLogLastError(wxT("EndDeferWindowPos"));
5167 // Reset our children's pending pos/size values.
5168 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
5170 node
= node
->GetNext() )
5172 wxWindowMSW
* const child
= node
->GetData();
5173 child
->MSWEndDeferWindowPos();
5176 #endif // wxUSE_DEFERRED_SIZING
5181 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
5183 wxSizeEvent
event(rect
, m_windowId
);
5184 event
.SetEventObject(this);
5186 bool rc
= HandleWindowEvent(event
);
5188 rect
= event
.GetRect();
5192 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
5197 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
5201 int minWidth
= GetMinWidth(),
5202 minHeight
= GetMinHeight(),
5203 maxWidth
= GetMaxWidth(),
5204 maxHeight
= GetMaxHeight();
5206 if ( minWidth
!= wxDefaultCoord
)
5208 info
->ptMinTrackSize
.x
= minWidth
;
5212 if ( minHeight
!= wxDefaultCoord
)
5214 info
->ptMinTrackSize
.y
= minHeight
;
5218 if ( maxWidth
!= wxDefaultCoord
)
5220 info
->ptMaxTrackSize
.x
= maxWidth
;
5224 if ( maxHeight
!= wxDefaultCoord
)
5226 info
->ptMaxTrackSize
.y
= maxHeight
;
5234 // ---------------------------------------------------------------------------
5236 // ---------------------------------------------------------------------------
5238 bool wxWindowMSW::HandleCommand(WXWORD id_
, WXWORD cmd
, WXHWND control
)
5240 // sign extend to int from short before comparing with the other int ids
5241 int id
= (signed short)id_
;
5243 #if wxUSE_MENUS_NATIVE
5244 if ( !cmd
&& wxCurrentPopupMenu
)
5246 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
5247 wxCurrentPopupMenu
= NULL
;
5249 return popupMenu
->MSWCommand(cmd
, id
);
5251 #endif // wxUSE_MENUS_NATIVE
5253 wxWindow
*win
= NULL
;
5255 // first try to find it from HWND - this works even with the broken
5256 // programs using the same ids for different controls
5259 win
= wxFindWinFromHandle(control
);
5270 return win
->MSWCommand(cmd
, id
);
5273 // the messages sent from the in-place edit control used by the treectrl
5274 // for label editing have id == 0, but they should _not_ be treated as menu
5275 // messages (they are EN_XXX ones, in fact) so don't translate anything
5276 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
5279 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
5280 event
.SetEventObject(this);
5283 return HandleWindowEvent(event
);
5287 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5288 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
5289 // notifications to its parent which we want to reflect back to
5291 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
5292 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
5294 #endif // wxUSE_SPINCTRL
5296 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
5297 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
5298 // notifications to its parent which we want to reflect back to
5300 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
5301 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
5309 // ---------------------------------------------------------------------------
5311 // ---------------------------------------------------------------------------
5313 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
5317 // our client coords are not quite the same as Windows ones
5318 wxPoint pt
= GetClientAreaOrigin();
5319 event
.m_x
= x
- pt
.x
;
5320 event
.m_y
= y
- pt
.y
;
5322 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
5323 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
5324 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
5325 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
5326 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
5327 #ifdef wxHAS_XBUTTON
5328 event
.m_aux1Down
= (flags
& MK_XBUTTON1
) != 0;
5329 event
.m_aux2Down
= (flags
& MK_XBUTTON2
) != 0;
5330 #endif // wxHAS_XBUTTON
5331 event
.m_altDown
= ::wxIsAltDown();
5334 event
.SetTimestamp(::GetMessageTime());
5337 event
.SetEventObject(this);
5338 event
.SetId(GetId());
5340 #if wxUSE_MOUSEEVENT_HACK
5341 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
5342 gs_lastMouseEvent
.type
= event
.GetEventType();
5343 #endif // wxUSE_MOUSEEVENT_HACK
5347 // Windows doesn't send the mouse events to the static controls (which are
5348 // transparent in the sense that their WM_NCHITTEST handler returns
5349 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
5350 // and so we manually check if we don't have a child window under mouse and if
5351 // we do, send the event to it instead of the window Windows had sent WM_XXX
5354 // Notice that this is not done for the mouse move events because this could
5355 // (would?) be too slow, but only for clicks which means that the static texts
5356 // still don't get move, enter nor leave events.
5357 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
5359 wxCHECK_MSG( x
&& y
, win
, wxT("NULL pointer in FindWindowForMouseEvent") );
5361 // first try to find a non transparent child: this allows us to send events
5362 // to a static text which is inside a static box, for example
5363 POINT pt
= { *x
, *y
};
5364 HWND hwnd
= GetHwndOf(win
),
5368 hwndUnderMouse
= ::ChildWindowFromPoint
5374 hwndUnderMouse
= ::ChildWindowFromPointEx
5384 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
5386 // now try any child window at all
5387 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
5390 // check that we have a child window which is susceptible to receive mouse
5391 // events: for this it must be shown and enabled
5392 if ( hwndUnderMouse
&&
5393 hwndUnderMouse
!= hwnd
&&
5394 ::IsWindowVisible(hwndUnderMouse
) &&
5395 ::IsWindowEnabled(hwndUnderMouse
) )
5397 wxWindow
*winUnderMouse
= wxFindWinFromHandle(hwndUnderMouse
);
5398 if ( winUnderMouse
)
5400 // translate the mouse coords to the other window coords
5401 win
->ClientToScreen(x
, y
);
5402 winUnderMouse
->ScreenToClient(x
, y
);
5404 win
= winUnderMouse
;
5410 #endif // __WXWINCE__
5412 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5414 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
5415 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
5416 // from the message id and take the value in the table to get wxWin event
5418 static const wxEventType eventsMouse
[] =
5429 wxEVT_MIDDLE_DCLICK
,
5430 0, // this one is for wxEVT_MOTION which is not used here
5439 #ifdef wxHAS_XBUTTON
5440 // the same messages are used for both auxillary mouse buttons so we need
5441 // to adjust the index manually
5444 case WM_XBUTTONDOWN
:
5446 case WM_XBUTTONDBLCLK
:
5447 if ( flags
& MK_XBUTTON2
)
5448 msg
+= wxEVT_AUX2_DOWN
- wxEVT_AUX1_DOWN
;
5450 #endif // wxHAS_XBUTTON
5452 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
5453 InitMouseEvent(event
, x
, y
, flags
);
5455 return HandleWindowEvent(event
);
5458 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
5460 if ( !m_mouseInWindow
)
5462 // it would be wrong to assume that just because we get a mouse move
5463 // event that the mouse is inside the window: although this is usually
5464 // true, it is not if we had captured the mouse, so we need to check
5465 // the mouse coordinates here
5466 if ( !HasCapture() || IsMouseInWindow() )
5468 // Generate an ENTER event
5469 m_mouseInWindow
= true;
5471 #ifdef HAVE_TRACKMOUSEEVENT
5472 typedef BOOL (WINAPI
*_TrackMouseEvent_t
)(LPTRACKMOUSEEVENT
);
5474 static const _TrackMouseEvent_t
5475 s_pfn_TrackMouseEvent
= _TrackMouseEvent
;
5476 #else // !__WXWINCE__
5477 static _TrackMouseEvent_t s_pfn_TrackMouseEvent
;
5478 static bool s_initDone
= false;
5481 // see comment in wxApp::GetComCtl32Version() explaining the
5482 // use of wxLoadedDLL
5483 wxLoadedDLL
dllComCtl32(wxT("comctl32.dll"));
5484 if ( dllComCtl32
.IsLoaded() )
5486 s_pfn_TrackMouseEvent
= (_TrackMouseEvent_t
)
5487 dllComCtl32
.RawGetSymbol(wxT("_TrackMouseEvent"));
5493 if ( s_pfn_TrackMouseEvent
)
5494 #endif // __WXWINCE__/!__WXWINCE__
5496 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
5498 trackinfo
.dwFlags
= TME_LEAVE
;
5499 trackinfo
.hwndTrack
= GetHwnd();
5501 (*s_pfn_TrackMouseEvent
)(&trackinfo
);
5503 #endif // HAVE_TRACKMOUSEEVENT
5505 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
5506 InitMouseEvent(event
, x
, y
, flags
);
5508 (void)HandleWindowEvent(event
);
5511 #ifdef HAVE_TRACKMOUSEEVENT
5512 else // mouse not in window
5514 // Check if we need to send a LEAVE event
5515 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
5516 // send it here if we are using native mouse leave tracking
5517 if ( HasCapture() && !IsMouseInWindow() )
5519 GenerateMouseLeave();
5522 #endif // HAVE_TRACKMOUSEEVENT
5524 #if wxUSE_MOUSEEVENT_HACK
5525 // Windows often generates mouse events even if mouse position hasn't
5526 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
5528 // Filter this out as it can result in unexpected behaviour compared to
5530 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
5531 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
5532 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
5533 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
5535 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
5537 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
5542 #endif // wxUSE_MOUSEEVENT_HACK
5544 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
5548 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
5550 #if wxUSE_MOUSEWHEEL
5551 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5552 // forwarded up to the parent by DefWindowProc()) and not in the client
5553 // ones as all the other messages, translate them to the client coords for
5556 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
5557 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
5558 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
5559 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5560 event
.m_wheelDelta
= WHEEL_DELTA
;
5562 static int s_linesPerRotation
= -1;
5563 if ( s_linesPerRotation
== -1 )
5565 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5566 &s_linesPerRotation
, 0))
5568 // this is not supposed to happen
5569 wxLogLastError(wxT("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5571 // the default is 3, so use it if SystemParametersInfo() failed
5572 s_linesPerRotation
= 3;
5576 event
.m_linesPerAction
= s_linesPerRotation
;
5577 return HandleWindowEvent(event
);
5579 #else // !wxUSE_MOUSEWHEEL
5580 wxUnusedVar(wParam
);
5581 wxUnusedVar(lParam
);
5584 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5587 void wxWindowMSW::GenerateMouseLeave()
5589 m_mouseInWindow
= false;
5592 if ( wxIsShiftDown() )
5594 if ( wxIsCtrlDown() )
5595 state
|= MK_CONTROL
;
5597 // Only the high-order bit should be tested
5598 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5599 state
|= MK_LBUTTON
;
5600 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5601 state
|= MK_MBUTTON
;
5602 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5603 state
|= MK_RBUTTON
;
5607 if ( !::GetCursorPosWinCE(&pt
) )
5609 if ( !::GetCursorPos(&pt
) )
5612 wxLogLastError(wxT("GetCursorPos"));
5615 // we need to have client coordinates here for symmetry with
5616 // wxEVT_ENTER_WINDOW
5617 RECT rect
= wxGetWindowRect(GetHwnd());
5621 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5622 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5624 (void)HandleWindowEvent(event
);
5627 // ---------------------------------------------------------------------------
5628 // keyboard handling
5629 // ---------------------------------------------------------------------------
5632 wxWindowMSW::InitAnyKeyEvent(wxKeyEvent
& event
,
5634 WXLPARAM lParam
) const
5636 event
.SetId(GetId());
5637 event
.m_shiftDown
= wxIsShiftDown();
5638 event
.m_controlDown
= wxIsCtrlDown();
5639 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5641 event
.SetEventObject(const_cast<wxWindow
*>(this));
5643 event
.m_rawCode
= (wxUint32
) wParam
;
5644 event
.m_rawFlags
= (wxUint32
) lParam
;
5646 event
.SetTimestamp(::GetMessageTime());
5649 // translate the position to client coordinates
5650 const wxPoint mousePos
= ScreenToClient(wxGetMousePosition());
5651 event
.m_x
= mousePos
.x
;
5652 event
.m_y
= mousePos
.y
;
5656 wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5658 WXLPARAM lParam
) const
5660 // Catch any attempts to use this with WM_CHAR, it wouldn't work because
5661 // wParam is supposed to be a virtual key and not a character here.
5662 wxASSERT_MSG( evType
!= wxEVT_CHAR
&& evType
!= wxEVT_CHAR_HOOK
,
5663 "CreateKeyEvent() can't be used for char events" );
5665 wxKeyEvent
event(evType
);
5666 InitAnyKeyEvent(event
, wParam
, lParam
);
5668 event
.m_keyCode
= wxMSWKeyboard::VKToWX(wParam
, lParam
);
5670 if ( event
.m_keyCode
< WXK_START
)
5672 // It's an ASCII character, set Unicode key code to the same value
5673 // for compatibility (both with the previous versions of wx and with
5674 // the other ports), even if it's not very useful for these events as
5675 // Unicode character is/should be mostly used by EVT_CHAR handlers.
5676 event
.m_uniChar
= event
.m_keyCode
;
5678 #endif // wxUSE_UNICODE
5683 // isASCII is true only when we're called from WM_CHAR handler and not from
5685 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
)
5687 wxKeyEvent
event(wxEVT_CHAR
);
5688 InitAnyKeyEvent(event
, wParam
, lParam
);
5691 // TODO: wParam uses UTF-16 so this is incorrect for characters outside of
5692 // the BMP, we should use WM_UNICHAR to handle them.
5693 event
.m_uniChar
= wParam
;
5694 #endif // wxUSE_UNICODE
5696 // Set non-Unicode key code too for compatibility if possible.
5697 if ( wParam
< 0x80 )
5699 // It's an ASCII character, no need to translate it.
5700 event
.m_keyCode
= wParam
;
5704 // Check if this key can be represented (as a single character) in the
5706 const wchar_t wc
= wParam
;
5708 if ( wxConvLibc
.FromWChar(&ch
, 1, &wc
, 1) != wxCONV_FAILED
)
5710 // For compatibility continue to provide the key code in this field
5711 // even though using GetUnicodeKey() is recommended now.
5712 event
.m_keyCode
= static_cast<unsigned char>(ch
);
5714 //else: Key can't be represented in the current locale, leave m_keyCode
5715 // as WXK_NONE and use GetUnicodeKey() to access the character.
5718 // the alphanumeric keys produced by pressing AltGr+something on European
5719 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5720 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5721 // alphanumeric, so pretend that there are no modifiers at all (the
5722 // KEY_DOWN event would still have the correct modifiers if they're really
5724 if ( event
.m_controlDown
&& event
.m_altDown
&&
5725 (event
.m_keyCode
>= 32 && event
.m_keyCode
< 256) )
5727 event
.m_controlDown
=
5728 event
.m_altDown
= false;
5731 return HandleWindowEvent(event
);
5734 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5736 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, wParam
, lParam
));
5737 return HandleWindowEvent(event
);
5740 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5742 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, wParam
, lParam
));
5743 return HandleWindowEvent(event
);
5747 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5748 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5750 // FIXME: implement GetMenuItemCount for WinCE, possibly
5751 // in terms of GetMenuItemInfo
5753 const HMENU hmenu
= (HMENU
)lParam
;
5757 mii
.cbSize
= sizeof(MENUITEMINFO
);
5759 // we could use MIIM_FTYPE here as we only need to know if the item is
5760 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5761 // MIIM_FTYPE is not supported under Win95
5762 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5764 // find if we have this letter in any owner drawn item
5765 const int count
= ::GetMenuItemCount(hmenu
);
5766 for ( int i
= 0; i
< count
; i
++ )
5768 // previous loop iteration could modify it, reset it back before
5769 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5772 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5774 if ( mii
.fType
== MFT_OWNERDRAW
)
5776 // dwItemData member of the MENUITEMINFO is a
5777 // pointer to the associated wxMenuItem -- see the
5778 // menu creation code
5779 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5781 const wxString
label(item
->GetItemLabel());
5782 const wxChar
*p
= wxStrchr(label
.wx_str(), wxT('&'));
5785 if ( *p
== wxT('&') )
5787 // this is not the accel char, find the real one
5788 p
= wxStrchr(p
+ 1, wxT('&'));
5790 else // got the accel char
5792 // FIXME-UNICODE: this comparison doesn't risk to work
5793 // for non ASCII accelerator characters I'm afraid, but
5795 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5801 // this one doesn't match
5808 else // failed to get the menu text?
5810 // it's not fatal, so don't show error, but still log it
5811 wxLogLastError(wxT("GetMenuItemInfo"));
5818 #endif // wxUSE_MENUS
5820 bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg
)
5822 const wxEventType type
= nMsg
== WM_CUT
? wxEVT_COMMAND_TEXT_CUT
5823 : nMsg
== WM_COPY
? wxEVT_COMMAND_TEXT_COPY
5824 : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE
;
5825 wxClipboardTextEvent
evt(type
, GetId());
5827 evt
.SetEventObject(this);
5829 return HandleWindowEvent(evt
);
5832 // ---------------------------------------------------------------------------
5834 // ---------------------------------------------------------------------------
5836 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5840 if ( flags
& JOY_BUTTON1CHG
)
5841 change
= wxJOY_BUTTON1
;
5842 if ( flags
& JOY_BUTTON2CHG
)
5843 change
= wxJOY_BUTTON2
;
5844 if ( flags
& JOY_BUTTON3CHG
)
5845 change
= wxJOY_BUTTON3
;
5846 if ( flags
& JOY_BUTTON4CHG
)
5847 change
= wxJOY_BUTTON4
;
5850 if ( flags
& JOY_BUTTON1
)
5851 buttons
|= wxJOY_BUTTON1
;
5852 if ( flags
& JOY_BUTTON2
)
5853 buttons
|= wxJOY_BUTTON2
;
5854 if ( flags
& JOY_BUTTON3
)
5855 buttons
|= wxJOY_BUTTON3
;
5856 if ( flags
& JOY_BUTTON4
)
5857 buttons
|= wxJOY_BUTTON4
;
5859 // the event ids aren't consecutive so we can't use table based lookup
5861 wxEventType eventType
;
5866 eventType
= wxEVT_JOY_MOVE
;
5871 eventType
= wxEVT_JOY_MOVE
;
5876 eventType
= wxEVT_JOY_ZMOVE
;
5881 eventType
= wxEVT_JOY_ZMOVE
;
5884 case MM_JOY1BUTTONDOWN
:
5886 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5889 case MM_JOY2BUTTONDOWN
:
5891 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5894 case MM_JOY1BUTTONUP
:
5896 eventType
= wxEVT_JOY_BUTTON_UP
;
5899 case MM_JOY2BUTTONUP
:
5901 eventType
= wxEVT_JOY_BUTTON_UP
;
5905 wxFAIL_MSG(wxT("no such joystick event"));
5910 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5911 event
.SetPosition(wxPoint(x
, y
));
5912 event
.SetEventObject(this);
5914 return HandleWindowEvent(event
);
5924 // ---------------------------------------------------------------------------
5926 // ---------------------------------------------------------------------------
5928 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5929 WXWORD pos
, WXHWND control
)
5931 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5933 wxWindow
*child
= wxFindWinFromHandle(control
);
5935 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5938 wxScrollWinEvent event
;
5939 event
.SetPosition(pos
);
5940 event
.SetOrientation(orientation
);
5941 event
.SetEventObject(this);
5946 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5950 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5954 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5958 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5962 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5966 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5969 case SB_THUMBPOSITION
:
5971 // under Win32, the scrollbar range and position are 32 bit integers,
5972 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5973 // explicitly query the scrollbar for the correct position (this must
5974 // be done only for these two SB_ events as they are the only one
5975 // carrying the scrollbar position)
5977 WinStruct
<SCROLLINFO
> scrollInfo
;
5978 scrollInfo
.fMask
= SIF_TRACKPOS
;
5980 if ( !::GetScrollInfo(GetHwnd(),
5981 WXOrientToSB(orientation
),
5984 // Not necessarily an error, if there are no scrollbars yet.
5985 // wxLogLastError(wxT("GetScrollInfo"));
5988 event
.SetPosition(scrollInfo
.nTrackPos
);
5991 event
.SetEventType( wParam
== SB_THUMBPOSITION
5992 ? wxEVT_SCROLLWIN_THUMBRELEASE
5993 : wxEVT_SCROLLWIN_THUMBTRACK
);
6000 return HandleWindowEvent(event
);
6003 // ----------------------------------------------------------------------------
6004 // custom message handlers
6005 // ----------------------------------------------------------------------------
6008 wxWindowMSW::MSWRegisterMessageHandler(int msg
, MSWMessageHandler handler
)
6010 wxCHECK_MSG( gs_messageHandlers
.find(msg
) == gs_messageHandlers
.end(),
6011 false, wxT("registering handler for the same message twice") );
6013 gs_messageHandlers
[msg
] = handler
;
6018 wxWindowMSW::MSWUnregisterMessageHandler(int msg
, MSWMessageHandler handler
)
6020 const MSWMessageHandlers::iterator i
= gs_messageHandlers
.find(msg
);
6021 wxCHECK_RET( i
!= gs_messageHandlers
.end() && i
->second
== handler
,
6022 wxT("unregistering non-registered handler?") );
6024 gs_messageHandlers
.erase(i
);
6027 // ===========================================================================
6029 // ===========================================================================
6031 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
6034 HDC dc
= ::GetDC((HWND
) wnd
);
6037 // the_font.UseResource();
6038 // the_font.RealizeResource();
6039 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
6041 was
= (HFONT
) SelectObject(dc
,fnt
);
6043 GetTextMetrics(dc
, &tm
);
6046 SelectObject(dc
,was
);
6048 ReleaseDC((HWND
)wnd
, dc
);
6051 *x
= tm
.tmAveCharWidth
;
6053 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
6055 // the_font.ReleaseResource();
6058 // ----------------------------------------------------------------------------
6060 // ----------------------------------------------------------------------------
6062 namespace wxMSWKeyboard
6068 // use the "extended" bit of lParam to distinguish extended keys from normal
6069 // keys as the same virtual key code is sent for both by Windows
6071 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
6073 // except that if lParam is 0, it means we don't have real lParam from
6074 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
6075 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
6076 // non-numpad (hence extended) key as this is a more common case
6077 return !lParam
|| (HIWORD(lParam
) & KF_EXTENDED
) ? keyExtended
: keyNormal
;
6080 // this array contains the Windows virtual key codes which map one to one to
6081 // WXK_xxx constants and is used in wxMSWKeyboard::VKToWX/WXToVK() below
6083 // note that keys having a normal and numpad version (e.g. WXK_HOME and
6084 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
6085 const struct wxKeyMapping
6089 } gs_specialKeys
[] =
6091 { VK_CANCEL
, WXK_CANCEL
},
6092 { VK_BACK
, WXK_BACK
},
6093 { VK_TAB
, WXK_TAB
},
6094 { VK_CLEAR
, WXK_CLEAR
},
6095 { VK_SHIFT
, WXK_SHIFT
},
6096 { VK_CONTROL
, WXK_CONTROL
},
6097 { VK_MENU
, WXK_ALT
},
6098 { VK_PAUSE
, WXK_PAUSE
},
6099 { VK_CAPITAL
, WXK_CAPITAL
},
6100 { VK_SPACE
, WXK_SPACE
},
6101 { VK_ESCAPE
, WXK_ESCAPE
},
6102 { VK_SELECT
, WXK_SELECT
},
6103 { VK_PRINT
, WXK_PRINT
},
6104 { VK_EXECUTE
, WXK_EXECUTE
},
6105 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
6106 { VK_HELP
, WXK_HELP
},
6108 { VK_NUMPAD0
, WXK_NUMPAD0
},
6109 { VK_NUMPAD1
, WXK_NUMPAD1
},
6110 { VK_NUMPAD2
, WXK_NUMPAD2
},
6111 { VK_NUMPAD3
, WXK_NUMPAD3
},
6112 { VK_NUMPAD4
, WXK_NUMPAD4
},
6113 { VK_NUMPAD5
, WXK_NUMPAD5
},
6114 { VK_NUMPAD6
, WXK_NUMPAD6
},
6115 { VK_NUMPAD7
, WXK_NUMPAD7
},
6116 { VK_NUMPAD8
, WXK_NUMPAD8
},
6117 { VK_NUMPAD9
, WXK_NUMPAD9
},
6118 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
6119 { VK_ADD
, WXK_NUMPAD_ADD
},
6120 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
6121 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
6122 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
6133 { VK_F10
, WXK_F10
},
6134 { VK_F11
, WXK_F11
},
6135 { VK_F12
, WXK_F12
},
6136 { VK_F13
, WXK_F13
},
6137 { VK_F14
, WXK_F14
},
6138 { VK_F15
, WXK_F15
},
6139 { VK_F16
, WXK_F16
},
6140 { VK_F17
, WXK_F17
},
6141 { VK_F18
, WXK_F18
},
6142 { VK_F19
, WXK_F19
},
6143 { VK_F20
, WXK_F20
},
6144 { VK_F21
, WXK_F21
},
6145 { VK_F22
, WXK_F22
},
6146 { VK_F23
, WXK_F23
},
6147 { VK_F24
, WXK_F24
},
6149 { VK_NUMLOCK
, WXK_NUMLOCK
},
6150 { VK_SCROLL
, WXK_SCROLL
},
6153 { VK_LWIN
, WXK_WINDOWS_LEFT
},
6154 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
6155 { VK_APPS
, WXK_WINDOWS_MENU
},
6156 #endif // VK_APPS defined
6159 } // anonymous namespace
6161 int VKToWX(WXWORD vk
, WXLPARAM lParam
)
6163 // check the table first
6164 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6166 if ( gs_specialKeys
[n
].vk
== vk
)
6167 return gs_specialKeys
[n
].wxk
;
6170 // keys requiring special handling
6174 // the mapping for these keys may be incorrect on non-US keyboards so
6175 // maybe we shouldn't map them to ASCII values at all
6176 case VK_OEM_1
: wxk
= ';'; break;
6177 case VK_OEM_PLUS
: wxk
= '+'; break;
6178 case VK_OEM_COMMA
: wxk
= ','; break;
6179 case VK_OEM_MINUS
: wxk
= '-'; break;
6180 case VK_OEM_PERIOD
: wxk
= '.'; break;
6181 case VK_OEM_2
: wxk
= '/'; break;
6182 case VK_OEM_3
: wxk
= '~'; break;
6183 case VK_OEM_4
: wxk
= '['; break;
6184 case VK_OEM_5
: wxk
= '\\'; break;
6185 case VK_OEM_6
: wxk
= ']'; break;
6186 case VK_OEM_7
: wxk
= '\''; break;
6188 // handle extended keys
6190 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
6194 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
6198 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
6202 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
6206 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
6210 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
6214 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
6218 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
6222 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
6226 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
6230 // don't use ChooseNormalOrExtended() here as the keys are reversed
6231 // here: numpad enter is the extended one
6232 wxk
= HIWORD(lParam
) & KF_EXTENDED
? WXK_NUMPAD_ENTER
: WXK_RETURN
;
6236 // must be a simple alphanumeric key and the values of them
6237 // coincide in Windows and wx
6244 WXWORD
WXToVK(int wxk
, bool *isExtended
)
6246 // check the table first
6247 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6249 if ( gs_specialKeys
[n
].wxk
== wxk
)
6251 // All extended keys (i.e. non-numpad versions of the keys that
6252 // exist both in the numpad and outside of it) are dealt with
6255 *isExtended
= false;
6257 return gs_specialKeys
[n
].vk
;
6261 // and then check for special keys not included in the table
6262 bool extended
= false;
6268 case WXK_NUMPAD_PAGEUP
:
6274 case WXK_NUMPAD_PAGEDOWN
:
6280 case WXK_NUMPAD_END
:
6286 case WXK_NUMPAD_HOME
:
6292 case WXK_NUMPAD_LEFT
:
6304 case WXK_NUMPAD_RIGHT
:
6310 case WXK_NUMPAD_DOWN
:
6316 case WXK_NUMPAD_INSERT
:
6322 case WXK_NUMPAD_DELETE
:
6327 // no VkKeyScan() under CE unfortunately, we need to test how does
6328 // it handle OEM keys
6330 // check to see if its one of the OEM key codes.
6331 BYTE vks
= LOBYTE(VkKeyScan(wxk
));
6337 #endif // !__WXWINCE__
6344 *isExtended
= extended
;
6349 } // namespace wxMSWKeyboard
6351 // small helper for wxGetKeyState() and wxGetMouseState()
6352 static inline bool wxIsKeyDown(WXWORD vk
)
6354 // SM_SWAPBUTTON is not available under CE, so don't swap buttons there
6355 #ifdef SM_SWAPBUTTON
6356 if ( vk
== VK_LBUTTON
|| vk
== VK_RBUTTON
)
6358 if ( ::GetSystemMetrics(SM_SWAPBUTTON
) )
6360 if ( vk
== VK_LBUTTON
)
6362 else // vk == VK_RBUTTON
6366 #endif // SM_SWAPBUTTON
6368 // the low order bit indicates whether the key was pressed since the last
6369 // call and the high order one indicates whether it is down right now and
6370 // we only want that one
6371 return (GetAsyncKeyState(vk
) & (1<<15)) != 0;
6374 bool wxGetKeyState(wxKeyCode key
)
6376 // although this does work under Windows, it is not supported under other
6377 // platforms so don't allow it, you must use wxGetMouseState() instead
6378 wxASSERT_MSG( key
!= VK_LBUTTON
&&
6379 key
!= VK_RBUTTON
&&
6381 wxT("can't use wxGetKeyState() for mouse buttons") );
6383 const WXWORD vk
= wxMSWKeyboard::WXToVK(key
);
6385 // if the requested key is a LED key, return true if the led is pressed
6386 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
6388 // low order bit means LED is highlighted and high order one means the
6389 // key is down; for compatibility with the other ports return true if
6390 // either one is set
6391 return GetKeyState(vk
) != 0;
6396 return wxIsKeyDown(vk
);
6401 wxMouseState
wxGetMouseState()
6405 GetCursorPos( &pt
);
6409 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
6410 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
6411 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
6412 #ifdef wxHAS_XBUTTON
6413 ms
.SetAux1Down(wxIsKeyDown(VK_XBUTTON1
));
6414 ms
.SetAux2Down(wxIsKeyDown(VK_XBUTTON2
));
6415 #endif // wxHAS_XBUTTON
6417 ms
.SetControlDown(wxIsCtrlDown ());
6418 ms
.SetShiftDown (wxIsShiftDown());
6419 ms
.SetAltDown (wxIsAltDown ());
6420 // ms.SetMetaDown();
6426 wxWindow
*wxGetActiveWindow()
6428 HWND hWnd
= GetActiveWindow();
6431 return wxFindWinFromHandle(hWnd
);
6436 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
6438 HWND hwnd
= (HWND
)hWnd
;
6440 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
6441 // by code in msw/radiobox.cpp), for all the others we just search up the
6443 wxWindow
*win
= NULL
;
6446 win
= wxFindWinFromHandle(hwnd
);
6450 // native radiobuttons return DLGC_RADIOBUTTON here and for any
6451 // wxWindow class which overrides WM_GETDLGCODE processing to
6452 // do it as well, win would be already non NULL
6453 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
6455 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
6457 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
6458 #endif // wxUSE_RADIOBOX
6460 // spin control text buddy window should be mapped to spin ctrl
6461 // itself so try it too
6462 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
6465 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
6467 #endif // wxUSE_SPINCTRL
6471 while ( hwnd
&& !win
)
6473 // this is a really ugly hack needed to avoid mistakenly returning the
6474 // parent frame wxWindow for the find/replace modeless dialog HWND -
6475 // this, in turn, is needed to call IsDialogMessage() from
6476 // wxApp::ProcessMessage() as for this we must return NULL from here
6478 // FIXME: this is clearly not the best way to do it but I think we'll
6479 // need to change HWND <-> wxWindow code more heavily than I can
6480 // do it now to fix it
6481 #ifndef __WXMICROWIN__
6482 if ( ::GetWindow(hwnd
, GW_OWNER
) )
6484 // it's a dialog box, don't go upwards
6489 hwnd
= ::GetParent(hwnd
);
6490 win
= wxFindWinFromHandle(hwnd
);
6496 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
6498 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
6499 // in active frames and dialogs, regardless of where the focus is.
6500 static HHOOK wxTheKeyboardHook
= 0;
6503 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
6505 DWORD hiWord
= HIWORD(lParam
);
6506 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
6508 int id
= wxMSWKeyboard::VKToWX(wParam
, lParam
);
6509 if ( id
>= WXK_START
)
6511 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
6512 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
6513 event
.m_altDown
= true;
6515 event
.SetEventObject(NULL
);
6516 event
.m_keyCode
= id
;
6517 event
.m_shiftDown
= wxIsShiftDown();
6518 event
.m_controlDown
= wxIsCtrlDown();
6520 event
.SetTimestamp(::GetMessageTime());
6522 wxWindow
*win
= wxGetActiveWindow();
6523 wxEvtHandler
*handler
;
6526 handler
= win
->GetEventHandler();
6527 event
.SetId(win
->GetId());
6532 event
.SetId(wxID_ANY
);
6535 if ( handler
&& handler
->ProcessEvent(event
) )
6543 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
6546 void wxSetKeyboardHook(bool doIt
)
6550 wxTheKeyboardHook
= ::SetWindowsHookEx
6553 (HOOKPROC
)wxKeyboardHook
,
6554 NULL
, // must be NULL for process hook
6555 ::GetCurrentThreadId()
6557 if ( !wxTheKeyboardHook
)
6559 wxLogLastError(wxT("SetWindowsHookEx(wxKeyboardHook)"));
6564 if ( wxTheKeyboardHook
)
6565 ::UnhookWindowsHookEx(wxTheKeyboardHook
);
6569 #endif // !__WXMICROWIN__
6571 #if wxDEBUG_LEVEL >= 2
6572 const wxChar
*wxGetMessageName(int message
)
6576 case 0x0000: return wxT("WM_NULL");
6577 case 0x0001: return wxT("WM_CREATE");
6578 case 0x0002: return wxT("WM_DESTROY");
6579 case 0x0003: return wxT("WM_MOVE");
6580 case 0x0005: return wxT("WM_SIZE");
6581 case 0x0006: return wxT("WM_ACTIVATE");
6582 case 0x0007: return wxT("WM_SETFOCUS");
6583 case 0x0008: return wxT("WM_KILLFOCUS");
6584 case 0x000A: return wxT("WM_ENABLE");
6585 case 0x000B: return wxT("WM_SETREDRAW");
6586 case 0x000C: return wxT("WM_SETTEXT");
6587 case 0x000D: return wxT("WM_GETTEXT");
6588 case 0x000E: return wxT("WM_GETTEXTLENGTH");
6589 case 0x000F: return wxT("WM_PAINT");
6590 case 0x0010: return wxT("WM_CLOSE");
6591 case 0x0011: return wxT("WM_QUERYENDSESSION");
6592 case 0x0012: return wxT("WM_QUIT");
6593 case 0x0013: return wxT("WM_QUERYOPEN");
6594 case 0x0014: return wxT("WM_ERASEBKGND");
6595 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
6596 case 0x0016: return wxT("WM_ENDSESSION");
6597 case 0x0017: return wxT("WM_SYSTEMERROR");
6598 case 0x0018: return wxT("WM_SHOWWINDOW");
6599 case 0x0019: return wxT("WM_CTLCOLOR");
6600 case 0x001A: return wxT("WM_WININICHANGE");
6601 case 0x001B: return wxT("WM_DEVMODECHANGE");
6602 case 0x001C: return wxT("WM_ACTIVATEAPP");
6603 case 0x001D: return wxT("WM_FONTCHANGE");
6604 case 0x001E: return wxT("WM_TIMECHANGE");
6605 case 0x001F: return wxT("WM_CANCELMODE");
6606 case 0x0020: return wxT("WM_SETCURSOR");
6607 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6608 case 0x0022: return wxT("WM_CHILDACTIVATE");
6609 case 0x0023: return wxT("WM_QUEUESYNC");
6610 case 0x0024: return wxT("WM_GETMINMAXINFO");
6611 case 0x0026: return wxT("WM_PAINTICON");
6612 case 0x0027: return wxT("WM_ICONERASEBKGND");
6613 case 0x0028: return wxT("WM_NEXTDLGCTL");
6614 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6615 case 0x002B: return wxT("WM_DRAWITEM");
6616 case 0x002C: return wxT("WM_MEASUREITEM");
6617 case 0x002D: return wxT("WM_DELETEITEM");
6618 case 0x002E: return wxT("WM_VKEYTOITEM");
6619 case 0x002F: return wxT("WM_CHARTOITEM");
6620 case 0x0030: return wxT("WM_SETFONT");
6621 case 0x0031: return wxT("WM_GETFONT");
6622 case 0x0037: return wxT("WM_QUERYDRAGICON");
6623 case 0x0039: return wxT("WM_COMPAREITEM");
6624 case 0x0041: return wxT("WM_COMPACTING");
6625 case 0x0044: return wxT("WM_COMMNOTIFY");
6626 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6627 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6628 case 0x0048: return wxT("WM_POWER");
6630 case 0x004A: return wxT("WM_COPYDATA");
6631 case 0x004B: return wxT("WM_CANCELJOURNAL");
6632 case 0x004E: return wxT("WM_NOTIFY");
6633 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6634 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6635 case 0x0052: return wxT("WM_TCARD");
6636 case 0x0053: return wxT("WM_HELP");
6637 case 0x0054: return wxT("WM_USERCHANGED");
6638 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6639 case 0x007B: return wxT("WM_CONTEXTMENU");
6640 case 0x007C: return wxT("WM_STYLECHANGING");
6641 case 0x007D: return wxT("WM_STYLECHANGED");
6642 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6643 case 0x007F: return wxT("WM_GETICON");
6644 case 0x0080: return wxT("WM_SETICON");
6646 case 0x0081: return wxT("WM_NCCREATE");
6647 case 0x0082: return wxT("WM_NCDESTROY");
6648 case 0x0083: return wxT("WM_NCCALCSIZE");
6649 case 0x0084: return wxT("WM_NCHITTEST");
6650 case 0x0085: return wxT("WM_NCPAINT");
6651 case 0x0086: return wxT("WM_NCACTIVATE");
6652 case 0x0087: return wxT("WM_GETDLGCODE");
6653 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6654 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6655 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6656 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6657 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6658 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6659 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6660 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6661 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6662 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6664 case 0x00B0: return wxT("EM_GETSEL");
6665 case 0x00B1: return wxT("EM_SETSEL");
6666 case 0x00B2: return wxT("EM_GETRECT");
6667 case 0x00B3: return wxT("EM_SETRECT");
6668 case 0x00B4: return wxT("EM_SETRECTNP");
6669 case 0x00B5: return wxT("EM_SCROLL");
6670 case 0x00B6: return wxT("EM_LINESCROLL");
6671 case 0x00B7: return wxT("EM_SCROLLCARET");
6672 case 0x00B8: return wxT("EM_GETMODIFY");
6673 case 0x00B9: return wxT("EM_SETMODIFY");
6674 case 0x00BA: return wxT("EM_GETLINECOUNT");
6675 case 0x00BB: return wxT("EM_LINEINDEX");
6676 case 0x00BC: return wxT("EM_SETHANDLE");
6677 case 0x00BD: return wxT("EM_GETHANDLE");
6678 case 0x00BE: return wxT("EM_GETTHUMB");
6679 case 0x00C1: return wxT("EM_LINELENGTH");
6680 case 0x00C2: return wxT("EM_REPLACESEL");
6681 case 0x00C4: return wxT("EM_GETLINE");
6682 case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */
6683 case 0x00C6: return wxT("EM_CANUNDO");
6684 case 0x00C7: return wxT("EM_UNDO");
6685 case 0x00C8: return wxT("EM_FMTLINES");
6686 case 0x00C9: return wxT("EM_LINEFROMCHAR");
6687 case 0x00CB: return wxT("EM_SETTABSTOPS");
6688 case 0x00CC: return wxT("EM_SETPASSWORDCHAR");
6689 case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER");
6690 case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE");
6691 case 0x00CF: return wxT("EM_SETREADONLY");
6692 case 0x00D0: return wxT("EM_SETWORDBREAKPROC");
6693 case 0x00D1: return wxT("EM_GETWORDBREAKPROC");
6694 case 0x00D2: return wxT("EM_GETPASSWORDCHAR");
6695 case 0x00D3: return wxT("EM_SETMARGINS");
6696 case 0x00D4: return wxT("EM_GETMARGINS");
6697 case 0x00D5: return wxT("EM_GETLIMITTEXT");
6698 case 0x00D6: return wxT("EM_POSFROMCHAR");
6699 case 0x00D7: return wxT("EM_CHARFROMPOS");
6700 case 0x00D8: return wxT("EM_SETIMESTATUS");
6701 case 0x00D9: return wxT("EM_GETIMESTATUS");
6703 case 0x0100: return wxT("WM_KEYDOWN");
6704 case 0x0101: return wxT("WM_KEYUP");
6705 case 0x0102: return wxT("WM_CHAR");
6706 case 0x0103: return wxT("WM_DEADCHAR");
6707 case 0x0104: return wxT("WM_SYSKEYDOWN");
6708 case 0x0105: return wxT("WM_SYSKEYUP");
6709 case 0x0106: return wxT("WM_SYSCHAR");
6710 case 0x0107: return wxT("WM_SYSDEADCHAR");
6711 case 0x0108: return wxT("WM_KEYLAST");
6713 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6714 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6715 case 0x010F: return wxT("WM_IME_COMPOSITION");
6717 case 0x0110: return wxT("WM_INITDIALOG");
6718 case 0x0111: return wxT("WM_COMMAND");
6719 case 0x0112: return wxT("WM_SYSCOMMAND");
6720 case 0x0113: return wxT("WM_TIMER");
6721 case 0x0114: return wxT("WM_HSCROLL");
6722 case 0x0115: return wxT("WM_VSCROLL");
6723 case 0x0116: return wxT("WM_INITMENU");
6724 case 0x0117: return wxT("WM_INITMENUPOPUP");
6725 case 0x011F: return wxT("WM_MENUSELECT");
6726 case 0x0120: return wxT("WM_MENUCHAR");
6727 case 0x0121: return wxT("WM_ENTERIDLE");
6729 case 0x0127: return wxT("WM_CHANGEUISTATE");
6730 case 0x0128: return wxT("WM_UPDATEUISTATE");
6731 case 0x0129: return wxT("WM_QUERYUISTATE");
6733 case 0x0132: return wxT("WM_CTLCOLORMSGBOX");
6734 case 0x0133: return wxT("WM_CTLCOLOREDIT");
6735 case 0x0134: return wxT("WM_CTLCOLORLISTBOX");
6736 case 0x0135: return wxT("WM_CTLCOLORBTN");
6737 case 0x0136: return wxT("WM_CTLCOLORDLG");
6738 case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR");
6739 case 0x0138: return wxT("WM_CTLCOLORSTATIC");
6740 case 0x01E1: return wxT("MN_GETHMENU");
6742 case 0x0200: return wxT("WM_MOUSEMOVE");
6743 case 0x0201: return wxT("WM_LBUTTONDOWN");
6744 case 0x0202: return wxT("WM_LBUTTONUP");
6745 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6746 case 0x0204: return wxT("WM_RBUTTONDOWN");
6747 case 0x0205: return wxT("WM_RBUTTONUP");
6748 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6749 case 0x0207: return wxT("WM_MBUTTONDOWN");
6750 case 0x0208: return wxT("WM_MBUTTONUP");
6751 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6752 case 0x020A: return wxT("WM_MOUSEWHEEL");
6753 case 0x020B: return wxT("WM_XBUTTONDOWN");
6754 case 0x020C: return wxT("WM_XBUTTONUP");
6755 case 0x020D: return wxT("WM_XBUTTONDBLCLK");
6756 case 0x0210: return wxT("WM_PARENTNOTIFY");
6757 case 0x0211: return wxT("WM_ENTERMENULOOP");
6758 case 0x0212: return wxT("WM_EXITMENULOOP");
6760 case 0x0213: return wxT("WM_NEXTMENU");
6761 case 0x0214: return wxT("WM_SIZING");
6762 case 0x0215: return wxT("WM_CAPTURECHANGED");
6763 case 0x0216: return wxT("WM_MOVING");
6764 case 0x0218: return wxT("WM_POWERBROADCAST");
6765 case 0x0219: return wxT("WM_DEVICECHANGE");
6767 case 0x0220: return wxT("WM_MDICREATE");
6768 case 0x0221: return wxT("WM_MDIDESTROY");
6769 case 0x0222: return wxT("WM_MDIACTIVATE");
6770 case 0x0223: return wxT("WM_MDIRESTORE");
6771 case 0x0224: return wxT("WM_MDINEXT");
6772 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6773 case 0x0226: return wxT("WM_MDITILE");
6774 case 0x0227: return wxT("WM_MDICASCADE");
6775 case 0x0228: return wxT("WM_MDIICONARRANGE");
6776 case 0x0229: return wxT("WM_MDIGETACTIVE");
6777 case 0x0230: return wxT("WM_MDISETMENU");
6778 case 0x0233: return wxT("WM_DROPFILES");
6780 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6781 case 0x0282: return wxT("WM_IME_NOTIFY");
6782 case 0x0283: return wxT("WM_IME_CONTROL");
6783 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6784 case 0x0285: return wxT("WM_IME_SELECT");
6785 case 0x0286: return wxT("WM_IME_CHAR");
6786 case 0x0290: return wxT("WM_IME_KEYDOWN");
6787 case 0x0291: return wxT("WM_IME_KEYUP");
6789 case 0x02A0: return wxT("WM_NCMOUSEHOVER");
6790 case 0x02A1: return wxT("WM_MOUSEHOVER");
6791 case 0x02A2: return wxT("WM_NCMOUSELEAVE");
6792 case 0x02A3: return wxT("WM_MOUSELEAVE");
6794 case 0x0300: return wxT("WM_CUT");
6795 case 0x0301: return wxT("WM_COPY");
6796 case 0x0302: return wxT("WM_PASTE");
6797 case 0x0303: return wxT("WM_CLEAR");
6798 case 0x0304: return wxT("WM_UNDO");
6799 case 0x0305: return wxT("WM_RENDERFORMAT");
6800 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6801 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6802 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6803 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6804 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6805 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6806 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6807 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6808 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6809 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6810 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6811 case 0x0311: return wxT("WM_PALETTECHANGED");
6812 case 0x0312: return wxT("WM_HOTKEY");
6814 case 0x0317: return wxT("WM_PRINT");
6815 case 0x0318: return wxT("WM_PRINTCLIENT");
6817 // common controls messages - although they're not strictly speaking
6818 // standard, it's nice to decode them nevertheless
6821 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6822 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6823 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6824 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6825 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6826 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6827 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6828 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6829 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6830 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6831 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6832 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6833 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6834 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6835 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6836 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6837 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6838 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6839 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6840 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6841 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6842 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6843 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6844 case 0x1000 + 18: return wxT("LVM_HITTEST");
6845 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6846 case 0x1000 + 20: return wxT("LVM_SCROLL");
6847 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6848 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6849 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6850 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6851 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6852 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6853 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6854 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6855 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6856 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6857 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6858 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6859 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6860 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6861 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6862 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6863 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6864 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6865 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6866 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6867 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6868 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6869 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6870 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6871 case 0x1000 + 42: return wxT("LVM_UPDATE");
6872 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6873 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6874 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6875 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6876 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6877 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6878 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6879 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6880 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6881 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6882 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6883 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6884 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6885 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6886 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6887 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6888 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6889 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6890 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6891 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6892 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6893 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6894 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6895 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6896 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6897 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6900 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6901 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6902 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6903 case 0x1100 + 2: return wxT("TVM_EXPAND");
6904 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6905 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6906 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6907 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6908 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6909 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6910 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6911 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6912 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6913 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6914 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6915 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6916 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6917 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6918 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6919 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6920 case 0x1100 + 17: return wxT("TVM_HITTEST");
6921 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6922 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6923 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6924 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6925 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6926 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6927 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6928 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6929 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6932 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6933 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6934 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6935 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6936 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6937 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6938 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6939 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6940 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6941 case 0x1200 + 6: return wxT("HDM_HITTEST");
6942 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6943 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6944 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6945 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6946 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6947 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6948 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6949 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6952 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6953 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6954 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6955 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6956 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6957 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6958 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6959 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6960 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6961 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6962 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6963 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6964 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6965 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6966 case 0x1300 + 13: return wxT("TCM_HITTEST");
6967 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6968 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6969 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6970 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6971 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6972 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6973 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6974 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6975 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6976 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6977 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6978 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6981 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6982 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
6983 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
6984 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
6985 case WM_USER
+5: return wxT("TB_INDETERMINATE");
6986 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
6987 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
6988 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
6989 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
6990 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
6991 case WM_USER
+17: return wxT("TB_SETSTATE");
6992 case WM_USER
+18: return wxT("TB_GETSTATE");
6993 case WM_USER
+19: return wxT("TB_ADDBITMAP");
6994 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
6995 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
6996 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
6997 case WM_USER
+23: return wxT("TB_GETBUTTON");
6998 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
6999 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
7000 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
7001 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
7002 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
7003 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
7004 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
7005 case WM_USER
+29: return wxT("TB_GETITEMRECT");
7006 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
7007 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
7008 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
7009 case WM_USER
+33: return wxT("TB_AUTOSIZE");
7010 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
7011 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
7012 case WM_USER
+37: return wxT("TB_SETPARENT");
7013 case WM_USER
+39: return wxT("TB_SETROWS");
7014 case WM_USER
+40: return wxT("TB_GETROWS");
7015 case WM_USER
+42: return wxT("TB_SETCMDID");
7016 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
7017 case WM_USER
+44: return wxT("TB_GETBITMAP");
7018 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
7019 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
7020 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
7021 case WM_USER
+47: return wxT("TB_SETINDENT");
7022 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
7023 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
7024 case WM_USER
+50: return wxT("TB_LOADIMAGES");
7025 case WM_USER
+51: return wxT("TB_GETRECT");
7026 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
7027 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
7028 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
7029 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
7030 case WM_USER
+56: return wxT("TB_SETSTYLE");
7031 case WM_USER
+57: return wxT("TB_GETSTYLE");
7032 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
7033 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
7034 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
7035 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
7036 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
7039 static wxString s_szBuf
;
7040 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
7041 return s_szBuf
.c_str();
7044 #endif // wxDEBUG_LEVEL >= 2
7046 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
7050 HWND hwnd
= GetHwndOf(win
);
7051 HDC hdc
= ::GetDC(hwnd
);
7053 #if !wxDIALOG_UNIT_COMPATIBILITY
7054 // and select the current font into it
7055 HFONT hfont
= GetHfontOf(win
->GetFont());
7058 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
7062 // finally retrieve the text metrics from it
7063 GetTextMetrics(hdc
, &tm
);
7065 #if !wxDIALOG_UNIT_COMPATIBILITY
7069 (void)::SelectObject(hdc
, hfont
);
7073 ::ReleaseDC(hwnd
, hdc
);
7078 // Find the wxWindow at the current mouse position, returning the mouse
7080 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
7082 pt
= wxGetMousePosition();
7083 return wxFindWindowAtPoint(pt
);
7086 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
7092 HWND hWnd
= ::WindowFromPoint(pt2
);
7094 return wxGetWindowFromHWND((WXHWND
)hWnd
);
7097 // Get the current mouse position.
7098 wxPoint
wxGetMousePosition()
7102 GetCursorPosWinCE(&pt
);
7104 GetCursorPos( & pt
);
7107 return wxPoint(pt
.x
, pt
.y
);
7112 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7113 static void WinCEUnregisterHotKey(int modifiers
, int id
)
7115 // Register hotkeys for the hardware buttons
7117 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
7119 UnregisterFunc1Proc procUnregisterFunc
;
7120 hCoreDll
= LoadLibrary(wxT("coredll.dll"));
7123 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, wxT("UnregisterFunc1"));
7124 if (procUnregisterFunc
)
7125 procUnregisterFunc(modifiers
, id
);
7126 FreeLibrary(hCoreDll
);
7131 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
7133 UINT win_modifiers
=0;
7134 if ( modifiers
& wxMOD_ALT
)
7135 win_modifiers
|= MOD_ALT
;
7136 if ( modifiers
& wxMOD_SHIFT
)
7137 win_modifiers
|= MOD_SHIFT
;
7138 if ( modifiers
& wxMOD_CONTROL
)
7139 win_modifiers
|= MOD_CONTROL
;
7140 if ( modifiers
& wxMOD_WIN
)
7141 win_modifiers
|= MOD_WIN
;
7143 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7144 // Required for PPC and Smartphone hardware buttons
7145 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
7146 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
7149 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
7151 wxLogLastError(wxT("RegisterHotKey"));
7159 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
7161 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7162 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
7165 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
7167 wxLogLastError(wxT("UnregisterHotKey"));
7177 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
7179 int win_modifiers
= LOWORD(lParam
);
7181 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, HIWORD(lParam
)));
7182 event
.SetId(wParam
);
7183 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
7184 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
7185 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
7186 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
7188 return HandleWindowEvent(event
);
7191 #endif // wxUSE_ACCEL
7193 #endif // wxUSE_HOTKEY
7195 // Not tested under WinCE
7198 // this class installs a message hook which really wakes up our idle processing
7199 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
7200 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
7201 // being dragged or even inside ::MessageBox()) and so don't control message
7202 // dispatching otherwise
7203 class wxIdleWakeUpModule
: public wxModule
7206 virtual bool OnInit()
7208 ms_hMsgHookProc
= ::SetWindowsHookEx
7211 &wxIdleWakeUpModule::MsgHookProc
,
7213 GetCurrentThreadId()
7216 if ( !ms_hMsgHookProc
)
7218 wxLogLastError(wxT("SetWindowsHookEx(WH_GETMESSAGE)"));
7226 virtual void OnExit()
7228 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
7231 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
7233 MSG
*msg
= (MSG
*)lParam
;
7235 // only process the message if it is actually going to be removed from
7236 // the message queue, this prevents that the same event from being
7237 // processed multiple times if now someone just called PeekMessage()
7238 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
7240 wxTheApp
->ProcessPendingEvents();
7243 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
7247 static HHOOK ms_hMsgHookProc
;
7249 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
7252 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
7254 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
7256 #endif // __WXWINCE__
7261 static void wxAdjustZOrder(wxWindow
* parent
)
7263 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
7265 // Set the z-order correctly
7266 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
7269 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
7272 wxWindow
*childWin
= current
->GetData();
7273 wxAdjustZOrder(childWin
);
7274 current
= current
->GetNext();
7279 // We need to adjust the z-order of static boxes in WinCE, to
7280 // make 'contained' controls visible
7281 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
7284 wxAdjustZOrder(this);