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