Merge branch 'modal-buttons' into 'master'

Modal buttons

See merge request GNOME/gtk!1679
This commit is contained in:
Matthias Clasen 2020-04-13 11:15:14 +00:00
commit 64b0c63190
9 changed files with 884 additions and 810 deletions

View File

@ -599,6 +599,8 @@ gtk_color_button_new
gtk_color_button_new_with_rgba
gtk_color_button_set_title
gtk_color_button_get_title
gtk_color_button_set_modal
gtk_color_button_get_modal
<SUBSECTION Standard>
GTK_COLOR_BUTTON
GTK_IS_COLOR_BUTTON
@ -1155,6 +1157,8 @@ gtk_file_chooser_button_get_title
gtk_file_chooser_button_set_title
gtk_file_chooser_button_get_width_chars
gtk_file_chooser_button_set_width_chars
gtk_file_chooser_button_get_modal
gtk_file_chooser_button_set_modal
<SUBSECTION Standard>
GTK_FILE_CHOOSER_BUTTON
@ -1269,6 +1273,8 @@ gtk_font_button_set_use_size
gtk_font_button_get_use_size
gtk_font_button_set_title
gtk_font_button_get_title
gtk_font_button_set_modal
gtk_font_button_get_modal
<SUBSECTION Standard>
GTK_FONT_BUTTON
GTK_IS_FONT_BUTTON
@ -5337,6 +5343,8 @@ gtk_app_chooser_button_get_show_dialog_item
gtk_app_chooser_button_set_show_dialog_item
gtk_app_chooser_button_get_heading
gtk_app_chooser_button_set_heading
gtk_app_chooser_button_get_modal
gtk_app_chooser_button_set_modal
<SUBSECTION Standard>
GTK_TYPE_APP_CHOOSER_BUTTON

View File

