]> git.saurik.com Git - wxWidgets.git/blame - src/msw/window.cpp
wxCaret MSW bug fixes
[wxWidgets.git] / src / msw / window.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: windows.cpp
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$
8// Copyright: (c) Julian Smart and Markus Holzem
a3622daa 9// Licence: wxWindows license
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
3a19e16d
VZ
32 #include "wx/setup.h"
33 #include "wx/menu.h"
34 #include "wx/dc.h"
35 #include "wx/dcclient.h"
36 #include "wx/utils.h"
37 #include "wx/app.h"
38 #include "wx/panel.h"
39 #include "wx/layout.h"
40 #include "wx/dialog.h"
41 #include "wx/frame.h"
42 #include "wx/listbox.h"
43 #include "wx/button.h"
3a19e16d 44 #include "wx/msgdlg.h"
341c92a8
VZ
45
46 #include <stdio.h>
2bda0e17
KB
47#endif
48
47d67540 49#if wxUSE_OWNER_DRAWN
09914df7 50 #include "wx/ownerdrw.h"
2bda0e17
KB
51#endif
52
47d67540 53#if wxUSE_DRAG_AND_DROP
09914df7 54 #include "wx/msw/ole/droptgt.h"
2bda0e17
KB
55#endif
56
57#include "wx/menuitem.h"
47cbd6da 58#include "wx/log.h"
750b78ba
JS
59
60#if wxUSE_TOOLTIPS
42e69d6b 61 #include "wx/tooltip.h"
750b78ba
JS
62#endif
63
789295bf
VZ
64#if wxUSE_CARET
65 #include "wx/caret.h"
66#endif // wxUSE_CARET
67
dbda9e86
JS
68#include "wx/intl.h"
69#include "wx/log.h"
3a19e16d 70
2bda0e17
KB
71#include "wx/msw/private.h"
72
2a47d3c1
JS
73#include "wx/textctrl.h"
74
2bda0e17
KB
75#include <string.h>
76
77#ifndef __GNUWIN32__
3a19e16d
VZ
78 #include <shellapi.h>
79 #include <mmsystem.h>
2bda0e17
KB
80#endif
81
82#ifdef __WIN32__
3a19e16d 83 #include <windowsx.h>
2bda0e17
KB
84#endif
85
cc2b7472 86#if ( defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__ )
42e69d6b 87 #include <commctrl.h>
acbd13a3 88#endif
3a19e16d 89
57c208c5 90#ifndef __TWIN32__
3a19e16d
VZ
91 #ifdef __GNUWIN32__
92 #include <wx/msw/gnuwin32/extra.h>
93 #endif
57c208c5 94#endif
2bda0e17 95
42e69d6b 96#include "wx/msw/winundef.h"
2bda0e17 97
a23fd0e1
VZ
98// ---------------------------------------------------------------------------
99// macros
100// ---------------------------------------------------------------------------
101
102// standard macros missing from some compilers headers
103#ifndef GET_X_LPARAM
104 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
105 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
106#endif // GET_X_LPARAM
107
108// ---------------------------------------------------------------------------
42e69d6b 109// global variables
a23fd0e1 110// ---------------------------------------------------------------------------
47cbd6da 111
42e69d6b
VZ
112// the last Windows message we got (MT-UNSAFE)
113extern MSG s_currentMsg;
2bda0e17
KB
114
115wxMenu *wxCurrentPopupMenu = NULL;
cde9f08e 116extern wxList WXDLLEXPORT wxPendingDelete;
42e69d6b
VZ
117extern char wxCanvasClassName[];
118
119// ---------------------------------------------------------------------------
120// private functions
121// ---------------------------------------------------------------------------
122
123// the window proc for all our windows
124LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
125 WPARAM wParam, LPARAM lParam);
126
127#ifdef __WXDEBUG__
128 const char *wxGetMessageName(int message);
129#endif //__WXDEBUG__
2bda0e17
KB
130
131void wxRemoveHandleAssociation(wxWindow *win);
132void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win);
133wxWindow *wxFindWinFromHandle(WXHWND hWnd);
134
a23fd0e1
VZ
135// ---------------------------------------------------------------------------
136// event tables
137// ---------------------------------------------------------------------------
138
42e69d6b
VZ
139#if !USE_SHARED_LIBRARY
140 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
141#endif
142
cc2b7472 143BEGIN_EVENT_TABLE(wxWindow, wxWindowBase)
cf65ad8d
VZ
144 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
145 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
146 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
147 EVT_IDLE(wxWindow::OnIdle)
2bda0e17
KB
148END_EVENT_TABLE()
149
a23fd0e1
VZ
150// ===========================================================================
151// implementation
152// ===========================================================================
153
42e69d6b
VZ
154// ---------------------------------------------------------------------------
155// wxWindow utility functions
156// ---------------------------------------------------------------------------
157
2bda0e17 158// Find an item given the MS Windows id
debe6624 159wxWindow *wxWindow::FindItem(int id) const
2bda0e17 160{
42e69d6b 161 wxWindowList::Node *current = GetChildren().GetFirst();
2d0a075d
JS
162 while (current)
163 {
42e69d6b 164 wxWindow *childWin = current->GetData();
2bda0e17 165
42e69d6b 166 wxWindow *wnd = childWin->FindItem(id);
cc2b7472 167 if ( wnd )
42e69d6b 168 return wnd;
2bda0e17 169
cc2b7472 170 if ( childWin->IsKindOf(CLASSINFO(wxControl)) )
2d0a075d
JS
171 {
172 wxControl *item = (wxControl *)childWin;
cc2b7472 173 if ( item->GetId() == id )
2d0a075d
JS
174 return item;
175 else
176 {
177 // In case it's a 'virtual' control (e.g. radiobox)
cc2b7472 178 if ( item->GetSubcontrols().Member((wxObject *)id) )
2d0a075d
JS
179 return item;
180 }
181 }
42e69d6b
VZ
182
183 current = current->GetNext();
2bda0e17 184 }
42e69d6b 185
2d0a075d 186 return NULL;
2bda0e17
KB
187}
188
189// Find an item given the MS Windows handle
debe6624 190wxWindow *wxWindow::FindItemByHWND(WXHWND hWnd, bool controlOnly) const
2bda0e17 191{
42e69d6b 192 wxWindowList::Node *current = GetChildren().GetFirst();
2d0a075d 193 while (current)
2bda0e17 194 {
42e69d6b
VZ
195 wxWindow *parent = current->GetData();
196
2d0a075d 197 // Do a recursive search.
42e69d6b 198 wxWindow *wnd = parent->FindItemByHWND(hWnd);
cc2b7472 199 if ( wnd )
42e69d6b 200 return wnd;
2d0a075d 201
42e69d6b 202 if ( !controlOnly || parent->IsKindOf(CLASSINFO(wxControl)) )
2d0a075d 203 {
42e69d6b
VZ
204 wxWindow *item = current->GetData();
205 if ( item->GetHWND() == hWnd )
2d0a075d
JS
206 return item;
207 else
208 {
209 if ( item->ContainsHWND(hWnd) )
210 return item;
211 }
212 }
42e69d6b
VZ
213
214 current = current->GetNext();
2bda0e17 215 }
2d0a075d 216 return NULL;
2bda0e17
KB
217}
218
219// Default command handler
debe6624 220bool wxWindow::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
2bda0e17 221{
2d0a075d 222 return FALSE;
2bda0e17
KB
223}
224
fd3f686c
VZ
225// ----------------------------------------------------------------------------
226// constructors and such
227// ----------------------------------------------------------------------------
228
229void wxWindow::Init()
2bda0e17 230{
cc2b7472
VZ
231 // generic
232 InitBase();
634903fd 233
cc2b7472 234 // MSW specific
42e69d6b 235 m_doubleClickAllowed = 0;
2d0a075d 236 m_winCaptured = FALSE;
cc2b7472 237
2d0a075d
JS
238 m_isBeingDeleted = FALSE;
239 m_oldWndProc = 0;
2d0a075d 240 m_useCtl3D = FALSE;
fd3f686c 241 m_mouseInWindow = FALSE;
2bda0e17 242
2d0a075d 243 // wxWnd
2d0a075d 244 m_hMenu = 0;
2bda0e17 245
2d0a075d
JS
246 m_xThumbSize = 0;
247 m_yThumbSize = 0;
248 m_backgroundTransparent = FALSE;
2bda0e17 249
85d10d9b
VZ
250 // as all windows are created with WS_VISIBLE style...
251 m_isShown = TRUE;
252
a23fd0e1 253#if wxUSE_MOUSEEVENT_HACK
cc2b7472
VZ
254 m_lastMouseX =
255 m_lastMouseY = -1;
256 m_lastMouseEvent = -1;
a23fd0e1 257#endif // wxUSE_MOUSEEVENT_HACK
fd3f686c
VZ
258}
259
2bda0e17 260// Destructor
fd3f686c 261wxWindow::~wxWindow()
2bda0e17 262{
2d0a075d 263 m_isBeingDeleted = TRUE;
2bda0e17 264
2d0a075d 265 MSWDetachWindowMenu();
2bda0e17 266
a23fd0e1
VZ
267 if ( m_parent )
268 m_parent->RemoveChild(this);
269
270 DestroyChildren();
271
cc2b7472 272 if ( m_hWnd )
42e69d6b
VZ
273 {
274 if ( !::DestroyWindow(GetHwnd()) )
275 wxLogLastError("DestroyWindow");
276 }
2bda0e17 277
cc2b7472
VZ
278 // Restore old Window proc, if required and remove hWnd <-> wxWindow
279 // association
2d0a075d 280 UnsubclassWin();
2bda0e17
KB
281}
282
fd3f686c 283// real construction (Init() must have been called before!)
debe6624 284bool wxWindow::Create(wxWindow *parent, wxWindowID id,
2d0a075d
JS
285 const wxPoint& pos,
286 const wxSize& size,
287 long style,
288 const wxString& name)
289{
fd3f686c 290 wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" );
2bda0e17 291
42e69d6b
VZ
292 CreateBase(parent, id, pos, size, style, name);
293
fd3f686c 294 parent->AddChild(this);
2bda0e17 295
2d0a075d 296 DWORD msflags = 0;
cc2b7472 297 if ( style & wxBORDER )
2d0a075d 298 msflags |= WS_BORDER;
cc2b7472 299 if ( style & wxTHICK_FRAME )
2d0a075d 300 msflags |= WS_THICKFRAME;
1c089c47 301
2d0a075d 302 msflags |= WS_CHILD | WS_VISIBLE;
cc2b7472 303 if ( style & wxCLIP_CHILDREN )
2d0a075d 304 msflags |= WS_CLIPCHILDREN;
2bda0e17 305
2d0a075d 306 bool want3D;
42e69d6b 307 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
2bda0e17 308
2d0a075d
JS
309 // Even with extended styles, need to combine with WS_BORDER
310 // for them to look right.
cc2b7472 311 if ( want3D || (m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER ) ||
2d0a075d 312 (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER))
cc2b7472 313 {
2d0a075d 314 msflags |= WS_BORDER;
cc2b7472 315 }
2bda0e17 316
2d0a075d 317 MSWCreate(m_windowId, parent, wxCanvasClassName, this, NULL,
cc2b7472
VZ
318 pos.x, pos.y,
319 WidthDefault(size.x), HeightDefault(size.y),
320 msflags, NULL, exStyle);
2bda0e17 321
2d0a075d 322 return TRUE;
2bda0e17
KB
323}
324
42e69d6b
VZ
325// ---------------------------------------------------------------------------
326// basic operations
327// ---------------------------------------------------------------------------
328
fd3f686c 329void wxWindow::SetFocus()
2bda0e17 330{
a23fd0e1 331 HWND hWnd = GetHwnd();
cc2b7472 332 if ( hWnd )
2d0a075d 333 ::SetFocus(hWnd);
2bda0e17
KB
334}
335
42e69d6b
VZ
336// Get the window with the focus
337wxWindow *wxWindowBase::FindFocus()
338{
339 HWND hWnd = ::GetFocus();
340 if ( hWnd )
341 {
342 return wxFindWinFromHandle((WXHWND) hWnd);
343 }
344
345 return NULL;
346}
347
cc2b7472 348bool wxWindow::Enable(bool enable)
2bda0e17 349{
cc2b7472
VZ
350 if ( !wxWindowBase::Enable(enable) )
351 return FALSE;
352
a23fd0e1 353 HWND hWnd = GetHwnd();
cc2b7472 354 if ( hWnd )
2d0a075d 355 ::EnableWindow(hWnd, (BOOL)enable);
cc2b7472
VZ
356
357 return TRUE;
2bda0e17
KB
358}
359
42e69d6b
VZ
360bool wxWindow::Show(bool show)
361{
362 if ( !wxWindowBase::Show(show) )
363 return FALSE;
364
365 HWND hWnd = GetHwnd();
366 int cshow = show ? SW_SHOW : SW_HIDE;
367 ::ShowWindow(hWnd, cshow);
368
369 if ( show )
370 {
371 BringWindowToTop(hWnd);
372 }
373
374 return TRUE;
375}
376
377// Raise the window to the top of the Z order
378void wxWindow::Raise()
379{
380 ::BringWindowToTop(GetHwnd());
381}
382
383// Lower the window to the bottom of the Z order
384void wxWindow::Lower()
385{
386 ::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0,
387 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
388}
389
390void wxWindow::SetTitle( const wxString& title)
391{
392 SetWindowText(GetHwnd(), title.c_str());
393}
394
395wxString wxWindow::GetTitle() const
396{
397 return wxGetWindowText(GetHWND());
398}
399
fd3f686c 400void wxWindow::CaptureMouse()
2bda0e17 401{
a23fd0e1 402 HWND hWnd = GetHwnd();
cc2b7472 403 if ( hWnd && !m_winCaptured )
2d0a075d
JS
404 {
405 SetCapture(hWnd);
406 m_winCaptured = TRUE;
407 }
2bda0e17
KB
408}
409
fd3f686c 410void wxWindow::ReleaseMouse()
2bda0e17 411{
cc2b7472 412 if ( m_winCaptured )
2d0a075d
JS
413 {
414 ReleaseCapture();
415 m_winCaptured = FALSE;
416 }
2bda0e17
KB
417}
418
42e69d6b 419bool wxWindow::SetFont(const wxFont& font)
2bda0e17 420{
42e69d6b
VZ
421 if ( !wxWindowBase::SetFont(font) )
422 {
423 // nothing to do
424 return FALSE;
2d0a075d 425 }
195896c7 426
42e69d6b
VZ
427 HWND hWnd = GetHwnd();
428 if ( hWnd != 0 )
429 {
430 WXHANDLE hFont = m_font.GetResourceHandle();
2bda0e17 431
42e69d6b 432 wxASSERT_MSG( hFont, _T("should have valid font") );
3a19e16d 433
42e69d6b
VZ
434 ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, TRUE);
435 }
2bda0e17 436
42e69d6b
VZ
437 return TRUE;
438}
439bool wxWindow::SetCursor(const wxCursor& cursor)
2bda0e17 440{
42e69d6b
VZ
441 if ( !wxWindowBase::SetCursor(cursor) )
442 {
443 // no change
444 return FALSE;
445 }
446
447 wxASSERT_MSG( m_cursor.Ok(),
448 _T("cursor must be valid after call to the base version"));
449
a23fd0e1 450 HWND hWnd = GetHwnd();
2bda0e17 451
42e69d6b
VZ
452 // Change the cursor NOW if we're within the correct window
453 POINT point;
454 ::GetCursorPos(&point);
3a19e16d 455
42e69d6b
VZ
456 RECT rect;
457 ::GetWindowRect(hWnd, &rect);
cb1a1dc9 458
42e69d6b
VZ
459 if ( ::PtInRect(&rect, point) && !wxIsBusy() )
460 ::SetCursor((HCURSOR)m_cursor.GetHCURSOR());
3a19e16d 461
42e69d6b 462 return TRUE;
3a19e16d
VZ
463}
464
42e69d6b 465void wxWindow::WarpPointer (int x_pos, int y_pos)
2bda0e17 466{
42e69d6b
VZ
467 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
468 // pixel coordinates, relatives to the canvas -- So, we first need to
469 // substract origin of the window, then convert to screen position
470
471 int x = x_pos; int y = y_pos;
2d0a075d 472 RECT rect;
42e69d6b 473 GetWindowRect (GetHwnd(), &rect);
cc2b7472 474
42e69d6b
VZ
475 x += rect.left;
476 y += rect.top;
477
478 SetCursorPos (x, y);
2bda0e17
KB
479}
480
42e69d6b
VZ
481#if WXWIN_COMPATIBILITY
482void wxWindow::MSWDeviceToLogical (float *x, float *y) const
2bda0e17 483{
42e69d6b
VZ
484}
485#endif // WXWIN_COMPATIBILITY
81d66cf3 486
42e69d6b
VZ
487// ---------------------------------------------------------------------------
488// scrolling stuff
489// ---------------------------------------------------------------------------
2d0a075d 490
42e69d6b
VZ
491#if WXWIN_COMPATIBILITY
492void wxWindow::SetScrollRange(int orient, int range, bool refresh)
493{
494#if defined(__WIN95__)
495
496 int range1 = range;
497
498 // Try to adjust the range to cope with page size > 1
499 // - a Windows API quirk
500 int pageSize = GetScrollPage(orient);
501 if ( pageSize > 1 && range > 0)
2d0a075d 502 {
42e69d6b 503 range1 += (pageSize - 1);
2d0a075d
JS
504 }
505
42e69d6b
VZ
506 SCROLLINFO info;
507 int dir;
508
509 if ( orient == wxHORIZONTAL ) {
510 dir = SB_HORZ;
511 } else {
512 dir = SB_VERT;
2d0a075d 513 }
cc2b7472 514
42e69d6b
VZ
515 info.cbSize = sizeof(SCROLLINFO);
516 info.nPage = pageSize; // Have to set this, or scrollbar goes awry
517 info.nMin = 0;
518 info.nMax = range1;
519 info.nPos = 0;
520 info.fMask = SIF_RANGE | SIF_PAGE;
521
522 HWND hWnd = GetHwnd();
523 if ( hWnd )
524 ::SetScrollInfo(hWnd, dir, &info, refresh);
525#else
526 int wOrient;
527 if ( orient == wxHORIZONTAL )
528 wOrient = SB_HORZ;
529 else
530 wOrient = SB_VERT;
531
532 HWND hWnd = GetHwnd();
533 if ( hWnd )
534 ::SetScrollRange(hWnd, wOrient, 0, range, refresh);
535#endif
2bda0e17
KB
536}
537
42e69d6b 538void wxWindow::SetScrollPage(int orient, int page, bool refresh)
2bda0e17 539{
42e69d6b
VZ
540#if defined(__WIN95__)
541 SCROLLINFO info;
542 int dir;
2d0a075d 543
42e69d6b
VZ
544 if ( orient == wxHORIZONTAL ) {
545 dir = SB_HORZ;
546 m_xThumbSize = page;
547 } else {
548 dir = SB_VERT;
549 m_yThumbSize = page;
550 }
0757d27c 551
42e69d6b
VZ
552 info.cbSize = sizeof(SCROLLINFO);
553 info.nPage = page;
554 info.nMin = 0;
555 info.fMask = SIF_PAGE;
556
557 HWND hWnd = GetHwnd();
558 if ( hWnd )
559 ::SetScrollInfo(hWnd, dir, &info, refresh);
560#else
561 if ( orient == wxHORIZONTAL )
562 m_xThumbSize = page;
563 else
564 m_yThumbSize = page;
565#endif
2bda0e17
KB
566}
567
42e69d6b 568int wxWindow::OldGetScrollRange(int orient) const
2bda0e17 569{
42e69d6b
VZ
570 int wOrient;
571 if ( orient == wxHORIZONTAL )
572 wOrient = SB_HORZ;
573 else
574 wOrient = SB_VERT;
2d0a075d 575
42e69d6b
VZ
576#if __WATCOMC__ && defined(__WINDOWS_386__)
577 short minPos, maxPos;
578#else
579 int minPos, maxPos;
580#endif
a23fd0e1 581 HWND hWnd = GetHwnd();
42e69d6b
VZ
582 if ( hWnd )
583 {
584 ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos);
585#if defined(__WIN95__)
586 // Try to adjust the range to cope with page size > 1
587 // - a Windows API quirk
588 int pageSize = GetScrollPage(orient);
589 if ( pageSize > 1 )
590 {
591 maxPos -= (pageSize - 1);
592 }
593#endif
594 return maxPos;
595 }
596 else
597 return 0;
598}
2bda0e17 599
42e69d6b
VZ
600int wxWindow::GetScrollPage(int orient) const
601{
602 if ( orient == wxHORIZONTAL )
603 return m_xThumbSize;
604 else
605 return m_yThumbSize;
2bda0e17
KB
606}
607
42e69d6b
VZ
608#endif // WXWIN_COMPATIBILITY
609
610int wxWindow::GetScrollPos(int orient) const
2bda0e17 611{
42e69d6b
VZ
612 int wOrient;
613 if ( orient == wxHORIZONTAL )
614 wOrient = SB_HORZ;
615 else
616 wOrient = SB_VERT;
617 HWND hWnd = GetHwnd();
618 if ( hWnd )
2d0a075d 619 {
42e69d6b 620 return ::GetScrollPos(hWnd, wOrient);
cc2b7472 621 }
42e69d6b
VZ
622 else
623 return 0;
624}
2bda0e17 625
42e69d6b
VZ
626// This now returns the whole range, not just the number
627// of positions that we can scroll.
628int wxWindow::GetScrollRange(int orient) const
629{
630 int wOrient;
631 if ( orient == wxHORIZONTAL )
632 wOrient = SB_HORZ;
633 else
634 wOrient = SB_VERT;
2bda0e17 635
42e69d6b
VZ
636#if __WATCOMC__ && defined(__WINDOWS_386__)
637 short minPos, maxPos;
638#else
639 int minPos, maxPos;
640#endif
a23fd0e1 641 HWND hWnd = GetHwnd();
42e69d6b
VZ
642 if ( hWnd )
643 {
644 ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos);
645#if defined(__WIN95__)
646 // Try to adjust the range to cope with page size > 1
647 // - a Windows API quirk
648 int pageSize = GetScrollThumb(orient);
649 if ( pageSize > 1 )
650 {
651 maxPos -= (pageSize - 1);
652 }
653 // October 10th: new range concept.
654 maxPos += pageSize;
655#endif
2bda0e17 656
42e69d6b
VZ
657 return maxPos;
658 }
659 else
660 return 0;
cc2b7472 661}
2bda0e17 662
42e69d6b 663int wxWindow::GetScrollThumb(int orient) const
2bda0e17 664{
42e69d6b
VZ
665 if ( orient == wxHORIZONTAL )
666 return m_xThumbSize;
667 else
668 return m_yThumbSize;
2bda0e17
KB
669}
670
42e69d6b 671void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
2bda0e17 672{
42e69d6b
VZ
673#if defined(__WIN95__)
674 SCROLLINFO info;
675 int dir;
72fd19a1 676
42e69d6b
VZ
677 if ( orient == wxHORIZONTAL ) {
678 dir = SB_HORZ;
679 } else {
680 dir = SB_VERT;
681 }
2d0a075d 682
42e69d6b
VZ
683 info.cbSize = sizeof(SCROLLINFO);
684 info.nPage = 0;
685 info.nMin = 0;
686 info.nPos = pos;
687 info.fMask = SIF_POS;
2d0a075d 688
42e69d6b
VZ
689 HWND hWnd = GetHwnd();
690 if ( hWnd )
691 ::SetScrollInfo(hWnd, dir, &info, refresh);
692#else
693 int wOrient;
694 if ( orient == wxHORIZONTAL )
695 wOrient = SB_HORZ;
696 else
697 wOrient = SB_VERT;
81d66cf3 698
a23fd0e1 699 HWND hWnd = GetHwnd();
cc2b7472 700 if ( hWnd )
42e69d6b
VZ
701 ::SetScrollPos(hWnd, wOrient, pos, refresh);
702#endif
2bda0e17
KB
703}
704
42e69d6b
VZ
705// New function that will replace some of the above.
706void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
707 int range, bool refresh)
2bda0e17 708{
42e69d6b
VZ
709#if defined(__WIN95__)
710 int oldRange = range - thumbVisible;
2bda0e17 711
42e69d6b 712 int range1 = oldRange;
2bda0e17 713
42e69d6b
VZ
714 // Try to adjust the range to cope with page size > 1
715 // - a Windows API quirk
716 int pageSize = thumbVisible;
717 if ( pageSize > 1 && range > 0)
718 {
719 range1 += (pageSize - 1);
720 }
2bda0e17 721
42e69d6b
VZ
722 SCROLLINFO info;
723 int dir;
2bda0e17 724
42e69d6b
VZ
725 if ( orient == wxHORIZONTAL ) {
726 dir = SB_HORZ;
727 } else {
728 dir = SB_VERT;
2d0a075d 729 }
2bda0e17 730
42e69d6b
VZ
731 info.cbSize = sizeof(SCROLLINFO);
732 info.nPage = pageSize; // Have to set this, or scrollbar goes awry
733 info.nMin = 0;
734 info.nMax = range1;
735 info.nPos = pos;
736 info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
2bda0e17 737
42e69d6b
VZ
738 HWND hWnd = GetHwnd();
739 if ( hWnd )
740 ::SetScrollInfo(hWnd, dir, &info, refresh);
741#else
742 int wOrient;
743 if ( orient == wxHORIZONTAL )
744 wOrient = SB_HORZ;
745 else
746 wOrient = SB_VERT;
81d66cf3 747
42e69d6b
VZ
748 HWND hWnd = GetHwnd();
749 if ( hWnd )
81d66cf3 750 {
42e69d6b
VZ
751 ::SetScrollRange(hWnd, wOrient, 0, range, FALSE);
752 ::SetScrollPos(hWnd, wOrient, pos, refresh);
753 }
754#endif
755 if ( orient == wxHORIZONTAL ) {
756 m_xThumbSize = thumbVisible;
757 } else {
758 m_yThumbSize = thumbVisible;
81d66cf3
JS
759 }
760}
761
42e69d6b 762void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
2bda0e17 763{
42e69d6b
VZ
764 RECT rect2;
765 if ( rect )
2d0a075d 766 {
42e69d6b
VZ
767 rect2.left = rect->x;
768 rect2.top = rect->y;
769 rect2.right = rect->x + rect->width;
770 rect2.bottom = rect->y + rect->height;
2d0a075d 771 }
2bda0e17 772
42e69d6b
VZ
773 if ( rect )
774 ::ScrollWindow(GetHwnd(), dx, dy, &rect2, NULL);
775 else
776 ::ScrollWindow(GetHwnd(), dx, dy, NULL, NULL);
2bda0e17
KB
777}
778
42e69d6b
VZ
779// ---------------------------------------------------------------------------
780// subclassing
781// ---------------------------------------------------------------------------
782
783void wxWindow::SubclassWin(WXHWND hWnd)
2bda0e17 784{
42e69d6b 785 wxASSERT_MSG( !m_oldWndProc, "subclassing window twice?" );
2bda0e17 786
42e69d6b 787 wxAssociateWinWithHandle((HWND)hWnd, this);
2bda0e17 788
42e69d6b
VZ
789 m_oldWndProc = (WXFARPROC) GetWindowLong((HWND) hWnd, GWL_WNDPROC);
790 SetWindowLong((HWND) hWnd, GWL_WNDPROC, (LONG) wxWndProc);
2bda0e17
KB
791}
792
42e69d6b 793void wxWindow::UnsubclassWin()
2bda0e17 794{
42e69d6b 795 wxRemoveHandleAssociation(this);
2bda0e17 796
42e69d6b
VZ
797 // Restore old Window proc
798 if ( GetHwnd() )
799 {
800 FARPROC farProc = (FARPROC) GetWindowLong(GetHwnd(), GWL_WNDPROC);
801 if ( (m_oldWndProc != 0) && (farProc != (FARPROC) m_oldWndProc) )
802 {
803 SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG) m_oldWndProc);
804 m_oldWndProc = 0;
805 }
2bda0e17 806
42e69d6b
VZ
807 m_hWnd = 0;
808 }
2bda0e17
KB
809}
810
42e69d6b
VZ
811// Make a Windows extended style from the given wxWindows window style
812WXDWORD wxWindow::MakeExtendedStyle(long style, bool eliminateBorders)
2bda0e17 813{
42e69d6b
VZ
814 WXDWORD exStyle = 0;
815 if ( style & wxTRANSPARENT_WINDOW )
816 exStyle |= WS_EX_TRANSPARENT;
2bda0e17 817
42e69d6b 818 if ( !eliminateBorders )
2d0a075d 819 {
42e69d6b
VZ
820 if ( style & wxSUNKEN_BORDER )
821 exStyle |= WS_EX_CLIENTEDGE;
822 if ( style & wxDOUBLE_BORDER )
823 exStyle |= WS_EX_DLGMODALFRAME;
824#if defined(__WIN95__)
825 if ( style & wxRAISED_BORDER )
826 exStyle |= WS_EX_WINDOWEDGE;
827 if ( style & wxSTATIC_BORDER )
828 exStyle |= WS_EX_STATICEDGE;
829#endif
2d0a075d 830 }
42e69d6b 831 return exStyle;
2bda0e17
KB
832}
833
42e69d6b
VZ
834// Determines whether native 3D effects or CTL3D should be used,
835// applying a default border style if required, and returning an extended
836// style to pass to CreateWindowEx.
837WXDWORD wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D)
2bda0e17 838{
42e69d6b
VZ
839 // If matches certain criteria, then assume no 3D effects
840 // unless specifically requested (dealt with in MakeExtendedStyle)
841 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl)) || (m_windowStyle & wxNO_BORDER) )
2bda0e17 842 {
42e69d6b
VZ
843 *want3D = FALSE;
844 return MakeExtendedStyle(m_windowStyle, FALSE);
2bda0e17 845 }
2bda0e17 846
42e69d6b
VZ
847 // Determine whether we should be using 3D effects or not.
848 bool nativeBorder = FALSE; // by default, we don't want a Win95 effect
a02eb1d2 849
42e69d6b
VZ
850 // 1) App can specify global 3D effects
851 *want3D = wxTheApp->GetAuto3D();
2bda0e17 852
42e69d6b
VZ
853 // 2) If the parent is being drawn with user colours, or simple border specified,
854 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
855 if ( GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) || (m_windowStyle & wxSIMPLE_BORDER) )
856 *want3D = FALSE;
a23fd0e1 857
42e69d6b
VZ
858 // 3) Control can override this global setting by defining
859 // a border style, e.g. wxSUNKEN_BORDER
860 if ( m_windowStyle & wxSUNKEN_BORDER )
861 *want3D = TRUE;
2bda0e17 862
42e69d6b
VZ
863 // 4) If it's a special border, CTL3D can't cope so we want a native border
864 if ( (m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
865 (m_windowStyle & wxSTATIC_BORDER) )
2d0a075d 866 {
42e69d6b
VZ
867 *want3D = TRUE;
868 nativeBorder = TRUE;
2d0a075d 869 }
ea57084d 870
42e69d6b
VZ
871 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
872 // effects from extended style
873#if wxUSE_CTL3D
874 if ( *want3D )
875 nativeBorder = FALSE;
876#endif
a23fd0e1 877
42e69d6b 878 DWORD exStyle = MakeExtendedStyle(m_windowStyle, !nativeBorder);
2bda0e17 879
42e69d6b
VZ
880 // If we want 3D, but haven't specified a border here,
881 // apply the default border style specified.
882 // TODO what about non-Win95 WIN32? Does it have borders?
883#if defined(__WIN95__) && !wxUSE_CTL3D
884 if ( defaultBorderStyle && (*want3D) && ! ((m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER ) ||
885 (m_windowStyle & wxSTATIC_BORDER) || (m_windowStyle & wxSIMPLE_BORDER) ))
886 exStyle |= defaultBorderStyle; // WS_EX_CLIENTEDGE;
887#endif
888
889 return exStyle;
a23fd0e1 890}
2bda0e17 891
42e69d6b
VZ
892#if WXWIN_COMPATIBILITY_2
893// If nothing defined for this, try the parent.
894// E.g. we may be a button loaded from a resource, with no callback function
895// defined.
896void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
2bda0e17 897{
42e69d6b
VZ
898 if ( GetEventHandler()->ProcessEvent(event) )
899 return;
900 if ( m_parent )
901 m_parent->GetEventHandler()->OnCommand(win, event);
902}
903#endif // WXWIN_COMPATIBILITY_2
c085e333 904
42e69d6b
VZ
905#if WXWIN_COMPATIBILITY
906wxObject* wxWindow::GetChild(int number) const
907{
908 // Return a pointer to the Nth object in the Panel
909 wxNode *node = GetChildren().First();
910 int n = number;
911 while (node && n--)
912 node = node->Next();
913 if ( node )
914 {
915 wxObject *obj = (wxObject *)node->Data();
916 return(obj);
917 }
918 else
919 return NULL;
920}
921#endif // WXWIN_COMPATIBILITY
2bda0e17 922
42e69d6b
VZ
923// Setup background and foreground colours correctly
924void wxWindow::SetupColours()
925{
926 if ( GetParent() )
927 SetBackgroundColour(GetParent()->GetBackgroundColour());
928}
a23fd0e1 929
42e69d6b
VZ
930void wxWindow::OnIdle(wxIdleEvent& event)
931{
932 // Check if we need to send a LEAVE event
933 if ( m_mouseInWindow )
2d0a075d 934 {
42e69d6b
VZ
935 POINT pt;
936 ::GetCursorPos(&pt);
937 if ( ::WindowFromPoint(pt) != GetHwnd() )
938 {
939 // Generate a LEAVE event
940 m_mouseInWindow = FALSE;
2bda0e17 941
42e69d6b
VZ
942 // Unfortunately the mouse button and keyboard state may have changed
943 // by the time the OnIdle function is called, so 'state' may be
944 // meaningless.
945 int state = 0;
946 if ( ::GetKeyState(VK_SHIFT) != 0 )
947 state |= MK_SHIFT;
948 if ( ::GetKeyState(VK_CONTROL) != 0 )
949 state |= MK_CONTROL;
a23fd0e1 950
42e69d6b
VZ
951 wxMouseEvent event(wxEVT_LEAVE_WINDOW);
952 InitMouseEvent(event, pt.x, pt.y, state);
c085e333 953
42e69d6b
VZ
954 (void)GetEventHandler()->ProcessEvent(event);
955 }
956 }
c085e333 957
42e69d6b
VZ
958 UpdateWindowUI();
959}
568cb543 960
42e69d6b
VZ
961// Set this window to be the child of 'parent'.
962bool wxWindow::Reparent(wxWindow *parent)
963{
964 if ( !wxWindowBase::Reparent(parent) )
965 return FALSE;
c085e333 966
42e69d6b
VZ
967 HWND hWndChild = GetHwnd();
968 HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
a23fd0e1 969
42e69d6b 970 ::SetParent(hWndChild, hWndParent);
a23fd0e1 971
42e69d6b
VZ
972 return TRUE;
973}
a23fd0e1 974
42e69d6b
VZ
975void wxWindow::Clear()
976{
977 wxClientDC dc(this);
978 wxBrush brush(GetBackgroundColour(), wxSOLID);
979 dc.SetBackground(brush);
980 dc.Clear();
981}
a23fd0e1 982
42e69d6b
VZ
983void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
984{
985 HWND hWnd = GetHwnd();
986 if ( hWnd )
987 {
988 if ( rect )
989 {
990 RECT mswRect;
991 mswRect.left = rect->x;
992 mswRect.top = rect->y;
993 mswRect.right = rect->x + rect->width;
994 mswRect.bottom = rect->y + rect->height;
a23fd0e1 995
42e69d6b
VZ
996 ::InvalidateRect(hWnd, &mswRect, eraseBack);
997 }
998 else
999 ::InvalidateRect(hWnd, NULL, eraseBack);
1000 }
1001}
a23fd0e1 1002
42e69d6b
VZ
1003// ---------------------------------------------------------------------------
1004// drag and drop
1005// ---------------------------------------------------------------------------
a23fd0e1 1006
42e69d6b 1007#if wxUSE_DRAG_AND_DROP
a23fd0e1 1008
42e69d6b
VZ
1009void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
1010{
1011 if ( m_dropTarget != 0 ) {
1012 m_dropTarget->Revoke(m_hWnd);
1013 delete m_dropTarget;
1014 }
a23fd0e1 1015
42e69d6b
VZ
1016 m_dropTarget = pDropTarget;
1017 if ( m_dropTarget != 0 )
1018 m_dropTarget->Register(m_hWnd);
1019}
a23fd0e1 1020
42e69d6b 1021#endif // wxUSE_DRAG_AND_DROP
2a47d3c1 1022
42e69d6b
VZ
1023// old style file-manager drag&drop support: we retain the old-style
1024// DragAcceptFiles in parallel with SetDropTarget.
1025void wxWindow::DragAcceptFiles(bool accept)
1026{
1027 HWND hWnd = GetHwnd();
1028 if ( hWnd )
1029 ::DragAcceptFiles(hWnd, (BOOL)accept);
1030}
a23fd0e1 1031
42e69d6b
VZ
1032// ----------------------------------------------------------------------------
1033// tooltips
1034// ----------------------------------------------------------------------------
dbda9e86 1035
42e69d6b 1036#if wxUSE_TOOLTIPS
2d0a075d 1037
42e69d6b
VZ
1038void wxWindow::DoSetToolTip(wxToolTip *tooltip)
1039{
1040 wxWindowBase::DoSetToolTip(tooltip);
839b865d 1041
42e69d6b
VZ
1042 if ( m_tooltip )
1043 m_tooltip->SetWindow(this);
1044}
9a05fd8d 1045
42e69d6b 1046#endif // wxUSE_TOOLTIPS
9a05fd8d 1047
42e69d6b
VZ
1048// ---------------------------------------------------------------------------
1049// moving and resizing
1050// ---------------------------------------------------------------------------
839b865d 1051
42e69d6b
VZ
1052// Get total size
1053void wxWindow::DoGetSize(int *x, int *y) const
1054{
1055 HWND hWnd = GetHwnd();
1056 RECT rect;
1057 GetWindowRect(hWnd, &rect);
1058
1059 if ( x )
1060 *x = rect.right - rect.left;
1061 if ( y )
1062 *y = rect.bottom - rect.top;
1063}
1064
1065void wxWindow::DoGetPosition(int *x, int *y) const
1066{
1067 HWND hWnd = GetHwnd();
1068 HWND hParentWnd = 0;
1069 if ( GetParent() )
1070 hParentWnd = (HWND) GetParent()->GetHWND();
1071
1072 RECT rect;
1073 GetWindowRect(hWnd, &rect);
1074
1075 // Since we now have the absolute screen coords, if there's a parent we
1076 // must subtract its top left corner
1077 POINT point;
1078 point.x = rect.left;
1079 point.y = rect.top;
1080 if ( hParentWnd )
1081 {
1082 ::ScreenToClient(hParentWnd, &point);
1083 }
1084
1085 // We may be faking the client origin. So a window that's really at (0,
1086 // 30) may appear (to wxWin apps) to be at (0, 0).
1087 if ( GetParent() )
1088 {
1089 wxPoint pt(GetParent()->GetClientAreaOrigin());
1090 point.x -= pt.x;
1091 point.y -= pt.y;
1092 }
1093
1094 if ( x )
1095 *x = point.x;
1096 if ( y )
1097 *y = point.y;
1098}
54bdd8b0 1099
dabc0cd5 1100void wxWindow::DoScreenToClient(int *x, int *y) const
42e69d6b
VZ
1101{
1102 POINT pt;
1103 if ( x )
1104 pt.x = *x;
1105 if ( y )
1106 pt.y = *y;
54bdd8b0 1107
42e69d6b
VZ
1108 HWND hWnd = GetHwnd();
1109 ::ScreenToClient(hWnd, &pt);
a23fd0e1 1110
42e69d6b
VZ
1111 if ( x )
1112 *x = pt.x;
1113 if ( y )
1114 *y = pt.y;
1115}
a23fd0e1 1116
dabc0cd5 1117void wxWindow::DoClientToScreen(int *x, int *y) const
42e69d6b
VZ
1118{
1119 POINT pt;
1120 if ( x )
1121 pt.x = *x;
1122 if ( y )
1123 pt.y = *y;
54bdd8b0 1124
42e69d6b
VZ
1125 HWND hWnd = GetHwnd();
1126 ::ClientToScreen(hWnd, &pt);
a23fd0e1 1127
42e69d6b
VZ
1128 if ( x )
1129 *x = pt.x;
1130 if ( y )
1131 *y = pt.y;
1132}
a23fd0e1 1133
42e69d6b
VZ
1134// Get size *available for subwindows* i.e. excluding menu bar etc.
1135void wxWindow::DoGetClientSize(int *x, int *y) const
1136{
1137 HWND hWnd = GetHwnd();
1138 RECT rect;
1139 ::GetClientRect(hWnd, &rect);
1140 if ( x )
1141 *x = rect.right;
1142 if ( y )
1143 *y = rect.bottom;
1144}
a23fd0e1 1145
42e69d6b
VZ
1146void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1147{
1148 int currentX, currentY;
1149 GetPosition(&currentX, &currentY);
1150 int currentW,currentH;
1151 GetSize(&currentW, &currentH);
a23fd0e1 1152
42e69d6b
VZ
1153 if ( x == currentX && y == currentY && width == currentW && height == currentH )
1154 return;
a23fd0e1 1155
42e69d6b
VZ
1156 int actualWidth = width;
1157 int actualHeight = height;
1158 int actualX = x;
1159 int actualY = y;
1160 if ( x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1161 actualX = currentX;
1162 if ( y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1163 actualY = currentY;
a23fd0e1 1164
42e69d6b 1165 AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
a23fd0e1 1166
42e69d6b
VZ
1167 if ( width == -1 )
1168 actualWidth = currentW;
1169 if ( height == -1 )
1170 actualHeight = currentH;
a23fd0e1 1171
42e69d6b
VZ
1172 HWND hWnd = GetHwnd();
1173 if ( hWnd )
1174 MoveWindow(hWnd, actualX, actualY, actualWidth, actualHeight, (BOOL)TRUE);
1175}
a23fd0e1 1176
42e69d6b
VZ
1177void wxWindow::DoSetClientSize(int width, int height)
1178{
1179 wxWindow *parent = GetParent();
1180 HWND hWnd = GetHwnd();
1181 HWND hParentWnd = (HWND) 0;
1182 if ( parent )
1183 hParentWnd = (HWND) parent->GetHWND();
2bda0e17 1184
42e69d6b
VZ
1185 RECT rect;
1186 ::GetClientRect(hWnd, &rect);
a23fd0e1 1187
42e69d6b
VZ
1188 RECT rect2;
1189 GetWindowRect(hWnd, &rect2);
a23fd0e1 1190
42e69d6b
VZ
1191 // Find the difference between the entire window (title bar and all)
1192 // and the client area; add this to the new client size to move the
1193 // window
1194 int actual_width = rect2.right - rect2.left - rect.right + width;
1195 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
a23fd0e1 1196
42e69d6b
VZ
1197 // If there's a parent, must subtract the parent's top left corner
1198 // since MoveWindow moves relative to the parent
a23fd0e1 1199
42e69d6b
VZ
1200 POINT point;
1201 point.x = rect2.left;
1202 point.y = rect2.top;
1203 if ( parent )
1204 {
1205 ::ScreenToClient(hParentWnd, &point);
1206 }
387a3b02 1207
42e69d6b 1208 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
a23fd0e1 1209
42e69d6b
VZ
1210 wxSizeEvent event(wxSize(width, height), m_windowId);
1211 event.SetEventObject(this);
1212 GetEventHandler()->ProcessEvent(event);
1213}
a23fd0e1 1214
42e69d6b
VZ
1215// For implementation purposes - sometimes decorations make the client area
1216// smaller
1217wxPoint wxWindow::GetClientAreaOrigin() const
1218{
1219 return wxPoint(0, 0);
1220}
a23fd0e1 1221
42e69d6b
VZ
1222// Makes an adjustment to the window position (for example, a frame that has
1223// a toolbar that it manages itself).
1224void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
1225{
1226 if ( ((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent() )
1227 {
1228 wxPoint pt(GetParent()->GetClientAreaOrigin());
1229 x += pt.x; y += pt.y;
1230 }
1231}
a23fd0e1 1232
42e69d6b
VZ
1233// ---------------------------------------------------------------------------
1234// text metrics
1235// ---------------------------------------------------------------------------
a23fd0e1 1236
42e69d6b
VZ
1237int wxWindow::GetCharHeight() const
1238{
1239 TEXTMETRIC lpTextMetric;
1240 HWND hWnd = GetHwnd();
1241 HDC dc = ::GetDC(hWnd);
a23fd0e1 1242
42e69d6b
VZ
1243 GetTextMetrics(dc, &lpTextMetric);
1244 ::ReleaseDC(hWnd, dc);
3eddf563 1245
42e69d6b
VZ
1246 return lpTextMetric.tmHeight;
1247}
3eddf563 1248
42e69d6b
VZ
1249int wxWindow::GetCharWidth() const
1250{
1251 TEXTMETRIC lpTextMetric;
1252 HWND hWnd = GetHwnd();
1253 HDC dc = ::GetDC(hWnd);
3eddf563 1254
42e69d6b
VZ
1255 GetTextMetrics(dc, &lpTextMetric);
1256 ::ReleaseDC(hWnd, dc);
3eddf563 1257
42e69d6b
VZ
1258 return lpTextMetric.tmAveCharWidth;
1259}
f4621a09 1260
42e69d6b
VZ
1261void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
1262 int *descent, int *externalLeading,
1263 const wxFont *theFont) const
1264{
1265 const wxFont *fontToUse = theFont;
1266 if ( !fontToUse )
1267 fontToUse = &m_font;
634903fd 1268
42e69d6b
VZ
1269 HWND hWnd = GetHwnd();
1270 HDC dc = ::GetDC(hWnd);
634903fd 1271
42e69d6b
VZ
1272 HFONT fnt = 0;
1273 HFONT hfontOld = 0;
1274 if ( fontToUse && fontToUse->Ok() )
1275 {
1276 fnt = (HFONT)((wxFont *)fontToUse)->GetResourceHandle(); // const_cast
1277 if ( fnt )
1278 hfontOld = (HFONT)SelectObject(dc,fnt);
2bda0e17 1279 }
341c92a8 1280
42e69d6b
VZ
1281 SIZE sizeRect;
1282 TEXTMETRIC tm;
1283 GetTextExtentPoint(dc, (const char *)string, (int)string.Length(), &sizeRect);
1284 GetTextMetrics(dc, &tm);
1285
1286 if ( fontToUse && fnt && hfontOld )
1287 SelectObject(dc, hfontOld);
1288
1289 ReleaseDC(hWnd, dc);
1290
1291 if ( x ) *x = sizeRect.cx;
1292 if ( y ) *y = sizeRect.cy;
1293 if ( descent ) *descent = tm.tmDescent;
1294 if ( externalLeading ) *externalLeading = tm.tmExternalLeading;
2bda0e17
KB
1295}
1296
789295bf 1297#if wxUSE_CARET
42e69d6b
VZ
1298// ---------------------------------------------------------------------------
1299// Caret manipulation
1300// ---------------------------------------------------------------------------
1301
1302void wxWindow::CreateCaret(int w, int h)
2bda0e17 1303{
789295bf 1304 SetCaret(new wxCaret(this, w, h));
2bda0e17
KB
1305}
1306
42e69d6b 1307void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
2bda0e17 1308{
789295bf 1309 wxFAIL_MSG("not implemented");
2bda0e17
KB
1310}
1311
42e69d6b 1312void wxWindow::ShowCaret(bool show)
2bda0e17 1313{
789295bf
VZ
1314 wxCHECK_RET( m_caret, "no caret to show" );
1315
1316 m_caret->Show(show);
2bda0e17
KB
1317}
1318
42e69d6b 1319void wxWindow::DestroyCaret()
2bda0e17 1320{
789295bf 1321 SetCaret(NULL);
2bda0e17
KB
1322}
1323
42e69d6b 1324void wxWindow::SetCaretPos(int x, int y)
2bda0e17 1325{
789295bf
VZ
1326 wxCHECK_RET( m_caret, "no caret to move" );
1327
1328 m_caret->Move(x, y);
2bda0e17
KB
1329}
1330
42e69d6b 1331void wxWindow::GetCaretPos(int *x, int *y) const
2d0a075d 1332{
789295bf
VZ
1333 wxCHECK_RET( m_caret, "no caret to get position of" );
1334
1335 m_caret->GetPosition(x, y);
42e69d6b 1336}
789295bf 1337#endif // wxUSE_CARET
2bda0e17 1338
42e69d6b
VZ
1339// ===========================================================================
1340// pre/post message processing
1341// ===========================================================================
2bda0e17 1342
42e69d6b
VZ
1343long wxWindow::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
1344{
1345 if ( m_oldWndProc )
1346 return ::CallWindowProc(CASTWNDPROC m_oldWndProc, GetHwnd(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
1347 else
1348 return ::DefWindowProc(GetHwnd(), nMsg, wParam, lParam);
1349}
2bda0e17 1350
42e69d6b
VZ
1351bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
1352{
1353 if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) )
2d0a075d 1354 {
42e69d6b
VZ
1355 // intercept dialog navigation keys
1356 MSG *msg = (MSG *)pMsg;
1357 bool bProcess = TRUE;
1358 if ( msg->message != WM_KEYDOWN )
1359 bProcess = FALSE;
c085e333 1360
42e69d6b
VZ
1361 if ( bProcess && (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN )
1362 bProcess = FALSE;
a23fd0e1 1363
42e69d6b
VZ
1364 if ( bProcess )
1365 {
1366 bool bCtrlDown = (::GetKeyState(VK_CONTROL) & 0x100) != 0;
a23fd0e1 1367
42e69d6b
VZ
1368 // WM_GETDLGCODE: ask the control if it wants the key for itself,
1369 // don't process it if it's the case (except for Ctrl-Tab/Enter
1370 // combinations which are always processed)
1371 LONG lDlgCode = 0;
1372 if ( !bCtrlDown )
1373 {
1374 lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0);
1375 }
a23fd0e1 1376
42e69d6b
VZ
1377 bool bForward = TRUE,
1378 bWindowChange = FALSE;
a23fd0e1 1379
9145664b 1380 switch ( msg->wParam )
42e69d6b
VZ
1381 {
1382 case VK_TAB:
1383 if ( lDlgCode & DLGC_WANTTAB ) {
1384 bProcess = FALSE;
1385 }
1386 else {
1387 // Ctrl-Tab cycles thru notebook pages
1388 bWindowChange = bCtrlDown;
1389 bForward = !(::GetKeyState(VK_SHIFT) & 0x100);
1390 }
1391 break;
a23fd0e1 1392
42e69d6b
VZ
1393 case VK_UP:
1394 case VK_LEFT:
1395 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
1396 bProcess = FALSE;
1397 else
1398 bForward = FALSE;
1399 break;
a02eb1d2 1400
42e69d6b
VZ
1401 case VK_DOWN:
1402 case VK_RIGHT:
1403 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
1404 bProcess = FALSE;
1405 break;
2bda0e17 1406
42e69d6b
VZ
1407 case VK_RETURN:
1408 {
1409 if ( lDlgCode & DLGC_WANTMESSAGE )
1410 {
1411 // control wants to process Enter itself, don't
1412 // call IsDialogMessage() which would interpret
1413 // it
1414 return FALSE;
1415 }
1416#ifndef __WIN16__
1417 wxButton *btnDefault = GetDefaultItem();
1418 if ( btnDefault && !bCtrlDown )
1419 {
1420 // if there is a default button, Enter should
1421 // press it
1422 (void)::SendMessage((HWND)btnDefault->GetHWND(),
1423 BM_CLICK, 0, 0);
1424 return TRUE;
1425 }
1426 // else: but if there is not it makes sense to make it
1427 // work like a TAB - and that's what we do.
1428 // Note that Ctrl-Enter always works this way.
1429#endif
1430 }
1431 break;
2bda0e17 1432
42e69d6b
VZ
1433 default:
1434 bProcess = FALSE;
1435 }
2bda0e17 1436
42e69d6b
VZ
1437 if ( bProcess )
1438 {
1439 wxNavigationKeyEvent event;
1440 event.SetDirection(bForward);
1441 event.SetWindowChange(bWindowChange);
1442 event.SetEventObject(this);
3572173c 1443
42e69d6b
VZ
1444 if ( GetEventHandler()->ProcessEvent(event) )
1445 return TRUE;
1446 }
1447 }
a23fd0e1 1448
42e69d6b
VZ
1449 if ( ::IsDialogMessage(GetHwnd(), msg) )
1450 return TRUE;
1451 }
a23fd0e1 1452
42e69d6b
VZ
1453#if wxUSE_TOOLTIPS
1454 if ( m_tooltip )
387a3b02 1455 {
42e69d6b
VZ
1456 // relay mouse move events to the tooltip control
1457 MSG *msg = (MSG *)pMsg;
1458 if ( msg->message == WM_MOUSEMOVE )
1459 m_tooltip->RelayEvent(pMsg);
387a3b02 1460 }
42e69d6b 1461#endif // wxUSE_TOOLTIPS
a23fd0e1 1462
42e69d6b 1463 return FALSE;
387a3b02
JS
1464}
1465
42e69d6b 1466bool wxWindow::MSWTranslateMessage(WXMSG* pMsg)
387a3b02 1467{
42e69d6b
VZ
1468 return m_acceleratorTable.Ok() &&
1469 ::TranslateAccelerator(GetHwnd(),
1470 GetTableHaccel(m_acceleratorTable),
1471 (MSG *)pMsg);
387a3b02
JS
1472}
1473
42e69d6b
VZ
1474// ---------------------------------------------------------------------------
1475// message params unpackers (different for Win16 and Win32)
1476// ---------------------------------------------------------------------------
2bda0e17 1477
42e69d6b 1478#ifdef __WIN32__
c085e333 1479
42e69d6b
VZ
1480void wxWindow::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
1481 WORD *id, WXHWND *hwnd, WORD *cmd)
1482{
1483 *id = LOWORD(wParam);
1484 *hwnd = (WXHWND)lParam;
1485 *cmd = HIWORD(wParam);
2bda0e17
KB
1486}
1487
42e69d6b
VZ
1488void wxWindow::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
1489 WXWORD *state, WXWORD *minimized, WXHWND *hwnd)
2bda0e17 1490{
42e69d6b
VZ
1491 *state = LOWORD(wParam);
1492 *minimized = HIWORD(wParam);
1493 *hwnd = (WXHWND)lParam;
2bda0e17
KB
1494}
1495
42e69d6b
VZ
1496void wxWindow::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
1497 WXWORD *code, WXWORD *pos, WXHWND *hwnd)
2bda0e17 1498{
42e69d6b
VZ
1499 *code = LOWORD(wParam);
1500 *pos = HIWORD(wParam);
1501 *hwnd = (WXHWND)lParam;
1502}
a23fd0e1 1503
42e69d6b
VZ
1504void wxWindow::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
1505 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd)
1506{
1507 *nCtlColor = CTLCOLOR_BTN;
1508 *hwnd = (WXHWND)lParam;
1509 *hdc = (WXHDC)wParam;
2bda0e17
KB
1510}
1511
42e69d6b
VZ
1512void wxWindow::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
1513 WXWORD *item, WXWORD *flags, WXHMENU *hmenu)
2bda0e17 1514{
42e69d6b
VZ
1515 *item = (WXWORD)wParam;
1516 *flags = HIWORD(wParam);
1517 *hmenu = (WXHMENU)lParam;
1518}
c085e333 1519
42e69d6b 1520#else // Win16
341c92a8 1521
42e69d6b
VZ
1522void wxWindow::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
1523 WXWORD *id, WXHWND *hwnd, WXWORD *cmd)
1524{
1525 *id = (WXWORD)wParam;
1526 *hwnd = (WXHWND)LOWORD(lParam);
1527 *cmd = HIWORD(lParam);
2bda0e17
KB
1528}
1529
42e69d6b
VZ
1530void wxWindow::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
1531 WXWORD *state, WXWORD *minimized, WXHWND *hwnd)
2bda0e17 1532{
42e69d6b
VZ
1533 *state = (WXWORD)wParam;
1534 *minimized = LOWORD(lParam);
1535 *hwnd = (WXHWND)HIWORD(lParam);
2bda0e17
KB
1536}
1537
42e69d6b
VZ
1538void wxWindow::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
1539 WXWORD *code, WXWORD *pos, WXHWND *hwnd)
2bda0e17 1540{
42e69d6b
VZ
1541 *code = (WXWORD)wParam;
1542 *pos = LOWORD(lParam);
1543 *hwnd = (WXHWND)HIWORD(lParam);
1544}
c085e333 1545
42e69d6b
VZ
1546void wxWindow::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
1547 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd)
1548{
1549 *control = (WXHWND)LOWORD(lParam);
1550 *nCtlColor = (int)HIWORD(lParam);
1551 *hdc = (WXHDC)wParam;
2bda0e17
KB
1552}
1553
42e69d6b
VZ
1554void wxWindow::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
1555 WXWORD *item, WXWORD *flags, WXHMENU *hmenu)
2bda0e17 1556{
42e69d6b
VZ
1557 *item = (WXWORD)wParam;
1558 *flags = LOWORD(lParam);
1559 *hmenu = (WXHMENU)HIWORD(lParam);
1560}
2d0a075d 1561
42e69d6b 1562#endif // Win32/16
c085e333 1563
42e69d6b
VZ
1564// ---------------------------------------------------------------------------
1565// Main wxWindows window proc and the window proc for wxWindow
1566// ---------------------------------------------------------------------------
2bda0e17 1567
42e69d6b
VZ
1568// Hook for new window just as it's being created, when the window isn't yet
1569// associated with the handle
1570wxWindow *wxWndHook = NULL;
1571
1572// Main window proc
1573LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
2bda0e17 1574{
42e69d6b
VZ
1575 // trace all messages - useful for the debugging
1576#ifdef __WXDEBUG__
1577 wxLogTrace(wxTraceMessages, "Processing %s(wParam=%8lx, lParam=%8lx)",
1578 wxGetMessageName(message), wParam, lParam);
1579#endif // __WXDEBUG__
2bda0e17 1580
42e69d6b 1581 wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd);
c085e333 1582
42e69d6b
VZ
1583 // when we get the first message for the HWND we just created, we associate
1584 // it with wxWindow stored in wxWndHook
1585 if ( !wnd && wxWndHook )
2d0a075d 1586 {
42e69d6b
VZ
1587 wxAssociateWinWithHandle(hWnd, wxWndHook);
1588 wnd = wxWndHook;
1589 wxWndHook = NULL;
1590 wnd->SetHWND((WXHWND)hWnd);
2d0a075d 1591 }
2bda0e17 1592
42e69d6b 1593 LRESULT rc;
a23fd0e1 1594
42e69d6b
VZ
1595 // Stop right here if we don't have a valid handle in our wxWindow object.
1596 if ( wnd && !wnd->GetHWND() )
2d0a075d 1597 {
42e69d6b
VZ
1598 // FIXME: why do we do this?
1599 wnd->SetHWND((WXHWND) hWnd);
1600 rc = wnd->MSWDefWindowProc(message, wParam, lParam );
1601 wnd->SetHWND(0);
a23fd0e1
VZ
1602 }
1603 else
1604 {
42e69d6b
VZ
1605 if ( wnd )
1606 rc = wnd->MSWWindowProc(message, wParam, lParam);
1607 else
1608 rc = DefWindowProc( hWnd, message, wParam, lParam );
2d0a075d 1609 }
2bda0e17 1610
42e69d6b 1611 return rc;
f7bd2698
JS
1612}
1613
42e69d6b 1614long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
f7bd2698 1615{
42e69d6b
VZ
1616 // did we process the message?
1617 bool processed = FALSE;
f7bd2698 1618
42e69d6b
VZ
1619 // the return value
1620 union
2bda0e17 1621 {
42e69d6b
VZ
1622 bool allow;
1623 long result;
1624 WXHICON hIcon;
1625 WXHBRUSH hBrush;
1626 } rc;
2bda0e17 1627
42e69d6b
VZ
1628 // for most messages we should return 0 when we do process the message
1629 rc.result = 0;
2bda0e17 1630
42e69d6b 1631 switch ( message )
39136494 1632 {
42e69d6b
VZ
1633 case WM_CREATE:
1634 {
1635 bool mayCreate;
1636 processed = HandleCreate((WXLPCREATESTRUCT)lParam, &mayCreate);
1637 if ( processed )
1638 {
1639 // return 0 to allow window creation
1640 rc.result = mayCreate ? 0 : -1;
1641 }
1642 }
1643 break;
47cbd6da 1644
42e69d6b
VZ
1645 case WM_DESTROY:
1646 processed = HandleDestroy();
1647 break;
1648
1649 case WM_MOVE:
1650 processed = HandleMove(LOWORD(lParam), HIWORD(lParam));
1651 break;
47cbd6da 1652
42e69d6b
VZ
1653 case WM_SIZE:
1654 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
1655 break;
47cbd6da 1656
42e69d6b 1657 case WM_ACTIVATE:
341c92a8 1658 {
42e69d6b
VZ
1659 WXWORD state, minimized;
1660 WXHWND hwnd;
1661 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
1662
1663 processed = HandleActivate(state, minimized != 0, (WXHWND)hwnd);
341c92a8 1664 }
42e69d6b 1665 break;
341c92a8 1666
42e69d6b
VZ
1667 case WM_SETFOCUS:
1668 processed = HandleSetFocus((WXHWND)(HWND)wParam);
1669 break;
47cbd6da 1670
42e69d6b
VZ
1671 case WM_KILLFOCUS:
1672 processed = HandleKillFocus((WXHWND)(HWND)wParam);
1673 break;
47cbd6da 1674
42e69d6b
VZ
1675 case WM_PAINT:
1676 processed = HandlePaint();
1677 break;
47cbd6da 1678
42e69d6b
VZ
1679 case WM_CLOSE:
1680 // don't let the DefWindowProc() destroy our window - we'll do it
1681 // ourselves in ~wxWindow
1682 processed = TRUE;
1683 rc.result = TRUE;
1684 break;
47cbd6da 1685
42e69d6b
VZ
1686 case WM_SHOWWINDOW:
1687 processed = HandleShow(wParam != 0, (int)lParam);
1688 break;
3a19e16d 1689
42e69d6b
VZ
1690 case WM_MOUSEMOVE:
1691 case WM_LBUTTONDOWN:
1692 case WM_LBUTTONUP:
1693 case WM_LBUTTONDBLCLK:
1694 case WM_RBUTTONDOWN:
1695 case WM_RBUTTONUP:
1696 case WM_RBUTTONDBLCLK:
1697 case WM_MBUTTONDOWN:
1698 case WM_MBUTTONUP:
1699 case WM_MBUTTONDBLCLK:
1700 {
1701 int x = LOWORD(lParam);
1702 int y = HIWORD(lParam);
1703
1704 processed = HandleMouseEvent(message, x, y, wParam);
2d0a075d 1705 }
42e69d6b 1706 break;
47cbd6da 1707
42e69d6b
VZ
1708 case MM_JOY1MOVE:
1709 case MM_JOY2MOVE:
1710 case MM_JOY1ZMOVE:
1711 case MM_JOY2ZMOVE:
1712 case MM_JOY1BUTTONDOWN:
1713 case MM_JOY2BUTTONDOWN:
1714 case MM_JOY1BUTTONUP:
1715 case MM_JOY2BUTTONUP:
341c92a8 1716 {
42e69d6b
VZ
1717 int x = LOWORD(lParam);
1718 int y = HIWORD(lParam);
47cbd6da 1719
42e69d6b 1720 processed = HandleJoystickEvent(message, x, y, wParam);
341c92a8 1721 }
42e69d6b 1722 break;
47cbd6da 1723
42e69d6b
VZ
1724 case WM_SYSCOMMAND:
1725 processed = HandleSysCommand(wParam, lParam);
1726 break;
2a47d3c1 1727
42e69d6b
VZ
1728 case WM_COMMAND:
1729 {
1730 WORD id, cmd;
1731 WXHWND hwnd;
1732 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
47cbd6da 1733
42e69d6b
VZ
1734 processed = HandleCommand(id, cmd, hwnd);
1735 }
1736 break;
7d532b0c 1737
42e69d6b
VZ
1738#ifdef __WIN95__
1739 case WM_NOTIFY:
1740 processed = HandleNotify((int)wParam, lParam, &rc.result);
1741 break;
1742#endif // Win95
2bda0e17 1743
42e69d6b
VZ
1744 // for these messages we must return TRUE if process the message
1745 case WM_DRAWITEM:
1746 case WM_MEASUREITEM:
1747 {
1748 int idCtrl = (UINT)wParam;
1749 if ( message == WM_DRAWITEM )
1750 {
1751 processed = MSWOnDrawItem(idCtrl,
1752 (WXDRAWITEMSTRUCT *)lParam);
1753 }
1754 else
1755 {
1756 processed = MSWOnMeasureItem(idCtrl,
1757 (WXMEASUREITEMSTRUCT *)lParam);
1758 }
57a7b7c1 1759
42e69d6b
VZ
1760 if ( processed )
1761 rc.result = TRUE;
1762 }
1763 break;
1764
1765 case WM_KEYDOWN:
1766 // If this has been processed by an event handler,
1767 // return 0 now (we've handled it).
1768 if ( HandleKeyDown((WORD) wParam, lParam) )
2d0a075d 1769 {
42e69d6b
VZ
1770 processed = TRUE;
1771
2d0a075d
JS
1772 break;
1773 }
81d66cf3 1774
42e69d6b
VZ
1775 // we consider these message "not interesting" to OnChar
1776 if ( wParam == VK_SHIFT || wParam == VK_CONTROL )
1777 {
1778 processed = TRUE;
81d66cf3 1779
42e69d6b
VZ
1780 break;
1781 }
debe6624 1782
42e69d6b
VZ
1783 switch ( wParam )
1784 {
1785 // avoid duplicate messages to OnChar for these ASCII keys: they
1786 // will be translated by TranslateMessage() and received in WM_CHAR
1787 case VK_ESCAPE:
1788 case VK_SPACE:
1789 case VK_RETURN:
1790 case VK_BACK:
1791 case VK_TAB:
1792 processed = TRUE;
2bda0e17 1793
42e69d6b 1794 break;
2bda0e17 1795
42e69d6b
VZ
1796#ifdef VK_APPS
1797 // special case of VK_APPS: treat it the same as right mouse
1798 // click because both usually pop up a context menu
1799 case VK_APPS:
1800 {
1801 // construct the key mask
1802 WPARAM fwKeys = MK_RBUTTON;
1803 if ( (::GetKeyState(VK_CONTROL) & 0x100) != 0 )
1804 fwKeys |= MK_CONTROL;
1805 if ( (::GetKeyState(VK_SHIFT) & 0x100) != 0 )
1806 fwKeys |= MK_SHIFT;
2bda0e17 1807
42e69d6b
VZ
1808 // simulate right mouse button click
1809 DWORD dwPos = ::GetMessagePos();
1810 int x = GET_X_LPARAM(dwPos),
1811 y = GET_Y_LPARAM(dwPos);
debe6624 1812
42e69d6b
VZ
1813 ScreenToClient(&x, &y);
1814 processed = HandleMouseEvent(WM_RBUTTONDOWN, x, y, fwKeys);
1815 }
1816 break;
1817#endif // VK_APPS
2bda0e17 1818
42e69d6b
VZ
1819 case VK_LEFT:
1820 case VK_RIGHT:
1821 case VK_DOWN:
1822 case VK_UP:
1823 default:
1824 processed = HandleChar((WORD)wParam, lParam);
1825 }
1826 break;
2bda0e17 1827
42e69d6b
VZ
1828 case WM_KEYUP:
1829 processed = HandleKeyUp((WORD) wParam, lParam);
1830 break;
debe6624 1831
42e69d6b
VZ
1832 case WM_CHAR: // Always an ASCII character
1833 processed = HandleChar((WORD)wParam, lParam, TRUE);
1834 break;
2bda0e17 1835
42e69d6b
VZ
1836 case WM_HSCROLL:
1837 case WM_VSCROLL:
a23fd0e1 1838 {
42e69d6b
VZ
1839 WXWORD code, pos;
1840 WXHWND hwnd;
1841 UnpackScroll(wParam, lParam, &code, &pos, &hwnd);
2bda0e17 1842
42e69d6b
VZ
1843 processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL
1844 : wxVERTICAL,
1845 code, pos, hwnd);
a23fd0e1 1846 }
42e69d6b 1847 break;
a23fd0e1 1848
42e69d6b
VZ
1849 // CTLCOLOR messages are sent by children to query the parent for their
1850 // colors
1851#ifdef __WIN32__
1852 case WM_CTLCOLORMSGBOX:
1853 case WM_CTLCOLOREDIT:
1854 case WM_CTLCOLORLISTBOX:
1855 case WM_CTLCOLORBTN:
1856 case WM_CTLCOLORDLG:
1857 case WM_CTLCOLORSCROLLBAR:
1858 case WM_CTLCOLORSTATIC:
1859#else // Win16
1860 case WM_CTLCOLOR:
1861#endif // Win32/16
a23fd0e1 1862 {
42e69d6b
VZ
1863 WXWORD nCtlColor;
1864 WXHDC hdc;
1865 WXHWND hwnd;
1866 UnpackCtlColor(wParam, lParam, &nCtlColor, &hdc, &hwnd);
1867
1868 processed = HandleCtlColor(&rc.hBrush,
1869 (WXHDC)hdc,
1870 (WXHWND)hwnd,
1871 nCtlColor,
1872 message,
1873 wParam,
1874 lParam);
a23fd0e1 1875 }
42e69d6b 1876 break;
debe6624 1877
42e69d6b
VZ
1878 // the return value for this message is ignored
1879 case WM_SYSCOLORCHANGE:
1880 processed = HandleSysColorChange();
1881 break;
2bda0e17 1882
42e69d6b
VZ
1883 case WM_PALETTECHANGED:
1884 processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
1885 break;
2bda0e17 1886
42e69d6b
VZ
1887 case WM_QUERYNEWPALETTE:
1888 processed = HandleQueryNewPalette();
1889 break;
2bda0e17 1890
42e69d6b
VZ
1891 case WM_ERASEBKGND:
1892 processed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
1893 if ( processed )
1894 {
1895 // we processed the message, i.e. erased the background
1896 rc.result = TRUE;
1897 }
1898 break;
debe6624 1899
42e69d6b
VZ
1900 case WM_DROPFILES:
1901 processed = HandleDropFiles(wParam);
1902 break;
2bda0e17 1903
42e69d6b
VZ
1904 case WM_INITDIALOG:
1905 processed = HandleInitDialog((WXHWND)(HWND)wParam);
a23fd0e1 1906
42e69d6b
VZ
1907 if ( processed )
1908 {
1909 // we never set focus from here
1910 rc.result = FALSE;
1911 }
1912 break;
a23fd0e1 1913
42e69d6b
VZ
1914 case WM_QUERYENDSESSION:
1915 processed = HandleQueryEndSession(lParam, &rc.allow);
1916 break;
2bda0e17 1917
42e69d6b
VZ
1918 case WM_ENDSESSION:
1919 processed = HandleEndSession(wParam != 0, lParam);
1920 break;
2bda0e17 1921
42e69d6b
VZ
1922 case WM_GETMINMAXINFO:
1923 processed = HandleGetMinMaxInfo((LPMINMAXINFO)lParam);
1924 break;
debe6624 1925
42e69d6b
VZ
1926 case WM_SETCURSOR:
1927 processed = HandleSetCursor((WXHWND)(HWND)wParam,
1928 LOWORD(lParam), // hit test
1929 HIWORD(lParam)); // mouse msg
1930
1931 if ( processed )
1932 {
1933 // returning TRUE stops the DefWindowProc() from further
1934 // processing this message - exactly what we need because we've
1935 // just set the cursor.
1936 rc.result = TRUE;
1937 }
1938 break;
a23fd0e1 1939 }
2d0a075d 1940
42e69d6b 1941 if ( !processed )
2d0a075d 1942 {
42e69d6b
VZ
1943#ifdef __WXDEBUG__
1944 wxLogTrace(wxTraceMessages, "Forwarding %s to DefWindowProc.",
1945 wxGetMessageName(message));
1946#endif // __WXDEBUG__
1947 rc.result = MSWDefWindowProc(message, wParam, lParam);
a23fd0e1 1948 }
2bda0e17 1949
42e69d6b 1950 return rc.result;
2bda0e17
KB
1951}
1952
42e69d6b
VZ
1953// Dialog window proc
1954LONG APIENTRY _EXPORT
1955wxDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
2bda0e17 1956{
42e69d6b 1957 if ( message == WM_INITDIALOG )
2bda0e17 1958 {
42e69d6b
VZ
1959 // for this message, returning TRUE tells system to set focus to the
1960 // first control in the dialog box
1961 return TRUE;
2d0a075d 1962 }
42e69d6b 1963 else
2d0a075d 1964 {
42e69d6b
VZ
1965 // for all the other ones, FALSE means that we didn't process the
1966 // message
1967 return 0;
2d0a075d 1968 }
2bda0e17
KB
1969}
1970
42e69d6b
VZ
1971wxList *wxWinHandleList = NULL;
1972wxWindow *wxFindWinFromHandle(WXHWND hWnd)
4ce81a75 1973{
42e69d6b
VZ
1974 wxNode *node = wxWinHandleList->Find((long)hWnd);
1975 if ( !node )
1976 return NULL;
1977 return (wxWindow *)node->Data();
1978}
4ce81a75 1979
42e69d6b
VZ
1980void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win)
1981{
1982 // adding NULL hWnd is (first) surely a result of an error and
1983 // (secondly) breaks menu command processing
1984 wxCHECK_RET( hWnd != (HWND)NULL,
1985 "attempt to add a NULL hWnd to window list ignored" );
4ce81a75 1986
42e69d6b
VZ
1987 if ( !wxWinHandleList->Find((long)hWnd) )
1988 wxWinHandleList->Append((long)hWnd, win);
1989}
4ce81a75 1990
42e69d6b
VZ
1991void wxRemoveHandleAssociation(wxWindow *win)
1992{
1993 wxWinHandleList->DeleteObject(win);
4ce81a75
JS
1994}
1995
42e69d6b
VZ
1996// Default destroyer - override if you destroy it in some other way
1997// (e.g. with MDI child windows)
1998void wxWindow::MSWDestroyWindow()
4ce81a75 1999{
42e69d6b 2000}
4ce81a75 2001
42e69d6b
VZ
2002void wxWindow::MSWDetachWindowMenu()
2003{
2004 if ( m_hMenu )
4ce81a75 2005 {
42e69d6b 2006 HMENU hMenu = (HMENU)m_hMenu;
4ce81a75 2007
42e69d6b
VZ
2008 int N = ::GetMenuItemCount(hMenu);
2009 int i;
2010 for (i = 0; i < N; i++)
2011 {
2012 char buf[100];
2013 int chars = GetMenuString(hMenu, i, buf, 100, MF_BYPOSITION);
2014 if ( !chars )
2015 {
2016 wxLogLastError("GetMenuString");
4ce81a75 2017
42e69d6b
VZ
2018 continue;
2019 }
4ce81a75 2020
42e69d6b
VZ
2021 if ( strcmp(buf, "&Window") == 0 )
2022 {
2023 RemoveMenu(hMenu, i, MF_BYPOSITION);
4ce81a75 2024
42e69d6b
VZ
2025 break;
2026 }
2027 }
4ce81a75
JS
2028 }
2029}
2030
42e69d6b
VZ
2031bool wxWindow::MSWCreate(int id,
2032 wxWindow *parent,
2033 const char *wclass,
2034 wxWindow *wx_win,
2035 const char *title,
2036 int x,
2037 int y,
2038 int width,
2039 int height,
2040 WXDWORD style,
2041 const char *dialog_template,
2042 WXDWORD extendedStyle)
2bda0e17 2043{
42e69d6b
VZ
2044 int x1 = CW_USEDEFAULT;
2045 int y1 = 0;
2046 int width1 = CW_USEDEFAULT;
2047 int height1 = 100;
c085e333 2048
42e69d6b
VZ
2049 // Find parent's size, if it exists, to set up a possible default
2050 // panel size the size of the parent window
2051 RECT parent_rect;
2052 if ( parent )
a23fd0e1 2053 {
42e69d6b 2054 ::GetClientRect((HWND) parent->GetHWND(), &parent_rect);
c085e333 2055
42e69d6b
VZ
2056 width1 = parent_rect.right - parent_rect.left;
2057 height1 = parent_rect.bottom - parent_rect.top;
2058 }
2bda0e17 2059
42e69d6b
VZ
2060 if ( x > -1 ) x1 = x;
2061 if ( y > -1 ) y1 = y;
2062 if ( width > -1 ) width1 = width;
2063 if ( height > -1 ) height1 = height;
c085e333 2064
42e69d6b
VZ
2065 HWND hParent = NULL;
2066 if ( parent )
2067 hParent = (HWND) parent->GetHWND();
c085e333 2068
42e69d6b 2069 wxWndHook = this;
c085e333 2070
42e69d6b
VZ
2071 if ( dialog_template )
2072 {
2073 m_hWnd = (WXHWND)::CreateDialog(wxGetInstance(),
2074 dialog_template,
2075 hParent,
2076 (DLGPROC)wxDlgProc);
2bda0e17 2077
42e69d6b
VZ
2078 if ( m_hWnd == 0 )
2079 {
2080 wxLogError(_("Can't find dummy dialog template!\n"
2081 "Check resource include path for finding wx.rc."));
c085e333 2082
42e69d6b
VZ
2083 return FALSE;
2084 }
c085e333 2085
789295bf
VZ
2086 // ::SetWindowLong(GWL_EXSTYLE) doesn't work for the dialogs, so try
2087 // to take care of (at least some) extended style flags ourselves
2088 if ( extendedStyle & WS_EX_TOPMOST )
2089 {
2090 if ( !::SetWindowPos(GetHwnd(), HWND_TOPMOST, 0, 0, 0, 0,
2091 SWP_NOSIZE | SWP_NOMOVE) )
2092 {
2093 wxLogLastError("SetWindowPos");
2094 }
2095 }
2096
2097 // move the dialog to its initial position without forcing repainting
2098 if ( !::MoveWindow(GetHwnd(), x1, y1, width1, height1, FALSE) )
2099 {
2100 wxLogLastError("MoveWindow");
2101 }
42e69d6b
VZ
2102 }
2103 else
2104 {
2105 int controlId = 0;
2106 if ( style & WS_CHILD )
2107 controlId = id;
2108
2109 m_hWnd = (WXHWND)CreateWindowEx(extendedStyle,
2110 wclass,
2111 title ? title : "",
2112 style,
2113 x1, y1,
2114 width1, height1,
2115 hParent, (HMENU)controlId,
2116 wxGetInstance(),
2117 NULL);
2118
2119 if ( !m_hWnd )
2120 {
2121 wxLogError(_("Can't create window of class %s!\n"
2122 "Possible Windows 3.x compatibility problem?"),
2123 wclass);
2bda0e17 2124
a23fd0e1 2125 return FALSE;
42e69d6b 2126 }
a23fd0e1 2127 }
c085e333 2128
42e69d6b
VZ
2129 wxWndHook = NULL;
2130 wxWinHandleList->Append((long)m_hWnd, this);
c085e333 2131
42e69d6b 2132 return TRUE;
2bda0e17
KB
2133}
2134
42e69d6b
VZ
2135// ===========================================================================
2136// MSW message handlers
2137// ===========================================================================
2138
2139// ---------------------------------------------------------------------------
2140// WM_NOTIFY
2141// ---------------------------------------------------------------------------
2142
2143#ifdef __WIN95__
2144// FIXME: VZ: I'm not sure at all that the order of processing is correct
2145bool wxWindow::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
2bda0e17 2146{
42e69d6b
VZ
2147 LPNMHDR hdr = (LPNMHDR)lParam;
2148 HWND hWnd = hdr->hwndFrom;
2149 wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd);
2150
2151 // is this one of our windows?
2152 if ( win )
564b2609 2153 {
42e69d6b 2154 return win->MSWOnNotify(idCtrl, lParam, result);
564b2609 2155 }
2bda0e17 2156
42e69d6b
VZ
2157 // try all our children
2158 wxWindowList::Node *node = GetChildren().GetFirst();
2159 while ( node )
564b2609 2160 {
42e69d6b
VZ
2161 wxWindow *child = node->GetData();
2162 if ( child->MSWOnNotify(idCtrl, lParam, result) )
2163 {
2164 return TRUE;
2d0a075d 2165
42e69d6b
VZ
2166 break;
2167 }
2d0a075d 2168
42e69d6b
VZ
2169 node = node->GetNext();
2170 }
2d0a075d 2171
42e69d6b
VZ
2172 // finally try this window too (catches toolbar case)
2173 return MSWOnNotify(idCtrl, lParam, result);
2174}
2d0a075d 2175
42e69d6b
VZ
2176bool wxWindow::MSWOnNotify(int WXUNUSED(idCtrl),
2177 WXLPARAM lParam,
2178 WXLPARAM* WXUNUSED(result))
2179{
2180#if wxUSE_TOOLTIPS
2181 NMHDR* hdr = (NMHDR *)lParam;
2182 if ( hdr->code == TTN_NEEDTEXT && m_tooltip )
2183 {
2184 TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
2185 ttt->lpszText = (char *)m_tooltip->GetTip().c_str();
2d0a075d 2186
42e69d6b
VZ
2187 // processed
2188 return TRUE;
2189 }
2190#endif // wxUSE_TOOLTIPS
2191
2192 return FALSE;
2193}
2194#endif // __WIN95__
2195
2196// ---------------------------------------------------------------------------
2197// end session messages
2198// ---------------------------------------------------------------------------
2d0a075d 2199
42e69d6b
VZ
2200bool wxWindow::HandleQueryEndSession(long logOff, bool *mayEnd)
2201{
2202 wxCloseEvent event(wxEVT_QUERY_END_SESSION, -1);
2203 event.SetEventObject(wxTheApp);
2204 event.SetCanVeto(TRUE);
2205 event.SetLoggingOff(logOff == ENDSESSION_LOGOFF);
2d0a075d 2206
42e69d6b
VZ
2207 bool rc = wxTheApp->ProcessEvent(event);
2208
2209 if ( rc )
2210 {
2211 // we may end only if the app didn't veto session closing (double
2212 // negation...)
2213 *mayEnd = !event.GetVeto();
2d0a075d
JS
2214 }
2215
42e69d6b 2216 return rc;
2bda0e17
KB
2217}
2218
42e69d6b 2219bool wxWindow::HandleEndSession(bool endSession, long logOff)
2bda0e17 2220{
42e69d6b
VZ
2221 // do nothing if the session isn't ending
2222 if ( !endSession )
2223 return FALSE;
a23fd0e1 2224
42e69d6b
VZ
2225 wxCloseEvent event(wxEVT_END_SESSION, -1);
2226 event.SetEventObject(wxTheApp);
2227 event.SetCanVeto(FALSE);
2228 event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) );
2229 if ( (this == wxTheApp->GetTopWindow()) && // Only send once
2230 wxTheApp->ProcessEvent(event))
2231 {
2232 }
2233 return TRUE;
2bda0e17
KB
2234}
2235
42e69d6b
VZ
2236// ---------------------------------------------------------------------------
2237// window creation/destruction
2238// ---------------------------------------------------------------------------
2239
2240bool wxWindow::HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate)
2bda0e17 2241{
42e69d6b
VZ
2242 // TODO: should generate this event from WM_NCCREATE
2243 wxWindowCreateEvent event(this);
2244 (void)GetEventHandler()->ProcessEvent(event);
a23fd0e1 2245
42e69d6b
VZ
2246 *mayCreate = TRUE;
2247
2248 return TRUE;
2bda0e17
KB
2249}
2250
42e69d6b 2251bool wxWindow::HandleDestroy()
2bda0e17 2252{
42e69d6b
VZ
2253 wxWindowDestroyEvent event(this);
2254 (void)GetEventHandler()->ProcessEvent(event);
2255
2256 // delete our drop target if we've got one
2257#if wxUSE_DRAG_AND_DROP
2258 if ( m_dropTarget != NULL )
2d0a075d 2259 {
42e69d6b
VZ
2260 m_dropTarget->Revoke(m_hWnd);
2261
2262 delete m_dropTarget;
2263 m_dropTarget = NULL;
2d0a075d 2264 }
42e69d6b 2265#endif // wxUSE_DRAG_AND_DROP
2bda0e17 2266
42e69d6b
VZ
2267 // WM_DESTROY handled
2268 return TRUE;
2bda0e17
KB
2269}
2270
42e69d6b
VZ
2271// ---------------------------------------------------------------------------
2272// activation/focus
2273// ---------------------------------------------------------------------------
2274
2275bool wxWindow::HandleActivate(int state,
2276 bool WXUNUSED(minimized),
2277 WXHWND WXUNUSED(activate))
2bda0e17 2278{
42e69d6b
VZ
2279 wxActivateEvent event(wxEVT_ACTIVATE,
2280 (state == WA_ACTIVE) || (state == WA_CLICKACTIVE),
2281 m_windowId);
2282 event.SetEventObject(this);
2283
2284 return GetEventHandler()->ProcessEvent(event);
2285}
2286
2287bool wxWindow::HandleSetFocus(WXHWND WXUNUSED(hwnd))
2288{
789295bf 2289#if wxUSE_CARET
42e69d6b 2290 // Deal with caret
789295bf 2291 if ( m_caret )
2d0a075d 2292 {
789295bf 2293 m_caret->OnSetFocus();
2bda0e17 2294 }
789295bf 2295#endif // wxUSE_CARET
42e69d6b
VZ
2296
2297 // panel wants to track the window which was the last to have focus in it
2298 wxWindow *parent = GetParent();
2299 if ( parent && parent->IsKindOf(CLASSINFO(wxPanel)) )
2300 {
2301 ((wxPanel *)parent)->SetLastFocus(GetId());
2302 }
2303
2304 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
2305 event.SetEventObject(this);
2306
2307 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
2308}
2309
42e69d6b 2310bool wxWindow::HandleKillFocus(WXHWND WXUNUSED(hwnd))
2bda0e17 2311{
789295bf 2312#if wxUSE_CARET
42e69d6b 2313 // Deal with caret
789295bf 2314 if ( m_caret )
2d0a075d 2315 {
789295bf 2316 m_caret->OnKillFocus();
2bda0e17 2317 }
789295bf 2318#endif // wxUSE_CARET
42e69d6b
VZ
2319
2320 wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId);
2321 event.SetEventObject(this);
2322
2323 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
2324}
2325
42e69d6b
VZ
2326// ---------------------------------------------------------------------------
2327// miscellaneous
2328// ---------------------------------------------------------------------------
2329
2330bool wxWindow::HandleShow(bool show, int status)
2bda0e17 2331{
42e69d6b
VZ
2332 wxShowEvent event(GetId(), show);
2333 event.m_eventObject = this;
2334
2335 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
2336}
2337
42e69d6b 2338bool wxWindow::HandleInitDialog(WXHWND WXUNUSED(hWndFocus))
2bda0e17 2339{
42e69d6b
VZ
2340 wxInitDialogEvent event(GetId());
2341 event.m_eventObject = this;
2342
2343 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
2344}
2345
42e69d6b 2346bool wxWindow::HandleDropFiles(WXWPARAM wParam)
2bda0e17 2347{
42e69d6b
VZ
2348 HDROP hFilesInfo = (HDROP) wParam;
2349 POINT dropPoint;
2350 DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
2351
2352 // Get the total number of files dropped
2353 WORD gwFilesDropped = (WORD)DragQueryFile ((HDROP)hFilesInfo,
2354 (UINT)-1,
2355 (LPSTR)0,
2356 (UINT)0);
2357
2358 wxString *files = new wxString[gwFilesDropped];
2359 int wIndex;
2360 for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++)
2d0a075d 2361 {
42e69d6b
VZ
2362 DragQueryFile (hFilesInfo, wIndex, (LPSTR) wxBuffer, 1000);
2363 files[wIndex] = wxBuffer;
2d0a075d 2364 }
42e69d6b 2365 DragFinish (hFilesInfo);
2bda0e17 2366
42e69d6b
VZ
2367 wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files);
2368 event.m_eventObject = this;
2369 event.m_pos.x = dropPoint.x; event.m_pos.x = dropPoint.y;
2370
2371 bool rc = GetEventHandler()->ProcessEvent(event);
2372
2373 delete[] files;
2374
2375 return rc;
2bda0e17
KB
2376}
2377
42e69d6b
VZ
2378bool wxWindow::HandleSetCursor(WXHWND hWnd,
2379 short nHitTest,
2380 int WXUNUSED(mouseMsg))
2bda0e17 2381{
42e69d6b
VZ
2382 // don't set cursor for other windows, only for this one: this prevents
2383 // children of this window from getting the same cursor as the parent has
2384 // (don't forget that this message is propagated by default up the window
2385 // parent-child hierarchy)
2386 if ( GetHWND() == hWnd )
2387 {
2388 // don't set cursor when the mouse is not in the client part
2389 if ( nHitTest == HTCLIENT || nHitTest == HTERROR )
2390 {
2391 HCURSOR hcursor = 0;
2392 if ( wxIsBusy() )
2393 {
2394 // from msw\utils.cpp
2395 extern HCURSOR gs_wxBusyCursor;
2396
2397 hcursor = gs_wxBusyCursor;
2398 }
2399 else
2400 {
2401 wxCursor *cursor = NULL;
2402
2403 if ( m_cursor.Ok() )
2404 {
2405 cursor = &m_cursor;
2406 }
2407 else
2408 {
2409 // from msw\data.cpp
2410 extern wxCursor *g_globalCursor;
2411
2412 if ( g_globalCursor && g_globalCursor->Ok() )
2413 cursor = g_globalCursor;
2414 }
2415
2416 if ( cursor )
2417 hcursor = (HCURSOR)cursor->GetHCURSOR();
2418 }
2419
2420 if ( hcursor )
2421 {
2422 ::SetCursor(hcursor);
2423
2424 return TRUE;
2425 }
2426 }
2427 }
2428
2429 return FALSE;
2bda0e17
KB
2430}
2431
42e69d6b
VZ
2432#if wxUSE_OWNER_DRAWN
2433// ---------------------------------------------------------------------------
2434// owner drawn stuff
2435// ---------------------------------------------------------------------------
2436
2437bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
2bda0e17 2438{
42e69d6b
VZ
2439 // is it a menu item?
2440 if ( id == 0 )
2441 {
2442 DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
2443 wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData);
2444
2445 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
2446
2447 // prepare to call OnDrawItem()
2448 wxDC dc;
2449 dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE);
2450 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
2451 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
2452 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
2453
2454 return pMenuItem->OnDrawItem
2455 (
2456 dc, rect,
2457 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
2458 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
2459 );
2460 }
2461
2462 wxWindow *item = FindItem(id);
2463 if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
2464 {
2465 return ((wxControl *)item)->MSWOnDraw(itemStruct);
2466 }
2467 else
2468 return FALSE;
2bda0e17
KB
2469}
2470
42e69d6b 2471bool wxWindow::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
2bda0e17 2472{
42e69d6b
VZ
2473 // is it a menu item?
2474 if ( id == 0 )
2d0a075d 2475 {
42e69d6b
VZ
2476 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
2477 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
2478
2479 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
2480
2481 return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth,
2482 &pMeasureStruct->itemHeight);
2d0a075d 2483 }
42e69d6b
VZ
2484
2485 wxWindow *item = FindItem(id);
2486 if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
2487 {
2488 return ((wxControl *)item)->MSWOnMeasure(itemStruct);
2489 }
2490
2491 return FALSE;
2bda0e17 2492}
42e69d6b 2493#endif // owner-drawn menus
2bda0e17 2494
42e69d6b
VZ
2495// ---------------------------------------------------------------------------
2496// colours and palettes
2497// ---------------------------------------------------------------------------
2bda0e17 2498
42e69d6b 2499bool wxWindow::HandleSysColorChange()
2bda0e17 2500{
42e69d6b
VZ
2501 wxSysColourChangedEvent event;
2502 event.SetEventObject(this);
2503
2504 return GetEventHandler()->ProcessEvent(event);
2505}
2506
2507bool wxWindow::HandleCtlColor(WXHBRUSH *brush,
2508 WXHDC pDC,
2509 WXHWND pWnd,
2510 WXUINT nCtlColor,
2511 WXUINT message,
2512 WXWPARAM wParam,
2513 WXLPARAM lParam)
2514{
2515 WXHBRUSH hBrush = 0;
2516
2517 if ( nCtlColor == CTLCOLOR_DLG )
2d0a075d 2518 {
42e69d6b 2519 hBrush = OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2d0a075d
JS
2520 }
2521 else
2522 {
42e69d6b
VZ
2523 wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE);
2524 if ( item )
2525 hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2d0a075d 2526 }
42e69d6b
VZ
2527
2528 if ( hBrush )
2529 *brush = hBrush;
2530
2531 return hBrush != 0;
2bda0e17
KB
2532}
2533
42e69d6b
VZ
2534// Define for each class of dialog and control
2535WXHBRUSH wxWindow::OnCtlColor(WXHDC hDC,
2536 WXHWND hWnd,
2537 WXUINT nCtlColor,
2538 WXUINT message,
2539 WXWPARAM wParam,
2540 WXLPARAM lParam)
2bda0e17 2541{
42e69d6b
VZ
2542 return (WXHBRUSH)0;
2543}
2d0a075d 2544
42e69d6b
VZ
2545bool wxWindow::HandlePaletteChanged(WXHWND hWndPalChange)
2546{
2547 wxPaletteChangedEvent event(GetId());
2548 event.SetEventObject(this);
2549 event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
2d0a075d 2550
42e69d6b
VZ
2551 return GetEventHandler()->ProcessEvent(event);
2552}
2553
2554bool wxWindow::HandleQueryNewPalette()
2555{
2556 wxQueryNewPaletteEvent event(GetId());
2557 event.SetEventObject(this);
2558
2559 return GetEventHandler()->ProcessEvent(event) && event.GetPaletteRealized();
2560}
2561
2562// Responds to colour changes: passes event on to children.
2563void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
2564{
2565 wxNode *node = GetChildren().First();
2566 while ( node )
2567 {
2568 // Only propagate to non-top-level windows
2569 wxWindow *win = (wxWindow *)node->Data();
2570 if ( win->GetParent() )
2571 {
2572 wxSysColourChangedEvent event2;
2573 event.m_eventObject = win;
2574 win->GetEventHandler()->ProcessEvent(event2);
564b2609 2575 }
42e69d6b
VZ
2576
2577 node = node->Next();
2bda0e17 2578 }
2bda0e17
KB
2579}
2580
42e69d6b
VZ
2581// ---------------------------------------------------------------------------
2582// painting
2583// ---------------------------------------------------------------------------
2584
2585bool wxWindow::HandlePaint()
2bda0e17 2586{
42e69d6b
VZ
2587#ifdef __WIN32__
2588 HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
2589 if ( !hRegion )
2590 wxLogLastError("CreateRectRgn");
2591 if ( ::GetUpdateRgn(GetHwnd(), hRegion, FALSE) == ERROR )
2592 wxLogLastError("GetUpdateRgn");
c085e333 2593
42e69d6b
VZ
2594 m_updateRegion = wxRegion((WXHRGN) hRegion);
2595#else
2596 RECT updateRect;
2597 ::GetUpdateRect(GetHwnd(), & updateRect, FALSE);
c085e333 2598
42e69d6b
VZ
2599 m_updateRegion = wxRegion(updateRect.left, updateRect.top,
2600 updateRect.right - updateRect.left,
2601 updateRect.bottom - updateRect.top);
2602#endif
c085e333 2603
42e69d6b
VZ
2604 wxPaintEvent event(m_windowId);
2605 event.SetEventObject(this);
2bda0e17 2606
42e69d6b 2607 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
2608}
2609
42e69d6b 2610bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
a23fd0e1 2611{
42e69d6b
VZ
2612 // Prevents flicker when dragging
2613 if ( ::IsIconic(GetHwnd()) )
2614 return TRUE;
a23fd0e1 2615
a23fd0e1 2616 wxDC dc;
c085e333 2617
a23fd0e1 2618 dc.SetHDC(hdc);
564b2609
VZ
2619 dc.SetWindow(this);
2620 dc.BeginDrawing();
c085e333 2621
2bda0e17 2622 wxEraseEvent event(m_windowId, &dc);
42e69d6b 2623 event.SetEventObject(this);
a23fd0e1 2624 bool rc = GetEventHandler()->ProcessEvent(event);
c085e333 2625
a23fd0e1
VZ
2626 dc.EndDrawing();
2627 dc.SelectOldObjects(hdc);
2bda0e17 2628 dc.SetHDC((WXHDC) NULL);
a23fd0e1
VZ
2629
2630 return rc;
2bda0e17
KB
2631}
2632
2633void wxWindow::OnEraseBackground(wxEraseEvent& event)
2634{
2d0a075d 2635 RECT rect;
a23fd0e1 2636 ::GetClientRect(GetHwnd(), &rect);
2bda0e17 2637
42e69d6b
VZ
2638 COLORREF ref = PALETTERGB(m_backgroundColour.Red(),
2639 m_backgroundColour.Green(),
2640 m_backgroundColour.Blue());
ce3ed50d 2641 HBRUSH hBrush = ::CreateSolidBrush(ref);
42e69d6b
VZ
2642 if ( !hBrush )
2643 wxLogLastError("CreateSolidBrush");
2644
2645 HDC hdc = (HDC)event.GetDC()->GetHDC();
2bda0e17 2646
42e69d6b
VZ
2647 int mode = ::SetMapMode(hdc, MM_TEXT);
2648
2649 ::FillRect(hdc, &rect, hBrush);
2d0a075d 2650 ::DeleteObject(hBrush);
42e69d6b
VZ
2651 ::SetMapMode(hdc, mode);
2652}
2653
2654// ---------------------------------------------------------------------------
2655// moving and resizing
2656// ---------------------------------------------------------------------------
2657
2658bool wxWindow::HandleMinimize()
2659{
2660 wxIconizeEvent event(m_windowId);
2661 event.SetEventObject(this);
2d0a075d 2662
42e69d6b 2663 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
2664}
2665
42e69d6b 2666bool wxWindow::HandleMaximize()
2bda0e17 2667{
42e69d6b
VZ
2668 wxMaximizeEvent event(m_windowId);
2669 event.SetEventObject(this);
c085e333 2670
42e69d6b
VZ
2671 return GetEventHandler()->ProcessEvent(event);
2672}
2bda0e17 2673
42e69d6b
VZ
2674bool wxWindow::HandleMove(int x, int y)
2675{
2676 wxMoveEvent event(wxPoint(x, y), m_windowId);
2677 event.SetEventObject(this);
2678
2679 return GetEventHandler()->ProcessEvent(event);
2680}
2681
2682bool wxWindow::HandleSize(int w, int h, WXUINT WXUNUSED(flag))
2683{
2684 wxSizeEvent event(wxSize(w, h), m_windowId);
2685 event.SetEventObject(this);
2686
2687 return GetEventHandler()->ProcessEvent(event);
2688}
2689
2690bool wxWindow::HandleGetMinMaxInfo(void *mmInfo)
2691{
2692 MINMAXINFO *info = (MINMAXINFO *)mmInfo;
2693
2694 bool rc = FALSE;
2695
2696 if ( m_minWidth != -1 )
2d0a075d 2697 {
42e69d6b
VZ
2698 info->ptMinTrackSize.x = m_minWidth;
2699 rc = TRUE;
2d0a075d 2700 }
2bda0e17 2701
42e69d6b
VZ
2702 if ( m_minHeight != -1 )
2703 {
2704 info->ptMinTrackSize.y = m_minHeight;
2705 rc = TRUE;
2706 }
2bda0e17 2707
42e69d6b
VZ
2708 if ( m_maxWidth != -1 )
2709 {
2710 info->ptMaxTrackSize.x = m_maxWidth;
2711 rc = TRUE;
2d0a075d 2712 }
2bda0e17 2713
42e69d6b
VZ
2714 if ( m_maxHeight != -1 )
2715 {
2716 info->ptMaxTrackSize.y = m_maxHeight;
2717 rc = TRUE;
2718 }
2bda0e17 2719
42e69d6b
VZ
2720 return rc;
2721}
2d0a075d 2722
42e69d6b
VZ
2723// ---------------------------------------------------------------------------
2724// command messages
2725// ---------------------------------------------------------------------------
2726
2727bool wxWindow::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
2728{
2729 if ( wxCurrentPopupMenu )
2730 {
2731 wxMenu *popupMenu = wxCurrentPopupMenu;
2732 wxCurrentPopupMenu = NULL;
2733
2734 return popupMenu->MSWCommand(cmd, id);
2735 }
2736
2737 wxWindow *win = FindItem(id);
2738 if ( !win )
2739 {
2740 win = wxFindWinFromHandle(control);
2741 }
2742
2743 if ( win )
2744 return win->MSWCommand(cmd, id);
2745
2746 return FALSE;
2bda0e17
KB
2747}
2748
42e69d6b 2749bool wxWindow::HandleSysCommand(WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 2750{
42e69d6b
VZ
2751 // 4 bits are reserved
2752 switch ( wParam & 0xFFFFFFF0 )
2753 {
2754 case SC_MAXIMIZE:
2755 return HandleMaximize();
2d0a075d 2756
42e69d6b
VZ
2757 case SC_MINIMIZE:
2758 return HandleMinimize();
2d0a075d 2759 }
2bda0e17 2760
42e69d6b
VZ
2761 return FALSE;
2762}
2763
2764// ---------------------------------------------------------------------------
2765// mouse events
2766// ---------------------------------------------------------------------------
2767
2768void wxWindow::InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags)
2769{
2770 event.m_x = x;
2771 event.m_y = y;
2772 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2773 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2774 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2775 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2776 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2777 event.SetTimestamp(s_currentMsg.time);
2778 event.m_eventObject = this;
2779
2780#if wxUSE_MOUSEEVENT_HACK
2781 m_lastMouseX = x;
2782 m_lastMouseY = y;
2783 m_lastMouseEvent = event.GetEventType();
2784#endif // wxUSE_MOUSEEVENT_HACK
2bda0e17 2785
2bda0e17
KB
2786}
2787
42e69d6b 2788bool wxWindow::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags)
2bda0e17 2789{
42e69d6b
VZ
2790 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
2791 // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST
2792 // from the message id and take the value in the table to get wxWin event
2793 // id
2794 static const wxEventType eventsMouse[] =
2795 {
2796 wxEVT_MOTION,
2797 wxEVT_LEFT_DOWN,
2798 wxEVT_LEFT_UP,
2799 wxEVT_LEFT_DCLICK,
2800 wxEVT_RIGHT_DOWN,
2801 wxEVT_RIGHT_UP,
2802 wxEVT_RIGHT_DCLICK,
2803 wxEVT_MIDDLE_DOWN,
2804 wxEVT_MIDDLE_UP,
2805 wxEVT_MIDDLE_DCLICK
2806 };
2bda0e17 2807
42e69d6b
VZ
2808 wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]);
2809 InitMouseEvent(event, x, y, flags);
2810
2811 return GetEventHandler()->ProcessEvent(event);
2812}
2813
2814bool wxWindow::HandleMouseMove(int x, int y, WXUINT flags)
2815{
2816 if ( !m_mouseInWindow )
2bda0e17 2817 {
42e69d6b
VZ
2818 // Generate an ENTER event
2819 m_mouseInWindow = TRUE;
2820
2821 wxMouseEvent event(wxEVT_ENTER_WINDOW);
2822 InitMouseEvent(event, x, y, flags);
2823
2824 (void)GetEventHandler()->ProcessEvent(event);
2825 }
2826
2827#if wxUSE_MOUSEEVENT_HACK
2828 // Window gets a click down message followed by a mouse move message even
2829 // if position isn't changed! We want to discard the trailing move event
2830 // if x and y are the same.
2831 if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN ||
2832 m_lastMouseEvent == wxEVT_LEFT_DOWN ||
2833 m_lastMouseEvent == wxEVT_MIDDLE_DOWN) &&
2834 (m_lastMouseX == event.m_x && m_lastMouseY == event.m_y) )
2835 {
2836 m_lastMouseEvent = wxEVT_MOTION;
2837
2838 return FALSE;
2839 }
2840#endif // wxUSE_MOUSEEVENT_HACK
2841
2842 return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags);
2843}
2844
2845// ---------------------------------------------------------------------------
2846// keyboard handling
2847// ---------------------------------------------------------------------------
2848
2849// isASCII is TRUE only when we're called from WM_CHAR handler and not from
2850// WM_KEYDOWN one
2851bool wxWindow::HandleChar(WXWORD wParam, WXLPARAM lParam, bool isASCII)
2852{
2853 int id;
2854 bool tempControlDown = FALSE;
2855 if ( isASCII )
2856 {
2857 // If 1 -> 26, translate to CTRL plus a letter.
2858 id = wParam;
2859 if ( (id > 0) && (id < 27) )
2d0a075d 2860 {
42e69d6b
VZ
2861 switch (id)
2862 {
2863 case 13:
2864 {
2865 id = WXK_RETURN;
2866 break;
2867 }
2868 case 8:
2869 {
2870 id = WXK_BACK;
2871 break;
2872 }
2873 case 9:
2874 {
2875 id = WXK_TAB;
2876 break;
2877 }
2878 default:
2879 {
2880 tempControlDown = TRUE;
2881 id = id + 96;
2882 }
2883 }
2d0a075d 2884 }
2d0a075d 2885 }
42e69d6b
VZ
2886 else if ( (id = wxCharCodeMSWToWX(wParam)) == 0 ) {
2887 // it's ASCII and will be processed here only when called from
2888 // WM_CHAR (i.e. when isASCII = TRUE)
2889 id = -1;
2890 }
2bda0e17 2891
42e69d6b 2892 if ( id != -1 )
2d0a075d 2893 {
42e69d6b
VZ
2894 wxKeyEvent event(wxEVT_CHAR);
2895 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
2896 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
2897 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
2898 event.m_altDown = TRUE;
2899
2900 event.m_eventObject = this;
2901 event.m_keyCode = id;
2902 event.SetTimestamp(s_currentMsg.time);
2903
2904 POINT pt;
2905 GetCursorPos(&pt);
2906 RECT rect;
2907 GetWindowRect(GetHwnd(),&rect);
2908 pt.x -= rect.left;
2909 pt.y -= rect.top;
2910
2911 event.m_x = pt.x; event.m_y = pt.y;
2912
2913 if ( GetEventHandler()->ProcessEvent(event) )
2914 return TRUE;
2915 else
2916 return FALSE;
2d0a075d
JS
2917 }
2918 else
42e69d6b 2919 return FALSE;
2bda0e17
KB
2920}
2921
42e69d6b 2922bool wxWindow::HandleKeyDown(WXWORD wParam, WXLPARAM lParam)
2bda0e17 2923{
42e69d6b 2924 int id;
2bda0e17 2925
42e69d6b
VZ
2926 if ( (id = wxCharCodeMSWToWX(wParam)) == 0 ) {
2927 id = wParam;
2928 }
2929
2930 if ( id != -1 )
2bda0e17 2931 {
42e69d6b
VZ
2932 wxKeyEvent event(wxEVT_KEY_DOWN);
2933 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
2934 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
2935 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
2936 event.m_altDown = TRUE;
2937
2938 event.m_eventObject = this;
2939 event.m_keyCode = id;
2940 event.SetTimestamp(s_currentMsg.time);
2941
2942 POINT pt;
2943 GetCursorPos(&pt);
2944 RECT rect;
2945 GetWindowRect(GetHwnd(),&rect);
2946 pt.x -= rect.left;
2947 pt.y -= rect.top;
2948
2949 event.m_x = pt.x; event.m_y = pt.y;
2950
2951 if ( GetEventHandler()->ProcessEvent(event) )
2d0a075d 2952 {
42e69d6b 2953 return TRUE;
2d0a075d 2954 }
42e69d6b 2955 else return FALSE;
2d0a075d
JS
2956 }
2957 else
42e69d6b
VZ
2958 {
2959 return FALSE;
2960 }
2bda0e17
KB
2961}
2962
42e69d6b 2963bool wxWindow::HandleKeyUp(WXWORD wParam, WXLPARAM lParam)
2bda0e17 2964{
42e69d6b 2965 int id;
2bda0e17 2966
42e69d6b
VZ
2967 if ( (id = wxCharCodeMSWToWX(wParam)) == 0 ) {
2968 id = wParam;
2d0a075d 2969 }
2bda0e17 2970
42e69d6b
VZ
2971 if ( id != -1 )
2972 {
2973 wxKeyEvent event(wxEVT_KEY_UP);
2974 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
2975 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
2976 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
2977 event.m_altDown = TRUE;
2bda0e17 2978
42e69d6b
VZ
2979 event.m_eventObject = this;
2980 event.m_keyCode = id;
2981 event.SetTimestamp(s_currentMsg.time);
2d0a075d 2982
42e69d6b
VZ
2983 POINT pt;
2984 GetCursorPos(&pt);
2985 RECT rect;
2986 GetWindowRect(GetHwnd(),&rect);
2987 pt.x -= rect.left;
2988 pt.y -= rect.top;
2989
2990 event.m_x = pt.x; event.m_y = pt.y;
2991
2992 if ( GetEventHandler()->ProcessEvent(event) )
2993 return TRUE;
2994 else
2995 return FALSE;
2996 }
2997 else
2998 return FALSE;
2bda0e17
KB
2999}
3000
42e69d6b
VZ
3001// ---------------------------------------------------------------------------
3002// joystick
3003// ---------------------------------------------------------------------------
3004
3005bool wxWindow::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
2bda0e17 3006{
42e69d6b
VZ
3007 int change = 0;
3008 if ( flags & JOY_BUTTON1CHG )
3009 change = wxJOY_BUTTON1;
3010 if ( flags & JOY_BUTTON2CHG )
3011 change = wxJOY_BUTTON2;
3012 if ( flags & JOY_BUTTON3CHG )
3013 change = wxJOY_BUTTON3;
3014 if ( flags & JOY_BUTTON4CHG )
3015 change = wxJOY_BUTTON4;
2bda0e17 3016
42e69d6b
VZ
3017 int buttons = 0;
3018 if ( flags & JOY_BUTTON1 )
3019 buttons |= wxJOY_BUTTON1;
3020 if ( flags & JOY_BUTTON2 )
3021 buttons |= wxJOY_BUTTON2;
3022 if ( flags & JOY_BUTTON3 )
3023 buttons |= wxJOY_BUTTON3;
3024 if ( flags & JOY_BUTTON4 )
3025 buttons |= wxJOY_BUTTON4;
c085e333 3026
42e69d6b
VZ
3027 // the event ids aren't consecutive so we can't use table based lookup
3028 int joystick;
3029 wxEventType eventType;
3030 switch ( msg )
3031 {
3032 case MM_JOY1MOVE:
3033 joystick = 1;
3034 eventType = wxEVT_JOY_MOVE;
3035 break;
2bda0e17 3036
42e69d6b
VZ
3037 case MM_JOY2MOVE:
3038 joystick = 2;
3039 eventType = wxEVT_JOY_MOVE;
3040 break;
2bda0e17 3041
42e69d6b
VZ
3042 case MM_JOY1ZMOVE:
3043 joystick = 1;
3044 eventType = wxEVT_JOY_ZMOVE;
3045 break;
2bda0e17 3046
42e69d6b
VZ
3047 case MM_JOY2ZMOVE:
3048 joystick = 2;
3049 eventType = wxEVT_JOY_ZMOVE;
3050 break;
2bda0e17 3051
42e69d6b
VZ
3052 case MM_JOY1BUTTONDOWN:
3053 joystick = 1;
3054 eventType = wxEVT_JOY_BUTTON_DOWN;
3055 break;
2bda0e17 3056
42e69d6b
VZ
3057 case MM_JOY2BUTTONDOWN:
3058 joystick = 2;
3059 eventType = wxEVT_JOY_BUTTON_DOWN;
3060 break;
2bda0e17 3061
42e69d6b
VZ
3062 case MM_JOY1BUTTONUP:
3063 joystick = 1;
3064 eventType = wxEVT_JOY_BUTTON_UP;
3065 break;
3066
3067 case MM_JOY2BUTTONUP:
3068 joystick = 2;
3069 eventType = wxEVT_JOY_BUTTON_UP;
3070 break;
3071
3072 default:
3073 wxFAIL_MSG("no such joystick event");
2d0a075d 3074
42e69d6b 3075 return FALSE;
2d0a075d 3076 }
2bda0e17 3077
42e69d6b
VZ
3078 wxJoystickEvent event(eventType, buttons, joystick, change);
3079 event.SetPosition(wxPoint(x, y));
3080 event.SetEventObject(this);
c085e333 3081
42e69d6b 3082 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3083}
3084
42e69d6b
VZ
3085// ---------------------------------------------------------------------------
3086// scrolling
3087// ---------------------------------------------------------------------------
3088
3089bool wxWindow::MSWOnScroll(int orientation, WXWORD wParam,
3090 WXWORD pos, WXHWND control)
2bda0e17 3091{
42e69d6b 3092 if ( control )
cc2b7472 3093 {
42e69d6b
VZ
3094 wxWindow *child = wxFindWinFromHandle(control);
3095 if ( child )
3096 return child->MSWOnScroll(orientation, wParam, pos, control);
cc2b7472 3097 }
2bda0e17 3098
9145664b 3099 wxScrollWinEvent event;
42e69d6b
VZ
3100 event.SetPosition(pos);
3101 event.SetOrientation(orientation);
3102 event.m_eventObject = this;
cc2b7472 3103
42e69d6b
VZ
3104 switch ( wParam )
3105 {
3106 case SB_TOP:
9145664b 3107 event.m_eventType = wxEVT_SCROLLWIN_TOP;
42e69d6b 3108 break;
cc2b7472 3109
42e69d6b 3110 case SB_BOTTOM:
9145664b 3111 event.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
42e69d6b 3112 break;
cc2b7472 3113
42e69d6b 3114 case SB_LINEUP:
9145664b 3115 event.m_eventType = wxEVT_SCROLLWIN_LINEUP;
42e69d6b 3116 break;
2bda0e17 3117
42e69d6b 3118 case SB_LINEDOWN:
9145664b 3119 event.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
42e69d6b 3120 break;
a02eb1d2 3121
42e69d6b 3122 case SB_PAGEUP:
9145664b 3123 event.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
42e69d6b 3124 break;
2bda0e17 3125
42e69d6b 3126 case SB_PAGEDOWN:
9145664b 3127 event.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
42e69d6b 3128 break;
2bda0e17 3129
42e69d6b
VZ
3130 case SB_THUMBTRACK:
3131 case SB_THUMBPOSITION:
9145664b 3132 event.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
42e69d6b 3133 break;
c085e333 3134
42e69d6b
VZ
3135 default:
3136 return FALSE;
564b2609 3137 }
2bda0e17 3138
42e69d6b 3139 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
3140}
3141
42e69d6b
VZ
3142// ===========================================================================
3143// global functions
3144// ===========================================================================
3145
3146void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font)
2bda0e17 3147{
42e69d6b
VZ
3148 TEXTMETRIC tm;
3149 HDC dc = ::GetDC((HWND) wnd);
3150 HFONT fnt =0;
3151 HFONT was = 0;
3152 if ( the_font )
2d0a075d 3153 {
42e69d6b
VZ
3154 // the_font->UseResource();
3155 // the_font->RealizeResource();
3156 fnt = (HFONT)the_font->GetResourceHandle();
3157 if ( fnt )
3158 was = (HFONT) SelectObject(dc,fnt);
2d0a075d 3159 }
42e69d6b
VZ
3160 GetTextMetrics(dc, &tm);
3161 if ( the_font && fnt && was )
2d0a075d 3162 {
42e69d6b 3163 SelectObject(dc,was);
2d0a075d 3164 }
42e69d6b
VZ
3165 ReleaseDC((HWND)wnd, dc);
3166 *x = tm.tmAveCharWidth;
3167 *y = tm.tmHeight + tm.tmExternalLeading;
2bda0e17 3168
42e69d6b
VZ
3169 // if ( the_font )
3170 // the_font->ReleaseResource();
3171}
c085e333 3172
42e69d6b
VZ
3173// Returns 0 if was a normal ASCII value, not a special key. This indicates that
3174// the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
3175int wxCharCodeMSWToWX(int keySym)
3176{
3177 int id = 0;
3178 switch (keySym)
3179 {
3180 case VK_CANCEL: id = WXK_CANCEL; break;
3181 case VK_BACK: id = WXK_BACK; break;
3182 case VK_TAB: id = WXK_TAB; break;
3183 case VK_CLEAR: id = WXK_CLEAR; break;
3184 case VK_RETURN: id = WXK_RETURN; break;
3185 case VK_SHIFT: id = WXK_SHIFT; break;
3186 case VK_CONTROL: id = WXK_CONTROL; break;
3187 case VK_MENU : id = WXK_MENU; break;
3188 case VK_PAUSE: id = WXK_PAUSE; break;
3189 case VK_SPACE: id = WXK_SPACE; break;
3190 case VK_ESCAPE: id = WXK_ESCAPE; break;
3191 case VK_PRIOR: id = WXK_PRIOR; break;
3192 case VK_NEXT : id = WXK_NEXT; break;
3193 case VK_END: id = WXK_END; break;
3194 case VK_HOME : id = WXK_HOME; break;
3195 case VK_LEFT : id = WXK_LEFT; break;
3196 case VK_UP: id = WXK_UP; break;
3197 case VK_RIGHT: id = WXK_RIGHT; break;
3198 case VK_DOWN : id = WXK_DOWN; break;
3199 case VK_SELECT: id = WXK_SELECT; break;
3200 case VK_PRINT: id = WXK_PRINT; break;
3201 case VK_EXECUTE: id = WXK_EXECUTE; break;
3202 case VK_INSERT: id = WXK_INSERT; break;
3203 case VK_DELETE: id = WXK_DELETE; break;
3204 case VK_HELP : id = WXK_HELP; break;
3205 case VK_NUMPAD0: id = WXK_NUMPAD0; break;
3206 case VK_NUMPAD1: id = WXK_NUMPAD1; break;
3207 case VK_NUMPAD2: id = WXK_NUMPAD2; break;
3208 case VK_NUMPAD3: id = WXK_NUMPAD3; break;
3209 case VK_NUMPAD4: id = WXK_NUMPAD4; break;
3210 case VK_NUMPAD5: id = WXK_NUMPAD5; break;
3211 case VK_NUMPAD6: id = WXK_NUMPAD6; break;
3212 case VK_NUMPAD7: id = WXK_NUMPAD7; break;
3213 case VK_NUMPAD8: id = WXK_NUMPAD8; break;
3214 case VK_NUMPAD9: id = WXK_NUMPAD9; break;
3215 case VK_MULTIPLY: id = WXK_MULTIPLY; break;
3216 case VK_ADD: id = WXK_ADD; break;
3217 case VK_SUBTRACT: id = WXK_SUBTRACT; break;
3218 case VK_DECIMAL: id = WXK_DECIMAL; break;
3219 case VK_DIVIDE: id = WXK_DIVIDE; break;
3220 case VK_F1: id = WXK_F1; break;
3221 case VK_F2: id = WXK_F2; break;
3222 case VK_F3: id = WXK_F3; break;
3223 case VK_F4: id = WXK_F4; break;
3224 case VK_F5: id = WXK_F5; break;
3225 case VK_F6: id = WXK_F6; break;
3226 case VK_F7: id = WXK_F7; break;
3227 case VK_F8: id = WXK_F8; break;
3228 case VK_F9: id = WXK_F9; break;
3229 case VK_F10: id = WXK_F10; break;
3230 case VK_F11: id = WXK_F11; break;
3231 case VK_F12: id = WXK_F12; break;
3232 case VK_F13: id = WXK_F13; break;
3233 case VK_F14: id = WXK_F14; break;
3234 case VK_F15: id = WXK_F15; break;
3235 case VK_F16: id = WXK_F16; break;
3236 case VK_F17: id = WXK_F17; break;
3237 case VK_F18: id = WXK_F18; break;
3238 case VK_F19: id = WXK_F19; break;
3239 case VK_F20: id = WXK_F20; break;
3240 case VK_F21: id = WXK_F21; break;
3241 case VK_F22: id = WXK_F22; break;
3242 case VK_F23: id = WXK_F23; break;
3243 case VK_F24: id = WXK_F24; break;
3244 case VK_NUMLOCK: id = WXK_NUMLOCK; break;
3245 case VK_SCROLL: id = WXK_SCROLL; break;
3246 default:
3247 {
3248 return 0;
3249 }
3250 }
3251 return id;
2bda0e17
KB
3252}
3253
42e69d6b 3254int wxCharCodeWXToMSW(int id, bool *isVirtual)
2bda0e17 3255{
42e69d6b
VZ
3256 *isVirtual = TRUE;
3257 int keySym = 0;
3258 switch (id)
2bda0e17 3259 {
42e69d6b
VZ
3260 case WXK_CANCEL: keySym = VK_CANCEL; break;
3261 case WXK_CLEAR: keySym = VK_CLEAR; break;
3262 case WXK_SHIFT: keySym = VK_SHIFT; break;
3263 case WXK_CONTROL: keySym = VK_CONTROL; break;
3264 case WXK_MENU : keySym = VK_MENU; break;
3265 case WXK_PAUSE: keySym = VK_PAUSE; break;
3266 case WXK_PRIOR: keySym = VK_PRIOR; break;
3267 case WXK_NEXT : keySym = VK_NEXT; break;
3268 case WXK_END: keySym = VK_END; break;
3269 case WXK_HOME : keySym = VK_HOME; break;
3270 case WXK_LEFT : keySym = VK_LEFT; break;
3271 case WXK_UP: keySym = VK_UP; break;
3272 case WXK_RIGHT: keySym = VK_RIGHT; break;
3273 case WXK_DOWN : keySym = VK_DOWN; break;
3274 case WXK_SELECT: keySym = VK_SELECT; break;
3275 case WXK_PRINT: keySym = VK_PRINT; break;
3276 case WXK_EXECUTE: keySym = VK_EXECUTE; break;
3277 case WXK_INSERT: keySym = VK_INSERT; break;
3278 case WXK_DELETE: keySym = VK_DELETE; break;
3279 case WXK_HELP : keySym = VK_HELP; break;
3280 case WXK_NUMPAD0: keySym = VK_NUMPAD0; break;
3281 case WXK_NUMPAD1: keySym = VK_NUMPAD1; break;
3282 case WXK_NUMPAD2: keySym = VK_NUMPAD2; break;
3283 case WXK_NUMPAD3: keySym = VK_NUMPAD3; break;
3284 case WXK_NUMPAD4: keySym = VK_NUMPAD4; break;
3285 case WXK_NUMPAD5: keySym = VK_NUMPAD5; break;
3286 case WXK_NUMPAD6: keySym = VK_NUMPAD6; break;
3287 case WXK_NUMPAD7: keySym = VK_NUMPAD7; break;
3288 case WXK_NUMPAD8: keySym = VK_NUMPAD8; break;
3289 case WXK_NUMPAD9: keySym = VK_NUMPAD9; break;
3290 case WXK_MULTIPLY: keySym = VK_MULTIPLY; break;
3291 case WXK_ADD: keySym = VK_ADD; break;
3292 case WXK_SUBTRACT: keySym = VK_SUBTRACT; break;
3293 case WXK_DECIMAL: keySym = VK_DECIMAL; break;
3294 case WXK_DIVIDE: keySym = VK_DIVIDE; break;
3295 case WXK_F1: keySym = VK_F1; break;
3296 case WXK_F2: keySym = VK_F2; break;
3297 case WXK_F3: keySym = VK_F3; break;
3298 case WXK_F4: keySym = VK_F4; break;
3299 case WXK_F5: keySym = VK_F5; break;
3300 case WXK_F6: keySym = VK_F6; break;
3301 case WXK_F7: keySym = VK_F7; break;
3302 case WXK_F8: keySym = VK_F8; break;
3303 case WXK_F9: keySym = VK_F9; break;
3304 case WXK_F10: keySym = VK_F10; break;
3305 case WXK_F11: keySym = VK_F11; break;
3306 case WXK_F12: keySym = VK_F12; break;
3307 case WXK_F13: keySym = VK_F13; break;
3308 case WXK_F14: keySym = VK_F14; break;
3309 case WXK_F15: keySym = VK_F15; break;
3310 case WXK_F16: keySym = VK_F16; break;
3311 case WXK_F17: keySym = VK_F17; break;
3312 case WXK_F18: keySym = VK_F18; break;
3313 case WXK_F19: keySym = VK_F19; break;
3314 case WXK_F20: keySym = VK_F20; break;
3315 case WXK_F21: keySym = VK_F21; break;
3316 case WXK_F22: keySym = VK_F22; break;
3317 case WXK_F23: keySym = VK_F23; break;
3318 case WXK_F24: keySym = VK_F24; break;
3319 case WXK_NUMLOCK: keySym = VK_NUMLOCK; break;
3320 case WXK_SCROLL: keySym = VK_SCROLL; break;
3321 default:
3322 {
3323 *isVirtual = FALSE;
3324 keySym = id;
3325 break;
3326 }
2bda0e17 3327 }
42e69d6b 3328 return keySym;
2bda0e17
KB
3329}
3330
42e69d6b 3331wxWindow *wxGetActiveWindow()
2bda0e17 3332{
42e69d6b
VZ
3333 HWND hWnd = GetActiveWindow();
3334 if ( hWnd != 0 )
2d0a075d 3335 {
42e69d6b 3336 return wxFindWinFromHandle((WXHWND) hWnd);
2d0a075d 3337 }
42e69d6b 3338 return NULL;
2bda0e17
KB
3339}
3340
42e69d6b
VZ
3341// Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
3342// in active frames and dialogs, regardless of where the focus is.
3343static HHOOK wxTheKeyboardHook = 0;
3344static FARPROC wxTheKeyboardHookProc = 0;
3345int APIENTRY _EXPORT
3346wxKeyboardHook(int nCode, WORD wParam, DWORD lParam);
2bda0e17 3347
42e69d6b 3348void wxSetKeyboardHook(bool doIt)
2bda0e17 3349{
42e69d6b 3350 if ( doIt )
2d0a075d 3351 {
42e69d6b
VZ
3352 wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance());
3353 wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
3354#if defined(__WIN32__) && !defined(__TWIN32__)
3355 GetCurrentThreadId());
3356 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
3357#else
3358 GetCurrentTask());
3359#endif
2d0a075d 3360 }
2d0a075d 3361 else
2d0a075d 3362 {
42e69d6b
VZ
3363 UnhookWindowsHookEx(wxTheKeyboardHook);
3364 FreeProcInstance(wxTheKeyboardHookProc);
2d0a075d 3365 }
2bda0e17
KB
3366}
3367
42e69d6b
VZ
3368int APIENTRY _EXPORT
3369wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
2bda0e17 3370{
42e69d6b
VZ
3371 DWORD hiWord = HIWORD(lParam);
3372 if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) )
43d811ea 3373 {
42e69d6b
VZ
3374 int id;
3375 if ( (id = wxCharCodeMSWToWX(wParam)) != 0 )
43d811ea 3376 {
42e69d6b
VZ
3377 wxKeyEvent event(wxEVT_CHAR_HOOK);
3378 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
3379 event.m_altDown = TRUE;
c085e333 3380
42e69d6b
VZ
3381 event.m_eventObject = NULL;
3382 event.m_keyCode = id;
3383 /* begin Albert's fix for control and shift key 26.5 */
3384 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
3385 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
3386 /* end Albert's fix for control and shift key 26.5 */
3387 event.SetTimestamp(s_currentMsg.time);
c085e333 3388
42e69d6b
VZ
3389 wxWindow *win = wxGetActiveWindow();
3390 if ( win )
3391 {
3392 if ( win->GetEventHandler()->ProcessEvent(event) )
3393 return 1;
3394 }
3395 else
3396 {
3397 if ( wxTheApp && wxTheApp->ProcessEvent(event) )
3398 return 1;
3399 }
43d811ea
JS
3400 }
3401 }
42e69d6b 3402 return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam);
4fabb575
JS
3403}
3404
b2aef89b 3405#ifdef __WXDEBUG__
f449ef69 3406const char *wxGetMessageName(int message)
47cbd6da 3407{
42e69d6b
VZ
3408 switch ( message )
3409 {
3410 case 0x0000: return "WM_NULL";
3411 case 0x0001: return "WM_CREATE";
3412 case 0x0002: return "WM_DESTROY";
3413 case 0x0003: return "WM_MOVE";
3414 case 0x0005: return "WM_SIZE";
3415 case 0x0006: return "WM_ACTIVATE";
3416 case 0x0007: return "WM_SETFOCUS";
3417 case 0x0008: return "WM_KILLFOCUS";
3418 case 0x000A: return "WM_ENABLE";
3419 case 0x000B: return "WM_SETREDRAW";
3420 case 0x000C: return "WM_SETTEXT";
3421 case 0x000D: return "WM_GETTEXT";
3422 case 0x000E: return "WM_GETTEXTLENGTH";
3423 case 0x000F: return "WM_PAINT";
3424 case 0x0010: return "WM_CLOSE";
3425 case 0x0011: return "WM_QUERYENDSESSION";
3426 case 0x0012: return "WM_QUIT";
3427 case 0x0013: return "WM_QUERYOPEN";
3428 case 0x0014: return "WM_ERASEBKGND";
3429 case 0x0015: return "WM_SYSCOLORCHANGE";
3430 case 0x0016: return "WM_ENDSESSION";
3431 case 0x0017: return "WM_SYSTEMERROR";
3432 case 0x0018: return "WM_SHOWWINDOW";
3433 case 0x0019: return "WM_CTLCOLOR";
3434 case 0x001A: return "WM_WININICHANGE";
3435 case 0x001B: return "WM_DEVMODECHANGE";
3436 case 0x001C: return "WM_ACTIVATEAPP";
3437 case 0x001D: return "WM_FONTCHANGE";
3438 case 0x001E: return "WM_TIMECHANGE";
3439 case 0x001F: return "WM_CANCELMODE";
3440 case 0x0020: return "WM_SETCURSOR";
3441 case 0x0021: return "WM_MOUSEACTIVATE";
3442 case 0x0022: return "WM_CHILDACTIVATE";
3443 case 0x0023: return "WM_QUEUESYNC";
3444 case 0x0024: return "WM_GETMINMAXINFO";
3445 case 0x0026: return "WM_PAINTICON";
3446 case 0x0027: return "WM_ICONERASEBKGND";
3447 case 0x0028: return "WM_NEXTDLGCTL";
3448 case 0x002A: return "WM_SPOOLERSTATUS";
3449 case 0x002B: return "WM_DRAWITEM";
3450 case 0x002C: return "WM_MEASUREITEM";
3451 case 0x002D: return "WM_DELETEITEM";
3452 case 0x002E: return "WM_VKEYTOITEM";
3453 case 0x002F: return "WM_CHARTOITEM";
3454 case 0x0030: return "WM_SETFONT";
3455 case 0x0031: return "WM_GETFONT";
3456 case 0x0037: return "WM_QUERYDRAGICON";
3457 case 0x0039: return "WM_COMPAREITEM";
3458 case 0x0041: return "WM_COMPACTING";
3459 case 0x0044: return "WM_COMMNOTIFY";
3460 case 0x0046: return "WM_WINDOWPOSCHANGING";
3461 case 0x0047: return "WM_WINDOWPOSCHANGED";
3462 case 0x0048: return "WM_POWER";
c085e333 3463
a02eb1d2 3464#ifdef __WIN32__
42e69d6b
VZ
3465 case 0x004A: return "WM_COPYDATA";
3466 case 0x004B: return "WM_CANCELJOURNAL";
3467 case 0x004E: return "WM_NOTIFY";
3468 case 0x0050: return "WM_INPUTLANGCHANGEREQUEST";
3469 case 0x0051: return "WM_INPUTLANGCHANGE";
3470 case 0x0052: return "WM_TCARD";
3471 case 0x0053: return "WM_HELP";
3472 case 0x0054: return "WM_USERCHANGED";
3473 case 0x0055: return "WM_NOTIFYFORMAT";
3474 case 0x007B: return "WM_CONTEXTMENU";
3475 case 0x007C: return "WM_STYLECHANGING";
3476 case 0x007D: return "WM_STYLECHANGED";
3477 case 0x007E: return "WM_DISPLAYCHANGE";
3478 case 0x007F: return "WM_GETICON";
3479 case 0x0080: return "WM_SETICON";
a02eb1d2 3480#endif //WIN32
c085e333 3481
42e69d6b
VZ
3482 case 0x0081: return "WM_NCCREATE";
3483 case 0x0082: return "WM_NCDESTROY";
3484 case 0x0083: return "WM_NCCALCSIZE";
3485 case 0x0084: return "WM_NCHITTEST";
3486 case 0x0085: return "WM_NCPAINT";
3487 case 0x0086: return "WM_NCACTIVATE";
3488 case 0x0087: return "WM_GETDLGCODE";
3489 case 0x00A0: return "WM_NCMOUSEMOVE";
3490 case 0x00A1: return "WM_NCLBUTTONDOWN";
3491 case 0x00A2: return "WM_NCLBUTTONUP";
3492 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
3493 case 0x00A4: return "WM_NCRBUTTONDOWN";
3494 case 0x00A5: return "WM_NCRBUTTONUP";
3495 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
3496 case 0x00A7: return "WM_NCMBUTTONDOWN";
3497 case 0x00A8: return "WM_NCMBUTTONUP";
3498 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
3499 case 0x0100: return "WM_KEYDOWN";
3500 case 0x0101: return "WM_KEYUP";
3501 case 0x0102: return "WM_CHAR";
3502 case 0x0103: return "WM_DEADCHAR";
3503 case 0x0104: return "WM_SYSKEYDOWN";
3504 case 0x0105: return "WM_SYSKEYUP";
3505 case 0x0106: return "WM_SYSCHAR";
3506 case 0x0107: return "WM_SYSDEADCHAR";
3507 case 0x0108: return "WM_KEYLAST";
c085e333 3508
a02eb1d2 3509#ifdef __WIN32__
42e69d6b
VZ
3510 case 0x010D: return "WM_IME_STARTCOMPOSITION";
3511 case 0x010E: return "WM_IME_ENDCOMPOSITION";
3512 case 0x010F: return "WM_IME_COMPOSITION";
a02eb1d2 3513#endif //WIN32
c085e333 3514
42e69d6b
VZ
3515 case 0x0110: return "WM_INITDIALOG";
3516 case 0x0111: return "WM_COMMAND";
3517 case 0x0112: return "WM_SYSCOMMAND";
3518 case 0x0113: return "WM_TIMER";
3519 case 0x0114: return "WM_HSCROLL";
3520 case 0x0115: return "WM_VSCROLL";
3521 case 0x0116: return "WM_INITMENU";
3522 case 0x0117: return "WM_INITMENUPOPUP";
3523 case 0x011F: return "WM_MENUSELECT";
3524 case 0x0120: return "WM_MENUCHAR";
3525 case 0x0121: return "WM_ENTERIDLE";
3526 case 0x0200: return "WM_MOUSEMOVE";
3527 case 0x0201: return "WM_LBUTTONDOWN";
3528 case 0x0202: return "WM_LBUTTONUP";
3529 case 0x0203: return "WM_LBUTTONDBLCLK";
3530 case 0x0204: return "WM_RBUTTONDOWN";
3531 case 0x0205: return "WM_RBUTTONUP";
3532 case 0x0206: return "WM_RBUTTONDBLCLK";
3533 case 0x0207: return "WM_MBUTTONDOWN";
3534 case 0x0208: return "WM_MBUTTONUP";
3535 case 0x0209: return "WM_MBUTTONDBLCLK";
3536 case 0x0210: return "WM_PARENTNOTIFY";
3537 case 0x0211: return "WM_ENTERMENULOOP";
3538 case 0x0212: return "WM_EXITMENULOOP";
c085e333 3539
a02eb1d2 3540#ifdef __WIN32__
42e69d6b
VZ
3541 case 0x0213: return "WM_NEXTMENU";
3542 case 0x0214: return "WM_SIZING";
3543 case 0x0215: return "WM_CAPTURECHANGED";
3544 case 0x0216: return "WM_MOVING";
3545 case 0x0218: return "WM_POWERBROADCAST";
3546 case 0x0219: return "WM_DEVICECHANGE";
a02eb1d2 3547#endif //WIN32
c085e333 3548
42e69d6b
VZ
3549 case 0x0220: return "WM_MDICREATE";
3550 case 0x0221: return "WM_MDIDESTROY";
3551 case 0x0222: return "WM_MDIACTIVATE";
3552 case 0x0223: return "WM_MDIRESTORE";
3553 case 0x0224: return "WM_MDINEXT";
3554 case 0x0225: return "WM_MDIMAXIMIZE";
3555 case 0x0226: return "WM_MDITILE";
3556 case 0x0227: return "WM_MDICASCADE";
3557 case 0x0228: return "WM_MDIICONARRANGE";
3558 case 0x0229: return "WM_MDIGETACTIVE";
3559 case 0x0230: return "WM_MDISETMENU";
3560 case 0x0233: return "WM_DROPFILES";
c085e333 3561
a02eb1d2 3562#ifdef __WIN32__
42e69d6b
VZ
3563 case 0x0281: return "WM_IME_SETCONTEXT";
3564 case 0x0282: return "WM_IME_NOTIFY";
3565 case 0x0283: return "WM_IME_CONTROL";
3566 case 0x0284: return "WM_IME_COMPOSITIONFULL";
3567 case 0x0285: return "WM_IME_SELECT";
3568 case 0x0286: return "WM_IME_CHAR";
3569 case 0x0290: return "WM_IME_KEYDOWN";
3570 case 0x0291: return "WM_IME_KEYUP";
a02eb1d2 3571#endif //WIN32
c085e333 3572
42e69d6b
VZ
3573 case 0x0300: return "WM_CUT";
3574 case 0x0301: return "WM_COPY";
3575 case 0x0302: return "WM_PASTE";
3576 case 0x0303: return "WM_CLEAR";
3577 case 0x0304: return "WM_UNDO";
3578 case 0x0305: return "WM_RENDERFORMAT";
3579 case 0x0306: return "WM_RENDERALLFORMATS";
3580 case 0x0307: return "WM_DESTROYCLIPBOARD";
3581 case 0x0308: return "WM_DRAWCLIPBOARD";
3582 case 0x0309: return "WM_PAINTCLIPBOARD";
3583 case 0x030A: return "WM_VSCROLLCLIPBOARD";
3584 case 0x030B: return "WM_SIZECLIPBOARD";
3585 case 0x030C: return "WM_ASKCBFORMATNAME";
3586 case 0x030D: return "WM_CHANGECBCHAIN";
3587 case 0x030E: return "WM_HSCROLLCLIPBOARD";
3588 case 0x030F: return "WM_QUERYNEWPALETTE";
3589 case 0x0310: return "WM_PALETTEISCHANGING";
3590 case 0x0311: return "WM_PALETTECHANGED";
c085e333 3591
a02eb1d2 3592#ifdef __WIN32__
2d0a075d
JS
3593 // common controls messages - although they're not strictly speaking
3594 // standard, it's nice to decode them nevertheless
a02eb1d2 3595
2d0a075d 3596 // listview
42e69d6b
VZ
3597 case 0x1000 + 0: return "LVM_GETBKCOLOR";
3598 case 0x1000 + 1: return "LVM_SETBKCOLOR";
3599 case 0x1000 + 2: return "LVM_GETIMAGELIST";
3600 case 0x1000 + 3: return "LVM_SETIMAGELIST";
3601 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
3602 case 0x1000 + 5: return "LVM_GETITEMA";
3603 case 0x1000 + 75: return "LVM_GETITEMW";
3604 case 0x1000 + 6: return "LVM_SETITEMA";
3605 case 0x1000 + 76: return "LVM_SETITEMW";
3606 case 0x1000 + 7: return "LVM_INSERTITEMA";
3607 case 0x1000 + 77: return "LVM_INSERTITEMW";
3608 case 0x1000 + 8: return "LVM_DELETEITEM";
3609 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
3610 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
3611 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
3612 case 0x1000 + 12: return "LVM_GETNEXTITEM";
3613 case 0x1000 + 13: return "LVM_FINDITEMA";
3614 case 0x1000 + 83: return "LVM_FINDITEMW";
3615 case 0x1000 + 14: return "LVM_GETITEMRECT";
3616 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
3617 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
3618 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
3619 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
3620 case 0x1000 + 18: return "LVM_HITTEST";
3621 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
3622 case 0x1000 + 20: return "LVM_SCROLL";
3623 case 0x1000 + 21: return "LVM_REDRAWITEMS";
3624 case 0x1000 + 22: return "LVM_ARRANGE";
3625 case 0x1000 + 23: return "LVM_EDITLABELA";
3626 case 0x1000 + 118: return "LVM_EDITLABELW";
3627 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
3628 case 0x1000 + 25: return "LVM_GETCOLUMNA";
3629 case 0x1000 + 95: return "LVM_GETCOLUMNW";
3630 case 0x1000 + 26: return "LVM_SETCOLUMNA";
3631 case 0x1000 + 96: return "LVM_SETCOLUMNW";
3632 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
3633 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
3634 case 0x1000 + 28: return "LVM_DELETECOLUMN";
3635 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
3636 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
3637 case 0x1000 + 31: return "LVM_GETHEADER";
3638 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
3639 case 0x1000 + 34: return "LVM_GETVIEWRECT";
3640 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
3641 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
3642 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
3643 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
3644 case 0x1000 + 39: return "LVM_GETTOPINDEX";
3645 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
3646 case 0x1000 + 41: return "LVM_GETORIGIN";
3647 case 0x1000 + 42: return "LVM_UPDATE";
3648 case 0x1000 + 43: return "LVM_SETITEMSTATE";
3649 case 0x1000 + 44: return "LVM_GETITEMSTATE";
3650 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
3651 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
3652 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
3653 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
3654 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
3655 case 0x1000 + 48: return "LVM_SORTITEMS";
3656 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
3657 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
3658 case 0x1000 + 51: return "LVM_GETITEMSPACING";
3659 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
3660 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
3661 case 0x1000 + 53: return "LVM_SETICONSPACING";
3662 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
3663 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
3664 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
3665 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
3666 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
3667 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
3668 case 0x1000 + 60: return "LVM_SETHOTITEM";
3669 case 0x1000 + 61: return "LVM_GETHOTITEM";
3670 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
3671 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
3672 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
3673 case 0x1000 + 65: return "LVM_SETWORKAREA";
c085e333 3674
2d0a075d 3675 // tree view
42e69d6b
VZ
3676 case 0x1100 + 0: return "TVM_INSERTITEMA";
3677 case 0x1100 + 50: return "TVM_INSERTITEMW";
3678 case 0x1100 + 1: return "TVM_DELETEITEM";
3679 case 0x1100 + 2: return "TVM_EXPAND";
3680 case 0x1100 + 4: return "TVM_GETITEMRECT";
3681 case 0x1100 + 5: return "TVM_GETCOUNT";
3682 case 0x1100 + 6: return "TVM_GETINDENT";
3683 case 0x1100 + 7: return "TVM_SETINDENT";
3684 case 0x1100 + 8: return "TVM_GETIMAGELIST";
3685 case 0x1100 + 9: return "TVM_SETIMAGELIST";
3686 case 0x1100 + 10: return "TVM_GETNEXTITEM";
3687 case 0x1100 + 11: return "TVM_SELECTITEM";
3688 case 0x1100 + 12: return "TVM_GETITEMA";
3689 case 0x1100 + 62: return "TVM_GETITEMW";
3690 case 0x1100 + 13: return "TVM_SETITEMA";
3691 case 0x1100 + 63: return "TVM_SETITEMW";
3692 case 0x1100 + 14: return "TVM_EDITLABELA";
3693 case 0x1100 + 65: return "TVM_EDITLABELW";
3694 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
3695 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
3696 case 0x1100 + 17: return "TVM_HITTEST";
3697 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
3698 case 0x1100 + 19: return "TVM_SORTCHILDREN";
3699 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
3700 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
3701 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
3702 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
3703 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
3704 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
3705 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
c085e333 3706
2d0a075d 3707 // header
42e69d6b
VZ
3708 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
3709 case 0x1200 + 1: return "HDM_INSERTITEMA";
3710 case 0x1200 + 10: return "HDM_INSERTITEMW";
3711 case 0x1200 + 2: return "HDM_DELETEITEM";
3712 case 0x1200 + 3: return "HDM_GETITEMA";
3713 case 0x1200 + 11: return "HDM_GETITEMW";
3714 case 0x1200 + 4: return "HDM_SETITEMA";
3715 case 0x1200 + 12: return "HDM_SETITEMW";
3716 case 0x1200 + 5: return "HDM_LAYOUT";
3717 case 0x1200 + 6: return "HDM_HITTEST";
3718 case 0x1200 + 7: return "HDM_GETITEMRECT";
3719 case 0x1200 + 8: return "HDM_SETIMAGELIST";
3720 case 0x1200 + 9: return "HDM_GETIMAGELIST";
3721 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
3722 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
3723 case 0x1200 + 17: return "HDM_GETORDERARRAY";
3724 case 0x1200 + 18: return "HDM_SETORDERARRAY";
3725 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
c085e333 3726
2d0a075d 3727 // tab control
42e69d6b
VZ
3728 case 0x1300 + 2: return "TCM_GETIMAGELIST";
3729 case 0x1300 + 3: return "TCM_SETIMAGELIST";
3730 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
3731 case 0x1300 + 5: return "TCM_GETITEMA";
3732 case 0x1300 + 60: return "TCM_GETITEMW";
3733 case 0x1300 + 6: return "TCM_SETITEMA";
3734 case 0x1300 + 61: return "TCM_SETITEMW";
3735 case 0x1300 + 7: return "TCM_INSERTITEMA";
3736 case 0x1300 + 62: return "TCM_INSERTITEMW";
3737 case 0x1300 + 8: return "TCM_DELETEITEM";
3738 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
3739 case 0x1300 + 10: return "TCM_GETITEMRECT";
3740 case 0x1300 + 11: return "TCM_GETCURSEL";
3741 case 0x1300 + 12: return "TCM_SETCURSEL";
3742 case 0x1300 + 13: return "TCM_HITTEST";
3743 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
3744 case 0x1300 + 40: return "TCM_ADJUSTRECT";
3745 case 0x1300 + 41: return "TCM_SETITEMSIZE";
3746 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
3747 case 0x1300 + 43: return "TCM_SETPADDING";
3748 case 0x1300 + 44: return "TCM_GETROWCOUNT";
3749 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
3750 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
3751 case 0x1300 + 47: return "TCM_GETCURFOCUS";
3752 case 0x1300 + 48: return "TCM_SETCURFOCUS";
3753 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
3754 case 0x1300 + 50: return "TCM_DESELECTALL";
c085e333 3755
2d0a075d 3756 // toolbar
42e69d6b
VZ
3757 case WM_USER+1: return "TB_ENABLEBUTTON";
3758 case WM_USER+2: return "TB_CHECKBUTTON";
3759 case WM_USER+3: return "TB_PRESSBUTTON";
3760 case WM_USER+4: return "TB_HIDEBUTTON";
3761 case WM_USER+5: return "TB_INDETERMINATE";
3762 case WM_USER+9: return "TB_ISBUTTONENABLED";
3763 case WM_USER+10: return "TB_ISBUTTONCHECKED";
3764 case WM_USER+11: return "TB_ISBUTTONPRESSED";
3765 case WM_USER+12: return "TB_ISBUTTONHIDDEN";
3766 case WM_USER+13: return "TB_ISBUTTONINDETERMINATE";
3767 case WM_USER+17: return "TB_SETSTATE";
3768 case WM_USER+18: return "TB_GETSTATE";
3769 case WM_USER+19: return "TB_ADDBITMAP";
3770 case WM_USER+20: return "TB_ADDBUTTONS";
3771 case WM_USER+21: return "TB_INSERTBUTTON";
3772 case WM_USER+22: return "TB_DELETEBUTTON";
3773 case WM_USER+23: return "TB_GETBUTTON";
3774 case WM_USER+24: return "TB_BUTTONCOUNT";
3775 case WM_USER+25: return "TB_COMMANDTOINDEX";
3776 case WM_USER+26: return "TB_SAVERESTOREA";
3777 case WM_USER+76: return "TB_SAVERESTOREW";
3778 case WM_USER+27: return "TB_CUSTOMIZE";
3779 case WM_USER+28: return "TB_ADDSTRINGA";
3780 case WM_USER+77: return "TB_ADDSTRINGW";
3781 case WM_USER+29: return "TB_GETITEMRECT";
3782 case WM_USER+30: return "TB_BUTTONSTRUCTSIZE";
3783 case WM_USER+31: return "TB_SETBUTTONSIZE";
3784 case WM_USER+32: return "TB_SETBITMAPSIZE";
3785 case WM_USER+33: return "TB_AUTOSIZE";
3786 case WM_USER+35: return "TB_GETTOOLTIPS";
3787 case WM_USER+36: return "TB_SETTOOLTIPS";
3788 case WM_USER+37: return "TB_SETPARENT";
3789 case WM_USER+39: return "TB_SETROWS";
3790 case WM_USER+40: return "TB_GETROWS";
3791 case WM_USER+42: return "TB_SETCMDID";
3792 case WM_USER+43: return "TB_CHANGEBITMAP";
3793 case WM_USER+44: return "TB_GETBITMAP";
3794 case WM_USER+45: return "TB_GETBUTTONTEXTA";
3795 case WM_USER+75: return "TB_GETBUTTONTEXTW";
3796 case WM_USER+46: return "TB_REPLACEBITMAP";
3797 case WM_USER+47: return "TB_SETINDENT";
3798 case WM_USER+48: return "TB_SETIMAGELIST";
3799 case WM_USER+49: return "TB_GETIMAGELIST";
3800 case WM_USER+50: return "TB_LOADIMAGES";
3801 case WM_USER+51: return "TB_GETRECT";
3802 case WM_USER+52: return "TB_SETHOTIMAGELIST";
3803 case WM_USER+53: return "TB_GETHOTIMAGELIST";
3804 case WM_USER+54: return "TB_SETDISABLEDIMAGELIST";
3805 case WM_USER+55: return "TB_GETDISABLEDIMAGELIST";
3806 case WM_USER+56: return "TB_SETSTYLE";
3807 case WM_USER+57: return "TB_GETSTYLE";
3808 case WM_USER+58: return "TB_GETBUTTONSIZE";
3809 case WM_USER+59: return "TB_SETBUTTONWIDTH";
3810 case WM_USER+60: return "TB_SETMAXTEXTROWS";
3811 case WM_USER+61: return "TB_GETTEXTROWS";
3812 case WM_USER+41: return "TB_GETBITMAPFLAGS";
c085e333 3813
a02eb1d2 3814#endif //WIN32
c085e333 3815
42e69d6b
VZ
3816 default:
3817 static char s_szBuf[128];
3818 sprintf(s_szBuf, "<unknown message = %d>", message);
3819 return s_szBuf;
3820 }
47cbd6da 3821}
ea57084d 3822#endif //__WXDEBUG__