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