]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/scrolbar.cpp
Deallocate wxThreadSpecificInfo when wxThread ends.
[wxWidgets.git] / src / os2 / scrolbar.cpp
index 4b3662cb84e70a1b662d73c09e4a4ae2d502e92d..fbb1fb2e9a5be633cdd247088b48a5ff4eccaea5 100644 (file)
@@ -1,10 +1,9 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        scrolbar.cpp
+// Name:        src/os2/scrolbar.cpp
 // Purpose:     wxScrollBar
 // Author:      David Webster
 // Modified by:
 // Created:     10/15/99
-// RCS-ID:      $Id$
 // Copyright:   (c) David Webster
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
+#include "wx/scrolbar.h"
+
 #ifndef WX_PRECOMP
-#include "wx/defs.h"
-#include "wx/utils.h"
+    #include "wx/utils.h"
 #endif
 
-#include "wx/scrolbar.h"
 #include "wx/os2/private.h"
 
-IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl)
-
-BEGIN_EVENT_TABLE(wxScrollBar, wxControl)
-#if WXWIN_COMPATIBILITY
-  EVT_SCROLL(wxScrollBar::OnScroll)
+// Scrollbar
+bool wxScrollBar::Create(wxWindow* pParent,
+                         wxWindowID vId,
+                         const wxPoint& rPos,
+                         const wxSize& rSize,
+                         long lStyle,
+#if wxUSE_VALIDATORS
+                         const wxValidator& rValidator,
 #endif
-END_EVENT_TABLE()
+                         const wxString& rsName
+                        )
+{
+    int nX = rPos.x;
+    int nY = rPos.y;
+    int nWidth = rSize.x;
+    int nHeight = rSize.y;
 
+    if (!pParent)
+        return false;
 
-// Scrollbar
-bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
-           const wxPoint& pos,
-           const wxSize& size, long style,
-           const wxValidator& validator,
-           const wxString& name)
-{
-    if (!parent)
-        return FALSE;
-    parent->AddChild(this);
-    SetName(name);
+    pParent->AddChild(this);
+    SetName(rsName);
 #if wxUSE_VALIDATORS
-    SetValidator(validator);
+    SetValidator(rValidator);
 #endif
+    SetBackgroundColour(pParent->GetBackgroundColour()) ;
+    SetForegroundColour(pParent->GetForegroundColour()) ;
 
-    SetBackgroundColour(parent->GetBackgroundColour()) ;
-    SetForegroundColour(parent->GetForegroundColour()) ;
-    m_windowStyle = style;
-
-    if ( id == -1 )
+    if (vId == wxID_ANY)
         m_windowId = (int)NewControlId();
     else
-        m_windowId = id;
+        m_windowId = vId;
 
-    int x = pos.x;
-    int y = pos.y;
-    int width = size.x;
-    int height = size.y;
-
-    if (width == -1)
+    if (nWidth == wxDefaultCoord)
     {
-        if (style & wxHORIZONTAL)
-            width = 140;
+        if (lStyle & wxHORIZONTAL)
+            nWidth = 140;
         else
-            width = 14;
+            nWidth = 14;
     }
-    if (height == -1)
+    if (nHeight == wxDefaultCoord)
     {
-        if (style & wxVERTICAL)
-            height = 140;
+        if (lStyle & wxVERTICAL)
+            nHeight = 140;
         else
-            height = 14;
+            nHeight = 14;
     }
 
-    // TODO create scrollbar
-
-    m_pageSize = 1;
-    m_viewSize = 1;
-    m_objectSize = 1;
-
-    SetFont(parent->GetFont());
-
-    m_hWnd = 0; // TODO: (WXHWND)scroll_bar;
-
-    HWND scroll_bar = 0; // temporary
-
+    DWORD                           dwStyle = WS_VISIBLE;
+
+    if (GetWindowStyleFlag() & wxCLIP_SIBLINGS)
+        dwStyle |= WS_CLIPSIBLINGS;
+
+    DWORD dwDirection = (lStyle & wxHORIZONTAL) ? SBS_HORZ: SBS_VERT;
+
+    HWND hScrollBar = ::WinCreateWindow( (HWND)GetHwndOf(pParent)
+                                         ,WC_SCROLLBAR
+                                         ,(PSZ)NULL
+                                         ,dwDirection | dwStyle
+                                         ,0, 0, 0, 0
+                                         ,(HWND)GetHwndOf(pParent)
+                                         ,HWND_TOP
+                                         ,(HMENU)m_windowId
+                                         ,NULL
+                                         ,NULL
+                                         );
+
+    m_nPageSize = 1;
+    m_nViewSize = 1;
+    m_nObjectSize = 1;
+    ::WinSendMsg( hScrollBar
+                 ,SBM_SETSCROLLBAR
+                 ,(MPARAM)0
+                 ,MPFROM2SHORT(0,1)
+                );
+    ::WinShowWindow( hScrollBar, TRUE );
+    SetFont(*wxSMALL_FONT);
+
+    m_hWnd = hScrollBar;
+
+    //
     // Subclass again for purposes of dialog editing mode
-    SubclassWin((WXHWND) scroll_bar);
-
-    SetSize(x, y, width, height);
-
-    return TRUE;
-}
+    //
+    SubclassWin((WXHWND)hScrollBar);
+    SetSize( nX
+            ,nY
+            ,nWidth
+            ,nHeight
+           );
+    return true;
+} // end of wxScrollBar::Create
 
 wxScrollBar::~wxScrollBar()
 {
 }
 
