protected:
// override the base class virtuals involved into geometry calculations
virtual wxSize DoGetBestSize() const;
+ virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
virtual void DoMoveWindow(int x, int y, int width, int height);
#ifdef __WXMSW__
void GtkEnableEvents() const;
virtual wxSize DoGetBestSize() const;
+ virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const;
// Widgets that use the style->base colour for the BG colour should
virtual void DoGetPosition(int *x, int *y) const;
virtual void DoMoveWindow(int x, int y, int width, int height);
virtual wxSize DoGetBestSize() const;
+ virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
virtual void DoGetSize(int *width, int *height) const;
virtual void DoGetClientSize(int *x, int *y) const;
#if wxUSE_TOOLTIPS
m_min = minNew;
m_max = maxNew;
+ wxString smax('9', m_textMax->GetValue().length());
+ wxSize
+ size = m_spinctrl->GetSizeFromTextSize(m_spinctrl->GetTextExtent(smax));
+
+ m_spinctrl->SetMinSize(size);
+ m_spinctrl->SetSize(size);
+
+ smax += ".0";
+ size = m_spinctrldbl->GetSizeFromTextSize(
+ m_spinctrldbl->GetTextExtent(smax)
+ );
+ m_spinctrldbl->SetMinSize(size);
+ m_spinctrldbl->SetSize(size);
m_spinbtn->SetRange(minNew, maxNew);
m_spinctrl->SetRange(minNew, maxNew);
(*it)->SetFont(m_font);
(*it)->Refresh();
}
+
+ // The best size of the widget could have changed after changing its font,
+ // so re-layout to show it correctly.
+ page->Layout();
#else
wxLogMessage(wxT("Font selection dialog not available in current build."));
#endif
wxSize wxSpinCtrlGenericBase::DoGetBestSize() const
{
- wxSize sizeBtn = m_spinButton->GetBestSize(),
- sizeText = m_textCtrl->GetBestSize();
+ return DoGetSizeFromTextSize(m_textCtrl->GetBestSize().x, -1);
+}
+
+wxSize wxSpinCtrlGenericBase::DoGetSizeFromTextSize(int xlen, int ylen) const
+{
+ wxSize sizeBtn = m_spinButton->GetBestSize();
+ wxSize totalS( m_textCtrl->GetBestSize() );
+
+ wxSize tsize(xlen + sizeBtn.x + MARGIN, totalS.y);
+#if defined(__WXMSW__)
+ tsize.IncBy(0.4 * totalS.y + 4, 0);
+#elif defined(__WXGTK__)
+ tsize.IncBy(totalS.y + 10, 0);
+#endif // MSW GTK
+
+ // Check if the user requested a non-standard height.
+ if ( ylen > 0 )
+ tsize.IncBy(0, ylen - GetCharHeight());
- return wxSize(sizeBtn.x + sizeText.x + MARGIN, sizeText.y);
+ return tsize;
}
void wxSpinCtrlGenericBase::DoMoveWindow(int x, int y, int width, int height)
wxSize wxSpinCtrlGTKBase::DoGetBestSize() const
{
- wxSize ret( wxControl::DoGetBestSize() );
- wxSize best(95, ret.y); // FIXME: 95?
- CacheBestSize(best);
- return best;
+ return DoGetSizeFromTextSize(95); // TODO: 95 is completely arbitrary
+}
+
+wxSize wxSpinCtrlGTKBase::DoGetSizeFromTextSize(int xlen, int ylen) const
+{
+ wxASSERT_MSG( m_widget, wxS("GetSizeFromTextSize called before creation") );
+
+ // Set an as small as possible size for the control, so preferred sizes
+ // return "natural" sizes, not taking into account the previous ones (which
+ // seems to be GTK+3 behaviour)
+ gtk_widget_set_size_request(m_widget, 0, 0);
+
+ // Both Gtk+2 and Gtk+3 use current value/range to measure control's width.
+ // So, we can't ask Gtk+ for its width. Instead, we used hardcoded values.
+
+ // Returned height is OK
+ wxSize totalS = GTKGetPreferredSize(m_widget);
+
+#if GTK_CHECK_VERSION(3,4,0)
+ // two buttons in horizontal
+ totalS.x = 46 + 15; // margins included
+#else
+ // two small buttons in vertical
+ totalS.x = GetFont().GetPixelSize().y + 13; // margins included
+#endif
+
+ wxSize tsize(xlen + totalS.x, totalS.y);
+
+ // Check if the user requested a non-standard height.
+ if ( ylen > 0 )
+ tsize.IncBy(0, ylen - GetCharHeight());
+
+ return tsize;
}
// static
// ----------------------------------------------------------------------------
wxSize wxSpinCtrl::DoGetBestSize() const
+{
+ return DoGetSizeFromTextSize(DEFAULT_ITEM_WIDTH);
+}
+
+wxSize wxSpinCtrl::DoGetSizeFromTextSize(int xlen, int ylen) const
{
wxSize sizeBtn = wxSpinButton::DoGetBestSize();
- sizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN;
int y;
wxGetCharSize(GetHWND(), NULL, &y, GetFont());
- y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(y);
-
// JACS: we should always use the height calculated
// from above, because otherwise we'll get a spin control
// that's too big. So never use the height calculated
// from wxSpinButton::DoGetBestSize().
- // if ( sizeBtn.y < y )
- {
- // make the text tall enough
- sizeBtn.y = y;
- }
+ wxSize tsize(xlen + sizeBtn.x + MARGIN_BETWEEN + 0.3 * y + 10,
+ EDIT_HEIGHT_FROM_CHAR_HEIGHT(y));
+
+ // Check if the user requested a non-standard height.
+ if ( ylen > 0 )
+ tsize.IncBy(0, ylen - y);
- return sizeBtn;
+ return tsize;
}
void wxSpinCtrl::DoMoveWindow(int x, int y, int width, int height)