]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/slider.cpp
use StretchDIBits() if we're drawing a DIB and not a DDB in Blit()
[wxWidgets.git] / src / os2 / slider.cpp
index 2a9101349e135da068a2c151b80c4a801b9ee637..0a6eb8f9854990a7d3d4549c571330f4ae206c1a 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <wx/utils.h>
 #include <wx/brush.h>
+#include <wx/scrolwin.h>
 #endif
 
 #include "wx/slider.h"
@@ -49,6 +50,125 @@ wxSlider::~wxSlider()
         ::WinDestroyWindow((HWND)m_hStaticValue);
 } // end of wxSlider::~wxSlider
 
+void wxSlider::AdjustSubControls(
+  int                               nX
+, int                               nY
+, int                               nWidth
+, int                               nHeight
+, int                               nSizeFlags
+)
+{
+    SWP                             vSwp;
+    int                             nXOffset = nX;
+    int                             nYOffset = nY;
+    int                             nCx;     // slider,min,max sizes
+    int                             nCy;
+    int                             nCyf;
+    char                            zBuf[300];
+
+    wxGetCharSize( GetHWND()
+                  ,&nCx
+                  ,&nCy
+                  ,&this->GetFont()
+                 );
+
+    if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL)
+    {
+        if (m_windowStyle & wxSL_LABELS )
+        {
+            int                     nMinLen = 0;
+            int                     nMaxLen = 0;
+
+            ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
+            GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
+
+            ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
+            GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
+
+            if (m_hStaticValue)
+            {
+                int                 nNewWidth = wxMax(nMinLen, nMaxLen);
+                int                 nValueHeight = nCyf;
+
+                ::WinSetWindowPos( (HWND)m_hStaticValue
+                                  ,HWND_TOP
+                                  ,(LONG)nXOffset - (nNewWidth + nCx + nMinLen + nCx)
+                                  ,(LONG)nYOffset
+                                  ,(LONG)nNewWidth
+                                  ,(LONG)nValueHeight
+                                  ,SWP_SIZE | SWP_MOVE
+                                 );
+            }
+            ::WinSetWindowPos( (HWND)m_hStaticMin
+                              ,HWND_TOP
+                              ,(LONG)nXOffset - (nMinLen + nCx)
+                              ,(LONG)nYOffset
+                              ,(LONG)nMinLen
+                              ,(LONG)nCyf
+                              ,SWP_SIZE | SWP_MOVE
+                             );
+            nXOffset += nWidth + nCx;
+
+            ::WinSetWindowPos( (HWND)m_hStaticMax
+                              ,HWND_TOP
+                              ,(LONG)nXOffset
+                              ,(LONG)nYOffset
+                              ,(LONG)nMaxLen
+                              ,(LONG)nCyf
+                              ,SWP_ZORDER | SWP_SHOW
+                             );
+        }
+    }
+    else
+    {
+        //
+        // Now deal with a vertical slider
+        //
+
+        if (m_windowStyle & wxSL_LABELS )
+        {
+            int                     nMinLen = 0;
+            int                     nMaxLen = 0;
+
+            ::WinQueryWindowText((HWND)m_hStaticMin, 300, zBuf);
+            GetTextExtent(zBuf, &nMinLen, &nCyf, NULL, NULL, &this->GetFont());
+
+            ::WinQueryWindowText((HWND)m_hStaticMax, 300, zBuf);
+            GetTextExtent(zBuf, &nMaxLen, &nCyf, NULL, NULL, &this->GetFont());
+
+            if (m_hStaticValue)
+            {
+                int                 nNewWidth = (wxMax(nMinLen, nMaxLen));
+
+                ::WinSetWindowPos( (HWND)m_hStaticValue
+                                  ,HWND_TOP
+                                  ,(LONG)nXOffset
+                                  ,(LONG)nYOffset + nHeight + nCyf
+                                  ,(LONG)nNewWidth
+                                  ,(LONG)nCyf
+                                  ,SWP_SIZE | SWP_MOVE
+                                 );
+            }
+            ::WinSetWindowPos( (HWND)m_hStaticMax
+                              ,HWND_TOP
+                              ,(LONG)nXOffset
+                              ,(LONG)nYOffset + nHeight
+                              ,(LONG)nMaxLen
+                              ,(LONG)nCyf
+                              ,SWP_SIZE | SWP_MOVE
+                             );
+            ::WinSetWindowPos( (HWND)m_hStaticMin
+                              ,HWND_TOP
+                              ,(LONG)nXOffset
+                              ,(LONG)nYOffset - nCyf
+                              ,(LONG)nMinLen
+                              ,(LONG)nCyf
+                              ,SWP_SIZE | SWP_MOVE
+                             );
+        }
+    }
+} // end of wxSlider::AdjustSubControls
+
 void wxSlider::ClearSel()
 {
 } // end of wxSlider::ClearSel
