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