[goffice] Moved plot area position page from plot to chart. [#605771]



commit 7201a4c91518bc9388f96e401c34768b92d0e007
Author: Jean Brefort <jean brefort normalesup org>
Date:   Wed Jan 6 19:49:41 2010 +0100

    Moved plot area position page from plot to chart. [#605771]

 ChangeLog                 |    8 ++
 NEWS                      |    1 +
 goffice/graph/gog-chart.c |  134 +++++++++++++++++++++++++++++++++++
 goffice/graph/gog-plot.c  |  170 +-------------------------------------------
 4 files changed, 147 insertions(+), 166 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5dfc2af..7672b32 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2010-01-06  Jean Brefort  <jean brefort normalesup org>
+
+	* goffice/graph/gog-chart.c (plot_area_pref_state_free),
+	(cb_plot_area_changed), (cb_manual_position_changed),
+	(gog_chart_populate_editor): moved plot area page there. [#605771]
+	* goffice/graph/gog-plot.c (cb_axis_changed),
+	(gog_plot_populate_editor): and remove it from here.
+
 2010-01-06  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* plugins/plot_pie/plot-types.xml.in: fix description
diff --git a/NEWS b/NEWS
index 10fbf62..fadb55e 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ Andreas:
 Jean:
 	* Add a name to regression curves for display in legends. [#605040]
 	* Fixed GocPolygon bounds. [#605496]
+	* Moved plot area position page from plot to chart. [#605771]
 
 --------------------------------------------------------------------------
 goffice 0.7.17:
diff --git a/goffice/graph/gog-chart.c b/goffice/graph/gog-chart.c
index 38c1352..6535b7f 100644
--- a/goffice/graph/gog-chart.c
+++ b/goffice/graph/gog-chart.c
@@ -222,6 +222,79 @@ gog_chart_get_property (GObject *obj, guint param_id,
 	}
 }
 
+#ifdef GOFFICE_WITH_GTK
+typedef struct {
+	GtkBuilder	*gui;
+	GtkWidget	*x_spin, *y_spin, *w_spin, *h_spin;
+	gulong		 w_spin_signal, h_spin_signal;
+	GtkWidget	*position_select_combo;
+	GtkWidget	*manual_setting_table;
+	GogChart	*chart;
+} PlotAreaPrefState;
+
+static void
+plot_area_pref_state_free (PlotAreaPrefState *state)
+{
+	g_object_unref (state->chart);
+	g_object_unref (state->gui);
+}
+
+static void
+cb_plot_area_changed (GtkWidget *spin, PlotAreaPrefState *state)
+{
+	GogViewAllocation pos;
+	double value;
+	double max;
+
+       	value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)) / 100.0;
+
+       	gog_chart_get_plot_area (state->chart, &pos);
+	if (spin == state->x_spin) {
+		pos.x = value;
+		max = 1.0 - pos.x;
+		g_signal_handler_block (state->w_spin, state->w_spin_signal);
+		gtk_spin_button_set_range (GTK_SPIN_BUTTON (state->w_spin), 0.0, max * 100.0);
+		if (pos.w > max) pos.w = max;
+		gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->w_spin), pos.w * 100.0);
+		g_signal_handler_unblock (state->w_spin, state->w_spin_signal);
+	}
+	else if (spin == state->y_spin) {
+		pos.y = value;
+		max = 1.0 - pos.y;
+		g_signal_handler_block (state->h_spin, state->h_spin_signal);
+		gtk_spin_button_set_range (GTK_SPIN_BUTTON (state->h_spin), 0.0, max * 100.0);
+		if (pos.h > max) pos.h = max;
+		gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->h_spin), pos.w * 100.0);
+		g_signal_handler_unblock (state->h_spin, state->h_spin_signal);
+	}
+	else if (spin == state->w_spin) {
+		pos.w = value;
+	}
+	else if (spin == state->h_spin) {
+		pos.h = value;
+	}
+	gog_chart_set_plot_area (state->chart, &pos);
+	gtk_combo_box_set_active (GTK_COMBO_BOX (state->position_select_combo), 1);
+	gtk_widget_show (state->manual_setting_table);
+}
+
+static void
+cb_manual_position_changed (GtkComboBox *combo, PlotAreaPrefState *state)
+{
+	if (gtk_combo_box_get_active (combo) == 1) {
+		GogViewAllocation plot_area;
+
+		gog_chart_get_plot_area (state->chart, &plot_area);
+		gog_chart_set_plot_area (state->chart, &plot_area);
+		gtk_widget_show (state->manual_setting_table);
+	} else {
+		gog_chart_set_plot_area (state->chart, NULL);
+		gtk_widget_hide (state->manual_setting_table);
+	}
+}
+
+#endif
+
 static void
 gog_chart_populate_editor (GogObject *gobj,
 			   GOEditor *editor,
@@ -230,8 +303,69 @@ gog_chart_populate_editor (GogObject *gobj,
 {
 	static guint chart_pref_page = 0;
 
+	GtkBuilder *gui;
+	PlotAreaPrefState *state;
+	gboolean is_plot_area_manual;
+	GogViewAllocation plot_area;
+	GtkWidget *w;
+	GogChart *chart = GOG_CHART (gobj);
+
+	g_return_if_fail (chart != NULL);
+
+	gui = go_gtk_builder_new ("gog-plot-prefs.ui", GETTEXT_PACKAGE, cc);
+	g_return_if_fail (gui != NULL);
+
 	(GOG_OBJECT_CLASS(chart_parent_klass)->populate_editor) (gobj, editor, dalloc, cc);
 
+	state = g_new  (PlotAreaPrefState, 1);
+	state->chart = chart;
+	state->gui = gui;
+
+	g_object_ref (G_OBJECT (chart));
+	is_plot_area_manual = gog_chart_get_plot_area (chart, &plot_area);
+
+	state->x_spin = go_gtk_builder_get_widget (gui, "x_spin");
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->x_spin),
+				   plot_area.x * 100.0);
+	g_signal_connect (G_OBJECT (state->x_spin), "value-changed",
+			  G_CALLBACK (cb_plot_area_changed), state);
+
+	state->y_spin = go_gtk_builder_get_widget (gui, "y_spin");
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->y_spin),
+				   plot_area.y * 100.0);
+	g_signal_connect (G_OBJECT (state->y_spin), "value-changed",
+			  G_CALLBACK (cb_plot_area_changed), state);
+
+	state->w_spin = go_gtk_builder_get_widget (gui, "w_spin");
+	gtk_spin_button_set_range (GTK_SPIN_BUTTON (state->w_spin),
+				   0.0, (1.0 - plot_area.x) * 100.0);
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->w_spin),
+				   100.0 * plot_area.w);
+	state->w_spin_signal = g_signal_connect (G_OBJECT (state->w_spin), "value-changed",
+						 G_CALLBACK (cb_plot_area_changed), state);
+
+	state->h_spin = go_gtk_builder_get_widget (gui, "h_spin");
+	gtk_spin_button_set_range (GTK_SPIN_BUTTON (state->h_spin),
+				   0.0, (1.0 - plot_area.y) * 100.0);
+	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->h_spin),
+				   100.0 * plot_area.h);
+	state->h_spin_signal = g_signal_connect (G_OBJECT (state->h_spin), "value-changed",
+						 G_CALLBACK (cb_plot_area_changed), state);
+
+	state->position_select_combo = go_gtk_builder_get_widget (gui, "position_select_combo");
+	gtk_combo_box_set_active (GTK_COMBO_BOX (state->position_select_combo),
+				  is_plot_area_manual ? 1 : 0);
+	state->manual_setting_table = go_gtk_builder_get_widget (gui, "manual_setting_table");
+	if (!is_plot_area_manual)
+		gtk_widget_hide (state->manual_setting_table);
+
+	g_signal_connect (G_OBJECT (state->position_select_combo),
+			  "changed", G_CALLBACK (cb_manual_position_changed), state);
+
+	w = go_gtk_builder_get_widget (gui, "gog_plot_prefs");
+	g_signal_connect_swapped (G_OBJECT (w), "destroy", G_CALLBACK (plot_area_pref_state_free), state);
+	go_editor_add_page (editor, w, _("Plot area"));
+
 	go_editor_set_store_page (editor, &chart_pref_page);
 }
 
