kspread

kspread_doc.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Ariya Hidayat <ariya@kde.org>
00003              (C) 2002-2003 Norbert Andres <nandres@web.de>
00004              (C) 2000-2005 Laurent Montel <montel@kde.org>
00005              (C) 2002 John Dailey <dailey@vt.edu>
00006              (C) 2002 Phillip Mueller <philipp.mueller@gmx.de>
00007              (C) 2000 Werner Trobin <trobin@kde.org>
00008              (C) 1999-2000 Simon Hausmann <hausmann@kde.org>
00009              (C) 1999 David Faure <faure@kde.org>
00010              (C) 1998-2000 Torben Weis <weis@kde.org>
00011 
00012    This library is free software; you can redistribute it and/or
00013    modify it under the terms of the GNU Library General Public
00014    License as published by the Free Software Foundation; either
00015    version 2 of the License, or (at your option) any later version.
00016 
00017    This library is distributed in the hope that it will be useful,
00018    but WITHOUT ANY WARRANTY; without even the implied warranty of
00019    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020    Library General Public License for more details.
00021 
00022    You should have received a copy of the GNU Library General Public License
00023    along with this library; see the file COPYING.LIB.  If not, write to
00024    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00025  * Boston, MA 02110-1301, USA.
00026 */
00027 
00028 #ifndef KSPREAD_DOC
00029 #define KSPREAD_DOC
00030 
00031 #include <qmap.h>
00032 #include <qobject.h>
00033 #include <qpainter.h>
00034 #include <qrect.h>
00035 #include <qstring.h>
00036 #include <qvaluelist.h>
00037 
00038 #include <kcompletion.h>
00039 
00040 #include <KoDocument.h>
00041 #include <KoZoomHandler.h>
00042 
00043 #include "kspread_global.h"
00044 
00045 class KCommand;
00046 
00047 class KoCommandHistory;
00048 class KoGenStyles;
00049 class KoOasisSettings;
00050 class KoPicture;
00051 class KoPictureCollection;
00052 class KoPictureKey;
00053 class KoStore;
00054 class KoXmlWriter;
00055 
00056 class DCOPObject;
00057 class QDomDocument;
00058 class KSpellConfig;
00059 
00060 #define MIME_TYPE "application/x-kspread"
00061 
00062 namespace KSpread
00063 {
00064 class Damage;
00065 class ValueParser;
00066 class ValueConverter;
00067 class ValueFormatter;
00068 class ValueCalc;
00069 class Sheet;
00070 class Doc;
00071 class View;
00072 class Map;
00073 class Region;
00074 class StyleManager;
00075 class UndoAction;
00076 class KSPLoadingInfo;
00077 class EmbeddedObject;
00078 
00079 struct Reference
00080 {
00081     QString sheet_name;
00082     QString ref_name;
00083     QRect rect;
00084 };
00085 
00086 class Plugin
00087 {
00088  public:
00089   Plugin() {}
00090   virtual ~Plugin() {}
00091   virtual QDomElement saveXML( QDomDocument & doc ) const = 0;
00092 };
00093 
00097 class KSPREAD_EXPORT Doc : public KoDocument, public KoZoomHandler
00098 {
00099   Q_OBJECT
00100   Q_PROPERTY( bool getShowRowHeader READ getShowRowHeader )
00101   Q_PROPERTY( bool getShowColHeader READ getShowColHeader )
00102   Q_PROPERTY( double getIndentValue READ getIndentValue WRITE setIndentValue )
00103   Q_PROPERTY( bool getShowMessageError READ getShowMessageError WRITE setShowMessageError)
00104   Q_PROPERTY( bool dontCheckUpperWord READ dontCheckUpperWord WRITE setDontCheckUpperWord)
00105   Q_PROPERTY( bool dontCheckTitleCase READ dontCheckTitleCase WRITE setDontCheckTitleCase)
00106 
00107   Q_PROPERTY( int syntaxVersion READ syntaxVersion )
00108   Q_PROPERTY( bool showVerticalScrollBar READ showVerticalScrollBar WRITE setShowVerticalScrollBar )
00109   Q_PROPERTY( bool showHorizontalScrollBar READ showHorizontalScrollBar WRITE setShowHorizontalScrollBar )
00110   Q_PROPERTY( bool showColumnHeader READ showColumnHeader WRITE setShowColumnHeader )
00111   Q_PROPERTY( bool showRowHeader READ showRowHeader WRITE setShowRowHeader )
00112   Q_PROPERTY( bool showStatusBar READ showStatusBar WRITE setShowStatusBar )
00113   Q_PROPERTY( bool showFormulaBar READ showFormulaBar WRITE setShowFormulaBar )
00114   Q_PROPERTY( bool showTabBar READ showTabBar WRITE setShowTabBar )
00115   Q_PROPERTY( int undoRedoLimit READ undoRedoLimit WRITE setUndoRedoLimit )
00116 
00117 public:
00118 
00122   Doc( QWidget *parentWidget = 0, const char *widgetName = 0, QObject* parent = 0,
00123   const char* name = 0, bool singleViewMode = false );
00124 
00128   ~Doc();
00129 
00133   enum { STYLE_PAGE = 20,
00134          STYLE_COLUMN,
00135          STYLE_ROW,
00136          STYLE_CELL_USER,
00137          STYLE_CELL_AUTO,
00138          STYLE_PAGEMASTER,
00139          STYLE_NUMERIC_NUMBER };
00140 
00144   static QValueList<Doc*> documents();
00145 
00149   virtual QCString mimeType() const { return MIME_TYPE; }
00150 
00151   KLocale *locale () const;
00152   Map *map () const;
00153   StyleManager *styleManager () const;
00154   ValueParser *parser () const;
00155   ValueFormatter *formatter () const;
00156   ValueConverter *converter () const;
00157   ValueCalc *calc () const;
00158 
00163   void addCommand( KCommand* command );
00164 
00165   /*
00166    * Adds an undo object. This is the same as addCommand, except
00167    * that it accepts Undo instance. Once every undo object
00168    * is converted to KCommand, this function will be obsoleted.
00169    */
00170   void addCommand( UndoAction* command );
00171 
00175   void undo();
00176 
00180   void redo();
00181 
00185   void undoLock();
00186 
00190   void undoUnlock();
00191 
00195   bool undoLocked() const;
00196 
00202   KoCommandHistory* commandHistory();
00203 
00209   QString unitName() const;
00210 
00214   int syntaxVersion( ) const;
00215 
00220   void setShowVerticalScrollBar( bool b );
00221 
00225   bool showVerticalScrollBar() const;
00226 
00230   bool getShowVerticalScrollBar() const { return showVerticalScrollBar(); }
00231 
00236   void setShowHorizontalScrollBar( bool b );
00237 
00241   bool showHorizontalScrollBar() const;
00242 
00246   bool getShowHorizontalScrollBar() const { return showHorizontalScrollBar(); }
00247 
00252   void setShowColumnHeader( bool b );
00253 
00257   bool showColumnHeader() const;
00258 
00262   void setShowColHeader( bool b ){ setShowColumnHeader( b ) ; }
00263 
00267   bool getShowColHeader() const { return showColumnHeader(); }
00268 
00273   void setShowRowHeader( bool b );
00274 
00278   bool showRowHeader() const;
00279 
00283   bool getShowRowHeader() const { return showRowHeader(); }
00284 
00288   void setGridColor( const QColor& color );
00289 
00293   QColor gridColor() const;
00294 
00298   void setIndentValue( double val );
00299 
00303   double indentValue() const;
00304 
00308   double getIndentValue() const { return indentValue(); }
00309 
00314   void setShowStatusBar( bool b );
00315 
00319   bool showStatusBar() const;
00320 
00324   bool getShowStatusBar() const { return showStatusBar(); }
00325 
00330   void setShowTabBar( bool b );
00331 
00335   bool showTabBar() const;
00336 
00340   bool getShowTabBar() const { return showTabBar(); }
00341 
00346   void setShowFormulaBar( bool b );
00347 
00351   bool showFormulaBar() const;
00352 
00356   bool getShowFormulaBar() const { return showFormulaBar(); }
00357 
00361   void setShowMessageError( bool b );
00362 
00366   bool showMessageError() const;
00367 
00371   bool getShowMessageError() const{ return showMessageError(); }
00372 
00377   KGlobalSettings::Completion completionMode( )const ;
00378   void setCompletionMode( KGlobalSettings::Completion _complMode);
00379 
00380   KSpread::MoveTo getMoveToValue()const;
00381   void setMoveToValue(KSpread::MoveTo _moveTo) ;
00382 
00386   void setTypeOfCalc( MethodOfCalc _calc);
00387   MethodOfCalc getTypeOfCalc() const;
00388 
00389 
00393   void setKSpellConfig(KSpellConfig _kspell);
00394   KSpellConfig * getKSpellConfig();
00395 
00396   bool dontCheckUpperWord() const;
00397   void setDontCheckUpperWord(bool _b);
00398 
00399   bool dontCheckTitleCase() const;
00400   void setDontCheckTitleCase(bool _b);
00401 
00402   QColor pageBorderColor() const;
00403   void changePageBorderColor( const QColor  & _color);
00404 
00405   virtual bool completeSaving( KoStore* _store );
00406 
00407   virtual QDomDocument saveXML();
00408 
00409   enum SaveFlag { SaveAll, SaveSelected }; // kpresenter and kword have have SavePage too
00410 
00411   bool savingWholeDocument();
00412 
00426   bool saveOasisHelper( KoStore* store, KoXmlWriter* manifestWriter, SaveFlag saveFlag,
00427                         QString* plainText = 0, KoPicture* picture = 0 );
00428 
00429   virtual bool saveOasis( KoStore* store, KoXmlWriter* manifestWriter );
00430   void saveOasisDocumentStyles( KoStore* store, KoGenStyles& mainStyles ) const;
00431   virtual int supportedSpecialFormats() const;
00432 
00433   virtual bool loadXML( QIODevice *, const QDomDocument& doc );
00434   virtual bool loadOasis( const QDomDocument& doc, KoOasisStyles& oasisStyles, const QDomDocument& settings, KoStore* );
00435   virtual bool loadChildren( KoStore* _store );
00436   QDomElement saveAreaName( QDomDocument& doc ) ;
00437     void saveOasisAreaName( KoXmlWriter & xmlWriter );
00438 
00439   void loadAreaName( const QDomElement& element );
00440   void loadOasisAreaName( const QDomElement& element );
00441   void loadOasisCellValidation( const QDomElement&body );
00442 
00443   virtual void addView( KoView *_view );
00444 
00445   virtual bool initDoc(InitDocFlags flags, QWidget* parentWidget=0);
00446 
00454   virtual void setZoomAndResolution( int zoom, int dpiX, int dpiY );
00455 
00459   void newZoomAndResolution( bool updateViews, bool forPrint );
00460 
00461   // virtual void printMap( QPainter & _painter );
00462 
00463   void enableUndo( bool _b );
00464   void enableRedo( bool _b );
00465 
00469   bool isLoading() const;
00470 
00475   void doNotPaint(bool status);
00476 
00477   virtual void paintContent( QPainter & painter, const QRect & rect, bool transparent = false,
00478                              double zoomX = 1.0, double zoomY = 1.0 );
00479   void paintContent( QPainter & painter, const QRect & rect, bool transparent,
00480                      Sheet * sheet, bool drawCursor = true );
00481 
00482   bool docData( QString const & xmlTag, QDomElement & data );
00483   void deregisterPlugin( Plugin * plugin );
00484   void registerPlugin( Plugin * plugin );
00485 
00507   void paintCellRegions(QPainter& painter, const QRect &viewRect,
00508                         View* view,
00509                         QValueList<QRect> cellRegions,
00510                         const Sheet* sheet, bool drawCursor);
00511 
00512   virtual DCOPObject* dcopObject();
00513 
00514   void addAreaName(const QRect &_rect,const QString & name,const QString & sheetName);
00515   const QValueList<Reference>  & listArea();
00516   void removeArea( const QString &name);
00517   KCompletion & completion();
00518   void addStringCompletion(const QString & stringCompletion);
00519 
00520   void changeAreaSheetName(const QString & oldName,const QString &sheetName);
00521 
00522 
00523   QRect getRectArea(const QString &  _sheetName);
00524 
00528   void insertObject( EmbeddedObject * obj );
00532   QPtrList<EmbeddedObject>& embeddedObjects();
00533   KoPictureCollection *pictureCollection();
00534 
00535   void initConfig();
00536   void saveConfig();
00537   void refreshLocale();
00538 
00557   void emitBeginOperation(bool waitCursor);
00558 
00562   virtual void emitBeginOperation();
00563 
00569   virtual void emitEndOperation();
00570 
00578   void emitEndOperation( const Region& region );
00579 
00580   bool delayCalculation() const;
00581 
00582 
00583   void updateBorderButton();
00584 
00585   void insertSheet( Sheet * sheet );
00586   void takeSheet( Sheet * sheet );
00587 
00588   // The user-chosen global unit
00589 
00590   static QString getAttribute(const QDomElement &element, const char *attributeName, const QString &defaultValue)
00591   {
00592     return element.attribute( attributeName, defaultValue );
00593   }
00594 
00595   static int getAttribute(const QDomElement &element, const char *attributeName, int defaultValue)
00596   {
00597     QString value;
00598     if ( ( value = element.attribute( attributeName ) ) != QString::null )
00599     return value.toInt();
00600     else
00601     return defaultValue;
00602   }
00603 
00604   static double getAttribute(const QDomElement &element, const char *attributeName, double defaultValue)
00605   {
00606     QString value;
00607       if ( ( value = element.attribute( attributeName ) ) != QString::null )
00608     return value.toDouble();
00609       else
00610     return defaultValue;
00611   }
00612 
00613     void addIgnoreWordAll( const QString & word);
00614     void clearIgnoreWordAll( );
00615     void addIgnoreWordAllList( const QStringList & _lst);
00616     QStringList spellListIgnoreAll() const ;
00617 
00618     void setDisplaySheet(Sheet *_Sheet );
00619     Sheet * displaySheet() const;
00620 
00624     KSPLoadingInfo* loadingInfo() const;
00625 
00629     void deleteLoadingInfo();
00630 
00631   void increaseNumOperation();
00632   void decreaseNumOperation();
00633 
00634   void addDamage( Damage* damage );
00635 
00636 /* Function specific when we load config from file */
00637   void loadConfigFromFile();
00638   bool configLoadFromFile() const;
00639 
00640   // repaint (update) all views
00641   void repaint( const QRect& );
00642   void repaint( EmbeddedObject* );
00643   void repaint( const KoRect& );
00644 
00645   virtual void addShell( KoMainWindow *shell );
00646 
00647   int undoRedoLimit() const;
00648   void setUndoRedoLimit(int _val);
00649 
00650 public slots:
00651 
00652   //void newView(); obsloete (Werner)
00653 
00654   void refreshInterface();
00655 
00656   void flushDamages();
00657 
00658 signals:
00659   // Document signals
00663   void sig_updateView();
00667   void sig_refreshView();
00671   void sig_refreshLocale();
00672 
00673   void sig_addAreaName( const QString & );
00674   void sig_removeAreaName( const QString & );
00675 
00676   void damagesFlushed( const QValueList<Damage*>& damages );
00677 
00678 protected slots:
00679   void commandExecuted();
00680   void documentRestored();
00681 
00682   virtual void openTemplate( const QString& file );
00683   virtual void initEmpty();
00684 
00685 protected:
00686   KoView* createViewInstance( QWidget* parent, const char* name );
00687 
00688   void makeUsedPixmapList();
00689   void insertPixmapKey( KoPictureKey key );
00690 
00694   virtual bool completeLoading( KoStore* );
00695 
00699   virtual bool saveChildren( KoStore* _store );
00700 
00701   class SavedDocParts : public QMap<QString, QDomElement> {};
00702   SavedDocParts m_savedDocParts;
00703 
00704 private:
00705   class Private;
00706   Private* d;
00707 
00708   // don't allow copy or assignment
00709   Doc( const Doc& );
00710   Doc& operator=( const Doc& );
00711 
00712   /* helper functions for painting */
00713 
00718   void paintUpdates();
00719 
00720   void PaintRegion(QPainter& painter, const KoRect &viewRegion,
00721                    View* view, const QRect &paintRegion,
00722                    const Sheet* sheet);
00723 
00724   void loadPaper( QDomElement const & paper );
00725 
00726     void saveOasisSettings( KoXmlWriter &settingsWriter );
00727     void loadOasisSettings( const QDomDocument&settingsDoc );
00728     void loadOasisIgnoreList( const KoOasisSettings& settings );
00729     KSPLoadingInfo *m_loadingInfo;
00730 };
00731 
00732 } // namespace KSpread
00733 
00734 #endif /* KSPREAD_DOC */
KDE Home | KDE Accessibility Home | Description of Access Keys