128
128
if (cell->row_info->spans == NULL)
131
g_hash_table_foreach_remove (cell->row_info->spans, &span_remove,
131
g_hash_table_foreach_remove (cell->row_info->spans,
132
&span_remove, (gpointer)cell);
168
168
* returns TRUE if the cell is empty.
170
170
static inline gboolean
171
cellspan_is_empty (int col, ColRowInfo const *ri, GnmCell const *ok_span_cell)
171
cellspan_is_empty (int col, GnmCell const *ok_span_cell)
173
CellSpanInfo const *span = row_span_get (ri, col);
173
CellSpanInfo const *span = row_span_get (ok_span_cell->row_info, col);
174
174
GnmCell const *tmp;
176
176
if (span != NULL && span->cell != ok_span_cell)
179
tmp = sheet_cell_get (ok_span_cell->base.sheet, col, ri->pos);
179
tmp = sheet_cell_get (ok_span_cell->base.sheet,
180
col, ok_span_cell->pos.row);
180
182
/* FIXME : cannot use cell_is_empty until expressions can span.
181
183
* because cells with expressions start out with value Empty
182
184
* existing spans continue to flow through, but never get removed
201
203
int h_align, v_align, left, max_col, min_col;
202
int row, pos, margin;
203
205
int cell_width_pixel, indented_w;
204
206
GnmStyle const *style;
205
ColRowInfo const *ri;
207
ColRowInfo const *ci;
206
208
GnmRange const *merge_left;
207
209
GnmRange const *merge_right;
209
211
g_return_if_fail (cell != NULL);
211
213
sheet = cell->base.sheet;
214
214
style = cell_get_style (cell);
215
215
h_align = style_default_halign (style, cell);
239
239
h_align = (h_align == HALIGN_LEFT) ? HALIGN_RIGHT : HALIGN_LEFT;
242
ci = sheet_col_get_info (sheet, cell->pos.col);
242
243
if (cell_is_empty (cell) ||
243
!cell->col_info->visible ||
244
245
(h_align != HALIGN_CENTER_ACROSS_SELECTION &&
245
246
(gnm_style_get_wrap_text (style) ||
246
indented_w <= COL_INTERNAL_WIDTH (cell->col_info))) ||
247
indented_w <= COL_INTERNAL_WIDTH (ci))) ||
247
248
h_align == HALIGN_JUSTIFY ||
248
249
h_align == HALIGN_FILL ||
249
250
h_align == HALIGN_DISTRIBUTED ||
261
262
switch (h_align) {
262
263
case HALIGN_LEFT:
263
264
pos = cell->pos.col + 1;
264
left = indented_w - COL_INTERNAL_WIDTH (cell->col_info);
265
margin = cell->col_info->margin_b;
265
left = indented_w - COL_INTERNAL_WIDTH (ci);
267
267
for (; left > 0 && pos < max_col; pos++){
268
268
ColRowInfo const *ci = sheet_col_get_info (sheet, pos);
270
270
if (ci->visible) {
271
if (!cellspan_is_empty (pos, ri, cell))
271
if (!cellspan_is_empty (pos, cell))
274
274
/* The space consumed is:
275
275
* - The margin_b from the last column
276
276
* - The width of the cell
278
left -= COL_INTERNAL_WIDTH (ci) +
279
margin + ci->margin_a;
278
left -= ci->size_pixels - 1;
282
margin = ci->margin_b;
286
284
case HALIGN_RIGHT:
287
285
pos = cell->pos.col - 1;
288
left = indented_w - COL_INTERNAL_WIDTH (cell->col_info);
289
margin = cell->col_info->margin_a;
286
left = indented_w - COL_INTERNAL_WIDTH (ci);
291
288
for (; left > 0 && pos > min_col; pos--){
292
289
ColRowInfo const *ci = sheet_col_get_info (sheet, pos);
294
291
if (ci->visible) {
295
if (!cellspan_is_empty (pos, ri, cell))
292
if (!cellspan_is_empty (pos, cell))
298
295
/* The space consumed is:
299
296
* - The margin_a from the last column
300
297
* - The width of this cell
302
left -= COL_INTERNAL_WIDTH (ci) +
303
margin + ci->margin_b;
299
left -= ci->size_pixels - 1;
306
margin = ci->margin_a;
310
305
case HALIGN_CENTER: {
311
306
int remain_left, remain_right;
312
int margin_a, margin_b, pos_l, pos_r;
314
309
pos_l = pos_r = cell->pos.col;
315
left = cell_width_pixel - COL_INTERNAL_WIDTH (cell->col_info);
310
left = cell_width_pixel - COL_INTERNAL_WIDTH (ci);
317
312
remain_left = left / 2 + (left % 2);
318
313
remain_right = left / 2;
319
margin_a = cell->col_info->margin_a;
320
margin_b = cell->col_info->margin_b;
322
315
for (; remain_left > 0 || remain_right > 0;){
323
316
ColRowInfo const *ci;
326
319
ci = sheet_col_get_info (sheet, pos_l);
328
321
if (ci->visible) {
329
if (cellspan_is_empty (pos_l, ri, cell)) {
330
remain_left -= COL_INTERNAL_WIDTH (ci) +
331
margin_a + ci->margin_b;
332
margin_a = ci->margin_a;
322
if (cellspan_is_empty (pos_l, cell)) {
323
remain_left -= ci->size_pixels - 1;
341
332
ci = sheet_col_get_info (sheet, pos_r);
343
334
if (ci->visible) {
344
if (cellspan_is_empty (pos_r, ri, cell)) {
345
remain_right -= COL_INTERNAL_WIDTH (ci) +
346
margin_b + ci->margin_a;
347
margin_b = ci->margin_b;
335
if (cellspan_is_empty (pos_r, cell)) {
336
remain_right -= ci->size_pixels - 1;
350
339
max_col = remain_right = 0;
356
345
} /* case HALIGN_CENTER */
358
case HALIGN_CENTER_ACROSS_SELECTION:
360
int const row = ri->pos;
347
case HALIGN_CENTER_ACROSS_SELECTION: {
348
int const row = cell->pos.row;
361
349
int pos_l, pos_r;
363
351
pos_l = pos_r = cell->pos.col;
364
352
while (--pos_l > min_col) {
365
353
ColRowInfo const *ci = sheet_col_get_info (sheet, pos_l);
366
354
if (ci->visible) {
367
if (cellspan_is_empty (pos_l, ri, cell)) {
355
if (cellspan_is_empty (pos_l, cell)) {
368
356
GnmStyle const * const style =
369
357
sheet_style_get (cell->base.sheet, pos_l, row);
378
366
while (++pos_r < max_col) {
379
367
ColRowInfo const *ci = sheet_col_get_info (sheet, pos_r);
380
368
if (ci->visible) {
381
if (cellspan_is_empty (pos_r, ri, cell)) {
369
if (cellspan_is_empty (pos_r, cell)) {
382
370
GnmStyle const * const style =
383
371
sheet_style_get (cell->base.sheet, pos_r, row);
401
row_calc_spans (ColRowInfo *rinfo, Sheet const *sheet)
389
row_calc_spans (ColRowInfo *ri, int row, Sheet const *sheet)
403
int left, right, col, row = rinfo->pos;
391
int left, right, col;
404
392
GnmRange const *merged;
406
394
int const last = sheet->cols.max_used;
408
row_destroy_span (rinfo);
396
row_destroy_span (ri);
409
397
for (col = 0 ; col <= last ; ) {
410
398
cell = sheet_cell_get (sheet, col, row);
411
399
if (cell == NULL) {