]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/slider95.cpp
Implement wxMimeTypesManager on mac
[wxWidgets.git] / src / msw / slider95.cpp
index 260aee55654159e2ea9746e56d680d791423df42..5db488c88c865275609ea9c10e00f9087b99af2a 100644 (file)
@@ -161,6 +161,35 @@ wxSlider::Create(wxWindow *parent,
                  const wxValidator& validator,
                  const wxString& name)
 {
+    // our styles are redundant: wxSL_LEFT/RIGHT imply wxSL_VERTICAL and
+    // wxSL_TOP/BOTTOM imply wxSL_HORIZONTAL, but for backwards compatibility
+    // reasons we can't really change it, instead try to infer the orientation
+    // from the flags given to us here
+    switch ( style & (wxSL_LEFT | wxSL_RIGHT | wxSL_TOP | wxSL_BOTTOM) )
+    {
+        case wxSL_LEFT:
+        case wxSL_RIGHT:
+            style |= wxSL_VERTICAL;
+            break;
+
+        case wxSL_TOP:
+        case wxSL_BOTTOM:
+            style |= wxSL_HORIZONTAL;
+            break;
+
+        case 0:
+            // no specific direction, do we have at least the orientation?
+            if ( !(style & (wxSL_HORIZONTAL | wxSL_VERTICAL)) )
+            {
+                // no, choose default
+                style |= wxSL_BOTTOM | wxSL_HORIZONTAL;
+            }
+    };
+
+    wxASSERT_MSG( !(style & wxSL_VERTICAL) | !(style & wxSL_HORIZONTAL),
+                    _T("incompatible slider direction and orientation") );
+
+
     // initialize everything
     if ( !CreateControl(parent, id, pos, size, style, validator, name) )
         return false;
@@ -223,24 +252,29 @@ WXDWORD wxSlider::MSWGetStyle(long style, WXDWORD *exstyle) const
 {
     WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
 
-    // TBS_HORZ is 0 anyhow, but do mention it explicitly for clarity
+    // TBS_HORZ, TBS_RIGHT and TBS_BOTTOM are 0 but do include them for clarity
     msStyle |= style & wxSL_VERTICAL ? TBS_VERT : TBS_HORZ;
 
-    if ( style & wxSL_AUTOTICKS )
-        msStyle |= TBS_AUTOTICKS ;
-
-    // again, TBS_RIGHT is 0 but do include it for clarity
-    if ( style & wxSL_LEFT )
-        msStyle |= TBS_LEFT;
-    else if ( style & wxSL_RIGHT )
-        msStyle |= TBS_RIGHT;
-    else if ( style & wxSL_TOP )
-        msStyle |= TBS_TOP;
-    else if ( style & wxSL_BOTTOM )
-        msStyle |= TBS_BOTTOM;
-    else if ( style & wxSL_BOTH )
+    if ( style & wxSL_BOTH )
+    {
+        // this fully specifies the style combined with TBS_VERT/HORZ above
         msStyle |= TBS_BOTH;
-    else if ( !(style & wxSL_AUTOTICKS) )
+    }
+    else // choose one direction
+    {
+        if ( style & wxSL_LEFT )
+            msStyle |= TBS_LEFT;
+        else if ( style & wxSL_RIGHT )
+            msStyle |= TBS_RIGHT;
+        else if ( style & wxSL_TOP )
+            msStyle |= TBS_TOP;
+        else if ( style & wxSL_BOTTOM )
+            msStyle |= TBS_BOTTOM;
+    }
+
+    if ( style & wxSL_AUTOTICKS )
+        msStyle |= TBS_AUTOTICKS;
+    else
         msStyle |= TBS_NOTICKS;
 
     if ( style & wxSL_SELRANGE )
@@ -468,13 +502,16 @@ wxSize wxSlider::DoGetBestSize() const
 {
     // these values are arbitrary
     static const int length = 100;
-    static const int thickness = 26;
+    static const int thumb = 24;
+    static const int ticks = 8;
 
+    int *width;
     wxSize size;
     if ( HasFlag(wxSL_VERTICAL) )
     {
-        size.x = thickness;
+        size.x = thumb;
         size.y = length;
+        width = &size.x;
 
         if ( m_labels )
         {
@@ -491,7 +528,8 @@ wxSize wxSlider::DoGetBestSize() const
     else // horizontal
     {
         size.x = length;
-        size.y = thickness;
+        size.y = thumb;
+        width = &size.y;
 
         if ( m_labels )
         {
@@ -500,6 +538,16 @@ wxSize wxSlider::DoGetBestSize() const
         }
     }
 
+    // need extra space to show ticks
+    if ( HasFlag(wxSL_TICKS) )
+    {
+        *width += ticks;
+
+        // and maybe twice as much if we show them on both sides
+        if ( HasFlag(wxSL_BOTH) )
+            *width += ticks;
+    }
+
     return size;
 }
 
@@ -527,7 +575,8 @@ void wxSlider::SetRange(int minValue, int maxValue)
     m_rangeMin = minValue;
     m_rangeMax = maxValue;
 
-    ::SendMessage(GetHwnd(), TBM_SETRANGE, TRUE, MAKELONG(minValue, maxValue));
+    ::SendMessage(GetHwnd(), TBM_SETRANGEMIN, TRUE, m_rangeMin);
+    ::SendMessage(GetHwnd(), TBM_SETRANGEMAX, TRUE, m_rangeMax);
 
     if ( m_labels )
     {