1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/window.cpp
3 // Purpose: wxWindowMSW
4 // Author: Julian Smart
5 // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/window.h"
30 #include "wx/msw/wrapwin.h"
31 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/msw/missing.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcmemory.h"
40 #include "wx/layout.h"
41 #include "wx/dialog.h"
43 #include "wx/listbox.h"
44 #include "wx/button.h"
45 #include "wx/msgdlg.h"
46 #include "wx/settings.h"
47 #include "wx/statbox.h"
51 #include "wx/textctrl.h"
52 #include "wx/menuitem.h"
53 #include "wx/module.h"
56 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
57 #include "wx/ownerdrw.h"
60 #include "wx/hashmap.h"
61 #include "wx/evtloop.h"
63 #include "wx/sysopt.h"
65 #if wxUSE_DRAG_AND_DROP
69 #if wxUSE_ACCESSIBILITY
70 #include "wx/access.h"
74 #define WM_GETOBJECT 0x003D
77 #define OBJID_CLIENT 0xFFFFFFFC
81 #include "wx/msw/private.h"
84 #include "wx/tooltip.h"
92 #include "wx/spinctrl.h"
93 #endif // wxUSE_SPINCTRL
95 #include "wx/notebook.h"
96 #include "wx/listctrl.h"
97 #include "wx/dynlib.h"
101 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
102 #include <shellapi.h>
103 #include <mmsystem.h>
107 #include <windowsx.h>
110 #if !defined __WXWINCE__ && !defined NEED_PBT_H
114 #if defined(__WXWINCE__)
115 #include "wx/msw/wince/missing.h"
118 #include <shellapi.h>
120 #include <aygshell.h>
124 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS
125 #define HAVE_TRACKMOUSEEVENT
126 #endif // everything needed for TrackMouseEvent()
128 // if this is set to 1, we use deferred window sizing to reduce flicker when
129 // resizing complicated window hierarchies, but this can in theory result in
130 // different behaviour than the old code so we keep the possibility to use it
131 // by setting this to 0 (in the future this should be removed completely)
133 #define USE_DEFERRED_SIZING 0
135 #define USE_DEFERRED_SIZING 1
138 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
139 // when mouse position didnd't change
141 #define wxUSE_MOUSEEVENT_HACK 0
143 #define wxUSE_MOUSEEVENT_HACK 1
146 // ---------------------------------------------------------------------------
148 // ---------------------------------------------------------------------------
150 #if wxUSE_MENUS_NATIVE
151 wxMenu
*wxCurrentPopupMenu
= NULL
;
152 #endif // wxUSE_MENUS_NATIVE
155 extern wxChar
*wxCanvasClassName
;
157 extern const wxChar
*wxCanvasClassName
;
160 // true if we had already created the std colour map, used by
161 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
162 static bool gs_hasStdCmap
= false;
164 // last mouse event information we need to filter out the duplicates
165 #if wxUSE_MOUSEEVENT_HACK
166 static struct MouseEventInfoDummy
168 // mouse position (in screen coordinates)
171 // last mouse event type
174 #endif // wxUSE_MOUSEEVENT_HACK
176 // hash containing the registered handlers for the custom messages
177 WX_DECLARE_HASH_MAP(int, wxWindow::MSWMessageHandler
,
178 wxIntegerHash
, wxIntegerEqual
,
181 static MSWMessageHandlers gs_messageHandlers
;
183 // ---------------------------------------------------------------------------
185 // ---------------------------------------------------------------------------
187 // the window proc for all our windows
188 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
189 WPARAM wParam
, LPARAM lParam
);
193 const wxChar
*wxGetMessageName(int message
);
196 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
197 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
198 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
200 // get the text metrics for the current font
201 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
204 // find the window for the mouse event at the specified position
205 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
206 #endif // __WXWINCE__
208 // wrapper around BringWindowToTop() API
209 static inline void wxBringWindowToTop(HWND hwnd
)
211 #ifdef __WXMICROWIN__
212 // It seems that MicroWindows brings the _parent_ of the window to the top,
213 // which can be the wrong one.
215 // activate (set focus to) specified window
219 // raise top level parent to top of z order
220 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
222 wxLogLastError(_T("SetWindowPos"));
228 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
229 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
232 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
233 parent as well as otherwise several Win32 functions using
234 GetNextDlgTabItem() to iterate over all controls such as
235 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
236 all of them iterate over all the controls starting from the currently
237 focused one and stop iterating when they get back to the focus but
238 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
239 get back to the initial (focused) window: as we do have this style,
240 GetNextDlgTabItem() will leave this window and continue in its parent,
241 but if the parent doesn't have it, it wouldn't recurse inside it later
242 on and so wouldn't have a chance of getting back to this window either.
244 while ( parent
&& !parent
->IsTopLevel() )
246 LONG exStyle
= ::GetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
);
247 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
249 // force the parent to have this style
250 ::SetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
,
251 exStyle
| WS_EX_CONTROLPARENT
);
254 parent
= parent
->GetParent();
258 #endif // !__WXWINCE__
261 // On Windows CE, GetCursorPos can return an error, so use this function
263 bool GetCursorPosWinCE(POINT
* pt
)
265 if (!GetCursorPos(pt
))
267 DWORD pos
= GetMessagePos();
275 // ---------------------------------------------------------------------------
277 // ---------------------------------------------------------------------------
279 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
281 #ifdef __WXUNIVERSAL__
282 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
284 #if wxUSE_EXTENDED_RTTI
286 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
287 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
288 // windows with negative ids never can be recreated anyway
290 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
292 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
293 if ( win
&& win
->GetId() < 0 )
298 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
300 // make wxWindowList known before the property is used
302 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
304 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
306 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
309 WX_DEFINE_FLAGS( wxWindowStyle
)
311 wxBEGIN_FLAGS( wxWindowStyle
)
312 // new style border flags, we put them first to
313 // use them for streaming out
315 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
316 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
317 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
318 wxFLAGS_MEMBER(wxBORDER_RAISED
)
319 wxFLAGS_MEMBER(wxBORDER_STATIC
)
320 wxFLAGS_MEMBER(wxBORDER_NONE
)
322 // old style border flags
323 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
324 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
325 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
326 wxFLAGS_MEMBER(wxRAISED_BORDER
)
327 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
328 wxFLAGS_MEMBER(wxBORDER
)
330 // standard window styles
331 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
332 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
333 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
334 wxFLAGS_MEMBER(wxWANTS_CHARS
)
335 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
336 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
337 wxFLAGS_MEMBER(wxVSCROLL
)
338 wxFLAGS_MEMBER(wxHSCROLL
)
340 wxEND_FLAGS( wxWindowStyle
)
342 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
343 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
344 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
345 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
346 // Always constructor Properties first
348 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
349 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
350 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
351 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
352 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
354 // Then all relations of the object graph
356 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
358 // and finally all other properties
360 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
361 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
362 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
363 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
364 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
366 // possible property candidates (not in xrc) or not valid in all subclasses
367 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
368 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
369 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
370 // MaxHeight, Width , MinHeight , Width
371 // TODO switch label to control and title to toplevels
373 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
374 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
375 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
376 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
381 wxEND_PROPERTIES_TABLE()
383 wxBEGIN_HANDLERS_TABLE(wxWindow
)
384 wxEND_HANDLERS_TABLE()
386 wxCONSTRUCTOR_DUMMY(wxWindow
)
389 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
391 #endif // __WXUNIVERSAL__/__WXMSW__
393 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
394 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
395 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground
)
397 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
401 // ===========================================================================
403 // ===========================================================================
405 // ---------------------------------------------------------------------------
406 // wxWindow utility functions
407 // ---------------------------------------------------------------------------
409 // Find an item given the MS Windows id
410 wxWindow
*wxWindowMSW::FindItem(long id
) const
413 wxControl
*item
= wxDynamicCastThis(wxControl
);
416 // is it us or one of our "internal" children?
417 if ( item
->GetId() == id
418 #ifndef __WXUNIVERSAL__
419 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
420 #endif // __WXUNIVERSAL__
426 #endif // wxUSE_CONTROLS
428 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
431 wxWindow
*childWin
= current
->GetData();
433 wxWindow
*wnd
= childWin
->FindItem(id
);
437 current
= current
->GetNext();
443 // Find an item given the MS Windows handle
444 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
446 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
449 wxWindow
*parent
= current
->GetData();
451 // Do a recursive search.
452 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
458 || parent
->IsKindOf(CLASSINFO(wxControl
))
459 #endif // wxUSE_CONTROLS
462 wxWindow
*item
= current
->GetData();
463 if ( item
->GetHWND() == hWnd
)
467 if ( item
->ContainsHWND(hWnd
) )
472 current
= current
->GetNext();
477 // Default command handler
478 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
483 // ----------------------------------------------------------------------------
484 // constructors and such
485 // ----------------------------------------------------------------------------
487 void wxWindowMSW::Init()
490 m_isBeingDeleted
= false;
492 m_mouseInWindow
= false;
493 m_lastKeydownProcessed
= false;
503 m_pendingPosition
= wxDefaultPosition
;
504 m_pendingSize
= wxDefaultSize
;
507 m_contextMenuEnabled
= false;
512 wxWindowMSW::~wxWindowMSW()
514 m_isBeingDeleted
= true;
516 #ifndef __WXUNIVERSAL__
517 // VS: make sure there's no wxFrame with last focus set to us:
518 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
520 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
523 if ( frame
->GetLastFocus() == this )
525 frame
->SetLastFocus(NULL
);
528 // apparently sometimes we can end up with our grand parent
529 // pointing to us as well: this is surely a bug in focus handling
530 // code but it's not clear where it happens so for now just try to
531 // fix it here by not breaking out of the loop
535 #endif // __WXUNIVERSAL__
537 // VS: destroy children first and _then_ detach *this from its parent.
538 // If we did it the other way around, children wouldn't be able
539 // find their parent frame (see above).
544 // VZ: test temp removed to understand what really happens here
545 //if (::IsWindow(GetHwnd()))
547 if ( !::DestroyWindow(GetHwnd()) )
548 wxLogLastError(wxT("DestroyWindow"));
551 // remove hWnd <-> wxWindow association
552 wxRemoveHandleAssociation(this);
557 // real construction (Init() must have been called before!)
558 bool wxWindowMSW::Create(wxWindow
*parent
,
563 const wxString
& name
)
565 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
567 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
570 parent
->AddChild(this);
573 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
575 #ifdef __WXUNIVERSAL__
576 // no borders, we draw them ourselves
577 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
581 msflags
&= ~WS_BORDER
;
582 #endif // wxUniversal
586 msflags
|= WS_VISIBLE
;
589 if ( !MSWCreate(wxCanvasClassName
, NULL
, pos
, size
, msflags
, exstyle
) )
597 // ---------------------------------------------------------------------------
599 // ---------------------------------------------------------------------------
601 void wxWindowMSW::SetFocus()
603 HWND hWnd
= GetHwnd();
604 wxCHECK_RET( hWnd
, _T("can't set focus to invalid window") );
606 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
610 if ( !::SetFocus(hWnd
) )
612 #if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
613 // was there really an error?
614 DWORD dwRes
= ::GetLastError();
617 HWND hwndFocus
= ::GetFocus();
618 if ( hwndFocus
!= hWnd
)
620 wxLogApiError(_T("SetFocus"), dwRes
);
627 void wxWindowMSW::SetFocusFromKbd()
629 // when the focus is given to the control with DLGC_HASSETSEL style from
630 // keyboard its contents should be entirely selected: this is what
631 // ::IsDialogMessage() does and so we should do it as well to provide the
632 // same LNF as the native programs
633 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
635 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
638 // do this after (maybe) setting the selection as like this when
639 // wxEVT_SET_FOCUS handler is called, the selection would have been already
640 // set correctly -- this may be important
641 wxWindowBase::SetFocusFromKbd();
644 // Get the window with the focus
645 wxWindow
*wxWindowBase::DoFindFocus()
647 HWND hWnd
= ::GetFocus();
650 return wxGetWindowFromHWND((WXHWND
)hWnd
);
656 void wxWindowMSW::DoEnable( bool enable
)
658 HWND hWnd
= GetHwnd();
660 ::EnableWindow(hWnd
, (BOOL
)enable
);
663 bool wxWindowMSW::Show(bool show
)
665 if ( !wxWindowBase::Show(show
) )
668 HWND hWnd
= GetHwnd();
670 // we could be called before the underlying window is created (this is
671 // actually useful to prevent it from being initially shown), e.g.
673 // wxFoo *foo = new wxFoo;
675 // foo->Create(parent, ...);
677 // should work without errors
680 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
686 // Raise the window to the top of the Z order
687 void wxWindowMSW::Raise()
689 wxBringWindowToTop(GetHwnd());
692 // Lower the window to the bottom of the Z order
693 void wxWindowMSW::Lower()
695 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
696 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
699 void wxWindowMSW::DoCaptureMouse()
701 HWND hWnd
= GetHwnd();
708 void wxWindowMSW::DoReleaseMouse()
710 if ( !::ReleaseCapture() )
712 wxLogLastError(_T("ReleaseCapture"));
716 /* static */ wxWindow
*wxWindowBase::GetCapture()
718 HWND hwnd
= ::GetCapture();
719 return hwnd
? wxFindWinFromHandle((WXHWND
)hwnd
) : (wxWindow
*)NULL
;
722 bool wxWindowMSW::SetFont(const wxFont
& font
)
724 if ( !wxWindowBase::SetFont(font
) )
730 HWND hWnd
= GetHwnd();
733 WXHANDLE hFont
= m_font
.GetResourceHandle();
735 wxASSERT_MSG( hFont
, wxT("should have valid font") );
737 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
742 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
744 if ( !wxWindowBase::SetCursor(cursor
) )
750 // don't "overwrite" busy cursor
751 if ( m_cursor
.Ok() && !wxIsBusy() )
753 // normally we should change the cursor only if it's over this window
754 // but we should do it always if we capture the mouse currently
755 bool set
= HasCapture();
758 HWND hWnd
= GetHwnd();
762 ::GetCursorPosWinCE(&point
);
764 ::GetCursorPos(&point
);
767 RECT rect
= wxGetWindowRect(hWnd
);
769 set
= ::PtInRect(&rect
, point
) != 0;
774 ::SetCursor(GetHcursorOf(m_cursor
));
776 //else: will be set later when the mouse enters this window
782 void wxWindowMSW::WarpPointer(int x
, int y
)
784 ClientToScreen(&x
, &y
);
786 if ( !::SetCursorPos(x
, y
) )
788 wxLogLastError(_T("SetCursorPos"));
792 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
794 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
795 // to use it on older systems -- and could possibly do some harm
796 static int s_needToUpdate
= -1;
797 if ( s_needToUpdate
== -1 )
800 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
804 if ( s_needToUpdate
)
806 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
807 // won't send WM_UPDATEUISTATE
808 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
812 // ---------------------------------------------------------------------------
814 // ---------------------------------------------------------------------------
816 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
818 #ifdef __WXMICROWIN__
819 return ::GetScrollPosWX(hWnd
, wOrient
);
821 WinStruct
<SCROLLINFO
> scrollInfo
;
822 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
823 scrollInfo
.fMask
= SIF_POS
;
824 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
826 return scrollInfo
.nPos
;
831 int wxWindowMSW::GetScrollPos(int orient
) const
833 HWND hWnd
= GetHwnd();
834 wxCHECK_MSG( hWnd
, 0, _T("no HWND in GetScrollPos") );
836 return GetScrollPosition(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
);
839 // This now returns the whole range, not just the number
840 // of positions that we can scroll.
841 int wxWindowMSW::GetScrollRange(int orient
) const
844 HWND hWnd
= GetHwnd();
848 ::GetScrollRange(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
851 WinStruct
<SCROLLINFO
> scrollInfo
;
852 scrollInfo
.fMask
= SIF_RANGE
;
853 if ( !::GetScrollInfo(hWnd
,
854 orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
857 // Most of the time this is not really an error, since the return
858 // value can also be zero when there is no scrollbar yet.
859 // wxLogLastError(_T("GetScrollInfo"));
861 maxPos
= scrollInfo
.nMax
;
863 // undo "range - 1" done in SetScrollbar()
867 int wxWindowMSW::GetScrollThumb(int orient
) const
869 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
872 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
874 HWND hWnd
= GetHwnd();
875 wxCHECK_RET( hWnd
, _T("SetScrollPos: no HWND") );
877 WinStruct
<SCROLLINFO
> info
;
881 info
.fMask
= SIF_POS
;
882 if ( HasFlag(wxALWAYS_SHOW_SB
) )
884 // disable scrollbar instead of removing it then
885 info
.fMask
|= SIF_DISABLENOSCROLL
;
888 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
892 // New function that will replace some of the above.
893 void wxWindowMSW::SetScrollbar(int orient
,
899 WinStruct
<SCROLLINFO
> info
;
900 info
.nPage
= pageSize
;
901 info
.nMin
= 0; // range is nMax - nMin + 1
902 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
904 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
905 if ( HasFlag(wxALWAYS_SHOW_SB
) )
907 // disable scrollbar instead of removing it then
908 info
.fMask
|= SIF_DISABLENOSCROLL
;
911 HWND hWnd
= GetHwnd();
914 // We have to set the variables here to make them valid in events
915 // triggered by ::SetScrollInfo()
916 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
918 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
923 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
929 wxCopyRectToRECT(*prect
, rect
);
939 // FIXME: is this the exact equivalent of the line below?
940 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
942 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
946 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
948 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
951 for ( int n
= 0; n
< count
; n
++ )
953 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
955 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
958 // don't bother to continue, we're already at top/bottom
965 return pos
!= posStart
;
968 bool wxWindowMSW::ScrollLines(int lines
)
970 bool down
= lines
> 0;
972 return ScrollVertically(GetHwnd(),
973 down
? SB_LINEDOWN
: SB_LINEUP
,
974 down
? lines
: -lines
);
977 bool wxWindowMSW::ScrollPages(int pages
)
979 bool down
= pages
> 0;
981 return ScrollVertically(GetHwnd(),
982 down
? SB_PAGEDOWN
: SB_PAGEUP
,
983 down
? pages
: -pages
);
986 // ----------------------------------------------------------------------------
988 // ----------------------------------------------------------------------------
990 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
995 const HWND hwnd
= GetHwnd();
996 wxCHECK_RET( hwnd
, _T("layout direction must be set after window creation") );
998 LONG styleOld
= ::GetWindowLong(hwnd
, GWL_EXSTYLE
);
1000 LONG styleNew
= styleOld
;
1003 case wxLayout_LeftToRight
:
1004 styleNew
&= ~WS_EX_LAYOUTRTL
;
1007 case wxLayout_RightToLeft
:
1008 styleNew
|= WS_EX_LAYOUTRTL
;
1012 wxFAIL_MSG(_T("unsupported layout direction"));
1016 if ( styleNew
!= styleOld
)
1018 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, styleNew
);
1023 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1026 return wxLayout_Default
;
1028 const HWND hwnd
= GetHwnd();
1029 wxCHECK_MSG( hwnd
, wxLayout_Default
, _T("invalid window") );
1031 return ::GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
1032 ? wxLayout_RightToLeft
1033 : wxLayout_LeftToRight
;
1038 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1039 wxCoord
WXUNUSED(width
),
1040 wxCoord
WXUNUSED(widthTotal
)) const
1042 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1043 // redo it ourselves
1047 // ---------------------------------------------------------------------------
1049 // ---------------------------------------------------------------------------
1051 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1053 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1055 HWND hwnd
= (HWND
)hWnd
;
1056 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1058 wxAssociateWinWithHandle(hwnd
, this);
1060 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1062 // we don't need to subclass the window of our own class (in the Windows
1063 // sense of the word)
1064 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1066 wxSetWindowProc(hwnd
, wxWndProc
);
1070 // don't bother restoring it either: this also makes it easy to
1071 // implement IsOfStandardClass() method which returns true for the
1072 // standard controls and false for the wxWidgets own windows as it can
1073 // simply check m_oldWndProc
1074 m_oldWndProc
= NULL
;
1077 // we're officially created now, send the event
1078 wxWindowCreateEvent
event((wxWindow
*)this);
1079 (void)GetEventHandler()->ProcessEvent(event
);
1082 void wxWindowMSW::UnsubclassWin()
1084 wxRemoveHandleAssociation(this);
1086 // Restore old Window proc
1087 HWND hwnd
= GetHwnd();
1092 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1096 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1098 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1101 m_oldWndProc
= NULL
;
1106 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1110 if ( !::DestroyWindow(GetHwnd()) )
1111 wxLogLastError(wxT("DestroyWindow"));
1114 WXHWND wxhwnd
= (WXHWND
)handle
;
1117 SubclassWin(wxhwnd
);
1120 void wxWindowMSW::DissociateHandle()
1122 // this also calls SetHWND(0) for us
1127 bool wxCheckWindowWndProc(WXHWND hWnd
,
1128 WXFARPROC
WXUNUSED(wndProc
))
1130 // TODO: This list of window class names should be factored out so they can be
1131 // managed in one place and then accessed from here and other places, such as
1132 // wxApp::RegisterWindowClasses() and wxApp::UnregisterWindowClasses()
1135 extern wxChar
*wxCanvasClassName
;
1136 extern wxChar
*wxCanvasClassNameNR
;
1138 extern const wxChar
*wxCanvasClassName
;
1139 extern const wxChar
*wxCanvasClassNameNR
;
1141 extern const wxChar
*wxMDIFrameClassName
;
1142 extern const wxChar
*wxMDIFrameClassNameNoRedraw
;
1143 extern const wxChar
*wxMDIChildFrameClassName
;
1144 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
1145 wxString
str(wxGetWindowClass(hWnd
));
1146 if (str
== wxCanvasClassName
||
1147 str
== wxCanvasClassNameNR
||
1149 str
== _T("wxGLCanvasClass") ||
1150 str
== _T("wxGLCanvasClassNR") ||
1151 #endif // wxUSE_GLCANVAS
1152 str
== wxMDIFrameClassName
||
1153 str
== wxMDIFrameClassNameNoRedraw
||
1154 str
== wxMDIChildFrameClassName
||
1155 str
== wxMDIChildFrameClassNameNoRedraw
||
1156 str
== _T("wxTLWHiddenParent"))
1157 return true; // Effectively means don't subclass
1162 // ----------------------------------------------------------------------------
1164 // ----------------------------------------------------------------------------
1166 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1168 long flagsOld
= GetWindowStyleFlag();
1169 if ( flags
== flagsOld
)
1172 // update the internal variable
1173 wxWindowBase::SetWindowStyleFlag(flags
);
1175 // and the real window flags
1176 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1179 void wxWindowMSW::SetExtraStyle(long exflags
)
1181 long exflagsOld
= GetExtraStyle();
1182 if ( exflags
== exflagsOld
)
1185 // update the internal variable
1186 wxWindowBase::SetExtraStyle(exflags
);
1188 // and the real window flags
1189 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1192 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1194 // now update the Windows style as well if needed - and if the window had
1195 // been already created
1199 // we may need to call SetWindowPos() when we change some styles
1200 bool callSWP
= false;
1203 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1205 // this is quite a horrible hack but we need it because MSWGetStyle()
1206 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1207 // and so we have to modify the window exflags temporarily to get the
1208 // correct exstyleOld
1209 long exflagsNew
= GetExtraStyle();
1210 wxWindowBase::SetExtraStyle(exflagsOld
);
1213 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1215 wxWindowBase::SetExtraStyle(exflagsNew
);
1218 if ( style
!= styleOld
)
1220 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1221 // this function so instead of simply setting the style to the new
1222 // value we clear the bits which were set in styleOld but are set in
1223 // the new one and set the ones which were not set before
1224 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1225 styleReal
&= ~styleOld
;
1228 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1230 // we need to call SetWindowPos() if any of the styles affecting the
1231 // frame appearance have changed
1232 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1241 // and the extended style
1242 long exstyleReal
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1244 if ( exstyle
!= exstyleOld
)
1246 exstyleReal
&= ~exstyleOld
;
1247 exstyleReal
|= exstyle
;
1249 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyleReal
);
1251 // ex style changes don't take effect without calling SetWindowPos
1257 // we must call SetWindowPos() to flush the cached extended style and
1258 // also to make the change to wxSTAY_ON_TOP style take effect: just
1259 // setting the style simply doesn't work
1260 if ( !::SetWindowPos(GetHwnd(),
1261 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1264 SWP_NOMOVE
| SWP_NOSIZE
| SWP_FRAMECHANGED
) )
1266 wxLogLastError(_T("SetWindowPos"));
1271 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1273 // translate common wxWidgets styles to Windows ones
1275 // most of windows are child ones, those which are not (such as
1276 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1277 WXDWORD style
= WS_CHILD
;
1279 // using this flag results in very significant reduction in flicker,
1280 // especially with controls inside the static boxes (as the interior of the
1281 // box is not redrawn twice), but sometimes results in redraw problems, so
1282 // optionally allow the old code to continue to use it provided a special
1283 // system option is turned on
1284 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1285 || (flags
& wxCLIP_CHILDREN
) )
1286 style
|= WS_CLIPCHILDREN
;
1288 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1289 // don't support overlapping windows and it only makes sense for them and,
1290 // presumably, gives the system some extra work (to manage more clipping
1291 // regions), so avoid it alltogether
1294 if ( flags
& wxVSCROLL
)
1295 style
|= WS_VSCROLL
;
1297 if ( flags
& wxHSCROLL
)
1298 style
|= WS_HSCROLL
;
1300 const wxBorder border
= GetBorder(flags
);
1302 // WS_BORDER is only required for wxBORDER_SIMPLE
1303 if ( border
== wxBORDER_SIMPLE
)
1306 // now deal with ext style if the caller wants it
1312 if ( flags
& wxTRANSPARENT_WINDOW
)
1313 *exstyle
|= WS_EX_TRANSPARENT
;
1319 case wxBORDER_DEFAULT
:
1320 wxFAIL_MSG( _T("unknown border style") );
1324 case wxBORDER_SIMPLE
:
1327 case wxBORDER_STATIC
:
1328 *exstyle
|= WS_EX_STATICEDGE
;
1331 case wxBORDER_RAISED
:
1332 *exstyle
|= WS_EX_DLGMODALFRAME
;
1335 case wxBORDER_SUNKEN
:
1336 *exstyle
|= WS_EX_CLIENTEDGE
;
1337 style
&= ~WS_BORDER
;
1340 case wxBORDER_DOUBLE
:
1341 *exstyle
|= WS_EX_DLGMODALFRAME
;
1345 // wxUniv doesn't use Windows dialog navigation functions at all
1346 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1347 // to make the dialog navigation work with the nested panels we must
1348 // use this style (top level windows such as dialogs don't need it)
1349 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1351 *exstyle
|= WS_EX_CONTROLPARENT
;
1353 #endif // __WXUNIVERSAL__
1359 // Setup background and foreground colours correctly
1360 void wxWindowMSW::SetupColours()
1363 SetBackgroundColour(GetParent()->GetBackgroundColour());
1366 bool wxWindowMSW::IsMouseInWindow() const
1368 // get the mouse position
1371 ::GetCursorPosWinCE(&pt
);
1373 ::GetCursorPos(&pt
);
1376 // find the window which currently has the cursor and go up the window
1377 // chain until we find this window - or exhaust it
1378 HWND hwnd
= ::WindowFromPoint(pt
);
1379 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1380 hwnd
= ::GetParent(hwnd
);
1382 return hwnd
!= NULL
;
1385 void wxWindowMSW::OnInternalIdle()
1387 #ifndef HAVE_TRACKMOUSEEVENT
1388 // Check if we need to send a LEAVE event
1389 if ( m_mouseInWindow
)
1391 // note that we should generate the leave event whether the window has
1392 // or doesn't have mouse capture
1393 if ( !IsMouseInWindow() )
1395 GenerateMouseLeave();
1398 #endif // !HAVE_TRACKMOUSEEVENT
1400 if (wxUpdateUIEvent::CanUpdate(this))
1401 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1404 // Set this window to be the child of 'parent'.
1405 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1407 if ( !wxWindowBase::Reparent(parent
) )
1410 HWND hWndChild
= GetHwnd();
1411 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1413 ::SetParent(hWndChild
, hWndParent
);
1416 if ( ::GetWindowLong(hWndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1418 EnsureParentHasControlParentStyle(GetParent());
1420 #endif // !__WXWINCE__
1425 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1427 #ifndef __WXMICROWIN__
1428 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1432 void wxWindowMSW::Freeze()
1434 if ( !m_frozenness
++ )
1437 SendSetRedraw(GetHwnd(), false);
1441 void wxWindowMSW::Thaw()
1443 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1445 if ( --m_frozenness
== 0 )
1449 SendSetRedraw(GetHwnd(), true);
1451 // we need to refresh everything or otherwise the invalidated area
1452 // is not going to be repainted
1458 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1460 HWND hWnd
= GetHwnd();
1467 wxCopyRectToRECT(*rect
, mswRect
);
1475 // RedrawWindow not available on SmartPhone or eVC++ 3
1476 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1477 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1481 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1483 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1488 void wxWindowMSW::Update()
1490 if ( !::UpdateWindow(GetHwnd()) )
1492 wxLogLastError(_T("UpdateWindow"));
1495 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1496 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1497 // handler needs to be really drawn right now
1502 // ---------------------------------------------------------------------------
1504 // ---------------------------------------------------------------------------
1506 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1510 // we need to lower the sibling static boxes so controls contained within can be
1512 static void AdjustStaticBoxZOrder(wxWindow
*parent
)
1514 // no sibling static boxes if we have no parent (ie TLW)
1518 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1520 node
= node
->GetNext() )
1522 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1525 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1526 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1531 #else // !wxUSE_STATBOX
1533 static inline void AdjustStaticBoxZOrder(wxWindow
* WXUNUSED(parent
))
1537 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1539 #endif // drag and drop is used
1541 #if wxUSE_DRAG_AND_DROP
1542 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1544 if ( m_dropTarget
!= 0 ) {
1545 m_dropTarget
->Revoke(m_hWnd
);
1546 delete m_dropTarget
;
1549 m_dropTarget
= pDropTarget
;
1550 if ( m_dropTarget
!= 0 )
1552 AdjustStaticBoxZOrder(GetParent());
1553 m_dropTarget
->Register(m_hWnd
);
1556 #endif // wxUSE_DRAG_AND_DROP
1558 // old-style file manager drag&drop support: we retain the old-style
1559 // DragAcceptFiles in parallel with SetDropTarget.
1560 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1563 HWND hWnd
= GetHwnd();
1566 AdjustStaticBoxZOrder(GetParent());
1567 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1572 // ----------------------------------------------------------------------------
1574 // ----------------------------------------------------------------------------
1578 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1580 wxWindowBase::DoSetToolTip(tooltip
);
1583 m_tooltip
->SetWindow((wxWindow
*)this);
1586 #endif // wxUSE_TOOLTIPS
1588 // ---------------------------------------------------------------------------
1589 // moving and resizing
1590 // ---------------------------------------------------------------------------
1592 bool wxWindowMSW::IsSizeDeferred() const
1594 #if USE_DEFERRED_SIZING
1595 if ( m_pendingPosition
!= wxDefaultPosition
||
1596 m_pendingSize
!= wxDefaultSize
)
1598 #endif // USE_DEFERRED_SIZING
1604 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1606 #if USE_DEFERRED_SIZING
1607 // if SetSize() had been called at wx level but not realized at Windows
1608 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1609 // the new and not the old position to the other wx code
1610 if ( m_pendingSize
!= wxDefaultSize
)
1613 *x
= m_pendingSize
.x
;
1615 *y
= m_pendingSize
.y
;
1617 else // use current size
1618 #endif // USE_DEFERRED_SIZING
1620 RECT rect
= wxGetWindowRect(GetHwnd());
1623 *x
= rect
.right
- rect
.left
;
1625 *y
= rect
.bottom
- rect
.top
;
1629 // Get size *available for subwindows* i.e. excluding menu bar etc.
1630 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1632 #if USE_DEFERRED_SIZING
1633 if ( m_pendingSize
!= wxDefaultSize
)
1635 // we need to calculate the client size corresponding to pending size
1637 rect
.left
= m_pendingPosition
.x
;
1638 rect
.top
= m_pendingPosition
.y
;
1639 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1640 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1642 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1645 *x
= rect
.right
- rect
.left
;
1647 *y
= rect
.bottom
- rect
.top
;
1650 #endif // USE_DEFERRED_SIZING
1652 RECT rect
= wxGetClientRect(GetHwnd());
1661 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1663 wxWindow
* const parent
= GetParent();
1666 if ( m_pendingPosition
!= wxDefaultPosition
)
1668 pos
= m_pendingPosition
;
1670 else // use current position
1672 RECT rect
= wxGetWindowRect(GetHwnd());
1675 point
.x
= rect
.left
;
1678 // we do the adjustments with respect to the parent only for the "real"
1679 // children, not for the dialogs/frames
1680 if ( !IsTopLevel() )
1682 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
1684 // In RTL mode, we want the logical left x-coordinate,
1685 // which would be the physical right x-coordinate.
1686 point
.x
= rect
.right
;
1689 // Since we now have the absolute screen coords, if there's a
1690 // parent we must subtract its top left corner
1693 ::ScreenToClient(GetHwndOf(parent
), &point
);
1701 // we also must adjust by the client area offset: a control which is just
1702 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1703 if ( parent
&& !IsTopLevel() )
1705 const wxPoint
pt(parent
->GetClientAreaOrigin());
1716 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1724 ::ScreenToClient(GetHwnd(), &pt
);
1732 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1740 ::ClientToScreen(GetHwnd(), &pt
);
1749 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1751 #if USE_DEFERRED_SIZING
1752 // if our parent had prepared a defer window handle for us, use it (unless
1753 // we are a top level window)
1754 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1756 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1759 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1760 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1763 wxLogLastError(_T("DeferWindowPos"));
1769 // hdwp must be updated as it may have been changed
1770 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1775 // did deferred move, remember new coordinates of the window as they're
1776 // different from what Windows would return for it
1780 // otherwise (or if deferring failed) move the window in place immediately
1781 #endif // USE_DEFERRED_SIZING
1782 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
1784 wxLogLastError(wxT("MoveWindow"));
1787 // if USE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1788 // ignored otherwise
1792 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1794 // TODO: is this consistent with other platforms?
1795 // Still, negative width or height shouldn't be allowed
1801 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
1803 #if USE_DEFERRED_SIZING
1804 m_pendingPosition
= wxPoint(x
, y
);
1805 m_pendingSize
= wxSize(width
, height
);
1806 #endif // USE_DEFERRED_SIZING
1810 // set the size of the window: if the dimensions are positive, just use them,
1811 // but if any of them is equal to -1, it means that we must find the value for
1812 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1813 // which case -1 is a valid value for x and y)
1815 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1816 // the width/height to best suit our contents, otherwise we reuse the current
1818 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1820 // get the current size and position...
1821 int currentX
, currentY
;
1822 int currentW
, currentH
;
1824 GetPosition(¤tX
, ¤tY
);
1825 GetSize(¤tW
, ¤tH
);
1827 // ... and don't do anything (avoiding flicker) if it's already ok unless
1828 // we're forced to resize the window
1829 if ( x
== currentX
&& y
== currentY
&&
1830 width
== currentW
&& height
== currentH
&&
1831 !(sizeFlags
& wxSIZE_FORCE
) )
1836 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1838 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1841 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1843 wxSize size
= wxDefaultSize
;
1844 if ( width
== wxDefaultCoord
)
1846 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1848 size
= DoGetBestSize();
1853 // just take the current one
1858 if ( height
== wxDefaultCoord
)
1860 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1862 if ( size
.x
== wxDefaultCoord
)
1864 size
= DoGetBestSize();
1866 //else: already called DoGetBestSize() above
1872 // just take the current one
1877 DoMoveWindow(x
, y
, width
, height
);
1880 void wxWindowMSW::DoSetClientSize(int width
, int height
)
1882 // setting the client size is less obvious than it could have been
1883 // because in the result of changing the total size the window scrollbar
1884 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
1885 // doesn't take neither into account) and so the client size will not be
1886 // correct as the difference between the total and client size changes --
1887 // so we keep changing it until we get it right
1889 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1890 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1891 // may become 3 if the window had 0 size originally and so we didn't
1892 // calculate the scrollbar correction correctly during the first iteration)
1893 // but just to be on the safe side we check for it instead of making it an
1894 // "infinite" loop (i.e. leaving break inside as the only way to get out)
1895 for ( int i
= 0; i
< 4; i
++ )
1898 ::GetClientRect(GetHwnd(), &rectClient
);
1900 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
1901 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
1902 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
1907 // Find the difference between the entire window (title bar and all)
1908 // and the client area; add this to the new client size to move the
1911 ::GetWindowRect(GetHwnd(), &rectWin
);
1913 const int widthWin
= rectWin
.right
- rectWin
.left
,
1914 heightWin
= rectWin
.bottom
- rectWin
.top
;
1916 // MoveWindow positions the child windows relative to the parent, so
1917 // adjust if necessary
1918 if ( !IsTopLevel() )
1920 wxWindow
*parent
= GetParent();
1923 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
1927 // don't call DoMoveWindow() because we want to move window immediately
1928 // and not defer it here as otherwise the value returned by
1929 // GetClient/WindowRect() wouldn't change as the window wouldn't be
1931 if ( !::MoveWindow(GetHwnd(),
1934 width
+ widthWin
- rectClient
.right
,
1935 height
+ heightWin
- rectClient
.bottom
,
1938 wxLogLastError(_T("MoveWindow"));
1943 // ---------------------------------------------------------------------------
1945 // ---------------------------------------------------------------------------
1947 int wxWindowMSW::GetCharHeight() const
1949 return wxGetTextMetrics(this).tmHeight
;
1952 int wxWindowMSW::GetCharWidth() const
1954 // +1 is needed because Windows apparently adds it when calculating the
1955 // dialog units size in pixels
1956 #if wxDIALOG_UNIT_COMPATIBILITY
1957 return wxGetTextMetrics(this).tmAveCharWidth
;
1959 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
1963 void wxWindowMSW::GetTextExtent(const wxString
& string
,
1965 int *descent
, int *externalLeading
,
1966 const wxFont
*theFont
) const
1968 wxASSERT_MSG( !theFont
|| theFont
->Ok(),
1969 _T("invalid font in GetTextExtent()") );
1973 fontToUse
= *theFont
;
1975 fontToUse
= GetFont();
1977 WindowHDC
hdc(GetHwnd());
1978 SelectInHDC
selectFont(hdc
, GetHfontOf(fontToUse
));
1982 ::GetTextExtentPoint32(hdc
, string
, string
.length(), &sizeRect
);
1983 GetTextMetrics(hdc
, &tm
);
1990 *descent
= tm
.tmDescent
;
1991 if ( externalLeading
)
1992 *externalLeading
= tm
.tmExternalLeading
;
1995 // ---------------------------------------------------------------------------
1997 // ---------------------------------------------------------------------------
1999 #if wxUSE_MENUS_NATIVE
2001 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2002 // immediately, without waiting for the next event loop iteration
2004 // NB: this function should probably be made public later as it can almost
2005 // surely replace wxYield() elsewhere as well
2006 static void wxYieldForCommandsOnly()
2008 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2009 // want to process it here)
2011 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2013 if ( msg
.message
== WM_QUIT
)
2015 // if we retrieved a WM_QUIT, insert back into the message queue.
2016 ::PostQuitMessage(0);
2020 // luckily (as we don't have access to wxEventLoopImpl method from here
2021 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2023 ::TranslateMessage(&msg
);
2024 ::DispatchMessage(&msg
);
2028 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2030 menu
->SetInvokingWindow(this);
2033 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2035 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2036 x
= mouse
.x
; y
= mouse
.y
;
2039 HWND hWnd
= GetHwnd();
2040 HMENU hMenu
= GetHmenuOf(menu
);
2044 ::ClientToScreen(hWnd
, &point
);
2045 wxCurrentPopupMenu
= menu
;
2046 #if defined(__WXWINCE__)
2047 static const UINT flags
= 0;
2048 #else // !__WXWINCE__
2049 UINT flags
= TPM_RIGHTBUTTON
;
2050 // NT4 doesn't support TPM_RECURSE and simply doesn't show the menu at all
2051 // when it's use, I'm not sure about Win95/98 but prefer to err on the safe
2052 // side and not to use it there neither -- modify the test if it does work
2054 if ( wxGetWinVersion() >= wxWinVersion_5
)
2056 // using TPM_RECURSE allows us to show a popup menu while another menu
2057 // is opened which can be useful and is supported by the other
2058 // platforms, so allow it under Windows too
2059 flags
|= TPM_RECURSE
;
2061 #endif // __WXWINCE__/!__WXWINCE__
2063 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2065 // we need to do it right now as otherwise the events are never going to be
2066 // sent to wxCurrentPopupMenu from HandleCommand()
2068 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2069 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2070 // destroyed as soon as we return (it can be a local variable in the caller
2071 // for example) and so we do need to process the event immediately
2072 wxYieldForCommandsOnly();
2074 wxCurrentPopupMenu
= NULL
;
2076 menu
->SetInvokingWindow(NULL
);
2081 #endif // wxUSE_MENUS_NATIVE
2083 // ===========================================================================
2084 // pre/post message processing
2085 // ===========================================================================
2087 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2090 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2092 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2095 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2097 // wxUniversal implements tab traversal itself
2098 #ifndef __WXUNIVERSAL__
2099 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2101 // intercept dialog navigation keys
2102 MSG
*msg
= (MSG
*)pMsg
;
2104 // here we try to do all the job which ::IsDialogMessage() usually does
2106 if ( msg
->message
== WM_KEYDOWN
)
2108 bool bCtrlDown
= wxIsCtrlDown();
2109 bool bShiftDown
= wxIsShiftDown();
2111 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2112 // don't process it if it's the case (except for Ctrl-Tab/Enter
2113 // combinations which are always processed)
2114 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2116 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2117 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2118 // it, of course, implies them
2119 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2121 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2124 bool bForward
= true,
2125 bWindowChange
= false,
2128 // should we process this message specially?
2129 bool bProcess
= true;
2130 switch ( msg
->wParam
)
2133 if ( (lDlgCode
& DLGC_WANTTAB
) && !bCtrlDown
)
2135 // let the control have the TAB
2138 else // use it for navigation
2140 // Ctrl-Tab cycles thru notebook pages
2141 bWindowChange
= bCtrlDown
;
2142 bForward
= !bShiftDown
;
2149 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2157 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2166 // we treat PageUp/Dn as arrows because chances are that
2167 // a control which needs arrows also needs them for
2168 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2169 if ( (lDlgCode
& DLGC_WANTARROWS
) && !bCtrlDown
)
2171 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
2172 bWindowChange
= true;
2177 if ( (lDlgCode
& DLGC_WANTMESSAGE
) && !bCtrlDown
)
2179 // control wants to process Enter itself, don't
2180 // call IsDialogMessage() which would consume it
2185 // currently active button should get enter press even
2186 // if there is a default button elsewhere so check if
2187 // this window is a button first
2188 wxWindow
*btn
= NULL
;
2189 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2191 // let IsDialogMessage() handle this for all
2192 // buttons except the owner-drawn ones which it
2193 // just seems to ignore
2194 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2195 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2197 // emulate the button click
2198 btn
= wxFindWinFromHandle((WXHWND
)msg
->hwnd
);
2203 else // not a button itself, do we have default button?
2206 tlw
= wxDynamicCast(wxGetTopLevelParent(this),
2210 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2215 if ( btn
&& btn
->IsEnabled() )
2217 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2221 #endif // wxUSE_BUTTON
2224 // map Enter presses into button presses on PDAs
2225 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2226 event
.SetEventObject(this);
2227 if ( GetEventHandler()->ProcessEvent(event
) )
2229 #endif // __WXWINCE__
2239 wxNavigationKeyEvent event
;
2240 event
.SetDirection(bForward
);
2241 event
.SetWindowChange(bWindowChange
);
2242 event
.SetFromTab(bFromTab
);
2243 event
.SetEventObject(this);
2245 if ( GetEventHandler()->ProcessEvent(event
) )
2247 // as we don't call IsDialogMessage(), which would take of
2248 // this by default, we need to manually send this message
2249 // so that controls can change their UI state if needed
2250 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2257 if ( ::IsDialogMessage(GetHwnd(), msg
) )
2259 // IsDialogMessage() did something...
2263 #endif // __WXUNIVERSAL__
2268 // relay mouse move events to the tooltip control
2269 MSG
*msg
= (MSG
*)pMsg
;
2270 if ( msg
->message
== WM_MOUSEMOVE
)
2271 wxToolTip::RelayEvent(pMsg
);
2273 #endif // wxUSE_TOOLTIPS
2278 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2280 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2281 return m_acceleratorTable
.Translate(this, pMsg
);
2285 #endif // wxUSE_ACCEL
2288 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* msg
)
2290 // all tests below have to deal with various bugs/misfeatures of
2291 // IsDialogMessage(): we have to prevent it from being called from our
2292 // MSWProcessMessage() in some situations
2294 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2295 // message even when there is no cancel button and when the message is
2296 // needed by the control itself: in particular, it prevents the tree in
2297 // place edit control from being closed with Escape in a dialog
2298 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_ESCAPE
)
2303 // ::IsDialogMessage() is broken and may sometimes hang the application by
2304 // going into an infinite loop when it tries to find the control to give
2305 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2306 // situations when this may happen and not call it then
2307 if ( msg
->message
!= WM_SYSCHAR
)
2310 // assume we can call it by default
2311 bool canSafelyCallIsDlgMsg
= true;
2313 HWND hwndFocus
= ::GetFocus();
2315 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2316 // ::IsDialogMessage() will also enter an infinite loop, because it will
2317 // recursively check the child windows but not the window itself and so if
2318 // none of the children accepts focus it loops forever (as it only stops
2319 // when it gets back to the window it started from)
2321 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2322 // style has the focus, it can happen. One such possibility is if
2323 // all windows are either toplevel, wxDialog, wxPanel or static
2324 // controls and no window can actually accept keyboard input.
2325 #if !defined(__WXWINCE__)
2326 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2328 // pessimistic by default
2329 canSafelyCallIsDlgMsg
= false;
2330 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2332 node
= node
->GetNext() )
2334 wxWindow
* const win
= node
->GetData();
2335 if ( win
->CanAcceptFocus() &&
2336 !(::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
) &
2337 WS_EX_CONTROLPARENT
) )
2339 // it shouldn't hang...
2340 canSafelyCallIsDlgMsg
= true;
2346 #endif // !__WXWINCE__
2348 if ( canSafelyCallIsDlgMsg
)
2350 // ::IsDialogMessage() can enter in an infinite loop when the
2351 // currently focused window is disabled or hidden and its
2352 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2356 if ( !::IsWindowEnabled(hwndFocus
) ||
2357 !::IsWindowVisible(hwndFocus
) )
2359 // it would enter an infinite loop if we do this!
2360 canSafelyCallIsDlgMsg
= false;
2365 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2367 // it's a top level window, don't go further -- e.g. even
2368 // if the parent of a dialog is disabled, this doesn't
2369 // break navigation inside the dialog
2373 hwndFocus
= ::GetParent(hwndFocus
);
2377 return canSafelyCallIsDlgMsg
;
2380 // ---------------------------------------------------------------------------
2381 // message params unpackers
2382 // ---------------------------------------------------------------------------
2384 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2385 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2387 *id
= LOWORD(wParam
);
2388 *hwnd
= (WXHWND
)lParam
;
2389 *cmd
= HIWORD(wParam
);
2392 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2393 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2395 *state
= LOWORD(wParam
);
2396 *minimized
= HIWORD(wParam
);
2397 *hwnd
= (WXHWND
)lParam
;
2400 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2401 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2403 *code
= LOWORD(wParam
);
2404 *pos
= HIWORD(wParam
);
2405 *hwnd
= (WXHWND
)lParam
;
2408 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2409 WXHDC
*hdc
, WXHWND
*hwnd
)
2411 *hwnd
= (WXHWND
)lParam
;
2412 *hdc
= (WXHDC
)wParam
;
2415 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2416 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2418 *item
= (WXWORD
)wParam
;
2419 *flags
= HIWORD(wParam
);
2420 *hmenu
= (WXHMENU
)lParam
;
2423 // ---------------------------------------------------------------------------
2424 // Main wxWidgets window proc and the window proc for wxWindow
2425 // ---------------------------------------------------------------------------
2427 // Hook for new window just as it's being created, when the window isn't yet
2428 // associated with the handle
2429 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2431 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2432 // window being created and insures that it's always unset back later
2433 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2435 gs_winBeingCreated
= winBeingCreated
;
2438 wxWindowCreationHook::~wxWindowCreationHook()
2440 gs_winBeingCreated
= NULL
;
2444 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2446 // trace all messages - useful for the debugging
2448 wxLogTrace(wxTraceMessages
,
2449 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2450 wxGetMessageName(message
), (long)hWnd
, (long)wParam
, lParam
);
2451 #endif // __WXDEBUG__
2453 wxWindowMSW
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
2455 // when we get the first message for the HWND we just created, we associate
2456 // it with wxWindow stored in gs_winBeingCreated
2457 if ( !wnd
&& gs_winBeingCreated
)
2459 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2460 wnd
= gs_winBeingCreated
;
2461 gs_winBeingCreated
= NULL
;
2462 wnd
->SetHWND((WXHWND
)hWnd
);
2467 if ( wnd
&& wxGUIEventLoop::AllowProcessing(wnd
) )
2468 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2470 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2475 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2477 // did we process the message?
2478 bool processed
= false;
2488 // for most messages we should return 0 when we do process the message
2496 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2499 // return 0 to allow window creation
2500 rc
.result
= mayCreate
? 0 : -1;
2506 // never set processed to true and *always* pass WM_DESTROY to
2507 // DefWindowProc() as Windows may do some internal cleanup when
2508 // processing it and failing to pass the message along may cause
2509 // memory and resource leaks!
2510 (void)HandleDestroy();
2514 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2518 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2521 #if !defined(__WXWINCE__)
2524 LPRECT pRect
= (LPRECT
)lParam
;
2526 rc
.SetLeft(pRect
->left
);
2527 rc
.SetTop(pRect
->top
);
2528 rc
.SetRight(pRect
->right
);
2529 rc
.SetBottom(pRect
->bottom
);
2530 processed
= HandleMoving(rc
);
2532 pRect
->left
= rc
.GetLeft();
2533 pRect
->top
= rc
.GetTop();
2534 pRect
->right
= rc
.GetRight();
2535 pRect
->bottom
= rc
.GetBottom();
2542 LPRECT pRect
= (LPRECT
)lParam
;
2544 rc
.SetLeft(pRect
->left
);
2545 rc
.SetTop(pRect
->top
);
2546 rc
.SetRight(pRect
->right
);
2547 rc
.SetBottom(pRect
->bottom
);
2548 processed
= HandleSizing(rc
);
2550 pRect
->left
= rc
.GetLeft();
2551 pRect
->top
= rc
.GetTop();
2552 pRect
->right
= rc
.GetRight();
2553 pRect
->bottom
= rc
.GetBottom();
2557 #endif // !__WXWINCE__
2559 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2560 case WM_ACTIVATEAPP
:
2561 // This implicitly sends a wxEVT_ACTIVATE_APP event
2562 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2568 WXWORD state
, minimized
;
2570 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2572 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2577 processed
= HandleSetFocus((WXHWND
)(HWND
)wParam
);
2581 processed
= HandleKillFocus((WXHWND
)(HWND
)wParam
);
2584 case WM_PRINTCLIENT
:
2585 processed
= HandlePrintClient((WXHDC
)wParam
);
2591 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2593 processed
= HandlePaint();
2597 processed
= HandlePaint();
2602 #ifdef __WXUNIVERSAL__
2603 // Universal uses its own wxFrame/wxDialog, so we don't receive
2604 // close events unless we have this.
2606 #endif // __WXUNIVERSAL__
2608 // don't let the DefWindowProc() destroy our window - we'll do it
2609 // ourselves in ~wxWindow
2615 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2619 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2620 GET_Y_LPARAM(lParam
),
2624 #ifdef HAVE_TRACKMOUSEEVENT
2626 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2628 if ( m_mouseInWindow
)
2630 GenerateMouseLeave();
2633 // always pass processed back as false, this allows the window
2634 // manager to process the message too. This is needed to
2635 // ensure windows XP themes work properly as the mouse moves
2636 // over widgets like buttons. So don't set processed to true here.
2638 #endif // HAVE_TRACKMOUSEEVENT
2640 #if wxUSE_MOUSEWHEEL
2642 processed
= HandleMouseWheel(wParam
, lParam
);
2646 case WM_LBUTTONDOWN
:
2648 case WM_LBUTTONDBLCLK
:
2649 case WM_RBUTTONDOWN
:
2651 case WM_RBUTTONDBLCLK
:
2652 case WM_MBUTTONDOWN
:
2654 case WM_MBUTTONDBLCLK
:
2656 #ifdef __WXMICROWIN__
2657 // MicroWindows seems to ignore the fact that a window is
2658 // disabled. So catch mouse events and throw them away if
2660 wxWindowMSW
* win
= this;
2663 if (!win
->IsEnabled())
2669 win
= win
->GetParent();
2670 if ( !win
|| win
->IsTopLevel() )
2677 #endif // __WXMICROWIN__
2678 int x
= GET_X_LPARAM(lParam
),
2679 y
= GET_Y_LPARAM(lParam
);
2682 // redirect the event to a static control if necessary by
2683 // finding one under mouse because under CE the static controls
2684 // don't generate mouse events (even with SS_NOTIFY)
2686 if ( GetCapture() == this )
2688 // but don't do it if the mouse is captured by this window
2689 // because then it should really get this event itself
2694 win
= FindWindowForMouseEvent(this, &x
, &y
);
2696 // this should never happen
2697 wxCHECK_MSG( win
, 0,
2698 _T("FindWindowForMouseEvent() returned NULL") );
2701 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
2703 SHRGINFO shrgi
= {0};
2705 shrgi
.cbSize
= sizeof(SHRGINFO
);
2706 shrgi
.hwndClient
= (HWND
) GetHWND();
2710 shrgi
.dwFlags
= SHRG_RETURNCMD
;
2711 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
2713 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
2716 pt
= ClientToScreen(pt
);
2718 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2720 evtCtx
.SetEventObject(this);
2721 if (GetEventHandler()->ProcessEvent(evtCtx
))
2730 #else // !__WXWINCE__
2731 wxWindowMSW
*win
= this;
2732 #endif // __WXWINCE__/!__WXWINCE__
2734 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2736 // if the app didn't eat the event, handle it in the default
2737 // way, that is by giving this window the focus
2740 // for the standard classes their WndProc sets the focus to
2741 // them anyhow and doing it from here results in some weird
2742 // problems, so don't do it for them (unnecessary anyhow)
2743 if ( !win
->IsOfStandardClass() )
2745 if ( message
== WM_LBUTTONDOWN
&& win
->CanAcceptFocus() )
2757 case MM_JOY1BUTTONDOWN
:
2758 case MM_JOY2BUTTONDOWN
:
2759 case MM_JOY1BUTTONUP
:
2760 case MM_JOY2BUTTONUP
:
2761 processed
= HandleJoystickEvent(message
,
2762 GET_X_LPARAM(lParam
),
2763 GET_Y_LPARAM(lParam
),
2766 #endif // __WXMICROWIN__
2772 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2774 processed
= HandleCommand(id
, cmd
, hwnd
);
2779 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2782 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
2783 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
2784 // apparently doesn't always behave properly and needs some help
2785 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
2786 case WM_NOTIFYFORMAT
:
2787 if ( lParam
== NF_QUERY
)
2790 rc
.result
= NFR_UNICODE
;
2793 #endif // wxUSE_UNICODE_MSLU
2795 // for these messages we must return true if process the message
2798 case WM_MEASUREITEM
:
2800 int idCtrl
= (UINT
)wParam
;
2801 if ( message
== WM_DRAWITEM
)
2803 processed
= MSWOnDrawItem(idCtrl
,
2804 (WXDRAWITEMSTRUCT
*)lParam
);
2808 processed
= MSWOnMeasureItem(idCtrl
,
2809 (WXMEASUREITEMSTRUCT
*)lParam
);
2816 #endif // defined(WM_DRAWITEM)
2819 if ( !IsOfStandardClass() || HasFlag(wxWANTS_CHARS
) )
2821 // we always want to get the char events
2822 rc
.result
= DLGC_WANTCHARS
;
2824 if ( HasFlag(wxWANTS_CHARS
) )
2826 // in fact, we want everything
2827 rc
.result
|= DLGC_WANTARROWS
|
2834 //else: get the dlg code from the DefWindowProc()
2839 // If this has been processed by an event handler, return 0 now
2840 // (we've handled it).
2841 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
2842 if ( m_lastKeydownProcessed
)
2851 // we consider these messages "not interesting" to OnChar, so
2852 // just don't do anything more with them
2862 // avoid duplicate messages to OnChar for these ASCII keys:
2863 // they will be translated by TranslateMessage() and received
2895 // but set processed to false, not true to still pass them
2896 // to the control's default window proc - otherwise
2897 // built-in keyboard handling won't work
2902 // special case of VK_APPS: treat it the same as right mouse
2903 // click because both usually pop up a context menu
2905 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
2910 // do generate a CHAR event
2911 processed
= HandleChar((WORD
)wParam
, lParam
);
2914 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
2921 // special case of VK_APPS: treat it the same as right mouse button
2922 if ( wParam
== VK_APPS
)
2924 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
2929 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
2934 case WM_CHAR
: // Always an ASCII character
2935 if ( m_lastKeydownProcessed
)
2937 // The key was handled in the EVT_KEY_DOWN and handling
2938 // a key in an EVT_KEY_DOWN handler is meant, by
2939 // design, to prevent EVT_CHARs from happening
2940 m_lastKeydownProcessed
= false;
2945 processed
= HandleChar((WORD
)wParam
, lParam
, true);
2951 processed
= HandleHotKey((WORD
)wParam
, lParam
);
2953 #endif // wxUSE_HOTKEY
2960 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
2962 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
2968 // CTLCOLOR messages are sent by children to query the parent for their
2970 #ifndef __WXMICROWIN__
2971 case WM_CTLCOLORMSGBOX
:
2972 case WM_CTLCOLOREDIT
:
2973 case WM_CTLCOLORLISTBOX
:
2974 case WM_CTLCOLORBTN
:
2975 case WM_CTLCOLORDLG
:
2976 case WM_CTLCOLORSCROLLBAR
:
2977 case WM_CTLCOLORSTATIC
:
2981 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
2983 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
2986 #endif // !__WXMICROWIN__
2988 case WM_SYSCOLORCHANGE
:
2989 // the return value for this message is ignored
2990 processed
= HandleSysColorChange();
2993 #if !defined(__WXWINCE__)
2994 case WM_DISPLAYCHANGE
:
2995 processed
= HandleDisplayChange();
2999 case WM_PALETTECHANGED
:
3000 processed
= HandlePaletteChanged((WXHWND
) (HWND
) wParam
);
3003 case WM_CAPTURECHANGED
:
3004 processed
= HandleCaptureChanged((WXHWND
) (HWND
) lParam
);
3007 case WM_SETTINGCHANGE
:
3008 processed
= HandleSettingChange(wParam
, lParam
);
3011 case WM_QUERYNEWPALETTE
:
3012 processed
= HandleQueryNewPalette();
3016 processed
= HandleEraseBkgnd((WXHDC
)(HDC
)wParam
);
3019 // we processed the message, i.e. erased the background
3024 #if !defined(__WXWINCE__)
3026 processed
= HandleDropFiles(wParam
);
3031 processed
= HandleInitDialog((WXHWND
)(HWND
)wParam
);
3035 // we never set focus from here
3040 #if !defined(__WXWINCE__)
3041 case WM_QUERYENDSESSION
:
3042 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3046 processed
= HandleEndSession(wParam
!= 0, lParam
);
3049 case WM_GETMINMAXINFO
:
3050 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3055 processed
= HandleSetCursor((WXHWND
)(HWND
)wParam
,
3056 LOWORD(lParam
), // hit test
3057 HIWORD(lParam
)); // mouse msg
3061 // returning TRUE stops the DefWindowProc() from further
3062 // processing this message - exactly what we need because we've
3063 // just set the cursor.
3068 #if wxUSE_ACCESSIBILITY
3071 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3072 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3074 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3076 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3082 #if defined(WM_HELP)
3085 // by default, WM_HELP is propagated by DefWindowProc() upwards
3086 // to the window parent but as we do it ourselves already
3087 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3088 // to get the other events if we process this message at all
3091 // WM_HELP doesn't use lParam under CE
3093 HELPINFO
* info
= (HELPINFO
*) lParam
;
3094 if ( info
->iContextType
== HELPINFO_WINDOW
)
3096 #endif // !__WXWINCE__
3097 wxHelpEvent helpEvent
3102 wxGetMousePosition() // what else?
3104 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3108 helpEvent
.SetEventObject(this);
3109 GetEventHandler()->ProcessEvent(helpEvent
);
3112 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3114 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3115 helpEvent
.SetEventObject(this);
3116 GetEventHandler()->ProcessEvent(helpEvent
);
3119 else // unknown help event?
3123 #endif // !__WXWINCE__
3128 #if !defined(__WXWINCE__)
3129 case WM_CONTEXTMENU
:
3131 // we don't convert from screen to client coordinates as
3132 // the event may be handled by a parent window
3133 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3135 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3137 // we could have got an event from our child, reflect it back
3138 // to it if this is the case
3139 wxWindowMSW
*win
= NULL
;
3140 if ( (WXHWND
)wParam
!= m_hWnd
)
3142 win
= FindItemByHWND((WXHWND
)wParam
);
3148 evtCtx
.SetEventObject(win
);
3149 processed
= win
->GetEventHandler()->ProcessEvent(evtCtx
);
3155 // we're only interested in our own menus, not MF_SYSMENU
3156 if ( HIWORD(wParam
) == MF_POPUP
)
3158 // handle menu chars for ownerdrawn menu items
3159 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3160 if ( i
!= wxNOT_FOUND
)
3162 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3169 case WM_POWERBROADCAST
:
3172 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3173 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3176 #endif // __WXWINCE__
3179 // try a custom message handler
3180 const MSWMessageHandlers::const_iterator
3181 i
= gs_messageHandlers
.find(message
);
3182 if ( i
!= gs_messageHandlers
.end() )
3184 processed
= (*i
->second
)(this, message
, wParam
, lParam
);
3191 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
3192 wxGetMessageName(message
));
3193 #endif // __WXDEBUG__
3194 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3200 // ----------------------------------------------------------------------------
3201 // wxWindow <-> HWND map
3202 // ----------------------------------------------------------------------------
3204 wxWinHashTable
*wxWinHandleHash
= NULL
;
3206 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
3208 return (wxWindow
*)wxWinHandleHash
->Get((long)hWnd
);
3211 void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
)
3213 // adding NULL hWnd is (first) surely a result of an error and
3214 // (secondly) breaks menu command processing
3215 wxCHECK_RET( hWnd
!= (HWND
)NULL
,
3216 wxT("attempt to add a NULL hWnd to window list ignored") );
3218 wxWindow
*oldWin
= wxFindWinFromHandle((WXHWND
) hWnd
);
3220 if ( oldWin
&& (oldWin
!= win
) )
3222 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
3223 (int) hWnd
, win
->GetClassInfo()->GetClassName());
3226 #endif // __WXDEBUG__
3229 wxWinHandleHash
->Put((long)hWnd
, (wxWindow
*)win
);
3233 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3235 wxWinHandleHash
->Delete((long)win
->GetHWND());
3238 // ----------------------------------------------------------------------------
3239 // various MSW speciic class dependent functions
3240 // ----------------------------------------------------------------------------
3242 // Default destroyer - override if you destroy it in some other way
3243 // (e.g. with MDI child windows)
3244 void wxWindowMSW::MSWDestroyWindow()
3248 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3251 int& w
, int& h
) const
3253 // yes, those are just some arbitrary hardcoded numbers
3254 static const int DEFAULT_Y
= 200;
3256 bool nonDefault
= false;
3258 if ( pos
.x
== wxDefaultCoord
)
3260 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
3261 // can just as well set it to CW_USEDEFAULT as well
3267 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
3268 // neither because it is not handled as a special value by Windows then
3269 // and so we have to choose some default value for it
3271 y
= pos
.y
== wxDefaultCoord
? DEFAULT_Y
: pos
.y
;
3277 NB: there used to be some code here which set the initial size of the
3278 window to the client size of the parent if no explicit size was
3279 specified. This was wrong because wxWidgets programs often assume
3280 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3281 it. To see why, you should understand that Windows sends WM_SIZE from
3282 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3283 from some base class ctor and so this WM_SIZE is not processed in the
3284 real class' OnSize() (because it's not fully constructed yet and the
3285 event goes to some base class OnSize() instead). So the WM_SIZE we
3286 rely on is the one sent when the parent frame resizes its children
3287 but here is the problem: if the child already has just the right
3288 size, nothing will happen as both wxWidgets and Windows check for
3289 this and ignore any attempts to change the window size to the size it
3290 already has - so no WM_SIZE would be sent.
3294 // we don't use CW_USEDEFAULT here for several reasons:
3296 // 1. it results in huge frames on modern screens (1000*800 is not
3297 // uncommon on my 1280*1024 screen) which is way too big for a half
3298 // empty frame of most of wxWidgets samples for example)
3300 // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
3301 // the default is for whatever reason 8*8 which breaks client <->
3302 // window size calculations (it would be nice if it didn't, but it
3303 // does and the simplest way to fix it seemed to change the broken
3304 // default size anyhow)
3306 // 3. there is just no advantage in doing it: with x and y it is
3307 // possible that [future versions of] Windows position the new top
3308 // level window in some smart way which we can't do, but we can
3309 // guess a reasonably good size for a new window just as well
3312 // However, on PocketPC devices, we must use the default
3313 // size if possible.
3315 if (size
.x
== wxDefaultCoord
)
3319 if (size
.y
== wxDefaultCoord
)
3324 if ( size
.x
== wxDefaultCoord
|| size
.y
== wxDefaultCoord
)
3328 w
= WidthDefault(size
.x
);
3329 h
= HeightDefault(size
.y
);
3332 AdjustForParentClientOrigin(x
, y
);
3337 WXHWND
wxWindowMSW::MSWGetParent() const
3339 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3342 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3343 const wxChar
*title
,
3347 WXDWORD extendedStyle
)
3349 // choose the position/size for the new window
3351 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3353 // controlId is menu handle for the top level windows, so set it to 0
3354 // unless we're creating a child window
3355 int controlId
= style
& WS_CHILD
? GetId() : 0;
3357 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3358 // which is the same but without CS_[HV]REDRAW class styles so using it
3359 // ensures that the window is not fully repainted on each resize
3360 wxString
className(wclass
);
3361 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3363 className
+= wxT("NR");
3366 // do create the window
3367 wxWindowCreationHook
hook(this);
3369 m_hWnd
= (WXHWND
)::CreateWindowEx
3373 title
? title
: (const wxChar
*)m_windowName
.c_str(),
3376 (HWND
)MSWGetParent(),
3379 NULL
// no extra data
3384 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3389 SubclassWin(m_hWnd
);
3394 // ===========================================================================
3395 // MSW message handlers
3396 // ===========================================================================
3398 // ---------------------------------------------------------------------------
3400 // ---------------------------------------------------------------------------
3402 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3404 #ifndef __WXMICROWIN__
3405 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3406 HWND hWnd
= hdr
->hwndFrom
;
3407 wxWindow
*win
= wxFindWinFromHandle((WXHWND
)hWnd
);
3409 // if the control is one of our windows, let it handle the message itself
3412 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3415 // VZ: why did we do it? normally this is unnecessary and, besides, it
3416 // breaks the message processing for the toolbars because the tooltip
3417 // notifications were being forwarded to the toolbar child controls
3418 // (if it had any) before being passed to the toolbar itself, so in my
3419 // example the tooltip for the combobox was always shown instead of the
3420 // correct button tooltips
3422 // try all our children
3423 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3426 wxWindow
*child
= node
->GetData();
3427 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3432 node
= node
->GetNext();
3436 // by default, handle it ourselves
3437 return MSWOnNotify(idCtrl
, lParam
, result
);
3438 #else // __WXMICROWIN__
3445 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3447 const wxString
& ttip
)
3449 // I don't know why it happens, but the versions of comctl32.dll starting
3450 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3451 // this message is supposed to be sent to Unicode programs only) -- hence
3452 // we need to handle it as well, otherwise no tooltips will be shown in
3455 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3458 // not a tooltip message or no tooltip to show anyhow
3463 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3465 // We don't want to use the szText buffer because it has a limit of 80
3466 // bytes and this is not enough, especially for Unicode build where it
3467 // limits the tooltip string length to only 40 characters
3469 // The best would be, of course, to not impose any length limitations at
3470 // all but then the buffer would have to be dynamic and someone would have
3471 // to free it and we don't have the tooltip owner object here any more, so
3472 // for now use our own static buffer with a higher fixed max length.
3474 // Note that using a static buffer should not be a problem as only a single
3475 // tooltip can be shown at the same time anyhow.
3477 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3479 // We need to convert tooltip from multi byte to Unicode on the fly.
3480 static wchar_t buf
[513];
3482 // Truncate tooltip length if needed as otherwise we might not have
3483 // enough space for it in the buffer and MultiByteToWideChar() would
3485 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3487 // Convert to WideChar without adding the NULL character. The NULL
3488 // character is added afterwards (this is more efficient).
3489 int len
= ::MultiByteToWideChar
3501 wxLogLastError(_T("MultiByteToWideChar()"));
3505 ttText
->lpszText
= (LPSTR
) buf
;
3507 else // TTN_NEEDTEXTA
3508 #endif // !wxUSE_UNICODE
3510 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3511 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3512 // to copy the string we have into the buffer
3513 static wxChar buf
[513];
3514 wxStrncpy(buf
, ttip
.c_str(), WXSIZEOF(buf
) - 1);
3515 buf
[WXSIZEOF(buf
) - 1] = _T('\0');
3516 ttText
->lpszText
= buf
;
3522 #endif // wxUSE_TOOLTIPS
3524 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3526 WXLPARAM
* WXUNUSED(result
))
3531 NMHDR
* hdr
= (NMHDR
*)lParam
;
3532 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3539 wxUnusedVar(lParam
);
3540 #endif // wxUSE_TOOLTIPS
3545 // ---------------------------------------------------------------------------
3546 // end session messages
3547 // ---------------------------------------------------------------------------
3549 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3551 #ifdef ENDSESSION_LOGOFF
3552 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3553 event
.SetEventObject(wxTheApp
);
3554 event
.SetCanVeto(true);
3555 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3557 bool rc
= wxTheApp
->ProcessEvent(event
);
3561 // we may end only if the app didn't veto session closing (double
3563 *mayEnd
= !event
.GetVeto();
3568 wxUnusedVar(logOff
);
3569 wxUnusedVar(mayEnd
);
3574 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3576 #ifdef ENDSESSION_LOGOFF
3577 // do nothing if the session isn't ending
3582 if ( (this != wxTheApp
->GetTopWindow()) )
3585 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3586 event
.SetEventObject(wxTheApp
);
3587 event
.SetCanVeto(false);
3588 event
.SetLoggingOff( (logOff
== (long)ENDSESSION_LOGOFF
) );
3590 return wxTheApp
->ProcessEvent(event
);
3592 wxUnusedVar(endSession
);
3593 wxUnusedVar(logOff
);
3598 // ---------------------------------------------------------------------------
3599 // window creation/destruction
3600 // ---------------------------------------------------------------------------
3602 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3605 // VZ: why is this commented out for WinCE? If it doesn't support
3606 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3607 // not with multiple #ifdef's!
3609 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3610 EnsureParentHasControlParentStyle(GetParent());
3611 #endif // !__WXWINCE__
3618 bool wxWindowMSW::HandleDestroy()
3622 // delete our drop target if we've got one
3623 #if wxUSE_DRAG_AND_DROP
3624 if ( m_dropTarget
!= NULL
)
3626 m_dropTarget
->Revoke(m_hWnd
);
3628 delete m_dropTarget
;
3629 m_dropTarget
= NULL
;
3631 #endif // wxUSE_DRAG_AND_DROP
3633 // WM_DESTROY handled
3637 // ---------------------------------------------------------------------------
3639 // ---------------------------------------------------------------------------
3641 bool wxWindowMSW::HandleActivate(int state
,
3642 bool WXUNUSED(minimized
),
3643 WXHWND
WXUNUSED(activate
))
3645 wxActivateEvent
event(wxEVT_ACTIVATE
,
3646 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3648 event
.SetEventObject(this);
3650 return GetEventHandler()->ProcessEvent(event
);
3653 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3655 // Strangly enough, some controls get set focus events when they are being
3656 // deleted, even if they already had focus before.
3657 if ( m_isBeingDeleted
)
3662 // notify the parent keeping track of focus for the kbd navigation
3663 // purposes that we got it
3664 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3665 (void)GetEventHandler()->ProcessEvent(eventFocus
);
3671 m_caret
->OnSetFocus();
3673 #endif // wxUSE_CARET
3676 // If it's a wxTextCtrl don't send the event as it will be done
3677 // after the control gets to process it from EN_FOCUS handler
3678 if ( wxDynamicCastThis(wxTextCtrl
) )
3682 #endif // wxUSE_TEXTCTRL
3684 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3685 event
.SetEventObject(this);
3687 // wxFindWinFromHandle() may return NULL, it is ok
3688 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3690 return GetEventHandler()->ProcessEvent(event
);
3693 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
3699 m_caret
->OnKillFocus();
3701 #endif // wxUSE_CARET
3704 // If it's a wxTextCtrl don't send the event as it will be done
3705 // after the control gets to process it.
3706 wxTextCtrl
*ctrl
= wxDynamicCastThis(wxTextCtrl
);
3713 // Don't send the event when in the process of being deleted. This can
3714 // only cause problems if the event handler tries to access the object.
3715 if ( m_isBeingDeleted
)
3720 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3721 event
.SetEventObject(this);
3723 // wxFindWinFromHandle() may return NULL, it is ok
3724 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3726 return GetEventHandler()->ProcessEvent(event
);
3729 // ---------------------------------------------------------------------------
3731 // ---------------------------------------------------------------------------
3733 void wxWindowMSW::SetLabel( const wxString
& label
)
3735 SetWindowText(GetHwnd(), label
.c_str());
3738 wxString
wxWindowMSW::GetLabel() const
3740 return wxGetWindowText(GetHWND());
3743 // ---------------------------------------------------------------------------
3745 // ---------------------------------------------------------------------------
3747 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
3749 wxShowEvent
event(GetId(), show
);
3750 event
.SetEventObject(this);
3752 return GetEventHandler()->ProcessEvent(event
);
3755 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
3757 wxInitDialogEvent
event(GetId());
3758 event
.SetEventObject(this);
3760 return GetEventHandler()->ProcessEvent(event
);
3763 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
3765 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
3766 wxUnusedVar(wParam
);
3768 #else // __WXMICROWIN__
3769 HDROP hFilesInfo
= (HDROP
) wParam
;
3771 // Get the total number of files dropped
3772 UINT gwFilesDropped
= ::DragQueryFile
3780 wxString
*files
= new wxString
[gwFilesDropped
];
3781 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
3783 // first get the needed buffer length (+1 for terminating NUL)
3784 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
3786 // and now get the file name
3787 ::DragQueryFile(hFilesInfo
, wIndex
,
3788 wxStringBuffer(files
[wIndex
], len
), len
);
3790 DragFinish (hFilesInfo
);
3792 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
3793 event
.SetEventObject(this);
3796 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
3797 event
.m_pos
.x
= dropPoint
.x
;
3798 event
.m_pos
.y
= dropPoint
.y
;
3800 return GetEventHandler()->ProcessEvent(event
);
3805 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
3807 int WXUNUSED(mouseMsg
))
3809 #ifndef __WXMICROWIN__
3810 // the logic is as follows:
3811 // -1. don't set cursor for non client area, including but not limited to
3812 // the title bar, scrollbars, &c
3813 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
3814 // 1. if we have the cursor set it unless wxIsBusy()
3815 // 2. if we're a top level window, set some cursor anyhow
3816 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
3818 if ( nHitTest
!= HTCLIENT
)
3823 HCURSOR hcursor
= 0;
3825 // first ask the user code - it may wish to set the cursor in some very
3826 // specific way (for example, depending on the current position)
3829 if ( !::GetCursorPosWinCE(&pt
))
3831 if ( !::GetCursorPos(&pt
) )
3834 wxLogLastError(wxT("GetCursorPos"));
3839 ScreenToClient(&x
, &y
);
3840 wxSetCursorEvent
event(x
, y
);
3842 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
3843 if ( processedEvtSetCursor
&& event
.HasCursor() )
3845 hcursor
= GetHcursorOf(event
.GetCursor());
3850 bool isBusy
= wxIsBusy();
3852 // the test for processedEvtSetCursor is here to prevent using m_cursor
3853 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3854 // it - this is a way to say that our cursor shouldn't be used for this
3856 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
3858 hcursor
= GetHcursorOf(m_cursor
);
3865 hcursor
= wxGetCurrentBusyCursor();
3867 else if ( !hcursor
)
3869 const wxCursor
*cursor
= wxGetGlobalCursor();
3870 if ( cursor
&& cursor
->Ok() )
3872 hcursor
= GetHcursorOf(*cursor
);
3880 // wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3882 ::SetCursor(hcursor
);
3884 // cursor set, stop here
3887 #endif // __WXMICROWIN__
3889 // pass up the window chain
3893 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
3894 WXLPARAM
WXUNUSED(lParam
),
3895 bool *WXUNUSED_IN_WINCE(vetoed
))
3901 wxEventType evtType
;
3904 case PBT_APMQUERYSUSPEND
:
3905 evtType
= wxEVT_POWER_SUSPENDING
;
3908 case PBT_APMQUERYSUSPENDFAILED
:
3909 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
3912 case PBT_APMSUSPEND
:
3913 evtType
= wxEVT_POWER_SUSPENDED
;
3916 case PBT_APMRESUMESUSPEND
:
3917 #ifdef PBT_APMRESUMEAUTOMATIC
3918 case PBT_APMRESUMEAUTOMATIC
:
3920 evtType
= wxEVT_POWER_RESUME
;
3924 wxLogDebug(_T("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
3927 // these messages are currently not mapped to wx events
3928 case PBT_APMQUERYSTANDBY
:
3929 case PBT_APMQUERYSTANDBYFAILED
:
3930 case PBT_APMSTANDBY
:
3931 case PBT_APMRESUMESTANDBY
:
3932 case PBT_APMBATTERYLOW
:
3933 case PBT_APMPOWERSTATUSCHANGE
:
3934 case PBT_APMOEMEVENT
:
3935 case PBT_APMRESUMECRITICAL
:
3936 evtType
= wxEVT_NULL
;
3940 // don't handle unknown messages
3941 if ( evtType
== wxEVT_NULL
)
3944 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
3946 wxPowerEvent
event(evtType
);
3947 if ( !GetEventHandler()->ProcessEvent(event
) )
3950 *vetoed
= event
.IsVetoed();
3956 bool wxWindowMSW::IsDoubleBuffered() const
3958 for ( const wxWindowMSW
*wnd
= this;
3959 wnd
&& !wnd
->IsTopLevel(); wnd
=
3962 if ( ::GetWindowLong(GetHwndOf(wnd
), GWL_EXSTYLE
) & WS_EX_COMPOSITED
)
3969 // ---------------------------------------------------------------------------
3970 // owner drawn stuff
3971 // ---------------------------------------------------------------------------
3973 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
3974 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
3975 #define WXUNUSED_UNLESS_ODRAWN(param) param
3977 #define WXUNUSED_UNLESS_ODRAWN(param)
3981 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
3982 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
3984 #if wxUSE_OWNER_DRAWN
3986 #if wxUSE_MENUS_NATIVE
3987 // is it a menu item?
3988 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
3989 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
3991 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
3993 // see comment before the same test in MSWOnMeasureItem() below
3997 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
3998 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
4000 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4001 // the DC from being released
4002 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
4003 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
4004 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
4005 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
4007 return pMenuItem
->OnDrawItem
4011 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
4012 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
4015 #endif // wxUSE_MENUS_NATIVE
4017 #endif // USE_OWNER_DRAWN
4019 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4021 #if wxUSE_OWNER_DRAWN
4022 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4023 #else // !wxUSE_OWNER_DRAWN
4024 // we may still have owner-drawn buttons internally because we have to make
4025 // them owner-drawn to support colour change
4028 wxDynamicCast(FindItem(id
), wxButton
)
4033 #endif // USE_OWNER_DRAWN
4037 return item
->MSWOnDraw(itemStruct
);
4040 #endif // wxUSE_CONTROLS
4046 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4048 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4049 // is it a menu item?
4050 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4051 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4053 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4055 // according to Carsten Fuchs the pointer may be NULL under XP if an
4056 // MDI child frame is initially maximized, see this for more info:
4057 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4059 // so silently ignore it instead of asserting
4063 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4064 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
4067 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4069 pMeasureStruct
->itemWidth
= w
;
4070 pMeasureStruct
->itemHeight
= h
;
4075 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4078 return item
->MSWOnMeasure(itemStruct
);
4082 wxUnusedVar(itemStruct
);
4083 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4088 // ---------------------------------------------------------------------------
4089 // colours and palettes
4090 // ---------------------------------------------------------------------------
4092 bool wxWindowMSW::HandleSysColorChange()
4094 wxSysColourChangedEvent event
;
4095 event
.SetEventObject(this);
4097 (void)GetEventHandler()->ProcessEvent(event
);
4099 // always let the system carry on the default processing to allow the
4100 // native controls to react to the colours update
4104 bool wxWindowMSW::HandleDisplayChange()
4106 wxDisplayChangedEvent event
;
4107 event
.SetEventObject(this);
4109 return GetEventHandler()->ProcessEvent(event
);
4112 #ifndef __WXMICROWIN__
4114 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4116 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4120 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4123 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4125 #endif // wxUSE_CONTROLS
4128 return *brush
!= NULL
;
4131 #endif // __WXMICROWIN__
4133 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4136 // same as below except we don't respond to our own messages
4137 if ( hWndPalChange
!= GetHWND() )
4139 // check to see if we our our parents have a custom palette
4140 wxWindowMSW
*win
= this;
4141 while ( win
&& !win
->HasCustomPalette() )
4143 win
= win
->GetParent();
4146 if ( win
&& win
->HasCustomPalette() )
4148 // realize the palette to see whether redrawing is needed
4149 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4150 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4151 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4153 int result
= ::RealizePalette(hdc
);
4155 // restore the palette (before releasing the DC)
4156 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4157 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4158 ::RealizePalette(hdc
);
4159 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4161 // now check for the need to redraw
4163 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4167 #endif // wxUSE_PALETTE
4169 wxPaletteChangedEvent
event(GetId());
4170 event
.SetEventObject(this);
4171 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4173 return GetEventHandler()->ProcessEvent(event
);
4176 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4178 // notify windows on the capture stack about lost capture
4179 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4180 wxWindowBase::NotifyCaptureLost();
4182 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4183 wxMouseCaptureChangedEvent
event(GetId(), win
);
4184 event
.SetEventObject(this);
4185 return GetEventHandler()->ProcessEvent(event
);
4188 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4190 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4191 // we need to send this to child windows (it is only sent to top-level
4192 // windows) so {list,tree}ctrls can adjust their font size if necessary
4193 // this is exactly how explorer does it to enable the font size changes
4195 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4198 // top-level windows already get this message from the system
4199 wxWindow
*win
= node
->GetData();
4200 if ( !win
->IsTopLevel() )
4202 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4205 node
= node
->GetNext();
4208 // let the system handle it
4212 bool wxWindowMSW::HandleQueryNewPalette()
4216 // check to see if we our our parents have a custom palette
4217 wxWindowMSW
*win
= this;
4218 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4219 if (win
->HasCustomPalette()) {
4220 /* realize the palette to see whether redrawing is needed */
4221 HDC hdc
= ::GetDC((HWND
) GetHWND());
4222 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4223 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4225 int result
= ::RealizePalette(hdc
);
4226 /* restore the palette (before releasing the DC) */
4227 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4228 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4229 ::RealizePalette(hdc
);
4230 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4231 /* now check for the need to redraw */
4233 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4235 #endif // wxUSE_PALETTE
4237 wxQueryNewPaletteEvent
event(GetId());
4238 event
.SetEventObject(this);
4240 return GetEventHandler()->ProcessEvent(event
) && event
.GetPaletteRealized();
4243 // Responds to colour changes: passes event on to children.
4244 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4246 // the top level window also reset the standard colour map as it might have
4247 // changed (there is no need to do it for the non top level windows as we
4248 // only have to do it once)
4252 gs_hasStdCmap
= false;
4254 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4257 // Only propagate to non-top-level windows because Windows already
4258 // sends this event to all top-level ones
4259 wxWindow
*win
= node
->GetData();
4260 if ( !win
->IsTopLevel() )
4262 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4263 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4264 // the standard controls
4265 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4268 node
= node
->GetNext();
4272 extern wxCOLORMAP
*wxGetStdColourMap()
4274 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4275 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4277 if ( !gs_hasStdCmap
)
4279 static bool s_coloursInit
= false;
4281 if ( !s_coloursInit
)
4283 // When a bitmap is loaded, the RGB values can change (apparently
4284 // because Windows adjusts them to care for the old programs always
4285 // using 0xc0c0c0 while the transparent colour for the new Windows
4286 // versions is different). But we do this adjustment ourselves so
4287 // we want to avoid Windows' "help" and for this we need to have a
4288 // reference bitmap which can tell us what the RGB values change
4290 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4291 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
4292 if ( stdColourBitmap
.Ok() )
4294 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4295 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4296 _T("forgot to update wxBITMAP_STD_COLOURS!") );
4299 memDC
.SelectObject(stdColourBitmap
);
4302 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4304 memDC
.GetPixel(i
, 0, &colour
);
4305 s_stdColours
[i
] = wxColourToRGB(colour
);
4308 else // wxBITMAP_STD_COLOURS couldn't be loaded
4310 s_stdColours
[0] = RGB(000,000,000); // black
4311 s_stdColours
[1] = RGB(128,128,128); // dark grey
4312 s_stdColours
[2] = RGB(192,192,192); // light grey
4313 s_stdColours
[3] = RGB(255,255,255); // white
4314 //s_stdColours[4] = RGB(000,000,255); // blue
4315 //s_stdColours[5] = RGB(255,000,255); // magenta
4318 s_coloursInit
= true;
4321 gs_hasStdCmap
= true;
4323 // create the colour map
4324 #define INIT_CMAP_ENTRY(col) \
4325 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4326 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4328 INIT_CMAP_ENTRY(BTNTEXT
);
4329 INIT_CMAP_ENTRY(BTNSHADOW
);
4330 INIT_CMAP_ENTRY(BTNFACE
);
4331 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4333 #undef INIT_CMAP_ENTRY
4339 // ---------------------------------------------------------------------------
4341 // ---------------------------------------------------------------------------
4343 bool wxWindowMSW::HandlePaint()
4345 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4347 wxLogLastError(wxT("CreateRectRgn"));
4348 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4349 wxLogLastError(wxT("GetUpdateRgn"));
4351 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4353 wxPaintEvent
event(m_windowId
);
4354 event
.SetEventObject(this);
4356 bool processed
= GetEventHandler()->ProcessEvent(event
);
4358 // note that we must generate NC event after the normal one as otherwise
4359 // BeginPaint() will happily overwrite our decorations with the background
4361 wxNcPaintEvent
eventNc(m_windowId
);
4362 eventNc
.SetEventObject(this);
4363 GetEventHandler()->ProcessEvent(eventNc
);
4368 // Can be called from an application's OnPaint handler
4369 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4371 #ifdef __WXUNIVERSAL__
4374 HDC hDC
= (HDC
) wxPaintDC::FindDCInCache((wxWindow
*) event
.GetEventObject());
4377 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4382 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4384 wxDCTemp
dc(hdc
, GetClientSize());
4387 dc
.SetWindow((wxWindow
*)this);
4389 wxEraseEvent
event(m_windowId
, &dc
);
4390 event
.SetEventObject(this);
4391 bool rc
= GetEventHandler()->ProcessEvent(event
);
4393 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
4394 dc
.SelectOldObjects(hdc
);
4399 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
4401 // standard non top level controls (i.e. except the dialogs) always erase
4402 // their background themselves in HandleCtlColor() or have some control-
4403 // specific ways to set the colours (common controls)
4404 if ( IsOfStandardClass() && !IsTopLevel() )
4410 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
4412 // don't skip the event here, custom background means that the app
4413 // is drawing it itself in its OnPaint(), so don't draw it at all
4414 // now to avoid flicker
4419 // do default background painting
4420 if ( !DoEraseBackground(GetHdcOf(*event
.GetDC())) )
4422 // let the system paint the background
4427 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4429 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4433 wxFillRect(GetHwnd(), (HDC
)hDC
, hbr
);
4439 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
), WXHWND hWnd
)
4443 // our background colour applies to:
4444 // 1. this window itself, always
4445 // 2. all children unless the colour is "not inheritable"
4446 // 3. even if it is not inheritable, our immediate transparent
4447 // children should still inherit it -- but not any transparent
4448 // children because it would look wrong if a child of non
4449 // transparent child would show our bg colour when the child itself
4451 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
4454 (win
&& win
->HasTransparentBackground() &&
4455 win
->GetParent() == this) )
4457 // draw children with the same colour as the parent
4459 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4461 return (WXHBRUSH
)GetHbrushOf(*brush
);
4468 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
, WXHWND hWndToPaint
)
4471 hWndToPaint
= GetHWND();
4473 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4475 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, hWndToPaint
);
4479 // background is not inherited beyond top level windows
4480 if ( win
->IsTopLevel() )
4487 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4489 // we receive this message when DrawThemeParentBackground() is
4490 // called from def window proc of several controls under XP and we
4491 // must draw properly themed background here
4493 // note that naively I'd expect filling the client rect with the
4494 // brush returned by MSWGetBgBrush() work -- but for some reason it
4495 // doesn't and we have to call parents MSWPrintChild() which is
4496 // supposed to call DrawThemeBackground() with appropriate params
4498 // also note that in this case lParam == PRF_CLIENT but we're
4499 // clearly expected to paint the background and nothing else!
4501 if ( IsTopLevel() || InheritsBackgroundColour() )
4504 // sometimes we don't want the parent to handle it at all, instead
4505 // return whatever value this window wants
4506 if ( !MSWShouldPropagatePrintChild() )
4507 return MSWPrintChild(hDC
, (wxWindow
*)this);
4509 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4511 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4514 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4521 // ---------------------------------------------------------------------------
4522 // moving and resizing
4523 // ---------------------------------------------------------------------------
4525 bool wxWindowMSW::HandleMinimize()
4527 wxIconizeEvent
event(m_windowId
);
4528 event
.SetEventObject(this);
4530 return GetEventHandler()->ProcessEvent(event
);
4533 bool wxWindowMSW::HandleMaximize()
4535 wxMaximizeEvent
event(m_windowId
);
4536 event
.SetEventObject(this);
4538 return GetEventHandler()->ProcessEvent(event
);
4541 bool wxWindowMSW::HandleMove(int x
, int y
)
4544 wxMoveEvent
event(point
, m_windowId
);
4545 event
.SetEventObject(this);
4547 return GetEventHandler()->ProcessEvent(event
);
4550 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
4552 wxMoveEvent
event(rect
, m_windowId
);
4553 event
.SetEventObject(this);
4555 bool rc
= GetEventHandler()->ProcessEvent(event
);
4557 rect
= event
.GetRect();
4561 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
4563 #if USE_DEFERRED_SIZING
4564 // when we resize this window, its children are probably going to be
4565 // repositioned as well, prepare to use DeferWindowPos() for them
4566 int numChildren
= 0;
4567 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
4569 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
4574 // Protect against valid m_hDWP being overwritten
4575 bool useDefer
= false;
4577 if ( numChildren
> 1 )
4581 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
4584 wxLogLastError(_T("BeginDeferWindowPos"));
4590 #endif // USE_DEFERRED_SIZING
4592 // update this window size
4593 bool processed
= false;
4597 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4598 // fall through nevertheless
4602 // we're not interested in these messages at all
4605 case SIZE_MINIMIZED
:
4606 processed
= HandleMinimize();
4609 case SIZE_MAXIMIZED
:
4610 /* processed = */ HandleMaximize();
4611 // fall through to send a normal size event as well
4614 // don't use w and h parameters as they specify the client size
4615 // while according to the docs EVT_SIZE handler is supposed to
4616 // receive the total size
4617 wxSizeEvent
event(GetSize(), m_windowId
);
4618 event
.SetEventObject(this);
4620 processed
= GetEventHandler()->ProcessEvent(event
);
4623 #if USE_DEFERRED_SIZING
4624 // and finally change the positions of all child windows at once
4625 if ( useDefer
&& m_hDWP
)
4627 // reset m_hDWP to NULL so that child windows don't try to use our
4628 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4629 // happen anyhow normally but who knows what weird flow of control we
4630 // may have depending on what the users EVT_SIZE handler does...)
4631 HDWP hDWP
= (HDWP
)m_hDWP
;
4634 // do put all child controls in place at once
4635 if ( !::EndDeferWindowPos(hDWP
) )
4637 wxLogLastError(_T("EndDeferWindowPos"));
4640 // Reset our children's pending pos/size values.
4641 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4643 node
= node
->GetNext() )
4645 wxWindowMSW
*child
= node
->GetData();
4646 child
->m_pendingPosition
= wxDefaultPosition
;
4647 child
->m_pendingSize
= wxDefaultSize
;
4650 #endif // USE_DEFERRED_SIZING
4655 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
4657 wxSizeEvent
event(rect
, m_windowId
);
4658 event
.SetEventObject(this);
4660 bool rc
= GetEventHandler()->ProcessEvent(event
);
4662 rect
= event
.GetRect();
4666 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
4671 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
4675 int minWidth
= GetMinWidth(),
4676 minHeight
= GetMinHeight(),
4677 maxWidth
= GetMaxWidth(),
4678 maxHeight
= GetMaxHeight();
4680 if ( minWidth
!= wxDefaultCoord
)
4682 info
->ptMinTrackSize
.x
= minWidth
;
4686 if ( minHeight
!= wxDefaultCoord
)
4688 info
->ptMinTrackSize
.y
= minHeight
;
4692 if ( maxWidth
!= wxDefaultCoord
)
4694 info
->ptMaxTrackSize
.x
= maxWidth
;
4698 if ( maxHeight
!= wxDefaultCoord
)
4700 info
->ptMaxTrackSize
.y
= maxHeight
;
4708 // ---------------------------------------------------------------------------
4710 // ---------------------------------------------------------------------------
4712 bool wxWindowMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
4714 #if wxUSE_MENUS_NATIVE
4715 if ( !cmd
&& wxCurrentPopupMenu
)
4717 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
4718 wxCurrentPopupMenu
= NULL
;
4720 return popupMenu
->MSWCommand(cmd
, id
);
4722 #endif // wxUSE_MENUS_NATIVE
4724 wxWindow
*win
= NULL
;
4726 // first try to find it from HWND - this works even with the broken
4727 // programs using the same ids for different controls
4730 win
= wxFindWinFromHandle(control
);
4736 // must cast to a signed type before comparing with other ids!
4737 win
= FindItem((signed short)id
);
4742 return win
->MSWCommand(cmd
, id
);
4745 // the messages sent from the in-place edit control used by the treectrl
4746 // for label editing have id == 0, but they should _not_ be treated as menu
4747 // messages (they are EN_XXX ones, in fact) so don't translate anything
4748 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4751 // If no child window, it may be an accelerator, e.g. for a popup menu
4754 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
4755 event
.SetEventObject(this);
4759 return GetEventHandler()->ProcessEvent(event
);
4763 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4764 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4765 // notifications to its parent which we want to reflect back to
4767 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
4768 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
4770 #endif // wxUSE_SPINCTRL
4772 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
4773 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
4774 // notifications to its parent which we want to reflect back to
4776 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
4777 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
4785 // ---------------------------------------------------------------------------
4787 // ---------------------------------------------------------------------------
4789 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
4793 // our client coords are not quite the same as Windows ones
4794 wxPoint pt
= GetClientAreaOrigin();
4795 event
.m_x
= x
- pt
.x
;
4796 event
.m_y
= y
- pt
.y
;
4798 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
4799 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
4800 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
4801 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
4802 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
4803 event
.m_altDown
= ::GetKeyState(VK_MENU
) < 0;
4806 event
.SetTimestamp(::GetMessageTime());
4809 event
.SetEventObject(this);
4810 event
.SetId(GetId());
4812 #if wxUSE_MOUSEEVENT_HACK
4813 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
4814 gs_lastMouseEvent
.type
= event
.GetEventType();
4815 #endif // wxUSE_MOUSEEVENT_HACK
4819 // Windows doesn't send the mouse events to the static controls (which are
4820 // transparent in the sense that their WM_NCHITTEST handler returns
4821 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4822 // and so we manually check if we don't have a child window under mouse and if
4823 // we do, send the event to it instead of the window Windows had sent WM_XXX
4826 // Notice that this is not done for the mouse move events because this could
4827 // (would?) be too slow, but only for clicks which means that the static texts
4828 // still don't get move, enter nor leave events.
4829 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
4831 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
4833 // first try to find a non transparent child: this allows us to send events
4834 // to a static text which is inside a static box, for example
4835 POINT pt
= { *x
, *y
};
4836 HWND hwnd
= GetHwndOf(win
),
4840 hwndUnderMouse
= ::ChildWindowFromPoint
4846 hwndUnderMouse
= ::ChildWindowFromPointEx
4856 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
4858 // now try any child window at all
4859 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
4862 // check that we have a child window which is susceptible to receive mouse
4863 // events: for this it must be shown and enabled
4864 if ( hwndUnderMouse
&&
4865 hwndUnderMouse
!= hwnd
&&
4866 ::IsWindowVisible(hwndUnderMouse
) &&
4867 ::IsWindowEnabled(hwndUnderMouse
) )
4869 wxWindow
*winUnderMouse
= wxFindWinFromHandle((WXHWND
)hwndUnderMouse
);
4870 if ( winUnderMouse
)
4872 // translate the mouse coords to the other window coords
4873 win
->ClientToScreen(x
, y
);
4874 winUnderMouse
->ScreenToClient(x
, y
);
4876 win
= winUnderMouse
;
4882 #endif // __WXWINCE__
4884 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4886 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4887 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
4888 // from the message id and take the value in the table to get wxWin event
4890 static const wxEventType eventsMouse
[] =
4904 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
4905 InitMouseEvent(event
, x
, y
, flags
);
4907 return GetEventHandler()->ProcessEvent(event
);
4910 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
4912 if ( !m_mouseInWindow
)
4914 // it would be wrong to assume that just because we get a mouse move
4915 // event that the mouse is inside the window: although this is usually
4916 // true, it is not if we had captured the mouse, so we need to check
4917 // the mouse coordinates here
4918 if ( !HasCapture() || IsMouseInWindow() )
4920 // Generate an ENTER event
4921 m_mouseInWindow
= true;
4923 #ifdef HAVE_TRACKMOUSEEVENT
4924 typedef BOOL (WINAPI
*_TrackMouseEvent_t
)(LPTRACKMOUSEEVENT
);
4926 static const _TrackMouseEvent_t
4927 s_pfn_TrackMouseEvent
= _TrackMouseEvent
;
4928 #else // !__WXWINCE__
4929 static _TrackMouseEvent_t s_pfn_TrackMouseEvent
;
4930 static bool s_initDone
= false;
4935 wxDynamicLibrary
dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM
);
4936 if ( dllComCtl32
.IsLoaded() )
4938 s_pfn_TrackMouseEvent
= (_TrackMouseEvent_t
)
4939 dllComCtl32
.GetSymbol(_T("_TrackMouseEvent"));
4944 // notice that it's ok to unload comctl32.dll here as it won't
4945 // be really unloaded, being still in use because we link to it
4949 if ( s_pfn_TrackMouseEvent
)
4950 #endif // __WXWINCE__/!__WXWINCE__
4952 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
4954 trackinfo
.dwFlags
= TME_LEAVE
;
4955 trackinfo
.hwndTrack
= GetHwnd();
4957 (*s_pfn_TrackMouseEvent
)(&trackinfo
);
4959 #endif // HAVE_TRACKMOUSEEVENT
4961 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
4962 InitMouseEvent(event
, x
, y
, flags
);
4964 (void)GetEventHandler()->ProcessEvent(event
);
4967 #ifdef HAVE_TRACKMOUSEEVENT
4968 else // mouse not in window
4970 // Check if we need to send a LEAVE event
4971 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
4972 // send it here if we are using native mouse leave tracking
4973 if ( HasCapture() && !IsMouseInWindow() )
4975 GenerateMouseLeave();
4978 #endif // HAVE_TRACKMOUSEEVENT
4980 #if wxUSE_MOUSEEVENT_HACK
4981 // Windows often generates mouse events even if mouse position hasn't
4982 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
4984 // Filter this out as it can result in unexpected behaviour compared to
4986 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
4987 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
4988 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
4989 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
4991 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
4993 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
4998 #endif // wxUSE_MOUSEEVENT_HACK
5000 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
5004 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
5006 #if wxUSE_MOUSEWHEEL
5007 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5008 // forwarded up to the parent by DefWindowProc()) and not in the client
5009 // ones as all the other messages, translate them to the client coords for
5012 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
5013 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
5014 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
5015 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5016 event
.m_wheelDelta
= WHEEL_DELTA
;
5018 static int s_linesPerRotation
= -1;
5019 if ( s_linesPerRotation
== -1 )
5021 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5022 &s_linesPerRotation
, 0))
5024 // this is not supposed to happen
5025 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5027 // the default is 3, so use it if SystemParametersInfo() failed
5028 s_linesPerRotation
= 3;
5032 event
.m_linesPerAction
= s_linesPerRotation
;
5033 return GetEventHandler()->ProcessEvent(event
);
5035 #else // !wxUSE_MOUSEWHEEL
5036 wxUnusedVar(wParam
);
5037 wxUnusedVar(lParam
);
5040 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5043 void wxWindowMSW::GenerateMouseLeave()
5045 m_mouseInWindow
= false;
5048 if ( wxIsShiftDown() )
5050 if ( wxIsCtrlDown() )
5051 state
|= MK_CONTROL
;
5053 // Only the high-order bit should be tested
5054 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5055 state
|= MK_LBUTTON
;
5056 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5057 state
|= MK_MBUTTON
;
5058 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5059 state
|= MK_RBUTTON
;
5063 if ( !::GetCursorPosWinCE(&pt
) )
5065 if ( !::GetCursorPos(&pt
) )
5068 wxLogLastError(_T("GetCursorPos"));
5071 // we need to have client coordinates here for symmetry with
5072 // wxEVT_ENTER_WINDOW
5073 RECT rect
= wxGetWindowRect(GetHwnd());
5077 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5078 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5080 (void)GetEventHandler()->ProcessEvent(event
);
5083 // ---------------------------------------------------------------------------
5084 // keyboard handling
5085 // ---------------------------------------------------------------------------
5087 // create the key event of the given type for the given key - used by
5088 // HandleChar and HandleKeyDown/Up
5089 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5092 WXWPARAM wParam
) const
5094 wxKeyEvent
event(evType
);
5095 event
.SetId(GetId());
5096 event
.m_shiftDown
= wxIsShiftDown();
5097 event
.m_controlDown
= wxIsCtrlDown();
5098 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5100 event
.SetEventObject((wxWindow
*)this); // const_cast
5101 event
.m_keyCode
= id
;
5103 event
.m_uniChar
= (wxChar
) wParam
;
5105 event
.m_rawCode
= (wxUint32
) wParam
;
5106 event
.m_rawFlags
= (wxUint32
) lParam
;
5108 event
.SetTimestamp(::GetMessageTime());
5111 // translate the position to client coords
5114 GetCursorPosWinCE(&pt
);
5119 GetWindowRect(GetHwnd(),&rect
);
5129 // isASCII is true only when we're called from WM_CHAR handler and not from
5131 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
5138 else // we're called from WM_KEYDOWN
5140 // don't pass lParam to wxCharCodeMSWToWX() here because we don't want
5141 // to get numpad key codes: CHAR events should use the logical keys
5142 // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events
5143 id
= wxCharCodeMSWToWX(wParam
);
5146 // it's ASCII and will be processed here only when called from
5147 // WM_CHAR (i.e. when isASCII = true), don't process it now
5152 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
5154 // the alphanumeric keys produced by pressing AltGr+something on European
5155 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5156 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5157 // alphanumeric, so pretend that there are no modifiers at all (the
5158 // KEY_DOWN event would still have the correct modifiers if they're really
5160 if ( event
.m_controlDown
&& event
.m_altDown
&&
5161 (id
>= 32 && id
< 256) )
5163 event
.m_controlDown
=
5164 event
.m_altDown
= false;
5167 return GetEventHandler()->ProcessEvent(event
);
5170 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5172 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5176 // normal ASCII char
5180 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
5181 return GetEventHandler()->ProcessEvent(event
);
5184 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5186 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5190 // normal ASCII char
5194 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
5195 return GetEventHandler()->ProcessEvent(event
);
5198 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5199 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5201 // FIXME: implement GetMenuItemCount for WinCE, possibly
5202 // in terms of GetMenuItemInfo
5204 const HMENU hmenu
= (HMENU
)lParam
;
5208 mii
.cbSize
= sizeof(MENUITEMINFO
);
5210 // we could use MIIM_FTYPE here as we only need to know if the item is
5211 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5212 // MIIM_FTYPE is not supported under Win95
5213 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5215 // find if we have this letter in any owner drawn item
5216 const int count
= ::GetMenuItemCount(hmenu
);
5217 for ( int i
= 0; i
< count
; i
++ )
5219 // previous loop iteration could modify it, reset it back before
5220 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5223 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5225 if ( mii
.fType
== MFT_OWNERDRAW
)
5227 // dwItemData member of the MENUITEMINFO is a
5228 // pointer to the associated wxMenuItem -- see the
5229 // menu creation code
5230 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5232 const wxChar
*p
= wxStrchr(item
->GetText(), _T('&'));
5235 if ( *p
== _T('&') )
5237 // this is not the accel char, find the real one
5238 p
= wxStrchr(p
+ 1, _T('&'));
5240 else // got the accel char
5242 // FIXME-UNICODE: this comparison doesn't risk to work
5243 // for non ASCII accelerator characters I'm afraid, but
5245 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5251 // this one doesn't match
5258 else // failed to get the menu text?
5260 // it's not fatal, so don't show error, but still log it
5261 wxLogLastError(_T("GetMenuItemInfo"));
5268 bool wxWindowMSW::HandleClipboardEvent( WXUINT nMsg
)
5270 const wxEventType type
= ( nMsg
== WM_CUT
) ? wxEVT_COMMAND_TEXT_CUT
:
5271 ( nMsg
== WM_COPY
) ? wxEVT_COMMAND_TEXT_COPY
:
5272 /*( nMsg == WM_PASTE ) ? */ wxEVT_COMMAND_TEXT_PASTE
;
5273 wxClipboardTextEvent
evt(type
, GetId());
5275 evt
.SetEventObject(this);
5277 return GetEventHandler()->ProcessEvent(evt
);
5280 // ---------------------------------------------------------------------------
5282 // ---------------------------------------------------------------------------
5284 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5288 if ( flags
& JOY_BUTTON1CHG
)
5289 change
= wxJOY_BUTTON1
;
5290 if ( flags
& JOY_BUTTON2CHG
)
5291 change
= wxJOY_BUTTON2
;
5292 if ( flags
& JOY_BUTTON3CHG
)
5293 change
= wxJOY_BUTTON3
;
5294 if ( flags
& JOY_BUTTON4CHG
)
5295 change
= wxJOY_BUTTON4
;
5298 if ( flags
& JOY_BUTTON1
)
5299 buttons
|= wxJOY_BUTTON1
;
5300 if ( flags
& JOY_BUTTON2
)
5301 buttons
|= wxJOY_BUTTON2
;
5302 if ( flags
& JOY_BUTTON3
)
5303 buttons
|= wxJOY_BUTTON3
;
5304 if ( flags
& JOY_BUTTON4
)
5305 buttons
|= wxJOY_BUTTON4
;
5307 // the event ids aren't consecutive so we can't use table based lookup
5309 wxEventType eventType
;
5314 eventType
= wxEVT_JOY_MOVE
;
5319 eventType
= wxEVT_JOY_MOVE
;
5324 eventType
= wxEVT_JOY_ZMOVE
;
5329 eventType
= wxEVT_JOY_ZMOVE
;
5332 case MM_JOY1BUTTONDOWN
:
5334 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5337 case MM_JOY2BUTTONDOWN
:
5339 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5342 case MM_JOY1BUTTONUP
:
5344 eventType
= wxEVT_JOY_BUTTON_UP
;
5347 case MM_JOY2BUTTONUP
:
5349 eventType
= wxEVT_JOY_BUTTON_UP
;
5353 wxFAIL_MSG(wxT("no such joystick event"));
5358 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5359 event
.SetPosition(wxPoint(x
, y
));
5360 event
.SetEventObject(this);
5362 return GetEventHandler()->ProcessEvent(event
);
5372 // ---------------------------------------------------------------------------
5374 // ---------------------------------------------------------------------------
5376 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5377 WXWORD pos
, WXHWND control
)
5379 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5381 wxWindow
*child
= wxFindWinFromHandle(control
);
5383 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5386 wxScrollWinEvent event
;
5387 event
.SetPosition(pos
);
5388 event
.SetOrientation(orientation
);
5389 event
.SetEventObject(this);
5394 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5398 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5402 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5406 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5410 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5414 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5417 case SB_THUMBPOSITION
:
5419 // under Win32, the scrollbar range and position are 32 bit integers,
5420 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5421 // explicitly query the scrollbar for the correct position (this must
5422 // be done only for these two SB_ events as they are the only one
5423 // carrying the scrollbar position)
5425 WinStruct
<SCROLLINFO
> scrollInfo
;
5426 scrollInfo
.fMask
= SIF_TRACKPOS
;
5428 if ( !::GetScrollInfo(GetHwnd(),
5429 orientation
== wxHORIZONTAL
? SB_HORZ
5433 // Not necessarily an error, if there are no scrollbars yet.
5434 // wxLogLastError(_T("GetScrollInfo"));
5437 event
.SetPosition(scrollInfo
.nTrackPos
);
5440 event
.SetEventType( wParam
== SB_THUMBPOSITION
5441 ? wxEVT_SCROLLWIN_THUMBRELEASE
5442 : wxEVT_SCROLLWIN_THUMBTRACK
);
5449 return GetEventHandler()->ProcessEvent(event
);
5452 // ----------------------------------------------------------------------------
5453 // custom message handlers
5454 // ----------------------------------------------------------------------------
5457 wxWindowMSW::MSWRegisterMessageHandler(int msg
, MSWMessageHandler handler
)
5459 wxCHECK_MSG( gs_messageHandlers
.find(msg
) == gs_messageHandlers
.end(),
5460 false, _T("registering handler for the same message twice") );
5462 gs_messageHandlers
[msg
] = handler
;
5467 wxWindowMSW::MSWUnregisterMessageHandler(int msg
, MSWMessageHandler handler
)
5469 const MSWMessageHandlers::iterator i
= gs_messageHandlers
.find(msg
);
5470 wxCHECK_RET( i
!= gs_messageHandlers
.end() && i
->second
== handler
,
5471 _T("unregistering non-registered handler?") );
5473 gs_messageHandlers
.erase(i
);
5476 // ===========================================================================
5478 // ===========================================================================
5480 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5483 HDC dc
= ::GetDC((HWND
) wnd
);
5486 // the_font.UseResource();
5487 // the_font.RealizeResource();
5488 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
5490 was
= (HFONT
) SelectObject(dc
,fnt
);
5492 GetTextMetrics(dc
, &tm
);
5495 SelectObject(dc
,was
);
5497 ReleaseDC((HWND
)wnd
, dc
);
5500 *x
= tm
.tmAveCharWidth
;
5502 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
5504 // the_font.ReleaseResource();
5507 // use the "extended" bit (24) of lParam to distinguish extended keys
5508 // from normal keys as the same key is sent
5510 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
5512 // except that if lParam is 0, it means we don't have real lParam from
5513 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
5514 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
5515 // non-numpad (hence extended) key as this is a more common case
5516 return !lParam
|| (lParam
& (1 << 24)) ? keyExtended
: keyNormal
;
5519 // this array contains the Windows virtual key codes which map one to one to
5520 // WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below
5522 // note that keys having a normal and numpad version (e.g. WXK_HOME and
5523 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
5524 static const struct wxKeyMapping
5528 } gs_specialKeys
[] =
5530 { VK_CANCEL
, WXK_CANCEL
},
5531 { VK_BACK
, WXK_BACK
},
5532 { VK_TAB
, WXK_TAB
},
5533 { VK_CLEAR
, WXK_CLEAR
},
5534 { VK_SHIFT
, WXK_SHIFT
},
5535 { VK_CONTROL
, WXK_CONTROL
},
5536 { VK_MENU
, WXK_ALT
},
5537 { VK_PAUSE
, WXK_PAUSE
},
5538 { VK_CAPITAL
, WXK_CAPITAL
},
5539 { VK_SPACE
, WXK_SPACE
},
5540 { VK_ESCAPE
, WXK_ESCAPE
},
5541 { VK_SELECT
, WXK_SELECT
},
5542 { VK_PRINT
, WXK_PRINT
},
5543 { VK_EXECUTE
, WXK_EXECUTE
},
5544 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
5545 { VK_HELP
, WXK_HELP
},
5547 { VK_NUMPAD0
, WXK_NUMPAD0
},
5548 { VK_NUMPAD1
, WXK_NUMPAD1
},
5549 { VK_NUMPAD2
, WXK_NUMPAD2
},
5550 { VK_NUMPAD3
, WXK_NUMPAD3
},
5551 { VK_NUMPAD4
, WXK_NUMPAD4
},
5552 { VK_NUMPAD5
, WXK_NUMPAD5
},
5553 { VK_NUMPAD6
, WXK_NUMPAD6
},
5554 { VK_NUMPAD7
, WXK_NUMPAD7
},
5555 { VK_NUMPAD8
, WXK_NUMPAD8
},
5556 { VK_NUMPAD9
, WXK_NUMPAD9
},
5557 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
5558 { VK_ADD
, WXK_NUMPAD_ADD
},
5559 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
5560 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
5561 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
5572 { VK_F10
, WXK_F10
},
5573 { VK_F11
, WXK_F11
},
5574 { VK_F12
, WXK_F12
},
5575 { VK_F13
, WXK_F13
},
5576 { VK_F14
, WXK_F14
},
5577 { VK_F15
, WXK_F15
},
5578 { VK_F16
, WXK_F16
},
5579 { VK_F17
, WXK_F17
},
5580 { VK_F18
, WXK_F18
},
5581 { VK_F19
, WXK_F19
},
5582 { VK_F20
, WXK_F20
},
5583 { VK_F21
, WXK_F21
},
5584 { VK_F22
, WXK_F22
},
5585 { VK_F23
, WXK_F23
},
5586 { VK_F24
, WXK_F24
},
5588 { VK_NUMLOCK
, WXK_NUMLOCK
},
5589 { VK_SCROLL
, WXK_SCROLL
},
5592 { VK_LWIN
, WXK_WINDOWS_LEFT
},
5593 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
5594 { VK_APPS
, WXK_WINDOWS_MENU
},
5595 #endif // VK_APPS defined
5598 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
5599 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
5600 int wxCharCodeMSWToWX(int vk
, WXLPARAM lParam
)
5602 // check the table first
5603 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5605 if ( gs_specialKeys
[n
].vk
== vk
)
5606 return gs_specialKeys
[n
].wxk
;
5609 // keys requiring special handling
5613 // the mapping for these keys may be incorrect on non-US keyboards so
5614 // maybe we shouldn't map them to ASCII values at all
5615 case VK_OEM_1
: wxk
= ';'; break;
5616 case VK_OEM_PLUS
: wxk
= '+'; break;
5617 case VK_OEM_COMMA
: wxk
= ','; break;
5618 case VK_OEM_MINUS
: wxk
= '-'; break;
5619 case VK_OEM_PERIOD
: wxk
= '.'; break;
5620 case VK_OEM_2
: wxk
= '/'; break;
5621 case VK_OEM_3
: wxk
= '~'; break;
5622 case VK_OEM_4
: wxk
= '['; break;
5623 case VK_OEM_5
: wxk
= '\\'; break;
5624 case VK_OEM_6
: wxk
= ']'; break;
5625 case VK_OEM_7
: wxk
= '\''; break;
5627 // handle extended keys
5629 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
5633 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
5637 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
5641 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
5645 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
5649 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
5653 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
5657 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
5661 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
5665 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
5669 // don't use ChooseNormalOrExtended() here as the keys are reversed
5670 // here: numpad enter is the extended one
5671 wxk
= lParam
&& (lParam
& (1 << 24)) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
5681 WXWORD
wxCharCodeWXToMSW(int wxk
, bool *isVirtual
)
5686 // check the table first
5687 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5689 if ( gs_specialKeys
[n
].wxk
== wxk
)
5690 return gs_specialKeys
[n
].vk
;
5693 // and then check for special keys not included in the table
5698 case WXK_NUMPAD_PAGEUP
:
5703 case WXK_NUMPAD_PAGEDOWN
:
5708 case WXK_NUMPAD_END
:
5713 case WXK_NUMPAD_HOME
:
5718 case WXK_NUMPAD_LEFT
:
5728 case WXK_NUMPAD_RIGHT
:
5733 case WXK_NUMPAD_DOWN
:
5738 case WXK_NUMPAD_INSERT
:
5743 case WXK_NUMPAD_DELETE
:
5757 #ifndef SM_SWAPBUTTON
5758 #define SM_SWAPBUTTON 23
5761 // small helper for wxGetKeyState() and wxGetMouseState()
5762 static inline bool wxIsKeyDown(WXWORD vk
)
5767 if (GetSystemMetrics(SM_SWAPBUTTON
)) vk
= VK_RBUTTON
;
5770 if (GetSystemMetrics(SM_SWAPBUTTON
)) vk
= VK_LBUTTON
;
5773 // the low order bit indicates whether the key was pressed since the last
5774 // call and the high order one indicates whether it is down right now and
5775 // we only want that one
5776 return (GetAsyncKeyState(vk
) & (1<<15)) != 0;
5779 bool wxGetKeyState(wxKeyCode key
)
5781 // although this does work under Windows, it is not supported under other
5782 // platforms so don't allow it, you must use wxGetMouseState() instead
5783 wxASSERT_MSG( key
!= VK_LBUTTON
&&
5784 key
!= VK_RBUTTON
&&
5786 wxT("can't use wxGetKeyState() for mouse buttons") );
5788 const WXWORD vk
= wxCharCodeWXToMSW(key
);
5790 // if the requested key is a LED key, return true if the led is pressed
5791 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
5793 // low order bit means LED is highlighted and high order one means the
5794 // key is down; for compatibility with the other ports return true if
5795 // either one is set
5796 return GetKeyState(vk
) != 0;
5801 return wxIsKeyDown(vk
);
5806 wxMouseState
wxGetMouseState()
5810 GetCursorPos( &pt
);
5814 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
5815 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
5816 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
5818 ms
.SetControlDown(wxIsKeyDown(VK_CONTROL
));
5819 ms
.SetShiftDown(wxIsKeyDown(VK_SHIFT
));
5820 ms
.SetAltDown(wxIsKeyDown(VK_MENU
));
5821 // ms.SetMetaDown();
5827 wxWindow
*wxGetActiveWindow()
5829 HWND hWnd
= GetActiveWindow();
5832 return wxFindWinFromHandle((WXHWND
) hWnd
);
5837 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
5839 HWND hwnd
= (HWND
)hWnd
;
5841 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
5842 // by code in msw/radiobox.cpp), for all the others we just search up the
5844 wxWindow
*win
= (wxWindow
*)NULL
;
5847 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5851 // native radiobuttons return DLGC_RADIOBUTTON here and for any
5852 // wxWindow class which overrides WM_GETDLGCODE processing to
5853 // do it as well, win would be already non NULL
5854 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
5856 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
5858 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
5859 #endif // wxUSE_RADIOBOX
5861 // spin control text buddy window should be mapped to spin ctrl
5862 // itself so try it too
5863 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5866 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
5868 #endif // wxUSE_SPINCTRL
5872 while ( hwnd
&& !win
)
5874 // this is a really ugly hack needed to avoid mistakenly returning the
5875 // parent frame wxWindow for the find/replace modeless dialog HWND -
5876 // this, in turn, is needed to call IsDialogMessage() from
5877 // wxApp::ProcessMessage() as for this we must return NULL from here
5879 // FIXME: this is clearly not the best way to do it but I think we'll
5880 // need to change HWND <-> wxWindow code more heavily than I can
5881 // do it now to fix it
5882 #ifndef __WXMICROWIN__
5883 if ( ::GetWindow(hwnd
, GW_OWNER
) )
5885 // it's a dialog box, don't go upwards
5890 hwnd
= ::GetParent(hwnd
);
5891 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5897 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
5899 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
5900 // in active frames and dialogs, regardless of where the focus is.
5901 static HHOOK wxTheKeyboardHook
= 0;
5902 static FARPROC wxTheKeyboardHookProc
= 0;
5903 int APIENTRY _EXPORT
5904 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
5906 void wxSetKeyboardHook(bool doIt
)
5910 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
5911 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
5913 GetCurrentThreadId()
5914 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
5919 UnhookWindowsHookEx(wxTheKeyboardHook
);
5923 int APIENTRY _EXPORT
5924 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
5926 DWORD hiWord
= HIWORD(lParam
);
5927 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
5929 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5932 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
5933 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
5934 event
.m_altDown
= true;
5936 event
.SetEventObject(NULL
);
5937 event
.m_keyCode
= id
;
5938 event
.m_shiftDown
= wxIsShiftDown();
5939 event
.m_controlDown
= wxIsCtrlDown();
5941 event
.SetTimestamp(::GetMessageTime());
5943 wxWindow
*win
= wxGetActiveWindow();
5944 wxEvtHandler
*handler
;
5947 handler
= win
->GetEventHandler();
5948 event
.SetId(win
->GetId());
5953 event
.SetId(wxID_ANY
);
5956 if ( handler
&& handler
->ProcessEvent(event
) )
5964 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
5967 #endif // !__WXMICROWIN__
5970 const wxChar
*wxGetMessageName(int message
)
5974 case 0x0000: return wxT("WM_NULL");
5975 case 0x0001: return wxT("WM_CREATE");
5976 case 0x0002: return wxT("WM_DESTROY");
5977 case 0x0003: return wxT("WM_MOVE");
5978 case 0x0005: return wxT("WM_SIZE");
5979 case 0x0006: return wxT("WM_ACTIVATE");
5980 case 0x0007: return wxT("WM_SETFOCUS");
5981 case 0x0008: return wxT("WM_KILLFOCUS");
5982 case 0x000A: return wxT("WM_ENABLE");
5983 case 0x000B: return wxT("WM_SETREDRAW");
5984 case 0x000C: return wxT("WM_SETTEXT");
5985 case 0x000D: return wxT("WM_GETTEXT");
5986 case 0x000E: return wxT("WM_GETTEXTLENGTH");
5987 case 0x000F: return wxT("WM_PAINT");
5988 case 0x0010: return wxT("WM_CLOSE");
5989 case 0x0011: return wxT("WM_QUERYENDSESSION");
5990 case 0x0012: return wxT("WM_QUIT");
5991 case 0x0013: return wxT("WM_QUERYOPEN");
5992 case 0x0014: return wxT("WM_ERASEBKGND");
5993 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
5994 case 0x0016: return wxT("WM_ENDSESSION");
5995 case 0x0017: return wxT("WM_SYSTEMERROR");
5996 case 0x0018: return wxT("WM_SHOWWINDOW");
5997 case 0x0019: return wxT("WM_CTLCOLOR");
5998 case 0x001A: return wxT("WM_WININICHANGE");
5999 case 0x001B: return wxT("WM_DEVMODECHANGE");
6000 case 0x001C: return wxT("WM_ACTIVATEAPP");
6001 case 0x001D: return wxT("WM_FONTCHANGE");
6002 case 0x001E: return wxT("WM_TIMECHANGE");
6003 case 0x001F: return wxT("WM_CANCELMODE");
6004 case 0x0020: return wxT("WM_SETCURSOR");
6005 case 0x0021: return wxT("WM_MOUSEACTIVATE");
6006 case 0x0022: return wxT("WM_CHILDACTIVATE");
6007 case 0x0023: return wxT("WM_QUEUESYNC");
6008 case 0x0024: return wxT("WM_GETMINMAXINFO");
6009 case 0x0026: return wxT("WM_PAINTICON");
6010 case 0x0027: return wxT("WM_ICONERASEBKGND");
6011 case 0x0028: return wxT("WM_NEXTDLGCTL");
6012 case 0x002A: return wxT("WM_SPOOLERSTATUS");
6013 case 0x002B: return wxT("WM_DRAWITEM");
6014 case 0x002C: return wxT("WM_MEASUREITEM");
6015 case 0x002D: return wxT("WM_DELETEITEM");
6016 case 0x002E: return wxT("WM_VKEYTOITEM");
6017 case 0x002F: return wxT("WM_CHARTOITEM");
6018 case 0x0030: return wxT("WM_SETFONT");
6019 case 0x0031: return wxT("WM_GETFONT");
6020 case 0x0037: return wxT("WM_QUERYDRAGICON");
6021 case 0x0039: return wxT("WM_COMPAREITEM");
6022 case 0x0041: return wxT("WM_COMPACTING");
6023 case 0x0044: return wxT("WM_COMMNOTIFY");
6024 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6025 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6026 case 0x0048: return wxT("WM_POWER");
6028 case 0x004A: return wxT("WM_COPYDATA");
6029 case 0x004B: return wxT("WM_CANCELJOURNAL");
6030 case 0x004E: return wxT("WM_NOTIFY");
6031 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6032 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6033 case 0x0052: return wxT("WM_TCARD");
6034 case 0x0053: return wxT("WM_HELP");
6035 case 0x0054: return wxT("WM_USERCHANGED");
6036 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6037 case 0x007B: return wxT("WM_CONTEXTMENU");
6038 case 0x007C: return wxT("WM_STYLECHANGING");
6039 case 0x007D: return wxT("WM_STYLECHANGED");
6040 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6041 case 0x007F: return wxT("WM_GETICON");
6042 case 0x0080: return wxT("WM_SETICON");
6044 case 0x0081: return wxT("WM_NCCREATE");
6045 case 0x0082: return wxT("WM_NCDESTROY");
6046 case 0x0083: return wxT("WM_NCCALCSIZE");
6047 case 0x0084: return wxT("WM_NCHITTEST");
6048 case 0x0085: return wxT("WM_NCPAINT");
6049 case 0x0086: return wxT("WM_NCACTIVATE");
6050 case 0x0087: return wxT("WM_GETDLGCODE");
6051 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6052 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6053 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6054 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6055 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6056 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6057 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6058 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6059 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6060 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6062 case 0x00B0: return wxT("EM_GETSEL");
6063 case 0x00B1: return wxT("EM_SETSEL");
6064 case 0x00B2: return wxT("EM_GETRECT");
6065 case 0x00B3: return wxT("EM_SETRECT");
6066 case 0x00B4: return wxT("EM_SETRECTNP");
6067 case 0x00B5: return wxT("EM_SCROLL");
6068 case 0x00B6: return wxT("EM_LINESCROLL");
6069 case 0x00B7: return wxT("EM_SCROLLCARET");
6070 case 0x00B8: return wxT("EM_GETMODIFY");
6071 case 0x00B9: return wxT("EM_SETMODIFY");
6072 case 0x00BA: return wxT("EM_GETLINECOUNT");
6073 case 0x00BB: return wxT("EM_LINEINDEX");
6074 case 0x00BC: return wxT("EM_SETHANDLE");
6075 case 0x00BD: return wxT("EM_GETHANDLE");
6076 case 0x00BE: return wxT("EM_GETTHUMB");
6077 case 0x00C1: return wxT("EM_LINELENGTH");
6078 case 0x00C2: return wxT("EM_REPLACESEL");
6079 case 0x00C4: return wxT("EM_GETLINE");
6080 case 0x00C5: return wxT("EM_LIMITTEXT/EM_SETLIMITTEXT"); /* ;win40 Name change */
6081 case 0x00C6: return wxT("EM_CANUNDO");
6082 case 0x00C7: return wxT("EM_UNDO");
6083 case 0x00C8: return wxT("EM_FMTLINES");
6084 case 0x00C9: return wxT("EM_LINEFROMCHAR");
6085 case 0x00CB: return wxT("EM_SETTABSTOPS");
6086 case 0x00CC: return wxT("EM_SETPASSWORDCHAR");
6087 case 0x00CD: return wxT("EM_EMPTYUNDOBUFFER");
6088 case 0x00CE: return wxT("EM_GETFIRSTVISIBLELINE");
6089 case 0x00CF: return wxT("EM_SETREADONLY");
6090 case 0x00D0: return wxT("EM_SETWORDBREAKPROC");
6091 case 0x00D1: return wxT("EM_GETWORDBREAKPROC");
6092 case 0x00D2: return wxT("EM_GETPASSWORDCHAR");
6093 case 0x00D3: return wxT("EM_SETMARGINS");
6094 case 0x00D4: return wxT("EM_GETMARGINS");
6095 case 0x00D5: return wxT("EM_GETLIMITTEXT");
6096 case 0x00D6: return wxT("EM_POSFROMCHAR");
6097 case 0x00D7: return wxT("EM_CHARFROMPOS");
6098 case 0x00D8: return wxT("EM_SETIMESTATUS");
6099 case 0x00D9: return wxT("EM_GETIMESTATUS");
6101 case 0x0100: return wxT("WM_KEYDOWN");
6102 case 0x0101: return wxT("WM_KEYUP");
6103 case 0x0102: return wxT("WM_CHAR");
6104 case 0x0103: return wxT("WM_DEADCHAR");
6105 case 0x0104: return wxT("WM_SYSKEYDOWN");
6106 case 0x0105: return wxT("WM_SYSKEYUP");
6107 case 0x0106: return wxT("WM_SYSCHAR");
6108 case 0x0107: return wxT("WM_SYSDEADCHAR");
6109 case 0x0108: return wxT("WM_KEYLAST");
6111 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6112 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6113 case 0x010F: return wxT("WM_IME_COMPOSITION");
6115 case 0x0110: return wxT("WM_INITDIALOG");
6116 case 0x0111: return wxT("WM_COMMAND");
6117 case 0x0112: return wxT("WM_SYSCOMMAND");
6118 case 0x0113: return wxT("WM_TIMER");
6119 case 0x0114: return wxT("WM_HSCROLL");
6120 case 0x0115: return wxT("WM_VSCROLL");
6121 case 0x0116: return wxT("WM_INITMENU");
6122 case 0x0117: return wxT("WM_INITMENUPOPUP");
6123 case 0x011F: return wxT("WM_MENUSELECT");
6124 case 0x0120: return wxT("WM_MENUCHAR");
6125 case 0x0121: return wxT("WM_ENTERIDLE");
6127 case 0x0132: return wxT("WM_CTLCOLORMSGBOX");
6128 case 0x0133: return wxT("WM_CTLCOLOREDIT");
6129 case 0x0134: return wxT("WM_CTLCOLORLISTBOX");
6130 case 0x0135: return wxT("WM_CTLCOLORBTN");
6131 case 0x0136: return wxT("WM_CTLCOLORDLG");
6132 case 0x0137: return wxT("WM_CTLCOLORSCROLLBAR");
6133 case 0x0138: return wxT("WM_CTLCOLORSTATIC");
6134 case 0x01E1: return wxT("MN_GETHMENU");
6136 case 0x0200: return wxT("WM_MOUSEMOVE");
6137 case 0x0201: return wxT("WM_LBUTTONDOWN");
6138 case 0x0202: return wxT("WM_LBUTTONUP");
6139 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6140 case 0x0204: return wxT("WM_RBUTTONDOWN");
6141 case 0x0205: return wxT("WM_RBUTTONUP");
6142 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6143 case 0x0207: return wxT("WM_MBUTTONDOWN");
6144 case 0x0208: return wxT("WM_MBUTTONUP");
6145 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6146 case 0x020A: return wxT("WM_MOUSEWHEEL");
6147 case 0x0210: return wxT("WM_PARENTNOTIFY");
6148 case 0x0211: return wxT("WM_ENTERMENULOOP");
6149 case 0x0212: return wxT("WM_EXITMENULOOP");
6151 case 0x0213: return wxT("WM_NEXTMENU");
6152 case 0x0214: return wxT("WM_SIZING");
6153 case 0x0215: return wxT("WM_CAPTURECHANGED");
6154 case 0x0216: return wxT("WM_MOVING");
6155 case 0x0218: return wxT("WM_POWERBROADCAST");
6156 case 0x0219: return wxT("WM_DEVICECHANGE");
6158 case 0x0220: return wxT("WM_MDICREATE");
6159 case 0x0221: return wxT("WM_MDIDESTROY");
6160 case 0x0222: return wxT("WM_MDIACTIVATE");
6161 case 0x0223: return wxT("WM_MDIRESTORE");
6162 case 0x0224: return wxT("WM_MDINEXT");
6163 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6164 case 0x0226: return wxT("WM_MDITILE");
6165 case 0x0227: return wxT("WM_MDICASCADE");
6166 case 0x0228: return wxT("WM_MDIICONARRANGE");
6167 case 0x0229: return wxT("WM_MDIGETACTIVE");
6168 case 0x0230: return wxT("WM_MDISETMENU");
6169 case 0x0233: return wxT("WM_DROPFILES");
6171 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6172 case 0x0282: return wxT("WM_IME_NOTIFY");
6173 case 0x0283: return wxT("WM_IME_CONTROL");
6174 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6175 case 0x0285: return wxT("WM_IME_SELECT");
6176 case 0x0286: return wxT("WM_IME_CHAR");
6177 case 0x0290: return wxT("WM_IME_KEYDOWN");
6178 case 0x0291: return wxT("WM_IME_KEYUP");
6180 case 0x02A0: return wxT("WM_NCMOUSEHOVER");
6181 case 0x02A1: return wxT("WM_MOUSEHOVER");
6182 case 0x02A2: return wxT("WM_NCMOUSELEAVE");
6183 case 0x02A3: return wxT("WM_MOUSELEAVE");
6185 case 0x0300: return wxT("WM_CUT");
6186 case 0x0301: return wxT("WM_COPY");
6187 case 0x0302: return wxT("WM_PASTE");
6188 case 0x0303: return wxT("WM_CLEAR");
6189 case 0x0304: return wxT("WM_UNDO");
6190 case 0x0305: return wxT("WM_RENDERFORMAT");
6191 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6192 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6193 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6194 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6195 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6196 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6197 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6198 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6199 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6200 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6201 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6202 case 0x0311: return wxT("WM_PALETTECHANGED");
6203 case 0x0312: return wxT("WM_HOTKEY");
6205 case 0x0317: return wxT("WM_PRINT");
6206 case 0x0318: return wxT("WM_PRINTCLIENT");
6208 // common controls messages - although they're not strictly speaking
6209 // standard, it's nice to decode them nevertheless
6212 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6213 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6214 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6215 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6216 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6217 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6218 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6219 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6220 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6221 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6222 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6223 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6224 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6225 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6226 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6227 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6228 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6229 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6230 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6231 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6232 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6233 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6234 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6235 case 0x1000 + 18: return wxT("LVM_HITTEST");
6236 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6237 case 0x1000 + 20: return wxT("LVM_SCROLL");
6238 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6239 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6240 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6241 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6242 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6243 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6244 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6245 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6246 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6247 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6248 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6249 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6250 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6251 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6252 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6253 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6254 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6255 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6256 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6257 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6258 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6259 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6260 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6261 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6262 case 0x1000 + 42: return wxT("LVM_UPDATE");
6263 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6264 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6265 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6266 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6267 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6268 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6269 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6270 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6271 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6272 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6273 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6274 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6275 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6276 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6277 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6278 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6279 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6280 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6281 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6282 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6283 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6284 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6285 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6286 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6287 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6288 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6291 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6292 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6293 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6294 case 0x1100 + 2: return wxT("TVM_EXPAND");
6295 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6296 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6297 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6298 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6299 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6300 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6301 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6302 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6303 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6304 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6305 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6306 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6307 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6308 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6309 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6310 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6311 case 0x1100 + 17: return wxT("TVM_HITTEST");
6312 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6313 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6314 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6315 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6316 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6317 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6318 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6319 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6320 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6323 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6324 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6325 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6326 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6327 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6328 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6329 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6330 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6331 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6332 case 0x1200 + 6: return wxT("HDM_HITTEST");
6333 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6334 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6335 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6336 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6337 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6338 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6339 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6340 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6343 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6344 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6345 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6346 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6347 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6348 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6349 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6350 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6351 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6352 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6353 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6354 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6355 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6356 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6357 case 0x1300 + 13: return wxT("TCM_HITTEST");
6358 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6359 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6360 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6361 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6362 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6363 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6364 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6365 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6366 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6367 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6368 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6369 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6372 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6373 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
6374 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
6375 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
6376 case WM_USER
+5: return wxT("TB_INDETERMINATE");
6377 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
6378 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
6379 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
6380 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
6381 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
6382 case WM_USER
+17: return wxT("TB_SETSTATE");
6383 case WM_USER
+18: return wxT("TB_GETSTATE");
6384 case WM_USER
+19: return wxT("TB_ADDBITMAP");
6385 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
6386 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
6387 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
6388 case WM_USER
+23: return wxT("TB_GETBUTTON");
6389 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
6390 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
6391 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
6392 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
6393 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
6394 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
6395 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
6396 case WM_USER
+29: return wxT("TB_GETITEMRECT");
6397 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
6398 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
6399 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
6400 case WM_USER
+33: return wxT("TB_AUTOSIZE");
6401 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
6402 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
6403 case WM_USER
+37: return wxT("TB_SETPARENT");
6404 case WM_USER
+39: return wxT("TB_SETROWS");
6405 case WM_USER
+40: return wxT("TB_GETROWS");
6406 case WM_USER
+42: return wxT("TB_SETCMDID");
6407 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
6408 case WM_USER
+44: return wxT("TB_GETBITMAP");
6409 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
6410 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
6411 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
6412 case WM_USER
+47: return wxT("TB_SETINDENT");
6413 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
6414 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
6415 case WM_USER
+50: return wxT("TB_LOADIMAGES");
6416 case WM_USER
+51: return wxT("TB_GETRECT");
6417 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
6418 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
6419 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
6420 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
6421 case WM_USER
+56: return wxT("TB_SETSTYLE");
6422 case WM_USER
+57: return wxT("TB_GETSTYLE");
6423 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
6424 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
6425 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
6426 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
6427 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
6430 static wxString s_szBuf
;
6431 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
6432 return s_szBuf
.c_str();
6435 #endif //__WXDEBUG__
6437 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
6441 HWND hwnd
= GetHwndOf(win
);
6442 HDC hdc
= ::GetDC(hwnd
);
6444 #if !wxDIALOG_UNIT_COMPATIBILITY
6445 // and select the current font into it
6446 HFONT hfont
= GetHfontOf(win
->GetFont());
6449 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
6453 // finally retrieve the text metrics from it
6454 GetTextMetrics(hdc
, &tm
);
6456 #if !wxDIALOG_UNIT_COMPATIBILITY
6460 (void)::SelectObject(hdc
, hfont
);
6464 ::ReleaseDC(hwnd
, hdc
);
6469 // Find the wxWindow at the current mouse position, returning the mouse
6471 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
6473 pt
= wxGetMousePosition();
6474 return wxFindWindowAtPoint(pt
);
6477 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
6483 HWND hWnd
= ::WindowFromPoint(pt2
);
6485 return wxGetWindowFromHWND((WXHWND
)hWnd
);
6488 // Get the current mouse position.
6489 wxPoint
wxGetMousePosition()
6493 GetCursorPosWinCE(&pt
);
6495 GetCursorPos( & pt
);
6498 return wxPoint(pt
.x
, pt
.y
);
6503 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6504 static void WinCEUnregisterHotKey(int modifiers
, int id
)
6506 // Register hotkeys for the hardware buttons
6508 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
6510 UnregisterFunc1Proc procUnregisterFunc
;
6511 hCoreDll
= LoadLibrary(_T("coredll.dll"));
6514 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, _T("UnregisterFunc1"));
6515 if (procUnregisterFunc
)
6516 procUnregisterFunc(modifiers
, id
);
6517 FreeLibrary(hCoreDll
);
6522 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
6524 UINT win_modifiers
=0;
6525 if ( modifiers
& wxMOD_ALT
)
6526 win_modifiers
|= MOD_ALT
;
6527 if ( modifiers
& wxMOD_SHIFT
)
6528 win_modifiers
|= MOD_SHIFT
;
6529 if ( modifiers
& wxMOD_CONTROL
)
6530 win_modifiers
|= MOD_CONTROL
;
6531 if ( modifiers
& wxMOD_WIN
)
6532 win_modifiers
|= MOD_WIN
;
6534 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6535 // Required for PPC and Smartphone hardware buttons
6536 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
6537 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
6540 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
6542 wxLogLastError(_T("RegisterHotKey"));
6550 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
6552 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6553 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
6556 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
6558 wxLogLastError(_T("UnregisterHotKey"));
6568 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
6570 int hotkeyId
= wParam
;
6571 int virtualKey
= HIWORD(lParam
);
6572 int win_modifiers
= LOWORD(lParam
);
6574 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
6575 event
.SetId(hotkeyId
);
6576 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
6577 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
6578 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
6579 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
6581 return GetEventHandler()->ProcessEvent(event
);
6584 #endif // wxUSE_ACCEL
6586 #endif // wxUSE_HOTKEY
6588 // Not tested under WinCE
6591 // this class installs a message hook which really wakes up our idle processing
6592 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
6593 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
6594 // being dragged or even inside ::MessageBox()) and so don't control message
6595 // dispatching otherwise
6596 class wxIdleWakeUpModule
: public wxModule
6599 virtual bool OnInit()
6601 ms_hMsgHookProc
= ::SetWindowsHookEx
6604 &wxIdleWakeUpModule::MsgHookProc
,
6606 GetCurrentThreadId()
6609 if ( !ms_hMsgHookProc
)
6611 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
6619 virtual void OnExit()
6621 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
6624 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
6626 MSG
*msg
= (MSG
*)lParam
;
6628 // only process the message if it is actually going to be removed from
6629 // the message queue, this prevents that the same event from being
6630 // processed multiple times if now someone just called PeekMessage()
6631 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
6633 wxTheApp
->ProcessPendingEvents();
6636 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
6640 static HHOOK ms_hMsgHookProc
;
6642 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
6645 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
6647 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
6649 #endif // __WXWINCE__
6654 static void wxAdjustZOrder(wxWindow
* parent
)
6656 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
6658 // Set the z-order correctly
6659 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
6662 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
6665 wxWindow
*childWin
= current
->GetData();
6666 wxAdjustZOrder(childWin
);
6667 current
= current
->GetNext();
6672 // We need to adjust the z-order of static boxes in WinCE, to
6673 // make 'contained' controls visible
6674 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
6677 wxAdjustZOrder(this);