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