]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/slider.cpp
Remove the long obsolete and unused since 2.7.0 __WIN95__ define.
[wxWidgets.git] / src / os2 / slider.cpp
index 1c806c968ab6865da230b440ff56ae1acf7ee70d..e74e38ac5edf7920f1ce1ab3dbcc10e41edecaa8 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        slider.cpp
+// Name:        src/os2/slider.cpp
 // Purpose:     wxSlider
 // Author:      David Webster
 // Modified by:
 #endif
 
 #ifndef WX_PRECOMP
-#include <stdio.h>
-#include <wx/utils.h>
-#include <wx/brush.h>
-#include <wx/scrolwin.h>
+    #include <stdio.h>
+    #include "wx/utils.h"
+    #include "wx/brush.h"
+    #include "wx/scrolwin.h"
 #endif
 
 #if wxUSE_SLIDER
@@ -28,8 +28,6 @@
 #include "wx/slider.h"
 #include "wx/os2/private.h"
 
-IMPLEMENT_DYNAMIC_CLASS(wxSlider, wxControl)
-
 wxSlider::wxSlider()
 {
     m_hStaticValue = 0L;
@@ -52,13 +50,11 @@ wxSlider::~wxSlider()
         ::WinDestroyWindow((HWND)m_hStaticValue);
 } // end of wxSlider::~wxSlider
 
