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