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