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