1 #ifndef _GNM_COLROW_H_ 2 # define _GNM_COLROW_H_ 3 4 #include <gnumeric.h> 5 6 G_BEGIN_DECLS 7 8 struct _ColRowInfo { 9 /* Size including margins, and right grid line */ 10 double size_pts; 11 int size_pixels; 12 13 unsigned is_default : 1; 14 unsigned outline_level : 4; 15 unsigned is_collapsed : 1; /* Does this terminate an outline ? */ 16 unsigned hard_size : 1; /* are dimensions explicitly set ? */ 17 unsigned visible : 1; /* visible */ 18 unsigned in_filter : 1; /* in a filter */ 19 unsigned in_advanced_filter : 1; /* in an advanced filter */ 20 unsigned needs_respan : 1; /* mark a row as needing span generation */ 21 22 /* TODO : Add per row/col min/max */ 23 24 gpointer spans; /* Only used for rows */ 25 }; 26 GType col_row_info_get_type (void); 27 28 /* We never did get around to support 'thick' borders so these are effectively 29 * unitless (margins do not scale) constants . */ 30 #define GNM_COL_MARGIN 2 31 #define GNM_ROW_MARGIN 0 32 33 /* The size, mask, and shift must be kept in sync */ 34 #define COLROW_SEGMENT_SIZE 0x80 35 #define COLROW_SUB_INDEX(i) ((i) & 0x7f) 36 #define COLROW_SEGMENT_START(i) ((i) & ~(0x7f)) 37 #define COLROW_SEGMENT_END(i) ((i) | 0x7f) 38 #define COLROW_SEGMENT_INDEX(i) ((i) >> 7) 39 #define COLROW_GET_SEGMENT(seg_array, i) \ 40 (g_ptr_array_index ((seg_array)->info, COLROW_SEGMENT_INDEX(i))) 41 42 struct _ColRowSegment { 43 ColRowInfo *info [COLROW_SEGMENT_SIZE]; 44 double size_pts; 45 int size_pixels; 46 }; 47 typedef struct _ColRowState { 48 double size_pts; 49 unsigned is_default : 1; 50 unsigned outline_level : 4; 51 unsigned is_collapsed : 1; /* Does this terminate an outline ? */ 52 unsigned hard_size : 1; /* are dimensions explicitly set ? */ 53 unsigned visible : 1; /* visible */ 54 } ColRowState; 55 56 typedef struct { 57 int length; 58 ColRowState state; 59 } ColRowRLEState; 60 61 #define COL_INTERNAL_WIDTH(col) \ 62 ((col)->size_pixels - (GNM_COL_MARGIN + GNM_COL_MARGIN + 1)) 63 64 double colrow_compute_pixel_scale (Sheet const *sheet, gboolean horizontal); 65 void colrow_compute_pixels_from_pts (ColRowInfo *cri, Sheet const *sheet, 66 gboolean horizontal, double scale); 67 void colrow_compute_pts_from_pixels (ColRowInfo *cri, Sheet const *sheet, 68 gboolean horizontal, double scale); 69 70 gboolean col_row_info_is_default (ColRowInfo const *cri); 71 gboolean col_row_info_is_empty (ColRowInfo const *cri); 72 gboolean col_row_info_equal (ColRowInfo const *a, ColRowInfo const *b); 73 void col_row_info_copy (ColRowInfo *dst, ColRowInfo const *src); 74 ColRowInfo *col_row_info_new (void); 75 void colrow_free (ColRowInfo *cri); 76 77 typedef struct { 78 int pos; 79 ColRowInfo const *cri; 80 } GnmColRowIter; 81 82 typedef gboolean (*ColRowHandler)(GnmColRowIter const *iter, gpointer user_data); 83 #define colrow_index_list_destroy(l) g_list_free_full ((l), g_free) 84 85 GString *colrow_index_list_to_string (ColRowIndexList *list, 86 gboolean is_cols, 87 gboolean *is_single); 88 ColRowIndexList *colrow_get_index_list (int first, int last, 89 ColRowIndexList *list); 90 ColRowIndexList *colrow_index_list_copy (ColRowIndexList *list); 91 92 ColRowStateList *colrow_state_list_destroy (ColRowStateList *list); 93 94 ColRowStateList *colrow_get_states (Sheet *sheet, gboolean is_cols, 95 int first, int last); 96 void colrow_set_states (Sheet *sheet, gboolean is_cols, 97 int first, ColRowStateList *states); 98 gboolean colrow_state_list_foreach (ColRowStateList *list, 99 Sheet const *sheet, 100 gboolean is_cols, 101 int base, 102 ColRowHandler callback, 103 gpointer user_data); 104 105 ColRowStateGroup *colrow_state_group_destroy (ColRowStateGroup *set); 106 ColRowStateGroup *colrow_set_sizes (Sheet *sheet, gboolean is_cols, 107 ColRowIndexList *src, int new_size, 108 int from, int to); 109 ColRowStateGroup *colrow_get_sizes (Sheet *sheet, gboolean is_cols, 110 ColRowIndexList *src, int new_size); 111 void colrow_restore_state_group (Sheet *sheet, gboolean is_cols, 112 ColRowIndexList *selection, 113 ColRowStateGroup *state_groups); 114 115 /* Support for Col/Row visibility */ 116 void col_row_info_set_outline (ColRowInfo *cri, int outline_level, 117 gboolean is_collapsed); 118 int colrow_find_outline_bound (Sheet const *sheet, gboolean is_cols, 119 int index, int depth, gboolean inc); 120 ColRowVisList *colrow_get_outline_toggle (Sheet const *sheet, gboolean is_cols, 121 gboolean visible, int first, int last); 122 ColRowVisList *colrow_get_visibility_toggle (SheetView *sv, gboolean is_cols, 123 gboolean visible); 124 void colrow_set_visibility (Sheet *sheet, gboolean is_cols, 125 gboolean visible, int first, int last); 126 void colrow_get_global_outline (Sheet const *sheet, gboolean is_cols, int depth, 127 ColRowVisList **show, ColRowVisList **hide); 128 129 #define colrow_vis_list_destroy(l) g_slist_free_full ((l), g_free) 130 gint colrow_vis_list_length (ColRowVisList *list); 131 void colrow_set_visibility_list (Sheet *sheet, gboolean is_cols, 132 gboolean visible, 133 ColRowVisList *list); 134 135 /* Misc */ 136 #define colrow_max(is_cols,sheet) ((is_cols) ? gnm_sheet_get_max_cols (sheet) : gnm_sheet_get_max_rows (sheet)) 137 void rows_height_update (Sheet *sheet, GnmRange const *range, 138 gboolean shrink); 139 140 void colrow_autofit (Sheet *sheet, 141 GnmRange const *r, 142 gboolean is_cols, 143 gboolean ignore_strings, 144 gboolean min_current, 145 gboolean min_default, 146 ColRowIndexList **indices, 147 ColRowStateList **sizes); 148 void colrow_autofit_col (Sheet *sheet, GnmRange *r); 149 void colrow_autofit_row (Sheet *sheet, GnmRange *r); 150 151 G_END_DECLS 152 153 #endif /* _GNM_COLROW_H_ */ 154