Binding Scribble’s Commands

This topic explains the issues and procedures involved in binding Scribble’s Clear All and Thick Line commands to their handlers using WizardBar. (You’ll bind the Pen Widths command in Adding a Dialog Box, Lesson 7.)

Which Command-Target Class Gets the Handler?

Before you can bind Scribble’s Clear All command to a message-handler function in the document class, you must solve some problems. Where should you put the handler for a command? Where should you put attributes, such as a line thickness value? In the document class? In the view class? Somewhere else?

Scribble has one document class (some applications might have several kinds of documents — such as text documents and graphics documents) and one view class (some documents might have more than one way to view their data — for example, as text or as an outline).

Scribble’s Clear All command has two effects: It deletes data in the document and it causes the view to be redrawn with no strokes. Should the handler for Clear All be located in the document or the view? Scribble’s CScribbleDoc class houses the application’s data structure, the stroke list. Clear All’s primary effect is to delete the data. Redrawing the view afterward is secondary. Hence, it makes sense to locate the OnEditClearAll handler in the document.

Scribble’s Thick Line command toggles the current value of a line thickness variable between thick and thin. Should the handler for Thick Line be located in the view because it affects how Scribble’s data is drawn? This seems reasonable, but consider what happens when, in Adding Splitter Windows, in Lesson 8, Scribble gets splitter window functionality. In that case, each pane of the splitter window is really a new view on the same data. Should each of these views house its own line thickness information (and its own pen)? A better solution is to store that information in the document instead, where all of the views can access it.

This decision is specific to Scribble’s user interface, where the pen width commands should apply to all views, not just the one with the current focus. You could organize things differently in another application. This type of program flow is up to you.

Consider a hypothetical application with more than one view on a document and perhaps even more than one frame window for the same document. Should handlers and attributes be part of the document, part of one of the frame windows, or part of one of the views? Should an attribute be duplicated in more than one view or frame window?

Here are some guidelines: