]> git.saurik.com Git - wxWidgets.git/blame - src/msw/window.cpp
fixed incorrectly inversed test for parent [not] being deleted (patch 1624472)
[wxWidgets.git] / src / msw / window.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
faa49bfd
WS
2// Name: src/msw/window.cpp
3// Purpose: wxWindowMSW
2bda0e17 4// Author: Julian Smart
a23fd0e1 5// Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation
2bda0e17
KB
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
a23fd0e1
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
09914df7 24 #pragma hdrstop
2bda0e17
KB
25#endif
26
e4db172a
WS
27#include "wx/window.h"
28
2bda0e17 29#ifndef WX_PRECOMP
9ed0d735 30 #include "wx/msw/wrapwin.h"
57bd4c60
WS
31 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
32 #include "wx/msw/missing.h"
0c589ad0 33 #include "wx/accel.h"
3a19e16d
VZ
34 #include "wx/menu.h"
35 #include "wx/dc.h"
36 #include "wx/dcclient.h"
8e92ccef 37 #include "wx/dcmemory.h"
3a19e16d
VZ
38 #include "wx/utils.h"
39 #include "wx/app.h"
3a19e16d
VZ
40 #include "wx/layout.h"
41 #include "wx/dialog.h"
42 #include "wx/frame.h"
43 #include "wx/listbox.h"
44 #include "wx/button.h"
3a19e16d 45 #include "wx/msgdlg.h"
1f3943e0 46 #include "wx/settings.h"
8d753488 47 #include "wx/statbox.h"
1e2aa2f8 48 #include "wx/sizer.h"
88a7a4e1 49 #include "wx/intl.h"
e4db172a 50 #include "wx/log.h"
fec9cc08 51 #include "wx/textctrl.h"
25466131 52 #include "wx/menuitem.h"
02761f6c 53 #include "wx/module.h"
2bda0e17
KB
54#endif
55
61fef19b 56#if wxUSE_OWNER_DRAWN && !defined(__WXUNIVERSAL__)
09914df7 57 #include "wx/ownerdrw.h"
2bda0e17
KB
58#endif
59
a3dc1da9 60#include "wx/evtloop.h"
355debca 61#include "wx/power.h"
c6430ed0 62#include "wx/sysopt.h"
d79df32c 63
9e2896e5
VZ
64#if wxUSE_DRAG_AND_DROP
65 #include "wx/dnd.h"
2bda0e17
KB
66#endif
67
ed5317e5
JS
68#if wxUSE_ACCESSIBILITY
69 #include "wx/access.h"
bef8d481 70 #include <ole2.h>
ed5317e5
JS
71 #include <oleacc.h>
72 #ifndef WM_GETOBJECT
73 #define WM_GETOBJECT 0x003D
74 #endif
75 #ifndef OBJID_CLIENT
76 #define OBJID_CLIENT 0xFFFFFFFC
77 #endif
78#endif
79
0c589ad0
BM
80#include "wx/msw/private.h"
81
750b78ba 82#if wxUSE_TOOLTIPS
42e69d6b 83 #include "wx/tooltip.h"
750b78ba
JS
84#endif
85
789295bf
VZ
86#if wxUSE_CARET
87 #include "wx/caret.h"
88#endif // wxUSE_CARET
89
6fe19057
VZ
90#if wxUSE_SPINCTRL
91 #include "wx/spinctrl.h"
92#endif // wxUSE_SPINCTRL
93
d9317fd4 94#include "wx/notebook.h"
5c6c3176 95#include "wx/listctrl.h"
aafb9978 96#include "wx/dynlib.h"
2a47d3c1 97
2bda0e17
KB
98#include <string.h>
99
d61c1a6f 100#if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__) /* && !defined(__WXWINCE__) */ ) || defined(__CYGWIN10__)
3a19e16d
VZ
101 #include <shellapi.h>
102 #include <mmsystem.h>
2bda0e17
KB
103#endif
104
105#ifdef __WIN32__
3a19e16d 106 #include <windowsx.h>
2bda0e17
KB
107#endif
108
dcfd4ac4 109#if !defined __WXWINCE__ && !defined NEED_PBT_H
dbc74bcc
WS
110 #include <pbt.h>
111#endif
2bda0e17 112
7f0586ef 113#if defined(__WXWINCE__)
4e5c6c33 114 #include "wx/msw/wince/missing.h"
7d4f65e3
JS
115#ifdef __POCKETPC__
116 #include <windows.h>
117 #include <shellapi.h>
118 #include <ole2.h>
119 #include <aygshell.h>
120#endif
7f0586ef
JS
121#endif
122
aafb9978 123#if defined(TME_LEAVE) && defined(WM_MOUSELEAVE) && wxUSE_DYNLIB_CLASS
4e5c6c33
VZ
124 #define HAVE_TRACKMOUSEEVENT
125#endif // everything needed for TrackMouseEvent()
126
7d86a2d4
VZ
127// if this is set to 1, we use deferred window sizing to reduce flicker when
128// resizing complicated window hierarchies, but this can in theory result in
129// different behaviour than the old code so we keep the possibility to use it
130// by setting this to 0 (in the future this should be removed completely)
f2197644
JS
131#ifdef __WXWINCE__
132#define USE_DEFERRED_SIZING 0
133#else
8e44f3ca 134#define USE_DEFERRED_SIZING 1
f2197644 135#endif
8e44f3ca 136
c358ea41
VZ
137// set this to 1 to filter out duplicate mouse events, e.g. mouse move events
138// when mouse position didnd't change
139#ifdef __WXWINCE__
140 #define wxUSE_MOUSEEVENT_HACK 0
141#else
142 #define wxUSE_MOUSEEVENT_HACK 1
143#endif
144
a23fd0e1 145// ---------------------------------------------------------------------------
42e69d6b 146// global variables
a23fd0e1 147// ---------------------------------------------------------------------------
47cbd6da 148
1e6feb95 149#if wxUSE_MENUS_NATIVE
2bda0e17 150wxMenu *wxCurrentPopupMenu = NULL;
1e6feb95
VZ
151#endif // wxUSE_MENUS_NATIVE
152
46fa338b
RR
153#ifdef __WXWINCE__
154extern wxChar *wxCanvasClassName;
155#else
2ffa221c 156extern const wxChar *wxCanvasClassName;
46fa338b 157#endif
42e69d6b 158
90c1530a
VZ
159// true if we had already created the std colour map, used by
160// wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
08158721 161static bool gs_hasStdCmap = false;
90c1530a 162
c358ea41
VZ
163// last mouse event information we need to filter out the duplicates
164#if wxUSE_MOUSEEVENT_HACK
2b053ae9 165static struct MouseEventInfoDummy
c358ea41
VZ
166{
167 // mouse position (in screen coordinates)
168 wxPoint pos;
169
170 // last mouse event type
171 wxEventType type;
172} gs_lastMouseEvent;
173#endif // wxUSE_MOUSEEVENT_HACK
174
42e69d6b
VZ
175// ---------------------------------------------------------------------------
176// private functions
177// ---------------------------------------------------------------------------
178
179// the window proc for all our windows
3135f4a7 180LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
42e69d6b 181 WPARAM wParam, LPARAM lParam);
577baeef 182
42e69d6b
VZ
183
184#ifdef __WXDEBUG__
4a712ba3 185 const wxChar *wxGetMessageName(int message);
42e69d6b 186#endif //__WXDEBUG__
2bda0e17 187
1e6feb95 188void wxRemoveHandleAssociation(wxWindowMSW *win);
cc972ac6 189extern void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win);
2bda0e17
KB
190wxWindow *wxFindWinFromHandle(WXHWND hWnd);
191
f6bcfd97 192// get the text metrics for the current font
1e6feb95
VZ
193static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win);
194
42b1fb63 195#ifdef __WXWINCE__
dfafa702 196// find the window for the mouse event at the specified position
42b1fb63
VZ
197static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y);
198#endif // __WXWINCE__
dfafa702 199
c48926e1 200// wrapper around BringWindowToTop() API
44d5b352 201static inline void wxBringWindowToTop(HWND hwnd)
c48926e1
VZ
202{
203#ifdef __WXMICROWIN__
204 // It seems that MicroWindows brings the _parent_ of the window to the top,
205 // which can be the wrong one.
206
207 // activate (set focus to) specified window
208 ::SetFocus(hwnd);
313901f3 209#endif
c48926e1
VZ
210
211 // raise top level parent to top of z order
313901f3 212 if (!::SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE))
c48926e1 213 {
313901f3 214 wxLogLastError(_T("SetWindowPos"));
c48926e1 215 }
c48926e1 216}
f6bcfd97 217
e0c5c96f
VZ
218#ifndef __WXWINCE__
219
ee471817
VZ
220// ensure that all our parent windows have WS_EX_CONTROLPARENT style
221static void EnsureParentHasControlParentStyle(wxWindow *parent)
222{
223 /*
224 If we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
225 parent as well as otherwise several Win32 functions using
226 GetNextDlgTabItem() to iterate over all controls such as
227 IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
228 all of them iterate over all the controls starting from the currently
229 focused one and stop iterating when they get back to the focus but
230 unless all parents have WS_EX_CONTROLPARENT bit set, they would never
231 get back to the initial (focused) window: as we do have this style,
232 GetNextDlgTabItem() will leave this window and continue in its parent,
233 but if the parent doesn't have it, it wouldn't recurse inside it later
90e572f1 234 on and so wouldn't have a chance of getting back to this window either.
ee471817 235 */
ee471817
VZ
236 while ( parent && !parent->IsTopLevel() )
237 {
238 LONG exStyle = ::GetWindowLong(GetHwndOf(parent), GWL_EXSTYLE);
239 if ( !(exStyle & WS_EX_CONTROLPARENT) )
240 {
241 // force the parent to have this style
242 ::SetWindowLong(GetHwndOf(parent), GWL_EXSTYLE,
243 exStyle | WS_EX_CONTROLPARENT);
244 }
245
246 parent = parent->GetParent();
247 }
ee471817
VZ
248}
249
e0c5c96f
VZ
250#endif // !__WXWINCE__
251
f2325516
JS
252#ifdef __WXWINCE__
253// On Windows CE, GetCursorPos can return an error, so use this function
254// instead
255bool GetCursorPosWinCE(POINT* pt)
256{
7d30268c
JS
257 if (!GetCursorPos(pt))
258 {
259 DWORD pos = GetMessagePos();
260 pt->x = LOWORD(pos);
261 pt->y = HIWORD(pos);
262 }
f2325516
JS
263 return true;
264}
265#endif
266
a23fd0e1
VZ
267// ---------------------------------------------------------------------------
268// event tables
269// ---------------------------------------------------------------------------
270
1e6feb95
VZ
271// in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
272// method
273#ifdef __WXUNIVERSAL__
274 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW, wxWindowBase)
275#else // __WXMSW__
51596bcb 276#if wxUSE_EXTENDED_RTTI
6a89f9ee 277
f3291a82
SC
278// windows that are created from a parent window during its Create method, eg. spin controls in a calendar controls
279// must never been streamed out separately otherwise chaos occurs. Right now easiest is to test for negative ids, as
280// windows with negative ids never can be recreated anyway
281
282bool wxWindowStreamingCallback( const wxObject *object, wxWriter * , wxPersister * , wxxVariantArray & )
283{
284 const wxWindow * win = dynamic_cast<const wxWindow*>(object) ;
285 if ( win && win->GetId() < 0 )
286 return false ;
287 return true ;
288}
289
290IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxWindow, wxWindowBase,"wx/window.h", wxWindowStreamingCallback)
51596bcb 291
6a89f9ee
SC
292// make wxWindowList known before the property is used
293
321239b6 294wxCOLLECTION_TYPE_INFO( wxWindow* , wxWindowList ) ;
6a89f9ee
SC
295
296template<> void wxCollectionToVariantArray( wxWindowList const &theList, wxxVariantArray &value)
297{
0c6b0084 298 wxListCollectionToVariantArray<wxWindowList::compatibility_iterator>( theList , value ) ;
6a89f9ee
SC
299}
300
bc9fb572
JS
301WX_DEFINE_FLAGS( wxWindowStyle )
302
321239b6 303wxBEGIN_FLAGS( wxWindowStyle )
bc9fb572
JS
304 // new style border flags, we put them first to
305 // use them for streaming out
5c6c3176 306
321239b6
SC
307 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
308 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
309 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
310 wxFLAGS_MEMBER(wxBORDER_RAISED)
311 wxFLAGS_MEMBER(wxBORDER_STATIC)
312 wxFLAGS_MEMBER(wxBORDER_NONE)
35bbb0c6 313
bc9fb572 314 // old style border flags
321239b6
SC
315 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
316 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
317 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
318 wxFLAGS_MEMBER(wxRAISED_BORDER)
319 wxFLAGS_MEMBER(wxSTATIC_BORDER)
cb0afb26 320 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
321
322 // standard window styles
321239b6
SC
323 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
324 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
325 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
326 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 327 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
321239b6
SC
328 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
329 wxFLAGS_MEMBER(wxVSCROLL)
330 wxFLAGS_MEMBER(wxHSCROLL)
331
332wxEND_FLAGS( wxWindowStyle )
333
334wxBEGIN_PROPERTIES_TABLE(wxWindow)
3a3c8603
DS
335 wxEVENT_PROPERTY( Close , wxEVT_CLOSE_WINDOW , wxCloseEvent)
336 wxEVENT_PROPERTY( Create , wxEVT_CREATE , wxWindowCreateEvent )
337 wxEVENT_PROPERTY( Destroy , wxEVT_DESTROY , wxWindowDestroyEvent )
51741307
SC
338 // Always constructor Properties first
339
af498247 340 wxREADONLY_PROPERTY( Parent,wxWindow*, GetParent, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
fb7e28db 341 wxPROPERTY( Id,wxWindowID, SetId, GetId, -1 /*wxID_ANY*/ , 0 /*flags*/ , wxT("Helpstring") , wxT("group") )
abb74e0f
WS
342 wxPROPERTY( Position,wxPoint, SetPosition , GetPosition, wxDefaultPosition , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // pos
343 wxPROPERTY( Size,wxSize, SetSize, GetSize, wxDefaultSize , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // size
af498247 344 wxPROPERTY( WindowStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
51741307
SC
345
346 // Then all relations of the object graph
347
321239b6 348 wxREADONLY_PROPERTY_COLLECTION( Children , wxWindowList , wxWindowBase* , GetWindowChildren , wxPROP_OBJECT_GRAPH /*flags*/ , wxT("Helpstring") , wxT("group"))
51741307
SC
349
350 // and finally all other properties
351
3a3c8603
DS
352 wxPROPERTY( ExtraStyle , long , SetExtraStyle , GetExtraStyle , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // extstyle
353 wxPROPERTY( BackgroundColour , wxColour , SetBackgroundColour , GetBackgroundColour , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // bg
354 wxPROPERTY( ForegroundColour , wxColour , SetForegroundColour , GetForegroundColour , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // fg
355 wxPROPERTY( Enabled , bool , Enable , IsEnabled , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
356 wxPROPERTY( Shown , bool , Show , IsShown , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
51741307
SC
357#if 0
358 // possible property candidates (not in xrc) or not valid in all subclasses
8b5d5223 359 wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxEmptyString )
3a3c8603 360 wxPROPERTY( Font , wxFont , SetFont , GetWindowFont , )
8b5d5223 361 wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxEmptyString )
3a3c8603
DS
362 // MaxHeight, Width , MinHeight , Width
363 // TODO switch label to control and title to toplevels
6a89f9ee 364
3a3c8603
DS
365 wxPROPERTY( ThemeEnabled , bool , SetThemeEnabled , GetThemeEnabled , )
366 //wxPROPERTY( Cursor , wxCursor , SetCursor , GetCursor , )
367 // wxPROPERTY( ToolTip , wxString , SetToolTip , GetToolTipText , )
368 wxPROPERTY( AutoLayout , bool , SetAutoLayout , GetAutoLayout , )
6a89f9ee
SC
369
370
371
51741307 372#endif
321239b6 373wxEND_PROPERTIES_TABLE()
51596bcb 374
321239b6
SC
375wxBEGIN_HANDLERS_TABLE(wxWindow)
376wxEND_HANDLERS_TABLE()
51596bcb 377
321239b6 378wxCONSTRUCTOR_DUMMY(wxWindow)
6a89f9ee 379
51596bcb 380#else
1e6feb95 381 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
51596bcb 382#endif
1e6feb95
VZ
383#endif // __WXUNIVERSAL__/__WXMSW__
384
385BEGIN_EVENT_TABLE(wxWindowMSW, wxWindowBase)
1e6feb95 386 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged)
8681b094 387 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground)
79099b80 388#ifdef __WXWINCE__
1e6feb95 389 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog)
79099b80 390#endif
2bda0e17
KB
391END_EVENT_TABLE()
392
a23fd0e1
VZ
393// ===========================================================================
394// implementation
395// ===========================================================================
396
42e69d6b
VZ
397// ---------------------------------------------------------------------------
398// wxWindow utility functions
399// ---------------------------------------------------------------------------
400
2bda0e17 401// Find an item given the MS Windows id
1e6feb95 402wxWindow *wxWindowMSW::FindItem(long id) const
2bda0e17 403{
1e6feb95 404#if wxUSE_CONTROLS
f7637829 405 wxControl *item = wxDynamicCastThis(wxControl);
f048e32f
VZ
406 if ( item )
407 {
90e572f1 408 // is it us or one of our "internal" children?
1e6feb95
VZ
409 if ( item->GetId() == id
410#ifndef __WXUNIVERSAL__
411 || (item->GetSubcontrols().Index(id) != wxNOT_FOUND)
412#endif // __WXUNIVERSAL__
413 )
f048e32f
VZ
414 {
415 return item;
416 }
417 }
1e6feb95 418#endif // wxUSE_CONTROLS
f048e32f 419
222ed1d6 420 wxWindowList::compatibility_iterator current = GetChildren().GetFirst();
2d0a075d
JS
421 while (current)
422 {
42e69d6b 423 wxWindow *childWin = current->GetData();
2bda0e17 424
42e69d6b 425 wxWindow *wnd = childWin->FindItem(id);
cc2b7472 426 if ( wnd )
42e69d6b 427 return wnd;
2bda0e17 428
42e69d6b 429 current = current->GetNext();
2bda0e17 430 }
42e69d6b 431
2d0a075d 432 return NULL;
2bda0e17
KB
433}
434
435// Find an item given the MS Windows handle
1e6feb95 436wxWindow *wxWindowMSW::FindItemByHWND(WXHWND hWnd, bool controlOnly) const
2bda0e17 437{
222ed1d6 438 wxWindowList::compatibility_iterator current = GetChildren().GetFirst();
2d0a075d 439 while (current)
2bda0e17 440 {
42e69d6b
VZ
441 wxWindow *parent = current->GetData();
442
2d0a075d 443 // Do a recursive search.
42e69d6b 444 wxWindow *wnd = parent->FindItemByHWND(hWnd);
cc2b7472 445 if ( wnd )
42e69d6b 446 return wnd;
2d0a075d 447
1e6feb95
VZ
448 if ( !controlOnly
449#if wxUSE_CONTROLS
450 || parent->IsKindOf(CLASSINFO(wxControl))
451#endif // wxUSE_CONTROLS
452 )
2d0a075d 453 {
42e69d6b
VZ
454 wxWindow *item = current->GetData();
455 if ( item->GetHWND() == hWnd )
2d0a075d
JS
456 return item;
457 else
458 {
459 if ( item->ContainsHWND(hWnd) )
460 return item;
461 }
462 }
42e69d6b
VZ
463
464 current = current->GetNext();
2bda0e17 465 }
2d0a075d 466 return NULL;
2bda0e17
KB
467}
468
469// Default command handler
1e6feb95 470bool wxWindowMSW::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
2bda0e17 471{
08158721 472 return false;
2bda0e17
KB
473}
474
fd3f686c
VZ
475// ----------------------------------------------------------------------------
476// constructors and such
477// ----------------------------------------------------------------------------
478
1e6feb95 479void wxWindowMSW::Init()
2bda0e17 480{
cc2b7472 481 // MSW specific
08158721 482 m_isBeingDeleted = false;
5a403e3f 483 m_oldWndProc = NULL;
08158721
DS
484 m_mouseInWindow = false;
485 m_lastKeydownProcessed = false;
2bda0e17 486
d7cbabe0 487 m_childrenDisabled = NULL;
a1037371 488 m_frozenness = 0;
d7cbabe0 489
319fefa9 490 m_hWnd = 0;
220f77b0 491 m_hDWP = 0;
319fefa9 492
2d0a075d
JS
493 m_xThumbSize = 0;
494 m_yThumbSize = 0;
2bda0e17 495
67644c1d
RD
496 m_pendingPosition = wxDefaultPosition;
497 m_pendingSize = wxDefaultSize;
7d4f65e3
JS
498
499#ifdef __POCKETPC__
500 m_contextMenuEnabled = false;
501#endif
fd3f686c
VZ
502}
503
2bda0e17 504// Destructor
1e6feb95 505wxWindowMSW::~wxWindowMSW()
2bda0e17 506{
08158721 507 m_isBeingDeleted = true;
2bda0e17 508
2e9f62da 509#ifndef __WXUNIVERSAL__
4a41c655 510 // VS: make sure there's no wxFrame with last focus set to us:
2e9f62da 511 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
4a41c655 512 {
085ad686 513 wxTopLevelWindow *frame = wxDynamicCast(win, wxTopLevelWindow);
4a41c655
VS
514 if ( frame )
515 {
c5053639 516 if ( frame->GetLastFocus() == this )
2e9f62da 517 {
085ad686 518 frame->SetLastFocus(NULL);
2e9f62da 519 }
4552892f
VZ
520
521 // apparently sometimes we can end up with our grand parent
522 // pointing to us as well: this is surely a bug in focus handling
523 // code but it's not clear where it happens so for now just try to
524 // fix it here by not breaking out of the loop
525 //break;
4a41c655
VS
526 }
527 }
2e9f62da 528#endif // __WXUNIVERSAL__
2bda0e17 529
cc0c7cd8 530 // VS: destroy children first and _then_ detach *this from its parent.
90e572f1 531 // If we did it the other way around, children wouldn't be able
cc0c7cd8
VS
532 // find their parent frame (see above).
533 DestroyChildren();
534
cc2b7472 535 if ( m_hWnd )
42e69d6b 536 {
98440bc3
VZ
537 // VZ: test temp removed to understand what really happens here
538 //if (::IsWindow(GetHwnd()))
df61c009
JS
539 {
540 if ( !::DestroyWindow(GetHwnd()) )
f6bcfd97 541 wxLogLastError(wxT("DestroyWindow"));
df61c009 542 }
2bda0e17 543
c50f1fb9
VZ
544 // remove hWnd <-> wxWindow association
545 wxRemoveHandleAssociation(this);
546 }
d7cbabe0
VZ
547
548 delete m_childrenDisabled;
da78f3b1 549
2bda0e17
KB
550}
551
fd3f686c 552// real construction (Init() must have been called before!)
1e6feb95
VZ
553bool wxWindowMSW::Create(wxWindow *parent,
554 wxWindowID id,
555 const wxPoint& pos,
556 const wxSize& size,
557 long style,
558 const wxString& name)
2d0a075d 559{
08158721 560 wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") );
2bda0e17 561
8d99be5f 562 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
08158721 563 return false;
42e69d6b 564
fd3f686c 565 parent->AddChild(this);
2bda0e17 566
b2d5a7ee 567 WXDWORD exstyle;
e49d97e6 568 DWORD msflags = MSWGetCreateWindowFlags(&exstyle);
1e6feb95
VZ
569
570#ifdef __WXUNIVERSAL__
d1fe917b 571 // no borders, we draw them ourselves
76c79ff4
VZ
572 exstyle &= ~(WS_EX_DLGMODALFRAME |
573 WS_EX_STATICEDGE |
574 WS_EX_CLIENTEDGE |
575 WS_EX_WINDOWEDGE);
d1fe917b 576 msflags &= ~WS_BORDER;
b2d5a7ee 577#endif // wxUniversal
1e6feb95 578
ff792344 579 if ( IsShown() )
e49d97e6
VZ
580 {
581 msflags |= WS_VISIBLE;
582 }
1e6feb95 583
45956e37
VZ
584 if ( !MSWCreate(wxCanvasClassName, NULL, pos, size, msflags, exstyle) )
585 return false;
586
587 InheritAttributes();
588
589 return true;
2bda0e17
KB
590}
591
42e69d6b
VZ
592// ---------------------------------------------------------------------------
593// basic operations
594// ---------------------------------------------------------------------------
595
1e6feb95 596void wxWindowMSW::SetFocus()
2bda0e17 597{
a23fd0e1 598 HWND hWnd = GetHwnd();
1e6feb95
VZ
599 wxCHECK_RET( hWnd, _T("can't set focus to invalid window") );
600
7f0586ef 601#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1e6feb95 602 ::SetLastError(0);
8cb172b4 603#endif
d0a3d109 604
1e6feb95
VZ
605 if ( !::SetFocus(hWnd) )
606 {
5262eb0a 607#if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
1e6feb95
VZ
608 // was there really an error?
609 DWORD dwRes = ::GetLastError();
610 if ( dwRes )
611 {
5262eb0a
VZ
612 HWND hwndFocus = ::GetFocus();
613 if ( hwndFocus != hWnd )
614 {
615 wxLogApiError(_T("SetFocus"), dwRes);
616 }
1e6feb95 617 }
5262eb0a 618#endif // Debug
1e6feb95 619 }
2bda0e17
KB
620}
621
ddf9d04f
VZ
622void wxWindowMSW::SetFocusFromKbd()
623{
ddf9d04f
VZ
624 // when the focus is given to the control with DLGC_HASSETSEL style from
625 // keyboard its contents should be entirely selected: this is what
626 // ::IsDialogMessage() does and so we should do it as well to provide the
627 // same LNF as the native programs
628 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE, 0, 0) & DLGC_HASSETSEL )
629 {
630 ::SendMessage(GetHwnd(), EM_SETSEL, 0, -1);
631 }
1b1ca07a
VZ
632
633 // do this after (maybe) setting the selection as like this when
634 // wxEVT_SET_FOCUS handler is called, the selection would have been already
635 // set correctly -- this may be important
636 wxWindowBase::SetFocusFromKbd();
ddf9d04f
VZ
637}
638
42e69d6b 639// Get the window with the focus
0fe02759 640wxWindow *wxWindowBase::DoFindFocus()
42e69d6b
VZ
641{
642 HWND hWnd = ::GetFocus();
643 if ( hWnd )
644 {
a2242341 645 return wxGetWindowFromHWND((WXHWND)hWnd);
42e69d6b
VZ
646 }
647
648 return NULL;
649}
650
1e6feb95 651bool wxWindowMSW::Enable(bool enable)
2bda0e17 652{
cc2b7472 653 if ( !wxWindowBase::Enable(enable) )
08158721 654 return false;
cc2b7472 655
a23fd0e1 656 HWND hWnd = GetHwnd();
cc2b7472 657 if ( hWnd )
2d0a075d 658 ::EnableWindow(hWnd, (BOOL)enable);
cc2b7472 659
83a16cfa
VZ
660 // the logic below doesn't apply to the top level windows -- otherwise
661 // showing a modal dialog would result in total greying out (and ungreying
662 // out later) of everything which would be really ugly
663 if ( IsTopLevel() )
08158721 664 return true;
83a16cfa 665
d7cbabe0
VZ
666 // when the parent is disabled, all of its children should be disabled as
667 // well but when it is enabled back, only those of the children which
668 // hadn't been already disabled in the beginning should be enabled again,
669 // so we have to keep the list of those children
222ed1d6 670 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
fa3d9b4e
VZ
671 node;
672 node = node->GetNext() )
87a1e308
VZ
673 {
674 wxWindow *child = node->GetData();
fa3d9b4e
VZ
675 if ( child->IsTopLevel() )
676 {
677 // the logic below doesn't apply to top level children
678 continue;
679 }
d7cbabe0
VZ
680
681 if ( enable )
682 {
90e572f1 683 // re-enable the child unless it had been disabled before us
d7cbabe0
VZ
684 if ( !m_childrenDisabled || !m_childrenDisabled->Find(child) )
685 child->Enable();
686 }
687 else // we're being disabled
688 {
689 if ( child->IsEnabled() )
690 {
691 // disable it as children shouldn't stay enabled while the
692 // parent is not
693 child->Disable();
694 }
695 else // child already disabled, remember it
696 {
697 // have we created the list of disabled children already?
698 if ( !m_childrenDisabled )
699 m_childrenDisabled = new wxWindowList;
700
701 m_childrenDisabled->Append(child);
702 }
703 }
87a1e308 704 }
d7cbabe0
VZ
705
706 if ( enable && m_childrenDisabled )
707 {
708 // we don't need this list any more, don't keep unused memory
709 delete m_childrenDisabled;
710 m_childrenDisabled = NULL;
711 }
87a1e308 712
08158721 713 return true;
2bda0e17
KB
714}
715
1e6feb95 716bool wxWindowMSW::Show(bool show)
42e69d6b
VZ
717{
718 if ( !wxWindowBase::Show(show) )
08158721 719 return false;
42e69d6b
VZ
720
721 HWND hWnd = GetHwnd();
42e69d6b 722
a068160f
VZ
723 // we could be called before the underlying window is created (this is
724 // actually useful to prevent it from being initially shown), e.g.
725 //
726 // wxFoo *foo = new wxFoo;
727 // foo->Hide();
728 // foo->Create(parent, ...);
729 //
730 // should work without errors
731 if ( hWnd )
42e69d6b 732 {
a068160f 733 ::ShowWindow(hWnd, show ? SW_SHOW : SW_HIDE);
42e69d6b
VZ
734 }
735
08158721 736 return true;
42e69d6b
VZ
737}
738
739// Raise the window to the top of the Z order
1e6feb95 740void wxWindowMSW::Raise()
42e69d6b 741{
c48926e1 742 wxBringWindowToTop(GetHwnd());
42e69d6b
VZ
743}
744
745// Lower the window to the bottom of the Z order
1e6feb95 746void wxWindowMSW::Lower()
42e69d6b
VZ
747{
748 ::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0,
749 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
750}
751
94633ad9 752void wxWindowMSW::DoCaptureMouse()
2bda0e17 753{
a23fd0e1 754 HWND hWnd = GetHwnd();
1e6feb95 755 if ( hWnd )
2d0a075d 756 {
1e6feb95 757 ::SetCapture(hWnd);
2d0a075d 758 }
2bda0e17
KB
759}
760
94633ad9 761void wxWindowMSW::DoReleaseMouse()
2bda0e17 762{
1e6feb95 763 if ( !::ReleaseCapture() )
2d0a075d 764 {
1e6feb95 765 wxLogLastError(_T("ReleaseCapture"));
2d0a075d 766 }
2bda0e17
KB
767}
768
1e6feb95
VZ
769/* static */ wxWindow *wxWindowBase::GetCapture()
770{
771 HWND hwnd = ::GetCapture();
772 return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : (wxWindow *)NULL;
773}
774
775bool wxWindowMSW::SetFont(const wxFont& font)
2bda0e17 776{
42e69d6b
VZ
777 if ( !wxWindowBase::SetFont(font) )
778 {
779 // nothing to do
08158721 780 return false;
2d0a075d 781 }
195896c7 782
42e69d6b
VZ
783 HWND hWnd = GetHwnd();
784 if ( hWnd != 0 )
785 {
786 WXHANDLE hFont = m_font.GetResourceHandle();
2bda0e17 787
223d09f6 788 wxASSERT_MSG( hFont, wxT("should have valid font") );
3a19e16d 789
c50f1fb9 790 ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
42e69d6b 791 }
2bda0e17 792
08158721 793 return true;
42e69d6b 794}
1e6feb95 795bool wxWindowMSW::SetCursor(const wxCursor& cursor)
2bda0e17 796{
42e69d6b
VZ
797 if ( !wxWindowBase::SetCursor(cursor) )
798 {
799 // no change
08158721 800 return false;
42e69d6b
VZ
801 }
802
8e75dca8
VZ
803 // don't "overwrite" busy cursor
804 if ( m_cursor.Ok() && !wxIsBusy() )
8a9c2246 805 {
8e75dca8 806 ::SetCursor(GetHcursorOf(m_cursor));
8a9c2246 807 }
3a19e16d 808
08158721 809 return true;
3a19e16d
VZ
810}
811
d7e0024b 812void wxWindowMSW::WarpPointer(int x, int y)
2bda0e17 813{
1e6feb95 814 ClientToScreen(&x, &y);
42e69d6b 815
1e6feb95
VZ
816 if ( !::SetCursorPos(x, y) )
817 {
818 wxLogLastError(_T("SetCursorPos"));
819 }
2bda0e17
KB
820}
821
1ca78aa1 822void wxWindowMSW::MSWUpdateUIState(int action, int state)
d7e0024b 823{
1ca78aa1 824 // WM_CHANGEUISTATE only appeared in Windows 2000 so it can do us no good
d7e0024b
VZ
825 // to use it on older systems -- and could possibly do some harm
826 static int s_needToUpdate = -1;
827 if ( s_needToUpdate == -1 )
828 {
829 int verMaj, verMin;
406d283a 830 s_needToUpdate = wxGetOsVersion(&verMaj, &verMin) == wxOS_WINDOWS_NT &&
d7e0024b
VZ
831 verMaj >= 5;
832 }
833
834 if ( s_needToUpdate )
835 {
1ca78aa1
JS
836 // we send WM_CHANGEUISTATE so if nothing needs changing then the system
837 // won't send WM_UPDATEUISTATE
838 ::SendMessage(GetHwnd(), WM_CHANGEUISTATE, MAKEWPARAM(action, state), 0);
d7e0024b
VZ
839 }
840}
841
42e69d6b
VZ
842// ---------------------------------------------------------------------------
843// scrolling stuff
844// ---------------------------------------------------------------------------
2d0a075d 845
9cd6d737
VZ
846inline int GetScrollPosition(HWND hWnd, int wOrient)
847{
848#ifdef __WXMICROWIN__
849 return ::GetScrollPosWX(hWnd, wOrient);
850#else
f676b387 851 WinStruct<SCROLLINFO> scrollInfo;
4676948b 852 scrollInfo.cbSize = sizeof(SCROLLINFO);
7f0586ef 853 scrollInfo.fMask = SIF_POS;
e795e8b5 854 ::GetScrollInfo(hWnd, wOrient, &scrollInfo );
a71d815b 855
7f0586ef 856 return scrollInfo.nPos;
e795e8b5 857
9cd6d737
VZ
858#endif
859}
860
1e6feb95 861int wxWindowMSW::GetScrollPos(int orient) const
2bda0e17 862{
42e69d6b 863 HWND hWnd = GetHwnd();
9cd6d737
VZ
864 wxCHECK_MSG( hWnd, 0, _T("no HWND in GetScrollPos") );
865
0cf5de11 866 return GetScrollPosition(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT);
42e69d6b 867}
2bda0e17 868
42e69d6b
VZ
869// This now returns the whole range, not just the number
870// of positions that we can scroll.
1e6feb95 871int wxWindowMSW::GetScrollRange(int orient) const
42e69d6b 872{
7f0586ef 873 int maxPos;
a23fd0e1 874 HWND hWnd = GetHwnd();
0cf5de11 875 if ( !hWnd )
42e69d6b 876 return 0;
7f0586ef 877#if 0
0cf5de11
VZ
878 ::GetScrollRange(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT,
879 &minPos, &maxPos);
7f0586ef 880#endif
f676b387 881 WinStruct<SCROLLINFO> scrollInfo;
7f0586ef
JS
882 scrollInfo.fMask = SIF_RANGE;
883 if ( !::GetScrollInfo(hWnd,
f676b387
RD
884 orient == wxHORIZONTAL ? SB_HORZ : SB_VERT,
885 &scrollInfo) )
7f0586ef 886 {
f676b387
RD
887 // Most of the time this is not really an error, since the return
888 // value can also be zero when there is no scrollbar yet.
889 // wxLogLastError(_T("GetScrollInfo"));
7f0586ef
JS
890 }
891 maxPos = scrollInfo.nMax;
0cf5de11
VZ
892
893 // undo "range - 1" done in SetScrollbar()
894 return maxPos + 1;
cc2b7472 895}
2bda0e17 896
1e6feb95 897int wxWindowMSW::GetScrollThumb(int orient) const
2bda0e17 898{
0cf5de11 899 return orient == wxHORIZONTAL ? m_xThumbSize : m_yThumbSize;
2bda0e17
KB
900}
901
1e6feb95 902void wxWindowMSW::SetScrollPos(int orient, int pos, bool refresh)
2bda0e17 903{
5f3286d1
VZ
904 HWND hWnd = GetHwnd();
905 wxCHECK_RET( hWnd, _T("SetScrollPos: no HWND") );
72fd19a1 906
0cf5de11 907 WinStruct<SCROLLINFO> info;
42e69d6b
VZ
908 info.nPage = 0;
909 info.nMin = 0;
910 info.nPos = pos;
911 info.fMask = SIF_POS;
a647d42a
VZ
912 if ( HasFlag(wxALWAYS_SHOW_SB) )
913 {
914 // disable scrollbar instead of removing it then
915 info.fMask |= SIF_DISABLENOSCROLL;
916 }
2d0a075d 917
0cf5de11
VZ
918 ::SetScrollInfo(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT,
919 &info, refresh);
2bda0e17
KB
920}
921
42e69d6b 922// New function that will replace some of the above.
0cf5de11
VZ
923void wxWindowMSW::SetScrollbar(int orient,
924 int pos,
925 int pageSize,
926 int range,
927 bool refresh)
928{
929 WinStruct<SCROLLINFO> info;
930 info.nPage = pageSize;
931 info.nMin = 0; // range is nMax - nMin + 1
932 info.nMax = range - 1; // as both nMax and nMax are inclusive
42e69d6b
VZ
933 info.nPos = pos;
934 info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
a647d42a
VZ
935 if ( HasFlag(wxALWAYS_SHOW_SB) )
936 {
937 // disable scrollbar instead of removing it then
938 info.fMask |= SIF_DISABLENOSCROLL;
939 }
2bda0e17 940
42e69d6b
VZ
941 HWND hWnd = GetHwnd();
942 if ( hWnd )
81d66cf3 943 {
55a667b6
JS
944 // We have to set the variables here to make them valid in events
945 // triggered by ::SetScrollInfo()
946 *(orient == wxHORIZONTAL ? &m_xThumbSize : &m_yThumbSize) = pageSize;
521bf4ff 947
0cf5de11
VZ
948 ::SetScrollInfo(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT,
949 &info, refresh);
81d66cf3
JS
950 }
951}
952
1e6feb95 953void wxWindowMSW::ScrollWindow(int dx, int dy, const wxRect *prect)
2bda0e17 954{
574c939e
KB
955 RECT rect;
956 RECT *pr;
1e6feb95 957 if ( prect )
2d0a075d 958 {
1e6feb95
VZ
959 rect.left = prect->x;
960 rect.top = prect->y;
961 rect.right = prect->x + prect->width;
962 rect.bottom = prect->y + prect->height;
f797e53d
VZ
963 pr = &rect;
964 }
965 else
966 {
967 pr = NULL;
304b8bc1 968
2d0a075d 969 }
2bda0e17 970
7f0586ef
JS
971#ifdef __WXWINCE__
972 // FIXME: is this the exact equivalent of the line below?
304b8bc1 973 ::ScrollWindowEx(GetHwnd(), dx, dy, pr, pr, 0, 0, SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);
7f0586ef 974#else
f797e53d 975 ::ScrollWindow(GetHwnd(), dx, dy, pr, pr);
7f0586ef 976#endif
2bda0e17
KB
977}
978
9cd6d737 979static bool ScrollVertically(HWND hwnd, int kind, int count)
b9b3393e 980{
9cd6d737
VZ
981 int posStart = GetScrollPosition(hwnd, SB_VERT);
982
983 int pos = posStart;
c0cdd6cc
VZ
984 for ( int n = 0; n < count; n++ )
985 {
986 ::SendMessage(hwnd, WM_VSCROLL, kind, 0);
9cd6d737
VZ
987
988 int posNew = GetScrollPosition(hwnd, SB_VERT);
989 if ( posNew == pos )
990 {
991 // don't bother to continue, we're already at top/bottom
992 break;
993 }
994
995 pos = posNew;
c0cdd6cc 996 }
9cd6d737
VZ
997
998 return pos != posStart;
b9b3393e
VZ
999}
1000
9cd6d737 1001bool wxWindowMSW::ScrollLines(int lines)
b9b3393e
VZ
1002{
1003 bool down = lines > 0;
1004
9cd6d737
VZ
1005 return ScrollVertically(GetHwnd(),
1006 down ? SB_LINEDOWN : SB_LINEUP,
1007 down ? lines : -lines);
b9b3393e
VZ
1008}
1009
9cd6d737 1010bool wxWindowMSW::ScrollPages(int pages)
b9b3393e
VZ
1011{
1012 bool down = pages > 0;
1013
9cd6d737
VZ
1014 return ScrollVertically(GetHwnd(),
1015 down ? SB_PAGEDOWN : SB_PAGEUP,
1016 down ? pages : -pages);
b9b3393e
VZ
1017}
1018
978af864
VZ
1019// ----------------------------------------------------------------------------
1020// RTL support
1021// ----------------------------------------------------------------------------
1022
1023void wxWindowMSW::SetLayoutDirection(wxLayoutDirection dir)
1024{
08a58133
WS
1025#ifdef __WXWINCE__
1026 wxUnusedVar(dir);
1027#else
978af864
VZ
1028 const HWND hwnd = GetHwnd();
1029 wxCHECK_RET( hwnd, _T("layout direction must be set after window creation") );
1030
1031 LONG styleOld = ::GetWindowLong(hwnd, GWL_EXSTYLE);
1032
1033 LONG styleNew = styleOld;
1034 switch ( dir )
1035 {
1036 case wxLayout_LeftToRight:
1037 styleNew &= ~WS_EX_LAYOUTRTL;
1038 break;
1039
1040 case wxLayout_RightToLeft:
1041 styleNew |= WS_EX_LAYOUTRTL;
1042 break;
1043
1044 default:
1045 wxFAIL_MSG(_T("unsupported layout direction"));
1046 break;
1047 }
1048
1049 if ( styleNew != styleOld )
1050 {
1051 ::SetWindowLong(hwnd, GWL_EXSTYLE, styleNew);
1052 }
08a58133 1053#endif
978af864
VZ
1054}
1055
1056wxLayoutDirection wxWindowMSW::GetLayoutDirection() const
1057{
08a58133
WS
1058#ifdef __WXWINCE__
1059 return wxLayout_Default;
1060#else
978af864
VZ
1061 const HWND hwnd = GetHwnd();
1062 wxCHECK_MSG( hwnd, wxLayout_Default, _T("invalid window") );
1063
1064 return ::GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_LAYOUTRTL
1065 ? wxLayout_RightToLeft
1066 : wxLayout_LeftToRight;
08a58133 1067#endif
978af864
VZ
1068}
1069
1070wxCoord
1071wxWindowMSW::AdjustForLayoutDirection(wxCoord x,
1072 wxCoord WXUNUSED(width),
1073 wxCoord WXUNUSED(widthTotal)) const
1074{
1075 // Win32 mirrors the coordinates of RTL windows automatically, so don't
1076 // redo it ourselves
1077 return x;
1078}
1079
42e69d6b
VZ
1080// ---------------------------------------------------------------------------
1081// subclassing
1082// ---------------------------------------------------------------------------
1083
1e6feb95 1084void wxWindowMSW::SubclassWin(WXHWND hWnd)
2bda0e17 1085{
223d09f6 1086 wxASSERT_MSG( !m_oldWndProc, wxT("subclassing window twice?") );
2bda0e17 1087
c50f1fb9 1088 HWND hwnd = (HWND)hWnd;
223d09f6 1089 wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in SubclassWin") );
c50f1fb9
VZ
1090
1091 wxAssociateWinWithHandle(hwnd, this);
2bda0e17 1092
975b6bcf 1093 m_oldWndProc = (WXFARPROC)wxGetWindowProc((HWND)hWnd);
b2d5a7ee 1094
b225f659
VZ
1095 // we don't need to subclass the window of our own class (in the Windows
1096 // sense of the word)
3a3c8603 1097 if ( !wxCheckWindowWndProc(hWnd, (WXFARPROC)wxWndProc) )
b225f659 1098 {
975b6bcf 1099 wxSetWindowProc(hwnd, wxWndProc);
b225f659
VZ
1100 }
1101 else
1102 {
90e572f1 1103 // don't bother restoring it either: this also makes it easy to
08158721 1104 // implement IsOfStandardClass() method which returns true for the
77ffb593 1105 // standard controls and false for the wxWidgets own windows as it can
5a403e3f 1106 // simply check m_oldWndProc
b225f659
VZ
1107 m_oldWndProc = NULL;
1108 }
e7c652bc
VZ
1109
1110 // we're officially created now, send the event
1111 wxWindowCreateEvent event((wxWindow *)this);
1112 (void)GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
1113}
1114
1e6feb95 1115void wxWindowMSW::UnsubclassWin()
2bda0e17 1116{
42e69d6b 1117 wxRemoveHandleAssociation(this);
2bda0e17 1118
42e69d6b 1119 // Restore old Window proc
c50f1fb9
VZ
1120 HWND hwnd = GetHwnd();
1121 if ( hwnd )
42e69d6b 1122 {
ed4780ea 1123 SetHWND(0);
c50f1fb9 1124
223d09f6 1125 wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in UnsubclassWin") );
c50f1fb9 1126
b225f659 1127 if ( m_oldWndProc )
42e69d6b 1128 {
eb5e4d9a 1129 if ( !wxCheckWindowWndProc((WXHWND)hwnd, m_oldWndProc) )
b225f659 1130 {
975b6bcf 1131 wxSetWindowProc(hwnd, (WNDPROC)m_oldWndProc);
b225f659
VZ
1132 }
1133
1134 m_oldWndProc = NULL;
42e69d6b 1135 }
42e69d6b 1136 }
2bda0e17
KB
1137}
1138
a4d1972d 1139void wxWindowMSW::AssociateHandle(WXWidget handle)
ed4780ea
VZ
1140{
1141 if ( m_hWnd )
1142 {
1143 if ( !::DestroyWindow(GetHwnd()) )
1144 wxLogLastError(wxT("DestroyWindow"));
1145 }
a4d1972d 1146
ed4780ea
VZ
1147 WXHWND wxhwnd = (WXHWND)handle;
1148
1149 SetHWND(wxhwnd);
1150 SubclassWin(wxhwnd);
1151}
1152
1153void wxWindowMSW::DissociateHandle()
a4d1972d 1154{
ed4780ea 1155 // this also calls SetHWND(0) for us
a4d1972d 1156 UnsubclassWin();
ed4780ea
VZ
1157}
1158
1159
0c0d1521 1160bool wxCheckWindowWndProc(WXHWND hWnd,
11f104e5 1161 WXFARPROC WXUNUSED(wndProc))
eb5e4d9a 1162{
f57f984c
RD
1163// TODO: This list of window class names should be factored out so they can be
1164// managed in one place and then accessed from here and other places, such as
1165// wxApp::RegisterWindowClasses() and wxApp::UnregisterWindowClasses()
521bf4ff
WS
1166
1167#ifdef __WXWINCE__
3a3c8603
DS
1168 extern wxChar *wxCanvasClassName;
1169 extern wxChar *wxCanvasClassNameNR;
f57f984c
RD
1170#else
1171 extern const wxChar *wxCanvasClassName;
1172 extern const wxChar *wxCanvasClassNameNR;
1173#endif
3a3c8603
DS
1174 extern const wxChar *wxMDIFrameClassName;
1175 extern const wxChar *wxMDIFrameClassNameNoRedraw;
1176 extern const wxChar *wxMDIChildFrameClassName;
1177 extern const wxChar *wxMDIChildFrameClassNameNoRedraw;
1178 wxString str(wxGetWindowClass(hWnd));
1179 if (str == wxCanvasClassName ||
1180 str == wxCanvasClassNameNR ||
26c2a266
JG
1181#if wxUSE_GLCANVAS
1182 str == _T("wxGLCanvasClass") ||
1183 str == _T("wxGLCanvasClassNR") ||
1184#endif // wxUSE_GLCANVAS
3a3c8603
DS
1185 str == wxMDIFrameClassName ||
1186 str == wxMDIFrameClassNameNoRedraw ||
1187 str == wxMDIChildFrameClassName ||
1188 str == wxMDIChildFrameClassNameNoRedraw ||
1189 str == _T("wxTLWHiddenParent"))
1190 return true; // Effectively means don't subclass
f57f984c 1191 else
08158721 1192 return false;
eb5e4d9a
VS
1193}
1194
b2d5a7ee
VZ
1195// ----------------------------------------------------------------------------
1196// Style handling
1197// ----------------------------------------------------------------------------
1198
1199void wxWindowMSW::SetWindowStyleFlag(long flags)
1200{
1201 long flagsOld = GetWindowStyleFlag();
1202 if ( flags == flagsOld )
1203 return;
1204
1205 // update the internal variable
1206 wxWindowBase::SetWindowStyleFlag(flags);
1207
7bd6bf45
VZ
1208 // and the real window flags
1209 MSWUpdateStyle(flagsOld, GetExtraStyle());
1210}
1211
1212void wxWindowMSW::SetExtraStyle(long exflags)
1213{
1214 long exflagsOld = GetExtraStyle();
1215 if ( exflags == exflagsOld )
1216 return;
1217
1218 // update the internal variable
1219 wxWindowBase::SetExtraStyle(exflags);
1220
1221 // and the real window flags
1222 MSWUpdateStyle(GetWindowStyleFlag(), exflagsOld);
1223}
1224
1225void wxWindowMSW::MSWUpdateStyle(long flagsOld, long exflagsOld)
1226{
5b2f31eb
VZ
1227 // now update the Windows style as well if needed - and if the window had
1228 // been already created
1229 if ( !GetHwnd() )
1230 return;
1231
9ce75461
VZ
1232 // we may need to call SetWindowPos() when we change some styles
1233 bool callSWP = false;
1234
7bd6bf45
VZ
1235 WXDWORD exstyle;
1236 long style = MSWGetStyle(GetWindowStyleFlag(), &exstyle);
1237
1238 // this is quite a horrible hack but we need it because MSWGetStyle()
1239 // doesn't take exflags as parameter but uses GetExtraStyle() internally
1240 // and so we have to modify the window exflags temporarily to get the
1241 // correct exstyleOld
1242 long exflagsNew = GetExtraStyle();
1243 wxWindowBase::SetExtraStyle(exflagsOld);
1244
1245 WXDWORD exstyleOld;
1246 long styleOld = MSWGetStyle(flagsOld, &exstyleOld);
1247
1248 wxWindowBase::SetExtraStyle(exflagsNew);
1249
b2d5a7ee
VZ
1250
1251 if ( style != styleOld )
1252 {
1253 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1254 // this function so instead of simply setting the style to the new
1255 // value we clear the bits which were set in styleOld but are set in
1256 // the new one and set the ones which were not set before
1257 long styleReal = ::GetWindowLong(GetHwnd(), GWL_STYLE);
1258 styleReal &= ~styleOld;
1259 styleReal |= style;
1260
1261 ::SetWindowLong(GetHwnd(), GWL_STYLE, styleReal);
9ce75461 1262
7bd6bf45
VZ
1263 // we need to call SetWindowPos() if any of the styles affecting the
1264 // frame appearance have changed
9ce75461
VZ
1265 callSWP = ((styleOld ^ style ) & (WS_BORDER |
1266 WS_THICKFRAME |
1267 WS_CAPTION |
1268 WS_DLGFRAME |
1269 WS_MAXIMIZEBOX |
1270 WS_MINIMIZEBOX |
1271 WS_SYSMENU) ) != 0;
b2d5a7ee
VZ
1272 }
1273
1274 // and the extended style
9ce75461
VZ
1275 long exstyleReal = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
1276
b2d5a7ee
VZ
1277 if ( exstyle != exstyleOld )
1278 {
b2d5a7ee
VZ
1279 exstyleReal &= ~exstyleOld;
1280 exstyleReal |= exstyle;
1281
1282 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyleReal);
1283
9ce75461
VZ
1284 // ex style changes don't take effect without calling SetWindowPos
1285 callSWP = true;
1286 }
1287
1288 if ( callSWP )
1289 {
85d8df29 1290 // we must call SetWindowPos() to flush the cached extended style and
b2d5a7ee
VZ
1291 // also to make the change to wxSTAY_ON_TOP style take effect: just
1292 // setting the style simply doesn't work
1293 if ( !::SetWindowPos(GetHwnd(),
1294 exstyleReal & WS_EX_TOPMOST ? HWND_TOPMOST
1295 : HWND_NOTOPMOST,
1296 0, 0, 0, 0,
9ce75461 1297 SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED) )
b2d5a7ee
VZ
1298 {
1299 wxLogLastError(_T("SetWindowPos"));
1300 }
1301 }
1302}
1303
1304WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const
1305{
77ffb593 1306 // translate common wxWidgets styles to Windows ones
af495479
VZ
1307
1308 // most of windows are child ones, those which are not (such as
1309 // wxTopLevelWindow) should remove WS_CHILD in their MSWGetStyle()
1310 WXDWORD style = WS_CHILD;
b2d5a7ee 1311
9b6ae450
VZ
1312 // using this flag results in very significant reduction in flicker,
1313 // especially with controls inside the static boxes (as the interior of the
90e572f1 1314 // box is not redrawn twice), but sometimes results in redraw problems, so
c7e1d004
VZ
1315 // optionally allow the old code to continue to use it provided a special
1316 // system option is turned on
1317 if ( !wxSystemOptions::GetOptionInt(wxT("msw.window.no-clip-children"))
1318 || (flags & wxCLIP_CHILDREN) )
c6430ed0 1319 style |= WS_CLIPCHILDREN;
9b6ae450
VZ
1320
1321 // it doesn't seem useful to use WS_CLIPSIBLINGS here as we officially
1322 // don't support overlapping windows and it only makes sense for them and,
1323 // presumably, gives the system some extra work (to manage more clipping
1324 // regions), so avoid it alltogether
b2d5a7ee 1325
b2d5a7ee 1326
f9007c32
JS
1327 if ( flags & wxVSCROLL )
1328 style |= WS_VSCROLL;
1329
1330 if ( flags & wxHSCROLL )
1331 style |= WS_HSCROLL;
1332
65bc172c 1333 const wxBorder border = GetBorder(flags);
577baeef 1334
65bc172c
VZ
1335 // WS_BORDER is only required for wxBORDER_SIMPLE
1336 if ( border == wxBORDER_SIMPLE )
b2d5a7ee 1337 style |= WS_BORDER;
577baeef 1338
b2d5a7ee
VZ
1339 // now deal with ext style if the caller wants it
1340 if ( exstyle )
1341 {
1342 *exstyle = 0;
1343
7f0586ef 1344#ifndef __WXWINCE__
b2d5a7ee
VZ
1345 if ( flags & wxTRANSPARENT_WINDOW )
1346 *exstyle |= WS_EX_TRANSPARENT;
7f0586ef 1347#endif
b2d5a7ee 1348
fe3d9123 1349 switch ( border )
b2d5a7ee
VZ
1350 {
1351 default:
65bc172c 1352 case wxBORDER_DEFAULT:
b2d5a7ee
VZ
1353 wxFAIL_MSG( _T("unknown border style") );
1354 // fall through
1355
1356 case wxBORDER_NONE:
1357 case wxBORDER_SIMPLE:
1358 break;
1359
1360 case wxBORDER_STATIC:
1361 *exstyle |= WS_EX_STATICEDGE;
1362 break;
1363
1364 case wxBORDER_RAISED:
7699361c 1365 *exstyle |= WS_EX_DLGMODALFRAME;
b2d5a7ee
VZ
1366 break;
1367
b2d5a7ee
VZ
1368 case wxBORDER_SUNKEN:
1369 *exstyle |= WS_EX_CLIENTEDGE;
fe3d9123 1370 style &= ~WS_BORDER;
b2d5a7ee
VZ
1371 break;
1372
1373 case wxBORDER_DOUBLE:
1374 *exstyle |= WS_EX_DLGMODALFRAME;
1375 break;
1376 }
d515c32d 1377
09168de7 1378 // wxUniv doesn't use Windows dialog navigation functions at all
7f0586ef 1379#if !defined(__WXUNIVERSAL__) && !defined(__WXWINCE__)
5b9c12e1 1380 // to make the dialog navigation work with the nested panels we must
09168de7
VZ
1381 // use this style (top level windows such as dialogs don't need it)
1382 if ( (flags & wxTAB_TRAVERSAL) && !IsTopLevel() )
d515c32d
VZ
1383 {
1384 *exstyle |= WS_EX_CONTROLPARENT;
1385 }
09168de7 1386#endif // __WXUNIVERSAL__
b2d5a7ee
VZ
1387 }
1388
1389 return style;
1390}
eb5e4d9a 1391
42e69d6b 1392// Setup background and foreground colours correctly
1e6feb95 1393void wxWindowMSW::SetupColours()
42e69d6b
VZ
1394{
1395 if ( GetParent() )
1396 SetBackgroundColour(GetParent()->GetBackgroundColour());
1397}
a23fd0e1 1398
1e6feb95
VZ
1399bool wxWindowMSW::IsMouseInWindow() const
1400{
1401 // get the mouse position
1402 POINT pt;
f2325516
JS
1403#ifdef __WXWINCE__
1404 ::GetCursorPosWinCE(&pt);
1405#else
1e6feb95 1406 ::GetCursorPos(&pt);
f2325516 1407#endif
1e6feb95
VZ
1408
1409 // find the window which currently has the cursor and go up the window
1410 // chain until we find this window - or exhaust it
1411 HWND hwnd = ::WindowFromPoint(pt);
1412 while ( hwnd && (hwnd != GetHwnd()) )
1413 hwnd = ::GetParent(hwnd);
1414
1415 return hwnd != NULL;
1416}
1417
e39af974 1418void wxWindowMSW::OnInternalIdle()
42e69d6b 1419{
4e5c6c33 1420#ifndef HAVE_TRACKMOUSEEVENT
42e69d6b
VZ
1421 // Check if we need to send a LEAVE event
1422 if ( m_mouseInWindow )
2d0a075d 1423 {
ee74faf9
VZ
1424 // note that we should generate the leave event whether the window has
1425 // or doesn't have mouse capture
1426 if ( !IsMouseInWindow() )
42e69d6b 1427 {
51e4e266 1428 GenerateMouseLeave();
42e69d6b
VZ
1429 }
1430 }
4e5c6c33 1431#endif // !HAVE_TRACKMOUSEEVENT
c085e333 1432
e39af974
JS
1433 if (wxUpdateUIEvent::CanUpdate(this))
1434 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
42e69d6b 1435}
568cb543 1436
42e69d6b 1437// Set this window to be the child of 'parent'.
1e6feb95 1438bool wxWindowMSW::Reparent(wxWindowBase *parent)
42e69d6b
VZ
1439{
1440 if ( !wxWindowBase::Reparent(parent) )
08158721 1441 return false;
c085e333 1442
42e69d6b
VZ
1443 HWND hWndChild = GetHwnd();
1444 HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
a23fd0e1 1445
42e69d6b 1446 ::SetParent(hWndChild, hWndParent);
a23fd0e1 1447
ee471817
VZ
1448#ifndef __WXWINCE__
1449 if ( ::GetWindowLong(hWndChild, GWL_EXSTYLE) & WS_EX_CONTROLPARENT )
1450 {
1451 EnsureParentHasControlParentStyle(GetParent());
1452 }
1453#endif // !__WXWINCE__
1454
08158721 1455 return true;
42e69d6b 1456}
a23fd0e1 1457
a0e449ff
VZ
1458static inline void SendSetRedraw(HWND hwnd, bool on)
1459{
c67d6888 1460#ifndef __WXMICROWIN__
a0e449ff 1461 ::SendMessage(hwnd, WM_SETREDRAW, (WPARAM)on, 0);
c67d6888 1462#endif
a0e449ff
VZ
1463}
1464
1465void wxWindowMSW::Freeze()
1466{
a1037371
VZ
1467 if ( !m_frozenness++ )
1468 {
dc993cbf
VZ
1469 if ( IsShown() )
1470 SendSetRedraw(GetHwnd(), false);
a1037371 1471 }
a0e449ff
VZ
1472}
1473
1474void wxWindowMSW::Thaw()
1475{
a1037371 1476 wxASSERT_MSG( m_frozenness > 0, _T("Thaw() without matching Freeze()") );
c0cdd6cc 1477
8d7eaf91 1478 if ( --m_frozenness == 0 )
a1037371 1479 {
dc993cbf
VZ
1480 if ( IsShown() )
1481 {
1482 SendSetRedraw(GetHwnd(), true);
a1037371 1483
dc993cbf
VZ
1484 // we need to refresh everything or otherwise the invalidated area
1485 // is not going to be repainted
1486 Refresh();
1487 }
a1037371 1488 }
a0e449ff
VZ
1489}
1490
1e6feb95 1491void wxWindowMSW::Refresh(bool eraseBack, const wxRect *rect)
42e69d6b
VZ
1492{
1493 HWND hWnd = GetHwnd();
1494 if ( hWnd )
1495 {
d181e053
VZ
1496 RECT mswRect;
1497 const RECT *pRect;
42e69d6b
VZ
1498 if ( rect )
1499 {
42e69d6b
VZ
1500 mswRect.left = rect->x;
1501 mswRect.top = rect->y;
1502 mswRect.right = rect->x + rect->width;
1503 mswRect.bottom = rect->y + rect->height;
a23fd0e1 1504
d181e053 1505 pRect = &mswRect;
42e69d6b
VZ
1506 }
1507 else
d181e053
VZ
1508 {
1509 pRect = NULL;
1510 }
1511
82e3664e 1512 // RedrawWindow not available on SmartPhone or eVC++ 3
41527143 1513#if !defined(__SMARTPHONE__) && !(defined(_WIN32_WCE) && _WIN32_WCE < 400)
d181e053
VZ
1514 UINT flags = RDW_INVALIDATE | RDW_ALLCHILDREN;
1515 if ( eraseBack )
1516 flags |= RDW_ERASE;
1517
1518 ::RedrawWindow(hWnd, pRect, NULL, flags);
480e9098 1519#else
16d652a5 1520 ::InvalidateRect(hWnd, pRect, eraseBack);
480e9098 1521#endif
42e69d6b
VZ
1522 }
1523}
a23fd0e1 1524
1e6feb95
VZ
1525void wxWindowMSW::Update()
1526{
1527 if ( !::UpdateWindow(GetHwnd()) )
1528 {
1529 wxLogLastError(_T("UpdateWindow"));
1530 }
2b5f62a0 1531
7f0586ef 1532#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1e6feb95
VZ
1533 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1534 // handler needs to be really drawn right now
1535 (void)::GdiFlush();
1536#endif // __WIN32__
1537}
1538
42e69d6b
VZ
1539// ---------------------------------------------------------------------------
1540// drag and drop
1541// ---------------------------------------------------------------------------
a23fd0e1 1542
3febc967
VZ
1543#if wxUSE_DRAG_AND_DROP || !defined(__WXWINCE__)
1544
1545#if wxUSE_STATBOX
1546
006b8dff
JG
1547// we need to lower the sibling static boxes so controls contained within can be
1548// a drop target
3febc967 1549static void AdjustStaticBoxZOrder(wxWindow *parent)
006b8dff 1550{
deb0d191
JG
1551 // no sibling static boxes if we have no parent (ie TLW)
1552 if ( !parent )
1553 return;
1554
006b8dff
JG
1555 for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
1556 node;
1557 node = node->GetNext() )
1558 {
1559 wxStaticBox *statbox = wxDynamicCast(node->GetData(), wxStaticBox);
1560 if ( statbox )
1561 {
1562 ::SetWindowPos(GetHwndOf(statbox), HWND_BOTTOM, 0, 0, 0, 0,
1563 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
1564 }
1565 }
1566}
a23fd0e1 1567
3febc967
VZ
1568#else // !wxUSE_STATBOX
1569
1570static inline void AdjustStaticBoxZOrder(wxWindow * WXUNUSED(parent))
1571{
1572}
1573
1574#endif // wxUSE_STATBOX/!wxUSE_STATBOX
1575
1576#endif // drag and drop is used
1577
4ce1efe1 1578#if wxUSE_DRAG_AND_DROP
1e6feb95 1579void wxWindowMSW::SetDropTarget(wxDropTarget *pDropTarget)
42e69d6b
VZ
1580{
1581 if ( m_dropTarget != 0 ) {
1582 m_dropTarget->Revoke(m_hWnd);
1583 delete m_dropTarget;
1584 }
a23fd0e1 1585
42e69d6b
VZ
1586 m_dropTarget = pDropTarget;
1587 if ( m_dropTarget != 0 )
006b8dff
JG
1588 {
1589 AdjustStaticBoxZOrder(GetParent());
42e69d6b 1590 m_dropTarget->Register(m_hWnd);
006b8dff 1591 }
42e69d6b 1592}
42e69d6b 1593#endif // wxUSE_DRAG_AND_DROP
2a47d3c1 1594
90e572f1 1595// old-style file manager drag&drop support: we retain the old-style
42e69d6b 1596// DragAcceptFiles in parallel with SetDropTarget.
0c0d1521 1597void wxWindowMSW::DragAcceptFiles(bool WXUNUSED_IN_WINCE(accept))
42e69d6b 1598{
0c0d1521 1599#ifndef __WXWINCE__
42e69d6b
VZ
1600 HWND hWnd = GetHwnd();
1601 if ( hWnd )
006b8dff
JG
1602 {
1603 AdjustStaticBoxZOrder(GetParent());
42e69d6b 1604 ::DragAcceptFiles(hWnd, (BOOL)accept);
006b8dff 1605 }
7f0586ef 1606#endif
42e69d6b 1607}
a23fd0e1 1608
42e69d6b
VZ
1609// ----------------------------------------------------------------------------
1610// tooltips
1611// ----------------------------------------------------------------------------
dbda9e86 1612
42e69d6b 1613#if wxUSE_TOOLTIPS
2d0a075d 1614
1e6feb95 1615void wxWindowMSW::DoSetToolTip(wxToolTip *tooltip)
42e69d6b
VZ
1616{
1617 wxWindowBase::DoSetToolTip(tooltip);
839b865d 1618
42e69d6b 1619 if ( m_tooltip )
d4e5272b 1620 m_tooltip->SetWindow((wxWindow *)this);
42e69d6b 1621}
9a05fd8d 1622
42e69d6b 1623#endif // wxUSE_TOOLTIPS
9a05fd8d 1624
42e69d6b
VZ
1625// ---------------------------------------------------------------------------
1626// moving and resizing
1627// ---------------------------------------------------------------------------
839b865d 1628
f7040b5f
VZ
1629bool wxWindowMSW::IsSizeDeferred() const
1630{
1631#if USE_DEFERRED_SIZING
1632 if ( m_pendingPosition != wxDefaultPosition ||
1633 m_pendingSize != wxDefaultSize )
1634 return true;
1635#endif // USE_DEFERRED_SIZING
1636
1637 return false;
1638}
1639
42e69d6b 1640// Get total size
1e6feb95 1641void wxWindowMSW::DoGetSize(int *x, int *y) const
42e69d6b 1642{
0d6fdb3c 1643#if USE_DEFERRED_SIZING
11cfa8ef
VZ
1644 // if SetSize() had been called at wx level but not realized at Windows
1645 // level yet (i.e. EndDeferWindowPos() not called), we still should return
1646 // the new and not the old position to the other wx code
1647 if ( m_pendingSize != wxDefaultSize )
1648 {
1649 if ( x )
1650 *x = m_pendingSize.x;
1651 if ( y )
1652 *y = m_pendingSize.y;
1653 }
1654 else // use current size
0d6fdb3c 1655#endif // USE_DEFERRED_SIZING
11cfa8ef
VZ
1656 {
1657 RECT rect = wxGetWindowRect(GetHwnd());
82c9f85c 1658
11cfa8ef
VZ
1659 if ( x )
1660 *x = rect.right - rect.left;
1661 if ( y )
1662 *y = rect.bottom - rect.top;
1663 }
42e69d6b
VZ
1664}
1665
82c9f85c
VZ
1666// Get size *available for subwindows* i.e. excluding menu bar etc.
1667void wxWindowMSW::DoGetClientSize(int *x, int *y) const
42e69d6b 1668{
f2197644 1669#if USE_DEFERRED_SIZING
0d6fdb3c 1670 if ( m_pendingSize != wxDefaultSize )
0d7f75df 1671 {
0d6fdb3c 1672 // we need to calculate the client size corresponding to pending size
dc497201
JG
1673 RECT rect;
1674 rect.left = m_pendingPosition.x;
1675 rect.top = m_pendingPosition.y;
1676 rect.right = rect.left + m_pendingSize.x;
1677 rect.bottom = rect.top + m_pendingSize.y;
1678
1679 ::SendMessage(GetHwnd(), WM_NCCALCSIZE, FALSE, (LPARAM)&rect);
1680
1681 if ( x )
1682 *x = rect.right - rect.left;
1683 if ( y )
1684 *y = rect.bottom - rect.top;
0d7f75df 1685 }
0d6fdb3c
VZ
1686 else
1687#endif // USE_DEFERRED_SIZING
1688 {
1689 RECT rect = wxGetClientRect(GetHwnd());
1690
1691 if ( x )
1692 *x = rect.right;
1693 if ( y )
1694 *y = rect.bottom;
1695 }
82c9f85c
VZ
1696}
1697
1698void wxWindowMSW::DoGetPosition(int *x, int *y) const
1699{
a7e0e432
VZ
1700 wxWindow * const parent = GetParent();
1701
1702 wxPoint pos;
11cfa8ef
VZ
1703 if ( m_pendingPosition != wxDefaultPosition )
1704 {
a7e0e432 1705 pos = m_pendingPosition;
11cfa8ef
VZ
1706 }
1707 else // use current position
1708 {
1709 RECT rect = wxGetWindowRect(GetHwnd());
42e69d6b 1710
11cfa8ef
VZ
1711 POINT point;
1712 point.x = rect.left;
1713 point.y = rect.top;
42e69d6b 1714
11cfa8ef
VZ
1715 // we do the adjustments with respect to the parent only for the "real"
1716 // children, not for the dialogs/frames
1717 if ( !IsTopLevel() )
92049cd4 1718 {
e5b5af91
VZ
1719 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
1720 {
967acfb5 1721 // In RTL mode, we want the logical left x-coordinate,
e5b5af91
VZ
1722 // which would be the physical right x-coordinate.
1723 point.x = rect.right;
1724 }
1725
11cfa8ef
VZ
1726 // Since we now have the absolute screen coords, if there's a
1727 // parent we must subtract its top left corner
11cfa8ef
VZ
1728 if ( parent )
1729 {
a7e0e432 1730 ::ScreenToClient(GetHwndOf(parent), &point);
11cfa8ef 1731 }
89e3037c 1732 }
42e69d6b 1733
a7e0e432
VZ
1734 pos.x = point.x;
1735 pos.y = point.y;
1736 }
1737
1738 // we also must adjust by the client area offset: a control which is just
1739 // under a toolbar could be at (0, 30) in Windows but at (0, 0) in wx
1740 if ( parent && !IsTopLevel() )
1741 {
1742 const wxPoint pt(parent->GetClientAreaOrigin());
1743 pos.x -= pt.x;
1744 pos.y -= pt.y;
11cfa8ef 1745 }
a7e0e432
VZ
1746
1747 if ( x )
1748 *x = pos.x;
1749 if ( y )
1750 *y = pos.y;
42e69d6b 1751}
54bdd8b0 1752
1e6feb95 1753void wxWindowMSW::DoScreenToClient(int *x, int *y) const
42e69d6b
VZ
1754{
1755 POINT pt;
1756 if ( x )
1757 pt.x = *x;
1758 if ( y )
1759 pt.y = *y;
54bdd8b0 1760
82c9f85c 1761 ::ScreenToClient(GetHwnd(), &pt);
a23fd0e1 1762
42e69d6b
VZ
1763 if ( x )
1764 *x = pt.x;
1765 if ( y )
1766 *y = pt.y;
1767}
a23fd0e1 1768
1e6feb95 1769void wxWindowMSW::DoClientToScreen(int *x, int *y) const
42e69d6b
VZ
1770{
1771 POINT pt;
1772 if ( x )
1773 pt.x = *x;
1774 if ( y )
1775 pt.y = *y;
54bdd8b0 1776
82c9f85c 1777 ::ClientToScreen(GetHwnd(), &pt);
a23fd0e1 1778
42e69d6b
VZ
1779 if ( x )
1780 *x = pt.x;
1781 if ( y )
1782 *y = pt.y;
1783}
a23fd0e1 1784
86e30911 1785bool
7d86a2d4
VZ
1786wxWindowMSW::DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height)
1787{
1788#if USE_DEFERRED_SIZING
1789 // if our parent had prepared a defer window handle for us, use it (unless
1790 // we are a top level window)
1791 wxWindowMSW * const parent = IsTopLevel() ? NULL : GetParent();
1792
1793 HDWP hdwp = parent ? (HDWP)parent->m_hDWP : NULL;
1794 if ( hdwp )
1795 {
1796 hdwp = ::DeferWindowPos(hdwp, (HWND)hwnd, NULL, x, y, width, height,
dd28827a 1797 SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
7d86a2d4
VZ
1798 if ( !hdwp )
1799 {
1800 wxLogLastError(_T("DeferWindowPos"));
1801 }
1802 }
1803
1804 if ( parent )
1805 {
1806 // hdwp must be updated as it may have been changed
1807 parent->m_hDWP = (WXHANDLE)hdwp;
1808 }
1809
86e30911
VZ
1810 if ( hdwp )
1811 {
1812 // did deferred move, remember new coordinates of the window as they're
1813 // different from what Windows would return for it
1814 return true;
1815 }
1816
7d86a2d4 1817 // otherwise (or if deferring failed) move the window in place immediately
7d86a2d4 1818#endif // USE_DEFERRED_SIZING
86e30911 1819 if ( !::MoveWindow((HWND)hwnd, x, y, width, height, IsShown()) )
7d86a2d4 1820 {
86e30911 1821 wxLogLastError(wxT("MoveWindow"));
7d86a2d4 1822 }
86e30911
VZ
1823
1824 // if USE_DEFERRED_SIZING, indicates that we didn't use deferred move,
1825 // ignored otherwise
1826 return false;
7d86a2d4
VZ
1827}
1828
1e6feb95 1829void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height)
b782f2e0 1830{
62e1ba75
JS
1831 // TODO: is this consistent with other platforms?
1832 // Still, negative width or height shouldn't be allowed
1833 if (width < 0)
1834 width = 0;
1835 if (height < 0)
1836 height = 0;
9b6ae450 1837
86e30911
VZ
1838 if ( DoMoveSibling(m_hWnd, x, y, width, height) )
1839 {
1840#if USE_DEFERRED_SIZING
1841 m_pendingPosition = wxPoint(x, y);
1842 m_pendingSize = wxSize(width, height);
1843#endif // USE_DEFERRED_SIZING
1844 }
b782f2e0
VZ
1845}
1846
4438caf4
VZ
1847// set the size of the window: if the dimensions are positive, just use them,
1848// but if any of them is equal to -1, it means that we must find the value for
1849// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1850// which case -1 is a valid value for x and y)
1851//
1852// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1853// the width/height to best suit our contents, otherwise we reuse the current
1854// width/height
1e6feb95 1855void wxWindowMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
42e69d6b 1856{
4438caf4 1857 // get the current size and position...
42e69d6b 1858 int currentX, currentY;
da78f3b1
RD
1859 int currentW, currentH;
1860
42e69d6b 1861 GetPosition(&currentX, &currentY);
42e69d6b 1862 GetSize(&currentW, &currentH);
a23fd0e1 1863
952f2aaa
VZ
1864 // ... and don't do anything (avoiding flicker) if it's already ok unless
1865 // we're forced to resize the window
4438caf4 1866 if ( x == currentX && y == currentY &&
952f2aaa
VZ
1867 width == currentW && height == currentH &&
1868 !(sizeFlags & wxSIZE_FORCE) )
4438caf4 1869 {
42e69d6b 1870 return;
4438caf4 1871 }
a23fd0e1 1872
422d0ff0 1873 if ( x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
4438caf4 1874 x = currentX;
422d0ff0 1875 if ( y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
4438caf4 1876 y = currentY;
a23fd0e1 1877
4438caf4 1878 AdjustForParentClientOrigin(x, y, sizeFlags);
a23fd0e1 1879
abb74e0f 1880 wxSize size = wxDefaultSize;
422d0ff0 1881 if ( width == wxDefaultCoord )
4438caf4 1882 {
9e2896e5 1883 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
4438caf4
VZ
1884 {
1885 size = DoGetBestSize();
1886 width = size.x;
1887 }
1888 else
1889 {
1890 // just take the current one
1891 width = currentW;
1892 }
1893 }
1894
422d0ff0 1895 if ( height == wxDefaultCoord )
4438caf4 1896 {
9e2896e5 1897 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
4438caf4 1898 {
422d0ff0 1899 if ( size.x == wxDefaultCoord )
4438caf4 1900 {
b782f2e0 1901 size = DoGetBestSize();
4438caf4
VZ
1902 }
1903 //else: already called DoGetBestSize() above
a23fd0e1 1904
4438caf4
VZ
1905 height = size.y;
1906 }
1907 else
1908 {
1909 // just take the current one
1910 height = currentH;
1911 }
1912 }
1913
b782f2e0 1914 DoMoveWindow(x, y, width, height);
4438caf4
VZ
1915}
1916
1e6feb95 1917void wxWindowMSW::DoSetClientSize(int width, int height)
42e69d6b 1918{
90e572f1 1919 // setting the client size is less obvious than it could have been
d4597e13 1920 // because in the result of changing the total size the window scrollbar
c72b1ad7
VZ
1921 // may [dis]appear and/or its menubar may [un]wrap (and AdjustWindowRect()
1922 // doesn't take neither into account) and so the client size will not be
1923 // correct as the difference between the total and client size changes --
1924 // so we keep changing it until we get it right
d4597e13 1925 //
d6a97306
VZ
1926 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1927 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1928 // may become 3 if the window had 0 size originally and so we didn't
1929 // calculate the scrollbar correction correctly during the first iteration)
1930 // but just to be on the safe side we check for it instead of making it an
d4597e13 1931 // "infinite" loop (i.e. leaving break inside as the only way to get out)
d6a97306 1932 for ( int i = 0; i < 4; i++ )
d4597e13
VZ
1933 {
1934 RECT rectClient;
1935 ::GetClientRect(GetHwnd(), &rectClient);
2bda0e17 1936
b0268daf 1937 // if the size is already ok, stop here (NB: rectClient.left = top = 0)
422d0ff0
WS
1938 if ( (rectClient.right == width || width == wxDefaultCoord) &&
1939 (rectClient.bottom == height || height == wxDefaultCoord) )
d4597e13
VZ
1940 {
1941 break;
1942 }
a23fd0e1 1943
d4597e13
VZ
1944 // Find the difference between the entire window (title bar and all)
1945 // and the client area; add this to the new client size to move the
1946 // window
1947 RECT rectWin;
1948 ::GetWindowRect(GetHwnd(), &rectWin);
1949
b0268daf
VZ
1950 const int widthWin = rectWin.right - rectWin.left,
1951 heightWin = rectWin.bottom - rectWin.top;
387a3b02 1952
d4597e13
VZ
1953 // MoveWindow positions the child windows relative to the parent, so
1954 // adjust if necessary
1955 if ( !IsTopLevel() )
1956 {
1957 wxWindow *parent = GetParent();
1958 if ( parent )
1959 {
b0268daf 1960 ::ScreenToClient(GetHwndOf(parent), (POINT *)&rectWin);
d4597e13
VZ
1961 }
1962 }
a23fd0e1 1963
b0268daf 1964 // don't call DoMoveWindow() because we want to move window immediately
c72b1ad7
VZ
1965 // and not defer it here as otherwise the value returned by
1966 // GetClient/WindowRect() wouldn't change as the window wouldn't be
1967 // really resized
b0268daf
VZ
1968 if ( !::MoveWindow(GetHwnd(),
1969 rectWin.left,
1970 rectWin.top,
1971 width + widthWin - rectClient.right,
1972 height + heightWin - rectClient.bottom,
1973 TRUE) )
1974 {
1975 wxLogLastError(_T("MoveWindow"));
1976 }
d4597e13 1977 }
42e69d6b 1978}
a23fd0e1 1979
42e69d6b
VZ
1980// ---------------------------------------------------------------------------
1981// text metrics
1982// ---------------------------------------------------------------------------
a23fd0e1 1983
1e6feb95 1984int wxWindowMSW::GetCharHeight() const
42e69d6b 1985{
f6bcfd97 1986 return wxGetTextMetrics(this).tmHeight;
42e69d6b 1987}
3eddf563 1988
1e6feb95 1989int wxWindowMSW::GetCharWidth() const
42e69d6b 1990{
f6bcfd97
BP
1991 // +1 is needed because Windows apparently adds it when calculating the
1992 // dialog units size in pixels
1993#if wxDIALOG_UNIT_COMPATIBILITY
1e6feb95 1994 return wxGetTextMetrics(this).tmAveCharWidth;
f6bcfd97
BP
1995#else
1996 return wxGetTextMetrics(this).tmAveCharWidth + 1;
1997#endif
42e69d6b 1998}
f4621a09 1999
1e6feb95 2000void wxWindowMSW::GetTextExtent(const wxString& string,
34636400 2001 int *x, int *y,
42e69d6b
VZ
2002 int *descent, int *externalLeading,
2003 const wxFont *theFont) const
2004{
64869ab7
VZ
2005 wxASSERT_MSG( !theFont || theFont->Ok(),
2006 _T("invalid font in GetTextExtent()") );
634903fd 2007
2d17baae
VS
2008 wxFont fontToUse;
2009 if (theFont)
2010 fontToUse = *theFont;
2011 else
2012 fontToUse = GetFont();
634903fd 2013
64869ab7
VZ
2014 WindowHDC hdc(GetHwnd());
2015 SelectInHDC selectFont(hdc, GetHfontOf(fontToUse));
341c92a8 2016
42e69d6b
VZ
2017 SIZE sizeRect;
2018 TEXTMETRIC tm;
767b35a5 2019 ::GetTextExtentPoint32(hdc, string, string.length(), &sizeRect);
64869ab7 2020 GetTextMetrics(hdc, &tm);
42e69d6b 2021
0655ad29
VZ
2022 if ( x )
2023 *x = sizeRect.cx;
2024 if ( y )
2025 *y = sizeRect.cy;
2026 if ( descent )
2027 *descent = tm.tmDescent;
2028 if ( externalLeading )
2029 *externalLeading = tm.tmExternalLeading;
2bda0e17
KB
2030}
2031
c50f1fb9
VZ
2032// ---------------------------------------------------------------------------
2033// popup menu
2034// ---------------------------------------------------------------------------
2035
2e9f62da
VZ
2036#if wxUSE_MENUS_NATIVE
2037
ed45e263
VZ
2038// yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
2039// immediately, without waiting for the next event loop iteration
2040//
2041// NB: this function should probably be made public later as it can almost
2042// surely replace wxYield() elsewhere as well
2043static void wxYieldForCommandsOnly()
2044{
2045 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
2046 // want to process it here)
2047 MSG msg;
1bf77ee5 2048 while ( ::PeekMessage(&msg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE) )
ed45e263 2049 {
dd7ebf8b 2050 if ( msg.message == WM_QUIT )
1bf77ee5
VZ
2051 {
2052 // if we retrieved a WM_QUIT, insert back into the message queue.
2053 ::PostQuitMessage(0);
2054 break;
2055 }
7de59551 2056
1bf77ee5
VZ
2057 // luckily (as we don't have access to wxEventLoopImpl method from here
2058 // anyhow...) we don't need to pre process WM_COMMANDs so dispatch it
2059 // immediately
2060 ::TranslateMessage(&msg);
2061 ::DispatchMessage(&msg);
2062 }
ed45e263
VZ
2063}
2064
1e6feb95 2065bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y)
c50f1fb9
VZ
2066{
2067 menu->SetInvokingWindow(this);
2068 menu->UpdateUI();
2069
27d2dbbc 2070 if ( x == wxDefaultCoord && y == wxDefaultCoord )
971562cb
VS
2071 {
2072 wxPoint mouse = ScreenToClient(wxGetMousePosition());
2073 x = mouse.x; y = mouse.y;
2074 }
2075
c50f1fb9
VZ
2076 HWND hWnd = GetHwnd();
2077 HMENU hMenu = GetHmenuOf(menu);
2078 POINT point;
2079 point.x = x;
2080 point.y = y;
2081 ::ClientToScreen(hWnd, &point);
2082 wxCurrentPopupMenu = menu;
5cb598ae 2083#if defined(__WXWINCE__)
7f0586ef 2084 UINT flags = 0;
5cb598ae 2085#else
114c220f 2086 UINT flags = TPM_RIGHTBUTTON | TPM_RECURSE;
7f0586ef
JS
2087#endif
2088 ::TrackPopupMenu(hMenu, flags, point.x, point.y, 0, hWnd, NULL);
ed45e263 2089
90e572f1 2090 // we need to do it right now as otherwise the events are never going to be
ed45e263
VZ
2091 // sent to wxCurrentPopupMenu from HandleCommand()
2092 //
2093 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
2094 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
2095 // destroyed as soon as we return (it can be a local variable in the caller
2096 // for example) and so we do need to process the event immediately
2097 wxYieldForCommandsOnly();
2098
c50f1fb9
VZ
2099 wxCurrentPopupMenu = NULL;
2100
2101 menu->SetInvokingWindow(NULL);
2102
08158721 2103 return true;
c50f1fb9
VZ
2104}
2105
1e6feb95
VZ
2106#endif // wxUSE_MENUS_NATIVE
2107
42e69d6b
VZ
2108// ===========================================================================
2109// pre/post message processing
2110// ===========================================================================
2bda0e17 2111
c140b7e7 2112WXLRESULT wxWindowMSW::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
42e69d6b
VZ
2113{
2114 if ( m_oldWndProc )
2115 return ::CallWindowProc(CASTWNDPROC m_oldWndProc, GetHwnd(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
2116 else
2117 return ::DefWindowProc(GetHwnd(), nMsg, wParam, lParam);
2118}
2bda0e17 2119
1e6feb95 2120bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
42e69d6b 2121{
1e6feb95
VZ
2122 // wxUniversal implements tab traversal itself
2123#ifndef __WXUNIVERSAL__
42e69d6b 2124 if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) )
2d0a075d 2125 {
42e69d6b
VZ
2126 // intercept dialog navigation keys
2127 MSG *msg = (MSG *)pMsg;
d9317fd4
VZ
2128
2129 // here we try to do all the job which ::IsDialogMessage() usually does
2130 // internally
573a1586 2131 if ( msg->message == WM_KEYDOWN )
42e69d6b 2132 {
3f7bc32b
VZ
2133 bool bCtrlDown = wxIsCtrlDown();
2134 bool bShiftDown = wxIsShiftDown();
a23fd0e1 2135
42e69d6b
VZ
2136 // WM_GETDLGCODE: ask the control if it wants the key for itself,
2137 // don't process it if it's the case (except for Ctrl-Tab/Enter
2138 // combinations which are always processed)
977f50f3
VZ
2139 LONG lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0);
2140
2141 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
2142 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
2143 // it, of course, implies them
2144 if ( lDlgCode & DLGC_WANTALLKEYS )
42e69d6b 2145 {
977f50f3 2146 lDlgCode |= DLGC_WANTTAB | DLGC_WANTARROWS;
42e69d6b 2147 }
a23fd0e1 2148
08158721 2149 bool bForward = true,
298ca00c
VZ
2150 bWindowChange = false,
2151 bFromTab = false;
a23fd0e1 2152
573a1586 2153 // should we process this message specially?
08158721 2154 bool bProcess = true;
9145664b 2155 switch ( msg->wParam )
42e69d6b
VZ
2156 {
2157 case VK_TAB:
7cc44669
VZ
2158 if ( (lDlgCode & DLGC_WANTTAB) && !bCtrlDown )
2159 {
2160 // let the control have the TAB
08158721 2161 bProcess = false;
42e69d6b 2162 }
7cc44669
VZ
2163 else // use it for navigation
2164 {
42e69d6b
VZ
2165 // Ctrl-Tab cycles thru notebook pages
2166 bWindowChange = bCtrlDown;
319fefa9 2167 bForward = !bShiftDown;
298ca00c 2168 bFromTab = true;
42e69d6b
VZ
2169 }
2170 break;
a23fd0e1 2171
42e69d6b
VZ
2172 case VK_UP:
2173 case VK_LEFT:
2174 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
08158721 2175 bProcess = false;
42e69d6b 2176 else
08158721 2177 bForward = false;
42e69d6b 2178 break;
a02eb1d2 2179
42e69d6b
VZ
2180 case VK_DOWN:
2181 case VK_RIGHT:
2182 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
08158721 2183 bProcess = false;
42e69d6b 2184 break;
2bda0e17 2185
efe5e221
VZ
2186 case VK_PRIOR:
2187 bForward = false;
2188 // fall through
2189
2190 case VK_NEXT:
2191 // we treat PageUp/Dn as arrows because chances are that
2192 // a control which needs arrows also needs them for
2193 // navigation (e.g. wxTextCtrl, wxListCtrl, ...)
ada5f90d 2194 if ( (lDlgCode & DLGC_WANTARROWS) && !bCtrlDown )
efe5e221 2195 bProcess = false;
ada5f90d 2196 else // OTOH Ctrl-PageUp/Dn works as [Shift-]Ctrl-Tab
efe5e221
VZ
2197 bWindowChange = true;
2198 break;
2199
42e69d6b
VZ
2200 case VK_RETURN:
2201 {
edccf428 2202 if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown )
42e69d6b
VZ
2203 {
2204 // control wants to process Enter itself, don't
90c6edd7 2205 // call IsDialogMessage() which would consume it
08158721 2206 return false;
42e69d6b 2207 }
3147bb58 2208
90c6edd7 2209#if wxUSE_BUTTON
3147bb58 2210 // currently active button should get enter press even
90c6edd7
VZ
2211 // if there is a default button elsewhere so check if
2212 // this window is a button first
2213 wxWindow *btn = NULL;
3147bb58 2214 if ( lDlgCode & DLGC_DEFPUSHBUTTON )
319fefa9 2215 {
3e79ed96
VZ
2216 // let IsDialogMessage() handle this for all
2217 // buttons except the owner-drawn ones which it
2218 // just seems to ignore
2219 long style = ::GetWindowLong(msg->hwnd, GWL_STYLE);
2220 if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW )
2221 {
2222 // emulate the button click
90c6edd7 2223 btn = wxFindWinFromHandle((WXHWND)msg->hwnd);
3e79ed96
VZ
2224 }
2225
08158721 2226 bProcess = false;
319fefa9 2227 }
90c6edd7 2228 else // not a button itself, do we have default button?
c50f1fb9 2229 {
90c6edd7
VZ
2230 wxTopLevelWindow *
2231 tlw = wxDynamicCast(wxGetTopLevelParent(this),
2232 wxTopLevelWindow);
6c20e8f8 2233 if ( tlw )
c50f1fb9 2234 {
90c6edd7
VZ
2235 btn = wxDynamicCast(tlw->GetDefaultItem(),
2236 wxButton);
c50f1fb9 2237 }
90c6edd7
VZ
2238 }
2239
2240 if ( btn && btn->IsEnabled() )
2241 {
2242 btn->MSWCommand(BN_CLICKED, 0 /* unused */);
2243 return true;
2244 }
2245
1e6feb95 2246#endif // wxUSE_BUTTON
90c6edd7 2247
7b504551 2248#ifdef __WXWINCE__
90c6edd7
VZ
2249 // map Enter presses into button presses on PDAs
2250 wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN);
2251 event.SetEventObject(this);
2252 if ( GetEventHandler()->ProcessEvent(event) )
2253 return true;
2254#endif // __WXWINCE__
42e69d6b
VZ
2255 }
2256 break;
2bda0e17 2257
42e69d6b 2258 default:
08158721 2259 bProcess = false;
42e69d6b 2260 }
2bda0e17 2261
42e69d6b
VZ
2262 if ( bProcess )
2263 {
2264 wxNavigationKeyEvent event;
2265 event.SetDirection(bForward);
2266 event.SetWindowChange(bWindowChange);
298ca00c 2267 event.SetFromTab(bFromTab);
42e69d6b 2268 event.SetEventObject(this);
3572173c 2269
42e69d6b 2270 if ( GetEventHandler()->ProcessEvent(event) )
57c0af52 2271 {
d7e0024b
VZ
2272 // as we don't call IsDialogMessage(), which would take of
2273 // this by default, we need to manually send this message
1ca78aa1
JS
2274 // so that controls can change their UI state if needed
2275 MSWUpdateUIState(UIS_CLEAR, UISF_HIDEFOCUS);
d7e0024b 2276
08158721 2277 return true;
57c0af52 2278 }
42e69d6b
VZ
2279 }
2280 }
a23fd0e1 2281
98ebf919 2282 if ( ::IsDialogMessage(GetHwnd(), msg) )
f6bcfd97 2283 {
98ebf919
VZ
2284 // IsDialogMessage() did something...
2285 return true;
f6bcfd97 2286 }
42e69d6b 2287 }
1e6feb95 2288#endif // __WXUNIVERSAL__
a23fd0e1 2289
42e69d6b
VZ
2290#if wxUSE_TOOLTIPS
2291 if ( m_tooltip )
387a3b02 2292 {
42e69d6b
VZ
2293 // relay mouse move events to the tooltip control
2294 MSG *msg = (MSG *)pMsg;
2295 if ( msg->message == WM_MOUSEMOVE )
259a4264 2296 wxToolTip::RelayEvent(pMsg);
387a3b02 2297 }
42e69d6b 2298#endif // wxUSE_TOOLTIPS
a23fd0e1 2299
08158721 2300 return false;
387a3b02
JS
2301}
2302
1e6feb95 2303bool wxWindowMSW::MSWTranslateMessage(WXMSG* pMsg)
387a3b02 2304{
1e6feb95 2305#if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
c50f1fb9 2306 return m_acceleratorTable.Translate(this, pMsg);
1e6feb95 2307#else
574c939e 2308 (void) pMsg;
08158721 2309 return false;
1e6feb95 2310#endif // wxUSE_ACCEL
387a3b02
JS
2311}
2312
98ebf919 2313bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG* msg)
a37d422a 2314{
98ebf919
VZ
2315 // all tests below have to deal with various bugs/misfeatures of
2316 // IsDialogMessage(): we have to prevent it from being called from our
2317 // MSWProcessMessage() in some situations
2318
2319 // don't let IsDialogMessage() get VK_ESCAPE as it _always_ eats the
2320 // message even when there is no cancel button and when the message is
2321 // needed by the control itself: in particular, it prevents the tree in
2322 // place edit control from being closed with Escape in a dialog
2323 if ( msg->message == WM_KEYDOWN && msg->wParam == VK_ESCAPE )
2324 {
2325 return false;
2326 }
2327
2328 // ::IsDialogMessage() is broken and may sometimes hang the application by
2329 // going into an infinite loop when it tries to find the control to give
2330 // focus to when Alt-<key> is pressed, so we try to detect [some of] the
2331 // situations when this may happen and not call it then
2332 if ( msg->message != WM_SYSCHAR )
2333 return true;
2334
2335 // assume we can call it by default
2336 bool canSafelyCallIsDlgMsg = true;
2337
2338 HWND hwndFocus = ::GetFocus();
2339
2340 // if the currently focused window itself has WS_EX_CONTROLPARENT style,
2341 // ::IsDialogMessage() will also enter an infinite loop, because it will
2342 // recursively check the child windows but not the window itself and so if
2343 // none of the children accepts focus it loops forever (as it only stops
2344 // when it gets back to the window it started from)
2345 //
2346 // while it is very unusual that a window with WS_EX_CONTROLPARENT
2347 // style has the focus, it can happen. One such possibility is if
2348 // all windows are either toplevel, wxDialog, wxPanel or static
2349 // controls and no window can actually accept keyboard input.
2350#if !defined(__WXWINCE__)
2351 if ( ::GetWindowLong(hwndFocus, GWL_EXSTYLE) & WS_EX_CONTROLPARENT )
2352 {
2353 // pessimistic by default
2354 canSafelyCallIsDlgMsg = false;
2355 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
2356 node;
2357 node = node->GetNext() )
2358 {
2359 wxWindow * const win = node->GetData();
2360 if ( win->AcceptsFocus() &&
2361 !(::GetWindowLong(GetHwndOf(win), GWL_EXSTYLE) &
2362 WS_EX_CONTROLPARENT) )
2363 {
2364 // it shouldn't hang...
2365 canSafelyCallIsDlgMsg = true;
2366
2367 break;
2368 }
2369 }
2370 }
2371#endif // !__WXWINCE__
2372
2373 if ( canSafelyCallIsDlgMsg )
2374 {
2375 // ::IsDialogMessage() can enter in an infinite loop when the
2376 // currently focused window is disabled or hidden and its
2377 // parent has WS_EX_CONTROLPARENT style, so don't call it in
2378 // this case
2379 while ( hwndFocus )
2380 {
2381 if ( !::IsWindowEnabled(hwndFocus) ||
2382 !::IsWindowVisible(hwndFocus) )
2383 {
2384 // it would enter an infinite loop if we do this!
2385 canSafelyCallIsDlgMsg = false;
2386
2387 break;
2388 }
2389
2390 if ( !(::GetWindowLong(hwndFocus, GWL_STYLE) & WS_CHILD) )
2391 {
2392 // it's a top level window, don't go further -- e.g. even
2393 // if the parent of a dialog is disabled, this doesn't
2394 // break navigation inside the dialog
2395 break;
2396 }
2397
2398 hwndFocus = ::GetParent(hwndFocus);
2399 }
2400 }
2401
2402 return canSafelyCallIsDlgMsg;
a37d422a
VZ
2403}
2404
42e69d6b 2405// ---------------------------------------------------------------------------
e39af974 2406// message params unpackers
42e69d6b 2407// ---------------------------------------------------------------------------
2bda0e17 2408
1e6feb95 2409void wxWindowMSW::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b
VZ
2410 WORD *id, WXHWND *hwnd, WORD *cmd)
2411{
2412 *id = LOWORD(wParam);
2413 *hwnd = (WXHWND)lParam;
2414 *cmd = HIWORD(wParam);
2bda0e17
KB
2415}
2416
1e6feb95 2417void wxWindowMSW::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b 2418 WXWORD *state, WXWORD *minimized, WXHWND *hwnd)
2bda0e17 2419{
42e69d6b
VZ
2420 *state = LOWORD(wParam);
2421 *minimized = HIWORD(wParam);
2422 *hwnd = (WXHWND)lParam;
2bda0e17
KB
2423}
2424
1e6feb95 2425void wxWindowMSW::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b 2426 WXWORD *code, WXWORD *pos, WXHWND *hwnd)
2bda0e17 2427{
42e69d6b
VZ
2428 *code = LOWORD(wParam);
2429 *pos = HIWORD(wParam);
2430 *hwnd = (WXHWND)lParam;
2431}
a23fd0e1 2432
1e6feb95 2433void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
01c500af 2434 WXHDC *hdc, WXHWND *hwnd)
42e69d6b 2435{
42e69d6b
VZ
2436 *hwnd = (WXHWND)lParam;
2437 *hdc = (WXHDC)wParam;
2bda0e17
KB
2438}
2439
1e6feb95 2440void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b 2441 WXWORD *item, WXWORD *flags, WXHMENU *hmenu)
2bda0e17 2442{
42e69d6b
VZ
2443 *item = (WXWORD)wParam;
2444 *flags = HIWORD(wParam);
2445 *hmenu = (WXHMENU)lParam;
2446}
c085e333 2447
42e69d6b 2448// ---------------------------------------------------------------------------
77ffb593 2449// Main wxWidgets window proc and the window proc for wxWindow
42e69d6b 2450// ---------------------------------------------------------------------------
2bda0e17 2451
42e69d6b
VZ
2452// Hook for new window just as it's being created, when the window isn't yet
2453// associated with the handle
b225f659
VZ
2454static wxWindowMSW *gs_winBeingCreated = NULL;
2455
2456// implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2457// window being created and insures that it's always unset back later
2458wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW *winBeingCreated)
2459{
2460 gs_winBeingCreated = winBeingCreated;
2461}
2462
2463wxWindowCreationHook::~wxWindowCreationHook()
2464{
2465 gs_winBeingCreated = NULL;
2466}
42e69d6b
VZ
2467
2468// Main window proc
3135f4a7 2469LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
2bda0e17 2470{
42e69d6b
VZ
2471 // trace all messages - useful for the debugging
2472#ifdef __WXDEBUG__
13e4c4d9
VZ
2473 wxLogTrace(wxTraceMessages,
2474 wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
2475 wxGetMessageName(message), (long)hWnd, (long)wParam, lParam);
42e69d6b 2476#endif // __WXDEBUG__
2bda0e17 2477
1e6feb95 2478 wxWindowMSW *wnd = wxFindWinFromHandle((WXHWND) hWnd);
c085e333 2479
42e69d6b 2480 // when we get the first message for the HWND we just created, we associate
b225f659
VZ
2481 // it with wxWindow stored in gs_winBeingCreated
2482 if ( !wnd && gs_winBeingCreated )
2d0a075d 2483 {
b225f659
VZ
2484 wxAssociateWinWithHandle(hWnd, gs_winBeingCreated);
2485 wnd = gs_winBeingCreated;
2486 gs_winBeingCreated = NULL;
42e69d6b 2487 wnd->SetHWND((WXHWND)hWnd);
2d0a075d 2488 }
2bda0e17 2489
42e69d6b 2490 LRESULT rc;
a23fd0e1 2491
a3dc1da9 2492 if ( wnd && wxEventLoop::AllowProcessing(wnd) )
b225f659 2493 rc = wnd->MSWWindowProc(message, wParam, lParam);
a23fd0e1 2494 else
b225f659 2495 rc = ::DefWindowProc(hWnd, message, wParam, lParam);
2bda0e17 2496
42e69d6b 2497 return rc;
f7bd2698
JS
2498}
2499
c140b7e7 2500WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
f7bd2698 2501{
42e69d6b 2502 // did we process the message?
08158721 2503 bool processed = false;
f7bd2698 2504
42e69d6b
VZ
2505 // the return value
2506 union
2bda0e17 2507 {
42e69d6b 2508 bool allow;
c140b7e7 2509 WXLRESULT result;
42e69d6b
VZ
2510 WXHBRUSH hBrush;
2511 } rc;
2bda0e17 2512
42e69d6b
VZ
2513 // for most messages we should return 0 when we do process the message
2514 rc.result = 0;
2bda0e17 2515
42e69d6b 2516 switch ( message )
39136494 2517 {
42e69d6b
VZ
2518 case WM_CREATE:
2519 {
2520 bool mayCreate;
2521 processed = HandleCreate((WXLPCREATESTRUCT)lParam, &mayCreate);
2522 if ( processed )
2523 {
2524 // return 0 to allow window creation
2525 rc.result = mayCreate ? 0 : -1;
2526 }
2527 }
2528 break;
47cbd6da 2529
42e69d6b 2530 case WM_DESTROY:
08158721 2531 // never set processed to true and *always* pass WM_DESTROY to
ad4297f3
VZ
2532 // DefWindowProc() as Windows may do some internal cleanup when
2533 // processing it and failing to pass the message along may cause
2534 // memory and resource leaks!
2535 (void)HandleDestroy();
42e69d6b
VZ
2536 break;
2537
9b6ae450
VZ
2538 case WM_SIZE:
2539 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
9b6ae450
VZ
2540 break;
2541
42e69d6b 2542 case WM_MOVE:
132cb640 2543 processed = HandleMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
42e69d6b 2544 break;
47cbd6da 2545
7f0586ef 2546#if !defined(__WXWINCE__)
5706de1c 2547 case WM_MOVING:
540b6b09
VZ
2548 {
2549 LPRECT pRect = (LPRECT)lParam;
2550 wxRect rc;
2551 rc.SetLeft(pRect->left);
2552 rc.SetTop(pRect->top);
2553 rc.SetRight(pRect->right);
2554 rc.SetBottom(pRect->bottom);
2555 processed = HandleMoving(rc);
2556 if (processed) {
2557 pRect->left = rc.GetLeft();
2558 pRect->top = rc.GetTop();
2559 pRect->right = rc.GetRight();
2560 pRect->bottom = rc.GetBottom();
2561 }
2562 }
5706de1c
JS
2563 break;
2564
5706de1c
JS
2565 case WM_SIZING:
2566 {
2567 LPRECT pRect = (LPRECT)lParam;
2568 wxRect rc;
2569 rc.SetLeft(pRect->left);
2570 rc.SetTop(pRect->top);
2571 rc.SetRight(pRect->right);
2572 rc.SetBottom(pRect->bottom);
2573 processed = HandleSizing(rc);
2574 if (processed) {
2575 pRect->left = rc.GetLeft();
2576 pRect->top = rc.GetTop();
2577 pRect->right = rc.GetRight();
2578 pRect->bottom = rc.GetBottom();
2579 }
2580 }
2581 break;
9b6ae450 2582#endif // !__WXWINCE__
5706de1c 2583
7f0586ef 2584#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1e6feb95 2585 case WM_ACTIVATEAPP:
afafd942 2586 // This implicitly sends a wxEVT_ACTIVATE_APP event
1e6feb95 2587 wxTheApp->SetActive(wParam != 0, FindFocus());
42e69d6b 2588 break;
8a46f9b1 2589#endif
47cbd6da 2590
42e69d6b 2591 case WM_ACTIVATE:
341c92a8 2592 {
42e69d6b
VZ
2593 WXWORD state, minimized;
2594 WXHWND hwnd;
2595 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
2596
2597 processed = HandleActivate(state, minimized != 0, (WXHWND)hwnd);
341c92a8 2598 }
42e69d6b 2599 break;
341c92a8 2600
42e69d6b
VZ
2601 case WM_SETFOCUS:
2602 processed = HandleSetFocus((WXHWND)(HWND)wParam);
2603 break;
47cbd6da 2604
42e69d6b
VZ
2605 case WM_KILLFOCUS:
2606 processed = HandleKillFocus((WXHWND)(HWND)wParam);
2607 break;
47cbd6da 2608
c3732409 2609 case WM_PRINTCLIENT:
1a784dfc 2610 processed = HandlePrintClient((WXHDC)wParam);
07c19327
VZ
2611 break;
2612
c3732409
VZ
2613 case WM_PAINT:
2614 if ( wParam )
5c6c3176 2615 {
5c6c3176 2616 wxPaintDCEx dc((wxWindow *)this, (WXHDC)wParam);
07c19327 2617
5c6c3176
RD
2618 processed = HandlePaint();
2619 }
c3732409
VZ
2620 else // no DC given
2621 {
2622 processed = HandlePaint();
2623 }
5c6c3176
RD
2624 break;
2625
42e69d6b 2626 case WM_CLOSE:
9fd9e47a
JS
2627#ifdef __WXUNIVERSAL__
2628 // Universal uses its own wxFrame/wxDialog, so we don't receive
2629 // close events unless we have this.
2630 Close();
c3732409
VZ
2631#endif // __WXUNIVERSAL__
2632
42e69d6b
VZ
2633 // don't let the DefWindowProc() destroy our window - we'll do it
2634 // ourselves in ~wxWindow
08158721 2635 processed = true;
42e69d6b
VZ
2636 rc.result = TRUE;
2637 break;
47cbd6da 2638
42e69d6b
VZ
2639 case WM_SHOWWINDOW:
2640 processed = HandleShow(wParam != 0, (int)lParam);
2641 break;
3a19e16d 2642
42e69d6b 2643 case WM_MOUSEMOVE:
132cb640
VZ
2644 processed = HandleMouseMove(GET_X_LPARAM(lParam),
2645 GET_Y_LPARAM(lParam),
2646 wParam);
2647 break;
0d0512bd 2648
4e5c6c33 2649#ifdef HAVE_TRACKMOUSEEVENT
e5297b7f 2650 case WM_MOUSELEAVE:
aafb9978
VZ
2651 // filter out excess WM_MOUSELEAVE events sent after PopupMenu()
2652 // (on XP at least)
4e5c6c33 2653 if ( m_mouseInWindow )
e5297b7f 2654 {
4e5c6c33 2655 GenerateMouseLeave();
e5297b7f 2656 }
4e5c6c33
VZ
2657
2658 // always pass processed back as false, this allows the window
2659 // manager to process the message too. This is needed to
2660 // ensure windows XP themes work properly as the mouse moves
2661 // over widgets like buttons. So don't set processed to true here.
51e4e266 2662 break;
4e5c6c33 2663#endif // HAVE_TRACKMOUSEEVENT
35bbb0c6 2664
d2c52078
RD
2665#if wxUSE_MOUSEWHEEL
2666 case WM_MOUSEWHEEL:
2667 processed = HandleMouseWheel(wParam, lParam);
2668 break;
2669#endif
2670
42e69d6b
VZ
2671 case WM_LBUTTONDOWN:
2672 case WM_LBUTTONUP:
2673 case WM_LBUTTONDBLCLK:
2674 case WM_RBUTTONDOWN:
2675 case WM_RBUTTONUP:
2676 case WM_RBUTTONDBLCLK:
2677 case WM_MBUTTONDOWN:
2678 case WM_MBUTTONUP:
2679 case WM_MBUTTONDBLCLK:
dfafa702 2680 {
98363307 2681#ifdef __WXMICROWIN__
cd4453e5
VZ
2682 // MicroWindows seems to ignore the fact that a window is
2683 // disabled. So catch mouse events and throw them away if
2684 // necessary.
d0a3d109 2685 wxWindowMSW* win = this;
dfafa702 2686 for ( ;; )
d0a3d109
VZ
2687 {
2688 if (!win->IsEnabled())
2689 {
08158721 2690 processed = true;
d0a3d109
VZ
2691 break;
2692 }
dfafa702 2693
d0a3d109 2694 win = win->GetParent();
dfafa702 2695 if ( !win || win->IsTopLevel() )
d0a3d109
VZ
2696 break;
2697 }
dfafa702 2698
03e0b2b1
VZ
2699 if ( processed )
2700 break;
2701
dfafa702 2702#endif // __WXMICROWIN__
03e0b2b1
VZ
2703 int x = GET_X_LPARAM(lParam),
2704 y = GET_Y_LPARAM(lParam);
dfafa702 2705
42b1fb63 2706#ifdef __WXWINCE__
03e0b2b1 2707 // redirect the event to a static control if necessary by
42b1fb63
VZ
2708 // finding one under mouse because under CE the static controls
2709 // don't generate mouse events (even with SS_NOTIFY)
03e0b2b1
VZ
2710 wxWindowMSW *win;
2711 if ( GetCapture() == this )
2712 {
2713 // but don't do it if the mouse is captured by this window
2714 // because then it should really get this event itself
2715 win = this;
d0a3d109 2716 }
03e0b2b1
VZ
2717 else
2718 {
2719 win = FindWindowForMouseEvent(this, &x, &y);
2b5f62a0
VZ
2720
2721 // this should never happen
2722 wxCHECK_MSG( win, 0,
2723 _T("FindWindowForMouseEvent() returned NULL") );
9f011847 2724 }
7d4f65e3
JS
2725#ifdef __POCKETPC__
2726 if (IsContextMenuEnabled() && message == WM_LBUTTONDOWN)
2727 {
2728 SHRGINFO shrgi = {0};
faa94f3e 2729
7d4f65e3
JS
2730 shrgi.cbSize = sizeof(SHRGINFO);
2731 shrgi.hwndClient = (HWND) GetHWND();
2732 shrgi.ptDown.x = x;
2733 shrgi.ptDown.y = y;
faa94f3e 2734
7d4f65e3
JS
2735 shrgi.dwFlags = SHRG_RETURNCMD;
2736 // shrgi.dwFlags = SHRG_NOTIFYPARENT;
faa94f3e 2737
7d4f65e3
JS
2738 if (GN_CONTEXTMENU == ::SHRecognizeGesture(&shrgi))
2739 {
2740 wxPoint pt(x, y);
2741 pt = ClientToScreen(pt);
faa94f3e 2742
7d4f65e3 2743 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt);
faa94f3e 2744
7d4f65e3
JS
2745 evtCtx.SetEventObject(this);
2746 if (GetEventHandler()->ProcessEvent(evtCtx))
f350d4b2 2747 {
7d4f65e3 2748 processed = true;
f350d4b2
JS
2749 return true;
2750 }
7d4f65e3
JS
2751 }
2752 }
2753#endif
2754
42b1fb63
VZ
2755#else // !__WXWINCE__
2756 wxWindowMSW *win = this;
2757#endif // __WXWINCE__/!__WXWINCE__
9f011847
VZ
2758
2759 processed = win->HandleMouseEvent(message, x, y, wParam);
2b5f62a0 2760
9f011847
VZ
2761 // if the app didn't eat the event, handle it in the default
2762 // way, that is by giving this window the focus
2763 if ( !processed )
2764 {
2b5f62a0
VZ
2765 // for the standard classes their WndProc sets the focus to
2766 // them anyhow and doing it from here results in some weird
9f011847 2767 // problems, so don't do it for them (unnecessary anyhow)
2b5f62a0
VZ
2768 if ( !win->IsOfStandardClass() )
2769 {
2770 if ( message == WM_LBUTTONDOWN && win->AcceptsFocus() )
2771 win->SetFocus();
2772 }
03e0b2b1 2773 }
98363307 2774 }
dfafa702 2775 break;
d0a3d109 2776
cd4453e5 2777#ifdef MM_JOY1MOVE
42e69d6b
VZ
2778 case MM_JOY1MOVE:
2779 case MM_JOY2MOVE:
2780 case MM_JOY1ZMOVE:
2781 case MM_JOY2ZMOVE:
2782 case MM_JOY1BUTTONDOWN:
2783 case MM_JOY2BUTTONDOWN:
2784 case MM_JOY1BUTTONUP:
2785 case MM_JOY2BUTTONUP:
132cb640
VZ
2786 processed = HandleJoystickEvent(message,
2787 GET_X_LPARAM(lParam),
2788 GET_Y_LPARAM(lParam),
2789 wParam);
42e69d6b 2790 break;
cd4453e5 2791#endif // __WXMICROWIN__
47cbd6da 2792
42e69d6b
VZ
2793 case WM_COMMAND:
2794 {
2795 WORD id, cmd;
2796 WXHWND hwnd;
2797 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
47cbd6da 2798
42e69d6b
VZ
2799 processed = HandleCommand(id, cmd, hwnd);
2800 }
2801 break;
7d532b0c 2802
42e69d6b
VZ
2803 case WM_NOTIFY:
2804 processed = HandleNotify((int)wParam, lParam, &rc.result);
2805 break;
2bda0e17 2806
27005f3a
VZ
2807 // we only need to reply to WM_NOTIFYFORMAT manually when using MSLU,
2808 // otherwise DefWindowProc() does it perfectly fine for us, but MSLU
2809 // apparently doesn't always behave properly and needs some help
2810#if wxUSE_UNICODE_MSLU && defined(NF_QUERY)
2811 case WM_NOTIFYFORMAT:
2812 if ( lParam == NF_QUERY )
2813 {
2814 processed = true;
2815 rc.result = NFR_UNICODE;
2816 }
2817 break;
2818#endif // wxUSE_UNICODE_MSLU
2819
08158721 2820 // for these messages we must return true if process the message
cd4453e5 2821#ifdef WM_DRAWITEM
42e69d6b
VZ
2822 case WM_DRAWITEM:
2823 case WM_MEASUREITEM:
2824 {
2825 int idCtrl = (UINT)wParam;
2826 if ( message == WM_DRAWITEM )
2827 {
2828 processed = MSWOnDrawItem(idCtrl,
2829 (WXDRAWITEMSTRUCT *)lParam);
2830 }
2831 else
2832 {
2833 processed = MSWOnMeasureItem(idCtrl,
2834 (WXMEASUREITEMSTRUCT *)lParam);
2835 }
57a7b7c1 2836
42e69d6b
VZ
2837 if ( processed )
2838 rc.result = TRUE;
2839 }
2840 break;
cd4453e5
VZ
2841#endif // defined(WM_DRAWITEM)
2842
9bf84618 2843 case WM_GETDLGCODE:
5a403e3f 2844 if ( !IsOfStandardClass() )
9bf84618 2845 {
5a403e3f
VZ
2846 // we always want to get the char events
2847 rc.result = DLGC_WANTCHARS;
2848
2849 if ( GetWindowStyleFlag() & wxWANTS_CHARS )
2850 {
2851 // in fact, we want everything
2852 rc.result |= DLGC_WANTARROWS |
2853 DLGC_WANTTAB |
2854 DLGC_WANTALLKEYS;
2855 }
2856
08158721 2857 processed = true;
9bf84618 2858 }
101f488c 2859 //else: get the dlg code from the DefWindowProc()
9bf84618
VZ
2860 break;
2861
4004f41e 2862 case WM_SYSKEYDOWN:
42e69d6b 2863 case WM_KEYDOWN:
9c7df356
VZ
2864 // If this has been processed by an event handler, return 0 now
2865 // (we've handled it).
2866 m_lastKeydownProcessed = HandleKeyDown((WORD) wParam, lParam);
2867 if ( m_lastKeydownProcessed )
2d0a075d 2868 {
08158721 2869 processed = true;
2d0a075d 2870 }
81d66cf3 2871
2b5f62a0 2872 if ( !processed )
42e69d6b 2873 {
2b5f62a0
VZ
2874 switch ( wParam )
2875 {
90e572f1 2876 // we consider these messages "not interesting" to OnChar, so
2b5f62a0
VZ
2877 // just don't do anything more with them
2878 case VK_SHIFT:
2879 case VK_CONTROL:
2880 case VK_MENU:
2881 case VK_CAPITAL:
2882 case VK_NUMLOCK:
2883 case VK_SCROLL:
08158721 2884 processed = true;
2b5f62a0 2885 break;
2bda0e17 2886
2b5f62a0
VZ
2887 // avoid duplicate messages to OnChar for these ASCII keys:
2888 // they will be translated by TranslateMessage() and received
2889 // in WM_CHAR
2890 case VK_ESCAPE:
2891 case VK_SPACE:
2892 case VK_RETURN:
2893 case VK_BACK:
2894 case VK_TAB:
2895 case VK_ADD:
2896 case VK_SUBTRACT:
2897 case VK_MULTIPLY:
2898 case VK_DIVIDE:
3f2174bb
VZ
2899 case VK_NUMPAD0:
2900 case VK_NUMPAD1:
2901 case VK_NUMPAD2:
2902 case VK_NUMPAD3:
2903 case VK_NUMPAD4:
2904 case VK_NUMPAD5:
2905 case VK_NUMPAD6:
2906 case VK_NUMPAD7:
2907 case VK_NUMPAD8:
2908 case VK_NUMPAD9:
2b5f62a0
VZ
2909 case VK_OEM_1:
2910 case VK_OEM_2:
2911 case VK_OEM_3:
2912 case VK_OEM_4:
2913 case VK_OEM_5:
2914 case VK_OEM_6:
2915 case VK_OEM_7:
2916 case VK_OEM_PLUS:
2917 case VK_OEM_COMMA:
2918 case VK_OEM_MINUS:
2919 case VK_OEM_PERIOD:
08158721 2920 // but set processed to false, not true to still pass them
2b5f62a0
VZ
2921 // to the control's default window proc - otherwise
2922 // built-in keyboard handling won't work
08158721 2923 processed = false;
2b5f62a0 2924 break;
2bda0e17 2925
42e69d6b 2926#ifdef VK_APPS
2b5f62a0
VZ
2927 // special case of VK_APPS: treat it the same as right mouse
2928 // click because both usually pop up a context menu
2929 case VK_APPS:
ae177b45 2930 processed = HandleMouseEvent(WM_RBUTTONDOWN, -1, -1, 0);
2b5f62a0 2931 break;
42e69d6b 2932#endif // VK_APPS
2bda0e17 2933
2b5f62a0
VZ
2934 default:
2935 // do generate a CHAR event
2936 processed = HandleChar((WORD)wParam, lParam);
2937 }
42e69d6b 2938 }
2b5f62a0 2939 if (message == WM_SYSKEYDOWN) // Let Windows still handle the SYSKEYs
08158721 2940 processed = false;
42e69d6b 2941 break;
2bda0e17 2942
4004f41e 2943 case WM_SYSKEYUP:
42e69d6b 2944 case WM_KEYUP:
4aff28fc
VZ
2945#ifdef VK_APPS
2946 // special case of VK_APPS: treat it the same as right mouse button
2947 if ( wParam == VK_APPS )
2948 {
ae177b45 2949 processed = HandleMouseEvent(WM_RBUTTONUP, -1, -1, 0);
4aff28fc
VZ
2950 }
2951 else
2952#endif // VK_APPS
2953 {
2954 processed = HandleKeyUp((WORD) wParam, lParam);
2955 }
42e69d6b 2956 break;
debe6624 2957
170cbe33 2958 case WM_SYSCHAR:
42e69d6b 2959 case WM_CHAR: // Always an ASCII character
d9f14e16
RD
2960 if ( m_lastKeydownProcessed )
2961 {
2962 // The key was handled in the EVT_KEY_DOWN and handling
2963 // a key in an EVT_KEY_DOWN handler is meant, by
2964 // design, to prevent EVT_CHARs from happening
08158721
DS
2965 m_lastKeydownProcessed = false;
2966 processed = true;
d9f14e16
RD
2967 }
2968 else
7de5bdf4 2969 {
08158721 2970 processed = HandleChar((WORD)wParam, lParam, true);
7de5bdf4 2971 }
42e69d6b 2972 break;
2bda0e17 2973
5048c832
JS
2974#if wxUSE_HOTKEY
2975 case WM_HOTKEY:
2976 processed = HandleHotKey((WORD)wParam, lParam);
2977 break;
540b6b09 2978#endif // wxUSE_HOTKEY
5048c832 2979
42e69d6b
VZ
2980 case WM_HSCROLL:
2981 case WM_VSCROLL:
a23fd0e1 2982 {
42e69d6b
VZ
2983 WXWORD code, pos;
2984 WXHWND hwnd;
2985 UnpackScroll(wParam, lParam, &code, &pos, &hwnd);
2bda0e17 2986
42e69d6b
VZ
2987 processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL
2988 : wxVERTICAL,
2989 code, pos, hwnd);
a23fd0e1 2990 }
42e69d6b 2991 break;
a23fd0e1 2992
42e69d6b 2993 // CTLCOLOR messages are sent by children to query the parent for their
01c500af 2994 // colors
04ef50df 2995#ifndef __WXMICROWIN__
42e69d6b
VZ
2996 case WM_CTLCOLORMSGBOX:
2997 case WM_CTLCOLOREDIT:
2998 case WM_CTLCOLORLISTBOX:
2999 case WM_CTLCOLORBTN:
3000 case WM_CTLCOLORDLG:
3001 case WM_CTLCOLORSCROLLBAR:
3002 case WM_CTLCOLORSTATIC:
a23fd0e1 3003 {
42e69d6b
VZ
3004 WXHDC hdc;
3005 WXHWND hwnd;
01c500af 3006 UnpackCtlColor(wParam, lParam, &hdc, &hwnd);
42e69d6b 3007
48fa6bd3 3008 processed = HandleCtlColor(&rc.hBrush, (WXHDC)hdc, (WXHWND)hwnd);
a23fd0e1 3009 }
42e69d6b 3010 break;
cd4453e5 3011#endif // !__WXMICROWIN__
debe6624 3012
42e69d6b 3013 case WM_SYSCOLORCHANGE:
90c1530a 3014 // the return value for this message is ignored
42e69d6b
VZ
3015 processed = HandleSysColorChange();
3016 break;
2bda0e17 3017
7f0586ef 3018#if !defined(__WXWINCE__)
574c939e
KB
3019 case WM_DISPLAYCHANGE:
3020 processed = HandleDisplayChange();
3021 break;
7f0586ef 3022#endif
574c939e 3023
42e69d6b
VZ
3024 case WM_PALETTECHANGED:
3025 processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
3026 break;
2bda0e17 3027
a5e84126
JS
3028 case WM_CAPTURECHANGED:
3029 processed = HandleCaptureChanged((WXHWND) (HWND) lParam);
3030 break;
3031
3c96418b
JG
3032 case WM_SETTINGCHANGE:
3033 processed = HandleSettingChange(wParam, lParam);
3034 break;
3035
42e69d6b
VZ
3036 case WM_QUERYNEWPALETTE:
3037 processed = HandleQueryNewPalette();
3038 break;
2bda0e17 3039
42e69d6b
VZ
3040 case WM_ERASEBKGND:
3041 processed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
3042 if ( processed )
3043 {
3044 // we processed the message, i.e. erased the background
3045 rc.result = TRUE;
3046 }
3047 break;
debe6624 3048
7f0586ef 3049#if !defined(__WXWINCE__)
42e69d6b
VZ
3050 case WM_DROPFILES:
3051 processed = HandleDropFiles(wParam);
3052 break;
7f0586ef 3053#endif
2bda0e17 3054
42e69d6b
VZ
3055 case WM_INITDIALOG:
3056 processed = HandleInitDialog((WXHWND)(HWND)wParam);
a23fd0e1 3057
42e69d6b
VZ
3058 if ( processed )
3059 {
3060 // we never set focus from here
3061 rc.result = FALSE;
3062 }
3063 break;
a23fd0e1 3064
7f0586ef 3065#if !defined(__WXWINCE__)
42e69d6b
VZ
3066 case WM_QUERYENDSESSION:
3067 processed = HandleQueryEndSession(lParam, &rc.allow);
3068 break;
2bda0e17 3069
42e69d6b
VZ
3070 case WM_ENDSESSION:
3071 processed = HandleEndSession(wParam != 0, lParam);
3072 break;
2bda0e17 3073
42e69d6b 3074 case WM_GETMINMAXINFO:
25889d3c 3075 processed = HandleGetMinMaxInfo((MINMAXINFO*)lParam);
42e69d6b 3076 break;
7f0586ef 3077#endif
debe6624 3078
42e69d6b
VZ
3079 case WM_SETCURSOR:
3080 processed = HandleSetCursor((WXHWND)(HWND)wParam,
3081 LOWORD(lParam), // hit test
3082 HIWORD(lParam)); // mouse msg
3083
3084 if ( processed )
3085 {
3086 // returning TRUE stops the DefWindowProc() from further
3087 // processing this message - exactly what we need because we've
3088 // just set the cursor.
3089 rc.result = TRUE;
3090 }
3091 break;
4cdc2c13 3092
ed5317e5
JS
3093#if wxUSE_ACCESSIBILITY
3094 case WM_GETOBJECT:
3095 {
3096 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
3097 LPARAM dwObjId = (LPARAM) (DWORD) lParam;
3098
66b9ec3d 3099 if (dwObjId == (LPARAM)OBJID_CLIENT && GetOrCreateAccessible())
ed5317e5
JS
3100 {
3101 return LresultFromObject(IID_IAccessible, wParam, (IUnknown*) GetAccessible()->GetIAccessible());
3102 }
3103 break;
3104 }
3105#endif
3106
e39af974 3107#if defined(WM_HELP)
b96340e6 3108 case WM_HELP:
b96340e6 3109 {
a9c11b71
VZ
3110 // by default, WM_HELP is propagated by DefWindowProc() upwards
3111 // to the window parent but as we do it ourselves already
3112 // (wxHelpEvent is derived from wxCommandEvent), we don't want
3113 // to get the other events if we process this message at all
3114 processed = true;
3115
3116 // WM_HELP doesn't use lParam under CE
7f0586ef 3117#ifndef __WXWINCE__
4cdc2c13 3118 HELPINFO* info = (HELPINFO*) lParam;
a9c11b71 3119 if ( info->iContextType == HELPINFO_WINDOW )
b96340e6 3120 {
a9c11b71
VZ
3121#endif // !__WXWINCE__
3122 wxHelpEvent helpEvent
3123 (
3124 wxEVT_HELP,
3125 GetId(),
7f0586ef 3126#ifdef __WXWINCE__
2d4ec362 3127 wxGetMousePosition() // what else?
7f0586ef 3128#else
a9c11b71 3129 wxPoint(info->MousePos.x, info->MousePos.y)
7f0586ef 3130#endif
a9c11b71 3131 );
b96340e6 3132
a9c11b71
VZ
3133 helpEvent.SetEventObject(this);
3134 GetEventHandler()->ProcessEvent(helpEvent);
7f0586ef 3135#ifndef __WXWINCE__
b96340e6 3136 }
a9c11b71 3137 else if ( info->iContextType == HELPINFO_MENUITEM )
4cdc2c13
VZ
3138 {
3139 wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
3140 helpEvent.SetEventObject(this);
a9c11b71 3141 GetEventHandler()->ProcessEvent(helpEvent);
69231000 3142
4cdc2c13 3143 }
a9c11b71
VZ
3144 else // unknown help event?
3145 {
3146 processed = false;
3147 }
3148#endif // !__WXWINCE__
b96340e6 3149 }
b96340e6 3150 break;
a9c11b71 3151#endif // WM_HELP
4cdc2c13 3152
7f0586ef 3153#if !defined(__WXWINCE__)
69231000 3154 case WM_CONTEXTMENU:
4cdc2c13
VZ
3155 {
3156 // we don't convert from screen to client coordinates as
3157 // the event may be handled by a parent window
3158 wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
3159
3160 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt);
2d1715aa
VZ
3161
3162 // we could have got an event from our child, reflect it back
3163 // to it if this is the case
d85c53a5 3164 wxWindowMSW *win = NULL;
c140b7e7 3165 if ( (WXHWND)wParam != m_hWnd )
2d1715aa
VZ
3166 {
3167 win = FindItemByHWND((WXHWND)wParam);
3168 }
3169
3170 if ( !win )
3171 win = this;
3172
3173 evtCtx.SetEventObject(win);
3174 processed = win->GetEventHandler()->ProcessEvent(evtCtx);
4cdc2c13 3175 }
69231000 3176 break;
7f0586ef 3177#endif
b74cce40
VZ
3178
3179 case WM_MENUCHAR:
3180 // we're only interested in our own menus, not MF_SYSMENU
3181 if ( HIWORD(wParam) == MF_POPUP )
3182 {
3183 // handle menu chars for ownerdrawn menu items
3184 int i = HandleMenuChar(toupper(LOWORD(wParam)), lParam);
3185 if ( i != wxNOT_FOUND )
3186 {
3187 rc.result = MAKELRESULT(i, MNC_EXECUTE);
08158721 3188 processed = true;
b74cce40
VZ
3189 }
3190 }
3191 break;
355debca 3192
dbc74bcc 3193#ifndef __WXWINCE__
355debca
VZ
3194 case WM_POWERBROADCAST:
3195 {
3196 bool vetoed;
3197 processed = HandlePower(wParam, lParam, &vetoed);
3198 rc.result = processed && vetoed ? BROADCAST_QUERY_DENY : TRUE;
3199 }
3200 break;
dbc74bcc 3201#endif // __WXWINCE__
a23fd0e1 3202 }
2d0a075d 3203
42e69d6b 3204 if ( !processed )
2d0a075d 3205 {
42e69d6b 3206#ifdef __WXDEBUG__
223d09f6 3207 wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."),
42e69d6b
VZ
3208 wxGetMessageName(message));
3209#endif // __WXDEBUG__
3210 rc.result = MSWDefWindowProc(message, wParam, lParam);
a23fd0e1 3211 }
2bda0e17 3212
42e69d6b 3213 return rc.result;
2bda0e17
KB
3214}
3215
b225f659
VZ
3216// ----------------------------------------------------------------------------
3217// wxWindow <-> HWND map
3218// ----------------------------------------------------------------------------
2bda0e17 3219
1bffa913 3220wxWinHashTable *wxWinHandleHash = NULL;
b225f659 3221
42e69d6b 3222wxWindow *wxFindWinFromHandle(WXHWND hWnd)
4ce81a75 3223{
40ad3426 3224 return (wxWindow*)wxWinHandleHash->Get((long)hWnd);
42e69d6b 3225}
4ce81a75 3226
1e6feb95 3227void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win)
42e69d6b
VZ
3228{
3229 // adding NULL hWnd is (first) surely a result of an error and
3230 // (secondly) breaks menu command processing
3231 wxCHECK_RET( hWnd != (HWND)NULL,
223d09f6 3232 wxT("attempt to add a NULL hWnd to window list ignored") );
4ce81a75 3233
c7527e3f 3234 wxWindow *oldWin = wxFindWinFromHandle((WXHWND) hWnd);
b225f659 3235#ifdef __WXDEBUG__
c7527e3f
JS
3236 if ( oldWin && (oldWin != win) )
3237 {
b225f659 3238 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
9b601c24 3239 (int) hWnd, win->GetClassInfo()->GetClassName());
c7527e3f 3240 }
b225f659
VZ
3241 else
3242#endif // __WXDEBUG__
3243 if (!oldWin)
c7527e3f 3244 {
d2d14464 3245 wxWinHandleHash->Put((long)hWnd, (wxWindow *)win);
c7527e3f 3246 }
42e69d6b 3247}
4ce81a75 3248
1e6feb95 3249void wxRemoveHandleAssociation(wxWindowMSW *win)
42e69d6b 3250{
1bffa913 3251 wxWinHandleHash->Delete((long)win->GetHWND());
4ce81a75
JS
3252}
3253
b225f659
VZ
3254// ----------------------------------------------------------------------------
3255// various MSW speciic class dependent functions
3256// ----------------------------------------------------------------------------
3257
42e69d6b
VZ
3258// Default destroyer - override if you destroy it in some other way
3259// (e.g. with MDI child windows)
1e6feb95 3260void wxWindowMSW::MSWDestroyWindow()
4ce81a75 3261{
42e69d6b 3262}
4ce81a75 3263
b225f659
VZ
3264bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos,
3265 const wxSize& size,
3266 int& x, int& y,
3267 int& w, int& h) const
2bda0e17 3268{
9cb57df4 3269 // yes, those are just some arbitrary hardcoded numbers
2a77c8c4 3270 static const int DEFAULT_Y = 200;
2a77c8c4 3271
08158721 3272 bool nonDefault = false;
c085e333 3273
422d0ff0 3274 if ( pos.x == wxDefaultCoord )
b225f659 3275 {
9cb57df4
VZ
3276 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
3277 // can just as well set it to CW_USEDEFAULT as well
b225f659
VZ
3278 x =
3279 y = CW_USEDEFAULT;
3280 }
3281 else
a23fd0e1 3282 {
2a77c8c4
VZ
3283 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
3284 // neither because it is not handled as a special value by Windows then
3285 // and so we have to choose some default value for it
b225f659 3286 x = pos.x;
422d0ff0 3287 y = pos.y == wxDefaultCoord ? DEFAULT_Y : pos.y;
c085e333 3288
08158721 3289 nonDefault = true;
42e69d6b 3290 }
2bda0e17 3291
b889a3a2
VZ
3292 /*
3293 NB: there used to be some code here which set the initial size of the
3294 window to the client size of the parent if no explicit size was
77ffb593 3295 specified. This was wrong because wxWidgets programs often assume
b889a3a2
VZ
3296 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
3297 it. To see why, you should understand that Windows sends WM_SIZE from
3298 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
3299 from some base class ctor and so this WM_SIZE is not processed in the
3300 real class' OnSize() (because it's not fully constructed yet and the
3301 event goes to some base class OnSize() instead). So the WM_SIZE we
3302 rely on is the one sent when the parent frame resizes its children
3303 but here is the problem: if the child already has just the right
77ffb593 3304 size, nothing will happen as both wxWidgets and Windows check for
b889a3a2
VZ
3305 this and ignore any attempts to change the window size to the size it
3306 already has - so no WM_SIZE would be sent.
3307 */
b225f659 3308
35bbb0c6 3309
426936d1
RD
3310 // we don't use CW_USEDEFAULT here for several reasons:
3311 //
3312 // 1. it results in huge frames on modern screens (1000*800 is not
3313 // uncommon on my 1280*1024 screen) which is way too big for a half
77ffb593 3314 // empty frame of most of wxWidgets samples for example)
426936d1
RD
3315 //
3316 // 2. it is buggy for frames with wxFRAME_TOOL_WINDOW style for which
3317 // the default is for whatever reason 8*8 which breaks client <->
3318 // window size calculations (it would be nice if it didn't, but it
3319 // does and the simplest way to fix it seemed to change the broken
3320 // default size anyhow)
3321 //
3322 // 3. there is just no advantage in doing it: with x and y it is
3323 // possible that [future versions of] Windows position the new top
3324 // level window in some smart way which we can't do, but we can
3325 // guess a reasonably good size for a new window just as well
3326 // ourselves
960b193e 3327
3a3c8603
DS
3328 // However, on PocketPC devices, we must use the default
3329 // size if possible.
960b193e 3330#ifdef _WIN32_WCE
422d0ff0 3331 if (size.x == wxDefaultCoord)
3a3c8603
DS
3332 w = CW_USEDEFAULT;
3333 else
3334 w = size.x;
422d0ff0 3335 if (size.y == wxDefaultCoord)
3a3c8603
DS
3336 h = CW_USEDEFAULT;
3337 else
3338 h = size.y;
960b193e 3339#else
422d0ff0 3340 if ( size.x == wxDefaultCoord || size.y == wxDefaultCoord)
426936d1 3341 {
08158721 3342 nonDefault = true;
8614c467 3343 }
426936d1
RD
3344 w = WidthDefault(size.x);
3345 h = HeightDefault(size.y);
960b193e 3346#endif
8614c467 3347
4e9d23cd
VZ
3348 AdjustForParentClientOrigin(x, y);
3349
b225f659
VZ
3350 return nonDefault;
3351}
3352
9dfef5ac
VZ
3353WXHWND wxWindowMSW::MSWGetParent() const
3354{
d285d708 3355 return m_parent ? m_parent->GetHWND() : WXHWND(NULL);
9dfef5ac
VZ
3356}
3357
b225f659
VZ
3358bool wxWindowMSW::MSWCreate(const wxChar *wclass,
3359 const wxChar *title,
3360 const wxPoint& pos,
3361 const wxSize& size,
3362 WXDWORD style,
3363 WXDWORD extendedStyle)
3364{
3365 // choose the position/size for the new window
3366 int x, y, w, h;
3367 (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h);
3368
b225f659
VZ
3369 // controlId is menu handle for the top level windows, so set it to 0
3370 // unless we're creating a child window
f586fde3 3371 int controlId = style & WS_CHILD ? GetId() : 0;
2bda0e17 3372
b225f659
VZ
3373 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
3374 // which is the same but without CS_[HV]REDRAW class styles so using it
3375 // ensures that the window is not fully repainted on each resize
3376 wxString className(wclass);
e441e1f4 3377 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) )
b225f659
VZ
3378 {
3379 className += wxT("NR");
a23fd0e1 3380 }
c085e333 3381
b225f659
VZ
3382 // do create the window
3383 wxWindowCreationHook hook(this);
b3daa5a3 3384
5e67eb97
VZ
3385 m_hWnd = (WXHWND)::CreateWindowEx
3386 (
3387 extendedStyle,
3388 className,
3389 title ? title : m_windowName.c_str(),
3390 style,
3391 x, y, w, h,
3392 (HWND)MSWGetParent(),
3393 (HMENU)controlId,
3394 wxGetInstance(),
3395 NULL // no extra data
3396 );
b225f659
VZ
3397
3398 if ( !m_hWnd )
c7527e3f 3399 {
5e67eb97 3400 wxLogSysError(_("Can't create window of class %s"), className.c_str());
b225f659 3401
08158721 3402 return false;
c7527e3f 3403 }
b3daa5a3 3404
b225f659 3405 SubclassWin(m_hWnd);
c085e333 3406
08158721 3407 return true;
2bda0e17
KB
3408}
3409
42e69d6b
VZ
3410// ===========================================================================
3411// MSW message handlers
3412// ===========================================================================
3413
3414// ---------------------------------------------------------------------------
3415// WM_NOTIFY
3416// ---------------------------------------------------------------------------
3417
1e6feb95 3418bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
2bda0e17 3419{
04ef50df 3420#ifndef __WXMICROWIN__
42e69d6b
VZ
3421 LPNMHDR hdr = (LPNMHDR)lParam;
3422 HWND hWnd = hdr->hwndFrom;
3423 wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd);
3424
2b15b970 3425 // if the control is one of our windows, let it handle the message itself
42e69d6b 3426 if ( win )
564b2609 3427 {
42e69d6b 3428 return win->MSWOnNotify(idCtrl, lParam, result);
564b2609 3429 }
2bda0e17 3430
2b15b970
VZ
3431 // VZ: why did we do it? normally this is unnecessary and, besides, it
3432 // breaks the message processing for the toolbars because the tooltip
3433 // notifications were being forwarded to the toolbar child controls
3434 // (if it had any) before being passed to the toolbar itself, so in my
3435 // example the tooltip for the combobox was always shown instead of the
3436 // correct button tooltips
3437#if 0
42e69d6b 3438 // try all our children
222ed1d6 3439 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
42e69d6b 3440 while ( node )
564b2609 3441 {
42e69d6b
VZ
3442 wxWindow *child = node->GetData();
3443 if ( child->MSWOnNotify(idCtrl, lParam, result) )
3444 {
08158721 3445 return true;
42e69d6b 3446 }
2d0a075d 3447
42e69d6b
VZ
3448 node = node->GetNext();
3449 }
2b15b970 3450#endif // 0
2d0a075d 3451
2b15b970 3452 // by default, handle it ourselves
42e69d6b 3453 return MSWOnNotify(idCtrl, lParam, result);
cd4453e5 3454#else // __WXMICROWIN__
08158721 3455 return false;
04ef50df 3456#endif
42e69d6b 3457}
2d0a075d 3458
bd9cd534
VZ
3459#if wxUSE_TOOLTIPS
3460
3461bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
3462 WXLPARAM lParam,
3463 const wxString& ttip)
3464{
3465 // I don't know why it happens, but the versions of comctl32.dll starting
3466 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
3467 // this message is supposed to be sent to Unicode programs only) -- hence
3468 // we need to handle it as well, otherwise no tooltips will be shown in
3469 // this case
7f0586ef 3470#ifndef __WXWINCE__
118208ac
VZ
3471 if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW)
3472 || ttip.empty() )
bd9cd534
VZ
3473 {
3474 // not a tooltip message or no tooltip to show anyhow
08158721 3475 return false;
bd9cd534 3476 }
7f0586ef 3477#endif
bd9cd534
VZ
3478
3479 LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
3480
118208ac
VZ
3481 // We don't want to use the szText buffer because it has a limit of 80
3482 // bytes and this is not enough, especially for Unicode build where it
3483 // limits the tooltip string length to only 40 characters
3484 //
3485 // The best would be, of course, to not impose any length limitations at
3486 // all but then the buffer would have to be dynamic and someone would have
3487 // to free it and we don't have the tooltip owner object here any more, so
3488 // for now use our own static buffer with a higher fixed max length.
3489 //
3490 // Note that using a static buffer should not be a problem as only a single
3491 // tooltip can be shown at the same time anyhow.
2b5f62a0 3492#if !wxUSE_UNICODE
118208ac 3493 if ( code == (WXUINT) TTN_NEEDTEXTW )
bd9cd534 3494 {
118208ac
VZ
3495 // We need to convert tooltip from multi byte to Unicode on the fly.
3496 static wchar_t buf[513];
25c46fda 3497
118208ac
VZ
3498 // Truncate tooltip length if needed as otherwise we might not have
3499 // enough space for it in the buffer and MultiByteToWideChar() would
3500 // return an error
fec9cc08 3501 size_t tipLength = wxMin(ttip.length(), WXSIZEOF(buf) - 1);
7afebc8c
JS
3502
3503 // Convert to WideChar without adding the NULL character. The NULL
25c46fda 3504 // character is added afterwards (this is more efficient).
118208ac
VZ
3505 int len = ::MultiByteToWideChar
3506 (
3507 CP_ACP,
3508 0, // no flags
3509 ttip,
3510 tipLength,
3511 buf,
3512 WXSIZEOF(buf) - 1
3513 );
3514
3515 if ( !len )
3516 {
3517 wxLogLastError(_T("MultiByteToWideChar()"));
3518 }
7afebc8c 3519
118208ac
VZ
3520 buf[len] = L'\0';
3521 ttText->lpszText = (LPSTR) buf;
3522 }
3523 else // TTN_NEEDTEXTA
3524#endif // !wxUSE_UNICODE
3525 {
3526 // we get here if we got TTN_NEEDTEXTA (only happens in ANSI build) or
3527 // if we got TTN_NEEDTEXTW in Unicode build: in this case we just have
3528 // to copy the string we have into the buffer
3529 static wxChar buf[513];
3530 wxStrncpy(buf, ttip.c_str(), WXSIZEOF(buf) - 1);
3531 buf[WXSIZEOF(buf) - 1] = _T('\0');
3532 ttText->lpszText = buf;
bd9cd534
VZ
3533 }
3534
08158721 3535 return true;
bd9cd534
VZ
3536}
3537
3538#endif // wxUSE_TOOLTIPS
3539
1e6feb95 3540bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl),
bd9cd534
VZ
3541 WXLPARAM lParam,
3542 WXLPARAM* WXUNUSED(result))
42e69d6b
VZ
3543{
3544#if wxUSE_TOOLTIPS
bd9cd534 3545 if ( m_tooltip )
42e69d6b 3546 {
bd9cd534
VZ
3547 NMHDR* hdr = (NMHDR *)lParam;
3548 if ( HandleTooltipNotify(hdr->code, lParam, m_tooltip->GetTip()))
3549 {
3550 // processed
08158721 3551 return true;
bd9cd534 3552 }
42e69d6b 3553 }
f5dd1cf1
WS
3554#else
3555 wxUnusedVar(lParam);
42e69d6b
VZ
3556#endif // wxUSE_TOOLTIPS
3557
08158721 3558 return false;
42e69d6b 3559}
2b15b970 3560
42e69d6b
VZ
3561// ---------------------------------------------------------------------------
3562// end session messages
3563// ---------------------------------------------------------------------------
2d0a075d 3564
1e6feb95 3565bool wxWindowMSW::HandleQueryEndSession(long logOff, bool *mayEnd)
42e69d6b 3566{
040e5f77 3567#ifdef ENDSESSION_LOGOFF
abb74e0f 3568 wxCloseEvent event(wxEVT_QUERY_END_SESSION, wxID_ANY);
42e69d6b 3569 event.SetEventObject(wxTheApp);
08158721 3570 event.SetCanVeto(true);
a17e237f 3571 event.SetLoggingOff(logOff == (long)ENDSESSION_LOGOFF);
2d0a075d 3572
42e69d6b
VZ
3573 bool rc = wxTheApp->ProcessEvent(event);
3574
3575 if ( rc )
3576 {
3577 // we may end only if the app didn't veto session closing (double
3578 // negation...)
3579 *mayEnd = !event.GetVeto();
2d0a075d
JS
3580 }
3581
42e69d6b 3582 return rc;
7f0586ef 3583#else
040e5f77
VZ
3584 wxUnusedVar(logOff);
3585 wxUnusedVar(mayEnd);
08158721 3586 return false;
7f0586ef 3587#endif
2bda0e17
KB
3588}
3589
1e6feb95 3590bool wxWindowMSW::HandleEndSession(bool endSession, long logOff)
2bda0e17 3591{
040e5f77 3592#ifdef ENDSESSION_LOGOFF
42e69d6b
VZ
3593 // do nothing if the session isn't ending
3594 if ( !endSession )
08158721 3595 return false;
a23fd0e1 3596
519dc37f
VZ
3597 // only send once
3598 if ( (this != wxTheApp->GetTopWindow()) )
08158721 3599 return false;
519dc37f 3600
abb74e0f 3601 wxCloseEvent event(wxEVT_END_SESSION, wxID_ANY);
42e69d6b 3602 event.SetEventObject(wxTheApp);
08158721 3603 event.SetCanVeto(false);
a17e237f 3604 event.SetLoggingOff( (logOff == (long)ENDSESSION_LOGOFF) );
519dc37f
VZ
3605
3606 return wxTheApp->ProcessEvent(event);
7f0586ef 3607#else
040e5f77
VZ
3608 wxUnusedVar(endSession);
3609 wxUnusedVar(logOff);
08158721 3610 return false;
7f0586ef 3611#endif
2bda0e17
KB
3612}
3613
42e69d6b
VZ
3614// ---------------------------------------------------------------------------
3615// window creation/destruction
3616// ---------------------------------------------------------------------------
3617
0c0d1521
WS
3618bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT WXUNUSED_IN_WINCE(cs),
3619 bool *mayCreate)
61179e28 3620{
ee471817
VZ
3621 // VZ: why is this commented out for WinCE? If it doesn't support
3622 // WS_EX_CONTROLPARENT at all it should be somehow handled globally,
3623 // not with multiple #ifdef's!
7f0586ef 3624#ifndef __WXWINCE__
61179e28 3625 if ( ((CREATESTRUCT *)cs)->dwExStyle & WS_EX_CONTROLPARENT )
ee471817
VZ
3626 EnsureParentHasControlParentStyle(GetParent());
3627#endif // !__WXWINCE__
61179e28 3628
08158721 3629 *mayCreate = true;
42e69d6b 3630
08158721 3631 return true;
2bda0e17
KB
3632}
3633
1e6feb95 3634bool wxWindowMSW::HandleDestroy()
2bda0e17 3635{
7de59551 3636 SendDestroyEvent();
42e69d6b
VZ
3637
3638 // delete our drop target if we've got one
3639#if wxUSE_DRAG_AND_DROP
3640 if ( m_dropTarget != NULL )
2d0a075d 3641 {
42e69d6b
VZ
3642 m_dropTarget->Revoke(m_hWnd);
3643
3644 delete m_dropTarget;
3645 m_dropTarget = NULL;
2d0a075d 3646 }
42e69d6b 3647#endif // wxUSE_DRAG_AND_DROP
2bda0e17 3648
42e69d6b 3649 // WM_DESTROY handled
08158721 3650 return true;
2bda0e17
KB
3651}
3652
42e69d6b
VZ
3653// ---------------------------------------------------------------------------
3654// activation/focus
3655// ---------------------------------------------------------------------------
3656
1e6feb95 3657bool wxWindowMSW::HandleActivate(int state,
42e69d6b
VZ
3658 bool WXUNUSED(minimized),
3659 WXHWND WXUNUSED(activate))
2bda0e17 3660{
42e69d6b
VZ
3661 wxActivateEvent event(wxEVT_ACTIVATE,
3662 (state == WA_ACTIVE) || (state == WA_CLICKACTIVE),
3663 m_windowId);
3664 event.SetEventObject(this);
3665
3666 return GetEventHandler()->ProcessEvent(event);
3667}
3668
1e6feb95 3669bool wxWindowMSW::HandleSetFocus(WXHWND hwnd)
42e69d6b 3670{
c7aee865
RD
3671 // Strangly enough, some controls get set focus events when they are being
3672 // deleted, even if they already had focus before.
3673 if ( m_isBeingDeleted )
3674 {
3675 return false;
3676 }
35bbb0c6 3677
456bc6d9
VZ
3678 // notify the parent keeping track of focus for the kbd navigation
3679 // purposes that we got it
e72aa7f5 3680 wxChildFocusEvent eventFocus((wxWindow *)this);
456bc6d9
VZ
3681 (void)GetEventHandler()->ProcessEvent(eventFocus);
3682
789295bf 3683#if wxUSE_CARET
42e69d6b 3684 // Deal with caret
789295bf 3685 if ( m_caret )
2d0a075d 3686 {
789295bf 3687 m_caret->OnSetFocus();
2bda0e17 3688 }
789295bf 3689#endif // wxUSE_CARET
42e69d6b 3690
ab93a576
RD
3691#if wxUSE_TEXTCTRL
3692 // If it's a wxTextCtrl don't send the event as it will be done
456bc6d9
VZ
3693 // after the control gets to process it from EN_FOCUS handler
3694 if ( wxDynamicCastThis(wxTextCtrl) )
ab93a576 3695 {
08158721 3696 return false;
ab93a576 3697 }
456bc6d9 3698#endif // wxUSE_TEXTCTRL
ab93a576 3699
42e69d6b
VZ
3700 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
3701 event.SetEventObject(this);
3702
1e6feb95
VZ
3703 // wxFindWinFromHandle() may return NULL, it is ok
3704 event.SetWindow(wxFindWinFromHandle(hwnd));
3705
42e69d6b 3706 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3707}
3708
1e6feb95 3709bool wxWindowMSW::HandleKillFocus(WXHWND hwnd)
2bda0e17 3710{
789295bf 3711#if wxUSE_CARET
42e69d6b 3712 // Deal with caret
789295bf 3713 if ( m_caret )
2d0a075d 3714 {
789295bf 3715 m_caret->OnKillFocus();
2bda0e17 3716 }
789295bf 3717#endif // wxUSE_CARET
42e69d6b 3718
ab93a576
RD
3719#if wxUSE_TEXTCTRL
3720 // If it's a wxTextCtrl don't send the event as it will be done
3721 // after the control gets to process it.
3722 wxTextCtrl *ctrl = wxDynamicCastThis(wxTextCtrl);
3723 if ( ctrl )
3724 {
08158721 3725 return false;
ab93a576
RD
3726 }
3727#endif
3728
2913e597
RD
3729 // Don't send the event when in the process of being deleted. This can
3730 // only cause problems if the event handler tries to access the object.
3731 if ( m_isBeingDeleted )
3732 {
08158721 3733 return false;
2913e597
RD
3734 }
3735
42e69d6b
VZ
3736 wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId);
3737 event.SetEventObject(this);
3738
1e6feb95
VZ
3739 // wxFindWinFromHandle() may return NULL, it is ok
3740 event.SetWindow(wxFindWinFromHandle(hwnd));
3741
42e69d6b 3742 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3743}
3744
faa49bfd
WS
3745// ---------------------------------------------------------------------------
3746// labels
3747// ---------------------------------------------------------------------------
3748
3749void wxWindowMSW::SetLabel( const wxString& label)
3750{
3751 SetWindowText(GetHwnd(), label.c_str());
3752}
3753
3754wxString wxWindowMSW::GetLabel() const
3755{
3756 return wxGetWindowText(GetHWND());
3757}
3758
42e69d6b
VZ
3759// ---------------------------------------------------------------------------
3760// miscellaneous
3761// ---------------------------------------------------------------------------
3762
1e6feb95 3763bool wxWindowMSW::HandleShow(bool show, int WXUNUSED(status))
2bda0e17 3764{
42e69d6b 3765 wxShowEvent event(GetId(), show);
687706f5 3766 event.SetEventObject(this);
42e69d6b
VZ
3767
3768 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3769}
3770
1e6feb95 3771bool wxWindowMSW::HandleInitDialog(WXHWND WXUNUSED(hWndFocus))
2bda0e17 3772{
42e69d6b 3773 wxInitDialogEvent event(GetId());
687706f5 3774 event.SetEventObject(this);
42e69d6b
VZ
3775
3776 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3777}
3778
1e6feb95 3779bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam)
2bda0e17 3780{
7f0586ef 3781#if defined (__WXMICROWIN__) || defined(__WXWINCE__)
35bbb0c6 3782 wxUnusedVar(wParam);
08158721 3783 return false;
4ce1efe1 3784#else // __WXMICROWIN__
42e69d6b 3785 HDROP hFilesInfo = (HDROP) wParam;
42e69d6b
VZ
3786
3787 // Get the total number of files dropped
c3c39620 3788 UINT gwFilesDropped = ::DragQueryFile
f6bcfd97
BP
3789 (
3790 (HDROP)hFilesInfo,
3791 (UINT)-1,
3792 (LPTSTR)0,
3793 (UINT)0
3794 );
42e69d6b
VZ
3795
3796 wxString *files = new wxString[gwFilesDropped];
c3c39620 3797 for ( UINT wIndex = 0; wIndex < gwFilesDropped; wIndex++ )
2d0a075d 3798 {
c3c39620
VZ
3799 // first get the needed buffer length (+1 for terminating NUL)
3800 size_t len = ::DragQueryFile(hFilesInfo, wIndex, NULL, 0) + 1;
3801
3802 // and now get the file name
3803 ::DragQueryFile(hFilesInfo, wIndex,
de564874 3804 wxStringBuffer(files[wIndex], len), len);
2d0a075d 3805 }
42e69d6b 3806 DragFinish (hFilesInfo);
2bda0e17 3807
42e69d6b 3808 wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files);
687706f5 3809 event.SetEventObject(this);
c3c39620
VZ
3810
3811 POINT dropPoint;
3812 DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
b3dc8a3e
VZ
3813 event.m_pos.x = dropPoint.x;
3814 event.m_pos.y = dropPoint.y;
42e69d6b 3815
c3c39620 3816 return GetEventHandler()->ProcessEvent(event);
04ef50df 3817#endif
2bda0e17
KB
3818}
3819
cc972ac6 3820
1e6feb95
VZ
3821bool wxWindowMSW::HandleSetCursor(WXHWND WXUNUSED(hWnd),
3822 short nHitTest,
3823 int WXUNUSED(mouseMsg))
2bda0e17 3824{
04ef50df 3825#ifndef __WXMICROWIN__
bfbd6dc1 3826 // the logic is as follows:
43b5058d
VZ
3827 // -1. don't set cursor for non client area, including but not limited to
3828 // the title bar, scrollbars, &c
3829 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
bfbd6dc1
VZ
3830 // 1. if we have the cursor set it unless wxIsBusy()
3831 // 2. if we're a top level window, set some cursor anyhow
3832 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
42e69d6b 3833
43b5058d
VZ
3834 if ( nHitTest != HTCLIENT )
3835 {
08158721 3836 return false;
43b5058d
VZ
3837 }
3838
bfbd6dc1 3839 HCURSOR hcursor = 0;
43b5058d
VZ
3840
3841 // first ask the user code - it may wish to set the cursor in some very
3842 // specific way (for example, depending on the current position)
3843 POINT pt;
f2325516 3844#ifdef __WXWINCE__
7d30268c 3845 if ( !::GetCursorPosWinCE(&pt))
f2325516 3846#else
43b5058d 3847 if ( !::GetCursorPos(&pt) )
3fca879c 3848#endif
43b5058d 3849 {
f6bcfd97 3850 wxLogLastError(wxT("GetCursorPos"));
43b5058d
VZ
3851 }
3852
3853 int x = pt.x,
3854 y = pt.y;
3855 ScreenToClient(&x, &y);
3856 wxSetCursorEvent event(x, y);
3857
3858 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
3859 if ( processedEvtSetCursor && event.HasCursor() )
bfbd6dc1 3860 {
43b5058d 3861 hcursor = GetHcursorOf(event.GetCursor());
bfbd6dc1 3862 }
42e69d6b 3863
43b5058d 3864 if ( !hcursor )
bfbd6dc1 3865 {
43b5058d
VZ
3866 bool isBusy = wxIsBusy();
3867
3868 // the test for processedEvtSetCursor is here to prevent using m_cursor
3869 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3870 // it - this is a way to say that our cursor shouldn't be used for this
3871 // point
3872 if ( !processedEvtSetCursor && m_cursor.Ok() )
bfbd6dc1 3873 {
43b5058d 3874 hcursor = GetHcursorOf(m_cursor);
bfbd6dc1 3875 }
43b5058d
VZ
3876
3877 if ( !GetParent() )
bfbd6dc1 3878 {
43b5058d 3879 if ( isBusy )
42e69d6b 3880 {
43b5058d
VZ
3881 hcursor = wxGetCurrentBusyCursor();
3882 }
3883 else if ( !hcursor )
3884 {
3885 const wxCursor *cursor = wxGetGlobalCursor();
3886 if ( cursor && cursor->Ok() )
3887 {
3888 hcursor = GetHcursorOf(*cursor);
3889 }
42e69d6b
VZ
3890 }
3891 }
3892 }
3893
bfbd6dc1
VZ
3894 if ( hcursor )
3895 {
2b5f62a0
VZ
3896// wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3897
bfbd6dc1
VZ
3898 ::SetCursor(hcursor);
3899
3900 // cursor set, stop here
08158721 3901 return true;
bfbd6dc1 3902 }
cd4453e5
VZ
3903#endif // __WXMICROWIN__
3904
3ca6a5f0 3905 // pass up the window chain
08158721 3906 return false;
2bda0e17
KB
3907}
3908
dbc74bcc 3909bool wxWindowMSW::HandlePower(WXWPARAM WXUNUSED_IN_WINCE(wParam),
355debca 3910 WXLPARAM WXUNUSED(lParam),
dbc74bcc 3911 bool *WXUNUSED_IN_WINCE(vetoed))
355debca 3912{
dbc74bcc
WS
3913#ifdef __WXWINCE__
3914 // FIXME
3915 return false;
3916#else
355debca
VZ
3917 wxEventType evtType;
3918 switch ( wParam )
3919 {
3920 case PBT_APMQUERYSUSPEND:
3921 evtType = wxEVT_POWER_SUSPENDING;
3922 break;
3923
3924 case PBT_APMQUERYSUSPENDFAILED:
3925 evtType = wxEVT_POWER_SUSPEND_CANCEL;
3926 break;
3927
3928 case PBT_APMSUSPEND:
3929 evtType = wxEVT_POWER_SUSPENDED;
3930 break;
3931
3932 case PBT_APMRESUMESUSPEND:
d4cd85a0
VZ
3933#ifdef PBT_APMRESUMEAUTOMATIC
3934 case PBT_APMRESUMEAUTOMATIC:
3935#endif
355debca
VZ
3936 evtType = wxEVT_POWER_RESUME;
3937 break;
3938
3939 default:
3940 wxLogDebug(_T("Unknown WM_POWERBROADCAST(%d) event"), wParam);
3941 // fall through
3942
3943 // these messages are currently not mapped to wx events
3944 case PBT_APMQUERYSTANDBY:
3945 case PBT_APMQUERYSTANDBYFAILED:
3946 case PBT_APMSTANDBY:
3947 case PBT_APMRESUMESTANDBY:
3948 case PBT_APMBATTERYLOW:
3949 case PBT_APMPOWERSTATUSCHANGE:
3950 case PBT_APMOEMEVENT:
355debca
VZ
3951 case PBT_APMRESUMECRITICAL:
3952 evtType = wxEVT_NULL;
3953 break;
3954 }
3955
3956 // don't handle unknown messages
3957 if ( evtType == wxEVT_NULL )
3958 return false;
3959
3960 // TODO: notify about PBTF_APMRESUMEFROMFAILURE in case of resume events?
3961
3962 wxPowerEvent event(evtType);
3963 if ( !GetEventHandler()->ProcessEvent(event) )
3964 return false;
3965
3966 *vetoed = event.IsVetoed();
3967
3968 return true;
dbc74bcc 3969#endif
355debca
VZ
3970}
3971
2e992e06
VZ
3972bool wxWindowMSW::IsDoubleBuffered() const
3973{
967acfb5 3974 for ( const wxWindowMSW *wnd = this;
c719013f
VZ
3975 wnd && !wnd->IsTopLevel(); wnd =
3976 wnd->GetParent() )
2e992e06 3977 {
c719013f 3978 if ( ::GetWindowLong(GetHwndOf(wnd), GWL_EXSTYLE) & WS_EX_COMPOSITED )
2e992e06 3979 return true;
2e992e06
VZ
3980 }
3981
3982 return false;
3983}
3984
42e69d6b
VZ
3985// ---------------------------------------------------------------------------
3986// owner drawn stuff
3987// ---------------------------------------------------------------------------
3988
61fef19b
VZ
3989#if (wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE) || \
3990 (wxUSE_CONTROLS && !defined(__WXUNIVERSAL__))
3991 #define WXUNUSED_UNLESS_ODRAWN(param) param
3992#else
3993 #define WXUNUSED_UNLESS_ODRAWN(param)
3994#endif
3995
3996bool
3997wxWindowMSW::MSWOnDrawItem(int WXUNUSED_UNLESS_ODRAWN(id),
3998 WXDRAWITEMSTRUCT * WXUNUSED_UNLESS_ODRAWN(itemStruct))
2bda0e17 3999{
4286a5b5 4000#if wxUSE_OWNER_DRAWN
1e6feb95
VZ
4001
4002#if wxUSE_MENUS_NATIVE
42e69d6b 4003 // is it a menu item?
6f806543
VZ
4004 DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
4005 if ( id == 0 && pDrawStruct->CtlType == ODT_MENU )
42e69d6b 4006 {
42e69d6b 4007 wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData);
03cef643 4008
2d29bf54
JS
4009 // see comment before the same test in MSWOnMeasureItem() below
4010 if ( !pMenuItem )
4011 return false;
4012
4013 wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem),
42f25dcf 4014 false, _T("MSWOnDrawItem: bad wxMenuItem pointer") );
42e69d6b 4015
7561aacd
VZ
4016 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
4017 // the DC from being released
4018 wxDCTemp dc((WXHDC)pDrawStruct->hDC);
42e69d6b
VZ
4019 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
4020 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
4021 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
4022
4023 return pMenuItem->OnDrawItem
7561aacd
VZ
4024 (
4025 dc,
4026 rect,
4027 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
4028 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
4029 );
42e69d6b 4030 }
1e6feb95 4031#endif // wxUSE_MENUS_NATIVE
42e69d6b 4032
c8e4fa8b
JS
4033#endif // USE_OWNER_DRAWN
4034
6a89f9ee 4035#if wxUSE_CONTROLS && !defined(__WXUNIVERSAL__)
c8e4fa8b 4036
c8e4fa8b 4037#if wxUSE_OWNER_DRAWN
1384636d 4038 wxControl *item = wxDynamicCast(FindItem(id), wxControl);
567be187 4039#else // !wxUSE_OWNER_DRAWN
1384636d
VS
4040 // we may still have owner-drawn buttons internally because we have to make
4041 // them owner-drawn to support colour change
35bbb0c6 4042 wxControl *item =
095b80e2
WS
4043# if wxUSE_BUTTON
4044 wxDynamicCast(FindItem(id), wxButton)
4045# else
4046 NULL
4047# endif
4048 ;
cd0b1709 4049#endif // USE_OWNER_DRAWN
567be187
VZ
4050
4051 if ( item )
4052 {
4053 return item->MSWOnDraw(itemStruct);
4054 }
4286a5b5 4055
c8e4fa8b
JS
4056#endif // wxUSE_CONTROLS
4057
08158721 4058 return false;
2bda0e17
KB
4059}
4060
61fef19b 4061bool
d1d276f2 4062wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
2bda0e17 4063{
61fef19b 4064#if wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
42e69d6b 4065 // is it a menu item?
6f806543
VZ
4066 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
4067 if ( id == 0 && pMeasureStruct->CtlType == ODT_MENU )
2d0a075d 4068 {
42e69d6b
VZ
4069 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
4070
b6afa1a3
VZ
4071 // according to Carsten Fuchs the pointer may be NULL under XP if an
4072 // MDI child frame is initially maximized, see this for more info:
4073 // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
4074 //
4075 // so silently ignore it instead of asserting
4076 if ( !pMenuItem )
4077 return false;
4078
4079 wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem),
42f25dcf 4080 false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
42e69d6b 4081
975b6bcf
VZ
4082 size_t w, h;
4083 bool rc = pMenuItem->OnMeasureItem(&w, &h);
4084
4085 pMeasureStruct->itemWidth = w;
4086 pMeasureStruct->itemHeight = h;
4087
4088 return rc;
2d0a075d 4089 }
42e69d6b 4090
567be187
VZ
4091 wxControl *item = wxDynamicCast(FindItem(id), wxControl);
4092 if ( item )
42e69d6b 4093 {
567be187 4094 return item->MSWOnMeasure(itemStruct);
42e69d6b 4095 }
d1d276f2
WS
4096#else
4097 wxUnusedVar(id);
4098 wxUnusedVar(itemStruct);
4099#endif // wxUSE_OWNER_DRAWN && wxUSE_MENUS_NATIVE
567be187 4100
08158721 4101 return false;
2bda0e17
KB
4102}
4103
42e69d6b
VZ
4104// ---------------------------------------------------------------------------
4105// colours and palettes
4106// ---------------------------------------------------------------------------
2bda0e17 4107
1e6feb95 4108bool wxWindowMSW::HandleSysColorChange()
2bda0e17 4109{
42e69d6b
VZ
4110 wxSysColourChangedEvent event;
4111 event.SetEventObject(this);
4112
23895080
VZ
4113 (void)GetEventHandler()->ProcessEvent(event);
4114
4115 // always let the system carry on the default processing to allow the
4116 // native controls to react to the colours update
08158721 4117 return false;
42e69d6b
VZ
4118}
4119
574c939e
KB
4120bool wxWindowMSW::HandleDisplayChange()
4121{
4122 wxDisplayChangedEvent event;
4123 event.SetEventObject(this);
4124
4125 return GetEventHandler()->ProcessEvent(event);
4126}
4127
04ef50df 4128#ifndef __WXMICROWIN__
42e69d6b 4129
1a784dfc 4130bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush, WXHDC hDC, WXHWND hWnd)
01c500af 4131{
3d74a760 4132#if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
43bfb798 4133 wxUnusedVar(hDC);
3d74a760
WS
4134 wxUnusedVar(hWnd);
4135#else
2bae4332 4136 wxControl *item = wxDynamicCast(FindItemByHWND(hWnd, true), wxControl);
c3732409 4137
01c500af 4138 if ( item )
1a784dfc 4139 *brush = item->MSWControlColor(hDC, hWnd);
2d0a075d 4140 else
1e6feb95 4141#endif // wxUSE_CONTROLS
01c500af 4142 *brush = NULL;
42e69d6b 4143
01c500af 4144 return *brush != NULL;
2bda0e17
KB
4145}
4146
01c500af
VZ
4147#endif // __WXMICROWIN__
4148
1e6feb95 4149bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange)
42e69d6b 4150{
574c939e 4151#if wxUSE_PALETTE
b95edd47
VZ
4152 // same as below except we don't respond to our own messages
4153 if ( hWndPalChange != GetHWND() )
4154 {
574c939e 4155 // check to see if we our our parents have a custom palette
fa21d338 4156 wxWindowMSW *win = this;
b95edd47
VZ
4157 while ( win && !win->HasCustomPalette() )
4158 {
4159 win = win->GetParent();
4160 }
4161
4162 if ( win && win->HasCustomPalette() )
4163 {
4164 // realize the palette to see whether redrawing is needed
4165 HDC hdc = ::GetDC((HWND) hWndPalChange);
4166 win->m_palette.SetHPALETTE((WXHPALETTE)
4167 ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
574c939e
KB
4168
4169 int result = ::RealizePalette(hdc);
b95edd47
VZ
4170
4171 // restore the palette (before releasing the DC)
4172 win->m_palette.SetHPALETTE((WXHPALETTE)
4173 ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
4174 ::RealizePalette(hdc);
4175 ::ReleaseDC((HWND) hWndPalChange, hdc);
4176
4177 // now check for the need to redraw
574c939e 4178 if (result > 0)
08158721 4179 ::InvalidateRect((HWND) hWndPalChange, NULL, TRUE);
574c939e 4180 }
b95edd47
VZ
4181
4182 }
4183#endif // wxUSE_PALETTE
574c939e 4184
42e69d6b
VZ
4185 wxPaletteChangedEvent event(GetId());
4186 event.SetEventObject(this);
4187 event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
2d0a075d 4188
42e69d6b
VZ
4189 return GetEventHandler()->ProcessEvent(event);
4190}
4191
a5e84126
JS
4192bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture)
4193{
63e819f2
VS
4194 // notify windows on the capture stack about lost capture
4195 // (see http://sourceforge.net/tracker/index.php?func=detail&aid=1153662&group_id=9863&atid=109863):
72f8c792 4196 wxWindowBase::NotifyCaptureLost();
a5e84126 4197
72f8c792 4198 wxWindow *win = wxFindWinFromHandle(hWndGainedCapture);
63e819f2
VS
4199 wxMouseCaptureChangedEvent event(GetId(), win);
4200 event.SetEventObject(this);
a5e84126
JS
4201 return GetEventHandler()->ProcessEvent(event);
4202}
4203
3c96418b
JG
4204bool wxWindowMSW::HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam)
4205{
4206 // despite MSDN saying "(This message cannot be sent directly to a window.)"
4207 // we need to send this to child windows (it is only sent to top-level
4208 // windows) so {list,tree}ctrls can adjust their font size if necessary
4209 // this is exactly how explorer does it to enable the font size changes
4210
4211 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
4212 while ( node )
4213 {
4214 // top-level windows already get this message from the system
4215 wxWindow *win = node->GetData();
4216 if ( !win->IsTopLevel() )
4217 {
4218 ::SendMessage(GetHwndOf(win), WM_SETTINGCHANGE, wParam, lParam);
4219 }
4220
4221 node = node->GetNext();
4222 }
4223
3c96418b
JG
4224 // let the system handle it
4225 return false;
4226}
4227
1e6feb95 4228bool wxWindowMSW::HandleQueryNewPalette()
42e69d6b 4229{
574c939e
KB
4230
4231#if wxUSE_PALETTE
4232 // check to see if we our our parents have a custom palette
fa21d338 4233 wxWindowMSW *win = this;
574c939e
KB
4234 while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent();
4235 if (win->HasCustomPalette()) {
4236 /* realize the palette to see whether redrawing is needed */
3a3c8603 4237 HDC hdc = ::GetDC((HWND) GetHWND());
574c939e 4238 win->m_palette.SetHPALETTE( (WXHPALETTE)
b95edd47 4239 ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), FALSE) );
574c939e
KB
4240
4241 int result = ::RealizePalette(hdc);
4242 /* restore the palette (before releasing the DC) */
4243 win->m_palette.SetHPALETTE( (WXHPALETTE)
b95edd47 4244 ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), TRUE) );
574c939e
KB
4245 ::RealizePalette(hdc);
4246 ::ReleaseDC((HWND) GetHWND(), hdc);
4247 /* now check for the need to redraw */
4248 if (result > 0)
4249 ::InvalidateRect((HWND) GetHWND(), NULL, TRUE);
4250 }
b95edd47 4251#endif // wxUSE_PALETTE
574c939e 4252
42e69d6b
VZ
4253 wxQueryNewPaletteEvent event(GetId());
4254 event.SetEventObject(this);
4255
4256 return GetEventHandler()->ProcessEvent(event) && event.GetPaletteRealized();
4257}
4258
4259// Responds to colour changes: passes event on to children.
574c939e 4260void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
42e69d6b 4261{
90c1530a
VZ
4262 // the top level window also reset the standard colour map as it might have
4263 // changed (there is no need to do it for the non top level windows as we
4264 // only have to do it once)
4265 if ( IsTopLevel() )
4266 {
4267 // FIXME-MT
08158721 4268 gs_hasStdCmap = false;
90c1530a 4269 }
222ed1d6 4270 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
42e69d6b
VZ
4271 while ( node )
4272 {
23895080
VZ
4273 // Only propagate to non-top-level windows because Windows already
4274 // sends this event to all top-level ones
4275 wxWindow *win = node->GetData();
4276 if ( !win->IsTopLevel() )
42e69d6b 4277 {
23895080
VZ
4278 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
4279 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
4280 // the standard controls
4281 ::SendMessage(GetHwndOf(win), WM_SYSCOLORCHANGE, 0, 0);
564b2609 4282 }
42e69d6b 4283
23895080
VZ
4284 node = node->GetNext();
4285 }
2bda0e17
KB
4286}
4287
90c1530a
VZ
4288extern wxCOLORMAP *wxGetStdColourMap()
4289{
4290 static COLORREF s_stdColours[wxSTD_COL_MAX];
4291 static wxCOLORMAP s_cmap[wxSTD_COL_MAX];
4292
4293 if ( !gs_hasStdCmap )
4294 {
08158721 4295 static bool s_coloursInit = false;
90c1530a
VZ
4296
4297 if ( !s_coloursInit )
4298 {
4299 // When a bitmap is loaded, the RGB values can change (apparently
4300 // because Windows adjusts them to care for the old programs always
4301 // using 0xc0c0c0 while the transparent colour for the new Windows
4302 // versions is different). But we do this adjustment ourselves so
4303 // we want to avoid Windows' "help" and for this we need to have a
4304 // reference bitmap which can tell us what the RGB values change
4305 // to.
e5dbcb50 4306 wxLogNull logNo; // suppress error if we couldn't load the bitmap
90c1530a
VZ
4307 wxBitmap stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
4308 if ( stdColourBitmap.Ok() )
4309 {
4310 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
4311 wxASSERT_MSG( stdColourBitmap.GetWidth() == wxSTD_COL_MAX,
4312 _T("forgot to update wxBITMAP_STD_COLOURS!") );
4313
4314 wxMemoryDC memDC;
4315 memDC.SelectObject(stdColourBitmap);
4316
4317 wxColour colour;
4318 for ( size_t i = 0; i < WXSIZEOF(s_stdColours); i++ )
4319 {
4320 memDC.GetPixel(i, 0, &colour);
4321 s_stdColours[i] = wxColourToRGB(colour);
4322 }
4323 }
4324 else // wxBITMAP_STD_COLOURS couldn't be loaded
4325 {
4326 s_stdColours[0] = RGB(000,000,000); // black
4327 s_stdColours[1] = RGB(128,128,128); // dark grey
4328 s_stdColours[2] = RGB(192,192,192); // light grey
4329 s_stdColours[3] = RGB(255,255,255); // white
4330 //s_stdColours[4] = RGB(000,000,255); // blue
4331 //s_stdColours[5] = RGB(255,000,255); // magenta
4332 }
4333
08158721 4334 s_coloursInit = true;
90c1530a
VZ
4335 }
4336
08158721 4337 gs_hasStdCmap = true;
90c1530a
VZ
4338
4339 // create the colour map
4340#define INIT_CMAP_ENTRY(col) \
4341 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
4342 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
4343
4344 INIT_CMAP_ENTRY(BTNTEXT);
4345 INIT_CMAP_ENTRY(BTNSHADOW);
4346 INIT_CMAP_ENTRY(BTNFACE);
4347 INIT_CMAP_ENTRY(BTNHIGHLIGHT);
4348
4349#undef INIT_CMAP_ENTRY
4350 }
4351
4352 return s_cmap;
4353}
4354
42e69d6b
VZ
4355// ---------------------------------------------------------------------------
4356// painting
4357// ---------------------------------------------------------------------------
4358
1e6feb95 4359bool wxWindowMSW::HandlePaint()
2bda0e17 4360{
42e69d6b
VZ
4361 HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
4362 if ( !hRegion )
f6bcfd97 4363 wxLogLastError(wxT("CreateRectRgn"));
42e69d6b 4364 if ( ::GetUpdateRgn(GetHwnd(), hRegion, FALSE) == ERROR )
f6bcfd97 4365 wxLogLastError(wxT("GetUpdateRgn"));
c085e333 4366
42e69d6b 4367 m_updateRegion = wxRegion((WXHRGN) hRegion);
c085e333 4368
42e69d6b
VZ
4369 wxPaintEvent event(m_windowId);
4370 event.SetEventObject(this);
2bda0e17 4371
1e6feb95
VZ
4372 bool processed = GetEventHandler()->ProcessEvent(event);
4373
4374 // note that we must generate NC event after the normal one as otherwise
4375 // BeginPaint() will happily overwrite our decorations with the background
4376 // colour
4377 wxNcPaintEvent eventNc(m_windowId);
4378 eventNc.SetEventObject(this);
4379 GetEventHandler()->ProcessEvent(eventNc);
4380
4381 return processed;
2bda0e17
KB
4382}
4383
63da7df7 4384// Can be called from an application's OnPaint handler
1e6feb95 4385void wxWindowMSW::OnPaint(wxPaintEvent& event)
63da7df7 4386{
1e6feb95
VZ
4387#ifdef __WXUNIVERSAL__
4388 event.Skip();
4389#else
63da7df7
JS
4390 HDC hDC = (HDC) wxPaintDC::FindDCInCache((wxWindow*) event.GetEventObject());
4391 if (hDC != 0)
4392 {
4393 MSWDefWindowProc(WM_PAINT, (WPARAM) hDC, 0);
4394 }
1e6feb95 4395#endif
63da7df7
JS
4396}
4397
1e6feb95 4398bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc)
a23fd0e1 4399{
e0e6ac8a 4400 wxDCTemp dc(hdc, GetClientSize());
c085e333 4401
1e6feb95
VZ
4402 dc.SetHDC(hdc);
4403 dc.SetWindow((wxWindow *)this);
c085e333 4404
2bda0e17 4405 wxEraseEvent event(m_windowId, &dc);
42e69d6b 4406 event.SetEventObject(this);
a23fd0e1 4407 bool rc = GetEventHandler()->ProcessEvent(event);
c085e333 4408
7561aacd 4409 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
a23fd0e1 4410 dc.SelectOldObjects(hdc);
a23fd0e1
VZ
4411
4412 return rc;
2bda0e17
KB
4413}
4414
8681b094
VZ
4415void wxWindowMSW::OnEraseBackground(wxEraseEvent& event)
4416{
52c3e064
VZ
4417 // standard non top level controls (i.e. except the dialogs) always erase
4418 // their background themselves in HandleCtlColor() or have some control-
4419 // specific ways to set the colours (common controls)
4420 if ( IsOfStandardClass() && !IsTopLevel() )
b8335252 4421 {
c5bd3c62
VZ
4422 event.Skip();
4423 return;
4424 }
b8335252 4425
c5bd3c62
VZ
4426 if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM )
4427 {
4428 // don't skip the event here, custom background means that the app
4429 // is drawing it itself in its OnPaint(), so don't draw it at all
4430 // now to avoid flicker
4431 return;
4432 }
8681b094 4433
8681b094 4434
c5bd3c62 4435 // do default background painting
c3732409 4436 if ( !DoEraseBackground(GetHdcOf(*event.GetDC())) )
c5bd3c62
VZ
4437 {
4438 // let the system paint the background
4439 event.Skip();
4440 }
4441}
4442
c3732409 4443bool wxWindowMSW::DoEraseBackground(WXHDC hDC)
c581abbc 4444{
c3732409
VZ
4445 HBRUSH hbr = (HBRUSH)MSWGetBgBrush(hDC);
4446 if ( !hbr )
c581abbc
VZ
4447 return false;
4448
c3732409 4449 wxFillRect(GetHwnd(), (HDC)hDC, hbr);
c581abbc
VZ
4450
4451 return true;
4452}
4453
c3732409 4454WXHBRUSH
2bae4332 4455wxWindowMSW::MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC), WXHWND hWnd)
c5bd3c62 4456{
accbb1e7
VZ
4457 if ( m_hasBgCol )
4458 {
8d075f8d
VZ
4459 // our background colour applies to:
4460 // 1. this window itself, always
4461 // 2. all children unless the colour is "not inheritable"
c3732409
VZ
4462 // 3. even if it is not inheritable, our immediate transparent
4463 // children should still inherit it -- but not any transparent
4464 // children because it would look wrong if a child of non
4465 // transparent child would show our bg colour when the child itself
4466 // does not
2bae4332
VZ
4467 wxWindow *win = wxFindWinFromHandle(hWnd);
4468 if ( win == this ||
c3732409 4469 m_inheritBgCol ||
2bae4332
VZ
4470 (win && win->HasTransparentBackground() &&
4471 win->GetParent() == this) )
accbb1e7 4472 {
c3732409
VZ
4473 // draw children with the same colour as the parent
4474 wxBrush *
4475 brush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour());
4476
4477 return (WXHBRUSH)GetHbrushOf(*brush);
accbb1e7
VZ
4478 }
4479 }
4480
c3732409 4481 return 0;
c5bd3c62 4482}
8681b094 4483
2bae4332 4484WXHBRUSH wxWindowMSW::MSWGetBgBrush(WXHDC hDC, WXHWND hWndToPaint)
bdd1a35d 4485{
2bae4332
VZ
4486 if ( !hWndToPaint )
4487 hWndToPaint = GetHWND();
bdd1a35d 4488
c3732409 4489 for ( wxWindowMSW *win = this; win; win = win->GetParent() )
c5bd3c62 4490 {
2bae4332 4491 WXHBRUSH hBrush = win->MSWGetBgBrushForChild(hDC, hWndToPaint);
c5bd3c62
VZ
4492 if ( hBrush )
4493 return hBrush;
24cb4019 4494
c3732409
VZ
4495 // background is not inherited beyond top level windows
4496 if ( win->IsTopLevel() )
24cb4019 4497 break;
01c500af 4498 }
c5bd3c62
VZ
4499
4500 return 0;
8681b094
VZ
4501}
4502
b728a212 4503bool wxWindowMSW::HandlePrintClient(WXHDC hDC)
1a784dfc 4504{
b728a212
JG
4505 // we receive this message when DrawThemeParentBackground() is
4506 // called from def window proc of several controls under XP and we
4507 // must draw properly themed background here
4508 //
4509 // note that naively I'd expect filling the client rect with the
4510 // brush returned by MSWGetBgBrush() work -- but for some reason it
4511 // doesn't and we have to call parents MSWPrintChild() which is
4512 // supposed to call DrawThemeBackground() with appropriate params
4513 //
4514 // also note that in this case lParam == PRF_CLIENT but we're
4515 // clearly expected to paint the background and nothing else!
4516
4517 if ( IsTopLevel() || InheritsBackgroundColour() )
4518 return false;
4519
4520 // sometimes we don't want the parent to handle it at all, instead
4521 // return whatever value this window wants
4522 if ( !MSWShouldPropagatePrintChild() )
4523 return MSWPrintChild(hDC, (wxWindow *)this);
4524
4525 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
4526 {
4527 if ( win->MSWPrintChild(hDC, (wxWindow *)this) )
4528 return true;
4529
4530 if ( win->IsTopLevel() || win->InheritsBackgroundColour() )
4531 break;
4532 }
4533
1a784dfc
VZ
4534 return false;
4535}
4536
42e69d6b
VZ
4537// ---------------------------------------------------------------------------
4538// moving and resizing
4539// ---------------------------------------------------------------------------
4540
1e6feb95 4541bool wxWindowMSW::HandleMinimize()
42e69d6b
VZ
4542{
4543 wxIconizeEvent event(m_windowId);
4544 event.SetEventObject(this);
2d0a075d 4545
42e69d6b 4546 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
4547}
4548
1e6feb95 4549bool wxWindowMSW::HandleMaximize()
2bda0e17 4550{
42e69d6b
VZ
4551 wxMaximizeEvent event(m_windowId);
4552 event.SetEventObject(this);
c085e333 4553
42e69d6b
VZ
4554 return GetEventHandler()->ProcessEvent(event);
4555}
2bda0e17 4556
1e6feb95 4557bool wxWindowMSW::HandleMove(int x, int y)
42e69d6b 4558{
907173e5
WS
4559 wxPoint point(x,y);
4560 wxMoveEvent event(point, m_windowId);
42e69d6b
VZ
4561 event.SetEventObject(this);
4562
4563 return GetEventHandler()->ProcessEvent(event);
4564}
4565
5706de1c
JS
4566bool wxWindowMSW::HandleMoving(wxRect& rect)
4567{
4568 wxMoveEvent event(rect, m_windowId);
4569 event.SetEventObject(this);
577baeef 4570
5706de1c
JS
4571 bool rc = GetEventHandler()->ProcessEvent(event);
4572 if (rc)
4573 rect = event.GetRect();
4574 return rc;
4575}
4576
4bc0f25e 4577bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h), WXUINT wParam)
42e69d6b 4578{
c3723477
JS
4579#if USE_DEFERRED_SIZING
4580 // when we resize this window, its children are probably going to be
4581 // repositioned as well, prepare to use DeferWindowPos() for them
4582 int numChildren = 0;
4583 for ( HWND child = ::GetWindow(GetHwndOf(this), GW_CHILD);
4584 child;
4585 child = ::GetWindow(child, GW_HWNDNEXT) )
4586 {
4587 numChildren ++;
4588 }
4589
3fca879c 4590 // Protect against valid m_hDWP being overwritten
c3723477
JS
4591 bool useDefer = false;
4592
3f48c8e2
VZ
4593 if ( numChildren > 1 )
4594 {
c3723477 4595 if (!m_hDWP)
3fca879c 4596 {
c3723477
JS
4597 m_hDWP = (WXHANDLE)::BeginDeferWindowPos(numChildren);
4598 if ( !m_hDWP )
4599 {
4600 wxLogLastError(_T("BeginDeferWindowPos"));
4601 }
4602 if (m_hDWP)
4603 useDefer = true;
3f48c8e2
VZ
4604 }
4605 }
f7040b5f 4606#endif // USE_DEFERRED_SIZING
42e69d6b 4607
3f48c8e2
VZ
4608 // update this window size
4609 bool processed = false;
4bc0f25e
VZ
4610 switch ( wParam )
4611 {
4612 default:
4613 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
4614 // fall through nevertheless
4615
4616 case SIZE_MAXHIDE:
4617 case SIZE_MAXSHOW:
4618 // we're not interested in these messages at all
4619 break;
4620
4621 case SIZE_MINIMIZED:
4622 processed = HandleMinimize();
4623 break;
4624
4625 case SIZE_MAXIMIZED:
a4d1972d 4626 /* processed = */ HandleMaximize();
4bc0f25e
VZ
4627 // fall through to send a normal size event as well
4628
4629 case SIZE_RESTORED:
4630 // don't use w and h parameters as they specify the client size
4631 // while according to the docs EVT_SIZE handler is supposed to
4632 // receive the total size
4633 wxSizeEvent event(GetSize(), m_windowId);
4634 event.SetEventObject(this);
4635
4636 processed = GetEventHandler()->ProcessEvent(event);
4637 }
4638
c3723477 4639#if USE_DEFERRED_SIZING
3f48c8e2 4640 // and finally change the positions of all child windows at once
c3723477 4641 if ( useDefer && m_hDWP )
3f48c8e2
VZ
4642 {
4643 // reset m_hDWP to NULL so that child windows don't try to use our
4644 // m_hDWP after we call EndDeferWindowPos() on it (this shouldn't
4645 // happen anyhow normally but who knows what weird flow of control we
4646 // may have depending on what the users EVT_SIZE handler does...)
4647 HDWP hDWP = (HDWP)m_hDWP;
4648 m_hDWP = NULL;
3fca879c 4649
3f48c8e2
VZ
4650 // do put all child controls in place at once
4651 if ( !::EndDeferWindowPos(hDWP) )
4652 {
4653 wxLogLastError(_T("EndDeferWindowPos"));
4654 }
c3723477 4655
da78f3b1 4656 // Reset our children's pending pos/size values.
c3723477
JS
4657 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
4658 node;
4659 node = node->GetNext() )
4660 {
82e3664e 4661 wxWindowMSW *child = node->GetData();
67644c1d
RD
4662 child->m_pendingPosition = wxDefaultPosition;
4663 child->m_pendingSize = wxDefaultSize;
c3723477 4664 }
3f48c8e2 4665 }
7d86a2d4 4666#endif // USE_DEFERRED_SIZING
3f48c8e2 4667
4bc0f25e 4668 return processed;
42e69d6b
VZ
4669}
4670
5706de1c
JS
4671bool wxWindowMSW::HandleSizing(wxRect& rect)
4672{
4673 wxSizeEvent event(rect, m_windowId);
4674 event.SetEventObject(this);
577baeef 4675
5706de1c
JS
4676 bool rc = GetEventHandler()->ProcessEvent(event);
4677 if (rc)
4678 rect = event.GetRect();
4679 return rc;
4680}
4681
0c0d1521 4682bool wxWindowMSW::HandleGetMinMaxInfo(void *WXUNUSED_IN_WINCE(mmInfo))
42e69d6b 4683{
7f0586ef 4684#ifdef __WXWINCE__
08158721 4685 return false;
7f0586ef 4686#else
42e69d6b
VZ
4687 MINMAXINFO *info = (MINMAXINFO *)mmInfo;
4688
08158721 4689 bool rc = false;
b2d5a7ee 4690
e7dda1ff
VS
4691 int minWidth = GetMinWidth(),
4692 minHeight = GetMinHeight(),
4693 maxWidth = GetMaxWidth(),
4694 maxHeight = GetMaxHeight();
42e69d6b 4695
422d0ff0 4696 if ( minWidth != wxDefaultCoord )
2d0a075d 4697 {
e7dda1ff 4698 info->ptMinTrackSize.x = minWidth;
08158721 4699 rc = true;
2d0a075d 4700 }
2bda0e17 4701
422d0ff0 4702 if ( minHeight != wxDefaultCoord )
42e69d6b 4703 {
e7dda1ff 4704 info->ptMinTrackSize.y = minHeight;
08158721 4705 rc = true;
42e69d6b 4706 }
2bda0e17 4707
422d0ff0 4708 if ( maxWidth != wxDefaultCoord )
42e69d6b 4709 {
e7dda1ff 4710 info->ptMaxTrackSize.x = maxWidth;
08158721 4711 rc = true;
2d0a075d 4712 }
2bda0e17 4713
422d0ff0 4714 if ( maxHeight != wxDefaultCoord )
42e69d6b 4715 {
e7dda1ff 4716 info->ptMaxTrackSize.y = maxHeight;
08158721 4717 rc = true;
42e69d6b 4718 }
2bda0e17 4719
42e69d6b 4720 return rc;
7f0586ef 4721#endif
42e69d6b 4722}
2d0a075d 4723
42e69d6b
VZ
4724// ---------------------------------------------------------------------------
4725// command messages
4726// ---------------------------------------------------------------------------
4727
1e6feb95 4728bool wxWindowMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
42e69d6b 4729{
1e6feb95 4730#if wxUSE_MENUS_NATIVE
8c290175 4731 if ( !cmd && wxCurrentPopupMenu )
42e69d6b
VZ
4732 {
4733 wxMenu *popupMenu = wxCurrentPopupMenu;
4734 wxCurrentPopupMenu = NULL;
4735
4736 return popupMenu->MSWCommand(cmd, id);
4737 }
1e6feb95 4738#endif // wxUSE_MENUS_NATIVE
42e69d6b 4739
8c290175 4740 wxWindow *win = NULL;
71292fab
VZ
4741
4742 // first try to find it from HWND - this works even with the broken
4743 // programs using the same ids for different controls
4744 if ( control )
42e69d6b 4745 {
71292fab 4746 win = wxFindWinFromHandle(control);
b853f898 4747 }
2f4ef631 4748
71292fab
VZ
4749 // try the id
4750 if ( !win )
b853f898 4751 {
71292fab
VZ
4752 // must cast to a signed type before comparing with other ids!
4753 win = FindItem((signed short)id);
42e69d6b
VZ
4754 }
4755
4756 if ( win )
b94ae1ea 4757 {
42e69d6b 4758 return win->MSWCommand(cmd, id);
b94ae1ea
VZ
4759 }
4760
4761 // the messages sent from the in-place edit control used by the treectrl
4762 // for label editing have id == 0, but they should _not_ be treated as menu
4763 // messages (they are EN_XXX ones, in fact) so don't translate anything
4764 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
4765 if ( !control )
a84fc80b 4766 {
b94ae1ea
VZ
4767 // If no child window, it may be an accelerator, e.g. for a popup menu
4768 // command
a84fc80b
JS
4769
4770 wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED);
4771 event.SetEventObject(this);
4772 event.SetId(id);
4773 event.SetInt(id);
b94ae1ea
VZ
4774
4775 return GetEventHandler()->ProcessEvent(event);
a84fc80b 4776 }
6fe19057
VZ
4777 else
4778 {
01d2bf4d 4779#if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
6fe19057
VZ
4780 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
4781 // notifications to its parent which we want to reflect back to
4782 // wxSpinCtrl
4783 wxSpinCtrl *spin = wxSpinCtrl::GetSpinForTextCtrl(control);
4784 if ( spin && spin->ProcessTextCommand(cmd, id) )
08158721 4785 return true;
6fe19057 4786#endif // wxUSE_SPINCTRL
42e69d6b 4787
01d2bf4d
WS
4788#if wxUSE_CHOICE && defined(__SMARTPHONE__)
4789 // the listbox ctrl which is logically part of wxChoice sends WM_COMMAND
4790 // notifications to its parent which we want to reflect back to
4791 // wxChoice
4792 wxChoice *choice = wxChoice::GetChoiceForListBox(control);
4793 if ( choice && choice->MSWCommand(cmd, id) )
4794 return true;
4795#endif
4796 }
4797
08158721 4798 return false;
2bda0e17
KB
4799}
4800
42e69d6b
VZ
4801// ---------------------------------------------------------------------------
4802// mouse events
4803// ---------------------------------------------------------------------------
4804
1e6feb95
VZ
4805void wxWindowMSW::InitMouseEvent(wxMouseEvent& event,
4806 int x, int y,
4807 WXUINT flags)
42e69d6b 4808{
1e6feb95
VZ
4809 // our client coords are not quite the same as Windows ones
4810 wxPoint pt = GetClientAreaOrigin();
4811 event.m_x = x - pt.x;
4812 event.m_y = y - pt.y;
4813
4814 event.m_shiftDown = (flags & MK_SHIFT) != 0;
4815 event.m_controlDown = (flags & MK_CONTROL) != 0;
4816 event.m_leftDown = (flags & MK_LBUTTON) != 0;
4817 event.m_middleDown = (flags & MK_MBUTTON) != 0;
4818 event.m_rightDown = (flags & MK_RBUTTON) != 0;
1fdf858b 4819 event.m_altDown = ::GetKeyState(VK_MENU) < 0;
1e6feb95 4820
f0b1ccde 4821#ifndef __WXWINCE__
1bf77ee5 4822 event.SetTimestamp(::GetMessageTime());
f0b1ccde
JS
4823#endif
4824
687706f5 4825 event.SetEventObject(this);
fb35f0c7 4826 event.SetId(GetId());
42e69d6b
VZ
4827
4828#if wxUSE_MOUSEEVENT_HACK
c358ea41
VZ
4829 gs_lastMouseEvent.pos = ClientToScreen(wxPoint(x, y));
4830 gs_lastMouseEvent.type = event.GetEventType();
42e69d6b 4831#endif // wxUSE_MOUSEEVENT_HACK
2bda0e17
KB
4832}
4833
42b1fb63 4834#ifdef __WXWINCE__
dfafa702
VZ
4835// Windows doesn't send the mouse events to the static controls (which are
4836// transparent in the sense that their WM_NCHITTEST handler returns
4837// HTTRANSPARENT) at all but we want all controls to receive the mouse events
4838// and so we manually check if we don't have a child window under mouse and if
4839// we do, send the event to it instead of the window Windows had sent WM_XXX
4840// to.
4841//
4842// Notice that this is not done for the mouse move events because this could
4843// (would?) be too slow, but only for clicks which means that the static texts
4844// still don't get move, enter nor leave events.
42b1fb63 4845static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y)
dfafa702
VZ
4846{
4847 wxCHECK_MSG( x && y, win, _T("NULL pointer in FindWindowForMouseEvent") );
4848
4849 // first try to find a non transparent child: this allows us to send events
4850 // to a static text which is inside a static box, for example
4851 POINT pt = { *x, *y };
4852 HWND hwnd = GetHwndOf(win),
4853 hwndUnderMouse;
4854
7f0586ef
JS
4855#ifdef __WXWINCE__
4856 hwndUnderMouse = ::ChildWindowFromPoint
4857 (
4858 hwnd,
4859 pt
4860 );
4861#else
dfafa702
VZ
4862 hwndUnderMouse = ::ChildWindowFromPointEx
4863 (
4864 hwnd,
4865 pt,
4866 CWP_SKIPINVISIBLE |
4867 CWP_SKIPDISABLED |
4868 CWP_SKIPTRANSPARENT
4869 );
7f0586ef 4870#endif
dfafa702
VZ
4871
4872 if ( !hwndUnderMouse || hwndUnderMouse == hwnd )
dfafa702
VZ
4873 {
4874 // now try any child window at all
4875 hwndUnderMouse = ::ChildWindowFromPoint(hwnd, pt);
4876 }
4877
4878 // check that we have a child window which is susceptible to receive mouse
4879 // events: for this it must be shown and enabled
4880 if ( hwndUnderMouse &&
4881 hwndUnderMouse != hwnd &&
4882 ::IsWindowVisible(hwndUnderMouse) &&
4883 ::IsWindowEnabled(hwndUnderMouse) )
4884 {
4885 wxWindow *winUnderMouse = wxFindWinFromHandle((WXHWND)hwndUnderMouse);
4886 if ( winUnderMouse )
4887 {
4888 // translate the mouse coords to the other window coords
4889 win->ClientToScreen(x, y);
4890 winUnderMouse->ScreenToClient(x, y);
4891
4892 win = winUnderMouse;
4893 }
4894 }
4895
4896 return win;
4897}
42b1fb63 4898#endif // __WXWINCE__
dfafa702 4899
1e6feb95 4900bool wxWindowMSW::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags)
2bda0e17 4901{
42e69d6b 4902 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
34621cc5 4903 // WM_MOUSELAST, so it's enough to subtract WM_MOUSEMOVE == WM_MOUSEFIRST
42e69d6b
VZ
4904 // from the message id and take the value in the table to get wxWin event
4905 // id
4906 static const wxEventType eventsMouse[] =
4907 {
4908 wxEVT_MOTION,
4909 wxEVT_LEFT_DOWN,
4910 wxEVT_LEFT_UP,
4911 wxEVT_LEFT_DCLICK,
4912 wxEVT_RIGHT_DOWN,
4913 wxEVT_RIGHT_UP,
4914 wxEVT_RIGHT_DCLICK,
4915 wxEVT_MIDDLE_DOWN,
4916 wxEVT_MIDDLE_UP,
4917 wxEVT_MIDDLE_DCLICK
4918 };
2bda0e17 4919
42e69d6b
VZ
4920 wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]);
4921 InitMouseEvent(event, x, y, flags);
4922
4923 return GetEventHandler()->ProcessEvent(event);
4924}
4925
1e6feb95 4926bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags)
42e69d6b
VZ
4927{
4928 if ( !m_mouseInWindow )
2bda0e17 4929 {
1e6feb95
VZ
4930 // it would be wrong to assume that just because we get a mouse move
4931 // event that the mouse is inside the window: although this is usually
4932 // true, it is not if we had captured the mouse, so we need to check
4933 // the mouse coordinates here
4934 if ( !HasCapture() || IsMouseInWindow() )
4935 {
4936 // Generate an ENTER event
08158721 4937 m_mouseInWindow = true;
e5297b7f 4938
4e5c6c33 4939#ifdef HAVE_TRACKMOUSEEVENT
aafb9978
VZ
4940 typedef BOOL (WINAPI *_TrackMouseEvent_t)(LPTRACKMOUSEEVENT);
4941#ifdef __WXWINCE__
4942 static const _TrackMouseEvent_t
4943 s_pfn_TrackMouseEvent = _TrackMouseEvent;
4944#else // !__WXWINCE__
4945 static _TrackMouseEvent_t s_pfn_TrackMouseEvent;
4946 static bool s_initDone = false;
4947 if ( !s_initDone )
4948 {
4949 wxLogNull noLog;
4950
4951 wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM);
4952 if ( dllComCtl32.IsLoaded() )
4953 {
4954 s_pfn_TrackMouseEvent = (_TrackMouseEvent_t)
4955 dllComCtl32.GetSymbol(_T("_TrackMouseEvent"));
4956 }
4957
4958 s_initDone = true;
4e5c6c33 4959
aafb9978
VZ
4960 // notice that it's ok to unload comctl32.dll here as it won't
4961 // be really unloaded, being still in use because we link to it
4962 // statically too
4963 }
4964
4965 if ( s_pfn_TrackMouseEvent )
4966#endif // __WXWINCE__/!__WXWINCE__
4967 {
4968 WinStruct<TRACKMOUSEEVENT> trackinfo;
4e5c6c33 4969
aafb9978
VZ
4970 trackinfo.dwFlags = TME_LEAVE;
4971 trackinfo.hwndTrack = GetHwnd();
4972
4973 (*s_pfn_TrackMouseEvent)(&trackinfo);
4974 }
4e5c6c33
VZ
4975#endif // HAVE_TRACKMOUSEEVENT
4976
1e6feb95
VZ
4977 wxMouseEvent event(wxEVT_ENTER_WINDOW);
4978 InitMouseEvent(event, x, y, flags);
42e69d6b 4979
1e6feb95
VZ
4980 (void)GetEventHandler()->ProcessEvent(event);
4981 }
42e69d6b 4982 }
cff58b52 4983#ifdef HAVE_TRACKMOUSEEVENT
aafb9978 4984 else // mouse not in window
cff58b52
KH
4985 {
4986 // Check if we need to send a LEAVE event
4987 // Windows doesn't send WM_MOUSELEAVE if the mouse has been captured so
4988 // send it here if we are using native mouse leave tracking
4989 if ( HasCapture() && !IsMouseInWindow() )
4990 {
4991 GenerateMouseLeave();
4992 }
4993 }
1ca78aa1 4994#endif // HAVE_TRACKMOUSEEVENT
42e69d6b
VZ
4995
4996#if wxUSE_MOUSEEVENT_HACK
c358ea41
VZ
4997 // Windows often generates mouse events even if mouse position hasn't
4998 // changed (http://article.gmane.org/gmane.comp.lib.wxwidgets.devel/66576)
4999 //
5000 // Filter this out as it can result in unexpected behaviour compared to
5001 // other platforms
5002 if ( gs_lastMouseEvent.type == wxEVT_RIGHT_DOWN ||
5003 gs_lastMouseEvent.type == wxEVT_LEFT_DOWN ||
5004 gs_lastMouseEvent.type == wxEVT_MIDDLE_DOWN ||
5005 gs_lastMouseEvent.type == wxEVT_MOTION )
5006 {
5007 if ( ClientToScreen(wxPoint(x, y)) == gs_lastMouseEvent.pos )
5008 {
5009 gs_lastMouseEvent.type = wxEVT_MOTION;
42e69d6b 5010
c358ea41
VZ
5011 return false;
5012 }
42e69d6b
VZ
5013 }
5014#endif // wxUSE_MOUSEEVENT_HACK
5015
5016 return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags);
5017}
5018
d2c52078 5019
24ce4c18 5020bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam)
d2c52078
RD
5021{
5022#if wxUSE_MOUSEWHEEL
3c297348
VZ
5023 // notice that WM_MOUSEWHEEL position is in screen coords (as it's
5024 // forwarded up to the parent by DefWindowProc()) and not in the client
5025 // ones as all the other messages, translate them to the client coords for
5026 // consistency
5027 const wxPoint
5028 pt = ScreenToClient(wxPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
d2c52078 5029 wxMouseEvent event(wxEVT_MOUSEWHEEL);
3c297348 5030 InitMouseEvent(event, pt.x, pt.y, LOWORD(wParam));
d2c52078
RD
5031 event.m_wheelRotation = (short)HIWORD(wParam);
5032 event.m_wheelDelta = WHEEL_DELTA;
5033
0f7a546d
RD
5034 static int s_linesPerRotation = -1;
5035 if ( s_linesPerRotation == -1 )
5036 {
5037 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
5038 &s_linesPerRotation, 0))
5039 {
5040 // this is not supposed to happen
5041 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
5042
5043 // the default is 3, so use it if SystemParametersInfo() failed
5044 s_linesPerRotation = 3;
5045 }
5046 }
d2c52078 5047
0f7a546d 5048 event.m_linesPerAction = s_linesPerRotation;
d2c52078 5049 return GetEventHandler()->ProcessEvent(event);
0f7a546d 5050
51e4e266
VZ
5051#else // !wxUSE_MOUSEWHEEL
5052 wxUnusedVar(wParam);
5053 wxUnusedVar(lParam);
38caaa61 5054
08158721 5055 return false;
51e4e266 5056#endif // wxUSE_MOUSEWHEEL/!wxUSE_MOUSEWHEEL
d2c52078
RD
5057}
5058
51e4e266
VZ
5059void wxWindowMSW::GenerateMouseLeave()
5060{
5061 m_mouseInWindow = false;
5062
5063 int state = 0;
5064 if ( wxIsShiftDown() )
5065 state |= MK_SHIFT;
5066 if ( wxIsCtrlDown() )
5067 state |= MK_CONTROL;
5068
5069 // Only the high-order bit should be tested
5070 if ( GetKeyState( VK_LBUTTON ) & (1<<15) )
5071 state |= MK_LBUTTON;
5072 if ( GetKeyState( VK_MBUTTON ) & (1<<15) )
5073 state |= MK_MBUTTON;
5074 if ( GetKeyState( VK_RBUTTON ) & (1<<15) )
5075 state |= MK_RBUTTON;
5076
5077 POINT pt;
f2325516
JS
5078#ifdef __WXWINCE__
5079 if ( !::GetCursorPosWinCE(&pt) )
5080#else
51e4e266 5081 if ( !::GetCursorPos(&pt) )
f2325516 5082#endif
51e4e266
VZ
5083 {
5084 wxLogLastError(_T("GetCursorPos"));
5085 }
5086
5087 // we need to have client coordinates here for symmetry with
5088 // wxEVT_ENTER_WINDOW
5089 RECT rect = wxGetWindowRect(GetHwnd());
5090 pt.x -= rect.left;
5091 pt.y -= rect.top;
5092
5093 wxMouseEvent event(wxEVT_LEAVE_WINDOW);
5094 InitMouseEvent(event, pt.x, pt.y, state);
5095
5096 (void)GetEventHandler()->ProcessEvent(event);
5097}
d2c52078 5098
42e69d6b
VZ
5099// ---------------------------------------------------------------------------
5100// keyboard handling
5101// ---------------------------------------------------------------------------
5102
c42404a5
VZ
5103// create the key event of the given type for the given key - used by
5104// HandleChar and HandleKeyDown/Up
1e6feb95 5105wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType,
b09bda68 5106 int id,
9c7df356
VZ
5107 WXLPARAM lParam,
5108 WXWPARAM wParam) const
c42404a5
VZ
5109{
5110 wxKeyEvent event(evType);
5111 event.SetId(GetId());
3f7bc32b
VZ
5112 event.m_shiftDown = wxIsShiftDown();
5113 event.m_controlDown = wxIsCtrlDown();
c42404a5
VZ
5114 event.m_altDown = (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN;
5115
687706f5 5116 event.SetEventObject((wxWindow *)this); // const_cast
c42404a5 5117 event.m_keyCode = id;
0d9b2c16 5118#if wxUSE_UNICODE
32b13913 5119 event.m_uniChar = (wxChar) wParam;
0d9b2c16 5120#endif
9c7df356
VZ
5121 event.m_rawCode = (wxUint32) wParam;
5122 event.m_rawFlags = (wxUint32) lParam;
f0b1ccde 5123#ifndef __WXWINCE__
1bf77ee5 5124 event.SetTimestamp(::GetMessageTime());
f0b1ccde 5125#endif
c42404a5
VZ
5126
5127 // translate the position to client coords
5128 POINT pt;
f2325516
JS
5129#ifdef __WXWINCE__
5130 GetCursorPosWinCE(&pt);
5131#else
c42404a5 5132 GetCursorPos(&pt);
f2325516 5133#endif
c42404a5
VZ
5134 RECT rect;
5135 GetWindowRect(GetHwnd(),&rect);
5136 pt.x -= rect.left;
5137 pt.y -= rect.top;
5138
5139 event.m_x = pt.x;
5140 event.m_y = pt.y;
5141
5142 return event;
5143}
5144
08158721 5145// isASCII is true only when we're called from WM_CHAR handler and not from
42e69d6b 5146// WM_KEYDOWN one
1e6feb95 5147bool wxWindowMSW::HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII)
42e69d6b
VZ
5148{
5149 int id;
42e69d6b
VZ
5150 if ( isASCII )
5151 {
42e69d6b 5152 id = wParam;
2d0a075d 5153 }
9c7df356 5154 else // we're called from WM_KEYDOWN
c42404a5 5155 {
6121a198
VZ
5156 // don't pass lParam to wxCharCodeMSWToWX() here because we don't want
5157 // to get numpad key codes: CHAR events should use the logical keys
5158 // such as WXK_HOME instead of WXK_NUMPAD_HOME which is for KEY events
5159 id = wxCharCodeMSWToWX(wParam);
9c7df356 5160 if ( id == 0 )
c42404a5 5161 {
9c7df356 5162 // it's ASCII and will be processed here only when called from
08158721
DS
5163 // WM_CHAR (i.e. when isASCII = true), don't process it now
5164 return false;
c42404a5 5165 }
9c7df356 5166 }
42e69d6b 5167
9c7df356 5168 wxKeyEvent event(CreateKeyEvent(wxEVT_CHAR, id, lParam, wParam));
2b5f62a0
VZ
5169
5170 // the alphanumeric keys produced by pressing AltGr+something on European
5171 // keyboards have both Ctrl and Alt modifiers which may confuse the user
5172 // code as, normally, keys with Ctrl and/or Alt don't result in anything
5173 // alphanumeric, so pretend that there are no modifiers at all (the
5174 // KEY_DOWN event would still have the correct modifiers if they're really
5175 // needed)
5176 if ( event.m_controlDown && event.m_altDown &&
5177 (id >= 32 && id < 256) )
9c7df356 5178 {
2b5f62a0 5179 event.m_controlDown =
08158721 5180 event.m_altDown = false;
2d0a075d 5181 }
c42404a5 5182
9c7df356 5183 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
5184}
5185
1e6feb95 5186bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 5187{
ff792344 5188 int id = wxCharCodeMSWToWX(wParam, lParam);
2bda0e17 5189
c42404a5
VZ
5190 if ( !id )
5191 {
5192 // normal ASCII char
42e69d6b
VZ
5193 id = wParam;
5194 }
5195
b60978b2
VZ
5196 wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, id, lParam, wParam));
5197 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
5198}
5199
1e6feb95 5200bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 5201{
ff792344 5202 int id = wxCharCodeMSWToWX(wParam, lParam);
2bda0e17 5203
c42404a5
VZ
5204 if ( !id )
5205 {
5206 // normal ASCII char
42e69d6b 5207 id = wParam;
2d0a075d 5208 }
2bda0e17 5209
b60978b2
VZ
5210 wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_UP, id, lParam, wParam));
5211 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
5212}
5213
0c0d1521
WS
5214int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel),
5215 WXLPARAM WXUNUSED_IN_WINCE(lParam))
b74cce40 5216{
7f0586ef
JS
5217 // FIXME: implement GetMenuItemCount for WinCE, possibly
5218 // in terms of GetMenuItemInfo
5219#ifndef __WXWINCE__
b74cce40
VZ
5220 const HMENU hmenu = (HMENU)lParam;
5221
5222 MENUITEMINFO mii;
5223 wxZeroMemory(mii);
5224 mii.cbSize = sizeof(MENUITEMINFO);
c70ffbdb
VZ
5225
5226 // we could use MIIM_FTYPE here as we only need to know if the item is
5227 // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but
5228 // MIIM_FTYPE is not supported under Win95
b74cce40
VZ
5229 mii.fMask = MIIM_TYPE | MIIM_DATA;
5230
5231 // find if we have this letter in any owner drawn item
5232 const int count = ::GetMenuItemCount(hmenu);
5233 for ( int i = 0; i < count; i++ )
5234 {
c70ffbdb
VZ
5235 // previous loop iteration could modify it, reset it back before
5236 // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData
5237 mii.cch = 0;
5238
b74cce40
VZ
5239 if ( ::GetMenuItemInfo(hmenu, i, TRUE, &mii) )
5240 {
5241 if ( mii.fType == MFT_OWNERDRAW )
5242 {
5243 // dwItemData member of the MENUITEMINFO is a
5244 // pointer to the associated wxMenuItem -- see the
5245 // menu creation code
5246 wxMenuItem *item = (wxMenuItem*)mii.dwItemData;
5247
5248 const wxChar *p = wxStrchr(item->GetText(), _T('&'));
5249 while ( p++ )
5250 {
5251 if ( *p == _T('&') )
5252 {
5253 // this is not the accel char, find the real one
5254 p = wxStrchr(p + 1, _T('&'));
5255 }
5256 else // got the accel char
5257 {
5258 // FIXME-UNICODE: this comparison doesn't risk to work
5259 // for non ASCII accelerator characters I'm afraid, but
5260 // what can we do?
907173e5 5261 if ( (wchar_t)wxToupper(*p) == (wchar_t)chAccel )
b74cce40
VZ
5262 {
5263 return i;
5264 }
5265 else
5266 {
5267 // this one doesn't match
5268 break;
5269 }
5270 }
5271 }
5272 }
5273 }
e39af974 5274 else // failed to get the menu text?
b74cce40 5275 {
c70ffbdb 5276 // it's not fatal, so don't show error, but still log it
b74cce40
VZ
5277 wxLogLastError(_T("GetMenuItemInfo"));
5278 }
5279 }
7f0586ef 5280#endif
b74cce40
VZ
5281 return wxNOT_FOUND;
5282}
5283
78c91815
VZ
5284bool wxWindowMSW::HandleClipboardEvent( WXUINT nMsg )
5285{
5286 const wxEventType type = ( nMsg == WM_CUT ) ? wxEVT_COMMAND_TEXT_CUT :
5287 ( nMsg == WM_COPY ) ? wxEVT_COMMAND_TEXT_COPY :
5288 /*( nMsg == WM_PASTE ) ? */ wxEVT_COMMAND_TEXT_PASTE;
5289 wxClipboardTextEvent evt(type, GetId());
5290
5291 evt.SetEventObject(this);
5292
5293 return GetEventHandler()->ProcessEvent(evt);
5294}
5295
42e69d6b
VZ
5296// ---------------------------------------------------------------------------
5297// joystick
5298// ---------------------------------------------------------------------------
5299
1e6feb95 5300bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
2bda0e17 5301{
8cb172b4 5302#ifdef JOY_BUTTON1
42e69d6b
VZ
5303 int change = 0;
5304 if ( flags & JOY_BUTTON1CHG )
5305 change = wxJOY_BUTTON1;
5306 if ( flags & JOY_BUTTON2CHG )
5307 change = wxJOY_BUTTON2;
5308 if ( flags & JOY_BUTTON3CHG )
5309 change = wxJOY_BUTTON3;
5310 if ( flags & JOY_BUTTON4CHG )
5311 change = wxJOY_BUTTON4;
2bda0e17 5312
42e69d6b
VZ
5313 int buttons = 0;
5314 if ( flags & JOY_BUTTON1 )
5315 buttons |= wxJOY_BUTTON1;
5316 if ( flags & JOY_BUTTON2 )
5317 buttons |= wxJOY_BUTTON2;
5318 if ( flags & JOY_BUTTON3 )
5319 buttons |= wxJOY_BUTTON3;
5320 if ( flags & JOY_BUTTON4 )
5321 buttons |= wxJOY_BUTTON4;
c085e333 5322
42e69d6b
VZ
5323 // the event ids aren't consecutive so we can't use table based lookup
5324 int joystick;
5325 wxEventType eventType;
5326 switch ( msg )
5327 {
5328 case MM_JOY1MOVE:
5329 joystick = 1;
5330 eventType = wxEVT_JOY_MOVE;
5331 break;
2bda0e17 5332
42e69d6b
VZ
5333 case MM_JOY2MOVE:
5334 joystick = 2;
5335 eventType = wxEVT_JOY_MOVE;
5336 break;
2bda0e17 5337
42e69d6b
VZ
5338 case MM_JOY1ZMOVE:
5339 joystick = 1;
5340 eventType = wxEVT_JOY_ZMOVE;
5341 break;
2bda0e17 5342
42e69d6b
VZ
5343 case MM_JOY2ZMOVE:
5344 joystick = 2;
5345 eventType = wxEVT_JOY_ZMOVE;
5346 break;
2bda0e17 5347
42e69d6b
VZ
5348 case MM_JOY1BUTTONDOWN:
5349 joystick = 1;
5350 eventType = wxEVT_JOY_BUTTON_DOWN;
5351 break;
2bda0e17 5352
42e69d6b
VZ
5353 case MM_JOY2BUTTONDOWN:
5354 joystick = 2;
5355 eventType = wxEVT_JOY_BUTTON_DOWN;
5356 break;
2bda0e17 5357
42e69d6b
VZ
5358 case MM_JOY1BUTTONUP:
5359 joystick = 1;
5360 eventType = wxEVT_JOY_BUTTON_UP;
5361 break;
5362
5363 case MM_JOY2BUTTONUP:
5364 joystick = 2;
5365 eventType = wxEVT_JOY_BUTTON_UP;
5366 break;
5367
5368 default:
223d09f6 5369 wxFAIL_MSG(wxT("no such joystick event"));
2d0a075d 5370
08158721 5371 return false;
2d0a075d 5372 }
2bda0e17 5373
42e69d6b
VZ
5374 wxJoystickEvent event(eventType, buttons, joystick, change);
5375 event.SetPosition(wxPoint(x, y));
5376 event.SetEventObject(this);
c085e333 5377
42e69d6b 5378 return GetEventHandler()->ProcessEvent(event);
8cb172b4 5379#else
991420e6
WS
5380 wxUnusedVar(msg);
5381 wxUnusedVar(x);
5382 wxUnusedVar(y);
5383 wxUnusedVar(flags);
08158721 5384 return false;
8cb172b4 5385#endif
2bda0e17
KB
5386}
5387
42e69d6b
VZ
5388// ---------------------------------------------------------------------------
5389// scrolling
5390// ---------------------------------------------------------------------------
5391
1e6feb95 5392bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam,
f4f734c1 5393 WXWORD pos, WXHWND control)
35bbb0c6 5394{
a0d924c6 5395 if ( control && control != m_hWnd ) // Prevent infinite recursion
cc2b7472 5396 {
42e69d6b
VZ
5397 wxWindow *child = wxFindWinFromHandle(control);
5398 if ( child )
5399 return child->MSWOnScroll(orientation, wParam, pos, control);
cc2b7472 5400 }
2bda0e17 5401
9145664b 5402 wxScrollWinEvent event;
42e69d6b
VZ
5403 event.SetPosition(pos);
5404 event.SetOrientation(orientation);
687706f5 5405 event.SetEventObject(this);
cc2b7472 5406
42e69d6b
VZ
5407 switch ( wParam )
5408 {
5409 case SB_TOP:
687706f5 5410 event.SetEventType(wxEVT_SCROLLWIN_TOP);
42e69d6b 5411 break;
cc2b7472 5412
42e69d6b 5413 case SB_BOTTOM:
687706f5 5414 event.SetEventType(wxEVT_SCROLLWIN_BOTTOM);
42e69d6b 5415 break;
cc2b7472 5416
42e69d6b 5417 case SB_LINEUP:
687706f5 5418 event.SetEventType(wxEVT_SCROLLWIN_LINEUP);
42e69d6b 5419 break;
2bda0e17 5420
42e69d6b 5421 case SB_LINEDOWN:
687706f5 5422 event.SetEventType(wxEVT_SCROLLWIN_LINEDOWN);
42e69d6b 5423 break;
a02eb1d2 5424
42e69d6b 5425 case SB_PAGEUP:
687706f5 5426 event.SetEventType(wxEVT_SCROLLWIN_PAGEUP);
42e69d6b 5427 break;
2bda0e17 5428
42e69d6b 5429 case SB_PAGEDOWN:
687706f5 5430 event.SetEventType(wxEVT_SCROLLWIN_PAGEDOWN);
42e69d6b 5431 break;
2bda0e17 5432
42e69d6b 5433 case SB_THUMBPOSITION:
feda3011 5434 case SB_THUMBTRACK:
f6bcfd97
BP
5435 // under Win32, the scrollbar range and position are 32 bit integers,
5436 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
5437 // explicitly query the scrollbar for the correct position (this must
5438 // be done only for these two SB_ events as they are the only one
5439 // carrying the scrollbar position)
5440 {
0cf5de11 5441 WinStruct<SCROLLINFO> scrollInfo;
f6bcfd97
BP
5442 scrollInfo.fMask = SIF_TRACKPOS;
5443
5444 if ( !::GetScrollInfo(GetHwnd(),
5445 orientation == wxHORIZONTAL ? SB_HORZ
5446 : SB_VERT,
5447 &scrollInfo) )
5448 {
3103e8a9 5449 // Not necessarily an error, if there are no scrollbars yet.
f676b387 5450 // wxLogLastError(_T("GetScrollInfo"));
f6bcfd97
BP
5451 }
5452
5453 event.SetPosition(scrollInfo.nTrackPos);
5454 }
f6bcfd97 5455
687706f5 5456 event.SetEventType( wParam == SB_THUMBPOSITION
f6bcfd97 5457 ? wxEVT_SCROLLWIN_THUMBRELEASE
687706f5 5458 : wxEVT_SCROLLWIN_THUMBTRACK );
42e69d6b 5459 break;
c085e333 5460
42e69d6b 5461 default:
08158721 5462 return false;
564b2609 5463 }
2bda0e17 5464
42e69d6b 5465 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
5466}
5467
42e69d6b
VZ
5468// ===========================================================================
5469// global functions
5470// ===========================================================================
5471
7a5e53ab 5472void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font)
2bda0e17 5473{
42e69d6b
VZ
5474 TEXTMETRIC tm;
5475 HDC dc = ::GetDC((HWND) wnd);
42e69d6b 5476 HFONT was = 0;
35bbb0c6 5477
7a5e53ab
VS
5478 // the_font.UseResource();
5479 // the_font.RealizeResource();
c57c2993 5480 HFONT fnt = (HFONT)the_font.GetResourceHandle(); // const_cast
7a5e53ab
VS
5481 if ( fnt )
5482 was = (HFONT) SelectObject(dc,fnt);
35bbb0c6 5483
42e69d6b 5484 GetTextMetrics(dc, &tm);
7a5e53ab 5485 if ( fnt && was )
2d0a075d 5486 {
42e69d6b 5487 SelectObject(dc,was);
2d0a075d 5488 }
42e69d6b 5489 ReleaseDC((HWND)wnd, dc);
0655ad29
VZ
5490
5491 if ( x )
5492 *x = tm.tmAveCharWidth;
5493 if ( y )
5494 *y = tm.tmHeight + tm.tmExternalLeading;
2bda0e17 5495
7a5e53ab 5496 // the_font.ReleaseResource();
42e69d6b 5497}
c085e333 5498
5004c3ad
JG
5499// use the "extended" bit (24) of lParam to distinguish extended keys
5500// from normal keys as the same key is sent
ed5bc8f1
VZ
5501static inline
5502int ChooseNormalOrExtended(int lParam, int keyNormal, int keyExtended)
5004c3ad 5503{
ed5bc8f1
VZ
5504 // except that if lParam is 0, it means we don't have real lParam from
5505 // WM_KEYDOWN but are just translating just a VK constant (e.g. done from
5506 // msw/treectrl.cpp when processing TVN_KEYDOWN) -- then assume this is a
5507 // non-numpad (hence extended) key as this is a more common case
5508 return !lParam || (lParam & (1 << 24)) ? keyExtended : keyNormal;
5004c3ad
JG
5509}
5510
d5c21b02
VZ
5511// this array contains the Windows virtual key codes which map one to one to
5512// WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below
5513//
5514// note that keys having a normal and numpad version (e.g. WXK_HOME and
5515// WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1
5516static const struct wxKeyMapping
5517{
5518 int vk;
5519 wxKeyCode wxk;
5520} gs_specialKeys[] =
5521{
5522 { VK_CANCEL, WXK_CANCEL },
5523 { VK_BACK, WXK_BACK },
5524 { VK_TAB, WXK_TAB },
5525 { VK_CLEAR, WXK_CLEAR },
5526 { VK_SHIFT, WXK_SHIFT },
5527 { VK_CONTROL, WXK_CONTROL },
5528 { VK_MENU , WXK_ALT },
5529 { VK_PAUSE, WXK_PAUSE },
5530 { VK_CAPITAL, WXK_CAPITAL },
5531 { VK_SPACE, WXK_SPACE },
5532 { VK_ESCAPE, WXK_ESCAPE },
5533 { VK_SELECT, WXK_SELECT },
5534 { VK_PRINT, WXK_PRINT },
5535 { VK_EXECUTE, WXK_EXECUTE },
e59c2b2d
VZ
5536 { VK_SNAPSHOT, WXK_SNAPSHOT },
5537 { VK_HELP, WXK_HELP },
d5c21b02
VZ
5538
5539 { VK_NUMPAD0, WXK_NUMPAD0 },
5540 { VK_NUMPAD1, WXK_NUMPAD1 },
5541 { VK_NUMPAD2, WXK_NUMPAD2 },
5542 { VK_NUMPAD3, WXK_NUMPAD3 },
5543 { VK_NUMPAD4, WXK_NUMPAD4 },
5544 { VK_NUMPAD5, WXK_NUMPAD5 },
5545 { VK_NUMPAD6, WXK_NUMPAD6 },
5546 { VK_NUMPAD7, WXK_NUMPAD7 },
5547 { VK_NUMPAD8, WXK_NUMPAD8 },
5548 { VK_NUMPAD9, WXK_NUMPAD9 },
5549 { VK_MULTIPLY, WXK_NUMPAD_MULTIPLY },
5550 { VK_ADD, WXK_NUMPAD_ADD },
5551 { VK_SUBTRACT, WXK_NUMPAD_SUBTRACT },
5552 { VK_DECIMAL, WXK_NUMPAD_DECIMAL },
5553 { VK_DIVIDE, WXK_NUMPAD_DIVIDE },
5554
5555 { VK_F1, WXK_F1 },
5556 { VK_F2, WXK_F2 },
5557 { VK_F3, WXK_F3 },
5558 { VK_F4, WXK_F4 },
5559 { VK_F5, WXK_F5 },
5560 { VK_F6, WXK_F6 },
5561 { VK_F7, WXK_F7 },
5562 { VK_F8, WXK_F8 },
5563 { VK_F9, WXK_F9 },
5564 { VK_F10, WXK_F10 },
5565 { VK_F11, WXK_F11 },
5566 { VK_F12, WXK_F12 },
5567 { VK_F13, WXK_F13 },
5568 { VK_F14, WXK_F14 },
5569 { VK_F15, WXK_F15 },
5570 { VK_F16, WXK_F16 },
5571 { VK_F17, WXK_F17 },
5572 { VK_F18, WXK_F18 },
5573 { VK_F19, WXK_F19 },
5574 { VK_F20, WXK_F20 },
5575 { VK_F21, WXK_F21 },
5576 { VK_F22, WXK_F22 },
5577 { VK_F23, WXK_F23 },
5578 { VK_F24, WXK_F24 },
5579
5580 { VK_NUMLOCK, WXK_NUMLOCK },
5581 { VK_SCROLL, WXK_SCROLL },
5582
5583#ifdef VK_APPS
5584 { VK_LWIN, WXK_WINDOWS_LEFT },
5585 { VK_RWIN, WXK_WINDOWS_RIGHT },
5586 { VK_APPS, WXK_WINDOWS_MENU },
5587#endif // VK_APPS defined
5588};
5589
42e69d6b
VZ
5590// Returns 0 if was a normal ASCII value, not a special key. This indicates that
5591// the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
d5c21b02 5592int wxCharCodeMSWToWX(int vk, WXLPARAM lParam)
42e69d6b 5593{
d5c21b02
VZ
5594 // check the table first
5595 for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ )
5596 {
5597 if ( gs_specialKeys[n].vk == vk )
5598 return gs_specialKeys[n].wxk;
5599 }
9c7df356 5600
d5c21b02
VZ
5601 // keys requiring special handling
5602 int wxk;
5603 switch ( vk )
5604 {
e77c5d96
VZ
5605 // the mapping for these keys may be incorrect on non-US keyboards so
5606 // maybe we shouldn't map them to ASCII values at all
d5c21b02
VZ
5607 case VK_OEM_1: wxk = ';'; break;
5608 case VK_OEM_PLUS: wxk = '+'; break;
5609 case VK_OEM_COMMA: wxk = ','; break;
5610 case VK_OEM_MINUS: wxk = '-'; break;
5611 case VK_OEM_PERIOD: wxk = '.'; break;
5612 case VK_OEM_2: wxk = '/'; break;
5613 case VK_OEM_3: wxk = '~'; break;
5614 case VK_OEM_4: wxk = '['; break;
5615 case VK_OEM_5: wxk = '\\'; break;
5616 case VK_OEM_6: wxk = ']'; break;
5617 case VK_OEM_7: wxk = '\''; break;
702c4208 5618
5004c3ad 5619 // handle extended keys
413553cc 5620 case VK_PRIOR:
d5c21b02 5621 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PAGEUP, WXK_PAGEUP);
413553cc 5622 break;
d5c21b02 5623
413553cc 5624 case VK_NEXT:
d5c21b02 5625 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_PAGEDOWN, WXK_PAGEDOWN);
413553cc 5626 break;
d5c21b02 5627
413553cc 5628 case VK_END:
d5c21b02 5629 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_END, WXK_END);
413553cc 5630 break;
d5c21b02 5631
413553cc 5632 case VK_HOME:
d5c21b02 5633 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_HOME, WXK_HOME);
413553cc 5634 break;
d5c21b02 5635
413553cc 5636 case VK_LEFT:
d5c21b02 5637 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_LEFT, WXK_LEFT);
413553cc 5638 break;
d5c21b02 5639
413553cc 5640 case VK_UP:
d5c21b02 5641 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_UP, WXK_UP);
413553cc 5642 break;
d5c21b02 5643
413553cc 5644 case VK_RIGHT:
d5c21b02 5645 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_RIGHT, WXK_RIGHT);
413553cc 5646 break;
d5c21b02 5647
413553cc 5648 case VK_DOWN:
d5c21b02 5649 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_DOWN, WXK_DOWN);
413553cc 5650 break;
d5c21b02 5651
413553cc 5652 case VK_INSERT:
d5c21b02 5653 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_INSERT, WXK_INSERT);
413553cc 5654 break;
d5c21b02 5655
413553cc 5656 case VK_DELETE:
d5c21b02 5657 wxk = ChooseNormalOrExtended(lParam, WXK_NUMPAD_DELETE, WXK_DELETE);
413553cc 5658 break;
d5c21b02 5659
ff792344 5660 case VK_RETURN:
ed5bc8f1
VZ
5661 // don't use ChooseNormalOrExtended() here as the keys are reversed
5662 // here: numpad enter is the extended one
d5c21b02 5663 wxk = lParam && (lParam & (1 << 24)) ? WXK_NUMPAD_ENTER : WXK_RETURN;
ff792344
VZ
5664 break;
5665
f6bcfd97 5666 default:
d5c21b02
VZ
5667 wxk = 0;
5668 }
5669
5670 return wxk;
5671}
5672
5673WXWORD wxCharCodeWXToMSW(int wxk, bool *isVirtual)
5674{
5675 if ( isVirtual )
5676 *isVirtual = true;
5677
5678 // check the table first
5679 for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ )
5680 {
5681 if ( gs_specialKeys[n].wxk == wxk )
5682 return gs_specialKeys[n].vk;
5683 }
5684
5685 // and then check for special keys not included in the table
5686 WXWORD vk;
5687 switch ( wxk )
5688 {
71403278
VZ
5689 case WXK_PAGEUP:
5690 case WXK_NUMPAD_PAGEUP:
5691 vk = VK_PRIOR;
5692 break;
5693
5694 case WXK_PAGEDOWN:
5695 case WXK_NUMPAD_PAGEDOWN:
5696 vk = VK_NEXT;
5697 break;
5698
5699 case WXK_END:
5700 case WXK_NUMPAD_END:
5701 vk = VK_END;
5702 break;
5703
5704 case WXK_HOME:
5705 case WXK_NUMPAD_HOME:
5706 vk = VK_HOME;
5707 break;
5708
5709 case WXK_LEFT:
5710 case WXK_NUMPAD_LEFT:
5711 vk = VK_LEFT;
5712 break;
5713
5714 case WXK_UP:
5715 case WXK_NUMPAD_UP:
5716 vk = VK_UP;
5717 break;
5718
5719 case WXK_RIGHT:
5720 case WXK_NUMPAD_RIGHT:
5721 vk = VK_RIGHT;
5722 break;
5723
5724 case WXK_DOWN:
5725 case WXK_NUMPAD_DOWN:
5726 vk = VK_DOWN;
5727 break;
5728
5729 case WXK_INSERT:
5730 case WXK_NUMPAD_INSERT:
5731 vk = VK_INSERT;
5732 break;
5733
5734 case WXK_DELETE:
5735 case WXK_NUMPAD_DELETE:
5736 vk = VK_DELETE;
5737 break;
d5c21b02
VZ
5738
5739 default:
5740 if ( isVirtual )
5741 *isVirtual = false;
5742 vk = (WXWORD)wxk;
42e69d6b 5743 break;
2bda0e17 5744 }
d5c21b02
VZ
5745
5746 return vk;
5747}
5748
5749// small helper for wxGetKeyState() and wxGetMouseState()
5750static inline bool wxIsKeyDown(WXWORD vk)
5751{
5752 // the low order bit indicates whether the key was pressed since the last
5753 // call and the high order one indicates whether it is down right now and
5754 // we only want that one
5755 return (::GetAsyncKeyState(vk) & (1<<15)) != 0;
2bda0e17
KB
5756}
5757
1751226c 5758bool wxGetKeyState(wxKeyCode key)
6ed892f3 5759{
d5c21b02
VZ
5760 // although this does work under Windows, it is not supported under other
5761 // platforms so don't allow it, you must use wxGetMouseState() instead
5762 wxASSERT_MSG( key != VK_LBUTTON &&
5763 key != VK_RBUTTON &&
5764 key != VK_MBUTTON,
5765 wxT("can't use wxGetKeyState() for mouse buttons") );
6ed892f3 5766
d5c21b02 5767 const WXWORD vk = wxCharCodeWXToMSW(key);
44353523 5768
d5c21b02
VZ
5769 // if the requested key is a LED key, return true if the led is pressed
5770 if ( key == WXK_NUMLOCK || key == WXK_CAPITAL || key == WXK_SCROLL )
fdec2c05 5771 {
d5c21b02
VZ
5772 // low order bit means LED is highlighted and high order one means the
5773 // key is down; for compatibility with the other ports return true if
5774 // either one is set
5775 return ::GetKeyState(vk) != 0;
35bbb0c6 5776
fdec2c05 5777 }
d5c21b02 5778 else // normal key
84c51ddf 5779 {
d5c21b02 5780 return wxIsKeyDown(vk);
84c51ddf 5781 }
6ed892f3
RN
5782}
5783
7dd40b6f
RD
5784
5785wxMouseState wxGetMouseState()
5786{
5787 wxMouseState ms;
5788 POINT pt;
5789 GetCursorPos( &pt );
5790
5791 ms.SetX(pt.x);
5792 ms.SetY(pt.y);
d5c21b02
VZ
5793 ms.SetLeftDown(wxIsKeyDown(VK_LBUTTON));
5794 ms.SetMiddleDown(wxIsKeyDown(VK_MBUTTON));
5795 ms.SetRightDown(wxIsKeyDown(VK_RBUTTON));
dd28827a 5796
d5c21b02
VZ
5797 ms.SetControlDown(wxIsKeyDown(VK_CONTROL));
5798 ms.SetShiftDown(wxIsKeyDown(VK_SHIFT));
5799 ms.SetAltDown(wxIsKeyDown(VK_MENU));
7dd40b6f 5800// ms.SetMetaDown();
dd28827a 5801
7dd40b6f
RD
5802 return ms;
5803}
5804
5805
42e69d6b 5806wxWindow *wxGetActiveWindow()
2bda0e17 5807{
42e69d6b
VZ
5808 HWND hWnd = GetActiveWindow();
5809 if ( hWnd != 0 )
2d0a075d 5810 {
42e69d6b 5811 return wxFindWinFromHandle((WXHWND) hWnd);
2d0a075d 5812 }
42e69d6b 5813 return NULL;
2bda0e17
KB
5814}
5815
8614c467
VZ
5816extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
5817{
5818 HWND hwnd = (HWND)hWnd;
5819
5820 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
5821 // by code in msw/radiobox.cpp), for all the others we just search up the
5822 // window hierarchy
5823 wxWindow *win = (wxWindow *)NULL;
5824 if ( hwnd )
5825 {
5826 win = wxFindWinFromHandle((WXHWND)hwnd);
5827 if ( !win )
5828 {
a2242341 5829#if wxUSE_RADIOBOX
8614c467
VZ
5830 // native radiobuttons return DLGC_RADIOBUTTON here and for any
5831 // wxWindow class which overrides WM_GETDLGCODE processing to
5832 // do it as well, win would be already non NULL
a2242341 5833 if ( ::SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_RADIOBUTTON )
8614c467 5834 {
975b6bcf 5835 win = (wxWindow *)wxGetWindowUserData(hwnd);
8614c467 5836 }
a2242341
VZ
5837 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
5838#endif // wxUSE_RADIOBOX
5839
5840 // spin control text buddy window should be mapped to spin ctrl
5841 // itself so try it too
24ce4c18 5842#if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
a2242341
VZ
5843 if ( !win )
5844 {
5845 win = wxSpinCtrl::GetSpinForTextCtrl((WXHWND)hwnd);
5846 }
5847#endif // wxUSE_SPINCTRL
8614c467 5848 }
8614c467
VZ
5849 }
5850
5851 while ( hwnd && !win )
5852 {
761989ff
VZ
5853 // this is a really ugly hack needed to avoid mistakenly returning the
5854 // parent frame wxWindow for the find/replace modeless dialog HWND -
5855 // this, in turn, is needed to call IsDialogMessage() from
5856 // wxApp::ProcessMessage() as for this we must return NULL from here
5857 //
5858 // FIXME: this is clearly not the best way to do it but I think we'll
5859 // need to change HWND <-> wxWindow code more heavily than I can
5860 // do it now to fix it
c67d6888 5861#ifndef __WXMICROWIN__
761989ff
VZ
5862 if ( ::GetWindow(hwnd, GW_OWNER) )
5863 {
5864 // it's a dialog box, don't go upwards
5865 break;
5866 }
c67d6888 5867#endif
761989ff 5868
8614c467 5869 hwnd = ::GetParent(hwnd);
761989ff 5870 win = wxFindWinFromHandle((WXHWND)hwnd);
8614c467
VZ
5871 }
5872
5873 return win;
5874}
5875
7f0586ef 5876#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
04ef50df 5877
42e69d6b
VZ
5878// Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
5879// in active frames and dialogs, regardless of where the focus is.
5880static HHOOK wxTheKeyboardHook = 0;
5881static FARPROC wxTheKeyboardHookProc = 0;
5882int APIENTRY _EXPORT
5883wxKeyboardHook(int nCode, WORD wParam, DWORD lParam);
2bda0e17 5884
42e69d6b 5885void wxSetKeyboardHook(bool doIt)
2bda0e17 5886{
42e69d6b 5887 if ( doIt )
2d0a075d 5888 {
42e69d6b
VZ
5889 wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance());
5890 wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
c7527e3f 5891
8614c467 5892 GetCurrentThreadId()
42e69d6b 5893 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
8614c467 5894 );
2d0a075d 5895 }
2d0a075d 5896 else
2d0a075d 5897 {
42e69d6b 5898 UnhookWindowsHookEx(wxTheKeyboardHook);
2d0a075d 5899 }
2bda0e17
KB
5900}
5901
42e69d6b
VZ
5902int APIENTRY _EXPORT
5903wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
2bda0e17 5904{
42e69d6b
VZ
5905 DWORD hiWord = HIWORD(lParam);
5906 if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) )
43d811ea 5907 {
ff792344 5908 int id = wxCharCodeMSWToWX(wParam, lParam);
32de7d24 5909 if ( id != 0 )
43d811ea 5910 {
42e69d6b
VZ
5911 wxKeyEvent event(wxEVT_CHAR_HOOK);
5912 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
08158721 5913 event.m_altDown = true;
c085e333 5914
687706f5 5915 event.SetEventObject(NULL);
42e69d6b 5916 event.m_keyCode = id;
3f7bc32b
VZ
5917 event.m_shiftDown = wxIsShiftDown();
5918 event.m_controlDown = wxIsCtrlDown();
f0b1ccde 5919#ifndef __WXWINCE__
1bf77ee5 5920 event.SetTimestamp(::GetMessageTime());
f0b1ccde 5921#endif
42e69d6b 5922 wxWindow *win = wxGetActiveWindow();
32de7d24 5923 wxEvtHandler *handler;
42e69d6b
VZ
5924 if ( win )
5925 {
32de7d24
VZ
5926 handler = win->GetEventHandler();
5927 event.SetId(win->GetId());
42e69d6b
VZ
5928 }
5929 else
5930 {
32de7d24 5931 handler = wxTheApp;
abb74e0f 5932 event.SetId(wxID_ANY);
32de7d24
VZ
5933 }
5934
5935 if ( handler && handler->ProcessEvent(event) )
5936 {
5937 // processed
5938 return 1;
42e69d6b 5939 }
43d811ea
JS
5940 }
5941 }
32de7d24 5942
42e69d6b 5943 return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam);
4fabb575 5944}
cd4453e5
VZ
5945
5946#endif // !__WXMICROWIN__
4fabb575 5947
b2aef89b 5948#ifdef __WXDEBUG__
4a712ba3 5949const wxChar *wxGetMessageName(int message)
47cbd6da 5950{
42e69d6b
VZ
5951 switch ( message )
5952 {
4a712ba3
VZ
5953 case 0x0000: return wxT("WM_NULL");
5954 case 0x0001: return wxT("WM_CREATE");
5955 case 0x0002: return wxT("WM_DESTROY");
5956 case 0x0003: return wxT("WM_MOVE");
5957 case 0x0005: return wxT("WM_SIZE");
5958 case 0x0006: return wxT("WM_ACTIVATE");
5959 case 0x0007: return wxT("WM_SETFOCUS");
5960 case 0x0008: return wxT("WM_KILLFOCUS");
5961 case 0x000A: return wxT("WM_ENABLE");
5962 case 0x000B: return wxT("WM_SETREDRAW");
5963 case 0x000C: return wxT("WM_SETTEXT");
5964 case 0x000D: return wxT("WM_GETTEXT");
5965 case 0x000E: return wxT("WM_GETTEXTLENGTH");
5966 case 0x000F: return wxT("WM_PAINT");
5967 case 0x0010: return wxT("WM_CLOSE");
5968 case 0x0011: return wxT("WM_QUERYENDSESSION");
5969 case 0x0012: return wxT("WM_QUIT");
5970 case 0x0013: return wxT("WM_QUERYOPEN");
5971 case 0x0014: return wxT("WM_ERASEBKGND");
5972 case 0x0015: return wxT("WM_SYSCOLORCHANGE");
5973 case 0x0016: return wxT("WM_ENDSESSION");
5974 case 0x0017: return wxT("WM_SYSTEMERROR");
5975 case 0x0018: return wxT("WM_SHOWWINDOW");
5976 case 0x0019: return wxT("WM_CTLCOLOR");
5977 case 0x001A: return wxT("WM_WININICHANGE");
5978 case 0x001B: return wxT("WM_DEVMODECHANGE");
5979 case 0x001C: return wxT("WM_ACTIVATEAPP");
5980 case 0x001D: return wxT("WM_FONTCHANGE");
5981 case 0x001E: return wxT("WM_TIMECHANGE");
5982 case 0x001F: return wxT("WM_CANCELMODE");
5983 case 0x0020: return wxT("WM_SETCURSOR");
5984 case 0x0021: return wxT("WM_MOUSEACTIVATE");
5985 case 0x0022: return wxT("WM_CHILDACTIVATE");
5986 case 0x0023: return wxT("WM_QUEUESYNC");
5987 case 0x0024: return wxT("WM_GETMINMAXINFO");
5988 case 0x0026: return wxT("WM_PAINTICON");
5989 case 0x0027: return wxT("WM_ICONERASEBKGND");
5990 case 0x0028: return wxT("WM_NEXTDLGCTL");
5991 case 0x002A: return wxT("WM_SPOOLERSTATUS");
5992 case 0x002B: return wxT("WM_DRAWITEM");
5993 case 0x002C: return wxT("WM_MEASUREITEM");
5994 case 0x002D: return wxT("WM_DELETEITEM");
5995 case 0x002E: return wxT("WM_VKEYTOITEM");
5996 case 0x002F: return wxT("WM_CHARTOITEM");
5997 case 0x0030: return wxT("WM_SETFONT");
5998 case 0x0031: return wxT("WM_GETFONT");
5999 case 0x0037: return wxT("WM_QUERYDRAGICON");
6000 case 0x0039: return wxT("WM_COMPAREITEM");
6001 case 0x0041: return wxT("WM_COMPACTING");
6002 case 0x0044: return wxT("WM_COMMNOTIFY");
6003 case 0x0046: return wxT("WM_WINDOWPOSCHANGING");
6004 case 0x0047: return wxT("WM_WINDOWPOSCHANGED");
6005 case 0x0048: return wxT("WM_POWER");
6006
6007 case 0x004A: return wxT("WM_COPYDATA");
6008 case 0x004B: return wxT("WM_CANCELJOURNAL");
6009 case 0x004E: return wxT("WM_NOTIFY");
6010 case 0x0050: return wxT("WM_INPUTLANGCHANGEREQUEST");
6011 case 0x0051: return wxT("WM_INPUTLANGCHANGE");
6012 case 0x0052: return wxT("WM_TCARD");
6013 case 0x0053: return wxT("WM_HELP");
6014 case 0x0054: return wxT("WM_USERCHANGED");
6015 case 0x0055: return wxT("WM_NOTIFYFORMAT");
6016 case 0x007B: return wxT("WM_CONTEXTMENU");
6017 case 0x007C: return wxT("WM_STYLECHANGING");
6018 case 0x007D: return wxT("WM_STYLECHANGED");
6019 case 0x007E: return wxT("WM_DISPLAYCHANGE");
6020 case 0x007F: return wxT("WM_GETICON");
6021 case 0x0080: return wxT("WM_SETICON");
6022
6023 case 0x0081: return wxT("WM_NCCREATE");
6024 case 0x0082: return wxT("WM_NCDESTROY");
6025 case 0x0083: return wxT("WM_NCCALCSIZE");
6026 case 0x0084: return wxT("WM_NCHITTEST");
6027 case 0x0085: return wxT("WM_NCPAINT");
6028 case 0x0086: return wxT("WM_NCACTIVATE");
6029 case 0x0087: return wxT("WM_GETDLGCODE");
6030 case 0x00A0: return wxT("WM_NCMOUSEMOVE");
6031 case 0x00A1: return wxT("WM_NCLBUTTONDOWN");
6032 case 0x00A2: return wxT("WM_NCLBUTTONUP");
6033 case 0x00A3: return wxT("WM_NCLBUTTONDBLCLK");
6034 case 0x00A4: return wxT("WM_NCRBUTTONDOWN");
6035 case 0x00A5: return wxT("WM_NCRBUTTONUP");
6036 case 0x00A6: return wxT("WM_NCRBUTTONDBLCLK");
6037 case 0x00A7: return wxT("WM_NCMBUTTONDOWN");
6038 case 0x00A8: return wxT("WM_NCMBUTTONUP");
6039 case 0x00A9: return wxT("WM_NCMBUTTONDBLCLK");
6040 case 0x0100: return wxT("WM_KEYDOWN");
6041 case 0x0101: return wxT("WM_KEYUP");
6042 case 0x0102: return wxT("WM_CHAR");
6043 case 0x0103: return wxT("WM_DEADCHAR");
6044 case 0x0104: return wxT("WM_SYSKEYDOWN");
6045 case 0x0105: return wxT("WM_SYSKEYUP");
6046 case 0x0106: return wxT("WM_SYSCHAR");
6047 case 0x0107: return wxT("WM_SYSDEADCHAR");
6048 case 0x0108: return wxT("WM_KEYLAST");
6049
6050 case 0x010D: return wxT("WM_IME_STARTCOMPOSITION");
6051 case 0x010E: return wxT("WM_IME_ENDCOMPOSITION");
6052 case 0x010F: return wxT("WM_IME_COMPOSITION");
6053
6054 case 0x0110: return wxT("WM_INITDIALOG");
6055 case 0x0111: return wxT("WM_COMMAND");
6056 case 0x0112: return wxT("WM_SYSCOMMAND");
6057 case 0x0113: return wxT("WM_TIMER");
6058 case 0x0114: return wxT("WM_HSCROLL");
6059 case 0x0115: return wxT("WM_VSCROLL");
6060 case 0x0116: return wxT("WM_INITMENU");
6061 case 0x0117: return wxT("WM_INITMENUPOPUP");
6062 case 0x011F: return wxT("WM_MENUSELECT");
6063 case 0x0120: return wxT("WM_MENUCHAR");
6064 case 0x0121: return wxT("WM_ENTERIDLE");
6065 case 0x0200: return wxT("WM_MOUSEMOVE");
6066 case 0x0201: return wxT("WM_LBUTTONDOWN");
6067 case 0x0202: return wxT("WM_LBUTTONUP");
6068 case 0x0203: return wxT("WM_LBUTTONDBLCLK");
6069 case 0x0204: return wxT("WM_RBUTTONDOWN");
6070 case 0x0205: return wxT("WM_RBUTTONUP");
6071 case 0x0206: return wxT("WM_RBUTTONDBLCLK");
6072 case 0x0207: return wxT("WM_MBUTTONDOWN");
6073 case 0x0208: return wxT("WM_MBUTTONUP");
6074 case 0x0209: return wxT("WM_MBUTTONDBLCLK");
6075 case 0x020A: return wxT("WM_MOUSEWHEEL");
6076 case 0x0210: return wxT("WM_PARENTNOTIFY");
6077 case 0x0211: return wxT("WM_ENTERMENULOOP");
6078 case 0x0212: return wxT("WM_EXITMENULOOP");
6079
6080 case 0x0213: return wxT("WM_NEXTMENU");
6081 case 0x0214: return wxT("WM_SIZING");
6082 case 0x0215: return wxT("WM_CAPTURECHANGED");
6083 case 0x0216: return wxT("WM_MOVING");
6084 case 0x0218: return wxT("WM_POWERBROADCAST");
6085 case 0x0219: return wxT("WM_DEVICECHANGE");
6086
6087 case 0x0220: return wxT("WM_MDICREATE");
6088 case 0x0221: return wxT("WM_MDIDESTROY");
6089 case 0x0222: return wxT("WM_MDIACTIVATE");
6090 case 0x0223: return wxT("WM_MDIRESTORE");
6091 case 0x0224: return wxT("WM_MDINEXT");
6092 case 0x0225: return wxT("WM_MDIMAXIMIZE");
6093 case 0x0226: return wxT("WM_MDITILE");
6094 case 0x0227: return wxT("WM_MDICASCADE");
6095 case 0x0228: return wxT("WM_MDIICONARRANGE");
6096 case 0x0229: return wxT("WM_MDIGETACTIVE");
6097 case 0x0230: return wxT("WM_MDISETMENU");
6098 case 0x0233: return wxT("WM_DROPFILES");
6099
6100 case 0x0281: return wxT("WM_IME_SETCONTEXT");
6101 case 0x0282: return wxT("WM_IME_NOTIFY");
6102 case 0x0283: return wxT("WM_IME_CONTROL");
6103 case 0x0284: return wxT("WM_IME_COMPOSITIONFULL");
6104 case 0x0285: return wxT("WM_IME_SELECT");
6105 case 0x0286: return wxT("WM_IME_CHAR");
6106 case 0x0290: return wxT("WM_IME_KEYDOWN");
6107 case 0x0291: return wxT("WM_IME_KEYUP");
6108
6109 case 0x0300: return wxT("WM_CUT");
6110 case 0x0301: return wxT("WM_COPY");
6111 case 0x0302: return wxT("WM_PASTE");
6112 case 0x0303: return wxT("WM_CLEAR");
6113 case 0x0304: return wxT("WM_UNDO");
6114 case 0x0305: return wxT("WM_RENDERFORMAT");
6115 case 0x0306: return wxT("WM_RENDERALLFORMATS");
6116 case 0x0307: return wxT("WM_DESTROYCLIPBOARD");
6117 case 0x0308: return wxT("WM_DRAWCLIPBOARD");
6118 case 0x0309: return wxT("WM_PAINTCLIPBOARD");
6119 case 0x030A: return wxT("WM_VSCROLLCLIPBOARD");
6120 case 0x030B: return wxT("WM_SIZECLIPBOARD");
6121 case 0x030C: return wxT("WM_ASKCBFORMATNAME");
6122 case 0x030D: return wxT("WM_CHANGECBCHAIN");
6123 case 0x030E: return wxT("WM_HSCROLLCLIPBOARD");
6124 case 0x030F: return wxT("WM_QUERYNEWPALETTE");
6125 case 0x0310: return wxT("WM_PALETTEISCHANGING");
6126 case 0x0311: return wxT("WM_PALETTECHANGED");
5048c832 6127#if wxUSE_HOTKEY
4a712ba3 6128 case 0x0312: return wxT("WM_HOTKEY");
5048c832 6129#endif
c085e333 6130
2d0a075d
JS
6131 // common controls messages - although they're not strictly speaking
6132 // standard, it's nice to decode them nevertheless
a02eb1d2 6133
2d0a075d 6134 // listview
4a712ba3
VZ
6135 case 0x1000 + 0: return wxT("LVM_GETBKCOLOR");
6136 case 0x1000 + 1: return wxT("LVM_SETBKCOLOR");
6137 case 0x1000 + 2: return wxT("LVM_GETIMAGELIST");
6138 case 0x1000 + 3: return wxT("LVM_SETIMAGELIST");
6139 case 0x1000 + 4: return wxT("LVM_GETITEMCOUNT");
6140 case 0x1000 + 5: return wxT("LVM_GETITEMA");
6141 case 0x1000 + 75: return wxT("LVM_GETITEMW");
6142 case 0x1000 + 6: return wxT("LVM_SETITEMA");
6143 case 0x1000 + 76: return wxT("LVM_SETITEMW");
6144 case 0x1000 + 7: return wxT("LVM_INSERTITEMA");
6145 case 0x1000 + 77: return wxT("LVM_INSERTITEMW");
6146 case 0x1000 + 8: return wxT("LVM_DELETEITEM");
6147 case 0x1000 + 9: return wxT("LVM_DELETEALLITEMS");
6148 case 0x1000 + 10: return wxT("LVM_GETCALLBACKMASK");
6149 case 0x1000 + 11: return wxT("LVM_SETCALLBACKMASK");
6150 case 0x1000 + 12: return wxT("LVM_GETNEXTITEM");
6151 case 0x1000 + 13: return wxT("LVM_FINDITEMA");
6152 case 0x1000 + 83: return wxT("LVM_FINDITEMW");
6153 case 0x1000 + 14: return wxT("LVM_GETITEMRECT");
6154 case 0x1000 + 15: return wxT("LVM_SETITEMPOSITION");
6155 case 0x1000 + 16: return wxT("LVM_GETITEMPOSITION");
6156 case 0x1000 + 17: return wxT("LVM_GETSTRINGWIDTHA");
6157 case 0x1000 + 87: return wxT("LVM_GETSTRINGWIDTHW");
6158 case 0x1000 + 18: return wxT("LVM_HITTEST");
6159 case 0x1000 + 19: return wxT("LVM_ENSUREVISIBLE");
6160 case 0x1000 + 20: return wxT("LVM_SCROLL");
6161 case 0x1000 + 21: return wxT("LVM_REDRAWITEMS");
6162 case 0x1000 + 22: return wxT("LVM_ARRANGE");
6163 case 0x1000 + 23: return wxT("LVM_EDITLABELA");
6164 case 0x1000 + 118: return wxT("LVM_EDITLABELW");
6165 case 0x1000 + 24: return wxT("LVM_GETEDITCONTROL");
6166 case 0x1000 + 25: return wxT("LVM_GETCOLUMNA");
6167 case 0x1000 + 95: return wxT("LVM_GETCOLUMNW");
6168 case 0x1000 + 26: return wxT("LVM_SETCOLUMNA");
6169 case 0x1000 + 96: return wxT("LVM_SETCOLUMNW");
6170 case 0x1000 + 27: return wxT("LVM_INSERTCOLUMNA");
6171 case 0x1000 + 97: return wxT("LVM_INSERTCOLUMNW");
6172 case 0x1000 + 28: return wxT("LVM_DELETECOLUMN");
6173 case 0x1000 + 29: return wxT("LVM_GETCOLUMNWIDTH");
6174 case 0x1000 + 30: return wxT("LVM_SETCOLUMNWIDTH");
6175 case 0x1000 + 31: return wxT("LVM_GETHEADER");
6176 case 0x1000 + 33: return wxT("LVM_CREATEDRAGIMAGE");
6177 case 0x1000 + 34: return wxT("LVM_GETVIEWRECT");
6178 case 0x1000 + 35: return wxT("LVM_GETTEXTCOLOR");
6179 case 0x1000 + 36: return wxT("LVM_SETTEXTCOLOR");
6180 case 0x1000 + 37: return wxT("LVM_GETTEXTBKCOLOR");
6181 case 0x1000 + 38: return wxT("LVM_SETTEXTBKCOLOR");
6182 case 0x1000 + 39: return wxT("LVM_GETTOPINDEX");
6183 case 0x1000 + 40: return wxT("LVM_GETCOUNTPERPAGE");
6184 case 0x1000 + 41: return wxT("LVM_GETORIGIN");
6185 case 0x1000 + 42: return wxT("LVM_UPDATE");
6186 case 0x1000 + 43: return wxT("LVM_SETITEMSTATE");
6187 case 0x1000 + 44: return wxT("LVM_GETITEMSTATE");
6188 case 0x1000 + 45: return wxT("LVM_GETITEMTEXTA");
6189 case 0x1000 + 115: return wxT("LVM_GETITEMTEXTW");
6190 case 0x1000 + 46: return wxT("LVM_SETITEMTEXTA");
6191 case 0x1000 + 116: return wxT("LVM_SETITEMTEXTW");
6192 case 0x1000 + 47: return wxT("LVM_SETITEMCOUNT");
6193 case 0x1000 + 48: return wxT("LVM_SORTITEMS");
6194 case 0x1000 + 49: return wxT("LVM_SETITEMPOSITION32");
6195 case 0x1000 + 50: return wxT("LVM_GETSELECTEDCOUNT");
6196 case 0x1000 + 51: return wxT("LVM_GETITEMSPACING");
6197 case 0x1000 + 52: return wxT("LVM_GETISEARCHSTRINGA");
6198 case 0x1000 + 117: return wxT("LVM_GETISEARCHSTRINGW");
6199 case 0x1000 + 53: return wxT("LVM_SETICONSPACING");
6200 case 0x1000 + 54: return wxT("LVM_SETEXTENDEDLISTVIEWSTYLE");
6201 case 0x1000 + 55: return wxT("LVM_GETEXTENDEDLISTVIEWSTYLE");
6202 case 0x1000 + 56: return wxT("LVM_GETSUBITEMRECT");
6203 case 0x1000 + 57: return wxT("LVM_SUBITEMHITTEST");
6204 case 0x1000 + 58: return wxT("LVM_SETCOLUMNORDERARRAY");
6205 case 0x1000 + 59: return wxT("LVM_GETCOLUMNORDERARRAY");
6206 case 0x1000 + 60: return wxT("LVM_SETHOTITEM");
6207 case 0x1000 + 61: return wxT("LVM_GETHOTITEM");
6208 case 0x1000 + 62: return wxT("LVM_SETHOTCURSOR");
6209 case 0x1000 + 63: return wxT("LVM_GETHOTCURSOR");
6210 case 0x1000 + 64: return wxT("LVM_APPROXIMATEVIEWRECT");
6211 case 0x1000 + 65: return wxT("LVM_SETWORKAREA");
c085e333 6212
2d0a075d 6213 // tree view
4a712ba3
VZ
6214 case 0x1100 + 0: return wxT("TVM_INSERTITEMA");
6215 case 0x1100 + 50: return wxT("TVM_INSERTITEMW");
6216 case 0x1100 + 1: return wxT("TVM_DELETEITEM");
6217 case 0x1100 + 2: return wxT("TVM_EXPAND");
6218 case 0x1100 + 4: return wxT("TVM_GETITEMRECT");
6219 case 0x1100 + 5: return wxT("TVM_GETCOUNT");
6220 case 0x1100 + 6: return wxT("TVM_GETINDENT");
6221 case 0x1100 + 7: return wxT("TVM_SETINDENT");
6222 case 0x1100 + 8: return wxT("TVM_GETIMAGELIST");
6223 case 0x1100 + 9: return wxT("TVM_SETIMAGELIST");
6224 case 0x1100 + 10: return wxT("TVM_GETNEXTITEM");
6225 case 0x1100 + 11: return wxT("TVM_SELECTITEM");
6226 case 0x1100 + 12: return wxT("TVM_GETITEMA");
6227 case 0x1100 + 62: return wxT("TVM_GETITEMW");
6228 case 0x1100 + 13: return wxT("TVM_SETITEMA");
6229 case 0x1100 + 63: return wxT("TVM_SETITEMW");
6230 case 0x1100 + 14: return wxT("TVM_EDITLABELA");
6231 case 0x1100 + 65: return wxT("TVM_EDITLABELW");
6232 case 0x1100 + 15: return wxT("TVM_GETEDITCONTROL");
6233 case 0x1100 + 16: return wxT("TVM_GETVISIBLECOUNT");
6234 case 0x1100 + 17: return wxT("TVM_HITTEST");
6235 case 0x1100 + 18: return wxT("TVM_CREATEDRAGIMAGE");
6236 case 0x1100 + 19: return wxT("TVM_SORTCHILDREN");
6237 case 0x1100 + 20: return wxT("TVM_ENSUREVISIBLE");
6238 case 0x1100 + 21: return wxT("TVM_SORTCHILDRENCB");
6239 case 0x1100 + 22: return wxT("TVM_ENDEDITLABELNOW");
6240 case 0x1100 + 23: return wxT("TVM_GETISEARCHSTRINGA");
6241 case 0x1100 + 64: return wxT("TVM_GETISEARCHSTRINGW");
6242 case 0x1100 + 24: return wxT("TVM_SETTOOLTIPS");
6243 case 0x1100 + 25: return wxT("TVM_GETTOOLTIPS");
c085e333 6244
2d0a075d 6245 // header
4a712ba3
VZ
6246 case 0x1200 + 0: return wxT("HDM_GETITEMCOUNT");
6247 case 0x1200 + 1: return wxT("HDM_INSERTITEMA");
6248 case 0x1200 + 10: return wxT("HDM_INSERTITEMW");
6249 case 0x1200 + 2: return wxT("HDM_DELETEITEM");
6250 case 0x1200 + 3: return wxT("HDM_GETITEMA");
6251 case 0x1200 + 11: return wxT("HDM_GETITEMW");
6252 case 0x1200 + 4: return wxT("HDM_SETITEMA");
6253 case 0x1200 + 12: return wxT("HDM_SETITEMW");
6254 case 0x1200 + 5: return wxT("HDM_LAYOUT");
6255 case 0x1200 + 6: return wxT("HDM_HITTEST");
6256 case 0x1200 + 7: return wxT("HDM_GETITEMRECT");
6257 case 0x1200 + 8: return wxT("HDM_SETIMAGELIST");
6258 case 0x1200 + 9: return wxT("HDM_GETIMAGELIST");
6259 case 0x1200 + 15: return wxT("HDM_ORDERTOINDEX");
6260 case 0x1200 + 16: return wxT("HDM_CREATEDRAGIMAGE");
6261 case 0x1200 + 17: return wxT("HDM_GETORDERARRAY");
6262 case 0x1200 + 18: return wxT("HDM_SETORDERARRAY");
6263 case 0x1200 + 19: return wxT("HDM_SETHOTDIVIDER");
c085e333 6264
2d0a075d 6265 // tab control
4a712ba3
VZ
6266 case 0x1300 + 2: return wxT("TCM_GETIMAGELIST");
6267 case 0x1300 + 3: return wxT("TCM_SETIMAGELIST");
6268 case 0x1300 + 4: return wxT("TCM_GETITEMCOUNT");
6269 case 0x1300 + 5: return wxT("TCM_GETITEMA");
6270 case 0x1300 + 60: return wxT("TCM_GETITEMW");
6271 case 0x1300 + 6: return wxT("TCM_SETITEMA");
6272 case 0x1300 + 61: return wxT("TCM_SETITEMW");
6273 case 0x1300 + 7: return wxT("TCM_INSERTITEMA");
6274 case 0x1300 + 62: return wxT("TCM_INSERTITEMW");
6275 case 0x1300 + 8: return wxT("TCM_DELETEITEM");
6276 case 0x1300 + 9: return wxT("TCM_DELETEALLITEMS");
6277 case 0x1300 + 10: return wxT("TCM_GETITEMRECT");
6278 case 0x1300 + 11: return wxT("TCM_GETCURSEL");
6279 case 0x1300 + 12: return wxT("TCM_SETCURSEL");
6280 case 0x1300 + 13: return wxT("TCM_HITTEST");
6281 case 0x1300 + 14: return wxT("TCM_SETITEMEXTRA");
6282 case 0x1300 + 40: return wxT("TCM_ADJUSTRECT");
6283 case 0x1300 + 41: return wxT("TCM_SETITEMSIZE");
6284 case 0x1300 + 42: return wxT("TCM_REMOVEIMAGE");
6285 case 0x1300 + 43: return wxT("TCM_SETPADDING");
6286 case 0x1300 + 44: return wxT("TCM_GETROWCOUNT");
6287 case 0x1300 + 45: return wxT("TCM_GETTOOLTIPS");
6288 case 0x1300 + 46: return wxT("TCM_SETTOOLTIPS");
6289 case 0x1300 + 47: return wxT("TCM_GETCURFOCUS");
6290 case 0x1300 + 48: return wxT("TCM_SETCURFOCUS");
6291 case 0x1300 + 49: return wxT("TCM_SETMINTABWIDTH");
6292 case 0x1300 + 50: return wxT("TCM_DESELECTALL");
c085e333 6293
2d0a075d 6294 // toolbar
4a712ba3
VZ
6295 case WM_USER+1: return wxT("TB_ENABLEBUTTON");
6296 case WM_USER+2: return wxT("TB_CHECKBUTTON");
6297 case WM_USER+3: return wxT("TB_PRESSBUTTON");
6298 case WM_USER+4: return wxT("TB_HIDEBUTTON");
6299 case WM_USER+5: return wxT("TB_INDETERMINATE");
6300 case WM_USER+9: return wxT("TB_ISBUTTONENABLED");
6301 case WM_USER+10: return wxT("TB_ISBUTTONCHECKED");
6302 case WM_USER+11: return wxT("TB_ISBUTTONPRESSED");
6303 case WM_USER+12: return wxT("TB_ISBUTTONHIDDEN");
6304 case WM_USER+13: return wxT("TB_ISBUTTONINDETERMINATE");
6305 case WM_USER+17: return wxT("TB_SETSTATE");
6306 case WM_USER+18: return wxT("TB_GETSTATE");
6307 case WM_USER+19: return wxT("TB_ADDBITMAP");
6308 case WM_USER+20: return wxT("TB_ADDBUTTONS");
6309 case WM_USER+21: return wxT("TB_INSERTBUTTON");
6310 case WM_USER+22: return wxT("TB_DELETEBUTTON");
6311 case WM_USER+23: return wxT("TB_GETBUTTON");
6312 case WM_USER+24: return wxT("TB_BUTTONCOUNT");
6313 case WM_USER+25: return wxT("TB_COMMANDTOINDEX");
6314 case WM_USER+26: return wxT("TB_SAVERESTOREA");
6315 case WM_USER+76: return wxT("TB_SAVERESTOREW");
6316 case WM_USER+27: return wxT("TB_CUSTOMIZE");
6317 case WM_USER+28: return wxT("TB_ADDSTRINGA");
6318 case WM_USER+77: return wxT("TB_ADDSTRINGW");
6319 case WM_USER+29: return wxT("TB_GETITEMRECT");
6320 case WM_USER+30: return wxT("TB_BUTTONSTRUCTSIZE");
6321 case WM_USER+31: return wxT("TB_SETBUTTONSIZE");
6322 case WM_USER+32: return wxT("TB_SETBITMAPSIZE");
6323 case WM_USER+33: return wxT("TB_AUTOSIZE");
6324 case WM_USER+35: return wxT("TB_GETTOOLTIPS");
6325 case WM_USER+36: return wxT("TB_SETTOOLTIPS");
6326 case WM_USER+37: return wxT("TB_SETPARENT");
6327 case WM_USER+39: return wxT("TB_SETROWS");
6328 case WM_USER+40: return wxT("TB_GETROWS");
6329 case WM_USER+42: return wxT("TB_SETCMDID");
6330 case WM_USER+43: return wxT("TB_CHANGEBITMAP");
6331 case WM_USER+44: return wxT("TB_GETBITMAP");
6332 case WM_USER+45: return wxT("TB_GETBUTTONTEXTA");
6333 case WM_USER+75: return wxT("TB_GETBUTTONTEXTW");
6334 case WM_USER+46: return wxT("TB_REPLACEBITMAP");
6335 case WM_USER+47: return wxT("TB_SETINDENT");
6336 case WM_USER+48: return wxT("TB_SETIMAGELIST");
6337 case WM_USER+49: return wxT("TB_GETIMAGELIST");
6338 case WM_USER+50: return wxT("TB_LOADIMAGES");
6339 case WM_USER+51: return wxT("TB_GETRECT");
6340 case WM_USER+52: return wxT("TB_SETHOTIMAGELIST");
6341 case WM_USER+53: return wxT("TB_GETHOTIMAGELIST");
6342 case WM_USER+54: return wxT("TB_SETDISABLEDIMAGELIST");
6343 case WM_USER+55: return wxT("TB_GETDISABLEDIMAGELIST");
6344 case WM_USER+56: return wxT("TB_SETSTYLE");
6345 case WM_USER+57: return wxT("TB_GETSTYLE");
6346 case WM_USER+58: return wxT("TB_GETBUTTONSIZE");
6347 case WM_USER+59: return wxT("TB_SETBUTTONWIDTH");
6348 case WM_USER+60: return wxT("TB_SETMAXTEXTROWS");
6349 case WM_USER+61: return wxT("TB_GETTEXTROWS");
6350 case WM_USER+41: return wxT("TB_GETBITMAPFLAGS");
c085e333 6351
42e69d6b 6352 default:
4a712ba3
VZ
6353 static wxString s_szBuf;
6354 s_szBuf.Printf(wxT("<unknown message = %d>"), message);
6355 return s_szBuf.c_str();
42e69d6b 6356 }
47cbd6da 6357}
ea57084d 6358#endif //__WXDEBUG__
4aff28fc 6359
1e6feb95 6360static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win)
f6bcfd97
BP
6361{
6362 // prepare the DC
6363 TEXTMETRIC tm;
6364 HWND hwnd = GetHwndOf(win);
6365 HDC hdc = ::GetDC(hwnd);
6366
6367#if !wxDIALOG_UNIT_COMPATIBILITY
6368 // and select the current font into it
6369 HFONT hfont = GetHfontOf(win->GetFont());
6370 if ( hfont )
6371 {
6372 hfont = (HFONT)::SelectObject(hdc, hfont);
6373 }
6374#endif
6375
6376 // finally retrieve the text metrics from it
6377 GetTextMetrics(hdc, &tm);
6378
6379#if !wxDIALOG_UNIT_COMPATIBILITY
6380 // and clean up
6381 if ( hfont )
6382 {
6383 (void)::SelectObject(hdc, hfont);
6384 }
6385#endif
6386
6387 ::ReleaseDC(hwnd, hdc);
6388
6389 return tm;
6390}
3723b7b1
JS
6391
6392// Find the wxWindow at the current mouse position, returning the mouse
6393// position.
2b5f62a0 6394wxWindow* wxFindWindowAtPointer(wxPoint& pt)
3723b7b1 6395{
2b5f62a0
VZ
6396 pt = wxGetMousePosition();
6397 return wxFindWindowAtPoint(pt);
57591e0e
JS
6398}
6399
6400wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
6401{
6402 POINT pt2;
6403 pt2.x = pt.x;
6404 pt2.y = pt.y;
3723b7b1 6405
ab3eae34 6406 HWND hWnd = ::WindowFromPoint(pt2);
3723b7b1 6407
ab3eae34 6408 return wxGetWindowFromHWND((WXHWND)hWnd);
3723b7b1
JS
6409}
6410
6411// Get the current mouse position.
6412wxPoint wxGetMousePosition()
6413{
1772ead0 6414 POINT pt;
f2325516
JS
6415#ifdef __WXWINCE__
6416 GetCursorPosWinCE(&pt);
6417#else
1772ead0 6418 GetCursorPos( & pt );
f2325516 6419#endif
5cd16c0c 6420
1772ead0 6421 return wxPoint(pt.x, pt.y);
3723b7b1
JS
6422}
6423
5048c832 6424#if wxUSE_HOTKEY
540b6b09 6425
afafd942
JS
6426#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6427static void WinCEUnregisterHotKey(int modifiers, int id)
6428{
6429 // Register hotkeys for the hardware buttons
6430 HINSTANCE hCoreDll;
6431 typedef BOOL (WINAPI *UnregisterFunc1Proc)(UINT, UINT);
6432
6433 UnregisterFunc1Proc procUnregisterFunc;
6434 hCoreDll = LoadLibrary(_T("coredll.dll"));
6435 if (hCoreDll)
6436 {
6437 procUnregisterFunc = (UnregisterFunc1Proc)GetProcAddress(hCoreDll, _T("UnregisterFunc1"));
6438 if (procUnregisterFunc)
6439 procUnregisterFunc(modifiers, id);
6440 FreeLibrary(hCoreDll);
6441 }
6442}
6443#endif
6444
540b6b09 6445bool wxWindowMSW::RegisterHotKey(int hotkeyId, int modifiers, int keycode)
5048c832
JS
6446{
6447 UINT win_modifiers=0;
540b6b09
VZ
6448 if ( modifiers & wxMOD_ALT )
6449 win_modifiers |= MOD_ALT;
6450 if ( modifiers & wxMOD_SHIFT )
6451 win_modifiers |= MOD_SHIFT;
6452 if ( modifiers & wxMOD_CONTROL )
6453 win_modifiers |= MOD_CONTROL;
6454 if ( modifiers & wxMOD_WIN )
6455 win_modifiers |= MOD_WIN;
6456
afafd942
JS
6457#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6458 // Required for PPC and Smartphone hardware buttons
6459 if (keycode >= WXK_SPECIAL1 && keycode <= WXK_SPECIAL20)
6460 WinCEUnregisterHotKey(win_modifiers, hotkeyId);
6461#endif
6462
540b6b09
VZ
6463 if ( !::RegisterHotKey(GetHwnd(), hotkeyId, win_modifiers, keycode) )
6464 {
6465 wxLogLastError(_T("RegisterHotKey"));
5048c832 6466
08158721 6467 return false;
540b6b09
VZ
6468 }
6469
08158721 6470 return true;
5048c832
JS
6471}
6472
6473bool wxWindowMSW::UnregisterHotKey(int hotkeyId)
6474{
afafd942
JS
6475#if defined(__SMARTPHONE__) || defined(__POCKETPC__)
6476 WinCEUnregisterHotKey(MOD_WIN, hotkeyId);
6477#endif
6478
540b6b09
VZ
6479 if ( !::UnregisterHotKey(GetHwnd(), hotkeyId) )
6480 {
6481 wxLogLastError(_T("UnregisterHotKey"));
6482
08158721 6483 return false;
540b6b09
VZ
6484 }
6485
08158721 6486 return true;
5048c832
JS
6487}
6488
0b4f47a3
DS
6489#if wxUSE_ACCEL
6490
5048c832
JS
6491bool wxWindowMSW::HandleHotKey(WXWPARAM wParam, WXLPARAM lParam)
6492{
540b6b09
VZ
6493 int hotkeyId = wParam;
6494 int virtualKey = HIWORD(lParam);
6495 int win_modifiers = LOWORD(lParam);
6496
5048c832
JS
6497 wxKeyEvent event(CreateKeyEvent(wxEVT_HOTKEY, virtualKey, wParam, lParam));
6498 event.SetId(hotkeyId);
6499 event.m_shiftDown = (win_modifiers & MOD_SHIFT) != 0;
6500 event.m_controlDown = (win_modifiers & MOD_CONTROL) != 0;
6501 event.m_altDown = (win_modifiers & MOD_ALT) != 0;
6502 event.m_metaDown = (win_modifiers & MOD_WIN) != 0;
540b6b09
VZ
6503
6504 return GetEventHandler()->ProcessEvent(event);
5048c832 6505}
540b6b09 6506
0b4f47a3
DS
6507#endif // wxUSE_ACCEL
6508
540b6b09 6509#endif // wxUSE_HOTKEY
5048c832 6510
550049c2 6511// Not tested under WinCE
d79df32c 6512#ifndef __WXWINCE__
d79df32c 6513
550049c2
VZ
6514// this class installs a message hook which really wakes up our idle processing
6515// each time a WM_NULL is received (wxWakeUpIdle does this), even if we're
6516// sitting inside a local modal loop (e.g. a menu is opened or scrollbar is
6517// being dragged or even inside ::MessageBox()) and so don't control message
6518// dispatching otherwise
6519class wxIdleWakeUpModule : public wxModule
6520{
d79df32c 6521public:
3a3c8603 6522 virtual bool OnInit()
550049c2 6523 {
3a3c8603 6524 ms_hMsgHookProc = ::SetWindowsHookEx
550049c2
VZ
6525 (
6526 WH_GETMESSAGE,
6527 &wxIdleWakeUpModule::MsgHookProc,
6528 NULL,
6529 GetCurrentThreadId()
6530 );
d79df32c 6531
550049c2
VZ
6532 if ( !ms_hMsgHookProc )
6533 {
6534 wxLogLastError(_T("SetWindowsHookEx(WH_GETMESSAGE)"));
6535
6536 return false;
6537 }
6538
6539 return true;
3a3c8603 6540 }
550049c2 6541
3a3c8603 6542 virtual void OnExit()
550049c2 6543 {
3a3c8603
DS
6544 ::UnhookWindowsHookEx(wxIdleWakeUpModule::ms_hMsgHookProc);
6545 }
550049c2 6546
3a3c8603 6547 static LRESULT CALLBACK MsgHookProc(int nCode, WPARAM wParam, LPARAM lParam)
550049c2 6548 {
3a3c8603 6549 MSG *msg = (MSG*)lParam;
34ea3c74
VZ
6550
6551 // only process the message if it is actually going to be removed from
6552 // the message queue, this prevents that the same event from being
6553 // processed multiple times if now someone just called PeekMessage()
6554 if ( msg->message == WM_NULL && wParam == PM_REMOVE )
3a3c8603 6555 {
550049c2 6556 wxTheApp->ProcessPendingEvents();
3a3c8603 6557 }
550049c2 6558
3a3c8603
DS
6559 return CallNextHookEx(ms_hMsgHookProc, nCode, wParam, lParam);
6560 };
550049c2 6561
d79df32c 6562private:
3a3c8603 6563 static HHOOK ms_hMsgHookProc;
550049c2
VZ
6564
6565 DECLARE_DYNAMIC_CLASS(wxIdleWakeUpModule)
d79df32c 6566};
d79df32c 6567
550049c2
VZ
6568HHOOK wxIdleWakeUpModule::ms_hMsgHookProc = 0;
6569
6570IMPLEMENT_DYNAMIC_CLASS(wxIdleWakeUpModule, wxModule)
6571
6572#endif // __WXWINCE__
3a3c8603 6573
d26e1ab2
JS
6574#ifdef __WXWINCE__
6575
6576#if wxUSE_STATBOX
6577static void wxAdjustZOrder(wxWindow* parent)
6578{
6579 if (parent->IsKindOf(CLASSINFO(wxStaticBox)))
6580 {
6581 // Set the z-order correctly
6582 SetWindowPos((HWND) parent->GetHWND(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
6583 }
35bbb0c6 6584
d26e1ab2
JS
6585 wxWindowList::compatibility_iterator current = parent->GetChildren().GetFirst();
6586 while (current)
6587 {
6588 wxWindow *childWin = current->GetData();
6589 wxAdjustZOrder(childWin);
6590 current = current->GetNext();
6591 }
6592}
6593#endif
6594
6595// We need to adjust the z-order of static boxes in WinCE, to
6596// make 'contained' controls visible
6597void wxWindowMSW::OnInitDialog( wxInitDialogEvent& event )
6598{
6599#if wxUSE_STATBOX
6600 wxAdjustZOrder(this);
6601#endif
35bbb0c6 6602
d26e1ab2
JS
6603 event.Skip();
6604}
6605#endif