6.4.4 Update, Save As, and New Commands

When a server is started as part of editing an object from within a compound document, the server application should change the Save command on the File menu to Update. When the user chooses the Update command, the server should call the OleSavedServerDoc function.

When the user chooses the Save As, New, or Open command in a single-document server, the application should display a message asking the user
whether to update the object in the compound document before performing the
action. When the user chooses the Save As command, the server should call the OleRenameServerDoc function. If the user responds to the message by choosing to save changes in the object before renaming the document, the server should call the OleSavedServerDoc function before calling OleRenameServerDoc. For embedded objects, choosing the Save As command causes the connection with the client to be broken, because this command reassociates a document in memory with the specified new file. For linked objects, calling OleRenameServerDoc when the user chooses Save As makes it possible for the client to associate the link with the new file.

Most server applications maintain a “dirty” flag that records whether changes have been made to each open document in an instance. The following table shows the rules that apply to this flag when the server edits an embedded object. By following these rules, a server can ensure that this flag is TRUE when the document being edited in the server matches the embedded object in the client and that, otherwise, this flag is FALSE.

Flag Condition

TRUE Library calls the Create function in the OLESERVERVTBL structure.
TRUE Library calls the CreateFromTemplate function in OLESERVERVTBL.
TRUE Document is changed in server.
FALSE Library calls the Edit function in OLESERVERVTBL.
FALSE Library calls the GetData function in OLEOBJECTVTBL with the Native data format. (The flag should not change for any other formats.)

A server following these rules displays the message asking whether to update the object whenever it destroys a document that was editing an embedded object and the “dirty” flag is TRUE.

In an MDI server application, the New and Open commands on the File menu simply open a new window, and the connection with the client application remains unchanged. The user can continue to work with the server application after choosing one of these commands, but when the user exits the server application, the focus does not necessarily return to the client application.

Typically, a server can call the OleSavedServerDoc function whenever an object needs to be updated in the client document, including when the server closes the document. When the server closes the document and the object should be updated, the server sends the OLE_CLOSED notification. Client applications receive the OLE_CLOSED notification for embedded objects but not for linked objects, because the server library intercepts the notification for linked objects.