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