#ifndef __kspread_idl__
#define __kspread_idl__

#include <openparts.idl>
#include <koffice.idl>
#include <openparts_ui.idl>

module KSpread
{
	interface Table;
	typedef sequence<Table> TableSeq;

	struct Range
	{
		unsigned long left;
		unsigned long top;
		unsigned long right;
		unsigned long bottom;
		string table;
	};

	struct Cell
	{
		unsigned long x;
		unsigned long y;
		string table;
	};

	exception NoNumericValue
	{
		Cell cell;
	};

	exception MalformedExpression
	{
		string expr;
	};

	exception DifferentTables
	{
		string table1;
		string table2;
	};

	exception UnknownTable
	{
		string table;
	};

	exception NoActiveSelection
	{
	};

	interface Book;
	interface Document;

	interface View : KOffice::View
	{
		slot void undo();
		slot void redo();
		slot void cutSelection();
		slot void copySelection();
		slot void paste();
		slot void editCell();
		slot void paperLayoutDlg();
		slot void togglePageBorders();
		slot void newView();
		slot void insertNewTable();
		slot void autoFill();
		slot void editGlobalScripts();
		slot void editLocalScripts();
		slot void reloadScripts();
		slot void helpUsing();
		slot void deleteRow();
		slot void deleteColumn();
		slot void insertRow();
		slot void insertColumn();
		slot void bold();
		slot void italic();
		slot void moneyFormat();
		slot void percent();
		slot void alignLeft();
		slot void alignCenter();
		slot void alignRight();
		slot void multiRow();
		slot void precisionMinus();
		slot void precisionPlus();
		slot void insertChart();
		slot void insertTable();
		slot void insertImage();
		slot void insertObject();
		slot void fontSizeSelected( in string size );
		slot void fontSelected( in string font );
		slot void consolidate();

		Book book();

		struct EventSelectionChanged
		{
			Range range;
		};
		const string eventSelectionChanged = "KSpread/View/SelectionChanged";
	};

	interface Book
	{
		TableSeq tables();
		Table table( in string name );		
	};

	interface Table
	{		
		Book book();

		string tableName();

		Range range( in unsigned long left, in unsigned long top,
			     in unsigned long right, in unsigned long bottom );
		Range rangeFromString( in string str ) raises( MalformedExpression );
		Range rangeFromCells( in Cell topleft, in Cell bottomright );

		Cell cellFromString( in string str ) raises( MalformedExpression );

		void setValue( in Cell cell, in double value );
		void setStringValue( in Cell cell, in string value );

		double value( in Cell cell ) raises ( NoNumericValue );
		string stringValue( in Cell cell );

		void insertColumn( in unsigned long col );
		void insertRow( in unsigned long row );
		void deleteColumn( in unsigned long col );
		void deleteRow( in unsigned long row );

		void setSelection( in Range sel );
		Range selection();
		void copySelection();
		void cutSelection();
		void pasteSelection( in Cell cell );

		boolean isEmpty( in unsigned long x, in unsigned long y );
	};

	interface Document : KOffice::Document, KOffice::Print
	{
		Book book();

		const string eventNewView = "KSpread/Document/NewView";
		typedef KSpread::View typeNewView;

		const string eventRemovedView = "KSpread/Document/RemovedView";
		typedef KSpread::View typeRemovedView;
	};

	interface DocumentFactory : KOffice::DocumentFactory
	{
	};

	struct DataToolsId
	{
		unsigned long time;
		unsigned long column;
		unsigned long row;
	};

	struct EventSetText
	{
		string text;
	};
	const string eventSetText = "UserEvent/KSpread/SetText";

	struct EventKeyPressed
	{
		long key;
		long state;
		long ascii;
	};
	const string eventKeyPressed = "UserEvent/KSpread/KeyPressed";

	struct EventChartInserted
	{
		long dx;
		long dy;
		long width;
		long height;
	};
	const string eventChartInserted = "UserEvent/KSpread/ChartInserted";
};

#endif

