summaryrefslogtreecommitdiffstats
path: root/kspread/KSpreadTableIface.cc
blob: cbf37f202d7925e67e50f992f570f783e89e6518 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
/* This file is part of the KDE project

   Copyright 2003 Lukas Tinkl <[email protected]>
   Copyright 2000, 2002-2003 Laurent Montel <[email protected]>
   Copyright 2001-2003 Philipp Mueller <[email protected]>
   Copyright 2003 Joseph Wenninger <[email protected]>
   Copyright 2002 Ariya Hidayat <[email protected]>
   Copyright 2002 Harri Porten <[email protected]>
   Copyright 2002 John Dailey <[email protected]>
   Copyright 2001 Simon Hausmann <[email protected]>
   Copyright 2000 Werner Trobin <[email protected]>
   Copyright 1999 Torben Weis <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "kspread_sheet.h"
#include "kspread_sheetprint.h"
#include "kspread_util.h"
#include "kspread_doc.h"

#include <dcopclient.h>
#include <tdeapplication.h>
#include <kdebug.h>

#include "KSpreadCellIface.h"
#include "region.h"

#include "KSpreadTableIface.h"

using namespace KSpread;

/*********************************************
 *
 * CellProxy
 *
 *********************************************/

class KSpread::CellProxy : public DCOPObjectProxy
{
public:
    CellProxy( Sheet* sheet, const TQCString& prefix );
    ~CellProxy();

    virtual bool process( const TQCString& obj, const TQCString& fun, const TQByteArray& data,
                          TQCString& replyType, TQByteArray &replyData );

private:
    TQCString m_prefix;
    CellIface* m_cell;
    Sheet* m_sheet;
};

KSpread::CellProxy::CellProxy( Sheet* sheet, const TQCString& prefix )
    : DCOPObjectProxy( kapp->dcopClient() ), m_prefix( prefix )
{
    m_cell = new CellIface;
    m_sheet = sheet;
}

KSpread::CellProxy::~CellProxy()
{
    delete m_cell;
}

bool KSpread::CellProxy::process( const TQCString& obj, const TQCString& fun, const TQByteArray& data,
                                        TQCString& replyType, TQByteArray &replyData )
{

	kdDebug()<<"CellProxy::process: requested object:"<<obj<<endl;
	kdDebug()<<"CellProxy::process: prefix:"<<m_prefix<<endl;
    if ( strncmp( m_prefix.data(), obj.data(), m_prefix.length() ) != 0 )
        return false;

	if ( fun == "functions()" ) {
        	replyType = "QCStringList";
	        TQDataStream reply( replyData, IO_WriteOnly );
		 QCStringList repList=m_cell->functions();
		reply<<repList;
	        return true;
	}

    TQString cellID=TQString::fromUtf8(obj.data() + m_prefix.length());
    cellID=m_sheet->sheetName()+"!"+cellID;

    kdDebug()<<"CellProxy::process: cellID="<<cellID<<endl;

    Point p( cellID); //obj.data() + m_prefix.length() );
    if ( p.pos().x()<0 ) {
	kdDebug(36001)<<"CellProyxy::process: resulting Point is not valid"<<endl;
        return false;
    }

    kdDebug(36001)<<"all checks finsihed, trying to access cell (x):"<<p.pos().x()<<endl;

    m_cell->setCell( m_sheet, p.pos() );
    return m_cell->process( fun, data, replyType, replyData );
}

/************************************************
 *
 * SheetIface
 *
 ************************************************/

SheetIface::SheetIface( Sheet* t )
    : DCOPObject()
{
    m_proxy=0;
    m_sheet = t;

    sheetNameHasChanged();

}

void SheetIface::sheetNameHasChanged() {
  ident.resize(1);
  TQObject *currentObj = m_sheet;
    while (currentObj != 0L) {
        ident.prepend( currentObj->name() );
        ident.prepend("/");
        currentObj = currentObj->parent();
    }
    if ( ident[0] == '/' )
        ident = ident.mid(1);

   if (qstrcmp(ident,objId())!=0) {
	   setObjId(ident);

           delete m_proxy;
           TQCString str = objId();
           str += "/";
	   kdDebug(36001)<<"SheetIface::tableNameHasChanged(): new DCOP-ID:"<<objId()<<endl;
           m_proxy = new CellProxy( m_sheet, str );
   }

}


SheetIface::~SheetIface()
{
    delete m_proxy;
}

DCOPRef SheetIface::cell( int x, int y )
{
    // if someone calls us with either x or y 0 he _most_ most likely doesn't
    // know that the cell counting starts with 1 (Simon)
    // P.S.: I did that mistake for weeks and already started looking for the
    // "bug" in kspread ;-)
    if ( x == 0 )
        x = 1;
    if ( y == 0 )
        y = 1;

    TQCString str = objId() + '/' + Cell::name( x, y ).latin1();

    return DCOPRef( kapp->dcopClient()->appId(), str );
}

DCOPRef SheetIface::cell( const TQString& name )
{
    TQCString str = objId();
    str += "/";
    str += name.latin1();

    return DCOPRef( kapp->dcopClient()->appId(), str );
}

DCOPRef SheetIface::column( int _col )
{
    //First col number = 1
    if(_col <1)
        return DCOPRef();
    return DCOPRef( kapp->dcopClient()->appId(),
		    m_sheet->nonDefaultColumnFormat( _col )->dcopObject()->objId() );

}

