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