[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl-Toolbox] Event Handling Basics



I am trying to understand how one handles updating of windows, and in the 
process of looking through the MacPerl book, and the online MacPerl help
have become confused:

1) The MacPerl book makes reference to a 'sethook()' function, beginning on
page 199, and is used to 'set' and event handler:

     $win->sethook('redraw' => \&draw_it)

(I am guessing that a reference to the subroutine draw_it is used due to
some 'order of execution' issue, for lack of a better term. That is, if one
were to place a call to draw_it instead, it would try to execute
immediately, instead of at run-time)

I cannot find the 'sethook()' function (method) in the Mac::Events, or
Mac::Windows online help (or in the corresponding .pm files). I understand
the examples of its use, but was wondering if it is documented anywhere?

2) The examples in the MacPerl book imply that redrawing a window consists
of re-executing the subroutine that drew the contents of the window
initially when the 'redraw' event is detected.  By extension, the
implication is that one has to have 'control' over the window's contents
(i.e, have created the window's content in the first place).  Can one update
(redraw) a window that one has not created the contents, like an "Open" or
"Save" dialog box?

Specifically, what I am trying to do is update a Navigation Services
(Navigation.pm) 'NavGetFile' window, and I'm stuck.  I have found that
simply by placing a dummy event-handling subroutine in the NavGetFile call:

     NavGetFile($defaultLocation, $dialogOptions, $typeList, sub {});

that the dialog box becomes movable and resizable (NavPutFile comes this way
by default, and also seems to 'announce' itself as such, since Default
Folder 3.0.1 modifies the navigation buttons, and adds its own).  So, taking
the advice in Inside Macintosh, I wanted to write a simple subroutine to
handle the updating of the window.

So, I went looking in the Mac::Windows module for a function(s) to do this,
and initially only found the 'BeginUpdate()' and 'EndUpdate()' functions,
but nothing to put between them. But, the MacWindows class seemed to have
two that might be useful, 'redraw' and/or 'update'.

Unsuccessfully, I somewhat blindly tried the following, hoping it would
'connect' the NavGetFile's GrafPtr to a new MacWindow object:

   $inputFiles = NavGetFile($defaultLocation, $dialogOptions, $typeList,
                \&eventProc);
   if (!$inputFiles) {exit}

   sub eventProc()
   {
     my $whatEvent = $_[1]->event->what;
     my $windowID = $_[1]->window;
     my $windowMac = new MacWindow(GetWMgrPort());
     if ($_[0] == kNavCBEvent)
     {
       if ($whatEvent == updateEvt)
       {
         BeginUpdate($windowID);
         $windowMac->redraw;
         EndUpdate($windowID);
       }
     }
   }

I am not sure if this is the best approach, or even a valid one (!), but it
brought a couple of questions to mind:

a) Can one update (redraw) a window that one has not created the contents?
(repeated from earlier to keep all ?'s together)

b) Can a MacWindows object utilize all the constants and functions in the
Mac::Windows module, or only the ones pertaining to it?

b) $macWindow->window "Returns the underlying toolbox GrafPtr" of the
window, is there a way to take an existing window's GrafPtr and associate it
with MacWindows object, so the method's defined for the class can be used?
(I was hoping, praying that my $windowMac = new MacWindow(GetWMgrPort())
might do it, but I don't think it worked).

Any and all instructive comments, leads, or solutions are gratefully
welcomed.


----------------------
Mark J. Yannuzzi
myannuzzi@aya.yale.edu

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-toolbox-request@macperl.org