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