]> git.saurik.com Git - wxWidgets.git/blame - src/msw/window.cpp
mac support as stubs added
[wxWidgets.git] / src / msw / window.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: windows.cpp
3// Purpose: wxWindow
4// Author: Julian Smart
5// Modified by:
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
12#ifdef __GNUG__
13#pragma implementation "window.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include <stdio.h>
25#include "wx/setup.h"
26#include "wx/menu.h"
27#include "wx/dc.h"
28#include "wx/dcclient.h"
29#include "wx/utils.h"
30#include "wx/app.h"
31#include "wx/panel.h"
32#include "wx/layout.h"
33#include "wx/dialog.h"
34#include "wx/listbox.h"
35#include "wx/button.h"
36#include "wx/settings.h"
37#include "wx/msgdlg.h"
38#endif
39
47d67540 40#if wxUSE_OWNER_DRAWN
2bda0e17
KB
41#include "wx/ownerdrw.h"
42#endif
43
47d67540 44#if wxUSE_DRAG_AND_DROP
2bda0e17
KB
45#include "wx/msw/ole/droptgt.h"
46#endif
47
48#include "wx/menuitem.h"
47cbd6da 49#include "wx/log.h"
2bda0e17
KB
50#include "wx/msw/private.h"
51
52#include <string.h>
53
54#ifndef __GNUWIN32__
55#include <shellapi.h>
56#include <mmsystem.h>
57#endif
58
59#ifdef __WIN32__
60#include <windowsx.h>
61#endif
62
63#ifdef __GNUWIN32__
64#include <wx/msw/gnuwin32/extra.h>
65#endif
66
67#ifdef GetCharWidth
68#undef GetCharWidth
69#endif
70
71#ifdef FindWindow
72#undef FindWindow
73#endif
74
75#ifdef GetClassName
76#undef GetClassName
77#endif
78
79#ifdef GetClassInfo
80#undef GetClassInfo
81#endif
82
b2aef89b 83#ifdef __WXDEBUG__
f449ef69 84const char *wxGetMessageName(int message);
ea57084d 85#endif //__WXDEBUG__
47cbd6da 86
f54f3bff 87#define WINDOW_MARGIN 3 // This defines sensitivity of Leave events
2bda0e17
KB
88
89wxMenu *wxCurrentPopupMenu = NULL;
90extern wxList wxPendingDelete;
91
92void wxRemoveHandleAssociation(wxWindow *win);
93void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win);
94wxWindow *wxFindWinFromHandle(WXHWND hWnd);
95
96#if !USE_SHARED_LIBRARY
97IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler)
cf65ad8d 98#endif
2bda0e17
KB
99
100BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler)
cf65ad8d
VZ
101 EVT_CHAR(wxWindow::OnChar)
102 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
103 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
104 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
105 EVT_IDLE(wxWindow::OnIdle)
2bda0e17
KB
106END_EVENT_TABLE()
107
2bda0e17 108// Find an item given the MS Windows id
debe6624 109wxWindow *wxWindow::FindItem(int id) const
2bda0e17 110{
c0ed460c
JS
111// if (!GetChildren())
112// return NULL;
113 wxNode *current = GetChildren().First();
2d0a075d
JS
114 while (current)
115 {
116 wxWindow *childWin = (wxWindow *)current->Data();
2bda0e17 117
2d0a075d
JS
118 wxWindow *wnd = childWin->FindItem(id) ;
119 if (wnd)
120 return wnd ;
2bda0e17 121
2d0a075d
JS
122 if (childWin->IsKindOf(CLASSINFO(wxControl)))
123 {
124 wxControl *item = (wxControl *)childWin;
125 if (item->m_windowId == id)
126 return item;
127 else
128 {
129 // In case it's a 'virtual' control (e.g. radiobox)
130 if (item->GetSubcontrols().Member((wxObject *)id))
131 return item;
132 }
133 }
134 current = current->Next();
2bda0e17 135 }
2d0a075d 136 return NULL;
2bda0e17
KB
137}
138
139// Find an item given the MS Windows handle
debe6624 140wxWindow *wxWindow::FindItemByHWND(WXHWND hWnd, bool controlOnly) const
2bda0e17 141{
c0ed460c
JS
142// if (!GetChildren())
143// return NULL;
144 wxNode *current = GetChildren().First();
2d0a075d 145 while (current)
2bda0e17 146 {
2d0a075d
JS
147 wxObject *obj = (wxObject *)current->Data() ;
148 // Do a recursive search.
149 wxWindow *parent = (wxWindow *)obj ;
150 wxWindow *wnd = parent->FindItemByHWND(hWnd) ;
151 if (wnd)
152 return wnd ;
153
154 if ((!controlOnly) || obj->IsKindOf(CLASSINFO(wxControl)))
155 {
156 wxWindow *item = (wxWindow *)current->Data();
157 if ((HWND)(item->GetHWND()) == (HWND) hWnd)
158 return item;
159 else
160 {
161 if ( item->ContainsHWND(hWnd) )
162 return item;
163 }
164 }
165 current = current->Next();
2bda0e17 166 }
2d0a075d 167 return NULL;
2bda0e17
KB
168}
169
170// Default command handler
debe6624 171bool wxWindow::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
2bda0e17 172{
2d0a075d 173 return FALSE;
2bda0e17
KB
174}
175
fd3f686c
VZ
176bool wxWindow::MSWNotify(WXWPARAM WXUNUSED(wParam),
177 WXLPARAM WXUNUSED(lParam),
178 WXLPARAM* WXUNUSED(result))
2bda0e17 179{
2d0a075d 180 return FALSE;
2bda0e17
KB
181}
182
debe6624 183void wxWindow::PreDelete(WXHDC WXUNUSED(dc))
2bda0e17
KB
184{
185}
186
187WXHWND wxWindow::GetHWND(void) const
188{
2d0a075d 189 return (WXHWND) m_hWnd;
2bda0e17
KB
190}
191
192void wxWindow::SetHWND(WXHWND hWnd)
193{
2d0a075d 194 m_hWnd = hWnd;
2bda0e17
KB
195}
196
fd3f686c
VZ
197// ----------------------------------------------------------------------------
198// constructors and such
199// ----------------------------------------------------------------------------
200
201void wxWindow::Init()
2bda0e17 202{
2d0a075d
JS
203 // Generic
204 m_windowId = 0;
205 m_isShown = TRUE;
206 m_windowStyle = 0;
207 m_windowParent = NULL;
208 m_windowEventHandler = this;
2d0a075d
JS
209 m_windowCursor = *wxSTANDARD_CURSOR;
210 m_children = new wxList;
211 m_doubleClickAllowed = 0 ;
212 m_winCaptured = FALSE;
213 m_constraints = NULL;
214 m_constraintsInvolvedIn = NULL;
215 m_windowSizer = NULL;
216 m_sizerParent = NULL;
217 m_autoLayout = FALSE;
218 m_windowValidator = NULL;
219
220 // MSW-specific
221 m_hWnd = 0;
222 m_winEnabled = TRUE;
fd3f686c
VZ
223 m_caretWidth = m_caretHeight = 0;
224 m_caretEnabled =
2d0a075d
JS
225 m_caretShown = FALSE;
226 m_inOnSize = FALSE;
fd3f686c
VZ
227 m_minSizeX =
228 m_minSizeY =
229 m_maxSizeX =
2d0a075d 230 m_maxSizeY = -1;
fd3f686c 231
2d0a075d
JS
232 m_isBeingDeleted = FALSE;
233 m_oldWndProc = 0;
2bda0e17 234#ifndef __WIN32__
2d0a075d 235 m_globalHandle = 0;
2bda0e17 236#endif
2d0a075d 237 m_useCtl3D = FALSE;
fd3f686c 238 m_mouseInWindow = FALSE;
2bda0e17 239
fd3f686c 240 m_windowParent = NULL;
2d0a075d 241 m_defaultItem = NULL;
2bda0e17 242
2d0a075d 243 wxSystemSettings settings;
2bda0e17 244
2d0a075d 245 m_backgroundColour = settings.GetSystemColour(wxSYS_COLOUR_3DFACE) ;
2d0a075d 246 m_foregroundColour = *wxBLACK;
2bda0e17 247
2d0a075d
JS
248 // wxWnd
249 m_lastMsg = 0;
250 m_lastWParam = 0;
251 m_lastLParam = 0;
2d0a075d 252 m_hMenu = 0;
2bda0e17 253
2d0a075d
JS
254 m_xThumbSize = 0;
255 m_yThumbSize = 0;
256 m_backgroundTransparent = FALSE;
2bda0e17 257
2d0a075d
JS
258 m_lastXPos = (float)-1.0;
259 m_lastYPos = (float)-1.0;
260 m_lastEvent = -1;
261 m_returnCode = 0;
2bda0e17 262
47d67540 263#if wxUSE_DRAG_AND_DROP
2d0a075d 264 m_pDropTarget = NULL;
2bda0e17
KB
265#endif
266}
267
fd3f686c
VZ
268wxWindow::wxWindow()
269{
270 Init();
271}
272
2bda0e17 273// Destructor
fd3f686c 274wxWindow::~wxWindow()
2bda0e17 275{
2d0a075d 276 m_isBeingDeleted = TRUE;
2bda0e17 277
2d0a075d
JS
278 // JACS - if behaviour is odd, restore this
279 // to the start of ~wxWindow. Vadim has changed
280 // it to nearer the end. Unsure of side-effects
281 // e.g. when deleting associated global data.
282 // Restore old Window proc, if required
283 // UnsubclassWin();
2bda0e17 284
2d0a075d
JS
285 // Have to delete constraints/sizer FIRST otherwise
286 // sizers may try to look at deleted windows as they
287 // delete themselves.
47d67540 288#if wxUSE_CONSTRAINTS
2d0a075d
JS
289 DeleteRelatedConstraints();
290 if (m_constraints)
291 {
292 // This removes any dangling pointers to this window
293 // in other windows' constraintsInvolvedIn lists.
294 UnsetConstraints(m_constraints);
295 delete m_constraints;
296 m_constraints = NULL;
297 }
298 if (m_windowSizer)
299 {
300 delete m_windowSizer;
301 m_windowSizer = NULL;
302 }
303 // If this is a child of a sizer, remove self from parent
304 if (m_sizerParent)
305 m_sizerParent->RemoveChild((wxWindow *)this);
2bda0e17 306#endif
c085e333 307
2d0a075d
JS
308 // wxWnd
309 MSWDetachWindowMenu();
2bda0e17 310
2d0a075d
JS
311 if (m_windowParent)
312 m_windowParent->RemoveChild(this);
2bda0e17 313
2d0a075d 314 DestroyChildren();
2bda0e17 315
2d0a075d
JS
316 if (m_hWnd)
317 ::DestroyWindow((HWND)m_hWnd);
195896c7 318
2d0a075d
JS
319 wxRemoveHandleAssociation(this);
320 m_hWnd = 0;
2bda0e17 321#ifndef __WIN32__
2d0a075d
JS
322 if (m_globalHandle)
323 {
324 GlobalFree((HGLOBAL) m_globalHandle);
325 m_globalHandle = 0;
326 }
2bda0e17 327#endif
c085e333 328
2d0a075d
JS
329 delete m_children;
330 m_children = NULL;
2bda0e17 331
2d0a075d
JS
332 // Just in case the window has been Closed, but
333 // we're then deleting immediately: don't leave
334 // dangling pointers.
335 wxPendingDelete.DeleteObject(this);
2bda0e17 336
2d0a075d
JS
337 // Just in case we've loaded a top-level window via
338 // wxWindow::LoadNativeDialog but we weren't a dialog
339 // class
340 wxTopLevelWindows.DeleteObject(this);
2bda0e17 341
2d0a075d
JS
342 if ( m_windowValidator )
343 delete m_windowValidator;
2bda0e17 344
c085e333 345 // Restore old Window proc, if required
2d0a075d
JS
346 // and remove hWnd <-> wxWindow association
347 UnsubclassWin();
2bda0e17
KB
348}
349
350// Destroy the window (delayed, if a managed window)
fd3f686c 351bool wxWindow::Destroy()
2bda0e17
KB
352{
353 delete this;
354 return TRUE;
355}
356
357extern char wxCanvasClassName[];
358
fd3f686c 359// real construction (Init() must have been called before!)
debe6624 360bool wxWindow::Create(wxWindow *parent, wxWindowID id,
2d0a075d
JS
361 const wxPoint& pos,
362 const wxSize& size,
363 long style,
364 const wxString& name)
365{
fd3f686c 366 wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" );
2bda0e17 367
fd3f686c 368 parent->AddChild(this);
2bda0e17 369
2d0a075d 370 SetName(name);
2bda0e17 371
2d0a075d
JS
372 if ( id == -1 )
373 m_windowId = (int)NewControlId();
374 else
375 m_windowId = id;
2bda0e17 376
2d0a075d
JS
377 int x = pos.x;
378 int y = pos.y;
379 int width = size.x;
380 int height = size.y;
2bda0e17 381
386af6a2
JS
382 // To be consistent with wxGTK
383 if (width == -1)
384 width = 20;
385 if (height == -1)
386 height = 20;
387
2d0a075d 388 wxSystemSettings settings;
2bda0e17 389
2d0a075d 390 m_windowStyle = style;
2bda0e17 391
2d0a075d
JS
392 DWORD msflags = 0;
393 if (style & wxBORDER)
394 msflags |= WS_BORDER;
395 if (style & wxTHICK_FRAME)
396 msflags |= WS_THICKFRAME;
1c089c47 397
2d0a075d
JS
398 msflags |= WS_CHILD | WS_VISIBLE;
399 if (style & wxCLIP_CHILDREN)
400 msflags |= WS_CLIPCHILDREN;
2bda0e17 401
2d0a075d
JS
402 bool want3D;
403 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
2bda0e17 404
2d0a075d
JS
405 // Even with extended styles, need to combine with WS_BORDER
406 // for them to look right.
407 if (want3D || (m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
408 (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER))
409 msflags |= WS_BORDER;
2bda0e17 410
2d0a075d 411 MSWCreate(m_windowId, parent, wxCanvasClassName, this, NULL,
fd3f686c 412 x, y, width, height, msflags, NULL, exStyle);
2bda0e17 413
2d0a075d 414 return TRUE;
2bda0e17
KB
415}
416
fd3f686c 417void wxWindow::SetFocus()
2bda0e17 418{
2d0a075d
JS
419 HWND hWnd = (HWND) GetHWND();
420 if (hWnd)
421 ::SetFocus(hWnd);
2bda0e17
KB
422}
423
debe6624 424void wxWindow::Enable(bool enable)
2bda0e17 425{
2d0a075d
JS
426 m_winEnabled = enable;
427 HWND hWnd = (HWND) GetHWND();
428 if (hWnd)
429 ::EnableWindow(hWnd, (BOOL)enable);
2bda0e17
KB
430}
431
fd3f686c 432void wxWindow::CaptureMouse()
2bda0e17 433{
2d0a075d
JS
434 HWND hWnd = (HWND) GetHWND();
435 if (hWnd && !m_winCaptured)
436 {
437 SetCapture(hWnd);
438 m_winCaptured = TRUE;
439 }
2bda0e17
KB
440}
441
fd3f686c 442void wxWindow::ReleaseMouse()
2bda0e17 443{
2d0a075d
JS
444 if (m_winCaptured)
445 {
446 ReleaseCapture();
447 m_winCaptured = FALSE;
448 }
2bda0e17
KB
449}
450
088a95f5
JS
451void wxWindow::SetAcceleratorTable(const wxAcceleratorTable& accel)
452{
453 m_acceleratorTable = accel;
454}
455
456
2bda0e17
KB
457// Push/pop event handler (i.e. allow a chain of event handlers
458// be searched)
459void wxWindow::PushEventHandler(wxEvtHandler *handler)
460{
2d0a075d
JS
461 handler->SetNextHandler(GetEventHandler());
462 SetEventHandler(handler);
2bda0e17
KB
463}
464
465wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler)
466{
2d0a075d 467 if ( GetEventHandler() )
564b2609 468 {
2d0a075d
JS
469 wxEvtHandler *handlerA = GetEventHandler();
470 wxEvtHandler *handlerB = handlerA->GetNextHandler();
471 handlerA->SetNextHandler(NULL);
472 SetEventHandler(handlerB);
473 if ( deleteHandler )
474 {
475 delete handlerA;
476 return NULL;
477 }
478 else
479 return handlerA;
564b2609
VZ
480 }
481 else
2d0a075d 482 return NULL;
2bda0e17
KB
483}
484
47d67540 485#if wxUSE_DRAG_AND_DROP
2bda0e17
KB
486
487void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
488{
2d0a075d
JS
489 if ( m_pDropTarget != 0 ) {
490 m_pDropTarget->Revoke(m_hWnd);
491 delete m_pDropTarget;
492 }
195896c7 493
2d0a075d
JS
494 m_pDropTarget = pDropTarget;
495 if ( m_pDropTarget != 0 )
496 m_pDropTarget->Register(m_hWnd);
2bda0e17
KB
497}
498
499#endif
500
501//old style file-manager drag&drop support
502// I think we should retain the old-style
503// DragAcceptFiles in parallel with SetDropTarget.
504// JACS
debe6624 505void wxWindow::DragAcceptFiles(bool accept)
2bda0e17 506{
2d0a075d
JS
507 HWND hWnd = (HWND) GetHWND();
508 if (hWnd)
509 ::DragAcceptFiles(hWnd, (BOOL)accept);
2bda0e17
KB
510}
511
512// Get total size
513void wxWindow::GetSize(int *x, int *y) const
514{
2d0a075d
JS
515 HWND hWnd = (HWND) GetHWND();
516 RECT rect;
517 GetWindowRect(hWnd, &rect);
518 *x = rect.right - rect.left;
519 *y = rect.bottom - rect.top;
2bda0e17
KB
520}
521
522void wxWindow::GetPosition(int *x, int *y) const
523{
2d0a075d
JS
524 HWND hWnd = (HWND) GetHWND();
525 HWND hParentWnd = 0;
526 if (GetParent())
527 hParentWnd = (HWND) GetParent()->GetHWND();
81d66cf3 528
2d0a075d
JS
529 RECT rect;
530 GetWindowRect(hWnd, &rect);
531
532 // Since we now have the absolute screen coords,
533 // if there's a parent we must subtract its top left corner
534 POINT point;
535 point.x = rect.left;
536 point.y = rect.top;
537 if (hParentWnd)
538 {
539 ::ScreenToClient(hParentWnd, &point);
540 }
541
542 // We may be faking the client origin.
543 // So a window that's really at (0, 30) may appear
544 // (to wxWin apps) to be at (0, 0).
545 if (GetParent())
546 {
547 wxPoint pt(GetParent()->GetClientAreaOrigin());
548 point.x -= pt.x;
549 point.y -= pt.y;
550 }
551 *x = point.x;
552 *y = point.y;
2bda0e17
KB
553}
554
555void wxWindow::ScreenToClient(int *x, int *y) const
556{
2d0a075d
JS
557 HWND hWnd = (HWND) GetHWND();
558 POINT pt;
559 pt.x = *x;
560 pt.y = *y;
2d0a075d 561
87d1e11f 562 ::ScreenToClient(hWnd, &pt);
0757d27c 563
2d0a075d
JS
564 *x = pt.x;
565 *y = pt.y;
2bda0e17
KB
566}
567
568void wxWindow::ClientToScreen(int *x, int *y) const
569{
2d0a075d
JS
570 HWND hWnd = (HWND) GetHWND();
571 POINT pt;
572 pt.x = *x;
573 pt.y = *y;
574
2d0a075d 575 ::ClientToScreen(hWnd, &pt);
2bda0e17 576
2d0a075d
JS
577 *x = pt.x;
578 *y = pt.y;
2bda0e17
KB
579}
580
581void wxWindow::SetCursor(const wxCursor& cursor)
582{
2d0a075d
JS
583 m_windowCursor = cursor;
584 if (m_windowCursor.Ok())
585 {
586 HWND hWnd = (HWND) GetHWND();
2bda0e17 587
2d0a075d
JS
588 // Change the cursor NOW if we're within the correct window
589 POINT point;
590 ::GetCursorPos(&point);
2bda0e17 591
2d0a075d
JS
592 RECT rect;
593 ::GetWindowRect(hWnd, &rect);
2bda0e17 594
2d0a075d
JS
595 if (::PtInRect(&rect, point) && !wxIsBusy())
596 ::SetCursor((HCURSOR) m_windowCursor.GetHCURSOR());
597 }
2bda0e17 598
2d0a075d
JS
599 // This will cause big reentrancy problems if wxFlushEvents is implemented.
600 // wxFlushEvents();
601 // return old_cursor;
2bda0e17
KB
602}
603
604
605// Get size *available for subwindows* i.e. excluding menu bar etc.
2bda0e17
KB
606void wxWindow::GetClientSize(int *x, int *y) const
607{
2d0a075d
JS
608 HWND hWnd = (HWND) GetHWND();
609 RECT rect;
610 GetClientRect(hWnd, &rect);
611 *x = rect.right;
612 *y = rect.bottom;
2bda0e17
KB
613}
614
debe6624 615void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags)
2bda0e17 616{
2d0a075d
JS
617 int currentX, currentY;
618 GetPosition(&currentX, &currentY);
72fd19a1
JS
619 int currentW,currentH;
620 GetSize(&currentW, &currentH);
621
622 if (x == currentX && y == currentY && width == currentW && height == currentH)
623 return;
624
2d0a075d
JS
625 int actualWidth = width;
626 int actualHeight = height;
627 int actualX = x;
628 int actualY = y;
629 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
630 actualX = currentX;
631 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
632 actualY = currentY;
633
634 AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
635
2d0a075d
JS
636 if (width == -1)
637 actualWidth = currentW ;
638 if (height == -1)
639 actualHeight = currentH ;
81d66cf3 640
2d0a075d
JS
641 HWND hWnd = (HWND) GetHWND();
642 if (hWnd)
643 MoveWindow(hWnd, actualX, actualY, actualWidth, actualHeight, (BOOL)TRUE);
2bda0e17
KB
644}
645
debe6624 646void wxWindow::SetClientSize(int width, int height)
2bda0e17 647{
2d0a075d
JS
648 wxWindow *parent = GetParent();
649 HWND hWnd = (HWND) GetHWND();
650 HWND hParentWnd = (HWND) (HWND) parent->GetHWND();
2bda0e17 651
2d0a075d
JS
652 RECT rect;
653 GetClientRect(hWnd, &rect);
2bda0e17 654
2d0a075d
JS
655 RECT rect2;
656 GetWindowRect(hWnd, &rect2);
2bda0e17 657
2d0a075d
JS
658 // Find the difference between the entire window (title bar and all)
659 // and the client area; add this to the new client size to move the
660 // window
661 int actual_width = rect2.right - rect2.left - rect.right + width;
662 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
2bda0e17 663
2d0a075d
JS
664 // If there's a parent, must subtract the parent's top left corner
665 // since MoveWindow moves relative to the parent
2bda0e17 666
2d0a075d
JS
667 POINT point;
668 point.x = rect2.left;
669 point.y = rect2.top;
670 if (parent)
671 {
672 ::ScreenToClient(hParentWnd, &point);
673 }
2bda0e17 674
2d0a075d 675 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
debe6624 676
2d0a075d
JS
677 wxSizeEvent event(wxSize(width, height), m_windowId);
678 event.SetEventObject(this);
679 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
680}
681
81d66cf3
JS
682// For implementation purposes - sometimes decorations make the client area
683// smaller
684wxPoint wxWindow::GetClientAreaOrigin() const
685{
686 return wxPoint(0, 0);
687}
688
689// Makes an adjustment to the window position (for example, a frame that has
690// a toolbar that it manages itself).
691void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
692{
693 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
694 {
695 wxPoint pt(GetParent()->GetClientAreaOrigin());
696 x += pt.x; y += pt.y;
697 }
698}
699
debe6624 700bool wxWindow::Show(bool show)
2bda0e17 701{
2d0a075d
JS
702 HWND hWnd = (HWND) GetHWND();
703 int cshow;
704 if (show)
705 cshow = SW_SHOW;
706 else
707 cshow = SW_HIDE;
708 ShowWindow(hWnd, (BOOL)cshow);
709 if (show)
710 {
711 BringWindowToTop(hWnd);
712 // Next line causes a crash on NT, apparently.
713 // UpdateWindow(hWnd); // Should this be here or will it cause inefficiency?
714 }
715 return TRUE;
2bda0e17
KB
716}
717
718bool wxWindow::IsShown(void) const
719{
2d0a075d 720 return (::IsWindowVisible((HWND) GetHWND()) != 0);
2bda0e17
KB
721}
722
723int wxWindow::GetCharHeight(void) const
724{
2d0a075d
JS
725 TEXTMETRIC lpTextMetric;
726 HWND hWnd = (HWND) GetHWND();
727 HDC dc = ::GetDC(hWnd);
2bda0e17 728
2d0a075d
JS
729 GetTextMetrics(dc, &lpTextMetric);
730 ::ReleaseDC(hWnd, dc);
2bda0e17 731
2d0a075d 732 return lpTextMetric.tmHeight;
2bda0e17
KB
733}
734
735int wxWindow::GetCharWidth(void) const
736{
2d0a075d
JS
737 TEXTMETRIC lpTextMetric;
738 HWND hWnd = (HWND) GetHWND();
739 HDC dc = ::GetDC(hWnd);
2bda0e17 740
2d0a075d
JS
741 GetTextMetrics(dc, &lpTextMetric);
742 ::ReleaseDC(hWnd, dc);
2bda0e17 743
2d0a075d 744 return lpTextMetric.tmAveCharWidth;
2bda0e17
KB
745}
746
747void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
2d0a075d 748 int *descent, int *externalLeading, const wxFont *theFont, bool) const
2bda0e17 749{
2d0a075d
JS
750 wxFont *fontToUse = (wxFont *)theFont;
751 if (!fontToUse)
752 fontToUse = (wxFont *) & m_windowFont;
2bda0e17 753
2d0a075d
JS
754 HWND hWnd = (HWND) GetHWND();
755 HDC dc = ::GetDC(hWnd);
2bda0e17 756
c085e333 757 HFONT fnt = 0;
2d0a075d
JS
758 HFONT was = 0;
759 if (fontToUse && fontToUse->Ok())
760 {
fd3f686c
VZ
761 fnt = (HFONT)fontToUse->GetResourceHandle();
762 if ( fnt )
2d0a075d
JS
763 was = (HFONT) SelectObject(dc,fnt) ;
764 }
2bda0e17 765
2d0a075d
JS
766 SIZE sizeRect;
767 TEXTMETRIC tm;
768 GetTextExtentPoint(dc, (const char *)string, (int)string.Length(), &sizeRect);
769 GetTextMetrics(dc, &tm);
2bda0e17 770
c085e333 771 if (fontToUse && fnt && was)
2d0a075d 772 SelectObject(dc,was) ;
2bda0e17 773
2d0a075d 774 ReleaseDC(hWnd, dc);
2bda0e17 775
2d0a075d
JS
776 *x = sizeRect.cx;
777 *y = sizeRect.cy;
778 if (descent) *descent = tm.tmDescent;
779 if (externalLeading) *externalLeading = tm.tmExternalLeading;
2bda0e17 780
2d0a075d
JS
781 // if (fontToUse)
782 // fontToUse->ReleaseResource();
2bda0e17
KB
783}
784
16e93305 785void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
2bda0e17 786{
2d0a075d
JS
787 HWND hWnd = (HWND) GetHWND();
788 if (hWnd)
2bda0e17 789 {
2d0a075d
JS
790 if (rect)
791 {
792 RECT mswRect;
793 mswRect.left = rect->x;
794 mswRect.top = rect->y;
795 mswRect.right = rect->x + rect->width;
796 mswRect.bottom = rect->y + rect->height;
797
798 ::InvalidateRect(hWnd, &mswRect, eraseBack);
799 }
800 else
801 ::InvalidateRect(hWnd, NULL, eraseBack);
2bda0e17 802 }
2bda0e17
KB
803}
804
a02eb1d2
VZ
805bool wxWindow::ProcessEvent(wxEvent& event)
806{
2d0a075d
JS
807 // we save here the information about the last message because it might be
808 // overwritten if the event handler sends any messages to our window (case
809 // in point: wxNotebook::OnSize) - and then if we call Default() later
810 // (which is done quite often if the message is not processed) it will use
811 // incorrect values for m_lastXXX variables
812 WXUINT lastMsg = m_lastMsg;
813 WXWPARAM lastWParam = m_lastWParam;
814 WXLPARAM lastLParam = m_lastLParam;
a02eb1d2 815
2d0a075d
JS
816 // call the base version
817 bool bProcessed = wxEvtHandler::ProcessEvent(event);
a02eb1d2 818
2d0a075d
JS
819 // restore
820 m_lastMsg = lastMsg;
821 m_lastWParam = lastWParam;
822 m_lastLParam = lastLParam;
a02eb1d2 823
2d0a075d 824 return bProcessed;
a02eb1d2
VZ
825}
826
2bda0e17
KB
827// Hook for new window just as it's being created,
828// when the window isn't yet associated with the handle
829wxWindow *wxWndHook = NULL;
830
1c089c47 831// Main window proc
2bda0e17
KB
832LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
833{
2d0a075d 834 wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd);
2bda0e17 835
2d0a075d
JS
836 if (!wnd && wxWndHook)
837 {
838 wxAssociateWinWithHandle(hWnd, wxWndHook);
839 wnd = wxWndHook;
840 wxWndHook = NULL;
841 wnd->m_hWnd = (WXHWND) hWnd;
842 }
ea57084d
JS
843 // wxDebugMsg("hWnd = %d, m_hWnd = %d, msg = %d\n", hWnd, m_hWnd, message);
844
2d0a075d
JS
845 // Stop right here if we don't have a valid handle
846 // in our wxWnd object.
847 if (wnd && !wnd->m_hWnd) {
848 // wxDebugMsg("Warning: could not find a valid handle, wx_win.cc/wxWndProc.\n");
849 wnd->m_hWnd = (WXHWND) hWnd;
850 long res = wnd->MSWDefWindowProc(message, wParam, lParam );
851 wnd->m_hWnd = 0;
852 return res;
853 }
2bda0e17 854
2d0a075d
JS
855 if (wnd) {
856 wnd->m_lastMsg = message;
857 wnd->m_lastWParam = wParam;
858 wnd->m_lastLParam = lParam;
859 }
860 if (wnd)
861 return wnd->MSWWindowProc(message, wParam, lParam);
862 else
863 return DefWindowProc( hWnd, message, wParam, lParam );
2bda0e17
KB
864}
865
866// Should probably have a test for 'genuine' NT
867#if defined(__WIN32__)
868#define DIMENSION_TYPE short
869#else
870#define DIMENSION_TYPE int
871#endif
872
873// Main Windows 3 window proc
874long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
875{
2d0a075d
JS
876 wxASSERT( m_lastMsg == message &&
877 m_lastWParam == wParam &&
878 m_lastLParam == lParam );
5de76427 879
2d0a075d 880#ifdef __WXDEBUG__
a02eb1d2 881 wxLogTrace(wxTraceMessages, "Processing %s(%lx, %lx)",
2d0a075d 882 wxGetMessageName(message), wParam, lParam);
ea57084d 883#endif // __WXDEBUG__
c085e333 884
2d0a075d 885 HWND hWnd = (HWND)m_hWnd;
2bda0e17 886
2d0a075d
JS
887 switch (message)
888 {
889 case WM_ACTIVATE:
2bda0e17
KB
890 {
891#ifdef __WIN32__
892 WORD state = LOWORD(wParam);
893 WORD minimized = HIWORD(wParam);
894 HWND hwnd = (HWND)lParam;
895#else
896 WORD state = (WORD)wParam;
897 WORD minimized = LOWORD(lParam);
898 HWND hwnd = (HWND)HIWORD(lParam);
899#endif
900 MSWOnActivate(state, (minimized != 0), (WXHWND) hwnd);
901 return 0;
902 break;
903 }
2d0a075d 904 case WM_SETFOCUS:
2bda0e17
KB
905 {
906 HWND hwnd = (HWND)wParam;
2d0a075d 907 // return OnSetFocus(hwnd);
2bda0e17
KB
908
909 if (MSWOnSetFocus((WXHWND) hwnd))
2d0a075d 910 return 0;
2bda0e17
KB
911 else return MSWDefWindowProc(message, wParam, lParam );
912 break;
913 }
2d0a075d 914 case WM_KILLFOCUS:
2bda0e17
KB
915 {
916 HWND hwnd = (HWND)lParam;
2d0a075d 917 // return OnKillFocus(hwnd);
2bda0e17 918 if (MSWOnKillFocus((WXHWND) hwnd))
2d0a075d 919 return 0;
2bda0e17 920 else
2d0a075d 921 return MSWDefWindowProc(message, wParam, lParam );
2bda0e17
KB
922 break;
923 }
2d0a075d 924 case WM_CREATE:
47cbd6da 925 {
2d0a075d
JS
926 MSWOnCreate((WXLPCREATESTRUCT) (LPCREATESTRUCT)lParam);
927 return 0;
928 break;
47cbd6da 929 }
2d0a075d 930 case WM_SHOWWINDOW:
47cbd6da 931 {
2d0a075d
JS
932 MSWOnShow((wParam != 0), (int) lParam);
933 break;
47cbd6da 934 }
2d0a075d 935 case WM_PAINT:
47cbd6da 936 {
2d0a075d
JS
937 if (MSWOnPaint())
938 return 0;
939 else return MSWDefWindowProc(message, wParam, lParam );
940 break;
2bda0e17 941 }
2d0a075d 942 case WM_QUERYDRAGICON:
47cbd6da 943 {
fd3f686c
VZ
944 HICON hIcon = (HICON)MSWOnQueryDragIcon();
945 if ( hIcon )
2d0a075d 946 return (long)hIcon;
fd3f686c
VZ
947 else
948 return MSWDefWindowProc(message, wParam, lParam );
2d0a075d 949 break;
2bda0e17 950 }
c085e333 951
2d0a075d 952 case WM_SIZE:
2bda0e17 953 {
2d0a075d
JS
954 int width = LOWORD(lParam);
955 int height = HIWORD(lParam);
956 MSWOnSize(width, height, wParam);
957 break;
2bda0e17 958 }
c085e333 959
2d0a075d
JS
960 case WM_MOVE:
961 {
568cb543 962 wxMoveEvent event(wxPoint(LOWORD(lParam), HIWORD(lParam)),
2d0a075d 963 m_windowId);
568cb543
VZ
964 event.SetEventObject(this);
965 if ( !GetEventHandler()->ProcessEvent(event) )
2d0a075d
JS
966 Default();
967 }
968 break;
568cb543 969
2d0a075d 970 case WM_WINDOWPOSCHANGING:
2bda0e17 971 {
2d0a075d
JS
972 MSWOnWindowPosChanging((void *)lParam);
973 break;
2bda0e17 974 }
c085e333 975
2d0a075d 976 case WM_RBUTTONDOWN:
2bda0e17
KB
977 {
978 int x = (DIMENSION_TYPE) LOWORD(lParam);
979 int y = (DIMENSION_TYPE) HIWORD(lParam);
980 MSWOnRButtonDown(x, y, wParam);
981 break;
982 }
2d0a075d 983 case WM_RBUTTONUP:
2bda0e17
KB
984 {
985 int x = (DIMENSION_TYPE) LOWORD(lParam);
986 int y = (DIMENSION_TYPE) HIWORD(lParam);
987 MSWOnRButtonUp(x, y, wParam);
988 break;
989 }
2d0a075d 990 case WM_RBUTTONDBLCLK:
2bda0e17
KB
991 {
992 int x = (DIMENSION_TYPE) LOWORD(lParam);
993 int y = (DIMENSION_TYPE) HIWORD(lParam);
994 MSWOnRButtonDClick(x, y, wParam);
995 break;
996 }
2d0a075d 997 case WM_MBUTTONDOWN:
2bda0e17
KB
998 {
999 int x = (DIMENSION_TYPE) LOWORD(lParam);
1000 int y = (DIMENSION_TYPE) HIWORD(lParam);
1001 MSWOnMButtonDown(x, y, wParam);
1002 break;
1003 }
2d0a075d 1004 case WM_MBUTTONUP:
2bda0e17
KB
1005 {
1006 int x = (DIMENSION_TYPE) LOWORD(lParam);
1007 int y = (DIMENSION_TYPE) HIWORD(lParam);
1008 MSWOnMButtonUp(x, y, wParam);
1009 break;
1010 }
2d0a075d 1011 case WM_MBUTTONDBLCLK:
2bda0e17
KB
1012 {
1013 int x = (DIMENSION_TYPE) LOWORD(lParam);
1014 int y = (DIMENSION_TYPE) HIWORD(lParam);
1015 MSWOnMButtonDClick(x, y, wParam);
1016 break;
1017 }
2d0a075d 1018 case WM_LBUTTONDOWN:
2bda0e17
KB
1019 {
1020 int x = (DIMENSION_TYPE) LOWORD(lParam);
1021 int y = (DIMENSION_TYPE) HIWORD(lParam);
1022 MSWOnLButtonDown(x, y, wParam);
1023 break;
1024 }
2d0a075d 1025 case WM_LBUTTONUP:
2bda0e17
KB
1026 {
1027 int x = (DIMENSION_TYPE) LOWORD(lParam);
1028 int y = (DIMENSION_TYPE) HIWORD(lParam);
1029 MSWOnLButtonUp(x, y, wParam);
1030 break;
1031 }
2d0a075d 1032 case WM_LBUTTONDBLCLK:
2bda0e17
KB
1033 {
1034 int x = (DIMENSION_TYPE) LOWORD(lParam);
1035 int y = (DIMENSION_TYPE) HIWORD(lParam);
1036 MSWOnLButtonDClick(x, y, wParam);
1037 break;
1038 }
2d0a075d 1039 case WM_MOUSEMOVE:
2bda0e17
KB
1040 {
1041 int x = (DIMENSION_TYPE) LOWORD(lParam);
1042 int y = (DIMENSION_TYPE) HIWORD(lParam);
1043 MSWOnMouseMove(x, y, wParam);
1044 break;
1045 }
2d0a075d 1046 case MM_JOY1BUTTONDOWN:
2bda0e17
KB
1047 {
1048 int x = LOWORD(lParam);
1049 int y = HIWORD(lParam);
1050 MSWOnJoyDown(wxJOYSTICK1, x, y, wParam);
1051 break;
1052 }
2d0a075d 1053 case MM_JOY2BUTTONDOWN:
2bda0e17
KB
1054 {
1055 int x = LOWORD(lParam);
1056 int y = HIWORD(lParam);
1057 MSWOnJoyDown(wxJOYSTICK2, x, y, wParam);
1058 break;
1059 }
2d0a075d 1060 case MM_JOY1BUTTONUP:
2bda0e17
KB
1061 {
1062 int x = LOWORD(lParam);
1063 int y = HIWORD(lParam);
1064 MSWOnJoyUp(wxJOYSTICK1, x, y, wParam);
1065 break;
1066 }
2d0a075d 1067 case MM_JOY2BUTTONUP:
2bda0e17
KB
1068 {
1069 int x = LOWORD(lParam);
1070 int y = HIWORD(lParam);
1071 MSWOnJoyUp(wxJOYSTICK2, x, y, wParam);
1072 break;
1073 }
2d0a075d 1074 case MM_JOY1MOVE:
2bda0e17
KB
1075 {
1076 int x = LOWORD(lParam);
1077 int y = HIWORD(lParam);
1078 MSWOnJoyMove(wxJOYSTICK1, x, y, wParam);
1079 break;
1080 }
2d0a075d 1081 case MM_JOY2MOVE:
2bda0e17
KB
1082 {
1083 int x = LOWORD(lParam);
1084 int y = HIWORD(lParam);
1085 MSWOnJoyMove(wxJOYSTICK2, x, y, wParam);
1086 break;
1087 }
2d0a075d 1088 case MM_JOY1ZMOVE:
2bda0e17
KB
1089 {
1090 int z = LOWORD(lParam);
1091 MSWOnJoyZMove(wxJOYSTICK1, z, wParam);
1092 break;
1093 }
2d0a075d 1094 case MM_JOY2ZMOVE:
2bda0e17
KB
1095 {
1096 int z = LOWORD(lParam);
1097 MSWOnJoyZMove(wxJOYSTICK2, z, wParam);
1098 break;
1099 }
2d0a075d 1100 case WM_DESTROY:
2bda0e17 1101 {
2d0a075d
JS
1102 if (MSWOnDestroy())
1103 return 0;
1104 else return MSWDefWindowProc(message, wParam, lParam );
1105 break;
2bda0e17 1106 }
2d0a075d 1107 case WM_SYSCOMMAND:
2bda0e17
KB
1108 {
1109 return MSWOnSysCommand(wParam, lParam);
1110 break;
1111 }
2d0a075d 1112 case WM_COMMAND:
47cbd6da 1113 {
2bda0e17
KB
1114#ifdef __WIN32__
1115 WORD id = LOWORD(wParam);
1116 HWND hwnd = (HWND)lParam;
1117 WORD cmd = HIWORD(wParam);
1118#else
1119 WORD id = (WORD)wParam;
1120 HWND hwnd = (HWND)LOWORD(lParam) ;
1121 WORD cmd = HIWORD(lParam);
1122#endif
1123 if (!MSWOnCommand(id, cmd, (WXHWND) hwnd))
2d0a075d 1124 return MSWDefWindowProc(message, wParam, lParam );
2bda0e17 1125 break;
47cbd6da 1126 }
2bda0e17 1127#if defined(__WIN95__)
2d0a075d 1128 case WM_NOTIFY:
47cbd6da 1129 {
fd3f686c
VZ
1130 // for some messages (TVN_ITEMEXPANDING for example), the return
1131 // value of WM_NOTIFY handler is important, so don't just return 0
1132 // if we processed the message
1133 return MSWOnNotify(wParam, lParam);
2bda0e17
KB
1134 }
1135#endif
2d0a075d 1136 case WM_MENUSELECT:
2bda0e17
KB
1137 {
1138#ifdef __WIN32__
1139 WORD flags = HIWORD(wParam);
1140 HMENU sysmenu = (HMENU)lParam;
1141#else
1142 WORD flags = LOWORD(lParam);
1143 HMENU sysmenu = (HMENU)HIWORD(lParam);
1144#endif
1145 MSWOnMenuHighlight((WORD)wParam, flags, (WXHMENU) sysmenu);
1146 break;
1147 }
2d0a075d 1148 case WM_INITMENUPOPUP:
2bda0e17
KB
1149 {
1150 MSWOnInitMenuPopup((WXHMENU) (HMENU)wParam, (int)LOWORD(lParam), (HIWORD(lParam) != 0));
1151 break;
1152 }
2d0a075d 1153 case WM_DRAWITEM:
2bda0e17 1154 {
2d0a075d
JS
1155 return MSWOnDrawItem((int)wParam, (WXDRAWITEMSTRUCT *)lParam);
1156 break;
2bda0e17 1157 }
2d0a075d 1158 case WM_MEASUREITEM:
2bda0e17 1159 {
2d0a075d
JS
1160 return MSWOnMeasureItem((int)wParam, (WXMEASUREITEMSTRUCT *)lParam);
1161 break;
2bda0e17 1162 }
c085e333 1163
2d0a075d
JS
1164 case WM_KEYDOWN:
1165 // we consider these message "not interesting"
1166 if ( wParam == VK_SHIFT || wParam == VK_CONTROL )
1167 return Default();
1168
1169 // Avoid duplicate messages to OnChar
1170 if ( (wParam != VK_ESCAPE) && (wParam != VK_SPACE) &&
1171 (wParam != VK_RETURN) && (wParam != VK_BACK) &&
1172 (wParam != VK_TAB) )
1173 {
1174 MSWOnChar((WORD)wParam, lParam);
1175 if ( ::GetKeyState(VK_CONTROL) & 0x100 )
47cbd6da 1176 return Default();
2d0a075d
JS
1177 }
1178 else if ( ::GetKeyState(VK_CONTROL) & 0x100 )
1179 MSWOnChar((WORD)wParam, lParam);
1180 else
1181 return Default();
1182 break;
47cbd6da 1183
2d0a075d
JS
1184 case WM_CHAR: // Always an ASCII character
1185 {
47cbd6da
VZ
1186 MSWOnChar((WORD)wParam, lParam, TRUE);
1187 break;
2d0a075d 1188 }
f54f3bff 1189
2d0a075d 1190 case WM_HSCROLL:
2bda0e17
KB
1191 {
1192#ifdef __WIN32__
1193 WORD code = LOWORD(wParam);
1194 WORD pos = HIWORD(wParam);
1195 HWND control = (HWND)lParam;
1196#else
1197 WORD code = (WORD)wParam;
1198 WORD pos = LOWORD(lParam);
1199 HWND control = (HWND)HIWORD(lParam);
1200#endif
1201 MSWOnHScroll(code, pos, (WXHWND) control);
1202 break;
1203 }
2d0a075d 1204 case WM_VSCROLL:
2bda0e17
KB
1205 {
1206#ifdef __WIN32__
1207 WORD code = LOWORD(wParam);
1208 WORD pos = HIWORD(wParam);
1209 HWND control = (HWND)lParam;
1210#else
1211 WORD code = (WORD)wParam;
1212 WORD pos = LOWORD(lParam);
1213 HWND control = (HWND)HIWORD(lParam);
1214#endif
1215 MSWOnVScroll(code, pos, (WXHWND) control);
1216 break;
1217 }
1218#ifdef __WIN32__
2d0a075d 1219 case WM_CTLCOLORBTN:
47cbd6da 1220 {
2d0a075d
JS
1221 int nCtlColor = CTLCOLOR_BTN;
1222 HWND control = (HWND)lParam;
1223 HDC pDC = (HDC)wParam;
1224 return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor,
1225 message, wParam, lParam);
1226 break;
47cbd6da 1227 }
2d0a075d 1228 case WM_CTLCOLORDLG:
47cbd6da 1229 {
2d0a075d
JS
1230 int nCtlColor = CTLCOLOR_DLG;
1231 HWND control = (HWND)lParam;
1232 HDC pDC = (HDC)wParam;
1233 return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor,
1234 message, wParam, lParam);\
1235 break;
47cbd6da 1236 }
2d0a075d 1237 case WM_CTLCOLORLISTBOX:
47cbd6da 1238 {
2d0a075d
JS
1239 int nCtlColor = CTLCOLOR_LISTBOX;
1240 HWND control = (HWND)lParam;
1241 HDC pDC = (HDC)wParam;
1242 return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor,
1243 message, wParam, lParam);
1244 break;
47cbd6da 1245 }
2d0a075d 1246 case WM_CTLCOLORMSGBOX:
47cbd6da 1247 {
2d0a075d
JS
1248 int nCtlColor = CTLCOLOR_MSGBOX;
1249 HWND control = (HWND)lParam;
1250 HDC pDC = (HDC)wParam;
1251 return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor,
1252 message, wParam, lParam);
1253 break;
47cbd6da 1254 }
2d0a075d 1255 case WM_CTLCOLORSCROLLBAR:
47cbd6da 1256 {
2d0a075d
JS
1257 int nCtlColor = CTLCOLOR_SCROLLBAR;
1258 HWND control = (HWND)lParam;
1259 HDC pDC = (HDC)wParam;
1260 return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor,
1261 message, wParam, lParam);
1262 break;
47cbd6da 1263 }
2d0a075d 1264 case WM_CTLCOLORSTATIC:
47cbd6da 1265 {
2d0a075d
JS
1266 int nCtlColor = CTLCOLOR_STATIC;
1267 HWND control = (HWND)lParam;
1268 HDC pDC = (HDC)wParam;
1269 return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor,
1270 message, wParam, lParam);
1271 break;
47cbd6da 1272 }
2d0a075d 1273 case WM_CTLCOLOREDIT:
47cbd6da 1274 {
2d0a075d
JS
1275 int nCtlColor = CTLCOLOR_EDIT;
1276 HWND control = (HWND)lParam;
1277 HDC pDC = (HDC)wParam;
1278 return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor,
1279 message, wParam, lParam);
1280 break;
47cbd6da 1281 }
2bda0e17 1282#else
2d0a075d 1283 case WM_CTLCOLOR:
2bda0e17 1284 {
2d0a075d
JS
1285 HWND control = (HWND)LOWORD(lParam);
1286 int nCtlColor = (int)HIWORD(lParam);
1287 HDC pDC = (HDC)wParam;
1288 return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor,
1289 message, wParam, lParam);
1290 break;
2bda0e17
KB
1291 }
1292#endif
2d0a075d 1293 case WM_SYSCOLORCHANGE:
2bda0e17 1294 {
2d0a075d
JS
1295 // Return value of 0 means, we processed it.
1296 if (MSWOnColorChange((WXHWND) hWnd, message, wParam, lParam) == 0)
1297 return 0;
1298 else
1299 return MSWDefWindowProc(message, wParam, lParam );
1300 break;
2bda0e17 1301 }
2d0a075d 1302 case WM_PALETTECHANGED:
f7bd2698
JS
1303 {
1304 return MSWOnPaletteChanged((WXHWND) (HWND) wParam);
1305 break;
1306 }
2d0a075d 1307 case WM_QUERYNEWPALETTE:
f7bd2698
JS
1308 {
1309 return MSWOnQueryNewPalette();
1310 break;
1311 }
2d0a075d 1312 case WM_ERASEBKGND:
2bda0e17 1313 {
2d0a075d
JS
1314 // Prevents flicker when dragging
1315 if (IsIconic(hWnd)) return 1;
2bda0e17 1316
2d0a075d
JS
1317 if (!MSWOnEraseBkgnd((WXHDC) (HDC)wParam))
1318 return 0; // Default(); MSWDefWindowProc(message, wParam, lParam );
1319 else return 1;
1320 break;
2bda0e17 1321 }
2d0a075d 1322 case WM_MDIACTIVATE:
2bda0e17
KB
1323 {
1324#ifdef __WIN32__
1325 HWND hWndActivate = GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam,lParam);
1326 HWND hWndDeactivate = GET_WM_MDIACTIVATE_HWNDDEACT(wParam,lParam);
1327 BOOL activate = GET_WM_MDIACTIVATE_FACTIVATE(hWnd,wParam,lParam);
1328 return MSWOnMDIActivate((long) activate, (WXHWND) hWndActivate, (WXHWND) hWndDeactivate);
1329#else
1330 return MSWOnMDIActivate((BOOL)wParam, (HWND)LOWORD(lParam),
2d0a075d 1331 (HWND)HIWORD(lParam));
2bda0e17
KB
1332#endif
1333 }
2d0a075d 1334 case WM_DROPFILES:
2bda0e17
KB
1335 {
1336 MSWOnDropFiles(wParam);
1337 break;
47cbd6da 1338 }
2d0a075d 1339 case WM_INITDIALOG:
2bda0e17
KB
1340 {
1341 return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam);
1342 break;
47cbd6da 1343 }
2d0a075d 1344 case WM_QUERYENDSESSION:
2bda0e17 1345 {
47cbd6da 1346 // Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
2d0a075d 1347 // return MSWOnClose();
387a3b02
JS
1348
1349 return MSWOnQueryEndSession(lParam);
1350 break;
1351 }
2d0a075d 1352 case WM_ENDSESSION:
387a3b02
JS
1353 {
1354 // Same as WM_CLOSE, but inverted results. Thx Microsoft :-)
1355 MSWOnEndSession((wParam != 0), lParam);
1356 return 0L;
2bda0e17
KB
1357 break;
1358 }
2d0a075d 1359 case WM_CLOSE:
2bda0e17
KB
1360 {
1361 if (MSWOnClose())
2d0a075d 1362 return 0L;
2bda0e17 1363 else
2d0a075d 1364 return 1L;
2bda0e17
KB
1365 break;
1366 }
c085e333 1367
2d0a075d 1368 case WM_GETMINMAXINFO:
2bda0e17 1369 {
2d0a075d
JS
1370 MINMAXINFO *info = (MINMAXINFO *)lParam;
1371 if (m_minSizeX != -1)
1372 info->ptMinTrackSize.x = (int)m_minSizeX;
1373 if (m_minSizeY != -1)
1374 info->ptMinTrackSize.y = (int)m_minSizeY;
1375 if (m_maxSizeX != -1)
1376 info->ptMaxTrackSize.x = (int)m_maxSizeX;
1377 if (m_maxSizeY != -1)
1378 info->ptMaxTrackSize.y = (int)m_maxSizeY;
1379 return MSWDefWindowProc(message, wParam, lParam );
1380 break;
2bda0e17 1381 }
c085e333 1382
2d0a075d
JS
1383 case WM_GETDLGCODE:
1384 return MSWGetDlgCode();
2bda0e17 1385
2d0a075d
JS
1386 default:
1387 return MSWDefWindowProc(message, wParam, lParam );
2bda0e17
KB
1388 }
1389 return 0; // Success: we processed this command.
1390}
1391
1392// Dialog window proc
1393LONG APIENTRY _EXPORT
2d0a075d 1394wxDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
2bda0e17 1395{
2d0a075d 1396 return 0;
2bda0e17
KB
1397}
1398
1399wxList *wxWinHandleList = NULL;
1400wxWindow *wxFindWinFromHandle(WXHWND hWnd)
1401{
2d0a075d
JS
1402 wxNode *node = wxWinHandleList->Find((long)hWnd);
1403 if (!node)
1404 return NULL;
1405 return (wxWindow *)node->Data();
2bda0e17
KB
1406}
1407
1408void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win)
1409{
2d0a075d
JS
1410 // adding NULL hWnd is (first) surely a result of an error and
1411 // (secondly) breaks menu command processing
1412 wxCHECK_RET( hWnd != NULL, "attempt to add a NULL hWnd to window list" );
195896c7 1413
2d0a075d
JS
1414 if ( !wxWinHandleList->Find((long)hWnd) )
1415 wxWinHandleList->Append((long)hWnd, win);
2bda0e17
KB
1416}
1417
1418void wxRemoveHandleAssociation(wxWindow *win)
1419{
2d0a075d 1420 wxWinHandleList->DeleteObject(win);
2bda0e17
KB
1421}
1422
1423// Default destroyer - override if you destroy it in some other way
1424// (e.g. with MDI child windows)
fd3f686c 1425void wxWindow::MSWDestroyWindow()
2bda0e17 1426{
2bda0e17
KB
1427}
1428
debe6624 1429void wxWindow::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title,
2d0a075d
JS
1430 int x, int y, int width, int height,
1431 WXDWORD style, const char *dialog_template, WXDWORD extendedStyle)
1432{
1433 bool is_dialog = (dialog_template != NULL);
1434 int x1 = CW_USEDEFAULT;
1435 int y1 = 0;
1436 int width1 = CW_USEDEFAULT;
1437 int height1 = 100;
1438
1439 // Find parent's size, if it exists, to set up a possible default
1440 // panel size the size of the parent window
1441 RECT parent_rect;
1442 if (parent)
1443 {
1444 // Was GetWindowRect: JACS 5/5/95
1445 ::GetClientRect((HWND) parent->GetHWND(), &parent_rect);
2bda0e17 1446
2d0a075d
JS
1447 width1 = parent_rect.right - parent_rect.left;
1448 height1 = parent_rect.bottom - parent_rect.top;
1449 }
2bda0e17 1450
2d0a075d
JS
1451 if (x > -1) x1 = x;
1452 if (y > -1) y1 = y;
1453 if (width > -1) width1 = width;
1454 if (height > -1) height1 = height;
2bda0e17 1455
2d0a075d
JS
1456 HWND hParent = NULL;
1457 if (parent)
1458 hParent = (HWND) parent->GetHWND();
2bda0e17 1459
2d0a075d 1460 wxWndHook = this;
2bda0e17 1461
2d0a075d
JS
1462 if (is_dialog)
1463 {
1464 // MakeProcInstance doesn't seem to be needed in C7. Is it needed for
1465 // other compilers???
1466 // VZ: it's always needed for Win16 and never for Win32
2bda0e17 1467#ifdef __WIN32__
2d0a075d
JS
1468 m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent,
1469 (DLGPROC)wxDlgProc);
2bda0e17 1470#else
f60d0f94
JS
1471 // N.B.: if we _don't_ use this form,
1472 // then with VC++ 1.5, it crashes horribly.
1473#if 1
1474 m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent,
1475 (DLGPROC)wxDlgProc);
1476#else
1477 // Crashes when we use this.
2d0a075d 1478 DLGPROC dlgproc = (DLGPROC)MakeProcInstance((DLGPROC)wxWndProc, wxGetInstance());
2bda0e17 1479
2d0a075d
JS
1480 m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent,
1481 (DLGPROC)dlgproc);
f60d0f94 1482#endif
2bda0e17 1483#endif
c085e333 1484
2d0a075d
JS
1485 if (m_hWnd == 0)
1486 MessageBox(NULL, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.",
1487 "wxWindows Error", MB_ICONEXCLAMATION | MB_OK);
1488 else MoveWindow((HWND) m_hWnd, x1, y1, width1, height1, FALSE);
1489 }
1490 else
1491 {
1492 int controlId = 0;
1493 if (style & WS_CHILD)
1494 controlId = id;
1495 if (!title)
1496 title = "";
1497
1498 m_hWnd = (WXHWND)CreateWindowEx(extendedStyle, wclass,
1499 title,
1500 style,
1501 x1, y1,
1502 width1, height1,
1503 hParent, (HMENU)controlId, wxGetInstance(),
1504 NULL);
1505
1506 if ( !m_hWnd ) {
1507 wxLogError("Can't create window of class %s!\n"
1508 "Possible Windows 3.x compatibility problem?", wclass);
1509 }
2bda0e17 1510 }
a02eb1d2 1511
2d0a075d
JS
1512 wxWndHook = NULL;
1513 wxWinHandleList->Append((long)m_hWnd, this);
2bda0e17
KB
1514}
1515
1516void wxWindow::MSWOnCreate(WXLPCREATESTRUCT WXUNUSED(cs))
1517{
1518}
1519
fd3f686c 1520bool wxWindow::MSWOnClose()
2bda0e17 1521{
2d0a075d 1522 return FALSE;
2bda0e17
KB
1523}
1524
3572173c
JS
1525// Some compilers don't define this
1526#ifndef ENDSESSION_LOGOFF
1527#define ENDSESSION_LOGOFF 0x80000000
1528#endif
1529
387a3b02
JS
1530// Return TRUE to end session, FALSE to veto end session.
1531bool wxWindow::MSWOnQueryEndSession(long logOff)
1532{
1533 wxCloseEvent event(wxEVT_QUERY_END_SESSION, -1);
1534 event.SetEventObject(wxTheApp);
1535 event.SetCanVeto(TRUE);
1536 event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) );
1537 if ((this == wxTheApp->GetTopWindow()) && // Only send once
2d0a075d 1538 wxTheApp->ProcessEvent(event) && event.GetVeto())
387a3b02
JS
1539 {
1540 return FALSE; // Veto!
1541 }
1542 else
1543 {
1544 return TRUE; // Don't veto
1545 }
1546}
1547
1548bool wxWindow::MSWOnEndSession(bool endSession, long logOff)
1549{
1550 wxCloseEvent event(wxEVT_END_SESSION, -1);
1551 event.SetEventObject(wxTheApp);
1552 event.SetCanVeto(FALSE);
1553 event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) );
1554 if (endSession && // No need to send if the session isn't ending
1555 (this == wxTheApp->GetTopWindow()) && // Only send once
2d0a075d 1556 wxTheApp->ProcessEvent(event))
387a3b02
JS
1557 {
1558 }
1559 return TRUE;
1560}
1561
fd3f686c 1562bool wxWindow::MSWOnDestroy()
2bda0e17 1563{
2d0a075d
JS
1564 // delete our drop target if we've got one
1565#if wxUSE_DRAG_AND_DROP
195896c7 1566 if ( m_pDropTarget != NULL ) {
2d0a075d 1567 m_pDropTarget->Revoke(m_hWnd);
2bda0e17 1568
2d0a075d
JS
1569 delete m_pDropTarget;
1570 m_pDropTarget = NULL;
2bda0e17 1571 }
2d0a075d 1572#endif
c085e333 1573
2d0a075d 1574 return TRUE;
2bda0e17
KB
1575}
1576
1577// Deal with child commands from buttons etc.
1578
fd3f686c 1579long wxWindow::MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam)
2bda0e17
KB
1580{
1581#if defined(__WIN95__)
1582 // Find a child window to send the notification to, e.g. a toolbar.
1583 // There's a problem here. NMHDR::hwndFrom doesn't give us the
1584 // handle of the toolbar; it's probably the handle of the tooltip
1585 // window (anyway, it's parent is also the toolbar's parent).
1586 // So, since we don't know which hWnd or wxWindow originated the
1587 // WM_NOTIFY, we'll need to go through all the children of this window
1588 // trying out MSWNotify.
2d0a075d
JS
1589 // This won't work now, though, because any number of controls
1590 // could respond to the same generic messages :-(
2bda0e17 1591
2d0a075d
JS
1592 /* This doesn't work for toolbars, but try for other controls first.
1593 */
2bda0e17
KB
1594 NMHDR *hdr = (NMHDR *)lParam;
1595 HWND hWnd = (HWND)hdr->hwndFrom;
1596 wxWindow *win = wxFindWinFromHandle((WXHWND) hWnd);
c085e333 1597
fd3f686c
VZ
1598 WXLPARAM result = 0;
1599
2d0a075d 1600 if ( win )
fd3f686c 1601 {
cf65ad8d
VZ
1602 if ( win->MSWNotify(wParam, lParam, &result) )
1603 return result;
fd3f686c 1604 }
2d0a075d
JS
1605 else
1606 {
564b2609 1607 // Rely on MSWNotify to check whether the message
2d0a075d 1608 // belongs to the window or not
c0ed460c 1609 wxNode *node = GetChildren().First();
564b2609
VZ
1610 while (node)
1611 {
1612 wxWindow *child = (wxWindow *)node->Data();
fd3f686c 1613 if ( child->MSWNotify(wParam, lParam, &result) )
cf65ad8d 1614 return result;
2d0a075d 1615 node = node->Next();
564b2609 1616 }
2bda0e17 1617
cf65ad8d
VZ
1618 // finally try this window too (catches toolbar case)
1619 if ( MSWNotify(wParam, lParam, &result) )
1620 return result;
1621 }
fd3f686c 1622#endif // Win95
c085e333 1623
cf65ad8d 1624 // not processed
2d0a075d 1625 return FALSE;
2bda0e17
KB
1626}
1627
debe6624 1628void wxWindow::MSWOnMenuHighlight(WXWORD WXUNUSED(item), WXWORD WXUNUSED(flags), WXHMENU WXUNUSED(sysmenu))
2bda0e17 1629{
2bda0e17
KB
1630}
1631
debe6624 1632void wxWindow::MSWOnInitMenuPopup(WXHMENU menu, int pos, bool isSystem)
2bda0e17 1633{
2bda0e17
KB
1634}
1635
debe6624 1636bool wxWindow::MSWOnActivate(int state, bool WXUNUSED(minimized), WXHWND WXUNUSED(activate))
2bda0e17 1637{
2d0a075d
JS
1638 wxActivateEvent event(wxEVT_ACTIVATE, ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)),
1639 m_windowId);
1640 event.SetEventObject(this);
1641 GetEventHandler()->ProcessEvent(event);
1642 return 0;
2bda0e17
KB
1643}
1644
debe6624 1645bool wxWindow::MSWOnSetFocus(WXHWND WXUNUSED(hwnd))
2bda0e17 1646{
2bda0e17
KB
1647 // Deal with caret
1648 if (m_caretEnabled && (m_caretWidth > 0) && (m_caretHeight > 0))
1649 {
2d0a075d
JS
1650 ::CreateCaret((HWND) GetHWND(), NULL, m_caretWidth, m_caretHeight);
1651 if (m_caretShown)
1652 ::ShowCaret((HWND) GetHWND());
2bda0e17 1653 }
c085e333 1654
2d0a075d
JS
1655 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
1656 event.SetEventObject(this);
1657 if (!GetEventHandler()->ProcessEvent(event))
1658 Default();
1659 return TRUE;
2bda0e17
KB
1660}
1661
debe6624 1662bool wxWindow::MSWOnKillFocus(WXHWND WXUNUSED(hwnd))
2bda0e17 1663{
2bda0e17
KB
1664 // Deal with caret
1665 if (m_caretEnabled)
1666 {
2d0a075d 1667 ::DestroyCaret();
2bda0e17 1668 }
c085e333 1669
2d0a075d
JS
1670 wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId);
1671 event.SetEventObject(this);
1672 if (!GetEventHandler()->ProcessEvent(event))
1673 Default();
1674 return TRUE;
2bda0e17
KB
1675}
1676
debe6624 1677void wxWindow::MSWOnDropFiles(WXWPARAM wParam)
2bda0e17 1678{
c085e333 1679
2d0a075d
JS
1680 HDROP hFilesInfo = (HDROP) wParam;
1681 POINT dropPoint;
1682 DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
1683
1684 // Get the total number of files dropped
1685 WORD gwFilesDropped = (WORD)DragQueryFile ((HDROP)hFilesInfo,
1686 (UINT)-1,
1687 (LPSTR)0,
1688 (UINT)0);
1689
1690 wxString *files = new wxString[gwFilesDropped];
1691 int wIndex;
1692 for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++)
1693 {
1694 DragQueryFile (hFilesInfo, wIndex, (LPSTR) wxBuffer, 1000);
1695 files[wIndex] = wxBuffer;
1696 }
1697 DragFinish (hFilesInfo);
2bda0e17 1698
2d0a075d
JS
1699 wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files);
1700 event.m_eventObject = this;
1701 event.m_pos.x = dropPoint.x; event.m_pos.x = dropPoint.y;
2bda0e17 1702
2d0a075d
JS
1703 if (!GetEventHandler()->ProcessEvent(event))
1704 Default();
2bda0e17 1705
2d0a075d 1706 delete[] files;
2bda0e17
KB
1707}
1708
debe6624 1709bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
2bda0e17 1710{
47d67540 1711#if wxUSE_OWNER_DRAWN
2bda0e17 1712 if ( id == 0 ) { // is it a menu item?
2d0a075d
JS
1713 DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
1714 wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData);
1715 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
1716
1717 // prepare to call OnDrawItem()
1718 wxDC dc;
1719 dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE);
1720 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
1721 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
1722 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
1723 return pMenuItem->OnDrawItem(
1724 dc, rect,
1725 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
1726 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
1727 );
2bda0e17
KB
1728 }
1729#endif // owner-drawn menus
c085e333 1730
2d0a075d 1731 wxWindow *item = FindItem(id);
47d67540 1732#if wxUSE_DYNAMIC_CLASSES
2d0a075d
JS
1733 if (item && item->IsKindOf(CLASSINFO(wxControl)))
1734 {
1735 return ((wxControl *)item)->MSWOnDraw(itemStruct);
1736 }
1737 else
2bda0e17 1738#endif
2d0a075d 1739 return FALSE;
2bda0e17
KB
1740}
1741
debe6624 1742bool wxWindow::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
2bda0e17 1743{
47d67540 1744#if wxUSE_OWNER_DRAWN
2bda0e17 1745 if ( id == 0 ) { // is it a menu item?
2d0a075d
JS
1746 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
1747 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
1748 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
2bda0e17 1749
c085e333 1750 return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth,
2d0a075d 1751 &pMeasureStruct->itemHeight);
2bda0e17
KB
1752 }
1753#endif // owner-drawn menus
c085e333 1754
2d0a075d 1755 wxWindow *item = FindItem(id);
47d67540 1756#if wxUSE_DYNAMIC_CLASSES
2d0a075d
JS
1757 if (item && item->IsKindOf(CLASSINFO(wxControl)))
1758 {
1759 return ((wxControl *)item)->MSWOnMeasure(itemStruct);
1760 }
1761 else
2bda0e17 1762#endif
2d0a075d 1763 return FALSE;
2bda0e17
KB
1764}
1765
debe6624 1766WXHBRUSH wxWindow::MSWOnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
2d0a075d 1767 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 1768{
2d0a075d
JS
1769 if (nCtlColor == CTLCOLOR_DLG)
1770 {
1771 return OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
1772 }
2bda0e17 1773
2d0a075d 1774 wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE);
2bda0e17 1775
2d0a075d 1776 WXHBRUSH hBrush = 0;
2bda0e17 1777
2d0a075d
JS
1778 if ( item )
1779 hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2bda0e17 1780
2d0a075d
JS
1781 // I think that even for dialogs, we may need to call DefWindowProc (?)
1782 // Or maybe just rely on the usual default behaviour.
1783 if ( !hBrush )
1784 hBrush = (WXHBRUSH) MSWDefWindowProc(message, wParam, lParam);
2bda0e17 1785
2d0a075d 1786 return hBrush ;
2bda0e17
KB
1787}
1788
1789// Define for each class of dialog and control
debe6624 1790WXHBRUSH wxWindow::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
2d0a075d 1791 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
2bda0e17
KB
1792{
1793 return (WXHBRUSH) MSWDefWindowProc(message, wParam, lParam);
1794}
1795
debe6624 1796bool wxWindow::MSWOnColorChange(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 1797{
2d0a075d
JS
1798 wxSysColourChangedEvent event;
1799 event.SetEventObject(this);
2bda0e17 1800
2d0a075d
JS
1801 // Check if app handles this.
1802 if (GetEventHandler()->ProcessEvent(event))
1803 return 0;
2bda0e17 1804
2d0a075d
JS
1805 // We didn't process it
1806 return 1;
2bda0e17
KB
1807}
1808
f7bd2698
JS
1809long wxWindow::MSWOnPaletteChanged(WXHWND hWndPalChange)
1810{
1811 wxPaletteChangedEvent event(GetId());
1812 event.SetEventObject(this);
1813 event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
1814 GetEventHandler()->ProcessEvent(event);
1815 return 0;
1816}
1817
1818long wxWindow::MSWOnQueryNewPalette()
1819{
1820 wxQueryNewPaletteEvent event(GetId());
1821 event.SetEventObject(this);
1822 if (!GetEventHandler()->ProcessEvent(event) || !event.GetPaletteRealized())
1823 {
1824 return (long) FALSE;
1825 }
1826 else
1827 return (long) TRUE;
1828}
1829
2bda0e17
KB
1830// Responds to colour changes: passes event on to children.
1831void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
1832{
c0ed460c 1833 wxNode *node = GetChildren().First();
2bda0e17
KB
1834 while ( node )
1835 {
1836 // Only propagate to non-top-level windows
1837 wxWindow *win = (wxWindow *)node->Data();
1838 if ( win->GetParent() )
1839 {
1840 wxSysColourChangedEvent event2;
1841 event.m_eventObject = win;
1842 win->GetEventHandler()->ProcessEvent(event2);
1843 }
c085e333 1844
2bda0e17
KB
1845 node = node->Next();
1846 }
1847}
1848
1849long wxWindow::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
1850{
2d0a075d
JS
1851 if ( m_oldWndProc )
1852 return ::CallWindowProc(CASTWNDPROC m_oldWndProc, (HWND) GetHWND(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
1853 else
1854 return ::DefWindowProc((HWND) GetHWND(), nMsg, wParam, lParam);
2bda0e17
KB
1855}
1856
1857long wxWindow::Default()
1858{
46851318
JS
1859 // Ignore 'fake' events (perhaps generated as a result of a separate real event)
1860 if (m_lastMsg == 0)
1c089c47 1861 return 0;
c085e333 1862
2d0a075d
JS
1863#ifdef __WXDEBUG__
1864 wxLogTrace(wxTraceMessages, "Forwarding %s to DefWindowProc.",
1865 wxGetMessageName(m_lastMsg));
ea57084d 1866#endif // __WXDEBUG__
c085e333 1867
46851318 1868 return this->MSWDefWindowProc(m_lastMsg, m_lastWParam, m_lastLParam);
2bda0e17
KB
1869}
1870
1871bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
1872{
2d0a075d
JS
1873 if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) ) {
1874 // intercept dialog navigation keys
1875 MSG *msg = (MSG *)pMsg;
1876 bool bProcess = TRUE;
1877 if ( msg->message != WM_KEYDOWN )
1878 bProcess = FALSE;
47cbd6da 1879
2d0a075d
JS
1880 if ( (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN )
1881 bProcess = FALSE;
47cbd6da 1882
2d0a075d 1883 bool bCtrlDown = (::GetKeyState(VK_CONTROL) & 0x100) != 0;
47cbd6da 1884
2d0a075d
JS
1885 // WM_GETDLGCODE: if the control wants it for itself, don't process it
1886 // (except for Ctrl-Tab combination which is always processed)
1887 LONG lDlgCode = 0;
1888 if ( bProcess && !bCtrlDown ) {
1889 lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0);
1890 }
47cbd6da 1891
fd3f686c 1892 bool bForward = TRUE;
2d0a075d
JS
1893 if ( bProcess ) {
1894 switch ( msg->wParam ) {
fd3f686c
VZ
1895 case VK_TAB:
1896 if ( lDlgCode & DLGC_WANTTAB ) // FALSE for Ctrl-Tab
1897 bProcess = FALSE;
1898 else
1899 bForward = !(::GetKeyState(VK_SHIFT) & 0x100);
1900 break;
47cbd6da 1901
fd3f686c
VZ
1902 case VK_UP:
1903 case VK_LEFT:
1904 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
1905 bProcess = FALSE;
1906 else
1907 bForward = FALSE;
1908 break;
47cbd6da 1909
fd3f686c
VZ
1910 case VK_DOWN:
1911 case VK_RIGHT:
1912 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
1913 bProcess = FALSE;
1914 break;
47cbd6da 1915
fd3f686c
VZ
1916 default:
1917 bProcess = FALSE;
2d0a075d
JS
1918 }
1919 }
47cbd6da 1920
2d0a075d
JS
1921 if ( bProcess ) {
1922 wxNavigationKeyEvent event;
1923 event.SetDirection(bForward);
1924 event.SetWindowChange(bCtrlDown);
1925 event.SetEventObject(this);
47cbd6da 1926
2d0a075d
JS
1927 if ( GetEventHandler()->ProcessEvent(event) )
1928 return TRUE;
1929 }
47cbd6da 1930
2d0a075d
JS
1931 return ::IsDialogMessage((HWND)GetHWND(), msg) != 0;
1932 }
47cbd6da 1933
2d0a075d 1934 return FALSE;
2bda0e17
KB
1935}
1936
088a95f5 1937bool wxWindow::MSWTranslateMessage(WXMSG* pMsg)
57a7b7c1 1938{
088a95f5 1939 if (m_acceleratorTable.Ok() &&
2d0a075d 1940 ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg))
088a95f5
JS
1941 return TRUE;
1942 else
1943 return FALSE;
57a7b7c1
JS
1944}
1945
debe6624 1946long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag), WXHWND WXUNUSED(activate), WXHWND WXUNUSED(deactivate))
2bda0e17 1947{
2d0a075d 1948 return 1;
2bda0e17
KB
1949}
1950
fd3f686c 1951void wxWindow::MSWDetachWindowMenu()
2bda0e17 1952{
2d0a075d 1953 if (m_hMenu)
2bda0e17 1954 {
2d0a075d
JS
1955 int N = GetMenuItemCount((HMENU) m_hMenu);
1956 int i;
1957 for (i = 0; i < N; i++)
1958 {
1959 char buf[100];
1960 int chars = GetMenuString((HMENU) m_hMenu, i, buf, 100, MF_BYPOSITION);
1961 if ((chars > 0) && (strcmp(buf, "&Window") == 0))
1962 {
1963 RemoveMenu((HMENU) m_hMenu, i, MF_BYPOSITION);
1964 break;
1965 }
1966 }
2bda0e17 1967 }
2bda0e17
KB
1968}
1969
fd3f686c 1970bool wxWindow::MSWOnPaint()
2bda0e17 1971{
81d66cf3 1972#ifdef __WIN32__
2d0a075d
JS
1973 HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
1974 ::GetUpdateRgn((HWND) GetHWND(), hRegion, FALSE);
81d66cf3 1975
2d0a075d 1976 m_updateRegion = wxRegion((WXHRGN) hRegion);
81d66cf3 1977#else
2d0a075d
JS
1978 RECT updateRect;
1979 ::GetUpdateRect((HWND) GetHWND(), & updateRect, FALSE);
81d66cf3 1980
2d0a075d
JS
1981 m_updateRegion = wxRegion(updateRect.left, updateRect.top,
1982 updateRect.right - updateRect.left, updateRect.bottom - updateRect.top);
81d66cf3 1983#endif
c085e333 1984
2d0a075d
JS
1985 wxPaintEvent event(m_windowId);
1986 event.SetEventObject(this);
1987 if (!GetEventHandler()->ProcessEvent(event))
1988 Default();
1989 return TRUE;
2bda0e17
KB
1990}
1991
debe6624 1992void wxWindow::MSWOnSize(int w, int h, WXUINT WXUNUSED(flag))
2bda0e17 1993{
2d0a075d
JS
1994 if (m_inOnSize)
1995 return;
1996
2d0a075d
JS
1997 if (!m_hWnd)
1998 return;
2bda0e17 1999
2d0a075d 2000 m_inOnSize = TRUE;
2bda0e17 2001
2d0a075d
JS
2002 wxSizeEvent event(wxSize(w, h), m_windowId);
2003 event.SetEventObject(this);
2004 if (!GetEventHandler()->ProcessEvent(event))
2005 Default();
2bda0e17 2006
2d0a075d 2007 m_inOnSize = FALSE;
2bda0e17
KB
2008}
2009
2010void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos))
2011{
2012 Default();
2013}
2014
2015// Deal with child commands from buttons etc.
34138703 2016bool wxWindow::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control)
2bda0e17 2017{
2d0a075d
JS
2018 if (wxCurrentPopupMenu)
2019 {
2020 wxMenu *popupMenu = wxCurrentPopupMenu;
2021 wxCurrentPopupMenu = NULL;
2022 bool succ = popupMenu->MSWCommand(cmd, id);
2023 return succ;
2024 }
c085e333 2025
2d0a075d
JS
2026 wxWindow *item = FindItem(id);
2027 if (item)
2028 {
2029 bool value = item->MSWCommand(cmd, id);
2d0a075d
JS
2030 return value;
2031 }
2032 else
2033 {
2034 wxWindow *win = wxFindWinFromHandle(control);
2035 if (win)
2036 return win->MSWCommand(cmd, id);
2037 }
2038 return FALSE;
2bda0e17
KB
2039}
2040
2041long wxWindow::MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam)
2042{
2043 switch (wParam)
2044 {
2d0a075d 2045 case SC_MAXIMIZE:
2bda0e17
KB
2046 {
2047 wxMaximizeEvent event(m_windowId);
2048 event.SetEventObject(this);
2049 if (!GetEventHandler()->ProcessEvent(event))
2050 return Default();
2051 else
2052 return 0;
2053 break;
2054 }
2d0a075d 2055 case SC_MINIMIZE:
2bda0e17
KB
2056 {
2057 wxIconizeEvent event(m_windowId);
2058 event.SetEventObject(this);
2059 if (!GetEventHandler()->ProcessEvent(event))
2060 return Default();
2061 else
2062 return 0;
2063 break;
2064 }
2d0a075d
JS
2065 default:
2066 return Default();
2bda0e17
KB
2067 }
2068 return 0;
2069}
2070
debe6624 2071void wxWindow::MSWOnLButtonDown(int x, int y, WXUINT flags)
2bda0e17 2072{
2d0a075d 2073 wxMouseEvent event(wxEVT_LEFT_DOWN);
2bda0e17 2074
2d0a075d
JS
2075 event.m_x = x; event.m_y = y;
2076 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2077 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2078 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2079 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2080 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2081 event.SetTimestamp(wxApp::sm_lastMessageTime);
2082 event.m_eventObject = this;
2bda0e17 2083
f5419957 2084 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_DOWN;
debe6624 2085
2d0a075d
JS
2086 if (!GetEventHandler()->ProcessEvent(event))
2087 Default();
2bda0e17
KB
2088}
2089
debe6624 2090void wxWindow::MSWOnLButtonUp(int x, int y, WXUINT flags)
2bda0e17 2091{
2d0a075d 2092 wxMouseEvent event(wxEVT_LEFT_UP);
2bda0e17 2093
2d0a075d
JS
2094 event.m_x = x; event.m_y = y;
2095 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2096 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2097 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2098 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2099 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2100 event.SetTimestamp(wxApp::sm_lastMessageTime);
2101 event.m_eventObject = this;
2bda0e17 2102
2d0a075d 2103 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_UP;
2bda0e17 2104
2d0a075d
JS
2105 if (!GetEventHandler()->ProcessEvent(event))
2106 Default();
2bda0e17
KB
2107}
2108
debe6624 2109void wxWindow::MSWOnLButtonDClick(int x, int y, WXUINT flags)
2bda0e17 2110{
2d0a075d 2111 wxMouseEvent event(wxEVT_LEFT_DCLICK);
2bda0e17 2112
2d0a075d
JS
2113 event.m_x = x; event.m_y = y;
2114 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2115 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2116 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2117 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2118 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2119 event.SetTimestamp(wxApp::sm_lastMessageTime);
2120 event.m_eventObject = this;
2bda0e17 2121
2d0a075d 2122 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_LEFT_DCLICK;
2bda0e17 2123
2d0a075d
JS
2124 if (!GetEventHandler()->ProcessEvent(event))
2125 Default();
2bda0e17
KB
2126}
2127
debe6624 2128void wxWindow::MSWOnMButtonDown(int x, int y, WXUINT flags)
2bda0e17 2129{
2d0a075d 2130 wxMouseEvent event(wxEVT_MIDDLE_DOWN);
2bda0e17 2131
2d0a075d
JS
2132 event.m_x = x; event.m_y = y;
2133 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2134 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2135 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2136 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2137 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2138 event.SetTimestamp(wxApp::sm_lastMessageTime);
2139 event.m_eventObject = this;
2bda0e17 2140
2d0a075d 2141 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_DOWN;
debe6624 2142
2d0a075d
JS
2143 if (!GetEventHandler()->ProcessEvent(event))
2144 Default();
2bda0e17
KB
2145}
2146
debe6624 2147void wxWindow::MSWOnMButtonUp(int x, int y, WXUINT flags)
2bda0e17 2148{
2d0a075d
JS
2149 //wxDebugMsg("MButtonUp\n") ;
2150 wxMouseEvent event(wxEVT_MIDDLE_UP);
2bda0e17 2151
2d0a075d
JS
2152 event.m_x = x; event.m_y = y;
2153 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2154 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2155 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2156 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2157 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2158 event.SetTimestamp(wxApp::sm_lastMessageTime);
2159 event.m_eventObject = this;
2bda0e17 2160
2d0a075d 2161 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_UP;
debe6624 2162
2d0a075d
JS
2163 if (!GetEventHandler()->ProcessEvent(event))
2164 Default();
2bda0e17
KB
2165}
2166
debe6624 2167void wxWindow::MSWOnMButtonDClick(int x, int y, WXUINT flags)
2bda0e17 2168{
2d0a075d 2169 wxMouseEvent event(wxEVT_MIDDLE_DCLICK);
2bda0e17 2170
2d0a075d
JS
2171 event.m_x = x; event.m_y = y;
2172 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2173 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2174 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2175 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2176 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2177 event.SetTimestamp(wxApp::sm_lastMessageTime);
2178 event.m_eventObject = this;
2bda0e17 2179
2d0a075d 2180 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_MIDDLE_DCLICK;
debe6624 2181
2d0a075d
JS
2182 if (!GetEventHandler()->ProcessEvent(event))
2183 Default();
2bda0e17
KB
2184}
2185
debe6624 2186void wxWindow::MSWOnRButtonDown(int x, int y, WXUINT flags)
2bda0e17 2187{
2d0a075d 2188 wxMouseEvent event(wxEVT_RIGHT_DOWN);
2bda0e17 2189
2d0a075d
JS
2190 event.m_x = x; event.m_y = y;
2191 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2192 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2193 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2194 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2195 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2196 event.SetTimestamp(wxApp::sm_lastMessageTime);
2197 event.m_eventObject = this;
2bda0e17 2198
2d0a075d 2199 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_DOWN;
debe6624 2200
2d0a075d
JS
2201 if (!GetEventHandler()->ProcessEvent(event))
2202 Default();
2bda0e17
KB
2203}
2204
debe6624 2205void wxWindow::MSWOnRButtonUp(int x, int y, WXUINT flags)
2bda0e17 2206{
2d0a075d 2207 wxMouseEvent event(wxEVT_RIGHT_UP);
2bda0e17 2208
2d0a075d
JS
2209 event.m_x = x; event.m_y = y;
2210 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2211 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2212 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2213 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2214 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2215 event.m_eventObject = this;
2216 event.SetTimestamp(wxApp::sm_lastMessageTime);
2bda0e17 2217
2d0a075d 2218 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_UP;
debe6624 2219
2d0a075d
JS
2220 if (!GetEventHandler()->ProcessEvent(event))
2221 Default();
2bda0e17
KB
2222}
2223
debe6624 2224void wxWindow::MSWOnRButtonDClick(int x, int y, WXUINT flags)
2bda0e17 2225{
2d0a075d 2226 wxMouseEvent event(wxEVT_RIGHT_DCLICK);
2bda0e17 2227
2d0a075d
JS
2228 event.m_x = x; event.m_y = y;
2229 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2230 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2231 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2232 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2233 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2234 event.SetTimestamp(wxApp::sm_lastMessageTime);
2235 event.m_eventObject = this;
2bda0e17 2236
2d0a075d 2237 m_lastXPos = event.m_x; m_lastYPos = event.m_y; m_lastEvent = wxEVT_RIGHT_DCLICK;
debe6624 2238
2d0a075d
JS
2239 if (!GetEventHandler()->ProcessEvent(event))
2240 Default();
2bda0e17
KB
2241}
2242
debe6624 2243void wxWindow::MSWOnMouseMove(int x, int y, WXUINT flags)
2bda0e17 2244{
2d0a075d
JS
2245 // 'normal' move event...
2246 // Set cursor, but only if we're not in 'busy' mode
2bda0e17 2247
2d0a075d
JS
2248 // Trouble with this is that it sets the cursor for controls too :-(
2249 if (m_windowCursor.Ok() && !wxIsBusy())
2250 ::SetCursor((HCURSOR) m_windowCursor.GetHCURSOR());
2bda0e17 2251
2d0a075d
JS
2252 if (!m_mouseInWindow)
2253 {
2254 // Generate an ENTER event
2255 m_mouseInWindow = TRUE;
2256 MSWOnMouseEnter(x, y, flags);
2257 }
2bda0e17 2258
2d0a075d 2259 wxMouseEvent event(wxEVT_MOTION);
debe6624 2260
2d0a075d
JS
2261 event.m_x = x; event.m_y = y;
2262 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2263 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2264 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2265 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2266 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2267 event.SetTimestamp(wxApp::sm_lastMessageTime);
2268 event.m_eventObject = this;
2269
2270 // Window gets a click down message followed by a mouse move
2271 // message even if position isn't changed! We want to discard
2272 // the trailing move event if x and y are the same.
2273 if ((m_lastEvent == wxEVT_RIGHT_DOWN || m_lastEvent == wxEVT_LEFT_DOWN ||
2274 m_lastEvent == wxEVT_MIDDLE_DOWN) &&
2275 (m_lastXPos == event.m_x && m_lastYPos == event.m_y))
2276 {
2277 m_lastXPos = event.m_x; m_lastYPos = event.m_y;
2278 m_lastEvent = wxEVT_MOTION;
2279 return;
2280 }
2281
2282 m_lastEvent = wxEVT_MOTION;
2283 m_lastXPos = event.m_x; m_lastYPos = event.m_y;
2284
2285 if (!GetEventHandler()->ProcessEvent(event))
2286 Default();
2bda0e17 2287}
2bda0e17 2288
debe6624 2289void wxWindow::MSWOnMouseEnter(int x, int y, WXUINT flags)
2bda0e17 2290{
2d0a075d 2291 wxMouseEvent event(wxEVT_ENTER_WINDOW);
2bda0e17 2292
2d0a075d
JS
2293 event.m_x = x; event.m_y = y;
2294 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2295 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2296 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2297 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2298 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2299 event.SetTimestamp(wxApp::sm_lastMessageTime);
2300 event.m_eventObject = this;
2bda0e17 2301
2d0a075d
JS
2302 m_lastEvent = wxEVT_ENTER_WINDOW;
2303 m_lastXPos = event.m_x; m_lastYPos = event.m_y;
2304 // No message - ensure we don't try to call the default behaviour accidentally.
2305 m_lastMsg = 0;
2306 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
2307}
2308
debe6624 2309void wxWindow::MSWOnMouseLeave(int x, int y, WXUINT flags)
2bda0e17 2310{
2d0a075d 2311 wxMouseEvent event(wxEVT_LEAVE_WINDOW);
2bda0e17 2312
2d0a075d
JS
2313 event.m_x = x; event.m_y = y;
2314 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2315 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2316 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2317 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2318 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2319 event.SetTimestamp(wxApp::sm_lastMessageTime);
2320 event.m_eventObject = this;
2bda0e17 2321
2d0a075d
JS
2322 m_lastEvent = wxEVT_LEAVE_WINDOW;
2323 m_lastXPos = event.m_x; m_lastYPos = event.m_y;
2324 // No message - ensure we don't try to call the default behaviour accidentally.
2325 m_lastMsg = 0;
2326 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
2327}
2328
debe6624 2329void wxWindow::MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII)
2bda0e17 2330{
2d0a075d
JS
2331 int id;
2332 bool tempControlDown = FALSE;
2333 if (isASCII)
2bda0e17 2334 {
2d0a075d
JS
2335 // If 1 -> 26, translate to CTRL plus a letter.
2336 id = wParam;
2337 if ((id > 0) && (id < 27))
2bda0e17 2338 {
2d0a075d
JS
2339 switch (id)
2340 {
2341 case 13:
2342 {
2343 id = WXK_RETURN;
2344 break;
2345 }
2346 case 8:
2347 {
2348 id = WXK_BACK;
2349 break;
2350 }
2351 case 9:
2352 {
2353 id = WXK_TAB;
2354 break;
2355 }
2356 default:
2357 {
2358 tempControlDown = TRUE;
2359 id = id + 96;
2360 }
2361 }
2bda0e17 2362 }
2bda0e17 2363 }
2d0a075d
JS
2364 else if ((id = wxCharCodeMSWToWX(wParam)) == 0) {
2365 // it's ASCII and will be processed here only when called from
2366 // WM_CHAR (i.e. when isASCII = TRUE)
2367 id = -1;
2368 }
2bda0e17 2369
2d0a075d
JS
2370 if (id != -1)
2371 {
2372 wxKeyEvent event(wxEVT_CHAR);
2373 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
2374 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
2375 if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN)
2376 event.m_altDown = TRUE;
2377
2378 event.m_eventObject = this;
2379 event.m_keyCode = id;
2380 event.SetTimestamp(wxApp::sm_lastMessageTime);
2381
2382 POINT pt ;
2383 GetCursorPos(&pt) ;
2384 RECT rect ;
2385 GetWindowRect((HWND) GetHWND(),&rect) ;
2386 pt.x -= rect.left ;
2387 pt.y -= rect.top ;
2388
2389 event.m_x = pt.x; event.m_y = pt.y;
2390
2391 if (!GetEventHandler()->ProcessEvent(event))
2392 Default();
2393 }
2bda0e17
KB
2394}
2395
debe6624 2396void wxWindow::MSWOnJoyDown(int joystick, int x, int y, WXUINT flags)
2bda0e17
KB
2397{
2398 int buttons = 0;
2399 int change = 0;
2400 if (flags & JOY_BUTTON1CHG)
2401 change = wxJOY_BUTTON1;
2402 if (flags & JOY_BUTTON2CHG)
2403 change = wxJOY_BUTTON2;
2404 if (flags & JOY_BUTTON3CHG)
2405 change = wxJOY_BUTTON3;
2406 if (flags & JOY_BUTTON4CHG)
2407 change = wxJOY_BUTTON4;
c085e333 2408
2bda0e17
KB
2409 if (flags & JOY_BUTTON1)
2410 buttons |= wxJOY_BUTTON1;
2411 if (flags & JOY_BUTTON2)
2412 buttons |= wxJOY_BUTTON2;
2413 if (flags & JOY_BUTTON3)
2414 buttons |= wxJOY_BUTTON3;
2415 if (flags & JOY_BUTTON4)
2416 buttons |= wxJOY_BUTTON4;
c085e333 2417
2bda0e17
KB
2418 wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN, buttons, joystick, change);
2419 event.SetPosition(wxPoint(x, y));
2420 event.SetEventObject(this);
c085e333 2421
2bda0e17
KB
2422 GetEventHandler()->ProcessEvent(event);
2423}
2424
debe6624 2425void wxWindow::MSWOnJoyUp(int joystick, int x, int y, WXUINT flags)
2bda0e17
KB
2426{
2427 int buttons = 0;
2428 int change = 0;
2429 if (flags & JOY_BUTTON1CHG)
2430 change = wxJOY_BUTTON1;
2431 if (flags & JOY_BUTTON2CHG)
2432 change = wxJOY_BUTTON2;
2433 if (flags & JOY_BUTTON3CHG)
2434 change = wxJOY_BUTTON3;
2435 if (flags & JOY_BUTTON4CHG)
2436 change = wxJOY_BUTTON4;
c085e333 2437
2bda0e17
KB
2438 if (flags & JOY_BUTTON1)
2439 buttons |= wxJOY_BUTTON1;
2440 if (flags & JOY_BUTTON2)
2441 buttons |= wxJOY_BUTTON2;
2442 if (flags & JOY_BUTTON3)
2443 buttons |= wxJOY_BUTTON3;
2444 if (flags & JOY_BUTTON4)
2445 buttons |= wxJOY_BUTTON4;
c085e333 2446
2bda0e17
KB
2447 wxJoystickEvent event(wxEVT_JOY_BUTTON_UP, buttons, joystick, change);
2448 event.SetPosition(wxPoint(x, y));
2449 event.SetEventObject(this);
c085e333 2450
2bda0e17
KB
2451 GetEventHandler()->ProcessEvent(event);
2452}
2453
debe6624 2454void wxWindow::MSWOnJoyMove(int joystick, int x, int y, WXUINT flags)
2bda0e17
KB
2455{
2456 int buttons = 0;
2457 if (flags & JOY_BUTTON1)
2458 buttons |= wxJOY_BUTTON1;
2459 if (flags & JOY_BUTTON2)
2460 buttons |= wxJOY_BUTTON2;
2461 if (flags & JOY_BUTTON3)
2462 buttons |= wxJOY_BUTTON3;
2463 if (flags & JOY_BUTTON4)
2464 buttons |= wxJOY_BUTTON4;
c085e333 2465
2bda0e17
KB
2466 wxJoystickEvent event(wxEVT_JOY_MOVE, buttons, joystick, 0);
2467 event.SetPosition(wxPoint(x, y));
2468 event.SetEventObject(this);
c085e333 2469
2bda0e17
KB
2470 GetEventHandler()->ProcessEvent(event);
2471}
2472
debe6624 2473void wxWindow::MSWOnJoyZMove(int joystick, int z, WXUINT flags)
2bda0e17
KB
2474{
2475 int buttons = 0;
2476 if (flags & JOY_BUTTON1)
2477 buttons |= wxJOY_BUTTON1;
2478 if (flags & JOY_BUTTON2)
2479 buttons |= wxJOY_BUTTON2;
2480 if (flags & JOY_BUTTON3)
2481 buttons |= wxJOY_BUTTON3;
2482 if (flags & JOY_BUTTON4)
2483 buttons |= wxJOY_BUTTON4;
c085e333 2484
2bda0e17
KB
2485 wxJoystickEvent event(wxEVT_JOY_ZMOVE, buttons, joystick, 0);
2486 event.SetZPosition(z);
2487 event.SetEventObject(this);
c085e333 2488
2bda0e17
KB
2489 GetEventHandler()->ProcessEvent(event);
2490}
2491
debe6624 2492void wxWindow::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control)
2bda0e17 2493{
2d0a075d 2494 if (control)
564b2609 2495 {
2d0a075d
JS
2496 wxWindow *child = wxFindWinFromHandle(control);
2497 if ( child )
2498 child->MSWOnVScroll(wParam, pos, control);
2499 return;
564b2609 2500 }
2bda0e17 2501
564b2609
VZ
2502 wxScrollEvent event;
2503 event.SetPosition(pos);
2d0a075d 2504 event.SetOrientation(wxVERTICAL);
564b2609 2505 event.m_eventObject = this;
2d0a075d 2506
564b2609
VZ
2507 switch ( wParam )
2508 {
2d0a075d 2509 case SB_TOP:
564b2609
VZ
2510 event.m_eventType = wxEVT_SCROLL_TOP;
2511 break;
2d0a075d
JS
2512
2513 case SB_BOTTOM:
564b2609
VZ
2514 event.m_eventType = wxEVT_SCROLL_BOTTOM;
2515 break;
2d0a075d
JS
2516
2517 case SB_LINEUP:
564b2609
VZ
2518 event.m_eventType = wxEVT_SCROLL_LINEUP;
2519 break;
2d0a075d
JS
2520
2521 case SB_LINEDOWN:
564b2609
VZ
2522 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
2523 break;
2d0a075d
JS
2524
2525 case SB_PAGEUP:
564b2609
VZ
2526 event.m_eventType = wxEVT_SCROLL_PAGEUP;
2527 break;
2d0a075d
JS
2528
2529 case SB_PAGEDOWN:
564b2609
VZ
2530 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
2531 break;
2d0a075d
JS
2532
2533 case SB_THUMBTRACK:
2534 case SB_THUMBPOSITION:
564b2609
VZ
2535 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
2536 break;
2d0a075d
JS
2537
2538 default:
564b2609 2539 return;
2d0a075d 2540 break;
564b2609 2541 }
c085e333 2542
2d0a075d
JS
2543 if (!GetEventHandler()->ProcessEvent(event))
2544 Default();
2545}
2546
2547void wxWindow::MSWOnHScroll( WXWORD wParam, WXWORD pos, WXHWND control)
2548{
2549 if (control)
2550 {
2551 wxWindow *child = wxFindWinFromHandle(control);
2552 if ( child ) {
2553 child->MSWOnHScroll(wParam, pos, control);
2554
2555 return;
2556 }
2557 }
2558 else {
2559 wxScrollEvent event;
2560 event.SetPosition(pos);
2561 event.SetOrientation(wxHORIZONTAL);
2562 event.m_eventObject = this;
2563
2564 switch ( wParam )
2565 {
2566 case SB_TOP:
2567 event.m_eventType = wxEVT_SCROLL_TOP;
2568 break;
2569
2570 case SB_BOTTOM:
2571 event.m_eventType = wxEVT_SCROLL_BOTTOM;
2572 break;
2573
2574 case SB_LINEUP:
2575 event.m_eventType = wxEVT_SCROLL_LINEUP;
2576 break;
2bda0e17 2577
2d0a075d
JS
2578 case SB_LINEDOWN:
2579 event.m_eventType = wxEVT_SCROLL_LINEDOWN;
2580 break;
2581
2582 case SB_PAGEUP:
2583 event.m_eventType = wxEVT_SCROLL_PAGEUP;
2584 break;
2585
2586 case SB_PAGEDOWN:
2587 event.m_eventType = wxEVT_SCROLL_PAGEDOWN;
2588 break;
2589
2590 case SB_THUMBTRACK:
2591 case SB_THUMBPOSITION:
2592 event.m_eventType = wxEVT_SCROLL_THUMBTRACK;
2593 break;
2594
2595 default:
2596 return;
2597 }
2bda0e17 2598
2d0a075d
JS
2599 if ( GetEventHandler()->ProcessEvent(event) )
2600 return;
2601 }
2602
2603 // call the default WM_HSCROLL handler: it's non trivial in some common
2604 // controls (up-down control for example)
2605 Default();
2bda0e17
KB
2606}
2607
2608void wxWindow::MSWOnShow(bool show, int status)
2609{
2d0a075d
JS
2610 wxShowEvent event(GetId(), show);
2611 event.m_eventObject = this;
2612 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
2613}
2614
2615bool wxWindow::MSWOnInitDialog(WXHWND WXUNUSED(hWndFocus))
2616{
2d0a075d
JS
2617 wxInitDialogEvent event(GetId());
2618 event.m_eventObject = this;
2619 GetEventHandler()->ProcessEvent(event);
2620 return TRUE;
2bda0e17
KB
2621}
2622
fd3f686c 2623void wxWindow::InitDialog()
2bda0e17 2624{
2d0a075d
JS
2625 wxInitDialogEvent event(GetId());
2626 event.SetEventObject( this );
2627 GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
2628}
2629
2630// Default init dialog behaviour is to transfer data to window
2631void wxWindow::OnInitDialog(wxInitDialogEvent& event)
2632{
2d0a075d 2633 TransferDataToWindow();
2bda0e17
KB
2634}
2635
2636void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font)
2637{
2d0a075d
JS
2638 TEXTMETRIC tm;
2639 HDC dc = ::GetDC((HWND) wnd);
2640 HFONT fnt =0;
2641 HFONT was = 0;
2642 if (the_font)
2643 {
2d0a075d
JS
2644 // the_font->UseResource();
2645 // the_font->RealizeResource();
fd3f686c
VZ
2646 fnt = (HFONT)the_font->GetResourceHandle();
2647 if ( fnt )
2d0a075d
JS
2648 was = (HFONT) SelectObject(dc,fnt) ;
2649 }
2650 GetTextMetrics(dc, &tm);
2651 if (the_font && fnt && was)
2652 {
2d0a075d
JS
2653 SelectObject(dc,was) ;
2654 }
2655 ReleaseDC((HWND)wnd, dc);
2656 *x = tm.tmAveCharWidth;
2657 *y = tm.tmHeight + tm.tmExternalLeading;
2bda0e17 2658
2d0a075d
JS
2659 // if (the_font)
2660 // the_font->ReleaseResource();
2bda0e17
KB
2661}
2662
2663// Returns 0 if was a normal ASCII value, not a special key. This indicates that
2664// the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
2665int wxCharCodeMSWToWX(int keySym)
2666{
2d0a075d
JS
2667 int id = 0;
2668 switch (keySym)
2669 {
2670 case VK_CANCEL: id = WXK_CANCEL; break;
2671 case VK_BACK: id = WXK_BACK; break;
2672 case VK_TAB: id = WXK_TAB; break;
564b2609
VZ
2673 case VK_CLEAR: id = WXK_CLEAR; break;
2674 case VK_RETURN: id = WXK_RETURN; break;
2675 case VK_SHIFT: id = WXK_SHIFT; break;
2d0a075d 2676 case VK_CONTROL: id = WXK_CONTROL; break;
564b2609
VZ
2677 case VK_MENU : id = WXK_MENU; break;
2678 case VK_PAUSE: id = WXK_PAUSE; break;
2679 case VK_SPACE: id = WXK_SPACE; break;
2680 case VK_ESCAPE: id = WXK_ESCAPE; break;
2681 case VK_PRIOR: id = WXK_PRIOR; break;
2682 case VK_NEXT : id = WXK_NEXT; break;
2683 case VK_END: id = WXK_END; break;
2684 case VK_HOME : id = WXK_HOME; break;
2685 case VK_LEFT : id = WXK_LEFT; break;
2d0a075d 2686 case VK_UP: id = WXK_UP; break;
564b2609
VZ
2687 case VK_RIGHT: id = WXK_RIGHT; break;
2688 case VK_DOWN : id = WXK_DOWN; break;
2689 case VK_SELECT: id = WXK_SELECT; break;
2690 case VK_PRINT: id = WXK_PRINT; break;
2d0a075d 2691 case VK_EXECUTE: id = WXK_EXECUTE; break;
564b2609
VZ
2692 case VK_INSERT: id = WXK_INSERT; break;
2693 case VK_DELETE: id = WXK_DELETE; break;
2694 case VK_HELP : id = WXK_HELP; break;
2d0a075d
JS
2695 case VK_NUMPAD0: id = WXK_NUMPAD0; break;
2696 case VK_NUMPAD1: id = WXK_NUMPAD1; break;
2697 case VK_NUMPAD2: id = WXK_NUMPAD2; break;
2698 case VK_NUMPAD3: id = WXK_NUMPAD3; break;
2699 case VK_NUMPAD4: id = WXK_NUMPAD4; break;
2700 case VK_NUMPAD5: id = WXK_NUMPAD5; break;
2701 case VK_NUMPAD6: id = WXK_NUMPAD6; break;
2702 case VK_NUMPAD7: id = WXK_NUMPAD7; break;
2703 case VK_NUMPAD8: id = WXK_NUMPAD8; break;
2704 case VK_NUMPAD9: id = WXK_NUMPAD9; break;
2705 case VK_MULTIPLY: id = WXK_MULTIPLY; break;
564b2609 2706 case VK_ADD: id = WXK_ADD; break;
2d0a075d
JS
2707 case VK_SUBTRACT: id = WXK_SUBTRACT; break;
2708 case VK_DECIMAL: id = WXK_DECIMAL; break;
564b2609 2709 case VK_DIVIDE: id = WXK_DIVIDE; break;
2d0a075d
JS
2710 case VK_F1: id = WXK_F1; break;
2711 case VK_F2: id = WXK_F2; break;
2712 case VK_F3: id = WXK_F3; break;
2713 case VK_F4: id = WXK_F4; break;
2714 case VK_F5: id = WXK_F5; break;
2715 case VK_F6: id = WXK_F6; break;
2716 case VK_F7: id = WXK_F7; break;
2717 case VK_F8: id = WXK_F8; break;
2718 case VK_F9: id = WXK_F9; break;
564b2609
VZ
2719 case VK_F10: id = WXK_F10; break;
2720 case VK_F11: id = WXK_F11; break;
2721 case VK_F12: id = WXK_F12; break;
2722 case VK_F13: id = WXK_F13; break;
2723 case VK_F14: id = WXK_F14; break;
2724 case VK_F15: id = WXK_F15; break;
2725 case VK_F16: id = WXK_F16; break;
2726 case VK_F17: id = WXK_F17; break;
2727 case VK_F18: id = WXK_F18; break;
2728 case VK_F19: id = WXK_F19; break;
2729 case VK_F20: id = WXK_F20; break;
2730 case VK_F21: id = WXK_F21; break;
2731 case VK_F22: id = WXK_F22; break;
2732 case VK_F23: id = WXK_F23; break;
2733 case VK_F24: id = WXK_F24; break;
2d0a075d 2734 case VK_NUMLOCK: id = WXK_NUMLOCK; break;
564b2609 2735 case VK_SCROLL: id = WXK_SCROLL; break;
2bda0e17 2736 default:
2d0a075d
JS
2737 {
2738 return 0;
2739 }
2bda0e17 2740 }
2d0a075d 2741 return id;
2bda0e17
KB
2742}
2743
2744int wxCharCodeWXToMSW(int id, bool *isVirtual)
2745{
2d0a075d
JS
2746 *isVirtual = TRUE;
2747 int keySym = 0;
2748 switch (id)
2749 {
2750 case WXK_CANCEL: keySym = VK_CANCEL; break;
564b2609
VZ
2751 case WXK_CLEAR: keySym = VK_CLEAR; break;
2752 case WXK_SHIFT: keySym = VK_SHIFT; break;
2d0a075d 2753 case WXK_CONTROL: keySym = VK_CONTROL; break;
564b2609
VZ
2754 case WXK_MENU : keySym = VK_MENU; break;
2755 case WXK_PAUSE: keySym = VK_PAUSE; break;
2756 case WXK_PRIOR: keySym = VK_PRIOR; break;
2757 case WXK_NEXT : keySym = VK_NEXT; break;
2758 case WXK_END: keySym = VK_END; break;
2759 case WXK_HOME : keySym = VK_HOME; break;
2760 case WXK_LEFT : keySym = VK_LEFT; break;
2761 case WXK_UP: keySym = VK_UP; break;
2762 case WXK_RIGHT: keySym = VK_RIGHT; break;
2763 case WXK_DOWN : keySym = VK_DOWN; break;
2d0a075d 2764 case WXK_SELECT: keySym = VK_SELECT; break;
564b2609 2765 case WXK_PRINT: keySym = VK_PRINT; break;
2d0a075d
JS
2766 case WXK_EXECUTE: keySym = VK_EXECUTE; break;
2767 case WXK_INSERT: keySym = VK_INSERT; break;
2768 case WXK_DELETE: keySym = VK_DELETE; break;
564b2609 2769 case WXK_HELP : keySym = VK_HELP; break;
2d0a075d
JS
2770 case WXK_NUMPAD0: keySym = VK_NUMPAD0; break;
2771 case WXK_NUMPAD1: keySym = VK_NUMPAD1; break;
2772 case WXK_NUMPAD2: keySym = VK_NUMPAD2; break;
2773 case WXK_NUMPAD3: keySym = VK_NUMPAD3; break;
2774 case WXK_NUMPAD4: keySym = VK_NUMPAD4; break;
2775 case WXK_NUMPAD5: keySym = VK_NUMPAD5; break;
2776 case WXK_NUMPAD6: keySym = VK_NUMPAD6; break;
2777 case WXK_NUMPAD7: keySym = VK_NUMPAD7; break;
2778 case WXK_NUMPAD8: keySym = VK_NUMPAD8; break;
2779 case WXK_NUMPAD9: keySym = VK_NUMPAD9; break;
2780 case WXK_MULTIPLY: keySym = VK_MULTIPLY; break;
564b2609 2781 case WXK_ADD: keySym = VK_ADD; break;
2d0a075d
JS
2782 case WXK_SUBTRACT: keySym = VK_SUBTRACT; break;
2783 case WXK_DECIMAL: keySym = VK_DECIMAL; break;
2784 case WXK_DIVIDE: keySym = VK_DIVIDE; break;
564b2609
VZ
2785 case WXK_F1: keySym = VK_F1; break;
2786 case WXK_F2: keySym = VK_F2; break;
2787 case WXK_F3: keySym = VK_F3; break;
2788 case WXK_F4: keySym = VK_F4; break;
2789 case WXK_F5: keySym = VK_F5; break;
2790 case WXK_F6: keySym = VK_F6; break;
2791 case WXK_F7: keySym = VK_F7; break;
2792 case WXK_F8: keySym = VK_F8; break;
2793 case WXK_F9: keySym = VK_F9; break;
2794 case WXK_F10: keySym = VK_F10; break;
2795 case WXK_F11: keySym = VK_F11; break;
2796 case WXK_F12: keySym = VK_F12; break;
2797 case WXK_F13: keySym = VK_F13; break;
2798 case WXK_F14: keySym = VK_F14; break;
2799 case WXK_F15: keySym = VK_F15; break;
2800 case WXK_F16: keySym = VK_F16; break;
2801 case WXK_F17: keySym = VK_F17; break;
2802 case WXK_F18: keySym = VK_F18; break;
2803 case WXK_F19: keySym = VK_F19; break;
2804 case WXK_F20: keySym = VK_F20; break;
2805 case WXK_F21: keySym = VK_F21; break;
2806 case WXK_F22: keySym = VK_F22; break;
2807 case WXK_F23: keySym = VK_F23; break;
2808 case WXK_F24: keySym = VK_F24; break;
2d0a075d
JS
2809 case WXK_NUMLOCK: keySym = VK_NUMLOCK; break;
2810 case WXK_SCROLL: keySym = VK_SCROLL; break;
2bda0e17 2811 default:
2d0a075d
JS
2812 {
2813 *isVirtual = FALSE;
2814 keySym = id;
2815 break;
2816 }
2bda0e17 2817 }
2d0a075d 2818 return keySym;
2bda0e17
KB
2819}
2820
2821// Caret manipulation
debe6624 2822void wxWindow::CreateCaret(int w, int h)
2bda0e17 2823{
2d0a075d
JS
2824 m_caretWidth = w;
2825 m_caretHeight = h;
2826 m_caretEnabled = TRUE;
2bda0e17
KB
2827}
2828
2829void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
2830{
2d0a075d 2831 // Not implemented
2bda0e17
KB
2832}
2833
debe6624 2834void wxWindow::ShowCaret(bool show)
2bda0e17 2835{
2d0a075d
JS
2836 if (m_caretEnabled)
2837 {
2838 if (show)
2839 ::ShowCaret((HWND) GetHWND());
2840 else
2841 ::HideCaret((HWND) GetHWND());
2842 m_caretShown = show;
2843 }
2bda0e17
KB
2844}
2845
fd3f686c 2846void wxWindow::DestroyCaret()
2bda0e17 2847{
2d0a075d 2848 m_caretEnabled = FALSE;
2bda0e17
KB
2849}
2850
debe6624 2851void wxWindow::SetCaretPos(int x, int y)
2bda0e17 2852{
2d0a075d 2853 ::SetCaretPos(x, y);
2bda0e17
KB
2854}
2855
2856void wxWindow::GetCaretPos(int *x, int *y) const
2857{
2d0a075d
JS
2858 POINT point;
2859 ::GetCaretPos(&point);
2860 *x = point.x;
2861 *y = point.y;
2bda0e17
KB
2862}
2863
fd3f686c 2864wxWindow *wxGetActiveWindow()
2bda0e17 2865{
2d0a075d
JS
2866 HWND hWnd = GetActiveWindow();
2867 if (hWnd != 0)
2868 {
2869 return wxFindWinFromHandle((WXHWND) hWnd);
2870 }
2871 return NULL;
2bda0e17
KB
2872}
2873
2874// Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
2875// in active frames and dialogs, regardless of where the focus is.
2876static HHOOK wxTheKeyboardHook = 0;
2877static FARPROC wxTheKeyboardHookProc = 0;
2878int APIENTRY _EXPORT
2d0a075d 2879wxKeyboardHook(int nCode, WORD wParam, DWORD lParam);
2bda0e17
KB
2880
2881void wxSetKeyboardHook(bool doIt)
2882{
2d0a075d
JS
2883 if (doIt)
2884 {
2885 wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance());
2886 wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
2bda0e17 2887#ifdef __WIN32__
2d0a075d
JS
2888 GetCurrentThreadId());
2889 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
2bda0e17 2890#else
2d0a075d 2891 GetCurrentTask());
2bda0e17 2892#endif
2d0a075d
JS
2893 }
2894 else
2895 {
2896 UnhookWindowsHookEx(wxTheKeyboardHook);
2897 FreeProcInstance(wxTheKeyboardHookProc);
2898 }
2bda0e17
KB
2899}
2900
2901int APIENTRY _EXPORT
2d0a075d 2902wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
2bda0e17 2903{
2d0a075d
JS
2904 DWORD hiWord = HIWORD(lParam);
2905 if (nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0))
2bda0e17 2906 {
2d0a075d
JS
2907 int id;
2908 if ((id = wxCharCodeMSWToWX(wParam)) != 0)
564b2609 2909 {
2d0a075d
JS
2910 wxKeyEvent event(wxEVT_CHAR_HOOK);
2911 if ((HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN)
2912 event.m_altDown = TRUE;
2913
2914 event.m_eventObject = NULL;
2915 event.m_keyCode = id;
2916 /* begin Albert's fix for control and shift key 26.5 */
2917 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
2918 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
2919 /* end Albert's fix for control and shift key 26.5 */
2920 event.SetTimestamp(wxApp::sm_lastMessageTime);
2921
2922 wxWindow *win = wxGetActiveWindow();
2923 if (win)
2924 {
2925 if (win->GetEventHandler()->ProcessEvent(event))
2926 return 1;
2927 }
2928 else
2929 {
2930 if ( wxTheApp && wxTheApp->ProcessEvent(event) )
2931 return 1;
2932 }
564b2609 2933 }
2bda0e17 2934 }
2d0a075d 2935 return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam);
2bda0e17
KB
2936}
2937
debe6624 2938void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH))
2bda0e17 2939{
2d0a075d
JS
2940 m_minSizeX = minW;
2941 m_minSizeY = minH;
2942 m_maxSizeX = maxW;
2943 m_maxSizeY = maxH;
2bda0e17
KB
2944}
2945
debe6624 2946void wxWindow::Centre(int direction)
2bda0e17 2947{
2d0a075d 2948 int x, y, width, height, panel_width, panel_height, new_x, new_y;
2bda0e17 2949
2d0a075d
JS
2950 wxWindow *father = (wxWindow *)GetParent();
2951 if (!father)
2952 return;
2bda0e17 2953
2d0a075d
JS
2954 father->GetClientSize(&panel_width, &panel_height);
2955 GetSize(&width, &height);
2956 GetPosition(&x, &y);
2bda0e17 2957
2d0a075d
JS
2958 new_x = -1;
2959 new_y = -1;
2bda0e17 2960
2d0a075d
JS
2961 if (direction & wxHORIZONTAL)
2962 new_x = (int)((panel_width - width)/2);
2bda0e17 2963
2d0a075d
JS
2964 if (direction & wxVERTICAL)
2965 new_y = (int)((panel_height - height)/2);
2bda0e17 2966
2d0a075d 2967 SetSize(new_x, new_y, -1, -1);
2bda0e17
KB
2968
2969}
2970
2971/* TODO (maybe)
fd3f686c 2972void wxWindow::OnPaint()
2bda0e17 2973{
2d0a075d 2974PaintSelectionHandles();
2bda0e17
KB
2975}
2976*/
2977
debe6624 2978void wxWindow::WarpPointer (int x_pos, int y_pos)
2bda0e17 2979{
5de76427
JS
2980 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
2981 // pixel coordinates, relatives to the canvas -- So, we first need to
2982 // substract origin of the window, then convert to screen position
c085e333 2983
5de76427
JS
2984 int x = x_pos; int y = y_pos;
2985 RECT rect;
2986 GetWindowRect ((HWND) GetHWND(), &rect);
c085e333 2987
5de76427
JS
2988 x += rect.left;
2989 y += rect.top;
c085e333 2990
5de76427 2991 SetCursorPos (x, y);
2bda0e17
KB
2992}
2993
2994void wxWindow::MSWDeviceToLogical (float *x, float *y) const
2995{
2bda0e17
KB
2996}
2997
debe6624 2998bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC)
2bda0e17
KB
2999{
3000 wxDC dc ;
c085e333 3001
564b2609
VZ
3002 dc.SetHDC(pDC);
3003 dc.SetWindow(this);
3004 dc.BeginDrawing();
c085e333 3005
2bda0e17
KB
3006 wxEraseEvent event(m_windowId, &dc);
3007 event.m_eventObject = this;
3008 if (!GetEventHandler()->ProcessEvent(event))
3009 {
564b2609
VZ
3010 dc.EndDrawing();
3011 dc.SelectOldObjects(pDC);
2bda0e17
KB
3012 return FALSE;
3013 }
3014 else
3015 {
564b2609
VZ
3016 dc.EndDrawing();
3017 dc.SelectOldObjects(pDC);
2bda0e17 3018 }
c085e333 3019
2bda0e17
KB
3020 dc.SetHDC((WXHDC) NULL);
3021 return TRUE;
3022}
3023
3024void wxWindow::OnEraseBackground(wxEraseEvent& event)
3025{
2d0a075d
JS
3026 RECT rect;
3027 ::GetClientRect((HWND) GetHWND(), &rect);
2bda0e17 3028
2d0a075d
JS
3029 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
3030 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
2bda0e17 3031
2d0a075d
JS
3032 // ::GetClipBox((HDC) event.GetDC()->GetHDC(), &rect);
3033 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
3034 ::DeleteObject(hBrush);
3035 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
3036 /*
3037 // Less efficient version (and doesn't account for scrolling)
3038 int w, h;
3039 GetClientSize(& w, & h);
3040 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(& GetBackgroundColour(), wxSOLID);
3041 event.GetDC()->SetBrush(brush);
3042 event.GetDC()->SetPen(wxTRANSPARENT_PEN);
3043
3044 event.GetDC()->DrawRectangle(0, 0, w+1, h+1);
3045 */
2bda0e17
KB
3046}
3047
3048#if WXWIN_COMPATIBILITY
debe6624 3049void wxWindow::SetScrollRange(int orient, int range, bool refresh)
2bda0e17
KB
3050{
3051#if defined(__WIN95__)
c085e333 3052
2d0a075d 3053 int range1 = range;
2bda0e17 3054
2d0a075d
JS
3055 // Try to adjust the range to cope with page size > 1
3056 // - a Windows API quirk
3057 int pageSize = GetScrollPage(orient);
3058 if ( pageSize > 1 && range > 0)
3059 {
3060 range1 += (pageSize - 1);
3061 }
2bda0e17 3062
2d0a075d
JS
3063 SCROLLINFO info;
3064 int dir;
2bda0e17 3065
2d0a075d
JS
3066 if (orient == wxHORIZONTAL) {
3067 dir = SB_HORZ;
3068 } else {
3069 dir = SB_VERT;
3070 }
2bda0e17 3071
2d0a075d
JS
3072 info.cbSize = sizeof(SCROLLINFO);
3073 info.nPage = pageSize; // Have to set this, or scrollbar goes awry
3074 info.nMin = 0;
3075 info.nMax = range1;
3076 info.nPos = 0;
3077 info.fMask = SIF_RANGE | SIF_PAGE;
2bda0e17 3078
2d0a075d
JS
3079 HWND hWnd = (HWND) GetHWND();
3080 if (hWnd)
3081 ::SetScrollInfo(hWnd, dir, &info, refresh);
2bda0e17 3082#else
2d0a075d
JS
3083 int wOrient ;
3084 if (orient == wxHORIZONTAL)
3085 wOrient = SB_HORZ;
3086 else
3087 wOrient = SB_VERT;
3088
3089 HWND hWnd = (HWND) GetHWND();
3090 if (hWnd)
3091 ::SetScrollRange(hWnd, wOrient, 0, range, refresh);
2bda0e17
KB
3092#endif
3093}
3094
debe6624 3095void wxWindow::SetScrollPage(int orient, int page, bool refresh)
2bda0e17
KB
3096{
3097#if defined(__WIN95__)
2d0a075d
JS
3098 SCROLLINFO info;
3099 int dir;
3100
3101 if (orient == wxHORIZONTAL) {
3102 dir = SB_HORZ;
3103 m_xThumbSize = page;
3104 } else {
3105 dir = SB_VERT;
3106 m_yThumbSize = page;
3107 }
2bda0e17 3108
2d0a075d
JS
3109 info.cbSize = sizeof(SCROLLINFO);
3110 info.nPage = page;
3111 info.nMin = 0;
3112 info.fMask = SIF_PAGE ;
2bda0e17 3113
2d0a075d
JS
3114 HWND hWnd = (HWND) GetHWND();
3115 if (hWnd)
3116 ::SetScrollInfo(hWnd, dir, &info, refresh);
2bda0e17 3117#else
2d0a075d
JS
3118 if (orient == wxHORIZONTAL)
3119 m_xThumbSize = page;
3120 else
3121 m_yThumbSize = page;
2bda0e17
KB
3122#endif
3123}
3124
debe6624 3125int wxWindow::OldGetScrollRange(int orient) const
2bda0e17 3126{
2d0a075d
JS
3127 int wOrient ;
3128 if (orient == wxHORIZONTAL)
3129 wOrient = SB_HORZ;
3130 else
3131 wOrient = SB_VERT;
2bda0e17
KB
3132
3133#if __WATCOMC__ && defined(__WINDOWS_386__)
2d0a075d 3134 short minPos, maxPos;
2bda0e17 3135#else
2d0a075d 3136 int minPos, maxPos;
2bda0e17 3137#endif
2d0a075d
JS
3138 HWND hWnd = (HWND) GetHWND();
3139 if (hWnd)
2bda0e17 3140 {
2d0a075d
JS
3141 ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos);
3142#if defined(__WIN95__)
3143 // Try to adjust the range to cope with page size > 1
3144 // - a Windows API quirk
3145 int pageSize = GetScrollPage(orient);
3146 if ( pageSize > 1 )
3147 {
3148 maxPos -= (pageSize - 1);
3149 }
2bda0e17 3150#endif
2d0a075d
JS
3151 return maxPos;
3152 }
3153 else
3154 return 0;
2bda0e17
KB
3155}
3156
debe6624 3157int wxWindow::GetScrollPage(int orient) const
2bda0e17 3158{
2d0a075d
JS
3159 if (orient == wxHORIZONTAL)
3160 return m_xThumbSize;
3161 else
3162 return m_yThumbSize;
2bda0e17
KB
3163}
3164#endif
3165
debe6624 3166int wxWindow::GetScrollPos(int orient) const
2bda0e17 3167{
2d0a075d
JS
3168 int wOrient ;
3169 if (orient == wxHORIZONTAL)
3170 wOrient = SB_HORZ;
3171 else
3172 wOrient = SB_VERT;
3173 HWND hWnd = (HWND) GetHWND();
3174 if (hWnd)
3175 {
3176 return ::GetScrollPos(hWnd, wOrient);
3177 }
3178 else
3179 return 0;
2bda0e17
KB
3180}
3181
3182// This now returns the whole range, not just the number
3183// of positions that we can scroll.
debe6624 3184int wxWindow::GetScrollRange(int orient) const
2bda0e17 3185{
2d0a075d
JS
3186 int wOrient ;
3187 if (orient == wxHORIZONTAL)
3188 wOrient = SB_HORZ;
3189 else
3190 wOrient = SB_VERT;
2bda0e17
KB
3191
3192#if __WATCOMC__ && defined(__WINDOWS_386__)
2d0a075d 3193 short minPos, maxPos;
2bda0e17 3194#else
2d0a075d 3195 int minPos, maxPos;
2bda0e17 3196#endif
2d0a075d
JS
3197 HWND hWnd = (HWND) GetHWND();
3198 if (hWnd)
2bda0e17 3199 {
2d0a075d
JS
3200 ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos);
3201#if defined(__WIN95__)
3202 // Try to adjust the range to cope with page size > 1
3203 // - a Windows API quirk
ca5e9f67 3204 int pageSize = GetScrollThumb(orient);
2d0a075d
JS
3205 if ( pageSize > 1 )
3206 {
3207 maxPos -= (pageSize - 1);
3208 }
3209 // October 10th: new range concept.
3210 maxPos += pageSize;
2bda0e17 3211#endif
c085e333 3212
2d0a075d
JS
3213 return maxPos;
3214 }
3215 else
3216 return 0;
2bda0e17
KB
3217}
3218
debe6624 3219int wxWindow::GetScrollThumb(int orient) const
2bda0e17 3220{
2d0a075d
JS
3221 if (orient == wxHORIZONTAL)
3222 return m_xThumbSize;
3223 else
3224 return m_yThumbSize;
2bda0e17
KB
3225}
3226
debe6624 3227void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
2bda0e17
KB
3228{
3229#if defined(__WIN95__)
2d0a075d
JS
3230 SCROLLINFO info;
3231 int dir;
2bda0e17 3232
2d0a075d
JS
3233 if (orient == wxHORIZONTAL) {
3234 dir = SB_HORZ;
3235 } else {
3236 dir = SB_VERT;
3237 }
2bda0e17 3238
2d0a075d
JS
3239 info.cbSize = sizeof(SCROLLINFO);
3240 info.nPage = 0;
3241 info.nMin = 0;
3242 info.nPos = pos;
3243 info.fMask = SIF_POS ;
2bda0e17 3244
2d0a075d
JS
3245 HWND hWnd = (HWND) GetHWND();
3246 if (hWnd)
3247 ::SetScrollInfo(hWnd, dir, &info, refresh);
2bda0e17 3248#else
2d0a075d
JS
3249 int wOrient ;
3250 if (orient == wxHORIZONTAL)
3251 wOrient = SB_HORZ;
3252 else
3253 wOrient = SB_VERT;
3254
3255 HWND hWnd = (HWND) GetHWND();
3256 if (hWnd)
3257 ::SetScrollPos(hWnd, wOrient, pos, refresh);
2bda0e17
KB
3258#endif
3259}
3260
3261// New function that will replace some of the above.
debe6624 3262void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
2d0a075d 3263 int range, bool refresh)
2bda0e17
KB
3264{
3265/*
2d0a075d 3266SetScrollPage(orient, thumbVisible, FALSE);
2bda0e17 3267
2d0a075d
JS
3268 int oldRange = range - thumbVisible ;
3269 SetScrollRange(orient, oldRange, FALSE);
c085e333 3270
2bda0e17 3271 SetScrollPos(orient, pos, refresh);
2d0a075d 3272 */
2bda0e17 3273#if defined(__WIN95__)
2d0a075d 3274 int oldRange = range - thumbVisible ;
2bda0e17 3275
2d0a075d 3276 int range1 = oldRange;
2bda0e17 3277
2d0a075d
JS
3278 // Try to adjust the range to cope with page size > 1
3279 // - a Windows API quirk
3280 int pageSize = thumbVisible;
3281 if ( pageSize > 1 && range > 0)
3282 {
3283 range1 += (pageSize - 1);
3284 }
2bda0e17 3285
2d0a075d
JS
3286 SCROLLINFO info;
3287 int dir;
2bda0e17 3288
2d0a075d
JS
3289 if (orient == wxHORIZONTAL) {
3290 dir = SB_HORZ;
3291 } else {
3292 dir = SB_VERT;
3293 }
2bda0e17 3294
2d0a075d
JS
3295 info.cbSize = sizeof(SCROLLINFO);
3296 info.nPage = pageSize; // Have to set this, or scrollbar goes awry
3297 info.nMin = 0;
3298 info.nMax = range1;
3299 info.nPos = pos;
3300 info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
2bda0e17 3301
2d0a075d
JS
3302 HWND hWnd = (HWND) GetHWND();
3303 if (hWnd)
3304 ::SetScrollInfo(hWnd, dir, &info, refresh);
2bda0e17 3305#else
2d0a075d
JS
3306 int wOrient ;
3307 if (orient == wxHORIZONTAL)
3308 wOrient = SB_HORZ;
3309 else
3310 wOrient = SB_VERT;
3311
3312 HWND hWnd = (HWND) GetHWND();
3313 if (hWnd)
3314 {
3315 ::SetScrollRange(hWnd, wOrient, 0, range, FALSE);
3316 ::SetScrollPos(hWnd, wOrient, pos, refresh);
3317 }
2bda0e17 3318#endif
2d0a075d
JS
3319 if (orient == wxHORIZONTAL) {
3320 m_xThumbSize = thumbVisible;
3321 } else {
3322 m_yThumbSize = thumbVisible;
3323 }
2bda0e17
KB
3324}
3325
16e93305 3326void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
2bda0e17 3327{
564b2609
VZ
3328 RECT rect2;
3329 if ( rect )
3330 {
3331 rect2.left = rect->x;
3332 rect2.top = rect->y;
3333 rect2.right = rect->x + rect->width;
3334 rect2.bottom = rect->y + rect->height;
3335 }
c085e333 3336
564b2609
VZ
3337 if ( rect )
3338 ::ScrollWindow((HWND) GetHWND(), dx, dy, &rect2, NULL);
3339 else
3340 ::ScrollWindow((HWND) GetHWND(), dx, dy, NULL, NULL);
2bda0e17
KB
3341}
3342
2bda0e17
KB
3343void wxWindow::SetFont(const wxFont& font)
3344{
2d0a075d 3345 m_windowFont = font;
2bda0e17 3346
2d0a075d
JS
3347 if (!m_windowFont.Ok())
3348 return;
2bda0e17 3349
2d0a075d
JS
3350 HWND hWnd = (HWND) GetHWND();
3351 if (hWnd != 0)
3352 {
3353 if (m_windowFont.GetResourceHandle())
3354 SendMessage(hWnd, WM_SETFONT,
3355 (WPARAM)m_windowFont.GetResourceHandle(),TRUE);
3356 }
2bda0e17
KB
3357}
3358
3359void wxWindow::SubclassWin(WXHWND hWnd)
3360{
2d0a075d 3361 wxASSERT_MSG( !m_oldWndProc, "subclassing window twice?" );
a02eb1d2 3362
2d0a075d 3363 wxAssociateWinWithHandle((HWND)hWnd, this);
2bda0e17 3364
2d0a075d
JS
3365 m_oldWndProc = (WXFARPROC) GetWindowLong((HWND) hWnd, GWL_WNDPROC);
3366 SetWindowLong((HWND) hWnd, GWL_WNDPROC, (LONG) wxWndProc);
2bda0e17
KB
3367}
3368
fd3f686c 3369void wxWindow::UnsubclassWin()
2bda0e17 3370{
564b2609 3371 wxRemoveHandleAssociation(this);
c085e333 3372
2d0a075d
JS
3373 // Restore old Window proc
3374 if ((HWND) GetHWND())
564b2609 3375 {
2d0a075d
JS
3376 FARPROC farProc = (FARPROC) GetWindowLong((HWND) GetHWND(), GWL_WNDPROC);
3377 if ((m_oldWndProc != 0) && (farProc != (FARPROC) m_oldWndProc))
3378 {
3379 SetWindowLong((HWND) GetHWND(), GWL_WNDPROC, (LONG) m_oldWndProc);
3380 m_oldWndProc = 0;
3381 }
564b2609 3382 }
2bda0e17
KB
3383}
3384
3385// Make a Windows extended style from the given wxWindows window style
3386WXDWORD wxWindow::MakeExtendedStyle(long style, bool eliminateBorders)
3387{
564b2609
VZ
3388 WXDWORD exStyle = 0;
3389 if ( style & wxTRANSPARENT_WINDOW )
3390 exStyle |= WS_EX_TRANSPARENT ;
c085e333 3391
2d0a075d
JS
3392 if ( !eliminateBorders )
3393 {
3394 if ( style & wxSUNKEN_BORDER )
3395 exStyle |= WS_EX_CLIENTEDGE ;
3396 if ( style & wxDOUBLE_BORDER )
3397 exStyle |= WS_EX_DLGMODALFRAME ;
2bda0e17 3398#if defined(__WIN95__)
2d0a075d
JS
3399 if ( style & wxRAISED_BORDER )
3400 exStyle |= WS_EX_WINDOWEDGE ;
3401 if ( style & wxSTATIC_BORDER )
3402 exStyle |= WS_EX_STATICEDGE ;
2bda0e17 3403#endif
2d0a075d
JS
3404 }
3405 return exStyle;
2bda0e17
KB
3406}
3407
3408// Determines whether native 3D effects or CTL3D should be used,
3409// applying a default border style if required, and returning an extended
3410// style to pass to CreateWindowEx.
3411WXDWORD wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D)
3412{
2d0a075d
JS
3413 // If matches certain criteria, then assume no 3D effects
3414 // unless specifically requested (dealt with in MakeExtendedStyle)
3415 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl)) || (m_windowStyle & wxNO_BORDER) )
3416 {
3417 *want3D = FALSE;
3418 return MakeExtendedStyle(m_windowStyle, FALSE);
3419 }
2bda0e17 3420
2d0a075d
JS
3421 // Determine whether we should be using 3D effects or not.
3422 bool nativeBorder = FALSE; // by default, we don't want a Win95 effect
2bda0e17 3423
2d0a075d
JS
3424 // 1) App can specify global 3D effects
3425 *want3D = wxTheApp->GetAuto3D();
2bda0e17 3426
2d0a075d
JS
3427 // 2) If the parent is being drawn with user colours, or simple border specified,
3428 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
3429 if (GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) || (m_windowStyle & wxSIMPLE_BORDER))
3430 *want3D = FALSE;
2bda0e17 3431
2d0a075d
JS
3432 // 3) Control can override this global setting by defining
3433 // a border style, e.g. wxSUNKEN_BORDER
3434 if (m_windowStyle & wxSUNKEN_BORDER )
3435 *want3D = TRUE;
2bda0e17 3436
2d0a075d
JS
3437 // 4) If it's a special border, CTL3D can't cope so we want a native border
3438 if ( (m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
3439 (m_windowStyle & wxSTATIC_BORDER) )
3440 {
3441 *want3D = TRUE;
3442 nativeBorder = TRUE;
3443 }
2bda0e17 3444
2d0a075d
JS
3445 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
3446 // effects from extended style
2bda0e17 3447#if CTL3D
2d0a075d
JS
3448 if ( *want3D )
3449 nativeBorder = FALSE;
2bda0e17 3450#endif
c085e333 3451
2d0a075d 3452 DWORD exStyle = MakeExtendedStyle(m_windowStyle, !nativeBorder);
2bda0e17 3453
2d0a075d
JS
3454 // If we want 3D, but haven't specified a border here,
3455 // apply the default border style specified.
3456 // TODO what about non-Win95 WIN32? Does it have borders?
2bda0e17 3457#if defined(__WIN95__) && !CTL3D
2d0a075d 3458 if (defaultBorderStyle && (*want3D) && ! ((m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
2bda0e17 3459 (m_windowStyle & wxSTATIC_BORDER) || (m_windowStyle & wxSIMPLE_BORDER) ))
2d0a075d 3460 exStyle |= defaultBorderStyle; // WS_EX_CLIENTEDGE ;
2bda0e17 3461#endif
c085e333 3462
2d0a075d 3463 return exStyle;
2bda0e17
KB
3464}
3465
2bda0e17
KB
3466void wxWindow::OnChar(wxKeyEvent& event)
3467{
47cbd6da
VZ
3468 if ( event.KeyCode() == WXK_TAB ) {
3469 // propagate the TABs to the parent - it's up to it to decide what
3470 // to do with it
3471 if ( GetParent() ) {
02800301 3472 if ( GetParent()->GetEventHandler()->ProcessEvent(event) )
47cbd6da
VZ
3473 return;
3474 }
3475 }
c085e333 3476
47cbd6da
VZ
3477 bool isVirtual;
3478 int id = wxCharCodeWXToMSW((int)event.KeyCode(), &isVirtual);
c085e333 3479
47cbd6da
VZ
3480 if ( id == -1 )
3481 id= m_lastWParam;
c085e333 3482
2bda0e17 3483 if ( !event.ControlDown() )
47cbd6da 3484 (void) MSWDefWindowProc(m_lastMsg, (WPARAM) id, m_lastLParam);
2bda0e17
KB
3485}
3486
3487void wxWindow::OnPaint(wxPaintEvent& event)
3488{
564b2609 3489 Default();
2bda0e17
KB
3490}
3491
3492bool wxWindow::IsEnabled(void) const
3493{
564b2609 3494 return (::IsWindowEnabled((HWND) GetHWND()) != 0);
2bda0e17
KB
3495}
3496
3497// Dialog support: override these and call
3498// base class members to add functionality
3499// that can't be done using validators.
3500// NOTE: these functions assume that controls
3501// are direct children of this window, not grandchildren
3502// or other levels of descendant.
3503
3504// Transfer values to controls. If returns FALSE,
3505// it's an application error (pops up a dialog)
fd3f686c 3506bool wxWindow::TransferDataToWindow()
2bda0e17 3507{
c0ed460c 3508 wxNode *node = GetChildren().First();
564b2609
VZ
3509 while ( node )
3510 {
3511 wxWindow *child = (wxWindow *)node->Data();
3512 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */
2d0a075d 3513 !child->GetValidator()->TransferToWindow() )
564b2609
VZ
3514 {
3515 wxMessageBox("Application Error", "Could not transfer data to window", wxOK|wxICON_EXCLAMATION);
3516 return FALSE;
3517 }
c085e333 3518
564b2609
VZ
3519 node = node->Next();
3520 }
3521 return TRUE;
2bda0e17
KB
3522}
3523
3524// Transfer values from controls. If returns FALSE,
3525// validation failed: don't quit
fd3f686c 3526bool wxWindow::TransferDataFromWindow()
2bda0e17 3527{
c0ed460c 3528 wxNode *node = GetChildren().First();
564b2609
VZ
3529 while ( node )
3530 {
3531 wxWindow *child = (wxWindow *)node->Data();
3532 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->TransferFromWindow() )
3533 {
3534 return FALSE;
3535 }
c085e333 3536
564b2609
VZ
3537 node = node->Next();
3538 }
3539 return TRUE;
2bda0e17
KB
3540}
3541
fd3f686c 3542bool wxWindow::Validate()
2bda0e17 3543{
c0ed460c 3544 wxNode *node = GetChildren().First();
564b2609
VZ
3545 while ( node )
3546 {
3547 wxWindow *child = (wxWindow *)node->Data();
3548 if ( child->GetValidator() && /* child->GetValidator()->Ok() && */ !child->GetValidator()->Validate(this) )
3549 {
3550 return FALSE;
3551 }
c085e333 3552
564b2609
VZ
3553 node = node->Next();
3554 }
3555 return TRUE;
2bda0e17
KB
3556}
3557
3558// Get the window with the focus
fd3f686c 3559wxWindow *wxWindow::FindFocus()
2bda0e17
KB
3560{
3561 HWND hWnd = ::GetFocus();
3562 if ( hWnd )
3563 {
3564 return wxFindWinFromHandle((WXHWND) hWnd);
3565 }
3566 return NULL;
3567}
3568
3569void wxWindow::AddChild(wxWindow *child)
3570{
c0ed460c 3571 GetChildren().Append(child);
2d0a075d 3572 child->m_windowParent = this;
2bda0e17
KB
3573}
3574
3575void wxWindow::RemoveChild(wxWindow *child)
3576{
c0ed460c
JS
3577// if (GetChildren())
3578 GetChildren().DeleteObject(child);
2d0a075d 3579 child->m_windowParent = NULL;
2bda0e17
KB
3580}
3581
fd3f686c 3582void wxWindow::DestroyChildren()
2bda0e17 3583{
2d0a075d 3584 wxNode *node;
c0ed460c 3585 while ((node = GetChildren().First()) != (wxNode *)NULL) {
2d0a075d
JS
3586 wxWindow *child;
3587 if ((child = (wxWindow *)node->Data()) != (wxWindow *)NULL) {
3588 delete child;
c0ed460c 3589 if ( GetChildren().Member(child) )
2d0a075d
JS
3590 delete node;
3591 }
3592 } /* while */
2bda0e17
KB
3593}
3594
debe6624 3595void wxWindow::MakeModal(bool modal)
2bda0e17 3596{
2d0a075d
JS
3597 // Disable all other windows
3598 if (this->IsKindOf(CLASSINFO(wxDialog)) || this->IsKindOf(CLASSINFO(wxFrame)))
2bda0e17 3599 {
2d0a075d
JS
3600 wxNode *node = wxTopLevelWindows.First();
3601 while (node)
3602 {
3603 wxWindow *win = (wxWindow *)node->Data();
3604 if (win != this)
3605 win->Enable(!modal);
2bda0e17 3606
2d0a075d
JS
3607 node = node->Next();
3608 }
2bda0e17 3609 }
2bda0e17
KB
3610}
3611
3612// If nothing defined for this, try the parent.
3613// E.g. we may be a button loaded from a resource, with no callback function
3614// defined.
3615void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
3616{
2d0a075d
JS
3617 if (GetEventHandler()->ProcessEvent(event) )
3618 return;
3619 if (m_windowParent)
3620 m_windowParent->GetEventHandler()->OnCommand(win, event);
2bda0e17
KB
3621}
3622
3623void wxWindow::SetConstraints(wxLayoutConstraints *c)
3624{
2d0a075d
JS
3625 if (m_constraints)
3626 {
3627 UnsetConstraints(m_constraints);
3628 delete m_constraints;
3629 }
3630 m_constraints = c;
3631 if (m_constraints)
3632 {
3633 // Make sure other windows know they're part of a 'meaningful relationship'
3634 if (m_constraints->left.GetOtherWindow() && (m_constraints->left.GetOtherWindow() != this))
3635 m_constraints->left.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3636 if (m_constraints->top.GetOtherWindow() && (m_constraints->top.GetOtherWindow() != this))
3637 m_constraints->top.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3638 if (m_constraints->right.GetOtherWindow() && (m_constraints->right.GetOtherWindow() != this))
3639 m_constraints->right.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3640 if (m_constraints->bottom.GetOtherWindow() && (m_constraints->bottom.GetOtherWindow() != this))
3641 m_constraints->bottom.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3642 if (m_constraints->width.GetOtherWindow() && (m_constraints->width.GetOtherWindow() != this))
3643 m_constraints->width.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3644 if (m_constraints->height.GetOtherWindow() && (m_constraints->height.GetOtherWindow() != this))
3645 m_constraints->height.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3646 if (m_constraints->centreX.GetOtherWindow() && (m_constraints->centreX.GetOtherWindow() != this))
3647 m_constraints->centreX.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3648 if (m_constraints->centreY.GetOtherWindow() && (m_constraints->centreY.GetOtherWindow() != this))
3649 m_constraints->centreY.GetOtherWindow()->AddConstraintReference((wxWindow *)this);
3650 }
2bda0e17
KB
3651}
3652
3653// This removes any dangling pointers to this window
3654// in other windows' constraintsInvolvedIn lists.
3655void wxWindow::UnsetConstraints(wxLayoutConstraints *c)
3656{
2d0a075d
JS
3657 if (c)
3658 {
3659 if (c->left.GetOtherWindow() && (c->top.GetOtherWindow() != this))
3660 c->left.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3661 if (c->top.GetOtherWindow() && (c->top.GetOtherWindow() != this))
3662 c->top.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3663 if (c->right.GetOtherWindow() && (c->right.GetOtherWindow() != this))
3664 c->right.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3665 if (c->bottom.GetOtherWindow() && (c->bottom.GetOtherWindow() != this))
3666 c->bottom.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3667 if (c->width.GetOtherWindow() && (c->width.GetOtherWindow() != this))
3668 c->width.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3669 if (c->height.GetOtherWindow() && (c->height.GetOtherWindow() != this))
3670 c->height.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3671 if (c->centreX.GetOtherWindow() && (c->centreX.GetOtherWindow() != this))
3672 c->centreX.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3673 if (c->centreY.GetOtherWindow() && (c->centreY.GetOtherWindow() != this))
3674 c->centreY.GetOtherWindow()->RemoveConstraintReference((wxWindow *)this);
3675 }
2bda0e17
KB
3676}
3677
3678// Back-pointer to other windows we're involved with, so if we delete
3679// this window, we must delete any constraints we're involved with.
3680void wxWindow::AddConstraintReference(wxWindow *otherWin)
3681{
2d0a075d
JS
3682 if (!m_constraintsInvolvedIn)
3683 m_constraintsInvolvedIn = new wxList;
3684 if (!m_constraintsInvolvedIn->Member(otherWin))
3685 m_constraintsInvolvedIn->Append(otherWin);
2bda0e17
KB
3686}
3687
3688// REMOVE back-pointer to other windows we're involved with.
3689void wxWindow::RemoveConstraintReference(wxWindow *otherWin)
3690{
2d0a075d
JS
3691 if (m_constraintsInvolvedIn)
3692 m_constraintsInvolvedIn->DeleteObject(otherWin);
2bda0e17
KB
3693}
3694
3695// Reset any constraints that mention this window
fd3f686c 3696void wxWindow::DeleteRelatedConstraints()
2bda0e17 3697{
2d0a075d 3698 if (m_constraintsInvolvedIn)
2bda0e17 3699 {
2d0a075d
JS
3700 wxNode *node = m_constraintsInvolvedIn->First();
3701 while (node)
3702 {
3703 wxWindow *win = (wxWindow *)node->Data();
3704 wxNode *next = node->Next();
3705 wxLayoutConstraints *constr = win->GetConstraints();
3706
3707 // Reset any constraints involving this window
3708 if (constr)
3709 {
3710 constr->left.ResetIfWin((wxWindow *)this);
3711 constr->top.ResetIfWin((wxWindow *)this);
3712 constr->right.ResetIfWin((wxWindow *)this);
3713 constr->bottom.ResetIfWin((wxWindow *)this);
3714 constr->width.ResetIfWin((wxWindow *)this);
3715 constr->height.ResetIfWin((wxWindow *)this);
3716 constr->centreX.ResetIfWin((wxWindow *)this);
3717 constr->centreY.ResetIfWin((wxWindow *)this);
3718 }
3719 delete node;
3720 node = next;
3721 }
3722 delete m_constraintsInvolvedIn;
3723 m_constraintsInvolvedIn = NULL;
2bda0e17 3724 }
2bda0e17
KB
3725}
3726
3727void wxWindow::SetSizer(wxSizer *sizer)
3728{
2d0a075d
JS
3729 m_windowSizer = sizer;
3730 if (sizer)
3731 sizer->SetSizerParent((wxWindow *)this);
2bda0e17
KB
3732}
3733
3734/*
2d0a075d
JS
3735* New version
3736*/
2bda0e17 3737
fd3f686c 3738bool wxWindow::Layout()
2bda0e17 3739{
2d0a075d
JS
3740 if (GetConstraints())
3741 {
3742 int w, h;
3743 GetClientSize(&w, &h);
3744 GetConstraints()->width.SetValue(w);
3745 GetConstraints()->height.SetValue(h);
3746 }
3747
3748 // If top level (one sizer), evaluate the sizer's constraints.
3749 if (GetSizer())
3750 {
3751 int noChanges;
3752 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
3753 GetSizer()->LayoutPhase1(&noChanges);
3754 GetSizer()->LayoutPhase2(&noChanges);
3755 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
3756 return TRUE;
3757 }
3758 else
3759 {
3760 // Otherwise, evaluate child constraints
3761 ResetConstraints(); // Mark all constraints as unevaluated
3762 DoPhase(1); // Just one phase need if no sizers involved
3763 DoPhase(2);
3764 SetConstraintSizes(); // Recursively set the real window sizes
3765 }
2bda0e17 3766 return TRUE;
2bda0e17
KB
3767}
3768
3769
3770// Do a phase of evaluating constraints:
3771// the default behaviour. wxSizers may do a similar
3772// thing, but also impose their own 'constraints'
3773// and order the evaluation differently.
3774bool wxWindow::LayoutPhase1(int *noChanges)
3775{
2d0a075d
JS
3776 wxLayoutConstraints *constr = GetConstraints();
3777 if (constr)
3778 {
3779 return constr->SatisfyConstraints((wxWindow *)this, noChanges);
3780 }
3781 else
3782 return TRUE;
2bda0e17
KB
3783}
3784
3785bool wxWindow::LayoutPhase2(int *noChanges)
3786{
2d0a075d
JS
3787 *noChanges = 0;
3788
3789 // Layout children
3790 DoPhase(1);
3791 DoPhase(2);
3792 return TRUE;
2bda0e17
KB
3793}
3794
3795// Do a phase of evaluating child constraints
debe6624 3796bool wxWindow::DoPhase(int phase)
2bda0e17 3797{
2d0a075d
JS
3798 int noIterations = 0;
3799 int maxIterations = 500;
3800 int noChanges = 1;
3801 int noFailures = 0;
3802 wxList succeeded;
3803 while ((noChanges > 0) && (noIterations < maxIterations))
2bda0e17 3804 {
2d0a075d
JS
3805 noChanges = 0;
3806 noFailures = 0;
c0ed460c 3807 wxNode *node = GetChildren().First();
2d0a075d 3808 while (node)
2bda0e17 3809 {
2d0a075d
JS
3810 wxWindow *child = (wxWindow *)node->Data();
3811 if (!child->IsKindOf(CLASSINFO(wxFrame)) && !child->IsKindOf(CLASSINFO(wxDialog)))
2bda0e17 3812 {
2d0a075d
JS
3813 wxLayoutConstraints *constr = child->GetConstraints();
3814 if (constr)
3815 {
3816 if (succeeded.Member(child))
3817 {
3818 }
3819 else
3820 {
3821 int tempNoChanges = 0;
3822 bool success = ( (phase == 1) ? child->LayoutPhase1(&tempNoChanges) : child->LayoutPhase2(&tempNoChanges) ) ;
3823 noChanges += tempNoChanges;
3824 if (success)
3825 {
3826 succeeded.Append(child);
3827 }
3828 }
3829 }
2bda0e17 3830 }
2d0a075d 3831 node = node->Next();
2bda0e17 3832 }
2d0a075d 3833 noIterations ++;
2bda0e17 3834 }
2d0a075d 3835 return TRUE;
2bda0e17
KB
3836}
3837
fd3f686c 3838void wxWindow::ResetConstraints()
2bda0e17 3839{
2d0a075d
JS
3840 wxLayoutConstraints *constr = GetConstraints();
3841 if (constr)
3842 {
3843 constr->left.SetDone(FALSE);
3844 constr->top.SetDone(FALSE);
3845 constr->right.SetDone(FALSE);
3846 constr->bottom.SetDone(FALSE);
3847 constr->width.SetDone(FALSE);
3848 constr->height.SetDone(FALSE);
3849 constr->centreX.SetDone(FALSE);
3850 constr->centreY.SetDone(FALSE);
3851 }
c0ed460c 3852 wxNode *node = GetChildren().First();
2d0a075d
JS
3853 while (node)
3854 {
3855 wxWindow *win = (wxWindow *)node->Data();
3856 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
3857 win->ResetConstraints();
3858 node = node->Next();
3859 }
2bda0e17
KB
3860}
3861
3862// Need to distinguish between setting the 'fake' size for
3863// windows and sizers, and setting the real values.
debe6624 3864void wxWindow::SetConstraintSizes(bool recurse)
2bda0e17 3865{
2d0a075d
JS
3866 wxLayoutConstraints *constr = GetConstraints();
3867 if (constr && constr->left.GetDone() && constr->right.GetDone() &&
3868 constr->width.GetDone() && constr->height.GetDone())
2bda0e17 3869 {
2d0a075d
JS
3870 int x = constr->left.GetValue();
3871 int y = constr->top.GetValue();
3872 int w = constr->width.GetValue();
3873 int h = constr->height.GetValue();
3874
3875 // If we don't want to resize this window, just move it...
3876 if ((constr->width.GetRelationship() != wxAsIs) ||
3877 (constr->height.GetRelationship() != wxAsIs))
3878 {
3879 // Calls Layout() recursively. AAAGH. How can we stop that.
3880 // Simply take Layout() out of non-top level OnSizes.
3881 SizerSetSize(x, y, w, h);
3882 }
3883 else
3884 {
3885 SizerMove(x, y);
3886 }
2bda0e17 3887 }
2d0a075d 3888 else if (constr)
2bda0e17 3889 {
2d0a075d 3890 char *windowClass = this->GetClassInfo()->GetClassName();
2bda0e17 3891
2d0a075d
JS
3892 wxString winName;
3893 if (GetName() == "")
3894 winName = "unnamed";
3895 else
3896 winName = GetName();
3897 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass, (const char *)winName);
3898 if (!constr->left.GetDone())
3899 wxDebugMsg(" unsatisfied 'left' constraint.\n");
3900 if (!constr->right.GetDone())
3901 wxDebugMsg(" unsatisfied 'right' constraint.\n");
3902 if (!constr->width.GetDone())
3903 wxDebugMsg(" unsatisfied 'width' constraint.\n");
3904 if (!constr->height.GetDone())
3905 wxDebugMsg(" unsatisfied 'height' constraint.\n");
3906 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
3907 }
2bda0e17 3908
2d0a075d 3909 if (recurse)
2bda0e17 3910 {
c0ed460c 3911 wxNode *node = GetChildren().First();
2d0a075d
JS
3912 while (node)
3913 {
3914 wxWindow *win = (wxWindow *)node->Data();
3915 if (!win->IsKindOf(CLASSINFO(wxFrame)) && !win->IsKindOf(CLASSINFO(wxDialog)))
3916 win->SetConstraintSizes();
3917 node = node->Next();
3918 }
2bda0e17 3919 }
2bda0e17
KB
3920}
3921
3922// This assumes that all sizers are 'on' the same
3923// window, i.e. the parent of this window.
3924void wxWindow::TransformSizerToActual(int *x, int *y) const
3925{
2d0a075d
JS
3926 if (!m_sizerParent || m_sizerParent->IsKindOf(CLASSINFO(wxDialog)) ||
3927 m_sizerParent->IsKindOf(CLASSINFO(wxFrame)) )
3928 return;
3929
3930 int xp, yp;
3931 m_sizerParent->GetPosition(&xp, &yp);
3932 m_sizerParent->TransformSizerToActual(&xp, &yp);
3933 *x += xp;
3934 *y += yp;
2bda0e17
KB
3935}
3936
debe6624 3937void wxWindow::SizerSetSize(int x, int y, int w, int h)
2bda0e17 3938{
564b2609
VZ
3939 int xx = x;
3940 int yy = y;
2d0a075d
JS
3941 TransformSizerToActual(&xx, &yy);
3942 SetSize(xx, yy, w, h);
2bda0e17
KB
3943}
3944
debe6624 3945void wxWindow::SizerMove(int x, int y)
2bda0e17 3946{
564b2609
VZ
3947 int xx = x;
3948 int yy = y;
2d0a075d
JS
3949 TransformSizerToActual(&xx, &yy);
3950 Move(xx, yy);
2bda0e17
KB
3951}
3952
3953// Only set the size/position of the constraint (if any)
debe6624 3954void wxWindow::SetSizeConstraint(int x, int y, int w, int h)
2bda0e17 3955{
2d0a075d
JS
3956 wxLayoutConstraints *constr = GetConstraints();
3957 if (constr)
2bda0e17 3958 {
2d0a075d
JS
3959 if (x != -1)
3960 {
3961 constr->left.SetValue(x);
3962 constr->left.SetDone(TRUE);
3963 }
3964 if (y != -1)
3965 {
3966 constr->top.SetValue(y);
3967 constr->top.SetDone(TRUE);
3968 }
3969 if (w != -1)
3970 {
3971 constr->width.SetValue(w);
3972 constr->width.SetDone(TRUE);
3973 }
3974 if (h != -1)
3975 {
3976 constr->height.SetValue(h);
3977 constr->height.SetDone(TRUE);
3978 }
2bda0e17 3979 }
2bda0e17
KB
3980}
3981
debe6624 3982void wxWindow::MoveConstraint(int x, int y)
2bda0e17 3983{
2d0a075d
JS
3984 wxLayoutConstraints *constr = GetConstraints();
3985 if (constr)
2bda0e17 3986 {
2d0a075d
JS
3987 if (x != -1)
3988 {
3989 constr->left.SetValue(x);
3990 constr->left.SetDone(TRUE);
3991 }
3992 if (y != -1)
3993 {
3994 constr->top.SetValue(y);
3995 constr->top.SetDone(TRUE);
3996 }
2bda0e17 3997 }
2bda0e17
KB
3998}
3999
4000void wxWindow::GetSizeConstraint(int *w, int *h) const
4001{
2d0a075d
JS
4002 wxLayoutConstraints *constr = GetConstraints();
4003 if (constr)
4004 {
4005 *w = constr->width.GetValue();
4006 *h = constr->height.GetValue();
4007 }
4008 else
4009 GetSize(w, h);
2bda0e17
KB
4010}
4011
4012void wxWindow::GetClientSizeConstraint(int *w, int *h) const
4013{
2d0a075d
JS
4014 wxLayoutConstraints *constr = GetConstraints();
4015 if (constr)
4016 {
4017 *w = constr->width.GetValue();
4018 *h = constr->height.GetValue();
4019 }
4020 else
4021 GetClientSize(w, h);
2bda0e17
KB
4022}
4023
4024void wxWindow::GetPositionConstraint(int *x, int *y) const
4025{
2d0a075d
JS
4026 wxLayoutConstraints *constr = GetConstraints();
4027 if (constr)
4028 {
4029 *x = constr->left.GetValue();
4030 *y = constr->top.GetValue();
4031 }
4032 else
4033 GetPosition(x, y);
2bda0e17
KB
4034}
4035
debe6624 4036bool wxWindow::Close(bool force)
2bda0e17 4037{
2d0a075d
JS
4038 wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
4039 event.SetEventObject(this);
4040 event.SetForce(force);
4041 event.SetCanVeto(!force);
2bda0e17 4042
2d0a075d 4043 return (GetEventHandler()->ProcessEvent(event) && !event.GetVeto());
2bda0e17
KB
4044}
4045
debe6624 4046wxObject* wxWindow::GetChild(int number) const
2bda0e17 4047{
2d0a075d 4048 // Return a pointer to the Nth object in the Panel
c0ed460c
JS
4049// if (!GetChildren())
4050// return(NULL) ;
4051 wxNode *node = GetChildren().First();
2d0a075d
JS
4052 int n = number;
4053 while (node && n--)
4054 node = node->Next() ;
4055 if (node)
4056 {
4057 wxObject *obj = (wxObject *)node->Data();
4058 return(obj) ;
4059 }
4060 else
4061 return NULL ;
2bda0e17
KB
4062}
4063
4064void wxWindow::OnDefaultAction(wxControl *initiatingItem)
4065{
debe6624 4066/* This is obsolete now; if we wish to intercept listbox double-clicks,
2d0a075d
JS
4067* we explicitly intercept the wxEVT_COMMAND_LISTBOX_DOUBLECLICKED
4068* event.
debe6624
JS
4069
4070 if (initiatingItem->IsKindOf(CLASSINFO(wxListBox)))
2bda0e17 4071 {
2d0a075d
JS
4072 wxListBox *lbox = (wxListBox *)initiatingItem;
4073 wxCommandEvent event(wxEVT_COMMAND_LEFT_DCLICK);
4074 event.m_commandInt = -1;
4075 if ((lbox->GetWindowStyleFlag() & wxLB_MULTIPLE) == 0)
2bda0e17 4076 {
2d0a075d
JS
4077 event.m_commandString = copystring(lbox->GetStringSelection());
4078 event.m_commandInt = lbox->GetSelection();
4079 event.m_clientData = lbox->wxListBox::GetClientData(event.m_commandInt);
2bda0e17 4080 }
2d0a075d 4081 event.m_eventObject = lbox;
c085e333 4082
2d0a075d 4083 lbox->ProcessCommand(event);
c085e333 4084
2d0a075d
JS
4085 if (event.m_commandString)
4086 delete[] event.m_commandString;
4087 return;
4088 }
4089
4090 wxButton *but = GetDefaultItem();
4091 if (but)
4092 {
4093 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED);
4094 event.SetEventObject(but);
4095 but->Command(event);
4096 }
4097 */
2bda0e17
KB
4098}
4099
fd3f686c 4100void wxWindow::Clear()
2bda0e17 4101{
564b2609 4102 wxClientDC dc(this);
2bda0e17
KB
4103 wxBrush brush(GetBackgroundColour(), wxSOLID);
4104 dc.SetBackground(brush);
4105 dc.Clear();
4106}
4107
4108// Fits the panel around the items
fd3f686c 4109void wxWindow::Fit()
2bda0e17 4110{
564b2609
VZ
4111 int maxX = 0;
4112 int maxY = 0;
c0ed460c 4113 wxNode *node = GetChildren().First();
564b2609
VZ
4114 while ( node )
4115 {
4116 wxWindow *win = (wxWindow *)node->Data();
4117 int wx, wy, ww, wh;
4118 win->GetPosition(&wx, &wy);
4119 win->GetSize(&ww, &wh);
4120 if ( wx + ww > maxX )
4121 maxX = wx + ww;
4122 if ( wy + wh > maxY )
4123 maxY = wy + wh;
c085e333 4124
564b2609
VZ
4125 node = node->Next();
4126 }
4127 SetClientSize(maxX + 5, maxY + 5);
2bda0e17
KB
4128}
4129
4130void wxWindow::SetValidator(const wxValidator& validator)
4131{
564b2609
VZ
4132 if ( m_windowValidator )
4133 delete m_windowValidator;
4134 m_windowValidator = validator.Clone();
c085e333 4135
564b2609
VZ
4136 if ( m_windowValidator )
4137 m_windowValidator->SetWindow(this) ;
2bda0e17
KB
4138}
4139
4140// Find a window by id or name
debe6624 4141wxWindow *wxWindow::FindWindow(long id)
2bda0e17 4142{
564b2609
VZ
4143 if ( GetId() == id)
4144 return this;
c085e333 4145
c0ed460c 4146 wxNode *node = GetChildren().First();
564b2609
VZ
4147 while ( node )
4148 {
4149 wxWindow *child = (wxWindow *)node->Data();
4150 wxWindow *found = child->FindWindow(id);
4151 if ( found )
4152 return found;
4153 node = node->Next();
4154 }
4155 return NULL;
2bda0e17
KB
4156}
4157
4158wxWindow *wxWindow::FindWindow(const wxString& name)
4159{
564b2609
VZ
4160 if ( GetName() == name)
4161 return this;
c085e333 4162
c0ed460c 4163 wxNode *node = GetChildren().First();
564b2609
VZ
4164 while ( node )
4165 {
4166 wxWindow *child = (wxWindow *)node->Data();
4167 wxWindow *found = child->FindWindow(name);
4168 if ( found )
4169 return found;
4170 node = node->Next();
4171 }
4172 return NULL;
2bda0e17
KB
4173}
4174
4175/* TODO
4176// Default input behaviour for a scrolling canvas should be to scroll
4177// according to the cursor keys pressed
4178void wxWindow::OnChar(wxKeyEvent& event)
4179{
2d0a075d
JS
4180int x_page = 0;
4181int y_page = 0;
4182int start_x = 0;
4183int start_y = 0;
4184// Bugfix Begin
4185int v_width = 0;
4186int v_height = 0;
4187int y_pages = 0;
4188// Bugfix End
2bda0e17
KB
4189
4190 GetScrollUnitsPerPage(&x_page, &y_page);
4191 // Bugfix Begin
4192 GetVirtualSize(&v_width,&v_height);
4193 // Bugfix End
4194 ViewStart(&start_x, &start_y);
4195 // Bugfix begin
4196 if (vert_units)
2d0a075d 4197 y_pages = (int)(v_height/vert_units) - y_page;
c085e333 4198
2d0a075d
JS
4199 #ifdef __WXMSW__
4200 int y = 0;
4201 #else
4202 int y = y_page-1;
4203 #endif
4204 // Bugfix End
4205 switch (event.keyCode)
4206 {
4207 case WXK_PRIOR:
4208 {
4209 // BugFix Begin
4210 if (y_page > 0)
4211 {
4212 if (start_y - y_page > 0)
4213 Scroll(start_x, start_y - y_page);
4214 else
4215 Scroll(start_x, 0);
4216 }
4217 // Bugfix End
4218 break;
4219 }
4220 case WXK_NEXT:
4221 {
4222 // Bugfix Begin
4223 if ((y_page > 0) && (start_y <= y_pages-y-1))
4224 {
4225 if (y_pages + y < start_y + y_page)
4226 Scroll(start_x, y_pages + y);
4227 else
4228 Scroll(start_x, start_y + y_page);
4229 }
4230 // Bugfix End
4231 break;
4232 }
4233 case WXK_UP:
4234 {
4235 if ((y_page > 0) && (start_y >= 1))
4236 Scroll(start_x, start_y - 1);
4237 break;
4238 }
4239 case WXK_DOWN:
4240 {
4241 // Bugfix Begin
4242 if ((y_page > 0) && (start_y <= y_pages-y-1))
4243 // Bugfix End
4244 {
4245 Scroll(start_x, start_y + 1);
4246 }
4247 break;
4248 }
4249 case WXK_LEFT:
4250 {
4251 if ((x_page > 0) && (start_x >= 1))
4252 Scroll(start_x - 1, start_y);
4253 break;
4254 }
4255 case WXK_RIGHT:
4256 {
4257 if (x_page > 0)
4258 Scroll(start_x + 1, start_y);
4259 break;
4260 }
4261 case WXK_HOME:
4262 {
4263 Scroll(0, 0);
4264 break;
4265 }
4266 // This is new
4267 case WXK_END:
4268 {
4269 Scroll(start_x, y_pages+y);
4270 break;
4271 }
4272 // end
4273 }
4274 }
2bda0e17
KB
4275*/
4276
4277// Setup background and foreground colours correctly
fd3f686c 4278void wxWindow::SetupColours()
2bda0e17 4279{
564b2609
VZ
4280 if (GetParent())
4281 SetBackgroundColour(GetParent()->GetBackgroundColour());
2bda0e17
KB
4282}
4283
2bda0e17
KB
4284void wxWindow::OnIdle(wxIdleEvent& event)
4285{
43d811ea
JS
4286 // Check if we need to send a LEAVE event
4287 if (m_mouseInWindow)
4288 {
4289 POINT pt;
4290 ::GetCursorPos(&pt);
4291 if (::WindowFromPoint(pt) != (HWND) GetHWND())
4292 {
4293 // Generate a LEAVE event
4294 m_mouseInWindow = FALSE;
c085e333 4295
2d524929 4296 int state = 0;
567da5c6
JS
4297 if (::GetKeyState(VK_SHIFT) != 0)
4298 state |= MK_SHIFT;
4299 if (::GetKeyState(VK_CONTROL) != 0)
4300 state |= MK_CONTROL;
c085e333 4301
567da5c6
JS
4302 // Unfortunately the mouse button and keyboard state may have changed
4303 // by the time the OnIdle function is called, so 'state' may be
4304 // meaningless.
c085e333 4305
567da5c6 4306 MSWOnMouseLeave(pt.x, pt.y, state);
43d811ea
JS
4307 }
4308 }
564b2609 4309 UpdateWindowUI();
2bda0e17
KB
4310}
4311
4312// Raise the window to the top of the Z order
fd3f686c 4313void wxWindow::Raise()
2bda0e17
KB
4314{
4315 ::BringWindowToTop((HWND) GetHWND());
4316}
4317
4318// Lower the window to the bottom of the Z order
fd3f686c 4319void wxWindow::Lower()
2bda0e17
KB
4320{
4321 ::SetWindowPos((HWND) GetHWND(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
4322}
4323
47cbd6da
VZ
4324long wxWindow::MSWGetDlgCode()
4325{
2d0a075d
JS
4326 // default: just forward to def window proc (the msg has no parameters)
4327 return MSWDefWindowProc(WM_GETDLGCODE, 0, 0);
47cbd6da
VZ
4328}
4329
4330bool wxWindow::AcceptsFocus() const
4331{
2d0a075d 4332 return IsShown() && IsEnabled();
47cbd6da
VZ
4333}
4334
81d66cf3
JS
4335// Update region access
4336wxRegion wxWindow::GetUpdateRegion() const
4337{
4338 return m_updateRegion;
4339}
4340
4341bool wxWindow::IsExposed(int x, int y, int w, int h) const
4342{
4343 return (m_updateRegion.Contains(x, y, w, h) != wxOutRegion);
4344}
4345
4346bool wxWindow::IsExposed(const wxPoint& pt) const
4347{
4348 return (m_updateRegion.Contains(pt) != wxOutRegion);
4349}
4350
4351bool wxWindow::IsExposed(const wxRect& rect) const
4352{
4353 return (m_updateRegion.Contains(rect) != wxOutRegion);
4354}
4355
4fabb575
JS
4356// Set this window to be the child of 'parent'.
4357bool wxWindow::Reparent(wxWindow *parent)
4358{
4359 if (parent == GetParent())
4360 return TRUE;
4361
4362 // Unlink this window from the existing parent.
4363 if (GetParent())
4364 {
4365 GetParent()->RemoveChild(this);
4366 }
4367 else
4368 wxTopLevelWindows.DeleteObject(this);
4369
4370 HWND hWndParent = 0;
4371 HWND hWndChild = (HWND) GetHWND();
4372 if (parent != (wxWindow*) NULL)
4373 {
4374 parent->AddChild(this);
4375 hWndParent = (HWND) parent->GetHWND();
4376 }
4377 else
4378 wxTopLevelWindows.Append(this);
4379
4380 ::SetParent(hWndChild, hWndParent);
4381
4382 return TRUE;
4383}
4384
b2aef89b 4385#ifdef __WXDEBUG__
f449ef69 4386const char *wxGetMessageName(int message)
47cbd6da 4387{
2d0a075d 4388 switch ( message ) {
47cbd6da
VZ
4389 case 0x0000: return "WM_NULL";
4390 case 0x0001: return "WM_CREATE";
4391 case 0x0002: return "WM_DESTROY";
4392 case 0x0003: return "WM_MOVE";
4393 case 0x0005: return "WM_SIZE";
4394 case 0x0006: return "WM_ACTIVATE";
4395 case 0x0007: return "WM_SETFOCUS";
4396 case 0x0008: return "WM_KILLFOCUS";
4397 case 0x000A: return "WM_ENABLE";
4398 case 0x000B: return "WM_SETREDRAW";
4399 case 0x000C: return "WM_SETTEXT";
4400 case 0x000D: return "WM_GETTEXT";
4401 case 0x000E: return "WM_GETTEXTLENGTH";
4402 case 0x000F: return "WM_PAINT";
4403 case 0x0010: return "WM_CLOSE";
4404 case 0x0011: return "WM_QUERYENDSESSION";
4405 case 0x0012: return "WM_QUIT";
4406 case 0x0013: return "WM_QUERYOPEN";
4407 case 0x0014: return "WM_ERASEBKGND";
4408 case 0x0015: return "WM_SYSCOLORCHANGE";
4409 case 0x0016: return "WM_ENDSESSION";
4410 case 0x0017: return "WM_SYSTEMERROR";
4411 case 0x0018: return "WM_SHOWWINDOW";
4412 case 0x0019: return "WM_CTLCOLOR";
4413 case 0x001A: return "WM_WININICHANGE";
4414 case 0x001B: return "WM_DEVMODECHANGE";
4415 case 0x001C: return "WM_ACTIVATEAPP";
4416 case 0x001D: return "WM_FONTCHANGE";
4417 case 0x001E: return "WM_TIMECHANGE";
4418 case 0x001F: return "WM_CANCELMODE";
4419 case 0x0020: return "WM_SETCURSOR";
4420 case 0x0021: return "WM_MOUSEACTIVATE";
4421 case 0x0022: return "WM_CHILDACTIVATE";
4422 case 0x0023: return "WM_QUEUESYNC";
4423 case 0x0024: return "WM_GETMINMAXINFO";
4424 case 0x0026: return "WM_PAINTICON";
4425 case 0x0027: return "WM_ICONERASEBKGND";
4426 case 0x0028: return "WM_NEXTDLGCTL";
4427 case 0x002A: return "WM_SPOOLERSTATUS";
4428 case 0x002B: return "WM_DRAWITEM";
4429 case 0x002C: return "WM_MEASUREITEM";
4430 case 0x002D: return "WM_DELETEITEM";
4431 case 0x002E: return "WM_VKEYTOITEM";
4432 case 0x002F: return "WM_CHARTOITEM";
4433 case 0x0030: return "WM_SETFONT";
4434 case 0x0031: return "WM_GETFONT";
4435 case 0x0037: return "WM_QUERYDRAGICON";
4436 case 0x0039: return "WM_COMPAREITEM";
4437 case 0x0041: return "WM_COMPACTING";
4438 case 0x0044: return "WM_COMMNOTIFY";
4439 case 0x0046: return "WM_WINDOWPOSCHANGING";
4440 case 0x0047: return "WM_WINDOWPOSCHANGED";
4441 case 0x0048: return "WM_POWER";
c085e333 4442
a02eb1d2
VZ
4443#ifdef __WIN32__
4444 case 0x004A: return "WM_COPYDATA";
4445 case 0x004B: return "WM_CANCELJOURNAL";
4446 case 0x004E: return "WM_NOTIFY";
4447 case 0x0050: return "WM_INPUTLANGCHANGEREQUEST";
4448 case 0x0051: return "WM_INPUTLANGCHANGE";
4449 case 0x0052: return "WM_TCARD";
4450 case 0x0053: return "WM_HELP";
4451 case 0x0054: return "WM_USERCHANGED";
4452 case 0x0055: return "WM_NOTIFYFORMAT";
4453 case 0x007B: return "WM_CONTEXTMENU";
4454 case 0x007C: return "WM_STYLECHANGING";
4455 case 0x007D: return "WM_STYLECHANGED";
4456 case 0x007E: return "WM_DISPLAYCHANGE";
4457 case 0x007F: return "WM_GETICON";
4458 case 0x0080: return "WM_SETICON";
4459#endif //WIN32
c085e333 4460
47cbd6da
VZ
4461 case 0x0081: return "WM_NCCREATE";
4462 case 0x0082: return "WM_NCDESTROY";
4463 case 0x0083: return "WM_NCCALCSIZE";
4464 case 0x0084: return "WM_NCHITTEST";
4465 case 0x0085: return "WM_NCPAINT";
4466 case 0x0086: return "WM_NCACTIVATE";
4467 case 0x0087: return "WM_GETDLGCODE";
4468 case 0x00A0: return "WM_NCMOUSEMOVE";
4469 case 0x00A1: return "WM_NCLBUTTONDOWN";
4470 case 0x00A2: return "WM_NCLBUTTONUP";
4471 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
4472 case 0x00A4: return "WM_NCRBUTTONDOWN";
4473 case 0x00A5: return "WM_NCRBUTTONUP";
4474 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
4475 case 0x00A7: return "WM_NCMBUTTONDOWN";
4476 case 0x00A8: return "WM_NCMBUTTONUP";
4477 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
4478 case 0x0100: return "WM_KEYDOWN";
4479 case 0x0101: return "WM_KEYUP";
4480 case 0x0102: return "WM_CHAR";
4481 case 0x0103: return "WM_DEADCHAR";
4482 case 0x0104: return "WM_SYSKEYDOWN";
4483 case 0x0105: return "WM_SYSKEYUP";
4484 case 0x0106: return "WM_SYSCHAR";
4485 case 0x0107: return "WM_SYSDEADCHAR";
4486 case 0x0108: return "WM_KEYLAST";
c085e333 4487
a02eb1d2
VZ
4488#ifdef __WIN32__
4489 case 0x010D: return "WM_IME_STARTCOMPOSITION";
4490 case 0x010E: return "WM_IME_ENDCOMPOSITION";
4491 case 0x010F: return "WM_IME_COMPOSITION";
4492#endif //WIN32
c085e333 4493
47cbd6da
VZ
4494 case 0x0110: return "WM_INITDIALOG";
4495 case 0x0111: return "WM_COMMAND";
4496 case 0x0112: return "WM_SYSCOMMAND";
4497 case 0x0113: return "WM_TIMER";
4498 case 0x0114: return "WM_HSCROLL";
4499 case 0x0115: return "WM_VSCROLL";
4500 case 0x0116: return "WM_INITMENU";
4501 case 0x0117: return "WM_INITMENUPOPUP";
4502 case 0x011F: return "WM_MENUSELECT";
4503 case 0x0120: return "WM_MENUCHAR";
4504 case 0x0121: return "WM_ENTERIDLE";
4505 case 0x0200: return "WM_MOUSEMOVE";
4506 case 0x0201: return "WM_LBUTTONDOWN";
4507 case 0x0202: return "WM_LBUTTONUP";
4508 case 0x0203: return "WM_LBUTTONDBLCLK";
4509 case 0x0204: return "WM_RBUTTONDOWN";
4510 case 0x0205: return "WM_RBUTTONUP";
4511 case 0x0206: return "WM_RBUTTONDBLCLK";
4512 case 0x0207: return "WM_MBUTTONDOWN";
4513 case 0x0208: return "WM_MBUTTONUP";
4514 case 0x0209: return "WM_MBUTTONDBLCLK";
4515 case 0x0210: return "WM_PARENTNOTIFY";
a02eb1d2
VZ
4516 case 0x0211: return "WM_ENTERMENULOOP";
4517 case 0x0212: return "WM_EXITMENULOOP";
c085e333 4518
a02eb1d2
VZ
4519#ifdef __WIN32__
4520 case 0x0213: return "WM_NEXTMENU";
4521 case 0x0214: return "WM_SIZING";
4522 case 0x0215: return "WM_CAPTURECHANGED";
4523 case 0x0216: return "WM_MOVING";
4524 case 0x0218: return "WM_POWERBROADCAST";
4525 case 0x0219: return "WM_DEVICECHANGE";
4526#endif //WIN32
c085e333 4527
47cbd6da
VZ
4528 case 0x0220: return "WM_MDICREATE";
4529 case 0x0221: return "WM_MDIDESTROY";
4530 case 0x0222: return "WM_MDIACTIVATE";
4531 case 0x0223: return "WM_MDIRESTORE";
4532 case 0x0224: return "WM_MDINEXT";
4533 case 0x0225: return "WM_MDIMAXIMIZE";
4534 case 0x0226: return "WM_MDITILE";
4535 case 0x0227: return "WM_MDICASCADE";
4536 case 0x0228: return "WM_MDIICONARRANGE";
4537 case 0x0229: return "WM_MDIGETACTIVE";
4538 case 0x0230: return "WM_MDISETMENU";
4539 case 0x0233: return "WM_DROPFILES";
c085e333 4540
a02eb1d2
VZ
4541#ifdef __WIN32__
4542 case 0x0281: return "WM_IME_SETCONTEXT";
4543 case 0x0282: return "WM_IME_NOTIFY";
4544 case 0x0283: return "WM_IME_CONTROL";
4545 case 0x0284: return "WM_IME_COMPOSITIONFULL";
4546 case 0x0285: return "WM_IME_SELECT";
4547 case 0x0286: return "WM_IME_CHAR";
4548 case 0x0290: return "WM_IME_KEYDOWN";
4549 case 0x0291: return "WM_IME_KEYUP";
4550#endif //WIN32
c085e333 4551
47cbd6da
VZ
4552 case 0x0300: return "WM_CUT";
4553 case 0x0301: return "WM_COPY";
4554 case 0x0302: return "WM_PASTE";
4555 case 0x0303: return "WM_CLEAR";
4556 case 0x0304: return "WM_UNDO";
4557 case 0x0305: return "WM_RENDERFORMAT";
4558 case 0x0306: return "WM_RENDERALLFORMATS";
4559 case 0x0307: return "WM_DESTROYCLIPBOARD";
4560 case 0x0308: return "WM_DRAWCLIPBOARD";
4561 case 0x0309: return "WM_PAINTCLIPBOARD";
4562 case 0x030A: return "WM_VSCROLLCLIPBOARD";
4563 case 0x030B: return "WM_SIZECLIPBOARD";
4564 case 0x030C: return "WM_ASKCBFORMATNAME";
4565 case 0x030D: return "WM_CHANGECBCHAIN";
4566 case 0x030E: return "WM_HSCROLLCLIPBOARD";
4567 case 0x030F: return "WM_QUERYNEWPALETTE";
4568 case 0x0310: return "WM_PALETTEISCHANGING";
4569 case 0x0311: return "WM_PALETTECHANGED";
c085e333 4570
a02eb1d2 4571#ifdef __WIN32__
2d0a075d
JS
4572 // common controls messages - although they're not strictly speaking
4573 // standard, it's nice to decode them nevertheless
a02eb1d2 4574
2d0a075d 4575 // listview
a02eb1d2
VZ
4576 case 0x1000 + 0: return "LVM_GETBKCOLOR";
4577 case 0x1000 + 1: return "LVM_SETBKCOLOR";
4578 case 0x1000 + 2: return "LVM_GETIMAGELIST";
4579 case 0x1000 + 3: return "LVM_SETIMAGELIST";
4580 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
4581 case 0x1000 + 5: return "LVM_GETITEMA";
4582 case 0x1000 + 75: return "LVM_GETITEMW";
4583 case 0x1000 + 6: return "LVM_SETITEMA";
4584 case 0x1000 + 76: return "LVM_SETITEMW";
4585 case 0x1000 + 7: return "LVM_INSERTITEMA";
4586 case 0x1000 + 77: return "LVM_INSERTITEMW";
4587 case 0x1000 + 8: return "LVM_DELETEITEM";
4588 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
4589 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
4590 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
4591 case 0x1000 + 12: return "LVM_GETNEXTITEM";
4592 case 0x1000 + 13: return "LVM_FINDITEMA";
4593 case 0x1000 + 83: return "LVM_FINDITEMW";
4594 case 0x1000 + 14: return "LVM_GETITEMRECT";
4595 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
4596 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
4597 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
4598 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
4599 case 0x1000 + 18: return "LVM_HITTEST";
4600 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
4601 case 0x1000 + 20: return "LVM_SCROLL";
4602 case 0x1000 + 21: return "LVM_REDRAWITEMS";
4603 case 0x1000 + 22: return "LVM_ARRANGE";
4604 case 0x1000 + 23: return "LVM_EDITLABELA";
4605 case 0x1000 + 118: return "LVM_EDITLABELW";
4606 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
4607 case 0x1000 + 25: return "LVM_GETCOLUMNA";
4608 case 0x1000 + 95: return "LVM_GETCOLUMNW";
4609 case 0x1000 + 26: return "LVM_SETCOLUMNA";
4610 case 0x1000 + 96: return "LVM_SETCOLUMNW";
4611 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
4612 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
4613 case 0x1000 + 28: return "LVM_DELETECOLUMN";
4614 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
4615 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
4616 case 0x1000 + 31: return "LVM_GETHEADER";
4617 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
4618 case 0x1000 + 34: return "LVM_GETVIEWRECT";
4619 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
4620 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
4621 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
4622 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
4623 case 0x1000 + 39: return "LVM_GETTOPINDEX";
4624 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
4625 case 0x1000 + 41: return "LVM_GETORIGIN";
4626 case 0x1000 + 42: return "LVM_UPDATE";
4627 case 0x1000 + 43: return "LVM_SETITEMSTATE";
4628 case 0x1000 + 44: return "LVM_GETITEMSTATE";
4629 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
4630 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
4631 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
4632 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
4633 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
4634 case 0x1000 + 48: return "LVM_SORTITEMS";
4635 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
4636 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
4637 case 0x1000 + 51: return "LVM_GETITEMSPACING";
4638 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
4639 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
4640 case 0x1000 + 53: return "LVM_SETICONSPACING";
4641 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
4642 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
4643 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
4644 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
4645 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
4646 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
4647 case 0x1000 + 60: return "LVM_SETHOTITEM";
4648 case 0x1000 + 61: return "LVM_GETHOTITEM";
4649 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
4650 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
4651 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
4652 case 0x1000 + 65: return "LVM_SETWORKAREA";
c085e333 4653
2d0a075d 4654 // tree view
a02eb1d2
VZ
4655 case 0x1100 + 0: return "TVM_INSERTITEMA";
4656 case 0x1100 + 50: return "TVM_INSERTITEMW";
4657 case 0x1100 + 1: return "TVM_DELETEITEM";
4658 case 0x1100 + 2: return "TVM_EXPAND";
4659 case 0x1100 + 4: return "TVM_GETITEMRECT";
4660 case 0x1100 + 5: return "TVM_GETCOUNT";
4661 case 0x1100 + 6: return "TVM_GETINDENT";
4662 case 0x1100 + 7: return "TVM_SETINDENT";
4663 case 0x1100 + 8: return "TVM_GETIMAGELIST";
4664 case 0x1100 + 9: return "TVM_SETIMAGELIST";
4665 case 0x1100 + 10: return "TVM_GETNEXTITEM";
4666 case 0x1100 + 11: return "TVM_SELECTITEM";
4667 case 0x1100 + 12: return "TVM_GETITEMA";
4668 case 0x1100 + 62: return "TVM_GETITEMW";
4669 case 0x1100 + 13: return "TVM_SETITEMA";
4670 case 0x1100 + 63: return "TVM_SETITEMW";
4671 case 0x1100 + 14: return "TVM_EDITLABELA";
4672 case 0x1100 + 65: return "TVM_EDITLABELW";
4673 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
4674 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
4675 case 0x1100 + 17: return "TVM_HITTEST";
4676 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
4677 case 0x1100 + 19: return "TVM_SORTCHILDREN";
4678 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
4679 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
4680 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
4681 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
4682 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
4683 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
4684 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
c085e333 4685
2d0a075d 4686 // header
a02eb1d2
VZ
4687 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
4688 case 0x1200 + 1: return "HDM_INSERTITEMA";
4689 case 0x1200 + 10: return "HDM_INSERTITEMW";
4690 case 0x1200 + 2: return "HDM_DELETEITEM";
4691 case 0x1200 + 3: return "HDM_GETITEMA";
4692 case 0x1200 + 11: return "HDM_GETITEMW";
4693 case 0x1200 + 4: return "HDM_SETITEMA";
4694 case 0x1200 + 12: return "HDM_SETITEMW";
4695 case 0x1200 + 5: return "HDM_LAYOUT";
4696 case 0x1200 + 6: return "HDM_HITTEST";
4697 case 0x1200 + 7: return "HDM_GETITEMRECT";
4698 case 0x1200 + 8: return "HDM_SETIMAGELIST";
4699 case 0x1200 + 9: return "HDM_GETIMAGELIST";
4700 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
4701 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
4702 case 0x1200 + 17: return "HDM_GETORDERARRAY";
4703 case 0x1200 + 18: return "HDM_SETORDERARRAY";
4704 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
c085e333 4705
2d0a075d 4706 // tab control
a02eb1d2
VZ
4707 case 0x1300 + 2: return "TCM_GETIMAGELIST";
4708 case 0x1300 + 3: return "TCM_SETIMAGELIST";
4709 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
4710 case 0x1300 + 5: return "TCM_GETITEMA";
4711 case 0x1300 + 60: return "TCM_GETITEMW";
4712 case 0x1300 + 6: return "TCM_SETITEMA";
4713 case 0x1300 + 61: return "TCM_SETITEMW";
4714 case 0x1300 + 7: return "TCM_INSERTITEMA";
4715 case 0x1300 + 62: return "TCM_INSERTITEMW";
4716 case 0x1300 + 8: return "TCM_DELETEITEM";
4717 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
4718 case 0x1300 + 10: return "TCM_GETITEMRECT";
4719 case 0x1300 + 11: return "TCM_GETCURSEL";
4720 case 0x1300 + 12: return "TCM_SETCURSEL";
4721 case 0x1300 + 13: return "TCM_HITTEST";
4722 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
4723 case 0x1300 + 40: return "TCM_ADJUSTRECT";
4724 case 0x1300 + 41: return "TCM_SETITEMSIZE";
4725 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
4726 case 0x1300 + 43: return "TCM_SETPADDING";
4727 case 0x1300 + 44: return "TCM_GETROWCOUNT";
4728 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
4729 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
4730 case 0x1300 + 47: return "TCM_GETCURFOCUS";
4731 case 0x1300 + 48: return "TCM_SETCURFOCUS";
4732 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
4733 case 0x1300 + 50: return "TCM_DESELECTALL";
c085e333 4734
2d0a075d 4735 // toolbar
a02eb1d2
VZ
4736 case WM_USER+1: return "TB_ENABLEBUTTON";
4737 case WM_USER+2: return "TB_CHECKBUTTON";
4738 case WM_USER+3: return "TB_PRESSBUTTON";
4739 case WM_USER+4: return "TB_HIDEBUTTON";
4740 case WM_USER+5: return "TB_INDETERMINATE";
4741 case WM_USER+9: return "TB_ISBUTTONENABLED";
4742 case WM_USER+10: return "TB_ISBUTTONCHECKED";
4743 case WM_USER+11: return "TB_ISBUTTONPRESSED";
4744 case WM_USER+12: return "TB_ISBUTTONHIDDEN";
4745 case WM_USER+13: return "TB_ISBUTTONINDETERMINATE";
4746 case WM_USER+17: return "TB_SETSTATE";
4747 case WM_USER+18: return "TB_GETSTATE";
4748 case WM_USER+19: return "TB_ADDBITMAP";
4749 case WM_USER+20: return "TB_ADDBUTTONS";
4750 case WM_USER+21: return "TB_INSERTBUTTON";
4751 case WM_USER+22: return "TB_DELETEBUTTON";
4752 case WM_USER+23: return "TB_GETBUTTON";
4753 case WM_USER+24: return "TB_BUTTONCOUNT";
4754 case WM_USER+25: return "TB_COMMANDTOINDEX";
4755 case WM_USER+26: return "TB_SAVERESTOREA";
4756 case WM_USER+76: return "TB_SAVERESTOREW";
4757 case WM_USER+27: return "TB_CUSTOMIZE";
4758 case WM_USER+28: return "TB_ADDSTRINGA";
4759 case WM_USER+77: return "TB_ADDSTRINGW";
4760 case WM_USER+29: return "TB_GETITEMRECT";
4761 case WM_USER+30: return "TB_BUTTONSTRUCTSIZE";
4762 case WM_USER+31: return "TB_SETBUTTONSIZE";
4763 case WM_USER+32: return "TB_SETBITMAPSIZE";
4764 case WM_USER+33: return "TB_AUTOSIZE";
4765 case WM_USER+35: return "TB_GETTOOLTIPS";
4766 case WM_USER+36: return "TB_SETTOOLTIPS";
4767 case WM_USER+37: return "TB_SETPARENT";
4768 case WM_USER+39: return "TB_SETROWS";
4769 case WM_USER+40: return "TB_GETROWS";
4770 case WM_USER+42: return "TB_SETCMDID";
4771 case WM_USER+43: return "TB_CHANGEBITMAP";
4772 case WM_USER+44: return "TB_GETBITMAP";
4773 case WM_USER+45: return "TB_GETBUTTONTEXTA";
4774 case WM_USER+75: return "TB_GETBUTTONTEXTW";
4775 case WM_USER+46: return "TB_REPLACEBITMAP";
4776 case WM_USER+47: return "TB_SETINDENT";
4777 case WM_USER+48: return "TB_SETIMAGELIST";
4778 case WM_USER+49: return "TB_GETIMAGELIST";
4779 case WM_USER+50: return "TB_LOADIMAGES";
4780 case WM_USER+51: return "TB_GETRECT";
4781 case WM_USER+52: return "TB_SETHOTIMAGELIST";
4782 case WM_USER+53: return "TB_GETHOTIMAGELIST";
4783 case WM_USER+54: return "TB_SETDISABLEDIMAGELIST";
4784 case WM_USER+55: return "TB_GETDISABLEDIMAGELIST";
4785 case WM_USER+56: return "TB_SETSTYLE";
4786 case WM_USER+57: return "TB_GETSTYLE";
4787 case WM_USER+58: return "TB_GETBUTTONSIZE";
4788 case WM_USER+59: return "TB_SETBUTTONWIDTH";
4789 case WM_USER+60: return "TB_SETMAXTEXTROWS";
4790 case WM_USER+61: return "TB_GETTEXTROWS";
4791 case WM_USER+41: return "TB_GETBITMAPFLAGS";
c085e333 4792
a02eb1d2 4793#endif //WIN32
c085e333 4794
47cbd6da 4795 default:
2d0a075d
JS
4796 static char s_szBuf[128];
4797 sprintf(s_szBuf, "<unknown message = %d>", message);
4798 return s_szBuf;
47cbd6da
VZ
4799 }
4800}
ea57084d 4801#endif //__WXDEBUG__