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

« back to all changes in this revision

Viewing changes to src/tools/dao.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2009-06-22 13:37:20 UTC
  • mfrom: (1.1.20 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090622133720-rtdazsiz2lx5q8l7
Tags: 1.9.9-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
    o debian/gnumeric-plugins-extra.install: don't install the psiconv
      plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include "workbook-control.h"
41
41
#include "command-context.h"
42
42
#include "gnm-format.h"
 
43
#include "sheet-merge.h"
43
44
#include "sheet-object-cell-comment.h"
44
45
#include "style-color.h"
 
46
#include "style-border.h"
45
47
#include "graph.h"
46
 
#include <goffice/app/go-doc.h>
47
 
#include <goffice/utils/go-glib-extras.h>
 
48
#include <goffice/goffice.h>
48
49
 
49
50
#include <glib.h>
50
51
#include <glib/gi18n-lib.h>
196
197
void
197
198
dao_adjust (data_analysis_output_t *dao, gint cols, gint rows)
198
199
{
199
 
        int max_rows = gnm_sheet_get_max_rows (dao->sheet) - dao->start_row;
200
 
        int max_cols = gnm_sheet_get_max_cols (dao->sheet) - dao->start_col;
 
200
        int max_rows, max_cols;
201
201
 
202
202
        if (dao->cols == 1 && dao->rows == 1) {
203
203
                if (cols != -1)
211
211
                        dao->rows = MIN (rows, dao->rows);
212
212
        }
213
213
 
 
214
        if (dao->sheet) {
 
215
                max_rows = gnm_sheet_get_max_rows (dao->sheet) - dao->start_row;
 
216
                max_cols = gnm_sheet_get_max_cols (dao->sheet) - dao->start_col;
 
217
        } else {
 
218
                /* In case of NewSheetOutput and NewWorkbookOutput */
 
219
                /* this is called before we actually create the    */
 
220
                /* new sheet and/or workbook                       */
 
221
                Sheet *old_sheet = wb_control_cur_sheet (dao->wbc);
 
222
                max_rows = gnm_sheet_get_max_rows (old_sheet) - dao->start_row;
 
223
                max_cols = gnm_sheet_get_max_cols (old_sheet) - dao->start_col;         
 
224
        }
 
225
 
214
226
        if (dao->cols > max_cols)
215
227
                dao->cols = max_cols;
216
228
        if (dao->rows > max_rows)
308
320
}
309
321
 
310
322
 
 
323
static gboolean
 
324
adjust_range (data_analysis_output_t *dao, GnmRange *r)
 
325
{
 
326
        range_normalize (r);
 
327
 
 
328
        r->start.col += dao->offset_col + dao->start_col;
 
329
        r->end.col   += dao->offset_col + dao->start_col;
 
330
        r->start.row += dao->offset_row + dao->start_row;
 
331
        r->end.row   += dao->offset_row + dao->start_row;
 
332
 
 
333
        if (dao->type == RangeOutput && (dao->cols > 1 || dao->rows > 1)) {
 
334
                if (r->end.col >= dao->start_col + dao->cols)
 
335
                        r->end.col = dao->start_col + dao->cols - 1;
 
336
                if (r->end.row >= dao->start_row + dao->rows)
 
337
                        r->end.row = dao->start_row + dao->rows - 1;
 
338
        }
 
339
 
 
340
        range_ensure_sanity (r, dao->sheet);
 
341
        
 
342
        return ((r->start.col <= r->end.col) && (r->start.row <= r->end.row));
 
343
 
 
344
}
 
345
 
311
346
gboolean
312
347
dao_cell_is_visible (data_analysis_output_t *dao, int col, int row)
313
348
{
336
371
                    GnmExpr const *expr)
337
372
{
338
373
        GnmExprTop const *texpr;
339
 
        int col_end;
340
 
        int row_end;
341
 
 
342
 
        col += dao->offset_col;
343
 
        row += dao->offset_row;
344
 
        col_end = col + cols - 1;
345
 
        row_end = row + rows - 1;
346
 
 
347
 
        /* Check that the output is in the given range, but allow singletons
348
 
         * to expand
349
 
         */
350
 
        if (dao->type == RangeOutput && (dao->cols > 1 || dao->rows > 1)) {
351
 
                if (col >= dao->cols || row >= dao->rows) {
352
 
                        gnm_expr_free (expr);
353
 
                        return;
354
 
                }
355
 
                if (col_end >= dao->cols)
356
 
                        col_end = dao->cols - 1;
357
 
                if (row_end >= dao->rows)
358
 
                        row_end = dao->rows - 1;
359
 
        }
360
 
 
361
 
        col += dao->start_col;
362
 
        row += dao->start_row;
363
 
        col_end += dao->start_col;
364
 
        row_end += dao->start_row;
365
 
        if (col >= gnm_sheet_get_max_cols (dao->sheet) 
366
 
            || row >= gnm_sheet_get_max_rows (dao->sheet)) {
 
374
        GnmRange r;
 
375
 
 
376
        range_init (&r, col, row, col + cols - 1, row + rows -1);
 
377
 
 
378
        if (!adjust_range (dao, &r)) {
367
379
                gnm_expr_free (expr);
368
380
                return;
369
381
        }
370
 
        if (col_end >= gnm_sheet_get_max_cols (dao->sheet))
371
 
                col_end = gnm_sheet_get_last_col (dao->sheet);
372
 
        if (row_end >= gnm_sheet_get_max_rows (dao->sheet))
373
 
                row_end = gnm_sheet_get_last_row (dao->sheet);
374
382
 
375
383
        texpr = gnm_expr_top_new (expr);
376
384
        gnm_cell_set_array_formula (dao->sheet, 
377
 
                                    col, row, 
378
 
                                    col_end, row_end,
 
385
                                    r.start.col, r.start.row, 
 
386
                                    r.end.col, r.end.row,
379
387
                                    texpr);
380
388
}
381
389
/*
400
408
{
401
409
        GnmCell *cell;
402
410
        GnmExprTop const *texpr;
403
 
 
404
 
        col += dao->offset_col;
405
 
        row += dao->offset_row;
406
 
 
407
 
        /* Check that the output is in the given range, but allow singletons
408
 
         * to expand
409
 
         */
410
 
        if (dao->type == RangeOutput &&
411
 
            (dao->cols > 1 || dao->rows > 1) &&
412
 
            (col >= dao->cols || row >= dao->rows)) {
 
411
        GnmRange r;
 
412
 
 
413
        range_init (&r, col, row, col, row);
 
414
 
 
415
        if (!adjust_range (dao, &r)) {
413
416
                gnm_expr_free (expr);
414
417
                return;
415
418
        }
416
419
 
417
 
        col += dao->start_col;
418
 
        row += dao->start_row;
419
 
        if (col >= gnm_sheet_get_max_cols (dao->sheet) || row >= gnm_sheet_get_max_rows (dao->sheet)) {
420
 
                gnm_expr_free (expr);
421
 
                return;
422
 
        }
423
 
 
424
 
        cell = sheet_cell_fetch (dao->sheet, col, row);
 
420
        cell = sheet_cell_fetch (dao->sheet, r.start.col, r.start.row);
425
421
        texpr = gnm_expr_top_new (expr);
426
422
        gnm_cell_set_expr (cell, texpr);
427
423
        gnm_expr_top_unref (texpr);
447
443
dao_set_cell_value (data_analysis_output_t *dao, int col, int row, GnmValue *v)
448
444
{
449
445
        GnmCell *cell;
450
 
 
451
 
        col += dao->offset_col;
452
 
        row += dao->offset_row;
453
 
 
454
 
        /* Check that the output is in the given range, but allow singletons
455
 
         * to expand
456
 
         */
457
 
        if (dao->type == RangeOutput &&
458
 
            (dao->cols > 1 || dao->rows > 1) &&
459
 
            (col >= dao->cols || row >= dao->rows)) {
 
446
        GnmRange r;
 
447
 
 
448
        range_init (&r, col, row, col, row);
 
449
 
 
450
        if (!adjust_range (dao, &r)) {
460
451
                value_release (v);
461
452
                return;
462
453
        }
463
454
 
464
 
        col += dao->start_col;
465
 
        row += dao->start_row;
466
 
        if (col >= gnm_sheet_get_max_cols (dao->sheet) || row >= gnm_sheet_get_max_rows (dao->sheet)) {
467
 
                value_release (v);
468
 
                return;
469
 
        }
470
 
 
471
 
        cell = sheet_cell_fetch (dao->sheet, col, row);
 
455
        cell = sheet_cell_fetch (dao->sheet, r.start.col, r.start.row);
472
456
 
473
457
        sheet_cell_set_value (cell, v);
474
458
}
612
596
dao_set_cell_comment (data_analysis_output_t *dao, int col, int row,
613
597
                      const char *comment)
614
598
{
615
 
        GnmCellPos pos;
616
599
        char const *author = NULL;
617
 
 
618
 
        /* Check that the output is in the given range, but allow singletons
619
 
         * to expand
620
 
         */
621
 
        if (dao->type == RangeOutput &&
622
 
            (dao->cols > 1 || dao->rows > 1) &&
623
 
            (col >= dao->cols || row >= dao->rows))
624
 
                return;
625
 
 
626
 
        col += dao->start_col;
627
 
        row += dao->start_row;
628
 
        if (col >= gnm_sheet_get_max_cols (dao->sheet) || row >= gnm_sheet_get_max_rows (dao->sheet))
629
 
                return;
630
 
 
631
 
        pos.col = col;
632
 
        pos.row = row;
633
 
        cell_set_comment (dao->sheet, &pos, author, comment, NULL);
 
600
        GnmRange r;
 
601
 
 
602
        range_init (&r, col, row, col, row);
 
603
 
 
604
        if (adjust_range (dao, &r))
 
605
                cell_set_comment (dao->sheet, &r.start, author, comment, NULL);
634
606
}
635
607
 
636
608
 
714
686
dao_set_style (data_analysis_output_t *dao, int col1, int row1,
715
687
              int col2, int row2, GnmStyle *mstyle)
716
688
{
717
 
        GnmRange  range;
718
 
 
719
 
        range.start.col = col1 + dao->start_col + dao->offset_col;
720
 
        range.start.row = row1 + dao->start_row + dao->offset_row;
721
 
        range.end.col   = col2 + dao->start_col + dao->offset_col;
722
 
        range.end.row   = row2 + dao->start_row + dao->offset_row;
723
 
 
724
 
        if (range.end.col > dao->start_col + dao->cols)
725
 
                range.end.col = dao->start_col + dao->cols;
726
 
        if (range.end.row > dao->start_row + dao->rows)
727
 
                range.end.row = dao->start_row + dao->rows;
728
 
 
729
 
        if (range.end.col < range.start.col) {
730
 
                gnm_style_unref (mstyle);
731
 
                return;
732
 
        }
733
 
        if (range.end.row < range.start.row) {
734
 
                gnm_style_unref (mstyle);
735
 
                return;
736
 
        }
737
 
 
738
 
        sheet_style_apply_range (dao->sheet, &range, mstyle);
 
689
        GnmRange r;
 
690
 
 
691
        range_init (&r, col1, row1, col2, row2);
 
692
 
 
693
        if (!adjust_range (dao, &r)) {
 
694
                gnm_style_unref (mstyle);
 
695
                return;
 
696
        }
 
697
 
 
698
        sheet_style_apply_range (dao->sheet, &r, mstyle);
739
699
}
740
700
 
741
701
/**
755
715
              int col2, int row2)
756
716
{
757
717
        GnmStyle *mstyle = gnm_style_new ();
758
 
        GnmRange  range;
759
 
 
760
 
        range.start.col = col1 + dao->start_col;
761
 
        range.start.row = row1 + dao->start_row;
762
 
        range.end.col   = col2 + dao->start_col;
763
 
        range.end.row   = row2 + dao->start_row;
764
718
 
765
719
        gnm_style_set_font_bold (mstyle, TRUE);
766
 
        sheet_style_apply_range (dao->sheet, &range, mstyle);
 
720
 
 
721
        dao_set_style (dao, col1, row1, col2, row2, mstyle);
767
722
}
768
723
 
769
724
/**
783
738
                    int col2, int row2)
784
739
{
785
740
        GnmStyle *mstyle = gnm_style_new ();
786
 
        GnmRange  range;
787
 
 
788
 
        range.start.col = col1 + dao->start_col;
789
 
        range.start.row = row1 + dao->start_row;
790
 
        range.end.col   = col2 + dao->start_col;
791
 
        range.end.row   = row2 + dao->start_row;
792
741
 
793
742
        gnm_style_set_font_uline (mstyle, TRUE);
794
 
        sheet_style_apply_range (dao->sheet, &range, mstyle);
 
743
 
 
744
        dao_set_style (dao, col1, row1, col2, row2, mstyle);
795
745
}
796
746
 
797
747
/**
936
886
        dao_set_style (dao, col1, row1, col2, row2, mstyle);
937
887
}
938
888
 
 
889
/**
 
890
 * dao_set_border:
 
891
 * @dao:
 
892
 * @col1:
 
893
 * @row1:
 
894
 * @col2:
 
895
 * @row2:
 
896
 *
 
897
 *
 
898
 *
 
899
 **/
 
900
void
 
901
dao_set_border (data_analysis_output_t *dao, int col1, int row1,
 
902
               int col2, int row2,
 
903
                GnmStyleElement elem, GnmStyleBorderType border,
 
904
                GnmColor *color,
 
905
                GnmStyleBorderOrientation orientation)
 
906
{
 
907
        GnmStyle *mstyle;
 
908
 
 
909
        mstyle = gnm_style_new ();
 
910
        gnm_style_set_border (mstyle, elem, 
 
911
                              gnm_style_border_fetch (border,
 
912
                                                      color, 
 
913
                                                      orientation));
 
914
        dao_set_style (dao, col1, row1, col2, row2, mstyle);
 
915
}
 
916
 
 
917
 
939
918
 
940
919
/**
941
920
 * dao_get_colrow_state_list:
1002
981
        GTimeVal  t;
1003
982
        g_get_current_time (&t);
1004
983
        now = t.tv_sec;
1005
 
        g_date_set_time (&date, t.tv_sec);
 
984
        g_date_set_time (&date, t.tv_sec);
1006
985
#endif
1007
986
        g_date_to_struct_tm (&date, &tm_s);
1008
987
        tm_s.tm_sec  = now % 60;
1216
1195
{
1217
1196
        dao->omit_so = omit;
1218
1197
}
 
1198
 
 
1199
 
 
1200
 
 
1201
void 
 
1202
dao_set_merge (data_analysis_output_t *dao, int col1, int row1,
 
1203
               int col2, int row2)
 
1204
{
 
1205
        GnmRange r;
 
1206
 
 
1207
        range_init (&r, col1, row1, col2, row2);
 
1208
        if (adjust_range (dao, &r))
 
1209
                gnm_sheet_merge_add (dao->sheet, &r, TRUE, NULL);
 
1210
}