~ubuntu-branches/ubuntu/quantal/gnumeric/quantal

« back to all changes in this revision

Viewing changes to src/colrow.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2009-06-07 11:10:47 UTC
  • mfrom: (1.1.19 upstream) (2.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090607111047-l3rtbzfjxvmi1kx0
Tags: 1.9.8-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Promoted gnumeric-doc to Recommends in gnumeric package for help to be
    installed automatically
  - gnumeric-gtk is a transitional package
  - gnumeric conflicts with gnumeric-gtk << 1.8.3-3ubuntu1
  - call initltool-update in po*
  - remove psiconv support (psiconv is in universe):
    o debian/control: remove B-D on libpsiconv-dev
    o debian/rules: don't pass --with-psiconv to ./configure

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
                                Sheet const *sheet, gboolean horizontal)
41
41
{
42
42
        int const margin = horizontal ? 2*GNM_COL_MARGIN : 2*GNM_ROW_MARGIN;
43
 
        double const scale =
 
43
        double scale =
44
44
                sheet->last_zoom_factor_used *
45
45
                gnm_app_display_dpi_get (horizontal) / 72.;
46
46
 
 
47
        if (horizontal && sheet->display_formulas)
 
48
                scale *= 2;
 
49
 
47
50
        cri->size_pixels = (int)(cri->size_pts * scale + 0.5);
 
51
 
48
52
        if (cri->size_pixels <= margin)
49
53
                cri->size_pixels = margin + 1;
50
54
}
53
57
colrow_compute_pts_from_pixels (ColRowInfo *cri,
54
58
                                Sheet const *sheet, gboolean horizontal)
55
59
{
56
 
        double const scale =
 
60
        double scale =
57
61
                sheet->last_zoom_factor_used *
58
62
                gnm_app_display_dpi_get (horizontal) / 72.;
59
63
 
 
64
        if (horizontal && sheet->display_formulas)
 
65
                scale *= 2;
 
66
 
60
67
        cri->size_pts = cri->size_pixels / scale;
61
68
#if 0
62
69
        /* Disable this until we decide how to deal with scaling */
297
304
        return list;
298
305
}
299
306
 
300
 
ColRowStateList *
301
 
colrow_make_state (G_GNUC_UNUSED Sheet *sheet, int count,
302
 
                   float size_pts, gboolean hard_size,
303
 
                   int outline_level)
 
307
static void
 
308
colrow_set_single_state (ColRowState *state,
 
309
                         Sheet *sheet, int i, gboolean is_cols)
304
310
{
305
 
        ColRowRLEState  *rles = g_new0 (ColRowRLEState, 1);
306
 
        rles->length = count;
307
 
        rles->state.size_pts      = size_pts;
308
 
        rles->state.outline_level = outline_level;
309
 
        rles->state.is_collapsed  = FALSE;
310
 
        rles->state.hard_size     = hard_size;
311
 
        rles->state.visible       = TRUE;
312
 
        rles->state.is_default    = FALSE;
313
 
        return g_slist_prepend (NULL, rles);
 
311
        ColRowInfo const *info = sheet_colrow_get_info (sheet, i, is_cols);
 
312
        state->is_default = colrow_is_default (info);
 
313
        state->size_pts = info->size_pts;
 
314
        state->outline_level = info->outline_level;
 
315
        state->is_collapsed = info->is_collapsed;
 
316
        state->hard_size = info->hard_size;
 
317
        state->visible = info->visible;
314
318
}
315
319
 
