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