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