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