1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/window.cpp
3 // Purpose: wxWindowMSW
4 // Author: Julian Smart
5 // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/window.h"
30 #include "wx/msw/wrapwin.h"
31 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/msw/missing.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcmemory.h"
40 #include "wx/layout.h"
41 #include "wx/dialog.h"
43 #include "wx/listbox.h"
44 #include "wx/button.h"
45 #include "wx/msgdlg.h"
46 #include "wx/settings.h"
47 #include "wx/statbox.h"
51 #include "wx/textctrl.h"
52 #include "wx/menuitem.h"
53 #include "wx/module.h"
56 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
57 #include "wx/ownerdrw.h"
60 #include "wx/hashmap.h"
61 #include "wx/evtloop.h"
63 #include "wx/sysopt.h"
65 #if wxUSE_DRAG_AND_DROP
69 #if wxUSE_ACCESSIBILITY
70 #include "wx/access.h"
74 #define WM_GETOBJECT 0x003D
77 #define OBJID_CLIENT 0xFFFFFFFC
81 #include "wx/msw/private.h"
82 #include "wx/msw/private/keyboard.h"
83 #include "wx/msw/dcclient.h"
86 #include "wx/tooltip.h"
94 #include "wx/radiobox.h"
95 #endif // wxUSE_RADIOBOX
98 #include "wx/spinctrl.h"
99 #endif // wxUSE_SPINCTRL
101 #include "wx/notebook.h"
102 #include "wx/listctrl.h"
103 #include "wx/dynlib.h"
107 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
108 #include <shellapi.h>
109 #include <mmsystem.h>
113 #include <windowsx.h>
116 #if !defined __WXWINCE__ && !defined NEED_PBT_H
120 #if defined(__WXWINCE__)
121 #include "wx/msw/wince/missing.h"
124 #include <shellapi.h>
126 #include <aygshell.h>
131 #include "wx/msw/uxtheme.h"
132 #define EP_EDITTEXT 1
135 #define ETS_SELECTED 3
136 #define ETS_DISABLED 4
137 #define ETS_FOCUSED 5
138 #define ETS_READONLY 6
142 // define the constants used by AnimateWindow() if our SDK doesn't have them
144 #define AW_HOR_POSITIVE 0x00000001
145 #define AW_HOR_NEGATIVE 0x00000002
146 #define AW_VER_POSITIVE 0x00000004
147 #define AW_VER_NEGATIVE 0x00000008
148 #define AW_CENTER 0x00000010
149 #define AW_HIDE 0x00010000
150 #define AW_ACTIVATE 0x00020000
151 #define AW_SLIDE 0x00040000
152 #define AW_BLEND 0x00080000
155 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS
156 #define HAVE_TRACKMOUSEEVENT
157 #endif // everything needed for TrackMouseEvent()
159 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
160 // when mouse position didnd't change
162 #define wxUSE_MOUSEEVENT_HACK 0
164 #define wxUSE_MOUSEEVENT_HACK 1
167 // not all compilers/platforms have X button related declarations (notably
168 // Windows CE doesn't, and probably some old SDKs don't neither)
169 #ifdef WM_XBUTTONDOWN
170 #define wxHAS_XBUTTON
173 #ifndef MAPVK_VK_TO_CHAR
174 #define MAPVK_VK_TO_CHAR 2
177 // ---------------------------------------------------------------------------
179 // ---------------------------------------------------------------------------
181 #if wxUSE_MENUS_NATIVE
182 extern wxMenu
*wxCurrentPopupMenu
;
188 // true if we had already created the std colour map, used by
189 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
190 bool gs_hasStdCmap
= false;
192 // last mouse event information we need to filter out the duplicates
193 #if wxUSE_MOUSEEVENT_HACK
194 struct MouseEventInfoDummy
196 // mouse position (in screen coordinates)
199 // last mouse event type
202 #endif // wxUSE_MOUSEEVENT_HACK
204 // hash containing the registered handlers for the custom messages
205 WX_DECLARE_HASH_MAP(int, wxWindow::MSWMessageHandler
,
206 wxIntegerHash
, wxIntegerEqual
,
209 MSWMessageHandlers gs_messageHandlers
;
211 // hash containing all our windows, it uses HWND keys and wxWindow* values
212 WX_DECLARE_HASH_MAP(HWND
, wxWindow
*,
213 wxPointerHash
, wxPointerEqual
,
216 WindowHandles gs_windowHandles
;
218 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
220 // temporary override for WM_ERASEBKGND processing: we don't store this in
221 // wxWindow itself as we don't need it during most of the time so don't
222 // increase the size of all window objects unnecessarily
223 WX_DECLARE_HASH_MAP(wxWindow
*, wxWindow
*,
224 wxPointerHash
, wxPointerEqual
,
227 EraseBgHooks gs_eraseBgHooks
;
229 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
231 // If this variable is strictly positive, EVT_CHAR_HOOK is not generated for
232 // Escape key presses as it can't be intercepted because it's needed by some
233 // currently shown window, e.g. IME entry.
235 // This is currently global as we allow using UI from the main thread only
236 // anyhow but could be replaced with a thread-specific value in the future if
238 int gs_modalEntryWindowCount
= 0;
240 } // anonymous namespace
242 // ---------------------------------------------------------------------------
244 // ---------------------------------------------------------------------------
246 // the window proc for all our windows
247 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
248 WPARAM wParam
, LPARAM lParam
);
251 #if wxDEBUG_LEVEL >= 2
252 const wxChar
*wxGetMessageName(int message
);
253 #endif // wxDEBUG_LEVEL >= 2
255 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
256 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
258 // get the text metrics for the current font
259 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
262 // find the window for the mouse event at the specified position
263 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
264 #endif // __WXWINCE__
266 // wrapper around BringWindowToTop() API
267 static inline void wxBringWindowToTop(HWND hwnd
)
269 #ifdef __WXMICROWIN__
270 // It seems that MicroWindows brings the _parent_ of the window to the top,
271 // which can be the wrong one.
273 // activate (set focus to) specified window
277 // raise top level parent to top of z order
278 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
280 wxLogLastError(wxT("SetWindowPos"));
286 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
287 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
290 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
291 parent as well as otherwise several Win32 functions using
292 GetNextDlgTabItem() to iterate over all controls such as
293 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
294 all of them iterate over all the controls starting from the currently
295 focused one and stop iterating when they get back to the focus but
296 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
297 get back to the initial (focused) window: as we do have this style,
298 GetNextDlgTabItem() will leave this window and continue in its parent,
299 but if the parent doesn't have it, it wouldn't recurse inside it later
300 on and so wouldn't have a chance of getting back to this window either.
302 while ( parent
&& !parent
->IsTopLevel() )
304 LONG exStyle
= wxGetWindowExStyle(parent
);
305 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
307 // force the parent to have this style
308 wxSetWindowExStyle(parent
, exStyle
| WS_EX_CONTROLPARENT
);
311 parent
= parent
->GetParent();
315 #endif // !__WXWINCE__
318 // On Windows CE, GetCursorPos can return an error, so use this function
320 bool GetCursorPosWinCE(POINT
* pt
)
322 if (!GetCursorPos(pt
))
324 DWORD pos
= GetMessagePos();
332 // ---------------------------------------------------------------------------
334 // ---------------------------------------------------------------------------
336 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
338 #ifdef __WXUNIVERSAL__
339 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
340 #endif // __WXUNIVERSAL__
342 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
343 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
345 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
349 // ===========================================================================
351 // ===========================================================================
353 // ---------------------------------------------------------------------------
354 // wxWindow utility functions
355 // ---------------------------------------------------------------------------
357 // Find an item given the MS Windows id
358 wxWindow
*wxWindowMSW::FindItem(long id
) const
361 wxControl
*item
= wxDynamicCastThis(wxControl
);
364 // is it us or one of our "internal" children?
365 if ( item
->GetId() == id
366 #ifndef __WXUNIVERSAL__
367 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
368 #endif // __WXUNIVERSAL__
374 #endif // wxUSE_CONTROLS
376 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
379 wxWindow
*childWin
= current
->GetData();
381 wxWindow
*wnd
= childWin
->FindItem(id
);
385 current
= current
->GetNext();
391 // Find an item given the MS Windows handle
392 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
394 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
397 wxWindow
*parent
= current
->GetData();
399 // Do a recursive search.
400 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
406 || parent
->IsKindOf(CLASSINFO(wxControl
))
407 #endif // wxUSE_CONTROLS
410 wxWindow
*item
= current
->GetData();
411 if ( item
->GetHWND() == hWnd
)
415 if ( item
->ContainsHWND(hWnd
) )
420 current
= current
->GetNext();
425 // Default command handler
426 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
431 // ----------------------------------------------------------------------------
432 // constructors and such
433 // ----------------------------------------------------------------------------
435 void wxWindowMSW::Init()
439 m_mouseInWindow
= false;
440 m_lastKeydownProcessed
= false;
447 #if wxUSE_DEFERRED_SIZING
449 m_pendingPosition
= wxDefaultPosition
;
450 m_pendingSize
= wxDefaultSize
;
451 #endif // wxUSE_DEFERRED_SIZING
454 m_contextMenuEnabled
= false;
459 wxWindowMSW::~wxWindowMSW()
463 #ifndef __WXUNIVERSAL__
464 // VS: make sure there's no wxFrame with last focus set to us:
465 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
467 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
470 if ( frame
->GetLastFocus() == this )
472 frame
->SetLastFocus(NULL
);
475 // apparently sometimes we can end up with our grand parent
476 // pointing to us as well: this is surely a bug in focus handling
477 // code but it's not clear where it happens so for now just try to
478 // fix it here by not breaking out of the loop
482 #endif // __WXUNIVERSAL__
484 // VS: destroy children first and _then_ detach *this from its parent.
485 // If we did it the other way around, children wouldn't be able
486 // find their parent frame (see above).
491 // VZ: test temp removed to understand what really happens here
492 //if (::IsWindow(GetHwnd()))
494 if ( !::DestroyWindow(GetHwnd()) )
496 wxLogLastError(wxT("DestroyWindow"));
500 // remove hWnd <-> wxWindow association
501 wxRemoveHandleAssociation(this);
507 const wxChar
*wxWindowMSW::MSWGetRegisteredClassName()
509 return wxApp::GetRegisteredClassName(wxT("wxWindow"), COLOR_BTNFACE
);
512 // real construction (Init() must have been called before!)
513 bool wxWindowMSW::Create(wxWindow
*parent
,
518 const wxString
& name
)
520 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
522 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
525 parent
->AddChild(this);
528 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
530 #ifdef __WXUNIVERSAL__
531 // no borders, we draw them ourselves
532 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
536 msflags
&= ~WS_BORDER
;
537 #endif // wxUniversal
541 msflags
|= WS_VISIBLE
;
544 if ( !MSWCreate(MSWGetRegisteredClassName(),
545 NULL
, pos
, size
, msflags
, exstyle
) )
553 // ---------------------------------------------------------------------------
555 // ---------------------------------------------------------------------------
557 void wxWindowMSW::SetFocus()
559 HWND hWnd
= GetHwnd();
560 wxCHECK_RET( hWnd
, wxT("can't set focus to invalid window") );
562 #if !defined(__WXWINCE__)
566 if ( !::SetFocus(hWnd
) )
568 // was there really an error?
569 DWORD dwRes
= ::GetLastError();
572 HWND hwndFocus
= ::GetFocus();
573 if ( hwndFocus
!= hWnd
)
575 wxLogApiError(wxT("SetFocus"), dwRes
);
581 void wxWindowMSW::SetFocusFromKbd()
583 // when the focus is given to the control with DLGC_HASSETSEL style from
584 // keyboard its contents should be entirely selected: this is what
585 // ::IsDialogMessage() does and so we should do it as well to provide the
586 // same LNF as the native programs
587 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
589 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
592 // do this after (maybe) setting the selection as like this when
593 // wxEVT_SET_FOCUS handler is called, the selection would have been already
594 // set correctly -- this may be important
595 wxWindowBase::SetFocusFromKbd();
598 // Get the window with the focus
599 wxWindow
*wxWindowBase::DoFindFocus()
601 HWND hWnd
= ::GetFocus();
604 return wxGetWindowFromHWND((WXHWND
)hWnd
);
610 void wxWindowMSW::DoEnable( bool enable
)
612 MSWEnableHWND(GetHwnd(), enable
);
615 bool wxWindowMSW::MSWEnableHWND(WXHWND hWnd
, bool enable
)
620 // If disabling focused control, we move focus to the next one, as if the
621 // user pressed Tab. That's because we can't keep focus on a disabled
622 // control, Tab-navigation would stop working then.
623 if ( !enable
&& ::GetFocus() == hWnd
)
626 return ::EnableWindow(hWnd
, (BOOL
)enable
) != 0;
629 bool wxWindowMSW::Show(bool show
)
631 if ( !wxWindowBase::Show(show
) )
634 HWND hWnd
= GetHwnd();
636 // we could be called before the underlying window is created (this is
637 // actually useful to prevent it from being initially shown), e.g.
639 // wxFoo *foo = new wxFoo;
641 // foo->Create(parent, ...);
643 // should work without errors
646 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
651 // DoFreeze/DoThaw don't do anything if the window is not shown, so
652 // we have to call them from here now
663 wxWindowMSW::MSWShowWithEffect(bool show
,
667 if ( effect
== wxSHOW_EFFECT_NONE
)
670 if ( !wxWindowBase::Show(show
) )
673 typedef BOOL (WINAPI
*AnimateWindow_t
)(HWND
, DWORD
, DWORD
);
675 static AnimateWindow_t s_pfnAnimateWindow
= NULL
;
676 static bool s_initDone
= false;
679 wxDynamicLibrary
dllUser32(wxT("user32.dll"), wxDL_VERBATIM
| wxDL_QUIET
);
680 wxDL_INIT_FUNC(s_pfn
, AnimateWindow
, dllUser32
);
684 // notice that it's ok to unload user32.dll here as it won't be really
685 // unloaded, being still in use because we link to it statically too
688 if ( !s_pfnAnimateWindow
)
691 // Show() has a side effect of sending a WM_SIZE to the window, which helps
692 // ensuring that it's laid out correctly, but AnimateWindow() doesn't do
693 // this so send the event ourselves
696 // prepare to use AnimateWindow()
699 timeout
= 200; // this is the default animation timeout, per MSDN
701 DWORD dwFlags
= show
? 0 : AW_HIDE
;
705 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
706 dwFlags
|= AW_HOR_NEGATIVE
;
709 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
710 dwFlags
|= AW_HOR_POSITIVE
;
713 case wxSHOW_EFFECT_ROLL_TO_TOP
:
714 dwFlags
|= AW_VER_NEGATIVE
;
717 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
718 dwFlags
|= AW_VER_POSITIVE
;
721 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
722 dwFlags
|= AW_SLIDE
| AW_HOR_NEGATIVE
;
725 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
726 dwFlags
|= AW_SLIDE
| AW_HOR_POSITIVE
;
729 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
730 dwFlags
|= AW_SLIDE
| AW_VER_NEGATIVE
;
733 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
734 dwFlags
|= AW_SLIDE
| AW_VER_POSITIVE
;
737 case wxSHOW_EFFECT_BLEND
:
741 case wxSHOW_EFFECT_EXPAND
:
742 dwFlags
|= AW_CENTER
;
746 case wxSHOW_EFFECT_MAX
:
747 wxFAIL_MSG( wxT("invalid window show effect") );
751 wxFAIL_MSG( wxT("unknown window show effect") );
755 if ( !(*s_pfnAnimateWindow
)(GetHwnd(), timeout
, dwFlags
) )
757 wxLogLastError(wxT("AnimateWindow"));
765 // Raise the window to the top of the Z order
766 void wxWindowMSW::Raise()
768 wxBringWindowToTop(GetHwnd());
771 // Lower the window to the bottom of the Z order
772 void wxWindowMSW::Lower()
774 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
775 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
778 void wxWindowMSW::DoCaptureMouse()
780 HWND hWnd
= GetHwnd();
787 void wxWindowMSW::DoReleaseMouse()
789 if ( !::ReleaseCapture() )
791 wxLogLastError(wxT("ReleaseCapture"));
795 /* static */ wxWindow
*wxWindowBase::GetCapture()
797 HWND hwnd
= ::GetCapture();
798 return hwnd
? wxFindWinFromHandle(hwnd
) : NULL
;
801 bool wxWindowMSW::SetFont(const wxFont
& font
)
803 if ( !wxWindowBase::SetFont(font
) )
809 HWND hWnd
= GetHwnd();
812 // note the use of GetFont() instead of m_font: our own font could have
813 // just been reset and in this case we need to change the font used by
814 // the native window to the default for this class, i.e. exactly what
816 WXHANDLE hFont
= GetFont().GetResourceHandle();
818 wxASSERT_MSG( hFont
, wxT("should have valid font") );
820 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
825 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
827 if ( !wxWindowBase::SetCursor(cursor
) )
833 // don't "overwrite" busy cursor
834 if ( m_cursor
.Ok() && !wxIsBusy() )
836 // normally we should change the cursor only if it's over this window
837 // but we should do it always if we capture the mouse currently
838 bool set
= HasCapture();
841 HWND hWnd
= GetHwnd();
845 ::GetCursorPosWinCE(&point
);
847 ::GetCursorPos(&point
);
850 RECT rect
= wxGetWindowRect(hWnd
);
852 set
= ::PtInRect(&rect
, point
) != 0;
857 ::SetCursor(GetHcursorOf(m_cursor
));
859 //else: will be set later when the mouse enters this window
865 void wxWindowMSW::WarpPointer(int x
, int y
)
867 ClientToScreen(&x
, &y
);
869 if ( !::SetCursorPos(x
, y
) )
871 wxLogLastError(wxT("SetCursorPos"));
875 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
877 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
878 // to use it on older systems -- and could possibly do some harm
879 static int s_needToUpdate
= -1;
880 if ( s_needToUpdate
== -1 )
883 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
887 if ( s_needToUpdate
)
889 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
890 // won't send WM_UPDATEUISTATE
891 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
895 // ---------------------------------------------------------------------------
897 // ---------------------------------------------------------------------------
902 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
904 #ifdef __WXMICROWIN__
905 return ::GetScrollPosWX(hWnd
, wOrient
);
907 WinStruct
<SCROLLINFO
> scrollInfo
;
908 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
909 scrollInfo
.fMask
= SIF_POS
;
910 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
912 return scrollInfo
.nPos
;
917 inline UINT
WXOrientToSB(int orient
)
919 return orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
;
922 } // anonymous namespace
924 int wxWindowMSW::GetScrollPos(int orient
) const
926 HWND hWnd
= GetHwnd();
927 wxCHECK_MSG( hWnd
, 0, wxT("no HWND in GetScrollPos") );
929 return GetScrollPosition(hWnd
, WXOrientToSB(orient
));
932 // This now returns the whole range, not just the number
933 // of positions that we can scroll.
934 int wxWindowMSW::GetScrollRange(int orient
) const
937 HWND hWnd
= GetHwnd();
940 WinStruct
<SCROLLINFO
> scrollInfo
;
941 scrollInfo
.fMask
= SIF_RANGE
;
942 if ( !::GetScrollInfo(hWnd
, WXOrientToSB(orient
), &scrollInfo
) )
944 // Most of the time this is not really an error, since the return
945 // value can also be zero when there is no scrollbar yet.
946 // wxLogLastError(wxT("GetScrollInfo"));
948 maxPos
= scrollInfo
.nMax
;
950 // undo "range - 1" done in SetScrollbar()
954 int wxWindowMSW::GetScrollThumb(int orient
) const
956 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
959 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
961 HWND hWnd
= GetHwnd();
962 wxCHECK_RET( hWnd
, wxT("SetScrollPos: no HWND") );
964 WinStruct
<SCROLLINFO
> info
;
968 info
.fMask
= SIF_POS
;
969 if ( HasFlag(wxALWAYS_SHOW_SB
) )
971 // disable scrollbar instead of removing it then
972 info
.fMask
|= SIF_DISABLENOSCROLL
;
975 ::SetScrollInfo(hWnd
, WXOrientToSB(orient
), &info
, refresh
);
978 // New function that will replace some of the above.
979 void wxWindowMSW::SetScrollbar(int orient
,
985 // We have to set the variables here to make them valid in events
986 // triggered by ::SetScrollInfo()
987 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
989 HWND hwnd
= GetHwnd();
993 WinStruct
<SCROLLINFO
> info
;
996 info
.nPage
= pageSize
;
997 info
.nMin
= 0; // range is nMax - nMin + 1
998 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
1001 // We normally also reenable scrollbar in case it had been previously
1002 // disabled by specifying SIF_DISABLENOSCROLL below but we should only
1003 // do this if it has valid range, otherwise it would be enabled but not
1005 if ( range
>= pageSize
)
1007 ::EnableScrollBar(hwnd
, WXOrientToSB(orient
), ESB_ENABLE_BOTH
);
1010 //else: leave all the fields to be 0
1012 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
1013 if ( HasFlag(wxALWAYS_SHOW_SB
) || range
== -1 )
1015 // disable scrollbar instead of removing it then
1016 info
.fMask
|= SIF_DISABLENOSCROLL
;
1019 ::SetScrollInfo(hwnd
, WXOrientToSB(orient
), &info
, refresh
);
1022 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
1028 wxCopyRectToRECT(*prect
, rect
);
1038 // FIXME: is this the exact equivalent of the line below?
1039 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
1041 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
1045 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
1047 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
1050 for ( int n
= 0; n
< count
; n
++ )
1052 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
1054 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
1055 if ( posNew
== pos
)
1057 // don't bother to continue, we're already at top/bottom
1064 return pos
!= posStart
;
1067 bool wxWindowMSW::ScrollLines(int lines
)
1069 bool down
= lines
> 0;
1071 return ScrollVertically(GetHwnd(),
1072 down
? SB_LINEDOWN
: SB_LINEUP
,
1073 down
? lines
: -lines
);
1076 bool wxWindowMSW::ScrollPages(int pages
)
1078 bool down
= pages
> 0;
1080 return ScrollVertically(GetHwnd(),
1081 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1082 down
? pages
: -pages
);
1085 // ----------------------------------------------------------------------------
1087 // ----------------------------------------------------------------------------
1089 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
1094 wxCHECK_RET( GetHwnd(),
1095 wxT("layout direction must be set after window creation") );
1097 LONG styleOld
= wxGetWindowExStyle(this);
1099 LONG styleNew
= styleOld
;
1102 case wxLayout_LeftToRight
:
1103 styleNew
&= ~WS_EX_LAYOUTRTL
;
1106 case wxLayout_RightToLeft
:
1107 styleNew
|= WS_EX_LAYOUTRTL
;
1111 wxFAIL_MSG(wxT("unsupported layout direction"));
1115 if ( styleNew
!= styleOld
)
1117 wxSetWindowExStyle(this, styleNew
);
1122 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1125 return wxLayout_Default
;
1127 wxCHECK_MSG( GetHwnd(), wxLayout_Default
, wxT("invalid window") );
1129 return wxHasWindowExStyle(this, WS_EX_LAYOUTRTL
) ? wxLayout_RightToLeft
1130 : wxLayout_LeftToRight
;
1135 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1136 wxCoord
WXUNUSED(width
),
1137 wxCoord
WXUNUSED(widthTotal
)) const
1139 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1140 // redo it ourselves
1144 // ---------------------------------------------------------------------------
1146 // ---------------------------------------------------------------------------
1148 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1150 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1152 HWND hwnd
= (HWND
)hWnd
;
1153 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1157 wxAssociateWinWithHandle(hwnd
, this);
1159 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1161 // we don't need to subclass the window of our own class (in the Windows
1162 // sense of the word)
1163 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1165 wxSetWindowProc(hwnd
, wxWndProc
);
1169 // don't bother restoring it either: this also makes it easy to
1170 // implement IsOfStandardClass() method which returns true for the
1171 // standard controls and false for the wxWidgets own windows as it can
1172 // simply check m_oldWndProc
1173 m_oldWndProc
= NULL
;
1176 // we're officially created now, send the event
1177 wxWindowCreateEvent
event((wxWindow
*)this);
1178 (void)HandleWindowEvent(event
);
1181 void wxWindowMSW::UnsubclassWin()
1183 wxRemoveHandleAssociation(this);
1185 // Restore old Window proc
1186 HWND hwnd
= GetHwnd();
1191 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1195 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1197 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1200 m_oldWndProc
= NULL
;
1205 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1209 if ( !::DestroyWindow(GetHwnd()) )
1211 wxLogLastError(wxT("DestroyWindow"));
1215 WXHWND wxhwnd
= (WXHWND
)handle
;
1217 // this also calls SetHWND(wxhwnd)
1218 SubclassWin(wxhwnd
);
1221 void wxWindowMSW::DissociateHandle()
1223 // this also calls SetHWND(0) for us
1228 bool wxCheckWindowWndProc(WXHWND hWnd
,
1229 WXFARPROC
WXUNUSED(wndProc
))
1231 const wxString
str(wxGetWindowClass(hWnd
));
1233 // TODO: get rid of wxTLWHiddenParent special case (currently it's not
1234 // registered by wxApp but using ad hoc code in msw/toplevel.cpp);
1235 // there is also a hidden window class used by sockets &c
1236 return wxApp::IsRegisteredClassName(str
) || str
== wxT("wxTLWHiddenParent");
1239 // ----------------------------------------------------------------------------
1241 // ----------------------------------------------------------------------------
1243 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1245 long flagsOld
= GetWindowStyleFlag();
1246 if ( flags
== flagsOld
)
1249 // update the internal variable
1250 wxWindowBase::SetWindowStyleFlag(flags
);
1252 // and the real window flags
1253 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1256 void wxWindowMSW::SetExtraStyle(long exflags
)
1258 long exflagsOld
= GetExtraStyle();
1259 if ( exflags
== exflagsOld
)
1262 // update the internal variable
1263 wxWindowBase::SetExtraStyle(exflags
);
1265 // and the real window flags
1266 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1269 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1271 // now update the Windows style as well if needed - and if the window had
1272 // been already created
1276 // we may need to call SetWindowPos() when we change some styles
1277 bool callSWP
= false;
1280 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1282 // this is quite a horrible hack but we need it because MSWGetStyle()
1283 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1284 // and so we have to modify the window exflags temporarily to get the
1285 // correct exstyleOld
1286 long exflagsNew
= GetExtraStyle();
1287 wxWindowBase::SetExtraStyle(exflagsOld
);
1290 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1292 wxWindowBase::SetExtraStyle(exflagsNew
);
1295 if ( style
!= styleOld
)
1297 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1298 // this function so instead of simply setting the style to the new
1299 // value we clear the bits which were set in styleOld but are set in
1300 // the new one and set the ones which were not set before
1301 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1302 styleReal
&= ~styleOld
;
1305 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1307 // we need to call SetWindowPos() if any of the styles affecting the
1308 // frame appearance have changed
1309 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1318 // and the extended style
1319 long exstyleReal
= wxGetWindowExStyle(this);
1321 if ( exstyle
!= exstyleOld
)
1323 exstyleReal
&= ~exstyleOld
;
1324 exstyleReal
|= exstyle
;
1326 wxSetWindowExStyle(this, exstyleReal
);
1328 // ex style changes don't take effect without calling SetWindowPos
1334 // we must call SetWindowPos() to flush the cached extended style and
1335 // also to make the change to wxSTAY_ON_TOP style take effect: just
1336 // setting the style simply doesn't work
1337 if ( !::SetWindowPos(GetHwnd(),
1338 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1341 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1344 wxLogLastError(wxT("SetWindowPos"));
1349 wxBorder
wxWindowMSW::GetDefaultBorderForControl() const
1351 return wxBORDER_THEME
;
1354 wxBorder
wxWindowMSW::GetDefaultBorder() const
1356 return wxWindowBase::GetDefaultBorder();
1359 // Translate wxBORDER_THEME (and other border styles if necessary) to the value
1360 // that makes most sense for this Windows environment
1361 wxBorder
wxWindowMSW::TranslateBorder(wxBorder border
) const
1363 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
1364 if (border
== wxBORDER_THEME
|| border
== wxBORDER_SUNKEN
|| border
== wxBORDER_SIMPLE
)
1365 return wxBORDER_SIMPLE
;
1367 return wxBORDER_NONE
;
1370 if (border
== wxBORDER_THEME
)
1372 if (CanApplyThemeBorder())
1374 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
1376 return wxBORDER_THEME
;
1378 return wxBORDER_SUNKEN
;
1386 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1388 // translate common wxWidgets styles to Windows ones
1390 // most of windows are child ones, those which are not (such as
1391 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1392 WXDWORD style
= WS_CHILD
;
1394 // using this flag results in very significant reduction in flicker,
1395 // especially with controls inside the static boxes (as the interior of the
1396 // box is not redrawn twice), but sometimes results in redraw problems, so
1397 // optionally allow the old code to continue to use it provided a special
1398 // system option is turned on
1399 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1400 || (flags
& wxCLIP_CHILDREN
) )
1401 style
|= WS_CLIPCHILDREN
;
1403 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1404 // don't support overlapping windows and it only makes sense for them and,
1405 // presumably, gives the system some extra work (to manage more clipping
1406 // regions), so avoid it alltogether
1409 if ( flags
& wxVSCROLL
)
1410 style
|= WS_VSCROLL
;
1412 if ( flags
& wxHSCROLL
)
1413 style
|= WS_HSCROLL
;
1415 const wxBorder border
= TranslateBorder(GetBorder(flags
));
1417 // After translation, border is now optimized for the specific version of Windows
1418 // and theme engine presence.
1420 // WS_BORDER is only required for wxBORDER_SIMPLE
1421 if ( border
== wxBORDER_SIMPLE
)
1424 // now deal with ext style if the caller wants it
1430 if ( flags
& wxTRANSPARENT_WINDOW
)
1431 *exstyle
|= WS_EX_TRANSPARENT
;
1437 case wxBORDER_DEFAULT
:
1438 wxFAIL_MSG( wxT("unknown border style") );
1442 case wxBORDER_SIMPLE
:
1443 case wxBORDER_THEME
:
1446 case wxBORDER_STATIC
:
1447 *exstyle
|= WS_EX_STATICEDGE
;
1450 case wxBORDER_RAISED
:
1451 *exstyle
|= WS_EX_DLGMODALFRAME
;
1454 case wxBORDER_SUNKEN
:
1455 *exstyle
|= WS_EX_CLIENTEDGE
;
1456 style
&= ~WS_BORDER
;
1459 // case wxBORDER_DOUBLE:
1460 // *exstyle |= WS_EX_DLGMODALFRAME;
1464 // wxUniv doesn't use Windows dialog navigation functions at all
1465 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1466 // to make the dialog navigation work with the nested panels we must
1467 // use this style (top level windows such as dialogs don't need it)
1468 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1470 *exstyle
|= WS_EX_CONTROLPARENT
;
1472 #endif // __WXUNIVERSAL__
1478 // Setup background and foreground colours correctly
1479 void wxWindowMSW::SetupColours()
1482 SetBackgroundColour(GetParent()->GetBackgroundColour());
1485 bool wxWindowMSW::IsMouseInWindow() const
1487 // get the mouse position
1490 ::GetCursorPosWinCE(&pt
);
1492 ::GetCursorPos(&pt
);
1495 // find the window which currently has the cursor and go up the window
1496 // chain until we find this window - or exhaust it
1497 HWND hwnd
= ::WindowFromPoint(pt
);
1498 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1499 hwnd
= ::GetParent(hwnd
);
1501 return hwnd
!= NULL
;
1504 void wxWindowMSW::OnInternalIdle()
1506 #ifndef HAVE_TRACKMOUSEEVENT
1507 // Check if we need to send a LEAVE event
1508 if ( m_mouseInWindow
)
1510 // note that we should generate the leave event whether the window has
1511 // or doesn't have mouse capture
1512 if ( !IsMouseInWindow() )
1514 GenerateMouseLeave();
1517 #endif // !HAVE_TRACKMOUSEEVENT
1519 wxWindowBase::OnInternalIdle();
1522 // Set this window to be the child of 'parent'.
1523 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1525 if ( !wxWindowBase::Reparent(parent
) )
1528 HWND hWndChild
= GetHwnd();
1529 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1531 ::SetParent(hWndChild
, hWndParent
);
1534 if ( wxHasWindowExStyle(this, WS_EX_CONTROLPARENT
) )
1536 EnsureParentHasControlParentStyle(GetParent());
1538 #endif // !__WXWINCE__
1543 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1545 #ifndef __WXMICROWIN__
1546 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1550 void wxWindowMSW::DoFreeze()
1553 return; // no point in freezing hidden window
1555 SendSetRedraw(GetHwnd(), false);
1558 void wxWindowMSW::DoThaw()
1561 return; // hidden windows aren't frozen by DoFreeze
1563 SendSetRedraw(GetHwnd(), true);
1565 // we need to refresh everything or otherwise the invalidated area
1566 // is not going to be repainted
1570 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1572 HWND hWnd
= GetHwnd();
1579 wxCopyRectToRECT(*rect
, mswRect
);
1587 // RedrawWindow not available on SmartPhone or eVC++ 3
1588 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1589 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1593 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1595 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1600 void wxWindowMSW::Update()
1602 if ( !::UpdateWindow(GetHwnd()) )
1604 wxLogLastError(wxT("UpdateWindow"));
1607 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1608 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1609 // handler needs to be really drawn right now
1614 // ---------------------------------------------------------------------------
1616 // ---------------------------------------------------------------------------
1618 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1622 // we need to lower the sibling static boxes so controls contained within can be
1624 static void AdjustStaticBoxZOrder(wxWindow
*parent
)
1626 // no sibling static boxes if we have no parent (ie TLW)
1630 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1632 node
= node
->GetNext() )
1634 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1637 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1638 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1643 #else // !wxUSE_STATBOX
1645 static inline void AdjustStaticBoxZOrder(wxWindow
* WXUNUSED(parent
))
1649 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1651 #endif // drag and drop is used
1653 #if wxUSE_DRAG_AND_DROP
1654 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1656 if ( m_dropTarget
!= 0 ) {
1657 m_dropTarget
->Revoke(m_hWnd
);
1658 delete m_dropTarget
;
1661 m_dropTarget
= pDropTarget
;
1662 if ( m_dropTarget
!= 0 )
1664 AdjustStaticBoxZOrder(GetParent());
1665 m_dropTarget
->Register(m_hWnd
);
1668 #endif // wxUSE_DRAG_AND_DROP
1670 // old-style file manager drag&drop support: we retain the old-style
1671 // DragAcceptFiles in parallel with SetDropTarget.
1672 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1675 HWND hWnd
= GetHwnd();
1678 AdjustStaticBoxZOrder(GetParent());
1679 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1684 // ----------------------------------------------------------------------------
1686 // ----------------------------------------------------------------------------
1690 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1692 wxWindowBase::DoSetToolTip(tooltip
);
1695 m_tooltip
->SetWindow((wxWindow
*)this);
1698 #endif // wxUSE_TOOLTIPS
1700 // ---------------------------------------------------------------------------
1701 // moving and resizing
1702 // ---------------------------------------------------------------------------
1704 bool wxWindowMSW::IsSizeDeferred() const
1706 #if wxUSE_DEFERRED_SIZING
1707 if ( m_pendingPosition
!= wxDefaultPosition
||
1708 m_pendingSize
!= wxDefaultSize
)
1710 #endif // wxUSE_DEFERRED_SIZING
1716 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1718 #if wxUSE_DEFERRED_SIZING
1719 // if SetSize() had been called at wx level but not realized at Windows
1720 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1721 // the new and not the old position to the other wx code
1722 if ( m_pendingSize
!= wxDefaultSize
)
1725 *x
= m_pendingSize
.x
;
1727 *y
= m_pendingSize
.y
;
1729 else // use current size
1730 #endif // wxUSE_DEFERRED_SIZING
1732 RECT rect
= wxGetWindowRect(GetHwnd());
1735 *x
= rect
.right
- rect
.left
;
1737 *y
= rect
.bottom
- rect
.top
;
1741 // Get size *available for subwindows* i.e. excluding menu bar etc.
1742 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1744 #if wxUSE_DEFERRED_SIZING
1745 if ( m_pendingSize
!= wxDefaultSize
)
1747 // we need to calculate the client size corresponding to pending size
1749 // FIXME: Unfortunately this doesn't work correctly for the maximized
1750 // top level windows, the returned values are too small (e.g.
1751 // under Windows 7 on a 1600*1200 screen with task bar on the
1752 // right the pending size for a maximized window is 1538*1200
1753 // and WM_NCCALCSIZE returns 1528*1172 even though the correct
1754 // client size of such window is 1538*1182). No idea how to fix
1755 // it though, setting WS_MAXIMIZE in GWL_STYLE before calling
1756 // WM_NCCALCSIZE doesn't help and AdjustWindowRectEx() doesn't
1757 // work in this direction neither. So we just have to live with
1758 // the slightly wrong results and relayout the window when it
1759 // gets finally shown in its maximized state (see #11762).
1761 rect
.left
= m_pendingPosition
.x
;
1762 rect
.top
= m_pendingPosition
.y
;
1763 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1764 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1766 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1769 *x
= rect
.right
- rect
.left
;
1771 *y
= rect
.bottom
- rect
.top
;
1774 #endif // wxUSE_DEFERRED_SIZING
1776 RECT rect
= wxGetClientRect(GetHwnd());
1785 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1787 wxWindow
* const parent
= GetParent();
1790 #if wxUSE_DEFERRED_SIZING
1791 if ( m_pendingPosition
!= wxDefaultPosition
)
1793 pos
= m_pendingPosition
;
1795 else // use current position
1796 #endif // wxUSE_DEFERRED_SIZING
1798 RECT rect
= wxGetWindowRect(GetHwnd());
1801 point
.x
= rect
.left
;
1804 // we do the adjustments with respect to the parent only for the "real"
1805 // children, not for the dialogs/frames
1806 if ( !IsTopLevel() )
1808 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
1810 // In RTL mode, we want the logical left x-coordinate,
1811 // which would be the physical right x-coordinate.
1812 point
.x
= rect
.right
;
1815 // Since we now have the absolute screen coords, if there's a
1816 // parent we must subtract its top left corner
1819 ::ScreenToClient(GetHwndOf(parent
), &point
);
1827 // we also must adjust by the client area offset: a control which is just
1828 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1829 if ( parent
&& !IsTopLevel() )
1831 const wxPoint
pt(parent
->GetClientAreaOrigin());
1842 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1850 ::ScreenToClient(GetHwnd(), &pt
);
1858 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1866 ::ClientToScreen(GetHwnd(), &pt
);
1875 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1877 #if wxUSE_DEFERRED_SIZING
1878 // if our parent had prepared a defer window handle for us, use it (unless
1879 // we are a top level window)
1880 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1882 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1885 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1886 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1889 wxLogLastError(wxT("DeferWindowPos"));
1895 // hdwp must be updated as it may have been changed
1896 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1901 // did deferred move, remember new coordinates of the window as they're
1902 // different from what Windows would return for it
1906 // otherwise (or if deferring failed) move the window in place immediately
1907 #endif // wxUSE_DEFERRED_SIZING
1908 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
1910 wxLogLastError(wxT("MoveWindow"));
1913 // if wxUSE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1914 // ignored otherwise
1918 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1920 // TODO: is this consistent with other platforms?
1921 // Still, negative width or height shouldn't be allowed
1927 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
1929 #if wxUSE_DEFERRED_SIZING
1930 m_pendingPosition
= wxPoint(x
, y
);
1931 m_pendingSize
= wxSize(width
, height
);
1933 else // window was moved immediately, without deferring it
1935 m_pendingPosition
= wxDefaultPosition
;
1936 m_pendingSize
= wxDefaultSize
;
1937 #endif // wxUSE_DEFERRED_SIZING
1941 // set the size of the window: if the dimensions are positive, just use them,
1942 // but if any of them is equal to -1, it means that we must find the value for
1943 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1944 // which case -1 is a valid value for x and y)
1946 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1947 // the width/height to best suit our contents, otherwise we reuse the current
1949 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1951 // get the current size and position...
1952 int currentX
, currentY
;
1953 int currentW
, currentH
;
1955 GetPosition(¤tX
, ¤tY
);
1956 GetSize(¤tW
, ¤tH
);
1958 // ... and don't do anything (avoiding flicker) if it's already ok unless
1959 // we're forced to resize the window
1960 if ( x
== currentX
&& y
== currentY
&&
1961 width
== currentW
&& height
== currentH
&&
1962 !(sizeFlags
& wxSIZE_FORCE
) )
1964 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
1966 wxSizeEvent
event( wxSize(width
,height
), GetId() );
1967 event
.SetEventObject( this );
1968 HandleWindowEvent( event
);
1973 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1975 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1978 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1980 wxSize size
= wxDefaultSize
;
1981 if ( width
== wxDefaultCoord
)
1983 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1985 size
= GetBestSize();
1990 // just take the current one
1995 if ( height
== wxDefaultCoord
)
1997 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1999 if ( size
.x
== wxDefaultCoord
)
2001 size
= GetBestSize();
2003 //else: already called GetBestSize() above
2009 // just take the current one
2014 DoMoveWindow(x
, y
, width
, height
);
2017 void wxWindowMSW::DoSetClientSize(int width
, int height
)
2019 // setting the client size is less obvious than it could have been
2020 // because in the result of changing the total size the window scrollbar
2021 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
2022 // doesn't take neither into account) and so the client size will not be
2023 // correct as the difference between the total and client size changes --
2024 // so we keep changing it until we get it right
2026 // normally this loop shouldn't take more than 3 iterations (usually 1 but
2027 // if scrollbars [dis]appear as the result of the first call, then 2 and it
2028 // may become 3 if the window had 0 size originally and so we didn't
2029 // calculate the scrollbar correction correctly during the first iteration)
2030 // but just to be on the safe side we check for it instead of making it an
2031 // "infinite" loop (i.e. leaving break inside as the only way to get out)
2032 for ( int i
= 0; i
< 4; i
++ )
2035 ::GetClientRect(GetHwnd(), &rectClient
);
2037 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
2038 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
2039 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
2044 // Find the difference between the entire window (title bar and all)
2045 // and the client area; add this to the new client size to move the
2048 ::GetWindowRect(GetHwnd(), &rectWin
);
2050 const int widthWin
= rectWin
.right
- rectWin
.left
,
2051 heightWin
= rectWin
.bottom
- rectWin
.top
;
2053 // MoveWindow positions the child windows relative to the parent, so
2054 // adjust if necessary
2055 if ( !IsTopLevel() )
2057 wxWindow
*parent
= GetParent();
2060 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
2064 // don't call DoMoveWindow() because we want to move window immediately
2065 // and not defer it here as otherwise the value returned by
2066 // GetClient/WindowRect() wouldn't change as the window wouldn't be
2068 if ( !::MoveWindow(GetHwnd(),
2071 width
+ widthWin
- rectClient
.right
,
2072 height
+ heightWin
- rectClient
.bottom
,
2075 wxLogLastError(wxT("MoveWindow"));
2080 wxSize
wxWindowMSW::DoGetBorderSize() const
2083 switch ( GetBorder() )
2085 case wxBORDER_STATIC
:
2086 case wxBORDER_SIMPLE
:
2090 case wxBORDER_SUNKEN
:
2094 case wxBORDER_RAISED
:
2095 case wxBORDER_DOUBLE
:
2100 wxFAIL_MSG( wxT("unknown border style") );
2107 return 2*wxSize(border
, border
);
2110 // ---------------------------------------------------------------------------
2112 // ---------------------------------------------------------------------------
2114 int wxWindowMSW::GetCharHeight() const
2116 return wxGetTextMetrics(this).tmHeight
;
2119 int wxWindowMSW::GetCharWidth() const
2121 // +1 is needed because Windows apparently adds it when calculating the
2122 // dialog units size in pixels
2123 #if wxDIALOG_UNIT_COMPATIBILITY
2124 return wxGetTextMetrics(this).tmAveCharWidth
;
2126 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
2130 void wxWindowMSW::DoGetTextExtent(const wxString
& string
,
2133 int *externalLeading
,
2134 const wxFont
*fontToUse
) const
2136 wxASSERT_MSG( !fontToUse
|| fontToUse
->Ok(),
2137 wxT("invalid font in GetTextExtent()") );
2141 hfontToUse
= GetHfontOf(*fontToUse
);
2143 hfontToUse
= GetHfontOf(GetFont());
2145 WindowHDC
hdc(GetHwnd());
2146 SelectInHDC
selectFont(hdc
, hfontToUse
);
2150 ::GetTextExtentPoint32(hdc
, string
.wx_str(), string
.length(), &sizeRect
);
2151 GetTextMetrics(hdc
, &tm
);
2158 *descent
= tm
.tmDescent
;
2159 if ( externalLeading
)
2160 *externalLeading
= tm
.tmExternalLeading
;
2163 // ---------------------------------------------------------------------------
2165 // ---------------------------------------------------------------------------
2167 #if wxUSE_MENUS_NATIVE
2169 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2170 // immediately, without waiting for the next event loop iteration
2172 // NB: this function should probably be made public later as it can almost
2173 // surely replace wxYield() elsewhere as well
2174 static void wxYieldForCommandsOnly()
2176 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2177 // want to process it here)
2179 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2181 if ( msg
.message
== WM_QUIT
)
2183 // if we retrieved a WM_QUIT, insert back into the message queue.
2184 ::PostQuitMessage(0);
2188 // luckily (as we don't have access to wxEventLoopImpl method from here
2189 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2191 ::TranslateMessage(&msg
);
2192 ::DispatchMessage(&msg
);
2196 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2200 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2202 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2203 x
= mouse
.x
; y
= mouse
.y
;
2206 HWND hWnd
= GetHwnd();
2207 HMENU hMenu
= GetHmenuOf(menu
);
2211 ::ClientToScreen(hWnd
, &point
);
2212 #if defined(__WXWINCE__)
2213 static const UINT flags
= 0;
2214 #else // !__WXWINCE__
2215 UINT flags
= TPM_RIGHTBUTTON
;
2216 // NT4 doesn't support TPM_RECURSE and simply doesn't show the menu at all
2217 // when it's use, I'm not sure about Win95/98 but prefer to err on the safe
2218 // side and not to use it there neither -- modify the test if it does work
2220 if ( wxGetWinVersion() >= wxWinVersion_5
)
2222 // using TPM_RECURSE allows us to show a popup menu while another menu
2223 // is opened which can be useful and is supported by the other
2224 // platforms, so allow it under Windows too
2225 flags
|= TPM_RECURSE
;
2227 #endif // __WXWINCE__/!__WXWINCE__
2229 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2231 // we need to do it right now as otherwise the events are never going to be
2232 // sent to wxCurrentPopupMenu from HandleCommand()
2234 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2235 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2236 // destroyed as soon as we return (it can be a local variable in the caller
2237 // for example) and so we do need to process the event immediately
2238 wxYieldForCommandsOnly();
2243 #endif // wxUSE_MENUS_NATIVE
2245 // ===========================================================================
2246 // pre/post message processing
2247 // ===========================================================================
2249 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2252 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2254 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2257 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2259 // wxUniversal implements tab traversal itself
2260 #ifndef __WXUNIVERSAL__
2261 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2263 // intercept dialog navigation keys
2264 MSG
*msg
= (MSG
*)pMsg
;
2266 // here we try to do all the job which ::IsDialogMessage() usually does
2268 if ( msg
->message
== WM_KEYDOWN
)
2270 bool bCtrlDown
= wxIsCtrlDown();
2271 bool bShiftDown
= wxIsShiftDown();
2273 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2274 // don't process it if it's the case (except for Ctrl-Tab/Enter
2275 // combinations which are always processed)
2276 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2278 // surprisingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2279 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2280 // it, of course, implies them
2281 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2283 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2286 bool bForward
= true,
2287 bWindowChange
= false,
2290 // should we process this message specially?
2291 bool bProcess
= true;
2292 switch ( msg
->wParam
)
2295 if ( (lDlgCode
& DLGC_WANTTAB
) && !bCtrlDown
)
2297 // let the control have the TAB
2300 else // use it for navigation
2302 // Ctrl-Tab cycles thru notebook pages
2303 bWindowChange
= bCtrlDown
;
2304 bForward
= !bShiftDown
;
2311 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2319 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2328 // we treat PageUp/Dn as arrows because chances are that
2329 // a control which needs arrows also needs them for
2330 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2331 if ( (lDlgCode
& DLGC_WANTARROWS
) && !bCtrlDown
)
2333 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
2334 bWindowChange
= true;
2340 // currently active button should get enter press even
2341 // if there is a default button elsewhere so check if
2342 // this window is a button first
2343 wxWindow
*btn
= NULL
;
2344 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2346 // let IsDialogMessage() handle this for all
2347 // buttons except the owner-drawn ones which it
2348 // just seems to ignore
2349 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2350 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2352 // emulate the button click
2353 btn
= wxFindWinFromHandle(msg
->hwnd
);
2358 else // not a button itself, do we have default button?
2360 // check if this window or any of its ancestors
2361 // wants the message for itself (we always reserve
2362 // Ctrl-Enter for dialog navigation though)
2363 wxWindow
*win
= this;
2366 // this will contain the dialog code of this
2367 // window and all of its parent windows in turn
2368 LONG lDlgCode2
= lDlgCode
;
2372 if ( lDlgCode2
& DLGC_WANTMESSAGE
)
2374 // as it wants to process Enter itself,
2375 // don't call IsDialogMessage() which
2380 // don't propagate keyboard messages beyond
2381 // the first top level window parent
2382 if ( win
->IsTopLevel() )
2385 win
= win
->GetParent();
2387 lDlgCode2
= ::SendMessage
2398 win
= wxGetTopLevelParent(win
);
2401 wxTopLevelWindow
* const
2402 tlw
= wxDynamicCast(win
, wxTopLevelWindow
);
2405 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2410 if ( btn
&& btn
->IsEnabled() )
2412 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2416 #endif // wxUSE_BUTTON
2419 // map Enter presses into button presses on PDAs
2420 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2421 event
.SetEventObject(this);
2422 if ( HandleWindowEvent(event
) )
2424 #endif // __WXWINCE__
2434 wxNavigationKeyEvent event
;
2435 event
.SetDirection(bForward
);
2436 event
.SetWindowChange(bWindowChange
);
2437 event
.SetFromTab(bFromTab
);
2438 event
.SetEventObject(this);
2440 if ( HandleWindowEvent(event
) )
2442 // as we don't call IsDialogMessage(), which would take of
2443 // this by default, we need to manually send this message
2444 // so that controls can change their UI state if needed
2445 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2452 if ( ::IsDialogMessage(GetHwnd(), msg
) )
2454 // IsDialogMessage() did something...
2458 #endif // __WXUNIVERSAL__
2463 // relay mouse move events to the tooltip control
2464 MSG
*msg
= (MSG
*)pMsg
;
2465 if ( msg
->message
== WM_MOUSEMOVE
)
2466 wxToolTip::RelayEvent(pMsg
);
2468 #endif // wxUSE_TOOLTIPS
2473 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2475 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2476 return m_acceleratorTable
.Translate(this, pMsg
);
2480 #endif // wxUSE_ACCEL
2483 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* msg
)
2485 // all tests below have to deal with various bugs/misfeatures of
2486 // IsDialogMessage(): we have to prevent it from being called from our
2487 // MSWProcessMessage() in some situations
2489 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2490 // message even when there is no cancel button and when the message is
2491 // needed by the control itself: in particular, it prevents the tree in
2492 // place edit control from being closed with Escape in a dialog
2493 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_ESCAPE
)
2498 // ::IsDialogMessage() is broken and may sometimes hang the application by
2499 // going into an infinite loop when it tries to find the control to give
2500 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2501 // situations when this may happen and not call it then
2502 if ( msg
->message
!= WM_SYSCHAR
)
2505 // assume we can call it by default
2506 bool canSafelyCallIsDlgMsg
= true;
2508 HWND hwndFocus
= ::GetFocus();
2510 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2511 // ::IsDialogMessage() will also enter an infinite loop, because it will
2512 // recursively check the child windows but not the window itself and so if
2513 // none of the children accepts focus it loops forever (as it only stops
2514 // when it gets back to the window it started from)
2516 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2517 // style has the focus, it can happen. One such possibility is if
2518 // all windows are either toplevel, wxDialog, wxPanel or static
2519 // controls and no window can actually accept keyboard input.
2520 #if !defined(__WXWINCE__)
2521 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2523 // pessimistic by default
2524 canSafelyCallIsDlgMsg
= false;
2525 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2527 node
= node
->GetNext() )
2529 wxWindow
* const win
= node
->GetData();
2530 if ( win
->CanAcceptFocus() &&
2531 !wxHasWindowExStyle(win
, WS_EX_CONTROLPARENT
) )
2533 // it shouldn't hang...
2534 canSafelyCallIsDlgMsg
= true;
2540 #endif // !__WXWINCE__
2542 if ( canSafelyCallIsDlgMsg
)
2544 // ::IsDialogMessage() can enter in an infinite loop when the
2545 // currently focused window is disabled or hidden and its
2546 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2550 if ( !::IsWindowEnabled(hwndFocus
) ||
2551 !::IsWindowVisible(hwndFocus
) )
2553 // it would enter an infinite loop if we do this!
2554 canSafelyCallIsDlgMsg
= false;
2559 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2561 // it's a top level window, don't go further -- e.g. even
2562 // if the parent of a dialog is disabled, this doesn't
2563 // break navigation inside the dialog
2567 hwndFocus
= ::GetParent(hwndFocus
);
2571 return canSafelyCallIsDlgMsg
;
2574 // ---------------------------------------------------------------------------
2575 // message params unpackers
2576 // ---------------------------------------------------------------------------
2578 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2579 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2581 *id
= LOWORD(wParam
);
2582 *hwnd
= (WXHWND
)lParam
;
2583 *cmd
= HIWORD(wParam
);
2586 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2587 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2589 *state
= LOWORD(wParam
);
2590 *minimized
= HIWORD(wParam
);
2591 *hwnd
= (WXHWND
)lParam
;
2594 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2595 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2597 *code
= LOWORD(wParam
);
2598 *pos
= HIWORD(wParam
);
2599 *hwnd
= (WXHWND
)lParam
;
2602 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2603 WXHDC
*hdc
, WXHWND
*hwnd
)
2605 *hwnd
= (WXHWND
)lParam
;
2606 *hdc
= (WXHDC
)wParam
;
2609 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2610 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2612 *item
= (WXWORD
)wParam
;
2613 *flags
= HIWORD(wParam
);
2614 *hmenu
= (WXHMENU
)lParam
;
2617 // ---------------------------------------------------------------------------
2618 // Main wxWidgets window proc and the window proc for wxWindow
2619 // ---------------------------------------------------------------------------
2621 // Hook for new window just as it's being created, when the window isn't yet
2622 // associated with the handle
2623 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2625 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2626 // window being created and insures that it's always unset back later
2627 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2629 gs_winBeingCreated
= winBeingCreated
;
2632 wxWindowCreationHook::~wxWindowCreationHook()
2634 gs_winBeingCreated
= NULL
;
2638 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2640 // trace all messages: useful for the debugging but noticeably slows down
2641 // the code so don't do it by default
2642 #if wxDEBUG_LEVEL >= 2
2643 // notice that we cast wParam and lParam to long to avoid mismatch with
2644 // format specifiers in 64 bit builds where they are both int64 quantities
2646 // casting like this loses information, of course, but it shouldn't matter
2647 // much for this diagnostic code and it keeps the code simple
2648 wxLogTrace("winmsg",
2649 wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"),
2650 wxGetMessageName(message
), hWnd
, (long)wParam
, (long)lParam
);
2651 #endif // wxDEBUG_LEVEL >= 2
2653 wxWindowMSW
*wnd
= wxFindWinFromHandle(hWnd
);
2655 // when we get the first message for the HWND we just created, we associate
2656 // it with wxWindow stored in gs_winBeingCreated
2657 if ( !wnd
&& gs_winBeingCreated
)
2659 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2660 wnd
= gs_winBeingCreated
;
2661 gs_winBeingCreated
= NULL
;
2662 wnd
->SetHWND((WXHWND
)hWnd
);
2667 if ( wnd
&& wxGUIEventLoop::AllowProcessing(wnd
) )
2668 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2670 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2675 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2677 // did we process the message?
2678 bool processed
= false;
2688 // for most messages we should return 0 when we do process the message
2696 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2699 // return 0 to allow window creation
2700 rc
.result
= mayCreate
? 0 : -1;
2706 // never set processed to true and *always* pass WM_DESTROY to
2707 // DefWindowProc() as Windows may do some internal cleanup when
2708 // processing it and failing to pass the message along may cause
2709 // memory and resource leaks!
2710 (void)HandleDestroy();
2714 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2718 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2721 #if !defined(__WXWINCE__)
2724 LPRECT pRect
= (LPRECT
)lParam
;
2726 rc
.SetLeft(pRect
->left
);
2727 rc
.SetTop(pRect
->top
);
2728 rc
.SetRight(pRect
->right
);
2729 rc
.SetBottom(pRect
->bottom
);
2730 processed
= HandleMoving(rc
);
2732 pRect
->left
= rc
.GetLeft();
2733 pRect
->top
= rc
.GetTop();
2734 pRect
->right
= rc
.GetRight();
2735 pRect
->bottom
= rc
.GetBottom();
2740 case WM_ENTERSIZEMOVE
:
2742 processed
= HandleEnterSizeMove();
2746 case WM_EXITSIZEMOVE
:
2748 processed
= HandleExitSizeMove();
2754 LPRECT pRect
= (LPRECT
)lParam
;
2756 rc
.SetLeft(pRect
->left
);
2757 rc
.SetTop(pRect
->top
);
2758 rc
.SetRight(pRect
->right
);
2759 rc
.SetBottom(pRect
->bottom
);
2760 processed
= HandleSizing(rc
);
2762 pRect
->left
= rc
.GetLeft();
2763 pRect
->top
= rc
.GetTop();
2764 pRect
->right
= rc
.GetRight();
2765 pRect
->bottom
= rc
.GetBottom();
2769 #endif // !__WXWINCE__
2771 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2772 case WM_ACTIVATEAPP
:
2773 // This implicitly sends a wxEVT_ACTIVATE_APP event
2774 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2780 WXWORD state
, minimized
;
2782 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2784 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2789 processed
= HandleSetFocus((WXHWND
)wParam
);
2793 processed
= HandleKillFocus((WXHWND
)wParam
);
2796 case WM_PRINTCLIENT
:
2797 processed
= HandlePrintClient((WXHDC
)wParam
);
2803 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2805 processed
= HandlePaint();
2809 processed
= HandlePaint();
2814 #ifdef __WXUNIVERSAL__
2815 // Universal uses its own wxFrame/wxDialog, so we don't receive
2816 // close events unless we have this.
2818 #endif // __WXUNIVERSAL__
2820 // don't let the DefWindowProc() destroy our window - we'll do it
2821 // ourselves in ~wxWindow
2827 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2831 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2832 GET_Y_LPARAM(lParam
),
2836 #ifdef HAVE_TRACKMOUSEEVENT
2838 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2840 if ( m_mouseInWindow
)
2842 GenerateMouseLeave();
2845 // always pass processed back as false, this allows the window
2846 // manager to process the message too. This is needed to
2847 // ensure windows XP themes work properly as the mouse moves
2848 // over widgets like buttons. So don't set processed to true here.
2850 #endif // HAVE_TRACKMOUSEEVENT
2852 #if wxUSE_MOUSEWHEEL
2854 processed
= HandleMouseWheel(wParam
, lParam
);
2858 case WM_LBUTTONDOWN
:
2860 case WM_LBUTTONDBLCLK
:
2861 case WM_RBUTTONDOWN
:
2863 case WM_RBUTTONDBLCLK
:
2864 case WM_MBUTTONDOWN
:
2866 case WM_MBUTTONDBLCLK
:
2867 #ifdef wxHAS_XBUTTON
2868 case WM_XBUTTONDOWN
:
2870 case WM_XBUTTONDBLCLK
:
2871 #endif // wxHAS_XBUTTON
2873 #ifdef __WXMICROWIN__
2874 // MicroWindows seems to ignore the fact that a window is
2875 // disabled. So catch mouse events and throw them away if
2877 wxWindowMSW
* win
= this;
2880 if (!win
->IsEnabled())
2886 win
= win
->GetParent();
2887 if ( !win
|| win
->IsTopLevel() )
2894 #endif // __WXMICROWIN__
2895 int x
= GET_X_LPARAM(lParam
),
2896 y
= GET_Y_LPARAM(lParam
);
2899 // redirect the event to a static control if necessary by
2900 // finding one under mouse because under CE the static controls
2901 // don't generate mouse events (even with SS_NOTIFY)
2903 if ( GetCapture() == this )
2905 // but don't do it if the mouse is captured by this window
2906 // because then it should really get this event itself
2911 win
= FindWindowForMouseEvent(this, &x
, &y
);
2913 // this should never happen
2914 wxCHECK_MSG( win
, 0,
2915 wxT("FindWindowForMouseEvent() returned NULL") );
2918 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
2920 SHRGINFO shrgi
= {0};
2922 shrgi
.cbSize
= sizeof(SHRGINFO
);
2923 shrgi
.hwndClient
= (HWND
) GetHWND();
2927 shrgi
.dwFlags
= SHRG_RETURNCMD
;
2928 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
2930 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
2933 pt
= ClientToScreen(pt
);
2935 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2937 evtCtx
.SetEventObject(this);
2938 if (HandleWindowEvent(evtCtx
))
2947 #else // !__WXWINCE__
2948 wxWindowMSW
*win
= this;
2949 #endif // __WXWINCE__/!__WXWINCE__
2951 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2953 // if the app didn't eat the event, handle it in the default
2954 // way, that is by giving this window the focus
2957 // for the standard classes their WndProc sets the focus to
2958 // them anyhow and doing it from here results in some weird
2959 // problems, so don't do it for them (unnecessary anyhow)
2960 if ( !win
->IsOfStandardClass() )
2962 if ( message
== WM_LBUTTONDOWN
&& win
->IsFocusable() )
2974 case MM_JOY1BUTTONDOWN
:
2975 case MM_JOY2BUTTONDOWN
:
2976 case MM_JOY1BUTTONUP
:
2977 case MM_JOY2BUTTONUP
:
2978 processed
= HandleJoystickEvent(message
,
2979 GET_X_LPARAM(lParam
),
2980 GET_Y_LPARAM(lParam
),
2983 #endif // __WXMICROWIN__
2989 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2991 processed
= HandleCommand(id
, cmd
, hwnd
);
2996 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2999 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
3000 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
3001 // apparently doesn't always behave properly and needs some help
3002 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
3003 case WM_NOTIFYFORMAT
:
3004 if ( lParam
== NF_QUERY
)
3007 rc
.result
= NFR_UNICODE
;
3010 #endif // wxUSE_UNICODE_MSLU
3012 // for these messages we must return true if process the message
3015 processed
= MSWOnDrawItem(wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
3020 case WM_MEASUREITEM
:
3021 processed
= MSWOnMeasureItem(wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
3025 #endif // defined(WM_DRAWITEM)
3028 if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS
) )
3030 // we always want to get the char events
3031 rc
.result
= DLGC_WANTCHARS
;
3033 if ( HasFlag(wxWANTS_CHARS
) )
3035 // in fact, we want everything
3036 rc
.result
|= DLGC_WANTARROWS
|
3043 //else: get the dlg code from the DefWindowProc()
3048 // Generate the key down event in any case.
3049 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
3050 if ( m_lastKeydownProcessed
)
3052 // If it was processed by an event handler, we stop here,
3053 // notably we intentionally don't generate char event then.
3056 else // key down event not handled
3058 // Examine the event to decide whether we need to generate a
3059 // char event for it ourselves or let Windows do it. Window
3060 // mostly only does it for the keys which produce printable
3061 // characters (although there are exceptions, e.g. VK_ESCAPE or
3062 // VK_BACK (but not VK_DELETE)) while we do it for all keys
3063 // except the modifier ones (the wisdom of this is debatable
3064 // but by now this decision is enshrined forever due to
3065 // backwards compatibility).
3068 // No wxEVT_CHAR events are generated for these keys at all.
3076 // Windows will send us WM_CHAR for these ones so we'll
3077 // generate wxEVT_CHAR for them later when we get it.
3112 // special case of VK_APPS: treat it the same as right mouse
3113 // click because both usually pop up a context menu
3115 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
3120 if ( (wParam
>= '0' && wParam
<= '9') ||
3121 (wParam
>= 'A' && wParam
<= 'Z') )
3123 // We'll get WM_CHAR for those later too.
3127 // But for the rest we won't get WM_CHAR later so we do
3128 // need to generate the event right now.
3129 wxKeyEvent
event(wxEVT_CHAR
);
3130 InitAnyKeyEvent(event
, wParam
, lParam
);
3132 // Set the "extended" bit in lParam because we want to
3133 // generate CHAR events with WXK_HOME and not
3134 // WXK_NUMPAD_HOME even if the "Home" key on numpad was
3136 event
.m_keyCode
= wxMSWKeyboard::VKToWX
3139 lParam
| (KF_EXTENDED
<< 16)
3142 // Don't produce events without any valid character
3143 // code (even if this shouldn't normally happen...).
3144 if ( event
.m_keyCode
!= WXK_NONE
)
3145 processed
= HandleWindowEvent(event
);
3148 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
3155 // special case of VK_APPS: treat it the same as right mouse button
3156 if ( wParam
== VK_APPS
)
3158 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
3163 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
3168 case WM_CHAR
: // Always an ASCII character
3169 if ( m_lastKeydownProcessed
)
3171 // The key was handled in the EVT_KEY_DOWN and handling
3172 // a key in an EVT_KEY_DOWN handler is meant, by
3173 // design, to prevent EVT_CHARs from happening
3174 m_lastKeydownProcessed
= false;
3179 processed
= HandleChar((WORD
)wParam
, lParam
);
3183 case WM_IME_STARTCOMPOSITION
:
3184 // IME popup needs Escape as it should undo the changes in its
3185 // entry window instead of e.g. closing the dialog for which the
3186 // IME is used (and losing all the changes in the IME window).
3187 gs_modalEntryWindowCount
++;
3190 case WM_IME_ENDCOMPOSITION
:
3191 gs_modalEntryWindowCount
--;
3196 processed
= HandleHotKey((WORD
)wParam
, lParam
);
3198 #endif // wxUSE_HOTKEY
3203 processed
= HandleClipboardEvent(message
);
3211 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
3213 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
3219 // CTLCOLOR messages are sent by children to query the parent for their
3221 #ifndef __WXMICROWIN__
3222 case WM_CTLCOLORMSGBOX
:
3223 case WM_CTLCOLOREDIT
:
3224 case WM_CTLCOLORLISTBOX
:
3225 case WM_CTLCOLORBTN
:
3226 case WM_CTLCOLORDLG
:
3227 case WM_CTLCOLORSCROLLBAR
:
3228 case WM_CTLCOLORSTATIC
:
3232 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
3234 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
3237 #endif // !__WXMICROWIN__
3239 case WM_SYSCOLORCHANGE
:
3240 // the return value for this message is ignored
3241 processed
= HandleSysColorChange();
3244 #if !defined(__WXWINCE__)
3245 case WM_DISPLAYCHANGE
:
3246 processed
= HandleDisplayChange();
3250 case WM_PALETTECHANGED
:
3251 processed
= HandlePaletteChanged((WXHWND
)wParam
);
3254 case WM_CAPTURECHANGED
:
3255 processed
= HandleCaptureChanged((WXHWND
)lParam
);
3258 case WM_SETTINGCHANGE
:
3259 processed
= HandleSettingChange(wParam
, lParam
);
3262 case WM_QUERYNEWPALETTE
:
3263 processed
= HandleQueryNewPalette();
3268 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
3269 // check if an override was configured for this window
3270 EraseBgHooks::const_iterator it
= gs_eraseBgHooks
.find(this);
3271 if ( it
!= gs_eraseBgHooks
.end() )
3272 processed
= it
->second
->MSWEraseBgHook((WXHDC
)wParam
);
3274 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
3275 processed
= HandleEraseBkgnd((WXHDC
)wParam
);
3280 // we processed the message, i.e. erased the background
3285 #if !defined(__WXWINCE__)
3287 processed
= HandleDropFiles(wParam
);
3292 processed
= HandleInitDialog((WXHWND
)wParam
);
3296 // we never set focus from here
3301 #if !defined(__WXWINCE__)
3302 case WM_QUERYENDSESSION
:
3303 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3307 processed
= HandleEndSession(wParam
!= 0, lParam
);
3310 case WM_GETMINMAXINFO
:
3311 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3316 processed
= HandleSetCursor((WXHWND
)wParam
,
3317 LOWORD(lParam
), // hit test
3318 HIWORD(lParam
)); // mouse msg
3322 // returning TRUE stops the DefWindowProc() from further
3323 // processing this message - exactly what we need because we've
3324 // just set the cursor.
3329 #if wxUSE_ACCESSIBILITY
3332 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3333 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3335 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3337 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3343 #if defined(WM_HELP)
3346 // by default, WM_HELP is propagated by DefWindowProc() upwards
3347 // to the window parent but as we do it ourselves already
3348 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3349 // to get the other events if we process this message at all
3352 // WM_HELP doesn't use lParam under CE
3354 HELPINFO
* info
= (HELPINFO
*) lParam
;
3355 if ( info
->iContextType
== HELPINFO_WINDOW
)
3357 #endif // !__WXWINCE__
3358 wxHelpEvent helpEvent
3363 wxGetMousePosition() // what else?
3365 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3369 helpEvent
.SetEventObject(this);
3370 HandleWindowEvent(helpEvent
);
3373 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3375 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3376 helpEvent
.SetEventObject(this);
3377 HandleWindowEvent(helpEvent
);
3380 else // unknown help event?
3384 #endif // !__WXWINCE__
3389 #if !defined(__WXWINCE__)
3390 case WM_CONTEXTMENU
:
3392 // we don't convert from screen to client coordinates as
3393 // the event may be handled by a parent window
3394 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3396 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3398 // we could have got an event from our child, reflect it back
3399 // to it if this is the case
3400 wxWindowMSW
*win
= NULL
;
3401 WXHWND hWnd
= (WXHWND
)wParam
;
3402 if ( hWnd
!= m_hWnd
)
3404 win
= FindItemByHWND(hWnd
);
3410 evtCtx
.SetEventObject(win
);
3411 processed
= win
->HandleWindowEvent(evtCtx
);
3418 // we're only interested in our own menus, not MF_SYSMENU
3419 if ( HIWORD(wParam
) == MF_POPUP
)
3421 // handle menu chars for ownerdrawn menu items
3422 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3423 if ( i
!= wxNOT_FOUND
)
3425 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3430 #endif // wxUSE_MENUS
3433 case WM_POWERBROADCAST
:
3436 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3437 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3440 #endif // __WXWINCE__
3443 // If we want the default themed border then we need to draw it ourselves
3446 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3447 const wxBorder border
= TranslateBorder(GetBorder());
3448 if (theme
&& border
== wxBORDER_THEME
)
3450 // first ask the widget to calculate the border size
3451 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3454 // now alter the client size making room for drawing a
3457 NCCALCSIZE_PARAMS
*csparam
= NULL
;
3460 csparam
= (NCCALCSIZE_PARAMS
*)lParam
;
3461 rect
= &csparam
->rgrc
[0];
3465 rect
= (RECT
*)lParam
;
3468 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3469 RECT rcClient
= { 0, 0, 0, 0 };
3470 wxClientDC
dc((wxWindow
*)this);
3471 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3473 if ( theme
->GetThemeBackgroundContentRect
3480 &rcClient
) == S_OK
)
3482 InflateRect(&rcClient
, -1, -1);
3484 csparam
->rgrc
[0] = rcClient
;
3486 *((RECT
*)lParam
) = rcClient
;
3488 // WVR_REDRAW triggers a bug whereby child windows are moved up and left,
3490 // rc.result = WVR_REDRAW;
3498 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3499 const wxBorder border
= TranslateBorder(GetBorder());
3500 if (theme
&& border
== wxBORDER_THEME
)
3502 // first ask the widget to paint its non-client area, such as scrollbars, etc.
3503 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3506 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3507 wxWindowDC
dc((wxWindow
*)this);
3508 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3510 // Clip the DC so that you only draw on the non-client area
3512 wxCopyRectToRECT(GetSize(), rcBorder
);
3515 theme
->GetThemeBackgroundContentRect(
3516 hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, ETS_NORMAL
, &rcBorder
, &rcClient
);
3517 InflateRect(&rcClient
, -1, -1);
3519 ::ExcludeClipRect(GetHdcOf(*impl
), rcClient
.left
, rcClient
.top
,
3520 rcClient
.right
, rcClient
.bottom
);
3522 // Make sure the background is in a proper state
3523 if (theme
->IsThemeBackgroundPartiallyTransparent(hTheme
, EP_EDITTEXT
, ETS_NORMAL
))
3525 theme
->DrawThemeParentBackground(GetHwnd(), GetHdcOf(*impl
), &rcBorder
);
3531 nState
= ETS_DISABLED
;
3532 // should we check this?
3533 //else if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & ES_READONLY)
3534 // nState = ETS_READONLY;
3536 nState
= ETS_NORMAL
;
3537 theme
->DrawThemeBackground(hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, nState
, &rcBorder
, NULL
);
3542 #endif // wxUSE_UXTHEME
3545 // try a custom message handler
3546 const MSWMessageHandlers::const_iterator
3547 i
= gs_messageHandlers
.find(message
);
3548 if ( i
!= gs_messageHandlers
.end() )
3550 processed
= (*i
->second
)(this, message
, wParam
, lParam
);
3556 #if wxDEBUG_LEVEL >= 2
3557 wxLogTrace("winmsg", wxT("Forwarding %s to DefWindowProc."),
3558 wxGetMessageName(message
));
3559 #endif // wxDEBUG_LEVEL >= 2
3560 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3566 // ----------------------------------------------------------------------------
3567 // wxWindow <-> HWND map
3568 // ----------------------------------------------------------------------------
3570 wxWindow
*wxFindWinFromHandle(HWND hwnd
)
3572 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3573 return i
== gs_windowHandles
.end() ? NULL
: i
->second
;
3576 void wxAssociateWinWithHandle(HWND hwnd
, wxWindowMSW
*win
)
3578 // adding NULL hwnd is (first) surely a result of an error and
3579 // (secondly) breaks menu command processing
3580 wxCHECK_RET( hwnd
!= (HWND
)NULL
,
3581 wxT("attempt to add a NULL hwnd to window list ignored") );
3584 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3585 if ( i
!= gs_windowHandles
.end() )
3587 if ( i
->second
!= win
)
3591 wxT("HWND %p already associated with another window (%s)"),
3592 hwnd
, win
->GetClassInfo()->GetClassName()
3596 //else: this actually happens currently because we associate the window
3597 // with its HWND during creation (if we create it) and also when
3598 // SubclassWin() is called later, this is ok
3600 #endif // wxDEBUG_LEVEL
3602 gs_windowHandles
[hwnd
] = (wxWindow
*)win
;
3605 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3607 gs_windowHandles
.erase(GetHwndOf(win
));
3610 // ----------------------------------------------------------------------------
3611 // various MSW speciic class dependent functions
3612 // ----------------------------------------------------------------------------
3614 // Default destroyer - override if you destroy it in some other way
3615 // (e.g. with MDI child windows)
3616 void wxWindowMSW::MSWDestroyWindow()
3620 void wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3623 int& w
, int& h
) const
3625 // CW_USEDEFAULT can't be used for child windows so just position them at
3626 // the origin by default
3627 x
= pos
.x
== wxDefaultCoord
? 0 : pos
.x
;
3628 y
= pos
.y
== wxDefaultCoord
? 0 : pos
.y
;
3630 AdjustForParentClientOrigin(x
, y
);
3632 // We don't have any clearly good choice for the size by default neither
3633 // but we must use something non-zero.
3634 w
= WidthDefault(size
.x
);
3635 h
= HeightDefault(size
.y
);
3638 NB: there used to be some code here which set the initial size of the
3639 window to the client size of the parent if no explicit size was
3640 specified. This was wrong because wxWidgets programs often assume
3641 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3642 it. To see why, you should understand that Windows sends WM_SIZE from
3643 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3644 from some base class ctor and so this WM_SIZE is not processed in the
3645 real class' OnSize() (because it's not fully constructed yet and the
3646 event goes to some base class OnSize() instead). So the WM_SIZE we
3647 rely on is the one sent when the parent frame resizes its children
3648 but here is the problem: if the child already has just the right
3649 size, nothing will happen as both wxWidgets and Windows check for
3650 this and ignore any attempts to change the window size to the size it
3651 already has - so no WM_SIZE would be sent.
3655 WXHWND
wxWindowMSW::MSWGetParent() const
3657 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3660 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3661 const wxChar
*title
,
3665 WXDWORD extendedStyle
)
3667 // check a common bug in the user code: if the window is created with a
3668 // non-default ctor and Create() is called too, we'd create 2 HWND for a
3669 // single wxWindow object and this results in all sorts of trouble,
3670 // especially for wxTLWs
3671 wxCHECK_MSG( !m_hWnd
, true, "window can't be recreated" );
3673 // this can happen if this function is called using the return value of
3674 // wxApp::GetRegisteredClassName() which failed
3675 wxCHECK_MSG( wclass
, false, "failed to register window class?" );
3678 // choose the position/size for the new window
3680 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3682 // controlId is menu handle for the top level windows, so set it to 0
3683 // unless we're creating a child window
3684 int controlId
= style
& WS_CHILD
? GetId() : 0;
3686 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3687 // which is the same but without CS_[HV]REDRAW class styles so using it
3688 // ensures that the window is not fully repainted on each resize
3689 wxString
className(wclass
);
3690 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3692 className
+= wxApp::GetNoRedrawClassSuffix();
3695 // do create the window
3696 wxWindowCreationHook
hook(this);
3698 m_hWnd
= (WXHWND
)::CreateWindowEx
3702 title
? title
: m_windowName
.wx_str(),
3705 (HWND
)MSWGetParent(),
3706 (HMENU
)wxUIntToPtr(controlId
),
3708 NULL
// no extra data
3713 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3718 SubclassWin(m_hWnd
);
3723 // ===========================================================================
3724 // MSW message handlers
3725 // ===========================================================================
3727 // ---------------------------------------------------------------------------
3729 // ---------------------------------------------------------------------------
3731 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3733 #ifndef __WXMICROWIN__
3734 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3735 HWND hWnd
= hdr
->hwndFrom
;
3736 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
3738 // if the control is one of our windows, let it handle the message itself
3741 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3744 // VZ: why did we do it? normally this is unnecessary and, besides, it
3745 // breaks the message processing for the toolbars because the tooltip
3746 // notifications were being forwarded to the toolbar child controls
3747 // (if it had any) before being passed to the toolbar itself, so in my
3748 // example the tooltip for the combobox was always shown instead of the
3749 // correct button tooltips
3751 // try all our children
3752 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3755 wxWindow
*child
= node
->GetData();
3756 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3761 node
= node
->GetNext();
3765 // by default, handle it ourselves
3766 return MSWOnNotify(idCtrl
, lParam
, result
);
3767 #else // __WXMICROWIN__
3774 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3776 const wxString
& ttip
)
3778 // I don't know why it happens, but the versions of comctl32.dll starting
3779 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3780 // this message is supposed to be sent to Unicode programs only) -- hence
3781 // we need to handle it as well, otherwise no tooltips will be shown in
3784 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3787 // not a tooltip message or no tooltip to show anyhow
3792 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3794 // We don't want to use the szText buffer because it has a limit of 80
3795 // bytes and this is not enough, especially for Unicode build where it
3796 // limits the tooltip string length to only 40 characters
3798 // The best would be, of course, to not impose any length limitations at
3799 // all but then the buffer would have to be dynamic and someone would have
3800 // to free it and we don't have the tooltip owner object here any more, so
3801 // for now use our own static buffer with a higher fixed max length.
3803 // Note that using a static buffer should not be a problem as only a single
3804 // tooltip can be shown at the same time anyhow.
3806 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3808 // We need to convert tooltip from multi byte to Unicode on the fly.
3809 static wchar_t buf
[513];
3811 // Truncate tooltip length if needed as otherwise we might not have
3812 // enough space for it in the buffer and MultiByteToWideChar() would
3814 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3816 // Convert to WideChar without adding the NULL character. The NULL
3817 // character is added afterwards (this is more efficient).
3818 int len
= ::MultiByteToWideChar
3830 wxLogLastError(wxT("MultiByteToWideChar()"));
3834 ttText
->lpszText
= (LPSTR
) buf
;
3836 else // TTN_NEEDTEXTA
3837 #endif // !wxUSE_UNICODE
3839 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3840 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3841 // to copy the string we have into the buffer
3842 static wxChar buf
[513];
3843 wxStrlcpy(buf
, ttip
.c_str(), WXSIZEOF(buf
));
3844 ttText
->lpszText
= buf
;
3850 #endif // wxUSE_TOOLTIPS
3852 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3854 WXLPARAM
* WXUNUSED(result
))
3859 NMHDR
* hdr
= (NMHDR
*)lParam
;
3860 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3867 wxUnusedVar(lParam
);
3868 #endif // wxUSE_TOOLTIPS
3873 // ---------------------------------------------------------------------------
3874 // end session messages
3875 // ---------------------------------------------------------------------------
3877 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3879 #ifdef ENDSESSION_LOGOFF
3880 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3881 event
.SetEventObject(wxTheApp
);
3882 event
.SetCanVeto(true);
3883 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3885 bool rc
= wxTheApp
->ProcessEvent(event
);
3889 // we may end only if the app didn't veto session closing (double
3891 *mayEnd
= !event
.GetVeto();
3896 wxUnusedVar(logOff
);
3897 wxUnusedVar(mayEnd
);
3902 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3904 #ifdef ENDSESSION_LOGOFF
3905 // do nothing if the session isn't ending
3910 if ( (this != wxTheApp
->GetTopWindow()) )
3913 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3914 event
.SetEventObject(wxTheApp
);
3915 event
.SetCanVeto(false);
3916 event
.SetLoggingOff((logOff
& ENDSESSION_LOGOFF
) != 0);
3918 return wxTheApp
->ProcessEvent(event
);
3920 wxUnusedVar(endSession
);
3921 wxUnusedVar(logOff
);
3926 // ---------------------------------------------------------------------------
3927 // window creation/destruction
3928 // ---------------------------------------------------------------------------
3930 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3933 // VZ: why is this commented out for WinCE? If it doesn't support
3934 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3935 // not with multiple #ifdef's!
3937 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3938 EnsureParentHasControlParentStyle(GetParent());
3939 #endif // !__WXWINCE__
3946 bool wxWindowMSW::HandleDestroy()
3948 // delete our drop target if we've got one
3949 #if wxUSE_DRAG_AND_DROP
3950 if ( m_dropTarget
!= NULL
)
3952 m_dropTarget
->Revoke(m_hWnd
);
3954 wxDELETE(m_dropTarget
);
3956 #endif // wxUSE_DRAG_AND_DROP
3958 // WM_DESTROY handled
3962 // ---------------------------------------------------------------------------
3964 // ---------------------------------------------------------------------------
3966 bool wxWindowMSW::HandleActivate(int state
,
3967 bool WXUNUSED(minimized
),
3968 WXHWND
WXUNUSED(activate
))
3970 wxActivateEvent
event(wxEVT_ACTIVATE
,
3971 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3973 event
.SetEventObject(this);
3975 return HandleWindowEvent(event
);
3978 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3980 // Strangly enough, some controls get set focus events when they are being
3981 // deleted, even if they already had focus before.
3982 if ( m_isBeingDeleted
)
3987 // notify the parent keeping track of focus for the kbd navigation
3988 // purposes that we got it
3989 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3990 (void)HandleWindowEvent(eventFocus
);
3996 m_caret
->OnSetFocus();
3998 #endif // wxUSE_CARET
4000 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
4001 event
.SetEventObject(this);
4003 // wxFindWinFromHandle() may return NULL, it is ok
4004 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4006 return HandleWindowEvent(event
);
4009 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
4015 m_caret
->OnKillFocus();
4017 #endif // wxUSE_CARET
4019 // Don't send the event when in the process of being deleted. This can
4020 // only cause problems if the event handler tries to access the object.
4021 if ( m_isBeingDeleted
)
4026 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
4027 event
.SetEventObject(this);
4029 // wxFindWinFromHandle() may return NULL, it is ok
4030 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4032 return HandleWindowEvent(event
);
4035 // ---------------------------------------------------------------------------
4037 // ---------------------------------------------------------------------------
4039 void wxWindowMSW::SetLabel( const wxString
& label
)
4041 SetWindowText(GetHwnd(), label
.c_str());
4044 wxString
wxWindowMSW::GetLabel() const
4046 return wxGetWindowText(GetHWND());
4049 // ---------------------------------------------------------------------------
4051 // ---------------------------------------------------------------------------
4053 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
4055 wxShowEvent
event(GetId(), show
);
4056 event
.SetEventObject(this);
4058 return HandleWindowEvent(event
);
4061 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
4063 wxInitDialogEvent
event(GetId());
4064 event
.SetEventObject(this);
4066 return HandleWindowEvent(event
);
4069 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
4071 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
4072 wxUnusedVar(wParam
);
4074 #else // __WXMICROWIN__
4075 HDROP hFilesInfo
= (HDROP
) wParam
;
4077 // Get the total number of files dropped
4078 UINT gwFilesDropped
= ::DragQueryFile
4086 wxString
*files
= new wxString
[gwFilesDropped
];
4087 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
4089 // first get the needed buffer length (+1 for terminating NUL)
4090 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
4092 // and now get the file name
4093 ::DragQueryFile(hFilesInfo
, wIndex
,
4094 wxStringBuffer(files
[wIndex
], len
), len
);
4097 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
4098 event
.SetEventObject(this);
4101 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
4102 event
.m_pos
.x
= dropPoint
.x
;
4103 event
.m_pos
.y
= dropPoint
.y
;
4105 DragFinish(hFilesInfo
);
4107 return HandleWindowEvent(event
);
4112 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
4114 int WXUNUSED(mouseMsg
))
4116 #ifndef __WXMICROWIN__
4117 // the logic is as follows:
4118 // 0. if we're busy, set the busy cursor (even for non client elements)
4119 // 1. don't set custom cursor for non client area of enabled windows
4120 // 2. ask user EVT_SET_CURSOR handler for the cursor
4121 // 3. if still no cursor but we're in a TLW, set the global cursor
4123 HCURSOR hcursor
= 0;
4126 hcursor
= wxGetCurrentBusyCursor();
4130 if ( nHitTest
!= HTCLIENT
)
4133 // first ask the user code - it may wish to set the cursor in some very
4134 // specific way (for example, depending on the current position)
4137 if ( !::GetCursorPosWinCE(&pt
))
4139 if ( !::GetCursorPos(&pt
) )
4142 wxLogLastError(wxT("GetCursorPos"));
4147 ScreenToClient(&x
, &y
);
4148 wxSetCursorEvent
event(x
, y
);
4149 event
.SetId(GetId());
4150 event
.SetEventObject(this);
4152 bool processedEvtSetCursor
= HandleWindowEvent(event
);
4153 if ( processedEvtSetCursor
&& event
.HasCursor() )
4155 hcursor
= GetHcursorOf(event
.GetCursor());
4160 // the test for processedEvtSetCursor is here to prevent using
4161 // m_cursor if the user code caught EVT_SET_CURSOR() and returned
4162 // nothing from it - this is a way to say that our cursor shouldn't
4163 // be used for this point
4164 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
4166 hcursor
= GetHcursorOf(m_cursor
);
4169 if ( !hcursor
&& !GetParent() )
4171 const wxCursor
*cursor
= wxGetGlobalCursor();
4172 if ( cursor
&& cursor
->Ok() )
4174 hcursor
= GetHcursorOf(*cursor
);
4183 ::SetCursor(hcursor
);
4185 // cursor set, stop here
4188 #endif // __WXMICROWIN__
4190 // pass up the window chain
4194 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
4195 WXLPARAM
WXUNUSED(lParam
),
4196 bool *WXUNUSED_IN_WINCE(vetoed
))
4202 wxEventType evtType
;
4205 case PBT_APMQUERYSUSPEND
:
4206 evtType
= wxEVT_POWER_SUSPENDING
;
4209 case PBT_APMQUERYSUSPENDFAILED
:
4210 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
4213 case PBT_APMSUSPEND
:
4214 evtType
= wxEVT_POWER_SUSPENDED
;
4217 case PBT_APMRESUMESUSPEND
:
4218 evtType
= wxEVT_POWER_RESUME
;
4222 wxLogDebug(wxT("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
4225 // these messages are currently not mapped to wx events
4226 case PBT_APMQUERYSTANDBY
:
4227 case PBT_APMQUERYSTANDBYFAILED
:
4228 case PBT_APMSTANDBY
:
4229 case PBT_APMRESUMESTANDBY
:
4230 case PBT_APMBATTERYLOW
:
4231 case PBT_APMPOWERSTATUSCHANGE
:
4232 case PBT_APMOEMEVENT
:
4233 case PBT_APMRESUMECRITICAL
:
4234 #ifdef PBT_APMRESUMEAUTOMATIC
4235 case PBT_APMRESUMEAUTOMATIC
:
4237 evtType
= wxEVT_NULL
;
4241 // don't handle unknown messages
4242 if ( evtType
== wxEVT_NULL
)
4245 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
4247 wxPowerEvent
event(evtType
);
4248 if ( !HandleWindowEvent(event
) )
4251 *vetoed
= event
.IsVetoed();
4257 bool wxWindowMSW::IsDoubleBuffered() const
4259 for ( const wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4261 if ( wxHasWindowExStyle(win
, WS_EX_COMPOSITED
) )
4264 if ( win
->IsTopLevel() )
4271 void wxWindowMSW::SetDoubleBuffered(bool on
)
4273 // Get the current extended style bits
4274 long exstyle
= wxGetWindowExStyle(this);
4276 // Twiddle the bit as needed
4278 exstyle
|= WS_EX_COMPOSITED
;
4280 exstyle
&= ~WS_EX_COMPOSITED
;
4283 wxSetWindowExStyle(this, exstyle
);
4286 // ---------------------------------------------------------------------------
4287 // owner drawn stuff
4288 // ---------------------------------------------------------------------------
4290 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
4291 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
4292 #define WXUNUSED_UNLESS_ODRAWN(param) param
4294 #define WXUNUSED_UNLESS_ODRAWN(param)
4298 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
4299 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
4301 #if wxUSE_OWNER_DRAWN
4303 #if wxUSE_MENUS_NATIVE
4304 // is it a menu item?
4305 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
4306 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
4308 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
4310 // see comment before the same test in MSWOnMeasureItem() below
4314 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4315 false, wxT("MSWOnDrawItem: bad wxMenuItem pointer") );
4317 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4318 // the DC from being released
4319 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
4320 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
4321 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
4322 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
4324 return pMenuItem
->OnDrawItem
4328 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
4329 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
4332 #endif // wxUSE_MENUS_NATIVE
4334 #endif // USE_OWNER_DRAWN
4336 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4338 #if wxUSE_OWNER_DRAWN
4339 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4340 #else // !wxUSE_OWNER_DRAWN
4341 // we may still have owner-drawn buttons internally because we have to make
4342 // them owner-drawn to support colour change
4345 wxDynamicCast(FindItem(id
), wxButton
)
4350 #endif // USE_OWNER_DRAWN
4354 return item
->MSWOnDraw(itemStruct
);
4357 #endif // wxUSE_CONTROLS
4363 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4365 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4366 // is it a menu item?
4367 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4368 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4370 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4372 // according to Carsten Fuchs the pointer may be NULL under XP if an
4373 // MDI child frame is initially maximized, see this for more info:
4374 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4376 // so silently ignore it instead of asserting
4380 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4381 false, wxT("MSWOnMeasureItem: bad wxMenuItem pointer") );
4384 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4386 pMeasureStruct
->itemWidth
= w
;
4387 pMeasureStruct
->itemHeight
= h
;
4392 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4395 return item
->MSWOnMeasure(itemStruct
);
4399 wxUnusedVar(itemStruct
);
4400 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4405 // ---------------------------------------------------------------------------
4406 // colours and palettes
4407 // ---------------------------------------------------------------------------
4409 bool wxWindowMSW::HandleSysColorChange()
4411 wxSysColourChangedEvent event
;
4412 event
.SetEventObject(this);
4414 (void)HandleWindowEvent(event
);
4416 // always let the system carry on the default processing to allow the
4417 // native controls to react to the colours update
4421 bool wxWindowMSW::HandleDisplayChange()
4423 wxDisplayChangedEvent event
;
4424 event
.SetEventObject(this);
4426 return HandleWindowEvent(event
);
4429 #ifndef __WXMICROWIN__
4431 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4433 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4437 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4440 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4442 #endif // wxUSE_CONTROLS
4445 return *brush
!= NULL
;
4448 #endif // __WXMICROWIN__
4450 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4453 // same as below except we don't respond to our own messages
4454 if ( hWndPalChange
!= GetHWND() )
4456 // check to see if we our our parents have a custom palette
4457 wxWindowMSW
*win
= this;
4458 while ( win
&& !win
->HasCustomPalette() )
4460 win
= win
->GetParent();
4463 if ( win
&& win
->HasCustomPalette() )
4465 // realize the palette to see whether redrawing is needed
4466 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4467 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4468 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4470 int result
= ::RealizePalette(hdc
);
4472 // restore the palette (before releasing the DC)
4473 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4474 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4475 ::RealizePalette(hdc
);
4476 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4478 // now check for the need to redraw
4480 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4484 #endif // wxUSE_PALETTE
4486 wxPaletteChangedEvent
event(GetId());
4487 event
.SetEventObject(this);
4488 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4490 return HandleWindowEvent(event
);
4493 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4495 // notify windows on the capture stack about lost capture
4496 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4497 wxWindowBase::NotifyCaptureLost();
4499 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4500 wxMouseCaptureChangedEvent
event(GetId(), win
);
4501 event
.SetEventObject(this);
4502 return HandleWindowEvent(event
);
4505 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4507 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4508 // we need to send this to child windows (it is only sent to top-level
4509 // windows) so {list,tree}ctrls can adjust their font size if necessary
4510 // this is exactly how explorer does it to enable the font size changes
4512 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4515 // top-level windows already get this message from the system
4516 wxWindow
*win
= node
->GetData();
4517 if ( !win
->IsTopLevel() )
4519 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4522 node
= node
->GetNext();
4525 // let the system handle it
4529 bool wxWindowMSW::HandleQueryNewPalette()
4533 // check to see if we our our parents have a custom palette
4534 wxWindowMSW
*win
= this;
4535 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4536 if (win
->HasCustomPalette()) {
4537 /* realize the palette to see whether redrawing is needed */
4538 HDC hdc
= ::GetDC((HWND
) GetHWND());
4539 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4540 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4542 int result
= ::RealizePalette(hdc
);
4543 /* restore the palette (before releasing the DC) */
4544 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4545 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4546 ::RealizePalette(hdc
);
4547 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4548 /* now check for the need to redraw */
4550 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4552 #endif // wxUSE_PALETTE
4554 wxQueryNewPaletteEvent
event(GetId());
4555 event
.SetEventObject(this);
4557 return HandleWindowEvent(event
) && event
.GetPaletteRealized();
4560 // Responds to colour changes: passes event on to children.
4561 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4563 // the top level window also reset the standard colour map as it might have
4564 // changed (there is no need to do it for the non top level windows as we
4565 // only have to do it once)
4569 gs_hasStdCmap
= false;
4571 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4574 // Only propagate to non-top-level windows because Windows already
4575 // sends this event to all top-level ones
4576 wxWindow
*win
= node
->GetData();
4577 if ( !win
->IsTopLevel() )
4579 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4580 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4581 // the standard controls
4582 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4585 node
= node
->GetNext();
4589 extern wxCOLORMAP
*wxGetStdColourMap()
4591 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4592 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4594 if ( !gs_hasStdCmap
)
4596 static bool s_coloursInit
= false;
4598 if ( !s_coloursInit
)
4600 // When a bitmap is loaded, the RGB values can change (apparently
4601 // because Windows adjusts them to care for the old programs always
4602 // using 0xc0c0c0 while the transparent colour for the new Windows
4603 // versions is different). But we do this adjustment ourselves so
4604 // we want to avoid Windows' "help" and for this we need to have a
4605 // reference bitmap which can tell us what the RGB values change
4607 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4608 wxBitmap
stdColourBitmap(wxT("wxBITMAP_STD_COLOURS"));
4609 if ( stdColourBitmap
.Ok() )
4611 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4612 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4613 wxT("forgot to update wxBITMAP_STD_COLOURS!") );
4616 memDC
.SelectObject(stdColourBitmap
);
4619 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4621 memDC
.GetPixel(i
, 0, &colour
);
4622 s_stdColours
[i
] = wxColourToRGB(colour
);
4625 else // wxBITMAP_STD_COLOURS couldn't be loaded
4627 s_stdColours
[0] = RGB(000,000,000); // black
4628 s_stdColours
[1] = RGB(128,128,128); // dark grey
4629 s_stdColours
[2] = RGB(192,192,192); // light grey
4630 s_stdColours
[3] = RGB(255,255,255); // white
4631 //s_stdColours[4] = RGB(000,000,255); // blue
4632 //s_stdColours[5] = RGB(255,000,255); // magenta
4635 s_coloursInit
= true;
4638 gs_hasStdCmap
= true;
4640 // create the colour map
4641 #define INIT_CMAP_ENTRY(col) \
4642 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4643 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4645 INIT_CMAP_ENTRY(BTNTEXT
);
4646 INIT_CMAP_ENTRY(BTNSHADOW
);
4647 INIT_CMAP_ENTRY(BTNFACE
);
4648 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4650 #undef INIT_CMAP_ENTRY
4656 #if wxUSE_UXTHEME && !defined(TMT_FILLCOLOR)
4657 #define TMT_FILLCOLOR 3802
4658 #define TMT_TEXTCOLOR 3803
4659 #define TMT_BORDERCOLOR 3801
4662 wxColour
wxWindowMSW::MSWGetThemeColour(const wchar_t *themeName
,
4665 MSWThemeColour themeColour
,
4666 wxSystemColour fallback
) const
4669 const wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
4672 int themeProperty
= 0;
4674 // TODO: Convert this into a table? Sure would be faster.
4675 switch ( themeColour
)
4677 case ThemeColourBackground
:
4678 themeProperty
= TMT_FILLCOLOR
;
4680 case ThemeColourText
:
4681 themeProperty
= TMT_TEXTCOLOR
;
4683 case ThemeColourBorder
:
4684 themeProperty
= TMT_BORDERCOLOR
;
4687 wxFAIL_MSG(wxT("unsupported theme colour"));
4690 wxUxThemeHandle
hTheme((const wxWindow
*)this, themeName
);
4692 HRESULT hr
= theme
->GetThemeColor
4701 if ( SUCCEEDED(hr
) )
4702 return wxRGBToColour(col
);
4706 "GetThemeColor(%s, %i, %i, %i)",
4707 themeName
, themePart
, themeState
, themeProperty
),
4711 wxUnusedVar(themeName
);
4712 wxUnusedVar(themePart
);
4713 wxUnusedVar(themeState
);
4714 wxUnusedVar(themeColour
);
4716 return wxSystemSettings::GetColour(fallback
);
4719 // ---------------------------------------------------------------------------
4721 // ---------------------------------------------------------------------------
4723 // this variable is used to check that a paint event handler which processed
4724 // the event did create a wxPaintDC inside its code and called BeginPaint() to
4725 // validate the invalidated window area as otherwise we'd keep getting an
4726 // endless stream of WM_PAINT messages for this window resulting in a lot of
4727 // difficult to debug problems (e.g. impossibility to repaint other windows,
4728 // lack of timer and idle events and so on)
4729 extern bool wxDidCreatePaintDC
;
4730 bool wxDidCreatePaintDC
= false;
4732 bool wxWindowMSW::HandlePaint()
4734 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4737 wxLogLastError(wxT("CreateRectRgn"));
4739 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4741 wxLogLastError(wxT("GetUpdateRgn"));
4744 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4746 wxDidCreatePaintDC
= false;
4748 wxPaintEvent
event(m_windowId
);
4749 event
.SetEventObject(this);
4751 bool processed
= HandleWindowEvent(event
);
4753 if ( processed
&& !wxDidCreatePaintDC
)
4755 // do call MSWDefWindowProc() to validate the update region to avoid
4756 // the problems mentioned above
4760 // note that we must generate NC event after the normal one as otherwise
4761 // BeginPaint() will happily overwrite our decorations with the background
4763 wxNcPaintEvent
eventNc(m_windowId
);
4764 eventNc
.SetEventObject(this);
4765 HandleWindowEvent(eventNc
);
4767 // don't keep an HRGN we don't need any longer (GetUpdateRegion() can only
4768 // be called from inside the event handlers called above)
4769 m_updateRegion
.Clear();
4774 // Can be called from an application's OnPaint handler
4775 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4777 #ifdef __WXUNIVERSAL__
4780 HDC hDC
= (HDC
) wxPaintDCImpl::FindDCInCache((wxWindow
*) event
.GetEventObject());
4783 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4788 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4790 switch ( GetBackgroundStyle() )
4792 case wxBG_STYLE_ERASE
:
4793 case wxBG_STYLE_COLOUR
:
4794 // we need to generate an erase background event
4796 wxDCTemp
dc(hdc
, GetClientSize());
4797 wxDCTempImpl
*impl
= (wxDCTempImpl
*) dc
.GetImpl();
4800 impl
->SetWindow((wxWindow
*)this);
4802 wxEraseEvent
event(m_windowId
, &dc
);
4803 event
.SetEventObject(this);
4804 bool rc
= HandleWindowEvent(event
);
4806 // must be called manually as ~wxDC doesn't do anything for
4808 impl
->SelectOldObjects(hdc
);
4812 // background erased by the user-defined handler
4818 case wxBG_STYLE_SYSTEM
:
4819 if ( !DoEraseBackground(hdc
) )
4821 // let the default processing to take place if we didn't erase
4822 // the background ourselves
4827 case wxBG_STYLE_PAINT
:
4828 case wxBG_STYLE_TRANSPARENT
:
4829 // no need to do anything here at all, background will be entirely
4830 // redrawn in WM_PAINT handler
4834 wxFAIL_MSG( "unknown background style" );
4840 #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK
4842 bool wxWindowMSW::MSWHasEraseBgHook() const
4844 return gs_eraseBgHooks
.find(const_cast<wxWindowMSW
*>(this))
4845 != gs_eraseBgHooks
.end();
4848 void wxWindowMSW::MSWSetEraseBgHook(wxWindow
*child
)
4852 if ( !gs_eraseBgHooks
.insert(
4853 EraseBgHooks::value_type(this, child
)).second
)
4855 wxFAIL_MSG( wxT("Setting erase background hook twice?") );
4858 else // reset the hook
4860 if ( gs_eraseBgHooks
.erase(this) != 1 )
4862 wxFAIL_MSG( wxT("Resetting erase background which was not set?") );
4867 #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK
4869 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4871 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4875 // erase just the client area of the window, this is important for the
4876 // frames to avoid drawing over the toolbar part of the window (you might
4877 // think using WS_CLIPCHILDREN would prevent this from happening, but it
4880 wxCopyRectToRECT(GetClientRect(), rc
);
4881 ::FillRect((HDC
)hDC
, &rc
, hbr
);
4887 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
),
4888 wxWindowMSW
* WXUNUSED(child
))
4893 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4895 return (WXHBRUSH
)GetHbrushOf(*brush
);
4901 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
)
4903 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4905 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, this);
4909 // don't use the parent background if we're not transparent
4910 if ( !win
->HasTransparentBackground() )
4913 // background is not inherited beyond top level windows
4914 if ( win
->IsTopLevel() )
4921 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4923 // we receive this message when DrawThemeParentBackground() is
4924 // called from def window proc of several controls under XP and we
4925 // must draw properly themed background here
4927 // note that naively I'd expect filling the client rect with the
4928 // brush returned by MSWGetBgBrush() work -- but for some reason it
4929 // doesn't and we have to call parents MSWPrintChild() which is
4930 // supposed to call DrawThemeBackground() with appropriate params
4932 // also note that in this case lParam == PRF_CLIENT but we're
4933 // clearly expected to paint the background and nothing else!
4935 if ( IsTopLevel() || InheritsBackgroundColour() )
4938 // sometimes we don't want the parent to handle it at all, instead
4939 // return whatever value this window wants
4940 if ( !MSWShouldPropagatePrintChild() )
4941 return MSWPrintChild(hDC
, (wxWindow
*)this);
4943 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4945 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4948 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4955 // ---------------------------------------------------------------------------
4956 // moving and resizing
4957 // ---------------------------------------------------------------------------
4959 bool wxWindowMSW::HandleMinimize()
4961 wxIconizeEvent
event(m_windowId
);
4962 event
.SetEventObject(this);
4964 return HandleWindowEvent(event
);
4967 bool wxWindowMSW::HandleMaximize()
4969 wxMaximizeEvent
event(m_windowId
);
4970 event
.SetEventObject(this);
4972 return HandleWindowEvent(event
);
4975 bool wxWindowMSW::HandleMove(int x
, int y
)
4978 wxMoveEvent
event(point
, m_windowId
);
4979 event
.SetEventObject(this);
4981 return HandleWindowEvent(event
);
4984 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
4986 wxMoveEvent
event(rect
, m_windowId
);
4987 event
.SetEventObject(this);
4989 bool rc
= HandleWindowEvent(event
);
4991 rect
= event
.GetRect();
4995 bool wxWindowMSW::HandleEnterSizeMove()
4997 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
4998 event
.SetEventType(wxEVT_MOVE_START
);
4999 event
.SetEventObject(this);
5001 return HandleWindowEvent(event
);
5004 bool wxWindowMSW::HandleExitSizeMove()
5006 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5007 event
.SetEventType(wxEVT_MOVE_END
);
5008 event
.SetEventObject(this);
5010 return HandleWindowEvent(event
);
5013 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
5015 #if wxUSE_DEFERRED_SIZING
5016 // when we resize this window, its children are probably going to be
5017 // repositioned as well, prepare to use DeferWindowPos() for them
5018 int numChildren
= 0;
5019 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
5021 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
5026 // Protect against valid m_hDWP being overwritten
5027 bool useDefer
= false;
5029 if ( numChildren
> 1 )
5033 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
5036 wxLogLastError(wxT("BeginDeferWindowPos"));
5042 #endif // wxUSE_DEFERRED_SIZING
5044 // update this window size
5045 bool processed
= false;
5049 wxFAIL_MSG( wxT("unexpected WM_SIZE parameter") );
5050 // fall through nevertheless
5054 // we're not interested in these messages at all
5057 case SIZE_MINIMIZED
:
5058 processed
= HandleMinimize();
5061 case SIZE_MAXIMIZED
:
5062 /* processed = */ HandleMaximize();
5063 // fall through to send a normal size event as well
5066 // don't use w and h parameters as they specify the client size
5067 // while according to the docs EVT_SIZE handler is supposed to
5068 // receive the total size
5069 wxSizeEvent
event(GetSize(), m_windowId
);
5070 event
.SetEventObject(this);
5072 processed
= HandleWindowEvent(event
);
5075 #if wxUSE_DEFERRED_SIZING
5076 // and finally change the positions of all child windows at once
5077 if ( useDefer
&& m_hDWP
)
5079 // reset m_hDWP to NULL so that child windows don't try to use our
5080 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
5081 // happen anyhow normally but who knows what weird flow of control we
5082 // may have depending on what the users EVT_SIZE handler does...)
5083 HDWP hDWP
= (HDWP
)m_hDWP
;
5086 // do put all child controls in place at once
5087 if ( !::EndDeferWindowPos(hDWP
) )
5089 wxLogLastError(wxT("EndDeferWindowPos"));
5092 // Reset our children's pending pos/size values.
5093 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
5095 node
= node
->GetNext() )
5097 wxWindowMSW
* const child
= node
->GetData();
5098 child
->MSWEndDeferWindowPos();
5101 #endif // wxUSE_DEFERRED_SIZING
5106 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
5108 wxSizeEvent
event(rect
, m_windowId
);
5109 event
.SetEventObject(this);
5111 bool rc
= HandleWindowEvent(event
);
5113 rect
= event
.GetRect();
5117 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
5122 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
5126 int minWidth
= GetMinWidth(),
5127 minHeight
= GetMinHeight(),
5128 maxWidth
= GetMaxWidth(),
5129 maxHeight
= GetMaxHeight();
5131 if ( minWidth
!= wxDefaultCoord
)
5133 info
->ptMinTrackSize
.x
= minWidth
;
5137 if ( minHeight
!= wxDefaultCoord
)
5139 info
->ptMinTrackSize
.y
= minHeight
;
5143 if ( maxWidth
!= wxDefaultCoord
)
5145 info
->ptMaxTrackSize
.x
= maxWidth
;
5149 if ( maxHeight
!= wxDefaultCoord
)
5151 info
->ptMaxTrackSize
.y
= maxHeight
;
5159 // ---------------------------------------------------------------------------
5161 // ---------------------------------------------------------------------------
5163 bool wxWindowMSW::HandleCommand(WXWORD id_
, WXWORD cmd
, WXHWND control
)
5165 // sign extend to int from short before comparing with the other int ids
5166 int id
= (signed short)id_
;
5168 #if wxUSE_MENUS_NATIVE
5169 if ( !cmd
&& wxCurrentPopupMenu
)
5171 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
5172 wxCurrentPopupMenu
= NULL
;
5174 return popupMenu
->MSWCommand(cmd
, id
);
5176 #endif // wxUSE_MENUS_NATIVE
5178 wxWindow
*win
= NULL
;
5180 // first try to find it from HWND - this works even with the broken
5181 // programs using the same ids for different controls
5184 win
= wxFindWinFromHandle(control
);
5195 return win
->MSWCommand(cmd
, id
);
5198 // the messages sent from the in-place edit control used by the treectrl
5199 // for label editing have id == 0, but they should _not_ be treated as menu
5200 // messages (they are EN_XXX ones, in fact) so don't translate anything
5201 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
5204 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
5205 event
.SetEventObject(this);
5208 return HandleWindowEvent(event
);
5212 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5213 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
5214 // notifications to its parent which we want to reflect back to
5216 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
5217 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
5219 #endif // wxUSE_SPINCTRL
5221 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
5222 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
5223 // notifications to its parent which we want to reflect back to
5225 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
5226 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
5234 // ---------------------------------------------------------------------------
5236 // ---------------------------------------------------------------------------
5238 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
5242 // our client coords are not quite the same as Windows ones
5243 wxPoint pt
= GetClientAreaOrigin();
5244 event
.m_x
= x
- pt
.x
;
5245 event
.m_y
= y
- pt
.y
;
5247 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
5248 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
5249 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
5250 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
5251 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
5252 #ifdef wxHAS_XBUTTON
5253 event
.m_aux1Down
= (flags
& MK_XBUTTON1
) != 0;
5254 event
.m_aux2Down
= (flags
& MK_XBUTTON2
) != 0;
5255 #endif // wxHAS_XBUTTON
5256 event
.m_altDown
= ::wxIsAltDown();
5259 event
.SetTimestamp(::GetMessageTime());
5262 event
.SetEventObject(this);
5263 event
.SetId(GetId());
5265 #if wxUSE_MOUSEEVENT_HACK
5266 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
5267 gs_lastMouseEvent
.type
= event
.GetEventType();
5268 #endif // wxUSE_MOUSEEVENT_HACK
5272 // Windows doesn't send the mouse events to the static controls (which are
5273 // transparent in the sense that their WM_NCHITTEST handler returns
5274 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
5275 // and so we manually check if we don't have a child window under mouse and if
5276 // we do, send the event to it instead of the window Windows had sent WM_XXX
5279 // Notice that this is not done for the mouse move events because this could
5280 // (would?) be too slow, but only for clicks which means that the static texts
5281 // still don't get move, enter nor leave events.
5282 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
5284 wxCHECK_MSG( x
&& y
, win
, wxT("NULL pointer in FindWindowForMouseEvent") );
5286 // first try to find a non transparent child: this allows us to send events
5287 // to a static text which is inside a static box, for example
5288 POINT pt
= { *x
, *y
};
5289 HWND hwnd
= GetHwndOf(win
),
5293 hwndUnderMouse
= ::ChildWindowFromPoint
5299 hwndUnderMouse
= ::ChildWindowFromPointEx
5309 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
5311 // now try any child window at all
5312 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
5315 // check that we have a child window which is susceptible to receive mouse
5316 // events: for this it must be shown and enabled
5317 if ( hwndUnderMouse
&&
5318 hwndUnderMouse
!= hwnd
&&
5319 ::IsWindowVisible(hwndUnderMouse
) &&
5320 ::IsWindowEnabled(hwndUnderMouse
) )
5322 wxWindow
*winUnderMouse
= wxFindWinFromHandle(hwndUnderMouse
);
5323 if ( winUnderMouse
)
5325 // translate the mouse coords to the other window coords
5326 win
->ClientToScreen(x
, y
);
5327 winUnderMouse
->ScreenToClient(x
, y
);
5329 win
= winUnderMouse
;
5335 #endif // __WXWINCE__
5337 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5339 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
5340 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
5341 // from the message id and take the value in the table to get wxWin event
5343 static const wxEventType eventsMouse
[] =
5354 wxEVT_MIDDLE_DCLICK
,
5355 0, // this one is for wxEVT_MOTION which is not used here
5364 #ifdef wxHAS_XBUTTON
5365 // the same messages are used for both auxillary mouse buttons so we need
5366 // to adjust the index manually
5369 case WM_XBUTTONDOWN
:
5371 case WM_XBUTTONDBLCLK
:
5372 if ( flags
& MK_XBUTTON2
)
5373 msg
+= wxEVT_AUX2_DOWN
- wxEVT_AUX1_DOWN
;
5375 #endif // wxHAS_XBUTTON
5377 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
5378 InitMouseEvent(event
, x
, y
, flags
);
5380 return HandleWindowEvent(event
);
5383 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
5385 if ( !m_mouseInWindow
)
5387 // it would be wrong to assume that just because we get a mouse move
5388 // event that the mouse is inside the window: although this is usually
5389 // true, it is not if we had captured the mouse, so we need to check
5390 // the mouse coordinates here
5391 if ( !HasCapture() || IsMouseInWindow() )
5393 // Generate an ENTER event
5394 m_mouseInWindow
= true;
5396 #ifdef HAVE_TRACKMOUSEEVENT
5397 typedef BOOL (WINAPI
*_TrackMouseEvent_t
)(LPTRACKMOUSEEVENT
);
5399 static const _TrackMouseEvent_t
5400 s_pfn_TrackMouseEvent
= _TrackMouseEvent
;
5401 #else // !__WXWINCE__
5402 static _TrackMouseEvent_t s_pfn_TrackMouseEvent
;
5403 static bool s_initDone
= false;
5406 // see comment in wxApp::GetComCtl32Version() explaining the
5407 // use of wxLoadedDLL
5408 wxLoadedDLL
dllComCtl32(wxT("comctl32.dll"));
5409 if ( dllComCtl32
.IsLoaded() )
5411 s_pfn_TrackMouseEvent
= (_TrackMouseEvent_t
)
5412 dllComCtl32
.RawGetSymbol(wxT("_TrackMouseEvent"));
5418 if ( s_pfn_TrackMouseEvent
)
5419 #endif // __WXWINCE__/!__WXWINCE__
5421 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
5423 trackinfo
.dwFlags
= TME_LEAVE
;
5424 trackinfo
.hwndTrack
= GetHwnd();
5426 (*s_pfn_TrackMouseEvent
)(&trackinfo
);
5428 #endif // HAVE_TRACKMOUSEEVENT
5430 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
5431 InitMouseEvent(event
, x
, y
, flags
);
5433 (void)HandleWindowEvent(event
);
5436 #ifdef HAVE_TRACKMOUSEEVENT
5437 else // mouse not in window
5439 // Check if we need to send a LEAVE event
5440 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
5441 // send it here if we are using native mouse leave tracking
5442 if ( HasCapture() && !IsMouseInWindow() )
5444 GenerateMouseLeave();
5447 #endif // HAVE_TRACKMOUSEEVENT
5449 #if wxUSE_MOUSEEVENT_HACK
5450 // Windows often generates mouse events even if mouse position hasn't
5451 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
5453 // Filter this out as it can result in unexpected behaviour compared to
5455 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
5456 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
5457 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
5458 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
5460 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
5462 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
5467 #endif // wxUSE_MOUSEEVENT_HACK
5469 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
5473 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
5475 #if wxUSE_MOUSEWHEEL
5476 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5477 // forwarded up to the parent by DefWindowProc()) and not in the client
5478 // ones as all the other messages, translate them to the client coords for
5481 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
5482 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
5483 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
5484 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5485 event
.m_wheelDelta
= WHEEL_DELTA
;
5487 static int s_linesPerRotation
= -1;
5488 if ( s_linesPerRotation
== -1 )
5490 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5491 &s_linesPerRotation
, 0))
5493 // this is not supposed to happen
5494 wxLogLastError(wxT("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5496 // the default is 3, so use it if SystemParametersInfo() failed
5497 s_linesPerRotation
= 3;
5501 event
.m_linesPerAction
= s_linesPerRotation
;
5502 return HandleWindowEvent(event
);
5504 #else // !wxUSE_MOUSEWHEEL
5505 wxUnusedVar(wParam
);
5506 wxUnusedVar(lParam
);
5509 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5512 void wxWindowMSW::GenerateMouseLeave()
5514 m_mouseInWindow
= false;
5517 if ( wxIsShiftDown() )
5519 if ( wxIsCtrlDown() )
5520 state
|= MK_CONTROL
;
5522 // Only the high-order bit should be tested
5523 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5524 state
|= MK_LBUTTON
;
5525 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5526 state
|= MK_MBUTTON
;
5527 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5528 state
|= MK_RBUTTON
;
5532 if ( !::GetCursorPosWinCE(&pt
) )
5534 if ( !::GetCursorPos(&pt
) )
5537 wxLogLastError(wxT("GetCursorPos"));
5540 // we need to have client coordinates here for symmetry with
5541 // wxEVT_ENTER_WINDOW
5542 RECT rect
= wxGetWindowRect(GetHwnd());
5546 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5547 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5549 (void)HandleWindowEvent(event
);
5552 // ---------------------------------------------------------------------------
5553 // keyboard handling
5554 // ---------------------------------------------------------------------------
5559 // Implementation of InitAnyKeyEvent() which can also be used when there is no
5560 // associated window: this can happen for the wxEVT_CHAR_HOOK events created by
5561 // the global keyboard hook (e.g. the event might have happened in a non-wx
5564 MSWInitAnyKeyEvent(wxKeyEvent
& event
,
5567 const wxWindowBase
*win
/* may be NULL */)
5571 event
.SetId(win
->GetId());
5572 event
.SetEventObject(const_cast<wxWindowBase
*>(win
));
5574 else // No associated window.
5576 // Use wxID_ANY for compatibility with the old code even if wxID_NONE
5577 // would arguably make more sense.
5578 event
.SetId(wxID_ANY
);
5581 event
.m_shiftDown
= wxIsShiftDown();
5582 event
.m_controlDown
= wxIsCtrlDown();
5583 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5585 event
.m_rawCode
= (wxUint32
) wParam
;
5586 event
.m_rawFlags
= (wxUint32
) lParam
;
5588 event
.SetTimestamp(::GetMessageTime());
5591 // Event coordinates must be in window client coordinates system which
5592 // doesn't make sense if there is no window.
5594 // We could use screen coordinates for such events but this would make the
5595 // logic of the event handlers more complicated: you'd need to test for the
5596 // event object and interpret the coordinates differently according to
5597 // whether it's NULL or not so unless somebody really asks for this let's
5598 // just avoid the issue.
5601 const wxPoint mousePos
= win
->ScreenToClient(wxGetMousePosition());
5602 event
.m_x
= mousePos
.x
;
5603 event
.m_y
= mousePos
.y
;
5607 } // anonymous namespace
5610 wxWindowMSW::InitAnyKeyEvent(wxKeyEvent
& event
,
5612 WXLPARAM lParam
) const
5614 MSWInitAnyKeyEvent(event
, wParam
, lParam
, this);
5618 wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5620 WXLPARAM lParam
) const
5622 // Catch any attempts to use this with WM_CHAR, it wouldn't work because
5623 // wParam is supposed to be a virtual key and not a character here.
5624 wxASSERT_MSG( evType
!= wxEVT_CHAR
&& evType
!= wxEVT_CHAR_HOOK
,
5625 "CreateKeyEvent() can't be used for char events" );
5627 wxKeyEvent
event(evType
);
5628 InitAnyKeyEvent(event
, wParam
, lParam
);
5630 event
.m_keyCode
= wxMSWKeyboard::VKToWX
5636 #endif // wxUSE_UNICODE
5642 // isASCII is true only when we're called from WM_CHAR handler and not from
5644 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
)
5646 wxKeyEvent
event(wxEVT_CHAR
);
5647 InitAnyKeyEvent(event
, wParam
, lParam
);
5650 // TODO: wParam uses UTF-16 so this is incorrect for characters outside of
5651 // the BMP, we should use WM_UNICHAR to handle them.
5652 event
.m_uniChar
= wParam
;
5653 #endif // wxUSE_UNICODE
5655 // Set non-Unicode key code too for compatibility if possible.
5656 if ( wParam
< 0x80 )
5658 // It's an ASCII character, no need to translate it.
5659 event
.m_keyCode
= wParam
;
5663 // Check if this key can be represented (as a single character) in the
5665 const wchar_t wc
= wParam
;
5667 if ( wxConvLibc
.FromWChar(&ch
, 1, &wc
, 1) != wxCONV_FAILED
)
5669 // For compatibility continue to provide the key code in this field
5670 // even though using GetUnicodeKey() is recommended now.
5671 event
.m_keyCode
= static_cast<unsigned char>(ch
);
5673 //else: Key can't be represented in the current locale, leave m_keyCode
5674 // as WXK_NONE and use GetUnicodeKey() to access the character.
5677 // the alphanumeric keys produced by pressing AltGr+something on European
5678 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5679 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5680 // alphanumeric, so pretend that there are no modifiers at all (the
5681 // KEY_DOWN event would still have the correct modifiers if they're really
5683 if ( event
.m_controlDown
&& event
.m_altDown
&&
5684 (event
.m_keyCode
>= 32 && event
.m_keyCode
< 256) )
5686 event
.m_controlDown
=
5687 event
.m_altDown
= false;
5690 return HandleWindowEvent(event
);
5693 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5695 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, wParam
, lParam
));
5696 return HandleWindowEvent(event
);
5699 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5701 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, wParam
, lParam
));
5702 return HandleWindowEvent(event
);
5706 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5707 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5709 // FIXME: implement GetMenuItemCount for WinCE, possibly
5710 // in terms of GetMenuItemInfo
5712 const HMENU hmenu
= (HMENU
)lParam
;
5716 mii
.cbSize
= sizeof(MENUITEMINFO
);
5718 // we could use MIIM_FTYPE here as we only need to know if the item is
5719 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5720 // MIIM_FTYPE is not supported under Win95
5721 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5723 // find if we have this letter in any owner drawn item
5724 const int count
= ::GetMenuItemCount(hmenu
);
5725 for ( int i
= 0; i
< count
; i
++ )
5727 // previous loop iteration could modify it, reset it back before
5728 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5731 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5733 if ( mii
.fType
== MFT_OWNERDRAW
)
5735 // dwItemData member of the MENUITEMINFO is a
5736 // pointer to the associated wxMenuItem -- see the
5737 // menu creation code
5738 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5740 const wxString
label(item
->GetItemLabel());
5741 const wxChar
*p
= wxStrchr(label
.wx_str(), wxT('&'));
5744 if ( *p
== wxT('&') )
5746 // this is not the accel char, find the real one
5747 p
= wxStrchr(p
+ 1, wxT('&'));
5749 else // got the accel char
5751 // FIXME-UNICODE: this comparison doesn't risk to work
5752 // for non ASCII accelerator characters I'm afraid, but
5754 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5760 // this one doesn't match
5767 else // failed to get the menu text?
5769 // it's not fatal, so don't show error, but still log it
5770 wxLogLastError(wxT("GetMenuItemInfo"));
5777 #endif // wxUSE_MENUS
5779 bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg
)
5781 const wxEventType type
= nMsg
== WM_CUT
? wxEVT_COMMAND_TEXT_CUT
5782 : nMsg
== WM_COPY
? wxEVT_COMMAND_TEXT_COPY
5783 : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE
;
5784 wxClipboardTextEvent
evt(type
, GetId());
5786 evt
.SetEventObject(this);
5788 return HandleWindowEvent(evt
);
5791 // ---------------------------------------------------------------------------
5793 // ---------------------------------------------------------------------------
5795 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5799 if ( flags
& JOY_BUTTON1CHG
)
5800 change
= wxJOY_BUTTON1
;
5801 if ( flags
& JOY_BUTTON2CHG
)
5802 change
= wxJOY_BUTTON2
;
5803 if ( flags
& JOY_BUTTON3CHG
)
5804 change
= wxJOY_BUTTON3
;
5805 if ( flags
& JOY_BUTTON4CHG
)
5806 change
= wxJOY_BUTTON4
;
5809 if ( flags
& JOY_BUTTON1
)
5810 buttons
|= wxJOY_BUTTON1
;
5811 if ( flags
& JOY_BUTTON2
)
5812 buttons
|= wxJOY_BUTTON2
;
5813 if ( flags
& JOY_BUTTON3
)
5814 buttons
|= wxJOY_BUTTON3
;
5815 if ( flags
& JOY_BUTTON4
)
5816 buttons
|= wxJOY_BUTTON4
;
5818 // the event ids aren't consecutive so we can't use table based lookup
5820 wxEventType eventType
;
5825 eventType
= wxEVT_JOY_MOVE
;
5830 eventType
= wxEVT_JOY_MOVE
;
5835 eventType
= wxEVT_JOY_ZMOVE
;
5840 eventType
= wxEVT_JOY_ZMOVE
;
5843 case MM_JOY1BUTTONDOWN
:
5845 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5848 case MM_JOY2BUTTONDOWN
:
5850 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5853 case MM_JOY1BUTTONUP
:
5855 eventType
= wxEVT_JOY_BUTTON_UP
;
5858 case MM_JOY2BUTTONUP
:
5860 eventType
= wxEVT_JOY_BUTTON_UP
;
5864 wxFAIL_MSG(wxT("no such joystick event"));
5869 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5870 event
.SetPosition(wxPoint(x
, y
));
5871 event
.SetEventObject(this);
5873 return HandleWindowEvent(event
);
5883 // ---------------------------------------------------------------------------
5885 // ---------------------------------------------------------------------------
5887 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5888 WXWORD pos
, WXHWND control
)
5890 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5892 wxWindow
*child
= wxFindWinFromHandle(control
);
5894 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5897 wxScrollWinEvent event
;
5898 event
.SetPosition(pos
);
5899 event
.SetOrientation(orientation
);
5900 event
.SetEventObject(this);
5905 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5909 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5913 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5917 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5921 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5925 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5928 case SB_THUMBPOSITION
:
5930 // under Win32, the scrollbar range and position are 32 bit integers,
5931 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5932 // explicitly query the scrollbar for the correct position (this must
5933 // be done only for these two SB_ events as they are the only one
5934 // carrying the scrollbar position)
5936 WinStruct
<SCROLLINFO
> scrollInfo
;
5937 scrollInfo
.fMask
= SIF_TRACKPOS
;
5939 if ( !::GetScrollInfo(GetHwnd(),
5940 WXOrientToSB(orientation
),
5943 // Not necessarily an error, if there are no scrollbars yet.
5944 // wxLogLastError(wxT("GetScrollInfo"));
5947 event
.SetPosition(scrollInfo
.nTrackPos
);
5950 event
.SetEventType( wParam
== SB_THUMBPOSITION
5951 ? wxEVT_SCROLLWIN_THUMBRELEASE
5952 : wxEVT_SCROLLWIN_THUMBTRACK
);
5959 return HandleWindowEvent(event
);
5962 // ----------------------------------------------------------------------------
5963 // custom message handlers
5964 // ----------------------------------------------------------------------------
5967 wxWindowMSW::MSWRegisterMessageHandler(int msg
, MSWMessageHandler handler
)
5969 wxCHECK_MSG( gs_messageHandlers
.find(msg
) == gs_messageHandlers
.end(),
5970 false, wxT("registering handler for the same message twice") );
5972 gs_messageHandlers
[msg
] = handler
;
5977 wxWindowMSW::MSWUnregisterMessageHandler(int msg
, MSWMessageHandler handler
)
5979 const MSWMessageHandlers::iterator i
= gs_messageHandlers
.find(msg
);
5980 wxCHECK_RET( i
!= gs_messageHandlers
.end() && i
->second
== handler
,
5981 wxT("unregistering non-registered handler?") );
5983 gs_messageHandlers
.erase(i
);
5986 // ===========================================================================
5988 // ===========================================================================
5990 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5993 HDC dc
= ::GetDC((HWND
) wnd
);
5996 // the_font.UseResource();
5997 // the_font.RealizeResource();
5998 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
6000 was
= (HFONT
) SelectObject(dc
,fnt
);
6002 GetTextMetrics(dc
, &tm
);
6005 SelectObject(dc
,was
);
6007 ReleaseDC((HWND
)wnd
, dc
);
6010 *x
= tm
.tmAveCharWidth
;
6012 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
6014 // the_font.ReleaseResource();
6017 // ----------------------------------------------------------------------------
6019 // ----------------------------------------------------------------------------
6021 namespace wxMSWKeyboard
6027 // use the "extended" bit of lParam to distinguish extended keys from normal
6028 // keys as the same virtual key code is sent for both by Windows
6030 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
6032 // except that if lParam is 0, it means we don't have real lParam from
6033 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
6034 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
6035 // non-numpad (hence extended) key as this is a more common case
6036 return !lParam
|| (HIWORD(lParam
) & KF_EXTENDED
) ? keyExtended
: keyNormal
;
6039 // this array contains the Windows virtual key codes which map one to one to
6040 // WXK_xxx constants and is used in wxMSWKeyboard::VKToWX/WXToVK() below
6042 // note that keys having a normal and numpad version (e.g. WXK_HOME and
6043 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
6044 const struct wxKeyMapping
6048 } gs_specialKeys
[] =
6050 { VK_CANCEL
, WXK_CANCEL
},
6051 { VK_BACK
, WXK_BACK
},
6052 { VK_TAB
, WXK_TAB
},
6053 { VK_CLEAR
, WXK_CLEAR
},
6054 { VK_SHIFT
, WXK_SHIFT
},
6055 { VK_CONTROL
, WXK_CONTROL
},
6056 { VK_MENU
, WXK_ALT
},
6057 { VK_PAUSE
, WXK_PAUSE
},
6058 { VK_CAPITAL
, WXK_CAPITAL
},
6059 { VK_SPACE
, WXK_SPACE
},
6060 { VK_ESCAPE
, WXK_ESCAPE
},
6061 { VK_SELECT
, WXK_SELECT
},
6062 { VK_PRINT
, WXK_PRINT
},
6063 { VK_EXECUTE
, WXK_EXECUTE
},
6064 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
6065 { VK_HELP
, WXK_HELP
},
6067 { VK_NUMPAD0
, WXK_NUMPAD0
},
6068 { VK_NUMPAD1
, WXK_NUMPAD1
},
6069 { VK_NUMPAD2
, WXK_NUMPAD2
},
6070 { VK_NUMPAD3
, WXK_NUMPAD3
},
6071 { VK_NUMPAD4
, WXK_NUMPAD4
},
6072 { VK_NUMPAD5
, WXK_NUMPAD5
},
6073 { VK_NUMPAD6
, WXK_NUMPAD6
},
6074 { VK_NUMPAD7
, WXK_NUMPAD7
},
6075 { VK_NUMPAD8
, WXK_NUMPAD8
},
6076 { VK_NUMPAD9
, WXK_NUMPAD9
},
6077 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
6078 { VK_ADD
, WXK_NUMPAD_ADD
},
6079 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
6080 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
6081 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
6092 { VK_F10
, WXK_F10
},
6093 { VK_F11
, WXK_F11
},
6094 { VK_F12
, WXK_F12
},
6095 { VK_F13
, WXK_F13
},
6096 { VK_F14
, WXK_F14
},
6097 { VK_F15
, WXK_F15
},
6098 { VK_F16
, WXK_F16
},
6099 { VK_F17
, WXK_F17
},
6100 { VK_F18
, WXK_F18
},
6101 { VK_F19
, WXK_F19
},
6102 { VK_F20
, WXK_F20
},
6103 { VK_F21
, WXK_F21
},
6104 { VK_F22
, WXK_F22
},
6105 { VK_F23
, WXK_F23
},
6106 { VK_F24
, WXK_F24
},
6108 { VK_NUMLOCK
, WXK_NUMLOCK
},
6109 { VK_SCROLL
, WXK_SCROLL
},
6112 { VK_LWIN
, WXK_WINDOWS_LEFT
},
6113 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
6114 { VK_APPS
, WXK_WINDOWS_MENU
},
6115 #endif // VK_APPS defined
6118 } // anonymous namespace
6120 int VKToWX(WXWORD vk
, WXLPARAM lParam
, wchar_t *uc
)
6124 // check the table first
6125 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6127 if ( gs_specialKeys
[n
].vk
== vk
)
6129 wxk
= gs_specialKeys
[n
].wxk
;
6130 if ( wxk
< WXK_START
)
6132 // Unicode code for this key is the same as its ASCII code.
6141 // keys requiring special handling
6155 // MapVirtualKey() returns 0 if it fails to convert the virtual
6156 // key which nicely corresponds to our WXK_NONE.
6157 wxk
= ::MapVirtualKey(vk
, MAPVK_VK_TO_CHAR
);
6159 if ( HIWORD(wxk
) & 0x8000 )
6161 // It's a dead key and we don't return anything at all for them
6162 // as we simply don't have any way to indicate the difference
6163 // between e.g. a normal "'" and "'" as a dead key -- and
6164 // generating the same events for them just doesn't seem like a
6169 // In any case return this as a Unicode character value.
6173 // For compatibility with the old non-Unicode code we continue
6174 // returning key codes for Latin-1 characters directly
6175 // (normally it would really only make sense to do it for the
6176 // ASCII characters, not Latin-1 ones).
6179 // But for anything beyond this we can only return the key
6180 // value as a real Unicode character, not a wxKeyCode
6181 // because this enum values clash with Unicode characters
6182 // (e.g. WXK_LBUTTON also happens to be U+012C a.k.a.
6183 // "LATIN CAPITAL LETTER I WITH BREVE").
6188 // handle extended keys
6190 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
6194 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
6198 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
6202 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
6206 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
6210 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
6214 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
6218 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
6222 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
6226 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
6230 // don't use ChooseNormalOrExtended() here as the keys are reversed
6231 // here: numpad enter is the extended one
6232 wxk
= HIWORD(lParam
) & KF_EXTENDED
? WXK_NUMPAD_ENTER
: WXK_RETURN
;
6236 if ( (vk
>= '0' && vk
<= '9') || (vk
>= 'A' && vk
<= 'Z') )
6238 // A simple alphanumeric key and the values of them coincide in
6239 // Windows and wx for both ASCII and Unicode codes.
6242 else // Something we simply don't know about at all.
6254 WXWORD
WXToVK(int wxk
, bool *isExtended
)
6256 // check the table first
6257 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6259 if ( gs_specialKeys
[n
].wxk
== wxk
)
6261 // All extended keys (i.e. non-numpad versions of the keys that
6262 // exist both in the numpad and outside of it) are dealt with
6265 *isExtended
= false;
6267 return gs_specialKeys
[n
].vk
;
6271 // and then check for special keys not included in the table
6272 bool extended
= false;
6278 case WXK_NUMPAD_PAGEUP
:
6284 case WXK_NUMPAD_PAGEDOWN
:
6290 case WXK_NUMPAD_END
:
6296 case WXK_NUMPAD_HOME
:
6302 case WXK_NUMPAD_LEFT
:
6314 case WXK_NUMPAD_RIGHT
:
6320 case WXK_NUMPAD_DOWN
:
6326 case WXK_NUMPAD_INSERT
:
6332 case WXK_NUMPAD_DELETE
:
6337 // no VkKeyScan() under CE unfortunately, we need to test how does
6338 // it handle OEM keys
6340 // check to see if its one of the OEM key codes.
6341 BYTE vks
= LOBYTE(VkKeyScan(wxk
));
6347 #endif // !__WXWINCE__
6354 *isExtended
= extended
;
6359 } // namespace wxMSWKeyboard
6361 // small helper for wxGetKeyState() and wxGetMouseState()
6362 static inline bool wxIsKeyDown(WXWORD vk
)
6364 // SM_SWAPBUTTON is not available under CE, so don't swap buttons there
6365 #ifdef SM_SWAPBUTTON
6366 if ( vk
== VK_LBUTTON
|| vk
== VK_RBUTTON
)
6368 if ( ::GetSystemMetrics(SM_SWAPBUTTON
) )
6370 if ( vk
== VK_LBUTTON
)
6372 else // vk == VK_RBUTTON
6376 #endif // SM_SWAPBUTTON
6378 // the low order bit indicates whether the key was pressed since the last
6379 // call and the high order one indicates whether it is down right now and
6380 // we only want that one
6381 return (GetAsyncKeyState(vk
) & (1<<15)) != 0;
6384 bool wxGetKeyState(wxKeyCode key
)
6386 // although this does work under Windows, it is not supported under other
6387 // platforms so don't allow it, you must use wxGetMouseState() instead
6388 wxASSERT_MSG( key
!= VK_LBUTTON
&&
6389 key
!= VK_RBUTTON
&&
6391 wxT("can't use wxGetKeyState() for mouse buttons") );
6393 const WXWORD vk
= wxMSWKeyboard::WXToVK(key
);
6395 // if the requested key is a LED key, return true if the led is pressed
6396 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
6398 // low order bit means LED is highlighted and high order one means the
6399 // key is down; for compatibility with the other ports return true if
6400 // either one is set
6401 return GetKeyState(vk
) != 0;
6406 return wxIsKeyDown(vk
);
6411 wxMouseState
wxGetMouseState()
6415 GetCursorPos( &pt
);
6419 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
6420 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
6421 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
6422 #ifdef wxHAS_XBUTTON
6423 ms
.SetAux1Down(wxIsKeyDown(VK_XBUTTON1
));
6424 ms
.SetAux2Down(wxIsKeyDown(VK_XBUTTON2
));
6425 #endif // wxHAS_XBUTTON
6427 ms
.SetControlDown(wxIsCtrlDown ());
6428 ms
.SetShiftDown (wxIsShiftDown());
6429 ms
.SetAltDown (wxIsAltDown ());
6430 // ms.SetMetaDown();
6436 wxWindow
*wxGetActiveWindow()
6438 HWND hWnd
= GetActiveWindow();
6441 return wxFindWinFromHandle(hWnd
);
6446 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
6448 HWND hwnd
= (HWND
)hWnd
;
6450 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
6451 // by code in msw/radiobox.cpp), for all the others we just search up the
6453 wxWindow
*win
= NULL
;
6456 win
= wxFindWinFromHandle(hwnd
);
6459 #if wxUSE_RADIOBOX && !defined(__WXUNIVERSAL__)
6460 // native radiobuttons return DLGC_RADIOBUTTON here and for any
6461 // wxWindow class which overrides WM_GETDLGCODE processing to
6462 // do it as well, win would be already non NULL
6463 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
6465 win
= wxRadioBox::GetFromRadioButtonHWND(hwnd
);
6467 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
6468 #endif // wxUSE_RADIOBOX
6470 // spin control text buddy window should be mapped to spin ctrl
6471 // itself so try it too
6472 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
6475 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
6477 #endif // wxUSE_SPINCTRL
6481 while ( hwnd
&& !win
)
6483 // this is a really ugly hack needed to avoid mistakenly returning the
6484 // parent frame wxWindow for the find/replace modeless dialog HWND -
6485 // this, in turn, is needed to call IsDialogMessage() from
6486 // wxApp::ProcessMessage() as for this we must return NULL from here
6488 // FIXME: this is clearly not the best way to do it but I think we'll
6489 // need to change HWND <-> wxWindow code more heavily than I can
6490 // do it now to fix it
6491 #ifndef __WXMICROWIN__
6492 if ( ::GetWindow(hwnd
, GW_OWNER
) )
6494 // it's a dialog box, don't go upwards
6499 hwnd
= ::GetParent(hwnd
);
6500 win
= wxFindWinFromHandle(hwnd
);
6506 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
6508 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
6509 // in active frames and dialogs, regardless of where the focus is.
6510 static HHOOK wxTheKeyboardHook
= 0;
6513 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
6515 DWORD hiWord
= HIWORD(lParam
);
6516 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
6519 int id
= wxMSWKeyboard::VKToWX(wParam
, lParam
, &uc
);
6521 // Don't intercept keyboard entry (notably Escape) if a modal window
6522 // (not managed by wx, e.g. IME one) is currently opened as more often
6523 // than not it needs all the keys for itself.
6525 // Also don't catch it if a window currently captures the mouse as
6526 // Escape is normally used to release the mouse capture and if you
6527 // really need to catch all the keys in the window that has mouse
6528 // capture it can be easily done in its own EVT_CHAR handler as it is
6529 // certain to have focus while it has the capture.
6530 if ( !gs_modalEntryWindowCount
&& !::GetCapture() )
6534 || static_cast<int>(uc
) != WXK_NONE
6535 #endif // wxUSE_UNICODE
6538 const wxWindow
* const win
= wxGetActiveWindow();
6540 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
6541 MSWInitAnyKeyEvent(event
, wParam
, lParam
, win
);
6543 event
.m_keyCode
= id
;
6545 event
.m_uniChar
= uc
;
6546 #endif // wxUSE_UNICODE
6548 wxEvtHandler
* const handler
= win
? win
->GetEventHandler()
6551 if ( handler
&& handler
->ProcessEvent(event
) )
6560 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
6563 void wxSetKeyboardHook(bool doIt
)
6567 wxTheKeyboardHook
= ::SetWindowsHookEx
6570 (HOOKPROC
)wxKeyboardHook
,
6571 NULL
, // must be NULL for process hook
6572 ::GetCurrentThreadId()
6574 if ( !wxTheKeyboardHook
)
6576 wxLogLastError(wxT("SetWindowsHookEx(wxKeyboardHook)"));
6581 if ( wxTheKeyboardHook
)
6582 ::UnhookWindowsHookEx(wxTheKeyboardHook
);
6586 #endif // !__WXMICROWIN__
6588 #if wxDEBUG_LEVEL >= 2
6589 const wxChar
*wxGetMessageName(int message
)
6593 case 0x0000: return wxT("WM_NULL");
6594 case 0x0001: return wxT("WM_CREATE");
6595 case 0x0002: return wxT("WM_DESTROY");
6596 case 0x0003: return wxT("WM_MOVE");
6597 case 0x0005: return wxT("WM_SIZE");
6598 case 0x0006: return wxT("WM_ACTIVATE");
6599 case 0x0007: return wxT("WM_SETFOCUS");
6600 case 0x0008: return wxT("WM_KILLFOCUS");
6601 case 0x000A: return wxT("WM_ENABLE");
6602 case 0x000B: return wxT("WM_SETREDRAW");
6603 case 0x000C: return wxT("WM_SETTEXT");
6604 case 0x000D: return wxT("WM_GETTEXT");
6605 case 0x000E: return wxT("WM_GETTEXTLENGTH");
6606 case 0x000F: return wxT("WM_PAINT");
6607 case 0x0010: return wxT("WM_CLOSE");
6608 case 0x0011: return wxT("WM_QUERYENDSESSION");
6609 case 0x0012: return wxT("WM_QUIT");
6610 case 0x0013: return wxT("WM_QUERYOPEN");
6611 case 0x0014: return wxT("WM_ERASEBKGND");
6612 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
6613 case 0x0016: return wxT("WM_ENDSESSION");
6614 case 0x0017: return wxT("WM_SYSTEMERROR");
6615 case 0x0018: return wxT("WM_SHOWWINDOW");
6616 case 0x0019: return wxT("WM_CTLCOLOR");
6617 case 0x001A: return wxT("WM_WININICHANGE");
6618 case 0x001B: return wxT("WM_DEVMODECHANGE");
6619 case 0x001C: return wxT("WM_ACTIVATEAPP");
6620 case 0x001D: return wxT("WM_FONTCHANGE");
6621 case 0x001E: return wxT("WM_TIMECHANGE");
6622 case 0x001F: return wxT("WM_CANCELMODE");
6623 case 0x0020: return wxT("WM_SETCURSOR");
6624 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6625 case 0x0022: return wxT("WM_CHILDACTIVATE");
6626 case 0x0023: return wxT("WM_QUEUESYNC");
6627 case 0x0024: return wxT("WM_GETMINMAXINFO");
6628 case 0x0026: return wxT("WM_PAINTICON");
6629 case 0x0027: return wxT("WM_ICONERASEBKGND");
6630 case 0x0028: return wxT("WM_NEXTDLGCTL");
6631 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6632 case 0x002B: return wxT("WM_DRAWITEM");
6633 case 0x002C: return wxT("WM_MEASUREITEM");
6634 case 0x002D: return wxT("WM_DELETEITEM");
6635 case 0x002E: return wxT("WM_VKEYTOITEM");
6636 case 0x002F: return wxT("WM_CHARTOITEM");
6637 case 0x0030: return wxT("WM_SETFONT");
6638 case 0x0031: return wxT("WM_GETFONT");
6639 case 0x0037: return wxT("WM_QUERYDRAGICON");
6640 case 0x0039: return wxT("WM_COMPAREITEM");
6641 case 0x0041: return wxT("WM_COMPACTING");
6642 case 0x0044: return wxT("WM_COMMNOTIFY");
6643 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6644 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6645 case 0x0048: return wxT("WM_POWER");
6647 case 0x004A: return wxT("WM_COPYDATA");
6648 case 0x004B: return wxT("WM_CANCELJOURNAL");
6649 case 0x004E: return wxT("WM_NOTIFY");
6650 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6651 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6652 case 0x0052: return wxT("WM_TCARD");
6653 case 0x0053: return wxT("WM_HELP");
6654 case 0x0054: return wxT("WM_USERCHANGED");
6655 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6656 case 0x007B: return wxT("WM_CONTEXTMENU");
6657 case 0x007C: return wxT("WM_STYLECHANGING");
6658 case 0x007D: return wxT("WM_STYLECHANGED");
6659 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6660 case 0x007F: return wxT("WM_GETICON");
6661 case 0x0080: return wxT("WM_SETICON");
6663 case 0x0081: return wxT("WM_NCCREATE");
6664 case 0x0082: return wxT("WM_NCDESTROY");
6665 case 0x0083: return wxT("WM_NCCALCSIZE");
6666 case 0x0084: return wxT("WM_NCHITTEST");
6667 case 0x0085: return wxT("WM_NCPAINT");
6668 case 0x0086: return wxT("WM_NCACTIVATE");
6669 case 0x0087: return wxT("WM_GETDLGCODE");
6670 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6671 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6672 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6673 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6674 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6675 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6676 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6677 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6678 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6679 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6681 case 0x00B0: return wxT("EM_GETSEL");
6682 case 0x00B1: return wxT("EM_SETSEL");
6683 case 0x00B2: return wxT("EM_GETRECT");
6684 case 0x00B3: return wxT("EM_SETRECT");
6685 case 0x00B4: return wxT("EM_SETRECTNP");
6686 case 0x00B5: return wxT("EM_SCROLL");
6687 case 0x00B6: return wxT("EM_LINESCROLL");
6688 case 0x00B7: return wxT("EM_SCROLLCARET");
6689 case 0x00B8: return wxT("EM_GETMODIFY");
6690 case 0x00B9: return wxT("EM_SETMODIFY");
6691 case 0x00BA: return wxT("EM_GETLINECOUNT");
6692 case 0x00BB: return wxT("EM_LINEINDEX");
6693 case 0x00BC: return wxT("EM_SETHANDLE");
6694 case 0x00BD: return wxT("EM_GETHANDLE");
6695 case 0x00BE: return wxT("EM_GETTHUMB");
6696 case 0x00C1: return wxT("EM_LINELENGTH");
6697 case 0x00C2: return wxT("EM_REPLACESEL");
6698 case 0x00C4: return wxT("EM_GETLINE");
6699 case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */
6700 case 0x00C6: return wxT("EM_CANUNDO");
6701 case 0x00C7: return wxT("EM_UNDO");
6702 case 0x00C8: return wxT("EM_FMTLINES");
6703 case 0x00C9: return wxT("EM_LINEFROMCHAR");
6704 case 0x00CB: return wxT("EM_SETTABSTOPS");
6705 case 0x00CC: return wxT("EM_SETPASSWORDCHAR");
6706 case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER");
6707 case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE");
6708 case 0x00CF: return wxT("EM_SETREADONLY");
6709 case 0x00D0: return wxT("EM_SETWORDBREAKPROC");
6710 case 0x00D1: return wxT("EM_GETWORDBREAKPROC");
6711 case 0x00D2: return wxT("EM_GETPASSWORDCHAR");
6712 case 0x00D3: return wxT("EM_SETMARGINS");
6713 case 0x00D4: return wxT("EM_GETMARGINS");
6714 case 0x00D5: return wxT("EM_GETLIMITTEXT");
6715 case 0x00D6: return wxT("EM_POSFROMCHAR");
6716 case 0x00D7: return wxT("EM_CHARFROMPOS");
6717 case 0x00D8: return wxT("EM_SETIMESTATUS");
6718 case 0x00D9: return wxT("EM_GETIMESTATUS");
6720 case 0x0100: return wxT("WM_KEYDOWN");
6721 case 0x0101: return wxT("WM_KEYUP");
6722 case 0x0102: return wxT("WM_CHAR");
6723 case 0x0103: return wxT("WM_DEADCHAR");
6724 case 0x0104: return wxT("WM_SYSKEYDOWN");
6725 case 0x0105: return wxT("WM_SYSKEYUP");
6726 case 0x0106: return wxT("WM_SYSCHAR");
6727 case 0x0107: return wxT("WM_SYSDEADCHAR");
6728 case 0x0108: return wxT("WM_KEYLAST");
6730 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6731 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6732 case 0x010F: return wxT("WM_IME_COMPOSITION");
6734 case 0x0110: return wxT("WM_INITDIALOG");
6735 case 0x0111: return wxT("WM_COMMAND");
6736 case 0x0112: return wxT("WM_SYSCOMMAND");
6737 case 0x0113: return wxT("WM_TIMER");
6738 case 0x0114: return wxT("WM_HSCROLL");
6739 case 0x0115: return wxT("WM_VSCROLL");
6740 case 0x0116: return wxT("WM_INITMENU");
6741 case 0x0117: return wxT("WM_INITMENUPOPUP");
6742 case 0x011F: return wxT("WM_MENUSELECT");
6743 case 0x0120: return wxT("WM_MENUCHAR");
6744 case 0x0121: return wxT("WM_ENTERIDLE");
6746 case 0x0127: return wxT("WM_CHANGEUISTATE");
6747 case 0x0128: return wxT("WM_UPDATEUISTATE");
6748 case 0x0129: return wxT("WM_QUERYUISTATE");
6750 case 0x0132: return wxT("WM_CTLCOLORMSGBOX");
6751 case 0x0133: return wxT("WM_CTLCOLOREDIT");
6752 case 0x0134: return wxT("WM_CTLCOLORLISTBOX");
6753 case 0x0135: return wxT("WM_CTLCOLORBTN");
6754 case 0x0136: return wxT("WM_CTLCOLORDLG");
6755 case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR");
6756 case 0x0138: return wxT("WM_CTLCOLORSTATIC");
6757 case 0x01E1: return wxT("MN_GETHMENU");
6759 case 0x0200: return wxT("WM_MOUSEMOVE");
6760 case 0x0201: return wxT("WM_LBUTTONDOWN");
6761 case 0x0202: return wxT("WM_LBUTTONUP");
6762 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6763 case 0x0204: return wxT("WM_RBUTTONDOWN");
6764 case 0x0205: return wxT("WM_RBUTTONUP");
6765 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6766 case 0x0207: return wxT("WM_MBUTTONDOWN");
6767 case 0x0208: return wxT("WM_MBUTTONUP");
6768 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6769 case 0x020A: return wxT("WM_MOUSEWHEEL");
6770 case 0x020B: return wxT("WM_XBUTTONDOWN");
6771 case 0x020C: return wxT("WM_XBUTTONUP");
6772 case 0x020D: return wxT("WM_XBUTTONDBLCLK");
6773 case 0x0210: return wxT("WM_PARENTNOTIFY");
6774 case 0x0211: return wxT("WM_ENTERMENULOOP");
6775 case 0x0212: return wxT("WM_EXITMENULOOP");
6777 case 0x0213: return wxT("WM_NEXTMENU");
6778 case 0x0214: return wxT("WM_SIZING");
6779 case 0x0215: return wxT("WM_CAPTURECHANGED");
6780 case 0x0216: return wxT("WM_MOVING");
6781 case 0x0218: return wxT("WM_POWERBROADCAST");
6782 case 0x0219: return wxT("WM_DEVICECHANGE");
6784 case 0x0220: return wxT("WM_MDICREATE");
6785 case 0x0221: return wxT("WM_MDIDESTROY");
6786 case 0x0222: return wxT("WM_MDIACTIVATE");
6787 case 0x0223: return wxT("WM_MDIRESTORE");
6788 case 0x0224: return wxT("WM_MDINEXT");
6789 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6790 case 0x0226: return wxT("WM_MDITILE");
6791 case 0x0227: return wxT("WM_MDICASCADE");
6792 case 0x0228: return wxT("WM_MDIICONARRANGE");
6793 case 0x0229: return wxT("WM_MDIGETACTIVE");
6794 case 0x0230: return wxT("WM_MDISETMENU");
6795 case 0x0233: return wxT("WM_DROPFILES");
6797 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6798 case 0x0282: return wxT("WM_IME_NOTIFY");
6799 case 0x0283: return wxT("WM_IME_CONTROL");
6800 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6801 case 0x0285: return wxT("WM_IME_SELECT");
6802 case 0x0286: return wxT("WM_IME_CHAR");
6803 case 0x0290: return wxT("WM_IME_KEYDOWN");
6804 case 0x0291: return wxT("WM_IME_KEYUP");
6806 case 0x02A0: return wxT("WM_NCMOUSEHOVER");
6807 case 0x02A1: return wxT("WM_MOUSEHOVER");
6808 case 0x02A2: return wxT("WM_NCMOUSELEAVE");
6809 case 0x02A3: return wxT("WM_MOUSELEAVE");
6811 case 0x0300: return wxT("WM_CUT");
6812 case 0x0301: return wxT("WM_COPY");
6813 case 0x0302: return wxT("WM_PASTE");
6814 case 0x0303: return wxT("WM_CLEAR");
6815 case 0x0304: return wxT("WM_UNDO");
6816 case 0x0305: return wxT("WM_RENDERFORMAT");
6817 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6818 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6819 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6820 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6821 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6822 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6823 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6824 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6825 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6826 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6827 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6828 case 0x0311: return wxT("WM_PALETTECHANGED");
6829 case 0x0312: return wxT("WM_HOTKEY");
6831 case 0x0317: return wxT("WM_PRINT");
6832 case 0x0318: return wxT("WM_PRINTCLIENT");
6834 // common controls messages - although they're not strictly speaking
6835 // standard, it's nice to decode them nevertheless
6838 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6839 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6840 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6841 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6842 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6843 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6844 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6845 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6846 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6847 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6848 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6849 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6850 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6851 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6852 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6853 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6854 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6855 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6856 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6857 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6858 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6859 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6860 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6861 case 0x1000 + 18: return wxT("LVM_HITTEST");
6862 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6863 case 0x1000 + 20: return wxT("LVM_SCROLL");
6864 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6865 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6866 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6867 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6868 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6869 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6870 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6871 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6872 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6873 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6874 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6875 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6876 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6877 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6878 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6879 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6880 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6881 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6882 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6883 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6884 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6885 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6886 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6887 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6888 case 0x1000 + 42: return wxT("LVM_UPDATE");
6889 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6890 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6891 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6892 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6893 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6894 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6895 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6896 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6897 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6898 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6899 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6900 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6901 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6902 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6903 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6904 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6905 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6906 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6907 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6908 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6909 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6910 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6911 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6912 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6913 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6914 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6917 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6918 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6919 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6920 case 0x1100 + 2: return wxT("TVM_EXPAND");
6921 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6922 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6923 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6924 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6925 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6926 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6927 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6928 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6929 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6930 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6931 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6932 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6933 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6934 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6935 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6936 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6937 case 0x1100 + 17: return wxT("TVM_HITTEST");
6938 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6939 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6940 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6941 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6942 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6943 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6944 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6945 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6946 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6949 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6950 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6951 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6952 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6953 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6954 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6955 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6956 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6957 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6958 case 0x1200 + 6: return wxT("HDM_HITTEST");
6959 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6960 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6961 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6962 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6963 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6964 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6965 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6966 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6969 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6970 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6971 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6972 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6973 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6974 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6975 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6976 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6977 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6978 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6979 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6980 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6981 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6982 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6983 case 0x1300 + 13: return wxT("TCM_HITTEST");
6984 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6985 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6986 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6987 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6988 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6989 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6990 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6991 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6992 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6993 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6994 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6995 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6998 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6999 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
7000 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
7001 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
7002 case WM_USER
+5: return wxT("TB_INDETERMINATE");
7003 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
7004 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
7005 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
7006 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
7007 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
7008 case WM_USER
+17: return wxT("TB_SETSTATE");
7009 case WM_USER
+18: return wxT("TB_GETSTATE");
7010 case WM_USER
+19: return wxT("TB_ADDBITMAP");
7011 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
7012 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
7013 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
7014 case WM_USER
+23: return wxT("TB_GETBUTTON");
7015 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
7016 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
7017 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
7018 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
7019 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
7020 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
7021 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
7022 case WM_USER
+29: return wxT("TB_GETITEMRECT");
7023 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
7024 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
7025 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
7026 case WM_USER
+33: return wxT("TB_AUTOSIZE");
7027 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
7028 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
7029 case WM_USER
+37: return wxT("TB_SETPARENT");
7030 case WM_USER
+39: return wxT("TB_SETROWS");
7031 case WM_USER
+40: return wxT("TB_GETROWS");
7032 case WM_USER
+42: return wxT("TB_SETCMDID");
7033 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
7034 case WM_USER
+44: return wxT("TB_GETBITMAP");
7035 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
7036 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
7037 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
7038 case WM_USER
+47: return wxT("TB_SETINDENT");
7039 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
7040 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
7041 case WM_USER
+50: return wxT("TB_LOADIMAGES");
7042 case WM_USER
+51: return wxT("TB_GETRECT");
7043 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
7044 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
7045 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
7046 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
7047 case WM_USER
+56: return wxT("TB_SETSTYLE");
7048 case WM_USER
+57: return wxT("TB_GETSTYLE");
7049 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
7050 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
7051 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
7052 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
7053 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
7056 static wxString s_szBuf
;
7057 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
7058 return s_szBuf
.c_str();
7061 #endif // wxDEBUG_LEVEL >= 2
7063 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
7067 HWND hwnd
= GetHwndOf(win
);
7068 HDC hdc
= ::GetDC(hwnd
);
7070 #if !wxDIALOG_UNIT_COMPATIBILITY
7071 // and select the current font into it
7072 HFONT hfont
= GetHfontOf(win
->GetFont());
7075 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
7079 // finally retrieve the text metrics from it
7080 GetTextMetrics(hdc
, &tm
);
7082 #if !wxDIALOG_UNIT_COMPATIBILITY
7086 (void)::SelectObject(hdc
, hfont
);
7090 ::ReleaseDC(hwnd
, hdc
);
7095 // Find the wxWindow at the current mouse position, returning the mouse
7097 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
7099 pt
= wxGetMousePosition();
7100 return wxFindWindowAtPoint(pt
);
7103 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
7109 HWND hWnd
= ::WindowFromPoint(pt2
);
7111 return wxGetWindowFromHWND((WXHWND
)hWnd
);
7114 // Get the current mouse position.
7115 wxPoint
wxGetMousePosition()
7119 GetCursorPosWinCE(&pt
);
7121 GetCursorPos( & pt
);
7124 return wxPoint(pt
.x
, pt
.y
);
7129 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7130 static void WinCEUnregisterHotKey(int modifiers
, int id
)
7132 // Register hotkeys for the hardware buttons
7134 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
7136 UnregisterFunc1Proc procUnregisterFunc
;
7137 hCoreDll
= LoadLibrary(wxT("coredll.dll"));
7140 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, wxT("UnregisterFunc1"));
7141 if (procUnregisterFunc
)
7142 procUnregisterFunc(modifiers
, id
);
7143 FreeLibrary(hCoreDll
);
7148 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
7150 UINT win_modifiers
=0;
7151 if ( modifiers
& wxMOD_ALT
)
7152 win_modifiers
|= MOD_ALT
;
7153 if ( modifiers
& wxMOD_SHIFT
)
7154 win_modifiers
|= MOD_SHIFT
;
7155 if ( modifiers
& wxMOD_CONTROL
)
7156 win_modifiers
|= MOD_CONTROL
;
7157 if ( modifiers
& wxMOD_WIN
)
7158 win_modifiers
|= MOD_WIN
;
7160 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7161 // Required for PPC and Smartphone hardware buttons
7162 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
7163 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
7166 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
7168 wxLogLastError(wxT("RegisterHotKey"));
7176 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
7178 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7179 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
7182 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
7184 wxLogLastError(wxT("UnregisterHotKey"));
7194 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
7196 int win_modifiers
= LOWORD(lParam
);
7198 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, HIWORD(lParam
)));
7199 event
.SetId(wParam
);
7200 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
7201 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
7202 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
7203 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
7205 return HandleWindowEvent(event
);
7208 #endif // wxUSE_ACCEL
7210 #endif // wxUSE_HOTKEY
7212 // Not tested under WinCE
7215 // this class installs a message hook which really wakes up our idle processing
7216 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
7217 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
7218 // being dragged or even inside ::MessageBox()) and so don't control message
7219 // dispatching otherwise
7220 class wxIdleWakeUpModule
: public wxModule
7223 virtual bool OnInit()
7225 ms_hMsgHookProc
= ::SetWindowsHookEx
7228 &wxIdleWakeUpModule::MsgHookProc
,
7230 GetCurrentThreadId()
7233 if ( !ms_hMsgHookProc
)
7235 wxLogLastError(wxT("SetWindowsHookEx(WH_GETMESSAGE)"));
7243 virtual void OnExit()
7245 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
7248 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
7250 MSG
*msg
= (MSG
*)lParam
;
7252 // only process the message if it is actually going to be removed from
7253 // the message queue, this prevents that the same event from being
7254 // processed multiple times if now someone just called PeekMessage()
7255 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
7257 wxTheApp
->ProcessPendingEvents();
7260 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
7264 static HHOOK ms_hMsgHookProc
;
7266 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
7269 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
7271 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
7273 #endif // __WXWINCE__
7278 static void wxAdjustZOrder(wxWindow
* parent
)
7280 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
7282 // Set the z-order correctly
7283 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
7286 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
7289 wxWindow
*childWin
= current
->GetData();
7290 wxAdjustZOrder(childWin
);
7291 current
= current
->GetNext();
7296 // We need to adjust the z-order of static boxes in WinCE, to
7297 // make 'contained' controls visible
7298 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
7301 wxAdjustZOrder(this);