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