Add wxControl::GetSizeFromTextSize() to size the control to its text.
This function can be used to size a, say, wxTextCtrl to be exactly of the size needed to enter the given amount of text in it. This patch adds wxGTK implementation for wxTextCtrl, wxChoice and wxCombobox; changes to the samples and the documentation. Closes #14812. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72935 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -86,24 +86,9 @@ wxSize wxControl::DoGetBestSize() const
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkRequisition req;
|
||||
#ifdef __WXGTK3__
|
||||
if (gtk_widget_get_request_mode(m_widget) != GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
|
||||
{
|
||||
gtk_widget_get_preferred_height(m_widget, NULL, &req.height);
|
||||
gtk_widget_get_preferred_width_for_height(m_widget, req.height, NULL, &req.width);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_get_preferred_width(m_widget, NULL, &req.width);
|
||||
gtk_widget_get_preferred_height_for_width(m_widget, req.width, NULL, &req.height);
|
||||
}
|
||||
#else
|
||||
GTK_WIDGET_GET_CLASS(m_widget)->size_request(m_widget, &req);
|
||||
#endif
|
||||
best.Set(req.width, req.height);
|
||||
best = GTKGetPreferredSize(m_widget);
|
||||
}
|
||||
CacheBestSize(best);
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
@@ -364,4 +349,58 @@ wxControl::GetDefaultAttributesFromGTKWidget(wxGtkWidgetNewFromAdj_t widget_new,
|
||||
return attr;
|
||||
}
|
||||
|
||||
// This is not the same as GetBestSize() because that size may have
|
||||
// been recalculated and cached by us. We want GTK+ information.
|
||||
wxSize wxControl::GTKGetPreferredSize(GtkWidget* widget) const
|
||||
{
|
||||
GtkRequisition req;
|
||||
#ifdef __WXGTK3__
|
||||
if (gtk_widget_get_request_mode(widget) != GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
|
||||
{
|
||||
gtk_widget_get_preferred_height(widget, NULL, &req.height);
|
||||
gtk_widget_get_preferred_width_for_height(widget, req.height, NULL, &req.width);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_get_preferred_width(widget, NULL, &req.width);
|
||||
gtk_widget_get_preferred_height_for_width(widget, req.width, NULL, &req.height);
|
||||
}
|
||||
#else
|
||||
GTK_WIDGET_GET_CLASS(widget)->size_request(widget, &req);
|
||||
#endif
|
||||
|
||||
return wxSize(req.width, req.height);
|
||||
}
|
||||
|
||||
wxPoint wxControl::GTKGetEntryMargins(GtkEntry* entry) const
|
||||
{
|
||||
wxPoint marg(0, 0);
|
||||
|
||||
#ifndef __WXGTK3__
|
||||
#if GTK_CHECK_VERSION(2,10,0)
|
||||
// The margins we have previously set
|
||||
const GtkBorder* border = gtk_entry_get_inner_border(entry);
|
||||
if ( border )
|
||||
{
|
||||
marg.x = border->left + border->right;
|
||||
marg.y = border->top + border->bottom;
|
||||
}
|
||||
#endif // GTK+ 2.10+
|
||||
#else // GTK+ 3
|
||||
// Gtk3 does not use inner border, but StyleContext and CSS
|
||||
// TODO: implement it, starting with wxTextEntry::DoSetMargins()
|
||||
#endif // GTK+ 2/3
|
||||
|
||||
int x, y;
|
||||
gtk_entry_get_layout_offsets(entry, &x, &y);
|
||||
// inner borders are included. Substract them so we can get other margins
|
||||
x -= marg.x;
|
||||
y -= marg.y;
|
||||
marg.x += 2 * x + 2;
|
||||
marg.y += 2 * y + 2;
|
||||
|
||||
return marg;
|
||||
}
|
||||
|
||||
|
||||
#endif // wxUSE_CONTROLS
|
||||
|
Reference in New Issue
Block a user