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