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