December 95 - Macintosh Q & A
Macintosh Q & A
QHow do I determine whether a Power Macintosh has PCI expansion slots?
A If there's a Name Registry, you can use it to determine whether a PCI bus exists.
To determine whether the Name Registry exists, use the new Gestalt selector
gestaltNameRegistryVersion ('nreg'). If the Name Registry exists, the value returned
is the version number of the Registry; otherwise, gestaltUndefSelectorErr is
returned, and you can assume that the machine doesn't have PCI slots.
If the Name Registry exists, call RegistryEntrySearch to look for an entry having a
property name of device_type and a propertyValue of pci. If an entry is found, there is
a PCI bus on the machine.
QOur software doesn't awaken properly on a PowerBook that has come out of sleep
mode. Are there any special handling requirements to recover from sleep mode?
A The changes to the system state when a PowerBook goes to sleep include the
following:
• All AppleTalk connections are lost, because the AppleTalk driver is turned
off.
• The serial ports are entirely shut down to conserve power.
There are two Macintosh Technical Notes that relate to your situation: "Little
PowerBook in Slumberland" (HW 24), which provides a brief overview of the sleep
process, and "Sleep Queue Tasks" (HW 31), which presents additional material
regarding the sleep process. The second one includes sample code that demonstrates a
sleep queue task implementation. The sleep queue task enables your program to save
state information that otherwise might be lost. Typically, this is important for a
networked process that needs to reestablish a connection upon awakening.
QCan we define our own extensions to QuickTime's ImageDescription structure? In
other words, can we just attach any kind of data to the end of the ImageDescription
structure? Our codec would use this data only on the Macintosh.
A Yes, you can add any extended data you like, with the utility routines provided for
this purpose (described in Inside Macintosh: QuickTime Components, starting on page
4-65). You have complete control over how your codec interprets the extensions.
Therefore, as long as the default image description handle remains intact (for the
benefit of the various Movie Toolbox calls that depend on the documented structure
being there), you can add whatever information you like. Note that Apple reserves all
extension types consisting entirely of lowercase letters.
QWe're trying to write a QuickTime codec, but we're having trouble because Inside
Macintosh: QuickTime Components was written before the universal headers, and the
sample codec source doesn't build at all with the latest headers. Where can we get a
QuickTime codec that builds for PowerPC under the current universal headers?
A Until a PowerPC-native codec example becomes available, you can get the
information you need from the Macintosh Technical Note "Component Manager version
3.0" (QT 5), which provides details on creating native components. Note that you have
to use Resorcerer or Rez to create the component templates; ResEdit won't suffice.
QOur codec needs to provide more options to the user than the normal
image-compression dialog contains. The documentation suggests that it's possible to
provide an extra Options button in the dialog, and I've seen some applications that do
provide an Options button for certain codecs. Is this a function of the application? How
does the application know to do this?
A If your codec component has an exported function named CDRequestSettings, the
standard image-compression dialog will automatically provide the specific button. In
other words, QuickTime checks the codec component, adds the button (provided it's
available), tracks clicks in the button, and calls your CDRequestSettings routine
appropriately. For further details, see the Macintosh Technical Note "QuickTime 1.6.1
Features" (QT 4) where CDRequestSettings is documented.
QWe have a non-Macintosh device that creates and reads QuickTime movies, and we
need to pass additional information about the images between the non-Macintosh device
and our QuickTime codec. It seems that the logical place to put this information is in an
ImageDescription extension (within the sample description atom), since this is about
all that's accessible to a codec. Is the format of this extension documented anywhere?
We've looked at the extension created by SetImageDescriptionExtension, and the format
seems simple, but it would be nice to know what the "official" format is.
A Chapter 4 of Inside Macintosh: QuickTime has a listing of the atoms and their
formats. Sample description atoms are described on page 4-35. Note that each media
format has its own sample description tables, which are not directly accessible.
The official guideline is to use, if possible, the provided APIs for creating sample
description atoms. If you're working on a platform for which there are no Toolbox
APIs, you'll have to obtain a source-code license agreement to get real source code
showing how the atoms are constructed. (For details regarding licensing part or all of
the QuickTime source code, contact Apple Software Licensing at AppleLink SW.LICENSE
or (512)919-2645.)
QOur application plays QuickTime movies. Some older movies played well in System
7.1, but they don't play properly in System 7.5 or 7.5.1. We happened to find the
Apple Multimedia Tuner, and it solves the problem. What is the Apple Multimedia
Tuner, who needs it, how does a customer get it, and can we distribute it?p>A The
real solution to your problem is just to preroll the movie before playing it, which is
what the Apple Multimedia Tuner is doing for you. QuickTime 2.1 incorporates all the
Tuner improvements, so there's no longer any need to distribute the Tuner separately.
QWe have a problem when we draw to an offscreen GWorld under low-memory
conditions (when the system heap can't grow) on a Power Macintosh. The GWorld
drawn contains digital noise. The same code works just fine in an 680x0 environment.
Any idea what's happening?
A It sounds as if the Code Fragment Manager is unable to load the code from the
PowerPlug library into temporary memory. This will cause QuickTime to issue a
noCodecErr error. You should always try to catch QuickTime-generated errors,
checking, for instance, for playback errors after each MoviesTask call like this:
anErr = GetMoviesStatus(Movie theMovie, Track *problemTrack);
Here's a possible workaround to your problem: Launch a small application that has the
QuickTimeLib (PowerPlug) library statically linked in, so that it's loaded. This
application should launch the main application and then kill itself. The second
application could try to grow to a predefined size and handle low-memory conditions in
whatever way it wants, but the CFM libraries are already in memory by then.
The Code Fragment Manager will never load fragments into an application heap,
because there's a global registry of CFM libraries present. If another application
registers to use a CFM library that's in an application heap that subsequently goes
away, this will obviously be a Bad Thing. In the 680x0 environment, the codecs are
components, and the Component Manager will always try to load components into the
application heap if the system heap doesn't have any available space.
QI need to add print items to a QuickDraw GX dialog box. In attempting to use the
Experiment no.9 sample, I found what appears to be a bug. This example uses
GXGetMessageHandlerResFile when it calls GXSetupDialogPanel, but it should call
CurResFile.
A You're right. Applications should call CurResFile. GXGetMessageHandlerResFile is
reserved for extensions and drivers.
For additional code examples that add print items to a QuickDraw GX dialog box, see the
Worldwide Developers Conference 1995 Technology CD (or the Mac OS Software
Developer's Kit). The Extension Shell, UserItems, and Additions samples provide the
basic item adding/handling code that you require.
QWhere can I find some good sample code that demonstrates the techniques required for
a "panel" with QuickDraw GX printing (as an application -- not an extension)?
A There are two sample applications ("Experiment no.9" and "Banana Jr.") that
show how to do this. In both of these applications, the panels appear in the Custom Page
Setup dialog. However, the sample code can easily be modified to add panels to the Page
Setup and Print dialogs.
QHow can I draw and print hairlines with QuickDraw GX? We use a picture comment in
the normal print code, but this seems to make QuickDraw GX fail. We get a -51 error
(reference number invalid) when we call GXGetJobError after calling GXFinishJob,
and we sometimes get this error without the picture comment code.
We also tried calling GXSetShapePen in our spool procedure. When we set it to a
fractional value, we get a wide line, but when we set it to a wide value, such as 8, it
works properly. What do we need to do to print fractional widths?
A Here are two ways to get QuickDraw GX to draw hairlines when printing:
• Call GXSetShapePen(myShape, 0). This sets your pen width to 0, meaning
as thin as possible on the output device. QuickDraw GX always draws hairlines
at the resolution of the output device -- one pixel wide.
• Call GXSetStylePen(myStyle, 0). This also sets your pen width to 0, with
the same result.
When using GXSetShapePen and GXSetStylePen, don't specify the pen width as an
integer: remember that it's a fixed-point value. GXSetStylePen(myStyle, 1) sets the
pen width to 1/65536; GXSetStylePen(myStyle, ff(1)) sets it to 1.0.
QuickDraw GX uses a backing store file (an invisible file within the System Folder) to
send QuickDraw GX objects to disk when additional space is needed within the
QuickDraw GX heap. Almost all -51 errors from within QuickDraw GX or an
application using QuickDraw GX are caused by double-disposing of a QuickDraw GX
object (that is, a shape, ink, style, or transform). The -51 error occurs because the
double dispose causes QuickDraw GX to set the shape attributes, which indicates that it
has sent the object to disk. When it needs this object, it goes to the backing store and
tries to get it, but it's not there. We've found a few cases where QuickDraw GX itself
was double-disposing of objects, and these were fixed in QuickDraw GX version 1.1.
Before calling GXDrawShape, call GXValidateShape on the shape or shapes you're trying
to print. This ensures that a shape is valid before it's drawn or printed. It slows things
down a little, but you'll be able to determine whether a shape is still available before
you attempt to draw it (you might be disposing of a shape before you draw it). If you
have an error handler installed, you usually receive the "shape_already_disposed
message, but you may not receive this message if something is wrong with the
QuickDraw GX backing store.
It's also possible that the hairline drawing problems you're encountering are related
to the translation options you're using. A translator takes your QuickDraw drawing
commands and converts them to QuickDraw GX objects, based on options you provide. If
you use the gxDefaultOptionsTranslation setting, a QuickDraw line turns into a
six-sided filled polygon. When your object is a polygon, changing the pen width has no
effect.
To avoid translation problems, call GXInstallQDTranslator with the
gxSimpleGeometryTranslation or the gxReplaceLineWidthTranslation option.
• gxSimpleGeometryTranslation turns on both the simple-lines and
simple-scaling translation options, and it translates QuickDraw lines into
QuickDraw GX lines with flat endcaps. The QuickDraw GX line shape runs along
the center of the original QuickDraw line, and it covers all the pixels of the
QuickDraw line and more.
• gxReplaceLineWidthTranslation turns a QuickDraw line into a QuickDraw
GX line with a width that is the average of the original pen's width and height.
This option also affects the way the SetLineWidth picture comment is
interpreted.
Once you set the translation option, your calls to GXSetShapePen or GXSetStylePen
should behave as you expect them to, because they're acting on QuickDraw GX lines, not
polygons. When you've installed a translator, be sure to remove it with
GXRemoveQDTranslator. To learn more about the translation options, see Chapter 1 of
Inside Macintosh: QuickDraw GX Environment and Utilities.
QI'm trying to send messages from within a QuickDraw GX message override. I want to