[gnumeric] Add option to sheet object lists and combos to enter values rather than index. [#629333]



commit 14f1280af85ee6eaa69c87e995c36390f804b007
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Mon Oct 4 21:43:41 2010 -0600

    Add option to sheet object lists and combos to enter values rather than index. [#629333]
    
    2010-10-04  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/commands.h (cmd_so_set_links): add argument
    	* src/commands.c (cmd_so_set_links): add argument
    	(cmd_so_set_links_redo): handle output ttpe
    	* src/sheet-object-widget.h
    	(sheet_widget_list_base_set_result_type): new
    	(sheet_widget_list_base_result_type_is_index): new
    	* src/sheet-object-widget.c
    	(sheet_widget_list_base_set_result_type): new
    	(sheet_widget_list_base_result_type_is_index): new
    	(sheet_widget_list_base_set_selection): consider swl->result_as_index
    	(sheet_widget_list_base_set_selection_value): new
    	(sheet_widget_list_base_init): initialize swl->result_as_index
    
    2010-10-04  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* so-list.glade: add radio buttons
    	* dialog-so-list.c (cb_so_list_response): handle as-value radios
    	(so_list_init): set up as-value radios

 ChangeLog                    |   15 ++
 NEWS                         |    2 +
 src/commands.c               |   11 +-
 src/commands.h               |    3 +-
 src/dialogs/ChangeLog        |    6 +
 src/dialogs/dialog-so-list.c |    9 +-
 src/dialogs/so-list.glade    |  382 +++++++++++++++++++++---------------------
 src/sheet-object-widget.c    |   81 ++++++++-
 src/sheet-object-widget.h    |    2 +
 9 files changed, 307 insertions(+), 204 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 50697ab..d811f9a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2010-10-04  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* src/commands.h (cmd_so_set_links): add argument
+	* src/commands.c (cmd_so_set_links): add argument
+	(cmd_so_set_links_redo): handle output ttpe
+	* src/sheet-object-widget.h 
+	(sheet_widget_list_base_set_result_type): new
+	(sheet_widget_list_base_result_type_is_index): new
+	* src/sheet-object-widget.c
+	(sheet_widget_list_base_set_result_type): new
+	(sheet_widget_list_base_result_type_is_index): new
+	(sheet_widget_list_base_set_selection): consider swl->result_as_index
+	(sheet_widget_list_base_set_selection_value): new
+	(sheet_widget_list_base_init): initialize swl->result_as_index
+
+2010-10-04  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* src/sheet-object-widget.c (cb_list_model_changed): save current 
 	  selection and flag selection as saved.
 	(cb_selection_changed): don't bother if the selection was saved
diff --git a/NEWS b/NEWS
index 37944de..85e07e6 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ Andreas:
 	* Fix selection for sheet object lists and combos. [#631322]
 	* Preserve selection for sheet object lists when we change 
 	  content. [#631327]
+	* Add option to sheet object lists and combos to enter values
+	  rather than index. [#629333]
 
 --------------------------------------------------------------------------
 Gnumeric 1.10.11
diff --git a/src/commands.c b/src/commands.c
index 8679ccc..fe677ba 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -7244,6 +7244,7 @@ typedef struct {
 	SheetObject *so;
 	GnmExprTop const *output;
 	GnmExprTop const *content;
+	gboolean as_index;
 } CmdSOSetLink;
 
 MAKE_GNM_COMMAND (CmdSOSetLink, cmd_so_set_links, NULL)
@@ -7254,12 +7255,18 @@ cmd_so_set_links_redo (GnmCommand *cmd, G_GNUC_UNUSED WorkbookControl *wbc)
 	CmdSOSetLink *me = CMD_SO_SET_LINKS (cmd);
 	GnmExprTop const *old_output;
 	GnmExprTop const *old_content;
+	gboolean old_as_index;
 
 	old_content = sheet_widget_list_base_get_content_link (me->so);
 	old_output = sheet_widget_list_base_get_result_link (me->so);
+	old_as_index = sheet_widget_list_base_result_type_is_index (me->so);
 
 	sheet_widget_list_base_set_links
 		(me->so, me->output, me->content);
+	if (old_as_index != me->as_index) {
+		sheet_widget_list_base_set_result_type (me->so, me->as_index);
+		me->as_index = old_as_index;
+	}
 	if (me->output)
 		gnm_expr_top_unref (me->output);
 	if (me->content)
@@ -7292,7 +7299,8 @@ gboolean
 cmd_so_set_links (WorkbookControl *wbc,
 		  SheetObject *so,
 		  GnmExprTop const *output,
-		  GnmExprTop const *content)
+		  GnmExprTop const *content,
+		  gboolean as_index)
 {
 	CmdSOSetLink *me;
 
@@ -7305,6 +7313,7 @@ cmd_so_set_links (WorkbookControl *wbc,
 	me->so = so;
 	me->output = output;
 	me->content = content;
+	me->as_index = as_index;
 
 	return gnm_command_push_undo (wbc, G_OBJECT (me));
 }
diff --git a/src/commands.h b/src/commands.h
index d98fcd4..ce38405 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -196,7 +196,8 @@ gboolean cmd_so_set_value (WorkbookControl *wbc,
 			   Sheet *sheet);
 
 gboolean cmd_so_set_links (WorkbookControl *wbc, SheetObject *so,
-			   GnmExprTop const *output, GnmExprTop const *content);
+			   GnmExprTop const *output, GnmExprTop const *content,
+			   gboolean as_index);
 
 gboolean cmd_so_set_frame_label (WorkbookControl *wbc, SheetObject *so,
 				 char *old_label, char *new_label);
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index acc44ed..a864498 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,3 +1,9 @@
+2010-10-04  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* so-list.glade: add radio buttons
+	* dialog-so-list.c (cb_so_list_response): handle as-value radios
+	(so_list_init): set up as-value radios
+
 2010-10-01  Morten Welinder <terra gnome org>
 
 	* Release 1.10.11
diff --git a/src/dialogs/dialog-so-list.c b/src/dialogs/dialog-so-list.c
index 38602c6..667b1bc 100644
--- a/src/dialogs/dialog-so-list.c
+++ b/src/dialogs/dialog-so-list.c
@@ -44,6 +44,7 @@
 typedef struct {
 	GladeXML	*gui;
 	GtkWidget	*dialog;
+	GtkWidget	*as_index_radio;
 	GnmExprEntry	*content_entry, *link_entry;
 
 	WBCGtk	*wbcg;
@@ -99,7 +100,9 @@ cb_so_list_response (GtkWidget *dialog, gint response_id, GnmDialogSOList *state
 					       &pp, NULL, FALSE, GNM_EE_FORCE_ABS_REF);
 		content = gnm_expr_entry_parse (state->content_entry,
 						&pp, NULL, FALSE, GNM_EE_FORCE_ABS_REF);
-		cmd_so_set_links (WORKBOOK_CONTROL (state->wbcg), state->so, output, content);
+		cmd_so_set_links (WORKBOOK_CONTROL (state->wbcg), state->so, output, content,
+				  gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON 
+								(state->as_index_radio)));
 	}
 
 	gtk_object_destroy (GTK_OBJECT (dialog));
@@ -129,6 +132,10 @@ so_list_init (GnmDialogSOList *state, WBCGtk *wbcg, SheetObject *so)
 	state->link_entry = init_entry (state, "link-entry", texpr);
 	if (texpr) gnm_expr_top_unref (texpr);
 
+	state->as_index_radio = glade_xml_get_widget (state->gui, "as-index-radio");
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state->as_index_radio), 
+				      sheet_widget_list_base_result_type_is_index (so));
+
 	g_signal_connect (G_OBJECT (state->dialog), "response",
 		G_CALLBACK (cb_so_list_response), state);
 	gnumeric_init_help_button (
diff --git a/src/dialogs/so-list.glade b/src/dialogs/so-list.glade
index 13acf91..1ccd5bd 100644
--- a/src/dialogs/so-list.glade
+++ b/src/dialogs/so-list.glade
@@ -1,197 +1,189 @@
-<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
-<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd";>
-
+<?xml version="1.0"?>
 <glade-interface>
-
-<widget class="GtkDialog" id="SOList">
-  <property name="title" translatable="yes">List Properties</property>
-  <property name="type">GTK_WINDOW_TOPLEVEL</property>
-  <property name="window_position">GTK_WIN_POS_MOUSE</property>
-  <property name="modal">False</property>
-  <property name="resizable">True</property>
-  <property name="destroy_with_parent">False</property>
-  <property name="decorated">True</property>
-  <property name="skip_taskbar_hint">False</property>
-  <property name="skip_pager_hint">False</property>
-  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
-  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
-  <property name="focus_on_map">True</property>
-  <property name="urgency_hint">False</property>
-  <property name="has_separator">False</property>
-
-  <child internal-child="vbox">
-    <widget class="GtkVBox" id="dialog-vbox1">
-      <property name="visible">True</property>
-      <property name="homogeneous">False</property>
-      <property name="spacing">0</property>
-
-      <child internal-child="action_area">
-	<widget class="GtkHButtonBox" id="dialog-action_area1">
-	  <property name="visible">True</property>
-	  <property name="layout_style">GTK_BUTTONBOX_END</property>
-
-	  <child>
-	    <widget class="GtkButton" id="help">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-help</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="focus_on_click">True</property>
-	      <property name="response_id">-11</property>
-	    </widget>
-	  </child>
-
-	  <child>
-	    <widget class="GtkButton" id="cancel">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-cancel</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="focus_on_click">True</property>
-	      <property name="response_id">-6</property>
-	    </widget>
-	  </child>
-
-	  <child>
-	    <widget class="GtkButton" id="ok">
-	      <property name="visible">True</property>
-	      <property name="can_default">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="label">gtk-ok</property>
-	      <property name="use_stock">True</property>
-	      <property name="relief">GTK_RELIEF_NORMAL</property>
-	      <property name="focus_on_click">True</property>
-	      <property name="response_id">-5</property>
-	    </widget>
-	  </child>
-	</widget>
-	<packing>
-	  <property name="padding">0</property>
-	  <property name="expand">False</property>
-	  <property name="fill">True</property>
-	  <property name="pack_type">GTK_PACK_END</property>
-	</packing>
-      </child>
-
-      <child>
-	<widget class="GtkTable" id="table">
-	  <property name="border_width">12</property>
-	  <property name="visible">True</property>
-	  <property name="n_rows">2</property>
-	  <property name="n_columns">2</property>
-	  <property name="homogeneous">False</property>
-	  <property name="row_spacing">12</property>
-	  <property name="column_spacing">12</property>
-
-	  <child>
-	    <widget class="GtkLabel" id="link-label">
-	      <property name="visible">True</property>
-	      <property name="label" translatable="yes">_Link :</property>
-	      <property name="use_underline">True</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>
-	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-	      <property name="width_chars">-1</property>
-	      <property name="single_line_mode">False</property>
-	      <property name="angle">0</property>
-	      <accessibility>
-		<atkrelation target="link-entry" type="label-for"/>
-	      </accessibility>
-	    </widget>
-	    <packing>
-	      <property name="left_attach">0</property>
-	      <property name="right_attach">1</property>
-	      <property name="top_attach">0</property>
-	      <property name="bottom_attach">1</property>
-	      <property name="x_options">fill</property>
-	      <property name="y_options"></property>
-	    </packing>
-	  </child>
-
-	  <child>
-	    <widget class="GtkLabel" id="content-label">
-	      <property name="visible">True</property>
-	      <property name="label" translatable="yes">_Content :</property>
-	      <property name="use_underline">True</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>
-	      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-	      <property name="width_chars">-1</property>
-	      <property name="single_line_mode">False</property>
-	      <property name="angle">0</property>
-	      <accessibility>
-		<atkrelation target="content-entry" type="label-for"/>
-	      </accessibility>
-	    </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="Custom" id="link-entry">
-	      <property name="visible">True</property>
-	      <property name="creation_function">gnm_expr_entry_new_glade</property>
-	      <accessibility>
-		<atkrelation target="link-label" type="labelled-by"/>
-	      </accessibility>
-	    </widget>
-	    <packing>
-	      <property name="left_attach">1</property>
-	      <property name="right_attach">2</property>
-	      <property name="top_attach">0</property>
-	      <property name="bottom_attach">1</property>
-	      <property name="y_options">fill</property>
-	    </packing>
-	  </child>
-
-	  <child>
-	    <widget class="Custom" id="content-entry">
-	      <property name="visible">True</property>
-	      <property name="creation_function">gnm_expr_entry_new_glade</property>
-	      <accessibility>
-		<atkrelation target="content-label" type="labelled-by"/>
-	      </accessibility>
-	    </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>
-	  <property name="expand">True</property>
-	  <property name="fill">True</property>
-	</packing>
-      </child>
-    </widget>
-  </child>
-</widget>
-
+  <!-- interface-requires gtk+ 2.6 -->
+  <!-- interface-naming-policy toplevel-contextual -->
+  <widget class="GtkDialog" id="SOList">
+    <property name="title" translatable="yes">List Properties</property>
+    <property name="window_position">mouse</property>
+    <property name="type_hint">dialog</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <child>
+          <widget class="GtkTable" id="table">
+            <property name="visible">True</property>
+            <property name="border_width">12</property>
+            <property name="n_rows">5</property>
+            <property name="n_columns">2</property>
+            <property name="column_spacing">12</property>
+            <child>
+              <widget class="GtkLabel" id="link-label">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">_Link :</property>
+                <property name="use_underline">True</property>
+                <accessibility>
+                  <atkrelation type="label-for" target="link-entry"/>
+                </accessibility>
+              </widget>
+              <packing>
+                <property name="x_options">GTK_FILL</property>
+                <property name="y_options"></property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkLabel" id="content-label">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">_Content :</property>
+                <property name="use_underline">True</property>
+                <accessibility>
+                  <atkrelation type="label-for" target="content-entry"/>
+                </accessibility>
+              </widget>
+              <packing>
+                <property name="top_attach">4</property>
+                <property name="bottom_attach">5</property>
+                <property name="x_options">GTK_FILL</property>
+                <property name="y_options"></property>
+              </packing>
+            </child>
+            <child>
+              <widget class="Custom" id="link-entry">
+                <property name="visible">True</property>
+                <property name="creation_function">gnm_expr_entry_new_glade</property>
+                <accessibility>
+                  <atkrelation type="labelled-by" target="link-label"/>
+                </accessibility>
+              </widget>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="y_options">GTK_FILL</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="Custom" id="content-entry">
+                <property name="visible">True</property>
+                <property name="creation_function">gnm_expr_entry_new_glade</property>
+                <accessibility>
+                  <atkrelation type="labelled-by" target="content-label"/>
+                </accessibility>
+              </widget>
+              <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="x_options">GTK_FILL</property>
+                <property name="y_options">GTK_FILL</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkRadioButton" id="as-value-radio">
+                <property name="label" translatable="yes">As value</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+              </widget>
+              <packing>
+                <property name="right_attach">2</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+                <property name="y_options">GTK_SHRINK | GTK_FILL</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkRadioButton" id="as-index-radio">
+                <property name="label" translatable="yes">As index</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="active">True</property>
+                <property name="draw_indicator">True</property>
+                <property name="group">as-value-radio</property>
+              </widget>
+              <packing>
+                <property name="right_attach">2</property>
+                <property name="top_attach">2</property>
+                <property name="bottom_attach">3</property>
+                <property name="y_options">GTK_SHRINK | GTK_FILL</property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <widget class="GtkButton" id="help">
+                <property name="label">gtk-help</property>
+                <property name="response_id">-11</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkButton" id="cancel">
+                <property name="label">gtk-cancel</property>
+                <property name="response_id">-6</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkButton" id="ok">
+                <property name="label">gtk-ok</property>
+                <property name="response_id">-5</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
 </glade-interface>
diff --git a/src/sheet-object-widget.c b/src/sheet-object-widget.c
index c25d6c7..1c6fd70 100644
--- a/src/sheet-object-widget.c
+++ b/src/sheet-object-widget.c
@@ -3254,6 +3254,7 @@ typedef struct {
 
 	GtkTreeModel	*model;
 	int		 selection;
+	gboolean        result_as_index;
 } SheetWidgetListBase;
 typedef struct {
 	SheetObjectWidgetClass base;
@@ -3287,12 +3288,52 @@ sheet_widget_list_base_set_selection (SheetWidgetListBase *swl, int selection,
 	if (swl->selection != selection) {
 		swl->selection = selection;
 		if (NULL!= wbc &&
-		    so_get_ref (SHEET_OBJECT (swl), &ref, TRUE) != NULL)
-			cmd_so_set_value (wbc,
-				_("Clicking in list"),
-					  &ref, value_new_int (swl->selection),
+		    so_get_ref (SHEET_OBJECT (swl), &ref, TRUE) != NULL) {
+			GnmValue *v;
+			if (swl->result_as_index)
+				v = value_new_int (swl->selection);
+			else if (selection != 0) {
+				GtkTreeIter iter;
+				char *content;
+				gtk_tree_model_iter_nth_child 
+					(swl->model, &iter, NULL, selection - 1);
+				gtk_tree_model_get (swl->model, &iter,
+						    0, &content, -1);
+				v = value_new_string_nocopy (content);
+			} else
+				v = value_new_string ("");
+			cmd_so_set_value (wbc, _("Clicking in list"), &ref, v,
 					  sheet_object_get_sheet (SHEET_OBJECT (swl)));
+		}
+		g_signal_emit (G_OBJECT (swl),
+			list_base_signals [LIST_BASE_SELECTION_CHANGED], 0);
+	}
+}
+
+static void
+sheet_widget_list_base_set_selection_value (SheetWidgetListBase *swl, GnmValue *v)
+{
+	char const *str = value_get_as_string (v);
+	GtkTreeIter iter;
+	int selection = 0, i = 1;
+
+	if (swl->model != NULL && gtk_tree_model_get_iter_first (swl->model, &iter))
+		do {
+			char *content;
+			gboolean match;
+			gtk_tree_model_get (swl->model, &iter,
+					    0, &content, -1);
+			match = 0 == g_ascii_strcasecmp (str, content);
+			g_free (content);
+			if (match) {
+				selection = i;
+				break;
+			}
+			i++;
+		} while (gtk_tree_model_iter_next (swl->model, &iter));
 
+	if (swl->selection != selection) {
+		swl->selection = selection;
 		g_signal_emit (G_OBJECT (swl),
 			list_base_signals [LIST_BASE_SELECTION_CHANGED], 0);
 	}
@@ -3305,8 +3346,13 @@ list_output_eval (GnmDependent *dep)
 	GnmValue *v = gnm_expr_top_eval (dep->texpr,
 		eval_pos_init_dep (&pos, dep),
 		GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
-	sheet_widget_list_base_set_selection (DEP_TO_LIST_BASE_OUTPUT (dep),
-		floor (value_get_as_float (v)), NULL);
+	SheetWidgetListBase *swl = DEP_TO_LIST_BASE_OUTPUT (dep);
+	
+	if (swl->result_as_index)
+		sheet_widget_list_base_set_selection 
+			(swl, floor (value_get_as_float (v)), NULL);
+	else
+		sheet_widget_list_base_set_selection_value (swl, v);
 	value_release (v);
 }
 
@@ -3391,6 +3437,7 @@ sheet_widget_list_base_init (SheetObjectWidget *sow)
 
 	swl->model = NULL;
 	swl->selection = 0;
+	swl->result_as_index = TRUE;
 }
 
 static void
@@ -3441,6 +3488,7 @@ sheet_widget_list_base_write_xml_sax (SheetObject const *so, GsfXMLOut *output,
 	SheetWidgetListBase const *swl = SHEET_WIDGET_LIST_BASE (so);
 	sax_write_dep (output, &swl->content_dep, "Content", convs);
 	sax_write_dep (output, &swl->output_dep, "Output", convs);
+	gsf_xml_out_add_int (output, "OutputAsIndex", swl->result_as_index ? 1 : 0);
 }
 
 static void
@@ -3453,6 +3501,7 @@ sheet_widget_list_base_prep_sax_parser (SheetObject *so, GsfXMLIn *xin,
 	for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2)
 		if (sax_read_dep (attrs, "Content", &swl->content_dep, xin, convs)) ;
 		else if (sax_read_dep (attrs, "Output", &swl->output_dep, xin, convs)) ;
+		else if (gnm_xml_attr_bool (attrs, "OutputAsIndex", &swl->result_as_index));
 }
 
 static GtkWidget *
@@ -3529,6 +3578,26 @@ sheet_widget_list_base_get_content_link (SheetObject const *so)
  	return texpr;
 }
 
+gboolean 
+sheet_widget_list_base_result_type_is_index (SheetObject const *so)
+{
+	SheetWidgetListBase *swl = SHEET_WIDGET_LIST_BASE (so);
+
+	return swl->result_as_index;
+}
+
+void  
+sheet_widget_list_base_set_result_type (SheetObject *so, gboolean as_index)
+{
+	SheetWidgetListBase *swl = SHEET_WIDGET_LIST_BASE (so);
+
+	if (swl->result_as_index == as_index)
+		return;
+
+	swl->result_as_index = as_index;
+	
+}
+
 /* Note: allocates a new adjustment.  */
 GtkAdjustment *
 sheet_widget_list_base_get_adjustment (SheetObject *so)
diff --git a/src/sheet-object-widget.h b/src/sheet-object-widget.h
index b5d5d64..8f7343f 100644
--- a/src/sheet-object-widget.h
+++ b/src/sheet-object-widget.h
@@ -84,7 +84,9 @@ void sheet_widget_frame_set_label        (SheetObject *so, char const *str);
 void  sheet_widget_list_base_set_links	 (SheetObject *so,
 					  GnmExprTop const *result_link,
 					  GnmExprTop const *content);
+void  sheet_widget_list_base_set_result_type (SheetObject *so, gboolean as_index);
 GnmExprTop const *sheet_widget_list_base_get_result_link (SheetObject const *so);
+gboolean sheet_widget_list_base_result_type_is_index (SheetObject const *so);
 GnmExprTop const *sheet_widget_list_base_get_content_link (SheetObject const *so);
 GtkAdjustment *sheet_widget_list_base_get_adjustment (SheetObject *so);
 



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