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