[gnumeric] Support conditional font styles



commit e4bf891a77f26e741b07fe74a4b4938e71959a70
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu Jul 7 18:58:44 2011 -0600

    Support conditional font styles
    
    2011-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/rendered-value.c (gnm_rendered_value_new): consider conditional
    	styles
    	* src/style.c (gnm_style_required_spanflags): consider conditional
    	styles
    
    2011-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* cell-format-cond-def.ui: enable font and background checkbox
    	* dialog-cell-format-cond.c (cb_c_fmt_dialog_chooser_check_page): new
    	(cb_c_fmt_dialog_chooser_new_button): check checkboxes
    	(cb_c_fmt_dialog_chooser_buttons): handle font items

 ChangeLog                             |    7 +++
 NEWS                                  |    2 +-
 src/dialogs/ChangeLog                 |    7 +++
 src/dialogs/cell-format-cond-def.ui   |   22 ++++-----
 src/dialogs/dialog-cell-format-cond.c |   84 ++++++++++++++++++++++++++++++---
 src/rendered-value.c                  |   12 +++++
 src/style.c                           |   52 ++++++++++++---------
 7 files changed, 144 insertions(+), 42 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 90fc880..90dc368 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* src/rendered-value.c (gnm_rendered_value_new): consider conditional
+	styles
+	* src/style.c (gnm_style_required_spanflags): consider conditional
+	styles
+
+2011-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* src/style-conditions.c (gnm_style_conditions_eval): fix the sense
 	of the comparison (the value string is expected to be smaller than
 	the cell string) and avoid infinite loops.
