2 * corba-sheet.c: The implementation of the Sheet CORBA interfaces
6 * Miguel de Icaza (miguel@gnu.org)
10 * Strings representing ranges, when parsed ignore relative strings.
13 #include <libgnorba/gnome-factory.h>
16 #include "selection.h"
18 #include "idl/Gnumeric.h"
22 #include "selection.h"
24 #include "command-context-corba.h"
28 #include "sheet-private.h"
30 #define verify(cond) if (!(cond)){ out_of_range (ev); return; }
31 #define verify_val(cond,val) if (!(cond)){ out_of_range (ev); return (val); }
32 #define verify_col(c) verify (((c) >= 0 && (c < SHEET_MAX_COLS)))
33 #define verify_col_val(c,val) verify_val (((c) >= 0 && (c < SHEET_MAX_COLS)),val)
34 #define verify_row(c) verify (((c) >= 0 && (c < SHEET_MAX_ROWS)))
35 #define verify_row_val(c,val) verify_val (((c) >= 0 && (c < SHEET_MAX_ROWS)),val)
36 #define verify_region(c1,r1,c2,r2) \
37 verify_col(c1); verify_col(c2); verify_row(r1); verify_row(r2); \
41 #define verify_range(sheet,range,l) \
42 if (!corba_range_parse (sheet,range,l)) \
43 { out_of_range (ev); return; }
45 #define verify_range_val(sheet,range,l,val) \
46 if (!corba_range_parse (sheet,range,l)) \
47 { out_of_range (ev); return (val); }
49 static POA_GNOME_Gnumeric_Sheet__vepv gnome_gnumeric_sheet_vepv
;
50 static POA_GNOME_Gnumeric_Sheet__epv gnome_gnumeric_sheet_epv
;
53 POA_GNOME_Gnumeric_Sheet servant
;
58 out_of_range (CORBA_Environment
*ev
)
60 CORBA_exception_set (ev
, CORBA_USER_EXCEPTION
, ex_GNOME_Gnumeric_Sheet_OutOfRange
, NULL
);
64 * Parses a list of ranges, returns a GList containing pointers to
65 * Value structures. Sets the return_list pointer to point to a
66 * a list of those values.
68 * Returns TRUE on successfully parsing the string, FALSE otherwise
71 corba_range_parse (Sheet
*sheet
, const char *range_spec
, GSList
**return_list
)
75 list
= range_list_parse (sheet
, range_spec
, TRUE
);
86 sheet_from_servant (PortableServer_Servant servant
)
88 SheetServant
*ss
= (SheetServant
*) servant
;
94 Sheet_cursor_set (PortableServer_Servant servant
,
95 const CORBA_long base_col
,
96 const CORBA_long base_row
,
97 const CORBA_long start_col
,
98 const CORBA_long start_row
,
99 const CORBA_long end_col
,
100 const CORBA_long end_row
,
101 CORBA_Environment
*ev
)
103 Sheet
*sheet
= sheet_from_servant (servant
);
105 verify_region (start_col
, start_row
, end_col
, end_row
);
106 verify ((base_col
> 0) && (base_row
> 0));
107 verify ((base_row
>= start_row
) && (base_row
<= end_row
) &&
108 (base_col
>= start_col
) && (base_col
<= end_col
));
110 sheet_cursor_set (sheet
, base_col
, base_row
, start_col
, start_row
, end_col
, end_row
);
114 Sheet_cursor_move (PortableServer_Servant servant
, const CORBA_long col
, const CORBA_long row
, CORBA_Environment
*ev
)
116 Sheet
*sheet
= sheet_from_servant (servant
);
121 sheet_cursor_set (sheet
, col
, row
, col
, row
, col
, row
);
125 Sheet_make_cell_visible (PortableServer_Servant servant
, const CORBA_long col
, const CORBA_long row
, CORBA_Environment
*ev
)
127 Sheet
*sheet
= sheet_from_servant (servant
);
132 sheet_make_cell_visible (sheet
, col
, row
);
136 Sheet_select_all (PortableServer_Servant servant
, CORBA_Environment
*ev
)
138 Sheet
*sheet
= sheet_from_servant (servant
);
140 sheet_select_all (sheet
);
144 Sheet_is_all_selected (PortableServer_Servant servant
, CORBA_Environment
*ev
)
146 Sheet
*sheet
= sheet_from_servant (servant
);
148 return sheet_is_all_selected (sheet
);
152 Sheet_selection_reset (PortableServer_Servant servant
, CORBA_Environment
*ev
)
154 Sheet
*sheet
= sheet_from_servant (servant
);
156 sheet_selection_reset (sheet
);
160 Sheet_selection_append (PortableServer_Servant servant
,
161 const CORBA_long col
, const CORBA_long row
,
162 CORBA_Environment
*ev
)
164 Sheet
*sheet
= sheet_from_servant (servant
);
169 sheet_selection_add (sheet
, col
, row
);
173 Sheet_selection_append_range (PortableServer_Servant servant
,
174 const CORBA_long start_col
, const CORBA_long start_row
,
175 const CORBA_long end_col
, const CORBA_long end_row
,
176 CORBA_Environment
*ev
)
178 Sheet
*sheet
= sheet_from_servant (servant
);
180 verify_region (start_col
, start_row
, end_col
, end_row
);
182 sheet_selection_add_range (sheet
,
183 start_col
, start_row
,
184 start_col
, start_row
,
189 Sheet_selection_copy (PortableServer_Servant servant
, CORBA_Environment
*ev
)
191 Sheet
*sheet
= sheet_from_servant (servant
);
193 sheet_selection_copy (command_context_corba (sheet
->workbook
), sheet
);
197 Sheet_selection_cut (PortableServer_Servant servant
, CORBA_Environment
*ev
)
199 Sheet
*sheet
= sheet_from_servant (servant
);
201 sheet_selection_cut (command_context_corba (sheet
->workbook
), sheet
);
205 Sheet_selection_paste (PortableServer_Servant servant
,
206 const CORBA_long dest_col
, const CORBA_long dest_row
,
207 const CORBA_long paste_flags
, CORBA_Environment
*ev
)
209 Sheet
*sheet
= sheet_from_servant (servant
);
211 verify_col (dest_col
);
212 verify_row (dest_row
);
214 sheet_selection_paste (
215 command_context_corba (sheet
->workbook
), sheet
,
216 dest_col
, dest_row
, paste_flags
, 0);
220 Sheet_clear_region (PortableServer_Servant servant
,
221 const CORBA_long start_col
, const CORBA_long start_row
,
222 const CORBA_long end_col
, const CORBA_long end_row
,
223 CORBA_Environment
*ev
)
225 Sheet
*sheet
= sheet_from_servant (servant
);
227 verify_region (start_col
, start_row
, end_col
, end_row
);
230 command_context_corba (sheet
->workbook
),
231 sheet
, start_col
, start_row
,
232 end_col
, end_row
, CLEAR_VALUES
|CLEAR_FORMATS
|CLEAR_COMMENTS
);
236 Sheet_clear_region_content (PortableServer_Servant servant
,
237 const CORBA_long start_col
, const CORBA_long start_row
,
238 const CORBA_long end_col
, const CORBA_long end_row
,
239 CORBA_Environment
*ev
)
241 Sheet
*sheet
= sheet_from_servant (servant
);
243 verify_region (start_col
, start_row
, end_col
, end_row
);
246 command_context_corba (sheet
->workbook
),
247 sheet
, start_col
, start_row
,
248 end_col
, end_row
, CLEAR_VALUES
|CLEAR_COMMENTS
);
252 Sheet_clear_region_comments (PortableServer_Servant servant
,
253 const CORBA_long start_col
, const CORBA_long start_row
,
254 const CORBA_long end_col
, const CORBA_long end_row
,
255 CORBA_Environment
*ev
)
257 Sheet
*sheet
= sheet_from_servant (servant
);
259 verify_region (start_col
, start_row
, end_col
, end_row
);
262 command_context_corba (sheet
->workbook
),
263 sheet
, start_col
, start_row
,
264 end_col
, end_row
, CLEAR_COMMENTS
);
268 Sheet_clear_region_formats (PortableServer_Servant servant
,
269 const CORBA_long start_col
, const CORBA_long start_row
,
270 const CORBA_long end_col
, const CORBA_long end_row
,
271 CORBA_Environment
*ev
)
273 Sheet
*sheet
= sheet_from_servant (servant
);
275 verify_region (start_col
, start_row
, end_col
, end_row
);
278 command_context_corba (sheet
->workbook
),
279 sheet
, start_col
, start_row
,
280 end_col
, end_row
, CLEAR_FORMATS
);
284 Sheet_cell_set_value (PortableServer_Servant servant
,
285 const CORBA_long col
, const CORBA_long row
,
286 const GNOME_Gnumeric_Value
*value
,
287 CORBA_Environment
*ev
)
289 Sheet
*sheet
= sheet_from_servant (servant
);
296 cell
= sheet_cell_fetch (sheet
, col
, row
);
299 case GNOME_Gnumeric_VALUE_EMPTY
:
300 v
= value_new_empty ();
303 case GNOME_Gnumeric_VALUE_BOOLEAN
:
304 v
= value_new_bool (value
->_u
.v_bool
);
307 case GNOME_Gnumeric_VALUE_ERROR
:
308 v
= value_new_error (NULL
, value
->_u
.error
);
311 case GNOME_Gnumeric_VALUE_STRING
:
312 v
= value_new_string (value
->_u
.str
);
315 case GNOME_Gnumeric_VALUE_INTEGER
:
316 v
= value_new_int (value
->_u
.v_int
);
319 case GNOME_Gnumeric_VALUE_FLOAT
:
320 v
= value_new_float (value
->_u
.v_float
);
323 case GNOME_Gnumeric_VALUE_CELLRANGE
: {
326 parse_cell_name (value
->_u
.cell_range
.cell_a
, &a
.col
, &a
.row
, TRUE
, NULL
);
327 parse_cell_name (value
->_u
.cell_range
.cell_b
, &b
.col
, &b
.row
, TRUE
, NULL
);
334 v
= value_new_cellrange (&a
, &b
);
338 case GNOME_Gnumeric_VALUE_ARRAY
:
340 g_error ("FIXME: Implement me");
344 CORBA_exception_set (ev
, CORBA_USER_EXCEPTION
, ex_GNOME_Gnumeric_Sheet_InvalidValue
, NULL
);
348 cell_set_value (cell
, v
);
352 fill_corba_value (GNOME_Gnumeric_Value
*value
, Sheet
*sheet
, CORBA_long col
, CORBA_long row
)
357 g_assert (value
!= NULL
);
358 g_assert (sheet
!= NULL
);
360 parse_pos_init (&pp
, sheet
->workbook
, col
, row
);
361 cell
= sheet_cell_get (sheet
, col
, row
);
362 if (cell
&& cell
->value
) {
363 switch (cell
->value
->type
) {
365 value
->_d
= GNOME_Gnumeric_VALUE_EMPTY
;
369 value
->_d
= GNOME_Gnumeric_VALUE_BOOLEAN
;
370 value
->_u
.v_bool
= cell
->value
->v
.v_bool
;
374 value
->_d
= GNOME_Gnumeric_VALUE_ERROR
;
375 value
->_u
.error
= CORBA_string_dup (cell
->value
->v
.error
.mesg
->str
);
379 value
->_d
= GNOME_Gnumeric_VALUE_STRING
;
380 value
->_u
.str
= CORBA_string_dup (cell
->value
->v
.str
->str
);
384 value
->_d
= GNOME_Gnumeric_VALUE_INTEGER
;
385 value
->_u
.v_int
= cell
->value
->v
.v_int
;
389 value
->_d
= GNOME_Gnumeric_VALUE_FLOAT
;
390 value
->_u
.v_float
= cell
->value
->v
.v_float
;
393 case VALUE_CELLRANGE
: {
396 a
= cellref_name (&cell
->value
->v
.cell_range
.cell_a
, &pp
);
397 b
= cellref_name (&cell
->value
->v
.cell_range
.cell_b
, &pp
);
399 value
->_d
= GNOME_Gnumeric_VALUE_CELLRANGE
;
400 value
->_u
.cell_range
.cell_a
= CORBA_string_dup (a
);
401 value
->_u
.cell_range
.cell_b
= CORBA_string_dup (b
);
408 g_error ("FIXME: Implement me");
412 value
->_d
= GNOME_Gnumeric_VALUE_INTEGER
;
418 static GNOME_Gnumeric_Value
*
419 Sheet_cell_get_value (PortableServer_Servant servant
,
420 const CORBA_long col
, const CORBA_long row
,
421 CORBA_Environment
*ev
)
423 Sheet
*sheet
= sheet_from_servant (servant
);
424 GNOME_Gnumeric_Value
*value
;
426 verify_col_val (col
, NULL
);
427 verify_row_val (row
, NULL
);
429 value
= GNOME_Gnumeric_Value__alloc ();
431 fill_corba_value (value
, sheet
, col
, row
);
436 Sheet_cell_set_text (PortableServer_Servant servant
,
437 const CORBA_long col
, const CORBA_long row
,
438 const CORBA_char
* text
, CORBA_Environment
*ev
)
440 Sheet
*sheet
= sheet_from_servant (servant
);
446 cell
= sheet_cell_fetch (sheet
, col
, row
);
447 cell_set_text (cell
, text
);
451 Sheet_cell_get_text (PortableServer_Servant servant
,
452 const CORBA_long col
,
453 const CORBA_long row
,
454 CORBA_Environment
*ev
)
456 Sheet
*sheet
= sheet_from_servant (servant
);
459 verify_col_val (col
, NULL
);
460 verify_row_val (row
, NULL
);
462 cell
= sheet_cell_get (sheet
, col
, row
);
466 str
= cell_get_text (cell
);
467 return CORBA_string_dup (str
);
469 return CORBA_string_dup ("");
474 Sheet_cell_set_formula (PortableServer_Servant servant
,
475 const CORBA_long col
,
476 const CORBA_long row
,
477 const CORBA_char
* formula
,
478 CORBA_Environment
*ev
)
480 Sheet
*sheet
= sheet_from_servant (servant
);
486 cell
= sheet_cell_fetch (sheet
, col
, row
);
487 cell_set_formula (cell
, formula
);
491 Sheet_cell_set_format (PortableServer_Servant servant
,
492 const CORBA_long col
,
493 const CORBA_long row
,
494 const CORBA_char
* format
,
495 CORBA_Environment
*ev
)
497 Sheet
*sheet
= sheet_from_servant (servant
);
503 cell
= sheet_cell_fetch (sheet
, col
, row
);
504 cell_set_format (cell
, format
);
508 Sheet_cell_get_format (PortableServer_Servant servant
,
509 const CORBA_long col
,
510 const CORBA_long row
,
511 CORBA_Environment
*ev
)
514 Sheet
*sheet
= sheet_from_servant (servant
);
517 verify_col_val (col
, NULL
);
518 verify_row_val (row
, NULL
);
520 mstyle
= sheet_style_compute (sheet
, col
, row
);
521 ans
= CORBA_string_dup (mstyle_get_format (mstyle
)->format
);
522 mstyle_unref (mstyle
);
528 Sheet_cell_set_font (PortableServer_Servant servant
,
529 const CORBA_long col
,
530 const CORBA_long row
,
531 const CORBA_char
* font
,
532 const CORBA_double points
,
533 CORBA_Environment
*ev
)
535 MStyle
*mstyle
= mstyle_new ();
536 mstyle_set_font_name (mstyle
, font
);
537 mstyle_set_font_size (mstyle
, points
);
538 sheet_style_attach_single (sheet_from_servant (servant
),
543 Sheet_cell_get_font (PortableServer_Servant servant
, const CORBA_long col
, const CORBA_long row
, CORBA_Environment
*ev
)
546 Sheet
*sheet
= sheet_from_servant (servant
);
549 verify_col_val (col
, NULL
);
550 verify_row_val (row
, NULL
);
552 mstyle
= sheet_style_compute (sheet
, col
, row
);
553 ans
= CORBA_string_dup (mstyle_get_font_name (mstyle
));
554 mstyle_unref (mstyle
);
560 Sheet_cell_set_comment (PortableServer_Servant servant
,
561 const CORBA_long col
, const CORBA_long row
,
562 const CORBA_char
* comment
, CORBA_Environment
*ev
)
564 Sheet
*sheet
= sheet_from_servant (servant
);
570 cell
= sheet_cell_fetch (sheet
, col
, row
);
571 cell_set_comment (cell
, comment
);
575 Sheet_cell_get_comment (PortableServer_Servant servant
,
576 const CORBA_long col
, const CORBA_long row
,
577 CORBA_Environment
*ev
)
579 Sheet
*sheet
= sheet_from_servant (servant
);
582 verify_col_val (col
, NULL
);
583 verify_row_val (row
, NULL
);
585 cell
= sheet_cell_get (sheet
, col
, row
);
587 return CORBA_string_dup (cell
->comment
->comment
->str
);
589 return CORBA_string_dup ("");
593 Sheet_cell_set_foreground (PortableServer_Servant servant
,
594 const CORBA_long col
, const CORBA_long row
,
595 const CORBA_char
* color
, CORBA_Environment
*ev
)
598 MStyle
*mstyle
= mstyle_new ();
603 gdk_color_parse (color
, &c
);
604 mstyle_set_color (mstyle
, MSTYLE_COLOR_FORE
,
605 style_color_new (c
.red
, c
.green
, c
.blue
));
606 sheet_style_attach_single (sheet_from_servant (servant
),
611 Sheet_cell_get_foreground (PortableServer_Servant servant
,
612 const CORBA_long col
, const CORBA_long row
,
613 CORBA_Environment
*ev
)
615 g_warning ("cell get foreground deprecated");
621 Sheet_cell_set_background (PortableServer_Servant servant
,
622 const CORBA_long col
, const CORBA_long row
,
623 const CORBA_char
* color
, CORBA_Environment
*ev
)
626 MStyle
*mstyle
= mstyle_new ();
631 gdk_color_parse (color
, &c
);
632 mstyle_set_color (mstyle
, MSTYLE_COLOR_BACK
,
633 style_color_new (c
.red
, c
.green
, c
.blue
));
634 sheet_style_attach_single (sheet_from_servant (servant
),
639 Sheet_cell_get_background (PortableServer_Servant servant
,
640 const CORBA_long col
, const CORBA_long row
,
641 CORBA_Environment
*ev
)
643 g_warning ("Deprecated cell get background");
648 Sheet_cell_set_pattern (PortableServer_Servant servant
,
649 const CORBA_long col
, const CORBA_long row
,
650 const CORBA_long pattern
, CORBA_Environment
*ev
)
652 MStyle
*mstyle
= mstyle_new ();
657 mstyle_set_pattern (mstyle
, pattern
);
658 sheet_style_attach_single (sheet_from_servant (servant
),
663 Sheet_cell_get_pattern (PortableServer_Servant servant
,
664 const CORBA_long col
, const CORBA_long row
,
665 CORBA_Environment
*ev
)
668 Sheet
*sheet
= sheet_from_servant (servant
);
671 verify_col_val (col
, 0);
672 verify_row_val (row
, 0);
674 mstyle
= sheet_style_compute (sheet
, col
, row
);
675 ans
= mstyle_get_pattern (mstyle
);
676 mstyle_unref (mstyle
);
682 Sheet_cell_set_alignment (PortableServer_Servant servant
,
683 const CORBA_long col
, const CORBA_long row
,
684 const CORBA_long halign
, const CORBA_long valign
,
685 const CORBA_long orientation
, const CORBA_boolean auto_return
,
686 CORBA_Environment
*ev
)
689 MStyle
*mstyle
= mstyle_new ();
695 case GNOME_Gnumeric_Sheet_HALIGN_GENERAL
:
699 case GNOME_Gnumeric_Sheet_HALIGN_LEFT
:
703 case GNOME_Gnumeric_Sheet_HALIGN_RIGHT
:
707 case GNOME_Gnumeric_Sheet_HALIGN_CENTER
:
711 case GNOME_Gnumeric_Sheet_HALIGN_FILL
:
715 case GNOME_Gnumeric_Sheet_HALIGN_JUSTIFY
:
719 case GNOME_Gnumeric_Sheet_HALIGN_CENTER_ACROSS_SELECTION
:
720 h
= HALIGN_CENTER_ACROSS_SELECTION
;
728 case GNOME_Gnumeric_Sheet_VALIGN_TOP
:
732 case GNOME_Gnumeric_Sheet_VALIGN_BOTTOM
:
736 case GNOME_Gnumeric_Sheet_VALIGN_CENTER
:
740 case GNOME_Gnumeric_Sheet_VALIGN_JUSTIFY
:
749 mstyle_set_align_v (mstyle
, v
);
750 mstyle_set_align_h (mstyle
, h
);
751 sheet_style_attach_single (sheet_from_servant (servant
),
756 Sheet_cell_get_alignment (PortableServer_Servant servant
,
757 const CORBA_long col
, const CORBA_long row
,
758 CORBA_long
* halign
, CORBA_long
* valign
,
759 CORBA_long
* orientation
, CORBA_boolean
* auto_return
,
760 CORBA_Environment
*ev
)
767 mstyle
= sheet_style_compute (sheet_from_servant (servant
), col
, row
);
769 switch (mstyle_get_align_h (mstyle
)) {
771 *halign
= GNOME_Gnumeric_Sheet_HALIGN_GENERAL
;
775 *halign
= GNOME_Gnumeric_Sheet_HALIGN_LEFT
;
779 *halign
= GNOME_Gnumeric_Sheet_HALIGN_RIGHT
;
783 *halign
= GNOME_Gnumeric_Sheet_HALIGN_CENTER
;
787 *halign
= GNOME_Gnumeric_Sheet_HALIGN_FILL
;
791 *halign
= GNOME_Gnumeric_Sheet_HALIGN_JUSTIFY
;
794 case HALIGN_CENTER_ACROSS_SELECTION
:
795 *halign
= GNOME_Gnumeric_Sheet_HALIGN_CENTER_ACROSS_SELECTION
;
799 g_assert_not_reached ();
802 switch (mstyle_get_align_v (mstyle
)) {
804 *valign
= GNOME_Gnumeric_Sheet_VALIGN_TOP
;
808 *valign
= GNOME_Gnumeric_Sheet_VALIGN_BOTTOM
;
812 *valign
= GNOME_Gnumeric_Sheet_VALIGN_CENTER
;
816 *valign
= GNOME_Gnumeric_Sheet_VALIGN_JUSTIFY
;
819 *orientation
= mstyle_get_orientation (mstyle
);
820 *auto_return
= mstyle_get_fit_in_cell (mstyle
);
822 mstyle_unref (mstyle
);
826 Sheet_set_dirty (PortableServer_Servant servant
, const CORBA_boolean is_dirty
, CORBA_Environment
*ev
)
828 Sheet
*sheet
= sheet_from_servant (servant
);
830 sheet
->modified
= is_dirty
;
834 Sheet_insert_col (PortableServer_Servant servant
,
835 const CORBA_long col
, const CORBA_long count
,
836 CORBA_Environment
*ev
)
838 Sheet
*sheet
= sheet_from_servant (servant
);
842 command_context_corba (sheet
->workbook
), sheet
,
847 Sheet_delete_col (PortableServer_Servant servant
,
848 const CORBA_long col
, const CORBA_long count
,
849 CORBA_Environment
*ev
)
851 Sheet
*sheet
= sheet_from_servant (servant
);
855 command_context_corba (sheet
->workbook
), sheet
,
860 Sheet_insert_row (PortableServer_Servant servant
,
861 const CORBA_long row
, const CORBA_long count
,
862 CORBA_Environment
*ev
)
864 Sheet
*sheet
= sheet_from_servant (servant
);
868 command_context_corba (sheet
->workbook
), sheet
,
873 Sheet_delete_row (PortableServer_Servant servant
,
874 const CORBA_long row
, const CORBA_long count
,
875 CORBA_Environment
*ev
)
877 Sheet
*sheet
= sheet_from_servant (servant
);
881 command_context_corba (sheet
->workbook
), sheet
,
886 Sheet_shift_rows (PortableServer_Servant servant
,
887 const CORBA_long col
, const CORBA_long start_row
,
888 const CORBA_long end_row
, const CORBA_long count
,
889 CORBA_Environment
*ev
)
891 Sheet
*sheet
= sheet_from_servant (servant
);
893 verify_row (start_row
);
894 verify_row (end_row
);
898 command_context_corba (sheet
->workbook
), sheet
,
899 col
, start_row
, end_row
, count
);
903 Sheet_shift_cols (PortableServer_Servant servant
,
904 const CORBA_long col
,
905 const CORBA_long start_row
, const CORBA_long end_row
,
906 const CORBA_long count
, CORBA_Environment
*ev
)
908 Sheet
*sheet
= sheet_from_servant (servant
);
911 verify_row (start_row
);
912 verify_row (end_row
);
915 command_context_corba (sheet
->workbook
), sheet
,
916 col
, start_row
, end_row
, count
);
919 static GNOME_Gnumeric_Sheet_ValueVector
*
920 Sheet_range_get_values (PortableServer_Servant servant
, const CORBA_char
*range
, CORBA_Environment
*ev
)
922 GNOME_Gnumeric_Sheet_ValueVector
*vector
;
923 Sheet
*sheet
= sheet_from_servant (servant
);
927 verify_range_val (sheet
, range
, &ranges
, NULL
);
930 * Find out how big is the array we need to return
933 for (l
= ranges
; l
; l
= l
->next
){
934 Value
*value
= l
->data
;
938 g_assert (value
->type
== VALUE_CELLRANGE
);
940 a
= value
->v
.cell_range
.cell_a
;
941 b
= value
->v
.cell_range
.cell_b
;
943 cols
= abs (b
.col
- a
.col
) + 1;
944 rows
= abs (b
.row
- a
.row
) + 1;
949 vector
= GNOME_Gnumeric_Sheet_ValueVector__alloc ();
950 vector
->_buffer
= CORBA_sequence_GNOME_Gnumeric_Value_allocbuf (size
);
952 /* No memory, return an empty vector */
953 if (vector
->_buffer
== NULL
) {
955 vector
->_maximum
= 0;
963 for (i
= 0, l
= ranges
; l
; l
= l
->next
, i
++) {
964 Value
*value
= l
->data
;
968 a
= value
->v
.cell_range
.cell_a
;
969 b
= value
->v
.cell_range
.cell_b
;
971 for (col
= a
.col
; col
<= b
.col
; col
++)
972 for (row
= a
.row
; row
< b
.row
; row
++)
973 fill_corba_value (&vector
->_buffer
[i
], sheet
, col
, row
);
976 range_list_destroy (ranges
);
981 cb_range_set_text (Cell
*cell
, void *data
)
983 cell_set_text (cell
, data
);
987 Sheet_range_set_text (PortableServer_Servant servant
,
988 const CORBA_char
*range
,
989 const CORBA_char
*text
,
990 CORBA_Environment
*ev
)
992 Sheet
*sheet
= sheet_from_servant (servant
);
995 verify_range (sheet
, range
, &ranges
);
997 range_list_foreach_all (ranges
, cb_range_set_text
, (char *) text
);
999 range_list_destroy (ranges
);
1003 cb_range_set_formula (Cell
*cell
, void *data
)
1005 cell_set_formula (cell
, data
);
1009 Sheet_range_set_formula (PortableServer_Servant servant
,
1010 const CORBA_char
*range
,
1011 const CORBA_char
*formula
,
1012 CORBA_Environment
*ev
)
1014 Sheet
*sheet
= sheet_from_servant (servant
);
1017 verify_range (sheet
, range
, &ranges
);
1019 range_list_foreach_all (ranges
, cb_range_set_formula
, (char *)formula
);
1021 range_list_destroy (ranges
);
1025 Sheet_range_set_format (PortableServer_Servant servant
,
1026 const CORBA_char
*range
,
1027 const CORBA_char
*format
,
1028 CORBA_Environment
*ev
)
1030 Sheet
*sheet
= sheet_from_servant (servant
);
1034 verify_range (sheet
, range
, &ranges
);
1036 cell_freeze_redraws ();
1038 mstyle
= mstyle_new ();
1039 mstyle_set_format (mstyle
, format
);
1040 ranges_set_style (sheet
, ranges
, mstyle
);
1042 cell_thaw_redraws ();
1044 range_list_destroy (ranges
);
1048 Sheet_range_set_font (PortableServer_Servant servant
,
1049 const CORBA_char
*range
,
1050 const CORBA_char
*font
,
1052 CORBA_Environment
*ev
)
1054 Sheet
*sheet
= sheet_from_servant (servant
);
1058 verify_range (sheet
, range
, &ranges
);
1060 cell_freeze_redraws ();
1062 mstyle
= mstyle_new ();
1063 mstyle_set_font_name (mstyle
, font
);
1064 mstyle_set_font_size (mstyle
, points
);
1065 ranges_set_style (sheet
, ranges
, mstyle
);
1067 cell_thaw_redraws ();
1069 range_list_destroy (ranges
);
1073 Sheet_range_set_foreground (PortableServer_Servant servant
,
1074 const CORBA_char
*range
,
1075 const CORBA_char
*color
,
1076 CORBA_Environment
*ev
)
1078 Sheet
*sheet
= sheet_from_servant (servant
);
1083 verify_range (sheet
, range
, &ranges
);
1085 gdk_color_parse (color
, &c
);
1086 cell_freeze_redraws ();
1088 mstyle
= mstyle_new ();
1089 mstyle_set_color (mstyle
, MSTYLE_COLOR_FORE
,
1090 style_color_new (c
.red
, c
.green
, c
.blue
));
1091 ranges_set_style (sheet
, ranges
, mstyle
);
1093 cell_thaw_redraws ();
1095 range_list_destroy (ranges
);
1099 Sheet_range_set_background (PortableServer_Servant servant
,
1100 const CORBA_char
*range
,
1101 const CORBA_char
*color
,
1102 CORBA_Environment
*ev
)
1104 Sheet
*sheet
= sheet_from_servant (servant
);
1109 verify_range (sheet
, range
, &ranges
);
1111 gdk_color_parse (color
, &c
);
1112 cell_freeze_redraws ();
1114 mstyle
= mstyle_new ();
1115 mstyle_set_color (mstyle
, MSTYLE_COLOR_BACK
,
1116 style_color_new (c
.red
, c
.green
, c
.blue
));
1117 ranges_set_style (sheet
, ranges
, mstyle
);
1119 cell_thaw_redraws ();
1121 range_list_destroy (ranges
);
1125 Sheet_range_set_pattern (PortableServer_Servant servant
,
1126 const CORBA_char
*range
,
1128 CORBA_Environment
*ev
)
1130 Sheet
*sheet
= sheet_from_servant (servant
);
1134 verify_range (sheet
, range
, &ranges
);
1136 cell_freeze_redraws ();
1138 mstyle
= mstyle_new ();
1139 mstyle_set_pattern (mstyle
, pattern
);
1140 ranges_set_style (sheet
, ranges
, mstyle
);
1142 cell_thaw_redraws ();
1144 range_list_destroy (ranges
);
1148 Sheet_range_set_alignment (PortableServer_Servant servant
,
1149 const CORBA_char
*range
,
1152 CORBA_long orientation
,
1153 CORBA_boolean auto_return
,
1154 CORBA_Environment
*ev
)
1156 Sheet
*sheet
= sheet_from_servant (servant
);
1160 verify_range (sheet
, range
, &ranges
);
1162 mstyle
= mstyle_new ();
1163 mstyle_set_align_h (mstyle
, halign
);
1164 mstyle_set_align_v (mstyle
, valign
);
1165 mstyle_set_orientation (mstyle
, orientation
);
1166 mstyle_set_fit_in_cell (mstyle
, (gboolean
) auto_return
);
1167 ranges_set_style (sheet
, ranges
, mstyle
);
1169 cell_thaw_redraws ();
1171 range_list_destroy (ranges
);
1175 Sheet_max_cols_used (PortableServer_Servant servant
, CORBA_Environment
*ev
)
1177 Sheet
*sheet
= sheet_from_servant (servant
);
1178 Range extent
= sheet_get_extent (sheet
);
1180 return extent
.end
.col
;
1184 Sheet_max_rows_used (PortableServer_Servant servant
, CORBA_Environment
*ev
)
1186 Sheet
*sheet
= sheet_from_servant (servant
);
1187 Range extent
= sheet_get_extent (sheet
);
1189 return extent
.end
.row
;
1193 Sheet_col_width (PortableServer_Servant servant
, CORBA_long col
, CORBA_Environment
*ev
)
1195 Sheet
*sheet
= sheet_from_servant (servant
);
1198 verify_col_val (col
, 0.0);
1200 ci
= sheet_col_get_info (sheet
, col
);
1201 return ci
->size_pts
;
1205 Sheet_row_height (PortableServer_Servant servant
, CORBA_long row
, CORBA_Environment
*ev
)
1207 Sheet
*sheet
= sheet_from_servant (servant
);
1210 verify_row_val (row
, 0.0);
1212 ri
= sheet_row_get_info (sheet
, row
);
1213 return ri
->size_pts
;
1217 Sheet_corba_class_init (void)
1225 gnome_gnumeric_sheet_vepv
.GNOME_Gnumeric_Sheet_epv
=
1226 &gnome_gnumeric_sheet_epv
;
1228 gnome_gnumeric_sheet_epv
.cursor_set
= Sheet_cursor_set
;
1229 gnome_gnumeric_sheet_epv
.cursor_move
= Sheet_cursor_move
;
1230 gnome_gnumeric_sheet_epv
.make_cell_visible
= Sheet_make_cell_visible
;
1231 gnome_gnumeric_sheet_epv
.select_all
= Sheet_select_all
;
1232 gnome_gnumeric_sheet_epv
.is_all_selected
= Sheet_is_all_selected
;
1233 gnome_gnumeric_sheet_epv
.selection_reset
= Sheet_selection_reset
;
1234 gnome_gnumeric_sheet_epv
.selection_append
= Sheet_selection_append
;
1235 gnome_gnumeric_sheet_epv
.selection_append_range
= Sheet_selection_append_range
;
1236 gnome_gnumeric_sheet_epv
.selection_copy
= Sheet_selection_copy
;
1237 gnome_gnumeric_sheet_epv
.selection_cut
= Sheet_selection_cut
;
1238 gnome_gnumeric_sheet_epv
.selection_paste
= Sheet_selection_paste
;
1239 gnome_gnumeric_sheet_epv
.clear_region
= Sheet_clear_region
;
1240 gnome_gnumeric_sheet_epv
.clear_region_content
= Sheet_clear_region_content
;
1241 gnome_gnumeric_sheet_epv
.clear_region_comments
= Sheet_clear_region_comments
;
1242 gnome_gnumeric_sheet_epv
.clear_region_formats
= Sheet_clear_region_formats
;
1245 * Cell based routines
1247 gnome_gnumeric_sheet_epv
.cell_set_value
= Sheet_cell_set_value
;
1248 gnome_gnumeric_sheet_epv
.cell_get_value
= Sheet_cell_get_value
;
1249 gnome_gnumeric_sheet_epv
.cell_set_text
= Sheet_cell_set_text
;
1250 gnome_gnumeric_sheet_epv
.cell_get_text
= Sheet_cell_get_text
;
1251 gnome_gnumeric_sheet_epv
.cell_set_formula
= Sheet_cell_set_formula
;
1252 gnome_gnumeric_sheet_epv
.cell_set_format
= Sheet_cell_set_format
;
1253 gnome_gnumeric_sheet_epv
.cell_get_format
= Sheet_cell_get_format
;
1254 gnome_gnumeric_sheet_epv
.cell_set_font
= Sheet_cell_set_font
;
1255 gnome_gnumeric_sheet_epv
.cell_get_font
= Sheet_cell_get_font
;
1256 gnome_gnumeric_sheet_epv
.cell_set_foreground
= Sheet_cell_set_foreground
;
1257 gnome_gnumeric_sheet_epv
.cell_get_foreground
= Sheet_cell_get_foreground
;
1258 gnome_gnumeric_sheet_epv
.cell_set_background
= Sheet_cell_set_background
;
1259 gnome_gnumeric_sheet_epv
.cell_get_background
= Sheet_cell_get_background
;
1260 gnome_gnumeric_sheet_epv
.cell_set_pattern
= Sheet_cell_set_pattern
;
1261 gnome_gnumeric_sheet_epv
.cell_get_pattern
= Sheet_cell_get_pattern
;
1262 gnome_gnumeric_sheet_epv
.cell_set_alignment
= Sheet_cell_set_alignment
;
1263 gnome_gnumeric_sheet_epv
.cell_get_alignment
= Sheet_cell_get_alignment
;
1264 gnome_gnumeric_sheet_epv
.cell_set_comment
= Sheet_cell_set_comment
;
1265 gnome_gnumeric_sheet_epv
.cell_get_comment
= Sheet_cell_get_comment
;
1268 * Column manipulation
1270 gnome_gnumeric_sheet_epv
.insert_col
= Sheet_insert_col
;
1271 gnome_gnumeric_sheet_epv
.delete_col
= Sheet_delete_col
;
1272 gnome_gnumeric_sheet_epv
.insert_row
= Sheet_insert_row
;
1273 gnome_gnumeric_sheet_epv
.delete_row
= Sheet_delete_row
;
1274 gnome_gnumeric_sheet_epv
.shift_cols
= Sheet_shift_cols
;
1275 gnome_gnumeric_sheet_epv
.shift_rows
= Sheet_shift_rows
;
1278 * Region based routines
1280 gnome_gnumeric_sheet_epv
.range_get_values
= Sheet_range_get_values
;
1281 gnome_gnumeric_sheet_epv
.range_set_text
= Sheet_range_set_text
;
1282 gnome_gnumeric_sheet_epv
.range_set_formula
= Sheet_range_set_formula
;
1283 gnome_gnumeric_sheet_epv
.range_set_format
= Sheet_range_set_format
;
1284 gnome_gnumeric_sheet_epv
.range_set_font
= Sheet_range_set_font
;
1285 gnome_gnumeric_sheet_epv
.range_set_foreground
= Sheet_range_set_foreground
;
1286 gnome_gnumeric_sheet_epv
.range_set_background
= Sheet_range_set_background
;
1287 gnome_gnumeric_sheet_epv
.range_set_pattern
= Sheet_range_set_pattern
;
1288 gnome_gnumeric_sheet_epv
.range_set_alignment
= Sheet_range_set_alignment
;
1290 gnome_gnumeric_sheet_epv
.set_dirty
= Sheet_set_dirty
;
1295 gnome_gnumeric_sheet_epv
.max_cols_used
= Sheet_max_cols_used
;
1296 gnome_gnumeric_sheet_epv
.max_rows_used
= Sheet_max_rows_used
;
1297 gnome_gnumeric_sheet_epv
.row_height
= Sheet_row_height
;
1298 gnome_gnumeric_sheet_epv
.col_width
= Sheet_col_width
;
1302 sheet_corba_setup (Sheet
*sheet
)
1305 CORBA_Environment ev
;
1306 PortableServer_ObjectId
*objid
;
1308 Sheet_corba_class_init ();
1310 ss
= g_new0 (SheetServant
, 1);
1311 ss
->servant
.vepv
= &gnome_gnumeric_sheet_vepv
;
1314 CORBA_exception_init (&ev
);
1315 POA_GNOME_Gnumeric_Sheet__init ((PortableServer_Servant
) ss
, &ev
);
1316 objid
= PortableServer_POA_activate_object (gnumeric_poa
, ss
, &ev
);
1319 sheet
->private->corba_server
= PortableServer_POA_servant_to_reference (gnumeric_poa
, ss
, &ev
);
1321 CORBA_exception_free (&ev
);
1325 sheet_corba_shutdown (Sheet
*sheet
)
1327 CORBA_Environment ev
;
1329 g_return_if_fail (sheet
!= NULL
);
1330 g_return_if_fail (IS_SHEET (sheet
));
1331 g_return_if_fail (sheet
->private->corba_server
!= NULL
);
1333 g_warning ("Should release all the corba resources here");
1335 CORBA_exception_init (&ev
);
1336 PortableServer_POA_deactivate_object (gnumeric_poa
, sheet
->private->corba_server
, &ev
);
1337 CORBA_exception_free (&ev
);