From: Włodzimierz Skiba <abx@abx.art.pl>
Date: Mon, 17 Jul 2006 08:45:12 +0000 (+0000)
Subject: [ 1519202 ] wxComboCtrl::SetButtonPosition() to support -1 width/height
X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7dc234d633e255de95f17d62d513d0525efad1af?ds=inline

[ 1519202 ] wxComboCtrl::SetButtonPosition() to support -1 width/height


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40158 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---

diff --git a/docs/latex/wx/comboctrl.tex b/docs/latex/wx/comboctrl.tex
index f7b7921cfb..1506f07e2e 100644
--- a/docs/latex/wx/comboctrl.tex
+++ b/docs/latex/wx/comboctrl.tex
@@ -289,6 +289,13 @@ Returns depressed button bitmap that has been set with
 A reference to the depressed state bitmap.
 
 
+\membersection{wxComboCtrl::GetButtonSize}\label{wxcomboctrlgetbuttonsize}
+
+\func{wxSize}{GetButtonSize}{\void}
+
+Returns current size of the dropdown button.
+
+
 \membersection{wxComboCtrl::GetCustomPaintWidth}\label{wxcomboctrlgetcustompaintwidth}
 
 \constfunc{int}{GetCustomPaintWidth}{\void}
@@ -466,15 +473,14 @@ different kind of button on mouse hover.}
 
 \membersection{wxComboCtrl::SetButtonPosition}\label{wxcomboctrlsetbuttonposition}
 
-\func{void}{SetButtonPosition}{\param{int }{width = 0}, \param{int }{height = 0}, \param{int }{side = wxRIGHT}, \param{int }{spacingX = 0}}
+\func{void}{SetButtonPosition}{\param{int }{width = -1}, \param{int }{height = -1}, \param{int }{side = wxRIGHT}, \param{int }{spacingX = 0}}
 
 Sets size and position of dropdown button.
 
 \wxheading{Parameters}
 
-\docparam{width}{If > $0$, defines specific button width. $0$ means platform default,
-while negative numbers allow adjusting smaller than default.}
-\docparam{height}{Same as width.}
+\docparam{width}{Button width. Value <= $0$ specifies default.}
+\docparam{height}{Button height. Value <= $0$ specifies default.}
 \docparam{side}{Indicates which side the button will be placed.
 Value can be {\tt wxLEFT} or {\tt wxRIGHT}.}
 \docparam{spacingX}{Horizontal spacing around the button. Default is $0$.}
diff --git a/include/wx/combo.h b/include/wx/combo.h
index fdece4b675..2c7b1b7faf 100644
--- a/include/wx/combo.h
+++ b/include/wx/combo.h
@@ -252,17 +252,19 @@ public:
     }
 
     // Set position of dropdown button.
-    //   width: 0 > for specific custom width, negative to adjust to smaller than default
-    //   height: 0 > for specific custom height, negative to adjust to smaller than default
+    //   width: button width. <= 0 for default.
+    //   height: button height. <= 0 for default.
     //   side: wxLEFT or wxRIGHT, indicates on which side the button will be placed.
     //   spacingX: empty space on sides of the button. Default is 0.
     // Remarks:
     //   There is no spacingY - the button will be centered vertically.
-    void SetButtonPosition( int width = 0,
-                            int height = 0,
+    void SetButtonPosition( int width = -1,
+                            int height = -1,
                             int side = wxRIGHT,
                             int spacingX = 0 );
 
+    // Returns current size of the dropdown button.
+    wxSize GetButtonSize();
 
     //
     // Sets dropbutton to be drawn with custom bitmaps.
diff --git a/samples/combo/combo.cpp b/samples/combo/combo.cpp
index 51e8a869ce..a136903a67 100644
--- a/samples/combo/combo.cpp
+++ b/samples/combo/combo.cpp
@@ -699,8 +699,11 @@ MyFrame::MyFrame(const wxString& title)
 
 
     odc->SetSelection(0);
-    odc->SetButtonPosition(-2, // width adjustment
-                           -6, // height adjustment
+
+    // Use button size that is slightly smaller than the default.
+    wxSize butSize = odc->GetButtonSize();
+    odc->SetButtonPosition(butSize.x - 2, // button width
+                           butSize.y - 6, // button height
                            wxLEFT, // side
                            2 // horizontal spacing
                           );
@@ -769,8 +772,8 @@ MyFrame::MyFrame(const wxString& title)
     gcc->SetValue(wxT("Subitem 05"));
 
     // Move button to left - it makes more sense for a tree ctrl
-    gcc->SetButtonPosition(0, // width adjustment
-                           0, // height adjustment
+    gcc->SetButtonPosition(-1, // button width
+                           -1, // button height
                            wxLEFT, // side
                            0 // horizontal spacing
                           );
diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp
index 30b35a7dd0..07ab83c061 100644
--- a/src/common/combocmn.cpp
+++ b/src/common/combocmn.cpp
@@ -681,7 +681,7 @@ void wxComboCtrlBase::Init()
     m_btnState = 0;
     m_btnWidDefault = 0;
     m_blankButtonBg = false;
-    m_btnWid = m_btnHei = 0;
+    m_btnWid = m_btnHei = -1;
     m_btnSide = wxRIGHT;
     m_btnSpacingX = 0;
 
@@ -813,7 +813,7 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth )
     if ( ( (m_iFlags & wxCC_BUTTON_OUTSIDE_BORDER) ||
                 (m_bmpNormal.Ok() && m_blankButtonBg) ) &&
          m_btnSpacingX == 0 &&
-         m_btnHei == 0 )
+         m_btnHei <= 0 )
     {
         m_iFlags |= wxCC_IFLAG_BUTTON_OUTSIDE;
         btnBorder = 0;
@@ -841,9 +841,7 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth )
     int butHeight = sz.y - btnBorder*2;
 
     // Adjust button width
-    if ( m_btnWid < 0 )
-        butWidth += m_btnWid;
-    else if ( m_btnWid > 0 )
+    if ( m_btnWid > 0 )
         butWidth = m_btnWid;
     else
     {
@@ -865,9 +863,7 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth )
     }
 
     // Adjust button height
-    if ( m_btnHei < 0 )
-        butHeight += m_btnHei;
-    else if ( m_btnHei > 0 )
+    if ( m_btnHei > 0 )
         butHeight = m_btnHei;
 
     // Use size of normal bitmap if...
@@ -1857,7 +1853,7 @@ void wxComboCtrlBase::HidePopup()
 // ----------------------------------------------------------------------------
 
 void wxComboCtrlBase::SetButtonPosition( int width, int height,
-                                            int side, int spacingX )
+                                         int side, int spacingX )
 {
     m_btnWid = width;
     m_btnHei = height;
@@ -1867,6 +1863,25 @@ void wxComboCtrlBase::SetButtonPosition( int width, int height,
     RecalcAndRefresh();
 }
 
+wxSize wxComboCtrlBase::GetButtonSize()
+{
+    if ( m_btnSize.x > 0 )
+        return m_btnSize;
+
+    wxSize retSize(m_btnWid,m_btnHei);
+
+    // Need to call CalculateAreas now if button size is
+    // is not explicitly specified.
+    if ( retSize.x <= 0 || retSize.y <= 0)
+    {
+        OnResize();
+
+        retSize = m_btnSize;
+    }
+
+    return retSize;
+}
+
 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal,
                                            bool blankButtonBg,
                                            const wxBitmap& bmpPressed,