Simplify GetDefaultAttributesFromGTKWidget() by passing the widget to use,
rather than a pointer to a function to create the widget git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73010 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -18,13 +18,6 @@ typedef struct _GtkEntry GtkEntry;
|
||||
// wxControl
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// C-linkage function pointer types for GetDefaultAttributesFromGTKWidget
|
||||
extern "C" {
|
||||
typedef GtkWidget* (*wxGtkWidgetNew_t)(void);
|
||||
typedef GtkWidget* (*wxGtkWidgetNewFromStr_t)(const char*);
|
||||
typedef GtkWidget* (*wxGtkWidgetNewFromAdj_t)(GtkAdjustment*);
|
||||
}
|
||||
|
||||
class WXDLLIMPEXP_CORE wxControl : public wxControlBase
|
||||
{
|
||||
typedef wxControlBase base_type;
|
||||
@@ -80,19 +73,6 @@ protected:
|
||||
GetDefaultAttributesFromGTKWidget(GtkWidget* widget,
|
||||
bool useBase = false,
|
||||
int state = 0);
|
||||
static wxVisualAttributes
|
||||
GetDefaultAttributesFromGTKWidget(wxGtkWidgetNew_t,
|
||||
bool useBase = false,
|
||||
int state = 0);
|
||||
static wxVisualAttributes
|
||||
GetDefaultAttributesFromGTKWidget(wxGtkWidgetNewFromStr_t,
|
||||
bool useBase = false,
|
||||
int state = 0);
|
||||
|
||||
static wxVisualAttributes
|
||||
GetDefaultAttributesFromGTKWidget(wxGtkWidgetNewFromAdj_t,
|
||||
bool useBase = false,
|
||||
int state = 0);
|
||||
|
||||
// Widgets that use the style->base colour for the BG colour should
|
||||
// override this and return true.
|
||||
|
@@ -95,7 +95,7 @@ GdkWindow *wxAnyButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
|
||||
wxVisualAttributes
|
||||
wxAnyButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_button_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_button_new());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@@ -334,7 +334,7 @@ wxSize wxButton::DoGetBestSize() const
|
||||
wxVisualAttributes
|
||||
wxButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_button_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_button_new());
|
||||
}
|
||||
|
||||
#endif // wxUSE_BUTTON
|
||||
|
@@ -236,7 +236,7 @@ GdkWindow *wxCheckBox::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
|
||||
wxVisualAttributes
|
||||
wxCheckBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_check_button_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_check_button_new());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -393,7 +393,7 @@ void wxChoice::DoApplyWidgetStyle(GtkRcStyle *style)
|
||||
wxVisualAttributes
|
||||
wxChoice::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_combo_box_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_combo_box_new());
|
||||
}
|
||||
|
||||
|
||||
|
@@ -290,9 +290,9 @@ wxVisualAttributes
|
||||
wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
#ifdef __WXGTK3__
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_combo_box_new_with_entry, true);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_combo_box_new_with_entry(), true);
|
||||
#else
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_combo_box_entry_new, true);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_combo_box_entry_new(), true);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -234,6 +234,14 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget,
|
||||
int state)
|
||||
{
|
||||
wxVisualAttributes attr;
|
||||
|
||||
GtkWidget* tlw = NULL;
|
||||
if (gtk_widget_get_parent(widget) == NULL)
|
||||
{
|
||||
tlw = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_container_add(GTK_CONTAINER(tlw), widget);
|
||||
}
|
||||
|
||||
#ifdef __WXGTK3__
|
||||
GtkStateFlags stateFlag = GTK_STATE_FLAG_NORMAL;
|
||||
if (state)
|
||||
@@ -258,11 +266,8 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget,
|
||||
if (!style)
|
||||
style = gtk_widget_get_default_style();
|
||||
|
||||
if (!style)
|
||||
if (style)
|
||||
{
|
||||
return wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL);
|
||||
}
|
||||
|
||||
// get the style's colours
|
||||
attr.colFg = wxColour(style->fg[state]);
|
||||
if (useBase)
|
||||
@@ -271,16 +276,20 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget,
|
||||
attr.colBg = wxColour(style->bg[state]);
|
||||
|
||||
// get the style's font
|
||||
if ( !style->font_desc )
|
||||
if (!style->font_desc)
|
||||
style = gtk_widget_get_default_style();
|
||||
if ( style && style->font_desc )
|
||||
if (style && style->font_desc)
|
||||
{
|
||||
wxNativeFontInfo info;
|
||||
info.description = style->font_desc;
|
||||
attr.font = wxFont(info);
|
||||
info.description = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
attr = wxWindow::GetClassDefaultAttributes(wxWINDOW_VARIANT_NORMAL);
|
||||
#endif
|
||||
|
||||
if (!attr.font.IsOk())
|
||||
{
|
||||
GtkSettings *settings = gtk_settings_get_default();
|
||||
@@ -296,56 +305,9 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget,
|
||||
g_free (font_name);
|
||||
}
|
||||
|
||||
return attr;
|
||||
}
|
||||
if (tlw)
|
||||
gtk_widget_destroy(tlw);
|
||||
|
||||
|
||||
//static
|
||||
wxVisualAttributes
|
||||
wxControl::GetDefaultAttributesFromGTKWidget(wxGtkWidgetNew_t widget_new,
|
||||
bool useBase,
|
||||
int state)
|
||||
{
|
||||
wxVisualAttributes attr;
|
||||
// NB: we need toplevel window so that GTK+ can find the right style
|
||||
GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
GtkWidget* widget = widget_new();
|
||||
gtk_container_add(GTK_CONTAINER(wnd), widget);
|
||||
attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state);
|
||||
gtk_widget_destroy(wnd);
|
||||
return attr;
|
||||
}
|
||||
|
||||
//static
|
||||
wxVisualAttributes
|
||||
wxControl::GetDefaultAttributesFromGTKWidget(wxGtkWidgetNewFromStr_t widget_new,
|
||||
bool useBase,
|
||||
int state)
|
||||
{
|
||||
wxVisualAttributes attr;
|
||||
// NB: we need toplevel window so that GTK+ can find the right style
|
||||
GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
GtkWidget* widget = widget_new("");
|
||||
gtk_container_add(GTK_CONTAINER(wnd), widget);
|
||||
attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state);
|
||||
gtk_widget_destroy(wnd);
|
||||
return attr;
|
||||
}
|
||||
|
||||
|
||||
//static
|
||||
wxVisualAttributes
|
||||
wxControl::GetDefaultAttributesFromGTKWidget(wxGtkWidgetNewFromAdj_t widget_new,
|
||||
bool useBase,
|
||||
int state)
|
||||
{
|
||||
wxVisualAttributes attr;
|
||||
// NB: we need toplevel window so that GTK+ can find the right style
|
||||
GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
GtkWidget* widget = widget_new(NULL);
|
||||
gtk_container_add(GTK_CONTAINER(wnd), widget);
|
||||
attr = GetDefaultAttributesFromGTKWidget(widget, useBase, state);
|
||||
gtk_widget_destroy(wnd);
|
||||
return attr;
|
||||
}
|
||||
|
||||
|
@@ -5104,7 +5104,7 @@ void wxDataViewCtrl::GtkEnableSelectionEvents()
|
||||
wxVisualAttributes
|
||||
wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new());
|
||||
}
|
||||
|
||||
void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle *style)
|
||||
|
@@ -128,7 +128,7 @@ wxVisualAttributes wxGauge::GetDefaultAttributes() const
|
||||
wxVisualAttributes
|
||||
wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new(),
|
||||
false, GTK_STATE_ACTIVE);
|
||||
}
|
||||
|
||||
|
@@ -931,7 +931,7 @@ wxSize wxListBox::DoGetBestSize() const
|
||||
wxVisualAttributes
|
||||
wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new, true);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new(), true);
|
||||
}
|
||||
|
||||
#endif // wxUSE_LISTBOX
|
||||
|
@@ -607,7 +607,7 @@ GdkWindow *wxNotebook::GTKGetWindow(wxArrayGdkWindows& windows) const
|
||||
wxVisualAttributes
|
||||
wxNotebook::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_notebook_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_notebook_new());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -617,14 +617,7 @@ GdkWindow *wxRadioBox::GTKGetWindow(wxArrayGdkWindows& windows) const
|
||||
wxVisualAttributes
|
||||
wxRadioBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
wxVisualAttributes attr;
|
||||
// NB: we need toplevel window so that GTK+ can find the right style
|
||||
GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
|
||||
gtk_container_add(GTK_CONTAINER(wnd), widget);
|
||||
attr = GetDefaultAttributesFromGTKWidget(widget);
|
||||
gtk_widget_destroy(wnd);
|
||||
return attr;
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_radio_button_new_with_label(NULL, ""));
|
||||
}
|
||||
|
||||
int wxRadioBox::GetItemFromPoint(const wxPoint& point) const
|
||||
|
@@ -181,14 +181,7 @@ wxRadioButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
|
||||
wxVisualAttributes
|
||||
wxRadioButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
wxVisualAttributes attr;
|
||||
// NB: we need toplevel window so that GTK+ can find the right style
|
||||
GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
GtkWidget* widget = gtk_radio_button_new_with_label(NULL, "");
|
||||
gtk_container_add(GTK_CONTAINER(wnd), widget);
|
||||
attr = GetDefaultAttributesFromGTKWidget(widget);
|
||||
gtk_widget_destroy(wnd);
|
||||
return attr;
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_radio_button_new_with_label(NULL, ""));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -235,7 +235,7 @@ void wxScrollBar::SetRange(int range)
|
||||
wxVisualAttributes
|
||||
wxScrollBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_vscrollbar_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_vscrollbar_new(NULL));
|
||||
}
|
||||
|
||||
#endif // wxUSE_SCROLLBAR
|
||||
|
@@ -533,7 +533,7 @@ GdkWindow *wxSlider::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
|
||||
wxVisualAttributes
|
||||
wxSlider::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_vscale_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_vscale_new(NULL));
|
||||
}
|
||||
|
||||
#endif // wxUSE_SLIDER
|
||||
|
@@ -217,9 +217,7 @@ wxSize wxSpinButton::DoGetBestSize() const
|
||||
wxVisualAttributes
|
||||
wxSpinButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
// TODO: overload to accept functions like gtk_spin_button_new?
|
||||
// Until then use a similar type
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_button_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_spin_button_new_with_range(0, 100, 1));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -376,9 +376,7 @@ wxSize wxSpinCtrlGTKBase::DoGetSizeFromTextSize(int xlen, int ylen) const
|
||||
wxVisualAttributes
|
||||
wxSpinCtrlGTKBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
// TODO: overload to accept functions like gtk_spin_button_new?
|
||||
// Until then use a similar type
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_spin_button_new_with_range(0, 100, 1), true);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@@ -75,8 +75,7 @@ void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
|
||||
wxVisualAttributes
|
||||
wxStaticBitmap::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
// TODO: overload to allow using gtk_pixmap_new?
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_label_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_image_new());
|
||||
}
|
||||
|
||||
#endif // wxUSE_STATBMP
|
||||
|
@@ -152,7 +152,7 @@ void wxStaticBox::GTKWidgetDoSetMnemonic(GtkWidget* w)
|
||||
wxVisualAttributes
|
||||
wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_frame_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_frame_new(""));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -76,7 +76,7 @@ bool wxStaticLine::Create( wxWindow *parent, wxWindowID id,
|
||||
wxVisualAttributes
|
||||
wxStaticLine::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_vseparator_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_vseparator_new());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -248,7 +248,7 @@ void wxStaticText::DoSetLabel(const wxString& str)
|
||||
wxVisualAttributes
|
||||
wxStaticText::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_label_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_label_new(""));
|
||||
}
|
||||
|
||||
#endif // wxUSE_STATTEXT
|
||||
|
@@ -2009,7 +2009,7 @@ bool wxTextCtrl::GTKProcessEvent(wxEvent& event) const
|
||||
wxVisualAttributes
|
||||
wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_entry_new(), true);
|
||||
}
|
||||
|
||||
#endif // wxUSE_TEXTCTRL
|
||||
|
@@ -235,7 +235,7 @@ wxSize wxToggleButton::DoGetBestSize() const
|
||||
wxVisualAttributes
|
||||
wxToggleButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new());
|
||||
}
|
||||
|
||||
#endif // wxUSE_TOGGLEBTN
|
||||
|
@@ -763,7 +763,7 @@ void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
|
||||
wxVisualAttributes
|
||||
wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new);
|
||||
return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new());
|
||||
}
|
||||
|
||||
#endif // wxUSE_TOOLBAR_NATIVE
|
||||
|
@@ -1004,7 +1004,7 @@ void wxWebViewWebKit::FindClear()
|
||||
wxVisualAttributes
|
||||
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
|
||||
{
|
||||
return GetDefaultAttributesFromGTKWidget(webkit_web_view_new);
|
||||
return GetDefaultAttributesFromGTKWidget(webkit_web_view_new());
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user