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