mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-01 16:30:15 +00:00
Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master See merge request GNOME/gtk!1685
This commit is contained in:
commit
eb5b3083ff
@ -73,23 +73,10 @@
|
||||
*/
|
||||
|
||||
typedef struct _GtkAppChooserWidgetClass GtkAppChooserWidgetClass;
|
||||
typedef struct _GtkAppChooserWidgetPrivate GtkAppChooserWidgetPrivate;
|
||||
|
||||
struct _GtkAppChooserWidget {
|
||||
GtkWidget parent_instance;
|
||||
};
|
||||
|
||||
struct _GtkAppChooserWidgetClass {
|
||||
GtkWidgetClass parent_class;
|
||||
|
||||
void (* application_selected) (GtkAppChooserWidget *self,
|
||||
GAppInfo *app_info);
|
||||
|
||||
void (* application_activated) (GtkAppChooserWidget *self,
|
||||
GAppInfo *app_info);
|
||||
};
|
||||
|
||||
struct _GtkAppChooserWidgetPrivate {
|
||||
GAppInfo *selected_app_info;
|
||||
|
||||
GtkWidget *overlay;
|
||||
@ -117,6 +104,16 @@ struct _GtkAppChooserWidgetPrivate {
|
||||
GtkWidget *popup_menu;
|
||||
};
|
||||
|
||||
struct _GtkAppChooserWidgetClass {
|
||||
GtkWidgetClass parent_class;
|
||||
|
||||
void (* application_selected) (GtkAppChooserWidget *self,
|
||||
GAppInfo *app_info);
|
||||
|
||||
void (* application_activated) (GtkAppChooserWidget *self,
|
||||
GAppInfo *app_info);
|
||||
};
|
||||
|
||||
enum {
|
||||
COLUMN_APP_INFO,
|
||||
COLUMN_GICON,
|
||||
@ -155,7 +152,6 @@ 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_WIDGET,
|
||||
G_ADD_PRIVATE (GtkAppChooserWidget)
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER,
|
||||
gtk_app_chooser_widget_iface_init));
|
||||
|
||||
@ -163,7 +159,6 @@ static void
|
||||
refresh_and_emit_app_selected (GtkAppChooserWidget *self,
|
||||
GtkTreeSelection *selection)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
GAppInfo *info = NULL;
|
||||
@ -175,25 +170,25 @@ refresh_and_emit_app_selected (GtkAppChooserWidget *self,
|
||||
if (info == NULL)
|
||||
return;
|
||||
|
||||
if (priv->selected_app_info)
|
||||
if (self->selected_app_info)
|
||||
{
|
||||
if (!g_app_info_equal (priv->selected_app_info, info))
|
||||
if (!g_app_info_equal (self->selected_app_info, info))
|
||||
{
|
||||
should_emit = TRUE;
|
||||
g_set_object (&priv->selected_app_info, info);
|
||||
g_set_object (&self->selected_app_info, info);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
should_emit = TRUE;
|
||||
g_set_object (&priv->selected_app_info, info);
|
||||
g_set_object (&self->selected_app_info, info);
|
||||
}
|
||||
|
||||
g_object_unref (info);
|
||||
|
||||
if (should_emit)
|
||||
g_signal_emit (self, signals[SIGNAL_APPLICATION_SELECTED], 0,
|
||||
priv->selected_app_info);
|
||||
self->selected_app_info);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -220,18 +215,17 @@ program_list_selection_activated (GtkTreeView *view,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkAppChooserWidget *self = user_data;
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
GtkTreeSelection *selection;
|
||||
|
||||
if (path_is_heading (view, path))
|
||||
return;
|
||||
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->program_list));
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->program_list));
|
||||
|
||||
refresh_and_emit_app_selected (self, selection);
|
||||
|
||||
g_signal_emit (self, signals[SIGNAL_APPLICATION_ACTIVATED], 0,
|
||||
priv->selected_app_info);
|
||||
self->selected_app_info);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -437,7 +431,6 @@ gtk_app_chooser_widget_add_section (GtkAppChooserWidget *self,
|
||||
GList *applications,
|
||||
GList *exclude_apps)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
gboolean heading_added, unref_icon;
|
||||
GtkTreeIter iter;
|
||||
GAppInfo *app;
|
||||
@ -454,7 +447,7 @@ gtk_app_chooser_widget_add_section (GtkAppChooserWidget *self,
|
||||
{
|
||||
app = l->data;
|
||||
|
||||
if (priv->content_type != NULL &&
|
||||
if (self->content_type != NULL &&
|
||||
!g_app_info_supports_uris (app) &&
|
||||
!g_app_info_supports_files (app))
|
||||
continue;
|
||||
@ -465,8 +458,8 @@ gtk_app_chooser_widget_add_section (GtkAppChooserWidget *self,
|
||||
|
||||
if (!heading_added && show_headings)
|
||||
{
|
||||
gtk_list_store_append (priv->program_list_store, &iter);
|
||||
gtk_list_store_set (priv->program_list_store, &iter,
|
||||
gtk_list_store_append (self->program_list_store, &iter);
|
||||
gtk_list_store_set (self->program_list_store, &iter,
|
||||
COLUMN_HEADING_TEXT, bold_string,
|
||||
COLUMN_HEADING, TRUE,
|
||||
COLUMN_RECOMMENDED, recommended,
|
||||
@ -488,8 +481,8 @@ gtk_app_chooser_widget_add_section (GtkAppChooserWidget *self,
|
||||
unref_icon = TRUE;
|
||||
}
|
||||
|
||||
gtk_list_store_append (priv->program_list_store, &iter);
|
||||
gtk_list_store_set (priv->program_list_store, &iter,
|
||||
gtk_list_store_append (self->program_list_store, &iter);
|
||||
gtk_list_store_set (self->program_list_store, &iter,
|
||||
COLUMN_APP_INFO, app,
|
||||
COLUMN_GICON, icon,
|
||||
COLUMN_NAME, g_app_info_get_name (app),
|
||||
@ -517,7 +510,6 @@ static void
|
||||
gtk_app_chooser_add_default (GtkAppChooserWidget *self,
|
||||
GAppInfo *app)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
GtkTreeIter iter;
|
||||
GIcon *icon;
|
||||
gchar *string;
|
||||
@ -526,8 +518,8 @@ gtk_app_chooser_add_default (GtkAppChooserWidget *self,
|
||||
unref_icon = FALSE;
|
||||
string = g_strdup_printf ("<b>%s</b>", _("Default Application"));
|
||||
|
||||
gtk_list_store_append (priv->program_list_store, &iter);
|
||||
gtk_list_store_set (priv->program_list_store, &iter,
|
||||
gtk_list_store_append (self->program_list_store, &iter);
|
||||
gtk_list_store_set (self->program_list_store, &iter,
|
||||
COLUMN_HEADING_TEXT, string,
|
||||
COLUMN_HEADING, TRUE,
|
||||
COLUMN_DEFAULT, TRUE,
|
||||
@ -546,8 +538,8 @@ gtk_app_chooser_add_default (GtkAppChooserWidget *self,
|
||||
unref_icon = TRUE;
|
||||
}
|
||||
|
||||
gtk_list_store_append (priv->program_list_store, &iter);
|
||||
gtk_list_store_set (priv->program_list_store, &iter,
|
||||
gtk_list_store_append (self->program_list_store, &iter);
|
||||
gtk_list_store_set (self->program_list_store, &iter,
|
||||
COLUMN_APP_INFO, app,
|
||||
COLUMN_GICON, icon,
|
||||
COLUMN_NAME, g_app_info_get_name (app),
|
||||
@ -566,24 +558,23 @@ gtk_app_chooser_add_default (GtkAppChooserWidget *self,
|
||||
static void
|
||||
update_no_applications_label (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
gchar *text = NULL, *desc = NULL;
|
||||
const gchar *string;
|
||||
|
||||
if (priv->default_text == NULL)
|
||||
if (self->default_text == NULL)
|
||||
{
|
||||
if (priv->content_type)
|
||||
desc = g_content_type_get_description (priv->content_type);
|
||||
if (self->content_type)
|
||||
desc = g_content_type_get_description (self->content_type);
|
||||
|
||||
string = text = g_strdup_printf (_("No applications found for “%s”."), desc);
|
||||
g_free (desc);
|
||||
}
|
||||
else
|
||||
{
|
||||
string = priv->default_text;
|
||||
string = self->default_text;
|
||||
}
|
||||
|
||||
gtk_label_set_text (GTK_LABEL (priv->no_apps_label), string);
|
||||
gtk_label_set_text (GTK_LABEL (self->no_apps_label), string);
|
||||
|
||||
g_free (text);
|
||||
}
|
||||
@ -591,12 +582,11 @@ update_no_applications_label (GtkAppChooserWidget *self)
|
||||
static void
|
||||
gtk_app_chooser_widget_select_first (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
GtkTreeIter iter;
|
||||
GAppInfo *info = NULL;
|
||||
GtkTreeModel *model;
|
||||
|
||||
model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->program_list));
|
||||
model = gtk_tree_view_get_model (GTK_TREE_VIEW (self->program_list));
|
||||
if (!gtk_tree_model_get_iter_first (model, &iter))
|
||||
return;
|
||||
|
||||
@ -617,7 +607,7 @@ gtk_app_chooser_widget_select_first (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkTreeSelection *selection;
|
||||
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->program_list));
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->program_list));
|
||||
gtk_tree_selection_select_iter (selection, &iter);
|
||||
|
||||
g_object_unref (info);
|
||||
@ -627,7 +617,6 @@ gtk_app_chooser_widget_select_first (GtkAppChooserWidget *self)
|
||||
static void
|
||||
gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
GList *all_applications = NULL;
|
||||
GList *recommended_apps = NULL;
|
||||
GList *fallback_apps = NULL;
|
||||
@ -639,12 +628,12 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
||||
show_headings = TRUE;
|
||||
apps_added = FALSE;
|
||||
|
||||
if (priv->show_all)
|
||||
if (self->show_all)
|
||||
show_headings = FALSE;
|
||||
|
||||
if (priv->show_default && priv->content_type)
|
||||
if (self->show_default && self->content_type)
|
||||
{
|
||||
default_app = g_app_info_get_default_for_type (priv->content_type, FALSE);
|
||||
default_app = g_app_info_get_default_for_type (self->content_type, FALSE);
|
||||
|
||||
if (default_app != NULL)
|
||||
{
|
||||
@ -655,14 +644,14 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
||||
}
|
||||
|
||||
#ifndef G_OS_WIN32
|
||||
if ((priv->content_type && priv->show_recommended) || priv->show_all)
|
||||
if ((self->content_type && self->show_recommended) || self->show_all)
|
||||
{
|
||||
if (priv->content_type)
|
||||
recommended_apps = g_app_info_get_recommended_for_type (priv->content_type);
|
||||
if (self->content_type)
|
||||
recommended_apps = g_app_info_get_recommended_for_type (self->content_type);
|
||||
|
||||
apps_added |= gtk_app_chooser_widget_add_section (self, _("Recommended Applications"),
|
||||
show_headings,
|
||||
!priv->show_all, /* mark as recommended */
|
||||
!self->show_all, /* mark as recommended */
|
||||
FALSE, /* mark as fallback */
|
||||
recommended_apps, exclude_apps);
|
||||
|
||||
@ -670,22 +659,22 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
||||
g_list_copy (recommended_apps));
|
||||
}
|
||||
|
||||
if ((priv->content_type && priv->show_fallback) || priv->show_all)
|
||||
if ((self->content_type && self->show_fallback) || self->show_all)
|
||||
{
|
||||
if (priv->content_type)
|
||||
fallback_apps = g_app_info_get_fallback_for_type (priv->content_type);
|
||||
if (self->content_type)
|
||||
fallback_apps = g_app_info_get_fallback_for_type (self->content_type);
|
||||
|
||||
apps_added |= gtk_app_chooser_widget_add_section (self, _("Related Applications"),
|
||||
show_headings,
|
||||
FALSE, /* mark as recommended */
|
||||
!priv->show_all, /* mark as fallback */
|
||||
!self->show_all, /* mark as fallback */
|
||||
fallback_apps, exclude_apps);
|
||||
exclude_apps = g_list_concat (exclude_apps,
|
||||
g_list_copy (fallback_apps));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (priv->show_other || priv->show_all)
|
||||
if (self->show_other || self->show_all)
|
||||
{
|
||||
all_applications = g_app_info_get_all ();
|
||||
|
||||
@ -699,7 +688,7 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
||||
if (!apps_added)
|
||||
update_no_applications_label (self);
|
||||
|
||||
gtk_widget_set_visible (priv->no_apps, !apps_added);
|
||||
gtk_widget_set_visible (self->no_apps, !apps_added);
|
||||
|
||||
gtk_app_chooser_widget_select_first (self);
|
||||
|
||||
@ -715,11 +704,9 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
||||
static void
|
||||
gtk_app_chooser_widget_initialize_items (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
/* initial padding */
|
||||
g_object_set (priv->padding_renderer,
|
||||
"xpad", priv->show_all ? 0 : 6,
|
||||
g_object_set (self->padding_renderer,
|
||||
"xpad", self->show_all ? 0 : 6,
|
||||
NULL);
|
||||
|
||||
/* populate the widget */
|
||||
@ -740,12 +727,11 @@ gtk_app_chooser_widget_set_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_CONTENT_TYPE:
|
||||
priv->content_type = g_value_dup_string (value);
|
||||
self->content_type = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_SHOW_DEFAULT:
|
||||
gtk_app_chooser_widget_set_show_default (self, g_value_get_boolean (value));
|
||||
@ -778,30 +764,29 @@ gtk_app_chooser_widget_get_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_CONTENT_TYPE:
|
||||
g_value_set_string (value, priv->content_type);
|
||||
g_value_set_string (value, self->content_type);
|
||||
break;
|
||||
case PROP_SHOW_DEFAULT:
|
||||
g_value_set_boolean (value, priv->show_default);
|
||||
g_value_set_boolean (value, self->show_default);
|
||||
break;
|
||||
case PROP_SHOW_RECOMMENDED:
|
||||
g_value_set_boolean (value, priv->show_recommended);
|
||||
g_value_set_boolean (value, self->show_recommended);
|
||||
break;
|
||||
case PROP_SHOW_FALLBACK:
|
||||
g_value_set_boolean (value, priv->show_fallback);
|
||||
g_value_set_boolean (value, self->show_fallback);
|
||||
break;
|
||||
case PROP_SHOW_OTHER:
|
||||
g_value_set_boolean (value, priv->show_other);
|
||||
g_value_set_boolean (value, self->show_other);
|
||||
break;
|
||||
case PROP_SHOW_ALL:
|
||||
g_value_set_boolean (value, priv->show_all);
|
||||
g_value_set_boolean (value, self->show_all);
|
||||
break;
|
||||
case PROP_DEFAULT_TEXT:
|
||||
g_value_set_string (value, priv->default_text);
|
||||
g_value_set_string (value, self->default_text);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
@ -824,12 +809,11 @@ static void
|
||||
gtk_app_chooser_widget_finalize (GObject *object)
|
||||
{
|
||||
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_free (priv->content_type);
|
||||
g_free (priv->default_text);
|
||||
g_signal_handlers_disconnect_by_func (priv->monitor, app_info_changed, self);
|
||||
g_object_unref (priv->monitor);
|
||||
g_free (self->content_type);
|
||||
g_free (self->default_text);
|
||||
g_signal_handlers_disconnect_by_func (self->monitor, app_info_changed, self);
|
||||
g_object_unref (self->monitor);
|
||||
|
||||
G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->finalize (object);
|
||||
}
|
||||
@ -838,14 +822,13 @@ 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 (&priv->selected_app_info);
|
||||
g_clear_object (&self->selected_app_info);
|
||||
|
||||
if (priv->overlay)
|
||||
if (self->overlay)
|
||||
{
|
||||
gtk_widget_unparent (priv->overlay);
|
||||
priv->overlay = NULL;
|
||||
gtk_widget_unparent (self->overlay);
|
||||
self->overlay = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->dispose (object);
|
||||
@ -861,9 +844,8 @@ gtk_app_chooser_widget_measure (GtkWidget *widget,
|
||||
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,
|
||||
gtk_widget_measure (self->overlay, orientation, for_size,
|
||||
minimum, natural,
|
||||
minimum_baseline, natural_baseline);
|
||||
}
|
||||
@ -873,9 +855,8 @@ 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);
|
||||
gtk_widget_snapshot_child (widget, self->overlay, snapshot);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -885,11 +866,10 @@ gtk_app_chooser_widget_size_allocate (GtkWidget *widget,
|
||||
int baseline)
|
||||
{
|
||||
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (widget);
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_app_chooser_widget_parent_class)->size_allocate (widget, width, height, baseline);
|
||||
|
||||
gtk_widget_size_allocate (priv->overlay,
|
||||
gtk_widget_size_allocate (self->overlay,
|
||||
&(GtkAllocation) {
|
||||
0, 0,
|
||||
width, height
|
||||
@ -1048,14 +1028,14 @@ gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *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);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, program_list_store);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, column);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkAppChooserWidget, padding_renderer);
|
||||
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_child (widget_class, GtkAppChooserWidget, program_list);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserWidget, program_list_store);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserWidget, column);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserWidget, padding_renderer);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserWidget, secondary_padding);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserWidget, no_apps_label);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkAppChooserWidget, no_apps);
|
||||
gtk_widget_class_bind_template_child (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);
|
||||
|
||||
@ -1065,7 +1045,6 @@ gtk_app_chooser_widget_class_init (GtkAppChooserWidgetClass *klass)
|
||||
static void
|
||||
gtk_app_chooser_widget_init (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
GtkTreeSelection *selection;
|
||||
GtkTreeModel *sort;
|
||||
|
||||
@ -1074,11 +1053,11 @@ gtk_app_chooser_widget_init (GtkAppChooserWidget *self)
|
||||
/* Various parts of the GtkTreeView code need custom code to setup, mostly
|
||||
* because we lack signals to connect to, or properties to set.
|
||||
*/
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->program_list));
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self->program_list));
|
||||
gtk_tree_selection_set_select_function (selection, gtk_app_chooser_selection_func,
|
||||
self, NULL);
|
||||
|
||||
sort = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->program_list));
|
||||
sort = gtk_tree_view_get_model (GTK_TREE_VIEW (self->program_list));
|
||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort),
|
||||
COLUMN_NAME,
|
||||
GTK_SORT_ASCENDING);
|
||||
@ -1087,18 +1066,18 @@ gtk_app_chooser_widget_init (GtkAppChooserWidget *self)
|
||||
gtk_app_chooser_sort_func,
|
||||
self, NULL);
|
||||
|
||||
gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->program_list), COLUMN_NAME);
|
||||
gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (priv->program_list),
|
||||
gtk_tree_view_set_search_column (GTK_TREE_VIEW (self->program_list), COLUMN_NAME);
|
||||
gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (self->program_list),
|
||||
gtk_app_chooser_search_equal_func,
|
||||
NULL, NULL);
|
||||
|
||||
gtk_tree_view_column_set_cell_data_func (priv->column,
|
||||
priv->secondary_padding,
|
||||
gtk_tree_view_column_set_cell_data_func (self->column,
|
||||
self->secondary_padding,
|
||||
padding_cell_renderer_func,
|
||||
NULL, NULL);
|
||||
|
||||
priv->monitor = g_app_info_monitor_get ();
|
||||
g_signal_connect (priv->monitor, "changed",
|
||||
self->monitor = g_app_info_monitor_get ();
|
||||
g_signal_connect (self->monitor, "changed",
|
||||
G_CALLBACK (app_info_changed), self);
|
||||
}
|
||||
|
||||
@ -1106,27 +1085,25 @@ static GAppInfo *
|
||||
gtk_app_chooser_widget_get_app_info (GtkAppChooser *object)
|
||||
{
|
||||
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
if (priv->selected_app_info == NULL)
|
||||
if (self->selected_app_info == NULL)
|
||||
return NULL;
|
||||
|
||||
return g_object_ref (priv->selected_app_info);
|
||||
return g_object_ref (self->selected_app_info);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_app_chooser_widget_refresh (GtkAppChooser *object)
|
||||
{
|
||||
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
if (priv->program_list_store != NULL)
|
||||
if (self->program_list_store != NULL)
|
||||
{
|
||||
gtk_list_store_clear (priv->program_list_store);
|
||||
gtk_list_store_clear (self->program_list_store);
|
||||
|
||||
/* don't add additional xpad if we don't have headings */
|
||||
g_object_set (priv->padding_renderer,
|
||||
"visible", !priv->show_all,
|
||||
g_object_set (self->padding_renderer,
|
||||
"visible", !self->show_all,
|
||||
NULL);
|
||||
|
||||
gtk_app_chooser_widget_real_add_items (self);
|
||||
@ -1169,13 +1146,11 @@ void
|
||||
gtk_app_chooser_widget_set_show_default (GtkAppChooserWidget *self,
|
||||
gboolean setting)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
||||
|
||||
if (priv->show_default != setting)
|
||||
if (self->show_default != setting)
|
||||
{
|
||||
priv->show_default = setting;
|
||||
self->show_default = setting;
|
||||
|
||||
g_object_notify (G_OBJECT (self), "show-default");
|
||||
|
||||
@ -1195,11 +1170,9 @@ gtk_app_chooser_widget_set_show_default (GtkAppChooserWidget *self,
|
||||
gboolean
|
||||
gtk_app_chooser_widget_get_show_default (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), FALSE);
|
||||
|
||||
return priv->show_default;
|
||||
return self->show_default;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1214,13 +1187,11 @@ void
|
||||
gtk_app_chooser_widget_set_show_recommended (GtkAppChooserWidget *self,
|
||||
gboolean setting)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
||||
|
||||
if (priv->show_recommended != setting)
|
||||
if (self->show_recommended != setting)
|
||||
{
|
||||
priv->show_recommended = setting;
|
||||
self->show_recommended = setting;
|
||||
|
||||
g_object_notify (G_OBJECT (self), "show-recommended");
|
||||
|
||||
@ -1240,11 +1211,9 @@ gtk_app_chooser_widget_set_show_recommended (GtkAppChooserWidget *self,
|
||||
gboolean
|
||||
gtk_app_chooser_widget_get_show_recommended (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), FALSE);
|
||||
|
||||
return priv->show_recommended;
|
||||
return self->show_recommended;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1259,13 +1228,11 @@ void
|
||||
gtk_app_chooser_widget_set_show_fallback (GtkAppChooserWidget *self,
|
||||
gboolean setting)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
||||
|
||||
if (priv->show_fallback != setting)
|
||||
if (self->show_fallback != setting)
|
||||
{
|
||||
priv->show_fallback = setting;
|
||||
self->show_fallback = setting;
|
||||
|
||||
g_object_notify (G_OBJECT (self), "show-fallback");
|
||||
|
||||
@ -1285,11 +1252,9 @@ gtk_app_chooser_widget_set_show_fallback (GtkAppChooserWidget *self,
|
||||
gboolean
|
||||
gtk_app_chooser_widget_get_show_fallback (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), FALSE);
|
||||
|
||||
return priv->show_fallback;
|
||||
return self->show_fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1304,13 +1269,11 @@ void
|
||||
gtk_app_chooser_widget_set_show_other (GtkAppChooserWidget *self,
|
||||
gboolean setting)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
||||
|
||||
if (priv->show_other != setting)
|
||||
if (self->show_other != setting)
|
||||
{
|
||||
priv->show_other = setting;
|
||||
self->show_other = setting;
|
||||
|
||||
g_object_notify (G_OBJECT (self), "show-other");
|
||||
|
||||
@ -1330,11 +1293,9 @@ gtk_app_chooser_widget_set_show_other (GtkAppChooserWidget *self,
|
||||
gboolean
|
||||
gtk_app_chooser_widget_get_show_other (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), FALSE);
|
||||
|
||||
return priv->show_other;
|
||||
return self->show_other;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1349,13 +1310,11 @@ void
|
||||
gtk_app_chooser_widget_set_show_all (GtkAppChooserWidget *self,
|
||||
gboolean setting)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
||||
|
||||
if (priv->show_all != setting)
|
||||
if (self->show_all != setting)
|
||||
{
|
||||
priv->show_all = setting;
|
||||
self->show_all = setting;
|
||||
|
||||
g_object_notify (G_OBJECT (self), "show-all");
|
||||
|
||||
@ -1375,11 +1334,9 @@ gtk_app_chooser_widget_set_show_all (GtkAppChooserWidget *self,
|
||||
gboolean
|
||||
gtk_app_chooser_widget_get_show_all (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), FALSE);
|
||||
|
||||
return priv->show_all;
|
||||
return self->show_all;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1394,14 +1351,12 @@ void
|
||||
gtk_app_chooser_widget_set_default_text (GtkAppChooserWidget *self,
|
||||
const gchar *text)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self));
|
||||
|
||||
if (g_strcmp0 (text, priv->default_text) != 0)
|
||||
if (g_strcmp0 (text, self->default_text) != 0)
|
||||
{
|
||||
g_free (priv->default_text);
|
||||
priv->default_text = g_strdup (text);
|
||||
g_free (self->default_text);
|
||||
self->default_text = g_strdup (text);
|
||||
|
||||
g_object_notify (G_OBJECT (self), "default-text");
|
||||
|
||||
@ -1421,22 +1376,18 @@ gtk_app_chooser_widget_set_default_text (GtkAppChooserWidget *self,
|
||||
const gchar *
|
||||
gtk_app_chooser_widget_get_default_text (GtkAppChooserWidget *self)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_APP_CHOOSER_WIDGET (self), NULL);
|
||||
|
||||
return priv->default_text;
|
||||
return self->default_text;
|
||||
}
|
||||
|
||||
void
|
||||
_gtk_app_chooser_widget_set_search_entry (GtkAppChooserWidget *self,
|
||||
GtkEditable *entry)
|
||||
{
|
||||
GtkAppChooserWidgetPrivate *priv = gtk_app_chooser_widget_get_instance_private (self);
|
||||
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (self->program_list), entry);
|
||||
|
||||
gtk_tree_view_set_search_entry (GTK_TREE_VIEW (priv->program_list), entry);
|
||||
|
||||
g_object_bind_property (priv->no_apps, "visible",
|
||||
g_object_bind_property (self->no_apps, "visible",
|
||||
entry, "sensitive",
|
||||
G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
|
||||
}
|
||||
|
@ -53,8 +53,12 @@
|
||||
* be removed for non-activatable swatches.
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
typedef struct _GtkColorSwatchClass GtkColorSwatchClass;
|
||||
|
||||
struct _GtkColorSwatch
|
||||
{
|
||||
GtkWidget parent_instance;
|
||||
|
||||
GdkRGBA color;
|
||||
gdouble radius[4];
|
||||
gchar *icon;
|
||||
@ -67,7 +71,15 @@ typedef struct
|
||||
|
||||
GtkWidget *popover;
|
||||
GtkDropTarget *dest;
|
||||
} GtkColorSwatchPrivate;
|
||||
};
|
||||
|
||||
struct _GtkColorSwatchClass
|
||||
{
|
||||
GtkWidgetClass parent_class;
|
||||
|
||||
void ( * activate) (GtkColorSwatch *swatch);
|
||||
void ( * customize) (GtkColorSwatch *swatch);
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
@ -78,7 +90,7 @@ enum
|
||||
PROP_CAN_DROP
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GtkColorSwatch, gtk_color_swatch, GTK_TYPE_WIDGET)
|
||||
G_DEFINE_TYPE (GtkColorSwatch, gtk_color_swatch, GTK_TYPE_WIDGET)
|
||||
|
||||
#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11)
|
||||
static void
|
||||
@ -86,23 +98,22 @@ swatch_snapshot (GtkWidget *widget,
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
const int width = gtk_widget_get_width (widget);
|
||||
const int height = gtk_widget_get_height (widget);
|
||||
const GdkRGBA *color;
|
||||
|
||||
color = &priv->color;
|
||||
if (priv->dest)
|
||||
color = &swatch->color;
|
||||
if (swatch->dest)
|
||||
{
|
||||
const GValue *value = gtk_drop_target_get_value (priv->dest);
|
||||
const GValue *value = gtk_drop_target_get_value (swatch->dest);
|
||||
|
||||
if (value)
|
||||
color = g_value_get_boxed (value);
|
||||
}
|
||||
|
||||
if (priv->has_color)
|
||||
if (swatch->has_color)
|
||||
{
|
||||
if (priv->use_alpha && !gdk_rgba_is_opaque (color))
|
||||
if (swatch->use_alpha && !gdk_rgba_is_opaque (color))
|
||||
{
|
||||
_gtk_color_chooser_snapshot_checkered_pattern (snapshot, width, height);
|
||||
|
||||
@ -122,7 +133,7 @@ swatch_snapshot (GtkWidget *widget,
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_snapshot_child (widget, priv->overlay_widget, snapshot);
|
||||
gtk_widget_snapshot_child (widget, swatch->overlay_widget, snapshot);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -141,13 +152,12 @@ swatch_drag_drop (GtkDropTarget *dest,
|
||||
static void
|
||||
activate_color (GtkColorSwatch *swatch)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
double red, green, blue, alpha;
|
||||
|
||||
red = priv->color.red;
|
||||
green = priv->color.green;
|
||||
blue = priv->color.blue;
|
||||
alpha = priv->color.alpha;
|
||||
red = swatch->color.red;
|
||||
green = swatch->color.green;
|
||||
blue = swatch->color.blue;
|
||||
alpha = swatch->color.alpha;
|
||||
|
||||
gtk_widget_activate_action (GTK_WIDGET (swatch),
|
||||
"color.select", "(dddd)", red, green, blue, alpha);
|
||||
@ -156,13 +166,12 @@ activate_color (GtkColorSwatch *swatch)
|
||||
static void
|
||||
customize_color (GtkColorSwatch *swatch)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
double red, green, blue, alpha;
|
||||
|
||||
red = priv->color.red;
|
||||
green = priv->color.green;
|
||||
blue = priv->color.blue;
|
||||
alpha = priv->color.alpha;
|
||||
red = swatch->color.red;
|
||||
green = swatch->color.green;
|
||||
blue = swatch->color.blue;
|
||||
alpha = swatch->color.alpha;
|
||||
|
||||
gtk_widget_activate_action (GTK_WIDGET (swatch),
|
||||
"color.customize", "(dddd)", red, green, blue, alpha);
|
||||
@ -176,7 +185,6 @@ key_controller_key_pressed (GtkEventControllerKey *controller,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
if (keyval == GDK_KEY_space ||
|
||||
keyval == GDK_KEY_Return ||
|
||||
@ -184,8 +192,8 @@ key_controller_key_pressed (GtkEventControllerKey *controller,
|
||||
keyval == GDK_KEY_KP_Enter ||
|
||||
keyval == GDK_KEY_KP_Space)
|
||||
{
|
||||
if (priv->has_color &&
|
||||
priv->selectable &&
|
||||
if (swatch->has_color &&
|
||||
swatch->selectable &&
|
||||
(gtk_widget_get_state_flags (widget) & GTK_STATE_FLAG_SELECTED) == 0)
|
||||
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE);
|
||||
else
|
||||
@ -200,17 +208,16 @@ key_controller_key_pressed (GtkEventControllerKey *controller,
|
||||
static GMenuModel *
|
||||
gtk_color_swatch_get_menu_model (GtkColorSwatch *swatch)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
GMenu *menu, *section;
|
||||
GMenuItem *item;
|
||||
double red, green, blue, alpha;
|
||||
|
||||
menu = g_menu_new ();
|
||||
|
||||
red = priv->color.red;
|
||||
green = priv->color.green;
|
||||
blue = priv->color.blue;
|
||||
alpha = priv->color.alpha;
|
||||
red = swatch->color.red;
|
||||
green = swatch->color.green;
|
||||
blue = swatch->color.blue;
|
||||
alpha = swatch->color.alpha;
|
||||
|
||||
section = g_menu_new ();
|
||||
item = g_menu_item_new (_("Customize"), NULL);
|
||||
@ -228,33 +235,31 @@ gtk_color_swatch_get_menu_model (GtkColorSwatch *swatch)
|
||||
static void
|
||||
do_popup (GtkColorSwatch *swatch)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
GMenuModel *model;
|
||||
|
||||
g_clear_pointer (&priv->popover, gtk_widget_unparent);
|
||||
g_clear_pointer (&swatch->popover, gtk_widget_unparent);
|
||||
|
||||
model = gtk_color_swatch_get_menu_model (swatch);
|
||||
priv->popover = gtk_popover_menu_new_from_model (model);
|
||||
gtk_widget_set_parent (priv->popover, GTK_WIDGET (swatch));
|
||||
swatch->popover = gtk_popover_menu_new_from_model (model);
|
||||
gtk_widget_set_parent (swatch->popover, GTK_WIDGET (swatch));
|
||||
g_object_unref (model);
|
||||
|
||||
gtk_popover_popup (GTK_POPOVER (priv->popover));
|
||||
gtk_popover_popup (GTK_POPOVER (swatch->popover));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
swatch_primary_action (GtkColorSwatch *swatch)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
GtkWidget *widget = (GtkWidget *)swatch;
|
||||
GtkStateFlags flags;
|
||||
|
||||
flags = gtk_widget_get_state_flags (widget);
|
||||
if (!priv->has_color)
|
||||
if (!swatch->has_color)
|
||||
{
|
||||
customize_color (swatch);
|
||||
return TRUE;
|
||||
}
|
||||
else if (priv->selectable &&
|
||||
else if (swatch->selectable &&
|
||||
(flags & GTK_STATE_FLAG_SELECTED) == 0)
|
||||
{
|
||||
gtk_widget_set_state_flags (widget, GTK_STATE_FLAG_SELECTED, FALSE);
|
||||
@ -281,7 +286,6 @@ tap_action (GtkGestureClick *gesture,
|
||||
gdouble y,
|
||||
GtkColorSwatch *swatch)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
guint button;
|
||||
|
||||
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
|
||||
@ -295,7 +299,7 @@ tap_action (GtkGestureClick *gesture,
|
||||
}
|
||||
else if (button == GDK_BUTTON_SECONDARY)
|
||||
{
|
||||
if (priv->has_color && priv->has_menu)
|
||||
if (swatch->has_color && swatch->has_menu)
|
||||
do_popup (swatch);
|
||||
}
|
||||
}
|
||||
@ -307,16 +311,15 @@ swatch_size_allocate (GtkWidget *widget,
|
||||
int baseline)
|
||||
{
|
||||
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
gtk_widget_size_allocate (priv->overlay_widget,
|
||||
gtk_widget_size_allocate (swatch->overlay_widget,
|
||||
&(GtkAllocation) {
|
||||
0, 0,
|
||||
width, height
|
||||
}, -1);
|
||||
|
||||
if (priv->popover)
|
||||
gtk_native_check_resize (GTK_NATIVE (priv->popover));
|
||||
if (swatch->popover)
|
||||
gtk_native_check_resize (GTK_NATIVE (swatch->popover));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -329,10 +332,9 @@ gtk_color_swatch_measure (GtkWidget *widget,
|
||||
int *natural_baseline)
|
||||
{
|
||||
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (widget);
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
gint w, h, min;
|
||||
|
||||
gtk_widget_measure (priv->overlay_widget,
|
||||
gtk_widget_measure (swatch->overlay_widget,
|
||||
orientation,
|
||||
-1,
|
||||
minimum, natural,
|
||||
@ -359,11 +361,10 @@ swatch_popup_menu (GtkWidget *widget,
|
||||
static void
|
||||
update_icon (GtkColorSwatch *swatch)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
GtkImage *image = GTK_IMAGE (priv->overlay_widget);
|
||||
GtkImage *image = GTK_IMAGE (swatch->overlay_widget);
|
||||
|
||||
if (priv->icon)
|
||||
gtk_image_set_from_icon_name (image, priv->icon);
|
||||
if (swatch->icon)
|
||||
gtk_image_set_from_icon_name (image, swatch->icon);
|
||||
else if (gtk_widget_get_state_flags (GTK_WIDGET (swatch)) & GTK_STATE_FLAG_SELECTED)
|
||||
gtk_image_set_from_icon_name (image, "object-select-symbolic");
|
||||
else
|
||||
@ -390,7 +391,6 @@ swatch_get_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
GdkRGBA color;
|
||||
|
||||
switch (prop_id)
|
||||
@ -403,10 +403,10 @@ swatch_get_property (GObject *object,
|
||||
g_value_set_boolean (value, gtk_color_swatch_get_selectable (swatch));
|
||||
break;
|
||||
case PROP_HAS_MENU:
|
||||
g_value_set_boolean (value, priv->has_menu);
|
||||
g_value_set_boolean (value, swatch->has_menu);
|
||||
break;
|
||||
case PROP_CAN_DROP:
|
||||
g_value_set_boolean (value, priv->dest != NULL);
|
||||
g_value_set_boolean (value, swatch->dest != NULL);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
@ -421,7 +421,6 @@ swatch_set_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
@ -432,7 +431,7 @@ swatch_set_property (GObject *object,
|
||||
gtk_color_swatch_set_selectable (swatch, g_value_get_boolean (value));
|
||||
break;
|
||||
case PROP_HAS_MENU:
|
||||
priv->has_menu = g_value_get_boolean (value);
|
||||
swatch->has_menu = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_CAN_DROP:
|
||||
gtk_color_swatch_set_can_drop (swatch, g_value_get_boolean (value));
|
||||
@ -447,10 +446,9 @@ static void
|
||||
swatch_finalize (GObject *object)
|
||||
{
|
||||
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
g_free (priv->icon);
|
||||
gtk_widget_unparent (priv->overlay_widget);
|
||||
g_free (swatch->icon);
|
||||
gtk_widget_unparent (swatch->overlay_widget);
|
||||
|
||||
G_OBJECT_CLASS (gtk_color_swatch_parent_class)->finalize (object);
|
||||
}
|
||||
@ -459,9 +457,8 @@ static void
|
||||
swatch_dispose (GObject *object)
|
||||
{
|
||||
GtkColorSwatch *swatch = GTK_COLOR_SWATCH (object);
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
g_clear_pointer (&priv->popover, gtk_widget_unparent);
|
||||
g_clear_pointer (&swatch->popover, gtk_widget_unparent);
|
||||
|
||||
G_OBJECT_CLASS (gtk_color_swatch_parent_class)->dispose (object);
|
||||
}
|
||||
@ -520,17 +517,16 @@ gtk_color_swatch_class_init (GtkColorSwatchClass *class)
|
||||
static void
|
||||
gtk_color_swatch_init (GtkColorSwatch *swatch)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
GtkEventController *controller;
|
||||
GtkGesture *gesture;
|
||||
|
||||
priv->use_alpha = TRUE;
|
||||
priv->selectable = TRUE;
|
||||
priv->has_menu = TRUE;
|
||||
priv->color.red = 0.75;
|
||||
priv->color.green = 0.25;
|
||||
priv->color.blue = 0.25;
|
||||
priv->color.alpha = 1.0;
|
||||
swatch->use_alpha = TRUE;
|
||||
swatch->selectable = TRUE;
|
||||
swatch->has_menu = TRUE;
|
||||
swatch->color.red = 0.75;
|
||||
swatch->color.green = 0.25;
|
||||
swatch->color.blue = 0.25;
|
||||
swatch->color.alpha = 1.0;
|
||||
|
||||
gtk_widget_set_can_focus (GTK_WIDGET (swatch), TRUE);
|
||||
gtk_widget_set_overflow (GTK_WIDGET (swatch), GTK_OVERFLOW_HIDDEN);
|
||||
@ -555,10 +551,10 @@ gtk_color_swatch_init (GtkColorSwatch *swatch)
|
||||
|
||||
gtk_widget_add_css_class (GTK_WIDGET (swatch), "activatable");
|
||||
|
||||
priv->overlay_widget = g_object_new (GTK_TYPE_IMAGE,
|
||||
swatch->overlay_widget = g_object_new (GTK_TYPE_IMAGE,
|
||||
"css-name", "overlay",
|
||||
NULL);
|
||||
gtk_widget_set_parent (priv->overlay_widget, GTK_WIDGET (swatch));
|
||||
gtk_widget_set_parent (swatch->overlay_widget, GTK_WIDGET (swatch));
|
||||
}
|
||||
|
||||
/* Public API {{{1 */
|
||||
@ -575,18 +571,14 @@ gtk_color_swatch_drag_prepare (GtkDragSource *source,
|
||||
double y,
|
||||
GtkColorSwatch *swatch)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
return gdk_content_provider_new_typed (GDK_TYPE_RGBA, &priv->color);
|
||||
return gdk_content_provider_new_typed (GDK_TYPE_RGBA, &swatch->color);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_color_swatch_set_rgba (GtkColorSwatch *swatch,
|
||||
const GdkRGBA *color)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
if (!priv->has_color)
|
||||
if (!swatch->has_color)
|
||||
{
|
||||
GtkDragSource *source;
|
||||
|
||||
@ -596,10 +588,10 @@ gtk_color_swatch_set_rgba (GtkColorSwatch *swatch,
|
||||
gtk_widget_add_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (source));
|
||||
}
|
||||
|
||||
priv->has_color = TRUE;
|
||||
priv->color = *color;
|
||||
swatch->has_color = TRUE;
|
||||
swatch->color = *color;
|
||||
|
||||
if (INTENSITY (priv->color.red, priv->color.green, priv->color.blue) > 0.5)
|
||||
if (INTENSITY (swatch->color.red, swatch->color.green, swatch->color.blue) > 0.5)
|
||||
{
|
||||
gtk_widget_add_css_class (GTK_WIDGET (swatch), "light");
|
||||
gtk_widget_remove_css_class (GTK_WIDGET (swatch), "dark");
|
||||
@ -618,14 +610,12 @@ gboolean
|
||||
gtk_color_swatch_get_rgba (GtkColorSwatch *swatch,
|
||||
GdkRGBA *color)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
if (priv->has_color)
|
||||
if (swatch->has_color)
|
||||
{
|
||||
color->red = priv->color.red;
|
||||
color->green = priv->color.green;
|
||||
color->blue = priv->color.blue;
|
||||
color->alpha = priv->color.alpha;
|
||||
color->red = swatch->color.red;
|
||||
color->green = swatch->color.green;
|
||||
color->blue = swatch->color.blue;
|
||||
color->alpha = swatch->color.alpha;
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
@ -642,9 +632,7 @@ void
|
||||
gtk_color_swatch_set_icon (GtkColorSwatch *swatch,
|
||||
const gchar *icon)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
priv->icon = g_strdup (icon);
|
||||
swatch->icon = g_strdup (icon);
|
||||
update_icon (swatch);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (swatch));
|
||||
}
|
||||
@ -653,23 +641,21 @@ void
|
||||
gtk_color_swatch_set_can_drop (GtkColorSwatch *swatch,
|
||||
gboolean can_drop)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
if (can_drop == (priv->dest != NULL))
|
||||
if (can_drop == (swatch->dest != NULL))
|
||||
return;
|
||||
|
||||
if (can_drop && !priv->dest)
|
||||
if (can_drop && !swatch->dest)
|
||||
{
|
||||
priv->dest = gtk_drop_target_new (GDK_TYPE_RGBA, GDK_ACTION_COPY);
|
||||
gtk_drop_target_set_preload (priv->dest, TRUE);
|
||||
g_signal_connect (priv->dest, "drop", G_CALLBACK (swatch_drag_drop), swatch);
|
||||
g_signal_connect_swapped (priv->dest, "notify::value", G_CALLBACK (gtk_widget_queue_draw), swatch);
|
||||
gtk_widget_add_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (priv->dest));
|
||||
swatch->dest = gtk_drop_target_new (GDK_TYPE_RGBA, GDK_ACTION_COPY);
|
||||
gtk_drop_target_set_preload (swatch->dest, TRUE);
|
||||
g_signal_connect (swatch->dest, "drop", G_CALLBACK (swatch_drag_drop), swatch);
|
||||
g_signal_connect_swapped (swatch->dest, "notify::value", G_CALLBACK (gtk_widget_queue_draw), swatch);
|
||||
gtk_widget_add_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (swatch->dest));
|
||||
}
|
||||
if (!can_drop && priv->dest)
|
||||
if (!can_drop && swatch->dest)
|
||||
{
|
||||
gtk_widget_remove_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (priv->dest));
|
||||
priv->dest = NULL;
|
||||
gtk_widget_remove_controller (GTK_WIDGET (swatch), GTK_EVENT_CONTROLLER (swatch->dest));
|
||||
swatch->dest = NULL;
|
||||
}
|
||||
|
||||
g_object_notify (G_OBJECT (swatch), "can-drop");
|
||||
@ -679,9 +665,7 @@ void
|
||||
gtk_color_swatch_set_use_alpha (GtkColorSwatch *swatch,
|
||||
gboolean use_alpha)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
priv->use_alpha = use_alpha;
|
||||
swatch->use_alpha = use_alpha;
|
||||
gtk_widget_queue_draw (GTK_WIDGET (swatch));
|
||||
}
|
||||
|
||||
@ -689,21 +673,17 @@ void
|
||||
gtk_color_swatch_set_selectable (GtkColorSwatch *swatch,
|
||||
gboolean selectable)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
if (selectable == priv->selectable)
|
||||
if (selectable == swatch->selectable)
|
||||
return;
|
||||
|
||||
priv->selectable = selectable;
|
||||
swatch->selectable = selectable;
|
||||
g_object_notify (G_OBJECT (swatch), "selectable");
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_color_swatch_get_selectable (GtkColorSwatch *swatch)
|
||||
{
|
||||
GtkColorSwatchPrivate *priv = gtk_color_swatch_get_instance_private (swatch);
|
||||
|
||||
return priv->selectable;
|
||||
return swatch->selectable;
|
||||
}
|
||||
|
||||
/* vim:set foldmethod=marker: */
|
||||
|
@ -24,34 +24,10 @@ G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_COLOR_SWATCH (gtk_color_swatch_get_type ())
|
||||
#define GTK_COLOR_SWATCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COLOR_SWATCH, GtkColorSwatch))
|
||||
#define GTK_COLOR_SWATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COLOR_SWATCH, GtkColorSwatchClass))
|
||||
#define GTK_IS_COLOR_SWATCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COLOR_SWATCH))
|
||||
#define GTK_IS_COLOR_SWATCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COLOR_SWATCH))
|
||||
#define GTK_COLOR_SWATCH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COLOR_SWATCH, GtkColorSwatchClass))
|
||||
|
||||
|
||||
typedef struct _GtkColorSwatch GtkColorSwatch;
|
||||
typedef struct _GtkColorSwatchClass GtkColorSwatchClass;
|
||||
|
||||
struct _GtkColorSwatch
|
||||
{
|
||||
GtkWidget parent_instance;
|
||||
};
|
||||
|
||||
struct _GtkColorSwatchClass
|
||||
{
|
||||
GtkWidgetClass parent_class;
|
||||
|
||||
void ( * activate) (GtkColorSwatch *swatch);
|
||||
void ( * customize) (GtkColorSwatch *swatch);
|
||||
|
||||
/* Padding for future expansion */
|
||||
void (*_gtk_reserved1) (void);
|
||||
void (*_gtk_reserved2) (void);
|
||||
void (*_gtk_reserved3) (void);
|
||||
void (*_gtk_reserved4) (void);
|
||||
};
|
||||
|
||||
|
||||
GType gtk_color_swatch_get_type (void) G_GNUC_CONST;
|
||||
GtkWidget * gtk_color_swatch_new (void);
|
||||
|
@ -149,18 +149,7 @@ typedef struct _GtkExpanderClass GtkExpanderClass;
|
||||
struct _GtkExpander
|
||||
{
|
||||
GtkContainer parent_instance;
|
||||
};
|
||||
|
||||
struct _GtkExpanderClass
|
||||
{
|
||||
GtkContainerClass parent_class;
|
||||
|
||||
void (* activate) (GtkExpander *expander);
|
||||
};
|
||||
|
||||
typedef struct _GtkExpanderPrivate GtkExpanderPrivate;
|
||||
struct _GtkExpanderPrivate
|
||||
{
|
||||
GtkWidget *label_widget;
|
||||
|
||||
GtkWidget *box;
|
||||
@ -176,6 +165,13 @@ struct _GtkExpanderPrivate
|
||||
guint resize_toplevel : 1;
|
||||
};
|
||||
|
||||
struct _GtkExpanderClass
|
||||
{
|
||||
GtkContainerClass parent_class;
|
||||
|
||||
void (* activate) (GtkExpander *expander);
|
||||
};
|
||||
|
||||
static void gtk_expander_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
@ -226,7 +222,6 @@ static void gesture_click_released_cb (GtkGestureClick *gesture,
|
||||
GtkExpander *expander);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkExpander, gtk_expander, GTK_TYPE_CONTAINER,
|
||||
G_ADD_PRIVATE (GtkExpander)
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
||||
gtk_expander_buildable_init))
|
||||
|
||||
@ -234,9 +229,8 @@ static gboolean
|
||||
expand_timeout (gpointer data)
|
||||
{
|
||||
GtkExpander *expander = GTK_EXPANDER (data);
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
priv->expand_timer = 0;
|
||||
expander->expand_timer = 0;
|
||||
gtk_expander_set_expanded (expander, TRUE);
|
||||
|
||||
return FALSE;
|
||||
@ -248,12 +242,10 @@ gtk_expander_drag_enter (GtkDropControllerMotion *motion,
|
||||
double y,
|
||||
GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
if (!priv->expanded && !priv->expand_timer)
|
||||
if (!expander->expanded && !expander->expand_timer)
|
||||
{
|
||||
priv->expand_timer = g_timeout_add (TIMEOUT_EXPAND, (GSourceFunc) expand_timeout, expander);
|
||||
g_source_set_name_by_id (priv->expand_timer, "[gtk] expand_timeout");
|
||||
expander->expand_timer = g_timeout_add (TIMEOUT_EXPAND, (GSourceFunc) expand_timeout, expander);
|
||||
g_source_set_name_by_id (expander->expand_timer, "[gtk] expand_timeout");
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@ -263,12 +255,10 @@ static void
|
||||
gtk_expander_drag_leave (GtkDropControllerMotion *motion,
|
||||
GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
if (priv->expand_timer)
|
||||
if (expander->expand_timer)
|
||||
{
|
||||
g_source_remove (priv->expand_timer);
|
||||
priv->expand_timer = 0;
|
||||
g_source_remove (expander->expand_timer);
|
||||
expander->expand_timer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,13 +267,13 @@ gtk_expander_forall (GtkContainer *container,
|
||||
GtkCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (GTK_EXPANDER (container));
|
||||
GtkExpander *expander = GTK_EXPANDER (container);
|
||||
|
||||
if (priv->child)
|
||||
(*callback) (priv->child, user_data);
|
||||
if (expander->child)
|
||||
(*callback) (expander->child, user_data);
|
||||
|
||||
if (priv->label_widget)
|
||||
(*callback) (priv->label_widget, user_data);
|
||||
if (expander->label_widget)
|
||||
(*callback) (expander->label_widget, user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -382,30 +372,29 @@ gtk_expander_class_init (GtkExpanderClass *klass)
|
||||
static void
|
||||
gtk_expander_init (GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
GtkGesture *gesture;
|
||||
GtkEventController *controller;
|
||||
|
||||
priv->label_widget = NULL;
|
||||
priv->child = NULL;
|
||||
expander->label_widget = NULL;
|
||||
expander->child = NULL;
|
||||
|
||||
priv->expanded = FALSE;
|
||||
priv->use_underline = FALSE;
|
||||
priv->use_markup = FALSE;
|
||||
priv->expand_timer = 0;
|
||||
priv->resize_toplevel = 0;
|
||||
expander->expanded = FALSE;
|
||||
expander->use_underline = FALSE;
|
||||
expander->use_markup = FALSE;
|
||||
expander->expand_timer = 0;
|
||||
expander->resize_toplevel = 0;
|
||||
|
||||
priv->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_widget_set_parent (priv->box, GTK_WIDGET (expander));
|
||||
expander->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_widget_set_parent (expander->box, GTK_WIDGET (expander));
|
||||
|
||||
priv->title_widget = g_object_new (GTK_TYPE_BOX,
|
||||
expander->title_widget = g_object_new (GTK_TYPE_BOX,
|
||||
"css-name", "title",
|
||||
NULL);
|
||||
gtk_container_add (GTK_CONTAINER (priv->box), priv->title_widget);
|
||||
gtk_container_add (GTK_CONTAINER (expander->box), expander->title_widget);
|
||||
|
||||
priv->arrow_widget = gtk_builtin_icon_new ("expander");
|
||||
gtk_widget_add_css_class (priv->arrow_widget, GTK_STYLE_CLASS_HORIZONTAL);
|
||||
gtk_container_add (GTK_CONTAINER (priv->title_widget), priv->arrow_widget);
|
||||
expander->arrow_widget = gtk_builtin_icon_new ("expander");
|
||||
gtk_widget_add_css_class (expander->arrow_widget, GTK_STYLE_CLASS_HORIZONTAL);
|
||||
gtk_container_add (GTK_CONTAINER (expander->title_widget), expander->arrow_widget);
|
||||
|
||||
controller = gtk_drop_controller_motion_new ();
|
||||
g_signal_connect (controller, "enter", G_CALLBACK (gtk_expander_drag_enter), expander);
|
||||
@ -421,7 +410,7 @@ gtk_expander_init (GtkExpander *expander)
|
||||
G_CALLBACK (gesture_click_released_cb), expander);
|
||||
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture),
|
||||
GTK_PHASE_BUBBLE);
|
||||
gtk_widget_add_controller (GTK_WIDGET (priv->title_widget), GTK_EVENT_CONTROLLER (gesture));
|
||||
gtk_widget_add_controller (GTK_WIDGET (expander->title_widget), GTK_EVENT_CONTROLLER (gesture));
|
||||
}
|
||||
|
||||
static GtkBuildableIface *parent_buildable_iface;
|
||||
@ -487,26 +476,25 @@ gtk_expander_get_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkExpander *expander = GTK_EXPANDER (object);
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_EXPANDED:
|
||||
g_value_set_boolean (value, priv->expanded);
|
||||
g_value_set_boolean (value, expander->expanded);
|
||||
break;
|
||||
case PROP_LABEL:
|
||||
g_value_set_string (value, gtk_expander_get_label (expander));
|
||||
break;
|
||||
case PROP_USE_UNDERLINE:
|
||||
g_value_set_boolean (value, priv->use_underline);
|
||||
g_value_set_boolean (value, expander->use_underline);
|
||||
break;
|
||||
case PROP_USE_MARKUP:
|
||||
g_value_set_boolean (value, priv->use_markup);
|
||||
g_value_set_boolean (value, expander->use_markup);
|
||||
break;
|
||||
case PROP_LABEL_WIDGET:
|
||||
g_value_set_object (value,
|
||||
priv->label_widget ?
|
||||
G_OBJECT (priv->label_widget) : NULL);
|
||||
expander->label_widget ?
|
||||
G_OBJECT (expander->label_widget) : NULL);
|
||||
break;
|
||||
case PROP_RESIZE_TOPLEVEL:
|
||||
g_value_set_boolean (value, gtk_expander_get_resize_toplevel (expander));
|
||||
@ -520,21 +508,21 @@ gtk_expander_get_property (GObject *object,
|
||||
static void
|
||||
gtk_expander_destroy (GtkWidget *widget)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (GTK_EXPANDER (widget));
|
||||
GtkExpander *expander = GTK_EXPANDER (widget);
|
||||
|
||||
if (priv->expand_timer)
|
||||
if (expander->expand_timer)
|
||||
{
|
||||
g_source_remove (priv->expand_timer);
|
||||
priv->expand_timer = 0;
|
||||
g_source_remove (expander->expand_timer);
|
||||
expander->expand_timer = 0;
|
||||
}
|
||||
|
||||
if (priv->box)
|
||||
if (expander->box)
|
||||
{
|
||||
gtk_widget_unparent (priv->box);
|
||||
priv->box = NULL;
|
||||
priv->child = NULL;
|
||||
priv->label_widget = NULL;
|
||||
priv->arrow_widget = NULL;
|
||||
gtk_widget_unparent (expander->box);
|
||||
expander->box = NULL;
|
||||
expander->child = NULL;
|
||||
expander->label_widget = NULL;
|
||||
expander->arrow_widget = NULL;
|
||||
}
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_expander_parent_class)->destroy (widget);
|
||||
@ -546,9 +534,9 @@ gtk_expander_size_allocate (GtkWidget *widget,
|
||||
int height,
|
||||
int baseline)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (GTK_EXPANDER (widget));
|
||||
GtkExpander *expander = GTK_EXPANDER (widget);
|
||||
|
||||
gtk_widget_size_allocate (priv->box,
|
||||
gtk_widget_size_allocate (expander->box,
|
||||
&(GtkAllocation) {
|
||||
0, 0,
|
||||
width, height
|
||||
@ -592,21 +580,19 @@ focus_in_site (GtkExpander *expander,
|
||||
FocusSite site,
|
||||
GtkDirectionType direction)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
switch (site)
|
||||
{
|
||||
case FOCUS_WIDGET:
|
||||
gtk_widget_grab_focus (GTK_WIDGET (expander));
|
||||
return TRUE;
|
||||
case FOCUS_LABEL:
|
||||
if (priv->label_widget)
|
||||
return gtk_widget_child_focus (priv->label_widget, direction);
|
||||
if (expander->label_widget)
|
||||
return gtk_widget_child_focus (expander->label_widget, direction);
|
||||
else
|
||||
return FALSE;
|
||||
case FOCUS_CHILD:
|
||||
{
|
||||
GtkWidget *child = priv->child;
|
||||
GtkWidget *child = expander->child;
|
||||
|
||||
if (child && gtk_widget_get_child_visible (child))
|
||||
return gtk_widget_child_focus (child, direction);
|
||||
@ -704,10 +690,9 @@ get_next_site (GtkExpander *expander,
|
||||
static void
|
||||
gtk_expander_resize_toplevel (GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
GtkWidget *child = priv->child;
|
||||
GtkWidget *child = expander->child;
|
||||
|
||||
if (child && priv->resize_toplevel &&
|
||||
if (child && expander->resize_toplevel &&
|
||||
gtk_widget_get_realized (GTK_WIDGET (expander)))
|
||||
{
|
||||
GtkWidget *toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (expander)));
|
||||
@ -722,7 +707,7 @@ gtk_expander_resize_toplevel (GtkExpander *expander)
|
||||
&child_height, NULL, NULL, NULL);
|
||||
gtk_window_get_size (GTK_WINDOW (toplevel), &toplevel_width, &toplevel_height);
|
||||
|
||||
if (priv->expanded)
|
||||
if (expander->expanded)
|
||||
toplevel_height += child_height;
|
||||
else
|
||||
toplevel_height -= child_height;
|
||||
@ -739,7 +724,6 @@ gtk_expander_focus (GtkWidget *widget,
|
||||
GtkDirectionType direction)
|
||||
{
|
||||
GtkExpander *expander = GTK_EXPANDER (widget);
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
if (!focus_current_site (expander, direction))
|
||||
{
|
||||
@ -750,7 +734,7 @@ gtk_expander_focus (GtkWidget *widget,
|
||||
widget_is_focus = gtk_widget_is_focus (widget);
|
||||
old_focus_child = gtk_widget_get_focus_child (GTK_WIDGET (widget));
|
||||
|
||||
if (old_focus_child && old_focus_child == priv->label_widget)
|
||||
if (old_focus_child && old_focus_child == expander->label_widget)
|
||||
site = FOCUS_LABEL;
|
||||
else if (old_focus_child)
|
||||
site = FOCUS_CHILD;
|
||||
@ -774,9 +758,8 @@ gtk_expander_add (GtkContainer *container,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
GtkExpander *expander = GTK_EXPANDER (container);
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
if (priv->child != NULL)
|
||||
if (expander->child != NULL)
|
||||
{
|
||||
g_warning ("Attempting to add a widget with type %s to a %s, "
|
||||
"but a %s can only contain one widget at a time; "
|
||||
@ -784,13 +767,13 @@ gtk_expander_add (GtkContainer *container,
|
||||
g_type_name (G_OBJECT_TYPE (widget)),
|
||||
g_type_name (G_OBJECT_TYPE (container)),
|
||||
g_type_name (G_OBJECT_TYPE (container)),
|
||||
g_type_name (G_OBJECT_TYPE (priv->child)));
|
||||
g_type_name (G_OBJECT_TYPE (expander->child)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (priv->expanded)
|
||||
if (expander->expanded)
|
||||
{
|
||||
gtk_container_add (GTK_CONTAINER (priv->box), widget);
|
||||
gtk_container_add (GTK_CONTAINER (expander->box), widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -800,7 +783,7 @@ gtk_expander_add (GtkContainer *container,
|
||||
g_object_ref (widget);
|
||||
}
|
||||
|
||||
priv->child = widget;
|
||||
expander->child = widget;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -808,14 +791,13 @@ gtk_expander_remove (GtkContainer *container,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
GtkExpander *expander = GTK_EXPANDER (container);
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
if (priv->label_widget == widget)
|
||||
if (expander->label_widget == widget)
|
||||
gtk_expander_set_label_widget (expander, NULL);
|
||||
else
|
||||
{
|
||||
gtk_container_remove (GTK_CONTAINER (priv->box), widget);
|
||||
if (!priv->expanded)
|
||||
gtk_container_remove (GTK_CONTAINER (expander->box), widget);
|
||||
if (!expander->expanded)
|
||||
{
|
||||
/* We hold an extra ref */
|
||||
g_object_unref (widget);
|
||||
@ -827,9 +809,7 @@ gtk_expander_remove (GtkContainer *container,
|
||||
static void
|
||||
gtk_expander_activate (GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
gtk_expander_set_expanded (expander, !priv->expanded);
|
||||
gtk_expander_set_expanded (expander, !expander->expanded);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -842,9 +822,8 @@ gtk_expander_measure (GtkWidget *widget,
|
||||
int *natural_baseline)
|
||||
{
|
||||
GtkExpander *expander = GTK_EXPANDER (widget);
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
gtk_widget_measure (priv->box,
|
||||
gtk_widget_measure (expander->box,
|
||||
orientation,
|
||||
for_size,
|
||||
minimum, natural,
|
||||
@ -901,36 +880,35 @@ void
|
||||
gtk_expander_set_expanded (GtkExpander *expander,
|
||||
gboolean expanded)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
GtkWidget *child;
|
||||
|
||||
g_return_if_fail (GTK_IS_EXPANDER (expander));
|
||||
|
||||
expanded = expanded != FALSE;
|
||||
|
||||
if (priv->expanded == expanded)
|
||||
if (expander->expanded == expanded)
|
||||
return;
|
||||
|
||||
priv->expanded = expanded;
|
||||
expander->expanded = expanded;
|
||||
|
||||
if (priv->expanded)
|
||||
gtk_widget_set_state_flags (priv->arrow_widget, GTK_STATE_FLAG_CHECKED, FALSE);
|
||||
if (expander->expanded)
|
||||
gtk_widget_set_state_flags (expander->arrow_widget, GTK_STATE_FLAG_CHECKED, FALSE);
|
||||
else
|
||||
gtk_widget_unset_state_flags (priv->arrow_widget, GTK_STATE_FLAG_CHECKED);
|
||||
gtk_widget_unset_state_flags (expander->arrow_widget, GTK_STATE_FLAG_CHECKED);
|
||||
|
||||
child = priv->child;
|
||||
child = expander->child;
|
||||
|
||||
if (child)
|
||||
{
|
||||
if (priv->expanded)
|
||||
if (expander->expanded)
|
||||
{
|
||||
gtk_container_add (GTK_CONTAINER (priv->box), child);
|
||||
g_object_unref (priv->child);
|
||||
gtk_container_add (GTK_CONTAINER (expander->box), child);
|
||||
g_object_unref (expander->child);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_object_ref (priv->child);
|
||||
gtk_container_remove (GTK_CONTAINER (priv->box), child);
|
||||
g_object_ref (expander->child);
|
||||
gtk_container_remove (GTK_CONTAINER (expander->box), child);
|
||||
}
|
||||
gtk_expander_resize_toplevel (expander);
|
||||
}
|
||||
@ -952,11 +930,9 @@ gtk_expander_set_expanded (GtkExpander *expander,
|
||||
gboolean
|
||||
gtk_expander_get_expanded (GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_EXPANDER (expander), FALSE);
|
||||
|
||||
return priv->expanded;
|
||||
return expander->expanded;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -972,8 +948,6 @@ void
|
||||
gtk_expander_set_label (GtkExpander *expander,
|
||||
const gchar *label)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
g_return_if_fail (GTK_IS_EXPANDER (expander));
|
||||
|
||||
if (!label)
|
||||
@ -985,8 +959,8 @@ gtk_expander_set_label (GtkExpander *expander,
|
||||
GtkWidget *child;
|
||||
|
||||
child = gtk_label_new (label);
|
||||
gtk_label_set_use_underline (GTK_LABEL (child), priv->use_underline);
|
||||
gtk_label_set_use_markup (GTK_LABEL (child), priv->use_markup);
|
||||
gtk_label_set_use_underline (GTK_LABEL (child), expander->use_underline);
|
||||
gtk_label_set_use_markup (GTK_LABEL (child), expander->use_markup);
|
||||
gtk_widget_show (child);
|
||||
|
||||
gtk_expander_set_label_widget (expander, child);
|
||||
@ -1017,12 +991,10 @@ gtk_expander_set_label (GtkExpander *expander,
|
||||
const gchar *
|
||||
gtk_expander_get_label (GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_EXPANDER (expander), NULL);
|
||||
|
||||
if (GTK_IS_LABEL (priv->label_widget))
|
||||
return gtk_label_get_label (GTK_LABEL (priv->label_widget));
|
||||
if (GTK_IS_LABEL (expander->label_widget))
|
||||
return gtk_label_get_label (GTK_LABEL (expander->label_widget));
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
@ -1039,18 +1011,16 @@ void
|
||||
gtk_expander_set_use_underline (GtkExpander *expander,
|
||||
gboolean use_underline)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
g_return_if_fail (GTK_IS_EXPANDER (expander));
|
||||
|
||||
use_underline = use_underline != FALSE;
|
||||
|
||||
if (priv->use_underline != use_underline)
|
||||
if (expander->use_underline != use_underline)
|
||||
{
|
||||
priv->use_underline = use_underline;
|
||||
expander->use_underline = use_underline;
|
||||
|
||||
if (GTK_IS_LABEL (priv->label_widget))
|
||||
gtk_label_set_use_underline (GTK_LABEL (priv->label_widget), use_underline);
|
||||
if (GTK_IS_LABEL (expander->label_widget))
|
||||
gtk_label_set_use_underline (GTK_LABEL (expander->label_widget), use_underline);
|
||||
|
||||
g_object_notify (G_OBJECT (expander), "use-underline");
|
||||
}
|
||||
@ -1069,11 +1039,9 @@ gtk_expander_set_use_underline (GtkExpander *expander,
|
||||
gboolean
|
||||
gtk_expander_get_use_underline (GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_EXPANDER (expander), FALSE);
|
||||
|
||||
return priv->use_underline;
|
||||
return expander->use_underline;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1089,18 +1057,16 @@ void
|
||||
gtk_expander_set_use_markup (GtkExpander *expander,
|
||||
gboolean use_markup)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
g_return_if_fail (GTK_IS_EXPANDER (expander));
|
||||
|
||||
use_markup = use_markup != FALSE;
|
||||
|
||||
if (priv->use_markup != use_markup)
|
||||
if (expander->use_markup != use_markup)
|
||||
{
|
||||
priv->use_markup = use_markup;
|
||||
expander->use_markup = use_markup;
|
||||
|
||||
if (GTK_IS_LABEL (priv->label_widget))
|
||||
gtk_label_set_use_markup (GTK_LABEL (priv->label_widget), use_markup);
|
||||
if (GTK_IS_LABEL (expander->label_widget))
|
||||
gtk_label_set_use_markup (GTK_LABEL (expander->label_widget), use_markup);
|
||||
|
||||
g_object_notify (G_OBJECT (expander), "use-markup");
|
||||
}
|
||||
@ -1119,11 +1085,9 @@ gtk_expander_set_use_markup (GtkExpander *expander,
|
||||
gboolean
|
||||
gtk_expander_get_use_markup (GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_EXPANDER (expander), FALSE);
|
||||
|
||||
return priv->use_markup;
|
||||
return expander->use_markup;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1138,29 +1102,28 @@ void
|
||||
gtk_expander_set_label_widget (GtkExpander *expander,
|
||||
GtkWidget *label_widget)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
GtkWidget *widget;
|
||||
|
||||
g_return_if_fail (GTK_IS_EXPANDER (expander));
|
||||
g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
|
||||
g_return_if_fail (label_widget == NULL || gtk_widget_get_parent (label_widget) == NULL);
|
||||
|
||||
if (priv->label_widget == label_widget)
|
||||
if (expander->label_widget == label_widget)
|
||||
return;
|
||||
|
||||
if (priv->label_widget)
|
||||
if (expander->label_widget)
|
||||
{
|
||||
gtk_container_remove (GTK_CONTAINER (priv->title_widget), priv->label_widget);
|
||||
gtk_container_remove (GTK_CONTAINER (expander->title_widget), expander->label_widget);
|
||||
}
|
||||
|
||||
priv->label_widget = label_widget;
|
||||
expander->label_widget = label_widget;
|
||||
widget = GTK_WIDGET (expander);
|
||||
|
||||
if (label_widget)
|
||||
{
|
||||
priv->label_widget = label_widget;
|
||||
expander->label_widget = label_widget;
|
||||
|
||||
gtk_container_add (GTK_CONTAINER (priv->title_widget), label_widget);
|
||||
gtk_container_add (GTK_CONTAINER (expander->title_widget), label_widget);
|
||||
}
|
||||
|
||||
if (gtk_widget_get_visible (widget))
|
||||
@ -1185,11 +1148,9 @@ gtk_expander_set_label_widget (GtkExpander *expander,
|
||||
GtkWidget *
|
||||
gtk_expander_get_label_widget (GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_EXPANDER (expander), NULL);
|
||||
|
||||
return priv->label_widget;
|
||||
return expander->label_widget;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1204,13 +1165,11 @@ void
|
||||
gtk_expander_set_resize_toplevel (GtkExpander *expander,
|
||||
gboolean resize_toplevel)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
g_return_if_fail (GTK_IS_EXPANDER (expander));
|
||||
|
||||
if (priv->resize_toplevel != resize_toplevel)
|
||||
if (expander->resize_toplevel != resize_toplevel)
|
||||
{
|
||||
priv->resize_toplevel = resize_toplevel ? TRUE : FALSE;
|
||||
expander->resize_toplevel = resize_toplevel ? TRUE : FALSE;
|
||||
g_object_notify (G_OBJECT (expander), "resize-toplevel");
|
||||
}
|
||||
}
|
||||
@ -1227,9 +1186,7 @@ gtk_expander_set_resize_toplevel (GtkExpander *expander,
|
||||
gboolean
|
||||
gtk_expander_get_resize_toplevel (GtkExpander *expander)
|
||||
{
|
||||
GtkExpanderPrivate *priv = gtk_expander_get_instance_private (expander);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_EXPANDER (expander), FALSE);
|
||||
|
||||
return priv->resize_toplevel;
|
||||
return expander->resize_toplevel;
|
||||
}
|
||||
|
@ -70,17 +70,7 @@
|
||||
struct _GtkLockButton
|
||||
{
|
||||
GtkButton parent_instance;
|
||||
};
|
||||
|
||||
typedef struct _GtkLockButtonClass GtkLockButtonClass;
|
||||
struct _GtkLockButtonClass
|
||||
{
|
||||
GtkButtonClass parent_class;
|
||||
};
|
||||
|
||||
typedef struct _GtkLockButtonPrivate GtkLockButtonPrivate;
|
||||
struct _GtkLockButtonPrivate
|
||||
{
|
||||
GPermission *permission;
|
||||
GCancellable *cancellable;
|
||||
|
||||
@ -97,6 +87,12 @@ struct _GtkLockButtonPrivate
|
||||
GtkWidget *label_unlock;
|
||||
};
|
||||
|
||||
typedef struct _GtkLockButtonClass GtkLockButtonClass;
|
||||
struct _GtkLockButtonClass
|
||||
{
|
||||
GtkButtonClass parent_class;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
@ -115,33 +111,32 @@ static void on_permission_changed (GPermission *permission,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data);
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GtkLockButton, gtk_lock_button, GTK_TYPE_BUTTON)
|
||||
G_DEFINE_TYPE (GtkLockButton, gtk_lock_button, GTK_TYPE_BUTTON)
|
||||
|
||||
static void
|
||||
gtk_lock_button_finalize (GObject *object)
|
||||
{
|
||||
GtkLockButton *button = GTK_LOCK_BUTTON (object);
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
|
||||
|
||||
g_free (priv->tooltip_lock);
|
||||
g_free (priv->tooltip_unlock);
|
||||
g_free (priv->tooltip_not_authorized);
|
||||
g_free (button->tooltip_lock);
|
||||
g_free (button->tooltip_unlock);
|
||||
g_free (button->tooltip_not_authorized);
|
||||
|
||||
g_object_unref (priv->icon_lock);
|
||||
g_object_unref (priv->icon_unlock);
|
||||
g_object_unref (button->icon_lock);
|
||||
g_object_unref (button->icon_unlock);
|
||||
|
||||
if (priv->cancellable != NULL)
|
||||
if (button->cancellable != NULL)
|
||||
{
|
||||
g_cancellable_cancel (priv->cancellable);
|
||||
g_object_unref (priv->cancellable);
|
||||
g_cancellable_cancel (button->cancellable);
|
||||
g_object_unref (button->cancellable);
|
||||
}
|
||||
|
||||
if (priv->permission)
|
||||
if (button->permission)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (priv->permission,
|
||||
g_signal_handlers_disconnect_by_func (button->permission,
|
||||
on_permission_changed,
|
||||
button);
|
||||
g_object_unref (priv->permission);
|
||||
g_object_unref (button->permission);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gtk_lock_button_parent_class)->finalize (object);
|
||||
@ -154,32 +149,31 @@ gtk_lock_button_get_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkLockButton *button = GTK_LOCK_BUTTON (object);
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_PERMISSION:
|
||||
g_value_set_object (value, priv->permission);
|
||||
g_value_set_object (value, button->permission);
|
||||
break;
|
||||
|
||||
case PROP_TEXT_LOCK:
|
||||
g_value_set_string (value, gtk_label_get_text (GTK_LABEL (priv->label_lock)));
|
||||
g_value_set_string (value, gtk_label_get_text (GTK_LABEL (button->label_lock)));
|
||||
break;
|
||||
|
||||
case PROP_TEXT_UNLOCK:
|
||||
g_value_set_string (value, gtk_label_get_text (GTK_LABEL (priv->label_unlock)));
|
||||
g_value_set_string (value, gtk_label_get_text (GTK_LABEL (button->label_unlock)));
|
||||
break;
|
||||
|
||||
case PROP_TOOLTIP_LOCK:
|
||||
g_value_set_string (value, priv->tooltip_lock);
|
||||
g_value_set_string (value, button->tooltip_lock);
|
||||
break;
|
||||
|
||||
case PROP_TOOLTIP_UNLOCK:
|
||||
g_value_set_string (value, priv->tooltip_unlock);
|
||||
g_value_set_string (value, button->tooltip_unlock);
|
||||
break;
|
||||
|
||||
case PROP_TOOLTIP_NOT_AUTHORIZED:
|
||||
g_value_set_string (value, priv->tooltip_not_authorized);
|
||||
g_value_set_string (value, button->tooltip_not_authorized);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -195,7 +189,6 @@ gtk_lock_button_set_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkLockButton *button = GTK_LOCK_BUTTON (object);
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
@ -204,28 +197,28 @@ gtk_lock_button_set_property (GObject *object,
|
||||
break;
|
||||
|
||||
case PROP_TEXT_LOCK:
|
||||
gtk_label_set_text (GTK_LABEL (priv->label_lock), g_value_get_string (value));
|
||||
gtk_label_set_text (GTK_LABEL (button->label_lock), g_value_get_string (value));
|
||||
_gtk_lock_button_accessible_name_changed (button);
|
||||
break;
|
||||
|
||||
case PROP_TEXT_UNLOCK:
|
||||
gtk_label_set_text (GTK_LABEL (priv->label_unlock), g_value_get_string (value));
|
||||
gtk_label_set_text (GTK_LABEL (button->label_unlock), g_value_get_string (value));
|
||||
_gtk_lock_button_accessible_name_changed (button);
|
||||
break;
|
||||
|
||||
case PROP_TOOLTIP_LOCK:
|
||||
g_free (priv->tooltip_lock);
|
||||
priv->tooltip_lock = g_value_dup_string (value);
|
||||
g_free (button->tooltip_lock);
|
||||
button->tooltip_lock = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_TOOLTIP_UNLOCK:
|
||||
g_free (priv->tooltip_unlock);
|
||||
priv->tooltip_unlock = g_value_dup_string (value);
|
||||
g_free (button->tooltip_unlock);
|
||||
button->tooltip_unlock = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
case PROP_TOOLTIP_NOT_AUTHORIZED:
|
||||
g_free (priv->tooltip_not_authorized);
|
||||
priv->tooltip_not_authorized = g_value_dup_string (value);
|
||||
g_free (button->tooltip_not_authorized);
|
||||
button->tooltip_not_authorized = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -239,7 +232,6 @@ gtk_lock_button_set_property (GObject *object,
|
||||
static void
|
||||
gtk_lock_button_init (GtkLockButton *button)
|
||||
{
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
|
||||
const char *names[3];
|
||||
|
||||
gtk_widget_init_template (GTK_WIDGET (button));
|
||||
@ -247,12 +239,12 @@ gtk_lock_button_init (GtkLockButton *button)
|
||||
names[0] = "changes-allow-symbolic";
|
||||
names[1] = "changes-allow";
|
||||
names[2] = NULL;
|
||||
priv->icon_unlock = g_themed_icon_new_from_names ((char **) names, -1);
|
||||
button->icon_unlock = g_themed_icon_new_from_names ((char **) names, -1);
|
||||
|
||||
names[0] = "changes-prevent-symbolic";
|
||||
names[1] = "changes-prevent";
|
||||
names[2] = NULL;
|
||||
priv->icon_lock = g_themed_icon_new_from_names ((char **) names, -1);
|
||||
button->icon_lock = g_themed_icon_new_from_names ((char **) names, -1);
|
||||
|
||||
update_state (button);
|
||||
|
||||
@ -328,11 +320,11 @@ gtk_lock_button_class_init (GtkLockButtonClass *klass)
|
||||
/* Bind class to template
|
||||
*/
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtklockbutton.ui");
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkLockButton, box);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkLockButton, image);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkLockButton, label_lock);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkLockButton, label_unlock);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GtkLockButton, stack);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkLockButton, box);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkLockButton, image);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkLockButton, label_lock);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkLockButton, label_unlock);
|
||||
gtk_widget_class_bind_template_child (widget_class, GtkLockButton, stack);
|
||||
|
||||
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LOCK_BUTTON_ACCESSIBLE);
|
||||
gtk_widget_class_set_css_name (widget_class, I_("button"));
|
||||
@ -341,7 +333,6 @@ gtk_lock_button_class_init (GtkLockButtonClass *klass)
|
||||
static void
|
||||
update_state (GtkLockButton *button)
|
||||
{
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
|
||||
gboolean allowed;
|
||||
gboolean can_acquire;
|
||||
gboolean can_release;
|
||||
@ -350,11 +341,11 @@ update_state (GtkLockButton *button)
|
||||
GIcon *icon;
|
||||
const gchar *tooltip;
|
||||
|
||||
if (priv->permission)
|
||||
if (button->permission)
|
||||
{
|
||||
allowed = g_permission_get_allowed (priv->permission);
|
||||
can_acquire = g_permission_get_can_acquire (priv->permission);
|
||||
can_release = g_permission_get_can_release (priv->permission);
|
||||
allowed = g_permission_get_allowed (button->permission);
|
||||
can_acquire = g_permission_get_can_acquire (button->permission);
|
||||
can_release = g_permission_get_can_release (button->permission);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -367,38 +358,38 @@ update_state (GtkLockButton *button)
|
||||
{
|
||||
visible = TRUE;
|
||||
sensitive = TRUE;
|
||||
icon = priv->icon_lock;
|
||||
tooltip = priv->tooltip_lock;
|
||||
icon = button->icon_lock;
|
||||
tooltip = button->tooltip_lock;
|
||||
}
|
||||
else if (allowed && !can_release)
|
||||
{
|
||||
visible = FALSE;
|
||||
sensitive = TRUE;
|
||||
icon = priv->icon_lock;
|
||||
tooltip = priv->tooltip_lock;
|
||||
icon = button->icon_lock;
|
||||
tooltip = button->tooltip_lock;
|
||||
}
|
||||
else if (!allowed && can_acquire)
|
||||
{
|
||||
visible = TRUE;
|
||||
sensitive = TRUE;
|
||||
icon = priv->icon_unlock;
|
||||
tooltip = priv->tooltip_unlock;
|
||||
icon = button->icon_unlock;
|
||||
tooltip = button->tooltip_unlock;
|
||||
}
|
||||
else if (!allowed && !can_acquire)
|
||||
{
|
||||
visible = TRUE;
|
||||
sensitive = FALSE;
|
||||
icon = priv->icon_unlock;
|
||||
tooltip = priv->tooltip_not_authorized;
|
||||
icon = button->icon_unlock;
|
||||
tooltip = button->tooltip_not_authorized;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
gtk_image_set_from_gicon (GTK_IMAGE (priv->image), icon);
|
||||
gtk_stack_set_visible_child (GTK_STACK (priv->stack),
|
||||
allowed ? priv->label_lock : priv->label_unlock);
|
||||
gtk_image_set_from_gicon (GTK_IMAGE (button->image), icon);
|
||||
gtk_stack_set_visible_child (GTK_STACK (button->stack),
|
||||
allowed ? button->label_lock : button->label_unlock);
|
||||
_gtk_lock_button_accessible_name_changed (button);
|
||||
gtk_widget_set_tooltip_markup (GTK_WIDGET (button), tooltip);
|
||||
gtk_widget_set_sensitive (GTK_WIDGET (button), sensitive);
|
||||
@ -421,18 +412,17 @@ acquire_cb (GObject *source,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkLockButton *button = GTK_LOCK_BUTTON (user_data);
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
|
||||
GError *error;
|
||||
|
||||
error = NULL;
|
||||
if (!g_permission_acquire_finish (priv->permission, result, &error))
|
||||
if (!g_permission_acquire_finish (button->permission, result, &error))
|
||||
{
|
||||
g_warning ("Error acquiring permission: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_object_unref (priv->cancellable);
|
||||
priv->cancellable = NULL;
|
||||
g_object_unref (button->cancellable);
|
||||
button->cancellable = NULL;
|
||||
|
||||
update_state (button);
|
||||
}
|
||||
@ -443,53 +433,52 @@ release_cb (GObject *source,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkLockButton *button = GTK_LOCK_BUTTON (user_data);
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
|
||||
GError *error;
|
||||
|
||||
error = NULL;
|
||||
if (!g_permission_release_finish (priv->permission, result, &error))
|
||||
if (!g_permission_release_finish (button->permission, result, &error))
|
||||
{
|
||||
g_warning ("Error releasing permission: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_object_unref (priv->cancellable);
|
||||
priv->cancellable = NULL;
|
||||
g_object_unref (button->cancellable);
|
||||
button->cancellable = NULL;
|
||||
|
||||
update_state (button);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_lock_button_clicked (GtkButton *button)
|
||||
gtk_lock_button_clicked (GtkButton *widget)
|
||||
{
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (GTK_LOCK_BUTTON (button));
|
||||
GtkLockButton *button = GTK_LOCK_BUTTON (widget);
|
||||
|
||||
/* if we already have a pending interactive check or permission is not set,
|
||||
* then do nothing
|
||||
*/
|
||||
if (priv->cancellable != NULL || priv->permission == NULL)
|
||||
if (button->cancellable != NULL || button->permission == NULL)
|
||||
return;
|
||||
|
||||
if (g_permission_get_allowed (priv->permission))
|
||||
if (g_permission_get_allowed (button->permission))
|
||||
{
|
||||
if (g_permission_get_can_release (priv->permission))
|
||||
if (g_permission_get_can_release (button->permission))
|
||||
{
|
||||
priv->cancellable = g_cancellable_new ();
|
||||
button->cancellable = g_cancellable_new ();
|
||||
|
||||
g_permission_release_async (priv->permission,
|
||||
priv->cancellable,
|
||||
g_permission_release_async (button->permission,
|
||||
button->cancellable,
|
||||
release_cb,
|
||||
button);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_permission_get_can_acquire (priv->permission))
|
||||
if (g_permission_get_can_acquire (button->permission))
|
||||
{
|
||||
priv->cancellable = g_cancellable_new ();
|
||||
button->cancellable = g_cancellable_new ();
|
||||
|
||||
g_permission_acquire_async (priv->permission,
|
||||
priv->cancellable,
|
||||
g_permission_acquire_async (button->permission,
|
||||
button->cancellable,
|
||||
acquire_cb,
|
||||
button);
|
||||
}
|
||||
@ -523,11 +512,9 @@ gtk_lock_button_new (GPermission *permission)
|
||||
GPermission *
|
||||
gtk_lock_button_get_permission (GtkLockButton *button)
|
||||
{
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_LOCK_BUTTON (button), NULL);
|
||||
|
||||
return priv->permission;
|
||||
return button->permission;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -541,27 +528,25 @@ void
|
||||
gtk_lock_button_set_permission (GtkLockButton *button,
|
||||
GPermission *permission)
|
||||
{
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
|
||||
|
||||
g_return_if_fail (GTK_IS_LOCK_BUTTON (button));
|
||||
g_return_if_fail (permission == NULL || G_IS_PERMISSION (permission));
|
||||
|
||||
if (priv->permission != permission)
|
||||
if (button->permission != permission)
|
||||
{
|
||||
if (priv->permission)
|
||||
if (button->permission)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (priv->permission,
|
||||
g_signal_handlers_disconnect_by_func (button->permission,
|
||||
on_permission_changed,
|
||||
button);
|
||||
g_object_unref (priv->permission);
|
||||
g_object_unref (button->permission);
|
||||
}
|
||||
|
||||
priv->permission = permission;
|
||||
button->permission = permission;
|
||||
|
||||
if (priv->permission)
|
||||
if (button->permission)
|
||||
{
|
||||
g_object_ref (priv->permission);
|
||||
g_signal_connect (priv->permission, "notify",
|
||||
g_object_ref (button->permission);
|
||||
g_signal_connect (button->permission, "notify",
|
||||
G_CALLBACK (on_permission_changed), button);
|
||||
}
|
||||
|
||||
@ -574,12 +559,11 @@ gtk_lock_button_set_permission (GtkLockButton *button,
|
||||
const char *
|
||||
_gtk_lock_button_get_current_text (GtkLockButton *button)
|
||||
{
|
||||
GtkLockButtonPrivate *priv = gtk_lock_button_get_instance_private (button);
|
||||
GtkWidget *label;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_LOCK_BUTTON (button), NULL);
|
||||
|
||||
label = gtk_stack_get_visible_child (GTK_STACK (priv->stack));
|
||||
label = gtk_stack_get_visible_child (GTK_STACK (button->stack));
|
||||
|
||||
return gtk_label_get_text (GTK_LABEL (label));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user