gtkdialog: Move public members to private structure

This commit is contained in:
Javier Jardón 2010-06-03 07:31:06 +02:00
parent 7f2cc85db9
commit a8014e6fec
2 changed files with 90 additions and 67 deletions

View File

@ -41,11 +41,16 @@
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtkbuildable.h" #include "gtkbuildable.h"
#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_DIALOG, GtkDialogPrivate))
typedef struct { struct _GtkDialogPriv
{
GtkWidget *vbox;
GtkWidget *action_area;
GtkWidget *separator;
guint ignore_separator : 1; guint ignore_separator : 1;
} GtkDialogPrivate; };
typedef struct _ResponseData ResponseData; typedef struct _ResponseData ResponseData;
@ -131,7 +136,7 @@ gtk_dialog_class_init (GtkDialogClass *class)
class->close = gtk_dialog_close; class->close = gtk_dialog_close;
g_type_class_add_private (gobject_class, sizeof (GtkDialogPrivate)); g_type_class_add_private (gobject_class, sizeof (GtkDialogPriv));
/** /**
* GtkDialog:has-separator: * GtkDialog:has-separator:
@ -237,6 +242,7 @@ gtk_dialog_class_init (GtkDialogClass *class)
static void static void
update_spacings (GtkDialog *dialog) update_spacings (GtkDialog *dialog)
{ {
GtkDialogPriv *priv = dialog->priv;
gint content_area_border; gint content_area_border;
gint content_area_spacing; gint content_area_spacing;
gint button_spacing; gint button_spacing;
@ -249,25 +255,29 @@ update_spacings (GtkDialog *dialog)
"action-area-border", &action_area_border, "action-area-border", &action_area_border,
NULL); NULL);
gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), gtk_container_set_border_width (GTK_CONTAINER (priv->vbox),
content_area_border); content_area_border);
if (!_gtk_box_get_spacing_set (GTK_BOX (dialog->vbox))) if (!_gtk_box_get_spacing_set (GTK_BOX (priv->vbox)))
{ {
gtk_box_set_spacing (GTK_BOX (dialog->vbox), content_area_spacing); gtk_box_set_spacing (GTK_BOX (priv->vbox), content_area_spacing);
_gtk_box_set_spacing_set (GTK_BOX (dialog->vbox), FALSE); _gtk_box_set_spacing_set (GTK_BOX (priv->vbox), FALSE);
} }
gtk_box_set_spacing (GTK_BOX (dialog->action_area), gtk_box_set_spacing (GTK_BOX (priv->action_area),
button_spacing); button_spacing);
gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), gtk_container_set_border_width (GTK_CONTAINER (priv->action_area),
action_area_border); action_area_border);
} }
static void static void
gtk_dialog_init (GtkDialog *dialog) gtk_dialog_init (GtkDialog *dialog)
{ {
GtkDialogPrivate *priv; GtkDialogPriv *priv;
dialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (dialog,
GTK_TYPE_DIALOG,
GtkDialogPriv);
priv = dialog->priv;
priv = GET_PRIVATE (dialog);
priv->ignore_separator = FALSE; priv->ignore_separator = FALSE;
/* To avoid breaking old code that prevents destroy on delete event /* To avoid breaking old code that prevents destroy on delete event
@ -279,23 +289,23 @@ gtk_dialog_init (GtkDialog *dialog)
G_CALLBACK (gtk_dialog_delete_event_handler), G_CALLBACK (gtk_dialog_delete_event_handler),
NULL); NULL);
dialog->vbox = gtk_vbox_new (FALSE, 0); priv->vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (dialog), dialog->vbox); gtk_container_add (GTK_CONTAINER (dialog), priv->vbox);
gtk_widget_show (dialog->vbox); gtk_widget_show (priv->vbox);
dialog->action_area = gtk_hbutton_box_new (); priv->action_area = gtk_hbutton_box_new ();
gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog->action_area), gtk_button_box_set_layout (GTK_BUTTON_BOX (priv->action_area),
GTK_BUTTONBOX_END); GTK_BUTTONBOX_END);
gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->action_area, gtk_box_pack_end (GTK_BOX (priv->vbox), priv->action_area,
FALSE, TRUE, 0); FALSE, TRUE, 0);
gtk_widget_show (dialog->action_area); gtk_widget_show (priv->action_area);
dialog->separator = gtk_hseparator_new (); priv->separator = gtk_hseparator_new ();
gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->separator, FALSE, TRUE, 0); gtk_box_pack_end (GTK_BOX (priv->vbox), priv->separator, FALSE, TRUE, 0);
gtk_widget_show (dialog->separator); gtk_widget_show (priv->separator);
gtk_window_set_type_hint (GTK_WINDOW (dialog), gtk_window_set_type_hint (GTK_WINDOW (dialog),
GDK_WINDOW_TYPE_HINT_DIALOG); GDK_WINDOW_TYPE_HINT_DIALOG);
@ -318,14 +328,16 @@ gtk_dialog_buildable_get_internal_child (GtkBuildable *buildable,
GtkBuilder *builder, GtkBuilder *builder,
const gchar *childname) const gchar *childname)
{ {
if (strcmp (childname, "vbox") == 0) GtkDialogPriv *priv = GTK_DIALOG (buildable)->priv;
return G_OBJECT (GTK_DIALOG (buildable)->vbox);
else if (strcmp (childname, "action_area") == 0)
return G_OBJECT (GTK_DIALOG (buildable)->action_area);
return parent_buildable_iface->get_internal_child (buildable, if (strcmp (childname, "vbox") == 0)
builder, return G_OBJECT (priv->vbox);
childname); else if (strcmp (childname, "action_area") == 0)
return G_OBJECT (priv->action_area);
return parent_buildable_iface->get_internal_child (buildable,
builder,
childname);
} }
static void static void
@ -356,14 +368,13 @@ gtk_dialog_get_property (GObject *object,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GtkDialog *dialog; GtkDialog *dialog = GTK_DIALOG (object);
GtkDialogPriv *priv = dialog->priv;
dialog = GTK_DIALOG (object);
switch (prop_id) switch (prop_id)
{ {
case PROP_HAS_SEPARATOR: case PROP_HAS_SEPARATOR:
g_value_set_boolean (value, dialog->separator != NULL); g_value_set_boolean (value, priv->separator != NULL);
break; break;
default: default:
@ -398,6 +409,7 @@ gtk_dialog_map (GtkWidget *widget)
{ {
GtkWindow *window = GTK_WINDOW (widget); GtkWindow *window = GTK_WINDOW (widget);
GtkDialog *dialog = GTK_DIALOG (widget); GtkDialog *dialog = GTK_DIALOG (widget);
GtkDialogPriv *priv = dialog->priv;
GTK_WIDGET_CLASS (gtk_dialog_parent_class)->map (widget); GTK_WIDGET_CLASS (gtk_dialog_parent_class)->map (widget);
@ -421,7 +433,7 @@ gtk_dialog_map (GtkWidget *widget)
} }
while (TRUE); while (TRUE);
tmp_list = children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area)); tmp_list = children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
while (tmp_list) while (tmp_list)
{ {
@ -454,10 +466,11 @@ static GtkWidget *
dialog_find_button (GtkDialog *dialog, dialog_find_button (GtkDialog *dialog,
gint response_id) gint response_id)
{ {
GList *children, *tmp_list; GtkDialogPriv *priv = dialog->priv;
GtkWidget *child = NULL; GtkWidget *child = NULL;
GList *children, *tmp_list;
children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area)); children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
for (tmp_list = children; tmp_list; tmp_list = tmp_list->next) for (tmp_list = children; tmp_list; tmp_list = tmp_list->next)
{ {
@ -643,12 +656,15 @@ gtk_dialog_add_action_widget (GtkDialog *dialog,
GtkWidget *child, GtkWidget *child,
gint response_id) gint response_id)
{ {
GtkDialogPriv *priv;
ResponseData *ad; ResponseData *ad;
guint signal_id; guint signal_id;
g_return_if_fail (GTK_IS_DIALOG (dialog)); g_return_if_fail (GTK_IS_DIALOG (dialog));
g_return_if_fail (GTK_IS_WIDGET (child)); g_return_if_fail (GTK_IS_WIDGET (child));
priv = dialog->priv;
ad = get_response_data (child, TRUE); ad = get_response_data (child, TRUE);
ad->response_id = response_id; ad->response_id = response_id;
@ -673,12 +689,12 @@ gtk_dialog_add_action_widget (GtkDialog *dialog,
else else
g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkDialog"); g_warning ("Only 'activatable' widgets can be packed into the action area of a GtkDialog");
gtk_box_pack_end (GTK_BOX (dialog->action_area), gtk_box_pack_end (GTK_BOX (priv->action_area),
child, child,
FALSE, TRUE, 0); FALSE, TRUE, 0);
if (response_id == GTK_RESPONSE_HELP) if (response_id == GTK_RESPONSE_HELP)
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (dialog->action_area), child, TRUE); gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (priv->action_area), child, TRUE);
} }
/** /**
@ -787,12 +803,15 @@ gtk_dialog_set_response_sensitive (GtkDialog *dialog,
gint response_id, gint response_id,
gboolean setting) gboolean setting)
{ {
GtkDialogPriv *priv;
GList *children; GList *children;
GList *tmp_list; GList *tmp_list;
g_return_if_fail (GTK_IS_DIALOG (dialog)); g_return_if_fail (GTK_IS_DIALOG (dialog));
children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area)); priv = dialog->priv;
children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
tmp_list = children; tmp_list = children;
while (tmp_list != NULL) while (tmp_list != NULL)
@ -822,12 +841,15 @@ void
gtk_dialog_set_default_response (GtkDialog *dialog, gtk_dialog_set_default_response (GtkDialog *dialog,
gint response_id) gint response_id)
{ {
GtkDialogPriv *priv;
GList *children; GList *children;
GList *tmp_list; GList *tmp_list;
g_return_if_fail (GTK_IS_DIALOG (dialog)); g_return_if_fail (GTK_IS_DIALOG (dialog));
children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area)); priv = dialog->priv;
children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
tmp_list = children; tmp_list = children;
while (tmp_list != NULL) while (tmp_list != NULL)
@ -856,14 +878,14 @@ void
gtk_dialog_set_has_separator (GtkDialog *dialog, gtk_dialog_set_has_separator (GtkDialog *dialog,
gboolean setting) gboolean setting)
{ {
GtkDialogPrivate *priv; GtkDialogPriv *priv;
g_return_if_fail (GTK_IS_DIALOG (dialog)); g_return_if_fail (GTK_IS_DIALOG (dialog));
priv = GET_PRIVATE (dialog); priv = dialog->priv;
/* this might fail if we get called before _init() somehow */ /* this might fail if we get called before _init() somehow */
g_assert (dialog->vbox != NULL); g_assert (priv->vbox != NULL);
if (priv->ignore_separator) if (priv->ignore_separator)
{ {
@ -871,21 +893,21 @@ gtk_dialog_set_has_separator (GtkDialog *dialog,
return; return;
} }
if (setting && dialog->separator == NULL) if (setting && priv->separator == NULL)
{ {
dialog->separator = gtk_hseparator_new (); priv->separator = gtk_hseparator_new ();
gtk_box_pack_end (GTK_BOX (dialog->vbox), dialog->separator, FALSE, TRUE, 0); gtk_box_pack_end (GTK_BOX (priv->vbox), priv->separator, FALSE, TRUE, 0);
/* The app programmer could screw this up, but, their own fault. /* The app programmer could screw this up, but, their own fault.
* Moves the separator just above the action area. * Moves the separator just above the action area.
*/ */
gtk_box_reorder_child (GTK_BOX (dialog->vbox), dialog->separator, 1); gtk_box_reorder_child (GTK_BOX (priv->vbox), priv->separator, 1);
gtk_widget_show (dialog->separator); gtk_widget_show (priv->separator);
} }
else if (!setting && dialog->separator != NULL) else if (!setting && priv->separator != NULL)
{ {
gtk_widget_destroy (dialog->separator); gtk_widget_destroy (priv->separator);
dialog->separator = NULL; priv->separator = NULL;
} }
g_object_notify (G_OBJECT (dialog), "has-separator"); g_object_notify (G_OBJECT (dialog), "has-separator");
@ -904,7 +926,7 @@ gtk_dialog_get_has_separator (GtkDialog *dialog)
{ {
g_return_val_if_fail (GTK_IS_DIALOG (dialog), FALSE); g_return_val_if_fail (GTK_IS_DIALOG (dialog), FALSE);
return dialog->separator != NULL; return dialog->priv->separator != NULL;
} }
/** /**
@ -1112,9 +1134,8 @@ void
_gtk_dialog_set_ignore_separator (GtkDialog *dialog, _gtk_dialog_set_ignore_separator (GtkDialog *dialog,
gboolean ignore_separator) gboolean ignore_separator)
{ {
GtkDialogPrivate *priv; GtkDialogPriv *priv = dialog->priv;
priv = GET_PRIVATE (dialog);
priv->ignore_separator = ignore_separator; priv->ignore_separator = ignore_separator;
} }
@ -1134,12 +1155,15 @@ GtkWidget*
gtk_dialog_get_widget_for_response (GtkDialog *dialog, gtk_dialog_get_widget_for_response (GtkDialog *dialog,
gint response_id) gint response_id)
{ {
GtkDialogPriv *priv;
GList *children; GList *children;
GList *tmp_list; GList *tmp_list;
g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
children = gtk_container_get_children (GTK_CONTAINER (dialog->action_area)); priv = dialog->priv;
children = gtk_container_get_children (GTK_CONTAINER (priv->action_area));
tmp_list = children; tmp_list = children;
while (tmp_list != NULL) while (tmp_list != NULL)
@ -1227,6 +1251,7 @@ gtk_dialog_set_alternative_button_order_valist (GtkDialog *dialog,
gint first_response_id, gint first_response_id,
va_list args) va_list args)
{ {
GtkDialogPriv *priv = dialog->priv;
GtkWidget *child; GtkWidget *child;
gint response_id; gint response_id;
gint position; gint position;
@ -1237,7 +1262,7 @@ gtk_dialog_set_alternative_button_order_valist (GtkDialog *dialog,
{ {
/* reorder child with response_id to position */ /* reorder child with response_id to position */
child = dialog_find_button (dialog, response_id); child = dialog_find_button (dialog, response_id);
gtk_box_reorder_child (GTK_BOX (dialog->action_area), child, position); gtk_box_reorder_child (GTK_BOX (priv->action_area), child, position);
response_id = va_arg (args, gint); response_id = va_arg (args, gint);
position++; position++;
@ -1331,6 +1356,7 @@ gtk_dialog_set_alternative_button_order_from_array (GtkDialog *dialog,
gint n_params, gint n_params,
gint *new_order) gint *new_order)
{ {
GtkDialogPriv *priv = dialog->priv;
GdkScreen *screen; GdkScreen *screen;
GtkWidget *child; GtkWidget *child;
gint position; gint position;
@ -1346,7 +1372,7 @@ gtk_dialog_set_alternative_button_order_from_array (GtkDialog *dialog,
{ {
/* reorder child with response_id to position */ /* reorder child with response_id to position */
child = dialog_find_button (dialog, new_order[position]); child = dialog_find_button (dialog, new_order[position]);
gtk_box_reorder_child (GTK_BOX (dialog->action_area), child, position); gtk_box_reorder_child (GTK_BOX (priv->action_area), child, position);
} }
} }
@ -1447,10 +1473,11 @@ gtk_dialog_buildable_custom_finished (GtkBuildable *buildable,
const gchar *tagname, const gchar *tagname,
gpointer user_data) gpointer user_data)
{ {
GtkDialog *dialog = GTK_DIALOG (buildable);
GtkDialogPriv *priv = dialog->priv;
GSList *l; GSList *l;
ActionWidgetsSubParserData *parser_data; ActionWidgetsSubParserData *parser_data;
GObject *object; GObject *object;
GtkDialog *dialog;
ResponseData *ad; ResponseData *ad;
guint signal_id; guint signal_id;
@ -1461,7 +1488,6 @@ gtk_dialog_buildable_custom_finished (GtkBuildable *buildable,
return; return;
} }
dialog = GTK_DIALOG (buildable);
parser_data = (ActionWidgetsSubParserData*)user_data; parser_data = (ActionWidgetsSubParserData*)user_data;
parser_data->items = g_slist_reverse (parser_data->items); parser_data->items = g_slist_reverse (parser_data->items);
@ -1500,7 +1526,7 @@ gtk_dialog_buildable_custom_finished (GtkBuildable *buildable,
} }
if (ad->response_id == GTK_RESPONSE_HELP) if (ad->response_id == GTK_RESPONSE_HELP)
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (dialog->action_area), gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (priv->action_area),
GTK_WIDGET (object), TRUE); GTK_WIDGET (object), TRUE);
g_free (item->widget_name); g_free (item->widget_name);
@ -1526,7 +1552,7 @@ gtk_dialog_get_action_area (GtkDialog *dialog)
{ {
g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
return dialog->action_area; return dialog->priv->action_area;
} }
/** /**
@ -1544,5 +1570,5 @@ gtk_dialog_get_content_area (GtkDialog *dialog)
{ {
g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL); g_return_val_if_fail (GTK_IS_DIALOG (dialog), NULL);
return dialog->vbox; return dialog->priv->vbox;
} }

View File

@ -92,18 +92,15 @@ typedef enum
typedef struct _GtkDialog GtkDialog; typedef struct _GtkDialog GtkDialog;
typedef struct _GtkDialogPriv GtkDialogPriv;
typedef struct _GtkDialogClass GtkDialogClass; typedef struct _GtkDialogClass GtkDialogClass;
struct _GtkDialog struct _GtkDialog
{ {
GtkWindow window; GtkWindow window;
/*< public >*/
GtkWidget *GSEAL (vbox);
GtkWidget *GSEAL (action_area);
/*< private >*/ /*< private >*/
GtkWidget *GSEAL (separator); GtkDialogPriv *priv;
}; };
struct _GtkDialogClass struct _GtkDialogClass