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