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