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