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
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
257 WX_DEFINE_FLAGS( wxWindowStyle
)
259 WX_BEGIN_FLAGS( wxWindowStyle
)
260 // new style border flags, we put them first to
261 // use them for streaming out
262 WX_FLAGS_MEMBER(wxBORDER_SIMPLE
)
263 WX_FLAGS_MEMBER(wxBORDER_SUNKEN
)
264 WX_FLAGS_MEMBER(wxBORDER_DOUBLE
)
265 WX_FLAGS_MEMBER(wxBORDER_RAISED
)
266 WX_FLAGS_MEMBER(wxBORDER_STATIC
)
267 WX_FLAGS_MEMBER(wxBORDER_NONE
)
269 // old style border flags
270 WX_FLAGS_MEMBER(wxSIMPLE_BORDER
)
271 WX_FLAGS_MEMBER(wxSUNKEN_BORDER
)
272 WX_FLAGS_MEMBER(wxDOUBLE_BORDER
)
273 WX_FLAGS_MEMBER(wxRAISED_BORDER
)
274 WX_FLAGS_MEMBER(wxSTATIC_BORDER
)
275 WX_FLAGS_MEMBER(wxNO_BORDER
)
277 // standard window styles
278 WX_FLAGS_MEMBER(wxTAB_TRAVERSAL
)
279 WX_FLAGS_MEMBER(wxCLIP_CHILDREN
)
280 WX_FLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
281 WX_FLAGS_MEMBER(wxWANTS_CHARS
)
282 WX_FLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE
)
283 WX_FLAGS_MEMBER(wxALWAYS_SHOW_SB
)
284 WX_FLAGS_MEMBER(wxVSCROLL
)
285 WX_FLAGS_MEMBER(wxHSCROLL
)
287 WX_END_FLAGS( wxWindowStyle
)
289 WX_BEGIN_PROPERTIES_TABLE(wxWindow
)
290 WX_EVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
291 WX_EVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
292 WX_EVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
293 // Always constructor Properties first
295 WX_READONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
296 WX_PROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1, 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
297 WX_PROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxPoint(-1,-1) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
298 WX_PROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxSize(-1,-1) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
299 WX_PROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
301 // Then all relations of the object graph
303 WX_READONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
305 // and finally all other properties
307 WX_PROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
308 WX_PROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
309 WX_PROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
310 WX_PROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
311 WX_PROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
313 // possible property candidates (not in xrc) or not valid in all subclasses
314 WX_PROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxT("") )
315 WX_PROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
316 WX_PROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxT("") )
317 // MaxHeight, Width , MinHeight , Width
318 // TODO switch label to control and title to toplevels
320 WX_PROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
321 //WX_PROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
322 // WX_PROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
323 WX_PROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
328 WX_END_PROPERTIES_TABLE()
330 WX_BEGIN_HANDLERS_TABLE(wxWindow
)
331 WX_END_HANDLERS_TABLE()
333 WX_CONSTRUCTOR_DUMMY(wxWindow
)
336 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
338 #endif // __WXUNIVERSAL__/__WXMSW__
340 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
341 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground
)
342 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
343 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
346 // ===========================================================================
348 // ===========================================================================
350 // ---------------------------------------------------------------------------
351 // wxWindow utility functions
352 // ---------------------------------------------------------------------------
354 // Find an item given the MS Windows id
355 wxWindow
*wxWindowMSW::FindItem(long id
) const
358 wxControl
*item
= wxDynamicCastThis(wxControl
);
361 // is it we or one of our "internal" children?
362 if ( item
->GetId() == id
363 #ifndef __WXUNIVERSAL__
364 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
365 #endif // __WXUNIVERSAL__
371 #endif // wxUSE_CONTROLS
373 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
376 wxWindow
*childWin
= current
->GetData();
378 wxWindow
*wnd
= childWin
->FindItem(id
);
382 current
= current
->GetNext();
388 // Find an item given the MS Windows handle
389 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
391 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
394 wxWindow
*parent
= current
->GetData();
396 // Do a recursive search.
397 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
403 || parent
->IsKindOf(CLASSINFO(wxControl
))
404 #endif // wxUSE_CONTROLS
407 wxWindow
*item
= current
->GetData();
408 if ( item
->GetHWND() == hWnd
)
412 if ( item
->ContainsHWND(hWnd
) )
417 current
= current
->GetNext();
422 // Default command handler
423 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
428 // ----------------------------------------------------------------------------
429 // constructors and such
430 // ----------------------------------------------------------------------------
432 void wxWindowMSW::Init()
438 m_isBeingDeleted
= FALSE
;
440 m_mouseInWindow
= FALSE
;
441 m_lastKeydownProcessed
= FALSE
;
443 m_childrenDisabled
= NULL
;
453 // as all windows are created with WS_VISIBLE style...
456 #if wxUSE_MOUSEEVENT_HACK
459 m_lastMouseEvent
= -1;
460 #endif // wxUSE_MOUSEEVENT_HACK
464 wxWindowMSW::~wxWindowMSW()
466 m_isBeingDeleted
= TRUE
;
468 #ifndef __WXUNIVERSAL__
469 // VS: make sure there's no wxFrame with last focus set to us:
470 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
472 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
475 if ( frame
->GetLastFocus() == this )
477 frame
->SetLastFocus(NULL
);
482 #endif // __WXUNIVERSAL__
484 // VS: destroy children first and _then_ detach *this from its parent.
485 // If we'd do it the other way around, children wouldn't be able
486 // find their parent frame (see above).
490 m_parent
->RemoveChild(this);
494 // VZ: test temp removed to understand what really happens here
495 //if (::IsWindow(GetHwnd()))
497 if ( !::DestroyWindow(GetHwnd()) )
498 wxLogLastError(wxT("DestroyWindow"));
501 // remove hWnd <-> wxWindow association
502 wxRemoveHandleAssociation(this);
505 delete m_childrenDisabled
;
508 // real construction (Init() must have been called before!)
509 bool wxWindowMSW::Create(wxWindow
*parent
,
514 const wxString
& name
)
516 wxCHECK_MSG( parent
, FALSE
, wxT("can't create wxWindow without parent") );
518 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
521 parent
->AddChild(this);
524 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
526 #ifdef __WXUNIVERSAL__
527 // no borders, we draw them ourselves
528 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
532 msflags
&= ~WS_BORDER
;
533 #endif // wxUniversal
535 // all windows are created visible by default except popup ones (which are
536 // like the wxTopLevelWindows in this aspect)
537 if ( style
& wxPOPUP_WINDOW
)
539 msflags
&= ~WS_VISIBLE
;
544 msflags
|= WS_VISIBLE
;
547 return MSWCreate(wxCanvasClassName
, NULL
, pos
, size
, msflags
, exstyle
);
550 // ---------------------------------------------------------------------------
552 // ---------------------------------------------------------------------------
554 void wxWindowMSW::SetFocus()
556 HWND hWnd
= GetHwnd();
557 wxCHECK_RET( hWnd
, _T("can't set focus to invalid window") );
559 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
563 if ( !::SetFocus(hWnd
) )
565 #if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
566 // was there really an error?
567 DWORD dwRes
= ::GetLastError();
570 HWND hwndFocus
= ::GetFocus();
571 if ( hwndFocus
!= hWnd
)
573 wxLogApiError(_T("SetFocus"), dwRes
);
580 void wxWindowMSW::SetFocusFromKbd()
582 // when the focus is given to the control with DLGC_HASSETSEL style from
583 // keyboard its contents should be entirely selected: this is what
584 // ::IsDialogMessage() does and so we should do it as well to provide the
585 // same LNF as the native programs
586 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
588 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
591 // do this after (maybe) setting the selection as like this when
592 // wxEVT_SET_FOCUS handler is called, the selection would have been already
593 // set correctly -- this may be important
594 wxWindowBase::SetFocusFromKbd();
597 // Get the window with the focus
598 wxWindow
*wxWindowBase::FindFocus()
600 HWND hWnd
= ::GetFocus();
603 return wxGetWindowFromHWND((WXHWND
)hWnd
);
609 bool wxWindowMSW::Enable(bool enable
)
611 if ( !wxWindowBase::Enable(enable
) )
614 HWND hWnd
= GetHwnd();
616 ::EnableWindow(hWnd
, (BOOL
)enable
);
618 // the logic below doesn't apply to the top level windows -- otherwise
619 // showing a modal dialog would result in total greying out (and ungreying
620 // out later) of everything which would be really ugly
624 // when the parent is disabled, all of its children should be disabled as
625 // well but when it is enabled back, only those of the children which
626 // hadn't been already disabled in the beginning should be enabled again,
627 // so we have to keep the list of those children
628 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
630 node
= node
->GetNext() )
632 wxWindow
*child
= node
->GetData();
633 if ( child
->IsTopLevel() )
635 // the logic below doesn't apply to top level children
641 // enable the child back unless it had been disabled before us
642 if ( !m_childrenDisabled
|| !m_childrenDisabled
->Find(child
) )
645 else // we're being disabled
647 if ( child
->IsEnabled() )
649 // disable it as children shouldn't stay enabled while the
653 else // child already disabled, remember it
655 // have we created the list of disabled children already?
656 if ( !m_childrenDisabled
)
657 m_childrenDisabled
= new wxWindowList
;
659 m_childrenDisabled
->Append(child
);
664 if ( enable
&& m_childrenDisabled
)
666 // we don't need this list any more, don't keep unused memory
667 delete m_childrenDisabled
;
668 m_childrenDisabled
= NULL
;
674 bool wxWindowMSW::Show(bool show
)
676 if ( !wxWindowBase::Show(show
) )
679 HWND hWnd
= GetHwnd();
680 int cshow
= show
? SW_SHOW
: SW_HIDE
;
681 ::ShowWindow(hWnd
, cshow
);
683 if ( show
&& IsTopLevel() )
685 wxBringWindowToTop(hWnd
);
691 // Raise the window to the top of the Z order
692 void wxWindowMSW::Raise()
694 wxBringWindowToTop(GetHwnd());
697 // Lower the window to the bottom of the Z order
698 void wxWindowMSW::Lower()
700 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
701 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
704 void wxWindowMSW::SetTitle( const wxString
& title
)
706 SetWindowText(GetHwnd(), title
.c_str());
709 wxString
wxWindowMSW::GetTitle() const
711 return wxGetWindowText(GetHWND());
714 void wxWindowMSW::DoCaptureMouse()
716 HWND hWnd
= GetHwnd();
723 void wxWindowMSW::DoReleaseMouse()
725 if ( !::ReleaseCapture() )
727 wxLogLastError(_T("ReleaseCapture"));
731 /* static */ wxWindow
*wxWindowBase::GetCapture()
733 HWND hwnd
= ::GetCapture();
734 return hwnd
? wxFindWinFromHandle((WXHWND
)hwnd
) : (wxWindow
*)NULL
;
737 bool wxWindowMSW::SetFont(const wxFont
& font
)
739 if ( !wxWindowBase::SetFont(font
) )
745 HWND hWnd
= GetHwnd();
748 WXHANDLE hFont
= m_font
.GetResourceHandle();
750 wxASSERT_MSG( hFont
, wxT("should have valid font") );
752 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
757 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
759 if ( !wxWindowBase::SetCursor(cursor
) )
767 HWND hWnd
= GetHwnd();
769 // Change the cursor NOW if we're within the correct window
771 ::GetCursorPos(&point
);
773 RECT rect
= wxGetWindowRect(hWnd
);
775 if ( ::PtInRect(&rect
, point
) && !wxIsBusy() )
776 ::SetCursor(GetHcursorOf(m_cursor
));
782 void wxWindowMSW::WarpPointer (int x
, int y
)
784 ClientToScreen(&x
, &y
);
786 if ( !::SetCursorPos(x
, y
) )
788 wxLogLastError(_T("SetCursorPos"));
792 // ---------------------------------------------------------------------------
794 // ---------------------------------------------------------------------------
796 // convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
797 static inline int wxDirToWinStyle(int orient
)
799 return orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
;
802 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
804 #ifdef __WXMICROWIN__
805 return ::GetScrollPosWX(hWnd
, wOrient
);
807 WinStruct
<SCROLLINFO
> scrollInfo
;
808 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
809 scrollInfo
.fMask
= SIF_POS
;
810 if ( !::GetScrollInfo(hWnd
,
814 // Not neccessarily an error, if there are no scrollbars yet.
815 // wxLogLastError(_T("GetScrollInfo"));
817 return scrollInfo
.nPos
;
818 // return ::GetScrollPos(hWnd, wOrient);
822 int wxWindowMSW::GetScrollPos(int orient
) const
824 HWND hWnd
= GetHwnd();
825 wxCHECK_MSG( hWnd
, 0, _T("no HWND in GetScrollPos") );
827 return GetScrollPosition(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
);
830 // This now returns the whole range, not just the number
831 // of positions that we can scroll.
832 int wxWindowMSW::GetScrollRange(int orient
) const
835 HWND hWnd
= GetHwnd();
839 ::GetScrollRange(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
842 WinStruct
<SCROLLINFO
> scrollInfo
;
843 scrollInfo
.fMask
= SIF_RANGE
;
844 if ( !::GetScrollInfo(hWnd
,
845 orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
848 // Most of the time this is not really an error, since the return
849 // value can also be zero when there is no scrollbar yet.
850 // wxLogLastError(_T("GetScrollInfo"));
852 maxPos
= scrollInfo
.nMax
;
854 // undo "range - 1" done in SetScrollbar()
858 int wxWindowMSW::GetScrollThumb(int orient
) const
860 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
863 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
865 HWND hWnd
= GetHwnd();
866 wxCHECK_RET( hWnd
, _T("SetScrollPos: no HWND") );
868 WinStruct
<SCROLLINFO
> info
;
872 info
.fMask
= SIF_POS
;
873 if ( HasFlag(wxALWAYS_SHOW_SB
) )
875 // disable scrollbar instead of removing it then
876 info
.fMask
|= SIF_DISABLENOSCROLL
;
879 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
883 // New function that will replace some of the above.
884 void wxWindowMSW::SetScrollbar(int orient
,
890 WinStruct
<SCROLLINFO
> info
;
891 info
.nPage
= pageSize
;
892 info
.nMin
= 0; // range is nMax - nMin + 1
893 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
895 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
896 if ( HasFlag(wxALWAYS_SHOW_SB
) )
898 // disable scrollbar instead of removing it then
899 info
.fMask
|= SIF_DISABLENOSCROLL
;
902 HWND hWnd
= GetHwnd();
905 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
909 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
912 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
918 rect
.left
= prect
->x
;
920 rect
.right
= prect
->x
+ prect
->width
;
921 rect
.bottom
= prect
->y
+ prect
->height
;
930 // FIXME: is this the exact equivalent of the line below?
931 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_ERASE
|SW_INVALIDATE
);
933 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
937 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
939 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
942 for ( int n
= 0; n
< count
; n
++ )
944 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
946 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
949 // don't bother to continue, we're already at top/bottom
956 return pos
!= posStart
;
959 bool wxWindowMSW::ScrollLines(int lines
)
961 bool down
= lines
> 0;
963 return ScrollVertically(GetHwnd(),
964 down
? SB_LINEDOWN
: SB_LINEUP
,
965 down
? lines
: -lines
);
968 bool wxWindowMSW::ScrollPages(int pages
)
970 bool down
= pages
> 0;
972 return ScrollVertically(GetHwnd(),
973 down
? SB_PAGEDOWN
: SB_PAGEUP
,
974 down
? pages
: -pages
);
977 // ---------------------------------------------------------------------------
979 // ---------------------------------------------------------------------------
981 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
983 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
985 HWND hwnd
= (HWND
)hWnd
;
986 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
988 wxAssociateWinWithHandle(hwnd
, this);
990 m_oldWndProc
= (WXFARPROC
)::GetWindowLong((HWND
)hWnd
, GWL_WNDPROC
);
992 // we don't need to subclass the window of our own class (in the Windows
993 // sense of the word)
994 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
996 ::SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG
) wxWndProc
);
1000 // don't bother restoring it neither: this also makes it easy to
1001 // implement IsOfStandardClass() method which returns TRUE for the
1002 // standard controls and FALSE for the wxWindows own windows as it can
1003 // simply check m_oldWndProc
1004 m_oldWndProc
= NULL
;
1008 void wxWindowMSW::UnsubclassWin()
1010 wxRemoveHandleAssociation(this);
1012 // Restore old Window proc
1013 HWND hwnd
= GetHwnd();
1018 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1022 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1024 ::SetWindowLong(hwnd
, GWL_WNDPROC
, (LONG
) m_oldWndProc
);
1027 m_oldWndProc
= NULL
;
1032 bool wxCheckWindowWndProc(WXHWND hWnd
, WXFARPROC wndProc
)
1034 // Unicows note: the code below works, but only because WNDCLASS contains
1035 // original window handler rather that the unicows fake one. This may not
1036 // be on purpose, though; if it stops working with future versions of
1037 // unicows.dll, we can override unicows hooks by setting
1038 // Unicows_{Set,Get}WindowLong and Unicows_RegisterClass to our own
1039 // versions that keep track of fake<->real wnd proc mapping.
1041 // On WinCE (at least), the wndproc comparison doesn't work,
1042 // so have to use something like this.
1044 extern const wxChar
*wxCanvasClassName
;
1045 extern const wxChar
*wxCanvasClassNameNR
;
1046 extern const wxChar
*wxMDIFrameClassName
;
1047 extern const wxChar
*wxMDIFrameClassNameNoRedraw
;
1048 extern const wxChar
*wxMDIChildFrameClassName
;
1049 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
1050 wxString
str(wxGetWindowClass(hWnd
));
1051 if (str
== wxCanvasClassName
||
1052 str
== wxCanvasClassNameNR
||
1053 str
== wxMDIFrameClassName
||
1054 str
== wxMDIFrameClassNameNoRedraw
||
1055 str
== wxMDIChildFrameClassName
||
1056 str
== wxMDIChildFrameClassNameNoRedraw
||
1057 str
== _T("wxTLWHiddenParent"))
1058 return TRUE
; // Effectively means don't subclass
1063 if ( !::GetClassInfo(wxGetInstance(), wxGetWindowClass(hWnd
), &cls
) )
1065 wxLogLastError(_T("GetClassInfo"));
1070 return wndProc
== (WXFARPROC
)cls
.lpfnWndProc
;
1074 // ----------------------------------------------------------------------------
1076 // ----------------------------------------------------------------------------
1078 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1080 long flagsOld
= GetWindowStyleFlag();
1081 if ( flags
== flagsOld
)
1084 // update the internal variable
1085 wxWindowBase::SetWindowStyleFlag(flags
);
1087 // now update the Windows style as well if needed - and if the window had
1088 // been already created
1092 WXDWORD exstyle
, exstyleOld
;
1093 long style
= MSWGetStyle(flags
, &exstyle
),
1094 styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1096 if ( style
!= styleOld
)
1098 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1099 // this function so instead of simply setting the style to the new
1100 // value we clear the bits which were set in styleOld but are set in
1101 // the new one and set the ones which were not set before
1102 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1103 styleReal
&= ~styleOld
;
1106 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1109 // and the extended style
1110 if ( exstyle
!= exstyleOld
)
1112 long exstyleReal
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1113 exstyleReal
&= ~exstyleOld
;
1114 exstyleReal
|= exstyle
;
1116 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyleReal
);
1118 // we must call SetWindowPos() to flash the cached extended style and
1119 // also to make the change to wxSTAY_ON_TOP style take effect: just
1120 // setting the style simply doesn't work
1121 if ( !::SetWindowPos(GetHwnd(),
1122 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1125 SWP_NOMOVE
| SWP_NOSIZE
) )
1127 wxLogLastError(_T("SetWindowPos"));
1132 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1134 // translate the style
1135 WXDWORD style
= WS_CHILD
| WS_VISIBLE
;
1137 if ( flags
& wxCLIP_CHILDREN
)
1138 style
|= WS_CLIPCHILDREN
;
1140 if ( flags
& wxCLIP_SIBLINGS
)
1141 style
|= WS_CLIPSIBLINGS
;
1143 if ( flags
& wxVSCROLL
)
1144 style
|= WS_VSCROLL
;
1146 if ( flags
& wxHSCROLL
)
1147 style
|= WS_HSCROLL
;
1149 const wxBorder border
= GetBorder(flags
);
1151 // WS_BORDER is only required for wxBORDER_SIMPLE
1152 if ( border
== wxBORDER_SIMPLE
)
1155 // now deal with ext style if the caller wants it
1161 if ( flags
& wxTRANSPARENT_WINDOW
)
1162 *exstyle
|= WS_EX_TRANSPARENT
;
1168 case wxBORDER_DEFAULT
:
1169 wxFAIL_MSG( _T("unknown border style") );
1173 case wxBORDER_SIMPLE
:
1176 case wxBORDER_STATIC
:
1177 *exstyle
|= WS_EX_STATICEDGE
;
1180 case wxBORDER_RAISED
:
1181 *exstyle
|= WS_EX_DLGMODALFRAME
;
1184 case wxBORDER_SUNKEN
:
1185 *exstyle
|= WS_EX_CLIENTEDGE
;
1186 style
&= ~WS_BORDER
;
1189 case wxBORDER_DOUBLE
:
1190 *exstyle
|= WS_EX_DLGMODALFRAME
;
1194 // wxUniv doesn't use Windows dialog navigation functions at all
1195 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1196 // to make the dialog navigation work with the nested panels we must
1197 // use this style (top level windows such as dialogs don't need it)
1198 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1200 *exstyle
|= WS_EX_CONTROLPARENT
;
1202 #endif // __WXUNIVERSAL__
1208 // Setup background and foreground colours correctly
1209 void wxWindowMSW::SetupColours()
1212 SetBackgroundColour(GetParent()->GetBackgroundColour());
1215 bool wxWindowMSW::IsMouseInWindow() const
1217 // get the mouse position
1219 ::GetCursorPos(&pt
);
1221 // find the window which currently has the cursor and go up the window
1222 // chain until we find this window - or exhaust it
1223 HWND hwnd
= ::WindowFromPoint(pt
);
1224 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1225 hwnd
= ::GetParent(hwnd
);
1227 return hwnd
!= NULL
;
1230 void wxWindowMSW::OnInternalIdle()
1232 // Check if we need to send a LEAVE event
1233 if ( m_mouseInWindow
)
1235 // note that we should generate the leave event whether the window has
1236 // or doesn't have mouse capture
1237 if ( !IsMouseInWindow() )
1239 // Generate a LEAVE event
1240 m_mouseInWindow
= FALSE
;
1242 // Unfortunately the mouse button and keyboard state may have
1243 // changed by the time the OnInternalIdle function is called, so 'state'
1244 // may be meaningless.
1246 if ( wxIsShiftDown() )
1248 if ( wxIsCtrlDown() )
1249 state
|= MK_CONTROL
;
1250 if ( GetKeyState( VK_LBUTTON
) )
1251 state
|= MK_LBUTTON
;
1252 if ( GetKeyState( VK_MBUTTON
) )
1253 state
|= MK_MBUTTON
;
1254 if ( GetKeyState( VK_RBUTTON
) )
1255 state
|= MK_RBUTTON
;
1258 if ( !::GetCursorPos(&pt
) )
1260 wxLogLastError(_T("GetCursorPos"));
1263 // we need to have client coordinates here for symmetry with
1264 // wxEVT_ENTER_WINDOW
1265 RECT rect
= wxGetWindowRect(GetHwnd());
1269 wxMouseEvent
event2(wxEVT_LEAVE_WINDOW
);
1270 InitMouseEvent(event2
, pt
.x
, pt
.y
, state
);
1272 (void)GetEventHandler()->ProcessEvent(event2
);
1276 if (wxUpdateUIEvent::CanUpdate(this))
1277 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1280 // Set this window to be the child of 'parent'.
1281 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1283 if ( !wxWindowBase::Reparent(parent
) )
1286 HWND hWndChild
= GetHwnd();
1287 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1289 ::SetParent(hWndChild
, hWndParent
);
1294 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1296 #ifndef __WXMICROWIN__
1297 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1301 void wxWindowMSW::Freeze()
1303 SendSetRedraw(GetHwnd(), FALSE
);
1306 void wxWindowMSW::Thaw()
1308 SendSetRedraw(GetHwnd(), TRUE
);
1310 // we need to refresh everything or otherwise he invalidated area is not
1315 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1317 HWND hWnd
= GetHwnd();
1323 mswRect
.left
= rect
->x
;
1324 mswRect
.top
= rect
->y
;
1325 mswRect
.right
= rect
->x
+ rect
->width
;
1326 mswRect
.bottom
= rect
->y
+ rect
->height
;
1328 ::InvalidateRect(hWnd
, &mswRect
, eraseBack
);
1331 ::InvalidateRect(hWnd
, NULL
, eraseBack
);
1335 void wxWindowMSW::Update()
1337 if ( !::UpdateWindow(GetHwnd()) )
1339 wxLogLastError(_T("UpdateWindow"));
1342 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1343 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1344 // handler needs to be really drawn right now
1349 // ---------------------------------------------------------------------------
1351 // ---------------------------------------------------------------------------
1354 #if wxUSE_DRAG_AND_DROP
1355 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1357 if ( m_dropTarget
!= 0 ) {
1358 m_dropTarget
->Revoke(m_hWnd
);
1359 delete m_dropTarget
;
1362 m_dropTarget
= pDropTarget
;
1363 if ( m_dropTarget
!= 0 )
1364 m_dropTarget
->Register(m_hWnd
);
1366 #endif // wxUSE_DRAG_AND_DROP
1368 // old style file-manager drag&drop support: we retain the old-style
1369 // DragAcceptFiles in parallel with SetDropTarget.
1370 void wxWindowMSW::DragAcceptFiles(bool accept
)
1372 #if !defined(__WXWINCE__)
1373 HWND hWnd
= GetHwnd();
1375 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1379 // ----------------------------------------------------------------------------
1381 // ----------------------------------------------------------------------------
1385 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1387 wxWindowBase::DoSetToolTip(tooltip
);
1390 m_tooltip
->SetWindow((wxWindow
*)this);
1393 #endif // wxUSE_TOOLTIPS
1395 // ---------------------------------------------------------------------------
1396 // moving and resizing
1397 // ---------------------------------------------------------------------------
1400 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1402 RECT rect
= wxGetWindowRect(GetHwnd());
1405 *x
= rect
.right
- rect
.left
;
1407 *y
= rect
.bottom
- rect
.top
;
1410 // Get size *available for subwindows* i.e. excluding menu bar etc.
1411 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1413 RECT rect
= wxGetClientRect(GetHwnd());
1421 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1423 RECT rect
= wxGetWindowRect(GetHwnd());
1426 point
.x
= rect
.left
;
1429 // we do the adjustments with respect to the parent only for the "real"
1430 // children, not for the dialogs/frames
1431 if ( !IsTopLevel() )
1433 HWND hParentWnd
= 0;
1434 wxWindow
*parent
= GetParent();
1436 hParentWnd
= GetWinHwnd(parent
);
1438 // Since we now have the absolute screen coords, if there's a parent we
1439 // must subtract its top left corner
1442 ::ScreenToClient(hParentWnd
, &point
);
1447 // We may be faking the client origin. So a window that's really at (0,
1448 // 30) may appear (to wxWin apps) to be at (0, 0).
1449 wxPoint
pt(parent
->GetClientAreaOrigin());
1461 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1469 ::ScreenToClient(GetHwnd(), &pt
);
1477 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1485 ::ClientToScreen(GetHwnd(), &pt
);
1493 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1495 // TODO: is this consistent with other platforms?
1496 // Still, negative width or height shouldn't be allowed
1501 if ( !::MoveWindow(GetHwnd(), x
, y
, width
, height
, TRUE
) )
1503 wxLogLastError(wxT("MoveWindow"));
1507 // set the size of the window: if the dimensions are positive, just use them,
1508 // but if any of them is equal to -1, it means that we must find the value for
1509 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1510 // which case -1 is a valid value for x and y)
1512 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1513 // the width/height to best suit our contents, otherwise we reuse the current
1515 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1517 // get the current size and position...
1518 int currentX
, currentY
;
1519 GetPosition(¤tX
, ¤tY
);
1520 int currentW
,currentH
;
1521 GetSize(¤tW
, ¤tH
);
1523 // ... and don't do anything (avoiding flicker) if it's already ok
1524 if ( x
== currentX
&& y
== currentY
&&
1525 width
== currentW
&& height
== currentH
)
1530 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1532 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1535 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1537 wxSize
size(-1, -1);
1540 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1542 size
= DoGetBestSize();
1547 // just take the current one
1554 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1558 size
= DoGetBestSize();
1560 //else: already called DoGetBestSize() above
1566 // just take the current one
1571 DoMoveWindow(x
, y
, width
, height
);
1574 void wxWindowMSW::DoSetClientSize(int width
, int height
)
1576 // setting the client size is less obvious than it it could have been
1577 // because in the result of changing the total size the window scrollbar
1578 // may [dis]appear and/or its menubar may [un]wrap and so the client size
1579 // will not be correct as the difference between the total and client size
1580 // changes - so we keep changing it until we get it right
1582 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1583 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1584 // may become 3 if the window had 0 size originally and so we didn't
1585 // calculate the scrollbar correction correctly during the first iteration)
1586 // but just to be on the safe side we check for it instead of making it an
1587 // "infinite" loop (i.e. leaving break inside as the only way to get out)
1588 for ( int i
= 0; i
< 4; i
++ )
1591 ::GetClientRect(GetHwnd(), &rectClient
);
1593 // if the size is already ok, stop here (rectClient.left = top = 0)
1594 if ( (rectClient
.right
== width
|| width
== -1) &&
1595 (rectClient
.bottom
== height
|| height
== -1) )
1600 int widthClient
= width
,
1601 heightClient
= height
;
1603 // Find the difference between the entire window (title bar and all)
1604 // and the client area; add this to the new client size to move the
1607 ::GetWindowRect(GetHwnd(), &rectWin
);
1609 widthClient
+= rectWin
.right
- rectWin
.left
- rectClient
.right
;
1610 heightClient
+= rectWin
.bottom
- rectWin
.top
- rectClient
.bottom
;
1613 point
.x
= rectWin
.left
;
1614 point
.y
= rectWin
.top
;
1616 // MoveWindow positions the child windows relative to the parent, so
1617 // adjust if necessary
1618 if ( !IsTopLevel() )
1620 wxWindow
*parent
= GetParent();
1623 ::ScreenToClient(GetHwndOf(parent
), &point
);
1627 DoMoveWindow(point
.x
, point
.y
, widthClient
, heightClient
);
1631 // For implementation purposes - sometimes decorations make the client area
1633 wxPoint
wxWindowMSW::GetClientAreaOrigin() const
1635 return wxPoint(0, 0);
1638 // ---------------------------------------------------------------------------
1640 // ---------------------------------------------------------------------------
1642 int wxWindowMSW::GetCharHeight() const
1644 return wxGetTextMetrics(this).tmHeight
;
1647 int wxWindowMSW::GetCharWidth() const
1649 // +1 is needed because Windows apparently adds it when calculating the
1650 // dialog units size in pixels
1651 #if wxDIALOG_UNIT_COMPATIBILITY
1652 return wxGetTextMetrics(this).tmAveCharWidth
;
1654 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
1658 void wxWindowMSW::GetTextExtent(const wxString
& string
,
1660 int *descent
, int *externalLeading
,
1661 const wxFont
*theFont
) const
1663 const wxFont
*fontToUse
= theFont
;
1665 fontToUse
= &m_font
;
1667 HWND hWnd
= GetHwnd();
1668 HDC dc
= ::GetDC(hWnd
);
1672 if ( fontToUse
&& fontToUse
->Ok() )
1674 fnt
= (HFONT
)((wxFont
*)fontToUse
)->GetResourceHandle(); // const_cast
1676 hfontOld
= (HFONT
)SelectObject(dc
,fnt
);
1681 GetTextExtentPoint(dc
, string
, (int)string
.Length(), &sizeRect
);
1682 GetTextMetrics(dc
, &tm
);
1684 if ( fontToUse
&& fnt
&& hfontOld
)
1685 SelectObject(dc
, hfontOld
);
1687 ReleaseDC(hWnd
, dc
);
1694 *descent
= tm
.tmDescent
;
1695 if ( externalLeading
)
1696 *externalLeading
= tm
.tmExternalLeading
;
1699 // ---------------------------------------------------------------------------
1701 // ---------------------------------------------------------------------------
1703 #if wxUSE_MENUS_NATIVE
1705 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
1706 // immediately, without waiting for the next event loop iteration
1708 // NB: this function should probably be made public later as it can almost
1709 // surely replace wxYield() elsewhere as well
1710 static void wxYieldForCommandsOnly()
1712 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
1713 // want to process it here)
1715 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
)
1716 && msg
.message
!= WM_QUIT
)
1718 wxTheApp
->DoMessage((WXMSG
*)&msg
);
1721 // If we retrieved a WM_QUIT, insert back into the message queue.
1722 if (msg
.message
== WM_QUIT
)
1723 ::PostQuitMessage(0);
1726 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1728 menu
->SetInvokingWindow(this);
1731 HWND hWnd
= GetHwnd();
1732 HMENU hMenu
= GetHmenuOf(menu
);
1736 ::ClientToScreen(hWnd
, &point
);
1737 wxCurrentPopupMenu
= menu
;
1739 #if !defined(__WXWINCE__)
1740 flags
= TPM_RIGHTBUTTON
;
1742 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
1744 // we need to do it righ now as otherwise the events are never going to be
1745 // sent to wxCurrentPopupMenu from HandleCommand()
1747 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
1748 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
1749 // destroyed as soon as we return (it can be a local variable in the caller
1750 // for example) and so we do need to process the event immediately
1751 wxYieldForCommandsOnly();
1753 wxCurrentPopupMenu
= NULL
;
1755 menu
->SetInvokingWindow(NULL
);
1760 #endif // wxUSE_MENUS_NATIVE
1762 // ===========================================================================
1763 // pre/post message processing
1764 // ===========================================================================
1766 long wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1769 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1771 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
1774 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
1776 // wxUniversal implements tab traversal itself
1777 #ifndef __WXUNIVERSAL__
1778 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
1780 // intercept dialog navigation keys
1781 MSG
*msg
= (MSG
*)pMsg
;
1783 // here we try to do all the job which ::IsDialogMessage() usually does
1786 if ( msg
->message
== WM_KEYDOWN
)
1788 bool bCtrlDown
= wxIsCtrlDown();
1789 bool bShiftDown
= wxIsShiftDown();
1791 // WM_GETDLGCODE: ask the control if it wants the key for itself,
1792 // don't process it if it's the case (except for Ctrl-Tab/Enter
1793 // combinations which are always processed)
1797 lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
1799 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
1800 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
1801 // it, of course, implies them
1802 if ( lDlgCode
& DLGC_WANTALLKEYS
)
1804 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
1808 bool bForward
= TRUE
,
1809 bWindowChange
= FALSE
;
1811 // should we process this message specially?
1812 bool bProcess
= TRUE
;
1813 switch ( msg
->wParam
)
1816 // assume that nobody wants Shift-TAB for himself - if we
1817 // don't do it there is no easy way for a control to grab
1818 // TABs but still let Shift-TAB work as navugation key
1819 if ( (lDlgCode
& DLGC_WANTTAB
) && !bShiftDown
) {
1823 // Ctrl-Tab cycles thru notebook pages
1824 bWindowChange
= bCtrlDown
;
1825 bForward
= !bShiftDown
;
1831 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
1839 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
1845 if ( (lDlgCode
& DLGC_WANTMESSAGE
) && !bCtrlDown
)
1847 // control wants to process Enter itself, don't
1848 // call IsDialogMessage() which would interpret
1852 else if ( lDlgCode
& DLGC_BUTTON
)
1854 // let IsDialogMessage() handle this for all
1855 // buttons except the owner-drawn ones which it
1856 // just seems to ignore
1857 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
1858 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
1860 // emulate the button click
1861 wxWindow
*btn
= wxFindWinFromHandle((WXHWND
)msg
->hwnd
);
1863 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
1868 // FIXME: this should be handled by
1869 // wxNavigationKeyEvent handler and not here!!
1873 wxButton
*btn
= wxDynamicCast(GetDefaultItem(),
1875 if ( btn
&& btn
->IsEnabled() )
1877 // if we do have a default button, do press it
1878 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
1882 else // no default button
1884 #endif // wxUSE_BUTTON
1885 // this is a quick and dirty test for a text
1887 if ( !(lDlgCode
& DLGC_HASSETSEL
) )
1889 // don't process Enter, the control might
1890 // need it for itself and don't let
1891 // ::IsDialogMessage() have it as it can
1892 // eat the Enter events sometimes
1895 else if (!IsTopLevel())
1897 // if not a top level window, let parent
1901 //else: treat Enter as TAB: pass to the next
1902 // control as this is the best thing to do
1903 // if the text doesn't handle Enter itself
1915 wxNavigationKeyEvent event
;
1916 event
.SetDirection(bForward
);
1917 event
.SetWindowChange(bWindowChange
);
1918 event
.SetEventObject(this);
1920 if ( GetEventHandler()->ProcessEvent(event
) )
1927 // let ::IsDialogMessage() do almost everything and handle just the
1928 // things it doesn't here: Ctrl-TAB for switching notebook pages
1929 if ( msg
->message
== WM_KEYDOWN
)
1931 // don't process system keys here
1932 if ( !(HIWORD(msg
->lParam
) & KF_ALTDOWN
) )
1934 if ( (msg
->wParam
== VK_TAB
) && wxIsCtrlDown() )
1936 // find the first notebook parent and change its page
1937 wxWindow
*win
= this;
1938 wxNotebook
*nbook
= NULL
;
1939 while ( win
&& !nbook
)
1941 nbook
= wxDynamicCast(win
, wxNotebook
);
1942 win
= win
->GetParent();
1947 bool forward
= !wxIsShiftDown();
1949 nbook
->AdvanceSelection(forward
);
1956 // we handle VK_ESCAPE ourselves in wxDialog::OnCharHook() and we
1957 // shouldn't let IsDialogMessage() get it as it _always_ eats the
1958 // message even when there is no cancel button and when the message is
1959 // needed by the control itself: in particular, it prevents the tree in
1960 // place edit control from being closed with Escape in a dialog
1961 if ( msg
->message
!= WM_KEYDOWN
|| msg
->wParam
!= VK_ESCAPE
)
1963 // ::IsDialogMessage() is broken and may sometimes hang the
1964 // application by going into an infinite loop, so we try to detect
1965 // [some of] the situatations when this may happen and not call it
1968 // assume we can call it by default
1969 bool canSafelyCallIsDlgMsg
= TRUE
;
1971 HWND hwndFocus
= ::GetFocus();
1973 // if the currently focused window itself has WS_EX_CONTROLPARENT style, ::IsDialogMessage() will also enter
1974 // an infinite loop, because it will recursively check the child
1975 // windows but not the window itself and so if none of the children
1976 // accepts focus it loops forever (as it only stops when it gets
1977 // back to the window it started from)
1979 // while it is very unusual that a window with WS_EX_CONTROLPARENT
1980 // style has the focus, it can happen. One such possibility is if
1981 // all windows are either toplevel, wxDialog, wxPanel or static
1982 // controls and no window can actually accept keyboard input.
1983 #if !defined(__WXWINCE__)
1984 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1986 // passimistic by default
1987 canSafelyCallIsDlgMsg
= FALSE
;
1988 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1990 node
= node
->GetNext() )
1992 wxWindow
* const win
= node
->GetData();
1993 if ( win
->AcceptsFocus() &&
1994 !(::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
) &
1995 WS_EX_CONTROLPARENT
) )
1997 // it shouldn't hang...
1998 canSafelyCallIsDlgMsg
= TRUE
;
2004 #endif // !__WXWINCE__
2006 if ( canSafelyCallIsDlgMsg
)
2008 // ::IsDialogMessage() can enter in an infinite loop when the
2009 // currently focused window is disabled or hidden and its
2010 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2014 if ( !::IsWindowEnabled(hwndFocus
) ||
2015 !::IsWindowVisible(hwndFocus
) )
2017 // it would enter an infinite loop if we do this!
2018 canSafelyCallIsDlgMsg
= FALSE
;
2023 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2025 // it's a top level window, don't go further -- e.g. even
2026 // if the parent of a dialog is disabled, this doesn't
2027 // break navigation inside the dialog
2031 hwndFocus
= ::GetParent(hwndFocus
);
2035 // let IsDialogMessage() have the message if it's safe to call it
2036 if ( canSafelyCallIsDlgMsg
&& ::IsDialogMessage(GetHwnd(), msg
) )
2038 // IsDialogMessage() did something...
2043 #endif // __WXUNIVERSAL__
2048 // relay mouse move events to the tooltip control
2049 MSG
*msg
= (MSG
*)pMsg
;
2050 if ( msg
->message
== WM_MOUSEMOVE
)
2051 m_tooltip
->RelayEvent(pMsg
);
2053 #endif // wxUSE_TOOLTIPS
2058 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2060 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2061 return m_acceleratorTable
.Translate(this, pMsg
);
2065 #endif // wxUSE_ACCEL
2068 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* WXUNUSED(pMsg
))
2070 // preprocess all messages by default
2074 // ---------------------------------------------------------------------------
2075 // message params unpackers
2076 // ---------------------------------------------------------------------------
2078 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2079 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2081 *id
= LOWORD(wParam
);
2082 *hwnd
= (WXHWND
)lParam
;
2083 *cmd
= HIWORD(wParam
);
2086 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2087 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2089 *state
= LOWORD(wParam
);
2090 *minimized
= HIWORD(wParam
);
2091 *hwnd
= (WXHWND
)lParam
;
2094 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2095 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2097 *code
= LOWORD(wParam
);
2098 *pos
= HIWORD(wParam
);
2099 *hwnd
= (WXHWND
)lParam
;
2102 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2103 WXWORD
*nCtlColor
, WXHDC
*hdc
, WXHWND
*hwnd
)
2105 #ifndef __WXMICROWIN__
2106 *nCtlColor
= CTLCOLOR_BTN
;
2107 *hwnd
= (WXHWND
)lParam
;
2108 *hdc
= (WXHDC
)wParam
;
2112 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2113 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2115 *item
= (WXWORD
)wParam
;
2116 *flags
= HIWORD(wParam
);
2117 *hmenu
= (WXHMENU
)lParam
;
2120 // ---------------------------------------------------------------------------
2121 // Main wxWindows window proc and the window proc for wxWindow
2122 // ---------------------------------------------------------------------------
2124 // Hook for new window just as it's being created, when the window isn't yet
2125 // associated with the handle
2126 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2128 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2129 // window being created and insures that it's always unset back later
2130 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2132 gs_winBeingCreated
= winBeingCreated
;
2135 wxWindowCreationHook::~wxWindowCreationHook()
2137 gs_winBeingCreated
= NULL
;
2141 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2143 // trace all messages - useful for the debugging
2145 wxLogTrace(wxTraceMessages
,
2146 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2147 wxGetMessageName(message
), (long)hWnd
, (long)wParam
, lParam
);
2148 #endif // __WXDEBUG__
2150 wxWindowMSW
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
2152 // when we get the first message for the HWND we just created, we associate
2153 // it with wxWindow stored in gs_winBeingCreated
2154 if ( !wnd
&& gs_winBeingCreated
)
2156 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2157 wnd
= gs_winBeingCreated
;
2158 gs_winBeingCreated
= NULL
;
2159 wnd
->SetHWND((WXHWND
)hWnd
);
2165 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2167 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2172 long wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2174 // did we process the message?
2175 bool processed
= FALSE
;
2186 // for most messages we should return 0 when we do process the message
2194 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2197 // return 0 to allow window creation
2198 rc
.result
= mayCreate
? 0 : -1;
2204 // never set processed to TRUE and *always* pass WM_DESTROY to
2205 // DefWindowProc() as Windows may do some internal cleanup when
2206 // processing it and failing to pass the message along may cause
2207 // memory and resource leaks!
2208 (void)HandleDestroy();
2212 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2215 #if !defined(__WXWINCE__)
2218 LPRECT pRect
= (LPRECT
)lParam
;
2220 rc
.SetLeft(pRect
->left
);
2221 rc
.SetTop(pRect
->top
);
2222 rc
.SetRight(pRect
->right
);
2223 rc
.SetBottom(pRect
->bottom
);
2224 processed
= HandleMoving(rc
);
2226 pRect
->left
= rc
.GetLeft();
2227 pRect
->top
= rc
.GetTop();
2228 pRect
->right
= rc
.GetRight();
2229 pRect
->bottom
= rc
.GetBottom();
2240 // we're not interested in these messages at all
2243 case SIZE_MINIMIZED
:
2244 // we shouldn't send sizev events for these messages as the
2245 // client size may be negative which breaks existing code
2247 // OTOH we might send another (wxMinimizedEvent?) one or
2248 // add an additional parameter to wxSizeEvent if this is
2249 // useful to anybody
2253 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
2254 // fall through nevertheless
2256 case SIZE_MAXIMIZED
:
2258 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
),
2263 #if !defined(__WXWINCE__)
2266 LPRECT pRect
= (LPRECT
)lParam
;
2268 rc
.SetLeft(pRect
->left
);
2269 rc
.SetTop(pRect
->top
);
2270 rc
.SetRight(pRect
->right
);
2271 rc
.SetBottom(pRect
->bottom
);
2272 processed
= HandleSizing(rc
);
2274 pRect
->left
= rc
.GetLeft();
2275 pRect
->top
= rc
.GetTop();
2276 pRect
->right
= rc
.GetRight();
2277 pRect
->bottom
= rc
.GetBottom();
2283 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2284 case WM_ACTIVATEAPP
:
2285 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2291 WXWORD state
, minimized
;
2293 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2295 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2300 processed
= HandleSetFocus((WXHWND
)(HWND
)wParam
);
2304 processed
= HandleKillFocus((WXHWND
)(HWND
)wParam
);
2311 // cast to wxWindow is needed for wxUniv
2312 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2313 processed
= HandlePaint();
2317 processed
= HandlePaint();
2323 #ifdef __WXUNIVERSAL__
2324 // Universal uses its own wxFrame/wxDialog, so we don't receive
2325 // close events unless we have this.
2330 // don't let the DefWindowProc() destroy our window - we'll do it
2331 // ourselves in ~wxWindow
2338 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2342 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2343 GET_Y_LPARAM(lParam
),
2347 #if wxUSE_MOUSEWHEEL
2349 processed
= HandleMouseWheel(wParam
, lParam
);
2353 case WM_LBUTTONDOWN
:
2355 case WM_LBUTTONDBLCLK
:
2356 case WM_RBUTTONDOWN
:
2358 case WM_RBUTTONDBLCLK
:
2359 case WM_MBUTTONDOWN
:
2361 case WM_MBUTTONDBLCLK
:
2363 #ifdef __WXMICROWIN__
2364 // MicroWindows seems to ignore the fact that a window is
2365 // disabled. So catch mouse events and throw them away if
2367 wxWindowMSW
* win
= this;
2370 if (!win
->IsEnabled())
2376 win
= win
->GetParent();
2377 if ( !win
|| win
->IsTopLevel() )
2384 #endif // __WXMICROWIN__
2385 int x
= GET_X_LPARAM(lParam
),
2386 y
= GET_Y_LPARAM(lParam
);
2388 // redirect the event to a static control if necessary by
2389 // finding one under mouse
2391 if ( GetCapture() == this )
2393 // but don't do it if the mouse is captured by this window
2394 // because then it should really get this event itself
2399 win
= FindWindowForMouseEvent(this, &x
, &y
);
2401 // this should never happen
2402 wxCHECK_MSG( win
, 0,
2403 _T("FindWindowForMouseEvent() returned NULL") );
2405 // for the standard classes their WndProc sets the focus to
2406 // them anyhow and doing it from here results in some weird
2407 // problems, but for our windows we want them to acquire
2408 // focus when clicked
2409 if ( !win
->IsOfStandardClass() )
2411 if ( message
== WM_LBUTTONDOWN
&& win
->AcceptsFocus() )
2416 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2425 case MM_JOY1BUTTONDOWN
:
2426 case MM_JOY2BUTTONDOWN
:
2427 case MM_JOY1BUTTONUP
:
2428 case MM_JOY2BUTTONUP
:
2429 processed
= HandleJoystickEvent(message
,
2430 GET_X_LPARAM(lParam
),
2431 GET_Y_LPARAM(lParam
),
2434 #endif // __WXMICROWIN__
2437 processed
= HandleSysCommand(wParam
, lParam
);
2444 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2446 processed
= HandleCommand(id
, cmd
, hwnd
);
2451 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2454 // for these messages we must return TRUE if process the message
2457 case WM_MEASUREITEM
:
2459 int idCtrl
= (UINT
)wParam
;
2460 if ( message
== WM_DRAWITEM
)
2462 processed
= MSWOnDrawItem(idCtrl
,
2463 (WXDRAWITEMSTRUCT
*)lParam
);
2467 processed
= MSWOnMeasureItem(idCtrl
,
2468 (WXMEASUREITEMSTRUCT
*)lParam
);
2475 #endif // defined(WM_DRAWITEM)
2478 if ( !IsOfStandardClass() )
2480 // we always want to get the char events
2481 rc
.result
= DLGC_WANTCHARS
;
2483 if ( GetWindowStyleFlag() & wxWANTS_CHARS
)
2485 // in fact, we want everything
2486 rc
.result
|= DLGC_WANTARROWS
|
2493 //else: get the dlg code from the DefWindowProc()
2498 // If this has been processed by an event handler, return 0 now
2499 // (we've handled it).
2500 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
2501 if ( m_lastKeydownProcessed
)
2510 // we consider these message "not interesting" to OnChar, so
2511 // just don't do anything more with them
2521 // avoid duplicate messages to OnChar for these ASCII keys:
2522 // they will be translated by TranslateMessage() and received
2544 // but set processed to FALSE, not TRUE to still pass them
2545 // to the control's default window proc - otherwise
2546 // built-in keyboard handling won't work
2551 // special case of VK_APPS: treat it the same as right mouse
2552 // click because both usually pop up a context menu
2558 TranslateKbdEventToMouse(this, &x
, &y
, &flags
);
2559 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, x
, y
, flags
);
2565 // do generate a CHAR event
2566 processed
= HandleChar((WORD
)wParam
, lParam
);
2569 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
2576 // special case of VK_APPS: treat it the same as right mouse button
2577 if ( wParam
== VK_APPS
)
2582 TranslateKbdEventToMouse(this, &x
, &y
, &flags
);
2583 processed
= HandleMouseEvent(WM_RBUTTONUP
, x
, y
, flags
);
2588 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
2593 case WM_CHAR
: // Always an ASCII character
2594 if ( m_lastKeydownProcessed
)
2596 // The key was handled in the EVT_KEY_DOWN and handling
2597 // a key in an EVT_KEY_DOWN handler is meant, by
2598 // design, to prevent EVT_CHARs from happening
2599 m_lastKeydownProcessed
= FALSE
;
2604 processed
= HandleChar((WORD
)wParam
, lParam
, TRUE
);
2610 processed
= HandleHotKey((WORD
)wParam
, lParam
);
2612 #endif // wxUSE_HOTKEY
2619 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
2621 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
2627 // CTLCOLOR messages are sent by children to query the parent for their
2628 // colors#ifndef __WXMICROWIN__
2629 #ifndef __WXMICROWIN__
2630 case WM_CTLCOLORMSGBOX
:
2631 case WM_CTLCOLOREDIT
:
2632 case WM_CTLCOLORLISTBOX
:
2633 case WM_CTLCOLORBTN
:
2634 case WM_CTLCOLORDLG
:
2635 case WM_CTLCOLORSCROLLBAR
:
2636 case WM_CTLCOLORSTATIC
:
2641 UnpackCtlColor(wParam
, lParam
, &nCtlColor
, &hdc
, &hwnd
);
2643 processed
= HandleCtlColor(&rc
.hBrush
,
2652 #endif // !__WXMICROWIN__
2654 case WM_SYSCOLORCHANGE
:
2655 // the return value for this message is ignored
2656 processed
= HandleSysColorChange();
2659 #if !defined(__WXWINCE__)
2660 case WM_DISPLAYCHANGE
:
2661 processed
= HandleDisplayChange();
2665 case WM_PALETTECHANGED
:
2666 processed
= HandlePaletteChanged((WXHWND
) (HWND
) wParam
);
2669 case WM_CAPTURECHANGED
:
2670 processed
= HandleCaptureChanged((WXHWND
) (HWND
) lParam
);
2673 case WM_QUERYNEWPALETTE
:
2674 processed
= HandleQueryNewPalette();
2678 processed
= HandleEraseBkgnd((WXHDC
)(HDC
)wParam
);
2681 // we processed the message, i.e. erased the background
2686 #if !defined(__WXWINCE__)
2688 processed
= HandleDropFiles(wParam
);
2693 processed
= HandleInitDialog((WXHWND
)(HWND
)wParam
);
2697 // we never set focus from here
2702 #if !defined(__WXWINCE__)
2703 case WM_QUERYENDSESSION
:
2704 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
2708 processed
= HandleEndSession(wParam
!= 0, lParam
);
2711 case WM_GETMINMAXINFO
:
2712 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
2717 processed
= HandleSetCursor((WXHWND
)(HWND
)wParam
,
2718 LOWORD(lParam
), // hit test
2719 HIWORD(lParam
)); // mouse msg
2723 // returning TRUE stops the DefWindowProc() from further
2724 // processing this message - exactly what we need because we've
2725 // just set the cursor.
2730 #if wxUSE_ACCESSIBILITY
2733 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
2734 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
2736 if (dwObjId
== OBJID_CLIENT
&& GetOrCreateAccessible())
2738 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
2744 #if defined(WM_HELP)
2747 // HELPINFO doesn't seem to be supported on WinCE.
2749 HELPINFO
* info
= (HELPINFO
*) lParam
;
2750 // Don't yet process menu help events, just windows
2751 if (info
->iContextType
== HELPINFO_WINDOW
)
2754 wxWindowMSW
* subjectOfHelp
= this;
2755 bool eventProcessed
= FALSE
;
2756 while (subjectOfHelp
&& !eventProcessed
)
2758 wxHelpEvent
helpEvent(wxEVT_HELP
,
2759 subjectOfHelp
->GetId(),
2763 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
2767 helpEvent
.SetEventObject(this);
2769 GetEventHandler()->ProcessEvent(helpEvent
);
2771 // Go up the window hierarchy until the event is
2773 subjectOfHelp
= subjectOfHelp
->GetParent();
2776 processed
= eventProcessed
;
2779 else if (info
->iContextType
== HELPINFO_MENUITEM
)
2781 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
2782 helpEvent
.SetEventObject(this);
2783 processed
= GetEventHandler()->ProcessEvent(helpEvent
);
2786 //else: processed is already FALSE
2792 #if !defined(__WXWINCE__)
2793 case WM_CONTEXTMENU
:
2795 // we don't convert from screen to client coordinates as
2796 // the event may be handled by a parent window
2797 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2799 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2800 processed
= GetEventHandler()->ProcessEvent(evtCtx
);
2806 // we're only interested in our own menus, not MF_SYSMENU
2807 if ( HIWORD(wParam
) == MF_POPUP
)
2809 // handle menu chars for ownerdrawn menu items
2810 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
2811 if ( i
!= wxNOT_FOUND
)
2813 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
2823 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
2824 wxGetMessageName(message
));
2825 #endif // __WXDEBUG__
2826 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
2832 // ----------------------------------------------------------------------------
2833 // wxWindow <-> HWND map
2834 // ----------------------------------------------------------------------------
2836 wxWinHashTable
*wxWinHandleHash
= NULL
;
2838 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
2840 return wxWinHandleHash
->Get((long)hWnd
);
2843 void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
)
2845 // adding NULL hWnd is (first) surely a result of an error and
2846 // (secondly) breaks menu command processing
2847 wxCHECK_RET( hWnd
!= (HWND
)NULL
,
2848 wxT("attempt to add a NULL hWnd to window list ignored") );
2850 wxWindow
*oldWin
= wxFindWinFromHandle((WXHWND
) hWnd
);
2852 if ( oldWin
&& (oldWin
!= win
) )
2854 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
2855 (int) hWnd
, win
->GetClassInfo()->GetClassName());
2858 #endif // __WXDEBUG__
2861 wxWinHandleHash
->Put((long)hWnd
, (wxWindow
*)win
);
2865 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
2867 wxWinHandleHash
->Delete((long)win
->GetHWND());
2870 // ----------------------------------------------------------------------------
2871 // various MSW speciic class dependent functions
2872 // ----------------------------------------------------------------------------
2874 // Default destroyer - override if you destroy it in some other way
2875 // (e.g. with MDI child windows)
2876 void wxWindowMSW::MSWDestroyWindow()
2880 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
2883 int& w
, int& h
) const
2885 static const int DEFAULT_Y
= 200;
2886 static const int DEFAULT_H
= 250;
2888 bool nonDefault
= FALSE
;
2892 // if set x to CW_USEDEFAULT, y parameter is ignored anyhow so we can
2893 // just as well set it to CW_USEDEFAULT as well
2899 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
2900 // neither because it is not handled as a special value by Windows then
2901 // and so we have to choose some default value for it
2903 y
= pos
.y
== -1 ? DEFAULT_Y
: pos
.y
;
2909 NB: there used to be some code here which set the initial size of the
2910 window to the client size of the parent if no explicit size was
2911 specified. This was wrong because wxWindows programs often assume
2912 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
2913 it. To see why, you should understand that Windows sends WM_SIZE from
2914 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
2915 from some base class ctor and so this WM_SIZE is not processed in the
2916 real class' OnSize() (because it's not fully constructed yet and the
2917 event goes to some base class OnSize() instead). So the WM_SIZE we
2918 rely on is the one sent when the parent frame resizes its children
2919 but here is the problem: if the child already has just the right
2920 size, nothing will happen as both wxWindows and Windows check for
2921 this and ignore any attempts to change the window size to the size it
2922 already has - so no WM_SIZE would be sent.
2926 // as above, h is not used at all in this case anyhow
2932 // and, again as above, we can't set the height to CW_USEDEFAULT here
2934 h
= size
.y
== -1 ? DEFAULT_H
: size
.y
;
2942 WXHWND
wxWindowMSW::MSWGetParent() const
2944 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
2947 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
2948 const wxChar
*title
,
2952 WXDWORD extendedStyle
)
2954 // choose the position/size for the new window
2956 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
2958 // controlId is menu handle for the top level windows, so set it to 0
2959 // unless we're creating a child window
2960 int controlId
= style
& WS_CHILD
? GetId() : 0;
2962 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
2963 // which is the same but without CS_[HV]REDRAW class styles so using it
2964 // ensures that the window is not fully repainted on each resize
2965 wxString
className(wclass
);
2966 if ( GetWindowStyleFlag() & wxNO_FULL_REPAINT_ON_RESIZE
)
2968 className
+= wxT("NR");
2971 // do create the window
2972 wxWindowCreationHook
hook(this);
2975 if (extendedStyle
== 0)
2977 m_hWnd
= (WXHWND
)::CreateWindow
2980 title
? title
: wxEmptyString
,
2983 (HWND
)MSWGetParent(),
2986 NULL
// no extra data
2992 m_hWnd
= (WXHWND
)::CreateWindowEx
2996 title
? title
: wxEmptyString
,
2999 (HWND
)MSWGetParent(),
3002 NULL
// no extra data
3008 wxLogSysError(_("Can't create window of class %s"), wclass
);
3013 SubclassWin(m_hWnd
);
3015 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3020 // ===========================================================================
3021 // MSW message handlers
3022 // ===========================================================================
3024 // ---------------------------------------------------------------------------
3026 // ---------------------------------------------------------------------------
3030 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3032 #ifndef __WXMICROWIN__
3033 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3034 HWND hWnd
= hdr
->hwndFrom
;
3035 wxWindow
*win
= wxFindWinFromHandle((WXHWND
)hWnd
);
3037 // if the control is one of our windows, let it handle the message itself
3040 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3043 // VZ: why did we do it? normally this is unnecessary and, besides, it
3044 // breaks the message processing for the toolbars because the tooltip
3045 // notifications were being forwarded to the toolbar child controls
3046 // (if it had any) before being passed to the toolbar itself, so in my
3047 // example the tooltip for the combobox was always shown instead of the
3048 // correct button tooltips
3050 // try all our children
3051 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3054 wxWindow
*child
= node
->GetData();
3055 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3060 node
= node
->GetNext();
3064 // by default, handle it ourselves
3065 return MSWOnNotify(idCtrl
, lParam
, result
);
3066 #else // __WXMICROWIN__
3073 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3075 const wxString
& ttip
)
3077 // I don't know why it happens, but the versions of comctl32.dll starting
3078 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3079 // this message is supposed to be sent to Unicode programs only) -- hence
3080 // we need to handle it as well, otherwise no tooltips will be shown in
3083 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
) || ttip
.empty() )
3085 // not a tooltip message or no tooltip to show anyhow
3090 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3093 if ( code
== (WXUINT
) TTN_NEEDTEXTA
)
3095 // we pass just the pointer as we store the string internally anyhow
3096 ttText
->lpszText
= (char *)ttip
.c_str();
3098 else // TTN_NEEDTEXTW
3102 // in Unicode mode this is just what we need
3103 ttText
->lpszText
= (wxChar
*)ttip
.c_str();
3105 MultiByteToWideChar(CP_ACP
, 0, ttip
, ttip
.length()+1,
3106 (wchar_t *)ttText
->szText
,
3107 sizeof(ttText
->szText
) / sizeof(wchar_t));
3108 #endif // Unicode/!Unicode
3114 #endif // wxUSE_TOOLTIPS
3116 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3118 WXLPARAM
* WXUNUSED(result
))
3123 NMHDR
* hdr
= (NMHDR
*)lParam
;
3124 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3130 #endif // wxUSE_TOOLTIPS
3137 // ---------------------------------------------------------------------------
3138 // end session messages
3139 // ---------------------------------------------------------------------------
3141 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3144 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, -1);
3145 event
.SetEventObject(wxTheApp
);
3146 event
.SetCanVeto(TRUE
);
3147 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3149 bool rc
= wxTheApp
->ProcessEvent(event
);
3153 // we may end only if the app didn't veto session closing (double
3155 *mayEnd
= !event
.GetVeto();
3164 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3167 // do nothing if the session isn't ending
3172 if ( (this != wxTheApp
->GetTopWindow()) )
3175 wxCloseEvent
event(wxEVT_END_SESSION
, -1);
3176 event
.SetEventObject(wxTheApp
);
3177 event
.SetCanVeto(FALSE
);
3178 event
.SetLoggingOff( (logOff
== (long)ENDSESSION_LOGOFF
) );
3180 return wxTheApp
->ProcessEvent(event
);
3186 // ---------------------------------------------------------------------------
3187 // window creation/destruction
3188 // ---------------------------------------------------------------------------
3190 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
)
3192 // if we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
3193 // parent as well as otherwise several Win32 functions using
3194 // GetNextDlgTabItem() to iterate over all controls such as
3195 // IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
3196 // all of them iterate over all the controls starting from the focus and
3197 // stop iterating when they get back to the focus but unless all parents
3198 // have WS_EX_CONTROLPARENT bit set, they would never get back to focus
3200 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3202 // there is no need to do anything for the top level windows
3203 const wxWindow
*parent
= GetParent();
3204 while ( parent
&& !parent
->IsTopLevel() )
3206 LONG exStyle
= ::GetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
);
3207 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
3209 // force the parent to have this style
3210 ::SetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
,
3211 exStyle
| WS_EX_CONTROLPARENT
);
3214 parent
= parent
->GetParent();
3219 // TODO: should generate this event from WM_NCCREATE
3220 wxWindowCreateEvent
event((wxWindow
*)this);
3221 (void)GetEventHandler()->ProcessEvent(event
);
3228 bool wxWindowMSW::HandleDestroy()
3232 // delete our drop target if we've got one
3233 #if wxUSE_DRAG_AND_DROP
3234 if ( m_dropTarget
!= NULL
)
3236 m_dropTarget
->Revoke(m_hWnd
);
3238 delete m_dropTarget
;
3239 m_dropTarget
= NULL
;
3241 #endif // wxUSE_DRAG_AND_DROP
3243 // WM_DESTROY handled
3247 // ---------------------------------------------------------------------------
3249 // ---------------------------------------------------------------------------
3251 bool wxWindowMSW::HandleActivate(int state
,
3252 bool WXUNUSED(minimized
),
3253 WXHWND
WXUNUSED(activate
))
3255 wxActivateEvent
event(wxEVT_ACTIVATE
,
3256 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3258 event
.SetEventObject(this);
3260 return GetEventHandler()->ProcessEvent(event
);
3263 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3265 // notify the parent keeping track of focus for the kbd navigation
3266 // purposes that we got it
3267 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3268 (void)GetEventHandler()->ProcessEvent(eventFocus
);
3274 m_caret
->OnSetFocus();
3276 #endif // wxUSE_CARET
3279 // If it's a wxTextCtrl don't send the event as it will be done
3280 // after the control gets to process it from EN_FOCUS handler
3281 if ( wxDynamicCastThis(wxTextCtrl
) )
3285 #endif // wxUSE_TEXTCTRL
3287 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3288 event
.SetEventObject(this);
3290 // wxFindWinFromHandle() may return NULL, it is ok
3291 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3293 return GetEventHandler()->ProcessEvent(event
);
3296 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
3302 m_caret
->OnKillFocus();
3304 #endif // wxUSE_CARET
3307 // If it's a wxTextCtrl don't send the event as it will be done
3308 // after the control gets to process it.
3309 wxTextCtrl
*ctrl
= wxDynamicCastThis(wxTextCtrl
);
3316 // Don't send the event when in the process of being deleted. This can
3317 // only cause problems if the event handler tries to access the object.
3318 if ( m_isBeingDeleted
)
3323 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3324 event
.SetEventObject(this);
3326 // wxFindWinFromHandle() may return NULL, it is ok
3327 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3329 return GetEventHandler()->ProcessEvent(event
);
3332 // ---------------------------------------------------------------------------
3334 // ---------------------------------------------------------------------------
3336 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
3338 wxShowEvent
event(GetId(), show
);
3339 event
.m_eventObject
= this;
3341 return GetEventHandler()->ProcessEvent(event
);
3344 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
3346 wxInitDialogEvent
event(GetId());
3347 event
.m_eventObject
= this;
3349 return GetEventHandler()->ProcessEvent(event
);
3352 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
3354 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
3356 #else // __WXMICROWIN__
3357 HDROP hFilesInfo
= (HDROP
) wParam
;
3359 // Get the total number of files dropped
3360 UINT gwFilesDropped
= ::DragQueryFile
3368 wxString
*files
= new wxString
[gwFilesDropped
];
3369 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
3371 // first get the needed buffer length (+1 for terminating NUL)
3372 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
3374 // and now get the file name
3375 ::DragQueryFile(hFilesInfo
, wIndex
,
3376 wxStringBuffer(files
[wIndex
], len
), len
);
3378 DragFinish (hFilesInfo
);
3380 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
3381 event
.m_eventObject
= this;
3384 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
3385 event
.m_pos
.x
= dropPoint
.x
;
3386 event
.m_pos
.y
= dropPoint
.y
;
3388 return GetEventHandler()->ProcessEvent(event
);
3393 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
3395 int WXUNUSED(mouseMsg
))
3397 #ifndef __WXMICROWIN__
3398 // the logic is as follows:
3399 // -1. don't set cursor for non client area, including but not limited to
3400 // the title bar, scrollbars, &c
3401 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
3402 // 1. if we have the cursor set it unless wxIsBusy()
3403 // 2. if we're a top level window, set some cursor anyhow
3404 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
3406 if ( nHitTest
!= HTCLIENT
)
3411 HCURSOR hcursor
= 0;
3413 // first ask the user code - it may wish to set the cursor in some very
3414 // specific way (for example, depending on the current position)
3416 if ( !::GetCursorPos(&pt
) )
3418 wxLogLastError(wxT("GetCursorPos"));
3423 ScreenToClient(&x
, &y
);
3424 wxSetCursorEvent
event(x
, y
);
3426 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
3427 if ( processedEvtSetCursor
&& event
.HasCursor() )
3429 hcursor
= GetHcursorOf(event
.GetCursor());
3434 bool isBusy
= wxIsBusy();
3436 // the test for processedEvtSetCursor is here to prevent using m_cursor
3437 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3438 // it - this is a way to say that our cursor shouldn't be used for this
3440 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
3442 hcursor
= GetHcursorOf(m_cursor
);
3449 hcursor
= wxGetCurrentBusyCursor();
3451 else if ( !hcursor
)
3453 const wxCursor
*cursor
= wxGetGlobalCursor();
3454 if ( cursor
&& cursor
->Ok() )
3456 hcursor
= GetHcursorOf(*cursor
);
3464 // wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3466 ::SetCursor(hcursor
);
3468 // cursor set, stop here
3471 #endif // __WXMICROWIN__
3473 // pass up the window chain
3477 // ---------------------------------------------------------------------------
3478 // owner drawn stuff
3479 // ---------------------------------------------------------------------------
3481 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
3482 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
3483 #define WXUNUSED_UNLESS_ODRAWN(param) param
3485 #define WXUNUSED_UNLESS_ODRAWN(param)
3489 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
3490 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
3492 #if wxUSE_OWNER_DRAWN
3494 #if wxUSE_MENUS_NATIVE
3495 // is it a menu item?
3496 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
3497 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
3499 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
3501 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
3503 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
3504 // the DC from being released
3505 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
3506 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
3507 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
3508 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
3510 return pMenuItem
->OnDrawItem
3514 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
3515 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
3518 #endif // wxUSE_MENUS_NATIVE
3520 #endif // USE_OWNER_DRAWN
3522 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
3524 #if wxUSE_OWNER_DRAWN
3525 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3526 #else // !wxUSE_OWNER_DRAWN
3527 // we may still have owner-drawn buttons internally because we have to make
3528 // them owner-drawn to support colour change
3529 wxControl
*item
= wxDynamicCast(FindItem(id
), wxButton
);
3530 #endif // USE_OWNER_DRAWN
3534 return item
->MSWOnDraw(itemStruct
);
3537 #endif // wxUSE_CONTROLS
3543 wxWindowMSW::MSWOnMeasureItem(int WXUNUSED_UNLESS_ODRAWN(id
),
3544 WXMEASUREITEMSTRUCT
*
3545 WXUNUSED_UNLESS_ODRAWN(itemStruct
))
3547 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
3548 // is it a menu item?
3549 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
3550 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
3552 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
3554 wxCHECK( pMenuItem
->IsKindOf(CLASSINFO(wxMenuItem
)), FALSE
);
3556 return pMenuItem
->OnMeasureItem(&pMeasureStruct
->itemWidth
,
3557 &pMeasureStruct
->itemHeight
);
3560 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3563 return item
->MSWOnMeasure(itemStruct
);
3565 #endif // wxUSE_OWNER_DRAWN
3570 // ---------------------------------------------------------------------------
3571 // colours and palettes
3572 // ---------------------------------------------------------------------------
3574 bool wxWindowMSW::HandleSysColorChange()
3576 wxSysColourChangedEvent event
;
3577 event
.SetEventObject(this);
3579 (void)GetEventHandler()->ProcessEvent(event
);
3581 // always let the system carry on the default processing to allow the
3582 // native controls to react to the colours update
3586 bool wxWindowMSW::HandleDisplayChange()
3588 wxDisplayChangedEvent event
;
3589 event
.SetEventObject(this);
3591 return GetEventHandler()->ProcessEvent(event
);
3594 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
,
3602 #ifndef __WXMICROWIN__
3603 WXHBRUSH hBrush
= 0;
3608 if ( nCtlColor
== CTLCOLOR_DLG
)
3611 hBrush
= OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
3616 wxControl
*item
= (wxControl
*)FindItemByHWND(pWnd
, TRUE
);
3618 hBrush
= item
->OnCtlColor(pDC
, pWnd
, nCtlColor
, message
, wParam
, lParam
);
3620 #endif // wxUSE_CONTROLS
3626 #else // __WXMICROWIN__
3631 // Define for each class of dialog and control
3632 WXHBRUSH
wxWindowMSW::OnCtlColor(WXHDC
WXUNUSED(hDC
),
3633 WXHWND
WXUNUSED(hWnd
),
3634 WXUINT
WXUNUSED(nCtlColor
),
3635 WXUINT
WXUNUSED(message
),
3636 WXWPARAM
WXUNUSED(wParam
),
3637 WXLPARAM
WXUNUSED(lParam
))
3642 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
3645 // same as below except we don't respond to our own messages
3646 if ( hWndPalChange
!= GetHWND() )
3648 // check to see if we our our parents have a custom palette
3649 wxWindowMSW
*win
= this;
3650 while ( win
&& !win
->HasCustomPalette() )
3652 win
= win
->GetParent();
3655 if ( win
&& win
->HasCustomPalette() )
3657 // realize the palette to see whether redrawing is needed
3658 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
3659 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
3660 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
3662 int result
= ::RealizePalette(hdc
);
3664 // restore the palette (before releasing the DC)
3665 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
3666 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
3667 ::RealizePalette(hdc
);
3668 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
3670 // now check for the need to redraw
3672 InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
3676 #endif // wxUSE_PALETTE
3678 wxPaletteChangedEvent
event(GetId());
3679 event
.SetEventObject(this);
3680 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
3682 return GetEventHandler()->ProcessEvent(event
);
3685 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
3687 wxMouseCaptureChangedEvent
event(GetId(), wxFindWinFromHandle(hWndGainedCapture
));
3688 event
.SetEventObject(this);
3690 return GetEventHandler()->ProcessEvent(event
);
3693 bool wxWindowMSW::HandleQueryNewPalette()
3697 // check to see if we our our parents have a custom palette
3698 wxWindowMSW
*win
= this;
3699 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
3700 if (win
->HasCustomPalette()) {
3701 /* realize the palette to see whether redrawing is needed */
3702 HDC hdc
= GetDC((HWND
) GetHWND());
3703 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
3704 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
3706 int result
= ::RealizePalette(hdc
);
3707 /* restore the palette (before releasing the DC) */
3708 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
3709 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
3710 ::RealizePalette(hdc
);
3711 ::ReleaseDC((HWND
) GetHWND(), hdc
);
3712 /* now check for the need to redraw */
3714 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
3716 #endif // wxUSE_PALETTE
3718 wxQueryNewPaletteEvent
event(GetId());
3719 event
.SetEventObject(this);
3721 return GetEventHandler()->ProcessEvent(event
) && event
.GetPaletteRealized();
3724 // Responds to colour changes: passes event on to children.
3725 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
3727 // the top level window also reset the standard colour map as it might have
3728 // changed (there is no need to do it for the non top level windows as we
3729 // only have to do it once)
3733 gs_hasStdCmap
= FALSE
;
3735 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3738 // Only propagate to non-top-level windows because Windows already
3739 // sends this event to all top-level ones
3740 wxWindow
*win
= node
->GetData();
3741 if ( !win
->IsTopLevel() )
3743 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
3744 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
3745 // the standard controls
3746 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
3749 node
= node
->GetNext();
3752 // update the colours we use if they were not set explicitly by the user:
3753 // this must be done or OnCtlColor() would continue to use the old colours
3756 m_foregroundColour
= wxSystemSettings::
3757 GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
);
3762 m_backgroundColour
= wxSystemSettings::
3763 GetSystemColour(wxSYS_COLOUR_BTNFACE
);
3767 extern wxCOLORMAP
*wxGetStdColourMap()
3769 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
3770 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
3772 if ( !gs_hasStdCmap
)
3774 static bool s_coloursInit
= FALSE
;
3776 if ( !s_coloursInit
)
3778 // When a bitmap is loaded, the RGB values can change (apparently
3779 // because Windows adjusts them to care for the old programs always
3780 // using 0xc0c0c0 while the transparent colour for the new Windows
3781 // versions is different). But we do this adjustment ourselves so
3782 // we want to avoid Windows' "help" and for this we need to have a
3783 // reference bitmap which can tell us what the RGB values change
3785 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
3786 if ( stdColourBitmap
.Ok() )
3788 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
3789 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
3790 _T("forgot to update wxBITMAP_STD_COLOURS!") );
3793 memDC
.SelectObject(stdColourBitmap
);
3796 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
3798 memDC
.GetPixel(i
, 0, &colour
);
3799 s_stdColours
[i
] = wxColourToRGB(colour
);
3802 else // wxBITMAP_STD_COLOURS couldn't be loaded
3804 s_stdColours
[0] = RGB(000,000,000); // black
3805 s_stdColours
[1] = RGB(128,128,128); // dark grey
3806 s_stdColours
[2] = RGB(192,192,192); // light grey
3807 s_stdColours
[3] = RGB(255,255,255); // white
3808 //s_stdColours[4] = RGB(000,000,255); // blue
3809 //s_stdColours[5] = RGB(255,000,255); // magenta
3812 s_coloursInit
= TRUE
;
3815 gs_hasStdCmap
= TRUE
;
3817 // create the colour map
3818 #define INIT_CMAP_ENTRY(col) \
3819 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
3820 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
3822 INIT_CMAP_ENTRY(BTNTEXT
);
3823 INIT_CMAP_ENTRY(BTNSHADOW
);
3824 INIT_CMAP_ENTRY(BTNFACE
);
3825 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
3827 #undef INIT_CMAP_ENTRY
3833 // ---------------------------------------------------------------------------
3835 // ---------------------------------------------------------------------------
3837 bool wxWindowMSW::HandlePaint()
3839 // if (GetExtraStyle() & wxWS_EX_THEMED_BACKGROUND)
3842 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
3844 wxLogLastError(wxT("CreateRectRgn"));
3845 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
3846 wxLogLastError(wxT("GetUpdateRgn"));
3848 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
3850 wxPaintEvent
event(m_windowId
);
3851 event
.SetEventObject(this);
3853 bool processed
= GetEventHandler()->ProcessEvent(event
);
3855 // note that we must generate NC event after the normal one as otherwise
3856 // BeginPaint() will happily overwrite our decorations with the background
3858 wxNcPaintEvent
eventNc(m_windowId
);
3859 eventNc
.SetEventObject(this);
3860 GetEventHandler()->ProcessEvent(eventNc
);
3865 // Can be called from an application's OnPaint handler
3866 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
3868 #ifdef __WXUNIVERSAL__
3871 HDC hDC
= (HDC
) wxPaintDC::FindDCInCache((wxWindow
*) event
.GetEventObject());
3874 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
3879 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
3881 // Prevents flicker when dragging
3882 if ( ::IsIconic(GetHwnd()) )
3886 if (GetParent() && GetParent()->GetExtraStyle() & wxWS_EX_THEMED_BACKGROUND
)
3891 if (GetExtraStyle() & wxWS_EX_THEMED_BACKGROUND
)
3893 if (wxUxThemeEngine::Get())
3895 WXHTHEME hTheme
= wxUxThemeEngine::Get()->m_pfnOpenThemeData(GetHWND(), L
"TAB");
3899 ::GetClientRect((HWND
) GetHWND(), (RECT
*) & rect
);
3900 wxUxThemeEngine::Get()->m_pfnDrawThemeBackground(hTheme
, hdc
, 10 /* TABP_BODY */, 0, &rect
, &rect
);
3901 wxUxThemeEngine::Get()->m_pfnCloseThemeData(hTheme
);
3911 dc
.SetWindow((wxWindow
*)this);
3914 wxEraseEvent
event(m_windowId
, &dc
);
3915 event
.SetEventObject(this);
3916 bool rc
= GetEventHandler()->ProcessEvent(event
);
3920 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
3921 dc
.SelectOldObjects(hdc
);
3926 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
3929 ::GetClientRect(GetHwnd(), &rect
);
3931 COLORREF ref
= PALETTERGB(m_backgroundColour
.Red(),
3932 m_backgroundColour
.Green(),
3933 m_backgroundColour
.Blue());
3934 HBRUSH hBrush
= ::CreateSolidBrush(ref
);
3936 wxLogLastError(wxT("CreateSolidBrush"));
3938 HDC hdc
= (HDC
)event
.GetDC()->GetHDC();
3941 int mode
= ::SetMapMode(hdc
, MM_TEXT
);
3944 ::FillRect(hdc
, &rect
, hBrush
);
3945 ::DeleteObject(hBrush
);
3948 ::SetMapMode(hdc
, mode
);
3952 // ---------------------------------------------------------------------------
3953 // moving and resizing
3954 // ---------------------------------------------------------------------------
3956 bool wxWindowMSW::HandleMinimize()
3958 wxIconizeEvent
event(m_windowId
);
3959 event
.SetEventObject(this);
3961 return GetEventHandler()->ProcessEvent(event
);
3964 bool wxWindowMSW::HandleMaximize()
3966 wxMaximizeEvent
event(m_windowId
);
3967 event
.SetEventObject(this);
3969 return GetEventHandler()->ProcessEvent(event
);
3972 bool wxWindowMSW::HandleMove(int x
, int y
)
3974 wxMoveEvent
event(wxPoint(x
, y
), m_windowId
);
3975 event
.SetEventObject(this);
3977 return GetEventHandler()->ProcessEvent(event
);
3980 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
3982 wxMoveEvent
event(rect
, m_windowId
);
3983 event
.SetEventObject(this);
3985 bool rc
= GetEventHandler()->ProcessEvent(event
);
3987 rect
= event
.GetRect();
3991 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
),
3992 WXUINT
WXUNUSED(flag
))
3994 // don't use w and h parameters as they specify the client size while
3995 // according to the docs EVT_SIZE handler is supposed to receive the total
3997 wxSizeEvent
event(GetSize(), m_windowId
);
3998 event
.SetEventObject(this);
4000 return GetEventHandler()->ProcessEvent(event
);
4003 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
4005 wxSizeEvent
event(rect
, m_windowId
);
4006 event
.SetEventObject(this);
4008 bool rc
= GetEventHandler()->ProcessEvent(event
);
4010 rect
= event
.GetRect();
4014 bool wxWindowMSW::HandleGetMinMaxInfo(void *mmInfo
)
4019 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
4023 int minWidth
= GetMinWidth(),
4024 minHeight
= GetMinHeight(),
4025 maxWidth
= GetMaxWidth(),
4026 maxHeight
= GetMaxHeight();
4028 if ( minWidth
!= -1 )
4030 info
->ptMinTrackSize
.x
= minWidth
;
4034 if ( minHeight
!= -1 )
4036 info
->ptMinTrackSize
.y
= minHeight
;
4040 if ( maxWidth
!= -1 )
4042 info
->ptMaxTrackSize
.x
= maxWidth
;
4046 if ( maxHeight
!= -1 )
4048 info
->ptMaxTrackSize
.y
= maxHeight
;
4056 // ---------------------------------------------------------------------------
4058 // ---------------------------------------------------------------------------
4060 bool wxWindowMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
4062 #if wxUSE_MENUS_NATIVE
4063 if ( !cmd
&& wxCurrentPopupMenu
)
4065 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
4066 wxCurrentPopupMenu
= NULL
;
4068 return popupMenu
->MSWCommand(cmd
, id
);
4070 #endif // wxUSE_MENUS_NATIVE
4072 wxWindow
*win
= NULL
;
4074 // first try to find it from HWND - this works even with the broken
4075 // programs using the same ids for different controls
4078 win
= wxFindWinFromHandle(control
);
4084 // must cast to a signed type before comparing with other ids!
4085 win
= FindItem((signed short)id
);
4090 return win
->MSWCommand(cmd
, id
);
4093 // the messages sent from the in-place edit control used by the treectrl
4094 // for label editing have id == 0, but they should _not_ be treated as menu
4095 // messages (they are EN_XXX ones, in fact) so don't translate anything
4096 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4099 // If no child window, it may be an accelerator, e.g. for a popup menu
4102 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
4103 event
.SetEventObject(this);
4107 return GetEventHandler()->ProcessEvent(event
);
4109 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4112 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4113 // notifications to its parent which we want to reflect back to
4115 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
4116 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
4119 #endif // wxUSE_SPINCTRL
4124 bool wxWindowMSW::HandleSysCommand(WXWPARAM wParam
, WXLPARAM
WXUNUSED(lParam
))
4127 // 4 bits are reserved
4128 switch ( wParam
& 0xFFFFFFF0 )
4131 return HandleMaximize();
4134 return HandleMinimize();
4141 // ---------------------------------------------------------------------------
4143 // ---------------------------------------------------------------------------
4145 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
4149 // our client coords are not quite the same as Windows ones
4150 wxPoint pt
= GetClientAreaOrigin();
4151 event
.m_x
= x
- pt
.x
;
4152 event
.m_y
= y
- pt
.y
;
4154 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
4155 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
4156 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
4157 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
4158 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
4159 // event.m_altDown = (::GetKeyState(VK_MENU) & 0x80000000) != 0;
4160 // Returns different negative values on WinME and WinNT,
4161 // so simply test for negative value.
4162 event
.m_altDown
= ::GetKeyState(VK_MENU
) < 0;
4164 event
.SetTimestamp(s_currentMsg
.time
);
4165 event
.m_eventObject
= this;
4166 event
.SetId(GetId());
4168 #if wxUSE_MOUSEEVENT_HACK
4171 m_lastMouseEvent
= event
.GetEventType();
4172 #endif // wxUSE_MOUSEEVENT_HACK
4175 // Windows doesn't send the mouse events to the static controls (which are
4176 // transparent in the sense that their WM_NCHITTEST handler returns
4177 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4178 // and so we manually check if we don't have a child window under mouse and if
4179 // we do, send the event to it instead of the window Windows had sent WM_XXX
4182 // Notice that this is not done for the mouse move events because this could
4183 // (would?) be too slow, but only for clicks which means that the static texts
4184 // still don't get move, enter nor leave events.
4185 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
) //TW:REQ:Univ
4187 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
4189 // first try to find a non transparent child: this allows us to send events
4190 // to a static text which is inside a static box, for example
4191 POINT pt
= { *x
, *y
};
4192 HWND hwnd
= GetHwndOf(win
),
4196 hwndUnderMouse
= ::ChildWindowFromPoint
4202 hwndUnderMouse
= ::ChildWindowFromPointEx
4212 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
4214 // now try any child window at all
4215 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
4218 // check that we have a child window which is susceptible to receive mouse
4219 // events: for this it must be shown and enabled
4220 if ( hwndUnderMouse
&&
4221 hwndUnderMouse
!= hwnd
&&
4222 ::IsWindowVisible(hwndUnderMouse
) &&
4223 ::IsWindowEnabled(hwndUnderMouse
) )
4225 wxWindow
*winUnderMouse
= wxFindWinFromHandle((WXHWND
)hwndUnderMouse
);
4226 if ( winUnderMouse
)
4228 // translate the mouse coords to the other window coords
4229 win
->ClientToScreen(x
, y
);
4230 winUnderMouse
->ScreenToClient(x
, y
);
4232 win
= winUnderMouse
;
4239 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4241 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4242 // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST
4243 // from the message id and take the value in the table to get wxWin event
4245 static const wxEventType eventsMouse
[] =
4259 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
4260 InitMouseEvent(event
, x
, y
, flags
);
4262 return GetEventHandler()->ProcessEvent(event
);
4265 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
4267 if ( !m_mouseInWindow
)
4269 // it would be wrong to assume that just because we get a mouse move
4270 // event that the mouse is inside the window: although this is usually
4271 // true, it is not if we had captured the mouse, so we need to check
4272 // the mouse coordinates here
4273 if ( !HasCapture() || IsMouseInWindow() )
4275 // Generate an ENTER event
4276 m_mouseInWindow
= TRUE
;
4278 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
4279 InitMouseEvent(event
, x
, y
, flags
);
4281 (void)GetEventHandler()->ProcessEvent(event
);
4285 #if wxUSE_MOUSEEVENT_HACK
4286 // Window gets a click down message followed by a mouse move message even
4287 // if position isn't changed! We want to discard the trailing move event
4288 // if x and y are the same.
4289 if ( (m_lastMouseEvent
== wxEVT_RIGHT_DOWN
||
4290 m_lastMouseEvent
== wxEVT_LEFT_DOWN
||
4291 m_lastMouseEvent
== wxEVT_MIDDLE_DOWN
) &&
4292 (m_lastMouseX
== x
&& m_lastMouseY
== y
) )
4294 m_lastMouseEvent
= wxEVT_MOTION
;
4298 #endif // wxUSE_MOUSEEVENT_HACK
4300 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
4304 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
4306 #if wxUSE_MOUSEWHEEL
4307 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
4308 InitMouseEvent(event
,
4309 GET_X_LPARAM(lParam
),
4310 GET_Y_LPARAM(lParam
),
4312 event
.m_wheelRotation
= (short)HIWORD(wParam
);
4313 event
.m_wheelDelta
= WHEEL_DELTA
;
4315 static int s_linesPerRotation
= -1;
4316 if ( s_linesPerRotation
== -1 )
4318 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
4319 &s_linesPerRotation
, 0))
4321 // this is not supposed to happen
4322 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
4324 // the default is 3, so use it if SystemParametersInfo() failed
4325 s_linesPerRotation
= 3;
4329 event
.m_linesPerAction
= s_linesPerRotation
;
4330 return GetEventHandler()->ProcessEvent(event
);
4341 // ---------------------------------------------------------------------------
4342 // keyboard handling
4343 // ---------------------------------------------------------------------------
4345 // create the key event of the given type for the given key - used by
4346 // HandleChar and HandleKeyDown/Up
4347 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
4350 WXWPARAM wParam
) const
4352 wxKeyEvent
event(evType
);
4353 event
.SetId(GetId());
4354 event
.m_shiftDown
= wxIsShiftDown();
4355 event
.m_controlDown
= wxIsCtrlDown();
4356 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
4358 event
.m_eventObject
= (wxWindow
*)this; // const_cast
4359 event
.m_keyCode
= id
;
4360 event
.m_rawCode
= (wxUint32
) wParam
;
4361 event
.m_rawFlags
= (wxUint32
) lParam
;
4362 event
.SetTimestamp(s_currentMsg
.time
);
4364 // translate the position to client coords
4368 GetWindowRect(GetHwnd(),&rect
);
4378 // isASCII is TRUE only when we're called from WM_CHAR handler and not from
4380 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
4385 // If 1 -> 26, translate to either special keycode or just set
4386 // ctrlDown. IOW, Ctrl-C should result in keycode == 3 and
4387 // ControlDown() == TRUE.
4389 if ( (id
> 0) && (id
< 27) )
4411 else // we're called from WM_KEYDOWN
4413 id
= wxCharCodeMSWToWX(wParam
);
4416 // it's ASCII and will be processed here only when called from
4417 // WM_CHAR (i.e. when isASCII = TRUE), don't process it now
4422 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
4424 // the alphanumeric keys produced by pressing AltGr+something on European
4425 // keyboards have both Ctrl and Alt modifiers which may confuse the user
4426 // code as, normally, keys with Ctrl and/or Alt don't result in anything
4427 // alphanumeric, so pretend that there are no modifiers at all (the
4428 // KEY_DOWN event would still have the correct modifiers if they're really
4430 if ( event
.m_controlDown
&& event
.m_altDown
&&
4431 (id
>= 32 && id
< 256) )
4433 event
.m_controlDown
=
4434 event
.m_altDown
= FALSE
;
4437 return GetEventHandler()->ProcessEvent(event
);
4440 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
4442 int id
= wxCharCodeMSWToWX(wParam
);
4446 // normal ASCII char
4450 if ( id
!= -1 ) // VZ: does this ever happen (FIXME)?
4452 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
4453 if ( GetEventHandler()->ProcessEvent(event
) )
4462 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
4464 int id
= wxCharCodeMSWToWX(wParam
);
4468 // normal ASCII char
4472 if ( id
!= -1 ) // VZ: does this ever happen (FIXME)?
4474 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
4475 if ( GetEventHandler()->ProcessEvent(event
) )
4482 int wxWindowMSW::HandleMenuChar(int chAccel
, WXLPARAM lParam
)
4484 // FIXME: implement GetMenuItemCount for WinCE, possibly
4485 // in terms of GetMenuItemInfo
4487 const HMENU hmenu
= (HMENU
)lParam
;
4491 mii
.cbSize
= sizeof(MENUITEMINFO
);
4492 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
4494 // find if we have this letter in any owner drawn item
4495 const int count
= ::GetMenuItemCount(hmenu
);
4496 for ( int i
= 0; i
< count
; i
++ )
4498 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
4500 if ( mii
.fType
== MFT_OWNERDRAW
)
4502 // dwItemData member of the MENUITEMINFO is a
4503 // pointer to the associated wxMenuItem -- see the
4504 // menu creation code
4505 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
4507 const wxChar
*p
= wxStrchr(item
->GetText(), _T('&'));
4510 if ( *p
== _T('&') )
4512 // this is not the accel char, find the real one
4513 p
= wxStrchr(p
+ 1, _T('&'));
4515 else // got the accel char
4517 // FIXME-UNICODE: this comparison doesn't risk to work
4518 // for non ASCII accelerator characters I'm afraid, but
4520 if ( wxToupper(*p
) == chAccel
)
4526 // this one doesn't match
4533 else // failed to get the menu text?
4535 // it's not fatal, so don't show error, but still log
4537 wxLogLastError(_T("GetMenuItemInfo"));
4544 // ---------------------------------------------------------------------------
4546 // ---------------------------------------------------------------------------
4548 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4552 if ( flags
& JOY_BUTTON1CHG
)
4553 change
= wxJOY_BUTTON1
;
4554 if ( flags
& JOY_BUTTON2CHG
)
4555 change
= wxJOY_BUTTON2
;
4556 if ( flags
& JOY_BUTTON3CHG
)
4557 change
= wxJOY_BUTTON3
;
4558 if ( flags
& JOY_BUTTON4CHG
)
4559 change
= wxJOY_BUTTON4
;
4562 if ( flags
& JOY_BUTTON1
)
4563 buttons
|= wxJOY_BUTTON1
;
4564 if ( flags
& JOY_BUTTON2
)
4565 buttons
|= wxJOY_BUTTON2
;
4566 if ( flags
& JOY_BUTTON3
)
4567 buttons
|= wxJOY_BUTTON3
;
4568 if ( flags
& JOY_BUTTON4
)
4569 buttons
|= wxJOY_BUTTON4
;
4571 // the event ids aren't consecutive so we can't use table based lookup
4573 wxEventType eventType
;
4578 eventType
= wxEVT_JOY_MOVE
;
4583 eventType
= wxEVT_JOY_MOVE
;
4588 eventType
= wxEVT_JOY_ZMOVE
;
4593 eventType
= wxEVT_JOY_ZMOVE
;
4596 case MM_JOY1BUTTONDOWN
:
4598 eventType
= wxEVT_JOY_BUTTON_DOWN
;
4601 case MM_JOY2BUTTONDOWN
:
4603 eventType
= wxEVT_JOY_BUTTON_DOWN
;
4606 case MM_JOY1BUTTONUP
:
4608 eventType
= wxEVT_JOY_BUTTON_UP
;
4611 case MM_JOY2BUTTONUP
:
4613 eventType
= wxEVT_JOY_BUTTON_UP
;
4617 wxFAIL_MSG(wxT("no such joystick event"));
4622 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
4623 event
.SetPosition(wxPoint(x
, y
));
4624 event
.SetEventObject(this);
4626 return GetEventHandler()->ProcessEvent(event
);
4632 // ---------------------------------------------------------------------------
4634 // ---------------------------------------------------------------------------
4636 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
4637 WXWORD pos
, WXHWND control
)
4641 wxWindow
*child
= wxFindWinFromHandle(control
);
4643 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
4646 wxScrollWinEvent event
;
4647 event
.SetPosition(pos
);
4648 event
.SetOrientation(orientation
);
4649 event
.m_eventObject
= this;
4654 event
.m_eventType
= wxEVT_SCROLLWIN_TOP
;
4658 event
.m_eventType
= wxEVT_SCROLLWIN_BOTTOM
;
4662 event
.m_eventType
= wxEVT_SCROLLWIN_LINEUP
;
4666 event
.m_eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
4670 event
.m_eventType
= wxEVT_SCROLLWIN_PAGEUP
;
4674 event
.m_eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
4677 case SB_THUMBPOSITION
:
4679 // under Win32, the scrollbar range and position are 32 bit integers,
4680 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
4681 // explicitly query the scrollbar for the correct position (this must
4682 // be done only for these two SB_ events as they are the only one
4683 // carrying the scrollbar position)
4685 WinStruct
<SCROLLINFO
> scrollInfo
;
4686 scrollInfo
.fMask
= SIF_TRACKPOS
;
4688 if ( !::GetScrollInfo(GetHwnd(),
4689 orientation
== wxHORIZONTAL
? SB_HORZ
4693 // Not neccessarily an error, if there are no scrollbars yet.
4694 // wxLogLastError(_T("GetScrollInfo"));
4697 event
.SetPosition(scrollInfo
.nTrackPos
);
4700 event
.m_eventType
= wParam
== SB_THUMBPOSITION
4701 ? wxEVT_SCROLLWIN_THUMBRELEASE
4702 : wxEVT_SCROLLWIN_THUMBTRACK
;
4709 return GetEventHandler()->ProcessEvent(event
);
4712 // ===========================================================================
4714 // ===========================================================================
4716 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
*the_font
)
4719 HDC dc
= ::GetDC((HWND
) wnd
);
4724 // the_font->UseResource();
4725 // the_font->RealizeResource();
4726 fnt
= (HFONT
)((wxFont
*)the_font
)->GetResourceHandle(); // const_cast
4728 was
= (HFONT
) SelectObject(dc
,fnt
);
4730 GetTextMetrics(dc
, &tm
);
4731 if ( the_font
&& fnt
&& was
)
4733 SelectObject(dc
,was
);
4735 ReleaseDC((HWND
)wnd
, dc
);
4738 *x
= tm
.tmAveCharWidth
;
4740 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
4743 // the_font->ReleaseResource();
4746 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
4747 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
4748 int wxCharCodeMSWToWX(int keySym
)
4753 case VK_CANCEL
: id
= WXK_CANCEL
; break;
4754 case VK_BACK
: id
= WXK_BACK
; break;
4755 case VK_TAB
: id
= WXK_TAB
; break;
4756 case VK_CLEAR
: id
= WXK_CLEAR
; break;
4757 case VK_RETURN
: id
= WXK_RETURN
; break;
4758 case VK_SHIFT
: id
= WXK_SHIFT
; break;
4759 case VK_CONTROL
: id
= WXK_CONTROL
; break;
4760 case VK_MENU
: id
= WXK_MENU
; break;
4761 case VK_PAUSE
: id
= WXK_PAUSE
; break;
4762 case VK_CAPITAL
: id
= WXK_CAPITAL
; break;
4763 case VK_SPACE
: id
= WXK_SPACE
; break;
4764 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
4765 case VK_PRIOR
: id
= WXK_PRIOR
; break;
4766 case VK_NEXT
: id
= WXK_NEXT
; break;
4767 case VK_END
: id
= WXK_END
; break;
4768 case VK_HOME
: id
= WXK_HOME
; break;
4769 case VK_LEFT
: id
= WXK_LEFT
; break;
4770 case VK_UP
: id
= WXK_UP
; break;
4771 case VK_RIGHT
: id
= WXK_RIGHT
; break;
4772 case VK_DOWN
: id
= WXK_DOWN
; break;
4773 case VK_SELECT
: id
= WXK_SELECT
; break;
4774 case VK_PRINT
: id
= WXK_PRINT
; break;
4775 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
4776 case VK_INSERT
: id
= WXK_INSERT
; break;
4777 case VK_DELETE
: id
= WXK_DELETE
; break;
4778 case VK_HELP
: id
= WXK_HELP
; break;
4779 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
4780 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
4781 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
4782 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
4783 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
4784 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
4785 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
4786 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
4787 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
4788 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
4789 case VK_MULTIPLY
: id
= WXK_NUMPAD_MULTIPLY
; break;
4790 case VK_ADD
: id
= WXK_NUMPAD_ADD
; break;
4791 case VK_SUBTRACT
: id
= WXK_NUMPAD_SUBTRACT
; break;
4792 case VK_DECIMAL
: id
= WXK_NUMPAD_DECIMAL
; break;
4793 case VK_DIVIDE
: id
= WXK_NUMPAD_DIVIDE
; break;
4794 case VK_F1
: id
= WXK_F1
; break;
4795 case VK_F2
: id
= WXK_F2
; break;
4796 case VK_F3
: id
= WXK_F3
; break;
4797 case VK_F4
: id
= WXK_F4
; break;
4798 case VK_F5
: id
= WXK_F5
; break;
4799 case VK_F6
: id
= WXK_F6
; break;
4800 case VK_F7
: id
= WXK_F7
; break;
4801 case VK_F8
: id
= WXK_F8
; break;
4802 case VK_F9
: id
= WXK_F9
; break;
4803 case VK_F10
: id
= WXK_F10
; break;
4804 case VK_F11
: id
= WXK_F11
; break;
4805 case VK_F12
: id
= WXK_F12
; break;
4806 case VK_F13
: id
= WXK_F13
; break;
4807 case VK_F14
: id
= WXK_F14
; break;
4808 case VK_F15
: id
= WXK_F15
; break;
4809 case VK_F16
: id
= WXK_F16
; break;
4810 case VK_F17
: id
= WXK_F17
; break;
4811 case VK_F18
: id
= WXK_F18
; break;
4812 case VK_F19
: id
= WXK_F19
; break;
4813 case VK_F20
: id
= WXK_F20
; break;
4814 case VK_F21
: id
= WXK_F21
; break;
4815 case VK_F22
: id
= WXK_F22
; break;
4816 case VK_F23
: id
= WXK_F23
; break;
4817 case VK_F24
: id
= WXK_F24
; break;
4818 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
4819 case VK_SCROLL
: id
= WXK_SCROLL
; break;
4821 case VK_OEM_1
: id
= ';'; break;
4822 case VK_OEM_PLUS
: id
= '+'; break;
4823 case VK_OEM_COMMA
: id
= ','; break;
4824 case VK_OEM_MINUS
: id
= '-'; break;
4825 case VK_OEM_PERIOD
: id
= '.'; break;
4826 case VK_OEM_2
: id
= '/'; break;
4827 case VK_OEM_3
: id
= '~'; break;
4828 case VK_OEM_4
: id
= '['; break;
4829 case VK_OEM_5
: id
= '\\'; break;
4830 case VK_OEM_6
: id
= ']'; break;
4831 case VK_OEM_7
: id
= '\''; break;
4834 case VK_LWIN
: id
= WXK_WINDOWS_LEFT
; break;
4835 case VK_RWIN
: id
= WXK_WINDOWS_RIGHT
; break;
4836 case VK_APPS
: id
= WXK_WINDOWS_MENU
; break;
4837 #endif // VK_APPS defined
4846 int wxCharCodeWXToMSW(int id
, bool *isVirtual
)
4852 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
4853 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
4854 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
4855 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
4856 case WXK_MENU
: keySym
= VK_MENU
; break;
4857 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
4858 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
4859 case WXK_NEXT
: keySym
= VK_NEXT
; break;
4860 case WXK_END
: keySym
= VK_END
; break;
4861 case WXK_HOME
: keySym
= VK_HOME
; break;
4862 case WXK_LEFT
: keySym
= VK_LEFT
; break;
4863 case WXK_UP
: keySym
= VK_UP
; break;
4864 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
4865 case WXK_DOWN
: keySym
= VK_DOWN
; break;
4866 case WXK_SELECT
: keySym
= VK_SELECT
; break;
4867 case WXK_PRINT
: keySym
= VK_PRINT
; break;
4868 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
4869 case WXK_INSERT
: keySym
= VK_INSERT
; break;
4870 case WXK_DELETE
: keySym
= VK_DELETE
; break;
4871 case WXK_HELP
: keySym
= VK_HELP
; break;
4872 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
4873 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
4874 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
4875 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
4876 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
4877 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
4878 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
4879 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
4880 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
4881 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
4882 case WXK_NUMPAD_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
4883 case WXK_NUMPAD_ADD
: keySym
= VK_ADD
; break;
4884 case WXK_NUMPAD_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
4885 case WXK_NUMPAD_DECIMAL
: keySym
= VK_DECIMAL
; break;
4886 case WXK_NUMPAD_DIVIDE
: keySym
= VK_DIVIDE
; break;
4887 case WXK_F1
: keySym
= VK_F1
; break;
4888 case WXK_F2
: keySym
= VK_F2
; break;
4889 case WXK_F3
: keySym
= VK_F3
; break;
4890 case WXK_F4
: keySym
= VK_F4
; break;
4891 case WXK_F5
: keySym
= VK_F5
; break;
4892 case WXK_F6
: keySym
= VK_F6
; break;
4893 case WXK_F7
: keySym
= VK_F7
; break;
4894 case WXK_F8
: keySym
= VK_F8
; break;
4895 case WXK_F9
: keySym
= VK_F9
; break;
4896 case WXK_F10
: keySym
= VK_F10
; break;
4897 case WXK_F11
: keySym
= VK_F11
; break;
4898 case WXK_F12
: keySym
= VK_F12
; break;
4899 case WXK_F13
: keySym
= VK_F13
; break;
4900 case WXK_F14
: keySym
= VK_F14
; break;
4901 case WXK_F15
: keySym
= VK_F15
; break;
4902 case WXK_F16
: keySym
= VK_F16
; break;
4903 case WXK_F17
: keySym
= VK_F17
; break;
4904 case WXK_F18
: keySym
= VK_F18
; break;
4905 case WXK_F19
: keySym
= VK_F19
; break;
4906 case WXK_F20
: keySym
= VK_F20
; break;
4907 case WXK_F21
: keySym
= VK_F21
; break;
4908 case WXK_F22
: keySym
= VK_F22
; break;
4909 case WXK_F23
: keySym
= VK_F23
; break;
4910 case WXK_F24
: keySym
= VK_F24
; break;
4911 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
4912 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
4923 wxWindow
*wxGetActiveWindow()
4925 HWND hWnd
= GetActiveWindow();
4928 return wxFindWinFromHandle((WXHWND
) hWnd
);
4933 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
4935 HWND hwnd
= (HWND
)hWnd
;
4937 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
4938 // by code in msw/radiobox.cpp), for all the others we just search up the
4940 wxWindow
*win
= (wxWindow
*)NULL
;
4943 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
4947 // native radiobuttons return DLGC_RADIOBUTTON here and for any
4948 // wxWindow class which overrides WM_GETDLGCODE processing to
4949 // do it as well, win would be already non NULL
4950 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
4952 win
= (wxWindow
*)::GetWindowLong(hwnd
, GWL_USERDATA
);
4954 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
4955 #endif // wxUSE_RADIOBOX
4957 // spin control text buddy window should be mapped to spin ctrl
4958 // itself so try it too
4959 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4962 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
4964 #endif // wxUSE_SPINCTRL
4968 while ( hwnd
&& !win
)
4970 // this is a really ugly hack needed to avoid mistakenly returning the
4971 // parent frame wxWindow for the find/replace modeless dialog HWND -
4972 // this, in turn, is needed to call IsDialogMessage() from
4973 // wxApp::ProcessMessage() as for this we must return NULL from here
4975 // FIXME: this is clearly not the best way to do it but I think we'll
4976 // need to change HWND <-> wxWindow code more heavily than I can
4977 // do it now to fix it
4978 #ifndef __WXMICROWIN__
4979 if ( ::GetWindow(hwnd
, GW_OWNER
) )
4981 // it's a dialog box, don't go upwards
4986 hwnd
= ::GetParent(hwnd
);
4987 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
4993 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
4995 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
4996 // in active frames and dialogs, regardless of where the focus is.
4997 static HHOOK wxTheKeyboardHook
= 0;
4998 static FARPROC wxTheKeyboardHookProc
= 0;
4999 int APIENTRY _EXPORT
5000 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
5002 void wxSetKeyboardHook(bool doIt
)
5006 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
5007 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
5009 GetCurrentThreadId()
5010 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
5015 UnhookWindowsHookEx(wxTheKeyboardHook
);
5019 int APIENTRY _EXPORT
5020 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
5022 DWORD hiWord
= HIWORD(lParam
);
5023 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
5025 int id
= wxCharCodeMSWToWX(wParam
);
5028 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
5029 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
5030 event
.m_altDown
= TRUE
;
5032 event
.m_eventObject
= NULL
;
5033 event
.m_keyCode
= id
;
5034 event
.m_shiftDown
= wxIsShiftDown();
5035 event
.m_controlDown
= wxIsCtrlDown();
5036 event
.SetTimestamp(s_currentMsg
.time
);
5038 wxWindow
*win
= wxGetActiveWindow();
5039 wxEvtHandler
*handler
;
5042 handler
= win
->GetEventHandler();
5043 event
.SetId(win
->GetId());
5051 if ( handler
&& handler
->ProcessEvent(event
) )
5059 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
5062 #endif // !__WXMICROWIN__
5065 const char *wxGetMessageName(int message
)
5069 case 0x0000: return "WM_NULL";
5070 case 0x0001: return "WM_CREATE";
5071 case 0x0002: return "WM_DESTROY";
5072 case 0x0003: return "WM_MOVE";
5073 case 0x0005: return "WM_SIZE";
5074 case 0x0006: return "WM_ACTIVATE";
5075 case 0x0007: return "WM_SETFOCUS";
5076 case 0x0008: return "WM_KILLFOCUS";
5077 case 0x000A: return "WM_ENABLE";
5078 case 0x000B: return "WM_SETREDRAW";
5079 case 0x000C: return "WM_SETTEXT";
5080 case 0x000D: return "WM_GETTEXT";
5081 case 0x000E: return "WM_GETTEXTLENGTH";
5082 case 0x000F: return "WM_PAINT";
5083 case 0x0010: return "WM_CLOSE";
5084 case 0x0011: return "WM_QUERYENDSESSION";
5085 case 0x0012: return "WM_QUIT";
5086 case 0x0013: return "WM_QUERYOPEN";
5087 case 0x0014: return "WM_ERASEBKGND";
5088 case 0x0015: return "WM_SYSCOLORCHANGE";
5089 case 0x0016: return "WM_ENDSESSION";
5090 case 0x0017: return "WM_SYSTEMERROR";
5091 case 0x0018: return "WM_SHOWWINDOW";
5092 case 0x0019: return "WM_CTLCOLOR";
5093 case 0x001A: return "WM_WININICHANGE";
5094 case 0x001B: return "WM_DEVMODECHANGE";
5095 case 0x001C: return "WM_ACTIVATEAPP";
5096 case 0x001D: return "WM_FONTCHANGE";
5097 case 0x001E: return "WM_TIMECHANGE";
5098 case 0x001F: return "WM_CANCELMODE";
5099 case 0x0020: return "WM_SETCURSOR";
5100 case 0x0021: return "WM_MOUSEACTIVATE";
5101 case 0x0022: return "WM_CHILDACTIVATE";
5102 case 0x0023: return "WM_QUEUESYNC";
5103 case 0x0024: return "WM_GETMINMAXINFO";
5104 case 0x0026: return "WM_PAINTICON";
5105 case 0x0027: return "WM_ICONERASEBKGND";
5106 case 0x0028: return "WM_NEXTDLGCTL";
5107 case 0x002A: return "WM_SPOOLERSTATUS";
5108 case 0x002B: return "WM_DRAWITEM";
5109 case 0x002C: return "WM_MEASUREITEM";
5110 case 0x002D: return "WM_DELETEITEM";
5111 case 0x002E: return "WM_VKEYTOITEM";
5112 case 0x002F: return "WM_CHARTOITEM";
5113 case 0x0030: return "WM_SETFONT";
5114 case 0x0031: return "WM_GETFONT";
5115 case 0x0037: return "WM_QUERYDRAGICON";
5116 case 0x0039: return "WM_COMPAREITEM";
5117 case 0x0041: return "WM_COMPACTING";
5118 case 0x0044: return "WM_COMMNOTIFY";
5119 case 0x0046: return "WM_WINDOWPOSCHANGING";
5120 case 0x0047: return "WM_WINDOWPOSCHANGED";
5121 case 0x0048: return "WM_POWER";
5123 case 0x004A: return "WM_COPYDATA";
5124 case 0x004B: return "WM_CANCELJOURNAL";
5125 case 0x004E: return "WM_NOTIFY";
5126 case 0x0050: return "WM_INPUTLANGCHANGEREQUEST";
5127 case 0x0051: return "WM_INPUTLANGCHANGE";
5128 case 0x0052: return "WM_TCARD";
5129 case 0x0053: return "WM_HELP";
5130 case 0x0054: return "WM_USERCHANGED";
5131 case 0x0055: return "WM_NOTIFYFORMAT";
5132 case 0x007B: return "WM_CONTEXTMENU";
5133 case 0x007C: return "WM_STYLECHANGING";
5134 case 0x007D: return "WM_STYLECHANGED";
5135 case 0x007E: return "WM_DISPLAYCHANGE";
5136 case 0x007F: return "WM_GETICON";
5137 case 0x0080: return "WM_SETICON";
5139 case 0x0081: return "WM_NCCREATE";
5140 case 0x0082: return "WM_NCDESTROY";
5141 case 0x0083: return "WM_NCCALCSIZE";
5142 case 0x0084: return "WM_NCHITTEST";
5143 case 0x0085: return "WM_NCPAINT";
5144 case 0x0086: return "WM_NCACTIVATE";
5145 case 0x0087: return "WM_GETDLGCODE";
5146 case 0x00A0: return "WM_NCMOUSEMOVE";
5147 case 0x00A1: return "WM_NCLBUTTONDOWN";
5148 case 0x00A2: return "WM_NCLBUTTONUP";
5149 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
5150 case 0x00A4: return "WM_NCRBUTTONDOWN";
5151 case 0x00A5: return "WM_NCRBUTTONUP";
5152 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
5153 case 0x00A7: return "WM_NCMBUTTONDOWN";
5154 case 0x00A8: return "WM_NCMBUTTONUP";
5155 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
5156 case 0x0100: return "WM_KEYDOWN";
5157 case 0x0101: return "WM_KEYUP";
5158 case 0x0102: return "WM_CHAR";
5159 case 0x0103: return "WM_DEADCHAR";
5160 case 0x0104: return "WM_SYSKEYDOWN";
5161 case 0x0105: return "WM_SYSKEYUP";
5162 case 0x0106: return "WM_SYSCHAR";
5163 case 0x0107: return "WM_SYSDEADCHAR";
5164 case 0x0108: return "WM_KEYLAST";
5166 case 0x010D: return "WM_IME_STARTCOMPOSITION";
5167 case 0x010E: return "WM_IME_ENDCOMPOSITION";
5168 case 0x010F: return "WM_IME_COMPOSITION";
5170 case 0x0110: return "WM_INITDIALOG";
5171 case 0x0111: return "WM_COMMAND";
5172 case 0x0112: return "WM_SYSCOMMAND";
5173 case 0x0113: return "WM_TIMER";
5174 case 0x0114: return "WM_HSCROLL";
5175 case 0x0115: return "WM_VSCROLL";
5176 case 0x0116: return "WM_INITMENU";
5177 case 0x0117: return "WM_INITMENUPOPUP";
5178 case 0x011F: return "WM_MENUSELECT";
5179 case 0x0120: return "WM_MENUCHAR";
5180 case 0x0121: return "WM_ENTERIDLE";
5181 case 0x0200: return "WM_MOUSEMOVE";
5182 case 0x0201: return "WM_LBUTTONDOWN";
5183 case 0x0202: return "WM_LBUTTONUP";
5184 case 0x0203: return "WM_LBUTTONDBLCLK";
5185 case 0x0204: return "WM_RBUTTONDOWN";
5186 case 0x0205: return "WM_RBUTTONUP";
5187 case 0x0206: return "WM_RBUTTONDBLCLK";
5188 case 0x0207: return "WM_MBUTTONDOWN";
5189 case 0x0208: return "WM_MBUTTONUP";
5190 case 0x0209: return "WM_MBUTTONDBLCLK";
5191 case 0x020A: return "WM_MOUSEWHEEL";
5192 case 0x0210: return "WM_PARENTNOTIFY";
5193 case 0x0211: return "WM_ENTERMENULOOP";
5194 case 0x0212: return "WM_EXITMENULOOP";
5196 case 0x0213: return "WM_NEXTMENU";
5197 case 0x0214: return "WM_SIZING";
5198 case 0x0215: return "WM_CAPTURECHANGED";
5199 case 0x0216: return "WM_MOVING";
5200 case 0x0218: return "WM_POWERBROADCAST";
5201 case 0x0219: return "WM_DEVICECHANGE";
5203 case 0x0220: return "WM_MDICREATE";
5204 case 0x0221: return "WM_MDIDESTROY";
5205 case 0x0222: return "WM_MDIACTIVATE";
5206 case 0x0223: return "WM_MDIRESTORE";
5207 case 0x0224: return "WM_MDINEXT";
5208 case 0x0225: return "WM_MDIMAXIMIZE";
5209 case 0x0226: return "WM_MDITILE";
5210 case 0x0227: return "WM_MDICASCADE";
5211 case 0x0228: return "WM_MDIICONARRANGE";
5212 case 0x0229: return "WM_MDIGETACTIVE";
5213 case 0x0230: return "WM_MDISETMENU";
5214 case 0x0233: return "WM_DROPFILES";
5216 case 0x0281: return "WM_IME_SETCONTEXT";
5217 case 0x0282: return "WM_IME_NOTIFY";
5218 case 0x0283: return "WM_IME_CONTROL";
5219 case 0x0284: return "WM_IME_COMPOSITIONFULL";
5220 case 0x0285: return "WM_IME_SELECT";
5221 case 0x0286: return "WM_IME_CHAR";
5222 case 0x0290: return "WM_IME_KEYDOWN";
5223 case 0x0291: return "WM_IME_KEYUP";
5225 case 0x0300: return "WM_CUT";
5226 case 0x0301: return "WM_COPY";
5227 case 0x0302: return "WM_PASTE";
5228 case 0x0303: return "WM_CLEAR";
5229 case 0x0304: return "WM_UNDO";
5230 case 0x0305: return "WM_RENDERFORMAT";
5231 case 0x0306: return "WM_RENDERALLFORMATS";
5232 case 0x0307: return "WM_DESTROYCLIPBOARD";
5233 case 0x0308: return "WM_DRAWCLIPBOARD";
5234 case 0x0309: return "WM_PAINTCLIPBOARD";
5235 case 0x030A: return "WM_VSCROLLCLIPBOARD";
5236 case 0x030B: return "WM_SIZECLIPBOARD";
5237 case 0x030C: return "WM_ASKCBFORMATNAME";
5238 case 0x030D: return "WM_CHANGECBCHAIN";
5239 case 0x030E: return "WM_HSCROLLCLIPBOARD";
5240 case 0x030F: return "WM_QUERYNEWPALETTE";
5241 case 0x0310: return "WM_PALETTEISCHANGING";
5242 case 0x0311: return "WM_PALETTECHANGED";
5244 case 0x0312: return "WM_HOTKEY";
5247 // common controls messages - although they're not strictly speaking
5248 // standard, it's nice to decode them nevertheless
5251 case 0x1000 + 0: return "LVM_GETBKCOLOR";
5252 case 0x1000 + 1: return "LVM_SETBKCOLOR";
5253 case 0x1000 + 2: return "LVM_GETIMAGELIST";
5254 case 0x1000 + 3: return "LVM_SETIMAGELIST";
5255 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
5256 case 0x1000 + 5: return "LVM_GETITEMA";
5257 case 0x1000 + 75: return "LVM_GETITEMW";
5258 case 0x1000 + 6: return "LVM_SETITEMA";
5259 case 0x1000 + 76: return "LVM_SETITEMW";
5260 case 0x1000 + 7: return "LVM_INSERTITEMA";
5261 case 0x1000 + 77: return "LVM_INSERTITEMW";
5262 case 0x1000 + 8: return "LVM_DELETEITEM";
5263 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
5264 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
5265 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
5266 case 0x1000 + 12: return "LVM_GETNEXTITEM";
5267 case 0x1000 + 13: return "LVM_FINDITEMA";
5268 case 0x1000 + 83: return "LVM_FINDITEMW";
5269 case 0x1000 + 14: return "LVM_GETITEMRECT";
5270 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
5271 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
5272 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
5273 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
5274 case 0x1000 + 18: return "LVM_HITTEST";
5275 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
5276 case 0x1000 + 20: return "LVM_SCROLL";
5277 case 0x1000 + 21: return "LVM_REDRAWITEMS";
5278 case 0x1000 + 22: return "LVM_ARRANGE";
5279 case 0x1000 + 23: return "LVM_EDITLABELA";
5280 case 0x1000 + 118: return "LVM_EDITLABELW";
5281 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
5282 case 0x1000 + 25: return "LVM_GETCOLUMNA";
5283 case 0x1000 + 95: return "LVM_GETCOLUMNW";
5284 case 0x1000 + 26: return "LVM_SETCOLUMNA";
5285 case 0x1000 + 96: return "LVM_SETCOLUMNW";
5286 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
5287 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
5288 case 0x1000 + 28: return "LVM_DELETECOLUMN";
5289 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
5290 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
5291 case 0x1000 + 31: return "LVM_GETHEADER";
5292 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
5293 case 0x1000 + 34: return "LVM_GETVIEWRECT";
5294 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
5295 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
5296 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
5297 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
5298 case 0x1000 + 39: return "LVM_GETTOPINDEX";
5299 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
5300 case 0x1000 + 41: return "LVM_GETORIGIN";
5301 case 0x1000 + 42: return "LVM_UPDATE";
5302 case 0x1000 + 43: return "LVM_SETITEMSTATE";
5303 case 0x1000 + 44: return "LVM_GETITEMSTATE";
5304 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
5305 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
5306 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
5307 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
5308 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
5309 case 0x1000 + 48: return "LVM_SORTITEMS";
5310 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
5311 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
5312 case 0x1000 + 51: return "LVM_GETITEMSPACING";
5313 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
5314 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
5315 case 0x1000 + 53: return "LVM_SETICONSPACING";
5316 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
5317 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
5318 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
5319 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
5320 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
5321 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
5322 case 0x1000 + 60: return "LVM_SETHOTITEM";
5323 case 0x1000 + 61: return "LVM_GETHOTITEM";
5324 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
5325 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
5326 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
5327 case 0x1000 + 65: return "LVM_SETWORKAREA";
5330 case 0x1100 + 0: return "TVM_INSERTITEMA";
5331 case 0x1100 + 50: return "TVM_INSERTITEMW";
5332 case 0x1100 + 1: return "TVM_DELETEITEM";
5333 case 0x1100 + 2: return "TVM_EXPAND";
5334 case 0x1100 + 4: return "TVM_GETITEMRECT";
5335 case 0x1100 + 5: return "TVM_GETCOUNT";
5336 case 0x1100 + 6: return "TVM_GETINDENT";
5337 case 0x1100 + 7: return "TVM_SETINDENT";
5338 case 0x1100 + 8: return "TVM_GETIMAGELIST";
5339 case 0x1100 + 9: return "TVM_SETIMAGELIST";
5340 case 0x1100 + 10: return "TVM_GETNEXTITEM";
5341 case 0x1100 + 11: return "TVM_SELECTITEM";
5342 case 0x1100 + 12: return "TVM_GETITEMA";
5343 case 0x1100 + 62: return "TVM_GETITEMW";
5344 case 0x1100 + 13: return "TVM_SETITEMA";
5345 case 0x1100 + 63: return "TVM_SETITEMW";
5346 case 0x1100 + 14: return "TVM_EDITLABELA";
5347 case 0x1100 + 65: return "TVM_EDITLABELW";
5348 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
5349 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
5350 case 0x1100 + 17: return "TVM_HITTEST";
5351 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
5352 case 0x1100 + 19: return "TVM_SORTCHILDREN";
5353 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
5354 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
5355 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
5356 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
5357 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
5358 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
5359 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
5362 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
5363 case 0x1200 + 1: return "HDM_INSERTITEMA";
5364 case 0x1200 + 10: return "HDM_INSERTITEMW";
5365 case 0x1200 + 2: return "HDM_DELETEITEM";
5366 case 0x1200 + 3: return "HDM_GETITEMA";
5367 case 0x1200 + 11: return "HDM_GETITEMW";
5368 case 0x1200 + 4: return "HDM_SETITEMA";
5369 case 0x1200 + 12: return "HDM_SETITEMW";
5370 case 0x1200 + 5: return "HDM_LAYOUT";
5371 case 0x1200 + 6: return "HDM_HITTEST";
5372 case 0x1200 + 7: return "HDM_GETITEMRECT";
5373 case 0x1200 + 8: return "HDM_SETIMAGELIST";
5374 case 0x1200 + 9: return "HDM_GETIMAGELIST";
5375 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
5376 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
5377 case 0x1200 + 17: return "HDM_GETORDERARRAY";
5378 case 0x1200 + 18: return "HDM_SETORDERARRAY";
5379 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
5382 case 0x1300 + 2: return "TCM_GETIMAGELIST";
5383 case 0x1300 + 3: return "TCM_SETIMAGELIST";
5384 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
5385 case 0x1300 + 5: return "TCM_GETITEMA";
5386 case 0x1300 + 60: return "TCM_GETITEMW";
5387 case 0x1300 + 6: return "TCM_SETITEMA";
5388 case 0x1300 + 61: return "TCM_SETITEMW";
5389 case 0x1300 + 7: return "TCM_INSERTITEMA";
5390 case 0x1300 + 62: return "TCM_INSERTITEMW";
5391 case 0x1300 + 8: return "TCM_DELETEITEM";
5392 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
5393 case 0x1300 + 10: return "TCM_GETITEMRECT";
5394 case 0x1300 + 11: return "TCM_GETCURSEL";
5395 case 0x1300 + 12: return "TCM_SETCURSEL";
5396 case 0x1300 + 13: return "TCM_HITTEST";
5397 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
5398 case 0x1300 + 40: return "TCM_ADJUSTRECT";
5399 case 0x1300 + 41: return "TCM_SETITEMSIZE";
5400 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
5401 case 0x1300 + 43: return "TCM_SETPADDING";
5402 case 0x1300 + 44: return "TCM_GETROWCOUNT";
5403 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
5404 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
5405 case 0x1300 + 47: return "TCM_GETCURFOCUS";
5406 case 0x1300 + 48: return "TCM_SETCURFOCUS";
5407 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
5408 case 0x1300 + 50: return "TCM_DESELECTALL";
5411 case WM_USER
+1: return "TB_ENABLEBUTTON";
5412 case WM_USER
+2: return "TB_CHECKBUTTON";
5413 case WM_USER
+3: return "TB_PRESSBUTTON";
5414 case WM_USER
+4: return "TB_HIDEBUTTON";
5415 case WM_USER
+5: return "TB_INDETERMINATE";
5416 case WM_USER
+9: return "TB_ISBUTTONENABLED";
5417 case WM_USER
+10: return "TB_ISBUTTONCHECKED";
5418 case WM_USER
+11: return "TB_ISBUTTONPRESSED";
5419 case WM_USER
+12: return "TB_ISBUTTONHIDDEN";
5420 case WM_USER
+13: return "TB_ISBUTTONINDETERMINATE";
5421 case WM_USER
+17: return "TB_SETSTATE";
5422 case WM_USER
+18: return "TB_GETSTATE";
5423 case WM_USER
+19: return "TB_ADDBITMAP";
5424 case WM_USER
+20: return "TB_ADDBUTTONS";
5425 case WM_USER
+21: return "TB_INSERTBUTTON";
5426 case WM_USER
+22: return "TB_DELETEBUTTON";
5427 case WM_USER
+23: return "TB_GETBUTTON";
5428 case WM_USER
+24: return "TB_BUTTONCOUNT";
5429 case WM_USER
+25: return "TB_COMMANDTOINDEX";
5430 case WM_USER
+26: return "TB_SAVERESTOREA";
5431 case WM_USER
+76: return "TB_SAVERESTOREW";
5432 case WM_USER
+27: return "TB_CUSTOMIZE";
5433 case WM_USER
+28: return "TB_ADDSTRINGA";
5434 case WM_USER
+77: return "TB_ADDSTRINGW";
5435 case WM_USER
+29: return "TB_GETITEMRECT";
5436 case WM_USER
+30: return "TB_BUTTONSTRUCTSIZE";
5437 case WM_USER
+31: return "TB_SETBUTTONSIZE";
5438 case WM_USER
+32: return "TB_SETBITMAPSIZE";
5439 case WM_USER
+33: return "TB_AUTOSIZE";
5440 case WM_USER
+35: return "TB_GETTOOLTIPS";
5441 case WM_USER
+36: return "TB_SETTOOLTIPS";
5442 case WM_USER
+37: return "TB_SETPARENT";
5443 case WM_USER
+39: return "TB_SETROWS";
5444 case WM_USER
+40: return "TB_GETROWS";
5445 case WM_USER
+42: return "TB_SETCMDID";
5446 case WM_USER
+43: return "TB_CHANGEBITMAP";
5447 case WM_USER
+44: return "TB_GETBITMAP";
5448 case WM_USER
+45: return "TB_GETBUTTONTEXTA";
5449 case WM_USER
+75: return "TB_GETBUTTONTEXTW";
5450 case WM_USER
+46: return "TB_REPLACEBITMAP";
5451 case WM_USER
+47: return "TB_SETINDENT";
5452 case WM_USER
+48: return "TB_SETIMAGELIST";
5453 case WM_USER
+49: return "TB_GETIMAGELIST";
5454 case WM_USER
+50: return "TB_LOADIMAGES";
5455 case WM_USER
+51: return "TB_GETRECT";
5456 case WM_USER
+52: return "TB_SETHOTIMAGELIST";
5457 case WM_USER
+53: return "TB_GETHOTIMAGELIST";
5458 case WM_USER
+54: return "TB_SETDISABLEDIMAGELIST";
5459 case WM_USER
+55: return "TB_GETDISABLEDIMAGELIST";
5460 case WM_USER
+56: return "TB_SETSTYLE";
5461 case WM_USER
+57: return "TB_GETSTYLE";
5462 case WM_USER
+58: return "TB_GETBUTTONSIZE";
5463 case WM_USER
+59: return "TB_SETBUTTONWIDTH";
5464 case WM_USER
+60: return "TB_SETMAXTEXTROWS";
5465 case WM_USER
+61: return "TB_GETTEXTROWS";
5466 case WM_USER
+41: return "TB_GETBITMAPFLAGS";
5469 static char s_szBuf
[128];
5470 sprintf(s_szBuf
, "<unknown message = %d>", message
);
5474 #endif //__WXDEBUG__
5476 static void TranslateKbdEventToMouse(wxWindowMSW
*win
,
5477 int *x
, int *y
, WPARAM
*flags
)
5479 // construct the key mask
5480 WPARAM
& fwKeys
= *flags
;
5482 fwKeys
= MK_RBUTTON
;
5483 if ( wxIsCtrlDown() )
5484 fwKeys
|= MK_CONTROL
;
5485 if ( wxIsShiftDown() )
5488 // simulate right mouse button click
5489 DWORD dwPos
= ::GetMessagePos();
5490 *x
= GET_X_LPARAM(dwPos
);
5491 *y
= GET_Y_LPARAM(dwPos
);
5493 win
->ScreenToClient(x
, y
);
5496 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
5500 HWND hwnd
= GetHwndOf(win
);
5501 HDC hdc
= ::GetDC(hwnd
);
5503 #if !wxDIALOG_UNIT_COMPATIBILITY
5504 // and select the current font into it
5505 HFONT hfont
= GetHfontOf(win
->GetFont());
5508 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
5512 // finally retrieve the text metrics from it
5513 GetTextMetrics(hdc
, &tm
);
5515 #if !wxDIALOG_UNIT_COMPATIBILITY
5519 (void)::SelectObject(hdc
, hfont
);
5523 ::ReleaseDC(hwnd
, hdc
);
5528 // Find the wxWindow at the current mouse position, returning the mouse
5530 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
5532 pt
= wxGetMousePosition();
5533 return wxFindWindowAtPoint(pt
);
5536 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
5541 HWND hWndHit
= ::WindowFromPoint(pt2
);
5543 wxWindow
* win
= wxFindWinFromHandle((WXHWND
) hWndHit
) ;
5544 HWND hWnd
= hWndHit
;
5546 // Try to find a window with a wxWindow associated with it
5547 while (!win
&& (hWnd
!= 0))
5549 hWnd
= ::GetParent(hWnd
);
5550 win
= wxFindWinFromHandle((WXHWND
) hWnd
) ;
5555 // Get the current mouse position.
5556 wxPoint
wxGetMousePosition()
5559 GetCursorPos( & pt
);
5561 return wxPoint(pt
.x
, pt
.y
);
5566 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
5568 UINT win_modifiers
=0;
5569 if ( modifiers
& wxMOD_ALT
)
5570 win_modifiers
|= MOD_ALT
;
5571 if ( modifiers
& wxMOD_SHIFT
)
5572 win_modifiers
|= MOD_SHIFT
;
5573 if ( modifiers
& wxMOD_CONTROL
)
5574 win_modifiers
|= MOD_CONTROL
;
5575 if ( modifiers
& wxMOD_WIN
)
5576 win_modifiers
|= MOD_WIN
;
5578 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
5580 wxLogLastError(_T("RegisterHotKey"));
5588 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
5590 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
5592 wxLogLastError(_T("UnregisterHotKey"));
5600 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
5602 int hotkeyId
= wParam
;
5603 int virtualKey
= HIWORD(lParam
);
5604 int win_modifiers
= LOWORD(lParam
);
5606 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
5607 event
.SetId(hotkeyId
);
5608 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
5609 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
5610 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
5611 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
5613 return GetEventHandler()->ProcessEvent(event
);
5616 #endif // wxUSE_HOTKEY