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