-bool wxScrollBar::OS2OnScroll(int WXUNUSED(orientation), WXWORD wParam,
-                              WXWORD pos, WXHWND control)
+bool wxScrollBar::OS2OnScroll ( int    WXUNUSED(nOrientation),
+                                WXWORD wParam,
+                                WXWORD wPos,
+                                WXHWND WXUNUSED(hControl) )
 {
-    // TODO:
-/*
-    int position = ::GetScrollPos((HWND) control, SB_CTL);
-    int minPos, maxPos;
-    ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos);
+    int         nPosition;
+    int         nMaxPos;
+    int         nTrackPos = wPos;
+    int         nMinPos;
+    int         nScrollInc;
+    wxEventType vScrollEvent = wxEVT_NULL;
+
+    MRESULT     vRange;
+
+    //
+    // When we're dragging the scrollbar we can't use pos parameter because it
+    // is limited to 16 bits
+    //
+    if (wParam == SB_SLIDERPOSITION || wParam == SB_SLIDERTRACK)
+    {
+        SBCDATA                     vScrollInfo;
+
+        vScrollInfo.sHilite = SB_SLIDERTRACK;
+
+        ::WinSendMsg((HWND)GetHwnd(), WM_QUERYWINDOWPARAMS, (PVOID)&vScrollInfo, NULL);
 
-#if defined(__WIN95__)
+        nTrackPos = vScrollInfo.posThumb;
+        nPosition = vScrollInfo.posFirst;
+        nMaxPos   = vScrollInfo.posLast;
+    }
+    else
+    {
+        nPosition = (int)(MRESULT)::WinSendMsg((HWND)GetHwnd(), SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL);
+        vRange = ::WinSendMsg((HWND)GetHwnd(), SBM_QUERYRANGE, (MPARAM)NULL, (MPARAM)NULL);
+        nMinPos = SHORT1FROMMR(vRange);
+        nMaxPos = SHORT2FROMMR(vRange);
+    }
+    //
     // A page size greater than one has the effect of reducing the effective
     // range, therefore the range has already been boosted artificially - so
     // reduce it again.
-    if ( m_pageSize > 1 )
-        maxPos -= (m_pageSize - 1);
-#endif // __WIN95__
-
-    wxEventType scrollEvent = wxEVT_NULL;
-
-    int nScrollInc;
-    switch ( wParam )
+    //
+    if (m_nPageSize > 1)
+        nMaxPos -= (m_nPageSize - 1);
+    switch (wParam)
     {
-        case SB_TOP:
-            nScrollInc = maxPos - position;
-            scrollEvent = wxEVT_SCROLL_TOP;
-            break;
-
-        case SB_BOTTOM:
-            nScrollInc = - position;
-            scrollEvent = wxEVT_SCROLL_BOTTOM;
-            break;
-
         case SB_LINEUP:
-            nScrollInc = -1;
-            scrollEvent = wxEVT_SCROLL_LINEUP;
+            nScrollInc   = -1;
+            vScrollEvent = wxEVT_SCROLL_LINEUP;
             break;
 
         case SB_LINEDOWN:
-            nScrollInc = 1;
-            scrollEvent = wxEVT_SCROLL_LINEDOWN;
+            nScrollInc   = 1;
+            vScrollEvent = wxEVT_SCROLL_LINEDOWN;
             break;
 
         case SB_PAGEUP:
-            nScrollInc = -GetPageSize();
-            scrollEvent = wxEVT_SCROLL_PAGEUP;
+            nScrollInc   = -GetPageSize();
+            vScrollEvent = wxEVT_SCROLL_PAGEUP;
             break;
 
         case SB_PAGEDOWN:
-            nScrollInc = GetPageSize();
-            scrollEvent = wxEVT_SCROLL_PAGEDOWN;
+            nScrollInc   = GetPageSize();
+            vScrollEvent = wxEVT_SCROLL_PAGEDOWN;
             break;
 
-        case SB_THUMBTRACK:
-        case SB_THUMBPOSITION:
-            nScrollInc = pos - position;
-            scrollEvent = wxEVT_SCROLL_THUMBTRACK;
+        case SB_SLIDERTRACK:
+            nScrollInc   = nTrackPos - nPosition;
+            vScrollEvent = wxEVT_SCROLL_THUMBTRACK;
+            break;
+
+        case SB_ENDSCROLL:
+            nScrollInc   = 0;
+            vScrollEvent = wxEVT_SCROLL_CHANGED;
             break;
 
         default:
             nScrollInc = 0;
     }
+    if (nScrollInc)
+    {
+        nPosition += nScrollInc;
 
-    if ( nScrollInc == 0 )
+        if (nPosition < 0)
+            nPosition = 0;
+        if (nPosition > nMaxPos)
+            nPosition = nMaxPos;
+        SetThumbPosition(nPosition);
+    }
+    else if ( vScrollEvent != wxEVT_SCROLL_THUMBRELEASE &&
+              vScrollEvent != wxEVT_SCROLL_CHANGED
+            )
     {
-        // no event to process, so don't process it
-        return FALSE;
+        //
+        // Don't process the event if there is no displacement,
+        // unless this is a thumb release or end scroll event.
+        //
+        return false;
     }
 
-    int new_pos = position + nScrollInc;
-
-    if (new_pos < 0)
-        new_pos = 0;
-    if (new_pos > maxPos)
-        new_pos = maxPos;
+    wxScrollEvent                   vEvent( vScrollEvent
+                                           ,m_windowId
+                                          );
 
-    SetThumbPosition(new_pos);
-    wxScrollEvent event(scrollEvent, m_windowId);
-    event.SetPosition(new_pos);
-    event.SetEventObject( this );
+    vEvent.SetOrientation(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
+    vEvent.SetPosition(nPosition);
+    vEvent.SetEventObject(this);
+    return HandleWindowEvent(vEvent);
+} // end of wxScrollBar::OS2OnScroll
 
-    return GetEventHandler()->ProcessEvent(event);
-*/
-    return FALSE;
-}
-
-void wxScrollBar::SetThumbPosition(int viewStart)
-{
-    // TODO
-}
-
-int wxScrollBar::GetThumbPosition() const
-{
-    // TODO
-    return 0;
-}
-
-void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageSize,
-    bool refresh)
-{
-    m_viewSize = pageSize;
-    m_pageSize = thumbSize;
-    m_objectSize = range;
-
-    // TODO
-}
-
-#if WXWIN_COMPATIBILITY
-void wxScrollBar::SetPageSize(int pageLength)
-{
-    m_pageSize = pageLength;
-
-    // TODO:
-}
-
-void wxScrollBar::SetObjectLength(int objectLength)
+void wxScrollBar::SetThumbPosition ( int nViewStart )
 {
-    m_objectSize = objectLength;
+    SBCDATA                        vInfo;
 
-    // The range (number of scroll steps) is the
-    // object length minus the view size.
-    int range = wxMax((objectLength - m_viewSize), 0) ;
+    memset(&vInfo, '\0', sizeof(SBCDATA));
+    vInfo.cb       = sizeof(SBCDATA);
+    vInfo.posThumb = (SHORT)nViewStart;
 
-    // TODO:
-}
+    ::WinSendMsg((HWND)GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vInfo, (MPARAM)NULL);
+    ::WinSendMsg((HWND)GetHwnd(), SBM_SETPOS, (MPARAM)nViewStart, (MPARAM)NULL);
+} // end of wxScrollBar::SetThumbPosition
 
