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