1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/window.cpp
3 // Purpose: wxWindowMSW
4 // Author: Julian Smart
5 // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/window.h"
30 #include "wx/msw/wrapwin.h"
34 #include "wx/dcclient.h"
35 #include "wx/dcmemory.h"
38 #include "wx/layout.h"
39 #include "wx/dialog.h"
41 #include "wx/listbox.h"
42 #include "wx/button.h"
43 #include "wx/msgdlg.h"
44 #include "wx/settings.h"
45 #include "wx/statbox.h"
51 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
52 #include "wx/ownerdrw.h"
55 #include "wx/evtloop.h"
56 #include "wx/module.h"
58 #include "wx/sysopt.h"
60 #if wxUSE_DRAG_AND_DROP
64 #if wxUSE_ACCESSIBILITY
65 #include "wx/access.h"
69 #define WM_GETOBJECT 0x003D
72 #define OBJID_CLIENT 0xFFFFFFFC
76 #include "wx/menuitem.h"
78 #include "wx/msw/private.h"
81 #include "wx/tooltip.h"
89 #include "wx/spinctrl.h"
90 #endif // wxUSE_SPINCTRL
92 #include "wx/textctrl.h"
93 #include "wx/notebook.h"
94 #include "wx/listctrl.h"
98 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
100 #include <mmsystem.h>
104 #include <windowsx.h>
107 #include <commctrl.h>
110 #include "wx/msw/missing.h"
112 #if defined(__WXWINCE__)
113 #include "wx/msw/wince/missing.h"
116 #include <shellapi.h>
118 #include <aygshell.h>
122 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE)
123 #define HAVE_TRACKMOUSEEVENT
124 #endif // everything needed for TrackMouseEvent()
126 // if this is set to 1, we use deferred window sizing to reduce flicker when
127 // resizing complicated window hierarchies, but this can in theory result in
128 // different behaviour than the old code so we keep the possibility to use it
129 // by setting this to 0 (in the future this should be removed completely)
131 #define USE_DEFERRED_SIZING 0
133 #define USE_DEFERRED_SIZING 1
136 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
137 // when mouse position didnd't change
139 #define wxUSE_MOUSEEVENT_HACK 0
141 #define wxUSE_MOUSEEVENT_HACK 1
144 // ---------------------------------------------------------------------------
146 // ---------------------------------------------------------------------------
148 #if wxUSE_MENUS_NATIVE
149 wxMenu
*wxCurrentPopupMenu
= NULL
;
150 #endif // wxUSE_MENUS_NATIVE
153 extern wxChar
*wxCanvasClassName
;
155 extern const wxChar
*wxCanvasClassName
;
158 // true if we had already created the std colour map, used by
159 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
160 static bool gs_hasStdCmap
= false;
162 // last mouse event information we need to filter out the duplicates
163 #if wxUSE_MOUSEEVENT_HACK
164 static struct MouseEventInfoDummy
166 // mouse position (in screen coordinates)
169 // last mouse event type
172 #endif // wxUSE_MOUSEEVENT_HACK
174 // ---------------------------------------------------------------------------
176 // ---------------------------------------------------------------------------
178 // the window proc for all our windows
179 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
180 WPARAM wParam
, LPARAM lParam
);
184 const wxChar
*wxGetMessageName(int message
);
187 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
188 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
189 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
191 // get the text metrics for the current font
192 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
195 // find the window for the mouse event at the specified position
196 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
197 #endif // __WXWINCE__
199 // wrapper around BringWindowToTop() API
200 static inline void wxBringWindowToTop(HWND hwnd
)
202 #ifdef __WXMICROWIN__
203 // It seems that MicroWindows brings the _parent_ of the window to the top,
204 // which can be the wrong one.
206 // activate (set focus to) specified window
210 // raise top level parent to top of z order
211 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
213 wxLogLastError(_T("SetWindowPos"));
219 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
220 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
223 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
224 parent as well as otherwise several Win32 functions using
225 GetNextDlgTabItem() to iterate over all controls such as
226 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
227 all of them iterate over all the controls starting from the currently
228 focused one and stop iterating when they get back to the focus but
229 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
230 get back to the initial (focused) window: as we do have this style,
231 GetNextDlgTabItem() will leave this window and continue in its parent,
232 but if the parent doesn't have it, it wouldn't recurse inside it later
233 on and so wouldn't have a chance of getting back to this window either.
235 while ( parent
&& !parent
->IsTopLevel() )
237 LONG exStyle
= ::GetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
);
238 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
240 // force the parent to have this style
241 ::SetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
,
242 exStyle
| WS_EX_CONTROLPARENT
);
245 parent
= parent
->GetParent();
249 #endif // !__WXWINCE__
252 // On Windows CE, GetCursorPos can return an error, so use this function
254 bool GetCursorPosWinCE(POINT
* pt
)
256 if (!GetCursorPos(pt
))
258 DWORD pos
= GetMessagePos();
266 // ---------------------------------------------------------------------------
268 // ---------------------------------------------------------------------------
270 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
272 #ifdef __WXUNIVERSAL__
273 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
275 #if wxUSE_EXTENDED_RTTI
277 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
278 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
279 // windows with negative ids never can be recreated anyway
281 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
283 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
284 if ( win
&& win
->GetId() < 0 )
289 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
291 // make wxWindowList known before the property is used
293 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
295 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
297 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
300 WX_DEFINE_FLAGS( wxWindowStyle
)
302 wxBEGIN_FLAGS( wxWindowStyle
)
303 // new style border flags, we put them first to
304 // use them for streaming out
306 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
307 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
308 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
309 wxFLAGS_MEMBER(wxBORDER_RAISED
)
310 wxFLAGS_MEMBER(wxBORDER_STATIC
)
311 wxFLAGS_MEMBER(wxBORDER_NONE
)
313 // old style border flags
314 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
315 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
316 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
317 wxFLAGS_MEMBER(wxRAISED_BORDER
)
318 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
319 wxFLAGS_MEMBER(wxBORDER
)
321 // standard window styles
322 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
323 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
324 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
325 wxFLAGS_MEMBER(wxWANTS_CHARS
)
326 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
327 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
328 wxFLAGS_MEMBER(wxVSCROLL
)
329 wxFLAGS_MEMBER(wxHSCROLL
)
331 wxEND_FLAGS( wxWindowStyle
)
333 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
334 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
335 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
336 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
337 // Always constructor Properties first
339 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
340 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
341 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
342 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
343 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
345 // Then all relations of the object graph
347 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
349 // and finally all other properties
351 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
352 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
353 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
354 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
355 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
357 // possible property candidates (not in xrc) or not valid in all subclasses
358 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
359 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
360 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
361 // MaxHeight, Width , MinHeight , Width
362 // TODO switch label to control and title to toplevels
364 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
365 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
366 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
367 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
372 wxEND_PROPERTIES_TABLE()
374 wxBEGIN_HANDLERS_TABLE(wxWindow
)
375 wxEND_HANDLERS_TABLE()
377 wxCONSTRUCTOR_DUMMY(wxWindow
)
380 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
382 #endif // __WXUNIVERSAL__/__WXMSW__
384 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
385 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
386 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground
)
388 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
392 // ===========================================================================
394 // ===========================================================================
396 // ---------------------------------------------------------------------------
397 // wxWindow utility functions
398 // ---------------------------------------------------------------------------
400 // Find an item given the MS Windows id
401 wxWindow
*wxWindowMSW::FindItem(long id
) const
404 wxControl
*item
= wxDynamicCastThis(wxControl
);
407 // is it us or one of our "internal" children?
408 if ( item
->GetId() == id
409 #ifndef __WXUNIVERSAL__
410 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
411 #endif // __WXUNIVERSAL__
417 #endif // wxUSE_CONTROLS
419 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
422 wxWindow
*childWin
= current
->GetData();
424 wxWindow
*wnd
= childWin
->FindItem(id
);
428 current
= current
->GetNext();
434 // Find an item given the MS Windows handle
435 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
437 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
440 wxWindow
*parent
= current
->GetData();
442 // Do a recursive search.
443 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
449 || parent
->IsKindOf(CLASSINFO(wxControl
))
450 #endif // wxUSE_CONTROLS
453 wxWindow
*item
= current
->GetData();
454 if ( item
->GetHWND() == hWnd
)
458 if ( item
->ContainsHWND(hWnd
) )
463 current
= current
->GetNext();
468 // Default command handler
469 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
474 // ----------------------------------------------------------------------------
475 // constructors and such
476 // ----------------------------------------------------------------------------
478 void wxWindowMSW::Init()
481 m_isBeingDeleted
= false;
483 m_mouseInWindow
= false;
484 m_lastKeydownProcessed
= false;
486 m_childrenDisabled
= NULL
;
495 m_pendingPosition
= wxDefaultPosition
;
496 m_pendingSize
= wxDefaultSize
;
499 m_contextMenuEnabled
= false;
504 wxWindowMSW::~wxWindowMSW()
506 m_isBeingDeleted
= true;
508 #ifndef __WXUNIVERSAL__
509 // VS: make sure there's no wxFrame with last focus set to us:
510 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
512 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
515 if ( frame
->GetLastFocus() == this )
517 frame
->SetLastFocus(NULL
);
520 // apparently sometimes we can end up with our grand parent
521 // pointing to us as well: this is surely a bug in focus handling
522 // code but it's not clear where it happens so for now just try to
523 // fix it here by not breaking out of the loop
527 #endif // __WXUNIVERSAL__
529 // VS: destroy children first and _then_ detach *this from its parent.
530 // If we did it the other way around, children wouldn't be able
531 // find their parent frame (see above).
536 // VZ: test temp removed to understand what really happens here
537 //if (::IsWindow(GetHwnd()))
539 if ( !::DestroyWindow(GetHwnd()) )
540 wxLogLastError(wxT("DestroyWindow"));
543 // remove hWnd <-> wxWindow association
544 wxRemoveHandleAssociation(this);
547 delete m_childrenDisabled
;
551 // real construction (Init() must have been called before!)
552 bool wxWindowMSW::Create(wxWindow
*parent
,
557 const wxString
& name
)
559 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
561 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
564 parent
->AddChild(this);
567 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
569 #ifdef __WXUNIVERSAL__
570 // no borders, we draw them ourselves
571 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
575 msflags
&= ~WS_BORDER
;
576 #endif // wxUniversal
580 msflags
|= WS_VISIBLE
;
583 if ( !MSWCreate(wxCanvasClassName
, NULL
, pos
, size
, msflags
, exstyle
) )
591 // ---------------------------------------------------------------------------
593 // ---------------------------------------------------------------------------
595 void wxWindowMSW::SetFocus()
597 HWND hWnd
= GetHwnd();
598 wxCHECK_RET( hWnd
, _T("can't set focus to invalid window") );
600 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
604 if ( !::SetFocus(hWnd
) )
606 #if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
607 // was there really an error?
608 DWORD dwRes
= ::GetLastError();
611 HWND hwndFocus
= ::GetFocus();
612 if ( hwndFocus
!= hWnd
)
614 wxLogApiError(_T("SetFocus"), dwRes
);
621 void wxWindowMSW::SetFocusFromKbd()
623 // when the focus is given to the control with DLGC_HASSETSEL style from
624 // keyboard its contents should be entirely selected: this is what
625 // ::IsDialogMessage() does and so we should do it as well to provide the
626 // same LNF as the native programs
627 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
629 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
632 // do this after (maybe) setting the selection as like this when
633 // wxEVT_SET_FOCUS handler is called, the selection would have been already
634 // set correctly -- this may be important
635 wxWindowBase::SetFocusFromKbd();
638 // Get the window with the focus
639 wxWindow
*wxWindowBase::DoFindFocus()
641 HWND hWnd
= ::GetFocus();
644 return wxGetWindowFromHWND((WXHWND
)hWnd
);
650 bool wxWindowMSW::Enable(bool enable
)
652 if ( !wxWindowBase::Enable(enable
) )
655 HWND hWnd
= GetHwnd();
657 ::EnableWindow(hWnd
, (BOOL
)enable
);
659 // the logic below doesn't apply to the top level windows -- otherwise
660 // showing a modal dialog would result in total greying out (and ungreying
661 // out later) of everything which would be really ugly
665 // when the parent is disabled, all of its children should be disabled as
666 // well but when it is enabled back, only those of the children which
667 // hadn't been already disabled in the beginning should be enabled again,
668 // so we have to keep the list of those children
669 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
671 node
= node
->GetNext() )
673 wxWindow
*child
= node
->GetData();
674 if ( child
->IsTopLevel() )
676 // the logic below doesn't apply to top level children
682 // re-enable the child unless it had been disabled before us
683 if ( !m_childrenDisabled
|| !m_childrenDisabled
->Find(child
) )
686 else // we're being disabled
688 if ( child
->IsEnabled() )
690 // disable it as children shouldn't stay enabled while the
694 else // child already disabled, remember it
696 // have we created the list of disabled children already?
697 if ( !m_childrenDisabled
)
698 m_childrenDisabled
= new wxWindowList
;
700 m_childrenDisabled
->Append(child
);
705 if ( enable
&& m_childrenDisabled
)
707 // we don't need this list any more, don't keep unused memory
708 delete m_childrenDisabled
;
709 m_childrenDisabled
= NULL
;
715 bool wxWindowMSW::Show(bool show
)
717 if ( !wxWindowBase::Show(show
) )
720 HWND hWnd
= GetHwnd();
722 // we could be called before the underlying window is created (this is
723 // actually useful to prevent it from being initially shown), e.g.
725 // wxFoo *foo = new wxFoo;
727 // foo->Create(parent, ...);
729 // should work without errors
732 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
738 // Raise the window to the top of the Z order
739 void wxWindowMSW::Raise()
741 wxBringWindowToTop(GetHwnd());
744 // Lower the window to the bottom of the Z order
745 void wxWindowMSW::Lower()
747 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
748 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
751 void wxWindowMSW::DoCaptureMouse()
753 HWND hWnd
= GetHwnd();
760 void wxWindowMSW::DoReleaseMouse()
762 if ( !::ReleaseCapture() )
764 wxLogLastError(_T("ReleaseCapture"));
768 /* static */ wxWindow
*wxWindowBase::GetCapture()
770 HWND hwnd
= ::GetCapture();
771 return hwnd
? wxFindWinFromHandle((WXHWND
)hwnd
) : (wxWindow
*)NULL
;
774 bool wxWindowMSW::SetFont(const wxFont
& font
)
776 if ( !wxWindowBase::SetFont(font
) )
782 HWND hWnd
= GetHwnd();
785 WXHANDLE hFont
= m_font
.GetResourceHandle();
787 wxASSERT_MSG( hFont
, wxT("should have valid font") );
789 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
794 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
796 if ( !wxWindowBase::SetCursor(cursor
) )
802 // don't "overwrite" busy cursor
803 if ( m_cursor
.Ok() && !wxIsBusy() )
805 ::SetCursor(GetHcursorOf(m_cursor
));
811 void wxWindowMSW::WarpPointer(int x
, int y
)
813 ClientToScreen(&x
, &y
);
815 if ( !::SetCursorPos(x
, y
) )
817 wxLogLastError(_T("SetCursorPos"));
821 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
823 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
824 // to use it on older systems -- and could possibly do some harm
825 static int s_needToUpdate
= -1;
826 if ( s_needToUpdate
== -1 )
829 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxWINDOWS_NT
&&
833 if ( s_needToUpdate
)
835 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
836 // won't send WM_UPDATEUISTATE
837 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
841 // ---------------------------------------------------------------------------
843 // ---------------------------------------------------------------------------
845 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
847 #ifdef __WXMICROWIN__
848 return ::GetScrollPosWX(hWnd
, wOrient
);
850 WinStruct
<SCROLLINFO
> scrollInfo
;
851 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
852 scrollInfo
.fMask
= SIF_POS
;
853 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
855 return scrollInfo
.nPos
;
860 int wxWindowMSW::GetScrollPos(int orient
) const
862 HWND hWnd
= GetHwnd();
863 wxCHECK_MSG( hWnd
, 0, _T("no HWND in GetScrollPos") );
865 return GetScrollPosition(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
);
868 // This now returns the whole range, not just the number
869 // of positions that we can scroll.
870 int wxWindowMSW::GetScrollRange(int orient
) const
873 HWND hWnd
= GetHwnd();
877 ::GetScrollRange(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
880 WinStruct
<SCROLLINFO
> scrollInfo
;
881 scrollInfo
.fMask
= SIF_RANGE
;
882 if ( !::GetScrollInfo(hWnd
,
883 orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
886 // Most of the time this is not really an error, since the return
887 // value can also be zero when there is no scrollbar yet.
888 // wxLogLastError(_T("GetScrollInfo"));
890 maxPos
= scrollInfo
.nMax
;
892 // undo "range - 1" done in SetScrollbar()
896 int wxWindowMSW::GetScrollThumb(int orient
) const
898 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
901 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
903 HWND hWnd
= GetHwnd();
904 wxCHECK_RET( hWnd
, _T("SetScrollPos: no HWND") );
906 WinStruct
<SCROLLINFO
> info
;
910 info
.fMask
= SIF_POS
;
911 if ( HasFlag(wxALWAYS_SHOW_SB
) )
913 // disable scrollbar instead of removing it then
914 info
.fMask
|= SIF_DISABLENOSCROLL
;
917 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
921 // New function that will replace some of the above.
922 void wxWindowMSW::SetScrollbar(int orient
,
928 WinStruct
<SCROLLINFO
> info
;
929 info
.nPage
= pageSize
;
930 info
.nMin
= 0; // range is nMax - nMin + 1
931 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
933 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
934 if ( HasFlag(wxALWAYS_SHOW_SB
) )
936 // disable scrollbar instead of removing it then
937 info
.fMask
|= SIF_DISABLENOSCROLL
;
940 HWND hWnd
= GetHwnd();
943 // We have to set the variables here to make them valid in events
944 // triggered by ::SetScrollInfo()
945 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
947 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
952 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
958 rect
.left
= prect
->x
;
960 rect
.right
= prect
->x
+ prect
->width
;
961 rect
.bottom
= prect
->y
+ prect
->height
;
971 // FIXME: is this the exact equivalent of the line below?
972 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
974 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
978 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
980 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
983 for ( int n
= 0; n
< count
; n
++ )
985 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
987 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
990 // don't bother to continue, we're already at top/bottom
997 return pos
!= posStart
;
1000 bool wxWindowMSW::ScrollLines(int lines
)
1002 bool down
= lines
> 0;
1004 return ScrollVertically(GetHwnd(),
1005 down
? SB_LINEDOWN
: SB_LINEUP
,
1006 down
? lines
: -lines
);
1009 bool wxWindowMSW::ScrollPages(int pages
)
1011 bool down
= pages
> 0;
1013 return ScrollVertically(GetHwnd(),
1014 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1015 down
? pages
: -pages
);
1018 // ---------------------------------------------------------------------------
1020 // ---------------------------------------------------------------------------
1022 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1024 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1026 HWND hwnd
= (HWND
)hWnd
;
1027 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1029 wxAssociateWinWithHandle(hwnd
, this);
1031 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1033 // we don't need to subclass the window of our own class (in the Windows
1034 // sense of the word)
1035 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1037 wxSetWindowProc(hwnd
, wxWndProc
);
1041 // don't bother restoring it either: this also makes it easy to
1042 // implement IsOfStandardClass() method which returns true for the
1043 // standard controls and false for the wxWidgets own windows as it can
1044 // simply check m_oldWndProc
1045 m_oldWndProc
= NULL
;
1048 // we're officially created now, send the event
1049 wxWindowCreateEvent
event((wxWindow
*)this);
1050 (void)GetEventHandler()->ProcessEvent(event
);
1053 void wxWindowMSW::UnsubclassWin()
1055 wxRemoveHandleAssociation(this);
1057 // Restore old Window proc
1058 HWND hwnd
= GetHwnd();
1063 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1067 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1069 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1072 m_oldWndProc
= NULL
;
1077 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1081 if ( !::DestroyWindow(GetHwnd()) )
1082 wxLogLastError(wxT("DestroyWindow"));
1085 WXHWND wxhwnd
= (WXHWND
)handle
;
1088 SubclassWin(wxhwnd
);
1091 void wxWindowMSW::DissociateHandle()
1093 // this also calls SetHWND(0) for us
1098 bool wxCheckWindowWndProc(WXHWND hWnd
,
1099 WXFARPROC
WXUNUSED(wndProc
))
1101 // TODO: This list of window class names should be factored out so they can be
1102 // managed in one place and then accessed from here and other places, such as
1103 // wxApp::RegisterWindowClasses() and wxApp::UnregisterWindowClasses()
1106 extern wxChar
*wxCanvasClassName
;
1107 extern wxChar
*wxCanvasClassNameNR
;
1109 extern const wxChar
*wxCanvasClassName
;
1110 extern const wxChar
*wxCanvasClassNameNR
;
1112 extern const wxChar
*wxMDIFrameClassName
;
1113 extern const wxChar
*wxMDIFrameClassNameNoRedraw
;
1114 extern const wxChar
*wxMDIChildFrameClassName
;
1115 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
1116 wxString
str(wxGetWindowClass(hWnd
));
1117 if (str
== wxCanvasClassName
||
1118 str
== wxCanvasClassNameNR
||
1120 str
== _T("wxGLCanvasClass") ||
1121 str
== _T("wxGLCanvasClassNR") ||
1122 #endif // wxUSE_GLCANVAS
1123 str
== wxMDIFrameClassName
||
1124 str
== wxMDIFrameClassNameNoRedraw
||
1125 str
== wxMDIChildFrameClassName
||
1126 str
== wxMDIChildFrameClassNameNoRedraw
||
1127 str
== _T("wxTLWHiddenParent"))
1128 return true; // Effectively means don't subclass
1133 // ----------------------------------------------------------------------------
1135 // ----------------------------------------------------------------------------
1137 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1139 long flagsOld
= GetWindowStyleFlag();
1140 if ( flags
== flagsOld
)
1143 // update the internal variable
1144 wxWindowBase::SetWindowStyleFlag(flags
);
1146 // now update the Windows style as well if needed - and if the window had
1147 // been already created
1151 // we may need to call SetWindowPos() when we change some styles
1152 bool callSWP
= false;
1154 WXDWORD exstyle
, exstyleOld
;
1155 long style
= MSWGetStyle(flags
, &exstyle
),
1156 styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1158 if ( style
!= styleOld
)
1160 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1161 // this function so instead of simply setting the style to the new
1162 // value we clear the bits which were set in styleOld but are set in
1163 // the new one and set the ones which were not set before
1164 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1165 styleReal
&= ~styleOld
;
1168 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1170 // If any of the style changes changed any of the frame styles:
1171 // MSDN: SetWindowLong:
1172 // Certain window data is cached, so changes you make using
1173 // SetWindowLong will not take effect until you call the
1174 // SetWindowPos function. Specifically, if you change any of
1175 // the frame styles, you must call SetWindowPos with the
1176 // SWP_FRAMECHANGED flag for the cache to be updated properly.
1178 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1187 // and the extended style
1188 long exstyleReal
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1190 if ( exstyle
!= exstyleOld
)
1192 exstyleReal
&= ~exstyleOld
;
1193 exstyleReal
|= exstyle
;
1195 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyleReal
);
1197 // ex style changes don't take effect without calling SetWindowPos
1203 // we must call SetWindowPos() to flush the cached extended style and
1204 // also to make the change to wxSTAY_ON_TOP style take effect: just
1205 // setting the style simply doesn't work
1206 if ( !::SetWindowPos(GetHwnd(),
1207 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1210 SWP_NOMOVE
| SWP_NOSIZE
| SWP_FRAMECHANGED
) )
1212 wxLogLastError(_T("SetWindowPos"));
1217 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1219 // translate common wxWidgets styles to Windows ones
1221 // most of windows are child ones, those which are not (such as
1222 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1223 WXDWORD style
= WS_CHILD
;
1225 // using this flag results in very significant reduction in flicker,
1226 // especially with controls inside the static boxes (as the interior of the
1227 // box is not redrawn twice), but sometimes results in redraw problems, so
1228 // optionally allow the old code to continue to use it provided a special
1229 // system option is turned on
1230 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1231 || (flags
& wxCLIP_CHILDREN
) )
1232 style
|= WS_CLIPCHILDREN
;
1234 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1235 // don't support overlapping windows and it only makes sense for them and,
1236 // presumably, gives the system some extra work (to manage more clipping
1237 // regions), so avoid it alltogether
1240 if ( flags
& wxVSCROLL
)
1241 style
|= WS_VSCROLL
;
1243 if ( flags
& wxHSCROLL
)
1244 style
|= WS_HSCROLL
;
1246 const wxBorder border
= GetBorder(flags
);
1248 // WS_BORDER is only required for wxBORDER_SIMPLE
1249 if ( border
== wxBORDER_SIMPLE
)
1252 // now deal with ext style if the caller wants it
1258 if ( flags
& wxTRANSPARENT_WINDOW
)
1259 *exstyle
|= WS_EX_TRANSPARENT
;
1265 case wxBORDER_DEFAULT
:
1266 wxFAIL_MSG( _T("unknown border style") );
1270 case wxBORDER_SIMPLE
:
1273 case wxBORDER_STATIC
:
1274 *exstyle
|= WS_EX_STATICEDGE
;
1277 case wxBORDER_RAISED
:
1278 *exstyle
|= WS_EX_DLGMODALFRAME
;
1281 case wxBORDER_SUNKEN
:
1282 *exstyle
|= WS_EX_CLIENTEDGE
;
1283 style
&= ~WS_BORDER
;
1286 case wxBORDER_DOUBLE
:
1287 *exstyle
|= WS_EX_DLGMODALFRAME
;
1291 // wxUniv doesn't use Windows dialog navigation functions at all
1292 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1293 // to make the dialog navigation work with the nested panels we must
1294 // use this style (top level windows such as dialogs don't need it)
1295 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1297 *exstyle
|= WS_EX_CONTROLPARENT
;
1299 #endif // __WXUNIVERSAL__
1305 // Setup background and foreground colours correctly
1306 void wxWindowMSW::SetupColours()
1309 SetBackgroundColour(GetParent()->GetBackgroundColour());
1312 bool wxWindowMSW::IsMouseInWindow() const
1314 // get the mouse position
1317 ::GetCursorPosWinCE(&pt
);
1319 ::GetCursorPos(&pt
);
1322 // find the window which currently has the cursor and go up the window
1323 // chain until we find this window - or exhaust it
1324 HWND hwnd
= ::WindowFromPoint(pt
);
1325 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1326 hwnd
= ::GetParent(hwnd
);
1328 return hwnd
!= NULL
;
1331 void wxWindowMSW::OnInternalIdle()
1333 #ifndef HAVE_TRACKMOUSEEVENT
1334 // Check if we need to send a LEAVE event
1335 if ( m_mouseInWindow
)
1337 // note that we should generate the leave event whether the window has
1338 // or doesn't have mouse capture
1339 if ( !IsMouseInWindow() )
1341 GenerateMouseLeave();
1344 #endif // !HAVE_TRACKMOUSEEVENT
1346 if (wxUpdateUIEvent::CanUpdate(this))
1347 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1350 // Set this window to be the child of 'parent'.
1351 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1353 if ( !wxWindowBase::Reparent(parent
) )
1356 HWND hWndChild
= GetHwnd();
1357 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1359 ::SetParent(hWndChild
, hWndParent
);
1362 if ( ::GetWindowLong(hWndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1364 EnsureParentHasControlParentStyle(GetParent());
1366 #endif // !__WXWINCE__
1371 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1373 #ifndef __WXMICROWIN__
1374 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1378 void wxWindowMSW::Freeze()
1380 if ( !m_frozenness
++ )
1383 SendSetRedraw(GetHwnd(), false);
1387 void wxWindowMSW::Thaw()
1389 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1391 if ( --m_frozenness
== 0 )
1395 SendSetRedraw(GetHwnd(), true);
1397 // we need to refresh everything or otherwise the invalidated area
1398 // is not going to be repainted
1404 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1406 HWND hWnd
= GetHwnd();
1413 mswRect
.left
= rect
->x
;
1414 mswRect
.top
= rect
->y
;
1415 mswRect
.right
= rect
->x
+ rect
->width
;
1416 mswRect
.bottom
= rect
->y
+ rect
->height
;
1425 // RedrawWindow not available on SmartPhone or eVC++ 3
1426 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1427 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1431 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1433 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1438 void wxWindowMSW::Update()
1440 if ( !::UpdateWindow(GetHwnd()) )
1442 wxLogLastError(_T("UpdateWindow"));
1445 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1446 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1447 // handler needs to be really drawn right now
1452 // ---------------------------------------------------------------------------
1454 // ---------------------------------------------------------------------------
1456 // we need to lower the sibling static boxes so controls contained within can be
1458 static inline void AdjustStaticBoxZOrder(wxWindow
*parent
)
1460 // no sibling static boxes if we have no parent (ie TLW)
1464 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1466 node
= node
->GetNext() )
1468 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1471 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1472 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1477 #if wxUSE_DRAG_AND_DROP
1478 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1480 if ( m_dropTarget
!= 0 ) {
1481 m_dropTarget
->Revoke(m_hWnd
);
1482 delete m_dropTarget
;
1485 m_dropTarget
= pDropTarget
;
1486 if ( m_dropTarget
!= 0 )
1488 AdjustStaticBoxZOrder(GetParent());
1489 m_dropTarget
->Register(m_hWnd
);
1492 #endif // wxUSE_DRAG_AND_DROP
1494 // old-style file manager drag&drop support: we retain the old-style
1495 // DragAcceptFiles in parallel with SetDropTarget.
1496 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1499 HWND hWnd
= GetHwnd();
1502 AdjustStaticBoxZOrder(GetParent());
1503 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1508 // ----------------------------------------------------------------------------
1510 // ----------------------------------------------------------------------------
1514 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1516 wxWindowBase::DoSetToolTip(tooltip
);
1519 m_tooltip
->SetWindow((wxWindow
*)this);
1522 #endif // wxUSE_TOOLTIPS
1524 // ---------------------------------------------------------------------------
1525 // moving and resizing
1526 // ---------------------------------------------------------------------------
1528 bool wxWindowMSW::IsSizeDeferred() const
1530 #if USE_DEFERRED_SIZING
1531 if ( m_pendingPosition
!= wxDefaultPosition
||
1532 m_pendingSize
!= wxDefaultSize
)
1534 #endif // USE_DEFERRED_SIZING
1540 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1542 // if SetSize() had been called at wx level but not realized at Windows
1543 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1544 // the new and not the old position to the other wx code
1545 if ( m_pendingSize
!= wxDefaultSize
)
1548 *x
= m_pendingSize
.x
;
1550 *y
= m_pendingSize
.y
;
1552 else // use current size
1554 RECT rect
= wxGetWindowRect(GetHwnd());
1557 *x
= rect
.right
- rect
.left
;
1559 *y
= rect
.bottom
- rect
.top
;
1563 // Get size *available for subwindows* i.e. excluding menu bar etc.
1564 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1566 #if USE_DEFERRED_SIZING
1567 if ( IsTopLevel() || m_pendingSize
== wxDefaultSize
)
1569 { // top level windows resizing is never deferred, so we can safely use
1570 // the current size here
1571 RECT rect
= wxGetClientRect(GetHwnd());
1578 #if USE_DEFERRED_SIZING
1579 else // non top level and using deferred sizing
1581 // we need to calculate the *pending* client size here
1583 rect
.left
= m_pendingPosition
.x
;
1584 rect
.top
= m_pendingPosition
.y
;
1585 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1586 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1588 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1591 *x
= rect
.right
- rect
.left
;
1593 *y
= rect
.bottom
- rect
.top
;
1598 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1600 wxWindow
* const parent
= GetParent();
1603 if ( m_pendingPosition
!= wxDefaultPosition
)
1605 pos
= m_pendingPosition
;
1607 else // use current position
1609 RECT rect
= wxGetWindowRect(GetHwnd());
1612 point
.x
= rect
.left
;
1615 // we do the adjustments with respect to the parent only for the "real"
1616 // children, not for the dialogs/frames
1617 if ( !IsTopLevel() )
1619 // Since we now have the absolute screen coords, if there's a
1620 // parent we must subtract its top left corner
1623 ::ScreenToClient(GetHwndOf(parent
), &point
);
1631 // we also must adjust by the client area offset: a control which is just
1632 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1633 if ( parent
&& !IsTopLevel() )
1635 const wxPoint
pt(parent
->GetClientAreaOrigin());
1646 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1654 ::ScreenToClient(GetHwnd(), &pt
);
1662 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1670 ::ClientToScreen(GetHwnd(), &pt
);
1679 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1681 #if USE_DEFERRED_SIZING
1682 // if our parent had prepared a defer window handle for us, use it (unless
1683 // we are a top level window)
1684 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1686 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1689 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1690 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1693 wxLogLastError(_T("DeferWindowPos"));
1699 // hdwp must be updated as it may have been changed
1700 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1705 // did deferred move, remember new coordinates of the window as they're
1706 // different from what Windows would return for it
1710 // otherwise (or if deferring failed) move the window in place immediately
1711 #endif // USE_DEFERRED_SIZING
1712 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
1714 wxLogLastError(wxT("MoveWindow"));
1717 // if USE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1718 // ignored otherwise
1722 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1724 // TODO: is this consistent with other platforms?
1725 // Still, negative width or height shouldn't be allowed
1731 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
1733 #if USE_DEFERRED_SIZING
1734 m_pendingPosition
= wxPoint(x
, y
);
1735 m_pendingSize
= wxSize(width
, height
);
1736 #endif // USE_DEFERRED_SIZING
1740 // set the size of the window: if the dimensions are positive, just use them,
1741 // but if any of them is equal to -1, it means that we must find the value for
1742 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1743 // which case -1 is a valid value for x and y)
1745 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1746 // the width/height to best suit our contents, otherwise we reuse the current
1748 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1750 // get the current size and position...
1751 int currentX
, currentY
;
1752 int currentW
, currentH
;
1754 GetPosition(¤tX
, ¤tY
);
1755 GetSize(¤tW
, ¤tH
);
1757 // ... and don't do anything (avoiding flicker) if it's already ok unless
1758 // we're forced to resize the window
1759 if ( x
== currentX
&& y
== currentY
&&
1760 width
== currentW
&& height
== currentH
&&
1761 !(sizeFlags
& wxSIZE_FORCE
) )
1766 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1768 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1771 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1773 wxSize size
= wxDefaultSize
;
1774 if ( width
== wxDefaultCoord
)
1776 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1778 size
= DoGetBestSize();
1783 // just take the current one
1788 if ( height
== wxDefaultCoord
)
1790 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1792 if ( size
.x
== wxDefaultCoord
)
1794 size
= DoGetBestSize();
1796 //else: already called DoGetBestSize() above
1802 // just take the current one
1807 DoMoveWindow(x
, y
, width
, height
);
1810 void wxWindowMSW::DoSetClientSize(int width
, int height
)
1812 // setting the client size is less obvious than it could have been
1813 // because in the result of changing the total size the window scrollbar
1814 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
1815 // doesn't take neither into account) and so the client size will not be
1816 // correct as the difference between the total and client size changes --
1817 // so we keep changing it until we get it right
1819 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1820 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1821 // may become 3 if the window had 0 size originally and so we didn't
1822 // calculate the scrollbar correction correctly during the first iteration)
1823 // but just to be on the safe side we check for it instead of making it an
1824 // "infinite" loop (i.e. leaving break inside as the only way to get out)
1825 for ( int i
= 0; i
< 4; i
++ )
1828 ::GetClientRect(GetHwnd(), &rectClient
);
1830 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
1831 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
1832 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
1837 // Find the difference between the entire window (title bar and all)
1838 // and the client area; add this to the new client size to move the
1841 ::GetWindowRect(GetHwnd(), &rectWin
);
1843 const int widthWin
= rectWin
.right
- rectWin
.left
,
1844 heightWin
= rectWin
.bottom
- rectWin
.top
;
1846 // MoveWindow positions the child windows relative to the parent, so
1847 // adjust if necessary
1848 if ( !IsTopLevel() )
1850 wxWindow
*parent
= GetParent();
1853 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
1857 // don't call DoMoveWindow() because we want to move window immediately
1858 // and not defer it here as otherwise the value returned by
1859 // GetClient/WindowRect() wouldn't change as the window wouldn't be
1861 if ( !::MoveWindow(GetHwnd(),
1864 width
+ widthWin
- rectClient
.right
,
1865 height
+ heightWin
- rectClient
.bottom
,
1868 wxLogLastError(_T("MoveWindow"));
1873 // ---------------------------------------------------------------------------
1875 // ---------------------------------------------------------------------------
1877 int wxWindowMSW::GetCharHeight() const
1879 return wxGetTextMetrics(this).tmHeight
;
1882 int wxWindowMSW::GetCharWidth() const
1884 // +1 is needed because Windows apparently adds it when calculating the
1885 // dialog units size in pixels
1886 #if wxDIALOG_UNIT_COMPATIBILITY
1887 return wxGetTextMetrics(this).tmAveCharWidth
;
1889 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
1893 void wxWindowMSW::GetTextExtent(const wxString
& string
,
1895 int *descent
, int *externalLeading
,
1896 const wxFont
*theFont
) const
1898 wxASSERT_MSG( !theFont
|| theFont
->Ok(),
1899 _T("invalid font in GetTextExtent()") );
1903 fontToUse
= *theFont
;
1905 fontToUse
= GetFont();
1907 WindowHDC
hdc(GetHwnd());
1908 SelectInHDC
selectFont(hdc
, GetHfontOf(fontToUse
));
1912 ::GetTextExtentPoint32(hdc
, string
, string
.length(), &sizeRect
);
1913 GetTextMetrics(hdc
, &tm
);
1920 *descent
= tm
.tmDescent
;
1921 if ( externalLeading
)
1922 *externalLeading
= tm
.tmExternalLeading
;
1925 // ---------------------------------------------------------------------------
1927 // ---------------------------------------------------------------------------
1929 #if wxUSE_MENUS_NATIVE
1931 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
1932 // immediately, without waiting for the next event loop iteration
1934 // NB: this function should probably be made public later as it can almost
1935 // surely replace wxYield() elsewhere as well
1936 static void wxYieldForCommandsOnly()
1938 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
1939 // want to process it here)
1941 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
1943 if ( msg
.message
== WM_QUIT
)
1945 // if we retrieved a WM_QUIT, insert back into the message queue.
1946 ::PostQuitMessage(0);
1950 // luckily (as we don't have access to wxEventLoopImpl method from here
1951 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
1953 ::TranslateMessage(&msg
);
1954 ::DispatchMessage(&msg
);
1958 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1960 menu
->SetInvokingWindow(this);
1963 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1965 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
1966 x
= mouse
.x
; y
= mouse
.y
;
1969 HWND hWnd
= GetHwnd();
1970 HMENU hMenu
= GetHmenuOf(menu
);
1974 ::ClientToScreen(hWnd
, &point
);
1975 wxCurrentPopupMenu
= menu
;
1976 #if defined(__WXWINCE__)
1979 UINT flags
= TPM_RIGHTBUTTON
| TPM_RECURSE
;
1981 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
1983 // we need to do it right now as otherwise the events are never going to be
1984 // sent to wxCurrentPopupMenu from HandleCommand()
1986 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
1987 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
1988 // destroyed as soon as we return (it can be a local variable in the caller
1989 // for example) and so we do need to process the event immediately
1990 wxYieldForCommandsOnly();
1992 wxCurrentPopupMenu
= NULL
;
1994 menu
->SetInvokingWindow(NULL
);
1999 #endif // wxUSE_MENUS_NATIVE
2001 // ===========================================================================
2002 // pre/post message processing
2003 // ===========================================================================
2005 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2008 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2010 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2013 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2015 // wxUniversal implements tab traversal itself
2016 #ifndef __WXUNIVERSAL__
2017 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2019 // intercept dialog navigation keys
2020 MSG
*msg
= (MSG
*)pMsg
;
2022 // here we try to do all the job which ::IsDialogMessage() usually does
2024 if ( msg
->message
== WM_KEYDOWN
)
2026 bool bCtrlDown
= wxIsCtrlDown();
2027 bool bShiftDown
= wxIsShiftDown();
2029 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2030 // don't process it if it's the case (except for Ctrl-Tab/Enter
2031 // combinations which are always processed)
2035 lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2037 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2038 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2039 // it, of course, implies them
2040 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2042 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2046 bool bForward
= true,
2047 bWindowChange
= false,
2050 // should we process this message specially?
2051 bool bProcess
= true;
2052 switch ( msg
->wParam
)
2055 if ( lDlgCode
& DLGC_WANTTAB
) {
2059 // Ctrl-Tab cycles thru notebook pages
2060 bWindowChange
= bCtrlDown
;
2061 bForward
= !bShiftDown
;
2068 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2076 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2082 if ( (lDlgCode
& DLGC_WANTMESSAGE
) && !bCtrlDown
)
2084 // control wants to process Enter itself, don't
2085 // call IsDialogMessage() which would interpret
2090 // currently active button should get enter press even
2091 // if there is a default button elsewhere
2092 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2094 // let IsDialogMessage() handle this for all
2095 // buttons except the owner-drawn ones which it
2096 // just seems to ignore
2097 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2098 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2100 // emulate the button click
2102 btn
= wxFindWinFromHandle((WXHWND
)msg
->hwnd
);
2104 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2109 else // not a button itself
2112 wxButton
*btn
= wxDynamicCast(GetDefaultItem(),
2114 if ( btn
&& btn
->IsEnabled() )
2116 // if we do have a default button, do press it
2117 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2121 else // no default button
2122 #endif // wxUSE_BUTTON
2125 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2126 event
.SetEventObject(this);
2127 if(GetEventHandler()->ProcessEvent(event
))
2130 // this is a quick and dirty test for a text
2132 if ( !(lDlgCode
& DLGC_HASSETSEL
) )
2134 // don't process Enter, the control might
2135 // need it for itself and don't let
2136 // ::IsDialogMessage() have it as it can
2137 // eat the Enter events sometimes
2140 else if (!IsTopLevel())
2142 // if not a top level window, let parent
2146 //else: treat Enter as TAB: pass to the next
2147 // control as this is the best thing to do
2148 // if the text doesn't handle Enter itself
2160 wxNavigationKeyEvent event
;
2161 event
.SetDirection(bForward
);
2162 event
.SetWindowChange(bWindowChange
);
2163 event
.SetFromTab(bFromTab
);
2164 event
.SetEventObject(this);
2166 if ( GetEventHandler()->ProcessEvent(event
) )
2168 // as we don't call IsDialogMessage(), which would take of
2169 // this by default, we need to manually send this message
2170 // so that controls can change their UI state if needed
2171 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2178 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2179 // message even when there is no cancel button and when the message is
2180 // needed by the control itself: in particular, it prevents the tree in
2181 // place edit control from being closed with Escape in a dialog
2182 if ( msg
->message
!= WM_KEYDOWN
|| msg
->wParam
!= VK_ESCAPE
)
2184 // ::IsDialogMessage() is broken and may sometimes hang the
2185 // application by going into an infinite loop, so we try to detect
2186 // [some of] the situations when this may happen and not call it
2189 // assume we can call it by default
2190 bool canSafelyCallIsDlgMsg
= true;
2192 HWND hwndFocus
= ::GetFocus();
2194 // if the currently focused window itself has WS_EX_CONTROLPARENT style, ::IsDialogMessage() will also enter
2195 // an infinite loop, because it will recursively check the child
2196 // windows but not the window itself and so if none of the children
2197 // accepts focus it loops forever (as it only stops when it gets
2198 // back to the window it started from)
2200 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2201 // style has the focus, it can happen. One such possibility is if
2202 // all windows are either toplevel, wxDialog, wxPanel or static
2203 // controls and no window can actually accept keyboard input.
2204 #if !defined(__WXWINCE__)
2205 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2207 // pessimistic by default
2208 canSafelyCallIsDlgMsg
= false;
2209 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2211 node
= node
->GetNext() )
2213 wxWindow
* const win
= node
->GetData();
2214 if ( win
->AcceptsFocus() &&
2215 !(::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
) &
2216 WS_EX_CONTROLPARENT
) )
2218 // it shouldn't hang...
2219 canSafelyCallIsDlgMsg
= true;
2225 #endif // !__WXWINCE__
2227 if ( canSafelyCallIsDlgMsg
)
2229 // ::IsDialogMessage() can enter in an infinite loop when the
2230 // currently focused window is disabled or hidden and its
2231 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2235 if ( !::IsWindowEnabled(hwndFocus
) ||
2236 !::IsWindowVisible(hwndFocus
) )
2238 // it would enter an infinite loop if we do this!
2239 canSafelyCallIsDlgMsg
= false;
2244 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2246 // it's a top level window, don't go further -- e.g. even
2247 // if the parent of a dialog is disabled, this doesn't
2248 // break navigation inside the dialog
2252 hwndFocus
= ::GetParent(hwndFocus
);
2256 // let IsDialogMessage() have the message if it's safe to call it
2257 if ( canSafelyCallIsDlgMsg
&& ::IsDialogMessage(GetHwnd(), msg
) )
2259 // IsDialogMessage() did something...
2264 #endif // __WXUNIVERSAL__
2269 // relay mouse move events to the tooltip control
2270 MSG
*msg
= (MSG
*)pMsg
;
2271 if ( msg
->message
== WM_MOUSEMOVE
)
2272 wxToolTip::RelayEvent(pMsg
);
2274 #endif // wxUSE_TOOLTIPS
2279 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2281 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2282 return m_acceleratorTable
.Translate(this, pMsg
);
2286 #endif // wxUSE_ACCEL
2289 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* WXUNUSED(pMsg
))
2291 // preprocess all messages by default
2295 // ---------------------------------------------------------------------------
2296 // message params unpackers
2297 // ---------------------------------------------------------------------------
2299 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2300 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2302 *id
= LOWORD(wParam
);
2303 *hwnd
= (WXHWND
)lParam
;
2304 *cmd
= HIWORD(wParam
);
2307 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2308 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2310 *state
= LOWORD(wParam
);
2311 *minimized
= HIWORD(wParam
);
2312 *hwnd
= (WXHWND
)lParam
;
2315 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2316 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2318 *code
= LOWORD(wParam
);
2319 *pos
= HIWORD(wParam
);
2320 *hwnd
= (WXHWND
)lParam
;
2323 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2324 WXHDC
*hdc
, WXHWND
*hwnd
)
2326 *hwnd
= (WXHWND
)lParam
;
2327 *hdc
= (WXHDC
)wParam
;
2330 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2331 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2333 *item
= (WXWORD
)wParam
;
2334 *flags
= HIWORD(wParam
);
2335 *hmenu
= (WXHMENU
)lParam
;
2338 // ---------------------------------------------------------------------------
2339 // Main wxWidgets window proc and the window proc for wxWindow
2340 // ---------------------------------------------------------------------------
2342 // Hook for new window just as it's being created, when the window isn't yet
2343 // associated with the handle
2344 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2346 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2347 // window being created and insures that it's always unset back later
2348 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2350 gs_winBeingCreated
= winBeingCreated
;
2353 wxWindowCreationHook::~wxWindowCreationHook()
2355 gs_winBeingCreated
= NULL
;
2359 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2361 // trace all messages - useful for the debugging
2363 wxLogTrace(wxTraceMessages
,
2364 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2365 wxGetMessageName(message
), (long)hWnd
, (long)wParam
, lParam
);
2366 #endif // __WXDEBUG__
2368 wxWindowMSW
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
2370 // when we get the first message for the HWND we just created, we associate
2371 // it with wxWindow stored in gs_winBeingCreated
2372 if ( !wnd
&& gs_winBeingCreated
)
2374 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2375 wnd
= gs_winBeingCreated
;
2376 gs_winBeingCreated
= NULL
;
2377 wnd
->SetHWND((WXHWND
)hWnd
);
2382 if ( wnd
&& wxEventLoop::AllowProcessing(wnd
) )
2383 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2385 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2390 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2392 // did we process the message?
2393 bool processed
= false;
2403 // for most messages we should return 0 when we do process the message
2411 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2414 // return 0 to allow window creation
2415 rc
.result
= mayCreate
? 0 : -1;
2421 // never set processed to true and *always* pass WM_DESTROY to
2422 // DefWindowProc() as Windows may do some internal cleanup when
2423 // processing it and failing to pass the message along may cause
2424 // memory and resource leaks!
2425 (void)HandleDestroy();
2429 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2433 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2436 #if !defined(__WXWINCE__)
2439 LPRECT pRect
= (LPRECT
)lParam
;
2441 rc
.SetLeft(pRect
->left
);
2442 rc
.SetTop(pRect
->top
);
2443 rc
.SetRight(pRect
->right
);
2444 rc
.SetBottom(pRect
->bottom
);
2445 processed
= HandleMoving(rc
);
2447 pRect
->left
= rc
.GetLeft();
2448 pRect
->top
= rc
.GetTop();
2449 pRect
->right
= rc
.GetRight();
2450 pRect
->bottom
= rc
.GetBottom();
2457 LPRECT pRect
= (LPRECT
)lParam
;
2459 rc
.SetLeft(pRect
->left
);
2460 rc
.SetTop(pRect
->top
);
2461 rc
.SetRight(pRect
->right
);
2462 rc
.SetBottom(pRect
->bottom
);
2463 processed
= HandleSizing(rc
);
2465 pRect
->left
= rc
.GetLeft();
2466 pRect
->top
= rc
.GetTop();
2467 pRect
->right
= rc
.GetRight();
2468 pRect
->bottom
= rc
.GetBottom();
2472 #endif // !__WXWINCE__
2474 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2475 case WM_ACTIVATEAPP
:
2476 // This implicitly sends a wxEVT_ACTIVATE_APP event
2477 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2483 WXWORD state
, minimized
;
2485 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2487 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2492 processed
= HandleSetFocus((WXHWND
)(HWND
)wParam
);
2496 processed
= HandleKillFocus((WXHWND
)(HWND
)wParam
);
2499 case WM_PRINTCLIENT
:
2500 processed
= HandlePrintClient((WXHDC
)wParam
);
2506 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2508 processed
= HandlePaint();
2512 processed
= HandlePaint();
2517 #ifdef __WXUNIVERSAL__
2518 // Universal uses its own wxFrame/wxDialog, so we don't receive
2519 // close events unless we have this.
2521 #endif // __WXUNIVERSAL__
2523 // don't let the DefWindowProc() destroy our window - we'll do it
2524 // ourselves in ~wxWindow
2530 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2534 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2535 GET_Y_LPARAM(lParam
),
2539 #ifdef HAVE_TRACKMOUSEEVENT
2541 // filter out excess WM_MOUSELEAVE events sent after PopupMenu() (on XP at least)
2542 if ( m_mouseInWindow
)
2544 GenerateMouseLeave();
2547 // always pass processed back as false, this allows the window
2548 // manager to process the message too. This is needed to
2549 // ensure windows XP themes work properly as the mouse moves
2550 // over widgets like buttons. So don't set processed to true here.
2552 #endif // HAVE_TRACKMOUSEEVENT
2554 #if wxUSE_MOUSEWHEEL
2556 processed
= HandleMouseWheel(wParam
, lParam
);
2560 case WM_LBUTTONDOWN
:
2562 case WM_LBUTTONDBLCLK
:
2563 case WM_RBUTTONDOWN
:
2565 case WM_RBUTTONDBLCLK
:
2566 case WM_MBUTTONDOWN
:
2568 case WM_MBUTTONDBLCLK
:
2570 #ifdef __WXMICROWIN__
2571 // MicroWindows seems to ignore the fact that a window is
2572 // disabled. So catch mouse events and throw them away if
2574 wxWindowMSW
* win
= this;
2577 if (!win
->IsEnabled())
2583 win
= win
->GetParent();
2584 if ( !win
|| win
->IsTopLevel() )
2591 #endif // __WXMICROWIN__
2592 int x
= GET_X_LPARAM(lParam
),
2593 y
= GET_Y_LPARAM(lParam
);
2596 // redirect the event to a static control if necessary by
2597 // finding one under mouse because under CE the static controls
2598 // don't generate mouse events (even with SS_NOTIFY)
2600 if ( GetCapture() == this )
2602 // but don't do it if the mouse is captured by this window
2603 // because then it should really get this event itself
2608 win
= FindWindowForMouseEvent(this, &x
, &y
);
2610 // this should never happen
2611 wxCHECK_MSG( win
, 0,
2612 _T("FindWindowForMouseEvent() returned NULL") );
2615 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
2617 SHRGINFO shrgi
= {0};
2619 shrgi
.cbSize
= sizeof(SHRGINFO
);
2620 shrgi
.hwndClient
= (HWND
) GetHWND();
2624 shrgi
.dwFlags
= SHRG_RETURNCMD
;
2625 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
2627 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
2630 pt
= ClientToScreen(pt
);
2632 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2634 evtCtx
.SetEventObject(this);
2635 if (GetEventHandler()->ProcessEvent(evtCtx
))
2644 #else // !__WXWINCE__
2645 wxWindowMSW
*win
= this;
2646 #endif // __WXWINCE__/!__WXWINCE__
2648 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2650 // if the app didn't eat the event, handle it in the default
2651 // way, that is by giving this window the focus
2654 // for the standard classes their WndProc sets the focus to
2655 // them anyhow and doing it from here results in some weird
2656 // problems, so don't do it for them (unnecessary anyhow)
2657 if ( !win
->IsOfStandardClass() )
2659 if ( message
== WM_LBUTTONDOWN
&& win
->AcceptsFocus() )
2671 case MM_JOY1BUTTONDOWN
:
2672 case MM_JOY2BUTTONDOWN
:
2673 case MM_JOY1BUTTONUP
:
2674 case MM_JOY2BUTTONUP
:
2675 processed
= HandleJoystickEvent(message
,
2676 GET_X_LPARAM(lParam
),
2677 GET_Y_LPARAM(lParam
),
2680 #endif // __WXMICROWIN__
2686 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2688 processed
= HandleCommand(id
, cmd
, hwnd
);
2693 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2696 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
2697 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
2698 // apparently doesn't always behave properly and needs some help
2699 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
2700 case WM_NOTIFYFORMAT
:
2701 if ( lParam
== NF_QUERY
)
2704 rc
.result
= NFR_UNICODE
;
2707 #endif // wxUSE_UNICODE_MSLU
2709 // for these messages we must return true if process the message
2712 case WM_MEASUREITEM
:
2714 int idCtrl
= (UINT
)wParam
;
2715 if ( message
== WM_DRAWITEM
)
2717 processed
= MSWOnDrawItem(idCtrl
,
2718 (WXDRAWITEMSTRUCT
*)lParam
);
2722 processed
= MSWOnMeasureItem(idCtrl
,
2723 (WXMEASUREITEMSTRUCT
*)lParam
);
2730 #endif // defined(WM_DRAWITEM)
2733 if ( !IsOfStandardClass() )
2735 // we always want to get the char events
2736 rc
.result
= DLGC_WANTCHARS
;
2738 if ( GetWindowStyleFlag() & wxWANTS_CHARS
)
2740 // in fact, we want everything
2741 rc
.result
|= DLGC_WANTARROWS
|
2748 //else: get the dlg code from the DefWindowProc()
2753 // If this has been processed by an event handler, return 0 now
2754 // (we've handled it).
2755 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
2756 if ( m_lastKeydownProcessed
)
2765 // we consider these messages "not interesting" to OnChar, so
2766 // just don't do anything more with them
2776 // avoid duplicate messages to OnChar for these ASCII keys:
2777 // they will be translated by TranslateMessage() and received
2809 // but set processed to false, not true to still pass them
2810 // to the control's default window proc - otherwise
2811 // built-in keyboard handling won't work
2816 // special case of VK_APPS: treat it the same as right mouse
2817 // click because both usually pop up a context menu
2819 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
2824 // do generate a CHAR event
2825 processed
= HandleChar((WORD
)wParam
, lParam
);
2828 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
2835 // special case of VK_APPS: treat it the same as right mouse button
2836 if ( wParam
== VK_APPS
)
2838 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
2843 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
2848 case WM_CHAR
: // Always an ASCII character
2849 if ( m_lastKeydownProcessed
)
2851 // The key was handled in the EVT_KEY_DOWN and handling
2852 // a key in an EVT_KEY_DOWN handler is meant, by
2853 // design, to prevent EVT_CHARs from happening
2854 m_lastKeydownProcessed
= false;
2859 processed
= HandleChar((WORD
)wParam
, lParam
, true);
2865 processed
= HandleHotKey((WORD
)wParam
, lParam
);
2867 #endif // wxUSE_HOTKEY
2874 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
2876 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
2882 // CTLCOLOR messages are sent by children to query the parent for their
2884 #ifndef __WXMICROWIN__
2885 case WM_CTLCOLORMSGBOX
:
2886 case WM_CTLCOLOREDIT
:
2887 case WM_CTLCOLORLISTBOX
:
2888 case WM_CTLCOLORBTN
:
2889 case WM_CTLCOLORDLG
:
2890 case WM_CTLCOLORSCROLLBAR
:
2891 case WM_CTLCOLORSTATIC
:
2895 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
2897 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
2900 #endif // !__WXMICROWIN__
2902 case WM_SYSCOLORCHANGE
:
2903 // the return value for this message is ignored
2904 processed
= HandleSysColorChange();
2907 #if !defined(__WXWINCE__)
2908 case WM_DISPLAYCHANGE
:
2909 processed
= HandleDisplayChange();
2913 case WM_PALETTECHANGED
:
2914 processed
= HandlePaletteChanged((WXHWND
) (HWND
) wParam
);
2917 case WM_CAPTURECHANGED
:
2918 processed
= HandleCaptureChanged((WXHWND
) (HWND
) lParam
);
2921 case WM_SETTINGCHANGE
:
2922 processed
= HandleSettingChange(wParam
, lParam
);
2925 case WM_QUERYNEWPALETTE
:
2926 processed
= HandleQueryNewPalette();
2930 processed
= HandleEraseBkgnd((WXHDC
)(HDC
)wParam
);
2933 // we processed the message, i.e. erased the background
2938 #if !defined(__WXWINCE__)
2940 processed
= HandleDropFiles(wParam
);
2945 processed
= HandleInitDialog((WXHWND
)(HWND
)wParam
);
2949 // we never set focus from here
2954 #if !defined(__WXWINCE__)
2955 case WM_QUERYENDSESSION
:
2956 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
2960 processed
= HandleEndSession(wParam
!= 0, lParam
);
2963 case WM_GETMINMAXINFO
:
2964 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
2969 processed
= HandleSetCursor((WXHWND
)(HWND
)wParam
,
2970 LOWORD(lParam
), // hit test
2971 HIWORD(lParam
)); // mouse msg
2975 // returning TRUE stops the DefWindowProc() from further
2976 // processing this message - exactly what we need because we've
2977 // just set the cursor.
2982 #if wxUSE_ACCESSIBILITY
2985 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
2986 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
2988 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
2990 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
2996 #if defined(WM_HELP)
2999 // HELPINFO doesn't seem to be supported on WinCE.
3001 HELPINFO
* info
= (HELPINFO
*) lParam
;
3002 // Don't yet process menu help events, just windows
3003 if (info
->iContextType
== HELPINFO_WINDOW
)
3006 wxWindowMSW
* subjectOfHelp
= this;
3007 bool eventProcessed
= false;
3008 while (subjectOfHelp
&& !eventProcessed
)
3010 wxHelpEvent
helpEvent(wxEVT_HELP
,
3011 subjectOfHelp
->GetId(),
3015 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3019 helpEvent
.SetEventObject(this);
3021 GetEventHandler()->ProcessEvent(helpEvent
);
3023 // Go up the window hierarchy until the event is
3025 subjectOfHelp
= subjectOfHelp
->GetParent();
3028 processed
= eventProcessed
;
3031 else if (info
->iContextType
== HELPINFO_MENUITEM
)
3033 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3034 helpEvent
.SetEventObject(this);
3035 processed
= GetEventHandler()->ProcessEvent(helpEvent
);
3038 //else: processed is already false
3044 #if !defined(__WXWINCE__)
3045 case WM_CONTEXTMENU
:
3047 // we don't convert from screen to client coordinates as
3048 // the event may be handled by a parent window
3049 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3051 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3053 // we could have got an event from our child, reflect it back
3054 // to it if this is the case
3055 wxWindowMSW
*win
= NULL
;
3056 if ( (WXHWND
)wParam
!= m_hWnd
)
3058 win
= FindItemByHWND((WXHWND
)wParam
);
3064 evtCtx
.SetEventObject(win
);
3065 processed
= win
->GetEventHandler()->ProcessEvent(evtCtx
);
3071 // we're only interested in our own menus, not MF_SYSMENU
3072 if ( HIWORD(wParam
) == MF_POPUP
)
3074 // handle menu chars for ownerdrawn menu items
3075 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3076 if ( i
!= wxNOT_FOUND
)
3078 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3084 case WM_POWERBROADCAST
:
3087 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3088 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3096 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
3097 wxGetMessageName(message
));
3098 #endif // __WXDEBUG__
3099 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3105 // ----------------------------------------------------------------------------
3106 // wxWindow <-> HWND map
3107 // ----------------------------------------------------------------------------
3109 wxWinHashTable
*wxWinHandleHash
= NULL
;
3111 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
3113 return (wxWindow
*)wxWinHandleHash
->Get((long)hWnd
);
3116 void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
)
3118 // adding NULL hWnd is (first) surely a result of an error and
3119 // (secondly) breaks menu command processing
3120 wxCHECK_RET( hWnd
!= (HWND
)NULL
,
3121 wxT("attempt to add a NULL hWnd to window list ignored") );
3123 wxWindow
*oldWin
= wxFindWinFromHandle((WXHWND
) hWnd
);
3125 if ( oldWin
&& (oldWin
!= win
) )
3127 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
3128 (int) hWnd
, win
->GetClassInfo()->GetClassName());
3131 #endif // __WXDEBUG__
3134 wxWinHandleHash
->Put((long)hWnd
, (wxWindow
*)win
);
3138 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3140 wxWinHandleHash
->Delete((long)win
->GetHWND());
3143 // ----------------------------------------------------------------------------
3144 // various MSW speciic class dependent functions
3145 // ----------------------------------------------------------------------------
3147 // Default destroyer - override if you destroy it in some other way
3148 // (e.g. with MDI child windows)
3149 void wxWindowMSW::MSWDestroyWindow()
3153 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3156 int& w
, int& h
) const
3158 // yes, those are just some arbitrary hardcoded numbers
3159 static const int DEFAULT_Y
= 200;
3161 bool nonDefault
= false;
3163 if ( pos
.x
== wxDefaultCoord
)
3165 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
3166 // can just as well set it to CW_USEDEFAULT as well
3172 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
3173 // neither because it is not handled as a special value by Windows then
3174 // and so we have to choose some default value for it
3176 y
= pos
.y
== wxDefaultCoord
? DEFAULT_Y
: pos
.y
;
3182 NB: there used to be some code here which set the initial size of the
3183 window to the client size of the parent if no explicit size was
3184 specified. This was wrong because wxWidgets programs often assume
3185 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3186 it. To see why, you should understand that Windows sends WM_SIZE from
3187 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3188 from some base class ctor and so this WM_SIZE is not processed in the
3189 real class' OnSize() (because it's not fully constructed yet and the
3190 event goes to some base class OnSize() instead). So the WM_SIZE we
3191 rely on is the one sent when the parent frame resizes its children
3192 but here is the problem: if the child already has just the right
3193 size, nothing will happen as both wxWidgets and Windows check for
3194 this and ignore any attempts to change the window size to the size it
3195 already has - so no WM_SIZE would be sent.
3199 // we don't use CW_USEDEFAULT here for several reasons:
3201 // 1. it results in huge frames on modern screens (1000*800 is not
3202 // uncommon on my 1280*1024 screen) which is way too big for a half
3203 // empty frame of most of wxWidgets samples for example)
3205 // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
3206 // the default is for whatever reason 8*8 which breaks client <->
3207 // window size calculations (it would be nice if it didn't, but it
3208 // does and the simplest way to fix it seemed to change the broken
3209 // default size anyhow)
3211 // 3. there is just no advantage in doing it: with x and y it is
3212 // possible that [future versions of] Windows position the new top
3213 // level window in some smart way which we can't do, but we can
3214 // guess a reasonably good size for a new window just as well
3217 // However, on PocketPC devices, we must use the default
3218 // size if possible.
3220 if (size
.x
== wxDefaultCoord
)
3224 if (size
.y
== wxDefaultCoord
)
3229 if ( size
.x
== wxDefaultCoord
|| size
.y
== wxDefaultCoord
)
3233 w
= WidthDefault(size
.x
);
3234 h
= HeightDefault(size
.y
);
3237 AdjustForParentClientOrigin(x
, y
);
3242 WXHWND
wxWindowMSW::MSWGetParent() const
3244 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3247 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3248 const wxChar
*title
,
3252 WXDWORD extendedStyle
)
3254 // choose the position/size for the new window
3256 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3258 // controlId is menu handle for the top level windows, so set it to 0
3259 // unless we're creating a child window
3260 int controlId
= style
& WS_CHILD
? GetId() : 0;
3262 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3263 // which is the same but without CS_[HV]REDRAW class styles so using it
3264 // ensures that the window is not fully repainted on each resize
3265 wxString
className(wclass
);
3266 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3268 className
+= wxT("NR");
3271 // do create the window
3272 wxWindowCreationHook
hook(this);
3274 m_hWnd
= (WXHWND
)::CreateWindowEx
3278 title
? title
: m_windowName
.c_str(),
3281 (HWND
)MSWGetParent(),
3284 NULL
// no extra data
3289 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3294 SubclassWin(m_hWnd
);
3299 // ===========================================================================
3300 // MSW message handlers
3301 // ===========================================================================
3303 // ---------------------------------------------------------------------------
3305 // ---------------------------------------------------------------------------
3307 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3309 #ifndef __WXMICROWIN__
3310 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3311 HWND hWnd
= hdr
->hwndFrom
;
3312 wxWindow
*win
= wxFindWinFromHandle((WXHWND
)hWnd
);
3314 // if the control is one of our windows, let it handle the message itself
3317 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3320 // VZ: why did we do it? normally this is unnecessary and, besides, it
3321 // breaks the message processing for the toolbars because the tooltip
3322 // notifications were being forwarded to the toolbar child controls
3323 // (if it had any) before being passed to the toolbar itself, so in my
3324 // example the tooltip for the combobox was always shown instead of the
3325 // correct button tooltips
3327 // try all our children
3328 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3331 wxWindow
*child
= node
->GetData();
3332 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3337 node
= node
->GetNext();
3341 // by default, handle it ourselves
3342 return MSWOnNotify(idCtrl
, lParam
, result
);
3343 #else // __WXMICROWIN__
3350 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3352 const wxString
& ttip
)
3354 // I don't know why it happens, but the versions of comctl32.dll starting
3355 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3356 // this message is supposed to be sent to Unicode programs only) -- hence
3357 // we need to handle it as well, otherwise no tooltips will be shown in
3360 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3363 // not a tooltip message or no tooltip to show anyhow
3368 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3370 // We don't want to use the szText buffer because it has a limit of 80
3371 // bytes and this is not enough, especially for Unicode build where it
3372 // limits the tooltip string length to only 40 characters
3374 // The best would be, of course, to not impose any length limitations at
3375 // all but then the buffer would have to be dynamic and someone would have
3376 // to free it and we don't have the tooltip owner object here any more, so
3377 // for now use our own static buffer with a higher fixed max length.
3379 // Note that using a static buffer should not be a problem as only a single
3380 // tooltip can be shown at the same time anyhow.
3382 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3384 // We need to convert tooltip from multi byte to Unicode on the fly.
3385 static wchar_t buf
[513];
3387 // Truncate tooltip length if needed as otherwise we might not have
3388 // enough space for it in the buffer and MultiByteToWideChar() would
3390 size_t tipLength
= wxMin(ttip
.Len(), WXSIZEOF(buf
) - 1);
3392 // Convert to WideChar without adding the NULL character. The NULL
3393 // character is added afterwards (this is more efficient).
3394 int len
= ::MultiByteToWideChar
3406 wxLogLastError(_T("MultiByteToWideChar()"));
3410 ttText
->lpszText
= (LPSTR
) buf
;
3412 else // TTN_NEEDTEXTA
3413 #endif // !wxUSE_UNICODE
3415 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3416 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3417 // to copy the string we have into the buffer
3418 static wxChar buf
[513];
3419 wxStrncpy(buf
, ttip
.c_str(), WXSIZEOF(buf
) - 1);
3420 buf
[WXSIZEOF(buf
) - 1] = _T('\0');
3421 ttText
->lpszText
= buf
;
3427 #endif // wxUSE_TOOLTIPS
3429 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3431 WXLPARAM
* WXUNUSED(result
))
3436 NMHDR
* hdr
= (NMHDR
*)lParam
;
3437 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3444 wxUnusedVar(lParam
);
3445 #endif // wxUSE_TOOLTIPS
3450 // ---------------------------------------------------------------------------
3451 // end session messages
3452 // ---------------------------------------------------------------------------
3454 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3456 #ifdef ENDSESSION_LOGOFF
3457 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3458 event
.SetEventObject(wxTheApp
);
3459 event
.SetCanVeto(true);
3460 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3462 bool rc
= wxTheApp
->ProcessEvent(event
);
3466 // we may end only if the app didn't veto session closing (double
3468 *mayEnd
= !event
.GetVeto();
3473 wxUnusedVar(logOff
);
3474 wxUnusedVar(mayEnd
);
3479 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3481 #ifdef ENDSESSION_LOGOFF
3482 // do nothing if the session isn't ending
3487 if ( (this != wxTheApp
->GetTopWindow()) )
3490 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3491 event
.SetEventObject(wxTheApp
);
3492 event
.SetCanVeto(false);
3493 event
.SetLoggingOff( (logOff
== (long)ENDSESSION_LOGOFF
) );
3495 return wxTheApp
->ProcessEvent(event
);
3497 wxUnusedVar(endSession
);
3498 wxUnusedVar(logOff
);
3503 // ---------------------------------------------------------------------------
3504 // window creation/destruction
3505 // ---------------------------------------------------------------------------
3507 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3510 // VZ: why is this commented out for WinCE? If it doesn't support
3511 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3512 // not with multiple #ifdef's!
3514 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3515 EnsureParentHasControlParentStyle(GetParent());
3516 #endif // !__WXWINCE__
3523 bool wxWindowMSW::HandleDestroy()
3527 // delete our drop target if we've got one
3528 #if wxUSE_DRAG_AND_DROP
3529 if ( m_dropTarget
!= NULL
)
3531 m_dropTarget
->Revoke(m_hWnd
);
3533 delete m_dropTarget
;
3534 m_dropTarget
= NULL
;
3536 #endif // wxUSE_DRAG_AND_DROP
3538 // WM_DESTROY handled
3542 // ---------------------------------------------------------------------------
3544 // ---------------------------------------------------------------------------
3546 bool wxWindowMSW::HandleActivate(int state
,
3547 bool WXUNUSED(minimized
),
3548 WXHWND
WXUNUSED(activate
))
3550 wxActivateEvent
event(wxEVT_ACTIVATE
,
3551 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3553 event
.SetEventObject(this);
3555 return GetEventHandler()->ProcessEvent(event
);
3558 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3560 // Strangly enough, some controls get set focus events when they are being
3561 // deleted, even if they already had focus before.
3562 if ( m_isBeingDeleted
)
3567 // notify the parent keeping track of focus for the kbd navigation
3568 // purposes that we got it
3569 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3570 (void)GetEventHandler()->ProcessEvent(eventFocus
);
3576 m_caret
->OnSetFocus();
3578 #endif // wxUSE_CARET
3581 // If it's a wxTextCtrl don't send the event as it will be done
3582 // after the control gets to process it from EN_FOCUS handler
3583 if ( wxDynamicCastThis(wxTextCtrl
) )
3587 #endif // wxUSE_TEXTCTRL
3589 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3590 event
.SetEventObject(this);
3592 // wxFindWinFromHandle() may return NULL, it is ok
3593 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3595 return GetEventHandler()->ProcessEvent(event
);
3598 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
3604 m_caret
->OnKillFocus();
3606 #endif // wxUSE_CARET
3609 // If it's a wxTextCtrl don't send the event as it will be done
3610 // after the control gets to process it.
3611 wxTextCtrl
*ctrl
= wxDynamicCastThis(wxTextCtrl
);
3618 // Don't send the event when in the process of being deleted. This can
3619 // only cause problems if the event handler tries to access the object.
3620 if ( m_isBeingDeleted
)
3625 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3626 event
.SetEventObject(this);
3628 // wxFindWinFromHandle() may return NULL, it is ok
3629 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3631 return GetEventHandler()->ProcessEvent(event
);
3634 // ---------------------------------------------------------------------------
3636 // ---------------------------------------------------------------------------
3638 void wxWindowMSW::SetLabel( const wxString
& label
)
3640 SetWindowText(GetHwnd(), label
.c_str());
3643 wxString
wxWindowMSW::GetLabel() const
3645 return wxGetWindowText(GetHWND());
3648 // ---------------------------------------------------------------------------
3650 // ---------------------------------------------------------------------------
3652 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
3654 wxShowEvent
event(GetId(), show
);
3655 event
.SetEventObject(this);
3657 return GetEventHandler()->ProcessEvent(event
);
3660 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
3662 wxInitDialogEvent
event(GetId());
3663 event
.SetEventObject(this);
3665 return GetEventHandler()->ProcessEvent(event
);
3668 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
3670 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
3671 wxUnusedVar(wParam
);
3673 #else // __WXMICROWIN__
3674 HDROP hFilesInfo
= (HDROP
) wParam
;
3676 // Get the total number of files dropped
3677 UINT gwFilesDropped
= ::DragQueryFile
3685 wxString
*files
= new wxString
[gwFilesDropped
];
3686 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
3688 // first get the needed buffer length (+1 for terminating NUL)
3689 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
3691 // and now get the file name
3692 ::DragQueryFile(hFilesInfo
, wIndex
,
3693 wxStringBuffer(files
[wIndex
], len
), len
);
3695 DragFinish (hFilesInfo
);
3697 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
3698 event
.SetEventObject(this);
3701 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
3702 event
.m_pos
.x
= dropPoint
.x
;
3703 event
.m_pos
.y
= dropPoint
.y
;
3705 return GetEventHandler()->ProcessEvent(event
);
3710 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
3712 int WXUNUSED(mouseMsg
))
3714 #ifndef __WXMICROWIN__
3715 // the logic is as follows:
3716 // -1. don't set cursor for non client area, including but not limited to
3717 // the title bar, scrollbars, &c
3718 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
3719 // 1. if we have the cursor set it unless wxIsBusy()
3720 // 2. if we're a top level window, set some cursor anyhow
3721 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
3723 if ( nHitTest
!= HTCLIENT
)
3728 HCURSOR hcursor
= 0;
3730 // first ask the user code - it may wish to set the cursor in some very
3731 // specific way (for example, depending on the current position)
3734 if ( !::GetCursorPosWinCE(&pt
))
3736 if ( !::GetCursorPos(&pt
) )
3739 wxLogLastError(wxT("GetCursorPos"));
3744 ScreenToClient(&x
, &y
);
3745 wxSetCursorEvent
event(x
, y
);
3747 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
3748 if ( processedEvtSetCursor
&& event
.HasCursor() )
3750 hcursor
= GetHcursorOf(event
.GetCursor());
3755 bool isBusy
= wxIsBusy();
3757 // the test for processedEvtSetCursor is here to prevent using m_cursor
3758 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3759 // it - this is a way to say that our cursor shouldn't be used for this
3761 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
3763 hcursor
= GetHcursorOf(m_cursor
);
3770 hcursor
= wxGetCurrentBusyCursor();
3772 else if ( !hcursor
)
3774 const wxCursor
*cursor
= wxGetGlobalCursor();
3775 if ( cursor
&& cursor
->Ok() )
3777 hcursor
= GetHcursorOf(*cursor
);
3785 // wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3787 ::SetCursor(hcursor
);
3789 // cursor set, stop here
3792 #endif // __WXMICROWIN__
3794 // pass up the window chain
3798 bool wxWindowMSW::HandlePower(WXWPARAM wParam
,
3799 WXLPARAM
WXUNUSED(lParam
),
3802 wxEventType evtType
;
3805 case PBT_APMQUERYSUSPEND
:
3806 evtType
= wxEVT_POWER_SUSPENDING
;
3809 case PBT_APMQUERYSUSPENDFAILED
:
3810 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
3813 case PBT_APMSUSPEND
:
3814 evtType
= wxEVT_POWER_SUSPENDED
;
3817 case PBT_APMRESUMESUSPEND
:
3818 evtType
= wxEVT_POWER_RESUME
;
3822 wxLogDebug(_T("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
3825 // these messages are currently not mapped to wx events
3826 case PBT_APMQUERYSTANDBY
:
3827 case PBT_APMQUERYSTANDBYFAILED
:
3828 case PBT_APMSTANDBY
:
3829 case PBT_APMRESUMESTANDBY
:
3830 case PBT_APMBATTERYLOW
:
3831 case PBT_APMPOWERSTATUSCHANGE
:
3832 case PBT_APMOEMEVENT
:
3833 #ifdef PBT_APMRESUMEAUTOMATIC
3834 case PBT_APMRESUMEAUTOMATIC
:
3836 case PBT_APMRESUMECRITICAL
:
3837 evtType
= wxEVT_NULL
;
3841 // don't handle unknown messages
3842 if ( evtType
== wxEVT_NULL
)
3845 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
3847 wxPowerEvent
event(evtType
);
3848 if ( !GetEventHandler()->ProcessEvent(event
) )
3851 *vetoed
= event
.IsVetoed();
3856 // ---------------------------------------------------------------------------
3857 // owner drawn stuff
3858 // ---------------------------------------------------------------------------
3860 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
3861 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
3862 #define WXUNUSED_UNLESS_ODRAWN(param) param
3864 #define WXUNUSED_UNLESS_ODRAWN(param)
3868 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
3869 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
3871 #if wxUSE_OWNER_DRAWN
3873 #if wxUSE_MENUS_NATIVE
3874 // is it a menu item?
3875 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
3876 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
3878 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
3880 // see comment before the same test in MSWOnMeasureItem() below
3884 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
3885 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
3887 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
3888 // the DC from being released
3889 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
3890 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
3891 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
3892 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
3894 return pMenuItem
->OnDrawItem
3898 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
3899 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
3902 #endif // wxUSE_MENUS_NATIVE
3904 #endif // USE_OWNER_DRAWN
3906 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
3908 #if wxUSE_OWNER_DRAWN
3909 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3910 #else // !wxUSE_OWNER_DRAWN
3911 // we may still have owner-drawn buttons internally because we have to make
3912 // them owner-drawn to support colour change
3915 wxDynamicCast(FindItem(id
), wxButton
)
3920 #endif // USE_OWNER_DRAWN
3924 return item
->MSWOnDraw(itemStruct
);
3927 #endif // wxUSE_CONTROLS
3933 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
3935 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
3936 // is it a menu item?
3937 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
3938 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
3940 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
3942 // according to Carsten Fuchs the pointer may be NULL under XP if an
3943 // MDI child frame is initially maximized, see this for more info:
3944 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
3946 // so silently ignore it instead of asserting
3950 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
3951 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
3954 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
3956 pMeasureStruct
->itemWidth
= w
;
3957 pMeasureStruct
->itemHeight
= h
;
3962 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3965 return item
->MSWOnMeasure(itemStruct
);
3969 wxUnusedVar(itemStruct
);
3970 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
3975 // ---------------------------------------------------------------------------
3976 // colours and palettes
3977 // ---------------------------------------------------------------------------
3979 bool wxWindowMSW::HandleSysColorChange()
3981 wxSysColourChangedEvent event
;
3982 event
.SetEventObject(this);
3984 (void)GetEventHandler()->ProcessEvent(event
);
3986 // always let the system carry on the default processing to allow the
3987 // native controls to react to the colours update
3991 bool wxWindowMSW::HandleDisplayChange()
3993 wxDisplayChangedEvent event
;
3994 event
.SetEventObject(this);
3996 return GetEventHandler()->ProcessEvent(event
);
3999 #ifndef __WXMICROWIN__
4001 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4003 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4007 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4010 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4012 #endif // wxUSE_CONTROLS
4015 return *brush
!= NULL
;
4018 #endif // __WXMICROWIN__
4020 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4023 // same as below except we don't respond to our own messages
4024 if ( hWndPalChange
!= GetHWND() )
4026 // check to see if we our our parents have a custom palette
4027 wxWindowMSW
*win
= this;
4028 while ( win
&& !win
->HasCustomPalette() )
4030 win
= win
->GetParent();
4033 if ( win
&& win
->HasCustomPalette() )
4035 // realize the palette to see whether redrawing is needed
4036 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4037 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4038 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4040 int result
= ::RealizePalette(hdc
);
4042 // restore the palette (before releasing the DC)
4043 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4044 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4045 ::RealizePalette(hdc
);
4046 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4048 // now check for the need to redraw
4050 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4054 #endif // wxUSE_PALETTE
4056 wxPaletteChangedEvent
event(GetId());
4057 event
.SetEventObject(this);
4058 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4060 return GetEventHandler()->ProcessEvent(event
);
4063 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4065 wxMouseCaptureChangedEvent
event(GetId(), wxFindWinFromHandle(hWndGainedCapture
));
4066 event
.SetEventObject(this);
4068 return GetEventHandler()->ProcessEvent(event
);
4071 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4073 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4074 // we need to send this to child windows (it is only sent to top-level
4075 // windows) so {list,tree}ctrls can adjust their font size if necessary
4076 // this is exactly how explorer does it to enable the font size changes
4078 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4081 // top-level windows already get this message from the system
4082 wxWindow
*win
= node
->GetData();
4083 if ( !win
->IsTopLevel() )
4085 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4088 node
= node
->GetNext();
4091 // let the system handle it
4095 bool wxWindowMSW::HandleQueryNewPalette()
4099 // check to see if we our our parents have a custom palette
4100 wxWindowMSW
*win
= this;
4101 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4102 if (win
->HasCustomPalette()) {
4103 /* realize the palette to see whether redrawing is needed */
4104 HDC hdc
= ::GetDC((HWND
) GetHWND());
4105 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4106 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4108 int result
= ::RealizePalette(hdc
);
4109 /* restore the palette (before releasing the DC) */
4110 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4111 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4112 ::RealizePalette(hdc
);
4113 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4114 /* now check for the need to redraw */
4116 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4118 #endif // wxUSE_PALETTE
4120 wxQueryNewPaletteEvent
event(GetId());
4121 event
.SetEventObject(this);
4123 return GetEventHandler()->ProcessEvent(event
) && event
.GetPaletteRealized();
4126 // Responds to colour changes: passes event on to children.
4127 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4129 // the top level window also reset the standard colour map as it might have
4130 // changed (there is no need to do it for the non top level windows as we
4131 // only have to do it once)
4135 gs_hasStdCmap
= false;
4137 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4140 // Only propagate to non-top-level windows because Windows already
4141 // sends this event to all top-level ones
4142 wxWindow
*win
= node
->GetData();
4143 if ( !win
->IsTopLevel() )
4145 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4146 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4147 // the standard controls
4148 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4151 node
= node
->GetNext();
4155 extern wxCOLORMAP
*wxGetStdColourMap()
4157 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4158 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4160 if ( !gs_hasStdCmap
)
4162 static bool s_coloursInit
= false;
4164 if ( !s_coloursInit
)
4166 // When a bitmap is loaded, the RGB values can change (apparently
4167 // because Windows adjusts them to care for the old programs always
4168 // using 0xc0c0c0 while the transparent colour for the new Windows
4169 // versions is different). But we do this adjustment ourselves so
4170 // we want to avoid Windows' "help" and for this we need to have a
4171 // reference bitmap which can tell us what the RGB values change
4173 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4174 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
4175 if ( stdColourBitmap
.Ok() )
4177 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4178 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4179 _T("forgot to update wxBITMAP_STD_COLOURS!") );
4182 memDC
.SelectObject(stdColourBitmap
);
4185 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4187 memDC
.GetPixel(i
, 0, &colour
);
4188 s_stdColours
[i
] = wxColourToRGB(colour
);
4191 else // wxBITMAP_STD_COLOURS couldn't be loaded
4193 s_stdColours
[0] = RGB(000,000,000); // black
4194 s_stdColours
[1] = RGB(128,128,128); // dark grey
4195 s_stdColours
[2] = RGB(192,192,192); // light grey
4196 s_stdColours
[3] = RGB(255,255,255); // white
4197 //s_stdColours[4] = RGB(000,000,255); // blue
4198 //s_stdColours[5] = RGB(255,000,255); // magenta
4201 s_coloursInit
= true;
4204 gs_hasStdCmap
= true;
4206 // create the colour map
4207 #define INIT_CMAP_ENTRY(col) \
4208 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4209 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4211 INIT_CMAP_ENTRY(BTNTEXT
);
4212 INIT_CMAP_ENTRY(BTNSHADOW
);
4213 INIT_CMAP_ENTRY(BTNFACE
);
4214 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4216 #undef INIT_CMAP_ENTRY
4222 // ---------------------------------------------------------------------------
4224 // ---------------------------------------------------------------------------
4226 bool wxWindowMSW::HandlePaint()
4228 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4230 wxLogLastError(wxT("CreateRectRgn"));
4231 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4232 wxLogLastError(wxT("GetUpdateRgn"));
4234 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4236 wxPaintEvent
event(m_windowId
);
4237 event
.SetEventObject(this);
4239 bool processed
= GetEventHandler()->ProcessEvent(event
);
4241 // note that we must generate NC event after the normal one as otherwise
4242 // BeginPaint() will happily overwrite our decorations with the background
4244 wxNcPaintEvent
eventNc(m_windowId
);
4245 eventNc
.SetEventObject(this);
4246 GetEventHandler()->ProcessEvent(eventNc
);
4251 // Can be called from an application's OnPaint handler
4252 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4254 #ifdef __WXUNIVERSAL__
4257 HDC hDC
= (HDC
) wxPaintDC::FindDCInCache((wxWindow
*) event
.GetEventObject());
4260 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4265 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4270 dc
.SetWindow((wxWindow
*)this);
4272 wxEraseEvent
event(m_windowId
, &dc
);
4273 event
.SetEventObject(this);
4274 bool rc
= GetEventHandler()->ProcessEvent(event
);
4276 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
4277 dc
.SelectOldObjects(hdc
);
4282 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
4284 // standard non top level controls (i.e. except the dialogs) always erase
4285 // their background themselves in HandleCtlColor() or have some control-
4286 // specific ways to set the colours (common controls)
4287 if ( IsOfStandardClass() && !IsTopLevel() )
4293 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
4295 // don't skip the event here, custom background means that the app
4296 // is drawing it itself in its OnPaint(), so don't draw it at all
4297 // now to avoid flicker
4302 // do default background painting
4303 if ( !DoEraseBackground(GetHdcOf(*event
.GetDC())) )
4305 // let the system paint the background
4310 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4312 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4316 wxFillRect(GetHwnd(), (HDC
)hDC
, hbr
);
4322 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
), WXHWND hWnd
)
4326 // our background colour applies to:
4327 // 1. this window itself, always
4328 // 2. all children unless the colour is "not inheritable"
4329 // 3. even if it is not inheritable, our immediate transparent
4330 // children should still inherit it -- but not any transparent
4331 // children because it would look wrong if a child of non
4332 // transparent child would show our bg colour when the child itself
4334 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
4337 (win
&& win
->HasTransparentBackground() &&
4338 win
->GetParent() == this) )
4340 // draw children with the same colour as the parent
4342 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4344 return (WXHBRUSH
)GetHbrushOf(*brush
);
4351 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
, WXHWND hWndToPaint
)
4354 hWndToPaint
= GetHWND();
4356 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4358 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, hWndToPaint
);
4362 // background is not inherited beyond top level windows
4363 if ( win
->IsTopLevel() )
4370 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4372 // we receive this message when DrawThemeParentBackground() is
4373 // called from def window proc of several controls under XP and we
4374 // must draw properly themed background here
4376 // note that naively I'd expect filling the client rect with the
4377 // brush returned by MSWGetBgBrush() work -- but for some reason it
4378 // doesn't and we have to call parents MSWPrintChild() which is
4379 // supposed to call DrawThemeBackground() with appropriate params
4381 // also note that in this case lParam == PRF_CLIENT but we're
4382 // clearly expected to paint the background and nothing else!
4384 if ( IsTopLevel() || InheritsBackgroundColour() )
4387 // sometimes we don't want the parent to handle it at all, instead
4388 // return whatever value this window wants
4389 if ( !MSWShouldPropagatePrintChild() )
4390 return MSWPrintChild(hDC
, (wxWindow
*)this);
4392 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4394 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4397 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4404 // ---------------------------------------------------------------------------
4405 // moving and resizing
4406 // ---------------------------------------------------------------------------
4408 bool wxWindowMSW::HandleMinimize()
4410 wxIconizeEvent
event(m_windowId
);
4411 event
.SetEventObject(this);
4413 return GetEventHandler()->ProcessEvent(event
);
4416 bool wxWindowMSW::HandleMaximize()
4418 wxMaximizeEvent
event(m_windowId
);
4419 event
.SetEventObject(this);
4421 return GetEventHandler()->ProcessEvent(event
);
4424 bool wxWindowMSW::HandleMove(int x
, int y
)
4427 wxMoveEvent
event(point
, m_windowId
);
4428 event
.SetEventObject(this);
4430 return GetEventHandler()->ProcessEvent(event
);
4433 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
4435 wxMoveEvent
event(rect
, m_windowId
);
4436 event
.SetEventObject(this);
4438 bool rc
= GetEventHandler()->ProcessEvent(event
);
4440 rect
= event
.GetRect();
4444 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
4446 #if USE_DEFERRED_SIZING
4447 // when we resize this window, its children are probably going to be
4448 // repositioned as well, prepare to use DeferWindowPos() for them
4449 int numChildren
= 0;
4450 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
4452 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
4457 // Protect against valid m_hDWP being overwritten
4458 bool useDefer
= false;
4460 if ( numChildren
> 1 )
4464 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
4467 wxLogLastError(_T("BeginDeferWindowPos"));
4473 #endif // USE_DEFERRED_SIZING
4475 // update this window size
4476 bool processed
= false;
4480 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4481 // fall through nevertheless
4485 // we're not interested in these messages at all
4488 case SIZE_MINIMIZED
:
4489 processed
= HandleMinimize();
4492 case SIZE_MAXIMIZED
:
4493 /* processed = */ HandleMaximize();
4494 // fall through to send a normal size event as well
4497 // don't use w and h parameters as they specify the client size
4498 // while according to the docs EVT_SIZE handler is supposed to
4499 // receive the total size
4500 wxSizeEvent
event(GetSize(), m_windowId
);
4501 event
.SetEventObject(this);
4503 processed
= GetEventHandler()->ProcessEvent(event
);
4506 #if USE_DEFERRED_SIZING
4507 // and finally change the positions of all child windows at once
4508 if ( useDefer
&& m_hDWP
)
4510 // reset m_hDWP to NULL so that child windows don't try to use our
4511 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4512 // happen anyhow normally but who knows what weird flow of control we
4513 // may have depending on what the users EVT_SIZE handler does...)
4514 HDWP hDWP
= (HDWP
)m_hDWP
;
4517 // do put all child controls in place at once
4518 if ( !::EndDeferWindowPos(hDWP
) )
4520 wxLogLastError(_T("EndDeferWindowPos"));
4523 // Reset our children's pending pos/size values.
4524 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4526 node
= node
->GetNext() )
4528 wxWindowMSW
*child
= node
->GetData();
4529 child
->m_pendingPosition
= wxDefaultPosition
;
4530 child
->m_pendingSize
= wxDefaultSize
;
4533 #endif // USE_DEFERRED_SIZING
4538 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
4540 wxSizeEvent
event(rect
, m_windowId
);
4541 event
.SetEventObject(this);
4543 bool rc
= GetEventHandler()->ProcessEvent(event
);
4545 rect
= event
.GetRect();
4549 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
4554 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
4558 int minWidth
= GetMinWidth(),
4559 minHeight
= GetMinHeight(),
4560 maxWidth
= GetMaxWidth(),
4561 maxHeight
= GetMaxHeight();
4563 if ( minWidth
!= wxDefaultCoord
)
4565 info
->ptMinTrackSize
.x
= minWidth
;
4569 if ( minHeight
!= wxDefaultCoord
)
4571 info
->ptMinTrackSize
.y
= minHeight
;
4575 if ( maxWidth
!= wxDefaultCoord
)
4577 info
->ptMaxTrackSize
.x
= maxWidth
;
4581 if ( maxHeight
!= wxDefaultCoord
)
4583 info
->ptMaxTrackSize
.y
= maxHeight
;
4591 // ---------------------------------------------------------------------------
4593 // ---------------------------------------------------------------------------
4595 bool wxWindowMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
4597 #if wxUSE_MENUS_NATIVE
4598 if ( !cmd
&& wxCurrentPopupMenu
)
4600 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
4601 wxCurrentPopupMenu
= NULL
;
4603 return popupMenu
->MSWCommand(cmd
, id
);
4605 #endif // wxUSE_MENUS_NATIVE
4607 wxWindow
*win
= NULL
;
4609 // first try to find it from HWND - this works even with the broken
4610 // programs using the same ids for different controls
4613 win
= wxFindWinFromHandle(control
);
4619 // must cast to a signed type before comparing with other ids!
4620 win
= FindItem((signed short)id
);
4625 return win
->MSWCommand(cmd
, id
);
4628 // the messages sent from the in-place edit control used by the treectrl
4629 // for label editing have id == 0, but they should _not_ be treated as menu
4630 // messages (they are EN_XXX ones, in fact) so don't translate anything
4631 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4634 // If no child window, it may be an accelerator, e.g. for a popup menu
4637 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
4638 event
.SetEventObject(this);
4642 return GetEventHandler()->ProcessEvent(event
);
4646 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4647 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4648 // notifications to its parent which we want to reflect back to
4650 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
4651 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
4653 #endif // wxUSE_SPINCTRL
4655 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
4656 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
4657 // notifications to its parent which we want to reflect back to
4659 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
4660 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
4668 // ---------------------------------------------------------------------------
4670 // ---------------------------------------------------------------------------
4672 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
4676 // our client coords are not quite the same as Windows ones
4677 wxPoint pt
= GetClientAreaOrigin();
4678 event
.m_x
= x
- pt
.x
;
4679 event
.m_y
= y
- pt
.y
;
4681 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
4682 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
4683 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
4684 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
4685 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
4686 event
.m_altDown
= ::GetKeyState(VK_MENU
) < 0;
4689 event
.SetTimestamp(::GetMessageTime());
4692 event
.SetEventObject(this);
4693 event
.SetId(GetId());
4695 #if wxUSE_MOUSEEVENT_HACK
4696 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
4697 gs_lastMouseEvent
.type
= event
.GetEventType();
4698 #endif // wxUSE_MOUSEEVENT_HACK
4702 // Windows doesn't send the mouse events to the static controls (which are
4703 // transparent in the sense that their WM_NCHITTEST handler returns
4704 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4705 // and so we manually check if we don't have a child window under mouse and if
4706 // we do, send the event to it instead of the window Windows had sent WM_XXX
4709 // Notice that this is not done for the mouse move events because this could
4710 // (would?) be too slow, but only for clicks which means that the static texts
4711 // still don't get move, enter nor leave events.
4712 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
4714 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
4716 // first try to find a non transparent child: this allows us to send events
4717 // to a static text which is inside a static box, for example
4718 POINT pt
= { *x
, *y
};
4719 HWND hwnd
= GetHwndOf(win
),
4723 hwndUnderMouse
= ::ChildWindowFromPoint
4729 hwndUnderMouse
= ::ChildWindowFromPointEx
4739 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
4741 // now try any child window at all
4742 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
4745 // check that we have a child window which is susceptible to receive mouse
4746 // events: for this it must be shown and enabled
4747 if ( hwndUnderMouse
&&
4748 hwndUnderMouse
!= hwnd
&&
4749 ::IsWindowVisible(hwndUnderMouse
) &&
4750 ::IsWindowEnabled(hwndUnderMouse
) )
4752 wxWindow
*winUnderMouse
= wxFindWinFromHandle((WXHWND
)hwndUnderMouse
);
4753 if ( winUnderMouse
)
4755 // translate the mouse coords to the other window coords
4756 win
->ClientToScreen(x
, y
);
4757 winUnderMouse
->ScreenToClient(x
, y
);
4759 win
= winUnderMouse
;
4765 #endif // __WXWINCE__
4767 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4769 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4770 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
4771 // from the message id and take the value in the table to get wxWin event
4773 static const wxEventType eventsMouse
[] =
4787 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
4788 InitMouseEvent(event
, x
, y
, flags
);
4790 return GetEventHandler()->ProcessEvent(event
);
4793 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
4795 if ( !m_mouseInWindow
)
4797 // it would be wrong to assume that just because we get a mouse move
4798 // event that the mouse is inside the window: although this is usually
4799 // true, it is not if we had captured the mouse, so we need to check
4800 // the mouse coordinates here
4801 if ( !HasCapture() || IsMouseInWindow() )
4803 // Generate an ENTER event
4804 m_mouseInWindow
= true;
4806 #ifdef HAVE_TRACKMOUSEEVENT
4807 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
4809 trackinfo
.dwFlags
= TME_LEAVE
;
4810 trackinfo
.hwndTrack
= GetHwnd();
4812 // Use the commctrl.h _TrackMouseEvent(), which will call the real
4813 // TrackMouseEvent() if available or emulate it
4814 _TrackMouseEvent(&trackinfo
);
4815 #endif // HAVE_TRACKMOUSEEVENT
4817 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
4818 InitMouseEvent(event
, x
, y
, flags
);
4820 (void)GetEventHandler()->ProcessEvent(event
);
4823 #ifdef HAVE_TRACKMOUSEEVENT
4826 // Check if we need to send a LEAVE event
4827 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
4828 // send it here if we are using native mouse leave tracking
4829 if ( HasCapture() && !IsMouseInWindow() )
4831 GenerateMouseLeave();
4834 #endif // HAVE_TRACKMOUSEEVENT
4836 #if wxUSE_MOUSEEVENT_HACK
4837 // Windows often generates mouse events even if mouse position hasn't
4838 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
4840 // Filter this out as it can result in unexpected behaviour compared to
4842 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
4843 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
4844 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
4845 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
4847 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
4849 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
4854 #endif // wxUSE_MOUSEEVENT_HACK
4856 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
4860 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
4862 #if wxUSE_MOUSEWHEEL
4863 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
4864 // forwarded up to the parent by DefWindowProc()) and not in the client
4865 // ones as all the other messages, translate them to the client coords for
4868 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
4869 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
4870 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
4871 event
.m_wheelRotation
= (short)HIWORD(wParam
);
4872 event
.m_wheelDelta
= WHEEL_DELTA
;
4874 static int s_linesPerRotation
= -1;
4875 if ( s_linesPerRotation
== -1 )
4877 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
4878 &s_linesPerRotation
, 0))
4880 // this is not supposed to happen
4881 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
4883 // the default is 3, so use it if SystemParametersInfo() failed
4884 s_linesPerRotation
= 3;
4888 event
.m_linesPerAction
= s_linesPerRotation
;
4889 return GetEventHandler()->ProcessEvent(event
);
4891 #else // !wxUSE_MOUSEWHEEL
4892 wxUnusedVar(wParam
);
4893 wxUnusedVar(lParam
);
4896 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
4899 void wxWindowMSW::GenerateMouseLeave()
4901 m_mouseInWindow
= false;
4904 if ( wxIsShiftDown() )
4906 if ( wxIsCtrlDown() )
4907 state
|= MK_CONTROL
;
4909 // Only the high-order bit should be tested
4910 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
4911 state
|= MK_LBUTTON
;
4912 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
4913 state
|= MK_MBUTTON
;
4914 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
4915 state
|= MK_RBUTTON
;
4919 if ( !::GetCursorPosWinCE(&pt
) )
4921 if ( !::GetCursorPos(&pt
) )
4924 wxLogLastError(_T("GetCursorPos"));
4927 // we need to have client coordinates here for symmetry with
4928 // wxEVT_ENTER_WINDOW
4929 RECT rect
= wxGetWindowRect(GetHwnd());
4933 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
4934 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
4936 (void)GetEventHandler()->ProcessEvent(event
);
4939 // ---------------------------------------------------------------------------
4940 // keyboard handling
4941 // ---------------------------------------------------------------------------
4943 // create the key event of the given type for the given key - used by
4944 // HandleChar and HandleKeyDown/Up
4945 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
4948 WXWPARAM wParam
) const
4950 wxKeyEvent
event(evType
);
4951 event
.SetId(GetId());
4952 event
.m_shiftDown
= wxIsShiftDown();
4953 event
.m_controlDown
= wxIsCtrlDown();
4954 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
4956 event
.SetEventObject((wxWindow
*)this); // const_cast
4957 event
.m_keyCode
= id
;
4959 event
.m_uniChar
= (wxChar
) wParam
;
4961 event
.m_rawCode
= (wxUint32
) wParam
;
4962 event
.m_rawFlags
= (wxUint32
) lParam
;
4964 event
.SetTimestamp(::GetMessageTime());
4967 // translate the position to client coords
4970 GetCursorPosWinCE(&pt
);
4975 GetWindowRect(GetHwnd(),&rect
);
4985 // isASCII is true only when we're called from WM_CHAR handler and not from
4987 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
4994 else // we're called from WM_KEYDOWN
4996 // don't pass lParam to wxCharCodeMSWToWX() here because we don't want
4997 // to get numpad key codes: CHAR events should use the logical keys
4998 // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events
4999 id
= wxCharCodeMSWToWX(wParam
);
5002 // it's ASCII and will be processed here only when called from
5003 // WM_CHAR (i.e. when isASCII = true), don't process it now
5008 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
5010 // the alphanumeric keys produced by pressing AltGr+something on European
5011 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5012 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5013 // alphanumeric, so pretend that there are no modifiers at all (the
5014 // KEY_DOWN event would still have the correct modifiers if they're really
5016 if ( event
.m_controlDown
&& event
.m_altDown
&&
5017 (id
>= 32 && id
< 256) )
5019 event
.m_controlDown
=
5020 event
.m_altDown
= false;
5023 return GetEventHandler()->ProcessEvent(event
);
5026 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5028 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5032 // normal ASCII char
5036 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
5037 return GetEventHandler()->ProcessEvent(event
);
5040 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5042 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5046 // normal ASCII char
5050 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
5051 return GetEventHandler()->ProcessEvent(event
);
5054 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5055 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5057 // FIXME: implement GetMenuItemCount for WinCE, possibly
5058 // in terms of GetMenuItemInfo
5060 const HMENU hmenu
= (HMENU
)lParam
;
5064 mii
.cbSize
= sizeof(MENUITEMINFO
);
5066 // we could use MIIM_FTYPE here as we only need to know if the item is
5067 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5068 // MIIM_FTYPE is not supported under Win95
5069 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5071 // find if we have this letter in any owner drawn item
5072 const int count
= ::GetMenuItemCount(hmenu
);
5073 for ( int i
= 0; i
< count
; i
++ )
5075 // previous loop iteration could modify it, reset it back before
5076 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5079 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5081 if ( mii
.fType
== MFT_OWNERDRAW
)
5083 // dwItemData member of the MENUITEMINFO is a
5084 // pointer to the associated wxMenuItem -- see the
5085 // menu creation code
5086 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5088 const wxChar
*p
= wxStrchr(item
->GetText(), _T('&'));
5091 if ( *p
== _T('&') )
5093 // this is not the accel char, find the real one
5094 p
= wxStrchr(p
+ 1, _T('&'));
5096 else // got the accel char
5098 // FIXME-UNICODE: this comparison doesn't risk to work
5099 // for non ASCII accelerator characters I'm afraid, but
5101 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5107 // this one doesn't match
5114 else // failed to get the menu text?
5116 // it's not fatal, so don't show error, but still log it
5117 wxLogLastError(_T("GetMenuItemInfo"));
5124 bool wxWindowMSW::HandleClipboardEvent( WXUINT nMsg
)
5126 const wxEventType type
= ( nMsg
== WM_CUT
) ? wxEVT_COMMAND_TEXT_CUT
:
5127 ( nMsg
== WM_COPY
) ? wxEVT_COMMAND_TEXT_COPY
:
5128 /*( nMsg == WM_PASTE ) ? */ wxEVT_COMMAND_TEXT_PASTE
;
5129 wxClipboardTextEvent
evt(type
, GetId());
5131 evt
.SetEventObject(this);
5133 return GetEventHandler()->ProcessEvent(evt
);
5136 // ---------------------------------------------------------------------------
5138 // ---------------------------------------------------------------------------
5140 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5144 if ( flags
& JOY_BUTTON1CHG
)
5145 change
= wxJOY_BUTTON1
;
5146 if ( flags
& JOY_BUTTON2CHG
)
5147 change
= wxJOY_BUTTON2
;
5148 if ( flags
& JOY_BUTTON3CHG
)
5149 change
= wxJOY_BUTTON3
;
5150 if ( flags
& JOY_BUTTON4CHG
)
5151 change
= wxJOY_BUTTON4
;
5154 if ( flags
& JOY_BUTTON1
)
5155 buttons
|= wxJOY_BUTTON1
;
5156 if ( flags
& JOY_BUTTON2
)
5157 buttons
|= wxJOY_BUTTON2
;
5158 if ( flags
& JOY_BUTTON3
)
5159 buttons
|= wxJOY_BUTTON3
;
5160 if ( flags
& JOY_BUTTON4
)
5161 buttons
|= wxJOY_BUTTON4
;
5163 // the event ids aren't consecutive so we can't use table based lookup
5165 wxEventType eventType
;
5170 eventType
= wxEVT_JOY_MOVE
;
5175 eventType
= wxEVT_JOY_MOVE
;
5180 eventType
= wxEVT_JOY_ZMOVE
;
5185 eventType
= wxEVT_JOY_ZMOVE
;
5188 case MM_JOY1BUTTONDOWN
:
5190 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5193 case MM_JOY2BUTTONDOWN
:
5195 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5198 case MM_JOY1BUTTONUP
:
5200 eventType
= wxEVT_JOY_BUTTON_UP
;
5203 case MM_JOY2BUTTONUP
:
5205 eventType
= wxEVT_JOY_BUTTON_UP
;
5209 wxFAIL_MSG(wxT("no such joystick event"));
5214 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5215 event
.SetPosition(wxPoint(x
, y
));
5216 event
.SetEventObject(this);
5218 return GetEventHandler()->ProcessEvent(event
);
5228 // ---------------------------------------------------------------------------
5230 // ---------------------------------------------------------------------------
5232 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5233 WXWORD pos
, WXHWND control
)
5235 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5237 wxWindow
*child
= wxFindWinFromHandle(control
);
5239 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5242 wxScrollWinEvent event
;
5243 event
.SetPosition(pos
);
5244 event
.SetOrientation(orientation
);
5245 event
.SetEventObject(this);
5250 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5254 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5258 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5262 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5266 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5270 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5273 case SB_THUMBPOSITION
:
5275 // under Win32, the scrollbar range and position are 32 bit integers,
5276 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5277 // explicitly query the scrollbar for the correct position (this must
5278 // be done only for these two SB_ events as they are the only one
5279 // carrying the scrollbar position)
5281 WinStruct
<SCROLLINFO
> scrollInfo
;
5282 scrollInfo
.fMask
= SIF_TRACKPOS
;
5284 if ( !::GetScrollInfo(GetHwnd(),
5285 orientation
== wxHORIZONTAL
? SB_HORZ
5289 // Not necessarily an error, if there are no scrollbars yet.
5290 // wxLogLastError(_T("GetScrollInfo"));
5293 event
.SetPosition(scrollInfo
.nTrackPos
);
5296 event
.SetEventType( wParam
== SB_THUMBPOSITION
5297 ? wxEVT_SCROLLWIN_THUMBRELEASE
5298 : wxEVT_SCROLLWIN_THUMBTRACK
);
5305 return GetEventHandler()->ProcessEvent(event
);
5308 // ===========================================================================
5310 // ===========================================================================
5312 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5315 HDC dc
= ::GetDC((HWND
) wnd
);
5318 // the_font.UseResource();
5319 // the_font.RealizeResource();
5320 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
5322 was
= (HFONT
) SelectObject(dc
,fnt
);
5324 GetTextMetrics(dc
, &tm
);
5327 SelectObject(dc
,was
);
5329 ReleaseDC((HWND
)wnd
, dc
);
5332 *x
= tm
.tmAveCharWidth
;
5334 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
5336 // the_font.ReleaseResource();
5339 // use the "extended" bit (24) of lParam to distinguish extended keys
5340 // from normal keys as the same key is sent
5342 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
5344 // except that if lParam is 0, it means we don't have real lParam from
5345 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
5346 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
5347 // non-numpad (hence extended) key as this is a more common case
5348 return !lParam
|| (lParam
& (1 << 24)) ? keyExtended
: keyNormal
;
5351 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
5352 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
5353 int wxCharCodeMSWToWX(int keySym
, WXLPARAM lParam
)
5358 case VK_CANCEL
: id
= WXK_CANCEL
; break;
5359 case VK_BACK
: id
= WXK_BACK
; break;
5360 case VK_TAB
: id
= WXK_TAB
; break;
5361 case VK_CLEAR
: id
= WXK_CLEAR
; break;
5362 case VK_SHIFT
: id
= WXK_SHIFT
; break;
5363 case VK_CONTROL
: id
= WXK_CONTROL
; break;
5364 case VK_MENU
: id
= WXK_ALT
; break;
5365 case VK_PAUSE
: id
= WXK_PAUSE
; break;
5366 case VK_CAPITAL
: id
= WXK_CAPITAL
; break;
5367 case VK_SPACE
: id
= WXK_SPACE
; break;
5368 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
5369 case VK_SELECT
: id
= WXK_SELECT
; break;
5370 case VK_PRINT
: id
= WXK_PRINT
; break;
5371 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
5372 case VK_HELP
: id
= WXK_HELP
; break;
5373 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
5374 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
5375 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
5376 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
5377 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
5378 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
5379 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
5380 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
5381 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
5382 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
5383 case VK_MULTIPLY
: id
= WXK_NUMPAD_MULTIPLY
; break;
5384 case VK_ADD
: id
= WXK_NUMPAD_ADD
; break;
5385 case VK_SUBTRACT
: id
= WXK_NUMPAD_SUBTRACT
; break;
5386 case VK_DECIMAL
: id
= WXK_NUMPAD_DECIMAL
; break;
5387 case VK_DIVIDE
: id
= WXK_NUMPAD_DIVIDE
; break;
5388 case VK_F1
: id
= WXK_F1
; break;
5389 case VK_F2
: id
= WXK_F2
; break;
5390 case VK_F3
: id
= WXK_F3
; break;
5391 case VK_F4
: id
= WXK_F4
; break;
5392 case VK_F5
: id
= WXK_F5
; break;
5393 case VK_F6
: id
= WXK_F6
; break;
5394 case VK_F7
: id
= WXK_F7
; break;
5395 case VK_F8
: id
= WXK_F8
; break;
5396 case VK_F9
: id
= WXK_F9
; break;
5397 case VK_F10
: id
= WXK_F10
; break;
5398 case VK_F11
: id
= WXK_F11
; break;
5399 case VK_F12
: id
= WXK_F12
; break;
5400 case VK_F13
: id
= WXK_F13
; break;
5401 case VK_F14
: id
= WXK_F14
; break;
5402 case VK_F15
: id
= WXK_F15
; break;
5403 case VK_F16
: id
= WXK_F16
; break;
5404 case VK_F17
: id
= WXK_F17
; break;
5405 case VK_F18
: id
= WXK_F18
; break;
5406 case VK_F19
: id
= WXK_F19
; break;
5407 case VK_F20
: id
= WXK_F20
; break;
5408 case VK_F21
: id
= WXK_F21
; break;
5409 case VK_F22
: id
= WXK_F22
; break;
5410 case VK_F23
: id
= WXK_F23
; break;
5411 case VK_F24
: id
= WXK_F24
; break;
5412 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
5413 case VK_SCROLL
: id
= WXK_SCROLL
; break;
5415 // the mapping for these keys may be incorrect on non-US keyboards so
5416 // maybe we shouldn't map them to ASCII values at all
5417 case VK_OEM_1
: id
= ';'; break;
5418 case VK_OEM_PLUS
: id
= '+'; break;
5419 case VK_OEM_COMMA
: id
= ','; break;
5420 case VK_OEM_MINUS
: id
= '-'; break;
5421 case VK_OEM_PERIOD
: id
= '.'; break;
5422 case VK_OEM_2
: id
= '/'; break;
5423 case VK_OEM_3
: id
= '~'; break;
5424 case VK_OEM_4
: id
= '['; break;
5425 case VK_OEM_5
: id
= '\\'; break;
5426 case VK_OEM_6
: id
= ']'; break;
5427 case VK_OEM_7
: id
= '\''; break;
5430 case VK_LWIN
: id
= WXK_WINDOWS_LEFT
; break;
5431 case VK_RWIN
: id
= WXK_WINDOWS_RIGHT
; break;
5432 case VK_APPS
: id
= WXK_WINDOWS_MENU
; break;
5433 #endif // VK_APPS defined
5435 // handle extended keys
5437 id
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
5440 id
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
5443 id
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
5446 id
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
5449 id
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
5452 id
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
5455 id
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
5458 id
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
5461 id
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
5464 id
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
5467 // don't use ChooseNormalOrExtended() here as the keys are reversed
5468 // here: numpad enter is the extended one
5469 id
= lParam
&& (lParam
& (1 << 24)) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
5479 WXWORD
wxCharCodeWXToMSW(int id
, bool *isVirtual
)
5485 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
5486 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
5487 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
5488 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
5489 case WXK_ALT
: keySym
= VK_MENU
; break;
5490 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
5491 case WXK_CAPITAL
: keySym
= VK_CAPITAL
; break;
5492 case WXK_PAGEUP
: keySym
= VK_PRIOR
; break;
5493 case WXK_PAGEDOWN
: keySym
= VK_NEXT
; break;
5494 case WXK_END
: keySym
= VK_END
; break;
5495 case WXK_HOME
: keySym
= VK_HOME
; break;
5496 case WXK_LEFT
: keySym
= VK_LEFT
; break;
5497 case WXK_UP
: keySym
= VK_UP
; break;
5498 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
5499 case WXK_DOWN
: keySym
= VK_DOWN
; break;
5500 case WXK_SELECT
: keySym
= VK_SELECT
; break;
5501 case WXK_PRINT
: keySym
= VK_PRINT
; break;
5502 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
5503 case WXK_INSERT
: keySym
= VK_INSERT
; break;
5504 case WXK_DELETE
: keySym
= VK_DELETE
; break;
5505 case WXK_HELP
: keySym
= VK_HELP
; break;
5506 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
5507 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
5508 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
5509 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
5510 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
5511 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
5512 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
5513 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
5514 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
5515 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
5516 case WXK_NUMPAD_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
5517 case WXK_NUMPAD_ADD
: keySym
= VK_ADD
; break;
5518 case WXK_NUMPAD_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
5519 case WXK_NUMPAD_DECIMAL
: keySym
= VK_DECIMAL
; break;
5520 case WXK_NUMPAD_DIVIDE
: keySym
= VK_DIVIDE
; break;
5521 case WXK_F1
: keySym
= VK_F1
; break;
5522 case WXK_F2
: keySym
= VK_F2
; break;
5523 case WXK_F3
: keySym
= VK_F3
; break;
5524 case WXK_F4
: keySym
= VK_F4
; break;
5525 case WXK_F5
: keySym
= VK_F5
; break;
5526 case WXK_F6
: keySym
= VK_F6
; break;
5527 case WXK_F7
: keySym
= VK_F7
; break;
5528 case WXK_F8
: keySym
= VK_F8
; break;
5529 case WXK_F9
: keySym
= VK_F9
; break;
5530 case WXK_F10
: keySym
= VK_F10
; break;
5531 case WXK_F11
: keySym
= VK_F11
; break;
5532 case WXK_F12
: keySym
= VK_F12
; break;
5533 case WXK_F13
: keySym
= VK_F13
; break;
5534 case WXK_F14
: keySym
= VK_F14
; break;
5535 case WXK_F15
: keySym
= VK_F15
; break;
5536 case WXK_F16
: keySym
= VK_F16
; break;
5537 case WXK_F17
: keySym
= VK_F17
; break;
5538 case WXK_F18
: keySym
= VK_F18
; break;
5539 case WXK_F19
: keySym
= VK_F19
; break;
5540 case WXK_F20
: keySym
= VK_F20
; break;
5541 case WXK_F21
: keySym
= VK_F21
; break;
5542 case WXK_F22
: keySym
= VK_F22
; break;
5543 case WXK_F23
: keySym
= VK_F23
; break;
5544 case WXK_F24
: keySym
= VK_F24
; break;
5545 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
5546 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
5557 bool wxGetKeyState(wxKeyCode key
)
5561 wxASSERT_MSG(key
!= WXK_LBUTTON
&& key
!= WXK_RBUTTON
&& key
!=
5562 WXK_MBUTTON
, wxT("can't use wxGetKeyState() for mouse buttons"));
5564 //High order with GetAsyncKeyState only available on WIN32
5566 //If the requested key is a LED key, return
5567 //true if the led is pressed
5568 if (key
== WXK_NUMLOCK
||
5569 key
== WXK_CAPITAL
||
5573 //low order bit means LED is highlighted,
5574 //high order means key is down
5575 //Here, for compat with other ports we want both
5576 return GetKeyState( wxCharCodeWXToMSW(key
, &bVirtual
) ) != 0;
5583 //low order bit means key pressed since last call
5584 //high order means key is down
5585 //We want only the high order bit - the key may not be down if only low order
5586 return ( GetAsyncKeyState( wxCharCodeWXToMSW(key
, &bVirtual
) ) & (1<<15) ) != 0;
5592 wxMouseState
wxGetMouseState()
5596 GetCursorPos( &pt
);
5600 ms
.SetLeftDown( (GetAsyncKeyState(VK_LBUTTON
) & (1<<15)) != 0 );
5601 ms
.SetMiddleDown( (GetAsyncKeyState(VK_MBUTTON
) & (1<<15)) != 0 );
5602 ms
.SetRightDown( (GetAsyncKeyState(VK_RBUTTON
) & (1<<15)) != 0 );
5604 ms
.SetControlDown( (GetAsyncKeyState(VK_CONTROL
) & (1<<15)) != 0 );
5605 ms
.SetShiftDown( (GetAsyncKeyState(VK_SHIFT
) & (1<<15)) != 0 );
5606 ms
.SetAltDown( (GetAsyncKeyState(VK_MENU
) & (1<<15)) != 0 );
5607 // ms.SetMetaDown();
5613 wxWindow
*wxGetActiveWindow()
5615 HWND hWnd
= GetActiveWindow();
5618 return wxFindWinFromHandle((WXHWND
) hWnd
);
5623 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
5625 HWND hwnd
= (HWND
)hWnd
;
5627 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
5628 // by code in msw/radiobox.cpp), for all the others we just search up the
5630 wxWindow
*win
= (wxWindow
*)NULL
;
5633 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5637 // native radiobuttons return DLGC_RADIOBUTTON here and for any
5638 // wxWindow class which overrides WM_GETDLGCODE processing to
5639 // do it as well, win would be already non NULL
5640 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
5642 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
5644 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
5645 #endif // wxUSE_RADIOBOX
5647 // spin control text buddy window should be mapped to spin ctrl
5648 // itself so try it too
5649 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5652 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
5654 #endif // wxUSE_SPINCTRL
5658 while ( hwnd
&& !win
)
5660 // this is a really ugly hack needed to avoid mistakenly returning the
5661 // parent frame wxWindow for the find/replace modeless dialog HWND -
5662 // this, in turn, is needed to call IsDialogMessage() from
5663 // wxApp::ProcessMessage() as for this we must return NULL from here
5665 // FIXME: this is clearly not the best way to do it but I think we'll
5666 // need to change HWND <-> wxWindow code more heavily than I can
5667 // do it now to fix it
5668 #ifndef __WXMICROWIN__
5669 if ( ::GetWindow(hwnd
, GW_OWNER
) )
5671 // it's a dialog box, don't go upwards
5676 hwnd
= ::GetParent(hwnd
);
5677 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5683 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
5685 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
5686 // in active frames and dialogs, regardless of where the focus is.
5687 static HHOOK wxTheKeyboardHook
= 0;
5688 static FARPROC wxTheKeyboardHookProc
= 0;
5689 int APIENTRY _EXPORT
5690 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
5692 void wxSetKeyboardHook(bool doIt
)
5696 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
5697 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
5699 GetCurrentThreadId()
5700 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
5705 UnhookWindowsHookEx(wxTheKeyboardHook
);
5709 int APIENTRY _EXPORT
5710 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
5712 DWORD hiWord
= HIWORD(lParam
);
5713 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
5715 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5718 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
5719 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
5720 event
.m_altDown
= true;
5722 event
.SetEventObject(NULL
);
5723 event
.m_keyCode
= id
;
5724 event
.m_shiftDown
= wxIsShiftDown();
5725 event
.m_controlDown
= wxIsCtrlDown();
5727 event
.SetTimestamp(::GetMessageTime());
5729 wxWindow
*win
= wxGetActiveWindow();
5730 wxEvtHandler
*handler
;
5733 handler
= win
->GetEventHandler();
5734 event
.SetId(win
->GetId());
5739 event
.SetId(wxID_ANY
);
5742 if ( handler
&& handler
->ProcessEvent(event
) )
5750 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
5753 #endif // !__WXMICROWIN__
5756 const wxChar
*wxGetMessageName(int message
)
5760 case 0x0000: return wxT("WM_NULL");
5761 case 0x0001: return wxT("WM_CREATE");
5762 case 0x0002: return wxT("WM_DESTROY");
5763 case 0x0003: return wxT("WM_MOVE");
5764 case 0x0005: return wxT("WM_SIZE");
5765 case 0x0006: return wxT("WM_ACTIVATE");
5766 case 0x0007: return wxT("WM_SETFOCUS");
5767 case 0x0008: return wxT("WM_KILLFOCUS");
5768 case 0x000A: return wxT("WM_ENABLE");
5769 case 0x000B: return wxT("WM_SETREDRAW");
5770 case 0x000C: return wxT("WM_SETTEXT");
5771 case 0x000D: return wxT("WM_GETTEXT");
5772 case 0x000E: return wxT("WM_GETTEXTLENGTH");
5773 case 0x000F: return wxT("WM_PAINT");
5774 case 0x0010: return wxT("WM_CLOSE");
5775 case 0x0011: return wxT("WM_QUERYENDSESSION");
5776 case 0x0012: return wxT("WM_QUIT");
5777 case 0x0013: return wxT("WM_QUERYOPEN");
5778 case 0x0014: return wxT("WM_ERASEBKGND");
5779 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
5780 case 0x0016: return wxT("WM_ENDSESSION");
5781 case 0x0017: return wxT("WM_SYSTEMERROR");
5782 case 0x0018: return wxT("WM_SHOWWINDOW");
5783 case 0x0019: return wxT("WM_CTLCOLOR");
5784 case 0x001A: return wxT("WM_WININICHANGE");
5785 case 0x001B: return wxT("WM_DEVMODECHANGE");
5786 case 0x001C: return wxT("WM_ACTIVATEAPP");
5787 case 0x001D: return wxT("WM_FONTCHANGE");
5788 case 0x001E: return wxT("WM_TIMECHANGE");
5789 case 0x001F: return wxT("WM_CANCELMODE");
5790 case 0x0020: return wxT("WM_SETCURSOR");
5791 case 0x0021: return wxT("WM_MOUSEACTIVATE");
5792 case 0x0022: return wxT("WM_CHILDACTIVATE");
5793 case 0x0023: return wxT("WM_QUEUESYNC");
5794 case 0x0024: return wxT("WM_GETMINMAXINFO");
5795 case 0x0026: return wxT("WM_PAINTICON");
5796 case 0x0027: return wxT("WM_ICONERASEBKGND");
5797 case 0x0028: return wxT("WM_NEXTDLGCTL");
5798 case 0x002A: return wxT("WM_SPOOLERSTATUS");
5799 case 0x002B: return wxT("WM_DRAWITEM");
5800 case 0x002C: return wxT("WM_MEASUREITEM");
5801 case 0x002D: return wxT("WM_DELETEITEM");
5802 case 0x002E: return wxT("WM_VKEYTOITEM");
5803 case 0x002F: return wxT("WM_CHARTOITEM");
5804 case 0x0030: return wxT("WM_SETFONT");
5805 case 0x0031: return wxT("WM_GETFONT");
5806 case 0x0037: return wxT("WM_QUERYDRAGICON");
5807 case 0x0039: return wxT("WM_COMPAREITEM");
5808 case 0x0041: return wxT("WM_COMPACTING");
5809 case 0x0044: return wxT("WM_COMMNOTIFY");
5810 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
5811 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
5812 case 0x0048: return wxT("WM_POWER");
5814 case 0x004A: return wxT("WM_COPYDATA");
5815 case 0x004B: return wxT("WM_CANCELJOURNAL");
5816 case 0x004E: return wxT("WM_NOTIFY");
5817 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
5818 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
5819 case 0x0052: return wxT("WM_TCARD");
5820 case 0x0053: return wxT("WM_HELP");
5821 case 0x0054: return wxT("WM_USERCHANGED");
5822 case 0x0055: return wxT("WM_NOTIFYFORMAT");
5823 case 0x007B: return wxT("WM_CONTEXTMENU");
5824 case 0x007C: return wxT("WM_STYLECHANGING");
5825 case 0x007D: return wxT("WM_STYLECHANGED");
5826 case 0x007E: return wxT("WM_DISPLAYCHANGE");
5827 case 0x007F: return wxT("WM_GETICON");
5828 case 0x0080: return wxT("WM_SETICON");
5830 case 0x0081: return wxT("WM_NCCREATE");
5831 case 0x0082: return wxT("WM_NCDESTROY");
5832 case 0x0083: return wxT("WM_NCCALCSIZE");
5833 case 0x0084: return wxT("WM_NCHITTEST");
5834 case 0x0085: return wxT("WM_NCPAINT");
5835 case 0x0086: return wxT("WM_NCACTIVATE");
5836 case 0x0087: return wxT("WM_GETDLGCODE");
5837 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
5838 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
5839 case 0x00A2: return wxT("WM_NCLBUTTONUP");
5840 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
5841 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
5842 case 0x00A5: return wxT("WM_NCRBUTTONUP");
5843 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
5844 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
5845 case 0x00A8: return wxT("WM_NCMBUTTONUP");
5846 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
5847 case 0x0100: return wxT("WM_KEYDOWN");
5848 case 0x0101: return wxT("WM_KEYUP");
5849 case 0x0102: return wxT("WM_CHAR");
5850 case 0x0103: return wxT("WM_DEADCHAR");
5851 case 0x0104: return wxT("WM_SYSKEYDOWN");
5852 case 0x0105: return wxT("WM_SYSKEYUP");
5853 case 0x0106: return wxT("WM_SYSCHAR");
5854 case 0x0107: return wxT("WM_SYSDEADCHAR");
5855 case 0x0108: return wxT("WM_KEYLAST");
5857 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
5858 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
5859 case 0x010F: return wxT("WM_IME_COMPOSITION");
5861 case 0x0110: return wxT("WM_INITDIALOG");
5862 case 0x0111: return wxT("WM_COMMAND");
5863 case 0x0112: return wxT("WM_SYSCOMMAND");
5864 case 0x0113: return wxT("WM_TIMER");
5865 case 0x0114: return wxT("WM_HSCROLL");
5866 case 0x0115: return wxT("WM_VSCROLL");
5867 case 0x0116: return wxT("WM_INITMENU");
5868 case 0x0117: return wxT("WM_INITMENUPOPUP");
5869 case 0x011F: return wxT("WM_MENUSELECT");
5870 case 0x0120: return wxT("WM_MENUCHAR");
5871 case 0x0121: return wxT("WM_ENTERIDLE");
5872 case 0x0200: return wxT("WM_MOUSEMOVE");
5873 case 0x0201: return wxT("WM_LBUTTONDOWN");
5874 case 0x0202: return wxT("WM_LBUTTONUP");
5875 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
5876 case 0x0204: return wxT("WM_RBUTTONDOWN");
5877 case 0x0205: return wxT("WM_RBUTTONUP");
5878 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
5879 case 0x0207: return wxT("WM_MBUTTONDOWN");
5880 case 0x0208: return wxT("WM_MBUTTONUP");
5881 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
5882 case 0x020A: return wxT("WM_MOUSEWHEEL");
5883 case 0x0210: return wxT("WM_PARENTNOTIFY");
5884 case 0x0211: return wxT("WM_ENTERMENULOOP");
5885 case 0x0212: return wxT("WM_EXITMENULOOP");
5887 case 0x0213: return wxT("WM_NEXTMENU");
5888 case 0x0214: return wxT("WM_SIZING");
5889 case 0x0215: return wxT("WM_CAPTURECHANGED");
5890 case 0x0216: return wxT("WM_MOVING");
5891 case 0x0218: return wxT("WM_POWERBROADCAST");
5892 case 0x0219: return wxT("WM_DEVICECHANGE");
5894 case 0x0220: return wxT("WM_MDICREATE");
5895 case 0x0221: return wxT("WM_MDIDESTROY");
5896 case 0x0222: return wxT("WM_MDIACTIVATE");
5897 case 0x0223: return wxT("WM_MDIRESTORE");
5898 case 0x0224: return wxT("WM_MDINEXT");
5899 case 0x0225: return wxT("WM_MDIMAXIMIZE");
5900 case 0x0226: return wxT("WM_MDITILE");
5901 case 0x0227: return wxT("WM_MDICASCADE");
5902 case 0x0228: return wxT("WM_MDIICONARRANGE");
5903 case 0x0229: return wxT("WM_MDIGETACTIVE");
5904 case 0x0230: return wxT("WM_MDISETMENU");
5905 case 0x0233: return wxT("WM_DROPFILES");
5907 case 0x0281: return wxT("WM_IME_SETCONTEXT");
5908 case 0x0282: return wxT("WM_IME_NOTIFY");
5909 case 0x0283: return wxT("WM_IME_CONTROL");
5910 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
5911 case 0x0285: return wxT("WM_IME_SELECT");
5912 case 0x0286: return wxT("WM_IME_CHAR");
5913 case 0x0290: return wxT("WM_IME_KEYDOWN");
5914 case 0x0291: return wxT("WM_IME_KEYUP");
5916 case 0x0300: return wxT("WM_CUT");
5917 case 0x0301: return wxT("WM_COPY");
5918 case 0x0302: return wxT("WM_PASTE");
5919 case 0x0303: return wxT("WM_CLEAR");
5920 case 0x0304: return wxT("WM_UNDO");
5921 case 0x0305: return wxT("WM_RENDERFORMAT");
5922 case 0x0306: return wxT("WM_RENDERALLFORMATS");
5923 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
5924 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
5925 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
5926 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
5927 case 0x030B: return wxT("WM_SIZECLIPBOARD");
5928 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
5929 case 0x030D: return wxT("WM_CHANGECBCHAIN");
5930 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
5931 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
5932 case 0x0310: return wxT("WM_PALETTEISCHANGING");
5933 case 0x0311: return wxT("WM_PALETTECHANGED");
5935 case 0x0312: return wxT("WM_HOTKEY");
5938 // common controls messages - although they're not strictly speaking
5939 // standard, it's nice to decode them nevertheless
5942 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
5943 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
5944 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
5945 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
5946 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
5947 case 0x1000 + 5: return wxT("LVM_GETITEMA");
5948 case 0x1000 + 75: return wxT("LVM_GETITEMW");
5949 case 0x1000 + 6: return wxT("LVM_SETITEMA");
5950 case 0x1000 + 76: return wxT("LVM_SETITEMW");
5951 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
5952 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
5953 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
5954 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
5955 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
5956 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
5957 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
5958 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
5959 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
5960 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
5961 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
5962 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
5963 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
5964 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
5965 case 0x1000 + 18: return wxT("LVM_HITTEST");
5966 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
5967 case 0x1000 + 20: return wxT("LVM_SCROLL");
5968 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
5969 case 0x1000 + 22: return wxT("LVM_ARRANGE");
5970 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
5971 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
5972 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
5973 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
5974 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
5975 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
5976 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
5977 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
5978 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
5979 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
5980 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
5981 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
5982 case 0x1000 + 31: return wxT("LVM_GETHEADER");
5983 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
5984 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
5985 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
5986 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
5987 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
5988 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
5989 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
5990 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
5991 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
5992 case 0x1000 + 42: return wxT("LVM_UPDATE");
5993 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
5994 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
5995 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
5996 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
5997 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
5998 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
5999 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6000 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6001 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6002 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6003 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6004 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6005 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6006 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6007 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6008 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6009 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6010 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6011 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6012 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6013 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6014 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6015 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6016 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6017 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6018 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6021 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6022 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6023 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6024 case 0x1100 + 2: return wxT("TVM_EXPAND");
6025 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6026 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6027 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6028 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6029 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6030 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6031 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6032 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6033 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6034 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6035 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6036 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6037 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6038 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6039 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6040 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6041 case 0x1100 + 17: return wxT("TVM_HITTEST");
6042 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6043 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6044 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6045 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6046 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6047 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6048 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6049 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6050 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6053 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6054 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6055 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6056 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6057 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6058 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6059 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6060 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6061 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6062 case 0x1200 + 6: return wxT("HDM_HITTEST");
6063 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6064 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6065 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6066 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6067 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6068 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6069 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6070 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6073 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6074 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6075 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6076 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6077 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6078 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6079 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6080 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6081 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6082 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6083 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6084 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6085 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6086 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6087 case 0x1300 + 13: return wxT("TCM_HITTEST");
6088 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6089 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6090 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6091 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6092 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6093 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6094 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6095 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6096 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6097 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6098 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6099 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6102 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6103 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
6104 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
6105 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
6106 case WM_USER
+5: return wxT("TB_INDETERMINATE");
6107 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
6108 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
6109 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
6110 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
6111 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
6112 case WM_USER
+17: return wxT("TB_SETSTATE");
6113 case WM_USER
+18: return wxT("TB_GETSTATE");
6114 case WM_USER
+19: return wxT("TB_ADDBITMAP");
6115 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
6116 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
6117 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
6118 case WM_USER
+23: return wxT("TB_GETBUTTON");
6119 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
6120 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
6121 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
6122 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
6123 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
6124 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
6125 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
6126 case WM_USER
+29: return wxT("TB_GETITEMRECT");
6127 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
6128 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
6129 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
6130 case WM_USER
+33: return wxT("TB_AUTOSIZE");
6131 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
6132 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
6133 case WM_USER
+37: return wxT("TB_SETPARENT");
6134 case WM_USER
+39: return wxT("TB_SETROWS");
6135 case WM_USER
+40: return wxT("TB_GETROWS");
6136 case WM_USER
+42: return wxT("TB_SETCMDID");
6137 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
6138 case WM_USER
+44: return wxT("TB_GETBITMAP");
6139 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
6140 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
6141 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
6142 case WM_USER
+47: return wxT("TB_SETINDENT");
6143 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
6144 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
6145 case WM_USER
+50: return wxT("TB_LOADIMAGES");
6146 case WM_USER
+51: return wxT("TB_GETRECT");
6147 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
6148 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
6149 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
6150 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
6151 case WM_USER
+56: return wxT("TB_SETSTYLE");
6152 case WM_USER
+57: return wxT("TB_GETSTYLE");
6153 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
6154 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
6155 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
6156 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
6157 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
6160 static wxString s_szBuf
;
6161 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
6162 return s_szBuf
.c_str();
6165 #endif //__WXDEBUG__
6167 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
6171 HWND hwnd
= GetHwndOf(win
);
6172 HDC hdc
= ::GetDC(hwnd
);
6174 #if !wxDIALOG_UNIT_COMPATIBILITY
6175 // and select the current font into it
6176 HFONT hfont
= GetHfontOf(win
->GetFont());
6179 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
6183 // finally retrieve the text metrics from it
6184 GetTextMetrics(hdc
, &tm
);
6186 #if !wxDIALOG_UNIT_COMPATIBILITY
6190 (void)::SelectObject(hdc
, hfont
);
6194 ::ReleaseDC(hwnd
, hdc
);
6199 // Find the wxWindow at the current mouse position, returning the mouse
6201 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
6203 pt
= wxGetMousePosition();
6204 return wxFindWindowAtPoint(pt
);
6207 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
6212 HWND hWndHit
= ::WindowFromPoint(pt2
);
6214 wxWindow
* win
= wxFindWinFromHandle((WXHWND
) hWndHit
) ;
6215 HWND hWnd
= hWndHit
;
6217 // Try to find a window with a wxWindow associated with it
6218 while (!win
&& (hWnd
!= 0))
6220 hWnd
= ::GetParent(hWnd
);
6221 win
= wxFindWinFromHandle((WXHWND
) hWnd
) ;
6226 // Get the current mouse position.
6227 wxPoint
wxGetMousePosition()
6231 GetCursorPosWinCE(&pt
);
6233 GetCursorPos( & pt
);
6236 return wxPoint(pt
.x
, pt
.y
);
6241 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6242 static void WinCEUnregisterHotKey(int modifiers
, int id
)
6244 // Register hotkeys for the hardware buttons
6246 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
6248 UnregisterFunc1Proc procUnregisterFunc
;
6249 hCoreDll
= LoadLibrary(_T("coredll.dll"));
6252 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, _T("UnregisterFunc1"));
6253 if (procUnregisterFunc
)
6254 procUnregisterFunc(modifiers
, id
);
6255 FreeLibrary(hCoreDll
);
6260 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
6262 UINT win_modifiers
=0;
6263 if ( modifiers
& wxMOD_ALT
)
6264 win_modifiers
|= MOD_ALT
;
6265 if ( modifiers
& wxMOD_SHIFT
)
6266 win_modifiers
|= MOD_SHIFT
;
6267 if ( modifiers
& wxMOD_CONTROL
)
6268 win_modifiers
|= MOD_CONTROL
;
6269 if ( modifiers
& wxMOD_WIN
)
6270 win_modifiers
|= MOD_WIN
;
6272 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6273 // Required for PPC and Smartphone hardware buttons
6274 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
6275 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
6278 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
6280 wxLogLastError(_T("RegisterHotKey"));
6288 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
6290 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6291 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
6294 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
6296 wxLogLastError(_T("UnregisterHotKey"));
6306 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
6308 int hotkeyId
= wParam
;
6309 int virtualKey
= HIWORD(lParam
);
6310 int win_modifiers
= LOWORD(lParam
);
6312 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
6313 event
.SetId(hotkeyId
);
6314 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
6315 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
6316 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
6317 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
6319 return GetEventHandler()->ProcessEvent(event
);
6322 #endif // wxUSE_ACCEL
6324 #endif // wxUSE_HOTKEY
6326 // Not tested under WinCE
6329 // this class installs a message hook which really wakes up our idle processing
6330 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
6331 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
6332 // being dragged or even inside ::MessageBox()) and so don't control message
6333 // dispatching otherwise
6334 class wxIdleWakeUpModule
: public wxModule
6337 virtual bool OnInit()
6339 ms_hMsgHookProc
= ::SetWindowsHookEx
6342 &wxIdleWakeUpModule::MsgHookProc
,
6344 GetCurrentThreadId()
6347 if ( !ms_hMsgHookProc
)
6349 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
6357 virtual void OnExit()
6359 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
6362 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
6364 MSG
*msg
= (MSG
*)lParam
;
6366 // only process the message if it is actually going to be removed from
6367 // the message queue, this prevents that the same event from being
6368 // processed multiple times if now someone just called PeekMessage()
6369 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
6371 wxTheApp
->ProcessPendingEvents();
6374 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
6378 static HHOOK ms_hMsgHookProc
;
6380 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
6383 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
6385 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
6387 #endif // __WXWINCE__
6392 static void wxAdjustZOrder(wxWindow
* parent
)
6394 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
6396 // Set the z-order correctly
6397 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
6400 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
6403 wxWindow
*childWin
= current
->GetData();
6404 wxAdjustZOrder(childWin
);
6405 current
= current
->GetNext();
6410 // We need to adjust the z-order of static boxes in WinCE, to
6411 // make 'contained' controls visible
6412 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
6415 wxAdjustZOrder(this);