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