[gnumeric] Sheet objects: make it possible to have horizontal widgets too.



commit ef29fa52c92b5cc2281d31481264a90cca9aa330
Author: Morten Welinder <terra gnome org>
Date:   Thu May 14 10:51:24 2009 -0400

    Sheet objects: make it possible to have horizontal widgets too.
---
 ChangeLog                      |    5 ++
 NEWS                           |    2 +-
 src/commands.c                 |    7 +++
 src/commands.h                 |    1 +
 src/dialogs/so-scrollbar.glade |  108 +++++++++++++++++++++++++++++++++-----
 src/sheet-object-widget.c      |  113 +++++++++++++++++++++++++++++++++++++---
 6 files changed, 212 insertions(+), 24 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 084e690..631d8f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-05-14  Morten Welinder  <terra gnome org>
 
+	* src/commands.c (cmd_so_set_adjustment): Handle h/v too.  All
+	callers changed.
+	* src/sheet-object-widget.c (sheet_widget_adjustment_user_config_impl):
+	Ditto.
+
 	* src/sheet-object-widget.c (SheetWidgetAdjustment): Add explicit
 	direction here.
 	(SheetWidgetAdjustmentClass): Identify h and v versions here.
diff --git a/NEWS b/NEWS
index deca751..fa2730c 100644
--- a/NEWS
+++ b/NEWS
@@ -25,7 +25,7 @@ Morten:
 	* Cache large ranges, possibly sorted.
 	* Add progress display for OO import.
 	* Improve ssindex' coverage.
-	* Fix problem with scrollbar sheet widgets.  [Part of #166487]
+	* Make it possible to have horizontal widgets too.  [#166487]
 
 Paul Fitzpatrick:
 	* Extend ssconvert to also merge multiple sheets.  [#581616]
diff --git a/src/commands.c b/src/commands.c
index d6a7b58..7fe8913 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -7367,6 +7367,7 @@ typedef struct {
 	double old_upper;
 	double old_step;
 	double old_page;
+	gboolean old_horizontal;
 } CmdSOSetAdjustment;
 
 MAKE_GNM_COMMAND (CmdSOSetAdjustment, cmd_so_set_adjustment, NULL)
@@ -7380,6 +7381,8 @@ cmd_so_set_adjustment_adj (CmdSOSetAdjustment *me)
 	double old_upper = gtk_adjustment_get_upper (adj);
 	double old_step = gtk_adjustment_get_step_increment (adj);
 	double old_page = gtk_adjustment_get_page_increment (adj);
+	double old_horizontal;
+	g_object_get (G_OBJECT (me->so), "horizontal", &old_horizontal, NULL);
 
 	gtk_adjustment_configure (adj,
 				  gtk_adjustment_get_value (adj),
@@ -7388,11 +7391,13 @@ cmd_so_set_adjustment_adj (CmdSOSetAdjustment *me)
 				  me->old_step,
 				  me->old_page,
 				  gtk_adjustment_get_page_size (adj));
+	g_object_set (G_OBJECT (me->so), "horizontal", me->old_horizontal, NULL);
 
 	me->old_lower = old_lower;
 	me->old_upper = old_upper;
 	me->old_step = old_step;
 	me->old_page = old_page;
+	me->old_horizontal = old_horizontal;
 }
 
 static gboolean
@@ -7431,6 +7436,7 @@ cmd_so_set_adjustment_finalize (GObject *cmd)
 gboolean
 cmd_so_set_adjustment (WorkbookControl *wbc,
 		       SheetObject *so, GnmExprTop const *link,
+		       gboolean horizontal,
 		       int lower, int upper,
 		       int step, int page,
 		       char const *undo_label)
@@ -7450,6 +7456,7 @@ cmd_so_set_adjustment (WorkbookControl *wbc,
 	me->old_upper = upper;
 	me->old_step = step;
 	me->old_page = page;
+	me->old_horizontal = horizontal;
 
 	me->old_link = sheet_widget_adjustment_get_link (so);
 
diff --git a/src/commands.h b/src/commands.h
index 16eac0d..01efd7b 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -186,6 +186,7 @@ gboolean cmd_so_set_checkbox (WorkbookControl *wbc, SheetObject *so,
 
 gboolean cmd_so_set_adjustment (WorkbookControl *wbc, SheetObject *so,
 				GnmExprTop const *link,
+				gboolean horizontal,
 				int lower, int upper,
 				int step, int page,
 				char const *undo_label);
diff --git a/src/dialogs/so-scrollbar.glade b/src/dialogs/so-scrollbar.glade
index f28ea94..741be0e 100644
--- a/src/dialogs/so-scrollbar.glade
+++ b/src/dialogs/so-scrollbar.glade
@@ -73,7 +73,7 @@
 	<widget class="GtkTable" id="table">
 	  <property name="border_width">5</property>
 	  <property name="visible">True</property>
-	  <property name="n_rows">5</property>
+	  <property name="n_rows">6</property>
 	  <property name="n_columns">2</property>
 	  <property name="homogeneous">False</property>
 	  <property name="row_spacing">6</property>
@@ -123,8 +123,8 @@
 	    <packing>
 	      <property name="left_attach">0</property>
 	      <property name="right_attach">1</property>
-	      <property name="top_attach">2</property>
-	      <property name="bottom_attach">3</property>
+	      <property name="top_attach">3</property>
+	      <property name="bottom_attach">4</property>
 	      <property name="x_options">fill</property>
 	      <property name="y_options"></property>
 	    </packing>
@@ -150,8 +150,8 @@
 	    <packing>
 	      <property name="left_attach">0</property>
 	      <property name="right_attach">1</property>
-	      <property name="top_attach">3</property>
-	      <property name="bottom_attach">4</property>
+	      <property name="top_attach">4</property>
+	      <property name="bottom_attach">5</property>
 	      <property name="x_options">fill</property>
 	      <property name="y_options"></property>
 	    </packing>
@@ -177,8 +177,8 @@
 	    <packing>
 	      <property name="left_attach">0</property>
 	      <property name="right_attach">1</property>
-	      <property name="top_attach">4</property>
-	      <property name="bottom_attach">5</property>
+	      <property name="top_attach">5</property>
+	      <property name="bottom_attach">6</property>
 	      <property name="x_options">fill</property>
 	      <property name="y_options"></property>
 	    </packing>
@@ -202,8 +202,8 @@
 	    <packing>
 	      <property name="left_attach">1</property>
 	      <property name="right_attach">2</property>
-	      <property name="top_attach">1</property>
-	      <property name="bottom_attach">2</property>
+	      <property name="top_attach">2</property>
+	      <property name="bottom_attach">3</property>
 	      <property name="y_options"></property>
 	    </packing>
 	  </child>
@@ -226,8 +226,8 @@
 	    <packing>
 	      <property name="left_attach">1</property>
 	      <property name="right_attach">2</property>
-	      <property name="top_attach">2</property>
-	      <property name="bottom_attach">3</property>
+	      <property name="top_attach">3</property>
+	      <property name="bottom_attach">4</property>
 	      <property name="y_options"></property>
 	    </packing>
 	  </child>
@@ -250,8 +250,8 @@
 	    <packing>
 	      <property name="left_attach">1</property>
 	      <property name="right_attach">2</property>
-	      <property name="top_attach">3</property>
-	      <property name="bottom_attach">4</property>
+	      <property name="top_attach">4</property>
+	      <property name="bottom_attach">5</property>
 	      <property name="y_options"></property>
 	    </packing>
 	  </child>
@@ -274,8 +274,8 @@
 	    <packing>
 	      <property name="left_attach">1</property>
 	      <property name="right_attach">2</property>
-	      <property name="top_attach">4</property>
-	      <property name="bottom_attach">5</property>
+	      <property name="top_attach">5</property>
+	      <property name="bottom_attach">6</property>
 	      <property name="y_options"></property>
 	    </packing>
 	  </child>
@@ -300,12 +300,90 @@
 	    <packing>
 	      <property name="left_attach">0</property>
 	      <property name="right_attach">1</property>
+	      <property name="top_attach">2</property>
+	      <property name="bottom_attach">3</property>
+	      <property name="x_options">fill</property>
+	      <property name="y_options"></property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkLabel" id="direction_label">
+	      <property name="visible">True</property>
+	      <property name="label" translatable="yes">Direction:</property>
+	      <property name="use_underline">False</property>
+	      <property name="use_markup">False</property>
+	      <property name="justify">GTK_JUSTIFY_LEFT</property>
+	      <property name="wrap">False</property>
+	      <property name="selectable">False</property>
+	      <property name="xalign">0</property>
+	      <property name="yalign">0.5</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">0</property>
+	    </widget>
+	    <packing>
+	      <property name="left_attach">0</property>
+	      <property name="right_attach">1</property>
 	      <property name="top_attach">1</property>
 	      <property name="bottom_attach">2</property>
 	      <property name="x_options">fill</property>
 	      <property name="y_options"></property>
 	    </packing>
 	  </child>
+
+	  <child>
+	    <widget class="GtkHBox" id="direction_box">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
+
+	      <child>
+		<widget class="GtkRadioButton" id="direction_h">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="label" translatable="yes">_Horizontal</property>
+		  <property name="use_underline">True</property>
+		  <property name="relief">GTK_RELIEF_NORMAL</property>
+		  <property name="active">False</property>
+		  <property name="inconsistent">False</property>
+		  <property name="draw_indicator">True</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkRadioButton" id="direction_v">
+		  <property name="visible">True</property>
+		  <property name="can_focus">True</property>
+		  <property name="label" translatable="yes">_Vertical</property>
+		  <property name="use_underline">True</property>
+		  <property name="relief">GTK_RELIEF_NORMAL</property>
+		  <property name="active">False</property>
+		  <property name="inconsistent">False</property>
+		  <property name="draw_indicator">True</property>
+		  <property name="group">direction_h</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		  <property name="pack_type">GTK_PACK_END</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="left_attach">1</property>
+	      <property name="right_attach">2</property>
+	      <property name="top_attach">1</property>
+	      <property name="bottom_attach">2</property>
+	      <property name="x_options">fill</property>
+	      <property name="y_options">fill</property>
+	    </packing>
+	  </child>
 	</widget>
 	<packing>
 	  <property name="padding">0</property>
diff --git a/src/sheet-object-widget.c b/src/sheet-object-widget.c
index 92cce59..94d3230 100644
--- a/src/sheet-object-widget.c
+++ b/src/sheet-object-widget.c
@@ -790,6 +790,11 @@ typedef struct {
 	GType htype, vtype;
 } SheetWidgetAdjustmentClass;
 
+enum {
+	SWA_PROP_0 = 0,
+	SWA_PROP_HORIZONTAL
+};
+
 static GType sheet_widget_adjustment_get_type (void);
 
 static void
@@ -882,6 +887,64 @@ cb_adjustment_widget_value_changed (GtkWidget *widget,
 }
 
 static void
+sheet_widget_adjustment_set_horizontal (SheetWidgetAdjustment *swa,
+					gboolean horizontal)
+{
+	SheetObjectWidgetClass *sow_class =
+		G_TYPE_INSTANCE_GET_CLASS (swa,
+					   sheet_object_widget_get_type(),
+					   SheetObjectWidgetClass);
+	GList *ptr;
+
+	horizontal = !!horizontal;
+	if (horizontal == swa->horizontal)
+		return;
+	swa->horizontal = horizontal;
+
+	/* Change direction for all realized widgets.  */
+	for (ptr = swa->sow.realized_list; ptr != NULL; ptr = ptr->next) {
+		FooCanvasItem *item = FOO_CANVAS_ITEM (ptr->data);
+		GtkWidget *neww = sow_class->create_widget (SHEET_OBJECT (swa));
+		gtk_widget_show (neww);
+		foo_canvas_item_set (item, "widget", neww, NULL);
+	}
+}
+
+
+static void
+sheet_widget_adjustment_get_property (GObject *obj, guint param_id,
+				      GValue  *value, GParamSpec *pspec)
+{
+	SheetWidgetAdjustment *swa = SHEET_WIDGET_ADJUSTMENT (obj);
+
+	switch (param_id) {
+	case SWA_PROP_HORIZONTAL:
+		g_value_set_boolean (value, swa->horizontal);
+		break;
+	default :
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
+		break;
+	}
+}
+
+static void
+sheet_widget_adjustment_set_property (GObject *obj, guint param_id,
+				      GValue const *value, GParamSpec *pspec)
+{
+	SheetWidgetAdjustment *swa = SHEET_WIDGET_ADJUSTMENT (obj);
+
+	switch (param_id) {
+	case SWA_PROP_HORIZONTAL:
+		sheet_widget_adjustment_set_horizontal (swa, g_value_get_boolean (value));
+		/* FIXME */
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
+		return;
+	}
+}
+
+static void
 sheet_widget_adjustment_init_full (SheetWidgetAdjustment *swa,
 				   GnmCellRef const *ref,
 				   gboolean horizontal)
@@ -951,11 +1014,13 @@ sheet_widget_adjustment_copy (SheetObject *dst, SheetObject const *src)
 typedef struct {
 	GladeXML           *gui;
 	GtkWidget          *dialog;
-	GnmExprEntry  *expression;
+	GnmExprEntry       *expression;
 	GtkWidget          *min;
 	GtkWidget          *max;
 	GtkWidget          *inc;
 	GtkWidget          *page;
+	GtkWidget          *direction_h;
+	GtkWidget          *direction_v;
 
 	char               *undo_label;
 	GtkWidget          *old_focus;
@@ -1006,13 +1071,19 @@ static void
 cb_adjustment_config_ok_clicked (GtkWidget *button, AdjustmentConfigState *state)
 {
 	SheetObject *so = SHEET_OBJECT (state->swa);
-	GnmParsePos  pp;
+	GnmParsePos pp;
 	GnmExprTop const *texpr = gnm_expr_entry_parse (state->expression,
 		parse_pos_init_sheet (&pp, so->sheet),
 		NULL, FALSE, GNM_EXPR_PARSE_DEFAULT);
+	gboolean horizontal;
+
+	horizontal = state->direction_h
+		? gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (state->direction_h))
+		: state->swa->horizontal;
 
 	cmd_so_set_adjustment (WORKBOOK_CONTROL (state->wbcg), so,
 			       texpr,
+			       horizontal,
 			       gtk_spin_button_get_value_as_int (
 				       GTK_SPIN_BUTTON (state->min)),
 			       gtk_spin_button_get_value_as_int (
@@ -1036,11 +1107,16 @@ static void
 sheet_widget_adjustment_user_config_impl (SheetObject *so, SheetControl *sc, char const *undo_label, char const *dialog_label)
 {
 	SheetWidgetAdjustment *swa = SHEET_WIDGET_ADJUSTMENT (so);
-	WBCGtk   *wbcg = scg_wbcg (SHEET_CONTROL_GUI (sc));
+	SheetWidgetAdjustmentClass *swa_class =
+		G_TYPE_INSTANCE_GET_CLASS (swa,
+					   sheet_widget_adjustment_get_type(),
+					   SheetWidgetAdjustmentClass);
+
+	WBCGtk *wbcg = scg_wbcg (SHEET_CONTROL_GUI (sc));
 	AdjustmentConfigState *state;
 	GtkWidget *table;
-
-	g_return_if_fail (swa != NULL);
+	gboolean has_directions = (swa_class->htype != G_TYPE_NONE &&
+				   swa_class->vtype != G_TYPE_NONE);
 
 	/* Only pop up one copy per workbook */
 	if (gnumeric_dialog_raise_if_exists (wbcg, SHEET_OBJECT_CONFIG_KEY))
@@ -1074,6 +1150,21 @@ sheet_widget_adjustment_user_config_impl (SheetObject *so, SheetControl *sc, cha
 			  0, 0);
 	gtk_widget_show (GTK_WIDGET (state->expression));
 
+	if (has_directions) {
+		state->direction_h = glade_xml_get_widget (state->gui, "direction_h");
+		state->direction_v = glade_xml_get_widget (state->gui, "direction_v");
+		gtk_toggle_button_set_active
+			(GTK_TOGGLE_BUTTON (swa->horizontal
+					    ? state->direction_h
+					    : state->direction_v),
+			 TRUE);
+	} else {
+		state->direction_h = NULL;
+		state->direction_v = NULL;
+		gtk_widget_destroy (glade_xml_get_widget (state->gui, "direction_label"));
+		gtk_widget_destroy (glade_xml_get_widget (state->gui, "direction_box"));
+	}
+
 	/* TODO : This is silly, no need to be similar to XL here. */
 	state->min = glade_xml_get_widget (state->gui, "spin_min");
 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (state->min), swa->adjustment->lower);
@@ -1279,9 +1370,15 @@ SOW_MAKE_TYPE (adjustment, Adjustment,
 	       sheet_widget_adjustment_read_xml_dom,
 	       sheet_widget_adjustment_write_xml_sax,
 	       sheet_widget_adjustment_prep_sax_parser,
-	       NULL,
-	       NULL,
-	       {})
+	       sheet_widget_adjustment_get_property,
+	       sheet_widget_adjustment_set_property,
+	       {
+		       g_object_class_install_property
+			       (object_class, SWA_PROP_HORIZONTAL,
+				g_param_spec_boolean ("horizontal", NULL, NULL,
+						      FALSE,
+						      GSF_PARAM_STATIC | G_PARAM_READWRITE));
+	       })
 
 /****************************************************************************/
 #define SHEET_WIDGET_SCROLLBAR_TYPE	(sheet_widget_scrollbar_get_type ())



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