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