#ifndef __GNUMERIC_IDL__
#define __GNUMERIC_IDL__

/*
 * If you are looking for a good example of Bonobo use, this is not it.
 * please see bonobo/samples/ for a better starting point.
 */

#include <Bonobo.idl>
#include <oaf-factory.idl>

module GNOME {
	module Gnumeric {
		struct CellRange {
			string cell_a;
			string cell_b;
		};

		const short VALUE_STRING    = 0;
		const short VALUE_INTEGER   = 1;
		const short VALUE_FLOAT     = 2;
		const short VALUE_CELLRANGE = 3;
		const short VALUE_ARRAY     = 4;
		const short VALUE_BOOLEAN   = 5;
		const short VALUE_ERROR     = 6;
		const short VALUE_EMPTY     = 7;
		
		union Value switch(short) {
		case VALUE_BOOLEAN: boolean v_bool;
		case VALUE_FLOAT:   double v_float;
		case VALUE_INTEGER: long v_int;
		case VALUE_STRING:  string str;
		case VALUE_ERROR:   string error;
		case VALUE_ARRAY:   string array;
		case VALUE_CELLRANGE: CellRange cell_range;
		};

		union VecValue switch (short) {
		case VALUE_FLOAT:   double v_float;
		case VALUE_STRING:  string str;
		};

		typedef sequence<VecValue> VecValueVec;

		exception PluginProblem { string mesg; };

		interface Sheet {
			exception OutOfRange {};
			exception ParseError {};
			exception InvalidCmd {};

			void cursor_set  (in long base_col, in long base_row,
					  in long start_col, in long start_row,
					  in long end_col, in long end_row)
				raises (OutOfRange);
			void cursor_move (in long col, in long row) 
				raises (OutOfRange);

			void make_cell_visible (in long col, in long row)
				raises (OutOfRange);

			// 
			// Selection
			//
			boolean is_all_selected ();
			void    selection_append (in long col, in long row) 
				raises (OutOfRange);
			void    selection_append_range (in long start_col,
							in long start_row,
							in long end_col, 
							in long end_row)
				raises (OutOfRange);
			void    selection_copy ();
			void    selection_cut ()
				raises (InvalidCmd);

			//
			// Operations on the region
			//
			void    clear_region (in long start_col, in long start_row,
					      in long end_col, in long end_row)
				raises (OutOfRange, InvalidCmd);
			void    clear_region_content (in long start_col, in long start_row,
						      in long end_col, in long end_row)
				raises (OutOfRange, InvalidCmd);
			void    clear_region_comments (in long start_col, in long start_row,
						       in long end_col, in long end_row)
				raises (OutOfRange);
			void    clear_region_formats (in long start_col, in long start_row,
						      in long end_col, in long end_row)
				raises (OutOfRange);


			//
			// Cell management
			//
			void    cell_set_value (in long col, in long row,
						in Gnumeric::Value value)
				raises (OutOfRange, InvalidCmd);
			Value   cell_get_value (in long col, in long row) 
				raises (OutOfRange);

			void    cell_set_text (in long col, in long row, in string text)
				raises (OutOfRange, InvalidCmd);
			string  cell_get_text (in long col, in long row)
				raises (OutOfRange);

			void    cell_set_format (in long col, in long row, in string format)
				raises (OutOfRange);
			string  cell_get_format (in long col, in long row)
				raises (OutOfRange);

			void    cell_set_font (in long col, in long row, in string font, in double points)
				raises (OutOfRange);
			string  cell_get_font (in long col, in long row)
				raises (OutOfRange);

			void    cell_set_comment (in long col, in long row, in string comment)
				raises (OutOfRange);
			string  cell_get_comment (in long col, in long row)
				raises (OutOfRange);

			void    cell_set_foreground (in long col, in long row, in string color)
				raises (OutOfRange);
			string  cell_get_foreground (in long col, in long row)
				raises (OutOfRange);

