]> git.saurik.com Git - wxWidgets.git/blob - src/os2/window.cpp
44481ff5dd0393a916e38767c56a618def006956
[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
2210 if (!bProcessed)
2211 {
2212 #ifdef __WXDEBUG__
2213 wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."),
2214 wxGetMessageName(uMsg));
2215 #endif // __WXDEBUG__
2216 mResult = OS2DefWindowProc(uMsg, wParam, lParam);
2217 }
2218 return mResult;
2219 } // end of wxWindow::OS2WindowProc
2220
2221 //
2222 // Dialog window proc
2223 //
2224 MRESULT wxDlgProc(
2225 HWND hWnd
2226 , UINT uMsg
2227 , MPARAM wParam
2228 , MPARAM lParam)
2229 {
2230 if (uMsg == WM_INITDLG)
2231 {
2232 //
2233 // For this message, returning TRUE tells system to set focus to the
2234 // first control in the dialog box
2235 //
2236 return (MRESULT)TRUE;
2237 }
2238 else
2239 {
2240 //
2241 // For all the other ones, FALSE means that we didn't process the
2242 // message
2243 //
2244 return (MRESULT)0;
2245 }
2246 } // end of wxDlgProc
2247
2248 wxWindow* wxFindWinFromHandle(
2249 WXHWND hWnd
2250 )
2251 {
2252 wxNode* pNode = wxWinHandleList->Find((long)hWnd);
2253
2254 if (!pNode)
2255 return NULL;
2256 return (wxWindow *)pNode->Data();
2257 } // end of wxFindWinFromHandle
2258
2259 void wxAssociateWinWithHandle(
2260 HWND hWnd
2261 , wxWindow* pWin
2262 )
2263 {
2264 //
2265 // Adding NULL hWnd is (first) surely a result of an error and
2266 // (secondly) breaks menu command processing
2267 //
2268 wxCHECK_RET( hWnd != (HWND)NULL,
2269 wxT("attempt to add a NULL hWnd to window list ignored") );
2270
2271
2272 wxWindow* pOldWin = wxFindWinFromHandle((WXHWND) hWnd);
2273
2274 if (pOldWin && (pOldWin != pWin))
2275 {
2276 wxString str(pWin->GetClassInfo()->GetClassName());
2277 wxLogError( "Bug! Found existing HWND %X for new window of class %s"
2278 ,(int)hWnd
2279 ,(const char*)str
2280 );
2281 }
2282 else if (!pOldWin)
2283 {
2284 wxWinHandleList->Append( (long)hWnd
2285 ,pWin
2286 );
2287 }
2288 } // end of wxAssociateWinWithHandle
2289
2290 void wxRemoveHandleAssociation(
2291 wxWindow* pWin
2292 )
2293 {
2294 wxWinHandleList->DeleteObject(pWin);
2295 } // end of wxRemoveHandleAssociation
2296
2297 //
2298 // Default destroyer - override if you destroy it in some other way
2299 // (e.g. with MDI child windows)
2300 //
2301 void wxWindow::OS2DestroyWindow()
2302 {
2303 }
2304
2305 void wxWindow::OS2DetachWindowMenu()
2306 {
2307 if (m_hMenu)
2308 {
2309 HMENU hMenu = (HMENU)m_hMenu;
2310
2311 int nN = (int)::WinSendMsg(hMenu, MM_QUERYITEMCOUNT, 0, 0);
2312 int i;
2313
2314 for (i = 0; i < nN; i++)
2315 {
2316 wxChar zBuf[100];
2317 int nChars = (int)::WinSendMsg( hMenu
2318 ,MM_QUERYITEMTEXT
2319 ,MPFROM2SHORT(i, nN)
2320 ,zBuf
2321 );
2322 if (!nChars)
2323 {
2324 wxLogLastError(wxT("GetMenuString"));
2325 continue;
2326 }
2327
2328 if (wxStrcmp(zBuf, wxT("&Window")) == 0)
2329 {
2330 ::WinSendMsg(hMenu, MM_DELETEITEM, MPFROM2SHORT(i, TRUE), 0);
2331 break;
2332 }
2333 }
2334 }
2335 } // end of wxWindow::OS2DetachWindowMenu
2336
2337 bool wxWindow::OS2Create(
2338 WXHWND hParent
2339 , PSZ zClass
2340 , const wxChar* zTitle
2341 , WXDWORD dwStyle
2342 , long lX
2343 , long lY
2344 , long lWidth
2345 , long lHeight
2346 , WXHWND hOwner
2347 , WXHWND hZOrder
2348 , unsigned long ulId
2349 , void* pCtlData
2350 , void* pPresParams
2351 )
2352 {
2353 ERRORID vError;
2354 wxString sError;
2355 long lX1 = 0L;
2356 long lY1 = 0L;
2357 long lWidth1 = 20L;
2358 long lHeight1 = 20L;
2359 int nControlId = 0;
2360 int nNeedsubclass = 0;
2361 PCSZ pszClass = zClass;
2362
2363 //
2364 // Find parent's size, if it exists, to set up a possible default
2365 // panel size the size of the parent window
2366 //
2367 RECTL vParentRect;
2368 HWND hWndClient;
2369
2370 if (lX > -1L)
2371 lX1 = lX;
2372 if (lY > -1L)
2373 lY1 = lY;
2374 if (lWidth > -1L)
2375 lWidth1 = lWidth;
2376 if (lHeight > -1L)
2377 lHeight1 = lHeight;
2378
2379 wxWndHook = this;
2380
2381 //
2382 // check to see if the new window is a standard control
2383 //
2384 if ((ULONG)zClass == (ULONG)WC_BUTTON ||
2385 (ULONG)zClass == (ULONG)WC_COMBOBOX ||
2386 (ULONG)zClass == (ULONG)WC_CONTAINER ||
2387 (ULONG)zClass == (ULONG)WC_ENTRYFIELD ||
2388 (ULONG)zClass == (ULONG)WC_FRAME ||
2389 (ULONG)zClass == (ULONG)WC_LISTBOX ||
2390 (ULONG)zClass == (ULONG)WC_MENU ||
2391 (ULONG)zClass == (ULONG)WC_NOTEBOOK ||
2392 (ULONG)zClass == (ULONG)WC_SCROLLBAR ||
2393 (ULONG)zClass == (ULONG)WC_SPINBUTTON ||
2394 (ULONG)zClass == (ULONG)WC_STATIC ||
2395 (ULONG)zClass == (ULONG)WC_TITLEBAR ||
2396 (ULONG)zClass == (ULONG)WC_VALUESET
2397 )
2398 {
2399 nControlId = ulId;
2400 }
2401 else
2402 {
2403 // no standard controls
2404 if(wxString (wxT("wxFrameClass")) == wxString(zClass) )
2405 {
2406 pszClass = WC_FRAME;
2407 nNeedsubclass = 1;
2408 }
2409 else
2410 {
2411 nControlId = ulId;
2412 if(nControlId < 0)
2413 nControlId = FID_CLIENT;
2414 }
2415 }
2416
2417 //
2418 // We will either have a registered class via string name or a standard PM Class via a long
2419 //
2420 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)hParent
2421 ,zClass
2422 ,(PSZ)zTitle ? zTitle : wxT("")
2423 ,(ULONG)dwStyle
2424 ,(LONG)lX1
2425 ,(LONG)lY1
2426 ,(LONG)lWidth
2427 ,(LONG)lHeight
2428 ,hOwner
2429 ,HWND_TOP
2430 ,(ULONG)nControlId
2431 ,pCtlData
2432 ,pPresParams
2433 );
2434 if (!m_hWnd)
2435 {
2436 vError = ::WinGetLastError(vHabmain);
2437 sError = wxPMErrorToStr(vError);
2438 wxLogError("Can't create window of class %s!. Error: %s\n", zClass, sError);
2439 return FALSE;
2440 }
2441 ::WinSetWindowULong(m_hWnd, QWL_USER, (ULONG) this);
2442 wxWndHook = NULL;
2443
2444 #ifdef __WXDEBUG__
2445 wxNode* pNode = wxWinHandleList->Member(this);
2446
2447 if (pNode)
2448 {
2449 HWND hWnd = (HWND)pNode->GetKeyInteger();
2450
2451 if (hWnd != (HWND)m_hWnd)
2452
2453 {
2454 wxLogError("A second HWND association is being added for the same window!");
2455 }
2456 }
2457 #endif
2458 wxAssociateWinWithHandle((HWND)m_hWnd
2459 ,this
2460 );
2461 //
2462 // Now need to subclass window.
2463 //
2464 if(!nNeedsubclass)
2465 {
2466 wxAssociateWinWithHandle((HWND)m_hWnd,this);
2467 }
2468 else
2469 {
2470 SubclassWin(GetHWND());
2471 }
2472 return TRUE;
2473 } // end of wxWindow::OS2Create
2474
2475 // ===========================================================================
2476 // OS2 PM message handlers
2477 // ===========================================================================
2478
2479 // ---------------------------------------------------------------------------
2480 // window creation/destruction
2481 // ---------------------------------------------------------------------------
2482
2483 bool wxWindow::HandleCreate(
2484 WXLPCREATESTRUCT vCs
2485 , bool* pbMayCreate
2486 )
2487 {
2488 wxWindowCreateEvent vEvent(this);
2489
2490 (void)GetEventHandler()->ProcessEvent(vEvent);
2491 *pbMayCreate = TRUE;
2492 return TRUE;
2493 } // end of wxWindow::HandleCreate
2494
2495 bool wxWindow::HandleDestroy()
2496 {
2497 wxWindowDestroyEvent vEvent(this);
2498
2499 (void)GetEventHandler()->ProcessEvent(vEvent);
2500
2501 //
2502 // Delete our drop target if we've got one
2503 //
2504 #if wxUSE_DRAG_AND_DROP
2505 if (m_dropTarget != NULL)
2506 {
2507 m_dropTarget->Revoke(m_hWnd);
2508 delete m_dropTarget;
2509 m_dropTarget = NULL;
2510 }
2511 #endif // wxUSE_DRAG_AND_DROP
2512
2513 //
2514 // WM_DESTROY handled
2515 //
2516 return TRUE;
2517 } // end of wxWindow::HandleDestroy
2518
2519 // ---------------------------------------------------------------------------
2520 // activation/focus
2521 // ---------------------------------------------------------------------------
2522 void wxWindow::OnSetFocus(
2523 wxFocusEvent& rEvent
2524 )
2525 {
2526 //
2527 // Panel wants to track the window which was the last to have focus in it,
2528 // so we want to set ourselves as the window which last had focus
2529 //
2530 // Notice that it's also important to do it upwards the tree becaus
2531 // otherwise when the top level panel gets focus, it won't set it back to
2532 // us, but to some other sibling
2533 //
2534 wxWindow* pWin = this;
2535
2536 while (pWin)
2537 {
2538 wxWindow* pParent = pWin->GetParent();
2539 wxPanel* pPanel = wxDynamicCast( pParent
2540 ,wxPanel
2541 );
2542 if (pPanel)
2543 {
2544 pPanel->SetLastFocus(pWin);
2545 }
2546 pWin = pParent;
2547 }
2548
2549 wxLogTrace(_T("focus"), _T("%s (0x%08x) gets focus"),
2550 GetClassInfo()->GetClassName(), GetHandle());
2551
2552 rEvent.Skip();
2553 } // end of wxWindow::OnSetFocus
2554
2555 bool wxWindow::HandleActivate(
2556 int nState
2557 , WXHWND WXUNUSED(hActivate)
2558 )
2559 {
2560 wxActivateEvent vEvent( wxEVT_ACTIVATE
2561 ,(bool)nState
2562 ,m_windowId
2563 );
2564 vEvent.SetEventObject(this);
2565 return GetEventHandler()->ProcessEvent(vEvent);
2566 } // end of wxWindow::HandleActivate
2567
2568 bool wxWindow::HandleSetFocus(
2569 WXHWND WXUNUSED(hWnd)
2570 )
2571 {
2572 #if wxUSE_CARET
2573 //
2574 // Deal with caret
2575 //
2576 if (m_caret)
2577 {
2578 m_caret->OnSetFocus();
2579 }
2580 #endif // wxUSE_CARET
2581
2582 //
2583 // Panel wants to track the window which was the last to have focus in it
2584 //
2585 wxPanel* pPanel = wxDynamicCast( GetParent()
2586 ,wxPanel
2587 );
2588 if (pPanel)
2589 {
2590 pPanel->SetLastFocus(this);
2591 }
2592
2593 wxFocusEvent vEvent(wxEVT_SET_FOCUS, m_windowId);
2594
2595 vEvent.SetEventObject(this);
2596 return GetEventHandler()->ProcessEvent(vEvent);
2597 } // end of wxWindow::HandleSetFocus
2598
2599 bool wxWindow::HandleKillFocus(
2600 WXHWND WXUNUSED(hWnd)
2601 )
2602 {
2603 #if wxUSE_CARET
2604 //
2605 // Deal with caret
2606 //
2607 if (m_caret)
2608 {
2609 m_caret->OnKillFocus();
2610 }
2611 #endif // wxUSE_CARET
2612
2613 wxFocusEvent vEvent( wxEVT_KILL_FOCUS
2614 ,m_windowId
2615 );
2616
2617 vEvent.SetEventObject(this);
2618 return GetEventHandler()->ProcessEvent(vEvent);
2619 } // end of wxWindow::HandleKillFocus
2620
2621 // ---------------------------------------------------------------------------
2622 // miscellaneous
2623 // ---------------------------------------------------------------------------
2624
2625 bool wxWindow::HandleShow(
2626 bool bShow
2627 , int nStatus
2628 )
2629 {
2630 wxShowEvent vEvent( GetId()
2631 ,bShow
2632 );
2633
2634 vEvent.m_eventObject = this;
2635 return GetEventHandler()->ProcessEvent(vEvent);
2636 } // end of wxWindow::HandleShow
2637
2638 bool wxWindow::HandleInitDialog(
2639 WXHWND WXUNUSED(hWndFocus)
2640 )
2641 {
2642 wxInitDialogEvent vEvent(GetId());
2643
2644 vEvent.m_eventObject = this;
2645 return GetEventHandler()->ProcessEvent(vEvent);
2646 } // end of wxWindow::HandleInitDialog
2647
2648 bool wxWindow::HandleEndDrag(WXWPARAM wParam)
2649 {
2650 // TODO: We'll handle drag and drop later
2651 return FALSE;
2652 }
2653
2654 bool wxWindow::HandleSetCursor(
2655 USHORT vId
2656 , WXHWND hPointer
2657 )
2658 {
2659 //
2660 // Under OS/2 PM this allows the pointer to be changed
2661 // as it passes over a control
2662 //
2663 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)hPointer);
2664 return TRUE;
2665 } // end of wxWindow::HandleSetCursor
2666
2667 // ---------------------------------------------------------------------------
2668 // owner drawn stuff
2669 // ---------------------------------------------------------------------------
2670 bool wxWindow::OS2OnDrawItem(
2671 int vId
2672 , WXDRAWITEMSTRUCT* pItemStruct
2673 )
2674 {
2675 //
2676 // I'll get to owner drawn stuff later
2677 //
2678
2679 //
2680 // is it a menu item or control?
2681 //
2682 wxWindow* pItem = FindItem(vId);
2683
2684 #if wxUSE_OWNER_DRAWN
2685 if (pItem && pItem->IsKindOf(CLASSINFO(wxControl)))
2686 {
2687 return ((wxControl *)pItem)->OS2OnDraw(pItemStruct);
2688 }
2689 else if (pItem && pItem->IsKindOf(CLASSINFO(wxMenu)))
2690 {
2691 /*
2692 // TODO: draw a menu item
2693 //
2694 POWNERITEM pDrawStruct = (OWNERITEM *)pItemStruct;
2695 wxMenuItem* pMenuItem = (wxMenuItem *)(pDrawStruct->pItemData);
2696
2697 wxCHECK(pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE);
2698
2699 //
2700 // Prepare to call OnDrawItem()
2701 //
2702 HPSdc;
2703 dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE);
2704 wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
2705 pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
2706 pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
2707
2708 return pMenuItem->OnDrawItem
2709 (
2710 dc, rect,
2711 (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
2712 (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
2713 );
2714 */
2715 }
2716
2717 else
2718 return FALSE;
2719 #endif
2720 return TRUE;
2721 } // end of wxWindow::OS2OnDrawItem
2722
2723 bool wxWindow::OS2OnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
2724 {
2725 // TODO: more owner drawn menu related stuff, get to it later
2726 /*
2727 #if wxUSE_OWNER_DRAWN
2728 // is it a menu item?
2729 if ( id == 0 )
2730 {
2731 MEASUREITEMSTRUCT *pMeasureStruct = (MEASUREITEMSTRUCT *)itemStruct;
2732 wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
2733
2734 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
2735
2736 return pMenuItem->OnMeasureItem(&pMeasureStruct->itemWidth,
2737 &pMeasureStruct->itemHeight);
2738 }
2739
2740 wxWindow *item = FindItem(id);
2741 if ( item && item->IsKindOf(CLASSINFO(wxControl)) )
2742 {
2743 return ((wxControl *)item)->MSWOnMeasure(itemStruct);
2744 }
2745 #endif // owner-drawn menus
2746 */
2747 return FALSE;
2748 }
2749
2750 // ---------------------------------------------------------------------------
2751 // colours and palettes
2752 // ---------------------------------------------------------------------------
2753
2754 bool wxWindow::HandleSysColorChange()
2755 {
2756 wxSysColourChangedEvent vEvent;
2757
2758 vEvent.SetEventObject(this);
2759 return GetEventHandler()->ProcessEvent(vEvent);
2760 } // end of wxWindow::HandleSysColorChange
2761
2762 bool wxWindow::HandleCtlColor(
2763 WXHBRUSH* phBrush
2764 )
2765 {
2766 //
2767 // Not much provided with message. So not sure I can do anything with it
2768 //
2769 return TRUE;
2770 } // end of wxWindow::HandleCtlColor
2771
2772 bool wxWindow::HandleWindowParams(
2773 PWNDPARAMS pWndParams
2774 , WXLPARAM lParam
2775 )
2776 {
2777 // TODO: I'll do something here, just not sure what yet
2778 return TRUE;
2779 }
2780
2781 // Define for each class of dialog and control
2782 WXHBRUSH wxWindow::OnCtlColor(WXHDC hDC,
2783 WXHWND hWnd,
2784 WXUINT nCtlColor,
2785 WXUINT message,
2786 WXWPARAM wParam,
2787 WXLPARAM lParam)
2788 {
2789 return (WXHBRUSH)0;
2790 }
2791
2792 bool wxWindow::HandlePaletteChanged()
2793 {
2794 // need to set this to something first
2795 WXHWND hWndPalChange = NULLHANDLE;
2796
2797 wxPaletteChangedEvent vEvent(GetId());
2798
2799 vEvent.SetEventObject(this);
2800 vEvent.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
2801
2802 return GetEventHandler()->ProcessEvent(vEvent);
2803 } // end of wxWindow::HandlePaletteChanged
2804
2805 bool wxWindow::HandlePresParamChanged(
2806 WXWPARAM wParam
2807 )
2808 {
2809 //
2810 // TODO: Once again I'll do something here when I need it
2811 //
2812 //wxQueryNewPaletteEvent event(GetId());
2813 //event.SetEventObject(this);
2814 // if the background is erased
2815 // bProcessed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
2816
2817 return FALSE; //GetEventHandler()->ProcessEvent(event) && event.GetPaletteRealized();
2818 }
2819
2820 //
2821 // Responds to colour changes: passes event on to children.
2822 //
2823 void wxWindow::OnSysColourChanged(
2824 wxSysColourChangedEvent& rEvent
2825 )
2826 {
2827 wxNode* pNode = GetChildren().First();
2828
2829 while (pNode)
2830 {
2831 //
2832 // Only propagate to non-top-level windows
2833 //
2834 wxWindow* pWin = (wxWindow *)pNode->Data();
2835
2836 if (pWin->GetParent())
2837 {
2838 wxSysColourChangedEvent vEvent;
2839
2840 rEvent.m_eventObject = pWin;
2841 pWin->GetEventHandler()->ProcessEvent(vEvent);
2842 }
2843 pNode = pNode->Next();
2844 }
2845 } // end of wxWindow::OnSysColourChanged
2846
2847 // ---------------------------------------------------------------------------
2848 // painting
2849 // ---------------------------------------------------------------------------
2850
2851 bool wxWindow::HandlePaint()
2852 {
2853 HRGN hRgn = NULLHANDLE;
2854 wxPaintEvent vEvent;
2855 HPS hPS;
2856 RECTL vRect;
2857
2858 if (::WinQueryUpdateRegion(GetHwnd(), hRgn) == RGN_NULL)
2859 {
2860 wxLogLastError("CreateRectRgn");
2861 return FALSE;
2862 }
2863 //
2864 // Debug code
2865 //
2866 #ifdef __WXDEBUG__
2867 {
2868 HWND hWnd;
2869 HWND hWnd0 = NULLHANDLE;
2870
2871 hWnd = GetHwnd();
2872 if(hWnd != hWnd0)
2873 printf("HandlePaint hWnd=%x ",hWnd);
2874 }
2875 #endif
2876
2877 m_updateRegion = wxRegion(hRgn);
2878 vEvent.SetEventObject(this);
2879 return (GetEventHandler()->ProcessEvent(vEvent));
2880 } // end of wxWindow::HandlePaint
2881
2882 bool wxWindow::HandleEraseBkgnd(WXHDC hdc)
2883 {
2884 // TODO: will have to worry about this later as part of
2885 // the handling of changed presentation parameters
2886 /*
2887 if ( ::IsIconic(GetHwnd()) )
2888 return TRUE;
2889
2890 wxDC dc;
2891
2892 dc.SetHDC(hdc);
2893 dc.SetWindow(this);
2894 dc.BeginDrawing();
2895
2896 wxEraseEvent event(m_windowId, &dc);
2897 event.SetEventObject(this);
2898 bool rc = GetEventHandler()->ProcessEvent(event);
2899
2900 dc.EndDrawing();
2901 dc.SelectOldObjects(hdc);
2902 dc.SetHDC((WXHDC) NULL);
2903 */
2904 return TRUE;
2905 } // end of wxWindow::HandleEraseBkgnd
2906
2907 void wxWindow::OnEraseBackground(
2908 wxEraseEvent& rEvent
2909 )
2910 {
2911 // TODO:
2912 } // end of wxWindow::OnEraseBackground
2913
2914 // ---------------------------------------------------------------------------
2915 // moving and resizing
2916 // ---------------------------------------------------------------------------
2917
2918 bool wxWindow::HandleMinimize()
2919 {
2920 wxIconizeEvent vEvent(m_windowId);
2921
2922 vEvent.SetEventObject(this);
2923 return GetEventHandler()->ProcessEvent(vEvent);
2924 } // end of wxWindow::HandleMinimize
2925
2926 bool wxWindow::HandleMaximize()
2927 {
2928 wxMaximizeEvent vEvent(m_windowId);
2929
2930 vEvent.SetEventObject(this);
2931 return GetEventHandler()->ProcessEvent(vEvent);
2932 } // end of wxWindow::HandleMaximize
2933
2934 bool wxWindow::HandleMove(
2935 int nX
2936 , int nY
2937 )
2938 {
2939 wxMoveEvent vEvent( wxPoint( nX
2940 ,nY
2941 )
2942 ,m_windowId
2943 );
2944
2945 vEvent.SetEventObject(this);
2946 return GetEventHandler()->ProcessEvent(vEvent);
2947 } // end of wxWindow::HandleMove
2948
2949 bool wxWindow::HandleSize(
2950 int nWidth
2951 , int nHeight
2952 , WXUINT WXUNUSED(nFlag)
2953 )
2954 {
2955 wxSizeEvent vEvent( wxSize( nWidth
2956 ,nHeight
2957 )
2958 ,m_windowId
2959 );
2960
2961 vEvent.SetEventObject(this);
2962 return GetEventHandler()->ProcessEvent(vEvent);
2963 } // end of wxWindow::HandleSize
2964
2965 bool wxWindow::HandleGetMinMaxInfo(
2966 PSWP pSwp
2967 )
2968 {
2969 bool bRc = FALSE;
2970 POINTL vPoint;
2971
2972 switch(pSwp->fl)
2973 {
2974 case SWP_MAXIMIZE:
2975 ::WinGetMaxPosition(GetHwnd(), pSwp);
2976 m_maxWidth = pSwp->cx;
2977 m_maxHeight = pSwp->cy;
2978 break;
2979
2980 case SWP_MINIMIZE:
2981 ::WinGetMinPosition(GetHwnd(), pSwp, &vPoint);
2982 m_minWidth = pSwp->cx;
2983 m_minHeight = pSwp->cy;
2984 break;
2985
2986 default:
2987 return FALSE;
2988 }
2989 return TRUE;
2990 } // end of wxWindow::HandleGetMinMaxInfo
2991
2992 // ---------------------------------------------------------------------------
2993 // command messages
2994 // ---------------------------------------------------------------------------
2995 bool wxWindow::HandleCommand(
2996 WXWORD wId
2997 , WXWORD wCmd
2998 , WXHWND hControl
2999 )
3000 {
3001 if (wxCurrentPopupMenu)
3002 {
3003 wxMenu* pPopupMenu = wxCurrentPopupMenu;
3004
3005 wxCurrentPopupMenu = NULL;
3006 return pPopupMenu->OS2Command(wCmd, wId);
3007 }
3008
3009 wxWindow* pWin = FindItem(wId);
3010
3011 if (!pWin)
3012 {
3013 pWin = wxFindWinFromHandle(hControl);
3014 }
3015
3016 if (pWin)
3017 return pWin->OS2Command( wCmd
3018 ,wId
3019 );
3020 return FALSE;
3021 } // end of wxWindow::HandleCommand
3022
3023 bool wxWindow::HandleSysCommand(
3024 WXWPARAM wParam
3025 , WXLPARAM lParam
3026 )
3027 {
3028 //
3029 // 4 bits are reserved
3030 //
3031 switch (SHORT1FROMMP(wParam))
3032 {
3033 case SC_MAXIMIZE:
3034 return HandleMaximize();
3035
3036 case SC_MINIMIZE:
3037 return HandleMinimize();
3038 }
3039 return FALSE;
3040 } // end of wxWindow::HandleSysCommand
3041
3042 // ---------------------------------------------------------------------------
3043 // mouse events
3044 // ---------------------------------------------------------------------------
3045
3046 void wxWindow::InitMouseEvent(
3047 wxMouseEvent& rEvent
3048 , int nX
3049 , int nY
3050 , WXUINT uFlags
3051 )
3052 {
3053 rEvent.m_x = nX;
3054 rEvent.m_y = nY;
3055 rEvent.m_shiftDown = ((uFlags & VK_SHIFT) != 0);
3056 rEvent.m_controlDown = ((uFlags & VK_CTRL) != 0);
3057 rEvent.m_leftDown = ((uFlags & VK_BUTTON1) != 0);
3058 rEvent.m_middleDown = ((uFlags & VK_BUTTON3) != 0);
3059 rEvent.m_rightDown = ((uFlags & VK_BUTTON2) != 0);
3060 rEvent.SetTimestamp(s_currentMsg.time);
3061 rEvent.m_eventObject = this;
3062
3063 #if wxUSE_MOUSEEVENT_HACK
3064 m_lastMouseX = nX;
3065 m_lastMouseY = nY;
3066 m_lastMouseEvent = rEvent.GetEventType();
3067 #endif // wxUSE_MOUSEEVENT_HACK
3068 } // end of wxWindow::InitMouseEvent
3069
3070 bool wxWindow::HandleMouseEvent(
3071 WXUINT uMsg
3072 , int nX
3073 , int nY
3074 , WXUINT uFlags
3075 )
3076 {
3077 //
3078 // The mouse events take consecutive IDs from WM_MOUSEFIRST to
3079 // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST
3080 // from the message id and take the value in the table to get wxWin event
3081 // id
3082 //
3083 static const wxEventType eventsMouse[] =
3084 {
3085 wxEVT_MOTION,
3086 wxEVT_LEFT_DOWN,
3087 wxEVT_LEFT_UP,
3088 wxEVT_LEFT_DCLICK,
3089 wxEVT_RIGHT_DOWN,
3090 wxEVT_RIGHT_UP,
3091 wxEVT_RIGHT_DCLICK,
3092 wxEVT_MIDDLE_DOWN,
3093 wxEVT_MIDDLE_UP,
3094 wxEVT_MIDDLE_DCLICK
3095 };
3096
3097 wxMouseEvent vEvent(eventsMouse[uMsg - WM_MOUSEMOVE]);
3098
3099 InitMouseEvent( vEvent
3100 ,nX
3101 ,nY
3102 ,uFlags
3103 );
3104
3105 return GetEventHandler()->ProcessEvent(vEvent);
3106 } // end of wxWindow::HandleMouseEvent
3107
3108 bool wxWindow::HandleMouseMove(
3109 int nX
3110 , int nY
3111 , WXUINT uFlags
3112 )
3113 {
3114 if (!m_bMouseInWindow)
3115 {
3116 //
3117 // Generate an ENTER event
3118 //
3119 m_bMouseInWindow = TRUE;
3120
3121 wxMouseEvent vEvent(wxEVT_ENTER_WINDOW);
3122
3123 InitMouseEvent( vEvent
3124 ,nX
3125 ,nY
3126 ,uFlags
3127 );
3128
3129 (void)GetEventHandler()->ProcessEvent(vEvent);
3130 }
3131 return HandleMouseEvent( WM_MOUSEMOVE
3132 ,nX
3133 ,nY
3134 ,uFlags
3135 );
3136 } // end of wxWindow::HandleMouseMove
3137
3138 // ---------------------------------------------------------------------------
3139 // keyboard handling
3140 // ---------------------------------------------------------------------------
3141
3142 //
3143 // Create the key event of the given type for the given key - used by
3144 // HandleChar and HandleKeyDown/Up
3145 //
3146 wxKeyEvent wxWindow::CreateKeyEvent(
3147 wxEventType eType
3148 , int nId
3149 , WXLPARAM lParam
3150 ) const
3151 {
3152 wxKeyEvent vEvent(eType);
3153
3154 vEvent.SetId(GetId());
3155 vEvent.m_shiftDown = IsShiftDown();
3156 vEvent.m_controlDown = IsCtrlDown();
3157 vEvent.m_altDown = (HIWORD(lParam) & KC_ALT) == KC_ALT;
3158
3159 vEvent.m_eventObject = (wxWindow *)this; // const_cast
3160 vEvent.m_keyCode = nId;
3161 vEvent.SetTimestamp(s_currentMsg.time);
3162
3163 //
3164 // Translate the position to client coords
3165 //
3166 POINTL vPoint;
3167 RECTL vRect;
3168
3169 ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
3170 ::WinQueryWindowRect( GetHwnd()
3171 ,&vRect
3172 );
3173
3174 vPoint.x -= vRect.xLeft;
3175 vPoint.y -= vRect.yBottom;
3176
3177 vEvent.m_x = vPoint.x;
3178 vEvent.m_y = vPoint.y;
3179
3180 return vEvent;
3181 } // end of wxWindow::CreateKeyEvent
3182
3183 //
3184 // isASCII is TRUE only when we're called from WM_CHAR handler and not from
3185 // WM_KEYDOWN one
3186 //
3187 bool wxWindow::HandleChar(
3188 WXWORD wParam
3189 , WXLPARAM lParam
3190 , bool isASCII
3191 )
3192 {
3193 bool bCtrlDown = FALSE;
3194 int vId;
3195
3196 if (isASCII)
3197 {
3198 //
3199 // If 1 -> 26, translate to CTRL plus a letter.
3200 //
3201 vId = wParam;
3202 if ((vId > 0) && (vId < 27))
3203 {
3204 switch (vId)
3205 {
3206 case 13:
3207 vId = WXK_RETURN;
3208 break;
3209
3210 case 8:
3211 vId = WXK_BACK;
3212 break;
3213
3214 case 9:
3215 vId = WXK_TAB;
3216 break;
3217
3218 default:
3219 bCtrlDown = TRUE;
3220 vId = vId + 96;
3221 }
3222 }
3223 }
3224 else if ( (vId = wxCharCodeOS2ToWX(wParam)) == 0)
3225 {
3226 //
3227 // It's ASCII and will be processed here only when called from
3228 // WM_CHAR (i.e. when isASCII = TRUE), don't process it now
3229 //
3230 vId = -1;
3231 }
3232
3233 if (vId != -1)
3234 {
3235 wxKeyEvent vEvent(CreateKeyEvent( wxEVT_CHAR
3236 ,vId
3237 ,lParam
3238 ));
3239
3240 if (bCtrlDown)
3241 {
3242 vEvent.m_controlDown = TRUE;
3243 }
3244
3245 if (GetEventHandler()->ProcessEvent(vEvent))
3246 return TRUE;
3247 }
3248 return FALSE;
3249 }
3250
3251 bool wxWindow::HandleKeyDown(
3252 WXWORD wParam
3253 , WXLPARAM lParam
3254 )
3255 {
3256 int nId = wxCharCodeOS2ToWX(wParam);
3257
3258 if (!nId)
3259 {
3260 //
3261 // Normal ASCII char
3262 //
3263 nId = wParam;
3264 }
3265
3266 if (nId != -1)
3267 {
3268 wxKeyEvent vEvent(CreateKeyEvent( wxEVT_KEY_DOWN
3269 ,nId
3270 ,lParam
3271 ));
3272
3273 if (GetEventHandler()->ProcessEvent(vEvent))
3274 {
3275 return TRUE;
3276 }
3277 }
3278 return FALSE;
3279 } // end of wxWindow::HandleKeyDown
3280
3281 bool wxWindow::HandleKeyUp(
3282 WXWORD wParam
3283 , WXLPARAM lParam
3284 )
3285 {
3286 int nId = wxCharCodeOS2ToWX(wParam);
3287
3288 if (!nId)
3289 {
3290 //
3291 // Normal ASCII char
3292 //
3293 nId = wParam;
3294 }
3295
3296 if (nId != -1)
3297 {
3298 wxKeyEvent vEvent(CreateKeyEvent( wxEVT_KEY_UP
3299 ,nId
3300 ,lParam
3301 ));
3302
3303 if (GetEventHandler()->ProcessEvent(vEvent))
3304 return TRUE;
3305 }
3306 return FALSE;
3307 } // end of wxWindow::HandleKeyUp
3308
3309 // ---------------------------------------------------------------------------
3310 // joystick
3311 // ---------------------------------------------------------------------------
3312
3313 // ---------------------------------------------------------------------------
3314 // scrolling
3315 // ---------------------------------------------------------------------------
3316
3317 bool wxWindow::OS2OnScroll(
3318 int nOrientation
3319 , WXWORD wParam
3320 , WXWORD wPos
3321 , WXHWND hControl
3322 )
3323 {
3324 if (hControl)
3325 {
3326 wxWindow* pChild = wxFindWinFromHandle(hControl);
3327
3328 if (pChild )
3329 return pChild->OS2OnScroll( nOrientation
3330 ,wParam
3331 ,wPos
3332 ,hControl
3333 );
3334 }
3335
3336 wxScrollWinEvent vEvent;
3337
3338 vEvent.SetPosition(wPos);
3339 vEvent.SetOrientation(nOrientation);
3340 vEvent.m_eventObject = this;
3341
3342 switch (wParam)
3343 {
3344 case SB_LINEUP:
3345 vEvent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
3346 break;
3347
3348 case SB_LINEDOWN:
3349 vEvent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
3350 break;
3351
3352 case SB_PAGEUP:
3353 vEvent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
3354 break;
3355
3356 case SB_PAGEDOWN:
3357 vEvent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
3358 break;
3359
3360 case SB_SLIDERPOSITION:
3361 vEvent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
3362 break;
3363
3364 case SB_SLIDERTRACK:
3365 vEvent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
3366 break;
3367
3368 default:
3369 return FALSE;
3370 }
3371 return GetEventHandler()->ProcessEvent(vEvent);
3372 } // end of wxWindow::OS2OnScroll
3373
3374 // ===========================================================================
3375 // global functions
3376 // ===========================================================================
3377
3378 void wxGetCharSize(
3379 WXHWND hWnd
3380 , int* pX
3381 , int* pY
3382 ,wxFont* pTheFont
3383 )
3384 {
3385 // TODO: we'll do this later
3386 } // end of wxGetCharSize
3387
3388 //
3389 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
3390 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
3391 //
3392 int wxCharCodeOS2ToWX(
3393 int nKeySym
3394 )
3395 {
3396 int nId = 0;
3397
3398 switch (nKeySym)
3399 {
3400 case VK_BACKTAB: nId = WXK_BACK; break;
3401 case VK_TAB: nId = WXK_TAB; break;
3402 case VK_CLEAR: nId = WXK_CLEAR; break;
3403 case VK_ENTER: nId = WXK_RETURN; break;
3404 case VK_SHIFT: nId = WXK_SHIFT; break;
3405 case VK_CTRL: nId = WXK_CONTROL; break;
3406 case VK_PAUSE: nId = WXK_PAUSE; break;
3407 case VK_SPACE: nId = WXK_SPACE; break;
3408 case VK_ESC: nId = WXK_ESCAPE; break;
3409 case VK_END: nId = WXK_END; break;
3410 case VK_HOME : nId = WXK_HOME; break;
3411 case VK_LEFT : nId = WXK_LEFT; break;
3412 case VK_UP: nId = WXK_UP; break;
3413 case VK_RIGHT: nId = WXK_RIGHT; break;
3414 case VK_DOWN : nId = WXK_DOWN; break;
3415 case VK_PRINTSCRN: nId = WXK_PRINT; break;
3416 case VK_INSERT: nId = WXK_INSERT; break;
3417 case VK_DELETE: nId = WXK_DELETE; break;
3418 case VK_F1: nId = WXK_F1; break;
3419 case VK_F2: nId = WXK_F2; break;
3420 case VK_F3: nId = WXK_F3; break;
3421 case VK_F4: nId = WXK_F4; break;
3422 case VK_F5: nId = WXK_F5; break;
3423 case VK_F6: nId = WXK_F6; break;
3424 case VK_F7: nId = WXK_F7; break;
3425 case VK_F8: nId = WXK_F8; break;
3426 case VK_F9: nId = WXK_F9; break;
3427 case VK_F10: nId = WXK_F10; break;
3428 case VK_F11: nId = WXK_F11; break;
3429 case VK_F12: nId = WXK_F12; break;
3430 case VK_F13: nId = WXK_F13; break;
3431 case VK_F14: nId = WXK_F14; break;
3432 case VK_F15: nId = WXK_F15; break;
3433 case VK_F16: nId = WXK_F16; break;
3434 case VK_F17: nId = WXK_F17; break;
3435 case VK_F18: nId = WXK_F18; break;
3436 case VK_F19: nId = WXK_F19; break;
3437 case VK_F20: nId = WXK_F20; break;
3438 case VK_F21: nId = WXK_F21; break;
3439 case VK_F22: nId = WXK_F22; break;
3440 case VK_F23: nId = WXK_F23; break;
3441 case VK_F24: nId = WXK_F24; break;
3442 case VK_NUMLOCK: nId = WXK_NUMLOCK; break;
3443 case VK_SCRLLOCK: nId = WXK_SCROLL; break;
3444 default:
3445 {
3446 return 0;
3447 }
3448 }
3449 return nId;
3450 } // end of wxCharCodeOS2ToWX
3451
3452 int wxCharCodeWXToOS2(
3453 int nId
3454 , bool* bIsVirtual
3455 )
3456 {
3457 int nKeySym = 0;
3458
3459 *bIsVirtual = TRUE;
3460 switch (nId)
3461 {
3462 case WXK_CLEAR: nKeySym = VK_CLEAR; break;
3463 case WXK_SHIFT: nKeySym = VK_SHIFT; break;
3464 case WXK_CONTROL: nKeySym = VK_CTRL; break;
3465 case WXK_PAUSE: nKeySym = VK_PAUSE; break;
3466 case WXK_END: nKeySym = VK_END; break;
3467 case WXK_HOME : nKeySym = VK_HOME; break;
3468 case WXK_LEFT : nKeySym = VK_LEFT; break;
3469 case WXK_UP: nKeySym = VK_UP; break;
3470 case WXK_RIGHT: nKeySym = VK_RIGHT; break;
3471 case WXK_DOWN : nKeySym = VK_DOWN; break;
3472 case WXK_PRINT: nKeySym = VK_PRINTSCRN; break;
3473 case WXK_INSERT: nKeySym = VK_INSERT; break;
3474 case WXK_DELETE: nKeySym = VK_DELETE; break;
3475 case WXK_F1: nKeySym = VK_F1; break;
3476 case WXK_F2: nKeySym = VK_F2; break;
3477 case WXK_F3: nKeySym = VK_F3; break;
3478 case WXK_F4: nKeySym = VK_F4; break;
3479 case WXK_F5: nKeySym = VK_F5; break;
3480 case WXK_F6: nKeySym = VK_F6; break;
3481 case WXK_F7: nKeySym = VK_F7; break;
3482 case WXK_F8: nKeySym = VK_F8; break;
3483 case WXK_F9: nKeySym = VK_F9; break;
3484 case WXK_F10: nKeySym = VK_F10; break;
3485 case WXK_F11: nKeySym = VK_F11; break;
3486 case WXK_F12: nKeySym = VK_F12; break;
3487 case WXK_F13: nKeySym = VK_F13; break;
3488 case WXK_F14: nKeySym = VK_F14; break;
3489 case WXK_F15: nKeySym = VK_F15; break;
3490 case WXK_F16: nKeySym = VK_F16; break;
3491 case WXK_F17: nKeySym = VK_F17; break;
3492 case WXK_F18: nKeySym = VK_F18; break;
3493 case WXK_F19: nKeySym = VK_F19; break;
3494 case WXK_F20: nKeySym = VK_F20; break;
3495 case WXK_F21: nKeySym = VK_F21; break;
3496 case WXK_F22: nKeySym = VK_F22; break;
3497 case WXK_F23: nKeySym = VK_F23; break;
3498 case WXK_F24: nKeySym = VK_F24; break;
3499 case WXK_NUMLOCK: nKeySym = VK_NUMLOCK; break;
3500 case WXK_SCROLL: nKeySym = VK_SCRLLOCK; break;
3501 default:
3502 {
3503 *bIsVirtual = FALSE;
3504 nKeySym = nId;
3505 break;
3506 }
3507 }
3508 return nKeySym;
3509 } // end of wxCharCodeWXToOS2
3510
3511 wxWindow* wxGetActiveWindow()
3512 {
3513 HWND hWnd = ::WinQueryActiveWindow(HWND_DESKTOP);
3514
3515 if (hWnd != 0)
3516 {
3517 return wxFindWinFromHandle((WXHWND)hWnd);
3518 }
3519 return NULL;
3520 } // end of wxGetActiveWindow
3521
3522 #ifdef __WXDEBUG__
3523 const char* wxGetMessageName(
3524 int nMessage)
3525 {
3526 switch (nMessage)
3527 {
3528 case 0x0000: return "WM_NULL";
3529 case 0x0001: return "WM_CREATE";
3530 case 0x0002: return "WM_DESTROY";
3531 case 0x0004: return "WM_ENABLE";
3532 case 0x0005: return "WM_SHOW";
3533 case 0x0006: return "WM_MOVE";
3534 case 0x0007: return "WM_SIZE";
3535 case 0x0008: return "WM_ADJUSTWINDOWPOS";
3536 case 0x0009: return "WM_CALCVALIDRECTS";
3537 case 0x000A: return "WM_SETWINDOWPARAMS";
3538 case 0x000B: return "WM_QUERYWINDOWPARAMS";
3539 case 0x000C: return "WM_HITTEST";
3540 case 0x000D: return "WM_ACTIVATE";
3541 case 0x000F: return "WM_SETFOCUS";
3542 case 0x0010: return "WM_SETSELECTION";
3543 case 0x0011: return "WM_PPAINT";
3544 case 0x0012: return "WM_PSETFOCUS";
3545 case 0x0013: return "WM_PSYSCOLORCHANGE";
3546 case 0x0014: return "WM_PSIZE";
3547 case 0x0015: return "WM_PACTIVATE";
3548 case 0x0016: return "WM_PCONTROL";
3549 case 0x0020: return "WM_COMMAND";
3550 case 0x0021: return "WM_SYSCOMMAND";
3551 case 0x0022: return "WM_HELP";
3552 case 0x0023: return "WM_PAINT";
3553 case 0x0024: return "WM_TIMER";
3554 case 0x0025: return "WM_SEM1";
3555 case 0x0026: return "WM_SEM2";
3556 case 0x0027: return "WM_SEM3";
3557 case 0x0028: return "WM_SEM4";
3558 case 0x0029: return "WM_CLOSE";
3559 case 0x002A: return "WM_QUIT";
3560 case 0x002B: return "WM_SYSCOLORCHANGE";
3561 case 0x002D: return "WM_SYSVALUECHANGE";
3562 case 0x002E: return "WM_APPTERMINATENOTIFY";
3563 case 0x002F: return "WM_PRESPARAMCHANGED";
3564 // Control notification messages
3565 case 0x0030: return "WM_CONTROL";
3566 case 0x0031: return "WM_VSCROLL";
3567 case 0x0032: return "WM_HSCROLL";
3568 case 0x0033: return "WM_INITMENU";
3569 case 0x0034: return "WM_MENUSELECT";
3570 case 0x0035: return "WM_MENUSEND";
3571 case 0x0036: return "WM_DRAWITEM";
3572 case 0x0037: return "WM_MEASUREITEM";
3573 case 0x0038: return "WM_CONTROLPOINTER";
3574 case 0x003A: return "WM_QUERYDLGCODE";
3575 case 0x003B: return "WM_INITDLG";
3576 case 0x003C: return "WM_SUBSTITUTESTRING";
3577 case 0x003D: return "WM_MATCHMNEMONIC";
3578 case 0x003E: return "WM_SAVEAPPLICATION";
3579 case 0x0129: return "WM_CTLCOLORCHANGE";
3580 case 0x0130: return "WM_QUERYCTLTYPE";
3581 // Frame messages
3582 case 0x0040: return "WM_FLASHWINDOW";
3583 case 0x0041: return "WM_FORMATFRAME";
3584 case 0x0042: return "WM_UPDATEFRAME";
3585 case 0x0043: return "WM_FOCUSCHANGE";
3586 case 0x0044: return "WM_SETBORDERSIZE";
3587 case 0x0045: return "WM_TRACKFRAME";
3588 case 0x0046: return "WM_MINMAXFRAME";
3589 case 0x0047: return "WM_SETICON";
3590 case 0x0048: return "WM_QUERYICON";
3591 case 0x0049: return "WM_SETACCELTABLE";
3592 case 0x004A: return "WM_QUERYACCELTABLE";
3593 case 0x004B: return "WM_TRANSLATEACCEL";
3594 case 0x004C: return "WM_QUERYTRACKINFO";
3595 case 0x004D: return "WM_QUERYBORDERSIZE";
3596 case 0x004E: return "WM_NEXTMENU";
3597 case 0x004F: return "WM_ERASEBACKGROUND";
3598 case 0x0050: return "WM_QUERYFRAMEINFO";
3599 case 0x0051: return "WM_QUERYFOCUSCHAIN";
3600 case 0x0052: return "WM_OWNERPOSCHANGE";
3601 case 0x0053: return "WM_CACLFRAMERECT";
3602 case 0x0055: return "WM_WINDOWPOSCHANGED";
3603 case 0x0056: return "WM_ADJUSTFRAMEPOS";
3604 case 0x0059: return "WM_QUERYFRAMECTLCOUNT";
3605 case 0x005B: return "WM_QUERYHELPINFO";
3606 case 0x005C: return "WM_SETHELPINFO";
3607 case 0x005D: return "WM_ERROR";
3608 case 0x005E: return "WM_REALIZEPALETTE";
3609 // Clipboard messages
3610 case 0x0060: return "WM_RENDERFMT";
3611 case 0x0061: return "WM_RENDERALLFMTS";
3612 case 0x0062: return "WM_DESTROYCLIPBOARD";
3613 case 0x0063: return "WM_PAINTCLIPBOARD";
3614 case 0x0064: return "WM_SIZECLIPBOARD";
3615 case 0x0065: return "WM_HSCROLLCLIPBOARD";
3616 case 0x0066: return "WM_VSCROLLCLIPBOARD";
3617 case 0x0067: return "WM_DRAWCLIPBOARD";
3618 // mouse messages
3619 case 0x0070: return "WM_MOUSEMOVE";
3620 case 0x0071: return "WM_BUTTON1DOWN";
3621 case 0x0072: return "WM_BUTTON1UP";
3622 case 0x0073: return "WM_BUTTON1DBLCLK";
3623 case 0x0074: return "WM_BUTTON2DOWN";
3624 case 0x0075: return "WM_BUTTON2UP";
3625 case 0x0076: return "WM_BUTTON2DBLCLK";
3626 case 0x0077: return "WM_BUTTON3DOWN";
3627 case 0x0078: return "WM_BUTTON3UP";
3628 case 0x0079: return "WM_BUTTON3DBLCLK";
3629 case 0x007D: return "WM_MOUSEMAP";
3630 case 0x007E: return "WM_VRNDISABLED";
3631 case 0x007F: return "WM_VRNENABLED";
3632 case 0x0410: return "WM_CHORD";
3633 case 0x0411: return "WM_BUTTON1MOTIONSTART";
3634 case 0x0412: return "WM_BUTTON1MOTIONEND";
3635 case 0x0413: return "WM_BUTTON1CLICK";
3636 case 0x0414: return "WM_BUTTON2MOTIONSTART";
3637 case 0x0415: return "WM_BUTTON2MOTIONEND";
3638 case 0x0416: return "WM_BUTTON2CLICK";
3639 case 0x0417: return "WM_BUTTON3MOTIONSTART";
3640 case 0x0418: return "WM_BUTTON3MOTIONEND";
3641 case 0x0419: return "WM_BUTTON3CLICK";
3642 case 0x0420: return "WM_BEGINDRAG";
3643 case 0x0421: return "WM_ENDDRAG";
3644 case 0x0422: return "WM_SINGLESELECT";
3645 case 0x0423: return "WM_OPEN";
3646 case 0x0424: return "WM_CONTEXTMENU";
3647 case 0x0425: return "WM_CONTEXTHELP";
3648 case 0x0426: return "WM_TEXTEDIT";
3649 case 0x0427: return "WM_BEGINSELECT";
3650 case 0x0228: return "WM_ENDSELECT";
3651 case 0x0429: return "WM_PICKUP";
3652 case 0x04C0: return "WM_PENFIRST";
3653 case 0x04FF: return "WM_PENLAST";
3654 case 0x0500: return "WM_MMPMFIRST";
3655 case 0x05FF: return "WM_MMPMLAST";
3656 case 0x0600: return "WM_STDDLGFIRST";
3657 case 0x06FF: return "WM_STDDLGLAST";
3658 case 0x0BD0: return "WM_BIDI_FIRST";
3659 case 0x0BFF: return "WM_BIDI_LAST";
3660 // keyboard input
3661 case 0x007A: return "WM_CHAR";
3662 case 0x007B: return "WM_VIOCHAR";
3663 // DDE messages
3664 case 0x00A0: return "WM_DDE_INITIATE";
3665 case 0x00A1: return "WM_DDE_REQUEST";
3666 case 0x00A2: return "WM_DDE_ACK";
3667 case 0x00A3: return "WM_DDE_DATA";
3668 case 0x00A4: return "WM_DDE_ADVISE";
3669 case 0x00A5: return "WM_DDE_UNADVISE";
3670 case 0x00A6: return "WM_DDE_POKE";
3671 case 0x00A7: return "WM_DDE_EXECUTE";
3672 case 0x00A8: return "WM_DDE_TERMINATE";
3673 case 0x00A9: return "WM_DDE_INITIATEACK";
3674 case 0x00AF: return "WM_DDE_LAST";
3675 // Buttons
3676 case 0x0120: return "BM_CLICK";
3677 case 0x0121: return "BM_QUERYCHECKINDEX";
3678 case 0x0122: return "BM_QUERYHILITE";
3679 case 0x0123: return "BM_SETHILITE";
3680 case 0x0124: return "BM_QUERYCHECK";
3681 case 0x0125: return "BM_SETCHECK";
3682 case 0x0126: return "BM_SETDEFAULT";
3683 case 0x0128: return "BM_AUTOSIZE";
3684 // Combo boxes
3685 case 0x029A: return "CBID_LIST";
3686 case 0x029B: return "CBID_EDIT";
3687 case 0x0170: return "CBM_SHOWLIST";
3688 case 0x0171: return "CBM_HILITE";
3689 case 0x0172: return "CBM_ISLISTSHOWING";
3690 // Edit fields
3691 case 0x0140: return "EM_QUERYCHANGED";
3692 case 0x0141: return "EM_QUERYSEL";
3693 case 0x0142: return "EM_SETSEL";
3694 case 0x0143: return "EM_SETTEXTLIMIT";
3695 case 0x0144: return "EM_CUT";
3696 case 0x0145: return "EM_COPY";
3697 case 0x0146: return "EM_CLEAR";
3698 case 0x0147: return "EM_PASTE";
3699 case 0x0148: return "EM_QUERYFIRSTCHAR";
3700 case 0x0149: return "EM_SETFIRSTCHAR";
3701 case 0x014A: return "EM_QUERYREADONLY";
3702 case 0x014B: return "EM_SETREADONLY";
3703 case 0x014C: return "EM_SETINSERTMODE";
3704 // Listboxes
3705 case 0x0160: return "LM_QUERYITEMCOUNT";
3706 case 0x0161: return "LM_INSERTITEM";
3707 case 0x0162: return "LM_SETOPENINDEX";
3708 case 0x0163: return "LM_DELETEITEM";
3709 case 0x0164: return "LM_SELECTITEM";
3710 case 0x0165: return "LM_QUERYSELECTION";
3711 case 0x0166: return "LM_SETITEMTEXT";
3712 case 0x0167: return "LM_QUERYITEMTEXTLENGTH";
3713 case 0x0168: return "LM_QUERYITEMTEXT";
3714 case 0x0169: return "LM_SETITEMHANDLE";
3715 case 0x016A: return "LM_QUERYITEMHANDLE";
3716 case 0x016B: return "LM_SEARCHSTRING";
3717 case 0x016C: return "LM_SETITEMHEIGHT";
3718 case 0x016D: return "LM_QUERYTOPINDEX";
3719 case 0x016E: return "LM_DELETEALL";
3720 case 0x016F: return "LM_INSERTMULITEMS";
3721 case 0x0660: return "LM_SETITEMWIDTH";
3722 // Menus
3723 case 0x0180: return "MM_INSERTITEM";
3724 case 0x0181: return "MM_DELETEITEM";
3725 case 0x0182: return "MM_QUERYITEM";
3726 case 0x0183: return "MM_SETITEM";
3727 case 0x0184: return "MM_QUERYITEMCOUNT";
3728 case 0x0185: return "MM_STARTMENUMODE";
3729 case 0x0186: return "MM_ENDMENUMODE";
3730 case 0x0188: return "MM_REMOVEITEM";
3731 case 0x0189: return "MM_SELECTITEM";
3732 case 0x018A: return "MM_QUERYSELITEMID";
3733 case 0x018B: return "MM_QUERYITEMTEXT";
3734 case 0x018C: return "MM_QUERYITEMTEXTLENGTH";
3735 case 0x018D: return "MM_SETITEMHANDLE";
3736 case 0x018E: return "MM_SETITEMTEXT";
3737 case 0x018F: return "MM_ITEMPOSITIONFROMID";
3738 case 0x0190: return "MM_ITEMIDFROMPOSITION";
3739 case 0x0191: return "MM_QUERYITEMATTR";
3740 case 0x0192: return "MM_SETITEMATTR";
3741 case 0x0193: return "MM_ISITEMVALID";
3742 case 0x0194: return "MM_QUERYITEMRECT";
3743 case 0x0431: return "MM_QUERYDEFAULTITEMID";
3744 case 0x0432: return "MM_SETDEFAULTITEMID";
3745 // Scrollbars
3746 case 0x01A0: return "SBM_SETSCROLLBAR";
3747 case 0x01A1: return "SBM_SETPOS";
3748 case 0x01A2: return "SBM_QUERYPOS";
3749 case 0x01A3: return "SBM_QUERYRANGE";
3750 case 0x01A6: return "SBM_SETTHUMBSIZE";
3751
3752 // Help messages
3753 case 0x0F00: return "WM_HELPBASE";
3754 case 0x0FFF: return "WM_HELPTOP";
3755 // Beginning of user defined messages
3756 case 0x1000: return "WM_USER";
3757
3758 // wxWindows user defined types
3759
3760 // listview
3761 // case 0x1000 + 0: return "LVM_GETBKCOLOR";
3762 case 0x1000 + 1: return "LVM_SETBKCOLOR";
3763 case 0x1000 + 2: return "LVM_GETIMAGELIST";
3764 case 0x1000 + 3: return "LVM_SETIMAGELIST";
3765 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
3766 case 0x1000 + 5: return "LVM_GETITEMA";
3767 case 0x1000 + 75: return "LVM_GETITEMW";
3768 case 0x1000 + 6: return "LVM_SETITEMA";
3769 case 0x1000 + 76: return "LVM_SETITEMW";
3770 case 0x1000 + 7: return "LVM_INSERTITEMA";
3771 case 0x1000 + 77: return "LVM_INSERTITEMW";
3772 case 0x1000 + 8: return "LVM_DELETEITEM";
3773 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
3774 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
3775 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
3776 case 0x1000 + 12: return "LVM_GETNEXTITEM";
3777 case 0x1000 + 13: return "LVM_FINDITEMA";
3778 case 0x1000 + 83: return "LVM_FINDITEMW";
3779 case 0x1000 + 14: return "LVM_GETITEMRECT";
3780 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
3781 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
3782 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
3783 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
3784 case 0x1000 + 18: return "LVM_HITTEST";
3785 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
3786 case 0x1000 + 20: return "LVM_SCROLL";
3787 case 0x1000 + 21: return "LVM_REDRAWITEMS";
3788 case 0x1000 + 22: return "LVM_ARRANGE";
3789 case 0x1000 + 23: return "LVM_EDITLABELA";
3790 case 0x1000 + 118: return "LVM_EDITLABELW";
3791 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
3792 case 0x1000 + 25: return "LVM_GETCOLUMNA";
3793 case 0x1000 + 95: return "LVM_GETCOLUMNW";
3794 case 0x1000 + 26: return "LVM_SETCOLUMNA";
3795 case 0x1000 + 96: return "LVM_SETCOLUMNW";
3796 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
3797 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
3798 case 0x1000 + 28: return "LVM_DELETECOLUMN";
3799 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
3800 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
3801 case 0x1000 + 31: return "LVM_GETHEADER";
3802 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
3803 case 0x1000 + 34: return "LVM_GETVIEWRECT";
3804 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
3805 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
3806 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
3807 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
3808 case 0x1000 + 39: return "LVM_GETTOPINDEX";
3809 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
3810 case 0x1000 + 41: return "LVM_GETORIGIN";
3811 case 0x1000 + 42: return "LVM_UPDATE";
3812 case 0x1000 + 43: return "LVM_SETITEMSTATE";
3813 case 0x1000 + 44: return "LVM_GETITEMSTATE";
3814 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
3815 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
3816 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
3817 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
3818 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
3819 case 0x1000 + 48: return "LVM_SORTITEMS";
3820 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
3821 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
3822 case 0x1000 + 51: return "LVM_GETITEMSPACING";
3823 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
3824 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
3825 case 0x1000 + 53: return "LVM_SETICONSPACING";
3826 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
3827 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
3828 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
3829 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
3830 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
3831 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
3832 case 0x1000 + 60: return "LVM_SETHOTITEM";
3833 case 0x1000 + 61: return "LVM_GETHOTITEM";
3834 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
3835 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
3836 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
3837 case 0x1000 + 65: return "LVM_SETWORKAREA";
3838
3839 // tree view
3840 case 0x1100 + 0: return "TVM_INSERTITEMA";
3841 case 0x1100 + 50: return "TVM_INSERTITEMW";
3842 case 0x1100 + 1: return "TVM_DELETEITEM";
3843 case 0x1100 + 2: return "TVM_EXPAND";
3844 case 0x1100 + 4: return "TVM_GETITEMRECT";
3845 case 0x1100 + 5: return "TVM_GETCOUNT";
3846 case 0x1100 + 6: return "TVM_GETINDENT";
3847 case 0x1100 + 7: return "TVM_SETINDENT";
3848 case 0x1100 + 8: return "TVM_GETIMAGELIST";
3849 case 0x1100 + 9: return "TVM_SETIMAGELIST";
3850 case 0x1100 + 10: return "TVM_GETNEXTITEM";
3851 case 0x1100 + 11: return "TVM_SELECTITEM";
3852 case 0x1100 + 12: return "TVM_GETITEMA";
3853 case 0x1100 + 62: return "TVM_GETITEMW";
3854 case 0x1100 + 13: return "TVM_SETITEMA";
3855 case 0x1100 + 63: return "TVM_SETITEMW";
3856 case 0x1100 + 14: return "TVM_EDITLABELA";
3857 case 0x1100 + 65: return "TVM_EDITLABELW";
3858 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
3859 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
3860 case 0x1100 + 17: return "TVM_HITTEST";
3861 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
3862 case 0x1100 + 19: return "TVM_SORTCHILDREN";
3863 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
3864 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
3865 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
3866 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
3867 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
3868 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
3869 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
3870
3871 // header
3872 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
3873 case 0x1200 + 1: return "HDM_INSERTITEMA";
3874 case 0x1200 + 10: return "HDM_INSERTITEMW";
3875 case 0x1200 + 2: return "HDM_DELETEITEM";
3876 case 0x1200 + 3: return "HDM_GETITEMA";
3877 case 0x1200 + 11: return "HDM_GETITEMW";
3878 case 0x1200 + 4: return "HDM_SETITEMA";
3879 case 0x1200 + 12: return "HDM_SETITEMW";
3880 case 0x1200 + 5: return "HDM_LAYOUT";
3881 case 0x1200 + 6: return "HDM_HITTEST";
3882 case 0x1200 + 7: return "HDM_GETITEMRECT";
3883 case 0x1200 + 8: return "HDM_SETIMAGELIST";
3884 case 0x1200 + 9: return "HDM_GETIMAGELIST";
3885 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
3886 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
3887 case 0x1200 + 17: return "HDM_GETORDERARRAY";
3888 case 0x1200 + 18: return "HDM_SETORDERARRAY";
3889 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
3890
3891 // tab control
3892 case 0x1300 + 2: return "TCM_GETIMAGELIST";
3893 case 0x1300 + 3: return "TCM_SETIMAGELIST";
3894 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
3895 case 0x1300 + 5: return "TCM_GETITEMA";
3896 case 0x1300 + 60: return "TCM_GETITEMW";
3897 case 0x1300 + 6: return "TCM_SETITEMA";
3898 case 0x1300 + 61: return "TCM_SETITEMW";
3899 case 0x1300 + 7: return "TCM_INSERTITEMA";
3900 case 0x1300 + 62: return "TCM_INSERTITEMW";
3901 case 0x1300 + 8: return "TCM_DELETEITEM";
3902 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
3903 case 0x1300 + 10: return "TCM_GETITEMRECT";
3904 case 0x1300 + 11: return "TCM_GETCURSEL";
3905 case 0x1300 + 12: return "TCM_SETCURSEL";
3906 case 0x1300 + 13: return "TCM_HITTEST";
3907 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
3908 case 0x1300 + 40: return "TCM_ADJUSTRECT";
3909 case 0x1300 + 41: return "TCM_SETITEMSIZE";
3910 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
3911 case 0x1300 + 43: return "TCM_SETPADDING";
3912 case 0x1300 + 44: return "TCM_GETROWCOUNT";
3913 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
3914 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
3915 case 0x1300 + 47: return "TCM_GETCURFOCUS";
3916 case 0x1300 + 48: return "TCM_SETCURFOCUS";
3917 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
3918 case 0x1300 + 50: return "TCM_DESELECTALL";
3919
3920 // toolbar
3921 case WM_USER+1000+1: return "TB_ENABLEBUTTON";
3922 case WM_USER+1000+2: return "TB_CHECKBUTTON";
3923 case WM_USER+1000+3: return "TB_PRESSBUTTON";
3924 case WM_USER+1000+4: return "TB_HIDEBUTTON";
3925 case WM_USER+1000+5: return "TB_INDETERMINATE";
3926 case WM_USER+1000+9: return "TB_ISBUTTONENABLED";
3927 case WM_USER+1000+10: return "TB_ISBUTTONCHECKED";
3928 case WM_USER+1000+11: return "TB_ISBUTTONPRESSED";
3929 case WM_USER+1000+12: return "TB_ISBUTTONHIDDEN";
3930 case WM_USER+1000+13: return "TB_ISBUTTONINDETERMINATE";
3931 case WM_USER+1000+17: return "TB_SETSTATE";
3932 case WM_USER+1000+18: return "TB_GETSTATE";
3933 case WM_USER+1000+19: return "TB_ADDBITMAP";
3934 case WM_USER+1000+20: return "TB_ADDBUTTONS";
3935 case WM_USER+1000+21: return "TB_INSERTBUTTON";
3936 case WM_USER+1000+22: return "TB_DELETEBUTTON";
3937 case WM_USER+1000+23: return "TB_GETBUTTON";
3938 case WM_USER+1000+24: return "TB_BUTTONCOUNT";
3939 case WM_USER+1000+25: return "TB_COMMANDTOINDEX";
3940 case WM_USER+1000+26: return "TB_SAVERESTOREA";
3941 case WM_USER+1000+76: return "TB_SAVERESTOREW";
3942 case WM_USER+1000+27: return "TB_CUSTOMIZE";
3943 case WM_USER+1000+28: return "TB_ADDSTRINGA";
3944 case WM_USER+1000+77: return "TB_ADDSTRINGW";
3945 case WM_USER+1000+29: return "TB_GETITEMRECT";
3946 case WM_USER+1000+30: return "TB_BUTTONSTRUCTSIZE";
3947 case WM_USER+1000+31: return "TB_SETBUTTONSIZE";
3948 case WM_USER+1000+32: return "TB_SETBITMAPSIZE";
3949 case WM_USER+1000+33: return "TB_AUTOSIZE";
3950 case WM_USER+1000+35: return "TB_GETTOOLTIPS";
3951 case WM_USER+1000+36: return "TB_SETTOOLTIPS";
3952 case WM_USER+1000+37: return "TB_SETPARENT";
3953 case WM_USER+1000+39: return "TB_SETROWS";
3954 case WM_USER+1000+40: return "TB_GETROWS";
3955 case WM_USER+1000+42: return "TB_SETCMDID";
3956 case WM_USER+1000+43: return "TB_CHANGEBITMAP";
3957 case WM_USER+1000+44: return "TB_GETBITMAP";
3958 case WM_USER+1000+45: return "TB_GETBUTTONTEXTA";
3959 case WM_USER+1000+75: return "TB_GETBUTTONTEXTW";
3960 case WM_USER+1000+46: return "TB_REPLACEBITMAP";
3961 case WM_USER+1000+47: return "TB_SETINDENT";
3962 case WM_USER+1000+48: return "TB_SETIMAGELIST";
3963 case WM_USER+1000+49: return "TB_GETIMAGELIST";
3964 case WM_USER+1000+50: return "TB_LOADIMAGES";
3965 case WM_USER+1000+51: return "TB_GETRECT";
3966 case WM_USER+1000+52: return "TB_SETHOTIMAGELIST";
3967 case WM_USER+1000+53: return "TB_GETHOTIMAGELIST";
3968 case WM_USER+1000+54: return "TB_SETDISABLEDIMAGELIST";
3969 case WM_USER+1000+55: return "TB_GETDISABLEDIMAGELIST";
3970 case WM_USER+1000+56: return "TB_SETSTYLE";
3971 case WM_USER+1000+57: return "TB_GETSTYLE";
3972 case WM_USER+1000+58: return "TB_GETBUTTONSIZE";
3973 case WM_USER+1000+59: return "TB_SETBUTTONWIDTH";
3974 case WM_USER+1000+60: return "TB_SETMAXTEXTROWS";
3975 case WM_USER+1000+61: return "TB_GETTEXTROWS";
3976 case WM_USER+1000+41: return "TB_GETBITMAPFLAGS";
3977
3978 default:
3979 static char s_szBuf[128];
3980 sprintf(s_szBuf, "<unknown message = %d>", nMessage);
3981 return s_szBuf;
3982 }
3983 return NULL;
3984 } // end of wxGetMessageName
3985
3986 #endif // __WXDEBUG__
3987
3988 static void TranslateKbdEventToMouse(
3989 wxWindow* pWin
3990 , int* pX
3991 , int* pY
3992 , ULONG* pFlags
3993 )
3994 {
3995 //
3996 // Construct the key mask
3997 ULONG& fwKeys = *pFlags;
3998
3999 fwKeys = VK_BUTTON2;
4000 if ((::WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x100) != 0)
4001 fwKeys |= VK_CTRL;
4002 if ((::WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x100) != 0)
4003 fwKeys |= VK_SHIFT;
4004
4005 //
4006 // Simulate right mouse button click
4007 //
4008 POINTL vPoint;
4009
4010 ::WinQueryMsgPos(vHabmain, &vPoint);
4011 *pX = vPoint.x;
4012 *pY = vPoint.y;
4013
4014 pWin->ScreenToClient(pX, pY);
4015 } // end of TranslateKbdEventToMouse
4016
4017 // Find the wxWindow at the current mouse position, returning the mouse
4018 // position.
4019 wxWindow* wxFindWindowAtPointer(
4020 wxPoint& rPt
4021 )
4022 {
4023 return wxFindWindowAtPoint(wxGetMousePosition());
4024 }
4025
4026 wxWindow* wxFindWindowAtPoint(
4027 const wxPoint& rPt
4028 )
4029 {
4030 POINTL vPt2;
4031
4032 vPt2.x = rPt.x;
4033 vPt2.y = rPt.y;
4034
4035 HWND hWndHit = ::WinWindowFromPoint(HWND_DESKTOP, &vPt2, FALSE);
4036 wxWindow* pWin = wxFindWinFromHandle((WXHWND)hWndHit) ;
4037 HWND hWnd = hWndHit;
4038
4039 //
4040 // Try to find a window with a wxWindow associated with it
4041 //
4042 while (!pWin && (hWnd != 0))
4043 {
4044 hWnd = ::WinQueryWindow(hWnd, QW_PARENT);
4045 pWin = wxFindWinFromHandle((WXHWND)hWnd) ;
4046 }
4047 return pWin;
4048 }
4049
4050 // Get the current mouse position.
4051 wxPoint wxGetMousePosition()
4052 {
4053 POINTL vPt;
4054
4055 ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
4056 return wxPoint(vPt.x, vPt.y);
4057 }
4058