Commit 56d5652f authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Move away from the "destroy" handlers and use g_object_set_data_full

2006-12-02  Jody Goldberg <jody@gnome.org>

	* *.c : Move away from the "destroy" handlers and use
	  g_object_set_data_full instead.  That guarantees being called only
	  once and does not need to return a flag.
parent 0fb55e5d
2006-12-02 Jody Goldberg <jody@gnome.org>
* *.c : Move away from the "destroy" handlers and use
g_object_set_data_full instead. That guarantees being called only
once and does not need to return a flag.
2006-12-02 Jody Goldberg <jody@gnome.org>
* dialog-sheet-order.c (cb_sheet_order_destroy) : we need to manually
unref the model.
* dialog-plugin-manager.c (pm_dialog_cleanup) : ditto.
* dialog-goto-cell.c (dialog_goto_close_destroy) : ditto.
* dialog-function-select.c (dialog_function_select_destroy) : ditto.
* dialog-cell-sort.c (dialog_destroy) : ditto.
* dialog-formula-guru.c (dialog_formula_guru_destroy) : ditto.
2006-11-28 Morten Welinder <terra@gnome.org>
* dialog-goal-seek.c (dialog_goal_seek): Call
......
......@@ -204,39 +204,17 @@ error_in_entry (GenericToolState *state, GtkWidget *entry, char const *err_str)
focus_on_entry (GTK_ENTRY (entry));
}
/**
* tool_destroy:
* @window:
* @state:
*
* Destroy the dialog and associated data structures.
*
**/
static gboolean
tool_destroy (GtkObject *w, GenericToolState *state)
static void
cb_tool_destroy (GenericToolState *state)
{
gboolean res = FALSE;
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
wbcg_edit_detach_guru (state->wbcg);
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
wbcg_edit_finish (state->wbcg, WBC_EDIT_REJECT, NULL);
state->dialog = NULL;
if (state->state_destroy)
res = state->state_destroy (w, state);
state->state_destroy (state);
g_free (state);
return (FALSE || res);
}
/**
......@@ -413,8 +391,8 @@ dialog_tool_init (GenericToolState *state,
state->warning = glade_xml_get_widget (state->gui, "warnings");
wbcg_edit_attach_guru (state->wbcg, state->dialog);
g_signal_connect (G_OBJECT (state->dialog), "destroy",
G_CALLBACK (tool_destroy), state);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) cb_tool_destroy);
dialog_tool_init_outputs (state, sensitivity_cb);
......
......@@ -192,9 +192,8 @@ ac_dialog_toggle_init (AutoCorrectState *state, char const *name,
G_CALLBACK (ac_button_toggled), state->features + f);
}
static gboolean
cb_autocorrect_destroy (G_GNUC_UNUSED GtkObject *w,
AutoCorrectState *state)
static void
cb_autocorrect_destroy (AutoCorrectState *state)
{
g_slist_foreach (state->init_caps.exceptions, (GFunc)g_free, NULL);
g_slist_free (state->init_caps.exceptions);
......@@ -204,15 +203,9 @@ cb_autocorrect_destroy (G_GNUC_UNUSED GtkObject *w,
g_slist_free (state->first_letter.exceptions);
state->first_letter.exceptions = NULL;
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
state->dialog = NULL;
g_free (state);
return TRUE;
}
static void
......@@ -299,9 +292,8 @@ dialog_init (AutoCorrectState *state)
"first_letter_entry", "first_letter_list",
"first_letter_add", "first_letter_remove");
g_signal_connect (G_OBJECT (state->dialog),
"destroy",
G_CALLBACK (cb_autocorrect_destroy), state);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) cb_autocorrect_destroy);
return FALSE;
}
......@@ -332,7 +324,7 @@ dialog_autocorrect (WorkbookControlGUI *wbcg)
if (dialog_init (state)) {
go_gtk_notice_dialog (wbcg_toplevel (wbcg), GTK_MESSAGE_ERROR,
_("Could not create the AutoCorrect dialog."));
cb_autocorrect_destroy (NULL, state);
cb_autocorrect_destroy (state);
return;
}
......
......@@ -82,52 +82,21 @@ dialog_autosave_prompt (WorkbookControlGUI *wbcg)
return result == GTK_RESPONSE_YES;
}
/**
* dialog_autosave:
* @window:
* @state:
*
* Destroy the dialog and associated data structures.
*
**/
static gboolean
dialog_autosave_destroy (GtkObject *w, autosave_t *state)
static void
cb_dialog_autosave_destroy (autosave_t *state)
{
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
state->dialog = NULL;
g_free (state);
return FALSE;
}
/**
* cb_autosave_cancel:
* @button:
* @state:
*
* Close (destroy) the dialog
**/
static void
cb_autosave_cancel (G_GNUC_UNUSED GtkWidget *button,
autosave_t *state)
{
gtk_widget_destroy (state->dialog);
return;
}
/**
* cb_autosave_ok:
* @button:
* @state:
**/
static void
cb_autosave_ok (G_GNUC_UNUSED GtkWidget *button, autosave_t *state)
{
......@@ -211,10 +180,9 @@ dialog_autosave (WorkbookControlGUI *wbcg)
g_signal_connect (G_OBJECT (state->cancel_button),
"clicked",
G_CALLBACK (cb_autosave_cancel), state);
g_signal_connect (G_OBJECT (state->dialog),
"destroy",
G_CALLBACK (dialog_autosave_destroy), state);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) cb_dialog_autosave_destroy);
gnumeric_init_help_button (
glade_xml_get_widget (state->gui, "button3"),
GNUMERIC_HELP_LINK_AUTOSAVE);
......@@ -228,5 +196,4 @@ dialog_autosave (WorkbookControlGUI *wbcg)
gnumeric_keyed_dialog (state->wbcg, GTK_WINDOW (state->dialog),
AUTOSAVE_KEY);
gtk_widget_show (state->dialog);
}
......@@ -45,24 +45,13 @@ typedef struct {
GladeXML *gui;
} CommentState;
static gboolean
dialog_cell_comment_destroy (GtkObject *w, CommentState *state)
static void
cb_dialog_cell_comment_destroy (CommentState *state)
{
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
wbcg_edit_detach_guru (state->wbcg);
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
state->dialog = NULL;
g_free (state);
return FALSE;
}
static void
......@@ -140,14 +129,11 @@ dialog_cell_comment (WorkbookControlGUI *wbcg, Sheet *sheet, GnmCellPos const *p
"clicked",
G_CALLBACK (cb_cell_comment_cancel_clicked), state);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) cb_dialog_cell_comment_destroy);
gnumeric_init_help_button (
glade_xml_get_widget (state->gui, "help_button"),
GNUMERIC_HELP_LINK_CELL_COMMENT);
g_signal_connect (G_OBJECT (state->dialog),
"destroy",
G_CALLBACK (dialog_cell_comment_destroy), state);
gtk_widget_grab_focus (textview);
wbcg_edit_attach_guru (state->wbcg, state->dialog);
......
......@@ -434,21 +434,9 @@ cb_update_sensitivity (SortFlowState *state)
gtk_widget_set_sensitive (state->clear_button, state->sort_items != 0);
}
/**
* dialog_destroy:
* @window:
* @focus_widget:
* @state:
*
* Destroy the dialog and associated data structures.
*
**/
static gboolean
dialog_destroy (GtkObject *w, SortFlowState *state)
static void
cb_dialog_destroy (SortFlowState *state)
{
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
if (state->sel) {
value_release (state->sel);
state->sel = NULL;
......@@ -456,10 +444,10 @@ dialog_destroy (GtkObject *w, SortFlowState *state)
wbcg_edit_detach_guru (state->wbcg);
if (state->gui != NULL) {
if (state->model != NULL)
g_object_unref (G_OBJECT (state->model));
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
wbcg_edit_finish (state->wbcg, WBC_EDIT_REJECT, NULL);
......@@ -471,17 +459,8 @@ dialog_destroy (GtkObject *w, SortFlowState *state)
state->image_descending = NULL;
g_free (state);
return FALSE;
}
/**
* cb_dialog_ok_clicked:
* @button:
* @state:
*
* Sort
**/
static void
cb_dialog_ok_clicked (G_GNUC_UNUSED GtkWidget *button,
SortFlowState *state)
......@@ -537,19 +516,11 @@ cb_dialog_ok_clicked (G_GNUC_UNUSED GtkWidget *button,
return;
}
/**
* cb_dialog_cancel_clicked:
* @button:
* @state:
*
* Close (destroy) the dialog
**/
static void
cb_dialog_cancel_clicked (G_GNUC_UNUSED GtkWidget *button,
SortFlowState *state)
{
gtk_widget_destroy (state->dialog);
return;
}
static void
......@@ -1148,15 +1119,13 @@ dialog_init (SortFlowState *state)
/* Finish dialog signals */
wbcg_edit_attach_guru (state->wbcg, state->dialog);
g_signal_connect (G_OBJECT (state->dialog),
"destroy",
G_CALLBACK (dialog_destroy), state);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) cb_dialog_destroy);
cb_sort_selection_changed (NULL, state);
dialog_load_selection (state);
cb_update_sensitivity (state);
cb_sort_header_check (state);
gnm_expr_entry_grab_focus(GNM_EXPR_ENTRY (state->add_entry), TRUE);
return FALSE;
......
......@@ -48,23 +48,13 @@ typedef struct {
ColRowCallback_t callback;
} ColRowState;
static gboolean
dialog_col_row_destroy (GtkObject *w, ColRowState *state)
static void
cb_dialog_col_row_destroy (GtkObject *w, ColRowState *state)
{
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
wbcg_edit_detach_guru (state->wbcg);
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
state->dialog = NULL;
g_free (state);
return FALSE;
}
static void
......@@ -128,10 +118,8 @@ dialog_col_row (WorkbookControlGUI *wbcg, char const *operation,
gnumeric_init_help_button (
glade_xml_get_widget (state->gui, "help_button"),
GNUMERIC_HELP_LINK_GROUP_UNGROUP);
g_signal_connect (G_OBJECT (state->dialog),
"destroy",
G_CALLBACK (dialog_col_row_destroy), state);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) cb_dialog_col_row_destroy);
gtk_frame_set_label (GTK_FRAME (glade_xml_get_widget (state->gui, "frame")), operation);
......
......@@ -86,23 +86,13 @@ dialog_col_width_button_sensitivity (ColWidthState *state)
gtk_widget_set_sensitive (state->apply_button, changed_info);
}
static gboolean
dialog_col_width_destroy (GtkObject *w, ColWidthState *state)
static void
cb_dialog_col_width_destroy (ColWidthState *state)
{
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
wbcg_edit_detach_guru (state->wbcg);
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
state->dialog = NULL;
g_free (state);
return FALSE;
}
static void
......@@ -298,11 +288,8 @@ dialog_col_width (WorkbookControlGUI *wbcg, gboolean use_default)
gnumeric_init_help_button (
glade_xml_get_widget (state->gui, "help_button"),
GNUMERIC_HELP_LINK_COL_WIDTH);
g_signal_connect (G_OBJECT (state->dialog),
"destroy",
G_CALLBACK (dialog_col_width_destroy), state);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) cb_dialog_col_width_destroy);
dialog_col_width_set_mode (use_default, state);
dialog_col_width_load_value (state);
......
......@@ -272,18 +272,15 @@ cb_source_edited (G_GNUC_UNUSED GtkCellRendererText *cell,
adjust_source_areas (state);
}
static gboolean
cb_dialog_destroy (G_GNUC_UNUSED GtkObject *w, ConsolidateState *state)
static void
cb_dialog_destroy (ConsolidateState *state)
{
if (state->pixmap != NULL) {
if (state->pixmap != NULL)
g_object_unref (G_OBJECT (state->pixmap));
state->pixmap = NULL;
}
if (state->construct_error) {
if (state->construct_error != NULL) {
g_warning ("The construct error was not freed, this should not happen!");
g_free (state->construct_error);
}
return FALSE;
}
static void
......
......@@ -51,23 +51,13 @@ typedef struct {
GladeXML *gui;
} DeleteCellState;
static gboolean
delete_cell_destroy (GtkObject *w, DeleteCellState *state)
static void
cb_delete_cell_destroy (DeleteCellState *state)
{
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
wbcg_edit_detach_guru (state->wbcg);
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
state->dialog = NULL;
g_free (state);
return FALSE;
}
static void
......@@ -181,10 +171,8 @@ dialog_delete_cells (WorkbookControlGUI *wbcg)
gnumeric_init_help_button (
glade_xml_get_widget (state->gui, "helpbutton"),
GNUMERIC_HELP_LINK_DELETE_CELLS);
g_signal_connect (G_OBJECT (state->dialog),
"destroy",
G_CALLBACK (delete_cell_destroy), state);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) cb_delete_cell_destroy);
gtk_toggle_button_set_active
(GTK_TOGGLE_BUTTON (glade_xml_get_widget
......
......@@ -491,38 +491,21 @@ dialog_formula_guru_load_expr (GtkTreePath const *parent_path, gint child_num,
gtk_tree_path_free (path);
}
/**
* dialog_function_select_destroy:
* @window:
* @state:
*
* Destroy the dialog and associated data structures.
*
**/
static void
dialog_formula_guru_destroy (FormulaGuruState *state)
cb_dialog_formula_guru_destroy (FormulaGuruState *state)
{
wbcg_edit_detach_guru (state->wbcg);
wbcg_edit_finish (state->wbcg, WBC_EDIT_REJECT, NULL);
if (state->model != NULL)
g_object_unref (G_OBJECT (state->model));
g_free (state->prefix);
state->prefix = NULL;
g_free (state->suffix);
state->suffix = NULL;
g_free (state->pos);
state->pos = NULL;
if (state->editable) {
if (state->editable)
g_object_unref (state->editable);
state->editable = NULL;
}
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
state->dialog = NULL;
g_free (state);
}
......@@ -912,7 +895,7 @@ dialog_formula_guru_init (FormulaGuruState *state)
glade_xml_get_widget (state->gui, "help_button"),
GNUMERIC_HELP_LINK_FORMULA_GURU);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) dialog_formula_guru_destroy);
"state", state, (GDestroyNotify) cb_dialog_formula_guru_destroy);
wbcg_edit_attach_guru (state->wbcg, state->dialog);
......@@ -1051,5 +1034,4 @@ dialog_formula_guru (WorkbookControlGUI *wbcg, GnmFunc const *fd)
}
gtk_widget_show_all (state->dialog);
return;
}
......@@ -121,7 +121,7 @@ dialog_function_write_recent_func (FunctionSelectState *state, GnmFunc const *fd
static void
dialog_function_select_destroy (FunctionSelectState *state)
cb_dialog_function_select_destroy (FunctionSelectState *state)
{
if (state->formula_guru_key &&
gnumeric_dialog_raise_if_exists (state->wbcg, state->formula_guru_key)) {
......@@ -130,12 +130,13 @@ dialog_function_select_destroy (FunctionSelectState *state)
dialog_formula_guru (state->wbcg, NULL);
}
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
if (state->model != NULL)
g_object_unref (G_OBJECT (state->model));
if (state->model_f != NULL)
g_object_unref (G_OBJECT (state->model_f));
g_slist_free (state->recent_funcs);
state->dialog = NULL;
g_free (state);
}
......@@ -586,7 +587,7 @@ dialog_function_select_init (FunctionSelectState *state)
glade_xml_get_widget (state->gui, "help_button"),
GNUMERIC_HELP_LINK_FUNCTION_SELECT);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) dialog_function_select_destroy);
"state", state, (GDestroyNotify) cb_dialog_function_select_destroy);
}
void
......
......@@ -260,21 +260,9 @@ gnumeric_goal_seek (GoalSeekState *state)
return status;
}
/**
* dialog_destroy:
* @window:
* @focus_widget:
* @state:
*
* Destroy the dialog and associated data structures.
*
**/
static gboolean
dialog_destroy (GtkObject *w, GoalSeekState *state)
static void
cb_dialog_destroy (GoalSeekState *state)
{
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
if (!state->cancelled
&& state->old_value != NULL
&& state->old_cell != NULL) {
......@@ -285,23 +273,13 @@ dialog_destroy (GtkObject *w, GoalSeekState *state)
wbcg_edit_detach_guru (state->wbcg);
if (state->old_value != NULL) {
if (state->old_value != NULL)
value_release (state->old_value);
state->old_value = NULL;
}
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
wbcg_edit_finish (state->wbcg, WBC_EDIT_REJECT, NULL);
state->dialog = NULL;
g_free (state);
return FALSE;
}
static void
......@@ -599,9 +577,8 @@ dialog_init (GoalSeekState *state)
g_signal_connect (G_OBJECT (state->dialog),
"realize",
G_CALLBACK (dialog_realized), state);
g_signal_connect (G_OBJECT (state->dialog),
"destroy",
G_CALLBACK (dialog_destroy), state);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) cb_dialog_destroy);
state->old_value = NULL;
state->old_cell = NULL;
......
......@@ -70,54 +70,25 @@ enum {
NUM_COLMNS
};
/**
* dialog_destroy:
* @window:
* @focus_widget:
* @state:
*
* Destroy the dialog and associated data structures.
*
**/
static gboolean
dialog_goto_close_destroy (GtkObject *w, GotoState *state)
static void
cb_dialog_goto_free (GotoState *state)
{
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
wbcg_edit_detach_guru (state->wbcg);
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
state->dialog = NULL;
if (state->model != NULL)
g_object_unref (G_OBJECT (state->model));
g_free (state);
return FALSE;
}
/**
* cb_dialog_goto_close_clicked:
* @button:
* @state:
*
* Close (destroy) the dialog
**/
static void
cb_dialog_goto_close_clicked (G_GNUC_UNUSED GtkWidget *button,
GotoState *state)
{
gtk_widget_destroy (state->dialog);
return;
}
/**
* cb_dialog_goto_go_clicked:
* @button:
* @state:
*
**/
static void
cb_dialog_goto_go_clicked (G_GNUC_UNUSED GtkWidget *button,
GotoState *state)
......@@ -316,10 +287,8 @@ dialog_goto_init (GotoState *state)
gnumeric_init_help_button (
glade_xml_get_widget (state->gui, "help_button"),
GNUMERIC_HELP_LINK_GOTO_CELL);
g_signal_connect (G_OBJECT (state->dialog),
"destroy",
G_CALLBACK (dialog_goto_close_destroy), state);
g_object_set_data_full (G_OBJECT (state->dialog),
"state", state, (GDestroyNotify) cb_dialog_goto_free);
cb_dialog_goto_update_sensitivity (NULL, state);
......
......@@ -51,23 +51,13 @@ typedef struct {
GladeXML *gui;
} InsertCellState;
static gboolean
insert_cell_destroy (GtkObject *w, InsertCellState *state)
static void
cb_insert_cell_destroy (InsertCellState *state)
{
g_return_val_if_fail (w != NULL, FALSE);
g_return_val_if_fail (state != NULL, FALSE);
wbcg_edit_detach_guru (state->wbcg);
if (state->gui != NULL) {
if (state->gui != NULL)
g_object_unref (G_OBJECT (state->gui));
state->gui = NULL;
}
state->dialog = NULL;
g_free (state);
return FALSE;
}