kspread Library API Documentation

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., 59 Temple Place - Suite 330,
00027    Boston, MA 02111-1307, USA.
00028 */
00029 
00030 #include "KSpreadTableIface.h"
00031 
00032 #include "kspread_sheet.h"
00033 #include "kspread_sheetprint.h"
00034 #include "kspread_util.h"
00035 #include "kspread_doc.h"
00036 
00037 #include "KSpreadCellIface.h"
00038 
00039 #include <kapplication.h>
00040 #include <dcopclient.h>
00041 #include <kdebug.h>
00042 
00043 /*********************************************
00044  *
00045  * KSpreadCellProxy
00046  *
00047  *********************************************/
00048 
00049 class KSpreadCellProxy : public DCOPObjectProxy
00050 {
00051 public:
00052     KSpreadCellProxy( KSpreadSheet* sheet, const QCString& prefix );
00053     ~KSpreadCellProxy();
00054 
00055     virtual bool process( const QCString& obj, const QCString& fun, const QByteArray& data,
00056                           QCString& replyType, QByteArray &replyData );
00057 
00058 private:
00059     QCString m_prefix;
00060     KSpreadCellIface* m_cell;
00061     KSpreadSheet* m_sheet;
00062 };
00063 
00064 KSpreadCellProxy::KSpreadCellProxy( KSpreadSheet* sheet, const QCString& prefix )
00065     : DCOPObjectProxy( kapp->dcopClient() ), m_prefix( prefix )
00066 {
00067     m_cell = new KSpreadCellIface;
00068     m_sheet = sheet;
00069 }
00070 
00071 KSpreadCellProxy::~KSpreadCellProxy()
00072 {
00073     delete m_cell;
00074 }
00075 
00076 bool KSpreadCellProxy::process( const QCString& obj, const QCString& fun, const QByteArray& data,
00077                                         QCString& replyType, QByteArray &replyData )
00078 {
00079 
00080     kdDebug()<<"KSpreadCellProxy::process: requested object:"<<obj<<endl;
00081     kdDebug()<<"KSpreadCellProxy::process: prefix:"<<m_prefix<<endl;
00082     if ( strncmp( m_prefix.data(), obj.data(), m_prefix.length() ) != 0 )
00083         return FALSE;
00084 
00085     if ( fun == "functions()" ) {
00086             replyType = "QCStringList";
00087             QDataStream reply( replyData, IO_WriteOnly );
00088          QCStringList repList=m_cell->functions();
00089         reply<<repList;
00090             return TRUE;
00091     }
00092 
00093     QString cellID=QString::fromUtf8(obj.data() + m_prefix.length());
00094     cellID=m_sheet->sheetName()+"!"+cellID;
00095 
00096     kdDebug()<<"KSpreadCellProxy::process: cellID="<<cellID<<endl;
00097 
00098     KSpreadPoint p( cellID); //obj.data() + m_prefix.length() );
00099     if ( p.pos.x()<0 ) {
00100     kdDebug(36001)<<"KSpreadCellProyxy::process: resulting KSpreadPoint is not valid"<<endl;
00101         return FALSE;
00102     }
00103 
00104     kdDebug(36001)<<"all checks finsihed, trying to access cell (x):"<<p.pos.x()<<endl;
00105 
00106     m_cell->setCell( m_sheet, p.pos );
00107     return m_cell->process( fun, data, replyType, replyData );
00108 }
00109 
00110 /************************************************
00111  *
00112  * KSpreadSheetIface
00113  *
00114  ************************************************/
00115 
00116 KSpreadSheetIface::KSpreadSheetIface( KSpreadSheet* t )
00117     : DCOPObject()
00118 {
00119     m_proxy=0;
00120     m_sheet = t;
00121 
00122     sheetNameHasChanged();
00123 
00124 }
00125 
00126 void KSpreadSheetIface::sheetNameHasChanged() {
00127   ident.resize(1);
00128   QObject *currentObj = m_sheet;
00129     while (currentObj != 0L) {
00130         ident.prepend( currentObj->name() );
00131         ident.prepend("/");
00132         currentObj = currentObj->parent();
00133     }
00134     if ( ident[0] == '/' )
00135         ident = ident.mid(1);
00136 
00137    if (qstrcmp(ident,objId())!=0) {
00138        setObjId(ident);
00139 
00140            delete m_proxy;
00141            QCString str = objId();
00142            str += "/";
00143        kdDebug(36001)<<"KSpreadSheetIface::tableNameHasChanged(): new DCOP-ID:"<<objId()<<endl;
00144            m_proxy = new KSpreadCellProxy( m_sheet, str );
00145    }
00146 
00147 }
00148 
00149 
00150 KSpreadSheetIface::~KSpreadSheetIface()
00151 {
00152     delete m_proxy;
00153 }
00154 
00155 DCOPRef KSpreadSheetIface::cell( int x, int y )
00156 {
00157     // if someone calls us with either x or y 0 he _most_ most likely doesn't
00158     // know that the cell counting starts with 1 (Simon)
00159     // P.S.: I did that mistake for weeks and already started looking for the
00160     // "bug" in kspread ;-)
00161     if ( x == 0 )
00162         x = 1;
00163     if ( y == 0 )
00164         y = 1;
00165 
00166     QCString str = objId() + '/' + KSpreadCell::name( x, y ).latin1();
00167 
00168     return DCOPRef( kapp->dcopClient()->appId(), str );
00169 }
00170 
00171 DCOPRef KSpreadSheetIface::cell( const QString& name )
00172 {
00173     QCString str = objId();
00174     str += "/";
00175     str += name.latin1();
00176 
00177     return DCOPRef( kapp->dcopClient()->appId(), str );
00178 }
00179 
00180 DCOPRef KSpreadSheetIface::column( int _col )
00181 {
00182     //First col number = 1
00183     if(_col <1)
00184         return DCOPRef();
00185     return DCOPRef( kapp->dcopClient()->appId(),
00186             m_sheet->nonDefaultColumnFormat( _col )->dcopObject()->objId() );
00187 
00188 }
00189 
00190 DCOPRef KSpreadSheetIface::row( int _row )
00191 {
00192     //First row number = 1
00193     if(_row <1)
00194         return DCOPRef();
00195     return DCOPRef( kapp->dcopClient()->appId(),
00196             m_sheet->nonDefaultRowFormat( _row )->dcopObject()->objId() );
00197 }
00198 
00199 
00200 QString KSpreadSheetIface::name() const
00201 {
00202     return m_sheet->sheetName();
00203 }
00204 
00205 
00206 int KSpreadSheetIface::maxColumn() const
00207 {
00208     return m_sheet->maxColumn();
00209 
00210 }
00211 
00212 bool KSpreadSheetIface::areaHasNoContent(QRect area) const
00213 {
00214     kdDebug(36001) << "KSpreadSheetIface::areaHasNoContent("<<area<<");"<<endl;
00215     return m_sheet->areaIsEmpty(area);
00216 }
00217 
00218 bool KSpreadSheetIface::areaHasNoComments(QRect area) const
00219 {
00220     return m_sheet->areaIsEmpty(area,KSpreadSheet::Comment);
00221 }
00222 
00223 int KSpreadSheetIface::maxRow() const
00224 {
00225     return m_sheet->maxRow();
00226 }
00227 
00228 bool KSpreadSheetIface::processDynamic( const QCString& fun, const QByteArray&/*data*/,
00229                                         QCString& replyType, QByteArray &replyData )
00230 {
00231     kdDebug(36001) << "Calling '" << fun.data() << "'" << endl;
00232     // Does the name follow the pattern "foobar()" ?
00233     uint len = fun.length();
00234     if ( len < 3 )
00235         return FALSE;
00236 
00237     if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
00238         return FALSE;
00239 
00240     // Is the function name a valid cell like "B5" ?
00241     KSpreadPoint p( fun.left( len - 2 ).data() );
00242     if ( !p.isValid() )
00243         return FALSE;
00244 
00245     QCString str = objId() + "/" + fun.left( len - 2 );
00246 
00247     replyType = "DCOPRef";
00248     QDataStream out( replyData, IO_WriteOnly );
00249     out << DCOPRef( kapp->dcopClient()->appId(), str );
00250     return TRUE;
00251 }
00252 
00253 bool KSpreadSheetIface::setSheetName( const QString & name)
00254 {
00255     return m_sheet->setSheetName( name);
00256 }
00257 
00258 bool KSpreadSheetIface::insertColumn( int col,int nbCol )
00259 {
00260     return m_sheet->insertColumn(col,nbCol);
00261 }
00262 
00263 bool KSpreadSheetIface::insertRow( int row,int nbRow)
00264 {
00265     return m_sheet->insertRow(row,nbRow);
00266 }
00267 
00268 void KSpreadSheetIface::removeColumn( int col,int nbCol )
00269 {
00270     m_sheet->removeColumn( col,nbCol );
00271 }
00272 
00273 void KSpreadSheetIface::removeRow( int row,int nbRow )
00274 {
00275     m_sheet->removeRow( row,nbRow );
00276 }
00277 
00278 
00279 bool KSpreadSheetIface::isHidden()const
00280 {
00281     return m_sheet->isHidden();
00282 }
00283 
00284 
00285 bool KSpreadSheetIface::showGrid() const
00286 {
00287     return m_sheet->getShowGrid();
00288 }
00289 
00290 bool KSpreadSheetIface::showFormula() const
00291 {
00292     return m_sheet->getShowFormula();
00293 }
00294 
00295 bool KSpreadSheetIface::lcMode() const
00296 {
00297     return m_sheet->getLcMode();
00298 }
00299 
00300 bool KSpreadSheetIface::autoCalc() const
00301 {
00302     return m_sheet->getAutoCalc();
00303 }
00304 
00305 bool KSpreadSheetIface::showColumnNumber() const
00306 {
00307     return m_sheet->getShowColumnNumber();
00308 }
00309 
00310 bool KSpreadSheetIface::hideZero() const
00311 {
00312     return m_sheet->getHideZero();
00313 }
00314 
00315 bool KSpreadSheetIface::firstLetterUpper() const
00316 {
00317     return m_sheet->getFirstLetterUpper();
00318 }
00319 
00320 void KSpreadSheetIface::setShowPageBorders( bool b )
00321 {
00322     m_sheet->setShowPageBorders( b );
00323     m_sheet->doc()->updateBorderButton();
00324 }
00325 
00326 float KSpreadSheetIface::paperHeight()const
00327 {
00328     return m_sheet->print()->paperHeight();
00329 }
00330 
00331 float KSpreadSheetIface::paperWidth()const
00332 {
00333     return m_sheet->print()->paperWidth();
00334 }
00335 
00336 float KSpreadSheetIface::leftBorder()const
00337 {
00338     return m_sheet->print()->leftBorder();
00339 }
00340 
00341 float KSpreadSheetIface::rightBorder()const
00342 {
00343     return m_sheet->print()->rightBorder();
00344 }
00345 
00346 float KSpreadSheetIface::topBorder()const
00347 {
00348     return m_sheet->print()->topBorder();
00349 }
00350 
00351 float KSpreadSheetIface::bottomBorder()const
00352 {
00353     return m_sheet->print()->bottomBorder();
00354 }
00355 
00356 QString KSpreadSheetIface::paperFormatString() const
00357 {
00358     return m_sheet->print()->paperFormatString();
00359 }
00360 
00361 QString KSpreadSheetIface::headLeft()const
00362 {
00363     return m_sheet->print()->headLeft();
00364 }
00365 
00366 QString KSpreadSheetIface::headMid()const
00367 {
00368     return m_sheet->print()->headMid();
00369 }
00370 
00371 QString KSpreadSheetIface::headRight()const
00372 {
00373     return m_sheet->print()->headRight();
00374 }
00375 
00376 QString KSpreadSheetIface::footLeft()const
00377 {
00378     return m_sheet->print()->footLeft();
00379 }
00380 
00381 QString KSpreadSheetIface::footMid()const
00382 {
00383     return m_sheet->print()->footMid();
00384 }
00385 
00386 QString KSpreadSheetIface::footRight()const
00387 {
00388     return m_sheet->print()->footRight();
00389 }
00390 
00391 void KSpreadSheetIface::setHeaderLeft(const QString & text)
00392 {
00393     m_sheet->print()->setHeadFootLine( text,       headMid(), headRight(),
00394                                        footLeft(), footMid(), footRight() );
00395 }
00396 
00397 void KSpreadSheetIface::setHeaderMiddle(const QString & text)
00398 {
00399     m_sheet->print()->setHeadFootLine( headLeft(), text,      headRight(),
00400                                        footLeft(), footMid(), footRight() );
00401 
00402 }
00403 
00404 void KSpreadSheetIface::setHeaderRight(const QString & text)
00405 {
00406     m_sheet->print()->setHeadFootLine( headLeft(), headMid(), text,
00407                                        footLeft(), footMid(), footRight() );
00408 }
00409 
00410 void KSpreadSheetIface::setFooterLeft(const QString & text)
00411 {
00412     m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
00413                                        text,       footMid(), footRight() );
00414 }
00415 
00416 void KSpreadSheetIface::setFooterMiddle(const QString & text)
00417 {
00418     m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
00419                                        footLeft(), text,      footRight() );
00420 }
00421 
00422 void KSpreadSheetIface::setFooterRight(const QString & text)
00423 {
00424     m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
00425                                        footLeft(), footMid(), text );
00426 }
00427 
00428 bool KSpreadSheetIface::isProtected() const
00429 {
00430     return m_sheet->isProtected();
00431 }
KDE Logo
This file is part of the documentation for kspread Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:43:38 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003