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