You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
435 lines
10 KiB
435 lines
10 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
|
||
|
Copyright 2003 Lukas Tinkl <lukas@kde.org>
|
||
|
Copyright 2000, 2002-2003 Laurent Montel <montel@kde.org>
|
||
|
Copyright 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
|
||
|
Copyright 2003 Joseph Wenninger <jowenn@kde.org>
|
||
|
Copyright 2002 Ariya Hidayat <ariya@kde.org>
|
||
|
Copyright 2002 Harri Porten <porten@kde.org>
|
||
|
Copyright 2002 John Dailey <dailey@vt.edu>
|
||
|
Copyright 2001 Simon Hausmann <hausmann@kde.org>
|
||
|
Copyright 2000 Werner Trobin <trobin@kde.org>
|
||
|
Copyright 1999 Torben Weis <weis@kde.org>
|
||
|
|
||
|
This library 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 library 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 library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kspread_sheet.h"
|
||
|
#include "kspread_sheetprint.h"
|
||
|
#include "kspread_util.h"
|
||
|
#include "kspread_doc.h"
|
||
|
|
||
|
#include <dcopclient.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
|
||
|
#include "KSpreadCellIface.h"
|
||
|
#include "region.h"
|
||
|
|
||
|
#include "KSpreadTableIface.h"
|
||
|
|
||
|
using namespace KSpread;
|
||
|
|
||
|
/*********************************************
|
||
|
*
|
||
|
* CellProxy
|
||
|
*
|
||
|
*********************************************/
|
||
|
|
||
|
class KSpread::CellProxy : public DCOPObjectProxy
|
||
|
{
|
||
|
public:
|
||
14 years ago
|
CellProxy( Sheet* sheet, const TQCString& prefix );
|
||
15 years ago
|
~CellProxy();
|
||
|
|
||
14 years ago
|
virtual bool process( const TQCString& obj, const TQCString& fun, const TQByteArray& data,
|
||
|
TQCString& replyType, TQByteArray &replyData );
|
||
15 years ago
|
|
||
|
private:
|
||
14 years ago
|
TQCString m_prefix;
|
||
15 years ago
|
CellIface* m_cell;
|
||
|
Sheet* m_sheet;
|
||
|
};
|
||
|
|
||
14 years ago
|
KSpread::CellProxy::CellProxy( Sheet* sheet, const TQCString& prefix )
|
||
15 years ago
|
: DCOPObjectProxy( kapp->dcopClient() ), m_prefix( prefix )
|
||
|
{
|
||
|
m_cell = new CellIface;
|
||
|
m_sheet = sheet;
|
||
|
}
|
||
|
|
||
|
KSpread::CellProxy::~CellProxy()
|
||
|
{
|
||
|
delete m_cell;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool KSpread::CellProxy::process( const TQCString& obj, const TQCString& fun, const TQByteArray& data,
|
||
|
TQCString& replyType, TQByteArray &replyData )
|
||
15 years ago
|
{
|
||
|
|
||
|
kdDebug()<<"CellProxy::process: requested object:"<<obj<<endl;
|
||
|
kdDebug()<<"CellProxy::process: prefix:"<<m_prefix<<endl;
|
||
|
if ( strncmp( m_prefix.data(), obj.data(), m_prefix.length() ) != 0 )
|
||
|
return false;
|
||
|
|
||
|
if ( fun == "functions()" ) {
|
||
|
replyType = "QCStringList";
|
||
14 years ago
|
TQDataStream reply( replyData, IO_WriteOnly );
|
||
15 years ago
|
QCStringList repList=m_cell->functions();
|
||
|
reply<<repList;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString cellID=TQString::fromUtf8(obj.data() + m_prefix.length());
|
||
15 years ago
|
cellID=m_sheet->sheetName()+"!"+cellID;
|
||
|
|
||
|
kdDebug()<<"CellProxy::process: cellID="<<cellID<<endl;
|
||
|
|
||
|
Point p( cellID); //obj.data() + m_prefix.length() );
|
||
|
if ( p.pos().x()<0 ) {
|
||
|
kdDebug(36001)<<"CellProyxy::process: resulting Point is not valid"<<endl;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
kdDebug(36001)<<"all checks finsihed, trying to access cell (x):"<<p.pos().x()<<endl;
|
||
|
|
||
|
m_cell->setCell( m_sheet, p.pos() );
|
||
|
return m_cell->process( fun, data, replyType, replyData );
|
||
|
}
|
||
|
|
||
|
/************************************************
|
||
|
*
|
||
|
* SheetIface
|
||
|
*
|
||
|
************************************************/
|
||
|
|
||
|
SheetIface::SheetIface( Sheet* t )
|
||
|
: DCOPObject()
|
||
|
{
|
||
|
m_proxy=0;
|
||
|
m_sheet = t;
|
||
|
|
||
|
sheetNameHasChanged();
|
||
|
|
||
|
}
|
||
|
|
||
|
void SheetIface::sheetNameHasChanged() {
|
||
|
ident.resize(1);
|
||
14 years ago
|
TQObject *currentObj = m_sheet;
|
||
15 years ago
|
while (currentObj != 0L) {
|
||
|
ident.prepend( currentObj->name() );
|
||
|
ident.prepend("/");
|
||
13 years ago
|
currentObj = currentObj->parent();
|
||
15 years ago
|
}
|
||
|
if ( ident[0] == '/' )
|
||
|
ident = ident.mid(1);
|
||
|
|
||
|
if (qstrcmp(ident,objId())!=0) {
|
||
|
setObjId(ident);
|
||
|
|
||
|
delete m_proxy;
|
||
14 years ago
|
TQCString str = objId();
|
||
15 years ago
|
str += "/";
|
||
|
kdDebug(36001)<<"SheetIface::tableNameHasChanged(): new DCOP-ID:"<<objId()<<endl;
|
||
|
m_proxy = new CellProxy( m_sheet, str );
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
SheetIface::~SheetIface()
|
||
|
{
|
||
|
delete m_proxy;
|
||
|
}
|
||
|
|
||
|
DCOPRef SheetIface::cell( int x, int y )
|
||
|
{
|
||
|
// if someone calls us with either x or y 0 he _most_ most likely doesn't
|
||
|
// know that the cell counting starts with 1 (Simon)
|
||
|
// P.S.: I did that mistake for weeks and already started looking for the
|
||
|
// "bug" in kspread ;-)
|
||
|
if ( x == 0 )
|
||
|
x = 1;
|
||
|
if ( y == 0 )
|
||
|
y = 1;
|
||
|
|
||
14 years ago
|
TQCString str = objId() + '/' + Cell::name( x, y ).latin1();
|
||
15 years ago
|
|
||
|
return DCOPRef( kapp->dcopClient()->appId(), str );
|
||
|
}
|
||
|
|
||
14 years ago
|
DCOPRef SheetIface::cell( const TQString& name )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQCString str = objId();
|
||
15 years ago
|
str += "/";
|
||
|
str += name.latin1();
|
||
|
|
||
|
return DCOPRef( kapp->dcopClient()->appId(), str );
|
||
|
}
|
||
|
|
||
|
DCOPRef SheetIface::column( int _col )
|
||
|
{
|
||
|
//First col number = 1
|
||
|
if(_col <1)
|
||
|
return DCOPRef();
|
||
|
return DCOPRef( kapp->dcopClient()->appId(),
|
||
|
m_sheet->nonDefaultColumnFormat( _col )->dcopObject()->objId() );
|
||
|
|
||
|
}
|
||
|
|
||
|
DCOPRef SheetIface::row( int _row )
|
||
|
{
|
||
|
//First row number = 1
|
||
|
if(_row <1)
|
||
|
return DCOPRef();
|
||
|
return DCOPRef( kapp->dcopClient()->appId(),
|
||
|
m_sheet->nonDefaultRowFormat( _row )->dcopObject()->objId() );
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
TQString SheetIface::name() const
|
||
15 years ago
|
{
|
||
|
return m_sheet->sheetName();
|
||
|
}
|
||
|
|
||
|
|
||
|
int SheetIface::maxColumn() const
|
||
|
{
|
||
|
return m_sheet->maxColumn();
|
||
|
|
||
|
}
|
||
|
|
||
14 years ago
|
bool SheetIface::areaHasNoContent(TQRect area) const
|
||
15 years ago
|
{
|
||
|
kdDebug(36001) << "SheetIface::areaHasNoContent("<<area<<");"<<endl;
|
||
|
return m_sheet->areaIsEmpty(area);
|
||
|
}
|
||
|
|
||
14 years ago
|
bool SheetIface::areaHasNoComments(TQRect area) const
|
||
15 years ago
|
{
|
||
|
return m_sheet->areaIsEmpty(area, Sheet::Comment);
|
||
|
}
|
||
|
|
||
|
int SheetIface::maxRow() const
|
||
|
{
|
||
|
return m_sheet->maxRow();
|
||
|
}
|
||
|
|
||
14 years ago
|
bool SheetIface::processDynamic( const TQCString& fun, const TQByteArray&/*data*/,
|
||
|
TQCString& replyType, TQByteArray &replyData )
|
||
15 years ago
|
{
|
||
|
kdDebug(36001) << "Calling '" << fun.data() << "'" << endl;
|
||
|
// Does the name follow the pattern "foobar()" ?
|
||
|
uint len = fun.length();
|
||
|
if ( len < 3 )
|
||
|
return false;
|
||
|
|
||
|
if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
|
||
|
return false;
|
||
|
|
||
|
// Is the function name a valid cell like "B5" ?
|
||
|
Point p( fun.left( len - 2 ).data() );
|
||
|
if ( !p.isValid() )
|
||
|
return false;
|
||
|
|
||
14 years ago
|
TQCString str = objId() + "/" + fun.left( len - 2 );
|
||
15 years ago
|
|
||
|
replyType = "DCOPRef";
|
||
14 years ago
|
TQDataStream out( replyData, IO_WriteOnly );
|
||
15 years ago
|
out << DCOPRef( kapp->dcopClient()->appId(), str );
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool SheetIface::setSheetName( const TQString & name)
|
||
15 years ago
|
{
|
||
|
return m_sheet->setSheetName( name);
|
||
|
}
|
||
|
|
||
|
bool SheetIface::insertColumn( int col,int nbCol )
|
||
|
{
|
||
|
return m_sheet->insertColumn(col,nbCol);
|
||
|
}
|
||
|
|
||
|
bool SheetIface::insertRow( int row,int nbRow)
|
||
|
{
|
||
|
return m_sheet->insertRow(row,nbRow);
|
||
|
}
|
||
|
|
||
|
void SheetIface::removeColumn( int col,int nbCol )
|
||
|
{
|
||
|
m_sheet->removeColumn( col,nbCol );
|
||
|
}
|
||
|
|
||
|
void SheetIface::removeRow( int row,int nbRow )
|
||
|
{
|
||
|
m_sheet->removeRow( row,nbRow );
|
||
|
}
|
||
|
|
||
|
|
||
|
bool SheetIface::isHidden()const
|
||
|
{
|
||
|
return m_sheet->isHidden();
|
||
|
}
|
||
|
|
||
|
|
||
|
bool SheetIface::showGrid() const
|
||
|
{
|
||
|
return m_sheet->getShowGrid();
|
||
|
}
|
||
|
|
||
|
bool SheetIface::showFormula() const
|
||
|
{
|
||
|
return m_sheet->getShowFormula();
|
||
|
}
|
||
|
|
||
|
bool SheetIface::lcMode() const
|
||
|
{
|
||
|
return m_sheet->getLcMode();
|
||
|
}
|
||
|
|
||
|
bool SheetIface::autoCalc() const
|
||
|
{
|
||
|
return m_sheet->getAutoCalc();
|
||
|
}
|
||
|
|
||
|
bool SheetIface::showColumnNumber() const
|
||
|
{
|
||
|
return m_sheet->getShowColumnNumber();
|
||
|
}
|
||
|
|
||
|
bool SheetIface::hideZero() const
|
||
|
{
|
||
|
return m_sheet->getHideZero();
|
||
|
}
|
||
|
|
||
|
bool SheetIface::firstLetterUpper() const
|
||
|
{
|
||
|
return m_sheet->getFirstLetterUpper();
|
||
|
}
|
||
|
|
||
|
void SheetIface::setShowPageBorders( bool b )
|
||
|
{
|
||
|
m_sheet->setShowPageBorders( b );
|
||
|
m_sheet->doc()->updateBorderButton();
|
||
|
}
|
||
|
|
||
|
float SheetIface::paperHeight()const
|
||
|
{
|
||
|
return m_sheet->print()->paperHeight();
|
||
|
}
|
||
|
|
||
|
float SheetIface::paperWidth()const
|
||
|
{
|
||
|
return m_sheet->print()->paperWidth();
|
||
|
}
|
||
|
|
||
|
float SheetIface::leftBorder()const
|
||
|
{
|
||
|
return m_sheet->print()->leftBorder();
|
||
|
}
|
||
|
|
||
|
float SheetIface::rightBorder()const
|
||
|
{
|
||
|
return m_sheet->print()->rightBorder();
|
||
|
}
|
||
|
|
||
|
float SheetIface::topBorder()const
|
||
|
{
|
||
|
return m_sheet->print()->topBorder();
|
||
|
}
|
||
|
|
||
|
float SheetIface::bottomBorder()const
|
||
|
{
|
||
|
return m_sheet->print()->bottomBorder();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString SheetIface::paperFormatString() const
|
||
15 years ago
|
{
|
||
|
return m_sheet->print()->paperFormatString();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString SheetIface::headLeft()const
|
||
15 years ago
|
{
|
||
|
return m_sheet->print()->headLeft();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString SheetIface::headMid()const
|
||
15 years ago
|
{
|
||
|
return m_sheet->print()->headMid();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString SheetIface::headRight()const
|
||
15 years ago
|
{
|
||
|
return m_sheet->print()->headRight();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString SheetIface::footLeft()const
|
||
15 years ago
|
{
|
||
|
return m_sheet->print()->footLeft();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString SheetIface::footMid()const
|
||
15 years ago
|
{
|
||
|
return m_sheet->print()->footMid();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQString SheetIface::footRight()const
|
||
15 years ago
|
{
|
||
|
return m_sheet->print()->footRight();
|
||
|
}
|
||
|
|
||
14 years ago
|
void SheetIface::setHeaderLeft(const TQString & text)
|
||
15 years ago
|
{
|
||
|
m_sheet->print()->setHeadFootLine( text, headMid(), headRight(),
|
||
|
footLeft(), footMid(), footRight() );
|
||
|
}
|
||
|
|
||
14 years ago
|
void SheetIface::setHeaderMiddle(const TQString & text)
|
||
15 years ago
|
{
|
||
|
m_sheet->print()->setHeadFootLine( headLeft(), text, headRight(),
|
||
|
footLeft(), footMid(), footRight() );
|
||
|
|
||
|
}
|
||
|
|
||
14 years ago
|
void SheetIface::setHeaderRight(const TQString & text)
|
||
15 years ago
|
{
|
||
|
m_sheet->print()->setHeadFootLine( headLeft(), headMid(), text,
|
||
|
footLeft(), footMid(), footRight() );
|
||
|
}
|
||
|
|
||
14 years ago
|
void SheetIface::setFooterLeft(const TQString & text)
|
||
15 years ago
|
{
|
||
|
m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
|
||
|
text, footMid(), footRight() );
|
||
|
}
|
||
|
|
||
14 years ago
|
void SheetIface::setFooterMiddle(const TQString & text)
|
||
15 years ago
|
{
|
||
|
m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
|
||
|
footLeft(), text, footRight() );
|
||
|
}
|
||
|
|
||
14 years ago
|
void SheetIface::setFooterRight(const TQString & text)
|
||
15 years ago
|
{
|
||
|
m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
|
||
|
footLeft(), footMid(), text );
|
||
|
}
|
||
|
|
||
|
bool SheetIface::isProtected() const
|
||
|
{
|
||
|
return m_sheet->isProtected();
|
||
|
}
|