Cross-Platform GUI Programming with wxWidgets
|
Other Document/View Capabilities
We've shown a simple example that demonstrates the essential steps you need to follow for a complete document-centric application. This section presents further tips on using the document/view framework. Standard Identifiers
The document/view system has default behavior for the following standard identifiers: wxID_OPEN, wxID_CLOSE, wxID_CLOSE_ALL, wxID_REVERT, wxID_NEW, wxID_SAVE, wxID_SAVEAS, wxID_UNDO, wxID_REDO, wxID_PRINT, and wxID_PREVIEW. Use these identifiers in your menu bars and toolbars to take full advantage of the framework. The functions that handle these identifiers are mostly implemented in wxDocManager: for example, OnFileOpen, OnFileClose, and OnUndo. These handlers then call appropriate functions in the currently active document. If you want, you can override these commands in your frame class or in a class derived from wxDocManager, but this is not usually necessary. Printing and Previewing
By default, wxID_PRINT and wxID_PREVIEW use the standard wxDocPrintout class to implement printing and print preview, taking advantage of wxView:: OnDraw if implemented. However, this has very limited functionalityit only copes with a single-page documentso you're likely to want to create your own wxPrintout class and override the standard handlers for wxID_PRINT and wxID_PREVIEW. The quickest method is to use the wxHtmlEasyPrinting class, as described in "HTML Printing" in Chapter 12, "Advanced Window Classes." File History
When your application initializes, you can load the file history shown at the bottom of the File menu from a wxConfig object with wxDocManager::File HistoryLoad and save it in your application cleanup with wxDocManager:: FileHistorySave. For example, to load the file history, type the following: // Load the file history wxConfig config(wxT("MyApp"), wxT("MyCompany")); config.SetPath(wxT("FileHistory")); m_docManager->FileHistoryLoad(config); config.SetPath(wxT("/"));
If you load the file history before you create your main frame and its menu bar, you will need to explicitly call wxDocManager::FileHistoryAddFilesToMenu. If you want, you can use the wxFileHistory class independently of the other document/view classes, or to implement file history in a different way (for example, if your application requires a separate file history for each document frame). Explicit Document Creation
Sometimes you may want to create a document explicitly in your documentfor example, if you are opening the last document that was viewed. You can open an existing document like this: wxDocument* doc = m_docManager->CreateDocument(filename, wxDOC_SILENT);
Or create a new document like this: wxDocument* doc = m_docManager->CreateDocument(wxEmptyString, wxDOC_NEW); In both cases, a view will be created automatically. |
|