Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GNOME
gnumeric
Commits
e49e86a5
Commit
e49e86a5
authored
Sep 04, 1998
by
Arturo Espinosa
Browse files
Just shuffled the new code to a new file -mig
parent
116d59c0
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/Makefile.am
View file @
e49e86a5
...
...
@@ -15,6 +15,7 @@ GNOME_XML_LIB = -lxml
GNUMERIC_BASE_SOURCES
=
\
cell.h
\
cell.c
\
cellspan.c
\
clipboard.c
\
clipboard.h
\
dialog-cell-format.c
\
...
...
src/cell.c
View file @
e49e86a5
...
...
@@ -907,146 +907,3 @@ cell_draw (Cell *cell, void *sv, GdkGC *gc, GdkDrawable *drawable, int x1, int y
}
}
static
guint
col_hash
(
gconstpointer
key
)
{
const
int
*
col
=
key
;
return
*
col
;
}
static
gint
col_compare
(
gconstpointer
a
,
gconstpointer
b
)
{
const
int
*
col_a
=
a
;
const
int
*
col_b
=
b
;
if
(
*
col_a
==
*
col_b
)
return
1
;
return
0
;
}
/*
* Initializes the hash table in the RowInfo for keeping track
* of cell spans (ie, which cells on the spreadsheet are displayed
* by which cell). This is required, as cells might be using
* more display space than the one where they store their information
*/
void
row_init_span
(
ColRowInfo
*
ri
)
{
g_return_if_fail
(
ri
!=
NULL
);
ri
->
data
=
g_hash_table_new
(
col_hash
,
col_compare
);
}
static
void
free_hash_key
(
gconstpointer
key
,
gconstpointer
value
,
gconstpointer
user_data
)
{
g_free
((
void
*
)
key
);
}
void
row_destroy_span
(
ColRowInfo
*
ri
)
{
g_return_if_fail
(
ri
!=
NULL
);
g_hash_table_foreach
(
ri
->
data
,
free_hash_key
,
NULL
);
g_hash_table_destroy
(
ri
->
data
);
}
/*
* sheet_cell_register_span
* @cell: The cell to register the span
* @left: the leftmost column used by the cell
* @right: the rightmost column used by the cell
*
* Registers the region
*/
void
cell_register_span
(
Cell
*
cell
,
int
left
,
int
right
)
{
ColRowInfo
*
ri
;
int
col
,
i
;
g_return_if_fail
(
cell
!=
NULL
);
g_return_if_fail
(
left
<=
right
);
ri
=
cell
->
row
;
col
=
cell
->
col
->
pos
;
for
(
i
=
left
;
i
<=
right
;
i
++
){
int
*
key
;
/* Do not register our column, as we already keep this on the main hash */
if
(
i
!=
col
)
continue
;
key
=
g_new
(
int
,
1
);
*
key
=
i
;
g_hash_table_insert
(
ri
->
data
,
key
,
cell
);
}
}
typedef
struct
{
Cell
*
cell
;
GList
*
list_of_keys
;
}
unregister_closure_t
;
static
void
assemble_unregister_span_list
(
gpointer
key
,
gpointer
value
,
gpointer
user_data
)
{
unregister_closure_t
*
c
=
user_data
;
if
(
c
->
cell
==
value
)
c
->
list_of_keys
=
g_list_prepend
(
c
->
list_of_keys
,
key
);
}
/*
* sheet_cell_unregister_span
* @cell: The cell to remove from the span information
*
* Remove all of the references to this cell on the span hash
* table
*/
void
cell_unregister_span
(
Cell
*
cell
)
{
unregister_closure_t
c
;
GList
*
l
;
g_return_if_fail
(
cell
!=
NULL
);
c
.
cell
=
cell
;
c
.
list_of_keys
=
NULL
;
g_hash_table_foreach
(
cell
->
row
->
data
,
assemble_unregister_span_list
,
&
c
);
for
(
l
=
c
.
list_of_keys
;
l
;
l
=
l
->
next
){
int
*
key
=
l
->
data
;
g_hash_table_remove
(
cell
->
row
->
data
,
key
);
g_free
(
key
);
}
g_list_free
(
c
.
list_of_keys
);
}
/*
* row_cell_get_displayed_at
* @ri: The ColRowInfo for the row we are looking up
* @col: the column position
*
* Returns the Cell* which happens to display at the column
*/
Cell
*
row_cell_get_displayed_at
(
ColRowInfo
*
ri
,
int
col
)
{
Cell
*
cell
;
g_return_val_if_fail
(
ri
!=
NULL
,
NULL
);
/* Ok, cell was not found, check the registered span regions */
cell
=
g_hash_table_lookup
(
ri
->
data
,
&
col
);
return
cell
;
}
src/cell.h
View file @
e49e86a5
...
...
@@ -89,7 +89,11 @@ void cell_draw (Cell *cell, void *sheet_view,
void
calc_text_dimensions
(
int
is_number
,
Style
*
style
,
char
*
text
,
int
cell_w
,
int
cell_h
,
int
*
h
,
int
*
w
);
/* Routines used to lookup which cells displays on a given column */
/*
* Routines used to lookup which cells displays on a given column
*
* These are defined in cellspan.c
*/
Cell
*
row_cell_get_displayed_at
(
ColRowInfo
*
ri
,
int
col
);
void
cell_register_span
(
Cell
*
cell
,
int
left
,
int
right
);
void
cell_unregister_span
(
Cell
*
cell
);
...
...
src/cellspan.c
0 → 100644
View file @
e49e86a5
/*
* cellspan.c: Keep track of the columns on which a cell
* displays information.
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*
* The information on cell spanning is attached in the row ColRowInfo
* structures. The actual representation of this information is
* opaque to the code that uses it (the idea is: this first
* implementation is not really awesome).
*
* The reason we need this is that the Grid draw code expects to find
* the "owner" of the cell to be able to repaint its contents.
*
*/
#include
<config.h>
#include
<gnome.h>
#include
"gnumeric.h"
#include
"gnumeric-sheet.h"
#include
"eval.h"
#include
"format.h"
static
guint
col_hash
(
gconstpointer
key
)
{
const
int
*
col
=
key
;
return
*
col
;
}
static
gint
col_compare
(
gconstpointer
a
,
gconstpointer
b
)
{
const
int
*
col_a
=
a
;
const
int
*
col_b
=
b
;
if
(
*
col_a
==
*
col_b
)
return
1
;
return
0
;
}
/*
* Initializes the hash table in the RowInfo for keeping track
* of cell spans (ie, which cells on the spreadsheet are displayed
* by which cell).
*/
void
row_init_span
(
ColRowInfo
*
ri
)
{
g_return_if_fail
(
ri
!=
NULL
);
ri
->
data
=
g_hash_table_new
(
col_hash
,
col_compare
);
}
static
void
free_hash_key
(
gpointer
key
,
gpointer
value
,
gpointer
user_data
)
{
g_free
(
key
);
}
void
row_destroy_span
(
ColRowInfo
*
ri
)
{
g_return_if_fail
(
ri
!=
NULL
);
g_hash_table_foreach
(
ri
->
data
,
free_hash_key
,
NULL
);
g_hash_table_destroy
(
ri
->
data
);
}
/*
* sheet_cell_register_span
* @cell: The cell to register the span
* @left: the leftmost column used by the cell
* @right: the rightmost column used by the cell
*
* Registers the region
*/
void
cell_register_span
(
Cell
*
cell
,
int
left
,
int
right
)
{
ColRowInfo
*
ri
;
int
col
,
i
;
g_return_if_fail
(
cell
!=
NULL
);
g_return_if_fail
(
left
<=
right
);
ri
=
cell
->
row
;
col
=
cell
->
col
->
pos
;
for
(
i
=
left
;
i
<=
right
;
i
++
){
int
*
key
;
/* Do not register our column, as we already keep this on the main hash */
if
(
i
!=
col
)
continue
;
key
=
g_new
(
int
,
1
);
*
key
=
i
;
g_hash_table_insert
(
ri
->
data
,
key
,
cell
);
}
}
typedef
struct
{
Cell
*
cell
;
GList
*
list_of_keys
;
}
unregister_closure_t
;
static
void
assemble_unregister_span_list
(
gpointer
key
,
gpointer
value
,
gpointer
user_data
)
{
unregister_closure_t
*
c
=
user_data
;
if
(
c
->
cell
==
value
)
c
->
list_of_keys
=
g_list_prepend
(
c
->
list_of_keys
,
key
);
}
/*
* sheet_cell_unregister_span
* @cell: The cell to remove from the span information
*
* Remove all of the references to this cell on the span hash
* table
*/
void
cell_unregister_span
(
Cell
*
cell
)
{
unregister_closure_t
c
;
GList
*
l
;
g_return_if_fail
(
cell
!=
NULL
);
c
.
cell
=
cell
;
c
.
list_of_keys
=
NULL
;
g_hash_table_foreach
(
cell
->
row
->
data
,
assemble_unregister_span_list
,
&
c
);
for
(
l
=
c
.
list_of_keys
;
l
;
l
=
l
->
next
){
int
*
key
=
l
->
data
;
g_hash_table_remove
(
cell
->
row
->
data
,
key
);
g_free
(
key
);
}
g_list_free
(
c
.
list_of_keys
);
}
/*
* row_cell_get_displayed_at
* @ri: The ColRowInfo for the row we are looking up
* @col: the column position
*
* Returns the Cell* which happens to display at the column
*/
Cell
*
row_cell_get_displayed_at
(
ColRowInfo
*
ri
,
int
col
)
{
Cell
*
cell
;
g_return_val_if_fail
(
ri
!=
NULL
,
NULL
);
/* Ok, cell was not found, check the registered span regions */
cell
=
g_hash_table_lookup
(
ri
->
data
,
&
col
);
return
cell
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment