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