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/radiobox.h"
95 #endif // wxUSE_RADIOBOX
98 #include "wx/spinctrl.h"
99 #endif // wxUSE_SPINCTRL
101 #include "wx/notebook.h"
102 #include "wx/listctrl.h"
103 #include "wx/dynlib.h"
107 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
108 #include <shellapi.h>
109 #include <mmsystem.h>
113 #include <windowsx.h>
116 #if !defined __WXWINCE__ && !defined NEED_PBT_H
120 #if defined(__WXWINCE__)
121 #include "wx/msw/wince/missing.h"
124 #include <shellapi.h>
126 #include <aygshell.h>
131 #include "wx/msw/uxtheme.h"
132 #define EP_EDITTEXT 1
135 #define ETS_SELECTED 3
136 #define ETS_DISABLED 4
137 #define ETS_FOCUSED 5
138 #define ETS_READONLY 6
142 // define the constants used by AnimateWindow() if our SDK doesn't have them
144 #define AW_HOR_POSITIVE 0x00000001
145 #define AW_HOR_NEGATIVE 0x00000002
146 #define AW_VER_POSITIVE 0x00000004
147 #define AW_VER_NEGATIVE 0x00000008
148 #define AW_CENTER 0x00000010
149 #define AW_HIDE 0x00010000
150 #define AW_ACTIVATE 0x00020000
151 #define AW_SLIDE 0x00040000
152 #define AW_BLEND 0x00080000
155 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS
156 #define HAVE_TRACKMOUSEEVENT
157 #endif // everything needed for TrackMouseEvent()
159 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
160 // when mouse position didnd't change
162 #define wxUSE_MOUSEEVENT_HACK 0
164 #define wxUSE_MOUSEEVENT_HACK 1
167 // not all compilers/platforms have X button related declarations (notably
168 // Windows CE doesn't, and probably some old SDKs don't neither)
169 #ifdef WM_XBUTTONDOWN
170 #define wxHAS_XBUTTON
173 #ifndef MAPVK_VK_TO_CHAR
174 #define MAPVK_VK_TO_CHAR 2
177 // ---------------------------------------------------------------------------
179 // ---------------------------------------------------------------------------
181 #if wxUSE_MENUS_NATIVE
182 extern wxMenu
*wxCurrentPopupMenu
;
188 // true if we had already created the std colour map, used by
189 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
190 bool gs_hasStdCmap
= false;
192 // last mouse event information we need to filter out the duplicates
193 #if wxUSE_MOUSEEVENT_HACK
194 struct MouseEventInfoDummy
196 // mouse position (in screen coordinates)
199 // last mouse event type
202 #endif // wxUSE_MOUSEEVENT_HACK
204 // hash containing the registered handlers for the custom messages
205 WX_DECLARE_HASH_MAP(int, wxWindow::MSWMessageHandler
,
206 wxIntegerHash
, wxIntegerEqual
,
209 MSWMessageHandlers gs_messageHandlers
;
211 // hash containing all our windows, it uses HWND keys and wxWindow* values
212 WX_DECLARE_HASH_MAP(HWND
, wxWindow
*,
213 wxPointerHash
, wxPointerEqual
,
216 WindowHandles gs_windowHandles
;
218 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
220 // temporary override for WM_ERASEBKGND processing: we don't store this in
221 // wxWindow itself as we don't need it during most of the time so don't
222 // increase the size of all window objects unnecessarily
223 WX_DECLARE_HASH_MAP(wxWindow
*, wxWindow
*,
224 wxPointerHash
, wxPointerEqual
,
227 EraseBgHooks gs_eraseBgHooks
;
229 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
231 } // anonymous namespace
233 // ---------------------------------------------------------------------------
235 // ---------------------------------------------------------------------------
237 // the window proc for all our windows
238 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
239 WPARAM wParam
, LPARAM lParam
);
242 #if wxDEBUG_LEVEL >= 2
243 const wxChar
*wxGetMessageName(int message
);
244 #endif // wxDEBUG_LEVEL >= 2
246 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
247 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
249 // get the text metrics for the current font
250 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
253 // find the window for the mouse event at the specified position
254 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
255 #endif // __WXWINCE__
257 // wrapper around BringWindowToTop() API
258 static inline void wxBringWindowToTop(HWND hwnd
)
260 #ifdef __WXMICROWIN__
261 // It seems that MicroWindows brings the _parent_ of the window to the top,
262 // which can be the wrong one.
264 // activate (set focus to) specified window
268 // raise top level parent to top of z order
269 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
271 wxLogLastError(wxT("SetWindowPos"));
277 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
278 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
281 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
282 parent as well as otherwise several Win32 functions using
283 GetNextDlgTabItem() to iterate over all controls such as
284 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
285 all of them iterate over all the controls starting from the currently
286 focused one and stop iterating when they get back to the focus but
287 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
288 get back to the initial (focused) window: as we do have this style,
289 GetNextDlgTabItem() will leave this window and continue in its parent,
290 but if the parent doesn't have it, it wouldn't recurse inside it later
291 on and so wouldn't have a chance of getting back to this window either.
293 while ( parent
&& !parent
->IsTopLevel() )
295 LONG exStyle
= wxGetWindowExStyle(parent
);
296 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
298 // force the parent to have this style
299 wxSetWindowExStyle(parent
, exStyle
| WS_EX_CONTROLPARENT
);
302 parent
= parent
->GetParent();
306 #endif // !__WXWINCE__
309 // On Windows CE, GetCursorPos can return an error, so use this function
311 bool GetCursorPosWinCE(POINT
* pt
)
313 if (!GetCursorPos(pt
))
315 DWORD pos
= GetMessagePos();
323 // ---------------------------------------------------------------------------
325 // ---------------------------------------------------------------------------
327 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
329 #ifdef __WXUNIVERSAL__
330 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
332 #if wxUSE_EXTENDED_RTTI
334 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
335 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
336 // windows with negative ids never can be recreated anyway
338 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
340 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
341 if ( win
&& win
->GetId() < 0 )
346 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
348 // make wxWindowList known before the property is used
350 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
352 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
354 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
357 WX_DEFINE_FLAGS( wxWindowStyle
)
359 wxBEGIN_FLAGS( wxWindowStyle
)
360 // new style border flags, we put them first to
361 // use them for streaming out
363 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
364 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
365 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
366 wxFLAGS_MEMBER(wxBORDER_RAISED
)
367 wxFLAGS_MEMBER(wxBORDER_STATIC
)
368 wxFLAGS_MEMBER(wxBORDER_NONE
)
370 // old style border flags
371 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
372 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
373 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
374 wxFLAGS_MEMBER(wxRAISED_BORDER
)
375 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
376 wxFLAGS_MEMBER(wxBORDER
)
378 // standard window styles
379 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
380 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
381 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
382 wxFLAGS_MEMBER(wxWANTS_CHARS
)
383 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
384 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
385 wxFLAGS_MEMBER(wxVSCROLL
)
386 wxFLAGS_MEMBER(wxHSCROLL
)
388 wxEND_FLAGS( wxWindowStyle
)
390 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
391 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
392 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
393 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
394 // Always constructor Properties first
396 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
397 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
398 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
399 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
400 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
402 // Then all relations of the object graph
404 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
406 // and finally all other properties
408 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
409 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
410 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
411 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
412 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
414 // possible property candidates (not in xrc) or not valid in all subclasses
415 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
416 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
417 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
418 // MaxHeight, Width , MinHeight , Width
419 // TODO switch label to control and title to toplevels
421 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
422 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
423 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
424 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
429 wxEND_PROPERTIES_TABLE()
431 wxBEGIN_HANDLERS_TABLE(wxWindow
)
432 wxEND_HANDLERS_TABLE()
434 wxCONSTRUCTOR_DUMMY(wxWindow
)
437 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
439 #endif // __WXUNIVERSAL__/__WXMSW__
441 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
442 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
444 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
448 // ===========================================================================
450 // ===========================================================================
452 // ---------------------------------------------------------------------------
453 // wxWindow utility functions
454 // ---------------------------------------------------------------------------
456 // Find an item given the MS Windows id
457 wxWindow
*wxWindowMSW::FindItem(long id
) const
460 wxControl
*item
= wxDynamicCastThis(wxControl
);
463 // is it us or one of our "internal" children?
464 if ( item
->GetId() == id
465 #ifndef __WXUNIVERSAL__
466 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
467 #endif // __WXUNIVERSAL__
473 #endif // wxUSE_CONTROLS
475 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
478 wxWindow
*childWin
= current
->GetData();
480 wxWindow
*wnd
= childWin
->FindItem(id
);
484 current
= current
->GetNext();
490 // Find an item given the MS Windows handle
491 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
493 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
496 wxWindow
*parent
= current
->GetData();
498 // Do a recursive search.
499 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
505 || parent
->IsKindOf(CLASSINFO(wxControl
))
506 #endif // wxUSE_CONTROLS
509 wxWindow
*item
= current
->GetData();
510 if ( item
->GetHWND() == hWnd
)
514 if ( item
->ContainsHWND(hWnd
) )
519 current
= current
->GetNext();
524 // Default command handler
525 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
530 // ----------------------------------------------------------------------------
531 // constructors and such
532 // ----------------------------------------------------------------------------
534 void wxWindowMSW::Init()
538 m_mouseInWindow
= false;
539 m_lastKeydownProcessed
= false;
546 #if wxUSE_DEFERRED_SIZING
548 m_pendingPosition
= wxDefaultPosition
;
549 m_pendingSize
= wxDefaultSize
;
550 #endif // wxUSE_DEFERRED_SIZING
553 m_contextMenuEnabled
= false;
558 wxWindowMSW::~wxWindowMSW()
562 #ifndef __WXUNIVERSAL__
563 // VS: make sure there's no wxFrame with last focus set to us:
564 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
566 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
569 if ( frame
->GetLastFocus() == this )
571 frame
->SetLastFocus(NULL
);
574 // apparently sometimes we can end up with our grand parent
575 // pointing to us as well: this is surely a bug in focus handling
576 // code but it's not clear where it happens so for now just try to
577 // fix it here by not breaking out of the loop
581 #endif // __WXUNIVERSAL__
583 // VS: destroy children first and _then_ detach *this from its parent.
584 // If we did it the other way around, children wouldn't be able
585 // find their parent frame (see above).
590 // VZ: test temp removed to understand what really happens here
591 //if (::IsWindow(GetHwnd()))
593 if ( !::DestroyWindow(GetHwnd()) )
595 wxLogLastError(wxT("DestroyWindow"));
599 // remove hWnd <-> wxWindow association
600 wxRemoveHandleAssociation(this);
606 const wxChar
*wxWindowMSW::MSWGetRegisteredClassName()
608 return wxApp::GetRegisteredClassName(wxT("wxWindow"), COLOR_BTNFACE
);
611 // real construction (Init() must have been called before!)
612 bool wxWindowMSW::Create(wxWindow
*parent
,
617 const wxString
& name
)
619 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
621 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
624 parent
->AddChild(this);
627 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
629 #ifdef __WXUNIVERSAL__
630 // no borders, we draw them ourselves
631 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
635 msflags
&= ~WS_BORDER
;
636 #endif // wxUniversal
640 msflags
|= WS_VISIBLE
;
643 if ( !MSWCreate(MSWGetRegisteredClassName(),
644 NULL
, pos
, size
, msflags
, exstyle
) )
652 // ---------------------------------------------------------------------------
654 // ---------------------------------------------------------------------------
656 void wxWindowMSW::SetFocus()
658 HWND hWnd
= GetHwnd();
659 wxCHECK_RET( hWnd
, wxT("can't set focus to invalid window") );
661 #if !defined(__WXWINCE__)
665 if ( !::SetFocus(hWnd
) )
667 // was there really an error?
668 DWORD dwRes
= ::GetLastError();
671 HWND hwndFocus
= ::GetFocus();
672 if ( hwndFocus
!= hWnd
)
674 wxLogApiError(wxT("SetFocus"), dwRes
);
680 void wxWindowMSW::SetFocusFromKbd()
682 // when the focus is given to the control with DLGC_HASSETSEL style from
683 // keyboard its contents should be entirely selected: this is what
684 // ::IsDialogMessage() does and so we should do it as well to provide the
685 // same LNF as the native programs
686 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
688 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
691 // do this after (maybe) setting the selection as like this when
692 // wxEVT_SET_FOCUS handler is called, the selection would have been already
693 // set correctly -- this may be important
694 wxWindowBase::SetFocusFromKbd();
697 // Get the window with the focus
698 wxWindow
*wxWindowBase::DoFindFocus()
700 HWND hWnd
= ::GetFocus();
703 return wxGetWindowFromHWND((WXHWND
)hWnd
);
709 void wxWindowMSW::DoEnable( bool enable
)
711 MSWEnableHWND(GetHwnd(), enable
);
714 bool wxWindowMSW::MSWEnableHWND(WXHWND hWnd
, bool enable
)
719 // If disabling focused control, we move focus to the next one, as if the
720 // user pressed Tab. That's because we can't keep focus on a disabled
721 // control, Tab-navigation would stop working then.
722 if ( !enable
&& ::GetFocus() == hWnd
)
725 return ::EnableWindow(hWnd
, (BOOL
)enable
) != 0;
728 bool wxWindowMSW::Show(bool show
)
730 if ( !wxWindowBase::Show(show
) )
733 HWND hWnd
= GetHwnd();
735 // we could be called before the underlying window is created (this is
736 // actually useful to prevent it from being initially shown), e.g.
738 // wxFoo *foo = new wxFoo;
740 // foo->Create(parent, ...);
742 // should work without errors
745 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
750 // DoFreeze/DoThaw don't do anything if the window is not shown, so
751 // we have to call them from here now
762 wxWindowMSW::MSWShowWithEffect(bool show
,
766 if ( effect
== wxSHOW_EFFECT_NONE
)
769 if ( !wxWindowBase::Show(show
) )
772 typedef BOOL (WINAPI
*AnimateWindow_t
)(HWND
, DWORD
, DWORD
);
774 static AnimateWindow_t s_pfnAnimateWindow
= NULL
;
775 static bool s_initDone
= false;
778 wxDynamicLibrary
dllUser32(wxT("user32.dll"), wxDL_VERBATIM
| wxDL_QUIET
);
779 wxDL_INIT_FUNC(s_pfn
, AnimateWindow
, dllUser32
);
783 // notice that it's ok to unload user32.dll here as it won't be really
784 // unloaded, being still in use because we link to it statically too
787 if ( !s_pfnAnimateWindow
)
790 // Show() has a side effect of sending a WM_SIZE to the window, which helps
791 // ensuring that it's laid out correctly, but AnimateWindow() doesn't do
792 // this so send the event ourselves
795 // prepare to use AnimateWindow()
798 timeout
= 200; // this is the default animation timeout, per MSDN
800 DWORD dwFlags
= show
? 0 : AW_HIDE
;
804 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
805 dwFlags
|= AW_HOR_NEGATIVE
;
808 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
809 dwFlags
|= AW_HOR_POSITIVE
;
812 case wxSHOW_EFFECT_ROLL_TO_TOP
:
813 dwFlags
|= AW_VER_NEGATIVE
;
816 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
817 dwFlags
|= AW_VER_POSITIVE
;
820 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
821 dwFlags
|= AW_SLIDE
| AW_HOR_NEGATIVE
;
824 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
825 dwFlags
|= AW_SLIDE
| AW_HOR_POSITIVE
;
828 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
829 dwFlags
|= AW_SLIDE
| AW_VER_NEGATIVE
;
832 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
833 dwFlags
|= AW_SLIDE
| AW_VER_POSITIVE
;
836 case wxSHOW_EFFECT_BLEND
:
840 case wxSHOW_EFFECT_EXPAND
:
841 dwFlags
|= AW_CENTER
;
845 case wxSHOW_EFFECT_MAX
:
846 wxFAIL_MSG( wxT("invalid window show effect") );
850 wxFAIL_MSG( wxT("unknown window show effect") );
854 if ( !(*s_pfnAnimateWindow
)(GetHwnd(), timeout
, dwFlags
) )
856 wxLogLastError(wxT("AnimateWindow"));
864 // Raise the window to the top of the Z order
865 void wxWindowMSW::Raise()
867 wxBringWindowToTop(GetHwnd());
870 // Lower the window to the bottom of the Z order
871 void wxWindowMSW::Lower()
873 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
874 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
877 void wxWindowMSW::DoCaptureMouse()
879 HWND hWnd
= GetHwnd();
886 void wxWindowMSW::DoReleaseMouse()
888 if ( !::ReleaseCapture() )
890 wxLogLastError(wxT("ReleaseCapture"));
894 /* static */ wxWindow
*wxWindowBase::GetCapture()
896 HWND hwnd
= ::GetCapture();
897 return hwnd
? wxFindWinFromHandle(hwnd
) : NULL
;
900 bool wxWindowMSW::SetFont(const wxFont
& font
)
902 if ( !wxWindowBase::SetFont(font
) )
908 HWND hWnd
= GetHwnd();
911 // note the use of GetFont() instead of m_font: our own font could have
912 // just been reset and in this case we need to change the font used by
913 // the native window to the default for this class, i.e. exactly what
915 WXHANDLE hFont
= GetFont().GetResourceHandle();
917 wxASSERT_MSG( hFont
, wxT("should have valid font") );
919 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
924 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
926 if ( !wxWindowBase::SetCursor(cursor
) )
932 // don't "overwrite" busy cursor
933 if ( m_cursor
.Ok() && !wxIsBusy() )
935 // normally we should change the cursor only if it's over this window
936 // but we should do it always if we capture the mouse currently
937 bool set
= HasCapture();
940 HWND hWnd
= GetHwnd();
944 ::GetCursorPosWinCE(&point
);
946 ::GetCursorPos(&point
);
949 RECT rect
= wxGetWindowRect(hWnd
);
951 set
= ::PtInRect(&rect
, point
) != 0;
956 ::SetCursor(GetHcursorOf(m_cursor
));
958 //else: will be set later when the mouse enters this window
964 void wxWindowMSW::WarpPointer(int x
, int y
)
966 ClientToScreen(&x
, &y
);
968 if ( !::SetCursorPos(x
, y
) )
970 wxLogLastError(wxT("SetCursorPos"));
974 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
976 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
977 // to use it on older systems -- and could possibly do some harm
978 static int s_needToUpdate
= -1;
979 if ( s_needToUpdate
== -1 )
982 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
986 if ( s_needToUpdate
)
988 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
989 // won't send WM_UPDATEUISTATE
990 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
994 // ---------------------------------------------------------------------------
996 // ---------------------------------------------------------------------------
1001 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
1003 #ifdef __WXMICROWIN__
1004 return ::GetScrollPosWX(hWnd
, wOrient
);
1006 WinStruct
<SCROLLINFO
> scrollInfo
;
1007 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
1008 scrollInfo
.fMask
= SIF_POS
;
1009 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
1011 return scrollInfo
.nPos
;
1016 inline UINT
WXOrientToSB(int orient
)
1018 return orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
;
1021 } // anonymous namespace
1023 int wxWindowMSW::GetScrollPos(int orient
) const
1025 HWND hWnd
= GetHwnd();
1026 wxCHECK_MSG( hWnd
, 0, wxT("no HWND in GetScrollPos") );
1028 return GetScrollPosition(hWnd
, WXOrientToSB(orient
));
1031 // This now returns the whole range, not just the number
1032 // of positions that we can scroll.
1033 int wxWindowMSW::GetScrollRange(int orient
) const
1036 HWND hWnd
= GetHwnd();
1039 WinStruct
<SCROLLINFO
> scrollInfo
;
1040 scrollInfo
.fMask
= SIF_RANGE
;
1041 if ( !::GetScrollInfo(hWnd
, WXOrientToSB(orient
), &scrollInfo
) )
1043 // Most of the time this is not really an error, since the return
1044 // value can also be zero when there is no scrollbar yet.
1045 // wxLogLastError(wxT("GetScrollInfo"));
1047 maxPos
= scrollInfo
.nMax
;
1049 // undo "range - 1" done in SetScrollbar()
1053 int wxWindowMSW::GetScrollThumb(int orient
) const
1055 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
1058 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
1060 HWND hWnd
= GetHwnd();
1061 wxCHECK_RET( hWnd
, wxT("SetScrollPos: no HWND") );
1063 WinStruct
<SCROLLINFO
> info
;
1067 info
.fMask
= SIF_POS
;
1068 if ( HasFlag(wxALWAYS_SHOW_SB
) )
1070 // disable scrollbar instead of removing it then
1071 info
.fMask
|= SIF_DISABLENOSCROLL
;
1074 ::SetScrollInfo(hWnd
, WXOrientToSB(orient
), &info
, refresh
);
1077 // New function that will replace some of the above.
1078 void wxWindowMSW::SetScrollbar(int orient
,
1084 // We have to set the variables here to make them valid in events
1085 // triggered by ::SetScrollInfo()
1086 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
1088 HWND hwnd
= GetHwnd();
1092 WinStruct
<SCROLLINFO
> info
;
1095 info
.nPage
= pageSize
;
1096 info
.nMin
= 0; // range is nMax - nMin + 1
1097 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
1100 // We normally also reenable scrollbar in case it had been previously
1101 // disabled by specifying SIF_DISABLENOSCROLL below but we should only
1102 // do this if it has valid range, otherwise it would be enabled but not
1104 if ( range
>= pageSize
)
1106 ::EnableScrollBar(hwnd
, WXOrientToSB(orient
), ESB_ENABLE_BOTH
);
1109 //else: leave all the fields to be 0
1111 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
1112 if ( HasFlag(wxALWAYS_SHOW_SB
) || range
== -1 )
1114 // disable scrollbar instead of removing it then
1115 info
.fMask
|= SIF_DISABLENOSCROLL
;
1118 ::SetScrollInfo(hwnd
, WXOrientToSB(orient
), &info
, refresh
);
1121 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
1127 wxCopyRectToRECT(*prect
, rect
);
1137 // FIXME: is this the exact equivalent of the line below?
1138 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
1140 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
1144 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
1146 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
1149 for ( int n
= 0; n
< count
; n
++ )
1151 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
1153 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
1154 if ( posNew
== pos
)
1156 // don't bother to continue, we're already at top/bottom
1163 return pos
!= posStart
;
1166 bool wxWindowMSW::ScrollLines(int lines
)
1168 bool down
= lines
> 0;
1170 return ScrollVertically(GetHwnd(),
1171 down
? SB_LINEDOWN
: SB_LINEUP
,
1172 down
? lines
: -lines
);
1175 bool wxWindowMSW::ScrollPages(int pages
)
1177 bool down
= pages
> 0;
1179 return ScrollVertically(GetHwnd(),
1180 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1181 down
? pages
: -pages
);
1184 // ----------------------------------------------------------------------------
1186 // ----------------------------------------------------------------------------
1188 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
1193 wxCHECK_RET( GetHwnd(),
1194 wxT("layout direction must be set after window creation") );
1196 LONG styleOld
= wxGetWindowExStyle(this);
1198 LONG styleNew
= styleOld
;
1201 case wxLayout_LeftToRight
:
1202 styleNew
&= ~WS_EX_LAYOUTRTL
;
1205 case wxLayout_RightToLeft
:
1206 styleNew
|= WS_EX_LAYOUTRTL
;
1210 wxFAIL_MSG(wxT("unsupported layout direction"));
1214 if ( styleNew
!= styleOld
)
1216 wxSetWindowExStyle(this, styleNew
);
1221 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1224 return wxLayout_Default
;
1226 wxCHECK_MSG( GetHwnd(), wxLayout_Default
, wxT("invalid window") );
1228 return wxHasWindowExStyle(this, WS_EX_LAYOUTRTL
) ? wxLayout_RightToLeft
1229 : wxLayout_LeftToRight
;
1234 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1235 wxCoord
WXUNUSED(width
),
1236 wxCoord
WXUNUSED(widthTotal
)) const
1238 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1239 // redo it ourselves
1243 // ---------------------------------------------------------------------------
1245 // ---------------------------------------------------------------------------
1247 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1249 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1251 HWND hwnd
= (HWND
)hWnd
;
1252 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1256 wxAssociateWinWithHandle(hwnd
, this);
1258 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1260 // we don't need to subclass the window of our own class (in the Windows
1261 // sense of the word)
1262 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1264 wxSetWindowProc(hwnd
, wxWndProc
);
1268 // don't bother restoring it either: this also makes it easy to
1269 // implement IsOfStandardClass() method which returns true for the
1270 // standard controls and false for the wxWidgets own windows as it can
1271 // simply check m_oldWndProc
1272 m_oldWndProc
= NULL
;
1275 // we're officially created now, send the event
1276 wxWindowCreateEvent
event((wxWindow
*)this);
1277 (void)HandleWindowEvent(event
);
1280 void wxWindowMSW::UnsubclassWin()
1282 wxRemoveHandleAssociation(this);
1284 // Restore old Window proc
1285 HWND hwnd
= GetHwnd();
1290 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1294 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1296 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1299 m_oldWndProc
= NULL
;
1304 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1308 if ( !::DestroyWindow(GetHwnd()) )
1310 wxLogLastError(wxT("DestroyWindow"));
1314 WXHWND wxhwnd
= (WXHWND
)handle
;
1316 // this also calls SetHWND(wxhwnd)
1317 SubclassWin(wxhwnd
);
1320 void wxWindowMSW::DissociateHandle()
1322 // this also calls SetHWND(0) for us
1327 bool wxCheckWindowWndProc(WXHWND hWnd
,
1328 WXFARPROC
WXUNUSED(wndProc
))
1330 const wxString
str(wxGetWindowClass(hWnd
));
1332 // TODO: get rid of wxTLWHiddenParent special case (currently it's not
1333 // registered by wxApp but using ad hoc code in msw/toplevel.cpp);
1334 // there is also a hidden window class used by sockets &c
1335 return wxApp::IsRegisteredClassName(str
) || str
== wxT("wxTLWHiddenParent");
1338 // ----------------------------------------------------------------------------
1340 // ----------------------------------------------------------------------------
1342 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1344 long flagsOld
= GetWindowStyleFlag();
1345 if ( flags
== flagsOld
)
1348 // update the internal variable
1349 wxWindowBase::SetWindowStyleFlag(flags
);
1351 // and the real window flags
1352 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1355 void wxWindowMSW::SetExtraStyle(long exflags
)
1357 long exflagsOld
= GetExtraStyle();
1358 if ( exflags
== exflagsOld
)
1361 // update the internal variable
1362 wxWindowBase::SetExtraStyle(exflags
);
1364 // and the real window flags
1365 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1368 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1370 // now update the Windows style as well if needed - and if the window had
1371 // been already created
1375 // we may need to call SetWindowPos() when we change some styles
1376 bool callSWP
= false;
1379 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1381 // this is quite a horrible hack but we need it because MSWGetStyle()
1382 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1383 // and so we have to modify the window exflags temporarily to get the
1384 // correct exstyleOld
1385 long exflagsNew
= GetExtraStyle();
1386 wxWindowBase::SetExtraStyle(exflagsOld
);
1389 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1391 wxWindowBase::SetExtraStyle(exflagsNew
);
1394 if ( style
!= styleOld
)
1396 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1397 // this function so instead of simply setting the style to the new
1398 // value we clear the bits which were set in styleOld but are set in
1399 // the new one and set the ones which were not set before
1400 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1401 styleReal
&= ~styleOld
;
1404 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1406 // we need to call SetWindowPos() if any of the styles affecting the
1407 // frame appearance have changed
1408 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1417 // and the extended style
1418 long exstyleReal
= wxGetWindowExStyle(this);
1420 if ( exstyle
!= exstyleOld
)
1422 exstyleReal
&= ~exstyleOld
;
1423 exstyleReal
|= exstyle
;
1425 wxSetWindowExStyle(this, exstyleReal
);
1427 // ex style changes don't take effect without calling SetWindowPos
1433 // we must call SetWindowPos() to flush the cached extended style and
1434 // also to make the change to wxSTAY_ON_TOP style take effect: just
1435 // setting the style simply doesn't work
1436 if ( !::SetWindowPos(GetHwnd(),
1437 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1440 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1443 wxLogLastError(wxT("SetWindowPos"));
1448 wxBorder
wxWindowMSW::GetDefaultBorderForControl() const
1450 return wxBORDER_THEME
;
1453 wxBorder
wxWindowMSW::GetDefaultBorder() const
1455 return wxWindowBase::GetDefaultBorder();
1458 // Translate wxBORDER_THEME (and other border styles if necessary) to the value
1459 // that makes most sense for this Windows environment
1460 wxBorder
wxWindowMSW::TranslateBorder(wxBorder border
) const
1462 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
1463 if (border
== wxBORDER_THEME
|| border
== wxBORDER_SUNKEN
|| border
== wxBORDER_SIMPLE
)
1464 return wxBORDER_SIMPLE
;
1466 return wxBORDER_NONE
;
1469 if (border
== wxBORDER_THEME
)
1471 if (CanApplyThemeBorder())
1473 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
1475 return wxBORDER_THEME
;
1477 return wxBORDER_SUNKEN
;
1485 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1487 // translate common wxWidgets styles to Windows ones
1489 // most of windows are child ones, those which are not (such as
1490 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1491 WXDWORD style
= WS_CHILD
;
1493 // using this flag results in very significant reduction in flicker,
1494 // especially with controls inside the static boxes (as the interior of the
1495 // box is not redrawn twice), but sometimes results in redraw problems, so
1496 // optionally allow the old code to continue to use it provided a special
1497 // system option is turned on
1498 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1499 || (flags
& wxCLIP_CHILDREN
) )
1500 style
|= WS_CLIPCHILDREN
;
1502 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1503 // don't support overlapping windows and it only makes sense for them and,
1504 // presumably, gives the system some extra work (to manage more clipping
1505 // regions), so avoid it alltogether
1508 if ( flags
& wxVSCROLL
)
1509 style
|= WS_VSCROLL
;
1511 if ( flags
& wxHSCROLL
)
1512 style
|= WS_HSCROLL
;
1514 const wxBorder border
= TranslateBorder(GetBorder(flags
));
1516 // After translation, border is now optimized for the specific version of Windows
1517 // and theme engine presence.
1519 // WS_BORDER is only required for wxBORDER_SIMPLE
1520 if ( border
== wxBORDER_SIMPLE
)
1523 // now deal with ext style if the caller wants it
1529 if ( flags
& wxTRANSPARENT_WINDOW
)
1530 *exstyle
|= WS_EX_TRANSPARENT
;
1536 case wxBORDER_DEFAULT
:
1537 wxFAIL_MSG( wxT("unknown border style") );
1541 case wxBORDER_SIMPLE
:
1542 case wxBORDER_THEME
:
1545 case wxBORDER_STATIC
:
1546 *exstyle
|= WS_EX_STATICEDGE
;
1549 case wxBORDER_RAISED
:
1550 *exstyle
|= WS_EX_DLGMODALFRAME
;
1553 case wxBORDER_SUNKEN
:
1554 *exstyle
|= WS_EX_CLIENTEDGE
;
1555 style
&= ~WS_BORDER
;
1558 // case wxBORDER_DOUBLE:
1559 // *exstyle |= WS_EX_DLGMODALFRAME;
1563 // wxUniv doesn't use Windows dialog navigation functions at all
1564 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1565 // to make the dialog navigation work with the nested panels we must
1566 // use this style (top level windows such as dialogs don't need it)
1567 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1569 *exstyle
|= WS_EX_CONTROLPARENT
;
1571 #endif // __WXUNIVERSAL__
1577 // Setup background and foreground colours correctly
1578 void wxWindowMSW::SetupColours()
1581 SetBackgroundColour(GetParent()->GetBackgroundColour());
1584 bool wxWindowMSW::IsMouseInWindow() const
1586 // get the mouse position
1589 ::GetCursorPosWinCE(&pt
);
1591 ::GetCursorPos(&pt
);
1594 // find the window which currently has the cursor and go up the window
1595 // chain until we find this window - or exhaust it
1596 HWND hwnd
= ::WindowFromPoint(pt
);
1597 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1598 hwnd
= ::GetParent(hwnd
);
1600 return hwnd
!= NULL
;
1603 void wxWindowMSW::OnInternalIdle()
1605 #ifndef HAVE_TRACKMOUSEEVENT
1606 // Check if we need to send a LEAVE event
1607 if ( m_mouseInWindow
)
1609 // note that we should generate the leave event whether the window has
1610 // or doesn't have mouse capture
1611 if ( !IsMouseInWindow() )
1613 GenerateMouseLeave();
1616 #endif // !HAVE_TRACKMOUSEEVENT
1618 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1619 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1622 // Set this window to be the child of 'parent'.
1623 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1625 if ( !wxWindowBase::Reparent(parent
) )
1628 HWND hWndChild
= GetHwnd();
1629 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1631 ::SetParent(hWndChild
, hWndParent
);
1634 if ( wxHasWindowExStyle(this, WS_EX_CONTROLPARENT
) )
1636 EnsureParentHasControlParentStyle(GetParent());
1638 #endif // !__WXWINCE__
1643 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1645 #ifndef __WXMICROWIN__
1646 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1650 void wxWindowMSW::DoFreeze()
1653 return; // no point in freezing hidden window
1655 SendSetRedraw(GetHwnd(), false);
1658 void wxWindowMSW::DoThaw()
1661 return; // hidden windows aren't frozen by DoFreeze
1663 SendSetRedraw(GetHwnd(), true);
1665 // we need to refresh everything or otherwise the invalidated area
1666 // is not going to be repainted
1670 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1672 HWND hWnd
= GetHwnd();
1679 wxCopyRectToRECT(*rect
, mswRect
);
1687 // RedrawWindow not available on SmartPhone or eVC++ 3
1688 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1689 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1693 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1695 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1700 void wxWindowMSW::Update()
1702 if ( !::UpdateWindow(GetHwnd()) )
1704 wxLogLastError(wxT("UpdateWindow"));
1707 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1708 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1709 // handler needs to be really drawn right now
1714 // ---------------------------------------------------------------------------
1716 // ---------------------------------------------------------------------------
1718 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1722 // we need to lower the sibling static boxes so controls contained within can be
1724 static void AdjustStaticBoxZOrder(wxWindow
*parent
)
1726 // no sibling static boxes if we have no parent (ie TLW)
1730 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1732 node
= node
->GetNext() )
1734 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1737 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1738 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1743 #else // !wxUSE_STATBOX
1745 static inline void AdjustStaticBoxZOrder(wxWindow
* WXUNUSED(parent
))
1749 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1751 #endif // drag and drop is used
1753 #if wxUSE_DRAG_AND_DROP
1754 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1756 if ( m_dropTarget
!= 0 ) {
1757 m_dropTarget
->Revoke(m_hWnd
);
1758 delete m_dropTarget
;
1761 m_dropTarget
= pDropTarget
;
1762 if ( m_dropTarget
!= 0 )
1764 AdjustStaticBoxZOrder(GetParent());
1765 m_dropTarget
->Register(m_hWnd
);
1768 #endif // wxUSE_DRAG_AND_DROP
1770 // old-style file manager drag&drop support: we retain the old-style
1771 // DragAcceptFiles in parallel with SetDropTarget.
1772 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1775 HWND hWnd
= GetHwnd();
1778 AdjustStaticBoxZOrder(GetParent());
1779 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1784 // ----------------------------------------------------------------------------
1786 // ----------------------------------------------------------------------------
1790 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1792 wxWindowBase::DoSetToolTip(tooltip
);
1795 m_tooltip
->SetWindow((wxWindow
*)this);
1798 #endif // wxUSE_TOOLTIPS
1800 // ---------------------------------------------------------------------------
1801 // moving and resizing
1802 // ---------------------------------------------------------------------------
1804 bool wxWindowMSW::IsSizeDeferred() const
1806 #if wxUSE_DEFERRED_SIZING
1807 if ( m_pendingPosition
!= wxDefaultPosition
||
1808 m_pendingSize
!= wxDefaultSize
)
1810 #endif // wxUSE_DEFERRED_SIZING
1816 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1818 #if wxUSE_DEFERRED_SIZING
1819 // if SetSize() had been called at wx level but not realized at Windows
1820 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1821 // the new and not the old position to the other wx code
1822 if ( m_pendingSize
!= wxDefaultSize
)
1825 *x
= m_pendingSize
.x
;
1827 *y
= m_pendingSize
.y
;
1829 else // use current size
1830 #endif // wxUSE_DEFERRED_SIZING
1832 RECT rect
= wxGetWindowRect(GetHwnd());
1835 *x
= rect
.right
- rect
.left
;
1837 *y
= rect
.bottom
- rect
.top
;
1841 // Get size *available for subwindows* i.e. excluding menu bar etc.
1842 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1844 #if wxUSE_DEFERRED_SIZING
1845 if ( m_pendingSize
!= wxDefaultSize
)
1847 // we need to calculate the client size corresponding to pending size
1849 // FIXME: Unfortunately this doesn't work correctly for the maximized
1850 // top level windows, the returned values are too small (e.g.
1851 // under Windows 7 on a 1600*1200 screen with task bar on the
1852 // right the pending size for a maximized window is 1538*1200
1853 // and WM_NCCALCSIZE returns 1528*1172 even though the correct
1854 // client size of such window is 1538*1182). No idea how to fix
1855 // it though, setting WS_MAXIMIZE in GWL_STYLE before calling
1856 // WM_NCCALCSIZE doesn't help and AdjustWindowRectEx() doesn't
1857 // work in this direction neither. So we just have to live with
1858 // the slightly wrong results and relayout the window when it
1859 // gets finally shown in its maximized state (see #11762).
1861 rect
.left
= m_pendingPosition
.x
;
1862 rect
.top
= m_pendingPosition
.y
;
1863 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1864 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1866 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1869 *x
= rect
.right
- rect
.left
;
1871 *y
= rect
.bottom
- rect
.top
;
1874 #endif // wxUSE_DEFERRED_SIZING
1876 RECT rect
= wxGetClientRect(GetHwnd());
1885 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1887 wxWindow
* const parent
= GetParent();
1890 #if wxUSE_DEFERRED_SIZING
1891 if ( m_pendingPosition
!= wxDefaultPosition
)
1893 pos
= m_pendingPosition
;
1895 else // use current position
1896 #endif // wxUSE_DEFERRED_SIZING
1898 RECT rect
= wxGetWindowRect(GetHwnd());
1901 point
.x
= rect
.left
;
1904 // we do the adjustments with respect to the parent only for the "real"
1905 // children, not for the dialogs/frames
1906 if ( !IsTopLevel() )
1908 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
1910 // In RTL mode, we want the logical left x-coordinate,
1911 // which would be the physical right x-coordinate.
1912 point
.x
= rect
.right
;
1915 // Since we now have the absolute screen coords, if there's a
1916 // parent we must subtract its top left corner
1919 ::ScreenToClient(GetHwndOf(parent
), &point
);
1927 // we also must adjust by the client area offset: a control which is just
1928 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1929 if ( parent
&& !IsTopLevel() )
1931 const wxPoint
pt(parent
->GetClientAreaOrigin());
1942 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1950 ::ScreenToClient(GetHwnd(), &pt
);
1958 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1966 ::ClientToScreen(GetHwnd(), &pt
);
1975 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1977 #if wxUSE_DEFERRED_SIZING
1978 // if our parent had prepared a defer window handle for us, use it (unless
1979 // we are a top level window)
1980 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1982 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1985 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1986 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1989 wxLogLastError(wxT("DeferWindowPos"));
1995 // hdwp must be updated as it may have been changed
1996 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
2001 // did deferred move, remember new coordinates of the window as they're
2002 // different from what Windows would return for it
2006 // otherwise (or if deferring failed) move the window in place immediately
2007 #endif // wxUSE_DEFERRED_SIZING
2008 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
2010 wxLogLastError(wxT("MoveWindow"));
2013 // if wxUSE_DEFERRED_SIZING, indicates that we didn't use deferred move,
2014 // ignored otherwise
2018 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
2020 // TODO: is this consistent with other platforms?
2021 // Still, negative width or height shouldn't be allowed
2027 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
2029 #if wxUSE_DEFERRED_SIZING
2030 m_pendingPosition
= wxPoint(x
, y
);
2031 m_pendingSize
= wxSize(width
, height
);
2033 else // window was moved immediately, without deferring it
2035 m_pendingPosition
= wxDefaultPosition
;
2036 m_pendingSize
= wxDefaultSize
;
2037 #endif // wxUSE_DEFERRED_SIZING
2041 // set the size of the window: if the dimensions are positive, just use them,
2042 // but if any of them is equal to -1, it means that we must find the value for
2043 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
2044 // which case -1 is a valid value for x and y)
2046 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
2047 // the width/height to best suit our contents, otherwise we reuse the current
2049 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
2051 // get the current size and position...
2052 int currentX
, currentY
;
2053 int currentW
, currentH
;
2055 GetPosition(¤tX
, ¤tY
);
2056 GetSize(¤tW
, ¤tH
);
2058 // ... and don't do anything (avoiding flicker) if it's already ok unless
2059 // we're forced to resize the window
2060 if ( x
== currentX
&& y
== currentY
&&
2061 width
== currentW
&& height
== currentH
&&
2062 !(sizeFlags
& wxSIZE_FORCE
) )
2064 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
2066 wxSizeEvent
event( wxSize(width
,height
), GetId() );
2067 event
.SetEventObject( this );
2068 HandleWindowEvent( event
);
2073 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2075 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2078 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2080 wxSize size
= wxDefaultSize
;
2081 if ( width
== wxDefaultCoord
)
2083 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2085 size
= GetBestSize();
2090 // just take the current one
2095 if ( height
== wxDefaultCoord
)
2097 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2099 if ( size
.x
== wxDefaultCoord
)
2101 size
= GetBestSize();
2103 //else: already called GetBestSize() above
2109 // just take the current one
2114 DoMoveWindow(x
, y
, width
, height
);
2117 void wxWindowMSW::DoSetClientSize(int width
, int height
)
2119 // setting the client size is less obvious than it could have been
2120 // because in the result of changing the total size the window scrollbar
2121 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
2122 // doesn't take neither into account) and so the client size will not be
2123 // correct as the difference between the total and client size changes --
2124 // so we keep changing it until we get it right
2126 // normally this loop shouldn't take more than 3 iterations (usually 1 but
2127 // if scrollbars [dis]appear as the result of the first call, then 2 and it
2128 // may become 3 if the window had 0 size originally and so we didn't
2129 // calculate the scrollbar correction correctly during the first iteration)
2130 // but just to be on the safe side we check for it instead of making it an
2131 // "infinite" loop (i.e. leaving break inside as the only way to get out)
2132 for ( int i
= 0; i
< 4; i
++ )
2135 ::GetClientRect(GetHwnd(), &rectClient
);
2137 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
2138 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
2139 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
2144 // Find the difference between the entire window (title bar and all)
2145 // and the client area; add this to the new client size to move the
2148 ::GetWindowRect(GetHwnd(), &rectWin
);
2150 const int widthWin
= rectWin
.right
- rectWin
.left
,
2151 heightWin
= rectWin
.bottom
- rectWin
.top
;
2153 // MoveWindow positions the child windows relative to the parent, so
2154 // adjust if necessary
2155 if ( !IsTopLevel() )
2157 wxWindow
*parent
= GetParent();
2160 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
2164 // don't call DoMoveWindow() because we want to move window immediately
2165 // and not defer it here as otherwise the value returned by
2166 // GetClient/WindowRect() wouldn't change as the window wouldn't be
2168 if ( !::MoveWindow(GetHwnd(),
2171 width
+ widthWin
- rectClient
.right
,
2172 height
+ heightWin
- rectClient
.bottom
,
2175 wxLogLastError(wxT("MoveWindow"));
2180 wxSize
wxWindowMSW::DoGetBorderSize() const
2183 switch ( GetBorder() )
2185 case wxBORDER_STATIC
:
2186 case wxBORDER_SIMPLE
:
2190 case wxBORDER_SUNKEN
:
2194 case wxBORDER_RAISED
:
2195 case wxBORDER_DOUBLE
:
2200 wxFAIL_MSG( wxT("unknown border style") );
2207 return 2*wxSize(border
, border
);
2210 // ---------------------------------------------------------------------------
2212 // ---------------------------------------------------------------------------
2214 int wxWindowMSW::GetCharHeight() const
2216 return wxGetTextMetrics(this).tmHeight
;
2219 int wxWindowMSW::GetCharWidth() const
2221 // +1 is needed because Windows apparently adds it when calculating the
2222 // dialog units size in pixels
2223 #if wxDIALOG_UNIT_COMPATIBILITY
2224 return wxGetTextMetrics(this).tmAveCharWidth
;
2226 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
2230 void wxWindowMSW::DoGetTextExtent(const wxString
& string
,
2233 int *externalLeading
,
2234 const wxFont
*fontToUse
) const
2236 wxASSERT_MSG( !fontToUse
|| fontToUse
->Ok(),
2237 wxT("invalid font in GetTextExtent()") );
2241 hfontToUse
= GetHfontOf(*fontToUse
);
2243 hfontToUse
= GetHfontOf(GetFont());
2245 WindowHDC
hdc(GetHwnd());
2246 SelectInHDC
selectFont(hdc
, hfontToUse
);
2250 ::GetTextExtentPoint32(hdc
, string
.wx_str(), string
.length(), &sizeRect
);
2251 GetTextMetrics(hdc
, &tm
);
2258 *descent
= tm
.tmDescent
;
2259 if ( externalLeading
)
2260 *externalLeading
= tm
.tmExternalLeading
;
2263 // ---------------------------------------------------------------------------
2265 // ---------------------------------------------------------------------------
2267 #if wxUSE_MENUS_NATIVE
2269 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2270 // immediately, without waiting for the next event loop iteration
2272 // NB: this function should probably be made public later as it can almost
2273 // surely replace wxYield() elsewhere as well
2274 static void wxYieldForCommandsOnly()
2276 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2277 // want to process it here)
2279 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2281 if ( msg
.message
== WM_QUIT
)
2283 // if we retrieved a WM_QUIT, insert back into the message queue.
2284 ::PostQuitMessage(0);
2288 // luckily (as we don't have access to wxEventLoopImpl method from here
2289 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2291 ::TranslateMessage(&msg
);
2292 ::DispatchMessage(&msg
);
2296 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2300 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2302 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2303 x
= mouse
.x
; y
= mouse
.y
;
2306 HWND hWnd
= GetHwnd();
2307 HMENU hMenu
= GetHmenuOf(menu
);
2311 ::ClientToScreen(hWnd
, &point
);
2312 #if defined(__WXWINCE__)
2313 static const UINT flags
= 0;
2314 #else // !__WXWINCE__
2315 UINT flags
= TPM_RIGHTBUTTON
;
2316 // NT4 doesn't support TPM_RECURSE and simply doesn't show the menu at all
2317 // when it's use, I'm not sure about Win95/98 but prefer to err on the safe
2318 // side and not to use it there neither -- modify the test if it does work
2320 if ( wxGetWinVersion() >= wxWinVersion_5
)
2322 // using TPM_RECURSE allows us to show a popup menu while another menu
2323 // is opened which can be useful and is supported by the other
2324 // platforms, so allow it under Windows too
2325 flags
|= TPM_RECURSE
;
2327 #endif // __WXWINCE__/!__WXWINCE__
2329 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2331 // we need to do it right now as otherwise the events are never going to be
2332 // sent to wxCurrentPopupMenu from HandleCommand()
2334 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2335 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2336 // destroyed as soon as we return (it can be a local variable in the caller
2337 // for example) and so we do need to process the event immediately
2338 wxYieldForCommandsOnly();
2343 #endif // wxUSE_MENUS_NATIVE
2345 // ===========================================================================
2346 // pre/post message processing
2347 // ===========================================================================
2349 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2352 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2354 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2357 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2359 // wxUniversal implements tab traversal itself
2360 #ifndef __WXUNIVERSAL__
2361 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2363 // intercept dialog navigation keys
2364 MSG
*msg
= (MSG
*)pMsg
;
2366 // here we try to do all the job which ::IsDialogMessage() usually does
2368 if ( msg
->message
== WM_KEYDOWN
)
2370 bool bCtrlDown
= wxIsCtrlDown();
2371 bool bShiftDown
= wxIsShiftDown();
2373 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2374 // don't process it if it's the case (except for Ctrl-Tab/Enter
2375 // combinations which are always processed)
2376 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2378 // surprisingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2379 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2380 // it, of course, implies them
2381 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2383 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2386 bool bForward
= true,
2387 bWindowChange
= false,
2390 // should we process this message specially?
2391 bool bProcess
= true;
2392 switch ( msg
->wParam
)
2395 if ( (lDlgCode
& DLGC_WANTTAB
) && !bCtrlDown
)
2397 // let the control have the TAB
2400 else // use it for navigation
2402 // Ctrl-Tab cycles thru notebook pages
2403 bWindowChange
= bCtrlDown
;
2404 bForward
= !bShiftDown
;
2411 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2419 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2428 // we treat PageUp/Dn as arrows because chances are that
2429 // a control which needs arrows also needs them for
2430 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2431 if ( (lDlgCode
& DLGC_WANTARROWS
) && !bCtrlDown
)
2433 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
2434 bWindowChange
= true;
2440 // currently active button should get enter press even
2441 // if there is a default button elsewhere so check if
2442 // this window is a button first
2443 wxWindow
*btn
= NULL
;
2444 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2446 // let IsDialogMessage() handle this for all
2447 // buttons except the owner-drawn ones which it
2448 // just seems to ignore
2449 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2450 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2452 // emulate the button click
2453 btn
= wxFindWinFromHandle(msg
->hwnd
);
2458 else // not a button itself, do we have default button?
2460 // check if this window or any of its ancestors
2461 // wants the message for itself (we always reserve
2462 // Ctrl-Enter for dialog navigation though)
2463 wxWindow
*win
= this;
2466 // this will contain the dialog code of this
2467 // window and all of its parent windows in turn
2468 LONG lDlgCode2
= lDlgCode
;
2472 if ( lDlgCode2
& DLGC_WANTMESSAGE
)
2474 // as it wants to process Enter itself,
2475 // don't call IsDialogMessage() which
2480 // don't propagate keyboard messages beyond
2481 // the first top level window parent
2482 if ( win
->IsTopLevel() )
2485 win
= win
->GetParent();
2487 lDlgCode2
= ::SendMessage
2498 win
= wxGetTopLevelParent(win
);
2501 wxTopLevelWindow
* const
2502 tlw
= wxDynamicCast(win
, wxTopLevelWindow
);
2505 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2510 if ( btn
&& btn
->IsEnabled() )
2512 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2516 #endif // wxUSE_BUTTON
2519 // map Enter presses into button presses on PDAs
2520 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2521 event
.SetEventObject(this);
2522 if ( HandleWindowEvent(event
) )
2524 #endif // __WXWINCE__
2534 wxNavigationKeyEvent event
;
2535 event
.SetDirection(bForward
);
2536 event
.SetWindowChange(bWindowChange
);
2537 event
.SetFromTab(bFromTab
);
2538 event
.SetEventObject(this);
2540 if ( HandleWindowEvent(event
) )
2542 // as we don't call IsDialogMessage(), which would take of
2543 // this by default, we need to manually send this message
2544 // so that controls can change their UI state if needed
2545 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2552 if ( ::IsDialogMessage(GetHwnd(), msg
) )
2554 // IsDialogMessage() did something...
2558 #endif // __WXUNIVERSAL__
2563 // relay mouse move events to the tooltip control
2564 MSG
*msg
= (MSG
*)pMsg
;
2565 if ( msg
->message
== WM_MOUSEMOVE
)
2566 wxToolTip::RelayEvent(pMsg
);
2568 #endif // wxUSE_TOOLTIPS
2573 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2575 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2576 return m_acceleratorTable
.Translate(this, pMsg
);
2580 #endif // wxUSE_ACCEL
2583 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* msg
)
2585 // all tests below have to deal with various bugs/misfeatures of
2586 // IsDialogMessage(): we have to prevent it from being called from our
2587 // MSWProcessMessage() in some situations
2589 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2590 // message even when there is no cancel button and when the message is
2591 // needed by the control itself: in particular, it prevents the tree in
2592 // place edit control from being closed with Escape in a dialog
2593 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_ESCAPE
)
2598 // ::IsDialogMessage() is broken and may sometimes hang the application by
2599 // going into an infinite loop when it tries to find the control to give
2600 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2601 // situations when this may happen and not call it then
2602 if ( msg
->message
!= WM_SYSCHAR
)
2605 // assume we can call it by default
2606 bool canSafelyCallIsDlgMsg
= true;
2608 HWND hwndFocus
= ::GetFocus();
2610 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2611 // ::IsDialogMessage() will also enter an infinite loop, because it will
2612 // recursively check the child windows but not the window itself and so if
2613 // none of the children accepts focus it loops forever (as it only stops
2614 // when it gets back to the window it started from)
2616 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2617 // style has the focus, it can happen. One such possibility is if
2618 // all windows are either toplevel, wxDialog, wxPanel or static
2619 // controls and no window can actually accept keyboard input.
2620 #if !defined(__WXWINCE__)
2621 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2623 // pessimistic by default
2624 canSafelyCallIsDlgMsg
= false;
2625 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2627 node
= node
->GetNext() )
2629 wxWindow
* const win
= node
->GetData();
2630 if ( win
->CanAcceptFocus() &&
2631 !wxHasWindowExStyle(win
, WS_EX_CONTROLPARENT
) )
2633 // it shouldn't hang...
2634 canSafelyCallIsDlgMsg
= true;
2640 #endif // !__WXWINCE__
2642 if ( canSafelyCallIsDlgMsg
)
2644 // ::IsDialogMessage() can enter in an infinite loop when the
2645 // currently focused window is disabled or hidden and its
2646 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2650 if ( !::IsWindowEnabled(hwndFocus
) ||
2651 !::IsWindowVisible(hwndFocus
) )
2653 // it would enter an infinite loop if we do this!
2654 canSafelyCallIsDlgMsg
= false;
2659 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2661 // it's a top level window, don't go further -- e.g. even
2662 // if the parent of a dialog is disabled, this doesn't
2663 // break navigation inside the dialog
2667 hwndFocus
= ::GetParent(hwndFocus
);
2671 return canSafelyCallIsDlgMsg
;
2674 // ---------------------------------------------------------------------------
2675 // message params unpackers
2676 // ---------------------------------------------------------------------------
2678 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2679 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2681 *id
= LOWORD(wParam
);
2682 *hwnd
= (WXHWND
)lParam
;
2683 *cmd
= HIWORD(wParam
);
2686 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2687 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2689 *state
= LOWORD(wParam
);
2690 *minimized
= HIWORD(wParam
);
2691 *hwnd
= (WXHWND
)lParam
;
2694 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2695 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2697 *code
= LOWORD(wParam
);
2698 *pos
= HIWORD(wParam
);
2699 *hwnd
= (WXHWND
)lParam
;
2702 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2703 WXHDC
*hdc
, WXHWND
*hwnd
)
2705 *hwnd
= (WXHWND
)lParam
;
2706 *hdc
= (WXHDC
)wParam
;
2709 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2710 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2712 *item
= (WXWORD
)wParam
;
2713 *flags
= HIWORD(wParam
);
2714 *hmenu
= (WXHMENU
)lParam
;
2717 // ---------------------------------------------------------------------------
2718 // Main wxWidgets window proc and the window proc for wxWindow
2719 // ---------------------------------------------------------------------------
2721 // Hook for new window just as it's being created, when the window isn't yet
2722 // associated with the handle
2723 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2725 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2726 // window being created and insures that it's always unset back later
2727 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2729 gs_winBeingCreated
= winBeingCreated
;
2732 wxWindowCreationHook::~wxWindowCreationHook()
2734 gs_winBeingCreated
= NULL
;
2738 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2740 // trace all messages: useful for the debugging but noticeably slows down
2741 // the code so don't do it by default
2742 #if wxDEBUG_LEVEL >= 2
2743 // notice that we cast wParam and lParam to long to avoid mismatch with
2744 // format specifiers in 64 bit builds where they are both int64 quantities
2746 // casting like this loses information, of course, but it shouldn't matter
2747 // much for this diagnostic code and it keeps the code simple
2748 wxLogTrace("winmsg",
2749 wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"),
2750 wxGetMessageName(message
), hWnd
, (long)wParam
, (long)lParam
);
2751 #endif // wxDEBUG_LEVEL >= 2
2753 wxWindowMSW
*wnd
= wxFindWinFromHandle(hWnd
);
2755 // when we get the first message for the HWND we just created, we associate
2756 // it with wxWindow stored in gs_winBeingCreated
2757 if ( !wnd
&& gs_winBeingCreated
)
2759 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2760 wnd
= gs_winBeingCreated
;
2761 gs_winBeingCreated
= NULL
;
2762 wnd
->SetHWND((WXHWND
)hWnd
);
2767 if ( wnd
&& wxGUIEventLoop::AllowProcessing(wnd
) )
2768 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2770 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2775 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2777 // did we process the message?
2778 bool processed
= false;
2788 // for most messages we should return 0 when we do process the message
2796 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2799 // return 0 to allow window creation
2800 rc
.result
= mayCreate
? 0 : -1;
2806 // never set processed to true and *always* pass WM_DESTROY to
2807 // DefWindowProc() as Windows may do some internal cleanup when
2808 // processing it and failing to pass the message along may cause
2809 // memory and resource leaks!
2810 (void)HandleDestroy();
2814 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2818 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2821 #if !defined(__WXWINCE__)
2824 LPRECT pRect
= (LPRECT
)lParam
;
2826 rc
.SetLeft(pRect
->left
);
2827 rc
.SetTop(pRect
->top
);
2828 rc
.SetRight(pRect
->right
);
2829 rc
.SetBottom(pRect
->bottom
);
2830 processed
= HandleMoving(rc
);
2832 pRect
->left
= rc
.GetLeft();
2833 pRect
->top
= rc
.GetTop();
2834 pRect
->right
= rc
.GetRight();
2835 pRect
->bottom
= rc
.GetBottom();
2840 case WM_ENTERSIZEMOVE
:
2842 processed
= HandleEnterSizeMove();
2846 case WM_EXITSIZEMOVE
:
2848 processed
= HandleExitSizeMove();
2854 LPRECT pRect
= (LPRECT
)lParam
;
2856 rc
.SetLeft(pRect
->left
);
2857 rc
.SetTop(pRect
->top
);
2858 rc
.SetRight(pRect
->right
);
2859 rc
.SetBottom(pRect
->bottom
);
2860 processed
= HandleSizing(rc
);
2862 pRect
->left
= rc
.GetLeft();
2863 pRect
->top
= rc
.GetTop();
2864 pRect
->right
= rc
.GetRight();
2865 pRect
->bottom
= rc
.GetBottom();
2869 #endif // !__WXWINCE__
2871 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2872 case WM_ACTIVATEAPP
:
2873 // This implicitly sends a wxEVT_ACTIVATE_APP event
2874 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2880 WXWORD state
, minimized
;
2882 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2884 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2889 processed
= HandleSetFocus((WXHWND
)wParam
);
2893 processed
= HandleKillFocus((WXHWND
)wParam
);
2896 case WM_PRINTCLIENT
:
2897 processed
= HandlePrintClient((WXHDC
)wParam
);
2903 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2905 processed
= HandlePaint();
2909 processed
= HandlePaint();
2914 #ifdef __WXUNIVERSAL__
2915 // Universal uses its own wxFrame/wxDialog, so we don't receive
2916 // close events unless we have this.
2918 #endif // __WXUNIVERSAL__
2920 // don't let the DefWindowProc() destroy our window - we'll do it
2921 // ourselves in ~wxWindow
2927 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2931 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2932 GET_Y_LPARAM(lParam
),
2936 #ifdef HAVE_TRACKMOUSEEVENT
2938 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2940 if ( m_mouseInWindow
)
2942 GenerateMouseLeave();
2945 // always pass processed back as false, this allows the window
2946 // manager to process the message too. This is needed to
2947 // ensure windows XP themes work properly as the mouse moves
2948 // over widgets like buttons. So don't set processed to true here.
2950 #endif // HAVE_TRACKMOUSEEVENT
2952 #if wxUSE_MOUSEWHEEL
2954 processed
= HandleMouseWheel(wParam
, lParam
);
2958 case WM_LBUTTONDOWN
:
2960 case WM_LBUTTONDBLCLK
:
2961 case WM_RBUTTONDOWN
:
2963 case WM_RBUTTONDBLCLK
:
2964 case WM_MBUTTONDOWN
:
2966 case WM_MBUTTONDBLCLK
:
2967 #ifdef wxHAS_XBUTTON
2968 case WM_XBUTTONDOWN
:
2970 case WM_XBUTTONDBLCLK
:
2971 #endif // wxHAS_XBUTTON
2973 #ifdef __WXMICROWIN__
2974 // MicroWindows seems to ignore the fact that a window is
2975 // disabled. So catch mouse events and throw them away if
2977 wxWindowMSW
* win
= this;
2980 if (!win
->IsEnabled())
2986 win
= win
->GetParent();
2987 if ( !win
|| win
->IsTopLevel() )
2994 #endif // __WXMICROWIN__
2995 int x
= GET_X_LPARAM(lParam
),
2996 y
= GET_Y_LPARAM(lParam
);
2999 // redirect the event to a static control if necessary by
3000 // finding one under mouse because under CE the static controls
3001 // don't generate mouse events (even with SS_NOTIFY)
3003 if ( GetCapture() == this )
3005 // but don't do it if the mouse is captured by this window
3006 // because then it should really get this event itself
3011 win
= FindWindowForMouseEvent(this, &x
, &y
);
3013 // this should never happen
3014 wxCHECK_MSG( win
, 0,
3015 wxT("FindWindowForMouseEvent() returned NULL") );
3018 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
3020 SHRGINFO shrgi
= {0};
3022 shrgi
.cbSize
= sizeof(SHRGINFO
);
3023 shrgi
.hwndClient
= (HWND
) GetHWND();
3027 shrgi
.dwFlags
= SHRG_RETURNCMD
;
3028 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
3030 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
3033 pt
= ClientToScreen(pt
);
3035 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3037 evtCtx
.SetEventObject(this);
3038 if (HandleWindowEvent(evtCtx
))
3047 #else // !__WXWINCE__
3048 wxWindowMSW
*win
= this;
3049 #endif // __WXWINCE__/!__WXWINCE__
3051 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
3053 // if the app didn't eat the event, handle it in the default
3054 // way, that is by giving this window the focus
3057 // for the standard classes their WndProc sets the focus to
3058 // them anyhow and doing it from here results in some weird
3059 // problems, so don't do it for them (unnecessary anyhow)
3060 if ( !win
->IsOfStandardClass() )
3062 if ( message
== WM_LBUTTONDOWN
&& win
->IsFocusable() )
3074 case MM_JOY1BUTTONDOWN
:
3075 case MM_JOY2BUTTONDOWN
:
3076 case MM_JOY1BUTTONUP
:
3077 case MM_JOY2BUTTONUP
:
3078 processed
= HandleJoystickEvent(message
,
3079 GET_X_LPARAM(lParam
),
3080 GET_Y_LPARAM(lParam
),
3083 #endif // __WXMICROWIN__
3089 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
3091 processed
= HandleCommand(id
, cmd
, hwnd
);
3096 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
3099 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
3100 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
3101 // apparently doesn't always behave properly and needs some help
3102 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
3103 case WM_NOTIFYFORMAT
:
3104 if ( lParam
== NF_QUERY
)
3107 rc
.result
= NFR_UNICODE
;
3110 #endif // wxUSE_UNICODE_MSLU
3112 // for these messages we must return true if process the message
3115 processed
= MSWOnDrawItem(wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
3120 case WM_MEASUREITEM
:
3121 processed
= MSWOnMeasureItem(wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
3125 #endif // defined(WM_DRAWITEM)
3128 if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS
) )
3130 // we always want to get the char events
3131 rc
.result
= DLGC_WANTCHARS
;
3133 if ( HasFlag(wxWANTS_CHARS
) )
3135 // in fact, we want everything
3136 rc
.result
|= DLGC_WANTARROWS
|
3143 //else: get the dlg code from the DefWindowProc()
3148 // Generate the key down event in any case.
3149 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
3150 if ( m_lastKeydownProcessed
)
3152 // If it was processed by an event handler, we stop here,
3153 // notably we intentionally don't generate char event then.
3156 else // key down event not handled
3158 // Examine the event to decide whether we need to generate a
3159 // char event for it ourselves or let Windows do it. Window
3160 // mostly only does it for the keys which produce printable
3161 // characters (although there are exceptions, e.g. VK_ESCAPE or
3162 // VK_BACK (but not VK_DELETE)) while we do it for all keys
3163 // except the modifier ones (the wisdom of this is debatable
3164 // but by now this decision is enshrined forever due to
3165 // backwards compatibility).
3168 // No wxEVT_CHAR events are generated for these keys at all.
3176 // Windows will send us WM_CHAR for these ones so we'll
3177 // generate wxEVT_CHAR for them later when we get it.
3212 // special case of VK_APPS: treat it the same as right mouse
3213 // click because both usually pop up a context menu
3215 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
3220 if ( (wParam
>= '0' && wParam
<= '9') ||
3221 (wParam
>= 'A' && wParam
<= 'Z') )
3223 // We'll get WM_CHAR for those later too.
3227 // But for the rest we won't get WM_CHAR later so we do
3228 // need to generate the event right now.
3229 wxKeyEvent
event(wxEVT_CHAR
);
3230 InitAnyKeyEvent(event
, wParam
, lParam
);
3232 // Set the "extended" bit in lParam because we want to
3233 // generate CHAR events with WXK_HOME and not
3234 // WXK_NUMPAD_HOME even if the "Home" key on numpad was
3236 event
.m_keyCode
= wxMSWKeyboard::VKToWX
3239 lParam
| (KF_EXTENDED
<< 16)
3242 // Don't produce events without any valid character
3243 // code (even if this shouldn't normally happen...).
3244 if ( event
.m_keyCode
!= WXK_NONE
)
3245 processed
= HandleWindowEvent(event
);
3248 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
3255 // special case of VK_APPS: treat it the same as right mouse button
3256 if ( wParam
== VK_APPS
)
3258 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
3263 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
3268 case WM_CHAR
: // Always an ASCII character
3269 if ( m_lastKeydownProcessed
)
3271 // The key was handled in the EVT_KEY_DOWN and handling
3272 // a key in an EVT_KEY_DOWN handler is meant, by
3273 // design, to prevent EVT_CHARs from happening
3274 m_lastKeydownProcessed
= false;
3279 processed
= HandleChar((WORD
)wParam
, lParam
);
3285 processed
= HandleHotKey((WORD
)wParam
, lParam
);
3287 #endif // wxUSE_HOTKEY
3292 processed
= HandleClipboardEvent(message
);
3300 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
3302 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
3308 // CTLCOLOR messages are sent by children to query the parent for their
3310 #ifndef __WXMICROWIN__
3311 case WM_CTLCOLORMSGBOX
:
3312 case WM_CTLCOLOREDIT
:
3313 case WM_CTLCOLORLISTBOX
:
3314 case WM_CTLCOLORBTN
:
3315 case WM_CTLCOLORDLG
:
3316 case WM_CTLCOLORSCROLLBAR
:
3317 case WM_CTLCOLORSTATIC
:
3321 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
3323 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
3326 #endif // !__WXMICROWIN__
3328 case WM_SYSCOLORCHANGE
:
3329 // the return value for this message is ignored
3330 processed
= HandleSysColorChange();
3333 #if !defined(__WXWINCE__)
3334 case WM_DISPLAYCHANGE
:
3335 processed
= HandleDisplayChange();
3339 case WM_PALETTECHANGED
:
3340 processed
= HandlePaletteChanged((WXHWND
)wParam
);
3343 case WM_CAPTURECHANGED
:
3344 processed
= HandleCaptureChanged((WXHWND
)lParam
);
3347 case WM_SETTINGCHANGE
:
3348 processed
= HandleSettingChange(wParam
, lParam
);
3351 case WM_QUERYNEWPALETTE
:
3352 processed
= HandleQueryNewPalette();
3357 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
3358 // check if an override was configured for this window
3359 EraseBgHooks::const_iterator it
= gs_eraseBgHooks
.find(this);
3360 if ( it
!= gs_eraseBgHooks
.end() )
3361 processed
= it
->second
->MSWEraseBgHook((WXHDC
)wParam
);
3363 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
3364 processed
= HandleEraseBkgnd((WXHDC
)wParam
);
3369 // we processed the message, i.e. erased the background
3374 #if !defined(__WXWINCE__)
3376 processed
= HandleDropFiles(wParam
);
3381 processed
= HandleInitDialog((WXHWND
)wParam
);
3385 // we never set focus from here
3390 #if !defined(__WXWINCE__)
3391 case WM_QUERYENDSESSION
:
3392 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3396 processed
= HandleEndSession(wParam
!= 0, lParam
);
3399 case WM_GETMINMAXINFO
:
3400 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3405 processed
= HandleSetCursor((WXHWND
)wParam
,
3406 LOWORD(lParam
), // hit test
3407 HIWORD(lParam
)); // mouse msg
3411 // returning TRUE stops the DefWindowProc() from further
3412 // processing this message - exactly what we need because we've
3413 // just set the cursor.
3418 #if wxUSE_ACCESSIBILITY
3421 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3422 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3424 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3426 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3432 #if defined(WM_HELP)
3435 // by default, WM_HELP is propagated by DefWindowProc() upwards
3436 // to the window parent but as we do it ourselves already
3437 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3438 // to get the other events if we process this message at all
3441 // WM_HELP doesn't use lParam under CE
3443 HELPINFO
* info
= (HELPINFO
*) lParam
;
3444 if ( info
->iContextType
== HELPINFO_WINDOW
)
3446 #endif // !__WXWINCE__
3447 wxHelpEvent helpEvent
3452 wxGetMousePosition() // what else?
3454 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3458 helpEvent
.SetEventObject(this);
3459 HandleWindowEvent(helpEvent
);
3462 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3464 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3465 helpEvent
.SetEventObject(this);
3466 HandleWindowEvent(helpEvent
);
3469 else // unknown help event?
3473 #endif // !__WXWINCE__
3478 #if !defined(__WXWINCE__)
3479 case WM_CONTEXTMENU
:
3481 // we don't convert from screen to client coordinates as
3482 // the event may be handled by a parent window
3483 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3485 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3487 // we could have got an event from our child, reflect it back
3488 // to it if this is the case
3489 wxWindowMSW
*win
= NULL
;
3490 WXHWND hWnd
= (WXHWND
)wParam
;
3491 if ( hWnd
!= m_hWnd
)
3493 win
= FindItemByHWND(hWnd
);
3499 evtCtx
.SetEventObject(win
);
3500 processed
= win
->HandleWindowEvent(evtCtx
);
3507 // we're only interested in our own menus, not MF_SYSMENU
3508 if ( HIWORD(wParam
) == MF_POPUP
)
3510 // handle menu chars for ownerdrawn menu items
3511 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3512 if ( i
!= wxNOT_FOUND
)
3514 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3519 #endif // wxUSE_MENUS
3522 case WM_POWERBROADCAST
:
3525 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3526 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3529 #endif // __WXWINCE__
3532 // If we want the default themed border then we need to draw it ourselves
3535 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3536 const wxBorder border
= TranslateBorder(GetBorder());
3537 if (theme
&& border
== wxBORDER_THEME
)
3539 // first ask the widget to calculate the border size
3540 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3543 // now alter the client size making room for drawing a
3546 NCCALCSIZE_PARAMS
*csparam
= NULL
;
3549 csparam
= (NCCALCSIZE_PARAMS
*)lParam
;
3550 rect
= &csparam
->rgrc
[0];
3554 rect
= (RECT
*)lParam
;
3557 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3558 RECT rcClient
= { 0, 0, 0, 0 };
3559 wxClientDC
dc((wxWindow
*)this);
3560 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3562 if ( theme
->GetThemeBackgroundContentRect
3569 &rcClient
) == S_OK
)
3571 InflateRect(&rcClient
, -1, -1);
3573 csparam
->rgrc
[0] = rcClient
;
3575 *((RECT
*)lParam
) = rcClient
;
3577 // WVR_REDRAW triggers a bug whereby child windows are moved up and left,
3579 // rc.result = WVR_REDRAW;
3587 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3588 const wxBorder border
= TranslateBorder(GetBorder());
3589 if (theme
&& border
== wxBORDER_THEME
)
3591 // first ask the widget to paint its non-client area, such as scrollbars, etc.
3592 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3595 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3596 wxWindowDC
dc((wxWindow
*)this);
3597 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3599 // Clip the DC so that you only draw on the non-client area
3601 wxCopyRectToRECT(GetSize(), rcBorder
);
3604 theme
->GetThemeBackgroundContentRect(
3605 hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, ETS_NORMAL
, &rcBorder
, &rcClient
);
3606 InflateRect(&rcClient
, -1, -1);
3608 ::ExcludeClipRect(GetHdcOf(*impl
), rcClient
.left
, rcClient
.top
,
3609 rcClient
.right
, rcClient
.bottom
);
3611 // Make sure the background is in a proper state
3612 if (theme
->IsThemeBackgroundPartiallyTransparent(hTheme
, EP_EDITTEXT
, ETS_NORMAL
))
3614 theme
->DrawThemeParentBackground(GetHwnd(), GetHdcOf(*impl
), &rcBorder
);
3620 nState
= ETS_DISABLED
;
3621 // should we check this?
3622 //else if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & ES_READONLY)
3623 // nState = ETS_READONLY;
3625 nState
= ETS_NORMAL
;
3626 theme
->DrawThemeBackground(hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, nState
, &rcBorder
, NULL
);
3631 #endif // wxUSE_UXTHEME
3634 // try a custom message handler
3635 const MSWMessageHandlers::const_iterator
3636 i
= gs_messageHandlers
.find(message
);
3637 if ( i
!= gs_messageHandlers
.end() )
3639 processed
= (*i
->second
)(this, message
, wParam
, lParam
);
3645 #if wxDEBUG_LEVEL >= 2
3646 wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."),
3647 wxGetMessageName(message
));
3648 #endif // wxDEBUG_LEVEL >= 2
3649 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3655 // ----------------------------------------------------------------------------
3656 // wxWindow <-> HWND map
3657 // ----------------------------------------------------------------------------
3659 wxWindow
*wxFindWinFromHandle(HWND hwnd
)
3661 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3662 return i
== gs_windowHandles
.end() ? NULL
: i
->second
;
3665 void wxAssociateWinWithHandle(HWND hwnd
, wxWindowMSW
*win
)
3667 // adding NULL hwnd is (first) surely a result of an error and
3668 // (secondly) breaks menu command processing
3669 wxCHECK_RET( hwnd
!= (HWND
)NULL
,
3670 wxT("attempt to add a NULL hwnd to window list ignored") );
3673 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3674 if ( i
!= gs_windowHandles
.end() )
3676 if ( i
->second
!= win
)
3680 wxT("HWND %p already associated with another window (%s)"),
3681 hwnd
, win
->GetClassInfo()->GetClassName()
3685 //else: this actually happens currently because we associate the window
3686 // with its HWND during creation (if we create it) and also when
3687 // SubclassWin() is called later, this is ok
3689 #endif // wxDEBUG_LEVEL
3691 gs_windowHandles
[hwnd
] = (wxWindow
*)win
;
3694 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3696 gs_windowHandles
.erase(GetHwndOf(win
));
3699 // ----------------------------------------------------------------------------
3700 // various MSW speciic class dependent functions
3701 // ----------------------------------------------------------------------------
3703 // Default destroyer - override if you destroy it in some other way
3704 // (e.g. with MDI child windows)
3705 void wxWindowMSW::MSWDestroyWindow()
3709 void wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3712 int& w
, int& h
) const
3714 // CW_USEDEFAULT can't be used for child windows so just position them at
3715 // the origin by default
3716 x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
;
3717 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
;
3719 AdjustForParentClientOrigin(x
, y
);
3721 // We don't have any clearly good choice for the size by default neither
3722 // but we must use something non-zero.
3723 w
= WidthDefault(size
.x
);
3724 h
= HeightDefault(size
.y
);
3727 NB: there used to be some code here which set the initial size of the
3728 window to the client size of the parent if no explicit size was
3729 specified. This was wrong because wxWidgets programs often assume
3730 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3731 it. To see why, you should understand that Windows sends WM_SIZE from
3732 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3733 from some base class ctor and so this WM_SIZE is not processed in the
3734 real class' OnSize() (because it's not fully constructed yet and the
3735 event goes to some base class OnSize() instead). So the WM_SIZE we
3736 rely on is the one sent when the parent frame resizes its children
3737 but here is the problem: if the child already has just the right
3738 size, nothing will happen as both wxWidgets and Windows check for
3739 this and ignore any attempts to change the window size to the size it
3740 already has - so no WM_SIZE would be sent.
3744 WXHWND
wxWindowMSW::MSWGetParent() const
3746 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3749 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3750 const wxChar
*title
,
3754 WXDWORD extendedStyle
)
3756 // check a common bug in the user code: if the window is created with a
3757 // non-default ctor and Create() is called too, we'd create 2 HWND for a
3758 // single wxWindow object and this results in all sorts of trouble,
3759 // especially for wxTLWs
3760 wxCHECK_MSG( !m_hWnd
, true, "window can't be recreated" );
3762 // this can happen if this function is called using the return value of
3763 // wxApp::GetRegisteredClassName() which failed
3764 wxCHECK_MSG( wclass
, false, "failed to register window class?" );
3767 // choose the position/size for the new window
3769 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3771 // controlId is menu handle for the top level windows, so set it to 0
3772 // unless we're creating a child window
3773 int controlId
= style
& WS_CHILD
? GetId() : 0;
3775 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3776 // which is the same but without CS_[HV]REDRAW class styles so using it
3777 // ensures that the window is not fully repainted on each resize
3778 wxString
className(wclass
);
3779 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3781 className
+= wxApp::GetNoRedrawClassSuffix();
3784 // do create the window
3785 wxWindowCreationHook
hook(this);
3787 m_hWnd
= (WXHWND
)::CreateWindowEx
3791 title
? title
: m_windowName
.wx_str(),
3794 (HWND
)MSWGetParent(),
3795 (HMENU
)wxUIntToPtr(controlId
),
3797 NULL
// no extra data
3802 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3807 SubclassWin(m_hWnd
);
3812 // ===========================================================================
3813 // MSW message handlers
3814 // ===========================================================================
3816 // ---------------------------------------------------------------------------
3818 // ---------------------------------------------------------------------------
3820 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3822 #ifndef __WXMICROWIN__
3823 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3824 HWND hWnd
= hdr
->hwndFrom
;
3825 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
3827 // if the control is one of our windows, let it handle the message itself
3830 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3833 // VZ: why did we do it? normally this is unnecessary and, besides, it
3834 // breaks the message processing for the toolbars because the tooltip
3835 // notifications were being forwarded to the toolbar child controls
3836 // (if it had any) before being passed to the toolbar itself, so in my
3837 // example the tooltip for the combobox was always shown instead of the
3838 // correct button tooltips
3840 // try all our children
3841 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3844 wxWindow
*child
= node
->GetData();
3845 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3850 node
= node
->GetNext();
3854 // by default, handle it ourselves
3855 return MSWOnNotify(idCtrl
, lParam
, result
);
3856 #else // __WXMICROWIN__
3863 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3865 const wxString
& ttip
)
3867 // I don't know why it happens, but the versions of comctl32.dll starting
3868 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3869 // this message is supposed to be sent to Unicode programs only) -- hence
3870 // we need to handle it as well, otherwise no tooltips will be shown in
3873 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3876 // not a tooltip message or no tooltip to show anyhow
3881 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3883 // We don't want to use the szText buffer because it has a limit of 80
3884 // bytes and this is not enough, especially for Unicode build where it
3885 // limits the tooltip string length to only 40 characters
3887 // The best would be, of course, to not impose any length limitations at
3888 // all but then the buffer would have to be dynamic and someone would have
3889 // to free it and we don't have the tooltip owner object here any more, so
3890 // for now use our own static buffer with a higher fixed max length.
3892 // Note that using a static buffer should not be a problem as only a single
3893 // tooltip can be shown at the same time anyhow.
3895 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3897 // We need to convert tooltip from multi byte to Unicode on the fly.
3898 static wchar_t buf
[513];
3900 // Truncate tooltip length if needed as otherwise we might not have
3901 // enough space for it in the buffer and MultiByteToWideChar() would
3903 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3905 // Convert to WideChar without adding the NULL character. The NULL
3906 // character is added afterwards (this is more efficient).
3907 int len
= ::MultiByteToWideChar
3919 wxLogLastError(wxT("MultiByteToWideChar()"));
3923 ttText
->lpszText
= (LPSTR
) buf
;
3925 else // TTN_NEEDTEXTA
3926 #endif // !wxUSE_UNICODE
3928 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3929 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3930 // to copy the string we have into the buffer
3931 static wxChar buf
[513];
3932 wxStrlcpy(buf
, ttip
.c_str(), WXSIZEOF(buf
));
3933 ttText
->lpszText
= buf
;
3939 #endif // wxUSE_TOOLTIPS
3941 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3943 WXLPARAM
* WXUNUSED(result
))
3948 NMHDR
* hdr
= (NMHDR
*)lParam
;
3949 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3956 wxUnusedVar(lParam
);
3957 #endif // wxUSE_TOOLTIPS
3962 // ---------------------------------------------------------------------------
3963 // end session messages
3964 // ---------------------------------------------------------------------------
3966 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3968 #ifdef ENDSESSION_LOGOFF
3969 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3970 event
.SetEventObject(wxTheApp
);
3971 event
.SetCanVeto(true);
3972 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3974 bool rc
= wxTheApp
->ProcessEvent(event
);
3978 // we may end only if the app didn't veto session closing (double
3980 *mayEnd
= !event
.GetVeto();
3985 wxUnusedVar(logOff
);
3986 wxUnusedVar(mayEnd
);
3991 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3993 #ifdef ENDSESSION_LOGOFF
3994 // do nothing if the session isn't ending
3999 if ( (this != wxTheApp
->GetTopWindow()) )
4002 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
4003 event
.SetEventObject(wxTheApp
);
4004 event
.SetCanVeto(false);
4005 event
.SetLoggingOff((logOff
& ENDSESSION_LOGOFF
) != 0);
4007 return wxTheApp
->ProcessEvent(event
);
4009 wxUnusedVar(endSession
);
4010 wxUnusedVar(logOff
);
4015 // ---------------------------------------------------------------------------
4016 // window creation/destruction
4017 // ---------------------------------------------------------------------------
4019 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
4022 // VZ: why is this commented out for WinCE? If it doesn't support
4023 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
4024 // not with multiple #ifdef's!
4026 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
4027 EnsureParentHasControlParentStyle(GetParent());
4028 #endif // !__WXWINCE__
4035 bool wxWindowMSW::HandleDestroy()
4037 // delete our drop target if we've got one
4038 #if wxUSE_DRAG_AND_DROP
4039 if ( m_dropTarget
!= NULL
)
4041 m_dropTarget
->Revoke(m_hWnd
);
4043 wxDELETE(m_dropTarget
);
4045 #endif // wxUSE_DRAG_AND_DROP
4047 // WM_DESTROY handled
4051 // ---------------------------------------------------------------------------
4053 // ---------------------------------------------------------------------------
4055 bool wxWindowMSW::HandleActivate(int state
,
4056 bool WXUNUSED(minimized
),
4057 WXHWND
WXUNUSED(activate
))
4059 wxActivateEvent
event(wxEVT_ACTIVATE
,
4060 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
4062 event
.SetEventObject(this);
4064 return HandleWindowEvent(event
);
4067 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
4069 // Strangly enough, some controls get set focus events when they are being
4070 // deleted, even if they already had focus before.
4071 if ( m_isBeingDeleted
)
4076 // notify the parent keeping track of focus for the kbd navigation
4077 // purposes that we got it
4078 wxChildFocusEvent
eventFocus((wxWindow
*)this);
4079 (void)HandleWindowEvent(eventFocus
);
4085 m_caret
->OnSetFocus();
4087 #endif // wxUSE_CARET
4089 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
4090 event
.SetEventObject(this);
4092 // wxFindWinFromHandle() may return NULL, it is ok
4093 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4095 return HandleWindowEvent(event
);
4098 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
4104 m_caret
->OnKillFocus();
4106 #endif // wxUSE_CARET
4108 // Don't send the event when in the process of being deleted. This can
4109 // only cause problems if the event handler tries to access the object.
4110 if ( m_isBeingDeleted
)
4115 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
4116 event
.SetEventObject(this);
4118 // wxFindWinFromHandle() may return NULL, it is ok
4119 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4121 return HandleWindowEvent(event
);
4124 // ---------------------------------------------------------------------------
4126 // ---------------------------------------------------------------------------
4128 void wxWindowMSW::SetLabel( const wxString
& label
)
4130 SetWindowText(GetHwnd(), label
.c_str());
4133 wxString
wxWindowMSW::GetLabel() const
4135 return wxGetWindowText(GetHWND());
4138 // ---------------------------------------------------------------------------
4140 // ---------------------------------------------------------------------------
4142 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
4144 wxShowEvent
event(GetId(), show
);
4145 event
.SetEventObject(this);
4147 return HandleWindowEvent(event
);
4150 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
4152 wxInitDialogEvent
event(GetId());
4153 event
.SetEventObject(this);
4155 return HandleWindowEvent(event
);
4158 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
4160 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
4161 wxUnusedVar(wParam
);
4163 #else // __WXMICROWIN__
4164 HDROP hFilesInfo
= (HDROP
) wParam
;
4166 // Get the total number of files dropped
4167 UINT gwFilesDropped
= ::DragQueryFile
4175 wxString
*files
= new wxString
[gwFilesDropped
];
4176 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
4178 // first get the needed buffer length (+1 for terminating NUL)
4179 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
4181 // and now get the file name
4182 ::DragQueryFile(hFilesInfo
, wIndex
,
4183 wxStringBuffer(files
[wIndex
], len
), len
);
4186 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
4187 event
.SetEventObject(this);
4190 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
4191 event
.m_pos
.x
= dropPoint
.x
;
4192 event
.m_pos
.y
= dropPoint
.y
;
4194 DragFinish(hFilesInfo
);
4196 return HandleWindowEvent(event
);
4201 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
4203 int WXUNUSED(mouseMsg
))
4205 #ifndef __WXMICROWIN__
4206 // the logic is as follows:
4207 // 0. if we're busy, set the busy cursor (even for non client elements)
4208 // 1. don't set custom cursor for non client area of enabled windows
4209 // 2. ask user EVT_SET_CURSOR handler for the cursor
4210 // 3. if still no cursor but we're in a TLW, set the global cursor
4212 HCURSOR hcursor
= 0;
4215 hcursor
= wxGetCurrentBusyCursor();
4219 if ( nHitTest
!= HTCLIENT
)
4222 // first ask the user code - it may wish to set the cursor in some very
4223 // specific way (for example, depending on the current position)
4226 if ( !::GetCursorPosWinCE(&pt
))
4228 if ( !::GetCursorPos(&pt
) )
4231 wxLogLastError(wxT("GetCursorPos"));
4236 ScreenToClient(&x
, &y
);
4237 wxSetCursorEvent
event(x
, y
);
4238 event
.SetId(GetId());
4239 event
.SetEventObject(this);
4241 bool processedEvtSetCursor
= HandleWindowEvent(event
);
4242 if ( processedEvtSetCursor
&& event
.HasCursor() )
4244 hcursor
= GetHcursorOf(event
.GetCursor());
4249 // the test for processedEvtSetCursor is here to prevent using
4250 // m_cursor if the user code caught EVT_SET_CURSOR() and returned
4251 // nothing from it - this is a way to say that our cursor shouldn't
4252 // be used for this point
4253 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
4255 hcursor
= GetHcursorOf(m_cursor
);
4258 if ( !hcursor
&& !GetParent() )
4260 const wxCursor
*cursor
= wxGetGlobalCursor();
4261 if ( cursor
&& cursor
->Ok() )
4263 hcursor
= GetHcursorOf(*cursor
);
4272 ::SetCursor(hcursor
);
4274 // cursor set, stop here
4277 #endif // __WXMICROWIN__
4279 // pass up the window chain
4283 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
4284 WXLPARAM
WXUNUSED(lParam
),
4285 bool *WXUNUSED_IN_WINCE(vetoed
))
4291 wxEventType evtType
;
4294 case PBT_APMQUERYSUSPEND
:
4295 evtType
= wxEVT_POWER_SUSPENDING
;
4298 case PBT_APMQUERYSUSPENDFAILED
:
4299 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
4302 case PBT_APMSUSPEND
:
4303 evtType
= wxEVT_POWER_SUSPENDED
;
4306 case PBT_APMRESUMESUSPEND
:
4307 evtType
= wxEVT_POWER_RESUME
;
4311 wxLogDebug(wxT("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
4314 // these messages are currently not mapped to wx events
4315 case PBT_APMQUERYSTANDBY
:
4316 case PBT_APMQUERYSTANDBYFAILED
:
4317 case PBT_APMSTANDBY
:
4318 case PBT_APMRESUMESTANDBY
:
4319 case PBT_APMBATTERYLOW
:
4320 case PBT_APMPOWERSTATUSCHANGE
:
4321 case PBT_APMOEMEVENT
:
4322 case PBT_APMRESUMECRITICAL
:
4323 #ifdef PBT_APMRESUMEAUTOMATIC
4324 case PBT_APMRESUMEAUTOMATIC
:
4326 evtType
= wxEVT_NULL
;
4330 // don't handle unknown messages
4331 if ( evtType
== wxEVT_NULL
)
4334 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
4336 wxPowerEvent
event(evtType
);
4337 if ( !HandleWindowEvent(event
) )
4340 *vetoed
= event
.IsVetoed();
4346 bool wxWindowMSW::IsDoubleBuffered() const
4348 for ( const wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4350 if ( wxHasWindowExStyle(win
, WS_EX_COMPOSITED
) )
4353 if ( win
->IsTopLevel() )
4360 void wxWindowMSW::SetDoubleBuffered(bool on
)
4362 // Get the current extended style bits
4363 long exstyle
= wxGetWindowExStyle(this);
4365 // Twiddle the bit as needed
4367 exstyle
|= WS_EX_COMPOSITED
;
4369 exstyle
&= ~WS_EX_COMPOSITED
;
4372 wxSetWindowExStyle(this, exstyle
);
4375 // ---------------------------------------------------------------------------
4376 // owner drawn stuff
4377 // ---------------------------------------------------------------------------
4379 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
4380 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
4381 #define WXUNUSED_UNLESS_ODRAWN(param) param
4383 #define WXUNUSED_UNLESS_ODRAWN(param)
4387 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
4388 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
4390 #if wxUSE_OWNER_DRAWN
4392 #if wxUSE_MENUS_NATIVE
4393 // is it a menu item?
4394 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
4395 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
4397 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
4399 // see comment before the same test in MSWOnMeasureItem() below
4403 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4404 false, wxT("MSWOnDrawItem: bad wxMenuItem pointer") );
4406 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4407 // the DC from being released
4408 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
4409 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
4410 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
4411 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
4413 return pMenuItem
->OnDrawItem
4417 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
4418 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
4421 #endif // wxUSE_MENUS_NATIVE
4423 #endif // USE_OWNER_DRAWN
4425 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4427 #if wxUSE_OWNER_DRAWN
4428 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4429 #else // !wxUSE_OWNER_DRAWN
4430 // we may still have owner-drawn buttons internally because we have to make
4431 // them owner-drawn to support colour change
4434 wxDynamicCast(FindItem(id
), wxButton
)
4439 #endif // USE_OWNER_DRAWN
4443 return item
->MSWOnDraw(itemStruct
);
4446 #endif // wxUSE_CONTROLS
4452 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4454 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4455 // is it a menu item?
4456 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4457 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4459 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4461 // according to Carsten Fuchs the pointer may be NULL under XP if an
4462 // MDI child frame is initially maximized, see this for more info:
4463 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4465 // so silently ignore it instead of asserting
4469 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4470 false, wxT("MSWOnMeasureItem: bad wxMenuItem pointer") );
4473 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4475 pMeasureStruct
->itemWidth
= w
;
4476 pMeasureStruct
->itemHeight
= h
;
4481 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4484 return item
->MSWOnMeasure(itemStruct
);
4488 wxUnusedVar(itemStruct
);
4489 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4494 // ---------------------------------------------------------------------------
4495 // colours and palettes
4496 // ---------------------------------------------------------------------------
4498 bool wxWindowMSW::HandleSysColorChange()
4500 wxSysColourChangedEvent event
;
4501 event
.SetEventObject(this);
4503 (void)HandleWindowEvent(event
);
4505 // always let the system carry on the default processing to allow the
4506 // native controls to react to the colours update
4510 bool wxWindowMSW::HandleDisplayChange()
4512 wxDisplayChangedEvent event
;
4513 event
.SetEventObject(this);
4515 return HandleWindowEvent(event
);
4518 #ifndef __WXMICROWIN__
4520 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4522 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4526 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4529 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4531 #endif // wxUSE_CONTROLS
4534 return *brush
!= NULL
;
4537 #endif // __WXMICROWIN__
4539 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4542 // same as below except we don't respond to our own messages
4543 if ( hWndPalChange
!= GetHWND() )
4545 // check to see if we our our parents have a custom palette
4546 wxWindowMSW
*win
= this;
4547 while ( win
&& !win
->HasCustomPalette() )
4549 win
= win
->GetParent();
4552 if ( win
&& win
->HasCustomPalette() )
4554 // realize the palette to see whether redrawing is needed
4555 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4556 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4557 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4559 int result
= ::RealizePalette(hdc
);
4561 // restore the palette (before releasing the DC)
4562 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4563 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4564 ::RealizePalette(hdc
);
4565 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4567 // now check for the need to redraw
4569 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4573 #endif // wxUSE_PALETTE
4575 wxPaletteChangedEvent
event(GetId());
4576 event
.SetEventObject(this);
4577 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4579 return HandleWindowEvent(event
);
4582 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4584 // notify windows on the capture stack about lost capture
4585 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4586 wxWindowBase::NotifyCaptureLost();
4588 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4589 wxMouseCaptureChangedEvent
event(GetId(), win
);
4590 event
.SetEventObject(this);
4591 return HandleWindowEvent(event
);
4594 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4596 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4597 // we need to send this to child windows (it is only sent to top-level
4598 // windows) so {list,tree}ctrls can adjust their font size if necessary
4599 // this is exactly how explorer does it to enable the font size changes
4601 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4604 // top-level windows already get this message from the system
4605 wxWindow
*win
= node
->GetData();
4606 if ( !win
->IsTopLevel() )
4608 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4611 node
= node
->GetNext();
4614 // let the system handle it
4618 bool wxWindowMSW::HandleQueryNewPalette()
4622 // check to see if we our our parents have a custom palette
4623 wxWindowMSW
*win
= this;
4624 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4625 if (win
->HasCustomPalette()) {
4626 /* realize the palette to see whether redrawing is needed */
4627 HDC hdc
= ::GetDC((HWND
) GetHWND());
4628 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4629 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4631 int result
= ::RealizePalette(hdc
);
4632 /* restore the palette (before releasing the DC) */
4633 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4634 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4635 ::RealizePalette(hdc
);
4636 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4637 /* now check for the need to redraw */
4639 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4641 #endif // wxUSE_PALETTE
4643 wxQueryNewPaletteEvent
event(GetId());
4644 event
.SetEventObject(this);
4646 return HandleWindowEvent(event
) && event
.GetPaletteRealized();
4649 // Responds to colour changes: passes event on to children.
4650 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4652 // the top level window also reset the standard colour map as it might have
4653 // changed (there is no need to do it for the non top level windows as we
4654 // only have to do it once)
4658 gs_hasStdCmap
= false;
4660 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4663 // Only propagate to non-top-level windows because Windows already
4664 // sends this event to all top-level ones
4665 wxWindow
*win
= node
->GetData();
4666 if ( !win
->IsTopLevel() )
4668 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4669 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4670 // the standard controls
4671 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4674 node
= node
->GetNext();
4678 extern wxCOLORMAP
*wxGetStdColourMap()
4680 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4681 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4683 if ( !gs_hasStdCmap
)
4685 static bool s_coloursInit
= false;
4687 if ( !s_coloursInit
)
4689 // When a bitmap is loaded, the RGB values can change (apparently
4690 // because Windows adjusts them to care for the old programs always
4691 // using 0xc0c0c0 while the transparent colour for the new Windows
4692 // versions is different). But we do this adjustment ourselves so
4693 // we want to avoid Windows' "help" and for this we need to have a
4694 // reference bitmap which can tell us what the RGB values change
4696 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4697 wxBitmap
stdColourBitmap(wxT("wxBITMAP_STD_COLOURS"));
4698 if ( stdColourBitmap
.Ok() )
4700 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4701 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4702 wxT("forgot to update wxBITMAP_STD_COLOURS!") );
4705 memDC
.SelectObject(stdColourBitmap
);
4708 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4710 memDC
.GetPixel(i
, 0, &colour
);
4711 s_stdColours
[i
] = wxColourToRGB(colour
);
4714 else // wxBITMAP_STD_COLOURS couldn't be loaded
4716 s_stdColours
[0] = RGB(000,000,000); // black
4717 s_stdColours
[1] = RGB(128,128,128); // dark grey
4718 s_stdColours
[2] = RGB(192,192,192); // light grey
4719 s_stdColours
[3] = RGB(255,255,255); // white
4720 //s_stdColours[4] = RGB(000,000,255); // blue
4721 //s_stdColours[5] = RGB(255,000,255); // magenta
4724 s_coloursInit
= true;
4727 gs_hasStdCmap
= true;
4729 // create the colour map
4730 #define INIT_CMAP_ENTRY(col) \
4731 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4732 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4734 INIT_CMAP_ENTRY(BTNTEXT
);
4735 INIT_CMAP_ENTRY(BTNSHADOW
);
4736 INIT_CMAP_ENTRY(BTNFACE
);
4737 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4739 #undef INIT_CMAP_ENTRY
4745 #if wxUSE_UXTHEME && !defined(TMT_FILLCOLOR)
4746 #define TMT_FILLCOLOR 3802
4747 #define TMT_TEXTCOLOR 3803
4748 #define TMT_BORDERCOLOR 3801
4751 wxColour
wxWindowMSW::MSWGetThemeColour(const wchar_t *themeName
,
4754 MSWThemeColour themeColour
,
4755 wxSystemColour fallback
) const
4758 const wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
4761 int themeProperty
= 0;
4763 // TODO: Convert this into a table? Sure would be faster.
4764 switch ( themeColour
)
4766 case ThemeColourBackground
:
4767 themeProperty
= TMT_FILLCOLOR
;
4769 case ThemeColourText
:
4770 themeProperty
= TMT_TEXTCOLOR
;
4772 case ThemeColourBorder
:
4773 themeProperty
= TMT_BORDERCOLOR
;
4776 wxFAIL_MSG(wxT("unsupported theme colour"));
4779 wxUxThemeHandle
hTheme((const wxWindow
*)this, themeName
);
4781 HRESULT hr
= theme
->GetThemeColor
4790 if ( SUCCEEDED(hr
) )
4791 return wxRGBToColour(col
);
4795 "GetThemeColor(%s, %i, %i, %i)",
4796 themeName
, themePart
, themeState
, themeProperty
),
4800 wxUnusedVar(themeName
);
4801 wxUnusedVar(themePart
);
4802 wxUnusedVar(themeState
);
4803 wxUnusedVar(themeColour
);
4805 return wxSystemSettings::GetColour(fallback
);
4808 // ---------------------------------------------------------------------------
4810 // ---------------------------------------------------------------------------
4812 // this variable is used to check that a paint event handler which processed
4813 // the event did create a wxPaintDC inside its code and called BeginPaint() to
4814 // validate the invalidated window area as otherwise we'd keep getting an
4815 // endless stream of WM_PAINT messages for this window resulting in a lot of
4816 // difficult to debug problems (e.g. impossibility to repaint other windows,
4817 // lack of timer and idle events and so on)
4818 extern bool wxDidCreatePaintDC
;
4819 bool wxDidCreatePaintDC
= false;
4821 bool wxWindowMSW::HandlePaint()
4823 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4826 wxLogLastError(wxT("CreateRectRgn"));
4828 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4830 wxLogLastError(wxT("GetUpdateRgn"));
4833 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4835 wxDidCreatePaintDC
= false;
4837 wxPaintEvent
event(m_windowId
);
4838 event
.SetEventObject(this);
4840 bool processed
= HandleWindowEvent(event
);
4842 if ( processed
&& !wxDidCreatePaintDC
)
4844 // do call MSWDefWindowProc() to validate the update region to avoid
4845 // the problems mentioned above
4849 // note that we must generate NC event after the normal one as otherwise
4850 // BeginPaint() will happily overwrite our decorations with the background
4852 wxNcPaintEvent
eventNc(m_windowId
);
4853 eventNc
.SetEventObject(this);
4854 HandleWindowEvent(eventNc
);
4856 // don't keep an HRGN we don't need any longer (GetUpdateRegion() can only
4857 // be called from inside the event handlers called above)
4858 m_updateRegion
.Clear();
4863 // Can be called from an application's OnPaint handler
4864 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4866 #ifdef __WXUNIVERSAL__
4869 HDC hDC
= (HDC
) wxPaintDCImpl::FindDCInCache((wxWindow
*) event
.GetEventObject());
4872 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4877 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4879 switch ( GetBackgroundStyle() )
4881 case wxBG_STYLE_ERASE
:
4882 case wxBG_STYLE_COLOUR
:
4883 // we need to generate an erase background event
4885 wxDCTemp
dc(hdc
, GetClientSize());
4886 wxDCTempImpl
*impl
= (wxDCTempImpl
*) dc
.GetImpl();
4889 impl
->SetWindow((wxWindow
*)this);
4891 wxEraseEvent
event(m_windowId
, &dc
);
4892 event
.SetEventObject(this);
4893 bool rc
= HandleWindowEvent(event
);
4895 // must be called manually as ~wxDC doesn't do anything for
4897 impl
->SelectOldObjects(hdc
);
4901 // background erased by the user-defined handler
4907 case wxBG_STYLE_SYSTEM
:
4908 if ( !DoEraseBackground(hdc
) )
4910 // let the default processing to take place if we didn't erase
4911 // the background ourselves
4916 case wxBG_STYLE_PAINT
:
4917 case wxBG_STYLE_TRANSPARENT
:
4918 // no need to do anything here at all, background will be entirely
4919 // redrawn in WM_PAINT handler
4923 wxFAIL_MSG( "unknown background style" );
4929 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
4931 bool wxWindowMSW::MSWHasEraseBgHook() const
4933 return gs_eraseBgHooks
.find(const_cast<wxWindowMSW
*>(this))
4934 != gs_eraseBgHooks
.end();
4937 void wxWindowMSW::MSWSetEraseBgHook(wxWindow
*child
)
4941 if ( !gs_eraseBgHooks
.insert(
4942 EraseBgHooks::value_type(this, child
)).second
)
4944 wxFAIL_MSG( wxT("Setting erase background hook twice?") );
4947 else // reset the hook
4949 if ( gs_eraseBgHooks
.erase(this) != 1 )
4951 wxFAIL_MSG( wxT("Resetting erase background which was not set?") );
4956 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
4958 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4960 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4964 // erase just the client area of the window, this is important for the
4965 // frames to avoid drawing over the toolbar part of the window (you might
4966 // think using WS_CLIPCHILDREN would prevent this from happening, but it
4969 wxCopyRectToRECT(GetClientRect(), rc
);
4970 ::FillRect((HDC
)hDC
, &rc
, hbr
);
4976 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
),
4977 wxWindowMSW
* WXUNUSED(child
))
4982 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4984 return (WXHBRUSH
)GetHbrushOf(*brush
);
4990 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
)
4992 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4994 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, this);
4998 // don't use the parent background if we're not transparent
4999 if ( !win
->HasTransparentBackground() )
5002 // background is not inherited beyond top level windows
5003 if ( win
->IsTopLevel() )
5010 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
5012 // we receive this message when DrawThemeParentBackground() is
5013 // called from def window proc of several controls under XP and we
5014 // must draw properly themed background here
5016 // note that naively I'd expect filling the client rect with the
5017 // brush returned by MSWGetBgBrush() work -- but for some reason it
5018 // doesn't and we have to call parents MSWPrintChild() which is
5019 // supposed to call DrawThemeBackground() with appropriate params
5021 // also note that in this case lParam == PRF_CLIENT but we're
5022 // clearly expected to paint the background and nothing else!
5024 if ( IsTopLevel() || InheritsBackgroundColour() )
5027 // sometimes we don't want the parent to handle it at all, instead
5028 // return whatever value this window wants
5029 if ( !MSWShouldPropagatePrintChild() )
5030 return MSWPrintChild(hDC
, (wxWindow
*)this);
5032 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
5034 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
5037 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
5044 // ---------------------------------------------------------------------------
5045 // moving and resizing
5046 // ---------------------------------------------------------------------------
5048 bool wxWindowMSW::HandleMinimize()
5050 wxIconizeEvent
event(m_windowId
);
5051 event
.SetEventObject(this);
5053 return HandleWindowEvent(event
);
5056 bool wxWindowMSW::HandleMaximize()
5058 wxMaximizeEvent
event(m_windowId
);
5059 event
.SetEventObject(this);
5061 return HandleWindowEvent(event
);
5064 bool wxWindowMSW::HandleMove(int x
, int y
)
5067 wxMoveEvent
event(point
, m_windowId
);
5068 event
.SetEventObject(this);
5070 return HandleWindowEvent(event
);
5073 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
5075 wxMoveEvent
event(rect
, m_windowId
);
5076 event
.SetEventObject(this);
5078 bool rc
= HandleWindowEvent(event
);
5080 rect
= event
.GetRect();
5084 bool wxWindowMSW::HandleEnterSizeMove()
5086 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5087 event
.SetEventType(wxEVT_MOVE_START
);
5088 event
.SetEventObject(this);
5090 return HandleWindowEvent(event
);
5093 bool wxWindowMSW::HandleExitSizeMove()
5095 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5096 event
.SetEventType(wxEVT_MOVE_END
);
5097 event
.SetEventObject(this);
5099 return HandleWindowEvent(event
);
5102 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
5104 #if wxUSE_DEFERRED_SIZING
5105 // when we resize this window, its children are probably going to be
5106 // repositioned as well, prepare to use DeferWindowPos() for them
5107 int numChildren
= 0;
5108 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
5110 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
5115 // Protect against valid m_hDWP being overwritten
5116 bool useDefer
= false;
5118 if ( numChildren
> 1 )
5122 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
5125 wxLogLastError(wxT("BeginDeferWindowPos"));
5131 #endif // wxUSE_DEFERRED_SIZING
5133 // update this window size
5134 bool processed
= false;
5138 wxFAIL_MSG( wxT("unexpected WM_SIZE parameter") );
5139 // fall through nevertheless
5143 // we're not interested in these messages at all
5146 case SIZE_MINIMIZED
:
5147 processed
= HandleMinimize();
5150 case SIZE_MAXIMIZED
:
5151 /* processed = */ HandleMaximize();
5152 // fall through to send a normal size event as well
5155 // don't use w and h parameters as they specify the client size
5156 // while according to the docs EVT_SIZE handler is supposed to
5157 // receive the total size
5158 wxSizeEvent
event(GetSize(), m_windowId
);
5159 event
.SetEventObject(this);
5161 processed
= HandleWindowEvent(event
);
5164 #if wxUSE_DEFERRED_SIZING
5165 // and finally change the positions of all child windows at once
5166 if ( useDefer
&& m_hDWP
)
5168 // reset m_hDWP to NULL so that child windows don't try to use our
5169 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
5170 // happen anyhow normally but who knows what weird flow of control we
5171 // may have depending on what the users EVT_SIZE handler does...)
5172 HDWP hDWP
= (HDWP
)m_hDWP
;
5175 // do put all child controls in place at once
5176 if ( !::EndDeferWindowPos(hDWP
) )
5178 wxLogLastError(wxT("EndDeferWindowPos"));
5181 // Reset our children's pending pos/size values.
5182 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
5184 node
= node
->GetNext() )
5186 wxWindowMSW
* const child
= node
->GetData();
5187 child
->MSWEndDeferWindowPos();
5190 #endif // wxUSE_DEFERRED_SIZING
5195 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
5197 wxSizeEvent
event(rect
, m_windowId
);
5198 event
.SetEventObject(this);
5200 bool rc
= HandleWindowEvent(event
);
5202 rect
= event
.GetRect();
5206 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
5211 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
5215 int minWidth
= GetMinWidth(),
5216 minHeight
= GetMinHeight(),
5217 maxWidth
= GetMaxWidth(),
5218 maxHeight
= GetMaxHeight();
5220 if ( minWidth
!= wxDefaultCoord
)
5222 info
->ptMinTrackSize
.x
= minWidth
;
5226 if ( minHeight
!= wxDefaultCoord
)
5228 info
->ptMinTrackSize
.y
= minHeight
;
5232 if ( maxWidth
!= wxDefaultCoord
)
5234 info
->ptMaxTrackSize
.x
= maxWidth
;
5238 if ( maxHeight
!= wxDefaultCoord
)
5240 info
->ptMaxTrackSize
.y
= maxHeight
;
5248 // ---------------------------------------------------------------------------
5250 // ---------------------------------------------------------------------------
5252 bool wxWindowMSW::HandleCommand(WXWORD id_
, WXWORD cmd
, WXHWND control
)
5254 // sign extend to int from short before comparing with the other int ids
5255 int id
= (signed short)id_
;
5257 #if wxUSE_MENUS_NATIVE
5258 if ( !cmd
&& wxCurrentPopupMenu
)
5260 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
5261 wxCurrentPopupMenu
= NULL
;
5263 return popupMenu
->MSWCommand(cmd
, id
);
5265 #endif // wxUSE_MENUS_NATIVE
5267 wxWindow
*win
= NULL
;
5269 // first try to find it from HWND - this works even with the broken
5270 // programs using the same ids for different controls
5273 win
= wxFindWinFromHandle(control
);
5284 return win
->MSWCommand(cmd
, id
);
5287 // the messages sent from the in-place edit control used by the treectrl
5288 // for label editing have id == 0, but they should _not_ be treated as menu
5289 // messages (they are EN_XXX ones, in fact) so don't translate anything
5290 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
5293 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
5294 event
.SetEventObject(this);
5297 return HandleWindowEvent(event
);
5301 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5302 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
5303 // notifications to its parent which we want to reflect back to
5305 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
5306 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
5308 #endif // wxUSE_SPINCTRL
5310 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
5311 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
5312 // notifications to its parent which we want to reflect back to
5314 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
5315 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
5323 // ---------------------------------------------------------------------------
5325 // ---------------------------------------------------------------------------
5327 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
5331 // our client coords are not quite the same as Windows ones
5332 wxPoint pt
= GetClientAreaOrigin();
5333 event
.m_x
= x
- pt
.x
;
5334 event
.m_y
= y
- pt
.y
;
5336 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
5337 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
5338 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
5339 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
5340 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
5341 #ifdef wxHAS_XBUTTON
5342 event
.m_aux1Down
= (flags
& MK_XBUTTON1
) != 0;
5343 event
.m_aux2Down
= (flags
& MK_XBUTTON2
) != 0;
5344 #endif // wxHAS_XBUTTON
5345 event
.m_altDown
= ::wxIsAltDown();
5348 event
.SetTimestamp(::GetMessageTime());
5351 event
.SetEventObject(this);
5352 event
.SetId(GetId());
5354 #if wxUSE_MOUSEEVENT_HACK
5355 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
5356 gs_lastMouseEvent
.type
= event
.GetEventType();
5357 #endif // wxUSE_MOUSEEVENT_HACK
5361 // Windows doesn't send the mouse events to the static controls (which are
5362 // transparent in the sense that their WM_NCHITTEST handler returns
5363 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
5364 // and so we manually check if we don't have a child window under mouse and if
5365 // we do, send the event to it instead of the window Windows had sent WM_XXX
5368 // Notice that this is not done for the mouse move events because this could
5369 // (would?) be too slow, but only for clicks which means that the static texts
5370 // still don't get move, enter nor leave events.
5371 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
5373 wxCHECK_MSG( x
&& y
, win
, wxT("NULL pointer in FindWindowForMouseEvent") );
5375 // first try to find a non transparent child: this allows us to send events
5376 // to a static text which is inside a static box, for example
5377 POINT pt
= { *x
, *y
};
5378 HWND hwnd
= GetHwndOf(win
),
5382 hwndUnderMouse
= ::ChildWindowFromPoint
5388 hwndUnderMouse
= ::ChildWindowFromPointEx
5398 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
5400 // now try any child window at all
5401 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
5404 // check that we have a child window which is susceptible to receive mouse
5405 // events: for this it must be shown and enabled
5406 if ( hwndUnderMouse
&&
5407 hwndUnderMouse
!= hwnd
&&
5408 ::IsWindowVisible(hwndUnderMouse
) &&
5409 ::IsWindowEnabled(hwndUnderMouse
) )
5411 wxWindow
*winUnderMouse
= wxFindWinFromHandle(hwndUnderMouse
);
5412 if ( winUnderMouse
)
5414 // translate the mouse coords to the other window coords
5415 win
->ClientToScreen(x
, y
);
5416 winUnderMouse
->ScreenToClient(x
, y
);
5418 win
= winUnderMouse
;
5424 #endif // __WXWINCE__
5426 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5428 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
5429 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
5430 // from the message id and take the value in the table to get wxWin event
5432 static const wxEventType eventsMouse
[] =
5443 wxEVT_MIDDLE_DCLICK
,
5444 0, // this one is for wxEVT_MOTION which is not used here
5453 #ifdef wxHAS_XBUTTON
5454 // the same messages are used for both auxillary mouse buttons so we need
5455 // to adjust the index manually
5458 case WM_XBUTTONDOWN
:
5460 case WM_XBUTTONDBLCLK
:
5461 if ( flags
& MK_XBUTTON2
)
5462 msg
+= wxEVT_AUX2_DOWN
- wxEVT_AUX1_DOWN
;
5464 #endif // wxHAS_XBUTTON
5466 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
5467 InitMouseEvent(event
, x
, y
, flags
);
5469 return HandleWindowEvent(event
);
5472 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
5474 if ( !m_mouseInWindow
)
5476 // it would be wrong to assume that just because we get a mouse move
5477 // event that the mouse is inside the window: although this is usually
5478 // true, it is not if we had captured the mouse, so we need to check
5479 // the mouse coordinates here
5480 if ( !HasCapture() || IsMouseInWindow() )
5482 // Generate an ENTER event
5483 m_mouseInWindow
= true;
5485 #ifdef HAVE_TRACKMOUSEEVENT
5486 typedef BOOL (WINAPI
*_TrackMouseEvent_t
)(LPTRACKMOUSEEVENT
);
5488 static const _TrackMouseEvent_t
5489 s_pfn_TrackMouseEvent
= _TrackMouseEvent
;
5490 #else // !__WXWINCE__
5491 static _TrackMouseEvent_t s_pfn_TrackMouseEvent
;
5492 static bool s_initDone
= false;
5495 // see comment in wxApp::GetComCtl32Version() explaining the
5496 // use of wxLoadedDLL
5497 wxLoadedDLL
dllComCtl32(wxT("comctl32.dll"));
5498 if ( dllComCtl32
.IsLoaded() )
5500 s_pfn_TrackMouseEvent
= (_TrackMouseEvent_t
)
5501 dllComCtl32
.RawGetSymbol(wxT("_TrackMouseEvent"));
5507 if ( s_pfn_TrackMouseEvent
)
5508 #endif // __WXWINCE__/!__WXWINCE__
5510 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
5512 trackinfo
.dwFlags
= TME_LEAVE
;
5513 trackinfo
.hwndTrack
= GetHwnd();
5515 (*s_pfn_TrackMouseEvent
)(&trackinfo
);
5517 #endif // HAVE_TRACKMOUSEEVENT
5519 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
5520 InitMouseEvent(event
, x
, y
, flags
);
5522 (void)HandleWindowEvent(event
);
5525 #ifdef HAVE_TRACKMOUSEEVENT
5526 else // mouse not in window
5528 // Check if we need to send a LEAVE event
5529 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
5530 // send it here if we are using native mouse leave tracking
5531 if ( HasCapture() && !IsMouseInWindow() )
5533 GenerateMouseLeave();
5536 #endif // HAVE_TRACKMOUSEEVENT
5538 #if wxUSE_MOUSEEVENT_HACK
5539 // Windows often generates mouse events even if mouse position hasn't
5540 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
5542 // Filter this out as it can result in unexpected behaviour compared to
5544 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
5545 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
5546 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
5547 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
5549 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
5551 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
5556 #endif // wxUSE_MOUSEEVENT_HACK
5558 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
5562 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
5564 #if wxUSE_MOUSEWHEEL
5565 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5566 // forwarded up to the parent by DefWindowProc()) and not in the client
5567 // ones as all the other messages, translate them to the client coords for
5570 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
5571 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
5572 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
5573 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5574 event
.m_wheelDelta
= WHEEL_DELTA
;
5576 static int s_linesPerRotation
= -1;
5577 if ( s_linesPerRotation
== -1 )
5579 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5580 &s_linesPerRotation
, 0))
5582 // this is not supposed to happen
5583 wxLogLastError(wxT("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5585 // the default is 3, so use it if SystemParametersInfo() failed
5586 s_linesPerRotation
= 3;
5590 event
.m_linesPerAction
= s_linesPerRotation
;
5591 return HandleWindowEvent(event
);
5593 #else // !wxUSE_MOUSEWHEEL
5594 wxUnusedVar(wParam
);
5595 wxUnusedVar(lParam
);
5598 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5601 void wxWindowMSW::GenerateMouseLeave()
5603 m_mouseInWindow
= false;
5606 if ( wxIsShiftDown() )
5608 if ( wxIsCtrlDown() )
5609 state
|= MK_CONTROL
;
5611 // Only the high-order bit should be tested
5612 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5613 state
|= MK_LBUTTON
;
5614 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5615 state
|= MK_MBUTTON
;
5616 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5617 state
|= MK_RBUTTON
;
5621 if ( !::GetCursorPosWinCE(&pt
) )
5623 if ( !::GetCursorPos(&pt
) )
5626 wxLogLastError(wxT("GetCursorPos"));
5629 // we need to have client coordinates here for symmetry with
5630 // wxEVT_ENTER_WINDOW
5631 RECT rect
= wxGetWindowRect(GetHwnd());
5635 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5636 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5638 (void)HandleWindowEvent(event
);
5641 // ---------------------------------------------------------------------------
5642 // keyboard handling
5643 // ---------------------------------------------------------------------------
5648 // Implementation of InitAnyKeyEvent() which can also be used when there is no
5649 // associated window: this can happen for the wxEVT_CHAR_HOOK events created by
5650 // the global keyboard hook (e.g. the event might have happened in a non-wx
5653 MSWInitAnyKeyEvent(wxKeyEvent
& event
,
5656 const wxWindowBase
*win
/* may be NULL */)
5660 event
.SetId(win
->GetId());
5661 event
.SetEventObject(const_cast<wxWindowBase
*>(win
));
5663 else // No associated window.
5665 // Use wxID_ANY for compatibility with the old code even if wxID_NONE
5666 // would arguably make more sense.
5667 event
.SetId(wxID_ANY
);
5670 event
.m_shiftDown
= wxIsShiftDown();
5671 event
.m_controlDown
= wxIsCtrlDown();
5672 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5674 event
.m_rawCode
= (wxUint32
) wParam
;
5675 event
.m_rawFlags
= (wxUint32
) lParam
;
5677 event
.SetTimestamp(::GetMessageTime());
5680 // Event coordinates must be in window client coordinates system which
5681 // doesn't make sense if there is no window.
5683 // We could use screen coordinates for such events but this would make the
5684 // logic of the event handlers more complicated: you'd need to test for the
5685 // event object and interpret the coordinates differently according to
5686 // whether it's NULL or not so unless somebody really asks for this let's
5687 // just avoid the issue.
5690 const wxPoint mousePos
= win
->ScreenToClient(wxGetMousePosition());
5691 event
.m_x
= mousePos
.x
;
5692 event
.m_y
= mousePos
.y
;
5696 } // anonymous namespace
5699 wxWindowMSW::InitAnyKeyEvent(wxKeyEvent
& event
,
5701 WXLPARAM lParam
) const
5703 MSWInitAnyKeyEvent(event
, wParam
, lParam
, this);
5707 wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5709 WXLPARAM lParam
) const
5711 // Catch any attempts to use this with WM_CHAR, it wouldn't work because
5712 // wParam is supposed to be a virtual key and not a character here.
5713 wxASSERT_MSG( evType
!= wxEVT_CHAR
&& evType
!= wxEVT_CHAR_HOOK
,
5714 "CreateKeyEvent() can't be used for char events" );
5716 wxKeyEvent
event(evType
);
5717 InitAnyKeyEvent(event
, wParam
, lParam
);
5719 event
.m_keyCode
= wxMSWKeyboard::VKToWX
5725 #endif // wxUSE_UNICODE
5731 // isASCII is true only when we're called from WM_CHAR handler and not from
5733 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
)
5735 wxKeyEvent
event(wxEVT_CHAR
);
5736 InitAnyKeyEvent(event
, wParam
, lParam
);
5739 // TODO: wParam uses UTF-16 so this is incorrect for characters outside of
5740 // the BMP, we should use WM_UNICHAR to handle them.
5741 event
.m_uniChar
= wParam
;
5742 #endif // wxUSE_UNICODE
5744 // Set non-Unicode key code too for compatibility if possible.
5745 if ( wParam
< 0x80 )
5747 // It's an ASCII character, no need to translate it.
5748 event
.m_keyCode
= wParam
;
5752 // Check if this key can be represented (as a single character) in the
5754 const wchar_t wc
= wParam
;
5756 if ( wxConvLibc
.FromWChar(&ch
, 1, &wc
, 1) != wxCONV_FAILED
)
5758 // For compatibility continue to provide the key code in this field
5759 // even though using GetUnicodeKey() is recommended now.
5760 event
.m_keyCode
= static_cast<unsigned char>(ch
);
5762 //else: Key can't be represented in the current locale, leave m_keyCode
5763 // as WXK_NONE and use GetUnicodeKey() to access the character.
5766 // the alphanumeric keys produced by pressing AltGr+something on European
5767 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5768 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5769 // alphanumeric, so pretend that there are no modifiers at all (the
5770 // KEY_DOWN event would still have the correct modifiers if they're really
5772 if ( event
.m_controlDown
&& event
.m_altDown
&&
5773 (event
.m_keyCode
>= 32 && event
.m_keyCode
< 256) )
5775 event
.m_controlDown
=
5776 event
.m_altDown
= false;
5779 return HandleWindowEvent(event
);
5782 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5784 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, wParam
, lParam
));
5785 return HandleWindowEvent(event
);
5788 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5790 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, wParam
, lParam
));
5791 return HandleWindowEvent(event
);
5795 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5796 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5798 // FIXME: implement GetMenuItemCount for WinCE, possibly
5799 // in terms of GetMenuItemInfo
5801 const HMENU hmenu
= (HMENU
)lParam
;
5805 mii
.cbSize
= sizeof(MENUITEMINFO
);
5807 // we could use MIIM_FTYPE here as we only need to know if the item is
5808 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5809 // MIIM_FTYPE is not supported under Win95
5810 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5812 // find if we have this letter in any owner drawn item
5813 const int count
= ::GetMenuItemCount(hmenu
);
5814 for ( int i
= 0; i
< count
; i
++ )
5816 // previous loop iteration could modify it, reset it back before
5817 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5820 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5822 if ( mii
.fType
== MFT_OWNERDRAW
)
5824 // dwItemData member of the MENUITEMINFO is a
5825 // pointer to the associated wxMenuItem -- see the
5826 // menu creation code
5827 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5829 const wxString
label(item
->GetItemLabel());
5830 const wxChar
*p
= wxStrchr(label
.wx_str(), wxT('&'));
5833 if ( *p
== wxT('&') )
5835 // this is not the accel char, find the real one
5836 p
= wxStrchr(p
+ 1, wxT('&'));
5838 else // got the accel char
5840 // FIXME-UNICODE: this comparison doesn't risk to work
5841 // for non ASCII accelerator characters I'm afraid, but
5843 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5849 // this one doesn't match
5856 else // failed to get the menu text?
5858 // it's not fatal, so don't show error, but still log it
5859 wxLogLastError(wxT("GetMenuItemInfo"));
5866 #endif // wxUSE_MENUS
5868 bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg
)
5870 const wxEventType type
= nMsg
== WM_CUT
? wxEVT_COMMAND_TEXT_CUT
5871 : nMsg
== WM_COPY
? wxEVT_COMMAND_TEXT_COPY
5872 : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE
;
5873 wxClipboardTextEvent
evt(type
, GetId());
5875 evt
.SetEventObject(this);
5877 return HandleWindowEvent(evt
);
5880 // ---------------------------------------------------------------------------
5882 // ---------------------------------------------------------------------------
5884 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5888 if ( flags
& JOY_BUTTON1CHG
)
5889 change
= wxJOY_BUTTON1
;
5890 if ( flags
& JOY_BUTTON2CHG
)
5891 change
= wxJOY_BUTTON2
;
5892 if ( flags
& JOY_BUTTON3CHG
)
5893 change
= wxJOY_BUTTON3
;
5894 if ( flags
& JOY_BUTTON4CHG
)
5895 change
= wxJOY_BUTTON4
;
5898 if ( flags
& JOY_BUTTON1
)
5899 buttons
|= wxJOY_BUTTON1
;
5900 if ( flags
& JOY_BUTTON2
)
5901 buttons
|= wxJOY_BUTTON2
;
5902 if ( flags
& JOY_BUTTON3
)
5903 buttons
|= wxJOY_BUTTON3
;
5904 if ( flags
& JOY_BUTTON4
)
5905 buttons
|= wxJOY_BUTTON4
;
5907 // the event ids aren't consecutive so we can't use table based lookup
5909 wxEventType eventType
;
5914 eventType
= wxEVT_JOY_MOVE
;
5919 eventType
= wxEVT_JOY_MOVE
;
5924 eventType
= wxEVT_JOY_ZMOVE
;
5929 eventType
= wxEVT_JOY_ZMOVE
;
5932 case MM_JOY1BUTTONDOWN
:
5934 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5937 case MM_JOY2BUTTONDOWN
:
5939 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5942 case MM_JOY1BUTTONUP
:
5944 eventType
= wxEVT_JOY_BUTTON_UP
;
5947 case MM_JOY2BUTTONUP
:
5949 eventType
= wxEVT_JOY_BUTTON_UP
;
5953 wxFAIL_MSG(wxT("no such joystick event"));
5958 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5959 event
.SetPosition(wxPoint(x
, y
));
5960 event
.SetEventObject(this);
5962 return HandleWindowEvent(event
);
5972 // ---------------------------------------------------------------------------
5974 // ---------------------------------------------------------------------------
5976 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5977 WXWORD pos
, WXHWND control
)
5979 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5981 wxWindow
*child
= wxFindWinFromHandle(control
);
5983 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5986 wxScrollWinEvent event
;
5987 event
.SetPosition(pos
);
5988 event
.SetOrientation(orientation
);
5989 event
.SetEventObject(this);
5994 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5998 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
6002 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
6006 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
6010 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
6014 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
6017 case SB_THUMBPOSITION
:
6019 // under Win32, the scrollbar range and position are 32 bit integers,
6020 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
6021 // explicitly query the scrollbar for the correct position (this must
6022 // be done only for these two SB_ events as they are the only one
6023 // carrying the scrollbar position)
6025 WinStruct
<SCROLLINFO
> scrollInfo
;
6026 scrollInfo
.fMask
= SIF_TRACKPOS
;
6028 if ( !::GetScrollInfo(GetHwnd(),
6029 WXOrientToSB(orientation
),
6032 // Not necessarily an error, if there are no scrollbars yet.
6033 // wxLogLastError(wxT("GetScrollInfo"));
6036 event
.SetPosition(scrollInfo
.nTrackPos
);
6039 event
.SetEventType( wParam
== SB_THUMBPOSITION
6040 ? wxEVT_SCROLLWIN_THUMBRELEASE
6041 : wxEVT_SCROLLWIN_THUMBTRACK
);
6048 return HandleWindowEvent(event
);
6051 // ----------------------------------------------------------------------------
6052 // custom message handlers
6053 // ----------------------------------------------------------------------------
6056 wxWindowMSW::MSWRegisterMessageHandler(int msg
, MSWMessageHandler handler
)
6058 wxCHECK_MSG( gs_messageHandlers
.find(msg
) == gs_messageHandlers
.end(),
6059 false, wxT("registering handler for the same message twice") );
6061 gs_messageHandlers
[msg
] = handler
;
6066 wxWindowMSW::MSWUnregisterMessageHandler(int msg
, MSWMessageHandler handler
)
6068 const MSWMessageHandlers::iterator i
= gs_messageHandlers
.find(msg
);
6069 wxCHECK_RET( i
!= gs_messageHandlers
.end() && i
->second
== handler
,
6070 wxT("unregistering non-registered handler?") );
6072 gs_messageHandlers
.erase(i
);
6075 // ===========================================================================
6077 // ===========================================================================
6079 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
6082 HDC dc
= ::GetDC((HWND
) wnd
);
6085 // the_font.UseResource();
6086 // the_font.RealizeResource();
6087 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
6089 was
= (HFONT
) SelectObject(dc
,fnt
);
6091 GetTextMetrics(dc
, &tm
);
6094 SelectObject(dc
,was
);
6096 ReleaseDC((HWND
)wnd
, dc
);
6099 *x
= tm
.tmAveCharWidth
;
6101 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
6103 // the_font.ReleaseResource();
6106 // ----------------------------------------------------------------------------
6108 // ----------------------------------------------------------------------------
6110 namespace wxMSWKeyboard
6116 // use the "extended" bit of lParam to distinguish extended keys from normal
6117 // keys as the same virtual key code is sent for both by Windows
6119 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
6121 // except that if lParam is 0, it means we don't have real lParam from
6122 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
6123 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
6124 // non-numpad (hence extended) key as this is a more common case
6125 return !lParam
|| (HIWORD(lParam
) & KF_EXTENDED
) ? keyExtended
: keyNormal
;
6128 // this array contains the Windows virtual key codes which map one to one to
6129 // WXK_xxx constants and is used in wxMSWKeyboard::VKToWX/WXToVK() below
6131 // note that keys having a normal and numpad version (e.g. WXK_HOME and
6132 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
6133 const struct wxKeyMapping
6137 } gs_specialKeys
[] =
6139 { VK_CANCEL
, WXK_CANCEL
},
6140 { VK_BACK
, WXK_BACK
},
6141 { VK_TAB
, WXK_TAB
},
6142 { VK_CLEAR
, WXK_CLEAR
},
6143 { VK_SHIFT
, WXK_SHIFT
},
6144 { VK_CONTROL
, WXK_CONTROL
},
6145 { VK_MENU
, WXK_ALT
},
6146 { VK_PAUSE
, WXK_PAUSE
},
6147 { VK_CAPITAL
, WXK_CAPITAL
},
6148 { VK_SPACE
, WXK_SPACE
},
6149 { VK_ESCAPE
, WXK_ESCAPE
},
6150 { VK_SELECT
, WXK_SELECT
},
6151 { VK_PRINT
, WXK_PRINT
},
6152 { VK_EXECUTE
, WXK_EXECUTE
},
6153 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
6154 { VK_HELP
, WXK_HELP
},
6156 { VK_NUMPAD0
, WXK_NUMPAD0
},
6157 { VK_NUMPAD1
, WXK_NUMPAD1
},
6158 { VK_NUMPAD2
, WXK_NUMPAD2
},
6159 { VK_NUMPAD3
, WXK_NUMPAD3
},
6160 { VK_NUMPAD4
, WXK_NUMPAD4
},
6161 { VK_NUMPAD5
, WXK_NUMPAD5
},
6162 { VK_NUMPAD6
, WXK_NUMPAD6
},
6163 { VK_NUMPAD7
, WXK_NUMPAD7
},
6164 { VK_NUMPAD8
, WXK_NUMPAD8
},
6165 { VK_NUMPAD9
, WXK_NUMPAD9
},
6166 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
6167 { VK_ADD
, WXK_NUMPAD_ADD
},
6168 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
6169 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
6170 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
6181 { VK_F10
, WXK_F10
},
6182 { VK_F11
, WXK_F11
},
6183 { VK_F12
, WXK_F12
},
6184 { VK_F13
, WXK_F13
},
6185 { VK_F14
, WXK_F14
},
6186 { VK_F15
, WXK_F15
},
6187 { VK_F16
, WXK_F16
},
6188 { VK_F17
, WXK_F17
},
6189 { VK_F18
, WXK_F18
},
6190 { VK_F19
, WXK_F19
},
6191 { VK_F20
, WXK_F20
},
6192 { VK_F21
, WXK_F21
},
6193 { VK_F22
, WXK_F22
},
6194 { VK_F23
, WXK_F23
},
6195 { VK_F24
, WXK_F24
},
6197 { VK_NUMLOCK
, WXK_NUMLOCK
},
6198 { VK_SCROLL
, WXK_SCROLL
},
6201 { VK_LWIN
, WXK_WINDOWS_LEFT
},
6202 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
6203 { VK_APPS
, WXK_WINDOWS_MENU
},
6204 #endif // VK_APPS defined
6207 } // anonymous namespace
6209 int VKToWX(WXWORD vk
, WXLPARAM lParam
, wchar_t *uc
)
6213 // check the table first
6214 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6216 if ( gs_specialKeys
[n
].vk
== vk
)
6218 wxk
= gs_specialKeys
[n
].wxk
;
6219 if ( wxk
< WXK_START
)
6221 // Unicode code for this key is the same as its ASCII code.
6230 // keys requiring special handling
6244 // MapVirtualKey() returns 0 if it fails to convert the virtual
6245 // key which nicely corresponds to our WXK_NONE.
6246 wxk
= ::MapVirtualKey(vk
, MAPVK_VK_TO_CHAR
);
6248 if ( HIWORD(wxk
) & 0x8000 )
6250 // It's a dead key and we don't return anything at all for them
6251 // as we simply don't have any way to indicate the difference
6252 // between e.g. a normal "'" and "'" as a dead key -- and
6253 // generating the same events for them just doesn't seem like a
6258 // In any case return this as a Unicode character value.
6262 // For compatibility with the old non-Unicode code we continue
6263 // returning key codes for Latin-1 characters directly
6264 // (normally it would really only make sense to do it for the
6265 // ASCII characters, not Latin-1 ones).
6268 // But for anything beyond this we can only return the key
6269 // value as a real Unicode character, not a wxKeyCode
6270 // because this enum values clash with Unicode characters
6271 // (e.g. WXK_LBUTTON also happens to be U+012C a.k.a.
6272 // "LATIN CAPITAL LETTER I WITH BREVE").
6277 // handle extended keys
6279 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
6283 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
6287 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
6291 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
6295 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
6299 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
6303 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
6307 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
6311 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
6315 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
6319 // don't use ChooseNormalOrExtended() here as the keys are reversed
6320 // here: numpad enter is the extended one
6321 wxk
= HIWORD(lParam
) & KF_EXTENDED
? WXK_NUMPAD_ENTER
: WXK_RETURN
;
6325 if ( (vk
>= '0' && vk
<= '9') || (vk
>= 'A' && vk
<= 'Z') )
6327 // A simple alphanumeric key and the values of them coincide in
6328 // Windows and wx for both ASCII and Unicode codes.
6331 else // Something we simply don't know about at all.
6343 WXWORD
WXToVK(int wxk
, bool *isExtended
)
6345 // check the table first
6346 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6348 if ( gs_specialKeys
[n
].wxk
== wxk
)
6350 // All extended keys (i.e. non-numpad versions of the keys that
6351 // exist both in the numpad and outside of it) are dealt with
6354 *isExtended
= false;
6356 return gs_specialKeys
[n
].vk
;
6360 // and then check for special keys not included in the table
6361 bool extended
= false;
6367 case WXK_NUMPAD_PAGEUP
:
6373 case WXK_NUMPAD_PAGEDOWN
:
6379 case WXK_NUMPAD_END
:
6385 case WXK_NUMPAD_HOME
:
6391 case WXK_NUMPAD_LEFT
:
6403 case WXK_NUMPAD_RIGHT
:
6409 case WXK_NUMPAD_DOWN
:
6415 case WXK_NUMPAD_INSERT
:
6421 case WXK_NUMPAD_DELETE
:
6426 // no VkKeyScan() under CE unfortunately, we need to test how does
6427 // it handle OEM keys
6429 // check to see if its one of the OEM key codes.
6430 BYTE vks
= LOBYTE(VkKeyScan(wxk
));
6436 #endif // !__WXWINCE__
6443 *isExtended
= extended
;
6448 } // namespace wxMSWKeyboard
6450 // small helper for wxGetKeyState() and wxGetMouseState()
6451 static inline bool wxIsKeyDown(WXWORD vk
)
6453 // SM_SWAPBUTTON is not available under CE, so don't swap buttons there
6454 #ifdef SM_SWAPBUTTON
6455 if ( vk
== VK_LBUTTON
|| vk
== VK_RBUTTON
)
6457 if ( ::GetSystemMetrics(SM_SWAPBUTTON
) )
6459 if ( vk
== VK_LBUTTON
)
6461 else // vk == VK_RBUTTON
6465 #endif // SM_SWAPBUTTON
6467 // the low order bit indicates whether the key was pressed since the last
6468 // call and the high order one indicates whether it is down right now and
6469 // we only want that one
6470 return (GetAsyncKeyState(vk
) & (1<<15)) != 0;
6473 bool wxGetKeyState(wxKeyCode key
)
6475 // although this does work under Windows, it is not supported under other
6476 // platforms so don't allow it, you must use wxGetMouseState() instead
6477 wxASSERT_MSG( key
!= VK_LBUTTON
&&
6478 key
!= VK_RBUTTON
&&
6480 wxT("can't use wxGetKeyState() for mouse buttons") );
6482 const WXWORD vk
= wxMSWKeyboard::WXToVK(key
);
6484 // if the requested key is a LED key, return true if the led is pressed
6485 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
6487 // low order bit means LED is highlighted and high order one means the
6488 // key is down; for compatibility with the other ports return true if
6489 // either one is set
6490 return GetKeyState(vk
) != 0;
6495 return wxIsKeyDown(vk
);
6500 wxMouseState
wxGetMouseState()
6504 GetCursorPos( &pt
);
6508 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
6509 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
6510 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
6511 #ifdef wxHAS_XBUTTON
6512 ms
.SetAux1Down(wxIsKeyDown(VK_XBUTTON1
));
6513 ms
.SetAux2Down(wxIsKeyDown(VK_XBUTTON2
));
6514 #endif // wxHAS_XBUTTON
6516 ms
.SetControlDown(wxIsCtrlDown ());
6517 ms
.SetShiftDown (wxIsShiftDown());
6518 ms
.SetAltDown (wxIsAltDown ());
6519 // ms.SetMetaDown();
6525 wxWindow
*wxGetActiveWindow()
6527 HWND hWnd
= GetActiveWindow();
6530 return wxFindWinFromHandle(hWnd
);
6535 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
6537 HWND hwnd
= (HWND
)hWnd
;
6539 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
6540 // by code in msw/radiobox.cpp), for all the others we just search up the
6542 wxWindow
*win
= NULL
;
6545 win
= wxFindWinFromHandle(hwnd
);
6549 // native radiobuttons return DLGC_RADIOBUTTON here and for any
6550 // wxWindow class which overrides WM_GETDLGCODE processing to
6551 // do it as well, win would be already non NULL
6552 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
6554 win
= wxRadioBox::GetFromRadioButtonHWND(hwnd
);
6556 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
6557 #endif // wxUSE_RADIOBOX
6559 // spin control text buddy window should be mapped to spin ctrl
6560 // itself so try it too
6561 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
6564 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
6566 #endif // wxUSE_SPINCTRL
6570 while ( hwnd
&& !win
)
6572 // this is a really ugly hack needed to avoid mistakenly returning the
6573 // parent frame wxWindow for the find/replace modeless dialog HWND -
6574 // this, in turn, is needed to call IsDialogMessage() from
6575 // wxApp::ProcessMessage() as for this we must return NULL from here
6577 // FIXME: this is clearly not the best way to do it but I think we'll
6578 // need to change HWND <-> wxWindow code more heavily than I can
6579 // do it now to fix it
6580 #ifndef __WXMICROWIN__
6581 if ( ::GetWindow(hwnd
, GW_OWNER
) )
6583 // it's a dialog box, don't go upwards
6588 hwnd
= ::GetParent(hwnd
);
6589 win
= wxFindWinFromHandle(hwnd
);
6595 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
6597 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
6598 // in active frames and dialogs, regardless of where the focus is.
6599 static HHOOK wxTheKeyboardHook
= 0;
6602 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
6604 DWORD hiWord
= HIWORD(lParam
);
6605 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
6608 int id
= wxMSWKeyboard::VKToWX(wParam
, lParam
, &uc
);
6611 || static_cast<int>(uc
) != WXK_NONE
6612 #endif // wxUSE_UNICODE
6615 const wxWindow
* const win
= wxGetActiveWindow();
6617 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
6618 MSWInitAnyKeyEvent(event
, wParam
, lParam
, win
);
6620 event
.m_keyCode
= id
;
6622 event
.m_uniChar
= uc
;
6623 #endif // wxUSE_UNICODE
6625 wxEvtHandler
* const handler
= win
? win
->GetEventHandler()
6628 if ( handler
&& handler
->ProcessEvent(event
) )
6636 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
6639 void wxSetKeyboardHook(bool doIt
)
6643 wxTheKeyboardHook
= ::SetWindowsHookEx
6646 (HOOKPROC
)wxKeyboardHook
,
6647 NULL
, // must be NULL for process hook
6648 ::GetCurrentThreadId()
6650 if ( !wxTheKeyboardHook
)
6652 wxLogLastError(wxT("SetWindowsHookEx(wxKeyboardHook)"));
6657 if ( wxTheKeyboardHook
)
6658 ::UnhookWindowsHookEx(wxTheKeyboardHook
);
6662 #endif // !__WXMICROWIN__
6664 #if wxDEBUG_LEVEL >= 2
6665 const wxChar
*wxGetMessageName(int message
)
6669 case 0x0000: return wxT("WM_NULL");
6670 case 0x0001: return wxT("WM_CREATE");
6671 case 0x0002: return wxT("WM_DESTROY");
6672 case 0x0003: return wxT("WM_MOVE");
6673 case 0x0005: return wxT("WM_SIZE");
6674 case 0x0006: return wxT("WM_ACTIVATE");
6675 case 0x0007: return wxT("WM_SETFOCUS");
6676 case 0x0008: return wxT("WM_KILLFOCUS");
6677 case 0x000A: return wxT("WM_ENABLE");
6678 case 0x000B: return wxT("WM_SETREDRAW");
6679 case 0x000C: return wxT("WM_SETTEXT");
6680 case 0x000D: return wxT("WM_GETTEXT");
6681 case 0x000E: return wxT("WM_GETTEXTLENGTH");
6682 case 0x000F: return wxT("WM_PAINT");
6683 case 0x0010: return wxT("WM_CLOSE");
6684 case 0x0011: return wxT("WM_QUERYENDSESSION");
6685 case 0x0012: return wxT("WM_QUIT");
6686 case 0x0013: return wxT("WM_QUERYOPEN");
6687 case 0x0014: return wxT("WM_ERASEBKGND");
6688 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
6689 case 0x0016: return wxT("WM_ENDSESSION");
6690 case 0x0017: return wxT("WM_SYSTEMERROR");
6691 case 0x0018: return wxT("WM_SHOWWINDOW");
6692 case 0x0019: return wxT("WM_CTLCOLOR");
6693 case 0x001A: return wxT("WM_WININICHANGE");
6694 case 0x001B: return wxT("WM_DEVMODECHANGE");
6695 case 0x001C: return wxT("WM_ACTIVATEAPP");
6696 case 0x001D: return wxT("WM_FONTCHANGE");
6697 case 0x001E: return wxT("WM_TIMECHANGE");
6698 case 0x001F: return wxT("WM_CANCELMODE");
6699 case 0x0020: return wxT("WM_SETCURSOR");
6700 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6701 case 0x0022: return wxT("WM_CHILDACTIVATE");
6702 case 0x0023: return wxT("WM_QUEUESYNC");
6703 case 0x0024: return wxT("WM_GETMINMAXINFO");
6704 case 0x0026: return wxT("WM_PAINTICON");
6705 case 0x0027: return wxT("WM_ICONERASEBKGND");
6706 case 0x0028: return wxT("WM_NEXTDLGCTL");
6707 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6708 case 0x002B: return wxT("WM_DRAWITEM");
6709 case 0x002C: return wxT("WM_MEASUREITEM");
6710 case 0x002D: return wxT("WM_DELETEITEM");
6711 case 0x002E: return wxT("WM_VKEYTOITEM");
6712 case 0x002F: return wxT("WM_CHARTOITEM");
6713 case 0x0030: return wxT("WM_SETFONT");
6714 case 0x0031: return wxT("WM_GETFONT");
6715 case 0x0037: return wxT("WM_QUERYDRAGICON");
6716 case 0x0039: return wxT("WM_COMPAREITEM");
6717 case 0x0041: return wxT("WM_COMPACTING");
6718 case 0x0044: return wxT("WM_COMMNOTIFY");
6719 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6720 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6721 case 0x0048: return wxT("WM_POWER");
6723 case 0x004A: return wxT("WM_COPYDATA");
6724 case 0x004B: return wxT("WM_CANCELJOURNAL");
6725 case 0x004E: return wxT("WM_NOTIFY");
6726 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6727 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6728 case 0x0052: return wxT("WM_TCARD");
6729 case 0x0053: return wxT("WM_HELP");
6730 case 0x0054: return wxT("WM_USERCHANGED");
6731 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6732 case 0x007B: return wxT("WM_CONTEXTMENU");
6733 case 0x007C: return wxT("WM_STYLECHANGING");
6734 case 0x007D: return wxT("WM_STYLECHANGED");
6735 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6736 case 0x007F: return wxT("WM_GETICON");
6737 case 0x0080: return wxT("WM_SETICON");
6739 case 0x0081: return wxT("WM_NCCREATE");
6740 case 0x0082: return wxT("WM_NCDESTROY");
6741 case 0x0083: return wxT("WM_NCCALCSIZE");
6742 case 0x0084: return wxT("WM_NCHITTEST");
6743 case 0x0085: return wxT("WM_NCPAINT");
6744 case 0x0086: return wxT("WM_NCACTIVATE");
6745 case 0x0087: return wxT("WM_GETDLGCODE");
6746 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6747 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6748 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6749 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6750 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6751 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6752 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6753 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6754 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6755 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6757 case 0x00B0: return wxT("EM_GETSEL");
6758 case 0x00B1: return wxT("EM_SETSEL");
6759 case 0x00B2: return wxT("EM_GETRECT");
6760 case 0x00B3: return wxT("EM_SETRECT");
6761 case 0x00B4: return wxT("EM_SETRECTNP");
6762 case 0x00B5: return wxT("EM_SCROLL");
6763 case 0x00B6: return wxT("EM_LINESCROLL");
6764 case 0x00B7: return wxT("EM_SCROLLCARET");
6765 case 0x00B8: return wxT("EM_GETMODIFY");
6766 case 0x00B9: return wxT("EM_SETMODIFY");
6767 case 0x00BA: return wxT("EM_GETLINECOUNT");
6768 case 0x00BB: return wxT("EM_LINEINDEX");
6769 case 0x00BC: return wxT("EM_SETHANDLE");
6770 case 0x00BD: return wxT("EM_GETHANDLE");
6771 case 0x00BE: return wxT("EM_GETTHUMB");
6772 case 0x00C1: return wxT("EM_LINELENGTH");
6773 case 0x00C2: return wxT("EM_REPLACESEL");
6774 case 0x00C4: return wxT("EM_GETLINE");
6775 case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */
6776 case 0x00C6: return wxT("EM_CANUNDO");
6777 case 0x00C7: return wxT("EM_UNDO");
6778 case 0x00C8: return wxT("EM_FMTLINES");
6779 case 0x00C9: return wxT("EM_LINEFROMCHAR");
6780 case 0x00CB: return wxT("EM_SETTABSTOPS");
6781 case 0x00CC: return wxT("EM_SETPASSWORDCHAR");
6782 case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER");
6783 case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE");
6784 case 0x00CF: return wxT("EM_SETREADONLY");
6785 case 0x00D0: return wxT("EM_SETWORDBREAKPROC");
6786 case 0x00D1: return wxT("EM_GETWORDBREAKPROC");
6787 case 0x00D2: return wxT("EM_GETPASSWORDCHAR");
6788 case 0x00D3: return wxT("EM_SETMARGINS");
6789 case 0x00D4: return wxT("EM_GETMARGINS");
6790 case 0x00D5: return wxT("EM_GETLIMITTEXT");
6791 case 0x00D6: return wxT("EM_POSFROMCHAR");
6792 case 0x00D7: return wxT("EM_CHARFROMPOS");
6793 case 0x00D8: return wxT("EM_SETIMESTATUS");
6794 case 0x00D9: return wxT("EM_GETIMESTATUS");
6796 case 0x0100: return wxT("WM_KEYDOWN");
6797 case 0x0101: return wxT("WM_KEYUP");
6798 case 0x0102: return wxT("WM_CHAR");
6799 case 0x0103: return wxT("WM_DEADCHAR");
6800 case 0x0104: return wxT("WM_SYSKEYDOWN");
6801 case 0x0105: return wxT("WM_SYSKEYUP");
6802 case 0x0106: return wxT("WM_SYSCHAR");
6803 case 0x0107: return wxT("WM_SYSDEADCHAR");
6804 case 0x0108: return wxT("WM_KEYLAST");
6806 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6807 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6808 case 0x010F: return wxT("WM_IME_COMPOSITION");
6810 case 0x0110: return wxT("WM_INITDIALOG");
6811 case 0x0111: return wxT("WM_COMMAND");
6812 case 0x0112: return wxT("WM_SYSCOMMAND");
6813 case 0x0113: return wxT("WM_TIMER");
6814 case 0x0114: return wxT("WM_HSCROLL");
6815 case 0x0115: return wxT("WM_VSCROLL");
6816 case 0x0116: return wxT("WM_INITMENU");
6817 case 0x0117: return wxT("WM_INITMENUPOPUP");
6818 case 0x011F: return wxT("WM_MENUSELECT");
6819 case 0x0120: return wxT("WM_MENUCHAR");
6820 case 0x0121: return wxT("WM_ENTERIDLE");
6822 case 0x0127: return wxT("WM_CHANGEUISTATE");
6823 case 0x0128: return wxT("WM_UPDATEUISTATE");
6824 case 0x0129: return wxT("WM_QUERYUISTATE");
6826 case 0x0132: return wxT("WM_CTLCOLORMSGBOX");
6827 case 0x0133: return wxT("WM_CTLCOLOREDIT");
6828 case 0x0134: return wxT("WM_CTLCOLORLISTBOX");
6829 case 0x0135: return wxT("WM_CTLCOLORBTN");
6830 case 0x0136: return wxT("WM_CTLCOLORDLG");
6831 case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR");
6832 case 0x0138: return wxT("WM_CTLCOLORSTATIC");
6833 case 0x01E1: return wxT("MN_GETHMENU");
6835 case 0x0200: return wxT("WM_MOUSEMOVE");
6836 case 0x0201: return wxT("WM_LBUTTONDOWN");
6837 case 0x0202: return wxT("WM_LBUTTONUP");
6838 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6839 case 0x0204: return wxT("WM_RBUTTONDOWN");
6840 case 0x0205: return wxT("WM_RBUTTONUP");
6841 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6842 case 0x0207: return wxT("WM_MBUTTONDOWN");
6843 case 0x0208: return wxT("WM_MBUTTONUP");
6844 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6845 case 0x020A: return wxT("WM_MOUSEWHEEL");
6846 case 0x020B: return wxT("WM_XBUTTONDOWN");
6847 case 0x020C: return wxT("WM_XBUTTONUP");
6848 case 0x020D: return wxT("WM_XBUTTONDBLCLK");
6849 case 0x0210: return wxT("WM_PARENTNOTIFY");
6850 case 0x0211: return wxT("WM_ENTERMENULOOP");
6851 case 0x0212: return wxT("WM_EXITMENULOOP");
6853 case 0x0213: return wxT("WM_NEXTMENU");
6854 case 0x0214: return wxT("WM_SIZING");
6855 case 0x0215: return wxT("WM_CAPTURECHANGED");
6856 case 0x0216: return wxT("WM_MOVING");
6857 case 0x0218: return wxT("WM_POWERBROADCAST");
6858 case 0x0219: return wxT("WM_DEVICECHANGE");
6860 case 0x0220: return wxT("WM_MDICREATE");
6861 case 0x0221: return wxT("WM_MDIDESTROY");
6862 case 0x0222: return wxT("WM_MDIACTIVATE");
6863 case 0x0223: return wxT("WM_MDIRESTORE");
6864 case 0x0224: return wxT("WM_MDINEXT");
6865 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6866 case 0x0226: return wxT("WM_MDITILE");
6867 case 0x0227: return wxT("WM_MDICASCADE");
6868 case 0x0228: return wxT("WM_MDIICONARRANGE");
6869 case 0x0229: return wxT("WM_MDIGETACTIVE");
6870 case 0x0230: return wxT("WM_MDISETMENU");
6871 case 0x0233: return wxT("WM_DROPFILES");
6873 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6874 case 0x0282: return wxT("WM_IME_NOTIFY");
6875 case 0x0283: return wxT("WM_IME_CONTROL");
6876 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6877 case 0x0285: return wxT("WM_IME_SELECT");
6878 case 0x0286: return wxT("WM_IME_CHAR");
6879 case 0x0290: return wxT("WM_IME_KEYDOWN");
6880 case 0x0291: return wxT("WM_IME_KEYUP");
6882 case 0x02A0: return wxT("WM_NCMOUSEHOVER");
6883 case 0x02A1: return wxT("WM_MOUSEHOVER");
6884 case 0x02A2: return wxT("WM_NCMOUSELEAVE");
6885 case 0x02A3: return wxT("WM_MOUSELEAVE");
6887 case 0x0300: return wxT("WM_CUT");
6888 case 0x0301: return wxT("WM_COPY");
6889 case 0x0302: return wxT("WM_PASTE");
6890 case 0x0303: return wxT("WM_CLEAR");
6891 case 0x0304: return wxT("WM_UNDO");
6892 case 0x0305: return wxT("WM_RENDERFORMAT");
6893 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6894 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6895 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6896 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6897 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6898 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6899 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6900 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6901 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6902 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6903 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6904 case 0x0311: return wxT("WM_PALETTECHANGED");
6905 case 0x0312: return wxT("WM_HOTKEY");
6907 case 0x0317: return wxT("WM_PRINT");
6908 case 0x0318: return wxT("WM_PRINTCLIENT");
6910 // common controls messages - although they're not strictly speaking
6911 // standard, it's nice to decode them nevertheless
6914 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6915 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6916 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6917 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6918 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6919 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6920 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6921 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6922 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6923 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6924 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6925 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6926 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6927 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6928 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6929 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6930 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6931 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6932 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6933 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6934 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6935 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6936 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6937 case 0x1000 + 18: return wxT("LVM_HITTEST");
6938 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6939 case 0x1000 + 20: return wxT("LVM_SCROLL");
6940 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6941 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6942 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6943 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6944 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6945 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6946 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6947 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6948 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6949 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6950 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6951 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6952 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6953 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6954 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6955 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6956 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6957 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6958 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6959 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6960 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6961 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6962 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6963 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6964 case 0x1000 + 42: return wxT("LVM_UPDATE");
6965 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6966 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6967 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6968 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6969 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6970 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6971 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6972 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6973 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6974 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6975 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6976 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6977 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6978 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6979 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6980 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6981 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6982 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6983 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6984 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6985 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6986 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6987 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6988 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6989 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6990 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6993 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6994 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6995 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6996 case 0x1100 + 2: return wxT("TVM_EXPAND");
6997 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6998 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6999 case 0x1100 + 6: return wxT("TVM_GETINDENT");
7000 case 0x1100 + 7: return wxT("TVM_SETINDENT");
7001 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
7002 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
7003 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
7004 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
7005 case 0x1100 + 12: return wxT("TVM_GETITEMA");
7006 case 0x1100 + 62: return wxT("TVM_GETITEMW");
7007 case 0x1100 + 13: return wxT("TVM_SETITEMA");
7008 case 0x1100 + 63: return wxT("TVM_SETITEMW");
7009 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
7010 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
7011 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
7012 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
7013 case 0x1100 + 17: return wxT("TVM_HITTEST");
7014 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
7015 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
7016 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
7017 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
7018 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
7019 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
7020 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
7021 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
7022 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
7025 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
7026 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
7027 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
7028 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
7029 case 0x1200 + 3: return wxT("HDM_GETITEMA");
7030 case 0x1200 + 11: return wxT("HDM_GETITEMW");
7031 case 0x1200 + 4: return wxT("HDM_SETITEMA");
7032 case 0x1200 + 12: return wxT("HDM_SETITEMW");
7033 case 0x1200 + 5: return wxT("HDM_LAYOUT");
7034 case 0x1200 + 6: return wxT("HDM_HITTEST");
7035 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
7036 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
7037 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
7038 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
7039 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
7040 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
7041 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
7042 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
7045 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
7046 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
7047 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
7048 case 0x1300 + 5: return wxT("TCM_GETITEMA");
7049 case 0x1300 + 60: return wxT("TCM_GETITEMW");
7050 case 0x1300 + 6: return wxT("TCM_SETITEMA");
7051 case 0x1300 + 61: return wxT("TCM_SETITEMW");
7052 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
7053 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
7054 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
7055 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
7056 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
7057 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
7058 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
7059 case 0x1300 + 13: return wxT("TCM_HITTEST");
7060 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
7061 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
7062 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
7063 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
7064 case 0x1300 + 43: return wxT("TCM_SETPADDING");
7065 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
7066 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
7067 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
7068 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
7069 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
7070 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
7071 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
7074 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
7075 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
7076 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
7077 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
7078 case WM_USER
+5: return wxT("TB_INDETERMINATE");
7079 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
7080 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
7081 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
7082 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
7083 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
7084 case WM_USER
+17: return wxT("TB_SETSTATE");
7085 case WM_USER
+18: return wxT("TB_GETSTATE");
7086 case WM_USER
+19: return wxT("TB_ADDBITMAP");
7087 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
7088 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
7089 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
7090 case WM_USER
+23: return wxT("TB_GETBUTTON");
7091 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
7092 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
7093 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
7094 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
7095 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
7096 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
7097 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
7098 case WM_USER
+29: return wxT("TB_GETITEMRECT");
7099 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
7100 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
7101 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
7102 case WM_USER
+33: return wxT("TB_AUTOSIZE");
7103 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
7104 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
7105 case WM_USER
+37: return wxT("TB_SETPARENT");
7106 case WM_USER
+39: return wxT("TB_SETROWS");
7107 case WM_USER
+40: return wxT("TB_GETROWS");
7108 case WM_USER
+42: return wxT("TB_SETCMDID");
7109 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
7110 case WM_USER
+44: return wxT("TB_GETBITMAP");
7111 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
7112 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
7113 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
7114 case WM_USER
+47: return wxT("TB_SETINDENT");
7115 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
7116 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
7117 case WM_USER
+50: return wxT("TB_LOADIMAGES");
7118 case WM_USER
+51: return wxT("TB_GETRECT");
7119 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
7120 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
7121 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
7122 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
7123 case WM_USER
+56: return wxT("TB_SETSTYLE");
7124 case WM_USER
+57: return wxT("TB_GETSTYLE");
7125 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
7126 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
7127 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
7128 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
7129 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
7132 static wxString s_szBuf
;
7133 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
7134 return s_szBuf
.c_str();
7137 #endif // wxDEBUG_LEVEL >= 2
7139 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
7143 HWND hwnd
= GetHwndOf(win
);
7144 HDC hdc
= ::GetDC(hwnd
);
7146 #if !wxDIALOG_UNIT_COMPATIBILITY
7147 // and select the current font into it
7148 HFONT hfont
= GetHfontOf(win
->GetFont());
7151 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
7155 // finally retrieve the text metrics from it
7156 GetTextMetrics(hdc
, &tm
);
7158 #if !wxDIALOG_UNIT_COMPATIBILITY
7162 (void)::SelectObject(hdc
, hfont
);
7166 ::ReleaseDC(hwnd
, hdc
);
7171 // Find the wxWindow at the current mouse position, returning the mouse
7173 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
7175 pt
= wxGetMousePosition();
7176 return wxFindWindowAtPoint(pt
);
7179 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
7185 HWND hWnd
= ::WindowFromPoint(pt2
);
7187 return wxGetWindowFromHWND((WXHWND
)hWnd
);
7190 // Get the current mouse position.
7191 wxPoint
wxGetMousePosition()
7195 GetCursorPosWinCE(&pt
);
7197 GetCursorPos( & pt
);
7200 return wxPoint(pt
.x
, pt
.y
);
7205 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7206 static void WinCEUnregisterHotKey(int modifiers
, int id
)
7208 // Register hotkeys for the hardware buttons
7210 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
7212 UnregisterFunc1Proc procUnregisterFunc
;
7213 hCoreDll
= LoadLibrary(wxT("coredll.dll"));
7216 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, wxT("UnregisterFunc1"));
7217 if (procUnregisterFunc
)
7218 procUnregisterFunc(modifiers
, id
);
7219 FreeLibrary(hCoreDll
);
7224 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
7226 UINT win_modifiers
=0;
7227 if ( modifiers
& wxMOD_ALT
)
7228 win_modifiers
|= MOD_ALT
;
7229 if ( modifiers
& wxMOD_SHIFT
)
7230 win_modifiers
|= MOD_SHIFT
;
7231 if ( modifiers
& wxMOD_CONTROL
)
7232 win_modifiers
|= MOD_CONTROL
;
7233 if ( modifiers
& wxMOD_WIN
)
7234 win_modifiers
|= MOD_WIN
;
7236 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7237 // Required for PPC and Smartphone hardware buttons
7238 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
7239 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
7242 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
7244 wxLogLastError(wxT("RegisterHotKey"));
7252 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
7254 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7255 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
7258 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
7260 wxLogLastError(wxT("UnregisterHotKey"));
7270 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
7272 int win_modifiers
= LOWORD(lParam
);
7274 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, HIWORD(lParam
)));
7275 event
.SetId(wParam
);
7276 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
7277 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
7278 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
7279 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
7281 return HandleWindowEvent(event
);
7284 #endif // wxUSE_ACCEL
7286 #endif // wxUSE_HOTKEY
7288 // Not tested under WinCE
7291 // this class installs a message hook which really wakes up our idle processing
7292 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
7293 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
7294 // being dragged or even inside ::MessageBox()) and so don't control message
7295 // dispatching otherwise
7296 class wxIdleWakeUpModule
: public wxModule
7299 virtual bool OnInit()
7301 ms_hMsgHookProc
= ::SetWindowsHookEx
7304 &wxIdleWakeUpModule::MsgHookProc
,
7306 GetCurrentThreadId()
7309 if ( !ms_hMsgHookProc
)
7311 wxLogLastError(wxT("SetWindowsHookEx(WH_GETMESSAGE)"));
7319 virtual void OnExit()
7321 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
7324 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
7326 MSG
*msg
= (MSG
*)lParam
;
7328 // only process the message if it is actually going to be removed from
7329 // the message queue, this prevents that the same event from being
7330 // processed multiple times if now someone just called PeekMessage()
7331 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
7333 wxTheApp
->ProcessPendingEvents();
7336 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
7340 static HHOOK ms_hMsgHookProc
;
7342 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
7345 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
7347 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
7349 #endif // __WXWINCE__
7354 static void wxAdjustZOrder(wxWindow
* parent
)
7356 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
7358 // Set the z-order correctly
7359 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
7362 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
7365 wxWindow
*childWin
= current
->GetData();
7366 wxAdjustZOrder(childWin
);
7367 current
= current
->GetNext();
7372 // We need to adjust the z-order of static boxes in WinCE, to
7373 // make 'contained' controls visible
7374 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
7377 wxAdjustZOrder(this);