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