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 MSWEnableHWND(GetHwnd(), enable
);
705 bool wxWindowMSW::MSWEnableHWND(WXHWND hWnd
, bool enable
)
710 // If disabling focused control, we move focus to the next one, as if the
711 // user pressed Tab. That's because we can't keep focus on a disabled
712 // control, Tab-navigation would stop working then.
713 if ( !enable
&& ::GetFocus() == hWnd
)
716 return ::EnableWindow(hWnd
, (BOOL
)enable
) != 0;
719 bool wxWindowMSW::Show(bool show
)
721 if ( !wxWindowBase::Show(show
) )
724 HWND hWnd
= GetHwnd();
726 // we could be called before the underlying window is created (this is
727 // actually useful to prevent it from being initially shown), e.g.
729 // wxFoo *foo = new wxFoo;
731 // foo->Create(parent, ...);
733 // should work without errors
736 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
741 // DoFreeze/DoThaw don't do anything if the window is not shown, so
742 // we have to call them from here now
753 wxWindowMSW::MSWShowWithEffect(bool show
,
757 if ( effect
== wxSHOW_EFFECT_NONE
)
760 if ( !wxWindowBase::Show(show
) )
763 typedef BOOL (WINAPI
*AnimateWindow_t
)(HWND
, DWORD
, DWORD
);
765 static AnimateWindow_t s_pfnAnimateWindow
= NULL
;
766 static bool s_initDone
= false;
769 wxDynamicLibrary
dllUser32(wxT("user32.dll"), wxDL_VERBATIM
| wxDL_QUIET
);
770 wxDL_INIT_FUNC(s_pfn
, AnimateWindow
, dllUser32
);
774 // notice that it's ok to unload user32.dll here as it won't be really
775 // unloaded, being still in use because we link to it statically too
778 if ( !s_pfnAnimateWindow
)
781 // Show() has a side effect of sending a WM_SIZE to the window, which helps
782 // ensuring that it's laid out correctly, but AnimateWindow() doesn't do
783 // this so send the event ourselves
786 // prepare to use AnimateWindow()
789 timeout
= 200; // this is the default animation timeout, per MSDN
791 DWORD dwFlags
= show
? 0 : AW_HIDE
;
795 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
796 dwFlags
|= AW_HOR_NEGATIVE
;
799 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
800 dwFlags
|= AW_HOR_POSITIVE
;
803 case wxSHOW_EFFECT_ROLL_TO_TOP
:
804 dwFlags
|= AW_VER_NEGATIVE
;
807 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
808 dwFlags
|= AW_VER_POSITIVE
;
811 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
812 dwFlags
|= AW_SLIDE
| AW_HOR_NEGATIVE
;
815 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
816 dwFlags
|= AW_SLIDE
| AW_HOR_POSITIVE
;
819 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
820 dwFlags
|= AW_SLIDE
| AW_VER_NEGATIVE
;
823 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
824 dwFlags
|= AW_SLIDE
| AW_VER_POSITIVE
;
827 case wxSHOW_EFFECT_BLEND
:
831 case wxSHOW_EFFECT_EXPAND
:
832 dwFlags
|= AW_CENTER
;
836 case wxSHOW_EFFECT_MAX
:
837 wxFAIL_MSG( wxT("invalid window show effect") );
841 wxFAIL_MSG( wxT("unknown window show effect") );
845 if ( !(*s_pfnAnimateWindow
)(GetHwnd(), timeout
, dwFlags
) )
847 wxLogLastError(wxT("AnimateWindow"));
855 // Raise the window to the top of the Z order
856 void wxWindowMSW::Raise()
858 wxBringWindowToTop(GetHwnd());
861 // Lower the window to the bottom of the Z order
862 void wxWindowMSW::Lower()
864 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
865 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
868 void wxWindowMSW::DoCaptureMouse()
870 HWND hWnd
= GetHwnd();
877 void wxWindowMSW::DoReleaseMouse()
879 if ( !::ReleaseCapture() )
881 wxLogLastError(wxT("ReleaseCapture"));
885 /* static */ wxWindow
*wxWindowBase::GetCapture()
887 HWND hwnd
= ::GetCapture();
888 return hwnd
? wxFindWinFromHandle(hwnd
) : NULL
;
891 bool wxWindowMSW::SetFont(const wxFont
& font
)
893 if ( !wxWindowBase::SetFont(font
) )
899 HWND hWnd
= GetHwnd();
902 // note the use of GetFont() instead of m_font: our own font could have
903 // just been reset and in this case we need to change the font used by
904 // the native window to the default for this class, i.e. exactly what
906 WXHANDLE hFont
= GetFont().GetResourceHandle();
908 wxASSERT_MSG( hFont
, wxT("should have valid font") );
910 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
915 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
917 if ( !wxWindowBase::SetCursor(cursor
) )
923 // don't "overwrite" busy cursor
924 if ( m_cursor
.Ok() && !wxIsBusy() )
926 // normally we should change the cursor only if it's over this window
927 // but we should do it always if we capture the mouse currently
928 bool set
= HasCapture();
931 HWND hWnd
= GetHwnd();
935 ::GetCursorPosWinCE(&point
);
937 ::GetCursorPos(&point
);
940 RECT rect
= wxGetWindowRect(hWnd
);
942 set
= ::PtInRect(&rect
, point
) != 0;
947 ::SetCursor(GetHcursorOf(m_cursor
));
949 //else: will be set later when the mouse enters this window
955 void wxWindowMSW::WarpPointer(int x
, int y
)
957 ClientToScreen(&x
, &y
);
959 if ( !::SetCursorPos(x
, y
) )
961 wxLogLastError(wxT("SetCursorPos"));
965 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
967 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
968 // to use it on older systems -- and could possibly do some harm
969 static int s_needToUpdate
= -1;
970 if ( s_needToUpdate
== -1 )
973 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
977 if ( s_needToUpdate
)
979 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
980 // won't send WM_UPDATEUISTATE
981 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
985 // ---------------------------------------------------------------------------
987 // ---------------------------------------------------------------------------
992 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
994 #ifdef __WXMICROWIN__
995 return ::GetScrollPosWX(hWnd
, wOrient
);
997 WinStruct
<SCROLLINFO
> scrollInfo
;
998 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
999 scrollInfo
.fMask
= SIF_POS
;
1000 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
1002 return scrollInfo
.nPos
;
1007 inline UINT
WXOrientToSB(int orient
)
1009 return orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
;
1012 } // anonymous namespace
1014 int wxWindowMSW::GetScrollPos(int orient
) const
1016 HWND hWnd
= GetHwnd();
1017 wxCHECK_MSG( hWnd
, 0, wxT("no HWND in GetScrollPos") );
1019 return GetScrollPosition(hWnd
, WXOrientToSB(orient
));
1022 // This now returns the whole range, not just the number
1023 // of positions that we can scroll.
1024 int wxWindowMSW::GetScrollRange(int orient
) const
1027 HWND hWnd
= GetHwnd();
1030 WinStruct
<SCROLLINFO
> scrollInfo
;
1031 scrollInfo
.fMask
= SIF_RANGE
;
1032 if ( !::GetScrollInfo(hWnd
, WXOrientToSB(orient
), &scrollInfo
) )
1034 // Most of the time this is not really an error, since the return
1035 // value can also be zero when there is no scrollbar yet.
1036 // wxLogLastError(wxT("GetScrollInfo"));
1038 maxPos
= scrollInfo
.nMax
;
1040 // undo "range - 1" done in SetScrollbar()
1044 int wxWindowMSW::GetScrollThumb(int orient
) const
1046 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
1049 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
1051 HWND hWnd
= GetHwnd();
1052 wxCHECK_RET( hWnd
, wxT("SetScrollPos: no HWND") );
1054 WinStruct
<SCROLLINFO
> info
;
1058 info
.fMask
= SIF_POS
;
1059 if ( HasFlag(wxALWAYS_SHOW_SB
) )
1061 // disable scrollbar instead of removing it then
1062 info
.fMask
|= SIF_DISABLENOSCROLL
;
1065 ::SetScrollInfo(hWnd
, WXOrientToSB(orient
), &info
, refresh
);
1068 // New function that will replace some of the above.
1069 void wxWindowMSW::SetScrollbar(int orient
,
1075 // We have to set the variables here to make them valid in events
1076 // triggered by ::SetScrollInfo()
1077 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
1079 HWND hwnd
= GetHwnd();
1083 WinStruct
<SCROLLINFO
> info
;
1086 info
.nPage
= pageSize
;
1087 info
.nMin
= 0; // range is nMax - nMin + 1
1088 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
1091 // We normally also reenable scrollbar in case it had been previously
1092 // disabled by specifying SIF_DISABLENOSCROLL below but we should only
1093 // do this if it has valid range, otherwise it would be enabled but not
1095 if ( range
>= pageSize
)
1097 ::EnableScrollBar(hwnd
, WXOrientToSB(orient
), ESB_ENABLE_BOTH
);
1100 //else: leave all the fields to be 0
1102 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
1103 if ( HasFlag(wxALWAYS_SHOW_SB
) || range
== -1 )
1105 // disable scrollbar instead of removing it then
1106 info
.fMask
|= SIF_DISABLENOSCROLL
;
1109 ::SetScrollInfo(hwnd
, WXOrientToSB(orient
), &info
, refresh
);
1112 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
1118 wxCopyRectToRECT(*prect
, rect
);
1128 // FIXME: is this the exact equivalent of the line below?
1129 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
1131 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
1135 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
1137 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
1140 for ( int n
= 0; n
< count
; n
++ )
1142 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
1144 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
1145 if ( posNew
== pos
)
1147 // don't bother to continue, we're already at top/bottom
1154 return pos
!= posStart
;
1157 bool wxWindowMSW::ScrollLines(int lines
)
1159 bool down
= lines
> 0;
1161 return ScrollVertically(GetHwnd(),
1162 down
? SB_LINEDOWN
: SB_LINEUP
,
1163 down
? lines
: -lines
);
1166 bool wxWindowMSW::ScrollPages(int pages
)
1168 bool down
= pages
> 0;
1170 return ScrollVertically(GetHwnd(),
1171 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1172 down
? pages
: -pages
);
1175 // ----------------------------------------------------------------------------
1177 // ----------------------------------------------------------------------------
1179 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
1184 wxCHECK_RET( GetHwnd(),
1185 wxT("layout direction must be set after window creation") );
1187 LONG styleOld
= wxGetWindowExStyle(this);
1189 LONG styleNew
= styleOld
;
1192 case wxLayout_LeftToRight
:
1193 styleNew
&= ~WS_EX_LAYOUTRTL
;
1196 case wxLayout_RightToLeft
:
1197 styleNew
|= WS_EX_LAYOUTRTL
;
1201 wxFAIL_MSG(wxT("unsupported layout direction"));
1205 if ( styleNew
!= styleOld
)
1207 wxSetWindowExStyle(this, styleNew
);
1212 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1215 return wxLayout_Default
;
1217 wxCHECK_MSG( GetHwnd(), wxLayout_Default
, wxT("invalid window") );
1219 return wxHasWindowExStyle(this, WS_EX_LAYOUTRTL
) ? wxLayout_RightToLeft
1220 : wxLayout_LeftToRight
;
1225 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1226 wxCoord
WXUNUSED(width
),
1227 wxCoord
WXUNUSED(widthTotal
)) const
1229 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1230 // redo it ourselves
1234 // ---------------------------------------------------------------------------
1236 // ---------------------------------------------------------------------------
1238 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1240 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1242 HWND hwnd
= (HWND
)hWnd
;
1243 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1247 wxAssociateWinWithHandle(hwnd
, this);
1249 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1251 // we don't need to subclass the window of our own class (in the Windows
1252 // sense of the word)
1253 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1255 wxSetWindowProc(hwnd
, wxWndProc
);
1259 // don't bother restoring it either: this also makes it easy to
1260 // implement IsOfStandardClass() method which returns true for the
1261 // standard controls and false for the wxWidgets own windows as it can
1262 // simply check m_oldWndProc
1263 m_oldWndProc
= NULL
;
1266 // we're officially created now, send the event
1267 wxWindowCreateEvent
event((wxWindow
*)this);
1268 (void)HandleWindowEvent(event
);
1271 void wxWindowMSW::UnsubclassWin()
1273 wxRemoveHandleAssociation(this);
1275 // Restore old Window proc
1276 HWND hwnd
= GetHwnd();
1281 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1285 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1287 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1290 m_oldWndProc
= NULL
;
1295 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1299 if ( !::DestroyWindow(GetHwnd()) )
1301 wxLogLastError(wxT("DestroyWindow"));
1305 WXHWND wxhwnd
= (WXHWND
)handle
;
1307 // this also calls SetHWND(wxhwnd)
1308 SubclassWin(wxhwnd
);
1311 void wxWindowMSW::DissociateHandle()
1313 // this also calls SetHWND(0) for us
1318 bool wxCheckWindowWndProc(WXHWND hWnd
,
1319 WXFARPROC
WXUNUSED(wndProc
))
1321 const wxString
str(wxGetWindowClass(hWnd
));
1323 // TODO: get rid of wxTLWHiddenParent special case (currently it's not
1324 // registered by wxApp but using ad hoc code in msw/toplevel.cpp);
1325 // there is also a hidden window class used by sockets &c
1326 return wxApp::IsRegisteredClassName(str
) || str
== wxT("wxTLWHiddenParent");
1329 // ----------------------------------------------------------------------------
1331 // ----------------------------------------------------------------------------
1333 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1335 long flagsOld
= GetWindowStyleFlag();
1336 if ( flags
== flagsOld
)
1339 // update the internal variable
1340 wxWindowBase::SetWindowStyleFlag(flags
);
1342 // and the real window flags
1343 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1346 void wxWindowMSW::SetExtraStyle(long exflags
)
1348 long exflagsOld
= GetExtraStyle();
1349 if ( exflags
== exflagsOld
)
1352 // update the internal variable
1353 wxWindowBase::SetExtraStyle(exflags
);
1355 // and the real window flags
1356 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1359 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1361 // now update the Windows style as well if needed - and if the window had
1362 // been already created
1366 // we may need to call SetWindowPos() when we change some styles
1367 bool callSWP
= false;
1370 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1372 // this is quite a horrible hack but we need it because MSWGetStyle()
1373 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1374 // and so we have to modify the window exflags temporarily to get the
1375 // correct exstyleOld
1376 long exflagsNew
= GetExtraStyle();
1377 wxWindowBase::SetExtraStyle(exflagsOld
);
1380 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1382 wxWindowBase::SetExtraStyle(exflagsNew
);
1385 if ( style
!= styleOld
)
1387 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1388 // this function so instead of simply setting the style to the new
1389 // value we clear the bits which were set in styleOld but are set in
1390 // the new one and set the ones which were not set before
1391 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1392 styleReal
&= ~styleOld
;
1395 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1397 // we need to call SetWindowPos() if any of the styles affecting the
1398 // frame appearance have changed
1399 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1408 // and the extended style
1409 long exstyleReal
= wxGetWindowExStyle(this);
1411 if ( exstyle
!= exstyleOld
)
1413 exstyleReal
&= ~exstyleOld
;
1414 exstyleReal
|= exstyle
;
1416 wxSetWindowExStyle(this, exstyleReal
);
1418 // ex style changes don't take effect without calling SetWindowPos
1424 // we must call SetWindowPos() to flush the cached extended style and
1425 // also to make the change to wxSTAY_ON_TOP style take effect: just
1426 // setting the style simply doesn't work
1427 if ( !::SetWindowPos(GetHwnd(),
1428 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1431 SWP_NOMOVE
| SWP_NOSIZE
| SWP_FRAMECHANGED
) )
1433 wxLogLastError(wxT("SetWindowPos"));
1438 wxBorder
wxWindowMSW::GetDefaultBorderForControl() const
1440 return wxBORDER_THEME
;
1443 wxBorder
wxWindowMSW::GetDefaultBorder() const
1445 return wxWindowBase::GetDefaultBorder();
1448 // Translate wxBORDER_THEME (and other border styles if necessary) to the value
1449 // that makes most sense for this Windows environment
1450 wxBorder
wxWindowMSW::TranslateBorder(wxBorder border
) const
1452 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
1453 if (border
== wxBORDER_THEME
|| border
== wxBORDER_SUNKEN
|| border
== wxBORDER_SIMPLE
)
1454 return wxBORDER_SIMPLE
;
1456 return wxBORDER_NONE
;
1459 if (border
== wxBORDER_THEME
)
1461 if (CanApplyThemeBorder())
1463 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
1465 return wxBORDER_THEME
;
1467 return wxBORDER_SUNKEN
;
1475 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1477 // translate common wxWidgets styles to Windows ones
1479 // most of windows are child ones, those which are not (such as
1480 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1481 WXDWORD style
= WS_CHILD
;
1483 // using this flag results in very significant reduction in flicker,
1484 // especially with controls inside the static boxes (as the interior of the
1485 // box is not redrawn twice), but sometimes results in redraw problems, so
1486 // optionally allow the old code to continue to use it provided a special
1487 // system option is turned on
1488 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1489 || (flags
& wxCLIP_CHILDREN
) )
1490 style
|= WS_CLIPCHILDREN
;
1492 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1493 // don't support overlapping windows and it only makes sense for them and,
1494 // presumably, gives the system some extra work (to manage more clipping
1495 // regions), so avoid it alltogether
1498 if ( flags
& wxVSCROLL
)
1499 style
|= WS_VSCROLL
;
1501 if ( flags
& wxHSCROLL
)
1502 style
|= WS_HSCROLL
;
1504 const wxBorder border
= TranslateBorder(GetBorder(flags
));
1506 // After translation, border is now optimized for the specific version of Windows
1507 // and theme engine presence.
1509 // WS_BORDER is only required for wxBORDER_SIMPLE
1510 if ( border
== wxBORDER_SIMPLE
)
1513 // now deal with ext style if the caller wants it
1519 if ( flags
& wxTRANSPARENT_WINDOW
)
1520 *exstyle
|= WS_EX_TRANSPARENT
;
1526 case wxBORDER_DEFAULT
:
1527 wxFAIL_MSG( wxT("unknown border style") );
1531 case wxBORDER_SIMPLE
:
1532 case wxBORDER_THEME
:
1535 case wxBORDER_STATIC
:
1536 *exstyle
|= WS_EX_STATICEDGE
;
1539 case wxBORDER_RAISED
:
1540 *exstyle
|= WS_EX_DLGMODALFRAME
;
1543 case wxBORDER_SUNKEN
:
1544 *exstyle
|= WS_EX_CLIENTEDGE
;
1545 style
&= ~WS_BORDER
;
1548 // case wxBORDER_DOUBLE:
1549 // *exstyle |= WS_EX_DLGMODALFRAME;
1553 // wxUniv doesn't use Windows dialog navigation functions at all
1554 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1555 // to make the dialog navigation work with the nested panels we must
1556 // use this style (top level windows such as dialogs don't need it)
1557 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1559 *exstyle
|= WS_EX_CONTROLPARENT
;
1561 #endif // __WXUNIVERSAL__
1567 // Setup background and foreground colours correctly
1568 void wxWindowMSW::SetupColours()
1571 SetBackgroundColour(GetParent()->GetBackgroundColour());
1574 bool wxWindowMSW::IsMouseInWindow() const
1576 // get the mouse position
1579 ::GetCursorPosWinCE(&pt
);
1581 ::GetCursorPos(&pt
);
1584 // find the window which currently has the cursor and go up the window
1585 // chain until we find this window - or exhaust it
1586 HWND hwnd
= ::WindowFromPoint(pt
);
1587 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1588 hwnd
= ::GetParent(hwnd
);
1590 return hwnd
!= NULL
;
1593 void wxWindowMSW::OnInternalIdle()
1595 #ifndef HAVE_TRACKMOUSEEVENT
1596 // Check if we need to send a LEAVE event
1597 if ( m_mouseInWindow
)
1599 // note that we should generate the leave event whether the window has
1600 // or doesn't have mouse capture
1601 if ( !IsMouseInWindow() )
1603 GenerateMouseLeave();
1606 #endif // !HAVE_TRACKMOUSEEVENT
1608 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1609 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1612 // Set this window to be the child of 'parent'.
1613 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1615 if ( !wxWindowBase::Reparent(parent
) )
1618 HWND hWndChild
= GetHwnd();
1619 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1621 ::SetParent(hWndChild
, hWndParent
);
1624 if ( wxHasWindowExStyle(this, WS_EX_CONTROLPARENT
) )
1626 EnsureParentHasControlParentStyle(GetParent());
1628 #endif // !__WXWINCE__
1633 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1635 #ifndef __WXMICROWIN__
1636 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1640 void wxWindowMSW::DoFreeze()
1643 return; // no point in freezing hidden window
1645 SendSetRedraw(GetHwnd(), false);
1648 void wxWindowMSW::DoThaw()
1651 return; // hidden windows aren't frozen by DoFreeze
1653 SendSetRedraw(GetHwnd(), true);
1655 // we need to refresh everything or otherwise the invalidated area
1656 // is not going to be repainted
1660 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1662 HWND hWnd
= GetHwnd();
1669 wxCopyRectToRECT(*rect
, mswRect
);
1677 // RedrawWindow not available on SmartPhone or eVC++ 3
1678 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1679 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1683 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1685 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1690 void wxWindowMSW::Update()
1692 if ( !::UpdateWindow(GetHwnd()) )
1694 wxLogLastError(wxT("UpdateWindow"));
1697 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1698 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1699 // handler needs to be really drawn right now
1704 // ---------------------------------------------------------------------------
1706 // ---------------------------------------------------------------------------
1708 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1712 // we need to lower the sibling static boxes so controls contained within can be
1714 static void AdjustStaticBoxZOrder(wxWindow
*parent
)
1716 // no sibling static boxes if we have no parent (ie TLW)
1720 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1722 node
= node
->GetNext() )
1724 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1727 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1728 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1733 #else // !wxUSE_STATBOX
1735 static inline void AdjustStaticBoxZOrder(wxWindow
* WXUNUSED(parent
))
1739 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1741 #endif // drag and drop is used
1743 #if wxUSE_DRAG_AND_DROP
1744 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1746 if ( m_dropTarget
!= 0 ) {
1747 m_dropTarget
->Revoke(m_hWnd
);
1748 delete m_dropTarget
;
1751 m_dropTarget
= pDropTarget
;
1752 if ( m_dropTarget
!= 0 )
1754 AdjustStaticBoxZOrder(GetParent());
1755 m_dropTarget
->Register(m_hWnd
);
1758 #endif // wxUSE_DRAG_AND_DROP
1760 // old-style file manager drag&drop support: we retain the old-style
1761 // DragAcceptFiles in parallel with SetDropTarget.
1762 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1765 HWND hWnd
= GetHwnd();
1768 AdjustStaticBoxZOrder(GetParent());
1769 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1774 // ----------------------------------------------------------------------------
1776 // ----------------------------------------------------------------------------
1780 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1782 wxWindowBase::DoSetToolTip(tooltip
);
1785 m_tooltip
->SetWindow((wxWindow
*)this);
1788 #endif // wxUSE_TOOLTIPS
1790 // ---------------------------------------------------------------------------
1791 // moving and resizing
1792 // ---------------------------------------------------------------------------
1794 bool wxWindowMSW::IsSizeDeferred() const
1796 #if wxUSE_DEFERRED_SIZING
1797 if ( m_pendingPosition
!= wxDefaultPosition
||
1798 m_pendingSize
!= wxDefaultSize
)
1800 #endif // wxUSE_DEFERRED_SIZING
1806 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1808 #if wxUSE_DEFERRED_SIZING
1809 // if SetSize() had been called at wx level but not realized at Windows
1810 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1811 // the new and not the old position to the other wx code
1812 if ( m_pendingSize
!= wxDefaultSize
)
1815 *x
= m_pendingSize
.x
;
1817 *y
= m_pendingSize
.y
;
1819 else // use current size
1820 #endif // wxUSE_DEFERRED_SIZING
1822 RECT rect
= wxGetWindowRect(GetHwnd());
1825 *x
= rect
.right
- rect
.left
;
1827 *y
= rect
.bottom
- rect
.top
;
1831 // Get size *available for subwindows* i.e. excluding menu bar etc.
1832 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1834 #if wxUSE_DEFERRED_SIZING
1835 if ( m_pendingSize
!= wxDefaultSize
)
1837 // we need to calculate the client size corresponding to pending size
1839 // FIXME: Unfortunately this doesn't work correctly for the maximized
1840 // top level windows, the returned values are too small (e.g.
1841 // under Windows 7 on a 1600*1200 screen with task bar on the
1842 // right the pending size for a maximized window is 1538*1200
1843 // and WM_NCCALCSIZE returns 1528*1172 even though the correct
1844 // client size of such window is 1538*1182). No idea how to fix
1845 // it though, setting WS_MAXIMIZE in GWL_STYLE before calling
1846 // WM_NCCALCSIZE doesn't help and AdjustWindowRectEx() doesn't
1847 // work in this direction neither. So we just have to live with
1848 // the slightly wrong results and relayout the window when it
1849 // gets finally shown in its maximized state (see #11762).
1851 rect
.left
= m_pendingPosition
.x
;
1852 rect
.top
= m_pendingPosition
.y
;
1853 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1854 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1856 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1859 *x
= rect
.right
- rect
.left
;
1861 *y
= rect
.bottom
- rect
.top
;
1864 #endif // wxUSE_DEFERRED_SIZING
1866 RECT rect
= wxGetClientRect(GetHwnd());
1875 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1877 wxWindow
* const parent
= GetParent();
1880 #if wxUSE_DEFERRED_SIZING
1881 if ( m_pendingPosition
!= wxDefaultPosition
)
1883 pos
= m_pendingPosition
;
1885 else // use current position
1886 #endif // wxUSE_DEFERRED_SIZING
1888 RECT rect
= wxGetWindowRect(GetHwnd());
1891 point
.x
= rect
.left
;
1894 // we do the adjustments with respect to the parent only for the "real"
1895 // children, not for the dialogs/frames
1896 if ( !IsTopLevel() )
1898 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
1900 // In RTL mode, we want the logical left x-coordinate,
1901 // which would be the physical right x-coordinate.
1902 point
.x
= rect
.right
;
1905 // Since we now have the absolute screen coords, if there's a
1906 // parent we must subtract its top left corner
1909 ::ScreenToClient(GetHwndOf(parent
), &point
);
1917 // we also must adjust by the client area offset: a control which is just
1918 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1919 if ( parent
&& !IsTopLevel() )
1921 const wxPoint
pt(parent
->GetClientAreaOrigin());
1932 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1940 ::ScreenToClient(GetHwnd(), &pt
);
1948 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1956 ::ClientToScreen(GetHwnd(), &pt
);
1965 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1967 #if wxUSE_DEFERRED_SIZING
1968 // if our parent had prepared a defer window handle for us, use it (unless
1969 // we are a top level window)
1970 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1972 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1975 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1976 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1979 wxLogLastError(wxT("DeferWindowPos"));
1985 // hdwp must be updated as it may have been changed
1986 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1991 // did deferred move, remember new coordinates of the window as they're
1992 // different from what Windows would return for it
1996 // otherwise (or if deferring failed) move the window in place immediately
1997 #endif // wxUSE_DEFERRED_SIZING
1998 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
2000 wxLogLastError(wxT("MoveWindow"));
2003 // if wxUSE_DEFERRED_SIZING, indicates that we didn't use deferred move,
2004 // ignored otherwise
2008 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
2010 // TODO: is this consistent with other platforms?
2011 // Still, negative width or height shouldn't be allowed
2017 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
2019 #if wxUSE_DEFERRED_SIZING
2020 m_pendingPosition
= wxPoint(x
, y
);
2021 m_pendingSize
= wxSize(width
, height
);
2023 else // window was moved immediately, without deferring it
2025 m_pendingPosition
= wxDefaultPosition
;
2026 m_pendingSize
= wxDefaultSize
;
2027 #endif // wxUSE_DEFERRED_SIZING
2031 // set the size of the window: if the dimensions are positive, just use them,
2032 // but if any of them is equal to -1, it means that we must find the value for
2033 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
2034 // which case -1 is a valid value for x and y)
2036 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
2037 // the width/height to best suit our contents, otherwise we reuse the current
2039 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
2041 // get the current size and position...
2042 int currentX
, currentY
;
2043 int currentW
, currentH
;
2045 GetPosition(¤tX
, ¤tY
);
2046 GetSize(¤tW
, ¤tH
);
2048 // ... and don't do anything (avoiding flicker) if it's already ok unless
2049 // we're forced to resize the window
2050 if ( x
== currentX
&& y
== currentY
&&
2051 width
== currentW
&& height
== currentH
&&
2052 !(sizeFlags
& wxSIZE_FORCE
) )
2054 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
2056 wxSizeEvent
event( wxSize(width
,height
), GetId() );
2057 event
.SetEventObject( this );
2058 HandleWindowEvent( event
);
2063 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2065 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2068 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2070 wxSize size
= wxDefaultSize
;
2071 if ( width
== wxDefaultCoord
)
2073 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2075 size
= GetBestSize();
2080 // just take the current one
2085 if ( height
== wxDefaultCoord
)
2087 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2089 if ( size
.x
== wxDefaultCoord
)
2091 size
= GetBestSize();
2093 //else: already called GetBestSize() above
2099 // just take the current one
2104 DoMoveWindow(x
, y
, width
, height
);
2107 void wxWindowMSW::DoSetClientSize(int width
, int height
)
2109 // setting the client size is less obvious than it could have been
2110 // because in the result of changing the total size the window scrollbar
2111 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
2112 // doesn't take neither into account) and so the client size will not be
2113 // correct as the difference between the total and client size changes --
2114 // so we keep changing it until we get it right
2116 // normally this loop shouldn't take more than 3 iterations (usually 1 but
2117 // if scrollbars [dis]appear as the result of the first call, then 2 and it
2118 // may become 3 if the window had 0 size originally and so we didn't
2119 // calculate the scrollbar correction correctly during the first iteration)
2120 // but just to be on the safe side we check for it instead of making it an
2121 // "infinite" loop (i.e. leaving break inside as the only way to get out)
2122 for ( int i
= 0; i
< 4; i
++ )
2125 ::GetClientRect(GetHwnd(), &rectClient
);
2127 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
2128 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
2129 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
2134 // Find the difference between the entire window (title bar and all)
2135 // and the client area; add this to the new client size to move the
2138 ::GetWindowRect(GetHwnd(), &rectWin
);
2140 const int widthWin
= rectWin
.right
- rectWin
.left
,
2141 heightWin
= rectWin
.bottom
- rectWin
.top
;
2143 // MoveWindow positions the child windows relative to the parent, so
2144 // adjust if necessary
2145 if ( !IsTopLevel() )
2147 wxWindow
*parent
= GetParent();
2150 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
2154 // don't call DoMoveWindow() because we want to move window immediately
2155 // and not defer it here as otherwise the value returned by
2156 // GetClient/WindowRect() wouldn't change as the window wouldn't be
2158 if ( !::MoveWindow(GetHwnd(),
2161 width
+ widthWin
- rectClient
.right
,
2162 height
+ heightWin
- rectClient
.bottom
,
2165 wxLogLastError(wxT("MoveWindow"));
2170 wxSize
wxWindowMSW::DoGetBorderSize() const
2173 switch ( GetBorder() )
2175 case wxBORDER_STATIC
:
2176 case wxBORDER_SIMPLE
:
2180 case wxBORDER_SUNKEN
:
2184 case wxBORDER_RAISED
:
2185 case wxBORDER_DOUBLE
:
2190 wxFAIL_MSG( wxT("unknown border style") );
2197 return 2*wxSize(border
, border
);
2200 // ---------------------------------------------------------------------------
2202 // ---------------------------------------------------------------------------
2204 int wxWindowMSW::GetCharHeight() const
2206 return wxGetTextMetrics(this).tmHeight
;
2209 int wxWindowMSW::GetCharWidth() const
2211 // +1 is needed because Windows apparently adds it when calculating the
2212 // dialog units size in pixels
2213 #if wxDIALOG_UNIT_COMPATIBILITY
2214 return wxGetTextMetrics(this).tmAveCharWidth
;
2216 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
2220 void wxWindowMSW::DoGetTextExtent(const wxString
& string
,
2223 int *externalLeading
,
2224 const wxFont
*fontToUse
) const
2226 wxASSERT_MSG( !fontToUse
|| fontToUse
->Ok(),
2227 wxT("invalid font in GetTextExtent()") );
2231 hfontToUse
= GetHfontOf(*fontToUse
);
2233 hfontToUse
= GetHfontOf(GetFont());
2235 WindowHDC
hdc(GetHwnd());
2236 SelectInHDC
selectFont(hdc
, hfontToUse
);
2240 ::GetTextExtentPoint32(hdc
, string
.wx_str(), string
.length(), &sizeRect
);
2241 GetTextMetrics(hdc
, &tm
);
2248 *descent
= tm
.tmDescent
;
2249 if ( externalLeading
)
2250 *externalLeading
= tm
.tmExternalLeading
;
2253 // ---------------------------------------------------------------------------
2255 // ---------------------------------------------------------------------------
2257 #if wxUSE_MENUS_NATIVE
2259 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2260 // immediately, without waiting for the next event loop iteration
2262 // NB: this function should probably be made public later as it can almost
2263 // surely replace wxYield() elsewhere as well
2264 static void wxYieldForCommandsOnly()
2266 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2267 // want to process it here)
2269 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2271 if ( msg
.message
== WM_QUIT
)
2273 // if we retrieved a WM_QUIT, insert back into the message queue.
2274 ::PostQuitMessage(0);
2278 // luckily (as we don't have access to wxEventLoopImpl method from here
2279 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2281 ::TranslateMessage(&msg
);
2282 ::DispatchMessage(&msg
);
2286 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2290 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2292 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2293 x
= mouse
.x
; y
= mouse
.y
;
2296 HWND hWnd
= GetHwnd();
2297 HMENU hMenu
= GetHmenuOf(menu
);
2301 ::ClientToScreen(hWnd
, &point
);
2302 #if defined(__WXWINCE__)
2303 static const UINT flags
= 0;
2304 #else // !__WXWINCE__
2305 UINT flags
= TPM_RIGHTBUTTON
;
2306 // NT4 doesn't support TPM_RECURSE and simply doesn't show the menu at all
2307 // when it's use, I'm not sure about Win95/98 but prefer to err on the safe
2308 // side and not to use it there neither -- modify the test if it does work
2310 if ( wxGetWinVersion() >= wxWinVersion_5
)
2312 // using TPM_RECURSE allows us to show a popup menu while another menu
2313 // is opened which can be useful and is supported by the other
2314 // platforms, so allow it under Windows too
2315 flags
|= TPM_RECURSE
;
2317 #endif // __WXWINCE__/!__WXWINCE__
2319 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2321 // we need to do it right now as otherwise the events are never going to be
2322 // sent to wxCurrentPopupMenu from HandleCommand()
2324 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2325 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2326 // destroyed as soon as we return (it can be a local variable in the caller
2327 // for example) and so we do need to process the event immediately
2328 wxYieldForCommandsOnly();
2333 #endif // wxUSE_MENUS_NATIVE
2335 // ===========================================================================
2336 // pre/post message processing
2337 // ===========================================================================
2339 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2342 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2344 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2347 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2349 // wxUniversal implements tab traversal itself
2350 #ifndef __WXUNIVERSAL__
2351 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2353 // intercept dialog navigation keys
2354 MSG
*msg
= (MSG
*)pMsg
;
2356 // here we try to do all the job which ::IsDialogMessage() usually does
2358 if ( msg
->message
== WM_KEYDOWN
)
2360 bool bCtrlDown
= wxIsCtrlDown();
2361 bool bShiftDown
= wxIsShiftDown();
2363 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2364 // don't process it if it's the case (except for Ctrl-Tab/Enter
2365 // combinations which are always processed)
2366 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2368 // surprisingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2369 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2370 // it, of course, implies them
2371 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2373 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2376 bool bForward
= true,
2377 bWindowChange
= false,
2380 // should we process this message specially?
2381 bool bProcess
= true;
2382 switch ( msg
->wParam
)
2385 if ( (lDlgCode
& DLGC_WANTTAB
) && !bCtrlDown
)
2387 // let the control have the TAB
2390 else // use it for navigation
2392 // Ctrl-Tab cycles thru notebook pages
2393 bWindowChange
= bCtrlDown
;
2394 bForward
= !bShiftDown
;
2401 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2409 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2418 // we treat PageUp/Dn as arrows because chances are that
2419 // a control which needs arrows also needs them for
2420 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2421 if ( (lDlgCode
& DLGC_WANTARROWS
) && !bCtrlDown
)
2423 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
2424 bWindowChange
= true;
2430 // currently active button should get enter press even
2431 // if there is a default button elsewhere so check if
2432 // this window is a button first
2433 wxWindow
*btn
= NULL
;
2434 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2436 // let IsDialogMessage() handle this for all
2437 // buttons except the owner-drawn ones which it
2438 // just seems to ignore
2439 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2440 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2442 // emulate the button click
2443 btn
= wxFindWinFromHandle(msg
->hwnd
);
2448 else // not a button itself, do we have default button?
2450 // check if this window or any of its ancestors
2451 // wants the message for itself (we always reserve
2452 // Ctrl-Enter for dialog navigation though)
2453 wxWindow
*win
= this;
2456 // this will contain the dialog code of this
2457 // window and all of its parent windows in turn
2458 LONG lDlgCode2
= lDlgCode
;
2462 if ( lDlgCode2
& DLGC_WANTMESSAGE
)
2464 // as it wants to process Enter itself,
2465 // don't call IsDialogMessage() which
2470 // don't propagate keyboard messages beyond
2471 // the first top level window parent
2472 if ( win
->IsTopLevel() )
2475 win
= win
->GetParent();
2477 lDlgCode2
= ::SendMessage
2488 win
= wxGetTopLevelParent(win
);
2491 wxTopLevelWindow
* const
2492 tlw
= wxDynamicCast(win
, wxTopLevelWindow
);
2495 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2500 if ( btn
&& btn
->IsEnabled() )
2502 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2506 #endif // wxUSE_BUTTON
2509 // map Enter presses into button presses on PDAs
2510 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2511 event
.SetEventObject(this);
2512 if ( HandleWindowEvent(event
) )
2514 #endif // __WXWINCE__
2524 wxNavigationKeyEvent event
;
2525 event
.SetDirection(bForward
);
2526 event
.SetWindowChange(bWindowChange
);
2527 event
.SetFromTab(bFromTab
);
2528 event
.SetEventObject(this);
2530 if ( HandleWindowEvent(event
) )
2532 // as we don't call IsDialogMessage(), which would take of
2533 // this by default, we need to manually send this message
2534 // so that controls can change their UI state if needed
2535 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2542 if ( ::IsDialogMessage(GetHwnd(), msg
) )
2544 // IsDialogMessage() did something...
2548 #endif // __WXUNIVERSAL__
2553 // relay mouse move events to the tooltip control
2554 MSG
*msg
= (MSG
*)pMsg
;
2555 if ( msg
->message
== WM_MOUSEMOVE
)
2556 wxToolTip::RelayEvent(pMsg
);
2558 #endif // wxUSE_TOOLTIPS
2563 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2565 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2566 return m_acceleratorTable
.Translate(this, pMsg
);
2570 #endif // wxUSE_ACCEL
2573 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* msg
)
2575 // all tests below have to deal with various bugs/misfeatures of
2576 // IsDialogMessage(): we have to prevent it from being called from our
2577 // MSWProcessMessage() in some situations
2579 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2580 // message even when there is no cancel button and when the message is
2581 // needed by the control itself: in particular, it prevents the tree in
2582 // place edit control from being closed with Escape in a dialog
2583 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_ESCAPE
)
2588 // ::IsDialogMessage() is broken and may sometimes hang the application by
2589 // going into an infinite loop when it tries to find the control to give
2590 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2591 // situations when this may happen and not call it then
2592 if ( msg
->message
!= WM_SYSCHAR
)
2595 // assume we can call it by default
2596 bool canSafelyCallIsDlgMsg
= true;
2598 HWND hwndFocus
= ::GetFocus();
2600 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2601 // ::IsDialogMessage() will also enter an infinite loop, because it will
2602 // recursively check the child windows but not the window itself and so if
2603 // none of the children accepts focus it loops forever (as it only stops
2604 // when it gets back to the window it started from)
2606 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2607 // style has the focus, it can happen. One such possibility is if
2608 // all windows are either toplevel, wxDialog, wxPanel or static
2609 // controls and no window can actually accept keyboard input.
2610 #if !defined(__WXWINCE__)
2611 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2613 // pessimistic by default
2614 canSafelyCallIsDlgMsg
= false;
2615 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2617 node
= node
->GetNext() )
2619 wxWindow
* const win
= node
->GetData();
2620 if ( win
->CanAcceptFocus() &&
2621 !wxHasWindowExStyle(win
, WS_EX_CONTROLPARENT
) )
2623 // it shouldn't hang...
2624 canSafelyCallIsDlgMsg
= true;
2630 #endif // !__WXWINCE__
2632 if ( canSafelyCallIsDlgMsg
)
2634 // ::IsDialogMessage() can enter in an infinite loop when the
2635 // currently focused window is disabled or hidden and its
2636 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2640 if ( !::IsWindowEnabled(hwndFocus
) ||
2641 !::IsWindowVisible(hwndFocus
) )
2643 // it would enter an infinite loop if we do this!
2644 canSafelyCallIsDlgMsg
= false;
2649 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2651 // it's a top level window, don't go further -- e.g. even
2652 // if the parent of a dialog is disabled, this doesn't
2653 // break navigation inside the dialog
2657 hwndFocus
= ::GetParent(hwndFocus
);
2661 return canSafelyCallIsDlgMsg
;
2664 // ---------------------------------------------------------------------------
2665 // message params unpackers
2666 // ---------------------------------------------------------------------------
2668 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2669 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2671 *id
= LOWORD(wParam
);
2672 *hwnd
= (WXHWND
)lParam
;
2673 *cmd
= HIWORD(wParam
);
2676 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2677 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2679 *state
= LOWORD(wParam
);
2680 *minimized
= HIWORD(wParam
);
2681 *hwnd
= (WXHWND
)lParam
;
2684 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2685 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2687 *code
= LOWORD(wParam
);
2688 *pos
= HIWORD(wParam
);
2689 *hwnd
= (WXHWND
)lParam
;
2692 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2693 WXHDC
*hdc
, WXHWND
*hwnd
)
2695 *hwnd
= (WXHWND
)lParam
;
2696 *hdc
= (WXHDC
)wParam
;
2699 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2700 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2702 *item
= (WXWORD
)wParam
;
2703 *flags
= HIWORD(wParam
);
2704 *hmenu
= (WXHMENU
)lParam
;
2707 // ---------------------------------------------------------------------------
2708 // Main wxWidgets window proc and the window proc for wxWindow
2709 // ---------------------------------------------------------------------------
2711 // Hook for new window just as it's being created, when the window isn't yet
2712 // associated with the handle
2713 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2715 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2716 // window being created and insures that it's always unset back later
2717 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2719 gs_winBeingCreated
= winBeingCreated
;
2722 wxWindowCreationHook::~wxWindowCreationHook()
2724 gs_winBeingCreated
= NULL
;
2728 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2730 // trace all messages: useful for the debugging but noticeably slows down
2731 // the code so don't do it by default
2732 #if wxDEBUG_LEVEL >= 2
2733 // notice that we cast wParam and lParam to long to avoid mismatch with
2734 // format specifiers in 64 bit builds where they are both int64 quantities
2736 // casting like this loses information, of course, but it shouldn't matter
2737 // much for this diagnostic code and it keeps the code simple
2738 wxLogTrace("winmsg",
2739 wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"),
2740 wxGetMessageName(message
), hWnd
, (long)wParam
, (long)lParam
);
2741 #endif // wxDEBUG_LEVEL >= 2
2743 wxWindowMSW
*wnd
= wxFindWinFromHandle(hWnd
);
2745 // when we get the first message for the HWND we just created, we associate
2746 // it with wxWindow stored in gs_winBeingCreated
2747 if ( !wnd
&& gs_winBeingCreated
)
2749 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2750 wnd
= gs_winBeingCreated
;
2751 gs_winBeingCreated
= NULL
;
2752 wnd
->SetHWND((WXHWND
)hWnd
);
2757 if ( wnd
&& wxGUIEventLoop::AllowProcessing(wnd
) )
2758 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2760 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2765 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2767 // did we process the message?
2768 bool processed
= false;
2778 // for most messages we should return 0 when we do process the message
2786 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2789 // return 0 to allow window creation
2790 rc
.result
= mayCreate
? 0 : -1;
2796 // never set processed to true and *always* pass WM_DESTROY to
2797 // DefWindowProc() as Windows may do some internal cleanup when
2798 // processing it and failing to pass the message along may cause
2799 // memory and resource leaks!
2800 (void)HandleDestroy();
2804 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2808 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2811 #if !defined(__WXWINCE__)
2814 LPRECT pRect
= (LPRECT
)lParam
;
2816 rc
.SetLeft(pRect
->left
);
2817 rc
.SetTop(pRect
->top
);
2818 rc
.SetRight(pRect
->right
);
2819 rc
.SetBottom(pRect
->bottom
);
2820 processed
= HandleMoving(rc
);
2822 pRect
->left
= rc
.GetLeft();
2823 pRect
->top
= rc
.GetTop();
2824 pRect
->right
= rc
.GetRight();
2825 pRect
->bottom
= rc
.GetBottom();
2830 case WM_ENTERSIZEMOVE
:
2832 processed
= HandleEnterSizeMove();
2836 case WM_EXITSIZEMOVE
:
2838 processed
= HandleExitSizeMove();
2844 LPRECT pRect
= (LPRECT
)lParam
;
2846 rc
.SetLeft(pRect
->left
);
2847 rc
.SetTop(pRect
->top
);
2848 rc
.SetRight(pRect
->right
);
2849 rc
.SetBottom(pRect
->bottom
);
2850 processed
= HandleSizing(rc
);
2852 pRect
->left
= rc
.GetLeft();
2853 pRect
->top
= rc
.GetTop();
2854 pRect
->right
= rc
.GetRight();
2855 pRect
->bottom
= rc
.GetBottom();
2859 #endif // !__WXWINCE__
2861 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2862 case WM_ACTIVATEAPP
:
2863 // This implicitly sends a wxEVT_ACTIVATE_APP event
2864 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2870 WXWORD state
, minimized
;
2872 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2874 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2879 processed
= HandleSetFocus((WXHWND
)wParam
);
2883 processed
= HandleKillFocus((WXHWND
)wParam
);
2886 case WM_PRINTCLIENT
:
2887 processed
= HandlePrintClient((WXHDC
)wParam
);
2893 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2895 processed
= HandlePaint();
2899 processed
= HandlePaint();
2904 #ifdef __WXUNIVERSAL__
2905 // Universal uses its own wxFrame/wxDialog, so we don't receive
2906 // close events unless we have this.
2908 #endif // __WXUNIVERSAL__
2910 // don't let the DefWindowProc() destroy our window - we'll do it
2911 // ourselves in ~wxWindow
2917 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2921 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2922 GET_Y_LPARAM(lParam
),
2926 #ifdef HAVE_TRACKMOUSEEVENT
2928 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2930 if ( m_mouseInWindow
)
2932 GenerateMouseLeave();
2935 // always pass processed back as false, this allows the window
2936 // manager to process the message too. This is needed to
2937 // ensure windows XP themes work properly as the mouse moves
2938 // over widgets like buttons. So don't set processed to true here.
2940 #endif // HAVE_TRACKMOUSEEVENT
2942 #if wxUSE_MOUSEWHEEL
2944 processed
= HandleMouseWheel(wParam
, lParam
);
2948 case WM_LBUTTONDOWN
:
2950 case WM_LBUTTONDBLCLK
:
2951 case WM_RBUTTONDOWN
:
2953 case WM_RBUTTONDBLCLK
:
2954 case WM_MBUTTONDOWN
:
2956 case WM_MBUTTONDBLCLK
:
2957 #ifdef wxHAS_XBUTTON
2958 case WM_XBUTTONDOWN
:
2960 case WM_XBUTTONDBLCLK
:
2961 #endif // wxHAS_XBUTTON
2963 #ifdef __WXMICROWIN__
2964 // MicroWindows seems to ignore the fact that a window is
2965 // disabled. So catch mouse events and throw them away if
2967 wxWindowMSW
* win
= this;
2970 if (!win
->IsEnabled())
2976 win
= win
->GetParent();
2977 if ( !win
|| win
->IsTopLevel() )
2984 #endif // __WXMICROWIN__
2985 int x
= GET_X_LPARAM(lParam
),
2986 y
= GET_Y_LPARAM(lParam
);
2989 // redirect the event to a static control if necessary by
2990 // finding one under mouse because under CE the static controls
2991 // don't generate mouse events (even with SS_NOTIFY)
2993 if ( GetCapture() == this )
2995 // but don't do it if the mouse is captured by this window
2996 // because then it should really get this event itself
3001 win
= FindWindowForMouseEvent(this, &x
, &y
);
3003 // this should never happen
3004 wxCHECK_MSG( win
, 0,
3005 wxT("FindWindowForMouseEvent() returned NULL") );
3008 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
3010 SHRGINFO shrgi
= {0};
3012 shrgi
.cbSize
= sizeof(SHRGINFO
);
3013 shrgi
.hwndClient
= (HWND
) GetHWND();
3017 shrgi
.dwFlags
= SHRG_RETURNCMD
;
3018 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
3020 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
3023 pt
= ClientToScreen(pt
);
3025 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3027 evtCtx
.SetEventObject(this);
3028 if (HandleWindowEvent(evtCtx
))
3037 #else // !__WXWINCE__
3038 wxWindowMSW
*win
= this;
3039 #endif // __WXWINCE__/!__WXWINCE__
3041 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
3043 // if the app didn't eat the event, handle it in the default
3044 // way, that is by giving this window the focus
3047 // for the standard classes their WndProc sets the focus to
3048 // them anyhow and doing it from here results in some weird
3049 // problems, so don't do it for them (unnecessary anyhow)
3050 if ( !win
->IsOfStandardClass() )
3052 if ( message
== WM_LBUTTONDOWN
&& win
->IsFocusable() )
3064 case MM_JOY1BUTTONDOWN
:
3065 case MM_JOY2BUTTONDOWN
:
3066 case MM_JOY1BUTTONUP
:
3067 case MM_JOY2BUTTONUP
:
3068 processed
= HandleJoystickEvent(message
,
3069 GET_X_LPARAM(lParam
),
3070 GET_Y_LPARAM(lParam
),
3073 #endif // __WXMICROWIN__
3079 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
3081 processed
= HandleCommand(id
, cmd
, hwnd
);
3086 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
3089 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
3090 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
3091 // apparently doesn't always behave properly and needs some help
3092 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
3093 case WM_NOTIFYFORMAT
:
3094 if ( lParam
== NF_QUERY
)
3097 rc
.result
= NFR_UNICODE
;
3100 #endif // wxUSE_UNICODE_MSLU
3102 // for these messages we must return true if process the message
3105 processed
= MSWOnDrawItem(wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
3110 case WM_MEASUREITEM
:
3111 processed
= MSWOnMeasureItem(wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
3115 #endif // defined(WM_DRAWITEM)
3118 if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS
) )
3120 // we always want to get the char events
3121 rc
.result
= DLGC_WANTCHARS
;
3123 if ( HasFlag(wxWANTS_CHARS
) )
3125 // in fact, we want everything
3126 rc
.result
|= DLGC_WANTARROWS
|
3133 //else: get the dlg code from the DefWindowProc()
3138 // If this has been processed by an event handler, return 0 now
3139 // (we've handled it).
3140 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
3141 if ( m_lastKeydownProcessed
)
3150 // we consider these messages "not interesting" to OnChar, so
3151 // just don't do anything more with them
3161 // avoid duplicate messages to OnChar for these ASCII keys:
3162 // they will be translated by TranslateMessage() and received
3195 // but set processed to false, not true to still pass them
3196 // to the control's default window proc - otherwise
3197 // built-in keyboard handling won't work
3202 // special case of VK_APPS: treat it the same as right mouse
3203 // click because both usually pop up a context menu
3205 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
3210 // do generate a CHAR event
3211 processed
= HandleChar((WORD
)wParam
, lParam
);
3214 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
3221 // special case of VK_APPS: treat it the same as right mouse button
3222 if ( wParam
== VK_APPS
)
3224 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
3229 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
3234 case WM_CHAR
: // Always an ASCII character
3235 if ( m_lastKeydownProcessed
)
3237 // The key was handled in the EVT_KEY_DOWN and handling
3238 // a key in an EVT_KEY_DOWN handler is meant, by
3239 // design, to prevent EVT_CHARs from happening
3240 m_lastKeydownProcessed
= false;
3245 processed
= HandleChar((WORD
)wParam
, lParam
, true);
3251 processed
= HandleHotKey((WORD
)wParam
, lParam
);
3253 #endif // wxUSE_HOTKEY
3258 processed
= HandleClipboardEvent(message
);
3266 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
3268 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
3274 // CTLCOLOR messages are sent by children to query the parent for their
3276 #ifndef __WXMICROWIN__
3277 case WM_CTLCOLORMSGBOX
:
3278 case WM_CTLCOLOREDIT
:
3279 case WM_CTLCOLORLISTBOX
:
3280 case WM_CTLCOLORBTN
:
3281 case WM_CTLCOLORDLG
:
3282 case WM_CTLCOLORSCROLLBAR
:
3283 case WM_CTLCOLORSTATIC
:
3287 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
3289 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
3292 #endif // !__WXMICROWIN__
3294 case WM_SYSCOLORCHANGE
:
3295 // the return value for this message is ignored
3296 processed
= HandleSysColorChange();
3299 #if !defined(__WXWINCE__)
3300 case WM_DISPLAYCHANGE
:
3301 processed
= HandleDisplayChange();
3305 case WM_PALETTECHANGED
:
3306 processed
= HandlePaletteChanged((WXHWND
)wParam
);
3309 case WM_CAPTURECHANGED
:
3310 processed
= HandleCaptureChanged((WXHWND
)lParam
);
3313 case WM_SETTINGCHANGE
:
3314 processed
= HandleSettingChange(wParam
, lParam
);
3317 case WM_QUERYNEWPALETTE
:
3318 processed
= HandleQueryNewPalette();
3323 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
3324 // check if an override was configured for this window
3325 EraseBgHooks::const_iterator it
= gs_eraseBgHooks
.find(this);
3326 if ( it
!= gs_eraseBgHooks
.end() )
3327 processed
= it
->second
->MSWEraseBgHook((WXHDC
)wParam
);
3329 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
3330 processed
= HandleEraseBkgnd((WXHDC
)wParam
);
3335 // we processed the message, i.e. erased the background
3340 #if !defined(__WXWINCE__)
3342 processed
= HandleDropFiles(wParam
);
3347 processed
= HandleInitDialog((WXHWND
)wParam
);
3351 // we never set focus from here
3356 #if !defined(__WXWINCE__)
3357 case WM_QUERYENDSESSION
:
3358 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3362 processed
= HandleEndSession(wParam
!= 0, lParam
);
3365 case WM_GETMINMAXINFO
:
3366 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3371 processed
= HandleSetCursor((WXHWND
)wParam
,
3372 LOWORD(lParam
), // hit test
3373 HIWORD(lParam
)); // mouse msg
3377 // returning TRUE stops the DefWindowProc() from further
3378 // processing this message - exactly what we need because we've
3379 // just set the cursor.
3384 #if wxUSE_ACCESSIBILITY
3387 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3388 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3390 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3392 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3398 #if defined(WM_HELP)
3401 // by default, WM_HELP is propagated by DefWindowProc() upwards
3402 // to the window parent but as we do it ourselves already
3403 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3404 // to get the other events if we process this message at all
3407 // WM_HELP doesn't use lParam under CE
3409 HELPINFO
* info
= (HELPINFO
*) lParam
;
3410 if ( info
->iContextType
== HELPINFO_WINDOW
)
3412 #endif // !__WXWINCE__
3413 wxHelpEvent helpEvent
3418 wxGetMousePosition() // what else?
3420 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3424 helpEvent
.SetEventObject(this);
3425 HandleWindowEvent(helpEvent
);
3428 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3430 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3431 helpEvent
.SetEventObject(this);
3432 HandleWindowEvent(helpEvent
);
3435 else // unknown help event?
3439 #endif // !__WXWINCE__
3444 #if !defined(__WXWINCE__)
3445 case WM_CONTEXTMENU
:
3447 // we don't convert from screen to client coordinates as
3448 // the event may be handled by a parent window
3449 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3451 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3453 // we could have got an event from our child, reflect it back
3454 // to it if this is the case
3455 wxWindowMSW
*win
= NULL
;
3456 WXHWND hWnd
= (WXHWND
)wParam
;
3457 if ( hWnd
!= m_hWnd
)
3459 win
= FindItemByHWND(hWnd
);
3465 evtCtx
.SetEventObject(win
);
3466 processed
= win
->HandleWindowEvent(evtCtx
);
3473 // we're only interested in our own menus, not MF_SYSMENU
3474 if ( HIWORD(wParam
) == MF_POPUP
)
3476 // handle menu chars for ownerdrawn menu items
3477 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3478 if ( i
!= wxNOT_FOUND
)
3480 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3485 #endif // wxUSE_MENUS
3488 case WM_POWERBROADCAST
:
3491 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3492 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3495 #endif // __WXWINCE__
3498 // If we want the default themed border then we need to draw it ourselves
3501 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3502 const wxBorder border
= TranslateBorder(GetBorder());
3503 if (theme
&& border
== wxBORDER_THEME
)
3505 // first ask the widget to calculate the border size
3506 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3509 // now alter the client size making room for drawing a
3512 NCCALCSIZE_PARAMS
*csparam
= NULL
;
3515 csparam
= (NCCALCSIZE_PARAMS
*)lParam
;
3516 rect
= &csparam
->rgrc
[0];
3520 rect
= (RECT
*)lParam
;
3523 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3524 RECT rcClient
= { 0, 0, 0, 0 };
3525 wxClientDC
dc((wxWindow
*)this);
3526 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3528 if ( theme
->GetThemeBackgroundContentRect
3535 &rcClient
) == S_OK
)
3537 InflateRect(&rcClient
, -1, -1);
3539 csparam
->rgrc
[0] = rcClient
;
3541 *((RECT
*)lParam
) = rcClient
;
3543 // WVR_REDRAW triggers a bug whereby child windows are moved up and left,
3545 // rc.result = WVR_REDRAW;
3553 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3554 const wxBorder border
= TranslateBorder(GetBorder());
3555 if (theme
&& border
== wxBORDER_THEME
)
3557 // first ask the widget to paint its non-client area, such as scrollbars, etc.
3558 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3561 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3562 wxWindowDC
dc((wxWindow
*)this);
3563 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3565 // Clip the DC so that you only draw on the non-client area
3567 wxCopyRectToRECT(GetSize(), rcBorder
);
3570 theme
->GetThemeBackgroundContentRect(
3571 hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, ETS_NORMAL
, &rcBorder
, &rcClient
);
3572 InflateRect(&rcClient
, -1, -1);
3574 ::ExcludeClipRect(GetHdcOf(*impl
), rcClient
.left
, rcClient
.top
,
3575 rcClient
.right
, rcClient
.bottom
);
3577 // Make sure the background is in a proper state
3578 if (theme
->IsThemeBackgroundPartiallyTransparent(hTheme
, EP_EDITTEXT
, ETS_NORMAL
))
3580 theme
->DrawThemeParentBackground(GetHwnd(), GetHdcOf(*impl
), &rcBorder
);
3586 nState
= ETS_DISABLED
;
3587 // should we check this?
3588 //else if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & ES_READONLY)
3589 // nState = ETS_READONLY;
3591 nState
= ETS_NORMAL
;
3592 theme
->DrawThemeBackground(hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, nState
, &rcBorder
, NULL
);
3597 #endif // wxUSE_UXTHEME
3600 // try a custom message handler
3601 const MSWMessageHandlers::const_iterator
3602 i
= gs_messageHandlers
.find(message
);
3603 if ( i
!= gs_messageHandlers
.end() )
3605 processed
= (*i
->second
)(this, message
, wParam
, lParam
);
3611 #if wxDEBUG_LEVEL >= 2
3612 wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."),
3613 wxGetMessageName(message
));
3614 #endif // wxDEBUG_LEVEL >= 2
3615 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3621 // ----------------------------------------------------------------------------
3622 // wxWindow <-> HWND map
3623 // ----------------------------------------------------------------------------
3625 wxWindow
*wxFindWinFromHandle(HWND hwnd
)
3627 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3628 return i
== gs_windowHandles
.end() ? NULL
: i
->second
;
3631 void wxAssociateWinWithHandle(HWND hwnd
, wxWindowMSW
*win
)
3633 // adding NULL hwnd is (first) surely a result of an error and
3634 // (secondly) breaks menu command processing
3635 wxCHECK_RET( hwnd
!= (HWND
)NULL
,
3636 wxT("attempt to add a NULL hwnd to window list ignored") );
3639 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3640 if ( i
!= gs_windowHandles
.end() )
3642 if ( i
->second
!= win
)
3646 wxT("HWND %p already associated with another window (%s)"),
3647 hwnd
, win
->GetClassInfo()->GetClassName()
3651 //else: this actually happens currently because we associate the window
3652 // with its HWND during creation (if we create it) and also when
3653 // SubclassWin() is called later, this is ok
3655 #endif // wxDEBUG_LEVEL
3657 gs_windowHandles
[hwnd
] = (wxWindow
*)win
;
3660 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3662 gs_windowHandles
.erase(GetHwndOf(win
));
3665 // ----------------------------------------------------------------------------
3666 // various MSW speciic class dependent functions
3667 // ----------------------------------------------------------------------------
3669 // Default destroyer - override if you destroy it in some other way
3670 // (e.g. with MDI child windows)
3671 void wxWindowMSW::MSWDestroyWindow()
3675 void wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3678 int& w
, int& h
) const
3680 // CW_USEDEFAULT can't be used for child windows so just position them at
3681 // the origin by default
3682 x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
;
3683 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
;
3685 AdjustForParentClientOrigin(x
, y
);
3687 // We don't have any clearly good choice for the size by default neither
3688 // but we must use something non-zero.
3689 w
= WidthDefault(size
.x
);
3690 h
= HeightDefault(size
.y
);
3693 NB: there used to be some code here which set the initial size of the
3694 window to the client size of the parent if no explicit size was
3695 specified. This was wrong because wxWidgets programs often assume
3696 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3697 it. To see why, you should understand that Windows sends WM_SIZE from
3698 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3699 from some base class ctor and so this WM_SIZE is not processed in the
3700 real class' OnSize() (because it's not fully constructed yet and the
3701 event goes to some base class OnSize() instead). So the WM_SIZE we
3702 rely on is the one sent when the parent frame resizes its children
3703 but here is the problem: if the child already has just the right
3704 size, nothing will happen as both wxWidgets and Windows check for
3705 this and ignore any attempts to change the window size to the size it
3706 already has - so no WM_SIZE would be sent.
3710 WXHWND
wxWindowMSW::MSWGetParent() const
3712 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3715 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3716 const wxChar
*title
,
3720 WXDWORD extendedStyle
)
3722 // check a common bug in the user code: if the window is created with a
3723 // non-default ctor and Create() is called too, we'd create 2 HWND for a
3724 // single wxWindow object and this results in all sorts of trouble,
3725 // especially for wxTLWs
3726 wxCHECK_MSG( !m_hWnd
, true, "window can't be recreated" );
3728 // this can happen if this function is called using the return value of
3729 // wxApp::GetRegisteredClassName() which failed
3730 wxCHECK_MSG( wclass
, false, "failed to register window class?" );
3733 // choose the position/size for the new window
3735 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3737 // controlId is menu handle for the top level windows, so set it to 0
3738 // unless we're creating a child window
3739 int controlId
= style
& WS_CHILD
? GetId() : 0;
3741 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3742 // which is the same but without CS_[HV]REDRAW class styles so using it
3743 // ensures that the window is not fully repainted on each resize
3744 wxString
className(wclass
);
3745 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3747 className
+= wxApp::GetNoRedrawClassSuffix();
3750 // do create the window
3751 wxWindowCreationHook
hook(this);
3753 m_hWnd
= (WXHWND
)::CreateWindowEx
3757 title
? title
: m_windowName
.wx_str(),
3760 (HWND
)MSWGetParent(),
3761 (HMENU
)wxUIntToPtr(controlId
),
3763 NULL
// no extra data
3768 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3773 SubclassWin(m_hWnd
);
3778 // ===========================================================================
3779 // MSW message handlers
3780 // ===========================================================================
3782 // ---------------------------------------------------------------------------
3784 // ---------------------------------------------------------------------------
3786 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3788 #ifndef __WXMICROWIN__
3789 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3790 HWND hWnd
= hdr
->hwndFrom
;
3791 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
3793 // if the control is one of our windows, let it handle the message itself
3796 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3799 // VZ: why did we do it? normally this is unnecessary and, besides, it
3800 // breaks the message processing for the toolbars because the tooltip
3801 // notifications were being forwarded to the toolbar child controls
3802 // (if it had any) before being passed to the toolbar itself, so in my
3803 // example the tooltip for the combobox was always shown instead of the
3804 // correct button tooltips
3806 // try all our children
3807 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3810 wxWindow
*child
= node
->GetData();
3811 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3816 node
= node
->GetNext();
3820 // by default, handle it ourselves
3821 return MSWOnNotify(idCtrl
, lParam
, result
);
3822 #else // __WXMICROWIN__
3829 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3831 const wxString
& ttip
)
3833 // I don't know why it happens, but the versions of comctl32.dll starting
3834 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3835 // this message is supposed to be sent to Unicode programs only) -- hence
3836 // we need to handle it as well, otherwise no tooltips will be shown in
3839 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3842 // not a tooltip message or no tooltip to show anyhow
3847 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3849 // We don't want to use the szText buffer because it has a limit of 80
3850 // bytes and this is not enough, especially for Unicode build where it
3851 // limits the tooltip string length to only 40 characters
3853 // The best would be, of course, to not impose any length limitations at
3854 // all but then the buffer would have to be dynamic and someone would have
3855 // to free it and we don't have the tooltip owner object here any more, so
3856 // for now use our own static buffer with a higher fixed max length.
3858 // Note that using a static buffer should not be a problem as only a single
3859 // tooltip can be shown at the same time anyhow.
3861 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3863 // We need to convert tooltip from multi byte to Unicode on the fly.
3864 static wchar_t buf
[513];
3866 // Truncate tooltip length if needed as otherwise we might not have
3867 // enough space for it in the buffer and MultiByteToWideChar() would
3869 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3871 // Convert to WideChar without adding the NULL character. The NULL
3872 // character is added afterwards (this is more efficient).
3873 int len
= ::MultiByteToWideChar
3885 wxLogLastError(wxT("MultiByteToWideChar()"));
3889 ttText
->lpszText
= (LPSTR
) buf
;
3891 else // TTN_NEEDTEXTA
3892 #endif // !wxUSE_UNICODE
3894 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3895 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3896 // to copy the string we have into the buffer
3897 static wxChar buf
[513];
3898 wxStrlcpy(buf
, ttip
.c_str(), WXSIZEOF(buf
));
3899 ttText
->lpszText
= buf
;
3905 #endif // wxUSE_TOOLTIPS
3907 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3909 WXLPARAM
* WXUNUSED(result
))
3914 NMHDR
* hdr
= (NMHDR
*)lParam
;
3915 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3922 wxUnusedVar(lParam
);
3923 #endif // wxUSE_TOOLTIPS
3928 // ---------------------------------------------------------------------------
3929 // end session messages
3930 // ---------------------------------------------------------------------------
3932 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3934 #ifdef ENDSESSION_LOGOFF
3935 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3936 event
.SetEventObject(wxTheApp
);
3937 event
.SetCanVeto(true);
3938 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3940 bool rc
= wxTheApp
->ProcessEvent(event
);
3944 // we may end only if the app didn't veto session closing (double
3946 *mayEnd
= !event
.GetVeto();
3951 wxUnusedVar(logOff
);
3952 wxUnusedVar(mayEnd
);
3957 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3959 #ifdef ENDSESSION_LOGOFF
3960 // do nothing if the session isn't ending
3965 if ( (this != wxTheApp
->GetTopWindow()) )
3968 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3969 event
.SetEventObject(wxTheApp
);
3970 event
.SetCanVeto(false);
3971 event
.SetLoggingOff((logOff
& ENDSESSION_LOGOFF
) != 0);
3973 return wxTheApp
->ProcessEvent(event
);
3975 wxUnusedVar(endSession
);
3976 wxUnusedVar(logOff
);
3981 // ---------------------------------------------------------------------------
3982 // window creation/destruction
3983 // ---------------------------------------------------------------------------
3985 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3988 // VZ: why is this commented out for WinCE? If it doesn't support
3989 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3990 // not with multiple #ifdef's!
3992 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3993 EnsureParentHasControlParentStyle(GetParent());
3994 #endif // !__WXWINCE__
4001 bool wxWindowMSW::HandleDestroy()
4003 // delete our drop target if we've got one
4004 #if wxUSE_DRAG_AND_DROP
4005 if ( m_dropTarget
!= NULL
)
4007 m_dropTarget
->Revoke(m_hWnd
);
4009 wxDELETE(m_dropTarget
);
4011 #endif // wxUSE_DRAG_AND_DROP
4013 // WM_DESTROY handled
4017 // ---------------------------------------------------------------------------
4019 // ---------------------------------------------------------------------------
4021 bool wxWindowMSW::HandleActivate(int state
,
4022 bool WXUNUSED(minimized
),
4023 WXHWND
WXUNUSED(activate
))
4025 wxActivateEvent
event(wxEVT_ACTIVATE
,
4026 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
4028 event
.SetEventObject(this);
4030 return HandleWindowEvent(event
);
4033 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
4035 // Strangly enough, some controls get set focus events when they are being
4036 // deleted, even if they already had focus before.
4037 if ( m_isBeingDeleted
)
4042 // notify the parent keeping track of focus for the kbd navigation
4043 // purposes that we got it
4044 wxChildFocusEvent
eventFocus((wxWindow
*)this);
4045 (void)HandleWindowEvent(eventFocus
);
4051 m_caret
->OnSetFocus();
4053 #endif // wxUSE_CARET
4055 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
4056 event
.SetEventObject(this);
4058 // wxFindWinFromHandle() may return NULL, it is ok
4059 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4061 return HandleWindowEvent(event
);
4064 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
4070 m_caret
->OnKillFocus();
4072 #endif // wxUSE_CARET
4074 // Don't send the event when in the process of being deleted. This can
4075 // only cause problems if the event handler tries to access the object.
4076 if ( m_isBeingDeleted
)
4081 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
4082 event
.SetEventObject(this);
4084 // wxFindWinFromHandle() may return NULL, it is ok
4085 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4087 return HandleWindowEvent(event
);
4090 // ---------------------------------------------------------------------------
4092 // ---------------------------------------------------------------------------
4094 void wxWindowMSW::SetLabel( const wxString
& label
)
4096 SetWindowText(GetHwnd(), label
.c_str());
4099 wxString
wxWindowMSW::GetLabel() const
4101 return wxGetWindowText(GetHWND());
4104 // ---------------------------------------------------------------------------
4106 // ---------------------------------------------------------------------------
4108 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
4110 wxShowEvent
event(GetId(), show
);
4111 event
.SetEventObject(this);
4113 return HandleWindowEvent(event
);
4116 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
4118 wxInitDialogEvent
event(GetId());
4119 event
.SetEventObject(this);
4121 return HandleWindowEvent(event
);
4124 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
4126 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
4127 wxUnusedVar(wParam
);
4129 #else // __WXMICROWIN__
4130 HDROP hFilesInfo
= (HDROP
) wParam
;
4132 // Get the total number of files dropped
4133 UINT gwFilesDropped
= ::DragQueryFile
4141 wxString
*files
= new wxString
[gwFilesDropped
];
4142 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
4144 // first get the needed buffer length (+1 for terminating NUL)
4145 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
4147 // and now get the file name
4148 ::DragQueryFile(hFilesInfo
, wIndex
,
4149 wxStringBuffer(files
[wIndex
], len
), len
);
4152 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
4153 event
.SetEventObject(this);
4156 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
4157 event
.m_pos
.x
= dropPoint
.x
;
4158 event
.m_pos
.y
= dropPoint
.y
;
4160 DragFinish(hFilesInfo
);
4162 return HandleWindowEvent(event
);
4167 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
4169 int WXUNUSED(mouseMsg
))
4171 #ifndef __WXMICROWIN__
4172 // the logic is as follows:
4173 // 0. if we're busy, set the busy cursor (even for non client elements)
4174 // 1. don't set custom cursor for non client area of enabled windows
4175 // 2. ask user EVT_SET_CURSOR handler for the cursor
4176 // 3. if still no cursor but we're in a TLW, set the global cursor
4178 HCURSOR hcursor
= 0;
4181 hcursor
= wxGetCurrentBusyCursor();
4185 if ( nHitTest
!= HTCLIENT
)
4188 // first ask the user code - it may wish to set the cursor in some very
4189 // specific way (for example, depending on the current position)
4192 if ( !::GetCursorPosWinCE(&pt
))
4194 if ( !::GetCursorPos(&pt
) )
4197 wxLogLastError(wxT("GetCursorPos"));
4202 ScreenToClient(&x
, &y
);
4203 wxSetCursorEvent
event(x
, y
);
4204 event
.SetId(GetId());
4205 event
.SetEventObject(this);
4207 bool processedEvtSetCursor
= HandleWindowEvent(event
);
4208 if ( processedEvtSetCursor
&& event
.HasCursor() )
4210 hcursor
= GetHcursorOf(event
.GetCursor());
4215 // the test for processedEvtSetCursor is here to prevent using
4216 // m_cursor if the user code caught EVT_SET_CURSOR() and returned
4217 // nothing from it - this is a way to say that our cursor shouldn't
4218 // be used for this point
4219 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
4221 hcursor
= GetHcursorOf(m_cursor
);
4224 if ( !hcursor
&& !GetParent() )
4226 const wxCursor
*cursor
= wxGetGlobalCursor();
4227 if ( cursor
&& cursor
->Ok() )
4229 hcursor
= GetHcursorOf(*cursor
);
4238 ::SetCursor(hcursor
);
4240 // cursor set, stop here
4243 #endif // __WXMICROWIN__
4245 // pass up the window chain
4249 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
4250 WXLPARAM
WXUNUSED(lParam
),
4251 bool *WXUNUSED_IN_WINCE(vetoed
))
4257 wxEventType evtType
;
4260 case PBT_APMQUERYSUSPEND
:
4261 evtType
= wxEVT_POWER_SUSPENDING
;
4264 case PBT_APMQUERYSUSPENDFAILED
:
4265 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
4268 case PBT_APMSUSPEND
:
4269 evtType
= wxEVT_POWER_SUSPENDED
;
4272 case PBT_APMRESUMESUSPEND
:
4273 evtType
= wxEVT_POWER_RESUME
;
4277 wxLogDebug(wxT("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
4280 // these messages are currently not mapped to wx events
4281 case PBT_APMQUERYSTANDBY
:
4282 case PBT_APMQUERYSTANDBYFAILED
:
4283 case PBT_APMSTANDBY
:
4284 case PBT_APMRESUMESTANDBY
:
4285 case PBT_APMBATTERYLOW
:
4286 case PBT_APMPOWERSTATUSCHANGE
:
4287 case PBT_APMOEMEVENT
:
4288 case PBT_APMRESUMECRITICAL
:
4289 #ifdef PBT_APMRESUMEAUTOMATIC
4290 case PBT_APMRESUMEAUTOMATIC
:
4292 evtType
= wxEVT_NULL
;
4296 // don't handle unknown messages
4297 if ( evtType
== wxEVT_NULL
)
4300 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
4302 wxPowerEvent
event(evtType
);
4303 if ( !HandleWindowEvent(event
) )
4306 *vetoed
= event
.IsVetoed();
4312 bool wxWindowMSW::IsDoubleBuffered() const
4314 for ( const wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4316 if ( wxHasWindowExStyle(win
, WS_EX_COMPOSITED
) )
4319 if ( win
->IsTopLevel() )
4326 void wxWindowMSW::SetDoubleBuffered(bool on
)
4328 // Get the current extended style bits
4329 long exstyle
= wxGetWindowExStyle(this);
4331 // Twiddle the bit as needed
4333 exstyle
|= WS_EX_COMPOSITED
;
4335 exstyle
&= ~WS_EX_COMPOSITED
;
4338 wxSetWindowExStyle(this, exstyle
);
4341 // ---------------------------------------------------------------------------
4342 // owner drawn stuff
4343 // ---------------------------------------------------------------------------
4345 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
4346 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
4347 #define WXUNUSED_UNLESS_ODRAWN(param) param
4349 #define WXUNUSED_UNLESS_ODRAWN(param)
4353 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
4354 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
4356 #if wxUSE_OWNER_DRAWN
4358 #if wxUSE_MENUS_NATIVE
4359 // is it a menu item?
4360 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
4361 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
4363 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
4365 // see comment before the same test in MSWOnMeasureItem() below
4369 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4370 false, wxT("MSWOnDrawItem: bad wxMenuItem pointer") );
4372 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4373 // the DC from being released
4374 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
4375 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
4376 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
4377 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
4379 return pMenuItem
->OnDrawItem
4383 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
4384 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
4387 #endif // wxUSE_MENUS_NATIVE
4389 #endif // USE_OWNER_DRAWN
4391 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4393 #if wxUSE_OWNER_DRAWN
4394 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4395 #else // !wxUSE_OWNER_DRAWN
4396 // we may still have owner-drawn buttons internally because we have to make
4397 // them owner-drawn to support colour change
4400 wxDynamicCast(FindItem(id
), wxButton
)
4405 #endif // USE_OWNER_DRAWN
4409 return item
->MSWOnDraw(itemStruct
);
4412 #endif // wxUSE_CONTROLS
4418 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4420 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4421 // is it a menu item?
4422 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4423 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4425 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4427 // according to Carsten Fuchs the pointer may be NULL under XP if an
4428 // MDI child frame is initially maximized, see this for more info:
4429 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4431 // so silently ignore it instead of asserting
4435 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4436 false, wxT("MSWOnMeasureItem: bad wxMenuItem pointer") );
4439 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4441 pMeasureStruct
->itemWidth
= w
;
4442 pMeasureStruct
->itemHeight
= h
;
4447 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4450 return item
->MSWOnMeasure(itemStruct
);
4454 wxUnusedVar(itemStruct
);
4455 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4460 // ---------------------------------------------------------------------------
4461 // colours and palettes
4462 // ---------------------------------------------------------------------------
4464 bool wxWindowMSW::HandleSysColorChange()
4466 wxSysColourChangedEvent event
;
4467 event
.SetEventObject(this);
4469 (void)HandleWindowEvent(event
);
4471 // always let the system carry on the default processing to allow the
4472 // native controls to react to the colours update
4476 bool wxWindowMSW::HandleDisplayChange()
4478 wxDisplayChangedEvent event
;
4479 event
.SetEventObject(this);
4481 return HandleWindowEvent(event
);
4484 #ifndef __WXMICROWIN__
4486 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4488 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4492 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4495 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4497 #endif // wxUSE_CONTROLS
4500 return *brush
!= NULL
;
4503 #endif // __WXMICROWIN__
4505 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4508 // same as below except we don't respond to our own messages
4509 if ( hWndPalChange
!= GetHWND() )
4511 // check to see if we our our parents have a custom palette
4512 wxWindowMSW
*win
= this;
4513 while ( win
&& !win
->HasCustomPalette() )
4515 win
= win
->GetParent();
4518 if ( win
&& win
->HasCustomPalette() )
4520 // realize the palette to see whether redrawing is needed
4521 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4522 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4523 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4525 int result
= ::RealizePalette(hdc
);
4527 // restore the palette (before releasing the DC)
4528 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4529 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4530 ::RealizePalette(hdc
);
4531 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4533 // now check for the need to redraw
4535 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4539 #endif // wxUSE_PALETTE
4541 wxPaletteChangedEvent
event(GetId());
4542 event
.SetEventObject(this);
4543 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4545 return HandleWindowEvent(event
);
4548 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4550 // notify windows on the capture stack about lost capture
4551 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4552 wxWindowBase::NotifyCaptureLost();
4554 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4555 wxMouseCaptureChangedEvent
event(GetId(), win
);
4556 event
.SetEventObject(this);
4557 return HandleWindowEvent(event
);
4560 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4562 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4563 // we need to send this to child windows (it is only sent to top-level
4564 // windows) so {list,tree}ctrls can adjust their font size if necessary
4565 // this is exactly how explorer does it to enable the font size changes
4567 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4570 // top-level windows already get this message from the system
4571 wxWindow
*win
= node
->GetData();
4572 if ( !win
->IsTopLevel() )
4574 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4577 node
= node
->GetNext();
4580 // let the system handle it
4584 bool wxWindowMSW::HandleQueryNewPalette()
4588 // check to see if we our our parents have a custom palette
4589 wxWindowMSW
*win
= this;
4590 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4591 if (win
->HasCustomPalette()) {
4592 /* realize the palette to see whether redrawing is needed */
4593 HDC hdc
= ::GetDC((HWND
) GetHWND());
4594 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4595 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4597 int result
= ::RealizePalette(hdc
);
4598 /* restore the palette (before releasing the DC) */
4599 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4600 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4601 ::RealizePalette(hdc
);
4602 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4603 /* now check for the need to redraw */
4605 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4607 #endif // wxUSE_PALETTE
4609 wxQueryNewPaletteEvent
event(GetId());
4610 event
.SetEventObject(this);
4612 return HandleWindowEvent(event
) && event
.GetPaletteRealized();
4615 // Responds to colour changes: passes event on to children.
4616 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4618 // the top level window also reset the standard colour map as it might have
4619 // changed (there is no need to do it for the non top level windows as we
4620 // only have to do it once)
4624 gs_hasStdCmap
= false;
4626 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4629 // Only propagate to non-top-level windows because Windows already
4630 // sends this event to all top-level ones
4631 wxWindow
*win
= node
->GetData();
4632 if ( !win
->IsTopLevel() )
4634 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4635 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4636 // the standard controls
4637 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4640 node
= node
->GetNext();
4644 extern wxCOLORMAP
*wxGetStdColourMap()
4646 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4647 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4649 if ( !gs_hasStdCmap
)
4651 static bool s_coloursInit
= false;
4653 if ( !s_coloursInit
)
4655 // When a bitmap is loaded, the RGB values can change (apparently
4656 // because Windows adjusts them to care for the old programs always
4657 // using 0xc0c0c0 while the transparent colour for the new Windows
4658 // versions is different). But we do this adjustment ourselves so
4659 // we want to avoid Windows' "help" and for this we need to have a
4660 // reference bitmap which can tell us what the RGB values change
4662 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4663 wxBitmap
stdColourBitmap(wxT("wxBITMAP_STD_COLOURS"));
4664 if ( stdColourBitmap
.Ok() )
4666 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4667 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4668 wxT("forgot to update wxBITMAP_STD_COLOURS!") );
4671 memDC
.SelectObject(stdColourBitmap
);
4674 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4676 memDC
.GetPixel(i
, 0, &colour
);
4677 s_stdColours
[i
] = wxColourToRGB(colour
);
4680 else // wxBITMAP_STD_COLOURS couldn't be loaded
4682 s_stdColours
[0] = RGB(000,000,000); // black
4683 s_stdColours
[1] = RGB(128,128,128); // dark grey
4684 s_stdColours
[2] = RGB(192,192,192); // light grey
4685 s_stdColours
[3] = RGB(255,255,255); // white
4686 //s_stdColours[4] = RGB(000,000,255); // blue
4687 //s_stdColours[5] = RGB(255,000,255); // magenta
4690 s_coloursInit
= true;
4693 gs_hasStdCmap
= true;
4695 // create the colour map
4696 #define INIT_CMAP_ENTRY(col) \
4697 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4698 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4700 INIT_CMAP_ENTRY(BTNTEXT
);
4701 INIT_CMAP_ENTRY(BTNSHADOW
);
4702 INIT_CMAP_ENTRY(BTNFACE
);
4703 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4705 #undef INIT_CMAP_ENTRY
4711 #if wxUSE_UXTHEME && !defined(TMT_FILLCOLOR)
4712 #define TMT_FILLCOLOR 3802
4713 #define TMT_TEXTCOLOR 3803
4714 #define TMT_BORDERCOLOR 3801
4717 wxColour
wxWindowMSW::MSWGetThemeColour(const wchar_t *themeName
,
4720 MSWThemeColour themeColour
,
4721 wxSystemColour fallback
) const
4724 const wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
4727 int themeProperty
= 0;
4729 // TODO: Convert this into a table? Sure would be faster.
4730 switch ( themeColour
)
4732 case ThemeColourBackground
:
4733 themeProperty
= TMT_FILLCOLOR
;
4735 case ThemeColourText
:
4736 themeProperty
= TMT_TEXTCOLOR
;
4738 case ThemeColourBorder
:
4739 themeProperty
= TMT_BORDERCOLOR
;
4742 wxFAIL_MSG(wxT("unsupported theme colour"));
4745 wxUxThemeHandle
hTheme((const wxWindow
*)this, themeName
);
4747 HRESULT hr
= theme
->GetThemeColor
4756 if ( SUCCEEDED(hr
) )
4757 return wxRGBToColour(col
);
4761 "GetThemeColor(%s, %i, %i, %i)",
4762 themeName
, themePart
, themeState
, themeProperty
),
4766 wxUnusedVar(themeName
);
4767 wxUnusedVar(themePart
);
4768 wxUnusedVar(themeState
);
4769 wxUnusedVar(themeColour
);
4771 return wxSystemSettings::GetColour(fallback
);
4774 // ---------------------------------------------------------------------------
4776 // ---------------------------------------------------------------------------
4778 // this variable is used to check that a paint event handler which processed
4779 // the event did create a wxPaintDC inside its code and called BeginPaint() to
4780 // validate the invalidated window area as otherwise we'd keep getting an
4781 // endless stream of WM_PAINT messages for this window resulting in a lot of
4782 // difficult to debug problems (e.g. impossibility to repaint other windows,
4783 // lack of timer and idle events and so on)
4784 extern bool wxDidCreatePaintDC
;
4785 bool wxDidCreatePaintDC
= false;
4787 bool wxWindowMSW::HandlePaint()
4789 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4792 wxLogLastError(wxT("CreateRectRgn"));
4794 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4796 wxLogLastError(wxT("GetUpdateRgn"));
4799 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4801 wxDidCreatePaintDC
= false;
4803 wxPaintEvent
event(m_windowId
);
4804 event
.SetEventObject(this);
4806 bool processed
= HandleWindowEvent(event
);
4808 if ( processed
&& !wxDidCreatePaintDC
)
4810 // do call MSWDefWindowProc() to validate the update region to avoid
4811 // the problems mentioned above
4815 // note that we must generate NC event after the normal one as otherwise
4816 // BeginPaint() will happily overwrite our decorations with the background
4818 wxNcPaintEvent
eventNc(m_windowId
);
4819 eventNc
.SetEventObject(this);
4820 HandleWindowEvent(eventNc
);
4822 // don't keep an HRGN we don't need any longer (GetUpdateRegion() can only
4823 // be called from inside the event handlers called above)
4824 m_updateRegion
.Clear();
4829 // Can be called from an application's OnPaint handler
4830 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4832 #ifdef __WXUNIVERSAL__
4835 HDC hDC
= (HDC
) wxPaintDCImpl::FindDCInCache((wxWindow
*) event
.GetEventObject());
4838 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4843 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4845 switch ( GetBackgroundStyle() )
4847 case wxBG_STYLE_ERASE
:
4848 case wxBG_STYLE_COLOUR
:
4849 // we need to generate an erase background event
4851 wxDCTemp
dc(hdc
, GetClientSize());
4852 wxDCTempImpl
*impl
= (wxDCTempImpl
*) dc
.GetImpl();
4855 impl
->SetWindow((wxWindow
*)this);
4857 wxEraseEvent
event(m_windowId
, &dc
);
4858 event
.SetEventObject(this);
4859 bool rc
= HandleWindowEvent(event
);
4861 // must be called manually as ~wxDC doesn't do anything for
4863 impl
->SelectOldObjects(hdc
);
4867 // background erased by the user-defined handler
4873 case wxBG_STYLE_SYSTEM
:
4874 if ( !DoEraseBackground(hdc
) )
4876 // let the default processing to take place if we didn't erase
4877 // the background ourselves
4882 case wxBG_STYLE_PAINT
:
4883 case wxBG_STYLE_TRANSPARENT
:
4884 // no need to do anything here at all, background will be entirely
4885 // redrawn in WM_PAINT handler
4889 wxFAIL_MSG( "unknown background style" );
4895 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
4897 bool wxWindowMSW::MSWHasEraseBgHook() const
4899 return gs_eraseBgHooks
.find(this) != gs_eraseBgHooks
.end();
4902 void wxWindowMSW::MSWSetEraseBgHook(wxWindow
*child
)
4906 if ( !gs_eraseBgHooks
.insert(
4907 EraseBgHooks::value_type(this, child
)).second
)
4909 wxFAIL_MSG( wxT("Setting erase background hook twice?") );
4912 else // reset the hook
4914 if ( gs_eraseBgHooks
.erase(this) != 1 )
4916 wxFAIL_MSG( wxT("Resetting erase background which was not set?") );
4921 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
4923 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4925 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4929 // erase just the client area of the window, this is important for the
4930 // frames to avoid drawing over the toolbar part of the window (you might
4931 // think using WS_CLIPCHILDREN would prevent this from happening, but it
4934 wxCopyRectToRECT(GetClientRect(), rc
);
4935 ::FillRect((HDC
)hDC
, &rc
, hbr
);
4941 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
),
4942 wxWindowMSW
* WXUNUSED(child
))
4947 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4949 return (WXHBRUSH
)GetHbrushOf(*brush
);
4955 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
)
4957 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4959 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, this);
4963 // don't use the parent background if we're not transparent
4964 if ( !win
->HasTransparentBackground() )
4967 // background is not inherited beyond top level windows
4968 if ( win
->IsTopLevel() )
4975 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4977 // we receive this message when DrawThemeParentBackground() is
4978 // called from def window proc of several controls under XP and we
4979 // must draw properly themed background here
4981 // note that naively I'd expect filling the client rect with the
4982 // brush returned by MSWGetBgBrush() work -- but for some reason it
4983 // doesn't and we have to call parents MSWPrintChild() which is
4984 // supposed to call DrawThemeBackground() with appropriate params
4986 // also note that in this case lParam == PRF_CLIENT but we're
4987 // clearly expected to paint the background and nothing else!
4989 if ( IsTopLevel() || InheritsBackgroundColour() )
4992 // sometimes we don't want the parent to handle it at all, instead
4993 // return whatever value this window wants
4994 if ( !MSWShouldPropagatePrintChild() )
4995 return MSWPrintChild(hDC
, (wxWindow
*)this);
4997 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4999 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
5002 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
5009 // ---------------------------------------------------------------------------
5010 // moving and resizing
5011 // ---------------------------------------------------------------------------
5013 bool wxWindowMSW::HandleMinimize()
5015 wxIconizeEvent
event(m_windowId
);
5016 event
.SetEventObject(this);
5018 return HandleWindowEvent(event
);
5021 bool wxWindowMSW::HandleMaximize()
5023 wxMaximizeEvent
event(m_windowId
);
5024 event
.SetEventObject(this);
5026 return HandleWindowEvent(event
);
5029 bool wxWindowMSW::HandleMove(int x
, int y
)
5032 wxMoveEvent
event(point
, m_windowId
);
5033 event
.SetEventObject(this);
5035 return HandleWindowEvent(event
);
5038 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
5040 wxMoveEvent
event(rect
, m_windowId
);
5041 event
.SetEventObject(this);
5043 bool rc
= HandleWindowEvent(event
);
5045 rect
= event
.GetRect();
5049 bool wxWindowMSW::HandleEnterSizeMove()
5051 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5052 event
.SetEventType(wxEVT_MOVE_START
);
5053 event
.SetEventObject(this);
5055 return HandleWindowEvent(event
);
5058 bool wxWindowMSW::HandleExitSizeMove()
5060 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5061 event
.SetEventType(wxEVT_MOVE_END
);
5062 event
.SetEventObject(this);
5064 return HandleWindowEvent(event
);
5067 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
5069 #if wxUSE_DEFERRED_SIZING
5070 // when we resize this window, its children are probably going to be
5071 // repositioned as well, prepare to use DeferWindowPos() for them
5072 int numChildren
= 0;
5073 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
5075 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
5080 // Protect against valid m_hDWP being overwritten
5081 bool useDefer
= false;
5083 if ( numChildren
> 1 )
5087 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
5090 wxLogLastError(wxT("BeginDeferWindowPos"));
5096 #endif // wxUSE_DEFERRED_SIZING
5098 // update this window size
5099 bool processed
= false;
5103 wxFAIL_MSG( wxT("unexpected WM_SIZE parameter") );
5104 // fall through nevertheless
5108 // we're not interested in these messages at all
5111 case SIZE_MINIMIZED
:
5112 processed
= HandleMinimize();
5115 case SIZE_MAXIMIZED
:
5116 /* processed = */ HandleMaximize();
5117 // fall through to send a normal size event as well
5120 // don't use w and h parameters as they specify the client size
5121 // while according to the docs EVT_SIZE handler is supposed to
5122 // receive the total size
5123 wxSizeEvent
event(GetSize(), m_windowId
);
5124 event
.SetEventObject(this);
5126 processed
= HandleWindowEvent(event
);
5129 #if wxUSE_DEFERRED_SIZING
5130 // and finally change the positions of all child windows at once
5131 if ( useDefer
&& m_hDWP
)
5133 // reset m_hDWP to NULL so that child windows don't try to use our
5134 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
5135 // happen anyhow normally but who knows what weird flow of control we
5136 // may have depending on what the users EVT_SIZE handler does...)
5137 HDWP hDWP
= (HDWP
)m_hDWP
;
5140 // do put all child controls in place at once
5141 if ( !::EndDeferWindowPos(hDWP
) )
5143 wxLogLastError(wxT("EndDeferWindowPos"));
5146 // Reset our children's pending pos/size values.
5147 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
5149 node
= node
->GetNext() )
5151 wxWindowMSW
* const child
= node
->GetData();
5152 child
->MSWEndDeferWindowPos();
5155 #endif // wxUSE_DEFERRED_SIZING
5160 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
5162 wxSizeEvent
event(rect
, m_windowId
);
5163 event
.SetEventObject(this);
5165 bool rc
= HandleWindowEvent(event
);
5167 rect
= event
.GetRect();
5171 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
5176 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
5180 int minWidth
= GetMinWidth(),
5181 minHeight
= GetMinHeight(),
5182 maxWidth
= GetMaxWidth(),
5183 maxHeight
= GetMaxHeight();
5185 if ( minWidth
!= wxDefaultCoord
)
5187 info
->ptMinTrackSize
.x
= minWidth
;
5191 if ( minHeight
!= wxDefaultCoord
)
5193 info
->ptMinTrackSize
.y
= minHeight
;
5197 if ( maxWidth
!= wxDefaultCoord
)
5199 info
->ptMaxTrackSize
.x
= maxWidth
;
5203 if ( maxHeight
!= wxDefaultCoord
)
5205 info
->ptMaxTrackSize
.y
= maxHeight
;
5213 // ---------------------------------------------------------------------------
5215 // ---------------------------------------------------------------------------
5217 bool wxWindowMSW::HandleCommand(WXWORD id_
, WXWORD cmd
, WXHWND control
)
5219 // sign extend to int from short before comparing with the other int ids
5220 int id
= (signed short)id_
;
5222 #if wxUSE_MENUS_NATIVE
5223 if ( !cmd
&& wxCurrentPopupMenu
)
5225 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
5226 wxCurrentPopupMenu
= NULL
;
5228 return popupMenu
->MSWCommand(cmd
, id
);
5230 #endif // wxUSE_MENUS_NATIVE
5232 wxWindow
*win
= NULL
;
5234 // first try to find it from HWND - this works even with the broken
5235 // programs using the same ids for different controls
5238 win
= wxFindWinFromHandle(control
);
5249 return win
->MSWCommand(cmd
, id
);
5252 // the messages sent from the in-place edit control used by the treectrl
5253 // for label editing have id == 0, but they should _not_ be treated as menu
5254 // messages (they are EN_XXX ones, in fact) so don't translate anything
5255 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
5258 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
5259 event
.SetEventObject(this);
5262 return HandleWindowEvent(event
);
5266 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5267 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
5268 // notifications to its parent which we want to reflect back to
5270 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
5271 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
5273 #endif // wxUSE_SPINCTRL
5275 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
5276 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
5277 // notifications to its parent which we want to reflect back to
5279 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
5280 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
5288 // ---------------------------------------------------------------------------
5290 // ---------------------------------------------------------------------------
5292 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
5296 // our client coords are not quite the same as Windows ones
5297 wxPoint pt
= GetClientAreaOrigin();
5298 event
.m_x
= x
- pt
.x
;
5299 event
.m_y
= y
- pt
.y
;
5301 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
5302 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
5303 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
5304 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
5305 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
5306 #ifdef wxHAS_XBUTTON
5307 event
.m_aux1Down
= (flags
& MK_XBUTTON1
) != 0;
5308 event
.m_aux2Down
= (flags
& MK_XBUTTON2
) != 0;
5309 #endif // wxHAS_XBUTTON
5310 event
.m_altDown
= ::wxIsAltDown();
5313 event
.SetTimestamp(::GetMessageTime());
5316 event
.SetEventObject(this);
5317 event
.SetId(GetId());
5319 #if wxUSE_MOUSEEVENT_HACK
5320 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
5321 gs_lastMouseEvent
.type
= event
.GetEventType();
5322 #endif // wxUSE_MOUSEEVENT_HACK
5326 // Windows doesn't send the mouse events to the static controls (which are
5327 // transparent in the sense that their WM_NCHITTEST handler returns
5328 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
5329 // and so we manually check if we don't have a child window under mouse and if
5330 // we do, send the event to it instead of the window Windows had sent WM_XXX
5333 // Notice that this is not done for the mouse move events because this could
5334 // (would?) be too slow, but only for clicks which means that the static texts
5335 // still don't get move, enter nor leave events.
5336 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
5338 wxCHECK_MSG( x
&& y
, win
, wxT("NULL pointer in FindWindowForMouseEvent") );
5340 // first try to find a non transparent child: this allows us to send events
5341 // to a static text which is inside a static box, for example
5342 POINT pt
= { *x
, *y
};
5343 HWND hwnd
= GetHwndOf(win
),
5347 hwndUnderMouse
= ::ChildWindowFromPoint
5353 hwndUnderMouse
= ::ChildWindowFromPointEx
5363 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
5365 // now try any child window at all
5366 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
5369 // check that we have a child window which is susceptible to receive mouse
5370 // events: for this it must be shown and enabled
5371 if ( hwndUnderMouse
&&
5372 hwndUnderMouse
!= hwnd
&&
5373 ::IsWindowVisible(hwndUnderMouse
) &&
5374 ::IsWindowEnabled(hwndUnderMouse
) )
5376 wxWindow
*winUnderMouse
= wxFindWinFromHandle(hwndUnderMouse
);
5377 if ( winUnderMouse
)
5379 // translate the mouse coords to the other window coords
5380 win
->ClientToScreen(x
, y
);
5381 winUnderMouse
->ScreenToClient(x
, y
);
5383 win
= winUnderMouse
;
5389 #endif // __WXWINCE__
5391 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5393 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
5394 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
5395 // from the message id and take the value in the table to get wxWin event
5397 static const wxEventType eventsMouse
[] =
5408 wxEVT_MIDDLE_DCLICK
,
5409 0, // this one is for wxEVT_MOTION which is not used here
5418 #ifdef wxHAS_XBUTTON
5419 // the same messages are used for both auxillary mouse buttons so we need
5420 // to adjust the index manually
5423 case WM_XBUTTONDOWN
:
5425 case WM_XBUTTONDBLCLK
:
5426 if ( flags
& MK_XBUTTON2
)
5427 msg
+= wxEVT_AUX2_DOWN
- wxEVT_AUX1_DOWN
;
5429 #endif // wxHAS_XBUTTON
5431 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
5432 InitMouseEvent(event
, x
, y
, flags
);
5434 return HandleWindowEvent(event
);
5437 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
5439 if ( !m_mouseInWindow
)
5441 // it would be wrong to assume that just because we get a mouse move
5442 // event that the mouse is inside the window: although this is usually
5443 // true, it is not if we had captured the mouse, so we need to check
5444 // the mouse coordinates here
5445 if ( !HasCapture() || IsMouseInWindow() )
5447 // Generate an ENTER event
5448 m_mouseInWindow
= true;
5450 #ifdef HAVE_TRACKMOUSEEVENT
5451 typedef BOOL (WINAPI
*_TrackMouseEvent_t
)(LPTRACKMOUSEEVENT
);
5453 static const _TrackMouseEvent_t
5454 s_pfn_TrackMouseEvent
= _TrackMouseEvent
;
5455 #else // !__WXWINCE__
5456 static _TrackMouseEvent_t s_pfn_TrackMouseEvent
;
5457 static bool s_initDone
= false;
5460 // see comment in wxApp::GetComCtl32Version() explaining the
5461 // use of wxLoadedDLL
5462 wxLoadedDLL
dllComCtl32(wxT("comctl32.dll"));
5463 if ( dllComCtl32
.IsLoaded() )
5465 s_pfn_TrackMouseEvent
= (_TrackMouseEvent_t
)
5466 dllComCtl32
.RawGetSymbol(wxT("_TrackMouseEvent"));
5472 if ( s_pfn_TrackMouseEvent
)
5473 #endif // __WXWINCE__/!__WXWINCE__
5475 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
5477 trackinfo
.dwFlags
= TME_LEAVE
;
5478 trackinfo
.hwndTrack
= GetHwnd();
5480 (*s_pfn_TrackMouseEvent
)(&trackinfo
);
5482 #endif // HAVE_TRACKMOUSEEVENT
5484 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
5485 InitMouseEvent(event
, x
, y
, flags
);
5487 (void)HandleWindowEvent(event
);
5490 #ifdef HAVE_TRACKMOUSEEVENT
5491 else // mouse not in window
5493 // Check if we need to send a LEAVE event
5494 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
5495 // send it here if we are using native mouse leave tracking
5496 if ( HasCapture() && !IsMouseInWindow() )
5498 GenerateMouseLeave();
5501 #endif // HAVE_TRACKMOUSEEVENT
5503 #if wxUSE_MOUSEEVENT_HACK
5504 // Windows often generates mouse events even if mouse position hasn't
5505 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
5507 // Filter this out as it can result in unexpected behaviour compared to
5509 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
5510 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
5511 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
5512 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
5514 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
5516 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
5521 #endif // wxUSE_MOUSEEVENT_HACK
5523 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
5527 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
5529 #if wxUSE_MOUSEWHEEL
5530 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5531 // forwarded up to the parent by DefWindowProc()) and not in the client
5532 // ones as all the other messages, translate them to the client coords for
5535 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
5536 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
5537 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
5538 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5539 event
.m_wheelDelta
= WHEEL_DELTA
;
5541 static int s_linesPerRotation
= -1;
5542 if ( s_linesPerRotation
== -1 )
5544 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5545 &s_linesPerRotation
, 0))
5547 // this is not supposed to happen
5548 wxLogLastError(wxT("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5550 // the default is 3, so use it if SystemParametersInfo() failed
5551 s_linesPerRotation
= 3;
5555 event
.m_linesPerAction
= s_linesPerRotation
;
5556 return HandleWindowEvent(event
);
5558 #else // !wxUSE_MOUSEWHEEL
5559 wxUnusedVar(wParam
);
5560 wxUnusedVar(lParam
);
5563 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5566 void wxWindowMSW::GenerateMouseLeave()
5568 m_mouseInWindow
= false;
5571 if ( wxIsShiftDown() )
5573 if ( wxIsCtrlDown() )
5574 state
|= MK_CONTROL
;
5576 // Only the high-order bit should be tested
5577 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5578 state
|= MK_LBUTTON
;
5579 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5580 state
|= MK_MBUTTON
;
5581 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5582 state
|= MK_RBUTTON
;
5586 if ( !::GetCursorPosWinCE(&pt
) )
5588 if ( !::GetCursorPos(&pt
) )
5591 wxLogLastError(wxT("GetCursorPos"));
5594 // we need to have client coordinates here for symmetry with
5595 // wxEVT_ENTER_WINDOW
5596 RECT rect
= wxGetWindowRect(GetHwnd());
5600 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5601 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5603 (void)HandleWindowEvent(event
);
5606 // ---------------------------------------------------------------------------
5607 // keyboard handling
5608 // ---------------------------------------------------------------------------
5610 // create the key event of the given type for the given key - used by
5611 // HandleChar and HandleKeyDown/Up
5612 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5615 WXWPARAM wParam
) const
5617 wxKeyEvent
event(evType
);
5618 event
.SetId(GetId());
5619 event
.m_shiftDown
= wxIsShiftDown();
5620 event
.m_controlDown
= wxIsCtrlDown();
5621 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5623 event
.SetEventObject((wxWindow
*)this); // const_cast
5624 event
.m_keyCode
= id
;
5626 event
.m_uniChar
= (wxChar
) wParam
;
5628 event
.m_rawCode
= (wxUint32
) wParam
;
5629 event
.m_rawFlags
= (wxUint32
) lParam
;
5631 event
.SetTimestamp(::GetMessageTime());
5634 // translate the position to client coordinates
5635 const wxPoint mousePos
= ScreenToClient(wxGetMousePosition());
5636 event
.m_x
= mousePos
.x
;
5637 event
.m_y
= mousePos
.y
;
5642 // isASCII is true only when we're called from WM_CHAR handler and not from
5644 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
5651 else // we're called from WM_KEYDOWN
5653 // don't pass lParam to wxCharCodeMSWToWX() here because we don't want
5654 // to get numpad key codes: CHAR events should use the logical keys
5655 // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events
5656 id
= wxCharCodeMSWToWX(wParam
);
5659 // it's ASCII and will be processed here only when called from
5660 // WM_CHAR (i.e. when isASCII = true), don't process it now
5665 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
5667 // the alphanumeric keys produced by pressing AltGr+something on European
5668 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5669 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5670 // alphanumeric, so pretend that there are no modifiers at all (the
5671 // KEY_DOWN event would still have the correct modifiers if they're really
5673 if ( event
.m_controlDown
&& event
.m_altDown
&&
5674 (id
>= 32 && id
< 256) )
5676 event
.m_controlDown
=
5677 event
.m_altDown
= false;
5680 return HandleWindowEvent(event
);
5683 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5685 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5689 // normal ASCII char
5693 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
5694 return HandleWindowEvent(event
);
5697 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5699 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5703 // normal ASCII char
5707 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
5708 return HandleWindowEvent(event
);
5712 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5713 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5715 // FIXME: implement GetMenuItemCount for WinCE, possibly
5716 // in terms of GetMenuItemInfo
5718 const HMENU hmenu
= (HMENU
)lParam
;
5722 mii
.cbSize
= sizeof(MENUITEMINFO
);
5724 // we could use MIIM_FTYPE here as we only need to know if the item is
5725 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5726 // MIIM_FTYPE is not supported under Win95
5727 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5729 // find if we have this letter in any owner drawn item
5730 const int count
= ::GetMenuItemCount(hmenu
);
5731 for ( int i
= 0; i
< count
; i
++ )
5733 // previous loop iteration could modify it, reset it back before
5734 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5737 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5739 if ( mii
.fType
== MFT_OWNERDRAW
)
5741 // dwItemData member of the MENUITEMINFO is a
5742 // pointer to the associated wxMenuItem -- see the
5743 // menu creation code
5744 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5746 const wxString
label(item
->GetItemLabel());
5747 const wxChar
*p
= wxStrchr(label
.wx_str(), wxT('&'));
5750 if ( *p
== wxT('&') )
5752 // this is not the accel char, find the real one
5753 p
= wxStrchr(p
+ 1, wxT('&'));
5755 else // got the accel char
5757 // FIXME-UNICODE: this comparison doesn't risk to work
5758 // for non ASCII accelerator characters I'm afraid, but
5760 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5766 // this one doesn't match
5773 else // failed to get the menu text?
5775 // it's not fatal, so don't show error, but still log it
5776 wxLogLastError(wxT("GetMenuItemInfo"));
5783 #endif // wxUSE_MENUS
5785 bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg
)
5787 const wxEventType type
= nMsg
== WM_CUT
? wxEVT_COMMAND_TEXT_CUT
5788 : nMsg
== WM_COPY
? wxEVT_COMMAND_TEXT_COPY
5789 : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE
;
5790 wxClipboardTextEvent
evt(type
, GetId());
5792 evt
.SetEventObject(this);
5794 return HandleWindowEvent(evt
);
5797 // ---------------------------------------------------------------------------
5799 // ---------------------------------------------------------------------------
5801 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5805 if ( flags
& JOY_BUTTON1CHG
)
5806 change
= wxJOY_BUTTON1
;
5807 if ( flags
& JOY_BUTTON2CHG
)
5808 change
= wxJOY_BUTTON2
;
5809 if ( flags
& JOY_BUTTON3CHG
)
5810 change
= wxJOY_BUTTON3
;
5811 if ( flags
& JOY_BUTTON4CHG
)
5812 change
= wxJOY_BUTTON4
;
5815 if ( flags
& JOY_BUTTON1
)
5816 buttons
|= wxJOY_BUTTON1
;
5817 if ( flags
& JOY_BUTTON2
)
5818 buttons
|= wxJOY_BUTTON2
;
5819 if ( flags
& JOY_BUTTON3
)
5820 buttons
|= wxJOY_BUTTON3
;
5821 if ( flags
& JOY_BUTTON4
)
5822 buttons
|= wxJOY_BUTTON4
;
5824 // the event ids aren't consecutive so we can't use table based lookup
5826 wxEventType eventType
;
5831 eventType
= wxEVT_JOY_MOVE
;
5836 eventType
= wxEVT_JOY_MOVE
;
5841 eventType
= wxEVT_JOY_ZMOVE
;
5846 eventType
= wxEVT_JOY_ZMOVE
;
5849 case MM_JOY1BUTTONDOWN
:
5851 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5854 case MM_JOY2BUTTONDOWN
:
5856 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5859 case MM_JOY1BUTTONUP
:
5861 eventType
= wxEVT_JOY_BUTTON_UP
;
5864 case MM_JOY2BUTTONUP
:
5866 eventType
= wxEVT_JOY_BUTTON_UP
;
5870 wxFAIL_MSG(wxT("no such joystick event"));
5875 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5876 event
.SetPosition(wxPoint(x
, y
));
5877 event
.SetEventObject(this);
5879 return HandleWindowEvent(event
);
5889 // ---------------------------------------------------------------------------
5891 // ---------------------------------------------------------------------------
5893 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5894 WXWORD pos
, WXHWND control
)
5896 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5898 wxWindow
*child
= wxFindWinFromHandle(control
);
5900 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5903 wxScrollWinEvent event
;
5904 event
.SetPosition(pos
);
5905 event
.SetOrientation(orientation
);
5906 event
.SetEventObject(this);
5911 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5915 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5919 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5923 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5927 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5931 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5934 case SB_THUMBPOSITION
:
5936 // under Win32, the scrollbar range and position are 32 bit integers,
5937 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5938 // explicitly query the scrollbar for the correct position (this must
5939 // be done only for these two SB_ events as they are the only one
5940 // carrying the scrollbar position)
5942 WinStruct
<SCROLLINFO
> scrollInfo
;
5943 scrollInfo
.fMask
= SIF_TRACKPOS
;
5945 if ( !::GetScrollInfo(GetHwnd(),
5946 WXOrientToSB(orientation
),
5949 // Not necessarily an error, if there are no scrollbars yet.
5950 // wxLogLastError(wxT("GetScrollInfo"));
5953 event
.SetPosition(scrollInfo
.nTrackPos
);
5956 event
.SetEventType( wParam
== SB_THUMBPOSITION
5957 ? wxEVT_SCROLLWIN_THUMBRELEASE
5958 : wxEVT_SCROLLWIN_THUMBTRACK
);
5965 return HandleWindowEvent(event
);
5968 // ----------------------------------------------------------------------------
5969 // custom message handlers
5970 // ----------------------------------------------------------------------------
5973 wxWindowMSW::MSWRegisterMessageHandler(int msg
, MSWMessageHandler handler
)
5975 wxCHECK_MSG( gs_messageHandlers
.find(msg
) == gs_messageHandlers
.end(),
5976 false, wxT("registering handler for the same message twice") );
5978 gs_messageHandlers
[msg
] = handler
;
5983 wxWindowMSW::MSWUnregisterMessageHandler(int msg
, MSWMessageHandler handler
)
5985 const MSWMessageHandlers::iterator i
= gs_messageHandlers
.find(msg
);
5986 wxCHECK_RET( i
!= gs_messageHandlers
.end() && i
->second
== handler
,
5987 wxT("unregistering non-registered handler?") );
5989 gs_messageHandlers
.erase(i
);
5992 // ===========================================================================
5994 // ===========================================================================
5996 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5999 HDC dc
= ::GetDC((HWND
) wnd
);
6002 // the_font.UseResource();
6003 // the_font.RealizeResource();
6004 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
6006 was
= (HFONT
) SelectObject(dc
,fnt
);
6008 GetTextMetrics(dc
, &tm
);
6011 SelectObject(dc
,was
);
6013 ReleaseDC((HWND
)wnd
, dc
);
6016 *x
= tm
.tmAveCharWidth
;
6018 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
6020 // the_font.ReleaseResource();
6023 // use the "extended" bit (24) of lParam to distinguish extended keys
6024 // from normal keys as the same key is sent
6026 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
6028 // except that if lParam is 0, it means we don't have real lParam from
6029 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
6030 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
6031 // non-numpad (hence extended) key as this is a more common case
6032 return !lParam
|| (lParam
& (1 << 24)) ? keyExtended
: keyNormal
;
6035 // this array contains the Windows virtual key codes which map one to one to
6036 // WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below
6038 // note that keys having a normal and numpad version (e.g. WXK_HOME and
6039 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
6040 static const struct wxKeyMapping
6044 } gs_specialKeys
[] =
6046 { VK_CANCEL
, WXK_CANCEL
},
6047 { VK_BACK
, WXK_BACK
},
6048 { VK_TAB
, WXK_TAB
},
6049 { VK_CLEAR
, WXK_CLEAR
},
6050 { VK_SHIFT
, WXK_SHIFT
},
6051 { VK_CONTROL
, WXK_CONTROL
},
6052 { VK_MENU
, WXK_ALT
},
6053 { VK_PAUSE
, WXK_PAUSE
},
6054 { VK_CAPITAL
, WXK_CAPITAL
},
6055 { VK_SPACE
, WXK_SPACE
},
6056 { VK_ESCAPE
, WXK_ESCAPE
},
6057 { VK_SELECT
, WXK_SELECT
},
6058 { VK_PRINT
, WXK_PRINT
},
6059 { VK_EXECUTE
, WXK_EXECUTE
},
6060 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
6061 { VK_HELP
, WXK_HELP
},
6063 { VK_NUMPAD0
, WXK_NUMPAD0
},
6064 { VK_NUMPAD1
, WXK_NUMPAD1
},
6065 { VK_NUMPAD2
, WXK_NUMPAD2
},
6066 { VK_NUMPAD3
, WXK_NUMPAD3
},
6067 { VK_NUMPAD4
, WXK_NUMPAD4
},
6068 { VK_NUMPAD5
, WXK_NUMPAD5
},
6069 { VK_NUMPAD6
, WXK_NUMPAD6
},
6070 { VK_NUMPAD7
, WXK_NUMPAD7
},
6071 { VK_NUMPAD8
, WXK_NUMPAD8
},
6072 { VK_NUMPAD9
, WXK_NUMPAD9
},
6073 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
6074 { VK_ADD
, WXK_NUMPAD_ADD
},
6075 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
6076 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
6077 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
6088 { VK_F10
, WXK_F10
},
6089 { VK_F11
, WXK_F11
},
6090 { VK_F12
, WXK_F12
},
6091 { VK_F13
, WXK_F13
},
6092 { VK_F14
, WXK_F14
},
6093 { VK_F15
, WXK_F15
},
6094 { VK_F16
, WXK_F16
},
6095 { VK_F17
, WXK_F17
},
6096 { VK_F18
, WXK_F18
},
6097 { VK_F19
, WXK_F19
},
6098 { VK_F20
, WXK_F20
},
6099 { VK_F21
, WXK_F21
},
6100 { VK_F22
, WXK_F22
},
6101 { VK_F23
, WXK_F23
},
6102 { VK_F24
, WXK_F24
},
6104 { VK_NUMLOCK
, WXK_NUMLOCK
},
6105 { VK_SCROLL
, WXK_SCROLL
},
6108 { VK_LWIN
, WXK_WINDOWS_LEFT
},
6109 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
6110 { VK_APPS
, WXK_WINDOWS_MENU
},
6111 #endif // VK_APPS defined
6114 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
6115 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
6116 int wxCharCodeMSWToWX(int vk
, WXLPARAM lParam
)
6118 // check the table first
6119 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6121 if ( gs_specialKeys
[n
].vk
== vk
)
6122 return gs_specialKeys
[n
].wxk
;
6125 // keys requiring special handling
6129 // the mapping for these keys may be incorrect on non-US keyboards so
6130 // maybe we shouldn't map them to ASCII values at all
6131 case VK_OEM_1
: wxk
= ';'; break;
6132 case VK_OEM_PLUS
: wxk
= '+'; break;
6133 case VK_OEM_COMMA
: wxk
= ','; break;
6134 case VK_OEM_MINUS
: wxk
= '-'; break;
6135 case VK_OEM_PERIOD
: wxk
= '.'; break;
6136 case VK_OEM_2
: wxk
= '/'; break;
6137 case VK_OEM_3
: wxk
= '~'; break;
6138 case VK_OEM_4
: wxk
= '['; break;
6139 case VK_OEM_5
: wxk
= '\\'; break;
6140 case VK_OEM_6
: wxk
= ']'; break;
6141 case VK_OEM_7
: wxk
= '\''; break;
6143 // handle extended keys
6145 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
6149 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
6153 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
6157 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
6161 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
6165 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
6169 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
6173 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
6177 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
6181 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
6185 // don't use ChooseNormalOrExtended() here as the keys are reversed
6186 // here: numpad enter is the extended one
6187 wxk
= lParam
&& (lParam
& (1 << 24)) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
6197 WXWORD
wxCharCodeWXToMSW(int wxk
)
6199 // check the table first
6200 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6202 if ( gs_specialKeys
[n
].wxk
== wxk
)
6203 return gs_specialKeys
[n
].vk
;
6206 // and then check for special keys not included in the table
6211 case WXK_NUMPAD_PAGEUP
:
6216 case WXK_NUMPAD_PAGEDOWN
:
6221 case WXK_NUMPAD_END
:
6226 case WXK_NUMPAD_HOME
:
6231 case WXK_NUMPAD_LEFT
:
6241 case WXK_NUMPAD_RIGHT
:
6246 case WXK_NUMPAD_DOWN
:
6251 case WXK_NUMPAD_INSERT
:
6256 case WXK_NUMPAD_DELETE
:
6261 // no VkKeyScan() under CE unfortunately, we need to test how does
6262 // it handle OEM keys
6264 // check to see if its one of the OEM key codes.
6265 BYTE vks
= LOBYTE(VkKeyScan(wxk
));
6271 #endif // !__WXWINCE__
6280 // small helper for wxGetKeyState() and wxGetMouseState()
6281 static inline bool wxIsKeyDown(WXWORD vk
)
6283 // SM_SWAPBUTTON is not available under CE, so don't swap buttons there
6284 #ifdef SM_SWAPBUTTON
6285 if ( vk
== VK_LBUTTON
|| vk
== VK_RBUTTON
)
6287 if ( ::GetSystemMetrics(SM_SWAPBUTTON
) )
6289 if ( vk
== VK_LBUTTON
)
6291 else // vk == VK_RBUTTON
6295 #endif // SM_SWAPBUTTON
6297 // the low order bit indicates whether the key was pressed since the last
6298 // call and the high order one indicates whether it is down right now and
6299 // we only want that one
6300 return (GetAsyncKeyState(vk
) & (1<<15)) != 0;
6303 bool wxGetKeyState(wxKeyCode key
)
6305 // although this does work under Windows, it is not supported under other
6306 // platforms so don't allow it, you must use wxGetMouseState() instead
6307 wxASSERT_MSG( key
!= VK_LBUTTON
&&
6308 key
!= VK_RBUTTON
&&
6310 wxT("can't use wxGetKeyState() for mouse buttons") );
6312 const WXWORD vk
= wxCharCodeWXToMSW(key
);
6314 // if the requested key is a LED key, return true if the led is pressed
6315 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
6317 // low order bit means LED is highlighted and high order one means the
6318 // key is down; for compatibility with the other ports return true if
6319 // either one is set
6320 return GetKeyState(vk
) != 0;
6325 return wxIsKeyDown(vk
);
6330 wxMouseState
wxGetMouseState()
6334 GetCursorPos( &pt
);
6338 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
6339 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
6340 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
6341 #ifdef wxHAS_XBUTTON
6342 ms
.SetAux1Down(wxIsKeyDown(VK_XBUTTON1
));
6343 ms
.SetAux2Down(wxIsKeyDown(VK_XBUTTON2
));
6344 #endif // wxHAS_XBUTTON
6346 ms
.SetControlDown(wxIsCtrlDown ());
6347 ms
.SetShiftDown (wxIsShiftDown());
6348 ms
.SetAltDown (wxIsAltDown ());
6349 // ms.SetMetaDown();
6355 wxWindow
*wxGetActiveWindow()
6357 HWND hWnd
= GetActiveWindow();
6360 return wxFindWinFromHandle(hWnd
);
6365 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
6367 HWND hwnd
= (HWND
)hWnd
;
6369 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
6370 // by code in msw/radiobox.cpp), for all the others we just search up the
6372 wxWindow
*win
= NULL
;
6375 win
= wxFindWinFromHandle(hwnd
);
6379 // native radiobuttons return DLGC_RADIOBUTTON here and for any
6380 // wxWindow class which overrides WM_GETDLGCODE processing to
6381 // do it as well, win would be already non NULL
6382 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
6384 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
6386 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
6387 #endif // wxUSE_RADIOBOX
6389 // spin control text buddy window should be mapped to spin ctrl
6390 // itself so try it too
6391 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
6394 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
6396 #endif // wxUSE_SPINCTRL
6400 while ( hwnd
&& !win
)
6402 // this is a really ugly hack needed to avoid mistakenly returning the
6403 // parent frame wxWindow for the find/replace modeless dialog HWND -
6404 // this, in turn, is needed to call IsDialogMessage() from
6405 // wxApp::ProcessMessage() as for this we must return NULL from here
6407 // FIXME: this is clearly not the best way to do it but I think we'll
6408 // need to change HWND <-> wxWindow code more heavily than I can
6409 // do it now to fix it
6410 #ifndef __WXMICROWIN__
6411 if ( ::GetWindow(hwnd
, GW_OWNER
) )
6413 // it's a dialog box, don't go upwards
6418 hwnd
= ::GetParent(hwnd
);
6419 win
= wxFindWinFromHandle(hwnd
);
6425 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
6427 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
6428 // in active frames and dialogs, regardless of where the focus is.
6429 static HHOOK wxTheKeyboardHook
= 0;
6432 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
6434 DWORD hiWord
= HIWORD(lParam
);
6435 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
6437 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
6440 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
6441 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
6442 event
.m_altDown
= true;
6444 event
.SetEventObject(NULL
);
6445 event
.m_keyCode
= id
;
6446 event
.m_shiftDown
= wxIsShiftDown();
6447 event
.m_controlDown
= wxIsCtrlDown();
6449 event
.SetTimestamp(::GetMessageTime());
6451 wxWindow
*win
= wxGetActiveWindow();
6452 wxEvtHandler
*handler
;
6455 handler
= win
->GetEventHandler();
6456 event
.SetId(win
->GetId());
6461 event
.SetId(wxID_ANY
);
6464 if ( handler
&& handler
->ProcessEvent(event
) )
6472 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
6475 void wxSetKeyboardHook(bool doIt
)
6479 wxTheKeyboardHook
= ::SetWindowsHookEx
6482 (HOOKPROC
)wxKeyboardHook
,
6483 NULL
, // must be NULL for process hook
6484 ::GetCurrentThreadId()
6486 if ( !wxTheKeyboardHook
)
6488 wxLogLastError(wxT("SetWindowsHookEx(wxKeyboardHook)"));
6493 if ( wxTheKeyboardHook
)
6494 ::UnhookWindowsHookEx(wxTheKeyboardHook
);
6498 #endif // !__WXMICROWIN__
6500 #if wxDEBUG_LEVEL >= 2
6501 const wxChar
*wxGetMessageName(int message
)
6505 case 0x0000: return wxT("WM_NULL");
6506 case 0x0001: return wxT("WM_CREATE");
6507 case 0x0002: return wxT("WM_DESTROY");
6508 case 0x0003: return wxT("WM_MOVE");
6509 case 0x0005: return wxT("WM_SIZE");
6510 case 0x0006: return wxT("WM_ACTIVATE");
6511 case 0x0007: return wxT("WM_SETFOCUS");
6512 case 0x0008: return wxT("WM_KILLFOCUS");
6513 case 0x000A: return wxT("WM_ENABLE");
6514 case 0x000B: return wxT("WM_SETREDRAW");
6515 case 0x000C: return wxT("WM_SETTEXT");
6516 case 0x000D: return wxT("WM_GETTEXT");
6517 case 0x000E: return wxT("WM_GETTEXTLENGTH");
6518 case 0x000F: return wxT("WM_PAINT");
6519 case 0x0010: return wxT("WM_CLOSE");
6520 case 0x0011: return wxT("WM_QUERYENDSESSION");
6521 case 0x0012: return wxT("WM_QUIT");
6522 case 0x0013: return wxT("WM_QUERYOPEN");
6523 case 0x0014: return wxT("WM_ERASEBKGND");
6524 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
6525 case 0x0016: return wxT("WM_ENDSESSION");
6526 case 0x0017: return wxT("WM_SYSTEMERROR");
6527 case 0x0018: return wxT("WM_SHOWWINDOW");
6528 case 0x0019: return wxT("WM_CTLCOLOR");
6529 case 0x001A: return wxT("WM_WININICHANGE");
6530 case 0x001B: return wxT("WM_DEVMODECHANGE");
6531 case 0x001C: return wxT("WM_ACTIVATEAPP");
6532 case 0x001D: return wxT("WM_FONTCHANGE");
6533 case 0x001E: return wxT("WM_TIMECHANGE");
6534 case 0x001F: return wxT("WM_CANCELMODE");
6535 case 0x0020: return wxT("WM_SETCURSOR");
6536 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6537 case 0x0022: return wxT("WM_CHILDACTIVATE");
6538 case 0x0023: return wxT("WM_QUEUESYNC");
6539 case 0x0024: return wxT("WM_GETMINMAXINFO");
6540 case 0x0026: return wxT("WM_PAINTICON");
6541 case 0x0027: return wxT("WM_ICONERASEBKGND");
6542 case 0x0028: return wxT("WM_NEXTDLGCTL");
6543 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6544 case 0x002B: return wxT("WM_DRAWITEM");
6545 case 0x002C: return wxT("WM_MEASUREITEM");
6546 case 0x002D: return wxT("WM_DELETEITEM");
6547 case 0x002E: return wxT("WM_VKEYTOITEM");
6548 case 0x002F: return wxT("WM_CHARTOITEM");
6549 case 0x0030: return wxT("WM_SETFONT");
6550 case 0x0031: return wxT("WM_GETFONT");
6551 case 0x0037: return wxT("WM_QUERYDRAGICON");
6552 case 0x0039: return wxT("WM_COMPAREITEM");
6553 case 0x0041: return wxT("WM_COMPACTING");
6554 case 0x0044: return wxT("WM_COMMNOTIFY");
6555 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6556 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6557 case 0x0048: return wxT("WM_POWER");
6559 case 0x004A: return wxT("WM_COPYDATA");
6560 case 0x004B: return wxT("WM_CANCELJOURNAL");
6561 case 0x004E: return wxT("WM_NOTIFY");
6562 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6563 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6564 case 0x0052: return wxT("WM_TCARD");
6565 case 0x0053: return wxT("WM_HELP");
6566 case 0x0054: return wxT("WM_USERCHANGED");
6567 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6568 case 0x007B: return wxT("WM_CONTEXTMENU");
6569 case 0x007C: return wxT("WM_STYLECHANGING");
6570 case 0x007D: return wxT("WM_STYLECHANGED");
6571 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6572 case 0x007F: return wxT("WM_GETICON");
6573 case 0x0080: return wxT("WM_SETICON");
6575 case 0x0081: return wxT("WM_NCCREATE");
6576 case 0x0082: return wxT("WM_NCDESTROY");
6577 case 0x0083: return wxT("WM_NCCALCSIZE");
6578 case 0x0084: return wxT("WM_NCHITTEST");
6579 case 0x0085: return wxT("WM_NCPAINT");
6580 case 0x0086: return wxT("WM_NCACTIVATE");
6581 case 0x0087: return wxT("WM_GETDLGCODE");
6582 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6583 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6584 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6585 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6586 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6587 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6588 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6589 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6590 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6591 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6593 case 0x00B0: return wxT("EM_GETSEL");
6594 case 0x00B1: return wxT("EM_SETSEL");
6595 case 0x00B2: return wxT("EM_GETRECT");
6596 case 0x00B3: return wxT("EM_SETRECT");
6597 case 0x00B4: return wxT("EM_SETRECTNP");
6598 case 0x00B5: return wxT("EM_SCROLL");
6599 case 0x00B6: return wxT("EM_LINESCROLL");
6600 case 0x00B7: return wxT("EM_SCROLLCARET");
6601 case 0x00B8: return wxT("EM_GETMODIFY");
6602 case 0x00B9: return wxT("EM_SETMODIFY");
6603 case 0x00BA: return wxT("EM_GETLINECOUNT");
6604 case 0x00BB: return wxT("EM_LINEINDEX");
6605 case 0x00BC: return wxT("EM_SETHANDLE");
6606 case 0x00BD: return wxT("EM_GETHANDLE");
6607 case 0x00BE: return wxT("EM_GETTHUMB");
6608 case 0x00C1: return wxT("EM_LINELENGTH");
6609 case 0x00C2: return wxT("EM_REPLACESEL");
6610 case 0x00C4: return wxT("EM_GETLINE");
6611 case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */
6612 case 0x00C6: return wxT("EM_CANUNDO");
6613 case 0x00C7: return wxT("EM_UNDO");
6614 case 0x00C8: return wxT("EM_FMTLINES");
6615 case 0x00C9: return wxT("EM_LINEFROMCHAR");
6616 case 0x00CB: return wxT("EM_SETTABSTOPS");
6617 case 0x00CC: return wxT("EM_SETPASSWORDCHAR");
6618 case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER");
6619 case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE");
6620 case 0x00CF: return wxT("EM_SETREADONLY");
6621 case 0x00D0: return wxT("EM_SETWORDBREAKPROC");
6622 case 0x00D1: return wxT("EM_GETWORDBREAKPROC");
6623 case 0x00D2: return wxT("EM_GETPASSWORDCHAR");
6624 case 0x00D3: return wxT("EM_SETMARGINS");
6625 case 0x00D4: return wxT("EM_GETMARGINS");
6626 case 0x00D5: return wxT("EM_GETLIMITTEXT");
6627 case 0x00D6: return wxT("EM_POSFROMCHAR");
6628 case 0x00D7: return wxT("EM_CHARFROMPOS");
6629 case 0x00D8: return wxT("EM_SETIMESTATUS");
6630 case 0x00D9: return wxT("EM_GETIMESTATUS");
6632 case 0x0100: return wxT("WM_KEYDOWN");
6633 case 0x0101: return wxT("WM_KEYUP");
6634 case 0x0102: return wxT("WM_CHAR");
6635 case 0x0103: return wxT("WM_DEADCHAR");
6636 case 0x0104: return wxT("WM_SYSKEYDOWN");
6637 case 0x0105: return wxT("WM_SYSKEYUP");
6638 case 0x0106: return wxT("WM_SYSCHAR");
6639 case 0x0107: return wxT("WM_SYSDEADCHAR");
6640 case 0x0108: return wxT("WM_KEYLAST");
6642 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6643 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6644 case 0x010F: return wxT("WM_IME_COMPOSITION");
6646 case 0x0110: return wxT("WM_INITDIALOG");
6647 case 0x0111: return wxT("WM_COMMAND");
6648 case 0x0112: return wxT("WM_SYSCOMMAND");
6649 case 0x0113: return wxT("WM_TIMER");
6650 case 0x0114: return wxT("WM_HSCROLL");
6651 case 0x0115: return wxT("WM_VSCROLL");
6652 case 0x0116: return wxT("WM_INITMENU");
6653 case 0x0117: return wxT("WM_INITMENUPOPUP");
6654 case 0x011F: return wxT("WM_MENUSELECT");
6655 case 0x0120: return wxT("WM_MENUCHAR");
6656 case 0x0121: return wxT("WM_ENTERIDLE");
6658 case 0x0127: return wxT("WM_CHANGEUISTATE");
6659 case 0x0128: return wxT("WM_UPDATEUISTATE");
6660 case 0x0129: return wxT("WM_QUERYUISTATE");
6662 case 0x0132: return wxT("WM_CTLCOLORMSGBOX");
6663 case 0x0133: return wxT("WM_CTLCOLOREDIT");
6664 case 0x0134: return wxT("WM_CTLCOLORLISTBOX");
6665 case 0x0135: return wxT("WM_CTLCOLORBTN");
6666 case 0x0136: return wxT("WM_CTLCOLORDLG");
6667 case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR");
6668 case 0x0138: return wxT("WM_CTLCOLORSTATIC");
6669 case 0x01E1: return wxT("MN_GETHMENU");
6671 case 0x0200: return wxT("WM_MOUSEMOVE");
6672 case 0x0201: return wxT("WM_LBUTTONDOWN");
6673 case 0x0202: return wxT("WM_LBUTTONUP");
6674 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6675 case 0x0204: return wxT("WM_RBUTTONDOWN");
6676 case 0x0205: return wxT("WM_RBUTTONUP");
6677 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6678 case 0x0207: return wxT("WM_MBUTTONDOWN");
6679 case 0x0208: return wxT("WM_MBUTTONUP");
6680 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6681 case 0x020A: return wxT("WM_MOUSEWHEEL");
6682 case 0x020B: return wxT("WM_XBUTTONDOWN");
6683 case 0x020C: return wxT("WM_XBUTTONUP");
6684 case 0x020D: return wxT("WM_XBUTTONDBLCLK");
6685 case 0x0210: return wxT("WM_PARENTNOTIFY");
6686 case 0x0211: return wxT("WM_ENTERMENULOOP");
6687 case 0x0212: return wxT("WM_EXITMENULOOP");
6689 case 0x0213: return wxT("WM_NEXTMENU");
6690 case 0x0214: return wxT("WM_SIZING");
6691 case 0x0215: return wxT("WM_CAPTURECHANGED");
6692 case 0x0216: return wxT("WM_MOVING");
6693 case 0x0218: return wxT("WM_POWERBROADCAST");
6694 case 0x0219: return wxT("WM_DEVICECHANGE");
6696 case 0x0220: return wxT("WM_MDICREATE");
6697 case 0x0221: return wxT("WM_MDIDESTROY");
6698 case 0x0222: return wxT("WM_MDIACTIVATE");
6699 case 0x0223: return wxT("WM_MDIRESTORE");
6700 case 0x0224: return wxT("WM_MDINEXT");
6701 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6702 case 0x0226: return wxT("WM_MDITILE");
6703 case 0x0227: return wxT("WM_MDICASCADE");
6704 case 0x0228: return wxT("WM_MDIICONARRANGE");
6705 case 0x0229: return wxT("WM_MDIGETACTIVE");
6706 case 0x0230: return wxT("WM_MDISETMENU");
6707 case 0x0233: return wxT("WM_DROPFILES");
6709 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6710 case 0x0282: return wxT("WM_IME_NOTIFY");
6711 case 0x0283: return wxT("WM_IME_CONTROL");
6712 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6713 case 0x0285: return wxT("WM_IME_SELECT");
6714 case 0x0286: return wxT("WM_IME_CHAR");
6715 case 0x0290: return wxT("WM_IME_KEYDOWN");
6716 case 0x0291: return wxT("WM_IME_KEYUP");
6718 case 0x02A0: return wxT("WM_NCMOUSEHOVER");
6719 case 0x02A1: return wxT("WM_MOUSEHOVER");
6720 case 0x02A2: return wxT("WM_NCMOUSELEAVE");
6721 case 0x02A3: return wxT("WM_MOUSELEAVE");
6723 case 0x0300: return wxT("WM_CUT");
6724 case 0x0301: return wxT("WM_COPY");
6725 case 0x0302: return wxT("WM_PASTE");
6726 case 0x0303: return wxT("WM_CLEAR");
6727 case 0x0304: return wxT("WM_UNDO");
6728 case 0x0305: return wxT("WM_RENDERFORMAT");
6729 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6730 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6731 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6732 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6733 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6734 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6735 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6736 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6737 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6738 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6739 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6740 case 0x0311: return wxT("WM_PALETTECHANGED");
6741 case 0x0312: return wxT("WM_HOTKEY");
6743 case 0x0317: return wxT("WM_PRINT");
6744 case 0x0318: return wxT("WM_PRINTCLIENT");
6746 // common controls messages - although they're not strictly speaking
6747 // standard, it's nice to decode them nevertheless
6750 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6751 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6752 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6753 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6754 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6755 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6756 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6757 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6758 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6759 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6760 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6761 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6762 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6763 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6764 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6765 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6766 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6767 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6768 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6769 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6770 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6771 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6772 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6773 case 0x1000 + 18: return wxT("LVM_HITTEST");
6774 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6775 case 0x1000 + 20: return wxT("LVM_SCROLL");
6776 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6777 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6778 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6779 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6780 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6781 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6782 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6783 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6784 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6785 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6786 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6787 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6788 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6789 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6790 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6791 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6792 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6793 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6794 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6795 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6796 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6797 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6798 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6799 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6800 case 0x1000 + 42: return wxT("LVM_UPDATE");
6801 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6802 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6803 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6804 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6805 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6806 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6807 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6808 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6809 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6810 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6811 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6812 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6813 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6814 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6815 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6816 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6817 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6818 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6819 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6820 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6821 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6822 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6823 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6824 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6825 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6826 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6829 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6830 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6831 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6832 case 0x1100 + 2: return wxT("TVM_EXPAND");
6833 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6834 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6835 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6836 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6837 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6838 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6839 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6840 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6841 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6842 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6843 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6844 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6845 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6846 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6847 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6848 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6849 case 0x1100 + 17: return wxT("TVM_HITTEST");
6850 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6851 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6852 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6853 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6854 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6855 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6856 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6857 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6858 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6861 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6862 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6863 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6864 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6865 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6866 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6867 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6868 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6869 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6870 case 0x1200 + 6: return wxT("HDM_HITTEST");
6871 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6872 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6873 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6874 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6875 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6876 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6877 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6878 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6881 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6882 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6883 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6884 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6885 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6886 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6887 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6888 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6889 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6890 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6891 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6892 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6893 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6894 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6895 case 0x1300 + 13: return wxT("TCM_HITTEST");
6896 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6897 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6898 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6899 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6900 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6901 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6902 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6903 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6904 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6905 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6906 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6907 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6910 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6911 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
6912 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
6913 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
6914 case WM_USER
+5: return wxT("TB_INDETERMINATE");
6915 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
6916 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
6917 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
6918 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
6919 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
6920 case WM_USER
+17: return wxT("TB_SETSTATE");
6921 case WM_USER
+18: return wxT("TB_GETSTATE");
6922 case WM_USER
+19: return wxT("TB_ADDBITMAP");
6923 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
6924 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
6925 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
6926 case WM_USER
+23: return wxT("TB_GETBUTTON");
6927 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
6928 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
6929 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
6930 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
6931 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
6932 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
6933 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
6934 case WM_USER
+29: return wxT("TB_GETITEMRECT");
6935 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
6936 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
6937 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
6938 case WM_USER
+33: return wxT("TB_AUTOSIZE");
6939 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
6940 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
6941 case WM_USER
+37: return wxT("TB_SETPARENT");
6942 case WM_USER
+39: return wxT("TB_SETROWS");
6943 case WM_USER
+40: return wxT("TB_GETROWS");
6944 case WM_USER
+42: return wxT("TB_SETCMDID");
6945 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
6946 case WM_USER
+44: return wxT("TB_GETBITMAP");
6947 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
6948 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
6949 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
6950 case WM_USER
+47: return wxT("TB_SETINDENT");
6951 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
6952 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
6953 case WM_USER
+50: return wxT("TB_LOADIMAGES");
6954 case WM_USER
+51: return wxT("TB_GETRECT");
6955 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
6956 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
6957 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
6958 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
6959 case WM_USER
+56: return wxT("TB_SETSTYLE");
6960 case WM_USER
+57: return wxT("TB_GETSTYLE");
6961 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
6962 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
6963 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
6964 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
6965 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
6968 static wxString s_szBuf
;
6969 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
6970 return s_szBuf
.c_str();
6973 #endif // wxDEBUG_LEVEL >= 2
6975 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
6979 HWND hwnd
= GetHwndOf(win
);
6980 HDC hdc
= ::GetDC(hwnd
);
6982 #if !wxDIALOG_UNIT_COMPATIBILITY
6983 // and select the current font into it
6984 HFONT hfont
= GetHfontOf(win
->GetFont());
6987 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
6991 // finally retrieve the text metrics from it
6992 GetTextMetrics(hdc
, &tm
);
6994 #if !wxDIALOG_UNIT_COMPATIBILITY
6998 (void)::SelectObject(hdc
, hfont
);
7002 ::ReleaseDC(hwnd
, hdc
);
7007 // Find the wxWindow at the current mouse position, returning the mouse
7009 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
7011 pt
= wxGetMousePosition();
7012 return wxFindWindowAtPoint(pt
);
7015 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
7021 HWND hWnd
= ::WindowFromPoint(pt2
);
7023 return wxGetWindowFromHWND((WXHWND
)hWnd
);
7026 // Get the current mouse position.
7027 wxPoint
wxGetMousePosition()
7031 GetCursorPosWinCE(&pt
);
7033 GetCursorPos( & pt
);
7036 return wxPoint(pt
.x
, pt
.y
);
7041 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7042 static void WinCEUnregisterHotKey(int modifiers
, int id
)
7044 // Register hotkeys for the hardware buttons
7046 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
7048 UnregisterFunc1Proc procUnregisterFunc
;
7049 hCoreDll
= LoadLibrary(wxT("coredll.dll"));
7052 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, wxT("UnregisterFunc1"));
7053 if (procUnregisterFunc
)
7054 procUnregisterFunc(modifiers
, id
);
7055 FreeLibrary(hCoreDll
);
7060 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
7062 UINT win_modifiers
=0;
7063 if ( modifiers
& wxMOD_ALT
)
7064 win_modifiers
|= MOD_ALT
;
7065 if ( modifiers
& wxMOD_SHIFT
)
7066 win_modifiers
|= MOD_SHIFT
;
7067 if ( modifiers
& wxMOD_CONTROL
)
7068 win_modifiers
|= MOD_CONTROL
;
7069 if ( modifiers
& wxMOD_WIN
)
7070 win_modifiers
|= MOD_WIN
;
7072 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7073 // Required for PPC and Smartphone hardware buttons
7074 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
7075 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
7078 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
7080 wxLogLastError(wxT("RegisterHotKey"));
7088 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
7090 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7091 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
7094 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
7096 wxLogLastError(wxT("UnregisterHotKey"));
7106 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
7108 int hotkeyId
= wParam
;
7109 int virtualKey
= HIWORD(lParam
);
7110 int win_modifiers
= LOWORD(lParam
);
7112 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
7113 event
.SetId(hotkeyId
);
7114 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
7115 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
7116 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
7117 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
7119 return HandleWindowEvent(event
);
7122 #endif // wxUSE_ACCEL
7124 #endif // wxUSE_HOTKEY
7126 // Not tested under WinCE
7129 // this class installs a message hook which really wakes up our idle processing
7130 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
7131 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
7132 // being dragged or even inside ::MessageBox()) and so don't control message
7133 // dispatching otherwise
7134 class wxIdleWakeUpModule
: public wxModule
7137 virtual bool OnInit()
7139 ms_hMsgHookProc
= ::SetWindowsHookEx
7142 &wxIdleWakeUpModule::MsgHookProc
,
7144 GetCurrentThreadId()
7147 if ( !ms_hMsgHookProc
)
7149 wxLogLastError(wxT("SetWindowsHookEx(WH_GETMESSAGE)"));
7157 virtual void OnExit()
7159 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
7162 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
7164 MSG
*msg
= (MSG
*)lParam
;
7166 // only process the message if it is actually going to be removed from
7167 // the message queue, this prevents that the same event from being
7168 // processed multiple times if now someone just called PeekMessage()
7169 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
7171 wxTheApp
->ProcessPendingEvents();
7174 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
7178 static HHOOK ms_hMsgHookProc
;
7180 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
7183 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
7185 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
7187 #endif // __WXWINCE__
7192 static void wxAdjustZOrder(wxWindow
* parent
)
7194 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
7196 // Set the z-order correctly
7197 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
7200 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
7203 wxWindow
*childWin
= current
->GetData();
7204 wxAdjustZOrder(childWin
);
7205 current
= current
->GetNext();
7210 // We need to adjust the z-order of static boxes in WinCE, to
7211 // make 'contained' controls visible
7212 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
7215 wxAdjustZOrder(this);