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