]> git.saurik.com Git - wxWidgets.git/commitdiff
Ensure that combobox editor used by wxGrid is tall enough.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 25 Feb 2012 23:49:55 +0000 (23:49 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 25 Feb 2012 23:49:55 +0000 (23:49 +0000)
Set the rectangle of wxGridCellChoiceEditor to be at least as tall as the best
(i.e. minimal) wxComboBox size because otherwise the control can be unusable.

Closes #13818.

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

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

index e76e61957601bcc71ceb8c2967ac4f0d3beb790b..4a7b9270ddf696a900592cf5253b16d8e41ecee9 100644 (file)
@@ -295,6 +295,8 @@ public:
                         wxWindowID id,
                         wxEvtHandler* evtHandler);
 
+    virtual void SetSize(const wxRect& rect);
+
     virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
 
     virtual void BeginEdit(int row, int col, wxGrid* grid);
index 835ca10e7184a16064aa94eb44268174d2b87c0d..6af6ad1462735bf873ddbb81f11b501b78015559 100644 (file)
@@ -1414,6 +1414,29 @@ void wxGridCellChoiceEditor::Create(wxWindow* parent,
     wxGridCellEditor::Create(parent, id, evtHandler);
 }
 
+void wxGridCellChoiceEditor::SetSize(const wxRect& rect)
+{
+    wxASSERT_MSG(m_control,
+                 wxT("The wxGridCellChoiceEditor must be created first!"));
+
+    // Check that the height is not too small to fit the combobox.
+    wxRect rectTallEnough = rect;
+    const wxSize bestSize = m_control->GetBestSize();
+    const wxCoord diffY = bestSize.GetHeight() - rectTallEnough.GetHeight();
+    if ( diffY > 0 )
+    {
+        // Do make it tall enough.
+        rectTallEnough.height += diffY;
+
+        // Also centre the effective rectangle vertically with respect to the
+        // original one.
+        rectTallEnough.y -= diffY/2;
+    }
+    //else: The rectangle provided is already tall enough.
+
+    wxGridCellEditor::SetSize(rectTallEnough);
+}
+
 void wxGridCellChoiceEditor::PaintBackground(const wxRect& rectCell,
                                              wxGridCellAttr * attr)
 {