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