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"
34 #include "wx/dcclient.h"
35 #include "wx/dcmemory.h"
38 #include "wx/layout.h"
39 #include "wx/dialog.h"
41 #include "wx/listbox.h"
42 #include "wx/button.h"
43 #include "wx/msgdlg.h"
44 #include "wx/settings.h"
45 #include "wx/statbox.h"
49 #include "wx/textctrl.h"
50 #include "wx/menuitem.h"
51 #include "wx/module.h"
54 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
55 #include "wx/ownerdrw.h"
58 #include "wx/evtloop.h"
60 #include "wx/sysopt.h"
62 #if wxUSE_DRAG_AND_DROP
66 #if wxUSE_ACCESSIBILITY
67 #include "wx/access.h"
71 #define WM_GETOBJECT 0x003D
74 #define OBJID_CLIENT 0xFFFFFFFC
78 #include "wx/msw/private.h"
81 #include "wx/tooltip.h"
89 #include "wx/spinctrl.h"
90 #endif // wxUSE_SPINCTRL
92 #include "wx/notebook.h"
93 #include "wx/listctrl.h"
97 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
103 #include <windowsx.h>
106 // include <commctrl.h> "properly"
107 #include "wx/msw/wrapcctl.h"
109 #if !defined __WXWINCE__ && !defined NEED_PBT_H
113 #include "wx/msw/missing.h"
115 #if defined(__WXWINCE__)
116 #include "wx/msw/wince/missing.h"
119 #include <shellapi.h>
121 #include <aygshell.h>
125 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE)
126 #define HAVE_TRACKMOUSEEVENT
127 #endif // everything needed for TrackMouseEvent()
129 // if this is set to 1, we use deferred window sizing to reduce flicker when
130 // resizing complicated window hierarchies, but this can in theory result in
131 // different behaviour than the old code so we keep the possibility to use it
132 // by setting this to 0 (in the future this should be removed completely)
134 #define USE_DEFERRED_SIZING 0
136 #define USE_DEFERRED_SIZING 1
139 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
140 // when mouse position didnd't change
142 #define wxUSE_MOUSEEVENT_HACK 0
144 #define wxUSE_MOUSEEVENT_HACK 1
147 // ---------------------------------------------------------------------------
149 // ---------------------------------------------------------------------------
151 #if wxUSE_MENUS_NATIVE
152 wxMenu
*wxCurrentPopupMenu
= NULL
;
153 #endif // wxUSE_MENUS_NATIVE
156 extern wxChar
*wxCanvasClassName
;
158 extern const wxChar
*wxCanvasClassName
;
161 // true if we had already created the std colour map, used by
162 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
163 static bool gs_hasStdCmap
= false;
165 // last mouse event information we need to filter out the duplicates
166 #if wxUSE_MOUSEEVENT_HACK
167 static struct MouseEventInfoDummy
169 // mouse position (in screen coordinates)
172 // last mouse event type
175 #endif // wxUSE_MOUSEEVENT_HACK
177 // ---------------------------------------------------------------------------
179 // ---------------------------------------------------------------------------
181 // the window proc for all our windows
182 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
183 WPARAM wParam
, LPARAM lParam
);
187 const wxChar
*wxGetMessageName(int message
);
190 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
191 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
192 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
194 // get the text metrics for the current font
195 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
198 // find the window for the mouse event at the specified position
199 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
200 #endif // __WXWINCE__
202 // wrapper around BringWindowToTop() API
203 static inline void wxBringWindowToTop(HWND hwnd
)
205 #ifdef __WXMICROWIN__
206 // It seems that MicroWindows brings the _parent_ of the window to the top,
207 // which can be the wrong one.
209 // activate (set focus to) specified window
213 // raise top level parent to top of z order
214 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
216 wxLogLastError(_T("SetWindowPos"));
222 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
223 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
226 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
227 parent as well as otherwise several Win32 functions using
228 GetNextDlgTabItem() to iterate over all controls such as
229 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
230 all of them iterate over all the controls starting from the currently
231 focused one and stop iterating when they get back to the focus but
232 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
233 get back to the initial (focused) window: as we do have this style,
234 GetNextDlgTabItem() will leave this window and continue in its parent,
235 but if the parent doesn't have it, it wouldn't recurse inside it later
236 on and so wouldn't have a chance of getting back to this window either.
238 while ( parent
&& !parent
->IsTopLevel() )
240 LONG exStyle
= ::GetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
);
241 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
243 // force the parent to have this style
244 ::SetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
,
245 exStyle
| WS_EX_CONTROLPARENT
);
248 parent
= parent
->GetParent();
252 #endif // !__WXWINCE__
255 // On Windows CE, GetCursorPos can return an error, so use this function
257 bool GetCursorPosWinCE(POINT
* pt
)
259 if (!GetCursorPos(pt
))
261 DWORD pos
= GetMessagePos();
269 // ---------------------------------------------------------------------------
271 // ---------------------------------------------------------------------------
273 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
275 #ifdef __WXUNIVERSAL__
276 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
278 #if wxUSE_EXTENDED_RTTI
280 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
281 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
282 // windows with negative ids never can be recreated anyway
284 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
286 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
287 if ( win
&& win
->GetId() < 0 )
292 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
294 // make wxWindowList known before the property is used
296 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
298 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
300 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
303 WX_DEFINE_FLAGS( wxWindowStyle
)
305 wxBEGIN_FLAGS( wxWindowStyle
)
306 // new style border flags, we put them first to
307 // use them for streaming out
309 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
310 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
311 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
312 wxFLAGS_MEMBER(wxBORDER_RAISED
)
313 wxFLAGS_MEMBER(wxBORDER_STATIC
)
314 wxFLAGS_MEMBER(wxBORDER_NONE
)
316 // old style border flags
317 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
318 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
319 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
320 wxFLAGS_MEMBER(wxRAISED_BORDER
)
321 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
322 wxFLAGS_MEMBER(wxBORDER
)
324 // standard window styles
325 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
326 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
327 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
328 wxFLAGS_MEMBER(wxWANTS_CHARS
)
329 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
330 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
331 wxFLAGS_MEMBER(wxVSCROLL
)
332 wxFLAGS_MEMBER(wxHSCROLL
)
334 wxEND_FLAGS( wxWindowStyle
)
336 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
337 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
338 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
339 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
340 // Always constructor Properties first
342 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
343 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
344 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
345 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
346 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
348 // Then all relations of the object graph
350 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
352 // and finally all other properties
354 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
355 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
356 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
357 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
358 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
360 // possible property candidates (not in xrc) or not valid in all subclasses
361 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
362 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
363 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
364 // MaxHeight, Width , MinHeight , Width
365 // TODO switch label to control and title to toplevels
367 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
368 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
369 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
370 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
375 wxEND_PROPERTIES_TABLE()
377 wxBEGIN_HANDLERS_TABLE(wxWindow
)
378 wxEND_HANDLERS_TABLE()
380 wxCONSTRUCTOR_DUMMY(wxWindow
)
383 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
385 #endif // __WXUNIVERSAL__/__WXMSW__
387 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
388 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
389 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground
)
391 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
395 // ===========================================================================
397 // ===========================================================================
399 // ---------------------------------------------------------------------------
400 // wxWindow utility functions
401 // ---------------------------------------------------------------------------
403 // Find an item given the MS Windows id
404 wxWindow
*wxWindowMSW::FindItem(long id
) const
407 wxControl
*item
= wxDynamicCastThis(wxControl
);
410 // is it us or one of our "internal" children?
411 if ( item
->GetId() == id
412 #ifndef __WXUNIVERSAL__
413 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
414 #endif // __WXUNIVERSAL__
420 #endif // wxUSE_CONTROLS
422 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
425 wxWindow
*childWin
= current
->GetData();
427 wxWindow
*wnd
= childWin
->FindItem(id
);
431 current
= current
->GetNext();
437 // Find an item given the MS Windows handle
438 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
440 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
443 wxWindow
*parent
= current
->GetData();
445 // Do a recursive search.
446 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
452 || parent
->IsKindOf(CLASSINFO(wxControl
))
453 #endif // wxUSE_CONTROLS
456 wxWindow
*item
= current
->GetData();
457 if ( item
->GetHWND() == hWnd
)
461 if ( item
->ContainsHWND(hWnd
) )
466 current
= current
->GetNext();
471 // Default command handler
472 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
477 // ----------------------------------------------------------------------------
478 // constructors and such
479 // ----------------------------------------------------------------------------
481 void wxWindowMSW::Init()
484 m_isBeingDeleted
= false;
486 m_mouseInWindow
= false;
487 m_lastKeydownProcessed
= false;
489 m_childrenDisabled
= NULL
;
498 m_pendingPosition
= wxDefaultPosition
;
499 m_pendingSize
= wxDefaultSize
;
502 m_contextMenuEnabled
= false;
507 wxWindowMSW::~wxWindowMSW()
509 m_isBeingDeleted
= true;
511 #ifndef __WXUNIVERSAL__
512 // VS: make sure there's no wxFrame with last focus set to us:
513 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
515 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
518 if ( frame
->GetLastFocus() == this )
520 frame
->SetLastFocus(NULL
);
523 // apparently sometimes we can end up with our grand parent
524 // pointing to us as well: this is surely a bug in focus handling
525 // code but it's not clear where it happens so for now just try to
526 // fix it here by not breaking out of the loop
530 #endif // __WXUNIVERSAL__
532 // VS: destroy children first and _then_ detach *this from its parent.
533 // If we did it the other way around, children wouldn't be able
534 // find their parent frame (see above).
539 // VZ: test temp removed to understand what really happens here
540 //if (::IsWindow(GetHwnd()))
542 if ( !::DestroyWindow(GetHwnd()) )
543 wxLogLastError(wxT("DestroyWindow"));
546 // remove hWnd <-> wxWindow association
547 wxRemoveHandleAssociation(this);
550 delete m_childrenDisabled
;
554 // real construction (Init() must have been called before!)
555 bool wxWindowMSW::Create(wxWindow
*parent
,
560 const wxString
& name
)
562 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
564 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
567 parent
->AddChild(this);
570 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
572 #ifdef __WXUNIVERSAL__
573 // no borders, we draw them ourselves
574 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
578 msflags
&= ~WS_BORDER
;
579 #endif // wxUniversal
583 msflags
|= WS_VISIBLE
;
586 if ( !MSWCreate(wxCanvasClassName
, NULL
, pos
, size
, msflags
, exstyle
) )
594 // ---------------------------------------------------------------------------
596 // ---------------------------------------------------------------------------
598 void wxWindowMSW::SetFocus()
600 HWND hWnd
= GetHwnd();
601 wxCHECK_RET( hWnd
, _T("can't set focus to invalid window") );
603 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
607 if ( !::SetFocus(hWnd
) )
609 #if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
610 // was there really an error?
611 DWORD dwRes
= ::GetLastError();
614 HWND hwndFocus
= ::GetFocus();
615 if ( hwndFocus
!= hWnd
)
617 wxLogApiError(_T("SetFocus"), dwRes
);
624 void wxWindowMSW::SetFocusFromKbd()
626 // when the focus is given to the control with DLGC_HASSETSEL style from
627 // keyboard its contents should be entirely selected: this is what
628 // ::IsDialogMessage() does and so we should do it as well to provide the
629 // same LNF as the native programs
630 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
632 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
635 // do this after (maybe) setting the selection as like this when
636 // wxEVT_SET_FOCUS handler is called, the selection would have been already
637 // set correctly -- this may be important
638 wxWindowBase::SetFocusFromKbd();
641 // Get the window with the focus
642 wxWindow
*wxWindowBase::DoFindFocus()
644 HWND hWnd
= ::GetFocus();
647 return wxGetWindowFromHWND((WXHWND
)hWnd
);
653 bool wxWindowMSW::Enable(bool enable
)
655 if ( !wxWindowBase::Enable(enable
) )
658 HWND hWnd
= GetHwnd();
660 ::EnableWindow(hWnd
, (BOOL
)enable
);
662 // the logic below doesn't apply to the top level windows -- otherwise
663 // showing a modal dialog would result in total greying out (and ungreying
664 // out later) of everything which would be really ugly
668 // when the parent is disabled, all of its children should be disabled as
669 // well but when it is enabled back, only those of the children which
670 // hadn't been already disabled in the beginning should be enabled again,
671 // so we have to keep the list of those children
672 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
674 node
= node
->GetNext() )
676 wxWindow
*child
= node
->GetData();
677 if ( child
->IsTopLevel() )
679 // the logic below doesn't apply to top level children
685 // re-enable the child unless it had been disabled before us
686 if ( !m_childrenDisabled
|| !m_childrenDisabled
->Find(child
) )
689 else // we're being disabled
691 if ( child
->IsEnabled() )
693 // disable it as children shouldn't stay enabled while the
697 else // child already disabled, remember it
699 // have we created the list of disabled children already?
700 if ( !m_childrenDisabled
)
701 m_childrenDisabled
= new wxWindowList
;
703 m_childrenDisabled
->Append(child
);
708 if ( enable
&& m_childrenDisabled
)
710 // we don't need this list any more, don't keep unused memory
711 delete m_childrenDisabled
;
712 m_childrenDisabled
= NULL
;
718 bool wxWindowMSW::Show(bool show
)
720 if ( !wxWindowBase::Show(show
) )
723 HWND hWnd
= GetHwnd();
725 // we could be called before the underlying window is created (this is
726 // actually useful to prevent it from being initially shown), e.g.
728 // wxFoo *foo = new wxFoo;
730 // foo->Create(parent, ...);
732 // should work without errors
735 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
741 // Raise the window to the top of the Z order
742 void wxWindowMSW::Raise()
744 wxBringWindowToTop(GetHwnd());
747 // Lower the window to the bottom of the Z order
748 void wxWindowMSW::Lower()
750 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
751 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
754 void wxWindowMSW::DoCaptureMouse()
756 HWND hWnd
= GetHwnd();
763 void wxWindowMSW::DoReleaseMouse()
765 if ( !::ReleaseCapture() )
767 wxLogLastError(_T("ReleaseCapture"));
771 /* static */ wxWindow
*wxWindowBase::GetCapture()
773 HWND hwnd
= ::GetCapture();
774 return hwnd
? wxFindWinFromHandle((WXHWND
)hwnd
) : (wxWindow
*)NULL
;
777 bool wxWindowMSW::SetFont(const wxFont
& font
)
779 if ( !wxWindowBase::SetFont(font
) )
785 HWND hWnd
= GetHwnd();
788 WXHANDLE hFont
= m_font
.GetResourceHandle();
790 wxASSERT_MSG( hFont
, wxT("should have valid font") );
792 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
797 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
799 if ( !wxWindowBase::SetCursor(cursor
) )
805 // don't "overwrite" busy cursor
806 if ( m_cursor
.Ok() && !wxIsBusy() )
808 ::SetCursor(GetHcursorOf(m_cursor
));
814 void wxWindowMSW::WarpPointer(int x
, int y
)
816 ClientToScreen(&x
, &y
);
818 if ( !::SetCursorPos(x
, y
) )
820 wxLogLastError(_T("SetCursorPos"));
824 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
826 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
827 // to use it on older systems -- and could possibly do some harm
828 static int s_needToUpdate
= -1;
829 if ( s_needToUpdate
== -1 )
832 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
836 if ( s_needToUpdate
)
838 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
839 // won't send WM_UPDATEUISTATE
840 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
844 // ---------------------------------------------------------------------------
846 // ---------------------------------------------------------------------------
848 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
850 #ifdef __WXMICROWIN__
851 return ::GetScrollPosWX(hWnd
, wOrient
);
853 WinStruct
<SCROLLINFO
> scrollInfo
;
854 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
855 scrollInfo
.fMask
= SIF_POS
;
856 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
858 return scrollInfo
.nPos
;
863 int wxWindowMSW::GetScrollPos(int orient
) const
865 HWND hWnd
= GetHwnd();
866 wxCHECK_MSG( hWnd
, 0, _T("no HWND in GetScrollPos") );
868 return GetScrollPosition(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
);
871 // This now returns the whole range, not just the number
872 // of positions that we can scroll.
873 int wxWindowMSW::GetScrollRange(int orient
) const
876 HWND hWnd
= GetHwnd();
880 ::GetScrollRange(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
883 WinStruct
<SCROLLINFO
> scrollInfo
;
884 scrollInfo
.fMask
= SIF_RANGE
;
885 if ( !::GetScrollInfo(hWnd
,
886 orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
889 // Most of the time this is not really an error, since the return
890 // value can also be zero when there is no scrollbar yet.
891 // wxLogLastError(_T("GetScrollInfo"));
893 maxPos
= scrollInfo
.nMax
;
895 // undo "range - 1" done in SetScrollbar()
899 int wxWindowMSW::GetScrollThumb(int orient
) const
901 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
904 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
906 HWND hWnd
= GetHwnd();
907 wxCHECK_RET( hWnd
, _T("SetScrollPos: no HWND") );
909 WinStruct
<SCROLLINFO
> info
;
913 info
.fMask
= SIF_POS
;
914 if ( HasFlag(wxALWAYS_SHOW_SB
) )
916 // disable scrollbar instead of removing it then
917 info
.fMask
|= SIF_DISABLENOSCROLL
;
920 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
924 // New function that will replace some of the above.
925 void wxWindowMSW::SetScrollbar(int orient
,
931 WinStruct
<SCROLLINFO
> info
;
932 info
.nPage
= pageSize
;
933 info
.nMin
= 0; // range is nMax - nMin + 1
934 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
936 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
937 if ( HasFlag(wxALWAYS_SHOW_SB
) )
939 // disable scrollbar instead of removing it then
940 info
.fMask
|= SIF_DISABLENOSCROLL
;
943 HWND hWnd
= GetHwnd();
946 // We have to set the variables here to make them valid in events
947 // triggered by ::SetScrollInfo()
948 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
950 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
955 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
961 rect
.left
= prect
->x
;
963 rect
.right
= prect
->x
+ prect
->width
;
964 rect
.bottom
= prect
->y
+ prect
->height
;
974 // FIXME: is this the exact equivalent of the line below?
975 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
977 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
981 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
983 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
986 for ( int n
= 0; n
< count
; n
++ )
988 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
990 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
993 // don't bother to continue, we're already at top/bottom
1000 return pos
!= posStart
;
1003 bool wxWindowMSW::ScrollLines(int lines
)
1005 bool down
= lines
> 0;
1007 return ScrollVertically(GetHwnd(),
1008 down
? SB_LINEDOWN
: SB_LINEUP
,
1009 down
? lines
: -lines
);
1012 bool wxWindowMSW::ScrollPages(int pages
)
1014 bool down
= pages
> 0;
1016 return ScrollVertically(GetHwnd(),
1017 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1018 down
? pages
: -pages
);
1021 // ----------------------------------------------------------------------------
1023 // ----------------------------------------------------------------------------
1025 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
1030 const HWND hwnd
= GetHwnd();
1031 wxCHECK_RET( hwnd
, _T("layout direction must be set after window creation") );
1033 LONG styleOld
= ::GetWindowLong(hwnd
, GWL_EXSTYLE
);
1035 LONG styleNew
= styleOld
;
1038 case wxLayout_LeftToRight
:
1039 styleNew
&= ~WS_EX_LAYOUTRTL
;
1042 case wxLayout_RightToLeft
:
1043 styleNew
|= WS_EX_LAYOUTRTL
;
1047 wxFAIL_MSG(_T("unsupported layout direction"));
1051 if ( styleNew
!= styleOld
)
1053 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, styleNew
);
1058 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1061 return wxLayout_Default
;
1063 const HWND hwnd
= GetHwnd();
1064 wxCHECK_MSG( hwnd
, wxLayout_Default
, _T("invalid window") );
1066 return ::GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
1067 ? wxLayout_RightToLeft
1068 : wxLayout_LeftToRight
;
1073 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1074 wxCoord
WXUNUSED(width
),
1075 wxCoord
WXUNUSED(widthTotal
)) const
1077 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1078 // redo it ourselves
1082 // ---------------------------------------------------------------------------
1084 // ---------------------------------------------------------------------------
1086 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1088 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1090 HWND hwnd
= (HWND
)hWnd
;
1091 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1093 wxAssociateWinWithHandle(hwnd
, this);
1095 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1097 // we don't need to subclass the window of our own class (in the Windows
1098 // sense of the word)
1099 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1101 wxSetWindowProc(hwnd
, wxWndProc
);
1105 // don't bother restoring it either: this also makes it easy to
1106 // implement IsOfStandardClass() method which returns true for the
1107 // standard controls and false for the wxWidgets own windows as it can
1108 // simply check m_oldWndProc
1109 m_oldWndProc
= NULL
;
1112 // we're officially created now, send the event
1113 wxWindowCreateEvent
event((wxWindow
*)this);
1114 (void)GetEventHandler()->ProcessEvent(event
);
1117 void wxWindowMSW::UnsubclassWin()
1119 wxRemoveHandleAssociation(this);
1121 // Restore old Window proc
1122 HWND hwnd
= GetHwnd();
1127 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1131 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1133 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1136 m_oldWndProc
= NULL
;
1141 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1145 if ( !::DestroyWindow(GetHwnd()) )
1146 wxLogLastError(wxT("DestroyWindow"));
1149 WXHWND wxhwnd
= (WXHWND
)handle
;
1152 SubclassWin(wxhwnd
);
1155 void wxWindowMSW::DissociateHandle()
1157 // this also calls SetHWND(0) for us
1162 bool wxCheckWindowWndProc(WXHWND hWnd
,
1163 WXFARPROC
WXUNUSED(wndProc
))
1165 // TODO: This list of window class names should be factored out so they can be
1166 // managed in one place and then accessed from here and other places, such as
1167 // wxApp::RegisterWindowClasses() and wxApp::UnregisterWindowClasses()
1170 extern wxChar
*wxCanvasClassName
;
1171 extern wxChar
*wxCanvasClassNameNR
;
1173 extern const wxChar
*wxCanvasClassName
;
1174 extern const wxChar
*wxCanvasClassNameNR
;
1176 extern const wxChar
*wxMDIFrameClassName
;
1177 extern const wxChar
*wxMDIFrameClassNameNoRedraw
;
1178 extern const wxChar
*wxMDIChildFrameClassName
;
1179 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
1180 wxString
str(wxGetWindowClass(hWnd
));
1181 if (str
== wxCanvasClassName
||
1182 str
== wxCanvasClassNameNR
||
1184 str
== _T("wxGLCanvasClass") ||
1185 str
== _T("wxGLCanvasClassNR") ||
1186 #endif // wxUSE_GLCANVAS
1187 str
== wxMDIFrameClassName
||
1188 str
== wxMDIFrameClassNameNoRedraw
||
1189 str
== wxMDIChildFrameClassName
||
1190 str
== wxMDIChildFrameClassNameNoRedraw
||
1191 str
== _T("wxTLWHiddenParent"))
1192 return true; // Effectively means don't subclass
1197 // ----------------------------------------------------------------------------
1199 // ----------------------------------------------------------------------------
1201 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1203 long flagsOld
= GetWindowStyleFlag();
1204 if ( flags
== flagsOld
)
1207 // update the internal variable
1208 wxWindowBase::SetWindowStyleFlag(flags
);
1210 // and the real window flags
1211 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1214 void wxWindowMSW::SetExtraStyle(long exflags
)
1216 long exflagsOld
= GetExtraStyle();
1217 if ( exflags
== exflagsOld
)
1220 // update the internal variable
1221 wxWindowBase::SetExtraStyle(exflags
);
1223 // and the real window flags
1224 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1227 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1229 // now update the Windows style as well if needed - and if the window had
1230 // been already created
1234 // we may need to call SetWindowPos() when we change some styles
1235 bool callSWP
= false;
1238 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1240 // this is quite a horrible hack but we need it because MSWGetStyle()
1241 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1242 // and so we have to modify the window exflags temporarily to get the
1243 // correct exstyleOld
1244 long exflagsNew
= GetExtraStyle();
1245 wxWindowBase::SetExtraStyle(exflagsOld
);
1248 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1250 wxWindowBase::SetExtraStyle(exflagsNew
);
1253 if ( style
!= styleOld
)
1255 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1256 // this function so instead of simply setting the style to the new
1257 // value we clear the bits which were set in styleOld but are set in
1258 // the new one and set the ones which were not set before
1259 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1260 styleReal
&= ~styleOld
;
1263 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1265 // we need to call SetWindowPos() if any of the styles affecting the
1266 // frame appearance have changed
1267 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1276 // and the extended style
1277 long exstyleReal
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1279 if ( exstyle
!= exstyleOld
)
1281 exstyleReal
&= ~exstyleOld
;
1282 exstyleReal
|= exstyle
;
1284 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyleReal
);
1286 // ex style changes don't take effect without calling SetWindowPos
1292 // we must call SetWindowPos() to flush the cached extended style and
1293 // also to make the change to wxSTAY_ON_TOP style take effect: just
1294 // setting the style simply doesn't work
1295 if ( !::SetWindowPos(GetHwnd(),
1296 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1299 SWP_NOMOVE
| SWP_NOSIZE
| SWP_FRAMECHANGED
) )
1301 wxLogLastError(_T("SetWindowPos"));
1306 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1308 // translate common wxWidgets styles to Windows ones
1310 // most of windows are child ones, those which are not (such as
1311 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1312 WXDWORD style
= WS_CHILD
;
1314 // using this flag results in very significant reduction in flicker,
1315 // especially with controls inside the static boxes (as the interior of the
1316 // box is not redrawn twice), but sometimes results in redraw problems, so
1317 // optionally allow the old code to continue to use it provided a special
1318 // system option is turned on
1319 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1320 || (flags
& wxCLIP_CHILDREN
) )
1321 style
|= WS_CLIPCHILDREN
;
1323 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1324 // don't support overlapping windows and it only makes sense for them and,
1325 // presumably, gives the system some extra work (to manage more clipping
1326 // regions), so avoid it alltogether
1329 if ( flags
& wxVSCROLL
)
1330 style
|= WS_VSCROLL
;
1332 if ( flags
& wxHSCROLL
)
1333 style
|= WS_HSCROLL
;
1335 const wxBorder border
= GetBorder(flags
);
1337 // WS_BORDER is only required for wxBORDER_SIMPLE
1338 if ( border
== wxBORDER_SIMPLE
)
1341 // now deal with ext style if the caller wants it
1347 if ( flags
& wxTRANSPARENT_WINDOW
)
1348 *exstyle
|= WS_EX_TRANSPARENT
;
1354 case wxBORDER_DEFAULT
:
1355 wxFAIL_MSG( _T("unknown border style") );
1359 case wxBORDER_SIMPLE
:
1362 case wxBORDER_STATIC
:
1363 *exstyle
|= WS_EX_STATICEDGE
;
1366 case wxBORDER_RAISED
:
1367 *exstyle
|= WS_EX_DLGMODALFRAME
;
1370 case wxBORDER_SUNKEN
:
1371 *exstyle
|= WS_EX_CLIENTEDGE
;
1372 style
&= ~WS_BORDER
;
1375 case wxBORDER_DOUBLE
:
1376 *exstyle
|= WS_EX_DLGMODALFRAME
;
1380 // wxUniv doesn't use Windows dialog navigation functions at all
1381 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1382 // to make the dialog navigation work with the nested panels we must
1383 // use this style (top level windows such as dialogs don't need it)
1384 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1386 *exstyle
|= WS_EX_CONTROLPARENT
;
1388 #endif // __WXUNIVERSAL__
1394 // Setup background and foreground colours correctly
1395 void wxWindowMSW::SetupColours()
1398 SetBackgroundColour(GetParent()->GetBackgroundColour());
1401 bool wxWindowMSW::IsMouseInWindow() const
1403 // get the mouse position
1406 ::GetCursorPosWinCE(&pt
);
1408 ::GetCursorPos(&pt
);
1411 // find the window which currently has the cursor and go up the window
1412 // chain until we find this window - or exhaust it
1413 HWND hwnd
= ::WindowFromPoint(pt
);
1414 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1415 hwnd
= ::GetParent(hwnd
);
1417 return hwnd
!= NULL
;
1420 void wxWindowMSW::OnInternalIdle()
1422 #ifndef HAVE_TRACKMOUSEEVENT
1423 // Check if we need to send a LEAVE event
1424 if ( m_mouseInWindow
)
1426 // note that we should generate the leave event whether the window has
1427 // or doesn't have mouse capture
1428 if ( !IsMouseInWindow() )
1430 GenerateMouseLeave();
1433 #endif // !HAVE_TRACKMOUSEEVENT
1435 if (wxUpdateUIEvent::CanUpdate(this))
1436 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1439 // Set this window to be the child of 'parent'.
1440 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1442 if ( !wxWindowBase::Reparent(parent
) )
1445 HWND hWndChild
= GetHwnd();
1446 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1448 ::SetParent(hWndChild
, hWndParent
);
1451 if ( ::GetWindowLong(hWndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1453 EnsureParentHasControlParentStyle(GetParent());
1455 #endif // !__WXWINCE__
1460 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1462 #ifndef __WXMICROWIN__
1463 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1467 void wxWindowMSW::Freeze()
1469 if ( !m_frozenness
++ )
1472 SendSetRedraw(GetHwnd(), false);
1476 void wxWindowMSW::Thaw()
1478 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1480 if ( --m_frozenness
== 0 )
1484 SendSetRedraw(GetHwnd(), true);
1486 // we need to refresh everything or otherwise the invalidated area
1487 // is not going to be repainted
1493 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1495 HWND hWnd
= GetHwnd();
1502 mswRect
.left
= rect
->x
;
1503 mswRect
.top
= rect
->y
;
1504 mswRect
.right
= rect
->x
+ rect
->width
;
1505 mswRect
.bottom
= rect
->y
+ rect
->height
;
1514 // RedrawWindow not available on SmartPhone or eVC++ 3
1515 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1516 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1520 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1522 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1527 void wxWindowMSW::Update()
1529 if ( !::UpdateWindow(GetHwnd()) )
1531 wxLogLastError(_T("UpdateWindow"));
1534 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1535 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1536 // handler needs to be really drawn right now
1541 // ---------------------------------------------------------------------------
1543 // ---------------------------------------------------------------------------
1545 // we need to lower the sibling static boxes so controls contained within can be
1547 static inline void AdjustStaticBoxZOrder(wxWindow
*parent
)
1549 // no sibling static boxes if we have no parent (ie TLW)
1553 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1555 node
= node
->GetNext() )
1557 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1560 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1561 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1566 #if wxUSE_DRAG_AND_DROP
1567 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1569 if ( m_dropTarget
!= 0 ) {
1570 m_dropTarget
->Revoke(m_hWnd
);
1571 delete m_dropTarget
;
1574 m_dropTarget
= pDropTarget
;
1575 if ( m_dropTarget
!= 0 )
1577 AdjustStaticBoxZOrder(GetParent());
1578 m_dropTarget
->Register(m_hWnd
);
1581 #endif // wxUSE_DRAG_AND_DROP
1583 // old-style file manager drag&drop support: we retain the old-style
1584 // DragAcceptFiles in parallel with SetDropTarget.
1585 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1588 HWND hWnd
= GetHwnd();
1591 AdjustStaticBoxZOrder(GetParent());
1592 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1597 // ----------------------------------------------------------------------------
1599 // ----------------------------------------------------------------------------
1603 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1605 wxWindowBase::DoSetToolTip(tooltip
);
1608 m_tooltip
->SetWindow((wxWindow
*)this);
1611 #endif // wxUSE_TOOLTIPS
1613 // ---------------------------------------------------------------------------
1614 // moving and resizing
1615 // ---------------------------------------------------------------------------
1617 bool wxWindowMSW::IsSizeDeferred() const
1619 #if USE_DEFERRED_SIZING
1620 if ( m_pendingPosition
!= wxDefaultPosition
||
1621 m_pendingSize
!= wxDefaultSize
)
1623 #endif // USE_DEFERRED_SIZING
1629 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1631 #if USE_DEFERRED_SIZING
1632 // if SetSize() had been called at wx level but not realized at Windows
1633 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1634 // the new and not the old position to the other wx code
1635 if ( m_pendingSize
!= wxDefaultSize
)
1638 *x
= m_pendingSize
.x
;
1640 *y
= m_pendingSize
.y
;
1642 else // use current size
1643 #endif // USE_DEFERRED_SIZING
1645 RECT rect
= wxGetWindowRect(GetHwnd());
1648 *x
= rect
.right
- rect
.left
;
1650 *y
= rect
.bottom
- rect
.top
;
1654 // Get size *available for subwindows* i.e. excluding menu bar etc.
1655 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1657 #if USE_DEFERRED_SIZING
1658 if ( m_pendingSize
!= wxDefaultSize
)
1660 // we need to calculate the client size corresponding to pending size
1662 rect
.left
= m_pendingPosition
.x
;
1663 rect
.top
= m_pendingPosition
.y
;
1664 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1665 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1667 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1670 *x
= rect
.right
- rect
.left
;
1672 *y
= rect
.bottom
- rect
.top
;
1675 #endif // USE_DEFERRED_SIZING
1677 RECT rect
= wxGetClientRect(GetHwnd());
1686 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1688 wxWindow
* const parent
= GetParent();
1691 if ( m_pendingPosition
!= wxDefaultPosition
)
1693 pos
= m_pendingPosition
;
1695 else // use current position
1697 RECT rect
= wxGetWindowRect(GetHwnd());
1700 point
.x
= rect
.left
;
1703 // we do the adjustments with respect to the parent only for the "real"
1704 // children, not for the dialogs/frames
1705 if ( !IsTopLevel() )
1707 // Since we now have the absolute screen coords, if there's a
1708 // parent we must subtract its top left corner
1711 ::ScreenToClient(GetHwndOf(parent
), &point
);
1719 // we also must adjust by the client area offset: a control which is just
1720 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1721 if ( parent
&& !IsTopLevel() )
1723 const wxPoint
pt(parent
->GetClientAreaOrigin());
1734 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1742 ::ScreenToClient(GetHwnd(), &pt
);
1750 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1758 ::ClientToScreen(GetHwnd(), &pt
);
1767 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1769 #if USE_DEFERRED_SIZING
1770 // if our parent had prepared a defer window handle for us, use it (unless
1771 // we are a top level window)
1772 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1774 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1777 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1778 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1781 wxLogLastError(_T("DeferWindowPos"));
1787 // hdwp must be updated as it may have been changed
1788 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1793 // did deferred move, remember new coordinates of the window as they're
1794 // different from what Windows would return for it
1798 // otherwise (or if deferring failed) move the window in place immediately
1799 #endif // USE_DEFERRED_SIZING
1800 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
1802 wxLogLastError(wxT("MoveWindow"));
1805 // if USE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1806 // ignored otherwise
1810 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1812 // TODO: is this consistent with other platforms?
1813 // Still, negative width or height shouldn't be allowed
1819 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
1821 #if USE_DEFERRED_SIZING
1822 m_pendingPosition
= wxPoint(x
, y
);
1823 m_pendingSize
= wxSize(width
, height
);
1824 #endif // USE_DEFERRED_SIZING
1828 // set the size of the window: if the dimensions are positive, just use them,
1829 // but if any of them is equal to -1, it means that we must find the value for
1830 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1831 // which case -1 is a valid value for x and y)
1833 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1834 // the width/height to best suit our contents, otherwise we reuse the current
1836 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1838 // get the current size and position...
1839 int currentX
, currentY
;
1840 int currentW
, currentH
;
1842 GetPosition(¤tX
, ¤tY
);
1843 GetSize(¤tW
, ¤tH
);
1845 // ... and don't do anything (avoiding flicker) if it's already ok unless
1846 // we're forced to resize the window
1847 if ( x
== currentX
&& y
== currentY
&&
1848 width
== currentW
&& height
== currentH
&&
1849 !(sizeFlags
& wxSIZE_FORCE
) )
1854 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1856 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1859 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1861 wxSize size
= wxDefaultSize
;
1862 if ( width
== wxDefaultCoord
)
1864 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1866 size
= DoGetBestSize();
1871 // just take the current one
1876 if ( height
== wxDefaultCoord
)
1878 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1880 if ( size
.x
== wxDefaultCoord
)
1882 size
= DoGetBestSize();
1884 //else: already called DoGetBestSize() above
1890 // just take the current one
1895 DoMoveWindow(x
, y
, width
, height
);
1898 void wxWindowMSW::DoSetClientSize(int width
, int height
)
1900 // setting the client size is less obvious than it could have been
1901 // because in the result of changing the total size the window scrollbar
1902 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
1903 // doesn't take neither into account) and so the client size will not be
1904 // correct as the difference between the total and client size changes --
1905 // so we keep changing it until we get it right
1907 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1908 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1909 // may become 3 if the window had 0 size originally and so we didn't
1910 // calculate the scrollbar correction correctly during the first iteration)
1911 // but just to be on the safe side we check for it instead of making it an
1912 // "infinite" loop (i.e. leaving break inside as the only way to get out)
1913 for ( int i
= 0; i
< 4; i
++ )
1916 ::GetClientRect(GetHwnd(), &rectClient
);
1918 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
1919 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
1920 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
1925 // Find the difference between the entire window (title bar and all)
1926 // and the client area; add this to the new client size to move the
1929 ::GetWindowRect(GetHwnd(), &rectWin
);
1931 const int widthWin
= rectWin
.right
- rectWin
.left
,
1932 heightWin
= rectWin
.bottom
- rectWin
.top
;
1934 // MoveWindow positions the child windows relative to the parent, so
1935 // adjust if necessary
1936 if ( !IsTopLevel() )
1938 wxWindow
*parent
= GetParent();
1941 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
1945 // don't call DoMoveWindow() because we want to move window immediately
1946 // and not defer it here as otherwise the value returned by
1947 // GetClient/WindowRect() wouldn't change as the window wouldn't be
1949 if ( !::MoveWindow(GetHwnd(),
1952 width
+ widthWin
- rectClient
.right
,
1953 height
+ heightWin
- rectClient
.bottom
,
1956 wxLogLastError(_T("MoveWindow"));
1961 // ---------------------------------------------------------------------------
1963 // ---------------------------------------------------------------------------
1965 int wxWindowMSW::GetCharHeight() const
1967 return wxGetTextMetrics(this).tmHeight
;
1970 int wxWindowMSW::GetCharWidth() const
1972 // +1 is needed because Windows apparently adds it when calculating the
1973 // dialog units size in pixels
1974 #if wxDIALOG_UNIT_COMPATIBILITY
1975 return wxGetTextMetrics(this).tmAveCharWidth
;
1977 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
1981 void wxWindowMSW::GetTextExtent(const wxString
& string
,
1983 int *descent
, int *externalLeading
,
1984 const wxFont
*theFont
) const
1986 wxASSERT_MSG( !theFont
|| theFont
->Ok(),
1987 _T("invalid font in GetTextExtent()") );
1991 fontToUse
= *theFont
;
1993 fontToUse
= GetFont();
1995 WindowHDC
hdc(GetHwnd());
1996 SelectInHDC
selectFont(hdc
, GetHfontOf(fontToUse
));
2000 ::GetTextExtentPoint32(hdc
, string
, string
.length(), &sizeRect
);
2001 GetTextMetrics(hdc
, &tm
);
2008 *descent
= tm
.tmDescent
;
2009 if ( externalLeading
)
2010 *externalLeading
= tm
.tmExternalLeading
;
2013 // ---------------------------------------------------------------------------
2015 // ---------------------------------------------------------------------------
2017 #if wxUSE_MENUS_NATIVE
2019 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2020 // immediately, without waiting for the next event loop iteration
2022 // NB: this function should probably be made public later as it can almost
2023 // surely replace wxYield() elsewhere as well
2024 static void wxYieldForCommandsOnly()
2026 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2027 // want to process it here)
2029 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2031 if ( msg
.message
== WM_QUIT
)
2033 // if we retrieved a WM_QUIT, insert back into the message queue.
2034 ::PostQuitMessage(0);
2038 // luckily (as we don't have access to wxEventLoopImpl method from here
2039 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2041 ::TranslateMessage(&msg
);
2042 ::DispatchMessage(&msg
);
2046 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2048 menu
->SetInvokingWindow(this);
2051 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2053 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2054 x
= mouse
.x
; y
= mouse
.y
;
2057 HWND hWnd
= GetHwnd();
2058 HMENU hMenu
= GetHmenuOf(menu
);
2062 ::ClientToScreen(hWnd
, &point
);
2063 wxCurrentPopupMenu
= menu
;
2064 #if defined(__WXWINCE__)
2067 UINT flags
= TPM_RIGHTBUTTON
| TPM_RECURSE
;
2069 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2071 // we need to do it right now as otherwise the events are never going to be
2072 // sent to wxCurrentPopupMenu from HandleCommand()
2074 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2075 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2076 // destroyed as soon as we return (it can be a local variable in the caller
2077 // for example) and so we do need to process the event immediately
2078 wxYieldForCommandsOnly();
2080 wxCurrentPopupMenu
= NULL
;
2082 menu
->SetInvokingWindow(NULL
);
2087 #endif // wxUSE_MENUS_NATIVE
2089 // ===========================================================================
2090 // pre/post message processing
2091 // ===========================================================================
2093 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2096 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2098 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2101 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2103 // wxUniversal implements tab traversal itself
2104 #ifndef __WXUNIVERSAL__
2105 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2107 // intercept dialog navigation keys
2108 MSG
*msg
= (MSG
*)pMsg
;
2110 // here we try to do all the job which ::IsDialogMessage() usually does
2112 if ( msg
->message
== WM_KEYDOWN
)
2114 bool bCtrlDown
= wxIsCtrlDown();
2115 bool bShiftDown
= wxIsShiftDown();
2117 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2118 // don't process it if it's the case (except for Ctrl-Tab/Enter
2119 // combinations which are always processed)
2120 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2122 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2123 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2124 // it, of course, implies them
2125 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2127 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2130 bool bForward
= true,
2131 bWindowChange
= false,
2134 // should we process this message specially?
2135 bool bProcess
= true;
2136 switch ( msg
->wParam
)
2139 if ( lDlgCode
& DLGC_WANTTAB
) {
2143 // Ctrl-Tab cycles thru notebook pages
2144 bWindowChange
= bCtrlDown
;
2145 bForward
= !bShiftDown
;
2152 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2160 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2169 // we treat PageUp/Dn as arrows because chances are that
2170 // a control which needs arrows also needs them for
2171 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2172 if ( (lDlgCode
& DLGC_WANTARROWS
) || !bCtrlDown
)
2175 bWindowChange
= true;
2180 if ( (lDlgCode
& DLGC_WANTMESSAGE
) && !bCtrlDown
)
2182 // control wants to process Enter itself, don't
2183 // call IsDialogMessage() which would consume it
2188 // currently active button should get enter press even
2189 // if there is a default button elsewhere so check if
2190 // this window is a button first
2191 wxWindow
*btn
= NULL
;
2192 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2194 // let IsDialogMessage() handle this for all
2195 // buttons except the owner-drawn ones which it
2196 // just seems to ignore
2197 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2198 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2200 // emulate the button click
2201 btn
= wxFindWinFromHandle((WXHWND
)msg
->hwnd
);
2206 else // not a button itself, do we have default button?
2209 tlw
= wxDynamicCast(wxGetTopLevelParent(this),
2213 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2218 if ( btn
&& btn
->IsEnabled() )
2220 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2224 #endif // wxUSE_BUTTON
2227 // map Enter presses into button presses on PDAs
2228 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2229 event
.SetEventObject(this);
2230 if ( GetEventHandler()->ProcessEvent(event
) )
2232 #endif // __WXWINCE__
2242 wxNavigationKeyEvent event
;
2243 event
.SetDirection(bForward
);
2244 event
.SetWindowChange(bWindowChange
);
2245 event
.SetFromTab(bFromTab
);
2246 event
.SetEventObject(this);
2248 if ( GetEventHandler()->ProcessEvent(event
) )
2250 // as we don't call IsDialogMessage(), which would take of
2251 // this by default, we need to manually send this message
2252 // so that controls can change their UI state if needed
2253 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2260 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2261 // message even when there is no cancel button and when the message is
2262 // needed by the control itself: in particular, it prevents the tree in
2263 // place edit control from being closed with Escape in a dialog
2264 if ( msg
->message
!= WM_KEYDOWN
|| msg
->wParam
!= VK_ESCAPE
)
2266 // ::IsDialogMessage() is broken and may sometimes hang the
2267 // application by going into an infinite loop, so we try to detect
2268 // [some of] the situations when this may happen and not call it
2271 // assume we can call it by default
2272 bool canSafelyCallIsDlgMsg
= true;
2274 HWND hwndFocus
= ::GetFocus();
2276 // if the currently focused window itself has WS_EX_CONTROLPARENT style, ::IsDialogMessage() will also enter
2277 // an infinite loop, because it will recursively check the child
2278 // windows but not the window itself and so if none of the children
2279 // accepts focus it loops forever (as it only stops when it gets
2280 // back to the window it started from)
2282 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2283 // style has the focus, it can happen. One such possibility is if
2284 // all windows are either toplevel, wxDialog, wxPanel or static
2285 // controls and no window can actually accept keyboard input.
2286 #if !defined(__WXWINCE__)
2287 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2289 // pessimistic by default
2290 canSafelyCallIsDlgMsg
= false;
2291 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2293 node
= node
->GetNext() )
2295 wxWindow
* const win
= node
->GetData();
2296 if ( win
->AcceptsFocus() &&
2297 !(::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
) &
2298 WS_EX_CONTROLPARENT
) )
2300 // it shouldn't hang...
2301 canSafelyCallIsDlgMsg
= true;
2307 #endif // !__WXWINCE__
2309 if ( canSafelyCallIsDlgMsg
)
2311 // ::IsDialogMessage() can enter in an infinite loop when the
2312 // currently focused window is disabled or hidden and its
2313 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2317 if ( !::IsWindowEnabled(hwndFocus
) ||
2318 !::IsWindowVisible(hwndFocus
) )
2320 // it would enter an infinite loop if we do this!
2321 canSafelyCallIsDlgMsg
= false;
2326 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2328 // it's a top level window, don't go further -- e.g. even
2329 // if the parent of a dialog is disabled, this doesn't
2330 // break navigation inside the dialog
2334 hwndFocus
= ::GetParent(hwndFocus
);
2338 // let IsDialogMessage() have the message if it's safe to call it
2339 if ( canSafelyCallIsDlgMsg
&& ::IsDialogMessage(GetHwnd(), msg
) )
2341 // IsDialogMessage() did something...
2346 #endif // __WXUNIVERSAL__
2351 // relay mouse move events to the tooltip control
2352 MSG
*msg
= (MSG
*)pMsg
;
2353 if ( msg
->message
== WM_MOUSEMOVE
)
2354 wxToolTip::RelayEvent(pMsg
);
2356 #endif // wxUSE_TOOLTIPS
2361 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2363 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2364 return m_acceleratorTable
.Translate(this, pMsg
);
2368 #endif // wxUSE_ACCEL
2371 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* WXUNUSED(pMsg
))
2373 // preprocess all messages by default
2377 // ---------------------------------------------------------------------------
2378 // message params unpackers
2379 // ---------------------------------------------------------------------------
2381 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2382 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2384 *id
= LOWORD(wParam
);
2385 *hwnd
= (WXHWND
)lParam
;
2386 *cmd
= HIWORD(wParam
);
2389 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2390 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2392 *state
= LOWORD(wParam
);
2393 *minimized
= HIWORD(wParam
);
2394 *hwnd
= (WXHWND
)lParam
;
2397 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2398 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2400 *code
= LOWORD(wParam
);
2401 *pos
= HIWORD(wParam
);
2402 *hwnd
= (WXHWND
)lParam
;
2405 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2406 WXHDC
*hdc
, WXHWND
*hwnd
)
2408 *hwnd
= (WXHWND
)lParam
;
2409 *hdc
= (WXHDC
)wParam
;
2412 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2413 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2415 *item
= (WXWORD
)wParam
;
2416 *flags
= HIWORD(wParam
);
2417 *hmenu
= (WXHMENU
)lParam
;
2420 // ---------------------------------------------------------------------------
2421 // Main wxWidgets window proc and the window proc for wxWindow
2422 // ---------------------------------------------------------------------------
2424 // Hook for new window just as it's being created, when the window isn't yet
2425 // associated with the handle
2426 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2428 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2429 // window being created and insures that it's always unset back later
2430 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2432 gs_winBeingCreated
= winBeingCreated
;
2435 wxWindowCreationHook::~wxWindowCreationHook()
2437 gs_winBeingCreated
= NULL
;
2441 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2443 // trace all messages - useful for the debugging
2445 wxLogTrace(wxTraceMessages
,
2446 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2447 wxGetMessageName(message
), (long)hWnd
, (long)wParam
, lParam
);
2448 #endif // __WXDEBUG__
2450 wxWindowMSW
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
2452 // when we get the first message for the HWND we just created, we associate
2453 // it with wxWindow stored in gs_winBeingCreated
2454 if ( !wnd
&& gs_winBeingCreated
)
2456 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2457 wnd
= gs_winBeingCreated
;
2458 gs_winBeingCreated
= NULL
;
2459 wnd
->SetHWND((WXHWND
)hWnd
);
2464 if ( wnd
&& wxEventLoop::AllowProcessing(wnd
) )
2465 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2467 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2472 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2474 // did we process the message?
2475 bool processed
= false;
2485 // for most messages we should return 0 when we do process the message
2493 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2496 // return 0 to allow window creation
2497 rc
.result
= mayCreate
? 0 : -1;
2503 // never set processed to true and *always* pass WM_DESTROY to
2504 // DefWindowProc() as Windows may do some internal cleanup when
2505 // processing it and failing to pass the message along may cause
2506 // memory and resource leaks!
2507 (void)HandleDestroy();
2511 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2515 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2518 #if !defined(__WXWINCE__)
2521 LPRECT pRect
= (LPRECT
)lParam
;
2523 rc
.SetLeft(pRect
->left
);
2524 rc
.SetTop(pRect
->top
);
2525 rc
.SetRight(pRect
->right
);
2526 rc
.SetBottom(pRect
->bottom
);
2527 processed
= HandleMoving(rc
);
2529 pRect
->left
= rc
.GetLeft();
2530 pRect
->top
= rc
.GetTop();
2531 pRect
->right
= rc
.GetRight();
2532 pRect
->bottom
= rc
.GetBottom();
2539 LPRECT pRect
= (LPRECT
)lParam
;
2541 rc
.SetLeft(pRect
->left
);
2542 rc
.SetTop(pRect
->top
);
2543 rc
.SetRight(pRect
->right
);
2544 rc
.SetBottom(pRect
->bottom
);
2545 processed
= HandleSizing(rc
);
2547 pRect
->left
= rc
.GetLeft();
2548 pRect
->top
= rc
.GetTop();
2549 pRect
->right
= rc
.GetRight();
2550 pRect
->bottom
= rc
.GetBottom();
2554 #endif // !__WXWINCE__
2556 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2557 case WM_ACTIVATEAPP
:
2558 // This implicitly sends a wxEVT_ACTIVATE_APP event
2559 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2565 WXWORD state
, minimized
;
2567 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2569 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2574 processed
= HandleSetFocus((WXHWND
)(HWND
)wParam
);
2578 processed
= HandleKillFocus((WXHWND
)(HWND
)wParam
);
2581 case WM_PRINTCLIENT
:
2582 processed
= HandlePrintClient((WXHDC
)wParam
);
2588 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2590 processed
= HandlePaint();
2594 processed
= HandlePaint();
2599 #ifdef __WXUNIVERSAL__
2600 // Universal uses its own wxFrame/wxDialog, so we don't receive
2601 // close events unless we have this.
2603 #endif // __WXUNIVERSAL__
2605 // don't let the DefWindowProc() destroy our window - we'll do it
2606 // ourselves in ~wxWindow
2612 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2616 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2617 GET_Y_LPARAM(lParam
),
2621 #ifdef HAVE_TRACKMOUSEEVENT
2623 // filter out excess WM_MOUSELEAVE events sent after PopupMenu() (on XP at least)
2624 if ( m_mouseInWindow
)
2626 GenerateMouseLeave();
2629 // always pass processed back as false, this allows the window
2630 // manager to process the message too. This is needed to
2631 // ensure windows XP themes work properly as the mouse moves
2632 // over widgets like buttons. So don't set processed to true here.
2634 #endif // HAVE_TRACKMOUSEEVENT
2636 #if wxUSE_MOUSEWHEEL
2638 processed
= HandleMouseWheel(wParam
, lParam
);
2642 case WM_LBUTTONDOWN
:
2644 case WM_LBUTTONDBLCLK
:
2645 case WM_RBUTTONDOWN
:
2647 case WM_RBUTTONDBLCLK
:
2648 case WM_MBUTTONDOWN
:
2650 case WM_MBUTTONDBLCLK
:
2652 #ifdef __WXMICROWIN__
2653 // MicroWindows seems to ignore the fact that a window is
2654 // disabled. So catch mouse events and throw them away if
2656 wxWindowMSW
* win
= this;
2659 if (!win
->IsEnabled())
2665 win
= win
->GetParent();
2666 if ( !win
|| win
->IsTopLevel() )
2673 #endif // __WXMICROWIN__
2674 int x
= GET_X_LPARAM(lParam
),
2675 y
= GET_Y_LPARAM(lParam
);
2678 // redirect the event to a static control if necessary by
2679 // finding one under mouse because under CE the static controls
2680 // don't generate mouse events (even with SS_NOTIFY)
2682 if ( GetCapture() == this )
2684 // but don't do it if the mouse is captured by this window
2685 // because then it should really get this event itself
2690 win
= FindWindowForMouseEvent(this, &x
, &y
);
2692 // this should never happen
2693 wxCHECK_MSG( win
, 0,
2694 _T("FindWindowForMouseEvent() returned NULL") );
2697 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
2699 SHRGINFO shrgi
= {0};
2701 shrgi
.cbSize
= sizeof(SHRGINFO
);
2702 shrgi
.hwndClient
= (HWND
) GetHWND();
2706 shrgi
.dwFlags
= SHRG_RETURNCMD
;
2707 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
2709 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
2712 pt
= ClientToScreen(pt
);
2714 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2716 evtCtx
.SetEventObject(this);
2717 if (GetEventHandler()->ProcessEvent(evtCtx
))
2726 #else // !__WXWINCE__
2727 wxWindowMSW
*win
= this;
2728 #endif // __WXWINCE__/!__WXWINCE__
2730 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2732 // if the app didn't eat the event, handle it in the default
2733 // way, that is by giving this window the focus
2736 // for the standard classes their WndProc sets the focus to
2737 // them anyhow and doing it from here results in some weird
2738 // problems, so don't do it for them (unnecessary anyhow)
2739 if ( !win
->IsOfStandardClass() )
2741 if ( message
== WM_LBUTTONDOWN
&& win
->AcceptsFocus() )
2753 case MM_JOY1BUTTONDOWN
:
2754 case MM_JOY2BUTTONDOWN
:
2755 case MM_JOY1BUTTONUP
:
2756 case MM_JOY2BUTTONUP
:
2757 processed
= HandleJoystickEvent(message
,
2758 GET_X_LPARAM(lParam
),
2759 GET_Y_LPARAM(lParam
),
2762 #endif // __WXMICROWIN__
2768 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2770 processed
= HandleCommand(id
, cmd
, hwnd
);
2775 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2778 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
2779 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
2780 // apparently doesn't always behave properly and needs some help
2781 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
2782 case WM_NOTIFYFORMAT
:
2783 if ( lParam
== NF_QUERY
)
2786 rc
.result
= NFR_UNICODE
;
2789 #endif // wxUSE_UNICODE_MSLU
2791 // for these messages we must return true if process the message
2794 case WM_MEASUREITEM
:
2796 int idCtrl
= (UINT
)wParam
;
2797 if ( message
== WM_DRAWITEM
)
2799 processed
= MSWOnDrawItem(idCtrl
,
2800 (WXDRAWITEMSTRUCT
*)lParam
);
2804 processed
= MSWOnMeasureItem(idCtrl
,
2805 (WXMEASUREITEMSTRUCT
*)lParam
);
2812 #endif // defined(WM_DRAWITEM)
2815 if ( !IsOfStandardClass() )
2817 // we always want to get the char events
2818 rc
.result
= DLGC_WANTCHARS
;
2820 if ( GetWindowStyleFlag() & wxWANTS_CHARS
)
2822 // in fact, we want everything
2823 rc
.result
|= DLGC_WANTARROWS
|
2830 //else: get the dlg code from the DefWindowProc()
2835 // If this has been processed by an event handler, return 0 now
2836 // (we've handled it).
2837 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
2838 if ( m_lastKeydownProcessed
)
2847 // we consider these messages "not interesting" to OnChar, so
2848 // just don't do anything more with them
2858 // avoid duplicate messages to OnChar for these ASCII keys:
2859 // they will be translated by TranslateMessage() and received
2891 // but set processed to false, not true to still pass them
2892 // to the control's default window proc - otherwise
2893 // built-in keyboard handling won't work
2898 // special case of VK_APPS: treat it the same as right mouse
2899 // click because both usually pop up a context menu
2901 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
2906 // do generate a CHAR event
2907 processed
= HandleChar((WORD
)wParam
, lParam
);
2910 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
2917 // special case of VK_APPS: treat it the same as right mouse button
2918 if ( wParam
== VK_APPS
)
2920 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
2925 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
2930 case WM_CHAR
: // Always an ASCII character
2931 if ( m_lastKeydownProcessed
)
2933 // The key was handled in the EVT_KEY_DOWN and handling
2934 // a key in an EVT_KEY_DOWN handler is meant, by
2935 // design, to prevent EVT_CHARs from happening
2936 m_lastKeydownProcessed
= false;
2941 processed
= HandleChar((WORD
)wParam
, lParam
, true);
2947 processed
= HandleHotKey((WORD
)wParam
, lParam
);
2949 #endif // wxUSE_HOTKEY
2956 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
2958 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
2964 // CTLCOLOR messages are sent by children to query the parent for their
2966 #ifndef __WXMICROWIN__
2967 case WM_CTLCOLORMSGBOX
:
2968 case WM_CTLCOLOREDIT
:
2969 case WM_CTLCOLORLISTBOX
:
2970 case WM_CTLCOLORBTN
:
2971 case WM_CTLCOLORDLG
:
2972 case WM_CTLCOLORSCROLLBAR
:
2973 case WM_CTLCOLORSTATIC
:
2977 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
2979 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
2982 #endif // !__WXMICROWIN__
2984 case WM_SYSCOLORCHANGE
:
2985 // the return value for this message is ignored
2986 processed
= HandleSysColorChange();
2989 #if !defined(__WXWINCE__)
2990 case WM_DISPLAYCHANGE
:
2991 processed
= HandleDisplayChange();
2995 case WM_PALETTECHANGED
:
2996 processed
= HandlePaletteChanged((WXHWND
) (HWND
) wParam
);
2999 case WM_CAPTURECHANGED
:
3000 processed
= HandleCaptureChanged((WXHWND
) (HWND
) lParam
);
3003 case WM_SETTINGCHANGE
:
3004 processed
= HandleSettingChange(wParam
, lParam
);
3007 case WM_QUERYNEWPALETTE
:
3008 processed
= HandleQueryNewPalette();
3012 processed
= HandleEraseBkgnd((WXHDC
)(HDC
)wParam
);
3015 // we processed the message, i.e. erased the background
3020 #if !defined(__WXWINCE__)
3022 processed
= HandleDropFiles(wParam
);
3027 processed
= HandleInitDialog((WXHWND
)(HWND
)wParam
);
3031 // we never set focus from here
3036 #if !defined(__WXWINCE__)
3037 case WM_QUERYENDSESSION
:
3038 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3042 processed
= HandleEndSession(wParam
!= 0, lParam
);
3045 case WM_GETMINMAXINFO
:
3046 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3051 processed
= HandleSetCursor((WXHWND
)(HWND
)wParam
,
3052 LOWORD(lParam
), // hit test
3053 HIWORD(lParam
)); // mouse msg
3057 // returning TRUE stops the DefWindowProc() from further
3058 // processing this message - exactly what we need because we've
3059 // just set the cursor.
3064 #if wxUSE_ACCESSIBILITY
3067 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3068 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3070 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3072 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3078 #if defined(WM_HELP)
3081 // by default, WM_HELP is propagated by DefWindowProc() upwards
3082 // to the window parent but as we do it ourselves already
3083 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3084 // to get the other events if we process this message at all
3087 // WM_HELP doesn't use lParam under CE
3089 HELPINFO
* info
= (HELPINFO
*) lParam
;
3090 if ( info
->iContextType
== HELPINFO_WINDOW
)
3092 #endif // !__WXWINCE__
3093 wxHelpEvent helpEvent
3098 wxGetMousePosition() // what else?
3100 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3104 helpEvent
.SetEventObject(this);
3105 GetEventHandler()->ProcessEvent(helpEvent
);
3108 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3110 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3111 helpEvent
.SetEventObject(this);
3112 GetEventHandler()->ProcessEvent(helpEvent
);
3115 else // unknown help event?
3119 #endif // !__WXWINCE__
3124 #if !defined(__WXWINCE__)
3125 case WM_CONTEXTMENU
:
3127 // we don't convert from screen to client coordinates as
3128 // the event may be handled by a parent window
3129 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3131 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3133 // we could have got an event from our child, reflect it back
3134 // to it if this is the case
3135 wxWindowMSW
*win
= NULL
;
3136 if ( (WXHWND
)wParam
!= m_hWnd
)
3138 win
= FindItemByHWND((WXHWND
)wParam
);
3144 evtCtx
.SetEventObject(win
);
3145 processed
= win
->GetEventHandler()->ProcessEvent(evtCtx
);
3151 // we're only interested in our own menus, not MF_SYSMENU
3152 if ( HIWORD(wParam
) == MF_POPUP
)
3154 // handle menu chars for ownerdrawn menu items
3155 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3156 if ( i
!= wxNOT_FOUND
)
3158 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3165 case WM_POWERBROADCAST
:
3168 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3169 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3172 #endif // __WXWINCE__
3178 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
3179 wxGetMessageName(message
));
3180 #endif // __WXDEBUG__
3181 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3187 // ----------------------------------------------------------------------------
3188 // wxWindow <-> HWND map
3189 // ----------------------------------------------------------------------------
3191 wxWinHashTable
*wxWinHandleHash
= NULL
;
3193 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
3195 return (wxWindow
*)wxWinHandleHash
->Get((long)hWnd
);
3198 void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
)
3200 // adding NULL hWnd is (first) surely a result of an error and
3201 // (secondly) breaks menu command processing
3202 wxCHECK_RET( hWnd
!= (HWND
)NULL
,
3203 wxT("attempt to add a NULL hWnd to window list ignored") );
3205 wxWindow
*oldWin
= wxFindWinFromHandle((WXHWND
) hWnd
);
3207 if ( oldWin
&& (oldWin
!= win
) )
3209 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
3210 (int) hWnd
, win
->GetClassInfo()->GetClassName());
3213 #endif // __WXDEBUG__
3216 wxWinHandleHash
->Put((long)hWnd
, (wxWindow
*)win
);
3220 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3222 wxWinHandleHash
->Delete((long)win
->GetHWND());
3225 // ----------------------------------------------------------------------------
3226 // various MSW speciic class dependent functions
3227 // ----------------------------------------------------------------------------
3229 // Default destroyer - override if you destroy it in some other way
3230 // (e.g. with MDI child windows)
3231 void wxWindowMSW::MSWDestroyWindow()
3235 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3238 int& w
, int& h
) const
3240 // yes, those are just some arbitrary hardcoded numbers
3241 static const int DEFAULT_Y
= 200;
3243 bool nonDefault
= false;
3245 if ( pos
.x
== wxDefaultCoord
)
3247 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
3248 // can just as well set it to CW_USEDEFAULT as well
3254 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
3255 // neither because it is not handled as a special value by Windows then
3256 // and so we have to choose some default value for it
3258 y
= pos
.y
== wxDefaultCoord
? DEFAULT_Y
: pos
.y
;
3264 NB: there used to be some code here which set the initial size of the
3265 window to the client size of the parent if no explicit size was
3266 specified. This was wrong because wxWidgets programs often assume
3267 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3268 it. To see why, you should understand that Windows sends WM_SIZE from
3269 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3270 from some base class ctor and so this WM_SIZE is not processed in the
3271 real class' OnSize() (because it's not fully constructed yet and the
3272 event goes to some base class OnSize() instead). So the WM_SIZE we
3273 rely on is the one sent when the parent frame resizes its children
3274 but here is the problem: if the child already has just the right
3275 size, nothing will happen as both wxWidgets and Windows check for
3276 this and ignore any attempts to change the window size to the size it
3277 already has - so no WM_SIZE would be sent.
3281 // we don't use CW_USEDEFAULT here for several reasons:
3283 // 1. it results in huge frames on modern screens (1000*800 is not
3284 // uncommon on my 1280*1024 screen) which is way too big for a half
3285 // empty frame of most of wxWidgets samples for example)
3287 // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
3288 // the default is for whatever reason 8*8 which breaks client <->
3289 // window size calculations (it would be nice if it didn't, but it
3290 // does and the simplest way to fix it seemed to change the broken
3291 // default size anyhow)
3293 // 3. there is just no advantage in doing it: with x and y it is
3294 // possible that [future versions of] Windows position the new top
3295 // level window in some smart way which we can't do, but we can
3296 // guess a reasonably good size for a new window just as well
3299 // However, on PocketPC devices, we must use the default
3300 // size if possible.
3302 if (size
.x
== wxDefaultCoord
)
3306 if (size
.y
== wxDefaultCoord
)
3311 if ( size
.x
== wxDefaultCoord
|| size
.y
== wxDefaultCoord
)
3315 w
= WidthDefault(size
.x
);
3316 h
= HeightDefault(size
.y
);
3319 AdjustForParentClientOrigin(x
, y
);
3324 WXHWND
wxWindowMSW::MSWGetParent() const
3326 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3329 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3330 const wxChar
*title
,
3334 WXDWORD extendedStyle
)
3336 // choose the position/size for the new window
3338 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3340 // controlId is menu handle for the top level windows, so set it to 0
3341 // unless we're creating a child window
3342 int controlId
= style
& WS_CHILD
? GetId() : 0;
3344 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3345 // which is the same but without CS_[HV]REDRAW class styles so using it
3346 // ensures that the window is not fully repainted on each resize
3347 wxString
className(wclass
);
3348 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3350 className
+= wxT("NR");
3353 // do create the window
3354 wxWindowCreationHook
hook(this);
3356 m_hWnd
= (WXHWND
)::CreateWindowEx
3360 title
? title
: m_windowName
.c_str(),
3363 (HWND
)MSWGetParent(),
3366 NULL
// no extra data
3371 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3376 SubclassWin(m_hWnd
);
3381 // ===========================================================================
3382 // MSW message handlers
3383 // ===========================================================================
3385 // ---------------------------------------------------------------------------
3387 // ---------------------------------------------------------------------------
3389 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3391 #ifndef __WXMICROWIN__
3392 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3393 HWND hWnd
= hdr
->hwndFrom
;
3394 wxWindow
*win
= wxFindWinFromHandle((WXHWND
)hWnd
);
3396 // if the control is one of our windows, let it handle the message itself
3399 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3402 // VZ: why did we do it? normally this is unnecessary and, besides, it
3403 // breaks the message processing for the toolbars because the tooltip
3404 // notifications were being forwarded to the toolbar child controls
3405 // (if it had any) before being passed to the toolbar itself, so in my
3406 // example the tooltip for the combobox was always shown instead of the
3407 // correct button tooltips
3409 // try all our children
3410 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3413 wxWindow
*child
= node
->GetData();
3414 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3419 node
= node
->GetNext();
3423 // by default, handle it ourselves
3424 return MSWOnNotify(idCtrl
, lParam
, result
);
3425 #else // __WXMICROWIN__
3432 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3434 const wxString
& ttip
)
3436 // I don't know why it happens, but the versions of comctl32.dll starting
3437 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3438 // this message is supposed to be sent to Unicode programs only) -- hence
3439 // we need to handle it as well, otherwise no tooltips will be shown in
3442 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3445 // not a tooltip message or no tooltip to show anyhow
3450 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3452 // We don't want to use the szText buffer because it has a limit of 80
3453 // bytes and this is not enough, especially for Unicode build where it
3454 // limits the tooltip string length to only 40 characters
3456 // The best would be, of course, to not impose any length limitations at
3457 // all but then the buffer would have to be dynamic and someone would have
3458 // to free it and we don't have the tooltip owner object here any more, so
3459 // for now use our own static buffer with a higher fixed max length.
3461 // Note that using a static buffer should not be a problem as only a single
3462 // tooltip can be shown at the same time anyhow.
3464 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3466 // We need to convert tooltip from multi byte to Unicode on the fly.
3467 static wchar_t buf
[513];
3469 // Truncate tooltip length if needed as otherwise we might not have
3470 // enough space for it in the buffer and MultiByteToWideChar() would
3472 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3474 // Convert to WideChar without adding the NULL character. The NULL
3475 // character is added afterwards (this is more efficient).
3476 int len
= ::MultiByteToWideChar
3488 wxLogLastError(_T("MultiByteToWideChar()"));
3492 ttText
->lpszText
= (LPSTR
) buf
;
3494 else // TTN_NEEDTEXTA
3495 #endif // !wxUSE_UNICODE
3497 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3498 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3499 // to copy the string we have into the buffer
3500 static wxChar buf
[513];
3501 wxStrncpy(buf
, ttip
.c_str(), WXSIZEOF(buf
) - 1);
3502 buf
[WXSIZEOF(buf
) - 1] = _T('\0');
3503 ttText
->lpszText
= buf
;
3509 #endif // wxUSE_TOOLTIPS
3511 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3513 WXLPARAM
* WXUNUSED(result
))
3518 NMHDR
* hdr
= (NMHDR
*)lParam
;
3519 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3526 wxUnusedVar(lParam
);
3527 #endif // wxUSE_TOOLTIPS
3532 // ---------------------------------------------------------------------------
3533 // end session messages
3534 // ---------------------------------------------------------------------------
3536 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3538 #ifdef ENDSESSION_LOGOFF
3539 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3540 event
.SetEventObject(wxTheApp
);
3541 event
.SetCanVeto(true);
3542 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3544 bool rc
= wxTheApp
->ProcessEvent(event
);
3548 // we may end only if the app didn't veto session closing (double
3550 *mayEnd
= !event
.GetVeto();
3555 wxUnusedVar(logOff
);
3556 wxUnusedVar(mayEnd
);
3561 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3563 #ifdef ENDSESSION_LOGOFF
3564 // do nothing if the session isn't ending
3569 if ( (this != wxTheApp
->GetTopWindow()) )
3572 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3573 event
.SetEventObject(wxTheApp
);
3574 event
.SetCanVeto(false);
3575 event
.SetLoggingOff( (logOff
== (long)ENDSESSION_LOGOFF
) );
3577 return wxTheApp
->ProcessEvent(event
);
3579 wxUnusedVar(endSession
);
3580 wxUnusedVar(logOff
);
3585 // ---------------------------------------------------------------------------
3586 // window creation/destruction
3587 // ---------------------------------------------------------------------------
3589 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3592 // VZ: why is this commented out for WinCE? If it doesn't support
3593 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3594 // not with multiple #ifdef's!
3596 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3597 EnsureParentHasControlParentStyle(GetParent());
3598 #endif // !__WXWINCE__
3605 bool wxWindowMSW::HandleDestroy()
3609 // delete our drop target if we've got one
3610 #if wxUSE_DRAG_AND_DROP
3611 if ( m_dropTarget
!= NULL
)
3613 m_dropTarget
->Revoke(m_hWnd
);
3615 delete m_dropTarget
;
3616 m_dropTarget
= NULL
;
3618 #endif // wxUSE_DRAG_AND_DROP
3620 // WM_DESTROY handled
3624 // ---------------------------------------------------------------------------
3626 // ---------------------------------------------------------------------------
3628 bool wxWindowMSW::HandleActivate(int state
,
3629 bool WXUNUSED(minimized
),
3630 WXHWND
WXUNUSED(activate
))
3632 wxActivateEvent
event(wxEVT_ACTIVATE
,
3633 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3635 event
.SetEventObject(this);
3637 return GetEventHandler()->ProcessEvent(event
);
3640 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3642 // Strangly enough, some controls get set focus events when they are being
3643 // deleted, even if they already had focus before.
3644 if ( m_isBeingDeleted
)
3649 // notify the parent keeping track of focus for the kbd navigation
3650 // purposes that we got it
3651 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3652 (void)GetEventHandler()->ProcessEvent(eventFocus
);
3658 m_caret
->OnSetFocus();
3660 #endif // wxUSE_CARET
3663 // If it's a wxTextCtrl don't send the event as it will be done
3664 // after the control gets to process it from EN_FOCUS handler
3665 if ( wxDynamicCastThis(wxTextCtrl
) )
3669 #endif // wxUSE_TEXTCTRL
3671 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3672 event
.SetEventObject(this);
3674 // wxFindWinFromHandle() may return NULL, it is ok
3675 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3677 return GetEventHandler()->ProcessEvent(event
);
3680 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
3686 m_caret
->OnKillFocus();
3688 #endif // wxUSE_CARET
3691 // If it's a wxTextCtrl don't send the event as it will be done
3692 // after the control gets to process it.
3693 wxTextCtrl
*ctrl
= wxDynamicCastThis(wxTextCtrl
);
3700 // Don't send the event when in the process of being deleted. This can
3701 // only cause problems if the event handler tries to access the object.
3702 if ( m_isBeingDeleted
)
3707 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3708 event
.SetEventObject(this);
3710 // wxFindWinFromHandle() may return NULL, it is ok
3711 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3713 return GetEventHandler()->ProcessEvent(event
);
3716 // ---------------------------------------------------------------------------
3718 // ---------------------------------------------------------------------------
3720 void wxWindowMSW::SetLabel( const wxString
& label
)
3722 SetWindowText(GetHwnd(), label
.c_str());
3725 wxString
wxWindowMSW::GetLabel() const
3727 return wxGetWindowText(GetHWND());
3730 // ---------------------------------------------------------------------------
3732 // ---------------------------------------------------------------------------
3734 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
3736 wxShowEvent
event(GetId(), show
);
3737 event
.SetEventObject(this);
3739 return GetEventHandler()->ProcessEvent(event
);
3742 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
3744 wxInitDialogEvent
event(GetId());
3745 event
.SetEventObject(this);
3747 return GetEventHandler()->ProcessEvent(event
);
3750 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
3752 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
3753 wxUnusedVar(wParam
);
3755 #else // __WXMICROWIN__
3756 HDROP hFilesInfo
= (HDROP
) wParam
;
3758 // Get the total number of files dropped
3759 UINT gwFilesDropped
= ::DragQueryFile
3767 wxString
*files
= new wxString
[gwFilesDropped
];
3768 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
3770 // first get the needed buffer length (+1 for terminating NUL)
3771 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
3773 // and now get the file name
3774 ::DragQueryFile(hFilesInfo
, wIndex
,
3775 wxStringBuffer(files
[wIndex
], len
), len
);
3777 DragFinish (hFilesInfo
);
3779 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
3780 event
.SetEventObject(this);
3783 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
3784 event
.m_pos
.x
= dropPoint
.x
;
3785 event
.m_pos
.y
= dropPoint
.y
;
3787 return GetEventHandler()->ProcessEvent(event
);
3792 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
3794 int WXUNUSED(mouseMsg
))
3796 #ifndef __WXMICROWIN__
3797 // the logic is as follows:
3798 // -1. don't set cursor for non client area, including but not limited to
3799 // the title bar, scrollbars, &c
3800 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
3801 // 1. if we have the cursor set it unless wxIsBusy()
3802 // 2. if we're a top level window, set some cursor anyhow
3803 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
3805 if ( nHitTest
!= HTCLIENT
)
3810 HCURSOR hcursor
= 0;
3812 // first ask the user code - it may wish to set the cursor in some very
3813 // specific way (for example, depending on the current position)
3816 if ( !::GetCursorPosWinCE(&pt
))
3818 if ( !::GetCursorPos(&pt
) )
3821 wxLogLastError(wxT("GetCursorPos"));
3826 ScreenToClient(&x
, &y
);
3827 wxSetCursorEvent
event(x
, y
);
3829 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
3830 if ( processedEvtSetCursor
&& event
.HasCursor() )
3832 hcursor
= GetHcursorOf(event
.GetCursor());
3837 bool isBusy
= wxIsBusy();
3839 // the test for processedEvtSetCursor is here to prevent using m_cursor
3840 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3841 // it - this is a way to say that our cursor shouldn't be used for this
3843 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
3845 hcursor
= GetHcursorOf(m_cursor
);
3852 hcursor
= wxGetCurrentBusyCursor();
3854 else if ( !hcursor
)
3856 const wxCursor
*cursor
= wxGetGlobalCursor();
3857 if ( cursor
&& cursor
->Ok() )
3859 hcursor
= GetHcursorOf(*cursor
);
3867 // wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3869 ::SetCursor(hcursor
);
3871 // cursor set, stop here
3874 #endif // __WXMICROWIN__
3876 // pass up the window chain
3880 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
3881 WXLPARAM
WXUNUSED(lParam
),
3882 bool *WXUNUSED_IN_WINCE(vetoed
))
3888 wxEventType evtType
;
3891 case PBT_APMQUERYSUSPEND
:
3892 evtType
= wxEVT_POWER_SUSPENDING
;
3895 case PBT_APMQUERYSUSPENDFAILED
:
3896 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
3899 case PBT_APMSUSPEND
:
3900 evtType
= wxEVT_POWER_SUSPENDED
;
3903 case PBT_APMRESUMESUSPEND
:
3904 #ifdef PBT_APMRESUMEAUTOMATIC
3905 case PBT_APMRESUMEAUTOMATIC
:
3907 evtType
= wxEVT_POWER_RESUME
;
3911 wxLogDebug(_T("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
3914 // these messages are currently not mapped to wx events
3915 case PBT_APMQUERYSTANDBY
:
3916 case PBT_APMQUERYSTANDBYFAILED
:
3917 case PBT_APMSTANDBY
:
3918 case PBT_APMRESUMESTANDBY
:
3919 case PBT_APMBATTERYLOW
:
3920 case PBT_APMPOWERSTATUSCHANGE
:
3921 case PBT_APMOEMEVENT
:
3922 case PBT_APMRESUMECRITICAL
:
3923 evtType
= wxEVT_NULL
;
3927 // don't handle unknown messages
3928 if ( evtType
== wxEVT_NULL
)
3931 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
3933 wxPowerEvent
event(evtType
);
3934 if ( !GetEventHandler()->ProcessEvent(event
) )
3937 *vetoed
= event
.IsVetoed();
3943 // ---------------------------------------------------------------------------
3944 // owner drawn stuff
3945 // ---------------------------------------------------------------------------
3947 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
3948 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
3949 #define WXUNUSED_UNLESS_ODRAWN(param) param
3951 #define WXUNUSED_UNLESS_ODRAWN(param)
3955 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
3956 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
3958 #if wxUSE_OWNER_DRAWN
3960 #if wxUSE_MENUS_NATIVE
3961 // is it a menu item?
3962 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
3963 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
3965 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
3967 // see comment before the same test in MSWOnMeasureItem() below
3971 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
3972 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
3974 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
3975 // the DC from being released
3976 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
3977 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
3978 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
3979 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
3981 return pMenuItem
->OnDrawItem
3985 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
3986 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
3989 #endif // wxUSE_MENUS_NATIVE
3991 #endif // USE_OWNER_DRAWN
3993 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
3995 #if wxUSE_OWNER_DRAWN
3996 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3997 #else // !wxUSE_OWNER_DRAWN
3998 // we may still have owner-drawn buttons internally because we have to make
3999 // them owner-drawn to support colour change
4002 wxDynamicCast(FindItem(id
), wxButton
)
4007 #endif // USE_OWNER_DRAWN
4011 return item
->MSWOnDraw(itemStruct
);
4014 #endif // wxUSE_CONTROLS
4020 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4022 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4023 // is it a menu item?
4024 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4025 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4027 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4029 // according to Carsten Fuchs the pointer may be NULL under XP if an
4030 // MDI child frame is initially maximized, see this for more info:
4031 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4033 // so silently ignore it instead of asserting
4037 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4038 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
4041 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4043 pMeasureStruct
->itemWidth
= w
;
4044 pMeasureStruct
->itemHeight
= h
;
4049 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4052 return item
->MSWOnMeasure(itemStruct
);
4056 wxUnusedVar(itemStruct
);
4057 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4062 // ---------------------------------------------------------------------------
4063 // colours and palettes
4064 // ---------------------------------------------------------------------------
4066 bool wxWindowMSW::HandleSysColorChange()
4068 wxSysColourChangedEvent event
;
4069 event
.SetEventObject(this);
4071 (void)GetEventHandler()->ProcessEvent(event
);
4073 // always let the system carry on the default processing to allow the
4074 // native controls to react to the colours update
4078 bool wxWindowMSW::HandleDisplayChange()
4080 wxDisplayChangedEvent event
;
4081 event
.SetEventObject(this);
4083 return GetEventHandler()->ProcessEvent(event
);
4086 #ifndef __WXMICROWIN__
4088 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4090 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4094 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4097 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4099 #endif // wxUSE_CONTROLS
4102 return *brush
!= NULL
;
4105 #endif // __WXMICROWIN__
4107 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4110 // same as below except we don't respond to our own messages
4111 if ( hWndPalChange
!= GetHWND() )
4113 // check to see if we our our parents have a custom palette
4114 wxWindowMSW
*win
= this;
4115 while ( win
&& !win
->HasCustomPalette() )
4117 win
= win
->GetParent();
4120 if ( win
&& win
->HasCustomPalette() )
4122 // realize the palette to see whether redrawing is needed
4123 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4124 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4125 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4127 int result
= ::RealizePalette(hdc
);
4129 // restore the palette (before releasing the DC)
4130 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4131 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4132 ::RealizePalette(hdc
);
4133 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4135 // now check for the need to redraw
4137 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4141 #endif // wxUSE_PALETTE
4143 wxPaletteChangedEvent
event(GetId());
4144 event
.SetEventObject(this);
4145 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4147 return GetEventHandler()->ProcessEvent(event
);
4150 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4152 // notify windows on the capture stack about lost capture
4153 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4154 wxWindowBase::NotifyCaptureLost();
4156 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4157 wxMouseCaptureChangedEvent
event(GetId(), win
);
4158 event
.SetEventObject(this);
4159 return GetEventHandler()->ProcessEvent(event
);
4162 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4164 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4165 // we need to send this to child windows (it is only sent to top-level
4166 // windows) so {list,tree}ctrls can adjust their font size if necessary
4167 // this is exactly how explorer does it to enable the font size changes
4169 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4172 // top-level windows already get this message from the system
4173 wxWindow
*win
= node
->GetData();
4174 if ( !win
->IsTopLevel() )
4176 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4179 node
= node
->GetNext();
4182 // let the system handle it
4186 bool wxWindowMSW::HandleQueryNewPalette()
4190 // check to see if we our our parents have a custom palette
4191 wxWindowMSW
*win
= this;
4192 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4193 if (win
->HasCustomPalette()) {
4194 /* realize the palette to see whether redrawing is needed */
4195 HDC hdc
= ::GetDC((HWND
) GetHWND());
4196 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4197 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4199 int result
= ::RealizePalette(hdc
);
4200 /* restore the palette (before releasing the DC) */
4201 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4202 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4203 ::RealizePalette(hdc
);
4204 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4205 /* now check for the need to redraw */
4207 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4209 #endif // wxUSE_PALETTE
4211 wxQueryNewPaletteEvent
event(GetId());
4212 event
.SetEventObject(this);
4214 return GetEventHandler()->ProcessEvent(event
) && event
.GetPaletteRealized();
4217 // Responds to colour changes: passes event on to children.
4218 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4220 // the top level window also reset the standard colour map as it might have
4221 // changed (there is no need to do it for the non top level windows as we
4222 // only have to do it once)
4226 gs_hasStdCmap
= false;
4228 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4231 // Only propagate to non-top-level windows because Windows already
4232 // sends this event to all top-level ones
4233 wxWindow
*win
= node
->GetData();
4234 if ( !win
->IsTopLevel() )
4236 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4237 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4238 // the standard controls
4239 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4242 node
= node
->GetNext();
4246 extern wxCOLORMAP
*wxGetStdColourMap()
4248 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4249 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4251 if ( !gs_hasStdCmap
)
4253 static bool s_coloursInit
= false;
4255 if ( !s_coloursInit
)
4257 // When a bitmap is loaded, the RGB values can change (apparently
4258 // because Windows adjusts them to care for the old programs always
4259 // using 0xc0c0c0 while the transparent colour for the new Windows
4260 // versions is different). But we do this adjustment ourselves so
4261 // we want to avoid Windows' "help" and for this we need to have a
4262 // reference bitmap which can tell us what the RGB values change
4264 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4265 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
4266 if ( stdColourBitmap
.Ok() )
4268 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4269 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4270 _T("forgot to update wxBITMAP_STD_COLOURS!") );
4273 memDC
.SelectObject(stdColourBitmap
);
4276 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4278 memDC
.GetPixel(i
, 0, &colour
);
4279 s_stdColours
[i
] = wxColourToRGB(colour
);
4282 else // wxBITMAP_STD_COLOURS couldn't be loaded
4284 s_stdColours
[0] = RGB(000,000,000); // black
4285 s_stdColours
[1] = RGB(128,128,128); // dark grey
4286 s_stdColours
[2] = RGB(192,192,192); // light grey
4287 s_stdColours
[3] = RGB(255,255,255); // white
4288 //s_stdColours[4] = RGB(000,000,255); // blue
4289 //s_stdColours[5] = RGB(255,000,255); // magenta
4292 s_coloursInit
= true;
4295 gs_hasStdCmap
= true;
4297 // create the colour map
4298 #define INIT_CMAP_ENTRY(col) \
4299 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4300 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4302 INIT_CMAP_ENTRY(BTNTEXT
);
4303 INIT_CMAP_ENTRY(BTNSHADOW
);
4304 INIT_CMAP_ENTRY(BTNFACE
);
4305 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4307 #undef INIT_CMAP_ENTRY
4313 // ---------------------------------------------------------------------------
4315 // ---------------------------------------------------------------------------
4317 bool wxWindowMSW::HandlePaint()
4319 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4321 wxLogLastError(wxT("CreateRectRgn"));
4322 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4323 wxLogLastError(wxT("GetUpdateRgn"));
4325 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4327 wxPaintEvent
event(m_windowId
);
4328 event
.SetEventObject(this);
4330 bool processed
= GetEventHandler()->ProcessEvent(event
);
4332 // note that we must generate NC event after the normal one as otherwise
4333 // BeginPaint() will happily overwrite our decorations with the background
4335 wxNcPaintEvent
eventNc(m_windowId
);
4336 eventNc
.SetEventObject(this);
4337 GetEventHandler()->ProcessEvent(eventNc
);
4342 // Can be called from an application's OnPaint handler
4343 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4345 #ifdef __WXUNIVERSAL__
4348 HDC hDC
= (HDC
) wxPaintDC::FindDCInCache((wxWindow
*) event
.GetEventObject());
4351 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4356 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4361 dc
.SetWindow((wxWindow
*)this);
4363 wxEraseEvent
event(m_windowId
, &dc
);
4364 event
.SetEventObject(this);
4365 bool rc
= GetEventHandler()->ProcessEvent(event
);
4367 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
4368 dc
.SelectOldObjects(hdc
);
4373 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
4375 // standard non top level controls (i.e. except the dialogs) always erase
4376 // their background themselves in HandleCtlColor() or have some control-
4377 // specific ways to set the colours (common controls)
4378 if ( IsOfStandardClass() && !IsTopLevel() )
4384 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
4386 // don't skip the event here, custom background means that the app
4387 // is drawing it itself in its OnPaint(), so don't draw it at all
4388 // now to avoid flicker
4393 // do default background painting
4394 if ( !DoEraseBackground(GetHdcOf(*event
.GetDC())) )
4396 // let the system paint the background
4401 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4403 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4407 wxFillRect(GetHwnd(), (HDC
)hDC
, hbr
);
4413 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
), WXHWND hWnd
)
4417 // our background colour applies to:
4418 // 1. this window itself, always
4419 // 2. all children unless the colour is "not inheritable"
4420 // 3. even if it is not inheritable, our immediate transparent
4421 // children should still inherit it -- but not any transparent
4422 // children because it would look wrong if a child of non
4423 // transparent child would show our bg colour when the child itself
4425 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
4428 (win
&& win
->HasTransparentBackground() &&
4429 win
->GetParent() == this) )
4431 // draw children with the same colour as the parent
4433 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4435 return (WXHBRUSH
)GetHbrushOf(*brush
);
4442 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
, WXHWND hWndToPaint
)
4445 hWndToPaint
= GetHWND();
4447 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4449 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, hWndToPaint
);
4453 // background is not inherited beyond top level windows
4454 if ( win
->IsTopLevel() )
4461 bool wxWindowMSW::HandlePrintClient(WXHDC
WXUNUSED(hDC
))
4463 // TODO: handle wxBG_STYLE_CUSTOM and/or wxBG_STYLE_COLOUR here so when
4464 // DrawParentThemeBackground() from uxtheme.dll is called we don't get
4465 // the default background e.g. the border when custom drawing buttons
4469 // ---------------------------------------------------------------------------
4470 // moving and resizing
4471 // ---------------------------------------------------------------------------
4473 bool wxWindowMSW::HandleMinimize()
4475 wxIconizeEvent
event(m_windowId
);
4476 event
.SetEventObject(this);
4478 return GetEventHandler()->ProcessEvent(event
);
4481 bool wxWindowMSW::HandleMaximize()
4483 wxMaximizeEvent
event(m_windowId
);
4484 event
.SetEventObject(this);
4486 return GetEventHandler()->ProcessEvent(event
);
4489 bool wxWindowMSW::HandleMove(int x
, int y
)
4492 wxMoveEvent
event(point
, m_windowId
);
4493 event
.SetEventObject(this);
4495 return GetEventHandler()->ProcessEvent(event
);
4498 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
4500 wxMoveEvent
event(rect
, m_windowId
);
4501 event
.SetEventObject(this);
4503 bool rc
= GetEventHandler()->ProcessEvent(event
);
4505 rect
= event
.GetRect();
4509 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
4511 #if USE_DEFERRED_SIZING
4512 // when we resize this window, its children are probably going to be
4513 // repositioned as well, prepare to use DeferWindowPos() for them
4514 int numChildren
= 0;
4515 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
4517 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
4522 // Protect against valid m_hDWP being overwritten
4523 bool useDefer
= false;
4525 if ( numChildren
> 1 )
4529 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
4532 wxLogLastError(_T("BeginDeferWindowPos"));
4538 #endif // USE_DEFERRED_SIZING
4540 // update this window size
4541 bool processed
= false;
4545 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4546 // fall through nevertheless
4550 // we're not interested in these messages at all
4553 case SIZE_MINIMIZED
:
4554 processed
= HandleMinimize();
4557 case SIZE_MAXIMIZED
:
4558 /* processed = */ HandleMaximize();
4559 // fall through to send a normal size event as well
4562 // don't use w and h parameters as they specify the client size
4563 // while according to the docs EVT_SIZE handler is supposed to
4564 // receive the total size
4565 wxSizeEvent
event(GetSize(), m_windowId
);
4566 event
.SetEventObject(this);
4568 processed
= GetEventHandler()->ProcessEvent(event
);
4571 #if USE_DEFERRED_SIZING
4572 // and finally change the positions of all child windows at once
4573 if ( useDefer
&& m_hDWP
)
4575 // reset m_hDWP to NULL so that child windows don't try to use our
4576 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4577 // happen anyhow normally but who knows what weird flow of control we
4578 // may have depending on what the users EVT_SIZE handler does...)
4579 HDWP hDWP
= (HDWP
)m_hDWP
;
4582 // do put all child controls in place at once
4583 if ( !::EndDeferWindowPos(hDWP
) )
4585 wxLogLastError(_T("EndDeferWindowPos"));
4588 // Reset our children's pending pos/size values.
4589 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4591 node
= node
->GetNext() )
4593 wxWindowMSW
*child
= node
->GetData();
4594 child
->m_pendingPosition
= wxDefaultPosition
;
4595 child
->m_pendingSize
= wxDefaultSize
;
4598 #endif // USE_DEFERRED_SIZING
4603 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
4605 wxSizeEvent
event(rect
, m_windowId
);
4606 event
.SetEventObject(this);
4608 bool rc
= GetEventHandler()->ProcessEvent(event
);
4610 rect
= event
.GetRect();
4614 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
4619 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
4623 int minWidth
= GetMinWidth(),
4624 minHeight
= GetMinHeight(),
4625 maxWidth
= GetMaxWidth(),
4626 maxHeight
= GetMaxHeight();
4628 if ( minWidth
!= wxDefaultCoord
)
4630 info
->ptMinTrackSize
.x
= minWidth
;
4634 if ( minHeight
!= wxDefaultCoord
)
4636 info
->ptMinTrackSize
.y
= minHeight
;
4640 if ( maxWidth
!= wxDefaultCoord
)
4642 info
->ptMaxTrackSize
.x
= maxWidth
;
4646 if ( maxHeight
!= wxDefaultCoord
)
4648 info
->ptMaxTrackSize
.y
= maxHeight
;
4656 // ---------------------------------------------------------------------------
4658 // ---------------------------------------------------------------------------
4660 bool wxWindowMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
4662 #if wxUSE_MENUS_NATIVE
4663 if ( !cmd
&& wxCurrentPopupMenu
)
4665 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
4666 wxCurrentPopupMenu
= NULL
;
4668 return popupMenu
->MSWCommand(cmd
, id
);
4670 #endif // wxUSE_MENUS_NATIVE
4672 wxWindow
*win
= NULL
;
4674 // first try to find it from HWND - this works even with the broken
4675 // programs using the same ids for different controls
4678 win
= wxFindWinFromHandle(control
);
4684 // must cast to a signed type before comparing with other ids!
4685 win
= FindItem((signed short)id
);
4690 return win
->MSWCommand(cmd
, id
);
4693 // the messages sent from the in-place edit control used by the treectrl
4694 // for label editing have id == 0, but they should _not_ be treated as menu
4695 // messages (they are EN_XXX ones, in fact) so don't translate anything
4696 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4699 // If no child window, it may be an accelerator, e.g. for a popup menu
4702 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
4703 event
.SetEventObject(this);
4707 return GetEventHandler()->ProcessEvent(event
);
4711 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4712 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4713 // notifications to its parent which we want to reflect back to
4715 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
4716 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
4718 #endif // wxUSE_SPINCTRL
4720 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
4721 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
4722 // notifications to its parent which we want to reflect back to
4724 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
4725 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
4733 // ---------------------------------------------------------------------------
4735 // ---------------------------------------------------------------------------
4737 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
4741 // our client coords are not quite the same as Windows ones
4742 wxPoint pt
= GetClientAreaOrigin();
4743 event
.m_x
= x
- pt
.x
;
4744 event
.m_y
= y
- pt
.y
;
4746 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
4747 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
4748 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
4749 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
4750 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
4751 event
.m_altDown
= ::GetKeyState(VK_MENU
) < 0;
4754 event
.SetTimestamp(::GetMessageTime());
4757 event
.SetEventObject(this);
4758 event
.SetId(GetId());
4760 #if wxUSE_MOUSEEVENT_HACK
4761 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
4762 gs_lastMouseEvent
.type
= event
.GetEventType();
4763 #endif // wxUSE_MOUSEEVENT_HACK
4767 // Windows doesn't send the mouse events to the static controls (which are
4768 // transparent in the sense that their WM_NCHITTEST handler returns
4769 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4770 // and so we manually check if we don't have a child window under mouse and if
4771 // we do, send the event to it instead of the window Windows had sent WM_XXX
4774 // Notice that this is not done for the mouse move events because this could
4775 // (would?) be too slow, but only for clicks which means that the static texts
4776 // still don't get move, enter nor leave events.
4777 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
4779 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
4781 // first try to find a non transparent child: this allows us to send events
4782 // to a static text which is inside a static box, for example
4783 POINT pt
= { *x
, *y
};
4784 HWND hwnd
= GetHwndOf(win
),
4788 hwndUnderMouse
= ::ChildWindowFromPoint
4794 hwndUnderMouse
= ::ChildWindowFromPointEx
4804 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
4806 // now try any child window at all
4807 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
4810 // check that we have a child window which is susceptible to receive mouse
4811 // events: for this it must be shown and enabled
4812 if ( hwndUnderMouse
&&
4813 hwndUnderMouse
!= hwnd
&&
4814 ::IsWindowVisible(hwndUnderMouse
) &&
4815 ::IsWindowEnabled(hwndUnderMouse
) )
4817 wxWindow
*winUnderMouse
= wxFindWinFromHandle((WXHWND
)hwndUnderMouse
);
4818 if ( winUnderMouse
)
4820 // translate the mouse coords to the other window coords
4821 win
->ClientToScreen(x
, y
);
4822 winUnderMouse
->ScreenToClient(x
, y
);
4824 win
= winUnderMouse
;
4830 #endif // __WXWINCE__
4832 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4834 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4835 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
4836 // from the message id and take the value in the table to get wxWin event
4838 static const wxEventType eventsMouse
[] =
4852 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
4853 InitMouseEvent(event
, x
, y
, flags
);
4855 return GetEventHandler()->ProcessEvent(event
);
4858 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
4860 if ( !m_mouseInWindow
)
4862 // it would be wrong to assume that just because we get a mouse move
4863 // event that the mouse is inside the window: although this is usually
4864 // true, it is not if we had captured the mouse, so we need to check
4865 // the mouse coordinates here
4866 if ( !HasCapture() || IsMouseInWindow() )
4868 // Generate an ENTER event
4869 m_mouseInWindow
= true;
4871 #ifdef HAVE_TRACKMOUSEEVENT
4872 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
4874 trackinfo
.dwFlags
= TME_LEAVE
;
4875 trackinfo
.hwndTrack
= GetHwnd();
4877 // Use the commctrl.h _TrackMouseEvent(), which will call the real
4878 // TrackMouseEvent() if available or emulate it
4879 _TrackMouseEvent(&trackinfo
);
4880 #endif // HAVE_TRACKMOUSEEVENT
4882 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
4883 InitMouseEvent(event
, x
, y
, flags
);
4885 (void)GetEventHandler()->ProcessEvent(event
);
4888 #ifdef HAVE_TRACKMOUSEEVENT
4891 // Check if we need to send a LEAVE event
4892 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
4893 // send it here if we are using native mouse leave tracking
4894 if ( HasCapture() && !IsMouseInWindow() )
4896 GenerateMouseLeave();
4899 #endif // HAVE_TRACKMOUSEEVENT
4901 #if wxUSE_MOUSEEVENT_HACK
4902 // Windows often generates mouse events even if mouse position hasn't
4903 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
4905 // Filter this out as it can result in unexpected behaviour compared to
4907 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
4908 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
4909 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
4910 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
4912 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
4914 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
4919 #endif // wxUSE_MOUSEEVENT_HACK
4921 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
4925 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
4927 #if wxUSE_MOUSEWHEEL
4928 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
4929 // forwarded up to the parent by DefWindowProc()) and not in the client
4930 // ones as all the other messages, translate them to the client coords for
4933 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
4934 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
4935 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
4936 event
.m_wheelRotation
= (short)HIWORD(wParam
);
4937 event
.m_wheelDelta
= WHEEL_DELTA
;
4939 static int s_linesPerRotation
= -1;
4940 if ( s_linesPerRotation
== -1 )
4942 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
4943 &s_linesPerRotation
, 0))
4945 // this is not supposed to happen
4946 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
4948 // the default is 3, so use it if SystemParametersInfo() failed
4949 s_linesPerRotation
= 3;
4953 event
.m_linesPerAction
= s_linesPerRotation
;
4954 return GetEventHandler()->ProcessEvent(event
);
4956 #else // !wxUSE_MOUSEWHEEL
4957 wxUnusedVar(wParam
);
4958 wxUnusedVar(lParam
);
4961 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
4964 void wxWindowMSW::GenerateMouseLeave()
4966 m_mouseInWindow
= false;
4969 if ( wxIsShiftDown() )
4971 if ( wxIsCtrlDown() )
4972 state
|= MK_CONTROL
;
4974 // Only the high-order bit should be tested
4975 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
4976 state
|= MK_LBUTTON
;
4977 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
4978 state
|= MK_MBUTTON
;
4979 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
4980 state
|= MK_RBUTTON
;
4984 if ( !::GetCursorPosWinCE(&pt
) )
4986 if ( !::GetCursorPos(&pt
) )
4989 wxLogLastError(_T("GetCursorPos"));
4992 // we need to have client coordinates here for symmetry with
4993 // wxEVT_ENTER_WINDOW
4994 RECT rect
= wxGetWindowRect(GetHwnd());
4998 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
4999 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5001 (void)GetEventHandler()->ProcessEvent(event
);
5004 // ---------------------------------------------------------------------------
5005 // keyboard handling
5006 // ---------------------------------------------------------------------------
5008 // create the key event of the given type for the given key - used by
5009 // HandleChar and HandleKeyDown/Up
5010 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5013 WXWPARAM wParam
) const
5015 wxKeyEvent
event(evType
);
5016 event
.SetId(GetId());
5017 event
.m_shiftDown
= wxIsShiftDown();
5018 event
.m_controlDown
= wxIsCtrlDown();
5019 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5021 event
.SetEventObject((wxWindow
*)this); // const_cast
5022 event
.m_keyCode
= id
;
5024 event
.m_uniChar
= (wxChar
) wParam
;
5026 event
.m_rawCode
= (wxUint32
) wParam
;
5027 event
.m_rawFlags
= (wxUint32
) lParam
;
5029 event
.SetTimestamp(::GetMessageTime());
5032 // translate the position to client coords
5035 GetCursorPosWinCE(&pt
);
5040 GetWindowRect(GetHwnd(),&rect
);
5050 // isASCII is true only when we're called from WM_CHAR handler and not from
5052 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
5059 else // we're called from WM_KEYDOWN
5061 // don't pass lParam to wxCharCodeMSWToWX() here because we don't want
5062 // to get numpad key codes: CHAR events should use the logical keys
5063 // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events
5064 id
= wxCharCodeMSWToWX(wParam
);
5067 // it's ASCII and will be processed here only when called from
5068 // WM_CHAR (i.e. when isASCII = true), don't process it now
5073 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
5075 // the alphanumeric keys produced by pressing AltGr+something on European
5076 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5077 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5078 // alphanumeric, so pretend that there are no modifiers at all (the
5079 // KEY_DOWN event would still have the correct modifiers if they're really
5081 if ( event
.m_controlDown
&& event
.m_altDown
&&
5082 (id
>= 32 && id
< 256) )
5084 event
.m_controlDown
=
5085 event
.m_altDown
= false;
5088 return GetEventHandler()->ProcessEvent(event
);
5091 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5093 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5097 // normal ASCII char
5101 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
5102 return GetEventHandler()->ProcessEvent(event
);
5105 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5107 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5111 // normal ASCII char
5115 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
5116 return GetEventHandler()->ProcessEvent(event
);
5119 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5120 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5122 // FIXME: implement GetMenuItemCount for WinCE, possibly
5123 // in terms of GetMenuItemInfo
5125 const HMENU hmenu
= (HMENU
)lParam
;
5129 mii
.cbSize
= sizeof(MENUITEMINFO
);
5131 // we could use MIIM_FTYPE here as we only need to know if the item is
5132 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5133 // MIIM_FTYPE is not supported under Win95
5134 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5136 // find if we have this letter in any owner drawn item
5137 const int count
= ::GetMenuItemCount(hmenu
);
5138 for ( int i
= 0; i
< count
; i
++ )
5140 // previous loop iteration could modify it, reset it back before
5141 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5144 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5146 if ( mii
.fType
== MFT_OWNERDRAW
)
5148 // dwItemData member of the MENUITEMINFO is a
5149 // pointer to the associated wxMenuItem -- see the
5150 // menu creation code
5151 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5153 const wxChar
*p
= wxStrchr(item
->GetText(), _T('&'));
5156 if ( *p
== _T('&') )
5158 // this is not the accel char, find the real one
5159 p
= wxStrchr(p
+ 1, _T('&'));
5161 else // got the accel char
5163 // FIXME-UNICODE: this comparison doesn't risk to work
5164 // for non ASCII accelerator characters I'm afraid, but
5166 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5172 // this one doesn't match
5179 else // failed to get the menu text?
5181 // it's not fatal, so don't show error, but still log it
5182 wxLogLastError(_T("GetMenuItemInfo"));
5189 bool wxWindowMSW::HandleClipboardEvent( WXUINT nMsg
)
5191 const wxEventType type
= ( nMsg
== WM_CUT
) ? wxEVT_COMMAND_TEXT_CUT
:
5192 ( nMsg
== WM_COPY
) ? wxEVT_COMMAND_TEXT_COPY
:
5193 /*( nMsg == WM_PASTE ) ? */ wxEVT_COMMAND_TEXT_PASTE
;
5194 wxClipboardTextEvent
evt(type
, GetId());
5196 evt
.SetEventObject(this);
5198 return GetEventHandler()->ProcessEvent(evt
);
5201 // ---------------------------------------------------------------------------
5203 // ---------------------------------------------------------------------------
5205 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5209 if ( flags
& JOY_BUTTON1CHG
)
5210 change
= wxJOY_BUTTON1
;
5211 if ( flags
& JOY_BUTTON2CHG
)
5212 change
= wxJOY_BUTTON2
;
5213 if ( flags
& JOY_BUTTON3CHG
)
5214 change
= wxJOY_BUTTON3
;
5215 if ( flags
& JOY_BUTTON4CHG
)
5216 change
= wxJOY_BUTTON4
;
5219 if ( flags
& JOY_BUTTON1
)
5220 buttons
|= wxJOY_BUTTON1
;
5221 if ( flags
& JOY_BUTTON2
)
5222 buttons
|= wxJOY_BUTTON2
;
5223 if ( flags
& JOY_BUTTON3
)
5224 buttons
|= wxJOY_BUTTON3
;
5225 if ( flags
& JOY_BUTTON4
)
5226 buttons
|= wxJOY_BUTTON4
;
5228 // the event ids aren't consecutive so we can't use table based lookup
5230 wxEventType eventType
;
5235 eventType
= wxEVT_JOY_MOVE
;
5240 eventType
= wxEVT_JOY_MOVE
;
5245 eventType
= wxEVT_JOY_ZMOVE
;
5250 eventType
= wxEVT_JOY_ZMOVE
;
5253 case MM_JOY1BUTTONDOWN
:
5255 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5258 case MM_JOY2BUTTONDOWN
:
5260 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5263 case MM_JOY1BUTTONUP
:
5265 eventType
= wxEVT_JOY_BUTTON_UP
;
5268 case MM_JOY2BUTTONUP
:
5270 eventType
= wxEVT_JOY_BUTTON_UP
;
5274 wxFAIL_MSG(wxT("no such joystick event"));
5279 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5280 event
.SetPosition(wxPoint(x
, y
));
5281 event
.SetEventObject(this);
5283 return GetEventHandler()->ProcessEvent(event
);
5293 // ---------------------------------------------------------------------------
5295 // ---------------------------------------------------------------------------
5297 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5298 WXWORD pos
, WXHWND control
)
5300 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5302 wxWindow
*child
= wxFindWinFromHandle(control
);
5304 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5307 wxScrollWinEvent event
;
5308 event
.SetPosition(pos
);
5309 event
.SetOrientation(orientation
);
5310 event
.SetEventObject(this);
5315 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5319 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5323 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5327 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5331 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5335 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5338 case SB_THUMBPOSITION
:
5340 // under Win32, the scrollbar range and position are 32 bit integers,
5341 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5342 // explicitly query the scrollbar for the correct position (this must
5343 // be done only for these two SB_ events as they are the only one
5344 // carrying the scrollbar position)
5346 WinStruct
<SCROLLINFO
> scrollInfo
;
5347 scrollInfo
.fMask
= SIF_TRACKPOS
;
5349 if ( !::GetScrollInfo(GetHwnd(),
5350 orientation
== wxHORIZONTAL
? SB_HORZ
5354 // Not necessarily an error, if there are no scrollbars yet.
5355 // wxLogLastError(_T("GetScrollInfo"));
5358 event
.SetPosition(scrollInfo
.nTrackPos
);
5361 event
.SetEventType( wParam
== SB_THUMBPOSITION
5362 ? wxEVT_SCROLLWIN_THUMBRELEASE
5363 : wxEVT_SCROLLWIN_THUMBTRACK
);
5370 return GetEventHandler()->ProcessEvent(event
);
5373 // ===========================================================================
5375 // ===========================================================================
5377 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5380 HDC dc
= ::GetDC((HWND
) wnd
);
5383 // the_font.UseResource();
5384 // the_font.RealizeResource();
5385 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
5387 was
= (HFONT
) SelectObject(dc
,fnt
);
5389 GetTextMetrics(dc
, &tm
);
5392 SelectObject(dc
,was
);
5394 ReleaseDC((HWND
)wnd
, dc
);
5397 *x
= tm
.tmAveCharWidth
;
5399 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
5401 // the_font.ReleaseResource();
5404 // use the "extended" bit (24) of lParam to distinguish extended keys
5405 // from normal keys as the same key is sent
5407 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
5409 // except that if lParam is 0, it means we don't have real lParam from
5410 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
5411 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
5412 // non-numpad (hence extended) key as this is a more common case
5413 return !lParam
|| (lParam
& (1 << 24)) ? keyExtended
: keyNormal
;
5416 // this array contains the Windows virtual key codes which map one to one to
5417 // WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below
5419 // note that keys having a normal and numpad version (e.g. WXK_HOME and
5420 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
5421 static const struct wxKeyMapping
5425 } gs_specialKeys
[] =
5427 { VK_CANCEL
, WXK_CANCEL
},
5428 { VK_BACK
, WXK_BACK
},
5429 { VK_TAB
, WXK_TAB
},
5430 { VK_CLEAR
, WXK_CLEAR
},
5431 { VK_SHIFT
, WXK_SHIFT
},
5432 { VK_CONTROL
, WXK_CONTROL
},
5433 { VK_MENU
, WXK_ALT
},
5434 { VK_PAUSE
, WXK_PAUSE
},
5435 { VK_CAPITAL
, WXK_CAPITAL
},
5436 { VK_SPACE
, WXK_SPACE
},
5437 { VK_ESCAPE
, WXK_ESCAPE
},
5438 { VK_SELECT
, WXK_SELECT
},
5439 { VK_PRINT
, WXK_PRINT
},
5440 { VK_EXECUTE
, WXK_EXECUTE
},
5441 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
5442 { VK_HELP
, WXK_HELP
},
5444 { VK_NUMPAD0
, WXK_NUMPAD0
},
5445 { VK_NUMPAD1
, WXK_NUMPAD1
},
5446 { VK_NUMPAD2
, WXK_NUMPAD2
},
5447 { VK_NUMPAD3
, WXK_NUMPAD3
},
5448 { VK_NUMPAD4
, WXK_NUMPAD4
},
5449 { VK_NUMPAD5
, WXK_NUMPAD5
},
5450 { VK_NUMPAD6
, WXK_NUMPAD6
},
5451 { VK_NUMPAD7
, WXK_NUMPAD7
},
5452 { VK_NUMPAD8
, WXK_NUMPAD8
},
5453 { VK_NUMPAD9
, WXK_NUMPAD9
},
5454 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
5455 { VK_ADD
, WXK_NUMPAD_ADD
},
5456 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
5457 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
5458 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
5469 { VK_F10
, WXK_F10
},
5470 { VK_F11
, WXK_F11
},
5471 { VK_F12
, WXK_F12
},
5472 { VK_F13
, WXK_F13
},
5473 { VK_F14
, WXK_F14
},
5474 { VK_F15
, WXK_F15
},
5475 { VK_F16
, WXK_F16
},
5476 { VK_F17
, WXK_F17
},
5477 { VK_F18
, WXK_F18
},
5478 { VK_F19
, WXK_F19
},
5479 { VK_F20
, WXK_F20
},
5480 { VK_F21
, WXK_F21
},
5481 { VK_F22
, WXK_F22
},
5482 { VK_F23
, WXK_F23
},
5483 { VK_F24
, WXK_F24
},
5485 { VK_NUMLOCK
, WXK_NUMLOCK
},
5486 { VK_SCROLL
, WXK_SCROLL
},
5489 { VK_LWIN
, WXK_WINDOWS_LEFT
},
5490 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
5491 { VK_APPS
, WXK_WINDOWS_MENU
},
5492 #endif // VK_APPS defined
5495 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
5496 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
5497 int wxCharCodeMSWToWX(int vk
, WXLPARAM lParam
)
5499 // check the table first
5500 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5502 if ( gs_specialKeys
[n
].vk
== vk
)
5503 return gs_specialKeys
[n
].wxk
;
5506 // keys requiring special handling
5510 // the mapping for these keys may be incorrect on non-US keyboards so
5511 // maybe we shouldn't map them to ASCII values at all
5512 case VK_OEM_1
: wxk
= ';'; break;
5513 case VK_OEM_PLUS
: wxk
= '+'; break;
5514 case VK_OEM_COMMA
: wxk
= ','; break;
5515 case VK_OEM_MINUS
: wxk
= '-'; break;
5516 case VK_OEM_PERIOD
: wxk
= '.'; break;
5517 case VK_OEM_2
: wxk
= '/'; break;
5518 case VK_OEM_3
: wxk
= '~'; break;
5519 case VK_OEM_4
: wxk
= '['; break;
5520 case VK_OEM_5
: wxk
= '\\'; break;
5521 case VK_OEM_6
: wxk
= ']'; break;
5522 case VK_OEM_7
: wxk
= '\''; break;
5524 // handle extended keys
5526 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
5530 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
5534 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
5538 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
5542 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
5546 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
5550 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
5554 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
5558 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
5562 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
5566 // don't use ChooseNormalOrExtended() here as the keys are reversed
5567 // here: numpad enter is the extended one
5568 wxk
= lParam
&& (lParam
& (1 << 24)) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
5578 WXWORD
wxCharCodeWXToMSW(int wxk
, bool *isVirtual
)
5583 // check the table first
5584 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5586 if ( gs_specialKeys
[n
].wxk
== wxk
)
5587 return gs_specialKeys
[n
].vk
;
5590 // and then check for special keys not included in the table
5595 case WXK_NUMPAD_PAGEUP
:
5600 case WXK_NUMPAD_PAGEDOWN
:
5605 case WXK_NUMPAD_END
:
5610 case WXK_NUMPAD_HOME
:
5615 case WXK_NUMPAD_LEFT
:
5625 case WXK_NUMPAD_RIGHT
:
5630 case WXK_NUMPAD_DOWN
:
5635 case WXK_NUMPAD_INSERT
:
5640 case WXK_NUMPAD_DELETE
:
5654 // small helper for wxGetKeyState() and wxGetMouseState()
5655 static inline bool wxIsKeyDown(WXWORD vk
)
5657 // the low order bit indicates whether the key was pressed since the last
5658 // call and the high order one indicates whether it is down right now and
5659 // we only want that one
5660 return (::GetAsyncKeyState(vk
) & (1<<15)) != 0;
5663 bool wxGetKeyState(wxKeyCode key
)
5665 // although this does work under Windows, it is not supported under other
5666 // platforms so don't allow it, you must use wxGetMouseState() instead
5667 wxASSERT_MSG( key
!= VK_LBUTTON
&&
5668 key
!= VK_RBUTTON
&&
5670 wxT("can't use wxGetKeyState() for mouse buttons") );
5672 const WXWORD vk
= wxCharCodeWXToMSW(key
);
5674 // if the requested key is a LED key, return true if the led is pressed
5675 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
5677 // low order bit means LED is highlighted and high order one means the
5678 // key is down; for compatibility with the other ports return true if
5679 // either one is set
5680 return ::GetKeyState(vk
) != 0;
5685 return wxIsKeyDown(vk
);
5690 wxMouseState
wxGetMouseState()
5694 GetCursorPos( &pt
);
5698 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
5699 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
5700 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
5702 ms
.SetControlDown(wxIsKeyDown(VK_CONTROL
));
5703 ms
.SetShiftDown(wxIsKeyDown(VK_SHIFT
));
5704 ms
.SetAltDown(wxIsKeyDown(VK_MENU
));
5705 // ms.SetMetaDown();
5711 wxWindow
*wxGetActiveWindow()
5713 HWND hWnd
= GetActiveWindow();
5716 return wxFindWinFromHandle((WXHWND
) hWnd
);
5721 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
5723 HWND hwnd
= (HWND
)hWnd
;
5725 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
5726 // by code in msw/radiobox.cpp), for all the others we just search up the
5728 wxWindow
*win
= (wxWindow
*)NULL
;
5731 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5735 // native radiobuttons return DLGC_RADIOBUTTON here and for any
5736 // wxWindow class which overrides WM_GETDLGCODE processing to
5737 // do it as well, win would be already non NULL
5738 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
5740 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
5742 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
5743 #endif // wxUSE_RADIOBOX
5745 // spin control text buddy window should be mapped to spin ctrl
5746 // itself so try it too
5747 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5750 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
5752 #endif // wxUSE_SPINCTRL
5756 while ( hwnd
&& !win
)
5758 // this is a really ugly hack needed to avoid mistakenly returning the
5759 // parent frame wxWindow for the find/replace modeless dialog HWND -
5760 // this, in turn, is needed to call IsDialogMessage() from
5761 // wxApp::ProcessMessage() as for this we must return NULL from here
5763 // FIXME: this is clearly not the best way to do it but I think we'll
5764 // need to change HWND <-> wxWindow code more heavily than I can
5765 // do it now to fix it
5766 #ifndef __WXMICROWIN__
5767 if ( ::GetWindow(hwnd
, GW_OWNER
) )
5769 // it's a dialog box, don't go upwards
5774 hwnd
= ::GetParent(hwnd
);
5775 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5781 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
5783 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
5784 // in active frames and dialogs, regardless of where the focus is.
5785 static HHOOK wxTheKeyboardHook
= 0;
5786 static FARPROC wxTheKeyboardHookProc
= 0;
5787 int APIENTRY _EXPORT
5788 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
5790 void wxSetKeyboardHook(bool doIt
)
5794 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
5795 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
5797 GetCurrentThreadId()
5798 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
5803 UnhookWindowsHookEx(wxTheKeyboardHook
);
5807 int APIENTRY _EXPORT
5808 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
5810 DWORD hiWord
= HIWORD(lParam
);
5811 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
5813 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5816 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
5817 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
5818 event
.m_altDown
= true;
5820 event
.SetEventObject(NULL
);
5821 event
.m_keyCode
= id
;
5822 event
.m_shiftDown
= wxIsShiftDown();
5823 event
.m_controlDown
= wxIsCtrlDown();
5825 event
.SetTimestamp(::GetMessageTime());
5827 wxWindow
*win
= wxGetActiveWindow();
5828 wxEvtHandler
*handler
;
5831 handler
= win
->GetEventHandler();
5832 event
.SetId(win
->GetId());
5837 event
.SetId(wxID_ANY
);
5840 if ( handler
&& handler
->ProcessEvent(event
) )
5848 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
5851 #endif // !__WXMICROWIN__
5854 const wxChar
*wxGetMessageName(int message
)
5858 case 0x0000: return wxT("WM_NULL");
5859 case 0x0001: return wxT("WM_CREATE");
5860 case 0x0002: return wxT("WM_DESTROY");
5861 case 0x0003: return wxT("WM_MOVE");
5862 case 0x0005: return wxT("WM_SIZE");
5863 case 0x0006: return wxT("WM_ACTIVATE");
5864 case 0x0007: return wxT("WM_SETFOCUS");
5865 case 0x0008: return wxT("WM_KILLFOCUS");
5866 case 0x000A: return wxT("WM_ENABLE");
5867 case 0x000B: return wxT("WM_SETREDRAW");
5868 case 0x000C: return wxT("WM_SETTEXT");
5869 case 0x000D: return wxT("WM_GETTEXT");
5870 case 0x000E: return wxT("WM_GETTEXTLENGTH");
5871 case 0x000F: return wxT("WM_PAINT");
5872 case 0x0010: return wxT("WM_CLOSE");
5873 case 0x0011: return wxT("WM_QUERYENDSESSION");
5874 case 0x0012: return wxT("WM_QUIT");
5875 case 0x0013: return wxT("WM_QUERYOPEN");
5876 case 0x0014: return wxT("WM_ERASEBKGND");
5877 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
5878 case 0x0016: return wxT("WM_ENDSESSION");
5879 case 0x0017: return wxT("WM_SYSTEMERROR");
5880 case 0x0018: return wxT("WM_SHOWWINDOW");
5881 case 0x0019: return wxT("WM_CTLCOLOR");
5882 case 0x001A: return wxT("WM_WININICHANGE");
5883 case 0x001B: return wxT("WM_DEVMODECHANGE");
5884 case 0x001C: return wxT("WM_ACTIVATEAPP");
5885 case 0x001D: return wxT("WM_FONTCHANGE");
5886 case 0x001E: return wxT("WM_TIMECHANGE");
5887 case 0x001F: return wxT("WM_CANCELMODE");
5888 case 0x0020: return wxT("WM_SETCURSOR");
5889 case 0x0021: return wxT("WM_MOUSEACTIVATE");
5890 case 0x0022: return wxT("WM_CHILDACTIVATE");
5891 case 0x0023: return wxT("WM_QUEUESYNC");
5892 case 0x0024: return wxT("WM_GETMINMAXINFO");
5893 case 0x0026: return wxT("WM_PAINTICON");
5894 case 0x0027: return wxT("WM_ICONERASEBKGND");
5895 case 0x0028: return wxT("WM_NEXTDLGCTL");
5896 case 0x002A: return wxT("WM_SPOOLERSTATUS");
5897 case 0x002B: return wxT("WM_DRAWITEM");
5898 case 0x002C: return wxT("WM_MEASUREITEM");
5899 case 0x002D: return wxT("WM_DELETEITEM");
5900 case 0x002E: return wxT("WM_VKEYTOITEM");
5901 case 0x002F: return wxT("WM_CHARTOITEM");
5902 case 0x0030: return wxT("WM_SETFONT");
5903 case 0x0031: return wxT("WM_GETFONT");
5904 case 0x0037: return wxT("WM_QUERYDRAGICON");
5905 case 0x0039: return wxT("WM_COMPAREITEM");
5906 case 0x0041: return wxT("WM_COMPACTING");
5907 case 0x0044: return wxT("WM_COMMNOTIFY");
5908 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
5909 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
5910 case 0x0048: return wxT("WM_POWER");
5912 case 0x004A: return wxT("WM_COPYDATA");
5913 case 0x004B: return wxT("WM_CANCELJOURNAL");
5914 case 0x004E: return wxT("WM_NOTIFY");
5915 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
5916 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
5917 case 0x0052: return wxT("WM_TCARD");
5918 case 0x0053: return wxT("WM_HELP");
5919 case 0x0054: return wxT("WM_USERCHANGED");
5920 case 0x0055: return wxT("WM_NOTIFYFORMAT");
5921 case 0x007B: return wxT("WM_CONTEXTMENU");
5922 case 0x007C: return wxT("WM_STYLECHANGING");
5923 case 0x007D: return wxT("WM_STYLECHANGED");
5924 case 0x007E: return wxT("WM_DISPLAYCHANGE");
5925 case 0x007F: return wxT("WM_GETICON");
5926 case 0x0080: return wxT("WM_SETICON");
5928 case 0x0081: return wxT("WM_NCCREATE");
5929 case 0x0082: return wxT("WM_NCDESTROY");
5930 case 0x0083: return wxT("WM_NCCALCSIZE");
5931 case 0x0084: return wxT("WM_NCHITTEST");
5932 case 0x0085: return wxT("WM_NCPAINT");
5933 case 0x0086: return wxT("WM_NCACTIVATE");
5934 case 0x0087: return wxT("WM_GETDLGCODE");
5935 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
5936 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
5937 case 0x00A2: return wxT("WM_NCLBUTTONUP");
5938 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
5939 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
5940 case 0x00A5: return wxT("WM_NCRBUTTONUP");
5941 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
5942 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
5943 case 0x00A8: return wxT("WM_NCMBUTTONUP");
5944 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
5945 case 0x0100: return wxT("WM_KEYDOWN");
5946 case 0x0101: return wxT("WM_KEYUP");
5947 case 0x0102: return wxT("WM_CHAR");
5948 case 0x0103: return wxT("WM_DEADCHAR");
5949 case 0x0104: return wxT("WM_SYSKEYDOWN");
5950 case 0x0105: return wxT("WM_SYSKEYUP");
5951 case 0x0106: return wxT("WM_SYSCHAR");
5952 case 0x0107: return wxT("WM_SYSDEADCHAR");
5953 case 0x0108: return wxT("WM_KEYLAST");
5955 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
5956 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
5957 case 0x010F: return wxT("WM_IME_COMPOSITION");
5959 case 0x0110: return wxT("WM_INITDIALOG");
5960 case 0x0111: return wxT("WM_COMMAND");
5961 case 0x0112: return wxT("WM_SYSCOMMAND");
5962 case 0x0113: return wxT("WM_TIMER");
5963 case 0x0114: return wxT("WM_HSCROLL");
5964 case 0x0115: return wxT("WM_VSCROLL");
5965 case 0x0116: return wxT("WM_INITMENU");
5966 case 0x0117: return wxT("WM_INITMENUPOPUP");
5967 case 0x011F: return wxT("WM_MENUSELECT");
5968 case 0x0120: return wxT("WM_MENUCHAR");
5969 case 0x0121: return wxT("WM_ENTERIDLE");
5970 case 0x0200: return wxT("WM_MOUSEMOVE");
5971 case 0x0201: return wxT("WM_LBUTTONDOWN");
5972 case 0x0202: return wxT("WM_LBUTTONUP");
5973 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
5974 case 0x0204: return wxT("WM_RBUTTONDOWN");
5975 case 0x0205: return wxT("WM_RBUTTONUP");
5976 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
5977 case 0x0207: return wxT("WM_MBUTTONDOWN");
5978 case 0x0208: return wxT("WM_MBUTTONUP");
5979 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
5980 case 0x020A: return wxT("WM_MOUSEWHEEL");
5981 case 0x0210: return wxT("WM_PARENTNOTIFY");
5982 case 0x0211: return wxT("WM_ENTERMENULOOP");
5983 case 0x0212: return wxT("WM_EXITMENULOOP");
5985 case 0x0213: return wxT("WM_NEXTMENU");
5986 case 0x0214: return wxT("WM_SIZING");
5987 case 0x0215: return wxT("WM_CAPTURECHANGED");
5988 case 0x0216: return wxT("WM_MOVING");
5989 case 0x0218: return wxT("WM_POWERBROADCAST");
5990 case 0x0219: return wxT("WM_DEVICECHANGE");
5992 case 0x0220: return wxT("WM_MDICREATE");
5993 case 0x0221: return wxT("WM_MDIDESTROY");
5994 case 0x0222: return wxT("WM_MDIACTIVATE");
5995 case 0x0223: return wxT("WM_MDIRESTORE");
5996 case 0x0224: return wxT("WM_MDINEXT");
5997 case 0x0225: return wxT("WM_MDIMAXIMIZE");
5998 case 0x0226: return wxT("WM_MDITILE");
5999 case 0x0227: return wxT("WM_MDICASCADE");
6000 case 0x0228: return wxT("WM_MDIICONARRANGE");
6001 case 0x0229: return wxT("WM_MDIGETACTIVE");
6002 case 0x0230: return wxT("WM_MDISETMENU");
6003 case 0x0233: return wxT("WM_DROPFILES");
6005 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6006 case 0x0282: return wxT("WM_IME_NOTIFY");
6007 case 0x0283: return wxT("WM_IME_CONTROL");
6008 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6009 case 0x0285: return wxT("WM_IME_SELECT");
6010 case 0x0286: return wxT("WM_IME_CHAR");
6011 case 0x0290: return wxT("WM_IME_KEYDOWN");
6012 case 0x0291: return wxT("WM_IME_KEYUP");
6014 case 0x0300: return wxT("WM_CUT");
6015 case 0x0301: return wxT("WM_COPY");
6016 case 0x0302: return wxT("WM_PASTE");
6017 case 0x0303: return wxT("WM_CLEAR");
6018 case 0x0304: return wxT("WM_UNDO");
6019 case 0x0305: return wxT("WM_RENDERFORMAT");
6020 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6021 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6022 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6023 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6024 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6025 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6026 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6027 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6028 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6029 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6030 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6031 case 0x0311: return wxT("WM_PALETTECHANGED");
6033 case 0x0312: return wxT("WM_HOTKEY");
6036 // common controls messages - although they're not strictly speaking
6037 // standard, it's nice to decode them nevertheless
6040 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6041 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6042 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6043 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6044 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6045 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6046 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6047 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6048 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6049 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6050 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6051 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6052 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6053 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6054 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6055 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6056 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6057 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6058 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6059 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6060 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6061 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6062 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6063 case 0x1000 + 18: return wxT("LVM_HITTEST");
6064 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6065 case 0x1000 + 20: return wxT("LVM_SCROLL");
6066 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6067 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6068 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6069 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6070 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6071 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6072 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6073 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6074 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6075 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6076 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6077 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6078 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6079 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6080 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6081 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6082 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6083 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6084 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6085 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6086 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6087 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6088 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6089 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6090 case 0x1000 + 42: return wxT("LVM_UPDATE");
6091 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6092 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6093 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6094 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6095 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6096 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6097 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6098 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6099 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6100 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6101 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6102 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6103 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6104 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6105 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6106 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6107 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6108 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6109 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6110 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6111 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6112 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6113 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6114 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6115 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6116 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6119 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6120 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6121 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6122 case 0x1100 + 2: return wxT("TVM_EXPAND");
6123 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6124 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6125 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6126 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6127 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6128 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6129 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6130 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6131 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6132 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6133 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6134 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6135 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6136 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6137 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6138 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6139 case 0x1100 + 17: return wxT("TVM_HITTEST");
6140 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6141 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6142 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6143 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6144 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6145 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6146 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6147 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6148 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6151 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6152 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6153 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6154 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6155 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6156 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6157 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6158 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6159 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6160 case 0x1200 + 6: return wxT("HDM_HITTEST");
6161 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6162 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6163 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6164 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6165 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6166 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6167 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6168 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6171 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6172 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6173 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6174 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6175 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6176 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6177 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6178 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6179 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6180 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6181 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6182 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6183 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6184 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6185 case 0x1300 + 13: return wxT("TCM_HITTEST");
6186 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6187 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6188 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6189 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6190 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6191 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6192 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6193 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6194 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6195 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6196 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6197 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6200 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6201 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
6202 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
6203 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
6204 case WM_USER
+5: return wxT("TB_INDETERMINATE");
6205 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
6206 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
6207 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
6208 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
6209 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
6210 case WM_USER
+17: return wxT("TB_SETSTATE");
6211 case WM_USER
+18: return wxT("TB_GETSTATE");
6212 case WM_USER
+19: return wxT("TB_ADDBITMAP");
6213 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
6214 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
6215 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
6216 case WM_USER
+23: return wxT("TB_GETBUTTON");
6217 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
6218 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
6219 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
6220 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
6221 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
6222 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
6223 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
6224 case WM_USER
+29: return wxT("TB_GETITEMRECT");
6225 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
6226 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
6227 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
6228 case WM_USER
+33: return wxT("TB_AUTOSIZE");
6229 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
6230 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
6231 case WM_USER
+37: return wxT("TB_SETPARENT");
6232 case WM_USER
+39: return wxT("TB_SETROWS");
6233 case WM_USER
+40: return wxT("TB_GETROWS");
6234 case WM_USER
+42: return wxT("TB_SETCMDID");
6235 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
6236 case WM_USER
+44: return wxT("TB_GETBITMAP");
6237 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
6238 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
6239 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
6240 case WM_USER
+47: return wxT("TB_SETINDENT");
6241 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
6242 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
6243 case WM_USER
+50: return wxT("TB_LOADIMAGES");
6244 case WM_USER
+51: return wxT("TB_GETRECT");
6245 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
6246 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
6247 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
6248 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
6249 case WM_USER
+56: return wxT("TB_SETSTYLE");
6250 case WM_USER
+57: return wxT("TB_GETSTYLE");
6251 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
6252 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
6253 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
6254 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
6255 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
6258 static wxString s_szBuf
;
6259 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
6260 return s_szBuf
.c_str();
6263 #endif //__WXDEBUG__
6265 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
6269 HWND hwnd
= GetHwndOf(win
);
6270 HDC hdc
= ::GetDC(hwnd
);
6272 #if !wxDIALOG_UNIT_COMPATIBILITY
6273 // and select the current font into it
6274 HFONT hfont
= GetHfontOf(win
->GetFont());
6277 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
6281 // finally retrieve the text metrics from it
6282 GetTextMetrics(hdc
, &tm
);
6284 #if !wxDIALOG_UNIT_COMPATIBILITY
6288 (void)::SelectObject(hdc
, hfont
);
6292 ::ReleaseDC(hwnd
, hdc
);
6297 // Find the wxWindow at the current mouse position, returning the mouse
6299 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
6301 pt
= wxGetMousePosition();
6302 return wxFindWindowAtPoint(pt
);
6305 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
6311 HWND hWnd
= ::WindowFromPoint(pt2
);
6313 return wxGetWindowFromHWND((WXHWND
)hWnd
);
6316 // Get the current mouse position.
6317 wxPoint
wxGetMousePosition()
6321 GetCursorPosWinCE(&pt
);
6323 GetCursorPos( & pt
);
6326 return wxPoint(pt
.x
, pt
.y
);
6331 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6332 static void WinCEUnregisterHotKey(int modifiers
, int id
)
6334 // Register hotkeys for the hardware buttons
6336 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
6338 UnregisterFunc1Proc procUnregisterFunc
;
6339 hCoreDll
= LoadLibrary(_T("coredll.dll"));
6342 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, _T("UnregisterFunc1"));
6343 if (procUnregisterFunc
)
6344 procUnregisterFunc(modifiers
, id
);
6345 FreeLibrary(hCoreDll
);
6350 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
6352 UINT win_modifiers
=0;
6353 if ( modifiers
& wxMOD_ALT
)
6354 win_modifiers
|= MOD_ALT
;
6355 if ( modifiers
& wxMOD_SHIFT
)
6356 win_modifiers
|= MOD_SHIFT
;
6357 if ( modifiers
& wxMOD_CONTROL
)
6358 win_modifiers
|= MOD_CONTROL
;
6359 if ( modifiers
& wxMOD_WIN
)
6360 win_modifiers
|= MOD_WIN
;
6362 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6363 // Required for PPC and Smartphone hardware buttons
6364 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
6365 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
6368 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
6370 wxLogLastError(_T("RegisterHotKey"));
6378 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
6380 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6381 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
6384 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
6386 wxLogLastError(_T("UnregisterHotKey"));
6396 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
6398 int hotkeyId
= wParam
;
6399 int virtualKey
= HIWORD(lParam
);
6400 int win_modifiers
= LOWORD(lParam
);
6402 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
6403 event
.SetId(hotkeyId
);
6404 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
6405 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
6406 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
6407 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
6409 return GetEventHandler()->ProcessEvent(event
);
6412 #endif // wxUSE_ACCEL
6414 #endif // wxUSE_HOTKEY
6416 // Not tested under WinCE
6419 // this class installs a message hook which really wakes up our idle processing
6420 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
6421 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
6422 // being dragged or even inside ::MessageBox()) and so don't control message
6423 // dispatching otherwise
6424 class wxIdleWakeUpModule
: public wxModule
6427 virtual bool OnInit()
6429 ms_hMsgHookProc
= ::SetWindowsHookEx
6432 &wxIdleWakeUpModule::MsgHookProc
,
6434 GetCurrentThreadId()
6437 if ( !ms_hMsgHookProc
)
6439 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
6447 virtual void OnExit()
6449 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
6452 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
6454 MSG
*msg
= (MSG
*)lParam
;
6456 // only process the message if it is actually going to be removed from
6457 // the message queue, this prevents that the same event from being
6458 // processed multiple times if now someone just called PeekMessage()
6459 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
6461 wxTheApp
->ProcessPendingEvents();
6464 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
6468 static HHOOK ms_hMsgHookProc
;
6470 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
6473 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
6475 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
6477 #endif // __WXWINCE__
6482 static void wxAdjustZOrder(wxWindow
* parent
)
6484 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
6486 // Set the z-order correctly
6487 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
6490 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
6493 wxWindow
*childWin
= current
->GetData();
6494 wxAdjustZOrder(childWin
);
6495 current
= current
->GetNext();
6500 // We need to adjust the z-order of static boxes in WinCE, to
6501 // make 'contained' controls visible
6502 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
6505 wxAdjustZOrder(this);