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