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