]> git.saurik.com Git - wxWidgets.git/commitdiff
[ 1519202 ] wxComboCtrl::SetButtonPosition() to support -1 width/height
authorWłodzimierz Skiba <abx@abx.art.pl>
Mon, 17 Jul 2006 08:45:12 +0000 (08:45 +0000)
committerWłodzimierz Skiba <abx@abx.art.pl>
Mon, 17 Jul 2006 08:45:12 +0000 (08:45 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40158 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/comboctrl.tex
include/wx/combo.h
samples/combo/combo.cpp
src/common/combocmn.cpp

index f7b7921cfbed01d2be7dde419ca730731e1a678b..1506f07e2eb1cbcf2e730189db0975662020355a 100644 (file)
@@ -289,6 +289,13 @@ Returns depressed button bitmap that has been set with
 A reference to the depressed state bitmap.
 
 
 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}
 \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}
 
 
 \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}
 
 
 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$.}
 \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$.}
index fdece4b675f4c09f88cd9d5962ce08bbedead3fc..2c7b1b7faf0860525bee925a72d7aa67c19d5ae7 100644 (file)
@@ -252,17 +252,19 @@ public:
     }
 
     // Set position of dropdown button.
     }
 
     // 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.
     //   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 );
 
                             int side = wxRIGHT,
                             int spacingX = 0 );
 
+    // Returns current size of the dropdown button.
+    wxSize GetButtonSize();
 
     //
     // Sets dropbutton to be drawn with custom bitmaps.
 
     //
     // Sets dropbutton to be drawn with custom bitmaps.
index 51e8a869ce8fc6604b0b307e6eb49217299c7d79..a136903a679e3b1746c70d81791daced1517250a 100644 (file)
@@ -699,8 +699,11 @@ MyFrame::MyFrame(const wxString& title)
 
 
     odc->SetSelection(0);
 
 
     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
                           );
                            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->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
                           );
                            wxLEFT, // side
                            0 // horizontal spacing
                           );
index 30b35a7dd0b8d502e7f1e131bdaaf45b7e6eb4d9..07ab83c061ac6705e47f1c58417431a0e198a252 100644 (file)
@@ -681,7 +681,7 @@ void wxComboCtrlBase::Init()
     m_btnState = 0;
     m_btnWidDefault = 0;
     m_blankButtonBg = false;
     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;
 
     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 &&
     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;
     {
         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
     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
     {
         butWidth = m_btnWid;
     else
     {
@@ -865,9 +863,7 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth )
     }
 
     // Adjust button height
     }
 
     // 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...
         butHeight = m_btnHei;
 
     // Use size of normal bitmap if...
@@ -1857,7 +1853,7 @@ void wxComboCtrlBase::HidePopup()
 // ----------------------------------------------------------------------------
 
 void wxComboCtrlBase::SetButtonPosition( int width, int height,
 // ----------------------------------------------------------------------------
 
 void wxComboCtrlBase::SetButtonPosition( int width, int height,
-                                            int side, int spacingX )
+                                         int side, int spacingX )
 {
     m_btnWid = width;
     m_btnHei = height;
 {
     m_btnWid = width;
     m_btnHei = height;
@@ -1867,6 +1863,25 @@ void wxComboCtrlBase::SetButtonPosition( int width, int height,
     RecalcAndRefresh();
 }
 
     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,
 void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal,
                                            bool blankButtonBg,
                                            const wxBitmap& bmpPressed,