]> git.saurik.com Git - wxWidgets.git/blob - src/msw/window.cpp
Added dcbase.cpp
[wxWidgets.git] / src / msw / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindow
4 // Author: Julian Smart
5 // Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "window.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/setup.h"
33 #include "wx/menu.h"
34 #include "wx/dc.h"
35 #include "wx/dcclient.h"
36 #include "wx/utils.h"
37 #include "wx/app.h"
38 #include "wx/panel.h"
39 #include "wx/layout.h"
40 #include "wx/dialog.h"
41 #include "wx/frame.h"
42 #include "wx/listbox.h"
43 #include "wx/button.h"
44 #include "wx/msgdlg.h"
45
46 #include <stdio.h>
47 #endif
48
49 #if wxUSE_OWNER_DRAWN
50 #include "wx/ownerdrw.h"
51 #endif
52
53 #if wxUSE_DRAG_AND_DROP
54 #include "wx/msw/ole/droptgt.h"
55 #endif
56
57 #include "wx/menuitem.h"
58 #include "wx/log.h"
59
60 #if wxUSE_TOOLTIPS
61 #include "wx/tooltip.h"
62 #endif
63
64 #if wxUSE_CARET
65 #include "wx/caret.h"
66 #endif // wxUSE_CARET
67
68 #include "wx/intl.h"
69 #include "wx/log.h"
70
71 #include "wx/msw/private.h"
72
73 #include "wx/textctrl.h"
74
75 #include <string.h>
76
77 #ifndef __GNUWIN32__
78 #include <shellapi.h>
79 #include <mmsystem.h>
80 #endif
81
82 #ifdef __WIN32__
83 #include <windowsx.h>
84 #endif
85
86 #if ( defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__ )
87 #include <commctrl.h>
88 #endif
89
90 #ifndef __TWIN32__
91 #ifdef __GNUWIN32__
92 #include <wx/msw/gnuwin32/extra.h>
93 #endif
94 #endif
95
96 #include "wx/msw/winundef.h"
97
98 // ---------------------------------------------------------------------------
99 // macros
100 // ---------------------------------------------------------------------------
101
102 // standard macros missing from some compilers headers
103 #ifndef GET_X_LPARAM
104 #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
105 #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
106 #endif // GET_X_LPARAM
107
108 // ---------------------------------------------------------------------------
109 // global variables
110 // ---------------------------------------------------------------------------
111
112 // the last Windows message we got (MT-UNSAFE)
113 extern MSG s_currentMsg;
114
115 wxMenu *wxCurrentPopupMenu = NULL;
116 extern wxList WXDLLEXPORT wxPendingDelete;
117 extern char wxCanvasClassName[];
118
119 // ---------------------------------------------------------------------------
120 // private functions
121 // ---------------------------------------------------------------------------
122
123 // the window proc for all our windows
124 LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
125 WPARAM wParam, LPARAM lParam);
126
127 #ifdef __WXDEBUG__
128 const char *wxGetMessageName(int message);
129 #endif //__WXDEBUG__
130
131 void wxRemoveHandleAssociation(wxWindow *win);
132 void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win);
133 wxWindow *wxFindWinFromHandle(WXHWND hWnd);
134
135 // ---------------------------------------------------------------------------
136 // event tables
137 // ---------------------------------------------------------------------------
138
139 #if !USE_SHARED_LIBRARY
140 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
141 #endif
142
143 BEGIN_EVENT_TABLE(wxWindow, wxWindowBase)
144 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
145 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
146 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
147 EVT_IDLE(wxWindow::OnIdle)
148 END_EVENT_TABLE()
149
150 // ===========================================================================
151 // implementation
152 // ===========================================================================
153
154 // ---------------------------------------------------------------------------
155 // wxWindow utility functions
156 // ---------------------------------------------------------------------------
157
158 // Find an item given the MS Windows id
159 wxWindow *wxWindow::FindItem(int id) const
160 {
161 wxWindowList::Node *current = GetChildren().GetFirst();
162 while (current)
163 {
164 wxWindow *childWin = current->GetData();
165
166 wxWindow *wnd = childWin->FindItem(id);
167 if ( wnd )
168 return wnd;
169
170 if ( childWin->IsKindOf(CLASSINFO(wxControl)) )
171 {
172 wxControl *item = (wxControl *)childWin;
173 if ( item->GetId() == id )
174 return item;
175 else
176 {
177 // In case it's a 'virtual' control (e.g. radiobox)
178 if ( item->GetSubcontrols().Member((wxObject *)id) )
179 return item;
180 }
181 }
182
183 current = current->GetNext();
184 }
185
186 return NULL;
187 }
188
189 // Find an item given the MS Windows handle
190 wxWindow *wxWindow::FindItemByHWND(WXHWND hWnd, bool controlOnly) const
191 {
192 wxWindowList::Node *current = GetChildren().GetFirst();
193 while (current)
194 {
195 wxWindow *parent = current->GetData();
196
197 // Do a recursive search.
198 wxWindow *wnd = parent->FindItemByHWND(hWnd);
199 if ( wnd )
200 return wnd;
201
202 if ( !controlOnly || parent->IsKindOf(CLASSINFO(wxControl)) )
203 {
204 wxWindow *item = current->GetData();
205 if ( item->GetHWND() == hWnd )
206 return item;
207 else
208 {
209 if ( item->ContainsHWND(hWnd) )
210 return item;
211 }
212 }
213
214 current = current->GetNext();
215 }
216 return NULL;
217 }
218
219 // Default command handler
220 bool wxWindow::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
221 {
222 return FALSE;
223 }
224
225 // ----------------------------------------------------------------------------
226 // constructors and such
227 // ----------------------------------------------------------------------------
228
229 void wxWindow::Init()
230 {
231 // generic
232 InitBase();
233
234 // MSW specific
235 m_doubleClickAllowed = 0;
236 m_winCaptured = FALSE;
237
238 m_isBeingDeleted = FALSE;
239 m_oldWndProc = 0;
240 m_useCtl3D = FALSE;
241 m_mouseInWindow = FALSE;
242
243 // wxWnd
244 m_hMenu = 0;
245
246 m_xThumbSize = 0;
247 m_yThumbSize = 0;
248 m_backgroundTransparent = FALSE;
249
250 // as all windows are created with WS_VISIBLE style...
251 m_isShown = TRUE;
252
253 #if wxUSE_MOUSEEVENT_HACK
254 m_lastMouseX =
255 m_lastMouseY = -1;
256 m_lastMouseEvent = -1;
257 #endif // wxUSE_MOUSEEVENT_HACK
258 }
259
260 // Destructor
261 wxWindow::~wxWindow()
262 {
263 m_isBeingDeleted = TRUE;
264
265 MSWDetachWindowMenu();
266
267 if ( m_parent )
268 m_parent->RemoveChild(this);
269
270 DestroyChildren();
271
272 if ( m_hWnd )
273 {
274 if ( !::DestroyWindow(GetHwnd()) )
275 wxLogLastError("DestroyWindow");
276 }
277
278 // Restore old Window proc, if required and remove hWnd <-> wxWindow
279 // association
280 UnsubclassWin();
281 }
282
283 // real construction (Init() must have been called before!)
284 bool wxWindow::Create(wxWindow *parent, wxWindowID id,
285 const wxPoint& pos,
286 const wxSize& size,
287 long style,
288 const wxString& name)
289 {
290 wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" );
291
292 CreateBase(parent, id, pos, size, style, name);
293
294 parent->AddChild(this);
295
296 DWORD msflags = 0;
297 if ( style & wxBORDER )
298 msflags |= WS_BORDER;
299 if ( style & wxTHICK_FRAME )
300 msflags |= WS_THICKFRAME;
301
302 msflags |= WS_CHILD | WS_VISIBLE;
303 if ( style & wxCLIP_CHILDREN )
304 msflags |= WS_CLIPCHILDREN;
305
306 bool want3D;
307 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
308
309 // Even with extended styles, need to combine with WS_BORDER
310 // for them to look right.
311 if ( want3D || (m_windowStyle & wxSIMPLE_BORDER) || (m_windowStyle & wxRAISED_BORDER ) ||
312 (m_windowStyle & wxSUNKEN_BORDER) || (m_windowStyle & wxDOUBLE_BORDER))
313 {
314 msflags |= WS_BORDER;
315 }
316
317 MSWCreate(m_windowId, parent, wxCanvasClassName, this, NULL,
318 pos.x, pos.y,
319 WidthDefault(size.x), HeightDefault(size.y),
320 msflags, NULL, exStyle);
321
322 return TRUE;
323 }
324
325 // ---------------------------------------------------------------------------
326 // basic operations
327 // ---------------------------------------------------------------------------
328
329 void wxWindow::SetFocus()
330 {
331 HWND hWnd = GetHwnd();
332 if ( hWnd )
333 ::SetFocus(hWnd);
334 }
335
336 // Get the window with the focus
337 wxWindow *wxWindowBase::FindFocus()
338 {
339 HWND hWnd = ::GetFocus();
340 if ( hWnd )
341 {
342 return wxFindWinFromHandle((WXHWND) hWnd);
343 }
344
345 return NULL;
346 }
347
348 bool wxWindow::Enable(bool enable)
349 {
350 if ( !wxWindowBase::Enable(enable) )
351 return FALSE;
352
353 HWND hWnd = GetHwnd();
354 if ( hWnd )
355 ::EnableWindow(hWnd, (BOOL)enable);
356
357 return TRUE;
358 }
359
360 bool wxWindow::Show(bool show)
361 {
362 if ( !wxWindowBase::Show(show) )
363 return FALSE;
364
365 HWND hWnd = GetHwnd();
366 int cshow = show ? SW_SHOW : SW_HIDE;
367 ::ShowWindow(hWnd, cshow);
368
369 if ( show )
370 {
371 BringWindowToTop(hWnd);
372 }
373
374 return TRUE;
375 }
376
377 // Raise the window to the top of the Z order
378 void wxWindow::Raise()
379 {
380 ::BringWindowToTop(GetHwnd());
381 }
382
383 // Lower the window to the bottom of the Z order
384 void wxWindow::Lower()
385 {
386 ::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0,
387 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
388 }
389
390 void wxWindow::SetTitle( const wxString& title)
391 {
392 SetWindowText(GetHwnd(), title.c_str());
393 }
394
395 wxString wxWindow::GetTitle() const
396 {
397 return wxGetWindowText(GetHWND());
398 }
399
400 void wxWindow::CaptureMouse()
401 {
402 HWND hWnd = GetHwnd();
403 if ( hWnd && !m_winCaptured )
404 {
405 SetCapture(hWnd);
406 m_winCaptured = TRUE;
407 }
408 }
409
410 void wxWindow::ReleaseMouse()
411 {
412 if ( m_winCaptured )
413 {
414 ReleaseCapture();
415 m_winCaptured = FALSE;
416 }
417 }
418
419 bool wxWindow::SetFont(const wxFont& font)
420 {
421 if ( !wxWindowBase::SetFont(font) )
422 {
423 // nothing to do
424 return FALSE;
425 }
426
427 HWND hWnd = GetHwnd();
428 if ( hWnd != 0 )
429 {
430 WXHANDLE hFont = m_font.GetResourceHandle();
431
432 wxASSERT_MSG( hFont, _T("should have valid font") );
433
434 ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, TRUE);
435 }
436
437 return TRUE;
438 }
439 bool wxWindow::SetCursor(const wxCursor& cursor)
440 {
441 if ( !wxWindowBase::SetCursor(cursor) )
442 {
443 // no change
444 return FALSE;
445 }
446
447 wxASSERT_MSG( m_cursor.Ok(),
448 _T("cursor must be valid after call to the base version"));
449
450 HWND hWnd = GetHwnd();
451
452 // Change the cursor NOW if we're within the correct window
453 POINT point;
454 ::GetCursorPos(&point);
455
456 RECT rect;
457 ::GetWindowRect(hWnd, &rect);
458
459 if ( ::PtInRect(&rect, point) && !wxIsBusy() )
460 ::SetCursor((HCURSOR)m_cursor.GetHCURSOR());
461
462 return TRUE;
463 }
464
465 void wxWindow::WarpPointer (int x_pos, int y_pos)
466 {
467 // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in
468 // pixel coordinates, relatives to the canvas -- So, we first need to
469 // substract origin of the window, then convert to screen position
470
471 int x = x_pos; int y = y_pos;
472 RECT rect;
473 GetWindowRect (GetHwnd(), &rect);
474
475 x += rect.left;
476 y += rect.top;
477
478 SetCursorPos (x, y);
479 }
480
481 #if WXWIN_COMPATIBILITY
482 void wxWindow::MSWDeviceToLogical (float *x, float *y) const
483 {
484 }
485 #endif // WXWIN_COMPATIBILITY
486
487 // ---------------------------------------------------------------------------
488 // scrolling stuff
489 // ---------------------------------------------------------------------------
490
491 #if WXWIN_COMPATIBILITY
492 void wxWindow::SetScrollRange(int orient, int range, bool refresh)
493 {
494 #if defined(__WIN95__)
495
496 int range1 = range;
497
498 // Try to adjust the range to cope with page size > 1
499 // - a Windows API quirk
500 int pageSize = GetScrollPage(orient);
501 if ( pageSize > 1 && range > 0)
502 {
503 range1 += (pageSize - 1);
504 }
505
506 SCROLLINFO info;
507 int dir;
508
509 if ( orient == wxHORIZONTAL ) {
510 dir = SB_HORZ;
511 } else {
512 dir = SB_VERT;
513 }
514
515 info.cbSize = sizeof(SCROLLINFO);
516 info.nPage = pageSize; // Have to set this, or scrollbar goes awry
517 info.nMin = 0;
518 info.nMax = range1;
519 info.nPos = 0;
520 info.fMask = SIF_RANGE | SIF_PAGE;
521
522 HWND hWnd = GetHwnd();
523 if ( hWnd )
524 ::SetScrollInfo(hWnd, dir, &info, refresh);
525 #else
526 int wOrient;
527 if ( orient == wxHORIZONTAL )
528 wOrient = SB_HORZ;
529 else
530 wOrient = SB_VERT;
531
532 HWND hWnd = GetHwnd();
533 if ( hWnd )
534 ::SetScrollRange(hWnd, wOrient, 0, range, refresh);
535 #endif
536 }
537
538 void wxWindow::SetScrollPage(int orient, int page, bool refresh)
539 {
540 #if defined(__WIN95__)
541 SCROLLINFO info;
542 int dir;
543
544 if ( orient == wxHORIZONTAL ) {
545 dir = SB_HORZ;
546 m_xThumbSize = page;
547 } else {
548 dir = SB_VERT;
549 m_yThumbSize = page;
550 }
551
552 info.cbSize = sizeof(SCROLLINFO);
553 info.nPage = page;
554 info.nMin = 0;
555 info.fMask = SIF_PAGE;
556
557 HWND hWnd = GetHwnd();
558 if ( hWnd )
559 ::SetScrollInfo(hWnd, dir, &info, refresh);
560 #else
561 if ( orient == wxHORIZONTAL )
562 m_xThumbSize = page;
563 else
564 m_yThumbSize = page;
565 #endif
566 }
567
568 int wxWindow::OldGetScrollRange(int orient) const
569 {
570 int wOrient;
571 if ( orient == wxHORIZONTAL )
572 wOrient = SB_HORZ;
573 else
574 wOrient = SB_VERT;
575
576 #if __WATCOMC__ && defined(__WINDOWS_386__)
577 short minPos, maxPos;
578 #else
579 int minPos, maxPos;
580 #endif
581 HWND hWnd = GetHwnd();
582 if ( hWnd )
583 {
584 ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos);
585 #if defined(__WIN95__)
586 // Try to adjust the range to cope with page size > 1
587 // - a Windows API quirk
588 int pageSize = GetScrollPage(orient);
589 if ( pageSize > 1 )
590 {
591 maxPos -= (pageSize - 1);
592 }
593 #endif
594 return maxPos;
595 }
596 else
597 return 0;
598 }
599
600 int wxWindow::GetScrollPage(int orient) const
601 {
602 if ( orient == wxHORIZONTAL )
603 return m_xThumbSize;
604 else
605 return m_yThumbSize;
606 }
607
608 #endif // WXWIN_COMPATIBILITY
609
610 int wxWindow::GetScrollPos(int orient) const
611 {
612 int wOrient;
613 if ( orient == wxHORIZONTAL )
614 wOrient = SB_HORZ;
615 else
616 wOrient = SB_VERT;
617 HWND hWnd = GetHwnd();
618 if ( hWnd )
619 {
620 return ::GetScrollPos(hWnd, wOrient);
621 }
622 else
623 return 0;
624 }
625
626 // This now returns the whole range, not just the number
627 // of positions that we can scroll.
628 int wxWindow::GetScrollRange(int orient) const
629 {
630 int wOrient;
631 if ( orient == wxHORIZONTAL )
632 wOrient = SB_HORZ;
633 else
634 wOrient = SB_VERT;
635
636 #if __WATCOMC__ && defined(__WINDOWS_386__)
637 short minPos, maxPos;
638 #else
639 int minPos, maxPos;
640 #endif
641 HWND hWnd = GetHwnd();
642 if ( hWnd )
643 {
644 ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos);
645 #if defined(__WIN95__)
646 // Try to adjust the range to cope with page size > 1
647 // - a Windows API quirk
648 int pageSize = GetScrollThumb(orient);
649 if ( pageSize > 1 )
650 {
651 maxPos -= (pageSize - 1);
652 }
653 // October 10th: new range concept.
654 maxPos += pageSize;
655 #endif
656
657 return maxPos;
658 }
659 else
660 return 0;
661 }
662
663 int wxWindow::GetScrollThumb(int orient) const
664 {
665 if ( orient == wxHORIZONTAL )
666 return m_xThumbSize;
667 else
668 return m_yThumbSize;
669 }
670
671 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
672 {
673 #if defined(__WIN95__)
674 SCROLLINFO info;
675 int dir;
676
677 if ( orient == wxHORIZONTAL ) {
678 dir = SB_HORZ;
679 } else {
680 dir = SB_VERT;
681 }
682
683 info.cbSize = sizeof(SCROLLINFO);
684 info.nPage = 0;
685 info.nMin = 0;
686 info.nPos = pos;
687 info.fMask = SIF_POS;
688
689 HWND hWnd = GetHwnd();
690 if ( hWnd )
691 ::SetScrollInfo(hWnd, dir, &info, refresh);
692 #else
693 int wOrient;
694 if ( orient == wxHORIZONTAL )
695 wOrient = SB_HORZ;
696 else
697 wOrient = SB_VERT;
698
699 HWND hWnd = GetHwnd();
700 if ( hWnd )
701 ::SetScrollPos(hWnd, wOrient, pos, refresh);
702 #endif
703 }
704
705 // New function that will replace some of the above.
706 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
707 int range, bool refresh)
708 {
709 #if defined(__WIN95__)
710 int oldRange = range - thumbVisible;
711
712 int range1 = oldRange;
713
714 // Try to adjust the range to cope with page size > 1
715 // - a Windows API quirk
716 int pageSize = thumbVisible;
717 if ( pageSize > 1 && range > 0)
718 {
719 range1 += (pageSize - 1);
720 }
721
722 SCROLLINFO info;
723 int dir;
724
725 if ( orient == wxHORIZONTAL ) {
726 dir = SB_HORZ;
727 } else {
728 dir = SB_VERT;
729 }
730
731 info.cbSize = sizeof(SCROLLINFO);
732 info.nPage = pageSize; // Have to set this, or scrollbar goes awry
733 info.nMin = 0;
734 info.nMax = range1;
735 info.nPos = pos;
736 info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
737
738 HWND hWnd = GetHwnd();
739 if ( hWnd )
740 ::SetScrollInfo(hWnd, dir, &info, refresh);
741 #else
742 int wOrient;
743 if ( orient == wxHORIZONTAL )
744 wOrient = SB_HORZ;
745 else
746 wOrient = SB_VERT;
747
748 HWND hWnd = GetHwnd();
749 if ( hWnd )
750 {
751 ::SetScrollRange(hWnd, wOrient, 0, range, FALSE);
752 ::SetScrollPos(hWnd, wOrient, pos, refresh);
753 }
754 #endif
755 if ( orient == wxHORIZONTAL ) {
756 m_xThumbSize = thumbVisible;
757 } else {
758 m_yThumbSize = thumbVisible;
759 }
760 }
761
762 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
763 {
764 RECT rect2;
765 if ( rect )
766 {
767 rect2.left = rect->x;
768 rect2.top = rect->y;
769 rect2.right = rect->x + rect->width;
770 rect2.bottom = rect->y + rect->height;
771 }
772
773 if ( rect )
774 ::ScrollWindow(GetHwnd(), dx, dy, &rect2, NULL);
775 else
776 ::ScrollWindow(GetHwnd(), dx, dy, NULL, NULL);
777 }
778
779 // ---------------------------------------------------------------------------
780 // subclassing
781 // ---------------------------------------------------------------------------
782
783 void wxWindow::SubclassWin(WXHWND hWnd)
784 {
785 wxASSERT_MSG( !m_oldWndProc, "subclassing window twice?" );
786
787 wxAssociateWinWithHandle((HWND)hWnd, this);
788
789 m_oldWndProc = (WXFARPROC) GetWindowLong((HWND) hWnd, GWL_WNDPROC);
790 SetWindowLong((HWND) hWnd, GWL_WNDPROC, (LONG) wxWndProc);
791 }
792
793 void wxWindow::UnsubclassWin()
794 {
795 wxRemoveHandleAssociation(this);
796
797 // Restore old Window proc
798 if ( GetHwnd() )
799 {
800 FARPROC farProc = (FARPROC) GetWindowLong(GetHwnd(), GWL_WNDPROC);
801 if ( (m_oldWndProc != 0) && (farProc != (FARPROC) m_oldWndProc) )
802 {
803 SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG) m_oldWndProc);
804 m_oldWndProc = 0;
805 }
806
807 m_hWnd = 0;
808 }
809 }
810
811 // Make a Windows extended style from the given wxWindows window style
812 WXDWORD wxWindow::MakeExtendedStyle(long style, bool eliminateBorders)
813 {
814 WXDWORD exStyle = 0;
815 if ( style & wxTRANSPARENT_WINDOW )
816 exStyle |= WS_EX_TRANSPARENT;
817
818 if ( !eliminateBorders )
819 {
820 if ( style & wxSUNKEN_BORDER )
821 exStyle |= WS_EX_CLIENTEDGE;
822 if ( style & wxDOUBLE_BORDER )
823 exStyle |= WS_EX_DLGMODALFRAME;
824 #if defined(__WIN95__)
825 if ( style & wxRAISED_BORDER )
826 exStyle |= WS_EX_WINDOWEDGE;
827 if ( style & wxSTATIC_BORDER )
828 exStyle |= WS_EX_STATICEDGE;
829 #endif
830 }
831 return exStyle;
832 }
833
834 // Determines whether native 3D effects or CTL3D should be used,
835 // applying a default border style if required, and returning an extended
836 // style to pass to CreateWindowEx.
837 WXDWORD wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D)
838 {
839 // If matches certain criteria, then assume no 3D effects
840 // unless specifically requested (dealt with in MakeExtendedStyle)
841 if ( !GetParent() || !IsKindOf(CLASSINFO(wxControl)) || (m_windowStyle & wxNO_BORDER) )
842 {
843 *want3D = FALSE;
844 return MakeExtendedStyle(m_windowStyle, FALSE);
845 }
846
847 // Determine whether we should be using 3D effects or not.
848 bool nativeBorder = FALSE; // by default, we don't want a Win95 effect
849
850 // 1) App can specify global 3D effects
851 *want3D = wxTheApp->GetAuto3D();
852
853 // 2) If the parent is being drawn with user colours, or simple border specified,
854 // switch effects off. TODO: replace wxUSER_COLOURS with wxNO_3D
855 if ( GetParent() && (GetParent()->GetWindowStyleFlag() & wxUSER_COLOURS) || (m_windowStyle & wxSIMPLE_BORDER) )
856 *want3D = FALSE;
857
858 // 3) Control can override this global setting by defining
859 // a border style, e.g. wxSUNKEN_BORDER
860 if ( m_windowStyle & wxSUNKEN_BORDER )
861 *want3D = TRUE;
862
863 // 4) If it's a special border, CTL3D can't cope so we want a native border
864 if ( (m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER) ||
865 (m_windowStyle & wxSTATIC_BORDER) )
866 {
867 *want3D = TRUE;
868 nativeBorder = TRUE;
869 }
870
871 // 5) If this isn't a Win95 app, and we are using CTL3D, remove border
872 // effects from extended style
873 #if wxUSE_CTL3D
874 if ( *want3D )
875 nativeBorder = FALSE;
876 #endif
877
878 DWORD exStyle = MakeExtendedStyle(m_windowStyle, !nativeBorder);
879
880 // If we want 3D, but haven't specified a border here,
881 // apply the default border style specified.
882 // TODO what about non-Win95 WIN32? Does it have borders?
883 #if defined(__WIN95__) && !wxUSE_CTL3D
884 if ( defaultBorderStyle && (*want3D) && ! ((m_windowStyle & wxDOUBLE_BORDER) || (m_windowStyle & wxRAISED_BORDER ) ||
885 (m_windowStyle & wxSTATIC_BORDER) || (m_windowStyle & wxSIMPLE_BORDER) ))
886 exStyle |= defaultBorderStyle; // WS_EX_CLIENTEDGE;
887 #endif
888
889 return exStyle;
890 }
891
892 #if WXWIN_COMPATIBILITY_2
893 // If nothing defined for this, try the parent.
894 // E.g. we may be a button loaded from a resource, with no callback function
895 // defined.
896 void wxWindow::OnCommand(wxWindow& win, wxCommandEvent& event)
897 {
898 if ( GetEventHandler()->ProcessEvent(event) )
899 return;
900 if ( m_parent )
901 m_parent->GetEventHandler()->OnCommand(win, event);
902 }
903 #endif // WXWIN_COMPATIBILITY_2
904
905 #if WXWIN_COMPATIBILITY
906 wxObject* wxWindow::GetChild(int number) const
907 {
908 // Return a pointer to the Nth object in the Panel
909 wxNode *node = GetChildren().First();
910 int n = number;
911 while (node && n--)
912 node = node->Next();
913 if ( node )
914 {
915 wxObject *obj = (wxObject *)node->Data();
916 return(obj);
917 }
918 else
919 return NULL;
920 }
921 #endif // WXWIN_COMPATIBILITY
922
923 // Setup background and foreground colours correctly
924 void wxWindow::SetupColours()
925 {
926 if ( GetParent() )
927 SetBackgroundColour(GetParent()->GetBackgroundColour());
928 }
929
930 void wxWindow::OnIdle(wxIdleEvent& event)
931 {
932 // Check if we need to send a LEAVE event
933 if ( m_mouseInWindow )
934 {
935 POINT pt;
936 ::GetCursorPos(&pt);
937 if ( ::WindowFromPoint(pt) != GetHwnd() )
938 {
939 // Generate a LEAVE event
940 m_mouseInWindow = FALSE;
941
942 // Unfortunately the mouse button and keyboard state may have changed
943 // by the time the OnIdle function is called, so 'state' may be
944 // meaningless.
945 int state = 0;
946 if ( ::GetKeyState(VK_SHIFT) != 0 )
947 state |= MK_SHIFT;
948 if ( ::GetKeyState(VK_CONTROL) != 0 )
949 state |= MK_CONTROL;
950
951 wxMouseEvent event(wxEVT_LEAVE_WINDOW);
952 InitMouseEvent(event, pt.x, pt.y, state);
953
954 (void)GetEventHandler()->ProcessEvent(event);
955 }
956 }
957
958 UpdateWindowUI();
959 }
960
961 // Set this window to be the child of 'parent'.
962 bool wxWindow::Reparent(wxWindow *parent)
963 {
964 if ( !wxWindowBase::Reparent(parent) )
965 return FALSE;
966
967 HWND hWndChild = GetHwnd();
968 HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
969
970 ::SetParent(hWndChild, hWndParent);
971
972 return TRUE;
973 }
974
975 void wxWindow::Clear()
976 {
977 wxClientDC dc(this);
978 wxBrush brush(GetBackgroundColour(), wxSOLID);
979 dc.SetBackground(brush);
980 dc.Clear();
981 }
982
983 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
984 {
985 HWND hWnd = GetHwnd();
986 if ( hWnd )
987 {
988 if ( rect )
989 {
990 RECT mswRect;
991 mswRect.left = rect->x;
992 mswRect.top = rect->y;
993 mswRect.right = rect->x + rect->width;
994 mswRect.bottom = rect->y + rect->height;
995
996 ::InvalidateRect(hWnd, &mswRect, eraseBack);
997 }
998 else
999 ::InvalidateRect(hWnd, NULL, eraseBack);
1000 }
1001 }
1002
1003 // ---------------------------------------------------------------------------
1004 // drag and drop
1005 // ---------------------------------------------------------------------------
1006
1007 #if wxUSE_DRAG_AND_DROP
1008
1009 void wxWindow::SetDropTarget(wxDropTarget *pDropTarget)
1010 {
1011 if ( m_dropTarget != 0 ) {
1012 m_dropTarget->Revoke(m_hWnd);
1013 delete m_dropTarget;
1014 }
1015
1016 m_dropTarget = pDropTarget;
1017 if ( m_dropTarget != 0 )
1018 m_dropTarget->Register(m_hWnd);
1019 }
1020
1021 #endif // wxUSE_DRAG_AND_DROP
1022
1023 // old style file-manager drag&drop support: we retain the old-style
1024 // DragAcceptFiles in parallel with SetDropTarget.
1025 void wxWindow::DragAcceptFiles(bool accept)
1026 {
1027 HWND hWnd = GetHwnd();
1028 if ( hWnd )
1029 ::DragAcceptFiles(hWnd, (BOOL)accept);
1030 }
1031
1032 // ----------------------------------------------------------------------------
1033 // tooltips
1034 // ----------------------------------------------------------------------------
1035
1036 #if wxUSE_TOOLTIPS
1037
1038 void wxWindow::DoSetToolTip(wxToolTip *tooltip)
1039 {
1040 wxWindowBase::DoSetToolTip(tooltip);
1041
1042 if ( m_tooltip )
1043 m_tooltip->SetWindow(this);
1044 }
1045
1046 #endif // wxUSE_TOOLTIPS
1047
1048 // ---------------------------------------------------------------------------
1049 // moving and resizing
1050 // ---------------------------------------------------------------------------
1051
1052 // Get total size
1053 void wxWindow::DoGetSize(int *x, int *y) const
1054 {
1055 HWND hWnd = GetHwnd();
1056 RECT rect;
1057 GetWindowRect(hWnd, &rect);
1058
1059 if ( x )
1060 *x = rect.right - rect.left;
1061 if ( y )
1062 *y = rect.bottom - rect.top;
1063 }
1064
1065 void wxWindow::DoGetPosition(int *x, int *y) const
1066 {
1067 HWND hWnd = GetHwnd();
1068 HWND hParentWnd = 0;
1069 if ( GetParent() )
1070 hParentWnd = (HWND) GetParent()->GetHWND();
1071
1072 RECT rect;
1073 GetWindowRect(hWnd, &rect);
1074
1075 // Since we now have the absolute screen coords, if there's a parent we
1076 // must subtract its top left corner
1077 POINT point;
1078 point.x = rect.left;
1079 point.y = rect.top;
1080 if ( hParentWnd )
1081 {
1082 ::ScreenToClient(hParentWnd, &point);
1083 }
1084
1085 // We may be faking the client origin. So a window that's really at (0,
1086 // 30) may appear (to wxWin apps) to be at (0, 0).
1087 if ( GetParent() )
1088 {
1089 wxPoint pt(GetParent()->GetClientAreaOrigin());
1090 point.x -= pt.x;
1091 point.y -= pt.y;
1092 }
1093
1094 if ( x )
1095 *x = point.x;
1096 if ( y )
1097 *y = point.y;
1098 }
1099
1100 void wxWindow::DoScreenToClient(int *x, int *y) const
1101 {
1102 POINT pt;
1103 if ( x )
1104 pt.x = *x;
1105 if ( y )
1106 pt.y = *y;
1107
1108 HWND hWnd = GetHwnd();
1109 ::ScreenToClient(hWnd, &pt);
1110
1111 if ( x )
1112 *x = pt.x;
1113 if ( y )
1114 *y = pt.y;
1115 }
1116
1117 void wxWindow::DoClientToScreen(int *x, int *y) const
1118 {
1119 POINT pt;
1120 if ( x )
1121 pt.x = *x;
1122 if ( y )
1123 pt.y = *y;
1124
1125 HWND hWnd = GetHwnd();
1126 ::ClientToScreen(hWnd, &pt);
1127
1128 if ( x )
1129 *x = pt.x;
1130 if ( y )
1131 *y = pt.y;
1132 }
1133
1134 // Get size *available for subwindows* i.e. excluding menu bar etc.
1135 void wxWindow::DoGetClientSize(int *x, int *y) const
1136 {
1137 HWND hWnd = GetHwnd();
1138 RECT rect;
1139 ::GetClientRect(hWnd, &rect);
1140 if ( x )
1141 *x = rect.right;
1142 if ( y )
1143 *y = rect.bottom;
1144 }
1145
1146 void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
1147 {
1148 int currentX, currentY;
1149 GetPosition(&currentX, &currentY);
1150 int currentW,currentH;
1151 GetSize(&currentW, &currentH);
1152
1153 if ( x == currentX && y == currentY && width == currentW && height == currentH )
1154 return;
1155
1156 int actualWidth = width;
1157 int actualHeight = height;
1158 int actualX = x;
1159 int actualY = y;
1160 if ( x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1161 actualX = currentX;
1162 if ( y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
1163 actualY = currentY;
1164
1165 AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
1166
1167 if ( width == -1 )
1168 actualWidth = currentW;
1169 if ( height == -1 )
1170 actualHeight = currentH;
1171
1172 HWND hWnd = GetHwnd();
1173 if ( hWnd )
1174 MoveWindow(hWnd, actualX, actualY, actualWidth, actualHeight, (BOOL)TRUE);
1175 }
1176
1177 void wxWindow::DoSetClientSize(int width, int height)
1178 {
1179 wxWindow *parent = GetParent();
1180 HWND hWnd = GetHwnd();
1181 HWND hParentWnd = (HWND) 0;
1182 if ( parent )
1183 hParentWnd = (HWND) parent->GetHWND();
1184
1185 RECT rect;
1186 ::GetClientRect(hWnd, &rect);
1187
1188 RECT rect2;
1189 GetWindowRect(hWnd, &rect2);
1190
1191 // Find the difference between the entire window (title bar and all)
1192 // and the client area; add this to the new client size to move the
1193 // window
1194 int actual_width = rect2.right - rect2.left - rect.right + width;
1195 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
1196
1197 // If there's a parent, must subtract the parent's top left corner
1198 // since MoveWindow moves relative to the parent
1199
1200 POINT point;
1201 point.x = rect2.left;
1202 point.y = rect2.top;
1203 if ( parent )
1204 {
1205 ::ScreenToClient(hParentWnd, &point);
1206 }
1207
1208 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
1209
1210 wxSizeEvent event(wxSize(width, height), m_windowId);
1211 event.SetEventObject(this);
1212 GetEventHandler()->ProcessEvent(event);
1213 }
1214
1215 // For implementation purposes - sometimes decorations make the client area
1216 // smaller
1217 wxPoint wxWindow::GetClientAreaOrigin() const
1218 {
1219 return wxPoint(0, 0);
1220 }
1221
1222 // Makes an adjustment to the window position (for example, a frame that has
1223 // a toolbar that it manages itself).
1224 void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
1225 {
1226 if ( ((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent() )
1227 {
1228 wxPoint pt(GetParent()->GetClientAreaOrigin());
1229 x += pt.x; y += pt.y;
1230 }
1231 }
1232
1233 // ---------------------------------------------------------------------------
1234 // text metrics
1235 // ---------------------------------------------------------------------------
1236
1237 int wxWindow::GetCharHeight() const
1238 {
1239 TEXTMETRIC lpTextMetric;
1240 HWND hWnd = GetHwnd();
1241 HDC dc = ::GetDC(hWnd);
1242
1243 GetTextMetrics(dc, &lpTextMetric);
1244 ::ReleaseDC(hWnd, dc);
1245
1246 return lpTextMetric.tmHeight;
1247 }
1248
1249 int wxWindow::GetCharWidth() const
1250 {
1251 TEXTMETRIC lpTextMetric;
1252 HWND hWnd = GetHwnd();
1253 HDC dc = ::GetDC(hWnd);
1254
1255 GetTextMetrics(dc, &lpTextMetric);
1256 ::ReleaseDC(hWnd, dc);
1257
1258 return lpTextMetric.tmAveCharWidth;
1259 }
1260
1261 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
1262 int *descent, int *externalLeading,
1263 const wxFont *theFont) const
1264 {
1265 const wxFont *fontToUse = theFont;
1266 if ( !fontToUse )
1267 fontToUse = &m_font;
1268
1269 HWND hWnd = GetHwnd();
1270 HDC dc = ::GetDC(hWnd);
1271
1272 HFONT fnt = 0;
1273 HFONT hfontOld = 0;
1274 if ( fontToUse && fontToUse->Ok() )
1275 {
1276 fnt = (HFONT)((wxFont *)fontToUse)->GetResourceHandle(); // const_cast
1277 if ( fnt )
1278 hfontOld = (HFONT)SelectObject(dc,fnt);
1279 }
1280
1281 SIZE sizeRect;
1282 TEXTMETRIC tm;
1283 GetTextExtentPoint(dc, (const char *)string, (int)string.Length(), &sizeRect);
1284 GetTextMetrics(dc, &tm);
1285
1286 if ( fontToUse && fnt && hfontOld )
1287 SelectObject(dc, hfontOld);
1288
1289 ReleaseDC(hWnd, dc);
1290
1291 if ( x ) *x = sizeRect.cx;
1292 if ( y ) *y = sizeRect.cy;
1293 if ( descent ) *descent = tm.tmDescent;
1294 if ( externalLeading ) *externalLeading = tm.tmExternalLeading;
1295 }
1296
1297 #if wxUSE_CARET
1298 // ---------------------------------------------------------------------------
1299 // Caret manipulation
1300 // ---------------------------------------------------------------------------
1301
1302 void wxWindow::CreateCaret(int w, int h)
1303 {
1304 SetCaret(new wxCaret(this, w, h));
1305 }
1306
1307 void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
1308 {
1309 wxFAIL_MSG("not implemented");
1310 }
1311
1312 void wxWindow::ShowCaret(bool show)
1313 {
1314 wxCHECK_RET( m_caret, "no caret to show" );
1315
1316 m_caret->Show(show);
1317 }
1318
1319 void wxWindow::DestroyCaret()
1320 {
1321 SetCaret(NULL);
1322 }
1323
1324 void wxWindow::SetCaretPos(int x, int y)
1325 {
1326 wxCHECK_RET( m_caret, "no caret to move" );
1327
1328 m_caret->Move(x, y);
1329 }
1330
1331 void wxWindow::GetCaretPos(int *x, int *y) const
1332 {
1333 wxCHECK_RET( m_caret, "no caret to get position of" );
1334
1335 m_caret->GetPosition(x, y);
1336 }
1337 #endif // wxUSE_CARET
1338
1339 // ===========================================================================
1340 // pre/post message processing
1341 // ===========================================================================
1342
1343 long wxWindow::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
1344 {
1345 if ( m_oldWndProc )
1346 return ::CallWindowProc(CASTWNDPROC m_oldWndProc, GetHwnd(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam);
1347 else
1348 return ::DefWindowProc(GetHwnd(), nMsg, wParam, lParam);
1349 }
1350
1351 bool wxWindow::MSWProcessMessage(WXMSG* pMsg)
1352 {
1353 if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) )
1354 {
1355 // intercept dialog navigation keys
1356 MSG *msg = (MSG *)pMsg;
1357 bool bProcess = TRUE;
1358 if ( msg->message != WM_KEYDOWN )
1359 bProcess = FALSE;
1360
1361 if ( bProcess && (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN )
1362 bProcess = FALSE;
1363
1364 if ( bProcess )
1365 {
1366 bool bCtrlDown = (::GetKeyState(VK_CONTROL) & 0x100) != 0;
1367
1368 // WM_GETDLGCODE: ask the control if it wants the key for itself,
1369 // don't process it if it's the case (except for Ctrl-Tab/Enter
1370 // combinations which are always processed)
1371 LONG lDlgCode = 0;
1372 if ( !bCtrlDown )
1373 {
1374 lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0);
1375 }
1376
1377 bool bForward = TRUE,
1378 bWindowChange = FALSE;
1379
1380 switch ( msg->wParam )
1381 {
1382 case VK_TAB:
1383 if ( lDlgCode & DLGC_WANTTAB ) {
1384 bProcess = FALSE;
1385 }
1386 else {
1387 // Ctrl-Tab cycles thru notebook pages
1388 bWindowChange = bCtrlDown;
1389 bForward = !(::GetKeyState(VK_SHIFT) & 0x100);
1390 }
1391 break;
1392
1393 case VK_UP:
1394 case VK_LEFT:
1395 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
1396 bProcess = FALSE;
1397 else
1398 bForward = FALSE;
1399 break;
1400
1401 case VK_DOWN:
1402 case VK_RIGHT:
1403 if ( (lDlgCode & DLGC_WANTARROWS) || bCtrlDown )
1404 bProcess = FALSE;
1405 break;
1406
1407 case VK_RETURN:
1408 {
1409 if ( lDlgCode & DLGC_WANTMESSAGE )
1410 {
1411 // control wants to process Enter itself, don't
1412 // call IsDialogMessage() which would interpret
1413 // it
1414 return FALSE;
1415 }
1416 #ifndef __WIN16__
1417 wxButton *btnDefault = GetDefaultItem();
1418 if ( btnDefault && !bCtrlDown )
1419 {
1420 // if there is a default button, Enter should
1421 // press it
1422 (void)::SendMessage((HWND)btnDefault->GetHWND(),
1423 BM_CLICK, 0, 0);
1424 return TRUE;
1425 }
1426 // else: but if there is not it makes sense to make it
1427 // work like a TAB - and that's what we do.
1428 // Note that Ctrl-Enter always works this way.
1429 #endif
1430 }
1431 break;
1432
1433 default:
1434 bProcess = FALSE;
1435 }
1436
1437 if ( bProcess )
1438 {
1439 wxNavigationKeyEvent event;
1440 event.SetDirection(bForward);
1441 event.SetWindowChange(bWindowChange);
1442 event.SetEventObject(this);
1443
1444 if ( GetEventHandler()->ProcessEvent(event) )
1445 return TRUE;
1446 }
1447 }
1448
1449 if ( ::IsDialogMessage(GetHwnd(), msg) )
1450 return TRUE;
1451 }
1452
1453 #if wxUSE_TOOLTIPS
1454 if ( m_tooltip )
1455 {
1456 // relay mouse move events to the tooltip control
1457 MSG *msg = (MSG *)pMsg;
1458 if ( msg->message == WM_MOUSEMOVE )
1459 m_tooltip->RelayEvent(pMsg);
1460 }
1461 #endif // wxUSE_TOOLTIPS
1462
1463 return FALSE;
1464 }
1465
1466 bool wxWindow::MSWTranslateMessage(WXMSG* pMsg)
1467 {
1468 return m_acceleratorTable.Ok() &&
1469 ::TranslateAccelerator(GetHwnd(),
1470 GetTableHaccel(m_acceleratorTable),
1471 (MSG *)pMsg);
1472 }
1473
1474 // ---------------------------------------------------------------------------
1475 // message params unpackers (different for Win16 and Win32)
1476 // ---------------------------------------------------------------------------
1477
1478 #ifdef __WIN32__
1479
1480 void wxWindow::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
1481 WORD *id, WXHWND *hwnd, WORD *cmd)
1482 {
1483 *id = LOWORD(wParam);
1484 *hwnd = (WXHWND)lParam;
1485 *cmd = HIWORD(wParam);
1486 }
1487
1488 void wxWindow::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
1489 WXWORD *state, WXWORD *minimized, WXHWND *hwnd)
1490 {
1491 *state = LOWORD(wParam);
1492 *minimized = HIWORD(wParam);
1493 *hwnd = (WXHWND)lParam;
1494 }
1495
1496 void wxWindow::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
1497 WXWORD *code, WXWORD *pos, WXHWND *hwnd)
1498 {
1499 *code = LOWORD(wParam);
1500 *pos = HIWORD(wParam);
1501 *hwnd = (WXHWND)lParam;
1502 }
1503
1504 void wxWindow::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
1505 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd)
1506 {
1507 *nCtlColor = CTLCOLOR_BTN;
1508 *hwnd = (WXHWND)lParam;
1509 *hdc = (WXHDC)wParam;
1510 }
1511
1512 void wxWindow::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
1513 WXWORD *item, WXWORD *flags, WXHMENU *hmenu)
1514 {
1515 *item = (WXWORD)wParam;
1516 *flags = HIWORD(wParam);
1517 *hmenu = (WXHMENU)lParam;
1518 }
1519
1520 #else // Win16
1521
1522 void wxWindow::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
1523 WXWORD *id, WXHWND *hwnd, WXWORD *cmd)
1524 {
1525 *id = (WXWORD)wParam;
1526 *hwnd = (WXHWND)LOWORD(lParam);
1527 *cmd = HIWORD(lParam);
1528 }
1529
1530 void wxWindow::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
1531 WXWORD *state, WXWORD *minimized, WXHWND *hwnd)
1532 {
1533 *state = (WXWORD)wParam;
1534 *minimized = LOWORD(lParam);
1535 *hwnd = (WXHWND)HIWORD(lParam);
1536 }
1537
1538 void wxWindow::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
1539 WXWORD *code, WXWORD *pos, WXHWND *hwnd)
1540 {
1541 *code = (WXWORD)wParam;
1542 *pos = LOWORD(lParam);
1543 *hwnd = (WXHWND)HIWORD(lParam);
1544 }
1545
1546 void wxWindow::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
1547 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd)
1548 {
1549 *control = (WXHWND)LOWORD(lParam);
1550 *nCtlColor = (int)HIWORD(lParam);
1551 *hdc = (WXHDC)wParam;
1552 }
1553
1554 void wxWindow::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
1555 WXWORD *item, WXWORD *flags, WXHMENU *hmenu)
1556 {
1557 *item = (WXWORD)wParam;
1558 *flags = LOWORD(lParam);
1559 *hmenu = (WXHMENU)HIWORD(lParam);
1560 }
1561
1562 #endif // Win32/16
1563
1564 // ---------------------------------------------------------------------------
1565 // Main wxWindows window proc and the window proc for wxWindow
1566 // ---------------------------------------------------------------------------
1567
1568 // Hook for new window just as it's being created, when the window isn't yet
1569 // associated with the handle
1570 wxWindow *wxWndHook = NULL;
1571
1572 // Main window proc
1573 LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1574 {
1575 // trace all messages - useful for the debugging
1576 #ifdef __WXDEBUG__
1577 wxLogTrace(wxTraceMessages, "Processing %s(wParam=%8lx, lParam=%8lx)",
1578 wxGetMessageName(message), wParam, lParam);
1579 #endif // __WXDEBUG__
1580
1581 wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd);
1582
1583 // when we get the first message for the HWND we just created, we associate
1584 // it with wxWindow stored in wxWndHook
1585 if ( !wnd && wxWndHook )
1586 {
1587 wxAssociateWinWithHandle(hWnd, wxWndHook);
1588 wnd = wxWndHook;
1589 wxWndHook = NULL;
1590 wnd->SetHWND((WXHWND)hWnd);
1591 }
1592
1593 LRESULT rc;
1594
1595 // Stop right here if we don't have a valid handle in our wxWindow object.
1596 if ( wnd && !wnd->GetHWND() )
1597 {
1598 // FIXME: why do we do this?
1599 wnd->SetHWND((WXHWND) hWnd);
1600 rc = wnd->MSWDefWindowProc(message, wParam, lParam );
1601 wnd->SetHWND(0);
1602 }
1603 else
1604 {
1605 if ( wnd )
1606 rc = wnd->MSWWindowProc(message, wParam, lParam);
1607 else
1608 rc = DefWindowProc( hWnd, message, wParam, lParam );
1609 }
1610
1611 return rc;
1612 }
1613
1614 long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
1615 {
1616 // did we process the message?
1617 bool processed = FALSE;
1618
1619 // the return value
1620 union
1621 {
1622 bool allow;
1623 long result;
1624 WXHICON hIcon;
1625 WXHBRUSH hBrush;
1626 } rc;
1627
1628 // for most messages we should return 0 when we do process the message
1629 rc.result = 0;
1630
1631 switch ( message )
1632 {
1633 case WM_CREATE:
1634 {
1635 bool mayCreate;
1636 processed = HandleCreate((WXLPCREATESTRUCT)lParam, &mayCreate);
1637 if ( processed )
1638 {
1639 // return 0 to allow window creation
1640 rc.result = mayCreate ? 0 : -1;
1641 }
1642 }
1643 break;
1644
1645 case WM_DESTROY:
1646 processed = HandleDestroy();
1647 break;
1648
1649 case WM_MOVE:
1650 processed = HandleMove(LOWORD(lParam), HIWORD(lParam));
1651 break;
1652
1653 case WM_SIZE:
1654 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
1655 break;
1656
1657 case WM_ACTIVATE:
1658 {
1659 WXWORD state, minimized;
1660 WXHWND hwnd;
1661 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
1662
1663 processed = HandleActivate(state, minimized != 0, (WXHWND)hwnd);
1664 }
1665 break;
1666
1667 case WM_SETFOCUS:
1668 processed = HandleSetFocus((WXHWND)(HWND)wParam);
1669 break;
1670
1671 case WM_KILLFOCUS:
1672 processed = HandleKillFocus((WXHWND)(HWND)wParam);
1673 break;
1674
1675 case WM_PAINT:
1676 processed = HandlePaint();
1677 break;
1678
1679 case WM_CLOSE:
1680 // don't let the DefWindowProc() destroy our window - we'll do it
1681 // ourselves in ~wxWindow
1682 processed = TRUE;
1683 rc.result = TRUE;
1684 break;
1685
1686 case WM_SHOWWINDOW:
1687 processed = HandleShow(wParam != 0, (int)lParam);
1688 break;
1689
1690 case WM_MOUSEMOVE:
1691 case WM_LBUTTONDOWN:
1692 case WM_LBUTTONUP:
1693 case WM_LBUTTONDBLCLK:
1694 case WM_RBUTTONDOWN:
1695 case WM_RBUTTONUP:
1696 case WM_RBUTTONDBLCLK:
1697 case WM_MBUTTONDOWN:
1698 case WM_MBUTTONUP:
1699 case WM_MBUTTONDBLCLK:
1700 {
1701 int x = LOWORD(lParam);
1702 int y = HIWORD(lParam);
1703
1704 processed = HandleMouseEvent(message, x, y, wParam);
1705 }
1706 break;
1707
1708 case MM_JOY1MOVE:
1709 case MM_JOY2MOVE:
1710 case MM_JOY1ZMOVE:
1711 case MM_JOY2ZMOVE:
1712 case MM_JOY1BUTTONDOWN:
1713 case MM_JOY2BUTTONDOWN:
1714 case MM_JOY1BUTTONUP:
1715 case MM_JOY2BUTTONUP:
1716 {
1717 int x = LOWORD(lParam);
1718 int y = HIWORD(lParam);
1719
1720 processed = HandleJoystickEvent(message, x, y, wParam);
1721 }
1722 break;
1723
1724 case WM_SYSCOMMAND:
1725 processed = HandleSysCommand(wParam, lParam);
1726 break;
1727
1728 case WM_COMMAND:
1729 {
1730 WORD id, cmd;
1731 WXHWND hwnd;
1732 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
1733
1734 processed = HandleCommand(id, cmd, hwnd);
1735 }
1736 break;
1737
1738 #ifdef __WIN95__
1739 case WM_NOTIFY:
1740 processed = HandleNotify((int)wParam, lParam, &rc.result);
1741 break;
1742 #endif // Win95
1743
1744 // for these messages we must return TRUE if process the message
1745 case WM_DRAWITEM:
1746 case WM_MEASUREITEM:
1747 {
1748 int idCtrl = (UINT)wParam;
1749 if ( message == WM_DRAWITEM )
1750 {
1751 processed = MSWOnDrawItem(idCtrl,
1752 (WXDRAWITEMSTRUCT *)lParam);
1753 }
1754 else
1755 {
1756 processed = MSWOnMeasureItem(idCtrl,
1757 (WXMEASUREITEMSTRUCT *)lParam);
1758 }
1759
1760 if ( processed )
1761 rc.result = TRUE;
1762 }
1763 break;
1764
1765 case WM_KEYDOWN:
1766 // If this has been processed by an event handler,
1767 // return 0 now (we've handled it).
1768 if ( HandleKeyDown((WORD) wParam, lParam) )
1769 {
1770 processed = TRUE;
1771
1772 break;
1773 }
1774
1775 // we consider these message "not interesting" to OnChar
1776 if ( wParam == VK_SHIFT || wParam == VK_CONTROL )
1777 {
1778 processed = TRUE;
1779
1780 break;
1781 }
1782
1783 switch ( wParam )
1784 {
1785 // avoid duplicate messages to OnChar for these ASCII keys: they
1786 // will be translated by TranslateMessage() and received in WM_CHAR
1787 case VK_ESCAPE:
1788 case VK_SPACE:
1789 case VK_RETURN:
1790 case VK_BACK:
1791 case VK_TAB:
1792 processed = TRUE;
1793
1794 break;
1795
1796 #ifdef VK_APPS
1797 // special case of VK_APPS: treat it the same as right mouse
1798 // click because both usually pop up a context menu
1799 case VK_APPS:
1800 {
1801 // construct the key mask
1802 WPARAM fwKeys = MK_RBUTTON;
1803 if ( (::GetKeyState(VK_CONTROL) & 0x100) != 0 )
1804 fwKeys |= MK_CONTROL;
1805 if ( (::GetKeyState(VK_SHIFT) & 0x100) != 0 )
1806 fwKeys |= MK_SHIFT;
1807
1808 // simulate right mouse button click
1809 DWORD dwPos = ::GetMessagePos();
1810 int x = GET_X_LPARAM(dwPos),
1811 y = GET_Y_LPARAM(dwPos);
1812
1813 ScreenToClient(&x, &y);
1814 processed = HandleMouseEvent(WM_RBUTTONDOWN, x, y, fwKeys);
1815 }
1816 break;
1817 #endif // VK_APPS
1818
1819 case VK_LEFT:
1820 case VK_RIGHT:
1821 case VK_DOWN:
1822 case VK_UP:
1823 default:
1824 processed = HandleChar((WORD)wParam, lParam);
1825 }
1826 break;
1827
1828 case WM_KEYUP:
1829 processed = HandleKeyUp((WORD) wParam, lParam);
1830 break;
1831
1832 case WM_CHAR: // Always an ASCII character
1833 processed = HandleChar((WORD)wParam, lParam, TRUE);
1834 break;
1835
1836 case WM_HSCROLL:
1837 case WM_VSCROLL:
1838 {
1839 WXWORD code, pos;
1840 WXHWND hwnd;
1841 UnpackScroll(wParam, lParam, &code, &pos, &hwnd);
1842
1843 processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL
1844 : wxVERTICAL,
1845 code, pos, hwnd);
1846 }
1847 break;
1848
1849 // CTLCOLOR messages are sent by children to query the parent for their
1850 // colors
1851 #ifdef __WIN32__
1852 case WM_CTLCOLORMSGBOX:
1853 case WM_CTLCOLOREDIT:
1854 case WM_CTLCOLORLISTBOX:
1855 case WM_CTLCOLORBTN:
1856 case WM_CTLCOLORDLG:
1857 case WM_CTLCOLORSCROLLBAR:
1858 case WM_CTLCOLORSTATIC:
1859 #else // Win16
1860 case WM_CTLCOLOR:
1861 #endif // Win32/16
1862 {
1863 WXWORD nCtlColor;
1864 WXHDC hdc;
1865 WXHWND hwnd;
1866 UnpackCtlColor(wParam, lParam, &nCtlColor, &hdc, &hwnd);
1867
1868 processed = HandleCtlColor(&rc.hBrush,
1869 (WXHDC)hdc,
1870 (WXHWND)hwnd,
1871 nCtlColor,
1872 message,
1873 wParam,
1874 lParam);
1875 }
1876 break;
1877
1878 // the return value for this message is ignored
1879 case WM_SYSCOLORCHANGE:
1880 processed = HandleSysColorChange();
1881 break;
1882
1883 case WM_PALETTECHANGED:
1884 processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
1885 break;
1886
1887 case WM_QUERYNEWPALETTE:
1888 processed = HandleQueryNewPalette();
1889 break;
1890
1891 case WM_ERASEBKGND:
1892 processed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
1893 if ( processed )
1894 {
1895 // we processed the message, i.e. erased the background
1896 rc.result = TRUE;
1897 }
1898 break;
1899
1900 case WM_DROPFILES:
1901 processed = HandleDropFiles(wParam);
1902 break;
1903
1904 case WM_INITDIALOG:
1905 processed = HandleInitDialog((WXHWND)(HWND)wParam);
1906
1907 if ( processed )
1908 {
1909 // we never set focus from here
1910 rc.result = FALSE;
1911 }
1912 break;
1913
1914 case WM_QUERYENDSESSION:
1915 processed = HandleQueryEndSession(lParam, &rc.allow);
1916 break;
1917
1918 case WM_ENDSESSION:
1919 processed = HandleEndSession(wParam != 0, lParam);
1920 break;
1921
1922 case WM_GETMINMAXINFO:
1923 processed = HandleGetMinMaxInfo((LPMINMAXINFO)lParam);
1924 break;
1925
1926 case WM_SETCURSOR:
1927 processed = HandleSetCursor((WXHWND)(HWND)wParam,
1928 LOWORD(lParam), // hit test
1929 HIWORD(lParam)); // mouse msg
1930
1931 if ( processed )
1932 {
1933 // returning TRUE stops the DefWindowProc() from further
1934 // processing this message - exactly what we need because we've
1935 // just set the cursor.
1936 rc.result = TRUE;
1937 }
1938 break;
1939 }
1940
1941 if ( !processed )
1942 {
1943 #ifdef __WXDEBUG__
1944 wxLogTrace(wxTraceMessages, "Forwarding %s to DefWindowProc.",
1945 wxGetMessageName(message));
1946 #endif // __WXDEBUG__
1947 rc.result = MSWDefWindowProc(message, wParam, lParam);
1948 }
1949
1950 return rc.result;
1951 }
1952
1953 // Dialog window proc
1954 LONG APIENTRY _EXPORT
1955 wxDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1956 {
1957 if ( message == WM_INITDIALOG )
1958 {
1959 // for this message, returning TRUE tells system to set focus to the
1960 // first control in the dialog box
1961 return TRUE;
1962 }
1963 else
1964 {
1965 // for all the other ones, FALSE means that we didn't process the
1966 // message
1967 return 0;
1968 }
1969 }
1970
1971 wxList *wxWinHandleList = NULL;
1972 wxWindow *wxFindWinFromHandle(WXHWND hWnd)
1973 {
1974 wxNode *node = wxWinHandleList->Find((long)hWnd);
1975 if ( !node )
1976 return NULL;
1977 return (wxWindow *)node->Data();
1978 }
1979
1980 void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win)
1981 {
1982 // adding NULL hWnd is (first) surely a result of an error and
1983 // (secondly) breaks menu command processing
1984 wxCHECK_RET( hWnd != (HWND)NULL,
1985 "attempt to add a NULL hWnd to window list ignored" );
1986
1987 if ( !wxWinHandleList->Find((long)hWnd) )
1988 wxWinHandleList->Append((long)hWnd, win);
1989 }
1990
1991 void wxRemoveHandleAssociation(wxWindow *win)
1992 {
1993 wxWinHandleList->DeleteObject(win);
1994 }
1995
1996 // Default destroyer - override if you destroy it in some other way
1997 // (e.g. with MDI child windows)
1998 void wxWindow::MSWDestroyWindow()
1999 {
2000 }
2001
2002 void wxWindow::MSWDetachWindowMenu()
2003 {
2004 if ( m_hMenu )
2005 {
2006 HMENU hMenu = (HMENU)m_hMenu;
2007
2008 int N = ::GetMenuItemCount(hMenu);
2009 int i;
2010 for (i = 0; i < N; i++)
2011 {
2012 char buf[100];
2013 int chars = GetMenuString(hMenu, i, buf, 100, MF_BYPOSITION);
2014 if ( !chars )
2015 {
2016 wxLogLastError("GetMenuString");
2017
2018 continue;
2019 }
2020
2021 if ( strcmp(buf, "&Window") == 0 )
2022 {
2023 RemoveMenu(hMenu, i, MF_BYPOSITION);
2024
2025 break;
2026 }
2027 }
2028 }
2029 }
2030
2031 bool wxWindow::MSWCreate(int id,
2032 wxWindow *parent,
2033 const char *wclass,
2034 wxWindow *wx_win,
2035 const char *title,
2036 int x,
2037 int y,
2038 int width,
2039 int height,
2040 WXDWORD style,
2041 const char *dialog_template,
2042 WXDWORD extendedStyle)
2043 {
2044 int x1 = CW_USEDEFAULT;
2045 int y1 = 0;
2046 int width1 = CW_USEDEFAULT;
2047 int height1 = 100;
2048
2049 // Find parent's size, if it exists, to set up a possible default
2050 // panel size the size of the parent window
2051 RECT parent_rect;
2052 if ( parent )
2053 {
2054 ::GetClientRect((HWND) parent->GetHWND(), &parent_rect);
2055
2056 width1 = parent_rect.right - parent_rect.left;
2057 height1 = parent_rect.bottom - parent_rect.top;
2058 }
2059
2060 if ( x > -1 ) x1 = x;
2061 if ( y > -1 ) y1 = y;
2062 if ( width > -1 ) width1 = width;
2063 if ( height > -1 ) height1 = height;
2064
2065 HWND hParent = NULL;
2066 if ( parent )
2067 hParent = (HWND) parent->GetHWND();
2068
2069 wxWndHook = this;
2070
2071 if ( dialog_template )
2072 {
2073 m_hWnd = (WXHWND)::CreateDialog(wxGetInstance(),
2074 dialog_template,
2075 hParent,
2076 (DLGPROC)wxDlgProc);
2077
2078 if ( m_hWnd == 0 )
2079 {
2080 wxLogError(_("Can't find dummy dialog template!\n"
2081 "Check resource include path for finding wx.rc."));
2082
2083 return FALSE;
2084 }
2085
2086 // ::SetWindowLong(GWL_EXSTYLE) doesn't work for the dialogs, so try
2087 // to take care of (at least some) extended style flags ourselves
2088 if ( extendedStyle & WS_EX_TOPMOST )
2089 {
2090 if ( !::SetWindowPos(GetHwnd(), HWND_TOPMOST, 0, 0, 0, 0,
2091 SWP_NOSIZE | SWP_NOMOVE) )
2092 {
2093 wxLogLastError("SetWindowPos");
2094 }
2095 }
2096
2097 // move the dialog to its initial position without forcing repainting
2098 if ( !::MoveWindow(GetHwnd(), x1, y1, width1, height1, FALSE) )
2099 {
2100 wxLogLastError("MoveWindow");
2101 }
2102 }
2103 else
2104 {
2105 int controlId = 0;
2106 if ( style & WS_CHILD )
2107 controlId = id;
2108
2109 m_hWnd = (WXHWND)CreateWindowEx(extendedStyle,
2110 wclass,
2111 title ? title : "",
2112 style,
2113 x1, y1,
2114 width1, height1,
2115 hParent, (HMENU)controlId,
2116 wxGetInstance(),
2117 NULL);
2118
2119 if ( !m_hWnd )
2120 {
2121 wxLogError(_("Can't create window of class %s!\n"
2122 "Possible Windows 3.x compatibility problem?"),
2123 wclass);
2124
2125 return FALSE;
2126 }
2127 }
2128
2129 wxWndHook = NULL;
2130 wxWinHandleList->Append((long)m_hWnd, this);
2131
2132 return TRUE;
2133 }
2134
2135 // ===========================================================================
2136 // MSW message handlers
2137 // ===========================================================================
2138
2139 // ---------------------------------------------------------------------------
2140 // WM_NOTIFY
2141 // ---------------------------------------------------------------------------
2142
2143 #ifdef __WIN95__
2144 // FIXME: VZ: I'm not sure at all that the order of processing is correct
2145 bool wxWindow::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
2146 {
2147 LPNMHDR hdr = (LPNMHDR)lParam;
2148 HWND hWnd = hdr->hwndFrom;
2149 wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd);
2150
2151 // is this one of our windows?
2152 if ( win )
2153 {
2154 return win->MSWOnNotify(idCtrl, lParam, result);
2155 }
2156
2157 // try all our children
2158 wxWindowList::Node *node = GetChildren().GetFirst();
2159 while ( node )
2160 {
2161 wxWindow *child = node->GetData();
2162 if ( child->MSWOnNotify(idCtrl, lParam, result) )
2163 {
2164 return TRUE;
2165
2166 break;
2167 }
2168
2169 node = node->GetNext();
2170 }
2171
2172 // finally try this window too (catches toolbar case)
2173 return MSWOnNotify(idCtrl, lParam, result);
2174 }
2175
2176 bool wxWindow::MSWOnNotify(int WXUNUSED(idCtrl),
2177 WXLPARAM lParam,
2178 WXLPARAM* WXUNUSED(result))
2179 {
2180 #if wxUSE_TOOLTIPS
2181 NMHDR* hdr = (NMHDR *)lParam;
2182 if ( hdr->code == TTN_NEEDTEXT && m_tooltip )
2183 {
2184 TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
2185 ttt->lpszText = (char *)m_tooltip->GetTip().c_str();
2186
2187 // processed
2188 return TRUE;
2189 }
2190 #endif // wxUSE_TOOLTIPS
2191
2192 return FALSE;
2193 }
2194 #endif // __WIN95__
2195
2196 // ---------------------------------------------------------------------------
2197 // end session messages
2198 // ---------------------------------------------------------------------------
2199
2200 bool wxWindow::HandleQueryEndSession(long logOff, bool *mayEnd)
2201 {
2202 wxCloseEvent event(wxEVT_QUERY_END_SESSION, -1);
2203 event.SetEventObject(wxTheApp);
2204 event.SetCanVeto(TRUE);
2205 event.SetLoggingOff(logOff == ENDSESSION_LOGOFF);
2206
2207 bool rc = wxTheApp->ProcessEvent(event);
2208
2209 if ( rc )
2210 {
2211 // we may end only if the app didn't veto session closing (double
2212 // negation...)
2213 *mayEnd = !event.GetVeto();
2214 }
2215
2216 return rc;
2217 }
2218
2219 bool wxWindow::HandleEndSession(bool endSession, long logOff)
2220 {
2221 // do nothing if the session isn't ending
2222 if ( !endSession )
2223 return FALSE;
2224
2225 wxCloseEvent event(wxEVT_END_SESSION, -1);
2226 event.SetEventObject(wxTheApp);
2227 event.SetCanVeto(FALSE);
2228 event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) );
2229 if ( (this == wxTheApp->GetTopWindow()) && // Only send once
2230 wxTheApp->ProcessEvent(event))
2231 {
2232 }
2233 return TRUE;
2234 }
2235
2236 // ---------------------------------------------------------------------------
2237 // window creation/destruction
2238 // ---------------------------------------------------------------------------
2239
2240 bool wxWindow::HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate)
2241 {
2242 // TODO: should generate this event from WM_NCCREATE
2243 wxWindowCreateEvent event(this);
2244 (void)GetEventHandler()->ProcessEvent(event);
2245
2246 *mayCreate = TRUE;
2247
2248 return TRUE;
2249 }
2250
2251 bool wxWindow::HandleDestroy()
2252 {
2253 wxWindowDestroyEvent event(this);
2254 (void)GetEventHandler()->ProcessEvent(event);
2255
2256 // delete our drop target if we've got one
2257 #if wxUSE_DRAG_AND_DROP
2258 if ( m_dropTarget != NULL )
2259 {
2260 m_dropTarget->Revoke(m_hWnd);
2261
2262 delete m_dropTarget;
2263 m_dropTarget = NULL;
2264 }
2265 #endif // wxUSE_DRAG_AND_DROP
2266
2267 // WM_DESTROY handled
2268 return TRUE;
2269 }
2270
2271 // ---------------------------------------------------------------------------
2272 // activation/focus
2273 // ---------------------------------------------------------------------------
2274
2275 bool wxWindow::HandleActivate(int state,
2276 bool WXUNUSED(minimized),
2277 WXHWND WXUNUSED(activate))
2278 {
2279 wxActivateEvent event(wxEVT_ACTIVATE,
2280 (state == WA_ACTIVE) || (state == WA_CLICKACTIVE),
2281 m_windowId);
2282 event.SetEventObject(this);
2283
2284 return GetEventHandler()->ProcessEvent(event);
2285 }
2286
2287 bool wxWindow::HandleSetFocus(WXHWND WXUNUSED(hwnd))
2288 {
2289 #if wxUSE_CARET
2290 // Deal with caret
2291 if ( m_caret )
2292 {
2293 m_caret->OnSetFocus();
2294 }
2295 #endif // wxUSE_CARET
2296
2297 // panel wants to track the window which was the last to have focus in it
2298 wxWindow *parent = GetParent();
2299 if ( parent && parent->IsKindOf(CLASSINFO(wxPanel)) )
2300 {
2301 ((wxPanel *)parent)->SetLastFocus(GetId());
2302 }
2303
2304 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
2305 event.SetEventObject(this);
2306
2307 return GetEventHandler()->ProcessEvent(event);
2308 }
2309
2310 bool wxWindow::HandleKillFocus(WXHWND WXUNUSED(hwnd))
2311 {
2312 #if wxUSE_CARET
2313 // Deal with caret
2314 if ( m_caret )
2315 {
2316 m_caret->OnKillFocus();
2317 }
2318 #endif // wxUSE_CARET
2319
2320 wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId);
2321 event.SetEventObject(this);
2322
2323 return GetEventHandler()->ProcessEvent(event);
2324 }
2325
2326 // ---------------------------------------------------------------------------
2327 // miscellaneous
2328 // ---------------------------------------------------------------------------
2329
2330 bool wxWindow::HandleShow(bool show, int status)
2331 {
2332 wxShowEvent event(GetId(), show);
2333 event.m_eventObject = this;
2334
2335 return GetEventHandler()->ProcessEvent(event);
2336 }
2337
2338 bool wxWindow::HandleInitDialog(WXHWND WXUNUSED(hWndFocus))
2339 {
2340 wxInitDialogEvent event(GetId());
2341 event.m_eventObject = this;
2342
2343 return GetEventHandler()->ProcessEvent(event);
2344 }
2345
2346 bool wxWindow::HandleDropFiles(WXWPARAM wParam)
2347 {
2348 HDROP hFilesInfo = (HDROP) wParam;
2349 POINT dropPoint;
2350 DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
2351
2352 // Get the total number of files dropped
2353 WORD gwFilesDropped = (WORD)DragQueryFile ((HDROP)hFilesInfo,
2354 (UINT)-1,
2355 (LPSTR)0,
2356 (UINT)0);
2357
2358 wxString *files = new wxString[gwFilesDropped];
2359 int wIndex;
2360 for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++)
2361 {
2362 DragQueryFile (hFilesInfo, wIndex, (LPSTR) wxBuffer, 1000);
2363 files[wIndex] = wxBuffer;
2364 }
2365 DragFinish (hFilesInfo);
2366
2367 wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files);
2368 event.m_eventObject = this;
2369 event.m_pos.x = dropPoint.x; event.m_pos.x = dropPoint.y;
2370
2371 bool rc = GetEventHandler()->ProcessEvent(event);
2372
2373 delete[] files;
2374
2375 return rc;
2376 }
2377
2378 bool wxWindow::HandleSetCursor(WXHWND hWnd,
2379 short nHitTest,
2380 int WXUNUSED(mouseMsg))
2381 {
2382 // don't set cursor for other windows, only for this one: this prevents
2383 // children of this window from getting the same cursor as the parent has
2384 // (don't forget that this message is propagated by default up the window
2385 // parent-child hierarchy)
2386 if ( GetHWND() == hWnd )
2387 {
2388 // don't set cursor when the mouse is not in the client part
2389 if ( nHitTest == HTCLIENT || nHitTest == HTERROR )
2390 {
2391 HCURSOR hcursor = 0;
2392 if ( wxIsBusy() )
2393 {
2394 // from msw\utils.cpp
2395 extern HCURSOR gs_wxBusyCursor;
2396
2397 hcursor = gs_wxBusyCursor;
2398 }
2399 else
2400 {
2401 wxCursor *cursor = NULL;
2402
2403 if ( m_cursor.Ok() )
2404 {
2405 cursor = &m_cursor;
2406 }
2407 else
2408 {
2409 // from msw\data.cpp
2410 extern wxCursor *g_globalCursor;
2411
2412 if ( g_globalCursor && g_globalCursor->Ok() )
2413 cursor = g_globalCursor;
2414 }
2415
2416 if ( cursor )
2417 hcursor = (HCURSOR)cursor->GetHCURSOR();
2418 }
2419
2420 if ( hcursor )
2421 {
2422 ::SetCursor(hcursor);
2423
2424 return TRUE;
2425 }
2426 }
2427 }
2428
2429 return FALSE;
2430 }
2431
2432 #if wxUSE_OWNER_DRAWN
2433 // ---------------------------------------------------------------------------
2434 // owner drawn stuff
2435 // ---------------------------------------------------------------------------
2436
2437 bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
2438 {
2439 // is it a menu item?
2440 if ( id == 0 )
2441 {
2442 DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
2443 wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData);
2444
2445 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
2446
2447 // prepare to call OnDrawItem()
2448 wxDC dc;
2449 dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE);
2450 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
2451 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
2452 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
2453
2454 return pMenuItem->OnDrawItem
2455 (
2456 dc, rect,
2457 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
2458 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
2459 );
2460 }
2461
2462 wxWindow *item = FindItem(id);
2463 if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
2464 {
2465 return ((wxControl *)item)->MSWOnDraw(itemStruct);
2466 }
2467 else
2468 return FALSE;
2469 }
2470
2471 bool wxWindow::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
2472 {
2473 // is it a menu item?
2474 if ( id == 0 )
2475 {
2476 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
2477 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
2478
2479 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
2480
2481 return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth,
2482 &pMeasureStruct->itemHeight);
2483 }
2484
2485 wxWindow *item = FindItem(id);
2486 if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
2487 {
2488 return ((wxControl *)item)->MSWOnMeasure(itemStruct);
2489 }
2490
2491 return FALSE;
2492 }
2493 #endif // owner-drawn menus
2494
2495 // ---------------------------------------------------------------------------
2496 // colours and palettes
2497 // ---------------------------------------------------------------------------
2498
2499 bool wxWindow::HandleSysColorChange()
2500 {
2501 wxSysColourChangedEvent event;
2502 event.SetEventObject(this);
2503
2504 return GetEventHandler()->ProcessEvent(event);
2505 }
2506
2507 bool wxWindow::HandleCtlColor(WXHBRUSH *brush,
2508 WXHDC pDC,
2509 WXHWND pWnd,
2510 WXUINT nCtlColor,
2511 WXUINT message,
2512 WXWPARAM wParam,
2513 WXLPARAM lParam)
2514 {
2515 WXHBRUSH hBrush = 0;
2516
2517 if ( nCtlColor == CTLCOLOR_DLG )
2518 {
2519 hBrush = OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2520 }
2521 else
2522 {
2523 wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE);
2524 if ( item )
2525 hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2526 }
2527
2528 if ( hBrush )
2529 *brush = hBrush;
2530
2531 return hBrush != 0;
2532 }
2533
2534 // Define for each class of dialog and control
2535 WXHBRUSH wxWindow::OnCtlColor(WXHDC hDC,
2536 WXHWND hWnd,
2537 WXUINT nCtlColor,
2538 WXUINT message,
2539 WXWPARAM wParam,
2540 WXLPARAM lParam)
2541 {
2542 return (WXHBRUSH)0;
2543 }
2544
2545 bool wxWindow::HandlePaletteChanged(WXHWND hWndPalChange)
2546 {
2547 wxPaletteChangedEvent event(GetId());
2548 event.SetEventObject(this);
2549 event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
2550
2551 return GetEventHandler()->ProcessEvent(event);
2552 }
2553
2554 bool wxWindow::HandleQueryNewPalette()
2555 {
2556 wxQueryNewPaletteEvent event(GetId());
2557 event.SetEventObject(this);
2558
2559 return GetEventHandler()->ProcessEvent(event) && event.GetPaletteRealized();
2560 }
2561
2562 // Responds to colour changes: passes event on to children.
2563 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
2564 {
2565 wxNode *node = GetChildren().First();
2566 while ( node )
2567 {
2568 // Only propagate to non-top-level windows
2569 wxWindow *win = (wxWindow *)node->Data();
2570 if ( win->GetParent() )
2571 {
2572 wxSysColourChangedEvent event2;
2573 event.m_eventObject = win;
2574 win->GetEventHandler()->ProcessEvent(event2);
2575 }
2576
2577 node = node->Next();
2578 }
2579 }
2580
2581 // ---------------------------------------------------------------------------
2582 // painting
2583 // ---------------------------------------------------------------------------
2584
2585 bool wxWindow::HandlePaint()
2586 {
2587 #ifdef __WIN32__
2588 HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
2589 if ( !hRegion )
2590 wxLogLastError("CreateRectRgn");
2591 if ( ::GetUpdateRgn(GetHwnd(), hRegion, FALSE) == ERROR )
2592 wxLogLastError("GetUpdateRgn");
2593
2594 m_updateRegion = wxRegion((WXHRGN) hRegion);
2595 #else
2596 RECT updateRect;
2597 ::GetUpdateRect(GetHwnd(), & updateRect, FALSE);
2598
2599 m_updateRegion = wxRegion(updateRect.left, updateRect.top,
2600 updateRect.right - updateRect.left,
2601 updateRect.bottom - updateRect.top);
2602 #endif
2603
2604 wxPaintEvent event(m_windowId);
2605 event.SetEventObject(this);
2606
2607 return GetEventHandler()->ProcessEvent(event);
2608 }
2609
2610 bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
2611 {
2612 // Prevents flicker when dragging
2613 if ( ::IsIconic(GetHwnd()) )
2614 return TRUE;
2615
2616 wxDC dc;
2617
2618 dc.SetHDC(hdc);
2619 dc.SetWindow(this);
2620 dc.BeginDrawing();
2621
2622 wxEraseEvent event(m_windowId, &dc);
2623 event.SetEventObject(this);
2624 bool rc = GetEventHandler()->ProcessEvent(event);
2625
2626 dc.EndDrawing();
2627 dc.SelectOldObjects(hdc);
2628 dc.SetHDC((WXHDC) NULL);
2629
2630 return rc;
2631 }
2632
2633 void wxWindow::OnEraseBackground(wxEraseEvent& event)
2634 {
2635 RECT rect;
2636 ::GetClientRect(GetHwnd(), &rect);
2637
2638 COLORREF ref = PALETTERGB(m_backgroundColour.Red(),
2639 m_backgroundColour.Green(),
2640 m_backgroundColour.Blue());
2641 HBRUSH hBrush = ::CreateSolidBrush(ref);
2642 if ( !hBrush )
2643 wxLogLastError("CreateSolidBrush");
2644
2645 HDC hdc = (HDC)event.GetDC()->GetHDC();
2646
2647 int mode = ::SetMapMode(hdc, MM_TEXT);
2648
2649 ::FillRect(hdc, &rect, hBrush);
2650 ::DeleteObject(hBrush);
2651 ::SetMapMode(hdc, mode);
2652 }
2653
2654 // ---------------------------------------------------------------------------
2655 // moving and resizing
2656 // ---------------------------------------------------------------------------
2657
2658 bool wxWindow::HandleMinimize()
2659 {
2660 wxIconizeEvent event(m_windowId);
2661 event.SetEventObject(this);
2662
2663 return GetEventHandler()->ProcessEvent(event);
2664 }
2665
2666 bool wxWindow::HandleMaximize()
2667 {
2668 wxMaximizeEvent event(m_windowId);
2669 event.SetEventObject(this);
2670
2671 return GetEventHandler()->ProcessEvent(event);
2672 }
2673
2674 bool wxWindow::HandleMove(int x, int y)
2675 {
2676 wxMoveEvent event(wxPoint(x, y), m_windowId);
2677 event.SetEventObject(this);
2678
2679 return GetEventHandler()->ProcessEvent(event);
2680 }
2681
2682 bool wxWindow::HandleSize(int w, int h, WXUINT WXUNUSED(flag))
2683 {
2684 wxSizeEvent event(wxSize(w, h), m_windowId);
2685 event.SetEventObject(this);
2686
2687 return GetEventHandler()->ProcessEvent(event);
2688 }
2689
2690 bool wxWindow::HandleGetMinMaxInfo(void *mmInfo)
2691 {
2692 MINMAXINFO *info = (MINMAXINFO *)mmInfo;
2693
2694 bool rc = FALSE;
2695
2696 if ( m_minWidth != -1 )
2697 {
2698 info->ptMinTrackSize.x = m_minWidth;
2699 rc = TRUE;
2700 }
2701
2702 if ( m_minHeight != -1 )
2703 {
2704 info->ptMinTrackSize.y = m_minHeight;
2705 rc = TRUE;
2706 }
2707
2708 if ( m_maxWidth != -1 )
2709 {
2710 info->ptMaxTrackSize.x = m_maxWidth;
2711 rc = TRUE;
2712 }
2713
2714 if ( m_maxHeight != -1 )
2715 {
2716 info->ptMaxTrackSize.y = m_maxHeight;
2717 rc = TRUE;
2718 }
2719
2720 return rc;
2721 }
2722
2723 // ---------------------------------------------------------------------------
2724 // command messages
2725 // ---------------------------------------------------------------------------
2726
2727 bool wxWindow::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
2728 {
2729 if ( wxCurrentPopupMenu )
2730 {
2731 wxMenu *popupMenu = wxCurrentPopupMenu;
2732 wxCurrentPopupMenu = NULL;
2733
2734 return popupMenu->MSWCommand(cmd, id);
2735 }
2736
2737 wxWindow *win = FindItem(id);
2738 if ( !win )
2739 {
2740 win = wxFindWinFromHandle(control);
2741 }
2742
2743 if ( win )
2744 return win->MSWCommand(cmd, id);
2745
2746 return FALSE;
2747 }
2748
2749 bool wxWindow::HandleSysCommand(WXWPARAM wParam, WXLPARAM lParam)
2750 {
2751 // 4 bits are reserved
2752 switch ( wParam & 0xFFFFFFF0 )
2753 {
2754 case SC_MAXIMIZE:
2755 return HandleMaximize();
2756
2757 case SC_MINIMIZE:
2758 return HandleMinimize();
2759 }
2760
2761 return FALSE;
2762 }
2763
2764 // ---------------------------------------------------------------------------
2765 // mouse events
2766 // ---------------------------------------------------------------------------
2767
2768 void wxWindow::InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags)
2769 {
2770 event.m_x = x;
2771 event.m_y = y;
2772 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
2773 event.m_controlDown = ((flags & MK_CONTROL) != 0);
2774 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
2775 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
2776 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
2777 event.SetTimestamp(s_currentMsg.time);
2778 event.m_eventObject = this;
2779
2780 #if wxUSE_MOUSEEVENT_HACK
2781 m_lastMouseX = x;
2782 m_lastMouseY = y;
2783 m_lastMouseEvent = event.GetEventType();
2784 #endif // wxUSE_MOUSEEVENT_HACK
2785
2786 }
2787
2788 bool wxWindow::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags)
2789 {
2790 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
2791 // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST
2792 // from the message id and take the value in the table to get wxWin event
2793 // id
2794 static const wxEventType eventsMouse[] =
2795 {
2796 wxEVT_MOTION,
2797 wxEVT_LEFT_DOWN,
2798 wxEVT_LEFT_UP,
2799 wxEVT_LEFT_DCLICK,
2800 wxEVT_RIGHT_DOWN,
2801 wxEVT_RIGHT_UP,
2802 wxEVT_RIGHT_DCLICK,
2803 wxEVT_MIDDLE_DOWN,
2804 wxEVT_MIDDLE_UP,
2805 wxEVT_MIDDLE_DCLICK
2806 };
2807
2808 wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]);
2809 InitMouseEvent(event, x, y, flags);
2810
2811 return GetEventHandler()->ProcessEvent(event);
2812 }
2813
2814 bool wxWindow::HandleMouseMove(int x, int y, WXUINT flags)
2815 {
2816 if ( !m_mouseInWindow )
2817 {
2818 // Generate an ENTER event
2819 m_mouseInWindow = TRUE;
2820
2821 wxMouseEvent event(wxEVT_ENTER_WINDOW);
2822 InitMouseEvent(event, x, y, flags);
2823
2824 (void)GetEventHandler()->ProcessEvent(event);
2825 }
2826
2827 #if wxUSE_MOUSEEVENT_HACK
2828 // Window gets a click down message followed by a mouse move message even
2829 // if position isn't changed! We want to discard the trailing move event
2830 // if x and y are the same.
2831 if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN ||
2832 m_lastMouseEvent == wxEVT_LEFT_DOWN ||
2833 m_lastMouseEvent == wxEVT_MIDDLE_DOWN) &&
2834 (m_lastMouseX == event.m_x && m_lastMouseY == event.m_y) )
2835 {
2836 m_lastMouseEvent = wxEVT_MOTION;
2837
2838 return FALSE;
2839 }
2840 #endif // wxUSE_MOUSEEVENT_HACK
2841
2842 return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags);
2843 }
2844
2845 // ---------------------------------------------------------------------------
2846 // keyboard handling
2847 // ---------------------------------------------------------------------------
2848
2849 // isASCII is TRUE only when we're called from WM_CHAR handler and not from
2850 // WM_KEYDOWN one
2851 bool wxWindow::HandleChar(WXWORD wParam, WXLPARAM lParam, bool isASCII)
2852 {
2853 int id;
2854 bool tempControlDown = FALSE;
2855 if ( isASCII )
2856 {
2857 // If 1 -> 26, translate to CTRL plus a letter.
2858 id = wParam;
2859 if ( (id > 0) && (id < 27) )
2860 {
2861 switch (id)
2862 {
2863 case 13:
2864 {
2865 id = WXK_RETURN;
2866 break;
2867 }
2868 case 8:
2869 {
2870 id = WXK_BACK;
2871 break;
2872 }
2873 case 9:
2874 {
2875 id = WXK_TAB;
2876 break;
2877 }
2878 default:
2879 {
2880 tempControlDown = TRUE;
2881 id = id + 96;
2882 }
2883 }
2884 }
2885 }
2886 else if ( (id = wxCharCodeMSWToWX(wParam)) == 0 ) {
2887 // it's ASCII and will be processed here only when called from
2888 // WM_CHAR (i.e. when isASCII = TRUE)
2889 id = -1;
2890 }
2891
2892 if ( id != -1 )
2893 {
2894 wxKeyEvent event(wxEVT_CHAR);
2895 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
2896 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
2897 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
2898 event.m_altDown = TRUE;
2899
2900 event.m_eventObject = this;
2901 event.m_keyCode = id;
2902 event.SetTimestamp(s_currentMsg.time);
2903
2904 POINT pt;
2905 GetCursorPos(&pt);
2906 RECT rect;
2907 GetWindowRect(GetHwnd(),&rect);
2908 pt.x -= rect.left;
2909 pt.y -= rect.top;
2910
2911 event.m_x = pt.x; event.m_y = pt.y;
2912
2913 if ( GetEventHandler()->ProcessEvent(event) )
2914 return TRUE;
2915 else
2916 return FALSE;
2917 }
2918 else
2919 return FALSE;
2920 }
2921
2922 bool wxWindow::HandleKeyDown(WXWORD wParam, WXLPARAM lParam)
2923 {
2924 int id;
2925
2926 if ( (id = wxCharCodeMSWToWX(wParam)) == 0 ) {
2927 id = wParam;
2928 }
2929
2930 if ( id != -1 )
2931 {
2932 wxKeyEvent event(wxEVT_KEY_DOWN);
2933 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
2934 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
2935 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
2936 event.m_altDown = TRUE;
2937
2938 event.m_eventObject = this;
2939 event.m_keyCode = id;
2940 event.SetTimestamp(s_currentMsg.time);
2941
2942 POINT pt;
2943 GetCursorPos(&pt);
2944 RECT rect;
2945 GetWindowRect(GetHwnd(),&rect);
2946 pt.x -= rect.left;
2947 pt.y -= rect.top;
2948
2949 event.m_x = pt.x; event.m_y = pt.y;
2950
2951 if ( GetEventHandler()->ProcessEvent(event) )
2952 {
2953 return TRUE;
2954 }
2955 else return FALSE;
2956 }
2957 else
2958 {
2959 return FALSE;
2960 }
2961 }
2962
2963 bool wxWindow::HandleKeyUp(WXWORD wParam, WXLPARAM lParam)
2964 {
2965 int id;
2966
2967 if ( (id = wxCharCodeMSWToWX(wParam)) == 0 ) {
2968 id = wParam;
2969 }
2970
2971 if ( id != -1 )
2972 {
2973 wxKeyEvent event(wxEVT_KEY_UP);
2974 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
2975 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
2976 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
2977 event.m_altDown = TRUE;
2978
2979 event.m_eventObject = this;
2980 event.m_keyCode = id;
2981 event.SetTimestamp(s_currentMsg.time);
2982
2983 POINT pt;
2984 GetCursorPos(&pt);
2985 RECT rect;
2986 GetWindowRect(GetHwnd(),&rect);
2987 pt.x -= rect.left;
2988 pt.y -= rect.top;
2989
2990 event.m_x = pt.x; event.m_y = pt.y;
2991
2992 if ( GetEventHandler()->ProcessEvent(event) )
2993 return TRUE;
2994 else
2995 return FALSE;
2996 }
2997 else
2998 return FALSE;
2999 }
3000
3001 // ---------------------------------------------------------------------------
3002 // joystick
3003 // ---------------------------------------------------------------------------
3004
3005 bool wxWindow::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
3006 {
3007 int change = 0;
3008 if ( flags & JOY_BUTTON1CHG )
3009 change = wxJOY_BUTTON1;
3010 if ( flags & JOY_BUTTON2CHG )
3011 change = wxJOY_BUTTON2;
3012 if ( flags & JOY_BUTTON3CHG )
3013 change = wxJOY_BUTTON3;
3014 if ( flags & JOY_BUTTON4CHG )
3015 change = wxJOY_BUTTON4;
3016
3017 int buttons = 0;
3018 if ( flags & JOY_BUTTON1 )
3019 buttons |= wxJOY_BUTTON1;
3020 if ( flags & JOY_BUTTON2 )
3021 buttons |= wxJOY_BUTTON2;
3022 if ( flags & JOY_BUTTON3 )
3023 buttons |= wxJOY_BUTTON3;
3024 if ( flags & JOY_BUTTON4 )
3025 buttons |= wxJOY_BUTTON4;
3026
3027 // the event ids aren't consecutive so we can't use table based lookup
3028 int joystick;
3029 wxEventType eventType;
3030 switch ( msg )
3031 {
3032 case MM_JOY1MOVE:
3033 joystick = 1;
3034 eventType = wxEVT_JOY_MOVE;
3035 break;
3036
3037 case MM_JOY2MOVE:
3038 joystick = 2;
3039 eventType = wxEVT_JOY_MOVE;
3040 break;
3041
3042 case MM_JOY1ZMOVE:
3043 joystick = 1;
3044 eventType = wxEVT_JOY_ZMOVE;
3045 break;
3046
3047 case MM_JOY2ZMOVE:
3048 joystick = 2;
3049 eventType = wxEVT_JOY_ZMOVE;
3050 break;
3051
3052 case MM_JOY1BUTTONDOWN:
3053 joystick = 1;
3054 eventType = wxEVT_JOY_BUTTON_DOWN;
3055 break;
3056
3057 case MM_JOY2BUTTONDOWN:
3058 joystick = 2;
3059 eventType = wxEVT_JOY_BUTTON_DOWN;
3060 break;
3061
3062 case MM_JOY1BUTTONUP:
3063 joystick = 1;
3064 eventType = wxEVT_JOY_BUTTON_UP;
3065 break;
3066
3067 case MM_JOY2BUTTONUP:
3068 joystick = 2;
3069 eventType = wxEVT_JOY_BUTTON_UP;
3070 break;
3071
3072 default:
3073 wxFAIL_MSG("no such joystick event");
3074
3075 return FALSE;
3076 }
3077
3078 wxJoystickEvent event(eventType, buttons, joystick, change);
3079 event.SetPosition(wxPoint(x, y));
3080 event.SetEventObject(this);
3081
3082 return GetEventHandler()->ProcessEvent(event);
3083 }
3084
3085 // ---------------------------------------------------------------------------
3086 // scrolling
3087 // ---------------------------------------------------------------------------
3088
3089 bool wxWindow::MSWOnScroll(int orientation, WXWORD wParam,
3090 WXWORD pos, WXHWND control)
3091 {
3092 if ( control )
3093 {
3094 wxWindow *child = wxFindWinFromHandle(control);
3095 if ( child )
3096 return child->MSWOnScroll(orientation, wParam, pos, control);
3097 }
3098
3099 wxScrollWinEvent event;
3100 event.SetPosition(pos);
3101 event.SetOrientation(orientation);
3102 event.m_eventObject = this;
3103
3104 switch ( wParam )
3105 {
3106 case SB_TOP:
3107 event.m_eventType = wxEVT_SCROLLWIN_TOP;
3108 break;
3109
3110 case SB_BOTTOM:
3111 event.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
3112 break;
3113
3114 case SB_LINEUP:
3115 event.m_eventType = wxEVT_SCROLLWIN_LINEUP;
3116 break;
3117
3118 case SB_LINEDOWN:
3119 event.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
3120 break;
3121
3122 case SB_PAGEUP:
3123 event.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
3124 break;
3125
3126 case SB_PAGEDOWN:
3127 event.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
3128 break;
3129
3130 case SB_THUMBTRACK:
3131 case SB_THUMBPOSITION:
3132 event.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
3133 break;
3134
3135 default:
3136 return FALSE;
3137 }
3138
3139 return GetEventHandler()->ProcessEvent(event);
3140 }
3141
3142 // ===========================================================================
3143 // global functions
3144 // ===========================================================================
3145
3146 void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font)
3147 {
3148 TEXTMETRIC tm;
3149 HDC dc = ::GetDC((HWND) wnd);
3150 HFONT fnt =0;
3151 HFONT was = 0;
3152 if ( the_font )
3153 {
3154 // the_font->UseResource();
3155 // the_font->RealizeResource();
3156 fnt = (HFONT)the_font->GetResourceHandle();
3157 if ( fnt )
3158 was = (HFONT) SelectObject(dc,fnt);
3159 }
3160 GetTextMetrics(dc, &tm);
3161 if ( the_font && fnt && was )
3162 {
3163 SelectObject(dc,was);
3164 }
3165 ReleaseDC((HWND)wnd, dc);
3166 *x = tm.tmAveCharWidth;
3167 *y = tm.tmHeight + tm.tmExternalLeading;
3168
3169 // if ( the_font )
3170 // the_font->ReleaseResource();
3171 }
3172
3173 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
3174 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
3175 int wxCharCodeMSWToWX(int keySym)
3176 {
3177 int id = 0;
3178 switch (keySym)
3179 {
3180 case VK_CANCEL: id = WXK_CANCEL; break;
3181 case VK_BACK: id = WXK_BACK; break;
3182 case VK_TAB: id = WXK_TAB; break;
3183 case VK_CLEAR: id = WXK_CLEAR; break;
3184 case VK_RETURN: id = WXK_RETURN; break;
3185 case VK_SHIFT: id = WXK_SHIFT; break;
3186 case VK_CONTROL: id = WXK_CONTROL; break;
3187 case VK_MENU : id = WXK_MENU; break;
3188 case VK_PAUSE: id = WXK_PAUSE; break;
3189 case VK_SPACE: id = WXK_SPACE; break;
3190 case VK_ESCAPE: id = WXK_ESCAPE; break;
3191 case VK_PRIOR: id = WXK_PRIOR; break;
3192 case VK_NEXT : id = WXK_NEXT; break;
3193 case VK_END: id = WXK_END; break;
3194 case VK_HOME : id = WXK_HOME; break;
3195 case VK_LEFT : id = WXK_LEFT; break;
3196 case VK_UP: id = WXK_UP; break;
3197 case VK_RIGHT: id = WXK_RIGHT; break;
3198 case VK_DOWN : id = WXK_DOWN; break;
3199 case VK_SELECT: id = WXK_SELECT; break;
3200 case VK_PRINT: id = WXK_PRINT; break;
3201 case VK_EXECUTE: id = WXK_EXECUTE; break;
3202 case VK_INSERT: id = WXK_INSERT; break;
3203 case VK_DELETE: id = WXK_DELETE; break;
3204 case VK_HELP : id = WXK_HELP; break;
3205 case VK_NUMPAD0: id = WXK_NUMPAD0; break;
3206 case VK_NUMPAD1: id = WXK_NUMPAD1; break;
3207 case VK_NUMPAD2: id = WXK_NUMPAD2; break;
3208 case VK_NUMPAD3: id = WXK_NUMPAD3; break;
3209 case VK_NUMPAD4: id = WXK_NUMPAD4; break;
3210 case VK_NUMPAD5: id = WXK_NUMPAD5; break;
3211 case VK_NUMPAD6: id = WXK_NUMPAD6; break;
3212 case VK_NUMPAD7: id = WXK_NUMPAD7; break;
3213 case VK_NUMPAD8: id = WXK_NUMPAD8; break;
3214 case VK_NUMPAD9: id = WXK_NUMPAD9; break;
3215 case VK_MULTIPLY: id = WXK_MULTIPLY; break;
3216 case VK_ADD: id = WXK_ADD; break;
3217 case VK_SUBTRACT: id = WXK_SUBTRACT; break;
3218 case VK_DECIMAL: id = WXK_DECIMAL; break;
3219 case VK_DIVIDE: id = WXK_DIVIDE; break;
3220 case VK_F1: id = WXK_F1; break;
3221 case VK_F2: id = WXK_F2; break;
3222 case VK_F3: id = WXK_F3; break;
3223 case VK_F4: id = WXK_F4; break;
3224 case VK_F5: id = WXK_F5; break;
3225 case VK_F6: id = WXK_F6; break;
3226 case VK_F7: id = WXK_F7; break;
3227 case VK_F8: id = WXK_F8; break;
3228 case VK_F9: id = WXK_F9; break;
3229 case VK_F10: id = WXK_F10; break;
3230 case VK_F11: id = WXK_F11; break;
3231 case VK_F12: id = WXK_F12; break;
3232 case VK_F13: id = WXK_F13; break;
3233 case VK_F14: id = WXK_F14; break;
3234 case VK_F15: id = WXK_F15; break;
3235 case VK_F16: id = WXK_F16; break;
3236 case VK_F17: id = WXK_F17; break;
3237 case VK_F18: id = WXK_F18; break;
3238 case VK_F19: id = WXK_F19; break;
3239 case VK_F20: id = WXK_F20; break;
3240 case VK_F21: id = WXK_F21; break;
3241 case VK_F22: id = WXK_F22; break;
3242 case VK_F23: id = WXK_F23; break;
3243 case VK_F24: id = WXK_F24; break;
3244 case VK_NUMLOCK: id = WXK_NUMLOCK; break;
3245 case VK_SCROLL: id = WXK_SCROLL; break;
3246 default:
3247 {
3248 return 0;
3249 }
3250 }
3251 return id;
3252 }
3253
3254 int wxCharCodeWXToMSW(int id, bool *isVirtual)
3255 {
3256 *isVirtual = TRUE;
3257 int keySym = 0;
3258 switch (id)
3259 {
3260 case WXK_CANCEL: keySym = VK_CANCEL; break;
3261 case WXK_CLEAR: keySym = VK_CLEAR; break;
3262 case WXK_SHIFT: keySym = VK_SHIFT; break;
3263 case WXK_CONTROL: keySym = VK_CONTROL; break;
3264 case WXK_MENU : keySym = VK_MENU; break;
3265 case WXK_PAUSE: keySym = VK_PAUSE; break;
3266 case WXK_PRIOR: keySym = VK_PRIOR; break;
3267 case WXK_NEXT : keySym = VK_NEXT; break;
3268 case WXK_END: keySym = VK_END; break;
3269 case WXK_HOME : keySym = VK_HOME; break;
3270 case WXK_LEFT : keySym = VK_LEFT; break;
3271 case WXK_UP: keySym = VK_UP; break;
3272 case WXK_RIGHT: keySym = VK_RIGHT; break;
3273 case WXK_DOWN : keySym = VK_DOWN; break;
3274 case WXK_SELECT: keySym = VK_SELECT; break;
3275 case WXK_PRINT: keySym = VK_PRINT; break;
3276 case WXK_EXECUTE: keySym = VK_EXECUTE; break;
3277 case WXK_INSERT: keySym = VK_INSERT; break;
3278 case WXK_DELETE: keySym = VK_DELETE; break;
3279 case WXK_HELP : keySym = VK_HELP; break;
3280 case WXK_NUMPAD0: keySym = VK_NUMPAD0; break;
3281 case WXK_NUMPAD1: keySym = VK_NUMPAD1; break;
3282 case WXK_NUMPAD2: keySym = VK_NUMPAD2; break;
3283 case WXK_NUMPAD3: keySym = VK_NUMPAD3; break;
3284 case WXK_NUMPAD4: keySym = VK_NUMPAD4; break;
3285 case WXK_NUMPAD5: keySym = VK_NUMPAD5; break;
3286 case WXK_NUMPAD6: keySym = VK_NUMPAD6; break;
3287 case WXK_NUMPAD7: keySym = VK_NUMPAD7; break;
3288 case WXK_NUMPAD8: keySym = VK_NUMPAD8; break;
3289 case WXK_NUMPAD9: keySym = VK_NUMPAD9; break;
3290 case WXK_MULTIPLY: keySym = VK_MULTIPLY; break;
3291 case WXK_ADD: keySym = VK_ADD; break;
3292 case WXK_SUBTRACT: keySym = VK_SUBTRACT; break;
3293 case WXK_DECIMAL: keySym = VK_DECIMAL; break;
3294 case WXK_DIVIDE: keySym = VK_DIVIDE; break;
3295 case WXK_F1: keySym = VK_F1; break;
3296 case WXK_F2: keySym = VK_F2; break;
3297 case WXK_F3: keySym = VK_F3; break;
3298 case WXK_F4: keySym = VK_F4; break;
3299 case WXK_F5: keySym = VK_F5; break;
3300 case WXK_F6: keySym = VK_F6; break;
3301 case WXK_F7: keySym = VK_F7; break;
3302 case WXK_F8: keySym = VK_F8; break;
3303 case WXK_F9: keySym = VK_F9; break;
3304 case WXK_F10: keySym = VK_F10; break;
3305 case WXK_F11: keySym = VK_F11; break;
3306 case WXK_F12: keySym = VK_F12; break;
3307 case WXK_F13: keySym = VK_F13; break;
3308 case WXK_F14: keySym = VK_F14; break;
3309 case WXK_F15: keySym = VK_F15; break;
3310 case WXK_F16: keySym = VK_F16; break;
3311 case WXK_F17: keySym = VK_F17; break;
3312 case WXK_F18: keySym = VK_F18; break;
3313 case WXK_F19: keySym = VK_F19; break;
3314 case WXK_F20: keySym = VK_F20; break;
3315 case WXK_F21: keySym = VK_F21; break;
3316 case WXK_F22: keySym = VK_F22; break;
3317 case WXK_F23: keySym = VK_F23; break;
3318 case WXK_F24: keySym = VK_F24; break;
3319 case WXK_NUMLOCK: keySym = VK_NUMLOCK; break;
3320 case WXK_SCROLL: keySym = VK_SCROLL; break;
3321 default:
3322 {
3323 *isVirtual = FALSE;
3324 keySym = id;
3325 break;
3326 }
3327 }
3328 return keySym;
3329 }
3330
3331 wxWindow *wxGetActiveWindow()
3332 {
3333 HWND hWnd = GetActiveWindow();
3334 if ( hWnd != 0 )
3335 {
3336 return wxFindWinFromHandle((WXHWND) hWnd);
3337 }
3338 return NULL;
3339 }
3340
3341 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
3342 // in active frames and dialogs, regardless of where the focus is.
3343 static HHOOK wxTheKeyboardHook = 0;
3344 static FARPROC wxTheKeyboardHookProc = 0;
3345 int APIENTRY _EXPORT
3346 wxKeyboardHook(int nCode, WORD wParam, DWORD lParam);
3347
3348 void wxSetKeyboardHook(bool doIt)
3349 {
3350 if ( doIt )
3351 {
3352 wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance());
3353 wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
3354 #if defined(__WIN32__) && !defined(__TWIN32__)
3355 GetCurrentThreadId());
3356 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
3357 #else
3358 GetCurrentTask());
3359 #endif
3360 }
3361 else
3362 {
3363 UnhookWindowsHookEx(wxTheKeyboardHook);
3364 FreeProcInstance(wxTheKeyboardHookProc);
3365 }
3366 }
3367
3368 int APIENTRY _EXPORT
3369 wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
3370 {
3371 DWORD hiWord = HIWORD(lParam);
3372 if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) )
3373 {
3374 int id;
3375 if ( (id = wxCharCodeMSWToWX(wParam)) != 0 )
3376 {
3377 wxKeyEvent event(wxEVT_CHAR_HOOK);
3378 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
3379 event.m_altDown = TRUE;
3380
3381 event.m_eventObject = NULL;
3382 event.m_keyCode = id;
3383 /* begin Albert's fix for control and shift key 26.5 */
3384 event.m_shiftDown = (::GetKeyState(VK_SHIFT)&0x100?TRUE:FALSE);
3385 event.m_controlDown = (::GetKeyState(VK_CONTROL)&0x100?TRUE:FALSE);
3386 /* end Albert's fix for control and shift key 26.5 */
3387 event.SetTimestamp(s_currentMsg.time);
3388
3389 wxWindow *win = wxGetActiveWindow();
3390 if ( win )
3391 {
3392 if ( win->GetEventHandler()->ProcessEvent(event) )
3393 return 1;
3394 }
3395 else
3396 {
3397 if ( wxTheApp && wxTheApp->ProcessEvent(event) )
3398 return 1;
3399 }
3400 }
3401 }
3402 return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam);
3403 }
3404
3405 #ifdef __WXDEBUG__
3406 const char *wxGetMessageName(int message)
3407 {
3408 switch ( message )
3409 {
3410 case 0x0000: return "WM_NULL";
3411 case 0x0001: return "WM_CREATE";
3412 case 0x0002: return "WM_DESTROY";
3413 case 0x0003: return "WM_MOVE";
3414 case 0x0005: return "WM_SIZE";
3415 case 0x0006: return "WM_ACTIVATE";
3416 case 0x0007: return "WM_SETFOCUS";
3417 case 0x0008: return "WM_KILLFOCUS";
3418 case 0x000A: return "WM_ENABLE";
3419 case 0x000B: return "WM_SETREDRAW";
3420 case 0x000C: return "WM_SETTEXT";
3421 case 0x000D: return "WM_GETTEXT";
3422 case 0x000E: return "WM_GETTEXTLENGTH";
3423 case 0x000F: return "WM_PAINT";
3424 case 0x0010: return "WM_CLOSE";
3425 case 0x0011: return "WM_QUERYENDSESSION";
3426 case 0x0012: return "WM_QUIT";
3427 case 0x0013: return "WM_QUERYOPEN";
3428 case 0x0014: return "WM_ERASEBKGND";
3429 case 0x0015: return "WM_SYSCOLORCHANGE";
3430 case 0x0016: return "WM_ENDSESSION";
3431 case 0x0017: return "WM_SYSTEMERROR";
3432 case 0x0018: return "WM_SHOWWINDOW";
3433 case 0x0019: return "WM_CTLCOLOR";
3434 case 0x001A: return "WM_WININICHANGE";
3435 case 0x001B: return "WM_DEVMODECHANGE";
3436 case 0x001C: return "WM_ACTIVATEAPP";
3437 case 0x001D: return "WM_FONTCHANGE";
3438 case 0x001E: return "WM_TIMECHANGE";
3439 case 0x001F: return "WM_CANCELMODE";
3440 case 0x0020: return "WM_SETCURSOR";
3441 case 0x0021: return "WM_MOUSEACTIVATE";
3442 case 0x0022: return "WM_CHILDACTIVATE";
3443 case 0x0023: return "WM_QUEUESYNC";
3444 case 0x0024: return "WM_GETMINMAXINFO";
3445 case 0x0026: return "WM_PAINTICON";
3446 case 0x0027: return "WM_ICONERASEBKGND";
3447 case 0x0028: return "WM_NEXTDLGCTL";
3448 case 0x002A: return "WM_SPOOLERSTATUS";
3449 case 0x002B: return "WM_DRAWITEM";
3450 case 0x002C: return "WM_MEASUREITEM";
3451 case 0x002D: return "WM_DELETEITEM";
3452 case 0x002E: return "WM_VKEYTOITEM";
3453 case 0x002F: return "WM_CHARTOITEM";
3454 case 0x0030: return "WM_SETFONT";
3455 case 0x0031: return "WM_GETFONT";
3456 case 0x0037: return "WM_QUERYDRAGICON";
3457 case 0x0039: return "WM_COMPAREITEM";
3458 case 0x0041: return "WM_COMPACTING";
3459 case 0x0044: return "WM_COMMNOTIFY";
3460 case 0x0046: return "WM_WINDOWPOSCHANGING";
3461 case 0x0047: return "WM_WINDOWPOSCHANGED";
3462 case 0x0048: return "WM_POWER";
3463
3464 #ifdef __WIN32__
3465 case 0x004A: return "WM_COPYDATA";
3466 case 0x004B: return "WM_CANCELJOURNAL";
3467 case 0x004E: return "WM_NOTIFY";
3468 case 0x0050: return "WM_INPUTLANGCHANGEREQUEST";
3469 case 0x0051: return "WM_INPUTLANGCHANGE";
3470 case 0x0052: return "WM_TCARD";
3471 case 0x0053: return "WM_HELP";
3472 case 0x0054: return "WM_USERCHANGED";
3473 case 0x0055: return "WM_NOTIFYFORMAT";
3474 case 0x007B: return "WM_CONTEXTMENU";
3475 case 0x007C: return "WM_STYLECHANGING";
3476 case 0x007D: return "WM_STYLECHANGED";
3477 case 0x007E: return "WM_DISPLAYCHANGE";
3478 case 0x007F: return "WM_GETICON";
3479 case 0x0080: return "WM_SETICON";
3480 #endif //WIN32
3481
3482 case 0x0081: return "WM_NCCREATE";
3483 case 0x0082: return "WM_NCDESTROY";
3484 case 0x0083: return "WM_NCCALCSIZE";
3485 case 0x0084: return "WM_NCHITTEST";
3486 case 0x0085: return "WM_NCPAINT";
3487 case 0x0086: return "WM_NCACTIVATE";
3488 case 0x0087: return "WM_GETDLGCODE";
3489 case 0x00A0: return "WM_NCMOUSEMOVE";
3490 case 0x00A1: return "WM_NCLBUTTONDOWN";
3491 case 0x00A2: return "WM_NCLBUTTONUP";
3492 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
3493 case 0x00A4: return "WM_NCRBUTTONDOWN";
3494 case 0x00A5: return "WM_NCRBUTTONUP";
3495 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
3496 case 0x00A7: return "WM_NCMBUTTONDOWN";
3497 case 0x00A8: return "WM_NCMBUTTONUP";
3498 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
3499 case 0x0100: return "WM_KEYDOWN";
3500 case 0x0101: return "WM_KEYUP";
3501 case 0x0102: return "WM_CHAR";
3502 case 0x0103: return "WM_DEADCHAR";
3503 case 0x0104: return "WM_SYSKEYDOWN";
3504 case 0x0105: return "WM_SYSKEYUP";
3505 case 0x0106: return "WM_SYSCHAR";
3506 case 0x0107: return "WM_SYSDEADCHAR";
3507 case 0x0108: return "WM_KEYLAST";
3508
3509 #ifdef __WIN32__
3510 case 0x010D: return "WM_IME_STARTCOMPOSITION";
3511 case 0x010E: return "WM_IME_ENDCOMPOSITION";
3512 case 0x010F: return "WM_IME_COMPOSITION";
3513 #endif //WIN32
3514
3515 case 0x0110: return "WM_INITDIALOG";
3516 case 0x0111: return "WM_COMMAND";
3517 case 0x0112: return "WM_SYSCOMMAND";
3518 case 0x0113: return "WM_TIMER";
3519 case 0x0114: return "WM_HSCROLL";
3520 case 0x0115: return "WM_VSCROLL";
3521 case 0x0116: return "WM_INITMENU";
3522 case 0x0117: return "WM_INITMENUPOPUP";
3523 case 0x011F: return "WM_MENUSELECT";
3524 case 0x0120: return "WM_MENUCHAR";
3525 case 0x0121: return "WM_ENTERIDLE";
3526 case 0x0200: return "WM_MOUSEMOVE";
3527 case 0x0201: return "WM_LBUTTONDOWN";
3528 case 0x0202: return "WM_LBUTTONUP";
3529 case 0x0203: return "WM_LBUTTONDBLCLK";
3530 case 0x0204: return "WM_RBUTTONDOWN";
3531 case 0x0205: return "WM_RBUTTONUP";
3532 case 0x0206: return "WM_RBUTTONDBLCLK";
3533 case 0x0207: return "WM_MBUTTONDOWN";
3534 case 0x0208: return "WM_MBUTTONUP";
3535 case 0x0209: return "WM_MBUTTONDBLCLK";
3536 case 0x0210: return "WM_PARENTNOTIFY";
3537 case 0x0211: return "WM_ENTERMENULOOP";
3538 case 0x0212: return "WM_EXITMENULOOP";
3539
3540 #ifdef __WIN32__
3541 case 0x0213: return "WM_NEXTMENU";
3542 case 0x0214: return "WM_SIZING";
3543 case 0x0215: return "WM_CAPTURECHANGED";
3544 case 0x0216: return "WM_MOVING";
3545 case 0x0218: return "WM_POWERBROADCAST";
3546 case 0x0219: return "WM_DEVICECHANGE";
3547 #endif //WIN32
3548
3549 case 0x0220: return "WM_MDICREATE";
3550 case 0x0221: return "WM_MDIDESTROY";
3551 case 0x0222: return "WM_MDIACTIVATE";
3552 case 0x0223: return "WM_MDIRESTORE";
3553 case 0x0224: return "WM_MDINEXT";
3554 case 0x0225: return "WM_MDIMAXIMIZE";
3555 case 0x0226: return "WM_MDITILE";
3556 case 0x0227: return "WM_MDICASCADE";
3557 case 0x0228: return "WM_MDIICONARRANGE";
3558 case 0x0229: return "WM_MDIGETACTIVE";
3559 case 0x0230: return "WM_MDISETMENU";
3560 case 0x0233: return "WM_DROPFILES";
3561
3562 #ifdef __WIN32__
3563 case 0x0281: return "WM_IME_SETCONTEXT";
3564 case 0x0282: return "WM_IME_NOTIFY";
3565 case 0x0283: return "WM_IME_CONTROL";
3566 case 0x0284: return "WM_IME_COMPOSITIONFULL";
3567 case 0x0285: return "WM_IME_SELECT";
3568 case 0x0286: return "WM_IME_CHAR";
3569 case 0x0290: return "WM_IME_KEYDOWN";
3570 case 0x0291: return "WM_IME_KEYUP";
3571 #endif //WIN32
3572
3573 case 0x0300: return "WM_CUT";
3574 case 0x0301: return "WM_COPY";
3575 case 0x0302: return "WM_PASTE";
3576 case 0x0303: return "WM_CLEAR";
3577 case 0x0304: return "WM_UNDO";
3578 case 0x0305: return "WM_RENDERFORMAT";
3579 case 0x0306: return "WM_RENDERALLFORMATS";
3580 case 0x0307: return "WM_DESTROYCLIPBOARD";
3581 case 0x0308: return "WM_DRAWCLIPBOARD";
3582 case 0x0309: return "WM_PAINTCLIPBOARD";
3583 case 0x030A: return "WM_VSCROLLCLIPBOARD";
3584 case 0x030B: return "WM_SIZECLIPBOARD";
3585 case 0x030C: return "WM_ASKCBFORMATNAME";
3586 case 0x030D: return "WM_CHANGECBCHAIN";
3587 case 0x030E: return "WM_HSCROLLCLIPBOARD";
3588 case 0x030F: return "WM_QUERYNEWPALETTE";
3589 case 0x0310: return "WM_PALETTEISCHANGING";
3590 case 0x0311: return "WM_PALETTECHANGED";
3591
3592 #ifdef __WIN32__
3593 // common controls messages - although they're not strictly speaking
3594 // standard, it's nice to decode them nevertheless
3595
3596 // listview
3597 case 0x1000 + 0: return "LVM_GETBKCOLOR";
3598 case 0x1000 + 1: return "LVM_SETBKCOLOR";
3599 case 0x1000 + 2: return "LVM_GETIMAGELIST";
3600 case 0x1000 + 3: return "LVM_SETIMAGELIST";
3601 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
3602 case 0x1000 + 5: return "LVM_GETITEMA";
3603 case 0x1000 + 75: return "LVM_GETITEMW";
3604 case 0x1000 + 6: return "LVM_SETITEMA";
3605 case 0x1000 + 76: return "LVM_SETITEMW";
3606 case 0x1000 + 7: return "LVM_INSERTITEMA";
3607 case 0x1000 + 77: return "LVM_INSERTITEMW";
3608 case 0x1000 + 8: return "LVM_DELETEITEM";
3609 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
3610 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
3611 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
3612 case 0x1000 + 12: return "LVM_GETNEXTITEM";
3613 case 0x1000 + 13: return "LVM_FINDITEMA";
3614 case 0x1000 + 83: return "LVM_FINDITEMW";
3615 case 0x1000 + 14: return "LVM_GETITEMRECT";
3616 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
3617 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
3618 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
3619 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
3620 case 0x1000 + 18: return "LVM_HITTEST";
3621 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
3622 case 0x1000 + 20: return "LVM_SCROLL";
3623 case 0x1000 + 21: return "LVM_REDRAWITEMS";
3624 case 0x1000 + 22: return "LVM_ARRANGE";
3625 case 0x1000 + 23: return "LVM_EDITLABELA";
3626 case 0x1000 + 118: return "LVM_EDITLABELW";
3627 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
3628 case 0x1000 + 25: return "LVM_GETCOLUMNA";
3629 case 0x1000 + 95: return "LVM_GETCOLUMNW";
3630 case 0x1000 + 26: return "LVM_SETCOLUMNA";
3631 case 0x1000 + 96: return "LVM_SETCOLUMNW";
3632 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
3633 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
3634 case 0x1000 + 28: return "LVM_DELETECOLUMN";
3635 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
3636 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
3637 case 0x1000 + 31: return "LVM_GETHEADER";
3638 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
3639 case 0x1000 + 34: return "LVM_GETVIEWRECT";
3640 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
3641 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
3642 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
3643 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
3644 case 0x1000 + 39: return "LVM_GETTOPINDEX";
3645 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
3646 case 0x1000 + 41: return "LVM_GETORIGIN";
3647 case 0x1000 + 42: return "LVM_UPDATE";
3648 case 0x1000 + 43: return "LVM_SETITEMSTATE";
3649 case 0x1000 + 44: return "LVM_GETITEMSTATE";
3650 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
3651 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
3652 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
3653 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
3654 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
3655 case 0x1000 + 48: return "LVM_SORTITEMS";
3656 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
3657 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
3658 case 0x1000 + 51: return "LVM_GETITEMSPACING";
3659 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
3660 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
3661 case 0x1000 + 53: return "LVM_SETICONSPACING";
3662 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
3663 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
3664 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
3665 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
3666 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
3667 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
3668 case 0x1000 + 60: return "LVM_SETHOTITEM";
3669 case 0x1000 + 61: return "LVM_GETHOTITEM";
3670 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
3671 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
3672 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
3673 case 0x1000 + 65: return "LVM_SETWORKAREA";
3674
3675 // tree view
3676 case 0x1100 + 0: return "TVM_INSERTITEMA";
3677 case 0x1100 + 50: return "TVM_INSERTITEMW";
3678 case 0x1100 + 1: return "TVM_DELETEITEM";
3679 case 0x1100 + 2: return "TVM_EXPAND";
3680 case 0x1100 + 4: return "TVM_GETITEMRECT";
3681 case 0x1100 + 5: return "TVM_GETCOUNT";
3682 case 0x1100 + 6: return "TVM_GETINDENT";
3683 case 0x1100 + 7: return "TVM_SETINDENT";
3684 case 0x1100 + 8: return "TVM_GETIMAGELIST";
3685 case 0x1100 + 9: return "TVM_SETIMAGELIST";
3686 case 0x1100 + 10: return "TVM_GETNEXTITEM";
3687 case 0x1100 + 11: return "TVM_SELECTITEM";
3688 case 0x1100 + 12: return "TVM_GETITEMA";
3689 case 0x1100 + 62: return "TVM_GETITEMW";
3690 case 0x1100 + 13: return "TVM_SETITEMA";
3691 case 0x1100 + 63: return "TVM_SETITEMW";
3692 case 0x1100 + 14: return "TVM_EDITLABELA";
3693 case 0x1100 + 65: return "TVM_EDITLABELW";
3694 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
3695 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
3696 case 0x1100 + 17: return "TVM_HITTEST";
3697 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
3698 case 0x1100 + 19: return "TVM_SORTCHILDREN";
3699 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
3700 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
3701 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
3702 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
3703 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
3704 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
3705 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
3706
3707 // header
3708 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
3709 case 0x1200 + 1: return "HDM_INSERTITEMA";
3710 case 0x1200 + 10: return "HDM_INSERTITEMW";
3711 case 0x1200 + 2: return "HDM_DELETEITEM";
3712 case 0x1200 + 3: return "HDM_GETITEMA";
3713 case 0x1200 + 11: return "HDM_GETITEMW";
3714 case 0x1200 + 4: return "HDM_SETITEMA";
3715 case 0x1200 + 12: return "HDM_SETITEMW";
3716 case 0x1200 + 5: return "HDM_LAYOUT";
3717 case 0x1200 + 6: return "HDM_HITTEST";
3718 case 0x1200 + 7: return "HDM_GETITEMRECT";
3719 case 0x1200 + 8: return "HDM_SETIMAGELIST";
3720 case 0x1200 + 9: return "HDM_GETIMAGELIST";
3721 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
3722 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
3723 case 0x1200 + 17: return "HDM_GETORDERARRAY";
3724 case 0x1200 + 18: return "HDM_SETORDERARRAY";
3725 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
3726
3727 // tab control
3728 case 0x1300 + 2: return "TCM_GETIMAGELIST";
3729 case 0x1300 + 3: return "TCM_SETIMAGELIST";
3730 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
3731 case 0x1300 + 5: return "TCM_GETITEMA";
3732 case 0x1300 + 60: return "TCM_GETITEMW";
3733 case 0x1300 + 6: return "TCM_SETITEMA";
3734 case 0x1300 + 61: return "TCM_SETITEMW";
3735 case 0x1300 + 7: return "TCM_INSERTITEMA";
3736 case 0x1300 + 62: return "TCM_INSERTITEMW";
3737 case 0x1300 + 8: return "TCM_DELETEITEM";
3738 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
3739 case 0x1300 + 10: return "TCM_GETITEMRECT";
3740 case 0x1300 + 11: return "TCM_GETCURSEL";
3741 case 0x1300 + 12: return "TCM_SETCURSEL";
3742 case 0x1300 + 13: return "TCM_HITTEST";
3743 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
3744 case 0x1300 + 40: return "TCM_ADJUSTRECT";
3745 case 0x1300 + 41: return "TCM_SETITEMSIZE";
3746 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
3747 case 0x1300 + 43: return "TCM_SETPADDING";
3748 case 0x1300 + 44: return "TCM_GETROWCOUNT";
3749 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
3750 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
3751 case 0x1300 + 47: return "TCM_GETCURFOCUS";
3752 case 0x1300 + 48: return "TCM_SETCURFOCUS";
3753 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
3754 case 0x1300 + 50: return "TCM_DESELECTALL";
3755
3756 // toolbar
3757 case WM_USER+1: return "TB_ENABLEBUTTON";
3758 case WM_USER+2: return "TB_CHECKBUTTON";
3759 case WM_USER+3: return "TB_PRESSBUTTON";
3760 case WM_USER+4: return "TB_HIDEBUTTON";
3761 case WM_USER+5: return "TB_INDETERMINATE";
3762 case WM_USER+9: return "TB_ISBUTTONENABLED";
3763 case WM_USER+10: return "TB_ISBUTTONCHECKED";
3764 case WM_USER+11: return "TB_ISBUTTONPRESSED";
3765 case WM_USER+12: return "TB_ISBUTTONHIDDEN";
3766 case WM_USER+13: return "TB_ISBUTTONINDETERMINATE";
3767 case WM_USER+17: return "TB_SETSTATE";
3768 case WM_USER+18: return "TB_GETSTATE";
3769 case WM_USER+19: return "TB_ADDBITMAP";
3770 case WM_USER+20: return "TB_ADDBUTTONS";
3771 case WM_USER+21: return "TB_INSERTBUTTON";
3772 case WM_USER+22: return "TB_DELETEBUTTON";
3773 case WM_USER+23: return "TB_GETBUTTON";
3774 case WM_USER+24: return "TB_BUTTONCOUNT";
3775 case WM_USER+25: return "TB_COMMANDTOINDEX";
3776 case WM_USER+26: return "TB_SAVERESTOREA";
3777 case WM_USER+76: return "TB_SAVERESTOREW";
3778 case WM_USER+27: return "TB_CUSTOMIZE";
3779 case WM_USER+28: return "TB_ADDSTRINGA";
3780 case WM_USER+77: return "TB_ADDSTRINGW";
3781 case WM_USER+29: return "TB_GETITEMRECT";
3782 case WM_USER+30: return "TB_BUTTONSTRUCTSIZE";
3783 case WM_USER+31: return "TB_SETBUTTONSIZE";
3784 case WM_USER+32: return "TB_SETBITMAPSIZE";
3785 case WM_USER+33: return "TB_AUTOSIZE";
3786 case WM_USER+35: return "TB_GETTOOLTIPS";
3787 case WM_USER+36: return "TB_SETTOOLTIPS";
3788 case WM_USER+37: return "TB_SETPARENT";
3789 case WM_USER+39: return "TB_SETROWS";
3790 case WM_USER+40: return "TB_GETROWS";
3791 case WM_USER+42: return "TB_SETCMDID";
3792 case WM_USER+43: return "TB_CHANGEBITMAP";
3793 case WM_USER+44: return "TB_GETBITMAP";
3794 case WM_USER+45: return "TB_GETBUTTONTEXTA";
3795 case WM_USER+75: return "TB_GETBUTTONTEXTW";
3796 case WM_USER+46: return "TB_REPLACEBITMAP";
3797 case WM_USER+47: return "TB_SETINDENT";
3798 case WM_USER+48: return "TB_SETIMAGELIST";
3799 case WM_USER+49: return "TB_GETIMAGELIST";
3800 case WM_USER+50: return "TB_LOADIMAGES";
3801 case WM_USER+51: return "TB_GETRECT";
3802 case WM_USER+52: return "TB_SETHOTIMAGELIST";
3803 case WM_USER+53: return "TB_GETHOTIMAGELIST";
3804 case WM_USER+54: return "TB_SETDISABLEDIMAGELIST";
3805 case WM_USER+55: return "TB_GETDISABLEDIMAGELIST";
3806 case WM_USER+56: return "TB_SETSTYLE";
3807 case WM_USER+57: return "TB_GETSTYLE";
3808 case WM_USER+58: return "TB_GETBUTTONSIZE";
3809 case WM_USER+59: return "TB_SETBUTTONWIDTH";
3810 case WM_USER+60: return "TB_SETMAXTEXTROWS";
3811 case WM_USER+61: return "TB_GETTEXTROWS";
3812 case WM_USER+41: return "TB_GETBITMAPFLAGS";
3813
3814 #endif //WIN32
3815
3816 default:
3817 static char s_szBuf[128];
3818 sprintf(s_szBuf, "<unknown message = %d>", message);
3819 return s_szBuf;
3820 }
3821 }
3822 #endif //__WXDEBUG__