Provides document display and editing facilities.
The Document class offers a complete page layout engine, providing rich text display features for creating complex documents and text-based interfaces. Internally, document data is maintained as a serial byte stream and all object model information from the source is discarded. This simplification of the data makes it possible to edit the document in-place, much the same as any word processor. Alternatively it can be used for presentation purposes only, similarly to PDF or HTML formats. Presentation is achieved by building a vector scene graph in conjunction with the Vector module. This means that the output is compatible with SVG and can be manipulated in detail with our existing vector API. Consequently, document formatting is closely integrated with SVG concepts and seamlessly inherits SVG functionality such as filling and stroking commands.
The native document format in Parasol is RIPL. Documentation for RIPL is available in the Parasol Wiki. Other document formats may be supported as sub-classes, but bear in mind that document parsing is a one-way trip and stateful information such as the HTML DOM is not supported.
The Document class does not include a security barrier in its current form. Documents that include scripted code should not be processed unless they originate from a trusted source and are confirmed as such. To mitigate security problems, we recommend that the application is built with some form of sandbox that can prevent the system being compromised by bad actors. Utilising a project such as Win32 App Isolation https://github.com/microsoft/win32-app-isolation is one potential way of doing this.
The Document class consists of the following fields:
Access | Name | Type | Comment | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Author | STRING | The author(s) of the document. | |||||||||||||||||||
If a document declares the names of its author(s) under a head tag, the author string will be readable from this field. This field is always | |||||||||||||||||||||
ClientScript | OBJECTPTR | Allows an external script object to be used by a document file. | |||||||||||||||||||
Set ClientScript with a Script object to allow document content to 'breach the firewall' and access functionality outside of its namespace. This feature is primarily intended for applications that need to interact with their own embedded documents. If a document defines a default script in its content, it will have priority over the one referenced here. | |||||||||||||||||||||
Copyright | STRING | Copyright information for the document. | |||||||||||||||||||
If a document declares copyright information under a head tag, the copyright string will be readable from this field. This field is always | |||||||||||||||||||||
Description | STRING | A description of the document, provided by its author. | |||||||||||||||||||
If the source document includes a description, it will be copied to this field. | |||||||||||||||||||||
Error | ERR | The most recently generated error code. | |||||||||||||||||||
The most recently generated error code is stored in this field. | |||||||||||||||||||||
EventCallback | FUNCTION | Provides callbacks for global state changes. | |||||||||||||||||||
Set this field with a function reference to receive event notifications. It must be set in conjunction with EventMask so that notifications are limited to those of interest. The callback function prototype is The Error codes returned from the callback will normally be discarded, however in some cases | |||||||||||||||||||||
EventMask | DEF | Specifies events that need to be reported from the Document object. | |||||||||||||||||||
To receive event notifications, set EventCallback with a function reference and the EventMask field with a mask that indicates the events that need to be received.
| |||||||||||||||||||||
Flags | DCF | Optional flags that affect object behaviour. | |||||||||||||||||||
| |||||||||||||||||||||
Focus | *VectorViewport | Refers to the object that will be monitored for user focusing. | |||||||||||||||||||
By default, a document object will become active (i.e. capable of receiving keyboard input) when its surface container receives the focus. If you would like to change this so that a document becomes active when some other object receives the focus, refer to that object by writing its ID to this field. | |||||||||||||||||||||
Keywords | STRING | Includes keywords declared by the source document. | |||||||||||||||||||
If a document declares keywords under a head tag, the keywords string will be readable from this field. This field is always | |||||||||||||||||||||
Origin | STRING | Similar to the Path field, but does not automatically load content if set. | |||||||||||||||||||
This field is identical to the Path field, with the exception that it does not update the content of a document object if it is set after initialisation. This may be useful if the location of a loaded document needs to be changed without causing a load operation. | |||||||||||||||||||||
Page | *VectorViewport | The Page contains the document content and is hosted by the View | |||||||||||||||||||
PageHeight | INT | Measures the page height of the document, in pixels. | |||||||||||||||||||
The exact height of the document is indicated in the PageHeight field. This value includes the top and bottom page margins. | |||||||||||||||||||||
PageWidth | INT | Measures the page width of the document, in pixels. | |||||||||||||||||||
The width of the longest document line can be retrieved from this field. The result includes the left and right page margins. | |||||||||||||||||||||
Path | STRING | Identifies the location of a document file to load. | |||||||||||||||||||
To load a document file into a document object, set the Path field. Valid string formats for setting the path are:
Setting this field post-initialisation will cause a complete reload unless the path begins with a hash to signal a change to the current page and parameters. Note: if a requested page does not exist in the currently loaded document, a dialog is displayed to bring the error to the user's attention). To leap to a bookmark in the page that has been specified with the Other means of opening a document include loading the data manually and passing it via the DataFeed() action. | |||||||||||||||||||||
Pretext | STRING | Execute the XML defined here prior to loading new pages. | |||||||||||||||||||
Use the Pretext field to execute document code prior to the loading of a new document. This feature is commonly used to set configure a document in advance, such as setting default font values and background graphics. It is functionally equivalent to embedding an A Pretext will always survive document unloading and resets. It can be removed only by setting this field with | |||||||||||||||||||||
TabFocus | OBJECTID | Allows the user to hit the tab key to focus on other GUI objects. | |||||||||||||||||||
If this field points to a TabFocus object, the user will be able to move between objects that are members of the TabFocus by pressing the tab key. Please refer to the TabFocus class for more details. | |||||||||||||||||||||
Title | STRING | The title of the document. | |||||||||||||||||||
If a document declares a title under a head tag, the title string will be readable from this field. This field is always | |||||||||||||||||||||
View | *VectorViewport | An internally created viewport that hosts the Page | |||||||||||||||||||
Viewport | *VectorViewport | A client-specific viewport that will host the document graphics. | |||||||||||||||||||
The Viewport field must refer to a VectorViewport that will host the document graphics. If undefined by the client, the nearest viewport container will be determined based on object ownership. | |||||||||||||||||||||
WorkingPath | STRING | Defines the working path (folder or URI). | |||||||||||||||||||
The working path for a document is defined here. By default this is defined as the location from which the document was loaded, without the file name. If this cannot be determined then the working path for the parent task is used (this is usually set to the location of the parasol executable). The working path is always fully qualified with a slash or colon at the end of the string unless the path cannot be determined - in which case an empty string is returned. You can manually change the working path by setting the Origin field without affecting the loaded document. |
The following actions are currently supported:
Name | Comment | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Activate | Activates all child objects of the document. | |||||||||||||||||||
ERR acActivate(*Object) Calling the Activate() action on a document object will forward Activate() calls to its child objects. | ||||||||||||||||||||
Clear | Clears all content from the object. | |||||||||||||||||||
ERR acClear(*Object) Using the Clear() action will delete all of the document's content. The UI will be updated to reflect a clear document. | ||||||||||||||||||||
Clipboard | Full support for clipboard activity is provided through this action. | |||||||||||||||||||
ERR acClipboard(*Object, OBJECTID Clipboard, CLIPMODE Mode)
| ||||||||||||||||||||
DataFeed | Document data can be sent and consumed via feeds. | |||||||||||||||||||
ERR acDataFeed(*Object, OBJECTID Object, DATA Datatype, APTR Buffer, LONG Size)
Appending content to an active document can be achieved via the data feed feature. The Document class currently supports the Error Codes
| ||||||||||||||||||||
Disable | Disables user interactivity. | |||||||||||||||||||
Draw | Force a page layout update (if changes are pending) and redraw to the display. | |||||||||||||||||||
ERR acDraw(*Object, DOUBLE X, DOUBLE Y, DOUBLE Width, DOUBLE Height)
| ||||||||||||||||||||
Enable | Enables object functionality. | |||||||||||||||||||
Focus | Sets the user focus on the document page. | |||||||||||||||||||
GetKey | Retrieves global variables and URI parameters. | |||||||||||||||||||
ERR acGetKey(*Object, CSTRING Key, STRING Value, LONG Size)
Use GetKey() to access the global variables and URI parameters of a document. Priority is given to global variables if there is a name clash. The current value of each document widget is also available as a global variable accessible from GetKey(). The key-value will be given the same name as that specified in the widget's element. | ||||||||||||||||||||
Refresh | Reloads the document data from the original source location. | |||||||||||||||||||
SaveToObject | Use this action to save edited information as an XML document file. | |||||||||||||||||||
ERR acSaveToObject(*Object, OBJECTID Dest, CLASSID ClassID)
| ||||||||||||||||||||
SetKey | Set a global key-value in the document. | |||||||||||||||||||
ERR acSetKey(*Object, CSTRING Key, CSTRING Value)
|
The following methods are currently supported:
Name | Comment | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AddListener | Adds a listener to a document trigger for receiving special callbacks. | ||||||||||||||||||||||||||||||
ERR doc::AddListener(OBJECTPTR Object, DRT Trigger, FUNCTION * Function)
Use the AddListener() method to receive feedback whenever a document event is triggered. Triggers are a fundamental part of document page development, accessible through the The following triggers are supported:
A listener can be removed by calling RemoveListener(), however this is normally unnecessary. Listeners are removed automatically if a new document source is loaded, or the document object is terminated. Note that a trigger can have multiple listeners attached to it, so a new subscription will not replace any prior subscriptions, nor is there any handling for multiple copies of a subscription to a trigger. Error Codes
| |||||||||||||||||||||||||||||||
CallFunction | Executes any registered function in the currently open document. | ||||||||||||||||||||||||||||||
ERR doc::CallFunction(OBJECTPTR Object, CSTRING Function, struct ScriptArg * Args, LONG TotalArgs)
This method will execute any registered function in the currently open document. The name of the function must be specified in the first parameter and that function must exist in the document's default script. If the document contains multiple scripts, then a specific script can be referenced by using the name format Arguments can be passed to the function by setting the Error Codes
| |||||||||||||||||||||||||||||||
Edit | Activates a user editing section within a document. | ||||||||||||||||||||||||||||||
ERR doc::Edit(OBJECTPTR Object, CSTRING Name, LONG Flags)
The Edit() method will manually activate an editable section in the document. This results in the text cursor being placed at the start of the editable section, where the user may immediately begin editing the section via the keyboard. If the editable section is associated with an Error Codes
| |||||||||||||||||||||||||||||||
FindIndex | Searches the document stream for an index, returning the start and end points if found. | ||||||||||||||||||||||||||||||
ERR doc::FindIndex(OBJECTPTR Object, CSTRING Name, LONG * Start, LONG * End)
Use the FindIndex() method to search for indexes that have been declared in a loaded document. Indexes are declared using the If the named index exists, then the start and end points (as determined by the opening and closing of the index tag) will be returned as byte indexes in the document stream. The starting byte will refer to an Error Codes
| |||||||||||||||||||||||||||||||
HideIndex | Hides the content held within a named index. | ||||||||||||||||||||||||||||||
ERR doc::HideIndex(OBJECTPTR Object, CSTRING Name)
The HideIndex() and ShowIndex() methods allow the display of document content to be controlled at code level. To control content visibility, start by encapsulating the content in the source document with an The document layout is automatically updated and pushed to the display when this method is called. Error Codes
| |||||||||||||||||||||||||||||||
InsertText | Inserts new content into a loaded document (raw text format). | ||||||||||||||||||||||||||||||
ERR doc::InsertText(OBJECTPTR Object, CSTRING Text, LONG Index, LONG Char, LONG Preformat)
Use the InsertText() method to insert new content into an initialised document. Caution must be exercised when inserting document content. Inserting an image in-between a set of table rows for instance, would cause unknown results. Corruption of the document data may lead to a program crash when the document is refreshed. The document view will not be automatically redrawn by this method. This must be done manually once all modifications to the document are complete. Error Codes
| |||||||||||||||||||||||||||||||
InsertXML | Inserts new content into a loaded document (XML format). | ||||||||||||||||||||||||||||||
ERR doc::InsertXML(OBJECTPTR Object, CSTRING XML, LONG Index)
Use the InsertXML() method to insert new content into an initialised document. Caution must be exercised when inserting document content. Inserting an image in-between a set of table rows for instance, would cause unknown results. Corruption of the document data may lead to a program crash when the document is refreshed. The document view will not be automatically redrawn by this method. This must be done manually once all modifications to the document are complete. Error Codes
| |||||||||||||||||||||||||||||||
ReadContent | Returns selected content from the document, either as plain text or original byte code. | ||||||||||||||||||||||||||||||
ERR doc::ReadContent(OBJECTPTR Object, DATA Format, LONG Start, LONG End, STRING * Result)
The ReadContent() method extracts content from the document stream, covering a specific area. It can return the data as a RIPL binary stream, or translate the content into plain-text (control codes are removed). If data is extracted in its original format, no post-processing is performed to fix validity errors that may arise from an invalid data range. For instance, if an opening paragraph code is not closed with a matching paragraph end point, this will remain the case in the resulting data. Error Codes
| |||||||||||||||||||||||||||||||
RemoveContent | Removes content from a loaded document. | ||||||||||||||||||||||||||||||
ERR doc::RemoveContent(OBJECTPTR Object, LONG Start, LONG End)
This method will remove all document content between the Error Codes
| |||||||||||||||||||||||||||||||
RemoveListener | Removes a previously configured listener from the document. | ||||||||||||||||||||||||||||||
ERR doc::RemoveListener(OBJECTPTR Object, LONG Trigger, FUNCTION * Function)
This method removes a previously configured listener from the document. The original parameters that were passed to AddListener() must be provided. Error Codes
| |||||||||||||||||||||||||||||||
SelectLink | Selects links in the document. | ||||||||||||||||||||||||||||||
ERR doc::SelectLink(OBJECTPTR Object, LONG Index, CSTRING Name)
This method will select a link in the document. Selecting a link will mean that the link in question will take on a different appearance (e.g. if a text link, the text will change colour). If the user presses the enter key when a hyperlink is selected, that link will be activated. Selecting a link may also enable drag and drop functionality for that link. Links are referenced either by their Error Codes
| |||||||||||||||||||||||||||||||
ShowIndex | Shows the content held within a named index. | ||||||||||||||||||||||||||||||
ERR doc::ShowIndex(OBJECTPTR Object, CSTRING Name)
The HideIndex() and ShowIndex() methods allow the display of document content to be controlled at code level. To control content visibility, start by encapsulating the content in the source document with an The document layout is automatically updated and pushed to the display when this method is called. Error Codes
|
Data codes
Name | Description |
---|---|
DATA::AUDIO | Audio file data, recognised by the Sound class |
DATA::CONTENT | Document content (between XML tags) - sent by document objects only |
DATA::DEVICE_INPUT | Device activity |
DATA::FILE | File location (the data will reflect the complete file path) |
DATA::IMAGE | Image file data, recognised by the Image class |
DATA::INPUT_READY | Device input that has been transformed into user input |
DATA::RAW | Raw unprocessed data |
DATA::RECEIPT | Receipt for item data, in response to an earlier request |
DATA::RECORD | Database record |
DATA::REQUEST | Make a request for item data |
DATA::TEXT | Standard ASCII text |
DATA::XML | Markup based text data. NOTE - For clipboard data, the top-level encapsulating tag must declare the type of XML, e.g. 'html', 'ripple'. For plain XML, use 'xml' |
Document flags
Name | Description |
---|---|
DCF::DISABLED | This read-only flag is set if the UI has been disabled through the Disable action. |
DCF::EDIT | Allow direct keyboard input and document editing. |
DCF::NO_LAYOUT_MSG | Turn off debug output produced during document layout and processing - useful on refresh for example. |
DCF::NO_SYS_KEYS | System-keys provide standard key support for Ctrl-C, Ctrl-X etc. Set this flag to turn them off. |
DCF::OVERWRITE | This flag forces overwrite mode when the user enters information through the keyboard. If the flag is not set, then insert mode is used. |
DCF::UNRESTRICTED | Turn off all security measures - may only be set prior to initialisation. |
Event flags for selectively receiving events from the Document object.
Name | Description |
---|---|
DEF::LINK_ACTIVATED | The user has interacted with a hyperlink. This event can be cancelled by returning ERR::Skip. |
DEF::ON_CLICK | The user has interacted with an element that has an on-click definition. |
DEF::ON_CROSSING | Synonym for ON_CROSSING_IN | ON_CROSSING_OUT |
DEF::ON_CROSSING_IN | The mouse pointer has crossed into an element. |
DEF::ON_CROSSING_OUT | The mouse pointer has crossed out of an element. |
DEF::ON_MOTION | The user has triggered a motion event in an element that supports motion monitoring. |
DEF::PATH | The source file path has changed. Useful for detecting when the user has left the page. |
DEF::WIDGET_STATE | The state value of a widget has changed (e.g. input, checkbox, text). name and value keys will be defined in the event parameters. |
Internal trigger codes
Name | Description |
---|---|
DRT::AFTER_LAYOUT | |
DRT::BEFORE_LAYOUT | |
DRT::END | |
DRT::GOT_FOCUS | |
DRT::LEAVING_PAGE | |
DRT::LOST_FOCUS | |
DRT::PAGE_PROCESSED | |
DRT::REFRESH | |
DRT::USER_CLICK | |
DRT::USER_CLICK_RELEASE | |
DRT::USER_MOVEMENT |
Class Info | |
---|---|
ID | ID_DOCUMENT |
Category | GUI |
Include | modules/document.h |
Version | 1 |