diff --git a/NEWS b/NEWS
index d93cede..740fe45 100644
--- a/NEWS
+++ b/NEWS
@@ -7,7 +7,7 @@ Andreas:
 	* Fix xlsx schema violations.
 	* Fix keyword handling in properties dialog. [#653378]
 	* Allow document properties to be edited and added.
-	* Add an interface for conditional background formatting.
+	* Add an interface for conditional formatting.
 
 Morten:
 	* Fix --with-gnome compilation:  [#652802]
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 2c2d635..7ed3ae8 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,5 +1,12 @@
 2011-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* cell-format-cond-def.ui: enable font and background checkbox
+	* dialog-cell-format-cond.c (cb_c_fmt_dialog_chooser_check_page): new
+	(cb_c_fmt_dialog_chooser_new_button): check checkboxes
+	(cb_c_fmt_dialog_chooser_buttons): handle font items
+	
+2011-07-07  Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* dialog-cell-format-cond.c (c_fmt_dialog_set_sensitive): fix parse
 	position
 	(cb_c_fmt_dialog_chooser_buttons): ditto
diff --git a/src/dialogs/cell-format-cond-def.ui b/src/dialogs/cell-format-cond-def.ui
index 158645b..88e8120 100644
--- a/src/dialogs/cell-format-cond-def.ui
+++ b/src/dialogs/cell-format-cond-def.ui
@@ -58,15 +58,6 @@
               </packing>
             </child>
             <child>
-              <placeholder/>
-            </child>
-            <child>
-              <placeholder/>
-            </child>
-            <child>
-              <placeholder/>
-            </child>
-            <child>
               <object class="GtkLabel" id="label4">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
@@ -94,6 +85,15 @@
                 <property name="y_options">GTK_SHRINK | GTK_FILL</property>
               </packing>
             </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
           </object>
           <packing>
             <property name="expand">True</property>
@@ -155,7 +155,6 @@
               <object class="GtkCheckButton" id="check-font">
                 <property name="label" translatable="yes">Font</property>
                 <property name="visible">True</property>
-                <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
                 <property name="use_action_appearance">False</property>
@@ -167,10 +166,9 @@
               </packing>
             </child>
             <child>
-              <object class="GtkCheckButton" id="checkbutton4">
+              <object class="GtkCheckButton" id="check-background">
                 <property name="label" translatable="yes">Background</property>
                 <property name="visible">True</property>
-                <property name="sensitive">False</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
                 <property name="use_action_appearance">False</property>
diff --git a/src/dialogs/dialog-cell-format-cond.c b/src/dialogs/dialog-cell-format-cond.c
index 90360c6..ce237de 100644
--- a/src/dialogs/dialog-cell-format-cond.c
+++ b/src/dialogs/dialog-cell-format-cond.c
@@ -207,10 +207,38 @@ dialog_cell_format_style_added (gpointer closure, GnmStyle *style)
 	c_fmt_dialog_set_sensitive (state);
 }
 
+static gint
+cb_c_fmt_dialog_chooser_check_page (CFormatChooseState *state, gchar const *name,
+				    gint page)
+{
+	GtkWidget *w = go_gtk_builder_get_widget (state->gui, name);
+	
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)))
+		return (1 << page);
+	else
+		return 0;
+}
+
 static void
 cb_c_fmt_dialog_chooser_new_button (G_GNUC_UNUSED GtkWidget *btn, CFormatChooseState *state)
 {
-	dialog_cell_format_select_style (state->cf_state->wbcg, 1 << FD_BACKGROUND, 
+	int pages = 0;
+	pages |= cb_c_fmt_dialog_chooser_check_page 
+		(state, "check-background", FD_BACKGROUND);
+	pages |= cb_c_fmt_dialog_chooser_check_page 
+		(state, "check-number", FD_NUMBER);
+	pages |= cb_c_fmt_dialog_chooser_check_page 
+		(state, "check-align", FD_ALIGNMENT);
+	pages |= cb_c_fmt_dialog_chooser_check_page 
+		(state, "check-font", FD_FONT);
+	pages |= cb_c_fmt_dialog_chooser_check_page 
+		(state, "check-border", FD_BORDER);
+	pages |= cb_c_fmt_dialog_chooser_check_page 
+		(state, "check-protection", FD_PROTECTION);
+	pages |= cb_c_fmt_dialog_chooser_check_page 
+		(state, "check-validation", FD_VALIDATION);
+
+	dialog_cell_format_select_style (state->cf_state->wbcg, pages, 
 					 GTK_WINDOW (state->dialog), state);
 }
 
@@ -227,12 +255,54 @@ cb_c_fmt_dialog_chooser_buttons (GtkWidget *btn, CFormatChooseState *state)
 
 		cond->overlay = gnm_style_new ();
 		if (state->style) {
-			gnm_style_merge_element (cond->overlay, state->style, 
-						 MSTYLE_COLOR_BACK);
-			gnm_style_merge_element (cond->overlay, state->style, 
-						 MSTYLE_COLOR_PATTERN);
-			gnm_style_merge_element (cond->overlay, state->style, 
-						 MSTYLE_PATTERN);
+			if (cb_c_fmt_dialog_chooser_check_page 
+			    (state, "check-background", FD_BACKGROUND)) {
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_COLOR_BACK);
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_COLOR_PATTERN);
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_PATTERN);
+			}
+			if (cb_c_fmt_dialog_chooser_check_page 
+			    (state, "check-number", FD_NUMBER)) {
+
+			}
+			if (cb_c_fmt_dialog_chooser_check_page 
+			    (state, "check-align", FD_ALIGNMENT)) {
+
+			}
+			if (cb_c_fmt_dialog_chooser_check_page 
+			    (state, "check-font", FD_FONT)) {
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_FONT_COLOR);
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_FONT_NAME);
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_FONT_BOLD);
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_FONT_ITALIC);
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_FONT_UNDERLINE);
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_FONT_STRIKETHROUGH);
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_FONT_SCRIPT);
+				gnm_style_merge_element (cond->overlay, state->style, 
+							 MSTYLE_FONT_SIZE);
+			}
+			if (cb_c_fmt_dialog_chooser_check_page 
+			     (state, "check-border", FD_BORDER)) {
+
+			}
+			if (cb_c_fmt_dialog_chooser_check_page 
+			    (state, "check-protection", FD_PROTECTION)) {
+
+			}
+			if (cb_c_fmt_dialog_chooser_check_page 
+			    (state, "check-validation", FD_VALIDATION)) {
+
+			}
 		}
 		if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (state->combo), &iter))
 			gtk_tree_model_get (GTK_TREE_MODEL (state->typestore),
diff --git a/src/rendered-value.c b/src/rendered-value.c
index d94a513..aa53db0 100644
--- a/src/rendered-value.c
+++ b/src/rendered-value.c
@@ -32,6 +32,8 @@
 #include "style-color.h"
 #include "style-font.h"
 #include "style-border.h"
+#include "style-conditions.h"
+#include "gnm-style-impl.h"
 #include "sheet.h"
 #include "sheet-merge.h"
 #include "gnm-format.h"
@@ -206,6 +208,16 @@ gnm_rendered_value_new (GnmCell const *cell,
 	g_return_val_if_fail (cell->value != NULL, NULL);
 
 	mstyle = gnm_cell_get_style (cell);
+
+	if (mstyle->conditions) {
+		GnmEvalPos ep;
+		int res;
+		eval_pos_init_cell (&ep, cell);
+		if ((res = gnm_style_conditions_eval (mstyle->conditions, &ep)) >= 0)
+			mstyle = g_ptr_array_index (mstyle->cond_styles, res);
+	}
+
+
 	rotation = gnm_style_get_rotation (mstyle);
 	if (rotation) {
 		static PangoMatrix const id = PANGO_MATRIX_INIT;
diff --git a/src/style.c b/src/style.c
index 943612f..321e2f9 100644
--- a/src/style.c
+++ b/src/style.c
@@ -11,6 +11,7 @@
 #include "gnumeric.h"
 #include "style.h"
 #include "style-font.h"
+#include "gnm-style-impl.h"
 
 #include "gnm-format.h"
 #include "style-color.h"
@@ -479,28 +480,35 @@ gnm_style_required_spanflags (GnmStyle const *style)
 {
 	GnmSpanCalcFlags res = GNM_SPANCALC_SIMPLE;
 
-	gboolean const row_height =
-		gnm_style_is_element_set (style, MSTYLE_FONT_SIZE) ||
-		gnm_style_is_element_set (style, MSTYLE_WRAP_TEXT) ||
-		gnm_style_is_element_set (style, MSTYLE_ROTATION) ||
-		gnm_style_is_element_set (style, MSTYLE_FONT_SCRIPT);
-	gboolean const size_change = row_height ||
-		gnm_style_is_element_set (style, MSTYLE_FONT_NAME) ||
-		gnm_style_is_element_set (style, MSTYLE_FONT_BOLD) ||
-		gnm_style_is_element_set (style, MSTYLE_FONT_ITALIC);
-	gboolean const format_change =
-		gnm_style_is_element_set (style, MSTYLE_FORMAT) ||
-		gnm_style_is_element_set (style, MSTYLE_INDENT) ||
-		gnm_style_is_element_set (style, MSTYLE_ALIGN_H) ||
-		gnm_style_is_element_set (style, MSTYLE_ALIGN_V) ||
-		gnm_style_is_element_set (style, MSTYLE_FONT_STRIKETHROUGH) ||
-		gnm_style_is_element_set (style, MSTYLE_FONT_UNDERLINE) ||
-		gnm_style_is_element_set (style, MSTYLE_FONT_COLOR);
-
-	if (row_height)
-		res |= GNM_SPANCALC_ROW_HEIGHT;
-	if (format_change || size_change)
-		res |= GNM_SPANCALC_RE_RENDER | GNM_SPANCALC_RESIZE;
+	if (gnm_style_is_element_set (style, MSTYLE_CONDITIONS))
+		/* Note that style->cond_styles may not be set yet */
+		/* More importantly, even if the conditions are empty we */
+		/* have to rerender everything since we do not know what changed. */
+		res |= GNM_SPANCALC_RE_RENDER | GNM_SPANCALC_RESIZE | GNM_SPANCALC_ROW_HEIGHT;
+	else {
+		gboolean const row_height =
+			gnm_style_is_element_set (style, MSTYLE_FONT_SIZE) ||
+			gnm_style_is_element_set (style, MSTYLE_WRAP_TEXT) ||
+			gnm_style_is_element_set (style, MSTYLE_ROTATION) ||
+			gnm_style_is_element_set (style, MSTYLE_FONT_SCRIPT);
+		gboolean const size_change = row_height ||
+			gnm_style_is_element_set (style, MSTYLE_FONT_NAME) ||
+			gnm_style_is_element_set (style, MSTYLE_FONT_BOLD) ||
+			gnm_style_is_element_set (style, MSTYLE_FONT_ITALIC);
+		gboolean const format_change =
+			gnm_style_is_element_set (style, MSTYLE_FORMAT) ||
+			gnm_style_is_element_set (style, MSTYLE_INDENT) ||
+			gnm_style_is_element_set (style, MSTYLE_ALIGN_H) ||
+			gnm_style_is_element_set (style, MSTYLE_ALIGN_V) ||
+			gnm_style_is_element_set (style, MSTYLE_FONT_STRIKETHROUGH) ||
+			gnm_style_is_element_set (style, MSTYLE_FONT_UNDERLINE) ||
+			gnm_style_is_element_set (style, MSTYLE_FONT_COLOR);
+
+		if (row_height)
+			res |= GNM_SPANCALC_ROW_HEIGHT;
+		if (format_change || size_change)
+			res |= GNM_SPANCALC_RE_RENDER | GNM_SPANCALC_RESIZE;
+	}
 	return res;
 }
 



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