diff --git a/goffice/graph/gog-plot.c b/goffice/graph/gog-plot.c
index be1a9f0..8fffade 100644
--- a/goffice/graph/gog-plot.c
+++ b/goffice/graph/gog-plot.c
@@ -135,82 +135,9 @@ role_series_pre_remove (GogObject *parent, GogObject *series)
 }
 
 #ifdef GOFFICE_WITH_GTK
-typedef struct {
-	GtkBuilder	*gui;
-	GtkWidget	*x_spin, *y_spin, *w_spin, *h_spin;
-	gulong		 w_spin_signal, h_spin_signal;
-	GtkWidget	*position_select_combo;
-	GtkWidget	*manual_setting_table;
-	GogChart	*chart;
-	GogPlot		*plot;
-	gulong		 update_editor_handler;
-} PlotPrefState;
-
-static void
-plot_pref_state_free (PlotPrefState *state)
-{
-	g_signal_handler_disconnect (G_OBJECT (state->plot), state->update_editor_handler);
-	g_object_unref (state->plot);
-	g_object_unref (state->chart);
-	g_object_unref (state->gui);
-}
-
-static void
-cb_plot_area_changed (GtkWidget *spin, PlotPrefState *state)
-{
-	GogViewAllocation pos;
-	double value;
-	double max;
-
-       	value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spin)) / 100.0;
-
-       	gog_chart_get_plot_area (state->chart, &pos);
-	if (spin == state->x_spin) {
-		pos.x = value;
-		max = 1.0 - pos.x;
-		g_signal_handler_block (state->w_spin, state->w_spin_signal);
-		gtk_spin_button_set_range (GTK_SPIN_BUTTON (state->w_spin), 0.0, max * 100.0);
-		if (pos.w > max) pos.w = max;
-		gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->w_spin), pos.w * 100.0);
-		g_signal_handler_unblock (state->w_spin, state->w_spin_signal);
-	}
-	else if (spin == state->y_spin) {
-		pos.y = value;
-		max = 1.0 - pos.y;
-		g_signal_handler_block (state->h_spin, state->h_spin_signal);
-		gtk_spin_button_set_range (GTK_SPIN_BUTTON (state->h_spin), 0.0, max * 100.0);
-		if (pos.h > max) pos.h = max;
-		gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->h_spin), pos.w * 100.0);
-		g_signal_handler_unblock (state->h_spin, state->h_spin_signal);
-	}
-	else if (spin == state->w_spin) {
-		pos.w = value;
-	}
-	else if (spin == state->h_spin) {
-		pos.h = value;
-	}
-	gog_chart_set_plot_area (state->chart, &pos);
-	gtk_combo_box_set_active (GTK_COMBO_BOX (state->position_select_combo), 1);
-	gtk_widget_show (state->manual_setting_table);
-}
-
-static void
-cb_manual_position_changed (GtkComboBox *combo, PlotPrefState *state)
-{
-	if (gtk_combo_box_get_active (combo) == 1) {
-		GogViewAllocation plot_area;
-
-		gog_chart_get_plot_area (state->chart, &plot_area);
-		gog_chart_set_plot_area (state->chart, &plot_area);
-		gtk_widget_show (state->manual_setting_table);
-	} else {
-		gog_chart_set_plot_area (state->chart, NULL);
-		gtk_widget_hide (state->manual_setting_table);
-	}
-}
 
 static void
