1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/window.cpp
3 // Purpose: wxWindowMSW
4 // Author: Julian Smart
5 // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/window.h"
30 #include "wx/msw/wrapwin.h"
31 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/msw/missing.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcmemory.h"
40 #include "wx/layout.h"
41 #include "wx/dialog.h"
43 #include "wx/listbox.h"
44 #include "wx/button.h"
45 #include "wx/msgdlg.h"
46 #include "wx/settings.h"
47 #include "wx/statbox.h"
51 #include "wx/textctrl.h"
52 #include "wx/menuitem.h"
53 #include "wx/module.h"
56 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
57 #include "wx/ownerdrw.h"
60 #include "wx/hashmap.h"
61 #include "wx/evtloop.h"
63 #include "wx/sysopt.h"
65 #if wxUSE_DRAG_AND_DROP
69 #if wxUSE_ACCESSIBILITY
70 #include "wx/access.h"
74 #define WM_GETOBJECT 0x003D
77 #define OBJID_CLIENT 0xFFFFFFFC
81 #include "wx/msw/private.h"
82 #include "wx/msw/dcclient.h"
85 #include "wx/tooltip.h"
93 #include "wx/spinctrl.h"
94 #endif // wxUSE_SPINCTRL
96 #include "wx/notebook.h"
97 #include "wx/listctrl.h"
98 #include "wx/dynlib.h"
102 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
103 #include <shellapi.h>
104 #include <mmsystem.h>
108 #include <windowsx.h>
111 #if !defined __WXWINCE__ && !defined NEED_PBT_H
115 #if defined(__WXWINCE__)
116 #include "wx/msw/wince/missing.h"
119 #include <shellapi.h>
121 #include <aygshell.h>
126 #include "wx/msw/uxtheme.h"
127 #define EP_EDITTEXT 1
130 #define ETS_SELECTED 3
131 #define ETS_DISABLED 4
132 #define ETS_FOCUSED 5
133 #define ETS_READONLY 6
137 // define the constants used by AnimateWindow() if our SDK doesn't have them
139 #define AW_HOR_POSITIVE 0x00000001
140 #define AW_HOR_NEGATIVE 0x00000002
141 #define AW_VER_POSITIVE 0x00000004
142 #define AW_VER_NEGATIVE 0x00000008
143 #define AW_CENTER 0x00000010
144 #define AW_HIDE 0x00010000
145 #define AW_ACTIVATE 0x00020000
146 #define AW_SLIDE 0x00040000
147 #define AW_BLEND 0x00080000
150 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS
151 #define HAVE_TRACKMOUSEEVENT
152 #endif // everything needed for TrackMouseEvent()
154 // if this is set to 1, we use deferred window sizing to reduce flicker when
155 // resizing complicated window hierarchies, but this can in theory result in
156 // different behaviour than the old code so we keep the possibility to use it
157 // by setting this to 0 (in the future this should be removed completely)
159 #define USE_DEFERRED_SIZING 0
161 #define USE_DEFERRED_SIZING 1
164 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
165 // when mouse position didnd't change
167 #define wxUSE_MOUSEEVENT_HACK 0
169 #define wxUSE_MOUSEEVENT_HACK 1
172 // not all compilers/platforms have X button related declarations (notably
173 // Windows CE doesn't, and probably some old SDKs don't neither)
174 #ifdef WM_XBUTTONDOWN
175 #define wxHAS_XBUTTON
178 // ---------------------------------------------------------------------------
180 // ---------------------------------------------------------------------------
182 #if wxUSE_MENUS_NATIVE
183 extern wxMenu
*wxCurrentPopupMenu
;
186 // true if we had already created the std colour map, used by
187 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
188 static bool gs_hasStdCmap
= false;
190 // last mouse event information we need to filter out the duplicates
191 #if wxUSE_MOUSEEVENT_HACK
192 static struct MouseEventInfoDummy
194 // mouse position (in screen coordinates)
197 // last mouse event type
200 #endif // wxUSE_MOUSEEVENT_HACK
202 // hash containing the registered handlers for the custom messages
203 WX_DECLARE_HASH_MAP(int, wxWindow::MSWMessageHandler
,
204 wxIntegerHash
, wxIntegerEqual
,
207 static MSWMessageHandlers gs_messageHandlers
;
209 // hash containing all our windows, it uses HWND keys and wxWindow* values
210 WX_DECLARE_HASH_MAP(HWND
, wxWindow
*,
211 wxPointerHash
, wxPointerEqual
,
214 static WindowHandles gs_windowHandles
;
216 // ---------------------------------------------------------------------------
218 // ---------------------------------------------------------------------------
220 // the window proc for all our windows
221 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
222 WPARAM wParam
, LPARAM lParam
);
225 #if wxDEBUG_LEVEL >= 2
226 const wxChar
*wxGetMessageName(int message
);
227 #endif // wxDEBUG_LEVEL >= 2
229 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
230 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
232 // get the text metrics for the current font
233 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
236 // find the window for the mouse event at the specified position
237 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
238 #endif // __WXWINCE__
240 // wrapper around BringWindowToTop() API
241 static inline void wxBringWindowToTop(HWND hwnd
)
243 #ifdef __WXMICROWIN__
244 // It seems that MicroWindows brings the _parent_ of the window to the top,
245 // which can be the wrong one.
247 // activate (set focus to) specified window
251 // raise top level parent to top of z order
252 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
254 wxLogLastError(_T("SetWindowPos"));
260 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
261 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
264 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
265 parent as well as otherwise several Win32 functions using
266 GetNextDlgTabItem() to iterate over all controls such as
267 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
268 all of them iterate over all the controls starting from the currently
269 focused one and stop iterating when they get back to the focus but
270 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
271 get back to the initial (focused) window: as we do have this style,
272 GetNextDlgTabItem() will leave this window and continue in its parent,
273 but if the parent doesn't have it, it wouldn't recurse inside it later
274 on and so wouldn't have a chance of getting back to this window either.
276 while ( parent
&& !parent
->IsTopLevel() )
278 LONG exStyle
= wxGetWindowExStyle(parent
);
279 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
281 // force the parent to have this style
282 wxSetWindowExStyle(parent
, exStyle
| WS_EX_CONTROLPARENT
);
285 parent
= parent
->GetParent();
289 #endif // !__WXWINCE__
292 // On Windows CE, GetCursorPos can return an error, so use this function
294 bool GetCursorPosWinCE(POINT
* pt
)
296 if (!GetCursorPos(pt
))
298 DWORD pos
= GetMessagePos();
306 // ---------------------------------------------------------------------------
308 // ---------------------------------------------------------------------------
310 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
312 #ifdef __WXUNIVERSAL__
313 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
315 #if wxUSE_EXTENDED_RTTI
317 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
318 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
319 // windows with negative ids never can be recreated anyway
321 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
323 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
324 if ( win
&& win
->GetId() < 0 )
329 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
331 // make wxWindowList known before the property is used
333 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
335 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
337 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
340 WX_DEFINE_FLAGS( wxWindowStyle
)
342 wxBEGIN_FLAGS( wxWindowStyle
)
343 // new style border flags, we put them first to
344 // use them for streaming out
346 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
347 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
348 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
349 wxFLAGS_MEMBER(wxBORDER_RAISED
)
350 wxFLAGS_MEMBER(wxBORDER_STATIC
)
351 wxFLAGS_MEMBER(wxBORDER_NONE
)
353 // old style border flags
354 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
355 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
356 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
357 wxFLAGS_MEMBER(wxRAISED_BORDER
)
358 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
359 wxFLAGS_MEMBER(wxBORDER
)
361 // standard window styles
362 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
363 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
364 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
365 wxFLAGS_MEMBER(wxWANTS_CHARS
)
366 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
367 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
368 wxFLAGS_MEMBER(wxVSCROLL
)
369 wxFLAGS_MEMBER(wxHSCROLL
)
371 wxEND_FLAGS( wxWindowStyle
)
373 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
374 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
375 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
376 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
377 // Always constructor Properties first
379 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
380 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
381 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
382 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
383 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
385 // Then all relations of the object graph
387 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
389 // and finally all other properties
391 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
392 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
393 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
394 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
395 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
397 // possible property candidates (not in xrc) or not valid in all subclasses
398 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
399 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
400 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
401 // MaxHeight, Width , MinHeight , Width
402 // TODO switch label to control and title to toplevels
404 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
405 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
406 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
407 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
412 wxEND_PROPERTIES_TABLE()
414 wxBEGIN_HANDLERS_TABLE(wxWindow
)
415 wxEND_HANDLERS_TABLE()
417 wxCONSTRUCTOR_DUMMY(wxWindow
)
420 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
422 #endif // __WXUNIVERSAL__/__WXMSW__
424 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
425 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
426 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground
)
428 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
432 // ===========================================================================
434 // ===========================================================================
436 // ---------------------------------------------------------------------------
437 // wxWindow utility functions
438 // ---------------------------------------------------------------------------
440 // Find an item given the MS Windows id
441 wxWindow
*wxWindowMSW::FindItem(long id
) const
444 wxControl
*item
= wxDynamicCastThis(wxControl
);
447 // is it us or one of our "internal" children?
448 if ( item
->GetId() == id
449 #ifndef __WXUNIVERSAL__
450 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
451 #endif // __WXUNIVERSAL__
457 #endif // wxUSE_CONTROLS
459 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
462 wxWindow
*childWin
= current
->GetData();
464 wxWindow
*wnd
= childWin
->FindItem(id
);
468 current
= current
->GetNext();
474 // Find an item given the MS Windows handle
475 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
477 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
480 wxWindow
*parent
= current
->GetData();
482 // Do a recursive search.
483 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
489 || parent
->IsKindOf(CLASSINFO(wxControl
))
490 #endif // wxUSE_CONTROLS
493 wxWindow
*item
= current
->GetData();
494 if ( item
->GetHWND() == hWnd
)
498 if ( item
->ContainsHWND(hWnd
) )
503 current
= current
->GetNext();
508 // Default command handler
509 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
514 // ----------------------------------------------------------------------------
515 // constructors and such
516 // ----------------------------------------------------------------------------
518 void wxWindowMSW::Init()
522 m_mouseInWindow
= false;
523 m_lastKeydownProcessed
= false;
531 m_pendingPosition
= wxDefaultPosition
;
532 m_pendingSize
= wxDefaultSize
;
535 m_contextMenuEnabled
= false;
540 wxWindowMSW::~wxWindowMSW()
544 #ifndef __WXUNIVERSAL__
545 // VS: make sure there's no wxFrame with last focus set to us:
546 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
548 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
551 if ( frame
->GetLastFocus() == this )
553 frame
->SetLastFocus(NULL
);
556 // apparently sometimes we can end up with our grand parent
557 // pointing to us as well: this is surely a bug in focus handling
558 // code but it's not clear where it happens so for now just try to
559 // fix it here by not breaking out of the loop
563 #endif // __WXUNIVERSAL__
565 // VS: destroy children first and _then_ detach *this from its parent.
566 // If we did it the other way around, children wouldn't be able
567 // find their parent frame (see above).
572 // VZ: test temp removed to understand what really happens here
573 //if (::IsWindow(GetHwnd()))
575 if ( !::DestroyWindow(GetHwnd()) )
576 wxLogLastError(wxT("DestroyWindow"));
579 // remove hWnd <-> wxWindow association
580 wxRemoveHandleAssociation(this);
586 const wxChar
*wxWindowMSW::MSWGetRegisteredClassName()
588 return wxApp::GetRegisteredClassName(_T("wxWindow"), COLOR_BTNFACE
);
591 // real construction (Init() must have been called before!)
592 bool wxWindowMSW::Create(wxWindow
*parent
,
597 const wxString
& name
)
599 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
601 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
604 parent
->AddChild(this);
607 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
609 #ifdef __WXUNIVERSAL__
610 // no borders, we draw them ourselves
611 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
615 msflags
&= ~WS_BORDER
;
616 #endif // wxUniversal
620 msflags
|= WS_VISIBLE
;
623 if ( !MSWCreate(MSWGetRegisteredClassName(),
624 NULL
, pos
, size
, msflags
, exstyle
) )
632 // ---------------------------------------------------------------------------
634 // ---------------------------------------------------------------------------
636 void wxWindowMSW::SetFocus()
638 HWND hWnd
= GetHwnd();
639 wxCHECK_RET( hWnd
, _T("can't set focus to invalid window") );
641 #if !defined(__WXWINCE__)
645 if ( !::SetFocus(hWnd
) )
647 // was there really an error?
648 DWORD dwRes
= ::GetLastError();
651 HWND hwndFocus
= ::GetFocus();
652 if ( hwndFocus
!= hWnd
)
654 wxLogApiError(_T("SetFocus"), dwRes
);
660 void wxWindowMSW::SetFocusFromKbd()
662 // when the focus is given to the control with DLGC_HASSETSEL style from
663 // keyboard its contents should be entirely selected: this is what
664 // ::IsDialogMessage() does and so we should do it as well to provide the
665 // same LNF as the native programs
666 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
668 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
671 // do this after (maybe) setting the selection as like this when
672 // wxEVT_SET_FOCUS handler is called, the selection would have been already
673 // set correctly -- this may be important
674 wxWindowBase::SetFocusFromKbd();
677 // Get the window with the focus
678 wxWindow
*wxWindowBase::DoFindFocus()
680 HWND hWnd
= ::GetFocus();
683 return wxGetWindowFromHWND((WXHWND
)hWnd
);
689 void wxWindowMSW::DoEnable( bool enable
)
691 HWND hWnd
= GetHwnd();
693 ::EnableWindow(hWnd
, (BOOL
)enable
);
696 bool wxWindowMSW::Show(bool show
)
698 if ( !wxWindowBase::Show(show
) )
701 HWND hWnd
= GetHwnd();
703 // we could be called before the underlying window is created (this is
704 // actually useful to prevent it from being initially shown), e.g.
706 // wxFoo *foo = new wxFoo;
708 // foo->Create(parent, ...);
710 // should work without errors
713 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
718 // DoFreeze/DoThaw don't do anything if the window is not shown, so
719 // we have to call them from here now
730 wxWindowMSW::MSWShowWithEffect(bool show
,
734 if ( !wxWindowBase::Show(show
) )
737 typedef BOOL (WINAPI
*AnimateWindow_t
)(HWND
, DWORD
, DWORD
);
739 static AnimateWindow_t s_pfnAnimateWindow
= NULL
;
740 static bool s_initDone
= false;
743 wxDynamicLibrary
dllUser32(_T("user32.dll"), wxDL_VERBATIM
| wxDL_QUIET
);
744 wxDL_INIT_FUNC(s_pfn
, AnimateWindow
, dllUser32
);
748 // notice that it's ok to unload user32.dll here as it won't be really
749 // unloaded, being still in use because we link to it statically too
752 if ( !s_pfnAnimateWindow
)
755 // Show() has a side effect of sending a WM_SIZE to the window, which helps
756 // ensuring that it's laid out correctly, but AnimateWindow() doesn't do
757 // this so send the event ourselves
760 // prepare to use AnimateWindow()
763 timeout
= 200; // this is the default animation timeout, per MSDN
765 DWORD dwFlags
= show
? 0 : AW_HIDE
;
769 case wxSHOW_EFFECT_ROLL_TO_LEFT
:
770 dwFlags
|= AW_HOR_NEGATIVE
;
773 case wxSHOW_EFFECT_ROLL_TO_RIGHT
:
774 dwFlags
|= AW_HOR_POSITIVE
;
777 case wxSHOW_EFFECT_ROLL_TO_TOP
:
778 dwFlags
|= AW_VER_NEGATIVE
;
781 case wxSHOW_EFFECT_ROLL_TO_BOTTOM
:
782 dwFlags
|= AW_VER_POSITIVE
;
785 case wxSHOW_EFFECT_SLIDE_TO_LEFT
:
786 dwFlags
|= AW_SLIDE
| AW_HOR_NEGATIVE
;
789 case wxSHOW_EFFECT_SLIDE_TO_RIGHT
:
790 dwFlags
|= AW_SLIDE
| AW_HOR_POSITIVE
;
793 case wxSHOW_EFFECT_SLIDE_TO_TOP
:
794 dwFlags
|= AW_SLIDE
| AW_VER_NEGATIVE
;
797 case wxSHOW_EFFECT_SLIDE_TO_BOTTOM
:
798 dwFlags
|= AW_SLIDE
| AW_VER_POSITIVE
;
801 case wxSHOW_EFFECT_BLEND
:
805 case wxSHOW_EFFECT_EXPAND
:
806 dwFlags
|= AW_CENTER
;
810 case wxSHOW_EFFECT_MAX
:
811 wxFAIL_MSG( _T("invalid window show effect") );
815 wxFAIL_MSG( _T("unknown window show effect") );
819 if ( !(*s_pfnAnimateWindow
)(GetHwnd(), timeout
, dwFlags
) )
821 wxLogLastError(_T("AnimateWindow"));
829 // Raise the window to the top of the Z order
830 void wxWindowMSW::Raise()
832 wxBringWindowToTop(GetHwnd());
835 // Lower the window to the bottom of the Z order
836 void wxWindowMSW::Lower()
838 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
839 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
842 void wxWindowMSW::DoCaptureMouse()
844 HWND hWnd
= GetHwnd();
851 void wxWindowMSW::DoReleaseMouse()
853 if ( !::ReleaseCapture() )
855 wxLogLastError(_T("ReleaseCapture"));
859 /* static */ wxWindow
*wxWindowBase::GetCapture()
861 HWND hwnd
= ::GetCapture();
862 return hwnd
? wxFindWinFromHandle(hwnd
) : NULL
;
865 bool wxWindowMSW::SetFont(const wxFont
& font
)
867 if ( !wxWindowBase::SetFont(font
) )
873 HWND hWnd
= GetHwnd();
876 // note the use of GetFont() instead of m_font: our own font could have
877 // just been reset and in this case we need to change the font used by
878 // the native window to the default for this class, i.e. exactly what
880 WXHANDLE hFont
= GetFont().GetResourceHandle();
882 wxASSERT_MSG( hFont
, wxT("should have valid font") );
884 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
889 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
891 if ( !wxWindowBase::SetCursor(cursor
) )
897 // don't "overwrite" busy cursor
898 if ( m_cursor
.Ok() && !wxIsBusy() )
900 // normally we should change the cursor only if it's over this window
901 // but we should do it always if we capture the mouse currently
902 bool set
= HasCapture();
905 HWND hWnd
= GetHwnd();
909 ::GetCursorPosWinCE(&point
);
911 ::GetCursorPos(&point
);
914 RECT rect
= wxGetWindowRect(hWnd
);
916 set
= ::PtInRect(&rect
, point
) != 0;
921 ::SetCursor(GetHcursorOf(m_cursor
));
923 //else: will be set later when the mouse enters this window
929 void wxWindowMSW::WarpPointer(int x
, int y
)
931 ClientToScreen(&x
, &y
);
933 if ( !::SetCursorPos(x
, y
) )
935 wxLogLastError(_T("SetCursorPos"));
939 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
941 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
942 // to use it on older systems -- and could possibly do some harm
943 static int s_needToUpdate
= -1;
944 if ( s_needToUpdate
== -1 )
947 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
951 if ( s_needToUpdate
)
953 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
954 // won't send WM_UPDATEUISTATE
955 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
959 // ---------------------------------------------------------------------------
961 // ---------------------------------------------------------------------------
966 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
968 #ifdef __WXMICROWIN__
969 return ::GetScrollPosWX(hWnd
, wOrient
);
971 WinStruct
<SCROLLINFO
> scrollInfo
;
972 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
973 scrollInfo
.fMask
= SIF_POS
;
974 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
976 return scrollInfo
.nPos
;
981 inline UINT
WXOrientToSB(int orient
)
983 return orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
;
986 } // anonymous namespace
988 int wxWindowMSW::GetScrollPos(int orient
) const
990 HWND hWnd
= GetHwnd();
991 wxCHECK_MSG( hWnd
, 0, _T("no HWND in GetScrollPos") );
993 return GetScrollPosition(hWnd
, WXOrientToSB(orient
));
996 // This now returns the whole range, not just the number
997 // of positions that we can scroll.
998 int wxWindowMSW::GetScrollRange(int orient
) const
1001 HWND hWnd
= GetHwnd();
1004 WinStruct
<SCROLLINFO
> scrollInfo
;
1005 scrollInfo
.fMask
= SIF_RANGE
;
1006 if ( !::GetScrollInfo(hWnd
, WXOrientToSB(orient
), &scrollInfo
) )
1008 // Most of the time this is not really an error, since the return
1009 // value can also be zero when there is no scrollbar yet.
1010 // wxLogLastError(_T("GetScrollInfo"));
1012 maxPos
= scrollInfo
.nMax
;
1014 // undo "range - 1" done in SetScrollbar()
1018 int wxWindowMSW::GetScrollThumb(int orient
) const
1020 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
1023 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
1025 HWND hWnd
= GetHwnd();
1026 wxCHECK_RET( hWnd
, _T("SetScrollPos: no HWND") );
1028 WinStruct
<SCROLLINFO
> info
;
1032 info
.fMask
= SIF_POS
;
1033 if ( HasFlag(wxALWAYS_SHOW_SB
) )
1035 // disable scrollbar instead of removing it then
1036 info
.fMask
|= SIF_DISABLENOSCROLL
;
1039 ::SetScrollInfo(hWnd
, WXOrientToSB(orient
), &info
, refresh
);
1042 // New function that will replace some of the above.
1043 void wxWindowMSW::SetScrollbar(int orient
,
1049 // We have to set the variables here to make them valid in events
1050 // triggered by ::SetScrollInfo()
1051 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
1053 HWND hwnd
= GetHwnd();
1057 WinStruct
<SCROLLINFO
> info
;
1060 info
.nPage
= pageSize
;
1061 info
.nMin
= 0; // range is nMax - nMin + 1
1062 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
1065 // enable the scrollbar if it had been disabled before by specifying
1066 // SIF_DISABLENOSCROLL below: as we can't know whether this had been
1067 // done or not just do it always
1068 ::EnableScrollBar(hwnd
, WXOrientToSB(orient
), ESB_ENABLE_BOTH
);
1070 //else: leave all the fields to be 0
1072 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
1073 if ( HasFlag(wxALWAYS_SHOW_SB
) || range
== -1 )
1075 // disable scrollbar instead of removing it then
1076 info
.fMask
|= SIF_DISABLENOSCROLL
;
1079 ::SetScrollInfo(hwnd
, WXOrientToSB(orient
), &info
, refresh
);
1082 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
1088 wxCopyRectToRECT(*prect
, rect
);
1098 // FIXME: is this the exact equivalent of the line below?
1099 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
1101 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
1105 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
1107 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
1110 for ( int n
= 0; n
< count
; n
++ )
1112 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
1114 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
1115 if ( posNew
== pos
)
1117 // don't bother to continue, we're already at top/bottom
1124 return pos
!= posStart
;
1127 bool wxWindowMSW::ScrollLines(int lines
)
1129 bool down
= lines
> 0;
1131 return ScrollVertically(GetHwnd(),
1132 down
? SB_LINEDOWN
: SB_LINEUP
,
1133 down
? lines
: -lines
);
1136 bool wxWindowMSW::ScrollPages(int pages
)
1138 bool down
= pages
> 0;
1140 return ScrollVertically(GetHwnd(),
1141 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1142 down
? pages
: -pages
);
1145 // ----------------------------------------------------------------------------
1147 // ----------------------------------------------------------------------------
1149 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
1154 wxCHECK_RET( GetHwnd(),
1155 _T("layout direction must be set after window creation") );
1157 LONG styleOld
= wxGetWindowExStyle(this);
1159 LONG styleNew
= styleOld
;
1162 case wxLayout_LeftToRight
:
1163 styleNew
&= ~WS_EX_LAYOUTRTL
;
1166 case wxLayout_RightToLeft
:
1167 styleNew
|= WS_EX_LAYOUTRTL
;
1171 wxFAIL_MSG(_T("unsupported layout direction"));
1175 if ( styleNew
!= styleOld
)
1177 wxSetWindowExStyle(this, styleNew
);
1182 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1185 return wxLayout_Default
;
1187 wxCHECK_MSG( GetHwnd(), wxLayout_Default
, _T("invalid window") );
1189 return wxHasWindowExStyle(this, WS_EX_LAYOUTRTL
) ? wxLayout_RightToLeft
1190 : wxLayout_LeftToRight
;
1195 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1196 wxCoord
WXUNUSED(width
),
1197 wxCoord
WXUNUSED(widthTotal
)) const
1199 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1200 // redo it ourselves
1204 // ---------------------------------------------------------------------------
1206 // ---------------------------------------------------------------------------
1208 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1210 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1212 HWND hwnd
= (HWND
)hWnd
;
1213 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1217 wxAssociateWinWithHandle(hwnd
, this);
1219 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1221 // we don't need to subclass the window of our own class (in the Windows
1222 // sense of the word)
1223 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1225 wxSetWindowProc(hwnd
, wxWndProc
);
1229 // don't bother restoring it either: this also makes it easy to
1230 // implement IsOfStandardClass() method which returns true for the
1231 // standard controls and false for the wxWidgets own windows as it can
1232 // simply check m_oldWndProc
1233 m_oldWndProc
= NULL
;
1236 // we're officially created now, send the event
1237 wxWindowCreateEvent
event((wxWindow
*)this);
1238 (void)HandleWindowEvent(event
);
1241 void wxWindowMSW::UnsubclassWin()
1243 wxRemoveHandleAssociation(this);
1245 // Restore old Window proc
1246 HWND hwnd
= GetHwnd();
1251 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1255 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1257 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1260 m_oldWndProc
= NULL
;
1265 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1269 if ( !::DestroyWindow(GetHwnd()) )
1270 wxLogLastError(wxT("DestroyWindow"));
1273 WXHWND wxhwnd
= (WXHWND
)handle
;
1275 // this also calls SetHWND(wxhwnd)
1276 SubclassWin(wxhwnd
);
1279 void wxWindowMSW::DissociateHandle()
1281 // this also calls SetHWND(0) for us
1286 bool wxCheckWindowWndProc(WXHWND hWnd
,
1287 WXFARPROC
WXUNUSED(wndProc
))
1289 const wxString
str(wxGetWindowClass(hWnd
));
1291 // TODO: get rid of wxTLWHiddenParent special case (currently it's not
1292 // registered by wxApp but using ad hoc code in msw/toplevel.cpp);
1293 // there is also a hidden window class used by sockets &c
1294 return wxApp::IsRegisteredClassName(str
) || str
== _T("wxTLWHiddenParent");
1297 // ----------------------------------------------------------------------------
1299 // ----------------------------------------------------------------------------
1301 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1303 long flagsOld
= GetWindowStyleFlag();
1304 if ( flags
== flagsOld
)
1307 // update the internal variable
1308 wxWindowBase::SetWindowStyleFlag(flags
);
1310 // and the real window flags
1311 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1314 void wxWindowMSW::SetExtraStyle(long exflags
)
1316 long exflagsOld
= GetExtraStyle();
1317 if ( exflags
== exflagsOld
)
1320 // update the internal variable
1321 wxWindowBase::SetExtraStyle(exflags
);
1323 // and the real window flags
1324 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1327 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1329 // now update the Windows style as well if needed - and if the window had
1330 // been already created
1334 // we may need to call SetWindowPos() when we change some styles
1335 bool callSWP
= false;
1338 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1340 // this is quite a horrible hack but we need it because MSWGetStyle()
1341 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1342 // and so we have to modify the window exflags temporarily to get the
1343 // correct exstyleOld
1344 long exflagsNew
= GetExtraStyle();
1345 wxWindowBase::SetExtraStyle(exflagsOld
);
1348 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1350 wxWindowBase::SetExtraStyle(exflagsNew
);
1353 if ( style
!= styleOld
)
1355 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1356 // this function so instead of simply setting the style to the new
1357 // value we clear the bits which were set in styleOld but are set in
1358 // the new one and set the ones which were not set before
1359 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1360 styleReal
&= ~styleOld
;
1363 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1365 // we need to call SetWindowPos() if any of the styles affecting the
1366 // frame appearance have changed
1367 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1376 // and the extended style
1377 long exstyleReal
= wxGetWindowExStyle(this);
1379 if ( exstyle
!= exstyleOld
)
1381 exstyleReal
&= ~exstyleOld
;
1382 exstyleReal
|= exstyle
;
1384 wxSetWindowExStyle(this, exstyleReal
);
1386 // ex style changes don't take effect without calling SetWindowPos
1392 // we must call SetWindowPos() to flush the cached extended style and
1393 // also to make the change to wxSTAY_ON_TOP style take effect: just
1394 // setting the style simply doesn't work
1395 if ( !::SetWindowPos(GetHwnd(),
1396 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1399 SWP_NOMOVE
| SWP_NOSIZE
| SWP_FRAMECHANGED
) )
1401 wxLogLastError(_T("SetWindowPos"));
1406 wxBorder
wxWindowMSW::GetDefaultBorderForControl() const
1408 return wxBORDER_THEME
;
1411 wxBorder
wxWindowMSW::GetDefaultBorder() const
1413 return wxWindowBase::GetDefaultBorder();
1416 // Translate wxBORDER_THEME (and other border styles if necessary) to the value
1417 // that makes most sense for this Windows environment
1418 wxBorder
wxWindowMSW::TranslateBorder(wxBorder border
) const
1420 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
1421 if (border
== wxBORDER_THEME
|| border
== wxBORDER_SUNKEN
|| border
== wxBORDER_SIMPLE
)
1422 return wxBORDER_SIMPLE
;
1424 return wxBORDER_NONE
;
1427 if (border
== wxBORDER_THEME
)
1429 if (CanApplyThemeBorder())
1431 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
1433 return wxBORDER_THEME
;
1435 return wxBORDER_SUNKEN
;
1443 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1445 // translate common wxWidgets styles to Windows ones
1447 // most of windows are child ones, those which are not (such as
1448 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1449 WXDWORD style
= WS_CHILD
;
1451 // using this flag results in very significant reduction in flicker,
1452 // especially with controls inside the static boxes (as the interior of the
1453 // box is not redrawn twice), but sometimes results in redraw problems, so
1454 // optionally allow the old code to continue to use it provided a special
1455 // system option is turned on
1456 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1457 || (flags
& wxCLIP_CHILDREN
) )
1458 style
|= WS_CLIPCHILDREN
;
1460 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1461 // don't support overlapping windows and it only makes sense for them and,
1462 // presumably, gives the system some extra work (to manage more clipping
1463 // regions), so avoid it alltogether
1466 if ( flags
& wxVSCROLL
)
1467 style
|= WS_VSCROLL
;
1469 if ( flags
& wxHSCROLL
)
1470 style
|= WS_HSCROLL
;
1472 const wxBorder border
= TranslateBorder(GetBorder(flags
));
1474 // After translation, border is now optimized for the specific version of Windows
1475 // and theme engine presence.
1477 // WS_BORDER is only required for wxBORDER_SIMPLE
1478 if ( border
== wxBORDER_SIMPLE
)
1481 // now deal with ext style if the caller wants it
1487 if ( flags
& wxTRANSPARENT_WINDOW
)
1488 *exstyle
|= WS_EX_TRANSPARENT
;
1494 case wxBORDER_DEFAULT
:
1495 wxFAIL_MSG( _T("unknown border style") );
1499 case wxBORDER_SIMPLE
:
1500 case wxBORDER_THEME
:
1503 case wxBORDER_STATIC
:
1504 *exstyle
|= WS_EX_STATICEDGE
;
1507 case wxBORDER_RAISED
:
1508 *exstyle
|= WS_EX_DLGMODALFRAME
;
1511 case wxBORDER_SUNKEN
:
1512 *exstyle
|= WS_EX_CLIENTEDGE
;
1513 style
&= ~WS_BORDER
;
1516 // case wxBORDER_DOUBLE:
1517 // *exstyle |= WS_EX_DLGMODALFRAME;
1521 // wxUniv doesn't use Windows dialog navigation functions at all
1522 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1523 // to make the dialog navigation work with the nested panels we must
1524 // use this style (top level windows such as dialogs don't need it)
1525 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1527 *exstyle
|= WS_EX_CONTROLPARENT
;
1529 #endif // __WXUNIVERSAL__
1535 // Setup background and foreground colours correctly
1536 void wxWindowMSW::SetupColours()
1539 SetBackgroundColour(GetParent()->GetBackgroundColour());
1542 bool wxWindowMSW::IsMouseInWindow() const
1544 // get the mouse position
1547 ::GetCursorPosWinCE(&pt
);
1549 ::GetCursorPos(&pt
);
1552 // find the window which currently has the cursor and go up the window
1553 // chain until we find this window - or exhaust it
1554 HWND hwnd
= ::WindowFromPoint(pt
);
1555 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1556 hwnd
= ::GetParent(hwnd
);
1558 return hwnd
!= NULL
;
1561 void wxWindowMSW::OnInternalIdle()
1563 #ifndef HAVE_TRACKMOUSEEVENT
1564 // Check if we need to send a LEAVE event
1565 if ( m_mouseInWindow
)
1567 // note that we should generate the leave event whether the window has
1568 // or doesn't have mouse capture
1569 if ( !IsMouseInWindow() )
1571 GenerateMouseLeave();
1574 #endif // !HAVE_TRACKMOUSEEVENT
1576 if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen())
1577 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1580 // Set this window to be the child of 'parent'.
1581 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1583 if ( !wxWindowBase::Reparent(parent
) )
1586 HWND hWndChild
= GetHwnd();
1587 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1589 ::SetParent(hWndChild
, hWndParent
);
1592 if ( wxHasWindowExStyle(this, WS_EX_CONTROLPARENT
) )
1594 EnsureParentHasControlParentStyle(GetParent());
1596 #endif // !__WXWINCE__
1601 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1603 #ifndef __WXMICROWIN__
1604 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1608 void wxWindowMSW::DoFreeze()
1611 return; // no point in freezing hidden window
1613 SendSetRedraw(GetHwnd(), false);
1616 void wxWindowMSW::DoThaw()
1619 return; // hidden windows aren't frozen by DoFreeze
1621 SendSetRedraw(GetHwnd(), true);
1623 // we need to refresh everything or otherwise the invalidated area
1624 // is not going to be repainted
1628 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1630 HWND hWnd
= GetHwnd();
1637 wxCopyRectToRECT(*rect
, mswRect
);
1645 // RedrawWindow not available on SmartPhone or eVC++ 3
1646 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1647 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1651 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1653 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1658 void wxWindowMSW::Update()
1660 if ( !::UpdateWindow(GetHwnd()) )
1662 wxLogLastError(_T("UpdateWindow"));
1665 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1666 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1667 // handler needs to be really drawn right now
1672 // ---------------------------------------------------------------------------
1674 // ---------------------------------------------------------------------------
1676 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1680 // we need to lower the sibling static boxes so controls contained within can be
1682 static void AdjustStaticBoxZOrder(wxWindow
*parent
)
1684 // no sibling static boxes if we have no parent (ie TLW)
1688 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1690 node
= node
->GetNext() )
1692 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1695 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1696 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1701 #else // !wxUSE_STATBOX
1703 static inline void AdjustStaticBoxZOrder(wxWindow
* WXUNUSED(parent
))
1707 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1709 #endif // drag and drop is used
1711 #if wxUSE_DRAG_AND_DROP
1712 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1714 if ( m_dropTarget
!= 0 ) {
1715 m_dropTarget
->Revoke(m_hWnd
);
1716 delete m_dropTarget
;
1719 m_dropTarget
= pDropTarget
;
1720 if ( m_dropTarget
!= 0 )
1722 AdjustStaticBoxZOrder(GetParent());
1723 m_dropTarget
->Register(m_hWnd
);
1726 #endif // wxUSE_DRAG_AND_DROP
1728 // old-style file manager drag&drop support: we retain the old-style
1729 // DragAcceptFiles in parallel with SetDropTarget.
1730 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1733 HWND hWnd
= GetHwnd();
1736 AdjustStaticBoxZOrder(GetParent());
1737 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1742 // ----------------------------------------------------------------------------
1744 // ----------------------------------------------------------------------------
1748 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1750 wxWindowBase::DoSetToolTip(tooltip
);
1753 m_tooltip
->SetWindow((wxWindow
*)this);
1756 #endif // wxUSE_TOOLTIPS
1758 // ---------------------------------------------------------------------------
1759 // moving and resizing
1760 // ---------------------------------------------------------------------------
1762 bool wxWindowMSW::IsSizeDeferred() const
1764 #if USE_DEFERRED_SIZING
1765 if ( m_pendingPosition
!= wxDefaultPosition
||
1766 m_pendingSize
!= wxDefaultSize
)
1768 #endif // USE_DEFERRED_SIZING
1774 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1776 #if USE_DEFERRED_SIZING
1777 // if SetSize() had been called at wx level but not realized at Windows
1778 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1779 // the new and not the old position to the other wx code
1780 if ( m_pendingSize
!= wxDefaultSize
)
1783 *x
= m_pendingSize
.x
;
1785 *y
= m_pendingSize
.y
;
1787 else // use current size
1788 #endif // USE_DEFERRED_SIZING
1790 RECT rect
= wxGetWindowRect(GetHwnd());
1793 *x
= rect
.right
- rect
.left
;
1795 *y
= rect
.bottom
- rect
.top
;
1799 // Get size *available for subwindows* i.e. excluding menu bar etc.
1800 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1802 #if USE_DEFERRED_SIZING
1803 if ( m_pendingSize
!= wxDefaultSize
)
1805 // we need to calculate the client size corresponding to pending size
1807 rect
.left
= m_pendingPosition
.x
;
1808 rect
.top
= m_pendingPosition
.y
;
1809 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1810 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1812 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1815 *x
= rect
.right
- rect
.left
;
1817 *y
= rect
.bottom
- rect
.top
;
1820 #endif // USE_DEFERRED_SIZING
1822 RECT rect
= wxGetClientRect(GetHwnd());
1831 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1833 wxWindow
* const parent
= GetParent();
1836 if ( m_pendingPosition
!= wxDefaultPosition
)
1838 pos
= m_pendingPosition
;
1840 else // use current position
1842 RECT rect
= wxGetWindowRect(GetHwnd());
1845 point
.x
= rect
.left
;
1848 // we do the adjustments with respect to the parent only for the "real"
1849 // children, not for the dialogs/frames
1850 if ( !IsTopLevel() )
1852 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
1854 // In RTL mode, we want the logical left x-coordinate,
1855 // which would be the physical right x-coordinate.
1856 point
.x
= rect
.right
;
1859 // Since we now have the absolute screen coords, if there's a
1860 // parent we must subtract its top left corner
1863 ::ScreenToClient(GetHwndOf(parent
), &point
);
1871 // we also must adjust by the client area offset: a control which is just
1872 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1873 if ( parent
&& !IsTopLevel() )
1875 const wxPoint
pt(parent
->GetClientAreaOrigin());
1886 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1894 ::ScreenToClient(GetHwnd(), &pt
);
1902 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1910 ::ClientToScreen(GetHwnd(), &pt
);
1919 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1921 #if USE_DEFERRED_SIZING
1922 // if our parent had prepared a defer window handle for us, use it (unless
1923 // we are a top level window)
1924 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1926 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1929 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1930 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1933 wxLogLastError(_T("DeferWindowPos"));
1939 // hdwp must be updated as it may have been changed
1940 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1945 // did deferred move, remember new coordinates of the window as they're
1946 // different from what Windows would return for it
1950 // otherwise (or if deferring failed) move the window in place immediately
1951 #endif // USE_DEFERRED_SIZING
1952 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
1954 wxLogLastError(wxT("MoveWindow"));
1957 // if USE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1958 // ignored otherwise
1962 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1964 // TODO: is this consistent with other platforms?
1965 // Still, negative width or height shouldn't be allowed
1971 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
1973 #if USE_DEFERRED_SIZING
1974 m_pendingPosition
= wxPoint(x
, y
);
1975 m_pendingSize
= wxSize(width
, height
);
1977 else // window was moved immediately, without deferring it
1979 m_pendingPosition
= wxDefaultPosition
;
1980 m_pendingSize
= wxDefaultSize
;
1981 #endif // USE_DEFERRED_SIZING
1985 // set the size of the window: if the dimensions are positive, just use them,
1986 // but if any of them is equal to -1, it means that we must find the value for
1987 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1988 // which case -1 is a valid value for x and y)
1990 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1991 // the width/height to best suit our contents, otherwise we reuse the current
1993 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1995 // get the current size and position...
1996 int currentX
, currentY
;
1997 int currentW
, currentH
;
1999 GetPosition(¤tX
, ¤tY
);
2000 GetSize(¤tW
, ¤tH
);
2002 // ... and don't do anything (avoiding flicker) if it's already ok unless
2003 // we're forced to resize the window
2004 if ( x
== currentX
&& y
== currentY
&&
2005 width
== currentW
&& height
== currentH
&&
2006 !(sizeFlags
& wxSIZE_FORCE
) )
2008 if (sizeFlags
& wxSIZE_FORCE_EVENT
)
2010 wxSizeEvent
event( wxSize(width
,height
), GetId() );
2011 event
.SetEventObject( this );
2012 HandleWindowEvent( event
);
2017 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2019 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
2022 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
2024 wxSize size
= wxDefaultSize
;
2025 if ( width
== wxDefaultCoord
)
2027 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
2029 size
= DoGetBestSize();
2034 // just take the current one
2039 if ( height
== wxDefaultCoord
)
2041 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
2043 if ( size
.x
== wxDefaultCoord
)
2045 size
= DoGetBestSize();
2047 //else: already called DoGetBestSize() above
2053 // just take the current one
2058 DoMoveWindow(x
, y
, width
, height
);
2061 void wxWindowMSW::DoSetClientSize(int width
, int height
)
2063 // setting the client size is less obvious than it could have been
2064 // because in the result of changing the total size the window scrollbar
2065 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
2066 // doesn't take neither into account) and so the client size will not be
2067 // correct as the difference between the total and client size changes --
2068 // so we keep changing it until we get it right
2070 // normally this loop shouldn't take more than 3 iterations (usually 1 but
2071 // if scrollbars [dis]appear as the result of the first call, then 2 and it
2072 // may become 3 if the window had 0 size originally and so we didn't
2073 // calculate the scrollbar correction correctly during the first iteration)
2074 // but just to be on the safe side we check for it instead of making it an
2075 // "infinite" loop (i.e. leaving break inside as the only way to get out)
2076 for ( int i
= 0; i
< 4; i
++ )
2079 ::GetClientRect(GetHwnd(), &rectClient
);
2081 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
2082 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
2083 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
2088 // Find the difference between the entire window (title bar and all)
2089 // and the client area; add this to the new client size to move the
2092 ::GetWindowRect(GetHwnd(), &rectWin
);
2094 const int widthWin
= rectWin
.right
- rectWin
.left
,
2095 heightWin
= rectWin
.bottom
- rectWin
.top
;
2097 // MoveWindow positions the child windows relative to the parent, so
2098 // adjust if necessary
2099 if ( !IsTopLevel() )
2101 wxWindow
*parent
= GetParent();
2104 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
2108 // don't call DoMoveWindow() because we want to move window immediately
2109 // and not defer it here as otherwise the value returned by
2110 // GetClient/WindowRect() wouldn't change as the window wouldn't be
2112 if ( !::MoveWindow(GetHwnd(),
2115 width
+ widthWin
- rectClient
.right
,
2116 height
+ heightWin
- rectClient
.bottom
,
2119 wxLogLastError(_T("MoveWindow"));
2124 // ---------------------------------------------------------------------------
2126 // ---------------------------------------------------------------------------
2128 int wxWindowMSW::GetCharHeight() const
2130 return wxGetTextMetrics(this).tmHeight
;
2133 int wxWindowMSW::GetCharWidth() const
2135 // +1 is needed because Windows apparently adds it when calculating the
2136 // dialog units size in pixels
2137 #if wxDIALOG_UNIT_COMPATIBILITY
2138 return wxGetTextMetrics(this).tmAveCharWidth
;
2140 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
2144 void wxWindowMSW::GetTextExtent(const wxString
& string
,
2146 int *descent
, int *externalLeading
,
2147 const wxFont
*fontToUse
) const
2149 wxASSERT_MSG( !fontToUse
|| fontToUse
->Ok(),
2150 _T("invalid font in GetTextExtent()") );
2154 hfontToUse
= GetHfontOf(*fontToUse
);
2156 hfontToUse
= GetHfontOf(GetFont());
2158 WindowHDC
hdc(GetHwnd());
2159 SelectInHDC
selectFont(hdc
, hfontToUse
);
2163 ::GetTextExtentPoint32(hdc
, string
.wx_str(), string
.length(), &sizeRect
);
2164 GetTextMetrics(hdc
, &tm
);
2171 *descent
= tm
.tmDescent
;
2172 if ( externalLeading
)
2173 *externalLeading
= tm
.tmExternalLeading
;
2176 // ---------------------------------------------------------------------------
2178 // ---------------------------------------------------------------------------
2180 #if wxUSE_MENUS_NATIVE
2182 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2183 // immediately, without waiting for the next event loop iteration
2185 // NB: this function should probably be made public later as it can almost
2186 // surely replace wxYield() elsewhere as well
2187 static void wxYieldForCommandsOnly()
2189 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2190 // want to process it here)
2192 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2194 if ( msg
.message
== WM_QUIT
)
2196 // if we retrieved a WM_QUIT, insert back into the message queue.
2197 ::PostQuitMessage(0);
2201 // luckily (as we don't have access to wxEventLoopImpl method from here
2202 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2204 ::TranslateMessage(&msg
);
2205 ::DispatchMessage(&msg
);
2209 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2211 menu
->SetInvokingWindow(this);
2214 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2216 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2217 x
= mouse
.x
; y
= mouse
.y
;
2220 HWND hWnd
= GetHwnd();
2221 HMENU hMenu
= GetHmenuOf(menu
);
2225 ::ClientToScreen(hWnd
, &point
);
2226 #if defined(__WXWINCE__)
2227 static const UINT flags
= 0;
2228 #else // !__WXWINCE__
2229 UINT flags
= TPM_RIGHTBUTTON
;
2230 // NT4 doesn't support TPM_RECURSE and simply doesn't show the menu at all
2231 // when it's use, I'm not sure about Win95/98 but prefer to err on the safe
2232 // side and not to use it there neither -- modify the test if it does work
2234 if ( wxGetWinVersion() >= wxWinVersion_5
)
2236 // using TPM_RECURSE allows us to show a popup menu while another menu
2237 // is opened which can be useful and is supported by the other
2238 // platforms, so allow it under Windows too
2239 flags
|= TPM_RECURSE
;
2241 #endif // __WXWINCE__/!__WXWINCE__
2243 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2245 // we need to do it right now as otherwise the events are never going to be
2246 // sent to wxCurrentPopupMenu from HandleCommand()
2248 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2249 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2250 // destroyed as soon as we return (it can be a local variable in the caller
2251 // for example) and so we do need to process the event immediately
2252 wxYieldForCommandsOnly();
2254 menu
->SetInvokingWindow(NULL
);
2259 #endif // wxUSE_MENUS_NATIVE
2261 // ===========================================================================
2262 // pre/post message processing
2263 // ===========================================================================
2265 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2268 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2270 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2273 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2275 // wxUniversal implements tab traversal itself
2276 #ifndef __WXUNIVERSAL__
2277 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2279 // intercept dialog navigation keys
2280 MSG
*msg
= (MSG
*)pMsg
;
2282 // here we try to do all the job which ::IsDialogMessage() usually does
2284 if ( msg
->message
== WM_KEYDOWN
)
2286 bool bCtrlDown
= wxIsCtrlDown();
2287 bool bShiftDown
= wxIsShiftDown();
2289 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2290 // don't process it if it's the case (except for Ctrl-Tab/Enter
2291 // combinations which are always processed)
2292 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2294 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2295 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2296 // it, of course, implies them
2297 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2299 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2302 bool bForward
= true,
2303 bWindowChange
= false,
2306 // should we process this message specially?
2307 bool bProcess
= true;
2308 switch ( msg
->wParam
)
2311 if ( (lDlgCode
& DLGC_WANTTAB
) && !bCtrlDown
)
2313 // let the control have the TAB
2316 else // use it for navigation
2318 // Ctrl-Tab cycles thru notebook pages
2319 bWindowChange
= bCtrlDown
;
2320 bForward
= !bShiftDown
;
2327 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2335 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2344 // we treat PageUp/Dn as arrows because chances are that
2345 // a control which needs arrows also needs them for
2346 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2347 if ( (lDlgCode
& DLGC_WANTARROWS
) && !bCtrlDown
)
2349 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
2350 bWindowChange
= true;
2356 // currently active button should get enter press even
2357 // if there is a default button elsewhere so check if
2358 // this window is a button first
2359 wxWindow
*btn
= NULL
;
2360 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2362 // let IsDialogMessage() handle this for all
2363 // buttons except the owner-drawn ones which it
2364 // just seems to ignore
2365 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2366 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2368 // emulate the button click
2369 btn
= wxFindWinFromHandle(msg
->hwnd
);
2374 else // not a button itself, do we have default button?
2376 // check if this window or any of its ancestors
2377 // wants the message for itself (we always reserve
2378 // Ctrl-Enter for dialog navigation though)
2379 wxWindow
*win
= this;
2382 // this will contain the dialog code of this
2383 // window and all of its parent windows in turn
2384 LONG lDlgCode2
= lDlgCode
;
2388 if ( lDlgCode2
& DLGC_WANTMESSAGE
)
2390 // as it wants to process Enter itself,
2391 // don't call IsDialogMessage() which
2396 // don't propagate keyboard messages beyond
2397 // the first top level window parent
2398 if ( win
->IsTopLevel() )
2401 win
= win
->GetParent();
2403 lDlgCode2
= ::SendMessage
2414 win
= wxGetTopLevelParent(win
);
2417 wxTopLevelWindow
* const
2418 tlw
= wxDynamicCast(win
, wxTopLevelWindow
);
2421 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2426 if ( btn
&& btn
->IsEnabled() )
2428 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2432 #endif // wxUSE_BUTTON
2435 // map Enter presses into button presses on PDAs
2436 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2437 event
.SetEventObject(this);
2438 if ( HandleWindowEvent(event
) )
2440 #endif // __WXWINCE__
2450 wxNavigationKeyEvent event
;
2451 event
.SetDirection(bForward
);
2452 event
.SetWindowChange(bWindowChange
);
2453 event
.SetFromTab(bFromTab
);
2454 event
.SetEventObject(this);
2456 if ( HandleWindowEvent(event
) )
2458 // as we don't call IsDialogMessage(), which would take of
2459 // this by default, we need to manually send this message
2460 // so that controls can change their UI state if needed
2461 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2468 if ( ::IsDialogMessage(GetHwnd(), msg
) )
2470 // IsDialogMessage() did something...
2474 #endif // __WXUNIVERSAL__
2479 // relay mouse move events to the tooltip control
2480 MSG
*msg
= (MSG
*)pMsg
;
2481 if ( msg
->message
== WM_MOUSEMOVE
)
2482 wxToolTip::RelayEvent(pMsg
);
2484 #endif // wxUSE_TOOLTIPS
2489 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2491 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2492 return m_acceleratorTable
.Translate(this, pMsg
);
2496 #endif // wxUSE_ACCEL
2499 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* msg
)
2501 // all tests below have to deal with various bugs/misfeatures of
2502 // IsDialogMessage(): we have to prevent it from being called from our
2503 // MSWProcessMessage() in some situations
2505 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2506 // message even when there is no cancel button and when the message is
2507 // needed by the control itself: in particular, it prevents the tree in
2508 // place edit control from being closed with Escape in a dialog
2509 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_ESCAPE
)
2514 // ::IsDialogMessage() is broken and may sometimes hang the application by
2515 // going into an infinite loop when it tries to find the control to give
2516 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2517 // situations when this may happen and not call it then
2518 if ( msg
->message
!= WM_SYSCHAR
)
2521 // assume we can call it by default
2522 bool canSafelyCallIsDlgMsg
= true;
2524 HWND hwndFocus
= ::GetFocus();
2526 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2527 // ::IsDialogMessage() will also enter an infinite loop, because it will
2528 // recursively check the child windows but not the window itself and so if
2529 // none of the children accepts focus it loops forever (as it only stops
2530 // when it gets back to the window it started from)
2532 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2533 // style has the focus, it can happen. One such possibility is if
2534 // all windows are either toplevel, wxDialog, wxPanel or static
2535 // controls and no window can actually accept keyboard input.
2536 #if !defined(__WXWINCE__)
2537 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2539 // pessimistic by default
2540 canSafelyCallIsDlgMsg
= false;
2541 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2543 node
= node
->GetNext() )
2545 wxWindow
* const win
= node
->GetData();
2546 if ( win
->CanAcceptFocus() &&
2547 !wxHasWindowExStyle(win
, WS_EX_CONTROLPARENT
) )
2549 // it shouldn't hang...
2550 canSafelyCallIsDlgMsg
= true;
2556 #endif // !__WXWINCE__
2558 if ( canSafelyCallIsDlgMsg
)
2560 // ::IsDialogMessage() can enter in an infinite loop when the
2561 // currently focused window is disabled or hidden and its
2562 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2566 if ( !::IsWindowEnabled(hwndFocus
) ||
2567 !::IsWindowVisible(hwndFocus
) )
2569 // it would enter an infinite loop if we do this!
2570 canSafelyCallIsDlgMsg
= false;
2575 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2577 // it's a top level window, don't go further -- e.g. even
2578 // if the parent of a dialog is disabled, this doesn't
2579 // break navigation inside the dialog
2583 hwndFocus
= ::GetParent(hwndFocus
);
2587 return canSafelyCallIsDlgMsg
;
2590 // ---------------------------------------------------------------------------
2591 // message params unpackers
2592 // ---------------------------------------------------------------------------
2594 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2595 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2597 *id
= LOWORD(wParam
);
2598 *hwnd
= (WXHWND
)lParam
;
2599 *cmd
= HIWORD(wParam
);
2602 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2603 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2605 *state
= LOWORD(wParam
);
2606 *minimized
= HIWORD(wParam
);
2607 *hwnd
= (WXHWND
)lParam
;
2610 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2611 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2613 *code
= LOWORD(wParam
);
2614 *pos
= HIWORD(wParam
);
2615 *hwnd
= (WXHWND
)lParam
;
2618 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2619 WXHDC
*hdc
, WXHWND
*hwnd
)
2621 *hwnd
= (WXHWND
)lParam
;
2622 *hdc
= (WXHDC
)wParam
;
2625 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2626 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2628 *item
= (WXWORD
)wParam
;
2629 *flags
= HIWORD(wParam
);
2630 *hmenu
= (WXHMENU
)lParam
;
2633 // ---------------------------------------------------------------------------
2634 // Main wxWidgets window proc and the window proc for wxWindow
2635 // ---------------------------------------------------------------------------
2637 // Hook for new window just as it's being created, when the window isn't yet
2638 // associated with the handle
2639 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2641 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2642 // window being created and insures that it's always unset back later
2643 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2645 gs_winBeingCreated
= winBeingCreated
;
2648 wxWindowCreationHook::~wxWindowCreationHook()
2650 gs_winBeingCreated
= NULL
;
2654 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2656 // trace all messages: useful for the debugging but noticeably slows down
2657 // the code so don't do it by default
2658 #if wxDEBUG_LEVEL >= 2
2659 wxLogTrace(wxTraceMessages
,
2660 wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"),
2661 wxGetMessageName(message
), hWnd
, (long)wParam
, lParam
);
2662 #endif // wxDEBUG_LEVEL >= 2
2664 wxWindowMSW
*wnd
= wxFindWinFromHandle(hWnd
);
2666 // when we get the first message for the HWND we just created, we associate
2667 // it with wxWindow stored in gs_winBeingCreated
2668 if ( !wnd
&& gs_winBeingCreated
)
2670 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2671 wnd
= gs_winBeingCreated
;
2672 gs_winBeingCreated
= NULL
;
2673 wnd
->SetHWND((WXHWND
)hWnd
);
2678 if ( wnd
&& wxGUIEventLoop::AllowProcessing(wnd
) )
2679 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2681 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2686 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2688 // did we process the message?
2689 bool processed
= false;
2699 // for most messages we should return 0 when we do process the message
2707 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2710 // return 0 to allow window creation
2711 rc
.result
= mayCreate
? 0 : -1;
2717 // never set processed to true and *always* pass WM_DESTROY to
2718 // DefWindowProc() as Windows may do some internal cleanup when
2719 // processing it and failing to pass the message along may cause
2720 // memory and resource leaks!
2721 (void)HandleDestroy();
2725 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2729 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2732 #if !defined(__WXWINCE__)
2735 LPRECT pRect
= (LPRECT
)lParam
;
2737 rc
.SetLeft(pRect
->left
);
2738 rc
.SetTop(pRect
->top
);
2739 rc
.SetRight(pRect
->right
);
2740 rc
.SetBottom(pRect
->bottom
);
2741 processed
= HandleMoving(rc
);
2743 pRect
->left
= rc
.GetLeft();
2744 pRect
->top
= rc
.GetTop();
2745 pRect
->right
= rc
.GetRight();
2746 pRect
->bottom
= rc
.GetBottom();
2751 case WM_ENTERSIZEMOVE
:
2753 processed
= HandleEnterSizeMove();
2757 case WM_EXITSIZEMOVE
:
2759 processed
= HandleExitSizeMove();
2765 LPRECT pRect
= (LPRECT
)lParam
;
2767 rc
.SetLeft(pRect
->left
);
2768 rc
.SetTop(pRect
->top
);
2769 rc
.SetRight(pRect
->right
);
2770 rc
.SetBottom(pRect
->bottom
);
2771 processed
= HandleSizing(rc
);
2773 pRect
->left
= rc
.GetLeft();
2774 pRect
->top
= rc
.GetTop();
2775 pRect
->right
= rc
.GetRight();
2776 pRect
->bottom
= rc
.GetBottom();
2780 #endif // !__WXWINCE__
2782 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2783 case WM_ACTIVATEAPP
:
2784 // This implicitly sends a wxEVT_ACTIVATE_APP event
2785 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2791 WXWORD state
, minimized
;
2793 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2795 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2800 processed
= HandleSetFocus((WXHWND
)wParam
);
2804 processed
= HandleKillFocus((WXHWND
)wParam
);
2807 case WM_PRINTCLIENT
:
2808 processed
= HandlePrintClient((WXHDC
)wParam
);
2814 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2816 processed
= HandlePaint();
2820 processed
= HandlePaint();
2825 #ifdef __WXUNIVERSAL__
2826 // Universal uses its own wxFrame/wxDialog, so we don't receive
2827 // close events unless we have this.
2829 #endif // __WXUNIVERSAL__
2831 // don't let the DefWindowProc() destroy our window - we'll do it
2832 // ourselves in ~wxWindow
2838 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2842 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2843 GET_Y_LPARAM(lParam
),
2847 #ifdef HAVE_TRACKMOUSEEVENT
2849 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2851 if ( m_mouseInWindow
)
2853 GenerateMouseLeave();
2856 // always pass processed back as false, this allows the window
2857 // manager to process the message too. This is needed to
2858 // ensure windows XP themes work properly as the mouse moves
2859 // over widgets like buttons. So don't set processed to true here.
2861 #endif // HAVE_TRACKMOUSEEVENT
2863 #if wxUSE_MOUSEWHEEL
2865 processed
= HandleMouseWheel(wParam
, lParam
);
2869 case WM_LBUTTONDOWN
:
2871 case WM_LBUTTONDBLCLK
:
2872 case WM_RBUTTONDOWN
:
2874 case WM_RBUTTONDBLCLK
:
2875 case WM_MBUTTONDOWN
:
2877 case WM_MBUTTONDBLCLK
:
2878 #ifdef wxHAS_XBUTTON
2879 case WM_XBUTTONDOWN
:
2881 case WM_XBUTTONDBLCLK
:
2882 #endif // wxHAS_XBUTTON
2884 #ifdef __WXMICROWIN__
2885 // MicroWindows seems to ignore the fact that a window is
2886 // disabled. So catch mouse events and throw them away if
2888 wxWindowMSW
* win
= this;
2891 if (!win
->IsEnabled())
2897 win
= win
->GetParent();
2898 if ( !win
|| win
->IsTopLevel() )
2905 #endif // __WXMICROWIN__
2906 int x
= GET_X_LPARAM(lParam
),
2907 y
= GET_Y_LPARAM(lParam
);
2910 // redirect the event to a static control if necessary by
2911 // finding one under mouse because under CE the static controls
2912 // don't generate mouse events (even with SS_NOTIFY)
2914 if ( GetCapture() == this )
2916 // but don't do it if the mouse is captured by this window
2917 // because then it should really get this event itself
2922 win
= FindWindowForMouseEvent(this, &x
, &y
);
2924 // this should never happen
2925 wxCHECK_MSG( win
, 0,
2926 _T("FindWindowForMouseEvent() returned NULL") );
2929 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
2931 SHRGINFO shrgi
= {0};
2933 shrgi
.cbSize
= sizeof(SHRGINFO
);
2934 shrgi
.hwndClient
= (HWND
) GetHWND();
2938 shrgi
.dwFlags
= SHRG_RETURNCMD
;
2939 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
2941 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
2944 pt
= ClientToScreen(pt
);
2946 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2948 evtCtx
.SetEventObject(this);
2949 if (HandleWindowEvent(evtCtx
))
2958 #else // !__WXWINCE__
2959 wxWindowMSW
*win
= this;
2960 #endif // __WXWINCE__/!__WXWINCE__
2962 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2964 // if the app didn't eat the event, handle it in the default
2965 // way, that is by giving this window the focus
2968 // for the standard classes their WndProc sets the focus to
2969 // them anyhow and doing it from here results in some weird
2970 // problems, so don't do it for them (unnecessary anyhow)
2971 if ( !win
->IsOfStandardClass() )
2973 if ( message
== WM_LBUTTONDOWN
&& win
->IsFocusable() )
2985 case MM_JOY1BUTTONDOWN
:
2986 case MM_JOY2BUTTONDOWN
:
2987 case MM_JOY1BUTTONUP
:
2988 case MM_JOY2BUTTONUP
:
2989 processed
= HandleJoystickEvent(message
,
2990 GET_X_LPARAM(lParam
),
2991 GET_Y_LPARAM(lParam
),
2994 #endif // __WXMICROWIN__
3000 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
3002 processed
= HandleCommand(id
, cmd
, hwnd
);
3007 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
3010 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
3011 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
3012 // apparently doesn't always behave properly and needs some help
3013 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
3014 case WM_NOTIFYFORMAT
:
3015 if ( lParam
== NF_QUERY
)
3018 rc
.result
= NFR_UNICODE
;
3021 #endif // wxUSE_UNICODE_MSLU
3023 // for these messages we must return true if process the message
3026 processed
= MSWOnDrawItem(wParam
, (WXDRAWITEMSTRUCT
*)lParam
);
3031 case WM_MEASUREITEM
:
3032 processed
= MSWOnMeasureItem(wParam
, (WXMEASUREITEMSTRUCT
*)lParam
);
3036 #endif // defined(WM_DRAWITEM)
3039 if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS
) )
3041 // we always want to get the char events
3042 rc
.result
= DLGC_WANTCHARS
;
3044 if ( HasFlag(wxWANTS_CHARS
) )
3046 // in fact, we want everything
3047 rc
.result
|= DLGC_WANTARROWS
|
3054 //else: get the dlg code from the DefWindowProc()
3059 // If this has been processed by an event handler, return 0 now
3060 // (we've handled it).
3061 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
3062 if ( m_lastKeydownProcessed
)
3071 // we consider these messages "not interesting" to OnChar, so
3072 // just don't do anything more with them
3082 // avoid duplicate messages to OnChar for these ASCII keys:
3083 // they will be translated by TranslateMessage() and received
3115 // but set processed to false, not true to still pass them
3116 // to the control's default window proc - otherwise
3117 // built-in keyboard handling won't work
3122 // special case of VK_APPS: treat it the same as right mouse
3123 // click because both usually pop up a context menu
3125 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
3130 // do generate a CHAR event
3131 processed
= HandleChar((WORD
)wParam
, lParam
);
3134 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
3141 // special case of VK_APPS: treat it the same as right mouse button
3142 if ( wParam
== VK_APPS
)
3144 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
3149 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
3154 case WM_CHAR
: // Always an ASCII character
3155 if ( m_lastKeydownProcessed
)
3157 // The key was handled in the EVT_KEY_DOWN and handling
3158 // a key in an EVT_KEY_DOWN handler is meant, by
3159 // design, to prevent EVT_CHARs from happening
3160 m_lastKeydownProcessed
= false;
3165 processed
= HandleChar((WORD
)wParam
, lParam
, true);
3171 processed
= HandleHotKey((WORD
)wParam
, lParam
);
3173 #endif // wxUSE_HOTKEY
3178 processed
= HandleClipboardEvent(message
);
3186 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
3188 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
3194 // CTLCOLOR messages are sent by children to query the parent for their
3196 #ifndef __WXMICROWIN__
3197 case WM_CTLCOLORMSGBOX
:
3198 case WM_CTLCOLOREDIT
:
3199 case WM_CTLCOLORLISTBOX
:
3200 case WM_CTLCOLORBTN
:
3201 case WM_CTLCOLORDLG
:
3202 case WM_CTLCOLORSCROLLBAR
:
3203 case WM_CTLCOLORSTATIC
:
3207 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
3209 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
3212 #endif // !__WXMICROWIN__
3214 case WM_SYSCOLORCHANGE
:
3215 // the return value for this message is ignored
3216 processed
= HandleSysColorChange();
3219 #if !defined(__WXWINCE__)
3220 case WM_DISPLAYCHANGE
:
3221 processed
= HandleDisplayChange();
3225 case WM_PALETTECHANGED
:
3226 processed
= HandlePaletteChanged((WXHWND
)wParam
);
3229 case WM_CAPTURECHANGED
:
3230 processed
= HandleCaptureChanged((WXHWND
)lParam
);
3233 case WM_SETTINGCHANGE
:
3234 processed
= HandleSettingChange(wParam
, lParam
);
3237 case WM_QUERYNEWPALETTE
:
3238 processed
= HandleQueryNewPalette();
3242 processed
= HandleEraseBkgnd((WXHDC
)wParam
);
3245 // we processed the message, i.e. erased the background
3250 #if !defined(__WXWINCE__)
3252 processed
= HandleDropFiles(wParam
);
3257 processed
= HandleInitDialog((WXHWND
)wParam
);
3261 // we never set focus from here
3266 #if !defined(__WXWINCE__)
3267 case WM_QUERYENDSESSION
:
3268 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3272 processed
= HandleEndSession(wParam
!= 0, lParam
);
3275 case WM_GETMINMAXINFO
:
3276 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3281 processed
= HandleSetCursor((WXHWND
)wParam
,
3282 LOWORD(lParam
), // hit test
3283 HIWORD(lParam
)); // mouse msg
3287 // returning TRUE stops the DefWindowProc() from further
3288 // processing this message - exactly what we need because we've
3289 // just set the cursor.
3294 #if wxUSE_ACCESSIBILITY
3297 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3298 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3300 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3302 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3308 #if defined(WM_HELP)
3311 // by default, WM_HELP is propagated by DefWindowProc() upwards
3312 // to the window parent but as we do it ourselves already
3313 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3314 // to get the other events if we process this message at all
3317 // WM_HELP doesn't use lParam under CE
3319 HELPINFO
* info
= (HELPINFO
*) lParam
;
3320 if ( info
->iContextType
== HELPINFO_WINDOW
)
3322 #endif // !__WXWINCE__
3323 wxHelpEvent helpEvent
3328 wxGetMousePosition() // what else?
3330 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3334 helpEvent
.SetEventObject(this);
3335 HandleWindowEvent(helpEvent
);
3338 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3340 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3341 helpEvent
.SetEventObject(this);
3342 HandleWindowEvent(helpEvent
);
3345 else // unknown help event?
3349 #endif // !__WXWINCE__
3354 #if !defined(__WXWINCE__)
3355 case WM_CONTEXTMENU
:
3357 // we don't convert from screen to client coordinates as
3358 // the event may be handled by a parent window
3359 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3361 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3363 // we could have got an event from our child, reflect it back
3364 // to it if this is the case
3365 wxWindowMSW
*win
= NULL
;
3366 WXHWND hWnd
= (WXHWND
)wParam
;
3367 if ( hWnd
!= m_hWnd
)
3369 win
= FindItemByHWND(hWnd
);
3375 evtCtx
.SetEventObject(win
);
3376 processed
= win
->HandleWindowEvent(evtCtx
);
3383 // we're only interested in our own menus, not MF_SYSMENU
3384 if ( HIWORD(wParam
) == MF_POPUP
)
3386 // handle menu chars for ownerdrawn menu items
3387 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3388 if ( i
!= wxNOT_FOUND
)
3390 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3395 #endif // wxUSE_MENUS
3398 case WM_POWERBROADCAST
:
3401 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3402 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3405 #endif // __WXWINCE__
3408 // If we want the default themed border then we need to draw it ourselves
3411 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3412 const wxBorder border
= TranslateBorder(GetBorder());
3413 if (theme
&& border
== wxBORDER_THEME
)
3415 // first ask the widget to calculate the border size
3416 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3419 // now alter the client size making room for drawing a
3424 NCCALCSIZE_PARAMS
*csparam
= (NCCALCSIZE_PARAMS
*)lParam
;
3425 rect
= &csparam
->rgrc
[0];
3429 rect
= (RECT
*)lParam
;
3432 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3433 RECT rcClient
= { 0, 0, 0, 0 };
3434 wxClientDC
dc((wxWindow
*)this);
3435 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3437 if ( theme
->GetThemeBackgroundContentRect
3444 &rcClient
) == S_OK
)
3446 InflateRect(&rcClient
, -1, -1);
3448 rc
.result
= WVR_REDRAW
;
3456 wxUxThemeEngine
* theme
= wxUxThemeEngine::GetIfActive();
3457 const wxBorder border
= TranslateBorder(GetBorder());
3458 if (theme
&& border
== wxBORDER_THEME
)
3460 // first ask the widget to paint its non-client area, such as scrollbars, etc.
3461 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3464 wxUxThemeHandle
hTheme((const wxWindow
*)this, L
"EDIT");
3465 wxWindowDC
dc((wxWindow
*)this);
3466 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
.GetImpl();
3468 // Clip the DC so that you only draw on the non-client area
3470 wxCopyRectToRECT(GetSize(), rcBorder
);
3473 theme
->GetThemeBackgroundContentRect(
3474 hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, ETS_NORMAL
, &rcBorder
, &rcClient
);
3475 InflateRect(&rcClient
, -1, -1);
3477 ::ExcludeClipRect(GetHdcOf(*impl
), rcClient
.left
, rcClient
.top
,
3478 rcClient
.right
, rcClient
.bottom
);
3480 // Make sure the background is in a proper state
3481 if (theme
->IsThemeBackgroundPartiallyTransparent(hTheme
, EP_EDITTEXT
, ETS_NORMAL
))
3483 theme
->DrawThemeParentBackground(GetHwnd(), GetHdcOf(*impl
), &rcBorder
);
3489 nState
= ETS_DISABLED
;
3490 // should we check this?
3491 //else if ( ::GetWindowLong(GetHwnd(), GWL_STYLE) & ES_READONLY)
3492 // nState = ETS_READONLY;
3494 nState
= ETS_NORMAL
;
3495 theme
->DrawThemeBackground(hTheme
, GetHdcOf(*impl
), EP_EDITTEXT
, nState
, &rcBorder
, NULL
);
3500 #endif // wxUSE_UXTHEME
3503 // try a custom message handler
3504 const MSWMessageHandlers::const_iterator
3505 i
= gs_messageHandlers
.find(message
);
3506 if ( i
!= gs_messageHandlers
.end() )
3508 processed
= (*i
->second
)(this, message
, wParam
, lParam
);
3514 #if wxDEBUG_LEVEL >= 2
3515 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
3516 wxGetMessageName(message
));
3517 #endif // wxDEBUG_LEVEL >= 2
3518 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3524 // ----------------------------------------------------------------------------
3525 // wxWindow <-> HWND map
3526 // ----------------------------------------------------------------------------
3528 wxWindow
*wxFindWinFromHandle(HWND hwnd
)
3530 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3531 return i
== gs_windowHandles
.end() ? NULL
: i
->second
;
3534 void wxAssociateWinWithHandle(HWND hwnd
, wxWindowMSW
*win
)
3536 // adding NULL hwnd is (first) surely a result of an error and
3537 // (secondly) breaks menu command processing
3538 wxCHECK_RET( hwnd
!= (HWND
)NULL
,
3539 wxT("attempt to add a NULL hwnd to window list ignored") );
3542 WindowHandles::const_iterator i
= gs_windowHandles
.find(hwnd
);
3543 if ( i
!= gs_windowHandles
.end() )
3545 if ( i
->second
!= win
)
3549 wxT("HWND %p already associated with another window (%s)"),
3550 hwnd
, win
->GetClassInfo()->GetClassName()
3554 //else: this actually happens currently because we associate the window
3555 // with its HWND during creation (if we create it) and also when
3556 // SubclassWin() is called later, this is ok
3558 #endif // wxDEBUG_LEVEL
3560 gs_windowHandles
[hwnd
] = (wxWindow
*)win
;
3563 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3565 gs_windowHandles
.erase(GetHwndOf(win
));
3568 // ----------------------------------------------------------------------------
3569 // various MSW speciic class dependent functions
3570 // ----------------------------------------------------------------------------
3572 // Default destroyer - override if you destroy it in some other way
3573 // (e.g. with MDI child windows)
3574 void wxWindowMSW::MSWDestroyWindow()
3578 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3581 int& w
, int& h
) const
3583 // yes, those are just some arbitrary hardcoded numbers
3584 static const int DEFAULT_Y
= 200;
3586 bool nonDefault
= false;
3588 if ( pos
.x
== wxDefaultCoord
)
3590 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
3591 // can just as well set it to CW_USEDEFAULT as well
3597 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
3598 // neither because it is not handled as a special value by Windows then
3599 // and so we have to choose some default value for it
3601 y
= pos
.y
== wxDefaultCoord
? DEFAULT_Y
: pos
.y
;
3607 NB: there used to be some code here which set the initial size of the
3608 window to the client size of the parent if no explicit size was
3609 specified. This was wrong because wxWidgets programs often assume
3610 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3611 it. To see why, you should understand that Windows sends WM_SIZE from
3612 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3613 from some base class ctor and so this WM_SIZE is not processed in the
3614 real class' OnSize() (because it's not fully constructed yet and the
3615 event goes to some base class OnSize() instead). So the WM_SIZE we
3616 rely on is the one sent when the parent frame resizes its children
3617 but here is the problem: if the child already has just the right
3618 size, nothing will happen as both wxWidgets and Windows check for
3619 this and ignore any attempts to change the window size to the size it
3620 already has - so no WM_SIZE would be sent.
3624 // we don't use CW_USEDEFAULT here for several reasons:
3626 // 1. it results in huge frames on modern screens (1000*800 is not
3627 // uncommon on my 1280*1024 screen) which is way too big for a half
3628 // empty frame of most of wxWidgets samples for example)
3630 // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
3631 // the default is for whatever reason 8*8 which breaks client <->
3632 // window size calculations (it would be nice if it didn't, but it
3633 // does and the simplest way to fix it seemed to change the broken
3634 // default size anyhow)
3636 // 3. there is just no advantage in doing it: with x and y it is
3637 // possible that [future versions of] Windows position the new top
3638 // level window in some smart way which we can't do, but we can
3639 // guess a reasonably good size for a new window just as well
3642 // However, on PocketPC devices, we must use the default
3643 // size if possible.
3645 if (size
.x
== wxDefaultCoord
)
3649 if (size
.y
== wxDefaultCoord
)
3654 if ( size
.x
== wxDefaultCoord
|| size
.y
== wxDefaultCoord
)
3658 w
= WidthDefault(size
.x
);
3659 h
= HeightDefault(size
.y
);
3662 AdjustForParentClientOrigin(x
, y
);
3667 WXHWND
wxWindowMSW::MSWGetParent() const
3669 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3672 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3673 const wxChar
*title
,
3677 WXDWORD extendedStyle
)
3679 // check a common bug in the user code: if the window is created with a
3680 // non-default ctor and Create() is called too, we'd create 2 HWND for a
3681 // single wxWindow object and this results in all sorts of trouble,
3682 // especially for wxTLWs
3683 wxCHECK_MSG( !m_hWnd
, true, "window can't be recreated" );
3685 // this can happen if this function is called using the return value of
3686 // wxApp::GetRegisteredClassName() which failed
3687 wxCHECK_MSG( wclass
, false, "failed to register window class?" );
3690 // choose the position/size for the new window
3692 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3694 // controlId is menu handle for the top level windows, so set it to 0
3695 // unless we're creating a child window
3696 int controlId
= style
& WS_CHILD
? GetId() : 0;
3698 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3699 // which is the same but without CS_[HV]REDRAW class styles so using it
3700 // ensures that the window is not fully repainted on each resize
3701 wxString
className(wclass
);
3702 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3704 className
+= wxApp::GetNoRedrawClassSuffix();
3707 // do create the window
3708 wxWindowCreationHook
hook(this);
3710 m_hWnd
= (WXHWND
)::CreateWindowEx
3714 title
? title
: m_windowName
.wx_str(),
3717 (HWND
)MSWGetParent(),
3718 (HMENU
)wxUIntToPtr(controlId
),
3720 NULL
// no extra data
3725 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3730 SubclassWin(m_hWnd
);
3735 // ===========================================================================
3736 // MSW message handlers
3737 // ===========================================================================
3739 // ---------------------------------------------------------------------------
3741 // ---------------------------------------------------------------------------
3743 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3745 #ifndef __WXMICROWIN__
3746 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3747 HWND hWnd
= hdr
->hwndFrom
;
3748 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
3750 // if the control is one of our windows, let it handle the message itself
3753 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3756 // VZ: why did we do it? normally this is unnecessary and, besides, it
3757 // breaks the message processing for the toolbars because the tooltip
3758 // notifications were being forwarded to the toolbar child controls
3759 // (if it had any) before being passed to the toolbar itself, so in my
3760 // example the tooltip for the combobox was always shown instead of the
3761 // correct button tooltips
3763 // try all our children
3764 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3767 wxWindow
*child
= node
->GetData();
3768 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3773 node
= node
->GetNext();
3777 // by default, handle it ourselves
3778 return MSWOnNotify(idCtrl
, lParam
, result
);
3779 #else // __WXMICROWIN__
3786 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3788 const wxString
& ttip
)
3790 // I don't know why it happens, but the versions of comctl32.dll starting
3791 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3792 // this message is supposed to be sent to Unicode programs only) -- hence
3793 // we need to handle it as well, otherwise no tooltips will be shown in
3796 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3799 // not a tooltip message or no tooltip to show anyhow
3804 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3806 // We don't want to use the szText buffer because it has a limit of 80
3807 // bytes and this is not enough, especially for Unicode build where it
3808 // limits the tooltip string length to only 40 characters
3810 // The best would be, of course, to not impose any length limitations at
3811 // all but then the buffer would have to be dynamic and someone would have
3812 // to free it and we don't have the tooltip owner object here any more, so
3813 // for now use our own static buffer with a higher fixed max length.
3815 // Note that using a static buffer should not be a problem as only a single
3816 // tooltip can be shown at the same time anyhow.
3818 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3820 // We need to convert tooltip from multi byte to Unicode on the fly.
3821 static wchar_t buf
[513];
3823 // Truncate tooltip length if needed as otherwise we might not have
3824 // enough space for it in the buffer and MultiByteToWideChar() would
3826 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3828 // Convert to WideChar without adding the NULL character. The NULL
3829 // character is added afterwards (this is more efficient).
3830 int len
= ::MultiByteToWideChar
3842 wxLogLastError(_T("MultiByteToWideChar()"));
3846 ttText
->lpszText
= (LPSTR
) buf
;
3848 else // TTN_NEEDTEXTA
3849 #endif // !wxUSE_UNICODE
3851 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3852 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3853 // to copy the string we have into the buffer
3854 static wxChar buf
[513];
3855 wxStrlcpy(buf
, ttip
.c_str(), WXSIZEOF(buf
));
3856 ttText
->lpszText
= buf
;
3862 #endif // wxUSE_TOOLTIPS
3864 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3866 WXLPARAM
* WXUNUSED(result
))
3871 NMHDR
* hdr
= (NMHDR
*)lParam
;
3872 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3879 wxUnusedVar(lParam
);
3880 #endif // wxUSE_TOOLTIPS
3885 // ---------------------------------------------------------------------------
3886 // end session messages
3887 // ---------------------------------------------------------------------------
3889 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3891 #ifdef ENDSESSION_LOGOFF
3892 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3893 event
.SetEventObject(wxTheApp
);
3894 event
.SetCanVeto(true);
3895 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3897 bool rc
= wxTheApp
->ProcessEvent(event
);
3901 // we may end only if the app didn't veto session closing (double
3903 *mayEnd
= !event
.GetVeto();
3908 wxUnusedVar(logOff
);
3909 wxUnusedVar(mayEnd
);
3914 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3916 #ifdef ENDSESSION_LOGOFF
3917 // do nothing if the session isn't ending
3922 if ( (this != wxTheApp
->GetTopWindow()) )
3925 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3926 event
.SetEventObject(wxTheApp
);
3927 event
.SetCanVeto(false);
3928 event
.SetLoggingOff((logOff
& ENDSESSION_LOGOFF
) != 0);
3930 return wxTheApp
->ProcessEvent(event
);
3932 wxUnusedVar(endSession
);
3933 wxUnusedVar(logOff
);
3938 // ---------------------------------------------------------------------------
3939 // window creation/destruction
3940 // ---------------------------------------------------------------------------
3942 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3945 // VZ: why is this commented out for WinCE? If it doesn't support
3946 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3947 // not with multiple #ifdef's!
3949 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3950 EnsureParentHasControlParentStyle(GetParent());
3951 #endif // !__WXWINCE__
3958 bool wxWindowMSW::HandleDestroy()
3960 // delete our drop target if we've got one
3961 #if wxUSE_DRAG_AND_DROP
3962 if ( m_dropTarget
!= NULL
)
3964 m_dropTarget
->Revoke(m_hWnd
);
3966 delete m_dropTarget
;
3967 m_dropTarget
= NULL
;
3969 #endif // wxUSE_DRAG_AND_DROP
3971 // WM_DESTROY handled
3975 // ---------------------------------------------------------------------------
3977 // ---------------------------------------------------------------------------
3979 bool wxWindowMSW::HandleActivate(int state
,
3980 bool WXUNUSED(minimized
),
3981 WXHWND
WXUNUSED(activate
))
3983 wxActivateEvent
event(wxEVT_ACTIVATE
,
3984 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3986 event
.SetEventObject(this);
3988 return HandleWindowEvent(event
);
3991 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3993 // Strangly enough, some controls get set focus events when they are being
3994 // deleted, even if they already had focus before.
3995 if ( m_isBeingDeleted
)
4000 // notify the parent keeping track of focus for the kbd navigation
4001 // purposes that we got it
4002 wxChildFocusEvent
eventFocus((wxWindow
*)this);
4003 (void)HandleWindowEvent(eventFocus
);
4009 m_caret
->OnSetFocus();
4011 #endif // wxUSE_CARET
4013 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
4014 event
.SetEventObject(this);
4016 // wxFindWinFromHandle() may return NULL, it is ok
4017 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4019 return HandleWindowEvent(event
);
4022 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
4028 m_caret
->OnKillFocus();
4030 #endif // wxUSE_CARET
4032 // Don't send the event when in the process of being deleted. This can
4033 // only cause problems if the event handler tries to access the object.
4034 if ( m_isBeingDeleted
)
4039 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
4040 event
.SetEventObject(this);
4042 // wxFindWinFromHandle() may return NULL, it is ok
4043 event
.SetWindow(wxFindWinFromHandle(hwnd
));
4045 return HandleWindowEvent(event
);
4048 // ---------------------------------------------------------------------------
4050 // ---------------------------------------------------------------------------
4052 void wxWindowMSW::SetLabel( const wxString
& label
)
4054 SetWindowText(GetHwnd(), label
.c_str());
4057 wxString
wxWindowMSW::GetLabel() const
4059 return wxGetWindowText(GetHWND());
4062 // ---------------------------------------------------------------------------
4064 // ---------------------------------------------------------------------------
4066 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
4068 wxShowEvent
event(GetId(), show
);
4069 event
.SetEventObject(this);
4071 return HandleWindowEvent(event
);
4074 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
4076 wxInitDialogEvent
event(GetId());
4077 event
.SetEventObject(this);
4079 return HandleWindowEvent(event
);
4082 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
4084 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
4085 wxUnusedVar(wParam
);
4087 #else // __WXMICROWIN__
4088 HDROP hFilesInfo
= (HDROP
) wParam
;
4090 // Get the total number of files dropped
4091 UINT gwFilesDropped
= ::DragQueryFile
4099 wxString
*files
= new wxString
[gwFilesDropped
];
4100 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
4102 // first get the needed buffer length (+1 for terminating NUL)
4103 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
4105 // and now get the file name
4106 ::DragQueryFile(hFilesInfo
, wIndex
,
4107 wxStringBuffer(files
[wIndex
], len
), len
);
4110 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
4111 event
.SetEventObject(this);
4114 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
4115 event
.m_pos
.x
= dropPoint
.x
;
4116 event
.m_pos
.y
= dropPoint
.y
;
4118 DragFinish(hFilesInfo
);
4120 return HandleWindowEvent(event
);
4125 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
4127 int WXUNUSED(mouseMsg
))
4129 #ifndef __WXMICROWIN__
4130 // the logic is as follows:
4131 // 0. if we're busy, set the busy cursor (even for non client elements)
4132 // 1. don't set custom cursor for non client area of enabled windows
4133 // 2. ask user EVT_SET_CURSOR handler for the cursor
4134 // 3. if still no cursor but we're in a TLW, set the global cursor
4136 HCURSOR hcursor
= 0;
4139 hcursor
= wxGetCurrentBusyCursor();
4143 if ( nHitTest
!= HTCLIENT
)
4146 // first ask the user code - it may wish to set the cursor in some very
4147 // specific way (for example, depending on the current position)
4150 if ( !::GetCursorPosWinCE(&pt
))
4152 if ( !::GetCursorPos(&pt
) )
4155 wxLogLastError(wxT("GetCursorPos"));
4160 ScreenToClient(&x
, &y
);
4161 wxSetCursorEvent
event(x
, y
);
4163 bool processedEvtSetCursor
= HandleWindowEvent(event
);
4164 if ( processedEvtSetCursor
&& event
.HasCursor() )
4166 hcursor
= GetHcursorOf(event
.GetCursor());
4171 // the test for processedEvtSetCursor is here to prevent using
4172 // m_cursor if the user code caught EVT_SET_CURSOR() and returned
4173 // nothing from it - this is a way to say that our cursor shouldn't
4174 // be used for this point
4175 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
4177 hcursor
= GetHcursorOf(m_cursor
);
4180 if ( !hcursor
&& !GetParent() )
4182 const wxCursor
*cursor
= wxGetGlobalCursor();
4183 if ( cursor
&& cursor
->Ok() )
4185 hcursor
= GetHcursorOf(*cursor
);
4194 ::SetCursor(hcursor
);
4196 // cursor set, stop here
4199 #endif // __WXMICROWIN__
4201 // pass up the window chain
4205 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
4206 WXLPARAM
WXUNUSED(lParam
),
4207 bool *WXUNUSED_IN_WINCE(vetoed
))
4213 wxEventType evtType
;
4216 case PBT_APMQUERYSUSPEND
:
4217 evtType
= wxEVT_POWER_SUSPENDING
;
4220 case PBT_APMQUERYSUSPENDFAILED
:
4221 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
4224 case PBT_APMSUSPEND
:
4225 evtType
= wxEVT_POWER_SUSPENDED
;
4228 case PBT_APMRESUMESUSPEND
:
4229 evtType
= wxEVT_POWER_RESUME
;
4233 wxLogDebug(_T("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
4236 // these messages are currently not mapped to wx events
4237 case PBT_APMQUERYSTANDBY
:
4238 case PBT_APMQUERYSTANDBYFAILED
:
4239 case PBT_APMSTANDBY
:
4240 case PBT_APMRESUMESTANDBY
:
4241 case PBT_APMBATTERYLOW
:
4242 case PBT_APMPOWERSTATUSCHANGE
:
4243 case PBT_APMOEMEVENT
:
4244 case PBT_APMRESUMECRITICAL
:
4245 #ifdef PBT_APMRESUMEAUTOMATIC
4246 case PBT_APMRESUMEAUTOMATIC
:
4248 evtType
= wxEVT_NULL
;
4252 // don't handle unknown messages
4253 if ( evtType
== wxEVT_NULL
)
4256 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
4258 wxPowerEvent
event(evtType
);
4259 if ( !HandleWindowEvent(event
) )
4262 *vetoed
= event
.IsVetoed();
4268 bool wxWindowMSW::IsDoubleBuffered() const
4270 for ( const wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4272 if ( wxHasWindowExStyle(win
, WS_EX_COMPOSITED
) )
4275 if ( win
->IsTopLevel() )
4282 void wxWindowMSW::SetDoubleBuffered(bool on
)
4284 // Get the current extended style bits
4285 long exstyle
= wxGetWindowExStyle(this);
4287 // Twiddle the bit as needed
4289 exstyle
|= WS_EX_COMPOSITED
;
4291 exstyle
&= ~WS_EX_COMPOSITED
;
4294 wxSetWindowExStyle(this, exstyle
);
4297 // ---------------------------------------------------------------------------
4298 // owner drawn stuff
4299 // ---------------------------------------------------------------------------
4301 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
4302 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
4303 #define WXUNUSED_UNLESS_ODRAWN(param) param
4305 #define WXUNUSED_UNLESS_ODRAWN(param)
4309 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
4310 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
4312 #if wxUSE_OWNER_DRAWN
4314 #if wxUSE_MENUS_NATIVE
4315 // is it a menu item?
4316 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
4317 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
4319 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
4321 // see comment before the same test in MSWOnMeasureItem() below
4325 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4326 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
4328 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4329 // the DC from being released
4330 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
4331 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
4332 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
4333 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
4335 return pMenuItem
->OnDrawItem
4339 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
4340 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
4343 #endif // wxUSE_MENUS_NATIVE
4345 #endif // USE_OWNER_DRAWN
4347 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4349 #if wxUSE_OWNER_DRAWN
4350 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4351 #else // !wxUSE_OWNER_DRAWN
4352 // we may still have owner-drawn buttons internally because we have to make
4353 // them owner-drawn to support colour change
4356 wxDynamicCast(FindItem(id
), wxButton
)
4361 #endif // USE_OWNER_DRAWN
4365 return item
->MSWOnDraw(itemStruct
);
4368 #endif // wxUSE_CONTROLS
4374 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4376 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4377 // is it a menu item?
4378 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4379 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4381 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4383 // according to Carsten Fuchs the pointer may be NULL under XP if an
4384 // MDI child frame is initially maximized, see this for more info:
4385 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4387 // so silently ignore it instead of asserting
4391 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4392 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
4395 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4397 pMeasureStruct
->itemWidth
= w
;
4398 pMeasureStruct
->itemHeight
= h
;
4403 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4406 return item
->MSWOnMeasure(itemStruct
);
4410 wxUnusedVar(itemStruct
);
4411 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4416 // ---------------------------------------------------------------------------
4417 // colours and palettes
4418 // ---------------------------------------------------------------------------
4420 bool wxWindowMSW::HandleSysColorChange()
4422 wxSysColourChangedEvent event
;
4423 event
.SetEventObject(this);
4425 (void)HandleWindowEvent(event
);
4427 // always let the system carry on the default processing to allow the
4428 // native controls to react to the colours update
4432 bool wxWindowMSW::HandleDisplayChange()
4434 wxDisplayChangedEvent event
;
4435 event
.SetEventObject(this);
4437 return HandleWindowEvent(event
);
4440 #ifndef __WXMICROWIN__
4442 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4444 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4448 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4451 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4453 #endif // wxUSE_CONTROLS
4456 return *brush
!= NULL
;
4459 #endif // __WXMICROWIN__
4461 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4464 // same as below except we don't respond to our own messages
4465 if ( hWndPalChange
!= GetHWND() )
4467 // check to see if we our our parents have a custom palette
4468 wxWindowMSW
*win
= this;
4469 while ( win
&& !win
->HasCustomPalette() )
4471 win
= win
->GetParent();
4474 if ( win
&& win
->HasCustomPalette() )
4476 // realize the palette to see whether redrawing is needed
4477 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4478 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4479 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4481 int result
= ::RealizePalette(hdc
);
4483 // restore the palette (before releasing the DC)
4484 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4485 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4486 ::RealizePalette(hdc
);
4487 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4489 // now check for the need to redraw
4491 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4495 #endif // wxUSE_PALETTE
4497 wxPaletteChangedEvent
event(GetId());
4498 event
.SetEventObject(this);
4499 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4501 return HandleWindowEvent(event
);
4504 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4506 // notify windows on the capture stack about lost capture
4507 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4508 wxWindowBase::NotifyCaptureLost();
4510 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4511 wxMouseCaptureChangedEvent
event(GetId(), win
);
4512 event
.SetEventObject(this);
4513 return HandleWindowEvent(event
);
4516 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4518 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4519 // we need to send this to child windows (it is only sent to top-level
4520 // windows) so {list,tree}ctrls can adjust their font size if necessary
4521 // this is exactly how explorer does it to enable the font size changes
4523 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4526 // top-level windows already get this message from the system
4527 wxWindow
*win
= node
->GetData();
4528 if ( !win
->IsTopLevel() )
4530 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4533 node
= node
->GetNext();
4536 // let the system handle it
4540 bool wxWindowMSW::HandleQueryNewPalette()
4544 // check to see if we our our parents have a custom palette
4545 wxWindowMSW
*win
= this;
4546 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4547 if (win
->HasCustomPalette()) {
4548 /* realize the palette to see whether redrawing is needed */
4549 HDC hdc
= ::GetDC((HWND
) GetHWND());
4550 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4551 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4553 int result
= ::RealizePalette(hdc
);
4554 /* restore the palette (before releasing the DC) */
4555 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4556 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4557 ::RealizePalette(hdc
);
4558 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4559 /* now check for the need to redraw */
4561 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4563 #endif // wxUSE_PALETTE
4565 wxQueryNewPaletteEvent
event(GetId());
4566 event
.SetEventObject(this);
4568 return HandleWindowEvent(event
) && event
.GetPaletteRealized();
4571 // Responds to colour changes: passes event on to children.
4572 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4574 // the top level window also reset the standard colour map as it might have
4575 // changed (there is no need to do it for the non top level windows as we
4576 // only have to do it once)
4580 gs_hasStdCmap
= false;
4582 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4585 // Only propagate to non-top-level windows because Windows already
4586 // sends this event to all top-level ones
4587 wxWindow
*win
= node
->GetData();
4588 if ( !win
->IsTopLevel() )
4590 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4591 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4592 // the standard controls
4593 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4596 node
= node
->GetNext();
4600 extern wxCOLORMAP
*wxGetStdColourMap()
4602 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4603 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4605 if ( !gs_hasStdCmap
)
4607 static bool s_coloursInit
= false;
4609 if ( !s_coloursInit
)
4611 // When a bitmap is loaded, the RGB values can change (apparently
4612 // because Windows adjusts them to care for the old programs always
4613 // using 0xc0c0c0 while the transparent colour for the new Windows
4614 // versions is different). But we do this adjustment ourselves so
4615 // we want to avoid Windows' "help" and for this we need to have a
4616 // reference bitmap which can tell us what the RGB values change
4618 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4619 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
4620 if ( stdColourBitmap
.Ok() )
4622 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4623 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4624 _T("forgot to update wxBITMAP_STD_COLOURS!") );
4627 memDC
.SelectObject(stdColourBitmap
);
4630 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4632 memDC
.GetPixel(i
, 0, &colour
);
4633 s_stdColours
[i
] = wxColourToRGB(colour
);
4636 else // wxBITMAP_STD_COLOURS couldn't be loaded
4638 s_stdColours
[0] = RGB(000,000,000); // black
4639 s_stdColours
[1] = RGB(128,128,128); // dark grey
4640 s_stdColours
[2] = RGB(192,192,192); // light grey
4641 s_stdColours
[3] = RGB(255,255,255); // white
4642 //s_stdColours[4] = RGB(000,000,255); // blue
4643 //s_stdColours[5] = RGB(255,000,255); // magenta
4646 s_coloursInit
= true;
4649 gs_hasStdCmap
= true;
4651 // create the colour map
4652 #define INIT_CMAP_ENTRY(col) \
4653 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4654 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4656 INIT_CMAP_ENTRY(BTNTEXT
);
4657 INIT_CMAP_ENTRY(BTNSHADOW
);
4658 INIT_CMAP_ENTRY(BTNFACE
);
4659 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4661 #undef INIT_CMAP_ENTRY
4667 // ---------------------------------------------------------------------------
4669 // ---------------------------------------------------------------------------
4671 bool wxWindowMSW::HandlePaint()
4673 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4675 wxLogLastError(wxT("CreateRectRgn"));
4676 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4677 wxLogLastError(wxT("GetUpdateRgn"));
4679 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4681 wxPaintEvent
event(m_windowId
);
4682 event
.SetEventObject(this);
4684 bool processed
= HandleWindowEvent(event
);
4686 // note that we must generate NC event after the normal one as otherwise
4687 // BeginPaint() will happily overwrite our decorations with the background
4689 wxNcPaintEvent
eventNc(m_windowId
);
4690 eventNc
.SetEventObject(this);
4691 HandleWindowEvent(eventNc
);
4693 // don't keep an HRGN we don't need any longer (GetUpdateRegion() can only
4694 // be called from inside the event handlers called above)
4695 m_updateRegion
.Clear();
4700 // Can be called from an application's OnPaint handler
4701 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4703 #ifdef __WXUNIVERSAL__
4706 HDC hDC
= (HDC
) wxPaintDCImpl::FindDCInCache((wxWindow
*) event
.GetEventObject());
4709 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4714 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4716 wxDCTemp
dc(hdc
, GetClientSize());
4717 wxDCTempImpl
*impl
= (wxDCTempImpl
*) dc
.GetImpl();
4720 impl
->SetWindow((wxWindow
*)this);
4722 wxEraseEvent
event(m_windowId
, &dc
);
4723 event
.SetEventObject(this);
4724 bool rc
= HandleWindowEvent(event
);
4726 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
4727 impl
->SelectOldObjects(hdc
);
4732 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
4734 // standard non top level controls (i.e. except the dialogs) always erase
4735 // their background themselves in HandleCtlColor() or have some control-
4736 // specific ways to set the colours (common controls)
4737 if ( IsOfStandardClass() && !IsTopLevel() )
4743 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
4745 // don't skip the event here, custom background means that the app
4746 // is drawing it itself in its OnPaint(), so don't draw it at all
4747 // now to avoid flicker
4751 wxDC
*dc
= event
.GetDC();
4753 wxMSWDCImpl
*impl
= (wxMSWDCImpl
*) dc
->GetImpl();
4755 // do default background painting
4756 if ( !DoEraseBackground(GetHdcOf(*impl
)) )
4758 // let the system paint the background
4763 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4765 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4769 wxFillRect(GetHwnd(), (HDC
)hDC
, hbr
);
4775 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
), WXHWND hWnd
)
4779 // our background colour applies to:
4780 // 1. this window itself, always
4781 // 2. all children unless the colour is "not inheritable"
4782 // 3. even if it is not inheritable, our immediate transparent
4783 // children should still inherit it -- but not any transparent
4784 // children because it would look wrong if a child of non
4785 // transparent child would show our bg colour when the child itself
4787 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
4790 (win
&& win
->HasTransparentBackground() &&
4791 win
->GetParent() == this) )
4793 // draw children with the same colour as the parent
4795 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4797 return (WXHBRUSH
)GetHbrushOf(*brush
);
4804 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
, WXHWND hWndToPaint
)
4807 hWndToPaint
= GetHWND();
4809 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4811 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, hWndToPaint
);
4815 // background is not inherited beyond top level windows
4816 if ( win
->IsTopLevel() )
4823 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4825 // we receive this message when DrawThemeParentBackground() is
4826 // called from def window proc of several controls under XP and we
4827 // must draw properly themed background here
4829 // note that naively I'd expect filling the client rect with the
4830 // brush returned by MSWGetBgBrush() work -- but for some reason it
4831 // doesn't and we have to call parents MSWPrintChild() which is
4832 // supposed to call DrawThemeBackground() with appropriate params
4834 // also note that in this case lParam == PRF_CLIENT but we're
4835 // clearly expected to paint the background and nothing else!
4837 if ( IsTopLevel() || InheritsBackgroundColour() )
4840 // sometimes we don't want the parent to handle it at all, instead
4841 // return whatever value this window wants
4842 if ( !MSWShouldPropagatePrintChild() )
4843 return MSWPrintChild(hDC
, (wxWindow
*)this);
4845 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4847 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4850 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4857 // ---------------------------------------------------------------------------
4858 // moving and resizing
4859 // ---------------------------------------------------------------------------
4861 bool wxWindowMSW::HandleMinimize()
4863 wxIconizeEvent
event(m_windowId
);
4864 event
.SetEventObject(this);
4866 return HandleWindowEvent(event
);
4869 bool wxWindowMSW::HandleMaximize()
4871 wxMaximizeEvent
event(m_windowId
);
4872 event
.SetEventObject(this);
4874 return HandleWindowEvent(event
);
4877 bool wxWindowMSW::HandleMove(int x
, int y
)
4880 wxMoveEvent
event(point
, m_windowId
);
4881 event
.SetEventObject(this);
4883 return HandleWindowEvent(event
);
4886 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
4888 wxMoveEvent
event(rect
, m_windowId
);
4889 event
.SetEventObject(this);
4891 bool rc
= HandleWindowEvent(event
);
4893 rect
= event
.GetRect();
4897 bool wxWindowMSW::HandleEnterSizeMove()
4899 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
4900 event
.SetEventType(wxEVT_MOVE_START
);
4901 event
.SetEventObject(this);
4903 return HandleWindowEvent(event
);
4906 bool wxWindowMSW::HandleExitSizeMove()
4908 wxMoveEvent
event(wxPoint(0,0), m_windowId
);
4909 event
.SetEventType(wxEVT_MOVE_END
);
4910 event
.SetEventObject(this);
4912 return HandleWindowEvent(event
);
4915 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
4917 #if USE_DEFERRED_SIZING
4918 // when we resize this window, its children are probably going to be
4919 // repositioned as well, prepare to use DeferWindowPos() for them
4920 int numChildren
= 0;
4921 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
4923 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
4928 // Protect against valid m_hDWP being overwritten
4929 bool useDefer
= false;
4931 if ( numChildren
> 1 )
4935 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
4938 wxLogLastError(_T("BeginDeferWindowPos"));
4944 #endif // USE_DEFERRED_SIZING
4946 // update this window size
4947 bool processed
= false;
4951 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4952 // fall through nevertheless
4956 // we're not interested in these messages at all
4959 case SIZE_MINIMIZED
:
4960 processed
= HandleMinimize();
4963 case SIZE_MAXIMIZED
:
4964 /* processed = */ HandleMaximize();
4965 // fall through to send a normal size event as well
4968 // don't use w and h parameters as they specify the client size
4969 // while according to the docs EVT_SIZE handler is supposed to
4970 // receive the total size
4971 wxSizeEvent
event(GetSize(), m_windowId
);
4972 event
.SetEventObject(this);
4974 processed
= HandleWindowEvent(event
);
4977 #if USE_DEFERRED_SIZING
4978 // and finally change the positions of all child windows at once
4979 if ( useDefer
&& m_hDWP
)
4981 // reset m_hDWP to NULL so that child windows don't try to use our
4982 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4983 // happen anyhow normally but who knows what weird flow of control we
4984 // may have depending on what the users EVT_SIZE handler does...)
4985 HDWP hDWP
= (HDWP
)m_hDWP
;
4988 // do put all child controls in place at once
4989 if ( !::EndDeferWindowPos(hDWP
) )
4991 wxLogLastError(_T("EndDeferWindowPos"));
4994 // Reset our children's pending pos/size values.
4995 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4997 node
= node
->GetNext() )
4999 wxWindowMSW
*child
= node
->GetData();
5000 child
->m_pendingPosition
= wxDefaultPosition
;
5001 child
->m_pendingSize
= wxDefaultSize
;
5004 #endif // USE_DEFERRED_SIZING
5009 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
5011 wxSizeEvent
event(rect
, m_windowId
);
5012 event
.SetEventObject(this);
5014 bool rc
= HandleWindowEvent(event
);
5016 rect
= event
.GetRect();
5020 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
5025 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
5029 int minWidth
= GetMinWidth(),
5030 minHeight
= GetMinHeight(),
5031 maxWidth
= GetMaxWidth(),
5032 maxHeight
= GetMaxHeight();
5034 if ( minWidth
!= wxDefaultCoord
)
5036 info
->ptMinTrackSize
.x
= minWidth
;
5040 if ( minHeight
!= wxDefaultCoord
)
5042 info
->ptMinTrackSize
.y
= minHeight
;
5046 if ( maxWidth
!= wxDefaultCoord
)
5048 info
->ptMaxTrackSize
.x
= maxWidth
;
5052 if ( maxHeight
!= wxDefaultCoord
)
5054 info
->ptMaxTrackSize
.y
= maxHeight
;
5062 // ---------------------------------------------------------------------------
5064 // ---------------------------------------------------------------------------
5066 bool wxWindowMSW::HandleCommand(WXWORD id_
, WXWORD cmd
, WXHWND control
)
5068 // sign extend to int from short before comparing with the other int ids
5069 int id
= (signed short)id_
;
5071 #if wxUSE_MENUS_NATIVE
5072 if ( !cmd
&& wxCurrentPopupMenu
)
5074 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
5075 wxCurrentPopupMenu
= NULL
;
5077 return popupMenu
->MSWCommand(cmd
, id
);
5079 #endif // wxUSE_MENUS_NATIVE
5081 wxWindow
*win
= NULL
;
5083 // first try to find it from HWND - this works even with the broken
5084 // programs using the same ids for different controls
5087 win
= wxFindWinFromHandle(control
);
5098 return win
->MSWCommand(cmd
, id
);
5101 // the messages sent from the in-place edit control used by the treectrl
5102 // for label editing have id == 0, but they should _not_ be treated as menu
5103 // messages (they are EN_XXX ones, in fact) so don't translate anything
5104 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
5107 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
, id
);
5108 event
.SetEventObject(this);
5111 return HandleWindowEvent(event
);
5115 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5116 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
5117 // notifications to its parent which we want to reflect back to
5119 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
5120 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
5122 #endif // wxUSE_SPINCTRL
5124 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
5125 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
5126 // notifications to its parent which we want to reflect back to
5128 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
5129 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
5137 // ---------------------------------------------------------------------------
5139 // ---------------------------------------------------------------------------
5141 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
5145 // our client coords are not quite the same as Windows ones
5146 wxPoint pt
= GetClientAreaOrigin();
5147 event
.m_x
= x
- pt
.x
;
5148 event
.m_y
= y
- pt
.y
;
5150 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
5151 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
5152 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
5153 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
5154 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
5155 #ifdef wxHAS_XBUTTON
5156 event
.m_aux1Down
= (flags
& MK_XBUTTON1
) != 0;
5157 event
.m_aux2Down
= (flags
& MK_XBUTTON2
) != 0;
5158 #endif // wxHAS_XBUTTON
5159 event
.m_altDown
= ::wxIsAltDown();
5162 event
.SetTimestamp(::GetMessageTime());
5165 event
.SetEventObject(this);
5166 event
.SetId(GetId());
5168 #if wxUSE_MOUSEEVENT_HACK
5169 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
5170 gs_lastMouseEvent
.type
= event
.GetEventType();
5171 #endif // wxUSE_MOUSEEVENT_HACK
5175 // Windows doesn't send the mouse events to the static controls (which are
5176 // transparent in the sense that their WM_NCHITTEST handler returns
5177 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
5178 // and so we manually check if we don't have a child window under mouse and if
5179 // we do, send the event to it instead of the window Windows had sent WM_XXX
5182 // Notice that this is not done for the mouse move events because this could
5183 // (would?) be too slow, but only for clicks which means that the static texts
5184 // still don't get move, enter nor leave events.
5185 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
5187 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
5189 // first try to find a non transparent child: this allows us to send events
5190 // to a static text which is inside a static box, for example
5191 POINT pt
= { *x
, *y
};
5192 HWND hwnd
= GetHwndOf(win
),
5196 hwndUnderMouse
= ::ChildWindowFromPoint
5202 hwndUnderMouse
= ::ChildWindowFromPointEx
5212 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
5214 // now try any child window at all
5215 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
5218 // check that we have a child window which is susceptible to receive mouse
5219 // events: for this it must be shown and enabled
5220 if ( hwndUnderMouse
&&
5221 hwndUnderMouse
!= hwnd
&&
5222 ::IsWindowVisible(hwndUnderMouse
) &&
5223 ::IsWindowEnabled(hwndUnderMouse
) )
5225 wxWindow
*winUnderMouse
= wxFindWinFromHandle(hwndUnderMouse
);
5226 if ( winUnderMouse
)
5228 // translate the mouse coords to the other window coords
5229 win
->ClientToScreen(x
, y
);
5230 winUnderMouse
->ScreenToClient(x
, y
);
5232 win
= winUnderMouse
;
5238 #endif // __WXWINCE__
5240 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5242 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
5243 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
5244 // from the message id and take the value in the table to get wxWin event
5246 static const wxEventType eventsMouse
[] =
5257 wxEVT_MIDDLE_DCLICK
,
5258 0, // this one is for wxEVT_MOTION which is not used here
5267 #ifdef wxHAS_XBUTTON
5268 // the same messages are used for both auxillary mouse buttons so we need
5269 // to adjust the index manually
5272 case WM_XBUTTONDOWN
:
5274 case WM_XBUTTONDBLCLK
:
5275 if ( flags
& MK_XBUTTON2
)
5276 msg
+= wxEVT_AUX2_DOWN
- wxEVT_AUX1_DOWN
;
5278 #endif // wxHAS_XBUTTON
5280 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
5281 InitMouseEvent(event
, x
, y
, flags
);
5283 return HandleWindowEvent(event
);
5286 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
5288 if ( !m_mouseInWindow
)
5290 // it would be wrong to assume that just because we get a mouse move
5291 // event that the mouse is inside the window: although this is usually
5292 // true, it is not if we had captured the mouse, so we need to check
5293 // the mouse coordinates here
5294 if ( !HasCapture() || IsMouseInWindow() )
5296 // Generate an ENTER event
5297 m_mouseInWindow
= true;
5299 #ifdef HAVE_TRACKMOUSEEVENT
5300 typedef BOOL (WINAPI
*_TrackMouseEvent_t
)(LPTRACKMOUSEEVENT
);
5302 static const _TrackMouseEvent_t
5303 s_pfn_TrackMouseEvent
= _TrackMouseEvent
;
5304 #else // !__WXWINCE__
5305 static _TrackMouseEvent_t s_pfn_TrackMouseEvent
;
5306 static bool s_initDone
= false;
5309 // see comment in wxApp::GetComCtl32Version() explaining the
5310 // use of wxLoadedDLL
5311 wxLoadedDLL
dllComCtl32(_T("comctl32.dll"));
5312 if ( dllComCtl32
.IsLoaded() )
5314 s_pfn_TrackMouseEvent
= (_TrackMouseEvent_t
)
5315 dllComCtl32
.RawGetSymbol(_T("_TrackMouseEvent"));
5321 if ( s_pfn_TrackMouseEvent
)
5322 #endif // __WXWINCE__/!__WXWINCE__
5324 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
5326 trackinfo
.dwFlags
= TME_LEAVE
;
5327 trackinfo
.hwndTrack
= GetHwnd();
5329 (*s_pfn_TrackMouseEvent
)(&trackinfo
);
5331 #endif // HAVE_TRACKMOUSEEVENT
5333 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
5334 InitMouseEvent(event
, x
, y
, flags
);
5336 (void)HandleWindowEvent(event
);
5339 #ifdef HAVE_TRACKMOUSEEVENT
5340 else // mouse not in window
5342 // Check if we need to send a LEAVE event
5343 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
5344 // send it here if we are using native mouse leave tracking
5345 if ( HasCapture() && !IsMouseInWindow() )
5347 GenerateMouseLeave();
5350 #endif // HAVE_TRACKMOUSEEVENT
5352 #if wxUSE_MOUSEEVENT_HACK
5353 // Windows often generates mouse events even if mouse position hasn't
5354 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
5356 // Filter this out as it can result in unexpected behaviour compared to
5358 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
5359 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
5360 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
5361 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
5363 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
5365 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
5370 #endif // wxUSE_MOUSEEVENT_HACK
5372 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
5376 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
5378 #if wxUSE_MOUSEWHEEL
5379 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5380 // forwarded up to the parent by DefWindowProc()) and not in the client
5381 // ones as all the other messages, translate them to the client coords for
5384 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
5385 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
5386 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
5387 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5388 event
.m_wheelDelta
= WHEEL_DELTA
;
5390 static int s_linesPerRotation
= -1;
5391 if ( s_linesPerRotation
== -1 )
5393 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5394 &s_linesPerRotation
, 0))
5396 // this is not supposed to happen
5397 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5399 // the default is 3, so use it if SystemParametersInfo() failed
5400 s_linesPerRotation
= 3;
5404 event
.m_linesPerAction
= s_linesPerRotation
;
5405 return HandleWindowEvent(event
);
5407 #else // !wxUSE_MOUSEWHEEL
5408 wxUnusedVar(wParam
);
5409 wxUnusedVar(lParam
);
5412 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5415 void wxWindowMSW::GenerateMouseLeave()
5417 m_mouseInWindow
= false;
5420 if ( wxIsShiftDown() )
5422 if ( wxIsCtrlDown() )
5423 state
|= MK_CONTROL
;
5425 // Only the high-order bit should be tested
5426 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5427 state
|= MK_LBUTTON
;
5428 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5429 state
|= MK_MBUTTON
;
5430 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5431 state
|= MK_RBUTTON
;
5435 if ( !::GetCursorPosWinCE(&pt
) )
5437 if ( !::GetCursorPos(&pt
) )
5440 wxLogLastError(_T("GetCursorPos"));
5443 // we need to have client coordinates here for symmetry with
5444 // wxEVT_ENTER_WINDOW
5445 RECT rect
= wxGetWindowRect(GetHwnd());
5449 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5450 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5452 (void)HandleWindowEvent(event
);
5455 // ---------------------------------------------------------------------------
5456 // keyboard handling
5457 // ---------------------------------------------------------------------------
5459 // create the key event of the given type for the given key - used by
5460 // HandleChar and HandleKeyDown/Up
5461 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5464 WXWPARAM wParam
) const
5466 wxKeyEvent
event(evType
);
5467 event
.SetId(GetId());
5468 event
.m_shiftDown
= wxIsShiftDown();
5469 event
.m_controlDown
= wxIsCtrlDown();
5470 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5472 event
.SetEventObject((wxWindow
*)this); // const_cast
5473 event
.m_keyCode
= id
;
5475 event
.m_uniChar
= (wxChar
) wParam
;
5477 event
.m_rawCode
= (wxUint32
) wParam
;
5478 event
.m_rawFlags
= (wxUint32
) lParam
;
5480 event
.SetTimestamp(::GetMessageTime());
5483 // translate the position to client coords
5486 GetCursorPosWinCE(&pt
);
5491 GetWindowRect(GetHwnd(),&rect
);
5501 // isASCII is true only when we're called from WM_CHAR handler and not from
5503 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
5510 else // we're called from WM_KEYDOWN
5512 // don't pass lParam to wxCharCodeMSWToWX() here because we don't want
5513 // to get numpad key codes: CHAR events should use the logical keys
5514 // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events
5515 id
= wxCharCodeMSWToWX(wParam
);
5518 // it's ASCII and will be processed here only when called from
5519 // WM_CHAR (i.e. when isASCII = true), don't process it now
5524 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
5526 // the alphanumeric keys produced by pressing AltGr+something on European
5527 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5528 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5529 // alphanumeric, so pretend that there are no modifiers at all (the
5530 // KEY_DOWN event would still have the correct modifiers if they're really
5532 if ( event
.m_controlDown
&& event
.m_altDown
&&
5533 (id
>= 32 && id
< 256) )
5535 event
.m_controlDown
=
5536 event
.m_altDown
= false;
5539 return HandleWindowEvent(event
);
5542 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5544 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5548 // normal ASCII char
5552 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
5553 return HandleWindowEvent(event
);
5556 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5558 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5562 // normal ASCII char
5566 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
5567 return HandleWindowEvent(event
);
5571 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5572 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5574 // FIXME: implement GetMenuItemCount for WinCE, possibly
5575 // in terms of GetMenuItemInfo
5577 const HMENU hmenu
= (HMENU
)lParam
;
5581 mii
.cbSize
= sizeof(MENUITEMINFO
);
5583 // we could use MIIM_FTYPE here as we only need to know if the item is
5584 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5585 // MIIM_FTYPE is not supported under Win95
5586 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5588 // find if we have this letter in any owner drawn item
5589 const int count
= ::GetMenuItemCount(hmenu
);
5590 for ( int i
= 0; i
< count
; i
++ )
5592 // previous loop iteration could modify it, reset it back before
5593 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5596 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5598 if ( mii
.fType
== MFT_OWNERDRAW
)
5600 // dwItemData member of the MENUITEMINFO is a
5601 // pointer to the associated wxMenuItem -- see the
5602 // menu creation code
5603 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5605 const wxChar
*p
= wxStrchr(item
->GetItemLabel().wx_str(), _T('&'));
5608 if ( *p
== _T('&') )
5610 // this is not the accel char, find the real one
5611 p
= wxStrchr(p
+ 1, _T('&'));
5613 else // got the accel char
5615 // FIXME-UNICODE: this comparison doesn't risk to work
5616 // for non ASCII accelerator characters I'm afraid, but
5618 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5624 // this one doesn't match
5631 else // failed to get the menu text?
5633 // it's not fatal, so don't show error, but still log it
5634 wxLogLastError(_T("GetMenuItemInfo"));
5641 #endif // wxUSE_MENUS
5643 bool wxWindowMSW::HandleClipboardEvent(WXUINT nMsg
)
5645 const wxEventType type
= nMsg
== WM_CUT
? wxEVT_COMMAND_TEXT_CUT
5646 : nMsg
== WM_COPY
? wxEVT_COMMAND_TEXT_COPY
5647 : /* nMsg == WM_PASTE */ wxEVT_COMMAND_TEXT_PASTE
;
5648 wxClipboardTextEvent
evt(type
, GetId());
5650 evt
.SetEventObject(this);
5652 return HandleWindowEvent(evt
);
5655 // ---------------------------------------------------------------------------
5657 // ---------------------------------------------------------------------------
5659 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5663 if ( flags
& JOY_BUTTON1CHG
)
5664 change
= wxJOY_BUTTON1
;
5665 if ( flags
& JOY_BUTTON2CHG
)
5666 change
= wxJOY_BUTTON2
;
5667 if ( flags
& JOY_BUTTON3CHG
)
5668 change
= wxJOY_BUTTON3
;
5669 if ( flags
& JOY_BUTTON4CHG
)
5670 change
= wxJOY_BUTTON4
;
5673 if ( flags
& JOY_BUTTON1
)
5674 buttons
|= wxJOY_BUTTON1
;
5675 if ( flags
& JOY_BUTTON2
)
5676 buttons
|= wxJOY_BUTTON2
;
5677 if ( flags
& JOY_BUTTON3
)
5678 buttons
|= wxJOY_BUTTON3
;
5679 if ( flags
& JOY_BUTTON4
)
5680 buttons
|= wxJOY_BUTTON4
;
5682 // the event ids aren't consecutive so we can't use table based lookup
5684 wxEventType eventType
;
5689 eventType
= wxEVT_JOY_MOVE
;
5694 eventType
= wxEVT_JOY_MOVE
;
5699 eventType
= wxEVT_JOY_ZMOVE
;
5704 eventType
= wxEVT_JOY_ZMOVE
;
5707 case MM_JOY1BUTTONDOWN
:
5709 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5712 case MM_JOY2BUTTONDOWN
:
5714 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5717 case MM_JOY1BUTTONUP
:
5719 eventType
= wxEVT_JOY_BUTTON_UP
;
5722 case MM_JOY2BUTTONUP
:
5724 eventType
= wxEVT_JOY_BUTTON_UP
;
5728 wxFAIL_MSG(wxT("no such joystick event"));
5733 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5734 event
.SetPosition(wxPoint(x
, y
));
5735 event
.SetEventObject(this);
5737 return HandleWindowEvent(event
);
5747 // ---------------------------------------------------------------------------
5749 // ---------------------------------------------------------------------------
5751 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5752 WXWORD pos
, WXHWND control
)
5754 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5756 wxWindow
*child
= wxFindWinFromHandle(control
);
5758 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5761 wxScrollWinEvent event
;
5762 event
.SetPosition(pos
);
5763 event
.SetOrientation(orientation
);
5764 event
.SetEventObject(this);
5769 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5773 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5777 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5781 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5785 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5789 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5792 case SB_THUMBPOSITION
:
5794 // under Win32, the scrollbar range and position are 32 bit integers,
5795 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5796 // explicitly query the scrollbar for the correct position (this must
5797 // be done only for these two SB_ events as they are the only one
5798 // carrying the scrollbar position)
5800 WinStruct
<SCROLLINFO
> scrollInfo
;
5801 scrollInfo
.fMask
= SIF_TRACKPOS
;
5803 if ( !::GetScrollInfo(GetHwnd(),
5804 WXOrientToSB(orientation
),
5807 // Not necessarily an error, if there are no scrollbars yet.
5808 // wxLogLastError(_T("GetScrollInfo"));
5811 event
.SetPosition(scrollInfo
.nTrackPos
);
5814 event
.SetEventType( wParam
== SB_THUMBPOSITION
5815 ? wxEVT_SCROLLWIN_THUMBRELEASE
5816 : wxEVT_SCROLLWIN_THUMBTRACK
);
5823 return HandleWindowEvent(event
);
5826 // ----------------------------------------------------------------------------
5827 // custom message handlers
5828 // ----------------------------------------------------------------------------
5831 wxWindowMSW::MSWRegisterMessageHandler(int msg
, MSWMessageHandler handler
)
5833 wxCHECK_MSG( gs_messageHandlers
.find(msg
) == gs_messageHandlers
.end(),
5834 false, _T("registering handler for the same message twice") );
5836 gs_messageHandlers
[msg
] = handler
;
5841 wxWindowMSW::MSWUnregisterMessageHandler(int msg
, MSWMessageHandler handler
)
5843 const MSWMessageHandlers::iterator i
= gs_messageHandlers
.find(msg
);
5844 wxCHECK_RET( i
!= gs_messageHandlers
.end() && i
->second
== handler
,
5845 _T("unregistering non-registered handler?") );
5847 gs_messageHandlers
.erase(i
);
5850 // ===========================================================================
5852 // ===========================================================================
5854 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5857 HDC dc
= ::GetDC((HWND
) wnd
);
5860 // the_font.UseResource();
5861 // the_font.RealizeResource();
5862 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
5864 was
= (HFONT
) SelectObject(dc
,fnt
);
5866 GetTextMetrics(dc
, &tm
);
5869 SelectObject(dc
,was
);
5871 ReleaseDC((HWND
)wnd
, dc
);
5874 *x
= tm
.tmAveCharWidth
;
5876 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
5878 // the_font.ReleaseResource();
5881 // use the "extended" bit (24) of lParam to distinguish extended keys
5882 // from normal keys as the same key is sent
5884 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
5886 // except that if lParam is 0, it means we don't have real lParam from
5887 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
5888 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
5889 // non-numpad (hence extended) key as this is a more common case
5890 return !lParam
|| (lParam
& (1 << 24)) ? keyExtended
: keyNormal
;
5893 // this array contains the Windows virtual key codes which map one to one to
5894 // WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below
5896 // note that keys having a normal and numpad version (e.g. WXK_HOME and
5897 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
5898 static const struct wxKeyMapping
5902 } gs_specialKeys
[] =
5904 { VK_CANCEL
, WXK_CANCEL
},
5905 { VK_BACK
, WXK_BACK
},
5906 { VK_TAB
, WXK_TAB
},
5907 { VK_CLEAR
, WXK_CLEAR
},
5908 { VK_SHIFT
, WXK_SHIFT
},
5909 { VK_CONTROL
, WXK_CONTROL
},
5910 { VK_MENU
, WXK_ALT
},
5911 { VK_PAUSE
, WXK_PAUSE
},
5912 { VK_CAPITAL
, WXK_CAPITAL
},
5913 { VK_SPACE
, WXK_SPACE
},
5914 { VK_ESCAPE
, WXK_ESCAPE
},
5915 { VK_SELECT
, WXK_SELECT
},
5916 { VK_PRINT
, WXK_PRINT
},
5917 { VK_EXECUTE
, WXK_EXECUTE
},
5918 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
5919 { VK_HELP
, WXK_HELP
},
5921 { VK_NUMPAD0
, WXK_NUMPAD0
},
5922 { VK_NUMPAD1
, WXK_NUMPAD1
},
5923 { VK_NUMPAD2
, WXK_NUMPAD2
},
5924 { VK_NUMPAD3
, WXK_NUMPAD3
},
5925 { VK_NUMPAD4
, WXK_NUMPAD4
},
5926 { VK_NUMPAD5
, WXK_NUMPAD5
},
5927 { VK_NUMPAD6
, WXK_NUMPAD6
},
5928 { VK_NUMPAD7
, WXK_NUMPAD7
},
5929 { VK_NUMPAD8
, WXK_NUMPAD8
},
5930 { VK_NUMPAD9
, WXK_NUMPAD9
},
5931 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
5932 { VK_ADD
, WXK_NUMPAD_ADD
},
5933 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
5934 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
5935 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
5946 { VK_F10
, WXK_F10
},
5947 { VK_F11
, WXK_F11
},
5948 { VK_F12
, WXK_F12
},
5949 { VK_F13
, WXK_F13
},
5950 { VK_F14
, WXK_F14
},
5951 { VK_F15
, WXK_F15
},
5952 { VK_F16
, WXK_F16
},
5953 { VK_F17
, WXK_F17
},
5954 { VK_F18
, WXK_F18
},
5955 { VK_F19
, WXK_F19
},
5956 { VK_F20
, WXK_F20
},
5957 { VK_F21
, WXK_F21
},
5958 { VK_F22
, WXK_F22
},
5959 { VK_F23
, WXK_F23
},
5960 { VK_F24
, WXK_F24
},
5962 { VK_NUMLOCK
, WXK_NUMLOCK
},
5963 { VK_SCROLL
, WXK_SCROLL
},
5966 { VK_LWIN
, WXK_WINDOWS_LEFT
},
5967 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
5968 { VK_APPS
, WXK_WINDOWS_MENU
},
5969 #endif // VK_APPS defined
5972 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
5973 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
5974 int wxCharCodeMSWToWX(int vk
, WXLPARAM lParam
)
5976 // check the table first
5977 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5979 if ( gs_specialKeys
[n
].vk
== vk
)
5980 return gs_specialKeys
[n
].wxk
;
5983 // keys requiring special handling
5987 // the mapping for these keys may be incorrect on non-US keyboards so
5988 // maybe we shouldn't map them to ASCII values at all
5989 case VK_OEM_1
: wxk
= ';'; break;
5990 case VK_OEM_PLUS
: wxk
= '+'; break;
5991 case VK_OEM_COMMA
: wxk
= ','; break;
5992 case VK_OEM_MINUS
: wxk
= '-'; break;
5993 case VK_OEM_PERIOD
: wxk
= '.'; break;
5994 case VK_OEM_2
: wxk
= '/'; break;
5995 case VK_OEM_3
: wxk
= '~'; break;
5996 case VK_OEM_4
: wxk
= '['; break;
5997 case VK_OEM_5
: wxk
= '\\'; break;
5998 case VK_OEM_6
: wxk
= ']'; break;
5999 case VK_OEM_7
: wxk
= '\''; break;
6001 // handle extended keys
6003 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
6007 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
6011 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
6015 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
6019 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
6023 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
6027 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
6031 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
6035 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
6039 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
6043 // don't use ChooseNormalOrExtended() here as the keys are reversed
6044 // here: numpad enter is the extended one
6045 wxk
= lParam
&& (lParam
& (1 << 24)) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
6055 WXWORD
wxCharCodeWXToMSW(int wxk
, bool *isVirtual
)
6060 // check the table first
6061 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
6063 if ( gs_specialKeys
[n
].wxk
== wxk
)
6064 return gs_specialKeys
[n
].vk
;
6067 // and then check for special keys not included in the table
6072 case WXK_NUMPAD_PAGEUP
:
6077 case WXK_NUMPAD_PAGEDOWN
:
6082 case WXK_NUMPAD_END
:
6087 case WXK_NUMPAD_HOME
:
6092 case WXK_NUMPAD_LEFT
:
6102 case WXK_NUMPAD_RIGHT
:
6107 case WXK_NUMPAD_DOWN
:
6112 case WXK_NUMPAD_INSERT
:
6117 case WXK_NUMPAD_DELETE
:
6122 // no VkKeyScan() under CE unfortunately, we need to test how does
6123 // it handle OEM keys
6125 // check to see if its one of the OEM key codes.
6126 BYTE vks
= LOBYTE(VkKeyScan(wxk
));
6132 #endif // !__WXWINCE__
6143 // small helper for wxGetKeyState() and wxGetMouseState()
6144 static inline bool wxIsKeyDown(WXWORD vk
)
6146 // SM_SWAPBUTTON is not available under CE, so don't swap buttons there
6147 #ifdef SM_SWAPBUTTON
6148 if ( vk
== VK_LBUTTON
|| vk
== VK_RBUTTON
)
6150 if ( ::GetSystemMetrics(SM_SWAPBUTTON
) )
6152 if ( vk
== VK_LBUTTON
)
6154 else // vk == VK_RBUTTON
6158 #endif // SM_SWAPBUTTON
6160 // the low order bit indicates whether the key was pressed since the last
6161 // call and the high order one indicates whether it is down right now and
6162 // we only want that one
6163 return (GetAsyncKeyState(vk
) & (1<<15)) != 0;
6166 bool wxGetKeyState(wxKeyCode key
)
6168 // although this does work under Windows, it is not supported under other
6169 // platforms so don't allow it, you must use wxGetMouseState() instead
6170 wxASSERT_MSG( key
!= VK_LBUTTON
&&
6171 key
!= VK_RBUTTON
&&
6173 wxT("can't use wxGetKeyState() for mouse buttons") );
6175 const WXWORD vk
= wxCharCodeWXToMSW(key
);
6177 // if the requested key is a LED key, return true if the led is pressed
6178 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
6180 // low order bit means LED is highlighted and high order one means the
6181 // key is down; for compatibility with the other ports return true if
6182 // either one is set
6183 return GetKeyState(vk
) != 0;
6188 return wxIsKeyDown(vk
);
6193 wxMouseState
wxGetMouseState()
6197 GetCursorPos( &pt
);
6201 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
6202 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
6203 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
6204 #ifdef wxHAS_XBUTTON
6205 ms
.SetAux1Down(wxIsKeyDown(VK_XBUTTON1
));
6206 ms
.SetAux2Down(wxIsKeyDown(VK_XBUTTON2
));
6207 #endif // wxHAS_XBUTTON
6209 ms
.SetControlDown(wxIsCtrlDown ());
6210 ms
.SetShiftDown (wxIsShiftDown());
6211 ms
.SetAltDown (wxIsAltDown ());
6212 // ms.SetMetaDown();
6218 wxWindow
*wxGetActiveWindow()
6220 HWND hWnd
= GetActiveWindow();
6223 return wxFindWinFromHandle(hWnd
);
6228 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
6230 HWND hwnd
= (HWND
)hWnd
;
6232 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
6233 // by code in msw/radiobox.cpp), for all the others we just search up the
6235 wxWindow
*win
= NULL
;
6238 win
= wxFindWinFromHandle(hwnd
);
6242 // native radiobuttons return DLGC_RADIOBUTTON here and for any
6243 // wxWindow class which overrides WM_GETDLGCODE processing to
6244 // do it as well, win would be already non NULL
6245 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
6247 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
6249 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
6250 #endif // wxUSE_RADIOBOX
6252 // spin control text buddy window should be mapped to spin ctrl
6253 // itself so try it too
6254 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
6257 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
6259 #endif // wxUSE_SPINCTRL
6263 while ( hwnd
&& !win
)
6265 // this is a really ugly hack needed to avoid mistakenly returning the
6266 // parent frame wxWindow for the find/replace modeless dialog HWND -
6267 // this, in turn, is needed to call IsDialogMessage() from
6268 // wxApp::ProcessMessage() as for this we must return NULL from here
6270 // FIXME: this is clearly not the best way to do it but I think we'll
6271 // need to change HWND <-> wxWindow code more heavily than I can
6272 // do it now to fix it
6273 #ifndef __WXMICROWIN__
6274 if ( ::GetWindow(hwnd
, GW_OWNER
) )
6276 // it's a dialog box, don't go upwards
6281 hwnd
= ::GetParent(hwnd
);
6282 win
= wxFindWinFromHandle(hwnd
);
6288 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
6290 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
6291 // in active frames and dialogs, regardless of where the focus is.
6292 static HHOOK wxTheKeyboardHook
= 0;
6295 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
6297 DWORD hiWord
= HIWORD(lParam
);
6298 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
6300 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
6303 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
6304 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
6305 event
.m_altDown
= true;
6307 event
.SetEventObject(NULL
);
6308 event
.m_keyCode
= id
;
6309 event
.m_shiftDown
= wxIsShiftDown();
6310 event
.m_controlDown
= wxIsCtrlDown();
6312 event
.SetTimestamp(::GetMessageTime());
6314 wxWindow
*win
= wxGetActiveWindow();
6315 wxEvtHandler
*handler
;
6318 handler
= win
->GetEventHandler();
6319 event
.SetId(win
->GetId());
6324 event
.SetId(wxID_ANY
);
6327 if ( handler
&& handler
->ProcessEvent(event
) )
6335 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
6338 void wxSetKeyboardHook(bool doIt
)
6342 wxTheKeyboardHook
= ::SetWindowsHookEx
6345 (HOOKPROC
)wxKeyboardHook
,
6346 NULL
, // must be NULL for process hook
6347 ::GetCurrentThreadId()
6349 if ( !wxTheKeyboardHook
)
6351 wxLogLastError(_T("SetWindowsHookEx(wxKeyboardHook)"));
6356 if ( wxTheKeyboardHook
)
6357 ::UnhookWindowsHookEx(wxTheKeyboardHook
);
6361 #endif // !__WXMICROWIN__
6363 #if wxDEBUG_LEVEL >= 2
6364 const wxChar
*wxGetMessageName(int message
)
6368 case 0x0000: return wxT("WM_NULL");
6369 case 0x0001: return wxT("WM_CREATE");
6370 case 0x0002: return wxT("WM_DESTROY");
6371 case 0x0003: return wxT("WM_MOVE");
6372 case 0x0005: return wxT("WM_SIZE");
6373 case 0x0006: return wxT("WM_ACTIVATE");
6374 case 0x0007: return wxT("WM_SETFOCUS");
6375 case 0x0008: return wxT("WM_KILLFOCUS");
6376 case 0x000A: return wxT("WM_ENABLE");
6377 case 0x000B: return wxT("WM_SETREDRAW");
6378 case 0x000C: return wxT("WM_SETTEXT");
6379 case 0x000D: return wxT("WM_GETTEXT");
6380 case 0x000E: return wxT("WM_GETTEXTLENGTH");
6381 case 0x000F: return wxT("WM_PAINT");
6382 case 0x0010: return wxT("WM_CLOSE");
6383 case 0x0011: return wxT("WM_QUERYENDSESSION");
6384 case 0x0012: return wxT("WM_QUIT");
6385 case 0x0013: return wxT("WM_QUERYOPEN");
6386 case 0x0014: return wxT("WM_ERASEBKGND");
6387 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
6388 case 0x0016: return wxT("WM_ENDSESSION");
6389 case 0x0017: return wxT("WM_SYSTEMERROR");
6390 case 0x0018: return wxT("WM_SHOWWINDOW");
6391 case 0x0019: return wxT("WM_CTLCOLOR");
6392 case 0x001A: return wxT("WM_WININICHANGE");
6393 case 0x001B: return wxT("WM_DEVMODECHANGE");
6394 case 0x001C: return wxT("WM_ACTIVATEAPP");
6395 case 0x001D: return wxT("WM_FONTCHANGE");
6396 case 0x001E: return wxT("WM_TIMECHANGE");
6397 case 0x001F: return wxT("WM_CANCELMODE");
6398 case 0x0020: return wxT("WM_SETCURSOR");
6399 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6400 case 0x0022: return wxT("WM_CHILDACTIVATE");
6401 case 0x0023: return wxT("WM_QUEUESYNC");
6402 case 0x0024: return wxT("WM_GETMINMAXINFO");
6403 case 0x0026: return wxT("WM_PAINTICON");
6404 case 0x0027: return wxT("WM_ICONERASEBKGND");
6405 case 0x0028: return wxT("WM_NEXTDLGCTL");
6406 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6407 case 0x002B: return wxT("WM_DRAWITEM");
6408 case 0x002C: return wxT("WM_MEASUREITEM");
6409 case 0x002D: return wxT("WM_DELETEITEM");
6410 case 0x002E: return wxT("WM_VKEYTOITEM");
6411 case 0x002F: return wxT("WM_CHARTOITEM");
6412 case 0x0030: return wxT("WM_SETFONT");
6413 case 0x0031: return wxT("WM_GETFONT");
6414 case 0x0037: return wxT("WM_QUERYDRAGICON");
6415 case 0x0039: return wxT("WM_COMPAREITEM");
6416 case 0x0041: return wxT("WM_COMPACTING");
6417 case 0x0044: return wxT("WM_COMMNOTIFY");
6418 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6419 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6420 case 0x0048: return wxT("WM_POWER");
6422 case 0x004A: return wxT("WM_COPYDATA");
6423 case 0x004B: return wxT("WM_CANCELJOURNAL");
6424 case 0x004E: return wxT("WM_NOTIFY");
6425 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6426 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6427 case 0x0052: return wxT("WM_TCARD");
6428 case 0x0053: return wxT("WM_HELP");
6429 case 0x0054: return wxT("WM_USERCHANGED");
6430 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6431 case 0x007B: return wxT("WM_CONTEXTMENU");
6432 case 0x007C: return wxT("WM_STYLECHANGING");
6433 case 0x007D: return wxT("WM_STYLECHANGED");
6434 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6435 case 0x007F: return wxT("WM_GETICON");
6436 case 0x0080: return wxT("WM_SETICON");
6438 case 0x0081: return wxT("WM_NCCREATE");
6439 case 0x0082: return wxT("WM_NCDESTROY");
6440 case 0x0083: return wxT("WM_NCCALCSIZE");
6441 case 0x0084: return wxT("WM_NCHITTEST");
6442 case 0x0085: return wxT("WM_NCPAINT");
6443 case 0x0086: return wxT("WM_NCACTIVATE");
6444 case 0x0087: return wxT("WM_GETDLGCODE");
6445 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6446 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6447 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6448 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6449 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6450 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6451 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6452 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6453 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6454 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6456 case 0x00B0: return wxT("EM_GETSEL");
6457 case 0x00B1: return wxT("EM_SETSEL");
6458 case 0x00B2: return wxT("EM_GETRECT");
6459 case 0x00B3: return wxT("EM_SETRECT");
6460 case 0x00B4: return wxT("EM_SETRECTNP");
6461 case 0x00B5: return wxT("EM_SCROLL");
6462 case 0x00B6: return wxT("EM_LINESCROLL");
6463 case 0x00B7: return wxT("EM_SCROLLCARET");
6464 case 0x00B8: return wxT("EM_GETMODIFY");
6465 case 0x00B9: return wxT("EM_SETMODIFY");
6466 case 0x00BA: return wxT("EM_GETLINECOUNT");
6467 case 0x00BB: return wxT("EM_LINEINDEX");
6468 case 0x00BC: return wxT("EM_SETHANDLE");
6469 case 0x00BD: return wxT("EM_GETHANDLE");
6470 case 0x00BE: return wxT("EM_GETTHUMB");
6471 case 0x00C1: return wxT("EM_LINELENGTH");
6472 case 0x00C2: return wxT("EM_REPLACESEL");
6473 case 0x00C4: return wxT("EM_GETLINE");
6474 case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */
6475 case 0x00C6: return wxT("EM_CANUNDO");
6476 case 0x00C7: return wxT("EM_UNDO");
6477 case 0x00C8: return wxT("EM_FMTLINES");
6478 case 0x00C9: return wxT("EM_LINEFROMCHAR");
6479 case 0x00CB: return wxT("EM_SETTABSTOPS");
6480 case 0x00CC: return wxT("EM_SETPASSWORDCHAR");
6481 case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER");
6482 case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE");
6483 case 0x00CF: return wxT("EM_SETREADONLY");
6484 case 0x00D0: return wxT("EM_SETWORDBREAKPROC");
6485 case 0x00D1: return wxT("EM_GETWORDBREAKPROC");
6486 case 0x00D2: return wxT("EM_GETPASSWORDCHAR");
6487 case 0x00D3: return wxT("EM_SETMARGINS");
6488 case 0x00D4: return wxT("EM_GETMARGINS");
6489 case 0x00D5: return wxT("EM_GETLIMITTEXT");
6490 case 0x00D6: return wxT("EM_POSFROMCHAR");
6491 case 0x00D7: return wxT("EM_CHARFROMPOS");
6492 case 0x00D8: return wxT("EM_SETIMESTATUS");
6493 case 0x00D9: return wxT("EM_GETIMESTATUS");
6495 case 0x0100: return wxT("WM_KEYDOWN");
6496 case 0x0101: return wxT("WM_KEYUP");
6497 case 0x0102: return wxT("WM_CHAR");
6498 case 0x0103: return wxT("WM_DEADCHAR");
6499 case 0x0104: return wxT("WM_SYSKEYDOWN");
6500 case 0x0105: return wxT("WM_SYSKEYUP");
6501 case 0x0106: return wxT("WM_SYSCHAR");
6502 case 0x0107: return wxT("WM_SYSDEADCHAR");
6503 case 0x0108: return wxT("WM_KEYLAST");
6505 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6506 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6507 case 0x010F: return wxT("WM_IME_COMPOSITION");
6509 case 0x0110: return wxT("WM_INITDIALOG");
6510 case 0x0111: return wxT("WM_COMMAND");
6511 case 0x0112: return wxT("WM_SYSCOMMAND");
6512 case 0x0113: return wxT("WM_TIMER");
6513 case 0x0114: return wxT("WM_HSCROLL");
6514 case 0x0115: return wxT("WM_VSCROLL");
6515 case 0x0116: return wxT("WM_INITMENU");
6516 case 0x0117: return wxT("WM_INITMENUPOPUP");
6517 case 0x011F: return wxT("WM_MENUSELECT");
6518 case 0x0120: return wxT("WM_MENUCHAR");
6519 case 0x0121: return wxT("WM_ENTERIDLE");
6521 case 0x0132: return wxT("WM_CTLCOLORMSGBOX");
6522 case 0x0133: return wxT("WM_CTLCOLOREDIT");
6523 case 0x0134: return wxT("WM_CTLCOLORLISTBOX");
6524 case 0x0135: return wxT("WM_CTLCOLORBTN");
6525 case 0x0136: return wxT("WM_CTLCOLORDLG");
6526 case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR");
6527 case 0x0138: return wxT("WM_CTLCOLORSTATIC");
6528 case 0x01E1: return wxT("MN_GETHMENU");
6530 case 0x0200: return wxT("WM_MOUSEMOVE");
6531 case 0x0201: return wxT("WM_LBUTTONDOWN");
6532 case 0x0202: return wxT("WM_LBUTTONUP");
6533 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6534 case 0x0204: return wxT("WM_RBUTTONDOWN");
6535 case 0x0205: return wxT("WM_RBUTTONUP");
6536 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6537 case 0x0207: return wxT("WM_MBUTTONDOWN");
6538 case 0x0208: return wxT("WM_MBUTTONUP");
6539 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6540 case 0x020A: return wxT("WM_MOUSEWHEEL");
6541 case 0x020B: return wxT("WM_XBUTTONDOWN");
6542 case 0x020C: return wxT("WM_XBUTTONUP");
6543 case 0x020D: return wxT("WM_XBUTTONDBLCLK");
6544 case 0x0210: return wxT("WM_PARENTNOTIFY");
6545 case 0x0211: return wxT("WM_ENTERMENULOOP");
6546 case 0x0212: return wxT("WM_EXITMENULOOP");
6548 case 0x0213: return wxT("WM_NEXTMENU");
6549 case 0x0214: return wxT("WM_SIZING");
6550 case 0x0215: return wxT("WM_CAPTURECHANGED");
6551 case 0x0216: return wxT("WM_MOVING");
6552 case 0x0218: return wxT("WM_POWERBROADCAST");
6553 case 0x0219: return wxT("WM_DEVICECHANGE");
6555 case 0x0220: return wxT("WM_MDICREATE");
6556 case 0x0221: return wxT("WM_MDIDESTROY");
6557 case 0x0222: return wxT("WM_MDIACTIVATE");
6558 case 0x0223: return wxT("WM_MDIRESTORE");
6559 case 0x0224: return wxT("WM_MDINEXT");
6560 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6561 case 0x0226: return wxT("WM_MDITILE");
6562 case 0x0227: return wxT("WM_MDICASCADE");
6563 case 0x0228: return wxT("WM_MDIICONARRANGE");
6564 case 0x0229: return wxT("WM_MDIGETACTIVE");
6565 case 0x0230: return wxT("WM_MDISETMENU");
6566 case 0x0233: return wxT("WM_DROPFILES");
6568 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6569 case 0x0282: return wxT("WM_IME_NOTIFY");
6570 case 0x0283: return wxT("WM_IME_CONTROL");
6571 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6572 case 0x0285: return wxT("WM_IME_SELECT");
6573 case 0x0286: return wxT("WM_IME_CHAR");
6574 case 0x0290: return wxT("WM_IME_KEYDOWN");
6575 case 0x0291: return wxT("WM_IME_KEYUP");
6577 case 0x02A0: return wxT("WM_NCMOUSEHOVER");
6578 case 0x02A1: return wxT("WM_MOUSEHOVER");
6579 case 0x02A2: return wxT("WM_NCMOUSELEAVE");
6580 case 0x02A3: return wxT("WM_MOUSELEAVE");
6582 case 0x0300: return wxT("WM_CUT");
6583 case 0x0301: return wxT("WM_COPY");
6584 case 0x0302: return wxT("WM_PASTE");
6585 case 0x0303: return wxT("WM_CLEAR");
6586 case 0x0304: return wxT("WM_UNDO");
6587 case 0x0305: return wxT("WM_RENDERFORMAT");
6588 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6589 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6590 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6591 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6592 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6593 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6594 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6595 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6596 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6597 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6598 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6599 case 0x0311: return wxT("WM_PALETTECHANGED");
6600 case 0x0312: return wxT("WM_HOTKEY");
6602 case 0x0317: return wxT("WM_PRINT");
6603 case 0x0318: return wxT("WM_PRINTCLIENT");
6605 // common controls messages - although they're not strictly speaking
6606 // standard, it's nice to decode them nevertheless
6609 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6610 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6611 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6612 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6613 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6614 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6615 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6616 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6617 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6618 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6619 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6620 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6621 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6622 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6623 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6624 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6625 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6626 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6627 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6628 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6629 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6630 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6631 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6632 case 0x1000 + 18: return wxT("LVM_HITTEST");
6633 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6634 case 0x1000 + 20: return wxT("LVM_SCROLL");
6635 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6636 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6637 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6638 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6639 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6640 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6641 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6642 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6643 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6644 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6645 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6646 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6647 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6648 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6649 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6650 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6651 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6652 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6653 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6654 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6655 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6656 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6657 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6658 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6659 case 0x1000 + 42: return wxT("LVM_UPDATE");
6660 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6661 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6662 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6663 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6664 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6665 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6666 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6667 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6668 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6669 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6670 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6671 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6672 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6673 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6674 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6675 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6676 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6677 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6678 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6679 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6680 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6681 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6682 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6683 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6684 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6685 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6688 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6689 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6690 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6691 case 0x1100 + 2: return wxT("TVM_EXPAND");
6692 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6693 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6694 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6695 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6696 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6697 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6698 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6699 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6700 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6701 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6702 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6703 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6704 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6705 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6706 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6707 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6708 case 0x1100 + 17: return wxT("TVM_HITTEST");
6709 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6710 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6711 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6712 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6713 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6714 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6715 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6716 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6717 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6720 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6721 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6722 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6723 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6724 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6725 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6726 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6727 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6728 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6729 case 0x1200 + 6: return wxT("HDM_HITTEST");
6730 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6731 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6732 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6733 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6734 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6735 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6736 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6737 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6740 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6741 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6742 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6743 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6744 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6745 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6746 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6747 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6748 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6749 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6750 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6751 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6752 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6753 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6754 case 0x1300 + 13: return wxT("TCM_HITTEST");
6755 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6756 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6757 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6758 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6759 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6760 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6761 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6762 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6763 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6764 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6765 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6766 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6769 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6770 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
6771 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
6772 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
6773 case WM_USER
+5: return wxT("TB_INDETERMINATE");
6774 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
6775 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
6776 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
6777 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
6778 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
6779 case WM_USER
+17: return wxT("TB_SETSTATE");
6780 case WM_USER
+18: return wxT("TB_GETSTATE");
6781 case WM_USER
+19: return wxT("TB_ADDBITMAP");
6782 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
6783 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
6784 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
6785 case WM_USER
+23: return wxT("TB_GETBUTTON");
6786 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
6787 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
6788 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
6789 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
6790 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
6791 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
6792 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
6793 case WM_USER
+29: return wxT("TB_GETITEMRECT");
6794 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
6795 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
6796 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
6797 case WM_USER
+33: return wxT("TB_AUTOSIZE");
6798 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
6799 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
6800 case WM_USER
+37: return wxT("TB_SETPARENT");
6801 case WM_USER
+39: return wxT("TB_SETROWS");
6802 case WM_USER
+40: return wxT("TB_GETROWS");
6803 case WM_USER
+42: return wxT("TB_SETCMDID");
6804 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
6805 case WM_USER
+44: return wxT("TB_GETBITMAP");
6806 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
6807 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
6808 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
6809 case WM_USER
+47: return wxT("TB_SETINDENT");
6810 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
6811 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
6812 case WM_USER
+50: return wxT("TB_LOADIMAGES");
6813 case WM_USER
+51: return wxT("TB_GETRECT");
6814 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
6815 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
6816 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
6817 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
6818 case WM_USER
+56: return wxT("TB_SETSTYLE");
6819 case WM_USER
+57: return wxT("TB_GETSTYLE");
6820 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
6821 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
6822 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
6823 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
6824 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
6827 static wxString s_szBuf
;
6828 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
6829 return s_szBuf
.c_str();
6832 #endif // wxDEBUG_LEVEL >= 2
6834 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
6838 HWND hwnd
= GetHwndOf(win
);
6839 HDC hdc
= ::GetDC(hwnd
);
6841 #if !wxDIALOG_UNIT_COMPATIBILITY
6842 // and select the current font into it
6843 HFONT hfont
= GetHfontOf(win
->GetFont());
6846 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
6850 // finally retrieve the text metrics from it
6851 GetTextMetrics(hdc
, &tm
);
6853 #if !wxDIALOG_UNIT_COMPATIBILITY
6857 (void)::SelectObject(hdc
, hfont
);
6861 ::ReleaseDC(hwnd
, hdc
);
6866 // Find the wxWindow at the current mouse position, returning the mouse
6868 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
6870 pt
= wxGetMousePosition();
6871 return wxFindWindowAtPoint(pt
);
6874 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
6880 HWND hWnd
= ::WindowFromPoint(pt2
);
6882 return wxGetWindowFromHWND((WXHWND
)hWnd
);
6885 // Get the current mouse position.
6886 wxPoint
wxGetMousePosition()
6890 GetCursorPosWinCE(&pt
);
6892 GetCursorPos( & pt
);
6895 return wxPoint(pt
.x
, pt
.y
);
6900 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6901 static void WinCEUnregisterHotKey(int modifiers
, int id
)
6903 // Register hotkeys for the hardware buttons
6905 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
6907 UnregisterFunc1Proc procUnregisterFunc
;
6908 hCoreDll
= LoadLibrary(_T("coredll.dll"));
6911 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, _T("UnregisterFunc1"));
6912 if (procUnregisterFunc
)
6913 procUnregisterFunc(modifiers
, id
);
6914 FreeLibrary(hCoreDll
);
6919 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
6921 UINT win_modifiers
=0;
6922 if ( modifiers
& wxMOD_ALT
)
6923 win_modifiers
|= MOD_ALT
;
6924 if ( modifiers
& wxMOD_SHIFT
)
6925 win_modifiers
|= MOD_SHIFT
;
6926 if ( modifiers
& wxMOD_CONTROL
)
6927 win_modifiers
|= MOD_CONTROL
;
6928 if ( modifiers
& wxMOD_WIN
)
6929 win_modifiers
|= MOD_WIN
;
6931 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6932 // Required for PPC and Smartphone hardware buttons
6933 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
6934 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
6937 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
6939 wxLogLastError(_T("RegisterHotKey"));
6947 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
6949 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6950 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
6953 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
6955 wxLogLastError(_T("UnregisterHotKey"));
6965 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
6967 int hotkeyId
= wParam
;
6968 int virtualKey
= HIWORD(lParam
);
6969 int win_modifiers
= LOWORD(lParam
);
6971 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
6972 event
.SetId(hotkeyId
);
6973 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
6974 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
6975 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
6976 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
6978 return HandleWindowEvent(event
);
6981 #endif // wxUSE_ACCEL
6983 #endif // wxUSE_HOTKEY
6985 // Not tested under WinCE
6988 // this class installs a message hook which really wakes up our idle processing
6989 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
6990 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
6991 // being dragged or even inside ::MessageBox()) and so don't control message
6992 // dispatching otherwise
6993 class wxIdleWakeUpModule
: public wxModule
6996 virtual bool OnInit()
6998 ms_hMsgHookProc
= ::SetWindowsHookEx
7001 &wxIdleWakeUpModule::MsgHookProc
,
7003 GetCurrentThreadId()
7006 if ( !ms_hMsgHookProc
)
7008 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
7016 virtual void OnExit()
7018 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
7021 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
7023 MSG
*msg
= (MSG
*)lParam
;
7025 // only process the message if it is actually going to be removed from
7026 // the message queue, this prevents that the same event from being
7027 // processed multiple times if now someone just called PeekMessage()
7028 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
7030 wxTheApp
->ProcessPendingEvents();
7033 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
7037 static HHOOK ms_hMsgHookProc
;
7039 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
7042 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
7044 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
7046 #endif // __WXWINCE__
7051 static void wxAdjustZOrder(wxWindow
* parent
)
7053 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
7055 // Set the z-order correctly
7056 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
7059 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
7062 wxWindow
*childWin
= current
->GetData();
7063 wxAdjustZOrder(childWin
);
7064 current
= current
->GetNext();
7069 // We need to adjust the z-order of static boxes in WinCE, to
7070 // make 'contained' controls visible
7071 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
7074 wxAdjustZOrder(this);