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