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