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