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