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