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