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