kspread

KSpreadMapIface.cpp
1/* This file is part of the KDE project
2
3 Copyright 2002 Ariya Hidayat <ariya@kde.org>
4 Copyright 2001 Laurent Montel <montel@kde.org>
5 Copyright 2001 Philipp Mueller <philipp.mueller@gmx.de>
6 Copyright 2000 Werner Trobin <trobin@kde.org>
7 Copyright 1999-2000 Torben Weis <weis@kde.org>
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
25#include <dcopclient.h>
26#include <tdeapplication.h>
27#include <kdebug.h>
28
29#include "kspread_doc.h"
30#include "kspread_map.h"
31#include "kspread_sheet.h"
32
33#include "KSpreadMapIface.h"
34
35using namespace KSpread;
36
37MapIface::MapIface( Map* map )
38 : DCOPObject( map )
39{
40 m_map = map;
41}
42
43DCOPRef MapIface::sheet( const TQString& name )
44{
45 Sheet* t = m_map->findSheet( name );
46 if ( !t )
47 return DCOPRef();
48
49 return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
50}
51
52DCOPRef MapIface::sheetByIndex( int index )
53{
54 Sheet* t = m_map->sheetList().at( index );
55 if ( !t )
56 {
57 kdDebug(36001) << "+++++ No table found at index " << index << endl;
58 return DCOPRef();
59 }
60
61 kdDebug(36001) << "+++++++ Returning table " << t->TQObject::name() << endl;
62
63 return DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
64}
65
66int MapIface::sheetCount() const
67{
68 return m_map->count();
69}
70
71TQStringList MapIface::sheetNames() const
72{
73 TQStringList names;
74
75 TQPtrList<Sheet>& lst = m_map->sheetList();
76 TQPtrListIterator<Sheet> it( lst );
77 for( ; it.current(); ++it )
78 names.append( it.current()->name() );
79
80 return names;
81}
82
83TQValueList<DCOPRef> MapIface::sheets()
84{
85 TQValueList<DCOPRef> t;
86
87 TQPtrList<Sheet>& lst = m_map->sheetList();
88 TQPtrListIterator<Sheet> it( lst );
89 for( ; it.current(); ++it )
90 t.append( DCOPRef( kapp->dcopClient()->appId(), it.current()->dcopObject()->objId() ) );
91
92 return t;
93}
94
95DCOPRef MapIface::insertSheet( const TQString& name )
96{
97 if ( m_map->findSheet( name ) )
98 return sheet( name );
99
100 Sheet* t = m_map->addNewSheet ();
101 t->setSheetName( name );
102
103 return sheet( name );
104}
105
106bool MapIface::processDynamic(const TQCString &fun, const TQByteArray &/*data*/,
107 TQCString& replyType, TQByteArray &replyData)
108{
109 // Does the name follow the pattern "foobar()" ?
110 uint len = fun.length();
111 if ( len < 3 )
112 return false;
113
114 if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
115 return false;
116
117 Sheet* t = m_map->findSheet( fun.left( len - 2 ).data() );
118 if ( !t )
119 return false;
120
121 replyType = "DCOPRef";
122 TQDataStream out( replyData, IO_WriteOnly );
123 out << DCOPRef( kapp->dcopClient()->appId(), t->dcopObject()->objId() );
124 return true;
125}
A map is a simple container for all sheets.
Definition kspread_map.h:59
Sheet * findSheet(const TQString &_name)
searches for a sheet named _name
The KSpread namespace.
Definition commands.h:39