DCOPRef SheetIface::row( int _row )
{
    //First row number = 1
    if(_row <1)
        return DCOPRef();
    return DCOPRef( kapp->dcopClient()->appId(),
		    m_sheet->nonDefaultRowFormat( _row )->dcopObject()->objId() );
}


TQString SheetIface::name() const
{
    return m_sheet->sheetName();
}


int SheetIface::maxColumn() const
{
    return m_sheet->maxColumn();

}

bool SheetIface::areaHasNoContent(TQRect area) const
{
	kdDebug(36001) << "SheetIface::areaHasNoContent("<<area<<");"<<endl;
	return m_sheet->areaIsEmpty(area);
}

bool SheetIface::areaHasNoComments(TQRect area) const
{
	return m_sheet->areaIsEmpty(area, Sheet::Comment);
}

int SheetIface::maxRow() const
{
    return m_sheet->maxRow();
}

bool SheetIface::processDynamic( const TQCString& fun, const TQByteArray&/*data*/,
                                        TQCString& replyType, TQByteArray &replyData )
{
    kdDebug(36001) << "Calling '" << fun.data() << "'" << endl;
    // Does the name follow the pattern "foobar()" ?
    uint len = fun.length();
    if ( len < 3 )
        return false;

    if ( fun[ len - 1 ] != ')' || fun[ len - 2 ] != '(' )
        return false;

    // Is the function name a valid cell like "B5" ?
    Point p( fun.left( len - 2 ).data() );
    if ( !p.isValid() )
        return false;

    TQCString str = objId() + "/" + fun.left( len - 2 );

    replyType = "DCOPRef";
    TQDataStream out( replyData, IO_WriteOnly );
    out << DCOPRef( kapp->dcopClient()->appId(), str );
    return true;
}

bool SheetIface::setSheetName( const TQString & name)
{
    return m_sheet->setSheetName( name);
}

bool SheetIface::insertColumn( int col,int nbCol )
{
    return m_sheet->insertColumn(col,nbCol);
}

bool SheetIface::insertRow( int row,int nbRow)
{
    return m_sheet->insertRow(row,nbRow);
}

void SheetIface::removeColumn( int col,int nbCol )
{
    m_sheet->removeColumn( col,nbCol );
}

void SheetIface::removeRow( int row,int nbRow )
{
    m_sheet->removeRow( row,nbRow );
}


bool SheetIface::isHidden()const
{
    return m_sheet->isHidden();
}


bool SheetIface::showGrid() const
{
    return m_sheet->getShowGrid();
}

bool SheetIface::showFormula() const
{
    return m_sheet->getShowFormula();
}

bool SheetIface::lcMode() const
{
    return m_sheet->getLcMode();
}

bool SheetIface::autoCalc() const
{
    return m_sheet->getAutoCalc();
}

bool SheetIface::showColumnNumber() const
{
    return m_sheet->getShowColumnNumber();
}

bool SheetIface::hideZero() const
{
    return m_sheet->getHideZero();
}

bool SheetIface::firstLetterUpper() const
{
    return m_sheet->getFirstLetterUpper();
}

void SheetIface::setShowPageBorders( bool b )
{
    m_sheet->setShowPageBorders( b );
    m_sheet->doc()->updateBorderButton();
}

float SheetIface::paperHeight()const
{
    return m_sheet->print()->paperHeight();
}

float SheetIface::paperWidth()const
{
    return m_sheet->print()->paperWidth();
}

float SheetIface::leftBorder()const
{
    return m_sheet->print()->leftBorder();
}

float SheetIface::rightBorder()const
{
    return m_sheet->print()->rightBorder();
}

float SheetIface::topBorder()const
{
    return m_sheet->print()->topBorder();
}

float SheetIface::bottomBorder()const
{
    return m_sheet->print()->bottomBorder();
}

TQString SheetIface::paperFormatString() const
{
    return m_sheet->print()->paperFormatString();
}

TQString SheetIface::headLeft()const
{
    return m_sheet->print()->headLeft();
}

TQString SheetIface::headMid()const
{
    return m_sheet->print()->headMid();
}

TQString SheetIface::headRight()const
{
    return m_sheet->print()->headRight();
}

TQString SheetIface::footLeft()const
{
    return m_sheet->print()->footLeft();
}

TQString SheetIface::footMid()const
{
    return m_sheet->print()->footMid();
}

TQString SheetIface::footRight()const
{
    return m_sheet->print()->footRight();
}

void SheetIface::setHeaderLeft(const TQString & text)
{
    m_sheet->print()->setHeadFootLine( text,       headMid(), headRight(),
                                       footLeft(), footMid(), footRight() );
}

void SheetIface::setHeaderMiddle(const TQString & text)
{
    m_sheet->print()->setHeadFootLine( headLeft(), text,      headRight(),
                                       footLeft(), footMid(), footRight() );

}

void SheetIface::setHeaderRight(const TQString & text)
{
    m_sheet->print()->setHeadFootLine( headLeft(), headMid(), text,
                                       footLeft(), footMid(), footRight() );
}

void SheetIface::setFooterLeft(const TQString & text)
{
    m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
                                       text,       footMid(), footRight() );
}

void SheetIface::setFooterMiddle(const TQString & text)
{
    m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
                                       footLeft(), text,      footRight() );
}

void SheetIface::setFooterRight(const TQString & text)
{
    m_sheet->print()->setHeadFootLine( headLeft(), headMid(), headRight(),
                                       footLeft(), footMid(), text );
}

bool SheetIface::isProtected() const
{
    return m_sheet->isProtected();
}