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