1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/windows.cpp
4 // Author: Julian Smart
5 // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "window.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/msw/wrapwin.h"
33 #include "wx/window.h"
38 #include "wx/dcclient.h"
39 #include "wx/dcmemory.h"
42 #include "wx/layout.h"
43 #include "wx/dialog.h"
45 #include "wx/listbox.h"
46 #include "wx/button.h"
47 #include "wx/msgdlg.h"
48 #include "wx/settings.h"
49 #include "wx/statbox.h"
52 #if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
53 #include "wx/ownerdrw.h"
56 #include "wx/module.h"
57 #include "wx/sysopt.h"
59 #if wxUSE_DRAG_AND_DROP
63 #if wxUSE_ACCESSIBILITY
64 #include "wx/access.h"
68 #define WM_GETOBJECT 0x003D
71 #define OBJID_CLIENT 0xFFFFFFFC
75 #include "wx/menuitem.h"
78 #include "wx/msw/private.h"
81 #include "wx/tooltip.h"
89 #include "wx/spinctrl.h"
90 #endif // wxUSE_SPINCTRL
95 #include "wx/textctrl.h"
96 #include "wx/notebook.h"
97 #include "wx/listctrl.h"
101 #if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
102 #include <shellapi.h>
103 #include <mmsystem.h>
107 #include <windowsx.h>
110 #include <commctrl.h>
112 #include "wx/msw/missing.h"
114 #if defined(__WXWINCE__)
115 #include "wx/msw/wince/missing.h"
118 #if defined(TME_LEAVE) && defined(WM_MOUSELEAVE)
119 #define HAVE_TRACKMOUSEEVENT
120 #endif // everything needed for TrackMouseEvent()
122 // ---------------------------------------------------------------------------
124 // ---------------------------------------------------------------------------
126 #if wxUSE_MENUS_NATIVE
127 wxMenu
*wxCurrentPopupMenu
= NULL
;
128 #endif // wxUSE_MENUS_NATIVE
131 extern wxChar
*wxCanvasClassName
;
133 extern const wxChar
*wxCanvasClassName
;
136 // true if we had already created the std colour map, used by
137 // wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
138 static bool gs_hasStdCmap
= false;
140 // ---------------------------------------------------------------------------
142 // ---------------------------------------------------------------------------
144 // the window proc for all our windows
145 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
146 WPARAM wParam
, LPARAM lParam
);
150 const char *wxGetMessageName(int message
);
153 void wxRemoveHandleAssociation(wxWindowMSW
*win
);
154 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
);
155 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
);
157 // get the text metrics for the current font
158 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
);
160 // find the window for the mouse event at the specified position
161 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
); //TW:REQ:Univ
163 // wrapper around BringWindowToTop() API
164 static inline void wxBringWindowToTop(HWND hwnd
)
166 #ifdef __WXMICROWIN__
167 // It seems that MicroWindows brings the _parent_ of the window to the top,
168 // which can be the wrong one.
170 // activate (set focus to) specified window
174 // raise top level parent to top of z order
175 if (!::SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
))
177 wxLogLastError(_T("SetWindowPos"));
183 // ensure that all our parent windows have WS_EX_CONTROLPARENT style
184 static void EnsureParentHasControlParentStyle(wxWindow
*parent
)
187 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
188 parent as well as otherwise several Win32 functions using
189 GetNextDlgTabItem() to iterate over all controls such as
190 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
191 all of them iterate over all the controls starting from the currently
192 focused one and stop iterating when they get back to the focus but
193 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
194 get back to the initial (focused) window: as we do have this style,
195 GetNextDlgTabItem() will leave this window and continue in its parent,
196 but if the parent doesn't have it, it wouldn't recurse inside it later
197 on and so wouldn't have a chance of getting back to this window neither.
199 while ( parent
&& !parent
->IsTopLevel() )
201 LONG exStyle
= ::GetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
);
202 if ( !(exStyle
& WS_EX_CONTROLPARENT
) )
204 // force the parent to have this style
205 ::SetWindowLong(GetHwndOf(parent
), GWL_EXSTYLE
,
206 exStyle
| WS_EX_CONTROLPARENT
);
209 parent
= parent
->GetParent();
213 #endif // !__WXWINCE__
216 // On Windows CE, GetCursorPos can return an error, so use this function
218 bool GetCursorPosWinCE(POINT
* pt
)
220 if (!GetCursorPos(pt
))
222 DWORD pos
= GetMessagePos();
230 // ---------------------------------------------------------------------------
232 // ---------------------------------------------------------------------------
234 // in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
236 #ifdef __WXUNIVERSAL__
237 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW
, wxWindowBase
)
239 #if wxUSE_EXTENDED_RTTI
241 // windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
242 // must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
243 // windows with negative ids never can be recreated anyway
245 bool wxWindowStreamingCallback( const wxObject
*object
, wxWriter
* , wxPersister
* , wxxVariantArray
& )
247 const wxWindow
* win
= dynamic_cast<const wxWindow
*>(object
) ;
248 if ( win
&& win
->GetId() < 0 )
253 IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow
, wxWindowBase
,"wx/window.h", wxWindowStreamingCallback
)
255 // make wxWindowList known before the property is used
257 wxCOLLECTION_TYPE_INFO( wxWindow
* , wxWindowList
) ;
259 template<> void wxCollectionToVariantArray( wxWindowList
const &theList
, wxxVariantArray
&value
)
261 wxListCollectionToVariantArray
<wxWindowList::compatibility_iterator
>( theList
, value
) ;
264 WX_DEFINE_FLAGS( wxWindowStyle
)
266 wxBEGIN_FLAGS( wxWindowStyle
)
267 // new style border flags, we put them first to
268 // use them for streaming out
270 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
271 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
272 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
273 wxFLAGS_MEMBER(wxBORDER_RAISED
)
274 wxFLAGS_MEMBER(wxBORDER_STATIC
)
275 wxFLAGS_MEMBER(wxBORDER_NONE
)
277 // old style border flags
278 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
279 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
280 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
281 wxFLAGS_MEMBER(wxRAISED_BORDER
)
282 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
283 wxFLAGS_MEMBER(wxBORDER
)
285 // standard window styles
286 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
287 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
288 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
289 wxFLAGS_MEMBER(wxWANTS_CHARS
)
290 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
291 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
292 wxFLAGS_MEMBER(wxVSCROLL
)
293 wxFLAGS_MEMBER(wxHSCROLL
)
295 wxEND_FLAGS( wxWindowStyle
)
297 wxBEGIN_PROPERTIES_TABLE(wxWindow
)
298 wxEVENT_PROPERTY( Close
, wxEVT_CLOSE_WINDOW
, wxCloseEvent
)
299 wxEVENT_PROPERTY( Create
, wxEVT_CREATE
, wxWindowCreateEvent
)
300 wxEVENT_PROPERTY( Destroy
, wxEVT_DESTROY
, wxWindowDestroyEvent
)
301 // Always constructor Properties first
303 wxREADONLY_PROPERTY( Parent
,wxWindow
*, GetParent
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
304 wxPROPERTY( Id
,wxWindowID
, SetId
, GetId
, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
305 wxPROPERTY( Position
,wxPoint
, SetPosition
, GetPosition
, wxDefaultPosition
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
306 wxPROPERTY( Size
,wxSize
, SetSize
, GetSize
, wxDefaultSize
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
307 wxPROPERTY( WindowStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
309 // Then all relations of the object graph
311 wxREADONLY_PROPERTY_COLLECTION( Children
, wxWindowList
, wxWindowBase
* , GetWindowChildren
, wxPROP_OBJECT_GRAPH
/*flags*/ , wxT("Helpstring") , wxT("group"))
313 // and finally all other properties
315 wxPROPERTY( ExtraStyle
, long , SetExtraStyle
, GetExtraStyle
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
316 wxPROPERTY( BackgroundColour
, wxColour
, SetBackgroundColour
, GetBackgroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
317 wxPROPERTY( ForegroundColour
, wxColour
, SetForegroundColour
, GetForegroundColour
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
318 wxPROPERTY( Enabled
, bool , Enable
, IsEnabled
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
319 wxPROPERTY( Shown
, bool , Show
, IsShown
, wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
321 // possible property candidates (not in xrc) or not valid in all subclasses
322 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxEmptyString
)
323 wxPROPERTY( Font
, wxFont
, SetFont
, GetWindowFont
, )
324 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxEmptyString
)
325 // MaxHeight, Width , MinHeight , Width
326 // TODO switch label to control and title to toplevels
328 wxPROPERTY( ThemeEnabled
, bool , SetThemeEnabled
, GetThemeEnabled
, )
329 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
330 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
331 wxPROPERTY( AutoLayout
, bool , SetAutoLayout
, GetAutoLayout
, )
336 wxEND_PROPERTIES_TABLE()
338 wxBEGIN_HANDLERS_TABLE(wxWindow
)
339 wxEND_HANDLERS_TABLE()
341 wxCONSTRUCTOR_DUMMY(wxWindow
)
344 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
346 #endif // __WXUNIVERSAL__/__WXMSW__
348 BEGIN_EVENT_TABLE(wxWindowMSW
, wxWindowBase
)
349 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged
)
350 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground
)
352 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog
)
356 // ===========================================================================
358 // ===========================================================================
360 // ---------------------------------------------------------------------------
361 // wxWindow utility functions
362 // ---------------------------------------------------------------------------
364 // Find an item given the MS Windows id
365 wxWindow
*wxWindowMSW::FindItem(long id
) const
368 wxControl
*item
= wxDynamicCastThis(wxControl
);
371 // is it we or one of our "internal" children?
372 if ( item
->GetId() == id
373 #ifndef __WXUNIVERSAL__
374 || (item
->GetSubcontrols().Index(id
) != wxNOT_FOUND
)
375 #endif // __WXUNIVERSAL__
381 #endif // wxUSE_CONTROLS
383 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
386 wxWindow
*childWin
= current
->GetData();
388 wxWindow
*wnd
= childWin
->FindItem(id
);
392 current
= current
->GetNext();
398 // Find an item given the MS Windows handle
399 wxWindow
*wxWindowMSW::FindItemByHWND(WXHWND hWnd
, bool controlOnly
) const
401 wxWindowList::compatibility_iterator current
= GetChildren().GetFirst();
404 wxWindow
*parent
= current
->GetData();
406 // Do a recursive search.
407 wxWindow
*wnd
= parent
->FindItemByHWND(hWnd
);
413 || parent
->IsKindOf(CLASSINFO(wxControl
))
414 #endif // wxUSE_CONTROLS
417 wxWindow
*item
= current
->GetData();
418 if ( item
->GetHWND() == hWnd
)
422 if ( item
->ContainsHWND(hWnd
) )
427 current
= current
->GetNext();
432 // Default command handler
433 bool wxWindowMSW::MSWCommand(WXUINT
WXUNUSED(param
), WXWORD
WXUNUSED(id
))
438 // ----------------------------------------------------------------------------
439 // constructors and such
440 // ----------------------------------------------------------------------------
442 void wxWindowMSW::Init()
445 m_isBeingDeleted
= false;
447 m_mouseInWindow
= false;
448 m_lastKeydownProcessed
= false;
450 m_childrenDisabled
= NULL
;
459 #if wxUSE_MOUSEEVENT_HACK
462 m_lastMouseEvent
= -1;
463 #endif // wxUSE_MOUSEEVENT_HACK
467 wxWindowMSW::~wxWindowMSW()
469 m_isBeingDeleted
= true;
471 #ifndef __WXUNIVERSAL__
472 // VS: make sure there's no wxFrame with last focus set to us:
473 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
475 wxTopLevelWindow
*frame
= wxDynamicCast(win
, wxTopLevelWindow
);
478 if ( frame
->GetLastFocus() == this )
480 frame
->SetLastFocus(NULL
);
483 // apparently sometimes we can end up with our grand parent
484 // pointing to us as well: this is surely a bug in focus handling
485 // code but it's not clear where it happens so for now just try to
486 // fix it here by not breaking out of the loop
490 #endif // __WXUNIVERSAL__
492 // VS: destroy children first and _then_ detach *this from its parent.
493 // If we'd do it the other way around, children wouldn't be able
494 // find their parent frame (see above).
499 // VZ: test temp removed to understand what really happens here
500 //if (::IsWindow(GetHwnd()))
502 if ( !::DestroyWindow(GetHwnd()) )
503 wxLogLastError(wxT("DestroyWindow"));
506 // remove hWnd <-> wxWindow association
507 wxRemoveHandleAssociation(this);
510 delete m_childrenDisabled
;
513 // real construction (Init() must have been called before!)
514 bool wxWindowMSW::Create(wxWindow
*parent
,
519 const wxString
& name
)
521 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
523 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
526 parent
->AddChild(this);
529 DWORD msflags
= MSWGetCreateWindowFlags(&exstyle
);
531 #ifdef __WXUNIVERSAL__
532 // no borders, we draw them ourselves
533 exstyle
&= ~(WS_EX_DLGMODALFRAME
|
537 msflags
&= ~WS_BORDER
;
538 #endif // wxUniversal
542 msflags
|= WS_VISIBLE
;
545 if ( !MSWCreate(wxCanvasClassName
, NULL
, pos
, size
, msflags
, exstyle
) )
553 // ---------------------------------------------------------------------------
555 // ---------------------------------------------------------------------------
557 void wxWindowMSW::SetFocus()
559 HWND hWnd
= GetHwnd();
560 wxCHECK_RET( hWnd
, _T("can't set focus to invalid window") );
562 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
566 if ( !::SetFocus(hWnd
) )
568 #if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
569 // was there really an error?
570 DWORD dwRes
= ::GetLastError();
573 HWND hwndFocus
= ::GetFocus();
574 if ( hwndFocus
!= hWnd
)
576 wxLogApiError(_T("SetFocus"), dwRes
);
583 void wxWindowMSW::SetFocusFromKbd()
585 // when the focus is given to the control with DLGC_HASSETSEL style from
586 // keyboard its contents should be entirely selected: this is what
587 // ::IsDialogMessage() does and so we should do it as well to provide the
588 // same LNF as the native programs
589 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE
, 0, 0) & DLGC_HASSETSEL
)
591 ::SendMessage(GetHwnd(), EM_SETSEL
, 0, -1);
594 // do this after (maybe) setting the selection as like this when
595 // wxEVT_SET_FOCUS handler is called, the selection would have been already
596 // set correctly -- this may be important
597 wxWindowBase::SetFocusFromKbd();
600 // Get the window with the focus
601 wxWindow
*wxWindowBase::DoFindFocus()
603 HWND hWnd
= ::GetFocus();
606 return wxGetWindowFromHWND((WXHWND
)hWnd
);
612 bool wxWindowMSW::Enable(bool enable
)
614 if ( !wxWindowBase::Enable(enable
) )
617 HWND hWnd
= GetHwnd();
619 ::EnableWindow(hWnd
, (BOOL
)enable
);
621 // the logic below doesn't apply to the top level windows -- otherwise
622 // showing a modal dialog would result in total greying out (and ungreying
623 // out later) of everything which would be really ugly
627 // when the parent is disabled, all of its children should be disabled as
628 // well but when it is enabled back, only those of the children which
629 // hadn't been already disabled in the beginning should be enabled again,
630 // so we have to keep the list of those children
631 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
633 node
= node
->GetNext() )
635 wxWindow
*child
= node
->GetData();
636 if ( child
->IsTopLevel() )
638 // the logic below doesn't apply to top level children
644 // enable the child back unless it had been disabled before us
645 if ( !m_childrenDisabled
|| !m_childrenDisabled
->Find(child
) )
648 else // we're being disabled
650 if ( child
->IsEnabled() )
652 // disable it as children shouldn't stay enabled while the
656 else // child already disabled, remember it
658 // have we created the list of disabled children already?
659 if ( !m_childrenDisabled
)
660 m_childrenDisabled
= new wxWindowList
;
662 m_childrenDisabled
->Append(child
);
667 if ( enable
&& m_childrenDisabled
)
669 // we don't need this list any more, don't keep unused memory
670 delete m_childrenDisabled
;
671 m_childrenDisabled
= NULL
;
677 bool wxWindowMSW::Show(bool show
)
679 if ( !wxWindowBase::Show(show
) )
682 HWND hWnd
= GetHwnd();
683 int cshow
= show
? SW_SHOW
: SW_HIDE
;
684 ::ShowWindow(hWnd
, cshow
);
686 if ( show
&& IsTopLevel() )
688 wxBringWindowToTop(hWnd
);
694 // Raise the window to the top of the Z order
695 void wxWindowMSW::Raise()
697 wxBringWindowToTop(GetHwnd());
700 // Lower the window to the bottom of the Z order
701 void wxWindowMSW::Lower()
703 ::SetWindowPos(GetHwnd(), HWND_BOTTOM
, 0, 0, 0, 0,
704 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
707 void wxWindowMSW::SetTitle( const wxString
& title
)
709 SetWindowText(GetHwnd(), title
.c_str());
712 wxString
wxWindowMSW::GetTitle() const
714 return wxGetWindowText(GetHWND());
717 void wxWindowMSW::DoCaptureMouse()
719 HWND hWnd
= GetHwnd();
726 void wxWindowMSW::DoReleaseMouse()
728 if ( !::ReleaseCapture() )
730 wxLogLastError(_T("ReleaseCapture"));
734 /* static */ wxWindow
*wxWindowBase::GetCapture()
736 HWND hwnd
= ::GetCapture();
737 return hwnd
? wxFindWinFromHandle((WXHWND
)hwnd
) : (wxWindow
*)NULL
;
740 bool wxWindowMSW::SetFont(const wxFont
& font
)
742 if ( !wxWindowBase::SetFont(font
) )
748 HWND hWnd
= GetHwnd();
751 WXHANDLE hFont
= m_font
.GetResourceHandle();
753 wxASSERT_MSG( hFont
, wxT("should have valid font") );
755 ::SendMessage(hWnd
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(TRUE
, 0));
760 bool wxWindowMSW::SetCursor(const wxCursor
& cursor
)
762 if ( !wxWindowBase::SetCursor(cursor
) )
770 HWND hWnd
= GetHwnd();
772 // Change the cursor NOW if we're within the correct window
775 ::GetCursorPosWinCE(&point
);
777 ::GetCursorPos(&point
);
780 RECT rect
= wxGetWindowRect(hWnd
);
782 if ( ::PtInRect(&rect
, point
) && !wxIsBusy() )
783 ::SetCursor(GetHcursorOf(m_cursor
));
789 void wxWindowMSW::WarpPointer (int x
, int y
)
791 ClientToScreen(&x
, &y
);
793 if ( !::SetCursorPos(x
, y
) )
795 wxLogLastError(_T("SetCursorPos"));
799 // ---------------------------------------------------------------------------
801 // ---------------------------------------------------------------------------
803 inline int GetScrollPosition(HWND hWnd
, int wOrient
)
805 #ifdef __WXMICROWIN__
806 return ::GetScrollPosWX(hWnd
, wOrient
);
808 WinStruct
<SCROLLINFO
> scrollInfo
;
809 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
810 scrollInfo
.fMask
= SIF_POS
;
811 if ( !::GetScrollInfo(hWnd
,
815 // Not neccessarily an error, if there are no scrollbars yet.
816 // wxLogLastError(_T("GetScrollInfo"));
818 return scrollInfo
.nPos
;
819 // return ::GetScrollPos(hWnd, wOrient);
823 int wxWindowMSW::GetScrollPos(int orient
) const
825 HWND hWnd
= GetHwnd();
826 wxCHECK_MSG( hWnd
, 0, _T("no HWND in GetScrollPos") );
828 return GetScrollPosition(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
);
831 // This now returns the whole range, not just the number
832 // of positions that we can scroll.
833 int wxWindowMSW::GetScrollRange(int orient
) const
836 HWND hWnd
= GetHwnd();
840 ::GetScrollRange(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
843 WinStruct
<SCROLLINFO
> scrollInfo
;
844 scrollInfo
.fMask
= SIF_RANGE
;
845 if ( !::GetScrollInfo(hWnd
,
846 orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
849 // Most of the time this is not really an error, since the return
850 // value can also be zero when there is no scrollbar yet.
851 // wxLogLastError(_T("GetScrollInfo"));
853 maxPos
= scrollInfo
.nMax
;
855 // undo "range - 1" done in SetScrollbar()
859 int wxWindowMSW::GetScrollThumb(int orient
) const
861 return orient
== wxHORIZONTAL
? m_xThumbSize
: m_yThumbSize
;
864 void wxWindowMSW::SetScrollPos(int orient
, int pos
, bool refresh
)
866 HWND hWnd
= GetHwnd();
867 wxCHECK_RET( hWnd
, _T("SetScrollPos: no HWND") );
869 WinStruct
<SCROLLINFO
> info
;
873 info
.fMask
= SIF_POS
;
874 if ( HasFlag(wxALWAYS_SHOW_SB
) )
876 // disable scrollbar instead of removing it then
877 info
.fMask
|= SIF_DISABLENOSCROLL
;
880 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
884 // New function that will replace some of the above.
885 void wxWindowMSW::SetScrollbar(int orient
,
891 WinStruct
<SCROLLINFO
> info
;
892 info
.nPage
= pageSize
;
893 info
.nMin
= 0; // range is nMax - nMin + 1
894 info
.nMax
= range
- 1; // as both nMax and nMax are inclusive
896 info
.fMask
= SIF_RANGE
| SIF_PAGE
| SIF_POS
;
897 if ( HasFlag(wxALWAYS_SHOW_SB
) )
899 // disable scrollbar instead of removing it then
900 info
.fMask
|= SIF_DISABLENOSCROLL
;
903 HWND hWnd
= GetHwnd();
906 ::SetScrollInfo(hWnd
, orient
== wxHORIZONTAL
? SB_HORZ
: SB_VERT
,
910 *(orient
== wxHORIZONTAL
? &m_xThumbSize
: &m_yThumbSize
) = pageSize
;
913 void wxWindowMSW::ScrollWindow(int dx
, int dy
, const wxRect
*prect
)
919 rect
.left
= prect
->x
;
921 rect
.right
= prect
->x
+ prect
->width
;
922 rect
.bottom
= prect
->y
+ prect
->height
;
932 // FIXME: is this the exact equivalent of the line below?
933 ::ScrollWindowEx(GetHwnd(), dx
, dy
, pr
, pr
, 0, 0, SW_SCROLLCHILDREN
|SW_ERASE
|SW_INVALIDATE
);
935 ::ScrollWindow(GetHwnd(), dx
, dy
, pr
, pr
);
939 static bool ScrollVertically(HWND hwnd
, int kind
, int count
)
941 int posStart
= GetScrollPosition(hwnd
, SB_VERT
);
944 for ( int n
= 0; n
< count
; n
++ )
946 ::SendMessage(hwnd
, WM_VSCROLL
, kind
, 0);
948 int posNew
= GetScrollPosition(hwnd
, SB_VERT
);
951 // don't bother to continue, we're already at top/bottom
958 return pos
!= posStart
;
961 bool wxWindowMSW::ScrollLines(int lines
)
963 bool down
= lines
> 0;
965 return ScrollVertically(GetHwnd(),
966 down
? SB_LINEDOWN
: SB_LINEUP
,
967 down
? lines
: -lines
);
970 bool wxWindowMSW::ScrollPages(int pages
)
972 bool down
= pages
> 0;
974 return ScrollVertically(GetHwnd(),
975 down
? SB_PAGEDOWN
: SB_PAGEUP
,
976 down
? pages
: -pages
);
979 // ---------------------------------------------------------------------------
981 // ---------------------------------------------------------------------------
983 void wxWindowMSW::SubclassWin(WXHWND hWnd
)
985 wxASSERT_MSG( !m_oldWndProc
, wxT("subclassing window twice?") );
987 HWND hwnd
= (HWND
)hWnd
;
988 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in SubclassWin") );
990 wxAssociateWinWithHandle(hwnd
, this);
992 m_oldWndProc
= (WXFARPROC
)wxGetWindowProc((HWND
)hWnd
);
994 // we don't need to subclass the window of our own class (in the Windows
995 // sense of the word)
996 if ( !wxCheckWindowWndProc(hWnd
, (WXFARPROC
)wxWndProc
) )
998 wxSetWindowProc(hwnd
, wxWndProc
);
1002 // don't bother restoring it neither: this also makes it easy to
1003 // implement IsOfStandardClass() method which returns true for the
1004 // standard controls and false for the wxWidgets own windows as it can
1005 // simply check m_oldWndProc
1006 m_oldWndProc
= NULL
;
1010 void wxWindowMSW::UnsubclassWin()
1012 wxRemoveHandleAssociation(this);
1014 // Restore old Window proc
1015 HWND hwnd
= GetHwnd();
1020 wxCHECK_RET( ::IsWindow(hwnd
), wxT("invalid HWND in UnsubclassWin") );
1024 if ( !wxCheckWindowWndProc((WXHWND
)hwnd
, m_oldWndProc
) )
1026 wxSetWindowProc(hwnd
, (WNDPROC
)m_oldWndProc
);
1029 m_oldWndProc
= NULL
;
1034 void wxWindowMSW::AssociateHandle(WXWidget handle
)
1038 if ( !::DestroyWindow(GetHwnd()) )
1039 wxLogLastError(wxT("DestroyWindow"));
1042 WXHWND wxhwnd
= (WXHWND
)handle
;
1045 SubclassWin(wxhwnd
);
1048 void wxWindowMSW::DissociateHandle()
1050 // this also calls SetHWND(0) for us
1055 bool wxCheckWindowWndProc(WXHWND hWnd
, WXFARPROC wndProc
)
1057 // Unicows note: the code below works, but only because WNDCLASS contains
1058 // original window handler rather that the unicows fake one. This may not
1059 // be on purpose, though; if it stops working with future versions of
1060 // unicows.dll, we can override unicows hooks by setting
1061 // Unicows_{Set,Get}WindowLong and Unicows_RegisterClass to our own
1062 // versions that keep track of fake<->real wnd proc mapping.
1064 // On WinCE (at least), the wndproc comparison doesn't work,
1065 // so have to use something like this.
1067 wxUnusedVar(wndProc
);
1069 extern wxChar
*wxCanvasClassName
;
1070 extern wxChar
*wxCanvasClassNameNR
;
1071 extern const wxChar
*wxMDIFrameClassName
;
1072 extern const wxChar
*wxMDIFrameClassNameNoRedraw
;
1073 extern const wxChar
*wxMDIChildFrameClassName
;
1074 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
1075 wxString
str(wxGetWindowClass(hWnd
));
1076 if (str
== wxCanvasClassName
||
1077 str
== wxCanvasClassNameNR
||
1078 str
== wxMDIFrameClassName
||
1079 str
== wxMDIFrameClassNameNoRedraw
||
1080 str
== wxMDIChildFrameClassName
||
1081 str
== wxMDIChildFrameClassNameNoRedraw
||
1082 str
== _T("wxTLWHiddenParent"))
1083 return true; // Effectively means don't subclass
1088 if ( !::GetClassInfo(wxGetInstance(), wxGetWindowClass(hWnd
), &cls
) )
1090 wxLogLastError(_T("GetClassInfo"));
1095 return wndProc
== (WXFARPROC
)cls
.lpfnWndProc
;
1099 // ----------------------------------------------------------------------------
1101 // ----------------------------------------------------------------------------
1103 void wxWindowMSW::SetWindowStyleFlag(long flags
)
1105 long flagsOld
= GetWindowStyleFlag();
1106 if ( flags
== flagsOld
)
1109 // update the internal variable
1110 wxWindowBase::SetWindowStyleFlag(flags
);
1112 // now update the Windows style as well if needed - and if the window had
1113 // been already created
1117 WXDWORD exstyle
, exstyleOld
;
1118 long style
= MSWGetStyle(flags
, &exstyle
),
1119 styleOld
= MSWGetStyle(flagsOld
, &exstyleOld
);
1121 if ( style
!= styleOld
)
1123 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1124 // this function so instead of simply setting the style to the new
1125 // value we clear the bits which were set in styleOld but are set in
1126 // the new one and set the ones which were not set before
1127 long styleReal
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1128 styleReal
&= ~styleOld
;
1131 ::SetWindowLong(GetHwnd(), GWL_STYLE
, styleReal
);
1134 // and the extended style
1135 if ( exstyle
!= exstyleOld
)
1137 long exstyleReal
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1138 exstyleReal
&= ~exstyleOld
;
1139 exstyleReal
|= exstyle
;
1141 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exstyleReal
);
1143 // we must call SetWindowPos() to flush the cached extended style and
1144 // also to make the change to wxSTAY_ON_TOP style take effect: just
1145 // setting the style simply doesn't work
1146 if ( !::SetWindowPos(GetHwnd(),
1147 exstyleReal
& WS_EX_TOPMOST
? HWND_TOPMOST
1150 SWP_NOMOVE
| SWP_NOSIZE
) )
1152 wxLogLastError(_T("SetWindowPos"));
1157 WXDWORD
wxWindowMSW::MSWGetStyle(long flags
, WXDWORD
*exstyle
) const
1159 // translate common wxWidgets styles to Windows ones
1161 // most of windows are child ones, those which are not (such as
1162 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1163 WXDWORD style
= WS_CHILD
;
1165 // using this flag results in very significant reduction in flicker,
1166 // especially with controls inside the static boxes (as the interior of the
1167 // box is not redrawn twice).but sometimes results in redraw problems, so
1168 // optionally allow the old code to continue to use it provided a special
1169 // system option is turned on
1170 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1171 || (flags
& wxCLIP_CHILDREN
) )
1172 style
|= WS_CLIPCHILDREN
;
1174 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1175 // don't support overlapping windows and it only makes sense for them and,
1176 // presumably, gives the system some extra work (to manage more clipping
1177 // regions), so avoid it alltogether
1180 if ( flags
& wxVSCROLL
)
1181 style
|= WS_VSCROLL
;
1183 if ( flags
& wxHSCROLL
)
1184 style
|= WS_HSCROLL
;
1186 const wxBorder border
= GetBorder(flags
);
1188 // WS_BORDER is only required for wxBORDER_SIMPLE
1189 if ( border
== wxBORDER_SIMPLE
)
1192 // now deal with ext style if the caller wants it
1198 if ( flags
& wxTRANSPARENT_WINDOW
)
1199 *exstyle
|= WS_EX_TRANSPARENT
;
1205 case wxBORDER_DEFAULT
:
1206 wxFAIL_MSG( _T("unknown border style") );
1210 case wxBORDER_SIMPLE
:
1213 case wxBORDER_STATIC
:
1214 *exstyle
|= WS_EX_STATICEDGE
;
1217 case wxBORDER_RAISED
:
1218 *exstyle
|= WS_EX_DLGMODALFRAME
;
1221 case wxBORDER_SUNKEN
:
1222 *exstyle
|= WS_EX_CLIENTEDGE
;
1223 style
&= ~WS_BORDER
;
1226 case wxBORDER_DOUBLE
:
1227 *exstyle
|= WS_EX_DLGMODALFRAME
;
1231 // wxUniv doesn't use Windows dialog navigation functions at all
1232 #if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
1233 // to make the dialog navigation work with the nested panels we must
1234 // use this style (top level windows such as dialogs don't need it)
1235 if ( (flags
& wxTAB_TRAVERSAL
) && !IsTopLevel() )
1237 *exstyle
|= WS_EX_CONTROLPARENT
;
1239 #endif // __WXUNIVERSAL__
1245 // Setup background and foreground colours correctly
1246 void wxWindowMSW::SetupColours()
1249 SetBackgroundColour(GetParent()->GetBackgroundColour());
1252 bool wxWindowMSW::IsMouseInWindow() const
1254 // get the mouse position
1257 ::GetCursorPosWinCE(&pt
);
1259 ::GetCursorPos(&pt
);
1262 // find the window which currently has the cursor and go up the window
1263 // chain until we find this window - or exhaust it
1264 HWND hwnd
= ::WindowFromPoint(pt
);
1265 while ( hwnd
&& (hwnd
!= GetHwnd()) )
1266 hwnd
= ::GetParent(hwnd
);
1268 return hwnd
!= NULL
;
1271 void wxWindowMSW::OnInternalIdle()
1273 #ifndef HAVE_TRACKMOUSEEVENT
1274 // Check if we need to send a LEAVE event
1275 if ( m_mouseInWindow
)
1277 // note that we should generate the leave event whether the window has
1278 // or doesn't have mouse capture
1279 if ( !IsMouseInWindow() )
1281 GenerateMouseLeave();
1284 #endif // !HAVE_TRACKMOUSEEVENT
1286 if (wxUpdateUIEvent::CanUpdate(this))
1287 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1290 // Set this window to be the child of 'parent'.
1291 bool wxWindowMSW::Reparent(wxWindowBase
*parent
)
1293 if ( !wxWindowBase::Reparent(parent
) )
1296 HWND hWndChild
= GetHwnd();
1297 HWND hWndParent
= GetParent() ? GetWinHwnd(GetParent()) : (HWND
)0;
1299 ::SetParent(hWndChild
, hWndParent
);
1302 if ( ::GetWindowLong(hWndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1304 EnsureParentHasControlParentStyle(GetParent());
1306 #endif // !__WXWINCE__
1311 static inline void SendSetRedraw(HWND hwnd
, bool on
)
1313 #ifndef __WXMICROWIN__
1314 ::SendMessage(hwnd
, WM_SETREDRAW
, (WPARAM
)on
, 0);
1318 void wxWindowMSW::Freeze()
1320 if ( !m_frozenness
++ )
1323 SendSetRedraw(GetHwnd(), false);
1327 void wxWindowMSW::Thaw()
1329 wxASSERT_MSG( m_frozenness
> 0, _T("Thaw() without matching Freeze()") );
1331 if ( !--m_frozenness
)
1335 SendSetRedraw(GetHwnd(), true);
1337 // we need to refresh everything or otherwise the invalidated area
1338 // is not going to be repainted
1344 void wxWindowMSW::Refresh(bool eraseBack
, const wxRect
*rect
)
1346 HWND hWnd
= GetHwnd();
1353 mswRect
.left
= rect
->x
;
1354 mswRect
.top
= rect
->y
;
1355 mswRect
.right
= rect
->x
+ rect
->width
;
1356 mswRect
.bottom
= rect
->y
+ rect
->height
;
1365 #ifndef __SMARTPHONE__
1366 UINT flags
= RDW_INVALIDATE
| RDW_ALLCHILDREN
;
1370 ::RedrawWindow(hWnd
, pRect
, NULL
, flags
);
1372 ::InvalidateRect(hWnd
, pRect
, eraseBack
);
1377 void wxWindowMSW::Update()
1379 if ( !::UpdateWindow(GetHwnd()) )
1381 wxLogLastError(_T("UpdateWindow"));
1384 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1385 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1386 // handler needs to be really drawn right now
1391 // ---------------------------------------------------------------------------
1393 // ---------------------------------------------------------------------------
1396 #if wxUSE_DRAG_AND_DROP
1397 void wxWindowMSW::SetDropTarget(wxDropTarget
*pDropTarget
)
1399 if ( m_dropTarget
!= 0 ) {
1400 m_dropTarget
->Revoke(m_hWnd
);
1401 delete m_dropTarget
;
1404 m_dropTarget
= pDropTarget
;
1405 if ( m_dropTarget
!= 0 )
1406 m_dropTarget
->Register(m_hWnd
);
1408 #endif // wxUSE_DRAG_AND_DROP
1410 // old style file-manager drag&drop support: we retain the old-style
1411 // DragAcceptFiles in parallel with SetDropTarget.
1412 void wxWindowMSW::DragAcceptFiles(bool accept
)
1414 #if !defined(__WXWINCE__)
1415 HWND hWnd
= GetHwnd();
1417 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
1419 wxUnusedVar(accept
);
1423 // ----------------------------------------------------------------------------
1425 // ----------------------------------------------------------------------------
1429 void wxWindowMSW::DoSetToolTip(wxToolTip
*tooltip
)
1431 wxWindowBase::DoSetToolTip(tooltip
);
1434 m_tooltip
->SetWindow((wxWindow
*)this);
1437 #endif // wxUSE_TOOLTIPS
1439 // ---------------------------------------------------------------------------
1440 // moving and resizing
1441 // ---------------------------------------------------------------------------
1444 void wxWindowMSW::DoGetSize(int *x
, int *y
) const
1446 RECT rect
= wxGetWindowRect(GetHwnd());
1449 *x
= rect
.right
- rect
.left
;
1451 *y
= rect
.bottom
- rect
.top
;
1454 // Get size *available for subwindows* i.e. excluding menu bar etc.
1455 void wxWindowMSW::DoGetClientSize(int *x
, int *y
) const
1457 RECT rect
= wxGetClientRect(GetHwnd());
1465 void wxWindowMSW::DoGetPosition(int *x
, int *y
) const
1467 RECT rect
= wxGetWindowRect(GetHwnd());
1470 point
.x
= rect
.left
;
1473 // we do the adjustments with respect to the parent only for the "real"
1474 // children, not for the dialogs/frames
1475 if ( !IsTopLevel() )
1477 HWND hParentWnd
= 0;
1478 wxWindow
*parent
= GetParent();
1480 hParentWnd
= GetWinHwnd(parent
);
1482 // Since we now have the absolute screen coords, if there's a parent we
1483 // must subtract its top left corner
1486 ::ScreenToClient(hParentWnd
, &point
);
1491 // We may be faking the client origin. So a window that's really at (0,
1492 // 30) may appear (to wxWin apps) to be at (0, 0).
1493 wxPoint
pt(parent
->GetClientAreaOrigin());
1505 void wxWindowMSW::DoScreenToClient(int *x
, int *y
) const
1513 ::ScreenToClient(GetHwnd(), &pt
);
1521 void wxWindowMSW::DoClientToScreen(int *x
, int *y
) const
1529 ::ClientToScreen(GetHwnd(), &pt
);
1537 void wxWindowMSW::DoMoveWindow(int x
, int y
, int width
, int height
)
1539 // TODO: is this consistent with other platforms?
1540 // Still, negative width or height shouldn't be allowed
1546 // if our parent had prepared a defer window handle for us, use it (unless
1547 // we are a top level window)
1548 wxWindowMSW
*parent
= GetParent();
1549 HDWP hdwp
= parent
&& !IsTopLevel() ? (HDWP
)parent
->m_hDWP
: NULL
;
1552 hdwp
= ::DeferWindowPos(hdwp
, GetHwnd(), NULL
,
1553 x
, y
, width
, height
,
1557 wxLogLastError(_T("DeferWindowPos"));
1560 // hdwp must be updated as it may have been changed
1561 parent
->m_hDWP
= (WXHANDLE
)hdwp
;
1564 // otherwise (or if deferring failed) move the window in place immediately
1567 if ( !::MoveWindow(GetHwnd(), x
, y
, width
, height
, IsShown()) )
1569 wxLogLastError(wxT("MoveWindow"));
1574 // set the size of the window: if the dimensions are positive, just use them,
1575 // but if any of them is equal to -1, it means that we must find the value for
1576 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1577 // which case -1 is a valid value for x and y)
1579 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1580 // the width/height to best suit our contents, otherwise we reuse the current
1582 void wxWindowMSW::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1584 // get the current size and position...
1585 int currentX
, currentY
;
1586 GetPosition(¤tX
, ¤tY
);
1587 int currentW
,currentH
;
1588 GetSize(¤tW
, ¤tH
);
1590 // ... and don't do anything (avoiding flicker) if it's already ok
1591 if ( x
== currentX
&& y
== currentY
&&
1592 width
== currentW
&& height
== currentH
)
1597 if ( x
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1599 if ( y
== wxDefaultCoord
&& !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1602 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1604 wxSize size
= wxDefaultSize
;
1605 if ( width
== wxDefaultCoord
)
1607 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1609 size
= DoGetBestSize();
1614 // just take the current one
1619 if ( height
== wxDefaultCoord
)
1621 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1623 if ( size
.x
== wxDefaultCoord
)
1625 size
= DoGetBestSize();
1627 //else: already called DoGetBestSize() above
1633 // just take the current one
1638 DoMoveWindow(x
, y
, width
, height
);
1641 void wxWindowMSW::DoSetClientSize(int width
, int height
)
1643 // setting the client size is less obvious than it it could have been
1644 // because in the result of changing the total size the window scrollbar
1645 // may [dis]appear and/or its menubar may [un]wrap and so the client size
1646 // will not be correct as the difference between the total and client size
1647 // changes - so we keep changing it until we get it right
1649 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1650 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1651 // may become 3 if the window had 0 size originally and so we didn't
1652 // calculate the scrollbar correction correctly during the first iteration)
1653 // but just to be on the safe side we check for it instead of making it an
1654 // "infinite" loop (i.e. leaving break inside as the only way to get out)
1655 for ( int i
= 0; i
< 4; i
++ )
1658 ::GetClientRect(GetHwnd(), &rectClient
);
1660 // if the size is already ok, stop here (rectClient.left = top = 0)
1661 if ( (rectClient
.right
== width
|| width
== wxDefaultCoord
) &&
1662 (rectClient
.bottom
== height
|| height
== wxDefaultCoord
) )
1667 int widthClient
= width
,
1668 heightClient
= height
;
1670 // Find the difference between the entire window (title bar and all)
1671 // and the client area; add this to the new client size to move the
1674 ::GetWindowRect(GetHwnd(), &rectWin
);
1676 widthClient
+= rectWin
.right
- rectWin
.left
- rectClient
.right
;
1677 heightClient
+= rectWin
.bottom
- rectWin
.top
- rectClient
.bottom
;
1680 point
.x
= rectWin
.left
;
1681 point
.y
= rectWin
.top
;
1683 // MoveWindow positions the child windows relative to the parent, so
1684 // adjust if necessary
1685 if ( !IsTopLevel() )
1687 wxWindow
*parent
= GetParent();
1690 ::ScreenToClient(GetHwndOf(parent
), &point
);
1694 DoMoveWindow(point
.x
, point
.y
, widthClient
, heightClient
);
1698 // ---------------------------------------------------------------------------
1700 // ---------------------------------------------------------------------------
1702 int wxWindowMSW::GetCharHeight() const
1704 return wxGetTextMetrics(this).tmHeight
;
1707 int wxWindowMSW::GetCharWidth() const
1709 // +1 is needed because Windows apparently adds it when calculating the
1710 // dialog units size in pixels
1711 #if wxDIALOG_UNIT_COMPATIBILITY
1712 return wxGetTextMetrics(this).tmAveCharWidth
;
1714 return wxGetTextMetrics(this).tmAveCharWidth
+ 1;
1718 void wxWindowMSW::GetTextExtent(const wxString
& string
,
1720 int *descent
, int *externalLeading
,
1721 const wxFont
*theFont
) const
1723 wxASSERT_MSG( !theFont
|| theFont
->Ok(),
1724 _T("invalid font in GetTextExtent()") );
1728 fontToUse
= *theFont
;
1730 fontToUse
= GetFont();
1732 WindowHDC
hdc(GetHwnd());
1733 SelectInHDC
selectFont(hdc
, GetHfontOf(fontToUse
));
1737 GetTextExtentPoint(hdc
, string
, string
.length(), &sizeRect
);
1738 GetTextMetrics(hdc
, &tm
);
1745 *descent
= tm
.tmDescent
;
1746 if ( externalLeading
)
1747 *externalLeading
= tm
.tmExternalLeading
;
1750 // ---------------------------------------------------------------------------
1752 // ---------------------------------------------------------------------------
1754 #if wxUSE_MENUS_NATIVE
1756 // yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
1757 // immediately, without waiting for the next event loop iteration
1759 // NB: this function should probably be made public later as it can almost
1760 // surely replace wxYield() elsewhere as well
1761 static void wxYieldForCommandsOnly()
1763 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
1764 // want to process it here)
1766 while ( ::PeekMessage(&msg
, (HWND
)0, WM_COMMAND
, WM_COMMAND
, PM_REMOVE
) )
1768 if ( msg
.message
== WM_QUIT
)
1770 // if we retrieved a WM_QUIT, insert back into the message queue.
1771 ::PostQuitMessage(0);
1775 // luckily (as we don't have access to wxEventLoopImpl method from here
1776 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
1778 ::TranslateMessage(&msg
);
1779 ::DispatchMessage(&msg
);
1783 bool wxWindowMSW::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1785 menu
->SetInvokingWindow(this);
1788 if ( x
== wxDefaultCoord
&& y
== wxDefaultCoord
)
1790 wxPoint mouse
= ScreenToClient(wxGetMousePosition());
1791 x
= mouse
.x
; y
= mouse
.y
;
1794 HWND hWnd
= GetHwnd();
1795 HMENU hMenu
= GetHmenuOf(menu
);
1799 ::ClientToScreen(hWnd
, &point
);
1800 wxCurrentPopupMenu
= menu
;
1801 #if defined(__WXWINCE__)
1804 UINT flags
= TPM_RIGHTBUTTON
;
1806 ::TrackPopupMenu(hMenu
, flags
, point
.x
, point
.y
, 0, hWnd
, NULL
);
1808 // we need to do it righ now as otherwise the events are never going to be
1809 // sent to wxCurrentPopupMenu from HandleCommand()
1811 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
1812 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
1813 // destroyed as soon as we return (it can be a local variable in the caller
1814 // for example) and so we do need to process the event immediately
1815 wxYieldForCommandsOnly();
1817 wxCurrentPopupMenu
= NULL
;
1819 menu
->SetInvokingWindow(NULL
);
1824 #endif // wxUSE_MENUS_NATIVE
1826 // ===========================================================================
1827 // pre/post message processing
1828 // ===========================================================================
1830 WXLRESULT
wxWindowMSW::MSWDefWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1833 return ::CallWindowProc(CASTWNDPROC m_oldWndProc
, GetHwnd(), (UINT
) nMsg
, (WPARAM
) wParam
, (LPARAM
) lParam
);
1835 return ::DefWindowProc(GetHwnd(), nMsg
, wParam
, lParam
);
1838 bool wxWindowMSW::MSWProcessMessage(WXMSG
* pMsg
)
1840 // wxUniversal implements tab traversal itself
1841 #ifndef __WXUNIVERSAL__
1842 if ( m_hWnd
!= 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL
) )
1844 // intercept dialog navigation keys
1845 MSG
*msg
= (MSG
*)pMsg
;
1847 // here we try to do all the job which ::IsDialogMessage() usually does
1849 if ( msg
->message
== WM_KEYDOWN
)
1851 bool bCtrlDown
= wxIsCtrlDown();
1852 bool bShiftDown
= wxIsShiftDown();
1854 // WM_GETDLGCODE: ask the control if it wants the key for itself,
1855 // don't process it if it's the case (except for Ctrl-Tab/Enter
1856 // combinations which are always processed)
1860 lDlgCode
= ::SendMessage(msg
->hwnd
, WM_GETDLGCODE
, 0, 0);
1862 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
1863 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
1864 // it, of course, implies them
1865 if ( lDlgCode
& DLGC_WANTALLKEYS
)
1867 lDlgCode
|= DLGC_WANTTAB
| DLGC_WANTARROWS
;
1871 bool bForward
= true,
1872 bWindowChange
= false,
1875 // should we process this message specially?
1876 bool bProcess
= true;
1877 switch ( msg
->wParam
)
1880 if ( lDlgCode
& DLGC_WANTTAB
) {
1884 // Ctrl-Tab cycles thru notebook pages
1885 bWindowChange
= bCtrlDown
;
1886 bForward
= !bShiftDown
;
1893 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
1901 if ( (lDlgCode
& DLGC_WANTARROWS
) || bCtrlDown
)
1908 wxButton
*btn
= wxDynamicCast(FindWindow(wxID_CANCEL
),wxButton
);
1910 // our own wxLogDialog should react to Esc
1911 // without Cancel button but this is a private class
1912 // so let's try recognize it by content
1913 #if wxUSE_LOG_DIALOG
1915 wxDynamicCast(this,wxDialog
) &&
1916 FindWindow(wxID_MORE
) &&
1917 FindWindow(wxID_OK
) &&
1918 !FindWindow(wxID_CANCEL
) &&
1919 GetTitle().MakeLower().StartsWith(wxTheApp
->GetAppName().c_str())
1921 btn
= wxDynamicCast(FindWindow(wxID_OK
),wxButton
);
1922 #endif // wxUSE_LOG_DIALOG
1923 if ( btn
&& btn
->IsEnabled() )
1925 // if we do have a cancel button, do press it
1926 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
1928 // we consumed the message
1931 #endif // wxUSE_BUTTON
1939 if ( (lDlgCode
& DLGC_WANTMESSAGE
) && !bCtrlDown
)
1941 // control wants to process Enter itself, don't
1942 // call IsDialogMessage() which would interpret
1946 else if ( lDlgCode
& DLGC_BUTTON
)
1948 // let IsDialogMessage() handle this for all
1949 // buttons except the owner-drawn ones which it
1950 // just seems to ignore
1951 long style
= ::GetWindowLong(msg
->hwnd
, GWL_STYLE
);
1952 if ( (style
& BS_OWNERDRAW
) == BS_OWNERDRAW
)
1954 // emulate the button click
1955 wxWindow
*btn
= wxFindWinFromHandle((WXHWND
)msg
->hwnd
);
1957 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
1962 // FIXME: this should be handled by
1963 // wxNavigationKeyEvent handler and not here!
1967 wxButton
*btn
= wxDynamicCast(GetDefaultItem(),
1969 if ( btn
&& btn
->IsEnabled() )
1971 // if we do have a default button, do press it
1972 btn
->MSWCommand(BN_CLICKED
, 0 /* unused */);
1976 else // no default button
1977 #endif // wxUSE_BUTTON
1979 // this is a quick and dirty test for a text
1981 if ( !(lDlgCode
& DLGC_HASSETSEL
) )
1983 // don't process Enter, the control might
1984 // need it for itself and don't let
1985 // ::IsDialogMessage() have it as it can
1986 // eat the Enter events sometimes
1989 else if (!IsTopLevel())
1991 // if not a top level window, let parent
1995 //else: treat Enter as TAB: pass to the next
1996 // control as this is the best thing to do
1997 // if the text doesn't handle Enter itself
2009 wxNavigationKeyEvent event
;
2010 event
.SetDirection(bForward
);
2011 event
.SetWindowChange(bWindowChange
);
2012 event
.SetFromTab(bFromTab
);
2013 event
.SetEventObject(this);
2015 if ( GetEventHandler()->ProcessEvent(event
) )
2022 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2023 // message even when there is no cancel button and when the message is
2024 // needed by the control itself: in particular, it prevents the tree in
2025 // place edit control from being closed with Escape in a dialog
2026 if ( msg
->message
!= WM_KEYDOWN
|| msg
->wParam
!= VK_ESCAPE
)
2028 // ::IsDialogMessage() is broken and may sometimes hang the
2029 // application by going into an infinite loop, so we try to detect
2030 // [some of] the situatations when this may happen and not call it
2033 // assume we can call it by default
2034 bool canSafelyCallIsDlgMsg
= true;
2036 HWND hwndFocus
= ::GetFocus();
2038 // if the currently focused window itself has WS_EX_CONTROLPARENT style, ::IsDialogMessage() will also enter
2039 // an infinite loop, because it will recursively check the child
2040 // windows but not the window itself and so if none of the children
2041 // accepts focus it loops forever (as it only stops when it gets
2042 // back to the window it started from)
2044 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2045 // style has the focus, it can happen. One such possibility is if
2046 // all windows are either toplevel, wxDialog, wxPanel or static
2047 // controls and no window can actually accept keyboard input.
2048 #if !defined(__WXWINCE__)
2049 if ( ::GetWindowLong(hwndFocus
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
2051 // passimistic by default
2052 canSafelyCallIsDlgMsg
= false;
2053 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2055 node
= node
->GetNext() )
2057 wxWindow
* const win
= node
->GetData();
2058 if ( win
->AcceptsFocus() &&
2059 !(::GetWindowLong(GetHwndOf(win
), GWL_EXSTYLE
) &
2060 WS_EX_CONTROLPARENT
) )
2062 // it shouldn't hang...
2063 canSafelyCallIsDlgMsg
= true;
2069 #endif // !__WXWINCE__
2071 if ( canSafelyCallIsDlgMsg
)
2073 // ::IsDialogMessage() can enter in an infinite loop when the
2074 // currently focused window is disabled or hidden and its
2075 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2079 if ( !::IsWindowEnabled(hwndFocus
) ||
2080 !::IsWindowVisible(hwndFocus
) )
2082 // it would enter an infinite loop if we do this!
2083 canSafelyCallIsDlgMsg
= false;
2088 if ( !(::GetWindowLong(hwndFocus
, GWL_STYLE
) & WS_CHILD
) )
2090 // it's a top level window, don't go further -- e.g. even
2091 // if the parent of a dialog is disabled, this doesn't
2092 // break navigation inside the dialog
2096 hwndFocus
= ::GetParent(hwndFocus
);
2100 // let IsDialogMessage() have the message if it's safe to call it
2101 if ( canSafelyCallIsDlgMsg
&& ::IsDialogMessage(GetHwnd(), msg
) )
2103 // IsDialogMessage() did something...
2108 #endif // __WXUNIVERSAL__
2113 // relay mouse move events to the tooltip control
2114 MSG
*msg
= (MSG
*)pMsg
;
2115 if ( msg
->message
== WM_MOUSEMOVE
)
2116 m_tooltip
->RelayEvent(pMsg
);
2118 #endif // wxUSE_TOOLTIPS
2123 bool wxWindowMSW::MSWTranslateMessage(WXMSG
* pMsg
)
2125 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2126 return m_acceleratorTable
.Translate(this, pMsg
);
2130 #endif // wxUSE_ACCEL
2133 bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG
* WXUNUSED(pMsg
))
2135 // preprocess all messages by default
2139 // ---------------------------------------------------------------------------
2140 // message params unpackers
2141 // ---------------------------------------------------------------------------
2143 void wxWindowMSW::UnpackCommand(WXWPARAM wParam
, WXLPARAM lParam
,
2144 WORD
*id
, WXHWND
*hwnd
, WORD
*cmd
)
2146 *id
= LOWORD(wParam
);
2147 *hwnd
= (WXHWND
)lParam
;
2148 *cmd
= HIWORD(wParam
);
2151 void wxWindowMSW::UnpackActivate(WXWPARAM wParam
, WXLPARAM lParam
,
2152 WXWORD
*state
, WXWORD
*minimized
, WXHWND
*hwnd
)
2154 *state
= LOWORD(wParam
);
2155 *minimized
= HIWORD(wParam
);
2156 *hwnd
= (WXHWND
)lParam
;
2159 void wxWindowMSW::UnpackScroll(WXWPARAM wParam
, WXLPARAM lParam
,
2160 WXWORD
*code
, WXWORD
*pos
, WXHWND
*hwnd
)
2162 *code
= LOWORD(wParam
);
2163 *pos
= HIWORD(wParam
);
2164 *hwnd
= (WXHWND
)lParam
;
2167 void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam
, WXLPARAM lParam
,
2168 WXHDC
*hdc
, WXHWND
*hwnd
)
2170 *hwnd
= (WXHWND
)lParam
;
2171 *hdc
= (WXHDC
)wParam
;
2174 void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam
, WXLPARAM lParam
,
2175 WXWORD
*item
, WXWORD
*flags
, WXHMENU
*hmenu
)
2177 *item
= (WXWORD
)wParam
;
2178 *flags
= HIWORD(wParam
);
2179 *hmenu
= (WXHMENU
)lParam
;
2182 // ---------------------------------------------------------------------------
2183 // Main wxWidgets window proc and the window proc for wxWindow
2184 // ---------------------------------------------------------------------------
2186 // Hook for new window just as it's being created, when the window isn't yet
2187 // associated with the handle
2188 static wxWindowMSW
*gs_winBeingCreated
= NULL
;
2190 // implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2191 // window being created and insures that it's always unset back later
2192 wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW
*winBeingCreated
)
2194 gs_winBeingCreated
= winBeingCreated
;
2197 wxWindowCreationHook::~wxWindowCreationHook()
2199 gs_winBeingCreated
= NULL
;
2203 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
2205 // trace all messages - useful for the debugging
2207 wxLogTrace(wxTraceMessages
,
2208 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2209 wxGetMessageName(message
), (long)hWnd
, (long)wParam
, lParam
);
2210 #endif // __WXDEBUG__
2212 wxWindowMSW
*wnd
= wxFindWinFromHandle((WXHWND
) hWnd
);
2214 // when we get the first message for the HWND we just created, we associate
2215 // it with wxWindow stored in gs_winBeingCreated
2216 if ( !wnd
&& gs_winBeingCreated
)
2218 wxAssociateWinWithHandle(hWnd
, gs_winBeingCreated
);
2219 wnd
= gs_winBeingCreated
;
2220 gs_winBeingCreated
= NULL
;
2221 wnd
->SetHWND((WXHWND
)hWnd
);
2227 rc
= wnd
->MSWWindowProc(message
, wParam
, lParam
);
2229 rc
= ::DefWindowProc(hWnd
, message
, wParam
, lParam
);
2234 WXLRESULT
wxWindowMSW::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
2236 // did we process the message?
2237 bool processed
= false;
2247 // for most messages we should return 0 when we do process the message
2255 processed
= HandleCreate((WXLPCREATESTRUCT
)lParam
, &mayCreate
);
2258 // return 0 to allow window creation
2259 rc
.result
= mayCreate
? 0 : -1;
2265 // never set processed to true and *always* pass WM_DESTROY to
2266 // DefWindowProc() as Windows may do some internal cleanup when
2267 // processing it and failing to pass the message along may cause
2268 // memory and resource leaks!
2269 (void)HandleDestroy();
2273 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
2277 processed
= HandleMove(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2280 #if !defined(__WXWINCE__)
2283 LPRECT pRect
= (LPRECT
)lParam
;
2285 rc
.SetLeft(pRect
->left
);
2286 rc
.SetTop(pRect
->top
);
2287 rc
.SetRight(pRect
->right
);
2288 rc
.SetBottom(pRect
->bottom
);
2289 processed
= HandleMoving(rc
);
2291 pRect
->left
= rc
.GetLeft();
2292 pRect
->top
= rc
.GetTop();
2293 pRect
->right
= rc
.GetRight();
2294 pRect
->bottom
= rc
.GetBottom();
2301 LPRECT pRect
= (LPRECT
)lParam
;
2303 rc
.SetLeft(pRect
->left
);
2304 rc
.SetTop(pRect
->top
);
2305 rc
.SetRight(pRect
->right
);
2306 rc
.SetBottom(pRect
->bottom
);
2307 processed
= HandleSizing(rc
);
2309 pRect
->left
= rc
.GetLeft();
2310 pRect
->top
= rc
.GetTop();
2311 pRect
->right
= rc
.GetRight();
2312 pRect
->bottom
= rc
.GetBottom();
2316 #endif // !__WXWINCE__
2318 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
2319 case WM_ACTIVATEAPP
:
2320 // This implicitly sends a wxEVT_ACTIVATE_APP event
2321 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
2327 WXWORD state
, minimized
;
2329 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
2331 processed
= HandleActivate(state
, minimized
!= 0, (WXHWND
)hwnd
);
2336 processed
= HandleSetFocus((WXHWND
)(HWND
)wParam
);
2340 processed
= HandleKillFocus((WXHWND
)(HWND
)wParam
);
2343 case WM_PRINTCLIENT
:
2344 processed
= HandlePrintClient((WXHDC
)wParam
);
2350 wxPaintDCEx
dc((wxWindow
*)this, (WXHDC
)wParam
);
2352 processed
= HandlePaint();
2356 processed
= HandlePaint();
2361 #ifdef __WXUNIVERSAL__
2362 // Universal uses its own wxFrame/wxDialog, so we don't receive
2363 // close events unless we have this.
2365 #endif // __WXUNIVERSAL__
2367 // don't let the DefWindowProc() destroy our window - we'll do it
2368 // ourselves in ~wxWindow
2374 processed
= HandleShow(wParam
!= 0, (int)lParam
);
2378 processed
= HandleMouseMove(GET_X_LPARAM(lParam
),
2379 GET_Y_LPARAM(lParam
),
2383 #ifdef HAVE_TRACKMOUSEEVENT
2385 // filter out excess WM_MOUSELEAVE events sent after PopupMenu() (on XP at least)
2386 if ( m_mouseInWindow
)
2388 GenerateMouseLeave();
2391 // always pass processed back as false, this allows the window
2392 // manager to process the message too. This is needed to
2393 // ensure windows XP themes work properly as the mouse moves
2394 // over widgets like buttons. So don't set processed to true here.
2396 #endif // HAVE_TRACKMOUSEEVENT
2398 #if wxUSE_MOUSEWHEEL
2400 processed
= HandleMouseWheel(wParam
, lParam
);
2404 case WM_LBUTTONDOWN
:
2406 case WM_LBUTTONDBLCLK
:
2407 case WM_RBUTTONDOWN
:
2409 case WM_RBUTTONDBLCLK
:
2410 case WM_MBUTTONDOWN
:
2412 case WM_MBUTTONDBLCLK
:
2414 #ifdef __WXMICROWIN__
2415 // MicroWindows seems to ignore the fact that a window is
2416 // disabled. So catch mouse events and throw them away if
2418 wxWindowMSW
* win
= this;
2421 if (!win
->IsEnabled())
2427 win
= win
->GetParent();
2428 if ( !win
|| win
->IsTopLevel() )
2435 #endif // __WXMICROWIN__
2436 int x
= GET_X_LPARAM(lParam
),
2437 y
= GET_Y_LPARAM(lParam
);
2439 // redirect the event to a static control if necessary by
2440 // finding one under mouse
2442 if ( GetCapture() == this )
2444 // but don't do it if the mouse is captured by this window
2445 // because then it should really get this event itself
2450 win
= FindWindowForMouseEvent(this, &x
, &y
);
2452 // this should never happen
2453 wxCHECK_MSG( win
, 0,
2454 _T("FindWindowForMouseEvent() returned NULL") );
2457 processed
= win
->HandleMouseEvent(message
, x
, y
, wParam
);
2459 // if the app didn't eat the event, handle it in the default
2460 // way, that is by giving this window the focus
2463 // for the standard classes their WndProc sets the focus to
2464 // them anyhow and doing it from here results in some weird
2465 // problems, so don't do it for them (unnecessary anyhow)
2466 if ( !win
->IsOfStandardClass() )
2468 if ( message
== WM_LBUTTONDOWN
&& win
->AcceptsFocus() )
2480 case MM_JOY1BUTTONDOWN
:
2481 case MM_JOY2BUTTONDOWN
:
2482 case MM_JOY1BUTTONUP
:
2483 case MM_JOY2BUTTONUP
:
2484 processed
= HandleJoystickEvent(message
,
2485 GET_X_LPARAM(lParam
),
2486 GET_Y_LPARAM(lParam
),
2489 #endif // __WXMICROWIN__
2495 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
2497 processed
= HandleCommand(id
, cmd
, hwnd
);
2502 processed
= HandleNotify((int)wParam
, lParam
, &rc
.result
);
2505 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
2506 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
2507 // apparently doesn't always behave properly and needs some help
2508 #if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
2509 case WM_NOTIFYFORMAT
:
2510 if ( lParam
== NF_QUERY
)
2513 rc
.result
= NFR_UNICODE
;
2516 #endif // wxUSE_UNICODE_MSLU
2518 // for these messages we must return true if process the message
2521 case WM_MEASUREITEM
:
2523 int idCtrl
= (UINT
)wParam
;
2524 if ( message
== WM_DRAWITEM
)
2526 processed
= MSWOnDrawItem(idCtrl
,
2527 (WXDRAWITEMSTRUCT
*)lParam
);
2531 processed
= MSWOnMeasureItem(idCtrl
,
2532 (WXMEASUREITEMSTRUCT
*)lParam
);
2539 #endif // defined(WM_DRAWITEM)
2542 if ( !IsOfStandardClass() )
2544 // we always want to get the char events
2545 rc
.result
= DLGC_WANTCHARS
;
2547 if ( GetWindowStyleFlag() & wxWANTS_CHARS
)
2549 // in fact, we want everything
2550 rc
.result
|= DLGC_WANTARROWS
|
2557 //else: get the dlg code from the DefWindowProc()
2562 // If this has been processed by an event handler, return 0 now
2563 // (we've handled it).
2564 m_lastKeydownProcessed
= HandleKeyDown((WORD
) wParam
, lParam
);
2565 if ( m_lastKeydownProcessed
)
2574 // we consider these message "not interesting" to OnChar, so
2575 // just don't do anything more with them
2585 // avoid duplicate messages to OnChar for these ASCII keys:
2586 // they will be translated by TranslateMessage() and received
2608 // but set processed to false, not true to still pass them
2609 // to the control's default window proc - otherwise
2610 // built-in keyboard handling won't work
2615 // special case of VK_APPS: treat it the same as right mouse
2616 // click because both usually pop up a context menu
2618 processed
= HandleMouseEvent(WM_RBUTTONDOWN
, -1, -1, 0);
2623 // do generate a CHAR event
2624 processed
= HandleChar((WORD
)wParam
, lParam
);
2627 if (message
== WM_SYSKEYDOWN
) // Let Windows still handle the SYSKEYs
2634 // special case of VK_APPS: treat it the same as right mouse button
2635 if ( wParam
== VK_APPS
)
2637 processed
= HandleMouseEvent(WM_RBUTTONUP
, -1, -1, 0);
2642 processed
= HandleKeyUp((WORD
) wParam
, lParam
);
2647 case WM_CHAR
: // Always an ASCII character
2648 if ( m_lastKeydownProcessed
)
2650 // The key was handled in the EVT_KEY_DOWN and handling
2651 // a key in an EVT_KEY_DOWN handler is meant, by
2652 // design, to prevent EVT_CHARs from happening
2653 m_lastKeydownProcessed
= false;
2658 processed
= HandleChar((WORD
)wParam
, lParam
, true);
2664 processed
= HandleHotKey((WORD
)wParam
, lParam
);
2666 #endif // wxUSE_HOTKEY
2673 UnpackScroll(wParam
, lParam
, &code
, &pos
, &hwnd
);
2675 processed
= MSWOnScroll(message
== WM_HSCROLL
? wxHORIZONTAL
2681 // CTLCOLOR messages are sent by children to query the parent for their
2683 #ifndef __WXMICROWIN__
2684 case WM_CTLCOLORMSGBOX
:
2685 case WM_CTLCOLOREDIT
:
2686 case WM_CTLCOLORLISTBOX
:
2687 case WM_CTLCOLORBTN
:
2688 case WM_CTLCOLORDLG
:
2689 case WM_CTLCOLORSCROLLBAR
:
2690 case WM_CTLCOLORSTATIC
:
2694 UnpackCtlColor(wParam
, lParam
, &hdc
, &hwnd
);
2696 processed
= HandleCtlColor(&rc
.hBrush
, (WXHDC
)hdc
, (WXHWND
)hwnd
);
2699 #endif // !__WXMICROWIN__
2701 case WM_SYSCOLORCHANGE
:
2702 // the return value for this message is ignored
2703 processed
= HandleSysColorChange();
2706 #if !defined(__WXWINCE__)
2707 case WM_DISPLAYCHANGE
:
2708 processed
= HandleDisplayChange();
2712 case WM_PALETTECHANGED
:
2713 processed
= HandlePaletteChanged((WXHWND
) (HWND
) wParam
);
2716 case WM_CAPTURECHANGED
:
2717 processed
= HandleCaptureChanged((WXHWND
) (HWND
) lParam
);
2720 case WM_QUERYNEWPALETTE
:
2721 processed
= HandleQueryNewPalette();
2725 processed
= HandleEraseBkgnd((WXHDC
)(HDC
)wParam
);
2728 // we processed the message, i.e. erased the background
2733 #if !defined(__WXWINCE__)
2735 processed
= HandleDropFiles(wParam
);
2740 processed
= HandleInitDialog((WXHWND
)(HWND
)wParam
);
2744 // we never set focus from here
2749 #if !defined(__WXWINCE__)
2750 case WM_QUERYENDSESSION
:
2751 processed
= HandleQueryEndSession(lParam
, &rc
.allow
);
2755 processed
= HandleEndSession(wParam
!= 0, lParam
);
2758 case WM_GETMINMAXINFO
:
2759 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
2764 processed
= HandleSetCursor((WXHWND
)(HWND
)wParam
,
2765 LOWORD(lParam
), // hit test
2766 HIWORD(lParam
)); // mouse msg
2770 // returning TRUE stops the DefWindowProc() from further
2771 // processing this message - exactly what we need because we've
2772 // just set the cursor.
2777 #if wxUSE_ACCESSIBILITY
2780 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
2781 LPARAM dwObjId
= (LPARAM
) (DWORD
) lParam
;
2783 if (dwObjId
== (LPARAM
)OBJID_CLIENT
&& GetOrCreateAccessible())
2785 return LresultFromObject(IID_IAccessible
, wParam
, (IUnknown
*) GetAccessible()->GetIAccessible());
2791 #if defined(WM_HELP)
2794 // HELPINFO doesn't seem to be supported on WinCE.
2796 HELPINFO
* info
= (HELPINFO
*) lParam
;
2797 // Don't yet process menu help events, just windows
2798 if (info
->iContextType
== HELPINFO_WINDOW
)
2801 wxWindowMSW
* subjectOfHelp
= this;
2802 bool eventProcessed
= false;
2803 while (subjectOfHelp
&& !eventProcessed
)
2805 wxHelpEvent
helpEvent(wxEVT_HELP
,
2806 subjectOfHelp
->GetId(),
2810 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
2814 helpEvent
.SetEventObject(this);
2816 GetEventHandler()->ProcessEvent(helpEvent
);
2818 // Go up the window hierarchy until the event is
2820 subjectOfHelp
= subjectOfHelp
->GetParent();
2823 processed
= eventProcessed
;
2826 else if (info
->iContextType
== HELPINFO_MENUITEM
)
2828 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
);
2829 helpEvent
.SetEventObject(this);
2830 processed
= GetEventHandler()->ProcessEvent(helpEvent
);
2833 //else: processed is already false
2839 #if !defined(__WXWINCE__)
2840 case WM_CONTEXTMENU
:
2842 // we don't convert from screen to client coordinates as
2843 // the event may be handled by a parent window
2844 wxPoint
pt(GET_X_LPARAM(lParam
), GET_Y_LPARAM(lParam
));
2846 wxContextMenuEvent
evtCtx(wxEVT_CONTEXT_MENU
, GetId(), pt
);
2848 // we could have got an event from our child, reflect it back
2849 // to it if this is the case
2850 wxWindowMSW
*win
= NULL
;
2851 if ( (WXHWND
)wParam
!= m_hWnd
)
2853 win
= FindItemByHWND((WXHWND
)wParam
);
2859 evtCtx
.SetEventObject(win
);
2860 processed
= win
->GetEventHandler()->ProcessEvent(evtCtx
);
2866 // we're only interested in our own menus, not MF_SYSMENU
2867 if ( HIWORD(wParam
) == MF_POPUP
)
2869 // handle menu chars for ownerdrawn menu items
2870 int i
= HandleMenuChar(toupper(LOWORD(wParam
)), lParam
);
2871 if ( i
!= wxNOT_FOUND
)
2873 rc
.result
= MAKELRESULT(i
, MNC_EXECUTE
);
2883 wxLogTrace(wxTraceMessages
, wxT("Forwarding %s to DefWindowProc."),
2884 wxGetMessageName(message
));
2885 #endif // __WXDEBUG__
2886 rc
.result
= MSWDefWindowProc(message
, wParam
, lParam
);
2892 // ----------------------------------------------------------------------------
2893 // wxWindow <-> HWND map
2894 // ----------------------------------------------------------------------------
2896 wxWinHashTable
*wxWinHandleHash
= NULL
;
2898 wxWindow
*wxFindWinFromHandle(WXHWND hWnd
)
2900 return (wxWindow
*)wxWinHandleHash
->Get((long)hWnd
);
2903 void wxAssociateWinWithHandle(HWND hWnd
, wxWindowMSW
*win
)
2905 // adding NULL hWnd is (first) surely a result of an error and
2906 // (secondly) breaks menu command processing
2907 wxCHECK_RET( hWnd
!= (HWND
)NULL
,
2908 wxT("attempt to add a NULL hWnd to window list ignored") );
2910 wxWindow
*oldWin
= wxFindWinFromHandle((WXHWND
) hWnd
);
2912 if ( oldWin
&& (oldWin
!= win
) )
2914 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
2915 (int) hWnd
, win
->GetClassInfo()->GetClassName());
2918 #endif // __WXDEBUG__
2921 wxWinHandleHash
->Put((long)hWnd
, (wxWindow
*)win
);
2925 void wxRemoveHandleAssociation(wxWindowMSW
*win
)
2927 wxWinHandleHash
->Delete((long)win
->GetHWND());
2930 // ----------------------------------------------------------------------------
2931 // various MSW speciic class dependent functions
2932 // ----------------------------------------------------------------------------
2934 // Default destroyer - override if you destroy it in some other way
2935 // (e.g. with MDI child windows)
2936 void wxWindowMSW::MSWDestroyWindow()
2940 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint
& pos
,
2943 int& w
, int& h
) const
2945 // yes, those are just some arbitrary hardcoded numbers
2946 static const int DEFAULT_Y
= 200;
2948 bool nonDefault
= false;
2950 if ( pos
.x
== wxDefaultCoord
)
2952 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
2953 // can just as well set it to CW_USEDEFAULT as well
2959 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
2960 // neither because it is not handled as a special value by Windows then
2961 // and so we have to choose some default value for it
2963 y
= pos
.y
== wxDefaultCoord
? DEFAULT_Y
: pos
.y
;
2969 NB: there used to be some code here which set the initial size of the
2970 window to the client size of the parent if no explicit size was
2971 specified. This was wrong because wxWidgets programs often assume
2972 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
2973 it. To see why, you should understand that Windows sends WM_SIZE from
2974 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
2975 from some base class ctor and so this WM_SIZE is not processed in the
2976 real class' OnSize() (because it's not fully constructed yet and the
2977 event goes to some base class OnSize() instead). So the WM_SIZE we
2978 rely on is the one sent when the parent frame resizes its children
2979 but here is the problem: if the child already has just the right
2980 size, nothing will happen as both wxWidgets and Windows check for
2981 this and ignore any attempts to change the window size to the size it
2982 already has - so no WM_SIZE would be sent.
2986 // we don't use CW_USEDEFAULT here for several reasons:
2988 // 1. it results in huge frames on modern screens (1000*800 is not
2989 // uncommon on my 1280*1024 screen) which is way too big for a half
2990 // empty frame of most of wxWidgets samples for example)
2992 // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
2993 // the default is for whatever reason 8*8 which breaks client <->
2994 // window size calculations (it would be nice if it didn't, but it
2995 // does and the simplest way to fix it seemed to change the broken
2996 // default size anyhow)
2998 // 3. there is just no advantage in doing it: with x and y it is
2999 // possible that [future versions of] Windows position the new top
3000 // level window in some smart way which we can't do, but we can
3001 // guess a reasonably good size for a new window just as well
3004 // However, on PocketPC devices, we must use the default
3005 // size if possible.
3007 if (size
.x
== wxDefaultCoord
)
3011 if (size
.y
== wxDefaultCoord
)
3016 if ( size
.x
== wxDefaultCoord
|| size
.y
== wxDefaultCoord
)
3020 w
= WidthDefault(size
.x
);
3021 h
= HeightDefault(size
.y
);
3024 AdjustForParentClientOrigin(x
, y
);
3029 WXHWND
wxWindowMSW::MSWGetParent() const
3031 return m_parent
? m_parent
->GetHWND() : WXHWND(NULL
);
3034 bool wxWindowMSW::MSWCreate(const wxChar
*wclass
,
3035 const wxChar
*title
,
3039 WXDWORD extendedStyle
)
3041 // choose the position/size for the new window
3043 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
3045 // controlId is menu handle for the top level windows, so set it to 0
3046 // unless we're creating a child window
3047 int controlId
= style
& WS_CHILD
? GetId() : 0;
3049 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3050 // which is the same but without CS_[HV]REDRAW class styles so using it
3051 // ensures that the window is not fully repainted on each resize
3052 wxString
className(wclass
);
3053 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) )
3055 className
+= wxT("NR");
3058 // do create the window
3059 wxWindowCreationHook
hook(this);
3061 m_hWnd
= (WXHWND
)::CreateWindowEx
3065 title
? title
: m_windowName
.c_str(),
3068 (HWND
)MSWGetParent(),
3071 NULL
// no extra data
3076 wxLogSysError(_("Can't create window of class %s"), className
.c_str());
3081 SubclassWin(m_hWnd
);
3086 // ===========================================================================
3087 // MSW message handlers
3088 // ===========================================================================
3090 // ---------------------------------------------------------------------------
3092 // ---------------------------------------------------------------------------
3096 bool wxWindowMSW::HandleNotify(int idCtrl
, WXLPARAM lParam
, WXLPARAM
*result
)
3098 #ifndef __WXMICROWIN__
3099 LPNMHDR hdr
= (LPNMHDR
)lParam
;
3100 HWND hWnd
= hdr
->hwndFrom
;
3101 wxWindow
*win
= wxFindWinFromHandle((WXHWND
)hWnd
);
3103 // if the control is one of our windows, let it handle the message itself
3106 return win
->MSWOnNotify(idCtrl
, lParam
, result
);
3109 // VZ: why did we do it? normally this is unnecessary and, besides, it
3110 // breaks the message processing for the toolbars because the tooltip
3111 // notifications were being forwarded to the toolbar child controls
3112 // (if it had any) before being passed to the toolbar itself, so in my
3113 // example the tooltip for the combobox was always shown instead of the
3114 // correct button tooltips
3116 // try all our children
3117 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3120 wxWindow
*child
= node
->GetData();
3121 if ( child
->MSWOnNotify(idCtrl
, lParam
, result
) )
3126 node
= node
->GetNext();
3130 // by default, handle it ourselves
3131 return MSWOnNotify(idCtrl
, lParam
, result
);
3132 #else // __WXMICROWIN__
3139 bool wxWindowMSW::HandleTooltipNotify(WXUINT code
,
3141 const wxString
& ttip
)
3143 // I don't know why it happens, but the versions of comctl32.dll starting
3144 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3145 // this message is supposed to be sent to Unicode programs only) -- hence
3146 // we need to handle it as well, otherwise no tooltips will be shown in
3149 if ( !(code
== (WXUINT
) TTN_NEEDTEXTA
|| code
== (WXUINT
) TTN_NEEDTEXTW
)
3152 // not a tooltip message or no tooltip to show anyhow
3157 LPTOOLTIPTEXT ttText
= (LPTOOLTIPTEXT
)lParam
;
3159 // We don't want to use the szText buffer because it has a limit of 80
3160 // bytes and this is not enough, especially for Unicode build where it
3161 // limits the tooltip string length to only 40 characters
3163 // The best would be, of course, to not impose any length limitations at
3164 // all but then the buffer would have to be dynamic and someone would have
3165 // to free it and we don't have the tooltip owner object here any more, so
3166 // for now use our own static buffer with a higher fixed max length.
3168 // Note that using a static buffer should not be a problem as only a single
3169 // tooltip can be shown at the same time anyhow.
3171 if ( code
== (WXUINT
) TTN_NEEDTEXTW
)
3173 // We need to convert tooltip from multi byte to Unicode on the fly.
3174 static wchar_t buf
[513];
3176 // Truncate tooltip length if needed as otherwise we might not have
3177 // enough space for it in the buffer and MultiByteToWideChar() would
3179 size_t tipLength
= wxMin(ttip
.Len(), WXSIZEOF(buf
) - 1);
3181 // Convert to WideChar without adding the NULL character. The NULL
3182 // character is added afterwards (this is more efficient).
3183 int len
= ::MultiByteToWideChar
3195 wxLogLastError(_T("MultiByteToWideChar()"));
3199 ttText
->lpszText
= (LPSTR
) buf
;
3201 else // TTN_NEEDTEXTA
3202 #endif // !wxUSE_UNICODE
3204 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3205 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3206 // to copy the string we have into the buffer
3207 static wxChar buf
[513];
3208 wxStrncpy(buf
, ttip
.c_str(), WXSIZEOF(buf
) - 1);
3209 buf
[WXSIZEOF(buf
) - 1] = _T('\0');
3210 ttText
->lpszText
= buf
;
3216 #endif // wxUSE_TOOLTIPS
3218 bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl
),
3220 WXLPARAM
* WXUNUSED(result
))
3225 NMHDR
* hdr
= (NMHDR
*)lParam
;
3226 if ( HandleTooltipNotify(hdr
->code
, lParam
, m_tooltip
->GetTip()))
3233 wxUnusedVar(lParam
);
3234 #endif // wxUSE_TOOLTIPS
3241 // ---------------------------------------------------------------------------
3242 // end session messages
3243 // ---------------------------------------------------------------------------
3245 bool wxWindowMSW::HandleQueryEndSession(long logOff
, bool *mayEnd
)
3247 #ifdef ENDSESSION_LOGOFF
3248 wxCloseEvent
event(wxEVT_QUERY_END_SESSION
, wxID_ANY
);
3249 event
.SetEventObject(wxTheApp
);
3250 event
.SetCanVeto(true);
3251 event
.SetLoggingOff(logOff
== (long)ENDSESSION_LOGOFF
);
3253 bool rc
= wxTheApp
->ProcessEvent(event
);
3257 // we may end only if the app didn't veto session closing (double
3259 *mayEnd
= !event
.GetVeto();
3264 wxUnusedVar(logOff
);
3265 wxUnusedVar(mayEnd
);
3270 bool wxWindowMSW::HandleEndSession(bool endSession
, long logOff
)
3272 #ifdef ENDSESSION_LOGOFF
3273 // do nothing if the session isn't ending
3278 if ( (this != wxTheApp
->GetTopWindow()) )
3281 wxCloseEvent
event(wxEVT_END_SESSION
, wxID_ANY
);
3282 event
.SetEventObject(wxTheApp
);
3283 event
.SetCanVeto(false);
3284 event
.SetLoggingOff( (logOff
== (long)ENDSESSION_LOGOFF
) );
3286 return wxTheApp
->ProcessEvent(event
);
3288 wxUnusedVar(endSession
);
3289 wxUnusedVar(logOff
);
3294 // ---------------------------------------------------------------------------
3295 // window creation/destruction
3296 // ---------------------------------------------------------------------------
3298 bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT cs
, bool *mayCreate
)
3300 // VZ: why is this commented out for WinCE? If it doesn't support
3301 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3302 // not with multiple #ifdef's!
3304 if ( ((CREATESTRUCT
*)cs
)->dwExStyle
& WS_EX_CONTROLPARENT
)
3305 EnsureParentHasControlParentStyle(GetParent());
3308 #endif // !__WXWINCE__
3310 // TODO: should generate this event from WM_NCCREATE
3311 wxWindowCreateEvent
event((wxWindow
*)this);
3312 (void)GetEventHandler()->ProcessEvent(event
);
3319 bool wxWindowMSW::HandleDestroy()
3323 // delete our drop target if we've got one
3324 #if wxUSE_DRAG_AND_DROP
3325 if ( m_dropTarget
!= NULL
)
3327 m_dropTarget
->Revoke(m_hWnd
);
3329 delete m_dropTarget
;
3330 m_dropTarget
= NULL
;
3332 #endif // wxUSE_DRAG_AND_DROP
3334 // WM_DESTROY handled
3338 // ---------------------------------------------------------------------------
3340 // ---------------------------------------------------------------------------
3342 bool wxWindowMSW::HandleActivate(int state
,
3343 bool WXUNUSED(minimized
),
3344 WXHWND
WXUNUSED(activate
))
3346 wxActivateEvent
event(wxEVT_ACTIVATE
,
3347 (state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
),
3349 event
.SetEventObject(this);
3351 return GetEventHandler()->ProcessEvent(event
);
3354 bool wxWindowMSW::HandleSetFocus(WXHWND hwnd
)
3356 // Strangly enough, some controls get set focus events when they are being
3357 // deleted, even if they already had focus before.
3358 if ( m_isBeingDeleted
)
3363 // notify the parent keeping track of focus for the kbd navigation
3364 // purposes that we got it
3365 wxChildFocusEvent
eventFocus((wxWindow
*)this);
3366 (void)GetEventHandler()->ProcessEvent(eventFocus
);
3372 m_caret
->OnSetFocus();
3374 #endif // wxUSE_CARET
3377 // If it's a wxTextCtrl don't send the event as it will be done
3378 // after the control gets to process it from EN_FOCUS handler
3379 if ( wxDynamicCastThis(wxTextCtrl
) )
3383 #endif // wxUSE_TEXTCTRL
3385 wxFocusEvent
event(wxEVT_SET_FOCUS
, m_windowId
);
3386 event
.SetEventObject(this);
3388 // wxFindWinFromHandle() may return NULL, it is ok
3389 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3391 return GetEventHandler()->ProcessEvent(event
);
3394 bool wxWindowMSW::HandleKillFocus(WXHWND hwnd
)
3400 m_caret
->OnKillFocus();
3402 #endif // wxUSE_CARET
3405 // If it's a wxTextCtrl don't send the event as it will be done
3406 // after the control gets to process it.
3407 wxTextCtrl
*ctrl
= wxDynamicCastThis(wxTextCtrl
);
3414 // Don't send the event when in the process of being deleted. This can
3415 // only cause problems if the event handler tries to access the object.
3416 if ( m_isBeingDeleted
)
3421 wxFocusEvent
event(wxEVT_KILL_FOCUS
, m_windowId
);
3422 event
.SetEventObject(this);
3424 // wxFindWinFromHandle() may return NULL, it is ok
3425 event
.SetWindow(wxFindWinFromHandle(hwnd
));
3427 return GetEventHandler()->ProcessEvent(event
);
3430 // ---------------------------------------------------------------------------
3432 // ---------------------------------------------------------------------------
3434 bool wxWindowMSW::HandleShow(bool show
, int WXUNUSED(status
))
3436 wxShowEvent
event(GetId(), show
);
3437 event
.SetEventObject(this);
3439 return GetEventHandler()->ProcessEvent(event
);
3442 bool wxWindowMSW::HandleInitDialog(WXHWND
WXUNUSED(hWndFocus
))
3444 wxInitDialogEvent
event(GetId());
3445 event
.SetEventObject(this);
3447 return GetEventHandler()->ProcessEvent(event
);
3450 bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam
)
3452 #if defined (__WXMICROWIN__) || defined(__WXWINCE__)
3453 wxUnusedVar(wParam
);
3455 #else // __WXMICROWIN__
3456 HDROP hFilesInfo
= (HDROP
) wParam
;
3458 // Get the total number of files dropped
3459 UINT gwFilesDropped
= ::DragQueryFile
3467 wxString
*files
= new wxString
[gwFilesDropped
];
3468 for ( UINT wIndex
= 0; wIndex
< gwFilesDropped
; wIndex
++ )
3470 // first get the needed buffer length (+1 for terminating NUL)
3471 size_t len
= ::DragQueryFile(hFilesInfo
, wIndex
, NULL
, 0) + 1;
3473 // and now get the file name
3474 ::DragQueryFile(hFilesInfo
, wIndex
,
3475 wxStringBuffer(files
[wIndex
], len
), len
);
3477 DragFinish (hFilesInfo
);
3479 wxDropFilesEvent
event(wxEVT_DROP_FILES
, gwFilesDropped
, files
);
3480 event
.SetEventObject(this);
3483 DragQueryPoint(hFilesInfo
, (LPPOINT
) &dropPoint
);
3484 event
.m_pos
.x
= dropPoint
.x
;
3485 event
.m_pos
.y
= dropPoint
.y
;
3487 return GetEventHandler()->ProcessEvent(event
);
3492 bool wxWindowMSW::HandleSetCursor(WXHWND
WXUNUSED(hWnd
),
3494 int WXUNUSED(mouseMsg
))
3496 #ifndef __WXMICROWIN__
3497 // the logic is as follows:
3498 // -1. don't set cursor for non client area, including but not limited to
3499 // the title bar, scrollbars, &c
3500 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
3501 // 1. if we have the cursor set it unless wxIsBusy()
3502 // 2. if we're a top level window, set some cursor anyhow
3503 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
3505 if ( nHitTest
!= HTCLIENT
)
3510 HCURSOR hcursor
= 0;
3512 // first ask the user code - it may wish to set the cursor in some very
3513 // specific way (for example, depending on the current position)
3516 if ( !::GetCursorPosWinCE(&pt
))
3518 if ( !::GetCursorPos(&pt
) )
3521 wxLogLastError(wxT("GetCursorPos"));
3526 ScreenToClient(&x
, &y
);
3527 wxSetCursorEvent
event(x
, y
);
3529 bool processedEvtSetCursor
= GetEventHandler()->ProcessEvent(event
);
3530 if ( processedEvtSetCursor
&& event
.HasCursor() )
3532 hcursor
= GetHcursorOf(event
.GetCursor());
3537 bool isBusy
= wxIsBusy();
3539 // the test for processedEvtSetCursor is here to prevent using m_cursor
3540 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3541 // it - this is a way to say that our cursor shouldn't be used for this
3543 if ( !processedEvtSetCursor
&& m_cursor
.Ok() )
3545 hcursor
= GetHcursorOf(m_cursor
);
3552 hcursor
= wxGetCurrentBusyCursor();
3554 else if ( !hcursor
)
3556 const wxCursor
*cursor
= wxGetGlobalCursor();
3557 if ( cursor
&& cursor
->Ok() )
3559 hcursor
= GetHcursorOf(*cursor
);
3567 // wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3569 ::SetCursor(hcursor
);
3571 // cursor set, stop here
3574 #endif // __WXMICROWIN__
3576 // pass up the window chain
3580 // ---------------------------------------------------------------------------
3581 // owner drawn stuff
3582 // ---------------------------------------------------------------------------
3584 #if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
3585 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
3586 #define WXUNUSED_UNLESS_ODRAWN(param) param
3588 #define WXUNUSED_UNLESS_ODRAWN(param)
3592 wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id
),
3593 WXDRAWITEMSTRUCT
* WXUNUSED_UNLESS_ODRAWN(itemStruct
))
3595 #if wxUSE_OWNER_DRAWN
3597 #if wxUSE_MENUS_NATIVE
3598 // is it a menu item?
3599 DRAWITEMSTRUCT
*pDrawStruct
= (DRAWITEMSTRUCT
*)itemStruct
;
3600 if ( id
== 0 && pDrawStruct
->CtlType
== ODT_MENU
)
3602 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pDrawStruct
->itemData
);
3604 // see comment before the same test in MSWOnMeasureItem() below
3608 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
3609 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
3611 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
3612 // the DC from being released
3613 wxDCTemp
dc((WXHDC
)pDrawStruct
->hDC
);
3614 wxRect
rect(pDrawStruct
->rcItem
.left
, pDrawStruct
->rcItem
.top
,
3615 pDrawStruct
->rcItem
.right
- pDrawStruct
->rcItem
.left
,
3616 pDrawStruct
->rcItem
.bottom
- pDrawStruct
->rcItem
.top
);
3618 return pMenuItem
->OnDrawItem
3622 (wxOwnerDrawn::wxODAction
)pDrawStruct
->itemAction
,
3623 (wxOwnerDrawn::wxODStatus
)pDrawStruct
->itemState
3626 #endif // wxUSE_MENUS_NATIVE
3628 #endif // USE_OWNER_DRAWN
3630 #if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
3632 #if wxUSE_OWNER_DRAWN
3633 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3634 #else // !wxUSE_OWNER_DRAWN
3635 // we may still have owner-drawn buttons internally because we have to make
3636 // them owner-drawn to support colour change
3639 wxDynamicCast(FindItem(id
), wxButton
)
3644 #endif // USE_OWNER_DRAWN
3648 return item
->MSWOnDraw(itemStruct
);
3651 #endif // wxUSE_CONTROLS
3657 wxWindowMSW::MSWOnMeasureItem(int id
, WXMEASUREITEMSTRUCT
*itemStruct
)
3659 #if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
3660 // is it a menu item?
3661 MEASUREITEMSTRUCT
*pMeasureStruct
= (MEASUREITEMSTRUCT
*)itemStruct
;
3662 if ( id
== 0 && pMeasureStruct
->CtlType
== ODT_MENU
)
3664 wxMenuItem
*pMenuItem
= (wxMenuItem
*)(pMeasureStruct
->itemData
);
3666 // according to Carsten Fuchs the pointer may be NULL under XP if an
3667 // MDI child frame is initially maximized, see this for more info:
3668 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
3670 // so silently ignore it instead of asserting
3674 wxCHECK_MSG( wxDynamicCast(pMenuItem
, wxMenuItem
),
3675 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
3678 bool rc
= pMenuItem
->OnMeasureItem(&w
, &h
);
3680 pMeasureStruct
->itemWidth
= w
;
3681 pMeasureStruct
->itemHeight
= h
;
3686 wxControl
*item
= wxDynamicCast(FindItem(id
), wxControl
);
3689 return item
->MSWOnMeasure(itemStruct
);
3693 wxUnusedVar(itemStruct
);
3694 #endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
3699 // ---------------------------------------------------------------------------
3700 // colours and palettes
3701 // ---------------------------------------------------------------------------
3703 bool wxWindowMSW::HandleSysColorChange()
3705 wxSysColourChangedEvent event
;
3706 event
.SetEventObject(this);
3708 (void)GetEventHandler()->ProcessEvent(event
);
3710 // always let the system carry on the default processing to allow the
3711 // native controls to react to the colours update
3715 bool wxWindowMSW::HandleDisplayChange()
3717 wxDisplayChangedEvent event
;
3718 event
.SetEventObject(this);
3720 return GetEventHandler()->ProcessEvent(event
);
3723 #ifndef __WXMICROWIN__
3725 bool wxWindowMSW::HandleCtlColor(WXHBRUSH
*brush
, WXHDC hDC
, WXHWND hWnd
)
3727 #if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
3731 wxControl
*item
= wxDynamicCast(FindItemByHWND(hWnd
, true), wxControl
);
3734 *brush
= item
->MSWControlColor(hDC
, hWnd
);
3736 #endif // wxUSE_CONTROLS
3739 return *brush
!= NULL
;
3742 #endif // __WXMICROWIN__
3744 bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange
)
3747 // same as below except we don't respond to our own messages
3748 if ( hWndPalChange
!= GetHWND() )
3750 // check to see if we our our parents have a custom palette
3751 wxWindowMSW
*win
= this;
3752 while ( win
&& !win
->HasCustomPalette() )
3754 win
= win
->GetParent();
3757 if ( win
&& win
->HasCustomPalette() )
3759 // realize the palette to see whether redrawing is needed
3760 HDC hdc
= ::GetDC((HWND
) hWndPalChange
);
3761 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
3762 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
3764 int result
= ::RealizePalette(hdc
);
3766 // restore the palette (before releasing the DC)
3767 win
->m_palette
.SetHPALETTE((WXHPALETTE
)
3768 ::SelectPalette(hdc
, GetHpaletteOf(win
->m_palette
), FALSE
));
3769 ::RealizePalette(hdc
);
3770 ::ReleaseDC((HWND
) hWndPalChange
, hdc
);
3772 // now check for the need to redraw
3774 ::InvalidateRect((HWND
) hWndPalChange
, NULL
, TRUE
);
3778 #endif // wxUSE_PALETTE
3780 wxPaletteChangedEvent
event(GetId());
3781 event
.SetEventObject(this);
3782 event
.SetChangedWindow(wxFindWinFromHandle(hWndPalChange
));
3784 return GetEventHandler()->ProcessEvent(event
);
3787 bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture
)
3789 wxMouseCaptureChangedEvent
event(GetId(), wxFindWinFromHandle(hWndGainedCapture
));
3790 event
.SetEventObject(this);
3792 return GetEventHandler()->ProcessEvent(event
);
3795 bool wxWindowMSW::HandleQueryNewPalette()
3799 // check to see if we our our parents have a custom palette
3800 wxWindowMSW
*win
= this;
3801 while (!win
->HasCustomPalette() && win
->GetParent()) win
= win
->GetParent();
3802 if (win
->HasCustomPalette()) {
3803 /* realize the palette to see whether redrawing is needed */
3804 HDC hdc
= ::GetDC((HWND
) GetHWND());
3805 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
3806 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), FALSE
) );
3808 int result
= ::RealizePalette(hdc
);
3809 /* restore the palette (before releasing the DC) */
3810 win
->m_palette
.SetHPALETTE( (WXHPALETTE
)
3811 ::SelectPalette(hdc
, (HPALETTE
) win
->m_palette
.GetHPALETTE(), TRUE
) );
3812 ::RealizePalette(hdc
);
3813 ::ReleaseDC((HWND
) GetHWND(), hdc
);
3814 /* now check for the need to redraw */
3816 ::InvalidateRect((HWND
) GetHWND(), NULL
, TRUE
);
3818 #endif // wxUSE_PALETTE
3820 wxQueryNewPaletteEvent
event(GetId());
3821 event
.SetEventObject(this);
3823 return GetEventHandler()->ProcessEvent(event
) && event
.GetPaletteRealized();
3826 // Responds to colour changes: passes event on to children.
3827 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent
& WXUNUSED(event
))
3829 // the top level window also reset the standard colour map as it might have
3830 // changed (there is no need to do it for the non top level windows as we
3831 // only have to do it once)
3835 gs_hasStdCmap
= false;
3837 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
3840 // Only propagate to non-top-level windows because Windows already
3841 // sends this event to all top-level ones
3842 wxWindow
*win
= node
->GetData();
3843 if ( !win
->IsTopLevel() )
3845 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
3846 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
3847 // the standard controls
3848 ::SendMessage(GetHwndOf(win
), WM_SYSCOLORCHANGE
, 0, 0);
3851 node
= node
->GetNext();
3855 extern wxCOLORMAP
*wxGetStdColourMap()
3857 static COLORREF s_stdColours
[wxSTD_COL_MAX
];
3858 static wxCOLORMAP s_cmap
[wxSTD_COL_MAX
];
3860 if ( !gs_hasStdCmap
)
3862 static bool s_coloursInit
= false;
3864 if ( !s_coloursInit
)
3866 // When a bitmap is loaded, the RGB values can change (apparently
3867 // because Windows adjusts them to care for the old programs always
3868 // using 0xc0c0c0 while the transparent colour for the new Windows
3869 // versions is different). But we do this adjustment ourselves so
3870 // we want to avoid Windows' "help" and for this we need to have a
3871 // reference bitmap which can tell us what the RGB values change
3873 wxBitmap
stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
3874 if ( stdColourBitmap
.Ok() )
3876 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
3877 wxASSERT_MSG( stdColourBitmap
.GetWidth() == wxSTD_COL_MAX
,
3878 _T("forgot to update wxBITMAP_STD_COLOURS!") );
3881 memDC
.SelectObject(stdColourBitmap
);
3884 for ( size_t i
= 0; i
< WXSIZEOF(s_stdColours
); i
++ )
3886 memDC
.GetPixel(i
, 0, &colour
);
3887 s_stdColours
[i
] = wxColourToRGB(colour
);
3890 else // wxBITMAP_STD_COLOURS couldn't be loaded
3892 s_stdColours
[0] = RGB(000,000,000); // black
3893 s_stdColours
[1] = RGB(128,128,128); // dark grey
3894 s_stdColours
[2] = RGB(192,192,192); // light grey
3895 s_stdColours
[3] = RGB(255,255,255); // white
3896 //s_stdColours[4] = RGB(000,000,255); // blue
3897 //s_stdColours[5] = RGB(255,000,255); // magenta
3900 s_coloursInit
= true;
3903 gs_hasStdCmap
= true;
3905 // create the colour map
3906 #define INIT_CMAP_ENTRY(col) \
3907 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
3908 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
3910 INIT_CMAP_ENTRY(BTNTEXT
);
3911 INIT_CMAP_ENTRY(BTNSHADOW
);
3912 INIT_CMAP_ENTRY(BTNFACE
);
3913 INIT_CMAP_ENTRY(BTNHIGHLIGHT
);
3915 #undef INIT_CMAP_ENTRY
3921 // ---------------------------------------------------------------------------
3923 // ---------------------------------------------------------------------------
3925 bool wxWindowMSW::HandlePaint()
3927 HRGN hRegion
= ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
3929 wxLogLastError(wxT("CreateRectRgn"));
3930 if ( ::GetUpdateRgn(GetHwnd(), hRegion
, FALSE
) == ERROR
)
3931 wxLogLastError(wxT("GetUpdateRgn"));
3933 m_updateRegion
= wxRegion((WXHRGN
) hRegion
);
3935 wxPaintEvent
event(m_windowId
);
3936 event
.SetEventObject(this);
3938 bool processed
= GetEventHandler()->ProcessEvent(event
);
3940 // note that we must generate NC event after the normal one as otherwise
3941 // BeginPaint() will happily overwrite our decorations with the background
3943 wxNcPaintEvent
eventNc(m_windowId
);
3944 eventNc
.SetEventObject(this);
3945 GetEventHandler()->ProcessEvent(eventNc
);
3950 // Can be called from an application's OnPaint handler
3951 void wxWindowMSW::OnPaint(wxPaintEvent
& event
)
3953 #ifdef __WXUNIVERSAL__
3956 HDC hDC
= (HDC
) wxPaintDC::FindDCInCache((wxWindow
*) event
.GetEventObject());
3959 MSWDefWindowProc(WM_PAINT
, (WPARAM
) hDC
, 0);
3964 bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc
)
3969 dc
.SetWindow((wxWindow
*)this);
3972 wxEraseEvent
event(m_windowId
, &dc
);
3973 event
.SetEventObject(this);
3974 bool rc
= GetEventHandler()->ProcessEvent(event
);
3978 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
3979 dc
.SelectOldObjects(hdc
);
3984 void wxWindowMSW::OnEraseBackground(wxEraseEvent
& event
)
3986 // standard non top level controls (i.e. except the dialogs) always erase
3987 // their background themselves in HandleCtlColor() or have some control-
3988 // specific ways to set the colours (common controls)
3989 if ( IsOfStandardClass() && !IsTopLevel() )
3995 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM
)
3997 // don't skip the event here, custom background means that the app
3998 // is drawing it itself in its OnPaint(), so don't draw it at all
3999 // now to avoid flicker
4004 // do default background painting
4005 if ( !DoEraseBackground(GetHdcOf(*event
.GetDC())) )
4007 // let the system paint the background
4012 bool wxWindowMSW::DoEraseBackground(WXHDC hDC
)
4014 HBRUSH hbr
= (HBRUSH
)MSWGetBgBrush(hDC
);
4018 wxFillRect(GetHwnd(), (HDC
)hDC
, hbr
);
4024 wxWindowMSW::MSWGetBgBrushForChild(WXHDC
WXUNUSED(hDC
), WXHWND hWnd
)
4028 // our background colour applies to:
4029 // 1. this window itself, always
4030 // 2. all children unless the colour is "not inheritable"
4031 // 3. even if it is not inheritable, our immediate transparent
4032 // children should still inherit it -- but not any transparent
4033 // children because it would look wrong if a child of non
4034 // transparent child would show our bg colour when the child itself
4036 wxWindow
*win
= wxFindWinFromHandle(hWnd
);
4039 (win
&& win
->HasTransparentBackground() &&
4040 win
->GetParent() == this) )
4042 // draw children with the same colour as the parent
4044 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
4046 return (WXHBRUSH
)GetHbrushOf(*brush
);
4053 WXHBRUSH
wxWindowMSW::MSWGetBgBrush(WXHDC hDC
, WXHWND hWndToPaint
)
4056 hWndToPaint
= GetHWND();
4058 for ( wxWindowMSW
*win
= this; win
; win
= win
->GetParent() )
4060 WXHBRUSH hBrush
= win
->MSWGetBgBrushForChild(hDC
, hWndToPaint
);
4064 // background is not inherited beyond top level windows
4065 if ( win
->IsTopLevel() )
4072 bool wxWindowMSW::HandlePrintClient(WXHDC hDC
)
4074 // we receive this message when DrawThemeParentBackground() is
4075 // called from def window proc of several controls under XP and we
4076 // must draw properly themed background here
4078 // note that naively I'd expect filling the client rect with the
4079 // brush returned by MSWGetBgBrush() work -- but for some reason it
4080 // doesn't and we have to call parents MSWPrintChild() which is
4081 // supposed to call DrawThemeBackground() with appropriate params
4083 // also note that in this case lParam == PRF_CLIENT but we're
4084 // clearly expected to paint the background and nothing else!
4085 for ( wxWindow
*win
= GetParent(); win
; win
= win
->GetParent() )
4087 if ( win
->MSWPrintChild(hDC
, (wxWindow
*)this) )
4090 if ( win
->IsTopLevel() || win
->InheritsBackgroundColour() )
4097 // ---------------------------------------------------------------------------
4098 // moving and resizing
4099 // ---------------------------------------------------------------------------
4101 bool wxWindowMSW::HandleMinimize()
4103 wxIconizeEvent
event(m_windowId
);
4104 event
.SetEventObject(this);
4106 return GetEventHandler()->ProcessEvent(event
);
4109 bool wxWindowMSW::HandleMaximize()
4111 wxMaximizeEvent
event(m_windowId
);
4112 event
.SetEventObject(this);
4114 return GetEventHandler()->ProcessEvent(event
);
4117 bool wxWindowMSW::HandleMove(int x
, int y
)
4120 wxMoveEvent
event(point
, m_windowId
);
4121 event
.SetEventObject(this);
4123 return GetEventHandler()->ProcessEvent(event
);
4126 bool wxWindowMSW::HandleMoving(wxRect
& rect
)
4128 wxMoveEvent
event(rect
, m_windowId
);
4129 event
.SetEventObject(this);
4131 bool rc
= GetEventHandler()->ProcessEvent(event
);
4133 rect
= event
.GetRect();
4137 bool wxWindowMSW::HandleSize(int WXUNUSED(w
), int WXUNUSED(h
), WXUINT wParam
)
4139 // when we resize this window, its children are probably going to be
4140 // repositioned as well, prepare to use DeferWindowPos() for them
4141 const int numChildren
= GetChildren().GetCount();
4142 if ( numChildren
> 1 )
4144 m_hDWP
= (WXHANDLE
)::BeginDeferWindowPos(numChildren
);
4147 wxLogLastError(_T("BeginDeferWindowPos"));
4151 // update this window size
4152 bool processed
= false;
4156 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4157 // fall through nevertheless
4161 // we're not interested in these messages at all
4164 case SIZE_MINIMIZED
:
4165 processed
= HandleMinimize();
4168 case SIZE_MAXIMIZED
:
4169 /* processed = */ HandleMaximize();
4170 // fall through to send a normal size event as well
4173 // don't use w and h parameters as they specify the client size
4174 // while according to the docs EVT_SIZE handler is supposed to
4175 // receive the total size
4176 wxSizeEvent
event(GetSize(), m_windowId
);
4177 event
.SetEventObject(this);
4179 processed
= GetEventHandler()->ProcessEvent(event
);
4182 // and finally change the positions of all child windows at once
4185 // reset m_hDWP to NULL so that child windows don't try to use our
4186 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4187 // happen anyhow normally but who knows what weird flow of control we
4188 // may have depending on what the users EVT_SIZE handler does...)
4189 HDWP hDWP
= (HDWP
)m_hDWP
;
4192 // do put all child controls in place at once
4193 if ( !::EndDeferWindowPos(hDWP
) )
4195 wxLogLastError(_T("EndDeferWindowPos"));
4202 bool wxWindowMSW::HandleSizing(wxRect
& rect
)
4204 wxSizeEvent
event(rect
, m_windowId
);
4205 event
.SetEventObject(this);
4207 bool rc
= GetEventHandler()->ProcessEvent(event
);
4209 rect
= event
.GetRect();
4213 bool wxWindowMSW::HandleGetMinMaxInfo(void *mmInfo
)
4216 wxUnusedVar(mmInfo
);
4219 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
4223 int minWidth
= GetMinWidth(),
4224 minHeight
= GetMinHeight(),
4225 maxWidth
= GetMaxWidth(),
4226 maxHeight
= GetMaxHeight();
4228 if ( minWidth
!= wxDefaultCoord
)
4230 info
->ptMinTrackSize
.x
= minWidth
;
4234 if ( minHeight
!= wxDefaultCoord
)
4236 info
->ptMinTrackSize
.y
= minHeight
;
4240 if ( maxWidth
!= wxDefaultCoord
)
4242 info
->ptMaxTrackSize
.x
= maxWidth
;
4246 if ( maxHeight
!= wxDefaultCoord
)
4248 info
->ptMaxTrackSize
.y
= maxHeight
;
4256 // ---------------------------------------------------------------------------
4258 // ---------------------------------------------------------------------------
4260 bool wxWindowMSW::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
4262 #if wxUSE_MENUS_NATIVE
4263 if ( !cmd
&& wxCurrentPopupMenu
)
4265 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
4266 wxCurrentPopupMenu
= NULL
;
4268 return popupMenu
->MSWCommand(cmd
, id
);
4270 #endif // wxUSE_MENUS_NATIVE
4272 wxWindow
*win
= NULL
;
4274 // first try to find it from HWND - this works even with the broken
4275 // programs using the same ids for different controls
4278 win
= wxFindWinFromHandle(control
);
4284 // must cast to a signed type before comparing with other ids!
4285 win
= FindItem((signed short)id
);
4290 return win
->MSWCommand(cmd
, id
);
4293 // the messages sent from the in-place edit control used by the treectrl
4294 // for label editing have id == 0, but they should _not_ be treated as menu
4295 // messages (they are EN_XXX ones, in fact) so don't translate anything
4296 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4299 // If no child window, it may be an accelerator, e.g. for a popup menu
4302 wxCommandEvent
event(wxEVT_COMMAND_MENU_SELECTED
);
4303 event
.SetEventObject(this);
4307 return GetEventHandler()->ProcessEvent(event
);
4311 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
4312 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4313 // notifications to its parent which we want to reflect back to
4315 wxSpinCtrl
*spin
= wxSpinCtrl::GetSpinForTextCtrl(control
);
4316 if ( spin
&& spin
->ProcessTextCommand(cmd
, id
) )
4318 #endif // wxUSE_SPINCTRL
4320 #if wxUSE_CHOICE && defined(__SMARTPHONE__)
4321 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
4322 // notifications to its parent which we want to reflect back to
4324 wxChoice
*choice
= wxChoice::GetChoiceForListBox(control
);
4325 if ( choice
&& choice
->MSWCommand(cmd
, id
) )
4333 // ---------------------------------------------------------------------------
4335 // ---------------------------------------------------------------------------
4337 void wxWindowMSW::InitMouseEvent(wxMouseEvent
& event
,
4341 // our client coords are not quite the same as Windows ones
4342 wxPoint pt
= GetClientAreaOrigin();
4343 event
.m_x
= x
- pt
.x
;
4344 event
.m_y
= y
- pt
.y
;
4346 event
.m_shiftDown
= (flags
& MK_SHIFT
) != 0;
4347 event
.m_controlDown
= (flags
& MK_CONTROL
) != 0;
4348 event
.m_leftDown
= (flags
& MK_LBUTTON
) != 0;
4349 event
.m_middleDown
= (flags
& MK_MBUTTON
) != 0;
4350 event
.m_rightDown
= (flags
& MK_RBUTTON
) != 0;
4351 event
.m_altDown
= ::GetKeyState(VK_MENU
) < 0;
4354 event
.SetTimestamp(::GetMessageTime());
4357 event
.SetEventObject(this);
4358 event
.SetId(GetId());
4360 #if wxUSE_MOUSEEVENT_HACK
4363 m_lastMouseEvent
= event
.GetEventType();
4364 #endif // wxUSE_MOUSEEVENT_HACK
4367 // Windows doesn't send the mouse events to the static controls (which are
4368 // transparent in the sense that their WM_NCHITTEST handler returns
4369 // HTTRANSPARENT) at all but we want all controls to receive the mouse events
4370 // and so we manually check if we don't have a child window under mouse and if
4371 // we do, send the event to it instead of the window Windows had sent WM_XXX
4374 // Notice that this is not done for the mouse move events because this could
4375 // (would?) be too slow, but only for clicks which means that the static texts
4376 // still don't get move, enter nor leave events.
4377 static wxWindowMSW
*FindWindowForMouseEvent(wxWindowMSW
*win
, int *x
, int *y
) //TW:REQ:Univ
4379 wxCHECK_MSG( x
&& y
, win
, _T("NULL pointer in FindWindowForMouseEvent") );
4381 // first try to find a non transparent child: this allows us to send events
4382 // to a static text which is inside a static box, for example
4383 POINT pt
= { *x
, *y
};
4384 HWND hwnd
= GetHwndOf(win
),
4388 hwndUnderMouse
= ::ChildWindowFromPoint
4394 hwndUnderMouse
= ::ChildWindowFromPointEx
4404 if ( !hwndUnderMouse
|| hwndUnderMouse
== hwnd
)
4406 // now try any child window at all
4407 hwndUnderMouse
= ::ChildWindowFromPoint(hwnd
, pt
);
4410 // check that we have a child window which is susceptible to receive mouse
4411 // events: for this it must be shown and enabled
4412 if ( hwndUnderMouse
&&
4413 hwndUnderMouse
!= hwnd
&&
4414 ::IsWindowVisible(hwndUnderMouse
) &&
4415 ::IsWindowEnabled(hwndUnderMouse
) )
4417 wxWindow
*winUnderMouse
= wxFindWinFromHandle((WXHWND
)hwndUnderMouse
);
4418 if ( winUnderMouse
)
4420 // translate the mouse coords to the other window coords
4421 win
->ClientToScreen(x
, y
);
4422 winUnderMouse
->ScreenToClient(x
, y
);
4424 win
= winUnderMouse
;
4431 bool wxWindowMSW::HandleMouseEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4433 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4434 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
4435 // from the message id and take the value in the table to get wxWin event
4437 static const wxEventType eventsMouse
[] =
4451 wxMouseEvent
event(eventsMouse
[msg
- WM_MOUSEMOVE
]);
4452 InitMouseEvent(event
, x
, y
, flags
);
4454 return GetEventHandler()->ProcessEvent(event
);
4457 bool wxWindowMSW::HandleMouseMove(int x
, int y
, WXUINT flags
)
4459 if ( !m_mouseInWindow
)
4461 // it would be wrong to assume that just because we get a mouse move
4462 // event that the mouse is inside the window: although this is usually
4463 // true, it is not if we had captured the mouse, so we need to check
4464 // the mouse coordinates here
4465 if ( !HasCapture() || IsMouseInWindow() )
4467 // Generate an ENTER event
4468 m_mouseInWindow
= true;
4470 #ifdef HAVE_TRACKMOUSEEVENT
4471 WinStruct
<TRACKMOUSEEVENT
> trackinfo
;
4473 trackinfo
.dwFlags
= TME_LEAVE
;
4474 trackinfo
.hwndTrack
= GetHwnd();
4476 // Use the commctrl.h _TrackMouseEvent(), which will call the real
4477 // TrackMouseEvent() if available or emulate it
4478 _TrackMouseEvent(&trackinfo
);
4479 #endif // HAVE_TRACKMOUSEEVENT
4481 wxMouseEvent
event(wxEVT_ENTER_WINDOW
);
4482 InitMouseEvent(event
, x
, y
, flags
);
4484 (void)GetEventHandler()->ProcessEvent(event
);
4488 #if wxUSE_MOUSEEVENT_HACK
4489 // Window gets a click down message followed by a mouse move message even
4490 // if position isn't changed! We want to discard the trailing move event
4491 // if x and y are the same.
4492 if ( (m_lastMouseEvent
== wxEVT_RIGHT_DOWN
||
4493 m_lastMouseEvent
== wxEVT_LEFT_DOWN
||
4494 m_lastMouseEvent
== wxEVT_MIDDLE_DOWN
) &&
4495 (m_lastMouseX
== x
&& m_lastMouseY
== y
) )
4497 m_lastMouseEvent
= wxEVT_MOTION
;
4501 #endif // wxUSE_MOUSEEVENT_HACK
4503 return HandleMouseEvent(WM_MOUSEMOVE
, x
, y
, flags
);
4507 bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam
, WXLPARAM lParam
)
4509 #if wxUSE_MOUSEWHEEL
4510 wxMouseEvent
event(wxEVT_MOUSEWHEEL
);
4511 InitMouseEvent(event
,
4512 GET_X_LPARAM(lParam
),
4513 GET_Y_LPARAM(lParam
),
4515 event
.m_wheelRotation
= (short)HIWORD(wParam
);
4516 event
.m_wheelDelta
= WHEEL_DELTA
;
4518 static int s_linesPerRotation
= -1;
4519 if ( s_linesPerRotation
== -1 )
4521 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES
, 0,
4522 &s_linesPerRotation
, 0))
4524 // this is not supposed to happen
4525 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
4527 // the default is 3, so use it if SystemParametersInfo() failed
4528 s_linesPerRotation
= 3;
4532 event
.m_linesPerAction
= s_linesPerRotation
;
4533 return GetEventHandler()->ProcessEvent(event
);
4535 #else // !wxUSE_MOUSEWHEEL
4536 wxUnusedVar(wParam
);
4537 wxUnusedVar(lParam
);
4540 #endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
4543 void wxWindowMSW::GenerateMouseLeave()
4545 m_mouseInWindow
= false;
4548 if ( wxIsShiftDown() )
4550 if ( wxIsCtrlDown() )
4551 state
|= MK_CONTROL
;
4553 // Only the high-order bit should be tested
4554 if ( GetKeyState( VK_LBUTTON
) & (1<<15) )
4555 state
|= MK_LBUTTON
;
4556 if ( GetKeyState( VK_MBUTTON
) & (1<<15) )
4557 state
|= MK_MBUTTON
;
4558 if ( GetKeyState( VK_RBUTTON
) & (1<<15) )
4559 state
|= MK_RBUTTON
;
4563 if ( !::GetCursorPosWinCE(&pt
) )
4565 if ( !::GetCursorPos(&pt
) )
4568 wxLogLastError(_T("GetCursorPos"));
4571 // we need to have client coordinates here for symmetry with
4572 // wxEVT_ENTER_WINDOW
4573 RECT rect
= wxGetWindowRect(GetHwnd());
4577 wxMouseEvent
event(wxEVT_LEAVE_WINDOW
);
4578 InitMouseEvent(event
, pt
.x
, pt
.y
, state
);
4580 (void)GetEventHandler()->ProcessEvent(event
);
4583 // ---------------------------------------------------------------------------
4584 // keyboard handling
4585 // ---------------------------------------------------------------------------
4587 // create the key event of the given type for the given key - used by
4588 // HandleChar and HandleKeyDown/Up
4589 wxKeyEvent
wxWindowMSW::CreateKeyEvent(wxEventType evType
,
4592 WXWPARAM wParam
) const
4594 wxKeyEvent
event(evType
);
4595 event
.SetId(GetId());
4596 event
.m_shiftDown
= wxIsShiftDown();
4597 event
.m_controlDown
= wxIsCtrlDown();
4598 event
.m_altDown
= (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
;
4600 event
.SetEventObject((wxWindow
*)this); // const_cast
4601 event
.m_keyCode
= id
;
4603 event
.m_uniChar
= (wxChar
) wParam
;
4605 event
.m_rawCode
= (wxUint32
) wParam
;
4606 event
.m_rawFlags
= (wxUint32
) lParam
;
4608 event
.SetTimestamp(::GetMessageTime());
4611 // translate the position to client coords
4614 GetCursorPosWinCE(&pt
);
4619 GetWindowRect(GetHwnd(),&rect
);
4629 // isASCII is true only when we're called from WM_CHAR handler and not from
4631 bool wxWindowMSW::HandleChar(WXWPARAM wParam
, WXLPARAM lParam
, bool isASCII
)
4636 // If 1 -> 26, translate to either special keycode or just set
4637 // ctrlDown. IOW, Ctrl-C should result in keycode == 3 and
4638 // ControlDown() == true.
4640 if ( (id
> 0) && (id
< 27) )
4662 else // we're called from WM_KEYDOWN
4664 id
= wxCharCodeMSWToWX(wParam
, lParam
);
4667 // it's ASCII and will be processed here only when called from
4668 // WM_CHAR (i.e. when isASCII = true), don't process it now
4673 wxKeyEvent
event(CreateKeyEvent(wxEVT_CHAR
, id
, lParam
, wParam
));
4675 // the alphanumeric keys produced by pressing AltGr+something on European
4676 // keyboards have both Ctrl and Alt modifiers which may confuse the user
4677 // code as, normally, keys with Ctrl and/or Alt don't result in anything
4678 // alphanumeric, so pretend that there are no modifiers at all (the
4679 // KEY_DOWN event would still have the correct modifiers if they're really
4681 if ( event
.m_controlDown
&& event
.m_altDown
&&
4682 (id
>= 32 && id
< 256) )
4684 event
.m_controlDown
=
4685 event
.m_altDown
= false;
4688 return GetEventHandler()->ProcessEvent(event
);
4691 bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam
, WXLPARAM lParam
)
4693 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
4697 // normal ASCII char
4701 if ( id
!= -1 ) // VZ: does this ever happen (FIXME)?
4703 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_DOWN
, id
, lParam
, wParam
));
4704 if ( GetEventHandler()->ProcessEvent(event
) )
4713 bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam
, WXLPARAM lParam
)
4715 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
4719 // normal ASCII char
4723 if ( id
!= -1 ) // VZ: does this ever happen (FIXME)?
4725 wxKeyEvent
event(CreateKeyEvent(wxEVT_KEY_UP
, id
, lParam
, wParam
));
4726 if ( GetEventHandler()->ProcessEvent(event
) )
4733 int wxWindowMSW::HandleMenuChar(int chAccel
, WXLPARAM lParam
)
4735 // FIXME: implement GetMenuItemCount for WinCE, possibly
4736 // in terms of GetMenuItemInfo
4738 const HMENU hmenu
= (HMENU
)lParam
;
4742 mii
.cbSize
= sizeof(MENUITEMINFO
);
4743 mii
.fMask
= MIIM_TYPE
| MIIM_DATA
;
4745 // find if we have this letter in any owner drawn item
4746 const int count
= ::GetMenuItemCount(hmenu
);
4747 for ( int i
= 0; i
< count
; i
++ )
4749 if ( ::GetMenuItemInfo(hmenu
, i
, TRUE
, &mii
) )
4751 if ( mii
.fType
== MFT_OWNERDRAW
)
4753 // dwItemData member of the MENUITEMINFO is a
4754 // pointer to the associated wxMenuItem -- see the
4755 // menu creation code
4756 wxMenuItem
*item
= (wxMenuItem
*)mii
.dwItemData
;
4758 const wxChar
*p
= wxStrchr(item
->GetText(), _T('&'));
4761 if ( *p
== _T('&') )
4763 // this is not the accel char, find the real one
4764 p
= wxStrchr(p
+ 1, _T('&'));
4766 else // got the accel char
4768 // FIXME-UNICODE: this comparison doesn't risk to work
4769 // for non ASCII accelerator characters I'm afraid, but
4771 if ( (wchar_t)wxToupper(*p
) == (wchar_t)chAccel
)
4777 // this one doesn't match
4784 else // failed to get the menu text?
4786 // it's not fatal, so don't show error, but still log
4788 wxLogLastError(_T("GetMenuItemInfo"));
4792 wxUnusedVar(chAccel
);
4793 wxUnusedVar(lParam
);
4798 // ---------------------------------------------------------------------------
4800 // ---------------------------------------------------------------------------
4802 bool wxWindowMSW::HandleJoystickEvent(WXUINT msg
, int x
, int y
, WXUINT flags
)
4806 if ( flags
& JOY_BUTTON1CHG
)
4807 change
= wxJOY_BUTTON1
;
4808 if ( flags
& JOY_BUTTON2CHG
)
4809 change
= wxJOY_BUTTON2
;
4810 if ( flags
& JOY_BUTTON3CHG
)
4811 change
= wxJOY_BUTTON3
;
4812 if ( flags
& JOY_BUTTON4CHG
)
4813 change
= wxJOY_BUTTON4
;
4816 if ( flags
& JOY_BUTTON1
)
4817 buttons
|= wxJOY_BUTTON1
;
4818 if ( flags
& JOY_BUTTON2
)
4819 buttons
|= wxJOY_BUTTON2
;
4820 if ( flags
& JOY_BUTTON3
)
4821 buttons
|= wxJOY_BUTTON3
;
4822 if ( flags
& JOY_BUTTON4
)
4823 buttons
|= wxJOY_BUTTON4
;
4825 // the event ids aren't consecutive so we can't use table based lookup
4827 wxEventType eventType
;
4832 eventType
= wxEVT_JOY_MOVE
;
4837 eventType
= wxEVT_JOY_MOVE
;
4842 eventType
= wxEVT_JOY_ZMOVE
;
4847 eventType
= wxEVT_JOY_ZMOVE
;
4850 case MM_JOY1BUTTONDOWN
:
4852 eventType
= wxEVT_JOY_BUTTON_DOWN
;
4855 case MM_JOY2BUTTONDOWN
:
4857 eventType
= wxEVT_JOY_BUTTON_DOWN
;
4860 case MM_JOY1BUTTONUP
:
4862 eventType
= wxEVT_JOY_BUTTON_UP
;
4865 case MM_JOY2BUTTONUP
:
4867 eventType
= wxEVT_JOY_BUTTON_UP
;
4871 wxFAIL_MSG(wxT("no such joystick event"));
4876 wxJoystickEvent
event(eventType
, buttons
, joystick
, change
);
4877 event
.SetPosition(wxPoint(x
, y
));
4878 event
.SetEventObject(this);
4880 return GetEventHandler()->ProcessEvent(event
);
4890 // ---------------------------------------------------------------------------
4892 // ---------------------------------------------------------------------------
4894 bool wxWindowMSW::MSWOnScroll(int orientation
, WXWORD wParam
,
4895 WXWORD pos
, WXHWND control
)
4897 if ( control
&& control
!= m_hWnd
) // Prevent infinite recursion
4899 wxWindow
*child
= wxFindWinFromHandle(control
);
4901 return child
->MSWOnScroll(orientation
, wParam
, pos
, control
);
4904 wxScrollWinEvent event
;
4905 event
.SetPosition(pos
);
4906 event
.SetOrientation(orientation
);
4907 event
.SetEventObject(this);
4912 event
.SetEventType(wxEVT_SCROLLWIN_TOP
);
4916 event
.SetEventType(wxEVT_SCROLLWIN_BOTTOM
);
4920 event
.SetEventType(wxEVT_SCROLLWIN_LINEUP
);
4924 event
.SetEventType(wxEVT_SCROLLWIN_LINEDOWN
);
4928 event
.SetEventType(wxEVT_SCROLLWIN_PAGEUP
);
4932 event
.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN
);
4935 case SB_THUMBPOSITION
:
4937 // under Win32, the scrollbar range and position are 32 bit integers,
4938 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
4939 // explicitly query the scrollbar for the correct position (this must
4940 // be done only for these two SB_ events as they are the only one
4941 // carrying the scrollbar position)
4943 WinStruct
<SCROLLINFO
> scrollInfo
;
4944 scrollInfo
.fMask
= SIF_TRACKPOS
;
4946 if ( !::GetScrollInfo(GetHwnd(),
4947 orientation
== wxHORIZONTAL
? SB_HORZ
4951 // Not neccessarily an error, if there are no scrollbars yet.
4952 // wxLogLastError(_T("GetScrollInfo"));
4955 event
.SetPosition(scrollInfo
.nTrackPos
);
4958 event
.SetEventType( wParam
== SB_THUMBPOSITION
4959 ? wxEVT_SCROLLWIN_THUMBRELEASE
4960 : wxEVT_SCROLLWIN_THUMBTRACK
);
4967 return GetEventHandler()->ProcessEvent(event
);
4970 // ===========================================================================
4972 // ===========================================================================
4974 void wxGetCharSize(WXHWND wnd
, int *x
, int *y
, const wxFont
& the_font
)
4977 HDC dc
= ::GetDC((HWND
) wnd
);
4980 // the_font.UseResource();
4981 // the_font.RealizeResource();
4982 HFONT fnt
= (HFONT
)the_font
.GetResourceHandle(); // const_cast
4984 was
= (HFONT
) SelectObject(dc
,fnt
);
4986 GetTextMetrics(dc
, &tm
);
4989 SelectObject(dc
,was
);
4991 ReleaseDC((HWND
)wnd
, dc
);
4994 *x
= tm
.tmAveCharWidth
;
4996 *y
= tm
.tmHeight
+ tm
.tmExternalLeading
;
4998 // the_font.ReleaseResource();
5001 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
5002 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
5003 int wxCharCodeMSWToWX(int keySym
, WXLPARAM lParam
)
5008 case VK_CANCEL
: id
= WXK_CANCEL
; break;
5009 case VK_BACK
: id
= WXK_BACK
; break;
5010 case VK_TAB
: id
= WXK_TAB
; break;
5011 case VK_CLEAR
: id
= WXK_CLEAR
; break;
5012 case VK_SHIFT
: id
= WXK_SHIFT
; break;
5013 case VK_CONTROL
: id
= WXK_CONTROL
; break;
5014 case VK_MENU
: id
= WXK_ALT
; break;
5015 case VK_PAUSE
: id
= WXK_PAUSE
; break;
5016 case VK_CAPITAL
: id
= WXK_CAPITAL
; break;
5017 case VK_SPACE
: id
= WXK_SPACE
; break;
5018 case VK_ESCAPE
: id
= WXK_ESCAPE
; break;
5019 case VK_PRIOR
: id
= WXK_PRIOR
; break;
5020 case VK_NEXT
: id
= WXK_NEXT
; break;
5021 case VK_END
: id
= WXK_END
; break;
5022 case VK_HOME
: id
= WXK_HOME
; break;
5023 case VK_LEFT
: id
= WXK_LEFT
; break;
5024 case VK_UP
: id
= WXK_UP
; break;
5025 case VK_RIGHT
: id
= WXK_RIGHT
; break;
5026 case VK_DOWN
: id
= WXK_DOWN
; break;
5027 case VK_SELECT
: id
= WXK_SELECT
; break;
5028 case VK_PRINT
: id
= WXK_PRINT
; break;
5029 case VK_EXECUTE
: id
= WXK_EXECUTE
; break;
5030 case VK_INSERT
: id
= WXK_INSERT
; break;
5031 case VK_DELETE
: id
= WXK_DELETE
; break;
5032 case VK_HELP
: id
= WXK_HELP
; break;
5033 case VK_NUMPAD0
: id
= WXK_NUMPAD0
; break;
5034 case VK_NUMPAD1
: id
= WXK_NUMPAD1
; break;
5035 case VK_NUMPAD2
: id
= WXK_NUMPAD2
; break;
5036 case VK_NUMPAD3
: id
= WXK_NUMPAD3
; break;
5037 case VK_NUMPAD4
: id
= WXK_NUMPAD4
; break;
5038 case VK_NUMPAD5
: id
= WXK_NUMPAD5
; break;
5039 case VK_NUMPAD6
: id
= WXK_NUMPAD6
; break;
5040 case VK_NUMPAD7
: id
= WXK_NUMPAD7
; break;
5041 case VK_NUMPAD8
: id
= WXK_NUMPAD8
; break;
5042 case VK_NUMPAD9
: id
= WXK_NUMPAD9
; break;
5043 case VK_MULTIPLY
: id
= WXK_NUMPAD_MULTIPLY
; break;
5044 case VK_ADD
: id
= WXK_NUMPAD_ADD
; break;
5045 case VK_SUBTRACT
: id
= WXK_NUMPAD_SUBTRACT
; break;
5046 case VK_DECIMAL
: id
= WXK_NUMPAD_DECIMAL
; break;
5047 case VK_DIVIDE
: id
= WXK_NUMPAD_DIVIDE
; break;
5048 case VK_F1
: id
= WXK_F1
; break;
5049 case VK_F2
: id
= WXK_F2
; break;
5050 case VK_F3
: id
= WXK_F3
; break;
5051 case VK_F4
: id
= WXK_F4
; break;
5052 case VK_F5
: id
= WXK_F5
; break;
5053 case VK_F6
: id
= WXK_F6
; break;
5054 case VK_F7
: id
= WXK_F7
; break;
5055 case VK_F8
: id
= WXK_F8
; break;
5056 case VK_F9
: id
= WXK_F9
; break;
5057 case VK_F10
: id
= WXK_F10
; break;
5058 case VK_F11
: id
= WXK_F11
; break;
5059 case VK_F12
: id
= WXK_F12
; break;
5060 case VK_F13
: id
= WXK_F13
; break;
5061 case VK_F14
: id
= WXK_F14
; break;
5062 case VK_F15
: id
= WXK_F15
; break;
5063 case VK_F16
: id
= WXK_F16
; break;
5064 case VK_F17
: id
= WXK_F17
; break;
5065 case VK_F18
: id
= WXK_F18
; break;
5066 case VK_F19
: id
= WXK_F19
; break;
5067 case VK_F20
: id
= WXK_F20
; break;
5068 case VK_F21
: id
= WXK_F21
; break;
5069 case VK_F22
: id
= WXK_F22
; break;
5070 case VK_F23
: id
= WXK_F23
; break;
5071 case VK_F24
: id
= WXK_F24
; break;
5072 case VK_NUMLOCK
: id
= WXK_NUMLOCK
; break;
5073 case VK_SCROLL
: id
= WXK_SCROLL
; break;
5075 // the mapping for these keys may be incorrect on non-US keyboards so
5076 // maybe we shouldn't map them to ASCII values at all
5077 case VK_OEM_1
: id
= ';'; break;
5078 case VK_OEM_PLUS
: id
= '+'; break;
5079 case VK_OEM_COMMA
: id
= ','; break;
5080 case VK_OEM_MINUS
: id
= '-'; break;
5081 case VK_OEM_PERIOD
: id
= '.'; break;
5082 case VK_OEM_2
: id
= '/'; break;
5083 case VK_OEM_3
: id
= '~'; break;
5084 case VK_OEM_4
: id
= '['; break;
5085 case VK_OEM_5
: id
= '\\'; break;
5086 case VK_OEM_6
: id
= ']'; break;
5087 case VK_OEM_7
: id
= '\''; break;
5090 case VK_LWIN
: id
= WXK_WINDOWS_LEFT
; break;
5091 case VK_RWIN
: id
= WXK_WINDOWS_RIGHT
; break;
5092 case VK_APPS
: id
= WXK_WINDOWS_MENU
; break;
5093 #endif // VK_APPS defined
5096 // the same key is sent for both the "return" key on the main
5097 // keyboard and the numeric keypad but we want to distinguish
5098 // between them: we do this using the "extended" bit (24) of lParam
5099 id
= lParam
& (1 << 24) ? WXK_NUMPAD_ENTER
: WXK_RETURN
;
5109 WXWORD
wxCharCodeWXToMSW(int id
, bool *isVirtual
)
5115 case WXK_CANCEL
: keySym
= VK_CANCEL
; break;
5116 case WXK_CLEAR
: keySym
= VK_CLEAR
; break;
5117 case WXK_SHIFT
: keySym
= VK_SHIFT
; break;
5118 case WXK_CONTROL
: keySym
= VK_CONTROL
; break;
5119 case WXK_ALT
: keySym
= VK_MENU
; break;
5120 case WXK_PAUSE
: keySym
= VK_PAUSE
; break;
5121 case WXK_CAPITAL
: keySym
= VK_CAPITAL
; break;
5122 case WXK_PRIOR
: keySym
= VK_PRIOR
; break;
5123 case WXK_NEXT
: keySym
= VK_NEXT
; break;
5124 case WXK_END
: keySym
= VK_END
; break;
5125 case WXK_HOME
: keySym
= VK_HOME
; break;
5126 case WXK_LEFT
: keySym
= VK_LEFT
; break;
5127 case WXK_UP
: keySym
= VK_UP
; break;
5128 case WXK_RIGHT
: keySym
= VK_RIGHT
; break;
5129 case WXK_DOWN
: keySym
= VK_DOWN
; break;
5130 case WXK_SELECT
: keySym
= VK_SELECT
; break;
5131 case WXK_PRINT
: keySym
= VK_PRINT
; break;
5132 case WXK_EXECUTE
: keySym
= VK_EXECUTE
; break;
5133 case WXK_INSERT
: keySym
= VK_INSERT
; break;
5134 case WXK_DELETE
: keySym
= VK_DELETE
; break;
5135 case WXK_HELP
: keySym
= VK_HELP
; break;
5136 case WXK_NUMPAD0
: keySym
= VK_NUMPAD0
; break;
5137 case WXK_NUMPAD1
: keySym
= VK_NUMPAD1
; break;
5138 case WXK_NUMPAD2
: keySym
= VK_NUMPAD2
; break;
5139 case WXK_NUMPAD3
: keySym
= VK_NUMPAD3
; break;
5140 case WXK_NUMPAD4
: keySym
= VK_NUMPAD4
; break;
5141 case WXK_NUMPAD5
: keySym
= VK_NUMPAD5
; break;
5142 case WXK_NUMPAD6
: keySym
= VK_NUMPAD6
; break;
5143 case WXK_NUMPAD7
: keySym
= VK_NUMPAD7
; break;
5144 case WXK_NUMPAD8
: keySym
= VK_NUMPAD8
; break;
5145 case WXK_NUMPAD9
: keySym
= VK_NUMPAD9
; break;
5146 case WXK_NUMPAD_MULTIPLY
: keySym
= VK_MULTIPLY
; break;
5147 case WXK_NUMPAD_ADD
: keySym
= VK_ADD
; break;
5148 case WXK_NUMPAD_SUBTRACT
: keySym
= VK_SUBTRACT
; break;
5149 case WXK_NUMPAD_DECIMAL
: keySym
= VK_DECIMAL
; break;
5150 case WXK_NUMPAD_DIVIDE
: keySym
= VK_DIVIDE
; break;
5151 case WXK_F1
: keySym
= VK_F1
; break;
5152 case WXK_F2
: keySym
= VK_F2
; break;
5153 case WXK_F3
: keySym
= VK_F3
; break;
5154 case WXK_F4
: keySym
= VK_F4
; break;
5155 case WXK_F5
: keySym
= VK_F5
; break;
5156 case WXK_F6
: keySym
= VK_F6
; break;
5157 case WXK_F7
: keySym
= VK_F7
; break;
5158 case WXK_F8
: keySym
= VK_F8
; break;
5159 case WXK_F9
: keySym
= VK_F9
; break;
5160 case WXK_F10
: keySym
= VK_F10
; break;
5161 case WXK_F11
: keySym
= VK_F11
; break;
5162 case WXK_F12
: keySym
= VK_F12
; break;
5163 case WXK_F13
: keySym
= VK_F13
; break;
5164 case WXK_F14
: keySym
= VK_F14
; break;
5165 case WXK_F15
: keySym
= VK_F15
; break;
5166 case WXK_F16
: keySym
= VK_F16
; break;
5167 case WXK_F17
: keySym
= VK_F17
; break;
5168 case WXK_F18
: keySym
= VK_F18
; break;
5169 case WXK_F19
: keySym
= VK_F19
; break;
5170 case WXK_F20
: keySym
= VK_F20
; break;
5171 case WXK_F21
: keySym
= VK_F21
; break;
5172 case WXK_F22
: keySym
= VK_F22
; break;
5173 case WXK_F23
: keySym
= VK_F23
; break;
5174 case WXK_F24
: keySym
= VK_F24
; break;
5175 case WXK_NUMLOCK
: keySym
= VK_NUMLOCK
; break;
5176 case WXK_SCROLL
: keySym
= VK_SCROLL
; break;
5187 bool wxGetKeyState(wxKeyCode key
)
5191 wxASSERT_MSG(key
!= WXK_LBUTTON
&& key
!= WXK_RBUTTON
&& key
!=
5192 WXK_MBUTTON
, wxT("can't use wxGetKeyState() for mouse buttons"));
5194 //High order with GetAsyncKeyState only available on WIN32
5196 //If the requested key is a LED key, return
5197 //true if the led is pressed
5198 if (key
== WXK_NUMLOCK
||
5199 key
== WXK_CAPITAL
||
5203 //low order bit means LED is highlighted,
5204 //high order means key is down
5205 //Here, for compat with other ports we want both
5206 return GetKeyState( wxCharCodeWXToMSW(key
, &bVirtual
) ) != 0;
5213 //low order bit means key pressed since last call
5214 //high order means key is down
5215 //We want only the high order bit - the key may not be down if only low order
5216 return ( GetAsyncKeyState( wxCharCodeWXToMSW(key
, &bVirtual
) ) & (1<<15) ) != 0;
5221 wxWindow
*wxGetActiveWindow()
5223 HWND hWnd
= GetActiveWindow();
5226 return wxFindWinFromHandle((WXHWND
) hWnd
);
5231 extern wxWindow
*wxGetWindowFromHWND(WXHWND hWnd
)
5233 HWND hwnd
= (HWND
)hWnd
;
5235 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
5236 // by code in msw/radiobox.cpp), for all the others we just search up the
5238 wxWindow
*win
= (wxWindow
*)NULL
;
5241 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5245 // native radiobuttons return DLGC_RADIOBUTTON here and for any
5246 // wxWindow class which overrides WM_GETDLGCODE processing to
5247 // do it as well, win would be already non NULL
5248 if ( ::SendMessage(hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_RADIOBUTTON
)
5250 win
= (wxWindow
*)wxGetWindowUserData(hwnd
);
5252 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
5253 #endif // wxUSE_RADIOBOX
5255 // spin control text buddy window should be mapped to spin ctrl
5256 // itself so try it too
5257 #if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
5260 win
= wxSpinCtrl::GetSpinForTextCtrl((WXHWND
)hwnd
);
5262 #endif // wxUSE_SPINCTRL
5266 while ( hwnd
&& !win
)
5268 // this is a really ugly hack needed to avoid mistakenly returning the
5269 // parent frame wxWindow for the find/replace modeless dialog HWND -
5270 // this, in turn, is needed to call IsDialogMessage() from
5271 // wxApp::ProcessMessage() as for this we must return NULL from here
5273 // FIXME: this is clearly not the best way to do it but I think we'll
5274 // need to change HWND <-> wxWindow code more heavily than I can
5275 // do it now to fix it
5276 #ifndef __WXMICROWIN__
5277 if ( ::GetWindow(hwnd
, GW_OWNER
) )
5279 // it's a dialog box, don't go upwards
5284 hwnd
= ::GetParent(hwnd
);
5285 win
= wxFindWinFromHandle((WXHWND
)hwnd
);
5291 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
5293 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
5294 // in active frames and dialogs, regardless of where the focus is.
5295 static HHOOK wxTheKeyboardHook
= 0;
5296 static FARPROC wxTheKeyboardHookProc
= 0;
5297 int APIENTRY _EXPORT
5298 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
);
5300 void wxSetKeyboardHook(bool doIt
)
5304 wxTheKeyboardHookProc
= MakeProcInstance((FARPROC
) wxKeyboardHook
, wxGetInstance());
5305 wxTheKeyboardHook
= SetWindowsHookEx(WH_KEYBOARD
, (HOOKPROC
) wxTheKeyboardHookProc
, wxGetInstance(),
5307 GetCurrentThreadId()
5308 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
5313 UnhookWindowsHookEx(wxTheKeyboardHook
);
5317 int APIENTRY _EXPORT
5318 wxKeyboardHook(int nCode
, WORD wParam
, DWORD lParam
)
5320 DWORD hiWord
= HIWORD(lParam
);
5321 if ( nCode
!= HC_NOREMOVE
&& ((hiWord
& KF_UP
) == 0) )
5323 int id
= wxCharCodeMSWToWX(wParam
, lParam
);
5326 wxKeyEvent
event(wxEVT_CHAR_HOOK
);
5327 if ( (HIWORD(lParam
) & KF_ALTDOWN
) == KF_ALTDOWN
)
5328 event
.m_altDown
= true;
5330 event
.SetEventObject(NULL
);
5331 event
.m_keyCode
= id
;
5332 event
.m_shiftDown
= wxIsShiftDown();
5333 event
.m_controlDown
= wxIsCtrlDown();
5335 event
.SetTimestamp(::GetMessageTime());
5337 wxWindow
*win
= wxGetActiveWindow();
5338 wxEvtHandler
*handler
;
5341 handler
= win
->GetEventHandler();
5342 event
.SetId(win
->GetId());
5347 event
.SetId(wxID_ANY
);
5350 if ( handler
&& handler
->ProcessEvent(event
) )
5358 return (int)CallNextHookEx(wxTheKeyboardHook
, nCode
, wParam
, lParam
);
5361 #endif // !__WXMICROWIN__
5364 const char *wxGetMessageName(int message
)
5368 case 0x0000: return "WM_NULL";
5369 case 0x0001: return "WM_CREATE";
5370 case 0x0002: return "WM_DESTROY";
5371 case 0x0003: return "WM_MOVE";
5372 case 0x0005: return "WM_SIZE";
5373 case 0x0006: return "WM_ACTIVATE";
5374 case 0x0007: return "WM_SETFOCUS";
5375 case 0x0008: return "WM_KILLFOCUS";
5376 case 0x000A: return "WM_ENABLE";
5377 case 0x000B: return "WM_SETREDRAW";
5378 case 0x000C: return "WM_SETTEXT";
5379 case 0x000D: return "WM_GETTEXT";
5380 case 0x000E: return "WM_GETTEXTLENGTH";
5381 case 0x000F: return "WM_PAINT";
5382 case 0x0010: return "WM_CLOSE";
5383 case 0x0011: return "WM_QUERYENDSESSION";
5384 case 0x0012: return "WM_QUIT";
5385 case 0x0013: return "WM_QUERYOPEN";
5386 case 0x0014: return "WM_ERASEBKGND";
5387 case 0x0015: return "WM_SYSCOLORCHANGE";
5388 case 0x0016: return "WM_ENDSESSION";
5389 case 0x0017: return "WM_SYSTEMERROR";
5390 case 0x0018: return "WM_SHOWWINDOW";
5391 case 0x0019: return "WM_CTLCOLOR";
5392 case 0x001A: return "WM_WININICHANGE";
5393 case 0x001B: return "WM_DEVMODECHANGE";
5394 case 0x001C: return "WM_ACTIVATEAPP";
5395 case 0x001D: return "WM_FONTCHANGE";
5396 case 0x001E: return "WM_TIMECHANGE";
5397 case 0x001F: return "WM_CANCELMODE";
5398 case 0x0020: return "WM_SETCURSOR";
5399 case 0x0021: return "WM_MOUSEACTIVATE";
5400 case 0x0022: return "WM_CHILDACTIVATE";
5401 case 0x0023: return "WM_QUEUESYNC";
5402 case 0x0024: return "WM_GETMINMAXINFO";
5403 case 0x0026: return "WM_PAINTICON";
5404 case 0x0027: return "WM_ICONERASEBKGND";
5405 case 0x0028: return "WM_NEXTDLGCTL";
5406 case 0x002A: return "WM_SPOOLERSTATUS";
5407 case 0x002B: return "WM_DRAWITEM";
5408 case 0x002C: return "WM_MEASUREITEM";
5409 case 0x002D: return "WM_DELETEITEM";
5410 case 0x002E: return "WM_VKEYTOITEM";
5411 case 0x002F: return "WM_CHARTOITEM";
5412 case 0x0030: return "WM_SETFONT";
5413 case 0x0031: return "WM_GETFONT";
5414 case 0x0037: return "WM_QUERYDRAGICON";
5415 case 0x0039: return "WM_COMPAREITEM";
5416 case 0x0041: return "WM_COMPACTING";
5417 case 0x0044: return "WM_COMMNOTIFY";
5418 case 0x0046: return "WM_WINDOWPOSCHANGING";
5419 case 0x0047: return "WM_WINDOWPOSCHANGED";
5420 case 0x0048: return "WM_POWER";
5422 case 0x004A: return "WM_COPYDATA";
5423 case 0x004B: return "WM_CANCELJOURNAL";
5424 case 0x004E: return "WM_NOTIFY";
5425 case 0x0050: return "WM_INPUTLANGCHANGEREQUEST";
5426 case 0x0051: return "WM_INPUTLANGCHANGE";
5427 case 0x0052: return "WM_TCARD";
5428 case 0x0053: return "WM_HELP";
5429 case 0x0054: return "WM_USERCHANGED";
5430 case 0x0055: return "WM_NOTIFYFORMAT";
5431 case 0x007B: return "WM_CONTEXTMENU";
5432 case 0x007C: return "WM_STYLECHANGING";
5433 case 0x007D: return "WM_STYLECHANGED";
5434 case 0x007E: return "WM_DISPLAYCHANGE";
5435 case 0x007F: return "WM_GETICON";
5436 case 0x0080: return "WM_SETICON";
5438 case 0x0081: return "WM_NCCREATE";
5439 case 0x0082: return "WM_NCDESTROY";
5440 case 0x0083: return "WM_NCCALCSIZE";
5441 case 0x0084: return "WM_NCHITTEST";
5442 case 0x0085: return "WM_NCPAINT";
5443 case 0x0086: return "WM_NCACTIVATE";
5444 case 0x0087: return "WM_GETDLGCODE";
5445 case 0x00A0: return "WM_NCMOUSEMOVE";
5446 case 0x00A1: return "WM_NCLBUTTONDOWN";
5447 case 0x00A2: return "WM_NCLBUTTONUP";
5448 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
5449 case 0x00A4: return "WM_NCRBUTTONDOWN";
5450 case 0x00A5: return "WM_NCRBUTTONUP";
5451 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
5452 case 0x00A7: return "WM_NCMBUTTONDOWN";
5453 case 0x00A8: return "WM_NCMBUTTONUP";
5454 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
5455 case 0x0100: return "WM_KEYDOWN";
5456 case 0x0101: return "WM_KEYUP";
5457 case 0x0102: return "WM_CHAR";
5458 case 0x0103: return "WM_DEADCHAR";
5459 case 0x0104: return "WM_SYSKEYDOWN";
5460 case 0x0105: return "WM_SYSKEYUP";
5461 case 0x0106: return "WM_SYSCHAR";
5462 case 0x0107: return "WM_SYSDEADCHAR";
5463 case 0x0108: return "WM_KEYLAST";
5465 case 0x010D: return "WM_IME_STARTCOMPOSITION";
5466 case 0x010E: return "WM_IME_ENDCOMPOSITION";
5467 case 0x010F: return "WM_IME_COMPOSITION";
5469 case 0x0110: return "WM_INITDIALOG";
5470 case 0x0111: return "WM_COMMAND";
5471 case 0x0112: return "WM_SYSCOMMAND";
5472 case 0x0113: return "WM_TIMER";
5473 case 0x0114: return "WM_HSCROLL";
5474 case 0x0115: return "WM_VSCROLL";
5475 case 0x0116: return "WM_INITMENU";
5476 case 0x0117: return "WM_INITMENUPOPUP";
5477 case 0x011F: return "WM_MENUSELECT";
5478 case 0x0120: return "WM_MENUCHAR";
5479 case 0x0121: return "WM_ENTERIDLE";
5480 case 0x0200: return "WM_MOUSEMOVE";
5481 case 0x0201: return "WM_LBUTTONDOWN";
5482 case 0x0202: return "WM_LBUTTONUP";
5483 case 0x0203: return "WM_LBUTTONDBLCLK";
5484 case 0x0204: return "WM_RBUTTONDOWN";
5485 case 0x0205: return "WM_RBUTTONUP";
5486 case 0x0206: return "WM_RBUTTONDBLCLK";
5487 case 0x0207: return "WM_MBUTTONDOWN";
5488 case 0x0208: return "WM_MBUTTONUP";
5489 case 0x0209: return "WM_MBUTTONDBLCLK";
5490 case 0x020A: return "WM_MOUSEWHEEL";
5491 case 0x0210: return "WM_PARENTNOTIFY";
5492 case 0x0211: return "WM_ENTERMENULOOP";
5493 case 0x0212: return "WM_EXITMENULOOP";
5495 case 0x0213: return "WM_NEXTMENU";
5496 case 0x0214: return "WM_SIZING";
5497 case 0x0215: return "WM_CAPTURECHANGED";
5498 case 0x0216: return "WM_MOVING";
5499 case 0x0218: return "WM_POWERBROADCAST";
5500 case 0x0219: return "WM_DEVICECHANGE";
5502 case 0x0220: return "WM_MDICREATE";
5503 case 0x0221: return "WM_MDIDESTROY";
5504 case 0x0222: return "WM_MDIACTIVATE";
5505 case 0x0223: return "WM_MDIRESTORE";
5506 case 0x0224: return "WM_MDINEXT";
5507 case 0x0225: return "WM_MDIMAXIMIZE";
5508 case 0x0226: return "WM_MDITILE";
5509 case 0x0227: return "WM_MDICASCADE";
5510 case 0x0228: return "WM_MDIICONARRANGE";
5511 case 0x0229: return "WM_MDIGETACTIVE";
5512 case 0x0230: return "WM_MDISETMENU";
5513 case 0x0233: return "WM_DROPFILES";
5515 case 0x0281: return "WM_IME_SETCONTEXT";
5516 case 0x0282: return "WM_IME_NOTIFY";
5517 case 0x0283: return "WM_IME_CONTROL";
5518 case 0x0284: return "WM_IME_COMPOSITIONFULL";
5519 case 0x0285: return "WM_IME_SELECT";
5520 case 0x0286: return "WM_IME_CHAR";
5521 case 0x0290: return "WM_IME_KEYDOWN";
5522 case 0x0291: return "WM_IME_KEYUP";
5524 case 0x0300: return "WM_CUT";
5525 case 0x0301: return "WM_COPY";
5526 case 0x0302: return "WM_PASTE";
5527 case 0x0303: return "WM_CLEAR";
5528 case 0x0304: return "WM_UNDO";
5529 case 0x0305: return "WM_RENDERFORMAT";
5530 case 0x0306: return "WM_RENDERALLFORMATS";
5531 case 0x0307: return "WM_DESTROYCLIPBOARD";
5532 case 0x0308: return "WM_DRAWCLIPBOARD";
5533 case 0x0309: return "WM_PAINTCLIPBOARD";
5534 case 0x030A: return "WM_VSCROLLCLIPBOARD";
5535 case 0x030B: return "WM_SIZECLIPBOARD";
5536 case 0x030C: return "WM_ASKCBFORMATNAME";
5537 case 0x030D: return "WM_CHANGECBCHAIN";
5538 case 0x030E: return "WM_HSCROLLCLIPBOARD";
5539 case 0x030F: return "WM_QUERYNEWPALETTE";
5540 case 0x0310: return "WM_PALETTEISCHANGING";
5541 case 0x0311: return "WM_PALETTECHANGED";
5543 case 0x0312: return "WM_HOTKEY";
5546 // common controls messages - although they're not strictly speaking
5547 // standard, it's nice to decode them nevertheless
5550 case 0x1000 + 0: return "LVM_GETBKCOLOR";
5551 case 0x1000 + 1: return "LVM_SETBKCOLOR";
5552 case 0x1000 + 2: return "LVM_GETIMAGELIST";
5553 case 0x1000 + 3: return "LVM_SETIMAGELIST";
5554 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
5555 case 0x1000 + 5: return "LVM_GETITEMA";
5556 case 0x1000 + 75: return "LVM_GETITEMW";
5557 case 0x1000 + 6: return "LVM_SETITEMA";
5558 case 0x1000 + 76: return "LVM_SETITEMW";
5559 case 0x1000 + 7: return "LVM_INSERTITEMA";
5560 case 0x1000 + 77: return "LVM_INSERTITEMW";
5561 case 0x1000 + 8: return "LVM_DELETEITEM";
5562 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
5563 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
5564 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
5565 case 0x1000 + 12: return "LVM_GETNEXTITEM";
5566 case 0x1000 + 13: return "LVM_FINDITEMA";
5567 case 0x1000 + 83: return "LVM_FINDITEMW";
5568 case 0x1000 + 14: return "LVM_GETITEMRECT";
5569 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
5570 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
5571 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
5572 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
5573 case 0x1000 + 18: return "LVM_HITTEST";
5574 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
5575 case 0x1000 + 20: return "LVM_SCROLL";
5576 case 0x1000 + 21: return "LVM_REDRAWITEMS";
5577 case 0x1000 + 22: return "LVM_ARRANGE";
5578 case 0x1000 + 23: return "LVM_EDITLABELA";
5579 case 0x1000 + 118: return "LVM_EDITLABELW";
5580 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
5581 case 0x1000 + 25: return "LVM_GETCOLUMNA";
5582 case 0x1000 + 95: return "LVM_GETCOLUMNW";
5583 case 0x1000 + 26: return "LVM_SETCOLUMNA";
5584 case 0x1000 + 96: return "LVM_SETCOLUMNW";
5585 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
5586 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
5587 case 0x1000 + 28: return "LVM_DELETECOLUMN";
5588 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
5589 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
5590 case 0x1000 + 31: return "LVM_GETHEADER";
5591 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
5592 case 0x1000 + 34: return "LVM_GETVIEWRECT";
5593 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
5594 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
5595 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
5596 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
5597 case 0x1000 + 39: return "LVM_GETTOPINDEX";
5598 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
5599 case 0x1000 + 41: return "LVM_GETORIGIN";
5600 case 0x1000 + 42: return "LVM_UPDATE";
5601 case 0x1000 + 43: return "LVM_SETITEMSTATE";
5602 case 0x1000 + 44: return "LVM_GETITEMSTATE";
5603 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
5604 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
5605 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
5606 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
5607 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
5608 case 0x1000 + 48: return "LVM_SORTITEMS";
5609 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
5610 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
5611 case 0x1000 + 51: return "LVM_GETITEMSPACING";
5612 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
5613 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
5614 case 0x1000 + 53: return "LVM_SETICONSPACING";
5615 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
5616 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
5617 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
5618 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
5619 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
5620 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
5621 case 0x1000 + 60: return "LVM_SETHOTITEM";
5622 case 0x1000 + 61: return "LVM_GETHOTITEM";
5623 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
5624 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
5625 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
5626 case 0x1000 + 65: return "LVM_SETWORKAREA";
5629 case 0x1100 + 0: return "TVM_INSERTITEMA";
5630 case 0x1100 + 50: return "TVM_INSERTITEMW";
5631 case 0x1100 + 1: return "TVM_DELETEITEM";
5632 case 0x1100 + 2: return "TVM_EXPAND";
5633 case 0x1100 + 4: return "TVM_GETITEMRECT";
5634 case 0x1100 + 5: return "TVM_GETCOUNT";
5635 case 0x1100 + 6: return "TVM_GETINDENT";
5636 case 0x1100 + 7: return "TVM_SETINDENT";
5637 case 0x1100 + 8: return "TVM_GETIMAGELIST";
5638 case 0x1100 + 9: return "TVM_SETIMAGELIST";
5639 case 0x1100 + 10: return "TVM_GETNEXTITEM";
5640 case 0x1100 + 11: return "TVM_SELECTITEM";
5641 case 0x1100 + 12: return "TVM_GETITEMA";
5642 case 0x1100 + 62: return "TVM_GETITEMW";
5643 case 0x1100 + 13: return "TVM_SETITEMA";
5644 case 0x1100 + 63: return "TVM_SETITEMW";
5645 case 0x1100 + 14: return "TVM_EDITLABELA";
5646 case 0x1100 + 65: return "TVM_EDITLABELW";
5647 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
5648 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
5649 case 0x1100 + 17: return "TVM_HITTEST";
5650 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
5651 case 0x1100 + 19: return "TVM_SORTCHILDREN";
5652 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
5653 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
5654 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
5655 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
5656 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
5657 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
5658 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
5661 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
5662 case 0x1200 + 1: return "HDM_INSERTITEMA";
5663 case 0x1200 + 10: return "HDM_INSERTITEMW";
5664 case 0x1200 + 2: return "HDM_DELETEITEM";
5665 case 0x1200 + 3: return "HDM_GETITEMA";
5666 case 0x1200 + 11: return "HDM_GETITEMW";
5667 case 0x1200 + 4: return "HDM_SETITEMA";
5668 case 0x1200 + 12: return "HDM_SETITEMW";
5669 case 0x1200 + 5: return "HDM_LAYOUT";
5670 case 0x1200 + 6: return "HDM_HITTEST";
5671 case 0x1200 + 7: return "HDM_GETITEMRECT";
5672 case 0x1200 + 8: return "HDM_SETIMAGELIST";
5673 case 0x1200 + 9: return "HDM_GETIMAGELIST";
5674 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
5675 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
5676 case 0x1200 + 17: return "HDM_GETORDERARRAY";
5677 case 0x1200 + 18: return "HDM_SETORDERARRAY";
5678 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
5681 case 0x1300 + 2: return "TCM_GETIMAGELIST";
5682 case 0x1300 + 3: return "TCM_SETIMAGELIST";
5683 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
5684 case 0x1300 + 5: return "TCM_GETITEMA";
5685 case 0x1300 + 60: return "TCM_GETITEMW";
5686 case 0x1300 + 6: return "TCM_SETITEMA";
5687 case 0x1300 + 61: return "TCM_SETITEMW";
5688 case 0x1300 + 7: return "TCM_INSERTITEMA";
5689 case 0x1300 + 62: return "TCM_INSERTITEMW";
5690 case 0x1300 + 8: return "TCM_DELETEITEM";
5691 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
5692 case 0x1300 + 10: return "TCM_GETITEMRECT";
5693 case 0x1300 + 11: return "TCM_GETCURSEL";
5694 case 0x1300 + 12: return "TCM_SETCURSEL";
5695 case 0x1300 + 13: return "TCM_HITTEST";
5696 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
5697 case 0x1300 + 40: return "TCM_ADJUSTRECT";
5698 case 0x1300 + 41: return "TCM_SETITEMSIZE";
5699 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
5700 case 0x1300 + 43: return "TCM_SETPADDING";
5701 case 0x1300 + 44: return "TCM_GETROWCOUNT";
5702 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
5703 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
5704 case 0x1300 + 47: return "TCM_GETCURFOCUS";
5705 case 0x1300 + 48: return "TCM_SETCURFOCUS";
5706 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
5707 case 0x1300 + 50: return "TCM_DESELECTALL";
5710 case WM_USER
+1: return "TB_ENABLEBUTTON";
5711 case WM_USER
+2: return "TB_CHECKBUTTON";
5712 case WM_USER
+3: return "TB_PRESSBUTTON";
5713 case WM_USER
+4: return "TB_HIDEBUTTON";
5714 case WM_USER
+5: return "TB_INDETERMINATE";
5715 case WM_USER
+9: return "TB_ISBUTTONENABLED";
5716 case WM_USER
+10: return "TB_ISBUTTONCHECKED";
5717 case WM_USER
+11: return "TB_ISBUTTONPRESSED";
5718 case WM_USER
+12: return "TB_ISBUTTONHIDDEN";
5719 case WM_USER
+13: return "TB_ISBUTTONINDETERMINATE";
5720 case WM_USER
+17: return "TB_SETSTATE";
5721 case WM_USER
+18: return "TB_GETSTATE";
5722 case WM_USER
+19: return "TB_ADDBITMAP";
5723 case WM_USER
+20: return "TB_ADDBUTTONS";
5724 case WM_USER
+21: return "TB_INSERTBUTTON";
5725 case WM_USER
+22: return "TB_DELETEBUTTON";
5726 case WM_USER
+23: return "TB_GETBUTTON";
5727 case WM_USER
+24: return "TB_BUTTONCOUNT";
5728 case WM_USER
+25: return "TB_COMMANDTOINDEX";
5729 case WM_USER
+26: return "TB_SAVERESTOREA";
5730 case WM_USER
+76: return "TB_SAVERESTOREW";
5731 case WM_USER
+27: return "TB_CUSTOMIZE";
5732 case WM_USER
+28: return "TB_ADDSTRINGA";
5733 case WM_USER
+77: return "TB_ADDSTRINGW";
5734 case WM_USER
+29: return "TB_GETITEMRECT";
5735 case WM_USER
+30: return "TB_BUTTONSTRUCTSIZE";
5736 case WM_USER
+31: return "TB_SETBUTTONSIZE";
5737 case WM_USER
+32: return "TB_SETBITMAPSIZE";
5738 case WM_USER
+33: return "TB_AUTOSIZE";
5739 case WM_USER
+35: return "TB_GETTOOLTIPS";
5740 case WM_USER
+36: return "TB_SETTOOLTIPS";
5741 case WM_USER
+37: return "TB_SETPARENT";
5742 case WM_USER
+39: return "TB_SETROWS";
5743 case WM_USER
+40: return "TB_GETROWS";
5744 case WM_USER
+42: return "TB_SETCMDID";
5745 case WM_USER
+43: return "TB_CHANGEBITMAP";
5746 case WM_USER
+44: return "TB_GETBITMAP";
5747 case WM_USER
+45: return "TB_GETBUTTONTEXTA";
5748 case WM_USER
+75: return "TB_GETBUTTONTEXTW";
5749 case WM_USER
+46: return "TB_REPLACEBITMAP";
5750 case WM_USER
+47: return "TB_SETINDENT";
5751 case WM_USER
+48: return "TB_SETIMAGELIST";
5752 case WM_USER
+49: return "TB_GETIMAGELIST";
5753 case WM_USER
+50: return "TB_LOADIMAGES";
5754 case WM_USER
+51: return "TB_GETRECT";
5755 case WM_USER
+52: return "TB_SETHOTIMAGELIST";
5756 case WM_USER
+53: return "TB_GETHOTIMAGELIST";
5757 case WM_USER
+54: return "TB_SETDISABLEDIMAGELIST";
5758 case WM_USER
+55: return "TB_GETDISABLEDIMAGELIST";
5759 case WM_USER
+56: return "TB_SETSTYLE";
5760 case WM_USER
+57: return "TB_GETSTYLE";
5761 case WM_USER
+58: return "TB_GETBUTTONSIZE";
5762 case WM_USER
+59: return "TB_SETBUTTONWIDTH";
5763 case WM_USER
+60: return "TB_SETMAXTEXTROWS";
5764 case WM_USER
+61: return "TB_GETTEXTROWS";
5765 case WM_USER
+41: return "TB_GETBITMAPFLAGS";
5768 static char s_szBuf
[128];
5769 sprintf(s_szBuf
, "<unknown message = %d>", message
);
5773 #endif //__WXDEBUG__
5775 static TEXTMETRIC
wxGetTextMetrics(const wxWindowMSW
*win
)
5779 HWND hwnd
= GetHwndOf(win
);
5780 HDC hdc
= ::GetDC(hwnd
);
5782 #if !wxDIALOG_UNIT_COMPATIBILITY
5783 // and select the current font into it
5784 HFONT hfont
= GetHfontOf(win
->GetFont());
5787 hfont
= (HFONT
)::SelectObject(hdc
, hfont
);
5791 // finally retrieve the text metrics from it
5792 GetTextMetrics(hdc
, &tm
);
5794 #if !wxDIALOG_UNIT_COMPATIBILITY
5798 (void)::SelectObject(hdc
, hfont
);
5802 ::ReleaseDC(hwnd
, hdc
);
5807 // Find the wxWindow at the current mouse position, returning the mouse
5809 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
5811 pt
= wxGetMousePosition();
5812 return wxFindWindowAtPoint(pt
);
5815 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
5820 HWND hWndHit
= ::WindowFromPoint(pt2
);
5822 wxWindow
* win
= wxFindWinFromHandle((WXHWND
) hWndHit
) ;
5823 HWND hWnd
= hWndHit
;
5825 // Try to find a window with a wxWindow associated with it
5826 while (!win
&& (hWnd
!= 0))
5828 hWnd
= ::GetParent(hWnd
);
5829 win
= wxFindWinFromHandle((WXHWND
) hWnd
) ;
5834 // Get the current mouse position.
5835 wxPoint
wxGetMousePosition()
5839 GetCursorPosWinCE(&pt
);
5841 GetCursorPos( & pt
);
5844 return wxPoint(pt
.x
, pt
.y
);
5849 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
5850 static void WinCEUnregisterHotKey(int modifiers
, int id
)
5852 // Register hotkeys for the hardware buttons
5854 typedef BOOL (WINAPI
*UnregisterFunc1Proc
)(UINT
, UINT
);
5856 UnregisterFunc1Proc procUnregisterFunc
;
5857 hCoreDll
= LoadLibrary(_T("coredll.dll"));
5860 procUnregisterFunc
= (UnregisterFunc1Proc
)GetProcAddress(hCoreDll
, _T("UnregisterFunc1"));
5861 if (procUnregisterFunc
)
5862 procUnregisterFunc(modifiers
, id
);
5863 FreeLibrary(hCoreDll
);
5868 bool wxWindowMSW::RegisterHotKey(int hotkeyId
, int modifiers
, int keycode
)
5870 UINT win_modifiers
=0;
5871 if ( modifiers
& wxMOD_ALT
)
5872 win_modifiers
|= MOD_ALT
;
5873 if ( modifiers
& wxMOD_SHIFT
)
5874 win_modifiers
|= MOD_SHIFT
;
5875 if ( modifiers
& wxMOD_CONTROL
)
5876 win_modifiers
|= MOD_CONTROL
;
5877 if ( modifiers
& wxMOD_WIN
)
5878 win_modifiers
|= MOD_WIN
;
5880 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
5881 // Required for PPC and Smartphone hardware buttons
5882 if (keycode
>= WXK_SPECIAL1
&& keycode
<= WXK_SPECIAL20
)
5883 WinCEUnregisterHotKey(win_modifiers
, hotkeyId
);
5886 if ( !::RegisterHotKey(GetHwnd(), hotkeyId
, win_modifiers
, keycode
) )
5888 wxLogLastError(_T("RegisterHotKey"));
5896 bool wxWindowMSW::UnregisterHotKey(int hotkeyId
)
5898 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
5899 WinCEUnregisterHotKey(MOD_WIN
, hotkeyId
);
5902 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId
) )
5904 wxLogLastError(_T("UnregisterHotKey"));
5914 bool wxWindowMSW::HandleHotKey(WXWPARAM wParam
, WXLPARAM lParam
)
5916 int hotkeyId
= wParam
;
5917 int virtualKey
= HIWORD(lParam
);
5918 int win_modifiers
= LOWORD(lParam
);
5920 wxKeyEvent
event(CreateKeyEvent(wxEVT_HOTKEY
, virtualKey
, wParam
, lParam
));
5921 event
.SetId(hotkeyId
);
5922 event
.m_shiftDown
= (win_modifiers
& MOD_SHIFT
) != 0;
5923 event
.m_controlDown
= (win_modifiers
& MOD_CONTROL
) != 0;
5924 event
.m_altDown
= (win_modifiers
& MOD_ALT
) != 0;
5925 event
.m_metaDown
= (win_modifiers
& MOD_WIN
) != 0;
5927 return GetEventHandler()->ProcessEvent(event
);
5930 #endif // wxUSE_ACCEL
5932 #endif // wxUSE_HOTKEY
5934 // Not tested under WinCE
5937 // this class installs a message hook which really wakes up our idle processing
5938 // each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
5939 // sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
5940 // being dragged or even inside ::MessageBox()) and so don't control message
5941 // dispatching otherwise
5942 class wxIdleWakeUpModule
: public wxModule
5945 virtual bool OnInit()
5947 ms_hMsgHookProc
= ::SetWindowsHookEx
5950 &wxIdleWakeUpModule::MsgHookProc
,
5952 GetCurrentThreadId()
5955 if ( !ms_hMsgHookProc
)
5957 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
5965 virtual void OnExit()
5967 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc
);
5970 static LRESULT CALLBACK
MsgHookProc(int nCode
, WPARAM wParam
, LPARAM lParam
)
5972 MSG
*msg
= (MSG
*)lParam
;
5974 // only process the message if it is actually going to be removed from
5975 // the message queue, this prevents that the same event from being
5976 // processed multiple times if now someone just called PeekMessage()
5977 if ( msg
->message
== WM_NULL
&& wParam
== PM_REMOVE
)
5979 wxTheApp
->ProcessPendingEvents();
5982 return CallNextHookEx(ms_hMsgHookProc
, nCode
, wParam
, lParam
);
5986 static HHOOK ms_hMsgHookProc
;
5988 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule
)
5991 HHOOK
wxIdleWakeUpModule::ms_hMsgHookProc
= 0;
5993 IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule
, wxModule
)
5995 #endif // __WXWINCE__
6000 static void wxAdjustZOrder(wxWindow
* parent
)
6002 if (parent
->IsKindOf(CLASSINFO(wxStaticBox
)))
6004 // Set the z-order correctly
6005 SetWindowPos((HWND
) parent
->GetHWND(), HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
6008 wxWindowList::compatibility_iterator current
= parent
->GetChildren().GetFirst();
6011 wxWindow
*childWin
= current
->GetData();
6012 wxAdjustZOrder(childWin
);
6013 current
= current
->GetNext();
6018 // We need to adjust the z-order of static boxes in WinCE, to
6019 // make 'contained' controls visible
6020 void wxWindowMSW::OnInitDialog( wxInitDialogEvent
& event
)
6023 wxAdjustZOrder(this);