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