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