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