For example, when a user clicks on a hypertext link that is embedded within the WebRunner Sample, the viewer switches the page to display the new content. The view does not display new windows--it simply reuses the current window. This functionality is accomplished by communicating with the embedded ("in-place") link and the containing WebRunner Sample viewer. The communication is made possible using a command that is sent from the link to the embedding viewer. Links of this type are distinguished by a downward-pointing link arrow.
WebRunner Sample takes a different approach when a user drags a hypertext link within the program and embeds it in another location. Whenever a user clicks on this "out-of-place" hypertext link it opens into a new WebRunner document. Links of this type are always followed by a sideways arrow.
Both of these actions are performed in the MouseDown member function of the hypertext link's view, TWebLinkView. The flow of control is illustrated here to help clarify the complex Document framework interactions that are taking place.
The Document framework offers a way for a document component view (in fact, any view that descends from MGUIBundle) to get access to its model using the member function GetModelReference. With the resulting reference, a view can create a model pointer that accesses and locks the model so that it can be communicated with. This model pointer gives access to the TAtomicModelOn<TWebLink>, which in turn gives access to its TWebLink value.
TWebLink holds another TModelReference that either refers to the embedding WebRunner Sample (if this link is embedded), or to an invalid document. The view asks TWebLink for this reference, and then checks for its validity.
Communicating through document commands provides several benefits. For example, you can take advantage of all the document commands that are streamed into a persistent state along with the document. If the program unexpectedly fails during operation, you can still achieve unlimited levels of Undo and Redo.
This operation can be complicated by the lock placed on the link component in creating a TModelPointer. Although it provides easy synchronization in a multithreaded environment, you might want to remove all the text in the hypertext viewer, along with all its embedded components. Unfortunately, this includes the link that you are currently working with.
You can solve this dilemma by limiting the scope of the model pointer to the time needed to retrieve information from it. By creating an enclosing scope that ends before the command is fired, you can avoid a deadlock by releasing the lock when it is no longer needed.