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

[MacPerl] Using Mac:: '...' Modules



Greetings All,

These questions may turn out to be more generic than posed, thus the generic
"Subject" title of this e-mail.  I am new to writing Mac-specific code, and
have had success with some of the simpler functions in modules such as
Mac::Files, and Mac::StandardFile.

! This is a lengthy message, so if you are not interested, now is the time
to hit the delete button. !

What I am trying to do is display an "Open" dialog box and allow the user to
select one or more TEXT files for processing.  Therefore, I am trying to use
the Mac::Navigation module, but am having trouble figuring out how to
provide one of the required parameters of the NavGetFile function:

$inputFiles = NavGetFile(DEFAULTLOCATION, DIALOGOPTIONS, TYPELIST);

specifically, the TYPELIST parameter.  I have been reading "Programming With
Navigation Services 1.1" from Inside Macintosh (PWNS), the .pod files, the
MacPerl book, and have successfully figured out how to provide the first two
parameters, but I am STUCK on the third.

According to Inside Macintosh, the DEFAULTLOCATION is a "...pointer to an
Apple event descriptor structure (AEDesc)...If you pass NULL in this
parameter, Navigation Services defaults to the last location visited during
a call to the NavGetFile function.", so in the hopes of just getting some
default location, like the Desktop, or the last folder visited, I passed a
null string '', which appears to work.

Passing NULL to DIALOGOPTIONS is also supposed to use defaults, but passing
'' generates a  "# dialogOptions is not of type NavDialogOptions." error.
Being that in Perl one does not explicitly declare a variable's data type,
unlike in Pascal, or C, I found this error confusing, initially.  However, I
little more digging in PWNS yielded this tidbit regarding the
NavGetDefaultDialogOptions function: "This function gives you a simple way
to initialize a structure of type NavDialogOptions (page 85) and set the
default dialog box options before calling...", so I tried:

$dialogOptions = NavGetDefaultDialogOptions;

This appears to work fine, the only remaining question is how one
sets/resets the dialogOptionFlags field.  According to the example in PWNS,
this is done in C with bitwise ORing (inclusive and exclusive):

set:   dialogOptions.dialogOptionsFlags |= kNavSelectDefaultLocation;
reset: dialogOptions.dialogOptionsFlags ^= kNavSelectDefaultLocation;

but, in MacPerl, changing an object's data field takes the form:

$object->dataField('someData');

so, a little experimenting should yield whether setting/resetting
dialogOptionFlags should mimic the C-form, or maybe look like:

set:   $dialogOptions->dialogOptionsFlags(kNavSelectDefaultLocation);
reset: $dialogOptions->dialogOptionsFlags(!kNavSelectDefaultLocation);

HOWEVER, before I can do this, I need to provide a valid TYPELIST parameter,
which is of type NavTypeListHandle.  The info contained in the Navigation.pm
file suggests two forms for generating a scalar of this type:

1) $typeList = new NavTypeListHandle [RSRCTYPE, ] RSRCID; 
2) $typeList = new NavTypeListHandle APPSIG, [ TYPE ...];

Providing the parameters [RSRCTYPE, ] RSRCID or APPSIG, [ TYPE ...] is where
I have hit a wall.  The first form appears to correlate with a PWNS example
(with the exception of the resource type being optional):

typeList = (NavTypeListHandle) GetResource('open', 128);

So, I thought that I might need to somehow use Mac::Resources to retrieve an
'open' resource with the necessary info, which for my needs appears to be
simply some application signature, and the TEXT file type.  Assuming this
would work, it seems potentially troublesome, since I would always need this
resource file available for my script to work.

The second form prompted me to try the brain-dead approach:

$typeList = new NavTypeListHandle('McPL', 'TEXT');

which, not surprisingly, generated an error: # Argument "TEXT" isn't numeric
in entersub.

PWNS states "Native file types are those types you provide in the typeList
parameter...This parameter has the same format as an 'open' resource and may
be loaded from a resource or passed in as a structure created on the fly."

"...passed in as a structure created on the fly."  FLASH!  How does one do
this, specifically in a MacPerl script?  Inside Macintosh: More Toolbox has
the format of the 'open' resource as:

/*open resource for TeachText */
resource 'open' (128)
{
  'ttxt', { 'ttro', 'PICT', 'TEXT' }
};

in Rez input format, which is a program I have never used.

Basically, all I care about is getting the file type 'TEXT' into the
typeList parameter, the application signature is irrelevant, since I wish to
set the kNavSelectAllReadableItem option, which will display all files of
type TEXT and ignore the application signature.

Any and all insights, suggestions, etc. would be greatly appreciated.

Thanks for the patience...regards,
Mark
----------------------
Mark J. Yannuzzi
myannuzzi@aya.yale.edu

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