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 // we shouldn't really enable the window if our parent is currently
654 // disabled because under MSW this would indeed show the window in enabled
655 // state but it still wouldn't respond to the input (as its parent is
656 // disabled), so just update the internal m_childrenDisabled list in this
657 // case and our state will be really changed when the parent is enabled
659 // the logic above doesn't apply to top level windows, of course
660 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
661 if ( parent
&& !parent
->IsEnabled() && !IsEnabled() )
663 // it's a reference as we can create it below
664 wxWindowList
*& disabledSiblings
= parent
->m_childrenDisabled
;
669 // shouldn't be disabled when the parent is reenabled
670 if ( disabledSiblings
)
672 wxWindowList::compatibility_iterator
673 i
= disabledSiblings
->Find(this);
676 disabledSiblings
->Erase(i
);
680 //else: nothing to do
684 // should disable this window when the parent is enabled
685 if ( !disabledSiblings
)
686 disabledSiblings
= new wxWindowList
;
688 disabledSiblings
->Append(this);
694 if ( !wxWindowBase::Enable(enable
) )
697 HWND hWnd
= GetHwnd();
699 ::EnableWindow(hWnd
, (BOOL
)enable
);
701 // the logic below doesn't apply to the top level windows -- otherwise
702 // showing a modal dialog would result in total greying out (and ungreying
703 // out later) of everything which would be really ugly
707 // when the parent is disabled, all of its children should be disabled as
708 // well but when it is enabled back, only those of the children which
709 // hadn't been already disabled in the beginning should be enabled again,
710 // so we have to keep the list of those children
711 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
713 node
= node
->GetNext() )
715 wxWindow
*child
= node
->GetData();
716 if ( child
->IsTopLevel() )
718 // the logic below doesn't apply to top level children
724 // re-enable the child unless it had been disabled before us
725 if ( !m_childrenDisabled
|| !m_childrenDisabled
->Find(child
) )
728 else // we're being disabled
730 if ( child
->IsEnabled() )
732 // disable it as children shouldn't stay enabled while the
736 else // child already disabled, remember it
738 // have we created the list of disabled children already?
739 if ( !m_childrenDisabled
)
740 m_childrenDisabled
= new wxWindowList
;
742 m_childrenDisabled
->Append(child
);
747 if ( enable
&& m_childrenDisabled
)
749 // we don't need this list any more, don't keep unused memory
750 delete m_childrenDisabled
;
751 m_childrenDisabled
= NULL
;
757 bool wxWindowMSW::Show(bool show
)
759 if ( !wxWindowBase::Show(show
) )
762 HWND hWnd
= GetHwnd();
764 // we could be called before the underlying window is created (this is
765 // actually useful to prevent it from being initially shown), e.g.
767 // wxFoo *foo = new wxFoo;
769 // foo->Create(parent, ...);
771 // should work without errors
774 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
780 // Raise the window to the top of the Z order
781 void wxWindowMSW::Raise()
783 wxBringWindowToTop(GetHwnd());
786 // Lower the window to the bottom of the Z order
787 void wxWindowMSW::Lower()
789 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
790 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
793 void wxWindowMSW::DoCaptureMouse()
795 HWND hWnd
= GetHwnd();
802 void wxWindowMSW::DoReleaseMouse()
804 if ( !::ReleaseCapture() )
806 wxLogLastError(_T("ReleaseCapture"));
810 /* static */ wxWindow
*wxWindowBase::GetCapture()
812 HWND hwnd
= ::GetCapture();
813 return hwnd
? wxFindWinFromHandle((WXHWND
)hwnd
) : (wxWindow
*)NULL
;
816 bool wxWindowMSW::SetFont(const wxFont
& font
)
818 if ( !wxWindowBase::SetFont(font
) )
824 HWND hWnd
= GetHwnd();
827 WXHANDLE hFont
= m_font
.GetResourceHandle();
829 wxASSERT_MSG( hFont
, wxT("should have valid font") );
831 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
836 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
838 if ( !wxWindowBase::SetCursor(cursor
) )
844 // don't "overwrite" busy cursor
845 if ( m_cursor
.Ok() && !wxIsBusy() )
847 // normally we should change the cursor only if it's over this window
848 // but we should do it always if we capture the mouse currently
849 bool set
= HasCapture();
852 HWND hWnd
= GetHwnd();
856 ::GetCursorPosWinCE(&point
);
858 ::GetCursorPos(&point
);
861 RECT rect
= wxGetWindowRect(hWnd
);
863 set
= ::PtInRect(&rect
, point
) != 0;
868 ::SetCursor(GetHcursorOf(m_cursor
));
870 //else: will be set later when the mouse enters this window
876 void wxWindowMSW::WarpPointer(int x
, int y
)
878 ClientToScreen(&x
, &y
);
880 if ( !::SetCursorPos(x
, y
) )
882 wxLogLastError(_T("SetCursorPos"));
886 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
888 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
889 // to use it on older systems -- and could possibly do some harm
890 static int s_needToUpdate
= -1;
891 if ( s_needToUpdate
== -1 )
894 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
898 if ( s_needToUpdate
)
900 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
901 // won't send WM_UPDATEUISTATE
902 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
906 // ---------------------------------------------------------------------------
908 // ---------------------------------------------------------------------------
910 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
912 #ifdef __WXMICROWIN__
913 return ::GetScrollPosWX(hWnd
, wOrient
);
915 WinStruct
<SCROLLINFO
> scrollInfo
;
916 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
917 scrollInfo
.fMask
= SIF_POS
;
918 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
920 return scrollInfo
.nPos
;
925 int wxWindowMSW::GetScrollPos(int orient
) const
927 HWND hWnd
= GetHwnd();
928 wxCHECK_MSG( hWnd
, 0, _T("no HWND in GetScrollPos") );
930 return GetScrollPosition(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
);
933 // This now returns the whole range, not just the number
934 // of positions that we can scroll.
935 int wxWindowMSW::GetScrollRange(int orient
) const
938 HWND hWnd
= GetHwnd();
942 ::GetScrollRange(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
945 WinStruct
<SCROLLINFO
> scrollInfo
;
946 scrollInfo
.fMask
= SIF_RANGE
;
947 if ( !::GetScrollInfo(hWnd
,
948 orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
951 // Most of the time this is not really an error, since the return
952 // value can also be zero when there is no scrollbar yet.
953 // wxLogLastError(_T("GetScrollInfo"));
955 maxPos
= scrollInfo
.nMax
;
957 // undo "range - 1" done in SetScrollbar()
961 int wxWindowMSW::GetScrollThumb(int orient
) const
963 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
966 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
968 HWND hWnd
= GetHwnd();
969 wxCHECK_RET( hWnd
, _T("SetScrollPos: no HWND") );
971 WinStruct
<SCROLLINFO
> info
;
975 info
.fMask
= SIF_POS
;
976 if ( HasFlag(wxALWAYS_SHOW_SB
) )
978 // disable scrollbar instead of removing it then
979 info
.fMask
|= SIF_DISABLENOSCROLL
;
982 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
986 // New function that will replace some of the above.
987 void wxWindowMSW::SetScrollbar(int orient
,
993 WinStruct
<SCROLLINFO
> info
;
994 info
.nPage
= pageSize
;
995 info
.nMin
= 0; // range is nMax - nMin + 1
996 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
998 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
999 if ( HasFlag(wxALWAYS_SHOW_SB
) )
1001 // disable scrollbar instead of removing it then
1002 info
.fMask
|= SIF_DISABLENOSCROLL
;
1005 HWND hWnd
= GetHwnd();
1008 // We have to set the variables here to make them valid in events
1009 // triggered by ::SetScrollInfo()
1010 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
1012 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
1017 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
1023 rect
.left
= prect
->x
;
1024 rect
.top
= prect
->y
;
1025 rect
.right
= prect
->x
+ prect
->width
;
1026 rect
.bottom
= prect
->y
+ prect
->height
;
1036 // FIXME: is this the exact equivalent of the line below?
1037 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
1039 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
1043 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
1045 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
1048 for ( int n
= 0; n
< count
; n
++ )
1050 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
1052 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
1053 if ( posNew
== pos
)
1055 // don't bother to continue, we're already at top/bottom
1062 return pos
!= posStart
;
1065 bool wxWindowMSW::ScrollLines(int lines
)
1067 bool down
= lines
> 0;
1069 return ScrollVertically(GetHwnd(),
1070 down
? SB_LINEDOWN
: SB_LINEUP
,
1071 down
? lines
: -lines
);
1074 bool wxWindowMSW::ScrollPages(int pages
)
1076 bool down
= pages
> 0;
1078 return ScrollVertically(GetHwnd(),
1079 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1080 down
? pages
: -pages
);
1083 // ----------------------------------------------------------------------------
1085 // ----------------------------------------------------------------------------
1087 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
1092 const HWND hwnd
= GetHwnd();
1093 wxCHECK_RET( hwnd
, _T("layout direction must be set after window creation") );
1095 LONG styleOld
= ::GetWindowLong(hwnd
, GWL_EXSTYLE
);
1097 LONG styleNew
= styleOld
;
1100 case wxLayout_LeftToRight
:
1101 styleNew
&= ~WS_EX_LAYOUTRTL
;
1104 case wxLayout_RightToLeft
:
1105 styleNew
|= WS_EX_LAYOUTRTL
;
1109 wxFAIL_MSG(_T("unsupported layout direction"));
1113 if ( styleNew
!= styleOld
)
1115 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, styleNew
);
1120 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1123 return wxLayout_Default
;
1125 const HWND hwnd
= GetHwnd();
1126 wxCHECK_MSG( hwnd
, wxLayout_Default
, _T("invalid window") );
1128 return ::GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
1129 ? wxLayout_RightToLeft
1130 : wxLayout_LeftToRight
;
1135 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1136 wxCoord
WXUNUSED(width
),
1137 wxCoord
WXUNUSED(widthTotal
)) const
1139 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1140 // redo it ourselves
1144 // ---------------------------------------------------------------------------
1146 // ---------------------------------------------------------------------------
1148 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1150 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1152 HWND hwnd
= (HWND
)hWnd
;
1153 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1155 wxAssociateWinWithHandle(hwnd
, this);
1157 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1159 // we don't need to subclass the window of our own class (in the Windows
1160 // sense of the word)
1161 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1163 wxSetWindowProc(hwnd
, wxWndProc
);
1167 // don't bother restoring it either: this also makes it easy to
1168 // implement IsOfStandardClass() method which returns true for the
1169 // standard controls and false for the wxWidgets own windows as it can
1170 // simply check m_oldWndProc
1171 m_oldWndProc
= NULL
;
1174 // we're officially created now, send the event
1175 wxWindowCreateEvent
event((wxWindow
*)this);
1176 (void)GetEventHandler()->ProcessEvent(event
);
1179 void wxWindowMSW::UnsubclassWin()
1181 wxRemoveHandleAssociation(this);
1183 // Restore old Window proc
1184 HWND hwnd
= GetHwnd();
1189 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1193 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1195 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1198 m_oldWndProc
= NULL
;
1203 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1207 if ( !::DestroyWindow(GetHwnd()) )
1208 wxLogLastError(wxT("DestroyWindow"));
1211 WXHWND wxhwnd
= (WXHWND
)handle
;
1214 SubclassWin(wxhwnd
);
1217 void wxWindowMSW::DissociateHandle()
1219 // this also calls SetHWND(0) for us
1224 bool wxCheckWindowWndProc(WXHWND hWnd
,
1225 WXFARPROC
WXUNUSED(wndProc
))
1227 // TODO: This list of window class names should be factored out so they can be
1228 // managed in one place and then accessed from here and other places, such as
1229 // wxApp::RegisterWindowClasses() and wxApp::UnregisterWindowClasses()
1232 extern wxChar
*wxCanvasClassName
;
1233 extern wxChar
*wxCanvasClassNameNR
;
1235 extern const wxChar
*wxCanvasClassName
;
1236 extern const wxChar
*wxCanvasClassNameNR
;
1238 extern const wxChar
*wxMDIFrameClassName
;
1239 extern const wxChar
*wxMDIFrameClassNameNoRedraw
;
1240 extern const wxChar
*wxMDIChildFrameClassName
;
1241 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
1242 wxString
str(wxGetWindowClass(hWnd
));
1243 if (str
== wxCanvasClassName
||
1244 str
== wxCanvasClassNameNR
||
1246 str
== _T("wxGLCanvasClass") ||
1247 str
== _T("wxGLCanvasClassNR") ||
1248 #endif // wxUSE_GLCANVAS
1249 str
== wxMDIFrameClassName
||
1250 str
== wxMDIFrameClassNameNoRedraw
||
1251 str
== wxMDIChildFrameClassName
||
1252 str
== wxMDIChildFrameClassNameNoRedraw
||
1253 str
== _T("wxTLWHiddenParent"))
1254 return true; // Effectively means don't subclass
1259 // ----------------------------------------------------------------------------
1261 // ----------------------------------------------------------------------------
1263 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1265 long flagsOld
= GetWindowStyleFlag();
1266 if ( flags
== flagsOld
)
1269 // update the internal variable
1270 wxWindowBase::SetWindowStyleFlag(flags
);
1272 // and the real window flags
1273 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1276 void wxWindowMSW::SetExtraStyle(long exflags
)
1278 long exflagsOld
= GetExtraStyle();
1279 if ( exflags
== exflagsOld
)
1282 // update the internal variable
1283 wxWindowBase::SetExtraStyle(exflags
);
1285 // and the real window flags
1286 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1289 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1291 // now update the Windows style as well if needed - and if the window had
1292 // been already created
1296 // we may need to call SetWindowPos() when we change some styles
1297 bool callSWP
= false;
1300 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1302 // this is quite a horrible hack but we need it because MSWGetStyle()
1303 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1304 // and so we have to modify the window exflags temporarily to get the
1305 // correct exstyleOld
1306 long exflagsNew
= GetExtraStyle();
1307 wxWindowBase::SetExtraStyle(exflagsOld
);
1310 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1312 wxWindowBase::SetExtraStyle(exflagsNew
);
1315 if ( style
!= styleOld
)
1317 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1318 // this function so instead of simply setting the style to the new
1319 // value we clear the bits which were set in styleOld but are set in
1320 // the new one and set the ones which were not set before
1321 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1322 styleReal
&= ~styleOld
;
1325 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1327 // we need to call SetWindowPos() if any of the styles affecting the
1328 // frame appearance have changed
1329 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1338 // and the extended style
1339 long exstyleReal
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1341 if ( exstyle
!= exstyleOld
)
1343 exstyleReal
&= ~exstyleOld
;
1344 exstyleReal
|= exstyle
;
1346 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyleReal
);
1348 // ex style changes don't take effect without calling SetWindowPos
1354 // we must call SetWindowPos() to flush the cached extended style and
1355 // also to make the change to wxSTAY_ON_TOP style take effect: just
1356 // setting the style simply doesn't work
1357 if ( !::SetWindowPos(GetHwnd(),
1358 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1361 SWP_NOMOVE
| SWP_NOSIZE
| SWP_FRAMECHANGED
) )
1363 wxLogLastError(_T("SetWindowPos"));
1368 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1370 // translate common wxWidgets styles to Windows ones
1372 // most of windows are child ones, those which are not (such as
1373 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1374 WXDWORD style
= WS_CHILD
;
1376 // using this flag results in very significant reduction in flicker,
1377 // especially with controls inside the static boxes (as the interior of the
1378 // box is not redrawn twice), but sometimes results in redraw problems, so
1379 // optionally allow the old code to continue to use it provided a special
1380 // system option is turned on
1381 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1382 || (flags
& wxCLIP_CHILDREN
) )
1383 style
|= WS_CLIPCHILDREN
;
1385 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1386 // don't support overlapping windows and it only makes sense for them and,
1387 // presumably, gives the system some extra work (to manage more clipping
1388 // regions), so avoid it alltogether
1391 if ( flags
& wxVSCROLL
)
1392 style
|= WS_VSCROLL
;
1394 if ( flags
& wxHSCROLL
)
1395 style
|= WS_HSCROLL
;
1397 const wxBorder border
= GetBorder(flags
);
1399 // WS_BORDER is only required for wxBORDER_SIMPLE
1400 if ( border
== wxBORDER_SIMPLE
)
1403 // now deal with ext style if the caller wants it
1409 if ( flags
& wxTRANSPARENT_WINDOW
)
1410 *exstyle
|= WS_EX_TRANSPARENT
;
1416 case wxBORDER_DEFAULT
:
1417 wxFAIL_MSG( _T("unknown border style") );
1421 case wxBORDER_SIMPLE
:
1424 case wxBORDER_STATIC
:
1425 *exstyle
|= WS_EX_STATICEDGE
;
1428 case wxBORDER_RAISED
:
1429 *exstyle
|= WS_EX_DLGMODALFRAME
;
1432 case wxBORDER_SUNKEN
:
1433 *exstyle
|= WS_EX_CLIENTEDGE
;
1434 style
&= ~WS_BORDER
;
1437 case wxBORDER_DOUBLE
:
1438 *exstyle
|= WS_EX_DLGMODALFRAME
;
1442 // wxUniv doesn't use Windows dialog navigation functions at all
1443 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1444 // to make the dialog navigation work with the nested panels we must
1445 // use this style (top level windows such as dialogs don't need it)
1446 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1448 *exstyle
|= WS_EX_CONTROLPARENT
;
1450 #endif // __WXUNIVERSAL__
1456 // Setup background and foreground colours correctly
1457 void wxWindowMSW::SetupColours()
1460 SetBackgroundColour(GetParent()->GetBackgroundColour());
1463 bool wxWindowMSW::IsMouseInWindow() const
1465 // get the mouse position
1468 ::GetCursorPosWinCE(&pt
);
1470 ::GetCursorPos(&pt
);
1473 // find the window which currently has the cursor and go up the window
1474 // chain until we find this window - or exhaust it
1475 HWND hwnd
= ::WindowFromPoint(pt
);
1476 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1477 hwnd
= ::GetParent(hwnd
);
1479 return hwnd
!= NULL
;
1482 void wxWindowMSW::OnInternalIdle()
1484 #ifndef HAVE_TRACKMOUSEEVENT
1485 // Check if we need to send a LEAVE event
1486 if ( m_mouseInWindow
)
1488 // note that we should generate the leave event whether the window has
1489 // or doesn't have mouse capture
1490 if ( !IsMouseInWindow() )
1492 GenerateMouseLeave();
1495 #endif // !HAVE_TRACKMOUSEEVENT
1497 if (wxUpdateUIEvent::CanUpdate(this))
1498 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1501 // Set this window to be the child of 'parent'.
1502 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1504 if ( !wxWindowBase::Reparent(parent
) )
1507 HWND hWndChild
= GetHwnd();
1508 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1510 ::SetParent(hWndChild
, hWndParent
);
1513 if ( ::GetWindowLong(hWndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1515 EnsureParentHasControlParentStyle(GetParent());
1517 #endif // !__WXWINCE__
1522 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1524 #ifndef __WXMICROWIN__
1525 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1529 void wxWindowMSW::Freeze()
1531 if ( !m_frozenness
++ )
1534 SendSetRedraw(GetHwnd(), false);
1538 void wxWindowMSW::Thaw()
1540 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1542 if ( --m_frozenness
== 0 )
1546 SendSetRedraw(GetHwnd(), true);
1548 // we need to refresh everything or otherwise the invalidated area
1549 // is not going to be repainted
1555 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1557 HWND hWnd
= GetHwnd();
1564 mswRect
.left
= rect
->x
;
1565 mswRect
.top
= rect
->y
;
1566 mswRect
.right
= rect
->x
+ rect
->width
;
1567 mswRect
.bottom
= rect
->y
+ rect
->height
;
1576 // RedrawWindow not available on SmartPhone or eVC++ 3
1577 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1578 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1582 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1584 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1589 void wxWindowMSW::Update()
1591 if ( !::UpdateWindow(GetHwnd()) )
1593 wxLogLastError(_T("UpdateWindow"));
1596 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1597 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1598 // handler needs to be really drawn right now
1603 // ---------------------------------------------------------------------------
1605 // ---------------------------------------------------------------------------
1607 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1611 // we need to lower the sibling static boxes so controls contained within can be
1613 static void AdjustStaticBoxZOrder(wxWindow
*parent
)
1615 // no sibling static boxes if we have no parent (ie TLW)
1619 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1621 node
= node
->GetNext() )
1623 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1626 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1627 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1632 #else // !wxUSE_STATBOX
1634 static inline void AdjustStaticBoxZOrder(wxWindow
* WXUNUSED(parent
))
1638 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1640 #endif // drag and drop is used
1642 #if wxUSE_DRAG_AND_DROP
1643 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1645 if ( m_dropTarget
!= 0 ) {
1646 m_dropTarget
->Revoke(m_hWnd
);
1647 delete m_dropTarget
;
1650 m_dropTarget
= pDropTarget
;
1651 if ( m_dropTarget
!= 0 )
1653 AdjustStaticBoxZOrder(GetParent());
1654 m_dropTarget
->Register(m_hWnd
);
1657 #endif // wxUSE_DRAG_AND_DROP
1659 // old-style file manager drag&drop support: we retain the old-style
1660 // DragAcceptFiles in parallel with SetDropTarget.
1661 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1664 HWND hWnd
= GetHwnd();
1667 AdjustStaticBoxZOrder(GetParent());
1668 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1673 // ----------------------------------------------------------------------------
1675 // ----------------------------------------------------------------------------
1679 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1681 wxWindowBase::DoSetToolTip(tooltip
);
1684 m_tooltip
->SetWindow((wxWindow
*)this);
1687 #endif // wxUSE_TOOLTIPS
1689 // ---------------------------------------------------------------------------
1690 // moving and resizing
1691 // ---------------------------------------------------------------------------
1693 bool wxWindowMSW::IsSizeDeferred() const
1695 #if USE_DEFERRED_SIZING
1696 if ( m_pendingPosition
!= wxDefaultPosition
||
1697 m_pendingSize
!= wxDefaultSize
)
1699 #endif // USE_DEFERRED_SIZING
1705 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1707 #if USE_DEFERRED_SIZING
1708 // if SetSize() had been called at wx level but not realized at Windows
1709 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1710 // the new and not the old position to the other wx code
1711 if ( m_pendingSize
!= wxDefaultSize
)
1714 *x
= m_pendingSize
.x
;
1716 *y
= m_pendingSize
.y
;
1718 else // use current size
1719 #endif // USE_DEFERRED_SIZING
1721 RECT rect
= wxGetWindowRect(GetHwnd());
1724 *x
= rect
.right
- rect
.left
;
1726 *y
= rect
.bottom
- rect
.top
;
1730 // Get size *available for subwindows* i.e. excluding menu bar etc.
1731 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1733 #if USE_DEFERRED_SIZING
1734 if ( m_pendingSize
!= wxDefaultSize
)
1736 // we need to calculate the client size corresponding to pending size
1738 rect
.left
= m_pendingPosition
.x
;
1739 rect
.top
= m_pendingPosition
.y
;
1740 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1741 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1743 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1746 *x
= rect
.right
- rect
.left
;
1748 *y
= rect
.bottom
- rect
.top
;
1751 #endif // USE_DEFERRED_SIZING
1753 RECT rect
= wxGetClientRect(GetHwnd());
1762 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1764 wxWindow
* const parent
= GetParent();
1767 if ( m_pendingPosition
!= wxDefaultPosition
)
1769 pos
= m_pendingPosition
;
1771 else // use current position
1773 RECT rect
= wxGetWindowRect(GetHwnd());
1776 point
.x
= rect
.left
;
1779 // we do the adjustments with respect to the parent only for the "real"
1780 // children, not for the dialogs/frames
1781 if ( !IsTopLevel() )
1783 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
1785 // In RTL mode, we want the logical left x-coordinate,
1786 // which would be the physical right x-coordinate.
1787 point
.x
= rect
.right
;
1790 // Since we now have the absolute screen coords, if there's a
1791 // parent we must subtract its top left corner
1794 ::ScreenToClient(GetHwndOf(parent
), &point
);
1802 // we also must adjust by the client area offset: a control which is just
1803 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1804 if ( parent
&& !IsTopLevel() )
1806 const wxPoint
pt(parent
->GetClientAreaOrigin());
1817 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1825 ::ScreenToClient(GetHwnd(), &pt
);
1833 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1841 ::ClientToScreen(GetHwnd(), &pt
);
1850 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1852 #if USE_DEFERRED_SIZING
1853 // if our parent had prepared a defer window handle for us, use it (unless
1854 // we are a top level window)
1855 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1857 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1860 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1861 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1864 wxLogLastError(_T("DeferWindowPos"));
1870 // hdwp must be updated as it may have been changed
1871 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1876 // did deferred move, remember new coordinates of the window as they're
1877 // different from what Windows would return for it
1881 // otherwise (or if deferring failed) move the window in place immediately
1882 #endif // USE_DEFERRED_SIZING
1883 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
1885 wxLogLastError(wxT("MoveWindow"));
1888 // if USE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1889 // ignored otherwise
1893 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1895 // TODO: is this consistent with other platforms?
1896 // Still, negative width or height shouldn't be allowed
1902 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
1904 #if USE_DEFERRED_SIZING
1905 m_pendingPosition
= wxPoint(x
, y
);
1906 m_pendingSize
= wxSize(width
, height
);
1907 #endif // USE_DEFERRED_SIZING
1911 // set the size of the window: if the dimensions are positive, just use them,
1912 // but if any of them is equal to -1, it means that we must find the value for
1913 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1914 // which case -1 is a valid value for x and y)
1916 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1917 // the width/height to best suit our contents, otherwise we reuse the current
1919 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1921 // get the current size and position...
1922 int currentX
, currentY
;
1923 int currentW
, currentH
;
1925 GetPosition(¤tX
, ¤tY
);
1926 GetSize(¤tW
, ¤tH
);
1928 // ... and don't do anything (avoiding flicker) if it's already ok unless
1929 // we're forced to resize the window
1930 if ( x
== currentX
&& y
== currentY
&&
1931 width
== currentW
&& height
== currentH
&&
1932 !(sizeFlags
& wxSIZE_FORCE
) )
1937 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1939 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1942 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1944 wxSize size
= wxDefaultSize
;
1945 if ( width
== wxDefaultCoord
)
1947 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1949 size
= DoGetBestSize();
1954 // just take the current one
1959 if ( height
== wxDefaultCoord
)
1961 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1963 if ( size
.x
== wxDefaultCoord
)
1965 size
= DoGetBestSize();
1967 //else: already called DoGetBestSize() above
1973 // just take the current one
1978 DoMoveWindow(x
, y
, width
, height
);
1981 void wxWindowMSW::DoSetClientSize(int width
, int height
)
1983 // setting the client size is less obvious than it could have been
1984 // because in the result of changing the total size the window scrollbar
1985 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
1986 // doesn't take neither into account) and so the client size will not be
1987 // correct as the difference between the total and client size changes --
1988 // so we keep changing it until we get it right
1990 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1991 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1992 // may become 3 if the window had 0 size originally and so we didn't
1993 // calculate the scrollbar correction correctly during the first iteration)
1994 // but just to be on the safe side we check for it instead of making it an
1995 // "infinite" loop (i.e. leaving break inside as the only way to get out)
1996 for ( int i
= 0; i
< 4; i
++ )
1999 ::GetClientRect(GetHwnd(), &rectClient
);
2001 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
2002 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
2003 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
2008 // Find the difference between the entire window (title bar and all)
2009 // and the client area; add this to the new client size to move the
2012 ::GetWindowRect(GetHwnd(), &rectWin
);
2014 const int widthWin
= rectWin
.right
- rectWin
.left
,
2015 heightWin
= rectWin
.bottom
- rectWin
.top
;
2017 // MoveWindow positions the child windows relative to the parent, so
2018 // adjust if necessary
2019 if ( !IsTopLevel() )
2021 wxWindow
*parent
= GetParent();
2024 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
2028 // don't call DoMoveWindow() because we want to move window immediately
2029 // and not defer it here as otherwise the value returned by
2030 // GetClient/WindowRect() wouldn't change as the window wouldn't be
2032 if ( !::MoveWindow(GetHwnd(),
2035 width
+ widthWin
- rectClient
.right
,
2036 height
+ heightWin
- rectClient
.bottom
,
2039 wxLogLastError(_T("MoveWindow"));
2044 // ---------------------------------------------------------------------------
2046 // ---------------------------------------------------------------------------
2048 int wxWindowMSW::GetCharHeight() const
2050 return wxGetTextMetrics(this).tmHeight
;
2053 int wxWindowMSW::GetCharWidth() const
2055 // +1 is needed because Windows apparently adds it when calculating the
2056 // dialog units size in pixels
2057 #if wxDIALOG_UNIT_COMPATIBILITY
2058 return wxGetTextMetrics(this).tmAveCharWidth
;
2060 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
2064 void wxWindowMSW::GetTextExtent(const wxString
& string
,
2066 int *descent
, int *externalLeading
,
2067 const wxFont
*theFont
) const
2069 wxASSERT_MSG( !theFont
|| theFont
->Ok(),
2070 _T("invalid font in GetTextExtent()") );
2074 fontToUse
= *theFont
;
2076 fontToUse
= GetFont();
2078 WindowHDC
hdc(GetHwnd());
2079 SelectInHDC
selectFont(hdc
, GetHfontOf(fontToUse
));
2083 ::GetTextExtentPoint32(hdc
, string
, string
.length(), &sizeRect
);
2084 GetTextMetrics(hdc
, &tm
);
2091 *descent
= tm
.tmDescent
;
2092 if ( externalLeading
)
2093 *externalLeading
= tm
.tmExternalLeading
;
2096 // ---------------------------------------------------------------------------
2098 // ---------------------------------------------------------------------------
2100 #if wxUSE_MENUS_NATIVE
2102 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2103 // immediately, without waiting for the next event loop iteration
2105 // NB: this function should probably be made public later as it can almost
2106 // surely replace wxYield() elsewhere as well
2107 static void wxYieldForCommandsOnly()
2109 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2110 // want to process it here)
2112 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2114 if ( msg
.message
== WM_QUIT
)
2116 // if we retrieved a WM_QUIT, insert back into the message queue.
2117 ::PostQuitMessage(0);
2121 // luckily (as we don't have access to wxEventLoopImpl method from here
2122 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2124 ::TranslateMessage(&msg
);
2125 ::DispatchMessage(&msg
);
2129 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2131 menu
->SetInvokingWindow(this);
2134 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2136 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2137 x
= mouse
.x
; y
= mouse
.y
;
2140 HWND hWnd
= GetHwnd();
2141 HMENU hMenu
= GetHmenuOf(menu
);
2145 ::ClientToScreen(hWnd
, &point
);
2146 wxCurrentPopupMenu
= menu
;
2147 #if defined(__WXWINCE__)
2150 UINT flags
= TPM_RIGHTBUTTON
| TPM_RECURSE
;
2152 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2154 // we need to do it right now as otherwise the events are never going to be
2155 // sent to wxCurrentPopupMenu from HandleCommand()
2157 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2158 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2159 // destroyed as soon as we return (it can be a local variable in the caller
2160 // for example) and so we do need to process the event immediately
2161 wxYieldForCommandsOnly();
2163 wxCurrentPopupMenu
= NULL
;
2165 menu
->SetInvokingWindow(NULL
);
2170 #endif // wxUSE_MENUS_NATIVE
2172 // ===========================================================================
2173 // pre/post message processing
2174 // ===========================================================================
2176 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2179 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2181 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2184 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2186 // wxUniversal implements tab traversal itself
2187 #ifndef __WXUNIVERSAL__
2188 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2190 // intercept dialog navigation keys
2191 MSG
*msg
= (MSG
*)pMsg
;
2193 // here we try to do all the job which ::IsDialogMessage() usually does
2195 if ( msg
->message
== WM_KEYDOWN
)
2197 bool bCtrlDown
= wxIsCtrlDown();
2198 bool bShiftDown
= wxIsShiftDown();
2200 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2201 // don't process it if it's the case (except for Ctrl-Tab/Enter
2202 // combinations which are always processed)
2203 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2205 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2206 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2207 // it, of course, implies them
2208 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2210 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2213 bool bForward
= true,
2214 bWindowChange
= false,
2217 // should we process this message specially?
2218 bool bProcess
= true;
2219 switch ( msg
->wParam
)
2222 if ( (lDlgCode
& DLGC_WANTTAB
) && !bCtrlDown
)
2224 // let the control have the TAB
2227 else // use it for navigation
2229 // Ctrl-Tab cycles thru notebook pages
2230 bWindowChange
= bCtrlDown
;
2231 bForward
= !bShiftDown
;
2238 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2246 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2255 // we treat PageUp/Dn as arrows because chances are that
2256 // a control which needs arrows also needs them for
2257 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2258 if ( (lDlgCode
& DLGC_WANTARROWS
) && !bCtrlDown
)
2260 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
2261 bWindowChange
= true;
2266 if ( (lDlgCode
& DLGC_WANTMESSAGE
) && !bCtrlDown
)
2268 // control wants to process Enter itself, don't
2269 // call IsDialogMessage() which would consume it
2274 // currently active button should get enter press even
2275 // if there is a default button elsewhere so check if
2276 // this window is a button first
2277 wxWindow
*btn
= NULL
;
2278 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2280 // let IsDialogMessage() handle this for all
2281 // buttons except the owner-drawn ones which it
2282 // just seems to ignore
2283 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2284 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2286 // emulate the button click
2287 btn
= wxFindWinFromHandle((WXHWND
)msg
->hwnd
);
2292 else // not a button itself, do we have default button?
2295 tlw
= wxDynamicCast(wxGetTopLevelParent(this),
2299 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2304 if ( btn
&& btn
->IsEnabled() )
2306 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2310 #endif // wxUSE_BUTTON
2313 // map Enter presses into button presses on PDAs
2314 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2315 event
.SetEventObject(this);
2316 if ( GetEventHandler()->ProcessEvent(event
) )
2318 #endif // __WXWINCE__
2328 wxNavigationKeyEvent event
;
2329 event
.SetDirection(bForward
);
2330 event
.SetWindowChange(bWindowChange
);
2331 event
.SetFromTab(bFromTab
);
2332 event
.SetEventObject(this);
2334 if ( GetEventHandler()->ProcessEvent(event
) )
2336 // as we don't call IsDialogMessage(), which would take of
2337 // this by default, we need to manually send this message
2338 // so that controls can change their UI state if needed
2339 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2346 if ( ::IsDialogMessage(GetHwnd(), msg
) )
2348 // IsDialogMessage() did something...
2352 #endif // __WXUNIVERSAL__
2357 // relay mouse move events to the tooltip control
2358 MSG
*msg
= (MSG
*)pMsg
;
2359 if ( msg
->message
== WM_MOUSEMOVE
)
2360 wxToolTip::RelayEvent(pMsg
);
2362 #endif // wxUSE_TOOLTIPS
2367 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2369 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2370 return m_acceleratorTable
.Translate(this, pMsg
);
2374 #endif // wxUSE_ACCEL
2377 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* msg
)
2379 // all tests below have to deal with various bugs/misfeatures of
2380 // IsDialogMessage(): we have to prevent it from being called from our
2381 // MSWProcessMessage() in some situations
2383 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2384 // message even when there is no cancel button and when the message is
2385 // needed by the control itself: in particular, it prevents the tree in
2386 // place edit control from being closed with Escape in a dialog
2387 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_ESCAPE
)
2392 // ::IsDialogMessage() is broken and may sometimes hang the application by
2393 // going into an infinite loop when it tries to find the control to give
2394 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2395 // situations when this may happen and not call it then
2396 if ( msg
->message
!= WM_SYSCHAR
)
2399 // assume we can call it by default
2400 bool canSafelyCallIsDlgMsg
= true;
2402 HWND hwndFocus
= ::GetFocus();
2404 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2405 // ::IsDialogMessage() will also enter an infinite loop, because it will
2406 // recursively check the child windows but not the window itself and so if
2407 // none of the children accepts focus it loops forever (as it only stops
2408 // when it gets back to the window it started from)
2410 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2411 // style has the focus, it can happen. One such possibility is if
2412 // all windows are either toplevel, wxDialog, wxPanel or static
2413 // controls and no window can actually accept keyboard input.
2414 #if !defined(__WXWINCE__)
2415 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2417 // pessimistic by default
2418 canSafelyCallIsDlgMsg
= false;
2419 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2421 node
= node
->GetNext() )
2423 wxWindow
* const win
= node
->GetData();
2424 if ( win
->AcceptsFocus() &&
2425 !(::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
) &
2426 WS_EX_CONTROLPARENT
) )
2428 // it shouldn't hang...
2429 canSafelyCallIsDlgMsg
= true;
2435 #endif // !__WXWINCE__
2437 if ( canSafelyCallIsDlgMsg
)
2439 // ::IsDialogMessage() can enter in an infinite loop when the
2440 // currently focused window is disabled or hidden and its
2441 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2445 if ( !::IsWindowEnabled(hwndFocus
) ||
2446 !::IsWindowVisible(hwndFocus
) )
2448 // it would enter an infinite loop if we do this!
2449 canSafelyCallIsDlgMsg
= false;
2454 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2456 // it's a top level window, don't go further -- e.g. even
2457 // if the parent of a dialog is disabled, this doesn't
2458 // break navigation inside the dialog
2462 hwndFocus
= ::GetParent(hwndFocus
);
2466 return canSafelyCallIsDlgMsg
;
2469 // ---------------------------------------------------------------------------
2470 // message params unpackers
2471 // ---------------------------------------------------------------------------
2473 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2474 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2476 *id
= LOWORD(wParam
);
2477 *hwnd
= (WXHWND
)lParam
;
2478 *cmd
= HIWORD(wParam
);
2481 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2482 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2484 *state
= LOWORD(wParam
);
2485 *minimized
= HIWORD(wParam
);
2486 *hwnd
= (WXHWND
)lParam
;
2489 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2490 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2492 *code
= LOWORD(wParam
);
2493 *pos
= HIWORD(wParam
);
2494 *hwnd
= (WXHWND
)lParam
;
2497 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2498 WXHDC
*hdc
, WXHWND
*hwnd
)
2500 *hwnd
= (WXHWND
)lParam
;
2501 *hdc
= (WXHDC
)wParam
;
2504 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2505 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2507 *item
= (WXWORD
)wParam
;
2508 *flags
= HIWORD(wParam
);
2509 *hmenu
= (WXHMENU
)lParam
;
2512 // ---------------------------------------------------------------------------
2513 // Main wxWidgets window proc and the window proc for wxWindow
2514 // ---------------------------------------------------------------------------
2516 // Hook for new window just as it's being created, when the window isn't yet
2517 // associated with the handle
2518 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2520 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2521 // window being created and insures that it's always unset back later
2522 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2524 gs_winBeingCreated
= winBeingCreated
;
2527 wxWindowCreationHook::~wxWindowCreationHook()
2529 gs_winBeingCreated
= NULL
;
2533 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2535 // trace all messages - useful for the debugging
2537 wxLogTrace(wxTraceMessages
,
2538 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2539 wxGetMessageName(message
), (long)hWnd
, (long)wParam
, lParam
);
2540 #endif // __WXDEBUG__
2542 wxWindowMSW
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
2544 // when we get the first message for the HWND we just created, we associate
2545 // it with wxWindow stored in gs_winBeingCreated
2546 if ( !wnd
&& gs_winBeingCreated
)
2548 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2549 wnd
= gs_winBeingCreated
;
2550 gs_winBeingCreated
= NULL
;
2551 wnd
->SetHWND((WXHWND
)hWnd
);
2556 if ( wnd
&& wxEventLoop::AllowProcessing(wnd
) )
2557 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2559 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2564 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2566 // did we process the message?
2567 bool processed
= false;
2577 // for most messages we should return 0 when we do process the message
2585 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2588 // return 0 to allow window creation
2589 rc
.result
= mayCreate
? 0 : -1;
2595 // never set processed to true and *always* pass WM_DESTROY to
2596 // DefWindowProc() as Windows may do some internal cleanup when
2597 // processing it and failing to pass the message along may cause
2598 // memory and resource leaks!
2599 (void)HandleDestroy();
2603 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2607 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2610 #if !defined(__WXWINCE__)
2613 LPRECT pRect
= (LPRECT
)lParam
;
2615 rc
.SetLeft(pRect
->left
);
2616 rc
.SetTop(pRect
->top
);
2617 rc
.SetRight(pRect
->right
);
2618 rc
.SetBottom(pRect
->bottom
);
2619 processed
= HandleMoving(rc
);
2621 pRect
->left
= rc
.GetLeft();
2622 pRect
->top
= rc
.GetTop();
2623 pRect
->right
= rc
.GetRight();
2624 pRect
->bottom
= rc
.GetBottom();
2631 LPRECT pRect
= (LPRECT
)lParam
;
2633 rc
.SetLeft(pRect
->left
);
2634 rc
.SetTop(pRect
->top
);
2635 rc
.SetRight(pRect
->right
);
2636 rc
.SetBottom(pRect
->bottom
);
2637 processed
= HandleSizing(rc
);
2639 pRect
->left
= rc
.GetLeft();
2640 pRect
->top
= rc
.GetTop();
2641 pRect
->right
= rc
.GetRight();
2642 pRect
->bottom
= rc
.GetBottom();
2646 #endif // !__WXWINCE__
2648 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2649 case WM_ACTIVATEAPP
:
2650 // This implicitly sends a wxEVT_ACTIVATE_APP event
2651 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2657 WXWORD state
, minimized
;
2659 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2661 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2666 processed
= HandleSetFocus((WXHWND
)(HWND
)wParam
);
2670 processed
= HandleKillFocus((WXHWND
)(HWND
)wParam
);
2673 case WM_PRINTCLIENT
:
2674 processed
= HandlePrintClient((WXHDC
)wParam
);
2680 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2682 processed
= HandlePaint();
2686 processed
= HandlePaint();
2691 #ifdef __WXUNIVERSAL__
2692 // Universal uses its own wxFrame/wxDialog, so we don't receive
2693 // close events unless we have this.
2695 #endif // __WXUNIVERSAL__
2697 // don't let the DefWindowProc() destroy our window - we'll do it
2698 // ourselves in ~wxWindow
2704 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2708 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2709 GET_Y_LPARAM(lParam
),
2713 #ifdef HAVE_TRACKMOUSEEVENT
2715 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2717 if ( m_mouseInWindow
)
2719 GenerateMouseLeave();
2722 // always pass processed back as false, this allows the window
2723 // manager to process the message too. This is needed to
2724 // ensure windows XP themes work properly as the mouse moves
2725 // over widgets like buttons. So don't set processed to true here.
2727 #endif // HAVE_TRACKMOUSEEVENT
2729 #if wxUSE_MOUSEWHEEL
2731 processed
= HandleMouseWheel(wParam
, lParam
);
2735 case WM_LBUTTONDOWN
:
2737 case WM_LBUTTONDBLCLK
:
2738 case WM_RBUTTONDOWN
:
2740 case WM_RBUTTONDBLCLK
:
2741 case WM_MBUTTONDOWN
:
2743 case WM_MBUTTONDBLCLK
:
2745 #ifdef __WXMICROWIN__
2746 // MicroWindows seems to ignore the fact that a window is
2747 // disabled. So catch mouse events and throw them away if
2749 wxWindowMSW
* win
= this;
2752 if (!win
->IsEnabled())
2758 win
= win
->GetParent();
2759 if ( !win
|| win
->IsTopLevel() )
2766 #endif // __WXMICROWIN__
2767 int x
= GET_X_LPARAM(lParam
),
2768 y
= GET_Y_LPARAM(lParam
);
2771 // redirect the event to a static control if necessary by
2772 // finding one under mouse because under CE the static controls
2773 // don't generate mouse events (even with SS_NOTIFY)
2775 if ( GetCapture() == this )
2777 // but don't do it if the mouse is captured by this window
2778 // because then it should really get this event itself
2783 win
= FindWindowForMouseEvent(this, &x
, &y
);
2785 // this should never happen
2786 wxCHECK_MSG( win
, 0,
2787 _T("FindWindowForMouseEvent() returned NULL") );
2790 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
2792 SHRGINFO shrgi
= {0};
2794 shrgi
.cbSize
= sizeof(SHRGINFO
);
2795 shrgi
.hwndClient
= (HWND
) GetHWND();
2799 shrgi
.dwFlags
= SHRG_RETURNCMD
;
2800 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
2802 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
2805 pt
= ClientToScreen(pt
);
2807 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2809 evtCtx
.SetEventObject(this);
2810 if (GetEventHandler()->ProcessEvent(evtCtx
))
2819 #else // !__WXWINCE__
2820 wxWindowMSW
*win
= this;
2821 #endif // __WXWINCE__/!__WXWINCE__
2823 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2825 // if the app didn't eat the event, handle it in the default
2826 // way, that is by giving this window the focus
2829 // for the standard classes their WndProc sets the focus to
2830 // them anyhow and doing it from here results in some weird
2831 // problems, so don't do it for them (unnecessary anyhow)
2832 if ( !win
->IsOfStandardClass() )
2834 if ( message
== WM_LBUTTONDOWN
&& win
->AcceptsFocus() )
2846 case MM_JOY1BUTTONDOWN
:
2847 case MM_JOY2BUTTONDOWN
:
2848 case MM_JOY1BUTTONUP
:
2849 case MM_JOY2BUTTONUP
:
2850 processed
= HandleJoystickEvent(message
,
2851 GET_X_LPARAM(lParam
),
2852 GET_Y_LPARAM(lParam
),
2855 #endif // __WXMICROWIN__
2861 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2863 processed
= HandleCommand(id
, cmd
, hwnd
);
2868 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2871 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
2872 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
2873 // apparently doesn't always behave properly and needs some help
2874 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
2875 case WM_NOTIFYFORMAT
:
2876 if ( lParam
== NF_QUERY
)
2879 rc
.result
= NFR_UNICODE
;
2882 #endif // wxUSE_UNICODE_MSLU
2884 // for these messages we must return true if process the message
2887 case WM_MEASUREITEM
:
2889 int idCtrl
= (UINT
)wParam
;
2890 if ( message
== WM_DRAWITEM
)
2892 processed
= MSWOnDrawItem(idCtrl
,
2893 (WXDRAWITEMSTRUCT
*)lParam
);
2897 processed
= MSWOnMeasureItem(idCtrl
,
2898 (WXMEASUREITEMSTRUCT
*)lParam
);
2905 #endif // defined(WM_DRAWITEM)
2908 if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS
) )
2910 // we always want to get the char events
2911 rc
.result
= DLGC_WANTCHARS
;
2913 if ( HasFlag(wxWANTS_CHARS
) )
2915 // in fact, we want everything
2916 rc
.result
|= DLGC_WANTARROWS
|
2923 //else: get the dlg code from the DefWindowProc()
2928 // If this has been processed by an event handler, return 0 now
2929 // (we've handled it).
2930 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
2931 if ( m_lastKeydownProcessed
)
2940 // we consider these messages "not interesting" to OnChar, so
2941 // just don't do anything more with them
2951 // avoid duplicate messages to OnChar for these ASCII keys:
2952 // they will be translated by TranslateMessage() and received
2984 // but set processed to false, not true to still pass them
2985 // to the control's default window proc - otherwise
2986 // built-in keyboard handling won't work
2991 // special case of VK_APPS: treat it the same as right mouse
2992 // click because both usually pop up a context menu
2994 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
2999 // do generate a CHAR event
3000 processed
= HandleChar((WORD
)wParam
, lParam
);
3003 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
3010 // special case of VK_APPS: treat it the same as right mouse button
3011 if ( wParam
== VK_APPS
)
3013 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
3018 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
3023 case WM_CHAR
: // Always an ASCII character
3024 if ( m_lastKeydownProcessed
)
3026 // The key was handled in the EVT_KEY_DOWN and handling
3027 // a key in an EVT_KEY_DOWN handler is meant, by
3028 // design, to prevent EVT_CHARs from happening
3029 m_lastKeydownProcessed
= false;
3034 processed
= HandleChar((WORD
)wParam
, lParam
, true);
3040 processed
= HandleHotKey((WORD
)wParam
, lParam
);
3042 #endif // wxUSE_HOTKEY
3049 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
3051 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
3057 // CTLCOLOR messages are sent by children to query the parent for their
3059 #ifndef __WXMICROWIN__
3060 case WM_CTLCOLORMSGBOX
:
3061 case WM_CTLCOLOREDIT
:
3062 case WM_CTLCOLORLISTBOX
:
3063 case WM_CTLCOLORBTN
:
3064 case WM_CTLCOLORDLG
:
3065 case WM_CTLCOLORSCROLLBAR
:
3066 case WM_CTLCOLORSTATIC
:
3070 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
3072 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
3075 #endif // !__WXMICROWIN__
3077 case WM_SYSCOLORCHANGE
:
3078 // the return value for this message is ignored
3079 processed
= HandleSysColorChange();
3082 #if !defined(__WXWINCE__)
3083 case WM_DISPLAYCHANGE
:
3084 processed
= HandleDisplayChange();
3088 case WM_PALETTECHANGED
:
3089 processed
= HandlePaletteChanged((WXHWND
) (HWND
) wParam
);
3092 case WM_CAPTURECHANGED
:
3093 processed
= HandleCaptureChanged((WXHWND
) (HWND
) lParam
);
3096 case WM_SETTINGCHANGE
:
3097 processed
= HandleSettingChange(wParam
, lParam
);
3100 case WM_QUERYNEWPALETTE
:
3101 processed
= HandleQueryNewPalette();
3105 processed
= HandleEraseBkgnd((WXHDC
)(HDC
)wParam
);
3108 // we processed the message, i.e. erased the background
3113 #if !defined(__WXWINCE__)
3115 processed
= HandleDropFiles(wParam
);
3120 processed
= HandleInitDialog((WXHWND
)(HWND
)wParam
);
3124 // we never set focus from here
3129 #if !defined(__WXWINCE__)
3130 case WM_QUERYENDSESSION
:
3131 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3135 processed
= HandleEndSession(wParam
!= 0, lParam
);
3138 case WM_GETMINMAXINFO
:
3139 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3144 processed
= HandleSetCursor((WXHWND
)(HWND
)wParam
,
3145 LOWORD(lParam
), // hit test
3146 HIWORD(lParam
)); // mouse msg
3150 // returning TRUE stops the DefWindowProc() from further
3151 // processing this message - exactly what we need because we've
3152 // just set the cursor.
3157 #if wxUSE_ACCESSIBILITY
3160 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3161 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3163 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3165 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3171 #if defined(WM_HELP)
3174 // by default, WM_HELP is propagated by DefWindowProc() upwards
3175 // to the window parent but as we do it ourselves already
3176 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3177 // to get the other events if we process this message at all
3180 // WM_HELP doesn't use lParam under CE
3182 HELPINFO
* info
= (HELPINFO
*) lParam
;
3183 if ( info
->iContextType
== HELPINFO_WINDOW
)
3185 #endif // !__WXWINCE__
3186 wxHelpEvent helpEvent
3191 wxGetMousePosition() // what else?
3193 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3197 helpEvent
.SetEventObject(this);
3198 GetEventHandler()->ProcessEvent(helpEvent
);
3201 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3203 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3204 helpEvent
.SetEventObject(this);
3205 GetEventHandler()->ProcessEvent(helpEvent
);
3208 else // unknown help event?
3212 #endif // !__WXWINCE__
3217 #if !defined(__WXWINCE__)
3218 case WM_CONTEXTMENU
:
3220 // we don't convert from screen to client coordinates as
3221 // the event may be handled by a parent window
3222 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3224 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3226 // we could have got an event from our child, reflect it back
3227 // to it if this is the case
3228 wxWindowMSW
*win
= NULL
;
3229 if ( (WXHWND
)wParam
!= m_hWnd
)
3231 win
= FindItemByHWND((WXHWND
)wParam
);
3237 evtCtx
.SetEventObject(win
);
3238 processed
= win
->GetEventHandler()->ProcessEvent(evtCtx
);
3244 // we're only interested in our own menus, not MF_SYSMENU
3245 if ( HIWORD(wParam
) == MF_POPUP
)
3247 // handle menu chars for ownerdrawn menu items
3248 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3249 if ( i
!= wxNOT_FOUND
)
3251 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3258 case WM_POWERBROADCAST
:
3261 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3262 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3265 #endif // __WXWINCE__
3271 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
3272 wxGetMessageName(message
));
3273 #endif // __WXDEBUG__
3274 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3280 // ----------------------------------------------------------------------------
3281 // wxWindow <-> HWND map
3282 // ----------------------------------------------------------------------------
3284 wxWinHashTable
*wxWinHandleHash
= NULL
;
3286 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
3288 return (wxWindow
*)wxWinHandleHash
->Get((long)hWnd
);
3291 void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
)
3293 // adding NULL hWnd is (first) surely a result of an error and
3294 // (secondly) breaks menu command processing
3295 wxCHECK_RET( hWnd
!= (HWND
)NULL
,
3296 wxT("attempt to add a NULL hWnd to window list ignored") );
3298 wxWindow
*oldWin
= wxFindWinFromHandle((WXHWND
) hWnd
);
3300 if ( oldWin
&& (oldWin
!= win
) )
3302 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
3303 (int) hWnd
, win
->GetClassInfo()->GetClassName());
3306 #endif // __WXDEBUG__
3309 wxWinHandleHash
->Put((long)hWnd
, (wxWindow
*)win
);
3313 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3315 wxWinHandleHash
->Delete((long)win
->GetHWND());
3318 // ----------------------------------------------------------------------------
3319 // various MSW speciic class dependent functions
3320 // ----------------------------------------------------------------------------
3322 // Default destroyer - override if you destroy it in some other way
3323 // (e.g. with MDI child windows)
3324 void wxWindowMSW::MSWDestroyWindow()
3328 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3331 int& w
, int& h
) const
3333 // yes, those are just some arbitrary hardcoded numbers
3334 static const int DEFAULT_Y
= 200;
3336 bool nonDefault
= false;
3338 if ( pos
.x
== wxDefaultCoord
)
3340 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
3341 // can just as well set it to CW_USEDEFAULT as well
3347 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
3348 // neither because it is not handled as a special value by Windows then
3349 // and so we have to choose some default value for it
3351 y
= pos
.y
== wxDefaultCoord
? DEFAULT_Y
: pos
.y
;
3357 NB: there used to be some code here which set the initial size of the
3358 window to the client size of the parent if no explicit size was
3359 specified. This was wrong because wxWidgets programs often assume
3360 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3361 it. To see why, you should understand that Windows sends WM_SIZE from
3362 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3363 from some base class ctor and so this WM_SIZE is not processed in the
3364 real class' OnSize() (because it's not fully constructed yet and the
3365 event goes to some base class OnSize() instead). So the WM_SIZE we
3366 rely on is the one sent when the parent frame resizes its children
3367 but here is the problem: if the child already has just the right
3368 size, nothing will happen as both wxWidgets and Windows check for
3369 this and ignore any attempts to change the window size to the size it
3370 already has - so no WM_SIZE would be sent.
3374 // we don't use CW_USEDEFAULT here for several reasons:
3376 // 1. it results in huge frames on modern screens (1000*800 is not
3377 // uncommon on my 1280*1024 screen) which is way too big for a half
3378 // empty frame of most of wxWidgets samples for example)
3380 // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
3381 // the default is for whatever reason 8*8 which breaks client <->
3382 // window size calculations (it would be nice if it didn't, but it
3383 // does and the simplest way to fix it seemed to change the broken
3384 // default size anyhow)
3386 // 3. there is just no advantage in doing it: with x and y it is
3387 // possible that [future versions of] Windows position the new top
3388 // level window in some smart way which we can't do, but we can
3389 // guess a reasonably good size for a new window just as well
3392 // However, on PocketPC devices, we must use the default
3393 // size if possible.
3395 if (size
.x
== wxDefaultCoord
)
3399 if (size
.y
== wxDefaultCoord
)
3404 if ( size
.x
== wxDefaultCoord
|| size
.y
== wxDefaultCoord
)
3408 w
= WidthDefault(size
.x
);
3409 h
= HeightDefault(size
.y
);
3412 AdjustForParentClientOrigin(x
, y
);
3417 WXHWND
wxWindowMSW::MSWGetParent() const
3419 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3422 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3423 const wxChar
*title
,
3427 WXDWORD extendedStyle
)
3429 // choose the position/size for the new window
3431 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3433 // controlId is menu handle for the top level windows, so set it to 0
3434 // unless we're creating a child window
3435 int controlId
= style
& WS_CHILD
? GetId() : 0;
3437 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3438 // which is the same but without CS_[HV]REDRAW class styles so using it
3439 // ensures that the window is not fully repainted on each resize
3440 wxString
className(wclass
);
3441 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3443 className
+= wxT("NR");
3446 // do create the window
3447 wxWindowCreationHook
hook(this);
3449 m_hWnd
= (WXHWND
)::CreateWindowEx
3453 title
? title
: (const wxChar
*)m_windowName
.c_str(),
3456 (HWND
)MSWGetParent(),
3459 NULL
// no extra data
3464 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3469 SubclassWin(m_hWnd
);
3474 // ===========================================================================
3475 // MSW message handlers
3476 // ===========================================================================
3478 // ---------------------------------------------------------------------------
3480 // ---------------------------------------------------------------------------
3482 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3484 #ifndef __WXMICROWIN__
3485 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3486 HWND hWnd
= hdr
->hwndFrom
;
3487 wxWindow
*win
= wxFindWinFromHandle((WXHWND
)hWnd
);
3489 // if the control is one of our windows, let it handle the message itself
3492 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3495 // VZ: why did we do it? normally this is unnecessary and, besides, it
3496 // breaks the message processing for the toolbars because the tooltip
3497 // notifications were being forwarded to the toolbar child controls
3498 // (if it had any) before being passed to the toolbar itself, so in my
3499 // example the tooltip for the combobox was always shown instead of the
3500 // correct button tooltips
3502 // try all our children
3503 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3506 wxWindow
*child
= node
->GetData();
3507 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3512 node
= node
->GetNext();
3516 // by default, handle it ourselves
3517 return MSWOnNotify(idCtrl
, lParam
, result
);
3518 #else // __WXMICROWIN__
3525 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3527 const wxString
& ttip
)
3529 // I don't know why it happens, but the versions of comctl32.dll starting
3530 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3531 // this message is supposed to be sent to Unicode programs only) -- hence
3532 // we need to handle it as well, otherwise no tooltips will be shown in
3535 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3538 // not a tooltip message or no tooltip to show anyhow
3543 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3545 // We don't want to use the szText buffer because it has a limit of 80
3546 // bytes and this is not enough, especially for Unicode build where it
3547 // limits the tooltip string length to only 40 characters
3549 // The best would be, of course, to not impose any length limitations at
3550 // all but then the buffer would have to be dynamic and someone would have
3551 // to free it and we don't have the tooltip owner object here any more, so
3552 // for now use our own static buffer with a higher fixed max length.
3554 // Note that using a static buffer should not be a problem as only a single
3555 // tooltip can be shown at the same time anyhow.
3557 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3559 // We need to convert tooltip from multi byte to Unicode on the fly.
3560 static wchar_t buf
[513];
3562 // Truncate tooltip length if needed as otherwise we might not have
3563 // enough space for it in the buffer and MultiByteToWideChar() would
3565 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3567 // Convert to WideChar without adding the NULL character. The NULL
3568 // character is added afterwards (this is more efficient).
3569 int len
= ::MultiByteToWideChar
3581 wxLogLastError(_T("MultiByteToWideChar()"));
3585 ttText
->lpszText
= (LPSTR
) buf
;
3587 else // TTN_NEEDTEXTA
3588 #endif // !wxUSE_UNICODE
3590 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3591 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3592 // to copy the string we have into the buffer
3593 static wxChar buf
[513];
3594 wxStrncpy(buf
, ttip
.c_str(), WXSIZEOF(buf
) - 1);
3595 buf
[WXSIZEOF(buf
) - 1] = _T('\0');
3596 ttText
->lpszText
= buf
;
3602 #endif // wxUSE_TOOLTIPS
3604 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3606 WXLPARAM
* WXUNUSED(result
))
3611 NMHDR
* hdr
= (NMHDR
*)lParam
;
3612 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3619 wxUnusedVar(lParam
);
3620 #endif // wxUSE_TOOLTIPS
3625 // ---------------------------------------------------------------------------
3626 // end session messages
3627 // ---------------------------------------------------------------------------
3629 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3631 #ifdef ENDSESSION_LOGOFF
3632 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3633 event
.SetEventObject(wxTheApp
);
3634 event
.SetCanVeto(true);
3635 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3637 bool rc
= wxTheApp
->ProcessEvent(event
);
3641 // we may end only if the app didn't veto session closing (double
3643 *mayEnd
= !event
.GetVeto();
3648 wxUnusedVar(logOff
);
3649 wxUnusedVar(mayEnd
);
3654 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3656 #ifdef ENDSESSION_LOGOFF
3657 // do nothing if the session isn't ending
3662 if ( (this != wxTheApp
->GetTopWindow()) )
3665 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3666 event
.SetEventObject(wxTheApp
);
3667 event
.SetCanVeto(false);
3668 event
.SetLoggingOff( (logOff
== (long)ENDSESSION_LOGOFF
) );
3670 return wxTheApp
->ProcessEvent(event
);
3672 wxUnusedVar(endSession
);
3673 wxUnusedVar(logOff
);
3678 // ---------------------------------------------------------------------------
3679 // window creation/destruction
3680 // ---------------------------------------------------------------------------
3682 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3685 // VZ: why is this commented out for WinCE? If it doesn't support
3686 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3687 // not with multiple #ifdef's!
3689 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3690 EnsureParentHasControlParentStyle(GetParent());
3691 #endif // !__WXWINCE__
3698 bool wxWindowMSW::HandleDestroy()
3702 // delete our drop target if we've got one
3703 #if wxUSE_DRAG_AND_DROP
3704 if ( m_dropTarget
!= NULL
)
3706 m_dropTarget
->Revoke(m_hWnd
);
3708 delete m_dropTarget
;
3709 m_dropTarget
= NULL
;
3711 #endif // wxUSE_DRAG_AND_DROP
3713 // WM_DESTROY handled
3717 // ---------------------------------------------------------------------------
3719 // ---------------------------------------------------------------------------
3721 bool wxWindowMSW::HandleActivate(int state
,
3722 bool WXUNUSED(minimized
),
3723 WXHWND
WXUNUSED(activate
))
3725 wxActivateEvent
event(wxEVT_ACTIVATE
,
3726 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3728 event
.SetEventObject(this);
3730 return GetEventHandler()->ProcessEvent(event
);
3733 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3735 // Strangly enough, some controls get set focus events when they are being
3736 // deleted, even if they already had focus before.
3737 if ( m_isBeingDeleted
)
3742 // notify the parent keeping track of focus for the kbd navigation
3743 // purposes that we got it
3744 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3745 (void)GetEventHandler()->ProcessEvent(eventFocus
);
3751 m_caret
->OnSetFocus();
3753 #endif // wxUSE_CARET
3756 // If it's a wxTextCtrl don't send the event as it will be done
3757 // after the control gets to process it from EN_FOCUS handler
3758 if ( wxDynamicCastThis(wxTextCtrl
) )
3762 #endif // wxUSE_TEXTCTRL
3764 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3765 event
.SetEventObject(this);
3767 // wxFindWinFromHandle() may return NULL, it is ok
3768 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3770 return GetEventHandler()->ProcessEvent(event
);
3773 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
3779 m_caret
->OnKillFocus();
3781 #endif // wxUSE_CARET
3784 // If it's a wxTextCtrl don't send the event as it will be done
3785 // after the control gets to process it.
3786 wxTextCtrl
*ctrl
= wxDynamicCastThis(wxTextCtrl
);
3793 // Don't send the event when in the process of being deleted. This can
3794 // only cause problems if the event handler tries to access the object.
3795 if ( m_isBeingDeleted
)
3800 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3801 event
.SetEventObject(this);
3803 // wxFindWinFromHandle() may return NULL, it is ok
3804 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3806 return GetEventHandler()->ProcessEvent(event
);
3809 // ---------------------------------------------------------------------------
3811 // ---------------------------------------------------------------------------
3813 void wxWindowMSW::SetLabel( const wxString
& label
)
3815 SetWindowText(GetHwnd(), label
.c_str());
3818 wxString
wxWindowMSW::GetLabel() const
3820 return wxGetWindowText(GetHWND());
3823 // ---------------------------------------------------------------------------
3825 // ---------------------------------------------------------------------------
3827 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
3829 wxShowEvent
event(GetId(), show
);
3830 event
.SetEventObject(this);
3832 return GetEventHandler()->ProcessEvent(event
);
3835 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
3837 wxInitDialogEvent
event(GetId());
3838 event
.SetEventObject(this);
3840 return GetEventHandler()->ProcessEvent(event
);
3843 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
3845 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
3846 wxUnusedVar(wParam
);
3848 #else // __WXMICROWIN__
3849 HDROP hFilesInfo
= (HDROP
) wParam
;
3851 // Get the total number of files dropped
3852 UINT gwFilesDropped
= ::DragQueryFile
3860 wxString
*files
= new wxString
[gwFilesDropped
];
3861 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
3863 // first get the needed buffer length (+1 for terminating NUL)
3864 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
3866 // and now get the file name
3867 ::DragQueryFile(hFilesInfo
, wIndex
,
3868 wxStringBuffer(files
[wIndex
], len
), len
);
3870 DragFinish (hFilesInfo
);
3872 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
3873 event
.SetEventObject(this);
3876 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
3877 event
.m_pos
.x
= dropPoint
.x
;
3878 event
.m_pos
.y
= dropPoint
.y
;
3880 return GetEventHandler()->ProcessEvent(event
);
3885 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
3887 int WXUNUSED(mouseMsg
))
3889 #ifndef __WXMICROWIN__
3890 // the logic is as follows:
3891 // -1. don't set cursor for non client area, including but not limited to
3892 // the title bar, scrollbars, &c
3893 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
3894 // 1. if we have the cursor set it unless wxIsBusy()
3895 // 2. if we're a top level window, set some cursor anyhow
3896 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
3898 if ( nHitTest
!= HTCLIENT
)
3903 HCURSOR hcursor
= 0;
3905 // first ask the user code - it may wish to set the cursor in some very
3906 // specific way (for example, depending on the current position)
3909 if ( !::GetCursorPosWinCE(&pt
))
3911 if ( !::GetCursorPos(&pt
) )
3914 wxLogLastError(wxT("GetCursorPos"));
3919 ScreenToClient(&x
, &y
);
3920 wxSetCursorEvent
event(x
, y
);
3922 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
3923 if ( processedEvtSetCursor
&& event
.HasCursor() )
3925 hcursor
= GetHcursorOf(event
.GetCursor());
3930 bool isBusy
= wxIsBusy();
3932 // the test for processedEvtSetCursor is here to prevent using m_cursor
3933 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3934 // it - this is a way to say that our cursor shouldn't be used for this
3936 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
3938 hcursor
= GetHcursorOf(m_cursor
);
3945 hcursor
= wxGetCurrentBusyCursor();
3947 else if ( !hcursor
)
3949 const wxCursor
*cursor
= wxGetGlobalCursor();
3950 if ( cursor
&& cursor
->Ok() )
3952 hcursor
= GetHcursorOf(*cursor
);
3960 // wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3962 ::SetCursor(hcursor
);
3964 // cursor set, stop here
3967 #endif // __WXMICROWIN__
3969 // pass up the window chain
3973 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
3974 WXLPARAM
WXUNUSED(lParam
),
3975 bool *WXUNUSED_IN_WINCE(vetoed
))
3981 wxEventType evtType
;
3984 case PBT_APMQUERYSUSPEND
:
3985 evtType
= wxEVT_POWER_SUSPENDING
;
3988 case PBT_APMQUERYSUSPENDFAILED
:
3989 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
3992 case PBT_APMSUSPEND
:
3993 evtType
= wxEVT_POWER_SUSPENDED
;
3996 case PBT_APMRESUMESUSPEND
:
3997 #ifdef PBT_APMRESUMEAUTOMATIC
3998 case PBT_APMRESUMEAUTOMATIC
:
4000 evtType
= wxEVT_POWER_RESUME
;
4004 wxLogDebug(_T("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
4007 // these messages are currently not mapped to wx events
4008 case PBT_APMQUERYSTANDBY
:
4009 case PBT_APMQUERYSTANDBYFAILED
:
4010 case PBT_APMSTANDBY
:
4011 case PBT_APMRESUMESTANDBY
:
4012 case PBT_APMBATTERYLOW
:
4013 case PBT_APMPOWERSTATUSCHANGE
:
4014 case PBT_APMOEMEVENT
:
4015 case PBT_APMRESUMECRITICAL
:
4016 evtType
= wxEVT_NULL
;
4020 // don't handle unknown messages
4021 if ( evtType
== wxEVT_NULL
)
4024 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
4026 wxPowerEvent
event(evtType
);
4027 if ( !GetEventHandler()->ProcessEvent(event
) )
4030 *vetoed
= event
.IsVetoed();
4036 bool wxWindowMSW::IsDoubleBuffered() const
4038 for ( const wxWindowMSW
*wnd
= this;
4039 wnd
&& !wnd
->IsTopLevel(); wnd
=
4042 if ( ::GetWindowLong(GetHwndOf(wnd
), GWL_EXSTYLE
) & WS_EX_COMPOSITED
)
4049 // ---------------------------------------------------------------------------
4050 // owner drawn stuff
4051 // ---------------------------------------------------------------------------
4053 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
4054 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
4055 #define WXUNUSED_UNLESS_ODRAWN(param) param
4057 #define WXUNUSED_UNLESS_ODRAWN(param)
4061 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
4062 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
4064 #if wxUSE_OWNER_DRAWN
4066 #if wxUSE_MENUS_NATIVE
4067 // is it a menu item?
4068 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
4069 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
4071 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
4073 // see comment before the same test in MSWOnMeasureItem() below
4077 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4078 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
4080 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4081 // the DC from being released
4082 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
4083 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
4084 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
4085 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
4087 return pMenuItem
->OnDrawItem
4091 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
4092 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
4095 #endif // wxUSE_MENUS_NATIVE
4097 #endif // USE_OWNER_DRAWN
4099 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4101 #if wxUSE_OWNER_DRAWN
4102 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4103 #else // !wxUSE_OWNER_DRAWN
4104 // we may still have owner-drawn buttons internally because we have to make
4105 // them owner-drawn to support colour change
4108 wxDynamicCast(FindItem(id
), wxButton
)
4113 #endif // USE_OWNER_DRAWN
4117 return item
->MSWOnDraw(itemStruct
);
4120 #endif // wxUSE_CONTROLS
4126 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4128 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4129 // is it a menu item?
4130 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4131 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4133 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4135 // according to Carsten Fuchs the pointer may be NULL under XP if an
4136 // MDI child frame is initially maximized, see this for more info:
4137 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4139 // so silently ignore it instead of asserting
4143 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4144 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
4147 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4149 pMeasureStruct
->itemWidth
= w
;
4150 pMeasureStruct
->itemHeight
= h
;
4155 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4158 return item
->MSWOnMeasure(itemStruct
);
4162 wxUnusedVar(itemStruct
);
4163 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4168 // ---------------------------------------------------------------------------
4169 // colours and palettes
4170 // ---------------------------------------------------------------------------
4172 bool wxWindowMSW::HandleSysColorChange()
4174 wxSysColourChangedEvent event
;
4175 event
.SetEventObject(this);
4177 (void)GetEventHandler()->ProcessEvent(event
);
4179 // always let the system carry on the default processing to allow the
4180 // native controls to react to the colours update
4184 bool wxWindowMSW::HandleDisplayChange()
4186 wxDisplayChangedEvent event
;
4187 event
.SetEventObject(this);
4189 return GetEventHandler()->ProcessEvent(event
);
4192 #ifndef __WXMICROWIN__
4194 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4196 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4200 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4203 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4205 #endif // wxUSE_CONTROLS
4208 return *brush
!= NULL
;
4211 #endif // __WXMICROWIN__
4213 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4216 // same as below except we don't respond to our own messages
4217 if ( hWndPalChange
!= GetHWND() )
4219 // check to see if we our our parents have a custom palette
4220 wxWindowMSW
*win
= this;
4221 while ( win
&& !win
->HasCustomPalette() )
4223 win
= win
->GetParent();
4226 if ( win
&& win
->HasCustomPalette() )
4228 // realize the palette to see whether redrawing is needed
4229 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4230 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4231 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4233 int result
= ::RealizePalette(hdc
);
4235 // restore the palette (before releasing the DC)
4236 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4237 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4238 ::RealizePalette(hdc
);
4239 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4241 // now check for the need to redraw
4243 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4247 #endif // wxUSE_PALETTE
4249 wxPaletteChangedEvent
event(GetId());
4250 event
.SetEventObject(this);
4251 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4253 return GetEventHandler()->ProcessEvent(event
);
4256 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4258 // notify windows on the capture stack about lost capture
4259 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4260 wxWindowBase::NotifyCaptureLost();
4262 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4263 wxMouseCaptureChangedEvent
event(GetId(), win
);
4264 event
.SetEventObject(this);
4265 return GetEventHandler()->ProcessEvent(event
);
4268 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4270 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4271 // we need to send this to child windows (it is only sent to top-level
4272 // windows) so {list,tree}ctrls can adjust their font size if necessary
4273 // this is exactly how explorer does it to enable the font size changes
4275 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4278 // top-level windows already get this message from the system
4279 wxWindow
*win
= node
->GetData();
4280 if ( !win
->IsTopLevel() )
4282 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4285 node
= node
->GetNext();
4288 // let the system handle it
4292 bool wxWindowMSW::HandleQueryNewPalette()
4296 // check to see if we our our parents have a custom palette
4297 wxWindowMSW
*win
= this;
4298 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4299 if (win
->HasCustomPalette()) {
4300 /* realize the palette to see whether redrawing is needed */
4301 HDC hdc
= ::GetDC((HWND
) GetHWND());
4302 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4303 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4305 int result
= ::RealizePalette(hdc
);
4306 /* restore the palette (before releasing the DC) */
4307 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4308 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4309 ::RealizePalette(hdc
);
4310 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4311 /* now check for the need to redraw */
4313 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4315 #endif // wxUSE_PALETTE
4317 wxQueryNewPaletteEvent
event(GetId());
4318 event
.SetEventObject(this);
4320 return GetEventHandler()->ProcessEvent(event
) && event
.GetPaletteRealized();
4323 // Responds to colour changes: passes event on to children.
4324 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4326 // the top level window also reset the standard colour map as it might have
4327 // changed (there is no need to do it for the non top level windows as we
4328 // only have to do it once)
4332 gs_hasStdCmap
= false;
4334 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4337 // Only propagate to non-top-level windows because Windows already
4338 // sends this event to all top-level ones
4339 wxWindow
*win
= node
->GetData();
4340 if ( !win
->IsTopLevel() )
4342 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4343 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4344 // the standard controls
4345 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4348 node
= node
->GetNext();
4352 extern wxCOLORMAP
*wxGetStdColourMap()
4354 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4355 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4357 if ( !gs_hasStdCmap
)
4359 static bool s_coloursInit
= false;
4361 if ( !s_coloursInit
)
4363 // When a bitmap is loaded, the RGB values can change (apparently
4364 // because Windows adjusts them to care for the old programs always
4365 // using 0xc0c0c0 while the transparent colour for the new Windows
4366 // versions is different). But we do this adjustment ourselves so
4367 // we want to avoid Windows' "help" and for this we need to have a
4368 // reference bitmap which can tell us what the RGB values change
4370 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4371 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
4372 if ( stdColourBitmap
.Ok() )
4374 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4375 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4376 _T("forgot to update wxBITMAP_STD_COLOURS!") );
4379 memDC
.SelectObject(stdColourBitmap
);
4382 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4384 memDC
.GetPixel(i
, 0, &colour
);
4385 s_stdColours
[i
] = wxColourToRGB(colour
);
4388 else // wxBITMAP_STD_COLOURS couldn't be loaded
4390 s_stdColours
[0] = RGB(000,000,000); // black
4391 s_stdColours
[1] = RGB(128,128,128); // dark grey
4392 s_stdColours
[2] = RGB(192,192,192); // light grey
4393 s_stdColours
[3] = RGB(255,255,255); // white
4394 //s_stdColours[4] = RGB(000,000,255); // blue
4395 //s_stdColours[5] = RGB(255,000,255); // magenta
4398 s_coloursInit
= true;
4401 gs_hasStdCmap
= true;
4403 // create the colour map
4404 #define INIT_CMAP_ENTRY(col) \
4405 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4406 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4408 INIT_CMAP_ENTRY(BTNTEXT
);
4409 INIT_CMAP_ENTRY(BTNSHADOW
);
4410 INIT_CMAP_ENTRY(BTNFACE
);
4411 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4413 #undef INIT_CMAP_ENTRY
4419 // ---------------------------------------------------------------------------
4421 // ---------------------------------------------------------------------------
4423 bool wxWindowMSW::HandlePaint()
4425 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4427 wxLogLastError(wxT("CreateRectRgn"));
4428 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4429 wxLogLastError(wxT("GetUpdateRgn"));
4431 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4433 wxPaintEvent
event(m_windowId
);
4434 event
.SetEventObject(this);
4436 bool processed
= GetEventHandler()->ProcessEvent(event
);
4438 // note that we must generate NC event after the normal one as otherwise
4439 // BeginPaint() will happily overwrite our decorations with the background
4441 wxNcPaintEvent
eventNc(m_windowId
);
4442 eventNc
.SetEventObject(this);
4443 GetEventHandler()->ProcessEvent(eventNc
);
4448 // Can be called from an application's OnPaint handler
4449 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4451 #ifdef __WXUNIVERSAL__
4454 HDC hDC
= (HDC
) wxPaintDC::FindDCInCache((wxWindow
*) event
.GetEventObject());
4457 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4462 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4464 wxDCTemp
dc(hdc
, GetClientSize());
4467 dc
.SetWindow((wxWindow
*)this);
4469 wxEraseEvent
event(m_windowId
, &dc
);
4470 event
.SetEventObject(this);
4471 bool rc
= GetEventHandler()->ProcessEvent(event
);
4473 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
4474 dc
.SelectOldObjects(hdc
);
4479 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
4481 // standard non top level controls (i.e. except the dialogs) always erase
4482 // their background themselves in HandleCtlColor() or have some control-
4483 // specific ways to set the colours (common controls)
4484 if ( IsOfStandardClass() && !IsTopLevel() )
4490 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
4492 // don't skip the event here, custom background means that the app
4493 // is drawing it itself in its OnPaint(), so don't draw it at all
4494 // now to avoid flicker
4499 // do default background painting
4500 if ( !DoEraseBackground(GetHdcOf(*event
.GetDC())) )
4502 // let the system paint the background
4507 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4509 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4513 wxFillRect(GetHwnd(), (HDC
)hDC
, hbr
);
4519 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
), WXHWND hWnd
)
4523 // our background colour applies to:
4524 // 1. this window itself, always
4525 // 2. all children unless the colour is "not inheritable"
4526 // 3. even if it is not inheritable, our immediate transparent
4527 // children should still inherit it -- but not any transparent
4528 // children because it would look wrong if a child of non
4529 // transparent child would show our bg colour when the child itself
4531 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
4534 (win
&& win
->HasTransparentBackground() &&
4535 win
->GetParent() == this) )
4537 // draw children with the same colour as the parent
4539 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4541 return (WXHBRUSH
)GetHbrushOf(*brush
);
4548 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
, WXHWND hWndToPaint
)
4551 hWndToPaint
= GetHWND();
4553 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4555 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, hWndToPaint
);
4559 // background is not inherited beyond top level windows
4560 if ( win
->IsTopLevel() )
4567 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4569 // we receive this message when DrawThemeParentBackground() is
4570 // called from def window proc of several controls under XP and we
4571 // must draw properly themed background here
4573 // note that naively I'd expect filling the client rect with the
4574 // brush returned by MSWGetBgBrush() work -- but for some reason it
4575 // doesn't and we have to call parents MSWPrintChild() which is
4576 // supposed to call DrawThemeBackground() with appropriate params
4578 // also note that in this case lParam == PRF_CLIENT but we're
4579 // clearly expected to paint the background and nothing else!
4581 if ( IsTopLevel() || InheritsBackgroundColour() )
4584 // sometimes we don't want the parent to handle it at all, instead
4585 // return whatever value this window wants
4586 if ( !MSWShouldPropagatePrintChild() )
4587 return MSWPrintChild(hDC
, (wxWindow
*)this);
4589 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4591 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4594 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4601 // ---------------------------------------------------------------------------
4602 // moving and resizing
4603 // ---------------------------------------------------------------------------
4605 bool wxWindowMSW::HandleMinimize()
4607 wxIconizeEvent
event(m_windowId
);
4608 event
.SetEventObject(this);
4610 return GetEventHandler()->ProcessEvent(event
);
4613 bool wxWindowMSW::HandleMaximize()
4615 wxMaximizeEvent
event(m_windowId
);
4616 event
.SetEventObject(this);
4618 return GetEventHandler()->ProcessEvent(event
);
4621 bool wxWindowMSW::HandleMove(int x
, int y
)
4624 wxMoveEvent
event(point
, m_windowId
);
4625 event
.SetEventObject(this);
4627 return GetEventHandler()->ProcessEvent(event
);
4630 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
4632 wxMoveEvent
event(rect
, m_windowId
);
4633 event
.SetEventObject(this);
4635 bool rc
= GetEventHandler()->ProcessEvent(event
);
4637 rect
= event
.GetRect();
4641 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
4643 #if USE_DEFERRED_SIZING
4644 // when we resize this window, its children are probably going to be
4645 // repositioned as well, prepare to use DeferWindowPos() for them
4646 int numChildren
= 0;
4647 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
4649 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
4654 // Protect against valid m_hDWP being overwritten
4655 bool useDefer
= false;
4657 if ( numChildren
> 1 )
4661 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
4664 wxLogLastError(_T("BeginDeferWindowPos"));
4670 #endif // USE_DEFERRED_SIZING
4672 // update this window size
4673 bool processed
= false;
4677 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4678 // fall through nevertheless
4682 // we're not interested in these messages at all
4685 case SIZE_MINIMIZED
:
4686 processed
= HandleMinimize();
4689 case SIZE_MAXIMIZED
:
4690 /* processed = */ HandleMaximize();
4691 // fall through to send a normal size event as well
4694 // don't use w and h parameters as they specify the client size
4695 // while according to the docs EVT_SIZE handler is supposed to
4696 // receive the total size
4697 wxSizeEvent
event(GetSize(), m_windowId
);
4698 event
.SetEventObject(this);
4700 processed
= GetEventHandler()->ProcessEvent(event
);
4703 #if USE_DEFERRED_SIZING
4704 // and finally change the positions of all child windows at once
4705 if ( useDefer
&& m_hDWP
)
4707 // reset m_hDWP to NULL so that child windows don't try to use our
4708 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4709 // happen anyhow normally but who knows what weird flow of control we
4710 // may have depending on what the users EVT_SIZE handler does...)
4711 HDWP hDWP
= (HDWP
)m_hDWP
;
4714 // do put all child controls in place at once
4715 if ( !::EndDeferWindowPos(hDWP
) )
4717 wxLogLastError(_T("EndDeferWindowPos"));
4720 // Reset our children's pending pos/size values.
4721 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4723 node
= node
->GetNext() )
4725 wxWindowMSW
*child
= node
->GetData();
4726 child
->m_pendingPosition
= wxDefaultPosition
;
4727 child
->m_pendingSize
= wxDefaultSize
;
4730 #endif // USE_DEFERRED_SIZING
4735 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
4737 wxSizeEvent
event(rect
, m_windowId
);
4738 event
.SetEventObject(this);
4740 bool rc
= GetEventHandler()->ProcessEvent(event
);
4742 rect
= event
.GetRect();
4746 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
4751 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
4755 int minWidth
= GetMinWidth(),
4756 minHeight
= GetMinHeight(),
4757 maxWidth
= GetMaxWidth(),
4758 maxHeight
= GetMaxHeight();
4760 if ( minWidth
!= wxDefaultCoord
)
4762 info
->ptMinTrackSize
.x
= minWidth
;
4766 if ( minHeight
!= wxDefaultCoord
)
4768 info
->ptMinTrackSize
.y
= minHeight
;
4772 if ( maxWidth
!= wxDefaultCoord
)
4774 info
->ptMaxTrackSize
.x
= maxWidth
;
4778 if ( maxHeight
!= wxDefaultCoord
)
4780 info
->ptMaxTrackSize
.y
= maxHeight
;
4788 // ---------------------------------------------------------------------------
4790 // ---------------------------------------------------------------------------
4792 bool wxWindowMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
4794 #if wxUSE_MENUS_NATIVE
4795 if ( !cmd
&& wxCurrentPopupMenu
)
4797 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
4798 wxCurrentPopupMenu
= NULL
;
4800 return popupMenu
->MSWCommand(cmd
, id
);
4802 #endif // wxUSE_MENUS_NATIVE
4804 wxWindow
*win
= NULL
;
4806 // first try to find it from HWND - this works even with the broken
4807 // programs using the same ids for different controls
4810 win
= wxFindWinFromHandle(control
);
4816 // must cast to a signed type before comparing with other ids!
4817 win
= FindItem((signed short)id
);
4822 return win
->MSWCommand(cmd
, id
);
4825 // the messages sent from the in-place edit control used by the treectrl
4826 // for label editing have id == 0, but they should _not_ be treated as menu
4827 // messages (they are EN_XXX ones, in fact) so don't translate anything
4828 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4831 // If no child window, it may be an accelerator, e.g. for a popup menu
4834 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
4835 event
.SetEventObject(this);
4839 return GetEventHandler()->ProcessEvent(event
);
4843 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4844 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4845 // notifications to its parent which we want to reflect back to
4847 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
4848 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
4850 #endif // wxUSE_SPINCTRL
4852 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
4853 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
4854 // notifications to its parent which we want to reflect back to
4856 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
4857 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
4865 // ---------------------------------------------------------------------------
4867 // ---------------------------------------------------------------------------
4869 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
4873 // our client coords are not quite the same as Windows ones
4874 wxPoint pt
= GetClientAreaOrigin();
4875 event
.m_x
= x
- pt
.x
;
4876 event
.m_y
= y
- pt
.y
;
4878 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
4879 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
4880 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
4881 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
4882 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
4883 event
.m_altDown
= ::GetKeyState(VK_MENU
) < 0;
4886 event
.SetTimestamp(::GetMessageTime());
4889 event
.SetEventObject(this);
4890 event
.SetId(GetId());
4892 #if wxUSE_MOUSEEVENT_HACK
4893 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
4894 gs_lastMouseEvent
.type
= event
.GetEventType();
4895 #endif // wxUSE_MOUSEEVENT_HACK
4899 // Windows doesn't send the mouse events to the static controls (which are
4900 // transparent in the sense that their WM_NCHITTEST handler returns
4901 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4902 // and so we manually check if we don't have a child window under mouse and if
4903 // we do, send the event to it instead of the window Windows had sent WM_XXX
4906 // Notice that this is not done for the mouse move events because this could
4907 // (would?) be too slow, but only for clicks which means that the static texts
4908 // still don't get move, enter nor leave events.
4909 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
4911 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
4913 // first try to find a non transparent child: this allows us to send events
4914 // to a static text which is inside a static box, for example
4915 POINT pt
= { *x
, *y
};
4916 HWND hwnd
= GetHwndOf(win
),
4920 hwndUnderMouse
= ::ChildWindowFromPoint
4926 hwndUnderMouse
= ::ChildWindowFromPointEx
4936 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
4938 // now try any child window at all
4939 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
4942 // check that we have a child window which is susceptible to receive mouse
4943 // events: for this it must be shown and enabled
4944 if ( hwndUnderMouse
&&
4945 hwndUnderMouse
!= hwnd
&&
4946 ::IsWindowVisible(hwndUnderMouse
) &&
4947 ::IsWindowEnabled(hwndUnderMouse
) )
4949 wxWindow
*winUnderMouse
= wxFindWinFromHandle((WXHWND
)hwndUnderMouse
);
4950 if ( winUnderMouse
)
4952 // translate the mouse coords to the other window coords
4953 win
->ClientToScreen(x
, y
);
4954 winUnderMouse
->ScreenToClient(x
, y
);
4956 win
= winUnderMouse
;
4962 #endif // __WXWINCE__
4964 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4966 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4967 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
4968 // from the message id and take the value in the table to get wxWin event
4970 static const wxEventType eventsMouse
[] =
4984 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
4985 InitMouseEvent(event
, x
, y
, flags
);
4987 return GetEventHandler()->ProcessEvent(event
);
4990 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
4992 if ( !m_mouseInWindow
)
4994 // it would be wrong to assume that just because we get a mouse move
4995 // event that the mouse is inside the window: although this is usually
4996 // true, it is not if we had captured the mouse, so we need to check
4997 // the mouse coordinates here
4998 if ( !HasCapture() || IsMouseInWindow() )
5000 // Generate an ENTER event
5001 m_mouseInWindow
= true;
5003 #ifdef HAVE_TRACKMOUSEEVENT
5004 typedef BOOL (WINAPI
*_TrackMouseEvent_t
)(LPTRACKMOUSEEVENT
);
5006 static const _TrackMouseEvent_t
5007 s_pfn_TrackMouseEvent
= _TrackMouseEvent
;
5008 #else // !__WXWINCE__
5009 static _TrackMouseEvent_t s_pfn_TrackMouseEvent
;
5010 static bool s_initDone
= false;
5015 wxDynamicLibrary
dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM
);
5016 if ( dllComCtl32
.IsLoaded() )
5018 s_pfn_TrackMouseEvent
= (_TrackMouseEvent_t
)
5019 dllComCtl32
.GetSymbol(_T("_TrackMouseEvent"));
5024 // notice that it's ok to unload comctl32.dll here as it won't
5025 // be really unloaded, being still in use because we link to it
5029 if ( s_pfn_TrackMouseEvent
)
5030 #endif // __WXWINCE__/!__WXWINCE__
5032 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
5034 trackinfo
.dwFlags
= TME_LEAVE
;
5035 trackinfo
.hwndTrack
= GetHwnd();
5037 (*s_pfn_TrackMouseEvent
)(&trackinfo
);
5039 #endif // HAVE_TRACKMOUSEEVENT
5041 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
5042 InitMouseEvent(event
, x
, y
, flags
);
5044 (void)GetEventHandler()->ProcessEvent(event
);
5047 #ifdef HAVE_TRACKMOUSEEVENT
5048 else // mouse not in window
5050 // Check if we need to send a LEAVE event
5051 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
5052 // send it here if we are using native mouse leave tracking
5053 if ( HasCapture() && !IsMouseInWindow() )
5055 GenerateMouseLeave();
5058 #endif // HAVE_TRACKMOUSEEVENT
5060 #if wxUSE_MOUSEEVENT_HACK
5061 // Windows often generates mouse events even if mouse position hasn't
5062 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
5064 // Filter this out as it can result in unexpected behaviour compared to
5066 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
5067 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
5068 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
5069 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
5071 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
5073 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
5078 #endif // wxUSE_MOUSEEVENT_HACK
5080 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
5084 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
5086 #if wxUSE_MOUSEWHEEL
5087 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5088 // forwarded up to the parent by DefWindowProc()) and not in the client
5089 // ones as all the other messages, translate them to the client coords for
5092 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
5093 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
5094 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
5095 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5096 event
.m_wheelDelta
= WHEEL_DELTA
;
5098 static int s_linesPerRotation
= -1;
5099 if ( s_linesPerRotation
== -1 )
5101 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5102 &s_linesPerRotation
, 0))
5104 // this is not supposed to happen
5105 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5107 // the default is 3, so use it if SystemParametersInfo() failed
5108 s_linesPerRotation
= 3;
5112 event
.m_linesPerAction
= s_linesPerRotation
;
5113 return GetEventHandler()->ProcessEvent(event
);
5115 #else // !wxUSE_MOUSEWHEEL
5116 wxUnusedVar(wParam
);
5117 wxUnusedVar(lParam
);
5120 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5123 void wxWindowMSW::GenerateMouseLeave()
5125 m_mouseInWindow
= false;
5128 if ( wxIsShiftDown() )
5130 if ( wxIsCtrlDown() )
5131 state
|= MK_CONTROL
;
5133 // Only the high-order bit should be tested
5134 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5135 state
|= MK_LBUTTON
;
5136 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5137 state
|= MK_MBUTTON
;
5138 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5139 state
|= MK_RBUTTON
;
5143 if ( !::GetCursorPosWinCE(&pt
) )
5145 if ( !::GetCursorPos(&pt
) )
5148 wxLogLastError(_T("GetCursorPos"));
5151 // we need to have client coordinates here for symmetry with
5152 // wxEVT_ENTER_WINDOW
5153 RECT rect
= wxGetWindowRect(GetHwnd());
5157 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5158 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5160 (void)GetEventHandler()->ProcessEvent(event
);
5163 // ---------------------------------------------------------------------------
5164 // keyboard handling
5165 // ---------------------------------------------------------------------------
5167 // create the key event of the given type for the given key - used by
5168 // HandleChar and HandleKeyDown/Up
5169 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5172 WXWPARAM wParam
) const
5174 wxKeyEvent
event(evType
);
5175 event
.SetId(GetId());
5176 event
.m_shiftDown
= wxIsShiftDown();
5177 event
.m_controlDown
= wxIsCtrlDown();
5178 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5180 event
.SetEventObject((wxWindow
*)this); // const_cast
5181 event
.m_keyCode
= id
;
5183 event
.m_uniChar
= (wxChar
) wParam
;
5185 event
.m_rawCode
= (wxUint32
) wParam
;
5186 event
.m_rawFlags
= (wxUint32
) lParam
;
5188 event
.SetTimestamp(::GetMessageTime());
5191 // translate the position to client coords
5194 GetCursorPosWinCE(&pt
);
5199 GetWindowRect(GetHwnd(),&rect
);
5209 // isASCII is true only when we're called from WM_CHAR handler and not from
5211 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
5218 else // we're called from WM_KEYDOWN
5220 // don't pass lParam to wxCharCodeMSWToWX() here because we don't want
5221 // to get numpad key codes: CHAR events should use the logical keys
5222 // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events
5223 id
= wxCharCodeMSWToWX(wParam
);
5226 // it's ASCII and will be processed here only when called from
5227 // WM_CHAR (i.e. when isASCII = true), don't process it now
5232 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
5234 // the alphanumeric keys produced by pressing AltGr+something on European
5235 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5236 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5237 // alphanumeric, so pretend that there are no modifiers at all (the
5238 // KEY_DOWN event would still have the correct modifiers if they're really
5240 if ( event
.m_controlDown
&& event
.m_altDown
&&
5241 (id
>= 32 && id
< 256) )
5243 event
.m_controlDown
=
5244 event
.m_altDown
= false;
5247 return GetEventHandler()->ProcessEvent(event
);
5250 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5252 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5256 // normal ASCII char
5260 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
5261 return GetEventHandler()->ProcessEvent(event
);
5264 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5266 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5270 // normal ASCII char
5274 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
5275 return GetEventHandler()->ProcessEvent(event
);
5278 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5279 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5281 // FIXME: implement GetMenuItemCount for WinCE, possibly
5282 // in terms of GetMenuItemInfo
5284 const HMENU hmenu
= (HMENU
)lParam
;
5288 mii
.cbSize
= sizeof(MENUITEMINFO
);
5290 // we could use MIIM_FTYPE here as we only need to know if the item is
5291 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5292 // MIIM_FTYPE is not supported under Win95
5293 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5295 // find if we have this letter in any owner drawn item
5296 const int count
= ::GetMenuItemCount(hmenu
);
5297 for ( int i
= 0; i
< count
; i
++ )
5299 // previous loop iteration could modify it, reset it back before
5300 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5303 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5305 if ( mii
.fType
== MFT_OWNERDRAW
)
5307 // dwItemData member of the MENUITEMINFO is a
5308 // pointer to the associated wxMenuItem -- see the
5309 // menu creation code
5310 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5312 const wxChar
*p
= wxStrchr(item
->GetText(), _T('&'));
5315 if ( *p
== _T('&') )
5317 // this is not the accel char, find the real one
5318 p
= wxStrchr(p
+ 1, _T('&'));
5320 else // got the accel char
5322 // FIXME-UNICODE: this comparison doesn't risk to work
5323 // for non ASCII accelerator characters I'm afraid, but
5325 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5331 // this one doesn't match
5338 else // failed to get the menu text?
5340 // it's not fatal, so don't show error, but still log it
5341 wxLogLastError(_T("GetMenuItemInfo"));
5348 bool wxWindowMSW::HandleClipboardEvent( WXUINT nMsg
)
5350 const wxEventType type
= ( nMsg
== WM_CUT
) ? wxEVT_COMMAND_TEXT_CUT
:
5351 ( nMsg
== WM_COPY
) ? wxEVT_COMMAND_TEXT_COPY
:
5352 /*( nMsg == WM_PASTE ) ? */ wxEVT_COMMAND_TEXT_PASTE
;
5353 wxClipboardTextEvent
evt(type
, GetId());
5355 evt
.SetEventObject(this);
5357 return GetEventHandler()->ProcessEvent(evt
);
5360 // ---------------------------------------------------------------------------
5362 // ---------------------------------------------------------------------------
5364 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5368 if ( flags
& JOY_BUTTON1CHG
)
5369 change
= wxJOY_BUTTON1
;
5370 if ( flags
& JOY_BUTTON2CHG
)
5371 change
= wxJOY_BUTTON2
;
5372 if ( flags
& JOY_BUTTON3CHG
)
5373 change
= wxJOY_BUTTON3
;
5374 if ( flags
& JOY_BUTTON4CHG
)
5375 change
= wxJOY_BUTTON4
;
5378 if ( flags
& JOY_BUTTON1
)
5379 buttons
|= wxJOY_BUTTON1
;
5380 if ( flags
& JOY_BUTTON2
)
5381 buttons
|= wxJOY_BUTTON2
;
5382 if ( flags
& JOY_BUTTON3
)
5383 buttons
|= wxJOY_BUTTON3
;
5384 if ( flags
& JOY_BUTTON4
)
5385 buttons
|= wxJOY_BUTTON4
;
5387 // the event ids aren't consecutive so we can't use table based lookup
5389 wxEventType eventType
;
5394 eventType
= wxEVT_JOY_MOVE
;
5399 eventType
= wxEVT_JOY_MOVE
;
5404 eventType
= wxEVT_JOY_ZMOVE
;
5409 eventType
= wxEVT_JOY_ZMOVE
;
5412 case MM_JOY1BUTTONDOWN
:
5414 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5417 case MM_JOY2BUTTONDOWN
:
5419 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5422 case MM_JOY1BUTTONUP
:
5424 eventType
= wxEVT_JOY_BUTTON_UP
;
5427 case MM_JOY2BUTTONUP
:
5429 eventType
= wxEVT_JOY_BUTTON_UP
;
5433 wxFAIL_MSG(wxT("no such joystick event"));
5438 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5439 event
.SetPosition(wxPoint(x
, y
));
5440 event
.SetEventObject(this);
5442 return GetEventHandler()->ProcessEvent(event
);
5452 // ---------------------------------------------------------------------------
5454 // ---------------------------------------------------------------------------
5456 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5457 WXWORD pos
, WXHWND control
)
5459 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5461 wxWindow
*child
= wxFindWinFromHandle(control
);
5463 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5466 wxScrollWinEvent event
;
5467 event
.SetPosition(pos
);
5468 event
.SetOrientation(orientation
);
5469 event
.SetEventObject(this);
5474 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5478 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5482 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5486 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5490 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5494 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5497 case SB_THUMBPOSITION
:
5499 // under Win32, the scrollbar range and position are 32 bit integers,
5500 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5501 // explicitly query the scrollbar for the correct position (this must
5502 // be done only for these two SB_ events as they are the only one
5503 // carrying the scrollbar position)
5505 WinStruct
<SCROLLINFO
> scrollInfo
;
5506 scrollInfo
.fMask
= SIF_TRACKPOS
;
5508 if ( !::GetScrollInfo(GetHwnd(),
5509 orientation
== wxHORIZONTAL
? SB_HORZ
5513 // Not necessarily an error, if there are no scrollbars yet.
5514 // wxLogLastError(_T("GetScrollInfo"));
5517 event
.SetPosition(scrollInfo
.nTrackPos
);
5520 event
.SetEventType( wParam
== SB_THUMBPOSITION
5521 ? wxEVT_SCROLLWIN_THUMBRELEASE
5522 : wxEVT_SCROLLWIN_THUMBTRACK
);
5529 return GetEventHandler()->ProcessEvent(event
);
5532 // ===========================================================================
5534 // ===========================================================================
5536 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5539 HDC dc
= ::GetDC((HWND
) wnd
);
5542 // the_font.UseResource();
5543 // the_font.RealizeResource();
5544 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
5546 was
= (HFONT
) SelectObject(dc
,fnt
);
5548 GetTextMetrics(dc
, &tm
);
5551 SelectObject(dc
,was
);
5553 ReleaseDC((HWND
)wnd
, dc
);
5556 *x
= tm
.tmAveCharWidth
;
5558 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
5560 // the_font.ReleaseResource();
5563 // use the "extended" bit (24) of lParam to distinguish extended keys
5564 // from normal keys as the same key is sent
5566 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
5568 // except that if lParam is 0, it means we don't have real lParam from
5569 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
5570 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
5571 // non-numpad (hence extended) key as this is a more common case
5572 return !lParam
|| (lParam
& (1 << 24)) ? keyExtended
: keyNormal
;
5575 // this array contains the Windows virtual key codes which map one to one to
5576 // WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below
5578 // note that keys having a normal and numpad version (e.g. WXK_HOME and
5579 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
5580 static const struct wxKeyMapping
5584 } gs_specialKeys
[] =
5586 { VK_CANCEL
, WXK_CANCEL
},
5587 { VK_BACK
, WXK_BACK
},
5588 { VK_TAB
, WXK_TAB
},
5589 { VK_CLEAR
, WXK_CLEAR
},
5590 { VK_SHIFT
, WXK_SHIFT
},
5591 { VK_CONTROL
, WXK_CONTROL
},
5592 { VK_MENU
, WXK_ALT
},
5593 { VK_PAUSE
, WXK_PAUSE
},
5594 { VK_CAPITAL
, WXK_CAPITAL
},
5595 { VK_SPACE
, WXK_SPACE
},
5596 { VK_ESCAPE
, WXK_ESCAPE
},
5597 { VK_SELECT
, WXK_SELECT
},
5598 { VK_PRINT
, WXK_PRINT
},
5599 { VK_EXECUTE
, WXK_EXECUTE
},
5600 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
5601 { VK_HELP
, WXK_HELP
},
5603 { VK_NUMPAD0
, WXK_NUMPAD0
},
5604 { VK_NUMPAD1
, WXK_NUMPAD1
},
5605 { VK_NUMPAD2
, WXK_NUMPAD2
},
5606 { VK_NUMPAD3
, WXK_NUMPAD3
},
5607 { VK_NUMPAD4
, WXK_NUMPAD4
},
5608 { VK_NUMPAD5
, WXK_NUMPAD5
},
5609 { VK_NUMPAD6
, WXK_NUMPAD6
},
5610 { VK_NUMPAD7
, WXK_NUMPAD7
},
5611 { VK_NUMPAD8
, WXK_NUMPAD8
},
5612 { VK_NUMPAD9
, WXK_NUMPAD9
},
5613 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
5614 { VK_ADD
, WXK_NUMPAD_ADD
},
5615 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
5616 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
5617 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
5628 { VK_F10
, WXK_F10
},
5629 { VK_F11
, WXK_F11
},
5630 { VK_F12
, WXK_F12
},
5631 { VK_F13
, WXK_F13
},
5632 { VK_F14
, WXK_F14
},
5633 { VK_F15
, WXK_F15
},
5634 { VK_F16
, WXK_F16
},
5635 { VK_F17
, WXK_F17
},
5636 { VK_F18
, WXK_F18
},
5637 { VK_F19
, WXK_F19
},
5638 { VK_F20
, WXK_F20
},
5639 { VK_F21
, WXK_F21
},
5640 { VK_F22
, WXK_F22
},
5641 { VK_F23
, WXK_F23
},
5642 { VK_F24
, WXK_F24
},
5644 { VK_NUMLOCK
, WXK_NUMLOCK
},
5645 { VK_SCROLL
, WXK_SCROLL
},
5648 { VK_LWIN
, WXK_WINDOWS_LEFT
},
5649 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
5650 { VK_APPS
, WXK_WINDOWS_MENU
},
5651 #endif // VK_APPS defined
5654 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
5655 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
5656 int wxCharCodeMSWToWX(int vk
, WXLPARAM lParam
)
5658 // check the table first
5659 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5661 if ( gs_specialKeys
[n
].vk
== vk
)
5662 return gs_specialKeys
[n
].wxk
;
5665 // keys requiring special handling
5669 // the mapping for these keys may be incorrect on non-US keyboards so
5670 // maybe we shouldn't map them to ASCII values at all
5671 case VK_OEM_1
: wxk
= ';'; break;
5672 case VK_OEM_PLUS
: wxk
= '+'; break;
5673 case VK_OEM_COMMA
: wxk
= ','; break;
5674 case VK_OEM_MINUS
: wxk
= '-'; break;
5675 case VK_OEM_PERIOD
: wxk
= '.'; break;
5676 case VK_OEM_2
: wxk
= '/'; break;
5677 case VK_OEM_3
: wxk
= '~'; break;
5678 case VK_OEM_4
: wxk
= '['; break;
5679 case VK_OEM_5
: wxk
= '\\'; break;
5680 case VK_OEM_6
: wxk
= ']'; break;
5681 case VK_OEM_7
: wxk
= '\''; break;
5683 // handle extended keys
5685 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
5689 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
5693 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
5697 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
5701 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
5705 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
5709 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
5713 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
5717 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
5721 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
5725 // don't use ChooseNormalOrExtended() here as the keys are reversed
5726 // here: numpad enter is the extended one
5727 wxk
= lParam
&& (lParam
& (1 << 24)) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
5737 WXWORD
wxCharCodeWXToMSW(int wxk
, bool *isVirtual
)
5742 // check the table first
5743 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5745 if ( gs_specialKeys
[n
].wxk
== wxk
)
5746 return gs_specialKeys
[n
].vk
;
5749 // and then check for special keys not included in the table
5754 case WXK_NUMPAD_PAGEUP
:
5759 case WXK_NUMPAD_PAGEDOWN
:
5764 case WXK_NUMPAD_END
:
5769 case WXK_NUMPAD_HOME
:
5774 case WXK_NUMPAD_LEFT
:
5784 case WXK_NUMPAD_RIGHT
:
5789 case WXK_NUMPAD_DOWN
:
5794 case WXK_NUMPAD_INSERT
:
5799 case WXK_NUMPAD_DELETE
:
5813 #ifndef SM_SWAPBUTTON
5814 #define SM_SWAPBUTTON 23
5817 // small helper for wxGetKeyState() and wxGetMouseState()
5818 static inline bool wxIsKeyDown(WXWORD vk
)
5823 if (GetSystemMetrics(SM_SWAPBUTTON
)) vk
= VK_RBUTTON
;
5826 if (GetSystemMetrics(SM_SWAPBUTTON
)) vk
= VK_LBUTTON
;
5829 // the low order bit indicates whether the key was pressed since the last
5830 // call and the high order one indicates whether it is down right now and
5831 // we only want that one
5832 return (GetAsyncKeyState(vk
) & (1<<15)) != 0;
5835 bool wxGetKeyState(wxKeyCode key
)
5837 // although this does work under Windows, it is not supported under other
5838 // platforms so don't allow it, you must use wxGetMouseState() instead
5839 wxASSERT_MSG( key
!= VK_LBUTTON
&&
5840 key
!= VK_RBUTTON
&&
5842 wxT("can't use wxGetKeyState() for mouse buttons") );
5844 const WXWORD vk
= wxCharCodeWXToMSW(key
);
5846 // if the requested key is a LED key, return true if the led is pressed
5847 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
5849 // low order bit means LED is highlighted and high order one means the
5850 // key is down; for compatibility with the other ports return true if
5851 // either one is set
5852 return GetKeyState(vk
) != 0;
5857 return wxIsKeyDown(vk
);
5862 wxMouseState
wxGetMouseState()
5866 GetCursorPos( &pt
);
5870 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
5871 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
5872 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
5874 ms
.SetControlDown(wxIsKeyDown(VK_CONTROL
));
5875 ms
.SetShiftDown(wxIsKeyDown(VK_SHIFT
));
5876 ms
.SetAltDown(wxIsKeyDown(VK_MENU
));
5877 // ms.SetMetaDown();
5883 wxWindow
*wxGetActiveWindow()
5885 HWND hWnd
= GetActiveWindow();
5888 return wxFindWinFromHandle((WXHWND
) hWnd
);
5893 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
5895 HWND hwnd
= (HWND
)hWnd
;
5897 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
5898 // by code in msw/radiobox.cpp), for all the others we just search up the
5900 wxWindow
*win
= (wxWindow
*)NULL
;
5903 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5907 // native radiobuttons return DLGC_RADIOBUTTON here and for any
5908 // wxWindow class which overrides WM_GETDLGCODE processing to
5909 // do it as well, win would be already non NULL
5910 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
5912 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
5914 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
5915 #endif // wxUSE_RADIOBOX
5917 // spin control text buddy window should be mapped to spin ctrl
5918 // itself so try it too
5919 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5922 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
5924 #endif // wxUSE_SPINCTRL
5928 while ( hwnd
&& !win
)
5930 // this is a really ugly hack needed to avoid mistakenly returning the
5931 // parent frame wxWindow for the find/replace modeless dialog HWND -
5932 // this, in turn, is needed to call IsDialogMessage() from
5933 // wxApp::ProcessMessage() as for this we must return NULL from here
5935 // FIXME: this is clearly not the best way to do it but I think we'll
5936 // need to change HWND <-> wxWindow code more heavily than I can
5937 // do it now to fix it
5938 #ifndef __WXMICROWIN__
5939 if ( ::GetWindow(hwnd
, GW_OWNER
) )
5941 // it's a dialog box, don't go upwards
5946 hwnd
= ::GetParent(hwnd
);
5947 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5953 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
5955 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
5956 // in active frames and dialogs, regardless of where the focus is.
5957 static HHOOK wxTheKeyboardHook
= 0;
5958 static FARPROC wxTheKeyboardHookProc
= 0;
5959 int APIENTRY _EXPORT
5960 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
5962 void wxSetKeyboardHook(bool doIt
)
5966 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
5967 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
5969 GetCurrentThreadId()
5970 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
5975 UnhookWindowsHookEx(wxTheKeyboardHook
);
5979 int APIENTRY _EXPORT
5980 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
5982 DWORD hiWord
= HIWORD(lParam
);
5983 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
5985 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5988 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
5989 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
5990 event
.m_altDown
= true;
5992 event
.SetEventObject(NULL
);
5993 event
.m_keyCode
= id
;
5994 event
.m_shiftDown
= wxIsShiftDown();
5995 event
.m_controlDown
= wxIsCtrlDown();
5997 event
.SetTimestamp(::GetMessageTime());
5999 wxWindow
*win
= wxGetActiveWindow();
6000 wxEvtHandler
*handler
;
6003 handler
= win
->GetEventHandler();
6004 event
.SetId(win
->GetId());
6009 event
.SetId(wxID_ANY
);
6012 if ( handler
&& handler
->ProcessEvent(event
) )
6020 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
6023 #endif // !__WXMICROWIN__
6026 const wxChar
*wxGetMessageName(int message
)
6030 case 0x0000: return wxT("WM_NULL");
6031 case 0x0001: return wxT("WM_CREATE");
6032 case 0x0002: return wxT("WM_DESTROY");
6033 case 0x0003: return wxT("WM_MOVE");
6034 case 0x0005: return wxT("WM_SIZE");
6035 case 0x0006: return wxT("WM_ACTIVATE");
6036 case 0x0007: return wxT("WM_SETFOCUS");
6037 case 0x0008: return wxT("WM_KILLFOCUS");
6038 case 0x000A: return wxT("WM_ENABLE");
6039 case 0x000B: return wxT("WM_SETREDRAW");
6040 case 0x000C: return wxT("WM_SETTEXT");
6041 case 0x000D: return wxT("WM_GETTEXT");
6042 case 0x000E: return wxT("WM_GETTEXTLENGTH");
6043 case 0x000F: return wxT("WM_PAINT");
6044 case 0x0010: return wxT("WM_CLOSE");
6045 case 0x0011: return wxT("WM_QUERYENDSESSION");
6046 case 0x0012: return wxT("WM_QUIT");
6047 case 0x0013: return wxT("WM_QUERYOPEN");
6048 case 0x0014: return wxT("WM_ERASEBKGND");
6049 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
6050 case 0x0016: return wxT("WM_ENDSESSION");
6051 case 0x0017: return wxT("WM_SYSTEMERROR");
6052 case 0x0018: return wxT("WM_SHOWWINDOW");
6053 case 0x0019: return wxT("WM_CTLCOLOR");
6054 case 0x001A: return wxT("WM_WININICHANGE");
6055 case 0x001B: return wxT("WM_DEVMODECHANGE");
6056 case 0x001C: return wxT("WM_ACTIVATEAPP");
6057 case 0x001D: return wxT("WM_FONTCHANGE");
6058 case 0x001E: return wxT("WM_TIMECHANGE");
6059 case 0x001F: return wxT("WM_CANCELMODE");
6060 case 0x0020: return wxT("WM_SETCURSOR");
6061 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6062 case 0x0022: return wxT("WM_CHILDACTIVATE");
6063 case 0x0023: return wxT("WM_QUEUESYNC");
6064 case 0x0024: return wxT("WM_GETMINMAXINFO");
6065 case 0x0026: return wxT("WM_PAINTICON");
6066 case 0x0027: return wxT("WM_ICONERASEBKGND");
6067 case 0x0028: return wxT("WM_NEXTDLGCTL");
6068 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6069 case 0x002B: return wxT("WM_DRAWITEM");
6070 case 0x002C: return wxT("WM_MEASUREITEM");
6071 case 0x002D: return wxT("WM_DELETEITEM");
6072 case 0x002E: return wxT("WM_VKEYTOITEM");
6073 case 0x002F: return wxT("WM_CHARTOITEM");
6074 case 0x0030: return wxT("WM_SETFONT");
6075 case 0x0031: return wxT("WM_GETFONT");
6076 case 0x0037: return wxT("WM_QUERYDRAGICON");
6077 case 0x0039: return wxT("WM_COMPAREITEM");
6078 case 0x0041: return wxT("WM_COMPACTING");
6079 case 0x0044: return wxT("WM_COMMNOTIFY");
6080 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6081 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6082 case 0x0048: return wxT("WM_POWER");
6084 case 0x004A: return wxT("WM_COPYDATA");
6085 case 0x004B: return wxT("WM_CANCELJOURNAL");
6086 case 0x004E: return wxT("WM_NOTIFY");
6087 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6088 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6089 case 0x0052: return wxT("WM_TCARD");
6090 case 0x0053: return wxT("WM_HELP");
6091 case 0x0054: return wxT("WM_USERCHANGED");
6092 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6093 case 0x007B: return wxT("WM_CONTEXTMENU");
6094 case 0x007C: return wxT("WM_STYLECHANGING");
6095 case 0x007D: return wxT("WM_STYLECHANGED");
6096 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6097 case 0x007F: return wxT("WM_GETICON");
6098 case 0x0080: return wxT("WM_SETICON");
6100 case 0x0081: return wxT("WM_NCCREATE");
6101 case 0x0082: return wxT("WM_NCDESTROY");
6102 case 0x0083: return wxT("WM_NCCALCSIZE");
6103 case 0x0084: return wxT("WM_NCHITTEST");
6104 case 0x0085: return wxT("WM_NCPAINT");
6105 case 0x0086: return wxT("WM_NCACTIVATE");
6106 case 0x0087: return wxT("WM_GETDLGCODE");
6107 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6108 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6109 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6110 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6111 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6112 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6113 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6114 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6115 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6116 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6118 case 0x00B0: return wxT("EM_GETSEL");
6119 case 0x00B1: return wxT("EM_SETSEL");
6120 case 0x00B2: return wxT("EM_GETRECT");
6121 case 0x00B3: return wxT("EM_SETRECT");
6122 case 0x00B4: return wxT("EM_SETRECTNP");
6123 case 0x00B5: return wxT("EM_SCROLL");
6124 case 0x00B6: return wxT("EM_LINESCROLL");
6125 case 0x00B7: return wxT("EM_SCROLLCARET");
6126 case 0x00B8: return wxT("EM_GETMODIFY");
6127 case 0x00B9: return wxT("EM_SETMODIFY");
6128 case 0x00BA: return wxT("EM_GETLINECOUNT");
6129 case 0x00BB: return wxT("EM_LINEINDEX");
6130 case 0x00BC: return wxT("EM_SETHANDLE");
6131 case 0x00BD: return wxT("EM_GETHANDLE");
6132 case 0x00BE: return wxT("EM_GETTHUMB");
6133 case 0x00C1: return wxT("EM_LINELENGTH");
6134 case 0x00C2: return wxT("EM_REPLACESEL");
6135 case 0x00C4: return wxT("EM_GETLINE");
6136 case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */
6137 case 0x00C6: return wxT("EM_CANUNDO");
6138 case 0x00C7: return wxT("EM_UNDO");
6139 case 0x00C8: return wxT("EM_FMTLINES");
6140 case 0x00C9: return wxT("EM_LINEFROMCHAR");
6141 case 0x00CB: return wxT("EM_SETTABSTOPS");
6142 case 0x00CC: return wxT("EM_SETPASSWORDCHAR");
6143 case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER");
6144 case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE");
6145 case 0x00CF: return wxT("EM_SETREADONLY");
6146 case 0x00D0: return wxT("EM_SETWORDBREAKPROC");
6147 case 0x00D1: return wxT("EM_GETWORDBREAKPROC");
6148 case 0x00D2: return wxT("EM_GETPASSWORDCHAR");
6149 case 0x00D3: return wxT("EM_SETMARGINS");
6150 case 0x00D4: return wxT("EM_GETMARGINS");
6151 case 0x00D5: return wxT("EM_GETLIMITTEXT");
6152 case 0x00D6: return wxT("EM_POSFROMCHAR");
6153 case 0x00D7: return wxT("EM_CHARFROMPOS");
6154 case 0x00D8: return wxT("EM_SETIMESTATUS");
6155 case 0x00D9: return wxT("EM_GETIMESTATUS");
6157 case 0x0100: return wxT("WM_KEYDOWN");
6158 case 0x0101: return wxT("WM_KEYUP");
6159 case 0x0102: return wxT("WM_CHAR");
6160 case 0x0103: return wxT("WM_DEADCHAR");
6161 case 0x0104: return wxT("WM_SYSKEYDOWN");
6162 case 0x0105: return wxT("WM_SYSKEYUP");
6163 case 0x0106: return wxT("WM_SYSCHAR");
6164 case 0x0107: return wxT("WM_SYSDEADCHAR");
6165 case 0x0108: return wxT("WM_KEYLAST");
6167 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6168 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6169 case 0x010F: return wxT("WM_IME_COMPOSITION");
6171 case 0x0110: return wxT("WM_INITDIALOG");
6172 case 0x0111: return wxT("WM_COMMAND");
6173 case 0x0112: return wxT("WM_SYSCOMMAND");
6174 case 0x0113: return wxT("WM_TIMER");
6175 case 0x0114: return wxT("WM_HSCROLL");
6176 case 0x0115: return wxT("WM_VSCROLL");
6177 case 0x0116: return wxT("WM_INITMENU");
6178 case 0x0117: return wxT("WM_INITMENUPOPUP");
6179 case 0x011F: return wxT("WM_MENUSELECT");
6180 case 0x0120: return wxT("WM_MENUCHAR");
6181 case 0x0121: return wxT("WM_ENTERIDLE");
6183 case 0x0132: return wxT("WM_CTLCOLORMSGBOX");
6184 case 0x0133: return wxT("WM_CTLCOLOREDIT");
6185 case 0x0134: return wxT("WM_CTLCOLORLISTBOX");
6186 case 0x0135: return wxT("WM_CTLCOLORBTN");
6187 case 0x0136: return wxT("WM_CTLCOLORDLG");
6188 case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR");
6189 case 0x0138: return wxT("WM_CTLCOLORSTATIC");
6190 case 0x01E1: return wxT("MN_GETHMENU");
6192 case 0x0200: return wxT("WM_MOUSEMOVE");
6193 case 0x0201: return wxT("WM_LBUTTONDOWN");
6194 case 0x0202: return wxT("WM_LBUTTONUP");
6195 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6196 case 0x0204: return wxT("WM_RBUTTONDOWN");
6197 case 0x0205: return wxT("WM_RBUTTONUP");
6198 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6199 case 0x0207: return wxT("WM_MBUTTONDOWN");
6200 case 0x0208: return wxT("WM_MBUTTONUP");
6201 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6202 case 0x020A: return wxT("WM_MOUSEWHEEL");
6203 case 0x0210: return wxT("WM_PARENTNOTIFY");
6204 case 0x0211: return wxT("WM_ENTERMENULOOP");
6205 case 0x0212: return wxT("WM_EXITMENULOOP");
6207 case 0x0213: return wxT("WM_NEXTMENU");
6208 case 0x0214: return wxT("WM_SIZING");
6209 case 0x0215: return wxT("WM_CAPTURECHANGED");
6210 case 0x0216: return wxT("WM_MOVING");
6211 case 0x0218: return wxT("WM_POWERBROADCAST");
6212 case 0x0219: return wxT("WM_DEVICECHANGE");
6214 case 0x0220: return wxT("WM_MDICREATE");
6215 case 0x0221: return wxT("WM_MDIDESTROY");
6216 case 0x0222: return wxT("WM_MDIACTIVATE");
6217 case 0x0223: return wxT("WM_MDIRESTORE");
6218 case 0x0224: return wxT("WM_MDINEXT");
6219 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6220 case 0x0226: return wxT("WM_MDITILE");
6221 case 0x0227: return wxT("WM_MDICASCADE");
6222 case 0x0228: return wxT("WM_MDIICONARRANGE");
6223 case 0x0229: return wxT("WM_MDIGETACTIVE");
6224 case 0x0230: return wxT("WM_MDISETMENU");
6225 case 0x0233: return wxT("WM_DROPFILES");
6227 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6228 case 0x0282: return wxT("WM_IME_NOTIFY");
6229 case 0x0283: return wxT("WM_IME_CONTROL");
6230 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6231 case 0x0285: return wxT("WM_IME_SELECT");
6232 case 0x0286: return wxT("WM_IME_CHAR");
6233 case 0x0290: return wxT("WM_IME_KEYDOWN");
6234 case 0x0291: return wxT("WM_IME_KEYUP");
6236 case 0x02A0: return wxT("WM_NCMOUSEHOVER");
6237 case 0x02A1: return wxT("WM_MOUSEHOVER");
6238 case 0x02A2: return wxT("WM_NCMOUSELEAVE");
6239 case 0x02A3: return wxT("WM_MOUSELEAVE");
6241 case 0x0300: return wxT("WM_CUT");
6242 case 0x0301: return wxT("WM_COPY");
6243 case 0x0302: return wxT("WM_PASTE");
6244 case 0x0303: return wxT("WM_CLEAR");
6245 case 0x0304: return wxT("WM_UNDO");
6246 case 0x0305: return wxT("WM_RENDERFORMAT");
6247 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6248 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6249 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6250 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6251 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6252 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6253 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6254 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6255 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6256 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6257 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6258 case 0x0311: return wxT("WM_PALETTECHANGED");
6259 case 0x0312: return wxT("WM_HOTKEY");
6261 case 0x0317: return wxT("WM_PRINT");
6262 case 0x0318: return wxT("WM_PRINTCLIENT");
6264 // common controls messages - although they're not strictly speaking
6265 // standard, it's nice to decode them nevertheless
6268 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6269 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6270 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6271 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6272 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6273 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6274 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6275 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6276 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6277 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6278 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6279 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6280 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6281 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6282 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6283 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6284 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6285 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6286 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6287 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6288 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6289 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6290 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6291 case 0x1000 + 18: return wxT("LVM_HITTEST");
6292 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6293 case 0x1000 + 20: return wxT("LVM_SCROLL");
6294 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6295 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6296 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6297 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6298 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6299 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6300 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6301 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6302 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6303 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6304 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6305 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6306 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6307 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6308 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6309 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6310 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6311 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6312 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6313 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6314 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6315 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6316 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6317 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6318 case 0x1000 + 42: return wxT("LVM_UPDATE");
6319 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6320 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6321 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6322 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6323 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6324 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6325 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6326 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6327 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6328 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6329 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6330 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6331 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6332 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6333 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6334 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6335 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6336 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6337 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6338 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6339 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6340 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6341 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6342 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6343 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6344 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6347 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6348 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6349 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6350 case 0x1100 + 2: return wxT("TVM_EXPAND");
6351 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6352 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6353 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6354 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6355 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6356 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6357 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6358 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6359 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6360 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6361 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6362 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6363 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6364 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6365 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6366 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6367 case 0x1100 + 17: return wxT("TVM_HITTEST");
6368 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6369 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6370 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6371 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6372 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6373 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6374 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6375 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6376 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6379 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6380 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6381 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6382 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6383 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6384 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6385 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6386 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6387 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6388 case 0x1200 + 6: return wxT("HDM_HITTEST");
6389 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6390 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6391 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6392 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6393 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6394 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6395 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6396 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6399 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6400 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6401 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6402 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6403 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6404 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6405 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6406 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6407 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6408 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6409 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6410 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6411 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6412 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6413 case 0x1300 + 13: return wxT("TCM_HITTEST");
6414 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6415 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6416 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6417 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6418 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6419 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6420 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6421 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6422 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6423 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6424 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6425 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6428 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6429 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
6430 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
6431 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
6432 case WM_USER
+5: return wxT("TB_INDETERMINATE");
6433 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
6434 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
6435 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
6436 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
6437 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
6438 case WM_USER
+17: return wxT("TB_SETSTATE");
6439 case WM_USER
+18: return wxT("TB_GETSTATE");
6440 case WM_USER
+19: return wxT("TB_ADDBITMAP");
6441 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
6442 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
6443 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
6444 case WM_USER
+23: return wxT("TB_GETBUTTON");
6445 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
6446 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
6447 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
6448 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
6449 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
6450 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
6451 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
6452 case WM_USER
+29: return wxT("TB_GETITEMRECT");
6453 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
6454 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
6455 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
6456 case WM_USER
+33: return wxT("TB_AUTOSIZE");
6457 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
6458 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
6459 case WM_USER
+37: return wxT("TB_SETPARENT");
6460 case WM_USER
+39: return wxT("TB_SETROWS");
6461 case WM_USER
+40: return wxT("TB_GETROWS");
6462 case WM_USER
+42: return wxT("TB_SETCMDID");
6463 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
6464 case WM_USER
+44: return wxT("TB_GETBITMAP");
6465 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
6466 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
6467 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
6468 case WM_USER
+47: return wxT("TB_SETINDENT");
6469 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
6470 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
6471 case WM_USER
+50: return wxT("TB_LOADIMAGES");
6472 case WM_USER
+51: return wxT("TB_GETRECT");
6473 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
6474 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
6475 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
6476 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
6477 case WM_USER
+56: return wxT("TB_SETSTYLE");
6478 case WM_USER
+57: return wxT("TB_GETSTYLE");
6479 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
6480 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
6481 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
6482 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
6483 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
6486 static wxString s_szBuf
;
6487 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
6488 return s_szBuf
.c_str();
6491 #endif //__WXDEBUG__
6493 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
6497 HWND hwnd
= GetHwndOf(win
);
6498 HDC hdc
= ::GetDC(hwnd
);
6500 #if !wxDIALOG_UNIT_COMPATIBILITY
6501 // and select the current font into it
6502 HFONT hfont
= GetHfontOf(win
->GetFont());
6505 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
6509 // finally retrieve the text metrics from it
6510 GetTextMetrics(hdc
, &tm
);
6512 #if !wxDIALOG_UNIT_COMPATIBILITY
6516 (void)::SelectObject(hdc
, hfont
);
6520 ::ReleaseDC(hwnd
, hdc
);
6525 // Find the wxWindow at the current mouse position, returning the mouse
6527 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
6529 pt
= wxGetMousePosition();
6530 return wxFindWindowAtPoint(pt
);
6533 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
6539 HWND hWnd
= ::WindowFromPoint(pt2
);
6541 return wxGetWindowFromHWND((WXHWND
)hWnd
);
6544 // Get the current mouse position.
6545 wxPoint
wxGetMousePosition()
6549 GetCursorPosWinCE(&pt
);
6551 GetCursorPos( & pt
);
6554 return wxPoint(pt
.x
, pt
.y
);
6559 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6560 static void WinCEUnregisterHotKey(int modifiers
, int id
)
6562 // Register hotkeys for the hardware buttons
6564 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
6566 UnregisterFunc1Proc procUnregisterFunc
;
6567 hCoreDll
= LoadLibrary(_T("coredll.dll"));
6570 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, _T("UnregisterFunc1"));
6571 if (procUnregisterFunc
)
6572 procUnregisterFunc(modifiers
, id
);
6573 FreeLibrary(hCoreDll
);
6578 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
6580 UINT win_modifiers
=0;
6581 if ( modifiers
& wxMOD_ALT
)
6582 win_modifiers
|= MOD_ALT
;
6583 if ( modifiers
& wxMOD_SHIFT
)
6584 win_modifiers
|= MOD_SHIFT
;
6585 if ( modifiers
& wxMOD_CONTROL
)
6586 win_modifiers
|= MOD_CONTROL
;
6587 if ( modifiers
& wxMOD_WIN
)
6588 win_modifiers
|= MOD_WIN
;
6590 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6591 // Required for PPC and Smartphone hardware buttons
6592 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
6593 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
6596 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
6598 wxLogLastError(_T("RegisterHotKey"));
6606 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
6608 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6609 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
6612 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
6614 wxLogLastError(_T("UnregisterHotKey"));
6624 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
6626 int hotkeyId
= wParam
;
6627 int virtualKey
= HIWORD(lParam
);
6628 int win_modifiers
= LOWORD(lParam
);
6630 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
6631 event
.SetId(hotkeyId
);
6632 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
6633 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
6634 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
6635 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
6637 return GetEventHandler()->ProcessEvent(event
);
6640 #endif // wxUSE_ACCEL
6642 #endif // wxUSE_HOTKEY
6644 // Not tested under WinCE
6647 // this class installs a message hook which really wakes up our idle processing
6648 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
6649 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
6650 // being dragged or even inside ::MessageBox()) and so don't control message
6651 // dispatching otherwise
6652 class wxIdleWakeUpModule
: public wxModule
6655 virtual bool OnInit()
6657 ms_hMsgHookProc
= ::SetWindowsHookEx
6660 &wxIdleWakeUpModule::MsgHookProc
,
6662 GetCurrentThreadId()
6665 if ( !ms_hMsgHookProc
)
6667 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
6675 virtual void OnExit()
6677 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
6680 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
6682 MSG
*msg
= (MSG
*)lParam
;
6684 // only process the message if it is actually going to be removed from
6685 // the message queue, this prevents that the same event from being
6686 // processed multiple times if now someone just called PeekMessage()
6687 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
6689 wxTheApp
->ProcessPendingEvents();
6692 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
6696 static HHOOK ms_hMsgHookProc
;
6698 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
6701 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
6703 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
6705 #endif // __WXWINCE__
6710 static void wxAdjustZOrder(wxWindow
* parent
)
6712 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
6714 // Set the z-order correctly
6715 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
6718 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
6721 wxWindow
*childWin
= current
->GetData();
6722 wxAdjustZOrder(childWin
);
6723 current
= current
->GetNext();
6728 // We need to adjust the z-order of static boxes in WinCE, to
6729 // make 'contained' controls visible
6730 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
6733 wxAdjustZOrder(this);