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 
00471   virtual void paintContent( QPainter & painter, const QRect & rect, bool transparent = false,
00472                              double zoomX = 1.0, double zoomY = 1.0 );
00473   void paintContent( QPainter & painter, const QRect & rect, bool transparent,
00474                      Sheet * sheet, bool drawCursor = true );
00475 
00476   bool docData( QString const & xmlTag, QDomElement & data );
00477   void deregisterPlugin( Plugin * plugin );
00478   void registerPlugin( Plugin * plugin );
00479 
00501   void paintCellRegions(QPainter& painter, const QRect &viewRect,
00502                         View* view,
00503                         QValueList<QRect> cellRegions,
00504                         const Sheet* sheet, bool drawCursor);
00505 
00506   virtual DCOPObject* dcopObject();
00507 
00508   void addAreaName(const QRect &_rect,const QString & name,const QString & sheetName);
00509   const QValueList<Reference>  & listArea();
00510   void removeArea( const QString &name);
00511   KCompletion & completion();
00512   void addStringCompletion(const QString & stringCompletion);
00513 
00514   void changeAreaSheetName(const QString & oldName,const QString &sheetName);
00515 
00516 
00517   QRect getRectArea(const QString &  _sheetName);
00518 
00522   void insertObject( EmbeddedObject * obj );
00526   QPtrList<EmbeddedObject>& embeddedObjects();
00527   KoPictureCollection *pictureCollection();
00528 
00529   void initConfig();
00530   void saveConfig();
00531   void refreshLocale();
00532 
00551   void emitBeginOperation(bool waitCursor);
00552 
00556   virtual void emitBeginOperation();
00557 
00563   virtual void emitEndOperation();
00564 
00572   void emitEndOperation( const Region& region );
00573 
00574   bool delayCalculation() const;
00575 
00576 
00577   void updateBorderButton();
00578 
00579   void insertSheet( Sheet * sheet );
00580   void takeSheet( Sheet * sheet );
00581 
00582   // The user-chosen global unit
00583 
00584   static QString getAttribute(const QDomElement &element, const char *attributeName, const QString &defaultValue)
00585   {
00586     return element.attribute( attributeName, defaultValue );
00587   }
00588 
00589   static int getAttribute(const QDomElement &element, const char *attributeName, int defaultValue)
00590   {
00591     QString value;
00592     if ( ( value = element.attribute( attributeName ) ) != QString::null )
00593     return value.toInt();
00594     else
00595     return defaultValue;
00596   }
00597 
00598   static double getAttribute(const QDomElement &element, const char *attributeName, double defaultValue)
00599   {
00600     QString value;
00601       if ( ( value = element.attribute( attributeName ) ) != QString::null )
00602     return value.toDouble();
00603       else
00604     return defaultValue;
00605   }
00606 
00607     void addIgnoreWordAll( const QString & word);
00608     void clearIgnoreWordAll( );
00609     void addIgnoreWordAllList( const QStringList & _lst);
00610     QStringList spellListIgnoreAll() const ;
00611 
00612     void setDisplaySheet(Sheet *_Sheet );
00613     Sheet * displaySheet() const;
00614     KSPLoadingInfo * loadingInfo() const;
00615   void increaseNumOperation();
00616   void decreaseNumOperation();
00617 
00618   void addDamage( Damage* damage );
00619 
00620 /* Function specific when we load config from file */
00621   void loadConfigFromFile();
00622   bool configLoadFromFile() const;
00623 
00624   // repaint (update) all views
00625   void repaint( const QRect& );
00626   void repaint( EmbeddedObject* );
00627   void repaint( const KoRect& );
00628 
00629   virtual void addShell( KoMainWindow *shell );
00630 
00631   int undoRedoLimit() const;
00632   void setUndoRedoLimit(int _val);
00633 
00634 public slots:
00635 
00636   //void newView(); obsloete (Werner)
00637 
00638   void refreshInterface();
00639 
00640   void flushDamages();
00641 
00642 signals:
00643   // Document signals
00647   void sig_updateView();
00651   void sig_refreshView();
00655   void sig_refreshLocale();
00656 
00657   void sig_addAreaName( const QString & );
00658   void sig_removeAreaName( const QString & );
00659 
00660   void damagesFlushed( const QValueList<Damage*>& damages );
00661 
00662 protected slots:
00663   void commandExecuted();
00664   void documentRestored();
00665 
00666   virtual void openTemplate( const QString& file );
00667   virtual void initEmpty();
00668 
00669 protected:
00670   KoView* createViewInstance( QWidget* parent, const char* name );
00671 
00672   void makeUsedPixmapList();
00673   void insertPixmapKey( KoPictureKey key );
00674 
00678   virtual bool completeLoading( KoStore* );
00679 
00683   virtual bool saveChildren( KoStore* _store );
00684 
00685   class SavedDocParts : public QMap<QString, QDomElement> {};
00686   SavedDocParts m_savedDocParts;
00687 
00688 private:
00689   class Private;
00690   Private* d;
00691 
00692   // don't allow copy or assignment
00693   Doc( const Doc& );
00694   Doc& operator=( const Doc& );
00695 
00696   /* helper functions for painting */
00697 
00702   void paintUpdates();
00703 
00704   void PaintRegion(QPainter& painter, const KoRect &viewRegion,
00705                    View* view, const QRect &paintRegion,
00706                    const Sheet* sheet);
00707 
00708   void loadPaper( QDomElement const & paper );
00709 
00710     void saveOasisSettings( KoXmlWriter &settingsWriter );
00711     void loadOasisSettings( const QDomDocument&settingsDoc );
00712     void loadOasisIgnoreList( const KoOasisSettings& settings );
00713     KSPLoadingInfo *m_loadingInfo;
00714 };
00715 
00716 } // namespace KSpread
00717 
00718 #endif /* KSPREAD_DOC */
KDE Home | KDE Accessibility Home | Description of Access Keys