TCL Quicktime
Volume Number: 9
Issue Number: 6
Column Tag: TCL workshop
The Compiler Knows 
The TCL undo mechanism - How do you undo?
By John A. Love, III, MacTech Magazine Regular Contributing Author
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
About the author
John is a member of the Washington Apple Pi Users’ Group from the greater
Washington D.C. metropolitan area and can be reached on America Online {John Love}
and on GEnie {J.LOVE7}. Take note that John appears to be more rested for this article,
although he apparently succumbs at the very end.
This series
The purpose of this continuing series is to laboriously trace through the source
code of Symantec’s THINK Class Library (TCL) that serves as the Object Oriented
Programming (OOP) arm of their Pascal and C compilers to provide the answers to
the age-old question, “Who does what to whom?”.
Forrest Tanaka and Sandy Mossberg wake up, this one’s for you also!!!
This article ...
In the first of my “TCL Knick-Knacks” series (August 1992) I addressed what I
considered the basics inherent to programming using the TCL:
• creation and initialization of an application object.
• creation and initialization of the all-purpose Event Loop.
• starting up your application.
• running and running and running and ... that Event Loop until you quit the
application.
• creation of the document object(s) that the application object supervises.
• creation of the MENUs.
• implementation of MENU commands such as “Save” and “Copy”.
• handling of Desk Accessories.
Several months later (November 1992) I described how Tear-Off Menus are
created primarily because I just out-and-out think they’re neat and also because I
opened my big mouth and promised I would in the August article.
This month I think I should return to basics this time exploring how the TCL
implements the notorious “Undo” Menu command. I might add that Neil is very
thankful TCL’s implementation of “Undo” is relatively straightforward (translate
“requires relatively few words to describe”). [Concise explanations - the dream of
every editor. - Ed.]
A commercial break
You will notice that both the source code fragments as well as the surrounding
explanation address QuickTime™ movies. The reason is very simple ... they’re directly
extracted from my new CQuickTime, CMovie and CMovieEditTask classes which are
included within my “CQuickTime.sea” package uploaded to both GEnie and America
Online. So what are you waiting for?
And now we return to our regularly scheduled program(ming)
I will talk about the specifics of QuickTime™ only as they affect the task at hand,
namely “Undoing”. But first some generalities
With only slight modification by yours truly, here’s what Symantec’s
“Object-Oriented Programming Manual” states:
“The TCL uses the abstract class CTask (sub to CObject) to implement undoable
actions. For every undoable action you want in your application, you need to create a
subclass of CTask.
“After you perform an action, you create a new CTask and initialize it. Within
your ITask method, you store enough information to undo it in your added CTask’s
instance variables. Then you pass the newly created CTask to your supervisor (e.g., a
CDocument) in a Notify message. CDocument:::Notify stores the passed CTask into
CDocument::lastTask after it disposes of the previously stored lastTask. When you
choose Undo from the Edit Menu, CDocument::DoCommand does the following:
/* 1 */
void CDocument::DoCommand (long theCommand)
{
switch (theCommand)
{
// etc.
case cmdUndo:
if (lastTask != NULL)
{
if (undone)
lastTask-> Redo();
else
lastTask-> Undo();
undone = !undone;
UpdateUndo();
}
break;
default:
inherited::DoCommand(theCommand);
break;
} /* end: switch */
}
Well I guess my modifications are more than just slight let’s live with them
anyway and explore the words in detail.
When TCL’s CDocument::IDocument is called, CDocument’s instance variable =
lastTask is initialized to NULL. How does CDocument’s IDocument get called? Answer
when any of the following occurs:
1) When the user double-clicks on one of your app’s documents to start up the
application. CApplication::Run calls CApplication’s Preload which will then call
CApplication::OpenDocument wherein IDocument should be called.
2) When the user double-clicks on the app itself for start up. Preload will not call
OpenDocument in this case because numPreloads returned from _CountAppFiles =