]> git.saurik.com Git - wxWidgets.git/commitdiff
Added GetWidestItem() and GetWidestItemWidth() to wxVListBoxComboPopup
authorAlex Bligh <alex@alex.org.uk>
Thu, 6 Jul 2006 17:42:39 +0000 (17:42 +0000)
committerAlex Bligh <alex@alex.org.uk>
Thu, 6 Jul 2006 17:42:39 +0000 (17:42 +0000)
and wxOwnerDrawnComboBox as per Jaakko Salli

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

include/wx/odcombo.h
src/generic/odcombo.cpp

index c775096e31f1703725b9dc870025139ebb6d58ab..451ab90e732f4958767e1334aa0432281321f726 100644 (file)
@@ -157,6 +157,12 @@ protected:
     void OnKey(wxKeyEvent& event);
     void OnLeftClick(wxMouseEvent& event);
 
+    // Return the widest item width (recalculating it if necessary)
+    int GetWidestItemWidth() { CalcWidths(); return m_widestWidth; }
+
+    // Return the index of the widest item (recalculating it if necessary)
+    int GetWidestItem() { CalcWidths(); return m_widestItem; }
+
     wxArrayString           m_strings;
     wxArrayPtrVoid          m_clientDatas;
 
@@ -189,6 +195,9 @@ private:
     // has the mouse been released on this control?
     bool                    m_clicked;
 
+    // Recalculate widths if they are dirty
+    void CalcWidths();
+
     DECLARE_EVENT_TABLE()
 };
 
@@ -293,6 +302,12 @@ public:
         wxComboCtrl::SetSelection(from,to);
     }
 
+    // Return the widest item width (recalculating it if necessary)
+    virtual int GetWidestItemWidth() { EnsurePopupControl(); return GetVListBoxComboPopup()->GetWidestItemWidth(); }
+
+    // Return the index of the widest item (recalculating it if necessary)
+    virtual int GetWidestItem() { EnsurePopupControl(); return GetVListBoxComboPopup()->GetWidestItem(); }
+
     wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST
 
 protected:
index 969d674f1d3a4a4d7b679cf2baf1e832445d152d..f824fa3670173d257805c9e679cbfbc2601a9218 100644 (file)
@@ -516,36 +516,8 @@ void wxVListBoxComboPopup::SetStringValue( const wxString& value )
         wxVListBox::SetSelection(index);
 }
 
-wxSize wxVListBoxComboPopup::GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
+void wxVListBoxComboPopup::CalcWidths()
 {
-    int height = 250;
-
-    if ( m_strings.GetCount() )
-    {
-        if ( prefHeight > 0 )
-            height = prefHeight;
-
-        if ( height > maxHeight )
-            height = maxHeight;
-
-        int totalHeight = GetTotalHeight(); // + 3;
-        if ( height >= totalHeight )
-        {
-            height = totalHeight;
-        }
-        else
-        {
-            // Adjust height to a multiple of the height of the first item
-            // NB: Calculations that take variable height into account
-            //     are unnecessary.
-            int fih = GetLineHeight(0);
-            int shown = height/fih;
-            height = shown * fih;
-        }
-    }
-    else
-        height = 50;
-
     bool doFindWidest = m_findWidest;
 
     // Measure items with dirty width.
@@ -631,6 +603,39 @@ wxSize wxVListBoxComboPopup::GetAdjustedSize( int minWidth, int prefHeight, int
 
         m_findWidest = false;
     }
+}
+
+wxSize wxVListBoxComboPopup::GetAdjustedSize( int minWidth, int prefHeight, int maxHeight )
+{
+    int height = 250;
+
+    if ( m_strings.GetCount() )
+    {
+        if ( prefHeight > 0 )
+            height = prefHeight;
+
+        if ( height > maxHeight )
+            height = maxHeight;
+
+        int totalHeight = GetTotalHeight(); // + 3;
+        if ( height >= totalHeight )
+        {
+            height = totalHeight;
+        }
+        else
+        {
+            // Adjust height to a multiple of the height of the first item
+            // NB: Calculations that take variable height into account
+            //     are unnecessary.
+            int fih = GetLineHeight(0);
+            int shown = height/fih;
+            height = shown * fih;
+        }
+    }
+    else
+        height = 50;
+
+    CalcWidths();
 
     // Take scrollbar into account in width calculations
     int widestWidth = m_widestWidth + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);