-void wxSlider::AdjustSubControls(
-  int                               nX
-, int                               nY
-, int                               nWidth
-, int                               nHeight
-, int                               nSizeFlags
-)
+void wxSlider::AdjustSubControls( int nX,
+                                  int nY,
+                                  int nWidth,
+                                  int nHeight,
+                                  int WXUNUSED(nSizeFlags) )
 {
     int                             nXOffset = nX;
     int                             nYOffset = nY;
@@ -234,7 +230,7 @@ bool wxSlider::Create(
     m_windowStyle  = lStyle;
     m_nTickFreq    = 0;
 
-    if (vId == -1)
+    if (vId == wxID_ANY)
         m_windowId = (int)NewControlId();
     else
         m_windowId = vId;
@@ -312,20 +308,20 @@ bool wxSlider::Create(
     lMsStyle |= SLS_RIBBONSTRIP;
 
     m_nPageSize = ((nMaxValue - nMinValue)/10);
-    vSlData.usScale1Increments = m_nPageSize;
-    vSlData.usScale2Increments = m_nPageSize;
-
-    HWND                            hScrollBar = ::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
-                                                                   ,WC_SLIDER                // Window class
-                                                                   ,(PSZ)wxBuffer            // Initial Text
-                                                                   ,(ULONG)lMsStyle          // Style flags
-                                                                   ,0L, 0L, 0L, 0L           // Origin -- 0 size
-                                                                   ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
-                                                                   ,HWND_BOTTOM                 // initial z position
-                                                                   ,(HMENU)m_windowId       // Window identifier
-                                                                   ,&vSlData                 // Slider control data
-                                                                   ,NULL                     // no Presentation parameters
-                                                                  );
+    vSlData.usScale1Increments = (USHORT)m_nPageSize;
+    vSlData.usScale2Increments = (USHORT)m_nPageSize;
+
+    HWND hScrollBar = ::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
+                                        ,WC_SLIDER                // Window class
+                                        ,(PSZ)wxBuffer            // Initial Text
+                                        ,(ULONG)lMsStyle          // Style flags
+                                        ,0L, 0L, 0L, 0L           // Origin -- 0 size
+                                        ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
+                                        ,HWND_BOTTOM                 // initial z position
+                                        ,(HMENU)m_windowId       // Window identifier
+                                        ,&vSlData                 // Slider control data
+                                        ,NULL                     // no Presentation parameters
+                                       );
     m_nRangeMax = nMaxValue;
     m_nRangeMin = nMinValue;
 
@@ -372,7 +368,7 @@ bool wxSlider::Create(
                                                  ,NULL                     // no control data
                                                  ,NULL                     // no Presentation parameters
                                                 );
-        if (GetFont().Ok())
+        if (GetFont().IsOk())
         {
             if (GetFont().GetResourceHandle())
             {
@@ -408,11 +404,9 @@ bool wxSlider::Create(
                                               )
                                  ) + 4; // for bordersizes
 
-    wxColour                        vColour;
-
-    vColour.Set(wxString(wxT("BLACK")));
+    wxColour vColour(*wxBLACK);
 
-    LONG                            lColor = (LONG)vColour.GetPixel();
+    LONG lColor = (LONG)vColour.GetPixel();
 
     ::WinSetPresParam( m_hStaticMin
                       ,PP_FOREGROUNDCOLOR
@@ -466,27 +460,25 @@ bool wxSlider::Create(
     return true;
 } // end of wxSlider::Create
 
-void wxSlider::DoSetSize(
-  int                               nX
-, int                               nY
-, int                               nWidth
-, int                               nHeight
-, int                               nSizeFlags
-)
+void wxSlider::DoSetSize( int nX,
+                          int nY,
+                          int nWidth,
+                          int nHeight,
+                          int nSizeFlags )
 {
-    int                             nX1      = nX;
-    int                             nY1      = nY;
-    int                             nWidth1  = nWidth;
-    int                             nHeight1 = nHeight;
-    int                             nXOffset = nX;
-    int                             nYOffset = nY;
-    int                             nCx;     // slider,min,max sizes
-    int                             nCy;
-    int                             nCyf;
-    int                             nCurrentX;
-    int                             nCurrentY;
-    wxChar                          zBuf[300];
-    wxFont                          vFont = this->GetFont();
+    int    nX1      = nX;
+    int    nY1      = nY;
+    int    nWidth1  = nWidth;
+    int    nHeight1 = nHeight;
+    int    nXOffset = nX;
+    int    nYOffset = nY;
+    int    nCx;     // slider,min,max sizes
+    int    nCy;
+    int    nCyf;
+    int    nCurrentX;
+    int    nCurrentY;
+    wxChar zBuf[300];
+    wxFont vFont = this->GetFont();
 
     //
     // Adjust for OS/2's reverse coordinate system
@@ -497,29 +489,28 @@ void wxSlider::DoSetSize(
 
     if (nOS2Height < 0)
         nOS2Height = 20;
+    CacheBestSize(wxSize(nWidth,nOS2Height));
 
     if (pParent)
     {
-        int                         nOS2ParentHeight = GetOS2ParentHeight(pParent);
+        int nOS2ParentHeight = GetOS2ParentHeight(pParent);
 
         nYOffset = nOS2ParentHeight - (nYOffset + nOS2Height);
-        if (nY != -1)
+        if (nY != wxDefaultCoord)
             nY1 = nOS2ParentHeight - (nY1 + nOS2Height);
     }
     else
     {
-        RECTL                       vRect;
+        RECTL vRect;
 
         ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
         nYOffset = vRect.yTop - (nYOffset + nOS2Height);
-        if (nY != -1)
+        if (nY != wxDefaultCoord)
             nY1 = vRect.yTop - (nY1 + nOS2Height);
     }
     m_nSizeFlags = nSizeFlags;
 
-    GetPosition( &nCurrentX
-                ,&nCurrentY
-               );
+    GetPosition( &nCurrentX, &nCurrentY );
     if (nX == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
         nX1 = nCurrentX;
     if (nY == -1 && !(nSizeFlags & wxSIZE_ALLOW_MINUS_ONE))
@@ -814,8 +805,10 @@ void wxSlider::GetPosition(
         vPoint.x -= vPt.x;
         vPoint.y -= vPt.y;
     }
-    *pnX = vPoint.x;
-    *pnY = vPoint.y;
+    if (pnX)
+        *pnX = vPoint.x;
+    if (pnY)
+        *pnY = vPoint.y;
 } // end of wxSlider::GetPosition
 
 int wxSlider::GetSelEnd() const
@@ -888,7 +881,6 @@ int wxSlider::GetValue() const
                                                                            )
                                                               );
     double                          dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
-    int                             nNewPos = 0;
     int                             nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
                                                                           ,SLM_QUERYSLIDERINFO
                                                                           ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
@@ -897,7 +889,7 @@ int wxSlider::GetValue() const
                                                                           ,(MPARAM)0
                                                                          )
                                                             );
-    nNewPos = (int)(nPixelPos/dPixelToRange);
+    int nNewPos = (int)(nPixelPos/dPixelToRange);
     if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
         nNewPos++;
     return nNewPos;
@@ -922,14 +914,12 @@ WXHBRUSH wxSlider::OnCtlColor(
            );
 } // end of wxSlider::OnCtlColor
 
