[gnumeric] dao: autofit improvements.



commit 9bf3f4d92621399087f2e04894da7a2921cbad49
Author: Morten Welinder <terra gnome org>
Date:   Wed Feb 10 21:22:50 2016 -0500

    dao: autofit improvements.
    
    Use general colrow code for the fitting and avoid shrinking any columns.

 src/tools/ChangeLog |    6 ++++
 src/tools/dao.c     |   73 +++++++++++++++++++++++++--------------------------
 src/tools/dao.h     |    8 ++++-
 3 files changed, 48 insertions(+), 39 deletions(-)
---
diff --git a/src/tools/ChangeLog b/src/tools/ChangeLog
index 8066b72..4dc1b6a 100644
--- a/src/tools/ChangeLog
+++ b/src/tools/ChangeLog
@@ -1,3 +1,9 @@
+2016-02-10  Morten Welinder  <terra gnome org>
+
+       * dao.c (dao_autofit_rows): New function.
+       (dao_autofit_these_columns): Simply use colrow_autofit.  Don't
+       shrink any columns.
+
 2016-02-06  Morten Welinder <terra gnome org>
 
        * Release 1.12.27
diff --git a/src/tools/dao.c b/src/tools/dao.c
index 7e45cee..c468cbe 100644
--- a/src/tools/dao.c
+++ b/src/tools/dao.c
@@ -81,6 +81,7 @@ dao_init (data_analysis_output_t *dao,
        dao->rows              = 1;
        dao->sheet             = NULL;
        dao->autofit_flag      = TRUE;
+       dao->autofit_noshrink  = TRUE;
        dao->clear_outputrange = TRUE;
        dao->retain_format     = FALSE;
        dao->retain_comments   = FALSE;
@@ -622,61 +623,35 @@ dao_set_cell_comment (data_analysis_output_t *dao, int col, int row,
 
 
 /**
- * autofit_column:
- * @dao:
- * @col:
- *
- * fits a column to the content
- *
- *
- **/
-static void
-dao_autofit_column (data_analysis_output_t *dao, int col)
-{
-        int ideal_size, actual_col;
-
-       actual_col = dao->start_col + col;
-
-       ideal_size = sheet_col_size_fit_pixels (dao->sheet, actual_col,
-                                               0, gnm_sheet_get_last_row (dao->sheet),
-                                               FALSE);
-       if (ideal_size == 0)
-               return;
-
-       sheet_col_set_size_pixels (dao->sheet, actual_col, ideal_size, TRUE);
-       sheet_recompute_spans_for_col (dao->sheet, col);
-}
-
-/**
  * dao_autofit_these_columns:
  * @dao:
  * @from_col:
  * @to_col:
  *
- * fits all columns to their content
- *
- *
+ * Fits the specified columns to their content
  **/
 void
 dao_autofit_these_columns (data_analysis_output_t *dao, int from_col, int to_col)
 {
-       int i;
+       GnmRange r;
 
        if (!dao->autofit_flag)
                return;
-       for (i = from_col; i <= to_col; i++)
-               dao_autofit_column (dao,i);
+
+       range_init_cols (&r, dao->sheet,
+                        from_col + dao->start_col,
+                        to_col + dao->start_col);
+
+       colrow_autofit (dao->sheet, &r, TRUE,
+                       FALSE, dao->autofit_noshrink, FALSE,
+                       NULL, NULL);
 }
 
 /**
- * autofit_columns:
+ * dao_autofit_columns:
  * @dao:
- * @from:
- * @to:
  *
  * fits all columns to their content
- *
- *
  **/
 void
 dao_autofit_columns (data_analysis_output_t *dao)
@@ -684,6 +659,30 @@ dao_autofit_columns (data_analysis_output_t *dao)
        dao_autofit_these_columns (dao, 0, dao->cols - 1);
 }
 
+void
+dao_autofit_these_rows (data_analysis_output_t *dao, int from_row, int to_row)
+{
+       GnmRange r;
+
+       if (!dao->autofit_flag)
+               return;
+
+       range_init_rows (&r, dao->sheet,
+                        from_row + dao->start_row,
+                        to_row + dao->start_row);
+
+       colrow_autofit (dao->sheet, &r, FALSE,
+                       FALSE, dao->autofit_noshrink, FALSE,
+                       NULL, NULL);
+}
+
+void
+dao_autofit_rows (data_analysis_output_t *dao)
+{
+       dao_autofit_these_rows (dao, 0, dao->rows - 1);
+}
+
+
 /**
  * dao_set_style:
  * @dao:
diff --git a/src/tools/dao.h b/src/tools/dao.h
index 781aab3..edb9438 100644
--- a/src/tools/dao.h
+++ b/src/tools/dao.h
@@ -47,6 +47,7 @@ typedef struct {
         int                         start_row, rows;
        int                         offset_col, offset_row;
        gboolean                    autofit_flag;
+       gboolean                    autofit_noshrink;
        gboolean                    clear_outputrange;
        gboolean                    retain_format;
        gboolean                    retain_comments;
@@ -65,8 +66,11 @@ data_analysis_output_t *dao_load_from_value (data_analysis_output_t *dao,
 void dao_free (data_analysis_output_t *dao);
 
 void dao_autofit_columns      (data_analysis_output_t *dao);
-void dao_autofit_these_columns (data_analysis_output_t *dao, int from_col,
-                               int to_col);
+void dao_autofit_these_columns (data_analysis_output_t *dao, int from_col, int to_col);
+
+void dao_autofit_rows      (data_analysis_output_t *dao);
+void dao_autofit_these_rows (data_analysis_output_t *dao, int from_row, int to_row);
+
 gboolean dao_cell_is_visible      (data_analysis_output_t *dao, int col, int row);
 void dao_set_bold             (data_analysis_output_t *dao, int col1, int row1,
                               int col2, int row2);


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