wxDocview Usage

Typical steps to use this framework

  1. Create your own document and view classes, overriding a minimal set of member functions of a2dDocument and a2dView.

  2. Create windows which should be used by the views, or better: where the views should be connected to. Either you use a wxDocviewWindow or a wxDocviewScrolledWindow or you may create your own windows.
  3. Define your view connector(s) by overriding the member methods OnPostCreateDocument(a2dDocumentTemplateEvent& event) and OnPostCreateView(a2dViewTemplateEvent& event) or catch the events wxEVT_POST_CREATE_DOCUMENT and wxEVT_POST_CREATE_VIEW to direct them to your own class functions. The latter event is more important than the first because the base class (a2dViewConnector) handles the first event, but it does know nothing about your application and will show an error if you don't catch the wxEVT_POST_CREATE_VIEW event.

  4. Create a a2dDocumentCommandProcessor at application start-up, i.e. in the OnInit() method of wxApp. Initialize a2dDocviewGlobals with it. You can also use the default a2dDocviewGlobals->GetDocviewCommandProcessor() directly if there is no need for you own one. a2dDocviewGlobals gives also access to a2dEventDistributer.

  5. Create one or more a2dDocumentTemplates and a2dViewTemplates and associate the templates with the a2dDocumentCommandProcessor.

Example: Creating the global used objects at application start-up

   1       bool MyApp::OnInit()
   2       {
   3       [...]
   4 
   5       // We hold a pointer to the docview command processor
   6       // because we use this pointer later for the doc/view templates
   7 
   8       // Use your own specific derived a2dDocumentCommandProcessor
   9       // a2dMultiViewDocManager* docmanager = new a2dMultiViewDocManager();
  10       // a2dDocviewGlobals->SetDocviewCommandProcessor( docmanager );
  11       // Initialize the <<Dox(a2dDocviewGlobal)>> global object, which gives us access to the command processor and friends
  12       // a2dDocviewGlobals->SetDocviewCommandProcessor( docMan );
  13       // OR the default
  14       <<Dox(a2dDocumentCommandProcessor)>>* docMan =   a2dDocviewGlobals->GetDocviewCommandProcessor();
  15 
  16       // Maybe we want to limit the no. of max. opened docs? (default value is 10000, which is enough in several cases ;) )
  17       docMan->SetMaxDocsOpen(20);
  18 
  19       [...]
  20       }

Example: Associating templates with the a2dDocumentCommandProcessor

   1       bool MyApp::OnInit()
   2       {
   3       [...]
   4       // We assume that you've created a <<Dox(a2dDocumentCommandProcessor)>> instance, called "docMan"
   5       // Also we assume that you've defined a MyDrawingDoc document (derived from a2dDocument
   6       // and a MyTextView and a MyDrawingView which were derived from <<Dox(a2dView)>>. You've also
   7       // created a view connector instance called "viewConn" to view only one document at time
   8 
   9       // Pointers to (maybe) several doc / view templates
  10       <<Dox(a2dDocumentTemplate)>>* docTpl;
  11       <<Dox(a2dViewTemplate)>>* viewTpl;
  12 
  13       // Creation of one template for only one known document
  14       docTpl = new <<Dox(a2dDocumentTemplate)>>(
  15                                   wxT("Drawing Document"),        // The description shown in the file selector dialog
  16                                   wxT("*.drw"),                   // The file extension shown in the file selector dialog
  17                                   wxT(""),                        // The default directory for this doc type
  18                                   wxT("drw"),                     // The file extension
  19                                   wxT("DrwDoc"),                  // The doc type description (must be unique to
  20                                                                   // associate the view tpl with the doc
  21                                   CLASSINFO(MyDrawingDoc),        // Your derived <<Dox(a2dDocument)>> class
  22                                   viewConn,                       // View connector instance to use
  23                                   a2dREFTEMPLATE_VISIBLE,          // Template should be visible (shown in file sel. dialogs)
  24                                   new MyIOHandler()               // The I/O handler for this document (optional value)
  25                               );
  26 
  27       // Make the doc template known by our <<Dox(a2dDocumentCommandProcessor)>> instance
  28       docMan->AssociateDocTemplate(docTpl);
  29 
  30       // We've two views, so we'll create two view templates
  31 
  32       // Creation of the drawing view template
  33       viewTpl = new <<Dox(a2dViewTemplate)>>(
  34                                   wxT("Drw View"),                // Description of the view
  35                                   wxT("DrwDoc"),                  // The unique document type name (see doc template)
  36                                   wxT("Drawing View"),            // View name which is shown by the view sel. dialog
  37                                   CLASSINFO(MyDrawingView),       // View class (our drawing view)
  38                                   viewConn,                       // View connector instance
  39                                   a2dREFTEMPLATE_VISIBLE,          // Template should be visible (shown in view sel. dialogs)
  40                                   wxSize(200, 300)                // Size of the view window / frame
  41                                                                   // (this is an optional value which you may use on your own,
  42                                                                   //  i.e. to create frames with a constant size)
  43                                  );
  44 
  45       // Associate the <<Dox(a2dDocumentCommandProcessor)>> with the view template
  46       docMan->AssociateViewTemplate(viewTpl);
  47 
  48 
  49       // Creation of the text view template
  50       viewTpl = new <<Dox(a2dViewTemplate)>>(
  51                                   wxT("Drw View"),
  52                                   wxT("DrwDoc"),
  53                                   wxT("Text View"),               // View name which is shown by the view sel. dialog
  54                                   CLASSINFO(MyTextView),          // View class (our text view)
  55                                   viewConn,
  56                                   a2dREFTEMPLATE_VISIBLE,
  57                                   wxSize(200, 450)
  58                                  );
  59 
  60       // Associate the <<Dox(a2dDocumentCommandProcessor)>> with the 2nd view template
  61       docMan->AssociateViewTemplate(viewTpl);
  62 
  63       [...]
  64       }

DocviewUsage (last edited 2011-03-05 20:35:48 by MichaelStratmann)