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