1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/window.cpp
3 // Purpose: wxWindowMSW
4 // Author: Julian Smart
5 // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/window.h"
30 #include "wx/msw/wrapwin.h"
31 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/msw/missing.h"
36 #include "wx/dcclient.h"
37 #include "wx/dcmemory.h"
40 #include "wx/layout.h"
41 #include "wx/dialog.h"
43 #include "wx/listbox.h"
44 #include "wx/button.h"
45 #include "wx/msgdlg.h"
46 #include "wx/settings.h"
47 #include "wx/statbox.h"
51 #include "wx/textctrl.h"
52 #include "wx/menuitem.h"
53 #include "wx/module.h"
56 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
57 #include "wx/ownerdrw.h"
60 #include "wx/evtloop.h"
62 #include "wx/sysopt.h"
64 #if wxUSE_DRAG_AND_DROP
68 #if wxUSE_ACCESSIBILITY
69 #include "wx/access.h"
73 #define WM_GETOBJECT 0x003D
76 #define OBJID_CLIENT 0xFFFFFFFC
80 #include "wx/msw/private.h"
83 #include "wx/tooltip.h"
91 #include "wx/spinctrl.h"
92 #endif // wxUSE_SPINCTRL
94 #include "wx/notebook.h"
95 #include "wx/listctrl.h"
99 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
100 #include <shellapi.h>
101 #include <mmsystem.h>
105 #include <windowsx.h>
108 #if !defined __WXWINCE__ && !defined NEED_PBT_H
112 #if defined(__WXWINCE__)
113 #include "wx/msw/wince/missing.h"
116 #include <shellapi.h>
118 #include <aygshell.h>
122 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE)
123 #define HAVE_TRACKMOUSEEVENT
124 #endif // everything needed for TrackMouseEvent()
126 // if this is set to 1, we use deferred window sizing to reduce flicker when
127 // resizing complicated window hierarchies, but this can in theory result in
128 // different behaviour than the old code so we keep the possibility to use it
129 // by setting this to 0 (in the future this should be removed completely)
131 #define USE_DEFERRED_SIZING 0
133 #define USE_DEFERRED_SIZING 1
136 // set this to 1 to filter out duplicate mouse events, e.g. mouse move events
137 // when mouse position didnd't change
139 #define wxUSE_MOUSEEVENT_HACK 0
141 #define wxUSE_MOUSEEVENT_HACK 1
144 // ---------------------------------------------------------------------------
146 // ---------------------------------------------------------------------------
148 #if wxUSE_MENUS_NATIVE
149 wxMenu
*wxCurrentPopupMenu
= NULL
;
150 #endif // wxUSE_MENUS_NATIVE
153 extern wxChar
*wxCanvasClassName
;
155 extern const wxChar
*wxCanvasClassName
;
158 // true if we had already created the std colour map, used by
159 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
160 static bool gs_hasStdCmap
= false;
162 // last mouse event information we need to filter out the duplicates
163 #if wxUSE_MOUSEEVENT_HACK
164 static struct MouseEventInfoDummy
166 // mouse position (in screen coordinates)
169 // last mouse event type
172 #endif // wxUSE_MOUSEEVENT_HACK
174 // ---------------------------------------------------------------------------
176 // ---------------------------------------------------------------------------
178 // the window proc for all our windows
179 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
180 WPARAM wParam
, LPARAM lParam
);
184 const wxChar
*wxGetMessageName(int message
);
187 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
188 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
189 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
191 // get the text metrics for the current font
192 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
195 // find the window for the mouse event at the specified position
196 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
);
197 #endif // __WXWINCE__
199 // wrapper around BringWindowToTop() API
200 static inline void wxBringWindowToTop(HWND hwnd
)
202 #ifdef __WXMICROWIN__
203 // It seems that MicroWindows brings the _parent_ of the window to the top,
204 // which can be the wrong one.
206 // activate (set focus to) specified window
210 // raise top level parent to top of z order
211 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
213 wxLogLastError(_T("SetWindowPos"));
219 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
220 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
223 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
224 parent as well as otherwise several Win32 functions using
225 GetNextDlgTabItem() to iterate over all controls such as
226 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
227 all of them iterate over all the controls starting from the currently
228 focused one and stop iterating when they get back to the focus but
229 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
230 get back to the initial (focused) window: as we do have this style,
231 GetNextDlgTabItem() will leave this window and continue in its parent,
232 but if the parent doesn't have it, it wouldn't recurse inside it later
233 on and so wouldn't have a chance of getting back to this window either.
235 while ( parent
&& !parent
->IsTopLevel() )
237 LONG exStyle
= ::GetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
);
238 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
240 // force the parent to have this style
241 ::SetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
,
242 exStyle
| WS_EX_CONTROLPARENT
);
245 parent
= parent
->GetParent();
249 #endif // !__WXWINCE__
252 // On Windows CE, GetCursorPos can return an error, so use this function
254 bool GetCursorPosWinCE(POINT
* pt
)
256 if (!GetCursorPos(pt
))
258 DWORD pos
= GetMessagePos();
266 // ---------------------------------------------------------------------------
268 // ---------------------------------------------------------------------------
270 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
272 #ifdef __WXUNIVERSAL__
273 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
275 #if wxUSE_EXTENDED_RTTI
277 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
278 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
279 // windows with negative ids never can be recreated anyway
281 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
283 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
284 if ( win
&& win
->GetId() < 0 )
289 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
291 // make wxWindowList known before the property is used
293 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
295 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
297 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
300 WX_DEFINE_FLAGS( wxWindowStyle
)
302 wxBEGIN_FLAGS( wxWindowStyle
)
303 // new style border flags, we put them first to
304 // use them for streaming out
306 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
307 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
308 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
309 wxFLAGS_MEMBER(wxBORDER_RAISED
)
310 wxFLAGS_MEMBER(wxBORDER_STATIC
)
311 wxFLAGS_MEMBER(wxBORDER_NONE
)
313 // old style border flags
314 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
315 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
316 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
317 wxFLAGS_MEMBER(wxRAISED_BORDER
)
318 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
319 wxFLAGS_MEMBER(wxBORDER
)
321 // standard window styles
322 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
323 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
324 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
325 wxFLAGS_MEMBER(wxWANTS_CHARS
)
326 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
327 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
328 wxFLAGS_MEMBER(wxVSCROLL
)
329 wxFLAGS_MEMBER(wxHSCROLL
)
331 wxEND_FLAGS( wxWindowStyle
)
333 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
334 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
335 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
336 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
337 // Always constructor Properties first
339 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
340 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
341 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
342 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
343 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
345 // Then all relations of the object graph
347 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
349 // and finally all other properties
351 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
352 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
353 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
354 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
355 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
357 // possible property candidates (not in xrc) or not valid in all subclasses
358 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
359 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
360 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
361 // MaxHeight, Width , MinHeight , Width
362 // TODO switch label to control and title to toplevels
364 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
365 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
366 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
367 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
372 wxEND_PROPERTIES_TABLE()
374 wxBEGIN_HANDLERS_TABLE(wxWindow
)
375 wxEND_HANDLERS_TABLE()
377 wxCONSTRUCTOR_DUMMY(wxWindow
)
380 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
382 #endif // __WXUNIVERSAL__/__WXMSW__
384 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
385 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
386 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground
)
388 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
392 // ===========================================================================
394 // ===========================================================================
396 // ---------------------------------------------------------------------------
397 // wxWindow utility functions
398 // ---------------------------------------------------------------------------
400 // Find an item given the MS Windows id
401 wxWindow
*wxWindowMSW::FindItem(long id
) const
404 wxControl
*item
= wxDynamicCastThis(wxControl
);
407 // is it us or one of our "internal" children?
408 if ( item
->GetId() == id
409 #ifndef __WXUNIVERSAL__
410 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
411 #endif // __WXUNIVERSAL__
417 #endif // wxUSE_CONTROLS
419 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
422 wxWindow
*childWin
= current
->GetData();
424 wxWindow
*wnd
= childWin
->FindItem(id
);
428 current
= current
->GetNext();
434 // Find an item given the MS Windows handle
435 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
437 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
440 wxWindow
*parent
= current
->GetData();
442 // Do a recursive search.
443 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
449 || parent
->IsKindOf(CLASSINFO(wxControl
))
450 #endif // wxUSE_CONTROLS
453 wxWindow
*item
= current
->GetData();
454 if ( item
->GetHWND() == hWnd
)
458 if ( item
->ContainsHWND(hWnd
) )
463 current
= current
->GetNext();
468 // Default command handler
469 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
474 // ----------------------------------------------------------------------------
475 // constructors and such
476 // ----------------------------------------------------------------------------
478 void wxWindowMSW::Init()
481 m_isBeingDeleted
= false;
483 m_mouseInWindow
= false;
484 m_lastKeydownProcessed
= false;
486 m_childrenDisabled
= NULL
;
495 m_pendingPosition
= wxDefaultPosition
;
496 m_pendingSize
= wxDefaultSize
;
499 m_contextMenuEnabled
= false;
504 wxWindowMSW::~wxWindowMSW()
506 m_isBeingDeleted
= true;
508 #ifndef __WXUNIVERSAL__
509 // VS: make sure there's no wxFrame with last focus set to us:
510 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
512 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
515 if ( frame
->GetLastFocus() == this )
517 frame
->SetLastFocus(NULL
);
520 // apparently sometimes we can end up with our grand parent
521 // pointing to us as well: this is surely a bug in focus handling
522 // code but it's not clear where it happens so for now just try to
523 // fix it here by not breaking out of the loop
527 #endif // __WXUNIVERSAL__
529 // VS: destroy children first and _then_ detach *this from its parent.
530 // If we did it the other way around, children wouldn't be able
531 // find their parent frame (see above).
536 // VZ: test temp removed to understand what really happens here
537 //if (::IsWindow(GetHwnd()))
539 if ( !::DestroyWindow(GetHwnd()) )
540 wxLogLastError(wxT("DestroyWindow"));
543 // remove hWnd <-> wxWindow association
544 wxRemoveHandleAssociation(this);
547 delete m_childrenDisabled
;
551 // real construction (Init() must have been called before!)
552 bool wxWindowMSW::Create(wxWindow
*parent
,
557 const wxString
& name
)
559 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
561 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
564 parent
->AddChild(this);
567 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
569 #ifdef __WXUNIVERSAL__
570 // no borders, we draw them ourselves
571 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
575 msflags
&= ~WS_BORDER
;
576 #endif // wxUniversal
580 msflags
|= WS_VISIBLE
;
583 if ( !MSWCreate(wxCanvasClassName
, NULL
, pos
, size
, msflags
, exstyle
) )
591 // ---------------------------------------------------------------------------
593 // ---------------------------------------------------------------------------
595 void wxWindowMSW::SetFocus()
597 HWND hWnd
= GetHwnd();
598 wxCHECK_RET( hWnd
, _T("can't set focus to invalid window") );
600 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
604 if ( !::SetFocus(hWnd
) )
606 #if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
607 // was there really an error?
608 DWORD dwRes
= ::GetLastError();
611 HWND hwndFocus
= ::GetFocus();
612 if ( hwndFocus
!= hWnd
)
614 wxLogApiError(_T("SetFocus"), dwRes
);
621 void wxWindowMSW::SetFocusFromKbd()
623 // when the focus is given to the control with DLGC_HASSETSEL style from
624 // keyboard its contents should be entirely selected: this is what
625 // ::IsDialogMessage() does and so we should do it as well to provide the
626 // same LNF as the native programs
627 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
629 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
632 // do this after (maybe) setting the selection as like this when
633 // wxEVT_SET_FOCUS handler is called, the selection would have been already
634 // set correctly -- this may be important
635 wxWindowBase::SetFocusFromKbd();
638 // Get the window with the focus
639 wxWindow
*wxWindowBase::DoFindFocus()
641 HWND hWnd
= ::GetFocus();
644 return wxGetWindowFromHWND((WXHWND
)hWnd
);
650 bool wxWindowMSW::Enable(bool enable
)
652 if ( !wxWindowBase::Enable(enable
) )
655 HWND hWnd
= GetHwnd();
657 ::EnableWindow(hWnd
, (BOOL
)enable
);
659 // the logic below doesn't apply to the top level windows -- otherwise
660 // showing a modal dialog would result in total greying out (and ungreying
661 // out later) of everything which would be really ugly
665 // when the parent is disabled, all of its children should be disabled as
666 // well but when it is enabled back, only those of the children which
667 // hadn't been already disabled in the beginning should be enabled again,
668 // so we have to keep the list of those children
669 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
671 node
= node
->GetNext() )
673 wxWindow
*child
= node
->GetData();
674 if ( child
->IsTopLevel() )
676 // the logic below doesn't apply to top level children
682 // re-enable the child unless it had been disabled before us
683 if ( !m_childrenDisabled
|| !m_childrenDisabled
->Find(child
) )
686 else // we're being disabled
688 if ( child
->IsEnabled() )
690 // disable it as children shouldn't stay enabled while the
694 else // child already disabled, remember it
696 // have we created the list of disabled children already?
697 if ( !m_childrenDisabled
)
698 m_childrenDisabled
= new wxWindowList
;
700 m_childrenDisabled
->Append(child
);
705 if ( enable
&& m_childrenDisabled
)
707 // we don't need this list any more, don't keep unused memory
708 delete m_childrenDisabled
;
709 m_childrenDisabled
= NULL
;
715 bool wxWindowMSW::Show(bool show
)
717 if ( !wxWindowBase::Show(show
) )
720 HWND hWnd
= GetHwnd();
722 // we could be called before the underlying window is created (this is
723 // actually useful to prevent it from being initially shown), e.g.
725 // wxFoo *foo = new wxFoo;
727 // foo->Create(parent, ...);
729 // should work without errors
732 ::ShowWindow(hWnd
, show
? SW_SHOW
: SW_HIDE
);
738 // Raise the window to the top of the Z order
739 void wxWindowMSW::Raise()
741 wxBringWindowToTop(GetHwnd());
744 // Lower the window to the bottom of the Z order
745 void wxWindowMSW::Lower()
747 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
748 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
751 void wxWindowMSW::DoCaptureMouse()
753 HWND hWnd
= GetHwnd();
760 void wxWindowMSW::DoReleaseMouse()
762 if ( !::ReleaseCapture() )
764 wxLogLastError(_T("ReleaseCapture"));
768 /* static */ wxWindow
*wxWindowBase::GetCapture()
770 HWND hwnd
= ::GetCapture();
771 return hwnd
? wxFindWinFromHandle((WXHWND
)hwnd
) : (wxWindow
*)NULL
;
774 bool wxWindowMSW::SetFont(const wxFont
& font
)
776 if ( !wxWindowBase::SetFont(font
) )
782 HWND hWnd
= GetHwnd();
785 WXHANDLE hFont
= m_font
.GetResourceHandle();
787 wxASSERT_MSG( hFont
, wxT("should have valid font") );
789 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
794 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
796 if ( !wxWindowBase::SetCursor(cursor
) )
802 // don't "overwrite" busy cursor
803 if ( m_cursor
.Ok() && !wxIsBusy() )
805 ::SetCursor(GetHcursorOf(m_cursor
));
811 void wxWindowMSW::WarpPointer(int x
, int y
)
813 ClientToScreen(&x
, &y
);
815 if ( !::SetCursorPos(x
, y
) )
817 wxLogLastError(_T("SetCursorPos"));
821 void wxWindowMSW::MSWUpdateUIState(int action
, int state
)
823 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
824 // to use it on older systems -- and could possibly do some harm
825 static int s_needToUpdate
= -1;
826 if ( s_needToUpdate
== -1 )
829 s_needToUpdate
= wxGetOsVersion(&verMaj
, &verMin
) == wxOS_WINDOWS_NT
&&
833 if ( s_needToUpdate
)
835 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
836 // won't send WM_UPDATEUISTATE
837 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE
, MAKEWPARAM(action
, state
), 0);
841 // ---------------------------------------------------------------------------
843 // ---------------------------------------------------------------------------
845 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
847 #ifdef __WXMICROWIN__
848 return ::GetScrollPosWX(hWnd
, wOrient
);
850 WinStruct
<SCROLLINFO
> scrollInfo
;
851 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
852 scrollInfo
.fMask
= SIF_POS
;
853 ::GetScrollInfo(hWnd
, wOrient
, &scrollInfo
);
855 return scrollInfo
.nPos
;
860 int wxWindowMSW::GetScrollPos(int orient
) const
862 HWND hWnd
= GetHwnd();
863 wxCHECK_MSG( hWnd
, 0, _T("no HWND in GetScrollPos") );
865 return GetScrollPosition(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
);
868 // This now returns the whole range, not just the number
869 // of positions that we can scroll.
870 int wxWindowMSW::GetScrollRange(int orient
) const
873 HWND hWnd
= GetHwnd();
877 ::GetScrollRange(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
880 WinStruct
<SCROLLINFO
> scrollInfo
;
881 scrollInfo
.fMask
= SIF_RANGE
;
882 if ( !::GetScrollInfo(hWnd
,
883 orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
886 // Most of the time this is not really an error, since the return
887 // value can also be zero when there is no scrollbar yet.
888 // wxLogLastError(_T("GetScrollInfo"));
890 maxPos
= scrollInfo
.nMax
;
892 // undo "range - 1" done in SetScrollbar()
896 int wxWindowMSW::GetScrollThumb(int orient
) const
898 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
901 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
903 HWND hWnd
= GetHwnd();
904 wxCHECK_RET( hWnd
, _T("SetScrollPos: no HWND") );
906 WinStruct
<SCROLLINFO
> info
;
910 info
.fMask
= SIF_POS
;
911 if ( HasFlag(wxALWAYS_SHOW_SB
) )
913 // disable scrollbar instead of removing it then
914 info
.fMask
|= SIF_DISABLENOSCROLL
;
917 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
921 // New function that will replace some of the above.
922 void wxWindowMSW::SetScrollbar(int orient
,
928 WinStruct
<SCROLLINFO
> info
;
929 info
.nPage
= pageSize
;
930 info
.nMin
= 0; // range is nMax - nMin + 1
931 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
933 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
934 if ( HasFlag(wxALWAYS_SHOW_SB
) )
936 // disable scrollbar instead of removing it then
937 info
.fMask
|= SIF_DISABLENOSCROLL
;
940 HWND hWnd
= GetHwnd();
943 // We have to set the variables here to make them valid in events
944 // triggered by ::SetScrollInfo()
945 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
947 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
952 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
958 rect
.left
= prect
->x
;
960 rect
.right
= prect
->x
+ prect
->width
;
961 rect
.bottom
= prect
->y
+ prect
->height
;
971 // FIXME: is this the exact equivalent of the line below?
972 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
974 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
978 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
980 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
983 for ( int n
= 0; n
< count
; n
++ )
985 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
987 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
990 // don't bother to continue, we're already at top/bottom
997 return pos
!= posStart
;
1000 bool wxWindowMSW::ScrollLines(int lines
)
1002 bool down
= lines
> 0;
1004 return ScrollVertically(GetHwnd(),
1005 down
? SB_LINEDOWN
: SB_LINEUP
,
1006 down
? lines
: -lines
);
1009 bool wxWindowMSW::ScrollPages(int pages
)
1011 bool down
= pages
> 0;
1013 return ScrollVertically(GetHwnd(),
1014 down
? SB_PAGEDOWN
: SB_PAGEUP
,
1015 down
? pages
: -pages
);
1018 // ----------------------------------------------------------------------------
1020 // ----------------------------------------------------------------------------
1022 void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir
)
1027 const HWND hwnd
= GetHwnd();
1028 wxCHECK_RET( hwnd
, _T("layout direction must be set after window creation") );
1030 LONG styleOld
= ::GetWindowLong(hwnd
, GWL_EXSTYLE
);
1032 LONG styleNew
= styleOld
;
1035 case wxLayout_LeftToRight
:
1036 styleNew
&= ~WS_EX_LAYOUTRTL
;
1039 case wxLayout_RightToLeft
:
1040 styleNew
|= WS_EX_LAYOUTRTL
;
1044 wxFAIL_MSG(_T("unsupported layout direction"));
1048 if ( styleNew
!= styleOld
)
1050 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, styleNew
);
1055 wxLayoutDirection
wxWindowMSW::GetLayoutDirection() const
1058 return wxLayout_Default
;
1060 const HWND hwnd
= GetHwnd();
1061 wxCHECK_MSG( hwnd
, wxLayout_Default
, _T("invalid window") );
1063 return ::GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_LAYOUTRTL
1064 ? wxLayout_RightToLeft
1065 : wxLayout_LeftToRight
;
1070 wxWindowMSW::AdjustForLayoutDirection(wxCoord x
,
1071 wxCoord
WXUNUSED(width
),
1072 wxCoord
WXUNUSED(widthTotal
)) const
1074 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1075 // redo it ourselves
1079 // ---------------------------------------------------------------------------
1081 // ---------------------------------------------------------------------------
1083 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
1085 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
1087 HWND hwnd
= (HWND
)hWnd
;
1088 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
1090 wxAssociateWinWithHandle(hwnd
, this);
1092 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
1094 // we don't need to subclass the window of our own class (in the Windows
1095 // sense of the word)
1096 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
1098 wxSetWindowProc(hwnd
, wxWndProc
);
1102 // don't bother restoring it either: this also makes it easy to
1103 // implement IsOfStandardClass() method which returns true for the
1104 // standard controls and false for the wxWidgets own windows as it can
1105 // simply check m_oldWndProc
1106 m_oldWndProc
= NULL
;
1109 // we're officially created now, send the event
1110 wxWindowCreateEvent
event((wxWindow
*)this);
1111 (void)GetEventHandler()->ProcessEvent(event
);
1114 void wxWindowMSW::UnsubclassWin()
1116 wxRemoveHandleAssociation(this);
1118 // Restore old Window proc
1119 HWND hwnd
= GetHwnd();
1124 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1128 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1130 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1133 m_oldWndProc
= NULL
;
1138 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1142 if ( !::DestroyWindow(GetHwnd()) )
1143 wxLogLastError(wxT("DestroyWindow"));
1146 WXHWND wxhwnd
= (WXHWND
)handle
;
1149 SubclassWin(wxhwnd
);
1152 void wxWindowMSW::DissociateHandle()
1154 // this also calls SetHWND(0) for us
1159 bool wxCheckWindowWndProc(WXHWND hWnd
,
1160 WXFARPROC
WXUNUSED(wndProc
))
1162 // TODO: This list of window class names should be factored out so they can be
1163 // managed in one place and then accessed from here and other places, such as
1164 // wxApp::RegisterWindowClasses() and wxApp::UnregisterWindowClasses()
1167 extern wxChar
*wxCanvasClassName
;
1168 extern wxChar
*wxCanvasClassNameNR
;
1170 extern const wxChar
*wxCanvasClassName
;
1171 extern const wxChar
*wxCanvasClassNameNR
;
1173 extern const wxChar
*wxMDIFrameClassName
;
1174 extern const wxChar
*wxMDIFrameClassNameNoRedraw
;
1175 extern const wxChar
*wxMDIChildFrameClassName
;
1176 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
1177 wxString
str(wxGetWindowClass(hWnd
));
1178 if (str
== wxCanvasClassName
||
1179 str
== wxCanvasClassNameNR
||
1181 str
== _T("wxGLCanvasClass") ||
1182 str
== _T("wxGLCanvasClassNR") ||
1183 #endif // wxUSE_GLCANVAS
1184 str
== wxMDIFrameClassName
||
1185 str
== wxMDIFrameClassNameNoRedraw
||
1186 str
== wxMDIChildFrameClassName
||
1187 str
== wxMDIChildFrameClassNameNoRedraw
||
1188 str
== _T("wxTLWHiddenParent"))
1189 return true; // Effectively means don't subclass
1194 // ----------------------------------------------------------------------------
1196 // ----------------------------------------------------------------------------
1198 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1200 long flagsOld
= GetWindowStyleFlag();
1201 if ( flags
== flagsOld
)
1204 // update the internal variable
1205 wxWindowBase::SetWindowStyleFlag(flags
);
1207 // and the real window flags
1208 MSWUpdateStyle(flagsOld
, GetExtraStyle());
1211 void wxWindowMSW::SetExtraStyle(long exflags
)
1213 long exflagsOld
= GetExtraStyle();
1214 if ( exflags
== exflagsOld
)
1217 // update the internal variable
1218 wxWindowBase::SetExtraStyle(exflags
);
1220 // and the real window flags
1221 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld
);
1224 void wxWindowMSW::MSWUpdateStyle(long flagsOld
, long exflagsOld
)
1226 // now update the Windows style as well if needed - and if the window had
1227 // been already created
1231 // we may need to call SetWindowPos() when we change some styles
1232 bool callSWP
= false;
1235 long style
= MSWGetStyle(GetWindowStyleFlag(), &exstyle
);
1237 // this is quite a horrible hack but we need it because MSWGetStyle()
1238 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1239 // and so we have to modify the window exflags temporarily to get the
1240 // correct exstyleOld
1241 long exflagsNew
= GetExtraStyle();
1242 wxWindowBase::SetExtraStyle(exflagsOld
);
1245 long styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1247 wxWindowBase::SetExtraStyle(exflagsNew
);
1250 if ( style
!= styleOld
)
1252 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1253 // this function so instead of simply setting the style to the new
1254 // value we clear the bits which were set in styleOld but are set in
1255 // the new one and set the ones which were not set before
1256 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1257 styleReal
&= ~styleOld
;
1260 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1262 // we need to call SetWindowPos() if any of the styles affecting the
1263 // frame appearance have changed
1264 callSWP
= ((styleOld
^ style
) & (WS_BORDER
|
1273 // and the extended style
1274 long exstyleReal
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1276 if ( exstyle
!= exstyleOld
)
1278 exstyleReal
&= ~exstyleOld
;
1279 exstyleReal
|= exstyle
;
1281 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyleReal
);
1283 // ex style changes don't take effect without calling SetWindowPos
1289 // we must call SetWindowPos() to flush the cached extended style and
1290 // also to make the change to wxSTAY_ON_TOP style take effect: just
1291 // setting the style simply doesn't work
1292 if ( !::SetWindowPos(GetHwnd(),
1293 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1296 SWP_NOMOVE
| SWP_NOSIZE
| SWP_FRAMECHANGED
) )
1298 wxLogLastError(_T("SetWindowPos"));
1303 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1305 // translate common wxWidgets styles to Windows ones
1307 // most of windows are child ones, those which are not (such as
1308 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1309 WXDWORD style
= WS_CHILD
;
1311 // using this flag results in very significant reduction in flicker,
1312 // especially with controls inside the static boxes (as the interior of the
1313 // box is not redrawn twice), but sometimes results in redraw problems, so
1314 // optionally allow the old code to continue to use it provided a special
1315 // system option is turned on
1316 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1317 || (flags
& wxCLIP_CHILDREN
) )
1318 style
|= WS_CLIPCHILDREN
;
1320 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1321 // don't support overlapping windows and it only makes sense for them and,
1322 // presumably, gives the system some extra work (to manage more clipping
1323 // regions), so avoid it alltogether
1326 if ( flags
& wxVSCROLL
)
1327 style
|= WS_VSCROLL
;
1329 if ( flags
& wxHSCROLL
)
1330 style
|= WS_HSCROLL
;
1332 const wxBorder border
= GetBorder(flags
);
1334 // WS_BORDER is only required for wxBORDER_SIMPLE
1335 if ( border
== wxBORDER_SIMPLE
)
1338 // now deal with ext style if the caller wants it
1344 if ( flags
& wxTRANSPARENT_WINDOW
)
1345 *exstyle
|= WS_EX_TRANSPARENT
;
1351 case wxBORDER_DEFAULT
:
1352 wxFAIL_MSG( _T("unknown border style") );
1356 case wxBORDER_SIMPLE
:
1359 case wxBORDER_STATIC
:
1360 *exstyle
|= WS_EX_STATICEDGE
;
1363 case wxBORDER_RAISED
:
1364 *exstyle
|= WS_EX_DLGMODALFRAME
;
1367 case wxBORDER_SUNKEN
:
1368 *exstyle
|= WS_EX_CLIENTEDGE
;
1369 style
&= ~WS_BORDER
;
1372 case wxBORDER_DOUBLE
:
1373 *exstyle
|= WS_EX_DLGMODALFRAME
;
1377 // wxUniv doesn't use Windows dialog navigation functions at all
1378 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1379 // to make the dialog navigation work with the nested panels we must
1380 // use this style (top level windows such as dialogs don't need it)
1381 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1383 *exstyle
|= WS_EX_CONTROLPARENT
;
1385 #endif // __WXUNIVERSAL__
1391 // Setup background and foreground colours correctly
1392 void wxWindowMSW::SetupColours()
1395 SetBackgroundColour(GetParent()->GetBackgroundColour());
1398 bool wxWindowMSW::IsMouseInWindow() const
1400 // get the mouse position
1403 ::GetCursorPosWinCE(&pt
);
1405 ::GetCursorPos(&pt
);
1408 // find the window which currently has the cursor and go up the window
1409 // chain until we find this window - or exhaust it
1410 HWND hwnd
= ::WindowFromPoint(pt
);
1411 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1412 hwnd
= ::GetParent(hwnd
);
1414 return hwnd
!= NULL
;
1417 void wxWindowMSW::OnInternalIdle()
1419 #ifndef HAVE_TRACKMOUSEEVENT
1420 // Check if we need to send a LEAVE event
1421 if ( m_mouseInWindow
)
1423 // note that we should generate the leave event whether the window has
1424 // or doesn't have mouse capture
1425 if ( !IsMouseInWindow() )
1427 GenerateMouseLeave();
1430 #endif // !HAVE_TRACKMOUSEEVENT
1432 if (wxUpdateUIEvent::CanUpdate(this))
1433 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1436 // Set this window to be the child of 'parent'.
1437 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1439 if ( !wxWindowBase::Reparent(parent
) )
1442 HWND hWndChild
= GetHwnd();
1443 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1445 ::SetParent(hWndChild
, hWndParent
);
1448 if ( ::GetWindowLong(hWndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1450 EnsureParentHasControlParentStyle(GetParent());
1452 #endif // !__WXWINCE__
1457 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1459 #ifndef __WXMICROWIN__
1460 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1464 void wxWindowMSW::Freeze()
1466 if ( !m_frozenness
++ )
1469 SendSetRedraw(GetHwnd(), false);
1473 void wxWindowMSW::Thaw()
1475 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1477 if ( --m_frozenness
== 0 )
1481 SendSetRedraw(GetHwnd(), true);
1483 // we need to refresh everything or otherwise the invalidated area
1484 // is not going to be repainted
1490 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1492 HWND hWnd
= GetHwnd();
1499 mswRect
.left
= rect
->x
;
1500 mswRect
.top
= rect
->y
;
1501 mswRect
.right
= rect
->x
+ rect
->width
;
1502 mswRect
.bottom
= rect
->y
+ rect
->height
;
1511 // RedrawWindow not available on SmartPhone or eVC++ 3
1512 #if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
1513 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1517 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1519 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1524 void wxWindowMSW::Update()
1526 if ( !::UpdateWindow(GetHwnd()) )
1528 wxLogLastError(_T("UpdateWindow"));
1531 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1532 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1533 // handler needs to be really drawn right now
1538 // ---------------------------------------------------------------------------
1540 // ---------------------------------------------------------------------------
1542 #if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1546 // we need to lower the sibling static boxes so controls contained within can be
1548 static void AdjustStaticBoxZOrder(wxWindow
*parent
)
1550 // no sibling static boxes if we have no parent (ie TLW)
1554 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1556 node
= node
->GetNext() )
1558 wxStaticBox
*statbox
= wxDynamicCast(node
->GetData(), wxStaticBox
);
1561 ::SetWindowPos(GetHwndOf(statbox
), HWND_BOTTOM
, 0, 0, 0, 0,
1562 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
1567 #else // !wxUSE_STATBOX
1569 static inline void AdjustStaticBoxZOrder(wxWindow
* WXUNUSED(parent
))
1573 #endif // wxUSE_STATBOX/!wxUSE_STATBOX
1575 #endif // drag and drop is used
1577 #if wxUSE_DRAG_AND_DROP
1578 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1580 if ( m_dropTarget
!= 0 ) {
1581 m_dropTarget
->Revoke(m_hWnd
);
1582 delete m_dropTarget
;
1585 m_dropTarget
= pDropTarget
;
1586 if ( m_dropTarget
!= 0 )
1588 AdjustStaticBoxZOrder(GetParent());
1589 m_dropTarget
->Register(m_hWnd
);
1592 #endif // wxUSE_DRAG_AND_DROP
1594 // old-style file manager drag&drop support: we retain the old-style
1595 // DragAcceptFiles in parallel with SetDropTarget.
1596 void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept
))
1599 HWND hWnd
= GetHwnd();
1602 AdjustStaticBoxZOrder(GetParent());
1603 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1608 // ----------------------------------------------------------------------------
1610 // ----------------------------------------------------------------------------
1614 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1616 wxWindowBase::DoSetToolTip(tooltip
);
1619 m_tooltip
->SetWindow((wxWindow
*)this);
1622 #endif // wxUSE_TOOLTIPS
1624 // ---------------------------------------------------------------------------
1625 // moving and resizing
1626 // ---------------------------------------------------------------------------
1628 bool wxWindowMSW::IsSizeDeferred() const
1630 #if USE_DEFERRED_SIZING
1631 if ( m_pendingPosition
!= wxDefaultPosition
||
1632 m_pendingSize
!= wxDefaultSize
)
1634 #endif // USE_DEFERRED_SIZING
1640 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1642 #if USE_DEFERRED_SIZING
1643 // if SetSize() had been called at wx level but not realized at Windows
1644 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1645 // the new and not the old position to the other wx code
1646 if ( m_pendingSize
!= wxDefaultSize
)
1649 *x
= m_pendingSize
.x
;
1651 *y
= m_pendingSize
.y
;
1653 else // use current size
1654 #endif // USE_DEFERRED_SIZING
1656 RECT rect
= wxGetWindowRect(GetHwnd());
1659 *x
= rect
.right
- rect
.left
;
1661 *y
= rect
.bottom
- rect
.top
;
1665 // Get size *available for subwindows* i.e. excluding menu bar etc.
1666 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1668 #if USE_DEFERRED_SIZING
1669 if ( m_pendingSize
!= wxDefaultSize
)
1671 // we need to calculate the client size corresponding to pending size
1673 rect
.left
= m_pendingPosition
.x
;
1674 rect
.top
= m_pendingPosition
.y
;
1675 rect
.right
= rect
.left
+ m_pendingSize
.x
;
1676 rect
.bottom
= rect
.top
+ m_pendingSize
.y
;
1678 ::SendMessage(GetHwnd(), WM_NCCALCSIZE
, FALSE
, (LPARAM
)&rect
);
1681 *x
= rect
.right
- rect
.left
;
1683 *y
= rect
.bottom
- rect
.top
;
1686 #endif // USE_DEFERRED_SIZING
1688 RECT rect
= wxGetClientRect(GetHwnd());
1697 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1699 wxWindow
* const parent
= GetParent();
1702 if ( m_pendingPosition
!= wxDefaultPosition
)
1704 pos
= m_pendingPosition
;
1706 else // use current position
1708 RECT rect
= wxGetWindowRect(GetHwnd());
1711 point
.x
= rect
.left
;
1714 // we do the adjustments with respect to the parent only for the "real"
1715 // children, not for the dialogs/frames
1716 if ( !IsTopLevel() )
1718 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
1720 // In RTL mode, we want the logical left x-coordinate,
1721 // which would be the physical right x-coordinate.
1722 point
.x
= rect
.right
;
1725 // Since we now have the absolute screen coords, if there's a
1726 // parent we must subtract its top left corner
1729 ::ScreenToClient(GetHwndOf(parent
), &point
);
1737 // we also must adjust by the client area offset: a control which is just
1738 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1739 if ( parent
&& !IsTopLevel() )
1741 const wxPoint
pt(parent
->GetClientAreaOrigin());
1752 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1760 ::ScreenToClient(GetHwnd(), &pt
);
1768 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1776 ::ClientToScreen(GetHwnd(), &pt
);
1785 wxWindowMSW::DoMoveSibling(WXHWND hwnd
, int x
, int y
, int width
, int height
)
1787 #if USE_DEFERRED_SIZING
1788 // if our parent had prepared a defer window handle for us, use it (unless
1789 // we are a top level window)
1790 wxWindowMSW
* const parent
= IsTopLevel() ? NULL
: GetParent();
1792 HDWP hdwp
= parent
? (HDWP
)parent
->m_hDWP
: NULL
;
1795 hdwp
= ::DeferWindowPos(hdwp
, (HWND
)hwnd
, NULL
, x
, y
, width
, height
,
1796 SWP_NOZORDER
| SWP_NOOWNERZORDER
| SWP_NOACTIVATE
);
1799 wxLogLastError(_T("DeferWindowPos"));
1805 // hdwp must be updated as it may have been changed
1806 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1811 // did deferred move, remember new coordinates of the window as they're
1812 // different from what Windows would return for it
1816 // otherwise (or if deferring failed) move the window in place immediately
1817 #endif // USE_DEFERRED_SIZING
1818 if ( !::MoveWindow((HWND
)hwnd
, x
, y
, width
, height
, IsShown()) )
1820 wxLogLastError(wxT("MoveWindow"));
1823 // if USE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1824 // ignored otherwise
1828 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1830 // TODO: is this consistent with other platforms?
1831 // Still, negative width or height shouldn't be allowed
1837 if ( DoMoveSibling(m_hWnd
, x
, y
, width
, height
) )
1839 #if USE_DEFERRED_SIZING
1840 m_pendingPosition
= wxPoint(x
, y
);
1841 m_pendingSize
= wxSize(width
, height
);
1842 #endif // USE_DEFERRED_SIZING
1846 // set the size of the window: if the dimensions are positive, just use them,
1847 // but if any of them is equal to -1, it means that we must find the value for
1848 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1849 // which case -1 is a valid value for x and y)
1851 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1852 // the width/height to best suit our contents, otherwise we reuse the current
1854 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1856 // get the current size and position...
1857 int currentX
, currentY
;
1858 int currentW
, currentH
;
1860 GetPosition(¤tX
, ¤tY
);
1861 GetSize(¤tW
, ¤tH
);
1863 // ... and don't do anything (avoiding flicker) if it's already ok unless
1864 // we're forced to resize the window
1865 if ( x
== currentX
&& y
== currentY
&&
1866 width
== currentW
&& height
== currentH
&&
1867 !(sizeFlags
& wxSIZE_FORCE
) )
1872 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1874 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1877 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1879 wxSize size
= wxDefaultSize
;
1880 if ( width
== wxDefaultCoord
)
1882 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1884 size
= DoGetBestSize();
1889 // just take the current one
1894 if ( height
== wxDefaultCoord
)
1896 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1898 if ( size
.x
== wxDefaultCoord
)
1900 size
= DoGetBestSize();
1902 //else: already called DoGetBestSize() above
1908 // just take the current one
1913 DoMoveWindow(x
, y
, width
, height
);
1916 void wxWindowMSW::DoSetClientSize(int width
, int height
)
1918 // setting the client size is less obvious than it could have been
1919 // because in the result of changing the total size the window scrollbar
1920 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
1921 // doesn't take neither into account) and so the client size will not be
1922 // correct as the difference between the total and client size changes --
1923 // so we keep changing it until we get it right
1925 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1926 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1927 // may become 3 if the window had 0 size originally and so we didn't
1928 // calculate the scrollbar correction correctly during the first iteration)
1929 // but just to be on the safe side we check for it instead of making it an
1930 // "infinite" loop (i.e. leaving break inside as the only way to get out)
1931 for ( int i
= 0; i
< 4; i
++ )
1934 ::GetClientRect(GetHwnd(), &rectClient
);
1936 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
1937 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
1938 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
1943 // Find the difference between the entire window (title bar and all)
1944 // and the client area; add this to the new client size to move the
1947 ::GetWindowRect(GetHwnd(), &rectWin
);
1949 const int widthWin
= rectWin
.right
- rectWin
.left
,
1950 heightWin
= rectWin
.bottom
- rectWin
.top
;
1952 // MoveWindow positions the child windows relative to the parent, so
1953 // adjust if necessary
1954 if ( !IsTopLevel() )
1956 wxWindow
*parent
= GetParent();
1959 ::ScreenToClient(GetHwndOf(parent
), (POINT
*)&rectWin
);
1963 // don't call DoMoveWindow() because we want to move window immediately
1964 // and not defer it here as otherwise the value returned by
1965 // GetClient/WindowRect() wouldn't change as the window wouldn't be
1967 if ( !::MoveWindow(GetHwnd(),
1970 width
+ widthWin
- rectClient
.right
,
1971 height
+ heightWin
- rectClient
.bottom
,
1974 wxLogLastError(_T("MoveWindow"));
1979 // ---------------------------------------------------------------------------
1981 // ---------------------------------------------------------------------------
1983 int wxWindowMSW::GetCharHeight() const
1985 return wxGetTextMetrics(this).tmHeight
;
1988 int wxWindowMSW::GetCharWidth() const
1990 // +1 is needed because Windows apparently adds it when calculating the
1991 // dialog units size in pixels
1992 #if wxDIALOG_UNIT_COMPATIBILITY
1993 return wxGetTextMetrics(this).tmAveCharWidth
;
1995 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
1999 void wxWindowMSW::GetTextExtent(const wxString
& string
,
2001 int *descent
, int *externalLeading
,
2002 const wxFont
*theFont
) const
2004 wxASSERT_MSG( !theFont
|| theFont
->Ok(),
2005 _T("invalid font in GetTextExtent()") );
2009 fontToUse
= *theFont
;
2011 fontToUse
= GetFont();
2013 WindowHDC
hdc(GetHwnd());
2014 SelectInHDC
selectFont(hdc
, GetHfontOf(fontToUse
));
2018 ::GetTextExtentPoint32(hdc
, string
, string
.length(), &sizeRect
);
2019 GetTextMetrics(hdc
, &tm
);
2026 *descent
= tm
.tmDescent
;
2027 if ( externalLeading
)
2028 *externalLeading
= tm
.tmExternalLeading
;
2031 // ---------------------------------------------------------------------------
2033 // ---------------------------------------------------------------------------
2035 #if wxUSE_MENUS_NATIVE
2037 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2038 // immediately, without waiting for the next event loop iteration
2040 // NB: this function should probably be made public later as it can almost
2041 // surely replace wxYield() elsewhere as well
2042 static void wxYieldForCommandsOnly()
2044 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2045 // want to process it here)
2047 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
2049 if ( msg
.message
== WM_QUIT
)
2051 // if we retrieved a WM_QUIT, insert back into the message queue.
2052 ::PostQuitMessage(0);
2056 // luckily (as we don't have access to wxEventLoopImpl method from here
2057 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2059 ::TranslateMessage(&msg
);
2060 ::DispatchMessage(&msg
);
2064 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
2066 menu
->SetInvokingWindow(this);
2069 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
2071 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
2072 x
= mouse
.x
; y
= mouse
.y
;
2075 HWND hWnd
= GetHwnd();
2076 HMENU hMenu
= GetHmenuOf(menu
);
2080 ::ClientToScreen(hWnd
, &point
);
2081 wxCurrentPopupMenu
= menu
;
2082 #if defined(__WXWINCE__)
2085 UINT flags
= TPM_RIGHTBUTTON
| TPM_RECURSE
;
2087 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
2089 // we need to do it right now as otherwise the events are never going to be
2090 // sent to wxCurrentPopupMenu from HandleCommand()
2092 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2093 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2094 // destroyed as soon as we return (it can be a local variable in the caller
2095 // for example) and so we do need to process the event immediately
2096 wxYieldForCommandsOnly();
2098 wxCurrentPopupMenu
= NULL
;
2100 menu
->SetInvokingWindow(NULL
);
2105 #endif // wxUSE_MENUS_NATIVE
2107 // ===========================================================================
2108 // pre/post message processing
2109 // ===========================================================================
2111 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
2114 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
2116 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
2119 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
2121 // wxUniversal implements tab traversal itself
2122 #ifndef __WXUNIVERSAL__
2123 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
2125 // intercept dialog navigation keys
2126 MSG
*msg
= (MSG
*)pMsg
;
2128 // here we try to do all the job which ::IsDialogMessage() usually does
2130 if ( msg
->message
== WM_KEYDOWN
)
2132 bool bCtrlDown
= wxIsCtrlDown();
2133 bool bShiftDown
= wxIsShiftDown();
2135 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2136 // don't process it if it's the case (except for Ctrl-Tab/Enter
2137 // combinations which are always processed)
2138 LONG lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
2140 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2141 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2142 // it, of course, implies them
2143 if ( lDlgCode
& DLGC_WANTALLKEYS
)
2145 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
2148 bool bForward
= true,
2149 bWindowChange
= false,
2152 // should we process this message specially?
2153 bool bProcess
= true;
2154 switch ( msg
->wParam
)
2157 if ( lDlgCode
& DLGC_WANTTAB
) {
2161 // Ctrl-Tab cycles thru notebook pages
2162 bWindowChange
= bCtrlDown
;
2163 bForward
= !bShiftDown
;
2170 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2178 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
2187 // we treat PageUp/Dn as arrows because chances are that
2188 // a control which needs arrows also needs them for
2189 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
2190 if ( (lDlgCode
& DLGC_WANTARROWS
) || !bCtrlDown
)
2193 bWindowChange
= true;
2198 if ( (lDlgCode
& DLGC_WANTMESSAGE
) && !bCtrlDown
)
2200 // control wants to process Enter itself, don't
2201 // call IsDialogMessage() which would consume it
2206 // currently active button should get enter press even
2207 // if there is a default button elsewhere so check if
2208 // this window is a button first
2209 wxWindow
*btn
= NULL
;
2210 if ( lDlgCode
& DLGC_DEFPUSHBUTTON
)
2212 // let IsDialogMessage() handle this for all
2213 // buttons except the owner-drawn ones which it
2214 // just seems to ignore
2215 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
2216 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
2218 // emulate the button click
2219 btn
= wxFindWinFromHandle((WXHWND
)msg
->hwnd
);
2224 else // not a button itself, do we have default button?
2227 tlw
= wxDynamicCast(wxGetTopLevelParent(this),
2231 btn
= wxDynamicCast(tlw
->GetDefaultItem(),
2236 if ( btn
&& btn
->IsEnabled() )
2238 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
2242 #endif // wxUSE_BUTTON
2245 // map Enter presses into button presses on PDAs
2246 wxJoystickEvent
event(wxEVT_JOY_BUTTON_DOWN
);
2247 event
.SetEventObject(this);
2248 if ( GetEventHandler()->ProcessEvent(event
) )
2250 #endif // __WXWINCE__
2260 wxNavigationKeyEvent event
;
2261 event
.SetDirection(bForward
);
2262 event
.SetWindowChange(bWindowChange
);
2263 event
.SetFromTab(bFromTab
);
2264 event
.SetEventObject(this);
2266 if ( GetEventHandler()->ProcessEvent(event
) )
2268 // as we don't call IsDialogMessage(), which would take of
2269 // this by default, we need to manually send this message
2270 // so that controls can change their UI state if needed
2271 MSWUpdateUIState(UIS_CLEAR
, UISF_HIDEFOCUS
);
2278 if ( ::IsDialogMessage(GetHwnd(), msg
) )
2280 // IsDialogMessage() did something...
2284 #endif // __WXUNIVERSAL__
2289 // relay mouse move events to the tooltip control
2290 MSG
*msg
= (MSG
*)pMsg
;
2291 if ( msg
->message
== WM_MOUSEMOVE
)
2292 wxToolTip::RelayEvent(pMsg
);
2294 #endif // wxUSE_TOOLTIPS
2299 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2301 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2302 return m_acceleratorTable
.Translate(this, pMsg
);
2306 #endif // wxUSE_ACCEL
2309 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* msg
)
2311 // all tests below have to deal with various bugs/misfeatures of
2312 // IsDialogMessage(): we have to prevent it from being called from our
2313 // MSWProcessMessage() in some situations
2315 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2316 // message even when there is no cancel button and when the message is
2317 // needed by the control itself: in particular, it prevents the tree in
2318 // place edit control from being closed with Escape in a dialog
2319 if ( msg
->message
== WM_KEYDOWN
&& msg
->wParam
== VK_ESCAPE
)
2324 // ::IsDialogMessage() is broken and may sometimes hang the application by
2325 // going into an infinite loop when it tries to find the control to give
2326 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2327 // situations when this may happen and not call it then
2328 if ( msg
->message
!= WM_SYSCHAR
)
2331 // assume we can call it by default
2332 bool canSafelyCallIsDlgMsg
= true;
2334 HWND hwndFocus
= ::GetFocus();
2336 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2337 // ::IsDialogMessage() will also enter an infinite loop, because it will
2338 // recursively check the child windows but not the window itself and so if
2339 // none of the children accepts focus it loops forever (as it only stops
2340 // when it gets back to the window it started from)
2342 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2343 // style has the focus, it can happen. One such possibility is if
2344 // all windows are either toplevel, wxDialog, wxPanel or static
2345 // controls and no window can actually accept keyboard input.
2346 #if !defined(__WXWINCE__)
2347 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2349 // pessimistic by default
2350 canSafelyCallIsDlgMsg
= false;
2351 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2353 node
= node
->GetNext() )
2355 wxWindow
* const win
= node
->GetData();
2356 if ( win
->AcceptsFocus() &&
2357 !(::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
) &
2358 WS_EX_CONTROLPARENT
) )
2360 // it shouldn't hang...
2361 canSafelyCallIsDlgMsg
= true;
2367 #endif // !__WXWINCE__
2369 if ( canSafelyCallIsDlgMsg
)
2371 // ::IsDialogMessage() can enter in an infinite loop when the
2372 // currently focused window is disabled or hidden and its
2373 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2377 if ( !::IsWindowEnabled(hwndFocus
) ||
2378 !::IsWindowVisible(hwndFocus
) )
2380 // it would enter an infinite loop if we do this!
2381 canSafelyCallIsDlgMsg
= false;
2386 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2388 // it's a top level window, don't go further -- e.g. even
2389 // if the parent of a dialog is disabled, this doesn't
2390 // break navigation inside the dialog
2394 hwndFocus
= ::GetParent(hwndFocus
);
2398 return canSafelyCallIsDlgMsg
;
2401 // ---------------------------------------------------------------------------
2402 // message params unpackers
2403 // ---------------------------------------------------------------------------
2405 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2406 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2408 *id
= LOWORD(wParam
);
2409 *hwnd
= (WXHWND
)lParam
;
2410 *cmd
= HIWORD(wParam
);
2413 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2414 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2416 *state
= LOWORD(wParam
);
2417 *minimized
= HIWORD(wParam
);
2418 *hwnd
= (WXHWND
)lParam
;
2421 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2422 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2424 *code
= LOWORD(wParam
);
2425 *pos
= HIWORD(wParam
);
2426 *hwnd
= (WXHWND
)lParam
;
2429 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2430 WXHDC
*hdc
, WXHWND
*hwnd
)
2432 *hwnd
= (WXHWND
)lParam
;
2433 *hdc
= (WXHDC
)wParam
;
2436 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2437 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2439 *item
= (WXWORD
)wParam
;
2440 *flags
= HIWORD(wParam
);
2441 *hmenu
= (WXHMENU
)lParam
;
2444 // ---------------------------------------------------------------------------
2445 // Main wxWidgets window proc and the window proc for wxWindow
2446 // ---------------------------------------------------------------------------
2448 // Hook for new window just as it's being created, when the window isn't yet
2449 // associated with the handle
2450 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2452 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2453 // window being created and insures that it's always unset back later
2454 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2456 gs_winBeingCreated
= winBeingCreated
;
2459 wxWindowCreationHook::~wxWindowCreationHook()
2461 gs_winBeingCreated
= NULL
;
2465 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2467 // trace all messages - useful for the debugging
2469 wxLogTrace(wxTraceMessages
,
2470 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2471 wxGetMessageName(message
), (long)hWnd
, (long)wParam
, lParam
);
2472 #endif // __WXDEBUG__
2474 wxWindowMSW
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
2476 // when we get the first message for the HWND we just created, we associate
2477 // it with wxWindow stored in gs_winBeingCreated
2478 if ( !wnd
&& gs_winBeingCreated
)
2480 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2481 wnd
= gs_winBeingCreated
;
2482 gs_winBeingCreated
= NULL
;
2483 wnd
->SetHWND((WXHWND
)hWnd
);
2488 if ( wnd
&& wxEventLoop::AllowProcessing(wnd
) )
2489 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2491 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2496 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2498 // did we process the message?
2499 bool processed
= false;
2509 // for most messages we should return 0 when we do process the message
2517 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2520 // return 0 to allow window creation
2521 rc
.result
= mayCreate
? 0 : -1;
2527 // never set processed to true and *always* pass WM_DESTROY to
2528 // DefWindowProc() as Windows may do some internal cleanup when
2529 // processing it and failing to pass the message along may cause
2530 // memory and resource leaks!
2531 (void)HandleDestroy();
2535 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2539 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2542 #if !defined(__WXWINCE__)
2545 LPRECT pRect
= (LPRECT
)lParam
;
2547 rc
.SetLeft(pRect
->left
);
2548 rc
.SetTop(pRect
->top
);
2549 rc
.SetRight(pRect
->right
);
2550 rc
.SetBottom(pRect
->bottom
);
2551 processed
= HandleMoving(rc
);
2553 pRect
->left
= rc
.GetLeft();
2554 pRect
->top
= rc
.GetTop();
2555 pRect
->right
= rc
.GetRight();
2556 pRect
->bottom
= rc
.GetBottom();
2563 LPRECT pRect
= (LPRECT
)lParam
;
2565 rc
.SetLeft(pRect
->left
);
2566 rc
.SetTop(pRect
->top
);
2567 rc
.SetRight(pRect
->right
);
2568 rc
.SetBottom(pRect
->bottom
);
2569 processed
= HandleSizing(rc
);
2571 pRect
->left
= rc
.GetLeft();
2572 pRect
->top
= rc
.GetTop();
2573 pRect
->right
= rc
.GetRight();
2574 pRect
->bottom
= rc
.GetBottom();
2578 #endif // !__WXWINCE__
2580 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2581 case WM_ACTIVATEAPP
:
2582 // This implicitly sends a wxEVT_ACTIVATE_APP event
2583 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2589 WXWORD state
, minimized
;
2591 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2593 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2598 processed
= HandleSetFocus((WXHWND
)(HWND
)wParam
);
2602 processed
= HandleKillFocus((WXHWND
)(HWND
)wParam
);
2605 case WM_PRINTCLIENT
:
2606 processed
= HandlePrintClient((WXHDC
)wParam
);
2612 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2614 processed
= HandlePaint();
2618 processed
= HandlePaint();
2623 #ifdef __WXUNIVERSAL__
2624 // Universal uses its own wxFrame/wxDialog, so we don't receive
2625 // close events unless we have this.
2627 #endif // __WXUNIVERSAL__
2629 // don't let the DefWindowProc() destroy our window - we'll do it
2630 // ourselves in ~wxWindow
2636 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2640 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2641 GET_Y_LPARAM(lParam
),
2645 #ifdef HAVE_TRACKMOUSEEVENT
2647 // filter out excess WM_MOUSELEAVE events sent after PopupMenu() (on XP at least)
2648 if ( m_mouseInWindow
)
2650 GenerateMouseLeave();
2653 // always pass processed back as false, this allows the window
2654 // manager to process the message too. This is needed to
2655 // ensure windows XP themes work properly as the mouse moves
2656 // over widgets like buttons. So don't set processed to true here.
2658 #endif // HAVE_TRACKMOUSEEVENT
2660 #if wxUSE_MOUSEWHEEL
2662 processed
= HandleMouseWheel(wParam
, lParam
);
2666 case WM_LBUTTONDOWN
:
2668 case WM_LBUTTONDBLCLK
:
2669 case WM_RBUTTONDOWN
:
2671 case WM_RBUTTONDBLCLK
:
2672 case WM_MBUTTONDOWN
:
2674 case WM_MBUTTONDBLCLK
:
2676 #ifdef __WXMICROWIN__
2677 // MicroWindows seems to ignore the fact that a window is
2678 // disabled. So catch mouse events and throw them away if
2680 wxWindowMSW
* win
= this;
2683 if (!win
->IsEnabled())
2689 win
= win
->GetParent();
2690 if ( !win
|| win
->IsTopLevel() )
2697 #endif // __WXMICROWIN__
2698 int x
= GET_X_LPARAM(lParam
),
2699 y
= GET_Y_LPARAM(lParam
);
2702 // redirect the event to a static control if necessary by
2703 // finding one under mouse because under CE the static controls
2704 // don't generate mouse events (even with SS_NOTIFY)
2706 if ( GetCapture() == this )
2708 // but don't do it if the mouse is captured by this window
2709 // because then it should really get this event itself
2714 win
= FindWindowForMouseEvent(this, &x
, &y
);
2716 // this should never happen
2717 wxCHECK_MSG( win
, 0,
2718 _T("FindWindowForMouseEvent() returned NULL") );
2721 if (IsContextMenuEnabled() && message
== WM_LBUTTONDOWN
)
2723 SHRGINFO shrgi
= {0};
2725 shrgi
.cbSize
= sizeof(SHRGINFO
);
2726 shrgi
.hwndClient
= (HWND
) GetHWND();
2730 shrgi
.dwFlags
= SHRG_RETURNCMD
;
2731 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
2733 if (GN_CONTEXTMENU
== ::SHRecognizeGesture(&shrgi
))
2736 pt
= ClientToScreen(pt
);
2738 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2740 evtCtx
.SetEventObject(this);
2741 if (GetEventHandler()->ProcessEvent(evtCtx
))
2750 #else // !__WXWINCE__
2751 wxWindowMSW
*win
= this;
2752 #endif // __WXWINCE__/!__WXWINCE__
2754 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2756 // if the app didn't eat the event, handle it in the default
2757 // way, that is by giving this window the focus
2760 // for the standard classes their WndProc sets the focus to
2761 // them anyhow and doing it from here results in some weird
2762 // problems, so don't do it for them (unnecessary anyhow)
2763 if ( !win
->IsOfStandardClass() )
2765 if ( message
== WM_LBUTTONDOWN
&& win
->AcceptsFocus() )
2777 case MM_JOY1BUTTONDOWN
:
2778 case MM_JOY2BUTTONDOWN
:
2779 case MM_JOY1BUTTONUP
:
2780 case MM_JOY2BUTTONUP
:
2781 processed
= HandleJoystickEvent(message
,
2782 GET_X_LPARAM(lParam
),
2783 GET_Y_LPARAM(lParam
),
2786 #endif // __WXMICROWIN__
2792 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2794 processed
= HandleCommand(id
, cmd
, hwnd
);
2799 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2802 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
2803 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
2804 // apparently doesn't always behave properly and needs some help
2805 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
2806 case WM_NOTIFYFORMAT
:
2807 if ( lParam
== NF_QUERY
)
2810 rc
.result
= NFR_UNICODE
;
2813 #endif // wxUSE_UNICODE_MSLU
2815 // for these messages we must return true if process the message
2818 case WM_MEASUREITEM
:
2820 int idCtrl
= (UINT
)wParam
;
2821 if ( message
== WM_DRAWITEM
)
2823 processed
= MSWOnDrawItem(idCtrl
,
2824 (WXDRAWITEMSTRUCT
*)lParam
);
2828 processed
= MSWOnMeasureItem(idCtrl
,
2829 (WXMEASUREITEMSTRUCT
*)lParam
);
2836 #endif // defined(WM_DRAWITEM)
2839 if ( !IsOfStandardClass() )
2841 // we always want to get the char events
2842 rc
.result
= DLGC_WANTCHARS
;
2844 if ( GetWindowStyleFlag() & wxWANTS_CHARS
)
2846 // in fact, we want everything
2847 rc
.result
|= DLGC_WANTARROWS
|
2854 //else: get the dlg code from the DefWindowProc()
2859 // If this has been processed by an event handler, return 0 now
2860 // (we've handled it).
2861 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
2862 if ( m_lastKeydownProcessed
)
2871 // we consider these messages "not interesting" to OnChar, so
2872 // just don't do anything more with them
2882 // avoid duplicate messages to OnChar for these ASCII keys:
2883 // they will be translated by TranslateMessage() and received
2915 // but set processed to false, not true to still pass them
2916 // to the control's default window proc - otherwise
2917 // built-in keyboard handling won't work
2922 // special case of VK_APPS: treat it the same as right mouse
2923 // click because both usually pop up a context menu
2925 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
2930 // do generate a CHAR event
2931 processed
= HandleChar((WORD
)wParam
, lParam
);
2934 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
2941 // special case of VK_APPS: treat it the same as right mouse button
2942 if ( wParam
== VK_APPS
)
2944 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
2949 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
2954 case WM_CHAR
: // Always an ASCII character
2955 if ( m_lastKeydownProcessed
)
2957 // The key was handled in the EVT_KEY_DOWN and handling
2958 // a key in an EVT_KEY_DOWN handler is meant, by
2959 // design, to prevent EVT_CHARs from happening
2960 m_lastKeydownProcessed
= false;
2965 processed
= HandleChar((WORD
)wParam
, lParam
, true);
2971 processed
= HandleHotKey((WORD
)wParam
, lParam
);
2973 #endif // wxUSE_HOTKEY
2980 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
2982 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
2988 // CTLCOLOR messages are sent by children to query the parent for their
2990 #ifndef __WXMICROWIN__
2991 case WM_CTLCOLORMSGBOX
:
2992 case WM_CTLCOLOREDIT
:
2993 case WM_CTLCOLORLISTBOX
:
2994 case WM_CTLCOLORBTN
:
2995 case WM_CTLCOLORDLG
:
2996 case WM_CTLCOLORSCROLLBAR
:
2997 case WM_CTLCOLORSTATIC
:
3001 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
3003 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
3006 #endif // !__WXMICROWIN__
3008 case WM_SYSCOLORCHANGE
:
3009 // the return value for this message is ignored
3010 processed
= HandleSysColorChange();
3013 #if !defined(__WXWINCE__)
3014 case WM_DISPLAYCHANGE
:
3015 processed
= HandleDisplayChange();
3019 case WM_PALETTECHANGED
:
3020 processed
= HandlePaletteChanged((WXHWND
) (HWND
) wParam
);
3023 case WM_CAPTURECHANGED
:
3024 processed
= HandleCaptureChanged((WXHWND
) (HWND
) lParam
);
3027 case WM_SETTINGCHANGE
:
3028 processed
= HandleSettingChange(wParam
, lParam
);
3031 case WM_QUERYNEWPALETTE
:
3032 processed
= HandleQueryNewPalette();
3036 processed
= HandleEraseBkgnd((WXHDC
)(HDC
)wParam
);
3039 // we processed the message, i.e. erased the background
3044 #if !defined(__WXWINCE__)
3046 processed
= HandleDropFiles(wParam
);
3051 processed
= HandleInitDialog((WXHWND
)(HWND
)wParam
);
3055 // we never set focus from here
3060 #if !defined(__WXWINCE__)
3061 case WM_QUERYENDSESSION
:
3062 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
3066 processed
= HandleEndSession(wParam
!= 0, lParam
);
3069 case WM_GETMINMAXINFO
:
3070 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
3075 processed
= HandleSetCursor((WXHWND
)(HWND
)wParam
,
3076 LOWORD(lParam
), // hit test
3077 HIWORD(lParam
)); // mouse msg
3081 // returning TRUE stops the DefWindowProc() from further
3082 // processing this message - exactly what we need because we've
3083 // just set the cursor.
3088 #if wxUSE_ACCESSIBILITY
3091 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3092 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
3094 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
3096 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
3102 #if defined(WM_HELP)
3105 // by default, WM_HELP is propagated by DefWindowProc() upwards
3106 // to the window parent but as we do it ourselves already
3107 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3108 // to get the other events if we process this message at all
3111 // WM_HELP doesn't use lParam under CE
3113 HELPINFO
* info
= (HELPINFO
*) lParam
;
3114 if ( info
->iContextType
== HELPINFO_WINDOW
)
3116 #endif // !__WXWINCE__
3117 wxHelpEvent helpEvent
3122 wxGetMousePosition() // what else?
3124 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
3128 helpEvent
.SetEventObject(this);
3129 GetEventHandler()->ProcessEvent(helpEvent
);
3132 else if ( info
->iContextType
== HELPINFO_MENUITEM
)
3134 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
3135 helpEvent
.SetEventObject(this);
3136 GetEventHandler()->ProcessEvent(helpEvent
);
3139 else // unknown help event?
3143 #endif // !__WXWINCE__
3148 #if !defined(__WXWINCE__)
3149 case WM_CONTEXTMENU
:
3151 // we don't convert from screen to client coordinates as
3152 // the event may be handled by a parent window
3153 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
3155 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
3157 // we could have got an event from our child, reflect it back
3158 // to it if this is the case
3159 wxWindowMSW
*win
= NULL
;
3160 if ( (WXHWND
)wParam
!= m_hWnd
)
3162 win
= FindItemByHWND((WXHWND
)wParam
);
3168 evtCtx
.SetEventObject(win
);
3169 processed
= win
->GetEventHandler()->ProcessEvent(evtCtx
);
3175 // we're only interested in our own menus, not MF_SYSMENU
3176 if ( HIWORD(wParam
) == MF_POPUP
)
3178 // handle menu chars for ownerdrawn menu items
3179 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
3180 if ( i
!= wxNOT_FOUND
)
3182 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
3189 case WM_POWERBROADCAST
:
3192 processed
= HandlePower(wParam
, lParam
, &vetoed
);
3193 rc
.result
= processed
&& vetoed
? BROADCAST_QUERY_DENY
: TRUE
;
3196 #endif // __WXWINCE__
3202 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
3203 wxGetMessageName(message
));
3204 #endif // __WXDEBUG__
3205 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
3211 // ----------------------------------------------------------------------------
3212 // wxWindow <-> HWND map
3213 // ----------------------------------------------------------------------------
3215 wxWinHashTable
*wxWinHandleHash
= NULL
;
3217 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
3219 return (wxWindow
*)wxWinHandleHash
->Get((long)hWnd
);
3222 void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
)
3224 // adding NULL hWnd is (first) surely a result of an error and
3225 // (secondly) breaks menu command processing
3226 wxCHECK_RET( hWnd
!= (HWND
)NULL
,
3227 wxT("attempt to add a NULL hWnd to window list ignored") );
3229 wxWindow
*oldWin
= wxFindWinFromHandle((WXHWND
) hWnd
);
3231 if ( oldWin
&& (oldWin
!= win
) )
3233 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
3234 (int) hWnd
, win
->GetClassInfo()->GetClassName());
3237 #endif // __WXDEBUG__
3240 wxWinHandleHash
->Put((long)hWnd
, (wxWindow
*)win
);
3244 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
3246 wxWinHandleHash
->Delete((long)win
->GetHWND());
3249 // ----------------------------------------------------------------------------
3250 // various MSW speciic class dependent functions
3251 // ----------------------------------------------------------------------------
3253 // Default destroyer - override if you destroy it in some other way
3254 // (e.g. with MDI child windows)
3255 void wxWindowMSW::MSWDestroyWindow()
3259 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
3262 int& w
, int& h
) const
3264 // yes, those are just some arbitrary hardcoded numbers
3265 static const int DEFAULT_Y
= 200;
3267 bool nonDefault
= false;
3269 if ( pos
.x
== wxDefaultCoord
)
3271 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
3272 // can just as well set it to CW_USEDEFAULT as well
3278 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
3279 // neither because it is not handled as a special value by Windows then
3280 // and so we have to choose some default value for it
3282 y
= pos
.y
== wxDefaultCoord
? DEFAULT_Y
: pos
.y
;
3288 NB: there used to be some code here which set the initial size of the
3289 window to the client size of the parent if no explicit size was
3290 specified. This was wrong because wxWidgets programs often assume
3291 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3292 it. To see why, you should understand that Windows sends WM_SIZE from
3293 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3294 from some base class ctor and so this WM_SIZE is not processed in the
3295 real class' OnSize() (because it's not fully constructed yet and the
3296 event goes to some base class OnSize() instead). So the WM_SIZE we
3297 rely on is the one sent when the parent frame resizes its children
3298 but here is the problem: if the child already has just the right
3299 size, nothing will happen as both wxWidgets and Windows check for
3300 this and ignore any attempts to change the window size to the size it
3301 already has - so no WM_SIZE would be sent.
3305 // we don't use CW_USEDEFAULT here for several reasons:
3307 // 1. it results in huge frames on modern screens (1000*800 is not
3308 // uncommon on my 1280*1024 screen) which is way too big for a half
3309 // empty frame of most of wxWidgets samples for example)
3311 // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
3312 // the default is for whatever reason 8*8 which breaks client <->
3313 // window size calculations (it would be nice if it didn't, but it
3314 // does and the simplest way to fix it seemed to change the broken
3315 // default size anyhow)
3317 // 3. there is just no advantage in doing it: with x and y it is
3318 // possible that [future versions of] Windows position the new top
3319 // level window in some smart way which we can't do, but we can
3320 // guess a reasonably good size for a new window just as well
3323 // However, on PocketPC devices, we must use the default
3324 // size if possible.
3326 if (size
.x
== wxDefaultCoord
)
3330 if (size
.y
== wxDefaultCoord
)
3335 if ( size
.x
== wxDefaultCoord
|| size
.y
== wxDefaultCoord
)
3339 w
= WidthDefault(size
.x
);
3340 h
= HeightDefault(size
.y
);
3343 AdjustForParentClientOrigin(x
, y
);
3348 WXHWND
wxWindowMSW::MSWGetParent() const
3350 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3353 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3354 const wxChar
*title
,
3358 WXDWORD extendedStyle
)
3360 // choose the position/size for the new window
3362 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3364 // controlId is menu handle for the top level windows, so set it to 0
3365 // unless we're creating a child window
3366 int controlId
= style
& WS_CHILD
? GetId() : 0;
3368 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3369 // which is the same but without CS_[HV]REDRAW class styles so using it
3370 // ensures that the window is not fully repainted on each resize
3371 wxString
className(wclass
);
3372 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3374 className
+= wxT("NR");
3377 // do create the window
3378 wxWindowCreationHook
hook(this);
3380 m_hWnd
= (WXHWND
)::CreateWindowEx
3384 title
? title
: m_windowName
.c_str(),
3387 (HWND
)MSWGetParent(),
3390 NULL
// no extra data
3395 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3400 SubclassWin(m_hWnd
);
3405 // ===========================================================================
3406 // MSW message handlers
3407 // ===========================================================================
3409 // ---------------------------------------------------------------------------
3411 // ---------------------------------------------------------------------------
3413 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3415 #ifndef __WXMICROWIN__
3416 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3417 HWND hWnd
= hdr
->hwndFrom
;
3418 wxWindow
*win
= wxFindWinFromHandle((WXHWND
)hWnd
);
3420 // if the control is one of our windows, let it handle the message itself
3423 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3426 // VZ: why did we do it? normally this is unnecessary and, besides, it
3427 // breaks the message processing for the toolbars because the tooltip
3428 // notifications were being forwarded to the toolbar child controls
3429 // (if it had any) before being passed to the toolbar itself, so in my
3430 // example the tooltip for the combobox was always shown instead of the
3431 // correct button tooltips
3433 // try all our children
3434 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3437 wxWindow
*child
= node
->GetData();
3438 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3443 node
= node
->GetNext();
3447 // by default, handle it ourselves
3448 return MSWOnNotify(idCtrl
, lParam
, result
);
3449 #else // __WXMICROWIN__
3456 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3458 const wxString
& ttip
)
3460 // I don't know why it happens, but the versions of comctl32.dll starting
3461 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3462 // this message is supposed to be sent to Unicode programs only) -- hence
3463 // we need to handle it as well, otherwise no tooltips will be shown in
3466 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3469 // not a tooltip message or no tooltip to show anyhow
3474 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3476 // We don't want to use the szText buffer because it has a limit of 80
3477 // bytes and this is not enough, especially for Unicode build where it
3478 // limits the tooltip string length to only 40 characters
3480 // The best would be, of course, to not impose any length limitations at
3481 // all but then the buffer would have to be dynamic and someone would have
3482 // to free it and we don't have the tooltip owner object here any more, so
3483 // for now use our own static buffer with a higher fixed max length.
3485 // Note that using a static buffer should not be a problem as only a single
3486 // tooltip can be shown at the same time anyhow.
3488 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3490 // We need to convert tooltip from multi byte to Unicode on the fly.
3491 static wchar_t buf
[513];
3493 // Truncate tooltip length if needed as otherwise we might not have
3494 // enough space for it in the buffer and MultiByteToWideChar() would
3496 size_t tipLength
= wxMin(ttip
.length(), WXSIZEOF(buf
) - 1);
3498 // Convert to WideChar without adding the NULL character. The NULL
3499 // character is added afterwards (this is more efficient).
3500 int len
= ::MultiByteToWideChar
3512 wxLogLastError(_T("MultiByteToWideChar()"));
3516 ttText
->lpszText
= (LPSTR
) buf
;
3518 else // TTN_NEEDTEXTA
3519 #endif // !wxUSE_UNICODE
3521 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3522 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3523 // to copy the string we have into the buffer
3524 static wxChar buf
[513];
3525 wxStrncpy(buf
, ttip
.c_str(), WXSIZEOF(buf
) - 1);
3526 buf
[WXSIZEOF(buf
) - 1] = _T('\0');
3527 ttText
->lpszText
= buf
;
3533 #endif // wxUSE_TOOLTIPS
3535 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3537 WXLPARAM
* WXUNUSED(result
))
3542 NMHDR
* hdr
= (NMHDR
*)lParam
;
3543 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3550 wxUnusedVar(lParam
);
3551 #endif // wxUSE_TOOLTIPS
3556 // ---------------------------------------------------------------------------
3557 // end session messages
3558 // ---------------------------------------------------------------------------
3560 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3562 #ifdef ENDSESSION_LOGOFF
3563 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3564 event
.SetEventObject(wxTheApp
);
3565 event
.SetCanVeto(true);
3566 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3568 bool rc
= wxTheApp
->ProcessEvent(event
);
3572 // we may end only if the app didn't veto session closing (double
3574 *mayEnd
= !event
.GetVeto();
3579 wxUnusedVar(logOff
);
3580 wxUnusedVar(mayEnd
);
3585 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3587 #ifdef ENDSESSION_LOGOFF
3588 // do nothing if the session isn't ending
3593 if ( (this != wxTheApp
->GetTopWindow()) )
3596 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3597 event
.SetEventObject(wxTheApp
);
3598 event
.SetCanVeto(false);
3599 event
.SetLoggingOff( (logOff
== (long)ENDSESSION_LOGOFF
) );
3601 return wxTheApp
->ProcessEvent(event
);
3603 wxUnusedVar(endSession
);
3604 wxUnusedVar(logOff
);
3609 // ---------------------------------------------------------------------------
3610 // window creation/destruction
3611 // ---------------------------------------------------------------------------
3613 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT
WXUNUSED_IN_WINCE(cs
),
3616 // VZ: why is this commented out for WinCE? If it doesn't support
3617 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3618 // not with multiple #ifdef's!
3620 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3621 EnsureParentHasControlParentStyle(GetParent());
3622 #endif // !__WXWINCE__
3629 bool wxWindowMSW::HandleDestroy()
3633 // delete our drop target if we've got one
3634 #if wxUSE_DRAG_AND_DROP
3635 if ( m_dropTarget
!= NULL
)
3637 m_dropTarget
->Revoke(m_hWnd
);
3639 delete m_dropTarget
;
3640 m_dropTarget
= NULL
;
3642 #endif // wxUSE_DRAG_AND_DROP
3644 // WM_DESTROY handled
3648 // ---------------------------------------------------------------------------
3650 // ---------------------------------------------------------------------------
3652 bool wxWindowMSW::HandleActivate(int state
,
3653 bool WXUNUSED(minimized
),
3654 WXHWND
WXUNUSED(activate
))
3656 wxActivateEvent
event(wxEVT_ACTIVATE
,
3657 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3659 event
.SetEventObject(this);
3661 return GetEventHandler()->ProcessEvent(event
);
3664 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3666 // Strangly enough, some controls get set focus events when they are being
3667 // deleted, even if they already had focus before.
3668 if ( m_isBeingDeleted
)
3673 // notify the parent keeping track of focus for the kbd navigation
3674 // purposes that we got it
3675 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3676 (void)GetEventHandler()->ProcessEvent(eventFocus
);
3682 m_caret
->OnSetFocus();
3684 #endif // wxUSE_CARET
3687 // If it's a wxTextCtrl don't send the event as it will be done
3688 // after the control gets to process it from EN_FOCUS handler
3689 if ( wxDynamicCastThis(wxTextCtrl
) )
3693 #endif // wxUSE_TEXTCTRL
3695 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3696 event
.SetEventObject(this);
3698 // wxFindWinFromHandle() may return NULL, it is ok
3699 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3701 return GetEventHandler()->ProcessEvent(event
);
3704 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
3710 m_caret
->OnKillFocus();
3712 #endif // wxUSE_CARET
3715 // If it's a wxTextCtrl don't send the event as it will be done
3716 // after the control gets to process it.
3717 wxTextCtrl
*ctrl
= wxDynamicCastThis(wxTextCtrl
);
3724 // Don't send the event when in the process of being deleted. This can
3725 // only cause problems if the event handler tries to access the object.
3726 if ( m_isBeingDeleted
)
3731 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3732 event
.SetEventObject(this);
3734 // wxFindWinFromHandle() may return NULL, it is ok
3735 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3737 return GetEventHandler()->ProcessEvent(event
);
3740 // ---------------------------------------------------------------------------
3742 // ---------------------------------------------------------------------------
3744 void wxWindowMSW::SetLabel( const wxString
& label
)
3746 SetWindowText(GetHwnd(), label
.c_str());
3749 wxString
wxWindowMSW::GetLabel() const
3751 return wxGetWindowText(GetHWND());
3754 // ---------------------------------------------------------------------------
3756 // ---------------------------------------------------------------------------
3758 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
3760 wxShowEvent
event(GetId(), show
);
3761 event
.SetEventObject(this);
3763 return GetEventHandler()->ProcessEvent(event
);
3766 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
3768 wxInitDialogEvent
event(GetId());
3769 event
.SetEventObject(this);
3771 return GetEventHandler()->ProcessEvent(event
);
3774 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
3776 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
3777 wxUnusedVar(wParam
);
3779 #else // __WXMICROWIN__
3780 HDROP hFilesInfo
= (HDROP
) wParam
;
3782 // Get the total number of files dropped
3783 UINT gwFilesDropped
= ::DragQueryFile
3791 wxString
*files
= new wxString
[gwFilesDropped
];
3792 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
3794 // first get the needed buffer length (+1 for terminating NUL)
3795 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
3797 // and now get the file name
3798 ::DragQueryFile(hFilesInfo
, wIndex
,
3799 wxStringBuffer(files
[wIndex
], len
), len
);
3801 DragFinish (hFilesInfo
);
3803 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
3804 event
.SetEventObject(this);
3807 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
3808 event
.m_pos
.x
= dropPoint
.x
;
3809 event
.m_pos
.y
= dropPoint
.y
;
3811 return GetEventHandler()->ProcessEvent(event
);
3816 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
3818 int WXUNUSED(mouseMsg
))
3820 #ifndef __WXMICROWIN__
3821 // the logic is as follows:
3822 // -1. don't set cursor for non client area, including but not limited to
3823 // the title bar, scrollbars, &c
3824 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
3825 // 1. if we have the cursor set it unless wxIsBusy()
3826 // 2. if we're a top level window, set some cursor anyhow
3827 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
3829 if ( nHitTest
!= HTCLIENT
)
3834 HCURSOR hcursor
= 0;
3836 // first ask the user code - it may wish to set the cursor in some very
3837 // specific way (for example, depending on the current position)
3840 if ( !::GetCursorPosWinCE(&pt
))
3842 if ( !::GetCursorPos(&pt
) )
3845 wxLogLastError(wxT("GetCursorPos"));
3850 ScreenToClient(&x
, &y
);
3851 wxSetCursorEvent
event(x
, y
);
3853 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
3854 if ( processedEvtSetCursor
&& event
.HasCursor() )
3856 hcursor
= GetHcursorOf(event
.GetCursor());
3861 bool isBusy
= wxIsBusy();
3863 // the test for processedEvtSetCursor is here to prevent using m_cursor
3864 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3865 // it - this is a way to say that our cursor shouldn't be used for this
3867 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
3869 hcursor
= GetHcursorOf(m_cursor
);
3876 hcursor
= wxGetCurrentBusyCursor();
3878 else if ( !hcursor
)
3880 const wxCursor
*cursor
= wxGetGlobalCursor();
3881 if ( cursor
&& cursor
->Ok() )
3883 hcursor
= GetHcursorOf(*cursor
);
3891 // wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3893 ::SetCursor(hcursor
);
3895 // cursor set, stop here
3898 #endif // __WXMICROWIN__
3900 // pass up the window chain
3904 bool wxWindowMSW::HandlePower(WXWPARAM
WXUNUSED_IN_WINCE(wParam
),
3905 WXLPARAM
WXUNUSED(lParam
),
3906 bool *WXUNUSED_IN_WINCE(vetoed
))
3912 wxEventType evtType
;
3915 case PBT_APMQUERYSUSPEND
:
3916 evtType
= wxEVT_POWER_SUSPENDING
;
3919 case PBT_APMQUERYSUSPENDFAILED
:
3920 evtType
= wxEVT_POWER_SUSPEND_CANCEL
;
3923 case PBT_APMSUSPEND
:
3924 evtType
= wxEVT_POWER_SUSPENDED
;
3927 case PBT_APMRESUMESUSPEND
:
3928 #ifdef PBT_APMRESUMEAUTOMATIC
3929 case PBT_APMRESUMEAUTOMATIC
:
3931 evtType
= wxEVT_POWER_RESUME
;
3935 wxLogDebug(_T("Unknown WM_POWERBROADCAST(%d) event"), wParam
);
3938 // these messages are currently not mapped to wx events
3939 case PBT_APMQUERYSTANDBY
:
3940 case PBT_APMQUERYSTANDBYFAILED
:
3941 case PBT_APMSTANDBY
:
3942 case PBT_APMRESUMESTANDBY
:
3943 case PBT_APMBATTERYLOW
:
3944 case PBT_APMPOWERSTATUSCHANGE
:
3945 case PBT_APMOEMEVENT
:
3946 case PBT_APMRESUMECRITICAL
:
3947 evtType
= wxEVT_NULL
;
3951 // don't handle unknown messages
3952 if ( evtType
== wxEVT_NULL
)
3955 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
3957 wxPowerEvent
event(evtType
);
3958 if ( !GetEventHandler()->ProcessEvent(event
) )
3961 *vetoed
= event
.IsVetoed();
3967 bool wxWindowMSW::IsDoubleBuffered() const
3969 for ( const wxWindowMSW
*wnd
= this;
3970 wnd
&& !wnd
->IsTopLevel(); wnd
=
3973 if ( ::GetWindowLong(GetHwndOf(wnd
), GWL_EXSTYLE
) & WS_EX_COMPOSITED
)
3980 // ---------------------------------------------------------------------------
3981 // owner drawn stuff
3982 // ---------------------------------------------------------------------------
3984 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
3985 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
3986 #define WXUNUSED_UNLESS_ODRAWN(param) param
3988 #define WXUNUSED_UNLESS_ODRAWN(param)
3992 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
3993 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
3995 #if wxUSE_OWNER_DRAWN
3997 #if wxUSE_MENUS_NATIVE
3998 // is it a menu item?
3999 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
4000 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
4002 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
4004 // see comment before the same test in MSWOnMeasureItem() below
4008 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4009 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
4011 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4012 // the DC from being released
4013 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
4014 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
4015 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
4016 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
4018 return pMenuItem
->OnDrawItem
4022 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
4023 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
4026 #endif // wxUSE_MENUS_NATIVE
4028 #endif // USE_OWNER_DRAWN
4030 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
4032 #if wxUSE_OWNER_DRAWN
4033 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4034 #else // !wxUSE_OWNER_DRAWN
4035 // we may still have owner-drawn buttons internally because we have to make
4036 // them owner-drawn to support colour change
4039 wxDynamicCast(FindItem(id
), wxButton
)
4044 #endif // USE_OWNER_DRAWN
4048 return item
->MSWOnDraw(itemStruct
);
4051 #endif // wxUSE_CONTROLS
4057 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
4059 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4060 // is it a menu item?
4061 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
4062 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
4064 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
4066 // according to Carsten Fuchs the pointer may be NULL under XP if an
4067 // MDI child frame is initially maximized, see this for more info:
4068 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4070 // so silently ignore it instead of asserting
4074 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
4075 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
4078 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
4080 pMeasureStruct
->itemWidth
= w
;
4081 pMeasureStruct
->itemHeight
= h
;
4086 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
4089 return item
->MSWOnMeasure(itemStruct
);
4093 wxUnusedVar(itemStruct
);
4094 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
4099 // ---------------------------------------------------------------------------
4100 // colours and palettes
4101 // ---------------------------------------------------------------------------
4103 bool wxWindowMSW::HandleSysColorChange()
4105 wxSysColourChangedEvent event
;
4106 event
.SetEventObject(this);
4108 (void)GetEventHandler()->ProcessEvent(event
);
4110 // always let the system carry on the default processing to allow the
4111 // native controls to react to the colours update
4115 bool wxWindowMSW::HandleDisplayChange()
4117 wxDisplayChangedEvent event
;
4118 event
.SetEventObject(this);
4120 return GetEventHandler()->ProcessEvent(event
);
4123 #ifndef __WXMICROWIN__
4125 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
4127 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
4131 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
4134 *brush
= item
->MSWControlColor(hDC
, hWnd
);
4136 #endif // wxUSE_CONTROLS
4139 return *brush
!= NULL
;
4142 #endif // __WXMICROWIN__
4144 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
4147 // same as below except we don't respond to our own messages
4148 if ( hWndPalChange
!= GetHWND() )
4150 // check to see if we our our parents have a custom palette
4151 wxWindowMSW
*win
= this;
4152 while ( win
&& !win
->HasCustomPalette() )
4154 win
= win
->GetParent();
4157 if ( win
&& win
->HasCustomPalette() )
4159 // realize the palette to see whether redrawing is needed
4160 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
4161 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4162 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4164 int result
= ::RealizePalette(hdc
);
4166 // restore the palette (before releasing the DC)
4167 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
4168 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
4169 ::RealizePalette(hdc
);
4170 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
4172 // now check for the need to redraw
4174 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
4178 #endif // wxUSE_PALETTE
4180 wxPaletteChangedEvent
event(GetId());
4181 event
.SetEventObject(this);
4182 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
4184 return GetEventHandler()->ProcessEvent(event
);
4187 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
4189 // notify windows on the capture stack about lost capture
4190 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
4191 wxWindowBase::NotifyCaptureLost();
4193 wxWindow
*win
= wxFindWinFromHandle(hWndGainedCapture
);
4194 wxMouseCaptureChangedEvent
event(GetId(), win
);
4195 event
.SetEventObject(this);
4196 return GetEventHandler()->ProcessEvent(event
);
4199 bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam
, WXLPARAM lParam
)
4201 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4202 // we need to send this to child windows (it is only sent to top-level
4203 // windows) so {list,tree}ctrls can adjust their font size if necessary
4204 // this is exactly how explorer does it to enable the font size changes
4206 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4209 // top-level windows already get this message from the system
4210 wxWindow
*win
= node
->GetData();
4211 if ( !win
->IsTopLevel() )
4213 ::SendMessage(GetHwndOf(win
), WM_SETTINGCHANGE
, wParam
, lParam
);
4216 node
= node
->GetNext();
4219 // let the system handle it
4223 bool wxWindowMSW::HandleQueryNewPalette()
4227 // check to see if we our our parents have a custom palette
4228 wxWindowMSW
*win
= this;
4229 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
4230 if (win
->HasCustomPalette()) {
4231 /* realize the palette to see whether redrawing is needed */
4232 HDC hdc
= ::GetDC((HWND
) GetHWND());
4233 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4234 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
4236 int result
= ::RealizePalette(hdc
);
4237 /* restore the palette (before releasing the DC) */
4238 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
4239 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
4240 ::RealizePalette(hdc
);
4241 ::ReleaseDC((HWND
) GetHWND(), hdc
);
4242 /* now check for the need to redraw */
4244 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
4246 #endif // wxUSE_PALETTE
4248 wxQueryNewPaletteEvent
event(GetId());
4249 event
.SetEventObject(this);
4251 return GetEventHandler()->ProcessEvent(event
) && event
.GetPaletteRealized();
4254 // Responds to colour changes: passes event on to children.
4255 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
4257 // the top level window also reset the standard colour map as it might have
4258 // changed (there is no need to do it for the non top level windows as we
4259 // only have to do it once)
4263 gs_hasStdCmap
= false;
4265 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4268 // Only propagate to non-top-level windows because Windows already
4269 // sends this event to all top-level ones
4270 wxWindow
*win
= node
->GetData();
4271 if ( !win
->IsTopLevel() )
4273 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4274 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4275 // the standard controls
4276 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
4279 node
= node
->GetNext();
4283 extern wxCOLORMAP
*wxGetStdColourMap()
4285 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
4286 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
4288 if ( !gs_hasStdCmap
)
4290 static bool s_coloursInit
= false;
4292 if ( !s_coloursInit
)
4294 // When a bitmap is loaded, the RGB values can change (apparently
4295 // because Windows adjusts them to care for the old programs always
4296 // using 0xc0c0c0 while the transparent colour for the new Windows
4297 // versions is different). But we do this adjustment ourselves so
4298 // we want to avoid Windows' "help" and for this we need to have a
4299 // reference bitmap which can tell us what the RGB values change
4301 wxLogNull logNo
; // suppress error if we couldn't load the bitmap
4302 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
4303 if ( stdColourBitmap
.Ok() )
4305 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4306 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
4307 _T("forgot to update wxBITMAP_STD_COLOURS!") );
4310 memDC
.SelectObject(stdColourBitmap
);
4313 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
4315 memDC
.GetPixel(i
, 0, &colour
);
4316 s_stdColours
[i
] = wxColourToRGB(colour
);
4319 else // wxBITMAP_STD_COLOURS couldn't be loaded
4321 s_stdColours
[0] = RGB(000,000,000); // black
4322 s_stdColours
[1] = RGB(128,128,128); // dark grey
4323 s_stdColours
[2] = RGB(192,192,192); // light grey
4324 s_stdColours
[3] = RGB(255,255,255); // white
4325 //s_stdColours[4] = RGB(000,000,255); // blue
4326 //s_stdColours[5] = RGB(255,000,255); // magenta
4329 s_coloursInit
= true;
4332 gs_hasStdCmap
= true;
4334 // create the colour map
4335 #define INIT_CMAP_ENTRY(col) \
4336 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4337 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4339 INIT_CMAP_ENTRY(BTNTEXT
);
4340 INIT_CMAP_ENTRY(BTNSHADOW
);
4341 INIT_CMAP_ENTRY(BTNFACE
);
4342 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
4344 #undef INIT_CMAP_ENTRY
4350 // ---------------------------------------------------------------------------
4352 // ---------------------------------------------------------------------------
4354 bool wxWindowMSW::HandlePaint()
4356 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4358 wxLogLastError(wxT("CreateRectRgn"));
4359 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
4360 wxLogLastError(wxT("GetUpdateRgn"));
4362 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
4364 wxPaintEvent
event(m_windowId
);
4365 event
.SetEventObject(this);
4367 bool processed
= GetEventHandler()->ProcessEvent(event
);
4369 // note that we must generate NC event after the normal one as otherwise
4370 // BeginPaint() will happily overwrite our decorations with the background
4372 wxNcPaintEvent
eventNc(m_windowId
);
4373 eventNc
.SetEventObject(this);
4374 GetEventHandler()->ProcessEvent(eventNc
);
4379 // Can be called from an application's OnPaint handler
4380 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
4382 #ifdef __WXUNIVERSAL__
4385 HDC hDC
= (HDC
) wxPaintDC::FindDCInCache((wxWindow
*) event
.GetEventObject());
4388 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
4393 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
4395 wxDCTemp
dc(hdc
, GetClientSize());
4398 dc
.SetWindow((wxWindow
*)this);
4400 wxEraseEvent
event(m_windowId
, &dc
);
4401 event
.SetEventObject(this);
4402 bool rc
= GetEventHandler()->ProcessEvent(event
);
4404 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
4405 dc
.SelectOldObjects(hdc
);
4410 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
4412 // standard non top level controls (i.e. except the dialogs) always erase
4413 // their background themselves in HandleCtlColor() or have some control-
4414 // specific ways to set the colours (common controls)
4415 if ( IsOfStandardClass() && !IsTopLevel() )
4421 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
4423 // don't skip the event here, custom background means that the app
4424 // is drawing it itself in its OnPaint(), so don't draw it at all
4425 // now to avoid flicker
4430 // do default background painting
4431 if ( !DoEraseBackground(GetHdcOf(*event
.GetDC())) )
4433 // let the system paint the background
4438 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4440 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4444 wxFillRect(GetHwnd(), (HDC
)hDC
, hbr
);
4450 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
), WXHWND hWnd
)
4454 // our background colour applies to:
4455 // 1. this window itself, always
4456 // 2. all children unless the colour is "not inheritable"
4457 // 3. even if it is not inheritable, our immediate transparent
4458 // children should still inherit it -- but not any transparent
4459 // children because it would look wrong if a child of non
4460 // transparent child would show our bg colour when the child itself
4462 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
4465 (win
&& win
->HasTransparentBackground() &&
4466 win
->GetParent() == this) )
4468 // draw children with the same colour as the parent
4470 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4472 return (WXHBRUSH
)GetHbrushOf(*brush
);
4479 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
, WXHWND hWndToPaint
)
4482 hWndToPaint
= GetHWND();
4484 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4486 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, hWndToPaint
);
4490 // background is not inherited beyond top level windows
4491 if ( win
->IsTopLevel() )
4498 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4500 // we receive this message when DrawThemeParentBackground() is
4501 // called from def window proc of several controls under XP and we
4502 // must draw properly themed background here
4504 // note that naively I'd expect filling the client rect with the
4505 // brush returned by MSWGetBgBrush() work -- but for some reason it
4506 // doesn't and we have to call parents MSWPrintChild() which is
4507 // supposed to call DrawThemeBackground() with appropriate params
4509 // also note that in this case lParam == PRF_CLIENT but we're
4510 // clearly expected to paint the background and nothing else!
4512 if ( IsTopLevel() || InheritsBackgroundColour() )
4515 // sometimes we don't want the parent to handle it at all, instead
4516 // return whatever value this window wants
4517 if ( !MSWShouldPropagatePrintChild() )
4518 return MSWPrintChild(hDC
, (wxWindow
*)this);
4520 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4522 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4525 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4532 // ---------------------------------------------------------------------------
4533 // moving and resizing
4534 // ---------------------------------------------------------------------------
4536 bool wxWindowMSW::HandleMinimize()
4538 wxIconizeEvent
event(m_windowId
);
4539 event
.SetEventObject(this);
4541 return GetEventHandler()->ProcessEvent(event
);
4544 bool wxWindowMSW::HandleMaximize()
4546 wxMaximizeEvent
event(m_windowId
);
4547 event
.SetEventObject(this);
4549 return GetEventHandler()->ProcessEvent(event
);
4552 bool wxWindowMSW::HandleMove(int x
, int y
)
4555 wxMoveEvent
event(point
, m_windowId
);
4556 event
.SetEventObject(this);
4558 return GetEventHandler()->ProcessEvent(event
);
4561 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
4563 wxMoveEvent
event(rect
, m_windowId
);
4564 event
.SetEventObject(this);
4566 bool rc
= GetEventHandler()->ProcessEvent(event
);
4568 rect
= event
.GetRect();
4572 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
4574 #if USE_DEFERRED_SIZING
4575 // when we resize this window, its children are probably going to be
4576 // repositioned as well, prepare to use DeferWindowPos() for them
4577 int numChildren
= 0;
4578 for ( HWND child
= ::GetWindow(GetHwndOf(this), GW_CHILD
);
4580 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
4585 // Protect against valid m_hDWP being overwritten
4586 bool useDefer
= false;
4588 if ( numChildren
> 1 )
4592 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
4595 wxLogLastError(_T("BeginDeferWindowPos"));
4601 #endif // USE_DEFERRED_SIZING
4603 // update this window size
4604 bool processed
= false;
4608 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4609 // fall through nevertheless
4613 // we're not interested in these messages at all
4616 case SIZE_MINIMIZED
:
4617 processed
= HandleMinimize();
4620 case SIZE_MAXIMIZED
:
4621 /* processed = */ HandleMaximize();
4622 // fall through to send a normal size event as well
4625 // don't use w and h parameters as they specify the client size
4626 // while according to the docs EVT_SIZE handler is supposed to
4627 // receive the total size
4628 wxSizeEvent
event(GetSize(), m_windowId
);
4629 event
.SetEventObject(this);
4631 processed
= GetEventHandler()->ProcessEvent(event
);
4634 #if USE_DEFERRED_SIZING
4635 // and finally change the positions of all child windows at once
4636 if ( useDefer
&& m_hDWP
)
4638 // reset m_hDWP to NULL so that child windows don't try to use our
4639 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4640 // happen anyhow normally but who knows what weird flow of control we
4641 // may have depending on what the users EVT_SIZE handler does...)
4642 HDWP hDWP
= (HDWP
)m_hDWP
;
4645 // do put all child controls in place at once
4646 if ( !::EndDeferWindowPos(hDWP
) )
4648 wxLogLastError(_T("EndDeferWindowPos"));
4651 // Reset our children's pending pos/size values.
4652 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
4654 node
= node
->GetNext() )
4656 wxWindowMSW
*child
= node
->GetData();
4657 child
->m_pendingPosition
= wxDefaultPosition
;
4658 child
->m_pendingSize
= wxDefaultSize
;
4661 #endif // USE_DEFERRED_SIZING
4666 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
4668 wxSizeEvent
event(rect
, m_windowId
);
4669 event
.SetEventObject(this);
4671 bool rc
= GetEventHandler()->ProcessEvent(event
);
4673 rect
= event
.GetRect();
4677 bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo
))
4682 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
4686 int minWidth
= GetMinWidth(),
4687 minHeight
= GetMinHeight(),
4688 maxWidth
= GetMaxWidth(),
4689 maxHeight
= GetMaxHeight();
4691 if ( minWidth
!= wxDefaultCoord
)
4693 info
->ptMinTrackSize
.x
= minWidth
;
4697 if ( minHeight
!= wxDefaultCoord
)
4699 info
->ptMinTrackSize
.y
= minHeight
;
4703 if ( maxWidth
!= wxDefaultCoord
)
4705 info
->ptMaxTrackSize
.x
= maxWidth
;
4709 if ( maxHeight
!= wxDefaultCoord
)
4711 info
->ptMaxTrackSize
.y
= maxHeight
;
4719 // ---------------------------------------------------------------------------
4721 // ---------------------------------------------------------------------------
4723 bool wxWindowMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
4725 #if wxUSE_MENUS_NATIVE
4726 if ( !cmd
&& wxCurrentPopupMenu
)
4728 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
4729 wxCurrentPopupMenu
= NULL
;
4731 return popupMenu
->MSWCommand(cmd
, id
);
4733 #endif // wxUSE_MENUS_NATIVE
4735 wxWindow
*win
= NULL
;
4737 // first try to find it from HWND - this works even with the broken
4738 // programs using the same ids for different controls
4741 win
= wxFindWinFromHandle(control
);
4747 // must cast to a signed type before comparing with other ids!
4748 win
= FindItem((signed short)id
);
4753 return win
->MSWCommand(cmd
, id
);
4756 // the messages sent from the in-place edit control used by the treectrl
4757 // for label editing have id == 0, but they should _not_ be treated as menu
4758 // messages (they are EN_XXX ones, in fact) so don't translate anything
4759 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4762 // If no child window, it may be an accelerator, e.g. for a popup menu
4765 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
4766 event
.SetEventObject(this);
4770 return GetEventHandler()->ProcessEvent(event
);
4774 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4775 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4776 // notifications to its parent which we want to reflect back to
4778 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
4779 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
4781 #endif // wxUSE_SPINCTRL
4783 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
4784 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
4785 // notifications to its parent which we want to reflect back to
4787 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
4788 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
4796 // ---------------------------------------------------------------------------
4798 // ---------------------------------------------------------------------------
4800 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
4804 // our client coords are not quite the same as Windows ones
4805 wxPoint pt
= GetClientAreaOrigin();
4806 event
.m_x
= x
- pt
.x
;
4807 event
.m_y
= y
- pt
.y
;
4809 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
4810 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
4811 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
4812 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
4813 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
4814 event
.m_altDown
= ::GetKeyState(VK_MENU
) < 0;
4817 event
.SetTimestamp(::GetMessageTime());
4820 event
.SetEventObject(this);
4821 event
.SetId(GetId());
4823 #if wxUSE_MOUSEEVENT_HACK
4824 gs_lastMouseEvent
.pos
= ClientToScreen(wxPoint(x
, y
));
4825 gs_lastMouseEvent
.type
= event
.GetEventType();
4826 #endif // wxUSE_MOUSEEVENT_HACK
4830 // Windows doesn't send the mouse events to the static controls (which are
4831 // transparent in the sense that their WM_NCHITTEST handler returns
4832 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4833 // and so we manually check if we don't have a child window under mouse and if
4834 // we do, send the event to it instead of the window Windows had sent WM_XXX
4837 // Notice that this is not done for the mouse move events because this could
4838 // (would?) be too slow, but only for clicks which means that the static texts
4839 // still don't get move, enter nor leave events.
4840 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
)
4842 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
4844 // first try to find a non transparent child: this allows us to send events
4845 // to a static text which is inside a static box, for example
4846 POINT pt
= { *x
, *y
};
4847 HWND hwnd
= GetHwndOf(win
),
4851 hwndUnderMouse
= ::ChildWindowFromPoint
4857 hwndUnderMouse
= ::ChildWindowFromPointEx
4867 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
4869 // now try any child window at all
4870 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
4873 // check that we have a child window which is susceptible to receive mouse
4874 // events: for this it must be shown and enabled
4875 if ( hwndUnderMouse
&&
4876 hwndUnderMouse
!= hwnd
&&
4877 ::IsWindowVisible(hwndUnderMouse
) &&
4878 ::IsWindowEnabled(hwndUnderMouse
) )
4880 wxWindow
*winUnderMouse
= wxFindWinFromHandle((WXHWND
)hwndUnderMouse
);
4881 if ( winUnderMouse
)
4883 // translate the mouse coords to the other window coords
4884 win
->ClientToScreen(x
, y
);
4885 winUnderMouse
->ScreenToClient(x
, y
);
4887 win
= winUnderMouse
;
4893 #endif // __WXWINCE__
4895 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4897 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4898 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
4899 // from the message id and take the value in the table to get wxWin event
4901 static const wxEventType eventsMouse
[] =
4915 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
4916 InitMouseEvent(event
, x
, y
, flags
);
4918 return GetEventHandler()->ProcessEvent(event
);
4921 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
4923 if ( !m_mouseInWindow
)
4925 // it would be wrong to assume that just because we get a mouse move
4926 // event that the mouse is inside the window: although this is usually
4927 // true, it is not if we had captured the mouse, so we need to check
4928 // the mouse coordinates here
4929 if ( !HasCapture() || IsMouseInWindow() )
4931 // Generate an ENTER event
4932 m_mouseInWindow
= true;
4934 #ifdef HAVE_TRACKMOUSEEVENT
4935 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
4937 trackinfo
.dwFlags
= TME_LEAVE
;
4938 trackinfo
.hwndTrack
= GetHwnd();
4940 // Use the commctrl.h _TrackMouseEvent(), which will call the real
4941 // TrackMouseEvent() if available or emulate it
4942 _TrackMouseEvent(&trackinfo
);
4943 #endif // HAVE_TRACKMOUSEEVENT
4945 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
4946 InitMouseEvent(event
, x
, y
, flags
);
4948 (void)GetEventHandler()->ProcessEvent(event
);
4951 #ifdef HAVE_TRACKMOUSEEVENT
4954 // Check if we need to send a LEAVE event
4955 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
4956 // send it here if we are using native mouse leave tracking
4957 if ( HasCapture() && !IsMouseInWindow() )
4959 GenerateMouseLeave();
4962 #endif // HAVE_TRACKMOUSEEVENT
4964 #if wxUSE_MOUSEEVENT_HACK
4965 // Windows often generates mouse events even if mouse position hasn't
4966 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
4968 // Filter this out as it can result in unexpected behaviour compared to
4970 if ( gs_lastMouseEvent
.type
== wxEVT_RIGHT_DOWN
||
4971 gs_lastMouseEvent
.type
== wxEVT_LEFT_DOWN
||
4972 gs_lastMouseEvent
.type
== wxEVT_MIDDLE_DOWN
||
4973 gs_lastMouseEvent
.type
== wxEVT_MOTION
)
4975 if ( ClientToScreen(wxPoint(x
, y
)) == gs_lastMouseEvent
.pos
)
4977 gs_lastMouseEvent
.type
= wxEVT_MOTION
;
4982 #endif // wxUSE_MOUSEEVENT_HACK
4984 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
4988 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
4990 #if wxUSE_MOUSEWHEEL
4991 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
4992 // forwarded up to the parent by DefWindowProc()) and not in the client
4993 // ones as all the other messages, translate them to the client coords for
4996 pt
= ScreenToClient(wxPoint(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
)));
4997 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
4998 InitMouseEvent(event
, pt
.x
, pt
.y
, LOWORD(wParam
));
4999 event
.m_wheelRotation
= (short)HIWORD(wParam
);
5000 event
.m_wheelDelta
= WHEEL_DELTA
;
5002 static int s_linesPerRotation
= -1;
5003 if ( s_linesPerRotation
== -1 )
5005 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
5006 &s_linesPerRotation
, 0))
5008 // this is not supposed to happen
5009 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5011 // the default is 3, so use it if SystemParametersInfo() failed
5012 s_linesPerRotation
= 3;
5016 event
.m_linesPerAction
= s_linesPerRotation
;
5017 return GetEventHandler()->ProcessEvent(event
);
5019 #else // !wxUSE_MOUSEWHEEL
5020 wxUnusedVar(wParam
);
5021 wxUnusedVar(lParam
);
5024 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
5027 void wxWindowMSW::GenerateMouseLeave()
5029 m_mouseInWindow
= false;
5032 if ( wxIsShiftDown() )
5034 if ( wxIsCtrlDown() )
5035 state
|= MK_CONTROL
;
5037 // Only the high-order bit should be tested
5038 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
5039 state
|= MK_LBUTTON
;
5040 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
5041 state
|= MK_MBUTTON
;
5042 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
5043 state
|= MK_RBUTTON
;
5047 if ( !::GetCursorPosWinCE(&pt
) )
5049 if ( !::GetCursorPos(&pt
) )
5052 wxLogLastError(_T("GetCursorPos"));
5055 // we need to have client coordinates here for symmetry with
5056 // wxEVT_ENTER_WINDOW
5057 RECT rect
= wxGetWindowRect(GetHwnd());
5061 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
5062 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
5064 (void)GetEventHandler()->ProcessEvent(event
);
5067 // ---------------------------------------------------------------------------
5068 // keyboard handling
5069 // ---------------------------------------------------------------------------
5071 // create the key event of the given type for the given key - used by
5072 // HandleChar and HandleKeyDown/Up
5073 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
5076 WXWPARAM wParam
) const
5078 wxKeyEvent
event(evType
);
5079 event
.SetId(GetId());
5080 event
.m_shiftDown
= wxIsShiftDown();
5081 event
.m_controlDown
= wxIsCtrlDown();
5082 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
5084 event
.SetEventObject((wxWindow
*)this); // const_cast
5085 event
.m_keyCode
= id
;
5087 event
.m_uniChar
= (wxChar
) wParam
;
5089 event
.m_rawCode
= (wxUint32
) wParam
;
5090 event
.m_rawFlags
= (wxUint32
) lParam
;
5092 event
.SetTimestamp(::GetMessageTime());
5095 // translate the position to client coords
5098 GetCursorPosWinCE(&pt
);
5103 GetWindowRect(GetHwnd(),&rect
);
5113 // isASCII is true only when we're called from WM_CHAR handler and not from
5115 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
5122 else // we're called from WM_KEYDOWN
5124 // don't pass lParam to wxCharCodeMSWToWX() here because we don't want
5125 // to get numpad key codes: CHAR events should use the logical keys
5126 // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events
5127 id
= wxCharCodeMSWToWX(wParam
);
5130 // it's ASCII and will be processed here only when called from
5131 // WM_CHAR (i.e. when isASCII = true), don't process it now
5136 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
5138 // the alphanumeric keys produced by pressing AltGr+something on European
5139 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5140 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5141 // alphanumeric, so pretend that there are no modifiers at all (the
5142 // KEY_DOWN event would still have the correct modifiers if they're really
5144 if ( event
.m_controlDown
&& event
.m_altDown
&&
5145 (id
>= 32 && id
< 256) )
5147 event
.m_controlDown
=
5148 event
.m_altDown
= false;
5151 return GetEventHandler()->ProcessEvent(event
);
5154 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
5156 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5160 // normal ASCII char
5164 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
5165 return GetEventHandler()->ProcessEvent(event
);
5168 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
5170 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5174 // normal ASCII char
5178 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
5179 return GetEventHandler()->ProcessEvent(event
);
5182 int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel
),
5183 WXLPARAM
WXUNUSED_IN_WINCE(lParam
))
5185 // FIXME: implement GetMenuItemCount for WinCE, possibly
5186 // in terms of GetMenuItemInfo
5188 const HMENU hmenu
= (HMENU
)lParam
;
5192 mii
.cbSize
= sizeof(MENUITEMINFO
);
5194 // we could use MIIM_FTYPE here as we only need to know if the item is
5195 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5196 // MIIM_FTYPE is not supported under Win95
5197 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
5199 // find if we have this letter in any owner drawn item
5200 const int count
= ::GetMenuItemCount(hmenu
);
5201 for ( int i
= 0; i
< count
; i
++ )
5203 // previous loop iteration could modify it, reset it back before
5204 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5207 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
5209 if ( mii
.fType
== MFT_OWNERDRAW
)
5211 // dwItemData member of the MENUITEMINFO is a
5212 // pointer to the associated wxMenuItem -- see the
5213 // menu creation code
5214 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
5216 const wxChar
*p
= wxStrchr(item
->GetText(), _T('&'));
5219 if ( *p
== _T('&') )
5221 // this is not the accel char, find the real one
5222 p
= wxStrchr(p
+ 1, _T('&'));
5224 else // got the accel char
5226 // FIXME-UNICODE: this comparison doesn't risk to work
5227 // for non ASCII accelerator characters I'm afraid, but
5229 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
5235 // this one doesn't match
5242 else // failed to get the menu text?
5244 // it's not fatal, so don't show error, but still log it
5245 wxLogLastError(_T("GetMenuItemInfo"));
5252 bool wxWindowMSW::HandleClipboardEvent( WXUINT nMsg
)
5254 const wxEventType type
= ( nMsg
== WM_CUT
) ? wxEVT_COMMAND_TEXT_CUT
:
5255 ( nMsg
== WM_COPY
) ? wxEVT_COMMAND_TEXT_COPY
:
5256 /*( nMsg == WM_PASTE ) ? */ wxEVT_COMMAND_TEXT_PASTE
;
5257 wxClipboardTextEvent
evt(type
, GetId());
5259 evt
.SetEventObject(this);
5261 return GetEventHandler()->ProcessEvent(evt
);
5264 // ---------------------------------------------------------------------------
5266 // ---------------------------------------------------------------------------
5268 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
5272 if ( flags
& JOY_BUTTON1CHG
)
5273 change
= wxJOY_BUTTON1
;
5274 if ( flags
& JOY_BUTTON2CHG
)
5275 change
= wxJOY_BUTTON2
;
5276 if ( flags
& JOY_BUTTON3CHG
)
5277 change
= wxJOY_BUTTON3
;
5278 if ( flags
& JOY_BUTTON4CHG
)
5279 change
= wxJOY_BUTTON4
;
5282 if ( flags
& JOY_BUTTON1
)
5283 buttons
|= wxJOY_BUTTON1
;
5284 if ( flags
& JOY_BUTTON2
)
5285 buttons
|= wxJOY_BUTTON2
;
5286 if ( flags
& JOY_BUTTON3
)
5287 buttons
|= wxJOY_BUTTON3
;
5288 if ( flags
& JOY_BUTTON4
)
5289 buttons
|= wxJOY_BUTTON4
;
5291 // the event ids aren't consecutive so we can't use table based lookup
5293 wxEventType eventType
;
5298 eventType
= wxEVT_JOY_MOVE
;
5303 eventType
= wxEVT_JOY_MOVE
;
5308 eventType
= wxEVT_JOY_ZMOVE
;
5313 eventType
= wxEVT_JOY_ZMOVE
;
5316 case MM_JOY1BUTTONDOWN
:
5318 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5321 case MM_JOY2BUTTONDOWN
:
5323 eventType
= wxEVT_JOY_BUTTON_DOWN
;
5326 case MM_JOY1BUTTONUP
:
5328 eventType
= wxEVT_JOY_BUTTON_UP
;
5331 case MM_JOY2BUTTONUP
:
5333 eventType
= wxEVT_JOY_BUTTON_UP
;
5337 wxFAIL_MSG(wxT("no such joystick event"));
5342 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
5343 event
.SetPosition(wxPoint(x
, y
));
5344 event
.SetEventObject(this);
5346 return GetEventHandler()->ProcessEvent(event
);
5356 // ---------------------------------------------------------------------------
5358 // ---------------------------------------------------------------------------
5360 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
5361 WXWORD pos
, WXHWND control
)
5363 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
5365 wxWindow
*child
= wxFindWinFromHandle(control
);
5367 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
5370 wxScrollWinEvent event
;
5371 event
.SetPosition(pos
);
5372 event
.SetOrientation(orientation
);
5373 event
.SetEventObject(this);
5378 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
5382 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
5386 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
5390 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
5394 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
5398 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
5401 case SB_THUMBPOSITION
:
5403 // under Win32, the scrollbar range and position are 32 bit integers,
5404 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5405 // explicitly query the scrollbar for the correct position (this must
5406 // be done only for these two SB_ events as they are the only one
5407 // carrying the scrollbar position)
5409 WinStruct
<SCROLLINFO
> scrollInfo
;
5410 scrollInfo
.fMask
= SIF_TRACKPOS
;
5412 if ( !::GetScrollInfo(GetHwnd(),
5413 orientation
== wxHORIZONTAL
? SB_HORZ
5417 // Not necessarily an error, if there are no scrollbars yet.
5418 // wxLogLastError(_T("GetScrollInfo"));
5421 event
.SetPosition(scrollInfo
.nTrackPos
);
5424 event
.SetEventType( wParam
== SB_THUMBPOSITION
5425 ? wxEVT_SCROLLWIN_THUMBRELEASE
5426 : wxEVT_SCROLLWIN_THUMBTRACK
);
5433 return GetEventHandler()->ProcessEvent(event
);
5436 // ===========================================================================
5438 // ===========================================================================
5440 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
5443 HDC dc
= ::GetDC((HWND
) wnd
);
5446 // the_font.UseResource();
5447 // the_font.RealizeResource();
5448 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
5450 was
= (HFONT
) SelectObject(dc
,fnt
);
5452 GetTextMetrics(dc
, &tm
);
5455 SelectObject(dc
,was
);
5457 ReleaseDC((HWND
)wnd
, dc
);
5460 *x
= tm
.tmAveCharWidth
;
5462 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
5464 // the_font.ReleaseResource();
5467 // use the "extended" bit (24) of lParam to distinguish extended keys
5468 // from normal keys as the same key is sent
5470 int ChooseNormalOrExtended(int lParam
, int keyNormal
, int keyExtended
)
5472 // except that if lParam is 0, it means we don't have real lParam from
5473 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
5474 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
5475 // non-numpad (hence extended) key as this is a more common case
5476 return !lParam
|| (lParam
& (1 << 24)) ? keyExtended
: keyNormal
;
5479 // this array contains the Windows virtual key codes which map one to one to
5480 // WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below
5482 // note that keys having a normal and numpad version (e.g. WXK_HOME and
5483 // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
5484 static const struct wxKeyMapping
5488 } gs_specialKeys
[] =
5490 { VK_CANCEL
, WXK_CANCEL
},
5491 { VK_BACK
, WXK_BACK
},
5492 { VK_TAB
, WXK_TAB
},
5493 { VK_CLEAR
, WXK_CLEAR
},
5494 { VK_SHIFT
, WXK_SHIFT
},
5495 { VK_CONTROL
, WXK_CONTROL
},
5496 { VK_MENU
, WXK_ALT
},
5497 { VK_PAUSE
, WXK_PAUSE
},
5498 { VK_CAPITAL
, WXK_CAPITAL
},
5499 { VK_SPACE
, WXK_SPACE
},
5500 { VK_ESCAPE
, WXK_ESCAPE
},
5501 { VK_SELECT
, WXK_SELECT
},
5502 { VK_PRINT
, WXK_PRINT
},
5503 { VK_EXECUTE
, WXK_EXECUTE
},
5504 { VK_SNAPSHOT
, WXK_SNAPSHOT
},
5505 { VK_HELP
, WXK_HELP
},
5507 { VK_NUMPAD0
, WXK_NUMPAD0
},
5508 { VK_NUMPAD1
, WXK_NUMPAD1
},
5509 { VK_NUMPAD2
, WXK_NUMPAD2
},
5510 { VK_NUMPAD3
, WXK_NUMPAD3
},
5511 { VK_NUMPAD4
, WXK_NUMPAD4
},
5512 { VK_NUMPAD5
, WXK_NUMPAD5
},
5513 { VK_NUMPAD6
, WXK_NUMPAD6
},
5514 { VK_NUMPAD7
, WXK_NUMPAD7
},
5515 { VK_NUMPAD8
, WXK_NUMPAD8
},
5516 { VK_NUMPAD9
, WXK_NUMPAD9
},
5517 { VK_MULTIPLY
, WXK_NUMPAD_MULTIPLY
},
5518 { VK_ADD
, WXK_NUMPAD_ADD
},
5519 { VK_SUBTRACT
, WXK_NUMPAD_SUBTRACT
},
5520 { VK_DECIMAL
, WXK_NUMPAD_DECIMAL
},
5521 { VK_DIVIDE
, WXK_NUMPAD_DIVIDE
},
5532 { VK_F10
, WXK_F10
},
5533 { VK_F11
, WXK_F11
},
5534 { VK_F12
, WXK_F12
},
5535 { VK_F13
, WXK_F13
},
5536 { VK_F14
, WXK_F14
},
5537 { VK_F15
, WXK_F15
},
5538 { VK_F16
, WXK_F16
},
5539 { VK_F17
, WXK_F17
},
5540 { VK_F18
, WXK_F18
},
5541 { VK_F19
, WXK_F19
},
5542 { VK_F20
, WXK_F20
},
5543 { VK_F21
, WXK_F21
},
5544 { VK_F22
, WXK_F22
},
5545 { VK_F23
, WXK_F23
},
5546 { VK_F24
, WXK_F24
},
5548 { VK_NUMLOCK
, WXK_NUMLOCK
},
5549 { VK_SCROLL
, WXK_SCROLL
},
5552 { VK_LWIN
, WXK_WINDOWS_LEFT
},
5553 { VK_RWIN
, WXK_WINDOWS_RIGHT
},
5554 { VK_APPS
, WXK_WINDOWS_MENU
},
5555 #endif // VK_APPS defined
5558 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
5559 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
5560 int wxCharCodeMSWToWX(int vk
, WXLPARAM lParam
)
5562 // check the table first
5563 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5565 if ( gs_specialKeys
[n
].vk
== vk
)
5566 return gs_specialKeys
[n
].wxk
;
5569 // keys requiring special handling
5573 // the mapping for these keys may be incorrect on non-US keyboards so
5574 // maybe we shouldn't map them to ASCII values at all
5575 case VK_OEM_1
: wxk
= ';'; break;
5576 case VK_OEM_PLUS
: wxk
= '+'; break;
5577 case VK_OEM_COMMA
: wxk
= ','; break;
5578 case VK_OEM_MINUS
: wxk
= '-'; break;
5579 case VK_OEM_PERIOD
: wxk
= '.'; break;
5580 case VK_OEM_2
: wxk
= '/'; break;
5581 case VK_OEM_3
: wxk
= '~'; break;
5582 case VK_OEM_4
: wxk
= '['; break;
5583 case VK_OEM_5
: wxk
= '\\'; break;
5584 case VK_OEM_6
: wxk
= ']'; break;
5585 case VK_OEM_7
: wxk
= '\''; break;
5587 // handle extended keys
5589 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEUP
, WXK_PAGEUP
);
5593 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_PAGEDOWN
, WXK_PAGEDOWN
);
5597 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_END
, WXK_END
);
5601 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_HOME
, WXK_HOME
);
5605 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_LEFT
, WXK_LEFT
);
5609 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_UP
, WXK_UP
);
5613 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_RIGHT
, WXK_RIGHT
);
5617 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DOWN
, WXK_DOWN
);
5621 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_INSERT
, WXK_INSERT
);
5625 wxk
= ChooseNormalOrExtended(lParam
, WXK_NUMPAD_DELETE
, WXK_DELETE
);
5629 // don't use ChooseNormalOrExtended() here as the keys are reversed
5630 // here: numpad enter is the extended one
5631 wxk
= lParam
&& (lParam
& (1 << 24)) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
5641 WXWORD
wxCharCodeWXToMSW(int wxk
, bool *isVirtual
)
5646 // check the table first
5647 for ( size_t n
= 0; n
< WXSIZEOF(gs_specialKeys
); n
++ )
5649 if ( gs_specialKeys
[n
].wxk
== wxk
)
5650 return gs_specialKeys
[n
].vk
;
5653 // and then check for special keys not included in the table
5658 case WXK_NUMPAD_PAGEUP
:
5663 case WXK_NUMPAD_PAGEDOWN
:
5668 case WXK_NUMPAD_END
:
5673 case WXK_NUMPAD_HOME
:
5678 case WXK_NUMPAD_LEFT
:
5688 case WXK_NUMPAD_RIGHT
:
5693 case WXK_NUMPAD_DOWN
:
5698 case WXK_NUMPAD_INSERT
:
5703 case WXK_NUMPAD_DELETE
:
5717 // small helper for wxGetKeyState() and wxGetMouseState()
5718 static inline bool wxIsKeyDown(WXWORD vk
)
5720 // the low order bit indicates whether the key was pressed since the last
5721 // call and the high order one indicates whether it is down right now and
5722 // we only want that one
5723 return (::GetAsyncKeyState(vk
) & (1<<15)) != 0;
5726 bool wxGetKeyState(wxKeyCode key
)
5728 // although this does work under Windows, it is not supported under other
5729 // platforms so don't allow it, you must use wxGetMouseState() instead
5730 wxASSERT_MSG( key
!= VK_LBUTTON
&&
5731 key
!= VK_RBUTTON
&&
5733 wxT("can't use wxGetKeyState() for mouse buttons") );
5735 const WXWORD vk
= wxCharCodeWXToMSW(key
);
5737 // if the requested key is a LED key, return true if the led is pressed
5738 if ( key
== WXK_NUMLOCK
|| key
== WXK_CAPITAL
|| key
== WXK_SCROLL
)
5740 // low order bit means LED is highlighted and high order one means the
5741 // key is down; for compatibility with the other ports return true if
5742 // either one is set
5743 return ::GetKeyState(vk
) != 0;
5748 return wxIsKeyDown(vk
);
5753 wxMouseState
wxGetMouseState()
5757 GetCursorPos( &pt
);
5761 ms
.SetLeftDown(wxIsKeyDown(VK_LBUTTON
));
5762 ms
.SetMiddleDown(wxIsKeyDown(VK_MBUTTON
));
5763 ms
.SetRightDown(wxIsKeyDown(VK_RBUTTON
));
5765 ms
.SetControlDown(wxIsKeyDown(VK_CONTROL
));
5766 ms
.SetShiftDown(wxIsKeyDown(VK_SHIFT
));
5767 ms
.SetAltDown(wxIsKeyDown(VK_MENU
));
5768 // ms.SetMetaDown();
5774 wxWindow
*wxGetActiveWindow()
5776 HWND hWnd
= GetActiveWindow();
5779 return wxFindWinFromHandle((WXHWND
) hWnd
);
5784 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
5786 HWND hwnd
= (HWND
)hWnd
;
5788 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
5789 // by code in msw/radiobox.cpp), for all the others we just search up the
5791 wxWindow
*win
= (wxWindow
*)NULL
;
5794 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5798 // native radiobuttons return DLGC_RADIOBUTTON here and for any
5799 // wxWindow class which overrides WM_GETDLGCODE processing to
5800 // do it as well, win would be already non NULL
5801 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
5803 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
5805 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
5806 #endif // wxUSE_RADIOBOX
5808 // spin control text buddy window should be mapped to spin ctrl
5809 // itself so try it too
5810 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5813 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
5815 #endif // wxUSE_SPINCTRL
5819 while ( hwnd
&& !win
)
5821 // this is a really ugly hack needed to avoid mistakenly returning the
5822 // parent frame wxWindow for the find/replace modeless dialog HWND -
5823 // this, in turn, is needed to call IsDialogMessage() from
5824 // wxApp::ProcessMessage() as for this we must return NULL from here
5826 // FIXME: this is clearly not the best way to do it but I think we'll
5827 // need to change HWND <-> wxWindow code more heavily than I can
5828 // do it now to fix it
5829 #ifndef __WXMICROWIN__
5830 if ( ::GetWindow(hwnd
, GW_OWNER
) )
5832 // it's a dialog box, don't go upwards
5837 hwnd
= ::GetParent(hwnd
);
5838 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5844 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
5846 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
5847 // in active frames and dialogs, regardless of where the focus is.
5848 static HHOOK wxTheKeyboardHook
= 0;
5849 static FARPROC wxTheKeyboardHookProc
= 0;
5850 int APIENTRY _EXPORT
5851 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
5853 void wxSetKeyboardHook(bool doIt
)
5857 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
5858 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
5860 GetCurrentThreadId()
5861 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
5866 UnhookWindowsHookEx(wxTheKeyboardHook
);
5870 int APIENTRY _EXPORT
5871 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
5873 DWORD hiWord
= HIWORD(lParam
);
5874 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
5876 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5879 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
5880 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
5881 event
.m_altDown
= true;
5883 event
.SetEventObject(NULL
);
5884 event
.m_keyCode
= id
;
5885 event
.m_shiftDown
= wxIsShiftDown();
5886 event
.m_controlDown
= wxIsCtrlDown();
5888 event
.SetTimestamp(::GetMessageTime());
5890 wxWindow
*win
= wxGetActiveWindow();
5891 wxEvtHandler
*handler
;
5894 handler
= win
->GetEventHandler();
5895 event
.SetId(win
->GetId());
5900 event
.SetId(wxID_ANY
);
5903 if ( handler
&& handler
->ProcessEvent(event
) )
5911 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
5914 #endif // !__WXMICROWIN__
5917 const wxChar
*wxGetMessageName(int message
)
5921 case 0x0000: return wxT("WM_NULL");
5922 case 0x0001: return wxT("WM_CREATE");
5923 case 0x0002: return wxT("WM_DESTROY");
5924 case 0x0003: return wxT("WM_MOVE");
5925 case 0x0005: return wxT("WM_SIZE");
5926 case 0x0006: return wxT("WM_ACTIVATE");
5927 case 0x0007: return wxT("WM_SETFOCUS");
5928 case 0x0008: return wxT("WM_KILLFOCUS");
5929 case 0x000A: return wxT("WM_ENABLE");
5930 case 0x000B: return wxT("WM_SETREDRAW");
5931 case 0x000C: return wxT("WM_SETTEXT");
5932 case 0x000D: return wxT("WM_GETTEXT");
5933 case 0x000E: return wxT("WM_GETTEXTLENGTH");
5934 case 0x000F: return wxT("WM_PAINT");
5935 case 0x0010: return wxT("WM_CLOSE");
5936 case 0x0011: return wxT("WM_QUERYENDSESSION");
5937 case 0x0012: return wxT("WM_QUIT");
5938 case 0x0013: return wxT("WM_QUERYOPEN");
5939 case 0x0014: return wxT("WM_ERASEBKGND");
5940 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
5941 case 0x0016: return wxT("WM_ENDSESSION");
5942 case 0x0017: return wxT("WM_SYSTEMERROR");
5943 case 0x0018: return wxT("WM_SHOWWINDOW");
5944 case 0x0019: return wxT("WM_CTLCOLOR");
5945 case 0x001A: return wxT("WM_WININICHANGE");
5946 case 0x001B: return wxT("WM_DEVMODECHANGE");
5947 case 0x001C: return wxT("WM_ACTIVATEAPP");
5948 case 0x001D: return wxT("WM_FONTCHANGE");
5949 case 0x001E: return wxT("WM_TIMECHANGE");
5950 case 0x001F: return wxT("WM_CANCELMODE");
5951 case 0x0020: return wxT("WM_SETCURSOR");
5952 case 0x0021: return wxT("WM_MOUSEACTIVATE");
5953 case 0x0022: return wxT("WM_CHILDACTIVATE");
5954 case 0x0023: return wxT("WM_QUEUESYNC");
5955 case 0x0024: return wxT("WM_GETMINMAXINFO");
5956 case 0x0026: return wxT("WM_PAINTICON");
5957 case 0x0027: return wxT("WM_ICONERASEBKGND");
5958 case 0x0028: return wxT("WM_NEXTDLGCTL");
5959 case 0x002A: return wxT("WM_SPOOLERSTATUS");
5960 case 0x002B: return wxT("WM_DRAWITEM");
5961 case 0x002C: return wxT("WM_MEASUREITEM");
5962 case 0x002D: return wxT("WM_DELETEITEM");
5963 case 0x002E: return wxT("WM_VKEYTOITEM");
5964 case 0x002F: return wxT("WM_CHARTOITEM");
5965 case 0x0030: return wxT("WM_SETFONT");
5966 case 0x0031: return wxT("WM_GETFONT");
5967 case 0x0037: return wxT("WM_QUERYDRAGICON");
5968 case 0x0039: return wxT("WM_COMPAREITEM");
5969 case 0x0041: return wxT("WM_COMPACTING");
5970 case 0x0044: return wxT("WM_COMMNOTIFY");
5971 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
5972 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
5973 case 0x0048: return wxT("WM_POWER");
5975 case 0x004A: return wxT("WM_COPYDATA");
5976 case 0x004B: return wxT("WM_CANCELJOURNAL");
5977 case 0x004E: return wxT("WM_NOTIFY");
5978 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
5979 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
5980 case 0x0052: return wxT("WM_TCARD");
5981 case 0x0053: return wxT("WM_HELP");
5982 case 0x0054: return wxT("WM_USERCHANGED");
5983 case 0x0055: return wxT("WM_NOTIFYFORMAT");
5984 case 0x007B: return wxT("WM_CONTEXTMENU");
5985 case 0x007C: return wxT("WM_STYLECHANGING");
5986 case 0x007D: return wxT("WM_STYLECHANGED");
5987 case 0x007E: return wxT("WM_DISPLAYCHANGE");
5988 case 0x007F: return wxT("WM_GETICON");
5989 case 0x0080: return wxT("WM_SETICON");
5991 case 0x0081: return wxT("WM_NCCREATE");
5992 case 0x0082: return wxT("WM_NCDESTROY");
5993 case 0x0083: return wxT("WM_NCCALCSIZE");
5994 case 0x0084: return wxT("WM_NCHITTEST");
5995 case 0x0085: return wxT("WM_NCPAINT");
5996 case 0x0086: return wxT("WM_NCACTIVATE");
5997 case 0x0087: return wxT("WM_GETDLGCODE");
5998 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
5999 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6000 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6001 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6002 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6003 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6004 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6005 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6006 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6007 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6008 case 0x0100: return wxT("WM_KEYDOWN");
6009 case 0x0101: return wxT("WM_KEYUP");
6010 case 0x0102: return wxT("WM_CHAR");
6011 case 0x0103: return wxT("WM_DEADCHAR");
6012 case 0x0104: return wxT("WM_SYSKEYDOWN");
6013 case 0x0105: return wxT("WM_SYSKEYUP");
6014 case 0x0106: return wxT("WM_SYSCHAR");
6015 case 0x0107: return wxT("WM_SYSDEADCHAR");
6016 case 0x0108: return wxT("WM_KEYLAST");
6018 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6019 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6020 case 0x010F: return wxT("WM_IME_COMPOSITION");
6022 case 0x0110: return wxT("WM_INITDIALOG");
6023 case 0x0111: return wxT("WM_COMMAND");
6024 case 0x0112: return wxT("WM_SYSCOMMAND");
6025 case 0x0113: return wxT("WM_TIMER");
6026 case 0x0114: return wxT("WM_HSCROLL");
6027 case 0x0115: return wxT("WM_VSCROLL");
6028 case 0x0116: return wxT("WM_INITMENU");
6029 case 0x0117: return wxT("WM_INITMENUPOPUP");
6030 case 0x011F: return wxT("WM_MENUSELECT");
6031 case 0x0120: return wxT("WM_MENUCHAR");
6032 case 0x0121: return wxT("WM_ENTERIDLE");
6033 case 0x0200: return wxT("WM_MOUSEMOVE");
6034 case 0x0201: return wxT("WM_LBUTTONDOWN");
6035 case 0x0202: return wxT("WM_LBUTTONUP");
6036 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6037 case 0x0204: return wxT("WM_RBUTTONDOWN");
6038 case 0x0205: return wxT("WM_RBUTTONUP");
6039 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6040 case 0x0207: return wxT("WM_MBUTTONDOWN");
6041 case 0x0208: return wxT("WM_MBUTTONUP");
6042 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6043 case 0x020A: return wxT("WM_MOUSEWHEEL");
6044 case 0x0210: return wxT("WM_PARENTNOTIFY");
6045 case 0x0211: return wxT("WM_ENTERMENULOOP");
6046 case 0x0212: return wxT("WM_EXITMENULOOP");
6048 case 0x0213: return wxT("WM_NEXTMENU");
6049 case 0x0214: return wxT("WM_SIZING");
6050 case 0x0215: return wxT("WM_CAPTURECHANGED");
6051 case 0x0216: return wxT("WM_MOVING");
6052 case 0x0218: return wxT("WM_POWERBROADCAST");
6053 case 0x0219: return wxT("WM_DEVICECHANGE");
6055 case 0x0220: return wxT("WM_MDICREATE");
6056 case 0x0221: return wxT("WM_MDIDESTROY");
6057 case 0x0222: return wxT("WM_MDIACTIVATE");
6058 case 0x0223: return wxT("WM_MDIRESTORE");
6059 case 0x0224: return wxT("WM_MDINEXT");
6060 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6061 case 0x0226: return wxT("WM_MDITILE");
6062 case 0x0227: return wxT("WM_MDICASCADE");
6063 case 0x0228: return wxT("WM_MDIICONARRANGE");
6064 case 0x0229: return wxT("WM_MDIGETACTIVE");
6065 case 0x0230: return wxT("WM_MDISETMENU");
6066 case 0x0233: return wxT("WM_DROPFILES");
6068 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6069 case 0x0282: return wxT("WM_IME_NOTIFY");
6070 case 0x0283: return wxT("WM_IME_CONTROL");
6071 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6072 case 0x0285: return wxT("WM_IME_SELECT");
6073 case 0x0286: return wxT("WM_IME_CHAR");
6074 case 0x0290: return wxT("WM_IME_KEYDOWN");
6075 case 0x0291: return wxT("WM_IME_KEYUP");
6077 case 0x0300: return wxT("WM_CUT");
6078 case 0x0301: return wxT("WM_COPY");
6079 case 0x0302: return wxT("WM_PASTE");
6080 case 0x0303: return wxT("WM_CLEAR");
6081 case 0x0304: return wxT("WM_UNDO");
6082 case 0x0305: return wxT("WM_RENDERFORMAT");
6083 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6084 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6085 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6086 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6087 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6088 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6089 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6090 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6091 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6092 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6093 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6094 case 0x0311: return wxT("WM_PALETTECHANGED");
6096 case 0x0312: return wxT("WM_HOTKEY");
6099 // common controls messages - although they're not strictly speaking
6100 // standard, it's nice to decode them nevertheless
6103 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6104 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6105 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6106 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6107 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6108 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6109 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6110 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6111 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6112 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6113 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6114 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6115 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6116 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6117 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6118 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6119 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6120 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6121 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6122 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6123 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6124 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6125 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6126 case 0x1000 + 18: return wxT("LVM_HITTEST");
6127 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6128 case 0x1000 + 20: return wxT("LVM_SCROLL");
6129 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6130 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6131 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6132 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6133 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6134 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6135 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6136 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6137 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6138 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6139 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6140 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6141 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6142 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6143 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6144 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6145 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6146 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6147 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6148 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6149 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6150 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6151 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6152 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6153 case 0x1000 + 42: return wxT("LVM_UPDATE");
6154 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6155 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6156 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6157 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6158 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6159 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6160 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6161 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6162 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6163 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6164 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6165 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6166 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6167 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6168 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6169 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6170 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6171 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6172 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6173 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6174 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6175 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6176 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6177 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6178 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6179 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
6182 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6183 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6184 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6185 case 0x1100 + 2: return wxT("TVM_EXPAND");
6186 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6187 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6188 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6189 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6190 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6191 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6192 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6193 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6194 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6195 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6196 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6197 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6198 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6199 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6200 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6201 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6202 case 0x1100 + 17: return wxT("TVM_HITTEST");
6203 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6204 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6205 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6206 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6207 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6208 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6209 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6210 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6211 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
6214 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6215 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6216 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6217 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6218 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6219 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6220 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6221 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6222 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6223 case 0x1200 + 6: return wxT("HDM_HITTEST");
6224 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6225 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6226 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6227 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6228 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6229 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6230 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6231 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
6234 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6235 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6236 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6237 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6238 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6239 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6240 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6241 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6242 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6243 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6244 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6245 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6246 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6247 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6248 case 0x1300 + 13: return wxT("TCM_HITTEST");
6249 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6250 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6251 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6252 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6253 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6254 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6255 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6256 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6257 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6258 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6259 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6260 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
6263 case WM_USER
+1: return wxT("TB_ENABLEBUTTON");
6264 case WM_USER
+2: return wxT("TB_CHECKBUTTON");
6265 case WM_USER
+3: return wxT("TB_PRESSBUTTON");
6266 case WM_USER
+4: return wxT("TB_HIDEBUTTON");
6267 case WM_USER
+5: return wxT("TB_INDETERMINATE");
6268 case WM_USER
+9: return wxT("TB_ISBUTTONENABLED");
6269 case WM_USER
+10: return wxT("TB_ISBUTTONCHECKED");
6270 case WM_USER
+11: return wxT("TB_ISBUTTONPRESSED");
6271 case WM_USER
+12: return wxT("TB_ISBUTTONHIDDEN");
6272 case WM_USER
+13: return wxT("TB_ISBUTTONINDETERMINATE");
6273 case WM_USER
+17: return wxT("TB_SETSTATE");
6274 case WM_USER
+18: return wxT("TB_GETSTATE");
6275 case WM_USER
+19: return wxT("TB_ADDBITMAP");
6276 case WM_USER
+20: return wxT("TB_ADDBUTTONS");
6277 case WM_USER
+21: return wxT("TB_INSERTBUTTON");
6278 case WM_USER
+22: return wxT("TB_DELETEBUTTON");
6279 case WM_USER
+23: return wxT("TB_GETBUTTON");
6280 case WM_USER
+24: return wxT("TB_BUTTONCOUNT");
6281 case WM_USER
+25: return wxT("TB_COMMANDTOINDEX");
6282 case WM_USER
+26: return wxT("TB_SAVERESTOREA");
6283 case WM_USER
+76: return wxT("TB_SAVERESTOREW");
6284 case WM_USER
+27: return wxT("TB_CUSTOMIZE");
6285 case WM_USER
+28: return wxT("TB_ADDSTRINGA");
6286 case WM_USER
+77: return wxT("TB_ADDSTRINGW");
6287 case WM_USER
+29: return wxT("TB_GETITEMRECT");
6288 case WM_USER
+30: return wxT("TB_BUTTONSTRUCTSIZE");
6289 case WM_USER
+31: return wxT("TB_SETBUTTONSIZE");
6290 case WM_USER
+32: return wxT("TB_SETBITMAPSIZE");
6291 case WM_USER
+33: return wxT("TB_AUTOSIZE");
6292 case WM_USER
+35: return wxT("TB_GETTOOLTIPS");
6293 case WM_USER
+36: return wxT("TB_SETTOOLTIPS");
6294 case WM_USER
+37: return wxT("TB_SETPARENT");
6295 case WM_USER
+39: return wxT("TB_SETROWS");
6296 case WM_USER
+40: return wxT("TB_GETROWS");
6297 case WM_USER
+42: return wxT("TB_SETCMDID");
6298 case WM_USER
+43: return wxT("TB_CHANGEBITMAP");
6299 case WM_USER
+44: return wxT("TB_GETBITMAP");
6300 case WM_USER
+45: return wxT("TB_GETBUTTONTEXTA");
6301 case WM_USER
+75: return wxT("TB_GETBUTTONTEXTW");
6302 case WM_USER
+46: return wxT("TB_REPLACEBITMAP");
6303 case WM_USER
+47: return wxT("TB_SETINDENT");
6304 case WM_USER
+48: return wxT("TB_SETIMAGELIST");
6305 case WM_USER
+49: return wxT("TB_GETIMAGELIST");
6306 case WM_USER
+50: return wxT("TB_LOADIMAGES");
6307 case WM_USER
+51: return wxT("TB_GETRECT");
6308 case WM_USER
+52: return wxT("TB_SETHOTIMAGELIST");
6309 case WM_USER
+53: return wxT("TB_GETHOTIMAGELIST");
6310 case WM_USER
+54: return wxT("TB_SETDISABLEDIMAGELIST");
6311 case WM_USER
+55: return wxT("TB_GETDISABLEDIMAGELIST");
6312 case WM_USER
+56: return wxT("TB_SETSTYLE");
6313 case WM_USER
+57: return wxT("TB_GETSTYLE");
6314 case WM_USER
+58: return wxT("TB_GETBUTTONSIZE");
6315 case WM_USER
+59: return wxT("TB_SETBUTTONWIDTH");
6316 case WM_USER
+60: return wxT("TB_SETMAXTEXTROWS");
6317 case WM_USER
+61: return wxT("TB_GETTEXTROWS");
6318 case WM_USER
+41: return wxT("TB_GETBITMAPFLAGS");
6321 static wxString s_szBuf
;
6322 s_szBuf
.Printf(wxT("<unknown message = %d>"), message
);
6323 return s_szBuf
.c_str();
6326 #endif //__WXDEBUG__
6328 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
6332 HWND hwnd
= GetHwndOf(win
);
6333 HDC hdc
= ::GetDC(hwnd
);
6335 #if !wxDIALOG_UNIT_COMPATIBILITY
6336 // and select the current font into it
6337 HFONT hfont
= GetHfontOf(win
->GetFont());
6340 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
6344 // finally retrieve the text metrics from it
6345 GetTextMetrics(hdc
, &tm
);
6347 #if !wxDIALOG_UNIT_COMPATIBILITY
6351 (void)::SelectObject(hdc
, hfont
);
6355 ::ReleaseDC(hwnd
, hdc
);
6360 // Find the wxWindow at the current mouse position, returning the mouse
6362 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
6364 pt
= wxGetMousePosition();
6365 return wxFindWindowAtPoint(pt
);
6368 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
6374 HWND hWnd
= ::WindowFromPoint(pt2
);
6376 return wxGetWindowFromHWND((WXHWND
)hWnd
);
6379 // Get the current mouse position.
6380 wxPoint
wxGetMousePosition()
6384 GetCursorPosWinCE(&pt
);
6386 GetCursorPos( & pt
);
6389 return wxPoint(pt
.x
, pt
.y
);
6394 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6395 static void WinCEUnregisterHotKey(int modifiers
, int id
)
6397 // Register hotkeys for the hardware buttons
6399 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
6401 UnregisterFunc1Proc procUnregisterFunc
;
6402 hCoreDll
= LoadLibrary(_T("coredll.dll"));
6405 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, _T("UnregisterFunc1"));
6406 if (procUnregisterFunc
)
6407 procUnregisterFunc(modifiers
, id
);
6408 FreeLibrary(hCoreDll
);
6413 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
6415 UINT win_modifiers
=0;
6416 if ( modifiers
& wxMOD_ALT
)
6417 win_modifiers
|= MOD_ALT
;
6418 if ( modifiers
& wxMOD_SHIFT
)
6419 win_modifiers
|= MOD_SHIFT
;
6420 if ( modifiers
& wxMOD_CONTROL
)
6421 win_modifiers
|= MOD_CONTROL
;
6422 if ( modifiers
& wxMOD_WIN
)
6423 win_modifiers
|= MOD_WIN
;
6425 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6426 // Required for PPC and Smartphone hardware buttons
6427 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
6428 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
6431 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
6433 wxLogLastError(_T("RegisterHotKey"));
6441 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
6443 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6444 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
6447 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
6449 wxLogLastError(_T("UnregisterHotKey"));
6459 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
6461 int hotkeyId
= wParam
;
6462 int virtualKey
= HIWORD(lParam
);
6463 int win_modifiers
= LOWORD(lParam
);
6465 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
6466 event
.SetId(hotkeyId
);
6467 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
6468 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
6469 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
6470 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
6472 return GetEventHandler()->ProcessEvent(event
);
6475 #endif // wxUSE_ACCEL
6477 #endif // wxUSE_HOTKEY
6479 // Not tested under WinCE
6482 // this class installs a message hook which really wakes up our idle processing
6483 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
6484 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
6485 // being dragged or even inside ::MessageBox()) and so don't control message
6486 // dispatching otherwise
6487 class wxIdleWakeUpModule
: public wxModule
6490 virtual bool OnInit()
6492 ms_hMsgHookProc
= ::SetWindowsHookEx
6495 &wxIdleWakeUpModule::MsgHookProc
,
6497 GetCurrentThreadId()
6500 if ( !ms_hMsgHookProc
)
6502 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
6510 virtual void OnExit()
6512 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
6515 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
6517 MSG
*msg
= (MSG
*)lParam
;
6519 // only process the message if it is actually going to be removed from
6520 // the message queue, this prevents that the same event from being
6521 // processed multiple times if now someone just called PeekMessage()
6522 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
6524 wxTheApp
->ProcessPendingEvents();
6527 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
6531 static HHOOK ms_hMsgHookProc
;
6533 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
6536 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
6538 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
6540 #endif // __WXWINCE__
6545 static void wxAdjustZOrder(wxWindow
* parent
)
6547 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
6549 // Set the z-order correctly
6550 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
6553 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
6556 wxWindow
*childWin
= current
->GetData();
6557 wxAdjustZOrder(childWin
);
6558 current
= current
->GetNext();
6563 // We need to adjust the z-order of static boxes in WinCE, to
6564 // make 'contained' controls visible
6565 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
6568 wxAdjustZOrder(this);