fontchooserwidget: Inherit from GtkWidget

This commit is contained in:
Timm Bäder 2017-03-25 20:49:00 +01:00
parent 11c599a1b5
commit fc22543b41
4 changed files with 66 additions and 12 deletions

View File

@ -81,6 +81,7 @@
struct _GtkFontChooserWidgetPrivate
{
GtkWidget *grid;
GtkWidget *search_entry;
GtkWidget *family_face_list;
GtkTreeViewColumn *family_face_column;
@ -171,7 +172,7 @@ static void gtk_font_chooser_widget_cell_data_func (GtkTreeViewColum
static void gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkFontChooserWidget, gtk_font_chooser_widget, GTK_TYPE_BOX,
G_DEFINE_TYPE_WITH_CODE (GtkFontChooserWidget, gtk_font_chooser_widget, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkFontChooserWidget)
G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER,
gtk_font_chooser_widget_iface_init))
@ -564,6 +565,58 @@ row_deleted_cb (GtkTreeModel *model,
gtk_stack_set_visible_child_name (GTK_STACK (priv->list_stack), "empty");
}
static void
gtk_font_chooser_widget_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
{
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
gtk_widget_measure (priv->grid, orientation, for_size,
minimum, natural,
minimum_baseline, natural_baseline);
}
static void
gtk_font_chooser_widget_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
{
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
gtk_widget_snapshot_child (widget, priv->grid, snapshot);
}
static void
gtk_font_chooser_widget_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
gtk_widget_size_allocate (priv->grid, allocation);
}
static void
gtk_font_chooser_widget_dispose (GObject *object)
{
GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (object);
GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
if (priv->grid)
{
gtk_widget_unparent (priv->grid);
priv->grid = NULL;
}
G_OBJECT_CLASS (gtk_font_chooser_widget_parent_class)->dispose (object);
}
static void
gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
{
@ -575,8 +628,12 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
widget_class->screen_changed = gtk_font_chooser_widget_screen_changed;
widget_class->style_updated = gtk_font_chooser_widget_style_updated;
widget_class->measure = gtk_font_chooser_widget_measure;
widget_class->size_allocate = gtk_font_chooser_widget_size_allocate;
widget_class->snapshot = gtk_font_chooser_widget_snapshot;
gobject_class->finalize = gtk_font_chooser_widget_finalize;
gobject_class->dispose = gtk_font_chooser_widget_dispose;
gobject_class->set_property = gtk_font_chooser_widget_set_property;
gobject_class->get_property = gtk_font_chooser_widget_get_property;
@ -597,6 +654,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, preview);
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, size_spin);
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, size_slider);
gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, grid);
gtk_widget_class_bind_template_callback (widget_class, text_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, stop_search_cb);
@ -621,6 +679,8 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
fontchooser->priv = gtk_font_chooser_widget_get_instance_private (fontchooser);
priv = fontchooser->priv;
gtk_widget_set_has_window (GTK_WIDGET (fontchooser), FALSE);
gtk_widget_init_template (GTK_WIDGET (fontchooser));
/* Default preview string */

View File

@ -22,7 +22,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkbox.h>
#include <gtk/gtkwidget.h>
G_BEGIN_DECLS
@ -39,7 +39,7 @@ typedef struct _GtkFontChooserWidgetClass GtkFontChooserWidgetClass;
struct _GtkFontChooserWidget
{
GtkBox parent_instance;
GtkWidget parent_instance;
/*< private >*/
GtkFontChooserWidgetPrivate *priv;
@ -51,7 +51,7 @@ struct _GtkFontChooserWidget
*/
struct _GtkFontChooserWidgetClass
{
GtkBoxClass parent_class;
GtkWidgetClass parent_class;
/*< private >*/

View File

@ -12,9 +12,6 @@
<child>
<object class="GtkFontChooserWidget" id="fontchooser">
<property name="visible">1</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<property name="margin">5</property>
<signal name="font-activated" handler="font_activated_cb" swapped="no"/>
</object>
<packing>

View File

@ -30,9 +30,9 @@
<property name="page-increment">10</property>
<signal name="value-changed" handler="size_change_cb" swapped="no"/>
</object>
<template class="GtkFontChooserWidget" parent="GtkBox">
<template class="GtkFontChooserWidget" parent="GtkWidget">
<child>
<object class="GtkGrid" id="grid1">
<object class="GtkGrid" id="grid">
<property name="visible">1</property>
<property name="row-spacing">6</property>
<property name="column-spacing">6</property>
@ -205,9 +205,6 @@
</packing>
</child>
</object>
<packing>
<property name="expand">1</property>
</packing>
</child>
</template>
<object class="GThemedIcon" id="fonticon">