1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/scrolbar.cpp 
   3 // Purpose:     wxScrollBar 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  15 #include "wx/scrolbar.h" 
  21 #include "wx/os2/private.h" 
  24 bool wxScrollBar::Create(wxWindow
* pParent
, 
  30                          const wxValidator
& rValidator
, 
  32                          const wxString
& rsName
 
  38     int nHeight 
= rSize
.y
; 
  43     pParent
->AddChild(this); 
  46     SetValidator(rValidator
); 
  48     SetBackgroundColour(pParent
->GetBackgroundColour()) ; 
  49     SetForegroundColour(pParent
->GetForegroundColour()) ; 
  52         m_windowId 
= (int)NewControlId(); 
  56     if (nWidth 
== wxDefaultCoord
) 
  58         if (lStyle 
& wxHORIZONTAL
) 
  63     if (nHeight 
== wxDefaultCoord
) 
  65         if (lStyle 
& wxVERTICAL
) 
  71     DWORD                           dwStyle 
= WS_VISIBLE
; 
  73     if (GetWindowStyleFlag() & wxCLIP_SIBLINGS
) 
  74         dwStyle 
|= WS_CLIPSIBLINGS
; 
  76     DWORD dwDirection 
= (lStyle 
& wxHORIZONTAL
) ? SBS_HORZ
: SBS_VERT
; 
  78     HWND hScrollBar 
= ::WinCreateWindow( (HWND
)GetHwndOf(pParent
) 
  81                                          ,dwDirection 
| dwStyle
 
  83                                          ,(HWND
)GetHwndOf(pParent
) 
  93     ::WinSendMsg( hScrollBar
 
  98     ::WinShowWindow( hScrollBar
, TRUE 
); 
  99     SetFont(*wxSMALL_FONT
); 
 104     // Subclass again for purposes of dialog editing mode 
 106     SubclassWin((WXHWND
)hScrollBar
); 
 113 } // end of wxScrollBar::Create 
 115 wxScrollBar::~wxScrollBar() 
 119 bool wxScrollBar::OS2OnScroll ( int    WXUNUSED(nOrientation
), 
 122                                 WXHWND 
WXUNUSED(hControl
) ) 
 126     int         nTrackPos 
= wPos
; 
 129     wxEventType vScrollEvent 
= wxEVT_NULL
; 
 134     // When we're dragging the scrollbar we can't use pos parameter because it 
 135     // is limited to 16 bits 
 137     if (wParam 
== SB_SLIDERPOSITION 
|| wParam 
== SB_SLIDERTRACK
) 
 141         vScrollInfo
.sHilite 
= SB_SLIDERTRACK
; 
 143         ::WinSendMsg((HWND
)GetHwnd(), WM_QUERYWINDOWPARAMS
, (PVOID
)&vScrollInfo
, NULL
); 
 145         nTrackPos 
= vScrollInfo
.posThumb
; 
 146         nPosition 
= vScrollInfo
.posFirst
; 
 147         nMaxPos   
= vScrollInfo
.posLast
; 
 151         nPosition 
= (int)(MRESULT
)::WinSendMsg((HWND
)GetHwnd(), SBM_QUERYPOS
, (MPARAM
)NULL
, (MPARAM
)NULL
); 
 152         vRange 
= ::WinSendMsg((HWND
)GetHwnd(), SBM_QUERYRANGE
, (MPARAM
)NULL
, (MPARAM
)NULL
); 
 153         nMinPos 
= SHORT1FROMMR(vRange
); 
 154         nMaxPos 
= SHORT2FROMMR(vRange
); 
 157     // A page size greater than one has the effect of reducing the effective 
 158     // range, therefore the range has already been boosted artificially - so 
 162         nMaxPos 
-= (m_nPageSize 
- 1); 
 167             vScrollEvent 
= wxEVT_SCROLL_LINEUP
; 
 172             vScrollEvent 
= wxEVT_SCROLL_LINEDOWN
; 
 176             nScrollInc   
= -GetPageSize(); 
 177             vScrollEvent 
= wxEVT_SCROLL_PAGEUP
; 
 181             nScrollInc   
= GetPageSize(); 
 182             vScrollEvent 
= wxEVT_SCROLL_PAGEDOWN
; 
 186             nScrollInc   
= nTrackPos 
- nPosition
; 
 187             vScrollEvent 
= wxEVT_SCROLL_THUMBTRACK
; 
 192             vScrollEvent 
= wxEVT_SCROLL_CHANGED
; 
 200         nPosition 
+= nScrollInc
; 
 204         if (nPosition 
> nMaxPos
) 
 206         SetThumbPosition(nPosition
); 
 208     else if ( vScrollEvent 
!= wxEVT_SCROLL_THUMBRELEASE 
&& 
 209               vScrollEvent 
!= wxEVT_SCROLL_CHANGED
 
 213         // Don't process the event if there is no displacement, 
 214         // unless this is a thumb release or end scroll event. 
 219     wxScrollEvent                   
vEvent( vScrollEvent
 
 223     vEvent
.SetOrientation(IsVertical() ? wxVERTICAL 
: wxHORIZONTAL
); 
 224     vEvent
.SetPosition(nPosition
); 
 225     vEvent
.SetEventObject(this); 
 226     return HandleWindowEvent(vEvent
); 
 227 } // end of wxScrollBar::OS2OnScroll 
 229 void wxScrollBar::SetThumbPosition ( int nViewStart 
) 
 233     memset(&vInfo
, '\0', sizeof(SBCDATA
)); 
 234     vInfo
.cb       
= sizeof(SBCDATA
); 
 235     vInfo
.posThumb 
= (SHORT
)nViewStart
; 
 237     ::WinSendMsg((HWND
)GetHwnd(), WM_SETWINDOWPARAMS
, (MPARAM
)&vInfo
, (MPARAM
)NULL
); 
 238     ::WinSendMsg((HWND
)GetHwnd(), SBM_SETPOS
, (MPARAM
)nViewStart
, (MPARAM
)NULL
); 
 239 } // end of wxScrollBar::SetThumbPosition 
 241 int wxScrollBar::GetThumbPosition() const 
 243     return((int)(MRESULT
)::WinSendMsg((HWND
)GetHwnd(), SBM_QUERYPOS
, (MPARAM
)NULL
, (MPARAM
)NULL
)); 
 244 } // end of wxScrollBar::GetThumbPosition 
 246 void wxScrollBar::SetScrollbar ( int  nPosition
, 
 250                                  bool WXUNUSED(bRefresh
) ) 
 254     // The lRange (number of scroll steps) is the 
 255     // object length minus the page size. 
 257     int                             nRange1 
= wxMax((m_nObjectSize 
- m_nPageSize
), 0); 
 259     m_nViewSize   
= nPageSize
; 
 260     m_nPageSize   
= nThumbSize
; 
 261     m_nObjectSize 
= nRange
; 
 265     // Try to adjust the lRange to cope with page size > 1 
 266     // (see comment for SetPageLength) 
 268     if (m_nPageSize 
> 1 ) 
 270         nRange1 
+= (m_nPageSize 
- 1); 
 272     vInfo
.cb 
= sizeof(SBCDATA
); 
 273     vInfo
.cVisible 
= (SHORT
)m_nPageSize
; 
 275     vInfo
.posLast  
= (SHORT
)nRange1
; 
 276     vInfo
.posThumb 
= (SHORT
)nPosition
; 
 278     ::WinSendMsg((HWND
)GetHwnd(), WM_SETWINDOWPARAMS
, (MPARAM
)&vInfo
, (MPARAM
)NULL
); 
 279 } // end of wxScrollBar::SetScrollbar 
 281 WXHBRUSH 
wxScrollBar::OnCtlColor ( WXHDC    
WXUNUSED(hDC
), 
 282                                    WXHWND   
WXUNUSED(hWnd
), 
 283                                    WXUINT   
WXUNUSED(uCtlColor
), 
 284                                    WXUINT   
WXUNUSED(uMessage
), 
 285                                    WXWPARAM 
WXUNUSED(wParam
), 
 286                                    WXLPARAM 
WXUNUSED(lParam
) ) 
 289     // Does nothing under OS/2 
 292 } // end of wxScrollBar::OnCtlColor 
 294 void wxScrollBar::Command ( wxCommandEvent
& rEvent 
) 
 296     SetThumbPosition(rEvent
.GetInt()); 
 297     ProcessCommand(rEvent
); 
 298 } // end of wxScrollBar::Command