]> git.saurik.com Git - wxWidgets.git/blob - src/msw/window.cpp
1. warning in gtk/menu.cpp fixed
[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 #ifndef __GNUWIN32_OLD__
83 #include <shellapi.h>
84 #include <mmsystem.h>
85 #endif
86
87 #ifdef __WIN32__
88 #include <windowsx.h>
89 #endif
90
91 #if !defined(__GNUWIN32_OLD__) && !defined(__TWIN32__)
92 #ifdef __WIN95__
93 #include <commctrl.h>
94 #endif
95 #else // broken compiler
96 #ifndef __TWIN32__
97 #include "wx/msw/gnuwin32/extra.h"
98 #endif
99 #endif
100
101 // ---------------------------------------------------------------------------
102 // global variables
103 // ---------------------------------------------------------------------------
104
105 // the last Windows message we got (MT-UNSAFE)
106 extern MSG s_currentMsg;
107
108 wxMenu *wxCurrentPopupMenu = NULL;
109 extern wxList WXDLLEXPORT wxPendingDelete;
110 extern const wxChar *wxCanvasClassName;
111
112 // ---------------------------------------------------------------------------
113 // private functions
114 // ---------------------------------------------------------------------------
115
116 // the window proc for all our windows
117 LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
118 WPARAM wParam, LPARAM lParam);
119
120 #ifdef __WXDEBUG__
121 const char *wxGetMessageName(int message);
122 #endif //__WXDEBUG__
123
124 void wxRemoveHandleAssociation(wxWindow *win);
125 void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win);
126 wxWindow *wxFindWinFromHandle(WXHWND hWnd);
127
128 // this magical function is used to translate VK_APPS key presses to right
129 // mouse clicks
130 static void TranslateKbdEventToMouse(wxWindow *win, int *x, int *y, WPARAM *flags);
131
132 // get the current state of SHIFT/CTRL keys
133 inline bool wxIsShiftDown() { return (GetKeyState(VK_SHIFT) & 0x100) != 0; }
134 inline bool wxIsCtrlDown() { return (GetKeyState(VK_CONTROL) & 0x100) != 0; }
135
136 // ---------------------------------------------------------------------------
137 // event tables
138 // ---------------------------------------------------------------------------
139
140 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
141
142 BEGIN_EVENT_TABLE(wxWindow, wxWindowBase)
143 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
144 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
145 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
146 EVT_IDLE(wxWindow::OnIdle)
147 EVT_SET_FOCUS(wxWindow::OnSetFocus)
148 END_EVENT_TABLE()
149
150 // ===========================================================================
151 // implementation
152 // ===========================================================================
153
154 // ---------------------------------------------------------------------------
155 // wxWindow utility functions
156 // ---------------------------------------------------------------------------
157
158 // Find an item given the MS Windows id
159 wxWindow *wxWindow::FindItem(long id) const
160 {
161 wxControl *item = wxDynamicCast(this, wxControl);
162 if ( item )
163 {
164 // i it we or one of our "internal" children?
165 if ( item->GetId() == id ||
166 (item->GetSubcontrols().Index(id) != wxNOT_FOUND) )
167 {
168 return item;
169 }
170 }
171
172 wxWindowList::Node *current = GetChildren().GetFirst();
173 while (current)
174 {
175 wxWindow *childWin = current->GetData();
176
177 wxWindow *wnd = childWin->FindItem(id);
178 if ( wnd )
179 return wnd;
180
181 current = current->GetNext();
182 }
183
184 return NULL;
185 }
186
187 // Find an item given the MS Windows handle
188 wxWindow *wxWindow::FindItemByHWND(WXHWND hWnd, bool controlOnly) const
189 {
190 wxWindowList::Node *current = GetChildren().GetFirst();
191 while (current)
192 {
193 wxWindow *parent = current->GetData();
194
195 // Do a recursive search.
196 wxWindow *wnd = parent->FindItemByHWND(hWnd);
197 if ( wnd )
198 return wnd;
199
200 if ( !controlOnly || parent->IsKindOf(CLASSINFO(wxControl)) )
201 {
202 wxWindow *item = current->GetData();
203 if ( item->GetHWND() == hWnd )
204 return item;
205 else
206 {
207 if ( item->ContainsHWND(hWnd) )
208 return item;
209 }
210 }
211
212 current = current->GetNext();
213 }
214 return NULL;
215 }
216
217 // Default command handler
218 bool wxWindow::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id))
219 {
220 return FALSE;
221 }
222
223 // ----------------------------------------------------------------------------
224 // constructors and such
225 // ----------------------------------------------------------------------------
226
227 void wxWindow::Init()
228 {
229 // generic
230 InitBase();
231
232 // MSW specific
233 m_doubleClickAllowed = 0;
234 m_winCaptured = FALSE;
235
236 m_isBeingDeleted = FALSE;
237 m_oldWndProc = 0;
238 m_useCtl3D = FALSE;
239 m_mouseInWindow = FALSE;
240
241 // wxWnd
242 m_hMenu = 0;
243
244 m_hWnd = 0;
245
246 // pass WM_GETDLGCODE to DefWindowProc()
247 m_lDlgCode = 0;
248
249 m_xThumbSize = 0;
250 m_yThumbSize = 0;
251 m_backgroundTransparent = FALSE;
252
253 // as all windows are created with WS_VISIBLE style...
254 m_isShown = TRUE;
255
256 #if wxUSE_MOUSEEVENT_HACK
257 m_lastMouseX =
258 m_lastMouseY = -1;
259 m_lastMouseEvent = -1;
260 #endif // wxUSE_MOUSEEVENT_HACK
261 }
262
263 // Destructor
264 wxWindow::~wxWindow()
265 {
266 m_isBeingDeleted = TRUE;
267
268 MSWDetachWindowMenu();
269
270 if ( m_parent )
271 m_parent->RemoveChild(this);
272
273 DestroyChildren();
274
275 if ( m_hWnd )
276 {
277 // VZ: test temp removed to understand what really happens here
278 //if (::IsWindow(GetHwnd()))
279 {
280 if ( !::DestroyWindow(GetHwnd()) )
281 wxLogLastError("DestroyWindow");
282 }
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(GetHcursorOf(m_cursor));
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 ( wxIsShiftDown() )
978 state |= MK_SHIFT;
979 if ( wxIsCtrlDown() )
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 = wxIsCtrlDown();
1487 bool bShiftDown = wxIsShiftDown();
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) && wxIsCtrlDown() )
1603 {
1604 // find the first notebook parent and change its page
1605 wxWindow *win = this;
1606 wxNotebook *nbook = NULL;
1607 while ( win && !nbook )
1608 {
1609 nbook = wxDynamicCast(win, wxNotebook);
1610 win = win->GetParent();
1611 }
1612
1613 if ( nbook )
1614 {
1615 bool forward = !wxIsShiftDown();
1616
1617 nbook->AdvanceSelection(forward);
1618 }
1619 }
1620 }
1621 }
1622 #endif // 0
1623
1624 if ( ::IsDialogMessage(GetHwnd(), msg) )
1625 return TRUE;
1626 }
1627
1628 #if wxUSE_TOOLTIPS
1629 if ( m_tooltip )
1630 {
1631 // relay mouse move events to the tooltip control
1632 MSG *msg = (MSG *)pMsg;
1633 if ( msg->message == WM_MOUSEMOVE )
1634 m_tooltip->RelayEvent(pMsg);
1635 }
1636 #endif // wxUSE_TOOLTIPS
1637
1638 return FALSE;
1639 }
1640
1641 bool wxWindow::MSWTranslateMessage(WXMSG* pMsg)
1642 {
1643 return m_acceleratorTable.Translate(this, pMsg);
1644 }
1645
1646 // ---------------------------------------------------------------------------
1647 // message params unpackers (different for Win16 and Win32)
1648 // ---------------------------------------------------------------------------
1649
1650 #ifdef __WIN32__
1651
1652 void wxWindow::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
1653 WORD *id, WXHWND *hwnd, WORD *cmd)
1654 {
1655 *id = LOWORD(wParam);
1656 *hwnd = (WXHWND)lParam;
1657 *cmd = HIWORD(wParam);
1658 }
1659
1660 void wxWindow::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
1661 WXWORD *state, WXWORD *minimized, WXHWND *hwnd)
1662 {
1663 *state = LOWORD(wParam);
1664 *minimized = HIWORD(wParam);
1665 *hwnd = (WXHWND)lParam;
1666 }
1667
1668 void wxWindow::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
1669 WXWORD *code, WXWORD *pos, WXHWND *hwnd)
1670 {
1671 *code = LOWORD(wParam);
1672 *pos = HIWORD(wParam);
1673 *hwnd = (WXHWND)lParam;
1674 }
1675
1676 void wxWindow::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
1677 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd)
1678 {
1679 *nCtlColor = CTLCOLOR_BTN;
1680 *hwnd = (WXHWND)lParam;
1681 *hdc = (WXHDC)wParam;
1682 }
1683
1684 void wxWindow::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
1685 WXWORD *item, WXWORD *flags, WXHMENU *hmenu)
1686 {
1687 *item = (WXWORD)wParam;
1688 *flags = HIWORD(wParam);
1689 *hmenu = (WXHMENU)lParam;
1690 }
1691
1692 #else // Win16
1693
1694 void wxWindow::UnpackCommand(WXWPARAM wParam, WXLPARAM lParam,
1695 WXWORD *id, WXHWND *hwnd, WXWORD *cmd)
1696 {
1697 *id = (WXWORD)wParam;
1698 *hwnd = (WXHWND)LOWORD(lParam);
1699 *cmd = HIWORD(lParam);
1700 }
1701
1702 void wxWindow::UnpackActivate(WXWPARAM wParam, WXLPARAM lParam,
1703 WXWORD *state, WXWORD *minimized, WXHWND *hwnd)
1704 {
1705 *state = (WXWORD)wParam;
1706 *minimized = LOWORD(lParam);
1707 *hwnd = (WXHWND)HIWORD(lParam);
1708 }
1709
1710 void wxWindow::UnpackScroll(WXWPARAM wParam, WXLPARAM lParam,
1711 WXWORD *code, WXWORD *pos, WXHWND *hwnd)
1712 {
1713 *code = (WXWORD)wParam;
1714 *pos = LOWORD(lParam);
1715 *hwnd = (WXHWND)HIWORD(lParam);
1716 }
1717
1718 void wxWindow::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
1719 WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd)
1720 {
1721 *hwnd = (WXHWND)LOWORD(lParam);
1722 *nCtlColor = (int)HIWORD(lParam);
1723 *hdc = (WXHDC)wParam;
1724 }
1725
1726 void wxWindow::UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam,
1727 WXWORD *item, WXWORD *flags, WXHMENU *hmenu)
1728 {
1729 *item = (WXWORD)wParam;
1730 *flags = LOWORD(lParam);
1731 *hmenu = (WXHMENU)HIWORD(lParam);
1732 }
1733
1734 #endif // Win32/16
1735
1736 // ---------------------------------------------------------------------------
1737 // Main wxWindows window proc and the window proc for wxWindow
1738 // ---------------------------------------------------------------------------
1739
1740 // Hook for new window just as it's being created, when the window isn't yet
1741 // associated with the handle
1742 wxWindow *wxWndHook = NULL;
1743
1744 // Main window proc
1745 LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1746 {
1747 // trace all messages - useful for the debugging
1748 #ifdef __WXDEBUG__
1749 wxLogTrace(wxTraceMessages, wxT("Processing %s(wParam=%8lx, lParam=%8lx)"),
1750 wxGetMessageName(message), wParam, lParam);
1751 #endif // __WXDEBUG__
1752
1753 wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd);
1754
1755 // when we get the first message for the HWND we just created, we associate
1756 // it with wxWindow stored in wxWndHook
1757 if ( !wnd && wxWndHook )
1758 {
1759 #if 0 // def __WXDEBUG__
1760 char buf[512];
1761 ::GetClassNameA((HWND) hWnd, buf, 512);
1762 wxString className(buf);
1763 #endif
1764
1765 wxAssociateWinWithHandle(hWnd, wxWndHook);
1766 wnd = wxWndHook;
1767 wxWndHook = NULL;
1768 wnd->SetHWND((WXHWND)hWnd);
1769 }
1770
1771 LRESULT rc;
1772
1773 // Stop right here if we don't have a valid handle in our wxWindow object.
1774 if ( wnd && !wnd->GetHWND() )
1775 {
1776 // FIXME: why do we do this?
1777 wnd->SetHWND((WXHWND) hWnd);
1778 rc = wnd->MSWDefWindowProc(message, wParam, lParam );
1779 wnd->SetHWND(0);
1780 }
1781 else
1782 {
1783 if ( wnd )
1784 rc = wnd->MSWWindowProc(message, wParam, lParam);
1785 else
1786 rc = DefWindowProc( hWnd, message, wParam, lParam );
1787 }
1788
1789 return rc;
1790 }
1791
1792 long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
1793 {
1794 // did we process the message?
1795 bool processed = FALSE;
1796
1797 // the return value
1798 union
1799 {
1800 bool allow;
1801 long result;
1802 WXHICON hIcon;
1803 WXHBRUSH hBrush;
1804 } rc;
1805
1806 // for most messages we should return 0 when we do process the message
1807 rc.result = 0;
1808
1809 switch ( message )
1810 {
1811 case WM_CREATE:
1812 {
1813 bool mayCreate;
1814 processed = HandleCreate((WXLPCREATESTRUCT)lParam, &mayCreate);
1815 if ( processed )
1816 {
1817 // return 0 to allow window creation
1818 rc.result = mayCreate ? 0 : -1;
1819 }
1820 }
1821 break;
1822
1823 case WM_DESTROY:
1824 processed = HandleDestroy();
1825 break;
1826
1827 case WM_MOVE:
1828 processed = HandleMove(LOWORD(lParam), HIWORD(lParam));
1829 break;
1830
1831 case WM_SIZE:
1832 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
1833 break;
1834
1835 case WM_ACTIVATE:
1836 {
1837 WXWORD state, minimized;
1838 WXHWND hwnd;
1839 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
1840
1841 processed = HandleActivate(state, minimized != 0, (WXHWND)hwnd);
1842 }
1843 break;
1844
1845 case WM_SETFOCUS:
1846 processed = HandleSetFocus((WXHWND)(HWND)wParam);
1847 break;
1848
1849 case WM_KILLFOCUS:
1850 processed = HandleKillFocus((WXHWND)(HWND)wParam);
1851 break;
1852
1853 case WM_PAINT:
1854 processed = HandlePaint();
1855 break;
1856
1857 case WM_CLOSE:
1858 // don't let the DefWindowProc() destroy our window - we'll do it
1859 // ourselves in ~wxWindow
1860 processed = TRUE;
1861 rc.result = TRUE;
1862 break;
1863
1864 case WM_SHOWWINDOW:
1865 processed = HandleShow(wParam != 0, (int)lParam);
1866 break;
1867
1868 case WM_MOUSEMOVE:
1869 {
1870 short x = LOWORD(lParam);
1871 short y = HIWORD(lParam);
1872
1873 processed = HandleMouseMove(x, y, wParam);
1874 }
1875 break;
1876
1877 case WM_LBUTTONDOWN:
1878 // set focus to this window
1879 SetFocus();
1880
1881 // fall through
1882
1883 case WM_LBUTTONUP:
1884 case WM_LBUTTONDBLCLK:
1885 case WM_RBUTTONDOWN:
1886 case WM_RBUTTONUP:
1887 case WM_RBUTTONDBLCLK:
1888 case WM_MBUTTONDOWN:
1889 case WM_MBUTTONUP:
1890 case WM_MBUTTONDBLCLK:
1891 {
1892 short x = LOWORD(lParam);
1893 short y = HIWORD(lParam);
1894
1895 processed = HandleMouseEvent(message, x, y, wParam);
1896 }
1897 break;
1898
1899 case MM_JOY1MOVE:
1900 case MM_JOY2MOVE:
1901 case MM_JOY1ZMOVE:
1902 case MM_JOY2ZMOVE:
1903 case MM_JOY1BUTTONDOWN:
1904 case MM_JOY2BUTTONDOWN:
1905 case MM_JOY1BUTTONUP:
1906 case MM_JOY2BUTTONUP:
1907 {
1908 int x = LOWORD(lParam);
1909 int y = HIWORD(lParam);
1910
1911 processed = HandleJoystickEvent(message, x, y, wParam);
1912 }
1913 break;
1914
1915 case WM_SYSCOMMAND:
1916 processed = HandleSysCommand(wParam, lParam);
1917 break;
1918
1919 case WM_COMMAND:
1920 {
1921 WORD id, cmd;
1922 WXHWND hwnd;
1923 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
1924
1925 processed = HandleCommand(id, cmd, hwnd);
1926 }
1927 break;
1928
1929 #ifdef __WIN95__
1930 case WM_NOTIFY:
1931 processed = HandleNotify((int)wParam, lParam, &rc.result);
1932 break;
1933 #endif // Win95
1934
1935 // for these messages we must return TRUE if process the message
1936 case WM_DRAWITEM:
1937 case WM_MEASUREITEM:
1938 {
1939 int idCtrl = (UINT)wParam;
1940 if ( message == WM_DRAWITEM )
1941 {
1942 processed = MSWOnDrawItem(idCtrl,
1943 (WXDRAWITEMSTRUCT *)lParam);
1944 }
1945 else
1946 {
1947 processed = MSWOnMeasureItem(idCtrl,
1948 (WXMEASUREITEMSTRUCT *)lParam);
1949 }
1950
1951 if ( processed )
1952 rc.result = TRUE;
1953 }
1954 break;
1955
1956 case WM_GETDLGCODE:
1957 if ( m_lDlgCode )
1958 {
1959 rc.result = m_lDlgCode;
1960 processed = TRUE;
1961 }
1962 //else: get the dlg code from the DefWindowProc()
1963 break;
1964
1965 case WM_SYSKEYDOWN:
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 WPARAM flags;
2008 int x, y;
2009
2010 TranslateKbdEventToMouse(this, &x, &y, &flags);
2011 processed = HandleMouseEvent(WM_RBUTTONDOWN, x, y, flags);
2012 }
2013 break;
2014 #endif // VK_APPS
2015
2016 case VK_LEFT:
2017 case VK_RIGHT:
2018 case VK_DOWN:
2019 case VK_UP:
2020 default:
2021 processed = HandleChar((WORD)wParam, lParam);
2022 }
2023 break;
2024
2025 case WM_SYSKEYUP:
2026 case WM_KEYUP:
2027 #ifdef VK_APPS
2028 // special case of VK_APPS: treat it the same as right mouse button
2029 if ( wParam == VK_APPS )
2030 {
2031 WPARAM flags;
2032 int x, y;
2033
2034 TranslateKbdEventToMouse(this, &x, &y, &flags);
2035 processed = HandleMouseEvent(WM_RBUTTONUP, x, y, flags);
2036 }
2037 else
2038 #endif // VK_APPS
2039 {
2040 processed = HandleKeyUp((WORD) wParam, lParam);
2041 }
2042 break;
2043
2044 case WM_SYSCHAR:
2045 case WM_CHAR: // Always an ASCII character
2046 processed = HandleChar((WORD)wParam, lParam, TRUE);
2047 break;
2048
2049 case WM_HSCROLL:
2050 case WM_VSCROLL:
2051 {
2052 WXWORD code, pos;
2053 WXHWND hwnd;
2054 UnpackScroll(wParam, lParam, &code, &pos, &hwnd);
2055
2056 processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL
2057 : wxVERTICAL,
2058 code, pos, hwnd);
2059 }
2060 break;
2061
2062 // CTLCOLOR messages are sent by children to query the parent for their
2063 // colors
2064 #ifdef __WIN32__
2065 case WM_CTLCOLORMSGBOX:
2066 case WM_CTLCOLOREDIT:
2067 case WM_CTLCOLORLISTBOX:
2068 case WM_CTLCOLORBTN:
2069 case WM_CTLCOLORDLG:
2070 case WM_CTLCOLORSCROLLBAR:
2071 case WM_CTLCOLORSTATIC:
2072 #else // Win16
2073 case WM_CTLCOLOR:
2074 #endif // Win32/16
2075 {
2076 WXWORD nCtlColor;
2077 WXHDC hdc;
2078 WXHWND hwnd;
2079 UnpackCtlColor(wParam, lParam, &nCtlColor, &hdc, &hwnd);
2080
2081 processed = HandleCtlColor(&rc.hBrush,
2082 (WXHDC)hdc,
2083 (WXHWND)hwnd,
2084 nCtlColor,
2085 message,
2086 wParam,
2087 lParam);
2088 }
2089 break;
2090
2091 // the return value for this message is ignored
2092 case WM_SYSCOLORCHANGE:
2093 processed = HandleSysColorChange();
2094 break;
2095
2096 case WM_PALETTECHANGED:
2097 processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
2098 break;
2099
2100 case WM_QUERYNEWPALETTE:
2101 processed = HandleQueryNewPalette();
2102 break;
2103
2104 case WM_ERASEBKGND:
2105 processed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
2106 if ( processed )
2107 {
2108 // we processed the message, i.e. erased the background
2109 rc.result = TRUE;
2110 }
2111 break;
2112
2113 case WM_DROPFILES:
2114 processed = HandleDropFiles(wParam);
2115 break;
2116
2117 case WM_INITDIALOG:
2118 processed = HandleInitDialog((WXHWND)(HWND)wParam);
2119
2120 if ( processed )
2121 {
2122 // we never set focus from here
2123 rc.result = FALSE;
2124 }
2125 break;
2126
2127 case WM_QUERYENDSESSION:
2128 processed = HandleQueryEndSession(lParam, &rc.allow);
2129 break;
2130
2131 case WM_ENDSESSION:
2132 processed = HandleEndSession(wParam != 0, lParam);
2133 break;
2134
2135 case WM_GETMINMAXINFO:
2136 processed = HandleGetMinMaxInfo((MINMAXINFO*)lParam);
2137 break;
2138
2139 case WM_SETCURSOR:
2140 processed = HandleSetCursor((WXHWND)(HWND)wParam,
2141 LOWORD(lParam), // hit test
2142 HIWORD(lParam)); // mouse msg
2143
2144 if ( processed )
2145 {
2146 // returning TRUE stops the DefWindowProc() from further
2147 // processing this message - exactly what we need because we've
2148 // just set the cursor.
2149 rc.result = TRUE;
2150 }
2151 break;
2152 }
2153
2154 if ( !processed )
2155 {
2156 #ifdef __WXDEBUG__
2157 wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."),
2158 wxGetMessageName(message));
2159 #endif // __WXDEBUG__
2160 rc.result = MSWDefWindowProc(message, wParam, lParam);
2161 }
2162
2163 return rc.result;
2164 }
2165
2166 // Dialog window proc
2167 LONG APIENTRY _EXPORT
2168 wxDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
2169 {
2170 if ( message == WM_INITDIALOG )
2171 {
2172 // for this message, returning TRUE tells system to set focus to the
2173 // first control in the dialog box
2174 return TRUE;
2175 }
2176 else
2177 {
2178 // for all the other ones, FALSE means that we didn't process the
2179 // message
2180 return 0;
2181 }
2182 }
2183
2184 wxList *wxWinHandleList = NULL;
2185 wxWindow *wxFindWinFromHandle(WXHWND hWnd)
2186 {
2187 wxNode *node = wxWinHandleList->Find((long)hWnd);
2188 if ( !node )
2189 return NULL;
2190 return (wxWindow *)node->Data();
2191 }
2192
2193 #if 0 // def __WXDEBUG__
2194 static int gs_AssociationCount = 0;
2195 #endif
2196
2197 void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win)
2198 {
2199 // adding NULL hWnd is (first) surely a result of an error and
2200 // (secondly) breaks menu command processing
2201 wxCHECK_RET( hWnd != (HWND)NULL,
2202 wxT("attempt to add a NULL hWnd to window list ignored") );
2203
2204
2205 wxWindow *oldWin = wxFindWinFromHandle((WXHWND) hWnd);
2206 if ( oldWin && (oldWin != win) )
2207 {
2208 wxString str(win->GetClassInfo()->GetClassName());
2209 wxLogError(wxT("Bug! Found existing HWND %X for new window of class %s"), (int) hWnd, (const wxChar*) str);
2210 }
2211 else if (!oldWin)
2212 {
2213 #if 0 // def __WXDEBUG__
2214 gs_AssociationCount ++;
2215 wxLogDebug("+ Association %d", gs_AssociationCount);
2216 #endif
2217
2218 wxWinHandleList->Append((long)hWnd, win);
2219 }
2220 }
2221
2222 void wxRemoveHandleAssociation(wxWindow *win)
2223 {
2224 #if 0 // def __WXDEBUG__
2225 if (wxWinHandleList->Member(win))
2226 {
2227 wxLogDebug("- Association %d", gs_AssociationCount);
2228 gs_AssociationCount --;
2229 }
2230 #endif
2231 wxWinHandleList->DeleteObject(win);
2232 }
2233
2234 // Default destroyer - override if you destroy it in some other way
2235 // (e.g. with MDI child windows)
2236 void wxWindow::MSWDestroyWindow()
2237 {
2238 }
2239
2240 void wxWindow::MSWDetachWindowMenu()
2241 {
2242 if ( m_hMenu )
2243 {
2244 HMENU hMenu = (HMENU)m_hMenu;
2245
2246 int N = ::GetMenuItemCount(hMenu);
2247 int i;
2248 for (i = 0; i < N; i++)
2249 {
2250 wxChar buf[100];
2251 int chars = GetMenuString(hMenu, i, buf, 100, MF_BYPOSITION);
2252 if ( !chars )
2253 {
2254 wxLogLastError(wxT("GetMenuString"));
2255
2256 continue;
2257 }
2258
2259 if ( wxStrcmp(buf, wxT("&Window")) == 0 )
2260 {
2261 RemoveMenu(hMenu, i, MF_BYPOSITION);
2262
2263 break;
2264 }
2265 }
2266 }
2267 }
2268
2269 bool wxWindow::MSWCreate(int id,
2270 wxWindow *parent,
2271 const wxChar *wclass,
2272 wxWindow *wx_win,
2273 const wxChar *title,
2274 int x,
2275 int y,
2276 int width,
2277 int height,
2278 WXDWORD style,
2279 const wxChar *dialog_template,
2280 WXDWORD extendedStyle)
2281 {
2282 int x1 = CW_USEDEFAULT;
2283 int y1 = 0;
2284 int width1 = CW_USEDEFAULT;
2285 int height1 = 100;
2286
2287 // Find parent's size, if it exists, to set up a possible default
2288 // panel size the size of the parent window
2289 RECT parent_rect;
2290 if ( parent )
2291 {
2292 ::GetClientRect((HWND) parent->GetHWND(), &parent_rect);
2293
2294 width1 = parent_rect.right - parent_rect.left;
2295 height1 = parent_rect.bottom - parent_rect.top;
2296 }
2297
2298 if ( x > -1 ) x1 = x;
2299 if ( y > -1 ) y1 = y;
2300 if ( width > -1 ) width1 = width;
2301 if ( height > -1 ) height1 = height;
2302
2303 // Unfortunately this won't work in WIN16. Unless perhaps
2304 // we define WS_EX_CONTROLPARENT ourselves?
2305 #ifndef __WIN16__
2306 // if we have wxTAB_TRAVERSAL style, we want WS_EX_CONTROLPARENT or
2307 // IsDialogMessage() won't work for us
2308 if ( GetWindowStyleFlag() & wxTAB_TRAVERSAL )
2309 {
2310 extendedStyle |= WS_EX_CONTROLPARENT;
2311 }
2312 #endif
2313
2314 HWND hParent = (HWND)NULL;
2315 if ( parent )
2316 hParent = (HWND) parent->GetHWND();
2317
2318 wxWndHook = this;
2319
2320 if ( dialog_template )
2321 {
2322 m_hWnd = (WXHWND)::CreateDialog(wxGetInstance(),
2323 dialog_template,
2324 hParent,
2325 (DLGPROC)wxDlgProc);
2326
2327 if ( m_hWnd == 0 )
2328 {
2329 wxLogError(_("Can't find dummy dialog template!\n"
2330 "Check resource include path for finding wx.rc."));
2331
2332 return FALSE;
2333 }
2334
2335 // ::SetWindowLong(GWL_EXSTYLE) doesn't work for the dialogs, so try
2336 // to take care of (at least some) extended style flags ourselves
2337 if ( extendedStyle & WS_EX_TOPMOST )
2338 {
2339 if ( !::SetWindowPos(GetHwnd(), HWND_TOPMOST, 0, 0, 0, 0,
2340 SWP_NOSIZE | SWP_NOMOVE) )
2341 {
2342 wxLogLastError(wxT("SetWindowPos"));
2343 }
2344 }
2345
2346 // move the dialog to its initial position without forcing repainting
2347 if ( !::MoveWindow(GetHwnd(), x1, y1, width1, height1, FALSE) )
2348 {
2349 wxLogLastError(wxT("MoveWindow"));
2350 }
2351 }
2352 else
2353 {
2354 int controlId = 0;
2355 if ( style & WS_CHILD )
2356 controlId = id;
2357
2358 wxString className(wclass);
2359 if ( GetWindowStyleFlag() & wxNO_FULL_REPAINT_ON_RESIZE )
2360 {
2361 className += wxT("NR");
2362 }
2363
2364 m_hWnd = (WXHWND)CreateWindowEx(extendedStyle,
2365 className,
2366 title ? title : wxT(""),
2367 style,
2368 x1, y1,
2369 width1, height1,
2370 hParent, (HMENU)controlId,
2371 wxGetInstance(),
2372 NULL);
2373
2374 if ( !m_hWnd )
2375 {
2376 wxLogError(_("Can't create window of class %s!\n"
2377 "Possible Windows 3.x compatibility problem?"),
2378 wclass);
2379
2380 return FALSE;
2381 }
2382 }
2383
2384 wxWndHook = NULL;
2385 #ifdef __WXDEBUG__
2386 wxNode* node = wxWinHandleList->Member(this);
2387 if (node)
2388 {
2389 HWND hWnd = (HWND) node->GetKeyInteger();
2390 if (hWnd != (HWND) m_hWnd)
2391 {
2392 wxLogError(wxT("A second HWND association is being added for the same window!"));
2393 }
2394 }
2395 #endif
2396 wxAssociateWinWithHandle((HWND) m_hWnd, this);
2397
2398 return TRUE;
2399 }
2400
2401 // ===========================================================================
2402 // MSW message handlers
2403 // ===========================================================================
2404
2405 // ---------------------------------------------------------------------------
2406 // WM_NOTIFY
2407 // ---------------------------------------------------------------------------
2408
2409 #ifdef __WIN95__
2410 // FIXME: VZ: I'm not sure at all that the order of processing is correct
2411 bool wxWindow::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
2412 {
2413 LPNMHDR hdr = (LPNMHDR)lParam;
2414 HWND hWnd = hdr->hwndFrom;
2415 wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd);
2416
2417 // is this one of our windows?
2418 if ( win )
2419 {
2420 return win->MSWOnNotify(idCtrl, lParam, result);
2421 }
2422
2423 // try all our children
2424 wxWindowList::Node *node = GetChildren().GetFirst();
2425 while ( node )
2426 {
2427 wxWindow *child = node->GetData();
2428 if ( child->MSWOnNotify(idCtrl, lParam, result) )
2429 {
2430 return TRUE;
2431
2432 break;
2433 }
2434
2435 node = node->GetNext();
2436 }
2437
2438 // finally try this window too (catches toolbar case)
2439 return MSWOnNotify(idCtrl, lParam, result);
2440 }
2441
2442 bool wxWindow::MSWOnNotify(int WXUNUSED(idCtrl),
2443 WXLPARAM lParam,
2444 WXLPARAM* WXUNUSED(result))
2445 {
2446 #if wxUSE_TOOLTIPS
2447 NMHDR* hdr = (NMHDR *)lParam;
2448 if ( (int)hdr->code == TTN_NEEDTEXT && m_tooltip )
2449 {
2450 TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
2451 ttt->lpszText = (wxChar *)m_tooltip->GetTip().c_str();
2452
2453 // processed
2454 return TRUE;
2455 }
2456 #endif // wxUSE_TOOLTIPS
2457
2458 return FALSE;
2459 }
2460 #endif // __WIN95__
2461
2462 // ---------------------------------------------------------------------------
2463 // end session messages
2464 // ---------------------------------------------------------------------------
2465
2466 bool wxWindow::HandleQueryEndSession(long logOff, bool *mayEnd)
2467 {
2468 wxCloseEvent event(wxEVT_QUERY_END_SESSION, -1);
2469 event.SetEventObject(wxTheApp);
2470 event.SetCanVeto(TRUE);
2471 event.SetLoggingOff(logOff == (long)ENDSESSION_LOGOFF);
2472
2473 bool rc = wxTheApp->ProcessEvent(event);
2474
2475 if ( rc )
2476 {
2477 // we may end only if the app didn't veto session closing (double
2478 // negation...)
2479 *mayEnd = !event.GetVeto();
2480 }
2481
2482 return rc;
2483 }
2484
2485 bool wxWindow::HandleEndSession(bool endSession, long logOff)
2486 {
2487 // do nothing if the session isn't ending
2488 if ( !endSession )
2489 return FALSE;
2490
2491 wxCloseEvent event(wxEVT_END_SESSION, -1);
2492 event.SetEventObject(wxTheApp);
2493 event.SetCanVeto(FALSE);
2494 event.SetLoggingOff( (logOff == (long)ENDSESSION_LOGOFF) );
2495 if ( (this == wxTheApp->GetTopWindow()) && // Only send once
2496 wxTheApp->ProcessEvent(event))
2497 {
2498 }
2499 return TRUE;
2500 }
2501
2502 // ---------------------------------------------------------------------------
2503 // window creation/destruction
2504 // ---------------------------------------------------------------------------
2505
2506 bool wxWindow::HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate)
2507 {
2508 // TODO: should generate this event from WM_NCCREATE
2509 wxWindowCreateEvent event(this);
2510 (void)GetEventHandler()->ProcessEvent(event);
2511
2512 *mayCreate = TRUE;
2513
2514 return TRUE;
2515 }
2516
2517 bool wxWindow::HandleDestroy()
2518 {
2519 wxWindowDestroyEvent event(this);
2520 (void)GetEventHandler()->ProcessEvent(event);
2521
2522 // delete our drop target if we've got one
2523 #if wxUSE_DRAG_AND_DROP
2524 if ( m_dropTarget != NULL )
2525 {
2526 m_dropTarget->Revoke(m_hWnd);
2527
2528 delete m_dropTarget;
2529 m_dropTarget = NULL;
2530 }
2531 #endif // wxUSE_DRAG_AND_DROP
2532
2533 // WM_DESTROY handled
2534 return TRUE;
2535 }
2536
2537 // ---------------------------------------------------------------------------
2538 // activation/focus
2539 // ---------------------------------------------------------------------------
2540
2541 void wxWindow::OnSetFocus(wxFocusEvent& event)
2542 {
2543 // panel wants to track the window which was the last to have focus in it,
2544 // so we want to set ourselves as the window which last had focus
2545 //
2546 // notice that it's also important to do it upwards the tree becaus
2547 // otherwise when the top level panel gets focus, it won't set it back to
2548 // us, but to some other sibling
2549 wxWindow *win = this;
2550 while ( win )
2551 {
2552 wxWindow *parent = win->GetParent();
2553 wxPanel *panel = wxDynamicCast(parent, wxPanel);
2554 if ( panel )
2555 {
2556 panel->SetLastFocus(win);
2557 }
2558
2559 win = parent;
2560 }
2561
2562 wxLogTrace(_T("focus"), _T("%s (0x%08x) gets focus"),
2563 GetClassInfo()->GetClassName(), GetHandle());
2564
2565 event.Skip();
2566 }
2567
2568 bool wxWindow::HandleActivate(int state,
2569 bool WXUNUSED(minimized),
2570 WXHWND WXUNUSED(activate))
2571 {
2572 wxActivateEvent event(wxEVT_ACTIVATE,
2573 (state == WA_ACTIVE) || (state == WA_CLICKACTIVE),
2574 m_windowId);
2575 event.SetEventObject(this);
2576
2577 return GetEventHandler()->ProcessEvent(event);
2578 }
2579
2580 bool wxWindow::HandleSetFocus(WXHWND WXUNUSED(hwnd))
2581 {
2582 #if wxUSE_CARET
2583 // Deal with caret
2584 if ( m_caret )
2585 {
2586 m_caret->OnSetFocus();
2587 }
2588 #endif // wxUSE_CARET
2589
2590 wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
2591 event.SetEventObject(this);
2592
2593 return GetEventHandler()->ProcessEvent(event);
2594 }
2595
2596 bool wxWindow::HandleKillFocus(WXHWND WXUNUSED(hwnd))
2597 {
2598 #if wxUSE_CARET
2599 // Deal with caret
2600 if ( m_caret )
2601 {
2602 m_caret->OnKillFocus();
2603 }
2604 #endif // wxUSE_CARET
2605
2606 wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId);
2607 event.SetEventObject(this);
2608
2609 return GetEventHandler()->ProcessEvent(event);
2610 }
2611
2612 // ---------------------------------------------------------------------------
2613 // miscellaneous
2614 // ---------------------------------------------------------------------------
2615
2616 bool wxWindow::HandleShow(bool show, int status)
2617 {
2618 wxShowEvent event(GetId(), show);
2619 event.m_eventObject = this;
2620
2621 return GetEventHandler()->ProcessEvent(event);
2622 }
2623
2624 bool wxWindow::HandleInitDialog(WXHWND WXUNUSED(hWndFocus))
2625 {
2626 wxInitDialogEvent event(GetId());
2627 event.m_eventObject = this;
2628
2629 return GetEventHandler()->ProcessEvent(event);
2630 }
2631
2632 bool wxWindow::HandleDropFiles(WXWPARAM wParam)
2633 {
2634 HDROP hFilesInfo = (HDROP) wParam;
2635 POINT dropPoint;
2636 DragQueryPoint(hFilesInfo, (LPPOINT) &dropPoint);
2637
2638 // Get the total number of files dropped
2639 WORD gwFilesDropped = (WORD)DragQueryFile ((HDROP)hFilesInfo,
2640 (UINT)-1,
2641 (LPSTR)0,
2642 (UINT)0);
2643
2644 wxString *files = new wxString[gwFilesDropped];
2645 int wIndex;
2646 for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++)
2647 {
2648 DragQueryFile (hFilesInfo, wIndex, (LPTSTR) wxBuffer, 1000);
2649 files[wIndex] = wxBuffer;
2650 }
2651 DragFinish (hFilesInfo);
2652
2653 wxDropFilesEvent event(wxEVT_DROP_FILES, gwFilesDropped, files);
2654 event.m_eventObject = this;
2655 event.m_pos.x = dropPoint.x; event.m_pos.x = dropPoint.y;
2656
2657 bool rc = GetEventHandler()->ProcessEvent(event);
2658
2659 delete[] files;
2660
2661 return rc;
2662 }
2663
2664 bool wxWindow::HandleSetCursor(WXHWND hWnd,
2665 short nHitTest,
2666 int WXUNUSED(mouseMsg))
2667 {
2668 // the logic is as follows:
2669 // 1. if we have the cursor set it unless wxIsBusy()
2670 // 2. if we're a top level window, set some cursor anyhow
2671 // 3. if wxIsBusy(), set the busy cursor, otherwise the global one
2672
2673 HCURSOR hcursor = 0;
2674 bool isBusy = wxIsBusy();
2675 if ( m_cursor.Ok() )
2676 {
2677 hcursor = GetHcursorOf(m_cursor);
2678 }
2679
2680 if ( !GetParent() )
2681 {
2682 if ( isBusy )
2683 {
2684 hcursor = wxGetCurrentBusyCursor();
2685 }
2686 else if ( !hcursor )
2687 {
2688 const wxCursor *cursor = wxGetGlobalCursor();
2689 if ( cursor && cursor->Ok() )
2690 {
2691 hcursor = GetHcursorOf(*cursor);
2692 }
2693 }
2694 }
2695
2696 if ( hcursor )
2697 {
2698 ::SetCursor(hcursor);
2699
2700 // cursor set, stop here
2701 return TRUE;
2702 }
2703 else
2704 {
2705 // pass up the window chain
2706 return FALSE;
2707 }
2708 }
2709
2710 // ---------------------------------------------------------------------------
2711 // owner drawn stuff
2712 // ---------------------------------------------------------------------------
2713
2714 bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
2715 {
2716 #if wxUSE_OWNER_DRAWN
2717 // is it a menu item?
2718 if ( id == 0 )
2719 {
2720 DRAWITEMSTRUCT *pDrawStruct = (DRAWITEMSTRUCT *)itemStruct;
2721 wxMenuItem *pMenuItem = (wxMenuItem *)(pDrawStruct->itemData);
2722
2723 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
2724
2725 // prepare to call OnDrawItem()
2726 wxDC dc;
2727 dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE);
2728 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
2729 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
2730 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
2731
2732 return pMenuItem->OnDrawItem
2733 (
2734 dc, rect,
2735 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
2736 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
2737 );
2738 }
2739
2740 wxWindow *item = FindItem(id);
2741 if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
2742 {
2743 return ((wxControl *)item)->MSWOnDraw(itemStruct);
2744 }
2745 #endif // USE_OWNER_DRAWN
2746
2747 return FALSE;
2748 }
2749
2750 bool wxWindow::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
2751 {
2752 #if wxUSE_OWNER_DRAWN
2753 // is it a menu item?
2754 if ( id == 0 )
2755 {
2756 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
2757 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
2758
2759 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
2760
2761 return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth,
2762 &pMeasureStruct->itemHeight);
2763 }
2764
2765 wxWindow *item = FindItem(id);
2766 if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
2767 {
2768 return ((wxControl *)item)->MSWOnMeasure(itemStruct);
2769 }
2770 #endif // owner-drawn menus
2771 return FALSE;
2772 }
2773
2774 // ---------------------------------------------------------------------------
2775 // colours and palettes
2776 // ---------------------------------------------------------------------------
2777
2778 bool wxWindow::HandleSysColorChange()
2779 {
2780 wxSysColourChangedEvent event;
2781 event.SetEventObject(this);
2782
2783 return GetEventHandler()->ProcessEvent(event);
2784 }
2785
2786 bool wxWindow::HandleCtlColor(WXHBRUSH *brush,
2787 WXHDC pDC,
2788 WXHWND pWnd,
2789 WXUINT nCtlColor,
2790 WXUINT message,
2791 WXWPARAM wParam,
2792 WXLPARAM lParam)
2793 {
2794 WXHBRUSH hBrush = 0;
2795
2796 if ( nCtlColor == CTLCOLOR_DLG )
2797 {
2798 hBrush = OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2799 }
2800 else
2801 {
2802 wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE);
2803 if ( item )
2804 hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam);
2805 }
2806
2807 if ( hBrush )
2808 *brush = hBrush;
2809
2810 return hBrush != 0;
2811 }
2812
2813 // Define for each class of dialog and control
2814 WXHBRUSH wxWindow::OnCtlColor(WXHDC hDC,
2815 WXHWND hWnd,
2816 WXUINT nCtlColor,
2817 WXUINT message,
2818 WXWPARAM wParam,
2819 WXLPARAM lParam)
2820 {
2821 return (WXHBRUSH)0;
2822 }
2823
2824 bool wxWindow::HandlePaletteChanged(WXHWND hWndPalChange)
2825 {
2826 wxPaletteChangedEvent event(GetId());
2827 event.SetEventObject(this);
2828 event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
2829
2830 return GetEventHandler()->ProcessEvent(event);
2831 }
2832
2833 bool wxWindow::HandleQueryNewPalette()
2834 {
2835 wxQueryNewPaletteEvent event(GetId());
2836 event.SetEventObject(this);
2837
2838 return GetEventHandler()->ProcessEvent(event) && event.GetPaletteRealized();
2839 }
2840
2841 // Responds to colour changes: passes event on to children.
2842 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
2843 {
2844 wxNode *node = GetChildren().First();
2845 while ( node )
2846 {
2847 // Only propagate to non-top-level windows
2848 wxWindow *win = (wxWindow *)node->Data();
2849 if ( win->GetParent() )
2850 {
2851 wxSysColourChangedEvent event2;
2852 event.m_eventObject = win;
2853 win->GetEventHandler()->ProcessEvent(event2);
2854 }
2855
2856 node = node->Next();
2857 }
2858 }
2859
2860 // ---------------------------------------------------------------------------
2861 // painting
2862 // ---------------------------------------------------------------------------
2863
2864 bool wxWindow::HandlePaint()
2865 {
2866 #ifdef __WIN32__
2867 HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle
2868 if ( !hRegion )
2869 wxLogLastError("CreateRectRgn");
2870 if ( ::GetUpdateRgn(GetHwnd(), hRegion, FALSE) == ERROR )
2871 wxLogLastError("GetUpdateRgn");
2872
2873 m_updateRegion = wxRegion((WXHRGN) hRegion);
2874 #else
2875 RECT updateRect;
2876 ::GetUpdateRect(GetHwnd(), & updateRect, FALSE);
2877
2878 m_updateRegion = wxRegion(updateRect.left, updateRect.top,
2879 updateRect.right - updateRect.left,
2880 updateRect.bottom - updateRect.top);
2881 #endif
2882
2883 wxPaintEvent event(m_windowId);
2884 event.SetEventObject(this);
2885
2886 return GetEventHandler()->ProcessEvent(event);
2887 }
2888
2889 bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
2890 {
2891 // Prevents flicker when dragging
2892 if ( ::IsIconic(GetHwnd()) )
2893 return TRUE;
2894
2895 wxDC dc;
2896
2897 dc.SetHDC(hdc);
2898 dc.SetWindow(this);
2899 dc.BeginDrawing();
2900
2901 wxEraseEvent event(m_windowId, &dc);
2902 event.SetEventObject(this);
2903 bool rc = GetEventHandler()->ProcessEvent(event);
2904
2905 dc.EndDrawing();
2906 dc.SelectOldObjects(hdc);
2907 dc.SetHDC((WXHDC) NULL);
2908
2909 return rc;
2910 }
2911
2912 void wxWindow::OnEraseBackground(wxEraseEvent& event)
2913 {
2914 RECT rect;
2915 ::GetClientRect(GetHwnd(), &rect);
2916
2917 COLORREF ref = PALETTERGB(m_backgroundColour.Red(),
2918 m_backgroundColour.Green(),
2919 m_backgroundColour.Blue());
2920 HBRUSH hBrush = ::CreateSolidBrush(ref);
2921 if ( !hBrush )
2922 wxLogLastError("CreateSolidBrush");
2923
2924 HDC hdc = (HDC)event.GetDC()->GetHDC();
2925
2926 int mode = ::SetMapMode(hdc, MM_TEXT);
2927
2928 ::FillRect(hdc, &rect, hBrush);
2929 ::DeleteObject(hBrush);
2930 ::SetMapMode(hdc, mode);
2931 }
2932
2933 // ---------------------------------------------------------------------------
2934 // moving and resizing
2935 // ---------------------------------------------------------------------------
2936
2937 bool wxWindow::HandleMinimize()
2938 {
2939 wxIconizeEvent event(m_windowId);
2940 event.SetEventObject(this);
2941
2942 return GetEventHandler()->ProcessEvent(event);
2943 }
2944
2945 bool wxWindow::HandleMaximize()
2946 {
2947 wxMaximizeEvent event(m_windowId);
2948 event.SetEventObject(this);
2949
2950 return GetEventHandler()->ProcessEvent(event);
2951 }
2952
2953 bool wxWindow::HandleMove(int x, int y)
2954 {
2955 wxMoveEvent event(wxPoint(x, y), m_windowId);
2956 event.SetEventObject(this);
2957
2958 return GetEventHandler()->ProcessEvent(event);
2959 }
2960
2961 bool wxWindow::HandleSize(int w, int h, WXUINT WXUNUSED(flag))
2962 {
2963 wxSizeEvent event(wxSize(w, h), m_windowId);
2964 event.SetEventObject(this);
2965
2966 return GetEventHandler()->ProcessEvent(event);
2967 }
2968
2969 bool wxWindow::HandleGetMinMaxInfo(void *mmInfo)
2970 {
2971 MINMAXINFO *info = (MINMAXINFO *)mmInfo;
2972
2973 bool rc = FALSE;
2974
2975 if ( m_minWidth != -1 )
2976 {
2977 info->ptMinTrackSize.x = m_minWidth;
2978 rc = TRUE;
2979 }
2980
2981 if ( m_minHeight != -1 )
2982 {
2983 info->ptMinTrackSize.y = m_minHeight;
2984 rc = TRUE;
2985 }
2986
2987 if ( m_maxWidth != -1 )
2988 {
2989 info->ptMaxTrackSize.x = m_maxWidth;
2990 rc = TRUE;
2991 }
2992
2993 if ( m_maxHeight != -1 )
2994 {
2995 info->ptMaxTrackSize.y = m_maxHeight;
2996 rc = TRUE;
2997 }
2998
2999 return rc;
3000 }
3001
3002 // ---------------------------------------------------------------------------
3003 // command messages
3004 // ---------------------------------------------------------------------------
3005
3006 bool wxWindow::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
3007 {
3008 if ( wxCurrentPopupMenu )
3009 {
3010 wxMenu *popupMenu = wxCurrentPopupMenu;
3011 wxCurrentPopupMenu = NULL;
3012
3013 return popupMenu->MSWCommand(cmd, id);
3014 }
3015
3016 wxWindow *win = (wxWindow*) NULL;
3017 if ( cmd == 0 || cmd == 1 ) // menu or accel - use id
3018 {
3019 // must cast to a signed type before comparing with other ids!
3020 win = FindItem((signed short)id);
3021 }
3022
3023 if (!win && control)
3024 {
3025 // find it from HWND - this works even with the broken programs using
3026 // the same ids for different controls
3027 win = wxFindWinFromHandle(control);
3028 }
3029
3030 if ( win )
3031 {
3032 return win->MSWCommand(cmd, id);
3033 }
3034
3035 // the messages sent from the in-place edit control used by the treectrl
3036 // for label editing have id == 0, but they should _not_ be treated as menu
3037 // messages (they are EN_XXX ones, in fact) so don't translate anything
3038 // coming from a control to wxEVT_COMMAND_MENU_SELECTED
3039 if ( !control )
3040 {
3041 // If no child window, it may be an accelerator, e.g. for a popup menu
3042 // command
3043
3044 wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED);
3045 event.SetEventObject(this);
3046 event.SetId(id);
3047 event.SetInt(id);
3048
3049 return GetEventHandler()->ProcessEvent(event);
3050 }
3051
3052 return FALSE;
3053 }
3054
3055 bool wxWindow::HandleSysCommand(WXWPARAM wParam, WXLPARAM lParam)
3056 {
3057 // 4 bits are reserved
3058 switch ( wParam & 0xFFFFFFF0 )
3059 {
3060 case SC_MAXIMIZE:
3061 return HandleMaximize();
3062
3063 case SC_MINIMIZE:
3064 return HandleMinimize();
3065 }
3066
3067 return FALSE;
3068 }
3069
3070 // ---------------------------------------------------------------------------
3071 // mouse events
3072 // ---------------------------------------------------------------------------
3073
3074 void wxWindow::InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags)
3075 {
3076 event.m_x = x;
3077 event.m_y = y;
3078 event.m_shiftDown = ((flags & MK_SHIFT) != 0);
3079 event.m_controlDown = ((flags & MK_CONTROL) != 0);
3080 event.m_leftDown = ((flags & MK_LBUTTON) != 0);
3081 event.m_middleDown = ((flags & MK_MBUTTON) != 0);
3082 event.m_rightDown = ((flags & MK_RBUTTON) != 0);
3083 event.SetTimestamp(s_currentMsg.time);
3084 event.m_eventObject = this;
3085
3086 #if wxUSE_MOUSEEVENT_HACK
3087 m_lastMouseX = x;
3088 m_lastMouseY = y;
3089 m_lastMouseEvent = event.GetEventType();
3090 #endif // wxUSE_MOUSEEVENT_HACK
3091
3092 }
3093
3094 bool wxWindow::HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags)
3095 {
3096 // the mouse events take consecutive IDs from WM_MOUSEFIRST to
3097 // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST
3098 // from the message id and take the value in the table to get wxWin event
3099 // id
3100 static const wxEventType eventsMouse[] =
3101 {
3102 wxEVT_MOTION,
3103 wxEVT_LEFT_DOWN,
3104 wxEVT_LEFT_UP,
3105 wxEVT_LEFT_DCLICK,
3106 wxEVT_RIGHT_DOWN,
3107 wxEVT_RIGHT_UP,
3108 wxEVT_RIGHT_DCLICK,
3109 wxEVT_MIDDLE_DOWN,
3110 wxEVT_MIDDLE_UP,
3111 wxEVT_MIDDLE_DCLICK
3112 };
3113
3114 wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]);
3115 InitMouseEvent(event, x, y, flags);
3116
3117 return GetEventHandler()->ProcessEvent(event);
3118 }
3119
3120 bool wxWindow::HandleMouseMove(int x, int y, WXUINT flags)
3121 {
3122 if ( !m_mouseInWindow )
3123 {
3124 // Generate an ENTER event
3125 m_mouseInWindow = TRUE;
3126
3127 wxMouseEvent event(wxEVT_ENTER_WINDOW);
3128 InitMouseEvent(event, x, y, flags);
3129
3130 (void)GetEventHandler()->ProcessEvent(event);
3131 }
3132
3133 #if wxUSE_MOUSEEVENT_HACK
3134 // Window gets a click down message followed by a mouse move message even
3135 // if position isn't changed! We want to discard the trailing move event
3136 // if x and y are the same.
3137 if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN ||
3138 m_lastMouseEvent == wxEVT_LEFT_DOWN ||
3139 m_lastMouseEvent == wxEVT_MIDDLE_DOWN) &&
3140 (m_lastMouseX == event.m_x && m_lastMouseY == event.m_y) )
3141 {
3142 m_lastMouseEvent = wxEVT_MOTION;
3143
3144 return FALSE;
3145 }
3146 #endif // wxUSE_MOUSEEVENT_HACK
3147
3148 return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags);
3149 }
3150
3151 // ---------------------------------------------------------------------------
3152 // keyboard handling
3153 // ---------------------------------------------------------------------------
3154
3155 // create the key event of the given type for the given key - used by
3156 // HandleChar and HandleKeyDown/Up
3157 wxKeyEvent wxWindow::CreateKeyEvent(wxEventType evType,
3158 int id,
3159 WXLPARAM lParam) const
3160 {
3161 wxKeyEvent event(evType);
3162 event.SetId(GetId());
3163 event.m_shiftDown = wxIsShiftDown();
3164 event.m_controlDown = wxIsCtrlDown();
3165 event.m_altDown = (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN;
3166
3167 event.m_eventObject = (wxWindow *)this; // const_cast
3168 event.m_keyCode = id;
3169 event.SetTimestamp(s_currentMsg.time);
3170
3171 // translate the position to client coords
3172 POINT pt;
3173 GetCursorPos(&pt);
3174 RECT rect;
3175 GetWindowRect(GetHwnd(),&rect);
3176 pt.x -= rect.left;
3177 pt.y -= rect.top;
3178
3179 event.m_x = pt.x;
3180 event.m_y = pt.y;
3181
3182 return event;
3183 }
3184
3185 // isASCII is TRUE only when we're called from WM_CHAR handler and not from
3186 // WM_KEYDOWN one
3187 bool wxWindow::HandleChar(WXWORD wParam, WXLPARAM lParam, bool isASCII)
3188 {
3189 bool ctrlDown = FALSE;
3190
3191 int id;
3192 if ( isASCII )
3193 {
3194 // If 1 -> 26, translate to CTRL plus a letter.
3195 id = wParam;
3196 if ( (id > 0) && (id < 27) )
3197 {
3198 switch (id)
3199 {
3200 case 13:
3201 id = WXK_RETURN;
3202 break;
3203
3204 case 8:
3205 id = WXK_BACK;
3206 break;
3207
3208 case 9:
3209 id = WXK_TAB;
3210 break;
3211
3212 default:
3213 ctrlDown = TRUE;
3214 id = id + 96;
3215 }
3216 }
3217 }
3218 else if ( (id = wxCharCodeMSWToWX(wParam)) == 0 )
3219 {
3220 // it's ASCII and will be processed here only when called from
3221 // WM_CHAR (i.e. when isASCII = TRUE), don't process it now
3222 id = -1;
3223 }
3224
3225 if ( id != -1 )
3226 {
3227 wxKeyEvent event(CreateKeyEvent(wxEVT_CHAR, id, lParam));
3228 if ( ctrlDown )
3229 {
3230 event.m_controlDown = TRUE;
3231 }
3232
3233 if ( GetEventHandler()->ProcessEvent(event) )
3234 return TRUE;
3235 }
3236
3237 return FALSE;
3238 }
3239
3240 bool wxWindow::HandleKeyDown(WXWORD wParam, WXLPARAM lParam)
3241 {
3242 int id = wxCharCodeMSWToWX(wParam);
3243
3244 if ( !id )
3245 {
3246 // normal ASCII char
3247 id = wParam;
3248 }
3249
3250 if ( id != -1 ) // VZ: does this ever happen (FIXME)?
3251 {
3252 wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_DOWN, id, lParam));
3253 if ( GetEventHandler()->ProcessEvent(event) )
3254 {
3255 return TRUE;
3256 }
3257 }
3258
3259 return FALSE;
3260 }
3261
3262 bool wxWindow::HandleKeyUp(WXWORD wParam, WXLPARAM lParam)
3263 {
3264 int id = wxCharCodeMSWToWX(wParam);
3265
3266 if ( !id )
3267 {
3268 // normal ASCII char
3269 id = wParam;
3270 }
3271
3272 if ( id != -1 ) // VZ: does this ever happen (FIXME)?
3273 {
3274 wxKeyEvent event(CreateKeyEvent(wxEVT_KEY_UP, id, lParam));
3275 if ( GetEventHandler()->ProcessEvent(event) )
3276 return TRUE;
3277 }
3278
3279 return FALSE;
3280 }
3281
3282 // ---------------------------------------------------------------------------
3283 // joystick
3284 // ---------------------------------------------------------------------------
3285
3286 bool wxWindow::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags)
3287 {
3288 int change = 0;
3289 if ( flags & JOY_BUTTON1CHG )
3290 change = wxJOY_BUTTON1;
3291 if ( flags & JOY_BUTTON2CHG )
3292 change = wxJOY_BUTTON2;
3293 if ( flags & JOY_BUTTON3CHG )
3294 change = wxJOY_BUTTON3;
3295 if ( flags & JOY_BUTTON4CHG )
3296 change = wxJOY_BUTTON4;
3297
3298 int buttons = 0;
3299 if ( flags & JOY_BUTTON1 )
3300 buttons |= wxJOY_BUTTON1;
3301 if ( flags & JOY_BUTTON2 )
3302 buttons |= wxJOY_BUTTON2;
3303 if ( flags & JOY_BUTTON3 )
3304 buttons |= wxJOY_BUTTON3;
3305 if ( flags & JOY_BUTTON4 )
3306 buttons |= wxJOY_BUTTON4;
3307
3308 // the event ids aren't consecutive so we can't use table based lookup
3309 int joystick;
3310 wxEventType eventType;
3311 switch ( msg )
3312 {
3313 case MM_JOY1MOVE:
3314 joystick = 1;
3315 eventType = wxEVT_JOY_MOVE;
3316 break;
3317
3318 case MM_JOY2MOVE:
3319 joystick = 2;
3320 eventType = wxEVT_JOY_MOVE;
3321 break;
3322
3323 case MM_JOY1ZMOVE:
3324 joystick = 1;
3325 eventType = wxEVT_JOY_ZMOVE;
3326 break;
3327
3328 case MM_JOY2ZMOVE:
3329 joystick = 2;
3330 eventType = wxEVT_JOY_ZMOVE;
3331 break;
3332
3333 case MM_JOY1BUTTONDOWN:
3334 joystick = 1;
3335 eventType = wxEVT_JOY_BUTTON_DOWN;
3336 break;
3337
3338 case MM_JOY2BUTTONDOWN:
3339 joystick = 2;
3340 eventType = wxEVT_JOY_BUTTON_DOWN;
3341 break;
3342
3343 case MM_JOY1BUTTONUP:
3344 joystick = 1;
3345 eventType = wxEVT_JOY_BUTTON_UP;
3346 break;
3347
3348 case MM_JOY2BUTTONUP:
3349 joystick = 2;
3350 eventType = wxEVT_JOY_BUTTON_UP;
3351 break;
3352
3353 default:
3354 wxFAIL_MSG(wxT("no such joystick event"));
3355
3356 return FALSE;
3357 }
3358
3359 wxJoystickEvent event(eventType, buttons, joystick, change);
3360 event.SetPosition(wxPoint(x, y));
3361 event.SetEventObject(this);
3362
3363 return GetEventHandler()->ProcessEvent(event);
3364 }
3365
3366 // ---------------------------------------------------------------------------
3367 // scrolling
3368 // ---------------------------------------------------------------------------
3369
3370 bool wxWindow::MSWOnScroll(int orientation, WXWORD wParam,
3371 WXWORD pos, WXHWND control)
3372 {
3373 if ( control )
3374 {
3375 wxWindow *child = wxFindWinFromHandle(control);
3376 if ( child )
3377 return child->MSWOnScroll(orientation, wParam, pos, control);
3378 }
3379
3380 wxScrollWinEvent event;
3381 event.SetPosition(pos);
3382 event.SetOrientation(orientation);
3383 event.m_eventObject = this;
3384
3385 switch ( wParam )
3386 {
3387 case SB_TOP:
3388 event.m_eventType = wxEVT_SCROLLWIN_TOP;
3389 break;
3390
3391 case SB_BOTTOM:
3392 event.m_eventType = wxEVT_SCROLLWIN_BOTTOM;
3393 break;
3394
3395 case SB_LINEUP:
3396 event.m_eventType = wxEVT_SCROLLWIN_LINEUP;
3397 break;
3398
3399 case SB_LINEDOWN:
3400 event.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
3401 break;
3402
3403 case SB_PAGEUP:
3404 event.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
3405 break;
3406
3407 case SB_PAGEDOWN:
3408 event.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
3409 break;
3410
3411 case SB_THUMBPOSITION:
3412 event.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
3413 break;
3414
3415 case SB_THUMBTRACK:
3416 event.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
3417 break;
3418
3419 default:
3420 return FALSE;
3421 }
3422
3423 return GetEventHandler()->ProcessEvent(event);
3424 }
3425
3426 // ===========================================================================
3427 // global functions
3428 // ===========================================================================
3429
3430 void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont *the_font)
3431 {
3432 TEXTMETRIC tm;
3433 HDC dc = ::GetDC((HWND) wnd);
3434 HFONT fnt =0;
3435 HFONT was = 0;
3436 if ( the_font )
3437 {
3438 // the_font->UseResource();
3439 // the_font->RealizeResource();
3440 fnt = (HFONT)((wxFont *)the_font)->GetResourceHandle(); // const_cast
3441 if ( fnt )
3442 was = (HFONT) SelectObject(dc,fnt);
3443 }
3444 GetTextMetrics(dc, &tm);
3445 if ( the_font && fnt && was )
3446 {
3447 SelectObject(dc,was);
3448 }
3449 ReleaseDC((HWND)wnd, dc);
3450
3451 if ( x )
3452 *x = tm.tmAveCharWidth;
3453 if ( y )
3454 *y = tm.tmHeight + tm.tmExternalLeading;
3455
3456 // if ( the_font )
3457 // the_font->ReleaseResource();
3458 }
3459
3460 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
3461 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
3462 int wxCharCodeMSWToWX(int keySym)
3463 {
3464 int id = 0;
3465 switch (keySym)
3466 {
3467 case VK_CANCEL: id = WXK_CANCEL; break;
3468 case VK_BACK: id = WXK_BACK; break;
3469 case VK_TAB: id = WXK_TAB; break;
3470 case VK_CLEAR: id = WXK_CLEAR; break;
3471 case VK_RETURN: id = WXK_RETURN; break;
3472 case VK_SHIFT: id = WXK_SHIFT; break;
3473 case VK_CONTROL: id = WXK_CONTROL; break;
3474 case VK_MENU : id = WXK_MENU; break;
3475 case VK_PAUSE: id = WXK_PAUSE; break;
3476 case VK_SPACE: id = WXK_SPACE; break;
3477 case VK_ESCAPE: id = WXK_ESCAPE; break;
3478 case VK_PRIOR: id = WXK_PRIOR; break;
3479 case VK_NEXT : id = WXK_NEXT; break;
3480 case VK_END: id = WXK_END; break;
3481 case VK_HOME : id = WXK_HOME; break;
3482 case VK_LEFT : id = WXK_LEFT; break;
3483 case VK_UP: id = WXK_UP; break;
3484 case VK_RIGHT: id = WXK_RIGHT; break;
3485 case VK_DOWN : id = WXK_DOWN; break;
3486 case VK_SELECT: id = WXK_SELECT; break;
3487 case VK_PRINT: id = WXK_PRINT; break;
3488 case VK_EXECUTE: id = WXK_EXECUTE; break;
3489 case VK_INSERT: id = WXK_INSERT; break;
3490 case VK_DELETE: id = WXK_DELETE; break;
3491 case VK_HELP : id = WXK_HELP; break;
3492 case VK_NUMPAD0: id = WXK_NUMPAD0; break;
3493 case VK_NUMPAD1: id = WXK_NUMPAD1; break;
3494 case VK_NUMPAD2: id = WXK_NUMPAD2; break;
3495 case VK_NUMPAD3: id = WXK_NUMPAD3; break;
3496 case VK_NUMPAD4: id = WXK_NUMPAD4; break;
3497 case VK_NUMPAD5: id = WXK_NUMPAD5; break;
3498 case VK_NUMPAD6: id = WXK_NUMPAD6; break;
3499 case VK_NUMPAD7: id = WXK_NUMPAD7; break;
3500 case VK_NUMPAD8: id = WXK_NUMPAD8; break;
3501 case VK_NUMPAD9: id = WXK_NUMPAD9; break;
3502 case VK_MULTIPLY: id = WXK_MULTIPLY; break;
3503 case VK_ADD: id = WXK_ADD; break;
3504 case VK_SUBTRACT: id = WXK_SUBTRACT; break;
3505 case VK_DECIMAL: id = WXK_DECIMAL; break;
3506 case VK_DIVIDE: id = WXK_DIVIDE; break;
3507 case VK_F1: id = WXK_F1; break;
3508 case VK_F2: id = WXK_F2; break;
3509 case VK_F3: id = WXK_F3; break;
3510 case VK_F4: id = WXK_F4; break;
3511 case VK_F5: id = WXK_F5; break;
3512 case VK_F6: id = WXK_F6; break;
3513 case VK_F7: id = WXK_F7; break;
3514 case VK_F8: id = WXK_F8; break;
3515 case VK_F9: id = WXK_F9; break;
3516 case VK_F10: id = WXK_F10; break;
3517 case VK_F11: id = WXK_F11; break;
3518 case VK_F12: id = WXK_F12; break;
3519 case VK_F13: id = WXK_F13; break;
3520 case VK_F14: id = WXK_F14; break;
3521 case VK_F15: id = WXK_F15; break;
3522 case VK_F16: id = WXK_F16; break;
3523 case VK_F17: id = WXK_F17; break;
3524 case VK_F18: id = WXK_F18; break;
3525 case VK_F19: id = WXK_F19; break;
3526 case VK_F20: id = WXK_F20; break;
3527 case VK_F21: id = WXK_F21; break;
3528 case VK_F22: id = WXK_F22; break;
3529 case VK_F23: id = WXK_F23; break;
3530 case VK_F24: id = WXK_F24; break;
3531 case VK_NUMLOCK: id = WXK_NUMLOCK; break;
3532 case VK_SCROLL: id = WXK_SCROLL; break;
3533 default:
3534 {
3535 return 0;
3536 }
3537 }
3538 return id;
3539 }
3540
3541 int wxCharCodeWXToMSW(int id, bool *isVirtual)
3542 {
3543 *isVirtual = TRUE;
3544 int keySym = 0;
3545 switch (id)
3546 {
3547 case WXK_CANCEL: keySym = VK_CANCEL; break;
3548 case WXK_CLEAR: keySym = VK_CLEAR; break;
3549 case WXK_SHIFT: keySym = VK_SHIFT; break;
3550 case WXK_CONTROL: keySym = VK_CONTROL; break;
3551 case WXK_MENU : keySym = VK_MENU; break;
3552 case WXK_PAUSE: keySym = VK_PAUSE; break;
3553 case WXK_PRIOR: keySym = VK_PRIOR; break;
3554 case WXK_NEXT : keySym = VK_NEXT; break;
3555 case WXK_END: keySym = VK_END; break;
3556 case WXK_HOME : keySym = VK_HOME; break;
3557 case WXK_LEFT : keySym = VK_LEFT; break;
3558 case WXK_UP: keySym = VK_UP; break;
3559 case WXK_RIGHT: keySym = VK_RIGHT; break;
3560 case WXK_DOWN : keySym = VK_DOWN; break;
3561 case WXK_SELECT: keySym = VK_SELECT; break;
3562 case WXK_PRINT: keySym = VK_PRINT; break;
3563 case WXK_EXECUTE: keySym = VK_EXECUTE; break;
3564 case WXK_INSERT: keySym = VK_INSERT; break;
3565 case WXK_DELETE: keySym = VK_DELETE; break;
3566 case WXK_HELP : keySym = VK_HELP; break;
3567 case WXK_NUMPAD0: keySym = VK_NUMPAD0; break;
3568 case WXK_NUMPAD1: keySym = VK_NUMPAD1; break;
3569 case WXK_NUMPAD2: keySym = VK_NUMPAD2; break;
3570 case WXK_NUMPAD3: keySym = VK_NUMPAD3; break;
3571 case WXK_NUMPAD4: keySym = VK_NUMPAD4; break;
3572 case WXK_NUMPAD5: keySym = VK_NUMPAD5; break;
3573 case WXK_NUMPAD6: keySym = VK_NUMPAD6; break;
3574 case WXK_NUMPAD7: keySym = VK_NUMPAD7; break;
3575 case WXK_NUMPAD8: keySym = VK_NUMPAD8; break;
3576 case WXK_NUMPAD9: keySym = VK_NUMPAD9; break;
3577 case WXK_MULTIPLY: keySym = VK_MULTIPLY; break;
3578 case WXK_ADD: keySym = VK_ADD; break;
3579 case WXK_SUBTRACT: keySym = VK_SUBTRACT; break;
3580 case WXK_DECIMAL: keySym = VK_DECIMAL; break;
3581 case WXK_DIVIDE: keySym = VK_DIVIDE; break;
3582 case WXK_F1: keySym = VK_F1; break;
3583 case WXK_F2: keySym = VK_F2; break;
3584 case WXK_F3: keySym = VK_F3; break;
3585 case WXK_F4: keySym = VK_F4; break;
3586 case WXK_F5: keySym = VK_F5; break;
3587 case WXK_F6: keySym = VK_F6; break;
3588 case WXK_F7: keySym = VK_F7; break;
3589 case WXK_F8: keySym = VK_F8; break;
3590 case WXK_F9: keySym = VK_F9; break;
3591 case WXK_F10: keySym = VK_F10; break;
3592 case WXK_F11: keySym = VK_F11; break;
3593 case WXK_F12: keySym = VK_F12; break;
3594 case WXK_F13: keySym = VK_F13; break;
3595 case WXK_F14: keySym = VK_F14; break;
3596 case WXK_F15: keySym = VK_F15; break;
3597 case WXK_F16: keySym = VK_F16; break;
3598 case WXK_F17: keySym = VK_F17; break;
3599 case WXK_F18: keySym = VK_F18; break;
3600 case WXK_F19: keySym = VK_F19; break;
3601 case WXK_F20: keySym = VK_F20; break;
3602 case WXK_F21: keySym = VK_F21; break;
3603 case WXK_F22: keySym = VK_F22; break;
3604 case WXK_F23: keySym = VK_F23; break;
3605 case WXK_F24: keySym = VK_F24; break;
3606 case WXK_NUMLOCK: keySym = VK_NUMLOCK; break;
3607 case WXK_SCROLL: keySym = VK_SCROLL; break;
3608 default:
3609 {
3610 *isVirtual = FALSE;
3611 keySym = id;
3612 break;
3613 }
3614 }
3615 return keySym;
3616 }
3617
3618 wxWindow *wxGetActiveWindow()
3619 {
3620 HWND hWnd = GetActiveWindow();
3621 if ( hWnd != 0 )
3622 {
3623 return wxFindWinFromHandle((WXHWND) hWnd);
3624 }
3625 return NULL;
3626 }
3627
3628 extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
3629 {
3630 HWND hwnd = (HWND)hWnd;
3631
3632 // For a radiobutton, we get the radiobox from GWL_USERDATA (which is set
3633 // by code in msw/radiobox.cpp), for all the others we just search up the
3634 // window hierarchy
3635 wxWindow *win = (wxWindow *)NULL;
3636 if ( hwnd )
3637 {
3638 win = wxFindWinFromHandle((WXHWND)hwnd);
3639 if ( !win )
3640 {
3641 // the radiobox pointer is stored in GWL_USERDATA only under Win32
3642 #ifdef __WIN32__
3643 // native radiobuttons return DLGC_RADIOBUTTON here and for any
3644 // wxWindow class which overrides WM_GETDLGCODE processing to
3645 // do it as well, win would be already non NULL
3646 if ( ::SendMessage((HWND)hwnd, WM_GETDLGCODE,
3647 0, 0) & DLGC_RADIOBUTTON )
3648 {
3649 win = (wxWindow *)::GetWindowLong(hwnd, GWL_USERDATA);
3650 }
3651 else
3652 #endif // Win32
3653 {
3654 // hwnd is not a wxWindow, try its parent next below
3655 hwnd = ::GetParent(hwnd);
3656 }
3657 }
3658 //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
3659 }
3660
3661 while ( hwnd && !win )
3662 {
3663 win = wxFindWinFromHandle((WXHWND)hwnd);
3664 hwnd = ::GetParent(hwnd);
3665 }
3666
3667 return win;
3668 }
3669
3670 // Windows keyboard hook. Allows interception of e.g. F1, ESCAPE
3671 // in active frames and dialogs, regardless of where the focus is.
3672 static HHOOK wxTheKeyboardHook = 0;
3673 static FARPROC wxTheKeyboardHookProc = 0;
3674 int APIENTRY _EXPORT
3675 wxKeyboardHook(int nCode, WORD wParam, DWORD lParam);
3676
3677 void wxSetKeyboardHook(bool doIt)
3678 {
3679 if ( doIt )
3680 {
3681 wxTheKeyboardHookProc = MakeProcInstance((FARPROC) wxKeyboardHook, wxGetInstance());
3682 wxTheKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC) wxTheKeyboardHookProc, wxGetInstance(),
3683
3684 #if defined(__WIN32__) && !defined(__TWIN32__)
3685 GetCurrentThreadId()
3686 // (DWORD)GetCurrentProcess()); // This is another possibility. Which is right?
3687 #else
3688 GetCurrentTask()
3689 #endif
3690 );
3691 }
3692 else
3693 {
3694 UnhookWindowsHookEx(wxTheKeyboardHook);
3695 // avoids mingw warning about statement with no effect (FreeProcInstance
3696 // doesn't do anything under Win32)
3697 #ifndef __GNUC__
3698 FreeProcInstance(wxTheKeyboardHookProc);
3699 #endif
3700 }
3701 }
3702
3703 int APIENTRY _EXPORT
3704 wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
3705 {
3706 DWORD hiWord = HIWORD(lParam);
3707 if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) )
3708 {
3709 int id = wxCharCodeMSWToWX(wParam);
3710 if ( id != 0 )
3711 {
3712 wxKeyEvent event(wxEVT_CHAR_HOOK);
3713 if ( (HIWORD(lParam) & KF_ALTDOWN) == KF_ALTDOWN )
3714 event.m_altDown = TRUE;
3715
3716 event.m_eventObject = NULL;
3717 event.m_keyCode = id;
3718 event.m_shiftDown = wxIsShiftDown();
3719 event.m_controlDown = wxIsCtrlDown();
3720 event.SetTimestamp(s_currentMsg.time);
3721
3722 wxWindow *win = wxGetActiveWindow();
3723 wxEvtHandler *handler;
3724 if ( win )
3725 {
3726 handler = win->GetEventHandler();
3727 event.SetId(win->GetId());
3728 }
3729 else
3730 {
3731 handler = wxTheApp;
3732 event.SetId(-1);
3733 }
3734
3735 if ( handler && handler->ProcessEvent(event) )
3736 {
3737 // processed
3738 return 1;
3739 }
3740 }
3741 }
3742
3743 return (int)CallNextHookEx(wxTheKeyboardHook, nCode, wParam, lParam);
3744 }
3745
3746 #ifdef __WXDEBUG__
3747 const char *wxGetMessageName(int message)
3748 {
3749 switch ( message )
3750 {
3751 case 0x0000: return "WM_NULL";
3752 case 0x0001: return "WM_CREATE";
3753 case 0x0002: return "WM_DESTROY";
3754 case 0x0003: return "WM_MOVE";
3755 case 0x0005: return "WM_SIZE";
3756 case 0x0006: return "WM_ACTIVATE";
3757 case 0x0007: return "WM_SETFOCUS";
3758 case 0x0008: return "WM_KILLFOCUS";
3759 case 0x000A: return "WM_ENABLE";
3760 case 0x000B: return "WM_SETREDRAW";
3761 case 0x000C: return "WM_SETTEXT";
3762 case 0x000D: return "WM_GETTEXT";
3763 case 0x000E: return "WM_GETTEXTLENGTH";
3764 case 0x000F: return "WM_PAINT";
3765 case 0x0010: return "WM_CLOSE";
3766 case 0x0011: return "WM_QUERYENDSESSION";
3767 case 0x0012: return "WM_QUIT";
3768 case 0x0013: return "WM_QUERYOPEN";
3769 case 0x0014: return "WM_ERASEBKGND";
3770 case 0x0015: return "WM_SYSCOLORCHANGE";
3771 case 0x0016: return "WM_ENDSESSION";
3772 case 0x0017: return "WM_SYSTEMERROR";
3773 case 0x0018: return "WM_SHOWWINDOW";
3774 case 0x0019: return "WM_CTLCOLOR";
3775 case 0x001A: return "WM_WININICHANGE";
3776 case 0x001B: return "WM_DEVMODECHANGE";
3777 case 0x001C: return "WM_ACTIVATEAPP";
3778 case 0x001D: return "WM_FONTCHANGE";
3779 case 0x001E: return "WM_TIMECHANGE";
3780 case 0x001F: return "WM_CANCELMODE";
3781 case 0x0020: return "WM_SETCURSOR";
3782 case 0x0021: return "WM_MOUSEACTIVATE";
3783 case 0x0022: return "WM_CHILDACTIVATE";
3784 case 0x0023: return "WM_QUEUESYNC";
3785 case 0x0024: return "WM_GETMINMAXINFO";
3786 case 0x0026: return "WM_PAINTICON";
3787 case 0x0027: return "WM_ICONERASEBKGND";
3788 case 0x0028: return "WM_NEXTDLGCTL";
3789 case 0x002A: return "WM_SPOOLERSTATUS";
3790 case 0x002B: return "WM_DRAWITEM";
3791 case 0x002C: return "WM_MEASUREITEM";
3792 case 0x002D: return "WM_DELETEITEM";
3793 case 0x002E: return "WM_VKEYTOITEM";
3794 case 0x002F: return "WM_CHARTOITEM";
3795 case 0x0030: return "WM_SETFONT";
3796 case 0x0031: return "WM_GETFONT";
3797 case 0x0037: return "WM_QUERYDRAGICON";
3798 case 0x0039: return "WM_COMPAREITEM";
3799 case 0x0041: return "WM_COMPACTING";
3800 case 0x0044: return "WM_COMMNOTIFY";
3801 case 0x0046: return "WM_WINDOWPOSCHANGING";
3802 case 0x0047: return "WM_WINDOWPOSCHANGED";
3803 case 0x0048: return "WM_POWER";
3804
3805 #ifdef __WIN32__
3806 case 0x004A: return "WM_COPYDATA";
3807 case 0x004B: return "WM_CANCELJOURNAL";
3808 case 0x004E: return "WM_NOTIFY";
3809 case 0x0050: return "WM_INPUTLANGCHANGEREQUEST";
3810 case 0x0051: return "WM_INPUTLANGCHANGE";
3811 case 0x0052: return "WM_TCARD";
3812 case 0x0053: return "WM_HELP";
3813 case 0x0054: return "WM_USERCHANGED";
3814 case 0x0055: return "WM_NOTIFYFORMAT";
3815 case 0x007B: return "WM_CONTEXTMENU";
3816 case 0x007C: return "WM_STYLECHANGING";
3817 case 0x007D: return "WM_STYLECHANGED";
3818 case 0x007E: return "WM_DISPLAYCHANGE";
3819 case 0x007F: return "WM_GETICON";
3820 case 0x0080: return "WM_SETICON";
3821 #endif //WIN32
3822
3823 case 0x0081: return "WM_NCCREATE";
3824 case 0x0082: return "WM_NCDESTROY";
3825 case 0x0083: return "WM_NCCALCSIZE";
3826 case 0x0084: return "WM_NCHITTEST";
3827 case 0x0085: return "WM_NCPAINT";
3828 case 0x0086: return "WM_NCACTIVATE";
3829 case 0x0087: return "WM_GETDLGCODE";
3830 case 0x00A0: return "WM_NCMOUSEMOVE";
3831 case 0x00A1: return "WM_NCLBUTTONDOWN";
3832 case 0x00A2: return "WM_NCLBUTTONUP";
3833 case 0x00A3: return "WM_NCLBUTTONDBLCLK";
3834 case 0x00A4: return "WM_NCRBUTTONDOWN";
3835 case 0x00A5: return "WM_NCRBUTTONUP";
3836 case 0x00A6: return "WM_NCRBUTTONDBLCLK";
3837 case 0x00A7: return "WM_NCMBUTTONDOWN";
3838 case 0x00A8: return "WM_NCMBUTTONUP";
3839 case 0x00A9: return "WM_NCMBUTTONDBLCLK";
3840 case 0x0100: return "WM_KEYDOWN";
3841 case 0x0101: return "WM_KEYUP";
3842 case 0x0102: return "WM_CHAR";
3843 case 0x0103: return "WM_DEADCHAR";
3844 case 0x0104: return "WM_SYSKEYDOWN";
3845 case 0x0105: return "WM_SYSKEYUP";
3846 case 0x0106: return "WM_SYSCHAR";
3847 case 0x0107: return "WM_SYSDEADCHAR";
3848 case 0x0108: return "WM_KEYLAST";
3849
3850 #ifdef __WIN32__
3851 case 0x010D: return "WM_IME_STARTCOMPOSITION";
3852 case 0x010E: return "WM_IME_ENDCOMPOSITION";
3853 case 0x010F: return "WM_IME_COMPOSITION";
3854 #endif //WIN32
3855
3856 case 0x0110: return "WM_INITDIALOG";
3857 case 0x0111: return "WM_COMMAND";
3858 case 0x0112: return "WM_SYSCOMMAND";
3859 case 0x0113: return "WM_TIMER";
3860 case 0x0114: return "WM_HSCROLL";
3861 case 0x0115: return "WM_VSCROLL";
3862 case 0x0116: return "WM_INITMENU";
3863 case 0x0117: return "WM_INITMENUPOPUP";
3864 case 0x011F: return "WM_MENUSELECT";
3865 case 0x0120: return "WM_MENUCHAR";
3866 case 0x0121: return "WM_ENTERIDLE";
3867 case 0x0200: return "WM_MOUSEMOVE";
3868 case 0x0201: return "WM_LBUTTONDOWN";
3869 case 0x0202: return "WM_LBUTTONUP";
3870 case 0x0203: return "WM_LBUTTONDBLCLK";
3871 case 0x0204: return "WM_RBUTTONDOWN";
3872 case 0x0205: return "WM_RBUTTONUP";
3873 case 0x0206: return "WM_RBUTTONDBLCLK";
3874 case 0x0207: return "WM_MBUTTONDOWN";
3875 case 0x0208: return "WM_MBUTTONUP";
3876 case 0x0209: return "WM_MBUTTONDBLCLK";
3877 case 0x0210: return "WM_PARENTNOTIFY";
3878 case 0x0211: return "WM_ENTERMENULOOP";
3879 case 0x0212: return "WM_EXITMENULOOP";
3880
3881 #ifdef __WIN32__
3882 case 0x0213: return "WM_NEXTMENU";
3883 case 0x0214: return "WM_SIZING";
3884 case 0x0215: return "WM_CAPTURECHANGED";
3885 case 0x0216: return "WM_MOVING";
3886 case 0x0218: return "WM_POWERBROADCAST";
3887 case 0x0219: return "WM_DEVICECHANGE";
3888 #endif //WIN32
3889
3890 case 0x0220: return "WM_MDICREATE";
3891 case 0x0221: return "WM_MDIDESTROY";
3892 case 0x0222: return "WM_MDIACTIVATE";
3893 case 0x0223: return "WM_MDIRESTORE";
3894 case 0x0224: return "WM_MDINEXT";
3895 case 0x0225: return "WM_MDIMAXIMIZE";
3896 case 0x0226: return "WM_MDITILE";
3897 case 0x0227: return "WM_MDICASCADE";
3898 case 0x0228: return "WM_MDIICONARRANGE";
3899 case 0x0229: return "WM_MDIGETACTIVE";
3900 case 0x0230: return "WM_MDISETMENU";
3901 case 0x0233: return "WM_DROPFILES";
3902
3903 #ifdef __WIN32__
3904 case 0x0281: return "WM_IME_SETCONTEXT";
3905 case 0x0282: return "WM_IME_NOTIFY";
3906 case 0x0283: return "WM_IME_CONTROL";
3907 case 0x0284: return "WM_IME_COMPOSITIONFULL";
3908 case 0x0285: return "WM_IME_SELECT";
3909 case 0x0286: return "WM_IME_CHAR";
3910 case 0x0290: return "WM_IME_KEYDOWN";
3911 case 0x0291: return "WM_IME_KEYUP";
3912 #endif //WIN32
3913
3914 case 0x0300: return "WM_CUT";
3915 case 0x0301: return "WM_COPY";
3916 case 0x0302: return "WM_PASTE";
3917 case 0x0303: return "WM_CLEAR";
3918 case 0x0304: return "WM_UNDO";
3919 case 0x0305: return "WM_RENDERFORMAT";
3920 case 0x0306: return "WM_RENDERALLFORMATS";
3921 case 0x0307: return "WM_DESTROYCLIPBOARD";
3922 case 0x0308: return "WM_DRAWCLIPBOARD";
3923 case 0x0309: return "WM_PAINTCLIPBOARD";
3924 case 0x030A: return "WM_VSCROLLCLIPBOARD";
3925 case 0x030B: return "WM_SIZECLIPBOARD";
3926 case 0x030C: return "WM_ASKCBFORMATNAME";
3927 case 0x030D: return "WM_CHANGECBCHAIN";
3928 case 0x030E: return "WM_HSCROLLCLIPBOARD";
3929 case 0x030F: return "WM_QUERYNEWPALETTE";
3930 case 0x0310: return "WM_PALETTEISCHANGING";
3931 case 0x0311: return "WM_PALETTECHANGED";
3932
3933 #ifdef __WIN32__
3934 // common controls messages - although they're not strictly speaking
3935 // standard, it's nice to decode them nevertheless
3936
3937 // listview
3938 case 0x1000 + 0: return "LVM_GETBKCOLOR";
3939 case 0x1000 + 1: return "LVM_SETBKCOLOR";
3940 case 0x1000 + 2: return "LVM_GETIMAGELIST";
3941 case 0x1000 + 3: return "LVM_SETIMAGELIST";
3942 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
3943 case 0x1000 + 5: return "LVM_GETITEMA";
3944 case 0x1000 + 75: return "LVM_GETITEMW";
3945 case 0x1000 + 6: return "LVM_SETITEMA";
3946 case 0x1000 + 76: return "LVM_SETITEMW";
3947 case 0x1000 + 7: return "LVM_INSERTITEMA";
3948 case 0x1000 + 77: return "LVM_INSERTITEMW";
3949 case 0x1000 + 8: return "LVM_DELETEITEM";
3950 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
3951 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
3952 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
3953 case 0x1000 + 12: return "LVM_GETNEXTITEM";
3954 case 0x1000 + 13: return "LVM_FINDITEMA";
3955 case 0x1000 + 83: return "LVM_FINDITEMW";
3956 case 0x1000 + 14: return "LVM_GETITEMRECT";
3957 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
3958 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
3959 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
3960 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
3961 case 0x1000 + 18: return "LVM_HITTEST";
3962 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
3963 case 0x1000 + 20: return "LVM_SCROLL";
3964 case 0x1000 + 21: return "LVM_REDRAWITEMS";
3965 case 0x1000 + 22: return "LVM_ARRANGE";
3966 case 0x1000 + 23: return "LVM_EDITLABELA";
3967 case 0x1000 + 118: return "LVM_EDITLABELW";
3968 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
3969 case 0x1000 + 25: return "LVM_GETCOLUMNA";
3970 case 0x1000 + 95: return "LVM_GETCOLUMNW";
3971 case 0x1000 + 26: return "LVM_SETCOLUMNA";
3972 case 0x1000 + 96: return "LVM_SETCOLUMNW";
3973 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
3974 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
3975 case 0x1000 + 28: return "LVM_DELETECOLUMN";
3976 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
3977 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
3978 case 0x1000 + 31: return "LVM_GETHEADER";
3979 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
3980 case 0x1000 + 34: return "LVM_GETVIEWRECT";
3981 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
3982 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
3983 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
3984 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
3985 case 0x1000 + 39: return "LVM_GETTOPINDEX";
3986 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
3987 case 0x1000 + 41: return "LVM_GETORIGIN";
3988 case 0x1000 + 42: return "LVM_UPDATE";
3989 case 0x1000 + 43: return "LVM_SETITEMSTATE";
3990 case 0x1000 + 44: return "LVM_GETITEMSTATE";
3991 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
3992 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
3993 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
3994 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
3995 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
3996 case 0x1000 + 48: return "LVM_SORTITEMS";
3997 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
3998 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
3999 case 0x1000 + 51: return "LVM_GETITEMSPACING";
4000 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
4001 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
4002 case 0x1000 + 53: return "LVM_SETICONSPACING";
4003 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
4004 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
4005 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
4006 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
4007 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
4008 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
4009 case 0x1000 + 60: return "LVM_SETHOTITEM";
4010 case 0x1000 + 61: return "LVM_GETHOTITEM";
4011 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
4012 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
4013 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
4014 case 0x1000 + 65: return "LVM_SETWORKAREA";
4015
4016 // tree view
4017 case 0x1100 + 0: return "TVM_INSERTITEMA";
4018 case 0x1100 + 50: return "TVM_INSERTITEMW";
4019 case 0x1100 + 1: return "TVM_DELETEITEM";
4020 case 0x1100 + 2: return "TVM_EXPAND";
4021 case 0x1100 + 4: return "TVM_GETITEMRECT";
4022 case 0x1100 + 5: return "TVM_GETCOUNT";
4023 case 0x1100 + 6: return "TVM_GETINDENT";
4024 case 0x1100 + 7: return "TVM_SETINDENT";
4025 case 0x1100 + 8: return "TVM_GETIMAGELIST";
4026 case 0x1100 + 9: return "TVM_SETIMAGELIST";
4027 case 0x1100 + 10: return "TVM_GETNEXTITEM";
4028 case 0x1100 + 11: return "TVM_SELECTITEM";
4029 case 0x1100 + 12: return "TVM_GETITEMA";
4030 case 0x1100 + 62: return "TVM_GETITEMW";
4031 case 0x1100 + 13: return "TVM_SETITEMA";
4032 case 0x1100 + 63: return "TVM_SETITEMW";
4033 case 0x1100 + 14: return "TVM_EDITLABELA";
4034 case 0x1100 + 65: return "TVM_EDITLABELW";
4035 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
4036 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
4037 case 0x1100 + 17: return "TVM_HITTEST";
4038 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
4039 case 0x1100 + 19: return "TVM_SORTCHILDREN";
4040 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
4041 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
4042 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
4043 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
4044 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
4045 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
4046 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
4047
4048 // header
4049 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
4050 case 0x1200 + 1: return "HDM_INSERTITEMA";
4051 case 0x1200 + 10: return "HDM_INSERTITEMW";
4052 case 0x1200 + 2: return "HDM_DELETEITEM";
4053 case 0x1200 + 3: return "HDM_GETITEMA";
4054 case 0x1200 + 11: return "HDM_GETITEMW";
4055 case 0x1200 + 4: return "HDM_SETITEMA";
4056 case 0x1200 + 12: return "HDM_SETITEMW";
4057 case 0x1200 + 5: return "HDM_LAYOUT";
4058 case 0x1200 + 6: return "HDM_HITTEST";
4059 case 0x1200 + 7: return "HDM_GETITEMRECT";
4060 case 0x1200 + 8: return "HDM_SETIMAGELIST";
4061 case 0x1200 + 9: return "HDM_GETIMAGELIST";
4062 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
4063 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
4064 case 0x1200 + 17: return "HDM_GETORDERARRAY";
4065 case 0x1200 + 18: return "HDM_SETORDERARRAY";
4066 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
4067
4068 // tab control
4069 case 0x1300 + 2: return "TCM_GETIMAGELIST";
4070 case 0x1300 + 3: return "TCM_SETIMAGELIST";
4071 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
4072 case 0x1300 + 5: return "TCM_GETITEMA";
4073 case 0x1300 + 60: return "TCM_GETITEMW";
4074 case 0x1300 + 6: return "TCM_SETITEMA";
4075 case 0x1300 + 61: return "TCM_SETITEMW";
4076 case 0x1300 + 7: return "TCM_INSERTITEMA";
4077 case 0x1300 + 62: return "TCM_INSERTITEMW";
4078 case 0x1300 + 8: return "TCM_DELETEITEM";
4079 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
4080 case 0x1300 + 10: return "TCM_GETITEMRECT";
4081 case 0x1300 + 11: return "TCM_GETCURSEL";
4082 case 0x1300 + 12: return "TCM_SETCURSEL";
4083 case 0x1300 + 13: return "TCM_HITTEST";
4084 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
4085 case 0x1300 + 40: return "TCM_ADJUSTRECT";
4086 case 0x1300 + 41: return "TCM_SETITEMSIZE";
4087 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
4088 case 0x1300 + 43: return "TCM_SETPADDING";
4089 case 0x1300 + 44: return "TCM_GETROWCOUNT";
4090 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
4091 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
4092 case 0x1300 + 47: return "TCM_GETCURFOCUS";
4093 case 0x1300 + 48: return "TCM_SETCURFOCUS";
4094 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
4095 case 0x1300 + 50: return "TCM_DESELECTALL";
4096
4097 // toolbar
4098 case WM_USER+1: return "TB_ENABLEBUTTON";
4099 case WM_USER+2: return "TB_CHECKBUTTON";
4100 case WM_USER+3: return "TB_PRESSBUTTON";
4101 case WM_USER+4: return "TB_HIDEBUTTON";
4102 case WM_USER+5: return "TB_INDETERMINATE";
4103 case WM_USER+9: return "TB_ISBUTTONENABLED";
4104 case WM_USER+10: return "TB_ISBUTTONCHECKED";
4105 case WM_USER+11: return "TB_ISBUTTONPRESSED";
4106 case WM_USER+12: return "TB_ISBUTTONHIDDEN";
4107 case WM_USER+13: return "TB_ISBUTTONINDETERMINATE";
4108 case WM_USER+17: return "TB_SETSTATE";
4109 case WM_USER+18: return "TB_GETSTATE";
4110 case WM_USER+19: return "TB_ADDBITMAP";
4111 case WM_USER+20: return "TB_ADDBUTTONS";
4112 case WM_USER+21: return "TB_INSERTBUTTON";
4113 case WM_USER+22: return "TB_DELETEBUTTON";
4114 case WM_USER+23: return "TB_GETBUTTON";
4115 case WM_USER+24: return "TB_BUTTONCOUNT";
4116 case WM_USER+25: return "TB_COMMANDTOINDEX";
4117 case WM_USER+26: return "TB_SAVERESTOREA";
4118 case WM_USER+76: return "TB_SAVERESTOREW";
4119 case WM_USER+27: return "TB_CUSTOMIZE";
4120 case WM_USER+28: return "TB_ADDSTRINGA";
4121 case WM_USER+77: return "TB_ADDSTRINGW";
4122 case WM_USER+29: return "TB_GETITEMRECT";
4123 case WM_USER+30: return "TB_BUTTONSTRUCTSIZE";
4124 case WM_USER+31: return "TB_SETBUTTONSIZE";
4125 case WM_USER+32: return "TB_SETBITMAPSIZE";
4126 case WM_USER+33: return "TB_AUTOSIZE";
4127 case WM_USER+35: return "TB_GETTOOLTIPS";
4128 case WM_USER+36: return "TB_SETTOOLTIPS";
4129 case WM_USER+37: return "TB_SETPARENT";
4130 case WM_USER+39: return "TB_SETROWS";
4131 case WM_USER+40: return "TB_GETROWS";
4132 case WM_USER+42: return "TB_SETCMDID";
4133 case WM_USER+43: return "TB_CHANGEBITMAP";
4134 case WM_USER+44: return "TB_GETBITMAP";
4135 case WM_USER+45: return "TB_GETBUTTONTEXTA";
4136 case WM_USER+75: return "TB_GETBUTTONTEXTW";
4137 case WM_USER+46: return "TB_REPLACEBITMAP";
4138 case WM_USER+47: return "TB_SETINDENT";
4139 case WM_USER+48: return "TB_SETIMAGELIST";
4140 case WM_USER+49: return "TB_GETIMAGELIST";
4141 case WM_USER+50: return "TB_LOADIMAGES";
4142 case WM_USER+51: return "TB_GETRECT";
4143 case WM_USER+52: return "TB_SETHOTIMAGELIST";
4144 case WM_USER+53: return "TB_GETHOTIMAGELIST";
4145 case WM_USER+54: return "TB_SETDISABLEDIMAGELIST";
4146 case WM_USER+55: return "TB_GETDISABLEDIMAGELIST";
4147 case WM_USER+56: return "TB_SETSTYLE";
4148 case WM_USER+57: return "TB_GETSTYLE";
4149 case WM_USER+58: return "TB_GETBUTTONSIZE";
4150 case WM_USER+59: return "TB_SETBUTTONWIDTH";
4151 case WM_USER+60: return "TB_SETMAXTEXTROWS";
4152 case WM_USER+61: return "TB_GETTEXTROWS";
4153 case WM_USER+41: return "TB_GETBITMAPFLAGS";
4154
4155 #endif //WIN32
4156
4157 default:
4158 static char s_szBuf[128];
4159 sprintf(s_szBuf, "<unknown message = %d>", message);
4160 return s_szBuf;
4161 }
4162 }
4163 #endif //__WXDEBUG__
4164
4165 static void TranslateKbdEventToMouse(wxWindow *win, int *x, int *y, WPARAM *flags)
4166 {
4167 // construct the key mask
4168 WPARAM& fwKeys = *flags;
4169
4170 fwKeys = MK_RBUTTON;
4171 if ( wxIsCtrlDown() )
4172 fwKeys |= MK_CONTROL;
4173 if ( wxIsShiftDown() )
4174 fwKeys |= MK_SHIFT;
4175
4176 // simulate right mouse button click
4177 DWORD dwPos = ::GetMessagePos();
4178 *x = GET_X_LPARAM(dwPos);
4179 *y = GET_Y_LPARAM(dwPos);
4180
4181 win->ScreenToClient(x, y);
4182 }