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