@@ -84,9 +204,7 @@ bool wxSlider::Create(
 , const wxPoint&                    rPos
 , const wxSize&                     rSize
 , long                              lStyle
-#if wxUSE_VALIDATORS
 , const wxValidator&                rValidator
-#endif
 , const wxString&                   rsName
 )
 {
@@ -145,6 +263,7 @@ bool wxSlider::Create(
         lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE;
         if (m_windowStyle & wxCLIP_SIBLINGS)
             lWstyle |= WS_CLIPSIBLINGS;
+
         m_hStaticMin = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
                                                  ,WC_STATIC                // Window class
                                                  ,(PSZ)wxBuffer            // Initial Text
@@ -163,9 +282,9 @@ bool wxSlider::Create(
 
     vSlData.cbSize = sizeof(SLDCDATA);
     if (m_windowStyle & wxSL_VERTICAL)
-        lMsStyle = SLS_VERTICAL | WS_VISIBLE | WS_TABSTOP;
+        lMsStyle = SLS_VERTICAL | SLS_HOMEBOTTOM | WS_VISIBLE | WS_TABSTOP;
     else
-        lMsStyle = SLS_HORIZONTAL | WS_VISIBLE | WS_TABSTOP;
+        lMsStyle = SLS_HORIZONTAL | SLS_HOMELEFT | WS_VISIBLE | WS_TABSTOP;
 
     if (m_windowStyle & wxCLIP_SIBLINGS)
         lMsStyle |= WS_CLIPSIBLINGS;
@@ -188,6 +307,7 @@ bool wxSlider::Create(
         lMsStyle |= SLS_PRIMARYSCALE1 | SLS_PRIMARYSCALE2;
     else
         lMsStyle |= SLS_PRIMARYSCALE2;
+    lMsStyle |= SLS_RIBBONSTRIP;
 
     m_nPageSize = ((nMaxValue - nMinValue)/10);
     vSlData.usScale1Increments = m_nPageSize;
@@ -199,7 +319,7 @@ bool wxSlider::Create(
                                                                    ,(ULONG)lMsStyle          // Style flags
                                                                    ,0L, 0L, 0L, 0L           // Origin -- 0 size
                                                                    ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
-                                                                   ,HWND_TOP                 // initial z position
+                                                                   ,HWND_BOTTOM                 // initial z position
                                                                    ,(HMENU)m_windowId       // Window identifier
                                                                    ,&vSlData                 // Slider control data
                                                                    ,NULL                     // no Presentation parameters
@@ -212,7 +332,7 @@ bool wxSlider::Create(
     //
     ::WinSendMsg( hScrollBar
                  ,SLM_SETTICKSIZE
-                 ,MPFROM2SHORT(SMA_SETALLTICKS, 6)
+                 ,MPFROM2SHORT(SMA_SETALLTICKS, (USHORT)12)
                  ,NULL
                 );
     //
@@ -227,7 +347,8 @@ bool wxSlider::Create(
     m_hWnd = (WXHWND)hScrollBar;
     SubclassWin(GetHWND());
     ::WinSetWindowText((HWND)m_hWnd, "");
-    SetFont(pParent->GetFont());
+
+    SetFont(*wxSMALL_FONT);
     if (m_windowStyle & wxSL_LABELS)
     {
         //
@@ -237,6 +358,7 @@ bool wxSlider::Create(
         lWstyle = SS_TEXT|DT_LEFT|WS_VISIBLE;
         if (m_windowStyle & wxCLIP_SIBLINGS)
             lMsStyle |= WS_CLIPSIBLINGS;
+
         m_hStaticMax = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
                                                  ,WC_STATIC                // Window class
                                                  ,(PSZ)wxBuffer            // Initial Text
@@ -268,6 +390,8 @@ bool wxSlider::Create(
         }
     }
 
+    SetXComp(0);
+    SetYComp(0);
     SetSize( nX
             ,nY
             ,nWidth
@@ -308,6 +432,34 @@ bool wxSlider::Create(
                       ,sizeof(LONG)
                       ,(PVOID)&lColor
                      );
+    lColor = (LONG)m_backgroundColour.GetPixel();
+    ::WinSetPresParam( m_hStaticMin
+                      ,PP_BACKGROUNDCOLOR
+                      ,sizeof(LONG)
+                      ,(PVOID)&lColor
+                     );
+    ::WinSetPresParam( m_hStaticMax
+                      ,PP_BACKGROUNDCOLOR
+                      ,sizeof(LONG)
+                      ,(PVOID)&lColor
+                     );
+    ::WinSetPresParam( m_hStaticValue
+                      ,PP_BACKGROUNDCOLOR
+                      ,sizeof(LONG)
+                      ,(PVOID)&lColor
+                     );
+    ::WinSetPresParam( m_hWnd
+                      ,PP_BACKGROUNDCOLOR
+                      ,sizeof(LONG)
+                      ,(PVOID)&lColor
+                     );
+    vColour.Set(wxString("BLUE"));
+    lColor = (LONG)vColour.GetPixel();
+    ::WinSetPresParam( m_hWnd
+                      ,PP_HILITEBACKGROUNDCOLOR
+                      ,sizeof(LONG)
+                      ,(PVOID)&lColor
+                     );
     SetValue(nValue);
     return TRUE;
 } // end of wxSlider::Create
@@ -345,24 +497,11 @@ void wxSlider::DoSetSize(
 
     if (pParent)
     {
-        //
-        // Under OS/2, where a frame window is the parent, most child windows
-        // that are not specific frame clients are actually children of the
-        // frame's client, not the frame itself, and so position themselves
-        // with regards to the client origin, not the frame.
-        //
-        if (pParent->IsKindOf(CLASSINFO(wxFrame)))
-        {
-            nYOffset = pParent->GetClientSize().y - (nYOffset + nOS2Height);
-            if (nY != -1)
-                nY1 = pParent->GetClientSize().y - (nY1 + nOS2Height);
-        }
-        else
-        {
-            nYOffset = pParent->GetSize().y - (nYOffset + nOS2Height);
-            if (nY != -1)
-                nY1 = pParent->GetSize().y - (nY1 + nOS2Height);
-        }
+        int                         nOS2ParentHeight = GetOS2ParentHeight(pParent);
+
+        nYOffset = nOS2ParentHeight - (nYOffset + nOS2Height);
+        if (nY != -1)
+            nY1 = nOS2ParentHeight - (nY1 + nOS2Height);
     }
     else
     {
@@ -373,6 +512,7 @@ void wxSlider::DoSetSize(
         if (nY != -1)
             nY1 = vRect.yTop - (nY1 + nOS2Height);
     }
+    m_nSizeFlags = nSizeFlags;
 
     GetPosition( &nCurrentX
                 ,&nCurrentY
@@ -422,7 +562,7 @@ void wxSlider::DoSetSize(
             ::WinSetWindowPos( (HWND)m_hStaticMin
                               ,HWND_TOP
                               ,(LONG)nXOffset
-                              ,(LONG)nYOffset - nCyf
+                              ,(LONG)nYOffset - (nCyf * 1.2)
                               ,(LONG)nMinLen
                               ,(LONG)nCy
                               ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
@@ -449,12 +589,20 @@ void wxSlider::DoSetSize(
                               ,(LONG)nSliderHeight
                               ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
                              );
+            ::WinQueryWindowPos(GetHwnd(), GetSwp());
+            ::WinSendMsg( GetHwnd()
+                         ,SLM_SETSLIDERINFO
+                         ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
+                                       ,0
+                                      )
+                         ,MPFROMLONG((ULONG)(nSliderHeight/2))
+                        );
             nXOffset += nSliderLength + nCx;
 
             ::WinSetWindowPos( (HWND)m_hStaticMax
                               ,HWND_TOP
                               ,(LONG)nXOffset
-                              ,(LONG)nYOffset - nCyf
+                              ,(LONG)nYOffset - (nCyf * 1.2)
                               ,(LONG)nMaxLen
                               ,(LONG)nCy
                               ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
@@ -507,33 +655,24 @@ void wxSlider::DoSetSize(
                 int              nNewWidth = wxMax(nMinLen, nMaxLen);
                 int              nValueHeight = nCyf;
 
-                nNewWidth += nCx;
-
-                //
-                // The height needs to be a bit bigger under Win95 if using native
-                // 3D effects.
-                //
-                nValueHeight = (int)(nValueHeight * 1.5);
                 ::WinSetWindowPos( (HWND)m_hStaticValue
                                   ,HWND_TOP
                                   ,(LONG)nXOffset
-                                  ,(LONG)nYOffset
+                                  ,(LONG)nYOffset + nHeight
                                   ,(LONG)nNewWidth
                                   ,(LONG)nValueHeight
                                   ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
                                  );
-                nYOffset -= nValueHeight;
-                nUsedHeight += nValueHeight;
+                nUsedHeight += nCyf;
             }
             ::WinSetWindowPos( (HWND)m_hStaticMin
                               ,HWND_TOP
                               ,(LONG)nXOffset
-                              ,(LONG)nYOffset
+                              ,(LONG)nYOffset + nHeight - nCyf
                               ,(LONG)nMinLen
                               ,(LONG)nCy
                               ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
                              );
-            nYOffset -= nCy;
             nUsedHeight += nCy;
 
             int                  nSliderLength = nHeight1 - (nUsedHeight + (2 * nCy));
@@ -548,20 +687,27 @@ void wxSlider::DoSetSize(
             if (nSliderLength < 100)
                 nSliderLength = 100;
 
-            ::WinSetWindowPos( (HWND)m_hStaticMin
+            ::WinSetWindowPos( GetHwnd()
                               ,HWND_TOP
                               ,(LONG)nXOffset
-                              ,(LONG)nYOffset
+                              ,(LONG)nYOffset + nCyf
                               ,(LONG)nSliderWidth
                               ,(LONG)nSliderLength
                               ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
                              );
-            nYOffset -= nSliderLength;
+            ::WinQueryWindowPos(GetHwnd(), GetSwp());
+            ::WinSendMsg( GetHwnd()
+                         ,SLM_SETSLIDERINFO
+                         ,MPFROM2SHORT( SMA_SHAFTDIMENSIONS
+                                       ,0
+                                      )
+                         ,MPFROMLONG((ULONG)(nSliderWidth/2))
+                        );
             nUsedHeight += nSliderLength;
             ::WinSetWindowPos( (HWND)m_hStaticMax
                               ,HWND_TOP
                               ,(LONG)nXOffset
-                              ,(LONG)nYOffset
+                              ,(LONG)nYOffset - nCyf
                               ,(LONG)nMaxLen
                               ,(LONG)nCy
                               ,SWP_ZORDER | SWP_SIZE | SWP_MOVE | SWP_SHOW
@@ -679,6 +825,16 @@ int wxSlider::GetSelStart() const
     return 0;
 } // end of wxSlider::GetSelStart
 
+void wxSlider::DoGetSize(
+  int*                              pnWidth
+, int*                              pnHeight
+) const
+{
+    GetSize( pnWidth
+            ,pnHeight
+           );
+} // end of wxSlider::DoGetSize
+
 void wxSlider::GetSize(
   int*                              pnWidth
 , int*                              pnHeight