summaryrefslogtreecommitdiffstats
path: root/kspread/kspread_doc.h
blob: f4cca795ac0b064a09da15394c28441602f4a3bb (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
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
/* This file is part of the KDE project
   Copyright (C) 2004 Ariya Hidayat <ariya@kde.org>
             (C) 2002-2003 Norbert Andres <nandres@web.de>
             (C) 2000-2005 Laurent Montel <montel@kde.org>
             (C) 2002 John Dailey <dailey@vt.edu>
             (C) 2002 Phillip Mueller <philipp.mueller@gmx.de>
             (C) 2000 Werner Trobin <trobin@kde.org>
             (C) 1999-2000 Simon Hausmann <hausmann@kde.org>
             (C) 1999 David Faure <faure@kde.org>
             (C) 1998-2000 Torben Weis <weis@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_DOC
#define KSPREAD_DOC

#include <tqmap.h>
#include <tqobject.h>
#include <tqpainter.h>
#include <tqrect.h>
#include <tqstring.h>
#include <tqvaluelist.h>

#include <kcompletion.h>

#include <KoDocument.h>
#include <KoZoomHandler.h>

#include "kspread_global.h"

class KCommand;

class KoCommandHistory;
class KoGenStyles;
class KoOasisSettings;
class KoPicture;
class KoPictureCollection;
class KoPictureKey;
class KoStore;
class KoXmlWriter;

class DCOPObject;
class TQDomDocument;
class KSpellConfig;

#define MIME_TYPE "application/x-kspread"

namespace KSpread
{
class Damage;
class ValueParser;
class ValueConverter;
class ValueFormatter;
class ValueCalc;
class Sheet;
class Doc;
class View;
class Map;
class Region;
class StyleManager;
class UndoAction;
class KSPLoadingInfo;
class EmbeddedObject;

struct Reference
{
    TQString sheet_name;
    TQString ref_name;
    TQRect rect;
};

class Plugin
{
 public:
  Plugin() {}
  virtual ~Plugin() {}
  virtual TQDomElement saveXML( TQDomDocument & doc ) const = 0;
};

/**
 * This class holds the data that makes up a spreadsheet.
 */
class KSPREAD_EXPORT Doc : public KoDocument, public KoZoomHandler
{
  Q_OBJECT
  TQ_OBJECT
  TQ_PROPERTY( bool getShowRowHeader READ getShowRowHeader )
  TQ_PROPERTY( bool getShowColHeader READ getShowColHeader )
  TQ_PROPERTY( double getIndentValue READ getIndentValue WRITE setIndentValue )
  TQ_PROPERTY( bool getShowMessageError READ getShowMessageError WRITE setShowMessageError)
  TQ_PROPERTY( bool dontCheckUpperWord READ dontCheckUpperWord WRITE setDontCheckUpperWord)
  TQ_PROPERTY( bool dontCheckTitleCase READ dontCheckTitleCase WRITE setDontCheckTitleCase)

  TQ_PROPERTY( int syntaxVersion READ syntaxVersion )
  TQ_PROPERTY( bool showVerticalScrollBar READ showVerticalScrollBar WRITE setShowVerticalScrollBar )
  TQ_PROPERTY( bool showHorizontalScrollBar READ showHorizontalScrollBar WRITE setShowHorizontalScrollBar )
  TQ_PROPERTY( bool showColumnHeader READ showColumnHeader WRITE setShowColumnHeader )
  TQ_PROPERTY( bool showRowHeader READ showRowHeader WRITE setShowRowHeader )
  TQ_PROPERTY( bool showStatusBar READ showStatusBar WRITE setShowStatusBar )
  TQ_PROPERTY( bool showFormulaBar READ showFormulaBar WRITE setShowFormulaBar )
  TQ_PROPERTY( bool showTabBar READ showTabBar WRITE setShowTabBar )
  TQ_PROPERTY( int undoRedoLimit READ undoRedoLimit WRITE setUndoRedoLimit )

public:

  /**
   * Creates a new document.
   */
  Doc( TQWidget *tqparentWidget = 0, const char *widgetName = 0, TQObject* tqparent = 0,
  const char* name = 0, bool singleViewMode = false );

  /**
   * Destroys the document.
   */
  ~Doc();

  /**
   * Possible values for the "type" argument of the KoGenStyle constructor.
   */
  enum { STYLE_PAGE = 20,
         STYLE_COLUMN_USER,    /**< commmon column styles */
         STYLE_COLUMN_AUTO,    /**< auto column styles */
         STYLE_ROW_USER,       /**< common row styles */
         STYLE_ROW_AUTO,       /**< auto row styles */
         STYLE_CELL_USER,
         STYLE_CELL_AUTO,
         STYLE_PAGEMASTER,
         STYLE_NUMERIC_NUMBER };

  /**
   * Returns list of all documents.
   */
  static TQValueList<Doc*> documents();

  /**
   * Returns the MIME type of KSpread document.
   */
  virtual TQCString mimeType() const { return MIME_TYPE; }

  KLocale *locale () const;
  Map *map () const;
  StyleManager *styleManager () const;
  ValueParser *parser () const;
  ValueFormatter *formatter () const;
  ValueConverter *converter () const;
  ValueCalc *calc () const;

  /**
   * Adds a command to the command history. The command itself
   * would not be executed.
   */
  void addCommand( KCommand* command );

  /*
   * Adds an undo object. This is the same as addCommand, except
   * that it accepts Undo instance. Once every undo object
   * is converted to KCommand, this function will be obsoleted.
   */
  void addCommand( UndoAction* command );

  /**
   * Undoes the last operation.
   */
  void undo();

  /**
   * Redoes the last undo.
   */
  void redo();

  /**
   * Locks the undo buffer.
   */
  void undoLock();

  /**
   * Releases lock of undo buffer.
   */
  void undoUnlock();

  /**
   * Returns true if undo buffer is locked.
   */
  bool undoLocked() const;

  /**
   * Returns the command history for the document. This is used
   * in View for updating the actions (i.e through
   * signal KoCommandHistory::commandExecuted)
   */
  KoCommandHistory* commandHistory();

  /**
   * Returns the name of the unit used to display margins.
   * For example, if unit() returns KoUnit::U_MM, then
   * this functions return "mm".
   */
  TQString unitName() const;

  /**
   * Returns the syntax version of the currently opened file
   */
  int syntaxVersion( ) const;

  /**
   * If b is true, vertical scrollbar is visible, otherwise
   * it will be hidden.
   */
  void setShowVerticalScrollBar( bool b );

  /**
   * Returns true if vertical scroll bar is visible.
   */
  bool showVerticalScrollBar() const;

  /**
   * \deprecated Use showVerticalScrollBar().
   */
  bool getShowVerticalScrollBar() const { return showVerticalScrollBar(); }

  /**
   * If b is true, horizontal scrollbar is visible, otherwise
   * it will be hidden.
   */
  void setShowHorizontalScrollBar( bool b );

  /**
   * Returns true if horizontal scroll bar is visible.
   */
  bool showHorizontalScrollBar() const;

  /**
   * \deprecated Use showHorizontalScrollBar().
   */
  bool getShowHorizontalScrollBar() const { return showHorizontalScrollBar(); }

  /**
   * If b is true, column header is visible, otherwise
   * it will be hidden.
   */
  void setShowColumnHeader( bool b );

  /**
   * Returns true if column header is visible.
   */
  bool showColumnHeader() const;

  /**
   * \deprecated Use setShowColumnHeader().
   */
  void setShowColHeader( bool b ){ setShowColumnHeader( b ) ; }

  /**
   * \deprecated Use showColumnHeader().
   */
  bool getShowColHeader() const { return showColumnHeader(); }

  /**
   * If b is true, row header is visible, otherwise
   * it will be hidden.
   */
  void setShowRowHeader( bool b );

  /**
   * Returns true if row header is visible.
   */
  bool showRowHeader() const;

  /**
   * \deprecated Use showRowHeader().
   */
  bool getShowRowHeader() const { return showRowHeader(); }

  /**
   * Sets the color of the grid.
   */
  void setGridColor( const TQColor& color );

  /**
   * Returns the color of the grid.
   */
  TQColor gridColor() const;

  /**
   * Sets the indentation value.
   */
  void setIndentValue( double val );

  /**
   * Returns the indentation value.
   */
  double indentValue() const;

  /**
   * \deprecated Use indentValue().
   */
  double getIndentValue() const { return indentValue(); }

  /**
   * If b is true, status bar is visible, otherwise
   * it will be hidden.
   */
  void setShowStatusBar( bool b );

  /**
   * Returns true if status bar is visible.
   */
  bool showStatusBar() const;

  /**
   * \deprecated Use showStatusBar().
   */
  bool getShowStatusBar() const { return showStatusBar(); }

  /**
   * If b is true, tab bar is visible, otherwise
   * it will be hidden.
   */
  void setShowTabBar( bool b );

  /**
   * Returns true if tab bar is visible.
   */
  bool showTabBar() const;

  /**
   * \deprecated Use showTabBar().
   */
  bool getShowTabBar() const { return showTabBar(); }

  /**
   * If b is true, formula bar is visible, otherwise
   * it will be hidden.
   */
  void setShowFormulaBar( bool b );

  /**
   * Returns true if formula bar is visible.
   */
  bool showFormulaBar() const;

  /**
   * \deprecated Use showFormulaBar().
   */
  bool getShowFormulaBar() const { return showFormulaBar(); }

  /**
   * If b is true, an error message will pop up whenever error occurs.
   */
  void setShowMessageError( bool b );

  /**
   * Returns true if error message should pop up whenever error occurs.
   */
  bool showMessageError() const;

  /**
   * \deprecated Use showMessageError().
   */
  bool getShowMessageError() const{ return showMessageError(); }

  /**
  * completion mode
  */

  KGlobalSettings::Completion completionMode( )const ;
  void setCompletionMode( KGlobalSettings::Completion _complMode);

  KSpread::MoveTo getMoveToValue()const;
  void setMoveToValue(KSpread::MoveTo _moveTo) ;

  /**
  * Method of calc
  */
  void setTypeOfCalc( MethodOfCalc _calc);
  MethodOfCalc getTypeOfCalc() const;


  /**
   * get custom kspell config
   */
  void setKSpellConfig(KSpellConfig _kspell);
  KSpellConfig * getKSpellConfig();

  bool dontCheckUpperWord() const;
  void setDontCheckUpperWord(bool _b);

  bool dontCheckTitleCase() const;
  void setDontCheckTitleCase(bool _b);

  TQColor pageBorderColor() const;
  void changePageBorderColor( const TQColor  & _color);

  virtual bool completeSaving( KoStore* _store );

  virtual TQDomDocument saveXML();

  enum SaveFlag { SaveAll, SaveSelected }; // kpresenter and kword have have SavePage too

  bool savingWholeDocument();

    /**
     * Save the whole document, or just the selection, into OASIS format
     * When saving the selection, also return the data as plain text and/or plain picture,
     * which are used to insert into the KMultipleDrag drag object.
     *
     * @param store the KoStore to save into
     * @param manifestWriter pointer to a koxmlwriter to add entries to the manifest
     * @param saveFlag either the whole document, or only the selected text/objects.
     * @param plainText must be set when saveFlag==SaveSelected.
     *        It returns the plain text format of the saved data, when available.
     * @param picture must be set when saveFlag==SaveSelected.
     *        It returns the selected picture, when exactly one picture was selected.
     */
  bool saveOasisHelper( KoStore* store, KoXmlWriter* manifestWriter, SaveFlag saveFlag,
                        TQString* plainText = 0, KoPicture* picture = 0 );

  virtual bool saveOasis( KoStore* store, KoXmlWriter* manifestWriter );
  void saveOasisDocumentStyles( KoStore* store, KoGenStyles& mainStyles ) const;
  virtual int supportedSpecialFormats() const;

  virtual bool loadXML( TQIODevice *, const TQDomDocument& doc );
  virtual bool loadOasis( const TQDomDocument& doc, KoOasisStyles& oasisStyles, const TQDomDocument& settings, KoStore* );
  virtual bool loadChildren( KoStore* _store );
  TQDomElement saveAreaName( TQDomDocument& doc ) ;
    void saveOasisAreaName( KoXmlWriter & xmlWriter );

  void loadAreaName( const TQDomElement& element );
  void loadOasisAreaName( const TQDomElement& element );
  void loadOasisCellValidation( const TQDomElement&body );

  virtual void addView( KoView *_view );

  virtual bool initDoc(InitDocFlags flags, TQWidget* tqparentWidget=0);

  /**
   * Change the zoom factor to @p z (e.g. 150 for 150%)
   * and/or change the resolution, given in DPI.
   * This is done on startup and when printing.
   * The same call combines both so that all the updating done behind
   * the scenes is done only once, even if both zoom and DPI must be changed.
   */
  virtual void setZoomAndResolution( int zoom, int dpiX, int dpiY );

  /**
   * updates all properties after zoom changed
   */
  void newZoomAndResolution( bool updateViews, bool forPrint );

  // virtual void printMap( TQPainter & _painter );

  void enableUndo( bool _b );
  void enableRedo( bool _b );

  /**
   * @return true if the document is currently loading.
   */
  bool isLoading() const;

  /**
     Prevents painting. Useful when importing data.
   * @param status switch the painting on/off
   */
  void doNotPaint(bool status);

  virtual void paintContent( TQPainter & painter, const TQRect & rect, bool transparent = false,
                             double zoomX = 1.0, double zoomY = 1.0 );
  void paintContent( TQPainter & painter, const TQRect & rect, bool transparent,
                     Sheet * sheet, bool drawCursor = true );

  bool docData( TQString const & xmlTag, TQDomElement & data );
  void deregisterPlugin( Plugin * plugin );
  void registerPlugin( Plugin * plugin );

  /**
   * Primary entry point for painting.  Use this function to paint groups of cells
   *
   * @param painter the painter object to use.  This should already be
   *                initialized with the world matrix.  The begin and end calls
   *                should surround this function.
   *
   * @param viewRect the document coordinates showing what is actually visible in
   *                 the screen
   *
   * @param view the view of the region -- may be NULL but no selection markers
   *        can be passed in that case.
   *
   * @param cellRegions a list of rectangles indicating the cell ranges needing
   *                    painted.
   *
   * @param sheet the sheet which the cells in cellRegions come from
   *
   * @param drawCursor whether or not to draw the selection rectangle and the choose
   *                   marker
   */
  void paintCellRegions(TQPainter& painter, const TQRect &viewRect,
                        View* view,
                        TQValueList<TQRect> cellRegions,
                        const Sheet* sheet, bool drawCursor);

  virtual DCOPObject* dcopObject();

  void addAreaName(const TQRect &_rect,const TQString & name,const TQString & sheetName);
  const TQValueList<Reference>  & listArea();
  void removeArea( const TQString &name);
  KCompletion & completion();
  void addStringCompletion(const TQString & stringCompletion);

  void changeAreaSheetName(const TQString & oldName,const TQString &sheetName);


  TQRect getRectArea(const TQString &  _sheetName);

  /**
   * Inserts an object to the object list.
   */
  void insertObject( EmbeddedObject * obj );
    /**
    * @return the list of all embedded objects (charts, pictures and koffice objects) Use insertObject to add an object to the list.
    */
  TQPtrList<EmbeddedObject>& embeddedObjects();
  KoPictureCollection *pictureCollection();

  void initConfig();
  void saveConfig();
  void refreshLocale();

  /**
   * Functions to begin a kspread 'operation'.  Calls to emitBeginOperation
   * and emitEndOperation should surround each logical user operation.
   * During the operation, the following should hold true:
   * - No painting will be done to the screen
   * - No cell calculation will be done (maybe there are exceptions, such
   *   as the goalseek operation needs to calculate values)
   * During an operation, calls to Sheet::setRegionPaintDirty mark
   * regions as needing tqrepainted.  Once the emitEndOperation function is
   * called, those regions will be painted all at once, values being calculated
   * as necessary.
   * Calls to begin/endOperation may be nested.  Calcualation/painting will
   * be delayed until the outer begin/end pair has finished.
   *
   * The waitCursor parameter specifies whether to put the hourglass
   * up during the operation.
   *
   */
  void emitBeginOperation(bool waitCursor);

  /** default override of koDocument version.  Changes the cursor to an
   * hourglass
   */
  virtual void emitBeginOperation();

  /**
   * Mark the end of an operation and triggers a tqrepaint of any cells or regions of cells which
   * have been marked as 'dirty' via calls to Sheet::setRegionPaintDirty
   * See above comment to emitBeginOperation(bool).
   */
  virtual void emitEndOperation();

  /**
   * s.a. difference does only specified tasks and thats why it improves performance
   * significantly. rect normally are the visible cells/the cells that need to be updated.
   *
   * TODO:  This is essentially redundant now since emitEndOperation behaviour has been fixed to
   * only update cells that were already in the paint dirty list.
   */
  void emitEndOperation( const Region& region );

  bool delayCalculation() const;


  void updateBorderButton();

  void insertSheet( Sheet * sheet );
  void takeSheet( Sheet * sheet );

  // The user-chosen global unit

  static TQString getAttribute(const TQDomElement &element, const char *attributeName, const TQString &defaultValue)
  {
    return element.attribute( attributeName, defaultValue );
  }

  static int getAttribute(const TQDomElement &element, const char *attributeName, int defaultValue)
  {
    TQString value;
    if ( ( value = element.attribute( attributeName ) ) != TQString() )
	return value.toInt();
    else
	return defaultValue;
  }

  static double getAttribute(const TQDomElement &element, const char *attributeName, double defaultValue)
  {
    TQString value;
      if ( ( value = element.attribute( attributeName ) ) != TQString() )
	return value.toDouble();
      else
	return defaultValue;
  }

    void addIgnoreWordAll( const TQString & word);
    void clearIgnoreWordAll( );
    void addIgnoreWordAllList( const TQStringList & _lst);
    TQStringList spellListIgnoreAll() const ;

    void setDisplaySheet(Sheet *_Sheet );
    Sheet * displaySheet() const;

    /**
     * @return the loading info
     */
    KSPLoadingInfo* loadingInfo() const;

    /**
     * deletes the loading info after loading is complete
     */
    void deleteLoadingInfo();

  void increaseNumOperation();
  void decreaseNumOperation();

  void addDamage( Damage* damage );

/* Function specific when we load config from file */
  void loadConfigFromFile();
  bool configLoadFromFile() const;

  // tqrepaint (update) all views
  void tqrepaint( const TQRect& );
  void tqrepaint( EmbeddedObject* );
  void tqrepaint( const KoRect& );

  virtual void addShell( KoMainWindow *shell );

  int undoRedoLimit() const;
  void setUndoRedoLimit(int _val);

public slots:

  //void newView(); obsloete (Werner)

  void refreshInterface();

  void flushDamages();

signals:
  // Document signals
  /**
   * Emitted if all views have to be updated.
   */
  void sig_updateView();
  /**
  *  Emitted if all interfaces have to be updated.
  */
  void sig_refreshView();
  /**
   * Emitted if we update to locale system
   */
  void sig_refreshLocale();

  void sig_addAreaName( const TQString & );
  void sig_removeAreaName( const TQString & );

  void damagesFlushed( const TQValueList<Damage*>& damages );

protected slots:
  void commandExecuted();
  void documentRestored();

  virtual void openTemplate( const TQString& file );
  virtual void initEmpty();

protected:
  KoView* createViewInstance( TQWidget* tqparent, const char* name );

  void makeUsedPixmapList();
  void insertPixmapKey( KoPictureKey key );

  /**
   * Overloaded function of @ref KoDocument.
   */
  virtual bool completeLoading( KoStore* );

  /**
   * Overloaded function of @ref KoDocument.
   */
  virtual bool saveChildren( KoStore* _store );

  class SavedDocParts : public TQMap<TQString, TQDomElement> {};
  SavedDocParts m_savedDocParts;

private:
  class Private;
  Private* d;

  // don't allow copy or assignment
  Doc( const Doc& );
  Doc& operator=( const Doc& );

  /* helper functions for painting */

  /**
   * This function is called at the end of an operation and is responsible
   * for painting any changes that have occurred in the meantime
   */
  void paintUpdates();

  void PaintRegion(TQPainter& painter, const KoRect &viewRegion,
                   View* view, const TQRect &paintRegion,
                   const Sheet* sheet);

  void loadPaper( TQDomElement const & paper );

    void saveOasisSettings( KoXmlWriter &settingsWriter );
    void loadOasisSettings( const TQDomDocument&settingsDoc );
    void loadOasisIgnoreList( const KoOasisSettings& settings );
    KSPLoadingInfo *m_loadingInfo;
};

} // namespace KSpread

#endif /* KSPREAD_DOC */