@ -66,6 +66,7 @@ enum {
PROP_SHOW_DIALOG_ITEM = 1,
PROP_SHOW_DEFAULT_ITEM,
PROP_HEADING,
PROP_MODAL,
NUM_PROPERTIES,
PROP_CONTENT_TYPE = NUM_PROPERTIES
@ -109,6 +110,18 @@ typedef struct _GtkAppChooserButtonClass GtkAppChooserButtonClass;
struct _GtkAppChooserButton {
GtkWidget parent_instance;
GtkWidget *combobox;
GtkListStore *store;
gchar *content_type;
gchar *heading;
gint last_active;
gboolean show_dialog_item;
gboolean show_default_item;
gboolean modal;
GHashTable *custom_item_names;
};
struct _GtkAppChooserButtonClass {
@ -119,22 +132,7 @@ struct _GtkAppChooserButtonClass {
const gchar *item_name);
};
typedef struct
{
GtkWidget *combobox;
GtkListStore *store;
gchar *content_type;
gchar *heading;
gint last_active;
gboolean show_dialog_item;
gboolean show_default_item;
GHashTable *custom_item_names;
} GtkAppChooserButtonPrivate;
G_DEFINE_TYPE_WITH_CODE (GtkAppChooserButton, gtk_app_chooser_button, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkAppChooserButton)
G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER,
app_chooser_iface_init));
@ -193,7 +191,6 @@ select_application_func_cb (GtkTreeModel *model,
{
SelectAppData *data = user_data;
GtkAppChooserButton *self = data->self;
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GAppInfo *app_to_match = data->info;
GAppInfo *app = NULL;
gboolean custom;
@ -211,7 +208,7 @@ select_application_func_cb (GtkTreeModel *model,
result = TRUE;
else if (g_app_info_equal (app, app_to_match))
{
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->combobox), iter);
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self->combobox), iter);
result = TRUE;
}
else
@ -226,14 +223,13 @@ static void
gtk_app_chooser_button_select_application (GtkAppChooserButton *self,
GAppInfo *info)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
SelectAppData *data;
data = g_slice_new0 (SelectAppData);
data->self = g_object_ref (self);
data->info = g_object_ref (info);
gtk_tree_model_foreach (GTK_TREE_MODEL (priv->store),
gtk_tree_model_foreach (GTK_TREE_MODEL (self->store),
select_application_func_cb, data);
select_app_data_free (data);
@ -245,7 +241,6 @@ other_application_dialog_response_cb (GtkDialog *dialog,
gpointer user_data)
{
GtkAppChooserButton *self = user_data;
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GAppInfo *info;
if (response_id != GTK_RESPONSE_OK)
@ -253,7 +248,7 @@ other_application_dialog_response_cb (GtkDialog *dialog,
/* reset the active item, otherwise we are stuck on
* 'Other application'
*/
gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox), priv->last_active);
gtk_combo_box_set_active (GTK_COMBO_BOX (self->combobox), self->last_active);
gtk_widget_destroy (GTK_WIDGET (dialog));
return;
}
@ -272,16 +267,15 @@ other_application_dialog_response_cb (GtkDialog *dialog,
static void
other_application_item_activated_cb (GtkAppChooserButton *self)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GtkWidget *dialog, *widget;
GtkRoot *root;
root = gtk_widget_get_root (GTK_WIDGET (self));
dialog = gtk_app_chooser_dialog_new_for_content_type (GTK_WINDOW (root),
GTK_DIALOG_DESTROY_WITH_PARENT,
priv->content_type);
gtk_window_set_modal (GTK_WINDOW (dialog), gtk_window_get_modal (GTK_WINDOW (root)));
gtk_app_chooser_dialog_set_heading (GTK_APP_CHOOSER_DIALOG (dialog), priv->heading);
self->content_type);
gtk_window_set_modal (GTK_WINDOW (dialog), self->modal | gtk_window_get_modal (GTK_WINDOW (root)));
gtk_app_chooser_dialog_set_heading (GTK_APP_CHOOSER_DIALOG (dialog), self->heading);
widget = gtk_app_chooser_dialog_get_widget (GTK_APP_CHOOSER_DIALOG (dialog));
g_object_set (widget,
@ -298,21 +292,20 @@ static void
gtk_app_chooser_button_ensure_dialog_item (GtkAppChooserButton *self,
GtkTreeIter *prev_iter)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GtkTreeIter iter, iter2;
if (!priv->show_dialog_item || !priv->content_type)
if (!self->show_dialog_item || !self->content_type)
return;
if (prev_iter == NULL)
gtk_list_store_append (priv->store, &iter);
gtk_list_store_append (self->store, &iter);
else
gtk_list_store_insert_after (priv->store, &iter, prev_iter);
gtk_list_store_insert_after (self->store, &iter, prev_iter);
real_insert_separator (self, FALSE, &iter);
iter2 = iter;
gtk_list_store_insert_after (priv->store, &iter, &iter2);
gtk_list_store_insert_after (self->store, &iter, &iter2);
real_insert_custom_item (self, CUSTOM_ITEM_OTHER_APP,
_("Other application…"), NULL,
FALSE, &iter);
@ -323,7 +316,6 @@ insert_one_application (GtkAppChooserButton *self,
GAppInfo *app,
GtkTreeIter *iter)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GIcon *icon;
icon = g_app_info_get_icon (app);
@ -333,7 +325,7 @@ insert_one_application (GtkAppChooserButton *self,
else
g_object_ref (icon);
gtk_list_store_set (priv->store, iter,
gtk_list_store_set (self->store, iter,
COLUMN_APP_INFO, app,
COLUMN_LABEL, g_app_info_get_name (app),
COLUMN_ICON, icon,
@ -346,26 +338,25 @@ insert_one_application (GtkAppChooserButton *self,
static void
gtk_app_chooser_button_populate (GtkAppChooserButton *self)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GList *recommended_apps = NULL, *l;
GAppInfo *app, *default_app = NULL;
GtkTreeIter iter, iter2;
gboolean cycled_recommended;
#ifndef G_OS_WIN32
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);
#endif
cycled_recommended = FALSE;
if (priv->show_default_item)
if (self->show_default_item)
{
if (priv->content_type)
default_app = g_app_info_get_default_for_type (priv->content_type, FALSE);
if (self->content_type)
default_app = g_app_info_get_default_for_type (self->content_type, FALSE);
if (default_app != NULL)
{
get_first_iter (priv->store, &iter);
get_first_iter (self->store, &iter);
cycled_recommended = TRUE;
insert_one_application (self, default_app, &iter);
@ -383,12 +374,12 @@ gtk_app_chooser_button_populate (GtkAppChooserButton *self)
if (cycled_recommended)
{
gtk_list_store_insert_after (priv->store, &iter2, &iter);
gtk_list_store_insert_after (self->store, &iter2, &iter);
iter = iter2;
}
else
{
get_first_iter (priv->store, &iter);
get_first_iter (self->store, &iter);
cycled_recommended = TRUE;
}
@ -403,22 +394,21 @@ gtk_app_chooser_button_populate (GtkAppChooserButton *self)
else
gtk_app_chooser_button_ensure_dialog_item (self, &iter);
gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combobox), 0);
gtk_combo_box_set_active (GTK_COMBO_BOX (self->combobox), 0);
}
static void
gtk_app_chooser_button_build_ui (GtkAppChooserButton *self)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GtkCellRenderer *cell;
GtkCellArea *area;
gtk_combo_box_set_model (GTK_COMBO_BOX (priv->combobox),
GTK_TREE_MODEL (priv->store));
gtk_combo_box_set_model (GTK_COMBO_BOX (self->combobox),
GTK_TREE_MODEL (self->store));
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (priv->combobox));
area = gtk_cell_layout_get_area (GTK_CELL_LAYOUT (self->combobox));
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (priv->combobox),
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (self->combobox),
row_separator_func, NULL, NULL);
cell = gtk_cell_renderer_pixbuf_new ();
@ -427,7 +417,7 @@ gtk_app_chooser_button_build_ui (GtkAppChooserButton *self)
"expand", FALSE,
"fixed-size", FALSE,
NULL);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->combobox), cell,
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self->combobox), cell,
"gicon", COLUMN_ICON,
NULL);
@ -436,7 +426,7 @@ gtk_app_chooser_button_build_ui (GtkAppChooserButton *self)
"align", FALSE,
"expand", TRUE,
NULL);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->combobox), cell,
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self->combobox), cell,
"text", COLUMN_LABEL,
NULL);
@ -446,12 +436,11 @@ gtk_app_chooser_button_build_ui (GtkAppChooserButton *self)
static void
gtk_app_chooser_button_remove_non_custom (GtkAppChooserButton *self)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GtkTreeModel *model;
GtkTreeIter iter;
gboolean custom, res;
model = GTK_TREE_MODEL (priv->store);
model = GTK_TREE_MODEL (self->store);
if (!gtk_tree_model_get_iter_first (model, &iter))
return;
@ -472,7 +461,6 @@ gtk_app_chooser_button_changed (GtkComboBox *object,
gpointer user_data)
{
GtkAppChooserButton *self = user_data;
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GtkTreeIter iter;
gchar *name = NULL;
gboolean custom;
@ -481,7 +469,7 @@ gtk_app_chooser_button_changed (GtkComboBox *object,
if (!gtk_combo_box_get_active_iter (object, &iter))
return;
gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter,
COLUMN_NAME, &name,
COLUMN_CUSTOM, &custom,
-1);
@ -492,7 +480,7 @@ gtk_app_chooser_button_changed (GtkComboBox *object,
{
name_quark = g_quark_from_string (name);
g_signal_emit (self, signals[SIGNAL_CUSTOM_ITEM_ACTIVATED], name_quark, name);
priv->last_active = gtk_combo_box_get_active (object);
self->last_active = gtk_combo_box_get_active (object);
}
else
{
@ -503,7 +491,7 @@ gtk_app_chooser_button_changed (GtkComboBox *object,
g_free (name);
}
else
priv->last_active = gtk_combo_box_get_active (object);
self->last_active = gtk_combo_box_get_active (object);
g_signal_emit (self, signals[SIGNAL_CHANGED], 0);
}
@ -521,14 +509,13 @@ static GAppInfo *
gtk_app_chooser_button_get_app_info (GtkAppChooser *object)
{
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (object);
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GtkTreeIter iter;
GAppInfo *info;
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->combobox), &iter))
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self->combobox), &iter))
return NULL;
gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter,
COLUMN_APP_INFO, &info,
-1);
@ -553,12 +540,11 @@ gtk_app_chooser_button_set_property (GObject *obj,
GParamSpec *pspec)
{
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_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_DIALOG_ITEM:
gtk_app_chooser_button_set_show_dialog_item (self, g_value_get_boolean (value));
@ -569,6 +555,9 @@ gtk_app_chooser_button_set_property (GObject *obj,
case PROP_HEADING:
gtk_app_chooser_button_set_heading (self, g_value_get_string (value));
break;
case PROP_MODAL:
gtk_app_chooser_button_set_modal (self, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
break;
@ -582,21 +571,23 @@ gtk_app_chooser_button_get_property (GObject *obj,
GParamSpec *pspec)
{
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_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_DIALOG_ITEM:
g_value_set_boolean (value, priv->show_dialog_item);
g_value_set_boolean (value, self->show_dialog_item);
break;
case PROP_SHOW_DEFAULT_ITEM:
g_value_set_boolean (value, priv->show_default_item);
g_value_set_boolean (value, self->show_default_item);
break;
case PROP_HEADING:
g_value_set_string (value, priv->heading);
g_value_set_string (value, self->heading);
break;
case PROP_MODAL:
g_value_set_boolean (value, self->modal);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
@ -608,13 +599,12 @@ static void
gtk_app_chooser_button_finalize (GObject *obj)
{
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (obj);
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
g_hash_table_destroy (priv->custom_item_names);
g_free (priv->content_type);
g_free (priv->heading);
g_object_unref (priv->store);
gtk_widget_unparent (priv->combobox);
g_hash_table_destroy (self->custom_item_names);
g_free (self->content_type);
g_free (self->heading);
g_object_unref (self->store);
gtk_widget_unparent (self->combobox);
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->finalize (obj);
}
@ -628,10 +618,9 @@ gtk_app_chooser_button_measure (GtkWidget *widget,
int *minimum_baseline,
int *natural_baseline)
{
GtkAppChooserButton *button = GTK_APP_CHOOSER_BUTTON (widget);
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (button);
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (widget);
gtk_widget_measure (priv->combobox, orientation, for_size,
gtk_widget_measure (self->combobox, orientation, for_size,
minimum, natural,
minimum_baseline, natural_baseline);
}
@ -642,10 +631,9 @@ gtk_app_chooser_button_size_allocate (GtkWidget *widget,
int height,
int baseline)
{
GtkAppChooserButton *button = GTK_APP_CHOOSER_BUTTON (widget);
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (button);
GtkAppChooserButton *self = GTK_APP_CHOOSER_BUTTON (widget);
gtk_widget_size_allocate (priv->combobox, &(GtkAllocation){0, 0, width, height}, baseline);
gtk_widget_size_allocate (self->combobox, &(GtkAllocation){0, 0, width, height}, baseline);
}
static void
@ -714,6 +702,12 @@ gtk_app_chooser_button_class_init (GtkAppChooserButtonClass *klass)
NULL,
G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
properties[PROP_MODAL] =
g_param_spec_boolean ("modal",
P_("Modal"),
P_("Whether the dialog should be modal"),
TRUE,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
signals[SIGNAL_CHANGED] =
@ -751,20 +745,20 @@ gtk_app_chooser_button_class_init (GtkAppChooserButtonClass *klass)
static void
gtk_app_chooser_button_init (GtkAppChooserButton *self)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
self->modal = TRUE;
priv->custom_item_names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
priv->store = gtk_list_store_new (NUM_COLUMNS,
self->custom_item_names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
self->store = gtk_list_store_new (NUM_COLUMNS,
G_TYPE_APP_INFO,
G_TYPE_STRING, /* name */
G_TYPE_STRING, /* label */
G_TYPE_ICON,
G_TYPE_BOOLEAN, /* separator */
G_TYPE_BOOLEAN); /* custom */
priv->combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (priv->store));
gtk_widget_set_parent (priv->combobox, GTK_WIDGET (self));
self->combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (self->store));
gtk_widget_set_parent (self->combobox, GTK_WIDGET (self));
g_signal_connect (priv->combobox, "changed",
g_signal_connect (self->combobox, "changed",
G_CALLBACK (gtk_app_chooser_button_changed), self);
}
@ -773,15 +767,14 @@ app_chooser_button_iter_from_custom_name (GtkAppChooserButton *self,
const gchar *name,
GtkTreeIter *set_me)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GtkTreeIter iter;
gchar *custom_name = NULL;
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->store), &iter))
if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (self->store), &iter))
return FALSE;
do {
gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
gtk_tree_model_get (GTK_TREE_MODEL (self->store), &iter,
COLUMN_NAME, &custom_name,
-1);
@ -794,7 +787,7 @@ app_chooser_button_iter_from_custom_name (GtkAppChooserButton *self,
}
g_free (custom_name);
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->store), &iter));
} while (gtk_tree_model_iter_next (GTK_TREE_MODEL (self->store), &iter));
return FALSE;
}
@ -807,21 +800,20 @@ real_insert_custom_item (GtkAppChooserButton *self,
gboolean custom,
GtkTreeIter *iter)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
if (custom)
{
if (g_hash_table_lookup (priv->custom_item_names, name) != NULL)
if (g_hash_table_lookup (self->custom_item_names, name) != NULL)
{
g_warning ("Attempting to add custom item %s to GtkAppChooserButton, "
"when there's already an item with the same name", name);
return;
}
g_hash_table_insert (priv->custom_item_names,
g_hash_table_insert (self->custom_item_names,
g_strdup (name), GINT_TO_POINTER (1));
}
gtk_list_store_set (priv->store, iter,
gtk_list_store_set (self->store, iter,
COLUMN_NAME, name,
COLUMN_LABEL, label,
COLUMN_ICON, icon,
@ -835,9 +827,7 @@ real_insert_separator (GtkAppChooserButton *self,
gboolean custom,
GtkTreeIter *iter)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
gtk_list_store_set (priv->store, iter,
gtk_list_store_set (self->store, iter,
COLUMN_CUSTOM, custom,
COLUMN_SEPARATOR, TRUE,
-1);
@ -872,12 +862,11 @@ gtk_app_chooser_button_new (const gchar *content_type)
void
gtk_app_chooser_button_append_separator (GtkAppChooserButton *self)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GtkTreeIter iter;
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
gtk_list_store_append (priv->store, &iter);
gtk_list_store_append (self->store, &iter);
real_insert_separator (self, TRUE, &iter);
}
@ -901,13 +890,12 @@ gtk_app_chooser_button_append_custom_item (GtkAppChooserButton *self,
const gchar *label,
GIcon *icon)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GtkTreeIter iter;
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
g_return_if_fail (name != NULL);
gtk_list_store_append (priv->store, &iter);
gtk_list_store_append (self->store, &iter);
real_insert_custom_item (self, name, label, icon, TRUE, &iter);
}
@ -926,20 +914,19 @@ void
gtk_app_chooser_button_set_active_custom_item (GtkAppChooserButton *self,
const gchar *name)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
GtkTreeIter iter;
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
g_return_if_fail (name != NULL);
if (!g_hash_table_contains (priv->custom_item_names, name) ||
if (!g_hash_table_contains (self->custom_item_names, name) ||
!app_chooser_button_iter_from_custom_name (self, name, &iter))
{
g_warning ("Can't find the item named %s in the app chooser.", name);
return;
}
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->combobox), &iter);
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self->combobox), &iter);
}
/**
@ -954,11 +941,9 @@ gtk_app_chooser_button_set_active_custom_item (GtkAppChooserButton *self,
gboolean
gtk_app_chooser_button_get_show_dialog_item (GtkAppChooserButton *self)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
g_return_val_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self), FALSE);
return priv->show_dialog_item;
return self->show_dialog_item;
}
/**
@ -973,10 +958,9 @@ void
gtk_app_chooser_button_set_show_dialog_item (GtkAppChooserButton *self,
gboolean setting)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
if (priv->show_dialog_item != setting)
if (self->show_dialog_item != setting)
{
priv->show_dialog_item = setting;
self->show_dialog_item = setting;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_DIALOG_ITEM]);
@ -996,11 +980,9 @@ gtk_app_chooser_button_set_show_dialog_item (GtkAppChooserButton *self,
gboolean
gtk_app_chooser_button_get_show_default_item (GtkAppChooserButton *self)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
g_return_val_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self), FALSE);
return priv->show_default_item;
return self->show_default_item;
}
/**
@ -1015,13 +997,11 @@ void
gtk_app_chooser_button_set_show_default_item (GtkAppChooserButton *self,
gboolean setting)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
if (priv->show_default_item != setting)
if (self->show_default_item != setting)
{
priv->show_default_item = setting;
self->show_default_item = setting;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_DEFAULT_ITEM]);
@ -1041,12 +1021,10 @@ void
gtk_app_chooser_button_set_heading (GtkAppChooserButton *self,
const gchar *heading)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
g_free (priv->heading);
priv->heading = g_strdup (heading);
g_free (self->heading);
self->heading = g_strdup (heading);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HEADING]);
}
@ -1063,9 +1041,45 @@ gtk_app_chooser_button_set_heading (GtkAppChooserButton *self,
const gchar *
gtk_app_chooser_button_get_heading (GtkAppChooserButton *self)
{
GtkAppChooserButtonPrivate *priv = gtk_app_chooser_button_get_instance_private (self);
g_return_val_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self), NULL);
return priv->heading;
return self->heading;
}
/**
* gtk_app_chooser_button_set_modal:
* @self: a #GtkAppChooserButton
* @modal: %TRUE to make the dialog modal
*
* Sets whether the dialog should be modal.
*/
void
gtk_app_chooser_button_set_modal (GtkAppChooserButton *self,
gboolean modal)
{
g_return_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self));
if (self->modal == modal)
return;
self->modal = modal;
g_object_notify (G_OBJECT (self), "modal");
}
/**
* gtk_app_chooser_button_get_modal:
* @self: a #GtkAppChooserButton
*
* Gets whether the dialog is modal.
*
* Returns: %TRUE if the dialog is modal
*/
gboolean
gtk_app_chooser_button_get_modal (GtkAppChooserButton *self)
{
g_return_val_if_fail (GTK_IS_APP_CHOOSER_BUTTON (self), FALSE);
return self->modal;
}

