kspread

KSpreadMapIface.cc

00001 /* This file is part of the KDE project
00002    
00003    Copyright 2002 Ariya Hidayat <ariya@kde.org>
00004    Copyright 2001 Laurent Montel <montel@kde.org>
00005    Copyright 2001 Philipp Mueller <philipp.mueller@gmx.de>
00006    Copyright 2000 Werner Trobin <trobin@kde.org>
00007    Copyright 1999-2000 Torben Weis <weis@kde.org>
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Library General Public
00011    License as published by the Free Software Foundation; either
00012    version 2 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017    Library General Public License for more details.
00018 
00019    You should have received a copy of the GNU Library General Public License
00020    along with this library; see the file COPYING.LIB.  If not, write to
00021    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00022  * Boston, MA 02110-1301, USA.
00023 */
00024 
00025 #include <dcopclient.h>
00026 #include <kapplication.h>
00027 #include <kdebug.h>
00028 
00029 #include "kspread_doc.h"
00030 #include "kspread_map.h"
00031 #include "kspread_sheet.h"
00032 
00033 #include "KSpreadMapIface.h"
00034 
00035 using namespace KSpread;
00036 
00037 MapIface::MapIface( Map* map )
00038     : DCOPObject( map )
00039 {
00040     m_map = map;
00041 }
00042 
00043 DCOPRef MapIface::sheet( const QString& name )
00044 {
00045     Sheet* t = m_map->findSheet( name );
00046     if ( !t )
00047         return DCOPRef();
00048 
00049     return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
00050 }
00051 
00052 DCOPRef MapIface::sheetByIndex( int index )
00053 {
00054     Sheet* t = m_map->sheetList().at( index );
00055     if ( !t )
00056     {
00057         kdDebug(36001) << "+++++ No table found at index " << index << endl;
00058         return DCOPRef();
00059     }
00060 
00061     kdDebug(36001) << "+++++++ Returning table " << t->QObject::name() << endl;
00062 
00063     return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
00064 }
00065 
00066 int MapIface::sheetCount() const
00067 {
00068     return m_map->count();
00069 }
00070 
00071 QStringList MapIface::sheetNames() const
00072 {
00073     QStringList names;
00074 
00075     QPtrList<Sheet>& lst = m_map->sheetList();
00076     QPtrListIterator<Sheet> it( lst );
00077     for( ; it.current(); ++it )
00078         names.append( it.current()->name() );
00079 
00080     return names;
00081 }
00082 
00083 QValueList<DCOPRef> MapIface::sheets()
00084 {
00085     QValueList<DCOPRef> t;
00086 
00087     QPtrList<Sheet>& lst = m_map->sheetList();
00088     QPtrListIterator<Sheet> it( lst );
00089     for( ; it.current(); ++it )
00090         t.append( DCOPRef( kapp->dcopClient()->appId(), it.current()->dcopObject()->objId() ) );
00091 
00092     return t;
00093 }
00094 
00095 DCOPRef MapIface::insertSheet( const QString& name )
00096 {
00097     if ( m_map->findSheet( name ) )
00098         return sheet( name );
00099 
00100     Sheet* t = m_map->addNewSheet ();
00101     t->setSheetName( name );
00102 
00103     return sheet( name );
00104 }
00105 
00106 bool MapIface::processDynamic(const QCString &fun, const QByteArray &/*data*/,
00107                                      QCString& replyType, QByteArray &replyData)
00108 {
00109     // Does the name follow the pattern "foobar()" ?
00110     uint len = fun.length();
00111     if ( len < 3 )
00112         return false;
00113 
00114     if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
00115         return false;
00116 
00117     Sheet* t = m_map->findSheet( fun.left( len - 2 ).data() );
00118     if ( !t )
00119         return false;
00120 
00121     replyType = "DCOPRef";
00122     QDataStream out( replyData, IO_WriteOnly );
00123     out << DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
00124     return true;
00125 }
KDE Home | KDE Accessibility Home | Description of Access Keys