~ubuntu-branches/ubuntu/feisty/gnumeric/feisty

« back to all changes in this revision

Viewing changes to src/cellspan.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2006-11-14 14:02:03 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061114140203-iv3j2aii3vch6isl
Tags: 1.7.2-1ubuntu1
* Merge with debian experimental:
  - debian/control, debian/*-gtk-*, debian/rules,
    debian/shlibs.local: Xubuntu changes for
    gtk/gnome multibuild.
  - run intltool-update in po*
  - Build Depend on intltool

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
        if (cell->row_info->spans == NULL)
129
129
                return;
130
130
 
131
 
        g_hash_table_foreach_remove (cell->row_info->spans, &span_remove,
132
 
                                     (gpointer)cell);
 
131
        g_hash_table_foreach_remove (cell->row_info->spans,
 
132
                &span_remove, (gpointer)cell);
133
133
}
134
134
 
135
135
/*
168
168
 * returns TRUE if the cell is empty.
169
169
 */
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)
172
172
{
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;
175
175
 
176
176
        if (span != NULL && span->cell != ok_span_cell)
177
177
                return FALSE;
178
178
 
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);
 
181
 
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
199
201
{
200
202
        Sheet *sheet;
201
203
        int h_align, v_align, left, max_col, min_col;
202
 
        int row, pos, margin;
 
204
        int row, pos;
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;
208
210
 
209
211
        g_return_if_fail (cell != NULL);
210
212
 
211
213
        sheet = cell->base.sheet;
212
 
        ri = cell->row_info;
213
 
 
214
214
        style = cell_get_style (cell);
215
215
        h_align = style_default_halign (style, cell);
216
216
 
239
239
                        h_align = (h_align == HALIGN_LEFT) ? HALIGN_RIGHT : HALIGN_LEFT;
240
240
        }
241
241
 
 
242
        ci = sheet_col_get_info (sheet, cell->pos.col);
242
243
        if (cell_is_empty (cell) ||
243
 
            !cell->col_info->visible ||
 
244
            !ci->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);
266
266
 
267
267
                for (; left > 0 && pos < max_col; pos++){
268
268
                        ColRowInfo const *ci = sheet_col_get_info (sheet, pos);
269
269
 
270
270
                        if (ci->visible) {
271
 
                                if (!cellspan_is_empty (pos, ri, cell))
 
271
                                if (!cellspan_is_empty (pos, cell))
272
272
                                        return;
273
273
 
274
274
                                /* The space consumed is:
275
275
                                 *   - The margin_b from the last column
276
276
                                 *   - The width of the cell
277
277
                                 */
278
 
                                left -= COL_INTERNAL_WIDTH (ci) +
279
 
                                        margin + ci->margin_a;
 
278
                                left -= ci->size_pixels - 1;
280
279
                                *col2 = pos;
281
280
                        }
282
 
                        margin = ci->margin_b;
283
281
                }
284
282
                return;
285
283
 
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);
290
287
 
291
288
                for (; left > 0 && pos > min_col; pos--){
292
289
                        ColRowInfo const *ci = sheet_col_get_info (sheet, pos);
293
290
 
294
291
                        if (ci->visible) {
295
 
                                if (!cellspan_is_empty (pos, ri, cell))
 
292
                                if (!cellspan_is_empty (pos, cell))
296
293
                                        return;
297
294
 
298
295
                                /* The space consumed is:
299
296
                                 *   - The margin_a from the last column
300
297
                                 *   - The width of this cell
301
298
                                 */
302
 
                                left -= COL_INTERNAL_WIDTH (ci) +
303
 
                                        margin + ci->margin_b;
 
299
                                left -= ci->size_pixels - 1;
304
300
                                *col1 = pos;
305
301
                        }
306
 
                        margin = ci->margin_a;
307
302
                }
308
303
                return;
309
304
 
310
305
        case HALIGN_CENTER: {
311
306
                int remain_left, remain_right;
312
 
                int margin_a, margin_b, pos_l, pos_r;
 
307
                int pos_l, pos_r;
313
308
 
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);
316
311
 
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;
321
314
 
322
315
                for (; remain_left > 0 || remain_right > 0;){
323
316
                        ColRowInfo const *ci;
326
319
                                ci = sheet_col_get_info (sheet, pos_l);
327
320
 
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;
333
324
                                                *col1 = pos_l;
334
325
                                        } else
335
326
                                                remain_left = 0;
341
332
                                ci = sheet_col_get_info (sheet, pos_r);
342
333
 
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;
348
337
                                                *col2 = pos_r;
349
338
                                        } else
350
339
                                                max_col = remain_right = 0;
355
344
                break;
356
345
        } /* case HALIGN_CENTER */
357
346
 
358
 
        case HALIGN_CENTER_ACROSS_SELECTION:
359
 
        {
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;
362
350
 
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);
370
358
 
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);
384
372
 
398
386
}
399
387
 
400
388
void
401
 
row_calc_spans (ColRowInfo *rinfo, Sheet const *sheet)
 
389
row_calc_spans (ColRowInfo *ri, int row, Sheet const *sheet)
402
390
{
403
 
        int left, right, col, row = rinfo->pos;
 
391
        int left, right, col;
404
392
        GnmRange const *merged;
405
393
        GnmCell *cell;
406
394
        int const last = sheet->cols.max_used;
407
395
 
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) {
438
426
                        col++;
439
427
        }
440
428
 
441
 
        rinfo->needs_respan = FALSE;
 
429
        ri->needs_respan = FALSE;
442
430
}