kspread

KSpreadTableIface.cpp
1/* This file is part of the KDE project
2
3 Copyright 2003 Lukas Tinkl <lukas@kde.org>
4 Copyright 2000, 2002-2003 Laurent Montel <montel@kde.org>
5 Copyright 2001-2003 Philipp Mueller <philipp.mueller@gmx.de>
6 Copyright 2003 Joseph Wenninger <jowenn@kde.org>
7 Copyright 2002 Ariya Hidayat <ariya@kde.org>
8 Copyright 2002 Harri Porten <porten@kde.org>
9 Copyright 2002 John Dailey <dailey@vt.edu>
10 Copyright 2001 Simon Hausmann <hausmann@kde.org>
11 Copyright 2000 Werner Trobin <trobin@kde.org>
12 Copyright 1999 Torben Weis <weis@kde.org>
13
14 This library is free software; you can redistribute it and/or
15 modify it under the terms of the GNU Library General Public
16 License as published by the Free Software Foundation; either
17 version 2 of the License, or (at your option) any later version.
18
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Library General Public License for more details.
23
24 You should have received a copy of the GNU Library General Public License
25 along with this library; see the file COPYING.LIB. If not, write to
26 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27 * Boston, MA 02110-1301, USA.
28*/
29
30#include "kspread_sheet.h"
31#include "kspread_sheetprint.h"
32#include "kspread_util.h"
33#include "kspread_doc.h"
34
35#include <dcopclient.h>
36#include <tdeapplication.h>
37#include <kdebug.h>
38
39#include "KSpreadCellIface.h"
40#include "region.h"
41
42#include "KSpreadTableIface.h"
43
44using namespace KSpread;
45
46/*********************************************
47 *
48 * CellProxy
49 *
50 *********************************************/
51
52class KSpread::CellProxy : public DCOPObjectProxy
53{
54public:
55 CellProxy( Sheet* sheet, const TQCString& prefix );
56 ~CellProxy();
57
58 virtual bool process( const TQCString& obj, const TQCString& fun, const TQByteArray& data,
59 TQCString& replyType, TQByteArray &replyData );
60
61private:
62 TQCString m_prefix;
63 CellIface* m_cell;
64 Sheet* m_sheet;
65};
66
67KSpread::CellProxy::CellProxy( Sheet* sheet, const TQCString& prefix )
68 : DCOPObjectProxy( kapp->dcopClient() ), m_prefix( prefix )
69{
70 m_cell = new CellIface;
71 m_sheet = sheet;
72}
73
74KSpread::CellProxy::~CellProxy()
75{
76 delete m_cell;
77}
78
79bool KSpread::CellProxy::process( const TQCString& obj, const TQCString& fun, const TQByteArray& data,
80 TQCString& replyType, TQByteArray &replyData )
81{
82
83 kdDebug()<<"CellProxy::process: requested object:"<<obj<<endl;
84 kdDebug()<<"CellProxy::process: prefix:"<<m_prefix<<endl;
85 if ( strncmp( m_prefix.data(), obj.data(), m_prefix.length() ) != 0 )
86 return false;
87
88 if ( fun == "functions()" ) {
89 replyType = "QCStringList";
90 TQDataStream reply( replyData, IO_WriteOnly );
91 QCStringList repList=m_cell->functions();
92 reply<<repList;
93 return true;
94 }
95
96 TQString cellID=TQString::fromUtf8(obj.data() + m_prefix.length());
97 cellID=m_sheet->sheetName()+"!"+cellID;
98
99 kdDebug()<<"CellProxy::process: cellID="<<cellID<<endl;
100
101 Point p( cellID); //obj.data() + m_prefix.length() );
102 if ( p.pos().x()<0 ) {
103 kdDebug(36001)<<"CellProyxy::process: resulting Point is not valid"<<endl;
104 return false;
105 }
106
107 kdDebug(36001)<<"all checks finsihed, trying to access cell (x):"<<p.pos().x()<<endl;
108
109 m_cell->setCell( m_sheet, p.pos() );
110 return m_cell->process( fun, data, replyType, replyData );
111}
112
113/************************************************
114 *
115 * SheetIface
116 *
117 ************************************************/
118
119SheetIface::SheetIface( Sheet* t )
120 : DCOPObject()
121{
122 m_proxy=0;
123 m_sheet = t;
124
125 sheetNameHasChanged();
126
127}
128
129void SheetIface::sheetNameHasChanged() {
130 ident.resize(1);
131 TQObject *currentObj = m_sheet;
132 while (currentObj != 0L) {
133 ident.prepend( currentObj->name() );
134 ident.prepend("/");
135 currentObj = currentObj->parent();
136 }
137 if ( ident[0] == '/' )
138 ident = ident.mid(1);
139
140 if (qstrcmp(ident,objId())!=0) {
141 setObjId(ident);
142
143 delete m_proxy;
144 TQCString str = objId();
145 str += "/";
146 kdDebug(36001)<<"SheetIface::tableNameHasChanged(): new DCOP-ID:"<<objId()<<endl;
147 m_proxy = new CellProxy( m_sheet, str );
148 }
149
150}
151
152
153SheetIface::~SheetIface()
154{
155 delete m_proxy;
156}
157
158DCOPRef SheetIface::cell( int x, int y )
159{
160 // if someone calls us with either x or y 0 he _most_ most likely doesn't
161 // know that the cell counting starts with 1 (Simon)
162 // P.S.: I did that mistake for weeks and already started looking for the
163 // "bug" in kspread ;-)
164 if ( x == 0 )
165 x = 1;
166 if ( y == 0 )
167 y = 1;
168
169 TQCString str = objId() + '/' + Cell::name( x, y ).latin1();
170
171 return DCOPRef( kapp->dcopClient()->appId(), str );
172}
173
174DCOPRef SheetIface::cell( const TQString& name )
175{
176 TQCString str = objId();
177 str += "/";
178 str += name.latin1();
179
180 return DCOPRef( kapp->dcopClient()->appId(), str );
181}
182
183DCOPRef SheetIface::column( int _col )
184{
185 //First col number = 1
186 if(_col <1)
187 return DCOPRef();
188 return DCOPRef( kapp->dcopClient()->appId(),
189 m_sheet->nonDefaultColumnFormat( _col )->dcopObject()->objId() );
190
191}
192
193DCOPRef SheetIface::row( int _row )
194{
195 //First row number = 1
196 if(_row <1)
197 return DCOPRef();
198 return DCOPRef( kapp->dcopClient()->appId(),
199 m_sheet->nonDefaultRowFormat( _row )->dcopObject()->objId() );
200}
201
202
203TQString SheetIface::name() const
204{
205 return m_sheet->sheetName();
206}
207
208
209int SheetIface::maxColumn() const
210{
211 return m_sheet->maxColumn();
212
213}
214
215bool SheetIface::areaHasNoContent(TQRect area) const
216{
217 kdDebug(36001) << "SheetIface::areaHasNoContent("<<area<<");"<<endl;
218 return m_sheet->areaIsEmpty(area);
219}
220
221bool SheetIface::areaHasNoComments(TQRect area) const
222{
223 return m_sheet->areaIsEmpty(area, Sheet::Comment);
224}
225
226int SheetIface::maxRow() const
227{
228 return m_sheet->maxRow();
229}
230
231bool SheetIface::processDynamic( const TQCString& fun, const TQByteArray&/*data*/,
232 TQCString& replyType, TQByteArray &replyData )
233{
234 kdDebug(36001) << "Calling '" << fun.data() << "'" << endl;
235 // Does the name follow the pattern "foobar()" ?
236 uint len = fun.length();
237 if ( len < 3 )
238 return false;
239
240 if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
241 return false;
242
243 // Is the function name a valid cell like "B5" ?
244 Point p( fun.left( len - 2 ).data() );
245 if ( !p.isValid() )
246 return false;
247
248 TQCString str = objId() + "/" + fun.left( len - 2 );
249
250 replyType = "DCOPRef";
251 TQDataStream out( replyData, IO_WriteOnly );
252 out << DCOPRef( kapp->dcopClient()->appId(), str );
253 return true;
254}
255
256bool SheetIface::setSheetName( const TQString & name)
257{
258 return m_sheet->setSheetName( name);
259}
260
261bool SheetIface::insertColumn( int col,int nbCol )
262{
263 return m_sheet->insertColumn(col,nbCol);
264}
265
266bool SheetIface::insertRow( int row,int nbRow)
267{
268 return m_sheet->insertRow(row,nbRow);
269}
270
271void SheetIface::removeColumn( int col,int nbCol )
272{
273 m_sheet->removeColumn( col,nbCol );
274}
275
276void SheetIface::removeRow( int row,int nbRow )
277{
278 m_sheet->removeRow( row,nbRow );
279}
280
281
282bool SheetIface::isHidden()const
283{
284 return m_sheet->isHidden();
285}
286
287
288bool SheetIface::showGrid() const
289{
290 return m_sheet->getShowGrid();
291}
292
293bool SheetIface::showFormula() const
294{
295 return m_sheet->getShowFormula();
296}
297
298bool SheetIface::lcMode() const
299{
300 return m_sheet->getLcMode();
301}
302
303bool SheetIface::autoCalc() const
304{
305 return m_sheet->getAutoCalc();
306}
307
308bool SheetIface::showColumnNumber() const
309{
310 return m_sheet->getShowColumnNumber();
311}
312
313bool SheetIface::hideZero() const
314{
315 return m_sheet->getHideZero();
316}
317
318bool SheetIface::firstLetterUpper() const
319{
320 return m_sheet->getFirstLetterUpper();
321}
322
323void SheetIface::setShowPageBorders( bool b )
324{
325 m_sheet->setShowPageBorders( b );
326 m_sheet->doc()->updateBorderButton();
327}
328
329float SheetIface::paperHeight()const
330{
331 return m_sheet->print()->paperHeight();
332}
333
334float SheetIface::paperWidth()const
335{
336 return m_sheet->print()->paperWidth();
337}
338
339float SheetIface::leftBorder()const
340{
341 return m_sheet->print()->leftBorder();
342}
343
344float SheetIface::rightBorder()const
345{
346 return m_sheet->print()->rightBorder();
347}
348
349float SheetIface::topBorder()const
350{
351 return m_sheet->print()->topBorder();
352}
353
354float SheetIface::bottomBorder()const
355{
356 return m_sheet->print()->bottomBorder();
357}
358
359TQString SheetIface::paperFormatString() const
360{
361 return m_sheet->print()->paperFormatString();
362}
363
364TQString SheetIface::headLeft()const
365{
366 return m_sheet->print()->headLeft();
367}
368
369TQString SheetIface::headMid()const
370{
371 return m_sheet->print()->headMid();
372}
373
374TQString SheetIface::headRight()const
375{
376 return m_sheet->print()->headRight();
377}
378
379TQString SheetIface::footLeft()const
380{
381 return m_sheet->print()->footLeft();
382}
383
384TQString SheetIface::footMid()const
385{
386 return m_sheet->print()->footMid();
387}
388
389TQString SheetIface::footRight()const
390{
391 return m_sheet->print()->footRight();
392}
393
394void SheetIface::setHeaderLeft(const TQString & text)
395{
396 m_sheet->print()->setHeadFootLine( text, headMid(), headRight(),
397 footLeft(), footMid(), footRight() );
398}
399
400void SheetIface::setHeaderMiddle(const TQString & text)
401{
402 m_sheet->print()->setHeadFootLine( headLeft(), text, headRight(),
403 footLeft(), footMid(), footRight() );
404
405}
406
407void SheetIface::setHeaderRight(const TQString & text)
408{
409 m_sheet->print()->setHeadFootLine( headLeft(), headMid(), text,
410 footLeft(), footMid(), footRight() );
411}
412
413void SheetIface::setFooterLeft(const TQString & text)
414{
415 m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
416 text, footMid(), footRight() );
417}
418
419void SheetIface::setFooterMiddle(const TQString & text)
420{
421 m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
422 footLeft(), text, footRight() );
423}
424
425void SheetIface::setFooterRight(const TQString & text)
426{
427 m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
428 footLeft(), footMid(), text );
429}
430
431bool SheetIface::isProtected() const
432{
433 return m_sheet->isProtected();
434}
TQString name() const
Returns the name of the cell.
Represents the position of a single cell in a workbook.
The KSpread namespace.
Definition commands.h:39