kspread

KSpreadTableIface.cc

00001 /* This file is part of the KDE project
00002 
00003    Copyright 2003 Lukas Tinkl <lukas@kde.org>
00004    Copyright 2000, 2002-2003 Laurent Montel <montel@kde.org>
00005    Copyright 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
00006    Copyright 2003 Joseph Wenninger <jowenn@kde.org>
00007    Copyright 2002 Ariya Hidayat <ariya@kde.org>
00008    Copyright 2002 Harri Porten <porten@kde.org>
00009    Copyright 2002 John Dailey <dailey@vt.edu>
00010    Copyright 2001 Simon Hausmann <hausmann@kde.org>
00011    Copyright 2000 Werner Trobin <trobin@kde.org>
00012    Copyright 1999 Torben Weis <weis@kde.org>
00013 
00014    This library is free software; you can redistribute it and/or
00015    modify it under the terms of the GNU Library General Public
00016    License as published by the Free Software Foundation; either
00017    version 2 of the License, or (at your option) any later version.
00018 
00019    This library is distributed in the hope that it will be useful,
00020    but WITHOUT ANY WARRANTY; without even the implied warranty of
00021    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022    Library General Public License for more details.
00023 
00024    You should have received a copy of the GNU Library General Public License
00025    along with this library; see the file COPYING.LIB.  If not, write to
00026    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00027  * Boston, MA 02110-1301, USA.
00028 */
00029 
00030 #include "kspread_sheet.h"
00031 #include "kspread_sheetprint.h"
00032 #include "kspread_util.h"
00033 #include "kspread_doc.h"
00034 
00035 #include <dcopclient.h>
00036 #include <kapplication.h>
00037 #include <kdebug.h>
00038 
00039 #include "KSpreadCellIface.h"
00040 #include "region.h"
00041 
00042 #include "KSpreadTableIface.h"
00043 
00044 using namespace KSpread;
00045 
00046 /*********************************************
00047  *
00048  * CellProxy
00049  *
00050  *********************************************/
00051 
00052 class KSpread::CellProxy : public DCOPObjectProxy
00053 {
00054 public:
00055     CellProxy( Sheet* sheet, const QCString& prefix );
00056     ~CellProxy();
00057 
00058     virtual bool process( const QCString& obj, const QCString& fun, const QByteArray& data,
00059                           QCString& replyType, QByteArray &replyData );
00060 
00061 private:
00062     QCString m_prefix;
00063     CellIface* m_cell;
00064     Sheet* m_sheet;
00065 };
00066 
00067 KSpread::CellProxy::CellProxy( Sheet* sheet, const QCString& prefix )
00068     : DCOPObjectProxy( kapp->dcopClient() ), m_prefix( prefix )
00069 {
00070     m_cell = new CellIface;
00071     m_sheet = sheet;
00072 }
00073 
00074 KSpread::CellProxy::~CellProxy()
00075 {
00076     delete m_cell;
00077 }
00078 
00079 bool KSpread::CellProxy::process( const QCString& obj, const QCString& fun, const QByteArray& data,
00080                                         QCString& replyType, QByteArray &replyData )
00081 {
00082 
00083     kdDebug()<<"CellProxy::process: requested object:"<<obj<<endl;
00084     kdDebug()<<"CellProxy::process: prefix:"<<m_prefix<<endl;
00085     if ( strncmp( m_prefix.data(), obj.data(), m_prefix.length() ) != 0 )
00086         return false;
00087 
00088     if ( fun == "functions()" ) {
00089             replyType = "QCStringList";
00090             QDataStream reply( replyData, IO_WriteOnly );
00091          QCStringList repList=m_cell->functions();
00092         reply<<repList;
00093             return true;
00094     }
00095 
00096     QString cellID=QString::fromUtf8(obj.data() + m_prefix.length());
00097     cellID=m_sheet->sheetName()+"!"+cellID;
00098 
00099     kdDebug()<<"CellProxy::process: cellID="<<cellID<<endl;
00100 
00101     Point p( cellID); //obj.data() + m_prefix.length() );
00102     if ( p.pos().x()<0 ) {
00103     kdDebug(36001)<<"CellProyxy::process: resulting Point is not valid"<<endl;
00104         return false;
00105     }
00106 
00107     kdDebug(36001)<<"all checks finsihed, trying to access cell (x):"<<p.pos().x()<<endl;
00108 
00109     m_cell->setCell( m_sheet, p.pos() );
00110     return m_cell->process( fun, data, replyType, replyData );
00111 }
00112 
00113 /************************************************
00114  *
00115  * SheetIface
00116  *
00117  ************************************************/
00118 
00119 SheetIface::SheetIface( Sheet* t )
00120     : DCOPObject()
00121 {
00122     m_proxy=0;
00123     m_sheet = t;
00124 
00125     sheetNameHasChanged();
00126 
00127 }
00128 
00129 void SheetIface::sheetNameHasChanged() {
00130   ident.resize(1);
00131   QObject *currentObj = m_sheet;
00132     while (currentObj != 0L) {
00133         ident.prepend( currentObj->name() );
00134         ident.prepend("/");
00135         currentObj = currentObj->parent();
00136     }
00137     if ( ident[0] == '/' )
00138         ident = ident.mid(1);
00139 
00140    if (qstrcmp(ident,objId())!=0) {
00141        setObjId(ident);
00142 
00143            delete m_proxy;
00144            QCString str = objId();
00145            str += "/";
00146        kdDebug(36001)<<"SheetIface::tableNameHasChanged(): new DCOP-ID:"<<objId()<<endl;
00147            m_proxy = new CellProxy( m_sheet, str );
00148    }
00149 
00150 }
00151 
00152 
00153 SheetIface::~SheetIface()
00154 {
00155     delete m_proxy;
00156 }
00157 
00158 DCOPRef SheetIface::cell( int x, int y )
00159 {
00160     // if someone calls us with either x or y 0 he _most_ most likely doesn't
00161     // know that the cell counting starts with 1 (Simon)
00162     // P.S.: I did that mistake for weeks and already started looking for the
00163     // "bug" in kspread ;-)
00164     if ( x == 0 )
00165         x = 1;
00166     if ( y == 0 )
00167         y = 1;
00168 
00169     QCString str = objId() + '/' + Cell::name( x, y ).latin1();
00170 
00171     return DCOPRef( kapp->dcopClient()->appId(), str );
00172 }
00173 
00174 DCOPRef SheetIface::cell( const QString& name )
00175 {
00176     QCString str = objId();
00177     str += "/";
00178     str += name.latin1();
00179 
00180     return DCOPRef( kapp->dcopClient()->appId(), str );
00181 }
00182 
00183 DCOPRef SheetIface::column( int _col )
00184 {
00185     //First col number = 1
00186     if(_col <1)
00187         return DCOPRef();
00188     return DCOPRef( kapp->dcopClient()->appId(),
00189             m_sheet->nonDefaultColumnFormat( _col )->dcopObject()->objId() );
00190 
00191 }
00192 
00193 DCOPRef SheetIface::row( int _row )
00194 {
00195     //First row number = 1
00196     if(_row <1)
00197         return DCOPRef();
00198     return DCOPRef( kapp->dcopClient()->appId(),
00199             m_sheet->nonDefaultRowFormat( _row )->dcopObject()->objId() );
00200 }
00201 
00202 
00203 QString SheetIface::name() const
00204 {
00205     return m_sheet->sheetName();
00206 }
00207 
00208 
00209 int SheetIface::maxColumn() const
00210 {
00211     return m_sheet->maxColumn();
00212 
00213 }
00214 
00215 bool SheetIface::areaHasNoContent(QRect area) const
00216 {
00217     kdDebug(36001) << "SheetIface::areaHasNoContent("<<area<<");"<<endl;
00218     return m_sheet->areaIsEmpty(area);
00219 }
00220 
00221 bool SheetIface::areaHasNoComments(QRect area) const
00222 {
00223     return m_sheet->areaIsEmpty(area, Sheet::Comment);
00224 }
00225 
00226 int SheetIface::maxRow() const
00227 {
00228     return m_sheet->maxRow();
00229 }
00230 
00231 bool SheetIface::processDynamic( const QCString& fun, const QByteArray&/*data*/,
00232                                         QCString& replyType, QByteArray &replyData )
00233 {
00234     kdDebug(36001) << "Calling '" << fun.data() << "'" << endl;
00235     // Does the name follow the pattern "foobar()" ?
00236     uint len = fun.length();
00237     if ( len < 3 )
00238         return false;
00239 
00240     if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
00241         return false;
00242 
00243     // Is the function name a valid cell like "B5" ?
00244     Point p( fun.left( len - 2 ).data() );
00245     if ( !p.isValid() )
00246         return false;
00247 
00248     QCString str = objId() + "/" + fun.left( len - 2 );
00249 
00250     replyType = "DCOPRef";
00251     QDataStream out( replyData, IO_WriteOnly );
00252     out << DCOPRef( kapp->dcopClient()->appId(), str );
00253     return true;
00254 }
00255 
00256 bool SheetIface::setSheetName( const QString & name)
00257 {
00258     return m_sheet->setSheetName( name);
00259 }
00260 
00261 bool SheetIface::insertColumn( int col,int nbCol )
00262 {
00263     return m_sheet->insertColumn(col,nbCol);
00264 }
00265 
00266 bool SheetIface::insertRow( int row,int nbRow)
00267 {
00268     return m_sheet->insertRow(row,nbRow);
00269 }
00270 
00271 void SheetIface::removeColumn( int col,int nbCol )
00272 {
00273     m_sheet->removeColumn( col,nbCol );
00274 }
00275 
00276 void SheetIface::removeRow( int row,int nbRow )
00277 {
00278     m_sheet->removeRow( row,nbRow );
00279 }
00280 
00281 
00282 bool SheetIface::isHidden()const
00283 {
00284     return m_sheet->isHidden();
00285 }
00286 
00287 
00288 bool SheetIface::showGrid() const
00289 {
00290     return m_sheet->getShowGrid();
00291 }
00292 
00293 bool SheetIface::showFormula() const
00294 {
00295     return m_sheet->getShowFormula();
00296 }
00297 
00298 bool SheetIface::lcMode() const
00299 {
00300     return m_sheet->getLcMode();
00301 }
00302 
00303 bool SheetIface::autoCalc() const
00304 {
00305     return m_sheet->getAutoCalc();
00306 }
00307 
00308 bool SheetIface::showColumnNumber() const
00309 {
00310     return m_sheet->getShowColumnNumber();
00311 }
00312 
00313 bool SheetIface::hideZero() const
00314 {
00315     return m_sheet->getHideZero();
00316 }
00317 
00318 bool SheetIface::firstLetterUpper() const
00319 {
00320     return m_sheet->getFirstLetterUpper();
00321 }
00322 
00323 void SheetIface::setShowPageBorders( bool b )
00324 {
00325     m_sheet->setShowPageBorders( b );
00326     m_sheet->doc()->updateBorderButton();
00327 }
00328 
00329 float SheetIface::paperHeight()const
00330 {
00331     return m_sheet->print()->paperHeight();
00332 }
00333 
00334 float SheetIface::paperWidth()const
00335 {
00336     return m_sheet->print()->paperWidth();
00337 }
00338 
00339 float SheetIface::leftBorder()const
00340 {
00341     return m_sheet->print()->leftBorder();
00342 }
00343 
00344 float SheetIface::rightBorder()const
00345 {
00346     return m_sheet->print()->rightBorder();
00347 }
00348 
00349 float SheetIface::topBorder()const
00350 {
00351     return m_sheet->print()->topBorder();
00352 }
00353 
00354 float SheetIface::bottomBorder()const
00355 {
00356     return m_sheet->print()->bottomBorder();
00357 }
00358 
00359 QString SheetIface::paperFormatString() const
00360 {
00361     return m_sheet->print()->paperFormatString();
00362 }
00363 
00364 QString SheetIface::headLeft()const
00365 {
00366     return m_sheet->print()->headLeft();
00367 }
00368 
00369 QString SheetIface::headMid()const
00370 {
00371     return m_sheet->print()->headMid();
00372 }
00373 
00374 QString SheetIface::headRight()const
00375 {
00376     return m_sheet->print()->headRight();
00377 }
00378 
00379 QString SheetIface::footLeft()const
00380 {
00381     return m_sheet->print()->footLeft();
00382 }
00383 
00384 QString SheetIface::footMid()const
00385 {
00386     return m_sheet->print()->footMid();
00387 }
00388 
00389 QString SheetIface::footRight()const
00390 {
00391     return m_sheet->print()->footRight();
00392 }
00393 
00394 void SheetIface::setHeaderLeft(const QString & text)
00395 {
00396     m_sheet->print()->setHeadFootLine( text,       headMid(), headRight(),
00397                                        footLeft(), footMid(), footRight() );
00398 }
00399 
00400 void SheetIface::setHeaderMiddle(const QString & text)
00401 {
00402     m_sheet->print()->setHeadFootLine( headLeft(), text,      headRight(),
00403                                        footLeft(), footMid(), footRight() );
00404 
00405 }
00406 
00407 void SheetIface::setHeaderRight(const QString & text)
00408 {
00409     m_sheet->print()->setHeadFootLine( headLeft(), headMid(), text,
00410                                        footLeft(), footMid(), footRight() );
00411 }
00412 
00413 void SheetIface::setFooterLeft(const QString & text)
00414 {
00415     m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
00416                                        text,       footMid(), footRight() );
00417 }
00418 
00419 void SheetIface::setFooterMiddle(const QString & text)
00420 {
00421     m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
00422                                        footLeft(), text,      footRight() );
00423 }
00424 
00425 void SheetIface::setFooterRight(const QString & text)
00426 {
00427     m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
00428                                        footLeft(), footMid(), text );
00429 }
00430 
00431 bool SheetIface::isProtected() const
00432 {
00433     return m_sheet->isProtected();
00434 }
KDE Home | KDE Accessibility Home | Description of Access Keys