View File

@ -71,6 +71,12 @@ void gtk_app_chooser_button_set_show_default_item (GtkAppChooserButton *self
GDK_AVAILABLE_IN_ALL
gboolean gtk_app_chooser_button_get_show_default_item (GtkAppChooserButton *self);
GDK_AVAILABLE_IN_ALL
gboolean gtk_app_chooser_button_get_modal (GtkAppChooserButton *self);
GDK_AVAILABLE_IN_ALL
void gtk_app_chooser_button_set_modal (GtkAppChooserButton *self,
gboolean modal);
G_END_DECLS
#endif /* __GTK_APP_CHOOSER_BUTTON_H__ */

View File

@ -66,16 +66,7 @@ typedef struct _GtkColorButtonClass GtkColorButtonClass;
struct _GtkColorButton {
GtkWidget parent_instance;
};
struct _GtkColorButtonClass {
GtkWidgetClass parent_class;
void (* color_set) (GtkColorButton *cp);
};
typedef struct
{
GtkWidget *button;
GtkWidget *swatch; /* Widget where we draw the color sample */
@ -84,9 +75,16 @@ typedef struct
gchar *title; /* Title for the color selection window */
GdkRGBA rgba;
guint use_alpha : 1; /* Use alpha or not */
guint use_alpha : 1; /* Use alpha or not */
guint show_editor : 1;
} GtkColorButtonPrivate;
guint modal : 1;
};
struct _GtkColorButtonClass {
GtkWidgetClass parent_class;
void (* color_set) (GtkColorButton *cp);
};
/* Properties */
enum
@ -95,7 +93,8 @@ enum
PROP_USE_ALPHA,
PROP_TITLE,
PROP_RGBA,
PROP_SHOW_EDITOR
PROP_SHOW_EDITOR,
PROP_MODAL
};
/* Signals */
@ -126,7 +125,6 @@ static guint color_button_signals[LAST_SIGNAL] = { 0 };
static void gtk_color_button_iface_init (GtkColorChooserInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GtkColorButton, gtk_color_button, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkColorButton)
G_IMPLEMENT_INTERFACE (GTK_TYPE_COLOR_CHOOSER,
gtk_color_button_iface_init))
@ -226,6 +224,14 @@ gtk_color_button_class_init (GtkColorButtonClass *klass)
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
g_object_class_install_property (gobject_class,
PROP_MODAL,
g_param_spec_boolean ("modal", P_("Modal"),
P_("Whether the dialog is modal"),
TRUE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_css_name (widget_class, "colorbutton");
}
@ -249,43 +255,41 @@ gtk_color_button_drag_prepare (GtkDragSource *source,
double y,
GtkColorButton *button)
{
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
return gdk_content_provider_new_typed (GDK_TYPE_RGBA, &priv->rgba);
return gdk_content_provider_new_typed (GDK_TYPE_RGBA, &button->rgba);
}
static void
gtk_color_button_init (GtkColorButton *button)
{
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
PangoLayout *layout;
PangoRectangle rect;
GtkDragSource *source;
GtkDropTarget *dest;
priv->button = gtk_button_new ();
g_signal_connect (priv->button, "clicked", G_CALLBACK (gtk_color_button_clicked), button);
gtk_widget_set_parent (priv->button, GTK_WIDGET (button));
button->button = gtk_button_new ();
g_signal_connect (button->button, "clicked", G_CALLBACK (gtk_color_button_clicked), button);
gtk_widget_set_parent (button->button, GTK_WIDGET (button));
priv->swatch = gtk_color_swatch_new ();
gtk_widget_set_can_focus (priv->swatch, FALSE);
g_object_set (priv->swatch, "has-menu", FALSE, NULL);
button->swatch = gtk_color_swatch_new ();
gtk_widget_set_can_focus (button->swatch, FALSE);
g_object_set (button->swatch, "has-menu", FALSE, NULL);
layout = gtk_widget_create_pango_layout (GTK_WIDGET (button), "Black");
pango_layout_get_pixel_extents (layout, NULL, &rect);
g_object_unref (layout);
gtk_widget_set_size_request (priv->swatch, rect.width, rect.height);
gtk_widget_set_size_request (button->swatch, rect.width, rect.height);
gtk_container_add (GTK_CONTAINER (priv->button), priv->swatch);
gtk_container_add (GTK_CONTAINER (button->button), button->swatch);
priv->title = g_strdup (_("Pick a Color")); /* default title */
button->title = g_strdup (_("Pick a Color")); /* default title */
/* Start with opaque black, alpha disabled */
priv->rgba.red = 0;
priv->rgba.green = 0;
priv->rgba.blue = 0;
priv->rgba.alpha = 1;
priv->use_alpha = FALSE;
button->rgba.red = 0;
button->rgba.green = 0;
button->rgba.blue = 0;
button->rgba.alpha = 1;
button->use_alpha = FALSE;
button->modal = TRUE;
dest = gtk_drop_target_new (GDK_TYPE_RGBA, GDK_ACTION_COPY);
g_signal_connect (dest, "drop", G_CALLBACK (gtk_color_button_drop), button);
@ -294,22 +298,21 @@ gtk_color_button_init (GtkColorButton *button)
source = gtk_drag_source_new ();
g_signal_connect (source, "prepare", G_CALLBACK (gtk_color_button_drag_prepare), button);
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (source), GTK_PHASE_CAPTURE);
gtk_widget_add_controller (priv->button, GTK_EVENT_CONTROLLER (source));
gtk_widget_add_controller (button->button, GTK_EVENT_CONTROLLER (source));
gtk_widget_add_css_class (priv->button, "color");
gtk_widget_add_css_class (button->button, "color");
}
static void
gtk_color_button_finalize (GObject *object)
{
GtkColorButton *button = GTK_COLOR_BUTTON (object);
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
if (priv->cs_dialog != NULL)
gtk_widget_destroy (priv->cs_dialog);
if (button->cs_dialog != NULL)
gtk_widget_destroy (button->cs_dialog);
g_free (priv->title);
gtk_widget_unparent (priv->button);
g_free (button->title);
gtk_widget_unparent (button->button);
G_OBJECT_CLASS (gtk_color_button_parent_class)->finalize (object);
}
@ -353,9 +356,8 @@ dialog_destroy (GtkWidget *widget,
gpointer data)
{
GtkColorButton *button = GTK_COLOR_BUTTON (data);
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
priv->cs_dialog = NULL;
button->cs_dialog = NULL;
return FALSE;
}
@ -370,10 +372,9 @@ dialog_response (GtkDialog *dialog,
else if (response == GTK_RESPONSE_OK)
{
GtkColorButton *button = GTK_COLOR_BUTTON (data);
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &priv->rgba);
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (priv->swatch), &priv->rgba);
gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (dialog), &button->rgba);
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (button->swatch), &button->rgba);
gtk_widget_hide (GTK_WIDGET (dialog));
@ -391,24 +392,24 @@ dialog_response (GtkDialog *dialog,
static void
ensure_dialog (GtkColorButton *button)
{
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
GtkWidget *parent, *dialog;
if (priv->cs_dialog != NULL)
if (button->cs_dialog != NULL)
return;
parent = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (button)));
priv->cs_dialog = dialog = gtk_color_chooser_dialog_new (priv->title, NULL);
button->cs_dialog = dialog = gtk_color_chooser_dialog_new (button->title, NULL);
gtk_window_set_hide_on_close (GTK_WINDOW (dialog), TRUE);
gtk_window_set_modal (GTK_WINDOW (dialog), button->modal);
if (GTK_IS_WINDOW (parent))
{
if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
gtk_window_set_modal (GTK_WINDOW (dialog),
gtk_window_get_modal (GTK_WINDOW (parent)));
if (gtk_window_get_modal (GTK_WINDOW (parent)))
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
}
g_signal_connect (dialog, "response",
@ -423,19 +424,18 @@ gtk_color_button_clicked (GtkButton *b,
gpointer user_data)
{
GtkColorButton *button = user_data;
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
/* if dialog already exists, make sure it's shown and raised */
ensure_dialog (button);
g_object_set (priv->cs_dialog, "show-editor", priv->show_editor, NULL);
g_object_set (button->cs_dialog, "show-editor", button->show_editor, NULL);
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (priv->cs_dialog), priv->use_alpha);
gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER (button->cs_dialog), button->use_alpha);
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (priv->cs_dialog), &priv->rgba);
gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (button->cs_dialog), &button->rgba);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_window_present (GTK_WINDOW (priv->cs_dialog));
gtk_window_present (GTK_WINDOW (button->cs_dialog));
G_GNUC_END_IGNORE_DEPRECATIONS
}
@ -443,13 +443,13 @@ static void
gtk_color_button_set_rgba (GtkColorChooser *chooser,
const GdkRGBA *rgba)
{
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (GTK_COLOR_BUTTON (chooser));
GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
g_return_if_fail (GTK_IS_COLOR_BUTTON (chooser));
g_return_if_fail (rgba != NULL);
priv->rgba = *rgba;
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (priv->swatch), &priv->rgba);
button->rgba = *rgba;
gtk_color_swatch_set_rgba (GTK_COLOR_SWATCH (button->swatch), &button->rgba);
g_object_notify (G_OBJECT (chooser), "rgba");
}
@ -458,27 +458,25 @@ static void
gtk_color_button_get_rgba (GtkColorChooser *chooser,
GdkRGBA *rgba)
{
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (GTK_COLOR_BUTTON (chooser));
GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
g_return_if_fail (GTK_IS_COLOR_BUTTON (chooser));
g_return_if_fail (rgba != NULL);
*rgba = priv->rgba;
*rgba = button->rgba;
}
static void
set_use_alpha (GtkColorButton *button,
gboolean use_alpha)
{
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
use_alpha = (use_alpha != FALSE);
if (priv->use_alpha != use_alpha)
if (button->use_alpha != use_alpha)
{
priv->use_alpha = use_alpha;
button->use_alpha = use_alpha;
gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (priv->swatch), use_alpha);
gtk_color_swatch_set_use_alpha (GTK_COLOR_SWATCH (button->swatch), use_alpha);
g_object_notify (G_OBJECT (button), "use-alpha");
}
@ -495,17 +493,16 @@ void
gtk_color_button_set_title (GtkColorButton *button,
const gchar *title)
{
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
gchar *old_title;
g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
old_title = priv->title;
priv->title = g_strdup (title);
old_title = button->title;
button->title = g_strdup (title);
g_free (old_title);
if (priv->cs_dialog)
gtk_window_set_title (GTK_WINDOW (priv->cs_dialog), priv->title);
if (button->cs_dialog)
gtk_window_set_title (GTK_WINDOW (button->cs_dialog), button->title);
g_object_notify (G_OBJECT (button), "title");
}
@ -521,11 +518,49 @@ gtk_color_button_set_title (GtkColorButton *button,
const gchar *
gtk_color_button_get_title (GtkColorButton *button)
{
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), NULL);
return priv->title;
return button->title;
}
/**
* gtk_color_button_set_modal:
* @button: a #GtkColorButton
* @modal: %TRUE to make the dialog modal
*
* Sets whether the dialog should be modal.
*/
void
gtk_color_button_set_modal (GtkColorButton *button,
gboolean modal)
{
g_return_if_fail (GTK_IS_COLOR_BUTTON (button));
if (button->modal == modal)
return;
button->modal = modal;
if (button->cs_dialog)
gtk_window_set_modal (GTK_WINDOW (button->cs_dialog), button->modal);
g_object_notify (G_OBJECT (button), "modal");
}
/**
* gtk_color_button_get_modal:
* @button: a #GtkColorButton
*
* Gets whether the dialog is modal.
*
* Returns: %TRUE if the dialog is modal
*/
gboolean
gtk_color_button_get_modal (GtkColorButton *button)
{
g_return_val_if_fail (GTK_IS_COLOR_BUTTON (button), FALSE);
return button->modal;
}
static void
@ -535,7 +570,6 @@ gtk_color_button_set_property (GObject *object,
GParamSpec *pspec)
{
GtkColorButton *button = GTK_COLOR_BUTTON (object);
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
switch (param_id)
{
@ -551,13 +585,16 @@ gtk_color_button_set_property (GObject *object,
case PROP_SHOW_EDITOR:
{
gboolean show_editor = g_value_get_boolean (value);
if (priv->show_editor != show_editor)
if (button->show_editor != show_editor)
{
priv->show_editor = show_editor;
button->show_editor = show_editor;
g_object_notify (object, "show-editor");
}
}
break;
case PROP_MODAL:
gtk_color_button_set_modal (button, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@ -571,12 +608,11 @@ gtk_color_button_get_property (GObject *object,
GParamSpec *pspec)
{
GtkColorButton *button = GTK_COLOR_BUTTON (object);
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
switch (param_id)
{
case PROP_USE_ALPHA:
g_value_set_boolean (value, priv->use_alpha);
g_value_set_boolean (value, button->use_alpha);
break;
case PROP_TITLE:
g_value_set_string (value, gtk_color_button_get_title (button));
@ -590,7 +626,10 @@ gtk_color_button_get_property (GObject *object,
}
break;
case PROP_SHOW_EDITOR:
g_value_set_boolean (value, priv->show_editor);
g_value_set_boolean (value, button->show_editor);
break;
case PROP_MODAL:
g_value_set_boolean (value, button->modal);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@ -606,11 +645,10 @@ gtk_color_button_add_palette (GtkColorChooser *chooser,
GdkRGBA *colors)
{
GtkColorButton *button = GTK_COLOR_BUTTON (chooser);
GtkColorButtonPrivate *priv = gtk_color_button_get_instance_private (button);
ensure_dialog (button);
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (priv->cs_dialog),
gtk_color_chooser_add_palette (GTK_COLOR_CHOOSER (button->cs_dialog),
orientation, colors_per_line, n_colors, colors);
}

View File

@ -58,6 +58,12 @@ void gtk_color_button_set_title (GtkColorButton *button,
GDK_AVAILABLE_IN_ALL
const gchar *gtk_color_button_get_title (GtkColorButton *button);
GDK_AVAILABLE_IN_ALL
gboolean gtk_color_button_get_modal (GtkColorButton *button);
GDK_AVAILABLE_IN_ALL
void gtk_color_button_set_modal (GtkColorButton *button,
gboolean modal);
G_END_DECLS
#endif /* __GTK_COLOR_BUTTON_H__ */

File diff suppressed because it is too large Load Diff

View File

@ -51,6 +51,11 @@ gint gtk_file_chooser_button_get_width_chars (GtkFileChooserBu
GDK_AVAILABLE_IN_ALL
void gtk_file_chooser_button_set_width_chars (GtkFileChooserButton *button,
gint n_chars);
GDK_AVAILABLE_IN_ALL
gboolean gtk_file_chooser_button_get_modal (GtkFileChooserButton *button);
GDK_AVAILABLE_IN_ALL
void gtk_file_chooser_button_set_modal (GtkFileChooserButton *button,
gboolean modal);
G_END_DECLS

View File

@ -67,24 +67,14 @@ typedef struct _GtkFontButtonClass GtkFontButtonClass;
struct _GtkFontButton
{
GtkWidget parent_instance;
};
struct _GtkFontButtonClass
{
GtkWidgetClass parent_class;
void (* font_set) (GtkFontButton *gfp);
};
typedef struct
{
gchar *title;
gchar *fontname;
guint use_font : 1;
guint use_size : 1;
guint show_preview_entry : 1;
guint modal : 1;
GtkWidget *button;
GtkWidget *font_dialog;
@ -106,7 +96,14 @@ typedef struct
GtkCssProvider *provider;
GtkFontChooserLevel level;
} GtkFontButtonPrivate;
};
struct _GtkFontButtonClass
{
GtkWidgetClass parent_class;
void (* font_set) (GtkFontButton *gfp);
};
/* Signals */
enum
@ -119,6 +116,7 @@ enum
{
PROP_0,
PROP_TITLE,
PROP_MODAL,
PROP_USE_FONT,
PROP_USE_SIZE
};
@ -182,32 +180,27 @@ gtk_font_button_font_chooser_iface_init (GtkFontChooserIface *iface)
}
G_DEFINE_TYPE_WITH_CODE (GtkFontButton, gtk_font_button, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkFontButton)
G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER,
gtk_font_button_font_chooser_iface_init))
static void
clear_font_data (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_clear_object (&priv->font_family);
g_clear_object (&priv->font_face);
g_clear_pointer (&priv->font_desc, pango_font_description_free);
g_clear_pointer (&priv->fontname, g_free);
g_clear_pointer (&priv->font_features, g_free);
g_clear_object (&font_button->font_family);
g_clear_object (&font_button->font_face);
g_clear_pointer (&font_button->font_desc, pango_font_description_free);
g_clear_pointer (&font_button->fontname, g_free);
g_clear_pointer (&font_button->font_features, g_free);
}
static void
clear_font_filter_data (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (priv->font_filter_data_destroy)
priv->font_filter_data_destroy (priv->font_filter_data);
priv->font_filter = NULL;
priv->font_filter_data = NULL;
priv->font_filter_data_destroy = NULL;
if (font_button->font_filter_data_destroy)
font_button->font_filter_data_destroy (font_button->font_filter_data);
font_button->font_filter = NULL;
font_button->font_filter_data = NULL;
font_button->font_filter_data_destroy = NULL;
}
static gboolean
@ -223,17 +216,16 @@ font_description_style_equal (const PangoFontDescription *a,
static void
gtk_font_button_update_font_data (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
PangoFontFamily **families;
PangoFontFace **faces;
gint n_families, n_faces, i;
const gchar *family;
g_assert (priv->font_desc != NULL);
g_assert (font_button->font_desc != NULL);
priv->fontname = pango_font_description_to_string (priv->font_desc);
font_button->fontname = pango_font_description_to_string (font_button->font_desc);
family = pango_font_description_get_family (priv->font_desc);
family = pango_font_description_get_family (font_button->font_desc);
if (family == NULL)
return;
@ -249,7 +241,7 @@ gtk_font_button_update_font_data (GtkFontButton *font_button)
if (!g_ascii_strcasecmp (name, family))
{
priv->font_family = g_object_ref (families[i]);
font_button->font_family = g_object_ref (families[i]);
pango_font_family_list_faces (families[i], &faces, &n_faces);
break;
@ -261,9 +253,9 @@ gtk_font_button_update_font_data (GtkFontButton *font_button)
{
PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]);
if (font_description_style_equal (tmp_desc, priv->font_desc))
if (font_description_style_equal (tmp_desc, font_button->font_desc))
{
priv->font_face = g_object_ref (faces[i]);
font_button->font_face = g_object_ref (faces[i]);
pango_font_description_free (tmp_desc);
break;
@ -278,56 +270,48 @@ gtk_font_button_update_font_data (GtkFontButton *font_button)
static gchar *
gtk_font_button_get_preview_text (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (font_button->font_dialog)
return gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (font_button->font_dialog));
if (priv->font_dialog)
return gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (priv->font_dialog));
return g_strdup (priv->preview_text);
return g_strdup (font_button->preview_text);
}
static void
gtk_font_button_set_preview_text (GtkFontButton *font_button,
const gchar *preview_text)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (priv->font_dialog)
if (font_button->font_dialog)
{
gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (priv->font_dialog),
gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (font_button->font_dialog),
preview_text);
return;
}
g_free (priv->preview_text);
priv->preview_text = g_strdup (preview_text);
g_free (font_button->preview_text);
font_button->preview_text = g_strdup (preview_text);
}
static gboolean
gtk_font_button_get_show_preview_entry (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (font_button->font_dialog)
return gtk_font_chooser_get_show_preview_entry (GTK_FONT_CHOOSER (font_button->font_dialog));
if (priv->font_dialog)
return gtk_font_chooser_get_show_preview_entry (GTK_FONT_CHOOSER (priv->font_dialog));
return priv->show_preview_entry;
return font_button->show_preview_entry;
}
static void
gtk_font_button_set_show_preview_entry (GtkFontButton *font_button,
gboolean show)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
show = show != FALSE;
if (priv->show_preview_entry != show)
if (font_button->show_preview_entry != show)
{
priv->show_preview_entry = show;
if (priv->font_dialog)
gtk_font_chooser_set_show_preview_entry (GTK_FONT_CHOOSER (priv->font_dialog), show);
font_button->show_preview_entry = show;
if (font_button->font_dialog)
gtk_font_chooser_set_show_preview_entry (GTK_FONT_CHOOSER (font_button->font_dialog), show);
g_object_notify (G_OBJECT (font_button), "show-preview-entry");
}
}
@ -336,27 +320,24 @@ static PangoFontFamily *
gtk_font_button_font_chooser_get_font_family (GtkFontChooser *chooser)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
return priv->font_family;
return font_button->font_family;
}
static PangoFontFace *
gtk_font_button_font_chooser_get_font_face (GtkFontChooser *chooser)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
return priv->font_face;
return font_button->font_face;
}
static int
gtk_font_button_font_chooser_get_font_size (GtkFontChooser *chooser)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
return priv->font_size;
return font_button->font_size;
}
static void
@ -366,11 +347,10 @@ gtk_font_button_font_chooser_set_filter_func (GtkFontChooser *chooser,
GDestroyNotify data_destroy)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (priv->font_dialog)
if (font_button->font_dialog)
{
gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (priv->font_dialog),
gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (font_button->font_dialog),
filter_func,
filter_data,
data_destroy);
@ -378,20 +358,19 @@ gtk_font_button_font_chooser_set_filter_func (GtkFontChooser *chooser,
}
clear_font_filter_data (font_button);
priv->font_filter = filter_func;
priv->font_filter_data = filter_data;
priv->font_filter_data_destroy = data_destroy;
font_button->font_filter = filter_func;
font_button->font_filter_data = filter_data;
font_button->font_filter_data_destroy = data_destroy;
}
static void
gtk_font_button_take_font_desc (GtkFontButton *font_button,
PangoFontDescription *font_desc)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
GObject *object = G_OBJECT (font_button);
if (priv->font_desc && font_desc &&
pango_font_description_equal (priv->font_desc, font_desc))
if (font_button->font_desc && font_desc &&
pango_font_description_equal (font_button->font_desc, font_desc))
{
pango_font_description_free (font_desc);
return;
@ -402,21 +381,21 @@ gtk_font_button_take_font_desc (GtkFontButton *font_button,
clear_font_data (font_button);
if (font_desc)
priv->font_desc = font_desc; /* adopted */
font_button->font_desc = font_desc; /* adopted */
else
priv->font_desc = pango_font_description_from_string (_("Sans 12"));
font_button->font_desc = pango_font_description_from_string (_("Sans 12"));
if (pango_font_description_get_size_is_absolute (priv->font_desc))
priv->font_size = pango_font_description_get_size (priv->font_desc);
if (pango_font_description_get_size_is_absolute (font_button->font_desc))
font_button->font_size = pango_font_description_get_size (font_button->font_desc);
else
priv->font_size = pango_font_description_get_size (priv->font_desc) / PANGO_SCALE;
font_button->font_size = pango_font_description_get_size (font_button->font_desc) / PANGO_SCALE;
gtk_font_button_update_font_data (font_button);
gtk_font_button_update_font_info (font_button);
if (priv->font_dialog)
gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (priv->font_dialog),
priv->font_desc);
if (font_button->font_dialog)
gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (font_button->font_dialog),
font_button->font_desc);
g_object_notify (G_OBJECT (font_button), "font");
g_object_notify (G_OBJECT (font_button), "font-desc");
@ -427,9 +406,7 @@ gtk_font_button_take_font_desc (GtkFontButton *font_button,
static const PangoFontDescription *
gtk_font_button_get_font_desc (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
return priv->font_desc;
return font_button->font_desc;
}
static void
@ -437,16 +414,15 @@ gtk_font_button_font_chooser_set_font_map (GtkFontChooser *chooser,
PangoFontMap *font_map)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (g_set_object (&priv->font_map, font_map))
if (g_set_object (&font_button->font_map, font_map))
{
PangoContext *context;
if (!font_map)
font_map = pango_cairo_font_map_get_default ();
context = gtk_widget_get_pango_context (priv->font_label);
context = gtk_widget_get_pango_context (font_button->font_label);
pango_context_set_font_map (context, font_map);
}
}
@ -455,9 +431,8 @@ static PangoFontMap *
gtk_font_button_font_chooser_get_font_map (GtkFontChooser *chooser)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
return priv->font_map;
return font_button->font_map;
}
static void
@ -532,6 +507,14 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
g_object_class_install_property (gobject_class,
PROP_MODAL,
g_param_spec_boolean ("modal",
P_("Modal"),
P_("Whether the dialog is modal"),
TRUE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
/**
* GtkFontButton::font-set:
* @widget: the object which received the signal.
@ -559,64 +542,63 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
static void
gtk_font_button_init (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
GtkWidget *box;
priv->button = gtk_button_new ();
g_signal_connect (priv->button, "clicked", G_CALLBACK (gtk_font_button_clicked), font_button);
priv->font_label = gtk_label_new (_("Font"));
gtk_widget_set_hexpand (priv->font_label, TRUE);
priv->size_label = gtk_label_new ("14");
priv->font_size_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
font_button->button = gtk_button_new ();
g_signal_connect (font_button->button, "clicked", G_CALLBACK (gtk_font_button_clicked), font_button);
font_button->font_label = gtk_label_new (_("Font"));
gtk_widget_set_hexpand (font_button->font_label, TRUE);
font_button->size_label = gtk_label_new ("14");
font_button->font_size_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (box), priv->font_label);
gtk_container_add (GTK_CONTAINER (box), font_button->font_label);
gtk_container_add (GTK_CONTAINER (priv->font_size_box), gtk_separator_new (GTK_ORIENTATION_VERTICAL));
gtk_container_add (GTK_CONTAINER (priv->font_size_box), priv->size_label);
gtk_container_add (GTK_CONTAINER (box), priv->font_size_box);
gtk_container_add (GTK_CONTAINER (font_button->font_size_box), gtk_separator_new (GTK_ORIENTATION_VERTICAL));
gtk_container_add (GTK_CONTAINER (font_button->font_size_box), font_button->size_label);
gtk_container_add (GTK_CONTAINER (box), font_button->font_size_box);
gtk_container_add (GTK_CONTAINER (priv->button), box);
gtk_widget_set_parent (priv->button, GTK_WIDGET (font_button));
gtk_container_add (GTK_CONTAINER (font_button->button), box);
gtk_widget_set_parent (font_button->button, GTK_WIDGET (font_button));
/* Initialize fields */
priv->use_font = FALSE;
priv->use_size = FALSE;
priv->show_preview_entry = TRUE;
priv->font_dialog = NULL;
priv->font_family = NULL;
priv->font_face = NULL;
priv->font_size = -1;
priv->title = g_strdup (_("Pick a Font"));
priv->level = GTK_FONT_CHOOSER_LEVEL_FAMILY |
GTK_FONT_CHOOSER_LEVEL_STYLE |
GTK_FONT_CHOOSER_LEVEL_SIZE;
priv->language = pango_language_get_default ();
font_button->modal = TRUE;
font_button->use_font = FALSE;
font_button->use_size = FALSE;
font_button->show_preview_entry = TRUE;
font_button->font_dialog = NULL;
font_button->font_family = NULL;
font_button->font_face = NULL;
font_button->font_size = -1;
font_button->title = g_strdup (_("Pick a Font"));
font_button->level = GTK_FONT_CHOOSER_LEVEL_FAMILY |
GTK_FONT_CHOOSER_LEVEL_STYLE |
GTK_FONT_CHOOSER_LEVEL_SIZE;
font_button->language = pango_language_get_default ();
gtk_font_button_take_font_desc (font_button, NULL);
gtk_widget_add_css_class (priv->button, "font");
gtk_widget_add_css_class (font_button->button, "font");
}
static void
gtk_font_button_finalize (GObject *object)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (object);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (priv->font_dialog != NULL)
gtk_widget_destroy (priv->font_dialog);
if (font_button->font_dialog != NULL)
gtk_widget_destroy (font_button->font_dialog);
g_free (priv->title);
g_free (font_button->title);
clear_font_data (font_button);
clear_font_filter_data (font_button);
g_free (priv->preview_text);
g_free (font_button->preview_text);
g_clear_object (&priv->provider);
g_clear_object (&font_button->provider);
gtk_widget_unparent (priv->button);
gtk_widget_unparent (font_button->button);
G_OBJECT_CLASS (gtk_font_button_parent_class)->finalize (object);
}
@ -640,6 +622,9 @@ gtk_font_button_set_property (GObject *object,
case PROP_TITLE:
gtk_font_button_set_title (font_button, g_value_get_string (value));
break;
case PROP_MODAL:
gtk_font_button_set_modal (font_button, g_value_get_boolean (value));
break;
case GTK_FONT_CHOOSER_PROP_FONT_DESC:
gtk_font_button_take_font_desc (font_button, g_value_dup_boxed (value));
break;
@ -671,7 +656,6 @@ gtk_font_button_get_property (GObject *object,
GParamSpec *pspec)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (object);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
switch (param_id)
{
@ -684,17 +668,20 @@ gtk_font_button_get_property (GObject *object,
case PROP_TITLE:
g_value_set_string (value, gtk_font_button_get_title (font_button));
break;
case PROP_MODAL:
g_value_set_boolean (value, gtk_font_button_get_modal (font_button));
break;
case GTK_FONT_CHOOSER_PROP_FONT_DESC:
g_value_set_boxed (value, gtk_font_button_get_font_desc (font_button));
break;
case GTK_FONT_CHOOSER_PROP_FONT_FEATURES:
g_value_set_string (value, priv->font_features);
g_value_set_string (value, font_button->font_features);
break;
case GTK_FONT_CHOOSER_PROP_LANGUAGE:
g_value_set_string (value, pango_language_to_string (priv->language));
g_value_set_string (value, pango_language_to_string (font_button->language));
break;
case GTK_FONT_CHOOSER_PROP_LEVEL:
g_value_set_flags (value, priv->level);
g_value_set_flags (value, font_button->level);
break;
case GTK_FONT_CHOOSER_PROP_FONT:
g_value_set_string (value, gtk_font_button_get_font_name (font_button));
@ -750,16 +737,15 @@ void
gtk_font_button_set_title (GtkFontButton *font_button,
const gchar *title)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
gchar *old_title;
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
old_title = priv->title;
priv->title = g_strdup (title);
old_title = font_button->title;
font_button->title = g_strdup (title);
g_free (old_title);
if (priv->font_dialog)
gtk_window_set_title (GTK_WINDOW (priv->font_dialog), priv->title);
if (font_button->font_dialog)
gtk_window_set_title (GTK_WINDOW (font_button->font_dialog), font_button->title);
g_object_notify (G_OBJECT (font_button), "title");
}
@ -775,13 +761,51 @@ gtk_font_button_set_title (GtkFontButton *font_button,
const gchar*
gtk_font_button_get_title (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), NULL);
return priv->title;
return font_button->title;
}
/**
* gtk_font_button_set_modal:
* @font_button: a #GtkFontButton
* @modal: %TRUE to make the dialog modal
*
* Sets whether the dialog should be modal.
*/
void
gtk_font_button_set_modal (GtkFontButton *font_button,
gboolean modal)
{
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
if (font_button->modal == modal)
return;
font_button->modal = modal;
if (font_button->font_dialog)
gtk_window_set_modal (GTK_WINDOW (font_button->font_dialog), font_button->modal);
g_object_notify (G_OBJECT (font_button), "modal");
}
/**
* gtk_font_button_get_modal:
* @font_button: a #GtkFontButton
*
* Gets whether the dialog is modal.
*
* Returns: %TRUE if the dialog is modal
*/
gboolean
gtk_font_button_get_modal (GtkFontButton *font_button)
{
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
return font_button->modal;
}
/**
* gtk_font_button_get_use_font:
* @font_button: a #GtkFontButton
@ -793,11 +817,9 @@ gtk_font_button_get_title (GtkFontButton *font_button)
gboolean
gtk_font_button_get_use_font (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
return priv->use_font;
return font_button->use_font;
}
/**
@ -811,14 +833,13 @@ void
gtk_font_button_set_use_font (GtkFontButton *font_button,
gboolean use_font)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
use_font = (use_font != FALSE);
if (priv->use_font != use_font)
if (font_button->use_font != use_font)
{
priv->use_font = use_font;
font_button->use_font = use_font;
gtk_font_button_label_use_font (font_button);
@ -838,11 +859,9 @@ gtk_font_button_set_use_font (GtkFontButton *font_button,
gboolean
gtk_font_button_get_use_size (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
return priv->use_size;
return font_button->use_size;
}
/**
@ -856,14 +875,12 @@ void
gtk_font_button_set_use_size (GtkFontButton *font_button,
gboolean use_size)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
use_size = (use_size != FALSE);
if (priv->use_size != use_size)
if (font_button->use_size != use_size)
{
priv->use_size = use_size;
font_button->use_size = use_size;
gtk_font_button_label_use_font (font_button);
@ -874,11 +891,9 @@ gtk_font_button_set_use_size (GtkFontButton *font_button,
static const gchar *
gtk_font_button_get_font_name (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), NULL);
return priv->fontname;
return font_button->fontname;
}
static void
@ -897,42 +912,42 @@ gtk_font_button_clicked (GtkButton *button,
{
GtkFontChooser *font_dialog;
GtkFontButton *font_button = user_data;
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (!priv->font_dialog)
if (!font_button->font_dialog)
{
GtkWidget *parent;
parent = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (font_button)));
priv->font_dialog = gtk_font_chooser_dialog_new (priv->title, NULL);
gtk_window_set_hide_on_close (GTK_WINDOW (priv->font_dialog), TRUE);
font_button->font_dialog = gtk_font_chooser_dialog_new (font_button->title, NULL);
gtk_window_set_hide_on_close (GTK_WINDOW (font_button->font_dialog), TRUE);
gtk_window_set_modal (GTK_WINDOW (font_button->font_dialog), font_button->modal);
font_dialog = GTK_FONT_CHOOSER (priv->font_dialog);
font_dialog = GTK_FONT_CHOOSER (font_button->font_dialog);
if (priv->font_map)
gtk_font_chooser_set_font_map (font_dialog, priv->font_map);
if (font_button->font_map)
gtk_font_chooser_set_font_map (font_dialog, font_button->font_map);
gtk_font_chooser_set_show_preview_entry (font_dialog, priv->show_preview_entry);
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_dialog), priv->level);
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_dialog), pango_language_to_string (priv->language));
gtk_font_chooser_set_show_preview_entry (font_dialog, font_button->show_preview_entry);
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_dialog), font_button->level);
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_dialog), pango_language_to_string (font_button->language));
if (priv->preview_text)
if (font_button->preview_text)
{
gtk_font_chooser_set_preview_text (font_dialog, priv->preview_text);
g_free (priv->preview_text);
priv->preview_text = NULL;
gtk_font_chooser_set_preview_text (font_dialog, font_button->preview_text);
g_free (font_button->preview_text);
font_button->preview_text = NULL;
}
if (priv->font_filter)
if (font_button->font_filter)
{
gtk_font_chooser_set_filter_func (font_dialog,
priv->font_filter,
priv->font_filter_data,
priv->font_filter_data_destroy);
priv->font_filter = NULL;
priv->font_filter_data = NULL;
priv->font_filter_data_destroy = NULL;
font_button->font_filter,
font_button->font_filter_data,
font_button->font_filter_data_destroy);
font_button->font_filter = NULL;
font_button->font_filter_data = NULL;
font_button->font_filter_data_destroy = NULL;
}
if (GTK_IS_WINDOW (parent))
@ -940,8 +955,8 @@ gtk_font_button_clicked (GtkButton *button,
if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (font_dialog)))
gtk_window_set_transient_for (GTK_WINDOW (font_dialog), GTK_WINDOW (parent));
gtk_window_set_modal (GTK_WINDOW (font_dialog),
gtk_window_get_modal (GTK_WINDOW (parent)));
if (gtk_window_get_modal (GTK_WINDOW (parent)))
gtk_window_set_modal (GTK_WINDOW (font_dialog), TRUE);
}
g_signal_connect (font_dialog, "notify",
@ -954,14 +969,14 @@ gtk_font_button_clicked (GtkButton *button,
G_CALLBACK (dialog_destroy), font_button);
}
if (!gtk_widget_get_visible (priv->font_dialog))
if (!gtk_widget_get_visible (font_button->font_dialog))
{
font_dialog = GTK_FONT_CHOOSER (priv->font_dialog);
gtk_font_chooser_set_font_desc (font_dialog, priv->font_desc);
font_dialog = GTK_FONT_CHOOSER (font_button->font_dialog);
gtk_font_chooser_set_font_desc (font_dialog, font_button->font_desc);
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_window_present (GTK_WINDOW (priv->font_dialog));
gtk_window_present (GTK_WINDOW (font_button->font_dialog));
G_GNUC_END_IGNORE_DEPRECATIONS
}
@ -972,35 +987,34 @@ response_cb (GtkDialog *dialog,
gpointer data)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (data);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
GtkFontChooser *font_chooser;
GObject *object;
gtk_widget_hide (priv->font_dialog);
gtk_widget_hide (font_button->font_dialog);
if (response_id != GTK_RESPONSE_OK)
return;
font_chooser = GTK_FONT_CHOOSER (priv->font_dialog);
font_chooser = GTK_FONT_CHOOSER (font_button->font_dialog);
object = G_OBJECT (font_chooser);
g_object_freeze_notify (object);
clear_font_data (font_button);
priv->font_desc = gtk_font_chooser_get_font_desc (font_chooser);
if (priv->font_desc)
priv->fontname = pango_font_description_to_string (priv->font_desc);
priv->font_family = gtk_font_chooser_get_font_family (font_chooser);
if (priv->font_family)
g_object_ref (priv->font_family);
priv->font_face = gtk_font_chooser_get_font_face (font_chooser);
if (priv->font_face)
g_object_ref (priv->font_face);
priv->font_size = gtk_font_chooser_get_font_size (font_chooser);
g_free (priv->font_features);
priv->font_features = gtk_font_chooser_get_font_features (font_chooser);
priv->language = pango_language_from_string (gtk_font_chooser_get_language (font_chooser));
font_button->font_desc = gtk_font_chooser_get_font_desc (font_chooser);
if (font_button->font_desc)
font_button->fontname = pango_font_description_to_string (font_button->font_desc);
font_button->font_family = gtk_font_chooser_get_font_family (font_chooser);
if (font_button->font_family)
g_object_ref (font_button->font_family);
font_button->font_face = gtk_font_chooser_get_font_face (font_chooser);
if (font_button->font_face)
g_object_ref (font_button->font_face);
font_button->font_size = gtk_font_chooser_get_font_size (font_chooser);
g_free (font_button->font_features);
font_button->font_features = gtk_font_chooser_get_font_features (font_chooser);
font_button->language = pango_language_from_string (gtk_font_chooser_get_language (font_chooser));
/* Set label font */
gtk_font_button_update_font_info (font_button);
@ -1020,10 +1034,9 @@ dialog_destroy (GtkWidget *widget,
gpointer data)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (data);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
/* Dialog will get destroyed so reference is not valid now */
priv->font_dialog = NULL;
font_button->font_dialog = NULL;
}
static void
@ -1229,17 +1242,16 @@ pango_font_description_to_css (PangoFontDescription *desc,
static void
gtk_font_button_label_use_font (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
GtkStyleContext *context;
context = gtk_widget_get_style_context (priv->font_label);
context = gtk_widget_get_style_context (font_button->font_label);
if (!priv->use_font)
if (!font_button->use_font)
{
if (priv->provider)
if (font_button->provider)
{
gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (priv->provider));
g_clear_object (&priv->provider);
gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (font_button->provider));
g_clear_object (&font_button->provider);
}
}
else
@ -1247,23 +1259,23 @@ gtk_font_button_label_use_font (GtkFontButton *font_button)
PangoFontDescription *desc;
gchar *data;
if (!priv->provider)
if (!font_button->provider)
{
priv->provider = gtk_css_provider_new ();
font_button->provider = gtk_css_provider_new ();
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (priv->provider),
GTK_STYLE_PROVIDER (font_button->provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
desc = pango_font_description_copy (priv->font_desc);
desc = pango_font_description_copy (font_button->font_desc);
if (!priv->use_size)
if (!font_button->use_size)
pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE);
data = pango_font_description_to_css (desc,
priv->font_features,
pango_language_to_string (priv->language));
gtk_css_provider_load_from_data (priv->provider, data, -1);
font_button->font_features,
pango_language_to_string (font_button->language));
gtk_css_provider_load_from_data (font_button->provider, data, -1);
g_free (data);
pango_font_description_free (desc);
@ -1273,43 +1285,42 @@ gtk_font_button_label_use_font (GtkFontButton *font_button)
static void
gtk_font_button_update_font_info (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
const gchar *fam_name;
const gchar *face_name;
gchar *family_style;
if (priv->font_family)
fam_name = pango_font_family_get_name (priv->font_family);
if (font_button->font_family)
fam_name = pango_font_family_get_name (font_button->font_family);
else
fam_name = C_("font", "None");
if (priv->font_face)
face_name = pango_font_face_get_face_name (priv->font_face);
if (font_button->font_face)
face_name = pango_font_face_get_face_name (font_button->font_face);
else
face_name = "";
if ((priv->level & GTK_FONT_CHOOSER_LEVEL_STYLE) != 0)
if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_STYLE) != 0)
family_style = g_strconcat (fam_name, " ", face_name, NULL);
else
family_style = g_strdup (fam_name);
gtk_label_set_text (GTK_LABEL (priv->font_label), family_style);
gtk_label_set_text (GTK_LABEL (font_button->font_label), family_style);
g_free (family_style);
if ((priv->level & GTK_FONT_CHOOSER_LEVEL_SIZE) != 0)
if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_SIZE) != 0)
{
/* mirror Pango, which doesn't translate this either */
gchar *size = g_strdup_printf ("%2.4g%s",
pango_font_description_get_size (priv->font_desc) / (double)PANGO_SCALE,
pango_font_description_get_size_is_absolute (priv->font_desc) ? "px" : "");
pango_font_description_get_size (font_button->font_desc) / (double)PANGO_SCALE,
pango_font_description_get_size_is_absolute (font_button->font_desc) ? "px" : "");
gtk_label_set_text (GTK_LABEL (priv->size_label), size);
gtk_label_set_text (GTK_LABEL (font_button->size_label), size);
g_free (size);
gtk_widget_show (priv->font_size_box);
gtk_widget_show (font_button->font_size_box);
}
else
gtk_widget_hide (priv->font_size_box);
gtk_widget_hide (font_button->font_size_box);
gtk_font_button_label_use_font (font_button);
@ -1319,15 +1330,13 @@ static void
gtk_font_button_set_level (GtkFontButton *font_button,
GtkFontChooserLevel level)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (priv->level == level)
if (font_button->level == level)
return;
priv->level = level;
font_button->level = level;
if (priv->font_dialog)
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (priv->font_dialog), level);
if (font_button->font_dialog)
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_button->font_dialog), level);
gtk_font_button_update_font_info (font_button);
@ -1338,12 +1347,10 @@ static void
gtk_font_button_set_language (GtkFontButton *font_button,
const char *language)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
font_button->language = pango_language_from_string (language);
priv->language = pango_language_from_string (language);
if (priv->font_dialog)
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (priv->font_dialog), language);
if (font_button->font_dialog)
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_button->font_dialog), language);
g_object_notify (G_OBJECT (font_button), "language");
}

View File

@ -54,6 +54,11 @@ GDK_AVAILABLE_IN_ALL
void gtk_font_button_set_title (GtkFontButton *font_button,
const gchar *title);
GDK_AVAILABLE_IN_ALL
gboolean gtk_font_button_get_modal (GtkFontButton *font_button);
GDK_AVAILABLE_IN_ALL
void gtk_font_button_set_modal (GtkFontButton *font_button,
gboolean modal);
GDK_AVAILABLE_IN_ALL
gboolean gtk_font_button_get_use_font (GtkFontButton *font_button);
GDK_AVAILABLE_IN_ALL
void gtk_font_button_set_use_font (GtkFontButton *font_button,