			void    cell_set_background (in long col, in long row, in string color)
				raises (OutOfRange);
			string  cell_get_background (in long col, in long row)
				raises (OutOfRange);

			void    cell_set_pattern (in long col, in long row, in long pattern)
				raises (OutOfRange);
			long    cell_get_pattern (in long col, in long row)
				raises (OutOfRange);

			const short HALIGN_GENERAL = 1;
			const short HALIGN_LEFT    = 2;
			const short HALIGN_RIGHT   = 4;
			const short HALIGN_CENTER  = 8;
			const short HALIGN_FILL    = 16;
			const short HALIGN_JUSTIFY = 32;
			const short HALIGN_CENTER_ACROSS_SELECTION  = 64;
			
			const short VALIGN_TOP     = 1;
			const short VALIGN_BOTTOM  = 2;
			const short VALIGN_CENTER  = 4;
			const short VALIGN_JUSTIFY = 8;

			void    cell_set_alignment (in long col, in long row, 
						    in long halign, in long valign,
						    in long orientation, in boolean wrap_text)
				raises (OutOfRange);
			void    cell_get_alignment (in long col, in long row,
						    out long halign, out long valign,
						    out long orientation, out boolean wrap_text)
				raises (OutOfRange);

			// 
			// Cell regions
			//
			typedef sequence<Value> ValueVector;

			ValueVector range_get_values (in string range)
				raises (OutOfRange);
			void    range_set_text (in string range, in string text)
				raises (OutOfRange, InvalidCmd);
			void    range_set_format (in string range, in string format)
				raises (OutOfRange);
			void    range_set_font (in string range, in string font, in short points)
				raises (OutOfRange);
			void    range_set_foreground (in string range, in string color)
				raises (OutOfRange);
			void    range_set_background (in string range, in string color)
				raises (OutOfRange);
			void    range_set_pattern (in string range, in long pattern)
				raises (OutOfRange);
			void    range_set_alignment (in string range, 
						    in long halign, in long valign,
						    in long orientation, in boolean auto_return)
				raises (OutOfRange);
			
			//
			// Sheet administrivia
			//
			void    set_dirty (in boolean is_dirty);

			//
			// Sheet manipulation
			//
			void    insert_col (in long col, in long count)
				raises(InvalidCmd);
			void    delete_col (in long col, in long count)
				raises(InvalidCmd);
			void    insert_row (in long row, in long count)
				raises(InvalidCmd);
			void    delete_row (in long row, in long count)
				raises(InvalidCmd);
			void    shift_rows (in long col, 
					    in long start_row, in long end_row,
					    in long count);
			void    shift_cols (in long col, 
					    in long start_row, in long end_row,
					    in long count);
			
			// 
			// Information
			//
			long max_cols_used ();
			long max_rows_used ();
			double col_width  (in long col);
			double row_height (in long row);
		};

		interface Workbook : Bonobo::Embeddable {
			exception NameExists {};

			Sheet sheet_new    (in string name) raises (NameExists);
			Sheet sheet_lookup (in string name);

			void  set_filename (in string name);

			void  save_to (in string filename);

			Sheet sheet_current ();
			Sheet sheet_nth (in long n);
			long  sheet_count ();

			//
			// Workbook administrivia
			//
			void set_dirty (in boolean is_dirty);

			boolean sheet_rename (in string old_name, in string new_name);

			//
			// Recomputation
			//
			void recalc ();
			void recalc_all ();

			//
			// Cell reference parsing
			//
			void parse (in string cellref,
				    out Gnumeric::Sheet sheet,
				    out long col, out long row);
		};

		//
		// Interfaces for embedding Gnumeric with Bonobo
		//
		interface WorkbookFactory : GNOME::ObjectFactory {
			Workbook read (in string filename);
		};
		
		interface Grid : Bonobo::Embeddable {
			Sheet get_sheet ();
			
			void set_header_visibility (in boolean cols, in boolean rows);
			void get_header_visibility (out boolean cols, out boolean rows);
		};
	};
};


#endif /* __GNUMERIC_IDL__ */
