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