]> git.saurik.com Git - wxWidgets.git/blob - src/os2/window.cpp
Window proc processing updates
[wxWidgets.git] / src / os2 / window.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: windows.cpp
3 // Purpose: wxWindow
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/12/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 //
13 // For compilers that support precompilation, includes "wx.h".
14 //
15 #include "wx/wxprec.h"
16
17 #ifndef WX_PRECOMP
18 #define INCL_DOS
19 #define INCL_PM
20 #include <os2.h>
21 #include "wx/window.h"
22 #include "wx/accel.h"
23 #include "wx/setup.h"
24 #include "wx/menu.h"
25 #include "wx/dc.h"
26 #include "wx/dcclient.h"
27 #include "wx/utils.h"
28 #include "wx/app.h"
29 #include "wx/panel.h"
30 #include "wx/layout.h"
31 #include "wx/dialog.h"
32 #include "wx/frame.h"
33 #include "wx/listbox.h"
34 #include "wx/button.h"
35 #include "wx/msgdlg.h"
36
37 #include <stdio.h>
38 #endif
39
40 #define DEBUG_PRINTF(NAME) { static int raz=0; \
41 printf( #NAME " %i\n",raz); fflush(stdout); \
42 raz++; \
43 }
44
45 #if wxUSE_OWNER_DRAWN
46 #include "wx/ownerdrw.h"
47 #endif
48
49 #if wxUSE_DRAG_AND_DROP
50 #include "wx/dnd.h"
51 #endif
52
53 #include "wx/menuitem.h"
54 #include "wx/log.h"
55
56 #include "wx/os2/private.h"
57
58 #if wxUSE_TOOLTIPS
59 #include "wx/tooltip.h"
60 #endif
61
62 #if wxUSE_CARET
63 #include "wx/caret.h"
64 #endif // wxUSE_CARET
65
66 #include "wx/intl.h"
67 #include "wx/log.h"
68
69
70 #include "wx/textctrl.h"
71
72 #include <string.h>
73
74 //
75 // Place compiler, OS specific includes here
76 //
77
78 //
79 // Standard macros -- these are for OS/2 PM, but most GUI's have something similar
80 //
81 #ifndef GET_X_LPARAM
82 //
83 // SHORT1FROMMP -- LOWORD
84 //
85 #define GET_X_LPARAM(mp) ((unsigned short)(unsigned long)(mp))
86 //
87 // SHORT2FROMMP -- HIWORD
88 //
89 #define GET_Y_LPARAM(mp) ((unsigned short)(unsigned long)(mp >> 16))
90 #endif // GET_X_LPARAM
91
92 #ifndef CW_USEDEFAULT
93 # define CW_USEDEFAULT ((int)0x80000000)
94 #endif
95
96 // ---------------------------------------------------------------------------
97 // global variables
98 // ---------------------------------------------------------------------------
99
100 //
101 // The last Windows message we got (MT-UNSAFE)
102 //
103 QMSG s_currentMsg;
104
105 wxMenu* wxCurrentPopupMenu = NULL;
106 extern wxList WXDLLEXPORT wxPendingDelete;
107 #if !defined(__VISAGECPP__) || (__IBMCPP__ < 400)
108 extern wxChar wxCanvasClassName[];
109 #endif
110 wxList* wxWinHandleList = NULL;
111
112 // ---------------------------------------------------------------------------
113 // private functions
114 // ---------------------------------------------------------------------------
115
116 //
117 // the window proc for all our windows; most gui's have something similar
118 //
119 MRESULT EXPENTRY wxWndProc( HWND hWnd
120 ,ULONG message
121 ,MPARAM mp1
122 ,MPARAM mp2
123 );
124
125 #ifdef __WXDEBUG__
126 const char *wxGetMessageName(int message);
127 #endif //__WXDEBUG__
128
129 void wxRemoveHandleAssociation(wxWindow* pWin);
130 void wxAssociateWinWithHandle( HWND hWnd
131 ,wxWindow* pWin
132 );
133 wxWindow* wxFindWinFromHandle(WXHWND hWnd);
134
135 //
136 // This magical function is used to translate VK_APPS key presses to right
137 // mouse clicks
138 //
139 static void TranslateKbdEventToMouse( wxWindow* pWin
140 ,int* pX
141 ,int* pY
142 ,MPARAM* pFlags
143 );
144
145 //
146 // get the current state of SHIFT/CTRL keys
147 //
148 static inline bool IsShiftDown() { return (::WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000) != 0; }
149 static inline bool IsCtrlDown() { return (::WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000) != 0; }
150 // ---------------------------------------------------------------------------
151 // event tables
152 // ---------------------------------------------------------------------------
153
154 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
155
156 BEGIN_EVENT_TABLE(wxWindow, wxWindowBase)
157 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground)
158 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged)
159 EVT_INIT_DIALOG(wxWindow::OnInitDialog)
160 EVT_IDLE(wxWindow::OnIdle)
161 EVT_SET_FOCUS(wxWindow::OnSetFocus)
162 END_EVENT_TABLE()
163
164 // ===========================================================================
165 // implementation
166 // ===========================================================================
167
168 //
169 // Find an item given the PM Window id
170 //
171 wxWindow* wxWindow::FindItem(
172 long lId
173 ) const
174 {
175 wxControl* pItem = wxDynamicCast( this
176 ,wxControl
177 );
178
179 if (pItem)
180 {
181 //
182 // I it we or one of our "internal" children?
183 //
184 if (pItem->GetId() == lId ||
185 (pItem->GetSubcontrols().Index(lId) != wxNOT_FOUND))
186 {
187 return pItem;
188 }
189 }
190
191 wxWindowList::Node* pCurrent = GetChildren().GetFirst();
192
193 while (pCurrent)
194 {
195 wxWindow* pChildWin = pCurrent->GetData();
196 wxWindow* pWnd = pChildWin->FindItem(lId);
197
198 if (pWnd)
199 return pWnd;
200
201 pCurrent = pCurrent->GetNext();
202 }
203 return(NULL);
204 } // end of wxWindow::FindItem
205
206 //
207 // Find an item given the PM Window handle
208 //
209 wxWindow* wxWindow::FindItemByHWND(
210 WXHWND hWnd
211 , bool bControlOnly
212 ) const
213 {
214 wxWindowList::Node* pCurrent = GetChildren().GetFirst();
215
216 while (pCurrent)
217 {
218 wxWindow* pParent = pCurrent->GetData();
219
220 //
221 // Do a recursive search.
222 //
223 wxWindow* pWnd = pParent->FindItemByHWND(hWnd);
224
225 if (pWnd)
226 return(pWnd);
227
228 if (!bControlOnly || pParent->IsKindOf(CLASSINFO(wxControl)))
229 {
230 wxWindow* pItem = pCurrent->GetData();
231
232 if (pItem->GetHWND() == hWnd)
233 return(pItem);
234 else
235 {
236 if (pItem->ContainsHWND(hWnd))
237 return(pItem);
238 }
239 }
240 pCurrent = pCurrent->GetNext();
241 }
242 return(NULL);
243 } // end of wxWindow::FindItemByHWND
244
245 //
246 // Default command handler
247 //
248 bool wxWindow::OS2Command(
249 WXUINT WXUNUSED(uParam)
250 , WXWORD WXUNUSED(uId)
251 )
252 {
253
254 DEBUG_PRINTF(wxWindow::OS2Command);
255
256 return(FALSE);
257 }
258
259 // ----------------------------------------------------------------------------
260 // constructors and such
261 // ----------------------------------------------------------------------------
262
263 void wxWindow::Init()
264 {
265 //
266 // Generic
267 //
268 InitBase();
269
270 //
271 // PM specific
272 //
273 m_bDoubleClickAllowed = 0;
274 m_bWinCaptured = FALSE;
275
276 m_isBeingDeleted = FALSE;
277 m_fnOldWndProc = 0;
278 m_bUseCtl3D = FALSE;
279 m_bMouseInWindow = FALSE;
280
281 //
282 // wxWnd
283 //
284 m_hMenu = 0;
285 m_hWnd = 0;
286
287 //
288 // Pass WM_GETDLGCODE to DefWindowProc()
289 m_lDlgCode = 0;
290
291 m_nXThumbSize = 0;
292 m_nYThumbSize = 0;
293 m_bBackgroundTransparent = FALSE;
294
295 //
296 // As all windows are created with WS_VISIBLE style...
297 //
298 m_isShown = TRUE;
299
300 #if wxUSE_MOUSEEVENT_HACK
301 m_lLastMouseX =
302 m_lLastMouseY = -1;
303 m_nLastMouseEvent = -1;
304 #endif // wxUSE_MOUSEEVENT_HACK
305
306 DEBUG_PRINTF(wxWindow::Init-End);
307
308 } // wxWindow::Init
309
310 //
311 // Destructor
312 //
313 wxWindow::~wxWindow()
314 {
315 DEBUG_PRINTF(wxWindow::~wxWindow-Start);
316 m_isBeingDeleted = TRUE;
317
318 OS2DetachWindowMenu();
319 if (m_parent)
320 m_parent->RemoveChild(this);
321 DestroyChildren();
322
323 if (m_hWnd)
324 {
325 if(!::WinDestroyWindow(GetHWND()))
326 wxLogLastError(wxT("DestroyWindow"));
327 //
328 // remove hWnd <-> wxWindow association
329 //
330 wxRemoveHandleAssociation(this);
331 }
332 DEBUG_PRINTF(wxWindow::~wxWindow-End);
333 } // end of wxWindow::~wxWindow
334
335 bool wxWindow::Create(
336 wxWindow* pParent
337 , wxWindowID vId
338 , const wxPoint& rPos
339 , const wxSize& rSize
340 , long lStyle
341 , const wxString& rName
342 )
343 {
344 HWND hParent = NULLHANDLE;
345
346 wxCHECK_MSG(pParent, FALSE, wxT("can't create wxWindow without parent"));
347
348 if ( !CreateBase( pParent
349 ,vId
350 ,rPos
351 ,rSize
352 ,lStyle
353 ,wxDefaultValidator
354 ,rName
355 ))
356 return(FALSE);
357
358 if (pParent)
359 {
360 pParent->AddChild(this);
361 hParent = GetWinHwnd(pParent);
362 }
363 else
364 hParent = HWND_DESKTOP;
365
366 ULONG ulCreateFlags = 0L;
367
368
369 //
370 // Most wxSTYLES are really PM Class specific styles and will be
371 // set in those class create procs. PM's basic windows styles are
372 // very limited.
373 //
374 ulCreateFlags |= WS_VISIBLE;
375
376
377 if ( lStyle & wxCLIP_SIBLINGS )
378 ulCreateFlags |= WS_CLIPSIBLINGS;
379
380 if (lStyle & wxCLIP_CHILDREN )
381 ulCreateFlags |= WS_CLIPCHILDREN;
382
383 //
384 // Empty stuff for now since PM has no custome 3D effects
385 // Doesn't mean someone cannot make some up though
386 //
387 bool bWant3D;
388 WXDWORD dwExStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &bWant3D);
389
390 //
391 // Generic OS/2 Windows are created with no owner, no Z Order, no Control data,
392 // and no presentation parameters
393 //
394 OS2Create( hParent
395 ,(PSZ)wxCanvasClassName
396 ,rName.c_str()
397 ,ulCreateFlags
398 ,rPos.x
399 ,rPos.y
400 ,WidthDefault(rSize.x)
401 ,HeightDefault(rSize.y)
402 ,NULLHANDLE
403 ,NULLHANDLE
404 ,m_windowId
405 );
406
407 return(TRUE);
408 } // end of wxWindow::Create
409
410 // ---------------------------------------------------------------------------
411 // basic operations
412 // ---------------------------------------------------------------------------
413
414 void wxWindow::SetFocus()
415 {
416 HWND hWnd = GetHwnd();
417
418 if (hWnd)
419 ::WinSetFocus(HWND_DESKTOP, hWnd);
420 } // end of wxWindow::SetFocus
421
422 wxWindow* wxWindowBase::FindFocus()
423 {
424 HWND hWnd = ::WinQueryFocus(HWND_DESKTOP);
425
426 if (hWnd)
427 {
428 return wxFindWinFromHandle((WXHWND)hWnd);
429 }
430 return NULL;
431 } // wxWindowBase::FindFocus
432
433 bool wxWindow::Enable(
434 bool bEnable
435 )
436 {
437 if (!wxWindowBase::Enable(bEnable))
438 return(FALSE);
439
440 HWND hWnd = GetHwnd();
441
442 if ( hWnd )
443 ::WinEnableWindow(hWnd, (BOOL)bEnable);
444
445 wxWindowList::Node* pNode = GetChildren().GetFirst();
446
447 while (pNode)
448 {
449 wxWindow* pChild = pNode->GetData();
450
451 pChild->Enable(bEnable);
452 pNode = pNode->GetNext();
453 }
454 return(TRUE);
455 } // end of wxWindow::Enable
456
457 bool wxWindow::Show(
458 bool bShow
459 )
460 {
461 if (!wxWindowBase::Show(bShow))
462 return(FALSE);
463
464 HWND hWnd = GetHwnd();
465
466 ::WinShowWindow(hWnd, bShow);
467
468 if (bShow)
469 {
470 ::WinSetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_ZORDER);
471 }
472 return(TRUE);
473 } // end of wxWindow::Show
474
475 void wxWindow::Raise()
476 {
477 ::WinSetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_ACTIVATE);
478 } // end of wxWindow::Raise
479
480 void wxWindow::Lower()
481 {
482 ::WinSetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_ZORDER | SWP_DEACTIVATE);
483 } // end of wxWindow::Lower
484
485 void wxWindow::SetTitle(
486 const wxString& rTitle
487 )
488 {
489 ::WinSetWindowText(GetHwnd(), rTitle.c_str());
490 } // end of wxWindow::SetTitle
491
492 wxString wxWindow::GetTitle() const
493 {
494 return wxGetWindowText(GetHWND());
495 } // end of wxWindow::GetTitle
496
497 void wxWindow::CaptureMouse()
498 {
499 HWND hWnd = GetHwnd();
500
501 if (hWnd && !m_bWinCaptured)
502 {
503 ::WinSetCapture(HWND_DESKTOP, hWnd);
504 m_bWinCaptured = TRUE;
505 }
506 } // end of wxWindow::GetTitle
507
508 void wxWindow::ReleaseMouse()
509 {
510 if (m_bWinCaptured)
511 {
512 ::WinSetCapture(HWND_DESKTOP, NULLHANDLE);
513 m_bWinCaptured = FALSE;
514 }
515 } // end of wxWindow::ReleaseMouse
516
517 bool wxWindow::SetFont(
518 const wxFont& rFont
519 )
520 {
521 DEBUG_PRINTF(wxWindow::SetFont);
522 if (!wxWindowBase::SetFont(rFont))
523 {
524 // nothing to do
525 return(FALSE);
526 }
527
528 HWND hWnd = GetHwnd();
529
530 if (hWnd != 0)
531 {
532 wxChar zFont[128];
533
534 sprintf(zFont, "%d.%s", rFont.GetPointSize(), rFont.GetFaceName().c_str());
535 return(::WinSetPresParam(hWnd, PP_FONTNAMESIZE, strlen(zFont), (PVOID)zFont));
536 }
537 return(TRUE);
538 }
539
540 bool wxWindow::SetCursor(
541 const wxCursor& rCursor
542 ) // check if base implementation is OK
543 {
544 if ( !wxWindowBase::SetCursor(rCursor))
545 {
546 // no change
547 return FALSE;
548 }
549
550 wxASSERT_MSG( m_cursor.Ok(),
551 wxT("cursor must be valid after call to the base version"));
552
553 HWND hWnd = GetHwnd();
554 POINTL vPoint;
555 RECTL vRect;
556 HPS hPS;
557 HRGN hRGN;
558
559 hPS = ::WinGetPS(hWnd);
560
561 ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
562 ::WinQueryWindowRect(hWnd, &vRect);
563
564 hRGN = ::GpiCreateRegion(hPS, 1L, &vRect);
565
566 if ((::GpiPtInRegion(hPS, hRGN, &vPoint) == PRGN_INSIDE) && !wxIsBusy())
567 {
568 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)m_cursor.GetHCURSOR());
569 }
570 return TRUE;
571 } // end of wxWindow::SetCursor
572
573 void wxWindow::WarpPointer(
574 int nXPos
575 , int nYPos
576 )
577 {
578 int nX = nXPos;
579 int nY = nYPos;
580 RECTL vRect;
581
582 ::WinQueryWindowRect(GetHwnd(), &vRect);
583 nX += vRect.xLeft;
584 nY += vRect.yBottom;
585
586 ::WinSetPointerPos(HWND_DESKTOP, (LONG)nX, (LONG)(nY));
587 } // end of wxWindow::WarpPointer
588
589 #if WXWIN_COMPATIBILITY
590 void wxWindow::OS2DeviceToLogical (float *x, float *y) const
591 {
592 }
593 #endif // WXWIN_COMPATIBILITY
594
595 // ---------------------------------------------------------------------------
596 // scrolling stuff
597 // ---------------------------------------------------------------------------
598
599 #if WXWIN_COMPATIBILITY
600 void wxWindow::SetScrollRange(
601 int nOrient
602 , int nRange
603 , bool bRefresh
604 )
605 {
606 ::WinSendMsg(GetHwnd(), SBM_SETSCROLLBAR, (MPARAM)0, MPFROM2SHORT(0, nRange));
607 } // end of wxWindow::SetScrollRange
608
609 void wxWindow::SetScrollPage(
610 int nOrient
611 , int nPage
612 , bool bRefresh
613 )
614 {
615 if ( orient == wxHORIZONTAL )
616 m_xThumbSize = page;
617 else
618 m_yThumbSize = page;
619 }
620
621 int wxWindow::OldGetScrollRange(
622 int nOrient
623 ) const
624 {
625 MRESULT mRc;
626 HWND hWnd = GetHwnd();
627
628 if (hWnd)
629 {
630 mRc = WinSendMsg(hWnd, SBM_QUERYRANGE, (MPARAM)0L, (MPARAM)0L);
631 return(SHORT2FROMMR(mRc));
632 }
633 return 0;
634 } // end of wxWindow::OldGetScrollRange
635
636 int wxWindow::GetScrollPage(
637 int nOrient
638 ) const
639 {
640 if (nOrient == wxHORIZONTAL)
641 return m_nXThumbSize;
642 else
643 return m_nYThumbSize;
644 } // end of wxWindow::GetScrollPage
645 #endif // WXWIN_COMPATIBILITY
646
647 int wxWindow::GetScrollPos(
648 int nOrient
649 ) const
650 {
651 return((int)::WinSendMsg(GetHwnd(), SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL));
652 } // end of wxWindow::GetScrollPos
653
654 int wxWindow::GetScrollRange(
655 int nOrient
656 ) const
657 {
658 MRESULT mr;
659
660 mr = ::WinSendMsg(GetHwnd(), SBM_QUERYRANGE, (MPARAM)NULL, (MPARAM)NULL);
661 return((int)SHORT2FROMMR(mr));
662 } // end of wxWindow::GetScrollRange
663
664 int wxWindow::GetScrollThumb(
665 int nOrient
666 ) const
667 {
668 WNDPARAMS vWndParams;
669 PSBCDATA pSbcd;
670
671 ::WinSendMsg(GetHwnd(), WM_QUERYWINDOWPARAMS, (MPARAM)&vWndParams, (MPARAM)NULL);
672 pSbcd = (PSBCDATA)vWndParams.pCtlData;
673 return((int)pSbcd->posThumb);
674 } // end of wxWindow::GetScrollThumb
675
676 void wxWindow::SetScrollPos(
677 int nOrient
678 , int nPos
679 , bool bRefresh
680 )
681 {
682 ::WinSendMsg(GetHwnd(), SBM_SETPOS, (MPARAM)nPos, (MPARAM)NULL);
683 } // end of wxWindow::SetScrollPos(
684
685 void wxWindow::SetScrollbar(
686 int nOrient
687 , int nPos
688 , int nThumbVisible
689 , int nRange
690 , bool bRefresh
691 )
692 {
693 ::WinSendMsg(GetHwnd(), SBM_SETSCROLLBAR, (MPARAM)nPos, MPFROM2SHORT(0, nRange));
694 if (nOrient == wxHORIZONTAL)
695 {
696 m_nXThumbSize = nThumbVisible;
697 }
698 else
699 {
700 m_nYThumbSize = nThumbVisible;
701 }
702 } // end of wxWindow::SetScrollbar
703
704 void wxWindow::ScrollWindow(
705 int nDx
706 , int nDy
707 , const wxRect* pRect
708 )
709 {
710 RECTL vRect2;
711
712 if (pRect)
713 {
714 vRect2.xLeft = pRect->x;
715 vRect2.yTop = pRect->y;
716 vRect2.xRight = pRect->x + pRect->width;
717 vRect2.yBottom = pRect->y + pRect->height;
718 }
719
720 if (pRect)
721 ::WinScrollWindow(GetHwnd(), (LONG)nDx, (LONG)nDy, &vRect2, NULL, NULLHANDLE, NULL, 0L);
722 else
723 ::WinScrollWindow(GetHwnd(), nDx, nDy, NULL, NULL, NULLHANDLE, NULL, 0L);
724 } // end of wxWindow::ScrollWindow
725
726 // ---------------------------------------------------------------------------
727 // subclassing
728 // ---------------------------------------------------------------------------
729
730 void wxWindow::SubclassWin(
731 WXHWND hWnd
732 )
733 {
734 HWND hwnd = (HWND)hWnd;
735
736 wxASSERT_MSG( !m_fnOldWndProc, wxT("subclassing window twice?") );
737 wxCHECK_RET(::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in SubclassWin") );
738 m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, (PFNWP)wxWndProc);
739 } // end of wxWindow::SubclassWin
740
741 void wxWindow::UnsubclassWin()
742 {
743 //
744 // Restore old Window proc
745 //
746 HWND hwnd = GetHWND();
747
748 if (m_hWnd)
749 {
750 wxCHECK_RET( ::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in UnsubclassWin") );
751
752 PFNWP fnProc = (PFNWP)::WinQueryWindowPtr(hwnd, QWP_PFNWP);
753
754 if ( (m_fnOldWndProc != 0) && (fnProc != (PFNWP) m_fnOldWndProc))
755 {
756 WinSubclassWindow(hwnd, (PFNWP)m_fnOldWndProc);
757 m_fnOldWndProc = 0;
758 }
759 }
760 } // end of wxWindow::UnsubclassWin
761
762 //
763 // Make a Windows extended style from the given wxWindows window style
764 //
765 WXDWORD wxWindow::MakeExtendedStyle(
766 long lStyle
767 , bool bEliminateBorders
768 )
769 {
770 //
771 // PM does not support extended style
772 //
773 WXDWORD exStyle = 0;
774 return exStyle;
775 } // end of wxWindow::MakeExtendedStyle
776
777 //
778 // Determines whether native 3D effects or CTL3D should be used,
779 // applying a default border style if required, and returning an extended
780 // style to pass to CreateWindowEx.
781 //
782 WXDWORD wxWindow::Determine3DEffects(
783 WXDWORD dwDefaultBorderStyle
784 , bool* pbWant3D
785 ) const
786 {
787 WXDWORD dwStyle = 0L;
788
789 //
790 // Native PM does not have any specialize 3D effects like WIN32 does
791 //
792 *pbWant3D = FALSE;
793 return dwStyle;
794 } // end of wxWindow::Determine3DEffects
795
796 #if WXWIN_COMPATIBILITY
797 void wxWindow::OnCommand(
798 wxWindow& rWin
799 , wxCommandEvent& rEvent
800 )
801 {
802 if (GetEventHandler()->ProcessEvent(rEvent))
803 return;
804 if (m_parent)
805 m_parent->GetEventHandler()->OnCommand( rWin
806 ,rEvent
807 );
808 } // end of wxWindow::OnCommand
809
810 wxObject* wxWindow::GetChild(
811 int nNumber
812 ) const
813 {
814 //
815 // Return a pointer to the Nth object in the Panel
816 //
817 wxNode* pNode = GetChildren().First();
818 int n = nNumber;
819
820 while (pNode && n--)
821 pNode = pNode->Next();
822 if (pNode)
823 {
824 wxObject* pObj = (wxObject*)pNode->Data();
825 return(pObj);
826 }
827 else
828 return NULL;
829 } // end of wxWindow::GetChild
830
831 #endif // WXWIN_COMPATIBILITY
832
833 //
834 // Setup background and foreground colours correctly
835 //
836 void wxWindow::SetupColours()
837 {
838 if ( GetParent() )
839 SetBackgroundColour(GetParent()->GetBackgroundColour());
840 } // end of wxWindow::SetupColours
841
842 void wxWindow::OnIdle(
843 wxIdleEvent& rEvent
844 )
845 {
846 //
847 // Check if we need to send a LEAVE event
848 //
849 if (m_bMouseInWindow)
850 {
851 POINTL vPoint;
852
853 ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
854 if (::WinWindowFromPoint(HWND_DESKTOP, &vPoint, FALSE) != (HWND)GetHwnd())
855 {
856 //
857 // Generate a LEAVE event
858 //
859 m_bMouseInWindow = FALSE;
860
861 //
862 // Unfortunately the mouse button and keyboard state may have changed
863 // by the time the OnIdle function is called, so 'state' may be
864 // meaningless.
865 //
866 int nState = 0;
867
868 if (::WinGetKeyState(HWND_DESKTOP, VK_SHIFT) != 0)
869 nState |= VK_SHIFT;
870 if (::WinGetKeyState(HWND_DESKTOP, VK_CTRL) != 0);
871 nState |= VK_CTRL;
872
873 wxMouseEvent rEvent(wxEVT_LEAVE_WINDOW);
874
875 InitMouseEvent( rEvent
876 ,vPoint.x
877 ,vPoint.y
878 ,nState
879 );
880 (void)GetEventHandler()->ProcessEvent(rEvent);
881 }
882 }
883 UpdateWindowUI();
884 } // end of wxWindow::OnIdle
885
886 //
887 // Set this window to be the child of 'parent'.
888 //
889 bool wxWindow::Reparent(
890 wxWindow* pParent
891 )
892 {
893 if (!wxWindowBase::Reparent(pParent))
894 return FALSE;
895
896 HWND hWndChild = GetHwnd();
897 HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
898
899 ::WinSetParent(hWndChild, hWndParent, TRUE);
900 return TRUE;
901 } // end of wxWindow::Reparent
902
903 void wxWindow::Clear()
904 {
905 wxClientDC vDc(this);
906 wxBrush vBrush( GetBackgroundColour()
907 ,wxSOLID
908 );
909
910 vDc.SetBackground(vBrush);
911 vDc.Clear();
912 } // end of wxWindow::Clear
913
914 void wxWindow::Refresh(
915 bool bEraseBack
916 , const wxRect* pRect
917 )
918 {
919 HWND hWnd = GetHwnd();
920
921 if (hWnd)
922 {
923 if (pRect)
924 {
925 RECTL vOs2Rect;
926
927 vOs2Rect.xLeft = pRect->x;
928 vOs2Rect.yTop = pRect->y;
929 vOs2Rect.xRight = pRect->x + pRect->width;
930 vOs2Rect.yBottom = pRect->y + pRect->height;
931
932 ::WinInvalidateRect(hWnd, &vOs2Rect, bEraseBack);
933 }
934 else
935 ::WinInvalidateRect(hWnd, NULL, bEraseBack);
936 }
937 } // end of wxWindow::Refresh
938
939 // ---------------------------------------------------------------------------
940 // drag and drop
941 // ---------------------------------------------------------------------------
942
943 #if wxUSE_DRAG_AND_DROP
944 void wxWindow::SetDropTarget(
945 wxDropTarget* pDropTarget
946 )
947 {
948 if (m_dropTarget != 0)
949 {
950 m_dropTarget->Revoke(m_hWnd);
951 delete m_dropTarget;
952 }
953 m_dropTarget = pDropTarget;
954 if (m_dropTarget != 0)
955 m_dropTarget->Register(m_hWnd);
956 } // end of wxWindow::SetDropTarget
957 #endif
958
959 //
960 // old style file-manager drag&drop support: we retain the old-style
961 // DragAcceptFiles in parallel with SetDropTarget.
962 //
963 void wxWindow::DragAcceptFiles(
964 bool bAccept
965 )
966 {
967 HWND hWnd = GetHwnd();
968
969 if (hWnd && bAccept)
970 ::DrgAcceptDroppedFiles(hWnd, NULL, NULL, DO_COPY, 0L);
971 } // end of wxWindow::DragAcceptFiles
972
973 // ----------------------------------------------------------------------------
974 // tooltips
975 // ----------------------------------------------------------------------------
976
977 #if wxUSE_TOOLTIPS
978
979 void wxWindow::DoSetToolTip(
980 wxToolTip* pTooltip
981 )
982 {
983 wxWindowBase::DoSetToolTip(pTooltip);
984
985 if (m_tooltip)
986 m_tooltip->SetWindow(this);
987 } // end of wxWindow::DoSetToolTip
988
989 #endif // wxUSE_TOOLTIPS
990
991 // ---------------------------------------------------------------------------
992 // moving and resizing
993 // ---------------------------------------------------------------------------
994
995 // Get total size
996 void wxWindow::DoGetSize(
997 int* pWidth
998 , int* pHeight
999 ) const
1000 {
1001 HWND hWnd = GetHwnd();
1002 RECTL vRect;
1003
1004 ::WinQueryWindowRect(hWnd, &vRect);
1005
1006 if (pWidth)
1007 *pWidth = vRect.xRight - vRect.xLeft;
1008 if (pHeight )
1009 // OS/2 PM is backwards from windows
1010 *pHeight = vRect.yTop - vRect.yBottom;
1011 } // end of wxWindow::DoGetSize
1012
1013 void wxWindow::DoGetPosition(
1014 int* pX
1015 , int* pY
1016 ) const
1017 {
1018 HWND hWnd = GetHwnd();
1019 RECT vRect;
1020 POINTL vPoint;
1021
1022 ::WinQueryWindowRect(hWnd, &vRect);
1023
1024 vPoint.x = vRect.xLeft;
1025 vPoint.y = vRect.yBottom;
1026
1027 //
1028 // We do the adjustments with respect to the parent only for the "real"
1029 // children, not for the dialogs/frames
1030 //
1031 if (!IsTopLevel())
1032 {
1033 HWND hParentWnd = 0;
1034 wxWindow* pParent = GetParent();
1035
1036 if (pParent)
1037 hParentWnd = GetWinHwnd(pParent);
1038
1039 //
1040 // Since we now have the absolute screen coords, if there's a parent we
1041 // must subtract its bottom left corner
1042 //
1043 if (hParentWnd)
1044 {
1045 RECTL vRect2;
1046
1047 ::WinQueryWindowRect(hParentWnd, &vRect2);
1048 vPoint.x -= vRect.xLeft;
1049 vPoint.y -= vRect.yBottom;
1050 }
1051
1052 //
1053 // We may be faking the client origin. So a window that's really at (0,
1054 // 30) may appear (to wxWin apps) to be at (0, 0).
1055 //
1056 wxPoint vPt(pParent->GetClientAreaOrigin());
1057
1058 vPoint.x -= vPt.x;
1059 vPoint.y -= vPt.y;
1060 }
1061
1062 if (pX)
1063 *pX = vPoint.x;
1064 if (pY)
1065 *pY = vPoint.y;
1066 } // end of wxWindow::DoGetPosition
1067
1068 void wxWindow::DoScreenToClient(
1069 int* pX
1070 , int* pY
1071 ) const
1072 {
1073 HWND hWnd = GetHwnd();
1074 SWP vSwp;
1075
1076 ::WinQueryWindowPos(hWnd, &vSwp);
1077
1078 if (pX)
1079 *pX -= vSwp.x;
1080 if (pY)
1081 *pY -= vSwp.y;
1082 } // end of wxWindow::DoScreenToClient
1083
1084 void wxWindow::DoClientToScreen(
1085 int* pX
1086 , int* pY
1087 ) const
1088 {
1089 HWND hWnd = GetHwnd();
1090 SWP vSwp;
1091
1092 ::WinQueryWindowPos(hWnd, &vSwp);
1093
1094 if (pX)
1095 *pX += vSwp.x;
1096 if (pY)
1097 *pY += vSwp.y;
1098 } // end of wxWindow::DoClientToScreen
1099
1100 //
1101 // Get size *available for subwindows* i.e. excluding menu bar etc.
1102 // Must be a frame type window
1103 //
1104 void wxWindow::DoGetClientSize(
1105 int* pWidth
1106 , int* pHeight
1107 ) const
1108 {
1109 HWND hWnd = GetHwnd();
1110 HWND hWndClient;
1111 RECTL vRect;
1112
1113 hWndClient = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
1114 if( hWndClient == NULLHANDLE)
1115 ::WinQueryWindowRect(GetHwnd(), &vRect);
1116 else
1117 ::WinQueryWindowRect(hWndClient, &vRect);
1118
1119 if (pWidth)
1120 *pWidth = vRect.xRight;
1121 if (pHeight)
1122 *pHeight = vRect.yTop;
1123 } // end of wxWindow::DoGetClientSize
1124
1125 void wxWindow::DoMoveWindow(
1126 int nX
1127 , int nY
1128 , int nWidth
1129 , int nHeight
1130 )
1131 {
1132 if ( !::WinSetWindowPos( GetHwnd()
1133 ,HWND_TOP
1134 ,(LONG)nX
1135 ,(LONG)nY
1136 ,(LONG)nWidth
1137 ,(LONG)nHeight
1138 ,SWP_SIZE | SWP_MOVE
1139 ))
1140 {
1141 wxLogLastError("MoveWindow");
1142 }
1143 } // end of wxWindow::DoMoveWindow
1144
1145 //
1146 // Set the size of the window: if the dimensions are positive, just use them,
1147 // but if any of them is equal to -1, it means that we must find the value for
1148 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1149 // which case -1 is a valid value for x and y)
1150 //
1151 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1152 // the width/height to best suit our contents, otherwise we reuse the current
1153 // width/height
1154 //
1155 void wxWindow::DoSetSize(
1156 int nX
1157 , int nY
1158 , int nWidth
1159 , int nHeight
1160 , int nSizeFlags
1161 )
1162 {
1163 //
1164 // Get the current size and position...
1165 //
1166 int nCurrentX;
1167 int nCurrentY;
1168 int nCurrentWidth;
1169 int nCurrentHeight;
1170 wxSize vSize(-1, -1);
1171
1172 GetPosition( &nCurrentX
1173 ,&nCurrentY
1174 );
1175 GetSize( &nCurrentWidth
1176 ,&nCurrentHeight
1177 );
1178
1179 //
1180 // ... and don't do anything (avoiding flicker) if it's already ok
1181 //
1182 if ( nX == nCurrentX &&
1183 nY == nCurrentY &&
1184 nWidth == nCurrentWidth &&
1185 nHeight == nCurrentHeight
1186 )
1187 {
1188 return;
1189 }
1190
1191 if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
1192 nX = nCurrentX;
1193 if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
1194 nY = nCurrentY;
1195
1196 AdjustForParentClientOrigin( nX
1197 ,nY
1198 ,nSizeFlags
1199 );
1200
1201 if (nWidth == -1)
1202 {
1203 if (nSizeFlags & wxSIZE_AUTO_WIDTH)
1204 {
1205 vSize = DoGetBestSize();
1206 nWidth = vSize.x;
1207 }
1208 else
1209 {
1210 //
1211 // Just take the current one
1212 //
1213 nWidth = nCurrentWidth;
1214 }
1215 }
1216
1217 if (nHeight == -1)
1218 {
1219 if (nSizeFlags & wxSIZE_AUTO_HEIGHT)
1220 {
1221 if (vSize.x == -1)
1222 {
1223 vSize = DoGetBestSize();
1224 }
1225 nHeight = vSize.y;
1226 }
1227 else
1228 {
1229 // just take the current one
1230 nHeight = nCurrentHeight;
1231 }
1232 }
1233
1234 DoMoveWindow( nX
1235 ,nY
1236 ,nWidth
1237 ,nHeight
1238 );
1239 } // end of wxWindow::DoSetSize
1240
1241 void wxWindow::DoSetClientSize(
1242 int nWidth
1243 , int nHeight
1244 )
1245 {
1246 wxWindow* pParent = GetParent();
1247 HWND hWnd = GetHwnd();
1248 HWND hParentWnd = (HWND)0;
1249 HWND hClientWnd = (HWND)0;
1250 RECTL vRect;
1251 RECT vRect2;
1252 RECT vRect3;
1253
1254 hClientWnd = ::WinWindowFromID(GetHwnd(), FID_CLIENT);
1255 ::WinQueryWindowRect(hClientWnd, &vRect2);
1256
1257 if (pParent)
1258 hParentWnd = (HWND) pParent->GetHWND();
1259
1260 ::WinQueryWindowRect(hWnd, &vRect);
1261 ::WinQueryWindowRect(hParentWnd, &vRect3);
1262 //
1263 // Find the difference between the entire window (title bar and all)
1264 // and the client area; add this to the new client size to move the
1265 // window. OS/2 is backward from windows on height
1266 //
1267 int nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
1268 int nActualHeight = vRect2.yTop - vRect2.yBottom - vRect.yTop + nHeight;
1269
1270 //
1271 // If there's a parent, must subtract the parent's bottom left corner
1272 // since MoveWindow moves relative to the parent
1273 //
1274 POINTL vPoint;
1275
1276 vPoint.x = vRect2.xLeft;
1277 vPoint.y = vRect2.yBottom;
1278 if (pParent)
1279 {
1280 vPoint.x -= vRect3.xLeft;
1281 vPoint.y -= vRect3.yBottom;
1282 }
1283
1284 DoMoveWindow( vPoint.x
1285 ,vPoint.y
1286 ,nActualWidth
1287 ,nActualHeight
1288 );
1289
1290 wxSizeEvent vEvent( wxSize( nWidth
1291 ,nHeight
1292 )
1293 ,m_windowId
1294 );
1295
1296 vEvent.SetEventObject(this);
1297 GetEventHandler()->ProcessEvent(vEvent);
1298 } // end of wxWindow::DoSetClientSize
1299
1300 wxPoint wxWindow::GetClientAreaOrigin() const
1301 {
1302 return wxPoint(0, 0);
1303 } // end of wxWindow::GetClientAreaOrigin
1304
1305 void wxWindow::AdjustForParentClientOrigin(
1306 int& rX
1307 , int& rY
1308 , int nSizeFlags
1309 )
1310 {
1311 //
1312 // Don't do it for the dialogs/frames - they float independently of their
1313 // parent
1314 //
1315 if (!IsTopLevel())
1316 {
1317 wxWindow* pParent = GetParent();
1318
1319 if (!(nSizeFlags & wxSIZE_NO_ADJUSTMENTS) && pParent)
1320 {
1321 wxPoint vPoint(pParent->GetClientAreaOrigin());
1322 rX += vPoint.x;
1323 rY += vPoint.y;
1324 }
1325 }
1326 } // end of wxWindow::AdjustForParentClientOrigin
1327
1328 // ---------------------------------------------------------------------------
1329 // text metrics
1330 // ---------------------------------------------------------------------------
1331
1332 int wxWindow::GetCharHeight() const
1333 {
1334 HPS hPs;
1335 FONTMETRICS vFontMetrics;
1336 BOOL bRc;
1337
1338 hPs = ::WinGetPS(GetHwnd());
1339
1340 if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics))
1341 return (0);
1342 else
1343 return(vFontMetrics.lMaxAscender + vFontMetrics.lMaxDescender);
1344 ::WinReleasePS(hPs);
1345 } // end of wxWindow::GetCharHeight
1346
1347 int wxWindow::GetCharWidth() const
1348 {
1349 HPS hPs;
1350 FONTMETRICS vFontMetrics;
1351
1352 hPs = ::WinGetPS(GetHwnd());
1353
1354 if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics))
1355 return (0);
1356 else
1357 return(vFontMetrics.lAveCharWidth);
1358 ::WinReleasePS(hPs);
1359 } // end of wxWindow::GetCharWidth
1360
1361 void wxWindow::GetTextExtent(
1362 const wxString& rString
1363 , int* pX
1364 , int* pY
1365 , int* pDescent
1366 , int* pExternalLeading
1367 , const wxFont* pTheFont
1368 ) const
1369 {
1370 const wxFont* pFontToUse = pTheFont;
1371 HPS hPs;
1372
1373 hPs = ::WinGetPS(GetHwnd());
1374 /*
1375 // TODO: Will have to play with fonts later
1376
1377 if (!pFontToUse)
1378 pFontToUse = &m_font;
1379
1380 HFONT hFnt = 0;
1381 HFONT hFfontOld = 0;
1382
1383 if (pFontToUse && pFontToUse->Ok())
1384 {
1385 ::GpiCreateLog
1386 hFnt = (HFONT)((wxFont *)pFontToUse)->GetResourceHandle(); // const_cast
1387 if (hFnt)
1388 hFontOld = (HFONT)SelectObject(dc,fnt);
1389 }
1390
1391 SIZE sizeRect;
1392 TEXTMETRIC tm;
1393 GetTextExtentPoint(dc, string, (int)string.Length(), &sizeRect);
1394 GetTextMetrics(dc, &tm);
1395
1396 if ( fontToUse && fnt && hfontOld )
1397 SelectObject(dc, hfontOld);
1398
1399 ReleaseDC(hWnd, dc);
1400
1401 if ( x )
1402 *x = sizeRect.cx;
1403 if ( y )
1404 *y = sizeRect.cy;
1405 if ( descent )
1406 *descent = tm.tmDescent;
1407 if ( externalLeading )
1408 *externalLeading = tm.tmExternalLeading;
1409 */
1410 ::WinReleasePS(hPs);
1411 }
1412
1413 #if wxUSE_CARET && WXWIN_COMPATIBILITY
1414 // ---------------------------------------------------------------------------
1415 // Caret manipulation
1416 // ---------------------------------------------------------------------------
1417
1418 void wxWindow::CreateCaret(
1419 int nWidth
1420 , int nHeight
1421 )
1422 {
1423 SetCaret(new wxCaret( this
1424 ,nWidth
1425 ,nHeight
1426 ));
1427 } // end of wxWindow::CreateCaret
1428
1429 void wxWindow::CreateCaret(
1430 const wxBitmap* pBitmap
1431 )
1432 {
1433 wxFAIL_MSG("not implemented");
1434 } // end of wxWindow::CreateCaret
1435
1436 void wxWindow::ShowCaret(
1437 bool bShow
1438 )
1439 {
1440 wxCHECK_RET( m_caret, "no caret to show" );
1441
1442 m_caret->Show(bShow);
1443 } // end of wxWindow::ShowCaret
1444
1445 void wxWindow::DestroyCaret()
1446 {
1447 SetCaret(NULL);
1448 } // end of wxWindow::DestroyCaret
1449
1450 void wxWindow::SetCaretPos(
1451 int nX
1452 , int nY)
1453 {
1454 wxCHECK_RET( m_caret, "no caret to move" );
1455
1456 m_caret->Move( nX
1457 ,nY
1458 );
1459 } // end of wxWindow::SetCaretPos
1460
1461 void wxWindow::GetCaretPos(
1462 int* pX
1463 , int* pY
1464 ) const
1465 {
1466 wxCHECK_RET( m_caret, "no caret to get position of" );
1467
1468 m_caret->GetPosition( pX
1469 ,pY
1470 );
1471 } // end of wxWindow::GetCaretPos
1472
1473 #endif //wxUSE_CARET
1474
1475 // ---------------------------------------------------------------------------
1476 // popup menu
1477 // ---------------------------------------------------------------------------
1478
1479 bool wxWindow::DoPopupMenu(
1480 wxMenu* pMenu
1481 , int nX
1482 , int nY
1483 )
1484 {
1485 HWND hWnd = GetHwnd();
1486 HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
1487 HWND hMenu = GetHmenuOf(pMenu);
1488
1489 pMenu->SetInvokingWindow(this);
1490 pMenu->UpdateUI();
1491
1492 DoClientToScreen( &nX
1493 ,&nY
1494 );
1495 wxCurrentPopupMenu = pMenu;
1496
1497 ::WinPopupMenu( hWndParent
1498 ,hWnd
1499 ,hMenu
1500 ,nX
1501 ,nY
1502 ,0L
1503 ,PU_MOUSEBUTTON2DOWN | PU_MOUSEBUTTON2 | PU_KEYBOARD
1504 );
1505 wxYield();
1506 wxCurrentPopupMenu = NULL;
1507
1508 pMenu->SetInvokingWindow(NULL);
1509 return TRUE;
1510 } // end of wxWindow::DoPopupMenu
1511
1512 // ===========================================================================
1513 // pre/post message processing
1514 // ===========================================================================
1515
1516 MRESULT wxWindow::OS2DefWindowProc(
1517 WXUINT uMsg
1518 , WXWPARAM wParam
1519 , WXLPARAM lParam
1520 )
1521 {
1522 DEBUG_PRINTF(wxWindow::OS2DefWindowProc);
1523
1524 if (m_fnOldWndProc)
1525 return (MRESULT)m_fnOldWndProc(GetHWND(), (ULONG)uMsg, (MPARAM)wParam, (MPARAM)lParam);
1526 else
1527 return ::WinDefWindowProc(GetHWND(), (ULONG)uMsg, (MPARAM)wParam, (MPARAM)lParam);
1528 } // end of wxWindow::OS2DefWindowProc
1529
1530 bool wxWindow::OS2ProcessMessage(
1531 WXMSG* pMsg
1532 )
1533 {
1534 QMSG* pQMsg = (QMSG*)pMsg;
1535
1536 if (m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL))
1537 {
1538 //
1539 // Intercept dialog navigation keys
1540 //
1541 bool bProcess = TRUE;
1542 USHORT uKeyFlags = SHORT1FROMMP(pQMsg->mp1);
1543
1544 if (uKeyFlags & KC_KEYUP)
1545 bProcess = FALSE;
1546
1547 if (uKeyFlags & KC_ALT)
1548 bProcess = FALSE;
1549
1550 if (!(uKeyFlags & KC_VIRTUALKEY))
1551 bProcess = FALSE;
1552
1553 if (bProcess)
1554 {
1555 bool bCtrlDown = IsCtrlDown();
1556 bool bShiftDown = IsShiftDown();
1557
1558 //
1559 // WM_QUERYDLGCODE: ask the control if it wants the key for itself,
1560 // don't process it if it's the case (except for Ctrl-Tab/Enter
1561 // combinations which are always processed)
1562 //
1563 ULONG ulDlgCode = 0;
1564
1565 if (!bCtrlDown)
1566 {
1567 ulDlgCode = (ULONG)::WinSendMsg(pQMsg->hwnd, WM_QUERYDLGCODE, pQMsg, 0);
1568 }
1569
1570 bool bForward = TRUE;
1571 bool bWindowChange = FALSE;
1572
1573 switch (SHORT2FROMMP(pQMsg->mp2))
1574 {
1575 //
1576 // Going to make certain assumptions about specific types of controls
1577 // here, so we may have to alter some things later if they prove invalid
1578 //
1579 case VK_TAB:
1580 //
1581 // Shift tabl will always be a nav-key but tabs may be wanted
1582 //
1583 if (!bShiftDown)
1584 {
1585 bProcess = FALSE;
1586 }
1587 else
1588 {
1589 //
1590 // Entry Fields want tabs for themselve usually
1591 //
1592 switch (ulDlgCode)
1593 {
1594 case DLGC_ENTRYFIELD:
1595 case DLGC_MLE:
1596 bProcess = TRUE;
1597 break;
1598
1599 default:
1600 bProcess = FALSE;
1601 }
1602
1603 //
1604 // Ctrl-Tab cycles thru notebook pages
1605 //
1606 bWindowChange = bCtrlDown;
1607 bForward = !bShiftDown;
1608 }
1609 break;
1610
1611 case VK_UP:
1612 case VK_LEFT:
1613 if (bCtrlDown)
1614 bProcess = FALSE;
1615 else
1616 bForward = FALSE;
1617 break;
1618
1619 case VK_DOWN:
1620 case VK_RIGHT:
1621 if (bCtrlDown)
1622 bProcess = FALSE;
1623 break;
1624
1625 case VK_ENTER:
1626 {
1627 if (bCtrlDown)
1628 {
1629 //
1630 // ctrl-enter is not processed
1631 //
1632 return FALSE;
1633 }
1634 else if (ulDlgCode & DLGC_BUTTON)
1635 {
1636 //
1637 // buttons want process Enter themselevs
1638 //
1639 bProcess = FALSE;
1640 }
1641 else
1642 {
1643 wxPanel* pPanel = wxDynamicCast(this, wxPanel);
1644 wxButton* pBtn = NULL;
1645
1646 if (pPanel)
1647 {
1648 //
1649 // Panel may have a default button which should
1650 // be activated by Enter
1651 //
1652 pBtn = pPanel->GetDefaultItem();
1653 }
1654
1655 if (pBtn && pBtn->IsEnabled())
1656 {
1657 //
1658 // If we do have a default button, do press it
1659 //
1660 pBtn->OS2Command(BN_CLICKED, 0 /* unused */);
1661 return TRUE;
1662 }
1663 // else: but if it does not it makes sense to make
1664 // it work like a TAB - and that's what we do.
1665 // Note that Ctrl-Enter always works this way.
1666 }
1667 }
1668 break;
1669
1670 default:
1671 bProcess = FALSE;
1672 }
1673
1674 if (bProcess)
1675 {
1676 wxNavigationKeyEvent vEvent;
1677
1678 vEvent.SetDirection(bForward);
1679 vEvent.SetWindowChange(bWindowChange);
1680 vEvent.SetEventObject(this);
1681
1682 if (GetEventHandler()->ProcessEvent(vEvent))
1683 {
1684 wxButton* pBtn = wxDynamicCast(FindFocus(), wxButton);
1685
1686 if (pBtn)
1687 {
1688 //
1689 // The button which has focus should be default
1690 //
1691 pBtn->SetDefault();
1692 }
1693 return TRUE;
1694 }
1695 }
1696 }
1697 //
1698 // Let Dialogs process
1699 //
1700 if (::WinSendMsg(pQMsg->hwnd, WM_QUERYDLGCODE, pQMsg, 0));
1701 return TRUE;
1702 }
1703
1704 #if wxUSE_TOOLTIPS
1705 if ( m_tooltip )
1706 {
1707 // relay mouse move events to the tooltip control
1708 QMSG* pQMsg = (QMSG*)pMsg;
1709
1710 if (pQMsg->msg == WM_MOUSEMOVE )
1711 m_tooltip->RelayEvent(pMsg);
1712 }
1713 #endif // wxUSE_TOOLTIPS
1714
1715 return FALSE;
1716 } // end of wxWindow::OS2ProcessMessage
1717
1718 bool wxWindow::OS2TranslateMessage(
1719 WXMSG* pMsg
1720 )
1721 {
1722 #if wxUSE_ACCEL
1723 return m_acceleratorTable.Translate(m_hWnd, pMsg);
1724 #else
1725 return FALSE;
1726 #endif //wxUSE_ACCEL
1727 } // end of wxWindow::OS2TranslateMessage
1728
1729 // ---------------------------------------------------------------------------
1730 // message params unpackers
1731 // ---------------------------------------------------------------------------
1732
1733 void wxWindow::UnpackCommand(
1734 WXWPARAM wParam
1735 , WXLPARAM lParam
1736 , WORD* pId
1737 , WXHWND* phWnd
1738 , WORD* pCmd
1739 )
1740 {
1741 *pId = LOWORD(wParam);
1742 *phWnd = NULL; // or may be GetHWND() ?
1743 *pCmd = LOWORD(lParam);
1744 } // end of wxWindow::UnpackCommand
1745
1746 void wxWindow::UnpackActivate(
1747 WXWPARAM wParam
1748 , WXLPARAM lParam
1749 , WXWORD* pState
1750 , WXHWND* phWnd
1751 )
1752 {
1753 *pState = LOWORD(wParam);
1754 *phWnd = (WXHWND)lParam;
1755 } // end of wxWindow::UnpackActivate
1756
1757 void wxWindow::UnpackScroll(
1758 WXWPARAM wParam
1759 , WXLPARAM lParam
1760 , WXWORD* pCode
1761 , WXWORD* pPos
1762 , WXHWND* phWnd
1763 )
1764 {
1765 *pCode = LOWORD(wParam);
1766 *pPos = HIWORD(wParam);
1767 *phWnd = (WXHWND)lParam;
1768 } // end of wxWindow::UnpackScroll
1769
1770 void wxWindow::UnpackMenuSelect(
1771 WXWPARAM wParam
1772 , WXLPARAM lParam
1773 , WXWORD* pItem
1774 , WXWORD* pFlags
1775 , WXHMENU* phMenu
1776 )
1777 {
1778 *pItem = (WXWORD)LOWORD(wParam);
1779 *pFlags = HIWORD(wParam);
1780 *phMenu = (WXHMENU)lParam;
1781 } // end of wxWindow::UnpackMenuSelect
1782
1783 // ---------------------------------------------------------------------------
1784 // Main wxWindows window proc and the window proc for wxWindow
1785 // ---------------------------------------------------------------------------
1786
1787 //
1788 // Hook for new window just as it's being created, when the window isn't yet
1789 // associated with the handle
1790 //
1791 wxWindow* wxWndHook = NULL;
1792
1793 //
1794 // Main window proc
1795 //
1796 MRESULT EXPENTRY wxWndProc(
1797 HWND hWnd
1798 , ULONG ulMsg
1799 , MPARAM wParam
1800 , MPARAM lParam
1801 )
1802 {
1803 //
1804 // Trace all ulMsgs - useful for the debugging
1805 //
1806 #ifdef __WXDEBUG__
1807 DEBUG_PRINTF(__WXDEBUG__wxWndProc);
1808 wxLogTrace(wxTraceMessages, wxT("Processing %s(wParam=%8lx, lParam=%8lx)"),
1809 wxGetMessageName(ulMsg), wParam, lParam);
1810 #endif // __WXDEBUG__
1811
1812 wxWindow* pWnd = wxFindWinFromHandle((WXHWND)hWnd);
1813
1814 //
1815 // When we get the first message for the HWND we just created, we associate
1816 // it with wxWindow stored in wxWndHook
1817 //
1818 if (!pWnd && wxWndHook)
1819 {
1820 wxAssociateWinWithHandle(hWnd, wxWndHook);
1821 pWnd = wxWndHook;
1822 wxWndHook = NULL;
1823 pWnd->SetHWND((WXHWND)hWnd);
1824 }
1825
1826 MRESULT rc = (MRESULT)0;
1827
1828
1829 //
1830 // Stop right here if we don't have a valid handle in our wxWindow object.
1831 //
1832 if (pWnd && !pWnd->GetHWND())
1833 {
1834 pWnd->SetHWND((WXHWND) hWnd);
1835 rc = pWnd->OS2DefWindowProc(ulMsg, wParam, lParam );
1836 pWnd->SetHWND(0);
1837 }
1838 else
1839 {
1840 if (pWnd)
1841 rc = pWnd->OS2WindowProc(ulMsg, wParam, lParam);
1842 else
1843 rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam);
1844 }
1845
1846 return rc;
1847 } // end of wxWndProc
1848
1849 //
1850 // We will add (or delete) messages we need to handle at this default
1851 // level as we go
1852 //
1853 MRESULT wxWindow::OS2WindowProc(
1854 WXUINT uMsg
1855 , WXWPARAM wParam
1856 , WXLPARAM lParam
1857 )
1858 {
1859 //
1860 // Did we process the uMsg?
1861 //
1862 bool bProcessed = FALSE;
1863 bool bAllow;
1864 MRESULT mResult;
1865 WXHICON hIcon;
1866 WXHBRUSH hBrush;
1867
1868 //
1869 // For most messages we should return 0 when we do process the message
1870 //
1871 mResult = (MRESULT)0;
1872
1873 switch (uMsg)
1874 {
1875 case WM_CREATE:
1876 {
1877 bool bMayCreate;
1878
1879 bProcessed = HandleCreate( (WXLPCREATESTRUCT)lParam
1880 ,&bMayCreate
1881 );
1882 if (bProcessed)
1883 {
1884 //
1885 // Return 0 to bAllow window creation
1886 //
1887 mResult = (MRESULT)(bMayCreate ? 0 : -1);
1888 }
1889 }
1890 break;
1891
1892 case WM_DESTROY:
1893 HandleDestroy();
1894 bProcessed = TRUE;
1895 break;
1896
1897 case WM_MOVE:
1898 bProcessed = HandleMove( LOWORD(lParam)
1899 ,HIWORD(lParam)
1900 );
1901 break;
1902
1903 case WM_SIZE:
1904 bProcessed = HandleSize( LOWORD(lParam)
1905 ,HIWORD(lParam)
1906 ,(WXUINT)wParam
1907 );
1908 break;
1909
1910 case WM_ACTIVATE:
1911 {
1912 WXWORD wState;
1913 WXHWND hWnd;
1914
1915 UnpackActivate( wParam
1916 ,lParam
1917 ,&wState
1918 ,&hWnd
1919 );
1920
1921 bProcessed = HandleActivate( wState
1922 ,(WXHWND)hWnd
1923 );
1924 bProcessed = FALSE;
1925 }
1926 break;
1927
1928 case WM_SETFOCUS:
1929 if (SHORT1FROMMP((MPARAM)lParam) == TRUE)
1930 bProcessed = HandleSetFocus((WXHWND)(HWND)wParam);
1931 else
1932 bProcessed = HandleKillFocus((WXHWND)(HWND)wParam);
1933 break;
1934
1935 case WM_PAINT:
1936 DEBUG_PRINTF(WM_PAINT)
1937 bProcessed = HandlePaint();
1938 break;
1939
1940 case WM_CLOSE:
1941 //
1942 // Don't let the DefWindowProc() destroy our window - we'll do it
1943 // ourselves in ~wxWindow
1944 //
1945 bProcessed = TRUE;
1946 mResult = (MRESULT)TRUE;
1947 DEBUG_PRINTF(WM_CLOSE)
1948 break;
1949
1950 case WM_SHOW:
1951 DEBUG_PRINTF(WM_SHOW)
1952 bProcessed = HandleShow(wParam != 0, (int)lParam);
1953 break;
1954
1955 //
1956 // Under OS2 PM Joysticks are treated just like mouse events
1957 // The "Motion" events will be prevelent in joysticks
1958 //
1959 case WM_MOUSEMOVE:
1960 case WM_BUTTON1DOWN:
1961 case WM_BUTTON1UP:
1962 case WM_BUTTON1DBLCLK:
1963 case WM_BUTTON1MOTIONEND:
1964 case WM_BUTTON1MOTIONSTART:
1965 case WM_BUTTON2DOWN:
1966 case WM_BUTTON2UP:
1967 case WM_BUTTON2DBLCLK:
1968 case WM_BUTTON2MOTIONEND:
1969 case WM_BUTTON2MOTIONSTART:
1970 case WM_BUTTON3DOWN:
1971 case WM_BUTTON3UP:
1972 case WM_BUTTON3DBLCLK:
1973 case WM_BUTTON3MOTIONEND:
1974 case WM_BUTTON3MOTIONSTART:
1975 {
1976 short x = LOWORD(lParam);
1977 short y = HIWORD(lParam);
1978
1979 bProcessed = HandleMouseEvent(uMsg, x, y, (WXUINT)wParam);
1980 }
1981 break;
1982 case WM_SYSCOMMAND:
1983 bProcessed = HandleSysCommand(wParam, lParam);
1984 break;
1985
1986 case WM_COMMAND:
1987 {
1988 WORD id, cmd;
1989 WXHWND hwnd;
1990 DEBUG_PRINTF(WM_COMMAND-in)
1991 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
1992
1993 bProcessed = HandleCommand(id, cmd, hwnd);
1994 DEBUG_PRINTF(WM_COMMAND-out)
1995 }
1996 break;
1997
1998 //
1999 // For these messages we must return TRUE if process the message
2000 //
2001 case WM_DRAWITEM:
2002 case WM_MEASUREITEM:
2003 {
2004 int idCtrl = (UINT)wParam;
2005 if ( uMsg == WM_DRAWITEM )
2006 {
2007 bProcessed = OS2OnDrawItem(idCtrl,
2008 (WXDRAWITEMSTRUCT *)lParam);
2009 }
2010 else
2011 {
2012 bProcessed = OS2OnMeasureItem(idCtrl,
2013 (WXMEASUREITEMSTRUCT *)lParam);
2014 }
2015
2016 if ( bProcessed )
2017 mResult = (MRESULT)TRUE;
2018 }
2019 break;
2020
2021 case WM_QUERYDLGCODE:
2022 if ( m_lDlgCode )
2023 {
2024 mResult = (MRESULT)m_lDlgCode;
2025 bProcessed = TRUE;
2026 }
2027 //
2028 //else: get the dlg code from the DefWindowProc()
2029 //
2030 break;
2031
2032 //
2033 // In OS/2 PM all keyboard events are of the WM_CHAR type. Virtual key and key-up
2034 // and key-down events are obtained from the WM_CHAR params.
2035 //
2036 case WM_CHAR:
2037 {
2038 USHORT uKeyFlags = SHORT1FROMMP((MPARAM)wParam);
2039
2040 if (uKeyFlags & KC_KEYUP)
2041 {
2042 bProcessed = HandleKeyUp((WXDWORD)wParam, lParam);
2043 break;
2044 }
2045 else // keydown event
2046 {
2047 //
2048 // If this has been processed by an event handler,
2049 // return 0 now (we've handled it). DON't RETURN
2050 // we still need to process further
2051 //
2052 HandleKeyDown((WXDWORD)wParam, lParam);
2053 if (uKeyFlags & KC_VIRTUALKEY)
2054 {
2055 USHORT uVk = SHORT2FROMMP((MPARAM)lParam);
2056
2057 //
2058 // We consider these message "not interesting" to OnChar
2059 //
2060 if (uVk == VK_SHIFT || uVk == VK_CTRL )
2061 {
2062 bProcessed = TRUE;
2063 break;
2064 }
2065 switch(uVk)
2066 {
2067 //
2068 // Avoid duplicate messages to OnChar for these ASCII keys: they
2069 // will be translated by TranslateMessage() and received in WM_CHAR
2070 case VK_ESC:
2071 case VK_SPACE:
2072 case VK_ENTER:
2073 case VK_BACKSPACE:
2074 case VK_TAB:
2075 // But set processed to FALSE, not TRUE to still pass them to
2076 // the control's default window proc - otherwise built-in
2077 // keyboard handling won't work
2078 bProcessed = FALSE;
2079 break;
2080
2081 case VK_LEFT:
2082 case VK_RIGHT:
2083 case VK_DOWN:
2084 case VK_UP:
2085 default:
2086 bProcessed = HandleChar((WXDWORD)wParam, lParam);
2087 }
2088 break;
2089 }
2090 else // WM_CHAR -- Always an ASCII character
2091 {
2092 bProcessed = HandleChar((WXDWORD)wParam, lParam, TRUE);
2093 break;
2094 }
2095 }
2096 }
2097
2098 case WM_HSCROLL:
2099 case WM_VSCROLL:
2100 {
2101 WXWORD wCode;
2102 WXWORD wPos;
2103 WXHWND hWnd;
2104 UnpackScroll( wParam
2105 ,lParam
2106 ,&wCode
2107 ,&wPos
2108 ,&hWnd
2109 );
2110
2111 bProcessed = OS2OnScroll( uMsg == WM_HSCROLL ? wxHORIZONTAL
2112 : wxVERTICAL
2113 ,wCode
2114 ,wPos
2115 ,hWnd
2116 );
2117 }
2118 break;
2119
2120 #if defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
2121 case WM_CTLCOLORCHANGE:
2122 {
2123 bProcessed = HandleCtlColor(&hBrush);
2124 }
2125 break;
2126 #endif
2127 //
2128 // Instead of CTLCOLOR messages PM sends QUERYWINDOWPARAMS to
2129 // things such as colors and fonts and such
2130 //
2131 case WM_QUERYWINDOWPARAMS:
2132 {
2133 PWNDPARAMS pWndParams = (PWNDPARAMS)wParam;
2134
2135 bProcessed = HandleWindowParams( pWndParams
2136 ,lParam
2137 );
2138 }
2139 break;
2140
2141 // the return value for this message is ignored
2142 case WM_SYSCOLORCHANGE:
2143 bProcessed = HandleSysColorChange();
2144 break;
2145
2146 case WM_REALIZEPALETTE:
2147 bProcessed = HandlePaletteChanged();
2148 break;
2149
2150 case WM_PRESPARAMCHANGED:
2151 bProcessed = HandlePresParamChanged(wParam);
2152 break;
2153
2154 // move this to wxFrame
2155 case WM_ERASEBACKGROUND:
2156 bProcessed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
2157 if (bProcessed)
2158 {
2159 //
2160 // We processed the message, i.e. erased the background
2161 //
2162 mResult = (MRESULT)TRUE;
2163 }
2164 break;
2165
2166 // move all drag and drops to wxDrg
2167 case WM_ENDDRAG:
2168 bProcessed = HandleEndDrag(wParam);
2169 break;
2170
2171 case WM_INITDLG:
2172 bProcessed = HandleInitDialog((WXHWND)(HWND)wParam);
2173
2174 if ( bProcessed )
2175 {
2176 // we never set focus from here
2177 mResult = FALSE;
2178 }
2179 break;
2180
2181 // wxFrame specific message
2182 case WM_MINMAXFRAME:
2183 bProcessed = HandleGetMinMaxInfo((PSWP)wParam);
2184 break;
2185
2186 case WM_SYSVALUECHANGED:
2187 // TODO: do something
2188 mResult = (MRESULT)TRUE;
2189 break;
2190
2191 //
2192 // Comparable to WM_SETPOINTER for windows, only for just controls
2193 //
2194 case WM_CONTROLPOINTER:
2195 bProcessed = HandleSetCursor( SHORT1FROMMP(wParam) // Control ID
2196 ,(HWND)lParam // Cursor Handle
2197 );
2198 if (bProcessed )
2199 {
2200 //
2201 // Returning TRUE stops the DefWindowProc() from further
2202 // processing this message - exactly what we need because we've
2203 // just set the cursor.
2204 //
2205 mResult = (MRESULT)TRUE;
2206 }
2207 break;
2208 }
2209 if (!bProcessed)
2210 {
2211 #ifdef __WXDEBUG__
2212 wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."),
2213 wxGetMessageName(uMsg));
2214 #endif // __WXDEBUG__
2215 if (IsKindOf(CLASSINFO(wxFrame)))
2216 mResult = ::WinDefWindowProc(m_hWnd, uMsg, wParam, lParam);
2217 else
2218 mResult = OS2DefWindowProc(uMsg, wParam, lParam);
2219 }
2220 return mResult;
2221 } // end of wxWindow::OS2WindowProc
2222
2223 //
2224 // Dialog window proc
2225 //
2226 MRESULT wxDlgProc(
2227 HWND hWnd
2228 , UINT uMsg
2229 , MPARAM wParam
2230 , MPARAM lParam)
2231 {
2232 if (uMsg == WM_INITDLG)
2233 {
2234 //
2235 // For this message, returning TRUE tells system to set focus to the
2236 // first control in the dialog box
2237 //
2238 return (MRESULT)TRUE;
2239 }
2240 else
2241 {
2242 //
2243 // For all the other ones, FALSE means that we didn't process the
2244 // message
2245 //
2246 return (MRESULT)0;
2247 }
2248 } // end of wxDlgProc
2249
2250 wxWindow* wxFindWinFromHandle(
2251 WXHWND hWnd
2252 )
2253 {
2254 wxNode* pNode = wxWinHandleList->Find((long)hWnd);
2255
2256 if (!pNode)
2257 return NULL;
2258 return (wxWindow *)pNode->Data();
2259 } // end of wxFindWinFromHandle
2260
2261 void wxAssociateWinWithHandle(
2262 HWND hWnd
2263 , wxWindow* pWin
2264 )
2265 {
2266 //
2267 // Adding NULL hWnd is (first) surely a result of an error and
2268 // (secondly) breaks menu command processing
2269 //
2270 wxCHECK_RET( hWnd != (HWND)NULL,
2271 wxT("attempt to add a NULL hWnd to window list ignored") );
2272
2273
2274 wxWindow* pOldWin = wxFindWinFromHandle((WXHWND) hWnd);
2275
2276 if (pOldWin && (pOldWin != pWin))
2277 {
2278 wxString str(pWin->GetClassInfo()->GetClassName());
2279 wxLogError( "Bug! Found existing HWND %X for new window of class %s"
2280 ,(int)hWnd
2281 ,(const char*)str
2282 );
2283 }
2284 else if (!pOldWin)
2285 {
2286 wxWinHandleList->Append( (long)hWnd
2287 ,pWin
2288 );
2289 }
2290 } // end of wxAssociateWinWithHandle
2291
2292 void wxRemoveHandleAssociation(
2293 wxWindow* pWin
2294 )
2295 {
2296 wxWinHandleList->DeleteObject(pWin);
2297 } // end of wxRemoveHandleAssociation
2298
2299 //
2300 // Default destroyer - override if you destroy it in some other way
2301 // (e.g. with MDI child windows)
2302 //
2303 void wxWindow::OS2DestroyWindow()
2304 {
2305 }
2306
2307 void wxWindow::OS2DetachWindowMenu()
2308 {
2309 if (m_hMenu)
2310 {
2311 HMENU hMenu = (HMENU)m_hMenu;
2312
2313 int nN = (int)::WinSendMsg(hMenu, MM_QUERYITEMCOUNT, 0, 0);
2314 int i;
2315
2316 for (i = 0; i < nN; i++)
2317 {
2318 wxChar zBuf[100];
2319 int nChars = (int)::WinSendMsg( hMenu
2320 ,MM_QUERYITEMTEXT
2321 ,MPFROM2SHORT(i, nN)
2322 ,zBuf
2323 );
2324 if (!nChars)
2325 {
2326 wxLogLastError(wxT("GetMenuString"));
2327 continue;
2328 }
2329
2330 if (wxStrcmp(zBuf, wxT("&Window")) == 0)
2331 {
2332 ::WinSendMsg(hMenu, MM_DELETEITEM, MPFROM2SHORT(i, TRUE), 0);
2333 break;
2334 }
2335 }
2336 }
2337 } // end of wxWindow::OS2DetachWindowMenu
2338
2339 bool wxWindow::OS2Create(
2340 WXHWND hParent
2341 , PSZ zClass
2342 , const wxChar* zTitle
2343 , WXDWORD dwStyle
2344 , long lX
2345 , long lY
2346 , long lWidth
2347 , long lHeight
2348 , WXHWND hOwner
2349 , WXHWND hZOrder
2350 , unsigned long ulId
2351 , void* pCtlData
2352 , void* pPresParams
2353 )
2354 {
2355 ERRORID vError;
2356 wxString sError;
2357 long lX1 = 0L;
2358 long lY1 = 0L;
2359 long lWidth1 = 20L;
2360 long lHeight1 = 20L;
2361 int nControlId = 0;
2362 int nNeedsubclass = 0;
2363 PCSZ pszClass = zClass;
2364
2365 //
2366 // Find parent's size, if it exists, to set up a possible default
2367 // panel size the size of the parent window
2368 //
2369 RECTL vParentRect;
2370 HWND hWndClient;
2371
2372 if (lX > -1L)
2373 lX1 = lX;
2374 if (lY > -1L)
2375 lY1 = lY;
2376 if (lWidth > -1L)
2377 lWidth1 = lWidth;
2378 if (lHeight > -1L)
2379 lHeight1 = lHeight;
2380
2381 wxWndHook = this;
2382
2383 //
2384 // check to see if the new window is a standard control
2385 //
2386 if ((ULONG)zClass == (ULONG)WC_BUTTON ||
2387 (ULONG)zClass == (ULONG)WC_COMBOBOX ||
2388 (ULONG)zClass == (ULONG)WC_CONTAINER ||
2389 (ULONG)zClass == (ULONG)WC_ENTRYFIELD ||
2390 (ULONG)zClass == (ULONG)WC_FRAME ||
2391 (ULONG)zClass == (ULONG)WC_LISTBOX ||
2392 (ULONG)zClass == (ULONG)WC_MENU ||
2393 (ULONG)zClass == (ULONG)WC_NOTEBOOK ||
2394 (ULONG)zClass == (ULONG)WC_SCROLLBAR ||
2395 (ULONG)zClass == (ULONG)WC_SPINBUTTON ||
2396 (ULONG)zClass == (ULONG)WC_STATIC ||
2397 (ULONG)zClass == (ULONG)WC_TITLEBAR ||
2398 (ULONG)zClass == (ULONG)WC_VALUESET
2399 )
2400 {
2401 nControlId = ulId;
2402 }
2403 else
2404 {
2405 // no standard controls
2406 if(wxString (wxT("wxFrameClass")) == wxString(zClass) )
2407 {
2408 pszClass = WC_FRAME;
2409 nNeedsubclass = 1;
2410 }
2411 else
2412 {
2413 nControlId = ulId;
2414 if(nControlId < 0)
2415 nControlId = FID_CLIENT;
2416 }
2417 }
2418
2419 //
2420 // We will either have a registered class via string name or a standard PM Class via a long
2421 //
2422 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)hParent
2423 ,zClass
2424 ,(PSZ)zTitle ? zTitle : wxT("")
2425 ,(ULONG)dwStyle
2426 ,(LONG)lX1
2427 ,(LONG)lY1
2428 ,(LONG)lWidth
2429 ,(LONG)lHeight
2430 ,hOwner
2431 ,HWND_TOP
2432 ,(ULONG)nControlId
2433 ,pCtlData
2434 ,pPresParams
2435 );
2436 if (!m_hWnd)
2437 {
2438 vError = ::WinGetLastError(vHabmain);
2439 sError = wxPMErrorToStr(vError);
2440 wxLogError("Can't create window of class %s!. Error: %s\n", zClass, sError);
2441 return FALSE;
2442 }
2443 ::WinSetWindowULong(m_hWnd, QWL_USER, (ULONG) this);
2444 wxWndHook = NULL;
2445
2446 #ifdef __WXDEBUG__
2447 wxNode* pNode = wxWinHandleList->Member(this);
2448
2449 if (pNode)
2450 {
2451 HWND hWnd = (HWND)pNode->GetKeyInteger();
2452
2453 if (hWnd != (HWND)m_hWnd)
2454
2455 {
2456 wxLogError("A second HWND association is being added for the same window!");
2457 }
2458 }
2459 #endif
2460 wxAssociateWinWithHandle((HWND)m_hWnd
2461 ,this
2462 );
2463 //
2464 // Now need to subclass window.
2465 //
2466 if(!nNeedsubclass)
2467 {
2468 wxAssociateWinWithHandle((HWND)m_hWnd,this);
2469 }
2470 else
2471 {
2472 SubclassWin(GetHWND());
2473 }
2474 return TRUE;
2475 } // end of wxWindow::OS2Create
2476
2477 // ===========================================================================
2478 // OS2 PM message handlers
2479 // ===========================================================================
2480
2481 // ---------------------------------------------------------------------------
2482 // window creation/destruction
2483 // ---------------------------------------------------------------------------
2484
2485 bool wxWindow::HandleCreate(
2486 WXLPCREATESTRUCT vCs
2487 , bool* pbMayCreate
2488 )
2489 {
2490 wxWindowCreateEvent vEvent(this);
2491
2492 (void)GetEventHandler()->ProcessEvent(vEvent);
2493 *pbMayCreate = TRUE;
2494 return TRUE;
2495 } // end of wxWindow::HandleCreate
2496
2497 bool wxWindow::HandleDestroy()
2498 {
2499 wxWindowDestroyEvent vEvent(this);
2500
2501 (void)GetEventHandler()->ProcessEvent(vEvent);
2502
2503 //
2504 // Delete our drop target if we've got one
2505 //
2506 #if wxUSE_DRAG_AND_DROP
2507 if (m_dropTarget != NULL)
2508 {
2509 m_dropTarget->Revoke(m_hWnd);
2510 delete m_dropTarget;
2511 m_dropTarget = NULL;
2512 }
2513 #endif // wxUSE_DRAG_AND_DROP
2514
2515 //
2516 // WM_DESTROY handled
2517 //
2518 return TRUE;
2519 } // end of wxWindow::HandleDestroy
2520
2521 // ---------------------------------------------------------------------------
2522 // activation/focus
2523 // ---------------------------------------------------------------------------
2524 void wxWindow::OnSetFocus(
2525 wxFocusEvent& rEvent
2526 )
2527 {
2528 //
2529 // Panel wants to track the window which was the last to have focus in it,
2530 // so we want to set ourselves as the window which last had focus
2531 //
2532 // Notice that it's also important to do it upwards the tree becaus
2533 // otherwise when the top level panel gets focus, it won't set it back to
2534 // us, but to some other sibling
2535 //
2536 wxWindow* pWin = this;
2537
2538 while (pWin)
2539 {
2540 wxWindow* pParent = pWin->GetParent();
2541 wxPanel* pPanel = wxDynamicCast( pParent
2542 ,wxPanel
2543 );
2544 if (pPanel)
2545 {
2546 pPanel->SetLastFocus(pWin);
2547 }
2548 pWin = pParent;
2549 }
2550
2551 wxLogTrace(_T("focus"), _T("%s (0x%08x) gets focus"),
2552 GetClassInfo()->GetClassName(), GetHandle());
2553
2554 rEvent.Skip();
2555 } // end of wxWindow::OnSetFocus
2556
2557 bool wxWindow::HandleActivate(
2558 int nState
2559 , WXHWND WXUNUSED(hActivate)
2560 )
2561 {
2562 wxActivateEvent vEvent( wxEVT_ACTIVATE
2563 ,(bool)nState
2564 ,m_windowId
2565 );
2566 vEvent.SetEventObject(this);
2567 return GetEventHandler()->ProcessEvent(vEvent);
2568 } // end of wxWindow::HandleActivate
2569
2570 bool wxWindow::HandleSetFocus(
2571 WXHWND WXUNUSED(hWnd)
2572 )
2573 {
2574 #if wxUSE_CARET
2575 //
2576 // Deal with caret
2577 //
2578 if (m_caret)
2579 {
2580 m_caret->OnSetFocus();
2581 }
2582 #endif // wxUSE_CARET
2583
2584 //
2585 // Panel wants to track the window which was the last to have focus in it
2586 //
2587 wxPanel* pPanel = wxDynamicCast( GetParent()
2588 ,wxPanel
2589 );
2590 if (pPanel)
2591 {
2592 pPanel->SetLastFocus(this);
2593 }
2594
2595 wxFocusEvent vEvent(wxEVT_SET_FOCUS, m_windowId);
2596
2597 vEvent.SetEventObject(this);
2598 return GetEventHandler()->ProcessEvent(vEvent);
2599 } // end of wxWindow::HandleSetFocus
2600
2601 bool wxWindow::HandleKillFocus(
2602 WXHWND WXUNUSED(hWnd)
2603 )
2604 {
2605 #if wxUSE_CARET
2606 //
2607 // Deal with caret
2608 //
2609 if (m_caret)
2610 {
2611 m_caret->OnKillFocus();
2612 }
2613 #endif // wxUSE_CARET
2614
2615 wxFocusEvent vEvent( wxEVT_KILL_FOCUS
2616 ,m_windowId
2617 );
2618
2619 vEvent.SetEventObject(this);
2620 return GetEventHandler()->ProcessEvent(vEvent);
2621 } // end of wxWindow::HandleKillFocus
2622
2623 // ---------------------------------------------------------------------------
2624 // miscellaneous
2625 // ---------------------------------------------------------------------------
2626
2627 bool wxWindow::HandleShow(
2628 bool bShow
2629 , int nStatus
2630 )
2631 {
2632 wxShowEvent vEvent( GetId()
2633 ,bShow
2634 );
2635
2636 vEvent.m_eventObject = this;
2637 return GetEventHandler()->ProcessEvent(vEvent);
2638 } // end of wxWindow::HandleShow
2639
2640 bool wxWindow::HandleInitDialog(
2641 WXHWND WXUNUSED(hWndFocus)
2642 )
2643 {
2644 wxInitDialogEvent vEvent(GetId());
2645
2646 vEvent.m_eventObject = this;
2647 return GetEventHandler()->ProcessEvent(vEvent);
2648 } // end of wxWindow::HandleInitDialog
2649
2650 bool wxWindow::HandleEndDrag(WXWPARAM wParam)
2651 {
2652 // TODO: We'll handle drag and drop later
2653 return FALSE;
2654 }
2655
2656 bool wxWindow::HandleSetCursor(
2657 USHORT vId
2658 , WXHWND hPointer
2659 )
2660 {
2661 //
2662 // Under OS/2 PM this allows the pointer to be changed
2663 // as it passes over a control
2664 //
2665 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)hPointer);
2666 return TRUE;
2667 } // end of wxWindow::HandleSetCursor
2668
2669 // ---------------------------------------------------------------------------
2670 // owner drawn stuff
2671 // ---------------------------------------------------------------------------
2672 bool wxWindow::OS2OnDrawItem(
2673 int vId
2674 , WXDRAWITEMSTRUCT* pItemStruct
2675 )
2676 {
2677 //
2678 // I'll get to owner drawn stuff later
2679 //
2680
2681 //
2682 // is it a menu item or control?
2683 //
2684 wxWindow* pItem = FindItem(vId);
2685
2686 #if wxUSE_OWNER_DRAWN
2687 if (pItem && pItem->IsKindOf(CLASSINFO(wxControl)))
2688 {
2689 return ((wxControl *)pItem)->OS2OnDraw(pItemStruct);
2690 }
2691 else if (pItem && pItem->IsKindOf(CLASSINFO(wxMenu)))
2692 {
2693 /*
2694 // TODO: draw a menu item
2695 //
2696 POWNERITEM pDrawStruct = (OWNERITEM *)pItemStruct;
2697 wxMenuItem* pMenuItem = (wxMenuItem *)(pDrawStruct->pItemData);
2698
2699 wxCHECK(pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE);
2700
2701 //
2702 // Prepare to call OnDrawItem()
2703 //
2704 HPSdc;
2705 dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE);
2706 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
2707 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
2708 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
2709
2710 return pMenuItem->OnDrawItem
2711 (
2712 dc, rect,
2713 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
2714 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
2715 );
2716 */
2717 }
2718
2719 else
2720 return FALSE;
2721 #endif
2722 return TRUE;
2723 } // end of wxWindow::OS2OnDrawItem
2724
2725 bool wxWindow::OS2OnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
2726 {
2727 // TODO: more owner drawn menu related stuff, get to it later
2728 /*
2729 #if wxUSE_OWNER_DRAWN
2730 // is it a menu item?
2731 if ( id == 0 )
2732 {
2733 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
2734 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
2735
2736 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
2737
2738 return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth,
2739 &pMeasureStruct->itemHeight);
2740 }
2741
2742 wxWindow *item = FindItem(id);
2743 if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
2744 {
2745 return ((wxControl *)item)->MSWOnMeasure(itemStruct);
2746 }
2747 #endif // owner-drawn menus
2748 */
2749 return FALSE;
2750 }
2751
2752 // ---------------------------------------------------------------------------
2753 // colours and palettes
2754 // ---------------------------------------------------------------------------
2755
2756 bool wxWindow::HandleSysColorChange()
2757 {
2758 wxSysColourChangedEvent vEvent;
2759
2760 vEvent.SetEventObject(this);
2761 return GetEventHandler()->ProcessEvent(vEvent);
2762 } // end of wxWindow::HandleSysColorChange
2763
2764 bool wxWindow::HandleCtlColor(
2765 WXHBRUSH* phBrush
2766 )
2767 {
2768 //
2769 // Not much provided with message. So not sure I can do anything with it
2770 //
2771 return TRUE;
2772 } // end of wxWindow::HandleCtlColor
2773
2774 bool wxWindow::HandleWindowParams(
2775 PWNDPARAMS pWndParams
2776 , WXLPARAM lParam
2777 )
2778 {
2779 // TODO: I'll do something here, just not sure what yet
2780 return TRUE;
2781 }
2782
2783 // Define for each class of dialog and control
2784 WXHBRUSH wxWindow::OnCtlColor(WXHDC hDC,
2785 WXHWND hWnd,
2786 WXUINT nCtlColor,
2787 WXUINT message,
2788 WXWPARAM wParam,
2789 WXLPARAM lParam)
2790 {
2791 return (WXHBRUSH)0;
2792 }
2793
2794 bool wxWindow::HandlePaletteChanged()
2795 {
2796 // need to set this to something first
2797 WXHWND hWndPalChange = NULLHANDLE;
2798
2799 wxPaletteChangedEvent vEvent(GetId());
2800
2801 vEvent.SetEventObject(this);
2802 vEvent.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
2803
2804 return GetEventHandler()->ProcessEvent(vEvent);
2805 } // end of wxWindow::HandlePaletteChanged
2806
2807 bool wxWindow::HandlePresParamChanged(
2808 WXWPARAM wParam
2809 )
2810 {
2811 //
2812 // TODO: Once again I'll do something here when I need it
2813 //
2814 //wxQueryNewPaletteEvent event(GetId());
2815 //event.SetEventObject(this);
2816 // if the background is erased
2817 // bProcessed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
2818
2819 return FALSE; //GetEventHandler()->ProcessEvent(event) && event.GetPaletteRealized();
2820 }
2821
2822 //
2823 // Responds to colour changes: passes event on to children.
2824 //
2825 void wxWindow::OnSysColourChanged(
2826 wxSysColourChangedEvent& rEvent
2827 )
2828 {
2829 wxNode* pNode = GetChildren().First();
2830
2831 while (pNode)
2832 {
2833 //
2834 // Only propagate to non-top-level windows
2835 //
2836 wxWindow* pWin = (wxWindow *)pNode->Data();
2837
2838 if (pWin->GetParent())
2839 {
2840 wxSysColourChangedEvent vEvent;
2841
2842 rEvent.m_eventObject = pWin;
2843 pWin->GetEventHandler()->ProcessEvent(vEvent);
2844 }
2845 pNode = pNode->Next();
2846 }
2847 } // end of wxWindow::OnSysColourChanged
2848
2849 // ---------------------------------------------------------------------------
2850 // painting
2851 // ---------------------------------------------------------------------------
2852
2853 bool wxWindow::HandlePaint()
2854 {
2855 HRGN hRgn = NULLHANDLE;
2856 wxPaintEvent vEvent;
2857 HPS hPS;
2858 RECTL vRect;
2859
2860 if (::WinQueryUpdateRegion(GetHwnd(), hRgn) == RGN_NULL)
2861 {
2862 wxLogLastError("CreateRectRgn");
2863 return FALSE;
2864 }
2865 //
2866 // Debug code
2867 //
2868 #ifdef __WXDEBUG__
2869 {
2870 HWND hWnd;
2871 HWND hWnd0 = NULLHANDLE;
2872
2873 hWnd = GetHwnd();
2874 if(hWnd != hWnd0)
2875 printf("HandlePaint hWnd=%x ",hWnd);
2876 }
2877 #endif
2878
2879 m_updateRegion = wxRegion(hRgn);
2880 vEvent.SetEventObject(this);
2881 return (GetEventHandler()->ProcessEvent(vEvent));
2882 } // end of wxWindow::HandlePaint
2883
2884 bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
2885 {
2886 // TODO: will have to worry about this later as part of
2887 // the handling of changed presentation parameters
2888 /*
2889 if ( ::IsIconic(GetHwnd()) )
2890 return TRUE;
2891
2892 wxDC dc;
2893
2894 dc.SetHDC(hdc);
2895 dc.SetWindow(this);
2896 dc.BeginDrawing();
2897
2898 wxEraseEvent event(m_windowId, &dc);
2899 event.SetEventObject(this);
2900 bool rc = GetEventHandler()->ProcessEvent(event);
2901
2902 dc.EndDrawing();
2903 dc.SelectOldObjects(hdc);
2904 dc.SetHDC((WXHDC) NULL);
2905 */
2906 return TRUE;
2907 } // end of wxWindow::HandleEraseBkgnd
2908
2909 void wxWindow::OnEraseBackground(
2910 wxEraseEvent& rEvent
2911 )
2912 {
2913 // TODO:
2914 } // end of wxWindow::OnEraseBackground
2915
2916 // ---------------------------------------------------------------------------
2917 // moving and resizing
2918 // ---------------------------------------------------------------------------
2919
2920 bool wxWindow::HandleMinimize()
2921 {
2922 wxIconizeEvent vEvent(m_windowId);
2923
2924 vEvent.SetEventObject(this);
2925 return GetEventHandler()->ProcessEvent(vEvent);
2926 } // end of wxWindow::HandleMinimize
2927
2928 bool wxWindow::HandleMaximize()
2929 {
2930 wxMaximizeEvent vEvent(m_windowId);
2931
2932 vEvent.SetEventObject(this);
2933 return GetEventHandler()->ProcessEvent(vEvent);
2934 } // end of wxWindow::HandleMaximize
2935
2936 bool wxWindow::HandleMove(
2937 int nX
2938 , int nY
2939 )
2940 {
2941 wxMoveEvent vEvent( wxPoint( nX
2942 ,nY
2943 )
2944 ,m_windowId
2945 );
2946
2947 vEvent.SetEventObject(this);
2948 return GetEventHandler()->ProcessEvent(vEvent);
2949 } // end of wxWindow::HandleMove
2950
2951 bool wxWindow::HandleSize(
2952 int nWidth
2953 , int nHeight
2954 , WXUINT WXUNUSED(nFlag)
2955 )
2956 {
2957 wxSizeEvent vEvent( wxSize( nWidth
2958 ,nHeight
2959 )
2960 ,m_windowId
2961 );
2962
2963 vEvent.SetEventObject(this);
2964 return GetEventHandler()->ProcessEvent(vEvent);
2965 } // end of wxWindow::HandleSize
2966
2967 bool wxWindow::HandleGetMinMaxInfo(
2968 PSWP pSwp
2969 )
2970 {
2971 bool bRc = FALSE;
2972 POINTL vPoint;
2973
2974 switch(pSwp->fl)
2975 {
2976 case SWP_MAXIMIZE:
2977 ::WinGetMaxPosition(GetHwnd(), pSwp);
2978 m_maxWidth = pSwp->cx;
2979 m_maxHeight = pSwp->cy;
2980 break;
2981
2982 case SWP_MINIMIZE:
2983 ::WinGetMinPosition(GetHwnd(), pSwp, &vPoint);
2984 m_minWidth = pSwp->cx;
2985 m_minHeight = pSwp->cy;
2986 break;
2987
2988 default:
2989 return FALSE;
2990 }
2991 return TRUE;
2992 } // end of wxWindow::HandleGetMinMaxInfo
2993
2994 // ---------------------------------------------------------------------------
2995 // command messages
2996 // ---------------------------------------------------------------------------
2997 bool wxWindow::HandleCommand(
2998 WXWORD wId
2999 , WXWORD wCmd
3000 , WXHWND hControl
3001 )
3002 {
3003 if (wxCurrentPopupMenu)
3004 {
3005 wxMenu* pPopupMenu = wxCurrentPopupMenu;
3006
3007 wxCurrentPopupMenu = NULL;
3008 return pPopupMenu->OS2Command(wCmd, wId);
3009 }
3010
3011 wxWindow* pWin = FindItem(wId);
3012
3013 if (!pWin)
3014 {
3015 pWin = wxFindWinFromHandle(hControl);
3016 }
3017
3018 if (pWin)
3019 return pWin->OS2Command( wCmd
3020 ,wId
3021 );
3022 return FALSE;
3023 } // end of wxWindow::HandleCommand
3024
3025 bool wxWindow::HandleSysCommand(
3026 WXWPARAM wParam
3027 , WXLPARAM lParam
3028 )
3029 {
3030 //
3031 // 4 bits are reserved
3032 //
3033 switch (SHORT1FROMMP(wParam))
3034 {
3035 case SC_MAXIMIZE:
3036 return HandleMaximize();
3037
3038 case SC_MINIMIZE:
3039 return HandleMinimize();
3040 }
3041 return FALSE;
3042 } // end of wxWindow::HandleSysCommand
3043
3044 // ---------------------------------------------------------------------------
3045 // mouse events
3046 // ---------------------------------------------------------------------------
3047
3048 void wxWindow::InitMouseEvent(
3049 wxMouseEvent& rEvent
3050 , int nX
3051 , int nY
3052 , WXUINT uFlags
3053 )
3054 {
3055 rEvent.m_x = nX;
3056 rEvent.m_y = nY;
3057 rEvent.m_shiftDown = ((uFlags & VK_SHIFT) != 0);
3058 rEvent.m_controlDown = ((uFlags & VK_CTRL) != 0);
3059 rEvent.m_leftDown = ((uFlags & VK_BUTTON1) != 0);
3060 rEvent.m_middleDown = ((uFlags & VK_BUTTON3) != 0);
3061 rEvent.m_rightDown = ((uFlags & VK_BUTTON2) != 0);
3062 rEvent.SetTimestamp(s_currentMsg.time);
3063 rEvent.m_eventObject = this;
3064
3065 #if wxUSE_MOUSEEVENT_HACK
3066 m_lastMouseX = nX;
3067 m_lastMouseY = nY;
3068 m_lastMouseEvent = rEvent.GetEventType();
3069 #endif // wxUSE_MOUSEEVENT_HACK
3070 } // end of wxWindow::InitMouseEvent
3071
3072 bool wxWindow::HandleMouseEvent(
3073 WXUINT uMsg
3074 , int nX
3075 , int nY
3076 , WXUINT uFlags
3077 )
3078 {
3079 //
3080 // The mouse events take consecutive IDs from WM_MOUSEFIRST to
3081 // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST
3082 // from the message id and take the value in the table to get wxWin event
3083 // id
3084 //
3085 static const wxEventType eventsMouse[] =
3086 {
3087 wxEVT_MOTION,
3088 wxEVT_LEFT_DOWN,
3089 wxEVT_LEFT_UP,
3090 wxEVT_LEFT_DCLICK,
3091 wxEVT_RIGHT_DOWN,
3092 wxEVT_RIGHT_UP,
3093 wxEVT_RIGHT_DCLICK,
3094 wxEVT_MIDDLE_DOWN,
3095 wxEVT_MIDDLE_UP,
3096 wxEVT_MIDDLE_DCLICK
3097 };
3098
3099 wxMouseEvent vEvent(eventsMouse[uMsg - WM_MOUSEMOVE]);
3100
3101 InitMouseEvent( vEvent
3102 ,nX
3103 ,nY
3104 ,uFlags
3105 );
3106
3107 return GetEventHandler()->ProcessEvent(vEvent);
3108 } // end of wxWindow::HandleMouseEvent
3109
3110 bool wxWindow::HandleMouseMove(
3111 int nX
3112 , int nY
3113 , WXUINT uFlags
3114 )
3115 {
3116 if (!m_bMouseInWindow)
3117 {
3118 //
3119 // Generate an ENTER event
3120 //
3121 m_bMouseInWindow = TRUE;
3122
3123 wxMouseEvent vEvent(wxEVT_ENTER_WINDOW);
3124
3125 InitMouseEvent( vEvent
3126 ,nX
3127 ,nY
3128 ,uFlags
3129 );
3130
3131 (void)GetEventHandler()->ProcessEvent(vEvent);
3132 }
3133 return HandleMouseEvent( WM_MOUSEMOVE
3134 ,nX
3135 ,nY
3136 ,uFlags
3137 );
3138 } // end of wxWindow::HandleMouseMove
3139
3140 // ---------------------------------------------------------------------------
3141 // keyboard handling
3142 // ---------------------------------------------------------------------------
3143
3144 //
3145 // Create the key event of the given type for the given key - used by
3146 // HandleChar and HandleKeyDown/Up
3147 //
3148 wxKeyEvent wxWindow::CreateKeyEvent(
3149 wxEventType eType
3150 , int nId
3151 , WXLPARAM lParam
3152 ) const
3153 {
3154 wxKeyEvent vEvent(eType);
3155
3156 vEvent.SetId(GetId());
3157 vEvent.m_shiftDown = IsShiftDown();
3158 vEvent.m_controlDown = IsCtrlDown();
3159 vEvent.m_altDown = (HIWORD(lParam) & KC_ALT) == KC_ALT;
3160
3161 vEvent.m_eventObject = (wxWindow *)this; // const_cast
3162 vEvent.m_keyCode = nId;
3163 vEvent.SetTimestamp(s_currentMsg.time);
3164
3165 //
3166 // Translate the position to client coords
3167 //
3168 POINTL vPoint;
3169 RECTL vRect;
3170
3171 ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
3172 ::WinQueryWindowRect( GetHwnd()
3173 ,&vRect
3174 );
3175
3176 vPoint.x -= vRect.xLeft;
3177 vPoint.y -= vRect.yBottom;
3178
3179 vEvent.m_x = vPoint.x;
3180 vEvent.m_y = vPoint.y;
3181
3182 return vEvent;
3183 } // end of wxWindow::CreateKeyEvent
3184
3185 //
3186 // isASCII is TRUE only when we're called from WM_CHAR handler and not from
3187 // WM_KEYDOWN one
3188 //
3189 bool wxWindow::HandleChar(
3190 WXWORD wParam
3191 , WXLPARAM lParam
3192 , bool isASCII
3193 )
3194 {
3195 bool bCtrlDown = FALSE;
3196 int vId;
3197
3198 if (isASCII)
3199 {
3200 //
3201 // If 1 -> 26, translate to CTRL plus a letter.
3202 //
3203 vId = wParam;
3204 if ((vId > 0) && (vId < 27))
3205 {
3206 switch (vId)
3207 {
3208 case 13:
3209 vId = WXK_RETURN;
3210 break;
3211
3212 case 8:
3213 vId = WXK_BACK;
3214 break;
3215
3216 case 9:
3217 vId = WXK_TAB;
3218 break;
3219
3220 default:
3221 bCtrlDown = TRUE;
3222 vId = vId + 96;
3223 }
3224 }
3225 }
3226 else if ( (vId = wxCharCodeOS2ToWX(wParam)) == 0)
3227 {
3228 //
3229 // It's ASCII and will be processed here only when called from
3230 // WM_CHAR (i.e. when isASCII = TRUE), don't process it now
3231 //
3232 vId = -1;
3233 }
3234
3235 if (vId != -1)
3236 {
3237 wxKeyEvent vEvent(CreateKeyEvent( wxEVT_CHAR
3238 ,vId
3239 ,lParam
3240 ));
3241
3242 if (bCtrlDown)
3243 {
3244 vEvent.m_controlDown = TRUE;
3245 }
3246
3247 if (GetEventHandler()->ProcessEvent(vEvent))
3248 return TRUE;
3249 }
3250 return FALSE;
3251 }
3252
3253 bool wxWindow::HandleKeyDown(
3254 WXWORD wParam
3255 , WXLPARAM lParam
3256 )
3257 {
3258 int nId = wxCharCodeOS2ToWX(wParam);
3259
3260 if (!nId)
3261 {
3262 //
3263 // Normal ASCII char
3264 //
3265 nId = wParam;
3266 }
3267
3268 if (nId != -1)
3269 {
3270 wxKeyEvent vEvent(CreateKeyEvent( wxEVT_KEY_DOWN
3271 ,nId
3272 ,lParam
3273 ));
3274
3275 if (GetEventHandler()->ProcessEvent(vEvent))
3276 {
3277 return TRUE;
3278 }
3279 }
3280 return FALSE;
3281 } // end of wxWindow::HandleKeyDown
3282
3283 bool wxWindow::HandleKeyUp(
3284 WXWORD wParam
3285 , WXLPARAM lParam
3286 )
3287 {
3288 int nId = wxCharCodeOS2ToWX(wParam);
3289
3290 if (!nId)
3291 {
3292 //
3293 // Normal ASCII char
3294 //
3295 nId = wParam;
3296 }
3297
3298 if (nId != -1)
3299 {
3300 wxKeyEvent vEvent(CreateKeyEvent( wxEVT_KEY_UP
3301 ,nId
3302 ,lParam
3303 ));
3304
3305 if (GetEventHandler()->ProcessEvent(vEvent))
3306 return TRUE;
3307 }
3308 return FALSE;
3309 } // end of wxWindow::HandleKeyUp
3310
3311 // ---------------------------------------------------------------------------
3312 // joystick
3313 // ---------------------------------------------------------------------------
3314
3315 // ---------------------------------------------------------------------------
3316 // scrolling
3317 // ---------------------------------------------------------------------------
3318
3319 bool wxWindow::OS2OnScroll(
3320 int nOrientation
3321 , WXWORD wParam
3322 , WXWORD wPos
3323 , WXHWND hControl
3324 )
3325 {
3326 if (hControl)
3327 {
3328 wxWindow* pChild = wxFindWinFromHandle(hControl);
3329
3330 if (pChild )
3331 return pChild->OS2OnScroll( nOrientation
3332 ,wParam
3333 ,wPos
3334 ,hControl
3335 );
3336 }
3337
3338 wxScrollWinEvent vEvent;
3339
3340 vEvent.SetPosition(wPos);
3341 vEvent.SetOrientation(nOrientation);
3342 vEvent.m_eventObject = this;
3343
3344 switch (wParam)
3345 {
3346 case SB_LINEUP:
3347 vEvent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
3348 break;
3349
3350 case SB_LINEDOWN:
3351 vEvent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
3352 break;
3353
3354 case SB_PAGEUP:
3355 vEvent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
3356 break;
3357
3358 case SB_PAGEDOWN:
3359 vEvent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
3360 break;
3361
3362 case SB_SLIDERPOSITION:
3363 vEvent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
3364 break;
3365
3366 case SB_SLIDERTRACK:
3367 vEvent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
3368 break;
3369
3370 default:
3371 return FALSE;
3372 }
3373 return GetEventHandler()->ProcessEvent(vEvent);
3374 } // end of wxWindow::OS2OnScroll
3375
3376 // ===========================================================================
3377 // global functions
3378 // ===========================================================================
3379
3380 void wxGetCharSize(
3381 WXHWND hWnd
3382 , int* pX
3383 , int* pY
3384 ,wxFont* pTheFont
3385 )
3386 {
3387 // TODO: we'll do this later
3388 } // end of wxGetCharSize
3389
3390 //
3391 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
3392 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
3393 //
3394 int wxCharCodeOS2ToWX(
3395 int nKeySym
3396 )
3397 {
3398 int nId = 0;
3399
3400 switch (nKeySym)
3401 {
3402 case VK_BACKTAB: nId = WXK_BACK; break;
3403 case VK_TAB: nId = WXK_TAB; break;
3404 case VK_CLEAR: nId = WXK_CLEAR; break;
3405 case VK_ENTER: nId = WXK_RETURN; break;
3406 case VK_SHIFT: nId = WXK_SHIFT; break;
3407 case VK_CTRL: nId = WXK_CONTROL; break;
3408 case VK_PAUSE: nId = WXK_PAUSE; break;
3409 case VK_SPACE: nId = WXK_SPACE; break;
3410 case VK_ESC: nId = WXK_ESCAPE; break;
3411 case VK_END: nId = WXK_END; break;
3412 case VK_HOME : nId = WXK_HOME; break;
3413 case VK_LEFT : nId = WXK_LEFT; break;
3414 case VK_UP: nId = WXK_UP; break;
3415 case VK_RIGHT: nId = WXK_RIGHT; break;
3416 case VK_DOWN : nId = WXK_DOWN; break;
3417 case VK_PRINTSCRN: nId = WXK_PRINT; break;
3418 case VK_INSERT: nId = WXK_INSERT; break;
3419 case VK_DELETE: nId = WXK_DELETE; break;
3420 case VK_F1: nId = WXK_F1; break;
3421 case VK_F2: nId = WXK_F2; break;
3422 case VK_F3: nId = WXK_F3; break;
3423 case VK_F4: nId = WXK_F4; break;
3424 case VK_F5: nId = WXK_F5; break;
3425 case VK_F6: nId = WXK_F6; break;
3426 case VK_F7: nId = WXK_F7; break;
3427 case VK_F8: nId = WXK_F8; break;
3428 case VK_F9: nId = WXK_F9; break;
3429 case VK_F10: nId = WXK_F10; break;
3430 case VK_F11: nId = WXK_F11; break;
3431 case VK_F12: nId = WXK_F12; break;
3432 case VK_F13: nId = WXK_F13; break;
3433 case VK_F14: nId = WXK_F14; break;
3434 case VK_F15: nId = WXK_F15; break;
3435 case VK_F16: nId = WXK_F16; break;
3436 case VK_F17: nId = WXK_F17; break;
3437 case VK_F18: nId = WXK_F18; break;
3438 case VK_F19: nId = WXK_F19; break;
3439 case VK_F20: nId = WXK_F20; break;
3440 case VK_F21: nId = WXK_F21; break;
3441 case VK_F22: nId = WXK_F22; break;
3442 case VK_F23: nId = WXK_F23; break;
3443 case VK_F24: nId = WXK_F24; break;
3444 case VK_NUMLOCK: nId = WXK_NUMLOCK; break;
3445 case VK_SCRLLOCK: nId = WXK_SCROLL; break;
3446 default:
3447 {
3448 return 0;
3449 }
3450 }
3451 return nId;
3452 } // end of wxCharCodeOS2ToWX
3453
3454 int wxCharCodeWXToOS2(
3455 int nId
3456 , bool* bIsVirtual
3457 )
3458 {
3459 int nKeySym = 0;
3460
3461 *bIsVirtual = TRUE;
3462 switch (nId)
3463 {
3464 case WXK_CLEAR: nKeySym = VK_CLEAR; break;
3465 case WXK_SHIFT: nKeySym = VK_SHIFT; break;
3466 case WXK_CONTROL: nKeySym = VK_CTRL; break;
3467 case WXK_PAUSE: nKeySym = VK_PAUSE; break;
3468 case WXK_END: nKeySym = VK_END; break;
3469 case WXK_HOME : nKeySym = VK_HOME; break;
3470 case WXK_LEFT : nKeySym = VK_LEFT; break;
3471 case WXK_UP: nKeySym = VK_UP; break;
3472 case WXK_RIGHT: nKeySym = VK_RIGHT; break;
3473 case WXK_DOWN : nKeySym = VK_DOWN; break;
3474 case WXK_PRINT: nKeySym = VK_PRINTSCRN; break;
3475 case WXK_INSERT: nKeySym = VK_INSERT; break;
3476 case WXK_DELETE: nKeySym = VK_DELETE; break;
3477 case WXK_F1: nKeySym = VK_F1; break;
3478 case WXK_F2: nKeySym = VK_F2; break;
3479 case WXK_F3: nKeySym = VK_F3; break;
3480 case WXK_F4: nKeySym = VK_F4; break;
3481 case WXK_F5: nKeySym = VK_F5; break;
3482 case WXK_F6: nKeySym = VK_F6; break;
3483 case WXK_F7: nKeySym = VK_F7; break;
3484 case WXK_F8: nKeySym = VK_F8; break;
3485 case WXK_F9: nKeySym = VK_F9; break;
3486 case WXK_F10: nKeySym = VK_F10; break;
3487 case WXK_F11: nKeySym = VK_F11; break;
3488 case WXK_F12: nKeySym = VK_F12; break;
3489 case WXK_F13: nKeySym = VK_F13; break;
3490 case WXK_F14: nKeySym = VK_F14; break;
3491 case WXK_F15: nKeySym = VK_F15; break;
3492 case WXK_F16: nKeySym = VK_F16; break;
3493 case WXK_F17: nKeySym = VK_F17; break;
3494 case WXK_F18: nKeySym = VK_F18; break;
3495 case WXK_F19: nKeySym = VK_F19; break;
3496 case WXK_F20: nKeySym = VK_F20; break;
3497 case WXK_F21: nKeySym = VK_F21; break;
3498 case WXK_F22: nKeySym = VK_F22; break;
3499 case WXK_F23: nKeySym = VK_F23; break;
3500 case WXK_F24: nKeySym = VK_F24; break;
3501 case WXK_NUMLOCK: nKeySym = VK_NUMLOCK; break;
3502 case WXK_SCROLL: nKeySym = VK_SCRLLOCK; break;
3503 default:
3504 {
3505 *bIsVirtual = FALSE;
3506 nKeySym = nId;
3507 break;
3508 }
3509 }
3510 return nKeySym;
3511 } // end of wxCharCodeWXToOS2
3512
3513 wxWindow* wxGetActiveWindow()
3514 {
3515 HWND hWnd = ::WinQueryActiveWindow(HWND_DESKTOP);
3516
3517 if (hWnd != 0)
3518 {
3519 return wxFindWinFromHandle((WXHWND)hWnd);
3520 }
3521 return NULL;
3522 } // end of wxGetActiveWindow
3523
3524 #ifdef __WXDEBUG__
3525 const char* wxGetMessageName(
3526 int nMessage)
3527 {
3528 switch (nMessage)
3529 {
3530 case 0x0000: return "WM_NULL";
3531 case 0x0001: return "WM_CREATE";
3532 case 0x0002: return "WM_DESTROY";
3533 case 0x0004: return "WM_ENABLE";
3534 case 0x0005: return "WM_SHOW";
3535 case 0x0006: return "WM_MOVE";
3536 case 0x0007: return "WM_SIZE";
3537 case 0x0008: return "WM_ADJUSTWINDOWPOS";
3538 case 0x0009: return "WM_CALCVALIDRECTS";
3539 case 0x000A: return "WM_SETWINDOWPARAMS";
3540 case 0x000B: return "WM_QUERYWINDOWPARAMS";
3541 case 0x000C: return "WM_HITTEST";
3542 case 0x000D: return "WM_ACTIVATE";
3543 case 0x000F: return "WM_SETFOCUS";
3544 case 0x0010: return "WM_SETSELECTION";
3545 case 0x0011: return "WM_PPAINT";
3546 case 0x0012: return "WM_PSETFOCUS";
3547 case 0x0013: return "WM_PSYSCOLORCHANGE";
3548 case 0x0014: return "WM_PSIZE";
3549 case 0x0015: return "WM_PACTIVATE";
3550 case 0x0016: return "WM_PCONTROL";
3551 case 0x0020: return "WM_COMMAND";
3552 case 0x0021: return "WM_SYSCOMMAND";
3553 case 0x0022: return "WM_HELP";
3554 case 0x0023: return "WM_PAINT";
3555 case 0x0024: return "WM_TIMER";
3556 case 0x0025: return "WM_SEM1";
3557 case 0x0026: return "WM_SEM2";
3558 case 0x0027: return "WM_SEM3";
3559 case 0x0028: return "WM_SEM4";
3560 case 0x0029: return "WM_CLOSE";
3561 case 0x002A: return "WM_QUIT";
3562 case 0x002B: return "WM_SYSCOLORCHANGE";
3563 case 0x002D: return "WM_SYSVALUECHANGE";
3564 case 0x002E: return "WM_APPTERMINATENOTIFY";
3565 case 0x002F: return "WM_PRESPARAMCHANGED";
3566 // Control notification messages
3567 case 0x0030: return "WM_CONTROL";
3568 case 0x0031: return "WM_VSCROLL";
3569 case 0x0032: return "WM_HSCROLL";
3570 case 0x0033: return "WM_INITMENU";
3571 case 0x0034: return "WM_MENUSELECT";
3572 case 0x0035: return "WM_MENUSEND";
3573 case 0x0036: return "WM_DRAWITEM";
3574 case 0x0037: return "WM_MEASUREITEM";
3575 case 0x0038: return "WM_CONTROLPOINTER";
3576 case 0x003A: return "WM_QUERYDLGCODE";
3577 case 0x003B: return "WM_INITDLG";
3578 case 0x003C: return "WM_SUBSTITUTESTRING";
3579 case 0x003D: return "WM_MATCHMNEMONIC";
3580 case 0x003E: return "WM_SAVEAPPLICATION";
3581 case 0x0129: return "WM_CTLCOLORCHANGE";
3582 case 0x0130: return "WM_QUERYCTLTYPE";
3583 // Frame messages
3584 case 0x0040: return "WM_FLASHWINDOW";
3585 case 0x0041: return "WM_FORMATFRAME";
3586 case 0x0042: return "WM_UPDATEFRAME";
3587 case 0x0043: return "WM_FOCUSCHANGE";
3588 case 0x0044: return "WM_SETBORDERSIZE";
3589 case 0x0045: return "WM_TRACKFRAME";
3590 case 0x0046: return "WM_MINMAXFRAME";
3591 case 0x0047: return "WM_SETICON";
3592 case 0x0048: return "WM_QUERYICON";
3593 case 0x0049: return "WM_SETACCELTABLE";
3594 case 0x004A: return "WM_QUERYACCELTABLE";
3595 case 0x004B: return "WM_TRANSLATEACCEL";
3596 case 0x004C: return "WM_QUERYTRACKINFO";
3597 case 0x004D: return "WM_QUERYBORDERSIZE";
3598 case 0x004E: return "WM_NEXTMENU";
3599 case 0x004F: return "WM_ERASEBACKGROUND";
3600 case 0x0050: return "WM_QUERYFRAMEINFO";
3601 case 0x0051: return "WM_QUERYFOCUSCHAIN";
3602 case 0x0052: return "WM_OWNERPOSCHANGE";
3603 case 0x0053: return "WM_CACLFRAMERECT";
3604 case 0x0055: return "WM_WINDOWPOSCHANGED";
3605 case 0x0056: return "WM_ADJUSTFRAMEPOS";
3606 case 0x0059: return "WM_QUERYFRAMECTLCOUNT";
3607 case 0x005B: return "WM_QUERYHELPINFO";
3608 case 0x005C: return "WM_SETHELPINFO";
3609 case 0x005D: return "WM_ERROR";
3610 case 0x005E: return "WM_REALIZEPALETTE";
3611 // Clipboard messages
3612 case 0x0060: return "WM_RENDERFMT";
3613 case 0x0061: return "WM_RENDERALLFMTS";
3614 case 0x0062: return "WM_DESTROYCLIPBOARD";
3615 case 0x0063: return "WM_PAINTCLIPBOARD";
3616 case 0x0064: return "WM_SIZECLIPBOARD";
3617 case 0x0065: return "WM_HSCROLLCLIPBOARD";
3618 case 0x0066: return "WM_VSCROLLCLIPBOARD";
3619 case 0x0067: return "WM_DRAWCLIPBOARD";
3620 // mouse messages
3621 case 0x0070: return "WM_MOUSEMOVE";
3622 case 0x0071: return "WM_BUTTON1DOWN";
3623 case 0x0072: return "WM_BUTTON1UP";
3624 case 0x0073: return "WM_BUTTON1DBLCLK";
3625 case 0x0074: return "WM_BUTTON2DOWN";
3626 case 0x0075: return "WM_BUTTON2UP";
3627 case 0x0076: return "WM_BUTTON2DBLCLK";
3628 case 0x0077: return "WM_BUTTON3DOWN";
3629 case 0x0078: return "WM_BUTTON3UP";
3630 case 0x0079: return "WM_BUTTON3DBLCLK";
3631 case 0x007D: return "WM_MOUSEMAP";
3632 case 0x007E: return "WM_VRNDISABLED";
3633 case 0x007F: return "WM_VRNENABLED";
3634 case 0x0410: return "WM_CHORD";
3635 case 0x0411: return "WM_BUTTON1MOTIONSTART";
3636 case 0x0412: return "WM_BUTTON1MOTIONEND";
3637 case 0x0413: return "WM_BUTTON1CLICK";
3638 case 0x0414: return "WM_BUTTON2MOTIONSTART";
3639 case 0x0415: return "WM_BUTTON2MOTIONEND";
3640 case 0x0416: return "WM_BUTTON2CLICK";
3641 case 0x0417: return "WM_BUTTON3MOTIONSTART";
3642 case 0x0418: return "WM_BUTTON3MOTIONEND";
3643 case 0x0419: return "WM_BUTTON3CLICK";
3644 case 0x0420: return "WM_BEGINDRAG";
3645 case 0x0421: return "WM_ENDDRAG";
3646 case 0x0422: return "WM_SINGLESELECT";
3647 case 0x0423: return "WM_OPEN";
3648 case 0x0424: return "WM_CONTEXTMENU";
3649 case 0x0425: return "WM_CONTEXTHELP";
3650 case 0x0426: return "WM_TEXTEDIT";
3651 case 0x0427: return "WM_BEGINSELECT";
3652 case 0x0228: return "WM_ENDSELECT";
3653 case 0x0429: return "WM_PICKUP";
3654 case 0x04C0: return "WM_PENFIRST";
3655 case 0x04FF: return "WM_PENLAST";
3656 case 0x0500: return "WM_MMPMFIRST";
3657 case 0x05FF: return "WM_MMPMLAST";
3658 case 0x0600: return "WM_STDDLGFIRST";
3659 case 0x06FF: return "WM_STDDLGLAST";
3660 case 0x0BD0: return "WM_BIDI_FIRST";
3661 case 0x0BFF: return "WM_BIDI_LAST";
3662 // keyboard input
3663 case 0x007A: return "WM_CHAR";
3664 case 0x007B: return "WM_VIOCHAR";
3665 // DDE messages
3666 case 0x00A0: return "WM_DDE_INITIATE";
3667 case 0x00A1: return "WM_DDE_REQUEST";
3668 case 0x00A2: return "WM_DDE_ACK";
3669 case 0x00A3: return "WM_DDE_DATA";
3670 case 0x00A4: return "WM_DDE_ADVISE";
3671 case 0x00A5: return "WM_DDE_UNADVISE";
3672 case 0x00A6: return "WM_DDE_POKE";
3673 case 0x00A7: return "WM_DDE_EXECUTE";
3674 case 0x00A8: return "WM_DDE_TERMINATE";
3675 case 0x00A9: return "WM_DDE_INITIATEACK";
3676 case 0x00AF: return "WM_DDE_LAST";
3677 // Buttons
3678 case 0x0120: return "BM_CLICK";
3679 case 0x0121: return "BM_QUERYCHECKINDEX";
3680 case 0x0122: return "BM_QUERYHILITE";
3681 case 0x0123: return "BM_SETHILITE";
3682 case 0x0124: return "BM_QUERYCHECK";
3683 case 0x0125: return "BM_SETCHECK";
3684 case 0x0126: return "BM_SETDEFAULT";
3685 case 0x0128: return "BM_AUTOSIZE";
3686 // Combo boxes
3687 case 0x029A: return "CBID_LIST";
3688 case 0x029B: return "CBID_EDIT";
3689 case 0x0170: return "CBM_SHOWLIST";
3690 case 0x0171: return "CBM_HILITE";
3691 case 0x0172: return "CBM_ISLISTSHOWING";
3692 // Edit fields
3693 case 0x0140: return "EM_QUERYCHANGED";
3694 case 0x0141: return "EM_QUERYSEL";
3695 case 0x0142: return "EM_SETSEL";
3696 case 0x0143: return "EM_SETTEXTLIMIT";
3697 case 0x0144: return "EM_CUT";
3698 case 0x0145: return "EM_COPY";
3699 case 0x0146: return "EM_CLEAR";
3700 case 0x0147: return "EM_PASTE";
3701 case 0x0148: return "EM_QUERYFIRSTCHAR";
3702 case 0x0149: return "EM_SETFIRSTCHAR";
3703 case 0x014A: return "EM_QUERYREADONLY";
3704 case 0x014B: return "EM_SETREADONLY";
3705 case 0x014C: return "EM_SETINSERTMODE";
3706 // Listboxes
3707 case 0x0160: return "LM_QUERYITEMCOUNT";
3708 case 0x0161: return "LM_INSERTITEM";
3709 case 0x0162: return "LM_SETOPENINDEX";
3710 case 0x0163: return "LM_DELETEITEM";
3711 case 0x0164: return "LM_SELECTITEM";
3712 case 0x0165: return "LM_QUERYSELECTION";
3713 case 0x0166: return "LM_SETITEMTEXT";
3714 case 0x0167: return "LM_QUERYITEMTEXTLENGTH";
3715 case 0x0168: return "LM_QUERYITEMTEXT";
3716 case 0x0169: return "LM_SETITEMHANDLE";
3717 case 0x016A: return "LM_QUERYITEMHANDLE";
3718 case 0x016B: return "LM_SEARCHSTRING";
3719 case 0x016C: return "LM_SETITEMHEIGHT";
3720 case 0x016D: return "LM_QUERYTOPINDEX";
3721 case 0x016E: return "LM_DELETEALL";
3722 case 0x016F: return "LM_INSERTMULITEMS";
3723 case 0x0660: return "LM_SETITEMWIDTH";
3724 // Menus
3725 case 0x0180: return "MM_INSERTITEM";
3726 case 0x0181: return "MM_DELETEITEM";
3727 case 0x0182: return "MM_QUERYITEM";
3728 case 0x0183: return "MM_SETITEM";
3729 case 0x0184: return "MM_QUERYITEMCOUNT";
3730 case 0x0185: return "MM_STARTMENUMODE";
3731 case 0x0186: return "MM_ENDMENUMODE";
3732 case 0x0188: return "MM_REMOVEITEM";
3733 case 0x0189: return "MM_SELECTITEM";
3734 case 0x018A: return "MM_QUERYSELITEMID";
3735 case 0x018B: return "MM_QUERYITEMTEXT";
3736 case 0x018C: return "MM_QUERYITEMTEXTLENGTH";
3737 case 0x018D: return "MM_SETITEMHANDLE";
3738 case 0x018E: return "MM_SETITEMTEXT";
3739 case 0x018F: return "MM_ITEMPOSITIONFROMID";
3740 case 0x0190: return "MM_ITEMIDFROMPOSITION";
3741 case 0x0191: return "MM_QUERYITEMATTR";
3742 case 0x0192: return "MM_SETITEMATTR";
3743 case 0x0193: return "MM_ISITEMVALID";
3744 case 0x0194: return "MM_QUERYITEMRECT";
3745 case 0x0431: return "MM_QUERYDEFAULTITEMID";
3746 case 0x0432: return "MM_SETDEFAULTITEMID";
3747 // Scrollbars
3748 case 0x01A0: return "SBM_SETSCROLLBAR";
3749 case 0x01A1: return "SBM_SETPOS";
3750 case 0x01A2: return "SBM_QUERYPOS";
3751 case 0x01A3: return "SBM_QUERYRANGE";
3752 case 0x01A6: return "SBM_SETTHUMBSIZE";
3753
3754 // Help messages
3755 case 0x0F00: return "WM_HELPBASE";
3756 case 0x0FFF: return "WM_HELPTOP";
3757 // Beginning of user defined messages
3758 case 0x1000: return "WM_USER";
3759
3760 // wxWindows user defined types
3761
3762 // listview
3763 // case 0x1000 + 0: return "LVM_GETBKCOLOR";
3764 case 0x1000 + 1: return "LVM_SETBKCOLOR";
3765 case 0x1000 + 2: return "LVM_GETIMAGELIST";
3766 case 0x1000 + 3: return "LVM_SETIMAGELIST";
3767 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
3768 case 0x1000 + 5: return "LVM_GETITEMA";
3769 case 0x1000 + 75: return "LVM_GETITEMW";
3770 case 0x1000 + 6: return "LVM_SETITEMA";
3771 case 0x1000 + 76: return "LVM_SETITEMW";
3772 case 0x1000 + 7: return "LVM_INSERTITEMA";
3773 case 0x1000 + 77: return "LVM_INSERTITEMW";
3774 case 0x1000 + 8: return "LVM_DELETEITEM";
3775 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
3776 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
3777 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
3778 case 0x1000 + 12: return "LVM_GETNEXTITEM";
3779 case 0x1000 + 13: return "LVM_FINDITEMA";
3780 case 0x1000 + 83: return "LVM_FINDITEMW";
3781 case 0x1000 + 14: return "LVM_GETITEMRECT";
3782 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
3783 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
3784 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
3785 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
3786 case 0x1000 + 18: return "LVM_HITTEST";
3787 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
3788 case 0x1000 + 20: return "LVM_SCROLL";
3789 case 0x1000 + 21: return "LVM_REDRAWITEMS";
3790 case 0x1000 + 22: return "LVM_ARRANGE";
3791 case 0x1000 + 23: return "LVM_EDITLABELA";
3792 case 0x1000 + 118: return "LVM_EDITLABELW";
3793 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
3794 case 0x1000 + 25: return "LVM_GETCOLUMNA";
3795 case 0x1000 + 95: return "LVM_GETCOLUMNW";
3796 case 0x1000 + 26: return "LVM_SETCOLUMNA";
3797 case 0x1000 + 96: return "LVM_SETCOLUMNW";
3798 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
3799 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
3800 case 0x1000 + 28: return "LVM_DELETECOLUMN";
3801 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
3802 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
3803 case 0x1000 + 31: return "LVM_GETHEADER";
3804 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
3805 case 0x1000 + 34: return "LVM_GETVIEWRECT";
3806 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
3807 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
3808 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
3809 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
3810 case 0x1000 + 39: return "LVM_GETTOPINDEX";
3811 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
3812 case 0x1000 + 41: return "LVM_GETORIGIN";
3813 case 0x1000 + 42: return "LVM_UPDATE";
3814 case 0x1000 + 43: return "LVM_SETITEMSTATE";
3815 case 0x1000 + 44: return "LVM_GETITEMSTATE";
3816 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
3817 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
3818 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
3819 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
3820 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
3821 case 0x1000 + 48: return "LVM_SORTITEMS";
3822 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
3823 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
3824 case 0x1000 + 51: return "LVM_GETITEMSPACING";
3825 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
3826 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
3827 case 0x1000 + 53: return "LVM_SETICONSPACING";
3828 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
3829 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
3830 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
3831 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
3832 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
3833 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
3834 case 0x1000 + 60: return "LVM_SETHOTITEM";
3835 case 0x1000 + 61: return "LVM_GETHOTITEM";
3836 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
3837 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
3838 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
3839 case 0x1000 + 65: return "LVM_SETWORKAREA";
3840
3841 // tree view
3842 case 0x1100 + 0: return "TVM_INSERTITEMA";
3843 case 0x1100 + 50: return "TVM_INSERTITEMW";
3844 case 0x1100 + 1: return "TVM_DELETEITEM";
3845 case 0x1100 + 2: return "TVM_EXPAND";
3846 case 0x1100 + 4: return "TVM_GETITEMRECT";
3847 case 0x1100 + 5: return "TVM_GETCOUNT";
3848 case 0x1100 + 6: return "TVM_GETINDENT";
3849 case 0x1100 + 7: return "TVM_SETINDENT";
3850 case 0x1100 + 8: return "TVM_GETIMAGELIST";
3851 case 0x1100 + 9: return "TVM_SETIMAGELIST";
3852 case 0x1100 + 10: return "TVM_GETNEXTITEM";
3853 case 0x1100 + 11: return "TVM_SELECTITEM";
3854 case 0x1100 + 12: return "TVM_GETITEMA";
3855 case 0x1100 + 62: return "TVM_GETITEMW";
3856 case 0x1100 + 13: return "TVM_SETITEMA";
3857 case 0x1100 + 63: return "TVM_SETITEMW";
3858 case 0x1100 + 14: return "TVM_EDITLABELA";
3859 case 0x1100 + 65: return "TVM_EDITLABELW";
3860 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
3861 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
3862 case 0x1100 + 17: return "TVM_HITTEST";
3863 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
3864 case 0x1100 + 19: return "TVM_SORTCHILDREN";
3865 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
3866 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
3867 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
3868 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
3869 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
3870 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
3871 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
3872
3873 // header
3874 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
3875 case 0x1200 + 1: return "HDM_INSERTITEMA";
3876 case 0x1200 + 10: return "HDM_INSERTITEMW";
3877 case 0x1200 + 2: return "HDM_DELETEITEM";
3878 case 0x1200 + 3: return "HDM_GETITEMA";
3879 case 0x1200 + 11: return "HDM_GETITEMW";
3880 case 0x1200 + 4: return "HDM_SETITEMA";
3881 case 0x1200 + 12: return "HDM_SETITEMW";
3882 case 0x1200 + 5: return "HDM_LAYOUT";
3883 case 0x1200 + 6: return "HDM_HITTEST";
3884 case 0x1200 + 7: return "HDM_GETITEMRECT";
3885 case 0x1200 + 8: return "HDM_SETIMAGELIST";
3886 case 0x1200 + 9: return "HDM_GETIMAGELIST";
3887 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
3888 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
3889 case 0x1200 + 17: return "HDM_GETORDERARRAY";
3890 case 0x1200 + 18: return "HDM_SETORDERARRAY";
3891 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
3892
3893 // tab control
3894 case 0x1300 + 2: return "TCM_GETIMAGELIST";
3895 case 0x1300 + 3: return "TCM_SETIMAGELIST";
3896 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
3897 case 0x1300 + 5: return "TCM_GETITEMA";
3898 case 0x1300 + 60: return "TCM_GETITEMW";
3899 case 0x1300 + 6: return "TCM_SETITEMA";
3900 case 0x1300 + 61: return "TCM_SETITEMW";
3901 case 0x1300 + 7: return "TCM_INSERTITEMA";
3902 case 0x1300 + 62: return "TCM_INSERTITEMW";
3903 case 0x1300 + 8: return "TCM_DELETEITEM";
3904 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
3905 case 0x1300 + 10: return "TCM_GETITEMRECT";
3906 case 0x1300 + 11: return "TCM_GETCURSEL";
3907 case 0x1300 + 12: return "TCM_SETCURSEL";
3908 case 0x1300 + 13: return "TCM_HITTEST";
3909 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
3910 case 0x1300 + 40: return "TCM_ADJUSTRECT";
3911 case 0x1300 + 41: return "TCM_SETITEMSIZE";
3912 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
3913 case 0x1300 + 43: return "TCM_SETPADDING";
3914 case 0x1300 + 44: return "TCM_GETROWCOUNT";
3915 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
3916 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
3917 case 0x1300 + 47: return "TCM_GETCURFOCUS";
3918 case 0x1300 + 48: return "TCM_SETCURFOCUS";
3919 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
3920 case 0x1300 + 50: return "TCM_DESELECTALL";
3921
3922 // toolbar
3923 case WM_USER+1000+1: return "TB_ENABLEBUTTON";
3924 case WM_USER+1000+2: return "TB_CHECKBUTTON";
3925 case WM_USER+1000+3: return "TB_PRESSBUTTON";
3926 case WM_USER+1000+4: return "TB_HIDEBUTTON";
3927 case WM_USER+1000+5: return "TB_INDETERMINATE";
3928 case WM_USER+1000+9: return "TB_ISBUTTONENABLED";
3929 case WM_USER+1000+10: return "TB_ISBUTTONCHECKED";
3930 case WM_USER+1000+11: return "TB_ISBUTTONPRESSED";
3931 case WM_USER+1000+12: return "TB_ISBUTTONHIDDEN";
3932 case WM_USER+1000+13: return "TB_ISBUTTONINDETERMINATE";
3933 case WM_USER+1000+17: return "TB_SETSTATE";
3934 case WM_USER+1000+18: return "TB_GETSTATE";
3935 case WM_USER+1000+19: return "TB_ADDBITMAP";
3936 case WM_USER+1000+20: return "TB_ADDBUTTONS";
3937 case WM_USER+1000+21: return "TB_INSERTBUTTON";
3938 case WM_USER+1000+22: return "TB_DELETEBUTTON";
3939 case WM_USER+1000+23: return "TB_GETBUTTON";
3940 case WM_USER+1000+24: return "TB_BUTTONCOUNT";
3941 case WM_USER+1000+25: return "TB_COMMANDTOINDEX";
3942 case WM_USER+1000+26: return "TB_SAVERESTOREA";
3943 case WM_USER+1000+76: return "TB_SAVERESTOREW";
3944 case WM_USER+1000+27: return "TB_CUSTOMIZE";
3945 case WM_USER+1000+28: return "TB_ADDSTRINGA";
3946 case WM_USER+1000+77: return "TB_ADDSTRINGW";
3947 case WM_USER+1000+29: return "TB_GETITEMRECT";
3948 case WM_USER+1000+30: return "TB_BUTTONSTRUCTSIZE";
3949 case WM_USER+1000+31: return "TB_SETBUTTONSIZE";
3950 case WM_USER+1000+32: return "TB_SETBITMAPSIZE";
3951 case WM_USER+1000+33: return "TB_AUTOSIZE";
3952 case WM_USER+1000+35: return "TB_GETTOOLTIPS";
3953 case WM_USER+1000+36: return "TB_SETTOOLTIPS";
3954 case WM_USER+1000+37: return "TB_SETPARENT";
3955 case WM_USER+1000+39: return "TB_SETROWS";
3956 case WM_USER+1000+40: return "TB_GETROWS";
3957 case WM_USER+1000+42: return "TB_SETCMDID";
3958 case WM_USER+1000+43: return "TB_CHANGEBITMAP";
3959 case WM_USER+1000+44: return "TB_GETBITMAP";
3960 case WM_USER+1000+45: return "TB_GETBUTTONTEXTA";
3961 case WM_USER+1000+75: return "TB_GETBUTTONTEXTW";
3962 case WM_USER+1000+46: return "TB_REPLACEBITMAP";
3963 case WM_USER+1000+47: return "TB_SETINDENT";
3964 case WM_USER+1000+48: return "TB_SETIMAGELIST";
3965 case WM_USER+1000+49: return "TB_GETIMAGELIST";
3966 case WM_USER+1000+50: return "TB_LOADIMAGES";
3967 case WM_USER+1000+51: return "TB_GETRECT";
3968 case WM_USER+1000+52: return "TB_SETHOTIMAGELIST";
3969 case WM_USER+1000+53: return "TB_GETHOTIMAGELIST";
3970 case WM_USER+1000+54: return "TB_SETDISABLEDIMAGELIST";
3971 case WM_USER+1000+55: return "TB_GETDISABLEDIMAGELIST";
3972 case WM_USER+1000+56: return "TB_SETSTYLE";
3973 case WM_USER+1000+57: return "TB_GETSTYLE";
3974 case WM_USER+1000+58: return "TB_GETBUTTONSIZE";
3975 case WM_USER+1000+59: return "TB_SETBUTTONWIDTH";
3976 case WM_USER+1000+60: return "TB_SETMAXTEXTROWS";
3977 case WM_USER+1000+61: return "TB_GETTEXTROWS";
3978 case WM_USER+1000+41: return "TB_GETBITMAPFLAGS";
3979
3980 default:
3981 static char s_szBuf[128];
3982 sprintf(s_szBuf, "<unknown message = %d>", nMessage);
3983 return s_szBuf;
3984 }
3985 return NULL;
3986 } // end of wxGetMessageName
3987
3988 #endif // __WXDEBUG__
3989
3990 static void TranslateKbdEventToMouse(
3991 wxWindow* pWin
3992 , int* pX
3993 , int* pY
3994 , ULONG* pFlags
3995 )
3996 {
3997 //
3998 // Construct the key mask
3999 ULONG& fwKeys = *pFlags;
4000
4001 fwKeys = VK_BUTTON2;
4002 if ((::WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x100) != 0)
4003 fwKeys |= VK_CTRL;
4004 if ((::WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x100) != 0)
4005 fwKeys |= VK_SHIFT;
4006
4007 //
4008 // Simulate right mouse button click
4009 //
4010 POINTL vPoint;
4011
4012 ::WinQueryMsgPos(vHabmain, &vPoint);
4013 *pX = vPoint.x;
4014 *pY = vPoint.y;
4015
4016 pWin->ScreenToClient(pX, pY);
4017 } // end of TranslateKbdEventToMouse
4018
4019 // Find the wxWindow at the current mouse position, returning the mouse
4020 // position.
4021 wxWindow* wxFindWindowAtPointer(
4022 wxPoint& rPt
4023 )
4024 {
4025 return wxFindWindowAtPoint(wxGetMousePosition());
4026 }
4027
4028 wxWindow* wxFindWindowAtPoint(
4029 const wxPoint& rPt
4030 )
4031 {
4032 POINTL vPt2;
4033
4034 vPt2.x = rPt.x;
4035 vPt2.y = rPt.y;
4036
4037 HWND hWndHit = ::WinWindowFromPoint(HWND_DESKTOP, &vPt2, FALSE);
4038 wxWindow* pWin = wxFindWinFromHandle((WXHWND)hWndHit) ;
4039 HWND hWnd = hWndHit;
4040
4041 //
4042 // Try to find a window with a wxWindow associated with it
4043 //
4044 while (!pWin && (hWnd != 0))
4045 {
4046 hWnd = ::WinQueryWindow(hWnd, QW_PARENT);
4047 pWin = wxFindWinFromHandle((WXHWND)hWnd) ;
4048 }
4049 return pWin;
4050 }
4051
4052 // Get the current mouse position.
4053 wxPoint wxGetMousePosition()
4054 {
4055 POINTL vPt;
4056
4057 ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
4058 return wxPoint(vPt.x, vPt.y);
4059 }
4060