-void wxScrollBar::SetViewLength(int viewLength)
+int wxScrollBar::GetThumbPosition() const
 {
-    m_viewSize = viewLength;
-}
-
-void wxScrollBar::GetValues(int *viewStart, int *viewLength, int *objectLength,
-           int *pageLength) const
+    return((int)(MRESULT)::WinSendMsg((HWND)GetHwnd(), SBM_QUERYPOS, (MPARAM)NULL, (MPARAM)NULL));
+} // end of wxScrollBar::GetThumbPosition
+
+void wxScrollBar::SetScrollbar ( int  nPosition,
+                                 int  nThumbSize,
+                                 int  nRange,
+                                 int  nPageSize,
+                                 bool WXUNUSED(bRefresh) )
 {
-// TODO:
-/*
-    *viewStart = ::GetScrollPos((HWND)m_hWnd, SB_CTL);
-    *viewLength = m_viewSize;
-    *objectLength = m_objectSize;
-    *pageLength = m_pageSize;
-*/
-}
-#endif
-
-WXHBRUSH wxScrollBar::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
-            WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
-{
-  return 0;
-}
-
-void wxScrollBar::Command(wxCommandEvent& event)
+    SBCDATA                         vInfo;
+    //
+    // The lRange (number of scroll steps) is the
+    // object length minus the page size.
+    //
+    int                             nRange1 = wxMax((m_nObjectSize - m_nPageSize), 0);
+
+    m_nViewSize   = nPageSize;
+    m_nPageSize   = nThumbSize;
+    m_nObjectSize = nRange;
+
+
+    //
+    // Try to adjust the lRange to cope with page size > 1
+    // (see comment for SetPageLength)
+    //
+    if (m_nPageSize > 1 )
+    {
+        nRange1 += (m_nPageSize - 1);
+    }
+    vInfo.cb = sizeof(SBCDATA);
+    vInfo.cVisible = (SHORT)m_nPageSize;
+    vInfo.posFirst = 0;
+    vInfo.posLast  = (SHORT)nRange1;
+    vInfo.posThumb = (SHORT)nPosition;
+
+    ::WinSendMsg((HWND)GetHwnd(), WM_SETWINDOWPARAMS, (MPARAM)&vInfo, (MPARAM)NULL);
+} // end of wxScrollBar::SetScrollbar
+
+WXHBRUSH wxScrollBar::OnCtlColor ( WXHDC    WXUNUSED(hDC),
+                                   WXHWND   WXUNUSED(hWnd),
+                                   WXUINT   WXUNUSED(uCtlColor),
+                                   WXUINT   WXUNUSED(uMessage),
+                                   WXWPARAM WXUNUSED(wParam),
+                                   WXLPARAM WXUNUSED(lParam) )
 {
-    SetThumbPosition(event.m_commandInt);
-    ProcessCommand(event);
-}
+    //
+    // Does nothing under OS/2
+    //
+    return 0;
+} // end of wxScrollBar::OnCtlColor
 
-#if WXWIN_COMPATIBILITY
-// Backward compatibility
-void wxScrollBar::OnScroll(wxScrollEvent& event)
+void wxScrollBar::Command ( wxCommandEvent& rEvent )
 {
-    // TODO:
-/*
-    wxEventType oldEvent = event.GetEventType();
-    event.SetEventType( wxEVT_COMMAND_SCROLLBAR_UPDATED );
-    if ( !GetEventHandler()->ProcessEvent(event) )
-    {
-        event.SetEventType( oldEvent );
-        if (!GetParent()->GetEventHandler()->ProcessEvent(event))
-            event.Skip();
-    }
-*/
-}
-#endif
+    SetThumbPosition(rEvent.GetInt());
+    ProcessCommand(rEvent);
+} // end of wxScrollBar::Command