appchooserwidget: Inherit from GtkWidget

This commit is contained in:
Timm Bäder 2017-03-25 21:10:27 +01:00
parent fc22543b41
commit cf80a03f91
4 changed files with 61 additions and 12 deletions

View File

@ -348,7 +348,6 @@ construct_appchooser_widget (GtkAppChooserDialog *self)
/* Need to build the appchooser widget after, because of the content-type construct-only property */
self->priv->app_chooser_widget = gtk_app_chooser_widget_new (self->priv->content_type);
gtk_box_pack_start (GTK_BOX (self->priv->inner_box), self->priv->app_chooser_widget, TRUE, TRUE);
gtk_widget_show (self->priv->app_chooser_widget);
g_signal_connect (self->priv->app_chooser_widget, "application-selected",
G_CALLBACK (widget_application_selected_cb), self);

View File

@ -75,6 +75,8 @@
struct _GtkAppChooserWidgetPrivate {
GAppInfo *selected_app_info;
GtkWidget *overlay;
gchar *content_type;
gchar *default_text;
@ -136,7 +138,7 @@ static guint signals[N_SIGNALS] = { 0, };
static void gtk_app_chooser_widget_iface_init (GtkAppChooserIface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkAppChooserWidget, gtk_app_chooser_widget, GTK_TYPE_BOX,
G_DEFINE_TYPE_WITH_CODE (GtkAppChooserWidget, gtk_app_chooser_widget, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkAppChooserWidget)
G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER,
gtk_app_chooser_widget_iface_init));
@ -928,12 +930,56 @@ static void
gtk_app_chooser_widget_dispose (GObject *object)
{
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
g_clear_object (&self->priv->selected_app_info);
g_clear_object (&priv->selected_app_info);
if (priv->overlay)
{
gtk_widget_unparent (priv->overlay);
priv->overlay = NULL;
}
G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->dispose (object);
}
static void
gtk_app_chooser_widget_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum,
int *natural,
int *minimum_baseline,
int *natural_baseline)
{
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (widget);
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
gtk_widget_measure (priv->overlay, orientation, for_size,
minimum, natural,
minimum_baseline, natural_baseline);
}
static void
gtk_app_chooser_widget_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
{
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (widget);
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
gtk_widget_snapshot_child (widget, priv->overlay, snapshot);
}
static void
gtk_app_chooser_widget_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (widget);
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
gtk_widget_size_allocate (priv->overlay, allocation);
}
static void
gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *klass)
{
@ -948,6 +994,12 @@ gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *klass)
gobject_class->get_property = gtk_app_chooser_widget_get_property;
gobject_class->constructed = gtk_app_chooser_widget_constructed;
widget_class = GTK_WIDGET_CLASS (klass);
widget_class->measure = gtk_app_chooser_widget_measure;
widget_class->size_allocate = gtk_app_chooser_widget_size_allocate;
widget_class->snapshot = gtk_app_chooser_widget_snapshot;
g_object_class_override_property (gobject_class, PROP_CONTENT_TYPE, "content-type");
/**
@ -1098,7 +1150,6 @@ gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *klass)
/* Bind class to template
*/
widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gtk/libgtk/ui/gtkappchooserwidget.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, program_list);
@ -1108,6 +1159,7 @@ gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, secondary_padding);
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, no_apps_label);
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, no_apps);
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, overlay);
gtk_widget_class_bind_template_callback (widget_class, refresh_and_emit_app_selected);
gtk_widget_class_bind_template_callback (widget_class, program_list_selection_activated);
gtk_widget_class_bind_template_callback (widget_class, widget_button_press_event_cb);
@ -1123,6 +1175,8 @@ gtk_app_chooser_widget_init (GtkAppChooserWidget *self)
self->priv = gtk_app_chooser_widget_get_instance_private (self);
gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
gtk_widget_init_template (GTK_WIDGET (self));
/* Various parts of the GtkTreeView code need custom code to setup, mostly

View File

@ -29,7 +29,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
#include <gtk/gtkbox.h>
#include <gtk/gtkwidget.h>
#include <gtk/gtkmenu.h>
#include <gio/gio.h>
@ -47,7 +47,7 @@ typedef struct _GtkAppChooserWidgetClass GtkAppChooserWidgetClass;
typedef struct _GtkAppChooserWidgetPrivate GtkAppChooserWidgetPrivate;
struct _GtkAppChooserWidget {
GtkBox parent;
GtkWidget parent_instance;
/*< private >*/
GtkAppChooserWidgetPrivate *priv;
@ -64,7 +64,7 @@ struct _GtkAppChooserWidget {
* popup over an application item.
*/
struct _GtkAppChooserWidgetClass {
GtkBoxClass parent_class;
GtkWidgetClass parent_class;
/*< public >*/

View File

@ -28,8 +28,7 @@
<object class="GtkTreeModelSort" id="program_list_sort">
<property name="model">program_list_store</property>
</object>
<template class="GtkAppChooserWidget" parent="GtkBox">
<property name="orientation">vertical</property>
<template class="GtkAppChooserWidget" parent="GtkWidget">
<child>
<object class="GtkOverlay" id="overlay">
<property name="visible">1</property>
@ -129,9 +128,6 @@
</object>
</child>
</object>
<packing>
<property name="expand">1</property>
</packing>
</child>
</template>
</interface>