]> git.saurik.com Git - wxWidgets.git/blame - src/msw/window.cpp
Applied patch [ 736321 ] Compile error for src/msw/textctrl.cpp
[wxWidgets.git] / src / msw / window.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
1e6feb95 2// Name: src/msw/windows.cpp
2bda0e17
KB
3// Purpose: wxWindow
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
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
a23fd0e1
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
a23fd0e1 21 #pragma implementation "window.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
09914df7 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
0c589ad0
BM
32 #include <windows.h>
33 #include "wx/msw/winundef.h"
4e938f5b 34 #include "wx/window.h"
0c589ad0 35 #include "wx/accel.h"
3a19e16d
VZ
36 #include "wx/setup.h"
37 #include "wx/menu.h"
38 #include "wx/dc.h"
39 #include "wx/dcclient.h"
8e92ccef 40 #include "wx/dcmemory.h"
3a19e16d
VZ
41 #include "wx/utils.h"
42 #include "wx/app.h"
3a19e16d
VZ
43 #include "wx/layout.h"
44 #include "wx/dialog.h"
45 #include "wx/frame.h"
46 #include "wx/listbox.h"
47 #include "wx/button.h"
3a19e16d 48 #include "wx/msgdlg.h"
1f3943e0 49 #include "wx/settings.h"
8d753488 50 #include "wx/statbox.h"
2bda0e17
KB
51#endif
52
f6bcfd97 53#if wxUSE_OWNER_DRAWN
09914df7 54 #include "wx/ownerdrw.h"
2bda0e17
KB
55#endif
56
9e2896e5
VZ
57#if wxUSE_DRAG_AND_DROP
58 #include "wx/dnd.h"
2bda0e17
KB
59#endif
60
ed5317e5
JS
61#if wxUSE_ACCESSIBILITY
62 #include "wx/access.h"
bef8d481 63 #include <ole2.h>
ed5317e5
JS
64 #include <oleacc.h>
65 #ifndef WM_GETOBJECT
66 #define WM_GETOBJECT 0x003D
67 #endif
68 #ifndef OBJID_CLIENT
69 #define OBJID_CLIENT 0xFFFFFFFC
70 #endif
71#endif
72
2bda0e17 73#include "wx/menuitem.h"
47cbd6da 74#include "wx/log.h"
750b78ba 75
0c589ad0
BM
76#include "wx/msw/private.h"
77
750b78ba 78#if wxUSE_TOOLTIPS
42e69d6b 79 #include "wx/tooltip.h"
750b78ba
JS
80#endif
81
789295bf
VZ
82#if wxUSE_CARET
83 #include "wx/caret.h"
84#endif // wxUSE_CARET
85
6fe19057
VZ
86#if wxUSE_SPINCTRL
87 #include "wx/spinctrl.h"
88#endif // wxUSE_SPINCTRL
89
dbda9e86
JS
90#include "wx/intl.h"
91#include "wx/log.h"
3a19e16d 92
2a47d3c1 93#include "wx/textctrl.h"
d9317fd4 94#include "wx/notebook.h"
2a47d3c1 95
2bda0e17
KB
96#include <string.h>
97
04ef50df 98#if (!defined(__GNUWIN32_OLD__) && !defined(__WXMICROWIN__)) || defined(__CYGWIN10__)
3a19e16d
VZ
99 #include <shellapi.h>
100 #include <mmsystem.h>
2bda0e17
KB
101#endif
102
103#ifdef __WIN32__
3a19e16d 104 #include <windowsx.h>
2bda0e17
KB
105#endif
106
04ef50df 107#if (!defined(__GNUWIN32_OLD__) && !defined(__TWIN32__) && !defined(__WXMICROWIN__)) || defined(__CYGWIN10__)
310df81b 108 #ifdef __WIN95__
c42404a5
VZ
109 #include <commctrl.h>
110 #endif
04ef50df 111#elif !defined(__WXMICROWIN__) // broken compiler
c42404a5
VZ
112 #ifndef __TWIN32__
113 #include "wx/msw/gnuwin32/extra.h"
3a19e16d 114 #endif
57c208c5 115#endif
2bda0e17 116
9c7df356
VZ
117// ----------------------------------------------------------------------------
118// standard constants not available with all compilers/headers
119// ----------------------------------------------------------------------------
120
f6bcfd97
BP
121// This didn't appear in mingw until 2.95.2
122#ifndef SIF_TRACKPOS
123#define SIF_TRACKPOS 16
124#endif
125
d2c52078
RD
126#if wxUSE_MOUSEWHEEL
127 #ifndef WM_MOUSEWHEEL
128 #define WM_MOUSEWHEEL 0x020A
c9d4f881
RD
129 #endif
130 #ifndef WHEEL_DELTA
d2c52078 131 #define WHEEL_DELTA 120
c9d4f881
RD
132 #endif
133 #ifndef SPI_GETWHEELSCROLLLINES
d2c52078
RD
134 #define SPI_GETWHEELSCROLLLINES 104
135 #endif
9c7df356
VZ
136#endif // wxUSE_MOUSEWHEEL
137
138#ifndef VK_OEM_1
139 #define VK_OEM_1 0xBA
9c7df356
VZ
140 #define VK_OEM_2 0xBF
141 #define VK_OEM_3 0xC0
142 #define VK_OEM_4 0xDB
143 #define VK_OEM_5 0xDC
144 #define VK_OEM_6 0xDD
145 #define VK_OEM_7 0xDE
d2c52078
RD
146#endif
147
3f3071dc
MB
148#ifndef VK_OEM_COMMA
149 #define VK_OEM_PLUS 0xBB
150 #define VK_OEM_COMMA 0xBC
151 #define VK_OEM_MINUS 0xBD
152 #define VK_OEM_PERIOD 0xBE
153#endif
154
a23fd0e1 155// ---------------------------------------------------------------------------
42e69d6b 156// global variables
a23fd0e1 157// ---------------------------------------------------------------------------
47cbd6da 158
90c1530a 159// the last Windows message we got (FIXME-MT)
42e69d6b 160extern MSG s_currentMsg;
2bda0e17 161
1e6feb95 162#if wxUSE_MENUS_NATIVE
2bda0e17 163wxMenu *wxCurrentPopupMenu = NULL;
1e6feb95
VZ
164#endif // wxUSE_MENUS_NATIVE
165
2ffa221c 166extern const wxChar *wxCanvasClassName;
42e69d6b 167
90c1530a
VZ
168// true if we had already created the std colour map, used by
169// wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
170static bool gs_hasStdCmap = FALSE;
171
42e69d6b
VZ
172// ---------------------------------------------------------------------------
173// private functions
174// ---------------------------------------------------------------------------
175
176// the window proc for all our windows
cc972ac6
CE
177#ifdef __DIGITALMARS__
178extern "C" LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
179 WPARAM wParam, LPARAM lParam);
180#else
3135f4a7 181LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
42e69d6b 182 WPARAM wParam, LPARAM lParam);
cc972ac6
CE
183#endif
184
42e69d6b
VZ
185
186#ifdef __WXDEBUG__
187 const char *wxGetMessageName(int message);
188#endif //__WXDEBUG__
2bda0e17 189
1e6feb95 190void wxRemoveHandleAssociation(wxWindowMSW *win);
cc972ac6
CE
191#ifdef __DIGITALMARS__
192extern "C" void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win);
193#else
194extern void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win);
195#endif
2bda0e17
KB
196wxWindow *wxFindWinFromHandle(WXHWND hWnd);
197
4aff28fc
VZ
198// this magical function is used to translate VK_APPS key presses to right
199// mouse clicks
1e6feb95
VZ
200static void TranslateKbdEventToMouse(wxWindowMSW *win,
201 int *x, int *y, WPARAM *flags);
4aff28fc 202
f6bcfd97 203// get the text metrics for the current font
1e6feb95
VZ
204static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win);
205
dfafa702 206// find the window for the mouse event at the specified position
abcbaea7 207static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y); //TW:REQ:Univ
dfafa702 208
c48926e1 209// wrapper around BringWindowToTop() API
44d5b352 210static inline void wxBringWindowToTop(HWND hwnd)
c48926e1
VZ
211{
212#ifdef __WXMICROWIN__
213 // It seems that MicroWindows brings the _parent_ of the window to the top,
214 // which can be the wrong one.
215
216 // activate (set focus to) specified window
217 ::SetFocus(hwnd);
218
219 // raise top level parent to top of z order
220 ::SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
221#else // !__WXMICROWIN__
222 if ( !::BringWindowToTop(hwnd) )
223 {
224 wxLogLastError(_T("BringWindowToTop"));
225 }
226#endif // __WXMICROWIN__/!__WXMICROWIN__
227}
f6bcfd97 228
a23fd0e1
VZ
229// ---------------------------------------------------------------------------
230// event tables
231// ---------------------------------------------------------------------------
232
1e6feb95
VZ
233// in wxUniv/MSW this class is abstract because it doesn't have DoPopupMenu()
234// method
235#ifdef __WXUNIVERSAL__
236 IMPLEMENT_ABSTRACT_CLASS(wxWindowMSW, wxWindowBase)
237#else // __WXMSW__
238 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
239#endif // __WXUNIVERSAL__/__WXMSW__
240
241BEGIN_EVENT_TABLE(wxWindowMSW, wxWindowBase)
242 EVT_ERASE_BACKGROUND(wxWindowMSW::OnEraseBackground)
243 EVT_SYS_COLOUR_CHANGED(wxWindowMSW::OnSysColourChanged)
244 EVT_INIT_DIALOG(wxWindowMSW::OnInitDialog)
245 EVT_IDLE(wxWindowMSW::OnIdle)
2bda0e17
KB
246END_EVENT_TABLE()
247
a23fd0e1
VZ
248// ===========================================================================
249// implementation
250// ===========================================================================
251
42e69d6b
VZ
252// ---------------------------------------------------------------------------
253// wxWindow utility functions
254// ---------------------------------------------------------------------------
255
2bda0e17 256// Find an item given the MS Windows id
1e6feb95 257wxWindow *wxWindowMSW::FindItem(long id) const
2bda0e17 258{
1e6feb95 259#if wxUSE_CONTROLS
f7637829 260 wxControl *item = wxDynamicCastThis(wxControl);
f048e32f
VZ
261 if ( item )
262 {
1e6feb95
VZ
263 // is it we or one of our "internal" children?
264 if ( item->GetId() == id
265#ifndef __WXUNIVERSAL__
266 || (item->GetSubcontrols().Index(id) != wxNOT_FOUND)
267#endif // __WXUNIVERSAL__
268 )
f048e32f
VZ
269 {
270 return item;
271 }
272 }
1e6feb95 273#endif // wxUSE_CONTROLS
f048e32f 274
42e69d6b 275 wxWindowList::Node *current = GetChildren().GetFirst();
2d0a075d
JS
276 while (current)
277 {
42e69d6b 278 wxWindow *childWin = current->GetData();
2bda0e17 279
42e69d6b 280 wxWindow *wnd = childWin->FindItem(id);
cc2b7472 281 if ( wnd )
42e69d6b 282 return wnd;
2bda0e17 283
42e69d6b 284 current = current->GetNext();
2bda0e17 285 }
42e69d6b 286
2d0a075d 287 return NULL;
2bda0e17
KB
288}
289
290// Find an item given the MS Windows handle
1e6feb95 291wxWindow *wxWindowMSW::FindItemByHWND(WXHWND hWnd, bool controlOnly) const
2bda0e17 292{
42e69d6b 293 wxWindowList::Node *current = GetChildren().GetFirst();
2d0a075d 294 while (current)
2bda0e17 295 {
42e69d6b
VZ
296 wxWindow *parent = current->GetData();
297
2d0a075d 298 // Do a recursive search.
42e69d6b 299 wxWindow *wnd = parent->FindItemByHWND(hWnd);
cc2b7472 300 if ( wnd )
42e69d6b 301 return wnd;
2d0a075d 302
1e6feb95
VZ
303 if ( !controlOnly
304#if wxUSE_CONTROLS
305 || parent->IsKindOf(CLASSINFO(wxControl))
306#endif // wxUSE_CONTROLS
307 )
2d0a075d 308 {
42e69d6b
VZ
309 wxWindow *item = current->GetData();
310 if ( item->GetHWND() == hWnd )
2d0a075d
JS
311 return item;
312 else
313 {
314 if ( item->ContainsHWND(hWnd) )
315 return item;
316 }
317 }
42e69d6b
VZ
318
319 current = current->GetNext();
2bda0e17 320 }
2d0a075d 321 return NULL;
2bda0e17
KB
322}
323
324// Default command handler
1e6feb95 325bool wxWindowMSW::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
2bda0e17 326{
2d0a075d 327 return FALSE;
2bda0e17
KB
328}
329
fd3f686c
VZ
330// ----------------------------------------------------------------------------
331// constructors and such
332// ----------------------------------------------------------------------------
333
1e6feb95 334void wxWindowMSW::Init()
2bda0e17 335{
cc2b7472
VZ
336 // generic
337 InitBase();
634903fd 338
cc2b7472 339 // MSW specific
2d0a075d 340 m_isBeingDeleted = FALSE;
5a403e3f 341 m_oldWndProc = NULL;
2d0a075d 342 m_useCtl3D = FALSE;
fd3f686c 343 m_mouseInWindow = FALSE;
68304caf 344 m_lastKeydownProcessed = FALSE;
2bda0e17 345
d7cbabe0
VZ
346 m_childrenDisabled = NULL;
347
2d0a075d 348 // wxWnd
2d0a075d 349 m_hMenu = 0;
2bda0e17 350
319fefa9
VZ
351 m_hWnd = 0;
352
2d0a075d
JS
353 m_xThumbSize = 0;
354 m_yThumbSize = 0;
355 m_backgroundTransparent = FALSE;
2bda0e17 356
85d10d9b
VZ
357 // as all windows are created with WS_VISIBLE style...
358 m_isShown = TRUE;
359
a23fd0e1 360#if wxUSE_MOUSEEVENT_HACK
cc2b7472
VZ
361 m_lastMouseX =
362 m_lastMouseY = -1;
363 m_lastMouseEvent = -1;
a23fd0e1 364#endif // wxUSE_MOUSEEVENT_HACK
fd3f686c
VZ
365}
366
2bda0e17 367// Destructor
1e6feb95 368wxWindowMSW::~wxWindowMSW()
2bda0e17 369{
2d0a075d 370 m_isBeingDeleted = TRUE;
2bda0e17 371
2e9f62da 372#ifndef __WXUNIVERSAL__
4a41c655 373 // VS: make sure there's no wxFrame with last focus set to us:
2e9f62da 374 for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
4a41c655 375 {
085ad686 376 wxTopLevelWindow *frame = wxDynamicCast(win, wxTopLevelWindow);
4a41c655
VS
377 if ( frame )
378 {
c5053639 379 if ( frame->GetLastFocus() == this )
2e9f62da 380 {
085ad686 381 frame->SetLastFocus(NULL);
2e9f62da 382 }
cc0c7cd8 383 break;
4a41c655
VS
384 }
385 }
2e9f62da 386#endif // __WXUNIVERSAL__
2bda0e17 387
cc0c7cd8
VS
388 // VS: destroy children first and _then_ detach *this from its parent.
389 // If we'd do it the other way around, children wouldn't be able
390 // find their parent frame (see above).
391 DestroyChildren();
392
a23fd0e1
VZ
393 if ( m_parent )
394 m_parent->RemoveChild(this);
395
cc2b7472 396 if ( m_hWnd )
42e69d6b 397 {
98440bc3
VZ
398 // VZ: test temp removed to understand what really happens here
399 //if (::IsWindow(GetHwnd()))
df61c009
JS
400 {
401 if ( !::DestroyWindow(GetHwnd()) )
f6bcfd97 402 wxLogLastError(wxT("DestroyWindow"));
df61c009 403 }
2bda0e17 404
c50f1fb9
VZ
405 // remove hWnd <-> wxWindow association
406 wxRemoveHandleAssociation(this);
407 }
d7cbabe0
VZ
408
409 delete m_childrenDisabled;
2bda0e17
KB
410}
411
fd3f686c 412// real construction (Init() must have been called before!)
1e6feb95
VZ
413bool wxWindowMSW::Create(wxWindow *parent,
414 wxWindowID id,
415 const wxPoint& pos,
416 const wxSize& size,
417 long style,
418 const wxString& name)
2d0a075d 419{
223d09f6 420 wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") );
2bda0e17 421
8d99be5f
VZ
422 if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
423 return FALSE;
42e69d6b 424
fd3f686c 425 parent->AddChild(this);
2bda0e17 426
b2d5a7ee 427 WXDWORD exstyle;
e49d97e6 428 DWORD msflags = MSWGetCreateWindowFlags(&exstyle);
1e6feb95
VZ
429
430#ifdef __WXUNIVERSAL__
d1fe917b 431 // no borders, we draw them ourselves
76c79ff4
VZ
432 exstyle &= ~(WS_EX_DLGMODALFRAME |
433 WS_EX_STATICEDGE |
434 WS_EX_CLIENTEDGE |
435 WS_EX_WINDOWEDGE);
d1fe917b 436 msflags &= ~WS_BORDER;
b2d5a7ee 437#endif // wxUniversal
1e6feb95 438
e49d97e6
VZ
439 // all windows are created visible by default except popup ones (which are
440 // like the wxTopLevelWindows in this aspect)
1e6feb95
VZ
441 if ( style & wxPOPUP_WINDOW )
442 {
1e6feb95
VZ
443 msflags &= ~WS_VISIBLE;
444 m_isShown = FALSE;
445 }
e49d97e6
VZ
446 else
447 {
448 msflags |= WS_VISIBLE;
449 }
1e6feb95 450
42cfcc58 451 return MSWCreate(wxCanvasClassName, NULL, pos, size, msflags, exstyle);
2bda0e17
KB
452}
453
42e69d6b
VZ
454// ---------------------------------------------------------------------------
455// basic operations
456// ---------------------------------------------------------------------------
457
1e6feb95 458void wxWindowMSW::SetFocus()
2bda0e17 459{
a23fd0e1 460 HWND hWnd = GetHwnd();
1e6feb95
VZ
461 wxCHECK_RET( hWnd, _T("can't set focus to invalid window") );
462
8cb172b4 463#ifndef __WXMICROWIN__
1e6feb95 464 ::SetLastError(0);
8cb172b4 465#endif
d0a3d109 466
1e6feb95
VZ
467 if ( !::SetFocus(hWnd) )
468 {
5262eb0a 469#if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
1e6feb95
VZ
470 // was there really an error?
471 DWORD dwRes = ::GetLastError();
472 if ( dwRes )
473 {
5262eb0a
VZ
474 HWND hwndFocus = ::GetFocus();
475 if ( hwndFocus != hWnd )
476 {
477 wxLogApiError(_T("SetFocus"), dwRes);
478 }
1e6feb95 479 }
5262eb0a 480#endif // Debug
1e6feb95 481 }
2bda0e17
KB
482}
483
ddf9d04f
VZ
484void wxWindowMSW::SetFocusFromKbd()
485{
486 wxWindowBase::SetFocusFromKbd();
487
488 // when the focus is given to the control with DLGC_HASSETSEL style from
489 // keyboard its contents should be entirely selected: this is what
490 // ::IsDialogMessage() does and so we should do it as well to provide the
491 // same LNF as the native programs
492 if ( ::SendMessage(GetHwnd(), WM_GETDLGCODE, 0, 0) & DLGC_HASSETSEL )
493 {
494 ::SendMessage(GetHwnd(), EM_SETSEL, 0, -1);
495 }
496}
497
42e69d6b
VZ
498// Get the window with the focus
499wxWindow *wxWindowBase::FindFocus()
500{
501 HWND hWnd = ::GetFocus();
502 if ( hWnd )
503 {
a2242341 504 return wxGetWindowFromHWND((WXHWND)hWnd);
42e69d6b
VZ
505 }
506
507 return NULL;
508}
509
1e6feb95 510bool wxWindowMSW::Enable(bool enable)
2bda0e17 511{
cc2b7472
VZ
512 if ( !wxWindowBase::Enable(enable) )
513 return FALSE;
514
a23fd0e1 515 HWND hWnd = GetHwnd();
cc2b7472 516 if ( hWnd )
2d0a075d 517 ::EnableWindow(hWnd, (BOOL)enable);
cc2b7472 518
83a16cfa
VZ
519 // the logic below doesn't apply to the top level windows -- otherwise
520 // showing a modal dialog would result in total greying out (and ungreying
521 // out later) of everything which would be really ugly
522 if ( IsTopLevel() )
523 return TRUE;
524
d7cbabe0
VZ
525 // when the parent is disabled, all of its children should be disabled as
526 // well but when it is enabled back, only those of the children which
527 // hadn't been already disabled in the beginning should be enabled again,
528 // so we have to keep the list of those children
fa3d9b4e
VZ
529 for ( wxWindowList::Node *node = GetChildren().GetFirst();
530 node;
531 node = node->GetNext() )
87a1e308
VZ
532 {
533 wxWindow *child = node->GetData();
fa3d9b4e
VZ
534 if ( child->IsTopLevel() )
535 {
536 // the logic below doesn't apply to top level children
537 continue;
538 }
d7cbabe0
VZ
539
540 if ( enable )
541 {
542 // enable the child back unless it had been disabled before us
543 if ( !m_childrenDisabled || !m_childrenDisabled->Find(child) )
544 child->Enable();
545 }
546 else // we're being disabled
547 {
548 if ( child->IsEnabled() )
549 {
550 // disable it as children shouldn't stay enabled while the
551 // parent is not
552 child->Disable();
553 }
554 else // child already disabled, remember it
555 {
556 // have we created the list of disabled children already?
557 if ( !m_childrenDisabled )
558 m_childrenDisabled = new wxWindowList;
559
560 m_childrenDisabled->Append(child);
561 }
562 }
87a1e308 563 }
d7cbabe0
VZ
564
565 if ( enable && m_childrenDisabled )
566 {
567 // we don't need this list any more, don't keep unused memory
568 delete m_childrenDisabled;
569 m_childrenDisabled = NULL;
570 }
87a1e308 571
cc2b7472 572 return TRUE;
2bda0e17
KB
573}
574
1e6feb95 575bool wxWindowMSW::Show(bool show)
42e69d6b
VZ
576{
577 if ( !wxWindowBase::Show(show) )
578 return FALSE;
579
580 HWND hWnd = GetHwnd();
581 int cshow = show ? SW_SHOW : SW_HIDE;
582 ::ShowWindow(hWnd, cshow);
583
584 if ( show )
585 {
c48926e1 586 wxBringWindowToTop(hWnd);
42e69d6b
VZ
587 }
588
589 return TRUE;
590}
591
592// Raise the window to the top of the Z order
1e6feb95 593void wxWindowMSW::Raise()
42e69d6b 594{
c48926e1 595 wxBringWindowToTop(GetHwnd());
42e69d6b
VZ
596}
597
598// Lower the window to the bottom of the Z order
1e6feb95 599void wxWindowMSW::Lower()
42e69d6b
VZ
600{
601 ::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0,
602 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
603}
604
1e6feb95 605void wxWindowMSW::SetTitle( const wxString& title)
42e69d6b
VZ
606{
607 SetWindowText(GetHwnd(), title.c_str());
608}
609
1e6feb95 610wxString wxWindowMSW::GetTitle() const
42e69d6b
VZ
611{
612 return wxGetWindowText(GetHWND());
613}
614
94633ad9 615void wxWindowMSW::DoCaptureMouse()
2bda0e17 616{
a23fd0e1 617 HWND hWnd = GetHwnd();
1e6feb95 618 if ( hWnd )
2d0a075d 619 {
1e6feb95 620 ::SetCapture(hWnd);
2d0a075d 621 }
2bda0e17
KB
622}
623
94633ad9 624void wxWindowMSW::DoReleaseMouse()
2bda0e17 625{
1e6feb95 626 if ( !::ReleaseCapture() )
2d0a075d 627 {
1e6feb95 628 wxLogLastError(_T("ReleaseCapture"));
2d0a075d 629 }
2bda0e17
KB
630}
631
1e6feb95
VZ
632/* static */ wxWindow *wxWindowBase::GetCapture()
633{
634 HWND hwnd = ::GetCapture();
635 return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : (wxWindow *)NULL;
636}
637
638bool wxWindowMSW::SetFont(const wxFont& font)
2bda0e17 639{
42e69d6b
VZ
640 if ( !wxWindowBase::SetFont(font) )
641 {
642 // nothing to do
643 return FALSE;
2d0a075d 644 }
195896c7 645
42e69d6b
VZ
646 HWND hWnd = GetHwnd();
647 if ( hWnd != 0 )
648 {
649 WXHANDLE hFont = m_font.GetResourceHandle();
2bda0e17 650
223d09f6 651 wxASSERT_MSG( hFont, wxT("should have valid font") );
3a19e16d 652
c50f1fb9 653 ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
42e69d6b 654 }
2bda0e17 655
42e69d6b
VZ
656 return TRUE;
657}
1e6feb95 658bool wxWindowMSW::SetCursor(const wxCursor& cursor)
2bda0e17 659{
42e69d6b
VZ
660 if ( !wxWindowBase::SetCursor(cursor) )
661 {
662 // no change
663 return FALSE;
664 }
665
8a9c2246
VZ
666 if ( m_cursor.Ok() )
667 {
668 HWND hWnd = GetHwnd();
42e69d6b 669
8a9c2246
VZ
670 // Change the cursor NOW if we're within the correct window
671 POINT point;
672 ::GetCursorPos(&point);
2bda0e17 673
82c9f85c 674 RECT rect = wxGetWindowRect(hWnd);
3a19e16d 675
8a9c2246
VZ
676 if ( ::PtInRect(&rect, point) && !wxIsBusy() )
677 ::SetCursor(GetHcursorOf(m_cursor));
678 }
3a19e16d 679
42e69d6b 680 return TRUE;
3a19e16d
VZ
681}
682
1e6feb95 683void wxWindowMSW::WarpPointer (int x, int y)
2bda0e17 684{
1e6feb95 685 ClientToScreen(&x, &y);
42e69d6b 686
1e6feb95
VZ
687 if ( !::SetCursorPos(x, y) )
688 {
689 wxLogLastError(_T("SetCursorPos"));
690 }
2bda0e17
KB
691}
692
42e69d6b 693#if WXWIN_COMPATIBILITY
1e6feb95 694void wxWindowMSW::MSWDeviceToLogical (float *x, float *y) const
2bda0e17 695{
42e69d6b
VZ
696}
697#endif // WXWIN_COMPATIBILITY
81d66cf3 698
42e69d6b
VZ
699// ---------------------------------------------------------------------------
700// scrolling stuff
701// ---------------------------------------------------------------------------
2d0a075d 702
0cf5de11 703// convert wxHORIZONTAL/wxVERTICAL to SB_HORZ/SB_VERT
3f3071dc 704static inline int wxDirToWinStyle(int orient)
0cf5de11
VZ
705{
706 return orient == wxHORIZONTAL ? SB_HORZ : SB_VERT;
707}
708
42e69d6b 709#if WXWIN_COMPATIBILITY
1e6feb95 710void wxWindowMSW::SetScrollRange(int orient, int range, bool refresh)
42e69d6b 711{
42e69d6b
VZ
712 int range1 = range;
713
714 // Try to adjust the range to cope with page size > 1
715 // - a Windows API quirk
716 int pageSize = GetScrollPage(orient);
717 if ( pageSize > 1 && range > 0)
2d0a075d 718 {
42e69d6b 719 range1 += (pageSize - 1);
2d0a075d
JS
720 }
721
0cf5de11 722 WinStruct<SCROLLINFO> info;
42e69d6b
VZ
723 info.nPage = pageSize; // Have to set this, or scrollbar goes awry
724 info.nMin = 0;
725 info.nMax = range1;
42e69d6b
VZ
726 info.fMask = SIF_RANGE | SIF_PAGE;
727
728 HWND hWnd = GetHwnd();
729 if ( hWnd )
0cf5de11 730 ::SetScrollInfo(hWnd, wxDirToWinStyle(orient), &info, refresh);
2bda0e17
KB
731}
732
1e6feb95 733void wxWindowMSW::SetScrollPage(int orient, int page, bool refresh)
2bda0e17 734{
0cf5de11 735 WinStruct<SCROLLINFO> info;
42e69d6b 736 info.nPage = page;
42e69d6b
VZ
737 info.fMask = SIF_PAGE;
738
739 HWND hWnd = GetHwnd();
740 if ( hWnd )
0cf5de11 741 ::SetScrollInfo(hWnd, wxDirToWinStyle(orient), &info, refresh);
42e69d6b 742}
2bda0e17 743
1e6feb95 744int wxWindowMSW::GetScrollPage(int orient) const
42e69d6b 745{
0cf5de11 746 return orient == wxHORIZONTAL ? m_xThumbSize : m_yThumbSize;
2bda0e17
KB
747}
748
42e69d6b
VZ
749#endif // WXWIN_COMPATIBILITY
750
9cd6d737
VZ
751inline int GetScrollPosition(HWND hWnd, int wOrient)
752{
753#ifdef __WXMICROWIN__
754 return ::GetScrollPosWX(hWnd, wOrient);
755#else
756 return ::GetScrollPos(hWnd, wOrient);
757#endif
758}
759
1e6feb95 760int wxWindowMSW::GetScrollPos(int orient) const
2bda0e17 761{
42e69d6b 762 HWND hWnd = GetHwnd();
9cd6d737
VZ
763 wxCHECK_MSG( hWnd, 0, _T("no HWND in GetScrollPos") );
764
0cf5de11 765 return GetScrollPosition(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT);
42e69d6b 766}
2bda0e17 767
42e69d6b
VZ
768// This now returns the whole range, not just the number
769// of positions that we can scroll.
1e6feb95 770int wxWindowMSW::GetScrollRange(int orient) const
42e69d6b 771{
42e69d6b 772 int minPos, maxPos;
a23fd0e1 773 HWND hWnd = GetHwnd();
0cf5de11 774 if ( !hWnd )
42e69d6b 775 return 0;
0cf5de11
VZ
776
777 ::GetScrollRange(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT,
778 &minPos, &maxPos);
779
780 // undo "range - 1" done in SetScrollbar()
781 return maxPos + 1;
cc2b7472 782}
2bda0e17 783
1e6feb95 784int wxWindowMSW::GetScrollThumb(int orient) const
2bda0e17 785{
0cf5de11 786 return orient == wxHORIZONTAL ? m_xThumbSize : m_yThumbSize;
2bda0e17
KB
787}
788
1e6feb95 789void wxWindowMSW::SetScrollPos(int orient, int pos, bool refresh)
2bda0e17 790{
5f3286d1
VZ
791 HWND hWnd = GetHwnd();
792 wxCHECK_RET( hWnd, _T("SetScrollPos: no HWND") );
72fd19a1 793
0cf5de11 794 WinStruct<SCROLLINFO> info;
42e69d6b
VZ
795 info.nPage = 0;
796 info.nMin = 0;
797 info.nPos = pos;
798 info.fMask = SIF_POS;
2d0a075d 799
0cf5de11
VZ
800 ::SetScrollInfo(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT,
801 &info, refresh);
2bda0e17
KB
802}
803
42e69d6b 804// New function that will replace some of the above.
0cf5de11
VZ
805void wxWindowMSW::SetScrollbar(int orient,
806 int pos,
807 int pageSize,
808 int range,
809 bool refresh)
810{
811 WinStruct<SCROLLINFO> info;
812 info.nPage = pageSize;
813 info.nMin = 0; // range is nMax - nMin + 1
814 info.nMax = range - 1; // as both nMax and nMax are inclusive
42e69d6b
VZ
815 info.nPos = pos;
816 info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
2bda0e17 817
42e69d6b
VZ
818 HWND hWnd = GetHwnd();
819 if ( hWnd )
81d66cf3 820 {
0cf5de11
VZ
821 ::SetScrollInfo(hWnd, orient == wxHORIZONTAL ? SB_HORZ : SB_VERT,
822 &info, refresh);
81d66cf3 823 }
0cf5de11
VZ
824
825 *(orient == wxHORIZONTAL ? &m_xThumbSize : &m_yThumbSize) = pageSize;
81d66cf3
JS
826}
827
1e6feb95 828void wxWindowMSW::ScrollWindow(int dx, int dy, const wxRect *prect)
2bda0e17 829{
574c939e
KB
830 RECT rect;
831 RECT *pr;
1e6feb95 832 if ( prect )
2d0a075d 833 {
1e6feb95
VZ
834 rect.left = prect->x;
835 rect.top = prect->y;
836 rect.right = prect->x + prect->width;
837 rect.bottom = prect->y + prect->height;
f797e53d
VZ
838 pr = &rect;
839 }
840 else
841 {
842 pr = NULL;
2d0a075d 843 }
2bda0e17 844
f797e53d 845 ::ScrollWindow(GetHwnd(), dx, dy, pr, pr);
2bda0e17
KB
846}
847
9cd6d737 848static bool ScrollVertically(HWND hwnd, int kind, int count)
b9b3393e 849{
9cd6d737
VZ
850 int posStart = GetScrollPosition(hwnd, SB_VERT);
851
852 int pos = posStart;
c0cdd6cc
VZ
853 for ( int n = 0; n < count; n++ )
854 {
855 ::SendMessage(hwnd, WM_VSCROLL, kind, 0);
9cd6d737
VZ
856
857 int posNew = GetScrollPosition(hwnd, SB_VERT);
858 if ( posNew == pos )
859 {
860 // don't bother to continue, we're already at top/bottom
861 break;
862 }
863
864 pos = posNew;
c0cdd6cc 865 }
9cd6d737
VZ
866
867 return pos != posStart;
b9b3393e
VZ
868}
869
9cd6d737 870bool wxWindowMSW::ScrollLines(int lines)
b9b3393e
VZ
871{
872 bool down = lines > 0;
873
9cd6d737
VZ
874 return ScrollVertically(GetHwnd(),
875 down ? SB_LINEDOWN : SB_LINEUP,
876 down ? lines : -lines);
b9b3393e
VZ
877}
878
9cd6d737 879bool wxWindowMSW::ScrollPages(int pages)
b9b3393e
VZ
880{
881 bool down = pages > 0;
882
9cd6d737
VZ
883 return ScrollVertically(GetHwnd(),
884 down ? SB_PAGEDOWN : SB_PAGEUP,
885 down ? pages : -pages);
b9b3393e
VZ
886}
887
42e69d6b
VZ
888// ---------------------------------------------------------------------------
889// subclassing
890// ---------------------------------------------------------------------------
891
1e6feb95 892void wxWindowMSW::SubclassWin(WXHWND hWnd)
2bda0e17 893{
223d09f6 894 wxASSERT_MSG( !m_oldWndProc, wxT("subclassing window twice?") );
2bda0e17 895
c50f1fb9 896 HWND hwnd = (HWND)hWnd;
223d09f6 897 wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in SubclassWin") );
c50f1fb9
VZ
898
899 wxAssociateWinWithHandle(hwnd, this);
2bda0e17 900
eb5e4d9a 901 m_oldWndProc = (WXFARPROC)::GetWindowLong((HWND)hWnd, GWL_WNDPROC);
b2d5a7ee 902
b225f659
VZ
903 // we don't need to subclass the window of our own class (in the Windows
904 // sense of the word)
eb5e4d9a 905 if ( !wxCheckWindowWndProc(hWnd, (WXFARPROC)wxWndProc) )
b225f659
VZ
906 {
907 ::SetWindowLong(hwnd, GWL_WNDPROC, (LONG) wxWndProc);
908 }
909 else
910 {
5a403e3f
VZ
911 // don't bother restoring it neither: this also makes it easy to
912 // implement IsOfStandardClass() method which returns TRUE for the
913 // standard controls and FALSE for the wxWindows own windows as it can
914 // simply check m_oldWndProc
b225f659
VZ
915 m_oldWndProc = NULL;
916 }
2bda0e17
KB
917}
918
1e6feb95 919void wxWindowMSW::UnsubclassWin()
2bda0e17 920{
42e69d6b 921 wxRemoveHandleAssociation(this);
2bda0e17 922
42e69d6b 923 // Restore old Window proc
c50f1fb9
VZ
924 HWND hwnd = GetHwnd();
925 if ( hwnd )
42e69d6b 926 {
c50f1fb9
VZ
927 m_hWnd = 0;
928
223d09f6 929 wxCHECK_RET( ::IsWindow(hwnd), wxT("invalid HWND in UnsubclassWin") );
c50f1fb9 930
b225f659 931 if ( m_oldWndProc )
42e69d6b 932 {
eb5e4d9a 933 if ( !wxCheckWindowWndProc((WXHWND)hwnd, m_oldWndProc) )
b225f659
VZ
934 {
935 ::SetWindowLong(hwnd, GWL_WNDPROC, (LONG) m_oldWndProc);
936 }
937
938 m_oldWndProc = NULL;
42e69d6b 939 }
42e69d6b 940 }
2bda0e17
KB
941}
942
eb5e4d9a
VS
943bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC wndProc)
944{
42cfcc58
VZ
945 // Unicows note: the code below works, but only because WNDCLASS contains
946 // original window handler rather that the unicows fake one. This may not
947 // be on purpose, though; if it stops working with future versions of
948 // unicows.dll, we can override unicows hooks by setting
949 // Unicows_{Set,Get}WindowLong and Unicows_RegisterClass to our own
950 // versions that keep track of fake<->real wnd proc mapping.
951 WNDCLASS cls;
952 if ( !::GetClassInfo(wxGetInstance(), wxGetWindowClass(hWnd), &cls) )
136cb3c7 953 {
42cfcc58 954 wxLogLastError(_T("GetClassInfo"));
eb5e4d9a 955
42cfcc58 956 return FALSE;
136cb3c7 957 }
42cfcc58
VZ
958
959 return wndProc == (WXFARPROC)cls.lpfnWndProc;
eb5e4d9a
VS
960}
961
b2d5a7ee
VZ
962// ----------------------------------------------------------------------------
963// Style handling
964// ----------------------------------------------------------------------------
965
966void wxWindowMSW::SetWindowStyleFlag(long flags)
967{
968 long flagsOld = GetWindowStyleFlag();
969 if ( flags == flagsOld )
970 return;
971
972 // update the internal variable
973 wxWindowBase::SetWindowStyleFlag(flags);
974
5b2f31eb
VZ
975 // now update the Windows style as well if needed - and if the window had
976 // been already created
977 if ( !GetHwnd() )
978 return;
979
b2d5a7ee
VZ
980 WXDWORD exstyle, exstyleOld;
981 long style = MSWGetStyle(flags, &exstyle),
982 styleOld = MSWGetStyle(flagsOld, &exstyleOld);
983
984 if ( style != styleOld )
985 {
986 // some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
987 // this function so instead of simply setting the style to the new
988 // value we clear the bits which were set in styleOld but are set in
989 // the new one and set the ones which were not set before
990 long styleReal = ::GetWindowLong(GetHwnd(), GWL_STYLE);
991 styleReal &= ~styleOld;
992 styleReal |= style;
993
994 ::SetWindowLong(GetHwnd(), GWL_STYLE, styleReal);
995 }
996
997 // and the extended style
998 if ( exstyle != exstyleOld )
999 {
1000 long exstyleReal = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
1001 exstyleReal &= ~exstyleOld;
1002 exstyleReal |= exstyle;
1003
1004 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyleReal);
1005
1006 // we must call SetWindowPos() to flash the cached extended style and
1007 // also to make the change to wxSTAY_ON_TOP style take effect: just
1008 // setting the style simply doesn't work
1009 if ( !::SetWindowPos(GetHwnd(),
1010 exstyleReal & WS_EX_TOPMOST ? HWND_TOPMOST
1011 : HWND_NOTOPMOST,
1012 0, 0, 0, 0,
1013 SWP_NOMOVE | SWP_NOSIZE) )
1014 {
1015 wxLogLastError(_T("SetWindowPos"));
1016 }
1017 }
1018}
1019
1020WXDWORD wxWindowMSW::MSWGetStyle(long flags, WXDWORD *exstyle) const
1021{
1022 // translate the style
6ae0daf6 1023 WXDWORD style = WS_CHILD | WS_VISIBLE;
b2d5a7ee
VZ
1024
1025 if ( flags & wxCLIP_CHILDREN )
1026 style |= WS_CLIPCHILDREN;
1027
1028 if ( flags & wxCLIP_SIBLINGS )
1029 style |= WS_CLIPSIBLINGS;
1030
3a01bb1b 1031 wxBorder border = (wxBorder)(flags & wxBORDER_MASK);
fe3d9123
JS
1032
1033 // Check if we want to automatically give it a sunken style.
1034 // Note than because 'sunken' actually maps to WS_EX_CLIENTEDGE, which
1035 // is a more neutral term, we don't necessarily get a sunken effect in
1036 // Windows XP. Instead we get the appropriate style for the theme.
1037
31e7e89f 1038 if (border == wxBORDER_DEFAULT && wxTheApp->GetAuto3D() &&
975ee4b4
JS
1039 GetParent() && (GetParent()->IsKindOf(CLASSINFO(wxPanel)) ||
1040 GetParent()->IsKindOf(CLASSINFO(wxDialog))) &&
fe3d9123
JS
1041 ((GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS))
1042 {
1043 border = (wxBorder)((flags & wxBORDER_MASK) | wxBORDER_SUNKEN);
1044 }
1045
1046 // Only give it WS_BORDER for wxBORDER_SIMPLE
1047 if (border & wxBORDER_SIMPLE)
b2d5a7ee 1048 style |= WS_BORDER;
fe3d9123 1049
b2d5a7ee
VZ
1050 // now deal with ext style if the caller wants it
1051 if ( exstyle )
1052 {
1053 *exstyle = 0;
1054
1055 if ( flags & wxTRANSPARENT_WINDOW )
1056 *exstyle |= WS_EX_TRANSPARENT;
1057
fe3d9123 1058 switch ( border )
b2d5a7ee
VZ
1059 {
1060 default:
1061 wxFAIL_MSG( _T("unknown border style") );
1062 // fall through
1063
1064 case wxBORDER_NONE:
1065 case wxBORDER_SIMPLE:
3a01bb1b 1066 case wxBORDER_DEFAULT:
b2d5a7ee
VZ
1067 break;
1068
1069 case wxBORDER_STATIC:
1070 *exstyle |= WS_EX_STATICEDGE;
1071 break;
1072
1073 case wxBORDER_RAISED:
7699361c 1074 *exstyle |= WS_EX_DLGMODALFRAME;
b2d5a7ee
VZ
1075 break;
1076
b2d5a7ee
VZ
1077 case wxBORDER_SUNKEN:
1078 *exstyle |= WS_EX_CLIENTEDGE;
fe3d9123 1079 style &= ~WS_BORDER;
b2d5a7ee
VZ
1080 break;
1081
1082 case wxBORDER_DOUBLE:
1083 *exstyle |= WS_EX_DLGMODALFRAME;
1084 break;
1085 }
d515c32d 1086
09168de7
VZ
1087 // wxUniv doesn't use Windows dialog navigation functions at all
1088#ifndef __WXUNIVERSAL__
5b9c12e1 1089 // to make the dialog navigation work with the nested panels we must
09168de7
VZ
1090 // use this style (top level windows such as dialogs don't need it)
1091 if ( (flags & wxTAB_TRAVERSAL) && !IsTopLevel() )
d515c32d
VZ
1092 {
1093 *exstyle |= WS_EX_CONTROLPARENT;
1094 }
09168de7 1095#endif // __WXUNIVERSAL__
b2d5a7ee
VZ
1096 }
1097
1098 return style;
1099}
eb5e4d9a 1100
c455ab93 1101#if WXWIN_COMPATIBILITY
42e69d6b
VZ
1102// If nothing defined for this, try the parent.
1103// E.g. we may be a button loaded from a resource, with no callback function
1104// defined.
1e6feb95 1105void wxWindowMSW::OnCommand(wxWindow& win, wxCommandEvent& event)
2bda0e17 1106{
42e69d6b
VZ
1107 if ( GetEventHandler()->ProcessEvent(event) )
1108 return;
1109 if ( m_parent )
1110 m_parent->GetEventHandler()->OnCommand(win, event);
1111}
1112#endif // WXWIN_COMPATIBILITY_2
c085e333 1113
42e69d6b 1114#if WXWIN_COMPATIBILITY
1e6feb95 1115wxObject* wxWindowMSW::GetChild(int number) const
42e69d6b
VZ
1116{
1117 // Return a pointer to the Nth object in the Panel
1118 wxNode *node = GetChildren().First();
1119 int n = number;
1120 while (node && n--)
1121 node = node->Next();
1122 if ( node )
1123 {
1124 wxObject *obj = (wxObject *)node->Data();
1125 return(obj);
1126 }
1127 else
1128 return NULL;
1129}
1130#endif // WXWIN_COMPATIBILITY
2bda0e17 1131
42e69d6b 1132// Setup background and foreground colours correctly
1e6feb95 1133void wxWindowMSW::SetupColours()
42e69d6b
VZ
1134{
1135 if ( GetParent() )
1136 SetBackgroundColour(GetParent()->GetBackgroundColour());
1137}
a23fd0e1 1138
1e6feb95
VZ
1139bool wxWindowMSW::IsMouseInWindow() const
1140{
1141 // get the mouse position
1142 POINT pt;
1143 ::GetCursorPos(&pt);
1144
1145 // find the window which currently has the cursor and go up the window
1146 // chain until we find this window - or exhaust it
1147 HWND hwnd = ::WindowFromPoint(pt);
1148 while ( hwnd && (hwnd != GetHwnd()) )
1149 hwnd = ::GetParent(hwnd);
1150
1151 return hwnd != NULL;
1152}
1153
1154void wxWindowMSW::OnIdle(wxIdleEvent& WXUNUSED(event))
42e69d6b
VZ
1155{
1156 // Check if we need to send a LEAVE event
1157 if ( m_mouseInWindow )
2d0a075d 1158 {
ee74faf9
VZ
1159 // note that we should generate the leave event whether the window has
1160 // or doesn't have mouse capture
1161 if ( !IsMouseInWindow() )
42e69d6b
VZ
1162 {
1163 // Generate a LEAVE event
1164 m_mouseInWindow = FALSE;
2bda0e17 1165
1e6feb95
VZ
1166 // Unfortunately the mouse button and keyboard state may have
1167 // changed by the time the OnIdle function is called, so 'state'
1168 // may be meaningless.
42e69d6b 1169 int state = 0;
3f7bc32b 1170 if ( wxIsShiftDown() )
42e69d6b 1171 state |= MK_SHIFT;
3f7bc32b 1172 if ( wxIsCtrlDown() )
42e69d6b 1173 state |= MK_CONTROL;
54ca0d12
GRG
1174 if ( GetKeyState( VK_LBUTTON ) )
1175 state |= MK_LBUTTON;
1176 if ( GetKeyState( VK_MBUTTON ) )
1177 state |= MK_MBUTTON;
1178 if ( GetKeyState( VK_RBUTTON ) )
1179 state |= MK_RBUTTON;
33ac7e6f 1180
1e6feb95
VZ
1181 POINT pt;
1182 if ( !::GetCursorPos(&pt) )
1183 {
1184 wxLogLastError(_T("GetCursorPos"));
1185 }
c085e333 1186
1e6feb95
VZ
1187 // we need to have client coordinates here for symmetry with
1188 // wxEVT_ENTER_WINDOW
82c9f85c 1189 RECT rect = wxGetWindowRect(GetHwnd());
1e6feb95
VZ
1190 pt.x -= rect.left;
1191 pt.y -= rect.top;
1192
1193 wxMouseEvent event2(wxEVT_LEAVE_WINDOW);
1194 InitMouseEvent(event2, pt.x, pt.y, state);
1195
1196 (void)GetEventHandler()->ProcessEvent(event2);
42e69d6b
VZ
1197 }
1198 }
c085e333 1199
42e69d6b
VZ
1200 UpdateWindowUI();
1201}
568cb543 1202
42e69d6b 1203// Set this window to be the child of 'parent'.
1e6feb95 1204bool wxWindowMSW::Reparent(wxWindowBase *parent)
42e69d6b
VZ
1205{
1206 if ( !wxWindowBase::Reparent(parent) )
1207 return FALSE;
c085e333 1208
42e69d6b
VZ
1209 HWND hWndChild = GetHwnd();
1210 HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
a23fd0e1 1211
42e69d6b 1212 ::SetParent(hWndChild, hWndParent);
a23fd0e1 1213
42e69d6b
VZ
1214 return TRUE;
1215}
a23fd0e1 1216
1e6feb95 1217void wxWindowMSW::Clear()
42e69d6b 1218{
1e6feb95 1219 wxClientDC dc((wxWindow *)this);
42e69d6b
VZ
1220 wxBrush brush(GetBackgroundColour(), wxSOLID);
1221 dc.SetBackground(brush);
1222 dc.Clear();
1223}
a23fd0e1 1224
a0e449ff
VZ
1225static inline void SendSetRedraw(HWND hwnd, bool on)
1226{
c67d6888 1227#ifndef __WXMICROWIN__
a0e449ff 1228 ::SendMessage(hwnd, WM_SETREDRAW, (WPARAM)on, 0);
c67d6888 1229#endif
a0e449ff
VZ
1230}
1231
1232void wxWindowMSW::Freeze()
1233{
94589c3f 1234 SendSetRedraw(GetHwnd(), FALSE);
a0e449ff
VZ
1235}
1236
1237void wxWindowMSW::Thaw()
1238{
94589c3f 1239 SendSetRedraw(GetHwnd(), TRUE);
c0cdd6cc
VZ
1240
1241 // we need to refresh everything or otherwise he invalidated area is not
1242 // repainted
1243 Refresh();
a0e449ff
VZ
1244}
1245
1e6feb95 1246void wxWindowMSW::Refresh(bool eraseBack, const wxRect *rect)
42e69d6b
VZ
1247{
1248 HWND hWnd = GetHwnd();
1249 if ( hWnd )
1250 {
1251 if ( rect )
1252 {
1253 RECT mswRect;
1254 mswRect.left = rect->x;
1255 mswRect.top = rect->y;
1256 mswRect.right = rect->x + rect->width;
1257 mswRect.bottom = rect->y + rect->height;
a23fd0e1 1258
42e69d6b
VZ
1259 ::InvalidateRect(hWnd, &mswRect, eraseBack);
1260 }
1261 else
1262 ::InvalidateRect(hWnd, NULL, eraseBack);
1263 }
1264}
a23fd0e1 1265
1e6feb95
VZ
1266void wxWindowMSW::Update()
1267{
1268 if ( !::UpdateWindow(GetHwnd()) )
1269 {
1270 wxLogLastError(_T("UpdateWindow"));
1271 }
2b5f62a0 1272
8cb172b4 1273#if defined(__WIN32__) && !defined(__WXMICROWIN__)
1e6feb95
VZ
1274 // just calling UpdateWindow() is not enough, what we did in our WM_PAINT
1275 // handler needs to be really drawn right now
1276 (void)::GdiFlush();
1277#endif // __WIN32__
1278}
1279
42e69d6b
VZ
1280// ---------------------------------------------------------------------------
1281// drag and drop
1282// ---------------------------------------------------------------------------
a23fd0e1 1283
a23fd0e1 1284
4ce1efe1 1285#if wxUSE_DRAG_AND_DROP
1e6feb95 1286void wxWindowMSW::SetDropTarget(wxDropTarget *pDropTarget)
42e69d6b
VZ
1287{
1288 if ( m_dropTarget != 0 ) {
1289 m_dropTarget->Revoke(m_hWnd);
1290 delete m_dropTarget;
1291 }
a23fd0e1 1292
42e69d6b
VZ
1293 m_dropTarget = pDropTarget;
1294 if ( m_dropTarget != 0 )
1295 m_dropTarget->Register(m_hWnd);
1296}
42e69d6b 1297#endif // wxUSE_DRAG_AND_DROP
2a47d3c1 1298
42e69d6b
VZ
1299// old style file-manager drag&drop support: we retain the old-style
1300// DragAcceptFiles in parallel with SetDropTarget.
1e6feb95 1301void wxWindowMSW::DragAcceptFiles(bool accept)
42e69d6b
VZ
1302{
1303 HWND hWnd = GetHwnd();
1304 if ( hWnd )
1305 ::DragAcceptFiles(hWnd, (BOOL)accept);
1306}
a23fd0e1 1307
42e69d6b
VZ
1308// ----------------------------------------------------------------------------
1309// tooltips
1310// ----------------------------------------------------------------------------
dbda9e86 1311
42e69d6b 1312#if wxUSE_TOOLTIPS
2d0a075d 1313
1e6feb95 1314void wxWindowMSW::DoSetToolTip(wxToolTip *tooltip)
42e69d6b
VZ
1315{
1316 wxWindowBase::DoSetToolTip(tooltip);
839b865d 1317
42e69d6b 1318 if ( m_tooltip )
d4e5272b 1319 m_tooltip->SetWindow((wxWindow *)this);
42e69d6b 1320}
9a05fd8d 1321
42e69d6b 1322#endif // wxUSE_TOOLTIPS
9a05fd8d 1323
42e69d6b
VZ
1324// ---------------------------------------------------------------------------
1325// moving and resizing
1326// ---------------------------------------------------------------------------
839b865d 1327
42e69d6b 1328// Get total size
1e6feb95 1329void wxWindowMSW::DoGetSize(int *x, int *y) const
42e69d6b 1330{
82c9f85c
VZ
1331 RECT rect = wxGetWindowRect(GetHwnd());
1332
42e69d6b
VZ
1333 if ( x )
1334 *x = rect.right - rect.left;
1335 if ( y )
1336 *y = rect.bottom - rect.top;
1337}
1338
82c9f85c
VZ
1339// Get size *available for subwindows* i.e. excluding menu bar etc.
1340void wxWindowMSW::DoGetClientSize(int *x, int *y) const
42e69d6b 1341{
82c9f85c 1342 RECT rect = wxGetClientRect(GetHwnd());
42e69d6b 1343
82c9f85c
VZ
1344 if ( x )
1345 *x = rect.right;
1346 if ( y )
1347 *y = rect.bottom;
1348}
1349
1350void wxWindowMSW::DoGetPosition(int *x, int *y) const
1351{
1352 RECT rect = wxGetWindowRect(GetHwnd());
42e69d6b 1353
42e69d6b
VZ
1354 POINT point;
1355 point.x = rect.left;
1356 point.y = rect.top;
42e69d6b 1357
92049cd4
VZ
1358 // we do the adjustments with respect to the parent only for the "real"
1359 // children, not for the dialogs/frames
1360 if ( !IsTopLevel() )
42e69d6b 1361 {
92049cd4
VZ
1362 HWND hParentWnd = 0;
1363 wxWindow *parent = GetParent();
1364 if ( parent )
1365 hParentWnd = GetWinHwnd(parent);
1366
1367 // Since we now have the absolute screen coords, if there's a parent we
1368 // must subtract its top left corner
1369 if ( hParentWnd )
1370 {
1371 ::ScreenToClient(hParentWnd, &point);
1372 }
1373
89e3037c
GT
1374 if ( parent )
1375 {
1376 // We may be faking the client origin. So a window that's really at (0,
1377 // 30) may appear (to wxWin apps) to be at (0, 0).
1378 wxPoint pt(parent->GetClientAreaOrigin());
1379 point.x -= pt.x;
1380 point.y -= pt.y;
1381 }
42e69d6b
VZ
1382 }
1383
1384 if ( x )
1385 *x = point.x;
1386 if ( y )
1387 *y = point.y;
1388}
54bdd8b0 1389
1e6feb95 1390void wxWindowMSW::DoScreenToClient(int *x, int *y) const
42e69d6b
VZ
1391{
1392 POINT pt;
1393 if ( x )
1394 pt.x = *x;
1395 if ( y )
1396 pt.y = *y;
54bdd8b0 1397
82c9f85c 1398 ::ScreenToClient(GetHwnd(), &pt);
a23fd0e1 1399
42e69d6b
VZ
1400 if ( x )
1401 *x = pt.x;
1402 if ( y )
1403 *y = pt.y;
1404}
a23fd0e1 1405
1e6feb95 1406void wxWindowMSW::DoClientToScreen(int *x, int *y) const
42e69d6b
VZ
1407{
1408 POINT pt;
1409 if ( x )
1410 pt.x = *x;
1411 if ( y )
1412 pt.y = *y;
54bdd8b0 1413
82c9f85c 1414 ::ClientToScreen(GetHwnd(), &pt);
a23fd0e1 1415
42e69d6b
VZ
1416 if ( x )
1417 *x = pt.x;
1418 if ( y )
1419 *y = pt.y;
1420}
a23fd0e1 1421
1e6feb95 1422void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height)
b782f2e0 1423{
62e1ba75
JS
1424 // TODO: is this consistent with other platforms?
1425 // Still, negative width or height shouldn't be allowed
1426 if (width < 0)
1427 width = 0;
1428 if (height < 0)
1429 height = 0;
b782f2e0
VZ
1430 if ( !::MoveWindow(GetHwnd(), x, y, width, height, TRUE) )
1431 {
f6bcfd97 1432 wxLogLastError(wxT("MoveWindow"));
b782f2e0
VZ
1433 }
1434}
1435
4438caf4
VZ
1436// set the size of the window: if the dimensions are positive, just use them,
1437// but if any of them is equal to -1, it means that we must find the value for
1438// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1439// which case -1 is a valid value for x and y)
1440//
1441// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1442// the width/height to best suit our contents, otherwise we reuse the current
1443// width/height
1e6feb95 1444void wxWindowMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags)
42e69d6b 1445{
4438caf4 1446 // get the current size and position...
42e69d6b
VZ
1447 int currentX, currentY;
1448 GetPosition(&currentX, &currentY);
1449 int currentW,currentH;
1450 GetSize(&currentW, &currentH);
a23fd0e1 1451
4438caf4
VZ
1452 // ... and don't do anything (avoiding flicker) if it's already ok
1453 if ( x == currentX && y == currentY &&
1454 width == currentW && height == currentH )
1455 {
42e69d6b 1456 return;
4438caf4 1457 }
a23fd0e1 1458
f8c03547 1459 if ( x == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
4438caf4 1460 x = currentX;
f8c03547 1461 if ( y == -1 && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
4438caf4 1462 y = currentY;
a23fd0e1 1463
4438caf4 1464 AdjustForParentClientOrigin(x, y, sizeFlags);
a23fd0e1 1465
4438caf4 1466 wxSize size(-1, -1);
42e69d6b 1467 if ( width == -1 )
4438caf4 1468 {
9e2896e5 1469 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
4438caf4
VZ
1470 {
1471 size = DoGetBestSize();
1472 width = size.x;
1473 }
1474 else
1475 {
1476 // just take the current one
1477 width = currentW;
1478 }
1479 }
1480
42e69d6b 1481 if ( height == -1 )
4438caf4 1482 {
9e2896e5 1483 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
4438caf4
VZ
1484 {
1485 if ( size.x == -1 )
1486 {
b782f2e0 1487 size = DoGetBestSize();
4438caf4
VZ
1488 }
1489 //else: already called DoGetBestSize() above
a23fd0e1 1490
4438caf4
VZ
1491 height = size.y;
1492 }
1493 else
1494 {
1495 // just take the current one
1496 height = currentH;
1497 }
1498 }
1499
b782f2e0 1500 DoMoveWindow(x, y, width, height);
4438caf4
VZ
1501}
1502
1e6feb95 1503void wxWindowMSW::DoSetClientSize(int width, int height)
42e69d6b 1504{
d4597e13
VZ
1505 // setting the client size is less obvious than it it could have been
1506 // because in the result of changing the total size the window scrollbar
1507 // may [dis]appear and/or its menubar may [un]wrap and so the client size
1508 // will not be correct as the difference between the total and client size
1509 // changes - so we keep changing it until we get it right
1510 //
d6a97306
VZ
1511 // normally this loop shouldn't take more than 3 iterations (usually 1 but
1512 // if scrollbars [dis]appear as the result of the first call, then 2 and it
1513 // may become 3 if the window had 0 size originally and so we didn't
1514 // calculate the scrollbar correction correctly during the first iteration)
1515 // but just to be on the safe side we check for it instead of making it an
d4597e13 1516 // "infinite" loop (i.e. leaving break inside as the only way to get out)
d6a97306 1517 for ( int i = 0; i < 4; i++ )
d4597e13
VZ
1518 {
1519 RECT rectClient;
1520 ::GetClientRect(GetHwnd(), &rectClient);
2bda0e17 1521
d4597e13 1522 // if the size is already ok, stop here (rectClient.left = top = 0)
9fce8d2e
JS
1523 if ( (rectClient.right == width || width == -1) &&
1524 (rectClient.bottom == height || height == -1) )
d4597e13
VZ
1525 {
1526 break;
1527 }
a23fd0e1 1528
d4597e13
VZ
1529 int widthClient = width,
1530 heightClient = height;
a23fd0e1 1531
d4597e13
VZ
1532 // Find the difference between the entire window (title bar and all)
1533 // and the client area; add this to the new client size to move the
1534 // window
1535 RECT rectWin;
1536 ::GetWindowRect(GetHwnd(), &rectWin);
1537
1538 widthClient += rectWin.right - rectWin.left - rectClient.right;
1539 heightClient += rectWin.bottom - rectWin.top - rectClient.bottom;
1540
1541 POINT point;
1542 point.x = rectWin.left;
1543 point.y = rectWin.top;
387a3b02 1544
d4597e13
VZ
1545 // MoveWindow positions the child windows relative to the parent, so
1546 // adjust if necessary
1547 if ( !IsTopLevel() )
1548 {
1549 wxWindow *parent = GetParent();
1550 if ( parent )
1551 {
1552 ::ScreenToClient(GetHwndOf(parent), &point);
1553 }
1554 }
a23fd0e1 1555
d4597e13
VZ
1556 DoMoveWindow(point.x, point.y, widthClient, heightClient);
1557 }
42e69d6b 1558}
a23fd0e1 1559
42e69d6b
VZ
1560// For implementation purposes - sometimes decorations make the client area
1561// smaller
1e6feb95 1562wxPoint wxWindowMSW::GetClientAreaOrigin() const
42e69d6b
VZ
1563{
1564 return wxPoint(0, 0);
1565}
a23fd0e1 1566
42e69d6b
VZ
1567// ---------------------------------------------------------------------------
1568// text metrics
1569// ---------------------------------------------------------------------------
a23fd0e1 1570
1e6feb95 1571int wxWindowMSW::GetCharHeight() const
42e69d6b 1572{
f6bcfd97 1573 return wxGetTextMetrics(this).tmHeight;
42e69d6b 1574}
3eddf563 1575
1e6feb95 1576int wxWindowMSW::GetCharWidth() const
42e69d6b 1577{
f6bcfd97
BP
1578 // +1 is needed because Windows apparently adds it when calculating the
1579 // dialog units size in pixels
1580#if wxDIALOG_UNIT_COMPATIBILITY
1e6feb95 1581 return wxGetTextMetrics(this).tmAveCharWidth;
f6bcfd97
BP
1582#else
1583 return wxGetTextMetrics(this).tmAveCharWidth + 1;
1584#endif
42e69d6b 1585}
f4621a09 1586
1e6feb95 1587void wxWindowMSW::GetTextExtent(const wxString& string,
34636400 1588 int *x, int *y,
42e69d6b
VZ
1589 int *descent, int *externalLeading,
1590 const wxFont *theFont) const
1591{
1592 const wxFont *fontToUse = theFont;
1593 if ( !fontToUse )
1594 fontToUse = &m_font;
634903fd 1595
42e69d6b
VZ
1596 HWND hWnd = GetHwnd();
1597 HDC dc = ::GetDC(hWnd);
634903fd 1598
42e69d6b
VZ
1599 HFONT fnt = 0;
1600 HFONT hfontOld = 0;
1601 if ( fontToUse && fontToUse->Ok() )
1602 {
1603 fnt = (HFONT)((wxFont *)fontToUse)->GetResourceHandle(); // const_cast
1604 if ( fnt )
1605 hfontOld = (HFONT)SelectObject(dc,fnt);
2bda0e17 1606 }
341c92a8 1607
42e69d6b
VZ
1608 SIZE sizeRect;
1609 TEXTMETRIC tm;
4438caf4 1610 GetTextExtentPoint(dc, string, (int)string.Length(), &sizeRect);
42e69d6b
VZ
1611 GetTextMetrics(dc, &tm);
1612
1613 if ( fontToUse && fnt && hfontOld )
1614 SelectObject(dc, hfontOld);
1615
1616 ReleaseDC(hWnd, dc);
1617
0655ad29
VZ
1618 if ( x )
1619 *x = sizeRect.cx;
1620 if ( y )
1621 *y = sizeRect.cy;
1622 if ( descent )
1623 *descent = tm.tmDescent;
1624 if ( externalLeading )
1625 *externalLeading = tm.tmExternalLeading;
2bda0e17
KB
1626}
1627
c455ab93 1628#if wxUSE_CARET && WXWIN_COMPATIBILITY
42e69d6b
VZ
1629// ---------------------------------------------------------------------------
1630// Caret manipulation
1631// ---------------------------------------------------------------------------
1632
1e6feb95 1633void wxWindowMSW::CreateCaret(int w, int h)
2bda0e17 1634{
789295bf 1635 SetCaret(new wxCaret(this, w, h));
2bda0e17
KB
1636}
1637
1e6feb95 1638void wxWindowMSW::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
2bda0e17 1639{
789295bf 1640 wxFAIL_MSG("not implemented");
2bda0e17
KB
1641}
1642
1e6feb95 1643void wxWindowMSW::ShowCaret(bool show)
2bda0e17 1644{
789295bf
VZ
1645 wxCHECK_RET( m_caret, "no caret to show" );
1646
1647 m_caret->Show(show);
2bda0e17
KB
1648}
1649
1e6feb95 1650void wxWindowMSW::DestroyCaret()
2bda0e17 1651{
789295bf 1652 SetCaret(NULL);
2bda0e17
KB
1653}
1654
1e6feb95 1655void wxWindowMSW::SetCaretPos(int x, int y)
2bda0e17 1656{
789295bf
VZ
1657 wxCHECK_RET( m_caret, "no caret to move" );
1658
1659 m_caret->Move(x, y);
2bda0e17
KB
1660}
1661
1e6feb95 1662void wxWindowMSW::GetCaretPos(int *x, int *y) const
2d0a075d 1663{
789295bf
VZ
1664 wxCHECK_RET( m_caret, "no caret to get position of" );
1665
1666 m_caret->GetPosition(x, y);
42e69d6b 1667}
789295bf 1668#endif // wxUSE_CARET
2bda0e17 1669
c50f1fb9
VZ
1670// ---------------------------------------------------------------------------
1671// popup menu
1672// ---------------------------------------------------------------------------
1673
2e9f62da
VZ
1674#if wxUSE_MENUS_NATIVE
1675
ed45e263
VZ
1676// yield for WM_COMMAND events only, i.e. process all WM_COMMANDs in the queue
1677// immediately, without waiting for the next event loop iteration
1678//
1679// NB: this function should probably be made public later as it can almost
1680// surely replace wxYield() elsewhere as well
1681static void wxYieldForCommandsOnly()
1682{
1683 // peek all WM_COMMANDs (it will always return WM_QUIT too but we don't
1684 // want to process it here)
1685 MSG msg;
1686 while ( ::PeekMessage(&msg, (HWND)0, WM_COMMAND, WM_COMMAND, PM_REMOVE)
1687 && msg.message != WM_QUIT )
1688 {
1689 wxTheApp->DoMessage((WXMSG *)&msg);
1690 }
7de59551 1691
2b5f62a0
VZ
1692 // If we retrieved a WM_QUIT, insert back into the message queue.
1693 if (msg.message == WM_QUIT)
1694 ::PostQuitMessage(0);
ed45e263
VZ
1695}
1696
1e6feb95 1697bool wxWindowMSW::DoPopupMenu(wxMenu *menu, int x, int y)
c50f1fb9
VZ
1698{
1699 menu->SetInvokingWindow(this);
1700 menu->UpdateUI();
1701
1702 HWND hWnd = GetHwnd();
1703 HMENU hMenu = GetHmenuOf(menu);
1704 POINT point;
1705 point.x = x;
1706 point.y = y;
1707 ::ClientToScreen(hWnd, &point);
1708 wxCurrentPopupMenu = menu;
1709 ::TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, point.x, point.y, 0, hWnd, NULL);
ed45e263
VZ
1710
1711 // we need to do it righ now as otherwise the events are never going to be
1712 // sent to wxCurrentPopupMenu from HandleCommand()
1713 //
1714 // note that even eliminating (ugly) wxCurrentPopupMenu global wouldn't
1715 // help and we'd still need wxYieldForCommandsOnly() as the menu may be
1716 // destroyed as soon as we return (it can be a local variable in the caller
1717 // for example) and so we do need to process the event immediately
1718 wxYieldForCommandsOnly();
1719
c50f1fb9
VZ
1720 wxCurrentPopupMenu = NULL;
1721
1722 menu->SetInvokingWindow(NULL);
1723
1724 return TRUE;
1725}
1726
1e6feb95
VZ
1727#endif // wxUSE_MENUS_NATIVE
1728
42e69d6b
VZ
1729// ===========================================================================
1730// pre/post message processing
1731// ===========================================================================
2bda0e17 1732
1e6feb95 1733long wxWindowMSW::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
42e69d6b
VZ
1734{
1735 if ( m_oldWndProc )
4ce1efe1
CE
1736#ifdef __DIGITALMARS__
1737 return ::CallWindowProc( (FARPROC) m_oldWndProc, GetHwnd(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
1738#else
42e69d6b 1739 return ::CallWindowProc(CASTWNDPROC m_oldWndProc, GetHwnd(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
4ce1efe1 1740#endif
42e69d6b
VZ
1741 else
1742 return ::DefWindowProc(GetHwnd(), nMsg, wParam, lParam);
1743}
2bda0e17 1744
1e6feb95 1745bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
42e69d6b 1746{
1e6feb95
VZ
1747 // wxUniversal implements tab traversal itself
1748#ifndef __WXUNIVERSAL__
42e69d6b 1749 if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) )
2d0a075d 1750 {
42e69d6b
VZ
1751 // intercept dialog navigation keys
1752 MSG *msg = (MSG *)pMsg;
d9317fd4
VZ
1753
1754 // here we try to do all the job which ::IsDialogMessage() usually does
1755 // internally
d9506e77 1756#if 1
573a1586 1757 if ( msg->message == WM_KEYDOWN )
42e69d6b 1758 {
3f7bc32b
VZ
1759 bool bCtrlDown = wxIsCtrlDown();
1760 bool bShiftDown = wxIsShiftDown();
a23fd0e1 1761
42e69d6b
VZ
1762 // WM_GETDLGCODE: ask the control if it wants the key for itself,
1763 // don't process it if it's the case (except for Ctrl-Tab/Enter
1764 // combinations which are always processed)
1765 LONG lDlgCode = 0;
1766 if ( !bCtrlDown )
1767 {
1768 lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0);
2b5f62a0
VZ
1769
1770 // surprizingly, DLGC_WANTALLKEYS bit mask doesn't contain the
1771 // DLGC_WANTTAB nor DLGC_WANTARROWS bits although, logically,
1772 // it, of course, implies them
1773 if ( lDlgCode & DLGC_WANTALLKEYS )
1774 {
1775 lDlgCode |= DLGC_WANTTAB | DLGC_WANTARROWS;
1776 }
42e69d6b 1777 }
a23fd0e1 1778
42e69d6b
VZ
1779 bool bForward = TRUE,
1780 bWindowChange = FALSE;
a23fd0e1 1781
573a1586
VZ
1782 // should we process this message specially?
1783 bool bProcess = TRUE;
9145664b 1784 switch ( msg->wParam )
42e69d6b
VZ
1785 {
1786 case VK_TAB:
319fefa9
VZ
1787 // assume that nobody wants Shift-TAB for himself - if we
1788 // don't do it there is no easy way for a control to grab
1789 // TABs but still let Shift-TAB work as navugation key
1790 if ( (lDlgCode & DLGC_WANTTAB) && !bShiftDown ) {
42e69d6b
VZ
1791 bProcess = FALSE;
1792 }
1793 else {
1794 // Ctrl-Tab cycles thru notebook pages
1795 bWindowChange = bCtrlDown;
319fefa9 1796 bForward = !bShiftDown;
42e69d6b
VZ
1797 }
1798 break;
a23fd0e1 1799
42e69d6b
VZ
1800 case VK_UP:
1801 case VK_LEFT:
1802 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
1803 bProcess = FALSE;
1804 else
1805 bForward = FALSE;
1806 break;
a02eb1d2 1807
42e69d6b
VZ
1808 case VK_DOWN:
1809 case VK_RIGHT:
1810 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
1811 bProcess = FALSE;
1812 break;
2bda0e17 1813
42e69d6b
VZ
1814 case VK_RETURN:
1815 {
edccf428 1816 if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown )
42e69d6b
VZ
1817 {
1818 // control wants to process Enter itself, don't
1819 // call IsDialogMessage() which would interpret
1820 // it
1821 return FALSE;
1822 }
319fefa9
VZ
1823 else if ( lDlgCode & DLGC_BUTTON )
1824 {
3e79ed96
VZ
1825 // let IsDialogMessage() handle this for all
1826 // buttons except the owner-drawn ones which it
1827 // just seems to ignore
1828 long style = ::GetWindowLong(msg->hwnd, GWL_STYLE);
1829 if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW )
1830 {
1831 // emulate the button click
1832 wxWindow *btn = wxFindWinFromHandle((WXHWND)msg->hwnd);
1833 if ( btn )
1834 btn->MSWCommand(BN_CLICKED, 0 /* unused */);
1835 }
1836
319fefa9
VZ
1837 bProcess = FALSE;
1838 }
456bc6d9
VZ
1839 // FIXME: this should be handled by
1840 // wxNavigationKeyEvent handler and not here!!
c50f1fb9
VZ
1841 else
1842 {
91a62137 1843#if wxUSE_BUTTON
456bc6d9
VZ
1844 wxButton *btn = wxDynamicCast(GetDefaultItem(),
1845 wxButton);
73927f8b 1846 if ( btn && btn->IsEnabled() )
c50f1fb9
VZ
1847 {
1848 // if we do have a default button, do press it
1849 btn->MSWCommand(BN_CLICKED, 0 /* unused */);
1850
1851 return TRUE;
1852 }
a6e67b55
VZ
1853 else // no default button
1854 {
1e6feb95 1855#endif // wxUSE_BUTTON
a6e67b55
VZ
1856 // this is a quick and dirty test for a text
1857 // control
1858 if ( !(lDlgCode & DLGC_HASSETSEL) )
1859 {
1860 // don't process Enter, the control might
1861 // need it for itself and don't let
1862 // ::IsDialogMessage() have it as it can
1863 // eat the Enter events sometimes
1864 return FALSE;
1865 }
2b5f62a0
VZ
1866 else if (!IsTopLevel())
1867 {
1868 // if not a top level window, let parent
1869 // handle it
1870 return FALSE;
1871 }
a6e67b55
VZ
1872 //else: treat Enter as TAB: pass to the next
1873 // control as this is the best thing to do
1874 // if the text doesn't handle Enter itself
1875 }
91a62137 1876 }
42e69d6b
VZ
1877 }
1878 break;
2bda0e17 1879
42e69d6b
VZ
1880 default:
1881 bProcess = FALSE;
1882 }
2bda0e17 1883
42e69d6b
VZ
1884 if ( bProcess )
1885 {
1886 wxNavigationKeyEvent event;
1887 event.SetDirection(bForward);
1888 event.SetWindowChange(bWindowChange);
1889 event.SetEventObject(this);
3572173c 1890
42e69d6b 1891 if ( GetEventHandler()->ProcessEvent(event) )
57c0af52 1892 {
42e69d6b 1893 return TRUE;
57c0af52 1894 }
42e69d6b
VZ
1895 }
1896 }
91a62137 1897#else // 0
d9317fd4
VZ
1898 // let ::IsDialogMessage() do almost everything and handle just the
1899 // things it doesn't here: Ctrl-TAB for switching notebook pages
1900 if ( msg->message == WM_KEYDOWN )
1901 {
1902 // don't process system keys here
1903 if ( !(HIWORD(msg->lParam) & KF_ALTDOWN) )
1904 {
3f7bc32b 1905 if ( (msg->wParam == VK_TAB) && wxIsCtrlDown() )
d9317fd4
VZ
1906 {
1907 // find the first notebook parent and change its page
1908 wxWindow *win = this;
1909 wxNotebook *nbook = NULL;
1910 while ( win && !nbook )
1911 {
1912 nbook = wxDynamicCast(win, wxNotebook);
1913 win = win->GetParent();
1914 }
1915
1916 if ( nbook )
1917 {
3f7bc32b 1918 bool forward = !wxIsShiftDown();
d9317fd4
VZ
1919
1920 nbook->AdvanceSelection(forward);
1921 }
1922 }
1923 }
1924 }
91a62137 1925#endif // 1/0
a23fd0e1 1926
aae032a0
VZ
1927 // we handle VK_ESCAPE ourselves in wxDialog::OnCharHook() and we
1928 // shouldn't let IsDialogMessage() get it as it _always_ eats the
1929 // message even when there is no cancel button and when the message is
1930 // needed by the control itself: in particular, it prevents the tree in
1931 // place edit control from being closed with Escape in a dialog
1932 if ( msg->message != WM_KEYDOWN || msg->wParam != VK_ESCAPE )
f6bcfd97 1933 {
573a1586
VZ
1934 // ::IsDialogMessage() can enter in an infinite loop when the
1935 // currently focused window is disabled or hidden and its parent
1936 // has WS_EX_CONTROLPARENT style, so don't call it in this case
085ad686
VZ
1937 bool canSafelyCallIsDlgMsg = TRUE;
1938
48c61225
VZ
1939 HWND hwndFocus = ::GetFocus();
1940 while ( hwndFocus )
aae032a0 1941 {
48c61225
VZ
1942 if ( !::IsWindowEnabled(hwndFocus) ||
1943 !::IsWindowVisible(hwndFocus) )
70a5eef8 1944 {
085ad686
VZ
1945 // it would enter an infinite loop if we do this!
1946 canSafelyCallIsDlgMsg = FALSE;
48c61225
VZ
1947
1948 break;
1949 }
1950
1951 if ( !(::GetWindowLong(hwndFocus, GWL_STYLE) & WS_CHILD) )
1952 {
1953 // it's a top level window, don't go further -- e.g. even
1954 // if the parent of a dialog is disabled, this doesn't
1955 // break navigation inside the dialog
1956 break;
70a5eef8 1957 }
48c61225
VZ
1958
1959 hwndFocus = ::GetParent(hwndFocus);
085ad686
VZ
1960 }
1961
1962 if ( canSafelyCallIsDlgMsg && ::IsDialogMessage(GetHwnd(), msg) )
1963 {
1964 // IsDialogMessage() did something...
1965 return TRUE;
aae032a0 1966 }
f6bcfd97 1967 }
42e69d6b 1968 }
1e6feb95 1969#endif // __WXUNIVERSAL__
a23fd0e1 1970
42e69d6b
VZ
1971#if wxUSE_TOOLTIPS
1972 if ( m_tooltip )
387a3b02 1973 {
42e69d6b
VZ
1974 // relay mouse move events to the tooltip control
1975 MSG *msg = (MSG *)pMsg;
1976 if ( msg->message == WM_MOUSEMOVE )
1977 m_tooltip->RelayEvent(pMsg);
387a3b02 1978 }
42e69d6b 1979#endif // wxUSE_TOOLTIPS
a23fd0e1 1980
42e69d6b 1981 return FALSE;
387a3b02
JS
1982}
1983
1e6feb95 1984bool wxWindowMSW::MSWTranslateMessage(WXMSG* pMsg)
387a3b02 1985{
1e6feb95 1986#if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
c50f1fb9 1987 return m_acceleratorTable.Translate(this, pMsg);
1e6feb95 1988#else
574c939e 1989 (void) pMsg;
1e6feb95
VZ
1990 return FALSE;
1991#endif // wxUSE_ACCEL
387a3b02
JS
1992}
1993
574c939e 1994bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG* WXUNUSED(pMsg))
a37d422a
VZ
1995{
1996 // preprocess all messages by default
1997 return TRUE;
1998}
1999
42e69d6b
VZ
2000// ---------------------------------------------------------------------------
2001// message params unpackers (different for Win16 and Win32)
2002// ---------------------------------------------------------------------------
2bda0e17 2003
42e69d6b 2004#ifdef __WIN32__
c085e333 2005
1e6feb95 2006void wxWindowMSW::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b
VZ
2007 WORD *id, WXHWND *hwnd, WORD *cmd)
2008{
2009 *id = LOWORD(wParam);
2010 *hwnd = (WXHWND)lParam;
2011 *cmd = HIWORD(wParam);
2bda0e17
KB
2012}
2013
1e6feb95 2014void wxWindowMSW::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b 2015 WXWORD *state, WXWORD *minimized, WXHWND *hwnd)
2bda0e17 2016{
42e69d6b
VZ
2017 *state = LOWORD(wParam);
2018 *minimized = HIWORD(wParam);
2019 *hwnd = (WXHWND)lParam;
2bda0e17
KB
2020}
2021
1e6feb95 2022void wxWindowMSW::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b 2023 WXWORD *code, WXWORD *pos, WXHWND *hwnd)
2bda0e17 2024{
42e69d6b
VZ
2025 *code = LOWORD(wParam);
2026 *pos = HIWORD(wParam);
2027 *hwnd = (WXHWND)lParam;
2028}
a23fd0e1 2029
1e6feb95 2030void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b
VZ
2031 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd)
2032{
04ef50df 2033#ifndef __WXMICROWIN__
42e69d6b
VZ
2034 *nCtlColor = CTLCOLOR_BTN;
2035 *hwnd = (WXHWND)lParam;
2036 *hdc = (WXHDC)wParam;
04ef50df 2037#endif
2bda0e17
KB
2038}
2039
1e6feb95 2040void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b 2041 WXWORD *item, WXWORD *flags, WXHMENU *hmenu)
2bda0e17 2042{
42e69d6b
VZ
2043 *item = (WXWORD)wParam;
2044 *flags = HIWORD(wParam);
2045 *hmenu = (WXHMENU)lParam;
2046}
c085e333 2047
42e69d6b 2048#else // Win16
341c92a8 2049
1e6feb95 2050void wxWindowMSW::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b
VZ
2051 WXWORD *id, WXHWND *hwnd, WXWORD *cmd)
2052{
2053 *id = (WXWORD)wParam;
2054 *hwnd = (WXHWND)LOWORD(lParam);
2055 *cmd = HIWORD(lParam);
2bda0e17
KB
2056}
2057
1e6feb95 2058void wxWindowMSW::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b 2059 WXWORD *state, WXWORD *minimized, WXHWND *hwnd)
2bda0e17 2060{
42e69d6b
VZ
2061 *state = (WXWORD)wParam;
2062 *minimized = LOWORD(lParam);
2063 *hwnd = (WXHWND)HIWORD(lParam);
2bda0e17
KB
2064}
2065
1e6feb95 2066void wxWindowMSW::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b 2067 WXWORD *code, WXWORD *pos, WXHWND *hwnd)
2bda0e17 2068{
42e69d6b
VZ
2069 *code = (WXWORD)wParam;
2070 *pos = LOWORD(lParam);
2071 *hwnd = (WXHWND)HIWORD(lParam);
2072}
c085e333 2073
1e6feb95 2074void wxWindowMSW::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b
VZ
2075 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd)
2076{
25889d3c 2077 *hwnd = (WXHWND)LOWORD(lParam);
42e69d6b
VZ
2078 *nCtlColor = (int)HIWORD(lParam);
2079 *hdc = (WXHDC)wParam;
2bda0e17
KB
2080}
2081
1e6feb95 2082void wxWindowMSW::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
42e69d6b 2083 WXWORD *item, WXWORD *flags, WXHMENU *hmenu)
2bda0e17 2084{
42e69d6b
VZ
2085 *item = (WXWORD)wParam;
2086 *flags = LOWORD(lParam);
2087 *hmenu = (WXHMENU)HIWORD(lParam);
2088}
2d0a075d 2089
42e69d6b 2090#endif // Win32/16
c085e333 2091
42e69d6b
VZ
2092// ---------------------------------------------------------------------------
2093// Main wxWindows window proc and the window proc for wxWindow
2094// ---------------------------------------------------------------------------
2bda0e17 2095
42e69d6b
VZ
2096// Hook for new window just as it's being created, when the window isn't yet
2097// associated with the handle
b225f659
VZ
2098static wxWindowMSW *gs_winBeingCreated = NULL;
2099
2100// implementation of wxWindowCreationHook class: it just sets gs_winBeingCreated to the
2101// window being created and insures that it's always unset back later
2102wxWindowCreationHook::wxWindowCreationHook(wxWindowMSW *winBeingCreated)
2103{
2104 gs_winBeingCreated = winBeingCreated;
2105}
2106
2107wxWindowCreationHook::~wxWindowCreationHook()
2108{
2109 gs_winBeingCreated = NULL;
2110}
42e69d6b
VZ
2111
2112// Main window proc
3135f4a7 2113LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
2bda0e17 2114{
42e69d6b
VZ
2115 // trace all messages - useful for the debugging
2116#ifdef __WXDEBUG__
e30285ab 2117#if wxUSE_LOG
223d09f6 2118 wxLogTrace(wxTraceMessages, wxT("Processing %s(wParam=%8lx, lParam=%8lx)"),
9b601c24 2119 wxGetMessageName(message), (long) wParam, lParam);
e30285ab 2120#endif // wxUSE_LOG
42e69d6b 2121#endif // __WXDEBUG__
2bda0e17 2122
1e6feb95 2123 wxWindowMSW *wnd = wxFindWinFromHandle((WXHWND) hWnd);
c085e333 2124
42e69d6b 2125 // when we get the first message for the HWND we just created, we associate
b225f659
VZ
2126 // it with wxWindow stored in gs_winBeingCreated
2127 if ( !wnd && gs_winBeingCreated )
2d0a075d 2128 {
b225f659
VZ
2129 wxAssociateWinWithHandle(hWnd, gs_winBeingCreated);
2130 wnd = gs_winBeingCreated;
2131 gs_winBeingCreated = NULL;
42e69d6b 2132 wnd->SetHWND((WXHWND)hWnd);
2d0a075d 2133 }
2bda0e17 2134
42e69d6b 2135 LRESULT rc;
a23fd0e1 2136
b225f659
VZ
2137 if ( wnd )
2138 rc = wnd->MSWWindowProc(message, wParam, lParam);
a23fd0e1 2139 else
b225f659 2140 rc = ::DefWindowProc(hWnd, message, wParam, lParam);
2bda0e17 2141
42e69d6b 2142 return rc;
f7bd2698
JS
2143}
2144
1e6feb95 2145long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
f7bd2698 2146{
42e69d6b
VZ
2147 // did we process the message?
2148 bool processed = FALSE;
f7bd2698 2149
42e69d6b
VZ
2150 // the return value
2151 union
2bda0e17 2152 {
42e69d6b
VZ
2153 bool allow;
2154 long result;
2155 WXHICON hIcon;
2156 WXHBRUSH hBrush;
2157 } rc;
2bda0e17 2158
42e69d6b
VZ
2159 // for most messages we should return 0 when we do process the message
2160 rc.result = 0;
2bda0e17 2161
42e69d6b 2162 switch ( message )
39136494 2163 {
42e69d6b
VZ
2164 case WM_CREATE:
2165 {
2166 bool mayCreate;
2167 processed = HandleCreate((WXLPCREATESTRUCT)lParam, &mayCreate);
2168 if ( processed )
2169 {
2170 // return 0 to allow window creation
2171 rc.result = mayCreate ? 0 : -1;
2172 }
2173 }
2174 break;
47cbd6da 2175
42e69d6b 2176 case WM_DESTROY:
ad4297f3
VZ
2177 // never set processed to TRUE and *always* pass WM_DESTROY to
2178 // DefWindowProc() as Windows may do some internal cleanup when
2179 // processing it and failing to pass the message along may cause
2180 // memory and resource leaks!
2181 (void)HandleDestroy();
42e69d6b
VZ
2182 break;
2183
2184 case WM_MOVE:
132cb640 2185 processed = HandleMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
42e69d6b 2186 break;
47cbd6da 2187
42e69d6b 2188 case WM_SIZE:
1e6feb95
VZ
2189 switch ( wParam )
2190 {
2191 case SIZE_MAXHIDE:
2192 case SIZE_MAXSHOW:
2193 // we're not interested in these messages at all
2194 break;
2195
2196 case SIZE_MINIMIZED:
2197 // we shouldn't send sizev events for these messages as the
2198 // client size may be negative which breaks existing code
2199 //
2200 // OTOH we might send another (wxMinimizedEvent?) one or
2201 // add an additional parameter to wxSizeEvent if this is
2202 // useful to anybody
2203 break;
2204
2205 default:
2206 wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
2207 // fall through nevertheless
2208
2209 case SIZE_MAXIMIZED:
2210 case SIZE_RESTORED:
2211 processed = HandleSize(LOWORD(lParam), HIWORD(lParam),
2212 wParam);
2213 }
2214 break;
2215
8a46f9b1 2216#ifndef __WXMICROWIN__
1e6feb95
VZ
2217 case WM_ACTIVATEAPP:
2218 wxTheApp->SetActive(wParam != 0, FindFocus());
42e69d6b 2219 break;
8a46f9b1 2220#endif
47cbd6da 2221
42e69d6b 2222 case WM_ACTIVATE:
341c92a8 2223 {
42e69d6b
VZ
2224 WXWORD state, minimized;
2225 WXHWND hwnd;
2226 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
2227
2228 processed = HandleActivate(state, minimized != 0, (WXHWND)hwnd);
341c92a8 2229 }
42e69d6b 2230 break;
341c92a8 2231
42e69d6b
VZ
2232 case WM_SETFOCUS:
2233 processed = HandleSetFocus((WXHWND)(HWND)wParam);
2234 break;
47cbd6da 2235
42e69d6b
VZ
2236 case WM_KILLFOCUS:
2237 processed = HandleKillFocus((WXHWND)(HWND)wParam);
2238 break;
47cbd6da 2239
42e69d6b
VZ
2240 case WM_PAINT:
2241 processed = HandlePaint();
2242 break;
47cbd6da 2243
42e69d6b 2244 case WM_CLOSE:
9fd9e47a
JS
2245#ifdef __WXUNIVERSAL__
2246 // Universal uses its own wxFrame/wxDialog, so we don't receive
2247 // close events unless we have this.
2248 Close();
2249 processed = TRUE;
2250 rc.result = TRUE;
2251#else
42e69d6b
VZ
2252 // don't let the DefWindowProc() destroy our window - we'll do it
2253 // ourselves in ~wxWindow
2254 processed = TRUE;
2255 rc.result = TRUE;
9fd9e47a 2256#endif
42e69d6b 2257 break;
47cbd6da 2258
42e69d6b
VZ
2259 case WM_SHOWWINDOW:
2260 processed = HandleShow(wParam != 0, (int)lParam);
2261 break;
3a19e16d 2262
42e69d6b 2263 case WM_MOUSEMOVE:
132cb640
VZ
2264 processed = HandleMouseMove(GET_X_LPARAM(lParam),
2265 GET_Y_LPARAM(lParam),
2266 wParam);
2267 break;
0d0512bd 2268
d2c52078
RD
2269#if wxUSE_MOUSEWHEEL
2270 case WM_MOUSEWHEEL:
2271 processed = HandleMouseWheel(wParam, lParam);
2272 break;
2273#endif
2274
42e69d6b
VZ
2275 case WM_LBUTTONDOWN:
2276 case WM_LBUTTONUP:
2277 case WM_LBUTTONDBLCLK:
2278 case WM_RBUTTONDOWN:
2279 case WM_RBUTTONUP:
2280 case WM_RBUTTONDBLCLK:
2281 case WM_MBUTTONDOWN:
2282 case WM_MBUTTONUP:
2283 case WM_MBUTTONDBLCLK:
dfafa702 2284 {
98363307 2285#ifdef __WXMICROWIN__
cd4453e5
VZ
2286 // MicroWindows seems to ignore the fact that a window is
2287 // disabled. So catch mouse events and throw them away if
2288 // necessary.
d0a3d109 2289 wxWindowMSW* win = this;
dfafa702 2290 for ( ;; )
d0a3d109
VZ
2291 {
2292 if (!win->IsEnabled())
2293 {
2294 processed = TRUE;
2295 break;
2296 }
dfafa702 2297
d0a3d109 2298 win = win->GetParent();
dfafa702 2299 if ( !win || win->IsTopLevel() )
d0a3d109
VZ
2300 break;
2301 }
dfafa702 2302
03e0b2b1
VZ
2303 if ( processed )
2304 break;
2305
dfafa702 2306#endif // __WXMICROWIN__
03e0b2b1
VZ
2307 int x = GET_X_LPARAM(lParam),
2308 y = GET_Y_LPARAM(lParam);
dfafa702 2309
03e0b2b1
VZ
2310 // redirect the event to a static control if necessary by
2311 // finding one under mouse
2312 wxWindowMSW *win;
2313 if ( GetCapture() == this )
2314 {
2315 // but don't do it if the mouse is captured by this window
2316 // because then it should really get this event itself
2317 win = this;
d0a3d109 2318 }
03e0b2b1
VZ
2319 else
2320 {
2321 win = FindWindowForMouseEvent(this, &x, &y);
2b5f62a0
VZ
2322
2323 // this should never happen
2324 wxCHECK_MSG( win, 0,
2325 _T("FindWindowForMouseEvent() returned NULL") );
2326
2327 // for the standard classes their WndProc sets the focus to
2328 // them anyhow and doing it from here results in some weird
2329 // problems, but for our windows we want them to acquire
2330 // focus when clicked
2331 if ( !win->IsOfStandardClass() )
2332 {
2333 if ( message == WM_LBUTTONDOWN && win->AcceptsFocus() )
2334 win->SetFocus();
2335 }
03e0b2b1
VZ
2336 }
2337
2338 processed = win->HandleMouseEvent(message, x, y, wParam);
98363307 2339 }
dfafa702 2340 break;
d0a3d109 2341
cd4453e5 2342#ifdef MM_JOY1MOVE
42e69d6b
VZ
2343 case MM_JOY1MOVE:
2344 case MM_JOY2MOVE:
2345 case MM_JOY1ZMOVE:
2346 case MM_JOY2ZMOVE:
2347 case MM_JOY1BUTTONDOWN:
2348 case MM_JOY2BUTTONDOWN:
2349 case MM_JOY1BUTTONUP:
2350 case MM_JOY2BUTTONUP:
132cb640
VZ
2351 processed = HandleJoystickEvent(message,
2352 GET_X_LPARAM(lParam),
2353 GET_Y_LPARAM(lParam),
2354 wParam);
42e69d6b 2355 break;
cd4453e5 2356#endif // __WXMICROWIN__
47cbd6da 2357
42e69d6b
VZ
2358 case WM_SYSCOMMAND:
2359 processed = HandleSysCommand(wParam, lParam);
2360 break;
2a47d3c1 2361
42e69d6b
VZ
2362 case WM_COMMAND:
2363 {
2364 WORD id, cmd;
2365 WXHWND hwnd;
2366 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
47cbd6da 2367
42e69d6b
VZ
2368 processed = HandleCommand(id, cmd, hwnd);
2369 }
2370 break;
7d532b0c 2371
42e69d6b
VZ
2372#ifdef __WIN95__
2373 case WM_NOTIFY:
2374 processed = HandleNotify((int)wParam, lParam, &rc.result);
2375 break;
2376#endif // Win95
2bda0e17 2377
42e69d6b 2378 // for these messages we must return TRUE if process the message
cd4453e5 2379#ifdef WM_DRAWITEM
42e69d6b
VZ
2380 case WM_DRAWITEM:
2381 case WM_MEASUREITEM:
2382 {
2383 int idCtrl = (UINT)wParam;
2384 if ( message == WM_DRAWITEM )
2385 {
2386 processed = MSWOnDrawItem(idCtrl,
2387 (WXDRAWITEMSTRUCT *)lParam);
2388 }
2389 else
2390 {
2391 processed = MSWOnMeasureItem(idCtrl,
2392 (WXMEASUREITEMSTRUCT *)lParam);
2393 }
57a7b7c1 2394
42e69d6b
VZ
2395 if ( processed )
2396 rc.result = TRUE;
2397 }
2398 break;
cd4453e5
VZ
2399#endif // defined(WM_DRAWITEM)
2400
9bf84618 2401 case WM_GETDLGCODE:
5a403e3f 2402 if ( !IsOfStandardClass() )
9bf84618 2403 {
5a403e3f
VZ
2404 // we always want to get the char events
2405 rc.result = DLGC_WANTCHARS;
2406
2407 if ( GetWindowStyleFlag() & wxWANTS_CHARS )
2408 {
2409 // in fact, we want everything
2410 rc.result |= DLGC_WANTARROWS |
2411 DLGC_WANTTAB |
2412 DLGC_WANTALLKEYS;
2413 }
2414
9bf84618
VZ
2415 processed = TRUE;
2416 }
101f488c 2417 //else: get the dlg code from the DefWindowProc()
9bf84618
VZ
2418 break;
2419
4004f41e 2420 case WM_SYSKEYDOWN:
42e69d6b 2421 case WM_KEYDOWN:
9c7df356
VZ
2422 // If this has been processed by an event handler, return 0 now
2423 // (we've handled it).
2424 m_lastKeydownProcessed = HandleKeyDown((WORD) wParam, lParam);
2425 if ( m_lastKeydownProcessed )
2d0a075d 2426 {
42e69d6b 2427 processed = TRUE;
2d0a075d 2428 }
81d66cf3 2429
2b5f62a0 2430 if ( !processed )
42e69d6b 2431 {
2b5f62a0
VZ
2432 switch ( wParam )
2433 {
2434 // we consider these message "not interesting" to OnChar, so
2435 // just don't do anything more with them
2436 case VK_SHIFT:
2437 case VK_CONTROL:
2438 case VK_MENU:
2439 case VK_CAPITAL:
2440 case VK_NUMLOCK:
2441 case VK_SCROLL:
2442 processed = TRUE;
2443 break;
2bda0e17 2444
2b5f62a0
VZ
2445 // avoid duplicate messages to OnChar for these ASCII keys:
2446 // they will be translated by TranslateMessage() and received
2447 // in WM_CHAR
2448 case VK_ESCAPE:
2449 case VK_SPACE:
2450 case VK_RETURN:
2451 case VK_BACK:
2452 case VK_TAB:
2453 case VK_ADD:
2454 case VK_SUBTRACT:
2455 case VK_MULTIPLY:
2456 case VK_DIVIDE:
2457 case VK_OEM_1:
2458 case VK_OEM_2:
2459 case VK_OEM_3:
2460 case VK_OEM_4:
2461 case VK_OEM_5:
2462 case VK_OEM_6:
2463 case VK_OEM_7:
2464 case VK_OEM_PLUS:
2465 case VK_OEM_COMMA:
2466 case VK_OEM_MINUS:
2467 case VK_OEM_PERIOD:
2468 // but set processed to FALSE, not TRUE to still pass them
2469 // to the control's default window proc - otherwise
2470 // built-in keyboard handling won't work
2471 processed = FALSE;
2472 break;
2bda0e17 2473
42e69d6b 2474#ifdef VK_APPS
2b5f62a0
VZ
2475 // special case of VK_APPS: treat it the same as right mouse
2476 // click because both usually pop up a context menu
2477 case VK_APPS:
2478 {
2479 WPARAM flags;
2480 int x, y;
4aff28fc 2481
2b5f62a0
VZ
2482 TranslateKbdEventToMouse(this, &x, &y, &flags);
2483 processed = HandleMouseEvent(WM_RBUTTONDOWN, x, y, flags);
2484 }
2485 break;
42e69d6b 2486#endif // VK_APPS
2bda0e17 2487
2b5f62a0
VZ
2488 default:
2489 // do generate a CHAR event
2490 processed = HandleChar((WORD)wParam, lParam);
2491 }
42e69d6b 2492 }
2b5f62a0
VZ
2493 if (message == WM_SYSKEYDOWN) // Let Windows still handle the SYSKEYs
2494 processed = FALSE;
42e69d6b 2495 break;
2bda0e17 2496
4004f41e 2497 case WM_SYSKEYUP:
42e69d6b 2498 case WM_KEYUP:
4aff28fc
VZ
2499#ifdef VK_APPS
2500 // special case of VK_APPS: treat it the same as right mouse button
2501 if ( wParam == VK_APPS )
2502 {
2503 WPARAM flags;
2504 int x, y;
2505
2506 TranslateKbdEventToMouse(this, &x, &y, &flags);
2507 processed = HandleMouseEvent(WM_RBUTTONUP, x, y, flags);
2508 }
2509 else
2510#endif // VK_APPS
2511 {
2512 processed = HandleKeyUp((WORD) wParam, lParam);
2513 }
42e69d6b 2514 break;
debe6624 2515
170cbe33 2516 case WM_SYSCHAR:
42e69d6b 2517 case WM_CHAR: // Always an ASCII character
d9f14e16
RD
2518 if ( m_lastKeydownProcessed )
2519 {
2520 // The key was handled in the EVT_KEY_DOWN and handling
2521 // a key in an EVT_KEY_DOWN handler is meant, by
2522 // design, to prevent EVT_CHARs from happening
2523 m_lastKeydownProcessed = FALSE;
2524 processed = TRUE;
2525 }
2526 else
7de5bdf4 2527 {
d9f14e16 2528 processed = HandleChar((WORD)wParam, lParam, TRUE);
7de5bdf4 2529 }
42e69d6b 2530 break;
2bda0e17 2531
42e69d6b
VZ
2532 case WM_HSCROLL:
2533 case WM_VSCROLL:
a23fd0e1 2534 {
42e69d6b
VZ
2535 WXWORD code, pos;
2536 WXHWND hwnd;
2537 UnpackScroll(wParam, lParam, &code, &pos, &hwnd);
2bda0e17 2538
42e69d6b
VZ
2539 processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL
2540 : wxVERTICAL,
2541 code, pos, hwnd);
a23fd0e1 2542 }
42e69d6b 2543 break;
a23fd0e1 2544
42e69d6b 2545 // CTLCOLOR messages are sent by children to query the parent for their
04ef50df
JS
2546 // colors#ifndef __WXMICROWIN__
2547#ifndef __WXMICROWIN__
42e69d6b
VZ
2548#ifdef __WIN32__
2549 case WM_CTLCOLORMSGBOX:
2550 case WM_CTLCOLOREDIT:
2551 case WM_CTLCOLORLISTBOX:
2552 case WM_CTLCOLORBTN:
2553 case WM_CTLCOLORDLG:
2554 case WM_CTLCOLORSCROLLBAR:
2555 case WM_CTLCOLORSTATIC:
2556#else // Win16
2557 case WM_CTLCOLOR:
2558#endif // Win32/16
a23fd0e1 2559 {
42e69d6b
VZ
2560 WXWORD nCtlColor;
2561 WXHDC hdc;
2562 WXHWND hwnd;
2563 UnpackCtlColor(wParam, lParam, &nCtlColor, &hdc, &hwnd);
2564
2565 processed = HandleCtlColor(&rc.hBrush,
2566 (WXHDC)hdc,
2567 (WXHWND)hwnd,
2568 nCtlColor,
2569 message,
2570 wParam,
2571 lParam);
a23fd0e1 2572 }
42e69d6b 2573 break;
cd4453e5 2574#endif // !__WXMICROWIN__
debe6624 2575
42e69d6b 2576 case WM_SYSCOLORCHANGE:
90c1530a 2577 // the return value for this message is ignored
42e69d6b
VZ
2578 processed = HandleSysColorChange();
2579 break;
2bda0e17 2580
574c939e
KB
2581 case WM_DISPLAYCHANGE:
2582 processed = HandleDisplayChange();
2583 break;
2584
42e69d6b
VZ
2585 case WM_PALETTECHANGED:
2586 processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
2587 break;
2bda0e17 2588
a5e84126
JS
2589 case WM_CAPTURECHANGED:
2590 processed = HandleCaptureChanged((WXHWND) (HWND) lParam);
2591 break;
2592
42e69d6b
VZ
2593 case WM_QUERYNEWPALETTE:
2594 processed = HandleQueryNewPalette();
2595 break;
2bda0e17 2596
42e69d6b
VZ
2597 case WM_ERASEBKGND:
2598 processed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
2599 if ( processed )
2600 {
2601 // we processed the message, i.e. erased the background
2602 rc.result = TRUE;
2603 }
2604 break;
debe6624 2605
42e69d6b
VZ
2606 case WM_DROPFILES:
2607 processed = HandleDropFiles(wParam);
2608 break;
2bda0e17 2609
42e69d6b
VZ
2610 case WM_INITDIALOG:
2611 processed = HandleInitDialog((WXHWND)(HWND)wParam);
a23fd0e1 2612
42e69d6b
VZ
2613 if ( processed )
2614 {
2615 // we never set focus from here
2616 rc.result = FALSE;
2617 }
2618 break;
a23fd0e1 2619
42e69d6b
VZ
2620 case WM_QUERYENDSESSION:
2621 processed = HandleQueryEndSession(lParam, &rc.allow);
2622 break;
2bda0e17 2623
42e69d6b
VZ
2624 case WM_ENDSESSION:
2625 processed = HandleEndSession(wParam != 0, lParam);
2626 break;
2bda0e17 2627
42e69d6b 2628 case WM_GETMINMAXINFO:
25889d3c 2629 processed = HandleGetMinMaxInfo((MINMAXINFO*)lParam);
42e69d6b 2630 break;
debe6624 2631
42e69d6b
VZ
2632 case WM_SETCURSOR:
2633 processed = HandleSetCursor((WXHWND)(HWND)wParam,
2634 LOWORD(lParam), // hit test
2635 HIWORD(lParam)); // mouse msg
2636
2637 if ( processed )
2638 {
2639 // returning TRUE stops the DefWindowProc() from further
2640 // processing this message - exactly what we need because we've
2641 // just set the cursor.
2642 rc.result = TRUE;
2643 }
2644 break;
4cdc2c13 2645
ed5317e5
JS
2646#if wxUSE_ACCESSIBILITY
2647 case WM_GETOBJECT:
2648 {
2649 //WPARAM dwFlags = (WPARAM) (DWORD) wParam;
2650 LPARAM dwObjId = (LPARAM) (DWORD) lParam;
2651
2652 if (dwObjId == OBJID_CLIENT && GetOrCreateAccessible())
2653 {
2654 return LresultFromObject(IID_IAccessible, wParam, (IUnknown*) GetAccessible()->GetIAccessible());
2655 }
2656 break;
2657 }
2658#endif
2659
04ef50df 2660#if defined(__WIN32__) && defined(WM_HELP)
b96340e6 2661 case WM_HELP:
b96340e6 2662 {
4cdc2c13
VZ
2663 HELPINFO* info = (HELPINFO*) lParam;
2664 // Don't yet process menu help events, just windows
2665 if (info->iContextType == HELPINFO_WINDOW)
b96340e6 2666 {
24ce4c18 2667 wxWindowMSW* subjectOfHelp = this;
4cdc2c13
VZ
2668 bool eventProcessed = FALSE;
2669 while (subjectOfHelp && !eventProcessed)
2670 {
2671 wxHelpEvent helpEvent(wxEVT_HELP,
2672 subjectOfHelp->GetId(),
2673 wxPoint(info->MousePos.x,
2674 info->MousePos.y) );
2675 helpEvent.SetEventObject(this);
2676 eventProcessed =
2677 GetEventHandler()->ProcessEvent(helpEvent);
2678
2679 // Go up the window hierarchy until the event is
2680 // handled (or not)
2681 subjectOfHelp = subjectOfHelp->GetParent();
2682 }
b96340e6 2683
4cdc2c13 2684 processed = eventProcessed;
b96340e6 2685 }
4cdc2c13
VZ
2686 else if (info->iContextType == HELPINFO_MENUITEM)
2687 {
2688 wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
2689 helpEvent.SetEventObject(this);
2690 processed = GetEventHandler()->ProcessEvent(helpEvent);
69231000 2691
4cdc2c13
VZ
2692 }
2693 //else: processed is already FALSE
b96340e6 2694 }
b96340e6 2695 break;
4cdc2c13 2696
69231000 2697 case WM_CONTEXTMENU:
4cdc2c13
VZ
2698 {
2699 // we don't convert from screen to client coordinates as
2700 // the event may be handled by a parent window
2701 wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
2702
2703 wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt);
0d6ae333 2704 processed = GetEventHandler()->ProcessEvent(evtCtx);
4cdc2c13 2705 }
69231000 2706 break;
b74cce40
VZ
2707
2708 case WM_MENUCHAR:
2709 // we're only interested in our own menus, not MF_SYSMENU
2710 if ( HIWORD(wParam) == MF_POPUP )
2711 {
2712 // handle menu chars for ownerdrawn menu items
2713 int i = HandleMenuChar(toupper(LOWORD(wParam)), lParam);
2714 if ( i != wxNOT_FOUND )
2715 {
2716 rc.result = MAKELRESULT(i, MNC_EXECUTE);
2717 processed = TRUE;
2718 }
2719 }
2720 break;
4cdc2c13 2721#endif // __WIN32__
a23fd0e1 2722 }
2d0a075d 2723
42e69d6b 2724 if ( !processed )
2d0a075d 2725 {
42e69d6b 2726#ifdef __WXDEBUG__
e30285ab 2727#if wxUSE_LOG
223d09f6 2728 wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."),
42e69d6b 2729 wxGetMessageName(message));
e30285ab 2730#endif // wxUSE_LOG
42e69d6b
VZ
2731#endif // __WXDEBUG__
2732 rc.result = MSWDefWindowProc(message, wParam, lParam);
a23fd0e1 2733 }
2bda0e17 2734
42e69d6b 2735 return rc.result;
2bda0e17
KB
2736}
2737
b225f659
VZ
2738// ----------------------------------------------------------------------------
2739// wxWindow <-> HWND map
2740// ----------------------------------------------------------------------------
2bda0e17 2741
1bffa913 2742wxWinHashTable *wxWinHandleHash = NULL;
b225f659 2743
42e69d6b 2744wxWindow *wxFindWinFromHandle(WXHWND hWnd)
4ce81a75 2745{
1bffa913 2746 return wxWinHandleHash->Get((long)hWnd);
42e69d6b 2747}
4ce81a75 2748
1e6feb95 2749void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win)
42e69d6b
VZ
2750{
2751 // adding NULL hWnd is (first) surely a result of an error and
2752 // (secondly) breaks menu command processing
2753 wxCHECK_RET( hWnd != (HWND)NULL,
223d09f6 2754 wxT("attempt to add a NULL hWnd to window list ignored") );
4ce81a75 2755
c7527e3f 2756 wxWindow *oldWin = wxFindWinFromHandle((WXHWND) hWnd);
b225f659 2757#ifdef __WXDEBUG__
c7527e3f
JS
2758 if ( oldWin && (oldWin != win) )
2759 {
b225f659 2760 wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
9b601c24 2761 (int) hWnd, win->GetClassInfo()->GetClassName());
c7527e3f 2762 }
b225f659
VZ
2763 else
2764#endif // __WXDEBUG__
2765 if (!oldWin)
c7527e3f 2766 {
d2d14464 2767 wxWinHandleHash->Put((long)hWnd, (wxWindow *)win);
c7527e3f 2768 }
42e69d6b 2769}
4ce81a75 2770
1e6feb95 2771void wxRemoveHandleAssociation(wxWindowMSW *win)
42e69d6b 2772{
1bffa913 2773 wxWinHandleHash->Delete((long)win->GetHWND());
4ce81a75
JS
2774}
2775
b225f659
VZ
2776// ----------------------------------------------------------------------------
2777// various MSW speciic class dependent functions
2778// ----------------------------------------------------------------------------
2779
42e69d6b
VZ
2780// Default destroyer - override if you destroy it in some other way
2781// (e.g. with MDI child windows)
1e6feb95 2782void wxWindowMSW::MSWDestroyWindow()
4ce81a75 2783{
42e69d6b 2784}
4ce81a75 2785
b225f659
VZ
2786bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos,
2787 const wxSize& size,
2788 int& x, int& y,
2789 int& w, int& h) const
2bda0e17 2790{
2a77c8c4
VZ
2791 static const int DEFAULT_Y = 200;
2792 static const int DEFAULT_H = 250;
2793
b225f659 2794 bool nonDefault = FALSE;
c085e333 2795
b225f659
VZ
2796 if ( pos.x == -1 )
2797 {
2798 // if set x to CW_USEDEFAULT, y parameter is ignored anyhow so we can
2799 // just as well set it to CW_USEDEFAULT as well
2800 x =
2801 y = CW_USEDEFAULT;
2802 }
2803 else
a23fd0e1 2804 {
2a77c8c4
VZ
2805 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
2806 // neither because it is not handled as a special value by Windows then
2807 // and so we have to choose some default value for it
b225f659 2808 x = pos.x;
2a77c8c4 2809 y = pos.y == -1 ? DEFAULT_Y : pos.y;
c085e333 2810
b225f659 2811 nonDefault = TRUE;
42e69d6b 2812 }
2bda0e17 2813
b889a3a2
VZ
2814 /*
2815 NB: there used to be some code here which set the initial size of the
2816 window to the client size of the parent if no explicit size was
2817 specified. This was wrong because wxWindows programs often assume
2818 that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
2819 it. To see why, you should understand that Windows sends WM_SIZE from
2820 inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
2821 from some base class ctor and so this WM_SIZE is not processed in the
2822 real class' OnSize() (because it's not fully constructed yet and the
2823 event goes to some base class OnSize() instead). So the WM_SIZE we
2824 rely on is the one sent when the parent frame resizes its children
2825 but here is the problem: if the child already has just the right
2826 size, nothing will happen as both wxWindows and Windows check for
2827 this and ignore any attempts to change the window size to the size it
2828 already has - so no WM_SIZE would be sent.
2829 */
2830 if ( size.x == -1 )
b225f659 2831 {
2a77c8c4 2832 // as above, h is not used at all in this case anyhow
b889a3a2
VZ
2833 w =
2834 h = CW_USEDEFAULT;
b225f659
VZ
2835 }
2836 else
8614c467 2837 {
2a77c8c4 2838 // and, again as above, we can't set the height to CW_USEDEFAULT here
b225f659 2839 w = size.x;
2a77c8c4 2840 h = size.y == -1 ? DEFAULT_H : size.y;
b225f659
VZ
2841
2842 nonDefault = TRUE;
8614c467
VZ
2843 }
2844
b225f659
VZ
2845 return nonDefault;
2846}
2847
9dfef5ac
VZ
2848WXHWND wxWindowMSW::MSWGetParent() const
2849{
d285d708 2850 return m_parent ? m_parent->GetHWND() : WXHWND(NULL);
9dfef5ac
VZ
2851}
2852
b225f659
VZ
2853bool wxWindowMSW::MSWCreate(const wxChar *wclass,
2854 const wxChar *title,
2855 const wxPoint& pos,
2856 const wxSize& size,
2857 WXDWORD style,
2858 WXDWORD extendedStyle)
2859{
2860 // choose the position/size for the new window
2861 int x, y, w, h;
2862 (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h);
2863
b225f659
VZ
2864 // controlId is menu handle for the top level windows, so set it to 0
2865 // unless we're creating a child window
f586fde3 2866 int controlId = style & WS_CHILD ? GetId() : 0;
2bda0e17 2867
b225f659
VZ
2868 // for each class "Foo" we have we also have "FooNR" ("no repaint") class
2869 // which is the same but without CS_[HV]REDRAW class styles so using it
2870 // ensures that the window is not fully repainted on each resize
2871 wxString className(wclass);
2872 if ( GetWindowStyleFlag() & wxNO_FULL_REPAINT_ON_RESIZE )
2873 {
2874 className += wxT("NR");
a23fd0e1 2875 }
c085e333 2876
b225f659
VZ
2877 // do create the window
2878 wxWindowCreationHook hook(this);
b3daa5a3 2879
b225f659 2880 m_hWnd = (WXHWND)::CreateWindowEx
9dfef5ac
VZ
2881 (
2882 extendedStyle,
2883 className,
2884 title ? title : wxT(""),
2885 style,
2886 x, y, w, h,
2887 (HWND)MSWGetParent(),
2888 (HMENU)controlId,
2889 wxGetInstance(),
2890 NULL // no extra data
2891 );
b225f659
VZ
2892
2893 if ( !m_hWnd )
c7527e3f 2894 {
b225f659
VZ
2895 wxLogSysError(_("Can't create window of class %s"), wclass);
2896
2897 return FALSE;
c7527e3f 2898 }
b3daa5a3 2899
b225f659 2900 SubclassWin(m_hWnd);
c085e333 2901
a756f210 2902 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
8bf30fe9 2903
42e69d6b 2904 return TRUE;
2bda0e17
KB
2905}
2906
42e69d6b
VZ
2907// ===========================================================================
2908// MSW message handlers
2909// ===========================================================================
2910
2911// ---------------------------------------------------------------------------
2912// WM_NOTIFY
2913// ---------------------------------------------------------------------------
2914
2915#ifdef __WIN95__
2b15b970 2916
1e6feb95 2917bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
2bda0e17 2918{
04ef50df 2919#ifndef __WXMICROWIN__
42e69d6b
VZ
2920 LPNMHDR hdr = (LPNMHDR)lParam;
2921 HWND hWnd = hdr->hwndFrom;
2922 wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd);
2923
2b15b970 2924 // if the control is one of our windows, let it handle the message itself
42e69d6b 2925 if ( win )
564b2609 2926 {
42e69d6b 2927 return win->MSWOnNotify(idCtrl, lParam, result);
564b2609 2928 }
2bda0e17 2929
2b15b970
VZ
2930 // VZ: why did we do it? normally this is unnecessary and, besides, it
2931 // breaks the message processing for the toolbars because the tooltip
2932 // notifications were being forwarded to the toolbar child controls
2933 // (if it had any) before being passed to the toolbar itself, so in my
2934 // example the tooltip for the combobox was always shown instead of the
2935 // correct button tooltips
2936#if 0
42e69d6b
VZ
2937 // try all our children
2938 wxWindowList::Node *node = GetChildren().GetFirst();
2939 while ( node )
564b2609 2940 {
42e69d6b
VZ
2941 wxWindow *child = node->GetData();
2942 if ( child->MSWOnNotify(idCtrl, lParam, result) )
2943 {
2944 return TRUE;
42e69d6b 2945 }
2d0a075d 2946
42e69d6b
VZ
2947 node = node->GetNext();
2948 }
2b15b970 2949#endif // 0
2d0a075d 2950
2b15b970 2951 // by default, handle it ourselves
42e69d6b 2952 return MSWOnNotify(idCtrl, lParam, result);
cd4453e5 2953#else // __WXMICROWIN__
04ef50df
JS
2954 return FALSE;
2955#endif
42e69d6b 2956}
2d0a075d 2957
bd9cd534
VZ
2958#if wxUSE_TOOLTIPS
2959
2960bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
2961 WXLPARAM lParam,
2962 const wxString& ttip)
2963{
2964 // I don't know why it happens, but the versions of comctl32.dll starting
2965 // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
2966 // this message is supposed to be sent to Unicode programs only) -- hence
2967 // we need to handle it as well, otherwise no tooltips will be shown in
2968 // this case
2969
b40e2278 2970 if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW) || ttip.empty() )
bd9cd534
VZ
2971 {
2972 // not a tooltip message or no tooltip to show anyhow
2973 return FALSE;
2974 }
2975
2976 LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
2977
2b5f62a0 2978#if !wxUSE_UNICODE
b40e2278 2979 if ( code == (WXUINT) TTN_NEEDTEXTA )
bd9cd534 2980 {
2b5f62a0
VZ
2981 // we pass just the pointer as we store the string internally anyhow
2982 ttText->lpszText = (char *)ttip.c_str();
bd9cd534 2983 }
2b5f62a0
VZ
2984 else // TTN_NEEDTEXTW
2985#endif // !Unicode
bd9cd534
VZ
2986 {
2987#if wxUSE_UNICODE
2b5f62a0 2988 // in Unicode mode this is just what we need
bd9cd534
VZ
2989 ttText->lpszText = (wxChar *)ttip.c_str();
2990#else // !Unicode
5571f3d3
VS
2991 MultiByteToWideChar(CP_ACP, 0, ttip, ttip.length()+1,
2992 (wchar_t *)ttText->szText,
2993 sizeof(ttText->szText) / sizeof(wchar_t));
bd9cd534
VZ
2994#endif // Unicode/!Unicode
2995 }
2996
2997 return TRUE;
2998}
2999
3000#endif // wxUSE_TOOLTIPS
3001
1e6feb95 3002bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl),
bd9cd534
VZ
3003 WXLPARAM lParam,
3004 WXLPARAM* WXUNUSED(result))
42e69d6b
VZ
3005{
3006#if wxUSE_TOOLTIPS
bd9cd534 3007 if ( m_tooltip )
42e69d6b 3008 {
bd9cd534
VZ
3009 NMHDR* hdr = (NMHDR *)lParam;
3010 if ( HandleTooltipNotify(hdr->code, lParam, m_tooltip->GetTip()))
3011 {
3012 // processed
3013 return TRUE;
3014 }
42e69d6b
VZ
3015 }
3016#endif // wxUSE_TOOLTIPS
3017
3018 return FALSE;
3019}
2b15b970 3020
42e69d6b
VZ
3021#endif // __WIN95__
3022
3023// ---------------------------------------------------------------------------
3024// end session messages
3025// ---------------------------------------------------------------------------
2d0a075d 3026
1e6feb95 3027bool wxWindowMSW::HandleQueryEndSession(long logOff, bool *mayEnd)
42e69d6b
VZ
3028{
3029 wxCloseEvent event(wxEVT_QUERY_END_SESSION, -1);
3030 event.SetEventObject(wxTheApp);
3031 event.SetCanVeto(TRUE);
a17e237f 3032 event.SetLoggingOff(logOff == (long)ENDSESSION_LOGOFF);
2d0a075d 3033
42e69d6b
VZ
3034 bool rc = wxTheApp->ProcessEvent(event);
3035
3036 if ( rc )
3037 {
3038 // we may end only if the app didn't veto session closing (double
3039 // negation...)
3040 *mayEnd = !event.GetVeto();
2d0a075d
JS
3041 }
3042
42e69d6b 3043 return rc;
2bda0e17
KB
3044}
3045
1e6feb95 3046bool wxWindowMSW::HandleEndSession(bool endSession, long logOff)
2bda0e17 3047{
42e69d6b
VZ
3048 // do nothing if the session isn't ending
3049 if ( !endSession )
3050 return FALSE;
a23fd0e1 3051
519dc37f
VZ
3052 // only send once
3053 if ( (this != wxTheApp->GetTopWindow()) )
3054 return FALSE;
3055
42e69d6b
VZ
3056 wxCloseEvent event(wxEVT_END_SESSION, -1);
3057 event.SetEventObject(wxTheApp);
3058 event.SetCanVeto(FALSE);
a17e237f 3059 event.SetLoggingOff( (logOff == (long)ENDSESSION_LOGOFF) );
519dc37f
VZ
3060
3061 return wxTheApp->ProcessEvent(event);
2bda0e17
KB
3062}
3063
42e69d6b
VZ
3064// ---------------------------------------------------------------------------
3065// window creation/destruction
3066// ---------------------------------------------------------------------------
3067
61179e28
VZ
3068bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate)
3069{
3070 // if we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
3071 // parent as well as otherwise several Win32 functions using
3072 // GetNextDlgTabItem() to iterate over all controls such as
3073 // IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
3074 // all of them iterate over all the controls starting from the focus and
3075 // stop iterating when they get back to the focus but unless all parents
3076 // have WS_EX_CONTROLPARENT bit set, they would never get back to focus
3077 if ( ((CREATESTRUCT *)cs)->dwExStyle & WS_EX_CONTROLPARENT )
3078 {
3079 // there is no need to do anything for the top level windows
3080 const wxWindow *parent = GetParent();
5624b2a1 3081 while ( parent && !parent->IsTopLevel() )
61179e28
VZ
3082 {
3083 LONG exStyle = ::GetWindowLong(GetHwndOf(parent), GWL_EXSTYLE);
3084 if ( !(exStyle & WS_EX_CONTROLPARENT) )
3085 {
3086 // force the parent to have this style
3087 ::SetWindowLong(GetHwndOf(parent), GWL_EXSTYLE,
3088 exStyle | WS_EX_CONTROLPARENT);
3089 }
5624b2a1
VZ
3090
3091 parent = parent->GetParent();
61179e28
VZ
3092 }
3093 }
3094
42e69d6b 3095 // TODO: should generate this event from WM_NCCREATE
1e6feb95 3096 wxWindowCreateEvent event((wxWindow *)this);
42e69d6b 3097 (void)GetEventHandler()->ProcessEvent(event);
a23fd0e1 3098
42e69d6b
VZ
3099 *mayCreate = TRUE;
3100
3101 return TRUE;
2bda0e17
KB
3102}
3103
1e6feb95 3104bool wxWindowMSW::HandleDestroy()
2bda0e17 3105{
7de59551 3106 SendDestroyEvent();
42e69d6b
VZ
3107
3108 // delete our drop target if we've got one
3109#if wxUSE_DRAG_AND_DROP
3110 if ( m_dropTarget != NULL )
2d0a075d 3111 {
42e69d6b
VZ
3112 m_dropTarget->Revoke(m_hWnd);
3113
3114 delete m_dropTarget;
3115 m_dropTarget = NULL;
2d0a075d 3116 }
42e69d6b 3117#endif // wxUSE_DRAG_AND_DROP
2bda0e17 3118
42e69d6b
VZ
3119 // WM_DESTROY handled
3120 return TRUE;
2bda0e17
KB
3121}
3122
42e69d6b
VZ
3123// ---------------------------------------------------------------------------
3124// activation/focus
3125// ---------------------------------------------------------------------------
3126
1e6feb95 3127bool wxWindowMSW::HandleActivate(int state,
42e69d6b
VZ
3128 bool WXUNUSED(minimized),
3129 WXHWND WXUNUSED(activate))
2bda0e17 3130{
42e69d6b
VZ
3131 wxActivateEvent event(wxEVT_ACTIVATE,
3132 (state == WA_ACTIVE) || (state == WA_CLICKACTIVE),
3133 m_windowId);
3134 event.SetEventObject(this);
3135
3136 return GetEventHandler()->ProcessEvent(event);
3137}
3138
1e6feb95 3139bool wxWindowMSW::HandleSetFocus(WXHWND hwnd)
42e69d6b 3140{
456bc6d9
VZ
3141 // notify the parent keeping track of focus for the kbd navigation
3142 // purposes that we got it
e72aa7f5 3143 wxChildFocusEvent eventFocus((wxWindow *)this);
456bc6d9
VZ
3144 (void)GetEventHandler()->ProcessEvent(eventFocus);
3145
789295bf 3146#if wxUSE_CARET
42e69d6b 3147 // Deal with caret
789295bf 3148 if ( m_caret )
2d0a075d 3149 {
789295bf 3150 m_caret->OnSetFocus();
2bda0e17 3151 }
789295bf 3152#endif // wxUSE_CARET
42e69d6b 3153
ab93a576
RD
3154#if wxUSE_TEXTCTRL
3155 // If it's a wxTextCtrl don't send the event as it will be done
456bc6d9
VZ
3156 // after the control gets to process it from EN_FOCUS handler
3157 if ( wxDynamicCastThis(wxTextCtrl) )
ab93a576
RD
3158 {
3159 return FALSE;
3160 }
456bc6d9 3161#endif // wxUSE_TEXTCTRL
ab93a576 3162
42e69d6b
VZ
3163 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
3164 event.SetEventObject(this);
3165
1e6feb95
VZ
3166 // wxFindWinFromHandle() may return NULL, it is ok
3167 event.SetWindow(wxFindWinFromHandle(hwnd));
3168
42e69d6b 3169 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3170}
3171
1e6feb95 3172bool wxWindowMSW::HandleKillFocus(WXHWND hwnd)
2bda0e17 3173{
789295bf 3174#if wxUSE_CARET
42e69d6b 3175 // Deal with caret
789295bf 3176 if ( m_caret )
2d0a075d 3177 {
789295bf 3178 m_caret->OnKillFocus();
2bda0e17 3179 }
789295bf 3180#endif // wxUSE_CARET
42e69d6b 3181
ab93a576
RD
3182#if wxUSE_TEXTCTRL
3183 // If it's a wxTextCtrl don't send the event as it will be done
3184 // after the control gets to process it.
3185 wxTextCtrl *ctrl = wxDynamicCastThis(wxTextCtrl);
3186 if ( ctrl )
3187 {
3188 return FALSE;
3189 }
3190#endif
3191
2913e597
RD
3192 // Don't send the event when in the process of being deleted. This can
3193 // only cause problems if the event handler tries to access the object.
3194 if ( m_isBeingDeleted )
3195 {
3196 return FALSE;
3197 }
3198
42e69d6b
VZ
3199 wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId);
3200 event.SetEventObject(this);
3201
1e6feb95
VZ
3202 // wxFindWinFromHandle() may return NULL, it is ok
3203 event.SetWindow(wxFindWinFromHandle(hwnd));
3204
42e69d6b 3205 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3206}
3207
42e69d6b
VZ
3208// ---------------------------------------------------------------------------
3209// miscellaneous
3210// ---------------------------------------------------------------------------
3211
1e6feb95 3212bool wxWindowMSW::HandleShow(bool show, int WXUNUSED(status))
2bda0e17 3213{
42e69d6b
VZ
3214 wxShowEvent event(GetId(), show);
3215 event.m_eventObject = this;
3216
3217 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3218}
3219
1e6feb95 3220bool wxWindowMSW::HandleInitDialog(WXHWND WXUNUSED(hWndFocus))
2bda0e17 3221{
42e69d6b
VZ
3222 wxInitDialogEvent event(GetId());
3223 event.m_eventObject = this;
3224
3225 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3226}
3227
1e6feb95 3228bool wxWindowMSW::HandleDropFiles(WXWPARAM wParam)
2bda0e17 3229{
05d3cd45 3230#if defined (__WXMICROWIN__)
4ce1efe1
CE
3231 return FALSE;
3232#else // __WXMICROWIN__
42e69d6b 3233 HDROP hFilesInfo = (HDROP) wParam;
42e69d6b
VZ
3234
3235 // Get the total number of files dropped
c3c39620 3236 UINT gwFilesDropped = ::DragQueryFile
f6bcfd97
BP
3237 (
3238 (HDROP)hFilesInfo,
3239 (UINT)-1,
3240 (LPTSTR)0,
3241 (UINT)0
3242 );
42e69d6b
VZ
3243
3244 wxString *files = new wxString[gwFilesDropped];
c3c39620 3245 for ( UINT wIndex = 0; wIndex < gwFilesDropped; wIndex++ )
2d0a075d 3246 {
c3c39620
VZ
3247 // first get the needed buffer length (+1 for terminating NUL)
3248 size_t len = ::DragQueryFile(hFilesInfo, wIndex, NULL, 0) + 1;
3249
3250 // and now get the file name
3251 ::DragQueryFile(hFilesInfo, wIndex,
3252 files[wIndex].GetWriteBuf(len), len);
3253
3254 files[wIndex].UngetWriteBuf();
2d0a075d 3255 }
42e69d6b 3256 DragFinish (hFilesInfo);
2bda0e17 3257
42e69d6b
VZ
3258 wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files);
3259 event.m_eventObject = this;
c3c39620
VZ
3260
3261 POINT dropPoint;
3262 DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
b3dc8a3e
VZ
3263 event.m_pos.x = dropPoint.x;
3264 event.m_pos.y = dropPoint.y;
42e69d6b 3265
c3c39620 3266 return GetEventHandler()->ProcessEvent(event);
04ef50df 3267#endif
2bda0e17
KB
3268}
3269
cc972ac6
CE
3270#ifdef __DIGITALMARS__
3271extern "C" HCURSOR wxGetCurrentBusyCursor();
3272#endif
3273
1e6feb95
VZ
3274bool wxWindowMSW::HandleSetCursor(WXHWND WXUNUSED(hWnd),
3275 short nHitTest,
3276 int WXUNUSED(mouseMsg))
2bda0e17 3277{
04ef50df 3278#ifndef __WXMICROWIN__
bfbd6dc1 3279 // the logic is as follows:
43b5058d
VZ
3280 // -1. don't set cursor for non client area, including but not limited to
3281 // the title bar, scrollbars, &c
3282 // 0. allow the user to override default behaviour by using EVT_SET_CURSOR
bfbd6dc1
VZ
3283 // 1. if we have the cursor set it unless wxIsBusy()
3284 // 2. if we're a top level window, set some cursor anyhow
3285 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
42e69d6b 3286
43b5058d
VZ
3287 if ( nHitTest != HTCLIENT )
3288 {
3289 return FALSE;
3290 }
3291
bfbd6dc1 3292 HCURSOR hcursor = 0;
43b5058d
VZ
3293
3294 // first ask the user code - it may wish to set the cursor in some very
3295 // specific way (for example, depending on the current position)
3296 POINT pt;
669f7a11 3297#ifdef __WIN32__
43b5058d
VZ
3298 if ( !::GetCursorPos(&pt) )
3299 {
f6bcfd97 3300 wxLogLastError(wxT("GetCursorPos"));
43b5058d 3301 }
669f7a11
JS
3302#else
3303 // In WIN16 it doesn't return a value.
3304 ::GetCursorPos(&pt);
3305#endif
43b5058d
VZ
3306
3307 int x = pt.x,
3308 y = pt.y;
3309 ScreenToClient(&x, &y);
3310 wxSetCursorEvent event(x, y);
3311
3312 bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event);
3313 if ( processedEvtSetCursor && event.HasCursor() )
bfbd6dc1 3314 {
43b5058d 3315 hcursor = GetHcursorOf(event.GetCursor());
bfbd6dc1 3316 }
42e69d6b 3317
43b5058d 3318 if ( !hcursor )
bfbd6dc1 3319 {
43b5058d
VZ
3320 bool isBusy = wxIsBusy();
3321
3322 // the test for processedEvtSetCursor is here to prevent using m_cursor
3323 // if the user code caught EVT_SET_CURSOR() and returned nothing from
3324 // it - this is a way to say that our cursor shouldn't be used for this
3325 // point
3326 if ( !processedEvtSetCursor && m_cursor.Ok() )
bfbd6dc1 3327 {
43b5058d 3328 hcursor = GetHcursorOf(m_cursor);
bfbd6dc1 3329 }
43b5058d
VZ
3330
3331 if ( !GetParent() )
bfbd6dc1 3332 {
43b5058d 3333 if ( isBusy )
42e69d6b 3334 {
43b5058d
VZ
3335 hcursor = wxGetCurrentBusyCursor();
3336 }
3337 else if ( !hcursor )
3338 {
3339 const wxCursor *cursor = wxGetGlobalCursor();
3340 if ( cursor && cursor->Ok() )
3341 {
3342 hcursor = GetHcursorOf(*cursor);
3343 }
42e69d6b
VZ
3344 }
3345 }
3346 }
3347
bfbd6dc1
VZ
3348 if ( hcursor )
3349 {
2b5f62a0
VZ
3350// wxLogDebug("HandleSetCursor: Setting cursor %ld", (long) hcursor);
3351
bfbd6dc1
VZ
3352 ::SetCursor(hcursor);
3353
3354 // cursor set, stop here
3355 return TRUE;
3356 }
cd4453e5
VZ
3357#endif // __WXMICROWIN__
3358
3ca6a5f0
BP
3359 // pass up the window chain
3360 return FALSE;
2bda0e17
KB
3361}
3362
42e69d6b
VZ
3363// ---------------------------------------------------------------------------
3364// owner drawn stuff
3365// ---------------------------------------------------------------------------
3366
1e6feb95 3367bool wxWindowMSW::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
2bda0e17 3368{
4286a5b5 3369#if wxUSE_OWNER_DRAWN
1e6feb95
VZ
3370
3371#if wxUSE_MENUS_NATIVE
42e69d6b 3372 // is it a menu item?
6f806543
VZ
3373 DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
3374 if ( id == 0 && pDrawStruct->CtlType == ODT_MENU )
42e69d6b 3375 {
42e69d6b
VZ
3376 wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData);
3377
3378 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
3379
7561aacd
VZ
3380 // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
3381 // the DC from being released
3382 wxDCTemp dc((WXHDC)pDrawStruct->hDC);
42e69d6b
VZ
3383 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
3384 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
3385 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
3386
3387 return pMenuItem->OnDrawItem
7561aacd
VZ
3388 (
3389 dc,
3390 rect,
3391 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
3392 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
3393 );
42e69d6b 3394 }
1e6feb95 3395#endif // wxUSE_MENUS_NATIVE
42e69d6b 3396
1e6feb95 3397#if wxUSE_CONTROLS
42e69d6b
VZ
3398 wxWindow *item = FindItem(id);
3399 if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
3400 {
3401 return ((wxControl *)item)->MSWOnDraw(itemStruct);
3402 }
1e6feb95
VZ
3403#endif // wxUSE_CONTROLS
3404
cd0b1709 3405#endif // USE_OWNER_DRAWN
4286a5b5 3406
cd0b1709 3407 return FALSE;
2bda0e17
KB
3408}
3409
1e6feb95 3410bool wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
2bda0e17 3411{
4286a5b5 3412#if wxUSE_OWNER_DRAWN
42e69d6b 3413 // is it a menu item?
6f806543
VZ
3414 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
3415 if ( id == 0 && pMeasureStruct->CtlType == ODT_MENU )
2d0a075d 3416 {
42e69d6b
VZ
3417 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
3418
3419 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
3420
3421 return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth,
3422 &pMeasureStruct->itemHeight);
2d0a075d 3423 }
42e69d6b
VZ
3424
3425 wxWindow *item = FindItem(id);
3426 if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
3427 {
3428 return ((wxControl *)item)->MSWOnMeasure(itemStruct);
3429 }
4286a5b5 3430#endif // owner-drawn menus
42e69d6b 3431 return FALSE;
2bda0e17
KB
3432}
3433
42e69d6b
VZ
3434// ---------------------------------------------------------------------------
3435// colours and palettes
3436// ---------------------------------------------------------------------------
2bda0e17 3437
1e6feb95 3438bool wxWindowMSW::HandleSysColorChange()
2bda0e17 3439{
42e69d6b
VZ
3440 wxSysColourChangedEvent event;
3441 event.SetEventObject(this);
3442
23895080
VZ
3443 (void)GetEventHandler()->ProcessEvent(event);
3444
3445 // always let the system carry on the default processing to allow the
3446 // native controls to react to the colours update
3447 return FALSE;
42e69d6b
VZ
3448}
3449
574c939e
KB
3450bool wxWindowMSW::HandleDisplayChange()
3451{
3452 wxDisplayChangedEvent event;
3453 event.SetEventObject(this);
3454
3455 return GetEventHandler()->ProcessEvent(event);
3456}
3457
1e6feb95 3458bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush,
42e69d6b
VZ
3459 WXHDC pDC,
3460 WXHWND pWnd,
3461 WXUINT nCtlColor,
3462 WXUINT message,
3463 WXWPARAM wParam,
3464 WXLPARAM lParam)
3465{
04ef50df 3466#ifndef __WXMICROWIN__
42e69d6b
VZ
3467 WXHBRUSH hBrush = 0;
3468
3469 if ( nCtlColor == CTLCOLOR_DLG )
2d0a075d 3470 {
42e69d6b 3471 hBrush = OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2d0a075d 3472 }
1e6feb95 3473#if wxUSE_CONTROLS
2d0a075d
JS
3474 else
3475 {
42e69d6b
VZ
3476 wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE);
3477 if ( item )
3478 hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2d0a075d 3479 }
1e6feb95 3480#endif // wxUSE_CONTROLS
42e69d6b
VZ
3481
3482 if ( hBrush )
3483 *brush = hBrush;
3484
3485 return hBrush != 0;
cd4453e5 3486#else // __WXMICROWIN__
04ef50df
JS
3487 return FALSE;
3488#endif
2bda0e17
KB
3489}
3490
42e69d6b 3491// Define for each class of dialog and control
1e6feb95
VZ
3492WXHBRUSH wxWindowMSW::OnCtlColor(WXHDC WXUNUSED(hDC),
3493 WXHWND WXUNUSED(hWnd),
3494 WXUINT WXUNUSED(nCtlColor),
3495 WXUINT WXUNUSED(message),
3496 WXWPARAM WXUNUSED(wParam),
3497 WXLPARAM WXUNUSED(lParam))
2bda0e17 3498{
42e69d6b
VZ
3499 return (WXHBRUSH)0;
3500}
2d0a075d 3501
1e6feb95 3502bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange)
42e69d6b 3503{
574c939e 3504#if wxUSE_PALETTE
b95edd47
VZ
3505 // same as below except we don't respond to our own messages
3506 if ( hWndPalChange != GetHWND() )
3507 {
574c939e 3508 // check to see if we our our parents have a custom palette
fa21d338 3509 wxWindowMSW *win = this;
b95edd47
VZ
3510 while ( win && !win->HasCustomPalette() )
3511 {
3512 win = win->GetParent();
3513 }
3514
3515 if ( win && win->HasCustomPalette() )
3516 {
3517 // realize the palette to see whether redrawing is needed
3518 HDC hdc = ::GetDC((HWND) hWndPalChange);
3519 win->m_palette.SetHPALETTE((WXHPALETTE)
3520 ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
574c939e
KB
3521
3522 int result = ::RealizePalette(hdc);
b95edd47
VZ
3523
3524 // restore the palette (before releasing the DC)
3525 win->m_palette.SetHPALETTE((WXHPALETTE)
3526 ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
3527 ::RealizePalette(hdc);
3528 ::ReleaseDC((HWND) hWndPalChange, hdc);
3529
3530 // now check for the need to redraw
574c939e
KB
3531 if (result > 0)
3532 InvalidateRect((HWND) hWndPalChange, NULL, TRUE);
574c939e 3533 }
b95edd47
VZ
3534
3535 }
3536#endif // wxUSE_PALETTE
574c939e 3537
42e69d6b
VZ
3538 wxPaletteChangedEvent event(GetId());
3539 event.SetEventObject(this);
3540 event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
2d0a075d 3541
42e69d6b
VZ
3542 return GetEventHandler()->ProcessEvent(event);
3543}
3544
a5e84126
JS
3545bool wxWindowMSW::HandleCaptureChanged(WXHWND hWndGainedCapture)
3546{
3547 wxMouseCaptureChangedEvent event(GetId(), wxFindWinFromHandle(hWndGainedCapture));
3548 event.SetEventObject(this);
3549
3550 return GetEventHandler()->ProcessEvent(event);
3551}
3552
1e6feb95 3553bool wxWindowMSW::HandleQueryNewPalette()
42e69d6b 3554{
574c939e
KB
3555
3556#if wxUSE_PALETTE
3557 // check to see if we our our parents have a custom palette
fa21d338 3558 wxWindowMSW *win = this;
574c939e
KB
3559 while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent();
3560 if (win->HasCustomPalette()) {
3561 /* realize the palette to see whether redrawing is needed */
3562 HDC hdc = GetDC((HWND) GetHWND());
3563 win->m_palette.SetHPALETTE( (WXHPALETTE)
b95edd47 3564 ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), FALSE) );
574c939e
KB
3565
3566 int result = ::RealizePalette(hdc);
3567 /* restore the palette (before releasing the DC) */
3568 win->m_palette.SetHPALETTE( (WXHPALETTE)
b95edd47 3569 ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), TRUE) );
574c939e
KB
3570 ::RealizePalette(hdc);
3571 ::ReleaseDC((HWND) GetHWND(), hdc);
3572 /* now check for the need to redraw */
3573 if (result > 0)
3574 ::InvalidateRect((HWND) GetHWND(), NULL, TRUE);
3575 }
b95edd47 3576#endif // wxUSE_PALETTE
574c939e 3577
42e69d6b
VZ
3578 wxQueryNewPaletteEvent event(GetId());
3579 event.SetEventObject(this);
3580
3581 return GetEventHandler()->ProcessEvent(event) && event.GetPaletteRealized();
3582}
3583
3584// Responds to colour changes: passes event on to children.
574c939e 3585void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
42e69d6b 3586{
90c1530a
VZ
3587 // the top level window also reset the standard colour map as it might have
3588 // changed (there is no need to do it for the non top level windows as we
3589 // only have to do it once)
3590 if ( IsTopLevel() )
3591 {
3592 // FIXME-MT
3593 gs_hasStdCmap = FALSE;
3594 }
23895080 3595 wxWindowList::Node *node = GetChildren().GetFirst();
42e69d6b
VZ
3596 while ( node )
3597 {
23895080
VZ
3598 // Only propagate to non-top-level windows because Windows already
3599 // sends this event to all top-level ones
3600 wxWindow *win = node->GetData();
3601 if ( !win->IsTopLevel() )
42e69d6b 3602 {
23895080
VZ
3603 // we need to send the real WM_SYSCOLORCHANGE and not just trigger
3604 // EVT_SYS_COLOUR_CHANGED call because the latter wouldn't work for
3605 // the standard controls
3606 ::SendMessage(GetHwndOf(win), WM_SYSCOLORCHANGE, 0, 0);
564b2609 3607 }
42e69d6b 3608
23895080
VZ
3609 node = node->GetNext();
3610 }
3611
3612 // update the colours we use if they were not set explicitly by the user:
3613 // this must be done or OnCtlColor() would continue to use the old colours
3614 if ( !m_hasFgCol )
3615 {
3616 m_foregroundColour = wxSystemSettings::
3617 GetSystemColour(wxSYS_COLOUR_WINDOWTEXT);
3618 }
3619
3620 if ( !m_hasBgCol )
3621 {
3622 m_backgroundColour = wxSystemSettings::
3623 GetSystemColour(wxSYS_COLOUR_BTNFACE);
2bda0e17 3624 }
2bda0e17
KB
3625}
3626
90c1530a
VZ
3627extern wxCOLORMAP *wxGetStdColourMap()
3628{
3629 static COLORREF s_stdColours[wxSTD_COL_MAX];
3630 static wxCOLORMAP s_cmap[wxSTD_COL_MAX];
3631
3632 if ( !gs_hasStdCmap )
3633 {
3634 static bool s_coloursInit = FALSE;
3635
3636 if ( !s_coloursInit )
3637 {
3638 // When a bitmap is loaded, the RGB values can change (apparently
3639 // because Windows adjusts them to care for the old programs always
3640 // using 0xc0c0c0 while the transparent colour for the new Windows
3641 // versions is different). But we do this adjustment ourselves so
3642 // we want to avoid Windows' "help" and for this we need to have a
3643 // reference bitmap which can tell us what the RGB values change
3644 // to.
3645 wxBitmap stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
3646 if ( stdColourBitmap.Ok() )
3647 {
3648 // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
3649 wxASSERT_MSG( stdColourBitmap.GetWidth() == wxSTD_COL_MAX,
3650 _T("forgot to update wxBITMAP_STD_COLOURS!") );
3651
3652 wxMemoryDC memDC;
3653 memDC.SelectObject(stdColourBitmap);
3654
3655 wxColour colour;
3656 for ( size_t i = 0; i < WXSIZEOF(s_stdColours); i++ )
3657 {
3658 memDC.GetPixel(i, 0, &colour);
3659 s_stdColours[i] = wxColourToRGB(colour);
3660 }
3661 }
3662 else // wxBITMAP_STD_COLOURS couldn't be loaded
3663 {
3664 s_stdColours[0] = RGB(000,000,000); // black
3665 s_stdColours[1] = RGB(128,128,128); // dark grey
3666 s_stdColours[2] = RGB(192,192,192); // light grey
3667 s_stdColours[3] = RGB(255,255,255); // white
3668 //s_stdColours[4] = RGB(000,000,255); // blue
3669 //s_stdColours[5] = RGB(255,000,255); // magenta
3670 }
3671
3672 s_coloursInit = TRUE;
3673 }
3674
3675 gs_hasStdCmap = TRUE;
3676
3677 // create the colour map
3678#define INIT_CMAP_ENTRY(col) \
3679 s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
3680 s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
3681
3682 INIT_CMAP_ENTRY(BTNTEXT);
3683 INIT_CMAP_ENTRY(BTNSHADOW);
3684 INIT_CMAP_ENTRY(BTNFACE);
3685 INIT_CMAP_ENTRY(BTNHIGHLIGHT);
3686
3687#undef INIT_CMAP_ENTRY
3688 }
3689
3690 return s_cmap;
3691}
3692
42e69d6b
VZ
3693// ---------------------------------------------------------------------------
3694// painting
3695// ---------------------------------------------------------------------------
3696
1e6feb95 3697bool wxWindowMSW::HandlePaint()
2bda0e17 3698{
42e69d6b
VZ
3699#ifdef __WIN32__
3700 HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
3701 if ( !hRegion )
f6bcfd97 3702 wxLogLastError(wxT("CreateRectRgn"));
42e69d6b 3703 if ( ::GetUpdateRgn(GetHwnd(), hRegion, FALSE) == ERROR )
f6bcfd97 3704 wxLogLastError(wxT("GetUpdateRgn"));
c085e333 3705
42e69d6b 3706 m_updateRegion = wxRegion((WXHRGN) hRegion);
1e6feb95 3707#else // Win16
42e69d6b 3708 RECT updateRect;
1e6feb95 3709 ::GetUpdateRect(GetHwnd(), &updateRect, FALSE);
c085e333 3710
42e69d6b
VZ
3711 m_updateRegion = wxRegion(updateRect.left, updateRect.top,
3712 updateRect.right - updateRect.left,
3713 updateRect.bottom - updateRect.top);
1e6feb95 3714#endif // Win32/16
c085e333 3715
42e69d6b
VZ
3716 wxPaintEvent event(m_windowId);
3717 event.SetEventObject(this);
2bda0e17 3718
1e6feb95
VZ
3719 bool processed = GetEventHandler()->ProcessEvent(event);
3720
3721 // note that we must generate NC event after the normal one as otherwise
3722 // BeginPaint() will happily overwrite our decorations with the background
3723 // colour
3724 wxNcPaintEvent eventNc(m_windowId);
3725 eventNc.SetEventObject(this);
3726 GetEventHandler()->ProcessEvent(eventNc);
3727
3728 return processed;
2bda0e17
KB
3729}
3730
63da7df7 3731// Can be called from an application's OnPaint handler
1e6feb95 3732void wxWindowMSW::OnPaint(wxPaintEvent& event)
63da7df7 3733{
1e6feb95
VZ
3734#ifdef __WXUNIVERSAL__
3735 event.Skip();
3736#else
63da7df7
JS
3737 HDC hDC = (HDC) wxPaintDC::FindDCInCache((wxWindow*) event.GetEventObject());
3738 if (hDC != 0)
3739 {
3740 MSWDefWindowProc(WM_PAINT, (WPARAM) hDC, 0);
3741 }
1e6feb95 3742#endif
63da7df7
JS
3743}
3744
1e6feb95 3745bool wxWindowMSW::HandleEraseBkgnd(WXHDC hdc)
a23fd0e1 3746{
42e69d6b
VZ
3747 // Prevents flicker when dragging
3748 if ( ::IsIconic(GetHwnd()) )
3749 return TRUE;
a23fd0e1 3750
7561aacd 3751 wxDCTemp dc(hdc);
c085e333 3752
1e6feb95
VZ
3753 dc.SetHDC(hdc);
3754 dc.SetWindow((wxWindow *)this);
564b2609 3755 dc.BeginDrawing();
c085e333 3756
2bda0e17 3757 wxEraseEvent event(m_windowId, &dc);
42e69d6b 3758 event.SetEventObject(this);
a23fd0e1 3759 bool rc = GetEventHandler()->ProcessEvent(event);
c085e333 3760
a23fd0e1 3761 dc.EndDrawing();
7561aacd
VZ
3762
3763 // must be called manually as ~wxDC doesn't do anything for wxDCTemp
a23fd0e1 3764 dc.SelectOldObjects(hdc);
a23fd0e1
VZ
3765
3766 return rc;
2bda0e17
KB
3767}
3768
1e6feb95 3769void wxWindowMSW::OnEraseBackground(wxEraseEvent& event)
2bda0e17 3770{
2d0a075d 3771 RECT rect;
a23fd0e1 3772 ::GetClientRect(GetHwnd(), &rect);
2bda0e17 3773
42e69d6b
VZ
3774 COLORREF ref = PALETTERGB(m_backgroundColour.Red(),
3775 m_backgroundColour.Green(),
3776 m_backgroundColour.Blue());
ce3ed50d 3777 HBRUSH hBrush = ::CreateSolidBrush(ref);
42e69d6b 3778 if ( !hBrush )
f6bcfd97 3779 wxLogLastError(wxT("CreateSolidBrush"));
42e69d6b
VZ
3780
3781 HDC hdc = (HDC)event.GetDC()->GetHDC();
2bda0e17 3782
42e69d6b
VZ
3783 int mode = ::SetMapMode(hdc, MM_TEXT);
3784
3785 ::FillRect(hdc, &rect, hBrush);
2d0a075d 3786 ::DeleteObject(hBrush);
42e69d6b
VZ
3787 ::SetMapMode(hdc, mode);
3788}
3789
3790// ---------------------------------------------------------------------------
3791// moving and resizing
3792// ---------------------------------------------------------------------------
3793
1e6feb95 3794bool wxWindowMSW::HandleMinimize()
42e69d6b
VZ
3795{
3796 wxIconizeEvent event(m_windowId);
3797 event.SetEventObject(this);
2d0a075d 3798
42e69d6b 3799 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3800}
3801
1e6feb95 3802bool wxWindowMSW::HandleMaximize()
2bda0e17 3803{
42e69d6b
VZ
3804 wxMaximizeEvent event(m_windowId);
3805 event.SetEventObject(this);
c085e333 3806
42e69d6b
VZ
3807 return GetEventHandler()->ProcessEvent(event);
3808}
2bda0e17 3809
1e6feb95 3810bool wxWindowMSW::HandleMove(int x, int y)
42e69d6b
VZ
3811{
3812 wxMoveEvent event(wxPoint(x, y), m_windowId);
3813 event.SetEventObject(this);
3814
3815 return GetEventHandler()->ProcessEvent(event);
3816}
3817
4e4a5fed
VZ
3818bool wxWindowMSW::HandleSize(int WXUNUSED(w), int WXUNUSED(h),
3819 WXUINT WXUNUSED(flag))
42e69d6b 3820{
4e4a5fed
VZ
3821 // don't use w and h parameters as they specify the client size while
3822 // according to the docs EVT_SIZE handler is supposed to receive the total
3823 // size
3824 wxSizeEvent event(GetSize(), m_windowId);
42e69d6b
VZ
3825 event.SetEventObject(this);
3826
3827 return GetEventHandler()->ProcessEvent(event);
3828}
3829
1e6feb95 3830bool wxWindowMSW::HandleGetMinMaxInfo(void *mmInfo)
42e69d6b
VZ
3831{
3832 MINMAXINFO *info = (MINMAXINFO *)mmInfo;
3833
3834 bool rc = FALSE;
b2d5a7ee 3835
e7dda1ff
VS
3836 int minWidth = GetMinWidth(),
3837 minHeight = GetMinHeight(),
3838 maxWidth = GetMaxWidth(),
3839 maxHeight = GetMaxHeight();
42e69d6b 3840
e7dda1ff 3841 if ( minWidth != -1 )
2d0a075d 3842 {
e7dda1ff 3843 info->ptMinTrackSize.x = minWidth;
42e69d6b 3844 rc = TRUE;
2d0a075d 3845 }
2bda0e17 3846
e7dda1ff 3847 if ( minHeight != -1 )
42e69d6b 3848 {
e7dda1ff 3849 info->ptMinTrackSize.y = minHeight;
42e69d6b
VZ
3850 rc = TRUE;
3851 }
2bda0e17 3852
e7dda1ff 3853 if ( maxWidth != -1 )
42e69d6b 3854 {
e7dda1ff 3855 info->ptMaxTrackSize.x = maxWidth;
42e69d6b 3856 rc = TRUE;
2d0a075d 3857 }
2bda0e17 3858
e7dda1ff 3859 if ( maxHeight != -1 )
42e69d6b 3860 {
e7dda1ff 3861 info->ptMaxTrackSize.y = maxHeight;
42e69d6b
VZ
3862 rc = TRUE;
3863 }
2bda0e17 3864
42e69d6b
VZ
3865 return rc;
3866}
2d0a075d 3867
42e69d6b
VZ
3868// ---------------------------------------------------------------------------
3869// command messages
3870// ---------------------------------------------------------------------------
3871
1e6feb95 3872bool wxWindowMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
42e69d6b 3873{
1e6feb95 3874#if wxUSE_MENUS_NATIVE
8c290175 3875 if ( !cmd && wxCurrentPopupMenu )
42e69d6b
VZ
3876 {
3877 wxMenu *popupMenu = wxCurrentPopupMenu;
3878 wxCurrentPopupMenu = NULL;
3879
3880 return popupMenu->MSWCommand(cmd, id);
3881 }
1e6feb95 3882#endif // wxUSE_MENUS_NATIVE
42e69d6b 3883
8c290175 3884 wxWindow *win = NULL;
71292fab
VZ
3885
3886 // first try to find it from HWND - this works even with the broken
3887 // programs using the same ids for different controls
3888 if ( control )
42e69d6b 3889 {
71292fab 3890 win = wxFindWinFromHandle(control);
b853f898 3891 }
2f4ef631 3892
71292fab
VZ
3893 // try the id
3894 if ( !win )
b853f898 3895 {
71292fab
VZ
3896 // must cast to a signed type before comparing with other ids!
3897 win = FindItem((signed short)id);
42e69d6b
VZ
3898 }
3899
3900 if ( win )
b94ae1ea 3901 {
42e69d6b 3902 return win->MSWCommand(cmd, id);
b94ae1ea
VZ
3903 }
3904
3905 // the messages sent from the in-place edit control used by the treectrl
3906 // for label editing have id == 0, but they should _not_ be treated as menu
3907 // messages (they are EN_XXX ones, in fact) so don't translate anything
3908 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
3909 if ( !control )
a84fc80b 3910 {
b94ae1ea
VZ
3911 // If no child window, it may be an accelerator, e.g. for a popup menu
3912 // command
a84fc80b
JS
3913
3914 wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED);
3915 event.SetEventObject(this);
3916 event.SetId(id);
3917 event.SetInt(id);
b94ae1ea
VZ
3918
3919 return GetEventHandler()->ProcessEvent(event);
a84fc80b 3920 }
24ce4c18 3921#if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
6fe19057
VZ
3922 else
3923 {
3924 // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
3925 // notifications to its parent which we want to reflect back to
3926 // wxSpinCtrl
3927 wxSpinCtrl *spin = wxSpinCtrl::GetSpinForTextCtrl(control);
3928 if ( spin && spin->ProcessTextCommand(cmd, id) )
3929 return TRUE;
3930 }
3931#endif // wxUSE_SPINCTRL
42e69d6b
VZ
3932
3933 return FALSE;
2bda0e17
KB
3934}
3935
1e6feb95 3936bool wxWindowMSW::HandleSysCommand(WXWPARAM wParam, WXLPARAM WXUNUSED(lParam))
2bda0e17 3937{
42e69d6b
VZ
3938 // 4 bits are reserved
3939 switch ( wParam & 0xFFFFFFF0 )
3940 {
3941 case SC_MAXIMIZE:
3942 return HandleMaximize();
2d0a075d 3943
42e69d6b
VZ
3944 case SC_MINIMIZE:
3945 return HandleMinimize();
2d0a075d 3946 }
2bda0e17 3947
42e69d6b
VZ
3948 return FALSE;
3949}
3950
3951// ---------------------------------------------------------------------------
3952// mouse events
3953// ---------------------------------------------------------------------------
3954
1e6feb95
VZ
3955void wxWindowMSW::InitMouseEvent(wxMouseEvent& event,
3956 int x, int y,
3957 WXUINT flags)
42e69d6b 3958{
1e6feb95
VZ
3959 // our client coords are not quite the same as Windows ones
3960 wxPoint pt = GetClientAreaOrigin();
3961 event.m_x = x - pt.x;
3962 event.m_y = y - pt.y;
3963
3964 event.m_shiftDown = (flags & MK_SHIFT) != 0;
3965 event.m_controlDown = (flags & MK_CONTROL) != 0;
3966 event.m_leftDown = (flags & MK_LBUTTON) != 0;
3967 event.m_middleDown = (flags & MK_MBUTTON) != 0;
3968 event.m_rightDown = (flags & MK_RBUTTON) != 0;
1fdf858b
JS
3969 // event.m_altDown = (::GetKeyState(VK_MENU) & 0x80000000) != 0;
3970 // Returns different negative values on WinME and WinNT,
3971 // so simply test for negative value.
3972 event.m_altDown = ::GetKeyState(VK_MENU) < 0;
1e6feb95 3973
42e69d6b
VZ
3974 event.SetTimestamp(s_currentMsg.time);
3975 event.m_eventObject = this;
fb35f0c7 3976 event.SetId(GetId());
42e69d6b
VZ
3977
3978#if wxUSE_MOUSEEVENT_HACK
3979 m_lastMouseX = x;
3980 m_lastMouseY = y;
3981 m_lastMouseEvent = event.GetEventType();
3982#endif // wxUSE_MOUSEEVENT_HACK
2bda0e17
KB
3983}
3984
dfafa702
VZ
3985// Windows doesn't send the mouse events to the static controls (which are
3986// transparent in the sense that their WM_NCHITTEST handler returns
3987// HTTRANSPARENT) at all but we want all controls to receive the mouse events
3988// and so we manually check if we don't have a child window under mouse and if
3989// we do, send the event to it instead of the window Windows had sent WM_XXX
3990// to.
3991//
3992// Notice that this is not done for the mouse move events because this could
3993// (would?) be too slow, but only for clicks which means that the static texts
3994// still don't get move, enter nor leave events.
abcbaea7 3995static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y) //TW:REQ:Univ
dfafa702
VZ
3996{
3997 wxCHECK_MSG( x && y, win, _T("NULL pointer in FindWindowForMouseEvent") );
3998
3999 // first try to find a non transparent child: this allows us to send events
4000 // to a static text which is inside a static box, for example
4001 POINT pt = { *x, *y };
4002 HWND hwnd = GetHwndOf(win),
4003 hwndUnderMouse;
4004
4005#ifdef __WIN32__
4006 hwndUnderMouse = ::ChildWindowFromPointEx
4007 (
4008 hwnd,
4009 pt,
4010 CWP_SKIPINVISIBLE |
4011 CWP_SKIPDISABLED |
4012 CWP_SKIPTRANSPARENT
4013 );
4014
4015 if ( !hwndUnderMouse || hwndUnderMouse == hwnd )
4016#endif // __WIN32__
4017 {
4018 // now try any child window at all
4019 hwndUnderMouse = ::ChildWindowFromPoint(hwnd, pt);
4020 }
4021
4022 // check that we have a child window which is susceptible to receive mouse
4023 // events: for this it must be shown and enabled
4024 if ( hwndUnderMouse &&
4025 hwndUnderMouse != hwnd &&
4026 ::IsWindowVisible(hwndUnderMouse) &&
4027 ::IsWindowEnabled(hwndUnderMouse) )
4028 {
4029 wxWindow *winUnderMouse = wxFindWinFromHandle((WXHWND)hwndUnderMouse);
4030 if ( winUnderMouse )
4031 {
4032 // translate the mouse coords to the other window coords
4033 win->ClientToScreen(x, y);
4034 winUnderMouse->ScreenToClient(x, y);
4035
4036 win = winUnderMouse;
4037 }
4038 }
4039
4040 return win;
4041}
4042
1e6feb95 4043bool wxWindowMSW::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags)
2bda0e17 4044{
42e69d6b
VZ
4045 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
4046 // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST
4047 // from the message id and take the value in the table to get wxWin event
4048 // id
4049 static const wxEventType eventsMouse[] =
4050 {
4051 wxEVT_MOTION,
4052 wxEVT_LEFT_DOWN,
4053 wxEVT_LEFT_UP,
4054 wxEVT_LEFT_DCLICK,
4055 wxEVT_RIGHT_DOWN,
4056 wxEVT_RIGHT_UP,
4057 wxEVT_RIGHT_DCLICK,
4058 wxEVT_MIDDLE_DOWN,
4059 wxEVT_MIDDLE_UP,
4060 wxEVT_MIDDLE_DCLICK
4061 };
2bda0e17 4062
42e69d6b
VZ
4063 wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]);
4064 InitMouseEvent(event, x, y, flags);
4065
4066 return GetEventHandler()->ProcessEvent(event);
4067}
4068
1e6feb95 4069bool wxWindowMSW::HandleMouseMove(int x, int y, WXUINT flags)
42e69d6b
VZ
4070{
4071 if ( !m_mouseInWindow )
2bda0e17 4072 {
1e6feb95
VZ
4073 // it would be wrong to assume that just because we get a mouse move
4074 // event that the mouse is inside the window: although this is usually
4075 // true, it is not if we had captured the mouse, so we need to check
4076 // the mouse coordinates here
4077 if ( !HasCapture() || IsMouseInWindow() )
4078 {
4079 // Generate an ENTER event
4080 m_mouseInWindow = TRUE;
42e69d6b 4081
1e6feb95
VZ
4082 wxMouseEvent event(wxEVT_ENTER_WINDOW);
4083 InitMouseEvent(event, x, y, flags);
42e69d6b 4084
1e6feb95
VZ
4085 (void)GetEventHandler()->ProcessEvent(event);
4086 }
42e69d6b
VZ
4087 }
4088
4089#if wxUSE_MOUSEEVENT_HACK
4090 // Window gets a click down message followed by a mouse move message even
4091 // if position isn't changed! We want to discard the trailing move event
4092 // if x and y are the same.
4093 if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN ||
4094 m_lastMouseEvent == wxEVT_LEFT_DOWN ||
4095 m_lastMouseEvent == wxEVT_MIDDLE_DOWN) &&
06b32ebe 4096 (m_lastMouseX == x && m_lastMouseY == y) )
42e69d6b
VZ
4097 {
4098 m_lastMouseEvent = wxEVT_MOTION;
4099
4100 return FALSE;
4101 }
4102#endif // wxUSE_MOUSEEVENT_HACK
4103
4104 return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags);
4105}
4106
d2c52078 4107
24ce4c18 4108bool wxWindowMSW::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam)
d2c52078
RD
4109{
4110#if wxUSE_MOUSEWHEEL
4111 wxMouseEvent event(wxEVT_MOUSEWHEEL);
4112 InitMouseEvent(event,
4113 GET_X_LPARAM(lParam),
4114 GET_Y_LPARAM(lParam),
4115 LOWORD(wParam));
d2c52078
RD
4116 event.m_wheelRotation = (short)HIWORD(wParam);
4117 event.m_wheelDelta = WHEEL_DELTA;
4118
0f7a546d
RD
4119#ifdef __WIN32__
4120 static int s_linesPerRotation = -1;
4121 if ( s_linesPerRotation == -1 )
4122 {
4123 if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
4124 &s_linesPerRotation, 0))
4125 {
4126 // this is not supposed to happen
4127 wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
4128
4129 // the default is 3, so use it if SystemParametersInfo() failed
4130 s_linesPerRotation = 3;
4131 }
4132 }
4133#else // Win16
4134 // no SystemParametersInfo() under Win16
4135 static const int s_linesPerRotation = 3;
4136#endif
d2c52078 4137
0f7a546d 4138 event.m_linesPerAction = s_linesPerRotation;
d2c52078 4139 return GetEventHandler()->ProcessEvent(event);
0f7a546d 4140
d2c52078 4141#else
38caaa61
KB
4142 (void) wParam;
4143 (void) lParam;
4144
d2c52078
RD
4145 return FALSE;
4146#endif
4147}
4148
4149
42e69d6b
VZ
4150// ---------------------------------------------------------------------------
4151// keyboard handling
4152// ---------------------------------------------------------------------------
4153
c42404a5
VZ
4154// create the key event of the given type for the given key - used by
4155// HandleChar and HandleKeyDown/Up
1e6feb95 4156wxKeyEvent wxWindowMSW::CreateKeyEvent(wxEventType evType,
b09bda68 4157 int id,
9c7df356
VZ
4158 WXLPARAM lParam,
4159 WXWPARAM wParam) const
c42404a5
VZ
4160{
4161 wxKeyEvent event(evType);
4162 event.SetId(GetId());
3f7bc32b
VZ
4163 event.m_shiftDown = wxIsShiftDown();
4164 event.m_controlDown = wxIsCtrlDown();
c42404a5
VZ
4165 event.m_altDown = (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN;
4166
4167 event.m_eventObject = (wxWindow *)this; // const_cast
4168 event.m_keyCode = id;
9c7df356
VZ
4169 event.m_rawCode = (wxUint32) wParam;
4170 event.m_rawFlags = (wxUint32) lParam;
c42404a5
VZ
4171 event.SetTimestamp(s_currentMsg.time);
4172
4173 // translate the position to client coords
4174 POINT pt;
4175 GetCursorPos(&pt);
4176 RECT rect;
4177 GetWindowRect(GetHwnd(),&rect);
4178 pt.x -= rect.left;
4179 pt.y -= rect.top;
4180
4181 event.m_x = pt.x;
4182 event.m_y = pt.y;
4183
4184 return event;
4185}
4186
42e69d6b
VZ
4187// isASCII is TRUE only when we're called from WM_CHAR handler and not from
4188// WM_KEYDOWN one
1e6feb95 4189bool wxWindowMSW::HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII)
42e69d6b 4190{
c42404a5
VZ
4191 bool ctrlDown = FALSE;
4192
42e69d6b 4193 int id;
42e69d6b
VZ
4194 if ( isASCII )
4195 {
ad9f1aec
RD
4196 // If 1 -> 26, translate to either special keycode or just set
4197 // ctrlDown. IOW, Ctrl-C should result in keycode == 3 and
4198 // ControlDown() == TRUE.
42e69d6b
VZ
4199 id = wParam;
4200 if ( (id > 0) && (id < 27) )
2d0a075d 4201 {
42e69d6b
VZ
4202 switch (id)
4203 {
c42404a5 4204 case 13:
42e69d6b
VZ
4205 id = WXK_RETURN;
4206 break;
c42404a5
VZ
4207
4208 case 8:
42e69d6b
VZ
4209 id = WXK_BACK;
4210 break;
c42404a5
VZ
4211
4212 case 9:
42e69d6b
VZ
4213 id = WXK_TAB;
4214 break;
c42404a5
VZ
4215
4216 default:
4217 ctrlDown = TRUE;
ad9f1aec 4218 break;
42e69d6b 4219 }
2d0a075d 4220 }
2d0a075d 4221 }
9c7df356 4222 else // we're called from WM_KEYDOWN
c42404a5 4223 {
9c7df356
VZ
4224 id = wxCharCodeMSWToWX(wParam);
4225 if ( id == 0 )
c42404a5 4226 {
9c7df356
VZ
4227 // it's ASCII and will be processed here only when called from
4228 // WM_CHAR (i.e. when isASCII = TRUE), don't process it now
4229 return FALSE;
c42404a5 4230 }
9c7df356 4231 }
42e69d6b 4232
9c7df356 4233 wxKeyEvent event(CreateKeyEvent(wxEVT_CHAR, id, lParam, wParam));
2b5f62a0
VZ
4234
4235 // the alphanumeric keys produced by pressing AltGr+something on European
4236 // keyboards have both Ctrl and Alt modifiers which may confuse the user
4237 // code as, normally, keys with Ctrl and/or Alt don't result in anything
4238 // alphanumeric, so pretend that there are no modifiers at all (the
4239 // KEY_DOWN event would still have the correct modifiers if they're really
4240 // needed)
4241 if ( event.m_controlDown && event.m_altDown &&
4242 (id >= 32 && id < 256) )
9c7df356 4243 {
2b5f62a0
VZ
4244 event.m_controlDown =
4245 event.m_altDown = FALSE;
2d0a075d 4246 }
c42404a5 4247
9c7df356 4248 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
4249}
4250
1e6feb95 4251bool wxWindowMSW::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 4252{
c42404a5 4253 int id = wxCharCodeMSWToWX(wParam);
2bda0e17 4254
c42404a5
VZ
4255 if ( !id )
4256 {
4257 // normal ASCII char
42e69d6b
VZ
4258 id = wParam;
4259 }
4260
c42404a5 4261 if ( id != -1 ) // VZ: does this ever happen (FIXME)?
2bda0e17 4262 {
9c7df356 4263 wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, id, lParam, wParam));
42e69d6b 4264 if ( GetEventHandler()->ProcessEvent(event) )
2d0a075d 4265 {
42e69d6b 4266 return TRUE;
2d0a075d 4267 }
42e69d6b 4268 }
c42404a5
VZ
4269
4270 return FALSE;
2bda0e17
KB
4271}
4272
1e6feb95 4273bool wxWindowMSW::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 4274{
c42404a5 4275 int id = wxCharCodeMSWToWX(wParam);
2bda0e17 4276
c42404a5
VZ
4277 if ( !id )
4278 {
4279 // normal ASCII char
42e69d6b 4280 id = wParam;
2d0a075d 4281 }
2bda0e17 4282
c42404a5 4283 if ( id != -1 ) // VZ: does this ever happen (FIXME)?
42e69d6b 4284 {
9c7df356 4285 wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_UP, id, lParam, wParam));
42e69d6b
VZ
4286 if ( GetEventHandler()->ProcessEvent(event) )
4287 return TRUE;
42e69d6b 4288 }
c42404a5
VZ
4289
4290 return FALSE;
2bda0e17
KB
4291}
4292
b74cce40
VZ
4293#ifdef __WIN32__
4294
4295int wxWindowMSW::HandleMenuChar(int chAccel, WXLPARAM lParam)
4296{
4297 const HMENU hmenu = (HMENU)lParam;
4298
4299 MENUITEMINFO mii;
4300 wxZeroMemory(mii);
4301 mii.cbSize = sizeof(MENUITEMINFO);
4302 mii.fMask = MIIM_TYPE | MIIM_DATA;
4303
4304 // find if we have this letter in any owner drawn item
4305 const int count = ::GetMenuItemCount(hmenu);
4306 for ( int i = 0; i < count; i++ )
4307 {
4308 if ( ::GetMenuItemInfo(hmenu, i, TRUE, &mii) )
4309 {
4310 if ( mii.fType == MFT_OWNERDRAW )
4311 {
4312 // dwItemData member of the MENUITEMINFO is a
4313 // pointer to the associated wxMenuItem -- see the
4314 // menu creation code
4315 wxMenuItem *item = (wxMenuItem*)mii.dwItemData;
4316
4317 const wxChar *p = wxStrchr(item->GetText(), _T('&'));
4318 while ( p++ )
4319 {
4320 if ( *p == _T('&') )
4321 {
4322 // this is not the accel char, find the real one
4323 p = wxStrchr(p + 1, _T('&'));
4324 }
4325 else // got the accel char
4326 {
4327 // FIXME-UNICODE: this comparison doesn't risk to work
4328 // for non ASCII accelerator characters I'm afraid, but
4329 // what can we do?
4330 if ( wxToupper(*p) == chAccel )
4331 {
4332 return i;
4333 }
4334 else
4335 {
4336 // this one doesn't match
4337 break;
4338 }
4339 }
4340 }
4341 }
4342 }
4343 else // failed ot get the menu text?
4344 {
4345 // it's not fatal, so don't show error, but still log
4346 // it
4347 wxLogLastError(_T("GetMenuItemInfo"));
4348 }
4349 }
4350
4351 return wxNOT_FOUND;
4352}
4353
4354#endif // __WIN32__
4355
42e69d6b
VZ
4356// ---------------------------------------------------------------------------
4357// joystick
4358// ---------------------------------------------------------------------------
4359
1e6feb95 4360bool wxWindowMSW::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
2bda0e17 4361{
8cb172b4 4362#ifdef JOY_BUTTON1
42e69d6b
VZ
4363 int change = 0;
4364 if ( flags & JOY_BUTTON1CHG )
4365 change = wxJOY_BUTTON1;
4366 if ( flags & JOY_BUTTON2CHG )
4367 change = wxJOY_BUTTON2;
4368 if ( flags & JOY_BUTTON3CHG )
4369 change = wxJOY_BUTTON3;
4370 if ( flags & JOY_BUTTON4CHG )
4371 change = wxJOY_BUTTON4;
2bda0e17 4372
42e69d6b
VZ
4373 int buttons = 0;
4374 if ( flags & JOY_BUTTON1 )
4375 buttons |= wxJOY_BUTTON1;
4376 if ( flags & JOY_BUTTON2 )
4377 buttons |= wxJOY_BUTTON2;
4378 if ( flags & JOY_BUTTON3 )
4379 buttons |= wxJOY_BUTTON3;
4380 if ( flags & JOY_BUTTON4 )
4381 buttons |= wxJOY_BUTTON4;
c085e333 4382
42e69d6b
VZ
4383 // the event ids aren't consecutive so we can't use table based lookup
4384 int joystick;
4385 wxEventType eventType;
4386 switch ( msg )
4387 {
4388 case MM_JOY1MOVE:
4389 joystick = 1;
4390 eventType = wxEVT_JOY_MOVE;
4391 break;
2bda0e17 4392
42e69d6b
VZ
4393 case MM_JOY2MOVE:
4394 joystick = 2;
4395 eventType = wxEVT_JOY_MOVE;
4396 break;
2bda0e17 4397
42e69d6b
VZ
4398 case MM_JOY1ZMOVE:
4399 joystick = 1;
4400 eventType = wxEVT_JOY_ZMOVE;
4401 break;
2bda0e17 4402
42e69d6b
VZ
4403 case MM_JOY2ZMOVE:
4404 joystick = 2;
4405 eventType = wxEVT_JOY_ZMOVE;
4406 break;
2bda0e17 4407
42e69d6b
VZ
4408 case MM_JOY1BUTTONDOWN:
4409 joystick = 1;
4410 eventType = wxEVT_JOY_BUTTON_DOWN;
4411 break;
2bda0e17 4412
42e69d6b
VZ
4413 case MM_JOY2BUTTONDOWN:
4414 joystick = 2;
4415 eventType = wxEVT_JOY_BUTTON_DOWN;
4416 break;
2bda0e17 4417
42e69d6b
VZ
4418 case MM_JOY1BUTTONUP:
4419 joystick = 1;
4420 eventType = wxEVT_JOY_BUTTON_UP;
4421 break;
4422
4423 case MM_JOY2BUTTONUP:
4424 joystick = 2;
4425 eventType = wxEVT_JOY_BUTTON_UP;
4426 break;
4427
4428 default:
223d09f6 4429 wxFAIL_MSG(wxT("no such joystick event"));
2d0a075d 4430
42e69d6b 4431 return FALSE;
2d0a075d 4432 }
2bda0e17 4433
42e69d6b
VZ
4434 wxJoystickEvent event(eventType, buttons, joystick, change);
4435 event.SetPosition(wxPoint(x, y));
4436 event.SetEventObject(this);
c085e333 4437
42e69d6b 4438 return GetEventHandler()->ProcessEvent(event);
8cb172b4
JS
4439#else
4440 return FALSE;
4441#endif
2bda0e17
KB
4442}
4443
42e69d6b
VZ
4444// ---------------------------------------------------------------------------
4445// scrolling
4446// ---------------------------------------------------------------------------
4447
1e6feb95 4448bool wxWindowMSW::MSWOnScroll(int orientation, WXWORD wParam,
f4f734c1 4449 WXWORD pos, WXHWND control)
2bda0e17 4450{
42e69d6b 4451 if ( control )
cc2b7472 4452 {
42e69d6b
VZ
4453 wxWindow *child = wxFindWinFromHandle(control);
4454 if ( child )
4455 return child->MSWOnScroll(orientation, wParam, pos, control);
cc2b7472 4456 }
2bda0e17 4457
9145664b 4458 wxScrollWinEvent event;
42e69d6b
VZ
4459 event.SetPosition(pos);
4460 event.SetOrientation(orientation);
4461 event.m_eventObject = this;
cc2b7472 4462
42e69d6b
VZ
4463 switch ( wParam )
4464 {
4465 case SB_TOP:
9145664b 4466 event.m_eventType = wxEVT_SCROLLWIN_TOP;
42e69d6b 4467 break;
cc2b7472 4468
42e69d6b 4469 case SB_BOTTOM:
9145664b 4470 event.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
42e69d6b 4471 break;
cc2b7472 4472
42e69d6b 4473 case SB_LINEUP:
9145664b 4474 event.m_eventType = wxEVT_SCROLLWIN_LINEUP;
42e69d6b 4475 break;
2bda0e17 4476
42e69d6b 4477 case SB_LINEDOWN:
9145664b 4478 event.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
42e69d6b 4479 break;
a02eb1d2 4480
42e69d6b 4481 case SB_PAGEUP:
9145664b 4482 event.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
42e69d6b 4483 break;
2bda0e17 4484
42e69d6b 4485 case SB_PAGEDOWN:
9145664b 4486 event.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
42e69d6b 4487 break;
2bda0e17 4488
42e69d6b 4489 case SB_THUMBPOSITION:
feda3011 4490 case SB_THUMBTRACK:
f6bcfd97
BP
4491#ifdef __WIN32__
4492 // under Win32, the scrollbar range and position are 32 bit integers,
4493 // but WM_[HV]SCROLL only carry the low 16 bits of them, so we must
4494 // explicitly query the scrollbar for the correct position (this must
4495 // be done only for these two SB_ events as they are the only one
4496 // carrying the scrollbar position)
4497 {
0cf5de11 4498 WinStruct<SCROLLINFO> scrollInfo;
f6bcfd97
BP
4499 scrollInfo.fMask = SIF_TRACKPOS;
4500
4501 if ( !::GetScrollInfo(GetHwnd(),
4502 orientation == wxHORIZONTAL ? SB_HORZ
4503 : SB_VERT,
4504 &scrollInfo) )
4505 {
4506 wxLogLastError(_T("GetScrollInfo"));
4507 }
4508
4509 event.SetPosition(scrollInfo.nTrackPos);
4510 }
4511#endif // Win32
4512
4513 event.m_eventType = wParam == SB_THUMBPOSITION
4514 ? wxEVT_SCROLLWIN_THUMBRELEASE
4515 : wxEVT_SCROLLWIN_THUMBTRACK;
42e69d6b 4516 break;
c085e333 4517
42e69d6b
VZ
4518 default:
4519 return FALSE;
564b2609 4520 }
2bda0e17 4521
42e69d6b 4522 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
4523}
4524
42e69d6b
VZ
4525// ===========================================================================
4526// global functions
4527// ===========================================================================
4528
f68586e5 4529void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont *the_font)
2bda0e17 4530{
42e69d6b
VZ
4531 TEXTMETRIC tm;
4532 HDC dc = ::GetDC((HWND) wnd);
4533 HFONT fnt =0;
4534 HFONT was = 0;
4535 if ( the_font )
2d0a075d 4536 {
42e69d6b
VZ
4537 // the_font->UseResource();
4538 // the_font->RealizeResource();
f68586e5 4539 fnt = (HFONT)((wxFont *)the_font)->GetResourceHandle(); // const_cast
42e69d6b
VZ
4540 if ( fnt )
4541 was = (HFONT) SelectObject(dc,fnt);
2d0a075d 4542 }
42e69d6b
VZ
4543 GetTextMetrics(dc, &tm);
4544 if ( the_font && fnt && was )
2d0a075d 4545 {
42e69d6b 4546 SelectObject(dc,was);
2d0a075d 4547 }
42e69d6b 4548 ReleaseDC((HWND)wnd, dc);
0655ad29
VZ
4549
4550 if ( x )
4551 *x = tm.tmAveCharWidth;
4552 if ( y )
4553 *y = tm.tmHeight + tm.tmExternalLeading;
2bda0e17 4554
42e69d6b
VZ
4555 // if ( the_font )
4556 // the_font->ReleaseResource();
4557}
c085e333 4558
42e69d6b
VZ
4559// Returns 0 if was a normal ASCII value, not a special key. This indicates that
4560// the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
4561int wxCharCodeMSWToWX(int keySym)
4562{
f6bcfd97 4563 int id;
42e69d6b
VZ
4564 switch (keySym)
4565 {
f6bcfd97
BP
4566 case VK_CANCEL: id = WXK_CANCEL; break;
4567 case VK_BACK: id = WXK_BACK; break;
4568 case VK_TAB: id = WXK_TAB; break;
4569 case VK_CLEAR: id = WXK_CLEAR; break;
4570 case VK_RETURN: id = WXK_RETURN; break;
4571 case VK_SHIFT: id = WXK_SHIFT; break;
4572 case VK_CONTROL: id = WXK_CONTROL; break;
4573 case VK_MENU : id = WXK_MENU; break;
4574 case VK_PAUSE: id = WXK_PAUSE; break;
9c7df356 4575 case VK_CAPITAL: id = WXK_CAPITAL; break;
f6bcfd97
BP
4576 case VK_SPACE: id = WXK_SPACE; break;
4577 case VK_ESCAPE: id = WXK_ESCAPE; break;
4578 case VK_PRIOR: id = WXK_PRIOR; break;
4579 case VK_NEXT : id = WXK_NEXT; break;
4580 case VK_END: id = WXK_END; break;
4581 case VK_HOME : id = WXK_HOME; break;
4582 case VK_LEFT : id = WXK_LEFT; break;
4583 case VK_UP: id = WXK_UP; break;
4584 case VK_RIGHT: id = WXK_RIGHT; break;
4585 case VK_DOWN : id = WXK_DOWN; break;
4586 case VK_SELECT: id = WXK_SELECT; break;
4587 case VK_PRINT: id = WXK_PRINT; break;
4588 case VK_EXECUTE: id = WXK_EXECUTE; break;
4589 case VK_INSERT: id = WXK_INSERT; break;
4590 case VK_DELETE: id = WXK_DELETE; break;
4591 case VK_HELP : id = WXK_HELP; break;
4592 case VK_NUMPAD0: id = WXK_NUMPAD0; break;
4593 case VK_NUMPAD1: id = WXK_NUMPAD1; break;
4594 case VK_NUMPAD2: id = WXK_NUMPAD2; break;
4595 case VK_NUMPAD3: id = WXK_NUMPAD3; break;
4596 case VK_NUMPAD4: id = WXK_NUMPAD4; break;
4597 case VK_NUMPAD5: id = WXK_NUMPAD5; break;
4598 case VK_NUMPAD6: id = WXK_NUMPAD6; break;
4599 case VK_NUMPAD7: id = WXK_NUMPAD7; break;
4600 case VK_NUMPAD8: id = WXK_NUMPAD8; break;
4601 case VK_NUMPAD9: id = WXK_NUMPAD9; break;
32a87ae7 4602 case VK_MULTIPLY: id = WXK_NUMPAD_MULTIPLY; break;
32a87ae7 4603 case VK_ADD: id = WXK_NUMPAD_ADD; break;
32a87ae7 4604 case VK_SUBTRACT: id = WXK_NUMPAD_SUBTRACT; break;
32a87ae7
VZ
4605 case VK_DECIMAL: id = WXK_NUMPAD_DECIMAL; break;
4606 case VK_DIVIDE: id = WXK_NUMPAD_DIVIDE; break;
f6bcfd97
BP
4607 case VK_F1: id = WXK_F1; break;
4608 case VK_F2: id = WXK_F2; break;
4609 case VK_F3: id = WXK_F3; break;
4610 case VK_F4: id = WXK_F4; break;
4611 case VK_F5: id = WXK_F5; break;
4612 case VK_F6: id = WXK_F6; break;
4613 case VK_F7: id = WXK_F7; break;
4614 case VK_F8: id = WXK_F8; break;
4615 case VK_F9: id = WXK_F9; break;
4616 case VK_F10: id = WXK_F10; break;
4617 case VK_F11: id = WXK_F11; break;
4618 case VK_F12: id = WXK_F12; break;
4619 case VK_F13: id = WXK_F13; break;
4620 case VK_F14: id = WXK_F14; break;
4621 case VK_F15: id = WXK_F15; break;
4622 case VK_F16: id = WXK_F16; break;
4623 case VK_F17: id = WXK_F17; break;
4624 case VK_F18: id = WXK_F18; break;
4625 case VK_F19: id = WXK_F19; break;
4626 case VK_F20: id = WXK_F20; break;
4627 case VK_F21: id = WXK_F21; break;
4628 case VK_F22: id = WXK_F22; break;
4629 case VK_F23: id = WXK_F23; break;
4630 case VK_F24: id = WXK_F24; break;
4631 case VK_NUMLOCK: id = WXK_NUMLOCK; break;
4632 case VK_SCROLL: id = WXK_SCROLL; break;
9c7df356
VZ
4633
4634 case VK_OEM_1: id = ';'; break;
4635 case VK_OEM_PLUS: id = '+'; break;
4636 case VK_OEM_COMMA: id = ','; break;
4637 case VK_OEM_MINUS: id = '-'; break;
4638 case VK_OEM_PERIOD: id = '.'; break;
4639 case VK_OEM_2: id = '/'; break;
4640 case VK_OEM_3: id = '~'; break;
4641 case VK_OEM_4: id = '['; break;
4642 case VK_OEM_5: id = '\\'; break;
4643 case VK_OEM_6: id = ']'; break;
4644 case VK_OEM_7: id = '\''; break;
4645
702c4208
VZ
4646#ifdef VK_APPS
4647 case VK_LWIN: id = WXK_WINDOWS_LEFT; break;
4648 case VK_RWIN: id = WXK_WINDOWS_RIGHT; break;
4649 case VK_APPS: id = WXK_WINDOWS_MENU; break;
4650#endif // VK_APPS defined
4651
f6bcfd97
BP
4652 default:
4653 id = 0;
42e69d6b 4654 }
f6bcfd97 4655
42e69d6b 4656 return id;
2bda0e17
KB
4657}
4658
42e69d6b 4659int wxCharCodeWXToMSW(int id, bool *isVirtual)
2bda0e17 4660{
42e69d6b
VZ
4661 *isVirtual = TRUE;
4662 int keySym = 0;
4663 switch (id)
2bda0e17 4664 {
42e69d6b
VZ
4665 case WXK_CANCEL: keySym = VK_CANCEL; break;
4666 case WXK_CLEAR: keySym = VK_CLEAR; break;
4667 case WXK_SHIFT: keySym = VK_SHIFT; break;
4668 case WXK_CONTROL: keySym = VK_CONTROL; break;
4669 case WXK_MENU : keySym = VK_MENU; break;
4670 case WXK_PAUSE: keySym = VK_PAUSE; break;
4671 case WXK_PRIOR: keySym = VK_PRIOR; break;
4672 case WXK_NEXT : keySym = VK_NEXT; break;
4673 case WXK_END: keySym = VK_END; break;
4674 case WXK_HOME : keySym = VK_HOME; break;
4675 case WXK_LEFT : keySym = VK_LEFT; break;
4676 case WXK_UP: keySym = VK_UP; break;
4677 case WXK_RIGHT: keySym = VK_RIGHT; break;
4678 case WXK_DOWN : keySym = VK_DOWN; break;
4679 case WXK_SELECT: keySym = VK_SELECT; break;
4680 case WXK_PRINT: keySym = VK_PRINT; break;
4681 case WXK_EXECUTE: keySym = VK_EXECUTE; break;
4682 case WXK_INSERT: keySym = VK_INSERT; break;
4683 case WXK_DELETE: keySym = VK_DELETE; break;
4684 case WXK_HELP : keySym = VK_HELP; break;
4685 case WXK_NUMPAD0: keySym = VK_NUMPAD0; break;
4686 case WXK_NUMPAD1: keySym = VK_NUMPAD1; break;
4687 case WXK_NUMPAD2: keySym = VK_NUMPAD2; break;
4688 case WXK_NUMPAD3: keySym = VK_NUMPAD3; break;
4689 case WXK_NUMPAD4: keySym = VK_NUMPAD4; break;
4690 case WXK_NUMPAD5: keySym = VK_NUMPAD5; break;
4691 case WXK_NUMPAD6: keySym = VK_NUMPAD6; break;
4692 case WXK_NUMPAD7: keySym = VK_NUMPAD7; break;
4693 case WXK_NUMPAD8: keySym = VK_NUMPAD8; break;
4694 case WXK_NUMPAD9: keySym = VK_NUMPAD9; break;
32a87ae7
VZ
4695 case WXK_NUMPAD_MULTIPLY: keySym = VK_MULTIPLY; break;
4696 case WXK_NUMPAD_ADD: keySym = VK_ADD; break;
4697 case WXK_NUMPAD_SUBTRACT: keySym = VK_SUBTRACT; break;
4698 case WXK_NUMPAD_DECIMAL: keySym = VK_DECIMAL; break;
4699 case WXK_NUMPAD_DIVIDE: keySym = VK_DIVIDE; break;
42e69d6b
VZ
4700 case WXK_F1: keySym = VK_F1; break;
4701 case WXK_F2: keySym = VK_F2; break;
4702 case WXK_F3: keySym = VK_F3; break;
4703 case WXK_F4: keySym = VK_F4; break;
4704 case WXK_F5: keySym = VK_F5; break;
4705 case WXK_F6: keySym = VK_F6; break;
4706 case WXK_F7: keySym = VK_F7; break;
4707 case WXK_F8: keySym = VK_F8; break;
4708 case WXK_F9: keySym = VK_F9; break;
4709 case WXK_F10: keySym = VK_F10; break;
4710 case WXK_F11: keySym = VK_F11; break;
4711 case WXK_F12: keySym = VK_F12; break;
4712 case WXK_F13: keySym = VK_F13; break;
4713 case WXK_F14: keySym = VK_F14; break;
4714 case WXK_F15: keySym = VK_F15; break;
4715 case WXK_F16: keySym = VK_F16; break;
4716 case WXK_F17: keySym = VK_F17; break;
4717 case WXK_F18: keySym = VK_F18; break;
4718 case WXK_F19: keySym = VK_F19; break;
4719 case WXK_F20: keySym = VK_F20; break;
4720 case WXK_F21: keySym = VK_F21; break;
4721 case WXK_F22: keySym = VK_F22; break;
4722 case WXK_F23: keySym = VK_F23; break;
4723 case WXK_F24: keySym = VK_F24; break;
4724 case WXK_NUMLOCK: keySym = VK_NUMLOCK; break;
4725 case WXK_SCROLL: keySym = VK_SCROLL; break;
4726 default:
4727 {
4728 *isVirtual = FALSE;
4729 keySym = id;
4730 break;
4731 }
2bda0e17 4732 }
42e69d6b 4733 return keySym;
2bda0e17
KB
4734}
4735
42e69d6b 4736wxWindow *wxGetActiveWindow()
2bda0e17 4737{
42e69d6b
VZ
4738 HWND hWnd = GetActiveWindow();
4739 if ( hWnd != 0 )
2d0a075d 4740 {
42e69d6b 4741 return wxFindWinFromHandle((WXHWND) hWnd);
2d0a075d 4742 }
42e69d6b 4743 return NULL;
2bda0e17
KB
4744}
4745
8614c467
VZ
4746extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
4747{
4748 HWND hwnd = (HWND)hWnd;
4749
4750 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
4751 // by code in msw/radiobox.cpp), for all the others we just search up the
4752 // window hierarchy
4753 wxWindow *win = (wxWindow *)NULL;
4754 if ( hwnd )
4755 {
4756 win = wxFindWinFromHandle((WXHWND)hwnd);
4757 if ( !win )
4758 {
a2242341 4759 // all these hacks only work under Win32 anyhow
4f527e71 4760#ifdef __WIN32__
a2242341
VZ
4761
4762#if wxUSE_RADIOBOX
8614c467
VZ
4763 // native radiobuttons return DLGC_RADIOBUTTON here and for any
4764 // wxWindow class which overrides WM_GETDLGCODE processing to
4765 // do it as well, win would be already non NULL
a2242341 4766 if ( ::SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_RADIOBUTTON )
8614c467
VZ
4767 {
4768 win = (wxWindow *)::GetWindowLong(hwnd, GWL_USERDATA);
4769 }
a2242341
VZ
4770 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
4771#endif // wxUSE_RADIOBOX
4772
4773 // spin control text buddy window should be mapped to spin ctrl
4774 // itself so try it too
24ce4c18 4775#if wxUSE_SPINCTRL && !defined(__WXUNIVERSAL__)
a2242341
VZ
4776 if ( !win )
4777 {
4778 win = wxSpinCtrl::GetSpinForTextCtrl((WXHWND)hwnd);
4779 }
4780#endif // wxUSE_SPINCTRL
4781
4f527e71 4782#endif // Win32
8614c467 4783 }
8614c467
VZ
4784 }
4785
4786 while ( hwnd && !win )
4787 {
761989ff
VZ
4788 // this is a really ugly hack needed to avoid mistakenly returning the
4789 // parent frame wxWindow for the find/replace modeless dialog HWND -
4790 // this, in turn, is needed to call IsDialogMessage() from
4791 // wxApp::ProcessMessage() as for this we must return NULL from here
4792 //
4793 // FIXME: this is clearly not the best way to do it but I think we'll
4794 // need to change HWND <-> wxWindow code more heavily than I can
4795 // do it now to fix it
c67d6888 4796#ifndef __WXMICROWIN__
761989ff
VZ
4797 if ( ::GetWindow(hwnd, GW_OWNER) )
4798 {
4799 // it's a dialog box, don't go upwards
4800 break;
4801 }
c67d6888 4802#endif
761989ff 4803
8614c467 4804 hwnd = ::GetParent(hwnd);
761989ff 4805 win = wxFindWinFromHandle((WXHWND)hwnd);
8614c467
VZ
4806 }
4807
4808 return win;
4809}
4810
04ef50df
JS
4811#ifndef __WXMICROWIN__
4812
42e69d6b
VZ
4813// Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
4814// in active frames and dialogs, regardless of where the focus is.
4815static HHOOK wxTheKeyboardHook = 0;
4816static FARPROC wxTheKeyboardHookProc = 0;
4817int APIENTRY _EXPORT
4818wxKeyboardHook(int nCode, WORD wParam, DWORD lParam);
2bda0e17 4819
42e69d6b 4820void wxSetKeyboardHook(bool doIt)
2bda0e17 4821{
42e69d6b 4822 if ( doIt )
2d0a075d 4823 {
42e69d6b
VZ
4824 wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance());
4825 wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
c7527e3f 4826
42e69d6b 4827#if defined(__WIN32__) && !defined(__TWIN32__)
8614c467 4828 GetCurrentThreadId()
42e69d6b
VZ
4829 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
4830#else
8614c467 4831 GetCurrentTask()
42e69d6b 4832#endif
8614c467 4833 );
2d0a075d 4834 }
2d0a075d 4835 else
2d0a075d 4836 {
42e69d6b 4837 UnhookWindowsHookEx(wxTheKeyboardHook);
4cdc2c13
VZ
4838
4839 // avoids warning about statement with no effect (FreeProcInstance
4840 // doesn't do anything under Win32)
d66dcb60 4841#if !defined(__WIN32__) && !defined(__NT__)
42e69d6b 4842 FreeProcInstance(wxTheKeyboardHookProc);
a17e237f 4843#endif
2d0a075d 4844 }
2bda0e17
KB
4845}
4846
42e69d6b
VZ
4847int APIENTRY _EXPORT
4848wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
2bda0e17 4849{
42e69d6b
VZ
4850 DWORD hiWord = HIWORD(lParam);
4851 if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) )
43d811ea 4852 {
32de7d24
VZ
4853 int id = wxCharCodeMSWToWX(wParam);
4854 if ( id != 0 )
43d811ea 4855 {
42e69d6b
VZ
4856 wxKeyEvent event(wxEVT_CHAR_HOOK);
4857 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
4858 event.m_altDown = TRUE;
c085e333 4859
42e69d6b
VZ
4860 event.m_eventObject = NULL;
4861 event.m_keyCode = id;
3f7bc32b
VZ
4862 event.m_shiftDown = wxIsShiftDown();
4863 event.m_controlDown = wxIsCtrlDown();
42e69d6b 4864 event.SetTimestamp(s_currentMsg.time);
c085e333 4865
42e69d6b 4866 wxWindow *win = wxGetActiveWindow();
32de7d24 4867 wxEvtHandler *handler;
42e69d6b
VZ
4868 if ( win )
4869 {
32de7d24
VZ
4870 handler = win->GetEventHandler();
4871 event.SetId(win->GetId());
42e69d6b
VZ
4872 }
4873 else
4874 {
32de7d24
VZ
4875 handler = wxTheApp;
4876 event.SetId(-1);
4877 }
4878
4879 if ( handler && handler->ProcessEvent(event) )
4880 {
4881 // processed
4882 return 1;
42e69d6b 4883 }
43d811ea
JS
4884 }
4885 }
32de7d24 4886
42e69d6b 4887 return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam);
4fabb575 4888}
cd4453e5
VZ
4889
4890#endif // !__WXMICROWIN__
4fabb575 4891
b2aef89b 4892#ifdef __WXDEBUG__
f449ef69 4893const char *wxGetMessageName(int message)
47cbd6da 4894{
42e69d6b
VZ
4895 switch ( message )
4896 {
4897 case 0x0000: return "WM_NULL";
4898 case 0x0001: return "WM_CREATE";
4899 case 0x0002: return "WM_DESTROY";
4900 case 0x0003: return "WM_MOVE";
4901 case 0x0005: return "WM_SIZE";
4902 case 0x0006: return "WM_ACTIVATE";
4903 case 0x0007: return "WM_SETFOCUS";
4904 case 0x0008: return "WM_KILLFOCUS";
4905 case 0x000A: return "WM_ENABLE";
4906 case 0x000B: return "WM_SETREDRAW";
9b64e798
VZ
4907 case 0x000C: return "WM_SETTEXT";
4908 case 0x000D: return "WM_GETTEXT";
42e69d6b 4909 case 0x000E: return "WM_GETTEXTLENGTH";
9b64e798 4910 case 0x000F: return "WM_PAINT";
42e69d6b
VZ
4911 case 0x0010: return "WM_CLOSE";
4912 case 0x0011: return "WM_QUERYENDSESSION";
9b64e798 4913 case 0x0012: return "WM_QUIT";
42e69d6b
VZ
4914 case 0x0013: return "WM_QUERYOPEN";
4915 case 0x0014: return "WM_ERASEBKGND";
4916 case 0x0015: return "WM_SYSCOLORCHANGE";
4917 case 0x0016: return "WM_ENDSESSION";
4918 case 0x0017: return "WM_SYSTEMERROR";
4919 case 0x0018: return "WM_SHOWWINDOW";
4920 case 0x0019: return "WM_CTLCOLOR";
4921 case 0x001A: return "WM_WININICHANGE";
4922 case 0x001B: return "WM_DEVMODECHANGE";
4923 case 0x001C: return "WM_ACTIVATEAPP";
4924 case 0x001D: return "WM_FONTCHANGE";
4925 case 0x001E: return "WM_TIMECHANGE";
4926 case 0x001F: return "WM_CANCELMODE";
4927 case 0x0020: return "WM_SETCURSOR";
4928 case 0x0021: return "WM_MOUSEACTIVATE";
4929 case 0x0022: return "WM_CHILDACTIVATE";
4930 case 0x0023: return "WM_QUEUESYNC";
4931 case 0x0024: return "WM_GETMINMAXINFO";
4932 case 0x0026: return "WM_PAINTICON";
4933 case 0x0027: return "WM_ICONERASEBKGND";
4934 case 0x0028: return "WM_NEXTDLGCTL";
4935 case 0x002A: return "WM_SPOOLERSTATUS";
4936 case 0x002B: return "WM_DRAWITEM";
4937 case 0x002C: return "WM_MEASUREITEM";
4938 case 0x002D: return "WM_DELETEITEM";
4939 case 0x002E: return "WM_VKEYTOITEM";
4940 case 0x002F: return "WM_CHARTOITEM";
9b64e798
VZ
4941 case 0x0030: return "WM_SETFONT";
4942 case 0x0031: return "WM_GETFONT";
42e69d6b
VZ
4943 case 0x0037: return "WM_QUERYDRAGICON";
4944 case 0x0039: return "WM_COMPAREITEM";
4945 case 0x0041: return "WM_COMPACTING";
4946 case 0x0044: return "WM_COMMNOTIFY";
4947 case 0x0046: return "WM_WINDOWPOSCHANGING";
4948 case 0x0047: return "WM_WINDOWPOSCHANGED";
4949 case 0x0048: return "WM_POWER";
c085e333 4950
a02eb1d2 4951#ifdef __WIN32__
42e69d6b
VZ
4952 case 0x004A: return "WM_COPYDATA";
4953 case 0x004B: return "WM_CANCELJOURNAL";
4954 case 0x004E: return "WM_NOTIFY";
9b64e798 4955 case 0x0050: return "WM_INPUTLANGCHANGEREQUEST";
42e69d6b
VZ
4956 case 0x0051: return "WM_INPUTLANGCHANGE";
4957 case 0x0052: return "WM_TCARD";
4958 case 0x0053: return "WM_HELP";
4959 case 0x0054: return "WM_USERCHANGED";
9b64e798 4960 case 0x0055: return "WM_NOTIFYFORMAT";
42e69d6b
VZ
4961 case 0x007B: return "WM_CONTEXTMENU";
4962 case 0x007C: return "WM_STYLECHANGING";
4963 case 0x007D: return "WM_STYLECHANGED";
4964 case 0x007E: return "WM_DISPLAYCHANGE";
4965 case 0x007F: return "WM_GETICON";
4966 case 0x0080: return "WM_SETICON";
a02eb1d2 4967#endif //WIN32
c085e333 4968
42e69d6b
VZ
4969 case 0x0081: return "WM_NCCREATE";
4970 case 0x0082: return "WM_NCDESTROY";
4971 case 0x0083: return "WM_NCCALCSIZE";
9b64e798
VZ
4972 case 0x0084: return "WM_NCHITTEST";
4973 case 0x0085: return "WM_NCPAINT";
42e69d6b
VZ
4974 case 0x0086: return "WM_NCACTIVATE";
4975 case 0x0087: return "WM_GETDLGCODE";
4976 case 0x00A0: return "WM_NCMOUSEMOVE";
4977 case 0x00A1: return "WM_NCLBUTTONDOWN";
4978 case 0x00A2: return "WM_NCLBUTTONUP";
4979 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
4980 case 0x00A4: return "WM_NCRBUTTONDOWN";
4981 case 0x00A5: return "WM_NCRBUTTONUP";
4982 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
4983 case 0x00A7: return "WM_NCMBUTTONDOWN";
4984 case 0x00A8: return "WM_NCMBUTTONUP";
4985 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
4986 case 0x0100: return "WM_KEYDOWN";
4987 case 0x0101: return "WM_KEYUP";
4988 case 0x0102: return "WM_CHAR";
4989 case 0x0103: return "WM_DEADCHAR";
4990 case 0x0104: return "WM_SYSKEYDOWN";
4991 case 0x0105: return "WM_SYSKEYUP";
4992 case 0x0106: return "WM_SYSCHAR";
4993 case 0x0107: return "WM_SYSDEADCHAR";
9b64e798 4994 case 0x0108: return "WM_KEYLAST";
c085e333 4995
a02eb1d2 4996#ifdef __WIN32__
42e69d6b
VZ
4997 case 0x010D: return "WM_IME_STARTCOMPOSITION";
4998 case 0x010E: return "WM_IME_ENDCOMPOSITION";
4999 case 0x010F: return "WM_IME_COMPOSITION";
a02eb1d2 5000#endif //WIN32
c085e333 5001
42e69d6b
VZ
5002 case 0x0110: return "WM_INITDIALOG";
5003 case 0x0111: return "WM_COMMAND";
5004 case 0x0112: return "WM_SYSCOMMAND";
5005 case 0x0113: return "WM_TIMER";
5006 case 0x0114: return "WM_HSCROLL";
5007 case 0x0115: return "WM_VSCROLL";
5008 case 0x0116: return "WM_INITMENU";
5009 case 0x0117: return "WM_INITMENUPOPUP";
9b64e798 5010 case 0x011F: return "WM_MENUSELECT";
42e69d6b
VZ
5011 case 0x0120: return "WM_MENUCHAR";
5012 case 0x0121: return "WM_ENTERIDLE";
5013 case 0x0200: return "WM_MOUSEMOVE";
5014 case 0x0201: return "WM_LBUTTONDOWN";
5015 case 0x0202: return "WM_LBUTTONUP";
5016 case 0x0203: return "WM_LBUTTONDBLCLK";
5017 case 0x0204: return "WM_RBUTTONDOWN";
5018 case 0x0205: return "WM_RBUTTONUP";
5019 case 0x0206: return "WM_RBUTTONDBLCLK";
5020 case 0x0207: return "WM_MBUTTONDOWN";
5021 case 0x0208: return "WM_MBUTTONUP";
5022 case 0x0209: return "WM_MBUTTONDBLCLK";
d2c52078 5023 case 0x020A: return "WM_MOUSEWHEEL";
42e69d6b
VZ
5024 case 0x0210: return "WM_PARENTNOTIFY";
5025 case 0x0211: return "WM_ENTERMENULOOP";
5026 case 0x0212: return "WM_EXITMENULOOP";
c085e333 5027
a02eb1d2 5028#ifdef __WIN32__
42e69d6b
VZ
5029 case 0x0213: return "WM_NEXTMENU";
5030 case 0x0214: return "WM_SIZING";
5031 case 0x0215: return "WM_CAPTURECHANGED";
5032 case 0x0216: return "WM_MOVING";
9b64e798 5033 case 0x0218: return "WM_POWERBROADCAST";
42e69d6b 5034 case 0x0219: return "WM_DEVICECHANGE";
a02eb1d2 5035#endif //WIN32
c085e333 5036
42e69d6b
VZ
5037 case 0x0220: return "WM_MDICREATE";
5038 case 0x0221: return "WM_MDIDESTROY";
5039 case 0x0222: return "WM_MDIACTIVATE";
5040 case 0x0223: return "WM_MDIRESTORE";
9b64e798 5041 case 0x0224: return "WM_MDINEXT";
42e69d6b
VZ
5042 case 0x0225: return "WM_MDIMAXIMIZE";
5043 case 0x0226: return "WM_MDITILE";
5044 case 0x0227: return "WM_MDICASCADE";
5045 case 0x0228: return "WM_MDIICONARRANGE";
5046 case 0x0229: return "WM_MDIGETACTIVE";
5047 case 0x0230: return "WM_MDISETMENU";
5048 case 0x0233: return "WM_DROPFILES";
c085e333 5049
a02eb1d2 5050#ifdef __WIN32__
9b64e798 5051 case 0x0281: return "WM_IME_SETCONTEXT";
42e69d6b
VZ
5052 case 0x0282: return "WM_IME_NOTIFY";
5053 case 0x0283: return "WM_IME_CONTROL";
5054 case 0x0284: return "WM_IME_COMPOSITIONFULL";
9b64e798 5055 case 0x0285: return "WM_IME_SELECT";
42e69d6b
VZ
5056 case 0x0286: return "WM_IME_CHAR";
5057 case 0x0290: return "WM_IME_KEYDOWN";
5058 case 0x0291: return "WM_IME_KEYUP";
a02eb1d2 5059#endif //WIN32
c085e333 5060
9b64e798 5061 case 0x0300: return "WM_CUT";
42e69d6b
VZ
5062 case 0x0301: return "WM_COPY";
5063 case 0x0302: return "WM_PASTE";
5064 case 0x0303: return "WM_CLEAR";
5065 case 0x0304: return "WM_UNDO";
9b64e798 5066 case 0x0305: return "WM_RENDERFORMAT";
42e69d6b
VZ
5067 case 0x0306: return "WM_RENDERALLFORMATS";
5068 case 0x0307: return "WM_DESTROYCLIPBOARD";
5069 case 0x0308: return "WM_DRAWCLIPBOARD";
5070 case 0x0309: return "WM_PAINTCLIPBOARD";
5071 case 0x030A: return "WM_VSCROLLCLIPBOARD";
5072 case 0x030B: return "WM_SIZECLIPBOARD";
5073 case 0x030C: return "WM_ASKCBFORMATNAME";
5074 case 0x030D: return "WM_CHANGECBCHAIN";
5075 case 0x030E: return "WM_HSCROLLCLIPBOARD";
5076 case 0x030F: return "WM_QUERYNEWPALETTE";
5077 case 0x0310: return "WM_PALETTEISCHANGING";
5078 case 0x0311: return "WM_PALETTECHANGED";
c085e333 5079
a02eb1d2 5080#ifdef __WIN32__
2d0a075d
JS
5081 // common controls messages - although they're not strictly speaking
5082 // standard, it's nice to decode them nevertheless
a02eb1d2 5083
2d0a075d 5084 // listview
42e69d6b
VZ
5085 case 0x1000 + 0: return "LVM_GETBKCOLOR";
5086 case 0x1000 + 1: return "LVM_SETBKCOLOR";
9b64e798
VZ
5087 case 0x1000 + 2: return "LVM_GETIMAGELIST";
5088 case 0x1000 + 3: return "LVM_SETIMAGELIST";
5089 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
42e69d6b
VZ
5090 case 0x1000 + 5: return "LVM_GETITEMA";
5091 case 0x1000 + 75: return "LVM_GETITEMW";
5092 case 0x1000 + 6: return "LVM_SETITEMA";
5093 case 0x1000 + 76: return "LVM_SETITEMW";
5094 case 0x1000 + 7: return "LVM_INSERTITEMA";
5095 case 0x1000 + 77: return "LVM_INSERTITEMW";
5096 case 0x1000 + 8: return "LVM_DELETEITEM";
5097 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
5098 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
5099 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
5100 case 0x1000 + 12: return "LVM_GETNEXTITEM";
5101 case 0x1000 + 13: return "LVM_FINDITEMA";
5102 case 0x1000 + 83: return "LVM_FINDITEMW";
9b64e798 5103 case 0x1000 + 14: return "LVM_GETITEMRECT";
42e69d6b
VZ
5104 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
5105 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
5106 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
5107 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
9b64e798 5108 case 0x1000 + 18: return "LVM_HITTEST";
42e69d6b
VZ
5109 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
5110 case 0x1000 + 20: return "LVM_SCROLL";
5111 case 0x1000 + 21: return "LVM_REDRAWITEMS";
5112 case 0x1000 + 22: return "LVM_ARRANGE";
5113 case 0x1000 + 23: return "LVM_EDITLABELA";
5114 case 0x1000 + 118: return "LVM_EDITLABELW";
5115 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
5116 case 0x1000 + 25: return "LVM_GETCOLUMNA";
5117 case 0x1000 + 95: return "LVM_GETCOLUMNW";
5118 case 0x1000 + 26: return "LVM_SETCOLUMNA";
5119 case 0x1000 + 96: return "LVM_SETCOLUMNW";
5120 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
5121 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
5122 case 0x1000 + 28: return "LVM_DELETECOLUMN";
5123 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
5124 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
5125 case 0x1000 + 31: return "LVM_GETHEADER";
5126 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
9b64e798 5127 case 0x1000 + 34: return "LVM_GETVIEWRECT";
42e69d6b
VZ
5128 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
5129 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
5130 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
5131 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
5132 case 0x1000 + 39: return "LVM_GETTOPINDEX";
5133 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
5134 case 0x1000 + 41: return "LVM_GETORIGIN";
5135 case 0x1000 + 42: return "LVM_UPDATE";
5136 case 0x1000 + 43: return "LVM_SETITEMSTATE";
5137 case 0x1000 + 44: return "LVM_GETITEMSTATE";
5138 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
5139 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
5140 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
5141 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
9b64e798 5142 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
42e69d6b
VZ
5143 case 0x1000 + 48: return "LVM_SORTITEMS";
5144 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
9b64e798 5145 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
42e69d6b
VZ
5146 case 0x1000 + 51: return "LVM_GETITEMSPACING";
5147 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
5148 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
5149 case 0x1000 + 53: return "LVM_SETICONSPACING";
5150 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
5151 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
9b64e798
VZ
5152 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
5153 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
42e69d6b
VZ
5154 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
5155 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
5156 case 0x1000 + 60: return "LVM_SETHOTITEM";
5157 case 0x1000 + 61: return "LVM_GETHOTITEM";
5158 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
5159 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
9b64e798 5160 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
42e69d6b 5161 case 0x1000 + 65: return "LVM_SETWORKAREA";
c085e333 5162
2d0a075d 5163 // tree view
42e69d6b
VZ
5164 case 0x1100 + 0: return "TVM_INSERTITEMA";
5165 case 0x1100 + 50: return "TVM_INSERTITEMW";
5166 case 0x1100 + 1: return "TVM_DELETEITEM";
5167 case 0x1100 + 2: return "TVM_EXPAND";
9b64e798
VZ
5168 case 0x1100 + 4: return "TVM_GETITEMRECT";
5169 case 0x1100 + 5: return "TVM_GETCOUNT";
5170 case 0x1100 + 6: return "TVM_GETINDENT";
5171 case 0x1100 + 7: return "TVM_SETINDENT";
5172 case 0x1100 + 8: return "TVM_GETIMAGELIST";
5173 case 0x1100 + 9: return "TVM_SETIMAGELIST";
42e69d6b
VZ
5174 case 0x1100 + 10: return "TVM_GETNEXTITEM";
5175 case 0x1100 + 11: return "TVM_SELECTITEM";
5176 case 0x1100 + 12: return "TVM_GETITEMA";
5177 case 0x1100 + 62: return "TVM_GETITEMW";
5178 case 0x1100 + 13: return "TVM_SETITEMA";
5179 case 0x1100 + 63: return "TVM_SETITEMW";
5180 case 0x1100 + 14: return "TVM_EDITLABELA";
5181 case 0x1100 + 65: return "TVM_EDITLABELW";
5182 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
9b64e798
VZ
5183 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
5184 case 0x1100 + 17: return "TVM_HITTEST";
42e69d6b
VZ
5185 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
5186 case 0x1100 + 19: return "TVM_SORTCHILDREN";
5187 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
5188 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
5189 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
5190 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
5191 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
5192 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
5193 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
c085e333 5194
2d0a075d 5195 // header
9b64e798 5196 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
42e69d6b
VZ
5197 case 0x1200 + 1: return "HDM_INSERTITEMA";
5198 case 0x1200 + 10: return "HDM_INSERTITEMW";
5199 case 0x1200 + 2: return "HDM_DELETEITEM";
5200 case 0x1200 + 3: return "HDM_GETITEMA";
5201 case 0x1200 + 11: return "HDM_GETITEMW";
5202 case 0x1200 + 4: return "HDM_SETITEMA";
5203 case 0x1200 + 12: return "HDM_SETITEMW";
9b64e798
VZ
5204 case 0x1200 + 5: return "HDM_LAYOUT";
5205 case 0x1200 + 6: return "HDM_HITTEST";
5206 case 0x1200 + 7: return "HDM_GETITEMRECT";
5207 case 0x1200 + 8: return "HDM_SETIMAGELIST";
5208 case 0x1200 + 9: return "HDM_GETIMAGELIST";
42e69d6b
VZ
5209 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
5210 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
5211 case 0x1200 + 17: return "HDM_GETORDERARRAY";
5212 case 0x1200 + 18: return "HDM_SETORDERARRAY";
5213 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
c085e333 5214
2d0a075d 5215 // tab control
9b64e798
VZ
5216 case 0x1300 + 2: return "TCM_GETIMAGELIST";
5217 case 0x1300 + 3: return "TCM_SETIMAGELIST";
5218 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
42e69d6b
VZ
5219 case 0x1300 + 5: return "TCM_GETITEMA";
5220 case 0x1300 + 60: return "TCM_GETITEMW";
5221 case 0x1300 + 6: return "TCM_SETITEMA";
5222 case 0x1300 + 61: return "TCM_SETITEMW";
5223 case 0x1300 + 7: return "TCM_INSERTITEMA";
5224 case 0x1300 + 62: return "TCM_INSERTITEMW";
5225 case 0x1300 + 8: return "TCM_DELETEITEM";
5226 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
9b64e798 5227 case 0x1300 + 10: return "TCM_GETITEMRECT";
42e69d6b
VZ
5228 case 0x1300 + 11: return "TCM_GETCURSEL";
5229 case 0x1300 + 12: return "TCM_SETCURSEL";
9b64e798 5230 case 0x1300 + 13: return "TCM_HITTEST";
42e69d6b 5231 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
9b64e798 5232 case 0x1300 + 40: return "TCM_ADJUSTRECT";
42e69d6b
VZ
5233 case 0x1300 + 41: return "TCM_SETITEMSIZE";
5234 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
5235 case 0x1300 + 43: return "TCM_SETPADDING";
9b64e798 5236 case 0x1300 + 44: return "TCM_GETROWCOUNT";
42e69d6b
VZ
5237 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
5238 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
5239 case 0x1300 + 47: return "TCM_GETCURFOCUS";
5240 case 0x1300 + 48: return "TCM_SETCURFOCUS";
5241 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
5242 case 0x1300 + 50: return "TCM_DESELECTALL";
c085e333 5243
2d0a075d 5244 // toolbar
42e69d6b
VZ
5245 case WM_USER+1: return "TB_ENABLEBUTTON";
5246 case WM_USER+2: return "TB_CHECKBUTTON";
5247 case WM_USER+3: return "TB_PRESSBUTTON";
5248 case WM_USER+4: return "TB_HIDEBUTTON";
5249 case WM_USER+5: return "TB_INDETERMINATE";
5250 case WM_USER+9: return "TB_ISBUTTONENABLED";
5251 case WM_USER+10: return "TB_ISBUTTONCHECKED";
5252 case WM_USER+11: return "TB_ISBUTTONPRESSED";
5253 case WM_USER+12: return "TB_ISBUTTONHIDDEN";
5254 case WM_USER+13: return "TB_ISBUTTONINDETERMINATE";
5255 case WM_USER+17: return "TB_SETSTATE";
5256 case WM_USER+18: return "TB_GETSTATE";
5257 case WM_USER+19: return "TB_ADDBITMAP";
5258 case WM_USER+20: return "TB_ADDBUTTONS";
5259 case WM_USER+21: return "TB_INSERTBUTTON";
5260 case WM_USER+22: return "TB_DELETEBUTTON";
5261 case WM_USER+23: return "TB_GETBUTTON";
9b64e798 5262 case WM_USER+24: return "TB_BUTTONCOUNT";
42e69d6b
VZ
5263 case WM_USER+25: return "TB_COMMANDTOINDEX";
5264 case WM_USER+26: return "TB_SAVERESTOREA";
5265 case WM_USER+76: return "TB_SAVERESTOREW";
5266 case WM_USER+27: return "TB_CUSTOMIZE";
5267 case WM_USER+28: return "TB_ADDSTRINGA";
5268 case WM_USER+77: return "TB_ADDSTRINGW";
9b64e798 5269 case WM_USER+29: return "TB_GETITEMRECT";
42e69d6b
VZ
5270 case WM_USER+30: return "TB_BUTTONSTRUCTSIZE";
5271 case WM_USER+31: return "TB_SETBUTTONSIZE";
5272 case WM_USER+32: return "TB_SETBITMAPSIZE";
5273 case WM_USER+33: return "TB_AUTOSIZE";
5274 case WM_USER+35: return "TB_GETTOOLTIPS";
5275 case WM_USER+36: return "TB_SETTOOLTIPS";
9b64e798 5276 case WM_USER+37: return "TB_SETPARENT";
42e69d6b
VZ
5277 case WM_USER+39: return "TB_SETROWS";
5278 case WM_USER+40: return "TB_GETROWS";
5279 case WM_USER+42: return "TB_SETCMDID";
5280 case WM_USER+43: return "TB_CHANGEBITMAP";
5281 case WM_USER+44: return "TB_GETBITMAP";
5282 case WM_USER+45: return "TB_GETBUTTONTEXTA";
5283 case WM_USER+75: return "TB_GETBUTTONTEXTW";
5284 case WM_USER+46: return "TB_REPLACEBITMAP";
9b64e798
VZ
5285 case WM_USER+47: return "TB_SETINDENT";
5286 case WM_USER+48: return "TB_SETIMAGELIST";
5287 case WM_USER+49: return "TB_GETIMAGELIST";
42e69d6b 5288 case WM_USER+50: return "TB_LOADIMAGES";
9b64e798
VZ
5289 case WM_USER+51: return "TB_GETRECT";
5290 case WM_USER+52: return "TB_SETHOTIMAGELIST";
5291 case WM_USER+53: return "TB_GETHOTIMAGELIST";
5292 case WM_USER+54: return "TB_SETDISABLEDIMAGELIST";
5293 case WM_USER+55: return "TB_GETDISABLEDIMAGELIST";
42e69d6b
VZ
5294 case WM_USER+56: return "TB_SETSTYLE";
5295 case WM_USER+57: return "TB_GETSTYLE";
5296 case WM_USER+58: return "TB_GETBUTTONSIZE";
5297 case WM_USER+59: return "TB_SETBUTTONWIDTH";
5298 case WM_USER+60: return "TB_SETMAXTEXTROWS";
5299 case WM_USER+61: return "TB_GETTEXTROWS";
5300 case WM_USER+41: return "TB_GETBITMAPFLAGS";
c085e333 5301
a02eb1d2 5302#endif //WIN32
c085e333 5303
42e69d6b
VZ
5304 default:
5305 static char s_szBuf[128];
5306 sprintf(s_szBuf, "<unknown message = %d>", message);
5307 return s_szBuf;
5308 }
47cbd6da 5309}
ea57084d 5310#endif //__WXDEBUG__
4aff28fc 5311
1e6feb95
VZ
5312static void TranslateKbdEventToMouse(wxWindowMSW *win,
5313 int *x, int *y, WPARAM *flags)
4aff28fc
VZ
5314{
5315 // construct the key mask
5316 WPARAM& fwKeys = *flags;
5317
5318 fwKeys = MK_RBUTTON;
3f7bc32b 5319 if ( wxIsCtrlDown() )
4aff28fc 5320 fwKeys |= MK_CONTROL;
3f7bc32b 5321 if ( wxIsShiftDown() )
4aff28fc
VZ
5322 fwKeys |= MK_SHIFT;
5323
5324 // simulate right mouse button click
5325 DWORD dwPos = ::GetMessagePos();
5326 *x = GET_X_LPARAM(dwPos);
5327 *y = GET_Y_LPARAM(dwPos);
5328
5329 win->ScreenToClient(x, y);
5330}
f6bcfd97 5331
1e6feb95 5332static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win)
f6bcfd97
BP
5333{
5334 // prepare the DC
5335 TEXTMETRIC tm;
5336 HWND hwnd = GetHwndOf(win);
5337 HDC hdc = ::GetDC(hwnd);
5338
5339#if !wxDIALOG_UNIT_COMPATIBILITY
5340 // and select the current font into it
5341 HFONT hfont = GetHfontOf(win->GetFont());
5342 if ( hfont )
5343 {
5344 hfont = (HFONT)::SelectObject(hdc, hfont);
5345 }
5346#endif
5347
5348 // finally retrieve the text metrics from it
5349 GetTextMetrics(hdc, &tm);
5350
5351#if !wxDIALOG_UNIT_COMPATIBILITY
5352 // and clean up
5353 if ( hfont )
5354 {
5355 (void)::SelectObject(hdc, hfont);
5356 }
5357#endif
5358
5359 ::ReleaseDC(hwnd, hdc);
5360
5361 return tm;
5362}
3723b7b1
JS
5363
5364// Find the wxWindow at the current mouse position, returning the mouse
5365// position.
2b5f62a0 5366wxWindow* wxFindWindowAtPointer(wxPoint& pt)
3723b7b1 5367{
2b5f62a0
VZ
5368 pt = wxGetMousePosition();
5369 return wxFindWindowAtPoint(pt);
57591e0e
JS
5370}
5371
5372wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
5373{
5374 POINT pt2;
5375 pt2.x = pt.x;
5376 pt2.y = pt.y;
5377 HWND hWndHit = ::WindowFromPoint(pt2);
3723b7b1
JS
5378
5379 wxWindow* win = wxFindWinFromHandle((WXHWND) hWndHit) ;
5380 HWND hWnd = hWndHit;
5381
5382 // Try to find a window with a wxWindow associated with it
5383 while (!win && (hWnd != 0))
5384 {
5385 hWnd = ::GetParent(hWnd);
5386 win = wxFindWinFromHandle((WXHWND) hWnd) ;
5387 }
5388 return win;
5389}
5390
5391// Get the current mouse position.
5392wxPoint wxGetMousePosition()
5393{
1772ead0
JS
5394 POINT pt;
5395 GetCursorPos( & pt );
5cd16c0c 5396
1772ead0 5397 return wxPoint(pt.x, pt.y);
3723b7b1
JS
5398}
5399