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