316
320
ColRowStateList *
318
322
{
319
323
        ColRowStateList *list = NULL;
320
324
        ColRowRLEState  *rles;
321
 
        /* gcc is wrong run_state is always initialized */
322
 
        ColRowState      run_state, cur_state;
323
 
        int              i, run_length = 0;
 
325
        ColRowState      run_state;
 
326
        int              i, run_length;
324
327
 
325
328
        g_return_val_if_fail (IS_SHEET (sheet), NULL);
326
329
        g_return_val_if_fail (first <= last, NULL);
327
330
 
328
 
        for (i = first; i <= last; ++i) {
329
 
                ColRowInfo const *info = sheet_colrow_get_info (sheet, i, is_cols);
330
 
 
331
 
                cur_state.is_default    = colrow_is_default (info);
332
 
                cur_state.size_pts      = info->size_pts;
333
 
                cur_state.outline_level = info->outline_level;
334
 
                cur_state.is_collapsed  = info->is_collapsed;
335
 
                cur_state.hard_size     = info->hard_size;
336
 
                cur_state.visible       = info->visible;
337
 
 
338
 
                /* Initialize the run_size in the first loop */
339
 
                if (run_length == 0) {
340
 
                        run_state = cur_state;
341
 
                        run_length = 1;
342
 
                        continue;
343
 
                }
 
331
        colrow_set_single_state (&run_state, sheet, first, is_cols);
 
332
        run_length = 1;
 
333
 
 
334
        for (i = first + 1; i <= last; ++i) {
 
335
                ColRowState cur_state;
 
336
                colrow_set_single_state (&cur_state, sheet, i, is_cols);
344
337
 
345
338
                /* If state changed, start a new block */
346
339
                if (cur_state.is_default    != run_state.is_default ||
349
342
                    cur_state.is_collapsed  != run_state.is_collapsed ||
350
343
                    cur_state.hard_size     != run_state.hard_size ||
351
344
                    cur_state.visible       != run_state.visible) {
352
 
                        rles         = g_new0 (ColRowRLEState, 1);
 
345
                        rles = g_new (ColRowRLEState, 1);
353
346
                        rles->length = run_length;
354
347
                        rles->state  = run_state;
355
348
                        list = g_slist_prepend (list, rles);
361
354
        }
362
355
 
363
356
        /* Store the final run */
364
 
        if (run_length > 0) {
365
 
                rles         = g_new0 (ColRowRLEState, 1);
366
 
                rles->length = run_length;
367
 
                rles->state  = run_state;
368
 
                list = g_slist_prepend (list, rles);
369
 
        }
 
357
        rles = g_new (ColRowRLEState, 1);
 
358
        rles->length = run_length;
 
359
        rles->state = run_state;
 
360
        list = g_slist_prepend (list, rles);
370
361
 
371
362
        return g_slist_reverse (list);
372
363
}
442
433
                        if (is_cols) {
443
434
                                rles->state.size_pts = sheet_col_get_default_size_pts (sheet);
444
435
                                sheet_col_set_default_size_pixels (sheet, new_size);
445
 
                                colrow_foreach (&sheet->cols, 0, gnm_sheet_get_max_cols (sheet)-1,
 
436
                                colrow_foreach (&sheet->cols, 0, gnm_sheet_get_last_col (sheet),
446
437
                                        &cb_set_colrow_size, &closure);
447
438
                        } else {
448
439
                                rles->state.size_pts = sheet_row_get_default_size_pts (sheet);
449
440
                                sheet_row_set_default_size_pixels (sheet, new_size);
450
 
                                colrow_foreach (&sheet->rows, 0, gnm_sheet_get_max_rows (sheet)-1,
 
441
                                colrow_foreach (&sheet->rows, 0, gnm_sheet_get_last_row (sheet),
451
442
                                        &cb_set_colrow_size, &closure);
452
443
                        }
453
444
 
454
445
                        /* force a re-render of cells with expanding formats */
455
446
                        if (is_cols)
456
447
                                sheet_foreach_cell_in_range (sheet, CELL_ITER_IGNORE_BLANK,
457
 
                                        0, 0, gnm_sheet_get_max_cols (sheet)-1, gnm_sheet_get_max_rows (sheet)-1,
 
448
                                        0, 0, gnm_sheet_get_last_col (sheet), gnm_sheet_get_last_row (sheet),
458
449
                                        (CellIterFunc) &cb_clear_variable_width_content, NULL);
459
450
 
460
451
                        /* Result is a magic 'default' record + >= 1 normal */
464
455
                if (is_cols) {
465
456
                        /* force a re-render of cells with expanding formats */
466
457
                        sheet_foreach_cell_in_range (sheet, CELL_ITER_IGNORE_BLANK,
467
 
                                index->first, 0, index->last, gnm_sheet_get_max_rows (sheet)-1,
 
458
                                index->first, 0, index->last, gnm_sheet_get_last_row (sheet),
468
459
                                (CellIterFunc) &cb_clear_variable_width_content, NULL);
469
460
 
470
461
                        /* In order to properly reposition cell comments in
479
470
                        if (tmp < 0)
480
471
                                /* Fall back to assigning the defaul if it is empty */
481
472
                                tmp = (is_cols)
482
 
                                        ? sheet_col_size_fit_pixels (sheet, i, 0, gnm_sheet_get_max_rows (sheet) - 1, FALSE)
483
 
                                        : sheet_row_size_fit_pixels (sheet, i, 0, gnm_sheet_get_max_cols (sheet) - 1, FALSE);
 
473
                                        ? sheet_col_size_fit_pixels (sheet, i, 0, gnm_sheet_get_last_row (sheet), FALSE)
 
474
                                        : sheet_row_size_fit_pixels (sheet, i, 0, gnm_sheet_get_last_col (sheet), FALSE);
484
475
 
485
476
                        if (tmp > 0) {
486
477
                                if (is_cols)
606
597
                /* force a re-render of cells with expanding formats */
607
598
                if (is_cols)
608
599
                        sheet_foreach_cell_in_range (sheet, CELL_ITER_IGNORE_BLANK,
609
 
                                index->first, 0, index->last, gnm_sheet_get_max_rows (sheet)-1,
 
600
                                index->first, 0, index->last, gnm_sheet_get_last_row (sheet),
610
601
                                (CellIterFunc) &cb_clear_variable_width_content, NULL);
611
602
                colrow_state_list_destroy (ptr->data);
612
603
                selection = selection->prev;
906
897
        }
907
898
 
908
899
        if (is_cols)
909
 
                sheet_queue_respan (sheet, 0, gnm_sheet_get_max_rows (sheet)-1);
 
900
                sheet_queue_respan (sheet, 0, gnm_sheet_get_last_row (sheet));
910
901
        if (list != NULL)
911
902
                sheet_redraw_all (sheet, TRUE);
912
903
}
1168
1159
 * and replace them with the default.
1169
1160
 **/
1170
1161
void
1171
 
colrow_reset_defaults (Sheet *sheet, gboolean is_cols,
1172
 
                       int maxima)
 
1162
colrow_reset_defaults (Sheet *sheet, gboolean is_cols, int maxima)
1173
1163
{
1174
1164
        ColRowCollection *infos = is_cols ? &sheet->cols : &sheet->rows;
1175
1165
        ColRowInfo const *default_cri = &infos->default_style;
1178
1168
        int const end = colrow_max (is_cols, sheet);
1179
1169
        int inner, inner_start, inner_last, i;
1180
1170
 
 
1171
        if (maxima >= end) {
 
1172
                g_warning ("In colrow_reset_defaults, someone set maxima to %d >= %d", maxima, end);
 
1173
                maxima = end - 1;
 
1174
        }
 
1175
 
 
1176
        /* From here on, maxima is the first unused.  */
 
1177
        maxima++;
 
1178
 
1181
1179
        i = COLROW_SEGMENT_START(maxima);
1182
1180
        inner_start = maxima - i;
1183
1181
        for ( ; i < end ; i += COLROW_SEGMENT_SIZE) {
1199
1197
                }
1200
1198
                inner_start = 0;
1201
1199
        }
1202
 
        infos->max_used = maxima;
 
1200
        infos->max_used = maxima - 1;
 
1201
}
 
1202
 
 
1203
void
 
1204
colrow_resize (ColRowCollection *infos, int size)
 
1205
{
 
1206
        int end_idx = COLROW_SEGMENT_INDEX (size);
 
1207
        int i = infos->info->len - 1;
 
1208
 
 
1209
        while (i >= end_idx) {
 
1210
                ColRowSegment *segment = g_ptr_array_index (infos->info, i);
 
1211
                if (segment) {
 
1212
                        g_free (segment);
 
1213
                        g_ptr_array_index (infos->info, i) = NULL;
 
1214
                }
 
1215
                i--;
 
1216
        }
 
1217
 
 
1218
        g_ptr_array_set_size (infos->info, end_idx);
1203
1219
}