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