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