documentmanager.h
来自「这是VCF框架的代码」· C头文件 代码 · 共 2,046 行 · 第 1/5 页
H
2,046 行
return NULL; } /** *there is an internal association map between a mimeType and the DocumentInfo *this function adds an item to this map. *@param const String&, the mime type. *@param const DocumentInfo& info, the DocumentInfo. */ void addDocumentInfo( const VCF::String& mimeType, const DocumentInfo& info ); /** * gets a pointer to the enumerator of all the registered DocumentInfo(s). *@param Enumerator<DocumentInfo>*, the pointer to this enumerator. */ Enumerator<DocumentInfo>* getRegisteredDocumentInfo(); /** * gets the DocumentInfo of a document from its mime type only. *@param const String&, the mime type. *@return DocumentInfo, the document infos. */ DocumentInfo getDocumentInfo( const String& mimeType ); /** * gets the mime type of a document from the extension of its associated file. *@param const String&, the filename. *@return String, the mime type. */ String getMimeTypeFromFileExtension( const String& fileName ); /** * sets a specified view for a specified new document. * In this default implementation the window, previously 'assigned' * to the document, becomes the view itself. * The DocumentInfo is also specified because in alternative * implementations we may need to decide to select which view * will be associated to the document: the window could be the view * itself or the control hosting the view instead. *@param DocumentInfo& info, the DocumentInfo. *@param View* view, the specified view. *@param Window* window, the window. *@param Document* newDocument, the new document. */ virtual void setNewView( const DocumentInfo& info, View* view, Window* window, Document* newDocument ) { view->setViewControl( window ); window->setView( view ); newDocument->addView( window ); } /** * preferences support. * performs any editing operation on the application's preferences. * The basic functionality is empty. Override this to implement one. */ virtual void editPreferences(){ }; /** * tells if our Document manager is expected to have (create) a User Interface. *@return bool, true if it does. */ bool getShouldCreateUI() { return shouldCreateUI_; } /** * states if our Document manager should create a User Interface. *@param bool, true if we want to have it. */ void setShouldCreateUI( bool val ) { shouldCreateUI_ = val; } /** * attaches a document specific User Interface to a document. * using the appropriate DocumentInfo extracted from the mimeType. * The basic functionality is empty. The real implementation is dependent on the policy. */ virtual void attachUIToDocument( const String& mimeType, Document* document ) { }; /** * gets a pointer to an enumerator of all the opened documents in the application. *@return Enumerator<Document*>* , the pointer to this enumerator. */ Enumerator<Document*>* getOpenedDocuments(); /** * creates the menus associated to our document based application. * The basic functionality is empty. The real implementation is dependent on the policy. */ virtual void createMenus(){ }; /** * initializes the menu for the window associated to a document. * The DocumentInfo is also specified. * The basic functionality is empty. The real implementation is dependent on the policy. *@param DocumentInfo& info, the DocumentInfo. *@param Window* window, the window. *@param Document* document, the document. */ virtual void initializeWindowMenus( Window* window, Document* document, const DocumentInfo& info ) { } /** * gets the action associated to an action tag, as specified by this document manager. *@param ActionTag, the action's tag. *@return Action*, the pointer to the associated action. *@see Action */ Action* getAction( ulong32 tag ); /** * performs a cut operation on the document, * if the document allows for it. *@param Document* doc, the document. */ virtual void cutFromDocument( Document* doc ); /** * performs a copy operation on the document, * if the document allows for it. *@param Document* doc, the document. */ virtual void copyFromDocument( Document* doc ); /** * performs a paste operation on the document, * if the document allows for it. *@param Document* doc, the document. */ virtual void pasteToDocument( Document* doc ); /** * performs an undo operation on the document. *@param Document* doc, the document. */ virtual void undoForDocument( Document* doc ); /** * performs a redo operation on the document. *@param Document* doc, the document. */ virtual void redoForDocument( Document* doc ); /** performs an undo operation using the shared undo-redo stack */ void undo(); /** performs a redo operation using the shared undo-redo stack */ void redo(); /** * gets the undo-redo stack associated with a document. *@param Document* doc, the document. If this is NULL then the function returns the default undo-redo stack, that is "global" and not specific to a particular document. *@return UndoRedoStack&, a reference to the document's stack. */ UndoRedoStack& getUndoRedoStack( Document* doc ); /** Returns the shared undo-redo stack for the document manager. @return UndoRedoStack&, a reference to the document's stack. @see getUndoRedoStack() */ UndoRedoStack& getSharedUndoRedoStack() { return getUndoRedoStack( NULL ); }protected: /** * gives the document info associated to the document * this implementation uses the VCF RTTI for this document. */ DocumentInfo* getDocumentInfo( Document* doc ); /** called to prepare a file open dialog */ virtual void prepareOpenDialog( CommonFileOpenDialog* openDialog ); /** called after the file open dialog has been closed by the user and confirmed Ok */ virtual void openDialogFinished( CommonFileOpenDialog* openDialog ){}; /** called to prepare a file save dialog */ virtual void prepareSaveDialog( CommonFileSaveDialog* saveDialog, Document* doc ); /** called after the file save dialog has been closed by the user and confirmed Ok */ virtual void saveDialogFinished( CommonFileSaveDialog* saveDialog ){}; /** called when this target gets notified for update events of the UI of a save operation */ virtual void updateSave( ActionEvent* event, Document* doc ); /** called when this target gets notified for update events of the UI of a saveAs operation */ virtual void updateSaveAs( ActionEvent* event, Document* doc ); /** called when this target gets notified for update events of the UI of a close operation */ virtual void updateClose( ActionEvent* event, Document* doc ); /** called when this target gets notified for update events of the UI of a cut operation */ virtual void updateCut( ActionEvent* event, Document* doc ); /** called when this target gets notified for update events of the UI of a copy operation */ virtual void updateCopy( ActionEvent* event, Document* doc ); /** called when this target gets notified for update events of the UI of a paste operation */ virtual void updatePaste( ActionEvent* event, Document* doc ); /** called when this target gets notified for update events of the UI of a undo operation */ virtual void updateUndo( ActionEvent* event, Document* doc ); /** called when this target gets notified for update events of the UI of a redo operation */ virtual void updateRedo( ActionEvent* event, Document* doc ); /** removes the undo redo stack from the specified document */ void removeUndoRedoStackForDocument( Document* doc ); /** called to save the changes done on a specified document */ virtual UIToolkit::ModalReturnType saveChanges( Document* document ); /** add an action to the internal action map */ void addAction( ulong32 tag, Action* action ); /** called to add a document to the document based application */ void addDocument( Document* document ); /** called to remove a document from the document based application */ void removeDocument( Document* document ); typedef std::map<String,DocumentInfo> DocumentInfoMap; typedef std::map<Document*,UndoRedoStack*> DocumentUndoRedoMap; typedef std::map< ulong32, Action* > ActionMap; /** the only document manager instance for the application */ static DocumentManager* docManagerInstance; /** The map of all registered DocumentInfo(s) */ DocumentInfoMap docInfo_; EnumeratorMapContainer< DocumentInfoMap, DocumentInfo > docInfoContainer_; /** The list of all the opened document at this moment */ std::vector<Document*> openDocuments_; EnumeratorContainer< std::vector<Document*>, Document* > openDocContainer_; /** this DocumentManager has a User Interface */ bool shouldCreateUI_; /** the map of all actions and their associated tags according to our document manager */ ActionMap actionsMap_; /** the map of all undo redo stack associated to each document */ DocumentUndoRedoMap undoRedoStack_;};/**\class DocumentManagerImpl DocumentManager.h "vcf/ApplicationKit/DocumentManager.h"* class DocumentManagerImpl* implementation of the DocumentManager for which also the DocInterfacePolicy* is specified.* The DocInterfacePolicy is the template argument class that specifies* how the DocumentManager is supposed to manage the collection (of one or more) documents.* We can say than DocumentManagerImpl is the part of the DocumentManager * whose member functions are depending on the DocInterfacePolicy chosen by the user.*/template < typename AppClass, typename DocInterfacePolicy >class DocumentManagerImpl : public DocumentManager, public DocInterfacePolicy {public: DocumentManagerImpl(): app_(NULL), closingDocument_(false), documentClosedOK_(false) { } /** * functions overrides with implementation depending on the DocInterfacePolicy. **/ /** * inizialization function for document based applications. * This is called just after Application::initRunningApplication(). */ virtual void init(); /** * gets a pointer to the active document. */ virtual Document* getCurrentDocument() { return DocInterfacePolicy::getCurrentDocument(); } /** * sets the given document as the active one. * Applies the policy's implemenation and send a change notification. */ virtual void setCurrentDocument( Document* newCurrentDocument ) { DocInterfacePolicy::setCurrentDocument(newCurrentDocument); VCF::DocumentManager::getDocumentManager()->currentDocumentChanged(); } /** * save a document into a file. * the standard behaviour is simply save the file if it has been modified, * and to create a backup copy first if the document specifies to keep one. * If there is a problem with the destination directory, the user is prompted * with a dialog in order to specify an alternative location. * If we don't want this base behaviour, an event handler must be implemented * and added to the SaveFile delegate. *@param Document* doc, the document. *@return bool, true if the operation completed successfully. *@fire DocumentManager::SaveFile *@event DocManagerEvent *@eventtype DocumentManager::dmSaveDocument */ virtual bool saveFile( Document* document ); /** * save a document into a file. * the standard behaviour is to show a dialog asking the user which file to open. * The user is prompted with a dialog if the destination filename is not specified * or if its directory does not exists. * If the document is saved, then a ModelChanged event with type Document::deSaved * is fired. * If we don't want this base behaviour, an event handler must be implemented * and added to the SaveFile delegate. *@param Document* doc, the document. *@param const String& newFileName, the new destination filename. By default it is empty * so the user is prompted with a dialog. *@return bool, true if the operation completed successfully. *@fire DocumentManager::SaveFile *@event DocManagerEvent *@eventtype DocumentManager::dmSaveDocument *@fire Model::ModelChanged *@event ModelEvent *@eventtype Document::deSaved */ virtual bool saveFileAs( Document* document, const String& newFileName=String( L"" ) ); /** * opens a file. * the standard behaviour is to show a dialog asking the user which file to open. * If we don't want this base behaviour, an event handler must be implemented * and added to the SaveFile delegate. *@fire DocumentManager::OpenFile *@event DocManagerEvent *@eventtype DocumentManager::dmOpenDocument */ virtual void openFile(); /** * closes the current document, and all its children if they exist * according to the policy. */ virtual void closeCurrentDocument(); /** * reloads a file for an existing document. * If the file is modified, the user is prompted to save it or not. * It the operation fails, the user is warned with a message, * but the document is not closed. *@param Document* doc, the document whose file needs to be reloaded. *@param const bool& keepPosition, true to reopen the file in the same * position as before. The default is true. */ virtual void reloadDocument( Document* document, const bool& keepPosition=true ); /** * just creates the object from its type using the VCF RTTI * The info.classID is used first if available, * otherwise the info.className. */ virtual Document* createDocumentFromType( const DocumentInfo& info ); /** * gets a window to be associated to the document just created. * This implementation just creates the associated window * from its type using the VCF RTTI. * In a SDI policy the new window for the document is the main window. * In a MDI policy the new window for the document is simply a new window.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?