1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/windows.cpp
4 // Author: Julian Smart
5 // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "window.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/msw/wrapwin.h"
33 #include "wx/window.h"
38 #include "wx/dcclient.h"
39 #include "wx/dcmemory.h"
42 #include "wx/layout.h"
43 #include "wx/dialog.h"
45 #include "wx/listbox.h"
46 #include "wx/button.h"
47 #include "wx/msgdlg.h"
48 #include "wx/settings.h"
49 #include "wx/statbox.h"
53 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
54 #include "wx/ownerdrw.h"
57 #include "wx/evtloop.h"
58 #include "wx/module.h"
59 #include "wx/sysopt.h"
61 #if wxUSE_DRAG_AND_DROP
65 #if wxUSE_ACCESSIBILITY
66 #include "wx/access.h"
70 #define WM_GETOBJECT 0x003D
73 #define OBJID_CLIENT 0xFFFFFFFC
77 #include "wx/menuitem.h"
80 #include "wx/msw/private.h"
83 #include "wx/tooltip.h"
91 #include "wx/spinctrl.h"
92 #endif // wxUSE_SPINCTRL
97 #include "wx/textctrl.h"
98 #include "wx/notebook.h"
99 #include "wx/listctrl.h"
103 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
104 #include <shellapi.h>
105 #include <mmsystem.h>
109 #include <windowsx.h>
112 #include <commctrl.h>
114 #include "wx/msw/missing.h"
116 #if defined(__WXWINCE__)
117 #include "wx/msw/wince/missing.h"
120 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE)
121 #define HAVE_TRACKMOUSEEVENT
122 #endif // everything needed for TrackMouseEvent()
124 // if this is set to 1, we use deferred window sizing to reduce flicker when
125 // resizing complicated window hierarchies, but this can in theory result in
126 // different behaviour than the old code so we keep the possibility to use it
127 // by setting this to 0 (in the future this should be removed completely)
128 #define USE_DEFERRED_SIZING 1
130 // ---------------------------------------------------------------------------
132 // ---------------------------------------------------------------------------
134 #if wxUSE_MENUS_NATIVE
135 wxMenu
*wxCurrentPopupMenu
= NULL
;
136 #endif // wxUSE_MENUS_NATIVE
139 extern wxChar
*wxCanvasClassName
;
141 extern const wxChar
*wxCanvasClassName
;
144 // true if we had already created the std colour map, used by
145 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
146 static bool gs_hasStdCmap
= false;
148 // ---------------------------------------------------------------------------
150 // ---------------------------------------------------------------------------
152 // the window proc for all our windows
153 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
154 WPARAM wParam
, LPARAM lParam
);
158 const wxChar
*wxGetMessageName(int message
);
161 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
162 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
163 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
165 // get the text metrics for the current font
166 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
169 // find the window for the mouse event at the specified position
170 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
171 #endif // __WXWINCE__
173 // wrapper around BringWindowToTop() API
174 static inline void wxBringWindowToTop(HWND hwnd
)
176 #ifdef __WXMICROWIN__
177 // It seems that MicroWindows brings the _parent_ of the window to the top,
178 // which can be the wrong one.
180 // activate (set focus to) specified window
184 // raise top level parent to top of z order
185 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
187 wxLogLastError(_T("SetWindowPos"));
193 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
194 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
197 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
198 parent as well as otherwise several Win32 functions using
199 GetNextDlgTabItem() to iterate over all controls such as
200 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
201 all of them iterate over all the controls starting from the currently
202 focused one and stop iterating when they get back to the focus but
203 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
204 get back to the initial (focused) window: as we do have this style,
205 GetNextDlgTabItem() will leave this window and continue in its parent,
206 but if the parent doesn't have it, it wouldn't recurse inside it later
207 on and so wouldn't have a chance of getting back to this window neither.
209 while ( parent
&& !parent
->IsTopLevel() )
211 LONG exStyle
= ::GetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
);
212 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
214 // force the parent to have this style
215 ::SetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
,
216 exStyle
| WS_EX_CONTROLPARENT
);
219 parent
= parent
->GetParent();
223 #endif // !__WXWINCE__
226 // On Windows CE, GetCursorPos can return an error, so use this function
228 bool GetCursorPosWinCE(POINT
* pt
)
230 if (!GetCursorPos(pt
))
232 DWORD pos
= GetMessagePos();
240 // ---------------------------------------------------------------------------
242 // ---------------------------------------------------------------------------
244 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
246 #ifdef __WXUNIVERSAL__
247 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
249 #if wxUSE_EXTENDED_RTTI
251 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
252 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
253 // windows with negative ids never can be recreated anyway
255 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
257 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
258 if ( win
&& win
->GetId() < 0 )
263 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
265 // make wxWindowList known before the property is used
267 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
269 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
271 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
274 WX_DEFINE_FLAGS( wxWindowStyle
)
276 wxBEGIN_FLAGS( wxWindowStyle
)
277 // new style border flags, we put them first to
278 // use them for streaming out
280 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
281 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
282 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
283 wxFLAGS_MEMBER(wxBORDER_RAISED
)
284 wxFLAGS_MEMBER(wxBORDER_STATIC
)
285 wxFLAGS_MEMBER(wxBORDER_NONE
)
287 // old style border flags
288 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
289 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
290 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
291 wxFLAGS_MEMBER(wxRAISED_BORDER
)
292 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
293 wxFLAGS_MEMBER(wxBORDER
)
295 // standard window styles
296 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
297 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
298 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
299 wxFLAGS_MEMBER(wxWANTS_CHARS
)
300 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
301 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
302 wxFLAGS_MEMBER(wxVSCROLL
)
303 wxFLAGS_MEMBER(wxHSCROLL
)
305 wxEND_FLAGS( wxWindowStyle
)
307 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
308 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
309 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
310 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
311 // Always constructor Properties first
313 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
314 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
315 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
316 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
317 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
319 // Then all relations of the object graph
321 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
323 // and finally all other properties
325 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
326 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
327 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
328 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
329 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
331 // possible property candidates (not in xrc) or not valid in all subclasses
332 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
333 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
334 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
335 // MaxHeight, Width , MinHeight , Width
336 // TODO switch label to control and title to toplevels
338 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
339 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
340 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
341 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
346 wxEND_PROPERTIES_TABLE()
348 wxBEGIN_HANDLERS_TABLE(wxWindow
)
349 wxEND_HANDLERS_TABLE()
351 wxCONSTRUCTOR_DUMMY(wxWindow
)
354 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
356 #endif // __WXUNIVERSAL__/__WXMSW__
358 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
359 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
360 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground
)
362 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
366 // ===========================================================================
368 // ===========================================================================
370 // ---------------------------------------------------------------------------
371 // wxWindow utility functions
372 // ---------------------------------------------------------------------------
374 // Find an item given the MS Windows id
375 wxWindow
*wxWindowMSW::FindItem(long id
) const
378 wxControl
*item
= wxDynamicCastThis(wxControl
);
381 // is it we or one of our "internal" children?
382 if ( item
->GetId() == id
383 #ifndef __WXUNIVERSAL__
384 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
385 #endif // __WXUNIVERSAL__
391 #endif // wxUSE_CONTROLS
393 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
396 wxWindow
*childWin
= current
->GetData();
398 wxWindow
*wnd
= childWin
->FindItem(id
);
402 current
= current
->GetNext();
408 // Find an item given the MS Windows handle
409 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
411 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
414 wxWindow
*parent
= current
->GetData();
416 // Do a recursive search.
417 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
423 || parent
->IsKindOf(CLASSINFO(wxControl
))
424 #endif // wxUSE_CONTROLS
427 wxWindow
*item
= current
->GetData();
428 if ( item
->GetHWND() == hWnd
)
432 if ( item
->ContainsHWND(hWnd
) )
437 current
= current
->GetNext();
442 // Default command handler
443 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
448 // ----------------------------------------------------------------------------
449 // constructors and such
450 // ----------------------------------------------------------------------------
452 void wxWindowMSW::Init()
455 m_isBeingDeleted
= false;
457 m_mouseInWindow
= false;
458 m_lastKeydownProcessed
= false;
460 m_childrenDisabled
= NULL
;
469 #if wxUSE_MOUSEEVENT_HACK
472 m_lastMouseEvent
= -1;
473 #endif // wxUSE_MOUSEEVENT_HACK
475 m_pendingPosition
= wxDefaultPosition
;
476 m_pendingSize
= wxDefaultSize
;
480 wxWindowMSW::~wxWindowMSW()
482 m_isBeingDeleted
= true;
484 #ifndef __WXUNIVERSAL__
485 // VS: make sure there's no wxFrame with last focus set to us:
486 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
488 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
491 if ( frame
->GetLastFocus() == this )
493 frame
->SetLastFocus(NULL
);
496 // apparently sometimes we can end up with our grand parent
497 // pointing to us as well: this is surely a bug in focus handling
498 // code but it's not clear where it happens so for now just try to
499 // fix it here by not breaking out of the loop
503 #endif // __WXUNIVERSAL__
505 // VS: destroy children first and _then_ detach *this from its parent.
506 // If we'd do it the other way around, children wouldn't be able
507 // find their parent frame (see above).
512 // VZ: test temp removed to understand what really happens here
513 //if (::IsWindow(GetHwnd()))
515 if ( !::DestroyWindow(GetHwnd()) )
516 wxLogLastError(wxT("DestroyWindow"));
519 // remove hWnd <-> wxWindow association
520 wxRemoveHandleAssociation(this);
523 delete m_childrenDisabled
;
527 // real construction (Init() must have been called before!)
528 bool wxWindowMSW::Create(wxWindow
*parent
,
533 const wxString
& name
)
535 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
537 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
540 parent
->AddChild(this);
543 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
545 #ifdef __WXUNIVERSAL__
546 // no borders, we draw them ourselves
547 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
551 msflags
&= ~WS_BORDER
;
552 #endif // wxUniversal
556 msflags
|= WS_VISIBLE
;
559 if ( !MSWCreate(wxCanvasClassName
, NULL
, pos
, size
, msflags
, exstyle
) )
567 // ---------------------------------------------------------------------------
569 // ---------------------------------------------------------------------------
571 void wxWindowMSW::SetFocus()
573 HWND hWnd
= GetHwnd();
574 wxCHECK_RET( hWnd
, _T("can't set focus to invalid window") );
576 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
580 if ( !::SetFocus(hWnd
) )
582 #if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
583 // was there really an error?
584 DWORD dwRes
= ::GetLastError();
587 HWND hwndFocus
= ::GetFocus();
588 if ( hwndFocus
!= hWnd
)
590 wxLogApiError(_T("SetFocus"), dwRes
);
597 void wxWindowMSW::SetFocusFromKbd()
599 // when the focus is given to the control with DLGC_HASSETSEL style from
600 // keyboard its contents should be entirely selected: this is what
601 // ::IsDialogMessage() does and so we should do it as well to provide the
602 // same LNF as the native programs
603 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
605 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
608 // do this after (maybe) setting the selection as like this when
609 // wxEVT_SET_FOCUS handler is called, the selection would have been already
610 // set correctly -- this may be important
611 wxWindowBase::SetFocusFromKbd();
614 // Get the window with the focus
615 wxWindow
*wxWindowBase::DoFindFocus()
617 HWND hWnd
= ::GetFocus();
620 return wxGetWindowFromHWND((WXHWND
)hWnd
);
626 bool wxWindowMSW::Enable(bool enable
)
628 if ( !wxWindowBase::Enable(enable
) )
631 HWND hWnd
= GetHwnd();
633 ::EnableWindow(hWnd
, (BOOL
)enable
);
635 // the logic below doesn't apply to the top level windows -- otherwise
636 // showing a modal dialog would result in total greying out (and ungreying
637 // out later) of everything which would be really ugly
641 // when the parent is disabled, all of its children should be disabled as
642 // well but when it is enabled back, only those of the children which
643 // hadn't been already disabled in the beginning should be enabled again,
644 // so we have to keep the list of those children
645 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
647 node
= node
->GetNext() )
649 wxWindow
*child
= node
->GetData();
650 if ( child
->IsTopLevel() )
652 // the logic below doesn't apply to top level children
658 // enable the child back unless it had been disabled before us
659 if ( !m_childrenDisabled
|| !m_childrenDisabled
->Find(child
) )
662 else // we're being disabled
664 if ( child
->IsEnabled() )
666 // disable it as children shouldn't stay enabled while the
670 else // child already disabled, remember it
672 // have we created the list of disabled children already?
673 if ( !m_childrenDisabled
)
674 m_childrenDisabled
= new wxWindowList
;
676 m_childrenDisabled
->Append(child
);
681 if ( enable
&& m_childrenDisabled
)
683 // we don't need this list any more, don't keep unused memory
684 delete m_childrenDisabled
;
685 m_childrenDisabled
= NULL
;
691 bool wxWindowMSW::Show(bool show
)
693 if ( !wxWindowBase::Show(show
) )
696 HWND hWnd
= GetHwnd();
697 int cshow
= show
? SW_SHOW
: SW_HIDE
;
698 ::ShowWindow(hWnd
, cshow
);
700 if ( show
&& IsTopLevel() )
702 wxBringWindowToTop(hWnd
);
708 // Raise the window to the top of the Z order
709 void wxWindowMSW::Raise()
711 wxBringWindowToTop(GetHwnd());
714 // Lower the window to the bottom of the Z order
715 void wxWindowMSW::Lower()
717 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
718 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
721 void wxWindowMSW::SetTitle( const wxString
& title
)
723 SetWindowText(GetHwnd(), title
.c_str());
726 wxString
wxWindowMSW::GetTitle() const
728 return wxGetWindowText(GetHWND());
731 void wxWindowMSW::DoCaptureMouse()
733 HWND hWnd
= GetHwnd();
740 void wxWindowMSW::DoReleaseMouse()
742 if ( !::ReleaseCapture() )
744 wxLogLastError(_T("ReleaseCapture"));
748 /* static */ wxWindow
*wxWindowBase::GetCapture()
750 HWND hwnd
= ::GetCapture();
751 return hwnd
? wxFindWinFromHandle((WXHWND
)hwnd
) : (wxWindow
*)NULL
;
754 bool wxWindowMSW::SetFont(const wxFont
& font
)
756 if ( !wxWindowBase::SetFont(font
) )
762 HWND hWnd
= GetHwnd();
765 WXHANDLE hFont
= m_font
.GetResourceHandle();
767 wxASSERT_MSG( hFont
, wxT("should have valid font") );
769 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
774 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
776 if ( !wxWindowBase::SetCursor(cursor
) )
784 HWND hWnd
= GetHwnd();
786 // Change the cursor NOW if we're within the correct window
789 ::GetCursorPosWinCE(&point
);
791 ::GetCursorPos(&point
);
794 RECT rect
= wxGetWindowRect(hWnd
);
796 if ( ::PtInRect(&rect
, point
) && !wxIsBusy() )
797 ::SetCursor(GetHcursorOf(m_cursor
));
803 void wxWindowMSW::WarpPointer(int x
, int y
)
805 ClientToScreen(&x
, &y
);
807 if ( !::SetCursorPos(x
, y
) )
809 wxLogLastError(_T("SetCursorPos"));
813 void wxWindowMSW::MSWUpdateUIState()
815 // WM_UPDATEUISTATE only appeared in Windows 2000 so it can do us no good
816 // to use it on older systems -- and could possibly do some harm
817 static int s_needToUpdate
= -1;
818 if ( s_needToUpdate
== -1 )
821 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxWINDOWS_NT
&&
825 if ( s_needToUpdate
)
827 // NB: it doesn't seem to matter what we put in wParam, whether we
828 // include just one UISF_XXX or both, both are affected, no idea
830 ::SendMessage(GetHwnd(), WM_UPDATEUISTATE
,
831 MAKEWPARAM(UIS_INITIALIZE
,
832 UISF_HIDEFOCUS
| UISF_HIDEACCEL
), 0);
836 // ---------------------------------------------------------------------------
838 // ---------------------------------------------------------------------------
840 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
842 #ifdef __WXMICROWIN__
843 return ::GetScrollPosWX(hWnd
, wOrient
);
845 WinStruct
<SCROLLINFO
> scrollInfo
;
846 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
847 scrollInfo
.fMask
= SIF_POS
;
848 if ( !::GetScrollInfo(hWnd
,
852 // Not necessarily an error, if there are no scrollbars yet.
853 // wxLogLastError(_T("GetScrollInfo"));
855 return scrollInfo
.nPos
;
856 // return ::GetScrollPos(hWnd, wOrient);
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 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
947 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
950 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
956 rect
.left
= prect
->x
;
958 rect
.right
= prect
->x
+ prect
->width
;
959 rect
.bottom
= prect
->y
+ prect
->height
;
969 // FIXME: is this the exact equivalent of the line below?
970 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
972 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
976 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
978 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
981 for ( int n
= 0; n
< count
; n
++ )
983 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
985 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
988 // don't bother to continue, we're already at top/bottom
995 return pos
!= posStart
;
998 bool wxWindowMSW::ScrollLines(int lines
)
1000 bool down
= lines
> 0;
1002 return ScrollVertically(GetHwnd(),
1003 down
? SB_LINEDOWN
: SB_LINEUP
,
1004 down
? lines
: -lines
);
1007 bool wxWindowMSW::ScrollPages(int pages
)
1009 bool down
= pages
> 0;
1011 return ScrollVertically(GetHwnd(),
1012 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1013 down
? pages
: -pages
);
1016 // ---------------------------------------------------------------------------
1018 // ---------------------------------------------------------------------------
1020 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1022 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1024 HWND hwnd
= (HWND
)hWnd
;
1025 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1027 wxAssociateWinWithHandle(hwnd
, this);
1029 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1031 // we don't need to subclass the window of our own class (in the Windows
1032 // sense of the word)
1033 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1035 wxSetWindowProc(hwnd
, wxWndProc
);
1039 // don't bother restoring it neither: this also makes it easy to
1040 // implement IsOfStandardClass() method which returns true for the
1041 // standard controls and false for the wxWidgets own windows as it can
1042 // simply check m_oldWndProc
1043 m_oldWndProc
= NULL
;
1047 void wxWindowMSW::UnsubclassWin()
1049 wxRemoveHandleAssociation(this);
1051 // Restore old Window proc
1052 HWND hwnd
= GetHwnd();
1057 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1061 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1063 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1066 m_oldWndProc
= NULL
;
1071 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1075 if ( !::DestroyWindow(GetHwnd()) )
1076 wxLogLastError(wxT("DestroyWindow"));
1079 WXHWND wxhwnd
= (WXHWND
)handle
;
1082 SubclassWin(wxhwnd
);
1085 void wxWindowMSW::DissociateHandle()
1087 // this also calls SetHWND(0) for us
1092 bool wxCheckWindowWndProc(WXHWND hWnd
,
1093 WXFARPROC
WXUNUSED_IN_WINCE(wndProc
))
1095 // Unicows note: the code below works, but only because WNDCLASS contains
1096 // original window handler rather that the unicows fake one. This may not
1097 // be on purpose, though; if it stops working with future versions of
1098 // unicows.dll, we can override unicows hooks by setting
1099 // Unicows_{Set,Get}WindowLong and Unicows_RegisterClass to our own
1100 // versions that keep track of fake<->real wnd proc mapping.
1102 // On WinCE (at least), the wndproc comparison doesn't work,
1103 // so have to use something like this.
1105 extern wxChar
*wxCanvasClassName
;
1106 extern wxChar
*wxCanvasClassNameNR
;
1107 extern const wxChar
*wxMDIFrameClassName
;
1108 extern const wxChar
*wxMDIFrameClassNameNoRedraw
;
1109 extern const wxChar
*wxMDIChildFrameClassName
;
1110 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
1111 wxString
str(wxGetWindowClass(hWnd
));
1112 if (str
== wxCanvasClassName
||
1113 str
== wxCanvasClassNameNR
||
1114 str
== wxMDIFrameClassName
||
1115 str
== wxMDIFrameClassNameNoRedraw
||
1116 str
== wxMDIChildFrameClassName
||
1117 str
== wxMDIChildFrameClassNameNoRedraw
||
1118 str
== _T("wxTLWHiddenParent"))
1119 return true; // Effectively means don't subclass
1124 if ( !::GetClassInfo(wxGetInstance(), wxGetWindowClass(hWnd
), &cls
) )
1126 wxLogLastError(_T("GetClassInfo"));
1131 return wndProc
== (WXFARPROC
)cls
.lpfnWndProc
;
1135 // ----------------------------------------------------------------------------
1137 // ----------------------------------------------------------------------------
1139 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1141 long flagsOld
= GetWindowStyleFlag();
1142 if ( flags
== flagsOld
)
1145 // update the internal variable
1146 wxWindowBase::SetWindowStyleFlag(flags
);
1148 // now update the Windows style as well if needed - and if the window had
1149 // been already created
1153 WXDWORD exstyle
, exstyleOld
;
1154 long style
= MSWGetStyle(flags
, &exstyle
),
1155 styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1157 if ( style
!= styleOld
)
1159 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1160 // this function so instead of simply setting the style to the new
1161 // value we clear the bits which were set in styleOld but are set in
1162 // the new one and set the ones which were not set before
1163 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1164 styleReal
&= ~styleOld
;
1167 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1170 // and the extended style
1171 if ( exstyle
!= exstyleOld
)
1173 long exstyleReal
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1174 exstyleReal
&= ~exstyleOld
;
1175 exstyleReal
|= exstyle
;
1177 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyleReal
);
1179 // we must call SetWindowPos() to flush the cached extended style and
1180 // also to make the change to wxSTAY_ON_TOP style take effect: just
1181 // setting the style simply doesn't work
1182 if ( !::SetWindowPos(GetHwnd(),
1183 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1186 SWP_NOMOVE
| SWP_NOSIZE
) )
1188 wxLogLastError(_T("SetWindowPos"));
1193 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1195 // translate common wxWidgets styles to Windows ones
1197 // most of windows are child ones, those which are not (such as
1198 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1199 WXDWORD style
= WS_CHILD
;
1201 // using this flag results in very significant reduction in flicker,
1202 // especially with controls inside the static boxes (as the interior of the
1203 // box is not redrawn twice).but sometimes results in redraw problems, so
1204 // optionally allow the old code to continue to use it provided a special
1205 // system option is turned on
1206 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1207 || (flags
& wxCLIP_CHILDREN
) )
1208 style
|= WS_CLIPCHILDREN
;
1210 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1211 // don't support overlapping windows and it only makes sense for them and,
1212 // presumably, gives the system some extra work (to manage more clipping
1213 // regions), so avoid it alltogether
1216 if ( flags
& wxVSCROLL
)
1217 style
|= WS_VSCROLL
;
1219 if ( flags
& wxHSCROLL
)
1220 style
|= WS_HSCROLL
;
1222 const wxBorder border
= GetBorder(flags
);
1224 // WS_BORDER is only required for wxBORDER_SIMPLE
1225 if ( border
== wxBORDER_SIMPLE
)
1228 // now deal with ext style if the caller wants it
1234 if ( flags
& wxTRANSPARENT_WINDOW
)
1235 *exstyle
|= WS_EX_TRANSPARENT
;
1241 case wxBORDER_DEFAULT
:
1242 wxFAIL_MSG( _T("unknown border style") );
1246 case wxBORDER_SIMPLE
:
1249 case wxBORDER_STATIC
:
1250 *exstyle
|= WS_EX_STATICEDGE
;
1253 case wxBORDER_RAISED
:
1254 *exstyle
|= WS_EX_DLGMODALFRAME
;
1257 case wxBORDER_SUNKEN
:
1258 *exstyle
|= WS_EX_CLIENTEDGE
;
1259 style
&= ~WS_BORDER
;
1262 case wxBORDER_DOUBLE
:
1263 *exstyle
|= WS_EX_DLGMODALFRAME
;
1267 // wxUniv doesn't use Windows dialog navigation functions at all
1268 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1269 // to make the dialog navigation work with the nested panels we must
1270 // use this style (top level windows such as dialogs don't need it)
1271 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1273 *exstyle
|= WS_EX_CONTROLPARENT
;
1275 #endif // __WXUNIVERSAL__
1281 // Setup background and foreground colours correctly
1282 void wxWindowMSW::SetupColours()
1285 SetBackgroundColour(GetParent()->GetBackgroundColour());
1288 bool wxWindowMSW::IsMouseInWindow() const
1290 // get the mouse position
1293 ::GetCursorPosWinCE(&pt
);
1295 ::GetCursorPos(&pt
);
1298 // find the window which currently has the cursor and go up the window
1299 // chain until we find this window - or exhaust it
1300 HWND hwnd
= ::WindowFromPoint(pt
);
1301 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1302 hwnd
= ::GetParent(hwnd
);
1304 return hwnd
!= NULL
;
1307 void wxWindowMSW::OnInternalIdle()
1309 #ifndef HAVE_TRACKMOUSEEVENT
1310 // Check if we need to send a LEAVE event
1311 if ( m_mouseInWindow
)
1313 // note that we should generate the leave event whether the window has
1314 // or doesn't have mouse capture
1315 if ( !IsMouseInWindow() )
1317 GenerateMouseLeave();
1320 #endif // !HAVE_TRACKMOUSEEVENT
1322 if (wxUpdateUIEvent::CanUpdate(this))
1323 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1326 // Set this window to be the child of 'parent'.
1327 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1329 if ( !wxWindowBase::Reparent(parent
) )
1332 HWND hWndChild
= GetHwnd();
1333 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1335 ::SetParent(hWndChild
, hWndParent
);
1338 if ( ::GetWindowLong(hWndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1340 EnsureParentHasControlParentStyle(GetParent());
1342 #endif // !__WXWINCE__
1347 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1349 #ifndef __WXMICROWIN__
1350 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1354 void wxWindowMSW::Freeze()
1356 if ( !m_frozenness
++ )
1359 SendSetRedraw(GetHwnd(), false);
1363 void wxWindowMSW::Thaw()
1365 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1367 if ( !--m_frozenness
)
1371 SendSetRedraw(GetHwnd(), true);
1373 // we need to refresh everything or otherwise the invalidated area
1374 // is not going to be repainted
1380 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1382 HWND hWnd
= GetHwnd();
1389 mswRect
.left
= rect
->x
;
1390 mswRect
.top
= rect
->y
;
1391 mswRect
.right
= rect
->x
+ rect
->width
;
1392 mswRect
.bottom
= rect
->y
+ rect
->height
;
1401 // RedrawWindow not available on SmartPhone or eVC++ 3
1402 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1403 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1407 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1409 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1414 void wxWindowMSW::Update()
1416 if ( !::UpdateWindow(GetHwnd()) )
1418 wxLogLastError(_T("UpdateWindow"));
1421 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1422 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1423 // handler needs to be really drawn right now
1428 // ---------------------------------------------------------------------------
1430 // ---------------------------------------------------------------------------
1433 #if wxUSE_DRAG_AND_DROP
1434 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1436 if ( m_dropTarget
!= 0 ) {
1437 m_dropTarget
->Revoke(m_hWnd
);
1438 delete m_dropTarget
;
1441 m_dropTarget
= pDropTarget
;
1442 if ( m_dropTarget
!= 0 )
1443 m_dropTarget
->Register(m_hWnd
);
1445 #endif // wxUSE_DRAG_AND_DROP
1447 // old style file-manager drag&drop support: we retain the old-style
1448 // DragAcceptFiles in parallel with SetDropTarget.
1449 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1452 HWND hWnd
= GetHwnd();
1454 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1458 // ----------------------------------------------------------------------------
1460 // ----------------------------------------------------------------------------
1464 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1466 wxWindowBase::DoSetToolTip(tooltip
);
1469 m_tooltip
->SetWindow((wxWindow
*)this);
1472 #endif // wxUSE_TOOLTIPS
1474 // ---------------------------------------------------------------------------
1475 // moving and resizing
1476 // ---------------------------------------------------------------------------
1478 bool wxWindowMSW::IsSizeDeferred() const
1480 #if USE_DEFERRED_SIZING
1481 if ( m_pendingPosition
!= wxDefaultPosition
||
1482 m_pendingSize
!= wxDefaultSize
)
1484 #endif // USE_DEFERRED_SIZING
1490 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1492 // if SetSize() had been called at wx level but not realized at Windows
1493 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1494 // the new and not the old position to the other wx code
1495 if ( m_pendingSize
!= wxDefaultSize
)
1498 *x
= m_pendingSize
.x
;
1500 *y
= m_pendingSize
.y
;
1502 else // use current size
1504 RECT rect
= wxGetWindowRect(GetHwnd());
1507 *x
= rect
.right
- rect
.left
;
1509 *y
= rect
.bottom
- rect
.top
;
1513 // Get size *available for subwindows* i.e. excluding menu bar etc.
1514 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1516 // this is only for top level windows whose resizing is never deferred, so
1517 // we can safely use the current size here
1518 RECT rect
= wxGetClientRect(GetHwnd());
1526 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1528 wxWindow
* const parent
= GetParent();
1531 if ( m_pendingPosition
!= wxDefaultPosition
)
1533 pos
= m_pendingPosition
;
1535 else // use current position
1537 RECT rect
= wxGetWindowRect(GetHwnd());
1540 point
.x
= rect
.left
;
1543 // we do the adjustments with respect to the parent only for the "real"
1544 // children, not for the dialogs/frames
1545 if ( !IsTopLevel() )
1547 // Since we now have the absolute screen coords, if there's a
1548 // parent we must subtract its top left corner
1551 ::ScreenToClient(GetHwndOf(parent
), &point
);
1559 // we also must adjust by the client area offset: a control which is just
1560 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1561 if ( parent
&& !IsTopLevel() )
1563 const wxPoint
pt(parent
->GetClientAreaOrigin());
1574 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1582 ::ScreenToClient(GetHwnd(), &pt
);
1590 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1598 ::ClientToScreen(GetHwnd(), &pt
);
1607 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1609 #if USE_DEFERRED_SIZING
1610 // if our parent had prepared a defer window handle for us, use it (unless
1611 // we are a top level window)
1612 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1614 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1617 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1621 wxLogLastError(_T("DeferWindowPos"));
1627 // hdwp must be updated as it may have been changed
1628 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1633 // did deferred move, remember new coordinates of the window as they're
1634 // different from what Windows would return for it
1638 // otherwise (or if deferring failed) move the window in place immediately
1639 #endif // USE_DEFERRED_SIZING
1640 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
1642 wxLogLastError(wxT("MoveWindow"));
1645 // if USE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1646 // ignored otherwise
1650 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1652 // TODO: is this consistent with other platforms?
1653 // Still, negative width or height shouldn't be allowed
1659 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
1661 #if USE_DEFERRED_SIZING
1662 m_pendingPosition
= wxPoint(x
, y
);
1663 m_pendingSize
= wxSize(width
, height
);
1664 #endif // USE_DEFERRED_SIZING
1668 // set the size of the window: if the dimensions are positive, just use them,
1669 // but if any of them is equal to -1, it means that we must find the value for
1670 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1671 // which case -1 is a valid value for x and y)
1673 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1674 // the width/height to best suit our contents, otherwise we reuse the current
1676 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1678 // get the current size and position...
1679 int currentX
, currentY
;
1680 int currentW
, currentH
;
1682 GetPosition(¤tX
, ¤tY
);
1683 GetSize(¤tW
, ¤tH
);
1685 // ... and don't do anything (avoiding flicker) if it's already ok unless
1686 // we're forced to resize the window
1687 if ( x
== currentX
&& y
== currentY
&&
1688 width
== currentW
&& height
== currentH
&&
1689 !(sizeFlags
& wxSIZE_FORCE
) )
1694 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1696 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1699 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1701 wxSize size
= wxDefaultSize
;
1702 if ( width
== wxDefaultCoord
)
1704 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1706 size
= DoGetBestSize();
1711 // just take the current one
1716 if ( height
== wxDefaultCoord
)
1718 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1720 if ( size
.x
== wxDefaultCoord
)
1722 size
= DoGetBestSize();
1724 //else: already called DoGetBestSize() above
1730 // just take the current one
1735 DoMoveWindow(x
, y
, width
, height
);
1738 void wxWindowMSW::DoSetClientSize(int width
, int height
)
1740 // setting the client size is less obvious than it it could have been
1741 // because in the result of changing the total size the window scrollbar
1742 // may [dis]appear and/or its menubar may [un]wrap and so the client size
1743 // will not be correct as the difference between the total and client size
1744 // changes - so we keep changing it until we get it right
1746 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1747 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1748 // may become 3 if the window had 0 size originally and so we didn't
1749 // calculate the scrollbar correction correctly during the first iteration)
1750 // but just to be on the safe side we check for it instead of making it an
1751 // "infinite" loop (i.e. leaving break inside as the only way to get out)
1752 for ( int i
= 0; i
< 4; i
++ )
1755 ::GetClientRect(GetHwnd(), &rectClient
);
1757 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
1758 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
1759 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
1764 // Find the difference between the entire window (title bar and all)
1765 // and the client area; add this to the new client size to move the
1768 ::GetWindowRect(GetHwnd(), &rectWin
);
1770 const int widthWin
= rectWin
.right
- rectWin
.left
,
1771 heightWin
= rectWin
.bottom
- rectWin
.top
;
1773 // MoveWindow positions the child windows relative to the parent, so
1774 // adjust if necessary
1775 if ( !IsTopLevel() )
1777 wxWindow
*parent
= GetParent();
1780 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
1784 // don't call DoMoveWindow() because we want to move window immediately
1785 // and not defer it here
1786 if ( !::MoveWindow(GetHwnd(),
1789 width
+ widthWin
- rectClient
.right
,
1790 height
+ heightWin
- rectClient
.bottom
,
1793 wxLogLastError(_T("MoveWindow"));
1798 // ---------------------------------------------------------------------------
1800 // ---------------------------------------------------------------------------
1802 int wxWindowMSW::GetCharHeight() const
1804 return wxGetTextMetrics(this).tmHeight
;
1807 int wxWindowMSW::GetCharWidth() const
1809 // +1 is needed because Windows apparently adds it when calculating the
1810 // dialog units size in pixels
1811 #if wxDIALOG_UNIT_COMPATIBILITY
1812 return wxGetTextMetrics(this).tmAveCharWidth
;
1814 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
1818 void wxWindowMSW::GetTextExtent(const wxString
& string
,
1820 int *descent
, int *externalLeading
,
1821 const wxFont
*theFont
) const
1823 wxASSERT_MSG( !theFont
|| theFont
->Ok(),
1824 _T("invalid font in GetTextExtent()") );
1828 fontToUse
= *theFont
;
1830 fontToUse
= GetFont();
1832 WindowHDC
hdc(GetHwnd());
1833 SelectInHDC
selectFont(hdc
, GetHfontOf(fontToUse
));
1837 ::GetTextExtentPoint32(hdc
, string
, string
.length(), &sizeRect
);
1838 GetTextMetrics(hdc
, &tm
);
1845 *descent
= tm
.tmDescent
;
1846 if ( externalLeading
)
1847 *externalLeading
= tm
.tmExternalLeading
;
1850 // ---------------------------------------------------------------------------
1852 // ---------------------------------------------------------------------------
1854 #if wxUSE_MENUS_NATIVE
1856 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
1857 // immediately, without waiting for the next event loop iteration
1859 // NB: this function should probably be made public later as it can almost
1860 // surely replace wxYield() elsewhere as well
1861 static void wxYieldForCommandsOnly()
1863 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
1864 // want to process it here)
1866 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
1868 if ( msg
.message
== WM_QUIT
)
1870 // if we retrieved a WM_QUIT, insert back into the message queue.
1871 ::PostQuitMessage(0);
1875 // luckily (as we don't have access to wxEventLoopImpl method from here
1876 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
1878 ::TranslateMessage(&msg
);
1879 ::DispatchMessage(&msg
);
1883 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1885 menu
->SetInvokingWindow(this);
1888 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1890 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
1891 x
= mouse
.x
; y
= mouse
.y
;
1894 HWND hWnd
= GetHwnd();
1895 HMENU hMenu
= GetHmenuOf(menu
);
1899 ::ClientToScreen(hWnd
, &point
);
1900 wxCurrentPopupMenu
= menu
;
1901 #if defined(__WXWINCE__)
1904 UINT flags
= TPM_RIGHTBUTTON
;
1906 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
1908 // we need to do it righ now as otherwise the events are never going to be
1909 // sent to wxCurrentPopupMenu from HandleCommand()
1911 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
1912 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
1913 // destroyed as soon as we return (it can be a local variable in the caller
1914 // for example) and so we do need to process the event immediately
1915 wxYieldForCommandsOnly();
1917 wxCurrentPopupMenu
= NULL
;
1919 menu
->SetInvokingWindow(NULL
);
1924 #endif // wxUSE_MENUS_NATIVE
1926 // ===========================================================================
1927 // pre/post message processing
1928 // ===========================================================================
1930 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1933 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1935 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
1938 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
1940 // wxUniversal implements tab traversal itself
1941 #ifndef __WXUNIVERSAL__
1942 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
1944 // intercept dialog navigation keys
1945 MSG
*msg
= (MSG
*)pMsg
;
1947 // here we try to do all the job which ::IsDialogMessage() usually does
1949 if ( msg
->message
== WM_KEYDOWN
)
1951 bool bCtrlDown
= wxIsCtrlDown();
1952 bool bShiftDown
= wxIsShiftDown();
1954 // WM_GETDLGCODE: ask the control if it wants the key for itself,
1955 // don't process it if it's the case (except for Ctrl-Tab/Enter
1956 // combinations which are always processed)
1960 lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
1962 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
1963 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
1964 // it, of course, implies them
1965 if ( lDlgCode
& DLGC_WANTALLKEYS
)
1967 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
1971 bool bForward
= true,
1972 bWindowChange
= false,
1975 // should we process this message specially?
1976 bool bProcess
= true;
1977 switch ( msg
->wParam
)
1980 if ( lDlgCode
& DLGC_WANTTAB
) {
1984 // Ctrl-Tab cycles thru notebook pages
1985 bWindowChange
= bCtrlDown
;
1986 bForward
= !bShiftDown
;
1993 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2001 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2007 if ( (lDlgCode
& DLGC_WANTMESSAGE
) && !bCtrlDown
)
2009 // control wants to process Enter itself, don't
2010 // call IsDialogMessage() which would interpret
2015 // currently active button should get enter press even
2016 // if there is a default button elsewhere
2017 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2019 // let IsDialogMessage() handle this for all
2020 // buttons except the owner-drawn ones which it
2021 // just seems to ignore
2022 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2023 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2025 // emulate the button click
2027 btn
= wxFindWinFromHandle((WXHWND
)msg
->hwnd
);
2029 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2034 else // not a button itself
2037 wxButton
*btn
= wxDynamicCast(GetDefaultItem(),
2039 if ( btn
&& btn
->IsEnabled() )
2041 // if we do have a default button, do press it
2042 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2046 else // no default button
2047 #endif // wxUSE_BUTTON
2049 // this is a quick and dirty test for a text
2051 if ( !(lDlgCode
& DLGC_HASSETSEL
) )
2053 // don't process Enter, the control might
2054 // need it for itself and don't let
2055 // ::IsDialogMessage() have it as it can
2056 // eat the Enter events sometimes
2059 else if (!IsTopLevel())
2061 // if not a top level window, let parent
2065 //else: treat Enter as TAB: pass to the next
2066 // control as this is the best thing to do
2067 // if the text doesn't handle Enter itself
2079 wxNavigationKeyEvent event
;
2080 event
.SetDirection(bForward
);
2081 event
.SetWindowChange(bWindowChange
);
2082 event
.SetFromTab(bFromTab
);
2083 event
.SetEventObject(this);
2085 if ( GetEventHandler()->ProcessEvent(event
) )
2087 // as we don't call IsDialogMessage(), which would take of
2088 // this by default, we need to manually send this message
2089 // so that controls could change their appearance
2098 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2099 // message even when there is no cancel button and when the message is
2100 // needed by the control itself: in particular, it prevents the tree in
2101 // place edit control from being closed with Escape in a dialog
2102 if ( msg
->message
!= WM_KEYDOWN
|| msg
->wParam
!= VK_ESCAPE
)
2104 // ::IsDialogMessage() is broken and may sometimes hang the
2105 // application by going into an infinite loop, so we try to detect
2106 // [some of] the situatations when this may happen and not call it
2109 // assume we can call it by default
2110 bool canSafelyCallIsDlgMsg
= true;
2112 HWND hwndFocus
= ::GetFocus();
2114 // if the currently focused window itself has WS_EX_CONTROLPARENT style, ::IsDialogMessage() will also enter
2115 // an infinite loop, because it will recursively check the child
2116 // windows but not the window itself and so if none of the children
2117 // accepts focus it loops forever (as it only stops when it gets
2118 // back to the window it started from)
2120 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2121 // style has the focus, it can happen. One such possibility is if
2122 // all windows are either toplevel, wxDialog, wxPanel or static
2123 // controls and no window can actually accept keyboard input.
2124 #if !defined(__WXWINCE__)
2125 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2127 // passimistic by default
2128 canSafelyCallIsDlgMsg
= false;
2129 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2131 node
= node
->GetNext() )
2133 wxWindow
* const win
= node
->GetData();
2134 if ( win
->AcceptsFocus() &&
2135 !(::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
) &
2136 WS_EX_CONTROLPARENT
) )
2138 // it shouldn't hang...
2139 canSafelyCallIsDlgMsg
= true;
2145 #endif // !__WXWINCE__
2147 if ( canSafelyCallIsDlgMsg
)
2149 // ::IsDialogMessage() can enter in an infinite loop when the
2150 // currently focused window is disabled or hidden and its
2151 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2155 if ( !::IsWindowEnabled(hwndFocus
) ||
2156 !::IsWindowVisible(hwndFocus
) )
2158 // it would enter an infinite loop if we do this!
2159 canSafelyCallIsDlgMsg
= false;
2164 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2166 // it's a top level window, don't go further -- e.g. even
2167 // if the parent of a dialog is disabled, this doesn't
2168 // break navigation inside the dialog
2172 hwndFocus
= ::GetParent(hwndFocus
);
2176 // let IsDialogMessage() have the message if it's safe to call it
2177 if ( canSafelyCallIsDlgMsg
&& ::IsDialogMessage(GetHwnd(), msg
) )
2179 // IsDialogMessage() did something...
2184 #endif // __WXUNIVERSAL__
2189 // relay mouse move events to the tooltip control
2190 MSG
*msg
= (MSG
*)pMsg
;
2191 if ( msg
->message
== WM_MOUSEMOVE
)
2192 m_tooltip
->RelayEvent(pMsg
);
2194 #endif // wxUSE_TOOLTIPS
2199 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2201 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2202 return m_acceleratorTable
.Translate(this, pMsg
);
2206 #endif // wxUSE_ACCEL
2209 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* WXUNUSED(pMsg
))
2211 // preprocess all messages by default
2215 // ---------------------------------------------------------------------------
2216 // message params unpackers
2217 // ---------------------------------------------------------------------------
2219 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2220 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2222 *id
= LOWORD(wParam
);
2223 *hwnd
= (WXHWND
)lParam
;
2224 *cmd
= HIWORD(wParam
);
2227 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2228 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2230 *state
= LOWORD(wParam
);
2231 *minimized
= HIWORD(wParam
);
2232 *hwnd
= (WXHWND
)lParam
;
2235 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2236 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2238 *code
= LOWORD(wParam
);
2239 *pos
= HIWORD(wParam
);
2240 *hwnd
= (WXHWND
)lParam
;
2243 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2244 WXHDC
*hdc
, WXHWND
*hwnd
)
2246 *hwnd
= (WXHWND
)lParam
;
2247 *hdc
= (WXHDC
)wParam
;
2250 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2251 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2253 *item
= (WXWORD
)wParam
;
2254 *flags
= HIWORD(wParam
);
2255 *hmenu
= (WXHMENU
)lParam
;
2258 // ---------------------------------------------------------------------------
2259 // Main wxWidgets window proc and the window proc for wxWindow
2260 // ---------------------------------------------------------------------------
2262 // Hook for new window just as it's being created, when the window isn't yet
2263 // associated with the handle
2264 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2266 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2267 // window being created and insures that it's always unset back later
2268 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2270 gs_winBeingCreated
= winBeingCreated
;
2273 wxWindowCreationHook::~wxWindowCreationHook()
2275 gs_winBeingCreated
= NULL
;
2279 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2281 // trace all messages - useful for the debugging
2283 wxLogTrace(wxTraceMessages
,
2284 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2285 wxGetMessageName(message
), (long)hWnd
, (long)wParam
, lParam
);
2286 #endif // __WXDEBUG__
2288 wxWindowMSW
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
2290 // when we get the first message for the HWND we just created, we associate
2291 // it with wxWindow stored in gs_winBeingCreated
2292 if ( !wnd
&& gs_winBeingCreated
)
2294 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2295 wnd
= gs_winBeingCreated
;
2296 gs_winBeingCreated
= NULL
;
2297 wnd
->SetHWND((WXHWND
)hWnd
);
2302 if ( wnd
&& wxEventLoop::AllowProcessing(wnd
) )
2303 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2305 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2310 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2312 // did we process the message?
2313 bool processed
= false;
2323 // for most messages we should return 0 when we do process the message
2331 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2334 // return 0 to allow window creation
2335 rc
.result
= mayCreate
? 0 : -1;
2341 // never set processed to true and *always* pass WM_DESTROY to
2342 // DefWindowProc() as Windows may do some internal cleanup when
2343 // processing it and failing to pass the message along may cause
2344 // memory and resource leaks!
2345 (void)HandleDestroy();
2349 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2353 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2356 #if !defined(__WXWINCE__)
2359 LPRECT pRect
= (LPRECT
)lParam
;
2361 rc
.SetLeft(pRect
->left
);
2362 rc
.SetTop(pRect
->top
);
2363 rc
.SetRight(pRect
->right
);
2364 rc
.SetBottom(pRect
->bottom
);
2365 processed
= HandleMoving(rc
);
2367 pRect
->left
= rc
.GetLeft();
2368 pRect
->top
= rc
.GetTop();
2369 pRect
->right
= rc
.GetRight();
2370 pRect
->bottom
= rc
.GetBottom();
2377 LPRECT pRect
= (LPRECT
)lParam
;
2379 rc
.SetLeft(pRect
->left
);
2380 rc
.SetTop(pRect
->top
);
2381 rc
.SetRight(pRect
->right
);
2382 rc
.SetBottom(pRect
->bottom
);
2383 processed
= HandleSizing(rc
);
2385 pRect
->left
= rc
.GetLeft();
2386 pRect
->top
= rc
.GetTop();
2387 pRect
->right
= rc
.GetRight();
2388 pRect
->bottom
= rc
.GetBottom();
2392 #endif // !__WXWINCE__
2394 #if !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
2395 case WM_WINDOWPOSCHANGED
:
2397 WINDOWPOS
*lpPos
= (WINDOWPOS
*)lParam
;
2399 if ( !(lpPos
->flags
& SWP_NOSIZE
) )
2402 ::GetClientRect(GetHwnd(), &rc
);
2404 AutoHRGN
hrgnClient(::CreateRectRgnIndirect(&rc
));
2405 AutoHRGN
hrgnNew(::CreateRectRgn(lpPos
->x
, lpPos
->y
,
2406 lpPos
->cx
, lpPos
->cy
));
2408 // we need to invalidate any new exposed areas here
2409 // to force them to repaint
2410 if ( ::CombineRgn(hrgnNew
, hrgnNew
, hrgnClient
, RGN_DIFF
) != NULLREGION
)
2411 ::InvalidateRgn(GetHwnd(), hrgnNew
, TRUE
);
2416 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2417 case WM_ACTIVATEAPP
:
2418 // This implicitly sends a wxEVT_ACTIVATE_APP event
2419 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2425 WXWORD state
, minimized
;
2427 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2429 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2434 processed
= HandleSetFocus((WXHWND
)(HWND
)wParam
);
2438 processed
= HandleKillFocus((WXHWND
)(HWND
)wParam
);
2441 case WM_PRINTCLIENT
:
2442 processed
= HandlePrintClient((WXHDC
)wParam
);
2448 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2450 processed
= HandlePaint();
2454 processed
= HandlePaint();
2459 #ifdef __WXUNIVERSAL__
2460 // Universal uses its own wxFrame/wxDialog, so we don't receive
2461 // close events unless we have this.
2463 #endif // __WXUNIVERSAL__
2465 // don't let the DefWindowProc() destroy our window - we'll do it
2466 // ourselves in ~wxWindow
2472 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2476 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2477 GET_Y_LPARAM(lParam
),
2481 #ifdef HAVE_TRACKMOUSEEVENT
2483 // filter out excess WM_MOUSELEAVE events sent after PopupMenu() (on XP at least)
2484 if ( m_mouseInWindow
)
2486 GenerateMouseLeave();
2489 // always pass processed back as false, this allows the window
2490 // manager to process the message too. This is needed to
2491 // ensure windows XP themes work properly as the mouse moves
2492 // over widgets like buttons. So don't set processed to true here.
2494 #endif // HAVE_TRACKMOUSEEVENT
2496 #if wxUSE_MOUSEWHEEL
2498 processed
= HandleMouseWheel(wParam
, lParam
);
2502 case WM_LBUTTONDOWN
:
2504 case WM_LBUTTONDBLCLK
:
2505 case WM_RBUTTONDOWN
:
2507 case WM_RBUTTONDBLCLK
:
2508 case WM_MBUTTONDOWN
:
2510 case WM_MBUTTONDBLCLK
:
2512 #ifdef __WXMICROWIN__
2513 // MicroWindows seems to ignore the fact that a window is
2514 // disabled. So catch mouse events and throw them away if
2516 wxWindowMSW
* win
= this;
2519 if (!win
->IsEnabled())
2525 win
= win
->GetParent();
2526 if ( !win
|| win
->IsTopLevel() )
2533 #endif // __WXMICROWIN__
2534 int x
= GET_X_LPARAM(lParam
),
2535 y
= GET_Y_LPARAM(lParam
);
2538 // redirect the event to a static control if necessary by
2539 // finding one under mouse because under CE the static controls
2540 // don't generate mouse events (even with SS_NOTIFY)
2542 if ( GetCapture() == this )
2544 // but don't do it if the mouse is captured by this window
2545 // because then it should really get this event itself
2550 win
= FindWindowForMouseEvent(this, &x
, &y
);
2552 // this should never happen
2553 wxCHECK_MSG( win
, 0,
2554 _T("FindWindowForMouseEvent() returned NULL") );
2556 #else // !__WXWINCE__
2557 wxWindowMSW
*win
= this;
2558 #endif // __WXWINCE__/!__WXWINCE__
2560 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2562 // if the app didn't eat the event, handle it in the default
2563 // way, that is by giving this window the focus
2566 // for the standard classes their WndProc sets the focus to
2567 // them anyhow and doing it from here results in some weird
2568 // problems, so don't do it for them (unnecessary anyhow)
2569 if ( !win
->IsOfStandardClass() )
2571 if ( message
== WM_LBUTTONDOWN
&& win
->AcceptsFocus() )
2583 case MM_JOY1BUTTONDOWN
:
2584 case MM_JOY2BUTTONDOWN
:
2585 case MM_JOY1BUTTONUP
:
2586 case MM_JOY2BUTTONUP
:
2587 processed
= HandleJoystickEvent(message
,
2588 GET_X_LPARAM(lParam
),
2589 GET_Y_LPARAM(lParam
),
2592 #endif // __WXMICROWIN__
2598 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2600 processed
= HandleCommand(id
, cmd
, hwnd
);
2605 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2608 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
2609 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
2610 // apparently doesn't always behave properly and needs some help
2611 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
2612 case WM_NOTIFYFORMAT
:
2613 if ( lParam
== NF_QUERY
)
2616 rc
.result
= NFR_UNICODE
;
2619 #endif // wxUSE_UNICODE_MSLU
2621 // for these messages we must return true if process the message
2624 case WM_MEASUREITEM
:
2626 int idCtrl
= (UINT
)wParam
;
2627 if ( message
== WM_DRAWITEM
)
2629 processed
= MSWOnDrawItem(idCtrl
,
2630 (WXDRAWITEMSTRUCT
*)lParam
);
2634 processed
= MSWOnMeasureItem(idCtrl
,
2635 (WXMEASUREITEMSTRUCT
*)lParam
);
2642 #endif // defined(WM_DRAWITEM)
2645 if ( !IsOfStandardClass() )
2647 // we always want to get the char events
2648 rc
.result
= DLGC_WANTCHARS
;
2650 if ( GetWindowStyleFlag() & wxWANTS_CHARS
)
2652 // in fact, we want everything
2653 rc
.result
|= DLGC_WANTARROWS
|
2660 //else: get the dlg code from the DefWindowProc()
2665 // If this has been processed by an event handler, return 0 now
2666 // (we've handled it).
2667 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
2668 if ( m_lastKeydownProcessed
)
2677 // we consider these message "not interesting" to OnChar, so
2678 // just don't do anything more with them
2688 // avoid duplicate messages to OnChar for these ASCII keys:
2689 // they will be translated by TranslateMessage() and received
2711 // but set processed to false, not true to still pass them
2712 // to the control's default window proc - otherwise
2713 // built-in keyboard handling won't work
2718 // special case of VK_APPS: treat it the same as right mouse
2719 // click because both usually pop up a context menu
2721 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
2726 // do generate a CHAR event
2727 processed
= HandleChar((WORD
)wParam
, lParam
);
2730 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
2737 // special case of VK_APPS: treat it the same as right mouse button
2738 if ( wParam
== VK_APPS
)
2740 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
2745 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
2750 case WM_CHAR
: // Always an ASCII character
2751 if ( m_lastKeydownProcessed
)
2753 // The key was handled in the EVT_KEY_DOWN and handling
2754 // a key in an EVT_KEY_DOWN handler is meant, by
2755 // design, to prevent EVT_CHARs from happening
2756 m_lastKeydownProcessed
= false;
2761 processed
= HandleChar((WORD
)wParam
, lParam
, true);
2767 processed
= HandleHotKey((WORD
)wParam
, lParam
);
2769 #endif // wxUSE_HOTKEY
2776 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
2778 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
2784 // CTLCOLOR messages are sent by children to query the parent for their
2786 #ifndef __WXMICROWIN__
2787 case WM_CTLCOLORMSGBOX
:
2788 case WM_CTLCOLOREDIT
:
2789 case WM_CTLCOLORLISTBOX
:
2790 case WM_CTLCOLORBTN
:
2791 case WM_CTLCOLORDLG
:
2792 case WM_CTLCOLORSCROLLBAR
:
2793 case WM_CTLCOLORSTATIC
:
2797 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
2799 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
2802 #endif // !__WXMICROWIN__
2804 case WM_SYSCOLORCHANGE
:
2805 // the return value for this message is ignored
2806 processed
= HandleSysColorChange();
2809 #if !defined(__WXWINCE__)
2810 case WM_DISPLAYCHANGE
:
2811 processed
= HandleDisplayChange();
2815 case WM_PALETTECHANGED
:
2816 processed
= HandlePaletteChanged((WXHWND
) (HWND
) wParam
);
2819 case WM_CAPTURECHANGED
:
2820 processed
= HandleCaptureChanged((WXHWND
) (HWND
) lParam
);
2823 case WM_QUERYNEWPALETTE
:
2824 processed
= HandleQueryNewPalette();
2828 processed
= HandleEraseBkgnd((WXHDC
)(HDC
)wParam
);
2831 // we processed the message, i.e. erased the background
2836 #if !defined(__WXWINCE__)
2838 processed
= HandleDropFiles(wParam
);
2843 processed
= HandleInitDialog((WXHWND
)(HWND
)wParam
);
2847 // we never set focus from here
2852 #if !defined(__WXWINCE__)
2853 case WM_QUERYENDSESSION
:
2854 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
2858 processed
= HandleEndSession(wParam
!= 0, lParam
);
2861 case WM_GETMINMAXINFO
:
2862 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
2867 processed
= HandleSetCursor((WXHWND
)(HWND
)wParam
,
2868 LOWORD(lParam
), // hit test
2869 HIWORD(lParam
)); // mouse msg
2873 // returning TRUE stops the DefWindowProc() from further
2874 // processing this message - exactly what we need because we've
2875 // just set the cursor.
2880 #if wxUSE_ACCESSIBILITY
2883 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
2884 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
2886 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
2888 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
2894 #if defined(WM_HELP)
2897 // HELPINFO doesn't seem to be supported on WinCE.
2899 HELPINFO
* info
= (HELPINFO
*) lParam
;
2900 // Don't yet process menu help events, just windows
2901 if (info
->iContextType
== HELPINFO_WINDOW
)
2904 wxWindowMSW
* subjectOfHelp
= this;
2905 bool eventProcessed
= false;
2906 while (subjectOfHelp
&& !eventProcessed
)
2908 wxHelpEvent
helpEvent(wxEVT_HELP
,
2909 subjectOfHelp
->GetId(),
2913 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
2917 helpEvent
.SetEventObject(this);
2919 GetEventHandler()->ProcessEvent(helpEvent
);
2921 // Go up the window hierarchy until the event is
2923 subjectOfHelp
= subjectOfHelp
->GetParent();
2926 processed
= eventProcessed
;
2929 else if (info
->iContextType
== HELPINFO_MENUITEM
)
2931 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
2932 helpEvent
.SetEventObject(this);
2933 processed
= GetEventHandler()->ProcessEvent(helpEvent
);
2936 //else: processed is already false
2942 #if !defined(__WXWINCE__)
2943 case WM_CONTEXTMENU
:
2945 // we don't convert from screen to client coordinates as
2946 // the event may be handled by a parent window
2947 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2949 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2951 // we could have got an event from our child, reflect it back
2952 // to it if this is the case
2953 wxWindowMSW
*win
= NULL
;
2954 if ( (WXHWND
)wParam
!= m_hWnd
)
2956 win
= FindItemByHWND((WXHWND
)wParam
);
2962 evtCtx
.SetEventObject(win
);
2963 processed
= win
->GetEventHandler()->ProcessEvent(evtCtx
);
2969 // we're only interested in our own menus, not MF_SYSMENU
2970 if ( HIWORD(wParam
) == MF_POPUP
)
2972 // handle menu chars for ownerdrawn menu items
2973 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
2974 if ( i
!= wxNOT_FOUND
)
2976 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
2986 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
2987 wxGetMessageName(message
));
2988 #endif // __WXDEBUG__
2989 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
2995 // ----------------------------------------------------------------------------
2996 // wxWindow <-> HWND map
2997 // ----------------------------------------------------------------------------
2999 wxWinHashTable
*wxWinHandleHash
= NULL
;
3001 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
3003 return (wxWindow
*)wxWinHandleHash
->Get((long)hWnd
);
3006 void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
)
3008 // adding NULL hWnd is (first) surely a result of an error and
3009 // (secondly) breaks menu command processing
3010 wxCHECK_RET( hWnd
!= (HWND
)NULL
,
3011 wxT("attempt to add a NULL hWnd to window list ignored") );
3013 wxWindow
*oldWin
= wxFindWinFromHandle((WXHWND
) hWnd
);
3015 if ( oldWin
&& (oldWin
!= win
) )
3017 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
3018 (int) hWnd
, win
->GetClassInfo()->GetClassName());
3021 #endif // __WXDEBUG__
3024 wxWinHandleHash
->Put((long)hWnd
, (wxWindow
*)win
);
3028 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3030 wxWinHandleHash
->Delete((long)win
->GetHWND());
3033 // ----------------------------------------------------------------------------
3034 // various MSW speciic class dependent functions
3035 // ----------------------------------------------------------------------------
3037 // Default destroyer - override if you destroy it in some other way
3038 // (e.g. with MDI child windows)
3039 void wxWindowMSW::MSWDestroyWindow()
3043 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3046 int& w
, int& h
) const
3048 // yes, those are just some arbitrary hardcoded numbers
3049 static const int DEFAULT_Y
= 200;
3051 bool nonDefault
= false;
3053 if ( pos
.x
== wxDefaultCoord
)
3055 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
3056 // can just as well set it to CW_USEDEFAULT as well
3062 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
3063 // neither because it is not handled as a special value by Windows then
3064 // and so we have to choose some default value for it
3066 y
= pos
.y
== wxDefaultCoord
? DEFAULT_Y
: pos
.y
;
3072 NB: there used to be some code here which set the initial size of the
3073 window to the client size of the parent if no explicit size was
3074 specified. This was wrong because wxWidgets programs often assume
3075 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3076 it. To see why, you should understand that Windows sends WM_SIZE from
3077 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3078 from some base class ctor and so this WM_SIZE is not processed in the
3079 real class' OnSize() (because it's not fully constructed yet and the
3080 event goes to some base class OnSize() instead). So the WM_SIZE we
3081 rely on is the one sent when the parent frame resizes its children
3082 but here is the problem: if the child already has just the right
3083 size, nothing will happen as both wxWidgets and Windows check for
3084 this and ignore any attempts to change the window size to the size it
3085 already has - so no WM_SIZE would be sent.
3089 // we don't use CW_USEDEFAULT here for several reasons:
3091 // 1. it results in huge frames on modern screens (1000*800 is not
3092 // uncommon on my 1280*1024 screen) which is way too big for a half
3093 // empty frame of most of wxWidgets samples for example)
3095 // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
3096 // the default is for whatever reason 8*8 which breaks client <->
3097 // window size calculations (it would be nice if it didn't, but it
3098 // does and the simplest way to fix it seemed to change the broken
3099 // default size anyhow)
3101 // 3. there is just no advantage in doing it: with x and y it is
3102 // possible that [future versions of] Windows position the new top
3103 // level window in some smart way which we can't do, but we can
3104 // guess a reasonably good size for a new window just as well
3107 // However, on PocketPC devices, we must use the default
3108 // size if possible.
3110 if (size
.x
== wxDefaultCoord
)
3114 if (size
.y
== wxDefaultCoord
)
3119 if ( size
.x
== wxDefaultCoord
|| size
.y
== wxDefaultCoord
)
3123 w
= WidthDefault(size
.x
);
3124 h
= HeightDefault(size
.y
);
3127 AdjustForParentClientOrigin(x
, y
);
3132 WXHWND
wxWindowMSW::MSWGetParent() const
3134 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3137 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3138 const wxChar
*title
,
3142 WXDWORD extendedStyle
)
3144 // choose the position/size for the new window
3146 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3148 // controlId is menu handle for the top level windows, so set it to 0
3149 // unless we're creating a child window
3150 int controlId
= style
& WS_CHILD
? GetId() : 0;
3152 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3153 // which is the same but without CS_[HV]REDRAW class styles so using it
3154 // ensures that the window is not fully repainted on each resize
3155 wxString
className(wclass
);
3156 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3158 className
+= wxT("NR");
3161 // do create the window
3162 wxWindowCreationHook
hook(this);
3164 m_hWnd
= (WXHWND
)::CreateWindowEx
3168 title
? title
: m_windowName
.c_str(),
3171 (HWND
)MSWGetParent(),
3174 NULL
// no extra data
3179 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3184 SubclassWin(m_hWnd
);
3189 // ===========================================================================
3190 // MSW message handlers
3191 // ===========================================================================
3193 // ---------------------------------------------------------------------------
3195 // ---------------------------------------------------------------------------
3199 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3201 #ifndef __WXMICROWIN__
3202 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3203 HWND hWnd
= hdr
->hwndFrom
;
3204 wxWindow
*win
= wxFindWinFromHandle((WXHWND
)hWnd
);
3206 // if the control is one of our windows, let it handle the message itself
3209 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3212 // VZ: why did we do it? normally this is unnecessary and, besides, it
3213 // breaks the message processing for the toolbars because the tooltip
3214 // notifications were being forwarded to the toolbar child controls
3215 // (if it had any) before being passed to the toolbar itself, so in my
3216 // example the tooltip for the combobox was always shown instead of the
3217 // correct button tooltips
3219 // try all our children
3220 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3223 wxWindow
*child
= node
->GetData();
3224 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3229 node
= node
->GetNext();
3233 // by default, handle it ourselves
3234 return MSWOnNotify(idCtrl
, lParam
, result
);
3235 #else // __WXMICROWIN__
3242 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3244 const wxString
& ttip
)
3246 // I don't know why it happens, but the versions of comctl32.dll starting
3247 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3248 // this message is supposed to be sent to Unicode programs only) -- hence
3249 // we need to handle it as well, otherwise no tooltips will be shown in
3252 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3255 // not a tooltip message or no tooltip to show anyhow
3260 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3262 // We don't want to use the szText buffer because it has a limit of 80
3263 // bytes and this is not enough, especially for Unicode build where it
3264 // limits the tooltip string length to only 40 characters
3266 // The best would be, of course, to not impose any length limitations at
3267 // all but then the buffer would have to be dynamic and someone would have
3268 // to free it and we don't have the tooltip owner object here any more, so
3269 // for now use our own static buffer with a higher fixed max length.
3271 // Note that using a static buffer should not be a problem as only a single
3272 // tooltip can be shown at the same time anyhow.
3274 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3276 // We need to convert tooltip from multi byte to Unicode on the fly.
3277 static wchar_t buf
[513];
3279 // Truncate tooltip length if needed as otherwise we might not have
3280 // enough space for it in the buffer and MultiByteToWideChar() would
3282 size_t tipLength
= wxMin(ttip
.Len(), WXSIZEOF(buf
) - 1);
3284 // Convert to WideChar without adding the NULL character. The NULL
3285 // character is added afterwards (this is more efficient).
3286 int len
= ::MultiByteToWideChar
3298 wxLogLastError(_T("MultiByteToWideChar()"));
3302 ttText
->lpszText
= (LPSTR
) buf
;
3304 else // TTN_NEEDTEXTA
3305 #endif // !wxUSE_UNICODE
3307 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3308 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3309 // to copy the string we have into the buffer
3310 static wxChar buf
[513];
3311 wxStrncpy(buf
, ttip
.c_str(), WXSIZEOF(buf
) - 1);
3312 buf
[WXSIZEOF(buf
) - 1] = _T('\0');
3313 ttText
->lpszText
= buf
;
3319 #endif // wxUSE_TOOLTIPS
3321 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3323 WXLPARAM
* WXUNUSED(result
))
3328 NMHDR
* hdr
= (NMHDR
*)lParam
;
3329 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3336 wxUnusedVar(lParam
);
3337 #endif // wxUSE_TOOLTIPS
3344 // ---------------------------------------------------------------------------
3345 // end session messages
3346 // ---------------------------------------------------------------------------
3348 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3350 #ifdef ENDSESSION_LOGOFF
3351 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3352 event
.SetEventObject(wxTheApp
);
3353 event
.SetCanVeto(true);
3354 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3356 bool rc
= wxTheApp
->ProcessEvent(event
);
3360 // we may end only if the app didn't veto session closing (double
3362 *mayEnd
= !event
.GetVeto();
3367 wxUnusedVar(logOff
);
3368 wxUnusedVar(mayEnd
);
3373 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3375 #ifdef ENDSESSION_LOGOFF
3376 // do nothing if the session isn't ending
3381 if ( (this != wxTheApp
->GetTopWindow()) )
3384 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3385 event
.SetEventObject(wxTheApp
);
3386 event
.SetCanVeto(false);
3387 event
.SetLoggingOff( (logOff
== (long)ENDSESSION_LOGOFF
) );
3389 return wxTheApp
->ProcessEvent(event
);
3391 wxUnusedVar(endSession
);
3392 wxUnusedVar(logOff
);
3397 // ---------------------------------------------------------------------------
3398 // window creation/destruction
3399 // ---------------------------------------------------------------------------
3401 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3404 // VZ: why is this commented out for WinCE? If it doesn't support
3405 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3406 // not with multiple #ifdef's!
3408 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3409 EnsureParentHasControlParentStyle(GetParent());
3410 #endif // !__WXWINCE__
3412 // TODO: should generate this event from WM_NCCREATE
3413 wxWindowCreateEvent
event((wxWindow
*)this);
3414 (void)GetEventHandler()->ProcessEvent(event
);
3421 bool wxWindowMSW::HandleDestroy()
3425 // delete our drop target if we've got one
3426 #if wxUSE_DRAG_AND_DROP
3427 if ( m_dropTarget
!= NULL
)
3429 m_dropTarget
->Revoke(m_hWnd
);
3431 delete m_dropTarget
;
3432 m_dropTarget
= NULL
;
3434 #endif // wxUSE_DRAG_AND_DROP
3436 // WM_DESTROY handled
3440 // ---------------------------------------------------------------------------
3442 // ---------------------------------------------------------------------------
3444 bool wxWindowMSW::HandleActivate(int state
,
3445 bool WXUNUSED(minimized
),
3446 WXHWND
WXUNUSED(activate
))
3448 wxActivateEvent
event(wxEVT_ACTIVATE
,
3449 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3451 event
.SetEventObject(this);
3453 return GetEventHandler()->ProcessEvent(event
);
3456 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3458 // Strangly enough, some controls get set focus events when they are being
3459 // deleted, even if they already had focus before.
3460 if ( m_isBeingDeleted
)
3465 // notify the parent keeping track of focus for the kbd navigation
3466 // purposes that we got it
3467 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3468 (void)GetEventHandler()->ProcessEvent(eventFocus
);
3474 m_caret
->OnSetFocus();
3476 #endif // wxUSE_CARET
3479 // If it's a wxTextCtrl don't send the event as it will be done
3480 // after the control gets to process it from EN_FOCUS handler
3481 if ( wxDynamicCastThis(wxTextCtrl
) )
3485 #endif // wxUSE_TEXTCTRL
3487 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3488 event
.SetEventObject(this);
3490 // wxFindWinFromHandle() may return NULL, it is ok
3491 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3493 return GetEventHandler()->ProcessEvent(event
);
3496 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
3502 m_caret
->OnKillFocus();
3504 #endif // wxUSE_CARET
3507 // If it's a wxTextCtrl don't send the event as it will be done
3508 // after the control gets to process it.
3509 wxTextCtrl
*ctrl
= wxDynamicCastThis(wxTextCtrl
);
3516 // Don't send the event when in the process of being deleted. This can
3517 // only cause problems if the event handler tries to access the object.
3518 if ( m_isBeingDeleted
)
3523 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3524 event
.SetEventObject(this);
3526 // wxFindWinFromHandle() may return NULL, it is ok
3527 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3529 return GetEventHandler()->ProcessEvent(event
);
3532 // ---------------------------------------------------------------------------
3534 // ---------------------------------------------------------------------------
3536 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
3538 wxShowEvent
event(GetId(), show
);
3539 event
.SetEventObject(this);
3541 return GetEventHandler()->ProcessEvent(event
);
3544 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
3546 wxInitDialogEvent
event(GetId());
3547 event
.SetEventObject(this);
3549 return GetEventHandler()->ProcessEvent(event
);
3552 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
3554 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
3555 wxUnusedVar(wParam
);
3557 #else // __WXMICROWIN__
3558 HDROP hFilesInfo
= (HDROP
) wParam
;
3560 // Get the total number of files dropped
3561 UINT gwFilesDropped
= ::DragQueryFile
3569 wxString
*files
= new wxString
[gwFilesDropped
];
3570 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
3572 // first get the needed buffer length (+1 for terminating NUL)
3573 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
3575 // and now get the file name
3576 ::DragQueryFile(hFilesInfo
, wIndex
,
3577 wxStringBuffer(files
[wIndex
], len
), len
);
3579 DragFinish (hFilesInfo
);
3581 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
3582 event
.SetEventObject(this);
3585 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
3586 event
.m_pos
.x
= dropPoint
.x
;
3587 event
.m_pos
.y
= dropPoint
.y
;
3589 return GetEventHandler()->ProcessEvent(event
);
3594 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
3596 int WXUNUSED(mouseMsg
))
3598 #ifndef __WXMICROWIN__
3599 // the logic is as follows:
3600 // -1. don't set cursor for non client area, including but not limited to
3601 // the title bar, scrollbars, &c
3602 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
3603 // 1. if we have the cursor set it unless wxIsBusy()
3604 // 2. if we're a top level window, set some cursor anyhow
3605 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
3607 if ( nHitTest
!= HTCLIENT
)
3612 HCURSOR hcursor
= 0;
3614 // first ask the user code - it may wish to set the cursor in some very
3615 // specific way (for example, depending on the current position)
3618 if ( !::GetCursorPosWinCE(&pt
))
3620 if ( !::GetCursorPos(&pt
) )
3623 wxLogLastError(wxT("GetCursorPos"));
3628 ScreenToClient(&x
, &y
);
3629 wxSetCursorEvent
event(x
, y
);
3631 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
3632 if ( processedEvtSetCursor
&& event
.HasCursor() )
3634 hcursor
= GetHcursorOf(event
.GetCursor());
3639 bool isBusy
= wxIsBusy();
3641 // the test for processedEvtSetCursor is here to prevent using m_cursor
3642 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3643 // it - this is a way to say that our cursor shouldn't be used for this
3645 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
3647 hcursor
= GetHcursorOf(m_cursor
);
3654 hcursor
= wxGetCurrentBusyCursor();
3656 else if ( !hcursor
)
3658 const wxCursor
*cursor
= wxGetGlobalCursor();
3659 if ( cursor
&& cursor
->Ok() )
3661 hcursor
= GetHcursorOf(*cursor
);
3669 // wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3671 ::SetCursor(hcursor
);
3673 // cursor set, stop here
3676 #endif // __WXMICROWIN__
3678 // pass up the window chain
3682 // ---------------------------------------------------------------------------
3683 // owner drawn stuff
3684 // ---------------------------------------------------------------------------
3686 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
3687 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
3688 #define WXUNUSED_UNLESS_ODRAWN(param) param
3690 #define WXUNUSED_UNLESS_ODRAWN(param)
3694 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
3695 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
3697 #if wxUSE_OWNER_DRAWN
3699 #if wxUSE_MENUS_NATIVE
3700 // is it a menu item?
3701 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
3702 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
3704 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
3706 // see comment before the same test in MSWOnMeasureItem() below
3710 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
3711 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
3713 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
3714 // the DC from being released
3715 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
3716 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
3717 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
3718 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
3720 return pMenuItem
->OnDrawItem
3724 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
3725 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
3728 #endif // wxUSE_MENUS_NATIVE
3730 #endif // USE_OWNER_DRAWN
3732 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
3734 #if wxUSE_OWNER_DRAWN
3735 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3736 #else // !wxUSE_OWNER_DRAWN
3737 // we may still have owner-drawn buttons internally because we have to make
3738 // them owner-drawn to support colour change
3741 wxDynamicCast(FindItem(id
), wxButton
)
3746 #endif // USE_OWNER_DRAWN
3750 return item
->MSWOnDraw(itemStruct
);
3753 #endif // wxUSE_CONTROLS
3759 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
3761 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
3762 // is it a menu item?
3763 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
3764 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
3766 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
3768 // according to Carsten Fuchs the pointer may be NULL under XP if an
3769 // MDI child frame is initially maximized, see this for more info:
3770 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
3772 // so silently ignore it instead of asserting
3776 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
3777 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
3780 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
3782 pMeasureStruct
->itemWidth
= w
;
3783 pMeasureStruct
->itemHeight
= h
;
3788 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3791 return item
->MSWOnMeasure(itemStruct
);
3795 wxUnusedVar(itemStruct
);
3796 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
3801 // ---------------------------------------------------------------------------
3802 // colours and palettes
3803 // ---------------------------------------------------------------------------
3805 bool wxWindowMSW::HandleSysColorChange()
3807 wxSysColourChangedEvent event
;
3808 event
.SetEventObject(this);
3810 (void)GetEventHandler()->ProcessEvent(event
);
3812 // always let the system carry on the default processing to allow the
3813 // native controls to react to the colours update
3817 bool wxWindowMSW::HandleDisplayChange()
3819 wxDisplayChangedEvent event
;
3820 event
.SetEventObject(this);
3822 return GetEventHandler()->ProcessEvent(event
);
3825 #ifndef __WXMICROWIN__
3827 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
3829 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
3833 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
3836 *brush
= item
->MSWControlColor(hDC
, hWnd
);
3838 #endif // wxUSE_CONTROLS
3841 return *brush
!= NULL
;
3844 #endif // __WXMICROWIN__
3846 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
3849 // same as below except we don't respond to our own messages
3850 if ( hWndPalChange
!= GetHWND() )
3852 // check to see if we our our parents have a custom palette
3853 wxWindowMSW
*win
= this;
3854 while ( win
&& !win
->HasCustomPalette() )
3856 win
= win
->GetParent();
3859 if ( win
&& win
->HasCustomPalette() )
3861 // realize the palette to see whether redrawing is needed
3862 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
3863 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
3864 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
3866 int result
= ::RealizePalette(hdc
);
3868 // restore the palette (before releasing the DC)
3869 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
3870 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
3871 ::RealizePalette(hdc
);
3872 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
3874 // now check for the need to redraw
3876 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
3880 #endif // wxUSE_PALETTE
3882 wxPaletteChangedEvent
event(GetId());
3883 event
.SetEventObject(this);
3884 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
3886 return GetEventHandler()->ProcessEvent(event
);
3889 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
3891 wxMouseCaptureChangedEvent
event(GetId(), wxFindWinFromHandle(hWndGainedCapture
));
3892 event
.SetEventObject(this);
3894 return GetEventHandler()->ProcessEvent(event
);
3897 bool wxWindowMSW::HandleQueryNewPalette()
3901 // check to see if we our our parents have a custom palette
3902 wxWindowMSW
*win
= this;
3903 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
3904 if (win
->HasCustomPalette()) {
3905 /* realize the palette to see whether redrawing is needed */
3906 HDC hdc
= ::GetDC((HWND
) GetHWND());
3907 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
3908 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
3910 int result
= ::RealizePalette(hdc
);
3911 /* restore the palette (before releasing the DC) */
3912 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
3913 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
3914 ::RealizePalette(hdc
);
3915 ::ReleaseDC((HWND
) GetHWND(), hdc
);
3916 /* now check for the need to redraw */
3918 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
3920 #endif // wxUSE_PALETTE
3922 wxQueryNewPaletteEvent
event(GetId());
3923 event
.SetEventObject(this);
3925 return GetEventHandler()->ProcessEvent(event
) && event
.GetPaletteRealized();
3928 // Responds to colour changes: passes event on to children.
3929 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
3931 // the top level window also reset the standard colour map as it might have
3932 // changed (there is no need to do it for the non top level windows as we
3933 // only have to do it once)
3937 gs_hasStdCmap
= false;
3939 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3942 // Only propagate to non-top-level windows because Windows already
3943 // sends this event to all top-level ones
3944 wxWindow
*win
= node
->GetData();
3945 if ( !win
->IsTopLevel() )
3947 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
3948 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
3949 // the standard controls
3950 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
3953 node
= node
->GetNext();
3957 extern wxCOLORMAP
*wxGetStdColourMap()
3959 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
3960 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
3962 if ( !gs_hasStdCmap
)
3964 static bool s_coloursInit
= false;
3966 if ( !s_coloursInit
)
3968 // When a bitmap is loaded, the RGB values can change (apparently
3969 // because Windows adjusts them to care for the old programs always
3970 // using 0xc0c0c0 while the transparent colour for the new Windows
3971 // versions is different). But we do this adjustment ourselves so
3972 // we want to avoid Windows' "help" and for this we need to have a
3973 // reference bitmap which can tell us what the RGB values change
3975 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
3976 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
3977 if ( stdColourBitmap
.Ok() )
3979 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
3980 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
3981 _T("forgot to update wxBITMAP_STD_COLOURS!") );
3984 memDC
.SelectObject(stdColourBitmap
);
3987 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
3989 memDC
.GetPixel(i
, 0, &colour
);
3990 s_stdColours
[i
] = wxColourToRGB(colour
);
3993 else // wxBITMAP_STD_COLOURS couldn't be loaded
3995 s_stdColours
[0] = RGB(000,000,000); // black
3996 s_stdColours
[1] = RGB(128,128,128); // dark grey
3997 s_stdColours
[2] = RGB(192,192,192); // light grey
3998 s_stdColours
[3] = RGB(255,255,255); // white
3999 //s_stdColours[4] = RGB(000,000,255); // blue
4000 //s_stdColours[5] = RGB(255,000,255); // magenta
4003 s_coloursInit
= true;
4006 gs_hasStdCmap
= true;
4008 // create the colour map
4009 #define INIT_CMAP_ENTRY(col) \
4010 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4011 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4013 INIT_CMAP_ENTRY(BTNTEXT
);
4014 INIT_CMAP_ENTRY(BTNSHADOW
);
4015 INIT_CMAP_ENTRY(BTNFACE
);
4016 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4018 #undef INIT_CMAP_ENTRY
4024 // ---------------------------------------------------------------------------
4026 // ---------------------------------------------------------------------------
4028 bool wxWindowMSW::HandlePaint()
4030 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4032 wxLogLastError(wxT("CreateRectRgn"));
4033 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4034 wxLogLastError(wxT("GetUpdateRgn"));
4036 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4038 wxPaintEvent
event(m_windowId
);
4039 event
.SetEventObject(this);
4041 bool processed
= GetEventHandler()->ProcessEvent(event
);
4043 // note that we must generate NC event after the normal one as otherwise
4044 // BeginPaint() will happily overwrite our decorations with the background
4046 wxNcPaintEvent
eventNc(m_windowId
);
4047 eventNc
.SetEventObject(this);
4048 GetEventHandler()->ProcessEvent(eventNc
);
4053 // Can be called from an application's OnPaint handler
4054 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4056 #ifdef __WXUNIVERSAL__
4059 HDC hDC
= (HDC
) wxPaintDC::FindDCInCache((wxWindow
*) event
.GetEventObject());
4062 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4067 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4072 dc
.SetWindow((wxWindow
*)this);
4075 wxEraseEvent
event(m_windowId
, &dc
);
4076 event
.SetEventObject(this);
4077 bool rc
= GetEventHandler()->ProcessEvent(event
);
4081 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
4082 dc
.SelectOldObjects(hdc
);
4087 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
4089 // standard non top level controls (i.e. except the dialogs) always erase
4090 // their background themselves in HandleCtlColor() or have some control-
4091 // specific ways to set the colours (common controls)
4092 if ( IsOfStandardClass() && !IsTopLevel() )
4098 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
4100 // don't skip the event here, custom background means that the app
4101 // is drawing it itself in its OnPaint(), so don't draw it at all
4102 // now to avoid flicker
4107 // do default background painting
4108 if ( !DoEraseBackground(GetHdcOf(*event
.GetDC())) )
4110 // let the system paint the background
4115 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4117 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4121 wxFillRect(GetHwnd(), (HDC
)hDC
, hbr
);
4127 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
), WXHWND hWnd
)
4131 // our background colour applies to:
4132 // 1. this window itself, always
4133 // 2. all children unless the colour is "not inheritable"
4134 // 3. even if it is not inheritable, our immediate transparent
4135 // children should still inherit it -- but not any transparent
4136 // children because it would look wrong if a child of non
4137 // transparent child would show our bg colour when the child itself
4139 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
4142 (win
&& win
->HasTransparentBackground() &&
4143 win
->GetParent() == this) )
4145 // draw children with the same colour as the parent
4147 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4149 return (WXHBRUSH
)GetHbrushOf(*brush
);
4156 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
, WXHWND hWndToPaint
)
4159 hWndToPaint
= GetHWND();
4161 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4163 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, hWndToPaint
);
4167 // background is not inherited beyond top level windows
4168 if ( win
->IsTopLevel() )
4175 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4177 // we receive this message when DrawThemeParentBackground() is
4178 // called from def window proc of several controls under XP and we
4179 // must draw properly themed background here
4181 // note that naively I'd expect filling the client rect with the
4182 // brush returned by MSWGetBgBrush() work -- but for some reason it
4183 // doesn't and we have to call parents MSWPrintChild() which is
4184 // supposed to call DrawThemeBackground() with appropriate params
4186 // also note that in this case lParam == PRF_CLIENT but we're
4187 // clearly expected to paint the background and nothing else!
4189 if ( IsTopLevel() || InheritsBackgroundColour() )
4192 // sometimes we don't want the parent to handle it at all, instead
4193 // return whatever value this window wants
4194 if ( !MSWShouldPropagatePrintChild() )
4195 return MSWPrintChild(hDC
, (wxWindow
*)this);
4197 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4199 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4202 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4209 // ---------------------------------------------------------------------------
4210 // moving and resizing
4211 // ---------------------------------------------------------------------------
4213 bool wxWindowMSW::HandleMinimize()
4215 wxIconizeEvent
event(m_windowId
);
4216 event
.SetEventObject(this);
4218 return GetEventHandler()->ProcessEvent(event
);
4221 bool wxWindowMSW::HandleMaximize()
4223 wxMaximizeEvent
event(m_windowId
);
4224 event
.SetEventObject(this);
4226 return GetEventHandler()->ProcessEvent(event
);
4229 bool wxWindowMSW::HandleMove(int x
, int y
)
4232 wxMoveEvent
event(point
, m_windowId
);
4233 event
.SetEventObject(this);
4235 return GetEventHandler()->ProcessEvent(event
);
4238 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
4240 wxMoveEvent
event(rect
, m_windowId
);
4241 event
.SetEventObject(this);
4243 bool rc
= GetEventHandler()->ProcessEvent(event
);
4245 rect
= event
.GetRect();
4249 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
4251 #if USE_DEFERRED_SIZING
4252 // when we resize this window, its children are probably going to be
4253 // repositioned as well, prepare to use DeferWindowPos() for them
4254 int numChildren
= 0;
4255 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
4257 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
4262 // Protect against valid m_hDWP being overwritten
4263 bool useDefer
= false;
4265 if ( numChildren
> 1 )
4269 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
4272 wxLogLastError(_T("BeginDeferWindowPos"));
4278 #endif // USE_DEFERRED_SIZING
4280 // update this window size
4281 bool processed
= false;
4285 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4286 // fall through nevertheless
4290 // we're not interested in these messages at all
4293 case SIZE_MINIMIZED
:
4294 processed
= HandleMinimize();
4297 case SIZE_MAXIMIZED
:
4298 /* processed = */ HandleMaximize();
4299 // fall through to send a normal size event as well
4302 // don't use w and h parameters as they specify the client size
4303 // while according to the docs EVT_SIZE handler is supposed to
4304 // receive the total size
4305 wxSizeEvent
event(GetSize(), m_windowId
);
4306 event
.SetEventObject(this);
4308 processed
= GetEventHandler()->ProcessEvent(event
);
4311 #if USE_DEFERRED_SIZING
4312 // and finally change the positions of all child windows at once
4313 if ( useDefer
&& m_hDWP
)
4315 // reset m_hDWP to NULL so that child windows don't try to use our
4316 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4317 // happen anyhow normally but who knows what weird flow of control we
4318 // may have depending on what the users EVT_SIZE handler does...)
4319 HDWP hDWP
= (HDWP
)m_hDWP
;
4322 // do put all child controls in place at once
4323 if ( !::EndDeferWindowPos(hDWP
) )
4325 wxLogLastError(_T("EndDeferWindowPos"));
4328 // Reset our children's pending pos/size values.
4329 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4331 node
= node
->GetNext() )
4333 wxWindowMSW
*child
= node
->GetData();
4334 child
->m_pendingPosition
= wxDefaultPosition
;
4335 child
->m_pendingSize
= wxDefaultSize
;
4338 #endif // USE_DEFERRED_SIZING
4343 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
4345 wxSizeEvent
event(rect
, m_windowId
);
4346 event
.SetEventObject(this);
4348 bool rc
= GetEventHandler()->ProcessEvent(event
);
4350 rect
= event
.GetRect();
4354 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
4359 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
4363 int minWidth
= GetMinWidth(),
4364 minHeight
= GetMinHeight(),
4365 maxWidth
= GetMaxWidth(),
4366 maxHeight
= GetMaxHeight();
4368 if ( minWidth
!= wxDefaultCoord
)
4370 info
->ptMinTrackSize
.x
= minWidth
;
4374 if ( minHeight
!= wxDefaultCoord
)
4376 info
->ptMinTrackSize
.y
= minHeight
;
4380 if ( maxWidth
!= wxDefaultCoord
)
4382 info
->ptMaxTrackSize
.x
= maxWidth
;
4386 if ( maxHeight
!= wxDefaultCoord
)
4388 info
->ptMaxTrackSize
.y
= maxHeight
;
4396 // ---------------------------------------------------------------------------
4398 // ---------------------------------------------------------------------------
4400 bool wxWindowMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
4402 #if wxUSE_MENUS_NATIVE
4403 if ( !cmd
&& wxCurrentPopupMenu
)
4405 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
4406 wxCurrentPopupMenu
= NULL
;
4408 return popupMenu
->MSWCommand(cmd
, id
);
4410 #endif // wxUSE_MENUS_NATIVE
4412 wxWindow
*win
= NULL
;
4414 // first try to find it from HWND - this works even with the broken
4415 // programs using the same ids for different controls
4418 win
= wxFindWinFromHandle(control
);
4424 // must cast to a signed type before comparing with other ids!
4425 win
= FindItem((signed short)id
);
4430 return win
->MSWCommand(cmd
, id
);
4433 // the messages sent from the in-place edit control used by the treectrl
4434 // for label editing have id == 0, but they should _not_ be treated as menu
4435 // messages (they are EN_XXX ones, in fact) so don't translate anything
4436 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4439 // If no child window, it may be an accelerator, e.g. for a popup menu
4442 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
4443 event
.SetEventObject(this);
4447 return GetEventHandler()->ProcessEvent(event
);
4451 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4452 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4453 // notifications to its parent which we want to reflect back to
4455 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
4456 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
4458 #endif // wxUSE_SPINCTRL
4460 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
4461 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
4462 // notifications to its parent which we want to reflect back to
4464 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
4465 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
4473 // ---------------------------------------------------------------------------
4475 // ---------------------------------------------------------------------------
4477 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
4481 // our client coords are not quite the same as Windows ones
4482 wxPoint pt
= GetClientAreaOrigin();
4483 event
.m_x
= x
- pt
.x
;
4484 event
.m_y
= y
- pt
.y
;
4486 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
4487 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
4488 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
4489 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
4490 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
4491 event
.m_altDown
= ::GetKeyState(VK_MENU
) < 0;
4494 event
.SetTimestamp(::GetMessageTime());
4497 event
.SetEventObject(this);
4498 event
.SetId(GetId());
4500 #if wxUSE_MOUSEEVENT_HACK
4503 m_lastMouseEvent
= event
.GetEventType();
4504 #endif // wxUSE_MOUSEEVENT_HACK
4508 // Windows doesn't send the mouse events to the static controls (which are
4509 // transparent in the sense that their WM_NCHITTEST handler returns
4510 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4511 // and so we manually check if we don't have a child window under mouse and if
4512 // we do, send the event to it instead of the window Windows had sent WM_XXX
4515 // Notice that this is not done for the mouse move events because this could
4516 // (would?) be too slow, but only for clicks which means that the static texts
4517 // still don't get move, enter nor leave events.
4518 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
4520 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
4522 // first try to find a non transparent child: this allows us to send events
4523 // to a static text which is inside a static box, for example
4524 POINT pt
= { *x
, *y
};
4525 HWND hwnd
= GetHwndOf(win
),
4529 hwndUnderMouse
= ::ChildWindowFromPoint
4535 hwndUnderMouse
= ::ChildWindowFromPointEx
4545 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
4547 // now try any child window at all
4548 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
4551 // check that we have a child window which is susceptible to receive mouse
4552 // events: for this it must be shown and enabled
4553 if ( hwndUnderMouse
&&
4554 hwndUnderMouse
!= hwnd
&&
4555 ::IsWindowVisible(hwndUnderMouse
) &&
4556 ::IsWindowEnabled(hwndUnderMouse
) )
4558 wxWindow
*winUnderMouse
= wxFindWinFromHandle((WXHWND
)hwndUnderMouse
);
4559 if ( winUnderMouse
)
4561 // translate the mouse coords to the other window coords
4562 win
->ClientToScreen(x
, y
);
4563 winUnderMouse
->ScreenToClient(x
, y
);
4565 win
= winUnderMouse
;
4571 #endif // __WXWINCE__
4573 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4575 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4576 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
4577 // from the message id and take the value in the table to get wxWin event
4579 static const wxEventType eventsMouse
[] =
4593 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
4594 InitMouseEvent(event
, x
, y
, flags
);
4596 return GetEventHandler()->ProcessEvent(event
);
4599 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
4601 if ( !m_mouseInWindow
)
4603 // it would be wrong to assume that just because we get a mouse move
4604 // event that the mouse is inside the window: although this is usually
4605 // true, it is not if we had captured the mouse, so we need to check
4606 // the mouse coordinates here
4607 if ( !HasCapture() || IsMouseInWindow() )
4609 // Generate an ENTER event
4610 m_mouseInWindow
= true;
4612 #ifdef HAVE_TRACKMOUSEEVENT
4613 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
4615 trackinfo
.dwFlags
= TME_LEAVE
;
4616 trackinfo
.hwndTrack
= GetHwnd();
4618 // Use the commctrl.h _TrackMouseEvent(), which will call the real
4619 // TrackMouseEvent() if available or emulate it
4620 _TrackMouseEvent(&trackinfo
);
4621 #endif // HAVE_TRACKMOUSEEVENT
4623 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
4624 InitMouseEvent(event
, x
, y
, flags
);
4626 (void)GetEventHandler()->ProcessEvent(event
);
4630 #if wxUSE_MOUSEEVENT_HACK
4631 // Window gets a click down message followed by a mouse move message even
4632 // if position isn't changed! We want to discard the trailing move event
4633 // if x and y are the same.
4634 if ( (m_lastMouseEvent
== wxEVT_RIGHT_DOWN
||
4635 m_lastMouseEvent
== wxEVT_LEFT_DOWN
||
4636 m_lastMouseEvent
== wxEVT_MIDDLE_DOWN
) &&
4637 (m_lastMouseX
== x
&& m_lastMouseY
== y
) )
4639 m_lastMouseEvent
= wxEVT_MOTION
;
4643 #endif // wxUSE_MOUSEEVENT_HACK
4645 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
4649 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
4651 #if wxUSE_MOUSEWHEEL
4652 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
4653 // forwarded up to the parent by DefWindowProc()) and not in the client
4654 // ones as all the other messages, translate them to the client coords for
4657 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
4658 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
4659 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
4660 event
.m_wheelRotation
= (short)HIWORD(wParam
);
4661 event
.m_wheelDelta
= WHEEL_DELTA
;
4663 static int s_linesPerRotation
= -1;
4664 if ( s_linesPerRotation
== -1 )
4666 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
4667 &s_linesPerRotation
, 0))
4669 // this is not supposed to happen
4670 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
4672 // the default is 3, so use it if SystemParametersInfo() failed
4673 s_linesPerRotation
= 3;
4677 event
.m_linesPerAction
= s_linesPerRotation
;
4678 return GetEventHandler()->ProcessEvent(event
);
4680 #else // !wxUSE_MOUSEWHEEL
4681 wxUnusedVar(wParam
);
4682 wxUnusedVar(lParam
);
4685 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
4688 void wxWindowMSW::GenerateMouseLeave()
4690 m_mouseInWindow
= false;
4693 if ( wxIsShiftDown() )
4695 if ( wxIsCtrlDown() )
4696 state
|= MK_CONTROL
;
4698 // Only the high-order bit should be tested
4699 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
4700 state
|= MK_LBUTTON
;
4701 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
4702 state
|= MK_MBUTTON
;
4703 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
4704 state
|= MK_RBUTTON
;
4708 if ( !::GetCursorPosWinCE(&pt
) )
4710 if ( !::GetCursorPos(&pt
) )
4713 wxLogLastError(_T("GetCursorPos"));
4716 // we need to have client coordinates here for symmetry with
4717 // wxEVT_ENTER_WINDOW
4718 RECT rect
= wxGetWindowRect(GetHwnd());
4722 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
4723 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
4725 (void)GetEventHandler()->ProcessEvent(event
);
4728 // ---------------------------------------------------------------------------
4729 // keyboard handling
4730 // ---------------------------------------------------------------------------
4732 // create the key event of the given type for the given key - used by
4733 // HandleChar and HandleKeyDown/Up
4734 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
4737 WXWPARAM wParam
) const
4739 wxKeyEvent
event(evType
);
4740 event
.SetId(GetId());
4741 event
.m_shiftDown
= wxIsShiftDown();
4742 event
.m_controlDown
= wxIsCtrlDown();
4743 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
4745 event
.SetEventObject((wxWindow
*)this); // const_cast
4746 event
.m_keyCode
= id
;
4748 event
.m_uniChar
= (wxChar
) wParam
;
4750 event
.m_rawCode
= (wxUint32
) wParam
;
4751 event
.m_rawFlags
= (wxUint32
) lParam
;
4753 event
.SetTimestamp(::GetMessageTime());
4756 // translate the position to client coords
4759 GetCursorPosWinCE(&pt
);
4764 GetWindowRect(GetHwnd(),&rect
);
4774 // isASCII is true only when we're called from WM_CHAR handler and not from
4776 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
4781 // If 1 -> 26, translate to either special keycode or just set
4782 // ctrlDown. IOW, Ctrl-C should result in keycode == 3 and
4783 // ControlDown() == true.
4785 if ( (id
> 0) && (id
< 27) )
4807 else // we're called from WM_KEYDOWN
4809 id
= wxCharCodeMSWToWX(wParam
, lParam
);
4812 // it's ASCII and will be processed here only when called from
4813 // WM_CHAR (i.e. when isASCII = true), don't process it now
4818 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
4820 // the alphanumeric keys produced by pressing AltGr+something on European
4821 // keyboards have both Ctrl and Alt modifiers which may confuse the user
4822 // code as, normally, keys with Ctrl and/or Alt don't result in anything
4823 // alphanumeric, so pretend that there are no modifiers at all (the
4824 // KEY_DOWN event would still have the correct modifiers if they're really
4826 if ( event
.m_controlDown
&& event
.m_altDown
&&
4827 (id
>= 32 && id
< 256) )
4829 event
.m_controlDown
=
4830 event
.m_altDown
= false;
4833 return GetEventHandler()->ProcessEvent(event
);
4836 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
4838 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
4842 // normal ASCII char
4846 if ( id
!= -1 ) // VZ: does this ever happen (FIXME)?
4848 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
4849 if ( GetEventHandler()->ProcessEvent(event
) )
4858 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
4860 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
4864 // normal ASCII char
4868 if ( id
!= -1 ) // VZ: does this ever happen (FIXME)?
4870 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
4871 if ( GetEventHandler()->ProcessEvent(event
) )
4878 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
4879 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
4881 // FIXME: implement GetMenuItemCount for WinCE, possibly
4882 // in terms of GetMenuItemInfo
4884 const HMENU hmenu
= (HMENU
)lParam
;
4888 mii
.cbSize
= sizeof(MENUITEMINFO
);
4889 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
4891 // find if we have this letter in any owner drawn item
4892 const int count
= ::GetMenuItemCount(hmenu
);
4893 for ( int i
= 0; i
< count
; i
++ )
4895 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
4897 if ( mii
.fType
== MFT_OWNERDRAW
)
4899 // dwItemData member of the MENUITEMINFO is a
4900 // pointer to the associated wxMenuItem -- see the
4901 // menu creation code
4902 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
4904 const wxChar
*p
= wxStrchr(item
->GetText(), _T('&'));
4907 if ( *p
== _T('&') )
4909 // this is not the accel char, find the real one
4910 p
= wxStrchr(p
+ 1, _T('&'));
4912 else // got the accel char
4914 // FIXME-UNICODE: this comparison doesn't risk to work
4915 // for non ASCII accelerator characters I'm afraid, but
4917 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
4923 // this one doesn't match
4930 else // failed to get the menu text?
4932 // it's not fatal, so don't show error, but still log
4934 wxLogLastError(_T("GetMenuItemInfo"));
4941 // ---------------------------------------------------------------------------
4943 // ---------------------------------------------------------------------------
4945 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4949 if ( flags
& JOY_BUTTON1CHG
)
4950 change
= wxJOY_BUTTON1
;
4951 if ( flags
& JOY_BUTTON2CHG
)
4952 change
= wxJOY_BUTTON2
;
4953 if ( flags
& JOY_BUTTON3CHG
)
4954 change
= wxJOY_BUTTON3
;
4955 if ( flags
& JOY_BUTTON4CHG
)
4956 change
= wxJOY_BUTTON4
;
4959 if ( flags
& JOY_BUTTON1
)
4960 buttons
|= wxJOY_BUTTON1
;
4961 if ( flags
& JOY_BUTTON2
)
4962 buttons
|= wxJOY_BUTTON2
;
4963 if ( flags
& JOY_BUTTON3
)
4964 buttons
|= wxJOY_BUTTON3
;
4965 if ( flags
& JOY_BUTTON4
)
4966 buttons
|= wxJOY_BUTTON4
;
4968 // the event ids aren't consecutive so we can't use table based lookup
4970 wxEventType eventType
;
4975 eventType
= wxEVT_JOY_MOVE
;
4980 eventType
= wxEVT_JOY_MOVE
;
4985 eventType
= wxEVT_JOY_ZMOVE
;
4990 eventType
= wxEVT_JOY_ZMOVE
;
4993 case MM_JOY1BUTTONDOWN
:
4995 eventType
= wxEVT_JOY_BUTTON_DOWN
;
4998 case MM_JOY2BUTTONDOWN
:
5000 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5003 case MM_JOY1BUTTONUP
:
5005 eventType
= wxEVT_JOY_BUTTON_UP
;
5008 case MM_JOY2BUTTONUP
:
5010 eventType
= wxEVT_JOY_BUTTON_UP
;
5014 wxFAIL_MSG(wxT("no such joystick event"));
5019 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5020 event
.SetPosition(wxPoint(x
, y
));
5021 event
.SetEventObject(this);
5023 return GetEventHandler()->ProcessEvent(event
);
5033 // ---------------------------------------------------------------------------
5035 // ---------------------------------------------------------------------------
5037 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5038 WXWORD pos
, WXHWND control
)
5040 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5042 wxWindow
*child
= wxFindWinFromHandle(control
);
5044 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5047 wxScrollWinEvent event
;
5048 event
.SetPosition(pos
);
5049 event
.SetOrientation(orientation
);
5050 event
.SetEventObject(this);
5055 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5059 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5063 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5067 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5071 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5075 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5078 case SB_THUMBPOSITION
:
5080 // under Win32, the scrollbar range and position are 32 bit integers,
5081 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5082 // explicitly query the scrollbar for the correct position (this must
5083 // be done only for these two SB_ events as they are the only one
5084 // carrying the scrollbar position)
5086 WinStruct
<SCROLLINFO
> scrollInfo
;
5087 scrollInfo
.fMask
= SIF_TRACKPOS
;
5089 if ( !::GetScrollInfo(GetHwnd(),
5090 orientation
== wxHORIZONTAL
? SB_HORZ
5094 // Not necessarily an error, if there are no scrollbars yet.
5095 // wxLogLastError(_T("GetScrollInfo"));
5098 event
.SetPosition(scrollInfo
.nTrackPos
);
5101 event
.SetEventType( wParam
== SB_THUMBPOSITION
5102 ? wxEVT_SCROLLWIN_THUMBRELEASE
5103 : wxEVT_SCROLLWIN_THUMBTRACK
);
5110 return GetEventHandler()->ProcessEvent(event
);
5113 // ===========================================================================
5115 // ===========================================================================
5117 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5120 HDC dc
= ::GetDC((HWND
) wnd
);
5123 // the_font.UseResource();
5124 // the_font.RealizeResource();
5125 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
5127 was
= (HFONT
) SelectObject(dc
,fnt
);
5129 GetTextMetrics(dc
, &tm
);
5132 SelectObject(dc
,was
);
5134 ReleaseDC((HWND
)wnd
, dc
);
5137 *x
= tm
.tmAveCharWidth
;
5139 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
5141 // the_font.ReleaseResource();
5144 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
5145 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
5146 int wxCharCodeMSWToWX(int keySym
, WXLPARAM lParam
)
5151 case VK_CANCEL
: id
= WXK_CANCEL
; break;
5152 case VK_BACK
: id
= WXK_BACK
; break;
5153 case VK_TAB
: id
= WXK_TAB
; break;
5154 case VK_CLEAR
: id
= WXK_CLEAR
; break;
5155 case VK_SHIFT
: id
= WXK_SHIFT
; break;
5156 case VK_CONTROL
: id
= WXK_CONTROL
; break;
5157 case VK_MENU
: id
= WXK_ALT
; break;
5158 case VK_PAUSE
: id
= WXK_PAUSE
; break;
5159 case VK_CAPITAL
: id
= WXK_CAPITAL
; break;
5160 case VK_SPACE
: id
= WXK_SPACE
; break;
5161 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
5162 case VK_PRIOR
: id
= WXK_PRIOR
; break;
5163 case VK_NEXT
: id
= WXK_NEXT
; break;
5164 case VK_END
: id
= WXK_END
; break;
5165 case VK_HOME
: id
= WXK_HOME
; break;
5166 case VK_LEFT
: id
= WXK_LEFT
; break;
5167 case VK_UP
: id
= WXK_UP
; break;
5168 case VK_RIGHT
: id
= WXK_RIGHT
; break;
5169 case VK_DOWN
: id
= WXK_DOWN
; break;
5170 case VK_SELECT
: id
= WXK_SELECT
; break;
5171 case VK_PRINT
: id
= WXK_PRINT
; break;
5172 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
5173 case VK_INSERT
: id
= WXK_INSERT
; break;
5174 case VK_DELETE
: id
= WXK_DELETE
; break;
5175 case VK_HELP
: id
= WXK_HELP
; break;
5176 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
5177 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
5178 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
5179 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
5180 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
5181 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
5182 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
5183 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
5184 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
5185 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
5186 case VK_MULTIPLY
: id
= WXK_NUMPAD_MULTIPLY
; break;
5187 case VK_ADD
: id
= WXK_NUMPAD_ADD
; break;
5188 case VK_SUBTRACT
: id
= WXK_NUMPAD_SUBTRACT
; break;
5189 case VK_DECIMAL
: id
= WXK_NUMPAD_DECIMAL
; break;
5190 case VK_DIVIDE
: id
= WXK_NUMPAD_DIVIDE
; break;
5191 case VK_F1
: id
= WXK_F1
; break;
5192 case VK_F2
: id
= WXK_F2
; break;
5193 case VK_F3
: id
= WXK_F3
; break;
5194 case VK_F4
: id
= WXK_F4
; break;
5195 case VK_F5
: id
= WXK_F5
; break;
5196 case VK_F6
: id
= WXK_F6
; break;
5197 case VK_F7
: id
= WXK_F7
; break;
5198 case VK_F8
: id
= WXK_F8
; break;
5199 case VK_F9
: id
= WXK_F9
; break;
5200 case VK_F10
: id
= WXK_F10
; break;
5201 case VK_F11
: id
= WXK_F11
; break;
5202 case VK_F12
: id
= WXK_F12
; break;
5203 case VK_F13
: id
= WXK_F13
; break;
5204 case VK_F14
: id
= WXK_F14
; break;
5205 case VK_F15
: id
= WXK_F15
; break;
5206 case VK_F16
: id
= WXK_F16
; break;
5207 case VK_F17
: id
= WXK_F17
; break;
5208 case VK_F18
: id
= WXK_F18
; break;
5209 case VK_F19
: id
= WXK_F19
; break;
5210 case VK_F20
: id
= WXK_F20
; break;
5211 case VK_F21
: id
= WXK_F21
; break;
5212 case VK_F22
: id
= WXK_F22
; break;
5213 case VK_F23
: id
= WXK_F23
; break;
5214 case VK_F24
: id
= WXK_F24
; break;
5215 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
5216 case VK_SCROLL
: id
= WXK_SCROLL
; break;
5218 // the mapping for these keys may be incorrect on non-US keyboards so
5219 // maybe we shouldn't map them to ASCII values at all
5220 case VK_OEM_1
: id
= ';'; break;
5221 case VK_OEM_PLUS
: id
= '+'; break;
5222 case VK_OEM_COMMA
: id
= ','; break;
5223 case VK_OEM_MINUS
: id
= '-'; break;
5224 case VK_OEM_PERIOD
: id
= '.'; break;
5225 case VK_OEM_2
: id
= '/'; break;
5226 case VK_OEM_3
: id
= '~'; break;
5227 case VK_OEM_4
: id
= '['; break;
5228 case VK_OEM_5
: id
= '\\'; break;
5229 case VK_OEM_6
: id
= ']'; break;
5230 case VK_OEM_7
: id
= '\''; break;
5233 case VK_LWIN
: id
= WXK_WINDOWS_LEFT
; break;
5234 case VK_RWIN
: id
= WXK_WINDOWS_RIGHT
; break;
5235 case VK_APPS
: id
= WXK_WINDOWS_MENU
; break;
5236 #endif // VK_APPS defined
5239 // the same key is sent for both the "return" key on the main
5240 // keyboard and the numeric keypad but we want to distinguish
5241 // between them: we do this using the "extended" bit (24) of lParam
5242 id
= lParam
& (1 << 24) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
5252 WXWORD
wxCharCodeWXToMSW(int id
, bool *isVirtual
)
5258 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
5259 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
5260 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
5261 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
5262 case WXK_ALT
: keySym
= VK_MENU
; break;
5263 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
5264 case WXK_CAPITAL
: keySym
= VK_CAPITAL
; break;
5265 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
5266 case WXK_NEXT
: keySym
= VK_NEXT
; break;
5267 case WXK_END
: keySym
= VK_END
; break;
5268 case WXK_HOME
: keySym
= VK_HOME
; break;
5269 case WXK_LEFT
: keySym
= VK_LEFT
; break;
5270 case WXK_UP
: keySym
= VK_UP
; break;
5271 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
5272 case WXK_DOWN
: keySym
= VK_DOWN
; break;
5273 case WXK_SELECT
: keySym
= VK_SELECT
; break;
5274 case WXK_PRINT
: keySym
= VK_PRINT
; break;
5275 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
5276 case WXK_INSERT
: keySym
= VK_INSERT
; break;
5277 case WXK_DELETE
: keySym
= VK_DELETE
; break;
5278 case WXK_HELP
: keySym
= VK_HELP
; break;
5279 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
5280 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
5281 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
5282 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
5283 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
5284 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
5285 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
5286 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
5287 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
5288 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
5289 case WXK_NUMPAD_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
5290 case WXK_NUMPAD_ADD
: keySym
= VK_ADD
; break;
5291 case WXK_NUMPAD_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
5292 case WXK_NUMPAD_DECIMAL
: keySym
= VK_DECIMAL
; break;
5293 case WXK_NUMPAD_DIVIDE
: keySym
= VK_DIVIDE
; break;
5294 case WXK_F1
: keySym
= VK_F1
; break;
5295 case WXK_F2
: keySym
= VK_F2
; break;
5296 case WXK_F3
: keySym
= VK_F3
; break;
5297 case WXK_F4
: keySym
= VK_F4
; break;
5298 case WXK_F5
: keySym
= VK_F5
; break;
5299 case WXK_F6
: keySym
= VK_F6
; break;
5300 case WXK_F7
: keySym
= VK_F7
; break;
5301 case WXK_F8
: keySym
= VK_F8
; break;
5302 case WXK_F9
: keySym
= VK_F9
; break;
5303 case WXK_F10
: keySym
= VK_F10
; break;
5304 case WXK_F11
: keySym
= VK_F11
; break;
5305 case WXK_F12
: keySym
= VK_F12
; break;
5306 case WXK_F13
: keySym
= VK_F13
; break;
5307 case WXK_F14
: keySym
= VK_F14
; break;
5308 case WXK_F15
: keySym
= VK_F15
; break;
5309 case WXK_F16
: keySym
= VK_F16
; break;
5310 case WXK_F17
: keySym
= VK_F17
; break;
5311 case WXK_F18
: keySym
= VK_F18
; break;
5312 case WXK_F19
: keySym
= VK_F19
; break;
5313 case WXK_F20
: keySym
= VK_F20
; break;
5314 case WXK_F21
: keySym
= VK_F21
; break;
5315 case WXK_F22
: keySym
= VK_F22
; break;
5316 case WXK_F23
: keySym
= VK_F23
; break;
5317 case WXK_F24
: keySym
= VK_F24
; break;
5318 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
5319 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
5330 bool wxGetKeyState(wxKeyCode key
)
5334 wxASSERT_MSG(key
!= WXK_LBUTTON
&& key
!= WXK_RBUTTON
&& key
!=
5335 WXK_MBUTTON
, wxT("can't use wxGetKeyState() for mouse buttons"));
5337 //High order with GetAsyncKeyState only available on WIN32
5339 //If the requested key is a LED key, return
5340 //true if the led is pressed
5341 if (key
== WXK_NUMLOCK
||
5342 key
== WXK_CAPITAL
||
5346 //low order bit means LED is highlighted,
5347 //high order means key is down
5348 //Here, for compat with other ports we want both
5349 return GetKeyState( wxCharCodeWXToMSW(key
, &bVirtual
) ) != 0;
5356 //low order bit means key pressed since last call
5357 //high order means key is down
5358 //We want only the high order bit - the key may not be down if only low order
5359 return ( GetAsyncKeyState( wxCharCodeWXToMSW(key
, &bVirtual
) ) & (1<<15) ) != 0;
5364 wxWindow
*wxGetActiveWindow()
5366 HWND hWnd
= GetActiveWindow();
5369 return wxFindWinFromHandle((WXHWND
) hWnd
);
5374 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
5376 HWND hwnd
= (HWND
)hWnd
;
5378 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
5379 // by code in msw/radiobox.cpp), for all the others we just search up the
5381 wxWindow
*win
= (wxWindow
*)NULL
;
5384 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5388 // native radiobuttons return DLGC_RADIOBUTTON here and for any
5389 // wxWindow class which overrides WM_GETDLGCODE processing to
5390 // do it as well, win would be already non NULL
5391 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
5393 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
5395 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
5396 #endif // wxUSE_RADIOBOX
5398 // spin control text buddy window should be mapped to spin ctrl
5399 // itself so try it too
5400 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5403 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
5405 #endif // wxUSE_SPINCTRL
5409 while ( hwnd
&& !win
)
5411 // this is a really ugly hack needed to avoid mistakenly returning the
5412 // parent frame wxWindow for the find/replace modeless dialog HWND -
5413 // this, in turn, is needed to call IsDialogMessage() from
5414 // wxApp::ProcessMessage() as for this we must return NULL from here
5416 // FIXME: this is clearly not the best way to do it but I think we'll
5417 // need to change HWND <-> wxWindow code more heavily than I can
5418 // do it now to fix it
5419 #ifndef __WXMICROWIN__
5420 if ( ::GetWindow(hwnd
, GW_OWNER
) )
5422 // it's a dialog box, don't go upwards
5427 hwnd
= ::GetParent(hwnd
);
5428 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5434 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
5436 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
5437 // in active frames and dialogs, regardless of where the focus is.
5438 static HHOOK wxTheKeyboardHook
= 0;
5439 static FARPROC wxTheKeyboardHookProc
= 0;
5440 int APIENTRY _EXPORT
5441 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
5443 void wxSetKeyboardHook(bool doIt
)
5447 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
5448 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
5450 GetCurrentThreadId()
5451 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
5456 UnhookWindowsHookEx(wxTheKeyboardHook
);
5460 int APIENTRY _EXPORT
5461 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
5463 DWORD hiWord
= HIWORD(lParam
);
5464 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
5466 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5469 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
5470 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
5471 event
.m_altDown
= true;
5473 event
.SetEventObject(NULL
);
5474 event
.m_keyCode
= id
;
5475 event
.m_shiftDown
= wxIsShiftDown();
5476 event
.m_controlDown
= wxIsCtrlDown();
5478 event
.SetTimestamp(::GetMessageTime());
5480 wxWindow
*win
= wxGetActiveWindow();
5481 wxEvtHandler
*handler
;
5484 handler
= win
->GetEventHandler();
5485 event
.SetId(win
->GetId());
5490 event
.SetId(wxID_ANY
);
5493 if ( handler
&& handler
->ProcessEvent(event
) )
5501 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
5504 #endif // !__WXMICROWIN__
5507 const wxChar
*wxGetMessageName(int message
)
5511 case 0x0000: return wxT("WM_NULL");
5512 case 0x0001: return wxT("WM_CREATE");
5513 case 0x0002: return wxT("WM_DESTROY");
5514 case 0x0003: return wxT("WM_MOVE");
5515 case 0x0005: return wxT("WM_SIZE");
5516 case 0x0006: return wxT("WM_ACTIVATE");
5517 case 0x0007: return wxT("WM_SETFOCUS");
5518 case 0x0008: return wxT("WM_KILLFOCUS");
5519 case 0x000A: return wxT("WM_ENABLE");
5520 case 0x000B: return wxT("WM_SETREDRAW");
5521 case 0x000C: return wxT("WM_SETTEXT");
5522 case 0x000D: return wxT("WM_GETTEXT");
5523 case 0x000E: return wxT("WM_GETTEXTLENGTH");
5524 case 0x000F: return wxT("WM_PAINT");
5525 case 0x0010: return wxT("WM_CLOSE");
5526 case 0x0011: return wxT("WM_QUERYENDSESSION");
5527 case 0x0012: return wxT("WM_QUIT");
5528 case 0x0013: return wxT("WM_QUERYOPEN");
5529 case 0x0014: return wxT("WM_ERASEBKGND");
5530 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
5531 case 0x0016: return wxT("WM_ENDSESSION");
5532 case 0x0017: return wxT("WM_SYSTEMERROR");
5533 case 0x0018: return wxT("WM_SHOWWINDOW");
5534 case 0x0019: return wxT("WM_CTLCOLOR");
5535 case 0x001A: return wxT("WM_WININICHANGE");
5536 case 0x001B: return wxT("WM_DEVMODECHANGE");
5537 case 0x001C: return wxT("WM_ACTIVATEAPP");
5538 case 0x001D: return wxT("WM_FONTCHANGE");
5539 case 0x001E: return wxT("WM_TIMECHANGE");
5540 case 0x001F: return wxT("WM_CANCELMODE");
5541 case 0x0020: return wxT("WM_SETCURSOR");
5542 case 0x0021: return wxT("WM_MOUSEACTIVATE");
5543 case 0x0022: return wxT("WM_CHILDACTIVATE");
5544 case 0x0023: return wxT("WM_QUEUESYNC");
5545 case 0x0024: return wxT("WM_GETMINMAXINFO");
5546 case 0x0026: return wxT("WM_PAINTICON");
5547 case 0x0027: return wxT("WM_ICONERASEBKGND");
5548 case 0x0028: return wxT("WM_NEXTDLGCTL");
5549 case 0x002A: return wxT("WM_SPOOLERSTATUS");
5550 case 0x002B: return wxT("WM_DRAWITEM");
5551 case 0x002C: return wxT("WM_MEASUREITEM");
5552 case 0x002D: return wxT("WM_DELETEITEM");
5553 case 0x002E: return wxT("WM_VKEYTOITEM");
5554 case 0x002F: return wxT("WM_CHARTOITEM");
5555 case 0x0030: return wxT("WM_SETFONT");
5556 case 0x0031: return wxT("WM_GETFONT");
5557 case 0x0037: return wxT("WM_QUERYDRAGICON");
5558 case 0x0039: return wxT("WM_COMPAREITEM");
5559 case 0x0041: return wxT("WM_COMPACTING");
5560 case 0x0044: return wxT("WM_COMMNOTIFY");
5561 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
5562 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
5563 case 0x0048: return wxT("WM_POWER");
5565 case 0x004A: return wxT("WM_COPYDATA");
5566 case 0x004B: return wxT("WM_CANCELJOURNAL");
5567 case 0x004E: return wxT("WM_NOTIFY");
5568 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
5569 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
5570 case 0x0052: return wxT("WM_TCARD");
5571 case 0x0053: return wxT("WM_HELP");
5572 case 0x0054: return wxT("WM_USERCHANGED");
5573 case 0x0055: return wxT("WM_NOTIFYFORMAT");
5574 case 0x007B: return wxT("WM_CONTEXTMENU");
5575 case 0x007C: return wxT("WM_STYLECHANGING");
5576 case 0x007D: return wxT("WM_STYLECHANGED");
5577 case 0x007E: return wxT("WM_DISPLAYCHANGE");
5578 case 0x007F: return wxT("WM_GETICON");
5579 case 0x0080: return wxT("WM_SETICON");
5581 case 0x0081: return wxT("WM_NCCREATE");
5582 case 0x0082: return wxT("WM_NCDESTROY");
5583 case 0x0083: return wxT("WM_NCCALCSIZE");
5584 case 0x0084: return wxT("WM_NCHITTEST");
5585 case 0x0085: return wxT("WM_NCPAINT");
5586 case 0x0086: return wxT("WM_NCACTIVATE");
5587 case 0x0087: return wxT("WM_GETDLGCODE");
5588 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
5589 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
5590 case 0x00A2: return wxT("WM_NCLBUTTONUP");
5591 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
5592 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
5593 case 0x00A5: return wxT("WM_NCRBUTTONUP");
5594 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
5595 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
5596 case 0x00A8: return wxT("WM_NCMBUTTONUP");
5597 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
5598 case 0x0100: return wxT("WM_KEYDOWN");
5599 case 0x0101: return wxT("WM_KEYUP");
5600 case 0x0102: return wxT("WM_CHAR");
5601 case 0x0103: return wxT("WM_DEADCHAR");
5602 case 0x0104: return wxT("WM_SYSKEYDOWN");
5603 case 0x0105: return wxT("WM_SYSKEYUP");
5604 case 0x0106: return wxT("WM_SYSCHAR");
5605 case 0x0107: return wxT("WM_SYSDEADCHAR");
5606 case 0x0108: return wxT("WM_KEYLAST");
5608 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
5609 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
5610 case 0x010F: return wxT("WM_IME_COMPOSITION");
5612 case 0x0110: return wxT("WM_INITDIALOG");
5613 case 0x0111: return wxT("WM_COMMAND");
5614 case 0x0112: return wxT("WM_SYSCOMMAND");
5615 case 0x0113: return wxT("WM_TIMER");
5616 case 0x0114: return wxT("WM_HSCROLL");
5617 case 0x0115: return wxT("WM_VSCROLL");
5618 case 0x0116: return wxT("WM_INITMENU");
5619 case 0x0117: return wxT("WM_INITMENUPOPUP");
5620 case 0x011F: return wxT("WM_MENUSELECT");
5621 case 0x0120: return wxT("WM_MENUCHAR");
5622 case 0x0121: return wxT("WM_ENTERIDLE");
5623 case 0x0200: return wxT("WM_MOUSEMOVE");
5624 case 0x0201: return wxT("WM_LBUTTONDOWN");
5625 case 0x0202: return wxT("WM_LBUTTONUP");
5626 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
5627 case 0x0204: return wxT("WM_RBUTTONDOWN");
5628 case 0x0205: return wxT("WM_RBUTTONUP");
5629 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
5630 case 0x0207: return wxT("WM_MBUTTONDOWN");
5631 case 0x0208: return wxT("WM_MBUTTONUP");
5632 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
5633 case 0x020A: return wxT("WM_MOUSEWHEEL");
5634 case 0x0210: return wxT("WM_PARENTNOTIFY");
5635 case 0x0211: return wxT("WM_ENTERMENULOOP");
5636 case 0x0212: return wxT("WM_EXITMENULOOP");
5638 case 0x0213: return wxT("WM_NEXTMENU");
5639 case 0x0214: return wxT("WM_SIZING");
5640 case 0x0215: return wxT("WM_CAPTURECHANGED");
5641 case 0x0216: return wxT("WM_MOVING");
5642 case 0x0218: return wxT("WM_POWERBROADCAST");
5643 case 0x0219: return wxT("WM_DEVICECHANGE");
5645 case 0x0220: return wxT("WM_MDICREATE");
5646 case 0x0221: return wxT("WM_MDIDESTROY");
5647 case 0x0222: return wxT("WM_MDIACTIVATE");
5648 case 0x0223: return wxT("WM_MDIRESTORE");
5649 case 0x0224: return wxT("WM_MDINEXT");
5650 case 0x0225: return wxT("WM_MDIMAXIMIZE");
5651 case 0x0226: return wxT("WM_MDITILE");
5652 case 0x0227: return wxT("WM_MDICASCADE");
5653 case 0x0228: return wxT("WM_MDIICONARRANGE");
5654 case 0x0229: return wxT("WM_MDIGETACTIVE");
5655 case 0x0230: return wxT("WM_MDISETMENU");
5656 case 0x0233: return wxT("WM_DROPFILES");
5658 case 0x0281: return wxT("WM_IME_SETCONTEXT");
5659 case 0x0282: return wxT("WM_IME_NOTIFY");
5660 case 0x0283: return wxT("WM_IME_CONTROL");
5661 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
5662 case 0x0285: return wxT("WM_IME_SELECT");
5663 case 0x0286: return wxT("WM_IME_CHAR");
5664 case 0x0290: return wxT("WM_IME_KEYDOWN");
5665 case 0x0291: return wxT("WM_IME_KEYUP");
5667 case 0x0300: return wxT("WM_CUT");
5668 case 0x0301: return wxT("WM_COPY");
5669 case 0x0302: return wxT("WM_PASTE");
5670 case 0x0303: return wxT("WM_CLEAR");
5671 case 0x0304: return wxT("WM_UNDO");
5672 case 0x0305: return wxT("WM_RENDERFORMAT");
5673 case 0x0306: return wxT("WM_RENDERALLFORMATS");
5674 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
5675 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
5676 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
5677 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
5678 case 0x030B: return wxT("WM_SIZECLIPBOARD");
5679 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
5680 case 0x030D: return wxT("WM_CHANGECBCHAIN");
5681 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
5682 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
5683 case 0x0310: return wxT("WM_PALETTEISCHANGING");
5684 case 0x0311: return wxT("WM_PALETTECHANGED");
5686 case 0x0312: return wxT("WM_HOTKEY");
5689 // common controls messages - although they're not strictly speaking
5690 // standard, it's nice to decode them nevertheless
5693 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
5694 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
5695 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
5696 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
5697 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
5698 case 0x1000 + 5: return wxT("LVM_GETITEMA");
5699 case 0x1000 + 75: return wxT("LVM_GETITEMW");
5700 case 0x1000 + 6: return wxT("LVM_SETITEMA");
5701 case 0x1000 + 76: return wxT("LVM_SETITEMW");
5702 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
5703 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
5704 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
5705 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
5706 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
5707 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
5708 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
5709 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
5710 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
5711 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
5712 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
5713 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
5714 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
5715 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
5716 case 0x1000 + 18: return wxT("LVM_HITTEST");
5717 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
5718 case 0x1000 + 20: return wxT("LVM_SCROLL");
5719 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
5720 case 0x1000 + 22: return wxT("LVM_ARRANGE");
5721 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
5722 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
5723 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
5724 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
5725 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
5726 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
5727 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
5728 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
5729 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
5730 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
5731 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
5732 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
5733 case 0x1000 + 31: return wxT("LVM_GETHEADER");
5734 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
5735 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
5736 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
5737 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
5738 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
5739 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
5740 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
5741 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
5742 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
5743 case 0x1000 + 42: return wxT("LVM_UPDATE");
5744 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
5745 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
5746 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
5747 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
5748 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
5749 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
5750 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
5751 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
5752 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
5753 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
5754 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
5755 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
5756 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
5757 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
5758 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
5759 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
5760 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
5761 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
5762 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
5763 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
5764 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
5765 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
5766 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
5767 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
5768 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
5769 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
5772 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
5773 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
5774 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
5775 case 0x1100 + 2: return wxT("TVM_EXPAND");
5776 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
5777 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
5778 case 0x1100 + 6: return wxT("TVM_GETINDENT");
5779 case 0x1100 + 7: return wxT("TVM_SETINDENT");
5780 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
5781 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
5782 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
5783 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
5784 case 0x1100 + 12: return wxT("TVM_GETITEMA");
5785 case 0x1100 + 62: return wxT("TVM_GETITEMW");
5786 case 0x1100 + 13: return wxT("TVM_SETITEMA");
5787 case 0x1100 + 63: return wxT("TVM_SETITEMW");
5788 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
5789 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
5790 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
5791 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
5792 case 0x1100 + 17: return wxT("TVM_HITTEST");
5793 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
5794 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
5795 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
5796 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
5797 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
5798 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
5799 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
5800 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
5801 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
5804 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
5805 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
5806 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
5807 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
5808 case 0x1200 + 3: return wxT("HDM_GETITEMA");
5809 case 0x1200 + 11: return wxT("HDM_GETITEMW");
5810 case 0x1200 + 4: return wxT("HDM_SETITEMA");
5811 case 0x1200 + 12: return wxT("HDM_SETITEMW");
5812 case 0x1200 + 5: return wxT("HDM_LAYOUT");
5813 case 0x1200 + 6: return wxT("HDM_HITTEST");
5814 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
5815 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
5816 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
5817 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
5818 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
5819 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
5820 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
5821 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
5824 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
5825 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
5826 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
5827 case 0x1300 + 5: return wxT("TCM_GETITEMA");
5828 case 0x1300 + 60: return wxT("TCM_GETITEMW");
5829 case 0x1300 + 6: return wxT("TCM_SETITEMA");
5830 case 0x1300 + 61: return wxT("TCM_SETITEMW");
5831 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
5832 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
5833 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
5834 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
5835 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
5836 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
5837 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
5838 case 0x1300 + 13: return wxT("TCM_HITTEST");
5839 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
5840 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
5841 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
5842 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
5843 case 0x1300 + 43: return wxT("TCM_SETPADDING");
5844 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
5845 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
5846 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
5847 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
5848 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
5849 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
5850 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
5853 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
5854 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
5855 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
5856 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
5857 case WM_USER
+5: return wxT("TB_INDETERMINATE");
5858 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
5859 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
5860 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
5861 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
5862 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
5863 case WM_USER
+17: return wxT("TB_SETSTATE");
5864 case WM_USER
+18: return wxT("TB_GETSTATE");
5865 case WM_USER
+19: return wxT("TB_ADDBITMAP");
5866 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
5867 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
5868 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
5869 case WM_USER
+23: return wxT("TB_GETBUTTON");
5870 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
5871 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
5872 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
5873 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
5874 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
5875 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
5876 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
5877 case WM_USER
+29: return wxT("TB_GETITEMRECT");
5878 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
5879 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
5880 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
5881 case WM_USER
+33: return wxT("TB_AUTOSIZE");
5882 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
5883 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
5884 case WM_USER
+37: return wxT("TB_SETPARENT");
5885 case WM_USER
+39: return wxT("TB_SETROWS");
5886 case WM_USER
+40: return wxT("TB_GETROWS");
5887 case WM_USER
+42: return wxT("TB_SETCMDID");
5888 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
5889 case WM_USER
+44: return wxT("TB_GETBITMAP");
5890 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
5891 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
5892 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
5893 case WM_USER
+47: return wxT("TB_SETINDENT");
5894 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
5895 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
5896 case WM_USER
+50: return wxT("TB_LOADIMAGES");
5897 case WM_USER
+51: return wxT("TB_GETRECT");
5898 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
5899 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
5900 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
5901 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
5902 case WM_USER
+56: return wxT("TB_SETSTYLE");
5903 case WM_USER
+57: return wxT("TB_GETSTYLE");
5904 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
5905 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
5906 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
5907 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
5908 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
5911 static wxString s_szBuf
;
5912 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
5913 return s_szBuf
.c_str();
5916 #endif //__WXDEBUG__
5918 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
5922 HWND hwnd
= GetHwndOf(win
);
5923 HDC hdc
= ::GetDC(hwnd
);
5925 #if !wxDIALOG_UNIT_COMPATIBILITY
5926 // and select the current font into it
5927 HFONT hfont
= GetHfontOf(win
->GetFont());
5930 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
5934 // finally retrieve the text metrics from it
5935 GetTextMetrics(hdc
, &tm
);
5937 #if !wxDIALOG_UNIT_COMPATIBILITY
5941 (void)::SelectObject(hdc
, hfont
);
5945 ::ReleaseDC(hwnd
, hdc
);
5950 // Find the wxWindow at the current mouse position, returning the mouse
5952 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
5954 pt
= wxGetMousePosition();
5955 return wxFindWindowAtPoint(pt
);
5958 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
5963 HWND hWndHit
= ::WindowFromPoint(pt2
);
5965 wxWindow
* win
= wxFindWinFromHandle((WXHWND
) hWndHit
) ;
5966 HWND hWnd
= hWndHit
;
5968 // Try to find a window with a wxWindow associated with it
5969 while (!win
&& (hWnd
!= 0))
5971 hWnd
= ::GetParent(hWnd
);
5972 win
= wxFindWinFromHandle((WXHWND
) hWnd
) ;
5977 // Get the current mouse position.
5978 wxPoint
wxGetMousePosition()
5982 GetCursorPosWinCE(&pt
);
5984 GetCursorPos( & pt
);
5987 return wxPoint(pt
.x
, pt
.y
);
5992 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
5993 static void WinCEUnregisterHotKey(int modifiers
, int id
)
5995 // Register hotkeys for the hardware buttons
5997 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
5999 UnregisterFunc1Proc procUnregisterFunc
;
6000 hCoreDll
= LoadLibrary(_T("coredll.dll"));
6003 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, _T("UnregisterFunc1"));
6004 if (procUnregisterFunc
)
6005 procUnregisterFunc(modifiers
, id
);
6006 FreeLibrary(hCoreDll
);
6011 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
6013 UINT win_modifiers
=0;
6014 if ( modifiers
& wxMOD_ALT
)
6015 win_modifiers
|= MOD_ALT
;
6016 if ( modifiers
& wxMOD_SHIFT
)
6017 win_modifiers
|= MOD_SHIFT
;
6018 if ( modifiers
& wxMOD_CONTROL
)
6019 win_modifiers
|= MOD_CONTROL
;
6020 if ( modifiers
& wxMOD_WIN
)
6021 win_modifiers
|= MOD_WIN
;
6023 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6024 // Required for PPC and Smartphone hardware buttons
6025 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
6026 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
6029 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
6031 wxLogLastError(_T("RegisterHotKey"));
6039 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
6041 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6042 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
6045 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
6047 wxLogLastError(_T("UnregisterHotKey"));
6057 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
6059 int hotkeyId
= wParam
;
6060 int virtualKey
= HIWORD(lParam
);
6061 int win_modifiers
= LOWORD(lParam
);
6063 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
6064 event
.SetId(hotkeyId
);
6065 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
6066 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
6067 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
6068 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
6070 return GetEventHandler()->ProcessEvent(event
);
6073 #endif // wxUSE_ACCEL
6075 #endif // wxUSE_HOTKEY
6077 // Not tested under WinCE
6080 // this class installs a message hook which really wakes up our idle processing
6081 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
6082 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
6083 // being dragged or even inside ::MessageBox()) and so don't control message
6084 // dispatching otherwise
6085 class wxIdleWakeUpModule
: public wxModule
6088 virtual bool OnInit()
6090 ms_hMsgHookProc
= ::SetWindowsHookEx
6093 &wxIdleWakeUpModule::MsgHookProc
,
6095 GetCurrentThreadId()
6098 if ( !ms_hMsgHookProc
)
6100 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
6108 virtual void OnExit()
6110 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
6113 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
6115 MSG
*msg
= (MSG
*)lParam
;
6117 // only process the message if it is actually going to be removed from
6118 // the message queue, this prevents that the same event from being
6119 // processed multiple times if now someone just called PeekMessage()
6120 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
6122 wxTheApp
->ProcessPendingEvents();
6125 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
6129 static HHOOK ms_hMsgHookProc
;
6131 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
6134 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
6136 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
6138 #endif // __WXWINCE__
6143 static void wxAdjustZOrder(wxWindow
* parent
)
6145 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
6147 // Set the z-order correctly
6148 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
6151 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
6154 wxWindow
*childWin
= current
->GetData();
6155 wxAdjustZOrder(childWin
);
6156 current
= current
->GetNext();
6161 // We need to adjust the z-order of static boxes in WinCE, to
6162 // make 'contained' controls visible
6163 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
6166 wxAdjustZOrder(this);