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/dcclient.h"
85 #include "wx/tooltip.h"
93 #include "wx/spinctrl.h"
94 #endif // wxUSE_SPINCTRL
96 #include "wx/notebook.h"
97 #include "wx/listctrl.h"
98 #include "wx/dynlib.h"
102 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
103 #include <shellapi.h>
104 #include <mmsystem.h>
108 #include <windowsx.h>
111 #if !defined __WXWINCE__ && !defined NEED_PBT_H
115 #if defined(__WXWINCE__)
116 #include "wx/msw/wince/missing.h"
119 #include <shellapi.h>
121 #include <aygshell.h>
126 #include "wx/msw/uxtheme.h"
127 #define EP_EDITTEXT 1
130 #define ETS_SELECTED 3
131 #define ETS_DISABLED 4
132 #define ETS_FOCUSED 5
133 #define ETS_READONLY 6
137 // define the constants used by AnimateWindow() if our SDK doesn't have them
139 #define AW_HOR_POSITIVE 0x00000001
140 #define AW_HOR_NEGATIVE 0x00000002
141 #define AW_VER_POSITIVE 0x00000004
142 #define AW_VER_NEGATIVE 0x00000008
143 #define AW_CENTER 0x00000010
144 #define AW_HIDE 0x00010000
145 #define AW_ACTIVATE 0x00020000
146 #define AW_SLIDE 0x00040000
147 #define AW_BLEND 0x00080000
150 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS
151 #define HAVE_TRACKMOUSEEVENT
152 #endif // everything needed for TrackMouseEvent()
154 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
155 // when mouse position didnd't change
157 #define wxUSE_MOUSEEVENT_HACK 0
159 #define wxUSE_MOUSEEVENT_HACK 1
162 // not all compilers/platforms have X button related declarations (notably
163 // Windows CE doesn't, and probably some old SDKs don't neither)
164 #ifdef WM_XBUTTONDOWN
165 #define wxHAS_XBUTTON
168 // ---------------------------------------------------------------------------
170 // ---------------------------------------------------------------------------
172 #if wxUSE_MENUS_NATIVE
173 extern wxMenu
*wxCurrentPopupMenu
;
179 // true if we had already created the std colour map, used by
180 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
181 bool gs_hasStdCmap
= false;
183 // last mouse event information we need to filter out the duplicates
184 #if wxUSE_MOUSEEVENT_HACK
185 struct MouseEventInfoDummy
187 // mouse position (in screen coordinates)
190 // last mouse event type
193 #endif // wxUSE_MOUSEEVENT_HACK
195 // hash containing the registered handlers for the custom messages
196 WX_DECLARE_HASH_MAP(int, wxWindow::MSWMessageHandler
,
197 wxIntegerHash
, wxIntegerEqual
,
200 MSWMessageHandlers gs_messageHandlers
;
202 // hash containing all our windows, it uses HWND keys and wxWindow* values
203 WX_DECLARE_HASH_MAP(HWND
, wxWindow
*,
204 wxPointerHash
, wxPointerEqual
,
207 WindowHandles gs_windowHandles
;
209 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
211 // temporary override for WM_ERASEBKGND processing: we don't store this in
212 // wxWindow itself as we don't need it during most of the time so don't
213 // increase the size of all window objects unnecessarily
214 WX_DECLARE_HASH_MAP(wxWindow
*, wxWindow
*,
215 wxPointerHash
, wxPointerEqual
,
218 EraseBgHooks gs_eraseBgHooks
;
220 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
222 } // anonymous namespace
224 // ---------------------------------------------------------------------------
226 // ---------------------------------------------------------------------------
228 // the window proc for all our windows
229 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
230 WPARAM wParam
, LPARAM lParam
);
233 #if wxDEBUG_LEVEL >= 2
234 const wxChar
*wxGetMessageName(int message
);
235 #endif // wxDEBUG_LEVEL >= 2
237 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
238 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
240 // get the text metrics for the current font
241 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
244 // find the window for the mouse event at the specified position
245 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
246 #endif // __WXWINCE__
248 // wrapper around BringWindowToTop() API
249 static inline void wxBringWindowToTop(HWND hwnd
)
251 #ifdef __WXMICROWIN__
252 // It seems that MicroWindows brings the _parent_ of the window to the top,
253 // which can be the wrong one.
255 // activate (set focus to) specified window
259 // raise top level parent to top of z order
260 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
262 wxLogLastError(wxT("SetWindowPos"));
268 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
269 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
272 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
273 parent as well as otherwise several Win32 functions using
274 GetNextDlgTabItem() to iterate over all controls such as
275 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
276 all of them iterate over all the controls starting from the currently
277 focused one and stop iterating when they get back to the focus but
278 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
279 get back to the initial (focused) window: as we do have this style,
280 GetNextDlgTabItem() will leave this window and continue in its parent,
281 but if the parent doesn't have it, it wouldn't recurse inside it later
282 on and so wouldn't have a chance of getting back to this window either.
284 while ( parent
&& !parent
->IsTopLevel() )
286 LONG exStyle
= wxGetWindowExStyle(parent
);
287 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
289 // force the parent to have this style
290 wxSetWindowExStyle(parent
, exStyle
| WS_EX_CONTROLPARENT
);
293 parent
= parent
->GetParent();
297 #endif // !__WXWINCE__
300 // On Windows CE, GetCursorPos can return an error, so use this function
302 bool GetCursorPosWinCE(POINT
* pt
)
304 if (!GetCursorPos(pt
))
306 DWORD pos
= GetMessagePos();
314 // ---------------------------------------------------------------------------
316 // ---------------------------------------------------------------------------
318 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
320 #ifdef __WXUNIVERSAL__
321 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
323 #if wxUSE_EXTENDED_RTTI
325 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
326 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
327 // windows with negative ids never can be recreated anyway
329 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
331 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
332 if ( win
&& win
->GetId() < 0 )
337 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
339 // make wxWindowList known before the property is used
341 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
343 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
345 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
348 WX_DEFINE_FLAGS( wxWindowStyle
)
350 wxBEGIN_FLAGS( wxWindowStyle
)
351 // new style border flags, we put them first to
352 // use them for streaming out
354 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
355 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
356 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
357 wxFLAGS_MEMBER(wxBORDER_RAISED
)
358 wxFLAGS_MEMBER(wxBORDER_STATIC
)
359 wxFLAGS_MEMBER(wxBORDER_NONE
)
361 // old style border flags
362 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
363 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
364 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
365 wxFLAGS_MEMBER(wxRAISED_BORDER
)
366 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
367 wxFLAGS_MEMBER(wxBORDER
)
369 // standard window styles
370 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
371 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
372 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
373 wxFLAGS_MEMBER(wxWANTS_CHARS
)
374 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
375 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
376 wxFLAGS_MEMBER(wxVSCROLL
)
377 wxFLAGS_MEMBER(wxHSCROLL
)
379 wxEND_FLAGS( wxWindowStyle
)
381 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
382 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
383 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
384 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
385 // Always constructor Properties first
387 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
388 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
389 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
390 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
391 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
393 // Then all relations of the object graph
395 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
397 // and finally all other properties
399 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
400 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
401 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
402 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
403 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
405 // possible property candidates (not in xrc) or not valid in all subclasses
406 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
407 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
408 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
409 // MaxHeight, Width , MinHeight , Width
410 // TODO switch label to control and title to toplevels
412 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
413 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
414 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
415 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
420 wxEND_PROPERTIES_TABLE()
422 wxBEGIN_HANDLERS_TABLE(wxWindow
)
423 wxEND_HANDLERS_TABLE()
425 wxCONSTRUCTOR_DUMMY(wxWindow
)
428 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
430 #endif // __WXUNIVERSAL__/__WXMSW__
432 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
433 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
435 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
439 // ===========================================================================
441 // ===========================================================================
443 // ---------------------------------------------------------------------------
444 // wxWindow utility functions
445 // ---------------------------------------------------------------------------
447 // Find an item given the MS Windows id
448 wxWindow
*wxWindowMSW::FindItem(long id
) const
451 wxControl
*item
= wxDynamicCastThis(wxControl
);
454 // is it us or one of our "internal" children?
455 if ( item
->GetId() == id
456 #ifndef __WXUNIVERSAL__
457 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
458 #endif // __WXUNIVERSAL__
464 #endif // wxUSE_CONTROLS
466 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
469 wxWindow
*childWin
= current
->GetData();
471 wxWindow
*wnd
= childWin
->FindItem(id
);
475 current
= current
->GetNext();
481 // Find an item given the MS Windows handle
482 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
484 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
487 wxWindow
*parent
= current
->GetData();
489 // Do a recursive search.
490 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
496 || parent
->IsKindOf(CLASSINFO(wxControl
))
497 #endif // wxUSE_CONTROLS
500 wxWindow
*item
= current
->GetData();
501 if ( item
->GetHWND() == hWnd
)
505 if ( item
->ContainsHWND(hWnd
) )
510 current
= current
->GetNext();
515 // Default command handler
516 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
521 // ----------------------------------------------------------------------------
522 // constructors and such
523 // ----------------------------------------------------------------------------
525 void wxWindowMSW::Init()
529 m_mouseInWindow
= false;
530 m_lastKeydownProcessed
= false;
537 #if wxUSE_DEFERRED_SIZING
539 m_pendingPosition
= wxDefaultPosition
;
540 m_pendingSize
= wxDefaultSize
;
541 #endif // wxUSE_DEFERRED_SIZING
544 m_contextMenuEnabled
= false;
549 wxWindowMSW::~wxWindowMSW()
553 #ifndef __WXUNIVERSAL__
554 // VS: make sure there's no wxFrame with last focus set to us:
555 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
557 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
560 if ( frame
->GetLastFocus() == this )
562 frame
->SetLastFocus(NULL
);
565 // apparently sometimes we can end up with our grand parent
566 // pointing to us as well: this is surely a bug in focus handling
567 // code but it's not clear where it happens so for now just try to
568 // fix it here by not breaking out of the loop
572 #endif // __WXUNIVERSAL__
574 // VS: destroy children first and _then_ detach *this from its parent.
575 // If we did it the other way around, children wouldn't be able
576 // find their parent frame (see above).
581 // VZ: test temp removed to understand what really happens here
582 //if (::IsWindow(GetHwnd()))
584 if ( !::DestroyWindow(GetHwnd()) )
586 wxLogLastError(wxT("DestroyWindow"));
590 // remove hWnd <-> wxWindow association
591 wxRemoveHandleAssociation(this);
597 const wxChar
*wxWindowMSW::MSWGetRegisteredClassName()
599 return wxApp::GetRegisteredClassName(wxT("wxWindow"), COLOR_BTNFACE
);
602 // real construction (Init() must have been called before!)
603 bool wxWindowMSW::Create(wxWindow
*parent
,
608 const wxString
& name
)
610 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
612 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
615 parent
->AddChild(this);
618 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
620 #ifdef __WXUNIVERSAL__
621 // no borders, we draw them ourselves
622 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
626 msflags
&= ~WS_BORDER
;
627 #endif // wxUniversal
631 msflags
|= WS_VISIBLE
;
634 if ( !MSWCreate(MSWGetRegisteredClassName(),
635 NULL
, pos
, size
, msflags
, exstyle
) )
643 // ---------------------------------------------------------------------------
645 // ---------------------------------------------------------------------------
647 void wxWindowMSW::SetFocus()
649 HWND hWnd
= GetHwnd();
650 wxCHECK_RET( hWnd
, wxT("can't set focus to invalid window") );
652 #if !defined(__WXWINCE__)
656 if ( !::SetFocus(hWnd
) )
658 // was there really an error?
659 DWORD dwRes
= ::GetLastError();
662 HWND hwndFocus
= ::GetFocus();
663 if ( hwndFocus
!= hWnd
)
665 wxLogApiError(wxT("SetFocus"), dwRes
);
671 void wxWindowMSW::SetFocusFromKbd()
673 // when the focus is given to the control with DLGC_HASSETSEL style from
674 // keyboard its contents should be entirely selected: this is what
675 // ::IsDialogMessage() does and so we should do it as well to provide the
676 // same LNF as the native programs
677 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
679 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
682 // do this after (maybe) setting the selection as like this when
683 // wxEVT_SET_FOCUS handler is called, the selection would have been already
684 // set correctly -- this may be important
685 wxWindowBase::SetFocusFromKbd();
688 // Get the window with the focus
689 wxWindow
*wxWindowBase::DoFindFocus()
691 HWND hWnd
= ::GetFocus();
694 return wxGetWindowFromHWND((WXHWND
)hWnd
);
700 void wxWindowMSW::DoEnable( bool enable
)
702 HWND hWnd
= GetHwnd();
704 ::EnableWindow(hWnd
, (BOOL
)enable
);
707 bool wxWindowMSW::Show(bool show
)
709 if ( !wxWindowBase::Show(show
) )
712 HWND hWnd
= GetHwnd();
714 // we could be called before the underlying window is created (this is
715 // actually useful to prevent it from being initially shown), e.g.
717 // wxFoo *foo = new wxFoo;
719 // foo->Create(parent, ...);
721 // should work without errors
724 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
729 // DoFreeze/DoThaw don't do anything if the window is not shown, so
730 // we have to call them from here now
741 wxWindowMSW::MSWShowWithEffect(bool show
,
745 if ( effect
== wxSHOW_EFFECT_NONE
)
748 if ( !wxWindowBase::Show(show
) )
751 typedef BOOL (WINAPI
*AnimateWindow_t
)(HWND
, DWORD
, DWORD
);
753 static AnimateWindow_t s_pfnAnimateWindow
= NULL
;
754 static bool s_initDone
= false;
757 wxDynamicLibrary
dllUser32(wxT("user32.dll"), wxDL_VERBATIM
| wxDL_QUIET
);
758 wxDL_INIT_FUNC(s_pfn
, AnimateWindow
, dllUser32
);
762 // notice that it's ok to unload user32.dll here as it won't be really
763 // unloaded, being still in use because we link to it statically too
766 if ( !s_pfnAnimateWindow
)
769 // Show() has a side effect of sending a WM_SIZE to the window, which helps
770 // ensuring that it's laid out correctly, but AnimateWindow() doesn't do
771 // this so send the event ourselves
774 // prepare to use AnimateWindow()
777 timeout
= 200; // this is the default animation timeout, per MSDN
779 DWORD dwFlags
= show
? 0 : AW_HIDE
;
783 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
784 dwFlags
|= AW_HOR_NEGATIVE
;
787 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
788 dwFlags
|= AW_HOR_POSITIVE
;
791 case wxSHOW_EFFECT_ROLL_TO_TOP
:
792 dwFlags
|= AW_VER_NEGATIVE
;
795 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
796 dwFlags
|= AW_VER_POSITIVE
;
799 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
800 dwFlags
|= AW_SLIDE
| AW_HOR_NEGATIVE
;
803 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
804 dwFlags
|= AW_SLIDE
| AW_HOR_POSITIVE
;
807 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
808 dwFlags
|= AW_SLIDE
| AW_VER_NEGATIVE
;
811 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
812 dwFlags
|= AW_SLIDE
| AW_VER_POSITIVE
;
815 case wxSHOW_EFFECT_BLEND
:
819 case wxSHOW_EFFECT_EXPAND
:
820 dwFlags
|= AW_CENTER
;
824 case wxSHOW_EFFECT_MAX
:
825 wxFAIL_MSG( wxT("invalid window show effect") );
829 wxFAIL_MSG( wxT("unknown window show effect") );
833 if ( !(*s_pfnAnimateWindow
)(GetHwnd(), timeout
, dwFlags
) )
835 wxLogLastError(wxT("AnimateWindow"));
843 // Raise the window to the top of the Z order
844 void wxWindowMSW::Raise()
846 wxBringWindowToTop(GetHwnd());
849 // Lower the window to the bottom of the Z order
850 void wxWindowMSW::Lower()
852 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
853 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
856 void wxWindowMSW::DoCaptureMouse()
858 HWND hWnd
= GetHwnd();
865 void wxWindowMSW::DoReleaseMouse()
867 if ( !::ReleaseCapture() )
869 wxLogLastError(wxT("ReleaseCapture"));
873 /* static */ wxWindow
*wxWindowBase::GetCapture()
875 HWND hwnd
= ::GetCapture();
876 return hwnd
? wxFindWinFromHandle(hwnd
) : NULL
;
879 bool wxWindowMSW::SetFont(const wxFont
& font
)
881 if ( !wxWindowBase::SetFont(font
) )
887 HWND hWnd
= GetHwnd();
890 // note the use of GetFont() instead of m_font: our own font could have
891 // just been reset and in this case we need to change the font used by
892 // the native window to the default for this class, i.e. exactly what
894 WXHANDLE hFont
= GetFont().GetResourceHandle();
896 wxASSERT_MSG( hFont
, wxT("should have valid font") );
898 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
903 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
905 if ( !wxWindowBase::SetCursor(cursor
) )
911 // don't "overwrite" busy cursor
912 if ( m_cursor
.Ok() && !wxIsBusy() )
914 // normally we should change the cursor only if it's over this window
915 // but we should do it always if we capture the mouse currently
916 bool set
= HasCapture();
919 HWND hWnd
= GetHwnd();
923 ::GetCursorPosWinCE(&point
);
925 ::GetCursorPos(&point
);
928 RECT rect
= wxGetWindowRect(hWnd
);
930 set
= ::PtInRect(&rect
, point
) != 0;
935 ::SetCursor(GetHcursorOf(m_cursor
));
937 //else: will be set later when the mouse enters this window
943 void wxWindowMSW::WarpPointer(int x
, int y
)
945 ClientToScreen(&x
, &y
);
947 if ( !::SetCursorPos(x
, y
) )
949 wxLogLastError(wxT("SetCursorPos"));
953 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
955 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
956 // to use it on older systems -- and could possibly do some harm
957 static int s_needToUpdate
= -1;
958 if ( s_needToUpdate
== -1 )
961 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
965 if ( s_needToUpdate
)
967 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
968 // won't send WM_UPDATEUISTATE
969 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
973 // ---------------------------------------------------------------------------
975 // ---------------------------------------------------------------------------
980 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
982 #ifdef __WXMICROWIN__
983 return ::GetScrollPosWX(hWnd
, wOrient
);
985 WinStruct
<SCROLLINFO
> scrollInfo
;
986 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
987 scrollInfo
.fMask
= SIF_POS
;
988 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
990 return scrollInfo
.nPos
;
995 inline UINT
WXOrientToSB(int orient
)
997 return orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
;
1000 } // anonymous namespace
1002 int wxWindowMSW::GetScrollPos(int orient
) const
1004 HWND hWnd
= GetHwnd();
1005 wxCHECK_MSG( hWnd
, 0, wxT("no HWND in GetScrollPos") );
1007 return GetScrollPosition(hWnd
, WXOrientToSB(orient
));
1010 // This now returns the whole range, not just the number
1011 // of positions that we can scroll.
1012 int wxWindowMSW::GetScrollRange(int orient
) const
1015 HWND hWnd
= GetHwnd();
1018 WinStruct
<SCROLLINFO
> scrollInfo
;
1019 scrollInfo
.fMask
= SIF_RANGE
;
1020 if ( !::GetScrollInfo(hWnd
, WXOrientToSB(orient
), &scrollInfo
) )
1022 // Most of the time this is not really an error, since the return
1023 // value can also be zero when there is no scrollbar yet.
1024 // wxLogLastError(wxT("GetScrollInfo"));
1026 maxPos
= scrollInfo
.nMax
;
1028 // undo "range - 1" done in SetScrollbar()
1032 int wxWindowMSW::GetScrollThumb(int orient
) const
1034 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
1037 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
1039 HWND hWnd
= GetHwnd();
1040 wxCHECK_RET( hWnd
, wxT("SetScrollPos: no HWND") );
1042 WinStruct
<SCROLLINFO
> info
;
1046 info
.fMask
= SIF_POS
;
1047 if ( HasFlag(wxALWAYS_SHOW_SB
) )
1049 // disable scrollbar instead of removing it then
1050 info
.fMask
|= SIF_DISABLENOSCROLL
;
1053 ::SetScrollInfo(hWnd
, WXOrientToSB(orient
), &info
, refresh
);
1056 // New function that will replace some of the above.
1057 void wxWindowMSW::SetScrollbar(int orient
,
1063 // We have to set the variables here to make them valid in events
1064 // triggered by ::SetScrollInfo()
1065 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
1067 HWND hwnd
= GetHwnd();
1071 WinStruct
<SCROLLINFO
> info
;
1074 info
.nPage
= pageSize
;
1075 info
.nMin
= 0; // range is nMax - nMin + 1
1076 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
1079 // We normally also reenable scrollbar in case it had been previously
1080 // disabled by specifying SIF_DISABLENOSCROLL below but we should only
1081 // do this if it has valid range, otherwise it would be enabled but not
1083 if ( range
>= pageSize
)
1085 ::EnableScrollBar(hwnd
, WXOrientToSB(orient
), ESB_ENABLE_BOTH
);
1088 //else: leave all the fields to be 0
1090 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
1091 if ( HasFlag(wxALWAYS_SHOW_SB
) || range
== -1 )
1093 // disable scrollbar instead of removing it then
1094 info
.fMask
|= SIF_DISABLENOSCROLL
;
1097 ::SetScrollInfo(hwnd
, WXOrientToSB(orient
), &info
, refresh
);
1100 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
1106 wxCopyRectToRECT(*prect
, rect
);
1116 // FIXME: is this the exact equivalent of the line below?
1117 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
1119 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
1123 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
1125 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
1128 for ( int n
= 0; n
< count
; n
++ )
1130 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
1132 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
1133 if ( posNew
== pos
)
1135 // don't bother to continue, we're already at top/bottom
1142 return pos
!= posStart
;
1145 bool wxWindowMSW::ScrollLines(int lines
)
1147 bool down
= lines
> 0;
1149 return ScrollVertically(GetHwnd(),
1150 down
? SB_LINEDOWN
: SB_LINEUP
,
1151 down
? lines
: -lines
);
1154 bool wxWindowMSW::ScrollPages(int pages
)
1156 bool down
= pages
> 0;
1158 return ScrollVertically(GetHwnd(),
1159 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1160 down
? pages
: -pages
);
1163 // ----------------------------------------------------------------------------
1165 // ----------------------------------------------------------------------------
1167 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
1172 wxCHECK_RET( GetHwnd(),
1173 wxT("layout direction must be set after window creation") );
1175 LONG styleOld
= wxGetWindowExStyle(this);
1177 LONG styleNew
= styleOld
;
1180 case wxLayout_LeftToRight
:
1181 styleNew
&= ~WS_EX_LAYOUTRTL
;
1184 case wxLayout_RightToLeft
:
1185 styleNew
|= WS_EX_LAYOUTRTL
;
1189 wxFAIL_MSG(wxT("unsupported layout direction"));
1193 if ( styleNew
!= styleOld
)
1195 wxSetWindowExStyle(this, styleNew
);
1200 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1203 return wxLayout_Default
;
1205 wxCHECK_MSG( GetHwnd(), wxLayout_Default
, wxT("invalid window") );
1207 return wxHasWindowExStyle(this, WS_EX_LAYOUTRTL
) ? wxLayout_RightToLeft
1208 : wxLayout_LeftToRight
;
1213 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1214 wxCoord
WXUNUSED(width
),
1215 wxCoord
WXUNUSED(widthTotal
)) const
1217 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1218 // redo it ourselves
1222 // ---------------------------------------------------------------------------
1224 // ---------------------------------------------------------------------------
1226 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1228 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1230 HWND hwnd
= (HWND
)hWnd
;
1231 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1235 wxAssociateWinWithHandle(hwnd
, this);
1237 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1239 // we don't need to subclass the window of our own class (in the Windows
1240 // sense of the word)
1241 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1243 wxSetWindowProc(hwnd
, wxWndProc
);
1247 // don't bother restoring it either: this also makes it easy to
1248 // implement IsOfStandardClass() method which returns true for the
1249 // standard controls and false for the wxWidgets own windows as it can
1250 // simply check m_oldWndProc
1251 m_oldWndProc
= NULL
;
1254 // we're officially created now, send the event
1255 wxWindowCreateEvent
event((wxWindow
*)this);
1256 (void)HandleWindowEvent(event
);
1259 void wxWindowMSW::UnsubclassWin()
1261 wxRemoveHandleAssociation(this);
1263 // Restore old Window proc
1264 HWND hwnd
= GetHwnd();
1269 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1273 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1275 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1278 m_oldWndProc
= NULL
;
1283 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1287 if ( !::DestroyWindow(GetHwnd()) )
1289 wxLogLastError(wxT("DestroyWindow"));
1293 WXHWND wxhwnd
= (WXHWND
)handle
;
1295 // this also calls SetHWND(wxhwnd)
1296 SubclassWin(wxhwnd
);
1299 void wxWindowMSW::DissociateHandle()
1301 // this also calls SetHWND(0) for us
1306 bool wxCheckWindowWndProc(WXHWND hWnd
,
1307 WXFARPROC
WXUNUSED(wndProc
))
1309 const wxString
str(wxGetWindowClass(hWnd
));
1311 // TODO: get rid of wxTLWHiddenParent special case (currently it's not
1312 // registered by wxApp but using ad hoc code in msw/toplevel.cpp);
1313 // there is also a hidden window class used by sockets &c
1314 return wxApp::IsRegisteredClassName(str
) || str
== wxT("wxTLWHiddenParent");
1317 // ----------------------------------------------------------------------------
1319 // ----------------------------------------------------------------------------
1321 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1323 long flagsOld
= GetWindowStyleFlag();
1324 if ( flags
== flagsOld
)
1327 // update the internal variable
1328 wxWindowBase::SetWindowStyleFlag(flags
);
1330 // and the real window flags
1331 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1334 void wxWindowMSW::SetExtraStyle(long exflags
)
1336 long exflagsOld
= GetExtraStyle();
1337 if ( exflags
== exflagsOld
)
1340 // update the internal variable
1341 wxWindowBase::SetExtraStyle(exflags
);
1343 // and the real window flags
1344 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1347 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1349 // now update the Windows style as well if needed - and if the window had
1350 // been already created
1354 // we may need to call SetWindowPos() when we change some styles
1355 bool callSWP
= false;
1358 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1360 // this is quite a horrible hack but we need it because MSWGetStyle()
1361 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1362 // and so we have to modify the window exflags temporarily to get the
1363 // correct exstyleOld
1364 long exflagsNew
= GetExtraStyle();
1365 wxWindowBase::SetExtraStyle(exflagsOld
);
1368 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1370 wxWindowBase::SetExtraStyle(exflagsNew
);
1373 if ( style
!= styleOld
)
1375 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1376 // this function so instead of simply setting the style to the new
1377 // value we clear the bits which were set in styleOld but are set in
1378 // the new one and set the ones which were not set before
1379 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1380 styleReal
&= ~styleOld
;
1383 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1385 // we need to call SetWindowPos() if any of the styles affecting the
1386 // frame appearance have changed
1387 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1396 // and the extended style
1397 long exstyleReal
= wxGetWindowExStyle(this);
1399 if ( exstyle
!= exstyleOld
)
1401 exstyleReal
&= ~exstyleOld
;
1402 exstyleReal
|= exstyle
;
1404 wxSetWindowExStyle(this, exstyleReal
);
1406 // ex style changes don't take effect without calling SetWindowPos
1412 // we must call SetWindowPos() to flush the cached extended style and
1413 // also to make the change to wxSTAY_ON_TOP style take effect: just
1414 // setting the style simply doesn't work
1415 if ( !::SetWindowPos(GetHwnd(),
1416 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1419 SWP_NOMOVE
| SWP_NOSIZE
| SWP_FRAMECHANGED
) )
1421 wxLogLastError(wxT("SetWindowPos"));
1426 wxBorder
wxWindowMSW::GetDefaultBorderForControl() const
1428 return wxBORDER_THEME
;
1431 wxBorder
wxWindowMSW::GetDefaultBorder() const
1433 return wxWindowBase::GetDefaultBorder();
1436 // Translate wxBORDER_THEME (and other border styles if necessary) to the value
1437 // that makes most sense for this Windows environment
1438 wxBorder
wxWindowMSW::TranslateBorder(wxBorder border
) const
1440 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
1441 if (border
== wxBORDER_THEME
|| border
== wxBORDER_SUNKEN
|| border
== wxBORDER_SIMPLE
)
1442 return wxBORDER_SIMPLE
;
1444 return wxBORDER_NONE
;
1447 if (border
== wxBORDER_THEME
)
1449 if (CanApplyThemeBorder())
1451 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
1453 return wxBORDER_THEME
;
1455 return wxBORDER_SUNKEN
;
1463 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1465 // translate common wxWidgets styles to Windows ones
1467 // most of windows are child ones, those which are not (such as
1468 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1469 WXDWORD style
= WS_CHILD
;
1471 // using this flag results in very significant reduction in flicker,
1472 // especially with controls inside the static boxes (as the interior of the
1473 // box is not redrawn twice), but sometimes results in redraw problems, so
1474 // optionally allow the old code to continue to use it provided a special
1475 // system option is turned on
1476 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1477 || (flags
& wxCLIP_CHILDREN
) )
1478 style
|= WS_CLIPCHILDREN
;
1480 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1481 // don't support overlapping windows and it only makes sense for them and,
1482 // presumably, gives the system some extra work (to manage more clipping
1483 // regions), so avoid it alltogether
1486 if ( flags
& wxVSCROLL
)
1487 style
|= WS_VSCROLL
;
1489 if ( flags
& wxHSCROLL
)
1490 style
|= WS_HSCROLL
;
1492 const wxBorder border
= TranslateBorder(GetBorder(flags
));
1494 // After translation, border is now optimized for the specific version of Windows
1495 // and theme engine presence.
1497 // WS_BORDER is only required for wxBORDER_SIMPLE
1498 if ( border
== wxBORDER_SIMPLE
)
1501 // now deal with ext style if the caller wants it
1507 if ( flags
& wxTRANSPARENT_WINDOW
)
1508 *exstyle
|= WS_EX_TRANSPARENT
;
1514 case wxBORDER_DEFAULT
:
1515 wxFAIL_MSG( wxT("unknown border style") );
1519 case wxBORDER_SIMPLE
:
1520 case wxBORDER_THEME
:
1523 case wxBORDER_STATIC
:
1524 *exstyle
|= WS_EX_STATICEDGE
;
1527 case wxBORDER_RAISED
:
1528 *exstyle
|= WS_EX_DLGMODALFRAME
;
1531 case wxBORDER_SUNKEN
:
1532 *exstyle
|= WS_EX_CLIENTEDGE
;
1533 style
&= ~WS_BORDER
;
1536 // case wxBORDER_DOUBLE:
1537 // *exstyle |= WS_EX_DLGMODALFRAME;
1541 // wxUniv doesn't use Windows dialog navigation functions at all
1542 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1543 // to make the dialog navigation work with the nested panels we must
1544 // use this style (top level windows such as dialogs don't need it)
1545 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1547 *exstyle
|= WS_EX_CONTROLPARENT
;
1549 #endif // __WXUNIVERSAL__
1555 // Setup background and foreground colours correctly
1556 void wxWindowMSW::SetupColours()
1559 SetBackgroundColour(GetParent()->GetBackgroundColour());
1562 bool wxWindowMSW::IsMouseInWindow() const
1564 // get the mouse position
1567 ::GetCursorPosWinCE(&pt
);
1569 ::GetCursorPos(&pt
);
1572 // find the window which currently has the cursor and go up the window
1573 // chain until we find this window - or exhaust it
1574 HWND hwnd
= ::WindowFromPoint(pt
);
1575 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1576 hwnd
= ::GetParent(hwnd
);
1578 return hwnd
!= NULL
;
1581 void wxWindowMSW::OnInternalIdle()
1583 #ifndef HAVE_TRACKMOUSEEVENT
1584 // Check if we need to send a LEAVE event
1585 if ( m_mouseInWindow
)
1587 // note that we should generate the leave event whether the window has
1588 // or doesn't have mouse capture
1589 if ( !IsMouseInWindow() )
1591 GenerateMouseLeave();
1594 #endif // !HAVE_TRACKMOUSEEVENT
1596 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1597 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1600 // Set this window to be the child of 'parent'.
1601 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1603 if ( !wxWindowBase::Reparent(parent
) )
1606 HWND hWndChild
= GetHwnd();
1607 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1609 ::SetParent(hWndChild
, hWndParent
);
1612 if ( wxHasWindowExStyle(this, WS_EX_CONTROLPARENT
) )
1614 EnsureParentHasControlParentStyle(GetParent());
1616 #endif // !__WXWINCE__
1621 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1623 #ifndef __WXMICROWIN__
1624 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1628 void wxWindowMSW::DoFreeze()
1631 return; // no point in freezing hidden window
1633 SendSetRedraw(GetHwnd(), false);
1636 void wxWindowMSW::DoThaw()
1639 return; // hidden windows aren't frozen by DoFreeze
1641 SendSetRedraw(GetHwnd(), true);
1643 // we need to refresh everything or otherwise the invalidated area
1644 // is not going to be repainted
1648 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1650 HWND hWnd
= GetHwnd();
1657 wxCopyRectToRECT(*rect
, mswRect
);
1665 // RedrawWindow not available on SmartPhone or eVC++ 3
1666 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1667 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1671 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1673 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1678 void wxWindowMSW::Update()
1680 if ( !::UpdateWindow(GetHwnd()) )
1682 wxLogLastError(wxT("UpdateWindow"));
1685 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1686 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1687 // handler needs to be really drawn right now
1692 // ---------------------------------------------------------------------------
1694 // ---------------------------------------------------------------------------
1696 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1700 // we need to lower the sibling static boxes so controls contained within can be
1702 static void AdjustStaticBoxZOrder(wxWindow
*parent
)
1704 // no sibling static boxes if we have no parent (ie TLW)
1708 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1710 node
= node
->GetNext() )
1712 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1715 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1716 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1721 #else // !wxUSE_STATBOX
1723 static inline void AdjustStaticBoxZOrder(wxWindow
* WXUNUSED(parent
))
1727 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1729 #endif // drag and drop is used
1731 #if wxUSE_DRAG_AND_DROP
1732 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1734 if ( m_dropTarget
!= 0 ) {
1735 m_dropTarget
->Revoke(m_hWnd
);
1736 delete m_dropTarget
;
1739 m_dropTarget
= pDropTarget
;
1740 if ( m_dropTarget
!= 0 )
1742 AdjustStaticBoxZOrder(GetParent());
1743 m_dropTarget
->Register(m_hWnd
);
1746 #endif // wxUSE_DRAG_AND_DROP
1748 // old-style file manager drag&drop support: we retain the old-style
1749 // DragAcceptFiles in parallel with SetDropTarget.
1750 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1753 HWND hWnd
= GetHwnd();
1756 AdjustStaticBoxZOrder(GetParent());
1757 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1762 // ----------------------------------------------------------------------------
1764 // ----------------------------------------------------------------------------
1768 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1770 wxWindowBase::DoSetToolTip(tooltip
);
1773 m_tooltip
->SetWindow((wxWindow
*)this);
1776 #endif // wxUSE_TOOLTIPS
1778 // ---------------------------------------------------------------------------
1779 // moving and resizing
1780 // ---------------------------------------------------------------------------
1782 bool wxWindowMSW::IsSizeDeferred() const
1784 #if wxUSE_DEFERRED_SIZING
1785 if ( m_pendingPosition
!= wxDefaultPosition
||
1786 m_pendingSize
!= wxDefaultSize
)
1788 #endif // wxUSE_DEFERRED_SIZING
1794 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1796 #if wxUSE_DEFERRED_SIZING
1797 // if SetSize() had been called at wx level but not realized at Windows
1798 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1799 // the new and not the old position to the other wx code
1800 if ( m_pendingSize
!= wxDefaultSize
)
1803 *x
= m_pendingSize
.x
;
1805 *y
= m_pendingSize
.y
;
1807 else // use current size
1808 #endif // wxUSE_DEFERRED_SIZING
1810 RECT rect
= wxGetWindowRect(GetHwnd());
1813 *x
= rect
.right
- rect
.left
;
1815 *y
= rect
.bottom
- rect
.top
;
1819 // Get size *available for subwindows* i.e. excluding menu bar etc.
1820 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1822 #if wxUSE_DEFERRED_SIZING
1823 if ( m_pendingSize
!= wxDefaultSize
)
1825 // we need to calculate the client size corresponding to pending size
1827 // FIXME: Unfortunately this doesn't work correctly for the maximized
1828 // top level windows, the returned values are too small (e.g.
1829 // under Windows 7 on a 1600*1200 screen with task bar on the
1830 // right the pending size for a maximized window is 1538*1200
1831 // and WM_NCCALCSIZE returns 1528*1172 even though the correct
1832 // client size of such window is 1538*1182). No idea how to fix
1833 // it though, setting WS_MAXIMIZE in GWL_STYLE before calling
1834 // WM_NCCALCSIZE doesn't help and AdjustWindowRectEx() doesn't
1835 // work in this direction neither. So we just have to live with
1836 // the slightly wrong results and relayout the window when it
1837 // gets finally shown in its maximized state (see #11762).
1839 rect
.left
= m_pendingPosition
.x
;
1840 rect
.top
= m_pendingPosition
.y
;
1841 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1842 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1844 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1847 *x
= rect
.right
- rect
.left
;
1849 *y
= rect
.bottom
- rect
.top
;
1852 #endif // wxUSE_DEFERRED_SIZING
1854 RECT rect
= wxGetClientRect(GetHwnd());
1863 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1865 wxWindow
* const parent
= GetParent();
1868 if ( m_pendingPosition
!= wxDefaultPosition
)
1870 pos
= m_pendingPosition
;
1872 else // use current position
1874 RECT rect
= wxGetWindowRect(GetHwnd());
1877 point
.x
= rect
.left
;
1880 // we do the adjustments with respect to the parent only for the "real"
1881 // children, not for the dialogs/frames
1882 if ( !IsTopLevel() )
1884 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
1886 // In RTL mode, we want the logical left x-coordinate,
1887 // which would be the physical right x-coordinate.
1888 point
.x
= rect
.right
;
1891 // Since we now have the absolute screen coords, if there's a
1892 // parent we must subtract its top left corner
1895 ::ScreenToClient(GetHwndOf(parent
), &point
);
1903 // we also must adjust by the client area offset: a control which is just
1904 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1905 if ( parent
&& !IsTopLevel() )
1907 const wxPoint
pt(parent
->GetClientAreaOrigin());
1918 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1926 ::ScreenToClient(GetHwnd(), &pt
);
1934 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1942 ::ClientToScreen(GetHwnd(), &pt
);
1951 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1953 #if wxUSE_DEFERRED_SIZING
1954 // if our parent had prepared a defer window handle for us, use it (unless
1955 // we are a top level window)
1956 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1958 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1961 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1962 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1965 wxLogLastError(wxT("DeferWindowPos"));
1971 // hdwp must be updated as it may have been changed
1972 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1977 // did deferred move, remember new coordinates of the window as they're
1978 // different from what Windows would return for it
1982 // otherwise (or if deferring failed) move the window in place immediately
1983 #endif // wxUSE_DEFERRED_SIZING
1984 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
1986 wxLogLastError(wxT("MoveWindow"));
1989 // if wxUSE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1990 // ignored otherwise
1994 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1996 // TODO: is this consistent with other platforms?
1997 // Still, negative width or height shouldn't be allowed
2003 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
2005 #if wxUSE_DEFERRED_SIZING
2006 m_pendingPosition
= wxPoint(x
, y
);
2007 m_pendingSize
= wxSize(width
, height
);
2009 else // window was moved immediately, without deferring it
2011 m_pendingPosition
= wxDefaultPosition
;
2012 m_pendingSize
= wxDefaultSize
;
2013 #endif // wxUSE_DEFERRED_SIZING
2017 // set the size of the window: if the dimensions are positive, just use them,
2018 // but if any of them is equal to -1, it means that we must find the value for
2019 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
2020 // which case -1 is a valid value for x and y)
2022 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
2023 // the width/height to best suit our contents, otherwise we reuse the current
2025 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
2027 // get the current size and position...
2028 int currentX
, currentY
;
2029 int currentW
, currentH
;
2031 GetPosition(¤tX
, ¤tY
);
2032 GetSize(¤tW
, ¤tH
);
2034 // ... and don't do anything (avoiding flicker) if it's already ok unless
2035 // we're forced to resize the window
2036 if ( x
== currentX
&& y
== currentY
&&
2037 width
== currentW
&& height
== currentH
&&
2038 !(sizeFlags
& wxSIZE_FORCE
) )
2040 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
2042 wxSizeEvent
event( wxSize(width
,height
), GetId() );
2043 event
.SetEventObject( this );
2044 HandleWindowEvent( event
);
2049 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2051 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2054 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2056 wxSize size
= wxDefaultSize
;
2057 if ( width
== wxDefaultCoord
)
2059 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2061 size
= GetBestSize();
2066 // just take the current one
2071 if ( height
== wxDefaultCoord
)
2073 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2075 if ( size
.x
== wxDefaultCoord
)
2077 size
= GetBestSize();
2079 //else: already called GetBestSize() above
2085 // just take the current one
2090 DoMoveWindow(x
, y
, width
, height
);
2093 void wxWindowMSW::DoSetClientSize(int width
, int height
)
2095 // setting the client size is less obvious than it could have been
2096 // because in the result of changing the total size the window scrollbar
2097 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
2098 // doesn't take neither into account) and so the client size will not be
2099 // correct as the difference between the total and client size changes --
2100 // so we keep changing it until we get it right
2102 // normally this loop shouldn't take more than 3 iterations (usually 1 but
2103 // if scrollbars [dis]appear as the result of the first call, then 2 and it
2104 // may become 3 if the window had 0 size originally and so we didn't
2105 // calculate the scrollbar correction correctly during the first iteration)
2106 // but just to be on the safe side we check for it instead of making it an
2107 // "infinite" loop (i.e. leaving break inside as the only way to get out)
2108 for ( int i
= 0; i
< 4; i
++ )
2111 ::GetClientRect(GetHwnd(), &rectClient
);
2113 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
2114 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
2115 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
2120 // Find the difference between the entire window (title bar and all)
2121 // and the client area; add this to the new client size to move the
2124 ::GetWindowRect(GetHwnd(), &rectWin
);
2126 const int widthWin
= rectWin
.right
- rectWin
.left
,
2127 heightWin
= rectWin
.bottom
- rectWin
.top
;
2129 // MoveWindow positions the child windows relative to the parent, so
2130 // adjust if necessary
2131 if ( !IsTopLevel() )
2133 wxWindow
*parent
= GetParent();
2136 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
2140 // don't call DoMoveWindow() because we want to move window immediately
2141 // and not defer it here as otherwise the value returned by
2142 // GetClient/WindowRect() wouldn't change as the window wouldn't be
2144 if ( !::MoveWindow(GetHwnd(),
2147 width
+ widthWin
- rectClient
.right
,
2148 height
+ heightWin
- rectClient
.bottom
,
2151 wxLogLastError(wxT("MoveWindow"));
2156 wxSize
wxWindowMSW::DoGetBorderSize() const
2159 switch ( GetBorder() )
2161 case wxBORDER_STATIC
:
2162 case wxBORDER_SIMPLE
:
2166 case wxBORDER_SUNKEN
:
2170 case wxBORDER_RAISED
:
2171 case wxBORDER_DOUBLE
:
2176 wxFAIL_MSG( wxT("unknown border style") );
2183 return 2*wxSize(border
, border
);
2186 // ---------------------------------------------------------------------------
2188 // ---------------------------------------------------------------------------
2190 int wxWindowMSW::GetCharHeight() const
2192 return wxGetTextMetrics(this).tmHeight
;
2195 int wxWindowMSW::GetCharWidth() const
2197 // +1 is needed because Windows apparently adds it when calculating the
2198 // dialog units size in pixels
2199 #if wxDIALOG_UNIT_COMPATIBILITY
2200 return wxGetTextMetrics(this).tmAveCharWidth
;
2202 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
2206 void wxWindowMSW::DoGetTextExtent(const wxString
& string
,
2209 int *externalLeading
,
2210 const wxFont
*fontToUse
) const
2212 wxASSERT_MSG( !fontToUse
|| fontToUse
->Ok(),
2213 wxT("invalid font in GetTextExtent()") );
2217 hfontToUse
= GetHfontOf(*fontToUse
);
2219 hfontToUse
= GetHfontOf(GetFont());
2221 WindowHDC
hdc(GetHwnd());
2222 SelectInHDC
selectFont(hdc
, hfontToUse
);
2226 ::GetTextExtentPoint32(hdc
, string
.wx_str(), string
.length(), &sizeRect
);
2227 GetTextMetrics(hdc
, &tm
);
2234 *descent
= tm
.tmDescent
;
2235 if ( externalLeading
)
2236 *externalLeading
= tm
.tmExternalLeading
;
2239 // ---------------------------------------------------------------------------
2241 // ---------------------------------------------------------------------------
2243 #if wxUSE_MENUS_NATIVE
2245 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2246 // immediately, without waiting for the next event loop iteration
2248 // NB: this function should probably be made public later as it can almost
2249 // surely replace wxYield() elsewhere as well
2250 static void wxYieldForCommandsOnly()
2252 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2253 // want to process it here)
2255 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2257 if ( msg
.message
== WM_QUIT
)
2259 // if we retrieved a WM_QUIT, insert back into the message queue.
2260 ::PostQuitMessage(0);
2264 // luckily (as we don't have access to wxEventLoopImpl method from here
2265 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2267 ::TranslateMessage(&msg
);
2268 ::DispatchMessage(&msg
);
2272 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2276 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2278 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2279 x
= mouse
.x
; y
= mouse
.y
;
2282 HWND hWnd
= GetHwnd();
2283 HMENU hMenu
= GetHmenuOf(menu
);
2287 ::ClientToScreen(hWnd
, &point
);
2288 #if defined(__WXWINCE__)
2289 static const UINT flags
= 0;
2290 #else // !__WXWINCE__
2291 UINT flags
= TPM_RIGHTBUTTON
;
2292 // NT4 doesn't support TPM_RECURSE and simply doesn't show the menu at all
2293 // when it's use, I'm not sure about Win95/98 but prefer to err on the safe
2294 // side and not to use it there neither -- modify the test if it does work
2296 if ( wxGetWinVersion() >= wxWinVersion_5
)
2298 // using TPM_RECURSE allows us to show a popup menu while another menu
2299 // is opened which can be useful and is supported by the other
2300 // platforms, so allow it under Windows too
2301 flags
|= TPM_RECURSE
;
2303 #endif // __WXWINCE__/!__WXWINCE__
2305 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2307 // we need to do it right now as otherwise the events are never going to be
2308 // sent to wxCurrentPopupMenu from HandleCommand()
2310 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2311 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2312 // destroyed as soon as we return (it can be a local variable in the caller
2313 // for example) and so we do need to process the event immediately
2314 wxYieldForCommandsOnly();
2319 #endif // wxUSE_MENUS_NATIVE
2321 // ===========================================================================
2322 // pre/post message processing
2323 // ===========================================================================
2325 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2328 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2330 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2333 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2335 // wxUniversal implements tab traversal itself
2336 #ifndef __WXUNIVERSAL__
2337 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2339 // intercept dialog navigation keys
2340 MSG
*msg
= (MSG
*)pMsg
;
2342 // here we try to do all the job which ::IsDialogMessage() usually does
2344 if ( msg
->message
== WM_KEYDOWN
)
2346 bool bCtrlDown
= wxIsCtrlDown();
2347 bool bShiftDown
= wxIsShiftDown();
2349 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2350 // don't process it if it's the case (except for Ctrl-Tab/Enter
2351 // combinations which are always processed)
2352 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2354 // surprisingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2355 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2356 // it, of course, implies them
2357 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2359 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2362 bool bForward
= true,
2363 bWindowChange
= false,
2366 // should we process this message specially?
2367 bool bProcess
= true;
2368 switch ( msg
->wParam
)
2371 if ( (lDlgCode
& DLGC_WANTTAB
) && !bCtrlDown
)
2373 // let the control have the TAB
2376 else // use it for navigation
2378 // Ctrl-Tab cycles thru notebook pages
2379 bWindowChange
= bCtrlDown
;
2380 bForward
= !bShiftDown
;
2387 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2395 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2404 // we treat PageUp/Dn as arrows because chances are that
2405 // a control which needs arrows also needs them for
2406 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2407 if ( (lDlgCode
& DLGC_WANTARROWS
) && !bCtrlDown
)
2409 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
2410 bWindowChange
= true;
2416 // currently active button should get enter press even
2417 // if there is a default button elsewhere so check if
2418 // this window is a button first
2419 wxWindow
*btn
= NULL
;
2420 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2422 // let IsDialogMessage() handle this for all
2423 // buttons except the owner-drawn ones which it
2424 // just seems to ignore
2425 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2426 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2428 // emulate the button click
2429 btn
= wxFindWinFromHandle(msg
->hwnd
);
2434 else // not a button itself, do we have default button?
2436 // check if this window or any of its ancestors
2437 // wants the message for itself (we always reserve
2438 // Ctrl-Enter for dialog navigation though)
2439 wxWindow
*win
= this;
2442 // this will contain the dialog code of this
2443 // window and all of its parent windows in turn
2444 LONG lDlgCode2
= lDlgCode
;
2448 if ( lDlgCode2
& DLGC_WANTMESSAGE
)
2450 // as it wants to process Enter itself,
2451 // don't call IsDialogMessage() which
2456 // don't propagate keyboard messages beyond
2457 // the first top level window parent
2458 if ( win
->IsTopLevel() )
2461 win
= win
->GetParent();
2463 lDlgCode2
= ::SendMessage
2474 win
= wxGetTopLevelParent(win
);
2477 wxTopLevelWindow
* const
2478 tlw
= wxDynamicCast(win
, wxTopLevelWindow
);
2481 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2486 if ( btn
&& btn
->IsEnabled() )
2488 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2492 #endif // wxUSE_BUTTON
2495 // map Enter presses into button presses on PDAs
2496 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2497 event
.SetEventObject(this);
2498 if ( HandleWindowEvent(event
) )
2500 #endif // __WXWINCE__
2510 wxNavigationKeyEvent event
;
2511 event
.SetDirection(bForward
);
2512 event
.SetWindowChange(bWindowChange
);
2513 event
.SetFromTab(bFromTab
);
2514 event
.SetEventObject(this);
2516 if ( HandleWindowEvent(event
) )
2518 // as we don't call IsDialogMessage(), which would take of
2519 // this by default, we need to manually send this message
2520 // so that controls can change their UI state if needed
2521 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2528 if ( ::IsDialogMessage(GetHwnd(), msg
) )
2530 // IsDialogMessage() did something...
2534 #endif // __WXUNIVERSAL__
2539 // relay mouse move events to the tooltip control
2540 MSG
*msg
= (MSG
*)pMsg
;
2541 if ( msg
->message
== WM_MOUSEMOVE
)
2542 wxToolTip::RelayEvent(pMsg
);
2544 #endif // wxUSE_TOOLTIPS
2549 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2551 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2552 return m_acceleratorTable
.Translate(this, pMsg
);
2556 #endif // wxUSE_ACCEL
2559 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* msg
)
2561 // all tests below have to deal with various bugs/misfeatures of
2562 // IsDialogMessage(): we have to prevent it from being called from our
2563 // MSWProcessMessage() in some situations
2565 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2566 // message even when there is no cancel button and when the message is
2567 // needed by the control itself: in particular, it prevents the tree in
2568 // place edit control from being closed with Escape in a dialog
2569 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_ESCAPE
)
2574 // ::IsDialogMessage() is broken and may sometimes hang the application by
2575 // going into an infinite loop when it tries to find the control to give
2576 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2577 // situations when this may happen and not call it then
2578 if ( msg
->message
!= WM_SYSCHAR
)
2581 // assume we can call it by default
2582 bool canSafelyCallIsDlgMsg
= true;
2584 HWND hwndFocus
= ::GetFocus();
2586 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2587 // ::IsDialogMessage() will also enter an infinite loop, because it will
2588 // recursively check the child windows but not the window itself and so if
2589 // none of the children accepts focus it loops forever (as it only stops
2590 // when it gets back to the window it started from)
2592 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2593 // style has the focus, it can happen. One such possibility is if
2594 // all windows are either toplevel, wxDialog, wxPanel or static
2595 // controls and no window can actually accept keyboard input.
2596 #if !defined(__WXWINCE__)
2597 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2599 // pessimistic by default
2600 canSafelyCallIsDlgMsg
= false;
2601 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2603 node
= node
->GetNext() )
2605 wxWindow
* const win
= node
->GetData();
2606 if ( win
->CanAcceptFocus() &&
2607 !wxHasWindowExStyle(win
, WS_EX_CONTROLPARENT
) )
2609 // it shouldn't hang...
2610 canSafelyCallIsDlgMsg
= true;
2616 #endif // !__WXWINCE__
2618 if ( canSafelyCallIsDlgMsg
)
2620 // ::IsDialogMessage() can enter in an infinite loop when the
2621 // currently focused window is disabled or hidden and its
2622 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2626 if ( !::IsWindowEnabled(hwndFocus
) ||
2627 !::IsWindowVisible(hwndFocus
) )
2629 // it would enter an infinite loop if we do this!
2630 canSafelyCallIsDlgMsg
= false;
2635 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2637 // it's a top level window, don't go further -- e.g. even
2638 // if the parent of a dialog is disabled, this doesn't
2639 // break navigation inside the dialog
2643 hwndFocus
= ::GetParent(hwndFocus
);
2647 return canSafelyCallIsDlgMsg
;
2650 // ---------------------------------------------------------------------------
2651 // message params unpackers
2652 // ---------------------------------------------------------------------------
2654 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2655 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2657 *id
= LOWORD(wParam
);
2658 *hwnd
= (WXHWND
)lParam
;
2659 *cmd
= HIWORD(wParam
);
2662 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2663 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2665 *state
= LOWORD(wParam
);
2666 *minimized
= HIWORD(wParam
);
2667 *hwnd
= (WXHWND
)lParam
;
2670 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2671 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2673 *code
= LOWORD(wParam
);
2674 *pos
= HIWORD(wParam
);
2675 *hwnd
= (WXHWND
)lParam
;
2678 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2679 WXHDC
*hdc
, WXHWND
*hwnd
)
2681 *hwnd
= (WXHWND
)lParam
;
2682 *hdc
= (WXHDC
)wParam
;
2685 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2686 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2688 *item
= (WXWORD
)wParam
;
2689 *flags
= HIWORD(wParam
);
2690 *hmenu
= (WXHMENU
)lParam
;
2693 // ---------------------------------------------------------------------------
2694 // Main wxWidgets window proc and the window proc for wxWindow
2695 // ---------------------------------------------------------------------------
2697 // Hook for new window just as it's being created, when the window isn't yet
2698 // associated with the handle
2699 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2701 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2702 // window being created and insures that it's always unset back later
2703 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2705 gs_winBeingCreated
= winBeingCreated
;
2708 wxWindowCreationHook::~wxWindowCreationHook()
2710 gs_winBeingCreated
= NULL
;
2714 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2716 // trace all messages: useful for the debugging but noticeably slows down
2717 // the code so don't do it by default
2718 #if wxDEBUG_LEVEL >= 2
2719 wxLogTrace("winmsg",
2720 wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"),
2721 wxGetMessageName(message
), hWnd
, (long)wParam
, lParam
);
2722 #endif // wxDEBUG_LEVEL >= 2
2724 wxWindowMSW
*wnd
= wxFindWinFromHandle(hWnd
);
2726 // when we get the first message for the HWND we just created, we associate
2727 // it with wxWindow stored in gs_winBeingCreated
2728 if ( !wnd
&& gs_winBeingCreated
)
2730 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2731 wnd
= gs_winBeingCreated
;
2732 gs_winBeingCreated
= NULL
;
2733 wnd
->SetHWND((WXHWND
)hWnd
);
2738 if ( wnd
&& wxGUIEventLoop::AllowProcessing(wnd
) )
2739 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2741 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2746 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2748 // did we process the message?
2749 bool processed
= false;
2759 // for most messages we should return 0 when we do process the message
2767 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2770 // return 0 to allow window creation
2771 rc
.result
= mayCreate
? 0 : -1;
2777 // never set processed to true and *always* pass WM_DESTROY to
2778 // DefWindowProc() as Windows may do some internal cleanup when
2779 // processing it and failing to pass the message along may cause
2780 // memory and resource leaks!
2781 (void)HandleDestroy();
2785 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2789 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2792 #if !defined(__WXWINCE__)
2795 LPRECT pRect
= (LPRECT
)lParam
;
2797 rc
.SetLeft(pRect
->left
);
2798 rc
.SetTop(pRect
->top
);
2799 rc
.SetRight(pRect
->right
);
2800 rc
.SetBottom(pRect
->bottom
);
2801 processed
= HandleMoving(rc
);
2803 pRect
->left
= rc
.GetLeft();
2804 pRect
->top
= rc
.GetTop();
2805 pRect
->right
= rc
.GetRight();
2806 pRect
->bottom
= rc
.GetBottom();
2811 case WM_ENTERSIZEMOVE
:
2813 processed
= HandleEnterSizeMove();
2817 case WM_EXITSIZEMOVE
:
2819 processed
= HandleExitSizeMove();
2825 LPRECT pRect
= (LPRECT
)lParam
;
2827 rc
.SetLeft(pRect
->left
);
2828 rc
.SetTop(pRect
->top
);
2829 rc
.SetRight(pRect
->right
);
2830 rc
.SetBottom(pRect
->bottom
);
2831 processed
= HandleSizing(rc
);
2833 pRect
->left
= rc
.GetLeft();
2834 pRect
->top
= rc
.GetTop();
2835 pRect
->right
= rc
.GetRight();
2836 pRect
->bottom
= rc
.GetBottom();
2840 #endif // !__WXWINCE__
2842 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2843 case WM_ACTIVATEAPP
:
2844 // This implicitly sends a wxEVT_ACTIVATE_APP event
2845 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2851 WXWORD state
, minimized
;
2853 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2855 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2860 processed
= HandleSetFocus((WXHWND
)wParam
);
2864 processed
= HandleKillFocus((WXHWND
)wParam
);
2867 case WM_PRINTCLIENT
:
2868 processed
= HandlePrintClient((WXHDC
)wParam
);
2874 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2876 processed
= HandlePaint();
2880 processed
= HandlePaint();
2885 #ifdef __WXUNIVERSAL__
2886 // Universal uses its own wxFrame/wxDialog, so we don't receive
2887 // close events unless we have this.
2889 #endif // __WXUNIVERSAL__
2891 // don't let the DefWindowProc() destroy our window - we'll do it
2892 // ourselves in ~wxWindow
2898 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2902 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2903 GET_Y_LPARAM(lParam
),
2907 #ifdef HAVE_TRACKMOUSEEVENT
2909 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2911 if ( m_mouseInWindow
)
2913 GenerateMouseLeave();
2916 // always pass processed back as false, this allows the window
2917 // manager to process the message too. This is needed to
2918 // ensure windows XP themes work properly as the mouse moves
2919 // over widgets like buttons. So don't set processed to true here.
2921 #endif // HAVE_TRACKMOUSEEVENT
2923 #if wxUSE_MOUSEWHEEL
2925 processed
= HandleMouseWheel(wParam
, lParam
);
2929 case WM_LBUTTONDOWN
:
2931 case WM_LBUTTONDBLCLK
:
2932 case WM_RBUTTONDOWN
:
2934 case WM_RBUTTONDBLCLK
:
2935 case WM_MBUTTONDOWN
:
2937 case WM_MBUTTONDBLCLK
:
2938 #ifdef wxHAS_XBUTTON
2939 case WM_XBUTTONDOWN
:
2941 case WM_XBUTTONDBLCLK
:
2942 #endif // wxHAS_XBUTTON
2944 #ifdef __WXMICROWIN__
2945 // MicroWindows seems to ignore the fact that a window is
2946 // disabled. So catch mouse events and throw them away if
2948 wxWindowMSW
* win
= this;
2951 if (!win
->IsEnabled())
2957 win
= win
->GetParent();
2958 if ( !win
|| win
->IsTopLevel() )
2965 #endif // __WXMICROWIN__
2966 int x
= GET_X_LPARAM(lParam
),
2967 y
= GET_Y_LPARAM(lParam
);
2970 // redirect the event to a static control if necessary by
2971 // finding one under mouse because under CE the static controls
2972 // don't generate mouse events (even with SS_NOTIFY)
2974 if ( GetCapture() == this )
2976 // but don't do it if the mouse is captured by this window
2977 // because then it should really get this event itself
2982 win
= FindWindowForMouseEvent(this, &x
, &y
);
2984 // this should never happen
2985 wxCHECK_MSG( win
, 0,
2986 wxT("FindWindowForMouseEvent() returned NULL") );
2989 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
2991 SHRGINFO shrgi
= {0};
2993 shrgi
.cbSize
= sizeof(SHRGINFO
);
2994 shrgi
.hwndClient
= (HWND
) GetHWND();
2998 shrgi
.dwFlags
= SHRG_RETURNCMD
;
2999 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
3001 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
3004 pt
= ClientToScreen(pt
);
3006 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3008 evtCtx
.SetEventObject(this);
3009 if (HandleWindowEvent(evtCtx
))
3018 #else // !__WXWINCE__
3019 wxWindowMSW
*win
= this;
3020 #endif // __WXWINCE__/!__WXWINCE__
3022 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
3024 // if the app didn't eat the event, handle it in the default
3025 // way, that is by giving this window the focus
3028 // for the standard classes their WndProc sets the focus to
3029 // them anyhow and doing it from here results in some weird
3030 // problems, so don't do it for them (unnecessary anyhow)
3031 if ( !win
->IsOfStandardClass() )
3033 if ( message
== WM_LBUTTONDOWN
&& win
->IsFocusable() )
3045 case MM_JOY1BUTTONDOWN
:
3046 case MM_JOY2BUTTONDOWN
:
3047 case MM_JOY1BUTTONUP
:
3048 case MM_JOY2BUTTONUP
:
3049 processed
= HandleJoystickEvent(message
,
3050 GET_X_LPARAM(lParam
),
3051 GET_Y_LPARAM(lParam
),
3054 #endif // __WXMICROWIN__
3060 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
3062 processed
= HandleCommand(id
, cmd
, hwnd
);
3067 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
3070 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
3071 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
3072 // apparently doesn't always behave properly and needs some help
3073 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
3074 case WM_NOTIFYFORMAT
:
3075 if ( lParam
== NF_QUERY
)
3078 rc
.result
= NFR_UNICODE
;
3081 #endif // wxUSE_UNICODE_MSLU
3083 // for these messages we must return true if process the message
3086 processed
= MSWOnDrawItem(wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
3091 case WM_MEASUREITEM
:
3092 processed
= MSWOnMeasureItem(wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
3096 #endif // defined(WM_DRAWITEM)
3099 if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS
) )
3101 // we always want to get the char events
3102 rc
.result
= DLGC_WANTCHARS
;
3104 if ( HasFlag(wxWANTS_CHARS
) )
3106 // in fact, we want everything
3107 rc
.result
|= DLGC_WANTARROWS
|
3114 //else: get the dlg code from the DefWindowProc()
3119 // If this has been processed by an event handler, return 0 now
3120 // (we've handled it).
3121 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
3122 if ( m_lastKeydownProcessed
)
3131 // we consider these messages "not interesting" to OnChar, so
3132 // just don't do anything more with them
3142 // avoid duplicate messages to OnChar for these ASCII keys:
3143 // they will be translated by TranslateMessage() and received
3176 // but set processed to false, not true to still pass them
3177 // to the control's default window proc - otherwise
3178 // built-in keyboard handling won't work
3183 // special case of VK_APPS: treat it the same as right mouse
3184 // click because both usually pop up a context menu
3186 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
3191 // do generate a CHAR event
3192 processed
= HandleChar((WORD
)wParam
, lParam
);
3195 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
3202 // special case of VK_APPS: treat it the same as right mouse button
3203 if ( wParam
== VK_APPS
)
3205 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
3210 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
3215 case WM_CHAR
: // Always an ASCII character
3216 if ( m_lastKeydownProcessed
)
3218 // The key was handled in the EVT_KEY_DOWN and handling
3219 // a key in an EVT_KEY_DOWN handler is meant, by
3220 // design, to prevent EVT_CHARs from happening
3221 m_lastKeydownProcessed
= false;
3226 processed
= HandleChar((WORD
)wParam
, lParam
, true);
3232 processed
= HandleHotKey((WORD
)wParam
, lParam
);
3234 #endif // wxUSE_HOTKEY
3239 processed
= HandleClipboardEvent(message
);
3247 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
3249 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
3255 // CTLCOLOR messages are sent by children to query the parent for their
3257 #ifndef __WXMICROWIN__
3258 case WM_CTLCOLORMSGBOX
:
3259 case WM_CTLCOLOREDIT
:
3260 case WM_CTLCOLORLISTBOX
:
3261 case WM_CTLCOLORBTN
:
3262 case WM_CTLCOLORDLG
:
3263 case WM_CTLCOLORSCROLLBAR
:
3264 case WM_CTLCOLORSTATIC
:
3268 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
3270 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
3273 #endif // !__WXMICROWIN__
3275 case WM_SYSCOLORCHANGE
:
3276 // the return value for this message is ignored
3277 processed
= HandleSysColorChange();
3280 #if !defined(__WXWINCE__)
3281 case WM_DISPLAYCHANGE
:
3282 processed
= HandleDisplayChange();
3286 case WM_PALETTECHANGED
:
3287 processed
= HandlePaletteChanged((WXHWND
)wParam
);
3290 case WM_CAPTURECHANGED
:
3291 processed
= HandleCaptureChanged((WXHWND
)lParam
);
3294 case WM_SETTINGCHANGE
:
3295 processed
= HandleSettingChange(wParam
, lParam
);
3298 case WM_QUERYNEWPALETTE
:
3299 processed
= HandleQueryNewPalette();
3304 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
3305 // check if an override was configured for this window
3306 EraseBgHooks::const_iterator it
= gs_eraseBgHooks
.find(this);
3307 if ( it
!= gs_eraseBgHooks
.end() )
3308 processed
= it
->second
->MSWEraseBgHook((WXHDC
)wParam
);
3310 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
3311 processed
= HandleEraseBkgnd((WXHDC
)wParam
);
3316 // we processed the message, i.e. erased the background
3321 #if !defined(__WXWINCE__)
3323 processed
= HandleDropFiles(wParam
);
3328 processed
= HandleInitDialog((WXHWND
)wParam
);
3332 // we never set focus from here
3337 #if !defined(__WXWINCE__)
3338 case WM_QUERYENDSESSION
:
3339 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3343 processed
= HandleEndSession(wParam
!= 0, lParam
);
3346 case WM_GETMINMAXINFO
:
3347 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3352 processed
= HandleSetCursor((WXHWND
)wParam
,
3353 LOWORD(lParam
), // hit test
3354 HIWORD(lParam
)); // mouse msg
3358 // returning TRUE stops the DefWindowProc() from further
3359 // processing this message - exactly what we need because we've
3360 // just set the cursor.
3365 #if wxUSE_ACCESSIBILITY
3368 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3369 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3371 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3373 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3379 #if defined(WM_HELP)
3382 // by default, WM_HELP is propagated by DefWindowProc() upwards
3383 // to the window parent but as we do it ourselves already
3384 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3385 // to get the other events if we process this message at all
3388 // WM_HELP doesn't use lParam under CE
3390 HELPINFO
* info
= (HELPINFO
*) lParam
;
3391 if ( info
->iContextType
== HELPINFO_WINDOW
)
3393 #endif // !__WXWINCE__
3394 wxHelpEvent helpEvent
3399 wxGetMousePosition() // what else?
3401 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3405 helpEvent
.SetEventObject(this);
3406 HandleWindowEvent(helpEvent
);
3409 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3411 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3412 helpEvent
.SetEventObject(this);
3413 HandleWindowEvent(helpEvent
);
3416 else // unknown help event?
3420 #endif // !__WXWINCE__
3425 #if !defined(__WXWINCE__)
3426 case WM_CONTEXTMENU
:
3428 // we don't convert from screen to client coordinates as
3429 // the event may be handled by a parent window
3430 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3432 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3434 // we could have got an event from our child, reflect it back
3435 // to it if this is the case
3436 wxWindowMSW
*win
= NULL
;
3437 WXHWND hWnd
= (WXHWND
)wParam
;
3438 if ( hWnd
!= m_hWnd
)
3440 win
= FindItemByHWND(hWnd
);
3446 evtCtx
.SetEventObject(win
);
3447 processed
= win
->HandleWindowEvent(evtCtx
);
3454 // we're only interested in our own menus, not MF_SYSMENU
3455 if ( HIWORD(wParam
) == MF_POPUP
)
3457 // handle menu chars for ownerdrawn menu items
3458 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3459 if ( i
!= wxNOT_FOUND
)
3461 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3466 #endif // wxUSE_MENUS
3469 case WM_POWERBROADCAST
:
3472 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3473 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3476 #endif // __WXWINCE__
3479 // If we want the default themed border then we need to draw it ourselves
3482 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3483 const wxBorder border
= TranslateBorder(GetBorder());
3484 if (theme
&& border
== wxBORDER_THEME
)
3486 // first ask the widget to calculate the border size
3487 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3490 // now alter the client size making room for drawing a
3493 NCCALCSIZE_PARAMS
*csparam
= NULL
;
3496 csparam
= (NCCALCSIZE_PARAMS
*)lParam
;
3497 rect
= &csparam
->rgrc
[0];
3501 rect
= (RECT
*)lParam
;
3504 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3505 RECT rcClient
= { 0, 0, 0, 0 };
3506 wxClientDC
dc((wxWindow
*)this);
3507 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3509 if ( theme
->GetThemeBackgroundContentRect
3516 &rcClient
) == S_OK
)
3518 InflateRect(&rcClient
, -1, -1);
3520 csparam
->rgrc
[0] = rcClient
;
3522 *((RECT
*)lParam
) = rcClient
;
3524 // WVR_REDRAW triggers a bug whereby child windows are moved up and left,
3526 // rc.result = WVR_REDRAW;
3534 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3535 const wxBorder border
= TranslateBorder(GetBorder());
3536 if (theme
&& border
== wxBORDER_THEME
)
3538 // first ask the widget to paint its non-client area, such as scrollbars, etc.
3539 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3542 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3543 wxWindowDC
dc((wxWindow
*)this);
3544 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3546 // Clip the DC so that you only draw on the non-client area
3548 wxCopyRectToRECT(GetSize(), rcBorder
);
3551 theme
->GetThemeBackgroundContentRect(
3552 hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, ETS_NORMAL
, &rcBorder
, &rcClient
);
3553 InflateRect(&rcClient
, -1, -1);
3555 ::ExcludeClipRect(GetHdcOf(*impl
), rcClient
.left
, rcClient
.top
,
3556 rcClient
.right
, rcClient
.bottom
);
3558 // Make sure the background is in a proper state
3559 if (theme
->IsThemeBackgroundPartiallyTransparent(hTheme
, EP_EDITTEXT
, ETS_NORMAL
))
3561 theme
->DrawThemeParentBackground(GetHwnd(), GetHdcOf(*impl
), &rcBorder
);
3567 nState
= ETS_DISABLED
;
3568 // should we check this?
3569 //else if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & ES_READONLY)
3570 // nState = ETS_READONLY;
3572 nState
= ETS_NORMAL
;
3573 theme
->DrawThemeBackground(hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, nState
, &rcBorder
, NULL
);
3578 #endif // wxUSE_UXTHEME
3581 // try a custom message handler
3582 const MSWMessageHandlers::const_iterator
3583 i
= gs_messageHandlers
.find(message
);
3584 if ( i
!= gs_messageHandlers
.end() )
3586 processed
= (*i
->second
)(this, message
, wParam
, lParam
);
3592 #if wxDEBUG_LEVEL >= 2
3593 wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."),
3594 wxGetMessageName(message
));
3595 #endif // wxDEBUG_LEVEL >= 2
3596 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3602 // ----------------------------------------------------------------------------
3603 // wxWindow <-> HWND map
3604 // ----------------------------------------------------------------------------
3606 wxWindow
*wxFindWinFromHandle(HWND hwnd
)
3608 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3609 return i
== gs_windowHandles
.end() ? NULL
: i
->second
;
3612 void wxAssociateWinWithHandle(HWND hwnd
, wxWindowMSW
*win
)
3614 // adding NULL hwnd is (first) surely a result of an error and
3615 // (secondly) breaks menu command processing
3616 wxCHECK_RET( hwnd
!= (HWND
)NULL
,
3617 wxT("attempt to add a NULL hwnd to window list ignored") );
3620 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3621 if ( i
!= gs_windowHandles
.end() )
3623 if ( i
->second
!= win
)
3627 wxT("HWND %p already associated with another window (%s)"),
3628 hwnd
, win
->GetClassInfo()->GetClassName()
3632 //else: this actually happens currently because we associate the window
3633 // with its HWND during creation (if we create it) and also when
3634 // SubclassWin() is called later, this is ok
3636 #endif // wxDEBUG_LEVEL
3638 gs_windowHandles
[hwnd
] = (wxWindow
*)win
;
3641 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3643 gs_windowHandles
.erase(GetHwndOf(win
));
3646 // ----------------------------------------------------------------------------
3647 // various MSW speciic class dependent functions
3648 // ----------------------------------------------------------------------------
3650 // Default destroyer - override if you destroy it in some other way
3651 // (e.g. with MDI child windows)
3652 void wxWindowMSW::MSWDestroyWindow()
3656 void wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3659 int& w
, int& h
) const
3661 // CW_USEDEFAULT can't be used for child windows so just position them at
3662 // the origin by default
3663 x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
;
3664 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
;
3666 AdjustForParentClientOrigin(x
, y
);
3668 // We don't have any clearly good choice for the size by default neither
3669 // but we must use something non-zero.
3670 w
= WidthDefault(size
.x
);
3671 h
= HeightDefault(size
.y
);
3674 NB: there used to be some code here which set the initial size of the
3675 window to the client size of the parent if no explicit size was
3676 specified. This was wrong because wxWidgets programs often assume
3677 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3678 it. To see why, you should understand that Windows sends WM_SIZE from
3679 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3680 from some base class ctor and so this WM_SIZE is not processed in the
3681 real class' OnSize() (because it's not fully constructed yet and the
3682 event goes to some base class OnSize() instead). So the WM_SIZE we
3683 rely on is the one sent when the parent frame resizes its children
3684 but here is the problem: if the child already has just the right
3685 size, nothing will happen as both wxWidgets and Windows check for
3686 this and ignore any attempts to change the window size to the size it
3687 already has - so no WM_SIZE would be sent.
3691 WXHWND
wxWindowMSW::MSWGetParent() const
3693 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3696 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3697 const wxChar
*title
,
3701 WXDWORD extendedStyle
)
3703 // check a common bug in the user code: if the window is created with a
3704 // non-default ctor and Create() is called too, we'd create 2 HWND for a
3705 // single wxWindow object and this results in all sorts of trouble,
3706 // especially for wxTLWs
3707 wxCHECK_MSG( !m_hWnd
, true, "window can't be recreated" );
3709 // this can happen if this function is called using the return value of
3710 // wxApp::GetRegisteredClassName() which failed
3711 wxCHECK_MSG( wclass
, false, "failed to register window class?" );
3714 // choose the position/size for the new window
3716 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3718 // controlId is menu handle for the top level windows, so set it to 0
3719 // unless we're creating a child window
3720 int controlId
= style
& WS_CHILD
? GetId() : 0;
3722 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3723 // which is the same but without CS_[HV]REDRAW class styles so using it
3724 // ensures that the window is not fully repainted on each resize
3725 wxString
className(wclass
);
3726 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3728 className
+= wxApp::GetNoRedrawClassSuffix();
3731 // do create the window
3732 wxWindowCreationHook
hook(this);
3734 m_hWnd
= (WXHWND
)::CreateWindowEx
3738 title
? title
: m_windowName
.wx_str(),
3741 (HWND
)MSWGetParent(),
3742 (HMENU
)wxUIntToPtr(controlId
),
3744 NULL
// no extra data
3749 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3754 SubclassWin(m_hWnd
);
3759 // ===========================================================================
3760 // MSW message handlers
3761 // ===========================================================================
3763 // ---------------------------------------------------------------------------
3765 // ---------------------------------------------------------------------------
3767 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3769 #ifndef __WXMICROWIN__
3770 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3771 HWND hWnd
= hdr
->hwndFrom
;
3772 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
3774 // if the control is one of our windows, let it handle the message itself
3777 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3780 // VZ: why did we do it? normally this is unnecessary and, besides, it
3781 // breaks the message processing for the toolbars because the tooltip
3782 // notifications were being forwarded to the toolbar child controls
3783 // (if it had any) before being passed to the toolbar itself, so in my
3784 // example the tooltip for the combobox was always shown instead of the
3785 // correct button tooltips
3787 // try all our children
3788 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3791 wxWindow
*child
= node
->GetData();
3792 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3797 node
= node
->GetNext();
3801 // by default, handle it ourselves
3802 return MSWOnNotify(idCtrl
, lParam
, result
);
3803 #else // __WXMICROWIN__
3810 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3812 const wxString
& ttip
)
3814 // I don't know why it happens, but the versions of comctl32.dll starting
3815 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3816 // this message is supposed to be sent to Unicode programs only) -- hence
3817 // we need to handle it as well, otherwise no tooltips will be shown in
3820 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3823 // not a tooltip message or no tooltip to show anyhow
3828 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3830 // We don't want to use the szText buffer because it has a limit of 80
3831 // bytes and this is not enough, especially for Unicode build where it
3832 // limits the tooltip string length to only 40 characters
3834 // The best would be, of course, to not impose any length limitations at
3835 // all but then the buffer would have to be dynamic and someone would have
3836 // to free it and we don't have the tooltip owner object here any more, so
3837 // for now use our own static buffer with a higher fixed max length.
3839 // Note that using a static buffer should not be a problem as only a single
3840 // tooltip can be shown at the same time anyhow.
3842 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3844 // We need to convert tooltip from multi byte to Unicode on the fly.
3845 static wchar_t buf
[513];
3847 // Truncate tooltip length if needed as otherwise we might not have
3848 // enough space for it in the buffer and MultiByteToWideChar() would
3850 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3852 // Convert to WideChar without adding the NULL character. The NULL
3853 // character is added afterwards (this is more efficient).
3854 int len
= ::MultiByteToWideChar
3866 wxLogLastError(wxT("MultiByteToWideChar()"));
3870 ttText
->lpszText
= (LPSTR
) buf
;
3872 else // TTN_NEEDTEXTA
3873 #endif // !wxUSE_UNICODE
3875 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3876 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3877 // to copy the string we have into the buffer
3878 static wxChar buf
[513];
3879 wxStrlcpy(buf
, ttip
.c_str(), WXSIZEOF(buf
));
3880 ttText
->lpszText
= buf
;
3886 #endif // wxUSE_TOOLTIPS
3888 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3890 WXLPARAM
* WXUNUSED(result
))
3895 NMHDR
* hdr
= (NMHDR
*)lParam
;
3896 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3903 wxUnusedVar(lParam
);
3904 #endif // wxUSE_TOOLTIPS
3909 // ---------------------------------------------------------------------------
3910 // end session messages
3911 // ---------------------------------------------------------------------------
3913 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3915 #ifdef ENDSESSION_LOGOFF
3916 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3917 event
.SetEventObject(wxTheApp
);
3918 event
.SetCanVeto(true);
3919 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3921 bool rc
= wxTheApp
->ProcessEvent(event
);
3925 // we may end only if the app didn't veto session closing (double
3927 *mayEnd
= !event
.GetVeto();
3932 wxUnusedVar(logOff
);
3933 wxUnusedVar(mayEnd
);
3938 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3940 #ifdef ENDSESSION_LOGOFF
3941 // do nothing if the session isn't ending
3946 if ( (this != wxTheApp
->GetTopWindow()) )
3949 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3950 event
.SetEventObject(wxTheApp
);
3951 event
.SetCanVeto(false);
3952 event
.SetLoggingOff((logOff
& ENDSESSION_LOGOFF
) != 0);
3954 return wxTheApp
->ProcessEvent(event
);
3956 wxUnusedVar(endSession
);
3957 wxUnusedVar(logOff
);
3962 // ---------------------------------------------------------------------------
3963 // window creation/destruction
3964 // ---------------------------------------------------------------------------
3966 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3969 // VZ: why is this commented out for WinCE? If it doesn't support
3970 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3971 // not with multiple #ifdef's!
3973 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3974 EnsureParentHasControlParentStyle(GetParent());
3975 #endif // !__WXWINCE__
3982 bool wxWindowMSW::HandleDestroy()
3984 // delete our drop target if we've got one
3985 #if wxUSE_DRAG_AND_DROP
3986 if ( m_dropTarget
!= NULL
)
3988 m_dropTarget
->Revoke(m_hWnd
);
3990 delete m_dropTarget
;
3991 m_dropTarget
= NULL
;
3993 #endif // wxUSE_DRAG_AND_DROP
3995 // WM_DESTROY handled
3999 // ---------------------------------------------------------------------------
4001 // ---------------------------------------------------------------------------
4003 bool wxWindowMSW::HandleActivate(int state
,
4004 bool WXUNUSED(minimized
),
4005 WXHWND
WXUNUSED(activate
))
4007 wxActivateEvent
event(wxEVT_ACTIVATE
,
4008 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
4010 event
.SetEventObject(this);
4012 return HandleWindowEvent(event
);
4015 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
4017 // Strangly enough, some controls get set focus events when they are being
4018 // deleted, even if they already had focus before.
4019 if ( m_isBeingDeleted
)
4024 // notify the parent keeping track of focus for the kbd navigation
4025 // purposes that we got it
4026 wxChildFocusEvent
eventFocus((wxWindow
*)this);
4027 (void)HandleWindowEvent(eventFocus
);
4033 m_caret
->OnSetFocus();
4035 #endif // wxUSE_CARET
4037 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
4038 event
.SetEventObject(this);
4040 // wxFindWinFromHandle() may return NULL, it is ok
4041 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4043 return HandleWindowEvent(event
);
4046 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
4052 m_caret
->OnKillFocus();
4054 #endif // wxUSE_CARET
4056 // Don't send the event when in the process of being deleted. This can
4057 // only cause problems if the event handler tries to access the object.
4058 if ( m_isBeingDeleted
)
4063 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
4064 event
.SetEventObject(this);
4066 // wxFindWinFromHandle() may return NULL, it is ok
4067 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4069 return HandleWindowEvent(event
);
4072 // ---------------------------------------------------------------------------
4074 // ---------------------------------------------------------------------------
4076 void wxWindowMSW::SetLabel( const wxString
& label
)
4078 SetWindowText(GetHwnd(), label
.c_str());
4081 wxString
wxWindowMSW::GetLabel() const
4083 return wxGetWindowText(GetHWND());
4086 // ---------------------------------------------------------------------------
4088 // ---------------------------------------------------------------------------
4090 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
4092 wxShowEvent
event(GetId(), show
);
4093 event
.SetEventObject(this);
4095 return HandleWindowEvent(event
);
4098 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
4100 wxInitDialogEvent
event(GetId());
4101 event
.SetEventObject(this);
4103 return HandleWindowEvent(event
);
4106 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
4108 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
4109 wxUnusedVar(wParam
);
4111 #else // __WXMICROWIN__
4112 HDROP hFilesInfo
= (HDROP
) wParam
;
4114 // Get the total number of files dropped
4115 UINT gwFilesDropped
= ::DragQueryFile
4123 wxString
*files
= new wxString
[gwFilesDropped
];
4124 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
4126 // first get the needed buffer length (+1 for terminating NUL)
4127 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
4129 // and now get the file name
4130 ::DragQueryFile(hFilesInfo
, wIndex
,
4131 wxStringBuffer(files
[wIndex
], len
), len
);
4134 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
4135 event
.SetEventObject(this);
4138 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
4139 event
.m_pos
.x
= dropPoint
.x
;
4140 event
.m_pos
.y
= dropPoint
.y
;
4142 DragFinish(hFilesInfo
);
4144 return HandleWindowEvent(event
);
4149 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
4151 int WXUNUSED(mouseMsg
))
4153 #ifndef __WXMICROWIN__
4154 // the logic is as follows:
4155 // 0. if we're busy, set the busy cursor (even for non client elements)
4156 // 1. don't set custom cursor for non client area of enabled windows
4157 // 2. ask user EVT_SET_CURSOR handler for the cursor
4158 // 3. if still no cursor but we're in a TLW, set the global cursor
4160 HCURSOR hcursor
= 0;
4163 hcursor
= wxGetCurrentBusyCursor();
4167 if ( nHitTest
!= HTCLIENT
)
4170 // first ask the user code - it may wish to set the cursor in some very
4171 // specific way (for example, depending on the current position)
4174 if ( !::GetCursorPosWinCE(&pt
))
4176 if ( !::GetCursorPos(&pt
) )
4179 wxLogLastError(wxT("GetCursorPos"));
4184 ScreenToClient(&x
, &y
);
4185 wxSetCursorEvent
event(x
, y
);
4186 event
.SetId(GetId());
4187 event
.SetEventObject(this);
4189 bool processedEvtSetCursor
= HandleWindowEvent(event
);
4190 if ( processedEvtSetCursor
&& event
.HasCursor() )
4192 hcursor
= GetHcursorOf(event
.GetCursor());
4197 // the test for processedEvtSetCursor is here to prevent using
4198 // m_cursor if the user code caught EVT_SET_CURSOR() and returned
4199 // nothing from it - this is a way to say that our cursor shouldn't
4200 // be used for this point
4201 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
4203 hcursor
= GetHcursorOf(m_cursor
);
4206 if ( !hcursor
&& !GetParent() )
4208 const wxCursor
*cursor
= wxGetGlobalCursor();
4209 if ( cursor
&& cursor
->Ok() )
4211 hcursor
= GetHcursorOf(*cursor
);
4220 ::SetCursor(hcursor
);
4222 // cursor set, stop here
4225 #endif // __WXMICROWIN__
4227 // pass up the window chain
4231 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
4232 WXLPARAM
WXUNUSED(lParam
),
4233 bool *WXUNUSED_IN_WINCE(vetoed
))
4239 wxEventType evtType
;
4242 case PBT_APMQUERYSUSPEND
:
4243 evtType
= wxEVT_POWER_SUSPENDING
;
4246 case PBT_APMQUERYSUSPENDFAILED
:
4247 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
4250 case PBT_APMSUSPEND
:
4251 evtType
= wxEVT_POWER_SUSPENDED
;
4254 case PBT_APMRESUMESUSPEND
:
4255 evtType
= wxEVT_POWER_RESUME
;
4259 wxLogDebug(wxT("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
4262 // these messages are currently not mapped to wx events
4263 case PBT_APMQUERYSTANDBY
:
4264 case PBT_APMQUERYSTANDBYFAILED
:
4265 case PBT_APMSTANDBY
:
4266 case PBT_APMRESUMESTANDBY
:
4267 case PBT_APMBATTERYLOW
:
4268 case PBT_APMPOWERSTATUSCHANGE
:
4269 case PBT_APMOEMEVENT
:
4270 case PBT_APMRESUMECRITICAL
:
4271 #ifdef PBT_APMRESUMEAUTOMATIC
4272 case PBT_APMRESUMEAUTOMATIC
:
4274 evtType
= wxEVT_NULL
;
4278 // don't handle unknown messages
4279 if ( evtType
== wxEVT_NULL
)
4282 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
4284 wxPowerEvent
event(evtType
);
4285 if ( !HandleWindowEvent(event
) )
4288 *vetoed
= event
.IsVetoed();
4294 bool wxWindowMSW::IsDoubleBuffered() const
4296 for ( const wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4298 if ( wxHasWindowExStyle(win
, WS_EX_COMPOSITED
) )
4301 if ( win
->IsTopLevel() )
4308 void wxWindowMSW::SetDoubleBuffered(bool on
)
4310 // Get the current extended style bits
4311 long exstyle
= wxGetWindowExStyle(this);
4313 // Twiddle the bit as needed
4315 exstyle
|= WS_EX_COMPOSITED
;
4317 exstyle
&= ~WS_EX_COMPOSITED
;
4320 wxSetWindowExStyle(this, exstyle
);
4323 // ---------------------------------------------------------------------------
4324 // owner drawn stuff
4325 // ---------------------------------------------------------------------------
4327 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
4328 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
4329 #define WXUNUSED_UNLESS_ODRAWN(param) param
4331 #define WXUNUSED_UNLESS_ODRAWN(param)
4335 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
4336 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
4338 #if wxUSE_OWNER_DRAWN
4340 #if wxUSE_MENUS_NATIVE
4341 // is it a menu item?
4342 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
4343 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
4345 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
4347 // see comment before the same test in MSWOnMeasureItem() below
4351 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4352 false, wxT("MSWOnDrawItem: bad wxMenuItem pointer") );
4354 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4355 // the DC from being released
4356 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
4357 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
4358 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
4359 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
4361 return pMenuItem
->OnDrawItem
4365 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
4366 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
4369 #endif // wxUSE_MENUS_NATIVE
4371 #endif // USE_OWNER_DRAWN
4373 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4375 #if wxUSE_OWNER_DRAWN
4376 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4377 #else // !wxUSE_OWNER_DRAWN
4378 // we may still have owner-drawn buttons internally because we have to make
4379 // them owner-drawn to support colour change
4382 wxDynamicCast(FindItem(id
), wxButton
)
4387 #endif // USE_OWNER_DRAWN
4391 return item
->MSWOnDraw(itemStruct
);
4394 #endif // wxUSE_CONTROLS
4400 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4402 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4403 // is it a menu item?
4404 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4405 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4407 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4409 // according to Carsten Fuchs the pointer may be NULL under XP if an
4410 // MDI child frame is initially maximized, see this for more info:
4411 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4413 // so silently ignore it instead of asserting
4417 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4418 false, wxT("MSWOnMeasureItem: bad wxMenuItem pointer") );
4421 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4423 pMeasureStruct
->itemWidth
= w
;
4424 pMeasureStruct
->itemHeight
= h
;
4429 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4432 return item
->MSWOnMeasure(itemStruct
);
4436 wxUnusedVar(itemStruct
);
4437 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4442 // ---------------------------------------------------------------------------
4443 // colours and palettes
4444 // ---------------------------------------------------------------------------
4446 bool wxWindowMSW::HandleSysColorChange()
4448 wxSysColourChangedEvent event
;
4449 event
.SetEventObject(this);
4451 (void)HandleWindowEvent(event
);
4453 // always let the system carry on the default processing to allow the
4454 // native controls to react to the colours update
4458 bool wxWindowMSW::HandleDisplayChange()
4460 wxDisplayChangedEvent event
;
4461 event
.SetEventObject(this);
4463 return HandleWindowEvent(event
);
4466 #ifndef __WXMICROWIN__
4468 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4470 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4474 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4477 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4479 #endif // wxUSE_CONTROLS
4482 return *brush
!= NULL
;
4485 #endif // __WXMICROWIN__
4487 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4490 // same as below except we don't respond to our own messages
4491 if ( hWndPalChange
!= GetHWND() )
4493 // check to see if we our our parents have a custom palette
4494 wxWindowMSW
*win
= this;
4495 while ( win
&& !win
->HasCustomPalette() )
4497 win
= win
->GetParent();
4500 if ( win
&& win
->HasCustomPalette() )
4502 // realize the palette to see whether redrawing is needed
4503 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4504 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4505 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4507 int result
= ::RealizePalette(hdc
);
4509 // restore the palette (before releasing the DC)
4510 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4511 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4512 ::RealizePalette(hdc
);
4513 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4515 // now check for the need to redraw
4517 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4521 #endif // wxUSE_PALETTE
4523 wxPaletteChangedEvent
event(GetId());
4524 event
.SetEventObject(this);
4525 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4527 return HandleWindowEvent(event
);
4530 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4532 // notify windows on the capture stack about lost capture
4533 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4534 wxWindowBase::NotifyCaptureLost();
4536 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4537 wxMouseCaptureChangedEvent
event(GetId(), win
);
4538 event
.SetEventObject(this);
4539 return HandleWindowEvent(event
);
4542 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4544 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4545 // we need to send this to child windows (it is only sent to top-level
4546 // windows) so {list,tree}ctrls can adjust their font size if necessary
4547 // this is exactly how explorer does it to enable the font size changes
4549 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4552 // top-level windows already get this message from the system
4553 wxWindow
*win
= node
->GetData();
4554 if ( !win
->IsTopLevel() )
4556 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4559 node
= node
->GetNext();
4562 // let the system handle it
4566 bool wxWindowMSW::HandleQueryNewPalette()
4570 // check to see if we our our parents have a custom palette
4571 wxWindowMSW
*win
= this;
4572 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4573 if (win
->HasCustomPalette()) {
4574 /* realize the palette to see whether redrawing is needed */
4575 HDC hdc
= ::GetDC((HWND
) GetHWND());
4576 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4577 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4579 int result
= ::RealizePalette(hdc
);
4580 /* restore the palette (before releasing the DC) */
4581 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4582 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4583 ::RealizePalette(hdc
);
4584 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4585 /* now check for the need to redraw */
4587 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4589 #endif // wxUSE_PALETTE
4591 wxQueryNewPaletteEvent
event(GetId());
4592 event
.SetEventObject(this);
4594 return HandleWindowEvent(event
) && event
.GetPaletteRealized();
4597 // Responds to colour changes: passes event on to children.
4598 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4600 // the top level window also reset the standard colour map as it might have
4601 // changed (there is no need to do it for the non top level windows as we
4602 // only have to do it once)
4606 gs_hasStdCmap
= false;
4608 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4611 // Only propagate to non-top-level windows because Windows already
4612 // sends this event to all top-level ones
4613 wxWindow
*win
= node
->GetData();
4614 if ( !win
->IsTopLevel() )
4616 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4617 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4618 // the standard controls
4619 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4622 node
= node
->GetNext();
4626 extern wxCOLORMAP
*wxGetStdColourMap()
4628 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4629 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4631 if ( !gs_hasStdCmap
)
4633 static bool s_coloursInit
= false;
4635 if ( !s_coloursInit
)
4637 // When a bitmap is loaded, the RGB values can change (apparently
4638 // because Windows adjusts them to care for the old programs always
4639 // using 0xc0c0c0 while the transparent colour for the new Windows
4640 // versions is different). But we do this adjustment ourselves so
4641 // we want to avoid Windows' "help" and for this we need to have a
4642 // reference bitmap which can tell us what the RGB values change
4644 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4645 wxBitmap
stdColourBitmap(wxT("wxBITMAP_STD_COLOURS"));
4646 if ( stdColourBitmap
.Ok() )
4648 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4649 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4650 wxT("forgot to update wxBITMAP_STD_COLOURS!") );
4653 memDC
.SelectObject(stdColourBitmap
);
4656 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4658 memDC
.GetPixel(i
, 0, &colour
);
4659 s_stdColours
[i
] = wxColourToRGB(colour
);
4662 else // wxBITMAP_STD_COLOURS couldn't be loaded
4664 s_stdColours
[0] = RGB(000,000,000); // black
4665 s_stdColours
[1] = RGB(128,128,128); // dark grey
4666 s_stdColours
[2] = RGB(192,192,192); // light grey
4667 s_stdColours
[3] = RGB(255,255,255); // white
4668 //s_stdColours[4] = RGB(000,000,255); // blue
4669 //s_stdColours[5] = RGB(255,000,255); // magenta
4672 s_coloursInit
= true;
4675 gs_hasStdCmap
= true;
4677 // create the colour map
4678 #define INIT_CMAP_ENTRY(col) \
4679 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4680 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4682 INIT_CMAP_ENTRY(BTNTEXT
);
4683 INIT_CMAP_ENTRY(BTNSHADOW
);
4684 INIT_CMAP_ENTRY(BTNFACE
);
4685 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4687 #undef INIT_CMAP_ENTRY
4693 #if wxUSE_UXTHEME && !defined(TMT_FILLCOLOR)
4694 #define TMT_FILLCOLOR 3802
4695 #define TMT_TEXTCOLOR 3803
4696 #define TMT_BORDERCOLOR 3801
4699 wxColour
wxWindowMSW::MSWGetThemeColour(const wchar_t *themeName
,
4702 MSWThemeColour themeColour
,
4703 wxSystemColour fallback
) const
4706 const wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
4709 int themeProperty
= 0;
4711 // TODO: Convert this into a table? Sure would be faster.
4712 switch ( themeColour
)
4714 case ThemeColourBackground
:
4715 themeProperty
= TMT_FILLCOLOR
;
4717 case ThemeColourText
:
4718 themeProperty
= TMT_TEXTCOLOR
;
4720 case ThemeColourBorder
:
4721 themeProperty
= TMT_BORDERCOLOR
;
4724 wxFAIL_MSG(wxT("unsupported theme colour"));
4727 wxUxThemeHandle
hTheme((const wxWindow
*)this, themeName
);
4729 HRESULT hr
= theme
->GetThemeColor
4738 if ( SUCCEEDED(hr
) )
4739 return wxRGBToColour(col
);
4743 "GetThemeColor(%s, %i, %i, %i)",
4744 themeName
, themePart
, themeState
, themeProperty
),
4748 wxUnusedVar(themeName
);
4749 wxUnusedVar(themePart
);
4750 wxUnusedVar(themeState
);
4751 wxUnusedVar(themeColour
);
4753 return wxSystemSettings::GetColour(fallback
);
4756 // ---------------------------------------------------------------------------
4758 // ---------------------------------------------------------------------------
4760 // this variable is used to check that a paint event handler which processed
4761 // the event did create a wxPaintDC inside its code and called BeginPaint() to
4762 // validate the invalidated window area as otherwise we'd keep getting an
4763 // endless stream of WM_PAINT messages for this window resulting in a lot of
4764 // difficult to debug problems (e.g. impossibility to repaint other windows,
4765 // lack of timer and idle events and so on)
4766 extern bool wxDidCreatePaintDC
;
4767 bool wxDidCreatePaintDC
= false;
4769 bool wxWindowMSW::HandlePaint()
4771 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4774 wxLogLastError(wxT("CreateRectRgn"));
4776 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4778 wxLogLastError(wxT("GetUpdateRgn"));
4781 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4783 wxDidCreatePaintDC
= false;
4785 wxPaintEvent
event(m_windowId
);
4786 event
.SetEventObject(this);
4788 bool processed
= HandleWindowEvent(event
);
4790 if ( processed
&& !wxDidCreatePaintDC
)
4792 // do call MSWDefWindowProc() to validate the update region to avoid
4793 // the problems mentioned above
4797 // note that we must generate NC event after the normal one as otherwise
4798 // BeginPaint() will happily overwrite our decorations with the background
4800 wxNcPaintEvent
eventNc(m_windowId
);
4801 eventNc
.SetEventObject(this);
4802 HandleWindowEvent(eventNc
);
4804 // don't keep an HRGN we don't need any longer (GetUpdateRegion() can only
4805 // be called from inside the event handlers called above)
4806 m_updateRegion
.Clear();
4811 // Can be called from an application's OnPaint handler
4812 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4814 #ifdef __WXUNIVERSAL__
4817 HDC hDC
= (HDC
) wxPaintDCImpl::FindDCInCache((wxWindow
*) event
.GetEventObject());
4820 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4825 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4827 switch ( GetBackgroundStyle() )
4829 case wxBG_STYLE_ERASE
:
4830 case wxBG_STYLE_COLOUR
:
4831 // we need to generate an erase background event
4833 wxDCTemp
dc(hdc
, GetClientSize());
4834 wxDCTempImpl
*impl
= (wxDCTempImpl
*) dc
.GetImpl();
4837 impl
->SetWindow((wxWindow
*)this);
4839 wxEraseEvent
event(m_windowId
, &dc
);
4840 event
.SetEventObject(this);
4841 bool rc
= HandleWindowEvent(event
);
4843 // must be called manually as ~wxDC doesn't do anything for
4845 impl
->SelectOldObjects(hdc
);
4849 // background erased by the user-defined handler
4855 case wxBG_STYLE_SYSTEM
:
4856 if ( !DoEraseBackground(hdc
) )
4858 // let the default processing to take place if we didn't erase
4859 // the background ourselves
4864 case wxBG_STYLE_PAINT
:
4865 case wxBG_STYLE_TRANSPARENT
:
4866 // no need to do anything here at all, background will be entirely
4867 // redrawn in WM_PAINT handler
4871 wxFAIL_MSG( "unknown background style" );
4877 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
4879 bool wxWindowMSW::MSWHasEraseBgHook() const
4881 return gs_eraseBgHooks
.find(this) != gs_eraseBgHooks
.end();
4884 void wxWindowMSW::MSWSetEraseBgHook(wxWindow
*child
)
4888 if ( !gs_eraseBgHooks
.insert(
4889 EraseBgHooks::value_type(this, child
)).second
)
4891 wxFAIL_MSG( wxT("Setting erase background hook twice?") );
4894 else // reset the hook
4896 if ( gs_eraseBgHooks
.erase(this) != 1 )
4898 wxFAIL_MSG( wxT("Resetting erase background which was not set?") );
4903 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
4905 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4907 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4911 // erase just the client area of the window, this is important for the
4912 // frames to avoid drawing over the toolbar part of the window (you might
4913 // think using WS_CLIPCHILDREN would prevent this from happening, but it
4916 wxCopyRectToRECT(GetClientRect(), rc
);
4917 ::FillRect((HDC
)hDC
, &rc
, hbr
);
4923 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
),
4924 wxWindowMSW
* WXUNUSED(child
))
4929 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4931 return (WXHBRUSH
)GetHbrushOf(*brush
);
4937 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
)
4939 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4941 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, this);
4945 // don't use the parent background if we're not transparent
4946 if ( !win
->HasTransparentBackground() )
4949 // background is not inherited beyond top level windows
4950 if ( win
->IsTopLevel() )
4957 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4959 // we receive this message when DrawThemeParentBackground() is
4960 // called from def window proc of several controls under XP and we
4961 // must draw properly themed background here
4963 // note that naively I'd expect filling the client rect with the
4964 // brush returned by MSWGetBgBrush() work -- but for some reason it
4965 // doesn't and we have to call parents MSWPrintChild() which is
4966 // supposed to call DrawThemeBackground() with appropriate params
4968 // also note that in this case lParam == PRF_CLIENT but we're
4969 // clearly expected to paint the background and nothing else!
4971 if ( IsTopLevel() || InheritsBackgroundColour() )
4974 // sometimes we don't want the parent to handle it at all, instead
4975 // return whatever value this window wants
4976 if ( !MSWShouldPropagatePrintChild() )
4977 return MSWPrintChild(hDC
, (wxWindow
*)this);
4979 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4981 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4984 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4991 // ---------------------------------------------------------------------------
4992 // moving and resizing
4993 // ---------------------------------------------------------------------------
4995 bool wxWindowMSW::HandleMinimize()
4997 wxIconizeEvent
event(m_windowId
);
4998 event
.SetEventObject(this);
5000 return HandleWindowEvent(event
);
5003 bool wxWindowMSW::HandleMaximize()
5005 wxMaximizeEvent
event(m_windowId
);
5006 event
.SetEventObject(this);
5008 return HandleWindowEvent(event
);
5011 bool wxWindowMSW::HandleMove(int x
, int y
)
5014 wxMoveEvent
event(point
, m_windowId
);
5015 event
.SetEventObject(this);
5017 return HandleWindowEvent(event
);
5020 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
5022 wxMoveEvent
event(rect
, m_windowId
);
5023 event
.SetEventObject(this);
5025 bool rc
= HandleWindowEvent(event
);
5027 rect
= event
.GetRect();
5031 bool wxWindowMSW::HandleEnterSizeMove()
5033 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5034 event
.SetEventType(wxEVT_MOVE_START
);
5035 event
.SetEventObject(this);
5037 return HandleWindowEvent(event
);
5040 bool wxWindowMSW::HandleExitSizeMove()
5042 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5043 event
.SetEventType(wxEVT_MOVE_END
);
5044 event
.SetEventObject(this);
5046 return HandleWindowEvent(event
);
5049 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
5051 #if wxUSE_DEFERRED_SIZING
5052 // when we resize this window, its children are probably going to be
5053 // repositioned as well, prepare to use DeferWindowPos() for them
5054 int numChildren
= 0;
5055 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
5057 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
5062 // Protect against valid m_hDWP being overwritten
5063 bool useDefer
= false;
5065 if ( numChildren
> 1 )
5069 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
5072 wxLogLastError(wxT("BeginDeferWindowPos"));
5078 #endif // wxUSE_DEFERRED_SIZING
5080 // update this window size
5081 bool processed
= false;
5085 wxFAIL_MSG( wxT("unexpected WM_SIZE parameter") );
5086 // fall through nevertheless
5090 // we're not interested in these messages at all
5093 case SIZE_MINIMIZED
:
5094 processed
= HandleMinimize();
5097 case SIZE_MAXIMIZED
:
5098 /* processed = */ HandleMaximize();
5099 // fall through to send a normal size event as well
5102 // don't use w and h parameters as they specify the client size
5103 // while according to the docs EVT_SIZE handler is supposed to
5104 // receive the total size
5105 wxSizeEvent
event(GetSize(), m_windowId
);
5106 event
.SetEventObject(this);
5108 processed
= HandleWindowEvent(event
);
5111 #if wxUSE_DEFERRED_SIZING
5112 // and finally change the positions of all child windows at once
5113 if ( useDefer
&& m_hDWP
)
5115 // reset m_hDWP to NULL so that child windows don't try to use our
5116 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
5117 // happen anyhow normally but who knows what weird flow of control we
5118 // may have depending on what the users EVT_SIZE handler does...)
5119 HDWP hDWP
= (HDWP
)m_hDWP
;
5122 // do put all child controls in place at once
5123 if ( !::EndDeferWindowPos(hDWP
) )
5125 wxLogLastError(wxT("EndDeferWindowPos"));
5128 // Reset our children's pending pos/size values.
5129 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
5131 node
= node
->GetNext() )
5133 wxWindowMSW
* const child
= node
->GetData();
5134 child
->MSWEndDeferWindowPos();
5137 #endif // wxUSE_DEFERRED_SIZING
5142 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
5144 wxSizeEvent
event(rect
, m_windowId
);
5145 event
.SetEventObject(this);
5147 bool rc
= HandleWindowEvent(event
);
5149 rect
= event
.GetRect();
5153 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
5158 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
5162 int minWidth
= GetMinWidth(),
5163 minHeight
= GetMinHeight(),
5164 maxWidth
= GetMaxWidth(),
5165 maxHeight
= GetMaxHeight();
5167 if ( minWidth
!= wxDefaultCoord
)
5169 info
->ptMinTrackSize
.x
= minWidth
;
5173 if ( minHeight
!= wxDefaultCoord
)
5175 info
->ptMinTrackSize
.y
= minHeight
;
5179 if ( maxWidth
!= wxDefaultCoord
)
5181 info
->ptMaxTrackSize
.x
= maxWidth
;
5185 if ( maxHeight
!= wxDefaultCoord
)
5187 info
->ptMaxTrackSize
.y
= maxHeight
;
5195 // ---------------------------------------------------------------------------
5197 // ---------------------------------------------------------------------------
5199 bool wxWindowMSW::HandleCommand(WXWORD id_
, WXWORD cmd
, WXHWND control
)
5201 // sign extend to int from short before comparing with the other int ids
5202 int id
= (signed short)id_
;
5204 #if wxUSE_MENUS_NATIVE
5205 if ( !cmd
&& wxCurrentPopupMenu
)
5207 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
5208 wxCurrentPopupMenu
= NULL
;
5210 return popupMenu
->MSWCommand(cmd
, id
);
5212 #endif // wxUSE_MENUS_NATIVE
5214 wxWindow
*win
= NULL
;
5216 // first try to find it from HWND - this works even with the broken
5217 // programs using the same ids for different controls
5220 win
= wxFindWinFromHandle(control
);
5231 return win
->MSWCommand(cmd
, id
);
5234 // the messages sent from the in-place edit control used by the treectrl
5235 // for label editing have id == 0, but they should _not_ be treated as menu
5236 // messages (they are EN_XXX ones, in fact) so don't translate anything
5237 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
5240 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
5241 event
.SetEventObject(this);
5244 return HandleWindowEvent(event
);
5248 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5249 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
5250 // notifications to its parent which we want to reflect back to
5252 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
5253 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
5255 #endif // wxUSE_SPINCTRL
5257 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
5258 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
5259 // notifications to its parent which we want to reflect back to
5261 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
5262 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
5270 // ---------------------------------------------------------------------------
5272 // ---------------------------------------------------------------------------
5274 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
5278 // our client coords are not quite the same as Windows ones
5279 wxPoint pt
= GetClientAreaOrigin();
5280 event
.m_x
= x
- pt
.x
;
5281 event
.m_y
= y
- pt
.y
;
5283 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
5284 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
5285 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
5286 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
5287 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
5288 #ifdef wxHAS_XBUTTON
5289 event
.m_aux1Down
= (flags
& MK_XBUTTON1
) != 0;
5290 event
.m_aux2Down
= (flags
& MK_XBUTTON2
) != 0;
5291 #endif // wxHAS_XBUTTON
5292 event
.m_altDown
= ::wxIsAltDown();
5295 event
.SetTimestamp(::GetMessageTime());
5298 event
.SetEventObject(this);
5299 event
.SetId(GetId());
5301 #if wxUSE_MOUSEEVENT_HACK
5302 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
5303 gs_lastMouseEvent
.type
= event
.GetEventType();
5304 #endif // wxUSE_MOUSEEVENT_HACK
5308 // Windows doesn't send the mouse events to the static controls (which are
5309 // transparent in the sense that their WM_NCHITTEST handler returns
5310 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
5311 // and so we manually check if we don't have a child window under mouse and if
5312 // we do, send the event to it instead of the window Windows had sent WM_XXX
5315 // Notice that this is not done for the mouse move events because this could
5316 // (would?) be too slow, but only for clicks which means that the static texts
5317 // still don't get move, enter nor leave events.
5318 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
5320 wxCHECK_MSG( x
&& y
, win
, wxT("NULL pointer in FindWindowForMouseEvent") );
5322 // first try to find a non transparent child: this allows us to send events
5323 // to a static text which is inside a static box, for example
5324 POINT pt
= { *x
, *y
};
5325 HWND hwnd
= GetHwndOf(win
),
5329 hwndUnderMouse
= ::ChildWindowFromPoint
5335 hwndUnderMouse
= ::ChildWindowFromPointEx
5345 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
5347 // now try any child window at all
5348 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
5351 // check that we have a child window which is susceptible to receive mouse
5352 // events: for this it must be shown and enabled
5353 if ( hwndUnderMouse
&&
5354 hwndUnderMouse
!= hwnd
&&
5355 ::IsWindowVisible(hwndUnderMouse
) &&
5356 ::IsWindowEnabled(hwndUnderMouse
) )
5358 wxWindow
*winUnderMouse
= wxFindWinFromHandle(hwndUnderMouse
);
5359 if ( winUnderMouse
)
5361 // translate the mouse coords to the other window coords
5362 win
->ClientToScreen(x
, y
);
5363 winUnderMouse
->ScreenToClient(x
, y
);
5365 win
= winUnderMouse
;
5371 #endif // __WXWINCE__
5373 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5375 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
5376 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
5377 // from the message id and take the value in the table to get wxWin event
5379 static const wxEventType eventsMouse
[] =
5390 wxEVT_MIDDLE_DCLICK
,
5391 0, // this one is for wxEVT_MOTION which is not used here
5400 #ifdef wxHAS_XBUTTON
5401 // the same messages are used for both auxillary mouse buttons so we need
5402 // to adjust the index manually
5405 case WM_XBUTTONDOWN
:
5407 case WM_XBUTTONDBLCLK
:
5408 if ( flags
& MK_XBUTTON2
)
5409 msg
+= wxEVT_AUX2_DOWN
- wxEVT_AUX1_DOWN
;
5411 #endif // wxHAS_XBUTTON
5413 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
5414 InitMouseEvent(event
, x
, y
, flags
);
5416 return HandleWindowEvent(event
);
5419 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
5421 if ( !m_mouseInWindow
)
5423 // it would be wrong to assume that just because we get a mouse move
5424 // event that the mouse is inside the window: although this is usually
5425 // true, it is not if we had captured the mouse, so we need to check
5426 // the mouse coordinates here
5427 if ( !HasCapture() || IsMouseInWindow() )
5429 // Generate an ENTER event
5430 m_mouseInWindow
= true;
5432 #ifdef HAVE_TRACKMOUSEEVENT
5433 typedef BOOL (WINAPI
*_TrackMouseEvent_t
)(LPTRACKMOUSEEVENT
);
5435 static const _TrackMouseEvent_t
5436 s_pfn_TrackMouseEvent
= _TrackMouseEvent
;
5437 #else // !__WXWINCE__
5438 static _TrackMouseEvent_t s_pfn_TrackMouseEvent
;
5439 static bool s_initDone
= false;
5442 // see comment in wxApp::GetComCtl32Version() explaining the
5443 // use of wxLoadedDLL
5444 wxLoadedDLL
dllComCtl32(wxT("comctl32.dll"));
5445 if ( dllComCtl32
.IsLoaded() )
5447 s_pfn_TrackMouseEvent
= (_TrackMouseEvent_t
)
5448 dllComCtl32
.RawGetSymbol(wxT("_TrackMouseEvent"));
5454 if ( s_pfn_TrackMouseEvent
)
5455 #endif // __WXWINCE__/!__WXWINCE__
5457 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
5459 trackinfo
.dwFlags
= TME_LEAVE
;
5460 trackinfo
.hwndTrack
= GetHwnd();
5462 (*s_pfn_TrackMouseEvent
)(&trackinfo
);
5464 #endif // HAVE_TRACKMOUSEEVENT
5466 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
5467 InitMouseEvent(event
, x
, y
, flags
);
5469 (void)HandleWindowEvent(event
);
5472 #ifdef HAVE_TRACKMOUSEEVENT
5473 else // mouse not in window
5475 // Check if we need to send a LEAVE event
5476 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
5477 // send it here if we are using native mouse leave tracking
5478 if ( HasCapture() && !IsMouseInWindow() )
5480 GenerateMouseLeave();
5483 #endif // HAVE_TRACKMOUSEEVENT
5485 #if wxUSE_MOUSEEVENT_HACK
5486 // Windows often generates mouse events even if mouse position hasn't
5487 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
5489 // Filter this out as it can result in unexpected behaviour compared to
5491 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
5492 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
5493 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
5494 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
5496 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
5498 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
5503 #endif // wxUSE_MOUSEEVENT_HACK
5505 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
5509 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
5511 #if wxUSE_MOUSEWHEEL
5512 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5513 // forwarded up to the parent by DefWindowProc()) and not in the client
5514 // ones as all the other messages, translate them to the client coords for
5517 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
5518 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
5519 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
5520 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5521 event
.m_wheelDelta
= WHEEL_DELTA
;
5523 static int s_linesPerRotation
= -1;
5524 if ( s_linesPerRotation
== -1 )
5526 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5527 &s_linesPerRotation
, 0))
5529 // this is not supposed to happen
5530 wxLogLastError(wxT("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5532 // the default is 3, so use it if SystemParametersInfo() failed
5533 s_linesPerRotation
= 3;
5537 event
.m_linesPerAction
= s_linesPerRotation
;
5538 return HandleWindowEvent(event
);
5540 #else // !wxUSE_MOUSEWHEEL
5541 wxUnusedVar(wParam
);
5542 wxUnusedVar(lParam
);
5545 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5548 void wxWindowMSW::GenerateMouseLeave()
5550 m_mouseInWindow
= false;
5553 if ( wxIsShiftDown() )
5555 if ( wxIsCtrlDown() )
5556 state
|= MK_CONTROL
;
5558 // Only the high-order bit should be tested
5559 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5560 state
|= MK_LBUTTON
;
5561 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5562 state
|= MK_MBUTTON
;
5563 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5564 state
|= MK_RBUTTON
;
5568 if ( !::GetCursorPosWinCE(&pt
) )
5570 if ( !::GetCursorPos(&pt
) )
5573 wxLogLastError(wxT("GetCursorPos"));
5576 // we need to have client coordinates here for symmetry with
5577 // wxEVT_ENTER_WINDOW
5578 RECT rect
= wxGetWindowRect(GetHwnd());
5582 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5583 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5585 (void)HandleWindowEvent(event
);
5588 // ---------------------------------------------------------------------------
5589 // keyboard handling
5590 // ---------------------------------------------------------------------------
5592 // create the key event of the given type for the given key - used by
5593 // HandleChar and HandleKeyDown/Up
5594 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5597 WXWPARAM wParam
) const
5599 wxKeyEvent
event(evType
);
5600 event
.SetId(GetId());
5601 event
.m_shiftDown
= wxIsShiftDown();
5602 event
.m_controlDown
= wxIsCtrlDown();
5603 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5605 event
.SetEventObject((wxWindow
*)this); // const_cast
5606 event
.m_keyCode
= id
;
5608 event
.m_uniChar
= (wxChar
) wParam
;
5610 event
.m_rawCode
= (wxUint32
) wParam
;
5611 event
.m_rawFlags
= (wxUint32
) lParam
;
5613 event
.SetTimestamp(::GetMessageTime());
5616 // translate the position to client coordinates
5617 const wxPoint mousePos
= ScreenToClient(wxGetMousePosition());
5618 event
.m_x
= mousePos
.x
;
5619 event
.m_y
= mousePos
.y
;
5624 // isASCII is true only when we're called from WM_CHAR handler and not from
5626 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
5633 else // we're called from WM_KEYDOWN
5635 // don't pass lParam to wxCharCodeMSWToWX() here because we don't want
5636 // to get numpad key codes: CHAR events should use the logical keys
5637 // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events
5638 id
= wxCharCodeMSWToWX(wParam
);
5641 // it's ASCII and will be processed here only when called from
5642 // WM_CHAR (i.e. when isASCII = true), don't process it now
5647 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
5649 // the alphanumeric keys produced by pressing AltGr+something on European
5650 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5651 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5652 // alphanumeric, so pretend that there are no modifiers at all (the
5653 // KEY_DOWN event would still have the correct modifiers if they're really
5655 if ( event
.m_controlDown
&& event
.m_altDown
&&
5656 (id
>= 32 && id
< 256) )
5658 event
.m_controlDown
=
5659 event
.m_altDown
= false;
5662 return HandleWindowEvent(event
);
5665 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5667 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5671 // normal ASCII char
5675 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
5676 return HandleWindowEvent(event
);
5679 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5681 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5685 // normal ASCII char
5689 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
5690 return HandleWindowEvent(event
);
5694 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5695 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5697 // FIXME: implement GetMenuItemCount for WinCE, possibly
5698 // in terms of GetMenuItemInfo
5700 const HMENU hmenu
= (HMENU
)lParam
;
5704 mii
.cbSize
= sizeof(MENUITEMINFO
);
5706 // we could use MIIM_FTYPE here as we only need to know if the item is
5707 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5708 // MIIM_FTYPE is not supported under Win95
5709 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5711 // find if we have this letter in any owner drawn item
5712 const int count
= ::GetMenuItemCount(hmenu
);
5713 for ( int i
= 0; i
< count
; i
++ )
5715 // previous loop iteration could modify it, reset it back before
5716 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5719 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5721 if ( mii
.fType
== MFT_OWNERDRAW
)
5723 // dwItemData member of the MENUITEMINFO is a
5724 // pointer to the associated wxMenuItem -- see the
5725 // menu creation code
5726 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5728 const wxChar
*p
= wxStrchr(item
->GetItemLabel().wx_str(), wxT('&'));
5731 if ( *p
== wxT('&') )
5733 // this is not the accel char, find the real one
5734 p
= wxStrchr(p
+ 1, wxT('&'));
5736 else // got the accel char
5738 // FIXME-UNICODE: this comparison doesn't risk to work
5739 // for non ASCII accelerator characters I'm afraid, but
5741 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5747 // this one doesn't match
5754 else // failed to get the menu text?
5756 // it's not fatal, so don't show error, but still log it
5757 wxLogLastError(wxT("GetMenuItemInfo"));
5764 #endif // wxUSE_MENUS
5766 bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg
)
5768 const wxEventType type
= nMsg
== WM_CUT
? wxEVT_COMMAND_TEXT_CUT
5769 : nMsg
== WM_COPY
? wxEVT_COMMAND_TEXT_COPY
5770 : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE
;
5771 wxClipboardTextEvent
evt(type
, GetId());
5773 evt
.SetEventObject(this);
5775 return HandleWindowEvent(evt
);
5778 // ---------------------------------------------------------------------------
5780 // ---------------------------------------------------------------------------
5782 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5786 if ( flags
& JOY_BUTTON1CHG
)
5787 change
= wxJOY_BUTTON1
;
5788 if ( flags
& JOY_BUTTON2CHG
)
5789 change
= wxJOY_BUTTON2
;
5790 if ( flags
& JOY_BUTTON3CHG
)
5791 change
= wxJOY_BUTTON3
;
5792 if ( flags
& JOY_BUTTON4CHG
)
5793 change
= wxJOY_BUTTON4
;
5796 if ( flags
& JOY_BUTTON1
)
5797 buttons
|= wxJOY_BUTTON1
;
5798 if ( flags
& JOY_BUTTON2
)
5799 buttons
|= wxJOY_BUTTON2
;
5800 if ( flags
& JOY_BUTTON3
)
5801 buttons
|= wxJOY_BUTTON3
;
5802 if ( flags
& JOY_BUTTON4
)
5803 buttons
|= wxJOY_BUTTON4
;
5805 // the event ids aren't consecutive so we can't use table based lookup
5807 wxEventType eventType
;
5812 eventType
= wxEVT_JOY_MOVE
;
5817 eventType
= wxEVT_JOY_MOVE
;
5822 eventType
= wxEVT_JOY_ZMOVE
;
5827 eventType
= wxEVT_JOY_ZMOVE
;
5830 case MM_JOY1BUTTONDOWN
:
5832 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5835 case MM_JOY2BUTTONDOWN
:
5837 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5840 case MM_JOY1BUTTONUP
:
5842 eventType
= wxEVT_JOY_BUTTON_UP
;
5845 case MM_JOY2BUTTONUP
:
5847 eventType
= wxEVT_JOY_BUTTON_UP
;
5851 wxFAIL_MSG(wxT("no such joystick event"));
5856 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5857 event
.SetPosition(wxPoint(x
, y
));
5858 event
.SetEventObject(this);
5860 return HandleWindowEvent(event
);
5870 // ---------------------------------------------------------------------------
5872 // ---------------------------------------------------------------------------
5874 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5875 WXWORD pos
, WXHWND control
)
5877 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5879 wxWindow
*child
= wxFindWinFromHandle(control
);
5881 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5884 wxScrollWinEvent event
;
5885 event
.SetPosition(pos
);
5886 event
.SetOrientation(orientation
);
5887 event
.SetEventObject(this);
5892 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5896 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5900 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5904 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5908 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5912 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5915 case SB_THUMBPOSITION
:
5917 // under Win32, the scrollbar range and position are 32 bit integers,
5918 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5919 // explicitly query the scrollbar for the correct position (this must
5920 // be done only for these two SB_ events as they are the only one
5921 // carrying the scrollbar position)
5923 WinStruct
<SCROLLINFO
> scrollInfo
;
5924 scrollInfo
.fMask
= SIF_TRACKPOS
;
5926 if ( !::GetScrollInfo(GetHwnd(),
5927 WXOrientToSB(orientation
),
5930 // Not necessarily an error, if there are no scrollbars yet.
5931 // wxLogLastError(wxT("GetScrollInfo"));
5934 event
.SetPosition(scrollInfo
.nTrackPos
);
5937 event
.SetEventType( wParam
== SB_THUMBPOSITION
5938 ? wxEVT_SCROLLWIN_THUMBRELEASE
5939 : wxEVT_SCROLLWIN_THUMBTRACK
);
5946 return HandleWindowEvent(event
);
5949 // ----------------------------------------------------------------------------
5950 // custom message handlers
5951 // ----------------------------------------------------------------------------
5954 wxWindowMSW::MSWRegisterMessageHandler(int msg
, MSWMessageHandler handler
)
5956 wxCHECK_MSG( gs_messageHandlers
.find(msg
) == gs_messageHandlers
.end(),
5957 false, wxT("registering handler for the same message twice") );
5959 gs_messageHandlers
[msg
] = handler
;
5964 wxWindowMSW::MSWUnregisterMessageHandler(int msg
, MSWMessageHandler handler
)
5966 const MSWMessageHandlers::iterator i
= gs_messageHandlers
.find(msg
);
5967 wxCHECK_RET( i
!= gs_messageHandlers
.end() && i
->second
== handler
,
5968 wxT("unregistering non-registered handler?") );
5970 gs_messageHandlers
.erase(i
);
5973 // ===========================================================================
5975 // ===========================================================================
5977 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5980 HDC dc
= ::GetDC((HWND
) wnd
);
5983 // the_font.UseResource();
5984 // the_font.RealizeResource();
5985 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
5987 was
= (HFONT
) SelectObject(dc
,fnt
);
5989 GetTextMetrics(dc
, &tm
);
5992 SelectObject(dc
,was
);
5994 ReleaseDC((HWND
)wnd
, dc
);
5997 *x
= tm
.tmAveCharWidth
;
5999 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
6001 // the_font.ReleaseResource();
6004 // use the "extended" bit (24) of lParam to distinguish extended keys
6005 // from normal keys as the same key is sent
6007 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
6009 // except that if lParam is 0, it means we don't have real lParam from
6010 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
6011 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
6012 // non-numpad (hence extended) key as this is a more common case
6013 return !lParam
|| (lParam
& (1 << 24)) ? keyExtended
: keyNormal
;
6016 // this array contains the Windows virtual key codes which map one to one to
6017 // WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below
6019 // note that keys having a normal and numpad version (e.g. WXK_HOME and
6020 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
6021 static const struct wxKeyMapping
6025 } gs_specialKeys
[] =
6027 { VK_CANCEL
, WXK_CANCEL
},
6028 { VK_BACK
, WXK_BACK
},
6029 { VK_TAB
, WXK_TAB
},
6030 { VK_CLEAR
, WXK_CLEAR
},
6031 { VK_SHIFT
, WXK_SHIFT
},
6032 { VK_CONTROL
, WXK_CONTROL
},
6033 { VK_MENU
, WXK_ALT
},
6034 { VK_PAUSE
, WXK_PAUSE
},
6035 { VK_CAPITAL
, WXK_CAPITAL
},
6036 { VK_SPACE
, WXK_SPACE
},
6037 { VK_ESCAPE
, WXK_ESCAPE
},
6038 { VK_SELECT
, WXK_SELECT
},
6039 { VK_PRINT
, WXK_PRINT
},
6040 { VK_EXECUTE
, WXK_EXECUTE
},
6041 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
6042 { VK_HELP
, WXK_HELP
},
6044 { VK_NUMPAD0
, WXK_NUMPAD0
},
6045 { VK_NUMPAD1
, WXK_NUMPAD1
},
6046 { VK_NUMPAD2
, WXK_NUMPAD2
},
6047 { VK_NUMPAD3
, WXK_NUMPAD3
},
6048 { VK_NUMPAD4
, WXK_NUMPAD4
},
6049 { VK_NUMPAD5
, WXK_NUMPAD5
},
6050 { VK_NUMPAD6
, WXK_NUMPAD6
},
6051 { VK_NUMPAD7
, WXK_NUMPAD7
},
6052 { VK_NUMPAD8
, WXK_NUMPAD8
},
6053 { VK_NUMPAD9
, WXK_NUMPAD9
},
6054 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
6055 { VK_ADD
, WXK_NUMPAD_ADD
},
6056 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
6057 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
6058 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
6069 { VK_F10
, WXK_F10
},
6070 { VK_F11
, WXK_F11
},
6071 { VK_F12
, WXK_F12
},
6072 { VK_F13
, WXK_F13
},
6073 { VK_F14
, WXK_F14
},
6074 { VK_F15
, WXK_F15
},
6075 { VK_F16
, WXK_F16
},
6076 { VK_F17
, WXK_F17
},
6077 { VK_F18
, WXK_F18
},
6078 { VK_F19
, WXK_F19
},
6079 { VK_F20
, WXK_F20
},
6080 { VK_F21
, WXK_F21
},
6081 { VK_F22
, WXK_F22
},
6082 { VK_F23
, WXK_F23
},
6083 { VK_F24
, WXK_F24
},
6085 { VK_NUMLOCK
, WXK_NUMLOCK
},
6086 { VK_SCROLL
, WXK_SCROLL
},
6089 { VK_LWIN
, WXK_WINDOWS_LEFT
},
6090 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
6091 { VK_APPS
, WXK_WINDOWS_MENU
},
6092 #endif // VK_APPS defined
6095 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
6096 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
6097 int wxCharCodeMSWToWX(int vk
, WXLPARAM lParam
)
6099 // check the table first
6100 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6102 if ( gs_specialKeys
[n
].vk
== vk
)
6103 return gs_specialKeys
[n
].wxk
;
6106 // keys requiring special handling
6110 // the mapping for these keys may be incorrect on non-US keyboards so
6111 // maybe we shouldn't map them to ASCII values at all
6112 case VK_OEM_1
: wxk
= ';'; break;
6113 case VK_OEM_PLUS
: wxk
= '+'; break;
6114 case VK_OEM_COMMA
: wxk
= ','; break;
6115 case VK_OEM_MINUS
: wxk
= '-'; break;
6116 case VK_OEM_PERIOD
: wxk
= '.'; break;
6117 case VK_OEM_2
: wxk
= '/'; break;
6118 case VK_OEM_3
: wxk
= '~'; break;
6119 case VK_OEM_4
: wxk
= '['; break;
6120 case VK_OEM_5
: wxk
= '\\'; break;
6121 case VK_OEM_6
: wxk
= ']'; break;
6122 case VK_OEM_7
: wxk
= '\''; break;
6124 // handle extended keys
6126 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
6130 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
6134 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
6138 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
6142 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
6146 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
6150 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
6154 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
6158 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
6162 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
6166 // don't use ChooseNormalOrExtended() here as the keys are reversed
6167 // here: numpad enter is the extended one
6168 wxk
= lParam
&& (lParam
& (1 << 24)) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
6178 WXWORD
wxCharCodeWXToMSW(int wxk
)
6180 // check the table first
6181 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6183 if ( gs_specialKeys
[n
].wxk
== wxk
)
6184 return gs_specialKeys
[n
].vk
;
6187 // and then check for special keys not included in the table
6192 case WXK_NUMPAD_PAGEUP
:
6197 case WXK_NUMPAD_PAGEDOWN
:
6202 case WXK_NUMPAD_END
:
6207 case WXK_NUMPAD_HOME
:
6212 case WXK_NUMPAD_LEFT
:
6222 case WXK_NUMPAD_RIGHT
:
6227 case WXK_NUMPAD_DOWN
:
6232 case WXK_NUMPAD_INSERT
:
6237 case WXK_NUMPAD_DELETE
:
6242 // no VkKeyScan() under CE unfortunately, we need to test how does
6243 // it handle OEM keys
6245 // check to see if its one of the OEM key codes.
6246 BYTE vks
= LOBYTE(VkKeyScan(wxk
));
6252 #endif // !__WXWINCE__
6261 // small helper for wxGetKeyState() and wxGetMouseState()
6262 static inline bool wxIsKeyDown(WXWORD vk
)
6264 // SM_SWAPBUTTON is not available under CE, so don't swap buttons there
6265 #ifdef SM_SWAPBUTTON
6266 if ( vk
== VK_LBUTTON
|| vk
== VK_RBUTTON
)
6268 if ( ::GetSystemMetrics(SM_SWAPBUTTON
) )
6270 if ( vk
== VK_LBUTTON
)
6272 else // vk == VK_RBUTTON
6276 #endif // SM_SWAPBUTTON
6278 // the low order bit indicates whether the key was pressed since the last
6279 // call and the high order one indicates whether it is down right now and
6280 // we only want that one
6281 return (GetAsyncKeyState(vk
) & (1<<15)) != 0;
6284 bool wxGetKeyState(wxKeyCode key
)
6286 // although this does work under Windows, it is not supported under other
6287 // platforms so don't allow it, you must use wxGetMouseState() instead
6288 wxASSERT_MSG( key
!= VK_LBUTTON
&&
6289 key
!= VK_RBUTTON
&&
6291 wxT("can't use wxGetKeyState() for mouse buttons") );
6293 const WXWORD vk
= wxCharCodeWXToMSW(key
);
6295 // if the requested key is a LED key, return true if the led is pressed
6296 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
6298 // low order bit means LED is highlighted and high order one means the
6299 // key is down; for compatibility with the other ports return true if
6300 // either one is set
6301 return GetKeyState(vk
) != 0;
6306 return wxIsKeyDown(vk
);
6311 wxMouseState
wxGetMouseState()
6315 GetCursorPos( &pt
);
6319 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
6320 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
6321 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
6322 #ifdef wxHAS_XBUTTON
6323 ms
.SetAux1Down(wxIsKeyDown(VK_XBUTTON1
));
6324 ms
.SetAux2Down(wxIsKeyDown(VK_XBUTTON2
));
6325 #endif // wxHAS_XBUTTON
6327 ms
.SetControlDown(wxIsCtrlDown ());
6328 ms
.SetShiftDown (wxIsShiftDown());
6329 ms
.SetAltDown (wxIsAltDown ());
6330 // ms.SetMetaDown();
6336 wxWindow
*wxGetActiveWindow()
6338 HWND hWnd
= GetActiveWindow();
6341 return wxFindWinFromHandle(hWnd
);
6346 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
6348 HWND hwnd
= (HWND
)hWnd
;
6350 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
6351 // by code in msw/radiobox.cpp), for all the others we just search up the
6353 wxWindow
*win
= NULL
;
6356 win
= wxFindWinFromHandle(hwnd
);
6360 // native radiobuttons return DLGC_RADIOBUTTON here and for any
6361 // wxWindow class which overrides WM_GETDLGCODE processing to
6362 // do it as well, win would be already non NULL
6363 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
6365 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
6367 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
6368 #endif // wxUSE_RADIOBOX
6370 // spin control text buddy window should be mapped to spin ctrl
6371 // itself so try it too
6372 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
6375 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
6377 #endif // wxUSE_SPINCTRL
6381 while ( hwnd
&& !win
)
6383 // this is a really ugly hack needed to avoid mistakenly returning the
6384 // parent frame wxWindow for the find/replace modeless dialog HWND -
6385 // this, in turn, is needed to call IsDialogMessage() from
6386 // wxApp::ProcessMessage() as for this we must return NULL from here
6388 // FIXME: this is clearly not the best way to do it but I think we'll
6389 // need to change HWND <-> wxWindow code more heavily than I can
6390 // do it now to fix it
6391 #ifndef __WXMICROWIN__
6392 if ( ::GetWindow(hwnd
, GW_OWNER
) )
6394 // it's a dialog box, don't go upwards
6399 hwnd
= ::GetParent(hwnd
);
6400 win
= wxFindWinFromHandle(hwnd
);
6406 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
6408 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
6409 // in active frames and dialogs, regardless of where the focus is.
6410 static HHOOK wxTheKeyboardHook
= 0;
6413 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
6415 DWORD hiWord
= HIWORD(lParam
);
6416 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
6418 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
6421 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
6422 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
6423 event
.m_altDown
= true;
6425 event
.SetEventObject(NULL
);
6426 event
.m_keyCode
= id
;
6427 event
.m_shiftDown
= wxIsShiftDown();
6428 event
.m_controlDown
= wxIsCtrlDown();
6430 event
.SetTimestamp(::GetMessageTime());
6432 wxWindow
*win
= wxGetActiveWindow();
6433 wxEvtHandler
*handler
;
6436 handler
= win
->GetEventHandler();
6437 event
.SetId(win
->GetId());
6442 event
.SetId(wxID_ANY
);
6445 if ( handler
&& handler
->ProcessEvent(event
) )
6453 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
6456 void wxSetKeyboardHook(bool doIt
)
6460 wxTheKeyboardHook
= ::SetWindowsHookEx
6463 (HOOKPROC
)wxKeyboardHook
,
6464 NULL
, // must be NULL for process hook
6465 ::GetCurrentThreadId()
6467 if ( !wxTheKeyboardHook
)
6469 wxLogLastError(wxT("SetWindowsHookEx(wxKeyboardHook)"));
6474 if ( wxTheKeyboardHook
)
6475 ::UnhookWindowsHookEx(wxTheKeyboardHook
);
6479 #endif // !__WXMICROWIN__
6481 #if wxDEBUG_LEVEL >= 2
6482 const wxChar
*wxGetMessageName(int message
)
6486 case 0x0000: return wxT("WM_NULL");
6487 case 0x0001: return wxT("WM_CREATE");
6488 case 0x0002: return wxT("WM_DESTROY");
6489 case 0x0003: return wxT("WM_MOVE");
6490 case 0x0005: return wxT("WM_SIZE");
6491 case 0x0006: return wxT("WM_ACTIVATE");
6492 case 0x0007: return wxT("WM_SETFOCUS");
6493 case 0x0008: return wxT("WM_KILLFOCUS");
6494 case 0x000A: return wxT("WM_ENABLE");
6495 case 0x000B: return wxT("WM_SETREDRAW");
6496 case 0x000C: return wxT("WM_SETTEXT");
6497 case 0x000D: return wxT("WM_GETTEXT");
6498 case 0x000E: return wxT("WM_GETTEXTLENGTH");
6499 case 0x000F: return wxT("WM_PAINT");
6500 case 0x0010: return wxT("WM_CLOSE");
6501 case 0x0011: return wxT("WM_QUERYENDSESSION");
6502 case 0x0012: return wxT("WM_QUIT");
6503 case 0x0013: return wxT("WM_QUERYOPEN");
6504 case 0x0014: return wxT("WM_ERASEBKGND");
6505 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
6506 case 0x0016: return wxT("WM_ENDSESSION");
6507 case 0x0017: return wxT("WM_SYSTEMERROR");
6508 case 0x0018: return wxT("WM_SHOWWINDOW");
6509 case 0x0019: return wxT("WM_CTLCOLOR");
6510 case 0x001A: return wxT("WM_WININICHANGE");
6511 case 0x001B: return wxT("WM_DEVMODECHANGE");
6512 case 0x001C: return wxT("WM_ACTIVATEAPP");
6513 case 0x001D: return wxT("WM_FONTCHANGE");
6514 case 0x001E: return wxT("WM_TIMECHANGE");
6515 case 0x001F: return wxT("WM_CANCELMODE");
6516 case 0x0020: return wxT("WM_SETCURSOR");
6517 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6518 case 0x0022: return wxT("WM_CHILDACTIVATE");
6519 case 0x0023: return wxT("WM_QUEUESYNC");
6520 case 0x0024: return wxT("WM_GETMINMAXINFO");
6521 case 0x0026: return wxT("WM_PAINTICON");
6522 case 0x0027: return wxT("WM_ICONERASEBKGND");
6523 case 0x0028: return wxT("WM_NEXTDLGCTL");
6524 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6525 case 0x002B: return wxT("WM_DRAWITEM");
6526 case 0x002C: return wxT("WM_MEASUREITEM");
6527 case 0x002D: return wxT("WM_DELETEITEM");
6528 case 0x002E: return wxT("WM_VKEYTOITEM");
6529 case 0x002F: return wxT("WM_CHARTOITEM");
6530 case 0x0030: return wxT("WM_SETFONT");
6531 case 0x0031: return wxT("WM_GETFONT");
6532 case 0x0037: return wxT("WM_QUERYDRAGICON");
6533 case 0x0039: return wxT("WM_COMPAREITEM");
6534 case 0x0041: return wxT("WM_COMPACTING");
6535 case 0x0044: return wxT("WM_COMMNOTIFY");
6536 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6537 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6538 case 0x0048: return wxT("WM_POWER");
6540 case 0x004A: return wxT("WM_COPYDATA");
6541 case 0x004B: return wxT("WM_CANCELJOURNAL");
6542 case 0x004E: return wxT("WM_NOTIFY");
6543 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6544 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6545 case 0x0052: return wxT("WM_TCARD");
6546 case 0x0053: return wxT("WM_HELP");
6547 case 0x0054: return wxT("WM_USERCHANGED");
6548 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6549 case 0x007B: return wxT("WM_CONTEXTMENU");
6550 case 0x007C: return wxT("WM_STYLECHANGING");
6551 case 0x007D: return wxT("WM_STYLECHANGED");
6552 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6553 case 0x007F: return wxT("WM_GETICON");
6554 case 0x0080: return wxT("WM_SETICON");
6556 case 0x0081: return wxT("WM_NCCREATE");
6557 case 0x0082: return wxT("WM_NCDESTROY");
6558 case 0x0083: return wxT("WM_NCCALCSIZE");
6559 case 0x0084: return wxT("WM_NCHITTEST");
6560 case 0x0085: return wxT("WM_NCPAINT");
6561 case 0x0086: return wxT("WM_NCACTIVATE");
6562 case 0x0087: return wxT("WM_GETDLGCODE");
6563 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6564 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6565 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6566 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6567 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6568 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6569 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6570 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6571 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6572 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6574 case 0x00B0: return wxT("EM_GETSEL");
6575 case 0x00B1: return wxT("EM_SETSEL");
6576 case 0x00B2: return wxT("EM_GETRECT");
6577 case 0x00B3: return wxT("EM_SETRECT");
6578 case 0x00B4: return wxT("EM_SETRECTNP");
6579 case 0x00B5: return wxT("EM_SCROLL");
6580 case 0x00B6: return wxT("EM_LINESCROLL");
6581 case 0x00B7: return wxT("EM_SCROLLCARET");
6582 case 0x00B8: return wxT("EM_GETMODIFY");
6583 case 0x00B9: return wxT("EM_SETMODIFY");
6584 case 0x00BA: return wxT("EM_GETLINECOUNT");
6585 case 0x00BB: return wxT("EM_LINEINDEX");
6586 case 0x00BC: return wxT("EM_SETHANDLE");
6587 case 0x00BD: return wxT("EM_GETHANDLE");
6588 case 0x00BE: return wxT("EM_GETTHUMB");
6589 case 0x00C1: return wxT("EM_LINELENGTH");
6590 case 0x00C2: return wxT("EM_REPLACESEL");
6591 case 0x00C4: return wxT("EM_GETLINE");
6592 case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */
6593 case 0x00C6: return wxT("EM_CANUNDO");
6594 case 0x00C7: return wxT("EM_UNDO");
6595 case 0x00C8: return wxT("EM_FMTLINES");
6596 case 0x00C9: return wxT("EM_LINEFROMCHAR");
6597 case 0x00CB: return wxT("EM_SETTABSTOPS");
6598 case 0x00CC: return wxT("EM_SETPASSWORDCHAR");
6599 case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER");
6600 case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE");
6601 case 0x00CF: return wxT("EM_SETREADONLY");
6602 case 0x00D0: return wxT("EM_SETWORDBREAKPROC");
6603 case 0x00D1: return wxT("EM_GETWORDBREAKPROC");
6604 case 0x00D2: return wxT("EM_GETPASSWORDCHAR");
6605 case 0x00D3: return wxT("EM_SETMARGINS");
6606 case 0x00D4: return wxT("EM_GETMARGINS");
6607 case 0x00D5: return wxT("EM_GETLIMITTEXT");
6608 case 0x00D6: return wxT("EM_POSFROMCHAR");
6609 case 0x00D7: return wxT("EM_CHARFROMPOS");
6610 case 0x00D8: return wxT("EM_SETIMESTATUS");
6611 case 0x00D9: return wxT("EM_GETIMESTATUS");
6613 case 0x0100: return wxT("WM_KEYDOWN");
6614 case 0x0101: return wxT("WM_KEYUP");
6615 case 0x0102: return wxT("WM_CHAR");
6616 case 0x0103: return wxT("WM_DEADCHAR");
6617 case 0x0104: return wxT("WM_SYSKEYDOWN");
6618 case 0x0105: return wxT("WM_SYSKEYUP");
6619 case 0x0106: return wxT("WM_SYSCHAR");
6620 case 0x0107: return wxT("WM_SYSDEADCHAR");
6621 case 0x0108: return wxT("WM_KEYLAST");
6623 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6624 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6625 case 0x010F: return wxT("WM_IME_COMPOSITION");
6627 case 0x0110: return wxT("WM_INITDIALOG");
6628 case 0x0111: return wxT("WM_COMMAND");
6629 case 0x0112: return wxT("WM_SYSCOMMAND");
6630 case 0x0113: return wxT("WM_TIMER");
6631 case 0x0114: return wxT("WM_HSCROLL");
6632 case 0x0115: return wxT("WM_VSCROLL");
6633 case 0x0116: return wxT("WM_INITMENU");
6634 case 0x0117: return wxT("WM_INITMENUPOPUP");
6635 case 0x011F: return wxT("WM_MENUSELECT");
6636 case 0x0120: return wxT("WM_MENUCHAR");
6637 case 0x0121: return wxT("WM_ENTERIDLE");
6639 case 0x0127: return wxT("WM_CHANGEUISTATE");
6640 case 0x0128: return wxT("WM_UPDATEUISTATE");
6641 case 0x0129: return wxT("WM_QUERYUISTATE");
6643 case 0x0132: return wxT("WM_CTLCOLORMSGBOX");
6644 case 0x0133: return wxT("WM_CTLCOLOREDIT");
6645 case 0x0134: return wxT("WM_CTLCOLORLISTBOX");
6646 case 0x0135: return wxT("WM_CTLCOLORBTN");
6647 case 0x0136: return wxT("WM_CTLCOLORDLG");
6648 case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR");
6649 case 0x0138: return wxT("WM_CTLCOLORSTATIC");
6650 case 0x01E1: return wxT("MN_GETHMENU");
6652 case 0x0200: return wxT("WM_MOUSEMOVE");
6653 case 0x0201: return wxT("WM_LBUTTONDOWN");
6654 case 0x0202: return wxT("WM_LBUTTONUP");
6655 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6656 case 0x0204: return wxT("WM_RBUTTONDOWN");
6657 case 0x0205: return wxT("WM_RBUTTONUP");
6658 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6659 case 0x0207: return wxT("WM_MBUTTONDOWN");
6660 case 0x0208: return wxT("WM_MBUTTONUP");
6661 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6662 case 0x020A: return wxT("WM_MOUSEWHEEL");
6663 case 0x020B: return wxT("WM_XBUTTONDOWN");
6664 case 0x020C: return wxT("WM_XBUTTONUP");
6665 case 0x020D: return wxT("WM_XBUTTONDBLCLK");
6666 case 0x0210: return wxT("WM_PARENTNOTIFY");
6667 case 0x0211: return wxT("WM_ENTERMENULOOP");
6668 case 0x0212: return wxT("WM_EXITMENULOOP");
6670 case 0x0213: return wxT("WM_NEXTMENU");
6671 case 0x0214: return wxT("WM_SIZING");
6672 case 0x0215: return wxT("WM_CAPTURECHANGED");
6673 case 0x0216: return wxT("WM_MOVING");
6674 case 0x0218: return wxT("WM_POWERBROADCAST");
6675 case 0x0219: return wxT("WM_DEVICECHANGE");
6677 case 0x0220: return wxT("WM_MDICREATE");
6678 case 0x0221: return wxT("WM_MDIDESTROY");
6679 case 0x0222: return wxT("WM_MDIACTIVATE");
6680 case 0x0223: return wxT("WM_MDIRESTORE");
6681 case 0x0224: return wxT("WM_MDINEXT");
6682 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6683 case 0x0226: return wxT("WM_MDITILE");
6684 case 0x0227: return wxT("WM_MDICASCADE");
6685 case 0x0228: return wxT("WM_MDIICONARRANGE");
6686 case 0x0229: return wxT("WM_MDIGETACTIVE");
6687 case 0x0230: return wxT("WM_MDISETMENU");
6688 case 0x0233: return wxT("WM_DROPFILES");
6690 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6691 case 0x0282: return wxT("WM_IME_NOTIFY");
6692 case 0x0283: return wxT("WM_IME_CONTROL");
6693 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6694 case 0x0285: return wxT("WM_IME_SELECT");
6695 case 0x0286: return wxT("WM_IME_CHAR");
6696 case 0x0290: return wxT("WM_IME_KEYDOWN");
6697 case 0x0291: return wxT("WM_IME_KEYUP");
6699 case 0x02A0: return wxT("WM_NCMOUSEHOVER");
6700 case 0x02A1: return wxT("WM_MOUSEHOVER");
6701 case 0x02A2: return wxT("WM_NCMOUSELEAVE");
6702 case 0x02A3: return wxT("WM_MOUSELEAVE");
6704 case 0x0300: return wxT("WM_CUT");
6705 case 0x0301: return wxT("WM_COPY");
6706 case 0x0302: return wxT("WM_PASTE");
6707 case 0x0303: return wxT("WM_CLEAR");
6708 case 0x0304: return wxT("WM_UNDO");
6709 case 0x0305: return wxT("WM_RENDERFORMAT");
6710 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6711 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6712 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6713 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6714 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6715 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6716 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6717 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6718 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6719 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6720 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6721 case 0x0311: return wxT("WM_PALETTECHANGED");
6722 case 0x0312: return wxT("WM_HOTKEY");
6724 case 0x0317: return wxT("WM_PRINT");
6725 case 0x0318: return wxT("WM_PRINTCLIENT");
6727 // common controls messages - although they're not strictly speaking
6728 // standard, it's nice to decode them nevertheless
6731 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6732 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6733 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6734 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6735 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6736 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6737 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6738 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6739 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6740 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6741 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6742 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6743 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6744 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6745 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6746 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6747 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6748 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6749 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6750 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6751 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6752 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6753 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6754 case 0x1000 + 18: return wxT("LVM_HITTEST");
6755 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6756 case 0x1000 + 20: return wxT("LVM_SCROLL");
6757 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6758 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6759 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6760 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6761 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6762 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6763 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6764 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6765 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6766 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6767 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6768 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6769 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6770 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6771 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6772 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6773 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6774 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6775 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6776 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6777 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6778 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6779 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6780 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6781 case 0x1000 + 42: return wxT("LVM_UPDATE");
6782 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6783 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6784 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6785 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6786 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6787 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6788 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6789 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6790 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6791 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6792 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6793 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6794 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6795 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6796 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6797 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6798 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6799 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6800 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6801 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6802 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6803 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6804 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6805 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6806 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6807 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6810 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6811 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6812 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6813 case 0x1100 + 2: return wxT("TVM_EXPAND");
6814 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6815 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6816 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6817 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6818 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6819 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6820 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6821 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6822 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6823 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6824 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6825 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6826 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6827 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6828 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6829 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6830 case 0x1100 + 17: return wxT("TVM_HITTEST");
6831 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6832 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6833 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6834 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6835 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6836 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6837 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6838 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6839 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6842 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6843 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6844 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6845 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6846 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6847 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6848 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6849 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6850 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6851 case 0x1200 + 6: return wxT("HDM_HITTEST");
6852 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6853 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6854 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6855 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6856 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6857 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6858 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6859 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6862 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6863 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6864 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6865 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6866 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6867 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6868 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6869 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6870 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6871 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6872 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6873 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6874 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6875 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6876 case 0x1300 + 13: return wxT("TCM_HITTEST");
6877 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6878 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6879 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6880 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6881 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6882 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6883 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6884 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6885 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6886 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6887 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6888 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6891 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6892 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
6893 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
6894 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
6895 case WM_USER
+5: return wxT("TB_INDETERMINATE");
6896 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
6897 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
6898 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
6899 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
6900 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
6901 case WM_USER
+17: return wxT("TB_SETSTATE");
6902 case WM_USER
+18: return wxT("TB_GETSTATE");
6903 case WM_USER
+19: return wxT("TB_ADDBITMAP");
6904 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
6905 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
6906 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
6907 case WM_USER
+23: return wxT("TB_GETBUTTON");
6908 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
6909 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
6910 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
6911 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
6912 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
6913 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
6914 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
6915 case WM_USER
+29: return wxT("TB_GETITEMRECT");
6916 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
6917 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
6918 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
6919 case WM_USER
+33: return wxT("TB_AUTOSIZE");
6920 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
6921 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
6922 case WM_USER
+37: return wxT("TB_SETPARENT");
6923 case WM_USER
+39: return wxT("TB_SETROWS");
6924 case WM_USER
+40: return wxT("TB_GETROWS");
6925 case WM_USER
+42: return wxT("TB_SETCMDID");
6926 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
6927 case WM_USER
+44: return wxT("TB_GETBITMAP");
6928 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
6929 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
6930 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
6931 case WM_USER
+47: return wxT("TB_SETINDENT");
6932 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
6933 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
6934 case WM_USER
+50: return wxT("TB_LOADIMAGES");
6935 case WM_USER
+51: return wxT("TB_GETRECT");
6936 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
6937 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
6938 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
6939 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
6940 case WM_USER
+56: return wxT("TB_SETSTYLE");
6941 case WM_USER
+57: return wxT("TB_GETSTYLE");
6942 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
6943 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
6944 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
6945 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
6946 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
6949 static wxString s_szBuf
;
6950 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
6951 return s_szBuf
.c_str();
6954 #endif // wxDEBUG_LEVEL >= 2
6956 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
6960 HWND hwnd
= GetHwndOf(win
);
6961 HDC hdc
= ::GetDC(hwnd
);
6963 #if !wxDIALOG_UNIT_COMPATIBILITY
6964 // and select the current font into it
6965 HFONT hfont
= GetHfontOf(win
->GetFont());
6968 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
6972 // finally retrieve the text metrics from it
6973 GetTextMetrics(hdc
, &tm
);
6975 #if !wxDIALOG_UNIT_COMPATIBILITY
6979 (void)::SelectObject(hdc
, hfont
);
6983 ::ReleaseDC(hwnd
, hdc
);
6988 // Find the wxWindow at the current mouse position, returning the mouse
6990 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
6992 pt
= wxGetMousePosition();
6993 return wxFindWindowAtPoint(pt
);
6996 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
7002 HWND hWnd
= ::WindowFromPoint(pt2
);
7004 return wxGetWindowFromHWND((WXHWND
)hWnd
);
7007 // Get the current mouse position.
7008 wxPoint
wxGetMousePosition()
7012 GetCursorPosWinCE(&pt
);
7014 GetCursorPos( & pt
);
7017 return wxPoint(pt
.x
, pt
.y
);
7022 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7023 static void WinCEUnregisterHotKey(int modifiers
, int id
)
7025 // Register hotkeys for the hardware buttons
7027 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
7029 UnregisterFunc1Proc procUnregisterFunc
;
7030 hCoreDll
= LoadLibrary(wxT("coredll.dll"));
7033 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, wxT("UnregisterFunc1"));
7034 if (procUnregisterFunc
)
7035 procUnregisterFunc(modifiers
, id
);
7036 FreeLibrary(hCoreDll
);
7041 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
7043 UINT win_modifiers
=0;
7044 if ( modifiers
& wxMOD_ALT
)
7045 win_modifiers
|= MOD_ALT
;
7046 if ( modifiers
& wxMOD_SHIFT
)
7047 win_modifiers
|= MOD_SHIFT
;
7048 if ( modifiers
& wxMOD_CONTROL
)
7049 win_modifiers
|= MOD_CONTROL
;
7050 if ( modifiers
& wxMOD_WIN
)
7051 win_modifiers
|= MOD_WIN
;
7053 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7054 // Required for PPC and Smartphone hardware buttons
7055 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
7056 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
7059 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
7061 wxLogLastError(wxT("RegisterHotKey"));
7069 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
7071 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7072 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
7075 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
7077 wxLogLastError(wxT("UnregisterHotKey"));
7087 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
7089 int hotkeyId
= wParam
;
7090 int virtualKey
= HIWORD(lParam
);
7091 int win_modifiers
= LOWORD(lParam
);
7093 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
7094 event
.SetId(hotkeyId
);
7095 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
7096 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
7097 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
7098 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
7100 return HandleWindowEvent(event
);
7103 #endif // wxUSE_ACCEL
7105 #endif // wxUSE_HOTKEY
7107 // Not tested under WinCE
7110 // this class installs a message hook which really wakes up our idle processing
7111 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
7112 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
7113 // being dragged or even inside ::MessageBox()) and so don't control message
7114 // dispatching otherwise
7115 class wxIdleWakeUpModule
: public wxModule
7118 virtual bool OnInit()
7120 ms_hMsgHookProc
= ::SetWindowsHookEx
7123 &wxIdleWakeUpModule::MsgHookProc
,
7125 GetCurrentThreadId()
7128 if ( !ms_hMsgHookProc
)
7130 wxLogLastError(wxT("SetWindowsHookEx(WH_GETMESSAGE)"));
7138 virtual void OnExit()
7140 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
7143 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
7145 MSG
*msg
= (MSG
*)lParam
;
7147 // only process the message if it is actually going to be removed from
7148 // the message queue, this prevents that the same event from being
7149 // processed multiple times if now someone just called PeekMessage()
7150 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
7152 wxTheApp
->ProcessPendingEvents();
7155 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
7159 static HHOOK ms_hMsgHookProc
;
7161 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
7164 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
7166 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
7168 #endif // __WXWINCE__
7173 static void wxAdjustZOrder(wxWindow
* parent
)
7175 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
7177 // Set the z-order correctly
7178 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
7181 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
7184 wxWindow
*childWin
= current
->GetData();
7185 wxAdjustZOrder(childWin
);
7186 current
= current
->GetNext();
7191 // We need to adjust the z-order of static boxes in WinCE, to
7192 // make 'contained' controls visible
7193 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
7196 wxAdjustZOrder(this);