-bool wxSlider::OS2OnScroll(
-  int                               WXUNUSED(nOrientation)
-, WXWORD                            wParam
-, WXWORD                            wPos
-, WXHWND                            hControl
-)
+bool wxSlider::OS2OnScroll( int    WXUNUSED(nOrientation),
+                            WXWORD wParam,
+                            WXWORD WXUNUSED(wPos),
+                            WXHWND WXUNUSED(hControl) )
 {
-    wxEventType                     eScrollEvent = wxEVT_NULL;
+    wxEventType eScrollEvent = wxEVT_NULL;
 
     switch (wParam)
     {
@@ -948,24 +938,21 @@ bool wxSlider::OS2OnScroll(
             return false;
     }
 
-    int                             nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
-                                                                            ,SLM_QUERYSLIDERINFO
-                                                                            ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
-                                                                                          ,SMA_RANGEVALUE
-                                                                                         )
-                                                                            ,(MPARAM)0
-                                                                           )
-                                                              );
+    int nPixelRange = SHORT1FROMMR(::WinSendMsg( GetHwnd()
+                                               , SLM_QUERYSLIDERINFO
+                                               , MPFROM2SHORT( SMA_SHAFTDIMENSIONS, SMA_RANGEVALUE )
+                                               , (MPARAM)0
+                                               )
+                                  );
     m_dPixelToRange = (double)(nPixelRange - m_nThumbLength)/(double)(m_nRangeMax - m_nRangeMin);
-    int                             nNewPos = 0;
-    int                             nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
-                                                                          ,SLM_QUERYSLIDERINFO
-                                                                          ,MPFROM2SHORT( SMA_SLIDERARMPOSITION
-                                                                                        ,SMA_RANGEVALUE
-                                                                                       )
-                                                                          ,(MPARAM)0
-                                                                         )
-                                                            );
+    int nNewPos = 0;
+    int nPixelPos = SHORT1FROMMR(::WinSendMsg( GetHwnd()
+                                             , SLM_QUERYSLIDERINFO
+                                             , MPFROM2SHORT( SMA_SLIDERARMPOSITION, SMA_RANGEVALUE )
+                                             , (MPARAM)0
+                                             )
+                                );
+
     nNewPos = (int)(nPixelPos/m_dPixelToRange);
     if (nNewPos > (m_nRangeMax - m_nRangeMin)/2)
         nNewPos++;
@@ -978,34 +965,26 @@ bool wxSlider::OS2OnScroll(
     }
     SetValue(nNewPos);
 
-    wxScrollEvent                   vEvent( eScrollEvent
-                                           ,m_windowId
-                                          );
+    wxScrollEvent vEvent( eScrollEvent, m_windowId );
 
     vEvent.SetPosition(nNewPos);
     vEvent.SetEventObject(this);
-    GetEventHandler()->ProcessEvent(vEvent);
+    HandleWindowEvent(vEvent);
 
-    wxCommandEvent                  vCevent( wxEVT_COMMAND_SLIDER_UPDATED
-                                            ,GetId()
-                                           );
+    wxCommandEvent vCevent( wxEVT_SLIDER, GetId() );
 
     vCevent.SetInt(nNewPos);
     vCevent.SetEventObject(this);
-    return (GetEventHandler()->ProcessEvent(vCevent));
+    return (HandleWindowEvent(vCevent));
 } // end of wxSlider::OS2OnScroll
 
-void wxSlider::SetLineSize(
-  int                               nLineSize
-)
+void wxSlider::SetLineSize( int nLineSize )
 {
     m_nLineSize = nLineSize;
 } // end of wxSlider::SetLineSize
 
 
-void wxSlider::SetPageSize(
-  int                               nPageSize
-)
+void wxSlider::SetPageSize( int nPageSize )
 {
     m_nPageSize = nPageSize;
 } // end of wxSlider::SetPageSize
@@ -1094,15 +1073,12 @@ void wxSlider::SetTick(
 } // end of wxSlider::SetTick
 
 // For trackbars only
-void wxSlider::SetTickFreq(
-  int                               n
-, int                               nPos
-)
+void wxSlider::DoSetTickFreq( int n )
 {
-    SLDCDATA                        vSlData;
-    WNDPARAMS                       vWndParams;
-    int                             nPixelPos;
-    int                             i;
+    SLDCDATA  vSlData;
+    WNDPARAMS vWndParams;
+    int       nPixelPos;
+    int       i;
 
     vSlData.cbSize = sizeof(SLDCDATA);
     if (m_windowStyle & wxSL_AUTOTICKS)
@@ -1110,8 +1086,8 @@ void wxSlider::SetTickFreq(
         vSlData.usScale1Spacing = 0;
         vSlData.usScale2Spacing = 0;
     }
-    vSlData.usScale1Increments = (m_nRangeMax - m_nRangeMin)/n;
-    vSlData.usScale2Increments = (m_nRangeMax - m_nRangeMin)/n;
+    vSlData.usScale1Increments = (USHORT)((m_nRangeMax - m_nRangeMin)/n);
+    vSlData.usScale2Increments = (USHORT)((m_nRangeMax - m_nRangeMin)/n);
 
     vWndParams.fsStatus = WPM_CTLDATA;
     vWndParams.cchText  = 0L;