00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __ko_document_h__
00023 #define __ko_document_h__
00024
00025 class KoTextDocument;
00026 namespace std { }
00027 using namespace std;
00028 #include <qwmatrix.h>
00029
00030 #include <kparts/part.h>
00031 #include <kurl.h>
00032 #include <kservice.h>
00033 #include <KoGlobal.h>
00034 #include <KoUnit.h>
00035 #include <KoPageLayout.h>
00036 #include <koffice_export.h>
00037
00038 class QDomElement;
00039 class QDomDocument;
00040 class QXmlSimpleReader;
00041
00042 class KoStore;
00043 class KoMainWindow;
00044
00045 class KoChild;
00046 class KoDocumentChild;
00047 class KoView;
00048 class KoDocumentInfo;
00049 class DCOPObject;
00050 class KoOasisStyles;
00051 class KoXmlWriter;
00052 class KoOpenPane;
00053
00061 class KOFFICECORE_EXPORT KoDocument : public KParts::ReadWritePart
00062 {
00063 Q_OBJECT
00064 Q_PROPERTY( QCString dcopObjectId READ dcopObjectId)
00065 Q_PROPERTY( bool backupFile READ backupFile WRITE setBackupFile )
00066
00067 public:
00068
00088 KoDocument( QWidget* parentWidget,
00089 const char* widgetName,
00090 QObject* parent,
00091 const char* name,
00092 bool singleViewMode = false );
00093
00100 virtual ~KoDocument();
00101
00106 bool isSingleViewMode() const;
00107
00111 bool isEmbedded() const;
00112
00128 virtual KAction *action( const QDomElement &element ) const;
00129
00134 virtual QDomDocument domDocument() const;
00135
00139 virtual void setManager( KParts::PartManager *manager );
00140
00145 virtual bool openURL( const KURL & url );
00146
00157 bool import( const KURL &url );
00158
00169 bool exp0rt( const KURL &url );
00170
00178 virtual void setReadWrite( bool readwrite = true );
00179
00190 static QCString readNativeFormatMimeType( KInstance *instance = 0 );
00191
00202 static QStringList readExtraNativeMimeTypes( KInstance *instance = 0 );
00203
00209 static KService::Ptr readNativeService( KInstance *instance = 0 );
00210
00214 static void setupXmlReader( QXmlSimpleReader& reader, bool namespaceProcessing = false );
00215
00223 virtual QCString nativeFormatMimeType() const;
00224
00229 QCString nativeOasisMimeType() const;
00230
00232 bool isNativeFormat( const QCString& mimetype ) const;
00233
00236 virtual QStringList extraNativeMimeTypes() const;
00237
00239 enum {
00240 SaveAsDirectoryStore = 2,
00241 SaveAsFlatXML = 4
00242
00243 };
00244
00249 virtual int supportedSpecialFormats() const;
00250
00254 QCString mimeType() const;
00255
00262 void setMimeType( const QCString & mimeType );
00263
00273 void setOutputMimeType( const QCString & mimeType, int specialOutputFlag = 0 );
00274 QCString outputMimeType() const;
00275 int specialOutputFlag() const;
00276
00290 bool confirmNonNativeSave( const bool exporting ) const;
00291 void setConfirmNonNativeSave( const bool exporting, const bool on );
00292
00293 virtual bool wantExportConfirmation() const;
00294
00301 void setErrorMessage( const QString& errMsg );
00302
00308 QString errorMessage() const;
00309
00316 void showSavingErrorDialog();
00317
00325 void showLoadingErrorDialog();
00326
00330 KoView *createView( QWidget *parent = 0, const char *name = 0 );
00331
00338 virtual void addView( KoView *view );
00339
00343 virtual void removeView( KoView *view );
00344
00348 const QPtrList<KoView> & views() const;
00349
00353 int viewCount() const;
00354
00358 virtual KParts::Part *hitTest( QWidget *widget, const QPoint &globalPos );
00359
00375 virtual KoDocument *hitTest( const QPoint &pos, const QWMatrix& matrix = QWMatrix() );
00379 KoView* hitTestView();
00380
00391 virtual void paintEverything( QPainter &painter, const QRect &rect, bool transparent = false,
00392 KoView *view = 0L, double zoomX = 1.0, double zoomY = 1.0 );
00393
00398 virtual QPixmap generatePreview( const QSize& size );
00399
00411 virtual void paintChildren( QPainter &painter, const QRect &rect, KoView *view, double zoomX = 1.0, double zoomY = 1.0 );
00412
00424 virtual void paintChild( KoDocumentChild *child, QPainter &painter, KoView *view,
00425 double zoomX = 1.0, double zoomY = 1.0 );
00426
00440 virtual void paintContent( QPainter &painter, const QRect &rect, bool transparent = false,
00441 double zoomX = 1.0, double zoomY = 1.0 ) = 0;
00442
00446 bool checkAutoSaveFile();
00447
00455 enum InitDocFlags { InitDocAppStarting, InitDocFileNew, InitDocFileClose, InitDocEmbedded, InitDocEmpty };
00456
00463 virtual bool initDoc(InitDocFlags flags, QWidget* parentWidget=0) = 0;
00464
00471 virtual void showStartUpWidget(KoMainWindow* parent, bool alwaysShow = false);
00472
00477 virtual void setModified( bool _mod );
00478
00484 virtual void setTitleModified();
00485
00489 virtual bool isEmpty() const { return m_bEmpty; }
00490
00499 virtual void setEmpty() { m_bEmpty = true; }
00500
00509 virtual bool loadFromStore( KoStore* store, const QString& url );
00510
00515 virtual bool loadOasisFromStore( KoStore* store );
00516
00522 virtual bool saveToStore( KoStore* store, const QString& path );
00523
00532 virtual bool loadXML( QIODevice *, const QDomDocument & doc ) = 0;
00533
00540 virtual bool loadOasis( const QDomDocument & doc, KoOasisStyles& oasisStyles,
00541 const QDomDocument & settings, KoStore* store ) = 0;
00542
00547 virtual bool saveOasis( KoStore* store, KoXmlWriter* manifestWriter ) = 0;
00548
00553 virtual QDomDocument saveXML();
00554
00562 QDomDocument createDomDocument( const QString& tagName, const QString& version ) const;
00563
00581 static KoXmlWriter* createOasisXmlWriter( QIODevice* dev, const char* rootElementName );
00582
00591 static QDomDocument createDomDocument( const QString& appName, const QString& tagName, const QString& version );
00592
00599 static QString tagNameToDocumentType( const QString& localName );
00600
00606 virtual bool saveToStream( QIODevice * dev );
00607
00614 virtual bool loadNativeFormat( const QString & file );
00615
00621 virtual bool saveNativeFormat( const QString & file );
00622
00627 void setAutoSave( int delay );
00628
00632 bool isAutosaving() const;
00633
00639 void setCheckAutoSaveFile( bool b );
00640
00646 void setAutoErrorHandlingEnabled( bool b );
00647
00652 bool isAutoErrorHandlingEnabled() const;
00653
00658 static int defaultAutoSave() { return s_defaultAutoSave; }
00659
00664 const QPtrList<KoDocumentChild>& children() const;
00665
00673 KoDocumentChild *child( KoDocument *doc );
00674
00679 KoDocumentInfo *documentInfo() const;
00680
00681 void setViewBuildDocument( KoView *view, const QDomDocument &doc );
00682 QDomDocument viewBuildDocument( KoView *view );
00683
00691 virtual void addShell( KoMainWindow *shell );
00692
00697 virtual void removeShell( KoMainWindow *shell );
00698
00702 const QPtrList<KoMainWindow>& shells() const;
00703
00707 int shellCount() const;
00708
00712 static QPtrList<KoDocument> *documentList() { return s_documentList; }
00713
00720 virtual DCOPObject * dcopObject();
00721
00725 QCString dcopObjectId() const;
00726
00730 void emitProgress( int value ) { emit sigProgress( value ); }
00731
00732 bool isInOperation() const;
00733 virtual void emitBeginOperation();
00734 virtual void emitEndOperation();
00735
00740 virtual bool isStoredExtern() const;
00741
00748 virtual KoPageLayout pageLayout(int pageNumber = 0) const;
00749
00753 void removeAutoSaveFiles();
00754
00755 void setBackupFile( bool _b );
00756
00757 bool backupFile()const;
00758
00762 bool isModified() const;
00763
00767 bool isLoading() const;
00768
00769 int queryCloseExternalChildren();
00770 int queryCloseDia();
00771
00785 void setDoNotSaveExtDoc( bool on = true );
00786
00790 void setBackupPath( const QString & _path );
00791
00795 QString backupPath()const;
00796
00802 void setCurrent( bool on = true );
00803
00807 void forceCurrent( bool on );
00808 bool isCurrent() const;
00809
00810 void setTitleModified( const QString caption, bool mod );
00811
00818 void resetURL() { m_url = KURL(); m_file = QString::null; }
00819
00823 void setStoreInternal( bool i );
00824
00828 bool storeInternal() const;
00829
00830 bool hasExternURL() const;
00831
00836 void setURL( const KURL& url ) { m_url = url; }
00837
00846 QString &file() { return m_file; }
00847
00856 void setFile( const QString &file ) { m_file = file; }
00857
00861 void setMimeTypeAfterLoading( const QString& mimeType );
00862
00866 virtual int pageCount() const { return 1; }
00867
00873 virtual QValueList<KoTextDocument *> allTextDocuments() const;
00874
00879 KoUnit::Unit unit() const;
00880
00885 void setUnit( KoUnit::Unit u );
00886
00893 QString unitName() const;
00894
00900 void setTemplateType(const QString& _templateType);
00906 QString templateType() const;
00907
00913 virtual bool showEmbedInitDialog(QWidget* parent);
00914
00915 public slots:
00920 virtual void initEmpty();
00921
00922 signals:
00923
00929 void unitChanged(KoUnit::Unit);
00930
00939 void childChanged( KoDocumentChild *child );
00940
00946 void sigProgress( int value );
00947
00952 void sigStatusBarMessage( const QString& text );
00953
00958 void sigClearStatusBarMessage();
00959
00960 void sigBeginOperation();
00961 void sigEndOperation();
00962
00966 void modified( bool );
00967
00968 void closeEmbedInitDialog();
00969
00970 protected slots:
00976 virtual void openExistingFile( const QString& file );
00982 virtual void openTemplate( const QString& file );
00983
00984 void deleteOpenPaneDelayed();
00985
00986 protected:
00987
00988 QString autoSaveFile( const QString & path ) const;
00989
00990 virtual KoView *createViewInstance( QWidget *parent, const char *name ) = 0;
00991
01000 virtual bool openFile();
01001
01008 virtual bool saveFile();
01009
01020 virtual QWidget* createCustomDocumentWidget(QWidget *parent);
01021
01042 virtual bool loadChildren( KoStore* );
01043
01049 virtual bool saveChildren( KoStore* store );
01050
01057 virtual bool saveChildrenOasis( KoStore* store, KoXmlWriter* manifestWriter );
01058
01064 virtual bool completeLoading( KoStore* store );
01065
01076 virtual bool completeSaving( KoStore* store );
01077
01089 virtual void insertChild( KoDocumentChild *child );
01090
01092 virtual void setModified() { KParts::ReadWritePart::setModified(); }
01093
01095 virtual void insertChild(QObject *o) { QObject::insertChild(o); }
01096
01097 KoPageLayout m_pageLayout;
01098
01104 virtual bool saveExternalChildren();
01105
01111 bool isImporting() const;
01112
01120 bool isExporting() const;
01121
01129 KoOpenPane* createOpenPane( QWidget* parent, KInstance* instance,
01130 const QString& templateType = QString::null);
01131
01132 private slots:
01133 void slotChildChanged( KoChild *c );
01134 void slotChildDestroyed();
01135 void slotAutoSave();
01136 void slotStarted( KIO::Job* );
01137 void startCustomDocument();
01142 void deleteOpenPane();
01143
01144 private:
01145 KService::Ptr nativeService();
01146 bool oldLoadAndParse( KoStore* store, const QString& filename, QDomDocument& doc );
01147 bool loadNativeFormatFromStore( const QString& file );
01148 bool savePreview( KoStore* store );
01149 bool saveOasisPreview( KoStore* store, KoXmlWriter* manifestWriter );
01150 class Private;
01151 Private *d;
01152 KService::Ptr m_nativeService;
01153 bool m_bEmpty;
01154 static QPtrList<KoDocument> *s_documentList;
01155 static const int s_defaultAutoSave;
01156 };
01157
01158 #endif