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