ranges.h 4.95 KB
Newer Older
1 2 3
/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifndef _GNM_RANGES_H_
# define _GNM_RANGES_H_
Arturo Espinosa's avatar
Arturo Espinosa committed
4

Jody Goldberg's avatar
Jody Goldberg committed
5
#include "gnumeric.h"
6
#include <glib-object.h>
Arturo Espinosa's avatar
Arturo Espinosa committed
7

8 9
G_BEGIN_DECLS

10 11 12 13 14
/**
 * range_equal:
 * @a: First range
 * @b: Second range
 *
15
 * NB. commutative, symmetric, and transitive.
16 17 18
 *
 * Returns: True if both ranges are equal.
 **/
Morten Welinder's avatar
Morten Welinder committed
19 20 21 22
#define range_equal(a,b)   ((a)->start.row == (b)->start.row && \
			    (a)->end.row   == (b)->end.row && \
			    (a)->start.col == (b)->start.col && \
			    (a)->end.col   == (b)->end.col)
23

24 25 26
GType	  gnm_range_get_type (void); /* GBoxedType */
GnmRange *gnm_range_dup	  (GnmRange const *r);
gboolean  gnm_range_equal (GnmRange const *a, GnmRange const *b);
27
int       gnm_range_compare (GnmRange const *a, GnmRange const *b);
28

29 30 31 32 33
/**
 * range_overlap:
 * @a: First range
 * @b: Second range
 *
34
 * NB. commutative, symmetric, but not transitive.
35 36 37
 *
 * Returns: True if the ranges overlap at all.
 **/
Morten Welinder's avatar
Morten Welinder committed
38 39 40 41
#define range_overlap(a,b) (((a)->end.row >= (b)->start.row) && \
			    ((b)->end.row >= (a)->start.row) && \
			    ((a)->end.col >= (b)->start.col) && \
			    ((b)->end.col >= (a)->start.col))
42

Michael Meeks's avatar
Michael Meeks committed
43 44 45 46 47
/**
 * range_contains:
 * @r:   range to operate on
 * @x:   column,
 * @y:   row co-ordinate
48
 *
Michael Meeks's avatar
Michael Meeks committed
49
 * Determine if a range contains a col,row co-ordinate.
50
 *
Michael Meeks's avatar
Michael Meeks committed
51 52
 * Return value: TRUE if co-ordinate contained.
 **/
53 54 55 56
#define range_contains(r,x,y)	(((y) <= (r)->end.row) && \
				 ((y) >= (r)->start.row) && \
				 ((x) >= (r)->start.col) && \
				 ((x) <= (r)->end.col))
Michael Meeks's avatar
Michael Meeks committed
57

58 59 60
/*
 * Quickly Test if a range is valid
 */
61 62
#define range_valid(r)          ((r)->start.col <= (r)->end.col && \
				 (r)->start.row <= (r)->end.row)
63

64
#define range_fragment_free(f) g_slist_free_full ((f), g_free)
65

66 67 68 69 70
GnmRange   *range_init_full_sheet   (GnmRange *r, Sheet const *sheet);
GnmRange   *range_init_cols   	    (GnmRange *r, Sheet const *sheet,
				     int start_col, int end_col);
GnmRange   *range_init_rows         (GnmRange *r, Sheet const *sheet,
				     int start_row, int end_row);
71
GnmRange   *range_init_invalid	    (GnmRange *r);
72 73
GnmRange   *range_init_rangeref	    (GnmRange *r, GnmRangeRef const *rr);
GnmRange   *range_init_value	    (GnmRange *r, GnmValue const *v);
74
GnmRange   *range_init_cellpos	    (GnmRange *r, GnmCellPos const *pos);
75 76
GnmRange   *range_init_cellpos_size (GnmRange *r, GnmCellPos const *start,
				     int cols, int rows);
Jody Goldberg's avatar
Jody Goldberg committed
77
GnmRange   *range_init              (GnmRange *r, int start_col, int start_row,
Michael Meeks's avatar
Michael Meeks committed
78
				     int end_col, int end_row);
79
gboolean    range_parse 	    (GnmRange *r, char const *text,
80
				     GnmSheetSize const *ss);
81

Arturo Espinosa's avatar
Arturo Espinosa committed
82 83
void        range_list_destroy      (GSList *ranges);

Jody Goldberg's avatar
Jody Goldberg committed
84 85 86
int	    range_width		(GnmRange const *r);
int	    range_height	(GnmRange const *r);
gboolean    range_is_singleton  (GnmRange const *r);
87
gboolean    range_is_full	(GnmRange const *r, Sheet const *sheet, gboolean horiz);
Jody Goldberg's avatar
Jody Goldberg committed
88 89 90 91 92 93 94
void        range_clip_to_finite(GnmRange *range, Sheet *sheet);
gboolean    range_contained     (GnmRange const *a, GnmRange const *b);
gboolean    range_intersection  (GnmRange *r,
				 GnmRange const *a,
				 GnmRange const *b);
void        range_normalize     (GnmRange *src);
GnmRange    range_union         (GnmRange const *a, GnmRange const *b);
95
void        range_ensure_sanity (GnmRange *range, Sheet const *sheet);
Jody Goldberg's avatar
Jody Goldberg committed
96
gboolean    range_is_sane	(GnmRange const *range);
97 98 99 100
gboolean    range_translate     (GnmRange *range, Sheet const *sheet,
				 int col_offset, int row_offset);
gboolean    range_transpose     (GnmRange *range, Sheet const *sheet,
				 GnmCellPos const *origin);
101

102 103
char const *range_as_string	(GnmRange const *r);
void        range_dump		(GnmRange const *r, char const *suffix);
104

Jody Goldberg's avatar
Jody Goldberg committed
105 106
GSList     *range_split_ranges    (GnmRange const *hard, GnmRange const *soft);
GSList     *range_fragment        (GnmRange const *a, GnmRange const *b);
107

108
GType	       gnm_sheet_range_get_type   (void); /* GBoxedType */
109 110 111 112
GnmSheetRange *gnm_sheet_range_new	  (Sheet *sheet, GnmRange const *r);
void           gnm_sheet_range_free       (GnmSheetRange *r);
gboolean       gnm_sheet_range_from_value (GnmSheetRange *r, GnmValue const *v);
gboolean       gnm_sheet_range_overlap    (GnmSheetRange const *a, GnmSheetRange const *b);
113
GnmSheetRange *gnm_sheet_range_dup	  (GnmSheetRange const *sr);
114 115
gboolean       gnm_sheet_range_equal      (GnmSheetRange const *a,
					   GnmSheetRange const *b);
116

117 118 119 120 121 122 123 124 125 126 127 128
char	      *global_range_name	  (Sheet const *sheet, GnmRange const *r);
char	      *undo_cell_pos_name	  (Sheet const *sheet, GnmCellPos const *pos);
char	      *undo_range_name		  (Sheet const *sheet, GnmRange const *r);
char	      *undo_range_list_name	  (Sheet const *sheet, GSList const *ranges);

GSList	      *global_range_list_parse    (Sheet *sheet, char const *str);
GnmValue      *global_range_list_foreach  (GSList *gr_list, GnmEvalPos const *ep,
					   CellIterFlags	flags,
					   CellIterFunc	handler,
					   gpointer	closure);
gboolean       global_range_contained	  (Sheet const *sheet,
					   GnmValue const *a, GnmValue const *b);
129

130 131 132
G_END_DECLS

#endif /* _GNM_RANGES_H_ */