Make scrolling work better (without constantly refreshing whole screen).
[wxWidgets.git] / src / os2 / window.cpp
1 // Name: windows.cpp
2 // Purpose: wxWindow
3 // Author: David Webster
4 // Modified by:
5 // Created: 10/12/99
6 // RCS-ID: $Id$
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 //
12 // For compilers that support precompilation, includes "wx.h".
13 //
14 #include "wx/wxprec.h"
15
16 #ifndef WX_PRECOMP
17 #define INCL_DOS
18 #define INCL_PM
19 #include <os2.h>
20 #include "wx/window.h"
21 #include "wx/accel.h"
22 #include "wx/setup.h"
23 #include "wx/menu.h"
24 #include "wx/dc.h"
25 #include "wx/dcclient.h"
26 #include "wx/utils.h"
27 #include "wx/app.h"
28 #include "wx/panel.h"
29 #include "wx/layout.h"
30 #include "wx/checkbox.h"
31 #include "wx/combobox.h"
32 #include "wx/dialog.h"
33 #include "wx/frame.h"
34 #include "wx/listbox.h"
35 #include "wx/button.h"
36 #include "wx/bmpbuttn.h"
37 #include "wx/msgdlg.h"
38 #include "wx/scrolwin.h"
39 #include "wx/radiobox.h"
40 #include "wx/radiobut.h"
41 #include "wx/slider.h"
42 #include "wx/statbox.h"
43 #include "wx/statusbr.h"
44 #include "wx/toolbar.h"
45 #include "wx/settings.h"
46 #include <stdio.h>
47 #endif
48
49 #if wxUSE_OWNER_DRAWN
50 #include "wx/ownerdrw.h"
51 #endif
52
53 #if wxUSE_DRAG_AND_DROP
54 #include "wx/dnd.h"
55 #endif
56
57 #include "wx/menuitem.h"
58 #include "wx/log.h"
59
60 #include "wx/os2/private.h"
61
62 #if wxUSE_TOOLTIPS
63 #include "wx/tooltip.h"
64 #endif
65
66 #if wxUSE_NOTEBOOK
67 #include "wx/notebook.h"
68 #endif
69
70 #if wxUSE_CARET
71 #include "wx/caret.h"
72 #endif // wxUSE_CARET
73
74 #include "wx/intl.h"
75 #include "wx/log.h"
76
77
78 #include "wx/textctrl.h"
79
80 #include <string.h>
81
82 //
83 // Place compiler, OS specific includes here
84 //
85
86 //
87 // Standard macros -- these are for OS/2 PM, but most GUI's have something similar
88 //
89 #ifndef GET_X_LPARAM
90 //
91 // SHORT1FROMMP -- LOWORD
92 //
93 #define GET_X_LPARAM(mp) ((unsigned short)(unsigned long)(mp))
94 //
95 // SHORT2FROMMP -- HIWORD
96 //
97 #define GET_Y_LPARAM(mp) ((unsigned short)(unsigned long)(mp >> 16))
98 #endif // GET_X_LPARAM
99
100 #ifndef CW_USEDEFAULT
101 # define CW_USEDEFAULT ((int)0x80000000)
102 #endif
103
104 #ifndef VK_OEM_1
105 #define VK_OEM_1 0xBA
106 #define VK_OEM_PLUS 0xBB
107 #define VK_OEM_COMMA 0xBC
108 #define VK_OEM_MINUS 0xBD
109 #define VK_OEM_PERIOD 0xBE
110 #define VK_OEM_2 0xBF
111 #define VK_OEM_3 0xC0
112 #define VK_OEM_4 0xDB
113 #define VK_OEM_5 0xDC
114 #define VK_OEM_6 0xDD
115 #define VK_OEM_7 0xDE
116 #endif
117
118 // ---------------------------------------------------------------------------
119 // global variables
120 // ---------------------------------------------------------------------------
121
122 //
123 // The last PM message we got (MT-UNSAFE)
124 //
125 QMSG s_currentMsg;
126
127 #if wxUSE_MENUS_NATIVE
128 wxMenu* wxCurrentPopupMenu = NULL;
129 #endif // wxUSE_MENUS_NATIVE
130
131 wxList* wxWinHandleList = NULL;
132
133 // ---------------------------------------------------------------------------
134 // private functions
135 // ---------------------------------------------------------------------------
136
137 //
138 // the window proc for all our windows; most gui's have something similar
139 //
140 MRESULT EXPENTRY wxWndProc( HWND hWnd
141 ,ULONG message
142 ,MPARAM mp1
143 ,MPARAM mp2
144 );
145
146 #ifdef __WXDEBUG__
147 const char *wxGetMessageName(int message);
148 #endif //__WXDEBUG__
149
150 wxWindowOS2* FindWindowForMouseEvent( wxWindow* pWin
151 ,short* pnX
152 ,short* pnY
153 );
154 void wxRemoveHandleAssociation(wxWindowOS2* pWin);
155 void wxAssociateWinWithHandle( HWND hWnd
156 ,wxWindowOS2* pWin
157 );
158 wxWindow* wxFindWinFromHandle(WXHWND hWnd);
159
160 //
161 // get the current state of SHIFT/CTRL keys
162 //
163 static inline bool IsShiftDown() { return (::WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000) != 0; }
164 static inline bool IsCtrlDown() { return (::WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000) != 0; }
165
166 static wxWindow* gpWinBeingCreated = NULL;
167
168 // ---------------------------------------------------------------------------
169 // event tables
170 // ---------------------------------------------------------------------------
171
172 // in wxUniv-OS/2 this class is abstract because it doesn't have DoPopupMenu()
173 // method
174 #ifdef __WXUNIVERSAL__
175 IMPLEMENT_ABSTRACT_CLASS(wxWindowOS2, wxWindowBase)
176 #else // __WXPM__
177 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
178 #endif // __WXUNIVERSAL__/__WXPM__
179
180 BEGIN_EVENT_TABLE(wxWindowOS2, wxWindowBase)
181 EVT_ERASE_BACKGROUND(wxWindowOS2::OnEraseBackground)
182 EVT_SYS_COLOUR_CHANGED(wxWindowOS2::OnSysColourChanged)
183 EVT_IDLE(wxWindowOS2::OnIdle)
184 EVT_SET_FOCUS(wxWindowOS2::OnSetFocus)
185 END_EVENT_TABLE()
186
187 // ===========================================================================
188 // implementation
189 // ===========================================================================
190
191 // ---------------------------------------------------------------------------
192 // wxWindow utility functions
193 // ---------------------------------------------------------------------------
194
195 //
196 // Find an item given the PM Window id
197 //
198 wxWindow* wxWindowOS2::FindItem(
199 long lId
200 ) const
201 {
202 #if wxUSE_CONTROLS
203 wxControl* pItem = wxDynamicCast(this, wxControl);
204
205 if (pItem)
206 {
207 //
208 // I it we or one of our "internal" children?
209 //
210 if (pItem->GetId() == lId
211 #ifndef __WXUNIVERSAL__
212 || (pItem->GetSubcontrols().Index(lId) != wxNOT_FOUND)
213 #endif
214 )
215 {
216 return pItem;
217 }
218 }
219 #endif // wxUSE_CONTROLS
220
221 wxWindowList::Node* pCurrent = GetChildren().GetFirst();
222
223 while (pCurrent)
224 {
225 wxWindow* pChildWin = pCurrent->GetData();
226 wxWindow* pWnd = pChildWin->FindItem(lId);
227
228 if (pWnd)
229 return pWnd;
230
231 pCurrent = pCurrent->GetNext();
232 }
233 return(NULL);
234 } // end of wxWindowOS2::FindItem
235
236 //
237 // Find an item given the PM Window handle
238 //
239 wxWindow* wxWindowOS2::FindItemByHWND(
240 WXHWND hWnd
241 , bool bControlOnly
242 ) const
243 {
244 wxWindowList::Node* pCurrent = GetChildren().GetFirst();
245
246 while (pCurrent)
247 {
248 wxWindow* pParent = pCurrent->GetData();
249
250 //
251 // Do a recursive search.
252 //
253 wxWindow* pWnd = pParent->FindItemByHWND(hWnd);
254
255 if (pWnd)
256 return(pWnd);
257
258 if (!bControlOnly
259 #if wxUSE_CONTROLS
260 || pParent->IsKindOf(CLASSINFO(wxControl))
261 #endif // wxUSE_CONTROLS
262 )
263 {
264 wxWindow* pItem = pCurrent->GetData();
265
266 if (pItem->GetHWND() == hWnd)
267 return(pItem);
268 else
269 {
270 if (pItem->ContainsHWND(hWnd))
271 return(pItem);
272 }
273 }
274 pCurrent = pCurrent->GetNext();
275 }
276 return(NULL);
277 } // end of wxWindowOS2::FindItemByHWND
278
279 //
280 // Default command handler
281 //
282 bool wxWindowOS2::OS2Command(
283 WXUINT WXUNUSED(uParam)
284 , WXWORD WXUNUSED(uId)
285 )
286 {
287 return(FALSE);
288 }
289
290 // ----------------------------------------------------------------------------
291 // constructors and such
292 // ----------------------------------------------------------------------------
293
294 void wxWindowOS2::Init()
295 {
296 //
297 // PM specific
298 //
299 m_bWinCaptured = FALSE;
300
301 m_fnOldWndProc = NULL;
302 m_bUseCtl3D = FALSE;
303 m_bMouseInWindow = FALSE;
304 m_bLastKeydownProcessed = FALSE;
305 m_pChildrenDisabled = NULL;
306
307 //
308 // wxWnd
309 //
310 m_hMenu = 0L;
311 m_hWnd = 0L;
312 m_hWndScrollBarHorz = 0L;
313 m_hWndScrollBarVert = 0L;
314
315 memset(&m_vWinSwp, '\0', sizeof (SWP));
316
317 //
318 // Pass WM_GETDLGCODE to DefWindowProc()
319 //
320 m_lDlgCode = 0;
321
322 m_nXThumbSize = 0;
323 m_nYThumbSize = 0;
324 m_bBackgroundTransparent = FALSE;
325
326 //
327 // As all windows are created with WS_VISIBLE style...
328 //
329 m_isShown = TRUE;
330
331 #if wxUSE_MOUSEEVENT_HACK
332 m_lLastMouseX =
333 m_lLastMouseY = -1;
334 m_nLastMouseEvent = -1;
335 #endif // wxUSE_MOUSEEVENT_HACK
336 } // wxWindowOS2::Init
337
338 //
339 // Destructor
340 //
341 wxWindowOS2::~wxWindowOS2()
342 {
343 m_isBeingDeleted = TRUE;
344
345 for (wxWindow* pWin = GetParent(); pWin; pWin = pWin->GetParent())
346 {
347 wxTopLevelWindow* pFrame = wxDynamicCast(pWin, wxTopLevelWindow);
348
349 if (pFrame)
350 {
351 if (pFrame->GetLastFocus() == this)
352 pFrame->SetLastFocus(NULL);
353 }
354 }
355
356 DestroyChildren();
357
358 if (m_hWnd)
359 {
360 if(!::WinDestroyWindow(GetHWND()))
361 wxLogLastError(wxT("DestroyWindow"));
362 //
363 // remove hWnd <-> wxWindow association
364 //
365 wxRemoveHandleAssociation(this);
366 }
367 delete m_pChildrenDisabled;
368 } // end of wxWindowOS2::~wxWindowOS2
369
370 // real construction (Init() must have been called before!)
371 bool wxWindowOS2::Create(
372 wxWindow* pParent
373 , wxWindowID vId
374 , const wxPoint& rPos
375 , const wxSize& rSize
376 , long lStyle
377 , const wxString& rName
378 )
379 {
380 HWND hParent = NULLHANDLE;
381 ULONG ulCreateFlags = 0;
382 WXDWORD dwExStyle = 0;
383
384 wxCHECK_MSG(pParent, FALSE, wxT("can't create wxWindow without parent"));
385
386 #if wxUSE_STATBOX
387 //
388 // wxGTK doesn't allow to create controls with static box as the parent so
389 // this will result in a crash when the program is ported to wxGTK - warn
390 // about it
391 //
392 // the correct solution is to create the controls as siblings of the
393 // static box
394 //
395 wxASSERT_MSG( !wxDynamicCast(pParent, wxStaticBox),
396 _T("wxStaticBox can't be used as a window parent!") );
397 #endif // wxUSE_STATBOX
398
399 if ( !CreateBase( pParent
400 ,vId
401 ,rPos
402 ,rSize
403 ,lStyle
404 ,wxDefaultValidator
405 ,rName
406 ))
407 return(FALSE);
408
409 if (pParent)
410 {
411 pParent->AddChild(this);
412 hParent = GetWinHwnd(pParent);
413
414 if ( pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow)) ||
415 pParent->IsKindOf(CLASSINFO(wxScrolledWindow))
416 )
417 ulCreateFlags |= WS_CLIPSIBLINGS;
418 }
419
420 //
421 // Most wxSTYLES are really PM Class specific styles and will be
422 // set in those class create procs. PM's basic windows styles are
423 // very limited.
424 //
425 ulCreateFlags |= OS2GetCreateWindowFlags(&dwExStyle);
426
427
428 #ifdef __WXUNIVERSAL__
429 // no 3d effects, we draw them ourselves
430 WXDWORD exStyle = 0;
431 #endif // !wxUniversal
432 if (lStyle & wxPOPUP_WINDOW)
433 {
434 ulCreateFlags &= ~WS_VISIBLE;
435 m_isShown = FALSE;
436 }
437 else
438 {
439 ulCreateFlags |= WS_VISIBLE;
440 }
441
442 //
443 // Generic OS/2 Windows have no Control Data but other classes
444 // that call OS2Create may have some.
445 //
446 return(OS2Create( (PSZ)wxCanvasClassName
447 ,rName.c_str()
448 ,ulCreateFlags
449 ,rPos
450 ,rSize
451 ,NULL // Control Data
452 ,dwExStyle
453 ,TRUE // Child
454 ));
455 } // end of wxWindowOS2::Create
456
457 // ---------------------------------------------------------------------------
458 // basic operations
459 // ---------------------------------------------------------------------------
460
461 void wxWindowOS2::SetFocus()
462 {
463 HWND hWnd = GetHwnd();
464 wxCHECK_RET( hWnd, _T("can't set focus to invalid window") );
465
466 if (hWnd)
467 ::WinSetFocus(HWND_DESKTOP, hWnd);
468 } // end of wxWindowOS2::SetFocus
469
470 void wxWindowOS2::SetFocusFromKbd()
471 {
472 //
473 // Nothing else to do under OS/2
474 //
475 wxWindowBase::SetFocusFromKbd();
476 } // end of wxWindowOS2::SetFocus
477
478 wxWindow* wxWindowBase::FindFocus()
479 {
480 HWND hWnd = ::WinQueryFocus(HWND_DESKTOP);
481
482 if (hWnd)
483 {
484 return wxFindWinFromHandle((WXHWND)hWnd);
485 }
486 return NULL;
487 } // wxWindowBase::FindFocus
488
489 bool wxWindowOS2::Enable(
490 bool bEnable
491 )
492 {
493 if (!wxWindowBase::Enable(bEnable))
494 return(FALSE);
495
496 HWND hWnd = GetHwnd();
497
498 if ( hWnd )
499 ::WinEnableWindow(hWnd, (BOOL)bEnable);
500
501 //
502 // The logic below doesn't apply to the top level windows -- otherwise
503 // showing a modal dialog would result in total greying out (and ungreying
504 // out later) of everything which would be really ugly
505 //
506 if (IsTopLevel())
507 return TRUE;
508
509 wxWindowList::Node* pNode = GetChildren().GetFirst();
510
511 while (pNode)
512 {
513 wxWindow* pChild = pNode->GetData();
514
515 if (bEnable)
516 {
517 //
518 // Enable the child back unless it had been disabled before us
519 //
520 if (!m_pChildrenDisabled || !m_pChildrenDisabled->Find(pChild))
521 pChild->Enable();
522 }
523 else // we're being disabled
524 {
525 if (pChild->IsEnabled())
526 {
527 //
528 // Disable it as children shouldn't stay enabled while the
529 // parent is not
530 //
531 pChild->Disable();
532 }
533 else // child already disabled, remember it
534 {
535 //
536 // Have we created the list of disabled children already?
537 //
538 if (!m_pChildrenDisabled)
539 m_pChildrenDisabled = new wxWindowList;
540 m_pChildrenDisabled->Append(pChild);
541 }
542 }
543 pNode = pNode->GetNext();
544 }
545 if (bEnable && m_pChildrenDisabled)
546 {
547 //
548 // We don't need this list any more, don't keep unused memory
549 //
550 delete m_pChildrenDisabled;
551 m_pChildrenDisabled = NULL;
552 }
553 return TRUE;
554 } // end of wxWindowOS2::Enable
555
556 bool wxWindowOS2::Show(
557 bool bShow
558 )
559 {
560 if (!wxWindowBase::Show(bShow))
561 return(FALSE);
562
563 HWND hWnd = GetHwnd();
564
565 ::WinShowWindow(hWnd, bShow);
566
567 if (bShow)
568 {
569 ::WinSetWindowPos(hWnd, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE | SWP_ZORDER);
570 }
571 return TRUE;
572 } // end of wxWindowOS2::Show
573
574 void wxWindowOS2::Raise()
575 {
576 ::WinSetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_ACTIVATE);
577 } // end of wxWindowOS2::Raise
578
579 void wxWindowOS2::Lower()
580 {
581 ::WinSetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_ZORDER | SWP_DEACTIVATE);
582 } // end of wxWindowOS2::Lower
583
584 void wxWindowOS2::SetTitle(
585 const wxString& rTitle
586 )
587 {
588 ::WinSetWindowText(GetHwnd(), rTitle.c_str());
589 } // end of wxWindowOS2::SetTitle
590
591 wxString wxWindowOS2::GetTitle() const
592 {
593 return wxGetWindowText(GetHWND());
594 } // end of wxWindowOS2::GetTitle
595
596 void wxWindowOS2::DoCaptureMouse()
597 {
598 HWND hWnd = GetHwnd();
599
600 if (hWnd && !m_bWinCaptured)
601 {
602 ::WinSetCapture(HWND_DESKTOP, hWnd);
603 m_bWinCaptured = TRUE;
604 }
605 } // end of wxWindowOS2::GetTitle
606
607 void wxWindowOS2::DoReleaseMouse()
608 {
609 if (m_bWinCaptured)
610 {
611 ::WinSetCapture(HWND_DESKTOP, NULLHANDLE);
612 m_bWinCaptured = FALSE;
613 }
614 } // end of wxWindowOS2::ReleaseMouse
615
616 /* static */ wxWindow* wxWindowBase::GetCapture()
617 {
618 HWND hwnd = ::WinQueryCapture(HWND_DESKTOP);
619 return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : (wxWindow *)NULL;
620 } // end of wxWindowBase::GetCapture
621
622 bool wxWindowOS2::SetFont(
623 const wxFont& rFont
624 )
625 {
626 if (!wxWindowBase::SetFont(rFont))
627 {
628 // nothing to do
629 return(FALSE);
630 }
631
632 HWND hWnd = GetHwnd();
633
634 wxOS2SetFont( hWnd
635 ,rFont
636 );
637 return(TRUE);
638 } // end of wxWindowOS2::SetFont
639
640 bool wxWindowOS2::SetCursor(
641 const wxCursor& rCursor
642 ) // check if base implementation is OK
643 {
644 if ( !wxWindowBase::SetCursor(rCursor))
645 {
646 // no change
647 return FALSE;
648 }
649
650 if ( m_cursor.Ok() ) {
651 HWND hWnd = GetHwnd();
652 POINTL vPoint;
653 RECTL vRect;
654
655 ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
656 ::WinQueryWindowRect(hWnd, &vRect);
657
658 if (::WinPtInRect(vHabmain, &vRect, &vPoint) && !wxIsBusy())
659 {
660 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)m_cursor.GetHCURSOR());
661 }
662 }
663 return TRUE;
664 } // end of wxWindowOS2::SetCursor
665
666 void wxWindowOS2::WarpPointer(
667 int nXPos
668 , int nYPos
669 )
670 {
671 int nX = nXPos;
672 int nY = nYPos;
673 RECTL vRect;
674
675 ::WinQueryWindowRect(GetHwnd(), &vRect);
676 nX += vRect.xLeft;
677 nY += vRect.yBottom;
678
679 ::WinSetPointerPos(HWND_DESKTOP, (LONG)nX, (LONG)(nY));
680 } // end of wxWindowOS2::WarpPointer
681
682
683 // ---------------------------------------------------------------------------
684 // scrolling stuff
685 // ---------------------------------------------------------------------------
686
687 int wxWindowOS2::GetScrollPos(
688 int nOrient
689 ) const
690 {
691 if (nOrient == wxHORIZONTAL)
692 return((int)::WinSendMsg(m_hWndScrollBarHorz, SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL));
693 else
694 return((int)::WinSendMsg(m_hWndScrollBarVert, SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL));
695 } // end of wxWindowOS2::GetScrollPos
696
697 int wxWindowOS2::GetScrollRange(
698 int nOrient
699 ) const
700 {
701 MRESULT mr;
702
703 if (nOrient == wxHORIZONTAL)
704 mr = ::WinSendMsg(m_hWndScrollBarHorz, SBM_QUERYRANGE, (MPARAM)NULL, (MPARAM)NULL);
705 else
706 mr = ::WinSendMsg(m_hWndScrollBarVert, SBM_QUERYRANGE, (MPARAM)NULL, (MPARAM)NULL);
707 return((int)SHORT2FROMMR(mr));
708 } // end of wxWindowOS2::GetScrollRange
709
710 int wxWindowOS2::GetScrollThumb(
711 int nOrient
712 ) const
713 {
714 if (nOrient == wxHORIZONTAL )
715 return m_nXThumbSize;
716 else
717 return m_nYThumbSize;
718 } // end of wxWindowOS2::GetScrollThumb
719
720 void wxWindowOS2::SetScrollPos(
721 int nOrient
722 , int nPos
723 , bool WXUNUSED(bRefresh)
724 )
725 {
726 if (nOrient == wxHORIZONTAL )
727 ::WinSendMsg(m_hWndScrollBarHorz, SBM_SETPOS, (MPARAM)nPos, (MPARAM)NULL);
728 else
729 ::WinSendMsg(m_hWndScrollBarVert, SBM_SETPOS, (MPARAM)nPos, (MPARAM)NULL);
730 } // end of wxWindowOS2::SetScrollPos
731
732 void wxWindowOS2::SetScrollbar(
733 int nOrient
734 , int nPos
735 , int nThumbVisible
736 , int nRange
737 , bool WXUNUSED(bRefresh)
738 )
739 {
740 HWND hWnd = GetHwnd();
741 int nOldRange = nRange - nThumbVisible;
742 int nRange1 = nOldRange;
743 int nPageSize = nThumbVisible;
744
745 SBCDATA vInfo;
746 ULONG ulStyle = WS_VISIBLE | WS_SYNCPAINT;
747 SWP vSwp;
748 SWP vSwpOwner;
749 HWND hWndParent;
750 HWND hWndClient;
751 wxWindow* pParent = GetParent();
752
753 if (pParent && pParent->IsKindOf(CLASSINFO(wxFrame)))
754 {
755 wxFrame* pFrame;
756
757 pFrame = wxDynamicCast(pParent, wxFrame);
758 hWndParent = pFrame->GetFrame();
759 hWndClient = GetHwndOf(pParent);
760 }
761 else
762 {
763 if (pParent)
764 hWndParent = GetHwndOf(pParent);
765 else
766 hWndParent = GetHwnd();
767 hWndClient = hWndParent;
768 }
769 ::WinQueryWindowPos(hWndClient, &vSwp);
770 ::WinQueryWindowPos(hWnd, &vSwpOwner);
771
772 if (nPageSize > 1 && nRange > 0)
773 {
774 nRange1 += (nPageSize - 1);
775 }
776
777 vInfo.cb = sizeof(SBCDATA);
778 vInfo.posFirst = 0;
779 vInfo.posLast = (SHORT)nRange1;
780 vInfo.posThumb = nPos;
781
782 if (nOrient == wxHORIZONTAL )
783 {
784 ulStyle |= SBS_HORZ;
785 if (m_hWndScrollBarHorz == 0L)
786 {
787 //
788 // Since the scrollbars are usually created before the owner is
789 // sized either via an OnSize event directly or via sizers or
790 // layout constraints, we will initially just use the coords of
791 // the parent window (this is usually a frame client window). But
792 // the bars themselves, are children of the parent frame (i.e
793 // siblings of the frame client. The owner, however is the actual
794 // window being scrolled (or at least the one responsible for
795 // handling the scroll events). The owner will be resized later,
796 // as it is usually a child of a top level window, and when that
797 // is done its scrollbars will be resized and repositioned as well.
798 //
799 m_hWndScrollBarHorz = ::WinCreateWindow( hWndParent
800 ,WC_SCROLLBAR
801 ,(PSZ)NULL
802 ,ulStyle
803 ,vSwp.x
804 ,vSwp.y
805 ,vSwp.cx - 20
806 ,20
807 ,hWnd
808 ,HWND_TOP
809 ,60000
810 ,&vInfo
811 ,NULL
812 );
813 }
814 else
815 {
816 //
817 // The owner (the scrolled window) is a child of the Frame's
818 // client window, usually. The scrollbars are children of the
819 // frame, itself, and thus are positioned relative to the frame's
820 // origin, not the frame's client window origin.
821 // The starting x position is the same as the starting x position
822 // of the owner, but in terms of the parent frame.
823 // The starting y position is 20 pels below the origin of the
824 // owner in terms of the parent frame.
825 // The horz bar is the same width as the owner and 20 pels high.
826 //
827 if (nRange1 >= nThumbVisible)
828 {
829 ::WinSetWindowPos( m_hWndScrollBarHorz
830 ,HWND_TOP
831 ,vSwp.x + vSwpOwner.x
832 ,(vSwp.y + vSwpOwner.y) - 20
833 ,vSwpOwner.cx
834 ,20
835 ,SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER
836 );
837 ::WinSendMsg( m_hWndScrollBarHorz
838 ,SBM_SETSCROLLBAR
839 ,(MPARAM)nPos
840 ,MPFROM2SHORT(0, (SHORT)nRange1)
841 );
842 ::WinSendMsg( m_hWndScrollBarHorz
843 ,SBM_SETTHUMBSIZE
844 ,MPFROM2SHORT( (SHORT)nThumbVisible
845 ,(SHORT)nRange1
846 )
847 ,(MPARAM)0
848 );
849 }
850 else
851 ::WinShowWindow(m_hWndScrollBarHorz, FALSE);
852 }
853 }
854 else
855 {
856 ulStyle |= SBS_VERT;
857 if (m_hWndScrollBarVert == 0L)
858 {
859 //
860 // Since the scrollbars are usually created before the owner is
861 // sized either via an OnSize event directly or via sizers or
862 // layout constraints, we will initially just use the coords of
863 // the parent window (this is usually a frame client window). But
864 // the bars themselves, are children of the parent frame (i.e
865 // siblings of the frame client. The owner, however is the actual
866 // window being scrolled (or at least the one responsible for
867 // handling the scroll events). The owner will be resized later,
868 // as it is usually a child of a top level window, and when that
869 // is done its scrollbars will be resized and repositioned as well.
870 //
871 m_hWndScrollBarVert = ::WinCreateWindow( hWndParent
872 ,WC_SCROLLBAR
873 ,(PSZ)NULL
874 ,ulStyle
875 ,vSwp.x + vSwp.cx - 20
876 ,vSwp.y + 20
877 ,20
878 ,vSwp.cy - 20
879 ,hWnd
880 ,HWND_TOP
881 ,60001
882 ,&vInfo
883 ,NULL
884 );
885 }
886 else
887 {
888 //
889 // The owner (the scrolled window) is a child of the Frame's
890 // client window, usually. The scrollbars are children of the
891 // frame, itself and thus are positioned relative to the frame's
892 // origin, not the frame's client window's origin.
893 // Thus, the x position will be frame client's x (usually a few
894 // pels inside the parent frame, plus the width of the owner.
895 // Since we may be using sizers or layout constraints for multiple
896 // child scrolled windows, the y position will be the frame client's
897 // y pos plus the scrolled windows y position, yielding the y
898 // position of the scrollbar relative to the parent frame (the vert
899 // scrollbar is on the right and starts at the bottom of the
900 // owner window).
901 // It is 20 pels wide and the same height as the owner.
902 //
903 if (nRange1 >= nThumbVisible)
904 {
905 ::WinSetWindowPos( m_hWndScrollBarVert
906 ,HWND_TOP
907 ,vSwp.x + vSwpOwner.x + vSwpOwner.cx
908 ,vSwp.y + vSwpOwner.y
909 ,20
910 ,vSwpOwner.cy
911 ,SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW
912 );
913 ::WinSendMsg( m_hWndScrollBarVert
914 ,SBM_SETSCROLLBAR
915 ,(MPARAM)nPos
916 ,MPFROM2SHORT(0, (SHORT)nRange1)
917 );
918 ::WinSendMsg( m_hWndScrollBarVert
919 ,SBM_SETTHUMBSIZE
920 ,MPFROM2SHORT( (SHORT)nThumbVisible
921 ,(SHORT)nRange1
922 )
923 ,(MPARAM)0
924 );
925 }
926 else
927 ::WinShowWindow(m_hWndScrollBarVert, FALSE);
928 }
929 m_nYThumbSize = nThumbVisible;
930 }
931 } // end of wxWindowOS2::SetScrollbar
932
933 void wxWindowOS2::ScrollWindow(
934 int nDx
935 , int nDy
936 , const wxRect* pRect
937 )
938 {
939 RECTL vRect;
940
941 ::WinQueryWindowRect(GetHwnd(), &vRect);
942 int height = vRect.yTop;
943 if (pRect)
944 {
945 vRect.xLeft = pRect->x;
946 vRect.yTop = height - pRect->y;
947 vRect.xRight = pRect->x + pRect->width;
948 vRect.yBottom = vRect.yTop - pRect->height;
949 }
950 nDy *= -1; // flip the sign of Dy as OS/2 is opposite Windows.
951 HPS hPs;
952 HRGN vUpdateRegion;
953 hPs = ::WinGetPS(GetHwnd());
954 vUpdateRegion = ::GpiCreateRegion(hPs, 0, NULL);
955 ::WinScrollWindow( GetHwnd()
956 ,(LONG)nDx
957 ,(LONG)nDy
958 ,&vRect
959 ,&vRect
960 ,vUpdateRegion
961 ,NULL
962 ,SW_SCROLLCHILDREN //| SW_INVALIDATERGN
963 );
964 RGNRECT vRgnData;
965 PRECTL pUpdateRects = NULL;
966 vRgnData.ulDirection = RECTDIR_LFRT_TOPBOT;
967 if (::GpiQueryRegionRects( hPs // Pres space
968 ,vUpdateRegion // Handle of region to query
969 ,NULL // Return all RECTs
970 ,&vRgnData // Will contain number or RECTs in region
971 ,NULL // NULL to return number of RECTs
972 ))
973 {
974 pUpdateRects = new RECTL[vRgnData.crcReturned];
975 vRgnData.crc = vRgnData.crcReturned;
976 vRgnData.ircStart = 1;
977 if (::GpiQueryRegionRects( hPs // Pres space of source
978 ,vUpdateRegion // Handle of source region
979 ,NULL // Return all RECTs
980 ,&vRgnData // Operations set to return rects
981 ,pUpdateRects // Will contain the actual RECTS
982 ))
983 {
984 for(size_t i = 0; i < vRgnData.crc; i++)
985 {
986 wxRect UpdateRect;
987 UpdateRect.x = pUpdateRects[i].xLeft;
988 UpdateRect.y = height - pUpdateRects[i].yTop;
989 UpdateRect.width = pUpdateRects[i].xRight - pUpdateRects[i].xLeft;
990 UpdateRect.height = pUpdateRects[i].yTop - pUpdateRects[i].yBottom;
991 Refresh(FALSE, &UpdateRect);
992 }
993 delete [] pUpdateRects;
994 }
995 }
996 } // end of wxWindowOS2::ScrollWindow
997
998 // ---------------------------------------------------------------------------
999 // subclassing
1000 // ---------------------------------------------------------------------------
1001
1002 void wxWindowOS2::SubclassWin(
1003 WXHWND hWnd
1004 )
1005 {
1006 HWND hwnd = (HWND)hWnd;
1007
1008 wxCHECK_RET(::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in SubclassWin") );
1009 wxAssociateWinWithHandle( hWnd
1010 ,(wxWindow*)this
1011 );
1012 if (!wxCheckWindowWndProc( hWnd
1013 ,(WXFARPROC)wxWndProc
1014 ))
1015 {
1016 m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(hwnd, (PFNWP)wxWndProc);
1017 }
1018 else
1019 {
1020 m_fnOldWndProc = (WXFARPROC)NULL;
1021 }
1022 } // end of wxWindowOS2::SubclassWin
1023
1024 void wxWindowOS2::UnsubclassWin()
1025 {
1026 //
1027 // Restore old Window proc
1028 //
1029 HWND hwnd = GetHWND();
1030
1031 if (m_hWnd)
1032 {
1033 wxCHECK_RET( ::WinIsWindow(vHabmain, hwnd), wxT("invalid HWND in UnsubclassWin") );
1034
1035 PFNWP fnProc = (PFNWP)::WinQueryWindowPtr(hwnd, QWP_PFNWP);
1036
1037 if ( (m_fnOldWndProc != 0) && (fnProc != (PFNWP) m_fnOldWndProc))
1038 {
1039 WinSubclassWindow(hwnd, (PFNWP)m_fnOldWndProc);
1040 m_fnOldWndProc = 0;
1041 }
1042 }
1043 } // end of wxWindowOS2::UnsubclassWin
1044
1045 bool wxCheckWindowWndProc(
1046 WXHWND hWnd
1047 , WXFARPROC fnWndProc
1048 )
1049 {
1050 static char zBuffer[512];
1051 CLASSINFO vCls;
1052
1053 ::WinQueryClassName((HWND)hWnd, (LONG)512, (PCH)zBuffer);
1054 ::WinQueryClassInfo(wxGetInstance(), (PSZ)zBuffer, &vCls);
1055 return(fnWndProc == (WXFARPROC)vCls.pfnWindowProc);
1056 } // end of WinGuiBase_CheckWindowWndProc
1057
1058 void wxWindowOS2::SetWindowStyleFlag(
1059 long lFlags
1060 )
1061 {
1062 long lFlagsOld = GetWindowStyleFlag();
1063
1064 if (lFlags == lFlagsOld)
1065 return;
1066
1067 //
1068 // Update the internal variable
1069 //
1070 wxWindowBase::SetWindowStyleFlag(lFlags);
1071
1072 //
1073 // Now update the Windows style as well if needed - and if the window had
1074 // been already created
1075 //
1076 if (!GetHwnd())
1077 return;
1078
1079 WXDWORD dwExstyle;
1080 WXDWORD dwExstyleOld;
1081 long lStyle = OS2GetStyle( lFlags
1082 ,&dwExstyle
1083 );
1084 long lStyleOld = OS2GetStyle( lFlagsOld
1085 ,&dwExstyleOld
1086 );
1087
1088 if (lStyle != lStyleOld)
1089 {
1090 //
1091 // Some flags (e.g. WS_VISIBLE or WS_DISABLED) should not be changed by
1092 // this function so instead of simply setting the style to the new
1093 // value we clear the bits which were set in styleOld but are set in
1094 // the new one and set the ones which were not set before
1095 //
1096 long lStyleReal = ::WinQueryWindowULong(GetHwnd(), QWL_STYLE);
1097
1098 lStyleReal &= ~lStyleOld;
1099 lStyleReal |= lStyle;
1100
1101 ::WinSetWindowULong(GetHwnd(), QWL_STYLE, lStyleReal);
1102 }
1103 } // end of wxWindowOS2::SetWindowStyleFlag
1104
1105 WXDWORD wxWindowOS2::OS2GetStyle(
1106 long lFlags
1107 , WXDWORD* pdwExstyle
1108 ) const
1109 {
1110 WXDWORD dwStyle = 0L;
1111
1112 if (lFlags & wxCLIP_CHILDREN )
1113 dwStyle |= WS_CLIPCHILDREN;
1114
1115 if (lFlags & wxCLIP_SIBLINGS )
1116 dwStyle |= WS_CLIPSIBLINGS;
1117
1118 return dwStyle;
1119 } // end of wxWindowMSW::MSWGetStyle
1120
1121 //
1122 // Make a Windows extended style from the given wxWidgets window style
1123 //
1124 WXDWORD wxWindowOS2::MakeExtendedStyle(
1125 long lStyle
1126 , bool bEliminateBorders
1127 )
1128 {
1129 //
1130 // Simply fill out with wxWindow extended styles. We'll conjure
1131 // something up in OS2Create and all window redrawing pieces later
1132 //
1133 WXDWORD dwStyle = 0;
1134
1135 if (lStyle & wxTRANSPARENT_WINDOW )
1136 dwStyle |= wxTRANSPARENT_WINDOW;
1137
1138 if (!bEliminateBorders)
1139 {
1140 if (lStyle & wxSUNKEN_BORDER)
1141 dwStyle |= wxSUNKEN_BORDER;
1142 if (lStyle & wxDOUBLE_BORDER)
1143 dwStyle |= wxDOUBLE_BORDER;
1144 if (lStyle & wxRAISED_BORDER )
1145 dwStyle |= wxRAISED_BORDER;
1146 if (lStyle & wxSTATIC_BORDER)
1147 dwStyle |= wxSTATIC_BORDER;
1148 }
1149 return dwStyle;
1150 } // end of wxWindowOS2::MakeExtendedStyle
1151
1152 //
1153 // Setup background and foreground colours correctly
1154 //
1155 void wxWindowOS2::SetupColours()
1156 {
1157 if ( GetParent() )
1158 SetBackgroundColour(GetParent()->GetBackgroundColour());
1159 } // end of wxWindowOS2::SetupColours
1160
1161 void wxWindowOS2::OnIdle(
1162 wxIdleEvent& WXUNUSED(rEvent)
1163 )
1164 {
1165 //
1166 // Check if we need to send a LEAVE event
1167 //
1168 if (m_bMouseInWindow)
1169 {
1170 POINTL vPoint;
1171
1172 ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
1173 if (::WinWindowFromPoint(HWND_DESKTOP, &vPoint, FALSE) != (HWND)GetHwnd())
1174 {
1175 //
1176 // Generate a LEAVE event
1177 //
1178 m_bMouseInWindow = FALSE;
1179
1180 //
1181 // Unfortunately the mouse button and keyboard state may have changed
1182 // by the time the OnIdle function is called, so 'state' may be
1183 // meaningless.
1184 //
1185 int nState = 0;
1186
1187 if (IsShiftDown())
1188 nState |= KC_SHIFT;
1189 if (IsCtrlDown())
1190 nState |= KC_CTRL;
1191
1192 wxMouseEvent rEvent(wxEVT_LEAVE_WINDOW);
1193
1194 InitMouseEvent( rEvent
1195 ,vPoint.x
1196 ,vPoint.y
1197 ,nState
1198 );
1199 (void)GetEventHandler()->ProcessEvent(rEvent);
1200 }
1201 }
1202 if (wxUpdateUIEvent::CanUpdate(this))
1203 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
1204 } // end of wxWindowOS2::OnIdle
1205
1206 //
1207 // Set this window to be the child of 'parent'.
1208 //
1209 bool wxWindowOS2::Reparent(
1210 wxWindow* pParent
1211 )
1212 {
1213 if (!wxWindowBase::Reparent(pParent))
1214 return FALSE;
1215
1216 HWND hWndChild = GetHwnd();
1217 HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0;
1218
1219 ::WinSetParent(hWndChild, hWndParent, TRUE);
1220 return TRUE;
1221 } // end of wxWindowOS2::Reparent
1222
1223 void wxWindowOS2::Update()
1224 {
1225 ::WinUpdateWindow(GetHwnd());
1226 } // end of wxWindowOS2::Update
1227
1228 void wxWindowOS2::Freeze()
1229 {
1230 ::WinSendMsg(GetHwnd(), WM_VRNDISABLED, (MPARAM)0, (MPARAM)0);
1231 } // end of wxWindowOS2::Freeze
1232
1233 void wxWindowOS2::Thaw()
1234 {
1235 ::WinSendMsg(GetHwnd(), WM_VRNENABLED, (MPARAM)TRUE, (MPARAM)0);
1236
1237 //
1238 // We need to refresh everything or otherwise he invalidated area is not
1239 // repainted.
1240 //
1241 Refresh();
1242 } // end of wxWindowOS2::Thaw
1243
1244 void wxWindowOS2::Refresh(
1245 bool bEraseBack
1246 , const wxRect* pRect
1247 )
1248 {
1249 HWND hWnd = GetHwnd();
1250
1251 if (hWnd)
1252 {
1253 if (pRect)
1254 {
1255 RECTL vOs2Rect;
1256 int height;
1257
1258 ::WinQueryWindowRect(GetHwnd(), &vOs2Rect);
1259 height = vOs2Rect.yTop;
1260 vOs2Rect.xLeft = pRect->x;
1261 vOs2Rect.yTop = height - pRect->y;
1262 vOs2Rect.xRight = pRect->x + pRect->width;
1263 vOs2Rect.yBottom = vOs2Rect.yTop - pRect->height;
1264
1265 ::WinInvalidateRect(hWnd, &vOs2Rect, bEraseBack);
1266 }
1267 else
1268 ::WinInvalidateRect(hWnd, NULL, bEraseBack);
1269 if (m_hWndScrollBarHorz != NULLHANDLE)
1270 ::WinInvalidateRect(m_hWndScrollBarHorz, NULL, TRUE);
1271 if (m_hWndScrollBarVert != NULLHANDLE)
1272 ::WinInvalidateRect(m_hWndScrollBarVert, NULL, TRUE);
1273 }
1274 } // end of wxWindowOS2::Refresh
1275
1276 // ---------------------------------------------------------------------------
1277 // drag and drop
1278 // ---------------------------------------------------------------------------
1279
1280 #if wxUSE_DRAG_AND_DROP
1281 void wxWindowOS2::SetDropTarget(
1282 wxDropTarget* pDropTarget
1283 )
1284 {
1285 m_dropTarget = pDropTarget;
1286 } // end of wxWindowOS2::SetDropTarget
1287 #endif
1288
1289 //
1290 // old style file-manager drag&drop support: we retain the old-style
1291 // DragAcceptFiles in parallel with SetDropTarget.
1292 //
1293 void wxWindowOS2::DragAcceptFiles(
1294 bool bAccept
1295 )
1296 {
1297 HWND hWnd = GetHwnd();
1298
1299 if (hWnd && bAccept)
1300 ::DrgAcceptDroppedFiles(hWnd, NULL, NULL, DO_COPY, 0L);
1301 } // end of wxWindowOS2::DragAcceptFiles
1302
1303 // ----------------------------------------------------------------------------
1304 // tooltips
1305 // ----------------------------------------------------------------------------
1306
1307 #if wxUSE_TOOLTIPS
1308
1309 void wxWindowOS2::DoSetToolTip(
1310 wxToolTip* pTooltip
1311 )
1312 {
1313 wxWindowBase::DoSetToolTip(pTooltip);
1314
1315 if (m_tooltip)
1316 m_tooltip->SetWindow(this);
1317 } // end of wxWindowOS2::DoSetToolTip
1318
1319 #endif // wxUSE_TOOLTIPS
1320
1321 // ---------------------------------------------------------------------------
1322 // moving and resizing
1323 // ---------------------------------------------------------------------------
1324
1325 // Get total size
1326 void wxWindowOS2::DoGetSize(
1327 int* pWidth
1328 , int* pHeight
1329 ) const
1330 {
1331 HWND hWnd;
1332 RECTL vRect;
1333
1334 if (IsKindOf(CLASSINFO(wxFrame)))
1335 {
1336 wxFrame* pFrame = wxDynamicCast(this, wxFrame);
1337 hWnd = pFrame->GetFrame();
1338 }
1339 else
1340 hWnd = GetHwnd();
1341
1342 ::WinQueryWindowRect(hWnd, &vRect);
1343
1344 if (pWidth)
1345 *pWidth = vRect.xRight - vRect.xLeft;
1346 if (pHeight )
1347 // OS/2 PM is backwards from windows
1348 *pHeight = vRect.yTop - vRect.yBottom;
1349 } // end of wxWindowOS2::DoGetSize
1350
1351 void wxWindowOS2::DoGetPosition(
1352 int* pX
1353 , int* pY
1354 ) const
1355 {
1356 HWND hWnd = GetHwnd();
1357 SWP vSwp;
1358 POINTL vPoint;
1359 wxWindow* pParent = GetParent();
1360
1361 //
1362 // It would seem that WinQueryWindowRect would be the correlary to
1363 // the WIN32 WinGetRect, but unlike WinGetRect which returns the window
1364 // origin position in screen coordinates, WinQueryWindowRect returns it
1365 // relative to itself, i.e. (0,0). To get the same under PM we must
1366 // us WinQueryWindowPos. This call, unlike the WIN32 call, however,
1367 // returns a position relative to it's parent, so no parent adujstments
1368 // are needed under OS/2. Also, windows should be created using
1369 // wxWindow coordinates, i.e 0,0 is the TOP left so vSwp will already
1370 // reflect that.
1371 //
1372 ::WinQueryWindowPos(hWnd, &vSwp);
1373
1374 vPoint.x = vSwp.x;
1375 vPoint.y = vSwp.y;
1376
1377 //
1378 // We may be faking the client origin. So a window that's really at (0,
1379 // 30) may appear (to wxWin apps) to be at (0, 0).
1380 //
1381 if (pParent)
1382 {
1383 wxPoint vPt(pParent->GetClientAreaOrigin());
1384
1385 vPoint.x -= vPt.x;
1386 vPoint.y -= vPt.y;
1387 }
1388
1389 if (pX)
1390 *pX = vPoint.x;
1391 if (pY)
1392 *pY = vPoint.y;
1393 } // end of wxWindowOS2::DoGetPosition
1394
1395 void wxWindowOS2::DoScreenToClient(
1396 int* pX
1397 , int* pY
1398 ) const
1399 {
1400 HWND hWnd = GetHwnd();
1401 SWP vSwp;
1402
1403 ::WinQueryWindowPos(hWnd, &vSwp);
1404
1405 if (pX)
1406 *pX += vSwp.x;
1407 if (pY)
1408 *pY += vSwp.y;
1409 } // end of wxWindowOS2::DoScreenToClient
1410
1411 void wxWindowOS2::DoClientToScreen(
1412 int* pX
1413 , int* pY
1414 ) const
1415 {
1416 HWND hWnd = GetHwnd();
1417 SWP vSwp;
1418
1419 ::WinQueryWindowPos(hWnd, &vSwp);
1420
1421 if (pX)
1422 *pX += vSwp.x;
1423 if (pY)
1424 *pY += vSwp.y;
1425 } // end of wxWindowOS2::DoClientToScreen
1426
1427 //
1428 // Get size *available for subwindows* i.e. excluding menu bar etc.
1429 // Must be a frame type window
1430 //
1431 void wxWindowOS2::DoGetClientSize(
1432 int* pWidth
1433 , int* pHeight
1434 ) const
1435 {
1436 HWND hWnd = GetHwnd();
1437 RECTL vRect;
1438
1439 ::WinQueryWindowRect(hWnd, &vRect);
1440 if (IsKindOf(CLASSINFO(wxDialog)))
1441 {
1442 RECTL vTitle;
1443 HWND hWndTitle;
1444 //
1445 // For a Dialog we have to explicitly request the client portion.
1446 // For a Frame the hWnd IS the client window
1447 //
1448 hWndTitle = ::WinWindowFromID(hWnd, FID_TITLEBAR);
1449 if (::WinQueryWindowRect(hWndTitle, &vTitle))
1450 {
1451 if (vTitle.yTop - vTitle.yBottom == 0)
1452 {
1453 //
1454 // Dialog has not been created yet, use a default
1455 //
1456 vTitle.yTop = 20;
1457 }
1458 vRect.yTop -= (vTitle.yTop - vTitle.yBottom);
1459 }
1460
1461 ULONG uStyle = ::WinQueryWindowULong(hWnd, QWL_STYLE);
1462
1463 //
1464 // Deal with borders
1465 //
1466 if (uStyle & FCF_DLGBORDER)
1467 {
1468 vRect.xLeft += 4;
1469 vRect.xRight -= 4;
1470 vRect.yTop -= 4;
1471 vRect.yBottom += 4;
1472 }
1473 else if (uStyle & FCF_SIZEBORDER)
1474 {
1475 vRect.xLeft += 4;
1476 vRect.xRight -= 4;
1477 vRect.yTop -= 4;
1478 vRect.yBottom += 4;
1479 }
1480 else if (uStyle & FCF_BORDER)
1481 {
1482 vRect.xLeft += 2;
1483 vRect.xRight -= 2;
1484 vRect.yTop -= 2;
1485 vRect.yBottom += 2;
1486 }
1487 else // make some kind of adjustment or top sizers ram into the titlebar!
1488 {
1489 vRect.xLeft += 3;
1490 vRect.xRight -= 3;
1491 vRect.yTop -= 3;
1492 vRect.yBottom += 3;
1493 }
1494 }
1495 if (pWidth)
1496 *pWidth = vRect.xRight - vRect.xLeft;
1497 if (pHeight)
1498 *pHeight = vRect.yTop - vRect.yBottom;
1499 } // end of wxWindowOS2::DoGetClientSize
1500
1501 void wxWindowOS2::DoMoveWindow(
1502 int nX
1503 , int nY
1504 , int nWidth
1505 , int nHeight
1506 )
1507 {
1508 RECTL vRect;
1509 wxWindow* pParent = GetParent();
1510
1511 if (pParent && !IsKindOf(CLASSINFO(wxDialog)))
1512 {
1513 int nOS2Height = GetOS2ParentHeight(pParent);
1514
1515 nY = nOS2Height - (nY + nHeight);
1516 }
1517 else
1518 {
1519 RECTL vRect;
1520
1521 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
1522 nY = vRect.yTop - (nY + nHeight);
1523 }
1524
1525 //
1526 // In the case of a frame whose client is sized, the client cannot be
1527 // large than its parent frame minus its borders! This usually happens
1528 // when using an autosizer to size a frame to precisely hold client
1529 // controls as in the notebook sample.
1530 //
1531 // In this case, we may need to resize both a frame and its client so we
1532 // need a quick calc of the frame border size, then if the frame
1533 // (less its borders) is smaller than the client, size the frame to
1534 // encompass the client with the appropriate border size.
1535 //
1536 if (IsKindOf(CLASSINFO(wxFrame)))
1537 {
1538 RECTL vFRect;
1539 HWND hWndFrame;
1540 int nWidthFrameDelta = 0;
1541 int nHeightFrameDelta = 0;
1542 int nHeightFrame = 0;
1543 int nWidthFrame = 0;
1544 wxFrame* pFrame;
1545
1546 pFrame = wxDynamicCast(this, wxFrame);
1547 hWndFrame = pFrame->GetFrame();
1548 ::WinQueryWindowRect(hWndFrame, &vRect);
1549 ::WinMapWindowPoints(hWndFrame, HWND_DESKTOP, (PPOINTL)&vRect, 2);
1550 vFRect = vRect;
1551 ::WinCalcFrameRect(hWndFrame, &vRect, TRUE);
1552 nWidthFrameDelta = ((vRect.xLeft - vFRect.xLeft) + (vFRect.xRight - vRect.xRight));
1553 nHeightFrameDelta = ((vRect.yBottom - vFRect.yBottom) + (vFRect.yTop - vRect.yTop));
1554 nWidthFrame = vFRect.xRight - vFRect.xLeft;
1555 nHeightFrame = vFRect.yTop - vFRect.yBottom;
1556
1557 if (nWidth == vFRect.xRight - vFRect.xLeft &&
1558 nHeight == vFRect.yTop - vFRect.yBottom)
1559 {
1560 //
1561 // In this case the caller is not aware of OS/2's need to size both
1562 // the frame and it's client and is really only moving the window,
1563 // not resizeing it. So move the frame, and back off the sizes
1564 // for a proper client fit.
1565 //
1566 ::WinSetWindowPos( hWndFrame
1567 ,HWND_TOP
1568 ,(LONG)nX - (vRect.xLeft - vFRect.xLeft)
1569 ,(LONG)nY - (vRect.yBottom - vFRect.yBottom)
1570 ,(LONG)0
1571 ,(LONG)0
1572 ,SWP_MOVE
1573 );
1574 nX += (vRect.xLeft - vFRect.xLeft);
1575 nY += (vRect.yBottom - vFRect.yBottom);
1576 nWidth -= nWidthFrameDelta;
1577 nHeight -= nHeightFrameDelta;
1578 }
1579 else
1580 {
1581 if (nWidth > nWidthFrame - nHeightFrameDelta ||
1582 nHeight > nHeightFrame - nHeightFrameDelta)
1583 {
1584 ::WinSetWindowPos( hWndFrame
1585 ,HWND_TOP
1586 ,(LONG)nX - (vRect.xLeft - vFRect.xLeft)
1587 ,(LONG)nY - (vRect.yBottom - vFRect.yBottom)
1588 ,(LONG)nWidth + nWidthFrameDelta
1589 ,(LONG)nHeight + nHeightFrameDelta
1590 ,SWP_MOVE | SWP_SIZE
1591 );
1592 }
1593 }
1594 }
1595
1596 ::WinSetWindowPos( GetHwnd()
1597 ,HWND_TOP
1598 ,(LONG)nX
1599 ,(LONG)nY
1600 ,(LONG)nWidth
1601 ,(LONG)nHeight
1602 ,SWP_SIZE | SWP_MOVE
1603 );
1604 if (m_vWinSwp.cx == 0 && m_vWinSwp.cy == 0 && m_vWinSwp.fl == 0)
1605 //
1606 // Uninitialized
1607 //
1608 ::WinQueryWindowPos(GetHwnd(), &m_vWinSwp);
1609 else
1610 {
1611 int nYDiff = m_vWinSwp.cy - nHeight;
1612
1613 //
1614 // Handle resizing of scrolled windows. The target or window to
1615 // be scrolled is the owner (gets the scroll notificaitons). The
1616 // parent is usually the parent frame of the scrolled panel window.
1617 // In order to show the scrollbars the target window will be shrunk
1618 // by the size of the scroll bar widths (20) and moved in the X and Y
1619 // directon. That value will be computed as part of the diff for
1620 // moving the children. Everytime the window is sized the
1621 // toplevel OnSize is going to resize the panel to fit the client
1622 // or the whole sizer and will need to me resized. This will send
1623 // a WM_SIZE out which will be intercepted by the ScrollHelper
1624 // which will cause the scrollbars to be displayed via the SetScrollbar
1625 // call in CWindow.
1626 //
1627 if ( IsKindOf(CLASSINFO(wxGenericScrolledWindow)) ||
1628 IsKindOf(CLASSINFO(wxScrolledWindow))
1629 )
1630 {
1631 int nAdjustWidth = 0;
1632 int nAdjustHeight = 0;
1633 SWP vSwpScroll;
1634
1635 if (GetScrollBarHorz() == NULLHANDLE ||
1636 !WinIsWindowShowing(GetScrollBarHorz()))
1637 nAdjustHeight = 0L;
1638 else
1639 nAdjustHeight = 20L;
1640 if (GetScrollBarVert() == NULLHANDLE ||
1641 !WinIsWindowShowing(GetScrollBarVert()))
1642 nAdjustWidth = 0L;
1643 else
1644 nAdjustWidth = 20L;
1645 ::WinQueryWindowPos(GetHWND(), &vSwpScroll);
1646 ::WinSetWindowPos( GetHWND()
1647 ,HWND_TOP
1648 ,vSwpScroll.x
1649 ,vSwpScroll.y + nAdjustHeight
1650 ,vSwpScroll.cx - nAdjustWidth
1651 ,vSwpScroll.cy - nAdjustHeight
1652 ,SWP_MOVE | SWP_SIZE
1653 );
1654 nYDiff += nAdjustHeight;
1655 }
1656 MoveChildren(nYDiff);
1657 ::WinQueryWindowPos(GetHwnd(), &m_vWinSwp);
1658 }
1659 } // end of wxWindowOS2::DoMoveWindow
1660
1661 //
1662 // Set the size of the window: if the dimensions are positive, just use them,
1663 // but if any of them is equal to -1, it means that we must find the value for
1664 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
1665 // which case -1 is a valid value for x and y)
1666 //
1667 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
1668 // the width/height to best suit our contents, otherwise we reuse the current
1669 // width/height
1670 //
1671 void wxWindowOS2::DoSetSize(
1672 int nX
1673 , int nY
1674 , int nWidth
1675 , int nHeight
1676 , int nSizeFlags
1677 )
1678 {
1679 //
1680 // Get the current size and position...
1681 //
1682 int nCurrentX;
1683 int nCurrentY;
1684 int nCurrentWidth;
1685 int nCurrentHeight;
1686 wxSize vSize(-1, -1);
1687
1688 GetPosition(&nCurrentX, &nCurrentY);
1689 GetSize(&nCurrentWidth, &nCurrentHeight);
1690
1691 //
1692 // ... and don't do anything (avoiding flicker) if it's already ok
1693 //
1694 //
1695 // Must convert Y coords to test for equality under OS/2
1696 //
1697 int nY2 = nY;
1698
1699 if (nX == nCurrentX && nY2 == nCurrentY &&
1700 nWidth == nCurrentWidth && nHeight == nCurrentHeight)
1701 {
1702 return;
1703 }
1704
1705 if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
1706 nX = nCurrentX;
1707 if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
1708 nY = nCurrentY;
1709
1710 AdjustForParentClientOrigin(nX, nY, nSizeFlags);
1711
1712 if (nWidth == -1)
1713 {
1714 if (nSizeFlags & wxSIZE_AUTO_WIDTH)
1715 {
1716 vSize = DoGetBestSize();
1717 nWidth = vSize.x;
1718 }
1719 else
1720 {
1721 //
1722 // Just take the current one
1723 //
1724 nWidth = nCurrentWidth;
1725 }
1726 }
1727
1728 if (nHeight == -1)
1729 {
1730 if (nSizeFlags & wxSIZE_AUTO_HEIGHT)
1731 {
1732 if (vSize.x == -1)
1733 {
1734 vSize = DoGetBestSize();
1735 }
1736 nHeight = vSize.y;
1737 }
1738 else
1739 {
1740 // just take the current one
1741 nHeight = nCurrentHeight;
1742 }
1743 }
1744
1745 DoMoveWindow( nX
1746 ,nY
1747 ,nWidth
1748 ,nHeight
1749 );
1750 } // end of wxWindowOS2::DoSetSize
1751
1752 void wxWindowOS2::DoSetClientSize(
1753 int nWidth
1754 , int nHeight
1755 )
1756 {
1757 POINTL vPoint;
1758 int nActualWidth;
1759 int nActualHeight;
1760 wxWindow* pParent = (wxWindow*)GetParent();
1761 HWND hParentWnd = (HWND)0;
1762
1763 if (pParent)
1764 hParentWnd = (HWND)pParent->GetHWND();
1765
1766 if (IsKindOf(CLASSINFO(wxFrame)))
1767 {
1768 wxFrame* pFrame = wxDynamicCast(this, wxFrame);
1769 HWND hFrame = pFrame->GetFrame();
1770 RECTL vRect;
1771 RECTL vRect2;
1772 RECTL vRect3;
1773
1774 ::WinQueryWindowRect(GetHwnd(), &vRect2);
1775 ::WinQueryWindowRect(hFrame, &vRect);
1776 ::WinQueryWindowRect(hParentWnd, &vRect3);
1777 nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth;
1778 nActualHeight = vRect2.yTop - vRect2.yBottom - vRect.yTop + nHeight;
1779
1780 vPoint.x = vRect2.xLeft;
1781 vPoint.y = vRect2.yBottom;
1782 if (pParent)
1783 {
1784 vPoint.x -= vRect3.xLeft;
1785 vPoint.y -= vRect3.yBottom;
1786 }
1787 }
1788 else
1789 {
1790 int nX;
1791 int nY;
1792
1793 GetPosition(&nX, &nY);
1794 nActualWidth = nWidth;
1795 nActualHeight = nHeight;
1796
1797 vPoint.x = nX;
1798 vPoint.y = nY;
1799 }
1800 DoMoveWindow( vPoint.x
1801 ,vPoint.y
1802 ,nActualWidth
1803 ,nActualHeight
1804 );
1805
1806 wxSizeEvent vEvent( wxSize( nWidth
1807 ,nHeight
1808 )
1809 ,m_windowId
1810 );
1811
1812 vEvent.SetEventObject(this);
1813 GetEventHandler()->ProcessEvent(vEvent);
1814 } // end of wxWindowOS2::DoSetClientSize
1815
1816 wxPoint wxWindowOS2::GetClientAreaOrigin() const
1817 {
1818 return wxPoint(0, 0);
1819 } // end of wxWindowOS2::GetClientAreaOrigin
1820
1821 // ---------------------------------------------------------------------------
1822 // text metrics
1823 // ---------------------------------------------------------------------------
1824
1825 int wxWindowOS2::GetCharHeight() const
1826 {
1827 HPS hPs;
1828 FONTMETRICS vFontMetrics;
1829
1830 hPs = ::WinGetPS(GetHwnd());
1831
1832 if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics))
1833 {
1834 ::WinReleasePS(hPs);
1835 return (0);
1836 }
1837 ::WinReleasePS(hPs);
1838 return(vFontMetrics.lMaxAscender + vFontMetrics.lMaxDescender);
1839 } // end of wxWindowOS2::GetCharHeight
1840
1841 int wxWindowOS2::GetCharWidth() const
1842 {
1843 HPS hPs;
1844 FONTMETRICS vFontMetrics;
1845
1846 hPs = ::WinGetPS(GetHwnd());
1847
1848 if(!GpiQueryFontMetrics(hPs, sizeof(FONTMETRICS), &vFontMetrics))
1849 {
1850 ::WinReleasePS(hPs);
1851 return (0);
1852 }
1853 ::WinReleasePS(hPs);
1854 return(vFontMetrics.lAveCharWidth);
1855 } // end of wxWindowOS2::GetCharWidth
1856
1857 void wxWindowOS2::GetTextExtent(
1858 const wxString& rString
1859 , int* pX
1860 , int* pY
1861 , int* pDescent
1862 , int* pExternalLeading
1863 , const wxFont* pTheFont
1864 ) const
1865 {
1866 POINTL avPoint[TXTBOX_COUNT];
1867 POINTL vPtMin;
1868 POINTL vPtMax;
1869 int i;
1870 int l;
1871 FONTMETRICS vFM; // metrics structure
1872 BOOL bRc = FALSE;
1873 char* pStr;
1874 HPS hPS;
1875
1876
1877 hPS = ::WinGetPS(GetHwnd());
1878
1879 l = rString.Length();
1880 if (l > 0L)
1881 {
1882 pStr = (PCH)rString.c_str();
1883
1884 //
1885 // In world coordinates.
1886 //
1887 bRc = ::GpiQueryTextBox( hPS
1888 ,l
1889 ,pStr
1890 ,TXTBOX_COUNT // return maximum information
1891 ,avPoint // array of coordinates points
1892 );
1893 if (bRc)
1894 {
1895 vPtMin.x = avPoint[0].x;
1896 vPtMax.x = avPoint[0].x;
1897 vPtMin.y = avPoint[0].y;
1898 vPtMax.y = avPoint[0].y;
1899 for (i = 1; i < 4; i++)
1900 {
1901 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
1902 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
1903 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
1904 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
1905 }
1906 bRc = ::GpiQueryFontMetrics( hPS
1907 ,sizeof(FONTMETRICS)
1908 ,&vFM
1909 );
1910 if (!bRc)
1911 {
1912 vPtMin.x = 0;
1913 vPtMin.y = 0;
1914 vPtMax.x = 0;
1915 vPtMax.y = 0;
1916 }
1917 }
1918 else
1919 {
1920 vPtMin.x = 0;
1921 vPtMin.y = 0;
1922 vPtMax.x = 0;
1923 vPtMax.y = 0;
1924 }
1925 }
1926 else
1927 {
1928 vPtMin.x = 0;
1929 vPtMin.y = 0;
1930 vPtMax.x = 0;
1931 vPtMax.y = 0;
1932 }
1933 if (pX)
1934 *pX = (vPtMax.x - vPtMin.x + 1);
1935 if (pY)
1936 *pY = (vPtMax.y - vPtMin.y + 1);
1937 if (pDescent)
1938 {
1939 if (bRc)
1940 *pDescent = vFM.lMaxDescender;
1941 else
1942 *pDescent = 0;
1943 }
1944 if (pExternalLeading)
1945 {
1946 if (bRc)
1947 *pExternalLeading = vFM.lExternalLeading;
1948 else
1949 *pExternalLeading = 0;
1950 }
1951 ::WinReleasePS(hPS);
1952 } // end of wxWindow::GetTextExtent
1953
1954 bool wxWindowOS2::IsMouseInWindow() const
1955 {
1956 //
1957 // Get the mouse position
1958 POINTL vPt;
1959
1960 ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
1961
1962 //
1963 // Find the window which currently has the cursor and go up the window
1964 // chain until we find this window - or exhaust it
1965 //
1966 HWND hWnd = ::WinWindowFromPoint(HWND_DESKTOP, &vPt, TRUE);
1967
1968 while (hWnd && (hWnd != GetHwnd()))
1969 hWnd = ::WinQueryWindow(hWnd, QW_PARENT);
1970
1971 return hWnd != NULL;
1972 } // end of wxWindowOS2::IsMouseInWindow
1973
1974
1975 // ---------------------------------------------------------------------------
1976 // popup menu
1977 // ---------------------------------------------------------------------------
1978 //
1979 #if wxUSE_MENUS_NATIVE
1980 bool wxWindowOS2::DoPopupMenu(
1981 wxMenu* pMenu
1982 , int nX
1983 , int nY
1984 )
1985 {
1986 HWND hWndOwner = GetHwnd();
1987 HWND hWndParent = GetHwnd();
1988 HWND hMenu = GetHmenuOf(pMenu);
1989 bool bIsWaiting = TRUE;
1990
1991 pMenu->SetInvokingWindow(this);
1992 pMenu->UpdateUI();
1993
1994 if ( nX == -1 && nY == -1 )
1995 {
1996 wxPoint mouse = wxGetMousePosition();
1997 nX = mouse.x; nY = mouse.y;
1998 }
1999 else
2000 {
2001 DoClientToScreen( &nX
2002 ,&nY
2003 );
2004 }
2005 wxCurrentPopupMenu = pMenu;
2006
2007 ::WinPopupMenu( hWndParent
2008 ,hWndOwner
2009 ,hMenu
2010 ,nX
2011 ,nY
2012 ,0L
2013 ,PU_HCONSTRAIN | PU_VCONSTRAIN | PU_MOUSEBUTTON1 | PU_KEYBOARD
2014 );
2015
2016 while(bIsWaiting)
2017 {
2018 QMSG vMsg;
2019
2020 if (vMsg.msg == WM_MENUEND || vMsg.msg == WM_COMMAND)
2021 {
2022 bIsWaiting = FALSE;
2023 }
2024 ::WinDispatchMsg(vHabmain, (PQMSG)&vMsg);
2025
2026 }
2027 wxCurrentPopupMenu = NULL;
2028 pMenu->SetInvokingWindow(NULL);
2029 return TRUE;
2030 } // end of wxWindowOS2::DoPopupMenu
2031 #endif // wxUSE_MENUS_NATIVE
2032
2033 // ===========================================================================
2034 // pre/post message processing
2035 // ===========================================================================
2036
2037 MRESULT wxWindowOS2::OS2DefWindowProc(
2038 WXUINT uMsg
2039 , WXWPARAM wParam
2040 , WXLPARAM lParam
2041 )
2042 {
2043 if (m_fnOldWndProc)
2044 return (MRESULT)m_fnOldWndProc(GetHWND(), uMsg, (MPARAM)wParam, (MPARAM)lParam);
2045 else
2046 return ::WinDefWindowProc(GetHWND(), uMsg, (MPARAM)wParam, (MPARAM)lParam);
2047 } // end of wxWindowOS2::OS2DefWindowProc
2048
2049 bool wxWindowOS2::OS2ProcessMessage(
2050 WXMSG* pMsg
2051 )
2052 {
2053 // wxUniversal implements tab traversal itself
2054 #ifndef __WXUNIVERSAL__
2055 QMSG* pQMsg = (QMSG*)pMsg;
2056
2057 if (m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL))
2058 {
2059 //
2060 // Intercept dialog navigation keys
2061 //
2062 bool bProcess = TRUE;
2063 USHORT uKeyFlags = SHORT1FROMMP(pQMsg->mp1);
2064
2065 if (uKeyFlags & KC_KEYUP)
2066 bProcess = FALSE;
2067
2068 if (uKeyFlags & KC_ALT)
2069 bProcess = FALSE;
2070
2071 if (!(uKeyFlags & KC_VIRTUALKEY))
2072 bProcess = FALSE;
2073
2074 if (bProcess)
2075 {
2076 bool bCtrlDown = IsCtrlDown();
2077 bool bShiftDown = IsShiftDown();
2078
2079 //
2080 // WM_QUERYDLGCODE: ask the control if it wants the key for itself,
2081 // don't process it if it's the case (except for Ctrl-Tab/Enter
2082 // combinations which are always processed)
2083 //
2084 ULONG ulDlgCode = 0;
2085
2086 if (!bCtrlDown)
2087 {
2088 ulDlgCode = (ULONG)::WinSendMsg(pQMsg->hwnd, WM_QUERYDLGCODE, pQMsg, 0);
2089 }
2090
2091 bool bForward = TRUE;
2092 bool bWindowChange = FALSE;
2093
2094 switch (SHORT2FROMMP(pQMsg->mp2))
2095 {
2096 //
2097 // Going to make certain assumptions about specific types of controls
2098 // here, so we may have to alter some things later if they prove invalid
2099 //
2100 case VK_TAB:
2101 //
2102 // Shift tabl will always be a nav-key but tabs may be wanted
2103 //
2104 if (!bShiftDown)
2105 {
2106 bProcess = FALSE;
2107 }
2108 else
2109 {
2110 //
2111 // Entry Fields want tabs for themselve usually
2112 //
2113 switch (ulDlgCode)
2114 {
2115 case DLGC_ENTRYFIELD:
2116 case DLGC_MLE:
2117 bProcess = TRUE;
2118 break;
2119
2120 default:
2121 bProcess = FALSE;
2122 }
2123
2124 //
2125 // Ctrl-Tab cycles thru notebook pages
2126 //
2127 bWindowChange = bCtrlDown;
2128 bForward = !bShiftDown;
2129 }
2130 break;
2131
2132 case VK_UP:
2133 case VK_LEFT:
2134 if (bCtrlDown)
2135 bProcess = FALSE;
2136 else
2137 bForward = FALSE;
2138 break;
2139
2140 case VK_DOWN:
2141 case VK_RIGHT:
2142 if (bCtrlDown)
2143 bProcess = FALSE;
2144 break;
2145
2146 case VK_ENTER:
2147 {
2148 if (bCtrlDown)
2149 {
2150 //
2151 // ctrl-enter is not processed
2152 //
2153 return FALSE;
2154 }
2155 else if (ulDlgCode & DLGC_BUTTON)
2156 {
2157 //
2158 // buttons want process Enter themselevs
2159 //
2160 bProcess = FALSE;
2161 }
2162 else
2163 {
2164 wxButton* pBtn = wxDynamicCast( GetDefaultItem()
2165 ,wxButton
2166 );
2167
2168 if (pBtn && pBtn->IsEnabled())
2169 {
2170 //
2171 // If we do have a default button, do press it
2172 //
2173 pBtn->OS2Command(BN_CLICKED, 0 /* unused */);
2174 return TRUE;
2175 }
2176 else if (!IsTopLevel())
2177 {
2178 //
2179 // if not a top level window, let parent
2180 // handle it
2181 //
2182 return FALSE;
2183 }
2184 // else: but if it does not it makes sense to make
2185 // it work like a TAB - and that's what we do.
2186 // Note that Ctrl-Enter always works this way.
2187 }
2188 }
2189 break;
2190
2191 default:
2192 bProcess = FALSE;
2193 }
2194
2195 if (bProcess)
2196 {
2197 wxNavigationKeyEvent vEvent;
2198
2199 vEvent.SetDirection(bForward);
2200 vEvent.SetWindowChange(bWindowChange);
2201 vEvent.SetEventObject(this);
2202
2203 if (GetEventHandler()->ProcessEvent(vEvent))
2204 {
2205 wxButton* pBtn = wxDynamicCast(FindFocus(), wxButton);
2206
2207 if (pBtn)
2208 {
2209 //
2210 // The button which has focus should be default
2211 //
2212 pBtn->SetDefault();
2213 }
2214 return TRUE;
2215 }
2216 }
2217 }
2218 //
2219 // Let Dialogs process
2220 //
2221 if (::WinSendMsg(pQMsg->hwnd, WM_QUERYDLGCODE, pQMsg, 0));
2222 return TRUE;
2223 }
2224 #else
2225 pMsg = pMsg; // just shut up the compiler
2226 #endif // __WXUNIVERSAL__
2227
2228 return FALSE;
2229 } // end of wxWindowOS2::OS2ProcessMessage
2230
2231 bool wxWindowOS2::OS2TranslateMessage(
2232 WXMSG* pMsg
2233 )
2234 {
2235 #if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
2236 return m_acceleratorTable.Translate(m_hWnd, pMsg);
2237 #else
2238 pMsg = pMsg;
2239 return FALSE;
2240 #endif //wxUSE_ACCEL
2241 } // end of wxWindowOS2::OS2TranslateMessage
2242
2243 bool wxWindowOS2::OS2ShouldPreProcessMessage(
2244 WXMSG* pMsg
2245 )
2246 {
2247 // preprocess all messages by default
2248 return TRUE;
2249 } // end of wxWindowOS2::OS2ShouldPreProcessMessage
2250
2251 // ---------------------------------------------------------------------------
2252 // message params unpackers
2253 // ---------------------------------------------------------------------------
2254
2255 void wxWindowOS2::UnpackCommand(
2256 WXWPARAM wParam
2257 , WXLPARAM lParam
2258 , WORD* pId
2259 , WXHWND* phWnd
2260 , WORD* pCmd
2261 )
2262 {
2263 *pId = LOWORD(wParam);
2264 *phWnd = NULL; // or may be GetHWND() ?
2265 *pCmd = LOWORD(lParam);
2266 } // end of wxWindowOS2::UnpackCommand
2267
2268 void wxWindowOS2::UnpackActivate(
2269 WXWPARAM wParam
2270 , WXLPARAM lParam
2271 , WXWORD* pState
2272 , WXHWND* phWnd
2273 )
2274 {
2275 *pState = LOWORD(wParam);
2276 *phWnd = (WXHWND)lParam;
2277 } // end of wxWindowOS2::UnpackActivate
2278
2279 void wxWindowOS2::UnpackScroll(
2280 WXWPARAM wParam
2281 , WXLPARAM lParam
2282 , WXWORD* pCode
2283 , WXWORD* pPos
2284 , WXHWND* phWnd
2285 )
2286 {
2287 ULONG ulId;
2288 HWND hWnd;
2289
2290 ulId = (ULONG)LONGFROMMP(wParam);
2291 hWnd = ::WinWindowFromID(GetHwnd(), ulId);
2292 if (hWnd == m_hWndScrollBarHorz || hWnd == m_hWndScrollBarVert)
2293 *phWnd = NULLHANDLE;
2294 else
2295 *phWnd = hWnd;
2296
2297 *pPos = SHORT1FROMMP(lParam);
2298 *pCode = SHORT2FROMMP(lParam);
2299 } // end of wxWindowOS2::UnpackScroll
2300
2301 void wxWindowOS2::UnpackMenuSelect(
2302 WXWPARAM wParam
2303 , WXLPARAM lParam
2304 , WXWORD* pItem
2305 , WXWORD* pFlags
2306 , WXHMENU* phMenu
2307 )
2308 {
2309 *pItem = (WXWORD)LOWORD(wParam);
2310 *pFlags = HIWORD(wParam);
2311 *phMenu = (WXHMENU)lParam;
2312 } // end of wxWindowOS2::UnpackMenuSelect
2313
2314 // ---------------------------------------------------------------------------
2315 // Main wxWidgets window proc and the window proc for wxWindow
2316 // ---------------------------------------------------------------------------
2317
2318 //
2319 // Hook for new window just as it's being created, when the window isn't yet
2320 // associated with the handle
2321 //
2322 wxWindowOS2* wxWndHook = NULL;
2323
2324 //
2325 // Main window proc
2326 //
2327 MRESULT EXPENTRY wxWndProc(
2328 HWND hWnd
2329 , ULONG ulMsg
2330 , MPARAM wParam
2331 , MPARAM lParam
2332 )
2333 {
2334 wxWindowOS2* pWnd = wxFindWinFromHandle((WXHWND)hWnd);
2335
2336 //
2337 // When we get the first message for the HWND we just created, we associate
2338 // it with wxWindow stored in wxWndHook
2339 //
2340 if (!pWnd && wxWndHook)
2341 {
2342 wxAssociateWinWithHandle(hWnd, wxWndHook);
2343 pWnd = wxWndHook;
2344 wxWndHook = NULL;
2345 pWnd->SetHWND((WXHWND)hWnd);
2346 }
2347
2348 MRESULT rc = (MRESULT)0;
2349
2350
2351 //
2352 // Stop right here if we don't have a valid handle in our wxWindow object.
2353 //
2354 if (pWnd && !pWnd->GetHWND())
2355 {
2356 pWnd->SetHWND((WXHWND) hWnd);
2357 rc = pWnd->OS2DefWindowProc(ulMsg, wParam, lParam );
2358 pWnd->SetHWND(0);
2359 }
2360 else
2361 {
2362 if (pWnd)
2363 {
2364 rc = pWnd->OS2WindowProc(ulMsg, wParam, lParam);
2365 if ( (pWnd->GetScrollBarHorz() != NULLHANDLE ||
2366 pWnd->GetScrollBarVert() != NULLHANDLE) &&
2367 ulMsg == WM_PAINT)
2368 {
2369 if (pWnd->GetScrollBarHorz() != NULLHANDLE)
2370 ::WinInvalidateRect(pWnd->GetScrollBarHorz(), NULL, TRUE);
2371 if (pWnd->GetScrollBarVert() != NULLHANDLE)
2372 ::WinInvalidateRect(pWnd->GetScrollBarVert(), NULL, TRUE);
2373 }
2374 }
2375 else
2376 rc = ::WinDefWindowProc(hWnd, ulMsg, wParam, lParam);
2377 }
2378
2379 return rc;
2380 } // end of wxWndProc
2381
2382 //
2383 // We will add (or delete) messages we need to handle at this default
2384 // level as we go
2385 //
2386 MRESULT wxWindowOS2::OS2WindowProc(
2387 WXUINT uMsg
2388 , WXWPARAM wParam
2389 , WXLPARAM lParam
2390 )
2391 {
2392 //
2393 // Did we process the uMsg?
2394 //
2395 bool bProcessed = FALSE;
2396 MRESULT mResult;
2397
2398 //
2399 // For most messages we should return 0 when we do process the message
2400 //
2401 mResult = (MRESULT)0;
2402
2403 switch (uMsg)
2404 {
2405 case WM_CREATE:
2406 {
2407 bool bMayCreate;
2408
2409 bProcessed = HandleCreate( (WXLPCREATESTRUCT)lParam
2410 ,&bMayCreate
2411 );
2412 if (bProcessed)
2413 {
2414 //
2415 // Return 0 to bAllow window creation
2416 //
2417 mResult = (MRESULT)(bMayCreate ? 0 : -1);
2418 }
2419 }
2420 break;
2421
2422 case WM_DESTROY:
2423 HandleDestroy();
2424 bProcessed = TRUE;
2425 break;
2426
2427 case WM_MOVE:
2428 bProcessed = HandleMove( LOWORD(lParam)
2429 ,HIWORD(lParam)
2430 );
2431 break;
2432
2433 case WM_SIZE:
2434 bProcessed = HandleSize( LOWORD(lParam)
2435 ,HIWORD(lParam)
2436 ,(WXUINT)wParam
2437 );
2438 break;
2439
2440 case WM_WINDOWPOSCHANGED:
2441
2442 //
2443 // Dialogs under OS/2 do not get WM_SIZE events at all.
2444 // Instead they get this, which can function much like WM_SIZE
2445 // PSWP contains the new sizes and positioning, PSWP+1 the old
2446 // We use this because ADJUSTWINDOWPOS comes BEFORE the new
2447 // position is added and our auto layout does a WinQueryWindowRect
2448 // to get the CURRENT client size. That is the size used to position
2449 // child controls, so we need to already be sized
2450 // in order to get the child controls positoned properly.
2451 //
2452 if (IsKindOf(CLASSINFO(wxDialog)) || IsKindOf(CLASSINFO(wxFrame)))
2453 {
2454 PSWP pSwp = (PSWP)PVOIDFROMMP(wParam);
2455 PSWP pSwp2 = pSwp++;
2456
2457 if (!(pSwp->cx == pSwp2->cx &&
2458 pSwp->cy == pSwp2->cy))
2459 bProcessed = HandleSize( pSwp->cx
2460 ,pSwp->cy
2461 ,(WXUINT)lParam
2462 );
2463 if (IsKindOf(CLASSINFO(wxFrame)))
2464 {
2465 wxFrame* pFrame = wxDynamicCast(this, wxFrame);
2466
2467 if (pFrame)
2468 {
2469 if (pFrame->GetStatusBar())
2470 pFrame->PositionStatusBar();
2471 if (pFrame->GetToolBar())
2472 pFrame->PositionToolBar();
2473 }
2474 }
2475 }
2476 break;
2477
2478 case WM_ACTIVATE:
2479 {
2480 WXWORD wState;
2481 WXHWND hWnd;
2482
2483 UnpackActivate( wParam
2484 ,lParam
2485 ,&wState
2486 ,&hWnd
2487 );
2488
2489 bProcessed = HandleActivate( wState
2490 ,(WXHWND)hWnd
2491 );
2492 bProcessed = FALSE;
2493 }
2494 break;
2495
2496 case WM_SETFOCUS:
2497 if (SHORT1FROMMP((MPARAM)lParam) == TRUE)
2498 bProcessed = HandleSetFocus((WXHWND)(HWND)wParam);
2499 else
2500 bProcessed = HandleKillFocus((WXHWND)(HWND)wParam);
2501 break;
2502
2503 case WM_PAINT:
2504 bProcessed = HandlePaint();
2505 break;
2506
2507 case WM_CLOSE:
2508 //
2509 // Don't let the DefWindowProc() destroy our window - we'll do it
2510 // ourselves in ~wxWindow
2511 //
2512 bProcessed = TRUE;
2513 mResult = (MRESULT)TRUE;
2514 break;
2515
2516 case WM_SHOW:
2517 bProcessed = HandleShow(wParam != 0, (int)lParam);
2518 break;
2519
2520 //
2521 // Under OS2 PM Joysticks are treated just like mouse events
2522 // The "Motion" events will be prevelent in joysticks
2523 //
2524 case WM_MOUSEMOVE:
2525 case WM_BUTTON1DOWN:
2526 case WM_BUTTON1UP:
2527 case WM_BUTTON1DBLCLK:
2528 case WM_BUTTON1MOTIONEND:
2529 case WM_BUTTON1MOTIONSTART:
2530 case WM_BUTTON2DOWN:
2531 case WM_BUTTON2UP:
2532 case WM_BUTTON2DBLCLK:
2533 case WM_BUTTON2MOTIONEND:
2534 case WM_BUTTON2MOTIONSTART:
2535 case WM_BUTTON3DOWN:
2536 case WM_BUTTON3UP:
2537 case WM_BUTTON3DBLCLK:
2538 case WM_BUTTON3MOTIONEND:
2539 case WM_BUTTON3MOTIONSTART:
2540 {
2541 if (uMsg == WM_BUTTON1DOWN && AcceptsFocus())
2542 SetFocus();
2543
2544 short nX = LOWORD(wParam);
2545 short nY = HIWORD(wParam);
2546
2547 //
2548 // Redirect the event to a static control if necessary
2549 //
2550 if (this == GetCapture())
2551 {
2552 bProcessed = HandleMouseEvent( uMsg
2553 ,nX
2554 ,nY
2555 ,(WXUINT)SHORT2FROMMP(lParam)
2556 );
2557 }
2558 else
2559 {
2560 wxWindow* pWin = FindWindowForMouseEvent( this
2561 ,&nX
2562 ,&nY
2563 );
2564 if (!pWin->IsOfStandardClass())
2565 {
2566 if (uMsg == WM_BUTTON1DOWN && pWin->AcceptsFocus() )
2567 pWin->SetFocus();
2568 }
2569 bProcessed = pWin->HandleMouseEvent( uMsg
2570 ,nX
2571 ,nY
2572 ,(WXUINT)SHORT2FROMMP(lParam)
2573 );
2574 }
2575 }
2576 break;
2577
2578 case WM_SYSCOMMAND:
2579 bProcessed = HandleSysCommand(wParam, lParam);
2580 break;
2581
2582 case WM_COMMAND:
2583 {
2584 WORD id, cmd;
2585 WXHWND hwnd;
2586 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
2587
2588 bProcessed = HandleCommand(id, cmd, hwnd);
2589 }
2590 break;
2591
2592 //
2593 // For these messages we must return TRUE if process the message
2594 //
2595 case WM_DRAWITEM:
2596 case WM_MEASUREITEM:
2597 {
2598 int nIdCtrl = (UINT)wParam;
2599
2600 if ( uMsg == WM_DRAWITEM )
2601 {
2602 bProcessed = OS2OnDrawItem(nIdCtrl,
2603 (WXDRAWITEMSTRUCT *)lParam);
2604 }
2605 else
2606 {
2607 return MRFROMLONG(OS2OnMeasureItem( nIdCtrl
2608 ,(WXMEASUREITEMSTRUCT *)lParam
2609 ));
2610 }
2611
2612 if ( bProcessed )
2613 mResult = (MRESULT)TRUE;
2614 }
2615 break;
2616
2617 case WM_QUERYDLGCODE:
2618 if (!IsOfStandardClass())
2619 {
2620 if ( m_lDlgCode )
2621 {
2622 mResult = (MRESULT)m_lDlgCode;
2623 bProcessed = TRUE;
2624 }
2625 }
2626 //
2627 //else: get the dlg code from the DefWindowProc()
2628 //
2629 break;
2630
2631 //
2632 // In OS/2 PM all keyboard events are of the WM_CHAR type. Virtual key and key-up
2633 // and key-down events are obtained from the WM_CHAR params.
2634 //
2635 case WM_CHAR:
2636 {
2637 USHORT uKeyFlags = SHORT1FROMMP((MPARAM)wParam);
2638
2639 if (uKeyFlags & KC_KEYUP)
2640 {
2641 //TODO: check if the cast to WXWORD isn't causing trouble
2642 bProcessed = HandleKeyUp(wParam, lParam);
2643 break;
2644 }
2645 else // keydown event
2646 {
2647 m_bLastKeydownProcessed = FALSE;
2648 //
2649 // If this has been processed by an event handler,
2650 // return 0 now (we've handled it). DON't RETURN
2651 // we still need to process further
2652 //
2653 m_bLastKeydownProcessed = HandleKeyDown(wParam, lParam);
2654 if (uKeyFlags & KC_VIRTUALKEY)
2655 {
2656 USHORT uVk = SHORT2FROMMP((MPARAM)lParam);
2657
2658 //
2659 // We consider these message "not interesting" to OnChar
2660 //
2661 switch(uVk)
2662 {
2663 case VK_SHIFT:
2664 case VK_CTRL:
2665 case VK_MENU:
2666 case VK_CAPSLOCK:
2667 case VK_NUMLOCK:
2668 case VK_SCRLLOCK:
2669 bProcessed = TRUE;
2670 break;
2671
2672 // Avoid duplicate messages to OnChar for these ASCII keys: they
2673 // will be translated by TranslateMessage() and received in WM_CHAR
2674 case VK_ESC:
2675 case VK_ENTER:
2676 case VK_BACKSPACE:
2677 case VK_TAB:
2678 // But set processed to FALSE, not TRUE to still pass them to
2679 // the control's default window proc - otherwise built-in
2680 // keyboard handling won't work
2681 bProcessed = FALSE;
2682 break;
2683
2684 default:
2685 bProcessed = HandleChar(wParam, lParam);
2686 }
2687 break;
2688 }
2689 else // WM_CHAR -- Always an ASCII character
2690 {
2691 if (m_bLastKeydownProcessed)
2692 {
2693 //
2694 // The key was handled in the EVT_KEY_DOWN and handling
2695 // a key in an EVT_KEY_DOWN handler is meant, by
2696 // design, to prevent EVT_CHARs from happening
2697 //
2698 m_bLastKeydownProcessed = FALSE;
2699 bProcessed = TRUE;
2700 }
2701 else // do generate a CHAR event
2702 {
2703 bProcessed = HandleChar(wParam, lParam, TRUE);
2704 break;
2705 }
2706 }
2707 }
2708 }
2709
2710 case WM_HSCROLL:
2711 case WM_VSCROLL:
2712 {
2713 WXWORD wCode;
2714 WXWORD wPos;
2715 WXHWND hWnd;
2716 UnpackScroll( wParam
2717 ,lParam
2718 ,&wCode
2719 ,&wPos
2720 ,&hWnd
2721 );
2722
2723 bProcessed = OS2OnScroll( uMsg == WM_HSCROLL ? wxHORIZONTAL
2724 : wxVERTICAL
2725 ,wCode
2726 ,wPos
2727 ,hWnd
2728 );
2729 }
2730 break;
2731
2732 case WM_CONTROL:
2733 switch(SHORT2FROMMP(wParam))
2734 {
2735 case BN_PAINT:
2736 {
2737 HWND hWnd = ::WinWindowFromID((HWND)GetHwnd(), SHORT1FROMMP(wParam));
2738 wxWindowOS2* pWin = wxFindWinFromHandle(hWnd);
2739
2740 if (!pWin)
2741 {
2742 bProcessed = FALSE;
2743 break;
2744 }
2745 if (pWin->IsKindOf(CLASSINFO(wxBitmapButton)))
2746 {
2747 wxBitmapButton* pBitmapButton = wxDynamicCast(pWin, wxBitmapButton);
2748
2749 pBitmapButton->OS2OnDraw((WXDRAWITEMSTRUCT *)lParam);
2750 }
2751 return 0;
2752 }
2753 break;
2754
2755 case BKN_PAGESELECTEDPENDING:
2756 {
2757 PPAGESELECTNOTIFY pPage = (PPAGESELECTNOTIFY)lParam;
2758
2759 if ((pPage->ulPageIdNew != pPage->ulPageIdCur) &&
2760 (pPage->ulPageIdNew > 0L && pPage->ulPageIdCur > 0L))
2761 {
2762 wxWindowOS2* pWin = wxFindWinFromHandle(pPage->hwndBook);
2763 wxNotebookEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
2764 ,(int)SHORT1FROMMP(wParam)
2765 ,(int)pPage->ulPageIdNew
2766 ,(int)pPage->ulPageIdCur
2767 );
2768 if (!pWin)
2769 {
2770 bProcessed = FALSE;
2771 break;
2772 }
2773 if (pWin->IsKindOf(CLASSINFO(wxNotebook)))
2774 {
2775 wxNotebook* pNotebook = wxDynamicCast(pWin, wxNotebook);
2776
2777 vEvent.SetEventObject(pWin);
2778 pNotebook->OnSelChange(vEvent);
2779 bProcessed = TRUE;
2780 }
2781 else
2782 bProcessed = FALSE;
2783 }
2784 else
2785 bProcessed = FALSE;
2786 }
2787 break;
2788
2789 case BN_CLICKED: // Dups as LN_SELECT and CBN_LBSELECT
2790 {
2791 HWND hWnd = ::WinWindowFromID((HWND)GetHwnd(), SHORT1FROMMP(wParam));
2792 wxWindowOS2* pWin = wxFindWinFromHandle(hWnd);
2793
2794 if (!pWin)
2795 {
2796 bProcessed = FALSE;
2797 break;
2798 }
2799 //
2800 // Simulate a WM_COMMAND here, as wxWidgets expects all control
2801 // button clicks to generate WM_COMMAND msgs, not WM_CONTROL
2802 //
2803 if (pWin->IsKindOf(CLASSINFO(wxRadioBox)))
2804 {
2805 wxRadioBox* pRadioBox = wxDynamicCast(pWin, wxRadioBox);
2806
2807 pRadioBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
2808 ,(WXUINT)SHORT1FROMMP(wParam)
2809 );
2810 }
2811 if (pWin->IsKindOf(CLASSINFO(wxRadioButton)))
2812 {
2813 wxRadioButton* pRadioButton = wxDynamicCast(pWin, wxRadioButton);
2814
2815 pRadioButton->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
2816 ,(WXUINT)SHORT1FROMMP(wParam)
2817 );
2818 }
2819 if (pWin->IsKindOf(CLASSINFO(wxCheckBox)))
2820 {
2821 wxCheckBox* pCheckBox = wxDynamicCast(pWin, wxCheckBox);
2822
2823 pCheckBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
2824 ,(WXUINT)SHORT1FROMMP(wParam)
2825 );
2826 }
2827 if (pWin->IsKindOf(CLASSINFO(wxListBox)))
2828 {
2829 wxListBox* pListBox = wxDynamicCast(pWin, wxListBox);
2830
2831 pListBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
2832 ,(WXUINT)SHORT1FROMMP(wParam)
2833 );
2834 if (pListBox->GetWindowStyle() & wxLB_OWNERDRAW)
2835 Refresh();
2836 }
2837 if (pWin->IsKindOf(CLASSINFO(wxComboBox)))
2838 {
2839 wxComboBox* pComboBox = wxDynamicCast(pWin, wxComboBox);
2840
2841 pComboBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
2842 ,(WXUINT)SHORT1FROMMP(wParam)
2843 );
2844 }
2845 return 0;
2846 }
2847 break;
2848
2849 case LN_ENTER: /* dups as CBN_EFCHANGE */
2850 {
2851 HWND hWnd = HWNDFROMMP(lParam);
2852 wxWindowOS2* pWin = wxFindWinFromHandle(hWnd);
2853
2854 if (!pWin)
2855 {
2856 bProcessed = FALSE;
2857 break;
2858 }
2859 //
2860 // Simulate a WM_COMMAND here, as wxWidgets expects all control
2861 // button clicks to generate WM_COMMAND msgs, not WM_CONTROL
2862 //
2863 if (pWin->IsKindOf(CLASSINFO(wxListBox)))
2864 {
2865 wxListBox* pListBox = wxDynamicCast(pWin, wxListBox);
2866
2867 pListBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
2868 ,(WXUINT)SHORT1FROMMP(wParam)
2869 );
2870 if (pListBox->GetWindowStyle() & wxLB_OWNERDRAW)
2871 Refresh();
2872
2873 }
2874 if (pWin->IsKindOf(CLASSINFO(wxComboBox)))
2875 {
2876 wxComboBox* pComboBox = wxDynamicCast(pWin, wxComboBox);
2877
2878 pComboBox->OS2Command( (WXUINT)SHORT2FROMMP(wParam)
2879 ,(WXUINT)SHORT1FROMMP(wParam)
2880 );
2881 }
2882 return 0;
2883 }
2884 break;
2885
2886 case SPBN_UPARROW:
2887 case SPBN_DOWNARROW:
2888 case SPBN_CHANGE:
2889 {
2890 char zVal[10];
2891 long lVal;
2892
2893 ::WinSendMsg( HWNDFROMMP(lParam)
2894 ,SPBM_QUERYVALUE
2895 ,&zVal
2896 ,MPFROM2SHORT( (USHORT)10
2897 ,(USHORT)SPBQ_UPDATEIFVALID
2898 )
2899 );
2900 lVal = atol(zVal);
2901 bProcessed = OS2OnScroll( wxVERTICAL
2902 ,(int)SHORT2FROMMP(wParam)
2903 ,(int)lVal
2904 ,HWNDFROMMP(lParam)
2905 );
2906 }
2907 break;
2908
2909 case SLN_SLIDERTRACK:
2910 {
2911 HWND hWnd = ::WinWindowFromID(GetHWND(), SHORT1FROMMP(wParam));
2912 wxWindowOS2* pChild = wxFindWinFromHandle(hWnd);
2913
2914 if (!pChild)
2915 {
2916 bProcessed = FALSE;
2917 break;
2918 }
2919 if (pChild->IsKindOf(CLASSINFO(wxSlider)))
2920 bProcessed = OS2OnScroll( wxVERTICAL
2921 ,(int)SHORT2FROMMP(wParam)
2922 ,(int)LONGFROMMP(lParam)
2923 ,hWnd
2924 );
2925 }
2926 break;
2927 }
2928 break;
2929
2930 #if defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
2931 case WM_CTLCOLORCHANGE:
2932 {
2933 bProcessed = HandleCtlColor(&hBrush);
2934 }
2935 break;
2936 #endif
2937 case WM_ERASEBACKGROUND:
2938 //
2939 // Returning TRUE to requestw PM to paint the window background
2940 // in SYSCLR_WINDOW. We don't really want that
2941 //
2942 bProcessed = HandleEraseBkgnd((WXHDC)(HPS)wParam);
2943 mResult = (MRESULT)(FALSE);
2944 break;
2945
2946 // the return value for this message is ignored
2947 case WM_SYSCOLORCHANGE:
2948 bProcessed = HandleSysColorChange();
2949 break;
2950
2951 case WM_REALIZEPALETTE:
2952 bProcessed = HandlePaletteChanged();
2953 break;
2954
2955 // move all drag and drops to wxDrg
2956 case WM_ENDDRAG:
2957 bProcessed = HandleEndDrag(wParam);
2958 break;
2959
2960 case WM_INITDLG:
2961 bProcessed = HandleInitDialog((WXHWND)(HWND)wParam);
2962
2963 if ( bProcessed )
2964 {
2965 // we never set focus from here
2966 mResult = (MRESULT)FALSE;
2967 }
2968 break;
2969
2970 // wxFrame specific message
2971 case WM_MINMAXFRAME:
2972 bProcessed = HandleGetMinMaxInfo((PSWP)wParam);
2973 break;
2974
2975 case WM_SYSVALUECHANGED:
2976 // TODO: do something
2977 mResult = (MRESULT)TRUE;
2978 break;
2979
2980 //
2981 // Comparable to WM_SETPOINTER for windows, only for just controls
2982 //
2983 case WM_CONTROLPOINTER:
2984 bProcessed = HandleSetCursor( SHORT1FROMMP(wParam) // Control ID
2985 ,(HWND)lParam // Cursor Handle
2986 );
2987 if (bProcessed )
2988 {
2989 //
2990 // Returning TRUE stops the DefWindowProc() from further
2991 // processing this message - exactly what we need because we've
2992 // just set the cursor.
2993 //
2994 mResult = (MRESULT)TRUE;
2995 }
2996 break;
2997 }
2998 if (!bProcessed)
2999 {
3000 #ifdef __WXDEBUG__
3001 wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."),
3002 wxGetMessageName(uMsg));
3003 #endif // __WXDEBUG__
3004 if (IsKindOf(CLASSINFO(wxFrame)))
3005 mResult = ::WinDefWindowProc(m_hWnd, uMsg, wParam, lParam);
3006 else if (IsKindOf(CLASSINFO(wxDialog)))
3007 mResult = ::WinDefDlgProc( m_hWnd, uMsg, wParam, lParam);
3008 else
3009 mResult = OS2DefWindowProc(uMsg, wParam, lParam);
3010 }
3011 return mResult;
3012 } // end of wxWindowOS2::OS2WindowProc
3013
3014 wxWindow* wxFindWinFromHandle(
3015 WXHWND hWnd
3016 )
3017 {
3018 wxNode* pNode = wxWinHandleList->Find((long)hWnd);
3019
3020 if (!pNode)
3021 return NULL;
3022 return (wxWindow *)pNode->GetData();
3023 } // end of wxFindWinFromHandle
3024
3025 void wxAssociateWinWithHandle(
3026 HWND hWnd
3027 , wxWindowOS2* pWin
3028 )
3029 {
3030 //
3031 // Adding NULL hWnd is (first) surely a result of an error and
3032 // (secondly) breaks menu command processing
3033 //
3034 wxCHECK_RET( hWnd != (HWND)NULL,
3035 wxT("attempt to add a NULL hWnd to window list ignored") );
3036
3037
3038 wxWindow* pOldWin = wxFindWinFromHandle((WXHWND) hWnd);
3039
3040 if (pOldWin && (pOldWin != pWin))
3041 {
3042 wxString str(pWin->GetClassInfo()->GetClassName());
3043 wxLogError( "Bug! Found existing HWND %X for new window of class %s"
3044 ,(int)hWnd
3045 ,(const char*)str
3046 );
3047 }
3048 else if (!pOldWin)
3049 {
3050 wxWinHandleList->Append( (long)hWnd
3051 ,pWin
3052 );
3053 }
3054 } // end of wxAssociateWinWithHandle
3055
3056 void wxRemoveHandleAssociation(
3057 wxWindowOS2* pWin
3058 )
3059 {
3060 wxWinHandleList->DeleteObject(pWin);
3061 } // end of wxRemoveHandleAssociation
3062
3063 //
3064 // Default destroyer - override if you destroy it in some other way
3065 // (e.g. with MDI child windows)
3066 //
3067 void wxWindowOS2::OS2DestroyWindow()
3068 {
3069 }
3070
3071 bool wxWindowOS2::OS2GetCreateWindowCoords(
3072 const wxPoint& rPos
3073 , const wxSize& rSize
3074 , int& rnX
3075 , int& rnY
3076 , int& rnWidth
3077 , int& rnHeight
3078 ) const
3079 {
3080 bool bNonDefault = FALSE;
3081 static const int DEFAULT_Y = 200;
3082 static const int DEFAULT_H = 250;
3083
3084 if (rPos.x == -1)
3085 {
3086 rnX = rnY = CW_USEDEFAULT;
3087 }
3088 else
3089 {
3090 rnX = rPos.x;
3091 rnY = rPos.y == -1 ? DEFAULT_Y : rPos.y;
3092 bNonDefault = TRUE;
3093 }
3094 if (rSize.x == -1)
3095 {
3096 rnWidth = rnHeight = CW_USEDEFAULT;
3097 }
3098 else
3099 {
3100 rnWidth = rSize.x;
3101 rnHeight = rSize.y == -1 ? DEFAULT_H : rSize.y;
3102 bNonDefault = TRUE;
3103 }
3104 return bNonDefault;
3105 } // end of wxWindowOS2::OS2GetCreateWindowCoords
3106
3107 WXHWND wxWindowOS2::OS2GetParent() const
3108 {
3109 return m_parent ? m_parent->GetHWND() : NULL;
3110 }
3111
3112 bool wxWindowOS2::OS2Create(
3113 PSZ zClass
3114 , const char* zTitle
3115 , WXDWORD dwStyle
3116 , const wxPoint& rPos
3117 , const wxSize& rSize
3118 , void* pCtlData
3119 , WXDWORD dwExStyle
3120 , bool bIsChild
3121 )
3122 {
3123 ERRORID vError;
3124 wxString sError;
3125 int nX = 0L;
3126 int nY = 0L;
3127 int nWidth = 0L;
3128 int nHeight = 0L;
3129 long lControlId = 0L;
3130 wxWindowCreationHook vHook(this);
3131 wxString sClassName((wxChar*)zClass);
3132
3133 OS2GetCreateWindowCoords( rPos
3134 ,rSize
3135 ,nX
3136 ,nY
3137 ,nWidth
3138 ,nHeight
3139 );
3140
3141 if (bIsChild)
3142 {
3143 lControlId = GetId();
3144 if (GetWindowStyleFlag() & wxCLIP_SIBLINGS)
3145 {
3146 dwStyle |= WS_CLIPSIBLINGS;
3147 }
3148 }
3149 //
3150 // For each class "Foo" we have we also have "FooNR" ("no repaint") class
3151 // which is the same but without CS_[HV]REDRAW class styles so using it
3152 // ensures that the window is not fully repainted on each resize
3153 //
3154 if (!HasFlag(wxFULL_REPAINT_ON_RESIZE))
3155 {
3156 sClassName += wxT("NR");
3157 }
3158 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)OS2GetParent()
3159 ,(PSZ)sClassName.c_str()
3160 ,(PSZ)zTitle ? zTitle : ""
3161 ,(ULONG)dwStyle
3162 ,(LONG)0L
3163 ,(LONG)0L
3164 ,(LONG)0L
3165 ,(LONG)0L
3166 ,NULLHANDLE
3167 ,HWND_TOP
3168 ,(ULONG)lControlId
3169 ,pCtlData
3170 ,NULL
3171 );
3172 if (!m_hWnd)
3173 {
3174 vError = ::WinGetLastError(wxGetInstance());
3175 sError = wxPMErrorToStr(vError);
3176 return FALSE;
3177 }
3178 SubclassWin(m_hWnd);
3179 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3180
3181 m_backgroundColour.Set(wxString("GREY"));
3182
3183 LONG lColor = (LONG)m_backgroundColour.GetPixel();
3184
3185 if (!::WinSetPresParam( m_hWnd
3186 ,PP_BACKGROUNDCOLOR
3187 ,sizeof(LONG)
3188 ,(PVOID)&lColor
3189 ))
3190 {
3191 vError = ::WinGetLastError(vHabmain);
3192 sError = wxPMErrorToStr(vError);
3193 wxLogError("Error creating frame. Error: %s\n", sError.c_str());
3194 return FALSE;
3195 }
3196 SetSize( nX
3197 ,nY
3198 ,nWidth
3199 ,nHeight
3200 );
3201 return TRUE;
3202 } // end of WinGuiBase_Window::OS2Create
3203
3204 // ===========================================================================
3205 // OS2 PM message handlers
3206 // ===========================================================================
3207
3208 // ---------------------------------------------------------------------------
3209 // window creation/destruction
3210 // ---------------------------------------------------------------------------
3211
3212 bool wxWindowOS2::HandleCreate(
3213 WXLPCREATESTRUCT WXUNUSED(vCs)
3214 , bool* pbMayCreate
3215 )
3216 {
3217 wxWindowCreateEvent vEvent((wxWindow*)this);
3218
3219 (void)GetEventHandler()->ProcessEvent(vEvent);
3220 *pbMayCreate = TRUE;
3221 return TRUE;
3222 } // end of wxWindowOS2::HandleCreate
3223
3224 bool wxWindowOS2::HandleDestroy()
3225 {
3226 wxWindowDestroyEvent vEvent((wxWindow*)this);
3227 vEvent.SetId(GetId());
3228 (void)GetEventHandler()->ProcessEvent(vEvent);
3229
3230 //
3231 // Delete our drop target if we've got one
3232 //
3233 #if wxUSE_DRAG_AND_DROP
3234 if (m_dropTarget != NULL)
3235 {
3236 delete m_dropTarget;
3237 m_dropTarget = NULL;
3238 }
3239 #endif // wxUSE_DRAG_AND_DROP
3240
3241 //
3242 // WM_DESTROY handled
3243 //
3244 return TRUE;
3245 } // end of wxWindowOS2::HandleDestroy
3246
3247 // ---------------------------------------------------------------------------
3248 // activation/focus
3249 // ---------------------------------------------------------------------------
3250 void wxWindowOS2::OnSetFocus(
3251 wxFocusEvent& rEvent
3252 )
3253 {
3254 rEvent.Skip();
3255 } // end of wxWindowOS2::OnSetFocus
3256
3257 bool wxWindowOS2::HandleActivate(
3258 int nState
3259 , WXHWND WXUNUSED(hActivate)
3260 )
3261 {
3262 wxActivateEvent vEvent( wxEVT_ACTIVATE
3263 ,(bool)nState
3264 ,m_windowId
3265 );
3266 vEvent.SetEventObject(this);
3267 return GetEventHandler()->ProcessEvent(vEvent);
3268 } // end of wxWindowOS2::HandleActivate
3269
3270 bool wxWindowOS2::HandleSetFocus(
3271 WXHWND WXUNUSED(hWnd)
3272 )
3273 {
3274 //
3275 // Notify the parent keeping track of focus for the kbd navigation
3276 // purposes that we got it
3277 //
3278 wxChildFocusEvent vEventFocus((wxWindow *)this);
3279 (void)GetEventHandler()->ProcessEvent(vEventFocus);
3280
3281 #if wxUSE_CARET
3282 //
3283 // Deal with caret
3284 //
3285 if (m_caret)
3286 {
3287 m_caret->OnSetFocus();
3288 }
3289 #endif // wxUSE_CARET
3290
3291 #if wxUSE_TEXTCTRL
3292 // If it's a wxTextCtrl don't send the event as it will be done
3293 // after the control gets to process it from EN_FOCUS handler
3294 if ( wxDynamicCastThis(wxTextCtrl) )
3295 {
3296 return FALSE;
3297 }
3298 #endif // wxUSE_TEXTCTRL
3299
3300 wxFocusEvent vEvent(wxEVT_SET_FOCUS, m_windowId);
3301
3302 vEvent.SetEventObject(this);
3303 return GetEventHandler()->ProcessEvent(vEvent);
3304 } // end of wxWindowOS2::HandleSetFocus
3305
3306 bool wxWindowOS2::HandleKillFocus(
3307 WXHWND hWnd
3308 )
3309 {
3310 #if wxUSE_CARET
3311 //
3312 // Deal with caret
3313 //
3314 if (m_caret)
3315 {
3316 m_caret->OnKillFocus();
3317 }
3318 #endif // wxUSE_CARET
3319
3320 #if wxUSE_TEXTCTRL
3321 //
3322 // If it's a wxTextCtrl don't send the event as it will be done
3323 // after the control gets to process it.
3324 //
3325 wxTextCtrl* pCtrl = wxDynamicCastThis(wxTextCtrl);
3326
3327 if (pCtrl)
3328 {
3329 return FALSE;
3330 }
3331 #endif
3332
3333 //
3334 // Don't send the event when in the process of being deleted. This can
3335 // only cause problems if the event handler tries to access the object.
3336 //
3337 if ( m_isBeingDeleted )
3338 {
3339 return FALSE;
3340 }
3341
3342 wxFocusEvent vEvent( wxEVT_KILL_FOCUS
3343 ,m_windowId
3344 );
3345
3346 vEvent.SetEventObject(this);
3347
3348 //
3349 // wxFindWinFromHandle() may return NULL, it is ok
3350 //
3351 vEvent.SetWindow(wxFindWinFromHandle(hWnd));
3352 return GetEventHandler()->ProcessEvent(vEvent);
3353 } // end of wxWindowOS2::HandleKillFocus
3354
3355 // ---------------------------------------------------------------------------
3356 // miscellaneous
3357 // ---------------------------------------------------------------------------
3358
3359 bool wxWindowOS2::HandleShow(
3360 bool bShow
3361 , int WXUNUSED(nStatus)
3362 )
3363 {
3364 wxShowEvent vEvent(GetId(), bShow);
3365
3366 vEvent.m_eventObject = this;
3367 return GetEventHandler()->ProcessEvent(vEvent);
3368 } // end of wxWindowOS2::HandleShow
3369
3370 bool wxWindowOS2::HandleInitDialog(
3371 WXHWND WXUNUSED(hWndFocus)
3372 )
3373 {
3374 wxInitDialogEvent vEvent(GetId());
3375
3376 vEvent.m_eventObject = this;
3377 return GetEventHandler()->ProcessEvent(vEvent);
3378 } // end of wxWindowOS2::HandleInitDialog
3379
3380 bool wxWindowOS2::HandleEndDrag(WXWPARAM WXUNUSED(wParam))
3381 {
3382 // TODO: We'll handle drag and drop later
3383 return FALSE;
3384 }
3385
3386 bool wxWindowOS2::HandleSetCursor(
3387 USHORT WXUNUSED(vId)
3388 , WXHWND hPointer
3389 )
3390 {
3391 //
3392 // Under OS/2 PM this allows the pointer to be changed
3393 // as it passes over a control
3394 //
3395 ::WinSetPointer(HWND_DESKTOP, (HPOINTER)hPointer);
3396 return TRUE;
3397 } // end of wxWindowOS2::HandleSetCursor
3398
3399 // ---------------------------------------------------------------------------
3400 // owner drawn stuff
3401 // ---------------------------------------------------------------------------
3402 bool wxWindowOS2::OS2OnDrawItem(
3403 int vId
3404 , WXDRAWITEMSTRUCT* pItemStruct
3405 )
3406 {
3407 #if wxUSE_OWNER_DRAWN
3408 wxDC vDc;
3409
3410 #if wxUSE_MENUS_NATIVE
3411 //
3412 // Is it a menu item?
3413 //
3414 if (vId == 0)
3415 {
3416 ERRORID vError;
3417 wxString sError;
3418 POWNERITEM pMeasureStruct = (POWNERITEM)pItemStruct;
3419 wxFrame* pFrame = (wxFrame*)this;
3420 wxMenuItem* pMenuItem = pFrame->GetMenuBar()->FindItem(pMeasureStruct->idItem, pMeasureStruct->hItem);
3421 HDC hDC = ::GpiQueryDevice(pMeasureStruct->hps);
3422 wxRect vRect( pMeasureStruct->rclItem.xLeft
3423 ,pMeasureStruct->rclItem.yBottom
3424 ,pMeasureStruct->rclItem.xRight - pMeasureStruct->rclItem.xLeft
3425 ,pMeasureStruct->rclItem.yTop - pMeasureStruct->rclItem.yBottom
3426 );
3427 vDc.SetHDC( hDC
3428 ,FALSE
3429 );
3430 vDc.SetHPS(pMeasureStruct->hps);
3431 //
3432 // Load the wxWidgets Pallete and set to RGB mode
3433 //
3434 if (!::GpiCreateLogColorTable( pMeasureStruct->hps
3435 ,0L
3436 ,LCOLF_CONSECRGB
3437 ,0L
3438 ,(LONG)wxTheColourDatabase->m_nSize
3439 ,(PLONG)wxTheColourDatabase->m_palTable
3440 ))
3441 {
3442 vError = ::WinGetLastError(vHabmain);
3443 sError = wxPMErrorToStr(vError);
3444 wxLogError("Unable to set current color table. Error: %s\n", sError.c_str());
3445 }
3446 //
3447 // Set the color table to RGB mode
3448 //
3449 if (!::GpiCreateLogColorTable( pMeasureStruct->hps
3450 ,0L
3451 ,LCOLF_RGB
3452 ,0L
3453 ,0L
3454 ,NULL
3455 ))
3456 {
3457 vError = ::WinGetLastError(vHabmain);
3458 sError = wxPMErrorToStr(vError);
3459 wxLogError("Unable to set current color table. Error: %s\n", sError.c_str());
3460 }
3461
3462 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
3463
3464
3465 int eAction = 0;
3466 int eStatus = 0;
3467
3468 if (pMeasureStruct->fsAttribute == pMeasureStruct->fsAttributeOld)
3469 {
3470 //
3471 // Entire Item needs to be redrawn (either it has reappeared from
3472 // behind another window or is being displayed for the first time
3473 //
3474 eAction = wxOwnerDrawn::wxODDrawAll;
3475
3476 if (pMeasureStruct->fsAttribute & MIA_HILITED)
3477 {
3478 //
3479 // If it is currently selected we let the system handle it
3480 //
3481 eStatus |= wxOwnerDrawn::wxODSelected;
3482 }
3483 if (pMeasureStruct->fsAttribute & MIA_CHECKED)
3484 {
3485 //
3486 // If it is currently checked we draw our own
3487 //
3488 eStatus |= wxOwnerDrawn::wxODChecked;
3489 pMeasureStruct->fsAttributeOld = pMeasureStruct->fsAttribute &= ~MIA_CHECKED;
3490 }
3491 if (pMeasureStruct->fsAttribute & MIA_DISABLED)
3492 {
3493 //
3494 // If it is currently disabled we let the system handle it
3495 //
3496 eStatus |= wxOwnerDrawn::wxODDisabled;
3497 }
3498 //
3499 // Don't really care about framed (indicationg focus) or NoDismiss
3500 //
3501 }
3502 else
3503 {
3504 if (pMeasureStruct->fsAttribute & MIA_HILITED)
3505 {
3506 eAction = wxOwnerDrawn::wxODDrawAll;
3507 eStatus |= wxOwnerDrawn::wxODSelected;
3508 //
3509 // Keep the system from trying to highlight with its bogus colors
3510 //
3511 pMeasureStruct->fsAttributeOld = pMeasureStruct->fsAttribute &= ~MIA_HILITED;
3512 }
3513 else if (!(pMeasureStruct->fsAttribute & MIA_HILITED))
3514 {
3515 eAction = wxOwnerDrawn::wxODDrawAll;
3516 eStatus = 0;
3517 //
3518 // Keep the system from trying to highlight with its bogus colors
3519 //
3520 pMeasureStruct->fsAttribute = pMeasureStruct->fsAttributeOld &= ~MIA_HILITED;
3521 }
3522 else
3523 {
3524 //
3525 // For now we don't care about anything else
3526 // just ignore the entire message!
3527 //
3528 return TRUE;
3529 }
3530 }
3531 //
3532 // Now redraw the item
3533 //
3534 return(pMenuItem->OnDrawItem( vDc
3535 ,vRect
3536 ,(wxOwnerDrawn::wxODAction)eAction
3537 ,(wxOwnerDrawn::wxODStatus)eStatus
3538 ));
3539 //
3540 // leave the fsAttribute and fsOldAttribute unchanged. If different,
3541 // the system will do the highlight or fraeming or disabling for us,
3542 // otherwise, we'd have to do it ourselves.
3543 //
3544 }
3545 #endif // wxUSE_MENUS_NATIVE
3546
3547 wxWindow* pItem = FindItem(vId);
3548
3549 if (pItem && pItem->IsKindOf(CLASSINFO(wxControl)))
3550 {
3551 return ((wxControl *)pItem)->OS2OnDraw(pItemStruct);
3552 }
3553 #else
3554 vId = vId;
3555 pItemStruct = pItemStruct;
3556 #endif
3557 return FALSE;
3558 } // end of wxWindowOS2::OS2OnDrawItem
3559
3560 long wxWindowOS2::OS2OnMeasureItem(
3561 int lId
3562 , WXMEASUREITEMSTRUCT* pItemStruct
3563 )
3564 {
3565 #if wxUSE_OWNER_DRAWN
3566 //
3567 // Is it a menu item?
3568 //
3569 if (lId == 65536) // I really don't like this...has to be a better indicator
3570 {
3571 if (IsKindOf(CLASSINFO(wxFrame))) // we'll assume if Frame then a menu
3572 {
3573 size_t nWidth;
3574 size_t nHeight;
3575 POWNERITEM pMeasureStruct = (POWNERITEM)pItemStruct;
3576 wxFrame* pFrame = (wxFrame*)this;
3577 wxMenuItem* pMenuItem = pFrame->GetMenuBar()->FindItem(pMeasureStruct->idItem, pMeasureStruct->hItem);
3578
3579 wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
3580 nWidth = 0L;
3581 nHeight = 0L;
3582 if (pMenuItem->OnMeasureItem( &nWidth
3583 ,&nHeight
3584 ))
3585 {
3586 MRESULT mRc;
3587
3588 pMeasureStruct->rclItem.xRight = nWidth;
3589 pMeasureStruct->rclItem.xLeft = 0L;
3590 pMeasureStruct->rclItem.yTop = nHeight;
3591 pMeasureStruct->rclItem.yBottom = 0L;
3592 mRc = MRFROM2SHORT(nHeight, nWidth);
3593 return LONGFROMMR(mRc);
3594 }
3595 return 0L;
3596 }
3597 }
3598 wxWindow* pItem = FindItem(lId);
3599
3600 if (pItem && pItem->IsKindOf(CLASSINFO(wxControl)))
3601 {
3602 OWNERITEM vItem;
3603
3604 vItem.idItem = (LONG)pItemStruct;
3605 return ((wxControl *)pItem)->OS2OnMeasure((WXMEASUREITEMSTRUCT*)&vItem);
3606 }
3607 #else
3608 lId = lId;
3609 pItemStruct = pItemStruct;
3610 #endif // wxUSE_OWNER_DRAWN
3611 return FALSE;
3612 }
3613
3614 // ---------------------------------------------------------------------------
3615 // colours and palettes
3616 // ---------------------------------------------------------------------------
3617
3618 bool wxWindowOS2::HandleSysColorChange()
3619 {
3620 wxSysColourChangedEvent vEvent;
3621
3622 vEvent.SetEventObject(this);
3623 return GetEventHandler()->ProcessEvent(vEvent);
3624 } // end of wxWindowOS2::HandleSysColorChange
3625
3626 bool wxWindowOS2::HandleCtlColor(
3627 WXHBRUSH* WXUNUSED(phBrush)
3628 )
3629 {
3630 //
3631 // Not much provided with message. So not sure I can do anything with it
3632 //
3633 return TRUE;
3634 } // end of wxWindowOS2::HandleCtlColor
3635
3636
3637 // Define for each class of dialog and control
3638 WXHBRUSH wxWindowOS2::OnCtlColor(WXHDC WXUNUSED(hDC),
3639 WXHWND WXUNUSED(hWnd),
3640 WXUINT WXUNUSED(nCtlColor),
3641 WXUINT WXUNUSED(message),
3642 WXWPARAM WXUNUSED(wParam),
3643 WXLPARAM WXUNUSED(lParam))
3644 {
3645 return (WXHBRUSH)0;
3646 }
3647
3648 bool wxWindowOS2::HandlePaletteChanged()
3649 {
3650 // need to set this to something first
3651 WXHWND hWndPalChange = NULLHANDLE;
3652
3653 wxPaletteChangedEvent vEvent(GetId());
3654
3655 vEvent.SetEventObject(this);
3656 vEvent.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
3657
3658 return GetEventHandler()->ProcessEvent(vEvent);
3659 } // end of wxWindowOS2::HandlePaletteChanged
3660
3661 //
3662 // Responds to colour changes: passes event on to children.
3663 //
3664 void wxWindowOS2::OnSysColourChanged(
3665 wxSysColourChangedEvent& rEvent
3666 )
3667 {
3668 wxWindowListNode* pNode = GetChildren().GetFirst();
3669
3670 while (pNode)
3671 {
3672 //
3673 // Only propagate to non-top-level windows
3674 //
3675 wxWindow* pWin = (wxWindow *)pNode->GetData();
3676
3677 if (pWin->GetParent())
3678 {
3679 wxSysColourChangedEvent vEvent;
3680
3681 rEvent.m_eventObject = pWin;
3682 pWin->GetEventHandler()->ProcessEvent(vEvent);
3683 }
3684 pNode = pNode->GetNext();
3685 }
3686 } // end of wxWindowOS2::OnSysColourChanged
3687
3688 // ---------------------------------------------------------------------------
3689 // painting
3690 // ---------------------------------------------------------------------------
3691
3692 void wxWindow::OnPaint (
3693 wxPaintEvent& rEvent
3694 )
3695 {
3696 HDC hDC = (HDC)wxPaintDC::FindDCInCache((wxWindow*) rEvent.GetEventObject());
3697
3698 if (hDC != 0)
3699 {
3700 OS2DefWindowProc( (WXUINT)WM_PAINT
3701 ,(WXWPARAM)hDC
3702 ,(WXLPARAM)0
3703 );
3704 }
3705 } // end of wxWindow::OnPaint
3706
3707 bool wxWindowOS2::HandlePaint()
3708 {
3709 HRGN hRgn;
3710 wxPaintEvent vEvent(m_windowId);
3711 HPS hPS;
3712 bool bProcessed;
3713
3714 // Create empty region
3715 // TODO: get HPS somewhere else if possible
3716 hPS = ::WinGetPS(GetHwnd());
3717 hRgn = ::GpiCreateRegion(hPS, 0, NULL);
3718
3719 if (::WinQueryUpdateRegion(GetHwnd(), hRgn) == RGN_ERROR)
3720 {
3721 wxLogLastError("CreateRectRgn");
3722 return FALSE;
3723 }
3724
3725 // Get all the rectangles from the region, convert the individual
3726 // rectangles to "the other" coordinate system and reassemble a
3727 // region from the rectangles, to be feed into m_updateRegion.
3728 //
3729 // FIXME: This is a bad hack since OS/2 API specifies that rectangles
3730 // passed into GpiSetRegion must not have Bottom > Top,
3731 // however, at first sight, it _seems_ to work nonetheless.
3732 //
3733 RGNRECT vRgnData;
3734 PRECTL pUpdateRects = NULL;
3735 vRgnData.ulDirection = RECTDIR_LFRT_TOPBOT;
3736 if (::GpiQueryRegionRects( hPS // Pres space
3737 ,hRgn // Handle of region to query
3738 ,NULL // Return all RECTs
3739 ,&vRgnData // Will contain number or RECTs in region
3740 ,NULL // NULL to return number of RECTs
3741 ))
3742 {
3743 pUpdateRects = new RECTL[vRgnData.crcReturned];
3744 vRgnData.crc = vRgnData.crcReturned;
3745 vRgnData.ircStart = 1;
3746 if (::GpiQueryRegionRects( hPS // Pres space of source
3747 ,hRgn // Handle of source region
3748 ,NULL // Return all RECTs
3749 ,&vRgnData // Operations set to return rects
3750 ,pUpdateRects // Will contain the actual RECTS
3751 ))
3752 {
3753 int height;
3754 RECT vRect;
3755 ::WinQueryWindowRect(GetHwnd(), &vRect);
3756 height = vRect.yTop;
3757
3758 for(size_t i = 0; i < vRgnData.crc; i++)
3759 {
3760 int rectHeight;
3761 rectHeight = pUpdateRects[i].yTop - pUpdateRects[i].yBottom;
3762 pUpdateRects[i].yTop = height - pUpdateRects[i].yTop;
3763 pUpdateRects[i].yBottom = pUpdateRects[i].yTop + rectHeight;
3764 }
3765 ::GpiSetRegion(hPS, hRgn, vRgnData.crc, pUpdateRects);
3766 delete [] pUpdateRects;
3767 }
3768 }
3769
3770 m_updateRegion = wxRegion(hRgn, hPS);
3771
3772 vEvent.SetEventObject(this);
3773 bProcessed = GetEventHandler()->ProcessEvent(vEvent);
3774
3775 if (!bProcessed &&
3776 IsKindOf(CLASSINFO(wxPanel)) &&
3777 GetChildren().GetCount() == 0
3778 )
3779 {
3780 //
3781 // OS/2 needs to process this right here, not by the default proc
3782 // Window's default proc correctly paints everything, OS/2 does not.
3783 // For decorative panels that typically have no children, we draw
3784 // borders.
3785 //
3786 HPS hPS;
3787 RECTL vRect;
3788
3789 hPS = ::WinBeginPaint( GetHwnd()
3790 ,NULLHANDLE
3791 ,&vRect
3792 );
3793 if(hPS)
3794 {
3795 ::GpiCreateLogColorTable( hPS
3796 ,0L
3797 ,LCOLF_CONSECRGB
3798 ,0L
3799 ,(LONG)wxTheColourDatabase->m_nSize
3800 ,(PLONG)wxTheColourDatabase->m_palTable
3801 );
3802 ::GpiCreateLogColorTable( hPS
3803 ,0L
3804 ,LCOLF_RGB
3805 ,0L
3806 ,0L
3807 ,NULL
3808 );
3809 if (::WinIsWindowVisible(GetHWND()))
3810 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
3811 if (m_dwExStyle)
3812 {
3813 LINEBUNDLE vLineBundle;
3814
3815 vLineBundle.lColor = 0x00000000; // Black
3816 vLineBundle.usMixMode = FM_OVERPAINT;
3817 vLineBundle.fxWidth = 1;
3818 vLineBundle.lGeomWidth = 1;
3819 vLineBundle.usType = LINETYPE_SOLID;
3820 vLineBundle.usEnd = 0;
3821 vLineBundle.usJoin = 0;
3822 ::GpiSetAttrs( hPS
3823 ,PRIM_LINE
3824 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE
3825 ,0L
3826 ,&vLineBundle
3827 );
3828 ::WinQueryWindowRect(GetHwnd(), &vRect);
3829 wxDrawBorder( hPS
3830 ,vRect
3831 ,m_dwExStyle
3832 );
3833 }
3834 }
3835 ::WinEndPaint(hPS);
3836 bProcessed = TRUE;
3837 }
3838 else if (!bProcessed &&
3839 IsKindOf(CLASSINFO(wxPanel))
3840 )
3841 {
3842 //
3843 // Panel with children, usually fills a frame client so no borders.
3844 //
3845 HPS hPS;
3846 RECTL vRect;
3847
3848 hPS = ::WinBeginPaint( GetHwnd()
3849 ,NULLHANDLE
3850 ,&vRect
3851 );
3852 if(hPS)
3853 {
3854 ::GpiCreateLogColorTable( hPS
3855 ,0L
3856 ,LCOLF_CONSECRGB
3857 ,0L
3858 ,(LONG)wxTheColourDatabase->m_nSize
3859 ,(PLONG)wxTheColourDatabase->m_palTable
3860 );
3861 ::GpiCreateLogColorTable( hPS
3862 ,0L
3863 ,LCOLF_RGB
3864 ,0L
3865 ,0L
3866 ,NULL
3867 );
3868
3869 if (::WinIsWindowVisible(GetHWND()))
3870 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
3871 }
3872 ::WinEndPaint(hPS);
3873 bProcessed = TRUE;
3874 }
3875 return bProcessed;
3876 } // end of wxWindowOS2::HandlePaint
3877
3878 bool wxWindowOS2::HandleEraseBkgnd(
3879 WXHDC hDC
3880 )
3881 {
3882 SWP vSwp;
3883 bool rc;
3884
3885 ::WinQueryWindowPos(GetHwnd(), &vSwp);
3886 if (vSwp.fl & SWP_MINIMIZE)
3887 return TRUE;
3888
3889 wxDC vDC;
3890
3891 vDC.m_hPS = (HPS)hDC; // this is really a PS
3892 vDC.SetWindow((wxWindow*)this);
3893 vDC.BeginDrawing();
3894
3895 wxEraseEvent vEvent(m_windowId, &vDC);
3896
3897 vEvent.SetEventObject(this);
3898
3899 rc = GetEventHandler()->ProcessEvent(vEvent);
3900
3901 vDC.EndDrawing();
3902 vDC.m_hPS = NULLHANDLE;
3903 return TRUE;
3904 } // end of wxWindowOS2::HandleEraseBkgnd
3905
3906 void wxWindowOS2::OnEraseBackground(
3907 wxEraseEvent& rEvent
3908 )
3909 {
3910 RECTL vRect;
3911 HPS hPS = rEvent.m_dc->m_hPS;
3912 APIRET rc;
3913 LONG lColor = m_backgroundColour.GetPixel();
3914
3915 rc = ::WinQueryWindowRect(GetHwnd(), &vRect);
3916 rc = ::WinFillRect(hPS, &vRect, lColor);
3917 } // end of wxWindowOS2::OnEraseBackground
3918
3919 // ---------------------------------------------------------------------------
3920 // moving and resizing
3921 // ---------------------------------------------------------------------------
3922
3923 bool wxWindowOS2::HandleMinimize()
3924 {
3925 wxIconizeEvent vEvent(m_windowId);
3926
3927 vEvent.SetEventObject(this);
3928 return GetEventHandler()->ProcessEvent(vEvent);
3929 } // end of wxWindowOS2::HandleMinimize
3930
3931 bool wxWindowOS2::HandleMaximize()
3932 {
3933 wxMaximizeEvent vEvent(m_windowId);
3934
3935 vEvent.SetEventObject(this);
3936 return GetEventHandler()->ProcessEvent(vEvent);
3937 } // end of wxWindowOS2::HandleMaximize
3938
3939 bool wxWindowOS2::HandleMove(
3940 int nX
3941 , int nY
3942 )
3943 {
3944 wxMoveEvent vEvent(wxPoint(nX, nY), m_windowId);
3945
3946 vEvent.SetEventObject(this);
3947 return GetEventHandler()->ProcessEvent(vEvent);
3948 } // end of wxWindowOS2::HandleMove
3949
3950 bool wxWindowOS2::HandleSize(
3951 int nWidth
3952 , int nHeight
3953 , WXUINT WXUNUSED(nFlag)
3954 )
3955 {
3956 wxSizeEvent vEvent(wxSize(nWidth, nHeight), m_windowId);
3957
3958 vEvent.SetEventObject(this);
3959 return GetEventHandler()->ProcessEvent(vEvent);
3960 } // end of wxWindowOS2::HandleSize
3961
3962 bool wxWindowOS2::HandleGetMinMaxInfo(
3963 PSWP pSwp
3964 )
3965 {
3966 POINTL vPoint;
3967
3968 switch(pSwp->fl)
3969 {
3970 case SWP_MAXIMIZE:
3971 ::WinGetMaxPosition(GetHwnd(), pSwp);
3972 m_maxWidth = pSwp->cx;
3973 m_maxHeight = pSwp->cy;
3974 break;
3975
3976 case SWP_MINIMIZE:
3977 ::WinGetMinPosition(GetHwnd(), pSwp, &vPoint);
3978 m_minWidth = pSwp->cx;
3979 m_minHeight = pSwp->cy;
3980 break;
3981
3982 default:
3983 return FALSE;
3984 }
3985 return TRUE;
3986 } // end of wxWindowOS2::HandleGetMinMaxInfo
3987
3988 // ---------------------------------------------------------------------------
3989 // command messages
3990 // ---------------------------------------------------------------------------
3991 bool wxWindowOS2::HandleCommand(
3992 WXWORD wId
3993 , WXWORD wCmd
3994 , WXHWND hControl
3995 )
3996 {
3997 #if wxUSE_MENUS_NATIVE
3998 if (wxCurrentPopupMenu)
3999 {
4000 wxMenu* pPopupMenu = wxCurrentPopupMenu;
4001
4002 wxCurrentPopupMenu = NULL;
4003 return pPopupMenu->OS2Command(wCmd, wId);
4004 }
4005 #endif // wxUSE_MENUS_NATIVE
4006
4007 wxWindow* pWin = FindItem(wId);
4008
4009 if (!pWin)
4010 {
4011 pWin = wxFindWinFromHandle(hControl);
4012 }
4013
4014 if (pWin)
4015 return pWin->OS2Command(wCmd, wId);
4016
4017 return FALSE;
4018 } // end of wxWindowOS2::HandleCommand
4019
4020 bool wxWindowOS2::HandleSysCommand(
4021 WXWPARAM wParam
4022 , WXLPARAM WXUNUSED(lParam)
4023 )
4024 {
4025 //
4026 // 4 bits are reserved
4027 //
4028 switch (SHORT1FROMMP(wParam))
4029 {
4030 case SC_MAXIMIZE:
4031 return HandleMaximize();
4032
4033 case SC_MINIMIZE:
4034 return HandleMinimize();
4035 }
4036 return FALSE;
4037 } // end of wxWindowOS2::HandleSysCommand
4038
4039 // ---------------------------------------------------------------------------
4040 // mouse events
4041 // ---------------------------------------------------------------------------
4042 //TODO!!! check against MSW
4043 void wxWindowOS2::InitMouseEvent(
4044 wxMouseEvent& rEvent
4045 , int nX
4046 , int nY
4047 , WXUINT uFlags
4048 )
4049 {
4050 int nHeight;
4051 DoGetSize(0, &nHeight);
4052 rEvent.m_x = nX;
4053 // Convert to wxWidgets standard coordinate system!
4054 rEvent.m_y = nHeight - nY;
4055 rEvent.m_shiftDown = ((uFlags & KC_SHIFT) != 0);
4056 rEvent.m_controlDown = ((uFlags & KC_CTRL) != 0);
4057 rEvent.m_altDown = ((uFlags & KC_ALT) != 0);
4058 rEvent.m_leftDown = (::WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) &
4059 0x8000) != 0;
4060 rEvent.m_middleDown = (::WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) &
4061 0x8000) != 0;
4062 rEvent.m_rightDown = (::WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) &
4063 0x8000) != 0;
4064 rEvent.SetTimestamp(s_currentMsg.time);
4065 rEvent.m_eventObject = this;
4066 rEvent.SetId(GetId());
4067
4068 #if wxUSE_MOUSEEVENT_HACK
4069 m_lastMouseX = nX;
4070 m_lastMouseY = nY;
4071 m_lastMouseEvent = rEvent.GetEventType();
4072 #endif // wxUSE_MOUSEEVENT_HACK
4073 } // end of wxWindowOS2::InitMouseEvent
4074
4075 bool wxWindowOS2::HandleMouseEvent(
4076 WXUINT uMsg
4077 , int nX
4078 , int nY
4079 , WXUINT uFlags
4080 )
4081 {
4082 bool bProcessed = FALSE;
4083
4084 //
4085 // The mouse events take consecutive IDs from WM_MOUSEFIRST to
4086 // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST
4087 // from the message id and take the value in the table to get wxWin event
4088 // id
4089 //
4090 static const wxEventType eventsMouse[] =
4091 {
4092 wxEVT_MOTION,
4093 wxEVT_LEFT_DOWN,
4094 wxEVT_LEFT_UP,
4095 wxEVT_LEFT_DCLICK,
4096 wxEVT_RIGHT_DOWN,
4097 wxEVT_RIGHT_UP,
4098 wxEVT_RIGHT_DCLICK,
4099 wxEVT_MIDDLE_DOWN,
4100 wxEVT_MIDDLE_UP,
4101 wxEVT_MIDDLE_DCLICK
4102 };
4103
4104 wxMouseEvent vEvent(eventsMouse[uMsg - WM_MOUSEMOVE]);
4105
4106 InitMouseEvent( vEvent
4107 ,nX
4108 ,nY
4109 ,uFlags
4110 );
4111
4112 bProcessed = GetEventHandler()->ProcessEvent(vEvent);
4113 if (!bProcessed)
4114 {
4115 HPOINTER hCursor = (HPOINTER)GetCursor().GetHCURSOR();
4116
4117 if (hCursor != NULLHANDLE)
4118 {
4119 ::WinSetPointer(HWND_DESKTOP, hCursor);
4120 bProcessed = TRUE;
4121 }
4122 }
4123 return GetEventHandler()->ProcessEvent(vEvent);
4124 } // end of wxWindowOS2::HandleMouseEvent
4125
4126 bool wxWindowOS2::HandleMouseMove(
4127 int nX
4128 , int nY
4129 , WXUINT uFlags
4130 )
4131 {
4132 if (!m_bMouseInWindow)
4133 {
4134 //
4135 // Generate an ENTER event
4136 //
4137 m_bMouseInWindow = TRUE;
4138
4139 wxMouseEvent vEvent(wxEVT_ENTER_WINDOW);
4140
4141 InitMouseEvent( vEvent
4142 ,nX
4143 ,nY
4144 ,uFlags
4145 );
4146
4147 (void)GetEventHandler()->ProcessEvent(vEvent);
4148 }
4149 return HandleMouseEvent( WM_MOUSEMOVE
4150 ,nX
4151 ,nY
4152 ,uFlags
4153 );
4154 } // end of wxWindowOS2::HandleMouseMove
4155
4156 // ---------------------------------------------------------------------------
4157 // keyboard handling
4158 // ---------------------------------------------------------------------------
4159
4160 //
4161 // Create the key event of the given type for the given key - used by
4162 // HandleChar and HandleKeyDown/Up
4163 //
4164 wxKeyEvent wxWindowOS2::CreateKeyEvent(
4165 wxEventType eType
4166 , int nId
4167 , WXLPARAM lParam
4168 , WXWPARAM wParam
4169 ) const
4170 {
4171 wxKeyEvent vEvent(eType);
4172
4173 vEvent.SetId(GetId());
4174 vEvent.m_shiftDown = IsShiftDown();
4175 vEvent.m_controlDown = IsCtrlDown();
4176 vEvent.m_altDown = (HIWORD(lParam) & KC_ALT) == KC_ALT;
4177
4178 vEvent.m_eventObject = (wxWindow *)this; // const_cast
4179 vEvent.m_keyCode = nId;
4180 vEvent.m_rawCode = (wxUint32)wParam;
4181 vEvent.m_rawFlags = (wxUint32)lParam;
4182 vEvent.SetTimestamp(s_currentMsg.time);
4183
4184 //
4185 // Translate the position to client coords
4186 //
4187 POINTL vPoint;
4188 RECTL vRect;
4189
4190 ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
4191 ::WinQueryWindowRect( GetHwnd()
4192 ,&vRect
4193 );
4194
4195 vPoint.x -= vRect.xLeft;
4196 vPoint.y -= vRect.yBottom;
4197
4198 vEvent.m_x = vPoint.x;
4199 vEvent.m_y = vPoint.y;
4200
4201 return vEvent;
4202 } // end of wxWindowOS2::CreateKeyEvent
4203
4204 //
4205 // isASCII is TRUE only when we're called from WM_CHAR handler and not from
4206 // WM_KEYDOWN one
4207 //
4208 bool wxWindowOS2::HandleChar(
4209 WXWPARAM wParam
4210 , WXLPARAM lParam
4211 , bool isASCII
4212 )
4213 {
4214 bool bCtrlDown = FALSE;
4215 int vId;
4216
4217 if (m_bLastKeydownProcessed)
4218 {
4219 //
4220 // The key was handled in the EVT_KEY_DOWN. Handling a key in an
4221 // EVT_KEY_DOWN handler is meant, by design, to prevent EVT_CHARs
4222 // from happening, so just bail out at this point.
4223 //
4224 m_bLastKeydownProcessed = FALSE;
4225 return TRUE;
4226 }
4227 if (isASCII)
4228 {
4229 //
4230 // If 1 -> 26, translate to either special keycode or just set
4231 // ctrlDown. IOW, Ctrl-C should result in keycode == 3 and
4232 // ControlDown() == TRUE.
4233 //
4234 vId = SHORT1FROMMP(lParam);
4235 if ((vId > 0) && (vId < 27))
4236 {
4237 switch (vId)
4238 {
4239 case 13:
4240 vId = WXK_RETURN;
4241 break;
4242
4243 case 8:
4244 vId = WXK_BACK;
4245 break;
4246
4247 case 9:
4248 vId = WXK_TAB;
4249 break;
4250
4251 default:
4252 bCtrlDown = TRUE;
4253 break;
4254 }
4255 }
4256 }
4257 else // we're called from WM_KEYDOWN
4258 {
4259 vId = wxCharCodeOS2ToWX((int)SHORT2FROMMP(lParam));
4260 if (vId == 0)
4261 return FALSE;
4262 }
4263
4264 wxKeyEvent vEvent(CreateKeyEvent( wxEVT_CHAR
4265 ,vId
4266 ,lParam
4267 ));
4268
4269 if (bCtrlDown)
4270 {
4271 vEvent.m_controlDown = TRUE;
4272 }
4273 return (GetEventHandler()->ProcessEvent(vEvent));
4274 }
4275
4276 bool wxWindowOS2::HandleKeyDown(
4277 WXWPARAM wParam
4278 , WXLPARAM lParam
4279 )
4280 {
4281 int nId = wxCharCodeOS2ToWX((int)SHORT2FROMMP(lParam));
4282
4283 if (!nId)
4284 {
4285 //
4286 // Normal ASCII char
4287 //
4288 nId = SHORT1FROMMP(lParam);
4289 }
4290
4291 if (nId != -1)
4292 {
4293 wxKeyEvent vEvent(CreateKeyEvent( wxEVT_KEY_DOWN
4294 ,nId
4295 ,(MPARAM)lParam
4296 ,(MPARAM)wParam
4297 ));
4298
4299 if (GetEventHandler()->ProcessEvent(vEvent))
4300 {
4301 return TRUE;
4302 }
4303 }
4304 return FALSE;
4305 } // end of wxWindowOS2::HandleKeyDown
4306
4307 bool wxWindowOS2::HandleKeyUp(
4308 WXWPARAM wParam
4309 , WXLPARAM lParam
4310 )
4311 {
4312 int nId = wxCharCodeOS2ToWX((int)SHORT2FROMMP(lParam));
4313
4314 if (!nId)
4315 {
4316 //
4317 // Normal ASCII char
4318 //
4319 nId = (int)wParam;
4320 }
4321
4322 if (nId != -1)
4323 {
4324 wxKeyEvent vEvent(CreateKeyEvent( wxEVT_KEY_UP
4325 ,nId
4326 ,lParam
4327 ,wParam
4328 ));
4329
4330 if (GetEventHandler()->ProcessEvent(vEvent))
4331 return TRUE;
4332 }
4333 return FALSE;
4334 } // end of wxWindowOS2::HandleKeyUp
4335
4336 // ---------------------------------------------------------------------------
4337 // joystick
4338 // ---------------------------------------------------------------------------
4339
4340 // ---------------------------------------------------------------------------
4341 // scrolling
4342 // ---------------------------------------------------------------------------
4343
4344 bool wxWindowOS2::OS2OnScroll(
4345 int nOrientation
4346 , WXWORD wParam
4347 , WXWORD wPos
4348 , WXHWND hControl
4349 )
4350 {
4351 if (hControl)
4352 {
4353 wxWindow* pChild = wxFindWinFromHandle(hControl);
4354
4355 if (pChild )
4356 return pChild->OS2OnScroll( nOrientation
4357 ,wParam
4358 ,wPos
4359 ,hControl
4360 );
4361 }
4362
4363 wxScrollWinEvent vEvent;
4364
4365 vEvent.SetPosition(wPos);
4366 vEvent.SetOrientation(nOrientation);
4367 vEvent.m_eventObject = this;
4368
4369 switch (wParam)
4370 {
4371 case SB_LINEUP:
4372 vEvent.m_eventType = wxEVT_SCROLLWIN_LINEUP;
4373 break;
4374
4375 case SB_LINEDOWN:
4376 vEvent.m_eventType = wxEVT_SCROLLWIN_LINEDOWN;
4377 break;
4378
4379 case SB_PAGEUP:
4380 vEvent.m_eventType = wxEVT_SCROLLWIN_PAGEUP;
4381 break;
4382
4383 case SB_PAGEDOWN:
4384 vEvent.m_eventType = wxEVT_SCROLLWIN_PAGEDOWN;
4385 break;
4386
4387 case SB_SLIDERPOSITION:
4388 vEvent.m_eventType = wxEVT_SCROLLWIN_THUMBRELEASE;
4389 break;
4390
4391 case SB_SLIDERTRACK:
4392 vEvent.m_eventType = wxEVT_SCROLLWIN_THUMBTRACK;
4393 break;
4394
4395 default:
4396 return FALSE;
4397 }
4398 return GetEventHandler()->ProcessEvent(vEvent);
4399 } // end of wxWindowOS2::OS2OnScroll
4400
4401 void wxWindowOS2::MoveChildren(
4402 int nDiff
4403 )
4404 {
4405 //
4406 // We want to handle top levels ourself, manually
4407 //
4408 if (!IsTopLevel() && GetAutoLayout())
4409 {
4410 Layout();
4411 }
4412 else
4413 {
4414 SWP vSwp;
4415
4416 for (wxWindowList::Node* pNode = GetChildren().GetFirst();
4417 pNode;
4418 pNode = pNode->GetNext())
4419 {
4420 wxWindow* pWin = pNode->GetData();
4421
4422 ::WinQueryWindowPos( GetHwndOf(pWin)
4423 ,&vSwp
4424 );
4425 if (pWin->IsKindOf(CLASSINFO(wxControl)))
4426 {
4427 wxControl* pCtrl;
4428
4429 //
4430 // Must deal with controls that have margins like ENTRYFIELD. The SWP
4431 // struct of such a control will have and origin offset from its intended
4432 // position by the width of the margins.
4433 //
4434 pCtrl = wxDynamicCast(pWin, wxControl);
4435 vSwp.y -= pCtrl->GetYComp();
4436 vSwp.x -= pCtrl->GetXComp();
4437 }
4438 ::WinSetWindowPos( GetHwndOf(pWin)
4439 ,HWND_TOP
4440 ,vSwp.x
4441 ,vSwp.y - nDiff
4442 ,vSwp.cx
4443 ,vSwp.cy
4444 ,SWP_MOVE
4445 );
4446 ::WinQueryWindowPos(GetHwndOf(pWin), pWin->GetSwp());
4447 if (pWin->IsKindOf(CLASSINFO(wxRadioBox)))
4448 {
4449 wxRadioBox* pRadioBox;
4450
4451 pRadioBox = wxDynamicCast(pWin, wxRadioBox);
4452 pRadioBox->AdjustButtons( (int)vSwp.x
4453 ,(int)vSwp.y - nDiff
4454 ,(int)vSwp.cx
4455 ,(int)vSwp.cy
4456 ,pRadioBox->GetSizeFlags()
4457 );
4458 }
4459 if (pWin->IsKindOf(CLASSINFO(wxSlider)))
4460 {
4461 wxSlider* pSlider;
4462
4463 pSlider = wxDynamicCast(pWin, wxSlider);
4464 pSlider->AdjustSubControls( (int)vSwp.x
4465 ,(int)vSwp.y - nDiff
4466 ,(int)vSwp.cx
4467 ,(int)vSwp.cy
4468 ,(int)pSlider->GetSizeFlags()
4469 );
4470 }
4471 }
4472 }
4473 Refresh();
4474 } // end of wxWindowOS2::MoveChildren
4475
4476 //
4477 // Getting the Y position for a window, like a control, is a real
4478 // pain. There are three sitatuions we must deal with in determining
4479 // the OS2 to wxWidgets Y coordinate.
4480 //
4481 // 1) The controls are created in a dialog.
4482 // This is the easiest since a dialog is created with its original
4483 // size so the standard: Y = ParentHeight - (Y + ControlHeight);
4484 //
4485 // 2) The controls are direct children of a frame
4486 // In this instance the controls are actually children of the Frame's
4487 // client. During creation the frame's client resizes several times
4488 // during creation of the status bar and toolbars. The CFrame class
4489 // will take care of this using its AlterChildPos proc.
4490 //
4491 // 3) The controls are children of a panel, which in turn is a child of
4492 // a frame.
4493 // The panel may be one of many, in which case the same treatment
4494 // as 1 applies. It may be the only child, though.
4495 // This is the nastiest case. A panel is created as the only child of
4496 // the frame and as such, when a frame has only one child, the child is
4497 // expanded to fit the entire client area of the frame. Because the
4498 // controls are created BEFORE this occurs their positions are totally
4499 // whacked and any call to WinQueryWindowPos will return invalid
4500 // coordinates. So for this situation we have to compare the size of
4501 // the panel at control creation time with that of the frame client. If
4502 // they are the same we can use the standard Y position equation. If
4503 // not, then we must use the Frame Client's dimensions to position them
4504 // as that will be the eventual size of the panel after the frame resizes
4505 // it!
4506 //
4507 int wxWindowOS2::GetOS2ParentHeight(
4508 wxWindowOS2* pParent
4509 )
4510 {
4511 //
4512 // Case 1
4513 //
4514 if (pParent->IsKindOf(CLASSINFO(wxDialog)))
4515 return(pParent->GetClientSize().y);
4516
4517 //
4518 // Case 2 -- if we are one of the separately built standard Frame
4519 // children, like a statusbar, menubar, or toolbar we want to
4520 // use the frame, itself, for positioning. Otherwise we are
4521 // child window and want to use the Frame's client.
4522 //
4523 else if (pParent->IsKindOf(CLASSINFO(wxFrame)))
4524 {
4525 if (IsKindOf(CLASSINFO(wxStatusBar)) ||
4526 IsKindOf(CLASSINFO(wxMenuBar)) ||
4527 IsKindOf(CLASSINFO(wxToolBar))
4528 )
4529 {
4530 if (IsKindOf(CLASSINFO(wxToolBar)))
4531 {
4532 wxFrame* pFrame = wxDynamicCast(GetParent(), wxFrame);
4533
4534 if (pFrame->GetToolBar() == this)
4535 return(pParent->GetSize().y);
4536 else
4537 return(pParent->GetClientSize().y);
4538 }
4539 else
4540 return(pParent->GetSize().y);
4541 }
4542 else
4543 return(pParent->GetClientSize().y);
4544 }
4545 //
4546 // Case -- this is for any window that is the sole child of a Frame.
4547 // The grandparent must exist and it must be of type CFrame
4548 // and it's height must be different. Otherwise the standard
4549 // applies.
4550 //
4551 else
4552 {
4553 return(pParent->GetClientSize().y);
4554 }
4555 return(0L);
4556 } // end of wxWindowOS2::GetOS2ParentHeight
4557
4558 //
4559 // OS/2 needs a lot extra manipulation to deal with layouts
4560 // for canvas windows, particularly scrolled ones.
4561 //
4562 wxWindowCreationHook::wxWindowCreationHook(
4563 wxWindow* pWinBeingCreated
4564 )
4565 {
4566 gpWinBeingCreated = pWinBeingCreated;
4567 } // end of wxWindowCreationHook::wxWindowCreationHook
4568
4569 wxWindowCreationHook::~wxWindowCreationHook()
4570 {
4571 gpWinBeingCreated = NULL;
4572 } // end of wxWindowCreationHook::~wxWindowCreationHook
4573
4574 // ===========================================================================
4575 // global functions
4576 // ===========================================================================
4577
4578 void wxGetCharSize(
4579 WXHWND hWnd
4580 , int* pX
4581 , int* pY
4582 ,wxFont* WXUNUSED(pTheFont)
4583 )
4584 {
4585 FONTMETRICS vFM;
4586 HPS hPS;
4587 BOOL rc;
4588
4589 hPS =::WinGetPS(hWnd);
4590
4591 rc = ::GpiQueryFontMetrics(hPS, sizeof(FONTMETRICS), &vFM);
4592 if (rc)
4593 {
4594 if (pX)
4595 *pX = vFM.lAveCharWidth;
4596 if (pY)
4597 *pY = vFM.lEmHeight + vFM.lExternalLeading;
4598 }
4599 else
4600 {
4601 if (pX)
4602 *pX = 10;
4603 if (pY)
4604 *pY = 15;
4605 }
4606 ::WinReleasePS(hPS);
4607 } // end of wxGetCharSize
4608
4609 //
4610 // Returns 0 if was a normal ASCII value, not a special key. This indicates that
4611 // the key should be ignored by WM_KEYDOWN and processed by WM_CHAR instead.
4612 //
4613 int wxCharCodeOS2ToWX(
4614 int nKeySym
4615 )
4616 {
4617 int nId = 0;
4618
4619 switch (nKeySym)
4620 {
4621 case VK_BACKTAB: nId = WXK_BACK; break;
4622 case VK_TAB: nId = WXK_TAB; break;
4623 case VK_CLEAR: nId = WXK_CLEAR; break;
4624 case VK_ENTER: nId = WXK_RETURN; break;
4625 case VK_SHIFT: nId = WXK_SHIFT; break;
4626 case VK_CTRL: nId = WXK_CONTROL; break;
4627 case VK_PAUSE: nId = WXK_PAUSE; break;
4628 case VK_SPACE: nId = WXK_SPACE; break;
4629 case VK_ESC: nId = WXK_ESCAPE; break;
4630 case VK_END: nId = WXK_END; break;
4631 case VK_HOME : nId = WXK_HOME; break;
4632 case VK_LEFT : nId = WXK_LEFT; break;
4633 case VK_UP: nId = WXK_UP; break;
4634 case VK_RIGHT: nId = WXK_RIGHT; break;
4635 case VK_DOWN : nId = WXK_DOWN; break;
4636 case VK_PRINTSCRN: nId = WXK_PRINT; break;
4637 case VK_INSERT: nId = WXK_INSERT; break;
4638 case VK_DELETE: nId = WXK_DELETE; break;
4639 case VK_CAPSLOCK: nId = WXK_CAPITAL; break;
4640 case VK_F1: nId = WXK_F1; break;
4641 case VK_F2: nId = WXK_F2; break;
4642 case VK_F3: nId = WXK_F3; break;
4643 case VK_F4: nId = WXK_F4; break;
4644 case VK_F5: nId = WXK_F5; break;
4645 case VK_F6: nId = WXK_F6; break;
4646 case VK_F7: nId = WXK_F7; break;
4647 case VK_F8: nId = WXK_F8; break;
4648 case VK_F9: nId = WXK_F9; break;
4649 case VK_F10: nId = WXK_F10; break;
4650 case VK_F11: nId = WXK_F11; break;
4651 case VK_F12: nId = WXK_F12; break;
4652 case VK_F13: nId = WXK_F13; break;
4653 case VK_F14: nId = WXK_F14; break;
4654 case VK_F15: nId = WXK_F15; break;
4655 case VK_F16: nId = WXK_F16; break;
4656 case VK_F17: nId = WXK_F17; break;
4657 case VK_F18: nId = WXK_F18; break;
4658 case VK_F19: nId = WXK_F19; break;
4659 case VK_F20: nId = WXK_F20; break;
4660 case VK_F21: nId = WXK_F21; break;
4661 case VK_F22: nId = WXK_F22; break;
4662 case VK_F23: nId = WXK_F23; break;
4663 case VK_F24: nId = WXK_F24; break;
4664 case VK_OEM_1: nId = ';'; break;
4665 case VK_OEM_PLUS: nId = '+'; break;
4666 case VK_OEM_COMMA: nId = ','; break;
4667 case VK_OEM_MINUS: nId = '-'; break;
4668 case VK_OEM_PERIOD: nId = '.'; break;
4669 case VK_OEM_2: nId = '/'; break;
4670 case VK_OEM_3: nId = '~'; break;
4671 case VK_OEM_4: nId = '['; break;
4672 case VK_OEM_5: nId = '\\'; break;
4673 case VK_OEM_6: nId = ']'; break;
4674 case VK_OEM_7: nId = '\''; break;
4675 case VK_NUMLOCK: nId = WXK_NUMLOCK; break;
4676 case VK_SCRLLOCK: nId = WXK_SCROLL; break;
4677 default:
4678 {
4679 return 0;
4680 }
4681 }
4682 return nId;
4683 } // end of wxCharCodeOS2ToWX
4684
4685 int wxCharCodeWXToOS2(
4686 int nId
4687 , bool* bIsVirtual
4688 )
4689 {
4690 int nKeySym = 0;
4691
4692 *bIsVirtual = TRUE;
4693 switch (nId)
4694 {
4695 case WXK_CLEAR: nKeySym = VK_CLEAR; break;
4696 case WXK_SHIFT: nKeySym = VK_SHIFT; break;
4697 case WXK_CONTROL: nKeySym = VK_CTRL; break;
4698 case WXK_PAUSE: nKeySym = VK_PAUSE; break;
4699 case WXK_END: nKeySym = VK_END; break;
4700 case WXK_HOME : nKeySym = VK_HOME; break;
4701 case WXK_LEFT : nKeySym = VK_LEFT; break;
4702 case WXK_UP: nKeySym = VK_UP; break;
4703 case WXK_RIGHT: nKeySym = VK_RIGHT; break;
4704 case WXK_DOWN : nKeySym = VK_DOWN; break;
4705 case WXK_PRINT: nKeySym = VK_PRINTSCRN; break;
4706 case WXK_INSERT: nKeySym = VK_INSERT; break;
4707 case WXK_DELETE: nKeySym = VK_DELETE; break;
4708 case WXK_F1: nKeySym = VK_F1; break;
4709 case WXK_F2: nKeySym = VK_F2; break;
4710 case WXK_F3: nKeySym = VK_F3; break;
4711 case WXK_F4: nKeySym = VK_F4; break;
4712 case WXK_F5: nKeySym = VK_F5; break;
4713 case WXK_F6: nKeySym = VK_F6; break;
4714 case WXK_F7: nKeySym = VK_F7; break;
4715 case WXK_F8: nKeySym = VK_F8; break;
4716 case WXK_F9: nKeySym = VK_F9; break;
4717 case WXK_F10: nKeySym = VK_F10; break;
4718 case WXK_F11: nKeySym = VK_F11; break;
4719 case WXK_F12: nKeySym = VK_F12; break;
4720 case WXK_F13: nKeySym = VK_F13; break;
4721 case WXK_F14: nKeySym = VK_F14; break;
4722 case WXK_F15: nKeySym = VK_F15; break;
4723 case WXK_F16: nKeySym = VK_F16; break;
4724 case WXK_F17: nKeySym = VK_F17; break;
4725 case WXK_F18: nKeySym = VK_F18; break;
4726 case WXK_F19: nKeySym = VK_F19; break;
4727 case WXK_F20: nKeySym = VK_F20; break;
4728 case WXK_F21: nKeySym = VK_F21; break;
4729 case WXK_F22: nKeySym = VK_F22; break;
4730 case WXK_F23: nKeySym = VK_F23; break;
4731 case WXK_F24: nKeySym = VK_F24; break;
4732 case WXK_NUMLOCK: nKeySym = VK_NUMLOCK; break;
4733 case WXK_SCROLL: nKeySym = VK_SCRLLOCK; break;
4734 default:
4735 {
4736 *bIsVirtual = FALSE;
4737 nKeySym = nId;
4738 break;
4739 }
4740 }
4741 return nKeySym;
4742 } // end of wxCharCodeWXToOS2
4743
4744 wxWindow* wxGetActiveWindow()
4745 {
4746 HWND hWnd = ::WinQueryActiveWindow(HWND_DESKTOP);
4747
4748 if (hWnd != 0)
4749 {
4750 return wxFindWinFromHandle((WXHWND)hWnd);
4751 }
4752 return NULL;
4753 } // end of wxGetActiveWindow
4754
4755 #ifdef __WXDEBUG__
4756 const char* wxGetMessageName(
4757 int nMessage)
4758 {
4759 switch (nMessage)
4760 {
4761 case 0x0000: return "WM_NULL";
4762 case 0x0001: return "WM_CREATE";
4763 case 0x0002: return "WM_DESTROY";
4764 case 0x0004: return "WM_ENABLE";
4765 case 0x0005: return "WM_SHOW";
4766 case 0x0006: return "WM_MOVE";
4767 case 0x0007: return "WM_SIZE";
4768 case 0x0008: return "WM_ADJUSTWINDOWPOS";
4769 case 0x0009: return "WM_CALCVALIDRECTS";
4770 case 0x000A: return "WM_SETWINDOWPARAMS";
4771 case 0x000B: return "WM_QUERYWINDOWPARAMS";
4772 case 0x000C: return "WM_HITTEST";
4773 case 0x000D: return "WM_ACTIVATE";
4774 case 0x000F: return "WM_SETFOCUS";
4775 case 0x0010: return "WM_SETSELECTION";
4776 case 0x0011: return "WM_PPAINT";
4777 case 0x0012: return "WM_PSETFOCUS";
4778 case 0x0013: return "WM_PSYSCOLORCHANGE";
4779 case 0x0014: return "WM_PSIZE";
4780 case 0x0015: return "WM_PACTIVATE";
4781 case 0x0016: return "WM_PCONTROL";
4782 case 0x0020: return "WM_COMMAND";
4783 case 0x0021: return "WM_SYSCOMMAND";
4784 case 0x0022: return "WM_HELP";
4785 case 0x0023: return "WM_PAINT";
4786 case 0x0024: return "WM_TIMER";
4787 case 0x0025: return "WM_SEM1";
4788 case 0x0026: return "WM_SEM2";
4789 case 0x0027: return "WM_SEM3";
4790 case 0x0028: return "WM_SEM4";
4791 case 0x0029: return "WM_CLOSE";
4792 case 0x002A: return "WM_QUIT";
4793 case 0x002B: return "WM_SYSCOLORCHANGE";
4794 case 0x002D: return "WM_SYSVALUECHANGE";
4795 case 0x002E: return "WM_APPTERMINATENOTIFY";
4796 case 0x002F: return "WM_PRESPARAMCHANGED";
4797 // Control notification messages
4798 case 0x0030: return "WM_CONTROL";
4799 case 0x0031: return "WM_VSCROLL";
4800 case 0x0032: return "WM_HSCROLL";
4801 case 0x0033: return "WM_INITMENU";
4802 case 0x0034: return "WM_MENUSELECT";
4803 case 0x0035: return "WM_MENUSEND";
4804 case 0x0036: return "WM_DRAWITEM";
4805 case 0x0037: return "WM_MEASUREITEM";
4806 case 0x0038: return "WM_CONTROLPOINTER";
4807 case 0x003A: return "WM_QUERYDLGCODE";
4808 case 0x003B: return "WM_INITDLG";
4809 case 0x003C: return "WM_SUBSTITUTESTRING";
4810 case 0x003D: return "WM_MATCHMNEMONIC";
4811 case 0x003E: return "WM_SAVEAPPLICATION";
4812 case 0x0129: return "WM_CTLCOLORCHANGE";
4813 case 0x0130: return "WM_QUERYCTLTYPE";
4814 // Frame messages
4815 case 0x0040: return "WM_FLASHWINDOW";
4816 case 0x0041: return "WM_FORMATFRAME";
4817 case 0x0042: return "WM_UPDATEFRAME";
4818 case 0x0043: return "WM_FOCUSCHANGE";
4819 case 0x0044: return "WM_SETBORDERSIZE";
4820 case 0x0045: return "WM_TRACKFRAME";
4821 case 0x0046: return "WM_MINMAXFRAME";
4822 case 0x0047: return "WM_SETICON";
4823 case 0x0048: return "WM_QUERYICON";
4824 case 0x0049: return "WM_SETACCELTABLE";
4825 case 0x004A: return "WM_QUERYACCELTABLE";
4826 case 0x004B: return "WM_TRANSLATEACCEL";
4827 case 0x004C: return "WM_QUERYTRACKINFO";
4828 case 0x004D: return "WM_QUERYBORDERSIZE";
4829 case 0x004E: return "WM_NEXTMENU";
4830 case 0x004F: return "WM_ERASEBACKGROUND";
4831 case 0x0050: return "WM_QUERYFRAMEINFO";
4832 case 0x0051: return "WM_QUERYFOCUSCHAIN";
4833 case 0x0052: return "WM_OWNERPOSCHANGE";
4834 case 0x0053: return "WM_CACLFRAMERECT";
4835 case 0x0055: return "WM_WINDOWPOSCHANGED";
4836 case 0x0056: return "WM_ADJUSTFRAMEPOS";
4837 case 0x0059: return "WM_QUERYFRAMECTLCOUNT";
4838 case 0x005B: return "WM_QUERYHELPINFO";
4839 case 0x005C: return "WM_SETHELPINFO";
4840 case 0x005D: return "WM_ERROR";
4841 case 0x005E: return "WM_REALIZEPALETTE";
4842 // Clipboard messages
4843 case 0x0060: return "WM_RENDERFMT";
4844 case 0x0061: return "WM_RENDERALLFMTS";
4845 case 0x0062: return "WM_DESTROYCLIPBOARD";
4846 case 0x0063: return "WM_PAINTCLIPBOARD";
4847 case 0x0064: return "WM_SIZECLIPBOARD";
4848 case 0x0065: return "WM_HSCROLLCLIPBOARD";
4849 case 0x0066: return "WM_VSCROLLCLIPBOARD";
4850 case 0x0067: return "WM_DRAWCLIPBOARD";
4851 // mouse messages
4852 case 0x0070: return "WM_MOUSEMOVE";
4853 case 0x0071: return "WM_BUTTON1DOWN";
4854 case 0x0072: return "WM_BUTTON1UP";
4855 case 0x0073: return "WM_BUTTON1DBLCLK";
4856 case 0x0074: return "WM_BUTTON2DOWN";
4857 case 0x0075: return "WM_BUTTON2UP";
4858 case 0x0076: return "WM_BUTTON2DBLCLK";
4859 case 0x0077: return "WM_BUTTON3DOWN";
4860 case 0x0078: return "WM_BUTTON3UP";
4861 case 0x0079: return "WM_BUTTON3DBLCLK";
4862 case 0x007D: return "WM_MOUSEMAP";
4863 case 0x007E: return "WM_VRNDISABLED";
4864 case 0x007F: return "WM_VRNENABLED";
4865 case 0x0410: return "WM_CHORD";
4866 case 0x0411: return "WM_BUTTON1MOTIONSTART";
4867 case 0x0412: return "WM_BUTTON1MOTIONEND";
4868 case 0x0413: return "WM_BUTTON1CLICK";
4869 case 0x0414: return "WM_BUTTON2MOTIONSTART";
4870 case 0x0415: return "WM_BUTTON2MOTIONEND";
4871 case 0x0416: return "WM_BUTTON2CLICK";
4872 case 0x0417: return "WM_BUTTON3MOTIONSTART";
4873 case 0x0418: return "WM_BUTTON3MOTIONEND";
4874 case 0x0419: return "WM_BUTTON3CLICK";
4875 case 0x0420: return "WM_BEGINDRAG";
4876 case 0x0421: return "WM_ENDDRAG";
4877 case 0x0422: return "WM_SINGLESELECT";
4878 case 0x0423: return "WM_OPEN";
4879 case 0x0424: return "WM_CONTEXTMENU";
4880 case 0x0425: return "WM_CONTEXTHELP";
4881 case 0x0426: return "WM_TEXTEDIT";
4882 case 0x0427: return "WM_BEGINSELECT";
4883 case 0x0228: return "WM_ENDSELECT";
4884 case 0x0429: return "WM_PICKUP";
4885 case 0x04C0: return "WM_PENFIRST";
4886 case 0x04FF: return "WM_PENLAST";
4887 case 0x0500: return "WM_MMPMFIRST";
4888 case 0x05FF: return "WM_MMPMLAST";
4889 case 0x0600: return "WM_STDDLGFIRST";
4890 case 0x06FF: return "WM_STDDLGLAST";
4891 case 0x0BD0: return "WM_BIDI_FIRST";
4892 case 0x0BFF: return "WM_BIDI_LAST";
4893 // keyboard input
4894 case 0x007A: return "WM_CHAR";
4895 case 0x007B: return "WM_VIOCHAR";
4896 // DDE messages
4897 case 0x00A0: return "WM_DDE_INITIATE";
4898 case 0x00A1: return "WM_DDE_REQUEST";
4899 case 0x00A2: return "WM_DDE_ACK";
4900 case 0x00A3: return "WM_DDE_DATA";
4901 case 0x00A4: return "WM_DDE_ADVISE";
4902 case 0x00A5: return "WM_DDE_UNADVISE";
4903 case 0x00A6: return "WM_DDE_POKE";
4904 case 0x00A7: return "WM_DDE_EXECUTE";
4905 case 0x00A8: return "WM_DDE_TERMINATE";
4906 case 0x00A9: return "WM_DDE_INITIATEACK";
4907 case 0x00AF: return "WM_DDE_LAST";
4908 // Buttons
4909 case 0x0120: return "BM_CLICK";
4910 case 0x0121: return "BM_QUERYCHECKINDEX";
4911 case 0x0122: return "BM_QUERYHILITE";
4912 case 0x0123: return "BM_SETHILITE";
4913 case 0x0124: return "BM_QUERYCHECK";
4914 case 0x0125: return "BM_SETCHECK";
4915 case 0x0126: return "BM_SETDEFAULT";
4916 case 0x0128: return "BM_AUTOSIZE";
4917 // Combo boxes
4918 case 0x029A: return "CBID_LIST";
4919 case 0x029B: return "CBID_EDIT";
4920 case 0x0170: return "CBM_SHOWLIST";
4921 case 0x0171: return "CBM_HILITE";
4922 case 0x0172: return "CBM_ISLISTSHOWING";
4923 // Edit fields
4924 case 0x0140: return "EM_QUERYCHANGED";
4925 case 0x0141: return "EM_QUERYSEL";
4926 case 0x0142: return "EM_SETSEL";
4927 case 0x0143: return "EM_SETTEXTLIMIT";
4928 case 0x0144: return "EM_CUT";
4929 case 0x0145: return "EM_COPY";
4930 case 0x0146: return "EM_CLEAR";
4931 case 0x0147: return "EM_PASTE";
4932 case 0x0148: return "EM_QUERYFIRSTCHAR";
4933 case 0x0149: return "EM_SETFIRSTCHAR";
4934 case 0x014A: return "EM_QUERYREADONLY";
4935 case 0x014B: return "EM_SETREADONLY";
4936 case 0x014C: return "EM_SETINSERTMODE";
4937 // Listboxes
4938 case 0x0160: return "LM_QUERYITEMCOUNT";
4939 case 0x0161: return "LM_INSERTITEM";
4940 case 0x0162: return "LM_SETOPENINDEX";
4941 case 0x0163: return "LM_DELETEITEM";
4942 case 0x0164: return "LM_SELECTITEM";
4943 case 0x0165: return "LM_QUERYSELECTION";
4944 case 0x0166: return "LM_SETITEMTEXT";
4945 case 0x0167: return "LM_QUERYITEMTEXTLENGTH";
4946 case 0x0168: return "LM_QUERYITEMTEXT";
4947 case 0x0169: return "LM_SETITEMHANDLE";
4948 case 0x016A: return "LM_QUERYITEMHANDLE";
4949 case 0x016B: return "LM_SEARCHSTRING";
4950 case 0x016C: return "LM_SETITEMHEIGHT";
4951 case 0x016D: return "LM_QUERYTOPINDEX";
4952 case 0x016E: return "LM_DELETEALL";
4953 case 0x016F: return "LM_INSERTMULITEMS";
4954 case 0x0660: return "LM_SETITEMWIDTH";
4955 // Menus
4956 case 0x0180: return "MM_INSERTITEM";
4957 case 0x0181: return "MM_DELETEITEM";
4958 case 0x0182: return "MM_QUERYITEM";
4959 case 0x0183: return "MM_SETITEM";
4960 case 0x0184: return "MM_QUERYITEMCOUNT";
4961 case 0x0185: return "MM_STARTMENUMODE";
4962 case 0x0186: return "MM_ENDMENUMODE";
4963 case 0x0188: return "MM_REMOVEITEM";
4964 case 0x0189: return "MM_SELECTITEM";
4965 case 0x018A: return "MM_QUERYSELITEMID";
4966 case 0x018B: return "MM_QUERYITEMTEXT";
4967 case 0x018C: return "MM_QUERYITEMTEXTLENGTH";
4968 case 0x018D: return "MM_SETITEMHANDLE";
4969 case 0x018E: return "MM_SETITEMTEXT";
4970 case 0x018F: return "MM_ITEMPOSITIONFROMID";
4971 case 0x0190: return "MM_ITEMIDFROMPOSITION";
4972 case 0x0191: return "MM_QUERYITEMATTR";
4973 case 0x0192: return "MM_SETITEMATTR";
4974 case 0x0193: return "MM_ISITEMVALID";
4975 case 0x0194: return "MM_QUERYITEMRECT";
4976 case 0x0431: return "MM_QUERYDEFAULTITEMID";
4977 case 0x0432: return "MM_SETDEFAULTITEMID";
4978 // Scrollbars
4979 case 0x01A0: return "SBM_SETSCROLLBAR";
4980 case 0x01A1: return "SBM_SETPOS";
4981 case 0x01A2: return "SBM_QUERYPOS";
4982 case 0x01A3: return "SBM_QUERYRANGE";
4983 case 0x01A6: return "SBM_SETTHUMBSIZE";
4984
4985 // Help messages
4986 case 0x0F00: return "WM_HELPBASE";
4987 case 0x0FFF: return "WM_HELPTOP";
4988 // Beginning of user defined messages
4989 case 0x1000: return "WM_USER";
4990
4991 // wxWidgets user defined types
4992
4993 // listview
4994 // case 0x1000 + 0: return "LVM_GETBKCOLOR";
4995 case 0x1000 + 1: return "LVM_SETBKCOLOR";
4996 case 0x1000 + 2: return "LVM_GETIMAGELIST";
4997 case 0x1000 + 3: return "LVM_SETIMAGELIST";
4998 case 0x1000 + 4: return "LVM_GETITEMCOUNT";
4999 case 0x1000 + 5: return "LVM_GETITEMA";
5000 case 0x1000 + 75: return "LVM_GETITEMW";
5001 case 0x1000 + 6: return "LVM_SETITEMA";
5002 case 0x1000 + 76: return "LVM_SETITEMW";
5003 case 0x1000 + 7: return "LVM_INSERTITEMA";
5004 case 0x1000 + 77: return "LVM_INSERTITEMW";
5005 case 0x1000 + 8: return "LVM_DELETEITEM";
5006 case 0x1000 + 9: return "LVM_DELETEALLITEMS";
5007 case 0x1000 + 10: return "LVM_GETCALLBACKMASK";
5008 case 0x1000 + 11: return "LVM_SETCALLBACKMASK";
5009 case 0x1000 + 12: return "LVM_GETNEXTITEM";
5010 case 0x1000 + 13: return "LVM_FINDITEMA";
5011 case 0x1000 + 83: return "LVM_FINDITEMW";
5012 case 0x1000 + 14: return "LVM_GETITEMRECT";
5013 case 0x1000 + 15: return "LVM_SETITEMPOSITION";
5014 case 0x1000 + 16: return "LVM_GETITEMPOSITION";
5015 case 0x1000 + 17: return "LVM_GETSTRINGWIDTHA";
5016 case 0x1000 + 87: return "LVM_GETSTRINGWIDTHW";
5017 case 0x1000 + 18: return "LVM_HITTEST";
5018 case 0x1000 + 19: return "LVM_ENSUREVISIBLE";
5019 case 0x1000 + 20: return "LVM_SCROLL";
5020 case 0x1000 + 21: return "LVM_REDRAWITEMS";
5021 case 0x1000 + 22: return "LVM_ARRANGE";
5022 case 0x1000 + 23: return "LVM_EDITLABELA";
5023 case 0x1000 + 118: return "LVM_EDITLABELW";
5024 case 0x1000 + 24: return "LVM_GETEDITCONTROL";
5025 case 0x1000 + 25: return "LVM_GETCOLUMNA";
5026 case 0x1000 + 95: return "LVM_GETCOLUMNW";
5027 case 0x1000 + 26: return "LVM_SETCOLUMNA";
5028 case 0x1000 + 96: return "LVM_SETCOLUMNW";
5029 case 0x1000 + 27: return "LVM_INSERTCOLUMNA";
5030 case 0x1000 + 97: return "LVM_INSERTCOLUMNW";
5031 case 0x1000 + 28: return "LVM_DELETECOLUMN";
5032 case 0x1000 + 29: return "LVM_GETCOLUMNWIDTH";
5033 case 0x1000 + 30: return "LVM_SETCOLUMNWIDTH";
5034 case 0x1000 + 31: return "LVM_GETHEADER";
5035 case 0x1000 + 33: return "LVM_CREATEDRAGIMAGE";
5036 case 0x1000 + 34: return "LVM_GETVIEWRECT";
5037 case 0x1000 + 35: return "LVM_GETTEXTCOLOR";
5038 case 0x1000 + 36: return "LVM_SETTEXTCOLOR";
5039 case 0x1000 + 37: return "LVM_GETTEXTBKCOLOR";
5040 case 0x1000 + 38: return "LVM_SETTEXTBKCOLOR";
5041 case 0x1000 + 39: return "LVM_GETTOPINDEX";
5042 case 0x1000 + 40: return "LVM_GETCOUNTPERPAGE";
5043 case 0x1000 + 41: return "LVM_GETORIGIN";
5044 case 0x1000 + 42: return "LVM_UPDATE";
5045 case 0x1000 + 43: return "LVM_SETITEMSTATE";
5046 case 0x1000 + 44: return "LVM_GETITEMSTATE";
5047 case 0x1000 + 45: return "LVM_GETITEMTEXTA";
5048 case 0x1000 + 115: return "LVM_GETITEMTEXTW";
5049 case 0x1000 + 46: return "LVM_SETITEMTEXTA";
5050 case 0x1000 + 116: return "LVM_SETITEMTEXTW";
5051 case 0x1000 + 47: return "LVM_SETITEMCOUNT";
5052 case 0x1000 + 48: return "LVM_SORTITEMS";
5053 case 0x1000 + 49: return "LVM_SETITEMPOSITION32";
5054 case 0x1000 + 50: return "LVM_GETSELECTEDCOUNT";
5055 case 0x1000 + 51: return "LVM_GETITEMSPACING";
5056 case 0x1000 + 52: return "LVM_GETISEARCHSTRINGA";
5057 case 0x1000 + 117: return "LVM_GETISEARCHSTRINGW";
5058 case 0x1000 + 53: return "LVM_SETICONSPACING";
5059 case 0x1000 + 54: return "LVM_SETEXTENDEDLISTVIEWSTYLE";
5060 case 0x1000 + 55: return "LVM_GETEXTENDEDLISTVIEWSTYLE";
5061 case 0x1000 + 56: return "LVM_GETSUBITEMRECT";
5062 case 0x1000 + 57: return "LVM_SUBITEMHITTEST";
5063 case 0x1000 + 58: return "LVM_SETCOLUMNORDERARRAY";
5064 case 0x1000 + 59: return "LVM_GETCOLUMNORDERARRAY";
5065 case 0x1000 + 60: return "LVM_SETHOTITEM";
5066 case 0x1000 + 61: return "LVM_GETHOTITEM";
5067 case 0x1000 + 62: return "LVM_SETHOTCURSOR";
5068 case 0x1000 + 63: return "LVM_GETHOTCURSOR";
5069 case 0x1000 + 64: return "LVM_APPROXIMATEVIEWRECT";
5070 case 0x1000 + 65: return "LVM_SETWORKAREA";
5071
5072 // tree view
5073 case 0x1100 + 0: return "TVM_INSERTITEMA";
5074 case 0x1100 + 50: return "TVM_INSERTITEMW";
5075 case 0x1100 + 1: return "TVM_DELETEITEM";
5076 case 0x1100 + 2: return "TVM_EXPAND";
5077 case 0x1100 + 4: return "TVM_GETITEMRECT";
5078 case 0x1100 + 5: return "TVM_GETCOUNT";
5079 case 0x1100 + 6: return "TVM_GETINDENT";
5080 case 0x1100 + 7: return "TVM_SETINDENT";
5081 case 0x1100 + 8: return "TVM_GETIMAGELIST";
5082 case 0x1100 + 9: return "TVM_SETIMAGELIST";
5083 case 0x1100 + 10: return "TVM_GETNEXTITEM";
5084 case 0x1100 + 11: return "TVM_SELECTITEM";
5085 case 0x1100 + 12: return "TVM_GETITEMA";
5086 case 0x1100 + 62: return "TVM_GETITEMW";
5087 case 0x1100 + 13: return "TVM_SETITEMA";
5088 case 0x1100 + 63: return "TVM_SETITEMW";
5089 case 0x1100 + 14: return "TVM_EDITLABELA";
5090 case 0x1100 + 65: return "TVM_EDITLABELW";
5091 case 0x1100 + 15: return "TVM_GETEDITCONTROL";
5092 case 0x1100 + 16: return "TVM_GETVISIBLECOUNT";
5093 case 0x1100 + 17: return "TVM_HITTEST";
5094 case 0x1100 + 18: return "TVM_CREATEDRAGIMAGE";
5095 case 0x1100 + 19: return "TVM_SORTCHILDREN";
5096 case 0x1100 + 20: return "TVM_ENSUREVISIBLE";
5097 case 0x1100 + 21: return "TVM_SORTCHILDRENCB";
5098 case 0x1100 + 22: return "TVM_ENDEDITLABELNOW";
5099 case 0x1100 + 23: return "TVM_GETISEARCHSTRINGA";
5100 case 0x1100 + 64: return "TVM_GETISEARCHSTRINGW";
5101 case 0x1100 + 24: return "TVM_SETTOOLTIPS";
5102 case 0x1100 + 25: return "TVM_GETTOOLTIPS";
5103
5104 // header
5105 case 0x1200 + 0: return "HDM_GETITEMCOUNT";
5106 case 0x1200 + 1: return "HDM_INSERTITEMA";
5107 case 0x1200 + 10: return "HDM_INSERTITEMW";
5108 case 0x1200 + 2: return "HDM_DELETEITEM";
5109 case 0x1200 + 3: return "HDM_GETITEMA";
5110 case 0x1200 + 11: return "HDM_GETITEMW";
5111 case 0x1200 + 4: return "HDM_SETITEMA";
5112 case 0x1200 + 12: return "HDM_SETITEMW";
5113 case 0x1200 + 5: return "HDM_LAYOUT";
5114 case 0x1200 + 6: return "HDM_HITTEST";
5115 case 0x1200 + 7: return "HDM_GETITEMRECT";
5116 case 0x1200 + 8: return "HDM_SETIMAGELIST";
5117 case 0x1200 + 9: return "HDM_GETIMAGELIST";
5118 case 0x1200 + 15: return "HDM_ORDERTOINDEX";
5119 case 0x1200 + 16: return "HDM_CREATEDRAGIMAGE";
5120 case 0x1200 + 17: return "HDM_GETORDERARRAY";
5121 case 0x1200 + 18: return "HDM_SETORDERARRAY";
5122 case 0x1200 + 19: return "HDM_SETHOTDIVIDER";
5123
5124 // tab control
5125 case 0x1300 + 2: return "TCM_GETIMAGELIST";
5126 case 0x1300 + 3: return "TCM_SETIMAGELIST";
5127 case 0x1300 + 4: return "TCM_GETITEMCOUNT";
5128 case 0x1300 + 5: return "TCM_GETITEMA";
5129 case 0x1300 + 60: return "TCM_GETITEMW";
5130 case 0x1300 + 6: return "TCM_SETITEMA";
5131 case 0x1300 + 61: return "TCM_SETITEMW";
5132 case 0x1300 + 7: return "TCM_INSERTITEMA";
5133 case 0x1300 + 62: return "TCM_INSERTITEMW";
5134 case 0x1300 + 8: return "TCM_DELETEITEM";
5135 case 0x1300 + 9: return "TCM_DELETEALLITEMS";
5136 case 0x1300 + 10: return "TCM_GETITEMRECT";
5137 case 0x1300 + 11: return "TCM_GETCURSEL";
5138 case 0x1300 + 12: return "TCM_SETCURSEL";
5139 case 0x1300 + 13: return "TCM_HITTEST";
5140 case 0x1300 + 14: return "TCM_SETITEMEXTRA";
5141 case 0x1300 + 40: return "TCM_ADJUSTRECT";
5142 case 0x1300 + 41: return "TCM_SETITEMSIZE";
5143 case 0x1300 + 42: return "TCM_REMOVEIMAGE";
5144 case 0x1300 + 43: return "TCM_SETPADDING";
5145 case 0x1300 + 44: return "TCM_GETROWCOUNT";
5146 case 0x1300 + 45: return "TCM_GETTOOLTIPS";
5147 case 0x1300 + 46: return "TCM_SETTOOLTIPS";
5148 case 0x1300 + 47: return "TCM_GETCURFOCUS";
5149 case 0x1300 + 48: return "TCM_SETCURFOCUS";
5150 case 0x1300 + 49: return "TCM_SETMINTABWIDTH";
5151 case 0x1300 + 50: return "TCM_DESELECTALL";
5152
5153 // toolbar
5154 case WM_USER+1000+1: return "TB_ENABLEBUTTON";
5155 case WM_USER+1000+2: return "TB_CHECKBUTTON";
5156 case WM_USER+1000+3: return "TB_PRESSBUTTON";
5157 case WM_USER+1000+4: return "TB_HIDEBUTTON";
5158 case WM_USER+1000+5: return "TB_INDETERMINATE";
5159 case WM_USER+1000+9: return "TB_ISBUTTONENABLED";
5160 case WM_USER+1000+10: return "TB_ISBUTTONCHECKED";
5161 case WM_USER+1000+11: return "TB_ISBUTTONPRESSED";
5162 case WM_USER+1000+12: return "TB_ISBUTTONHIDDEN";
5163 case WM_USER+1000+13: return "TB_ISBUTTONINDETERMINATE";
5164 case WM_USER+1000+17: return "TB_SETSTATE";
5165 case WM_USER+1000+18: return "TB_GETSTATE";
5166 case WM_USER+1000+19: return "TB_ADDBITMAP";
5167 case WM_USER+1000+20: return "TB_ADDBUTTONS";
5168 case WM_USER+1000+21: return "TB_INSERTBUTTON";
5169 case WM_USER+1000+22: return "TB_DELETEBUTTON";
5170 case WM_USER+1000+23: return "TB_GETBUTTON";
5171 case WM_USER+1000+24: return "TB_BUTTONCOUNT";
5172 case WM_USER+1000+25: return "TB_COMMANDTOINDEX";
5173 case WM_USER+1000+26: return "TB_SAVERESTOREA";
5174 case WM_USER+1000+76: return "TB_SAVERESTOREW";
5175 case WM_USER+1000+27: return "TB_CUSTOMIZE";
5176 case WM_USER+1000+28: return "TB_ADDSTRINGA";
5177 case WM_USER+1000+77: return "TB_ADDSTRINGW";
5178 case WM_USER+1000+29: return "TB_GETITEMRECT";
5179 case WM_USER+1000+30: return "TB_BUTTONSTRUCTSIZE";
5180 case WM_USER+1000+31: return "TB_SETBUTTONSIZE";
5181 case WM_USER+1000+32: return "TB_SETBITMAPSIZE";
5182 case WM_USER+1000+33: return "TB_AUTOSIZE";
5183 case WM_USER+1000+35: return "TB_GETTOOLTIPS";
5184 case WM_USER+1000+36: return "TB_SETTOOLTIPS";
5185 case WM_USER+1000+37: return "TB_SETPARENT";
5186 case WM_USER+1000+39: return "TB_SETROWS";
5187 case WM_USER+1000+40: return "TB_GETROWS";
5188 case WM_USER+1000+42: return "TB_SETCMDID";
5189 case WM_USER+1000+43: return "TB_CHANGEBITMAP";
5190 case WM_USER+1000+44: return "TB_GETBITMAP";
5191 case WM_USER+1000+45: return "TB_GETBUTTONTEXTA";
5192 case WM_USER+1000+75: return "TB_GETBUTTONTEXTW";
5193 case WM_USER+1000+46: return "TB_REPLACEBITMAP";
5194 case WM_USER+1000+47: return "TB_SETINDENT";
5195 case WM_USER+1000+48: return "TB_SETIMAGELIST";
5196 case WM_USER+1000+49: return "TB_GETIMAGELIST";
5197 case WM_USER+1000+50: return "TB_LOADIMAGES";
5198 case WM_USER+1000+51: return "TB_GETRECT";
5199 case WM_USER+1000+52: return "TB_SETHOTIMAGELIST";
5200 case WM_USER+1000+53: return "TB_GETHOTIMAGELIST";
5201 case WM_USER+1000+54: return "TB_SETDISABLEDIMAGELIST";
5202 case WM_USER+1000+55: return "TB_GETDISABLEDIMAGELIST";
5203 case WM_USER+1000+56: return "TB_SETSTYLE";
5204 case WM_USER+1000+57: return "TB_GETSTYLE";
5205 case WM_USER+1000+58: return "TB_GETBUTTONSIZE";
5206 case WM_USER+1000+59: return "TB_SETBUTTONWIDTH";
5207 case WM_USER+1000+60: return "TB_SETMAXTEXTROWS";
5208 case WM_USER+1000+61: return "TB_GETTEXTROWS";
5209 case WM_USER+1000+41: return "TB_GETBITMAPFLAGS";
5210
5211 default:
5212 static char s_szBuf[128];
5213 sprintf(s_szBuf, "<unknown message = %d>", nMessage);
5214 return s_szBuf;
5215 }
5216 return NULL;
5217 } // end of wxGetMessageName
5218
5219 #endif // __WXDEBUG__
5220
5221 // Unused?
5222 #if 0
5223 static void TranslateKbdEventToMouse(
5224 wxWindow* pWin
5225 , int* pX
5226 , int* pY
5227 , ULONG* pFlags
5228 )
5229 {
5230 //
5231 // Construct the key mask
5232 ULONG& fwKeys = *pFlags;
5233
5234 fwKeys = VK_BUTTON2;
5235 if ((::WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x100) != 0)
5236 fwKeys |= VK_CTRL;
5237 if ((::WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x100) != 0)
5238 fwKeys |= VK_SHIFT;
5239
5240 //
5241 // Simulate right mouse button click
5242 //
5243 POINTL vPoint;
5244
5245 ::WinQueryMsgPos(vHabmain, &vPoint);
5246 *pX = vPoint.x;
5247 *pY = vPoint.y;
5248
5249 pWin->ScreenToClient(pX, pY);
5250 } // end of TranslateKbdEventToMouse
5251 #endif
5252
5253 // Find the wxWindow at the current mouse position, returning the mouse
5254 // position.
5255 wxWindow* wxFindWindowAtPointer(
5256 wxPoint& WXUNUSED(rPt)
5257 )
5258 {
5259 return wxFindWindowAtPoint(wxGetMousePosition());
5260 }
5261
5262 wxWindow* wxFindWindowAtPoint(
5263 const wxPoint& rPt
5264 )
5265 {
5266 POINTL vPt2;
5267
5268 vPt2.x = rPt.x;
5269 vPt2.y = rPt.y;
5270
5271 HWND hWndHit = ::WinWindowFromPoint(HWND_DESKTOP, &vPt2, FALSE);
5272 wxWindow* pWin = wxFindWinFromHandle((WXHWND)hWndHit) ;
5273 HWND hWnd = hWndHit;
5274
5275 //
5276 // Try to find a window with a wxWindow associated with it
5277 //
5278 while (!pWin && (hWnd != 0))
5279 {
5280 hWnd = ::WinQueryWindow(hWnd, QW_PARENT);
5281 pWin = wxFindWinFromHandle((WXHWND)hWnd) ;
5282 }
5283 return pWin;
5284 }
5285
5286 // Get the current mouse position.
5287 wxPoint wxGetMousePosition()
5288 {
5289 POINTL vPt;
5290
5291 ::WinQueryPointerPos(HWND_DESKTOP, &vPt);
5292 return wxPoint(vPt.x, vPt.y);
5293 }
5294
5295 wxWindowOS2* FindWindowForMouseEvent(
5296 wxWindow* pWin
5297 , short* pnX
5298 , short* pnY
5299 )
5300 {
5301 HWND hWnd = GetHwndOf(pWin);
5302 HWND hWndUnderMouse;
5303 POINTL vPoint;
5304 BOOL rcEnabled = FALSE;
5305 BOOL rcVisible = FALSE;
5306
5307 ::WinQueryPointerPos(HWND_DESKTOP, &vPoint);
5308 hWndUnderMouse = ::WinWindowFromPoint(HWND_DESKTOP, &vPoint, TRUE);
5309 if (hWndUnderMouse != HWND_DESKTOP)
5310 {
5311 wxWindow* pWinUnderMouse = wxFindWinFromHandle((WXHWND)hWndUnderMouse);
5312
5313 if (pWinUnderMouse)
5314 {
5315 wxWindowList::Node* pCurrent = pWinUnderMouse->GetChildren().GetFirst();
5316 wxWindow* pGrandChild = NULL;
5317 RECTL vRect;
5318 POINTL vPoint2;
5319
5320 ::WinMapWindowPoints(HWND_DESKTOP, hWndUnderMouse, &vPoint, 1);
5321 //
5322 // Find a child window mouse might be under
5323 //
5324 while (pCurrent)
5325 {
5326 wxWindow* pChild = pCurrent->GetData();
5327
5328 vPoint2.x = vPoint.x;
5329 vPoint2.y = vPoint.y;
5330 ::WinMapWindowPoints(hWndUnderMouse, pChild->GetHWND(), &vPoint2, 1);
5331 ::WinQueryWindowRect(pChild->GetHWND(), &vRect);
5332 if (::WinPtInRect(vHabmain, &vRect, &vPoint2))
5333 {
5334 if (pChild->IsTopLevel())
5335 {
5336 POINTL vPoint3;
5337 wxWindowList::Node* pCurrent2 =pChild->GetChildren().GetFirst();
5338
5339 while (pCurrent2)
5340 {
5341 wxWindow* pGrandChild = pCurrent2->GetData();
5342
5343 vPoint3.x = vPoint2.x;
5344 vPoint3.y = vPoint2.y;
5345 ::WinMapWindowPoints( pChild->GetHWND()
5346 ,pGrandChild->GetHWND()
5347 ,&vPoint3
5348 ,1
5349 );
5350 ::WinQueryWindowRect(pGrandChild->GetHWND(), &vRect);
5351 if (::WinPtInRect(vHabmain, &vRect, &vPoint3))
5352 {
5353 hWndUnderMouse = GetHwndOf(pGrandChild);
5354 pWinUnderMouse = pGrandChild;
5355 break;
5356 }
5357 pCurrent2 = pCurrent2->GetNext();
5358 }
5359 if (pGrandChild)
5360 break;
5361 }
5362 hWndUnderMouse = GetHwndOf(pChild);
5363 pWinUnderMouse = pChild;
5364 rcVisible = ::WinIsWindowVisible(hWndUnderMouse);
5365 rcEnabled = ::WinIsWindowEnabled(hWndUnderMouse);
5366 if (rcVisible && rcEnabled)
5367 break;
5368 }
5369 pCurrent = pCurrent->GetNext();
5370 }
5371 }
5372 }
5373 rcVisible = ::WinIsWindowVisible(hWndUnderMouse);
5374 rcEnabled = ::WinIsWindowEnabled(hWndUnderMouse);
5375
5376
5377 //
5378 // Check that we have a child window which is susceptible to receive mouse
5379 // events: for this it must be shown and enabled
5380 //
5381 if ( hWndUnderMouse &&
5382 hWndUnderMouse != hWnd &&
5383 rcVisible && rcEnabled)
5384 {
5385 wxWindow* pWinUnderMouse = wxFindWinFromHandle((WXHWND)hWndUnderMouse);
5386
5387 if (pWinUnderMouse)
5388 {
5389 //
5390 // Translate the mouse coords to the other window coords
5391 //
5392 pWin = pWinUnderMouse;
5393 }
5394 }
5395 return pWin;
5396 } // end of FindWindowForMouseEvent
5397