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/evtloop.h"
62 #include "wx/sysopt.h"
64 #if wxUSE_DRAG_AND_DROP
68 #if wxUSE_ACCESSIBILITY
69 #include "wx/access.h"
73 #define WM_GETOBJECT 0x003D
76 #define OBJID_CLIENT 0xFFFFFFFC
80 #include "wx/msw/private.h"
83 #include "wx/tooltip.h"
91 #include "wx/spinctrl.h"
92 #endif // wxUSE_SPINCTRL
94 #include "wx/notebook.h"
95 #include "wx/listctrl.h"
96 #include "wx/dynlib.h"
100 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
101 #include <shellapi.h>
102 #include <mmsystem.h>
106 #include <windowsx.h>
109 #if !defined __WXWINCE__ && !defined NEED_PBT_H
113 #if defined(__WXWINCE__)
114 #include "wx/msw/wince/missing.h"
117 #include <shellapi.h>
119 #include <aygshell.h>
123 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS
124 #define HAVE_TRACKMOUSEEVENT
125 #endif // everything needed for TrackMouseEvent()
127 // if this is set to 1, we use deferred window sizing to reduce flicker when
128 // resizing complicated window hierarchies, but this can in theory result in
129 // different behaviour than the old code so we keep the possibility to use it
130 // by setting this to 0 (in the future this should be removed completely)
132 #define USE_DEFERRED_SIZING 0
134 #define USE_DEFERRED_SIZING 1
137 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
138 // when mouse position didnd't change
140 #define wxUSE_MOUSEEVENT_HACK 0
142 #define wxUSE_MOUSEEVENT_HACK 1
145 // ---------------------------------------------------------------------------
147 // ---------------------------------------------------------------------------
149 #if wxUSE_MENUS_NATIVE
150 wxMenu
*wxCurrentPopupMenu
= NULL
;
151 #endif // wxUSE_MENUS_NATIVE
154 extern wxChar
*wxCanvasClassName
;
156 extern const wxChar
*wxCanvasClassName
;
159 // true if we had already created the std colour map, used by
160 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
161 static bool gs_hasStdCmap
= false;
163 // last mouse event information we need to filter out the duplicates
164 #if wxUSE_MOUSEEVENT_HACK
165 static struct MouseEventInfoDummy
167 // mouse position (in screen coordinates)
170 // last mouse event type
173 #endif // wxUSE_MOUSEEVENT_HACK
175 // ---------------------------------------------------------------------------
177 // ---------------------------------------------------------------------------
179 // the window proc for all our windows
180 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
181 WPARAM wParam
, LPARAM lParam
);
185 const wxChar
*wxGetMessageName(int message
);
188 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
189 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
190 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
192 // get the text metrics for the current font
193 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
196 // find the window for the mouse event at the specified position
197 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
198 #endif // __WXWINCE__
200 // wrapper around BringWindowToTop() API
201 static inline void wxBringWindowToTop(HWND hwnd
)
203 #ifdef __WXMICROWIN__
204 // It seems that MicroWindows brings the _parent_ of the window to the top,
205 // which can be the wrong one.
207 // activate (set focus to) specified window
211 // raise top level parent to top of z order
212 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
214 wxLogLastError(_T("SetWindowPos"));
220 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
221 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
224 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
225 parent as well as otherwise several Win32 functions using
226 GetNextDlgTabItem() to iterate over all controls such as
227 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
228 all of them iterate over all the controls starting from the currently
229 focused one and stop iterating when they get back to the focus but
230 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
231 get back to the initial (focused) window: as we do have this style,
232 GetNextDlgTabItem() will leave this window and continue in its parent,
233 but if the parent doesn't have it, it wouldn't recurse inside it later
234 on and so wouldn't have a chance of getting back to this window either.
236 while ( parent
&& !parent
->IsTopLevel() )
238 LONG exStyle
= ::GetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
);
239 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
241 // force the parent to have this style
242 ::SetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
,
243 exStyle
| WS_EX_CONTROLPARENT
);
246 parent
= parent
->GetParent();
250 #endif // !__WXWINCE__
253 // On Windows CE, GetCursorPos can return an error, so use this function
255 bool GetCursorPosWinCE(POINT
* pt
)
257 if (!GetCursorPos(pt
))
259 DWORD pos
= GetMessagePos();
267 // ---------------------------------------------------------------------------
269 // ---------------------------------------------------------------------------
271 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
273 #ifdef __WXUNIVERSAL__
274 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
276 #if wxUSE_EXTENDED_RTTI
278 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
279 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
280 // windows with negative ids never can be recreated anyway
282 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
284 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
285 if ( win
&& win
->GetId() < 0 )
290 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
292 // make wxWindowList known before the property is used
294 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
296 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
298 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
301 WX_DEFINE_FLAGS( wxWindowStyle
)
303 wxBEGIN_FLAGS( wxWindowStyle
)
304 // new style border flags, we put them first to
305 // use them for streaming out
307 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
308 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
309 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
310 wxFLAGS_MEMBER(wxBORDER_RAISED
)
311 wxFLAGS_MEMBER(wxBORDER_STATIC
)
312 wxFLAGS_MEMBER(wxBORDER_NONE
)
314 // old style border flags
315 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
316 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
317 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
318 wxFLAGS_MEMBER(wxRAISED_BORDER
)
319 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
320 wxFLAGS_MEMBER(wxBORDER
)
322 // standard window styles
323 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
324 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
325 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
326 wxFLAGS_MEMBER(wxWANTS_CHARS
)
327 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
328 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
329 wxFLAGS_MEMBER(wxVSCROLL
)
330 wxFLAGS_MEMBER(wxHSCROLL
)
332 wxEND_FLAGS( wxWindowStyle
)
334 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
335 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
336 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
337 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
338 // Always constructor Properties first
340 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
341 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
342 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
343 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
344 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
346 // Then all relations of the object graph
348 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
350 // and finally all other properties
352 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
353 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
354 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
355 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
356 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
358 // possible property candidates (not in xrc) or not valid in all subclasses
359 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
360 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
361 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
362 // MaxHeight, Width , MinHeight , Width
363 // TODO switch label to control and title to toplevels
365 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
366 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
367 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
368 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
373 wxEND_PROPERTIES_TABLE()
375 wxBEGIN_HANDLERS_TABLE(wxWindow
)
376 wxEND_HANDLERS_TABLE()
378 wxCONSTRUCTOR_DUMMY(wxWindow
)
381 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
383 #endif // __WXUNIVERSAL__/__WXMSW__
385 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
386 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
387 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground
)
389 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
393 // ===========================================================================
395 // ===========================================================================
397 // ---------------------------------------------------------------------------
398 // wxWindow utility functions
399 // ---------------------------------------------------------------------------
401 // Find an item given the MS Windows id
402 wxWindow
*wxWindowMSW::FindItem(long id
) const
405 wxControl
*item
= wxDynamicCastThis(wxControl
);
408 // is it us or one of our "internal" children?
409 if ( item
->GetId() == id
410 #ifndef __WXUNIVERSAL__
411 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
412 #endif // __WXUNIVERSAL__
418 #endif // wxUSE_CONTROLS
420 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
423 wxWindow
*childWin
= current
->GetData();
425 wxWindow
*wnd
= childWin
->FindItem(id
);
429 current
= current
->GetNext();
435 // Find an item given the MS Windows handle
436 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
438 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
441 wxWindow
*parent
= current
->GetData();
443 // Do a recursive search.
444 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
450 || parent
->IsKindOf(CLASSINFO(wxControl
))
451 #endif // wxUSE_CONTROLS
454 wxWindow
*item
= current
->GetData();
455 if ( item
->GetHWND() == hWnd
)
459 if ( item
->ContainsHWND(hWnd
) )
464 current
= current
->GetNext();
469 // Default command handler
470 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
475 // ----------------------------------------------------------------------------
476 // constructors and such
477 // ----------------------------------------------------------------------------
479 void wxWindowMSW::Init()
482 m_isBeingDeleted
= false;
484 m_mouseInWindow
= false;
485 m_lastKeydownProcessed
= false;
487 m_childrenDisabled
= NULL
;
496 m_pendingPosition
= wxDefaultPosition
;
497 m_pendingSize
= wxDefaultSize
;
500 m_contextMenuEnabled
= false;
505 wxWindowMSW::~wxWindowMSW()
507 m_isBeingDeleted
= true;
509 #ifndef __WXUNIVERSAL__
510 // VS: make sure there's no wxFrame with last focus set to us:
511 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
513 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
516 if ( frame
->GetLastFocus() == this )
518 frame
->SetLastFocus(NULL
);
521 // apparently sometimes we can end up with our grand parent
522 // pointing to us as well: this is surely a bug in focus handling
523 // code but it's not clear where it happens so for now just try to
524 // fix it here by not breaking out of the loop
528 #endif // __WXUNIVERSAL__
530 // VS: destroy children first and _then_ detach *this from its parent.
531 // If we did it the other way around, children wouldn't be able
532 // find their parent frame (see above).
537 // VZ: test temp removed to understand what really happens here
538 //if (::IsWindow(GetHwnd()))
540 if ( !::DestroyWindow(GetHwnd()) )
541 wxLogLastError(wxT("DestroyWindow"));
544 // remove hWnd <-> wxWindow association
545 wxRemoveHandleAssociation(this);
548 delete m_childrenDisabled
;
552 // real construction (Init() must have been called before!)
553 bool wxWindowMSW::Create(wxWindow
*parent
,
558 const wxString
& name
)
560 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
562 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
565 parent
->AddChild(this);
568 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
570 #ifdef __WXUNIVERSAL__
571 // no borders, we draw them ourselves
572 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
576 msflags
&= ~WS_BORDER
;
577 #endif // wxUniversal
581 msflags
|= WS_VISIBLE
;
584 if ( !MSWCreate(wxCanvasClassName
, NULL
, pos
, size
, msflags
, exstyle
) )
592 // ---------------------------------------------------------------------------
594 // ---------------------------------------------------------------------------
596 void wxWindowMSW::SetFocus()
598 HWND hWnd
= GetHwnd();
599 wxCHECK_RET( hWnd
, _T("can't set focus to invalid window") );
601 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
605 if ( !::SetFocus(hWnd
) )
607 #if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
608 // was there really an error?
609 DWORD dwRes
= ::GetLastError();
612 HWND hwndFocus
= ::GetFocus();
613 if ( hwndFocus
!= hWnd
)
615 wxLogApiError(_T("SetFocus"), dwRes
);
622 void wxWindowMSW::SetFocusFromKbd()
624 // when the focus is given to the control with DLGC_HASSETSEL style from
625 // keyboard its contents should be entirely selected: this is what
626 // ::IsDialogMessage() does and so we should do it as well to provide the
627 // same LNF as the native programs
628 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
630 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
633 // do this after (maybe) setting the selection as like this when
634 // wxEVT_SET_FOCUS handler is called, the selection would have been already
635 // set correctly -- this may be important
636 wxWindowBase::SetFocusFromKbd();
639 // Get the window with the focus
640 wxWindow
*wxWindowBase::DoFindFocus()
642 HWND hWnd
= ::GetFocus();
645 return wxGetWindowFromHWND((WXHWND
)hWnd
);
651 bool wxWindowMSW::Enable(bool enable
)
653 if ( !wxWindowBase::Enable(enable
) )
656 HWND hWnd
= GetHwnd();
658 ::EnableWindow(hWnd
, (BOOL
)enable
);
660 // the logic below doesn't apply to the top level windows -- otherwise
661 // showing a modal dialog would result in total greying out (and ungreying
662 // out later) of everything which would be really ugly
666 // when the parent is disabled, all of its children should be disabled as
667 // well but when it is enabled back, only those of the children which
668 // hadn't been already disabled in the beginning should be enabled again,
669 // so we have to keep the list of those children
670 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
672 node
= node
->GetNext() )
674 wxWindow
*child
= node
->GetData();
675 if ( child
->IsTopLevel() )
677 // the logic below doesn't apply to top level children
683 // re-enable the child unless it had been disabled before us
684 if ( !m_childrenDisabled
|| !m_childrenDisabled
->Find(child
) )
687 else // we're being disabled
689 if ( child
->IsEnabled() )
691 // disable it as children shouldn't stay enabled while the
695 else // child already disabled, remember it
697 // have we created the list of disabled children already?
698 if ( !m_childrenDisabled
)
699 m_childrenDisabled
= new wxWindowList
;
701 m_childrenDisabled
->Append(child
);
706 if ( enable
&& m_childrenDisabled
)
708 // we don't need this list any more, don't keep unused memory
709 delete m_childrenDisabled
;
710 m_childrenDisabled
= NULL
;
716 bool wxWindowMSW::Show(bool show
)
718 if ( !wxWindowBase::Show(show
) )
721 HWND hWnd
= GetHwnd();
723 // we could be called before the underlying window is created (this is
724 // actually useful to prevent it from being initially shown), e.g.
726 // wxFoo *foo = new wxFoo;
728 // foo->Create(parent, ...);
730 // should work without errors
733 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
739 // Raise the window to the top of the Z order
740 void wxWindowMSW::Raise()
742 wxBringWindowToTop(GetHwnd());
745 // Lower the window to the bottom of the Z order
746 void wxWindowMSW::Lower()
748 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
749 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
752 void wxWindowMSW::DoCaptureMouse()
754 HWND hWnd
= GetHwnd();
761 void wxWindowMSW::DoReleaseMouse()
763 if ( !::ReleaseCapture() )
765 wxLogLastError(_T("ReleaseCapture"));
769 /* static */ wxWindow
*wxWindowBase::GetCapture()
771 HWND hwnd
= ::GetCapture();
772 return hwnd
? wxFindWinFromHandle((WXHWND
)hwnd
) : (wxWindow
*)NULL
;
775 bool wxWindowMSW::SetFont(const wxFont
& font
)
777 if ( !wxWindowBase::SetFont(font
) )
783 HWND hWnd
= GetHwnd();
786 WXHANDLE hFont
= m_font
.GetResourceHandle();
788 wxASSERT_MSG( hFont
, wxT("should have valid font") );
790 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
795 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
797 if ( !wxWindowBase::SetCursor(cursor
) )
803 // don't "overwrite" busy cursor
804 if ( m_cursor
.Ok() && !wxIsBusy() )
806 // normally we should change the cursor only if it's over this window
807 // but we should do it always if we capture the mouse currently
808 bool set
= HasCapture();
811 HWND hWnd
= GetHwnd();
815 ::GetCursorPosWinCE(&point
);
817 ::GetCursorPos(&point
);
820 RECT rect
= wxGetWindowRect(hWnd
);
822 set
= ::PtInRect(&rect
, point
) != 0;
827 ::SetCursor(GetHcursorOf(m_cursor
));
829 //else: will be set later when the mouse enters this window
835 void wxWindowMSW::WarpPointer(int x
, int y
)
837 ClientToScreen(&x
, &y
);
839 if ( !::SetCursorPos(x
, y
) )
841 wxLogLastError(_T("SetCursorPos"));
845 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
847 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
848 // to use it on older systems -- and could possibly do some harm
849 static int s_needToUpdate
= -1;
850 if ( s_needToUpdate
== -1 )
853 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
857 if ( s_needToUpdate
)
859 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
860 // won't send WM_UPDATEUISTATE
861 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
865 // ---------------------------------------------------------------------------
867 // ---------------------------------------------------------------------------
869 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
871 #ifdef __WXMICROWIN__
872 return ::GetScrollPosWX(hWnd
, wOrient
);
874 WinStruct
<SCROLLINFO
> scrollInfo
;
875 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
876 scrollInfo
.fMask
= SIF_POS
;
877 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
879 return scrollInfo
.nPos
;
884 int wxWindowMSW::GetScrollPos(int orient
) const
886 HWND hWnd
= GetHwnd();
887 wxCHECK_MSG( hWnd
, 0, _T("no HWND in GetScrollPos") );
889 return GetScrollPosition(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
);
892 // This now returns the whole range, not just the number
893 // of positions that we can scroll.
894 int wxWindowMSW::GetScrollRange(int orient
) const
897 HWND hWnd
= GetHwnd();
901 ::GetScrollRange(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
904 WinStruct
<SCROLLINFO
> scrollInfo
;
905 scrollInfo
.fMask
= SIF_RANGE
;
906 if ( !::GetScrollInfo(hWnd
,
907 orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
910 // Most of the time this is not really an error, since the return
911 // value can also be zero when there is no scrollbar yet.
912 // wxLogLastError(_T("GetScrollInfo"));
914 maxPos
= scrollInfo
.nMax
;
916 // undo "range - 1" done in SetScrollbar()
920 int wxWindowMSW::GetScrollThumb(int orient
) const
922 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
925 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
927 HWND hWnd
= GetHwnd();
928 wxCHECK_RET( hWnd
, _T("SetScrollPos: no HWND") );
930 WinStruct
<SCROLLINFO
> info
;
934 info
.fMask
= SIF_POS
;
935 if ( HasFlag(wxALWAYS_SHOW_SB
) )
937 // disable scrollbar instead of removing it then
938 info
.fMask
|= SIF_DISABLENOSCROLL
;
941 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
945 // New function that will replace some of the above.
946 void wxWindowMSW::SetScrollbar(int orient
,
952 WinStruct
<SCROLLINFO
> info
;
953 info
.nPage
= pageSize
;
954 info
.nMin
= 0; // range is nMax - nMin + 1
955 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
957 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
958 if ( HasFlag(wxALWAYS_SHOW_SB
) )
960 // disable scrollbar instead of removing it then
961 info
.fMask
|= SIF_DISABLENOSCROLL
;
964 HWND hWnd
= GetHwnd();
967 // We have to set the variables here to make them valid in events
968 // triggered by ::SetScrollInfo()
969 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
971 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
976 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
982 rect
.left
= prect
->x
;
984 rect
.right
= prect
->x
+ prect
->width
;
985 rect
.bottom
= prect
->y
+ prect
->height
;
995 // FIXME: is this the exact equivalent of the line below?
996 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
998 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
1002 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
1004 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
1007 for ( int n
= 0; n
< count
; n
++ )
1009 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
1011 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
1012 if ( posNew
== pos
)
1014 // don't bother to continue, we're already at top/bottom
1021 return pos
!= posStart
;
1024 bool wxWindowMSW::ScrollLines(int lines
)
1026 bool down
= lines
> 0;
1028 return ScrollVertically(GetHwnd(),
1029 down
? SB_LINEDOWN
: SB_LINEUP
,
1030 down
? lines
: -lines
);
1033 bool wxWindowMSW::ScrollPages(int pages
)
1035 bool down
= pages
> 0;
1037 return ScrollVertically(GetHwnd(),
1038 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1039 down
? pages
: -pages
);
1042 // ----------------------------------------------------------------------------
1044 // ----------------------------------------------------------------------------
1046 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
1051 const HWND hwnd
= GetHwnd();
1052 wxCHECK_RET( hwnd
, _T("layout direction must be set after window creation") );
1054 LONG styleOld
= ::GetWindowLong(hwnd
, GWL_EXSTYLE
);
1056 LONG styleNew
= styleOld
;
1059 case wxLayout_LeftToRight
:
1060 styleNew
&= ~WS_EX_LAYOUTRTL
;
1063 case wxLayout_RightToLeft
:
1064 styleNew
|= WS_EX_LAYOUTRTL
;
1068 wxFAIL_MSG(_T("unsupported layout direction"));
1072 if ( styleNew
!= styleOld
)
1074 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, styleNew
);
1079 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1082 return wxLayout_Default
;
1084 const HWND hwnd
= GetHwnd();
1085 wxCHECK_MSG( hwnd
, wxLayout_Default
, _T("invalid window") );
1087 return ::GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
1088 ? wxLayout_RightToLeft
1089 : wxLayout_LeftToRight
;
1094 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1095 wxCoord
WXUNUSED(width
),
1096 wxCoord
WXUNUSED(widthTotal
)) const
1098 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1099 // redo it ourselves
1103 // ---------------------------------------------------------------------------
1105 // ---------------------------------------------------------------------------
1107 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1109 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1111 HWND hwnd
= (HWND
)hWnd
;
1112 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1114 wxAssociateWinWithHandle(hwnd
, this);
1116 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1118 // we don't need to subclass the window of our own class (in the Windows
1119 // sense of the word)
1120 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1122 wxSetWindowProc(hwnd
, wxWndProc
);
1126 // don't bother restoring it either: this also makes it easy to
1127 // implement IsOfStandardClass() method which returns true for the
1128 // standard controls and false for the wxWidgets own windows as it can
1129 // simply check m_oldWndProc
1130 m_oldWndProc
= NULL
;
1133 // we're officially created now, send the event
1134 wxWindowCreateEvent
event((wxWindow
*)this);
1135 (void)GetEventHandler()->ProcessEvent(event
);
1138 void wxWindowMSW::UnsubclassWin()
1140 wxRemoveHandleAssociation(this);
1142 // Restore old Window proc
1143 HWND hwnd
= GetHwnd();
1148 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1152 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1154 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1157 m_oldWndProc
= NULL
;
1162 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1166 if ( !::DestroyWindow(GetHwnd()) )
1167 wxLogLastError(wxT("DestroyWindow"));
1170 WXHWND wxhwnd
= (WXHWND
)handle
;
1173 SubclassWin(wxhwnd
);
1176 void wxWindowMSW::DissociateHandle()
1178 // this also calls SetHWND(0) for us
1183 bool wxCheckWindowWndProc(WXHWND hWnd
,
1184 WXFARPROC
WXUNUSED(wndProc
))
1186 // TODO: This list of window class names should be factored out so they can be
1187 // managed in one place and then accessed from here and other places, such as
1188 // wxApp::RegisterWindowClasses() and wxApp::UnregisterWindowClasses()
1191 extern wxChar
*wxCanvasClassName
;
1192 extern wxChar
*wxCanvasClassNameNR
;
1194 extern const wxChar
*wxCanvasClassName
;
1195 extern const wxChar
*wxCanvasClassNameNR
;
1197 extern const wxChar
*wxMDIFrameClassName
;
1198 extern const wxChar
*wxMDIFrameClassNameNoRedraw
;
1199 extern const wxChar
*wxMDIChildFrameClassName
;
1200 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
1201 wxString
str(wxGetWindowClass(hWnd
));
1202 if (str
== wxCanvasClassName
||
1203 str
== wxCanvasClassNameNR
||
1205 str
== _T("wxGLCanvasClass") ||
1206 str
== _T("wxGLCanvasClassNR") ||
1207 #endif // wxUSE_GLCANVAS
1208 str
== wxMDIFrameClassName
||
1209 str
== wxMDIFrameClassNameNoRedraw
||
1210 str
== wxMDIChildFrameClassName
||
1211 str
== wxMDIChildFrameClassNameNoRedraw
||
1212 str
== _T("wxTLWHiddenParent"))
1213 return true; // Effectively means don't subclass
1218 // ----------------------------------------------------------------------------
1220 // ----------------------------------------------------------------------------
1222 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1224 long flagsOld
= GetWindowStyleFlag();
1225 if ( flags
== flagsOld
)
1228 // update the internal variable
1229 wxWindowBase::SetWindowStyleFlag(flags
);
1231 // and the real window flags
1232 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1235 void wxWindowMSW::SetExtraStyle(long exflags
)
1237 long exflagsOld
= GetExtraStyle();
1238 if ( exflags
== exflagsOld
)
1241 // update the internal variable
1242 wxWindowBase::SetExtraStyle(exflags
);
1244 // and the real window flags
1245 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1248 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1250 // now update the Windows style as well if needed - and if the window had
1251 // been already created
1255 // we may need to call SetWindowPos() when we change some styles
1256 bool callSWP
= false;
1259 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1261 // this is quite a horrible hack but we need it because MSWGetStyle()
1262 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1263 // and so we have to modify the window exflags temporarily to get the
1264 // correct exstyleOld
1265 long exflagsNew
= GetExtraStyle();
1266 wxWindowBase::SetExtraStyle(exflagsOld
);
1269 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1271 wxWindowBase::SetExtraStyle(exflagsNew
);
1274 if ( style
!= styleOld
)
1276 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1277 // this function so instead of simply setting the style to the new
1278 // value we clear the bits which were set in styleOld but are set in
1279 // the new one and set the ones which were not set before
1280 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1281 styleReal
&= ~styleOld
;
1284 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1286 // we need to call SetWindowPos() if any of the styles affecting the
1287 // frame appearance have changed
1288 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1297 // and the extended style
1298 long exstyleReal
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1300 if ( exstyle
!= exstyleOld
)
1302 exstyleReal
&= ~exstyleOld
;
1303 exstyleReal
|= exstyle
;
1305 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyleReal
);
1307 // ex style changes don't take effect without calling SetWindowPos
1313 // we must call SetWindowPos() to flush the cached extended style and
1314 // also to make the change to wxSTAY_ON_TOP style take effect: just
1315 // setting the style simply doesn't work
1316 if ( !::SetWindowPos(GetHwnd(),
1317 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1320 SWP_NOMOVE
| SWP_NOSIZE
| SWP_FRAMECHANGED
) )
1322 wxLogLastError(_T("SetWindowPos"));
1327 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1329 // translate common wxWidgets styles to Windows ones
1331 // most of windows are child ones, those which are not (such as
1332 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1333 WXDWORD style
= WS_CHILD
;
1335 // using this flag results in very significant reduction in flicker,
1336 // especially with controls inside the static boxes (as the interior of the
1337 // box is not redrawn twice), but sometimes results in redraw problems, so
1338 // optionally allow the old code to continue to use it provided a special
1339 // system option is turned on
1340 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1341 || (flags
& wxCLIP_CHILDREN
) )
1342 style
|= WS_CLIPCHILDREN
;
1344 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1345 // don't support overlapping windows and it only makes sense for them and,
1346 // presumably, gives the system some extra work (to manage more clipping
1347 // regions), so avoid it alltogether
1350 if ( flags
& wxVSCROLL
)
1351 style
|= WS_VSCROLL
;
1353 if ( flags
& wxHSCROLL
)
1354 style
|= WS_HSCROLL
;
1356 const wxBorder border
= GetBorder(flags
);
1358 // WS_BORDER is only required for wxBORDER_SIMPLE
1359 if ( border
== wxBORDER_SIMPLE
)
1362 // now deal with ext style if the caller wants it
1368 if ( flags
& wxTRANSPARENT_WINDOW
)
1369 *exstyle
|= WS_EX_TRANSPARENT
;
1375 case wxBORDER_DEFAULT
:
1376 wxFAIL_MSG( _T("unknown border style") );
1380 case wxBORDER_SIMPLE
:
1383 case wxBORDER_STATIC
:
1384 *exstyle
|= WS_EX_STATICEDGE
;
1387 case wxBORDER_RAISED
:
1388 *exstyle
|= WS_EX_DLGMODALFRAME
;
1391 case wxBORDER_SUNKEN
:
1392 *exstyle
|= WS_EX_CLIENTEDGE
;
1393 style
&= ~WS_BORDER
;
1396 case wxBORDER_DOUBLE
:
1397 *exstyle
|= WS_EX_DLGMODALFRAME
;
1401 // wxUniv doesn't use Windows dialog navigation functions at all
1402 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1403 // to make the dialog navigation work with the nested panels we must
1404 // use this style (top level windows such as dialogs don't need it)
1405 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1407 *exstyle
|= WS_EX_CONTROLPARENT
;
1409 #endif // __WXUNIVERSAL__
1415 // Setup background and foreground colours correctly
1416 void wxWindowMSW::SetupColours()
1419 SetBackgroundColour(GetParent()->GetBackgroundColour());
1422 bool wxWindowMSW::IsMouseInWindow() const
1424 // get the mouse position
1427 ::GetCursorPosWinCE(&pt
);
1429 ::GetCursorPos(&pt
);
1432 // find the window which currently has the cursor and go up the window
1433 // chain until we find this window - or exhaust it
1434 HWND hwnd
= ::WindowFromPoint(pt
);
1435 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1436 hwnd
= ::GetParent(hwnd
);
1438 return hwnd
!= NULL
;
1441 void wxWindowMSW::OnInternalIdle()
1443 #ifndef HAVE_TRACKMOUSEEVENT
1444 // Check if we need to send a LEAVE event
1445 if ( m_mouseInWindow
)
1447 // note that we should generate the leave event whether the window has
1448 // or doesn't have mouse capture
1449 if ( !IsMouseInWindow() )
1451 GenerateMouseLeave();
1454 #endif // !HAVE_TRACKMOUSEEVENT
1456 if (wxUpdateUIEvent::CanUpdate(this))
1457 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1460 // Set this window to be the child of 'parent'.
1461 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1463 if ( !wxWindowBase::Reparent(parent
) )
1466 HWND hWndChild
= GetHwnd();
1467 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1469 ::SetParent(hWndChild
, hWndParent
);
1472 if ( ::GetWindowLong(hWndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1474 EnsureParentHasControlParentStyle(GetParent());
1476 #endif // !__WXWINCE__
1481 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1483 #ifndef __WXMICROWIN__
1484 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1488 void wxWindowMSW::Freeze()
1490 if ( !m_frozenness
++ )
1493 SendSetRedraw(GetHwnd(), false);
1497 void wxWindowMSW::Thaw()
1499 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1501 if ( --m_frozenness
== 0 )
1505 SendSetRedraw(GetHwnd(), true);
1507 // we need to refresh everything or otherwise the invalidated area
1508 // is not going to be repainted
1514 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1516 HWND hWnd
= GetHwnd();
1523 mswRect
.left
= rect
->x
;
1524 mswRect
.top
= rect
->y
;
1525 mswRect
.right
= rect
->x
+ rect
->width
;
1526 mswRect
.bottom
= rect
->y
+ rect
->height
;
1535 // RedrawWindow not available on SmartPhone or eVC++ 3
1536 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1537 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1541 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1543 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1548 void wxWindowMSW::Update()
1550 if ( !::UpdateWindow(GetHwnd()) )
1552 wxLogLastError(_T("UpdateWindow"));
1555 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1556 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1557 // handler needs to be really drawn right now
1562 // ---------------------------------------------------------------------------
1564 // ---------------------------------------------------------------------------
1566 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1570 // we need to lower the sibling static boxes so controls contained within can be
1572 static void AdjustStaticBoxZOrder(wxWindow
*parent
)
1574 // no sibling static boxes if we have no parent (ie TLW)
1578 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1580 node
= node
->GetNext() )
1582 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1585 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1586 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1591 #else // !wxUSE_STATBOX
1593 static inline void AdjustStaticBoxZOrder(wxWindow
* WXUNUSED(parent
))
1597 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1599 #endif // drag and drop is used
1601 #if wxUSE_DRAG_AND_DROP
1602 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1604 if ( m_dropTarget
!= 0 ) {
1605 m_dropTarget
->Revoke(m_hWnd
);
1606 delete m_dropTarget
;
1609 m_dropTarget
= pDropTarget
;
1610 if ( m_dropTarget
!= 0 )
1612 AdjustStaticBoxZOrder(GetParent());
1613 m_dropTarget
->Register(m_hWnd
);
1616 #endif // wxUSE_DRAG_AND_DROP
1618 // old-style file manager drag&drop support: we retain the old-style
1619 // DragAcceptFiles in parallel with SetDropTarget.
1620 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1623 HWND hWnd
= GetHwnd();
1626 AdjustStaticBoxZOrder(GetParent());
1627 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1632 // ----------------------------------------------------------------------------
1634 // ----------------------------------------------------------------------------
1638 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1640 wxWindowBase::DoSetToolTip(tooltip
);
1643 m_tooltip
->SetWindow((wxWindow
*)this);
1646 #endif // wxUSE_TOOLTIPS
1648 // ---------------------------------------------------------------------------
1649 // moving and resizing
1650 // ---------------------------------------------------------------------------
1652 bool wxWindowMSW::IsSizeDeferred() const
1654 #if USE_DEFERRED_SIZING
1655 if ( m_pendingPosition
!= wxDefaultPosition
||
1656 m_pendingSize
!= wxDefaultSize
)
1658 #endif // USE_DEFERRED_SIZING
1664 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1666 #if USE_DEFERRED_SIZING
1667 // if SetSize() had been called at wx level but not realized at Windows
1668 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1669 // the new and not the old position to the other wx code
1670 if ( m_pendingSize
!= wxDefaultSize
)
1673 *x
= m_pendingSize
.x
;
1675 *y
= m_pendingSize
.y
;
1677 else // use current size
1678 #endif // USE_DEFERRED_SIZING
1680 RECT rect
= wxGetWindowRect(GetHwnd());
1683 *x
= rect
.right
- rect
.left
;
1685 *y
= rect
.bottom
- rect
.top
;
1689 // Get size *available for subwindows* i.e. excluding menu bar etc.
1690 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1692 #if USE_DEFERRED_SIZING
1693 if ( m_pendingSize
!= wxDefaultSize
)
1695 // we need to calculate the client size corresponding to pending size
1697 rect
.left
= m_pendingPosition
.x
;
1698 rect
.top
= m_pendingPosition
.y
;
1699 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1700 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1702 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1705 *x
= rect
.right
- rect
.left
;
1707 *y
= rect
.bottom
- rect
.top
;
1710 #endif // USE_DEFERRED_SIZING
1712 RECT rect
= wxGetClientRect(GetHwnd());
1721 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1723 wxWindow
* const parent
= GetParent();
1726 if ( m_pendingPosition
!= wxDefaultPosition
)
1728 pos
= m_pendingPosition
;
1730 else // use current position
1732 RECT rect
= wxGetWindowRect(GetHwnd());
1735 point
.x
= rect
.left
;
1738 // we do the adjustments with respect to the parent only for the "real"
1739 // children, not for the dialogs/frames
1740 if ( !IsTopLevel() )
1742 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
1744 // In RTL mode, we want the logical left x-coordinate,
1745 // which would be the physical right x-coordinate.
1746 point
.x
= rect
.right
;
1749 // Since we now have the absolute screen coords, if there's a
1750 // parent we must subtract its top left corner
1753 ::ScreenToClient(GetHwndOf(parent
), &point
);
1761 // we also must adjust by the client area offset: a control which is just
1762 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1763 if ( parent
&& !IsTopLevel() )
1765 const wxPoint
pt(parent
->GetClientAreaOrigin());
1776 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1784 ::ScreenToClient(GetHwnd(), &pt
);
1792 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1800 ::ClientToScreen(GetHwnd(), &pt
);
1809 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1811 #if USE_DEFERRED_SIZING
1812 // if our parent had prepared a defer window handle for us, use it (unless
1813 // we are a top level window)
1814 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1816 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1819 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1820 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1823 wxLogLastError(_T("DeferWindowPos"));
1829 // hdwp must be updated as it may have been changed
1830 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1835 // did deferred move, remember new coordinates of the window as they're
1836 // different from what Windows would return for it
1840 // otherwise (or if deferring failed) move the window in place immediately
1841 #endif // USE_DEFERRED_SIZING
1842 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
1844 wxLogLastError(wxT("MoveWindow"));
1847 // if USE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1848 // ignored otherwise
1852 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1854 // TODO: is this consistent with other platforms?
1855 // Still, negative width or height shouldn't be allowed
1861 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
1863 #if USE_DEFERRED_SIZING
1864 m_pendingPosition
= wxPoint(x
, y
);
1865 m_pendingSize
= wxSize(width
, height
);
1866 #endif // USE_DEFERRED_SIZING
1870 // set the size of the window: if the dimensions are positive, just use them,
1871 // but if any of them is equal to -1, it means that we must find the value for
1872 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1873 // which case -1 is a valid value for x and y)
1875 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1876 // the width/height to best suit our contents, otherwise we reuse the current
1878 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1880 // get the current size and position...
1881 int currentX
, currentY
;
1882 int currentW
, currentH
;
1884 GetPosition(¤tX
, ¤tY
);
1885 GetSize(¤tW
, ¤tH
);
1887 // ... and don't do anything (avoiding flicker) if it's already ok unless
1888 // we're forced to resize the window
1889 if ( x
== currentX
&& y
== currentY
&&
1890 width
== currentW
&& height
== currentH
&&
1891 !(sizeFlags
& wxSIZE_FORCE
) )
1896 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1898 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1901 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1903 wxSize size
= wxDefaultSize
;
1904 if ( width
== wxDefaultCoord
)
1906 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1908 size
= DoGetBestSize();
1913 // just take the current one
1918 if ( height
== wxDefaultCoord
)
1920 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1922 if ( size
.x
== wxDefaultCoord
)
1924 size
= DoGetBestSize();
1926 //else: already called DoGetBestSize() above
1932 // just take the current one
1937 DoMoveWindow(x
, y
, width
, height
);
1940 void wxWindowMSW::DoSetClientSize(int width
, int height
)
1942 // setting the client size is less obvious than it could have been
1943 // because in the result of changing the total size the window scrollbar
1944 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
1945 // doesn't take neither into account) and so the client size will not be
1946 // correct as the difference between the total and client size changes --
1947 // so we keep changing it until we get it right
1949 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1950 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1951 // may become 3 if the window had 0 size originally and so we didn't
1952 // calculate the scrollbar correction correctly during the first iteration)
1953 // but just to be on the safe side we check for it instead of making it an
1954 // "infinite" loop (i.e. leaving break inside as the only way to get out)
1955 for ( int i
= 0; i
< 4; i
++ )
1958 ::GetClientRect(GetHwnd(), &rectClient
);
1960 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
1961 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
1962 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
1967 // Find the difference between the entire window (title bar and all)
1968 // and the client area; add this to the new client size to move the
1971 ::GetWindowRect(GetHwnd(), &rectWin
);
1973 const int widthWin
= rectWin
.right
- rectWin
.left
,
1974 heightWin
= rectWin
.bottom
- rectWin
.top
;
1976 // MoveWindow positions the child windows relative to the parent, so
1977 // adjust if necessary
1978 if ( !IsTopLevel() )
1980 wxWindow
*parent
= GetParent();
1983 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
1987 // don't call DoMoveWindow() because we want to move window immediately
1988 // and not defer it here as otherwise the value returned by
1989 // GetClient/WindowRect() wouldn't change as the window wouldn't be
1991 if ( !::MoveWindow(GetHwnd(),
1994 width
+ widthWin
- rectClient
.right
,
1995 height
+ heightWin
- rectClient
.bottom
,
1998 wxLogLastError(_T("MoveWindow"));
2003 // ---------------------------------------------------------------------------
2005 // ---------------------------------------------------------------------------
2007 int wxWindowMSW::GetCharHeight() const
2009 return wxGetTextMetrics(this).tmHeight
;
2012 int wxWindowMSW::GetCharWidth() const
2014 // +1 is needed because Windows apparently adds it when calculating the
2015 // dialog units size in pixels
2016 #if wxDIALOG_UNIT_COMPATIBILITY
2017 return wxGetTextMetrics(this).tmAveCharWidth
;
2019 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
2023 void wxWindowMSW::GetTextExtent(const wxString
& string
,
2025 int *descent
, int *externalLeading
,
2026 const wxFont
*theFont
) const
2028 wxASSERT_MSG( !theFont
|| theFont
->Ok(),
2029 _T("invalid font in GetTextExtent()") );
2033 fontToUse
= *theFont
;
2035 fontToUse
= GetFont();
2037 WindowHDC
hdc(GetHwnd());
2038 SelectInHDC
selectFont(hdc
, GetHfontOf(fontToUse
));
2042 ::GetTextExtentPoint32(hdc
, string
, string
.length(), &sizeRect
);
2043 GetTextMetrics(hdc
, &tm
);
2050 *descent
= tm
.tmDescent
;
2051 if ( externalLeading
)
2052 *externalLeading
= tm
.tmExternalLeading
;
2055 // ---------------------------------------------------------------------------
2057 // ---------------------------------------------------------------------------
2059 #if wxUSE_MENUS_NATIVE
2061 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2062 // immediately, without waiting for the next event loop iteration
2064 // NB: this function should probably be made public later as it can almost
2065 // surely replace wxYield() elsewhere as well
2066 static void wxYieldForCommandsOnly()
2068 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2069 // want to process it here)
2071 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2073 if ( msg
.message
== WM_QUIT
)
2075 // if we retrieved a WM_QUIT, insert back into the message queue.
2076 ::PostQuitMessage(0);
2080 // luckily (as we don't have access to wxEventLoopImpl method from here
2081 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2083 ::TranslateMessage(&msg
);
2084 ::DispatchMessage(&msg
);
2088 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2090 menu
->SetInvokingWindow(this);
2093 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2095 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2096 x
= mouse
.x
; y
= mouse
.y
;
2099 HWND hWnd
= GetHwnd();
2100 HMENU hMenu
= GetHmenuOf(menu
);
2104 ::ClientToScreen(hWnd
, &point
);
2105 wxCurrentPopupMenu
= menu
;
2106 #if defined(__WXWINCE__)
2109 UINT flags
= TPM_RIGHTBUTTON
| TPM_RECURSE
;
2111 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2113 // we need to do it right now as otherwise the events are never going to be
2114 // sent to wxCurrentPopupMenu from HandleCommand()
2116 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2117 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2118 // destroyed as soon as we return (it can be a local variable in the caller
2119 // for example) and so we do need to process the event immediately
2120 wxYieldForCommandsOnly();
2122 wxCurrentPopupMenu
= NULL
;
2124 menu
->SetInvokingWindow(NULL
);
2129 #endif // wxUSE_MENUS_NATIVE
2131 // ===========================================================================
2132 // pre/post message processing
2133 // ===========================================================================
2135 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2138 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2140 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2143 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2145 // wxUniversal implements tab traversal itself
2146 #ifndef __WXUNIVERSAL__
2147 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2149 // intercept dialog navigation keys
2150 MSG
*msg
= (MSG
*)pMsg
;
2152 // here we try to do all the job which ::IsDialogMessage() usually does
2154 if ( msg
->message
== WM_KEYDOWN
)
2156 bool bCtrlDown
= wxIsCtrlDown();
2157 bool bShiftDown
= wxIsShiftDown();
2159 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2160 // don't process it if it's the case (except for Ctrl-Tab/Enter
2161 // combinations which are always processed)
2162 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2164 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2165 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2166 // it, of course, implies them
2167 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2169 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2172 bool bForward
= true,
2173 bWindowChange
= false,
2176 // should we process this message specially?
2177 bool bProcess
= true;
2178 switch ( msg
->wParam
)
2181 if ( (lDlgCode
& DLGC_WANTTAB
) && !bCtrlDown
)
2183 // let the control have the TAB
2186 else // use it for navigation
2188 // Ctrl-Tab cycles thru notebook pages
2189 bWindowChange
= bCtrlDown
;
2190 bForward
= !bShiftDown
;
2197 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2205 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2214 // we treat PageUp/Dn as arrows because chances are that
2215 // a control which needs arrows also needs them for
2216 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2217 if ( (lDlgCode
& DLGC_WANTARROWS
) && !bCtrlDown
)
2219 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
2220 bWindowChange
= true;
2225 if ( (lDlgCode
& DLGC_WANTMESSAGE
) && !bCtrlDown
)
2227 // control wants to process Enter itself, don't
2228 // call IsDialogMessage() which would consume it
2233 // currently active button should get enter press even
2234 // if there is a default button elsewhere so check if
2235 // this window is a button first
2236 wxWindow
*btn
= NULL
;
2237 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2239 // let IsDialogMessage() handle this for all
2240 // buttons except the owner-drawn ones which it
2241 // just seems to ignore
2242 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2243 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2245 // emulate the button click
2246 btn
= wxFindWinFromHandle((WXHWND
)msg
->hwnd
);
2251 else // not a button itself, do we have default button?
2254 tlw
= wxDynamicCast(wxGetTopLevelParent(this),
2258 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2263 if ( btn
&& btn
->IsEnabled() )
2265 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2269 #endif // wxUSE_BUTTON
2272 // map Enter presses into button presses on PDAs
2273 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2274 event
.SetEventObject(this);
2275 if ( GetEventHandler()->ProcessEvent(event
) )
2277 #endif // __WXWINCE__
2287 wxNavigationKeyEvent event
;
2288 event
.SetDirection(bForward
);
2289 event
.SetWindowChange(bWindowChange
);
2290 event
.SetFromTab(bFromTab
);
2291 event
.SetEventObject(this);
2293 if ( GetEventHandler()->ProcessEvent(event
) )
2295 // as we don't call IsDialogMessage(), which would take of
2296 // this by default, we need to manually send this message
2297 // so that controls can change their UI state if needed
2298 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2305 if ( ::IsDialogMessage(GetHwnd(), msg
) )
2307 // IsDialogMessage() did something...
2311 #endif // __WXUNIVERSAL__
2316 // relay mouse move events to the tooltip control
2317 MSG
*msg
= (MSG
*)pMsg
;
2318 if ( msg
->message
== WM_MOUSEMOVE
)
2319 wxToolTip::RelayEvent(pMsg
);
2321 #endif // wxUSE_TOOLTIPS
2326 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2328 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2329 return m_acceleratorTable
.Translate(this, pMsg
);
2333 #endif // wxUSE_ACCEL
2336 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* msg
)
2338 // all tests below have to deal with various bugs/misfeatures of
2339 // IsDialogMessage(): we have to prevent it from being called from our
2340 // MSWProcessMessage() in some situations
2342 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2343 // message even when there is no cancel button and when the message is
2344 // needed by the control itself: in particular, it prevents the tree in
2345 // place edit control from being closed with Escape in a dialog
2346 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_ESCAPE
)
2351 // ::IsDialogMessage() is broken and may sometimes hang the application by
2352 // going into an infinite loop when it tries to find the control to give
2353 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2354 // situations when this may happen and not call it then
2355 if ( msg
->message
!= WM_SYSCHAR
)
2358 // assume we can call it by default
2359 bool canSafelyCallIsDlgMsg
= true;
2361 HWND hwndFocus
= ::GetFocus();
2363 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2364 // ::IsDialogMessage() will also enter an infinite loop, because it will
2365 // recursively check the child windows but not the window itself and so if
2366 // none of the children accepts focus it loops forever (as it only stops
2367 // when it gets back to the window it started from)
2369 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2370 // style has the focus, it can happen. One such possibility is if
2371 // all windows are either toplevel, wxDialog, wxPanel or static
2372 // controls and no window can actually accept keyboard input.
2373 #if !defined(__WXWINCE__)
2374 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2376 // pessimistic by default
2377 canSafelyCallIsDlgMsg
= false;
2378 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2380 node
= node
->GetNext() )
2382 wxWindow
* const win
= node
->GetData();
2383 if ( win
->AcceptsFocus() &&
2384 !(::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
) &
2385 WS_EX_CONTROLPARENT
) )
2387 // it shouldn't hang...
2388 canSafelyCallIsDlgMsg
= true;
2394 #endif // !__WXWINCE__
2396 if ( canSafelyCallIsDlgMsg
)
2398 // ::IsDialogMessage() can enter in an infinite loop when the
2399 // currently focused window is disabled or hidden and its
2400 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2404 if ( !::IsWindowEnabled(hwndFocus
) ||
2405 !::IsWindowVisible(hwndFocus
) )
2407 // it would enter an infinite loop if we do this!
2408 canSafelyCallIsDlgMsg
= false;
2413 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2415 // it's a top level window, don't go further -- e.g. even
2416 // if the parent of a dialog is disabled, this doesn't
2417 // break navigation inside the dialog
2421 hwndFocus
= ::GetParent(hwndFocus
);
2425 return canSafelyCallIsDlgMsg
;
2428 // ---------------------------------------------------------------------------
2429 // message params unpackers
2430 // ---------------------------------------------------------------------------
2432 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2433 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2435 *id
= LOWORD(wParam
);
2436 *hwnd
= (WXHWND
)lParam
;
2437 *cmd
= HIWORD(wParam
);
2440 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2441 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2443 *state
= LOWORD(wParam
);
2444 *minimized
= HIWORD(wParam
);
2445 *hwnd
= (WXHWND
)lParam
;
2448 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2449 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2451 *code
= LOWORD(wParam
);
2452 *pos
= HIWORD(wParam
);
2453 *hwnd
= (WXHWND
)lParam
;
2456 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2457 WXHDC
*hdc
, WXHWND
*hwnd
)
2459 *hwnd
= (WXHWND
)lParam
;
2460 *hdc
= (WXHDC
)wParam
;
2463 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2464 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2466 *item
= (WXWORD
)wParam
;
2467 *flags
= HIWORD(wParam
);
2468 *hmenu
= (WXHMENU
)lParam
;
2471 // ---------------------------------------------------------------------------
2472 // Main wxWidgets window proc and the window proc for wxWindow
2473 // ---------------------------------------------------------------------------
2475 // Hook for new window just as it's being created, when the window isn't yet
2476 // associated with the handle
2477 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2479 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2480 // window being created and insures that it's always unset back later
2481 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2483 gs_winBeingCreated
= winBeingCreated
;
2486 wxWindowCreationHook::~wxWindowCreationHook()
2488 gs_winBeingCreated
= NULL
;
2492 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2494 // trace all messages - useful for the debugging
2496 wxLogTrace(wxTraceMessages
,
2497 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2498 wxGetMessageName(message
), (long)hWnd
, (long)wParam
, lParam
);
2499 #endif // __WXDEBUG__
2501 wxWindowMSW
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
2503 // when we get the first message for the HWND we just created, we associate
2504 // it with wxWindow stored in gs_winBeingCreated
2505 if ( !wnd
&& gs_winBeingCreated
)
2507 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2508 wnd
= gs_winBeingCreated
;
2509 gs_winBeingCreated
= NULL
;
2510 wnd
->SetHWND((WXHWND
)hWnd
);
2515 if ( wnd
&& wxEventLoop::AllowProcessing(wnd
) )
2516 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2518 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2523 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2525 // did we process the message?
2526 bool processed
= false;
2536 // for most messages we should return 0 when we do process the message
2544 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2547 // return 0 to allow window creation
2548 rc
.result
= mayCreate
? 0 : -1;
2554 // never set processed to true and *always* pass WM_DESTROY to
2555 // DefWindowProc() as Windows may do some internal cleanup when
2556 // processing it and failing to pass the message along may cause
2557 // memory and resource leaks!
2558 (void)HandleDestroy();
2562 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2566 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2569 #if !defined(__WXWINCE__)
2572 LPRECT pRect
= (LPRECT
)lParam
;
2574 rc
.SetLeft(pRect
->left
);
2575 rc
.SetTop(pRect
->top
);
2576 rc
.SetRight(pRect
->right
);
2577 rc
.SetBottom(pRect
->bottom
);
2578 processed
= HandleMoving(rc
);
2580 pRect
->left
= rc
.GetLeft();
2581 pRect
->top
= rc
.GetTop();
2582 pRect
->right
= rc
.GetRight();
2583 pRect
->bottom
= rc
.GetBottom();
2590 LPRECT pRect
= (LPRECT
)lParam
;
2592 rc
.SetLeft(pRect
->left
);
2593 rc
.SetTop(pRect
->top
);
2594 rc
.SetRight(pRect
->right
);
2595 rc
.SetBottom(pRect
->bottom
);
2596 processed
= HandleSizing(rc
);
2598 pRect
->left
= rc
.GetLeft();
2599 pRect
->top
= rc
.GetTop();
2600 pRect
->right
= rc
.GetRight();
2601 pRect
->bottom
= rc
.GetBottom();
2605 #endif // !__WXWINCE__
2607 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2608 case WM_ACTIVATEAPP
:
2609 // This implicitly sends a wxEVT_ACTIVATE_APP event
2610 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2616 WXWORD state
, minimized
;
2618 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2620 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2625 processed
= HandleSetFocus((WXHWND
)(HWND
)wParam
);
2629 processed
= HandleKillFocus((WXHWND
)(HWND
)wParam
);
2632 case WM_PRINTCLIENT
:
2633 processed
= HandlePrintClient((WXHDC
)wParam
);
2639 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2641 processed
= HandlePaint();
2645 processed
= HandlePaint();
2650 #ifdef __WXUNIVERSAL__
2651 // Universal uses its own wxFrame/wxDialog, so we don't receive
2652 // close events unless we have this.
2654 #endif // __WXUNIVERSAL__
2656 // don't let the DefWindowProc() destroy our window - we'll do it
2657 // ourselves in ~wxWindow
2663 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2667 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2668 GET_Y_LPARAM(lParam
),
2672 #ifdef HAVE_TRACKMOUSEEVENT
2674 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2676 if ( m_mouseInWindow
)
2678 GenerateMouseLeave();
2681 // always pass processed back as false, this allows the window
2682 // manager to process the message too. This is needed to
2683 // ensure windows XP themes work properly as the mouse moves
2684 // over widgets like buttons. So don't set processed to true here.
2686 #endif // HAVE_TRACKMOUSEEVENT
2688 #if wxUSE_MOUSEWHEEL
2690 processed
= HandleMouseWheel(wParam
, lParam
);
2694 case WM_LBUTTONDOWN
:
2696 case WM_LBUTTONDBLCLK
:
2697 case WM_RBUTTONDOWN
:
2699 case WM_RBUTTONDBLCLK
:
2700 case WM_MBUTTONDOWN
:
2702 case WM_MBUTTONDBLCLK
:
2704 #ifdef __WXMICROWIN__
2705 // MicroWindows seems to ignore the fact that a window is
2706 // disabled. So catch mouse events and throw them away if
2708 wxWindowMSW
* win
= this;
2711 if (!win
->IsEnabled())
2717 win
= win
->GetParent();
2718 if ( !win
|| win
->IsTopLevel() )
2725 #endif // __WXMICROWIN__
2726 int x
= GET_X_LPARAM(lParam
),
2727 y
= GET_Y_LPARAM(lParam
);
2730 // redirect the event to a static control if necessary by
2731 // finding one under mouse because under CE the static controls
2732 // don't generate mouse events (even with SS_NOTIFY)
2734 if ( GetCapture() == this )
2736 // but don't do it if the mouse is captured by this window
2737 // because then it should really get this event itself
2742 win
= FindWindowForMouseEvent(this, &x
, &y
);
2744 // this should never happen
2745 wxCHECK_MSG( win
, 0,
2746 _T("FindWindowForMouseEvent() returned NULL") );
2749 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
2751 SHRGINFO shrgi
= {0};
2753 shrgi
.cbSize
= sizeof(SHRGINFO
);
2754 shrgi
.hwndClient
= (HWND
) GetHWND();
2758 shrgi
.dwFlags
= SHRG_RETURNCMD
;
2759 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
2761 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
2764 pt
= ClientToScreen(pt
);
2766 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2768 evtCtx
.SetEventObject(this);
2769 if (GetEventHandler()->ProcessEvent(evtCtx
))
2778 #else // !__WXWINCE__
2779 wxWindowMSW
*win
= this;
2780 #endif // __WXWINCE__/!__WXWINCE__
2782 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2784 // if the app didn't eat the event, handle it in the default
2785 // way, that is by giving this window the focus
2788 // for the standard classes their WndProc sets the focus to
2789 // them anyhow and doing it from here results in some weird
2790 // problems, so don't do it for them (unnecessary anyhow)
2791 if ( !win
->IsOfStandardClass() )
2793 if ( message
== WM_LBUTTONDOWN
&& win
->AcceptsFocus() )
2805 case MM_JOY1BUTTONDOWN
:
2806 case MM_JOY2BUTTONDOWN
:
2807 case MM_JOY1BUTTONUP
:
2808 case MM_JOY2BUTTONUP
:
2809 processed
= HandleJoystickEvent(message
,
2810 GET_X_LPARAM(lParam
),
2811 GET_Y_LPARAM(lParam
),
2814 #endif // __WXMICROWIN__
2820 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2822 processed
= HandleCommand(id
, cmd
, hwnd
);
2827 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2830 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
2831 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
2832 // apparently doesn't always behave properly and needs some help
2833 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
2834 case WM_NOTIFYFORMAT
:
2835 if ( lParam
== NF_QUERY
)
2838 rc
.result
= NFR_UNICODE
;
2841 #endif // wxUSE_UNICODE_MSLU
2843 // for these messages we must return true if process the message
2846 case WM_MEASUREITEM
:
2848 int idCtrl
= (UINT
)wParam
;
2849 if ( message
== WM_DRAWITEM
)
2851 processed
= MSWOnDrawItem(idCtrl
,
2852 (WXDRAWITEMSTRUCT
*)lParam
);
2856 processed
= MSWOnMeasureItem(idCtrl
,
2857 (WXMEASUREITEMSTRUCT
*)lParam
);
2864 #endif // defined(WM_DRAWITEM)
2867 if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS
) )
2869 // we always want to get the char events
2870 rc
.result
= DLGC_WANTCHARS
;
2872 if ( HasFlag(wxWANTS_CHARS
) )
2874 // in fact, we want everything
2875 rc
.result
|= DLGC_WANTARROWS
|
2882 //else: get the dlg code from the DefWindowProc()
2887 // If this has been processed by an event handler, return 0 now
2888 // (we've handled it).
2889 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
2890 if ( m_lastKeydownProcessed
)
2899 // we consider these messages "not interesting" to OnChar, so
2900 // just don't do anything more with them
2910 // avoid duplicate messages to OnChar for these ASCII keys:
2911 // they will be translated by TranslateMessage() and received
2943 // but set processed to false, not true to still pass them
2944 // to the control's default window proc - otherwise
2945 // built-in keyboard handling won't work
2950 // special case of VK_APPS: treat it the same as right mouse
2951 // click because both usually pop up a context menu
2953 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
2958 // do generate a CHAR event
2959 processed
= HandleChar((WORD
)wParam
, lParam
);
2962 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
2969 // special case of VK_APPS: treat it the same as right mouse button
2970 if ( wParam
== VK_APPS
)
2972 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
2977 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
2982 case WM_CHAR
: // Always an ASCII character
2983 if ( m_lastKeydownProcessed
)
2985 // The key was handled in the EVT_KEY_DOWN and handling
2986 // a key in an EVT_KEY_DOWN handler is meant, by
2987 // design, to prevent EVT_CHARs from happening
2988 m_lastKeydownProcessed
= false;
2993 processed
= HandleChar((WORD
)wParam
, lParam
, true);
2999 processed
= HandleHotKey((WORD
)wParam
, lParam
);
3001 #endif // wxUSE_HOTKEY
3008 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
3010 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
3016 // CTLCOLOR messages are sent by children to query the parent for their
3018 #ifndef __WXMICROWIN__
3019 case WM_CTLCOLORMSGBOX
:
3020 case WM_CTLCOLOREDIT
:
3021 case WM_CTLCOLORLISTBOX
:
3022 case WM_CTLCOLORBTN
:
3023 case WM_CTLCOLORDLG
:
3024 case WM_CTLCOLORSCROLLBAR
:
3025 case WM_CTLCOLORSTATIC
:
3029 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
3031 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
3034 #endif // !__WXMICROWIN__
3036 case WM_SYSCOLORCHANGE
:
3037 // the return value for this message is ignored
3038 processed
= HandleSysColorChange();
3041 #if !defined(__WXWINCE__)
3042 case WM_DISPLAYCHANGE
:
3043 processed
= HandleDisplayChange();
3047 case WM_PALETTECHANGED
:
3048 processed
= HandlePaletteChanged((WXHWND
) (HWND
) wParam
);
3051 case WM_CAPTURECHANGED
:
3052 processed
= HandleCaptureChanged((WXHWND
) (HWND
) lParam
);
3055 case WM_SETTINGCHANGE
:
3056 processed
= HandleSettingChange(wParam
, lParam
);
3059 case WM_QUERYNEWPALETTE
:
3060 processed
= HandleQueryNewPalette();
3064 processed
= HandleEraseBkgnd((WXHDC
)(HDC
)wParam
);
3067 // we processed the message, i.e. erased the background
3072 #if !defined(__WXWINCE__)
3074 processed
= HandleDropFiles(wParam
);
3079 processed
= HandleInitDialog((WXHWND
)(HWND
)wParam
);
3083 // we never set focus from here
3088 #if !defined(__WXWINCE__)
3089 case WM_QUERYENDSESSION
:
3090 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3094 processed
= HandleEndSession(wParam
!= 0, lParam
);
3097 case WM_GETMINMAXINFO
:
3098 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3103 processed
= HandleSetCursor((WXHWND
)(HWND
)wParam
,
3104 LOWORD(lParam
), // hit test
3105 HIWORD(lParam
)); // mouse msg
3109 // returning TRUE stops the DefWindowProc() from further
3110 // processing this message - exactly what we need because we've
3111 // just set the cursor.
3116 #if wxUSE_ACCESSIBILITY
3119 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3120 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3122 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3124 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3130 #if defined(WM_HELP)
3133 // by default, WM_HELP is propagated by DefWindowProc() upwards
3134 // to the window parent but as we do it ourselves already
3135 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3136 // to get the other events if we process this message at all
3139 // WM_HELP doesn't use lParam under CE
3141 HELPINFO
* info
= (HELPINFO
*) lParam
;
3142 if ( info
->iContextType
== HELPINFO_WINDOW
)
3144 #endif // !__WXWINCE__
3145 wxHelpEvent helpEvent
3150 wxGetMousePosition() // what else?
3152 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3156 helpEvent
.SetEventObject(this);
3157 GetEventHandler()->ProcessEvent(helpEvent
);
3160 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3162 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3163 helpEvent
.SetEventObject(this);
3164 GetEventHandler()->ProcessEvent(helpEvent
);
3167 else // unknown help event?
3171 #endif // !__WXWINCE__
3176 #if !defined(__WXWINCE__)
3177 case WM_CONTEXTMENU
:
3179 // we don't convert from screen to client coordinates as
3180 // the event may be handled by a parent window
3181 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3183 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3185 // we could have got an event from our child, reflect it back
3186 // to it if this is the case
3187 wxWindowMSW
*win
= NULL
;
3188 if ( (WXHWND
)wParam
!= m_hWnd
)
3190 win
= FindItemByHWND((WXHWND
)wParam
);
3196 evtCtx
.SetEventObject(win
);
3197 processed
= win
->GetEventHandler()->ProcessEvent(evtCtx
);
3203 // we're only interested in our own menus, not MF_SYSMENU
3204 if ( HIWORD(wParam
) == MF_POPUP
)
3206 // handle menu chars for ownerdrawn menu items
3207 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3208 if ( i
!= wxNOT_FOUND
)
3210 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3217 case WM_POWERBROADCAST
:
3220 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3221 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3224 #endif // __WXWINCE__
3230 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
3231 wxGetMessageName(message
));
3232 #endif // __WXDEBUG__
3233 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3239 // ----------------------------------------------------------------------------
3240 // wxWindow <-> HWND map
3241 // ----------------------------------------------------------------------------
3243 wxWinHashTable
*wxWinHandleHash
= NULL
;
3245 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
3247 return (wxWindow
*)wxWinHandleHash
->Get((long)hWnd
);
3250 void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
)
3252 // adding NULL hWnd is (first) surely a result of an error and
3253 // (secondly) breaks menu command processing
3254 wxCHECK_RET( hWnd
!= (HWND
)NULL
,
3255 wxT("attempt to add a NULL hWnd to window list ignored") );
3257 wxWindow
*oldWin
= wxFindWinFromHandle((WXHWND
) hWnd
);
3259 if ( oldWin
&& (oldWin
!= win
) )
3261 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
3262 (int) hWnd
, win
->GetClassInfo()->GetClassName());
3265 #endif // __WXDEBUG__
3268 wxWinHandleHash
->Put((long)hWnd
, (wxWindow
*)win
);
3272 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3274 wxWinHandleHash
->Delete((long)win
->GetHWND());
3277 // ----------------------------------------------------------------------------
3278 // various MSW speciic class dependent functions
3279 // ----------------------------------------------------------------------------
3281 // Default destroyer - override if you destroy it in some other way
3282 // (e.g. with MDI child windows)
3283 void wxWindowMSW::MSWDestroyWindow()
3287 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3290 int& w
, int& h
) const
3292 // yes, those are just some arbitrary hardcoded numbers
3293 static const int DEFAULT_Y
= 200;
3295 bool nonDefault
= false;
3297 if ( pos
.x
== wxDefaultCoord
)
3299 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
3300 // can just as well set it to CW_USEDEFAULT as well
3306 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
3307 // neither because it is not handled as a special value by Windows then
3308 // and so we have to choose some default value for it
3310 y
= pos
.y
== wxDefaultCoord
? DEFAULT_Y
: pos
.y
;
3316 NB: there used to be some code here which set the initial size of the
3317 window to the client size of the parent if no explicit size was
3318 specified. This was wrong because wxWidgets programs often assume
3319 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3320 it. To see why, you should understand that Windows sends WM_SIZE from
3321 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3322 from some base class ctor and so this WM_SIZE is not processed in the
3323 real class' OnSize() (because it's not fully constructed yet and the
3324 event goes to some base class OnSize() instead). So the WM_SIZE we
3325 rely on is the one sent when the parent frame resizes its children
3326 but here is the problem: if the child already has just the right
3327 size, nothing will happen as both wxWidgets and Windows check for
3328 this and ignore any attempts to change the window size to the size it
3329 already has - so no WM_SIZE would be sent.
3333 // we don't use CW_USEDEFAULT here for several reasons:
3335 // 1. it results in huge frames on modern screens (1000*800 is not
3336 // uncommon on my 1280*1024 screen) which is way too big for a half
3337 // empty frame of most of wxWidgets samples for example)
3339 // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
3340 // the default is for whatever reason 8*8 which breaks client <->
3341 // window size calculations (it would be nice if it didn't, but it
3342 // does and the simplest way to fix it seemed to change the broken
3343 // default size anyhow)
3345 // 3. there is just no advantage in doing it: with x and y it is
3346 // possible that [future versions of] Windows position the new top
3347 // level window in some smart way which we can't do, but we can
3348 // guess a reasonably good size for a new window just as well
3351 // However, on PocketPC devices, we must use the default
3352 // size if possible.
3354 if (size
.x
== wxDefaultCoord
)
3358 if (size
.y
== wxDefaultCoord
)
3363 if ( size
.x
== wxDefaultCoord
|| size
.y
== wxDefaultCoord
)
3367 w
= WidthDefault(size
.x
);
3368 h
= HeightDefault(size
.y
);
3371 AdjustForParentClientOrigin(x
, y
);
3376 WXHWND
wxWindowMSW::MSWGetParent() const
3378 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3381 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3382 const wxChar
*title
,
3386 WXDWORD extendedStyle
)
3388 // choose the position/size for the new window
3390 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3392 // controlId is menu handle for the top level windows, so set it to 0
3393 // unless we're creating a child window
3394 int controlId
= style
& WS_CHILD
? GetId() : 0;
3396 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3397 // which is the same but without CS_[HV]REDRAW class styles so using it
3398 // ensures that the window is not fully repainted on each resize
3399 wxString
className(wclass
);
3400 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3402 className
+= wxT("NR");
3405 // do create the window
3406 wxWindowCreationHook
hook(this);
3408 m_hWnd
= (WXHWND
)::CreateWindowEx
3412 title
? title
: m_windowName
.c_str(),
3415 (HWND
)MSWGetParent(),
3418 NULL
// no extra data
3423 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3428 SubclassWin(m_hWnd
);
3433 // ===========================================================================
3434 // MSW message handlers
3435 // ===========================================================================
3437 // ---------------------------------------------------------------------------
3439 // ---------------------------------------------------------------------------
3441 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3443 #ifndef __WXMICROWIN__
3444 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3445 HWND hWnd
= hdr
->hwndFrom
;
3446 wxWindow
*win
= wxFindWinFromHandle((WXHWND
)hWnd
);
3448 // if the control is one of our windows, let it handle the message itself
3451 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3454 // VZ: why did we do it? normally this is unnecessary and, besides, it
3455 // breaks the message processing for the toolbars because the tooltip
3456 // notifications were being forwarded to the toolbar child controls
3457 // (if it had any) before being passed to the toolbar itself, so in my
3458 // example the tooltip for the combobox was always shown instead of the
3459 // correct button tooltips
3461 // try all our children
3462 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3465 wxWindow
*child
= node
->GetData();
3466 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3471 node
= node
->GetNext();
3475 // by default, handle it ourselves
3476 return MSWOnNotify(idCtrl
, lParam
, result
);
3477 #else // __WXMICROWIN__
3484 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3486 const wxString
& ttip
)
3488 // I don't know why it happens, but the versions of comctl32.dll starting
3489 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3490 // this message is supposed to be sent to Unicode programs only) -- hence
3491 // we need to handle it as well, otherwise no tooltips will be shown in
3494 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3497 // not a tooltip message or no tooltip to show anyhow
3502 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3504 // We don't want to use the szText buffer because it has a limit of 80
3505 // bytes and this is not enough, especially for Unicode build where it
3506 // limits the tooltip string length to only 40 characters
3508 // The best would be, of course, to not impose any length limitations at
3509 // all but then the buffer would have to be dynamic and someone would have
3510 // to free it and we don't have the tooltip owner object here any more, so
3511 // for now use our own static buffer with a higher fixed max length.
3513 // Note that using a static buffer should not be a problem as only a single
3514 // tooltip can be shown at the same time anyhow.
3516 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3518 // We need to convert tooltip from multi byte to Unicode on the fly.
3519 static wchar_t buf
[513];
3521 // Truncate tooltip length if needed as otherwise we might not have
3522 // enough space for it in the buffer and MultiByteToWideChar() would
3524 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3526 // Convert to WideChar without adding the NULL character. The NULL
3527 // character is added afterwards (this is more efficient).
3528 int len
= ::MultiByteToWideChar
3540 wxLogLastError(_T("MultiByteToWideChar()"));
3544 ttText
->lpszText
= (LPSTR
) buf
;
3546 else // TTN_NEEDTEXTA
3547 #endif // !wxUSE_UNICODE
3549 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3550 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3551 // to copy the string we have into the buffer
3552 static wxChar buf
[513];
3553 wxStrncpy(buf
, ttip
.c_str(), WXSIZEOF(buf
) - 1);
3554 buf
[WXSIZEOF(buf
) - 1] = _T('\0');
3555 ttText
->lpszText
= buf
;
3561 #endif // wxUSE_TOOLTIPS
3563 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3565 WXLPARAM
* WXUNUSED(result
))
3570 NMHDR
* hdr
= (NMHDR
*)lParam
;
3571 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3578 wxUnusedVar(lParam
);
3579 #endif // wxUSE_TOOLTIPS
3584 // ---------------------------------------------------------------------------
3585 // end session messages
3586 // ---------------------------------------------------------------------------
3588 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3590 #ifdef ENDSESSION_LOGOFF
3591 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3592 event
.SetEventObject(wxTheApp
);
3593 event
.SetCanVeto(true);
3594 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3596 bool rc
= wxTheApp
->ProcessEvent(event
);
3600 // we may end only if the app didn't veto session closing (double
3602 *mayEnd
= !event
.GetVeto();
3607 wxUnusedVar(logOff
);
3608 wxUnusedVar(mayEnd
);
3613 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3615 #ifdef ENDSESSION_LOGOFF
3616 // do nothing if the session isn't ending
3621 if ( (this != wxTheApp
->GetTopWindow()) )
3624 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3625 event
.SetEventObject(wxTheApp
);
3626 event
.SetCanVeto(false);
3627 event
.SetLoggingOff( (logOff
== (long)ENDSESSION_LOGOFF
) );
3629 return wxTheApp
->ProcessEvent(event
);
3631 wxUnusedVar(endSession
);
3632 wxUnusedVar(logOff
);
3637 // ---------------------------------------------------------------------------
3638 // window creation/destruction
3639 // ---------------------------------------------------------------------------
3641 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3644 // VZ: why is this commented out for WinCE? If it doesn't support
3645 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3646 // not with multiple #ifdef's!
3648 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3649 EnsureParentHasControlParentStyle(GetParent());
3650 #endif // !__WXWINCE__
3657 bool wxWindowMSW::HandleDestroy()
3661 // delete our drop target if we've got one
3662 #if wxUSE_DRAG_AND_DROP
3663 if ( m_dropTarget
!= NULL
)
3665 m_dropTarget
->Revoke(m_hWnd
);
3667 delete m_dropTarget
;
3668 m_dropTarget
= NULL
;
3670 #endif // wxUSE_DRAG_AND_DROP
3672 // WM_DESTROY handled
3676 // ---------------------------------------------------------------------------
3678 // ---------------------------------------------------------------------------
3680 bool wxWindowMSW::HandleActivate(int state
,
3681 bool WXUNUSED(minimized
),
3682 WXHWND
WXUNUSED(activate
))
3684 wxActivateEvent
event(wxEVT_ACTIVATE
,
3685 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3687 event
.SetEventObject(this);
3689 return GetEventHandler()->ProcessEvent(event
);
3692 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3694 // Strangly enough, some controls get set focus events when they are being
3695 // deleted, even if they already had focus before.
3696 if ( m_isBeingDeleted
)
3701 // notify the parent keeping track of focus for the kbd navigation
3702 // purposes that we got it
3703 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3704 (void)GetEventHandler()->ProcessEvent(eventFocus
);
3710 m_caret
->OnSetFocus();
3712 #endif // wxUSE_CARET
3715 // If it's a wxTextCtrl don't send the event as it will be done
3716 // after the control gets to process it from EN_FOCUS handler
3717 if ( wxDynamicCastThis(wxTextCtrl
) )
3721 #endif // wxUSE_TEXTCTRL
3723 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3724 event
.SetEventObject(this);
3726 // wxFindWinFromHandle() may return NULL, it is ok
3727 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3729 return GetEventHandler()->ProcessEvent(event
);
3732 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
3738 m_caret
->OnKillFocus();
3740 #endif // wxUSE_CARET
3743 // If it's a wxTextCtrl don't send the event as it will be done
3744 // after the control gets to process it.
3745 wxTextCtrl
*ctrl
= wxDynamicCastThis(wxTextCtrl
);
3752 // Don't send the event when in the process of being deleted. This can
3753 // only cause problems if the event handler tries to access the object.
3754 if ( m_isBeingDeleted
)
3759 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3760 event
.SetEventObject(this);
3762 // wxFindWinFromHandle() may return NULL, it is ok
3763 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3765 return GetEventHandler()->ProcessEvent(event
);
3768 // ---------------------------------------------------------------------------
3770 // ---------------------------------------------------------------------------
3772 void wxWindowMSW::SetLabel( const wxString
& label
)
3774 SetWindowText(GetHwnd(), label
.c_str());
3777 wxString
wxWindowMSW::GetLabel() const
3779 return wxGetWindowText(GetHWND());
3782 // ---------------------------------------------------------------------------
3784 // ---------------------------------------------------------------------------
3786 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
3788 wxShowEvent
event(GetId(), show
);
3789 event
.SetEventObject(this);
3791 return GetEventHandler()->ProcessEvent(event
);
3794 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
3796 wxInitDialogEvent
event(GetId());
3797 event
.SetEventObject(this);
3799 return GetEventHandler()->ProcessEvent(event
);
3802 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
3804 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
3805 wxUnusedVar(wParam
);
3807 #else // __WXMICROWIN__
3808 HDROP hFilesInfo
= (HDROP
) wParam
;
3810 // Get the total number of files dropped
3811 UINT gwFilesDropped
= ::DragQueryFile
3819 wxString
*files
= new wxString
[gwFilesDropped
];
3820 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
3822 // first get the needed buffer length (+1 for terminating NUL)
3823 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
3825 // and now get the file name
3826 ::DragQueryFile(hFilesInfo
, wIndex
,
3827 wxStringBuffer(files
[wIndex
], len
), len
);
3829 DragFinish (hFilesInfo
);
3831 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
3832 event
.SetEventObject(this);
3835 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
3836 event
.m_pos
.x
= dropPoint
.x
;
3837 event
.m_pos
.y
= dropPoint
.y
;
3839 return GetEventHandler()->ProcessEvent(event
);
3844 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
3846 int WXUNUSED(mouseMsg
))
3848 #ifndef __WXMICROWIN__
3849 // the logic is as follows:
3850 // -1. don't set cursor for non client area, including but not limited to
3851 // the title bar, scrollbars, &c
3852 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
3853 // 1. if we have the cursor set it unless wxIsBusy()
3854 // 2. if we're a top level window, set some cursor anyhow
3855 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
3857 if ( nHitTest
!= HTCLIENT
)
3862 HCURSOR hcursor
= 0;
3864 // first ask the user code - it may wish to set the cursor in some very
3865 // specific way (for example, depending on the current position)
3868 if ( !::GetCursorPosWinCE(&pt
))
3870 if ( !::GetCursorPos(&pt
) )
3873 wxLogLastError(wxT("GetCursorPos"));
3878 ScreenToClient(&x
, &y
);
3879 wxSetCursorEvent
event(x
, y
);
3881 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
3882 if ( processedEvtSetCursor
&& event
.HasCursor() )
3884 hcursor
= GetHcursorOf(event
.GetCursor());
3889 bool isBusy
= wxIsBusy();
3891 // the test for processedEvtSetCursor is here to prevent using m_cursor
3892 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3893 // it - this is a way to say that our cursor shouldn't be used for this
3895 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
3897 hcursor
= GetHcursorOf(m_cursor
);
3904 hcursor
= wxGetCurrentBusyCursor();
3906 else if ( !hcursor
)
3908 const wxCursor
*cursor
= wxGetGlobalCursor();
3909 if ( cursor
&& cursor
->Ok() )
3911 hcursor
= GetHcursorOf(*cursor
);
3919 // wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3921 ::SetCursor(hcursor
);
3923 // cursor set, stop here
3926 #endif // __WXMICROWIN__
3928 // pass up the window chain
3932 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
3933 WXLPARAM
WXUNUSED(lParam
),
3934 bool *WXUNUSED_IN_WINCE(vetoed
))
3940 wxEventType evtType
;
3943 case PBT_APMQUERYSUSPEND
:
3944 evtType
= wxEVT_POWER_SUSPENDING
;
3947 case PBT_APMQUERYSUSPENDFAILED
:
3948 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
3951 case PBT_APMSUSPEND
:
3952 evtType
= wxEVT_POWER_SUSPENDED
;
3955 case PBT_APMRESUMESUSPEND
:
3956 #ifdef PBT_APMRESUMEAUTOMATIC
3957 case PBT_APMRESUMEAUTOMATIC
:
3959 evtType
= wxEVT_POWER_RESUME
;
3963 wxLogDebug(_T("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
3966 // these messages are currently not mapped to wx events
3967 case PBT_APMQUERYSTANDBY
:
3968 case PBT_APMQUERYSTANDBYFAILED
:
3969 case PBT_APMSTANDBY
:
3970 case PBT_APMRESUMESTANDBY
:
3971 case PBT_APMBATTERYLOW
:
3972 case PBT_APMPOWERSTATUSCHANGE
:
3973 case PBT_APMOEMEVENT
:
3974 case PBT_APMRESUMECRITICAL
:
3975 evtType
= wxEVT_NULL
;
3979 // don't handle unknown messages
3980 if ( evtType
== wxEVT_NULL
)
3983 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
3985 wxPowerEvent
event(evtType
);
3986 if ( !GetEventHandler()->ProcessEvent(event
) )
3989 *vetoed
= event
.IsVetoed();
3995 bool wxWindowMSW::IsDoubleBuffered() const
3997 for ( const wxWindowMSW
*wnd
= this;
3998 wnd
&& !wnd
->IsTopLevel(); wnd
=
4001 if ( ::GetWindowLong(GetHwndOf(wnd
), GWL_EXSTYLE
) & WS_EX_COMPOSITED
)
4008 // ---------------------------------------------------------------------------
4009 // owner drawn stuff
4010 // ---------------------------------------------------------------------------
4012 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
4013 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
4014 #define WXUNUSED_UNLESS_ODRAWN(param) param
4016 #define WXUNUSED_UNLESS_ODRAWN(param)
4020 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
4021 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
4023 #if wxUSE_OWNER_DRAWN
4025 #if wxUSE_MENUS_NATIVE
4026 // is it a menu item?
4027 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
4028 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
4030 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
4032 // see comment before the same test in MSWOnMeasureItem() below
4036 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4037 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
4039 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4040 // the DC from being released
4041 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
4042 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
4043 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
4044 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
4046 return pMenuItem
->OnDrawItem
4050 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
4051 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
4054 #endif // wxUSE_MENUS_NATIVE
4056 #endif // USE_OWNER_DRAWN
4058 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4060 #if wxUSE_OWNER_DRAWN
4061 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4062 #else // !wxUSE_OWNER_DRAWN
4063 // we may still have owner-drawn buttons internally because we have to make
4064 // them owner-drawn to support colour change
4067 wxDynamicCast(FindItem(id
), wxButton
)
4072 #endif // USE_OWNER_DRAWN
4076 return item
->MSWOnDraw(itemStruct
);
4079 #endif // wxUSE_CONTROLS
4085 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4087 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4088 // is it a menu item?
4089 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4090 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4092 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4094 // according to Carsten Fuchs the pointer may be NULL under XP if an
4095 // MDI child frame is initially maximized, see this for more info:
4096 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4098 // so silently ignore it instead of asserting
4102 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4103 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
4106 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4108 pMeasureStruct
->itemWidth
= w
;
4109 pMeasureStruct
->itemHeight
= h
;
4114 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4117 return item
->MSWOnMeasure(itemStruct
);
4121 wxUnusedVar(itemStruct
);
4122 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4127 // ---------------------------------------------------------------------------
4128 // colours and palettes
4129 // ---------------------------------------------------------------------------
4131 bool wxWindowMSW::HandleSysColorChange()
4133 wxSysColourChangedEvent event
;
4134 event
.SetEventObject(this);
4136 (void)GetEventHandler()->ProcessEvent(event
);
4138 // always let the system carry on the default processing to allow the
4139 // native controls to react to the colours update
4143 bool wxWindowMSW::HandleDisplayChange()
4145 wxDisplayChangedEvent event
;
4146 event
.SetEventObject(this);
4148 return GetEventHandler()->ProcessEvent(event
);
4151 #ifndef __WXMICROWIN__
4153 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4155 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4159 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4162 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4164 #endif // wxUSE_CONTROLS
4167 return *brush
!= NULL
;
4170 #endif // __WXMICROWIN__
4172 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4175 // same as below except we don't respond to our own messages
4176 if ( hWndPalChange
!= GetHWND() )
4178 // check to see if we our our parents have a custom palette
4179 wxWindowMSW
*win
= this;
4180 while ( win
&& !win
->HasCustomPalette() )
4182 win
= win
->GetParent();
4185 if ( win
&& win
->HasCustomPalette() )
4187 // realize the palette to see whether redrawing is needed
4188 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4189 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4190 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4192 int result
= ::RealizePalette(hdc
);
4194 // restore the palette (before releasing the DC)
4195 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4196 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4197 ::RealizePalette(hdc
);
4198 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4200 // now check for the need to redraw
4202 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4206 #endif // wxUSE_PALETTE
4208 wxPaletteChangedEvent
event(GetId());
4209 event
.SetEventObject(this);
4210 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4212 return GetEventHandler()->ProcessEvent(event
);
4215 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4217 // notify windows on the capture stack about lost capture
4218 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4219 wxWindowBase::NotifyCaptureLost();
4221 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4222 wxMouseCaptureChangedEvent
event(GetId(), win
);
4223 event
.SetEventObject(this);
4224 return GetEventHandler()->ProcessEvent(event
);
4227 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4229 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4230 // we need to send this to child windows (it is only sent to top-level
4231 // windows) so {list,tree}ctrls can adjust their font size if necessary
4232 // this is exactly how explorer does it to enable the font size changes
4234 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4237 // top-level windows already get this message from the system
4238 wxWindow
*win
= node
->GetData();
4239 if ( !win
->IsTopLevel() )
4241 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4244 node
= node
->GetNext();
4247 // let the system handle it
4251 bool wxWindowMSW::HandleQueryNewPalette()
4255 // check to see if we our our parents have a custom palette
4256 wxWindowMSW
*win
= this;
4257 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4258 if (win
->HasCustomPalette()) {
4259 /* realize the palette to see whether redrawing is needed */
4260 HDC hdc
= ::GetDC((HWND
) GetHWND());
4261 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4262 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4264 int result
= ::RealizePalette(hdc
);
4265 /* restore the palette (before releasing the DC) */
4266 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4267 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4268 ::RealizePalette(hdc
);
4269 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4270 /* now check for the need to redraw */
4272 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4274 #endif // wxUSE_PALETTE
4276 wxQueryNewPaletteEvent
event(GetId());
4277 event
.SetEventObject(this);
4279 return GetEventHandler()->ProcessEvent(event
) && event
.GetPaletteRealized();
4282 // Responds to colour changes: passes event on to children.
4283 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4285 // the top level window also reset the standard colour map as it might have
4286 // changed (there is no need to do it for the non top level windows as we
4287 // only have to do it once)
4291 gs_hasStdCmap
= false;
4293 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4296 // Only propagate to non-top-level windows because Windows already
4297 // sends this event to all top-level ones
4298 wxWindow
*win
= node
->GetData();
4299 if ( !win
->IsTopLevel() )
4301 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4302 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4303 // the standard controls
4304 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4307 node
= node
->GetNext();
4311 extern wxCOLORMAP
*wxGetStdColourMap()
4313 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4314 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4316 if ( !gs_hasStdCmap
)
4318 static bool s_coloursInit
= false;
4320 if ( !s_coloursInit
)
4322 // When a bitmap is loaded, the RGB values can change (apparently
4323 // because Windows adjusts them to care for the old programs always
4324 // using 0xc0c0c0 while the transparent colour for the new Windows
4325 // versions is different). But we do this adjustment ourselves so
4326 // we want to avoid Windows' "help" and for this we need to have a
4327 // reference bitmap which can tell us what the RGB values change
4329 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4330 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
4331 if ( stdColourBitmap
.Ok() )
4333 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4334 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4335 _T("forgot to update wxBITMAP_STD_COLOURS!") );
4338 memDC
.SelectObject(stdColourBitmap
);
4341 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4343 memDC
.GetPixel(i
, 0, &colour
);
4344 s_stdColours
[i
] = wxColourToRGB(colour
);
4347 else // wxBITMAP_STD_COLOURS couldn't be loaded
4349 s_stdColours
[0] = RGB(000,000,000); // black
4350 s_stdColours
[1] = RGB(128,128,128); // dark grey
4351 s_stdColours
[2] = RGB(192,192,192); // light grey
4352 s_stdColours
[3] = RGB(255,255,255); // white
4353 //s_stdColours[4] = RGB(000,000,255); // blue
4354 //s_stdColours[5] = RGB(255,000,255); // magenta
4357 s_coloursInit
= true;
4360 gs_hasStdCmap
= true;
4362 // create the colour map
4363 #define INIT_CMAP_ENTRY(col) \
4364 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4365 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4367 INIT_CMAP_ENTRY(BTNTEXT
);
4368 INIT_CMAP_ENTRY(BTNSHADOW
);
4369 INIT_CMAP_ENTRY(BTNFACE
);
4370 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4372 #undef INIT_CMAP_ENTRY
4378 // ---------------------------------------------------------------------------
4380 // ---------------------------------------------------------------------------
4382 bool wxWindowMSW::HandlePaint()
4384 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4386 wxLogLastError(wxT("CreateRectRgn"));
4387 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4388 wxLogLastError(wxT("GetUpdateRgn"));
4390 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4392 wxPaintEvent
event(m_windowId
);
4393 event
.SetEventObject(this);
4395 bool processed
= GetEventHandler()->ProcessEvent(event
);
4397 // note that we must generate NC event after the normal one as otherwise
4398 // BeginPaint() will happily overwrite our decorations with the background
4400 wxNcPaintEvent
eventNc(m_windowId
);
4401 eventNc
.SetEventObject(this);
4402 GetEventHandler()->ProcessEvent(eventNc
);
4407 // Can be called from an application's OnPaint handler
4408 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4410 #ifdef __WXUNIVERSAL__
4413 HDC hDC
= (HDC
) wxPaintDC::FindDCInCache((wxWindow
*) event
.GetEventObject());
4416 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4421 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4423 wxDCTemp
dc(hdc
, GetClientSize());
4426 dc
.SetWindow((wxWindow
*)this);
4428 wxEraseEvent
event(m_windowId
, &dc
);
4429 event
.SetEventObject(this);
4430 bool rc
= GetEventHandler()->ProcessEvent(event
);
4432 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
4433 dc
.SelectOldObjects(hdc
);
4438 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
4440 // standard non top level controls (i.e. except the dialogs) always erase
4441 // their background themselves in HandleCtlColor() or have some control-
4442 // specific ways to set the colours (common controls)
4443 if ( IsOfStandardClass() && !IsTopLevel() )
4449 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
4451 // don't skip the event here, custom background means that the app
4452 // is drawing it itself in its OnPaint(), so don't draw it at all
4453 // now to avoid flicker
4458 // do default background painting
4459 if ( !DoEraseBackground(GetHdcOf(*event
.GetDC())) )
4461 // let the system paint the background
4466 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4468 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4472 wxFillRect(GetHwnd(), (HDC
)hDC
, hbr
);
4478 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
), WXHWND hWnd
)
4482 // our background colour applies to:
4483 // 1. this window itself, always
4484 // 2. all children unless the colour is "not inheritable"
4485 // 3. even if it is not inheritable, our immediate transparent
4486 // children should still inherit it -- but not any transparent
4487 // children because it would look wrong if a child of non
4488 // transparent child would show our bg colour when the child itself
4490 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
4493 (win
&& win
->HasTransparentBackground() &&
4494 win
->GetParent() == this) )
4496 // draw children with the same colour as the parent
4498 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4500 return (WXHBRUSH
)GetHbrushOf(*brush
);
4507 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
, WXHWND hWndToPaint
)
4510 hWndToPaint
= GetHWND();
4512 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4514 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, hWndToPaint
);
4518 // background is not inherited beyond top level windows
4519 if ( win
->IsTopLevel() )
4526 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4528 // we receive this message when DrawThemeParentBackground() is
4529 // called from def window proc of several controls under XP and we
4530 // must draw properly themed background here
4532 // note that naively I'd expect filling the client rect with the
4533 // brush returned by MSWGetBgBrush() work -- but for some reason it
4534 // doesn't and we have to call parents MSWPrintChild() which is
4535 // supposed to call DrawThemeBackground() with appropriate params
4537 // also note that in this case lParam == PRF_CLIENT but we're
4538 // clearly expected to paint the background and nothing else!
4540 if ( IsTopLevel() || InheritsBackgroundColour() )
4543 // sometimes we don't want the parent to handle it at all, instead
4544 // return whatever value this window wants
4545 if ( !MSWShouldPropagatePrintChild() )
4546 return MSWPrintChild(hDC
, (wxWindow
*)this);
4548 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4550 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4553 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4560 // ---------------------------------------------------------------------------
4561 // moving and resizing
4562 // ---------------------------------------------------------------------------
4564 bool wxWindowMSW::HandleMinimize()
4566 wxIconizeEvent
event(m_windowId
);
4567 event
.SetEventObject(this);
4569 return GetEventHandler()->ProcessEvent(event
);
4572 bool wxWindowMSW::HandleMaximize()
4574 wxMaximizeEvent
event(m_windowId
);
4575 event
.SetEventObject(this);
4577 return GetEventHandler()->ProcessEvent(event
);
4580 bool wxWindowMSW::HandleMove(int x
, int y
)
4583 wxMoveEvent
event(point
, m_windowId
);
4584 event
.SetEventObject(this);
4586 return GetEventHandler()->ProcessEvent(event
);
4589 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
4591 wxMoveEvent
event(rect
, m_windowId
);
4592 event
.SetEventObject(this);
4594 bool rc
= GetEventHandler()->ProcessEvent(event
);
4596 rect
= event
.GetRect();
4600 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
4602 #if USE_DEFERRED_SIZING
4603 // when we resize this window, its children are probably going to be
4604 // repositioned as well, prepare to use DeferWindowPos() for them
4605 int numChildren
= 0;
4606 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
4608 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
4613 // Protect against valid m_hDWP being overwritten
4614 bool useDefer
= false;
4616 if ( numChildren
> 1 )
4620 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
4623 wxLogLastError(_T("BeginDeferWindowPos"));
4629 #endif // USE_DEFERRED_SIZING
4631 // update this window size
4632 bool processed
= false;
4636 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4637 // fall through nevertheless
4641 // we're not interested in these messages at all
4644 case SIZE_MINIMIZED
:
4645 processed
= HandleMinimize();
4648 case SIZE_MAXIMIZED
:
4649 /* processed = */ HandleMaximize();
4650 // fall through to send a normal size event as well
4653 // don't use w and h parameters as they specify the client size
4654 // while according to the docs EVT_SIZE handler is supposed to
4655 // receive the total size
4656 wxSizeEvent
event(GetSize(), m_windowId
);
4657 event
.SetEventObject(this);
4659 processed
= GetEventHandler()->ProcessEvent(event
);
4662 #if USE_DEFERRED_SIZING
4663 // and finally change the positions of all child windows at once
4664 if ( useDefer
&& m_hDWP
)
4666 // reset m_hDWP to NULL so that child windows don't try to use our
4667 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4668 // happen anyhow normally but who knows what weird flow of control we
4669 // may have depending on what the users EVT_SIZE handler does...)
4670 HDWP hDWP
= (HDWP
)m_hDWP
;
4673 // do put all child controls in place at once
4674 if ( !::EndDeferWindowPos(hDWP
) )
4676 wxLogLastError(_T("EndDeferWindowPos"));
4679 // Reset our children's pending pos/size values.
4680 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4682 node
= node
->GetNext() )
4684 wxWindowMSW
*child
= node
->GetData();
4685 child
->m_pendingPosition
= wxDefaultPosition
;
4686 child
->m_pendingSize
= wxDefaultSize
;
4689 #endif // USE_DEFERRED_SIZING
4694 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
4696 wxSizeEvent
event(rect
, m_windowId
);
4697 event
.SetEventObject(this);
4699 bool rc
= GetEventHandler()->ProcessEvent(event
);
4701 rect
= event
.GetRect();
4705 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
4710 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
4714 int minWidth
= GetMinWidth(),
4715 minHeight
= GetMinHeight(),
4716 maxWidth
= GetMaxWidth(),
4717 maxHeight
= GetMaxHeight();
4719 if ( minWidth
!= wxDefaultCoord
)
4721 info
->ptMinTrackSize
.x
= minWidth
;
4725 if ( minHeight
!= wxDefaultCoord
)
4727 info
->ptMinTrackSize
.y
= minHeight
;
4731 if ( maxWidth
!= wxDefaultCoord
)
4733 info
->ptMaxTrackSize
.x
= maxWidth
;
4737 if ( maxHeight
!= wxDefaultCoord
)
4739 info
->ptMaxTrackSize
.y
= maxHeight
;
4747 // ---------------------------------------------------------------------------
4749 // ---------------------------------------------------------------------------
4751 bool wxWindowMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
4753 #if wxUSE_MENUS_NATIVE
4754 if ( !cmd
&& wxCurrentPopupMenu
)
4756 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
4757 wxCurrentPopupMenu
= NULL
;
4759 return popupMenu
->MSWCommand(cmd
, id
);
4761 #endif // wxUSE_MENUS_NATIVE
4763 wxWindow
*win
= NULL
;
4765 // first try to find it from HWND - this works even with the broken
4766 // programs using the same ids for different controls
4769 win
= wxFindWinFromHandle(control
);
4775 // must cast to a signed type before comparing with other ids!
4776 win
= FindItem((signed short)id
);
4781 return win
->MSWCommand(cmd
, id
);
4784 // the messages sent from the in-place edit control used by the treectrl
4785 // for label editing have id == 0, but they should _not_ be treated as menu
4786 // messages (they are EN_XXX ones, in fact) so don't translate anything
4787 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4790 // If no child window, it may be an accelerator, e.g. for a popup menu
4793 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
4794 event
.SetEventObject(this);
4798 return GetEventHandler()->ProcessEvent(event
);
4802 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4803 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4804 // notifications to its parent which we want to reflect back to
4806 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
4807 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
4809 #endif // wxUSE_SPINCTRL
4811 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
4812 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
4813 // notifications to its parent which we want to reflect back to
4815 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
4816 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
4824 // ---------------------------------------------------------------------------
4826 // ---------------------------------------------------------------------------
4828 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
4832 // our client coords are not quite the same as Windows ones
4833 wxPoint pt
= GetClientAreaOrigin();
4834 event
.m_x
= x
- pt
.x
;
4835 event
.m_y
= y
- pt
.y
;
4837 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
4838 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
4839 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
4840 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
4841 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
4842 event
.m_altDown
= ::GetKeyState(VK_MENU
) < 0;
4845 event
.SetTimestamp(::GetMessageTime());
4848 event
.SetEventObject(this);
4849 event
.SetId(GetId());
4851 #if wxUSE_MOUSEEVENT_HACK
4852 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
4853 gs_lastMouseEvent
.type
= event
.GetEventType();
4854 #endif // wxUSE_MOUSEEVENT_HACK
4858 // Windows doesn't send the mouse events to the static controls (which are
4859 // transparent in the sense that their WM_NCHITTEST handler returns
4860 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4861 // and so we manually check if we don't have a child window under mouse and if
4862 // we do, send the event to it instead of the window Windows had sent WM_XXX
4865 // Notice that this is not done for the mouse move events because this could
4866 // (would?) be too slow, but only for clicks which means that the static texts
4867 // still don't get move, enter nor leave events.
4868 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
4870 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
4872 // first try to find a non transparent child: this allows us to send events
4873 // to a static text which is inside a static box, for example
4874 POINT pt
= { *x
, *y
};
4875 HWND hwnd
= GetHwndOf(win
),
4879 hwndUnderMouse
= ::ChildWindowFromPoint
4885 hwndUnderMouse
= ::ChildWindowFromPointEx
4895 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
4897 // now try any child window at all
4898 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
4901 // check that we have a child window which is susceptible to receive mouse
4902 // events: for this it must be shown and enabled
4903 if ( hwndUnderMouse
&&
4904 hwndUnderMouse
!= hwnd
&&
4905 ::IsWindowVisible(hwndUnderMouse
) &&
4906 ::IsWindowEnabled(hwndUnderMouse
) )
4908 wxWindow
*winUnderMouse
= wxFindWinFromHandle((WXHWND
)hwndUnderMouse
);
4909 if ( winUnderMouse
)
4911 // translate the mouse coords to the other window coords
4912 win
->ClientToScreen(x
, y
);
4913 winUnderMouse
->ScreenToClient(x
, y
);
4915 win
= winUnderMouse
;
4921 #endif // __WXWINCE__
4923 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4925 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4926 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
4927 // from the message id and take the value in the table to get wxWin event
4929 static const wxEventType eventsMouse
[] =
4943 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
4944 InitMouseEvent(event
, x
, y
, flags
);
4946 return GetEventHandler()->ProcessEvent(event
);
4949 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
4951 if ( !m_mouseInWindow
)
4953 // it would be wrong to assume that just because we get a mouse move
4954 // event that the mouse is inside the window: although this is usually
4955 // true, it is not if we had captured the mouse, so we need to check
4956 // the mouse coordinates here
4957 if ( !HasCapture() || IsMouseInWindow() )
4959 // Generate an ENTER event
4960 m_mouseInWindow
= true;
4962 #ifdef HAVE_TRACKMOUSEEVENT
4963 typedef BOOL (WINAPI
*_TrackMouseEvent_t
)(LPTRACKMOUSEEVENT
);
4965 static const _TrackMouseEvent_t
4966 s_pfn_TrackMouseEvent
= _TrackMouseEvent
;
4967 #else // !__WXWINCE__
4968 static _TrackMouseEvent_t s_pfn_TrackMouseEvent
;
4969 static bool s_initDone
= false;
4974 wxDynamicLibrary
dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM
);
4975 if ( dllComCtl32
.IsLoaded() )
4977 s_pfn_TrackMouseEvent
= (_TrackMouseEvent_t
)
4978 dllComCtl32
.GetSymbol(_T("_TrackMouseEvent"));
4983 // notice that it's ok to unload comctl32.dll here as it won't
4984 // be really unloaded, being still in use because we link to it
4988 if ( s_pfn_TrackMouseEvent
)
4989 #endif // __WXWINCE__/!__WXWINCE__
4991 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
4993 trackinfo
.dwFlags
= TME_LEAVE
;
4994 trackinfo
.hwndTrack
= GetHwnd();
4996 (*s_pfn_TrackMouseEvent
)(&trackinfo
);
4998 #endif // HAVE_TRACKMOUSEEVENT
5000 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
5001 InitMouseEvent(event
, x
, y
, flags
);
5003 (void)GetEventHandler()->ProcessEvent(event
);
5006 #ifdef HAVE_TRACKMOUSEEVENT
5007 else // mouse not in window
5009 // Check if we need to send a LEAVE event
5010 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
5011 // send it here if we are using native mouse leave tracking
5012 if ( HasCapture() && !IsMouseInWindow() )
5014 GenerateMouseLeave();
5017 #endif // HAVE_TRACKMOUSEEVENT
5019 #if wxUSE_MOUSEEVENT_HACK
5020 // Windows often generates mouse events even if mouse position hasn't
5021 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
5023 // Filter this out as it can result in unexpected behaviour compared to
5025 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
5026 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
5027 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
5028 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
5030 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
5032 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
5037 #endif // wxUSE_MOUSEEVENT_HACK
5039 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
5043 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
5045 #if wxUSE_MOUSEWHEEL
5046 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5047 // forwarded up to the parent by DefWindowProc()) and not in the client
5048 // ones as all the other messages, translate them to the client coords for
5051 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
5052 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
5053 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
5054 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5055 event
.m_wheelDelta
= WHEEL_DELTA
;
5057 static int s_linesPerRotation
= -1;
5058 if ( s_linesPerRotation
== -1 )
5060 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5061 &s_linesPerRotation
, 0))
5063 // this is not supposed to happen
5064 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5066 // the default is 3, so use it if SystemParametersInfo() failed
5067 s_linesPerRotation
= 3;
5071 event
.m_linesPerAction
= s_linesPerRotation
;
5072 return GetEventHandler()->ProcessEvent(event
);
5074 #else // !wxUSE_MOUSEWHEEL
5075 wxUnusedVar(wParam
);
5076 wxUnusedVar(lParam
);
5079 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5082 void wxWindowMSW::GenerateMouseLeave()
5084 m_mouseInWindow
= false;
5087 if ( wxIsShiftDown() )
5089 if ( wxIsCtrlDown() )
5090 state
|= MK_CONTROL
;
5092 // Only the high-order bit should be tested
5093 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5094 state
|= MK_LBUTTON
;
5095 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5096 state
|= MK_MBUTTON
;
5097 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5098 state
|= MK_RBUTTON
;
5102 if ( !::GetCursorPosWinCE(&pt
) )
5104 if ( !::GetCursorPos(&pt
) )
5107 wxLogLastError(_T("GetCursorPos"));
5110 // we need to have client coordinates here for symmetry with
5111 // wxEVT_ENTER_WINDOW
5112 RECT rect
= wxGetWindowRect(GetHwnd());
5116 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5117 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5119 (void)GetEventHandler()->ProcessEvent(event
);
5122 // ---------------------------------------------------------------------------
5123 // keyboard handling
5124 // ---------------------------------------------------------------------------
5126 // create the key event of the given type for the given key - used by
5127 // HandleChar and HandleKeyDown/Up
5128 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5131 WXWPARAM wParam
) const
5133 wxKeyEvent
event(evType
);
5134 event
.SetId(GetId());
5135 event
.m_shiftDown
= wxIsShiftDown();
5136 event
.m_controlDown
= wxIsCtrlDown();
5137 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5139 event
.SetEventObject((wxWindow
*)this); // const_cast
5140 event
.m_keyCode
= id
;
5142 event
.m_uniChar
= (wxChar
) wParam
;
5144 event
.m_rawCode
= (wxUint32
) wParam
;
5145 event
.m_rawFlags
= (wxUint32
) lParam
;
5147 event
.SetTimestamp(::GetMessageTime());
5150 // translate the position to client coords
5153 GetCursorPosWinCE(&pt
);
5158 GetWindowRect(GetHwnd(),&rect
);
5168 // isASCII is true only when we're called from WM_CHAR handler and not from
5170 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
5177 else // we're called from WM_KEYDOWN
5179 // don't pass lParam to wxCharCodeMSWToWX() here because we don't want
5180 // to get numpad key codes: CHAR events should use the logical keys
5181 // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events
5182 id
= wxCharCodeMSWToWX(wParam
);
5185 // it's ASCII and will be processed here only when called from
5186 // WM_CHAR (i.e. when isASCII = true), don't process it now
5191 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
5193 // the alphanumeric keys produced by pressing AltGr+something on European
5194 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5195 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5196 // alphanumeric, so pretend that there are no modifiers at all (the
5197 // KEY_DOWN event would still have the correct modifiers if they're really
5199 if ( event
.m_controlDown
&& event
.m_altDown
&&
5200 (id
>= 32 && id
< 256) )
5202 event
.m_controlDown
=
5203 event
.m_altDown
= false;
5206 return GetEventHandler()->ProcessEvent(event
);
5209 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5211 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5215 // normal ASCII char
5219 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
5220 return GetEventHandler()->ProcessEvent(event
);
5223 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5225 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5229 // normal ASCII char
5233 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
5234 return GetEventHandler()->ProcessEvent(event
);
5237 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5238 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5240 // FIXME: implement GetMenuItemCount for WinCE, possibly
5241 // in terms of GetMenuItemInfo
5243 const HMENU hmenu
= (HMENU
)lParam
;
5247 mii
.cbSize
= sizeof(MENUITEMINFO
);
5249 // we could use MIIM_FTYPE here as we only need to know if the item is
5250 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5251 // MIIM_FTYPE is not supported under Win95
5252 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5254 // find if we have this letter in any owner drawn item
5255 const int count
= ::GetMenuItemCount(hmenu
);
5256 for ( int i
= 0; i
< count
; i
++ )
5258 // previous loop iteration could modify it, reset it back before
5259 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5262 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5264 if ( mii
.fType
== MFT_OWNERDRAW
)
5266 // dwItemData member of the MENUITEMINFO is a
5267 // pointer to the associated wxMenuItem -- see the
5268 // menu creation code
5269 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5271 const wxChar
*p
= wxStrchr(item
->GetText(), _T('&'));
5274 if ( *p
== _T('&') )
5276 // this is not the accel char, find the real one
5277 p
= wxStrchr(p
+ 1, _T('&'));
5279 else // got the accel char
5281 // FIXME-UNICODE: this comparison doesn't risk to work
5282 // for non ASCII accelerator characters I'm afraid, but
5284 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5290 // this one doesn't match
5297 else // failed to get the menu text?
5299 // it's not fatal, so don't show error, but still log it
5300 wxLogLastError(_T("GetMenuItemInfo"));
5307 bool wxWindowMSW::HandleClipboardEvent( WXUINT nMsg
)
5309 const wxEventType type
= ( nMsg
== WM_CUT
) ? wxEVT_COMMAND_TEXT_CUT
:
5310 ( nMsg
== WM_COPY
) ? wxEVT_COMMAND_TEXT_COPY
:
5311 /*( nMsg == WM_PASTE ) ? */ wxEVT_COMMAND_TEXT_PASTE
;
5312 wxClipboardTextEvent
evt(type
, GetId());
5314 evt
.SetEventObject(this);
5316 return GetEventHandler()->ProcessEvent(evt
);
5319 // ---------------------------------------------------------------------------
5321 // ---------------------------------------------------------------------------
5323 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5327 if ( flags
& JOY_BUTTON1CHG
)
5328 change
= wxJOY_BUTTON1
;
5329 if ( flags
& JOY_BUTTON2CHG
)
5330 change
= wxJOY_BUTTON2
;
5331 if ( flags
& JOY_BUTTON3CHG
)
5332 change
= wxJOY_BUTTON3
;
5333 if ( flags
& JOY_BUTTON4CHG
)
5334 change
= wxJOY_BUTTON4
;
5337 if ( flags
& JOY_BUTTON1
)
5338 buttons
|= wxJOY_BUTTON1
;
5339 if ( flags
& JOY_BUTTON2
)
5340 buttons
|= wxJOY_BUTTON2
;
5341 if ( flags
& JOY_BUTTON3
)
5342 buttons
|= wxJOY_BUTTON3
;
5343 if ( flags
& JOY_BUTTON4
)
5344 buttons
|= wxJOY_BUTTON4
;
5346 // the event ids aren't consecutive so we can't use table based lookup
5348 wxEventType eventType
;
5353 eventType
= wxEVT_JOY_MOVE
;
5358 eventType
= wxEVT_JOY_MOVE
;
5363 eventType
= wxEVT_JOY_ZMOVE
;
5368 eventType
= wxEVT_JOY_ZMOVE
;
5371 case MM_JOY1BUTTONDOWN
:
5373 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5376 case MM_JOY2BUTTONDOWN
:
5378 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5381 case MM_JOY1BUTTONUP
:
5383 eventType
= wxEVT_JOY_BUTTON_UP
;
5386 case MM_JOY2BUTTONUP
:
5388 eventType
= wxEVT_JOY_BUTTON_UP
;
5392 wxFAIL_MSG(wxT("no such joystick event"));
5397 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5398 event
.SetPosition(wxPoint(x
, y
));
5399 event
.SetEventObject(this);
5401 return GetEventHandler()->ProcessEvent(event
);
5411 // ---------------------------------------------------------------------------
5413 // ---------------------------------------------------------------------------
5415 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5416 WXWORD pos
, WXHWND control
)
5418 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5420 wxWindow
*child
= wxFindWinFromHandle(control
);
5422 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5425 wxScrollWinEvent event
;
5426 event
.SetPosition(pos
);
5427 event
.SetOrientation(orientation
);
5428 event
.SetEventObject(this);
5433 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5437 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5441 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5445 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5449 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5453 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5456 case SB_THUMBPOSITION
:
5458 // under Win32, the scrollbar range and position are 32 bit integers,
5459 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5460 // explicitly query the scrollbar for the correct position (this must
5461 // be done only for these two SB_ events as they are the only one
5462 // carrying the scrollbar position)
5464 WinStruct
<SCROLLINFO
> scrollInfo
;
5465 scrollInfo
.fMask
= SIF_TRACKPOS
;
5467 if ( !::GetScrollInfo(GetHwnd(),
5468 orientation
== wxHORIZONTAL
? SB_HORZ
5472 // Not necessarily an error, if there are no scrollbars yet.
5473 // wxLogLastError(_T("GetScrollInfo"));
5476 event
.SetPosition(scrollInfo
.nTrackPos
);
5479 event
.SetEventType( wParam
== SB_THUMBPOSITION
5480 ? wxEVT_SCROLLWIN_THUMBRELEASE
5481 : wxEVT_SCROLLWIN_THUMBTRACK
);
5488 return GetEventHandler()->ProcessEvent(event
);
5491 // ===========================================================================
5493 // ===========================================================================
5495 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5498 HDC dc
= ::GetDC((HWND
) wnd
);
5501 // the_font.UseResource();
5502 // the_font.RealizeResource();
5503 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
5505 was
= (HFONT
) SelectObject(dc
,fnt
);
5507 GetTextMetrics(dc
, &tm
);
5510 SelectObject(dc
,was
);
5512 ReleaseDC((HWND
)wnd
, dc
);
5515 *x
= tm
.tmAveCharWidth
;
5517 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
5519 // the_font.ReleaseResource();
5522 // use the "extended" bit (24) of lParam to distinguish extended keys
5523 // from normal keys as the same key is sent
5525 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
5527 // except that if lParam is 0, it means we don't have real lParam from
5528 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
5529 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
5530 // non-numpad (hence extended) key as this is a more common case
5531 return !lParam
|| (lParam
& (1 << 24)) ? keyExtended
: keyNormal
;
5534 // this array contains the Windows virtual key codes which map one to one to
5535 // WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below
5537 // note that keys having a normal and numpad version (e.g. WXK_HOME and
5538 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
5539 static const struct wxKeyMapping
5543 } gs_specialKeys
[] =
5545 { VK_CANCEL
, WXK_CANCEL
},
5546 { VK_BACK
, WXK_BACK
},
5547 { VK_TAB
, WXK_TAB
},
5548 { VK_CLEAR
, WXK_CLEAR
},
5549 { VK_SHIFT
, WXK_SHIFT
},
5550 { VK_CONTROL
, WXK_CONTROL
},
5551 { VK_MENU
, WXK_ALT
},
5552 { VK_PAUSE
, WXK_PAUSE
},
5553 { VK_CAPITAL
, WXK_CAPITAL
},
5554 { VK_SPACE
, WXK_SPACE
},
5555 { VK_ESCAPE
, WXK_ESCAPE
},
5556 { VK_SELECT
, WXK_SELECT
},
5557 { VK_PRINT
, WXK_PRINT
},
5558 { VK_EXECUTE
, WXK_EXECUTE
},
5559 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
5560 { VK_HELP
, WXK_HELP
},
5562 { VK_NUMPAD0
, WXK_NUMPAD0
},
5563 { VK_NUMPAD1
, WXK_NUMPAD1
},
5564 { VK_NUMPAD2
, WXK_NUMPAD2
},
5565 { VK_NUMPAD3
, WXK_NUMPAD3
},
5566 { VK_NUMPAD4
, WXK_NUMPAD4
},
5567 { VK_NUMPAD5
, WXK_NUMPAD5
},
5568 { VK_NUMPAD6
, WXK_NUMPAD6
},
5569 { VK_NUMPAD7
, WXK_NUMPAD7
},
5570 { VK_NUMPAD8
, WXK_NUMPAD8
},
5571 { VK_NUMPAD9
, WXK_NUMPAD9
},
5572 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
5573 { VK_ADD
, WXK_NUMPAD_ADD
},
5574 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
5575 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
5576 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
5587 { VK_F10
, WXK_F10
},
5588 { VK_F11
, WXK_F11
},
5589 { VK_F12
, WXK_F12
},
5590 { VK_F13
, WXK_F13
},
5591 { VK_F14
, WXK_F14
},
5592 { VK_F15
, WXK_F15
},
5593 { VK_F16
, WXK_F16
},
5594 { VK_F17
, WXK_F17
},
5595 { VK_F18
, WXK_F18
},
5596 { VK_F19
, WXK_F19
},
5597 { VK_F20
, WXK_F20
},
5598 { VK_F21
, WXK_F21
},
5599 { VK_F22
, WXK_F22
},
5600 { VK_F23
, WXK_F23
},
5601 { VK_F24
, WXK_F24
},
5603 { VK_NUMLOCK
, WXK_NUMLOCK
},
5604 { VK_SCROLL
, WXK_SCROLL
},
5607 { VK_LWIN
, WXK_WINDOWS_LEFT
},
5608 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
5609 { VK_APPS
, WXK_WINDOWS_MENU
},
5610 #endif // VK_APPS defined
5613 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
5614 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
5615 int wxCharCodeMSWToWX(int vk
, WXLPARAM lParam
)
5617 // check the table first
5618 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5620 if ( gs_specialKeys
[n
].vk
== vk
)
5621 return gs_specialKeys
[n
].wxk
;
5624 // keys requiring special handling
5628 // the mapping for these keys may be incorrect on non-US keyboards so
5629 // maybe we shouldn't map them to ASCII values at all
5630 case VK_OEM_1
: wxk
= ';'; break;
5631 case VK_OEM_PLUS
: wxk
= '+'; break;
5632 case VK_OEM_COMMA
: wxk
= ','; break;
5633 case VK_OEM_MINUS
: wxk
= '-'; break;
5634 case VK_OEM_PERIOD
: wxk
= '.'; break;
5635 case VK_OEM_2
: wxk
= '/'; break;
5636 case VK_OEM_3
: wxk
= '~'; break;
5637 case VK_OEM_4
: wxk
= '['; break;
5638 case VK_OEM_5
: wxk
= '\\'; break;
5639 case VK_OEM_6
: wxk
= ']'; break;
5640 case VK_OEM_7
: wxk
= '\''; break;
5642 // handle extended keys
5644 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
5648 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
5652 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
5656 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
5660 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
5664 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
5668 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
5672 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
5676 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
5680 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
5684 // don't use ChooseNormalOrExtended() here as the keys are reversed
5685 // here: numpad enter is the extended one
5686 wxk
= lParam
&& (lParam
& (1 << 24)) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
5696 WXWORD
wxCharCodeWXToMSW(int wxk
, bool *isVirtual
)
5701 // check the table first
5702 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5704 if ( gs_specialKeys
[n
].wxk
== wxk
)
5705 return gs_specialKeys
[n
].vk
;
5708 // and then check for special keys not included in the table
5713 case WXK_NUMPAD_PAGEUP
:
5718 case WXK_NUMPAD_PAGEDOWN
:
5723 case WXK_NUMPAD_END
:
5728 case WXK_NUMPAD_HOME
:
5733 case WXK_NUMPAD_LEFT
:
5743 case WXK_NUMPAD_RIGHT
:
5748 case WXK_NUMPAD_DOWN
:
5753 case WXK_NUMPAD_INSERT
:
5758 case WXK_NUMPAD_DELETE
:
5772 #ifndef SM_SWAPBUTTON
5773 #define SM_SWAPBUTTON 23
5776 // small helper for wxGetKeyState() and wxGetMouseState()
5777 static inline bool wxIsKeyDown(WXWORD vk
)
5782 if (GetSystemMetrics(SM_SWAPBUTTON
)) vk
= VK_RBUTTON
;
5785 if (GetSystemMetrics(SM_SWAPBUTTON
)) vk
= VK_LBUTTON
;
5788 // the low order bit indicates whether the key was pressed since the last
5789 // call and the high order one indicates whether it is down right now and
5790 // we only want that one
5791 return (GetAsyncKeyState(vk
) & (1<<15)) != 0;
5794 bool wxGetKeyState(wxKeyCode key
)
5796 // although this does work under Windows, it is not supported under other
5797 // platforms so don't allow it, you must use wxGetMouseState() instead
5798 wxASSERT_MSG( key
!= VK_LBUTTON
&&
5799 key
!= VK_RBUTTON
&&
5801 wxT("can't use wxGetKeyState() for mouse buttons") );
5803 const WXWORD vk
= wxCharCodeWXToMSW(key
);
5805 // if the requested key is a LED key, return true if the led is pressed
5806 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
5808 // low order bit means LED is highlighted and high order one means the
5809 // key is down; for compatibility with the other ports return true if
5810 // either one is set
5811 return GetKeyState(vk
) != 0;
5816 return wxIsKeyDown(vk
);
5821 wxMouseState
wxGetMouseState()
5825 GetCursorPos( &pt
);
5829 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
5830 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
5831 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
5833 ms
.SetControlDown(wxIsKeyDown(VK_CONTROL
));
5834 ms
.SetShiftDown(wxIsKeyDown(VK_SHIFT
));
5835 ms
.SetAltDown(wxIsKeyDown(VK_MENU
));
5836 // ms.SetMetaDown();
5842 wxWindow
*wxGetActiveWindow()
5844 HWND hWnd
= GetActiveWindow();
5847 return wxFindWinFromHandle((WXHWND
) hWnd
);
5852 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
5854 HWND hwnd
= (HWND
)hWnd
;
5856 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
5857 // by code in msw/radiobox.cpp), for all the others we just search up the
5859 wxWindow
*win
= (wxWindow
*)NULL
;
5862 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5866 // native radiobuttons return DLGC_RADIOBUTTON here and for any
5867 // wxWindow class which overrides WM_GETDLGCODE processing to
5868 // do it as well, win would be already non NULL
5869 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
5871 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
5873 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
5874 #endif // wxUSE_RADIOBOX
5876 // spin control text buddy window should be mapped to spin ctrl
5877 // itself so try it too
5878 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5881 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
5883 #endif // wxUSE_SPINCTRL
5887 while ( hwnd
&& !win
)
5889 // this is a really ugly hack needed to avoid mistakenly returning the
5890 // parent frame wxWindow for the find/replace modeless dialog HWND -
5891 // this, in turn, is needed to call IsDialogMessage() from
5892 // wxApp::ProcessMessage() as for this we must return NULL from here
5894 // FIXME: this is clearly not the best way to do it but I think we'll
5895 // need to change HWND <-> wxWindow code more heavily than I can
5896 // do it now to fix it
5897 #ifndef __WXMICROWIN__
5898 if ( ::GetWindow(hwnd
, GW_OWNER
) )
5900 // it's a dialog box, don't go upwards
5905 hwnd
= ::GetParent(hwnd
);
5906 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5912 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
5914 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
5915 // in active frames and dialogs, regardless of where the focus is.
5916 static HHOOK wxTheKeyboardHook
= 0;
5917 static FARPROC wxTheKeyboardHookProc
= 0;
5918 int APIENTRY _EXPORT
5919 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
5921 void wxSetKeyboardHook(bool doIt
)
5925 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
5926 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
5928 GetCurrentThreadId()
5929 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
5934 UnhookWindowsHookEx(wxTheKeyboardHook
);
5938 int APIENTRY _EXPORT
5939 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
5941 DWORD hiWord
= HIWORD(lParam
);
5942 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
5944 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5947 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
5948 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
5949 event
.m_altDown
= true;
5951 event
.SetEventObject(NULL
);
5952 event
.m_keyCode
= id
;
5953 event
.m_shiftDown
= wxIsShiftDown();
5954 event
.m_controlDown
= wxIsCtrlDown();
5956 event
.SetTimestamp(::GetMessageTime());
5958 wxWindow
*win
= wxGetActiveWindow();
5959 wxEvtHandler
*handler
;
5962 handler
= win
->GetEventHandler();
5963 event
.SetId(win
->GetId());
5968 event
.SetId(wxID_ANY
);
5971 if ( handler
&& handler
->ProcessEvent(event
) )
5979 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
5982 #endif // !__WXMICROWIN__
5985 const wxChar
*wxGetMessageName(int message
)
5989 case 0x0000: return wxT("WM_NULL");
5990 case 0x0001: return wxT("WM_CREATE");
5991 case 0x0002: return wxT("WM_DESTROY");
5992 case 0x0003: return wxT("WM_MOVE");
5993 case 0x0005: return wxT("WM_SIZE");
5994 case 0x0006: return wxT("WM_ACTIVATE");
5995 case 0x0007: return wxT("WM_SETFOCUS");
5996 case 0x0008: return wxT("WM_KILLFOCUS");
5997 case 0x000A: return wxT("WM_ENABLE");
5998 case 0x000B: return wxT("WM_SETREDRAW");
5999 case 0x000C: return wxT("WM_SETTEXT");
6000 case 0x000D: return wxT("WM_GETTEXT");
6001 case 0x000E: return wxT("WM_GETTEXTLENGTH");
6002 case 0x000F: return wxT("WM_PAINT");
6003 case 0x0010: return wxT("WM_CLOSE");
6004 case 0x0011: return wxT("WM_QUERYENDSESSION");
6005 case 0x0012: return wxT("WM_QUIT");
6006 case 0x0013: return wxT("WM_QUERYOPEN");
6007 case 0x0014: return wxT("WM_ERASEBKGND");
6008 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
6009 case 0x0016: return wxT("WM_ENDSESSION");
6010 case 0x0017: return wxT("WM_SYSTEMERROR");
6011 case 0x0018: return wxT("WM_SHOWWINDOW");
6012 case 0x0019: return wxT("WM_CTLCOLOR");
6013 case 0x001A: return wxT("WM_WININICHANGE");
6014 case 0x001B: return wxT("WM_DEVMODECHANGE");
6015 case 0x001C: return wxT("WM_ACTIVATEAPP");
6016 case 0x001D: return wxT("WM_FONTCHANGE");
6017 case 0x001E: return wxT("WM_TIMECHANGE");
6018 case 0x001F: return wxT("WM_CANCELMODE");
6019 case 0x0020: return wxT("WM_SETCURSOR");
6020 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6021 case 0x0022: return wxT("WM_CHILDACTIVATE");
6022 case 0x0023: return wxT("WM_QUEUESYNC");
6023 case 0x0024: return wxT("WM_GETMINMAXINFO");
6024 case 0x0026: return wxT("WM_PAINTICON");
6025 case 0x0027: return wxT("WM_ICONERASEBKGND");
6026 case 0x0028: return wxT("WM_NEXTDLGCTL");
6027 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6028 case 0x002B: return wxT("WM_DRAWITEM");
6029 case 0x002C: return wxT("WM_MEASUREITEM");
6030 case 0x002D: return wxT("WM_DELETEITEM");
6031 case 0x002E: return wxT("WM_VKEYTOITEM");
6032 case 0x002F: return wxT("WM_CHARTOITEM");
6033 case 0x0030: return wxT("WM_SETFONT");
6034 case 0x0031: return wxT("WM_GETFONT");
6035 case 0x0037: return wxT("WM_QUERYDRAGICON");
6036 case 0x0039: return wxT("WM_COMPAREITEM");
6037 case 0x0041: return wxT("WM_COMPACTING");
6038 case 0x0044: return wxT("WM_COMMNOTIFY");
6039 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6040 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6041 case 0x0048: return wxT("WM_POWER");
6043 case 0x004A: return wxT("WM_COPYDATA");
6044 case 0x004B: return wxT("WM_CANCELJOURNAL");
6045 case 0x004E: return wxT("WM_NOTIFY");
6046 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6047 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6048 case 0x0052: return wxT("WM_TCARD");
6049 case 0x0053: return wxT("WM_HELP");
6050 case 0x0054: return wxT("WM_USERCHANGED");
6051 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6052 case 0x007B: return wxT("WM_CONTEXTMENU");
6053 case 0x007C: return wxT("WM_STYLECHANGING");
6054 case 0x007D: return wxT("WM_STYLECHANGED");
6055 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6056 case 0x007F: return wxT("WM_GETICON");
6057 case 0x0080: return wxT("WM_SETICON");
6059 case 0x0081: return wxT("WM_NCCREATE");
6060 case 0x0082: return wxT("WM_NCDESTROY");
6061 case 0x0083: return wxT("WM_NCCALCSIZE");
6062 case 0x0084: return wxT("WM_NCHITTEST");
6063 case 0x0085: return wxT("WM_NCPAINT");
6064 case 0x0086: return wxT("WM_NCACTIVATE");
6065 case 0x0087: return wxT("WM_GETDLGCODE");
6066 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6067 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6068 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6069 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6070 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6071 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6072 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6073 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6074 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6075 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6076 case 0x0100: return wxT("WM_KEYDOWN");
6077 case 0x0101: return wxT("WM_KEYUP");
6078 case 0x0102: return wxT("WM_CHAR");
6079 case 0x0103: return wxT("WM_DEADCHAR");
6080 case 0x0104: return wxT("WM_SYSKEYDOWN");
6081 case 0x0105: return wxT("WM_SYSKEYUP");
6082 case 0x0106: return wxT("WM_SYSCHAR");
6083 case 0x0107: return wxT("WM_SYSDEADCHAR");
6084 case 0x0108: return wxT("WM_KEYLAST");
6086 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6087 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6088 case 0x010F: return wxT("WM_IME_COMPOSITION");
6090 case 0x0110: return wxT("WM_INITDIALOG");
6091 case 0x0111: return wxT("WM_COMMAND");
6092 case 0x0112: return wxT("WM_SYSCOMMAND");
6093 case 0x0113: return wxT("WM_TIMER");
6094 case 0x0114: return wxT("WM_HSCROLL");
6095 case 0x0115: return wxT("WM_VSCROLL");
6096 case 0x0116: return wxT("WM_INITMENU");
6097 case 0x0117: return wxT("WM_INITMENUPOPUP");
6098 case 0x011F: return wxT("WM_MENUSELECT");
6099 case 0x0120: return wxT("WM_MENUCHAR");
6100 case 0x0121: return wxT("WM_ENTERIDLE");
6101 case 0x0200: return wxT("WM_MOUSEMOVE");
6102 case 0x0201: return wxT("WM_LBUTTONDOWN");
6103 case 0x0202: return wxT("WM_LBUTTONUP");
6104 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6105 case 0x0204: return wxT("WM_RBUTTONDOWN");
6106 case 0x0205: return wxT("WM_RBUTTONUP");
6107 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6108 case 0x0207: return wxT("WM_MBUTTONDOWN");
6109 case 0x0208: return wxT("WM_MBUTTONUP");
6110 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6111 case 0x020A: return wxT("WM_MOUSEWHEEL");
6112 case 0x0210: return wxT("WM_PARENTNOTIFY");
6113 case 0x0211: return wxT("WM_ENTERMENULOOP");
6114 case 0x0212: return wxT("WM_EXITMENULOOP");
6116 case 0x0213: return wxT("WM_NEXTMENU");
6117 case 0x0214: return wxT("WM_SIZING");
6118 case 0x0215: return wxT("WM_CAPTURECHANGED");
6119 case 0x0216: return wxT("WM_MOVING");
6120 case 0x0218: return wxT("WM_POWERBROADCAST");
6121 case 0x0219: return wxT("WM_DEVICECHANGE");
6123 case 0x0220: return wxT("WM_MDICREATE");
6124 case 0x0221: return wxT("WM_MDIDESTROY");
6125 case 0x0222: return wxT("WM_MDIACTIVATE");
6126 case 0x0223: return wxT("WM_MDIRESTORE");
6127 case 0x0224: return wxT("WM_MDINEXT");
6128 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6129 case 0x0226: return wxT("WM_MDITILE");
6130 case 0x0227: return wxT("WM_MDICASCADE");
6131 case 0x0228: return wxT("WM_MDIICONARRANGE");
6132 case 0x0229: return wxT("WM_MDIGETACTIVE");
6133 case 0x0230: return wxT("WM_MDISETMENU");
6134 case 0x0233: return wxT("WM_DROPFILES");
6136 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6137 case 0x0282: return wxT("WM_IME_NOTIFY");
6138 case 0x0283: return wxT("WM_IME_CONTROL");
6139 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6140 case 0x0285: return wxT("WM_IME_SELECT");
6141 case 0x0286: return wxT("WM_IME_CHAR");
6142 case 0x0290: return wxT("WM_IME_KEYDOWN");
6143 case 0x0291: return wxT("WM_IME_KEYUP");
6145 case 0x0300: return wxT("WM_CUT");
6146 case 0x0301: return wxT("WM_COPY");
6147 case 0x0302: return wxT("WM_PASTE");
6148 case 0x0303: return wxT("WM_CLEAR");
6149 case 0x0304: return wxT("WM_UNDO");
6150 case 0x0305: return wxT("WM_RENDERFORMAT");
6151 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6152 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6153 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6154 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6155 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6156 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6157 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6158 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6159 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6160 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6161 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6162 case 0x0311: return wxT("WM_PALETTECHANGED");
6164 case 0x0312: return wxT("WM_HOTKEY");
6167 // common controls messages - although they're not strictly speaking
6168 // standard, it's nice to decode them nevertheless
6171 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6172 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6173 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6174 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6175 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6176 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6177 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6178 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6179 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6180 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6181 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6182 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6183 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6184 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6185 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6186 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6187 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6188 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6189 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6190 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6191 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6192 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6193 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6194 case 0x1000 + 18: return wxT("LVM_HITTEST");
6195 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6196 case 0x1000 + 20: return wxT("LVM_SCROLL");
6197 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6198 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6199 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6200 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6201 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6202 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6203 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6204 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6205 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6206 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6207 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6208 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6209 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6210 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6211 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6212 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6213 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6214 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6215 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6216 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6217 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6218 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6219 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6220 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6221 case 0x1000 + 42: return wxT("LVM_UPDATE");
6222 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6223 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6224 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6225 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6226 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6227 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6228 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6229 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6230 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6231 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6232 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6233 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6234 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6235 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6236 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6237 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6238 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6239 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6240 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6241 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6242 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6243 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6244 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6245 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6246 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6247 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6250 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6251 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6252 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6253 case 0x1100 + 2: return wxT("TVM_EXPAND");
6254 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6255 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6256 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6257 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6258 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6259 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6260 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6261 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6262 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6263 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6264 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6265 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6266 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6267 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6268 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6269 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6270 case 0x1100 + 17: return wxT("TVM_HITTEST");
6271 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6272 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6273 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6274 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6275 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6276 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6277 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6278 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6279 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6282 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6283 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6284 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6285 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6286 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6287 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6288 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6289 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6290 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6291 case 0x1200 + 6: return wxT("HDM_HITTEST");
6292 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6293 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6294 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6295 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6296 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6297 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6298 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6299 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6302 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6303 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6304 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6305 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6306 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6307 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6308 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6309 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6310 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6311 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6312 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6313 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6314 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6315 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6316 case 0x1300 + 13: return wxT("TCM_HITTEST");
6317 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6318 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6319 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6320 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6321 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6322 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6323 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6324 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6325 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6326 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6327 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6328 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6331 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6332 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
6333 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
6334 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
6335 case WM_USER
+5: return wxT("TB_INDETERMINATE");
6336 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
6337 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
6338 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
6339 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
6340 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
6341 case WM_USER
+17: return wxT("TB_SETSTATE");
6342 case WM_USER
+18: return wxT("TB_GETSTATE");
6343 case WM_USER
+19: return wxT("TB_ADDBITMAP");
6344 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
6345 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
6346 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
6347 case WM_USER
+23: return wxT("TB_GETBUTTON");
6348 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
6349 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
6350 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
6351 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
6352 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
6353 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
6354 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
6355 case WM_USER
+29: return wxT("TB_GETITEMRECT");
6356 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
6357 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
6358 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
6359 case WM_USER
+33: return wxT("TB_AUTOSIZE");
6360 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
6361 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
6362 case WM_USER
+37: return wxT("TB_SETPARENT");
6363 case WM_USER
+39: return wxT("TB_SETROWS");
6364 case WM_USER
+40: return wxT("TB_GETROWS");
6365 case WM_USER
+42: return wxT("TB_SETCMDID");
6366 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
6367 case WM_USER
+44: return wxT("TB_GETBITMAP");
6368 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
6369 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
6370 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
6371 case WM_USER
+47: return wxT("TB_SETINDENT");
6372 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
6373 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
6374 case WM_USER
+50: return wxT("TB_LOADIMAGES");
6375 case WM_USER
+51: return wxT("TB_GETRECT");
6376 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
6377 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
6378 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
6379 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
6380 case WM_USER
+56: return wxT("TB_SETSTYLE");
6381 case WM_USER
+57: return wxT("TB_GETSTYLE");
6382 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
6383 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
6384 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
6385 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
6386 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
6389 static wxString s_szBuf
;
6390 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
6391 return s_szBuf
.c_str();
6394 #endif //__WXDEBUG__
6396 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
6400 HWND hwnd
= GetHwndOf(win
);
6401 HDC hdc
= ::GetDC(hwnd
);
6403 #if !wxDIALOG_UNIT_COMPATIBILITY
6404 // and select the current font into it
6405 HFONT hfont
= GetHfontOf(win
->GetFont());
6408 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
6412 // finally retrieve the text metrics from it
6413 GetTextMetrics(hdc
, &tm
);
6415 #if !wxDIALOG_UNIT_COMPATIBILITY
6419 (void)::SelectObject(hdc
, hfont
);
6423 ::ReleaseDC(hwnd
, hdc
);
6428 // Find the wxWindow at the current mouse position, returning the mouse
6430 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
6432 pt
= wxGetMousePosition();
6433 return wxFindWindowAtPoint(pt
);
6436 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
6442 HWND hWnd
= ::WindowFromPoint(pt2
);
6444 return wxGetWindowFromHWND((WXHWND
)hWnd
);
6447 // Get the current mouse position.
6448 wxPoint
wxGetMousePosition()
6452 GetCursorPosWinCE(&pt
);
6454 GetCursorPos( & pt
);
6457 return wxPoint(pt
.x
, pt
.y
);
6462 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6463 static void WinCEUnregisterHotKey(int modifiers
, int id
)
6465 // Register hotkeys for the hardware buttons
6467 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
6469 UnregisterFunc1Proc procUnregisterFunc
;
6470 hCoreDll
= LoadLibrary(_T("coredll.dll"));
6473 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, _T("UnregisterFunc1"));
6474 if (procUnregisterFunc
)
6475 procUnregisterFunc(modifiers
, id
);
6476 FreeLibrary(hCoreDll
);
6481 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
6483 UINT win_modifiers
=0;
6484 if ( modifiers
& wxMOD_ALT
)
6485 win_modifiers
|= MOD_ALT
;
6486 if ( modifiers
& wxMOD_SHIFT
)
6487 win_modifiers
|= MOD_SHIFT
;
6488 if ( modifiers
& wxMOD_CONTROL
)
6489 win_modifiers
|= MOD_CONTROL
;
6490 if ( modifiers
& wxMOD_WIN
)
6491 win_modifiers
|= MOD_WIN
;
6493 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6494 // Required for PPC and Smartphone hardware buttons
6495 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
6496 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
6499 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
6501 wxLogLastError(_T("RegisterHotKey"));
6509 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
6511 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6512 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
6515 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
6517 wxLogLastError(_T("UnregisterHotKey"));
6527 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
6529 int hotkeyId
= wParam
;
6530 int virtualKey
= HIWORD(lParam
);
6531 int win_modifiers
= LOWORD(lParam
);
6533 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
6534 event
.SetId(hotkeyId
);
6535 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
6536 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
6537 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
6538 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
6540 return GetEventHandler()->ProcessEvent(event
);
6543 #endif // wxUSE_ACCEL
6545 #endif // wxUSE_HOTKEY
6547 // Not tested under WinCE
6550 // this class installs a message hook which really wakes up our idle processing
6551 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
6552 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
6553 // being dragged or even inside ::MessageBox()) and so don't control message
6554 // dispatching otherwise
6555 class wxIdleWakeUpModule
: public wxModule
6558 virtual bool OnInit()
6560 ms_hMsgHookProc
= ::SetWindowsHookEx
6563 &wxIdleWakeUpModule::MsgHookProc
,
6565 GetCurrentThreadId()
6568 if ( !ms_hMsgHookProc
)
6570 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
6578 virtual void OnExit()
6580 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
6583 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
6585 MSG
*msg
= (MSG
*)lParam
;
6587 // only process the message if it is actually going to be removed from
6588 // the message queue, this prevents that the same event from being
6589 // processed multiple times if now someone just called PeekMessage()
6590 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
6592 wxTheApp
->ProcessPendingEvents();
6595 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
6599 static HHOOK ms_hMsgHookProc
;
6601 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
6604 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
6606 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
6608 #endif // __WXWINCE__
6613 static void wxAdjustZOrder(wxWindow
* parent
)
6615 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
6617 // Set the z-order correctly
6618 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
6621 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
6624 wxWindow
*childWin
= current
->GetData();
6625 wxAdjustZOrder(childWin
);
6626 current
= current
->GetNext();
6631 // We need to adjust the z-order of static boxes in WinCE, to
6632 // make 'contained' controls visible
6633 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
6636 wxAdjustZOrder(this);