documentmanager.h

来自「这是VCF框架的代码」· C头文件 代码 · 共 2,046 行 · 第 1/5 页

H
2,046
字号
	* In an AdvancedMDIPolicy this implementation needs to be overriden.	*/	virtual Window* getWindowForNewDocument( Document* document, const DocumentInfo& info );	/**	* default procedures when creating a new document	* <ul>	*		<li>under SDI it saves the previous document if it was modified.	*		<li>it creates a document instance according to the mimetype.	*		<li>it calls the user implementation of Document::initNew()	*		<li>it attaches a UI to the document if this getShouldCreateUI() is true.	* </ul>	*	* this is normally called before actually opening the file for the document.	*	* In a SDI policy saveBeforeNewDocument() returns true so,	* if we create a new document while the current document has been modified	* the user is asked what to do, and the operation is aborted if the he decides to.	*@fire DocumentInitialized, indirectly if attachUI() is called.	*@see DocInterfacePolicy::saveBeforeNewDocument()	*@see DocumentManagerImpl:: attachUI()	*/	virtual Document* newDefaultDocument( const String& fileName, const String& mimetype=L"" );	/**	* attaches a document specific User Interface to a document	* using the appropriate DocumentInfo extracted from the mimeType.	* In this standard implementation:	*   first it saves the current document if the policy requests this	*   then it does the work of attaching the UI ( by calling attachUI ),	*   finally it notifies the document has been changed.	* The implementation is very similar to newDefaultDocument() with 	* the difference that a document instance is already given.	*@fire DocumentInitialized, indirectly if attachUI() is called.	*@fire Document::ModelChanged	*@event ModelEvent	*@eventtype Document::deOpened	*/	virtual void attachUIToDocument( const String& mimeType, Document* document );	/**	* creates the standard menu for a document based application	* and adds them as target to the appropriate action instances.	* The menu follows a standard for all the OS.	*/	virtual void createMenus();	/**	* initializes the menu for the window associated to a document.	* The DocumentInfo is also specified.	* Initializes the appropriate menu for the document's window, 	* by merging it with the application menu.	*@param DocumentInfo& info, the DocumentInfo.	*@param Window* window, the window.	*@param Document* document, the document.	*@see DocInterfacePolicy::mergeWindowMenus	*/	virtual void initializeWindowMenus( Window* window, Document* document, const DocumentInfo& info  );protected:	/**	* attaches a UI to the specified document	*param const DocumentInfo& info, the infos about this document's class.	*param Document* document, the document to attach the UI to.	*@fire DocumentManager::DocumentInitialized	*@event DocManagerEvent	*@eventtype DocumentManager::dmDocumentInitialized	* this event is fired after the UI has been attached to the given document;	* it is useful for custom document initializations ( preferences ).	*/	void attachUI( const DocumentInfo& info, Document* document );	/**	* initializes the actions for the application.	* These are tipical for any document based application.	*/	void initActions();protected:	/**	* message handlers.	* many of the associated events are called for the UI.	**/	/**	* saves the current document, if it has been modified.	*/	virtual void onSave( Event* e ) {		saveFile( DocInterfacePolicy::getCurrentDocument() );	}	/**	* called when this target gets notified for update events	*@see Action::update	*/	virtual void onUpdateSave( ActionEvent* e ) {		updateSave( e, DocInterfacePolicy::getCurrentDocument() );	}	/**	* saves the current document, but let the user to specify	* an alternative filename and type through a dialog box.	*/	virtual void onSaveAs( Event* e ) {		Document* doc = DocInterfacePolicy::getCurrentDocument();		saveFileAs( doc );	}	/**	* called when this target gets notified for update events	*@see Action::update	*/	virtual void onUpdateSaveAs( ActionEvent* e ) {		updateSaveAs( e, DocInterfacePolicy::getCurrentDocument() );	}	/**	* opens a document.	*/	virtual void onOpen( Event* e ) {		openFile();	}	/**	* closes a document.	*/	virtual void onClose( Event* e ) {		closeCurrentDocument();	}	/**	* called when this target gets notified for update events	*@see Action::update	*/	virtual void onUpdateClose( ActionEvent* e ) {		updateClose( e, DocInterfacePolicy::getCurrentDocument() );	}	/**	* creates a new document.	*/	virtual void onNew( Event* e ) {		newDocument();	}	/**	* let the user to change preferences.	*/	virtual void onPreferences( Event* e ) {		editPreferences();	}	/**	* handles notification that the user preferences has been changed	*/	virtual void onUpdatePreferences( ActionEvent* e ) {	}	/**	* closes the document's window	*/	void onDocWindowClosing( FrameEvent* e ) {		if ( !DocInterfacePolicy::closeDocumentWindow( (Window*)e->getSource() ) ) {			e->setOkToClose( false );		}	}	/**	* activates a window and its document	*/	void onDocWindowActive( WindowEvent* e ) {		Window* window = (Window*)e->getSource();		if ( window->isActive() ) {			DocInterfacePolicy::documentWindowActivated( window );		}	}	/**	Happens the first time after the window is created.	This will activate the window and its document	*/	void onDocWindowCreated( Event* e ) {		Window* window = (Window*)e->getSource();		window->show();			}	/**	* handles notification that a document ( specified  by the event ) has been changed.	* The UI will set the caption to the caption of modified document's window.	*/	void onDocModified( ModelEvent* e ) {		Document* doc = (Document*)e->getSource();		String caption = DocInterfacePolicy::getDocumentWindowCaption(doc);		if ( caption != doc->getWindow()->getCaption() ) {			doc->getWindow()->setCaption( caption );		}	}	/**	* starts cut operation	*/	virtual void onCut( Event* e ) {		cutFromDocument( DocInterfacePolicy::getCurrentDocument() );	}	/**	* called when this target gets notified for update events	*@see Action::update	*/	virtual void onUpdateCut( ActionEvent* e ) {		updateCut( e, DocInterfacePolicy::getCurrentDocument() );	}	/**	* starts copy operation	*/	virtual void onCopy( Event* e ) {		copyFromDocument( DocInterfacePolicy::getCurrentDocument() );	}	/**	* called when this target gets notified for update events	*@see Action::update	*/	virtual void onUpdateCopy( ActionEvent* e ) {		updateCopy( e, DocInterfacePolicy::getCurrentDocument() );	}	/**	* starts paste operation	*/	virtual void onPaste( Event* e ) {		pasteToDocument( DocInterfacePolicy::getCurrentDocument() );	}	/**	* called when this target gets notified for update events	*@see Action::update	*/	virtual void onUpdatePaste( ActionEvent* e ) {		updatePaste( e, DocInterfacePolicy::getCurrentDocument() );	}	/**	* starts undo operation	*/	virtual void onUndo( Event* e ) {		undoForDocument( DocInterfacePolicy::getCurrentDocument() );	}	/**	* called when this target gets notified for update events	*@see Action::update	*/	virtual void onUpdateUndo( ActionEvent* e ) {		updateUndo( e, DocInterfacePolicy::getCurrentDocument() );	}	/**	* starts redo operation	*/	virtual void onRedo( Event* e ) {		redoForDocument( DocInterfacePolicy::getCurrentDocument() );	}	/**	* called when this target gets notified for update events	*@see Action::update	*/	virtual void onUpdateRedo( ActionEvent* e ) {		updateRedo( e, DocInterfacePolicy::getCurrentDocument() );	}protected:	/** pointer to the application */	AppClass* app_;	bool closingDocument_;	bool documentClosedOK_;};///////////////////////////////////////////////////////////////////////////////// inlinestemplate < typename AppClass, typename DocInterfacePolicy >void DocumentManagerImpl<AppClass,DocInterfacePolicy>::init(){	app_ = reinterpret_cast<AppClass*>( Application::getRunningInstance() );	DocumentManager::init();	initActions();}template < typename AppClass, typename DocInterfacePolicy >void DocumentManagerImpl<AppClass,DocInterfacePolicy>::initActions(){	Action* action = new Action();	action->setName("FileNew");	action->Performed += new GenericEventHandler< AppClass >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onNew,	                        "onNew" );	addAction( DocumentManager::atFileNew, action );	action = new Action();	action->setName("FileOpen");	action->Performed += new GenericEventHandler< AppClass >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onOpen,	                        "onOpen" );	addAction( DocumentManager::atFileOpen, action );	action = new Action();	action->setName("FileSave");	action->Performed += new GenericEventHandler< AppClass >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onSave,	                        "onSave" );	action->Update += new EventHandlerInstance<AppClass,ActionEvent>( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onUpdateSave,	                        "onUpdateSave" );	addAction( DocumentManager::atFileSave, action );	action = new Action();	action->setName("FileSaveAs");	action->Performed += new GenericEventHandler< AppClass >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onSaveAs,	                        "onSaveAs" );	action->Update += new EventHandlerInstance<AppClass,ActionEvent>( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onUpdateSaveAs,	                        "onUpdateSaveAs" );	addAction( DocumentManager::atFileSaveAs, action );	action = new Action();	action->setName("FileClose");	action->Performed += new GenericEventHandler< AppClass >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onClose,	                        "onClose" );	action->Update += new EventHandlerInstance< AppClass,ActionEvent >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onUpdateClose,	                        "onUpdateClose" );	addAction( DocumentManager::atFileClose, action );	action = new Action();	action->setName("EditUndo");	action->Performed += new GenericEventHandler< AppClass >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onUndo,	                        "onUndo" );	action->Update += new EventHandlerInstance<AppClass,ActionEvent>( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onUpdateUndo,	                        "onUpdateUndo" );	addAction( DocumentManager::atEditUndo, action );	action = new Action();	action->setName("EditRedo");	action->Performed += new GenericEventHandler< AppClass >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onRedo,	                        "onRedo" );	action->Update += new EventHandlerInstance<AppClass,ActionEvent>( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onUpdateRedo,	                        "onUpdateRedo" );	addAction( DocumentManager::atEditRedo, action );	action = new Action();	action->setName("EditCut");	action->Performed += new GenericEventHandler< AppClass >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onCut,	                        "onCut" );	action->Update += new EventHandlerInstance<AppClass,ActionEvent>( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onUpdateCut,	                        "onUpdateCut" );	addAction( DocumentManager::atEditCut, action );	action = new Action();	action->setName("EditCopy");	action->Performed += new GenericEventHandler< AppClass >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onCopy,	                        "onCopy" );	action->Update += new EventHandlerInstance<AppClass,ActionEvent>( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onUpdateCopy,	                        "onUpdateCopy" );	addAction( DocumentManager::atEditCopy, action );	action = new Action();	action->setName("EditPaste");	action->Performed += new GenericEventHandler< AppClass >( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onPaste,	                        "onPaste" );	action->Update += new EventHandlerInstance<AppClass,ActionEvent>( app_,	                        &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onUpdatePaste,	                        "onUpdatePaste" );	addAction( DocumentManager::atEditPaste, action );

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?