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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
|
/* This file is part of the KDE project
Copyright 2004 Ariya Hidayat <ariya@kde.org>
Copyright 2004 Laurent Montel <montel@kde.org>
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.
*/
#ifndef KSPREAD_COMMANDS
#define KSPREAD_COMMANDS
#include <KoPageLayout.h>
#include <KoQueryTrader.h>
#include <KoUnit.h>
#include <tqrect.h>
#include <tqstring.h>
#include <kcommand.h>
#include "kspread_object.h"
#include "kspread_sheet.h" // for Sheet::LayoutDirection
/**
* The KSpread namespace.
*/
namespace KSpread
{
class Cell;
class Doc;
class UndoAction;
/** \page commands Commands
To implement undo and redo functionality, every possible action
by the user for editing and manipulating the document is encapsulated
in a command (based on KCommand).
There is one command class (which will be instantiated) for every unique
action. You need to reimplement the execute() and unexecute() methods
of KCommand.
Each command is created from the user interface, and then added
to the command history (see Doc::commandHistory) using
Doc::addCommand method. Because the command is not immediately
executed, you also need to call the execute() method of that command.
This is an example of typical use of command:
\code
KCommand* command = new RenameSheetCommand( sheet, name );
doc->addCommand( command );
command->execute();
\endcode
Then whenever the user triggers an "undo", the corresponding
unexecute() method of the command is called by the undo action,
thereby reverting the previously executed command. Similar thing
happens for the "redo".
Alphabetical list of commands:
\li AddSheetCommand
\li DissociateCellCommand
\li MergeCellCommand
\li RemoveSheetCommand
\li RenameSheetCommand
\sa Doc::addCommand
\sa KoCommandHistory
*/
/**
* Class UndoWrapperCommand is used to help migration from custom
* UndoAction to KCommand-based system.
* See Doc::addCommand for more information.
*/
class UndoWrapperCommand : public KCommand
{
public:
UndoWrapperCommand( UndoAction* undoAction );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
UndoAction* undoAction;
};
/**
* Class MergeCellCommand implements a command for merging two or more cells
* into one cell.
*/
class MergeCellCommand : public KCommand
{
public:
MergeCellCommand( Cell* cell, int colSpan, int rowSpan );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Cell* cell;
int colSpan;
int rowSpan;
int oldColSpan;
int oldRowSpan;
TQString rangeName;
};
/**
* Class DissociateCellCommand implements a command for breaking merged cells.
*/
class DissociateCellCommand : public KCommand
{
public:
DissociateCellCommand( Cell* cell );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Cell* cell;
int oldColSpan;
int oldRowSpan;
};
/**
* Class RenameSheetCommand implements a command for renaming a sheet.
*
* \sa Sheet::setSheetName
*/
class RenameSheetCommand : public KCommand
{
public:
RenameSheetCommand( Sheet* sheet, const TQString &name );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Sheet* sheet;
TQString oldName;
TQString newName;
};
class HideSheetCommand : public KCommand
{
public:
HideSheetCommand( Sheet* sheet );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Doc* doc;
TQString sheetName;
};
class ShowSheetCommand : public KCommand
{
public:
ShowSheetCommand( Sheet* sheet );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Doc* doc;
TQString sheetName;
};
class AddSheetCommand : public KCommand
{
public:
AddSheetCommand( Sheet* sheet );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Sheet* sheet;
Doc* doc;
};
class RemoveSheetCommand : public KCommand
{
public:
RemoveSheetCommand( Sheet* sheet );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Sheet* sheet;
Doc* doc;
};
/**
* Class SheetPropertiesCommand implements a command for changing sheet properties.
*/
class SheetPropertiesCommand : public KCommand
{
public:
SheetPropertiesCommand( Doc* doc, Sheet* sheet );
void setLayoutDirection( Sheet::LayoutDirection direction );
void setAutoCalc( bool b );
void setShowGrid( bool b );
void setShowPageBorders( bool b );
void setShowFormula( bool b );
void setHideZero( bool b );
void setShowFormulaIndicator( bool b );
void setShowCommentIndicator( bool b );
void setColumnAsNumber( bool b );
void setLcMode( bool b );
void setCapitalizeFirstLetter( bool b );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Sheet* sheet;
Doc* doc;
Sheet::LayoutDirection oldDirection, newDirection;
bool oldAutoCalc, newAutoCalc;
bool oldShowGrid, newShowGrid;
bool oldShowPageBorders, newShowPageBorders;
bool oldShowFormula, newShowFormula;
bool oldHideZero, newHideZero;
bool oldShowFormulaIndicator, newShowFormulaIndicator;
bool oldShowCommentIndicator, newShowCommentIndicator;
bool oldColumnAsNumber, newColumnAsNumber;
bool oldLcMode, newLcMode;
bool oldCapitalizeFirstLetter, newCapitalizeFirstLetter;
};
class InsertColumnCommand : public KCommand
{
public:
InsertColumnCommand( Sheet* s , unsigned int _column, unsigned int _nbCol );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Doc* doc;
TQString sheetName;
unsigned int insertPosColumn;
unsigned int nbColumnInserted;
};
class DefinePrintRangeCommand : public KCommand
{
public:
DefinePrintRangeCommand( Sheet* sheet );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Doc* doc;
TQString sheetName;
TQRect printRangeRedo, printRange;
};
class PaperLayoutCommand : public KCommand
{
public:
PaperLayoutCommand( Sheet* sheet );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Doc* doc;
TQString sheetName;
KoPageLayout pl;
KoPageLayout plRedo;
KoHeadFoot hf;
KoHeadFoot hfRedo;
KoUnit::Unit unit;
KoUnit::Unit unitRedo;
bool printGrid;
bool printGridRedo;
bool printCommentIndicator;
bool printCommentIndicatorRedo;
bool printFormulaIndicator;
bool printFormulaIndicatorRedo;
TQRect printRange;
TQRect printRangeRedo;
TQPair<int, int> printRepeatColumns;
TQPair<int, int> printRepeatColumnsRedo;
TQPair<int, int> printRepeatRows;
TQPair<int, int> printRepeatRowsRedo;
double zoom;
double zoomRedo;
int pageLimitX;
int pageLimitXRedo;
int pageLimitY;
int pageLimitYRedo;
};
class LinkCommand : public KCommand
{
public:
LinkCommand( Cell* cell, const TQString& text, const TQString& link );
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
Cell* cell;
Doc* doc;
TQString oldText;
TQString oldLink;
TQString newText;
TQString newLink;
};
class ChangeObjectGeometryCommand : public KCommand
{
public:
ChangeObjectGeometryCommand( EmbeddedObject *_obj, const KoPoint &_m_diff, const KoSize &_r_diff );
~ChangeObjectGeometryCommand();
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
KoPoint m_diff;
KoSize r_diff;
EmbeddedObject *obj;
Doc *doc;
};
class RemoveObjectCommand : public KCommand
{
public:
RemoveObjectCommand( EmbeddedObject *_obj, bool _cut = false );
~RemoveObjectCommand();
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
EmbeddedObject *obj;
Doc* doc;
bool executed;
bool cut;
};
class InsertObjectCommand : public KCommand
{
public:
InsertObjectCommand( const KoRect& _geometry, KoDocumentEntry&, Canvas *_canvas ); //child
InsertObjectCommand( const KoRect& _geometry, KoDocumentEntry&, const TQRect& _data, Canvas *_canvas ); //chart
InsertObjectCommand( const KoRect& _geometry, KURL& _file, Canvas *_canvas ); //picture
~InsertObjectCommand();
virtual void execute();
virtual void unexecute();
virtual TQString name() const;
protected:
KoRect geometry;
Canvas *canvas;
bool executed;
KoDocumentEntry entry;
TQRect data;
ObjType type;
KURL file;
EmbeddedObject *obj;
};
class RenameNameObjectCommand : public KNamedCommand
{
public:
RenameNameObjectCommand( const TQString &_name, const TQString &_objectName, EmbeddedObject *_obj, Doc *_doc );
~RenameNameObjectCommand();
void execute();
void unexecute();
protected:
TQString oldObjectName, newObjectName;
EmbeddedObject *object;
Doc *doc;
Sheet *m_page;
};
class GeometryPropertiesCommand : public KNamedCommand
{
public:
enum KgpType { ProtectSize, KeepRatio};
GeometryPropertiesCommand( const TQString &name, TQPtrList<EmbeddedObject> &objects,
bool newValue, KgpType type, Doc *_doc );
GeometryPropertiesCommand( const TQString &name, TQValueList<bool> &lst, TQPtrList<EmbeddedObject> &objects,
bool newValue, KgpType type, Doc *_doc );
~GeometryPropertiesCommand();
virtual void execute();
virtual void unexecute();
protected:
TQValueList<bool> m_oldValue;
TQPtrList<EmbeddedObject> m_objects;
bool m_newValue;
KgpType m_type;
Doc *m_doc;
};
class MoveObjectByCmd : public KNamedCommand
{
public:
MoveObjectByCmd( const TQString &_name, const KoPoint &_diff, TQPtrList<EmbeddedObject> &_objects,
Doc *_doc, Sheet *m_page );
~MoveObjectByCmd();
virtual void execute();
virtual void unexecute();
protected:
KoPoint diff;
TQPtrList<EmbeddedObject> objects;
Doc *doc;
Sheet *m_page;
};
} // namespace KSpread
#endif /* KSPREAD_COMMANDS */
|