1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/windows.cpp
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "window.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/msw/wrapwin.h"
33 #include "wx/window.h"
38 #include "wx/dcclient.h"
39 #include "wx/dcmemory.h"
42 #include "wx/layout.h"
43 #include "wx/dialog.h"
45 #include "wx/listbox.h"
46 #include "wx/button.h"
47 #include "wx/msgdlg.h"
48 #include "wx/settings.h"
49 #include "wx/statbox.h"
52 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
53 #include "wx/ownerdrw.h"
56 #if wxUSE_DRAG_AND_DROP
60 #if wxUSE_ACCESSIBILITY
61 #include "wx/access.h"
65 #define WM_GETOBJECT 0x003D
68 #define OBJID_CLIENT 0xFFFFFFFC
72 #include "wx/menuitem.h"
75 #include "wx/msw/private.h"
78 #include "wx/tooltip.h"
86 #include "wx/spinctrl.h"
87 #endif // wxUSE_SPINCTRL
92 #include "wx/textctrl.h"
93 #include "wx/notebook.h"
97 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)) || defined(__CYGWIN10__)
103 #include <windowsx.h>
106 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__)) || defined(__CYGWIN10__)
108 #include <commctrl.h>
110 #elif !defined(__WXMICROWIN__) && !defined(__WXWINCE__) // broken compiler
111 #include "wx/msw/gnuwin32/extra.h"
114 #if defined(__GNUG__)
115 #include "wx/msw/missing.h"
118 #if defined(__WXWINCE__)
119 #include "wx/msw/wince/missing.h"
122 // ----------------------------------------------------------------------------
123 // standard constants not available with all compilers/headers
124 // ----------------------------------------------------------------------------
126 // This didn't appear in mingw until 2.95.2
128 #define SIF_TRACKPOS 16
132 #ifndef WM_MOUSEWHEEL
133 #define WM_MOUSEWHEEL 0x020A
136 #define WHEEL_DELTA 120
138 #ifndef SPI_GETWHEELSCROLLLINES
139 #define SPI_GETWHEELSCROLLLINES 104
141 #endif // wxUSE_MOUSEWHEEL
144 #define VK_OEM_1 0xBA
145 #define VK_OEM_2 0xBF
146 #define VK_OEM_3 0xC0
147 #define VK_OEM_4 0xDB
148 #define VK_OEM_5 0xDC
149 #define VK_OEM_6 0xDD
150 #define VK_OEM_7 0xDE
154 #define VK_OEM_PLUS 0xBB
155 #define VK_OEM_COMMA 0xBC
156 #define VK_OEM_MINUS 0xBD
157 #define VK_OEM_PERIOD 0xBE
160 // ---------------------------------------------------------------------------
162 // ---------------------------------------------------------------------------
164 // the last Windows message we got (FIXME-MT)
165 extern MSG s_currentMsg
;
167 #if wxUSE_MENUS_NATIVE
168 wxMenu
*wxCurrentPopupMenu
= NULL
;
169 #endif // wxUSE_MENUS_NATIVE
171 extern const wxChar
*wxCanvasClassName
;
173 // true if we had already created the std colour map, used by
174 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
175 static bool gs_hasStdCmap
= FALSE
;
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 char *wxGetMessageName(int message
);
190 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
191 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
192 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
194 // this magical function is used to translate VK_APPS key presses to right
196 static void TranslateKbdEventToMouse(wxWindowMSW
*win
,
197 int *x
, int *y
, WPARAM
*flags
);
199 // get the text metrics for the current font
200 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
202 // find the window for the mouse event at the specified position
203 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
); //TW:REQ:Univ
205 // wrapper around BringWindowToTop() API
206 static inline void wxBringWindowToTop(HWND hwnd
)
208 #ifdef __WXMICROWIN__
209 // It seems that MicroWindows brings the _parent_ of the window to the top,
210 // which can be the wrong one.
212 // activate (set focus to) specified window
216 // raise top level parent to top of z order
217 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
219 wxLogLastError(_T("SetWindowPos"));
223 // ---------------------------------------------------------------------------
225 // ---------------------------------------------------------------------------
227 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
229 #ifdef __WXUNIVERSAL__
230 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
232 #if wxUSE_EXTENDED_RTTI
234 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
235 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
236 // windows with negative ids never can be recreated anyway
238 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
240 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
241 if ( win
&& win
->GetId() < 0 )
246 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
248 // make wxWindowList known before the property is used
250 WX_COLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
252 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
254 wxListCollectionToVariantArray( theList
, value
) ;
257 WX_BEGIN_PROPERTIES_TABLE(wxWindow
)
258 // Always constructor Properties first
260 WX_READONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
261 WX_PROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
262 WX_PROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxPoint(-1,-1) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
263 WX_PROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxSize(-1,-1) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
264 WX_PROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
266 // Then all relations of the object graph
268 WX_READONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
270 // and finally all other properties
272 WX_PROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
273 WX_PROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
274 WX_PROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
275 WX_PROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
276 WX_PROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
278 // possible property candidates (not in xrc) or not valid in all subclasses
279 WX_PROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxT("") )
280 WX_PROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
281 WX_PROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxT("") )
282 // MaxHeight, Width , MinHeight , Width
283 // TODO switch label to control and title to toplevels
285 WX_PROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
286 //WX_PROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
287 // WX_PROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
288 WX_PROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
293 WX_END_PROPERTIES_TABLE()
295 WX_BEGIN_HANDLERS_TABLE(wxWindow
)
296 WX_END_HANDLERS_TABLE()
298 WX_CONSTRUCTOR_DUMMY(wxWindow
)
301 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
303 #endif // __WXUNIVERSAL__/__WXMSW__
305 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
306 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground
)
307 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
308 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
311 // ===========================================================================
313 // ===========================================================================
315 // ---------------------------------------------------------------------------
316 // wxWindow utility functions
317 // ---------------------------------------------------------------------------
319 // Find an item given the MS Windows id
320 wxWindow
*wxWindowMSW::FindItem(long id
) const
323 wxControl
*item
= wxDynamicCastThis(wxControl
);
326 // is it we or one of our "internal" children?
327 if ( item
->GetId() == id
328 #ifndef __WXUNIVERSAL__
329 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
330 #endif // __WXUNIVERSAL__
336 #endif // wxUSE_CONTROLS
338 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
341 wxWindow
*childWin
= current
->GetData();
343 wxWindow
*wnd
= childWin
->FindItem(id
);
347 current
= current
->GetNext();
353 // Find an item given the MS Windows handle
354 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
356 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
359 wxWindow
*parent
= current
->GetData();
361 // Do a recursive search.
362 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
368 || parent
->IsKindOf(CLASSINFO(wxControl
))
369 #endif // wxUSE_CONTROLS
372 wxWindow
*item
= current
->GetData();
373 if ( item
->GetHWND() == hWnd
)
377 if ( item
->ContainsHWND(hWnd
) )
382 current
= current
->GetNext();
387 // Default command handler
388 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
393 // ----------------------------------------------------------------------------
394 // constructors and such
395 // ----------------------------------------------------------------------------
397 void wxWindowMSW::Init()
403 m_isBeingDeleted
= FALSE
;
405 m_mouseInWindow
= FALSE
;
406 m_lastKeydownProcessed
= FALSE
;
408 m_childrenDisabled
= NULL
;
418 // as all windows are created with WS_VISIBLE style...
421 #if wxUSE_MOUSEEVENT_HACK
424 m_lastMouseEvent
= -1;
425 #endif // wxUSE_MOUSEEVENT_HACK
429 wxWindowMSW::~wxWindowMSW()
431 m_isBeingDeleted
= TRUE
;
433 #ifndef __WXUNIVERSAL__
434 // VS: make sure there's no wxFrame with last focus set to us:
435 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
437 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
440 if ( frame
->GetLastFocus() == this )
442 frame
->SetLastFocus(NULL
);
447 #endif // __WXUNIVERSAL__
449 // VS: destroy children first and _then_ detach *this from its parent.
450 // If we'd do it the other way around, children wouldn't be able
451 // find their parent frame (see above).
455 m_parent
->RemoveChild(this);
459 // VZ: test temp removed to understand what really happens here
460 //if (::IsWindow(GetHwnd()))
462 if ( !::DestroyWindow(GetHwnd()) )
463 wxLogLastError(wxT("DestroyWindow"));
466 // remove hWnd <-> wxWindow association
467 wxRemoveHandleAssociation(this);
470 delete m_childrenDisabled
;
473 // real construction (Init() must have been called before!)
474 bool wxWindowMSW::Create(wxWindow
*parent
,
479 const wxString
& name
)
481 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
483 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
486 parent
->AddChild(this);
489 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
491 #ifdef __WXUNIVERSAL__
492 // no borders, we draw them ourselves
493 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
497 msflags
&= ~WS_BORDER
;
498 #endif // wxUniversal
500 // all windows are created visible by default except popup ones (which are
501 // like the wxTopLevelWindows in this aspect)
502 if ( style
& wxPOPUP_WINDOW
)
504 msflags
&= ~WS_VISIBLE
;
509 msflags
|= WS_VISIBLE
;
512 return MSWCreate(wxCanvasClassName
, NULL
, pos
, size
, msflags
, exstyle
);
515 // ---------------------------------------------------------------------------
517 // ---------------------------------------------------------------------------
519 void wxWindowMSW::SetFocus()
521 HWND hWnd
= GetHwnd();
522 wxCHECK_RET( hWnd
, _T("can't set focus to invalid window") );
524 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
528 if ( !::SetFocus(hWnd
) )
530 #if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
531 // was there really an error?
532 DWORD dwRes
= ::GetLastError();
535 HWND hwndFocus
= ::GetFocus();
536 if ( hwndFocus
!= hWnd
)
538 wxLogApiError(_T("SetFocus"), dwRes
);
545 void wxWindowMSW::SetFocusFromKbd()
547 // when the focus is given to the control with DLGC_HASSETSEL style from
548 // keyboard its contents should be entirely selected: this is what
549 // ::IsDialogMessage() does and so we should do it as well to provide the
550 // same LNF as the native programs
551 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
553 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
556 // do this after (maybe) setting the selection as like this when
557 // wxEVT_SET_FOCUS handler is called, the selection would have been already
558 // set correctly -- this may be important
559 wxWindowBase::SetFocusFromKbd();
562 // Get the window with the focus
563 wxWindow
*wxWindowBase::FindFocus()
565 HWND hWnd
= ::GetFocus();
568 return wxGetWindowFromHWND((WXHWND
)hWnd
);
574 bool wxWindowMSW::Enable(bool enable
)
576 if ( !wxWindowBase::Enable(enable
) )
579 HWND hWnd
= GetHwnd();
581 ::EnableWindow(hWnd
, (BOOL
)enable
);
583 // the logic below doesn't apply to the top level windows -- otherwise
584 // showing a modal dialog would result in total greying out (and ungreying
585 // out later) of everything which would be really ugly
589 // when the parent is disabled, all of its children should be disabled as
590 // well but when it is enabled back, only those of the children which
591 // hadn't been already disabled in the beginning should be enabled again,
592 // so we have to keep the list of those children
593 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
595 node
= node
->GetNext() )
597 wxWindow
*child
= node
->GetData();
598 if ( child
->IsTopLevel() )
600 // the logic below doesn't apply to top level children
606 // enable the child back unless it had been disabled before us
607 if ( !m_childrenDisabled
|| !m_childrenDisabled
->Find(child
) )
610 else // we're being disabled
612 if ( child
->IsEnabled() )
614 // disable it as children shouldn't stay enabled while the
618 else // child already disabled, remember it
620 // have we created the list of disabled children already?
621 if ( !m_childrenDisabled
)
622 m_childrenDisabled
= new wxWindowList
;
624 m_childrenDisabled
->Append(child
);
629 if ( enable
&& m_childrenDisabled
)
631 // we don't need this list any more, don't keep unused memory
632 delete m_childrenDisabled
;
633 m_childrenDisabled
= NULL
;
639 bool wxWindowMSW::Show(bool show
)
641 if ( !wxWindowBase::Show(show
) )
644 HWND hWnd
= GetHwnd();
645 int cshow
= show
? SW_SHOW
: SW_HIDE
;
646 ::ShowWindow(hWnd
, cshow
);
648 if ( show
&& IsTopLevel() )
650 wxBringWindowToTop(hWnd
);
656 // Raise the window to the top of the Z order
657 void wxWindowMSW::Raise()
659 wxBringWindowToTop(GetHwnd());
662 // Lower the window to the bottom of the Z order
663 void wxWindowMSW::Lower()
665 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
666 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
669 void wxWindowMSW::SetTitle( const wxString
& title
)
671 SetWindowText(GetHwnd(), title
.c_str());
674 wxString
wxWindowMSW::GetTitle() const
676 return wxGetWindowText(GetHWND());
679 void wxWindowMSW::DoCaptureMouse()
681 HWND hWnd
= GetHwnd();
688 void wxWindowMSW::DoReleaseMouse()
690 if ( !::ReleaseCapture() )
692 wxLogLastError(_T("ReleaseCapture"));
696 /* static */ wxWindow
*wxWindowBase::GetCapture()
698 HWND hwnd
= ::GetCapture();
699 return hwnd
? wxFindWinFromHandle((WXHWND
)hwnd
) : (wxWindow
*)NULL
;
702 bool wxWindowMSW::SetFont(const wxFont
& font
)
704 if ( !wxWindowBase::SetFont(font
) )
710 HWND hWnd
= GetHwnd();
713 WXHANDLE hFont
= m_font
.GetResourceHandle();
715 wxASSERT_MSG( hFont
, wxT("should have valid font") );
717 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
722 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
724 if ( !wxWindowBase::SetCursor(cursor
) )
732 HWND hWnd
= GetHwnd();
734 // Change the cursor NOW if we're within the correct window
736 ::GetCursorPos(&point
);
738 RECT rect
= wxGetWindowRect(hWnd
);
740 if ( ::PtInRect(&rect
, point
) && !wxIsBusy() )
741 ::SetCursor(GetHcursorOf(m_cursor
));
747 void wxWindowMSW::WarpPointer (int x
, int y
)
749 ClientToScreen(&x
, &y
);
751 if ( !::SetCursorPos(x
, y
) )
753 wxLogLastError(_T("SetCursorPos"));
757 // ---------------------------------------------------------------------------
759 // ---------------------------------------------------------------------------
761 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
762 static inline int wxDirToWinStyle(int orient
)
764 return orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
;
767 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
769 #ifdef __WXMICROWIN__
770 return ::GetScrollPosWX(hWnd
, wOrient
);
772 WinStruct
<SCROLLINFO
> scrollInfo
;
773 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
774 scrollInfo
.fMask
= SIF_POS
;
775 if ( !::GetScrollInfo(hWnd
,
779 // Not neccessarily an error, if there are no scrollbars yet.
780 // wxLogLastError(_T("GetScrollInfo"));
782 return scrollInfo
.nPos
;
783 // return ::GetScrollPos(hWnd, wOrient);
787 int wxWindowMSW::GetScrollPos(int orient
) const
789 HWND hWnd
= GetHwnd();
790 wxCHECK_MSG( hWnd
, 0, _T("no HWND in GetScrollPos") );
792 return GetScrollPosition(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
);
795 // This now returns the whole range, not just the number
796 // of positions that we can scroll.
797 int wxWindowMSW::GetScrollRange(int orient
) const
800 HWND hWnd
= GetHwnd();
804 ::GetScrollRange(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
807 WinStruct
<SCROLLINFO
> scrollInfo
;
808 scrollInfo
.fMask
= SIF_RANGE
;
809 if ( !::GetScrollInfo(hWnd
,
810 orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
813 // Most of the time this is not really an error, since the return
814 // value can also be zero when there is no scrollbar yet.
815 // wxLogLastError(_T("GetScrollInfo"));
817 maxPos
= scrollInfo
.nMax
;
819 // undo "range - 1" done in SetScrollbar()
823 int wxWindowMSW::GetScrollThumb(int orient
) const
825 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
828 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
830 HWND hWnd
= GetHwnd();
831 wxCHECK_RET( hWnd
, _T("SetScrollPos: no HWND") );
833 WinStruct
<SCROLLINFO
> info
;
837 info
.fMask
= SIF_POS
;
838 if ( HasFlag(wxALWAYS_SHOW_SB
) )
840 // disable scrollbar instead of removing it then
841 info
.fMask
|= SIF_DISABLENOSCROLL
;
844 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
848 // New function that will replace some of the above.
849 void wxWindowMSW::SetScrollbar(int orient
,
855 WinStruct
<SCROLLINFO
> info
;
856 info
.nPage
= pageSize
;
857 info
.nMin
= 0; // range is nMax - nMin + 1
858 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
860 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
861 if ( HasFlag(wxALWAYS_SHOW_SB
) )
863 // disable scrollbar instead of removing it then
864 info
.fMask
|= SIF_DISABLENOSCROLL
;
867 HWND hWnd
= GetHwnd();
870 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
874 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
877 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
883 rect
.left
= prect
->x
;
885 rect
.right
= prect
->x
+ prect
->width
;
886 rect
.bottom
= prect
->y
+ prect
->height
;
895 // FIXME: is this the exact equivalent of the line below?
896 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_ERASE
|SW_INVALIDATE
);
898 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
902 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
904 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
907 for ( int n
= 0; n
< count
; n
++ )
909 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
911 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
914 // don't bother to continue, we're already at top/bottom
921 return pos
!= posStart
;
924 bool wxWindowMSW::ScrollLines(int lines
)
926 bool down
= lines
> 0;
928 return ScrollVertically(GetHwnd(),
929 down
? SB_LINEDOWN
: SB_LINEUP
,
930 down
? lines
: -lines
);
933 bool wxWindowMSW::ScrollPages(int pages
)
935 bool down
= pages
> 0;
937 return ScrollVertically(GetHwnd(),
938 down
? SB_PAGEDOWN
: SB_PAGEUP
,
939 down
? pages
: -pages
);
942 // ---------------------------------------------------------------------------
944 // ---------------------------------------------------------------------------
946 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
948 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
950 HWND hwnd
= (HWND
)hWnd
;
951 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
953 wxAssociateWinWithHandle(hwnd
, this);
955 m_oldWndProc
= (WXFARPROC
)::GetWindowLong((HWND
)hWnd
, GWL_WNDPROC
);
957 // we don't need to subclass the window of our own class (in the Windows
958 // sense of the word)
959 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
961 ::SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
965 // don't bother restoring it neither: this also makes it easy to
966 // implement IsOfStandardClass() method which returns TRUE for the
967 // standard controls and FALSE for the wxWindows own windows as it can
968 // simply check m_oldWndProc
973 void wxWindowMSW::UnsubclassWin()
975 wxRemoveHandleAssociation(this);
977 // Restore old Window proc
978 HWND hwnd
= GetHwnd();
983 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
987 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
989 ::SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG
) m_oldWndProc
);
997 bool wxCheckWindowWndProc(WXHWND hWnd
, WXFARPROC wndProc
)
999 // Unicows note: the code below works, but only because WNDCLASS contains
1000 // original window handler rather that the unicows fake one. This may not
1001 // be on purpose, though; if it stops working with future versions of
1002 // unicows.dll, we can override unicows hooks by setting
1003 // Unicows_{Set,Get}WindowLong and Unicows_RegisterClass to our own
1004 // versions that keep track of fake<->real wnd proc mapping.
1006 // On WinCE (at least), the wndproc comparison doesn't work,
1007 // so have to use something like this.
1009 extern const wxChar
*wxCanvasClassName
;
1010 extern const wxChar
*wxCanvasClassNameNR
;
1011 extern const wxChar
*wxMDIFrameClassName
;
1012 extern const wxChar
*wxMDIFrameClassNameNoRedraw
;
1013 extern const wxChar
*wxMDIChildFrameClassName
;
1014 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
1015 wxString
str(wxGetWindowClass(hWnd
));
1016 if (str
== wxCanvasClassName
||
1017 str
== wxCanvasClassNameNR
||
1018 str
== wxMDIFrameClassName
||
1019 str
== wxMDIFrameClassNameNoRedraw
||
1020 str
== wxMDIChildFrameClassName
||
1021 str
== wxMDIChildFrameClassNameNoRedraw
||
1022 str
== _T("wxTLWHiddenParent"))
1023 return TRUE
; // Effectively means don't subclass
1028 if ( !::GetClassInfo(wxGetInstance(), wxGetWindowClass(hWnd
), &cls
) )
1030 wxLogLastError(_T("GetClassInfo"));
1035 return wndProc
== (WXFARPROC
)cls
.lpfnWndProc
;
1039 // ----------------------------------------------------------------------------
1041 // ----------------------------------------------------------------------------
1043 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1045 long flagsOld
= GetWindowStyleFlag();
1046 if ( flags
== flagsOld
)
1049 // update the internal variable
1050 wxWindowBase::SetWindowStyleFlag(flags
);
1052 // now update the Windows style as well if needed - and if the window had
1053 // been already created
1057 WXDWORD exstyle
, exstyleOld
;
1058 long style
= MSWGetStyle(flags
, &exstyle
),
1059 styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1061 if ( style
!= styleOld
)
1063 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1064 // this function so instead of simply setting the style to the new
1065 // value we clear the bits which were set in styleOld but are set in
1066 // the new one and set the ones which were not set before
1067 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1068 styleReal
&= ~styleOld
;
1071 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1074 // and the extended style
1075 if ( exstyle
!= exstyleOld
)
1077 long exstyleReal
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1078 exstyleReal
&= ~exstyleOld
;
1079 exstyleReal
|= exstyle
;
1081 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyleReal
);
1083 // we must call SetWindowPos() to flash the cached extended style and
1084 // also to make the change to wxSTAY_ON_TOP style take effect: just
1085 // setting the style simply doesn't work
1086 if ( !::SetWindowPos(GetHwnd(),
1087 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1090 SWP_NOMOVE
| SWP_NOSIZE
) )
1092 wxLogLastError(_T("SetWindowPos"));
1097 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1099 // translate the style
1100 WXDWORD style
= WS_CHILD
| WS_VISIBLE
;
1102 if ( flags
& wxCLIP_CHILDREN
)
1103 style
|= WS_CLIPCHILDREN
;
1105 if ( flags
& wxCLIP_SIBLINGS
)
1106 style
|= WS_CLIPSIBLINGS
;
1108 if ( flags
& wxVSCROLL
)
1109 style
|= WS_VSCROLL
;
1111 if ( flags
& wxHSCROLL
)
1112 style
|= WS_HSCROLL
;
1114 const wxBorder border
= GetBorder(flags
);
1116 // WS_BORDER is only required for wxBORDER_SIMPLE
1117 if ( border
== wxBORDER_SIMPLE
)
1120 // now deal with ext style if the caller wants it
1126 if ( flags
& wxTRANSPARENT_WINDOW
)
1127 *exstyle
|= WS_EX_TRANSPARENT
;
1133 case wxBORDER_DEFAULT
:
1134 wxFAIL_MSG( _T("unknown border style") );
1138 case wxBORDER_SIMPLE
:
1141 case wxBORDER_STATIC
:
1142 *exstyle
|= WS_EX_STATICEDGE
;
1145 case wxBORDER_RAISED
:
1146 *exstyle
|= WS_EX_DLGMODALFRAME
;
1149 case wxBORDER_SUNKEN
:
1150 *exstyle
|= WS_EX_CLIENTEDGE
;
1151 style
&= ~WS_BORDER
;
1154 case wxBORDER_DOUBLE
:
1155 *exstyle
|= WS_EX_DLGMODALFRAME
;
1159 // wxUniv doesn't use Windows dialog navigation functions at all
1160 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1161 // to make the dialog navigation work with the nested panels we must
1162 // use this style (top level windows such as dialogs don't need it)
1163 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1165 *exstyle
|= WS_EX_CONTROLPARENT
;
1167 #endif // __WXUNIVERSAL__
1173 // Setup background and foreground colours correctly
1174 void wxWindowMSW::SetupColours()
1177 SetBackgroundColour(GetParent()->GetBackgroundColour());
1180 bool wxWindowMSW::IsMouseInWindow() const
1182 // get the mouse position
1184 ::GetCursorPos(&pt
);
1186 // find the window which currently has the cursor and go up the window
1187 // chain until we find this window - or exhaust it
1188 HWND hwnd
= ::WindowFromPoint(pt
);
1189 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1190 hwnd
= ::GetParent(hwnd
);
1192 return hwnd
!= NULL
;
1195 void wxWindowMSW::OnInternalIdle()
1197 // Check if we need to send a LEAVE event
1198 if ( m_mouseInWindow
)
1200 // note that we should generate the leave event whether the window has
1201 // or doesn't have mouse capture
1202 if ( !IsMouseInWindow() )
1204 // Generate a LEAVE event
1205 m_mouseInWindow
= FALSE
;
1207 // Unfortunately the mouse button and keyboard state may have
1208 // changed by the time the OnInternalIdle function is called, so 'state'
1209 // may be meaningless.
1211 if ( wxIsShiftDown() )
1213 if ( wxIsCtrlDown() )
1214 state
|= MK_CONTROL
;
1215 if ( GetKeyState( VK_LBUTTON
) )
1216 state
|= MK_LBUTTON
;
1217 if ( GetKeyState( VK_MBUTTON
) )
1218 state
|= MK_MBUTTON
;
1219 if ( GetKeyState( VK_RBUTTON
) )
1220 state
|= MK_RBUTTON
;
1223 if ( !::GetCursorPos(&pt
) )
1225 wxLogLastError(_T("GetCursorPos"));
1228 // we need to have client coordinates here for symmetry with
1229 // wxEVT_ENTER_WINDOW
1230 RECT rect
= wxGetWindowRect(GetHwnd());
1234 wxMouseEvent
event2(wxEVT_LEAVE_WINDOW
);
1235 InitMouseEvent(event2
, pt
.x
, pt
.y
, state
);
1237 (void)GetEventHandler()->ProcessEvent(event2
);
1241 if (wxUpdateUIEvent::CanUpdate(this))
1242 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1245 // Set this window to be the child of 'parent'.
1246 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1248 if ( !wxWindowBase::Reparent(parent
) )
1251 HWND hWndChild
= GetHwnd();
1252 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1254 ::SetParent(hWndChild
, hWndParent
);
1259 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1261 #ifndef __WXMICROWIN__
1262 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1266 void wxWindowMSW::Freeze()
1268 SendSetRedraw(GetHwnd(), FALSE
);
1271 void wxWindowMSW::Thaw()
1273 SendSetRedraw(GetHwnd(), TRUE
);
1275 // we need to refresh everything or otherwise he invalidated area is not
1280 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1282 HWND hWnd
= GetHwnd();
1288 mswRect
.left
= rect
->x
;
1289 mswRect
.top
= rect
->y
;
1290 mswRect
.right
= rect
->x
+ rect
->width
;
1291 mswRect
.bottom
= rect
->y
+ rect
->height
;
1293 ::InvalidateRect(hWnd
, &mswRect
, eraseBack
);
1296 ::InvalidateRect(hWnd
, NULL
, eraseBack
);
1300 void wxWindowMSW::Update()
1302 if ( !::UpdateWindow(GetHwnd()) )
1304 wxLogLastError(_T("UpdateWindow"));
1307 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1308 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1309 // handler needs to be really drawn right now
1314 // ---------------------------------------------------------------------------
1316 // ---------------------------------------------------------------------------
1319 #if wxUSE_DRAG_AND_DROP
1320 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1322 if ( m_dropTarget
!= 0 ) {
1323 m_dropTarget
->Revoke(m_hWnd
);
1324 delete m_dropTarget
;
1327 m_dropTarget
= pDropTarget
;
1328 if ( m_dropTarget
!= 0 )
1329 m_dropTarget
->Register(m_hWnd
);
1331 #endif // wxUSE_DRAG_AND_DROP
1333 // old style file-manager drag&drop support: we retain the old-style
1334 // DragAcceptFiles in parallel with SetDropTarget.
1335 void wxWindowMSW::DragAcceptFiles(bool accept
)
1337 #if !defined(__WXWINCE__)
1338 HWND hWnd
= GetHwnd();
1340 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1344 // ----------------------------------------------------------------------------
1346 // ----------------------------------------------------------------------------
1350 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1352 wxWindowBase::DoSetToolTip(tooltip
);
1355 m_tooltip
->SetWindow((wxWindow
*)this);
1358 #endif // wxUSE_TOOLTIPS
1360 // ---------------------------------------------------------------------------
1361 // moving and resizing
1362 // ---------------------------------------------------------------------------
1365 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1367 RECT rect
= wxGetWindowRect(GetHwnd());
1370 *x
= rect
.right
- rect
.left
;
1372 *y
= rect
.bottom
- rect
.top
;
1375 // Get size *available for subwindows* i.e. excluding menu bar etc.
1376 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1378 RECT rect
= wxGetClientRect(GetHwnd());
1386 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1388 RECT rect
= wxGetWindowRect(GetHwnd());
1391 point
.x
= rect
.left
;
1394 // we do the adjustments with respect to the parent only for the "real"
1395 // children, not for the dialogs/frames
1396 if ( !IsTopLevel() )
1398 HWND hParentWnd
= 0;
1399 wxWindow
*parent
= GetParent();
1401 hParentWnd
= GetWinHwnd(parent
);
1403 // Since we now have the absolute screen coords, if there's a parent we
1404 // must subtract its top left corner
1407 ::ScreenToClient(hParentWnd
, &point
);
1412 // We may be faking the client origin. So a window that's really at (0,
1413 // 30) may appear (to wxWin apps) to be at (0, 0).
1414 wxPoint
pt(parent
->GetClientAreaOrigin());
1426 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1434 ::ScreenToClient(GetHwnd(), &pt
);
1442 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1450 ::ClientToScreen(GetHwnd(), &pt
);
1458 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1460 // TODO: is this consistent with other platforms?
1461 // Still, negative width or height shouldn't be allowed
1466 if ( !::MoveWindow(GetHwnd(), x
, y
, width
, height
, TRUE
) )
1468 wxLogLastError(wxT("MoveWindow"));
1472 // set the size of the window: if the dimensions are positive, just use them,
1473 // but if any of them is equal to -1, it means that we must find the value for
1474 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1475 // which case -1 is a valid value for x and y)
1477 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1478 // the width/height to best suit our contents, otherwise we reuse the current
1480 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1482 // get the current size and position...
1483 int currentX
, currentY
;
1484 GetPosition(¤tX
, ¤tY
);
1485 int currentW
,currentH
;
1486 GetSize(¤tW
, ¤tH
);
1488 // ... and don't do anything (avoiding flicker) if it's already ok
1489 if ( x
== currentX
&& y
== currentY
&&
1490 width
== currentW
&& height
== currentH
)
1495 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1497 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1500 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1502 wxSize
size(-1, -1);
1505 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1507 size
= DoGetBestSize();
1512 // just take the current one
1519 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1523 size
= DoGetBestSize();
1525 //else: already called DoGetBestSize() above
1531 // just take the current one
1536 DoMoveWindow(x
, y
, width
, height
);
1539 void wxWindowMSW::DoSetClientSize(int width
, int height
)
1541 // setting the client size is less obvious than it it could have been
1542 // because in the result of changing the total size the window scrollbar
1543 // may [dis]appear and/or its menubar may [un]wrap and so the client size
1544 // will not be correct as the difference between the total and client size
1545 // changes - so we keep changing it until we get it right
1547 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1548 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1549 // may become 3 if the window had 0 size originally and so we didn't
1550 // calculate the scrollbar correction correctly during the first iteration)
1551 // but just to be on the safe side we check for it instead of making it an
1552 // "infinite" loop (i.e. leaving break inside as the only way to get out)
1553 for ( int i
= 0; i
< 4; i
++ )
1556 ::GetClientRect(GetHwnd(), &rectClient
);
1558 // if the size is already ok, stop here (rectClient.left = top = 0)
1559 if ( (rectClient
.right
== width
|| width
== -1) &&
1560 (rectClient
.bottom
== height
|| height
== -1) )
1565 int widthClient
= width
,
1566 heightClient
= height
;
1568 // Find the difference between the entire window (title bar and all)
1569 // and the client area; add this to the new client size to move the
1572 ::GetWindowRect(GetHwnd(), &rectWin
);
1574 widthClient
+= rectWin
.right
- rectWin
.left
- rectClient
.right
;
1575 heightClient
+= rectWin
.bottom
- rectWin
.top
- rectClient
.bottom
;
1578 point
.x
= rectWin
.left
;
1579 point
.y
= rectWin
.top
;
1581 // MoveWindow positions the child windows relative to the parent, so
1582 // adjust if necessary
1583 if ( !IsTopLevel() )
1585 wxWindow
*parent
= GetParent();
1588 ::ScreenToClient(GetHwndOf(parent
), &point
);
1592 DoMoveWindow(point
.x
, point
.y
, widthClient
, heightClient
);
1596 // For implementation purposes - sometimes decorations make the client area
1598 wxPoint
wxWindowMSW::GetClientAreaOrigin() const
1600 return wxPoint(0, 0);
1603 // ---------------------------------------------------------------------------
1605 // ---------------------------------------------------------------------------
1607 int wxWindowMSW::GetCharHeight() const
1609 return wxGetTextMetrics(this).tmHeight
;
1612 int wxWindowMSW::GetCharWidth() const
1614 // +1 is needed because Windows apparently adds it when calculating the
1615 // dialog units size in pixels
1616 #if wxDIALOG_UNIT_COMPATIBILITY
1617 return wxGetTextMetrics(this).tmAveCharWidth
;
1619 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
1623 void wxWindowMSW::GetTextExtent(const wxString
& string
,
1625 int *descent
, int *externalLeading
,
1626 const wxFont
*theFont
) const
1628 const wxFont
*fontToUse
= theFont
;
1630 fontToUse
= &m_font
;
1632 HWND hWnd
= GetHwnd();
1633 HDC dc
= ::GetDC(hWnd
);
1637 if ( fontToUse
&& fontToUse
->Ok() )
1639 fnt
= (HFONT
)((wxFont
*)fontToUse
)->GetResourceHandle(); // const_cast
1641 hfontOld
= (HFONT
)SelectObject(dc
,fnt
);
1646 GetTextExtentPoint(dc
, string
, (int)string
.Length(), &sizeRect
);
1647 GetTextMetrics(dc
, &tm
);
1649 if ( fontToUse
&& fnt
&& hfontOld
)
1650 SelectObject(dc
, hfontOld
);
1652 ReleaseDC(hWnd
, dc
);
1659 *descent
= tm
.tmDescent
;
1660 if ( externalLeading
)
1661 *externalLeading
= tm
.tmExternalLeading
;
1664 // ---------------------------------------------------------------------------
1666 // ---------------------------------------------------------------------------
1668 #if wxUSE_MENUS_NATIVE
1670 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
1671 // immediately, without waiting for the next event loop iteration
1673 // NB: this function should probably be made public later as it can almost
1674 // surely replace wxYield() elsewhere as well
1675 static void wxYieldForCommandsOnly()
1677 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
1678 // want to process it here)
1680 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
)
1681 && msg
.message
!= WM_QUIT
)
1683 wxTheApp
->DoMessage((WXMSG
*)&msg
);
1686 // If we retrieved a WM_QUIT, insert back into the message queue.
1687 if (msg
.message
== WM_QUIT
)
1688 ::PostQuitMessage(0);
1691 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1693 menu
->SetInvokingWindow(this);
1696 HWND hWnd
= GetHwnd();
1697 HMENU hMenu
= GetHmenuOf(menu
);
1701 ::ClientToScreen(hWnd
, &point
);
1702 wxCurrentPopupMenu
= menu
;
1704 #if !defined(__WXWINCE__)
1705 flags
= TPM_RIGHTBUTTON
;
1707 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
1709 // we need to do it righ now as otherwise the events are never going to be
1710 // sent to wxCurrentPopupMenu from HandleCommand()
1712 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
1713 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
1714 // destroyed as soon as we return (it can be a local variable in the caller
1715 // for example) and so we do need to process the event immediately
1716 wxYieldForCommandsOnly();
1718 wxCurrentPopupMenu
= NULL
;
1720 menu
->SetInvokingWindow(NULL
);
1725 #endif // wxUSE_MENUS_NATIVE
1727 // ===========================================================================
1728 // pre/post message processing
1729 // ===========================================================================
1731 long wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1734 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1736 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
1739 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
1741 // wxUniversal implements tab traversal itself
1742 #ifndef __WXUNIVERSAL__
1743 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
1745 // intercept dialog navigation keys
1746 MSG
*msg
= (MSG
*)pMsg
;
1748 // here we try to do all the job which ::IsDialogMessage() usually does
1751 if ( msg
->message
== WM_KEYDOWN
)
1753 bool bCtrlDown
= wxIsCtrlDown();
1754 bool bShiftDown
= wxIsShiftDown();
1756 // WM_GETDLGCODE: ask the control if it wants the key for itself,
1757 // don't process it if it's the case (except for Ctrl-Tab/Enter
1758 // combinations which are always processed)
1762 lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
1764 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
1765 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
1766 // it, of course, implies them
1767 if ( lDlgCode
& DLGC_WANTALLKEYS
)
1769 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
1773 bool bForward
= TRUE
,
1774 bWindowChange
= FALSE
;
1776 // should we process this message specially?
1777 bool bProcess
= TRUE
;
1778 switch ( msg
->wParam
)
1781 // assume that nobody wants Shift-TAB for himself - if we
1782 // don't do it there is no easy way for a control to grab
1783 // TABs but still let Shift-TAB work as navugation key
1784 if ( (lDlgCode
& DLGC_WANTTAB
) && !bShiftDown
) {
1788 // Ctrl-Tab cycles thru notebook pages
1789 bWindowChange
= bCtrlDown
;
1790 bForward
= !bShiftDown
;
1796 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
1804 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
1810 if ( (lDlgCode
& DLGC_WANTMESSAGE
) && !bCtrlDown
)
1812 // control wants to process Enter itself, don't
1813 // call IsDialogMessage() which would interpret
1817 else if ( lDlgCode
& DLGC_BUTTON
)
1819 // let IsDialogMessage() handle this for all
1820 // buttons except the owner-drawn ones which it
1821 // just seems to ignore
1822 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
1823 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
1825 // emulate the button click
1826 wxWindow
*btn
= wxFindWinFromHandle((WXHWND
)msg
->hwnd
);
1828 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
1833 // FIXME: this should be handled by
1834 // wxNavigationKeyEvent handler and not here!!
1838 wxButton
*btn
= wxDynamicCast(GetDefaultItem(),
1840 if ( btn
&& btn
->IsEnabled() )
1842 // if we do have a default button, do press it
1843 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
1847 else // no default button
1849 #endif // wxUSE_BUTTON
1850 // this is a quick and dirty test for a text
1852 if ( !(lDlgCode
& DLGC_HASSETSEL
) )
1854 // don't process Enter, the control might
1855 // need it for itself and don't let
1856 // ::IsDialogMessage() have it as it can
1857 // eat the Enter events sometimes
1860 else if (!IsTopLevel())
1862 // if not a top level window, let parent
1866 //else: treat Enter as TAB: pass to the next
1867 // control as this is the best thing to do
1868 // if the text doesn't handle Enter itself
1880 wxNavigationKeyEvent event
;
1881 event
.SetDirection(bForward
);
1882 event
.SetWindowChange(bWindowChange
);
1883 event
.SetEventObject(this);
1885 if ( GetEventHandler()->ProcessEvent(event
) )
1892 // let ::IsDialogMessage() do almost everything and handle just the
1893 // things it doesn't here: Ctrl-TAB for switching notebook pages
1894 if ( msg
->message
== WM_KEYDOWN
)
1896 // don't process system keys here
1897 if ( !(HIWORD(msg
->lParam
) & KF_ALTDOWN
) )
1899 if ( (msg
->wParam
== VK_TAB
) && wxIsCtrlDown() )
1901 // find the first notebook parent and change its page
1902 wxWindow
*win
= this;
1903 wxNotebook
*nbook
= NULL
;
1904 while ( win
&& !nbook
)
1906 nbook
= wxDynamicCast(win
, wxNotebook
);
1907 win
= win
->GetParent();
1912 bool forward
= !wxIsShiftDown();
1914 nbook
->AdvanceSelection(forward
);
1921 // we handle VK_ESCAPE ourselves in wxDialog::OnCharHook() and we
1922 // shouldn't let IsDialogMessage() get it as it _always_ eats the
1923 // message even when there is no cancel button and when the message is
1924 // needed by the control itself: in particular, it prevents the tree in
1925 // place edit control from being closed with Escape in a dialog
1926 if ( msg
->message
!= WM_KEYDOWN
|| msg
->wParam
!= VK_ESCAPE
)
1928 // ::IsDialogMessage() is broken and may sometimes hang the
1929 // application by going into an infinite loop, so we try to detect
1930 // [some of] the situatations when this may happen and not call it
1933 // assume we can call it by default
1934 bool canSafelyCallIsDlgMsg
= TRUE
;
1936 HWND hwndFocus
= ::GetFocus();
1938 // if the currently focused window itself has WS_EX_CONTROLPARENT style, ::IsDialogMessage() will also enter
1939 // an infinite loop, because it will recursively check the child
1940 // windows but not the window itself and so if none of the children
1941 // accepts focus it loops forever (as it only stops when it gets
1942 // back to the window it started from)
1944 // while it is very unusual that a window with WS_EX_CONTROLPARENT
1945 // style has the focus, it can happen. One such possibility is if
1946 // all windows are either toplevel, wxDialog, wxPanel or static
1947 // controls and no window can actually accept keyboard input.
1948 #if !defined(__WXWINCE__)
1949 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1951 // passimistic by default
1952 canSafelyCallIsDlgMsg
= FALSE
;
1953 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1955 node
= node
->GetNext() )
1957 wxWindow
* const win
= node
->GetData();
1958 if ( win
->AcceptsFocus() &&
1959 !(::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
) &
1960 WS_EX_CONTROLPARENT
) )
1962 // it shouldn't hang...
1963 canSafelyCallIsDlgMsg
= TRUE
;
1969 #endif // !__WXWINCE__
1971 if ( canSafelyCallIsDlgMsg
)
1973 // ::IsDialogMessage() can enter in an infinite loop when the
1974 // currently focused window is disabled or hidden and its
1975 // parent has WS_EX_CONTROLPARENT style, so don't call it in
1979 if ( !::IsWindowEnabled(hwndFocus
) ||
1980 !::IsWindowVisible(hwndFocus
) )
1982 // it would enter an infinite loop if we do this!
1983 canSafelyCallIsDlgMsg
= FALSE
;
1988 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
1990 // it's a top level window, don't go further -- e.g. even
1991 // if the parent of a dialog is disabled, this doesn't
1992 // break navigation inside the dialog
1996 hwndFocus
= ::GetParent(hwndFocus
);
2000 // let IsDialogMessage() have the message if it's safe to call it
2001 if ( canSafelyCallIsDlgMsg
&& ::IsDialogMessage(GetHwnd(), msg
) )
2003 // IsDialogMessage() did something...
2008 #endif // __WXUNIVERSAL__
2013 // relay mouse move events to the tooltip control
2014 MSG
*msg
= (MSG
*)pMsg
;
2015 if ( msg
->message
== WM_MOUSEMOVE
)
2016 m_tooltip
->RelayEvent(pMsg
);
2018 #endif // wxUSE_TOOLTIPS
2023 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2025 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2026 return m_acceleratorTable
.Translate(this, pMsg
);
2030 #endif // wxUSE_ACCEL
2033 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* WXUNUSED(pMsg
))
2035 // preprocess all messages by default
2039 // ---------------------------------------------------------------------------
2040 // message params unpackers
2041 // ---------------------------------------------------------------------------
2043 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2044 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2046 *id
= LOWORD(wParam
);
2047 *hwnd
= (WXHWND
)lParam
;
2048 *cmd
= HIWORD(wParam
);
2051 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2052 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2054 *state
= LOWORD(wParam
);
2055 *minimized
= HIWORD(wParam
);
2056 *hwnd
= (WXHWND
)lParam
;
2059 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2060 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2062 *code
= LOWORD(wParam
);
2063 *pos
= HIWORD(wParam
);
2064 *hwnd
= (WXHWND
)lParam
;
2067 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2068 WXWORD
*nCtlColor
, WXHDC
*hdc
, WXHWND
*hwnd
)
2070 #ifndef __WXMICROWIN__
2071 *nCtlColor
= CTLCOLOR_BTN
;
2072 *hwnd
= (WXHWND
)lParam
;
2073 *hdc
= (WXHDC
)wParam
;
2077 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2078 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2080 *item
= (WXWORD
)wParam
;
2081 *flags
= HIWORD(wParam
);
2082 *hmenu
= (WXHMENU
)lParam
;
2085 // ---------------------------------------------------------------------------
2086 // Main wxWindows window proc and the window proc for wxWindow
2087 // ---------------------------------------------------------------------------
2089 // Hook for new window just as it's being created, when the window isn't yet
2090 // associated with the handle
2091 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2093 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2094 // window being created and insures that it's always unset back later
2095 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2097 gs_winBeingCreated
= winBeingCreated
;
2100 wxWindowCreationHook::~wxWindowCreationHook()
2102 gs_winBeingCreated
= NULL
;
2106 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2108 // trace all messages - useful for the debugging
2110 wxLogTrace(wxTraceMessages
,
2111 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2112 wxGetMessageName(message
), (long)hWnd
, (long)wParam
, lParam
);
2113 #endif // __WXDEBUG__
2115 wxWindowMSW
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
2117 // when we get the first message for the HWND we just created, we associate
2118 // it with wxWindow stored in gs_winBeingCreated
2119 if ( !wnd
&& gs_winBeingCreated
)
2121 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2122 wnd
= gs_winBeingCreated
;
2123 gs_winBeingCreated
= NULL
;
2124 wnd
->SetHWND((WXHWND
)hWnd
);
2130 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2132 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2137 long wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2139 // did we process the message?
2140 bool processed
= FALSE
;
2151 // for most messages we should return 0 when we do process the message
2159 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2162 // return 0 to allow window creation
2163 rc
.result
= mayCreate
? 0 : -1;
2169 // never set processed to TRUE and *always* pass WM_DESTROY to
2170 // DefWindowProc() as Windows may do some internal cleanup when
2171 // processing it and failing to pass the message along may cause
2172 // memory and resource leaks!
2173 (void)HandleDestroy();
2177 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2180 #if !defined(__WXWINCE__)
2183 LPRECT pRect
= (LPRECT
)lParam
;
2185 rc
.SetLeft(pRect
->left
);
2186 rc
.SetTop(pRect
->top
);
2187 rc
.SetRight(pRect
->right
);
2188 rc
.SetBottom(pRect
->bottom
);
2189 processed
= HandleMoving(rc
);
2191 pRect
->left
= rc
.GetLeft();
2192 pRect
->top
= rc
.GetTop();
2193 pRect
->right
= rc
.GetRight();
2194 pRect
->bottom
= rc
.GetBottom();
2205 // we're not interested in these messages at all
2208 case SIZE_MINIMIZED
:
2209 // we shouldn't send sizev events for these messages as the
2210 // client size may be negative which breaks existing code
2212 // OTOH we might send another (wxMinimizedEvent?) one or
2213 // add an additional parameter to wxSizeEvent if this is
2214 // useful to anybody
2218 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
2219 // fall through nevertheless
2221 case SIZE_MAXIMIZED
:
2223 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
),
2228 #if !defined(__WXWINCE__)
2231 LPRECT pRect
= (LPRECT
)lParam
;
2233 rc
.SetLeft(pRect
->left
);
2234 rc
.SetTop(pRect
->top
);
2235 rc
.SetRight(pRect
->right
);
2236 rc
.SetBottom(pRect
->bottom
);
2237 processed
= HandleSizing(rc
);
2239 pRect
->left
= rc
.GetLeft();
2240 pRect
->top
= rc
.GetTop();
2241 pRect
->right
= rc
.GetRight();
2242 pRect
->bottom
= rc
.GetBottom();
2248 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2249 case WM_ACTIVATEAPP
:
2250 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2256 WXWORD state
, minimized
;
2258 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2260 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2265 processed
= HandleSetFocus((WXHWND
)(HWND
)wParam
);
2269 processed
= HandleKillFocus((WXHWND
)(HWND
)wParam
);
2276 // cast to wxWindow is needed for wxUniv
2277 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2278 processed
= HandlePaint();
2282 processed
= HandlePaint();
2288 #ifdef __WXUNIVERSAL__
2289 // Universal uses its own wxFrame/wxDialog, so we don't receive
2290 // close events unless we have this.
2295 // don't let the DefWindowProc() destroy our window - we'll do it
2296 // ourselves in ~wxWindow
2303 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2307 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2308 GET_Y_LPARAM(lParam
),
2312 #if wxUSE_MOUSEWHEEL
2314 processed
= HandleMouseWheel(wParam
, lParam
);
2318 case WM_LBUTTONDOWN
:
2320 case WM_LBUTTONDBLCLK
:
2321 case WM_RBUTTONDOWN
:
2323 case WM_RBUTTONDBLCLK
:
2324 case WM_MBUTTONDOWN
:
2326 case WM_MBUTTONDBLCLK
:
2328 #ifdef __WXMICROWIN__
2329 // MicroWindows seems to ignore the fact that a window is
2330 // disabled. So catch mouse events and throw them away if
2332 wxWindowMSW
* win
= this;
2335 if (!win
->IsEnabled())
2341 win
= win
->GetParent();
2342 if ( !win
|| win
->IsTopLevel() )
2349 #endif // __WXMICROWIN__
2350 int x
= GET_X_LPARAM(lParam
),
2351 y
= GET_Y_LPARAM(lParam
);
2353 // redirect the event to a static control if necessary by
2354 // finding one under mouse
2356 if ( GetCapture() == this )
2358 // but don't do it if the mouse is captured by this window
2359 // because then it should really get this event itself
2364 win
= FindWindowForMouseEvent(this, &x
, &y
);
2366 // this should never happen
2367 wxCHECK_MSG( win
, 0,
2368 _T("FindWindowForMouseEvent() returned NULL") );
2370 // for the standard classes their WndProc sets the focus to
2371 // them anyhow and doing it from here results in some weird
2372 // problems, but for our windows we want them to acquire
2373 // focus when clicked
2374 if ( !win
->IsOfStandardClass() )
2376 if ( message
== WM_LBUTTONDOWN
&& win
->AcceptsFocus() )
2381 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2390 case MM_JOY1BUTTONDOWN
:
2391 case MM_JOY2BUTTONDOWN
:
2392 case MM_JOY1BUTTONUP
:
2393 case MM_JOY2BUTTONUP
:
2394 processed
= HandleJoystickEvent(message
,
2395 GET_X_LPARAM(lParam
),
2396 GET_Y_LPARAM(lParam
),
2399 #endif // __WXMICROWIN__
2402 processed
= HandleSysCommand(wParam
, lParam
);
2409 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2411 processed
= HandleCommand(id
, cmd
, hwnd
);
2416 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2419 // for these messages we must return TRUE if process the message
2422 case WM_MEASUREITEM
:
2424 int idCtrl
= (UINT
)wParam
;
2425 if ( message
== WM_DRAWITEM
)
2427 processed
= MSWOnDrawItem(idCtrl
,
2428 (WXDRAWITEMSTRUCT
*)lParam
);
2432 processed
= MSWOnMeasureItem(idCtrl
,
2433 (WXMEASUREITEMSTRUCT
*)lParam
);
2440 #endif // defined(WM_DRAWITEM)
2443 if ( !IsOfStandardClass() )
2445 // we always want to get the char events
2446 rc
.result
= DLGC_WANTCHARS
;
2448 if ( GetWindowStyleFlag() & wxWANTS_CHARS
)
2450 // in fact, we want everything
2451 rc
.result
|= DLGC_WANTARROWS
|
2458 //else: get the dlg code from the DefWindowProc()
2463 // If this has been processed by an event handler, return 0 now
2464 // (we've handled it).
2465 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
2466 if ( m_lastKeydownProcessed
)
2475 // we consider these message "not interesting" to OnChar, so
2476 // just don't do anything more with them
2486 // avoid duplicate messages to OnChar for these ASCII keys:
2487 // they will be translated by TranslateMessage() and received
2509 // but set processed to FALSE, not TRUE to still pass them
2510 // to the control's default window proc - otherwise
2511 // built-in keyboard handling won't work
2516 // special case of VK_APPS: treat it the same as right mouse
2517 // click because both usually pop up a context menu
2523 TranslateKbdEventToMouse(this, &x
, &y
, &flags
);
2524 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, x
, y
, flags
);
2530 // do generate a CHAR event
2531 processed
= HandleChar((WORD
)wParam
, lParam
);
2534 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
2541 // special case of VK_APPS: treat it the same as right mouse button
2542 if ( wParam
== VK_APPS
)
2547 TranslateKbdEventToMouse(this, &x
, &y
, &flags
);
2548 processed
= HandleMouseEvent(WM_RBUTTONUP
, x
, y
, flags
);
2553 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
2558 case WM_CHAR
: // Always an ASCII character
2559 if ( m_lastKeydownProcessed
)
2561 // The key was handled in the EVT_KEY_DOWN and handling
2562 // a key in an EVT_KEY_DOWN handler is meant, by
2563 // design, to prevent EVT_CHARs from happening
2564 m_lastKeydownProcessed
= FALSE
;
2569 processed
= HandleChar((WORD
)wParam
, lParam
, TRUE
);
2575 processed
= HandleHotKey((WORD
)wParam
, lParam
);
2577 #endif // wxUSE_HOTKEY
2584 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
2586 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
2592 // CTLCOLOR messages are sent by children to query the parent for their
2593 // colors#ifndef __WXMICROWIN__
2594 #ifndef __WXMICROWIN__
2595 case WM_CTLCOLORMSGBOX
:
2596 case WM_CTLCOLOREDIT
:
2597 case WM_CTLCOLORLISTBOX
:
2598 case WM_CTLCOLORBTN
:
2599 case WM_CTLCOLORDLG
:
2600 case WM_CTLCOLORSCROLLBAR
:
2601 case WM_CTLCOLORSTATIC
:
2606 UnpackCtlColor(wParam
, lParam
, &nCtlColor
, &hdc
, &hwnd
);
2608 processed
= HandleCtlColor(&rc
.hBrush
,
2617 #endif // !__WXMICROWIN__
2619 case WM_SYSCOLORCHANGE
:
2620 // the return value for this message is ignored
2621 processed
= HandleSysColorChange();
2624 #if !defined(__WXWINCE__)
2625 case WM_DISPLAYCHANGE
:
2626 processed
= HandleDisplayChange();
2630 case WM_PALETTECHANGED
:
2631 processed
= HandlePaletteChanged((WXHWND
) (HWND
) wParam
);
2634 case WM_CAPTURECHANGED
:
2635 processed
= HandleCaptureChanged((WXHWND
) (HWND
) lParam
);
2638 case WM_QUERYNEWPALETTE
:
2639 processed
= HandleQueryNewPalette();
2643 processed
= HandleEraseBkgnd((WXHDC
)(HDC
)wParam
);
2646 // we processed the message, i.e. erased the background
2651 #if !defined(__WXWINCE__)
2653 processed
= HandleDropFiles(wParam
);
2658 processed
= HandleInitDialog((WXHWND
)(HWND
)wParam
);
2662 // we never set focus from here
2667 #if !defined(__WXWINCE__)
2668 case WM_QUERYENDSESSION
:
2669 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
2673 processed
= HandleEndSession(wParam
!= 0, lParam
);
2676 case WM_GETMINMAXINFO
:
2677 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
2682 processed
= HandleSetCursor((WXHWND
)(HWND
)wParam
,
2683 LOWORD(lParam
), // hit test
2684 HIWORD(lParam
)); // mouse msg
2688 // returning TRUE stops the DefWindowProc() from further
2689 // processing this message - exactly what we need because we've
2690 // just set the cursor.
2695 #if wxUSE_ACCESSIBILITY
2698 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
2699 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
2701 if (dwObjId
== OBJID_CLIENT
&& GetOrCreateAccessible())
2703 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
2709 #if defined(WM_HELP)
2712 // HELPINFO doesn't seem to be supported on WinCE.
2714 HELPINFO
* info
= (HELPINFO
*) lParam
;
2715 // Don't yet process menu help events, just windows
2716 if (info
->iContextType
== HELPINFO_WINDOW
)
2719 wxWindowMSW
* subjectOfHelp
= this;
2720 bool eventProcessed
= FALSE
;
2721 while (subjectOfHelp
&& !eventProcessed
)
2723 wxHelpEvent
helpEvent(wxEVT_HELP
,
2724 subjectOfHelp
->GetId(),
2728 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
2732 helpEvent
.SetEventObject(this);
2734 GetEventHandler()->ProcessEvent(helpEvent
);
2736 // Go up the window hierarchy until the event is
2738 subjectOfHelp
= subjectOfHelp
->GetParent();
2741 processed
= eventProcessed
;
2744 else if (info
->iContextType
== HELPINFO_MENUITEM
)
2746 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
2747 helpEvent
.SetEventObject(this);
2748 processed
= GetEventHandler()->ProcessEvent(helpEvent
);
2751 //else: processed is already FALSE
2757 #if !defined(__WXWINCE__)
2758 case WM_CONTEXTMENU
:
2760 // we don't convert from screen to client coordinates as
2761 // the event may be handled by a parent window
2762 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2764 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2765 processed
= GetEventHandler()->ProcessEvent(evtCtx
);
2771 // we're only interested in our own menus, not MF_SYSMENU
2772 if ( HIWORD(wParam
) == MF_POPUP
)
2774 // handle menu chars for ownerdrawn menu items
2775 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
2776 if ( i
!= wxNOT_FOUND
)
2778 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
2788 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
2789 wxGetMessageName(message
));
2790 #endif // __WXDEBUG__
2791 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
2797 // ----------------------------------------------------------------------------
2798 // wxWindow <-> HWND map
2799 // ----------------------------------------------------------------------------
2801 wxWinHashTable
*wxWinHandleHash
= NULL
;
2803 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
2805 return wxWinHandleHash
->Get((long)hWnd
);
2808 void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
)
2810 // adding NULL hWnd is (first) surely a result of an error and
2811 // (secondly) breaks menu command processing
2812 wxCHECK_RET( hWnd
!= (HWND
)NULL
,
2813 wxT("attempt to add a NULL hWnd to window list ignored") );
2815 wxWindow
*oldWin
= wxFindWinFromHandle((WXHWND
) hWnd
);
2817 if ( oldWin
&& (oldWin
!= win
) )
2819 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
2820 (int) hWnd
, win
->GetClassInfo()->GetClassName());
2823 #endif // __WXDEBUG__
2826 wxWinHandleHash
->Put((long)hWnd
, (wxWindow
*)win
);
2830 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
2832 wxWinHandleHash
->Delete((long)win
->GetHWND());
2835 // ----------------------------------------------------------------------------
2836 // various MSW speciic class dependent functions
2837 // ----------------------------------------------------------------------------
2839 // Default destroyer - override if you destroy it in some other way
2840 // (e.g. with MDI child windows)
2841 void wxWindowMSW::MSWDestroyWindow()
2845 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
2848 int& w
, int& h
) const
2850 static const int DEFAULT_Y
= 200;
2851 static const int DEFAULT_H
= 250;
2853 bool nonDefault
= FALSE
;
2857 // if set x to CW_USEDEFAULT, y parameter is ignored anyhow so we can
2858 // just as well set it to CW_USEDEFAULT as well
2864 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
2865 // neither because it is not handled as a special value by Windows then
2866 // and so we have to choose some default value for it
2868 y
= pos
.y
== -1 ? DEFAULT_Y
: pos
.y
;
2874 NB: there used to be some code here which set the initial size of the
2875 window to the client size of the parent if no explicit size was
2876 specified. This was wrong because wxWindows programs often assume
2877 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
2878 it. To see why, you should understand that Windows sends WM_SIZE from
2879 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
2880 from some base class ctor and so this WM_SIZE is not processed in the
2881 real class' OnSize() (because it's not fully constructed yet and the
2882 event goes to some base class OnSize() instead). So the WM_SIZE we
2883 rely on is the one sent when the parent frame resizes its children
2884 but here is the problem: if the child already has just the right
2885 size, nothing will happen as both wxWindows and Windows check for
2886 this and ignore any attempts to change the window size to the size it
2887 already has - so no WM_SIZE would be sent.
2891 // as above, h is not used at all in this case anyhow
2897 // and, again as above, we can't set the height to CW_USEDEFAULT here
2899 h
= size
.y
== -1 ? DEFAULT_H
: size
.y
;
2907 WXHWND
wxWindowMSW::MSWGetParent() const
2909 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
2912 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
2913 const wxChar
*title
,
2917 WXDWORD extendedStyle
)
2919 // choose the position/size for the new window
2921 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
2923 // controlId is menu handle for the top level windows, so set it to 0
2924 // unless we're creating a child window
2925 int controlId
= style
& WS_CHILD
? GetId() : 0;
2927 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
2928 // which is the same but without CS_[HV]REDRAW class styles so using it
2929 // ensures that the window is not fully repainted on each resize
2930 wxString
className(wclass
);
2931 if ( GetWindowStyleFlag() & wxNO_FULL_REPAINT_ON_RESIZE
)
2933 className
+= wxT("NR");
2936 // do create the window
2937 wxWindowCreationHook
hook(this);
2940 if (extendedStyle
== 0)
2942 m_hWnd
= (WXHWND
)::CreateWindow
2945 title
? title
: wxEmptyString
,
2948 (HWND
)MSWGetParent(),
2951 NULL
// no extra data
2957 m_hWnd
= (WXHWND
)::CreateWindowEx
2961 title
? title
: wxEmptyString
,
2964 (HWND
)MSWGetParent(),
2967 NULL
// no extra data
2973 wxLogSysError(_("Can't create window of class %s"), wclass
);
2978 SubclassWin(m_hWnd
);
2980 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
2985 // ===========================================================================
2986 // MSW message handlers
2987 // ===========================================================================
2989 // ---------------------------------------------------------------------------
2991 // ---------------------------------------------------------------------------
2995 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
2997 #ifndef __WXMICROWIN__
2998 LPNMHDR hdr
= (LPNMHDR
)lParam
;
2999 HWND hWnd
= hdr
->hwndFrom
;
3000 wxWindow
*win
= wxFindWinFromHandle((WXHWND
)hWnd
);
3002 // if the control is one of our windows, let it handle the message itself
3005 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3008 // VZ: why did we do it? normally this is unnecessary and, besides, it
3009 // breaks the message processing for the toolbars because the tooltip
3010 // notifications were being forwarded to the toolbar child controls
3011 // (if it had any) before being passed to the toolbar itself, so in my
3012 // example the tooltip for the combobox was always shown instead of the
3013 // correct button tooltips
3015 // try all our children
3016 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3019 wxWindow
*child
= node
->GetData();
3020 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3025 node
= node
->GetNext();
3029 // by default, handle it ourselves
3030 return MSWOnNotify(idCtrl
, lParam
, result
);
3031 #else // __WXMICROWIN__
3038 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3040 const wxString
& ttip
)
3042 // I don't know why it happens, but the versions of comctl32.dll starting
3043 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3044 // this message is supposed to be sent to Unicode programs only) -- hence
3045 // we need to handle it as well, otherwise no tooltips will be shown in
3048 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
) || ttip
.empty() )
3050 // not a tooltip message or no tooltip to show anyhow
3055 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3058 if ( code
== (WXUINT
) TTN_NEEDTEXTA
)
3060 // we pass just the pointer as we store the string internally anyhow
3061 ttText
->lpszText
= (char *)ttip
.c_str();
3063 else // TTN_NEEDTEXTW
3067 // in Unicode mode this is just what we need
3068 ttText
->lpszText
= (wxChar
*)ttip
.c_str();
3070 MultiByteToWideChar(CP_ACP
, 0, ttip
, ttip
.length()+1,
3071 (wchar_t *)ttText
->szText
,
3072 sizeof(ttText
->szText
) / sizeof(wchar_t));
3073 #endif // Unicode/!Unicode
3079 #endif // wxUSE_TOOLTIPS
3081 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3083 WXLPARAM
* WXUNUSED(result
))
3088 NMHDR
* hdr
= (NMHDR
*)lParam
;
3089 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3095 #endif // wxUSE_TOOLTIPS
3102 // ---------------------------------------------------------------------------
3103 // end session messages
3104 // ---------------------------------------------------------------------------
3106 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3109 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, -1);
3110 event
.SetEventObject(wxTheApp
);
3111 event
.SetCanVeto(TRUE
);
3112 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3114 bool rc
= wxTheApp
->ProcessEvent(event
);
3118 // we may end only if the app didn't veto session closing (double
3120 *mayEnd
= !event
.GetVeto();
3129 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3132 // do nothing if the session isn't ending
3137 if ( (this != wxTheApp
->GetTopWindow()) )
3140 wxCloseEvent
event(wxEVT_END_SESSION
, -1);
3141 event
.SetEventObject(wxTheApp
);
3142 event
.SetCanVeto(FALSE
);
3143 event
.SetLoggingOff( (logOff
== (long)ENDSESSION_LOGOFF
) );
3145 return wxTheApp
->ProcessEvent(event
);
3151 // ---------------------------------------------------------------------------
3152 // window creation/destruction
3153 // ---------------------------------------------------------------------------
3155 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
)
3157 // if we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
3158 // parent as well as otherwise several Win32 functions using
3159 // GetNextDlgTabItem() to iterate over all controls such as
3160 // IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
3161 // all of them iterate over all the controls starting from the focus and
3162 // stop iterating when they get back to the focus but unless all parents
3163 // have WS_EX_CONTROLPARENT bit set, they would never get back to focus
3165 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3167 // there is no need to do anything for the top level windows
3168 const wxWindow
*parent
= GetParent();
3169 while ( parent
&& !parent
->IsTopLevel() )
3171 LONG exStyle
= ::GetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
);
3172 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
3174 // force the parent to have this style
3175 ::SetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
,
3176 exStyle
| WS_EX_CONTROLPARENT
);
3179 parent
= parent
->GetParent();
3184 // TODO: should generate this event from WM_NCCREATE
3185 wxWindowCreateEvent
event((wxWindow
*)this);
3186 (void)GetEventHandler()->ProcessEvent(event
);
3193 bool wxWindowMSW::HandleDestroy()
3197 // delete our drop target if we've got one
3198 #if wxUSE_DRAG_AND_DROP
3199 if ( m_dropTarget
!= NULL
)
3201 m_dropTarget
->Revoke(m_hWnd
);
3203 delete m_dropTarget
;
3204 m_dropTarget
= NULL
;
3206 #endif // wxUSE_DRAG_AND_DROP
3208 // WM_DESTROY handled
3212 // ---------------------------------------------------------------------------
3214 // ---------------------------------------------------------------------------
3216 bool wxWindowMSW::HandleActivate(int state
,
3217 bool WXUNUSED(minimized
),
3218 WXHWND
WXUNUSED(activate
))
3220 wxActivateEvent
event(wxEVT_ACTIVATE
,
3221 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3223 event
.SetEventObject(this);
3225 return GetEventHandler()->ProcessEvent(event
);
3228 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3230 // notify the parent keeping track of focus for the kbd navigation
3231 // purposes that we got it
3232 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3233 (void)GetEventHandler()->ProcessEvent(eventFocus
);
3239 m_caret
->OnSetFocus();
3241 #endif // wxUSE_CARET
3244 // If it's a wxTextCtrl don't send the event as it will be done
3245 // after the control gets to process it from EN_FOCUS handler
3246 if ( wxDynamicCastThis(wxTextCtrl
) )
3250 #endif // wxUSE_TEXTCTRL
3252 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3253 event
.SetEventObject(this);
3255 // wxFindWinFromHandle() may return NULL, it is ok
3256 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3258 return GetEventHandler()->ProcessEvent(event
);
3261 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
3267 m_caret
->OnKillFocus();
3269 #endif // wxUSE_CARET
3272 // If it's a wxTextCtrl don't send the event as it will be done
3273 // after the control gets to process it.
3274 wxTextCtrl
*ctrl
= wxDynamicCastThis(wxTextCtrl
);
3281 // Don't send the event when in the process of being deleted. This can
3282 // only cause problems if the event handler tries to access the object.
3283 if ( m_isBeingDeleted
)
3288 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3289 event
.SetEventObject(this);
3291 // wxFindWinFromHandle() may return NULL, it is ok
3292 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3294 return GetEventHandler()->ProcessEvent(event
);
3297 // ---------------------------------------------------------------------------
3299 // ---------------------------------------------------------------------------
3301 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
3303 wxShowEvent
event(GetId(), show
);
3304 event
.m_eventObject
= this;
3306 return GetEventHandler()->ProcessEvent(event
);
3309 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
3311 wxInitDialogEvent
event(GetId());
3312 event
.m_eventObject
= this;
3314 return GetEventHandler()->ProcessEvent(event
);
3317 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
3319 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
3321 #else // __WXMICROWIN__
3322 HDROP hFilesInfo
= (HDROP
) wParam
;
3324 // Get the total number of files dropped
3325 UINT gwFilesDropped
= ::DragQueryFile
3333 wxString
*files
= new wxString
[gwFilesDropped
];
3334 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
3336 // first get the needed buffer length (+1 for terminating NUL)
3337 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
3339 // and now get the file name
3340 ::DragQueryFile(hFilesInfo
, wIndex
,
3341 wxStringBuffer(files
[wIndex
], len
), len
);
3343 DragFinish (hFilesInfo
);
3345 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
3346 event
.m_eventObject
= this;
3349 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
3350 event
.m_pos
.x
= dropPoint
.x
;
3351 event
.m_pos
.y
= dropPoint
.y
;
3353 return GetEventHandler()->ProcessEvent(event
);
3358 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
3360 int WXUNUSED(mouseMsg
))
3362 #ifndef __WXMICROWIN__
3363 // the logic is as follows:
3364 // -1. don't set cursor for non client area, including but not limited to
3365 // the title bar, scrollbars, &c
3366 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
3367 // 1. if we have the cursor set it unless wxIsBusy()
3368 // 2. if we're a top level window, set some cursor anyhow
3369 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
3371 if ( nHitTest
!= HTCLIENT
)
3376 HCURSOR hcursor
= 0;
3378 // first ask the user code - it may wish to set the cursor in some very
3379 // specific way (for example, depending on the current position)
3381 if ( !::GetCursorPos(&pt
) )
3383 wxLogLastError(wxT("GetCursorPos"));
3388 ScreenToClient(&x
, &y
);
3389 wxSetCursorEvent
event(x
, y
);
3391 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
3392 if ( processedEvtSetCursor
&& event
.HasCursor() )
3394 hcursor
= GetHcursorOf(event
.GetCursor());
3399 bool isBusy
= wxIsBusy();
3401 // the test for processedEvtSetCursor is here to prevent using m_cursor
3402 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3403 // it - this is a way to say that our cursor shouldn't be used for this
3405 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
3407 hcursor
= GetHcursorOf(m_cursor
);
3414 hcursor
= wxGetCurrentBusyCursor();
3416 else if ( !hcursor
)
3418 const wxCursor
*cursor
= wxGetGlobalCursor();
3419 if ( cursor
&& cursor
->Ok() )
3421 hcursor
= GetHcursorOf(*cursor
);
3429 // wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3431 ::SetCursor(hcursor
);
3433 // cursor set, stop here
3436 #endif // __WXMICROWIN__
3438 // pass up the window chain
3442 // ---------------------------------------------------------------------------
3443 // owner drawn stuff
3444 // ---------------------------------------------------------------------------
3446 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
3447 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
3448 #define WXUNUSED_UNLESS_ODRAWN(param) param
3450 #define WXUNUSED_UNLESS_ODRAWN(param)
3454 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
3455 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
3457 #if wxUSE_OWNER_DRAWN
3459 #if wxUSE_MENUS_NATIVE
3460 // is it a menu item?
3461 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
3462 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
3464 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
3466 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
3468 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
3469 // the DC from being released
3470 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
3471 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
3472 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
3473 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
3475 return pMenuItem
->OnDrawItem
3479 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
3480 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
3483 #endif // wxUSE_MENUS_NATIVE
3485 #endif // USE_OWNER_DRAWN
3487 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
3489 #if wxUSE_OWNER_DRAWN
3490 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3491 #else // !wxUSE_OWNER_DRAWN
3492 // we may still have owner-drawn buttons internally because we have to make
3493 // them owner-drawn to support colour change
3494 wxControl
*item
= wxDynamicCast(FindItem(id
), wxButton
);
3495 #endif // USE_OWNER_DRAWN
3499 return item
->MSWOnDraw(itemStruct
);
3502 #endif // wxUSE_CONTROLS
3508 wxWindowMSW::MSWOnMeasureItem(int WXUNUSED_UNLESS_ODRAWN(id
),
3509 WXMEASUREITEMSTRUCT
*
3510 WXUNUSED_UNLESS_ODRAWN(itemStruct
))
3512 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
3513 // is it a menu item?
3514 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
3515 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
3517 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
3519 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
3521 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
3522 &pMeasureStruct
->itemHeight
);
3525 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3528 return item
->MSWOnMeasure(itemStruct
);
3530 #endif // wxUSE_OWNER_DRAWN
3535 // ---------------------------------------------------------------------------
3536 // colours and palettes
3537 // ---------------------------------------------------------------------------
3539 bool wxWindowMSW::HandleSysColorChange()
3541 wxSysColourChangedEvent event
;
3542 event
.SetEventObject(this);
3544 (void)GetEventHandler()->ProcessEvent(event
);
3546 // always let the system carry on the default processing to allow the
3547 // native controls to react to the colours update
3551 bool wxWindowMSW::HandleDisplayChange()
3553 wxDisplayChangedEvent event
;
3554 event
.SetEventObject(this);
3556 return GetEventHandler()->ProcessEvent(event
);
3559 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
,
3567 #ifndef __WXMICROWIN__
3568 WXHBRUSH hBrush
= 0;
3573 if ( nCtlColor
== CTLCOLOR_DLG
)
3576 hBrush
= OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
3581 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
3583 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
3585 #endif // wxUSE_CONTROLS
3591 #else // __WXMICROWIN__
3596 // Define for each class of dialog and control
3597 WXHBRUSH
wxWindowMSW::OnCtlColor(WXHDC
WXUNUSED(hDC
),
3598 WXHWND
WXUNUSED(hWnd
),
3599 WXUINT
WXUNUSED(nCtlColor
),
3600 WXUINT
WXUNUSED(message
),
3601 WXWPARAM
WXUNUSED(wParam
),
3602 WXLPARAM
WXUNUSED(lParam
))
3607 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
3610 // same as below except we don't respond to our own messages
3611 if ( hWndPalChange
!= GetHWND() )
3613 // check to see if we our our parents have a custom palette
3614 wxWindowMSW
*win
= this;
3615 while ( win
&& !win
->HasCustomPalette() )
3617 win
= win
->GetParent();
3620 if ( win
&& win
->HasCustomPalette() )
3622 // realize the palette to see whether redrawing is needed
3623 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
3624 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
3625 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
3627 int result
= ::RealizePalette(hdc
);
3629 // restore the palette (before releasing the DC)
3630 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
3631 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
3632 ::RealizePalette(hdc
);
3633 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
3635 // now check for the need to redraw
3637 InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
3641 #endif // wxUSE_PALETTE
3643 wxPaletteChangedEvent
event(GetId());
3644 event
.SetEventObject(this);
3645 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
3647 return GetEventHandler()->ProcessEvent(event
);
3650 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
3652 wxMouseCaptureChangedEvent
event(GetId(), wxFindWinFromHandle(hWndGainedCapture
));
3653 event
.SetEventObject(this);
3655 return GetEventHandler()->ProcessEvent(event
);
3658 bool wxWindowMSW::HandleQueryNewPalette()
3662 // check to see if we our our parents have a custom palette
3663 wxWindowMSW
*win
= this;
3664 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
3665 if (win
->HasCustomPalette()) {
3666 /* realize the palette to see whether redrawing is needed */
3667 HDC hdc
= GetDC((HWND
) GetHWND());
3668 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
3669 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
3671 int result
= ::RealizePalette(hdc
);
3672 /* restore the palette (before releasing the DC) */
3673 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
3674 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
3675 ::RealizePalette(hdc
);
3676 ::ReleaseDC((HWND
) GetHWND(), hdc
);
3677 /* now check for the need to redraw */
3679 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
3681 #endif // wxUSE_PALETTE
3683 wxQueryNewPaletteEvent
event(GetId());
3684 event
.SetEventObject(this);
3686 return GetEventHandler()->ProcessEvent(event
) && event
.GetPaletteRealized();
3689 // Responds to colour changes: passes event on to children.
3690 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
3692 // the top level window also reset the standard colour map as it might have
3693 // changed (there is no need to do it for the non top level windows as we
3694 // only have to do it once)
3698 gs_hasStdCmap
= FALSE
;
3700 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3703 // Only propagate to non-top-level windows because Windows already
3704 // sends this event to all top-level ones
3705 wxWindow
*win
= node
->GetData();
3706 if ( !win
->IsTopLevel() )
3708 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
3709 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
3710 // the standard controls
3711 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
3714 node
= node
->GetNext();
3717 // update the colours we use if they were not set explicitly by the user:
3718 // this must be done or OnCtlColor() would continue to use the old colours
3721 m_foregroundColour
= wxSystemSettings::
3722 GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
);
3727 m_backgroundColour
= wxSystemSettings::
3728 GetSystemColour(wxSYS_COLOUR_BTNFACE
);
3732 extern wxCOLORMAP
*wxGetStdColourMap()
3734 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
3735 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
3737 if ( !gs_hasStdCmap
)
3739 static bool s_coloursInit
= FALSE
;
3741 if ( !s_coloursInit
)
3743 // When a bitmap is loaded, the RGB values can change (apparently
3744 // because Windows adjusts them to care for the old programs always
3745 // using 0xc0c0c0 while the transparent colour for the new Windows
3746 // versions is different). But we do this adjustment ourselves so
3747 // we want to avoid Windows' "help" and for this we need to have a
3748 // reference bitmap which can tell us what the RGB values change
3750 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
3751 if ( stdColourBitmap
.Ok() )
3753 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
3754 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
3755 _T("forgot to update wxBITMAP_STD_COLOURS!") );
3758 memDC
.SelectObject(stdColourBitmap
);
3761 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
3763 memDC
.GetPixel(i
, 0, &colour
);
3764 s_stdColours
[i
] = wxColourToRGB(colour
);
3767 else // wxBITMAP_STD_COLOURS couldn't be loaded
3769 s_stdColours
[0] = RGB(000,000,000); // black
3770 s_stdColours
[1] = RGB(128,128,128); // dark grey
3771 s_stdColours
[2] = RGB(192,192,192); // light grey
3772 s_stdColours
[3] = RGB(255,255,255); // white
3773 //s_stdColours[4] = RGB(000,000,255); // blue
3774 //s_stdColours[5] = RGB(255,000,255); // magenta
3777 s_coloursInit
= TRUE
;
3780 gs_hasStdCmap
= TRUE
;
3782 // create the colour map
3783 #define INIT_CMAP_ENTRY(col) \
3784 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
3785 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
3787 INIT_CMAP_ENTRY(BTNTEXT
);
3788 INIT_CMAP_ENTRY(BTNSHADOW
);
3789 INIT_CMAP_ENTRY(BTNFACE
);
3790 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
3792 #undef INIT_CMAP_ENTRY
3798 // ---------------------------------------------------------------------------
3800 // ---------------------------------------------------------------------------
3802 bool wxWindowMSW::HandlePaint()
3804 // if (GetExtraStyle() & wxWS_EX_THEMED_BACKGROUND)
3807 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
3809 wxLogLastError(wxT("CreateRectRgn"));
3810 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
3811 wxLogLastError(wxT("GetUpdateRgn"));
3813 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
3815 wxPaintEvent
event(m_windowId
);
3816 event
.SetEventObject(this);
3818 bool processed
= GetEventHandler()->ProcessEvent(event
);
3820 // note that we must generate NC event after the normal one as otherwise
3821 // BeginPaint() will happily overwrite our decorations with the background
3823 wxNcPaintEvent
eventNc(m_windowId
);
3824 eventNc
.SetEventObject(this);
3825 GetEventHandler()->ProcessEvent(eventNc
);
3830 // Can be called from an application's OnPaint handler
3831 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
3833 #ifdef __WXUNIVERSAL__
3836 HDC hDC
= (HDC
) wxPaintDC::FindDCInCache((wxWindow
*) event
.GetEventObject());
3839 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
3844 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
3846 // Prevents flicker when dragging
3847 if ( ::IsIconic(GetHwnd()) )
3851 if (GetParent() && GetParent()->GetExtraStyle() & wxWS_EX_THEMED_BACKGROUND
)
3856 if (GetExtraStyle() & wxWS_EX_THEMED_BACKGROUND
)
3858 if (wxUxThemeEngine::Get())
3860 WXHTHEME hTheme
= wxUxThemeEngine::Get()->m_pfnOpenThemeData(GetHWND(), L
"TAB");
3864 ::GetClientRect((HWND
) GetHWND(), (RECT
*) & rect
);
3865 wxUxThemeEngine::Get()->m_pfnDrawThemeBackground(hTheme
, hdc
, 10 /* TABP_BODY */, 0, &rect
, &rect
);
3866 wxUxThemeEngine::Get()->m_pfnCloseThemeData(hTheme
);
3876 dc
.SetWindow((wxWindow
*)this);
3879 wxEraseEvent
event(m_windowId
, &dc
);
3880 event
.SetEventObject(this);
3881 bool rc
= GetEventHandler()->ProcessEvent(event
);
3885 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
3886 dc
.SelectOldObjects(hdc
);
3891 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
3894 ::GetClientRect(GetHwnd(), &rect
);
3896 COLORREF ref
= PALETTERGB(m_backgroundColour
.Red(),
3897 m_backgroundColour
.Green(),
3898 m_backgroundColour
.Blue());
3899 HBRUSH hBrush
= ::CreateSolidBrush(ref
);
3901 wxLogLastError(wxT("CreateSolidBrush"));
3903 HDC hdc
= (HDC
)event
.GetDC()->GetHDC();
3906 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
3909 ::FillRect(hdc
, &rect
, hBrush
);
3910 ::DeleteObject(hBrush
);
3913 ::SetMapMode(hdc
, mode
);
3917 // ---------------------------------------------------------------------------
3918 // moving and resizing
3919 // ---------------------------------------------------------------------------
3921 bool wxWindowMSW::HandleMinimize()
3923 wxIconizeEvent
event(m_windowId
);
3924 event
.SetEventObject(this);
3926 return GetEventHandler()->ProcessEvent(event
);
3929 bool wxWindowMSW::HandleMaximize()
3931 wxMaximizeEvent
event(m_windowId
);
3932 event
.SetEventObject(this);
3934 return GetEventHandler()->ProcessEvent(event
);
3937 bool wxWindowMSW::HandleMove(int x
, int y
)
3939 wxMoveEvent
event(wxPoint(x
, y
), m_windowId
);
3940 event
.SetEventObject(this);
3942 return GetEventHandler()->ProcessEvent(event
);
3945 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
3947 wxMoveEvent
event(rect
, m_windowId
);
3948 event
.SetEventObject(this);
3950 bool rc
= GetEventHandler()->ProcessEvent(event
);
3952 rect
= event
.GetRect();
3956 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
),
3957 WXUINT
WXUNUSED(flag
))
3959 // don't use w and h parameters as they specify the client size while
3960 // according to the docs EVT_SIZE handler is supposed to receive the total
3962 wxSizeEvent
event(GetSize(), m_windowId
);
3963 event
.SetEventObject(this);
3965 return GetEventHandler()->ProcessEvent(event
);
3968 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
3970 wxSizeEvent
event(rect
, m_windowId
);
3971 event
.SetEventObject(this);
3973 bool rc
= GetEventHandler()->ProcessEvent(event
);
3975 rect
= event
.GetRect();
3979 bool wxWindowMSW::HandleGetMinMaxInfo(void *mmInfo
)
3984 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
3988 int minWidth
= GetMinWidth(),
3989 minHeight
= GetMinHeight(),
3990 maxWidth
= GetMaxWidth(),
3991 maxHeight
= GetMaxHeight();
3993 if ( minWidth
!= -1 )
3995 info
->ptMinTrackSize
.x
= minWidth
;
3999 if ( minHeight
!= -1 )
4001 info
->ptMinTrackSize
.y
= minHeight
;
4005 if ( maxWidth
!= -1 )
4007 info
->ptMaxTrackSize
.x
= maxWidth
;
4011 if ( maxHeight
!= -1 )
4013 info
->ptMaxTrackSize
.y
= maxHeight
;
4021 // ---------------------------------------------------------------------------
4023 // ---------------------------------------------------------------------------
4025 bool wxWindowMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
4027 #if wxUSE_MENUS_NATIVE
4028 if ( !cmd
&& wxCurrentPopupMenu
)
4030 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
4031 wxCurrentPopupMenu
= NULL
;
4033 return popupMenu
->MSWCommand(cmd
, id
);
4035 #endif // wxUSE_MENUS_NATIVE
4037 wxWindow
*win
= NULL
;
4039 // first try to find it from HWND - this works even with the broken
4040 // programs using the same ids for different controls
4043 win
= wxFindWinFromHandle(control
);
4049 // must cast to a signed type before comparing with other ids!
4050 win
= FindItem((signed short)id
);
4055 return win
->MSWCommand(cmd
, id
);
4058 // the messages sent from the in-place edit control used by the treectrl
4059 // for label editing have id == 0, but they should _not_ be treated as menu
4060 // messages (they are EN_XXX ones, in fact) so don't translate anything
4061 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4064 // If no child window, it may be an accelerator, e.g. for a popup menu
4067 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
4068 event
.SetEventObject(this);
4072 return GetEventHandler()->ProcessEvent(event
);
4074 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4077 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4078 // notifications to its parent which we want to reflect back to
4080 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
4081 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
4084 #endif // wxUSE_SPINCTRL
4089 bool wxWindowMSW::HandleSysCommand(WXWPARAM wParam
, WXLPARAM
WXUNUSED(lParam
))
4092 // 4 bits are reserved
4093 switch ( wParam
& 0xFFFFFFF0 )
4096 return HandleMaximize();
4099 return HandleMinimize();
4106 // ---------------------------------------------------------------------------
4108 // ---------------------------------------------------------------------------
4110 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
4114 // our client coords are not quite the same as Windows ones
4115 wxPoint pt
= GetClientAreaOrigin();
4116 event
.m_x
= x
- pt
.x
;
4117 event
.m_y
= y
- pt
.y
;
4119 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
4120 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
4121 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
4122 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
4123 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
4124 // event.m_altDown = (::GetKeyState(VK_MENU) & 0x80000000) != 0;
4125 // Returns different negative values on WinME and WinNT,
4126 // so simply test for negative value.
4127 event
.m_altDown
= ::GetKeyState(VK_MENU
) < 0;
4129 event
.SetTimestamp(s_currentMsg
.time
);
4130 event
.m_eventObject
= this;
4131 event
.SetId(GetId());
4133 #if wxUSE_MOUSEEVENT_HACK
4136 m_lastMouseEvent
= event
.GetEventType();
4137 #endif // wxUSE_MOUSEEVENT_HACK
4140 // Windows doesn't send the mouse events to the static controls (which are
4141 // transparent in the sense that their WM_NCHITTEST handler returns
4142 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4143 // and so we manually check if we don't have a child window under mouse and if
4144 // we do, send the event to it instead of the window Windows had sent WM_XXX
4147 // Notice that this is not done for the mouse move events because this could
4148 // (would?) be too slow, but only for clicks which means that the static texts
4149 // still don't get move, enter nor leave events.
4150 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
) //TW:REQ:Univ
4152 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
4154 // first try to find a non transparent child: this allows us to send events
4155 // to a static text which is inside a static box, for example
4156 POINT pt
= { *x
, *y
};
4157 HWND hwnd
= GetHwndOf(win
),
4161 hwndUnderMouse
= ::ChildWindowFromPoint
4167 hwndUnderMouse
= ::ChildWindowFromPointEx
4177 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
4179 // now try any child window at all
4180 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
4183 // check that we have a child window which is susceptible to receive mouse
4184 // events: for this it must be shown and enabled
4185 if ( hwndUnderMouse
&&
4186 hwndUnderMouse
!= hwnd
&&
4187 ::IsWindowVisible(hwndUnderMouse
) &&
4188 ::IsWindowEnabled(hwndUnderMouse
) )
4190 wxWindow
*winUnderMouse
= wxFindWinFromHandle((WXHWND
)hwndUnderMouse
);
4191 if ( winUnderMouse
)
4193 // translate the mouse coords to the other window coords
4194 win
->ClientToScreen(x
, y
);
4195 winUnderMouse
->ScreenToClient(x
, y
);
4197 win
= winUnderMouse
;
4204 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4206 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4207 // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST
4208 // from the message id and take the value in the table to get wxWin event
4210 static const wxEventType eventsMouse
[] =
4224 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
4225 InitMouseEvent(event
, x
, y
, flags
);
4227 return GetEventHandler()->ProcessEvent(event
);
4230 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
4232 if ( !m_mouseInWindow
)
4234 // it would be wrong to assume that just because we get a mouse move
4235 // event that the mouse is inside the window: although this is usually
4236 // true, it is not if we had captured the mouse, so we need to check
4237 // the mouse coordinates here
4238 if ( !HasCapture() || IsMouseInWindow() )
4240 // Generate an ENTER event
4241 m_mouseInWindow
= TRUE
;
4243 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
4244 InitMouseEvent(event
, x
, y
, flags
);
4246 (void)GetEventHandler()->ProcessEvent(event
);
4250 #if wxUSE_MOUSEEVENT_HACK
4251 // Window gets a click down message followed by a mouse move message even
4252 // if position isn't changed! We want to discard the trailing move event
4253 // if x and y are the same.
4254 if ( (m_lastMouseEvent
== wxEVT_RIGHT_DOWN
||
4255 m_lastMouseEvent
== wxEVT_LEFT_DOWN
||
4256 m_lastMouseEvent
== wxEVT_MIDDLE_DOWN
) &&
4257 (m_lastMouseX
== x
&& m_lastMouseY
== y
) )
4259 m_lastMouseEvent
= wxEVT_MOTION
;
4263 #endif // wxUSE_MOUSEEVENT_HACK
4265 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
4269 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
4271 #if wxUSE_MOUSEWHEEL
4272 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
4273 InitMouseEvent(event
,
4274 GET_X_LPARAM(lParam
),
4275 GET_Y_LPARAM(lParam
),
4277 event
.m_wheelRotation
= (short)HIWORD(wParam
);
4278 event
.m_wheelDelta
= WHEEL_DELTA
;
4280 static int s_linesPerRotation
= -1;
4281 if ( s_linesPerRotation
== -1 )
4283 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
4284 &s_linesPerRotation
, 0))
4286 // this is not supposed to happen
4287 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
4289 // the default is 3, so use it if SystemParametersInfo() failed
4290 s_linesPerRotation
= 3;
4294 event
.m_linesPerAction
= s_linesPerRotation
;
4295 return GetEventHandler()->ProcessEvent(event
);
4306 // ---------------------------------------------------------------------------
4307 // keyboard handling
4308 // ---------------------------------------------------------------------------
4310 // create the key event of the given type for the given key - used by
4311 // HandleChar and HandleKeyDown/Up
4312 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
4315 WXWPARAM wParam
) const
4317 wxKeyEvent
event(evType
);
4318 event
.SetId(GetId());
4319 event
.m_shiftDown
= wxIsShiftDown();
4320 event
.m_controlDown
= wxIsCtrlDown();
4321 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
4323 event
.m_eventObject
= (wxWindow
*)this; // const_cast
4324 event
.m_keyCode
= id
;
4325 event
.m_rawCode
= (wxUint32
) wParam
;
4326 event
.m_rawFlags
= (wxUint32
) lParam
;
4327 event
.SetTimestamp(s_currentMsg
.time
);
4329 // translate the position to client coords
4333 GetWindowRect(GetHwnd(),&rect
);
4343 // isASCII is TRUE only when we're called from WM_CHAR handler and not from
4345 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
4350 // If 1 -> 26, translate to either special keycode or just set
4351 // ctrlDown. IOW, Ctrl-C should result in keycode == 3 and
4352 // ControlDown() == TRUE.
4354 if ( (id
> 0) && (id
< 27) )
4376 else // we're called from WM_KEYDOWN
4378 id
= wxCharCodeMSWToWX(wParam
);
4381 // it's ASCII and will be processed here only when called from
4382 // WM_CHAR (i.e. when isASCII = TRUE), don't process it now
4387 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
4389 // the alphanumeric keys produced by pressing AltGr+something on European
4390 // keyboards have both Ctrl and Alt modifiers which may confuse the user
4391 // code as, normally, keys with Ctrl and/or Alt don't result in anything
4392 // alphanumeric, so pretend that there are no modifiers at all (the
4393 // KEY_DOWN event would still have the correct modifiers if they're really
4395 if ( event
.m_controlDown
&& event
.m_altDown
&&
4396 (id
>= 32 && id
< 256) )
4398 event
.m_controlDown
=
4399 event
.m_altDown
= FALSE
;
4402 return GetEventHandler()->ProcessEvent(event
);
4405 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
4407 int id
= wxCharCodeMSWToWX(wParam
);
4411 // normal ASCII char
4415 if ( id
!= -1 ) // VZ: does this ever happen (FIXME)?
4417 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
4418 if ( GetEventHandler()->ProcessEvent(event
) )
4427 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
4429 int id
= wxCharCodeMSWToWX(wParam
);
4433 // normal ASCII char
4437 if ( id
!= -1 ) // VZ: does this ever happen (FIXME)?
4439 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
4440 if ( GetEventHandler()->ProcessEvent(event
) )
4447 int wxWindowMSW::HandleMenuChar(int chAccel
, WXLPARAM lParam
)
4449 // FIXME: implement GetMenuItemCount for WinCE, possibly
4450 // in terms of GetMenuItemInfo
4452 const HMENU hmenu
= (HMENU
)lParam
;
4456 mii
.cbSize
= sizeof(MENUITEMINFO
);
4457 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
4459 // find if we have this letter in any owner drawn item
4460 const int count
= ::GetMenuItemCount(hmenu
);
4461 for ( int i
= 0; i
< count
; i
++ )
4463 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
4465 if ( mii
.fType
== MFT_OWNERDRAW
)
4467 // dwItemData member of the MENUITEMINFO is a
4468 // pointer to the associated wxMenuItem -- see the
4469 // menu creation code
4470 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
4472 const wxChar
*p
= wxStrchr(item
->GetText(), _T('&'));
4475 if ( *p
== _T('&') )
4477 // this is not the accel char, find the real one
4478 p
= wxStrchr(p
+ 1, _T('&'));
4480 else // got the accel char
4482 // FIXME-UNICODE: this comparison doesn't risk to work
4483 // for non ASCII accelerator characters I'm afraid, but
4485 if ( wxToupper(*p
) == chAccel
)
4491 // this one doesn't match
4498 else // failed to get the menu text?
4500 // it's not fatal, so don't show error, but still log
4502 wxLogLastError(_T("GetMenuItemInfo"));
4509 // ---------------------------------------------------------------------------
4511 // ---------------------------------------------------------------------------
4513 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4517 if ( flags
& JOY_BUTTON1CHG
)
4518 change
= wxJOY_BUTTON1
;
4519 if ( flags
& JOY_BUTTON2CHG
)
4520 change
= wxJOY_BUTTON2
;
4521 if ( flags
& JOY_BUTTON3CHG
)
4522 change
= wxJOY_BUTTON3
;
4523 if ( flags
& JOY_BUTTON4CHG
)
4524 change
= wxJOY_BUTTON4
;
4527 if ( flags
& JOY_BUTTON1
)
4528 buttons
|= wxJOY_BUTTON1
;
4529 if ( flags
& JOY_BUTTON2
)
4530 buttons
|= wxJOY_BUTTON2
;
4531 if ( flags
& JOY_BUTTON3
)
4532 buttons
|= wxJOY_BUTTON3
;
4533 if ( flags
& JOY_BUTTON4
)
4534 buttons
|= wxJOY_BUTTON4
;
4536 // the event ids aren't consecutive so we can't use table based lookup
4538 wxEventType eventType
;
4543 eventType
= wxEVT_JOY_MOVE
;
4548 eventType
= wxEVT_JOY_MOVE
;
4553 eventType
= wxEVT_JOY_ZMOVE
;
4558 eventType
= wxEVT_JOY_ZMOVE
;
4561 case MM_JOY1BUTTONDOWN
:
4563 eventType
= wxEVT_JOY_BUTTON_DOWN
;
4566 case MM_JOY2BUTTONDOWN
:
4568 eventType
= wxEVT_JOY_BUTTON_DOWN
;
4571 case MM_JOY1BUTTONUP
:
4573 eventType
= wxEVT_JOY_BUTTON_UP
;
4576 case MM_JOY2BUTTONUP
:
4578 eventType
= wxEVT_JOY_BUTTON_UP
;
4582 wxFAIL_MSG(wxT("no such joystick event"));
4587 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
4588 event
.SetPosition(wxPoint(x
, y
));
4589 event
.SetEventObject(this);
4591 return GetEventHandler()->ProcessEvent(event
);
4597 // ---------------------------------------------------------------------------
4599 // ---------------------------------------------------------------------------
4601 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
4602 WXWORD pos
, WXHWND control
)
4606 wxWindow
*child
= wxFindWinFromHandle(control
);
4608 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
4611 wxScrollWinEvent event
;
4612 event
.SetPosition(pos
);
4613 event
.SetOrientation(orientation
);
4614 event
.m_eventObject
= this;
4619 event
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
4623 event
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
4627 event
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
4631 event
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
4635 event
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
4639 event
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
4642 case SB_THUMBPOSITION
:
4644 // under Win32, the scrollbar range and position are 32 bit integers,
4645 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
4646 // explicitly query the scrollbar for the correct position (this must
4647 // be done only for these two SB_ events as they are the only one
4648 // carrying the scrollbar position)
4650 WinStruct
<SCROLLINFO
> scrollInfo
;
4651 scrollInfo
.fMask
= SIF_TRACKPOS
;
4653 if ( !::GetScrollInfo(GetHwnd(),
4654 orientation
== wxHORIZONTAL
? SB_HORZ
4658 // Not neccessarily an error, if there are no scrollbars yet.
4659 // wxLogLastError(_T("GetScrollInfo"));
4662 event
.SetPosition(scrollInfo
.nTrackPos
);
4665 event
.m_eventType
= wParam
== SB_THUMBPOSITION
4666 ? wxEVT_SCROLLWIN_THUMBRELEASE
4667 : wxEVT_SCROLLWIN_THUMBTRACK
;
4674 return GetEventHandler()->ProcessEvent(event
);
4677 // ===========================================================================
4679 // ===========================================================================
4681 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
*the_font
)
4684 HDC dc
= ::GetDC((HWND
) wnd
);
4689 // the_font->UseResource();
4690 // the_font->RealizeResource();
4691 fnt
= (HFONT
)((wxFont
*)the_font
)->GetResourceHandle(); // const_cast
4693 was
= (HFONT
) SelectObject(dc
,fnt
);
4695 GetTextMetrics(dc
, &tm
);
4696 if ( the_font
&& fnt
&& was
)
4698 SelectObject(dc
,was
);
4700 ReleaseDC((HWND
)wnd
, dc
);
4703 *x
= tm
.tmAveCharWidth
;
4705 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
4708 // the_font->ReleaseResource();
4711 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
4712 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
4713 int wxCharCodeMSWToWX(int keySym
)
4718 case VK_CANCEL
: id
= WXK_CANCEL
; break;
4719 case VK_BACK
: id
= WXK_BACK
; break;
4720 case VK_TAB
: id
= WXK_TAB
; break;
4721 case VK_CLEAR
: id
= WXK_CLEAR
; break;
4722 case VK_RETURN
: id
= WXK_RETURN
; break;
4723 case VK_SHIFT
: id
= WXK_SHIFT
; break;
4724 case VK_CONTROL
: id
= WXK_CONTROL
; break;
4725 case VK_MENU
: id
= WXK_MENU
; break;
4726 case VK_PAUSE
: id
= WXK_PAUSE
; break;
4727 case VK_CAPITAL
: id
= WXK_CAPITAL
; break;
4728 case VK_SPACE
: id
= WXK_SPACE
; break;
4729 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
4730 case VK_PRIOR
: id
= WXK_PRIOR
; break;
4731 case VK_NEXT
: id
= WXK_NEXT
; break;
4732 case VK_END
: id
= WXK_END
; break;
4733 case VK_HOME
: id
= WXK_HOME
; break;
4734 case VK_LEFT
: id
= WXK_LEFT
; break;
4735 case VK_UP
: id
= WXK_UP
; break;
4736 case VK_RIGHT
: id
= WXK_RIGHT
; break;
4737 case VK_DOWN
: id
= WXK_DOWN
; break;
4738 case VK_SELECT
: id
= WXK_SELECT
; break;
4739 case VK_PRINT
: id
= WXK_PRINT
; break;
4740 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
4741 case VK_INSERT
: id
= WXK_INSERT
; break;
4742 case VK_DELETE
: id
= WXK_DELETE
; break;
4743 case VK_HELP
: id
= WXK_HELP
; break;
4744 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
4745 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
4746 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
4747 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
4748 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
4749 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
4750 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
4751 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
4752 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
4753 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
4754 case VK_MULTIPLY
: id
= WXK_NUMPAD_MULTIPLY
; break;
4755 case VK_ADD
: id
= WXK_NUMPAD_ADD
; break;
4756 case VK_SUBTRACT
: id
= WXK_NUMPAD_SUBTRACT
; break;
4757 case VK_DECIMAL
: id
= WXK_NUMPAD_DECIMAL
; break;
4758 case VK_DIVIDE
: id
= WXK_NUMPAD_DIVIDE
; break;
4759 case VK_F1
: id
= WXK_F1
; break;
4760 case VK_F2
: id
= WXK_F2
; break;
4761 case VK_F3
: id
= WXK_F3
; break;
4762 case VK_F4
: id
= WXK_F4
; break;
4763 case VK_F5
: id
= WXK_F5
; break;
4764 case VK_F6
: id
= WXK_F6
; break;
4765 case VK_F7
: id
= WXK_F7
; break;
4766 case VK_F8
: id
= WXK_F8
; break;
4767 case VK_F9
: id
= WXK_F9
; break;
4768 case VK_F10
: id
= WXK_F10
; break;
4769 case VK_F11
: id
= WXK_F11
; break;
4770 case VK_F12
: id
= WXK_F12
; break;
4771 case VK_F13
: id
= WXK_F13
; break;
4772 case VK_F14
: id
= WXK_F14
; break;
4773 case VK_F15
: id
= WXK_F15
; break;
4774 case VK_F16
: id
= WXK_F16
; break;
4775 case VK_F17
: id
= WXK_F17
; break;
4776 case VK_F18
: id
= WXK_F18
; break;
4777 case VK_F19
: id
= WXK_F19
; break;
4778 case VK_F20
: id
= WXK_F20
; break;
4779 case VK_F21
: id
= WXK_F21
; break;
4780 case VK_F22
: id
= WXK_F22
; break;
4781 case VK_F23
: id
= WXK_F23
; break;
4782 case VK_F24
: id
= WXK_F24
; break;
4783 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
4784 case VK_SCROLL
: id
= WXK_SCROLL
; break;
4786 case VK_OEM_1
: id
= ';'; break;
4787 case VK_OEM_PLUS
: id
= '+'; break;
4788 case VK_OEM_COMMA
: id
= ','; break;
4789 case VK_OEM_MINUS
: id
= '-'; break;
4790 case VK_OEM_PERIOD
: id
= '.'; break;
4791 case VK_OEM_2
: id
= '/'; break;
4792 case VK_OEM_3
: id
= '~'; break;
4793 case VK_OEM_4
: id
= '['; break;
4794 case VK_OEM_5
: id
= '\\'; break;
4795 case VK_OEM_6
: id
= ']'; break;
4796 case VK_OEM_7
: id
= '\''; break;
4799 case VK_LWIN
: id
= WXK_WINDOWS_LEFT
; break;
4800 case VK_RWIN
: id
= WXK_WINDOWS_RIGHT
; break;
4801 case VK_APPS
: id
= WXK_WINDOWS_MENU
; break;
4802 #endif // VK_APPS defined
4811 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
4817 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
4818 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
4819 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
4820 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
4821 case WXK_MENU
: keySym
= VK_MENU
; break;
4822 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
4823 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
4824 case WXK_NEXT
: keySym
= VK_NEXT
; break;
4825 case WXK_END
: keySym
= VK_END
; break;
4826 case WXK_HOME
: keySym
= VK_HOME
; break;
4827 case WXK_LEFT
: keySym
= VK_LEFT
; break;
4828 case WXK_UP
: keySym
= VK_UP
; break;
4829 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
4830 case WXK_DOWN
: keySym
= VK_DOWN
; break;
4831 case WXK_SELECT
: keySym
= VK_SELECT
; break;
4832 case WXK_PRINT
: keySym
= VK_PRINT
; break;
4833 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
4834 case WXK_INSERT
: keySym
= VK_INSERT
; break;
4835 case WXK_DELETE
: keySym
= VK_DELETE
; break;
4836 case WXK_HELP
: keySym
= VK_HELP
; break;
4837 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
4838 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
4839 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
4840 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
4841 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
4842 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
4843 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
4844 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
4845 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
4846 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
4847 case WXK_NUMPAD_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
4848 case WXK_NUMPAD_ADD
: keySym
= VK_ADD
; break;
4849 case WXK_NUMPAD_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
4850 case WXK_NUMPAD_DECIMAL
: keySym
= VK_DECIMAL
; break;
4851 case WXK_NUMPAD_DIVIDE
: keySym
= VK_DIVIDE
; break;
4852 case WXK_F1
: keySym
= VK_F1
; break;
4853 case WXK_F2
: keySym
= VK_F2
; break;
4854 case WXK_F3
: keySym
= VK_F3
; break;
4855 case WXK_F4
: keySym
= VK_F4
; break;
4856 case WXK_F5
: keySym
= VK_F5
; break;
4857 case WXK_F6
: keySym
= VK_F6
; break;
4858 case WXK_F7
: keySym
= VK_F7
; break;
4859 case WXK_F8
: keySym
= VK_F8
; break;
4860 case WXK_F9
: keySym
= VK_F9
; break;
4861 case WXK_F10
: keySym
= VK_F10
; break;
4862 case WXK_F11
: keySym
= VK_F11
; break;
4863 case WXK_F12
: keySym
= VK_F12
; break;
4864 case WXK_F13
: keySym
= VK_F13
; break;
4865 case WXK_F14
: keySym
= VK_F14
; break;
4866 case WXK_F15
: keySym
= VK_F15
; break;
4867 case WXK_F16
: keySym
= VK_F16
; break;
4868 case WXK_F17
: keySym
= VK_F17
; break;
4869 case WXK_F18
: keySym
= VK_F18
; break;
4870 case WXK_F19
: keySym
= VK_F19
; break;
4871 case WXK_F20
: keySym
= VK_F20
; break;
4872 case WXK_F21
: keySym
= VK_F21
; break;
4873 case WXK_F22
: keySym
= VK_F22
; break;
4874 case WXK_F23
: keySym
= VK_F23
; break;
4875 case WXK_F24
: keySym
= VK_F24
; break;
4876 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
4877 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
4888 wxWindow
*wxGetActiveWindow()
4890 HWND hWnd
= GetActiveWindow();
4893 return wxFindWinFromHandle((WXHWND
) hWnd
);
4898 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
4900 HWND hwnd
= (HWND
)hWnd
;
4902 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
4903 // by code in msw/radiobox.cpp), for all the others we just search up the
4905 wxWindow
*win
= (wxWindow
*)NULL
;
4908 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
4912 // native radiobuttons return DLGC_RADIOBUTTON here and for any
4913 // wxWindow class which overrides WM_GETDLGCODE processing to
4914 // do it as well, win would be already non NULL
4915 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
4917 win
= (wxWindow
*)::GetWindowLong(hwnd
, GWL_USERDATA
);
4919 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
4920 #endif // wxUSE_RADIOBOX
4922 // spin control text buddy window should be mapped to spin ctrl
4923 // itself so try it too
4924 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4927 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
4929 #endif // wxUSE_SPINCTRL
4933 while ( hwnd
&& !win
)
4935 // this is a really ugly hack needed to avoid mistakenly returning the
4936 // parent frame wxWindow for the find/replace modeless dialog HWND -
4937 // this, in turn, is needed to call IsDialogMessage() from
4938 // wxApp::ProcessMessage() as for this we must return NULL from here
4940 // FIXME: this is clearly not the best way to do it but I think we'll
4941 // need to change HWND <-> wxWindow code more heavily than I can
4942 // do it now to fix it
4943 #ifndef __WXMICROWIN__
4944 if ( ::GetWindow(hwnd
, GW_OWNER
) )
4946 // it's a dialog box, don't go upwards
4951 hwnd
= ::GetParent(hwnd
);
4952 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
4958 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
4960 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
4961 // in active frames and dialogs, regardless of where the focus is.
4962 static HHOOK wxTheKeyboardHook
= 0;
4963 static FARPROC wxTheKeyboardHookProc
= 0;
4964 int APIENTRY _EXPORT
4965 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
4967 void wxSetKeyboardHook(bool doIt
)
4971 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
4972 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
4974 GetCurrentThreadId()
4975 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
4980 UnhookWindowsHookEx(wxTheKeyboardHook
);
4984 int APIENTRY _EXPORT
4985 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
4987 DWORD hiWord
= HIWORD(lParam
);
4988 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
4990 int id
= wxCharCodeMSWToWX(wParam
);
4993 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
4994 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
4995 event
.m_altDown
= TRUE
;
4997 event
.m_eventObject
= NULL
;
4998 event
.m_keyCode
= id
;
4999 event
.m_shiftDown
= wxIsShiftDown();
5000 event
.m_controlDown
= wxIsCtrlDown();
5001 event
.SetTimestamp(s_currentMsg
.time
);
5003 wxWindow
*win
= wxGetActiveWindow();
5004 wxEvtHandler
*handler
;
5007 handler
= win
->GetEventHandler();
5008 event
.SetId(win
->GetId());
5016 if ( handler
&& handler
->ProcessEvent(event
) )
5024 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
5027 #endif // !__WXMICROWIN__
5030 const char *wxGetMessageName(int message
)
5034 case 0x0000: return "WM_NULL";
5035 case 0x0001: return "WM_CREATE";
5036 case 0x0002: return "WM_DESTROY";
5037 case 0x0003: return "WM_MOVE";
5038 case 0x0005: return "WM_SIZE";
5039 case 0x0006: return "WM_ACTIVATE";
5040 case 0x0007: return "WM_SETFOCUS";
5041 case 0x0008: return "WM_KILLFOCUS";
5042 case 0x000A: return "WM_ENABLE";
5043 case 0x000B: return "WM_SETREDRAW";
5044 case 0x000C: return "WM_SETTEXT";
5045 case 0x000D: return "WM_GETTEXT";
5046 case 0x000E: return "WM_GETTEXTLENGTH";
5047 case 0x000F: return "WM_PAINT";
5048 case 0x0010: return "WM_CLOSE";
5049 case 0x0011: return "WM_QUERYENDSESSION";
5050 case 0x0012: return "WM_QUIT";
5051 case 0x0013: return "WM_QUERYOPEN";
5052 case 0x0014: return "WM_ERASEBKGND";
5053 case 0x0015: return "WM_SYSCOLORCHANGE";
5054 case 0x0016: return "WM_ENDSESSION";
5055 case 0x0017: return "WM_SYSTEMERROR";
5056 case 0x0018: return "WM_SHOWWINDOW";
5057 case 0x0019: return "WM_CTLCOLOR";
5058 case 0x001A: return "WM_WININICHANGE";
5059 case 0x001B: return "WM_DEVMODECHANGE";
5060 case 0x001C: return "WM_ACTIVATEAPP";
5061 case 0x001D: return "WM_FONTCHANGE";
5062 case 0x001E: return "WM_TIMECHANGE";
5063 case 0x001F: return "WM_CANCELMODE";
5064 case 0x0020: return "WM_SETCURSOR";
5065 case 0x0021: return "WM_MOUSEACTIVATE";
5066 case 0x0022: return "WM_CHILDACTIVATE";
5067 case 0x0023: return "WM_QUEUESYNC";
5068 case 0x0024: return "WM_GETMINMAXINFO";
5069 case 0x0026: return "WM_PAINTICON";
5070 case 0x0027: return "WM_ICONERASEBKGND";
5071 case 0x0028: return "WM_NEXTDLGCTL";
5072 case 0x002A: return "WM_SPOOLERSTATUS";
5073 case 0x002B: return "WM_DRAWITEM";
5074 case 0x002C: return "WM_MEASUREITEM";
5075 case 0x002D: return "WM_DELETEITEM";
5076 case 0x002E: return "WM_VKEYTOITEM";
5077 case 0x002F: return "WM_CHARTOITEM";
5078 case 0x0030: return "WM_SETFONT";
5079 case 0x0031: return "WM_GETFONT";
5080 case 0x0037: return "WM_QUERYDRAGICON";
5081 case 0x0039: return "WM_COMPAREITEM";
5082 case 0x0041: return "WM_COMPACTING";
5083 case 0x0044: return "WM_COMMNOTIFY";
5084 case 0x0046: return "WM_WINDOWPOSCHANGING";
5085 case 0x0047: return "WM_WINDOWPOSCHANGED";
5086 case 0x0048: return "WM_POWER";
5088 case 0x004A: return "WM_COPYDATA";
5089 case 0x004B: return "WM_CANCELJOURNAL";
5090 case 0x004E: return "WM_NOTIFY";
5091 case 0x0050: return "WM_INPUTLANGCHANGEREQUEST";
5092 case 0x0051: return "WM_INPUTLANGCHANGE";
5093 case 0x0052: return "WM_TCARD";
5094 case 0x0053: return "WM_HELP";
5095 case 0x0054: return "WM_USERCHANGED";
5096 case 0x0055: return "WM_NOTIFYFORMAT";
5097 case 0x007B: return "WM_CONTEXTMENU";
5098 case 0x007C: return "WM_STYLECHANGING";
5099 case 0x007D: return "WM_STYLECHANGED";
5100 case 0x007E: return "WM_DISPLAYCHANGE";
5101 case 0x007F: return "WM_GETICON";
5102 case 0x0080: return "WM_SETICON";
5104 case 0x0081: return "WM_NCCREATE";
5105 case 0x0082: return "WM_NCDESTROY";
5106 case 0x0083: return "WM_NCCALCSIZE";
5107 case 0x0084: return "WM_NCHITTEST";
5108 case 0x0085: return "WM_NCPAINT";
5109 case 0x0086: return "WM_NCACTIVATE";
5110 case 0x0087: return "WM_GETDLGCODE";
5111 case 0x00A0: return "WM_NCMOUSEMOVE";
5112 case 0x00A1: return "WM_NCLBUTTONDOWN";
5113 case 0x00A2: return "WM_NCLBUTTONUP";
5114 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
5115 case 0x00A4: return "WM_NCRBUTTONDOWN";
5116 case 0x00A5: return "WM_NCRBUTTONUP";
5117 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
5118 case 0x00A7: return "WM_NCMBUTTONDOWN";
5119 case 0x00A8: return "WM_NCMBUTTONUP";
5120 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
5121 case 0x0100: return "WM_KEYDOWN";
5122 case 0x0101: return "WM_KEYUP";
5123 case 0x0102: return "WM_CHAR";
5124 case 0x0103: return "WM_DEADCHAR";
5125 case 0x0104: return "WM_SYSKEYDOWN";
5126 case 0x0105: return "WM_SYSKEYUP";
5127 case 0x0106: return "WM_SYSCHAR";
5128 case 0x0107: return "WM_SYSDEADCHAR";
5129 case 0x0108: return "WM_KEYLAST";
5131 case 0x010D: return "WM_IME_STARTCOMPOSITION";
5132 case 0x010E: return "WM_IME_ENDCOMPOSITION";
5133 case 0x010F: return "WM_IME_COMPOSITION";
5135 case 0x0110: return "WM_INITDIALOG";
5136 case 0x0111: return "WM_COMMAND";
5137 case 0x0112: return "WM_SYSCOMMAND";
5138 case 0x0113: return "WM_TIMER";
5139 case 0x0114: return "WM_HSCROLL";
5140 case 0x0115: return "WM_VSCROLL";
5141 case 0x0116: return "WM_INITMENU";
5142 case 0x0117: return "WM_INITMENUPOPUP";
5143 case 0x011F: return "WM_MENUSELECT";
5144 case 0x0120: return "WM_MENUCHAR";
5145 case 0x0121: return "WM_ENTERIDLE";
5146 case 0x0200: return "WM_MOUSEMOVE";
5147 case 0x0201: return "WM_LBUTTONDOWN";
5148 case 0x0202: return "WM_LBUTTONUP";
5149 case 0x0203: return "WM_LBUTTONDBLCLK";
5150 case 0x0204: return "WM_RBUTTONDOWN";
5151 case 0x0205: return "WM_RBUTTONUP";
5152 case 0x0206: return "WM_RBUTTONDBLCLK";
5153 case 0x0207: return "WM_MBUTTONDOWN";
5154 case 0x0208: return "WM_MBUTTONUP";
5155 case 0x0209: return "WM_MBUTTONDBLCLK";
5156 case 0x020A: return "WM_MOUSEWHEEL";
5157 case 0x0210: return "WM_PARENTNOTIFY";
5158 case 0x0211: return "WM_ENTERMENULOOP";
5159 case 0x0212: return "WM_EXITMENULOOP";
5161 case 0x0213: return "WM_NEXTMENU";
5162 case 0x0214: return "WM_SIZING";
5163 case 0x0215: return "WM_CAPTURECHANGED";
5164 case 0x0216: return "WM_MOVING";
5165 case 0x0218: return "WM_POWERBROADCAST";
5166 case 0x0219: return "WM_DEVICECHANGE";
5168 case 0x0220: return "WM_MDICREATE";
5169 case 0x0221: return "WM_MDIDESTROY";
5170 case 0x0222: return "WM_MDIACTIVATE";
5171 case 0x0223: return "WM_MDIRESTORE";
5172 case 0x0224: return "WM_MDINEXT";
5173 case 0x0225: return "WM_MDIMAXIMIZE";
5174 case 0x0226: return "WM_MDITILE";
5175 case 0x0227: return "WM_MDICASCADE";
5176 case 0x0228: return "WM_MDIICONARRANGE";
5177 case 0x0229: return "WM_MDIGETACTIVE";
5178 case 0x0230: return "WM_MDISETMENU";
5179 case 0x0233: return "WM_DROPFILES";
5181 case 0x0281: return "WM_IME_SETCONTEXT";
5182 case 0x0282: return "WM_IME_NOTIFY";
5183 case 0x0283: return "WM_IME_CONTROL";
5184 case 0x0284: return "WM_IME_COMPOSITIONFULL";
5185 case 0x0285: return "WM_IME_SELECT";
5186 case 0x0286: return "WM_IME_CHAR";
5187 case 0x0290: return "WM_IME_KEYDOWN";
5188 case 0x0291: return "WM_IME_KEYUP";
5190 case 0x0300: return "WM_CUT";
5191 case 0x0301: return "WM_COPY";
5192 case 0x0302: return "WM_PASTE";
5193 case 0x0303: return "WM_CLEAR";
5194 case 0x0304: return "WM_UNDO";
5195 case 0x0305: return "WM_RENDERFORMAT";
5196 case 0x0306: return "WM_RENDERALLFORMATS";
5197 case 0x0307: return "WM_DESTROYCLIPBOARD";
5198 case 0x0308: return "WM_DRAWCLIPBOARD";
5199 case 0x0309: return "WM_PAINTCLIPBOARD";
5200 case 0x030A: return "WM_VSCROLLCLIPBOARD";
5201 case 0x030B: return "WM_SIZECLIPBOARD";
5202 case 0x030C: return "WM_ASKCBFORMATNAME";
5203 case 0x030D: return "WM_CHANGECBCHAIN";
5204 case 0x030E: return "WM_HSCROLLCLIPBOARD";
5205 case 0x030F: return "WM_QUERYNEWPALETTE";
5206 case 0x0310: return "WM_PALETTEISCHANGING";
5207 case 0x0311: return "WM_PALETTECHANGED";
5209 case 0x0312: return "WM_HOTKEY";
5212 // common controls messages - although they're not strictly speaking
5213 // standard, it's nice to decode them nevertheless
5216 case 0x1000 + 0: return "LVM_GETBKCOLOR";
5217 case 0x1000 + 1: return "LVM_SETBKCOLOR";
5218 case 0x1000 + 2: return "LVM_GETIMAGELIST";
5219 case 0x1000 + 3: return "LVM_SETIMAGELIST";
5220 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
5221 case 0x1000 + 5: return "LVM_GETITEMA";
5222 case 0x1000 + 75: return "LVM_GETITEMW";
5223 case 0x1000 + 6: return "LVM_SETITEMA";
5224 case 0x1000 + 76: return "LVM_SETITEMW";
5225 case 0x1000 + 7: return "LVM_INSERTITEMA";
5226 case 0x1000 + 77: return "LVM_INSERTITEMW";
5227 case 0x1000 + 8: return "LVM_DELETEITEM";
5228 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
5229 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
5230 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
5231 case 0x1000 + 12: return "LVM_GETNEXTITEM";
5232 case 0x1000 + 13: return "LVM_FINDITEMA";
5233 case 0x1000 + 83: return "LVM_FINDITEMW";
5234 case 0x1000 + 14: return "LVM_GETITEMRECT";
5235 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
5236 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
5237 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
5238 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
5239 case 0x1000 + 18: return "LVM_HITTEST";
5240 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
5241 case 0x1000 + 20: return "LVM_SCROLL";
5242 case 0x1000 + 21: return "LVM_REDRAWITEMS";
5243 case 0x1000 + 22: return "LVM_ARRANGE";
5244 case 0x1000 + 23: return "LVM_EDITLABELA";
5245 case 0x1000 + 118: return "LVM_EDITLABELW";
5246 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
5247 case 0x1000 + 25: return "LVM_GETCOLUMNA";
5248 case 0x1000 + 95: return "LVM_GETCOLUMNW";
5249 case 0x1000 + 26: return "LVM_SETCOLUMNA";
5250 case 0x1000 + 96: return "LVM_SETCOLUMNW";
5251 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
5252 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
5253 case 0x1000 + 28: return "LVM_DELETECOLUMN";
5254 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
5255 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
5256 case 0x1000 + 31: return "LVM_GETHEADER";
5257 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
5258 case 0x1000 + 34: return "LVM_GETVIEWRECT";
5259 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
5260 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
5261 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
5262 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
5263 case 0x1000 + 39: return "LVM_GETTOPINDEX";
5264 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
5265 case 0x1000 + 41: return "LVM_GETORIGIN";
5266 case 0x1000 + 42: return "LVM_UPDATE";
5267 case 0x1000 + 43: return "LVM_SETITEMSTATE";
5268 case 0x1000 + 44: return "LVM_GETITEMSTATE";
5269 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
5270 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
5271 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
5272 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
5273 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
5274 case 0x1000 + 48: return "LVM_SORTITEMS";
5275 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
5276 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
5277 case 0x1000 + 51: return "LVM_GETITEMSPACING";
5278 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
5279 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
5280 case 0x1000 + 53: return "LVM_SETICONSPACING";
5281 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
5282 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
5283 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
5284 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
5285 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
5286 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
5287 case 0x1000 + 60: return "LVM_SETHOTITEM";
5288 case 0x1000 + 61: return "LVM_GETHOTITEM";
5289 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
5290 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
5291 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
5292 case 0x1000 + 65: return "LVM_SETWORKAREA";
5295 case 0x1100 + 0: return "TVM_INSERTITEMA";
5296 case 0x1100 + 50: return "TVM_INSERTITEMW";
5297 case 0x1100 + 1: return "TVM_DELETEITEM";
5298 case 0x1100 + 2: return "TVM_EXPAND";
5299 case 0x1100 + 4: return "TVM_GETITEMRECT";
5300 case 0x1100 + 5: return "TVM_GETCOUNT";
5301 case 0x1100 + 6: return "TVM_GETINDENT";
5302 case 0x1100 + 7: return "TVM_SETINDENT";
5303 case 0x1100 + 8: return "TVM_GETIMAGELIST";
5304 case 0x1100 + 9: return "TVM_SETIMAGELIST";
5305 case 0x1100 + 10: return "TVM_GETNEXTITEM";
5306 case 0x1100 + 11: return "TVM_SELECTITEM";
5307 case 0x1100 + 12: return "TVM_GETITEMA";
5308 case 0x1100 + 62: return "TVM_GETITEMW";
5309 case 0x1100 + 13: return "TVM_SETITEMA";
5310 case 0x1100 + 63: return "TVM_SETITEMW";
5311 case 0x1100 + 14: return "TVM_EDITLABELA";
5312 case 0x1100 + 65: return "TVM_EDITLABELW";
5313 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
5314 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
5315 case 0x1100 + 17: return "TVM_HITTEST";
5316 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
5317 case 0x1100 + 19: return "TVM_SORTCHILDREN";
5318 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
5319 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
5320 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
5321 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
5322 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
5323 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
5324 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
5327 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
5328 case 0x1200 + 1: return "HDM_INSERTITEMA";
5329 case 0x1200 + 10: return "HDM_INSERTITEMW";
5330 case 0x1200 + 2: return "HDM_DELETEITEM";
5331 case 0x1200 + 3: return "HDM_GETITEMA";
5332 case 0x1200 + 11: return "HDM_GETITEMW";
5333 case 0x1200 + 4: return "HDM_SETITEMA";
5334 case 0x1200 + 12: return "HDM_SETITEMW";
5335 case 0x1200 + 5: return "HDM_LAYOUT";
5336 case 0x1200 + 6: return "HDM_HITTEST";
5337 case 0x1200 + 7: return "HDM_GETITEMRECT";
5338 case 0x1200 + 8: return "HDM_SETIMAGELIST";
5339 case 0x1200 + 9: return "HDM_GETIMAGELIST";
5340 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
5341 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
5342 case 0x1200 + 17: return "HDM_GETORDERARRAY";
5343 case 0x1200 + 18: return "HDM_SETORDERARRAY";
5344 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
5347 case 0x1300 + 2: return "TCM_GETIMAGELIST";
5348 case 0x1300 + 3: return "TCM_SETIMAGELIST";
5349 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
5350 case 0x1300 + 5: return "TCM_GETITEMA";
5351 case 0x1300 + 60: return "TCM_GETITEMW";
5352 case 0x1300 + 6: return "TCM_SETITEMA";
5353 case 0x1300 + 61: return "TCM_SETITEMW";
5354 case 0x1300 + 7: return "TCM_INSERTITEMA";
5355 case 0x1300 + 62: return "TCM_INSERTITEMW";
5356 case 0x1300 + 8: return "TCM_DELETEITEM";
5357 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
5358 case 0x1300 + 10: return "TCM_GETITEMRECT";
5359 case 0x1300 + 11: return "TCM_GETCURSEL";
5360 case 0x1300 + 12: return "TCM_SETCURSEL";
5361 case 0x1300 + 13: return "TCM_HITTEST";
5362 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
5363 case 0x1300 + 40: return "TCM_ADJUSTRECT";
5364 case 0x1300 + 41: return "TCM_SETITEMSIZE";
5365 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
5366 case 0x1300 + 43: return "TCM_SETPADDING";
5367 case 0x1300 + 44: return "TCM_GETROWCOUNT";
5368 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
5369 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
5370 case 0x1300 + 47: return "TCM_GETCURFOCUS";
5371 case 0x1300 + 48: return "TCM_SETCURFOCUS";
5372 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
5373 case 0x1300 + 50: return "TCM_DESELECTALL";
5376 case WM_USER
+1: return "TB_ENABLEBUTTON";
5377 case WM_USER
+2: return "TB_CHECKBUTTON";
5378 case WM_USER
+3: return "TB_PRESSBUTTON";
5379 case WM_USER
+4: return "TB_HIDEBUTTON";
5380 case WM_USER
+5: return "TB_INDETERMINATE";
5381 case WM_USER
+9: return "TB_ISBUTTONENABLED";
5382 case WM_USER
+10: return "TB_ISBUTTONCHECKED";
5383 case WM_USER
+11: return "TB_ISBUTTONPRESSED";
5384 case WM_USER
+12: return "TB_ISBUTTONHIDDEN";
5385 case WM_USER
+13: return "TB_ISBUTTONINDETERMINATE";
5386 case WM_USER
+17: return "TB_SETSTATE";
5387 case WM_USER
+18: return "TB_GETSTATE";
5388 case WM_USER
+19: return "TB_ADDBITMAP";
5389 case WM_USER
+20: return "TB_ADDBUTTONS";
5390 case WM_USER
+21: return "TB_INSERTBUTTON";
5391 case WM_USER
+22: return "TB_DELETEBUTTON";
5392 case WM_USER
+23: return "TB_GETBUTTON";
5393 case WM_USER
+24: return "TB_BUTTONCOUNT";
5394 case WM_USER
+25: return "TB_COMMANDTOINDEX";
5395 case WM_USER
+26: return "TB_SAVERESTOREA";
5396 case WM_USER
+76: return "TB_SAVERESTOREW";
5397 case WM_USER
+27: return "TB_CUSTOMIZE";
5398 case WM_USER
+28: return "TB_ADDSTRINGA";
5399 case WM_USER
+77: return "TB_ADDSTRINGW";
5400 case WM_USER
+29: return "TB_GETITEMRECT";
5401 case WM_USER
+30: return "TB_BUTTONSTRUCTSIZE";
5402 case WM_USER
+31: return "TB_SETBUTTONSIZE";
5403 case WM_USER
+32: return "TB_SETBITMAPSIZE";
5404 case WM_USER
+33: return "TB_AUTOSIZE";
5405 case WM_USER
+35: return "TB_GETTOOLTIPS";
5406 case WM_USER
+36: return "TB_SETTOOLTIPS";
5407 case WM_USER
+37: return "TB_SETPARENT";
5408 case WM_USER
+39: return "TB_SETROWS";
5409 case WM_USER
+40: return "TB_GETROWS";
5410 case WM_USER
+42: return "TB_SETCMDID";
5411 case WM_USER
+43: return "TB_CHANGEBITMAP";
5412 case WM_USER
+44: return "TB_GETBITMAP";
5413 case WM_USER
+45: return "TB_GETBUTTONTEXTA";
5414 case WM_USER
+75: return "TB_GETBUTTONTEXTW";
5415 case WM_USER
+46: return "TB_REPLACEBITMAP";
5416 case WM_USER
+47: return "TB_SETINDENT";
5417 case WM_USER
+48: return "TB_SETIMAGELIST";
5418 case WM_USER
+49: return "TB_GETIMAGELIST";
5419 case WM_USER
+50: return "TB_LOADIMAGES";
5420 case WM_USER
+51: return "TB_GETRECT";
5421 case WM_USER
+52: return "TB_SETHOTIMAGELIST";
5422 case WM_USER
+53: return "TB_GETHOTIMAGELIST";
5423 case WM_USER
+54: return "TB_SETDISABLEDIMAGELIST";
5424 case WM_USER
+55: return "TB_GETDISABLEDIMAGELIST";
5425 case WM_USER
+56: return "TB_SETSTYLE";
5426 case WM_USER
+57: return "TB_GETSTYLE";
5427 case WM_USER
+58: return "TB_GETBUTTONSIZE";
5428 case WM_USER
+59: return "TB_SETBUTTONWIDTH";
5429 case WM_USER
+60: return "TB_SETMAXTEXTROWS";
5430 case WM_USER
+61: return "TB_GETTEXTROWS";
5431 case WM_USER
+41: return "TB_GETBITMAPFLAGS";
5434 static char s_szBuf
[128];
5435 sprintf(s_szBuf
, "<unknown message = %d>", message
);
5439 #endif //__WXDEBUG__
5441 static void TranslateKbdEventToMouse(wxWindowMSW
*win
,
5442 int *x
, int *y
, WPARAM
*flags
)
5444 // construct the key mask
5445 WPARAM
& fwKeys
= *flags
;
5447 fwKeys
= MK_RBUTTON
;
5448 if ( wxIsCtrlDown() )
5449 fwKeys
|= MK_CONTROL
;
5450 if ( wxIsShiftDown() )
5453 // simulate right mouse button click
5454 DWORD dwPos
= ::GetMessagePos();
5455 *x
= GET_X_LPARAM(dwPos
);
5456 *y
= GET_Y_LPARAM(dwPos
);
5458 win
->ScreenToClient(x
, y
);
5461 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
5465 HWND hwnd
= GetHwndOf(win
);
5466 HDC hdc
= ::GetDC(hwnd
);
5468 #if !wxDIALOG_UNIT_COMPATIBILITY
5469 // and select the current font into it
5470 HFONT hfont
= GetHfontOf(win
->GetFont());
5473 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
5477 // finally retrieve the text metrics from it
5478 GetTextMetrics(hdc
, &tm
);
5480 #if !wxDIALOG_UNIT_COMPATIBILITY
5484 (void)::SelectObject(hdc
, hfont
);
5488 ::ReleaseDC(hwnd
, hdc
);
5493 // Find the wxWindow at the current mouse position, returning the mouse
5495 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
5497 pt
= wxGetMousePosition();
5498 return wxFindWindowAtPoint(pt
);
5501 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
5506 HWND hWndHit
= ::WindowFromPoint(pt2
);
5508 wxWindow
* win
= wxFindWinFromHandle((WXHWND
) hWndHit
) ;
5509 HWND hWnd
= hWndHit
;
5511 // Try to find a window with a wxWindow associated with it
5512 while (!win
&& (hWnd
!= 0))
5514 hWnd
= ::GetParent(hWnd
);
5515 win
= wxFindWinFromHandle((WXHWND
) hWnd
) ;
5520 // Get the current mouse position.
5521 wxPoint
wxGetMousePosition()
5524 GetCursorPos( & pt
);
5526 return wxPoint(pt
.x
, pt
.y
);
5531 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
5533 UINT win_modifiers
=0;
5534 if ( modifiers
& wxMOD_ALT
)
5535 win_modifiers
|= MOD_ALT
;
5536 if ( modifiers
& wxMOD_SHIFT
)
5537 win_modifiers
|= MOD_SHIFT
;
5538 if ( modifiers
& wxMOD_CONTROL
)
5539 win_modifiers
|= MOD_CONTROL
;
5540 if ( modifiers
& wxMOD_WIN
)
5541 win_modifiers
|= MOD_WIN
;
5543 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
5545 wxLogLastError(_T("RegisterHotKey"));
5553 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
5555 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
5557 wxLogLastError(_T("UnregisterHotKey"));
5565 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
5567 int hotkeyId
= wParam
;
5568 int virtualKey
= HIWORD(lParam
);
5569 int win_modifiers
= LOWORD(lParam
);
5571 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
5572 event
.SetId(hotkeyId
);
5573 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
5574 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
5575 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
5576 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
5578 return GetEventHandler()->ProcessEvent(event
);
5581 #endif // wxUSE_HOTKEY