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