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 hDC
, wxWindowMSW
*child
)
4889 // Test for the custom background brush first.
4890 WXHBRUSH hbrush
= MSWGetCustomBgBrush();
4893 // We assume that this is either a stipple or hatched brush and not a
4894 // solid one as otherwise it would have been enough to set the
4895 // background colour and such brushes need to be positioned correctly
4896 // in order to align when different windows are painted, so do it here.
4898 ::GetWindowRect(GetHwndOf(child
), &rc
);
4900 ::MapWindowPoints(NULL
, GetHwnd(), (POINT
*)&rc
, 1);
4902 if ( !::SetBrushOrgEx((HDC
)hDC
, -rc
.left
, -rc
.top
, NULL
) )
4904 wxLogLastError(wxT("SetBrushOrgEx(bg brush)"));
4910 // Otherwise see if we have a custom background colour.
4914 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4916 return (WXHBRUSH
)GetHbrushOf(*brush
);
4922 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
)
4924 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4926 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, this);
4930 // don't use the parent background if we're not transparent
4931 if ( !win
->HasTransparentBackground() )
4934 // background is not inherited beyond top level windows
4935 if ( win
->IsTopLevel() )
4942 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4944 // we receive this message when DrawThemeParentBackground() is
4945 // called from def window proc of several controls under XP and we
4946 // must draw properly themed background here
4948 // note that naively I'd expect filling the client rect with the
4949 // brush returned by MSWGetBgBrush() work -- but for some reason it
4950 // doesn't and we have to call parents MSWPrintChild() which is
4951 // supposed to call DrawThemeBackground() with appropriate params
4953 // also note that in this case lParam == PRF_CLIENT but we're
4954 // clearly expected to paint the background and nothing else!
4956 if ( IsTopLevel() || InheritsBackgroundColour() )
4959 // sometimes we don't want the parent to handle it at all, instead
4960 // return whatever value this window wants
4961 if ( !MSWShouldPropagatePrintChild() )
4962 return MSWPrintChild(hDC
, (wxWindow
*)this);
4964 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4966 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4969 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4976 // ---------------------------------------------------------------------------
4977 // moving and resizing
4978 // ---------------------------------------------------------------------------
4980 bool wxWindowMSW::HandleMinimize()
4982 wxIconizeEvent
event(m_windowId
);
4983 event
.SetEventObject(this);
4985 return HandleWindowEvent(event
);
4988 bool wxWindowMSW::HandleMaximize()
4990 wxMaximizeEvent
event(m_windowId
);
4991 event
.SetEventObject(this);
4993 return HandleWindowEvent(event
);
4996 bool wxWindowMSW::HandleMove(int x
, int y
)
4999 wxMoveEvent
event(point
, m_windowId
);
5000 event
.SetEventObject(this);
5002 return HandleWindowEvent(event
);
5005 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
5007 wxMoveEvent
event(rect
, m_windowId
);
5008 event
.SetEventObject(this);
5010 bool rc
= HandleWindowEvent(event
);
5012 rect
= event
.GetRect();
5016 bool wxWindowMSW::HandleEnterSizeMove()
5018 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5019 event
.SetEventType(wxEVT_MOVE_START
);
5020 event
.SetEventObject(this);
5022 return HandleWindowEvent(event
);
5025 bool wxWindowMSW::HandleExitSizeMove()
5027 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
5028 event
.SetEventType(wxEVT_MOVE_END
);
5029 event
.SetEventObject(this);
5031 return HandleWindowEvent(event
);
5034 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
5036 #if wxUSE_DEFERRED_SIZING
5037 // when we resize this window, its children are probably going to be
5038 // repositioned as well, prepare to use DeferWindowPos() for them
5039 int numChildren
= 0;
5040 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
5042 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
5047 // Protect against valid m_hDWP being overwritten
5048 bool useDefer
= false;
5050 if ( numChildren
> 1 )
5054 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
5057 wxLogLastError(wxT("BeginDeferWindowPos"));
5063 #endif // wxUSE_DEFERRED_SIZING
5065 // update this window size
5066 bool processed
= false;
5070 wxFAIL_MSG( wxT("unexpected WM_SIZE parameter") );
5071 // fall through nevertheless
5075 // we're not interested in these messages at all
5078 case SIZE_MINIMIZED
:
5079 processed
= HandleMinimize();
5082 case SIZE_MAXIMIZED
:
5083 /* processed = */ HandleMaximize();
5084 // fall through to send a normal size event as well
5087 // don't use w and h parameters as they specify the client size
5088 // while according to the docs EVT_SIZE handler is supposed to
5089 // receive the total size
5090 wxSizeEvent
event(GetSize(), m_windowId
);
5091 event
.SetEventObject(this);
5093 processed
= HandleWindowEvent(event
);
5096 #if wxUSE_DEFERRED_SIZING
5097 // and finally change the positions of all child windows at once
5098 if ( useDefer
&& m_hDWP
)
5100 // reset m_hDWP to NULL so that child windows don't try to use our
5101 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
5102 // happen anyhow normally but who knows what weird flow of control we
5103 // may have depending on what the users EVT_SIZE handler does...)
5104 HDWP hDWP
= (HDWP
)m_hDWP
;
5107 // do put all child controls in place at once
5108 if ( !::EndDeferWindowPos(hDWP
) )
5110 wxLogLastError(wxT("EndDeferWindowPos"));
5113 // Reset our children's pending pos/size values.
5114 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
5116 node
= node
->GetNext() )
5118 wxWindowMSW
* const child
= node
->GetData();
5119 child
->MSWEndDeferWindowPos();
5122 #endif // wxUSE_DEFERRED_SIZING
5127 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
5129 wxSizeEvent
event(rect
, m_windowId
);
5130 event
.SetEventObject(this);
5132 bool rc
= HandleWindowEvent(event
);
5134 rect
= event
.GetRect();
5138 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
5143 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
5147 int minWidth
= GetMinWidth(),
5148 minHeight
= GetMinHeight(),
5149 maxWidth
= GetMaxWidth(),
5150 maxHeight
= GetMaxHeight();
5152 if ( minWidth
!= wxDefaultCoord
)
5154 info
->ptMinTrackSize
.x
= minWidth
;
5158 if ( minHeight
!= wxDefaultCoord
)
5160 info
->ptMinTrackSize
.y
= minHeight
;
5164 if ( maxWidth
!= wxDefaultCoord
)
5166 info
->ptMaxTrackSize
.x
= maxWidth
;
5170 if ( maxHeight
!= wxDefaultCoord
)
5172 info
->ptMaxTrackSize
.y
= maxHeight
;
5180 // ---------------------------------------------------------------------------
5182 // ---------------------------------------------------------------------------
5184 bool wxWindowMSW::HandleCommand(WXWORD id_
, WXWORD cmd
, WXHWND control
)
5186 // sign extend to int from short before comparing with the other int ids
5187 int id
= (signed short)id_
;
5189 #if wxUSE_MENUS_NATIVE
5190 if ( !cmd
&& wxCurrentPopupMenu
)
5192 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
5193 wxCurrentPopupMenu
= NULL
;
5195 return popupMenu
->MSWCommand(cmd
, id
);
5197 #endif // wxUSE_MENUS_NATIVE
5199 wxWindow
*win
= NULL
;
5201 // first try to find it from HWND - this works even with the broken
5202 // programs using the same ids for different controls
5205 win
= wxFindWinFromHandle(control
);
5216 return win
->MSWCommand(cmd
, id
);
5219 // the messages sent from the in-place edit control used by the treectrl
5220 // for label editing have id == 0, but they should _not_ be treated as menu
5221 // messages (they are EN_XXX ones, in fact) so don't translate anything
5222 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
5225 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
5226 event
.SetEventObject(this);
5229 return HandleWindowEvent(event
);
5233 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5234 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
5235 // notifications to its parent which we want to reflect back to
5237 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
5238 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
5240 #endif // wxUSE_SPINCTRL
5242 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
5243 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
5244 // notifications to its parent which we want to reflect back to
5246 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
5247 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
5255 // ---------------------------------------------------------------------------
5257 // ---------------------------------------------------------------------------
5259 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
5263 // our client coords are not quite the same as Windows ones
5264 wxPoint pt
= GetClientAreaOrigin();
5265 event
.m_x
= x
- pt
.x
;
5266 event
.m_y
= y
- pt
.y
;
5268 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
5269 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
5270 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
5271 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
5272 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
5273 #ifdef wxHAS_XBUTTON
5274 event
.m_aux1Down
= (flags
& MK_XBUTTON1
) != 0;
5275 event
.m_aux2Down
= (flags
& MK_XBUTTON2
) != 0;
5276 #endif // wxHAS_XBUTTON
5277 event
.m_altDown
= ::wxIsAltDown();
5280 event
.SetTimestamp(::GetMessageTime());
5283 event
.SetEventObject(this);
5284 event
.SetId(GetId());
5286 #if wxUSE_MOUSEEVENT_HACK
5287 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
5288 gs_lastMouseEvent
.type
= event
.GetEventType();
5289 #endif // wxUSE_MOUSEEVENT_HACK
5293 // Windows doesn't send the mouse events to the static controls (which are
5294 // transparent in the sense that their WM_NCHITTEST handler returns
5295 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
5296 // and so we manually check if we don't have a child window under mouse and if
5297 // we do, send the event to it instead of the window Windows had sent WM_XXX
5300 // Notice that this is not done for the mouse move events because this could
5301 // (would?) be too slow, but only for clicks which means that the static texts
5302 // still don't get move, enter nor leave events.
5303 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
5305 wxCHECK_MSG( x
&& y
, win
, wxT("NULL pointer in FindWindowForMouseEvent") );
5307 // first try to find a non transparent child: this allows us to send events
5308 // to a static text which is inside a static box, for example
5309 POINT pt
= { *x
, *y
};
5310 HWND hwnd
= GetHwndOf(win
),
5314 hwndUnderMouse
= ::ChildWindowFromPoint
5320 hwndUnderMouse
= ::ChildWindowFromPointEx
5330 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
5332 // now try any child window at all
5333 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
5336 // check that we have a child window which is susceptible to receive mouse
5337 // events: for this it must be shown and enabled
5338 if ( hwndUnderMouse
&&
5339 hwndUnderMouse
!= hwnd
&&
5340 ::IsWindowVisible(hwndUnderMouse
) &&
5341 ::IsWindowEnabled(hwndUnderMouse
) )
5343 wxWindow
*winUnderMouse
= wxFindWinFromHandle(hwndUnderMouse
);
5344 if ( winUnderMouse
)
5346 // translate the mouse coords to the other window coords
5347 win
->ClientToScreen(x
, y
);
5348 winUnderMouse
->ScreenToClient(x
, y
);
5350 win
= winUnderMouse
;
5356 #endif // __WXWINCE__
5358 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5360 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
5361 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
5362 // from the message id and take the value in the table to get wxWin event
5364 static const wxEventType eventsMouse
[] =
5375 wxEVT_MIDDLE_DCLICK
,
5376 0, // this one is for wxEVT_MOTION which is not used here
5385 #ifdef wxHAS_XBUTTON
5386 // the same messages are used for both auxillary mouse buttons so we need
5387 // to adjust the index manually
5390 case WM_XBUTTONDOWN
:
5392 case WM_XBUTTONDBLCLK
:
5393 if ( flags
& MK_XBUTTON2
)
5394 msg
+= wxEVT_AUX2_DOWN
- wxEVT_AUX1_DOWN
;
5396 #endif // wxHAS_XBUTTON
5398 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
5399 InitMouseEvent(event
, x
, y
, flags
);
5401 return HandleWindowEvent(event
);
5404 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
5406 if ( !m_mouseInWindow
)
5408 // it would be wrong to assume that just because we get a mouse move
5409 // event that the mouse is inside the window: although this is usually
5410 // true, it is not if we had captured the mouse, so we need to check
5411 // the mouse coordinates here
5412 if ( !HasCapture() || IsMouseInWindow() )
5414 // Generate an ENTER event
5415 m_mouseInWindow
= true;
5417 #ifdef HAVE_TRACKMOUSEEVENT
5418 typedef BOOL (WINAPI
*_TrackMouseEvent_t
)(LPTRACKMOUSEEVENT
);
5420 static const _TrackMouseEvent_t
5421 s_pfn_TrackMouseEvent
= _TrackMouseEvent
;
5422 #else // !__WXWINCE__
5423 static _TrackMouseEvent_t s_pfn_TrackMouseEvent
;
5424 static bool s_initDone
= false;
5427 // see comment in wxApp::GetComCtl32Version() explaining the
5428 // use of wxLoadedDLL
5429 wxLoadedDLL
dllComCtl32(wxT("comctl32.dll"));
5430 if ( dllComCtl32
.IsLoaded() )
5432 s_pfn_TrackMouseEvent
= (_TrackMouseEvent_t
)
5433 dllComCtl32
.RawGetSymbol(wxT("_TrackMouseEvent"));
5439 if ( s_pfn_TrackMouseEvent
)
5440 #endif // __WXWINCE__/!__WXWINCE__
5442 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
5444 trackinfo
.dwFlags
= TME_LEAVE
;
5445 trackinfo
.hwndTrack
= GetHwnd();
5447 (*s_pfn_TrackMouseEvent
)(&trackinfo
);
5449 #endif // HAVE_TRACKMOUSEEVENT
5451 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
5452 InitMouseEvent(event
, x
, y
, flags
);
5454 (void)HandleWindowEvent(event
);
5457 #ifdef HAVE_TRACKMOUSEEVENT
5458 else // mouse not in window
5460 // Check if we need to send a LEAVE event
5461 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
5462 // send it here if we are using native mouse leave tracking
5463 if ( HasCapture() && !IsMouseInWindow() )
5465 GenerateMouseLeave();
5468 #endif // HAVE_TRACKMOUSEEVENT
5470 #if wxUSE_MOUSEEVENT_HACK
5471 // Windows often generates mouse events even if mouse position hasn't
5472 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
5474 // Filter this out as it can result in unexpected behaviour compared to
5476 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
5477 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
5478 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
5479 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
5481 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
5483 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
5488 #endif // wxUSE_MOUSEEVENT_HACK
5490 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
5494 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
5496 #if wxUSE_MOUSEWHEEL
5497 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5498 // forwarded up to the parent by DefWindowProc()) and not in the client
5499 // ones as all the other messages, translate them to the client coords for
5502 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
5503 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
5504 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
5505 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5506 event
.m_wheelDelta
= WHEEL_DELTA
;
5508 static int s_linesPerRotation
= -1;
5509 if ( s_linesPerRotation
== -1 )
5511 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5512 &s_linesPerRotation
, 0))
5514 // this is not supposed to happen
5515 wxLogLastError(wxT("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5517 // the default is 3, so use it if SystemParametersInfo() failed
5518 s_linesPerRotation
= 3;
5522 event
.m_linesPerAction
= s_linesPerRotation
;
5523 return HandleWindowEvent(event
);
5525 #else // !wxUSE_MOUSEWHEEL
5526 wxUnusedVar(wParam
);
5527 wxUnusedVar(lParam
);
5530 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5533 void wxWindowMSW::GenerateMouseLeave()
5535 m_mouseInWindow
= false;
5538 if ( wxIsShiftDown() )
5540 if ( wxIsCtrlDown() )
5541 state
|= MK_CONTROL
;
5543 // Only the high-order bit should be tested
5544 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5545 state
|= MK_LBUTTON
;
5546 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5547 state
|= MK_MBUTTON
;
5548 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5549 state
|= MK_RBUTTON
;
5553 if ( !::GetCursorPosWinCE(&pt
) )
5555 if ( !::GetCursorPos(&pt
) )
5558 wxLogLastError(wxT("GetCursorPos"));
5561 // we need to have client coordinates here for symmetry with
5562 // wxEVT_ENTER_WINDOW
5563 RECT rect
= wxGetWindowRect(GetHwnd());
5567 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5568 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5570 (void)HandleWindowEvent(event
);
5573 // ---------------------------------------------------------------------------
5574 // keyboard handling
5575 // ---------------------------------------------------------------------------
5580 // Implementation of InitAnyKeyEvent() which can also be used when there is no
5581 // associated window: this can happen for the wxEVT_CHAR_HOOK events created by
5582 // the global keyboard hook (e.g. the event might have happened in a non-wx
5585 MSWInitAnyKeyEvent(wxKeyEvent
& event
,
5588 const wxWindowBase
*win
/* may be NULL */)
5592 event
.SetId(win
->GetId());
5593 event
.SetEventObject(const_cast<wxWindowBase
*>(win
));
5595 else // No associated window.
5597 // Use wxID_ANY for compatibility with the old code even if wxID_NONE
5598 // would arguably make more sense.
5599 event
.SetId(wxID_ANY
);
5602 event
.m_shiftDown
= wxIsShiftDown();
5603 event
.m_controlDown
= wxIsCtrlDown();
5604 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5606 event
.m_rawCode
= (wxUint32
) wParam
;
5607 event
.m_rawFlags
= (wxUint32
) lParam
;
5609 event
.SetTimestamp(::GetMessageTime());
5612 // Event coordinates must be in window client coordinates system which
5613 // doesn't make sense if there is no window.
5615 // We could use screen coordinates for such events but this would make the
5616 // logic of the event handlers more complicated: you'd need to test for the
5617 // event object and interpret the coordinates differently according to
5618 // whether it's NULL or not so unless somebody really asks for this let's
5619 // just avoid the issue.
5622 const wxPoint mousePos
= win
->ScreenToClient(wxGetMousePosition());
5623 event
.m_x
= mousePos
.x
;
5624 event
.m_y
= mousePos
.y
;
5628 } // anonymous namespace
5631 wxWindowMSW::InitAnyKeyEvent(wxKeyEvent
& event
,
5633 WXLPARAM lParam
) const
5635 MSWInitAnyKeyEvent(event
, wParam
, lParam
, this);
5639 wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5641 WXLPARAM lParam
) const
5643 // Catch any attempts to use this with WM_CHAR, it wouldn't work because
5644 // wParam is supposed to be a virtual key and not a character here.
5645 wxASSERT_MSG( evType
!= wxEVT_CHAR
&& evType
!= wxEVT_CHAR_HOOK
,
5646 "CreateKeyEvent() can't be used for char events" );
5648 wxKeyEvent
event(evType
);
5649 InitAnyKeyEvent(event
, wParam
, lParam
);
5651 event
.m_keyCode
= wxMSWKeyboard::VKToWX
5657 #endif // wxUSE_UNICODE
5663 // isASCII is true only when we're called from WM_CHAR handler and not from
5665 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
)
5667 wxKeyEvent
event(wxEVT_CHAR
);
5668 InitAnyKeyEvent(event
, wParam
, lParam
);
5671 // TODO: wParam uses UTF-16 so this is incorrect for characters outside of
5672 // the BMP, we should use WM_UNICHAR to handle them.
5673 event
.m_uniChar
= wParam
;
5674 #endif // wxUSE_UNICODE
5676 // Set non-Unicode key code too for compatibility if possible.
5677 if ( wParam
< 0x80 )
5679 // It's an ASCII character, no need to translate it.
5680 event
.m_keyCode
= wParam
;
5684 // Check if this key can be represented (as a single character) in the
5686 const wchar_t wc
= wParam
;
5688 if ( wxConvLibc
.FromWChar(&ch
, 1, &wc
, 1) != wxCONV_FAILED
)
5690 // For compatibility continue to provide the key code in this field
5691 // even though using GetUnicodeKey() is recommended now.
5692 event
.m_keyCode
= static_cast<unsigned char>(ch
);
5694 //else: Key can't be represented in the current locale, leave m_keyCode
5695 // as WXK_NONE and use GetUnicodeKey() to access the character.
5698 // the alphanumeric keys produced by pressing AltGr+something on European
5699 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5700 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5701 // alphanumeric, so pretend that there are no modifiers at all (the
5702 // KEY_DOWN event would still have the correct modifiers if they're really
5704 if ( event
.m_controlDown
&& event
.m_altDown
&&
5705 (event
.m_keyCode
>= 32 && event
.m_keyCode
< 256) )
5707 event
.m_controlDown
=
5708 event
.m_altDown
= false;
5711 return HandleWindowEvent(event
);
5714 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5716 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, wParam
, lParam
));
5717 return HandleWindowEvent(event
);
5720 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5722 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, wParam
, lParam
));
5723 return HandleWindowEvent(event
);
5727 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5728 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5730 // FIXME: implement GetMenuItemCount for WinCE, possibly
5731 // in terms of GetMenuItemInfo
5733 const HMENU hmenu
= (HMENU
)lParam
;
5737 mii
.cbSize
= sizeof(MENUITEMINFO
);
5739 // we could use MIIM_FTYPE here as we only need to know if the item is
5740 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5741 // MIIM_FTYPE is not supported under Win95
5742 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5744 // find if we have this letter in any owner drawn item
5745 const int count
= ::GetMenuItemCount(hmenu
);
5746 for ( int i
= 0; i
< count
; i
++ )
5748 // previous loop iteration could modify it, reset it back before
5749 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5752 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5754 if ( mii
.fType
== MFT_OWNERDRAW
)
5756 // dwItemData member of the MENUITEMINFO is a
5757 // pointer to the associated wxMenuItem -- see the
5758 // menu creation code
5759 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5761 const wxString
label(item
->GetItemLabel());
5762 const wxChar
*p
= wxStrchr(label
.wx_str(), wxT('&'));
5765 if ( *p
== wxT('&') )
5767 // this is not the accel char, find the real one
5768 p
= wxStrchr(p
+ 1, wxT('&'));
5770 else // got the accel char
5772 // FIXME-UNICODE: this comparison doesn't risk to work
5773 // for non ASCII accelerator characters I'm afraid, but
5775 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5781 // this one doesn't match
5788 else // failed to get the menu text?
5790 // it's not fatal, so don't show error, but still log it
5791 wxLogLastError(wxT("GetMenuItemInfo"));
5798 #endif // wxUSE_MENUS
5800 bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg
)
5802 const wxEventType type
= nMsg
== WM_CUT
? wxEVT_COMMAND_TEXT_CUT
5803 : nMsg
== WM_COPY
? wxEVT_COMMAND_TEXT_COPY
5804 : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE
;
5805 wxClipboardTextEvent
evt(type
, GetId());
5807 evt
.SetEventObject(this);
5809 return HandleWindowEvent(evt
);
5812 // ---------------------------------------------------------------------------
5814 // ---------------------------------------------------------------------------
5816 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5820 if ( flags
& JOY_BUTTON1CHG
)
5821 change
= wxJOY_BUTTON1
;
5822 if ( flags
& JOY_BUTTON2CHG
)
5823 change
= wxJOY_BUTTON2
;
5824 if ( flags
& JOY_BUTTON3CHG
)
5825 change
= wxJOY_BUTTON3
;
5826 if ( flags
& JOY_BUTTON4CHG
)
5827 change
= wxJOY_BUTTON4
;
5830 if ( flags
& JOY_BUTTON1
)
5831 buttons
|= wxJOY_BUTTON1
;
5832 if ( flags
& JOY_BUTTON2
)
5833 buttons
|= wxJOY_BUTTON2
;
5834 if ( flags
& JOY_BUTTON3
)
5835 buttons
|= wxJOY_BUTTON3
;
5836 if ( flags
& JOY_BUTTON4
)
5837 buttons
|= wxJOY_BUTTON4
;
5839 // the event ids aren't consecutive so we can't use table based lookup
5841 wxEventType eventType
;
5846 eventType
= wxEVT_JOY_MOVE
;
5851 eventType
= wxEVT_JOY_MOVE
;
5856 eventType
= wxEVT_JOY_ZMOVE
;
5861 eventType
= wxEVT_JOY_ZMOVE
;
5864 case MM_JOY1BUTTONDOWN
:
5866 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5869 case MM_JOY2BUTTONDOWN
:
5871 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5874 case MM_JOY1BUTTONUP
:
5876 eventType
= wxEVT_JOY_BUTTON_UP
;
5879 case MM_JOY2BUTTONUP
:
5881 eventType
= wxEVT_JOY_BUTTON_UP
;
5885 wxFAIL_MSG(wxT("no such joystick event"));
5890 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5891 event
.SetPosition(wxPoint(x
, y
));
5892 event
.SetEventObject(this);
5894 return HandleWindowEvent(event
);
5904 // ---------------------------------------------------------------------------
5906 // ---------------------------------------------------------------------------
5908 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5909 WXWORD pos
, WXHWND control
)
5911 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5913 wxWindow
*child
= wxFindWinFromHandle(control
);
5915 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5918 wxScrollWinEvent event
;
5919 event
.SetPosition(pos
);
5920 event
.SetOrientation(orientation
);
5921 event
.SetEventObject(this);
5926 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5930 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5934 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5938 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5942 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5946 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5949 case SB_THUMBPOSITION
:
5951 // under Win32, the scrollbar range and position are 32 bit integers,
5952 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5953 // explicitly query the scrollbar for the correct position (this must
5954 // be done only for these two SB_ events as they are the only one
5955 // carrying the scrollbar position)
5957 WinStruct
<SCROLLINFO
> scrollInfo
;
5958 scrollInfo
.fMask
= SIF_TRACKPOS
;
5960 if ( !::GetScrollInfo(GetHwnd(),
5961 WXOrientToSB(orientation
),
5964 // Not necessarily an error, if there are no scrollbars yet.
5965 // wxLogLastError(wxT("GetScrollInfo"));
5968 event
.SetPosition(scrollInfo
.nTrackPos
);
5971 event
.SetEventType( wParam
== SB_THUMBPOSITION
5972 ? wxEVT_SCROLLWIN_THUMBRELEASE
5973 : wxEVT_SCROLLWIN_THUMBTRACK
);
5980 return HandleWindowEvent(event
);
5983 // ----------------------------------------------------------------------------
5984 // custom message handlers
5985 // ----------------------------------------------------------------------------
5988 wxWindowMSW::MSWRegisterMessageHandler(int msg
, MSWMessageHandler handler
)
5990 wxCHECK_MSG( gs_messageHandlers
.find(msg
) == gs_messageHandlers
.end(),
5991 false, wxT("registering handler for the same message twice") );
5993 gs_messageHandlers
[msg
] = handler
;
5998 wxWindowMSW::MSWUnregisterMessageHandler(int msg
, MSWMessageHandler handler
)
6000 const MSWMessageHandlers::iterator i
= gs_messageHandlers
.find(msg
);
6001 wxCHECK_RET( i
!= gs_messageHandlers
.end() && i
->second
== handler
,
6002 wxT("unregistering non-registered handler?") );
6004 gs_messageHandlers
.erase(i
);
6007 // ===========================================================================
6009 // ===========================================================================
6011 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
6014 HDC dc
= ::GetDC((HWND
) wnd
);
6017 // the_font.UseResource();
6018 // the_font.RealizeResource();
6019 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
6021 was
= (HFONT
) SelectObject(dc
,fnt
);
6023 GetTextMetrics(dc
, &tm
);
6026 SelectObject(dc
,was
);
6028 ReleaseDC((HWND
)wnd
, dc
);
6031 *x
= tm
.tmAveCharWidth
;
6033 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
6035 // the_font.ReleaseResource();
6038 // ----------------------------------------------------------------------------
6040 // ----------------------------------------------------------------------------
6042 namespace wxMSWKeyboard
6048 // use the "extended" bit of lParam to distinguish extended keys from normal
6049 // keys as the same virtual key code is sent for both by Windows
6051 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
6053 // except that if lParam is 0, it means we don't have real lParam from
6054 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
6055 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
6056 // non-numpad (hence extended) key as this is a more common case
6057 return !lParam
|| (HIWORD(lParam
) & KF_EXTENDED
) ? keyExtended
: keyNormal
;
6060 // this array contains the Windows virtual key codes which map one to one to
6061 // WXK_xxx constants and is used in wxMSWKeyboard::VKToWX/WXToVK() below
6063 // note that keys having a normal and numpad version (e.g. WXK_HOME and
6064 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
6065 const struct wxKeyMapping
6069 } gs_specialKeys
[] =
6071 { VK_CANCEL
, WXK_CANCEL
},
6072 { VK_BACK
, WXK_BACK
},
6073 { VK_TAB
, WXK_TAB
},
6074 { VK_CLEAR
, WXK_CLEAR
},
6075 { VK_SHIFT
, WXK_SHIFT
},
6076 { VK_CONTROL
, WXK_CONTROL
},
6077 { VK_MENU
, WXK_ALT
},
6078 { VK_PAUSE
, WXK_PAUSE
},
6079 { VK_CAPITAL
, WXK_CAPITAL
},
6080 { VK_SPACE
, WXK_SPACE
},
6081 { VK_ESCAPE
, WXK_ESCAPE
},
6082 { VK_SELECT
, WXK_SELECT
},
6083 { VK_PRINT
, WXK_PRINT
},
6084 { VK_EXECUTE
, WXK_EXECUTE
},
6085 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
6086 { VK_HELP
, WXK_HELP
},
6088 { VK_NUMPAD0
, WXK_NUMPAD0
},
6089 { VK_NUMPAD1
, WXK_NUMPAD1
},
6090 { VK_NUMPAD2
, WXK_NUMPAD2
},
6091 { VK_NUMPAD3
, WXK_NUMPAD3
},
6092 { VK_NUMPAD4
, WXK_NUMPAD4
},
6093 { VK_NUMPAD5
, WXK_NUMPAD5
},
6094 { VK_NUMPAD6
, WXK_NUMPAD6
},
6095 { VK_NUMPAD7
, WXK_NUMPAD7
},
6096 { VK_NUMPAD8
, WXK_NUMPAD8
},
6097 { VK_NUMPAD9
, WXK_NUMPAD9
},
6098 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
6099 { VK_ADD
, WXK_NUMPAD_ADD
},
6100 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
6101 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
6102 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
6113 { VK_F10
, WXK_F10
},
6114 { VK_F11
, WXK_F11
},
6115 { VK_F12
, WXK_F12
},
6116 { VK_F13
, WXK_F13
},
6117 { VK_F14
, WXK_F14
},
6118 { VK_F15
, WXK_F15
},
6119 { VK_F16
, WXK_F16
},
6120 { VK_F17
, WXK_F17
},
6121 { VK_F18
, WXK_F18
},
6122 { VK_F19
, WXK_F19
},
6123 { VK_F20
, WXK_F20
},
6124 { VK_F21
, WXK_F21
},
6125 { VK_F22
, WXK_F22
},
6126 { VK_F23
, WXK_F23
},
6127 { VK_F24
, WXK_F24
},
6129 { VK_NUMLOCK
, WXK_NUMLOCK
},
6130 { VK_SCROLL
, WXK_SCROLL
},
6133 { VK_LWIN
, WXK_WINDOWS_LEFT
},
6134 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
6135 { VK_APPS
, WXK_WINDOWS_MENU
},
6136 #endif // VK_APPS defined
6139 } // anonymous namespace
6141 int VKToWX(WXWORD vk
, WXLPARAM lParam
, wchar_t *uc
)
6145 // check the table first
6146 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6148 if ( gs_specialKeys
[n
].vk
== vk
)
6150 wxk
= gs_specialKeys
[n
].wxk
;
6151 if ( wxk
< WXK_START
)
6153 // Unicode code for this key is the same as its ASCII code.
6162 // keys requiring special handling
6176 // MapVirtualKey() returns 0 if it fails to convert the virtual
6177 // key which nicely corresponds to our WXK_NONE.
6178 wxk
= ::MapVirtualKey(vk
, MAPVK_VK_TO_CHAR
);
6180 if ( HIWORD(wxk
) & 0x8000 )
6182 // It's a dead key and we don't return anything at all for them
6183 // as we simply don't have any way to indicate the difference
6184 // between e.g. a normal "'" and "'" as a dead key -- and
6185 // generating the same events for them just doesn't seem like a
6190 // In any case return this as a Unicode character value.
6194 // For compatibility with the old non-Unicode code we continue
6195 // returning key codes for Latin-1 characters directly
6196 // (normally it would really only make sense to do it for the
6197 // ASCII characters, not Latin-1 ones).
6200 // But for anything beyond this we can only return the key
6201 // value as a real Unicode character, not a wxKeyCode
6202 // because this enum values clash with Unicode characters
6203 // (e.g. WXK_LBUTTON also happens to be U+012C a.k.a.
6204 // "LATIN CAPITAL LETTER I WITH BREVE").
6209 // handle extended keys
6211 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
6215 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
6219 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
6223 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
6227 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
6231 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
6235 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
6239 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
6243 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
6247 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
6251 // don't use ChooseNormalOrExtended() here as the keys are reversed
6252 // here: numpad enter is the extended one
6253 wxk
= HIWORD(lParam
) & KF_EXTENDED
? WXK_NUMPAD_ENTER
: WXK_RETURN
;
6257 if ( (vk
>= '0' && vk
<= '9') || (vk
>= 'A' && vk
<= 'Z') )
6259 // A simple alphanumeric key and the values of them coincide in
6260 // Windows and wx for both ASCII and Unicode codes.
6263 else // Something we simply don't know about at all.
6275 WXWORD
WXToVK(int wxk
, bool *isExtended
)
6277 // check the table first
6278 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6280 if ( gs_specialKeys
[n
].wxk
== wxk
)
6282 // All extended keys (i.e. non-numpad versions of the keys that
6283 // exist both in the numpad and outside of it) are dealt with
6286 *isExtended
= false;
6288 return gs_specialKeys
[n
].vk
;
6292 // and then check for special keys not included in the table
6293 bool extended
= false;
6299 case WXK_NUMPAD_PAGEUP
:
6305 case WXK_NUMPAD_PAGEDOWN
:
6311 case WXK_NUMPAD_END
:
6317 case WXK_NUMPAD_HOME
:
6323 case WXK_NUMPAD_LEFT
:
6335 case WXK_NUMPAD_RIGHT
:
6341 case WXK_NUMPAD_DOWN
:
6347 case WXK_NUMPAD_INSERT
:
6353 case WXK_NUMPAD_DELETE
:
6358 // no VkKeyScan() under CE unfortunately, we need to test how does
6359 // it handle OEM keys
6361 // check to see if its one of the OEM key codes.
6362 BYTE vks
= LOBYTE(VkKeyScan(wxk
));
6368 #endif // !__WXWINCE__
6375 *isExtended
= extended
;
6380 } // namespace wxMSWKeyboard
6382 // small helper for wxGetKeyState() and wxGetMouseState()
6383 static inline bool wxIsKeyDown(WXWORD vk
)
6385 // SM_SWAPBUTTON is not available under CE, so don't swap buttons there
6386 #ifdef SM_SWAPBUTTON
6387 if ( vk
== VK_LBUTTON
|| vk
== VK_RBUTTON
)
6389 if ( ::GetSystemMetrics(SM_SWAPBUTTON
) )
6391 if ( vk
== VK_LBUTTON
)
6393 else // vk == VK_RBUTTON
6397 #endif // SM_SWAPBUTTON
6399 // the low order bit indicates whether the key was pressed since the last
6400 // call and the high order one indicates whether it is down right now and
6401 // we only want that one
6402 return (GetAsyncKeyState(vk
) & (1<<15)) != 0;
6405 bool wxGetKeyState(wxKeyCode key
)
6407 // although this does work under Windows, it is not supported under other
6408 // platforms so don't allow it, you must use wxGetMouseState() instead
6409 wxASSERT_MSG( key
!= VK_LBUTTON
&&
6410 key
!= VK_RBUTTON
&&
6412 wxT("can't use wxGetKeyState() for mouse buttons") );
6414 const WXWORD vk
= wxMSWKeyboard::WXToVK(key
);
6416 // if the requested key is a LED key, return true if the led is pressed
6417 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
6419 // low order bit means LED is highlighted and high order one means the
6420 // key is down; for compatibility with the other ports return true if
6421 // either one is set
6422 return GetKeyState(vk
) != 0;
6427 return wxIsKeyDown(vk
);
6432 wxMouseState
wxGetMouseState()
6436 GetCursorPos( &pt
);
6440 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
6441 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
6442 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
6443 #ifdef wxHAS_XBUTTON
6444 ms
.SetAux1Down(wxIsKeyDown(VK_XBUTTON1
));
6445 ms
.SetAux2Down(wxIsKeyDown(VK_XBUTTON2
));
6446 #endif // wxHAS_XBUTTON
6448 ms
.SetControlDown(wxIsCtrlDown ());
6449 ms
.SetShiftDown (wxIsShiftDown());
6450 ms
.SetAltDown (wxIsAltDown ());
6451 // ms.SetMetaDown();
6457 wxWindow
*wxGetActiveWindow()
6459 HWND hWnd
= GetActiveWindow();
6462 return wxFindWinFromHandle(hWnd
);
6467 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
6469 HWND hwnd
= (HWND
)hWnd
;
6471 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
6472 // by code in msw/radiobox.cpp), for all the others we just search up the
6474 wxWindow
*win
= NULL
;
6477 win
= wxFindWinFromHandle(hwnd
);
6480 #if wxUSE_RADIOBOX && !defined(__WXUNIVERSAL__)
6481 // native radiobuttons return DLGC_RADIOBUTTON here and for any
6482 // wxWindow class which overrides WM_GETDLGCODE processing to
6483 // do it as well, win would be already non NULL
6484 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
6486 win
= wxRadioBox::GetFromRadioButtonHWND(hwnd
);
6488 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
6489 #endif // wxUSE_RADIOBOX
6491 // spin control text buddy window should be mapped to spin ctrl
6492 // itself so try it too
6493 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
6496 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
6498 #endif // wxUSE_SPINCTRL
6502 while ( hwnd
&& !win
)
6504 // this is a really ugly hack needed to avoid mistakenly returning the
6505 // parent frame wxWindow for the find/replace modeless dialog HWND -
6506 // this, in turn, is needed to call IsDialogMessage() from
6507 // wxApp::ProcessMessage() as for this we must return NULL from here
6509 // FIXME: this is clearly not the best way to do it but I think we'll
6510 // need to change HWND <-> wxWindow code more heavily than I can
6511 // do it now to fix it
6512 #ifndef __WXMICROWIN__
6513 if ( ::GetWindow(hwnd
, GW_OWNER
) )
6515 // it's a dialog box, don't go upwards
6520 hwnd
= ::GetParent(hwnd
);
6521 win
= wxFindWinFromHandle(hwnd
);
6527 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
6529 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
6530 // in active frames and dialogs, regardless of where the focus is.
6531 static HHOOK wxTheKeyboardHook
= 0;
6534 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
6536 DWORD hiWord
= HIWORD(lParam
);
6537 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
6540 int id
= wxMSWKeyboard::VKToWX(wParam
, lParam
, &uc
);
6542 // Don't intercept keyboard entry (notably Escape) if a modal window
6543 // (not managed by wx, e.g. IME one) is currently opened as more often
6544 // than not it needs all the keys for itself.
6546 // Also don't catch it if a window currently captures the mouse as
6547 // Escape is normally used to release the mouse capture and if you
6548 // really need to catch all the keys in the window that has mouse
6549 // capture it can be easily done in its own EVT_CHAR handler as it is
6550 // certain to have focus while it has the capture.
6551 if ( !gs_modalEntryWindowCount
&& !::GetCapture() )
6555 || static_cast<int>(uc
) != WXK_NONE
6556 #endif // wxUSE_UNICODE
6559 const wxWindow
* const win
= wxGetActiveWindow();
6561 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
6562 MSWInitAnyKeyEvent(event
, wParam
, lParam
, win
);
6564 event
.m_keyCode
= id
;
6566 event
.m_uniChar
= uc
;
6567 #endif // wxUSE_UNICODE
6569 wxEvtHandler
* const handler
= win
? win
->GetEventHandler()
6572 if ( handler
&& handler
->ProcessEvent(event
) )
6581 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
6584 void wxSetKeyboardHook(bool doIt
)
6588 wxTheKeyboardHook
= ::SetWindowsHookEx
6591 (HOOKPROC
)wxKeyboardHook
,
6592 NULL
, // must be NULL for process hook
6593 ::GetCurrentThreadId()
6595 if ( !wxTheKeyboardHook
)
6597 wxLogLastError(wxT("SetWindowsHookEx(wxKeyboardHook)"));
6602 if ( wxTheKeyboardHook
)
6603 ::UnhookWindowsHookEx(wxTheKeyboardHook
);
6607 #endif // !__WXMICROWIN__
6609 #if wxDEBUG_LEVEL >= 2
6610 const wxChar
*wxGetMessageName(int message
)
6614 case 0x0000: return wxT("WM_NULL");
6615 case 0x0001: return wxT("WM_CREATE");
6616 case 0x0002: return wxT("WM_DESTROY");
6617 case 0x0003: return wxT("WM_MOVE");
6618 case 0x0005: return wxT("WM_SIZE");
6619 case 0x0006: return wxT("WM_ACTIVATE");
6620 case 0x0007: return wxT("WM_SETFOCUS");
6621 case 0x0008: return wxT("WM_KILLFOCUS");
6622 case 0x000A: return wxT("WM_ENABLE");
6623 case 0x000B: return wxT("WM_SETREDRAW");
6624 case 0x000C: return wxT("WM_SETTEXT");
6625 case 0x000D: return wxT("WM_GETTEXT");
6626 case 0x000E: return wxT("WM_GETTEXTLENGTH");
6627 case 0x000F: return wxT("WM_PAINT");
6628 case 0x0010: return wxT("WM_CLOSE");
6629 case 0x0011: return wxT("WM_QUERYENDSESSION");
6630 case 0x0012: return wxT("WM_QUIT");
6631 case 0x0013: return wxT("WM_QUERYOPEN");
6632 case 0x0014: return wxT("WM_ERASEBKGND");
6633 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
6634 case 0x0016: return wxT("WM_ENDSESSION");
6635 case 0x0017: return wxT("WM_SYSTEMERROR");
6636 case 0x0018: return wxT("WM_SHOWWINDOW");
6637 case 0x0019: return wxT("WM_CTLCOLOR");
6638 case 0x001A: return wxT("WM_WININICHANGE");
6639 case 0x001B: return wxT("WM_DEVMODECHANGE");
6640 case 0x001C: return wxT("WM_ACTIVATEAPP");
6641 case 0x001D: return wxT("WM_FONTCHANGE");
6642 case 0x001E: return wxT("WM_TIMECHANGE");
6643 case 0x001F: return wxT("WM_CANCELMODE");
6644 case 0x0020: return wxT("WM_SETCURSOR");
6645 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6646 case 0x0022: return wxT("WM_CHILDACTIVATE");
6647 case 0x0023: return wxT("WM_QUEUESYNC");
6648 case 0x0024: return wxT("WM_GETMINMAXINFO");
6649 case 0x0026: return wxT("WM_PAINTICON");
6650 case 0x0027: return wxT("WM_ICONERASEBKGND");
6651 case 0x0028: return wxT("WM_NEXTDLGCTL");
6652 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6653 case 0x002B: return wxT("WM_DRAWITEM");
6654 case 0x002C: return wxT("WM_MEASUREITEM");
6655 case 0x002D: return wxT("WM_DELETEITEM");
6656 case 0x002E: return wxT("WM_VKEYTOITEM");
6657 case 0x002F: return wxT("WM_CHARTOITEM");
6658 case 0x0030: return wxT("WM_SETFONT");
6659 case 0x0031: return wxT("WM_GETFONT");
6660 case 0x0037: return wxT("WM_QUERYDRAGICON");
6661 case 0x0039: return wxT("WM_COMPAREITEM");
6662 case 0x0041: return wxT("WM_COMPACTING");
6663 case 0x0044: return wxT("WM_COMMNOTIFY");
6664 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6665 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6666 case 0x0048: return wxT("WM_POWER");
6668 case 0x004A: return wxT("WM_COPYDATA");
6669 case 0x004B: return wxT("WM_CANCELJOURNAL");
6670 case 0x004E: return wxT("WM_NOTIFY");
6671 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6672 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6673 case 0x0052: return wxT("WM_TCARD");
6674 case 0x0053: return wxT("WM_HELP");
6675 case 0x0054: return wxT("WM_USERCHANGED");
6676 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6677 case 0x007B: return wxT("WM_CONTEXTMENU");
6678 case 0x007C: return wxT("WM_STYLECHANGING");
6679 case 0x007D: return wxT("WM_STYLECHANGED");
6680 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6681 case 0x007F: return wxT("WM_GETICON");
6682 case 0x0080: return wxT("WM_SETICON");
6684 case 0x0081: return wxT("WM_NCCREATE");
6685 case 0x0082: return wxT("WM_NCDESTROY");
6686 case 0x0083: return wxT("WM_NCCALCSIZE");
6687 case 0x0084: return wxT("WM_NCHITTEST");
6688 case 0x0085: return wxT("WM_NCPAINT");
6689 case 0x0086: return wxT("WM_NCACTIVATE");
6690 case 0x0087: return wxT("WM_GETDLGCODE");
6691 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6692 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6693 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6694 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6695 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6696 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6697 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6698 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6699 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6700 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6702 case 0x00B0: return wxT("EM_GETSEL");
6703 case 0x00B1: return wxT("EM_SETSEL");
6704 case 0x00B2: return wxT("EM_GETRECT");
6705 case 0x00B3: return wxT("EM_SETRECT");
6706 case 0x00B4: return wxT("EM_SETRECTNP");
6707 case 0x00B5: return wxT("EM_SCROLL");
6708 case 0x00B6: return wxT("EM_LINESCROLL");
6709 case 0x00B7: return wxT("EM_SCROLLCARET");
6710 case 0x00B8: return wxT("EM_GETMODIFY");
6711 case 0x00B9: return wxT("EM_SETMODIFY");
6712 case 0x00BA: return wxT("EM_GETLINECOUNT");
6713 case 0x00BB: return wxT("EM_LINEINDEX");
6714 case 0x00BC: return wxT("EM_SETHANDLE");
6715 case 0x00BD: return wxT("EM_GETHANDLE");
6716 case 0x00BE: return wxT("EM_GETTHUMB");
6717 case 0x00C1: return wxT("EM_LINELENGTH");
6718 case 0x00C2: return wxT("EM_REPLACESEL");
6719 case 0x00C4: return wxT("EM_GETLINE");
6720 case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */
6721 case 0x00C6: return wxT("EM_CANUNDO");
6722 case 0x00C7: return wxT("EM_UNDO");
6723 case 0x00C8: return wxT("EM_FMTLINES");
6724 case 0x00C9: return wxT("EM_LINEFROMCHAR");
6725 case 0x00CB: return wxT("EM_SETTABSTOPS");
6726 case 0x00CC: return wxT("EM_SETPASSWORDCHAR");
6727 case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER");
6728 case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE");
6729 case 0x00CF: return wxT("EM_SETREADONLY");
6730 case 0x00D0: return wxT("EM_SETWORDBREAKPROC");
6731 case 0x00D1: return wxT("EM_GETWORDBREAKPROC");
6732 case 0x00D2: return wxT("EM_GETPASSWORDCHAR");
6733 case 0x00D3: return wxT("EM_SETMARGINS");
6734 case 0x00D4: return wxT("EM_GETMARGINS");
6735 case 0x00D5: return wxT("EM_GETLIMITTEXT");
6736 case 0x00D6: return wxT("EM_POSFROMCHAR");
6737 case 0x00D7: return wxT("EM_CHARFROMPOS");
6738 case 0x00D8: return wxT("EM_SETIMESTATUS");
6739 case 0x00D9: return wxT("EM_GETIMESTATUS");
6741 case 0x0100: return wxT("WM_KEYDOWN");
6742 case 0x0101: return wxT("WM_KEYUP");
6743 case 0x0102: return wxT("WM_CHAR");
6744 case 0x0103: return wxT("WM_DEADCHAR");
6745 case 0x0104: return wxT("WM_SYSKEYDOWN");
6746 case 0x0105: return wxT("WM_SYSKEYUP");
6747 case 0x0106: return wxT("WM_SYSCHAR");
6748 case 0x0107: return wxT("WM_SYSDEADCHAR");
6749 case 0x0108: return wxT("WM_KEYLAST");
6751 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6752 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6753 case 0x010F: return wxT("WM_IME_COMPOSITION");
6755 case 0x0110: return wxT("WM_INITDIALOG");
6756 case 0x0111: return wxT("WM_COMMAND");
6757 case 0x0112: return wxT("WM_SYSCOMMAND");
6758 case 0x0113: return wxT("WM_TIMER");
6759 case 0x0114: return wxT("WM_HSCROLL");
6760 case 0x0115: return wxT("WM_VSCROLL");
6761 case 0x0116: return wxT("WM_INITMENU");
6762 case 0x0117: return wxT("WM_INITMENUPOPUP");
6763 case 0x011F: return wxT("WM_MENUSELECT");
6764 case 0x0120: return wxT("WM_MENUCHAR");
6765 case 0x0121: return wxT("WM_ENTERIDLE");
6767 case 0x0127: return wxT("WM_CHANGEUISTATE");
6768 case 0x0128: return wxT("WM_UPDATEUISTATE");
6769 case 0x0129: return wxT("WM_QUERYUISTATE");
6771 case 0x0132: return wxT("WM_CTLCOLORMSGBOX");
6772 case 0x0133: return wxT("WM_CTLCOLOREDIT");
6773 case 0x0134: return wxT("WM_CTLCOLORLISTBOX");
6774 case 0x0135: return wxT("WM_CTLCOLORBTN");
6775 case 0x0136: return wxT("WM_CTLCOLORDLG");
6776 case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR");
6777 case 0x0138: return wxT("WM_CTLCOLORSTATIC");
6778 case 0x01E1: return wxT("MN_GETHMENU");
6780 case 0x0200: return wxT("WM_MOUSEMOVE");
6781 case 0x0201: return wxT("WM_LBUTTONDOWN");
6782 case 0x0202: return wxT("WM_LBUTTONUP");
6783 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6784 case 0x0204: return wxT("WM_RBUTTONDOWN");
6785 case 0x0205: return wxT("WM_RBUTTONUP");
6786 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6787 case 0x0207: return wxT("WM_MBUTTONDOWN");
6788 case 0x0208: return wxT("WM_MBUTTONUP");
6789 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6790 case 0x020A: return wxT("WM_MOUSEWHEEL");
6791 case 0x020B: return wxT("WM_XBUTTONDOWN");
6792 case 0x020C: return wxT("WM_XBUTTONUP");
6793 case 0x020D: return wxT("WM_XBUTTONDBLCLK");
6794 case 0x0210: return wxT("WM_PARENTNOTIFY");
6795 case 0x0211: return wxT("WM_ENTERMENULOOP");
6796 case 0x0212: return wxT("WM_EXITMENULOOP");
6798 case 0x0213: return wxT("WM_NEXTMENU");
6799 case 0x0214: return wxT("WM_SIZING");
6800 case 0x0215: return wxT("WM_CAPTURECHANGED");
6801 case 0x0216: return wxT("WM_MOVING");
6802 case 0x0218: return wxT("WM_POWERBROADCAST");
6803 case 0x0219: return wxT("WM_DEVICECHANGE");
6805 case 0x0220: return wxT("WM_MDICREATE");
6806 case 0x0221: return wxT("WM_MDIDESTROY");
6807 case 0x0222: return wxT("WM_MDIACTIVATE");
6808 case 0x0223: return wxT("WM_MDIRESTORE");
6809 case 0x0224: return wxT("WM_MDINEXT");
6810 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6811 case 0x0226: return wxT("WM_MDITILE");
6812 case 0x0227: return wxT("WM_MDICASCADE");
6813 case 0x0228: return wxT("WM_MDIICONARRANGE");
6814 case 0x0229: return wxT("WM_MDIGETACTIVE");
6815 case 0x0230: return wxT("WM_MDISETMENU");
6816 case 0x0233: return wxT("WM_DROPFILES");
6818 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6819 case 0x0282: return wxT("WM_IME_NOTIFY");
6820 case 0x0283: return wxT("WM_IME_CONTROL");
6821 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6822 case 0x0285: return wxT("WM_IME_SELECT");
6823 case 0x0286: return wxT("WM_IME_CHAR");
6824 case 0x0290: return wxT("WM_IME_KEYDOWN");
6825 case 0x0291: return wxT("WM_IME_KEYUP");
6827 case 0x02A0: return wxT("WM_NCMOUSEHOVER");
6828 case 0x02A1: return wxT("WM_MOUSEHOVER");
6829 case 0x02A2: return wxT("WM_NCMOUSELEAVE");
6830 case 0x02A3: return wxT("WM_MOUSELEAVE");
6832 case 0x0300: return wxT("WM_CUT");
6833 case 0x0301: return wxT("WM_COPY");
6834 case 0x0302: return wxT("WM_PASTE");
6835 case 0x0303: return wxT("WM_CLEAR");
6836 case 0x0304: return wxT("WM_UNDO");
6837 case 0x0305: return wxT("WM_RENDERFORMAT");
6838 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6839 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6840 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6841 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6842 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6843 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6844 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6845 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6846 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6847 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6848 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6849 case 0x0311: return wxT("WM_PALETTECHANGED");
6850 case 0x0312: return wxT("WM_HOTKEY");
6852 case 0x0317: return wxT("WM_PRINT");
6853 case 0x0318: return wxT("WM_PRINTCLIENT");
6855 // common controls messages - although they're not strictly speaking
6856 // standard, it's nice to decode them nevertheless
6859 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6860 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6861 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6862 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6863 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6864 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6865 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6866 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6867 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6868 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6869 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6870 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6871 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6872 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6873 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6874 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6875 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6876 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6877 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6878 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6879 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6880 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6881 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6882 case 0x1000 + 18: return wxT("LVM_HITTEST");
6883 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6884 case 0x1000 + 20: return wxT("LVM_SCROLL");
6885 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6886 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6887 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6888 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6889 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6890 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6891 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6892 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6893 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6894 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6895 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6896 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6897 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6898 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6899 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6900 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6901 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6902 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6903 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6904 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6905 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6906 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6907 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6908 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6909 case 0x1000 + 42: return wxT("LVM_UPDATE");
6910 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6911 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6912 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6913 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6914 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6915 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6916 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6917 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6918 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6919 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6920 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6921 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6922 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6923 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6924 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6925 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6926 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6927 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6928 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6929 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6930 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6931 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6932 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6933 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6934 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6935 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6938 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6939 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6940 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6941 case 0x1100 + 2: return wxT("TVM_EXPAND");
6942 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6943 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6944 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6945 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6946 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6947 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6948 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6949 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6950 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6951 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6952 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6953 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6954 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6955 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6956 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6957 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6958 case 0x1100 + 17: return wxT("TVM_HITTEST");
6959 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6960 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6961 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6962 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6963 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6964 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6965 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6966 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6967 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6970 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6971 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6972 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6973 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6974 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6975 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6976 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6977 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6978 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6979 case 0x1200 + 6: return wxT("HDM_HITTEST");
6980 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6981 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6982 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6983 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6984 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6985 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6986 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6987 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6990 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6991 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6992 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6993 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6994 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6995 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6996 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6997 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6998 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6999 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
7000 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
7001 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
7002 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
7003 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
7004 case 0x1300 + 13: return wxT("TCM_HITTEST");
7005 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
7006 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
7007 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
7008 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
7009 case 0x1300 + 43: return wxT("TCM_SETPADDING");
7010 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
7011 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
7012 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
7013 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
7014 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
7015 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
7016 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
7019 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
7020 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
7021 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
7022 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
7023 case WM_USER
+5: return wxT("TB_INDETERMINATE");
7024 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
7025 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
7026 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
7027 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
7028 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
7029 case WM_USER
+17: return wxT("TB_SETSTATE");
7030 case WM_USER
+18: return wxT("TB_GETSTATE");
7031 case WM_USER
+19: return wxT("TB_ADDBITMAP");
7032 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
7033 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
7034 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
7035 case WM_USER
+23: return wxT("TB_GETBUTTON");
7036 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
7037 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
7038 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
7039 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
7040 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
7041 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
7042 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
7043 case WM_USER
+29: return wxT("TB_GETITEMRECT");
7044 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
7045 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
7046 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
7047 case WM_USER
+33: return wxT("TB_AUTOSIZE");
7048 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
7049 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
7050 case WM_USER
+37: return wxT("TB_SETPARENT");
7051 case WM_USER
+39: return wxT("TB_SETROWS");
7052 case WM_USER
+40: return wxT("TB_GETROWS");
7053 case WM_USER
+42: return wxT("TB_SETCMDID");
7054 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
7055 case WM_USER
+44: return wxT("TB_GETBITMAP");
7056 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
7057 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
7058 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
7059 case WM_USER
+47: return wxT("TB_SETINDENT");
7060 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
7061 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
7062 case WM_USER
+50: return wxT("TB_LOADIMAGES");
7063 case WM_USER
+51: return wxT("TB_GETRECT");
7064 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
7065 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
7066 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
7067 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
7068 case WM_USER
+56: return wxT("TB_SETSTYLE");
7069 case WM_USER
+57: return wxT("TB_GETSTYLE");
7070 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
7071 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
7072 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
7073 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
7074 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
7077 static wxString s_szBuf
;
7078 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
7079 return s_szBuf
.c_str();
7082 #endif // wxDEBUG_LEVEL >= 2
7084 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
7088 HWND hwnd
= GetHwndOf(win
);
7089 HDC hdc
= ::GetDC(hwnd
);
7091 #if !wxDIALOG_UNIT_COMPATIBILITY
7092 // and select the current font into it
7093 HFONT hfont
= GetHfontOf(win
->GetFont());
7096 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
7100 // finally retrieve the text metrics from it
7101 GetTextMetrics(hdc
, &tm
);
7103 #if !wxDIALOG_UNIT_COMPATIBILITY
7107 (void)::SelectObject(hdc
, hfont
);
7111 ::ReleaseDC(hwnd
, hdc
);
7116 // Find the wxWindow at the current mouse position, returning the mouse
7118 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
7120 pt
= wxGetMousePosition();
7121 return wxFindWindowAtPoint(pt
);
7124 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
7130 HWND hWnd
= ::WindowFromPoint(pt2
);
7132 return wxGetWindowFromHWND((WXHWND
)hWnd
);
7135 // Get the current mouse position.
7136 wxPoint
wxGetMousePosition()
7140 GetCursorPosWinCE(&pt
);
7142 GetCursorPos( & pt
);
7145 return wxPoint(pt
.x
, pt
.y
);
7150 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7151 static void WinCEUnregisterHotKey(int modifiers
, int id
)
7153 // Register hotkeys for the hardware buttons
7155 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
7157 UnregisterFunc1Proc procUnregisterFunc
;
7158 hCoreDll
= LoadLibrary(wxT("coredll.dll"));
7161 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, wxT("UnregisterFunc1"));
7162 if (procUnregisterFunc
)
7163 procUnregisterFunc(modifiers
, id
);
7164 FreeLibrary(hCoreDll
);
7169 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
7171 UINT win_modifiers
=0;
7172 if ( modifiers
& wxMOD_ALT
)
7173 win_modifiers
|= MOD_ALT
;
7174 if ( modifiers
& wxMOD_SHIFT
)
7175 win_modifiers
|= MOD_SHIFT
;
7176 if ( modifiers
& wxMOD_CONTROL
)
7177 win_modifiers
|= MOD_CONTROL
;
7178 if ( modifiers
& wxMOD_WIN
)
7179 win_modifiers
|= MOD_WIN
;
7181 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7182 // Required for PPC and Smartphone hardware buttons
7183 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
7184 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
7187 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
7189 wxLogLastError(wxT("RegisterHotKey"));
7197 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
7199 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
7200 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
7203 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
7205 wxLogLastError(wxT("UnregisterHotKey"));
7215 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
7217 int win_modifiers
= LOWORD(lParam
);
7219 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, HIWORD(lParam
)));
7220 event
.SetId(wParam
);
7221 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
7222 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
7223 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
7224 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
7226 return HandleWindowEvent(event
);
7229 #endif // wxUSE_ACCEL
7231 #endif // wxUSE_HOTKEY
7233 // Not tested under WinCE
7236 // this class installs a message hook which really wakes up our idle processing
7237 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
7238 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
7239 // being dragged or even inside ::MessageBox()) and so don't control message
7240 // dispatching otherwise
7241 class wxIdleWakeUpModule
: public wxModule
7244 virtual bool OnInit()
7246 ms_hMsgHookProc
= ::SetWindowsHookEx
7249 &wxIdleWakeUpModule::MsgHookProc
,
7251 GetCurrentThreadId()
7254 if ( !ms_hMsgHookProc
)
7256 wxLogLastError(wxT("SetWindowsHookEx(WH_GETMESSAGE)"));
7264 virtual void OnExit()
7266 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
7269 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
7271 MSG
*msg
= (MSG
*)lParam
;
7273 // only process the message if it is actually going to be removed from
7274 // the message queue, this prevents that the same event from being
7275 // processed multiple times if now someone just called PeekMessage()
7276 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
7278 wxTheApp
->ProcessPendingEvents();
7281 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
7285 static HHOOK ms_hMsgHookProc
;
7287 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
7290 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
7292 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
7294 #endif // __WXWINCE__
7299 static void wxAdjustZOrder(wxWindow
* parent
)
7301 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
7303 // Set the z-order correctly
7304 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
7307 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
7310 wxWindow
*childWin
= current
->GetData();
7311 wxAdjustZOrder(childWin
);
7312 current
= current
->GetNext();
7317 // We need to adjust the z-order of static boxes in WinCE, to
7318 // make 'contained' controls visible
7319 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
7322 wxAdjustZOrder(this);