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

« back to all changes in this revision

Viewing changes to src/sheet-object.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:
9
9
 *   Jody Goldberg   (jody@gnome.org)
10
10
 */
11
11
#include <gnumeric-config.h>
12
 
#include <glib/gi18n.h>
 
12
#include <glib/gi18n-lib.h>
13
13
#include "gnumeric.h"
14
14
#include "sheet-object.h"
15
15
 
104
104
}
105
105
 
106
106
static void
107
 
sheet_object_populate_menu (SheetObject *so, GPtrArray *actions)
 
107
sheet_object_populate_menu_real (SheetObject *so, GPtrArray *actions)
108
108
{
109
109
        static SheetObjectAction const so_actions [] = {
110
110
                { "gtk-properties",     NULL,           NULL,  0, sheet_object_get_editor },
127
127
}
128
128
 
129
129
/**
 
130
 * sheet_object_populate_menu :
 
131
 * @so : #SheetObject optionally NULL
 
132
 * @actions : #GPtrArray
 
133
 *
 
134
 * Get a list of the actions that can be performed on @so, if @so is NULL use
 
135
 * the default set.
 
136
 **/
 
137
void
 
138
sheet_object_populate_menu (SheetObject *so, GPtrArray *actions)
 
139
{
 
140
        if (NULL != so)
 
141
                SHEET_OBJECT_CLASS (G_OBJECT_GET_CLASS(so))->populate_menu (so, actions);
 
142
        else
 
143
                sheet_object_populate_menu (NULL, actions);
 
144
}
 
145
 
 
146
/**
130
147
 * sheet_objects_max_extent :
131
148
 * @sheet :
132
149
 *
176
193
        /* Store the logical position as A1 */
177
194
        so->anchor.cell_bound.start.col = so->anchor.cell_bound.start.row = 0;
178
195
        so->anchor.cell_bound.end.col = so->anchor.cell_bound.end.row = 1;
179
 
        so->anchor.direction = SO_DIR_UNKNOWN;
 
196
        so->anchor.base.direction = GOD_ANCHOR_DIR_UNKNOWN;
180
197
 
181
198
        for (i = 4; i-- > 0 ;) {
182
199
                so->anchor.offset [i] = 0.;
199
216
 
200
217
        parent_klass = g_type_class_peek_parent (klass);
201
218
        klass->finalize = sheet_object_finalize;
202
 
        sheet_object_class->populate_menu        = sheet_object_populate_menu;
 
219
        sheet_object_class->populate_menu        = sheet_object_populate_menu_real;
203
220
        sheet_object_class->print                = NULL;
204
221
        sheet_object_class->user_config          = NULL;
205
222
        sheet_object_class->rubber_band_directly = FALSE;
206
223
        sheet_object_class->default_size         = so_default_size;
207
224
        sheet_object_class->xml_export_name      = NULL;
 
225
        sheet_object_class->invalidate_sheet     = NULL;
208
226
 
209
227
        signals [BOUNDS_CHANGED] = g_signal_new ("bounds-changed",
210
228
                SHEET_OBJECT_TYPE,
396
414
        return FALSE;
397
415
}
398
416
 
 
417
void
 
418
sheet_object_invalidate_sheet (SheetObject *so, Sheet const *sheet)
 
419
{
 
420
        if (SO_CLASS (so)->invalidate_sheet)
 
421
                SO_CLASS (so)->invalidate_sheet (so, sheet);
 
422
}
 
423
 
399
424
static void
400
425
cb_sheet_object_view_finalized (SheetObject *so, GObject *view)
401
426
{
454
479
                SO_CLASS (so)->print (so, ctx, width, height);
455
480
}
456
481
 
 
482
/**
 
483
 * sheet_object_draw_cairo :
 
484
 *
 
485
 * Draw a sheet object using cairo.
 
486
 **/
 
487
void
 
488
sheet_object_draw_cairo (SheetObject const *so, gpointer *data)
 
489
{
 
490
#ifdef GOFFICE_WITH_CAIRO
 
491
        if (SO_CLASS (so)->draw_cairo) {
 
492
                cairo_t *cairo = (cairo_t*) data;
 
493
                SheetObjectAnchor const *anchor;
 
494
                double x = 0., y = 0., width, height, cell_width, cell_height;
 
495
                anchor = sheet_object_get_anchor (so);
 
496
                width = sheet_col_get_distance_pts (so->sheet,
 
497
                                        anchor->cell_bound.start.col,
 
498
                                        anchor->cell_bound.end.col + 1);
 
499
                height = sheet_row_get_distance_pts (so->sheet,
 
500
                                        anchor->cell_bound.start.row,
 
501
                                        anchor->cell_bound.end.row + 1);
 
502
                cell_width = sheet_col_get_distance_pts (so->sheet,
 
503
                                        anchor->cell_bound.start.col,
 
504
                                        anchor->cell_bound.start.col + 1);
 
505
                cell_height = sheet_row_get_distance_pts (so->sheet,
 
506
                                        anchor->cell_bound.start.row,
 
507
                                        anchor->cell_bound.start.row + 1);
 
508
                switch (anchor->type[0]) {
 
509
                case SO_ANCHOR_UNKNOWN:
 
510
                case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
 
511
                        x = cell_width * anchor->offset[0];
 
512
                        break;
 
513
                case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
 
514
                        x = cell_width * (1. - anchor->offset[0]);
 
515
                        break;
 
516
                case SO_ANCHOR_PTS_FROM_COLROW_START:
 
517
                        x = anchor->offset[0];
 
518
                        break;
 
519
                case SO_ANCHOR_PTS_FROM_COLROW_END:
 
520
                        x = cell_width - anchor->offset[0];
 
521
                        break;
 
522
                default:
 
523
                        break;
 
524
                }
 
525
                width -= x;     
 
526
                switch (anchor->type[1]) {
 
527
                case SO_ANCHOR_UNKNOWN:
 
528
                case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
 
529
                        y = cell_height * anchor->offset[1];
 
530
                        break;
 
531
                case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
 
532
                        y = cell_height * (1 - anchor->offset[1]);
 
533
                        break;
 
534
                case SO_ANCHOR_PTS_FROM_COLROW_START:
 
535
                        y = anchor->offset[1];
 
536
                        break;
 
537
                case SO_ANCHOR_PTS_FROM_COLROW_END:
 
538
                        y = cell_height - anchor->offset[1];
 
539
                        break;
 
540
                default:
 
541
                        break;
 
542
                }       
 
543
                height -= y;
 
544
                cell_width = sheet_col_get_distance_pts (so->sheet,
 
545
                                        anchor->cell_bound.end.col,
 
546
                                        anchor->cell_bound.end.col + 1);
 
547
                cell_height = sheet_row_get_distance_pts (so->sheet,
 
548
                                        anchor->cell_bound.end.row,
 
549
                                        anchor->cell_bound.end.row + 1);
 
550
                switch (anchor->type[2]) {
 
551
                case SO_ANCHOR_UNKNOWN:
 
552
                case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
 
553
                        width -= cell_width * (1. - anchor->offset[2]);
 
554
                        break;
 
555
                case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
 
556
                        width -= cell_width * anchor->offset[2];
 
557
                        break;
 
558
                case SO_ANCHOR_PTS_FROM_COLROW_START:
 
559
                        width -= cell_width - anchor->offset[2];
 
560
                        break;
 
561
                case SO_ANCHOR_PTS_FROM_COLROW_END:
 
562
                        width -= anchor->offset[2];
 
563
                        break;
 
564
                case SO_ANCHOR_PTS_ABSOLUTE:
 
565
                        width = anchor->offset[2];
 
566
                        break;
 
567
                default:
 
568
                        break;
 
569
                }               
 
570
                switch (anchor->type[3]) {
 
571
                case SO_ANCHOR_UNKNOWN:
 
572
                case SO_ANCHOR_PERCENTAGE_FROM_COLROW_START:
 
573
                        height -= cell_height * (1 - anchor->offset[3]);
 
574
                        break;
 
575
                case SO_ANCHOR_PERCENTAGE_FROM_COLROW_END:
 
576
                        height -= cell_height * anchor->offset[3];
 
577
                        break;
 
578
                case SO_ANCHOR_PTS_FROM_COLROW_START:
 
579
                        height -= cell_height - anchor->offset[3];
 
580
                        break;
 
581
                case SO_ANCHOR_PTS_FROM_COLROW_END:
 
582
                        height -= anchor->offset[3];
 
583
                        break;
 
584
                case SO_ANCHOR_PTS_ABSOLUTE:
 
585
                        height = anchor->offset[3];
 
586
                        break;
 
587
                default:
 
588
                        break;
 
589
                }
 
590
                /* we don't need to save/restore cairo, the caller must do it */
 
591
                cairo_translate (cairo, x, y);
 
592
                SO_CLASS (so)->draw_cairo (so, cairo, width, height);
 
593
        }
 
594
#endif
 
595
}
 
596
 
457
597
GnmRange const *
458
598
sheet_object_get_range (SheetObject const *so)
459
599
{
777
917
void
778
918
sheet_object_direction_set (SheetObject *so, gdouble const *coords)
779
919
{
780
 
        if (so->anchor.direction == SO_DIR_UNKNOWN)
 
920
        if (so->anchor.base.direction == GOD_ANCHOR_DIR_UNKNOWN)
781
921
                return;
782
922
 
783
 
        so->anchor.direction = SO_DIR_NONE_MASK;
 
923
        so->anchor.base.direction = GOD_ANCHOR_DIR_NONE_MASK;
784
924
 
785
925
        if (coords [1] < coords [3])
786
 
                so->anchor.direction |= SO_DIR_DOWN;
 
926
                so->anchor.base.direction |= GOD_ANCHOR_DIR_DOWN;
787
927
        if (coords [0] < coords [2])
788
 
                so->anchor.direction |= SO_DIR_RIGHT;
789
 
 
 
928
                so->anchor.base.direction |= GOD_ANCHOR_DIR_RIGHT;
790
929
}
791
930
 
792
931
/**
814
953
sheet_object_anchor_init (SheetObjectAnchor *anchor,
815
954
                          GnmRange const *r, float const *offsets,
816
955
                          SheetObjectAnchorType const *types,
817
 
                          SheetObjectDirection direction)
 
956
                          GODrawingAnchorDir direction)
818
957
{
819
958
        int i;
820
959
 
843
982
        for (i = 4; i-- > 0 ; )
844
983
                anchor->type [i] = types [i];
845
984
 
846
 
        anchor->direction = direction;
 
985
        anchor->base.direction = direction;
847
986
        /* TODO : add sanity checking to handle offsets past edges of col/row */
848
987
}
849
988
 
968
1107
}
969
1108
 
970
1109
void
971
 
sheet_object_write_image (SheetObject const *so, const char *format, double resolution,
 
1110
sheet_object_write_image (SheetObject const *so, char const *format, double resolution,
972
1111
                          GsfOutput *output, GError **err)
973
1112
{
974
1113
        g_return_if_fail (IS_SHEET_OBJECT_IMAGEABLE (so));
1011
1150
}
1012
1151
 
1013
1152
void
1014
 
sheet_object_write_object (SheetObject const *so, const char *format,
 
1153
sheet_object_write_object (SheetObject const *so, char const *format,
1015
1154
                          GsfOutput *output, GError **err)
1016
1155
{
1017
1156
        g_return_if_fail (IS_SHEET_OBJECT_EXPORTABLE (so));