A document based application is an application that has a specific file type associated with it that it edits.
A document based application has the following features.
To set up a file type for your document you need to add the following entries to your
!Boot
and !Run
files so the Desktop can identify your file type and
launch your application if it is double clicked upon in the filer.
| Variables need to be added (in this case for TbxDocEx file type hex 010) | Let the desktop know what to do to edit this file type Set Alias$RunType_010 Run <Obey$Dir>.!Run %%*0 | Set The description for the file type Set File$Type_010 "TbxDocEx"
You will also need to add an icon to your !Sprites
file for display in the filer.
This is the usual 34x17 sprite the same size as your application sprite, but with the
name file_XXX where XXX is your file type number. (In the above example it would be file_010).
tbx provides a group of classes to provide a framework in the tbx::doc namespace for all of this standard functionality. You do not have to use this framework, you can instead add listeners to the application for the WIMP messages you need to process for this type of application and the necessary toolbox objects and functionality.
To use the tbx::doc classes you need to create and add the following
resources to your Res
.
You then add the following code to you main
function.
tbx::Application docex_app("<TbxDocEx$Dir>"); tbx::doc::DocCreator<TbxExDoc, TbxExWnd> doc_creator(0x010); tbx::doc::DocManager doc_manager(&doc_creator); tbx::doc::DocIconbar doc_iconbar; tbx::doc::DocSaveAs doc_saveas; tbx::doc::DocFileInfo doc_fileinfo; if (argc > 1) doc_manager.load_files(argc-1, argv+1); docex_app.run();
In the above listing the following would be replaced with items for your application.
TbxDocEx$Dir would be replaced with the path name for your resources.
TbxExDoc
would be your document class (derived
from tbx::doc::Document
).
TbxExWnd
would be
your class to handle the display of the document (derived from tbx::doc::DocWindow
).
With this code in place all that is then needed is to derive your document from tbx::doc::Document
(TbxExDoc in the example code above) and overload the document_size
,
load(std::istream &is)
and save(std::ostream &os)
methods.
The window to display the document should be derived from tbx::doc::DocWindow and modified to show the data when it is created.
If more functionality is required from the iconbar you may want to derive
a class from tbx::doc::DocIconbar
as well.
There is a demo application called !TbxDocEx included in the separate TBX-Examples download that shows a simple document based application.