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