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