lib

KoDocument.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 Copyright (C) 2000-2005 David Faure <faure@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#ifndef __ko_document_h__
22#define __ko_document_h__
23
24class KoTextDocument;
25namespace std { }
26using namespace std;
27#include <tqwmatrix.h>
28
29#include <tdeparts/part.h>
30#include <kurl.h>
31#include <kservice.h>
32#include <KoGlobal.h>
33#include <KoUnit.h>
34#include <KoPageLayout.h>
35#include <koffice_export.h>
36
37class TQDomElement;
38class TQDomDocument;
39class TQXmlSimpleReader;
40
41class KoStore;
42class KoMainWindow;
43
44class KoChild;
45class KoDocumentChild;
46class KoView;
47class KoDocumentInfo;
48class DCOPObject;
49class KoOasisStyles;
50class KoXmlWriter;
51class KoOpenPane;
52
60class KOFFICECORE_EXPORT KoDocument : public KParts::ReadWritePart
61{
62 TQ_OBJECT
63
64 TQ_PROPERTY( TQCString dcopObjectId READ dcopObjectId)
65 TQ_PROPERTY( bool backupFile READ backupFile WRITE setBackupFile )
66
67public:
68
88 KoDocument( TQWidget* parentWidget,
89 const char* widgetName,
90 TQObject* parent,
91 const char* name,
92 bool singleViewMode = false );
93
100 virtual ~KoDocument();
101
106 bool isSingleViewMode() const;
107
111 bool isEmbedded() const;
112
128 virtual TDEAction *action( const TQDomElement &element ) const;
129
134 virtual TQDomDocument domDocument() const;
135
139 virtual void setManager( KParts::PartManager *manager );
140
145 virtual bool openURL( const KURL & url );
146
157 bool import( const KURL &url );
158
169 bool exp0rt( const KURL &url );
170
178 virtual void setReadWrite( bool readwrite = true );
179
190 static TQCString readNativeFormatMimeType( TDEInstance *instance = 0 );
191
202 static TQStringList readExtraNativeMimeTypes( TDEInstance *instance = 0 );
203
209 static KService::Ptr readNativeService( TDEInstance *instance = 0 );
210
214 static void setupXmlReader( TQXmlSimpleReader& reader, bool namespaceProcessing = false );
215
223 virtual TQCString nativeFormatMimeType() const;
224
229 TQCString nativeOasisMimeType() const;
230
232 bool isNativeFormat( const TQCString& mimetype ) const;
233
236 virtual TQStringList extraNativeMimeTypes() const;
237
239 enum { /*SaveAsKOffice1dot1 = 1,*/ // old and removed
240 SaveAsDirectoryStore = 2,
241 SaveAsFlatXML = 4
242 // bitfield! next value is 8
243 };
244
249 virtual int supportedSpecialFormats() const;
250
254 TQCString mimeType() const;
255
262 void setMimeType( const TQCString & mimeType );
263
273 void setOutputMimeType( const TQCString & mimeType, int specialOutputFlag = 0 );
274 TQCString outputMimeType() const;
275 int specialOutputFlag() const;
276
290 bool confirmNonNativeSave( const bool exporting ) const;
291 void setConfirmNonNativeSave( const bool exporting, const bool on );
292
293 virtual bool wantExportConfirmation() const;
294
301 void setErrorMessage( const TQString& errMsg );
302
308 TQString errorMessage() const;
309
317
326
330 KoView *createView( TQWidget *parent = 0, const char *name = 0 );
331
338 virtual void addView( KoView *view );
339
343 virtual void removeView( KoView *view );
344
348 const TQPtrList<KoView> & views() const;
349
353 int viewCount() const;
354
358 virtual KParts::Part *hitTest( TQWidget *widget, const TQPoint &globalPos );
359
375 virtual KoDocument *hitTest( const TQPoint &pos, const TQWMatrix& matrix = TQWMatrix() );
380
391 virtual void paintEverything( TQPainter &painter, const TQRect &rect, bool transparent = false,
392 KoView *view = 0L, double zoomX = 1.0, double zoomY = 1.0 );
393
398 virtual TQPixmap generatePreview( const TQSize& size );
399
411 virtual void paintChildren( TQPainter &painter, const TQRect &rect, KoView *view, double zoomX = 1.0, double zoomY = 1.0 );
412
424 virtual void paintChild( KoDocumentChild *child, TQPainter &painter, KoView *view,
425 double zoomX = 1.0, double zoomY = 1.0 );
426
440 virtual void paintContent( TQPainter &painter, const TQRect &rect, bool transparent = false,
441 double zoomX = 1.0, double zoomY = 1.0 ) = 0;
442
446 bool checkAutoSaveFile();
447
455 enum InitDocFlags { InitDocAppStarting, InitDocFileNew, InitDocFileClose, InitDocEmbedded, InitDocEmpty };
456
463 virtual bool initDoc(InitDocFlags flags, TQWidget* parentWidget=0) = 0;
464
471 virtual void showStartUpWidget(KoMainWindow* parent, bool alwaysShow = false);
472
477 virtual void setModified( bool _mod );
478
484 virtual void setTitleModified();
485
489 virtual bool isEmpty() const { return m_bEmpty; }
490
499 virtual void setEmpty() { m_bEmpty = true; }
500
509 virtual bool loadFromStore( KoStore* store, const TQString& url );
510
515 virtual bool loadOasisFromStore( KoStore* store );
516
522 virtual bool saveToStore( KoStore* store, const TQString& path );
523
532 virtual bool loadXML( TQIODevice *, const TQDomDocument & doc ) = 0;
533
540 virtual bool loadOasis( const TQDomDocument & doc, KoOasisStyles& oasisStyles,
541 const TQDomDocument & settings, KoStore* store ) = 0;
542
547 virtual bool saveOasis( KoStore* store, KoXmlWriter* manifestWriter ) = 0;
548
553 virtual TQDomDocument saveXML();
554
562 TQDomDocument createDomDocument( const TQString& tagName, const TQString& version ) const;
563
581 static KoXmlWriter* createOasisXmlWriter( TQIODevice* dev, const char* rootElementName );
582
591 static TQDomDocument createDomDocument( const TQString& appName, const TQString& tagName, const TQString& version );
592
599 static TQString tagNameToDocumentType( const TQString& localName );
600
606 virtual bool saveToStream( TQIODevice * dev );
607
614 virtual bool loadNativeFormat( const TQString & file );
615
621 virtual bool saveNativeFormat( const TQString & file );
622
627 void setAutoSave( int delay );
628
632 bool isAutosaving() const;
633
639 void setCheckAutoSaveFile( bool b );
640
646 void setAutoErrorHandlingEnabled( bool b );
647
652 bool isAutoErrorHandlingEnabled() const;
653
658 static int defaultAutoSave() { return s_defaultAutoSave; }
659
664 const TQPtrList<KoDocumentChild>& children() const;
665
673 KoDocumentChild *child( KoDocument *doc );
674
679 KoDocumentInfo *documentInfo() const;
680
681 void setViewBuildDocument( KoView *view, const TQDomDocument &doc );
682 TQDomDocument viewBuildDocument( KoView *view );
683
691 virtual void addShell( KoMainWindow *shell );
692
697 virtual void removeShell( KoMainWindow *shell );
698
702 const TQPtrList<KoMainWindow>& shells() const;
703
707 int shellCount() const;
708
712 static TQPtrList<KoDocument> *documentList() { return s_documentList; }
713
720 virtual DCOPObject * dcopObject();
721
725 TQCString dcopObjectId() const;
726
730 void emitProgress( int value ) { emit sigProgress( value ); }
731
732 bool isInOperation() const;
733 virtual void emitBeginOperation();
734 virtual void emitEndOperation();
735
740 virtual bool isStoredExtern() const;
741
748 virtual KoPageLayout pageLayout(int pageNumber = 0) const;
749
753 void removeAutoSaveFiles();
754
755 void setBackupFile( bool _b );
756
757 bool backupFile()const;
758
762 bool isModified() const;
763
767 bool isLoading() const;
768
769 int queryCloseExternalChildren();
770 int queryCloseDia();
771
785 void setDoNotSaveExtDoc( bool on = true );
786
790 void setBackupPath( const TQString & _path );
791
795 TQString backupPath()const;
796
802 void setCurrent( bool on = true );
803
807 void forceCurrent( bool on );
808 bool isCurrent() const;
809
810 void setTitleModified( const TQString caption, bool mod );
811
818 void resetURL() { m_url = KURL(); m_file = TQString(); }
819
823 void setStoreInternal( bool i );
824
828 bool storeInternal() const;
829
830 bool hasExternURL() const;
831
836 void setURL( const KURL& url ) { m_url = url; }
837
846 TQString &file() { return m_file; }
847
856 void setFile( const TQString &file ) { m_file = file; }
857
861 void setMimeTypeAfterLoading( const TQString& mimeType );
862
866 virtual int pageCount() const { return 1; }
867
873 virtual TQValueList<KoTextDocument *> allTextDocuments() const;
874
879 KoUnit::Unit unit() const;
880
885 void setUnit( KoUnit::Unit u );
886
893 TQString unitName() const;
894
900 void setTemplateType(const TQString& _templateType);
906 TQString templateType() const;
907
913 virtual bool showEmbedInitDialog(TQWidget* parent);
914
915public slots:
920 virtual void initEmpty();
921
922signals:
923
930
940
946 void sigProgress( int value );
947
952 void sigStatusBarMessage( const TQString& text );
953
959
960 void sigBeginOperation();
961 void sigEndOperation();
962
966 void modified( bool );
967
968 void closeEmbedInitDialog();
969
970protected slots:
976 virtual void openExistingFile( const TQString& file );
982 virtual void openTemplate( const TQString& file );
983
984 void deleteOpenPaneDelayed();
985
986protected:
987
988 TQString autoSaveFile( const TQString & path ) const;
989
990 virtual KoView *createViewInstance( TQWidget *parent, const char *name ) = 0;
991
1000 virtual bool openFile();
1001
1008 virtual bool saveFile();
1009
1020 virtual TQWidget* createCustomDocumentWidget(TQWidget *parent);
1021
1042 virtual bool loadChildren( KoStore* );
1043
1049 virtual bool saveChildren( KoStore* store );
1050
1057 virtual bool saveChildrenOasis( KoStore* store, KoXmlWriter* manifestWriter );
1058
1064 virtual bool completeLoading( KoStore* store );
1065
1076 virtual bool completeSaving( KoStore* store );
1077
1089 virtual void insertChild( KoDocumentChild *child );
1090
1093
1095 virtual void insertChild(TQObject *o) { TQObject::insertChild(o); }
1096
1097 KoPageLayout m_pageLayout;
1098
1104 virtual bool saveExternalChildren();
1105
1111 bool isImporting() const;
1112
1120 bool isExporting() const;
1121
1129 KoOpenPane* createOpenPane( TQWidget* parent, TDEInstance* instance,
1130 const TQString& templateType = TQString());
1131
1132private slots:
1133 void slotChildChanged( KoChild *c );
1134 void slotChildDestroyed();
1135 void slotAutoSave();
1136 void slotStarted( TDEIO::Job* );
1137 void startCustomDocument();
1142 void deleteOpenPane();
1143
1144private:
1145 KService::Ptr nativeService();
1146 bool oldLoadAndParse( KoStore* store, const TQString& filename, TQDomDocument& doc );
1147 bool loadNativeFormatFromStore( const TQString& file );
1148 bool savePreview( KoStore* store );
1149 bool saveOasisPreview( KoStore* store, KoXmlWriter* manifestWriter );
1150 class Private;
1151 Private *d;
1152 KService::Ptr m_nativeService;
1153 bool m_bEmpty;
1154 static TQPtrList<KoDocument> *s_documentList;
1155 static const int s_defaultAutoSave;
1156};
1157
1158#endif
virtual TQWidget * widget()
PartManager * manager() const
virtual Part * hitTest(TQWidget *widget, const TQPoint &globalPos)
virtual bool openURL(const KURL &url)
virtual bool openFile()=0
virtual void setReadWrite(bool readwrite=true)
virtual bool saveFile()=0
bool isModified() const
virtual void setModified()
virtual TDEInstance * instance() const
TDEAction * action(const char *name) const
virtual TQDomDocument domDocument() const
KoChild is an abstract base class that represents the geometry associated with an embedded document.
Definition KoChild.h:42
Holds an embedded object.
The KOffice document class.
Definition KoDocument.h:61
KoDocument(TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, bool singleViewMode=false)
Constructor.
virtual void openTemplate(const TQString &file)
This slot loads a template and deletes the start up widget.
static TQString tagNameToDocumentType(const TQString &localName)
The first thing to do in loadOasis is get hold of the office:body tag, then its child.
void resetURL()
Sets the document URL to empty URL KParts doesn't allow this, but KOffice apps have e....
Definition KoDocument.h:818
KoView * hitTestView()
Temporary API for accessing the view that calls hitTest.
virtual bool saveToStream(TQIODevice *dev)
Save the document.
virtual TQDomDocument saveXML()
Reimplement this to save the contents of the KOffice document into a TQDomDocument.
bool isAutoErrorHandlingEnabled() const
Checks whether error message boxes should be shown.
virtual int supportedSpecialFormats() const
Return the set of SupportedSpecialFormats that the application wants to offer in the "Save" file dial...
virtual TQWidget * createCustomDocumentWidget(TQWidget *parent)
Override this method in your derived class to show a widget in the startup 'dialog'.
virtual bool loadOasis(const TQDomDocument &doc, KoOasisStyles &oasisStyles, const TQDomDocument &settings, KoStore *store)=0
Reimplement this method to load the contents of your KOffice document, from the XML document ("conten...
virtual bool loadNativeFormat(const TQString &file)
Loads a document in the native format from a given URL.
bool checkAutoSaveFile()
Called by koApplication to check for an autosave file in $HOME.
TQString errorMessage() const
Return the last error message.
virtual bool completeLoading(KoStore *store)
Overload this function if you have to load additional files from a store.
virtual void paintChildren(TQPainter &painter, const TQRect &rect, KoView *view, double zoomX=1.0, double zoomY=1.0)
Paints all of the documents children into the given painter object.
KoDocumentChild * child(KoDocument *doc)
KoView * createView(TQWidget *parent=0, const char *name=0)
Create a new view for the document.
void setMimeType(const TQCString &mimeType)
Sets the mime type for the document.
static TQCString readNativeFormatMimeType(TDEInstance *instance=0)
Used by KoApplication, and by KoMainWindow, when no document exists yet.
void setAutoErrorHandlingEnabled(bool b)
Set whether the next openURL call should show error message boxes in case of errors.
virtual TQStringList extraNativeMimeTypes() const
Returns a list of the mimetypes considered "native", i.e.
virtual bool saveChildren(KoStore *store)
Saves all internal children (only!).
bool isNativeFormat(const TQCString &mimetype) const
Checks whether a given mimetype can be handled natively.
virtual bool loadChildren(KoStore *)
OLD XML method.
TQString & file()
Only use these functions to restore m_file (in KoMainWindow) after a failed save (remember to use set...
Definition KoDocument.h:846
static TQStringList readExtraNativeMimeTypes(TDEInstance *instance=0)
Used by KoMainWindow, when no document exists yet.
static TQPtrList< KoDocument > * documentList()
Definition KoDocument.h:712
virtual bool saveOasis(KoStore *store, KoXmlWriter *manifestWriter)=0
Reimplement this method to save the contents of your KOffice document, using the OASIS format.
virtual void setEmpty()
Sets the document to empty.
Definition KoDocument.h:499
void showSavingErrorDialog()
Show the last error message in a message box.
void sigStatusBarMessage(const TQString &text)
Emitted e.g.
void unitChanged(KoUnit::Unit)
This signal is emitted when the unit is changed by setUnit() It is common to connect views to it,...
TQCString mimeType() const
Returns the actual mimetype of the document.
virtual bool initDoc(InitDocFlags flags, TQWidget *parentWidget=0)=0
Initializes an empty document (display the template dialog!).
virtual TQPixmap generatePreview(const TQSize &size)
Generates a preview picture of the document.
void emitProgress(int value)
Signal the progress of operations such as loading or saving.
Definition KoDocument.h:730
static void setupXmlReader(TQXmlSimpleReader &reader, bool namespaceProcessing=false)
setup the XML reader, so that we don't have to duplicate the code.
void sigClearStatusBarMessage()
Emitted e.g.
bool isEmbedded() const
Is the document embedded?
TQCString nativeOasisMimeType() const
Returns the OASIS OpenDocument mimetype of the document, if supported This comes from the X-TDE-Nativ...
void modified(bool)
Emitted when the document is modified.
virtual bool saveNativeFormat(const TQString &file)
Saves the document in native format, to a given file You should never have to reimplement.
virtual void addView(KoView *view)
Adds a view to the document.
InitDocFlags
This setting indicates who is calling initDoc.
Definition KoDocument.h:455
virtual int pageCount() const
Definition KoDocument.h:866
void childChanged(KoDocumentChild *child)
This signal is emitted when a direct or indirect child document changes and needs to be updated in al...
bool isSingleViewMode() const
Tells whether this document is in singleview mode.
void setErrorMessage(const TQString &errMsg)
Sets the error message to be shown to the user (use i18n()!) when loading or saving fails.
TQDomDocument createDomDocument(const TQString &tagName, const TQString &version) const
Return a correctly created TQDomDocument for this KoDocument, including processing instruction,...
virtual void paintChild(KoDocumentChild *child, TQPainter &painter, KoView *view, double zoomX=1.0, double zoomY=1.0)
Paint a given child.
bool confirmNonNativeSave(const bool exporting) const
Returns true if this document was the result of opening a foreign file format and if the user hasn't ...
void sigProgress(int value)
Progress info while loading or saving.
TQCString dcopObjectId() const
virtual void paintContent(TQPainter &painter, const TQRect &rect, bool transparent=false, double zoomX=1.0, double zoomY=1.0)=0
Paints the data itself.
virtual bool completeSaving(KoStore *store)
If you want to write additional files to a store, then you must do it here.
int viewCount() const
void setCheckAutoSaveFile(bool b)
Set whether the next openURL call should check for an auto-saved file and offer to open it.
virtual void removeView(KoView *view)
Removes a view of the document.
static int defaultAutoSave()
Retrieve the default value for autosave in seconds.
Definition KoDocument.h:658
virtual void insertChild(KoDocumentChild *child)
Inserts the new child in the list of children and emits the childChanged() signal.
void setAutoSave(int delay)
Activate/deactivate/configure the autosave feature.
virtual TQCString nativeFormatMimeType() const
To be preferred when a document exists.
virtual bool loadXML(TQIODevice *, const TQDomDocument &doc)=0
Reimplement this method to load the contents of your KOffice document, from the XML document.
bool exp0rt(const KURL &url)
Saves the document as url without changing the state of the KoDocument (URL, modified flag etc....
void setURL(const KURL &url)
Sets the document URL to url KParts doesn't really allow this, but it is needed for undo of setStoreI...
Definition KoDocument.h:836
void setOutputMimeType(const TQCString &mimeType, int specialOutputFlag=0)
Set the format in which the document should be saved.
virtual void paintEverything(TQPainter &painter, const TQRect &rect, bool transparent=false, KoView *view=0L, double zoomX=1.0, double zoomY=1.0)
Paints the whole document into the given painter object.
bool isAutosaving() const
Checks whether the document is currently in the process of autosaving.
const TQPtrList< KoView > & views() const
static KService::Ptr readNativeService(TDEInstance *instance=0)
With the help of instance or TDEApplication::instance() this method figures out which ....
virtual void showStartUpWidget(KoMainWindow *parent, bool alwaysShow=false)
Creates and shows the start up widget.
virtual bool isEmpty() const
Definition KoDocument.h:489
void setFile(const TQString &file)
Only use these functions to restore m_file (in KoMainWindow) after a failed save (remember to use set...
Definition KoDocument.h:856
virtual bool saveChildrenOasis(KoStore *store, KoXmlWriter *manifestWriter)
Saves all internal children (only!), to the store, using the OASIS format.
virtual void setTitleModified()
Tells the document that its title has been modified, either because the modified status changes (this...
static KoXmlWriter * createOasisXmlWriter(TQIODevice *dev, const char *rootElementName)
Return an XML writer for saving Oasis XML into the device dev, including the XML processing instructi...
void showLoadingErrorDialog()
Show the last error message in a message box.
virtual void openExistingFile(const TQString &file)
This slot loads an existing file and deletes the start up widget.
Main window for a KOffice application.
Repository of styles used during loading of OASIS/OOo file.
Saves and loads KOffice documents using various backends.
Definition KoStore.h:40
Unit
Length units supported by KOffice.
Definition KoUnit.h:63
This class is used to display a KoDocument.
Definition KoView.h:58
A class for writing out XML (to any TQIODevice), with a special attention on performance.
Definition KoXmlWriter.h:37
This structure defines the page layout, including its size in pt, its format (e.g.