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