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