// 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;
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.
wxVisualAttributes
wxAnyButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_button_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_button_new());
}
// ----------------------------------------------------------------------------
wxVisualAttributes
wxButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_button_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_button_new());
}
#endif // wxUSE_BUTTON
wxVisualAttributes
wxCheckBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_check_button_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_check_button_new());
}
#endif
wxVisualAttributes
wxChoice::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_combo_box_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_combo_box_new());
}
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
}
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)
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)
- attr.colBg = wxColour(style->base[state]);
- else
- attr.colBg = wxColour(style->bg[state]);
+ // get the style's colours
+ attr.colFg = wxColour(style->fg[state]);
+ if (useBase)
+ attr.colBg = wxColour(style->base[state]);
+ else
+ attr.colBg = wxColour(style->bg[state]);
- // get the style's font
- if ( !style->font_desc )
- style = gtk_widget_get_default_style();
- if ( style && style->font_desc )
- {
- wxNativeFontInfo info;
- info.description = style->font_desc;
- attr.font = wxFont(info);
- info.description = NULL;
+ // get the style's font
+ if (!style->font_desc)
+ style = gtk_widget_get_default_style();
+ 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();
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;
}
wxVisualAttributes
wxDataViewCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new());
}
void wxDataViewCtrl::DoApplyWidgetStyle(GtkRcStyle *style)
wxVisualAttributes
wxGauge::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new,
+ return GetDefaultAttributesFromGTKWidget(gtk_progress_bar_new(),
false, GTK_STATE_ACTIVE);
}
wxVisualAttributes
wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new, true);
+ return GetDefaultAttributesFromGTKWidget(gtk_tree_view_new(), true);
}
#endif // wxUSE_LISTBOX
wxVisualAttributes
wxNotebook::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_notebook_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_notebook_new());
}
#endif
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
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, ""));
}
wxVisualAttributes
wxScrollBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_vscrollbar_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_vscrollbar_new(NULL));
}
#endif // wxUSE_SCROLLBAR
wxVisualAttributes
wxSlider::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_vscale_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_vscale_new(NULL));
}
#endif // wxUSE_SLIDER
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
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);
}
//-----------------------------------------------------------------------------
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
wxVisualAttributes
wxStaticBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_frame_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_frame_new(""));
}
wxVisualAttributes
wxStaticLine::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_vseparator_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_vseparator_new());
}
#endif
wxVisualAttributes
wxStaticText::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_label_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_label_new(""));
}
#endif // wxUSE_STATTEXT
wxVisualAttributes
wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true);
+ return GetDefaultAttributesFromGTKWidget(gtk_entry_new(), true);
}
#endif // wxUSE_TEXTCTRL
wxVisualAttributes
wxToggleButton::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_toggle_button_new());
}
#endif // wxUSE_TOGGLEBTN
wxVisualAttributes
wxToolBar::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new);
+ return GetDefaultAttributesFromGTKWidget(gtk_toolbar_new());
}
#endif // wxUSE_TOOLBAR_NATIVE
wxVisualAttributes
wxWebViewWebKit::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
{
- return GetDefaultAttributesFromGTKWidget(webkit_web_view_new);
+ return GetDefaultAttributesFromGTKWidget(webkit_web_view_new());
}