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