documentmanager.h
来自「这是VCF框架的代码」· C头文件 代码 · 共 2,046 行 · 第 1/5 页
H
2,046 行
newEv = new WindowEventHandler< AppClass >( app_, &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onDocWindowActive, "onDocWindowActive" ); } window->FrameActivation += newEv; newEv = app_->getEventHandler("onDocWindowCreated"); if ( NULL == newEv ) { newEv = new GenericEventHandler<AppClass>( app_, &DocumentManagerImpl<AppClass,DocInterfacePolicy>::onDocWindowCreated, "onDocWindowCreated" ); } window->ComponentCreated += newEv; document->updateAllViews();}template < typename AppClass, typename DocInterfacePolicy >void DocumentManagerImpl<AppClass,DocInterfacePolicy>::attachUIToDocument( const String& mimeType, Document* document ){ Window* window = NULL; DocumentInfo info = getDocumentInfo( mimeType ); // this handler notifies the UI to display any changes on the document EventHandler* docEv = app_->getEventHandler("onDocModified"); // see DocumentManagerImpl::newDefaultDocument() for explanation if ( DocInterfacePolicy::saveBeforeNewDocument() ) { Document* doc = DocInterfacePolicy::getCurrentDocument(); if ( NULL != doc ) { doc->removeModelHandler( docEv ); if ( doc->isModified() ) { switch ( saveChanges( doc ) ) { case UIToolkit::mrCancel : { doc->addModelHandler( docEv ); return ; } break; } } } } // creates or activates a window for it, and fires event for custom initializations. attachUI( info, document ); // after the document has been created, we notify that it has // been changed, so the UI can updates itself. ModelEvent e( document, Document::deOpened ); document->ModelChanged.fireEvent( &e );}template < typename AppClass, typename DocInterfacePolicy >Document* DocumentManagerImpl<AppClass,DocInterfacePolicy>::newDefaultDocument( const String& fileName, const String& mimetype ){ /** * if we create a new document while the current document of * the same type has been modified, we need to ask the user * what to do and abort the operation if the user wants to. */ DocumentInfo info = getDocumentInfo( mimetype ); Window* window = NULL; // this handler notifies the UI to display any changes on the document EventHandler* docEv = app_->getEventHandler("onDocModified"); if ( DocumentManager::getShouldCreateUI() ) { if ( DocInterfacePolicy::saveBeforeNewDocument() ) { // only in a SDI policy Document* doc = DocInterfacePolicy::getCurrentDocument(); if ( NULL != doc ) { // we remove this handler as we don't want the UI to display any changes at this point doc->removeModelHandler( docEv ); if ( doc->isModified() ) { // a dialog is shown to the user asking him to save the changes // of the current document previously modified switch ( saveChanges( doc ) ) { case UIToolkit::mrCancel : { /* the user wanted to abort saving the previous document no new document is created, and we put the handler back to the unsaved document */ doc->addModelHandler( docEv ); return NULL; } break; } } } } } // just creates the object from its type using the VCF RTTI Document* newDocument = createDocumentFromType( info ); if ( NULL != newDocument ) { if ( !fileName.empty() ) { newDocument->setFileName( fileName ); } // calls user implementation newDocument->initNew(); if ( DocumentManager::getShouldCreateUI() ) { // creates or activates a window for it, and fires event for custom initializations. attachUI( info, newDocument ); } } else { //throw exception ! } return newDocument;}template < typename AppClass, typename DocInterfacePolicy >Document* DocumentManagerImpl<AppClass,DocInterfacePolicy>::createDocumentFromType( const DocumentInfo& info ) { Document* result = NULL; Class* clazz = NULL; Object* objInstance = NULL; if ( !info.classID.empty() ) { objInstance = ClassRegistry::createNewInstanceFromClassID( info.classID ); } else { objInstance = ClassRegistry::createNewInstance( info.className ); } result = dynamic_cast<Document*>( objInstance ); if ( NULL == result ) { objInstance->free(); } return result;}template < typename AppClass, typename DocInterfacePolicy >void DocumentManagerImpl<AppClass,DocInterfacePolicy>::createMenus() { Menu* standardMenu = MenuManager::getMainMenu(); UIPolicyManager* mgr = UIToolkit::getUIPolicyManager(); MenuItem* root = standardMenu->getRootMenuItem(); DefaultMenuItem* file = new DefaultMenuItem( "&File", root, standardMenu); DefaultMenuItem* fileNew = new DefaultMenuItem( "&New", file, standardMenu); AcceleratorKey::Value val = mgr->getStandardAcceleratorFor(UIPolicyManager::saFileNew); fileNew->setAcceleratorKey( val.getKeyCode(), val.getModifierMask() ); fileNew->setTag( DocumentManager::atFileNew ); DefaultMenuItem* fileOpen = new DefaultMenuItem( "&Open...", file, standardMenu); val = mgr->getStandardAcceleratorFor(UIPolicyManager::saFileOpen); fileOpen->setAcceleratorKey( val.getKeyCode(), val.getModifierMask() ); fileOpen->setTag( DocumentManager::atFileOpen ); DefaultMenuItem* fileClose = new DefaultMenuItem( "Close", file, standardMenu); fileClose->setTag( DocumentManager::atFileClose ); DefaultMenuItem* separator = new DefaultMenuItem( "", file, standardMenu); separator->setSeparator( true ); DefaultMenuItem* fileSave = new DefaultMenuItem( "&Save", file, standardMenu); val = mgr->getStandardAcceleratorFor(UIPolicyManager::saFileSave); fileSave->setAcceleratorKey( val.getKeyCode(), val.getModifierMask() ); fileSave->setTag( DocumentManager::atFileSave ); DefaultMenuItem* fileSaveAs = new DefaultMenuItem( "Save &As...", file, standardMenu); val = mgr->getStandardAcceleratorFor(UIPolicyManager::saFileSaveAs); fileSaveAs->setAcceleratorKey( val.getKeyCode(), val.getModifierMask() ); fileSaveAs->setTag( DocumentManager::atFileSaveAs ); DefaultMenuItem* edit = new DefaultMenuItem( "&Edit", root, standardMenu); DefaultMenuItem* editUndo = new DefaultMenuItem( "&Undo", edit, standardMenu); val = mgr->getStandardAcceleratorFor(UIPolicyManager::saEditUndo); editUndo->setAcceleratorKey( val.getKeyCode(), val.getModifierMask() ); editUndo->setTag( DocumentManager::atEditUndo ); DefaultMenuItem* editRedo = new DefaultMenuItem( "&Redo", edit, standardMenu); val = mgr->getStandardAcceleratorFor(UIPolicyManager::saEditRedo); editRedo->setAcceleratorKey( val.getKeyCode(), val.getModifierMask() ); editRedo->setTag( DocumentManager::atEditRedo ); separator = new DefaultMenuItem( "", edit, standardMenu); separator->setSeparator( true ); DefaultMenuItem* editCut = new DefaultMenuItem( "Cu&t", edit, standardMenu); val = mgr->getStandardAcceleratorFor(UIPolicyManager::saEditCut); editCut->setAcceleratorKey( val.getKeyCode(), val.getModifierMask() ); editCut->setTag( DocumentManager::atEditCut ); DefaultMenuItem* editCopy = new DefaultMenuItem( "&Copy", edit, standardMenu); val = mgr->getStandardAcceleratorFor(UIPolicyManager::saEditCopy); editCopy->setAcceleratorKey( val.getKeyCode(), val.getModifierMask() ); editCopy->setTag( DocumentManager::atEditCopy ); DefaultMenuItem* editPaste = new DefaultMenuItem( "&Paste", edit, standardMenu); val = mgr->getStandardAcceleratorFor(UIPolicyManager::saEditPaste); editPaste->setAcceleratorKey( val.getKeyCode(), val.getModifierMask() ); editPaste->setTag( DocumentManager::atEditPaste ); separator = new DefaultMenuItem( "", edit, standardMenu); separator->setSeparator( true ); DefaultMenuItem* editPreferences = new DefaultMenuItem( "P&references...", edit, standardMenu); editPreferences->setTag( DocumentManager::atEditPreferences ); if ( NULL != app_ ) { DocumentManager::getAction( DocumentManager::atFileNew )->addTarget( fileNew ); DocumentManager::getAction( DocumentManager::atFileOpen )->addTarget( fileOpen ); DocumentManager::getAction( DocumentManager::atFileSave )->addTarget( fileSave ); DocumentManager::getAction( DocumentManager::atFileSaveAs )->addTarget( fileSaveAs ); DocumentManager::getAction( DocumentManager::atFileClose )->addTarget( fileClose ); DocumentManager::getAction( DocumentManager::atEditUndo )->addTarget( editUndo ); DocumentManager::getAction( DocumentManager::atEditRedo )->addTarget( editRedo ); DocumentManager::getAction( DocumentManager::atEditCut )->addTarget( editCut ); DocumentManager::getAction( DocumentManager::atEditCopy )->addTarget( editCopy ); DocumentManager::getAction( DocumentManager::atEditPaste )->addTarget( editPaste ); DocumentManager::getAction( DocumentManager::atEditPreferences )->addTarget( editPreferences ); }}};/***CVS Log info*$Log$*Revision 1.5 2006/04/07 02:35:23 ddiego*initial checkin of merge from 0.6.9 dev branch.**Revision 1.4.2.9 2006/04/05 03:35:58 ddiego*post cvs crash updates.**Revision 1.4.2.8 2006/03/18 22:17:42 ddiego*removed par tag for doxygen comments as its not needed and*screws up the doc formatting.**Revision 1.4.2.7 2006/03/14 02:25:46 ddiego*large amounts of source docs updated.**Revision 1.4.2.6 2006/03/06 03:48:30 ddiego*more docs, plus update add-ins, plus migrated HTML browser code to a new kit called HTMLKit.**Revision 1.4.2.5 2006/01/22 23:52:21 ddiego*some minor changed to doc manager.**Revision 1.4.2.4 2005/10/18 04:42:39 ddiego*fixed minor bug in doc manager.**Revision 1.4.2.3 2005/10/09 04:32:44 ddiego*added some minor fixes in component persistence for vcf builder.**Revision 1.4.2.2 2005/10/04 01:57:03 ddiego*fixed some miscellaneous issues, especially with model ownership.**Revision 1.4.2.1 2005/09/02 01:01:20 ddiego*changed some of the common dialogs around, was using a less clear class name.**Revision 1.4 2005/07/09 23:14:52 ddiego*merging in changes from devmain-0-6-7 branch.**Revision 1.3.2.14 2005/06/06 02:34:06 ddiego*menu changes to better support win32 and osx.**Revision 1.3.2.13 2005/06/02 15:56:04 marcelloptr*more documentation. Made some handlers virtual. Added some forgotten onUpdateXXX**Revision 1.3.2.12 2005/05/15 23:17:37 ddiego*fixes for better accelerator handling, and various fixes in hwo the text model works.**Revision 1.3.2.11 2005/05/06 20:35:19 marcelloptr*Added option to reloadDocument function**Revision 1.3.2.9 2005/04/18 14:56:51 marcelloptr*removed member variable added too soon**Revision 1.3.2.7 2005/04/15 20:25:39 marcelloptr*fix: saveAs now notifies the UI that the document has changed name**Revision 1.3.2.6 2005/04/09 17:20:35 marcelloptr*bugfix [ 1179853 ] memory fixes around memset. Documentation. DocumentManager::saveAs and DocumentManager::reload**Revision 1.3.2.5 2005/03/14 04:17:23 ddiego*adds a fix plus better handling of accelerator keys, ands auto menu title for the accelerator key data.**Revision 1.3.2.4 2005/03/06 22:50:59 ddiego*overhaul of RTTI macros. this includes changes to various examples to accommadate the new changes.**Revision 1.3.2.3 2005/03/05 18:21:18 ddiego*fixed a bug that marcello found in the vcfbuilder that is actually a bug in the document manager (see bug 1157348).**Revision 1.3.2.2 2005/03/02 19:41:13 marcelloptr*fixed crash when opening a non existing document**Revision 1.3.2.1 2005/01/28 02:49:01 ddiego*fixed bug 1111096 where the text control was properly handlind*input from the numbpad keys.**Revision 1.3 2004/12/01 04:31:21 ddiego*merged over devmain-0-6-6 code. Marcello did a kick ass job*of fixing a nasty bug (1074768VCF application slows down modal dialogs.)*that he found. Many, many thanks for this Marcello.**Revision 1.2.2.9 2004/11/19 05:54:28 ddiego*added some fixes to the text peer for win32 for printing. added toolbars to text edit example anmd added printing**Revision 1.2.2.8 2004/11/16 21:35:50 marcelloptr*more documentation**Revision 1.2.2.2 2004/10/26 05:44:12 marcelloptr*Document Window documentation**Revision 1.2 2004/08/07 02:49:08 ddiego*merged in the devmain-0-6-5 branch to stable**Revision 1.1.2.5 2004/07/18 14:45:18 ddiego*integrated Marcello's new File/Directory API changes into both*the FoundationKit and the ApplicationKit. Many, many thanks go out*to Marcello for a great job with this. This adds much better file searching*capabilities, with many options for how to use it and extend it in the*future.**Revision 1.1.2.4 2004/06/29 20:31:35 ddiego*some minor fixes to the DocumentManager**Revision 1.1.2.3 2004/06/06 07:05:30 marcelloptr*changed macros, text reformatting, copyright sections**Revision 1.1.2.2 2004/04/29 03:43:13 marcelloptr*reformatting of source files: macros and csvlog and copyright sections**Revision 1.1.2.1 2004/04/28 00:28:16 ddiego*migration towards new directory structure**Revision 1.4.2.2 2004/04/26 21:58:19 marcelloptr*changes for dir reorganization: _VCF_MACRO_H__**Revision 1.4.2.1 2004/04/10 04:37:19 ddiego*added a MIMType class that parses mime types.**Revision 1.4 2004/04/03 15:48:40 ddiego*Merged over code from the 0-6-3 branch.**Revision 1.3.2.4 2004/03/28 00:46:21 ddiego*added VisualFormFiles, fixed some code in the DocumentManager*class, and changed code over to create an Application class on the*heap instead of on the stack. This fixes a problem with static object*destrcutor order when using VC71. Also updated the project wizards*for vc6. Still need to update docs.**Revision 1.3.2.3 2004/03/24 21:28:49 ddiego*minor change to document manager - added*setCurrentDocument**Revision 1.3.2.2 2004/03/24 04:51:24 ddiego*empty**Revision 1.3.2.1 2004/03/08 04:41:07 ddiego*minor changes to DocumentManager - allow the use of*Actions so that other UI elements can be added besides menu*items (like Toolbar items)**Revision 1.3 2003/12/18 05:15:57 ddiego*merge from devmain-0-6-2 branch into the stable branch**Revision 1.2.2.17 2003/12/08 05:05:28 ddiego*added a bunch more documentation to classes, and added support for new doc*keywords (@delegates, @del, @delegate, @event, and @eventtype). This*makes it easier to see at a glance what events a class fires off.*Added finishing touches for the Action implementation and have a partially*complete example for this checked in.**Revision 1.2.2.16 2003/10/28 20:23:26 ddiego*minor header changes**Revision 1.2.2.15 2003/09/22 01:48:03 ddiego*some minor additions ot the DropTarget to allow it to have multiple*control targets*also a few other misc fixes**Revision 1.2.2.14 2003/09/19 21:24:21 ddiego*small changes**Revision 1.2.2.13 2003/09/19 04:12:01 ddiego*added fix to docmanager*added fix to handle path components with case insensitivity on Win32
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?