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