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