summaryrefslogtreecommitdiffstats
path: root/kspread/plugins/scripting/kspreadcore
diff options
context:
space:
mode:
Diffstat (limited to 'kspread/plugins/scripting/kspreadcore')
-rw-r--r--kspread/plugins/scripting/kspreadcore/CMakeLists.txt56
-rw-r--r--kspread/plugins/scripting/kspreadcore/Makefile.am23
-rw-r--r--kspread/plugins/scripting/kspreadcore/krs_cell.cpp211
-rw-r--r--kspread/plugins/scripting/kspreadcore/krs_cell.h170
-rw-r--r--kspread/plugins/scripting/kspreadcore/krs_doc.cpp135
-rw-r--r--kspread/plugins/scripting/kspreadcore/krs_doc.h122
-rw-r--r--kspread/plugins/scripting/kspreadcore/krs_sheet.cpp103
-rw-r--r--kspread/plugins/scripting/kspreadcore/krs_sheet.h140
-rw-r--r--kspread/plugins/scripting/kspreadcore/kspreadcoremodule.cpp82
-rw-r--r--kspread/plugins/scripting/kspreadcore/kspreadcoremodule.h82
10 files changed, 1124 insertions, 0 deletions
diff --git a/kspread/plugins/scripting/kspreadcore/CMakeLists.txt b/kspread/plugins/scripting/kspreadcore/CMakeLists.txt
new file mode 100644
index 00000000..50cd0a73
--- /dev/null
+++ b/kspread/plugins/scripting/kspreadcore/CMakeLists.txt
@@ -0,0 +1,56 @@
+
+
+include_directories( ${CMAKE_SOURCE_DIR}/core ${CMAKE_SOURCE_DIR}/kspread ${KDE4_INCLUDES} )
+
+
+########### next target ###############
+
+set(krosskspreadcore_PART_SRCS
+ kspreadcoremodule.cpp
+ krs_doc.cpp
+ krs_sheet.cpp
+ krs_cell.cpp )
+
+kde4_automoc(${krosskspreadcore_PART_SRCS})
+
+kde4_add_plugin(krosskspreadcore ${krosskspreadcore_PART_SRCS})
+
+kde4_install_libtool_file( ${PLUGIN_INSTALL_DIR} krosskspreadcore )
+
+target_link_libraries(krosskspreadcore ${KDE4_KDECORE_LIBS} krossapi krossmain kspreadcommon )
+
+install(TARGETS krosskspreadcore DESTINATION ${PLUGIN_INSTALL_DIR})
+
+
+########### install files ###############
+
+
+
+
+
+
+#original Makefile.am contents follow:
+
+#INCLUDES = -I$(top_srcdir)/core \
+# -I$(top_srcdir)/kspread $(KOFFICECORE_INCLUDES) $(KSTORE_INCLUDES) \
+# $(KOFFICEUI_INCLUDES) $(KROSS_INCLUDES) \
+# $(all_includes)
+#
+#kde_module_LTLIBRARIES = krosskspreadcore.la
+#
+#krosskspreadcore_la_SOURCES = kspreadcoremodule.cpp krs_doc.cpp krs_sheet.cpp krs_cell.cpp krs_color.cpp
+#
+#krosskspreadcore_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -module
+#krosskspreadcore_la_LIBADD = \
+# $(LIB_QT) \
+# $(LIB_KDECORE) \
+# $(top_builddir)/lib/kross/api/libkrossapi.la \
+# $(top_builddir)/lib/kross/main/libkrossmain.la \
+# $(top_builddir)/kspread/libkspreadcommon.la
+#
+#METASOURCES = AUTO
+#SUBDIRS = .
+#
+#KDE_CXXFLAGS = $(USE_EXCEPTIONS)
+#
+#noinst_HEADERS = krs_doc.h krs_sheet.h krs_cell.h krs_color.h
diff --git a/kspread/plugins/scripting/kspreadcore/Makefile.am b/kspread/plugins/scripting/kspreadcore/Makefile.am
new file mode 100644
index 00000000..1538610d
--- /dev/null
+++ b/kspread/plugins/scripting/kspreadcore/Makefile.am
@@ -0,0 +1,23 @@
+INCLUDES = -I$(top_srcdir)/core \
+ -I$(top_srcdir)/kspread $(KOFFICECORE_INCLUDES) $(KSTORE_INCLUDES) \
+ $(KOFFICEUI_INCLUDES) $(KROSS_INCLUDES) \
+ $(all_includes)
+
+kde_module_LTLIBRARIES = krosskspreadcore.la
+
+krosskspreadcore_la_SOURCES = kspreadcoremodule.cpp krs_doc.cpp krs_sheet.cpp krs_cell.cpp
+
+krosskspreadcore_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -module
+krosskspreadcore_la_LIBADD = \
+ $(LIB_QT) \
+ $(LIB_KDECORE) \
+ $(top_builddir)/lib/kross/api/libkrossapi.la \
+ $(top_builddir)/lib/kross/main/libkrossmain.la \
+ $(top_builddir)/kspread/libkspreadcommon.la
+
+METASOURCES = AUTO
+SUBDIRS = .
+
+KDE_CXXFLAGS = $(USE_EXCEPTIONS)
+
+noinst_HEADERS = krs_doc.h krs_sheet.h krs_cell.h
diff --git a/kspread/plugins/scripting/kspreadcore/krs_cell.cpp b/kspread/plugins/scripting/kspreadcore/krs_cell.cpp
new file mode 100644
index 00000000..cabf0c50
--- /dev/null
+++ b/kspread/plugins/scripting/kspreadcore/krs_cell.cpp
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ * Copyright (c) 2006 Isaac Clerencia <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "krs_cell.h"
+
+#include "manipulator.h"
+#include "manipulator_data.h"
+
+namespace Kross { namespace KSpreadCore {
+
+Cell::Cell(KSpread::Cell* cell, KSpread::Sheet* sheet, uint col, uint row)
+ : Kross::Api::Class<Cell>("KSpreadCell"), m_cell(cell), m_sheet(sheet), m_col(col), m_row(row)
+{
+ this->addFunction0< Kross::Api::Variant >("value", this, &Cell::value);
+ this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("setValue", this, &Cell::setValue);
+
+ this->addFunction0< Kross::Api::Variant >("column", this, &Cell::column);
+ this->addFunction0< Kross::Api::Variant >("row", this, &Cell::row);
+
+ this->addFunction0< Cell >("previousCell", this, &Cell::previousCell);
+ this->addFunction0< Cell >("nextCell", this, &Cell::nextCell);
+ this->addFunction1< void, Cell >("setPreviousCell", this, &Cell::setPreviousCell);
+ this->addFunction1< void, Cell >("setNextCell", this, &Cell::setNextCell);
+
+ this->addFunction0< Kross::Api::Variant >("name", this, &Cell::name);
+ this->addFunction0< Kross::Api::Variant >("fullName", this, &Cell::fullName);
+
+ this->addFunction0< Kross::Api::Variant >("comment", this, &Cell::comment);
+ this->addFunction1< void, Kross::Api::Variant >("setComment", this, &Cell::setComment);
+
+ this->addFunction0< Kross::Api::Variant >("getFormatString", this, &Cell::getFormatString);
+ this->addFunction1< void, Kross::Api::Variant >("setFormatString", this, &Cell::setFormatString);
+
+ this->addFunction0< Kross::Api::Variant >("text", this, &Cell::text);
+ this->addFunction1< void, Kross::Api::Variant >("setText", this, &Cell::setText);
+
+ this->addFunction0< Kross::Api::Variant >("textColor", this, &Cell::textColor);
+ this->addFunction1< void, Kross::Api::Variant >("setTextColor", this, &Cell::setTextColor);
+ this->addFunction0< Kross::Api::Variant >("backgroundColor", this, &Cell::backgroundColor);
+ this->addFunction1< void, Kross::Api::Variant >("setBackgroundColor", this, &Cell::setBackgroundColor);
+}
+
+Cell::~Cell() {
+}
+
+const QString Cell::getClassName() const {
+ return "Kross::KSpreadCore::KSpreadCell";
+}
+
+QVariant Cell::toVariant(const KSpread::Value& value) const
+{
+ //Should we use following value-format enums here?
+ //fmt_None, fmt_Boolean, fmt_Number, fmt_Percent, fmt_Money, fmt_DateTime, fmt_Date, fmt_Time, fmt_String
+
+ switch(value.type()) {
+ case KSpread::Value::Empty:
+ return QVariant();
+ case KSpread::Value::Boolean:
+ return QVariant( value.asBoolean() );
+ case KSpread::Value::Integer:
+ return static_cast<Q_LLONG>(value.asInteger());
+ case KSpread::Value::Float:
+ return (float)value.asFloat();
+ case KSpread::Value::String:
+ return value.asString();
+ case KSpread::Value::Array: {
+ QValueList<QVariant> colarray;
+ for(uint j = 0; j < value.rows(); j++) {
+ QValueList<QVariant> rowarray;
+ for( uint i = 0; i < value.columns(); i++) {
+ KSpread::Value v = value.element(i,j);
+ rowarray.append( toVariant(v) );
+ }
+ colarray.append(rowarray);
+ }
+ return colarray;
+ } break;
+ case KSpread::Value::CellRange:
+ //FIXME: not yet used
+ return QVariant();
+ case KSpread::Value::Error:
+ return QVariant();
+ }
+ return QVariant();
+}
+
+QVariant Cell::value() const {
+ return toVariant( m_cell->value() );
+}
+
+bool Cell::setValue(const QVariant& value) {
+ KSpread::Value v = m_cell->value();
+ switch(value.type()) {
+ case QVariant::Bool: v.setValue( value.toBool() ); break;
+ case QVariant::ULongLong: v.setValue( (long)value.toLongLong() ); break;
+ case QVariant::Int: v.setValue( value.toInt() ); break;
+ case QVariant::Double: v.setValue( value.toDouble() ); break;
+ case QVariant::String: v.setValue( value.toString() ); break;
+ case QVariant::Date: v.setValue( value.toDate() ); break;
+ case QVariant::Time: v.setValue( value.toTime() ); break;
+ case QVariant::DateTime: v.setValue( value.toDateTime() ); break;
+ default: return false;
+ }
+ return true;
+}
+
+int Cell::column() const {
+ return m_cell->column();
+}
+
+int Cell::row() const {
+ return m_cell->row();
+}
+
+Cell* Cell::previousCell() const {
+ KSpread::Cell* c = m_cell->previousCell();
+ return c ? new Cell(c,c->sheet(),c->column(),c->row()) : 0;
+}
+
+Cell* Cell::nextCell() const {
+ KSpread::Cell* c = m_cell->nextCell();
+ return c ? new Cell(c,c->sheet(),c->column(),c->row()) : 0;
+}
+
+void Cell::setPreviousCell(Cell* c) {
+ return m_cell->setPreviousCell(c->m_cell);
+}
+
+void Cell::setNextCell(Cell* c) {
+ return m_cell->setNextCell(c->m_cell);
+}
+
+const QString Cell::name() const {
+ return m_cell->name();
+}
+
+const QString Cell::fullName() const {
+ return m_cell->fullName();
+}
+
+const QString Cell::comment() const {
+ return m_cell->format()->comment(m_col, m_row);
+}
+
+void Cell::setComment(const QString& c) {
+ return m_cell->format()->setComment(c);
+}
+
+const QString Cell::getFormatString() const {
+ return m_cell->format()->getFormatString(m_col, m_row);
+}
+
+void Cell::setFormatString(const QString& format) {
+ m_cell->format()->setFormatString(format);
+}
+
+const QString Cell::text() const {
+ return m_cell->text();
+}
+
+bool Cell::setText(const QString& text) {
+ KSpread::ProtectedCheck prot;
+ prot.setSheet (m_sheet);
+ prot.add (QPoint (m_col, m_row));
+ if (prot.check())
+ return false;
+
+ KSpread::DataManipulator *dm = new KSpread::DataManipulator ();
+ dm->setSheet (m_sheet);
+ dm->setValue (text);
+ dm->setParsing (true);
+ dm->add (QPoint (m_col, m_row));
+ dm->execute ();
+
+ return true;
+}
+
+const QString Cell::textColor() {
+ return m_cell->format()->textColor(m_col, m_row).name();
+}
+
+void Cell::setTextColor(const QString& textcolor) {
+ m_cell->format()->setTextColor( QColor(textcolor) );
+}
+
+const QString Cell::backgroundColor() {
+ return m_cell->format()->bgColor(m_col, m_row).name();
+}
+
+void Cell::setBackgroundColor(const QString& backgroundcolor) {
+ m_cell->format()->setBgColor( QColor(backgroundcolor) );
+}
+
+}
+}
diff --git a/kspread/plugins/scripting/kspreadcore/krs_cell.h b/kspread/plugins/scripting/kspreadcore/krs_cell.h
new file mode 100644
index 00000000..5f3f221d
--- /dev/null
+++ b/kspread/plugins/scripting/kspreadcore/krs_cell.h
@@ -0,0 +1,170 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ * Copyright (c) 2006 Isaac Clerencia <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KROSS_KSPREADCOREKRSCELL_H
+#define KROSS_KSPREADCOREKRSCELL_H
+
+#include <kspread_sheet.h>
+#include <kspread_cell.h>
+#include <kspread_value.h>
+
+#include <api/class.h>
+
+#include <qstring.h>
+#include <qcolor.h>
+
+namespace Kross { namespace KSpreadCore {
+
+/**
+ * For every cell in the spread sheet there is a Cell object.
+ *
+ * Cell contains format information and algorithm and it
+ * contains the calculation algorithm.
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosskspreadcore::get("KSpreadDocument")
+ * sheet = doc.currentSheet()
+ * cellA1 = sheet.cell(0, 0)
+ * cellA2 = sheet.cell(0, 1)
+ * cellA2.setValue( cellA1.value() )
+ * cellA2.setTextColor( "#ff0000" )
+ * @endcode
+ */
+class Cell : public Kross::Api::Class<Cell>
+{
+ public:
+ Cell(KSpread::Cell* cell, KSpread::Sheet* sheet, uint col, uint row);
+ virtual ~Cell();
+ virtual const QString getClassName() const;
+ private:
+
+ /**
+ * Return the value of the cell.
+ */
+ QVariant value() const;
+ /**
+ * Set the value the cell has.
+ */
+ bool setValue(const QVariant& value);
+
+ /**
+ * Return the column number.
+ */
+ int column() const;
+ /**
+ * Return the row number.
+ */
+ int row() const;
+
+ /**
+ * Return the previous cell if there is any.
+ */
+ Cell* previousCell() const;
+ /**
+ * Return the next cell if there is any.
+ */
+ Cell* nextCell() const;
+ /**
+ * Set the previous cell.
+ */
+ void setPreviousCell(Cell* c);
+ /**
+ * Set the next cell.
+ */
+ void setNextCell(Cell* c);
+
+ /**
+ * Returns the name of the cell. For example, the cell in first column
+ * and first row is "A1".
+ */
+ const QString name() const;
+ /**
+ * Returns the full name of the cell, i.e. including the worksheet name.
+ * Example: "Sheet1!A1"
+ */
+ const QString fullName() const;
+
+ /**
+ * Returns the comment for the cell.
+ */
+ const QString comment() const;
+ /**
+ * Set the comment for the cell.
+ */
+ void setComment(const QString& c);
+
+#if 0
+ bool isFormula() const;
+ Formula *formula () const;
+#endif
+
+ /**
+ * Returns the format of the cell, e.g. #.##0.00, dd/mmm/yyyy,...
+ */
+ const QString getFormatString() const;
+ /**
+ * Sets the format of the cell, e.g. #.##0.00, dd/mmm/yyyy,...
+ */
+ void setFormatString(const QString& format);
+
+ /**
+ * Return the text of the cell (the formula if there is one,
+ * the value otherwise). This could be a value (e.g. "14.03")
+ * or a formula (e.g. "=SUM(A1:A10)")
+ */
+ const QString text() const;
+ /**
+ * Set the text of the cell. the text
+ * will be handled as string
+ */
+ bool setText(const QString& text);
+
+ /**
+ * Return the textcolor as RGB-value in the format "#RRGGBB".
+ */
+ const QString textColor();
+ /**
+ * Set the textcolor to the RGB-value in the format "#RRGGBB"
+ * where each of R, G, and B is a single hex digit.
+ */
+ void setTextColor(const QString& textcolor);
+
+ /**
+ * Return the backgroundcolor as RGB-value in the format "#RRGGBB".
+ */
+ const QString backgroundColor();
+ /**
+ * Set the backgroundcolor to the RGB-value in the format "#RRGGBB"
+ * where each of R, G, and B is a single hex digit.
+ */
+ void setBackgroundColor(const QString& backgroundcolor);
+
+ private:
+ KSpread::Cell* m_cell;
+ KSpread::Sheet* m_sheet;
+ uint m_col, m_row;
+
+ QVariant toVariant(const KSpread::Value& value) const;
+};
+}
+}
+
+
+#endif
diff --git a/kspread/plugins/scripting/kspreadcore/krs_doc.cpp b/kspread/plugins/scripting/kspreadcore/krs_doc.cpp
new file mode 100644
index 00000000..37c87efd
--- /dev/null
+++ b/kspread/plugins/scripting/kspreadcore/krs_doc.cpp
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ * Copyright (c) 2006 Isaac Clerencia <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "krs_doc.h"
+#include "krs_sheet.h"
+
+#include <kspread_map.h>
+#include <kspread_sheet.h>
+
+namespace Kross { namespace KSpreadCore {
+
+Doc::Doc(KSpread::Doc* doc)
+ : Kross::Api::Class<Doc>("KSpreadDocument"), m_doc(doc)
+{
+ this->addFunction0< Sheet >("currentSheet", this, &Doc::currentSheet);
+ this->addFunction1< Sheet, Kross::Api::Variant >("sheetByName", this, &Doc::sheetByName);
+ this->addFunction0< Kross::Api::Variant >("sheetNames", this, &Doc::sheetNames);
+
+ this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("addSheet", this, &Doc::addSheet);
+ this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("removeSheet", this, &Doc::removeSheet);
+
+ this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("loadNativeXML", this, &Doc::loadNativeXML);
+ this->addFunction0< Kross::Api::Variant >("saveNativeXML", this, &Doc::saveNativeXML);
+
+ this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("openUrl", this, &Doc::openUrl);
+ this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("saveUrl", this, &Doc::saveUrl);
+ this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("import", this, &Doc::import);
+ this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("exp0rt", this, &Doc::exp0rt);
+
+}
+
+Doc::~Doc() {
+
+}
+
+const QString Doc::getClassName() const {
+ return "Kross::KSpreadCore::Doc";
+}
+
+Sheet* Doc::currentSheet()
+{
+ return new Sheet(m_doc->displaySheet(), m_doc);
+}
+
+Sheet* Doc::sheetByName(const QString& name)
+{
+ QPtrListIterator<KSpread::Sheet> it (m_doc->map()->sheetList());
+ for( ; it.current(); ++it )
+ if(it.current()->sheetName() == name)
+ return new Sheet(it.current(), m_doc);
+ return 0;
+}
+
+QStringList Doc::sheetNames()
+{
+ QStringList names;
+ QPtrListIterator<KSpread::Sheet> it (m_doc->map()->sheetList());
+ for( ; it.current(); ++it )
+ names.append( it.current()->sheetName() );
+ return names;
+}
+
+bool Doc::addSheet(const QString& sheetname)
+{
+ KSpread::Sheet* sheet = m_doc->map()->createSheet();
+ if(sheet) {
+ if(! sheet->setSheetName(sheetname)) {
+ delete sheet;
+ return false;
+ }
+ m_doc->map()->addSheet(sheet);
+ return true;
+ }
+ return false;
+}
+
+bool Doc::removeSheet(const QString& sheetname)
+{
+ KSpread::Sheet* sheet = m_doc->map()->findSheet(sheetname);
+ if(sheet) {
+ m_doc->map()->takeSheet(sheet);
+ return true;
+ }
+ return false;
+}
+
+bool Doc::loadNativeXML(const QString& xml) {
+ QDomDocument doc;
+ if(! doc.setContent(xml, true))
+ return false;
+ return m_doc->loadXML(0, doc);
+}
+
+QString Doc::saveNativeXML() {
+ return m_doc->saveXML().toString(2);
+}
+
+bool Doc::openUrl(const QString& url)
+{
+ return m_doc->openURL(url);
+}
+
+bool Doc::saveUrl(const QString& url)
+{
+ return m_doc->saveAs(url);
+}
+
+bool Doc::import(const QString& url)
+{
+ return m_doc->import(url);
+}
+
+bool Doc::exp0rt(const QString& url)
+{
+ return m_doc->exp0rt(url);
+}
+
+}}
+
diff --git a/kspread/plugins/scripting/kspreadcore/krs_doc.h b/kspread/plugins/scripting/kspreadcore/krs_doc.h
new file mode 100644
index 00000000..28c69845
--- /dev/null
+++ b/kspread/plugins/scripting/kspreadcore/krs_doc.h
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ * Copyright (c) 2006 Isaac Clerencia <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KSPREAD_KROSS_KRS_DOC_H_
+#define KSPREAD_KROSS_KRS_DOC_H_
+
+#include <kspread_doc.h>
+
+#include <api/class.h>
+
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qdom.h>
+
+namespace Kross { namespace KSpreadCore {
+
+class Sheet;
+
+/**
+ * The KSpread document.
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosskspreadcore::get("KSpreadDocument")
+ * @endcode
+ */
+class Doc : public Kross::Api::Class<Doc>
+{
+ public:
+ explicit Doc(KSpread::Doc* doc);
+ virtual ~Doc();
+ virtual const QString getClassName() const;
+ private:
+
+ /**
+ * This function returns the Sheet currently active in this
+ * document.
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosskspreadcore::get("KSpreadDocument")
+ * sheet = doc.currentSheet()
+ * @endcode
+ */
+ Sheet* currentSheet();
+
+ /**
+ * This function returns a Sheet by name.
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosskspreadcore::get("KSpreadDocument")
+ * sheet = doc.sheetByName("foosheet")
+ * @endcode
+ */
+ Sheet* sheetByName(const QString& name);
+
+ /**
+ * This function returns an array with the sheet names
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosskspreadcore::get("KSpreadDocument")
+ * sheetnames = doc.sheetNames()
+ * sheet = doc.sheetByName( sheetnames[0] )
+ * @endcode
+ */
+ QStringList sheetNames();
+
+ /**
+ * Add a new sheet named @p sheetname to the document.
+ */
+ bool addSheet(const QString& sheetname);
+
+ /**
+ * Remove the sheet named @p sheetname from the document.
+ */
+ bool removeSheet(const QString& sheetname);
+
+ /**
+ * Loads the native XML document.
+ */
+ bool loadNativeXML(const QString& xml);
+ /**
+ * Save and return the to a native document saved XML.
+ */
+ QString saveNativeXML();
+
+#if 0
+ bool loadOpenDocXML(const QString& xml);
+ QString saveOpenDocXML();
+#endif
+
+ bool openUrl(const QString& url);
+ bool saveUrl(const QString& url);
+ bool import(const QString& url);
+ bool exp0rt(const QString& url);
+
+ private:
+ KSpread::Doc* m_doc;
+};
+}
+}
+
+
+#endif
diff --git a/kspread/plugins/scripting/kspreadcore/krs_sheet.cpp b/kspread/plugins/scripting/kspreadcore/krs_sheet.cpp
new file mode 100644
index 00000000..694037ed
--- /dev/null
+++ b/kspread/plugins/scripting/kspreadcore/krs_sheet.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ * Copyright (c) 2006 Isaac Clerencia <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "krs_cell.h"
+#include "krs_sheet.h"
+#include "krs_doc.h"
+
+#include <kspread_doc.h>
+#include <kspread_sheet.h>
+#include <kspread_cell.h>
+#include <kspread_value.h>
+
+namespace Kross { namespace KSpreadCore {
+
+Sheet::Sheet(KSpread::Sheet* sheet, KSpread::Doc *doc) : Kross::Api::Class<Sheet>("KSpreadSheet"), m_sheet(sheet), m_doc(doc) {
+
+ this->addFunction0< Kross::Api::Variant >("name", this, &Sheet::name);
+ this->addFunction1< void, Kross::Api::Variant >("setName", this, &Sheet::setName);
+
+ this->addFunction0< Kross::Api::Variant >("maxColumn", this, &Sheet::maxColumn);
+ this->addFunction0< Kross::Api::Variant >("maxRow", this, &Sheet::maxRow);
+
+ this->addFunction0< Cell >("firstCell", this, &Sheet::firstCell);
+
+ this->addFunction2< Cell, Kross::Api::Variant, Kross::Api::Variant >("cell", this, &Sheet::cell);
+
+ this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("insertRow", this, &Sheet::insertRow);
+ this->addFunction1< Kross::Api::Variant, Kross::Api::Variant >("insertColumn", this, &Sheet::insertColumn);
+
+ this->addFunction1< void, Kross::Api::Variant >("removeRow", this, &Sheet::removeRow);
+ this->addFunction1< void, Kross::Api::Variant >("removeColumn", this, &Sheet::removeColumn);
+}
+
+Sheet::~Sheet() {
+}
+
+const QString Sheet::getClassName() const {
+ return "Kross::KSpreadCore::Sheet";
+}
+
+const QString Sheet::name() const
+{
+ return m_sheet->sheetName();
+}
+
+void Sheet::setName(const QString& name)
+{
+ m_sheet->setSheetName(name);
+}
+
+int Sheet::maxColumn() const {
+ return m_sheet->maxColumn();
+}
+
+int Sheet::maxRow() const {
+ return m_sheet->maxRow();
+}
+
+Cell* Sheet::firstCell() const {
+ KSpread::Cell* c = m_sheet->firstCell();
+ return c ? new Cell(c,c->sheet(),c->column(),c->row()) : 0;
+}
+
+Cell* Sheet::cell(uint col, uint row) {
+ uint c = QMAX(uint(1), col);
+ uint r = QMAX(uint(1), row);
+ return new Cell(m_sheet->cellAt(c,r),m_sheet,c,r);
+}
+
+bool Sheet::insertRow(uint row) {
+ return m_sheet->insertRow(row);
+}
+
+bool Sheet::insertColumn(uint col) {
+ return m_sheet->insertColumn(col);
+}
+
+void Sheet::removeRow(uint row) {
+ m_sheet->removeRow( QMAX(uint(1), row) );
+}
+
+void Sheet::removeColumn(uint col) {
+ m_sheet->removeColumn( QMAX(uint(1), col) );
+}
+
+}
+}
diff --git a/kspread/plugins/scripting/kspreadcore/krs_sheet.h b/kspread/plugins/scripting/kspreadcore/krs_sheet.h
new file mode 100644
index 00000000..a96e758e
--- /dev/null
+++ b/kspread/plugins/scripting/kspreadcore/krs_sheet.h
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ * Copyright (c) 2006 Isaac Clerencia <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KROSS_KSPREADCOREKRSSHEET_H
+#define KROSS_KSPREADCOREKRSSHEET_H
+
+#include <kspread_sheet.h>
+#include <kspread_value.h>
+
+#include <api/class.h>
+
+namespace Kross { namespace KSpreadCore {
+
+class Cell;
+
+/**
+ * A sheet in a document.
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosskspreadcore::get("KSpreadDocument")
+ * sheet1 = doc.sheetByName("Sheet1")
+ * sheet2 = doc.sheetByName("Sheet2")
+ * cell1 = sheet1.firstCell()
+ * while cell1
+ * colnr = cell1.column()
+ * rownr = cell1.row()
+ * cell2 = sheet2.cell(colnr, rownr)
+ * cell2.setValue( cell1.value() )
+ * cell1 = cell1.nextCell()
+ * end
+ * @endcode
+ */
+class Sheet : public Kross::Api::Class<Sheet>
+{
+ public:
+ Sheet(KSpread::Sheet* sheet, KSpread::Doc* doc = 0);
+ virtual ~Sheet();
+ virtual const QString getClassName() const;
+ private:
+
+ /**
+ * Return the name of the sheet.
+ */
+ const QString name() const;
+ /**
+ * Set the name of the sheet.
+ */
+ void setName(const QString& name);
+
+ /**
+ * Return the currently maximum defined number of columns.
+ */
+ int maxColumn() const;
+ /**
+ * Return the currently maximum defined number of rows.
+ */
+ int maxRow() const;
+
+ /**
+ * Return the first cell. Use the firstCell() and nextCell()
+ * methods as outlined in the example to iterate only through
+ * filled cells (aka cells with content).
+ *
+ * Example (in Python) :
+ * @code
+ * import krosskspreadcore
+ * doc = krosskspreadcore.get("KSpreadDocument")
+ * sheet = doc.currentSheet()
+ * cell = sheet.firstCell()
+ * while cell:
+ * print "Cell col=%s row=%s value=%s" % (cell.column(),cell.row(),cell.value())
+ * cell = cell.nextCell()
+ * @endcode
+ */
+ Cell* firstCell() const;
+
+ /**
+ * Return the given cell. The first parameter is the column-number
+ * while the second defines the rownumber. The first cell starts
+ * with 0,0. If you like to iterate over all cells that have content,
+ * use the firstCell() and nextCell() methods which is much faster
+ * cause empty cells are ignored.
+ *
+ * Example (in Python) :
+ * @code
+ * import krosskspreadcore
+ * doc = krosskspreadcore.get("KSpreadDocument")
+ * sheet = doc.currentSheet()
+ * for colnr in range( sheet.maxColumn() ):
+ * for rownr in range( sheet.maxRow() ):
+ * cell = sheet.cell(colnr, rownr)
+ * if cell.value() != None:
+ * print "Cell col=%s row=%s value=%s" % (colnr,rownr,cell.value())
+ * @endcode
+ */
+ Cell* cell(uint col, uint row);
+
+ /**
+ * Add a new row.
+ */
+ bool insertRow(uint row);
+ /**
+ * Add a new column.
+ */
+ bool insertColumn(uint col);
+
+ /**
+ * Remove a row.
+ */
+ void removeRow(uint row);
+ /**
+ * Remove a column.
+ */
+ void removeColumn(uint col);
+
+ private:
+ KSpread::Sheet* m_sheet;
+ KSpread::Doc* m_doc;
+};
+}
+}
+
+#endif
diff --git a/kspread/plugins/scripting/kspreadcore/kspreadcoremodule.cpp b/kspread/plugins/scripting/kspreadcore/kspreadcoremodule.cpp
new file mode 100644
index 00000000..acfd0b2b
--- /dev/null
+++ b/kspread/plugins/scripting/kspreadcore/kspreadcoremodule.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ * Copyright (c) 2006 Isaac Clerencia <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "kspreadcoremodule.h"
+
+#include <kdebug.h>
+
+//#include <api/variant.h>
+#include <api/qtobject.h>
+#include <main/manager.h>
+
+#include "krs_doc.h"
+
+extern "C"
+{
+ /**
+ * Exported an loadable function as entry point to use
+ * the \a KexiAppModule.
+ */
+ Kross::Api::Object* init_module(Kross::Api::Manager* manager)
+ {
+ return new Kross::KSpreadCore::KSpreadCoreModule(manager);
+ }
+}
+
+
+using namespace Kross::KSpreadCore;
+
+KSpreadCoreModule::KSpreadCoreModule(Kross::Api::Manager* manager)
+ : Kross::Api::Module("kspreadcore") , m_manager(manager)
+{
+ QMap<QString, Object::Ptr> children = manager->getChildren();
+ kdDebug() << " there are " << children.size() << endl;
+ for(QMap<QString, Object::Ptr>::const_iterator it = children.begin(); it != children.end(); it++)
+ {
+ kdDebug() << it.key() << " " << it.data() << endl;
+ }
+
+ // Wrap doc
+ Kross::Api::Object::Ptr kspreaddocument = manager->getChild("KSpreadDocument");
+ if(! kspreaddocument) {
+ KSpread::Doc* doc = new KSpread::Doc();
+ addChild( new Kross::KSpreadCore::Doc(doc) );
+ }
+ else {
+ Kross::Api::QtObject* kspreaddocumentqt = dynamic_cast< Kross::Api::QtObject* >( kspreaddocument.data() );
+ if(kspreaddocumentqt) {
+ KSpread::Doc* document = dynamic_cast< ::KSpread::Doc* >( kspreaddocumentqt->getObject() );
+ if(document) {
+ addChild( new Doc(document) );
+ } else {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("There was no 'KSpreadDocument' published.") );
+ }
+ }
+ }
+}
+
+KSpreadCoreModule::~KSpreadCoreModule()
+{
+}
+
+
+const QString KSpreadCoreModule::getClassName() const
+{
+ return "Kross::KSpreadCore::KSpreadCoreModule";
+}
diff --git a/kspread/plugins/scripting/kspreadcore/kspreadcoremodule.h b/kspread/plugins/scripting/kspreadcore/kspreadcoremodule.h
new file mode 100644
index 00000000..ffc998cc
--- /dev/null
+++ b/kspread/plugins/scripting/kspreadcore/kspreadcoremodule.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ * Copyright (c) 2006 Isaac Clerencia <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KSPREAD_KROSS_KSPREADCOREMODULE_H
+#define KSPREAD_KROSS_KSPREADCOREMODULE_H
+
+#include <qstring.h>
+#include <qvariant.h>
+
+#define KROSS_MAIN_EXPORT KDE_EXPORT
+
+#include <api/module.h>
+#include <api/event.h>
+
+namespace Kross { namespace Api {
+ class Manager;
+}}
+
+namespace Kross { namespace KSpreadCore {
+
+ /**
+ * The KSpreadCoreModule class implements a Kross::Api::Module to
+ * provide access to the KSpread functionality.
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosskspreadcore::get("KSpreadDocument")
+ * sheet = doc.currentSheet()
+ * cell = sheet.cell(0, 0)
+ * cell.setValue("Hello World")
+ * @endcode
+ */
+ class KSpreadCoreModule : public Kross::Api::Module
+ {
+ public:
+ KSpreadCoreModule(Kross::Api::Manager* manager);
+ virtual ~KSpreadCoreModule();
+ virtual const QString getClassName() const;
+ //virtual Kross::Api::Object::Ptr call(const QString& name, Kross::Api::List::Ptr arguments);
+ private:
+
+#if 0
+ /**
+ * This function return a new Color with the given RGB triplet
+ * It takes three arguments :
+ * - red color (0 to 255)
+ * - blue color (0 to 255)
+ * - green color (0 to 255)
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosskritacore::newRGBColor(255,0,0) # create a red color
+ * Krosskritacore::newRGBColor(255,255,255) # create a white color
+ * @endcode
+ */
+ Kross::Api::Object::Ptr newRGBColor(Kross::Api::List::Ptr);
+#endif
+
+ private:
+ Kross::Api::Manager* m_manager;
+ };
+
+}}
+
+#endif
+