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