Draw Application Methods
In addition to the *RegTool
, *RegPatterns
, and *RegStamps
methods, and their unregistering counterparts discussed elsewhere in this chapter, the Draw application's viewDef contains three other methods of interest: *GetContents
,*SetContents
, and *GetCanvas
. The *GetContents
and *SetContents
methods are used to manipulate the entire contents of the current drawing.The *
GetCanvas
method returns a reference to the canvas view; a number of methods are defined in this view which are available to you. For more information on the canvas view, see "The Canvas and Its Methods".The way you get a reference to the Draw application viewDef, to send these methods to, depends on the environment in which your code is executing.
- If you are writing code for a tool, this code executes as a child of the canvas. In this case you can send these methods to
self
. The Draw application is found via parent inheritance, as in the following sample calls::GetContents();
:GetCanvas();
- If you are writing code for a tool to be added to the Tools picker, with the Newton Works *
RegNewtWorksTool
method, this code executes in the environment of Newton Works, not its Draw application viewDef. In this case, send these messages to theviewDefView
slot, as in the following sample calls:viewDefView:GetContents();
viewDefView:GetCanvas();
- If your code is executing outside these environments, you can get a reference to the Draw application by explicitly accessing Newton Work's
viewDefView
slot. However, in this case it is not guaranteed that the Draw application is the current displaying viewDef; you must check for this before sending these messages, as in the following code:if GetRoot().newtWorks AND Visible(GetRoot().newtWorks) then
begin local curNWApp := GetRoot().newtWorks.viewDefView; if GetVariable(curNWApp, 'currentdatatype) = 'drawPaper then begin local cont := curNWApp:GetContents(); local can := curNWApp:GetCanvas(); ... end; end;
Main | Top of Section | What's New | Apple Computer, Inc. | Find It | Feedback | Help