-cb_axis_changed (GtkComboBox *combo, PlotPrefState *state)
+cb_axis_changed (GtkComboBox *combo, GogPlot *plot)
 {
 	GtkTreeIter iter;
 	GValue value;
@@ -219,38 +146,12 @@ cb_axis_changed (GtkComboBox *combo, PlotPrefState *state)
 	memset (&value, 0, sizeof (GValue));
 	gtk_combo_box_get_active_iter (combo, &iter);
 	gtk_tree_model_get_value (model, &iter, 1, &value);
-	gog_plot_set_axis_by_id (state->plot,
+	gog_plot_set_axis_by_id (plot,
 				 GPOINTER_TO_UINT (g_object_get_data (G_OBJECT(combo), "axis-type")),
 				 g_value_get_uint (&value));
 }
 
 static void
-cb_update_editor (GogObject *gobj, PlotPrefState *state)
-{
-	GogViewAllocation plot_area;
-	gboolean is_plot_area_manual;
-
-	is_plot_area_manual = gog_chart_get_plot_area (state->chart, &plot_area);
-
-	if (state->x_spin != NULL)
-		gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->x_spin), plot_area.x * 100.0);
-	if (state->y_spin != NULL)
-		gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->y_spin), plot_area.y * 100.0);
-	if (state->w_spin != NULL)
-		gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->w_spin), plot_area.w * 100.0);
-	if (state->h_spin != NULL)
-		gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->h_spin), plot_area.h * 100.0);
-	if (state->position_select_combo != NULL) {
-		gtk_combo_box_set_active (GTK_COMBO_BOX (state->position_select_combo),
-					  is_plot_area_manual ? 1 : 0);
-		if (is_plot_area_manual)
-			gtk_widget_show (state->manual_setting_table);
-		else
-			gtk_widget_hide (state->manual_setting_table);
-	}
-}
-
-static void
 gog_plot_populate_editor (GogObject *obj,
 			  GOEditor *editor,
 			  G_GNUC_UNUSED GogDataAllocator *dalloc,
@@ -267,33 +168,18 @@ gog_plot_populate_editor (GogObject *obj,
 		N_("Bubble axis:")
 	};
 
-	GtkWidget *w;
 	GogAxisType type;
 	GogPlot *plot = GOG_PLOT (obj);
 	unsigned count = 0, axis_count;
 	GSList *axes, *ptr;
 	GogChart *chart = GOG_CHART (gog_object_get_parent (obj));
 	GogAxis *axis;
-	GogViewAllocation plot_area;
 	GtkListStore *store;
 	GtkTreeIter iter;
 	GtkCellRenderer *cell;
-	GtkBuilder *gui;
-	PlotPrefState *state;
-	gboolean is_plot_area_manual;
 
 	g_return_if_fail (chart != NULL);
-	gui = go_gtk_builder_new ("gog-plot-prefs.ui", GETTEXT_PACKAGE, cc);
-	g_return_if_fail (gui != NULL);
-
-	state = g_new  (PlotPrefState, 1);
-	state->plot = plot;
-	state->chart = chart;
-	state->gui = gui;
-
-	g_object_ref (G_OBJECT (plot));
-	g_object_ref (G_OBJECT (chart));
-
+	
 	if (gog_chart_get_axis_set (chart) == GOG_AXIS_SET_XY) {
 		GtkWidget *combo;
 		GtkWidget *table = gtk_table_new (0, 1, FALSE);
@@ -334,7 +220,7 @@ gog_plot_populate_editor (GogObject *obj,
 						  1, 2, count - 1, count, 0, 0, 0, 0);
 				g_object_set_data (G_OBJECT (combo), "axis-type", GUINT_TO_POINTER (type));
 				g_signal_connect (G_OBJECT (combo), "changed",
-						  G_CALLBACK (cb_axis_changed), state);
+						  G_CALLBACK (cb_axis_changed), plot);
 			}
 		}
 
@@ -349,54 +235,6 @@ gog_plot_populate_editor (GogObject *obj,
 			g_object_unref (G_OBJECT (table));
 	}
 
-	is_plot_area_manual = gog_chart_get_plot_area (chart, &plot_area);
-
-	state->x_spin = go_gtk_builder_get_widget (gui, "x_spin");
-	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->x_spin),
-				   plot_area.x * 100.0);
-	g_signal_connect (G_OBJECT (state->x_spin), "value-changed",
-			  G_CALLBACK (cb_plot_area_changed), state);
-
-	state->y_spin = go_gtk_builder_get_widget (gui, "y_spin");
-	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->y_spin),
-				   plot_area.y * 100.0);
-	g_signal_connect (G_OBJECT (state->y_spin), "value-changed",
-			  G_CALLBACK (cb_plot_area_changed), state);
-
-	state->w_spin = go_gtk_builder_get_widget (gui, "w_spin");
-	gtk_spin_button_set_range (GTK_SPIN_BUTTON (state->w_spin),
-				   0.0, (1.0 - plot_area.x) * 100.0);
-	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->w_spin),
-				   100.0 * plot_area.w);
-	state->w_spin_signal = g_signal_connect (G_OBJECT (state->w_spin), "value-changed",
-						 G_CALLBACK (cb_plot_area_changed), state);
-
-	state->h_spin = go_gtk_builder_get_widget (gui, "h_spin");
-	gtk_spin_button_set_range (GTK_SPIN_BUTTON (state->h_spin),
-				   0.0, (1.0 - plot_area.y) * 100.0);
-	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->h_spin),
-				   100.0 * plot_area.h);
-	state->h_spin_signal = g_signal_connect (G_OBJECT (state->h_spin), "value-changed",
-						 G_CALLBACK (cb_plot_area_changed), state);
-
-	state->position_select_combo = go_gtk_builder_get_widget (gui, "position_select_combo");
-	gtk_combo_box_set_active (GTK_COMBO_BOX (state->position_select_combo),
-				  is_plot_area_manual ? 1 : 0);
-	state->manual_setting_table = go_gtk_builder_get_widget (gui, "manual_setting_table");
-	if (!is_plot_area_manual)
-		gtk_widget_hide (state->manual_setting_table);
-
-	g_signal_connect (G_OBJECT (state->position_select_combo),
-			  "changed", G_CALLBACK (cb_manual_position_changed), state);
-
-	w = go_gtk_builder_get_widget (gui, "gog_plot_prefs");
-	g_signal_connect_swapped (G_OBJECT (w), "destroy", G_CALLBACK (plot_pref_state_free), state);
-	go_editor_add_page (editor, w, _("Plot area"));
-
-	state->update_editor_handler = g_signal_connect (G_OBJECT (plot),
-							 "update-editor",
-							 G_CALLBACK (cb_update_editor), state);
-
 	(GOG_OBJECT_CLASS(plot_parent_klass)->populate_editor) (obj, editor, dalloc, cc);
 }
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]