TweetFollow Us on Twitter

Summer 91 - PRINT HINTS FROM LUKE & ZZ

PRINT HINTS FROM LUKE & ZZ

HELP FOR YOUR DIALOG APPENDAGES

PETE "LUKE" ALEXANDER and Zz

[IMAGE Luke+Zz.GIF]

Zz speaks

OK, so you're cruising your source like a madman trying to get all those little System 7.0 changes in before that target ship date (whatever it is this week), and you notice that the items you've added to the Page Setup/Print dialogs don't have any Balloon HelpTM--you know, those items like Reverse Pages, Print Hidden Text, or even Use Fractional Font Widths. (Coming up with meaningful names for these items, in four words or less, was a little tricky.) But now there's help, literally, in System 7.0. Great! Then you remember that there wasn't a simple Printing Manager call to add those items to the dialogs. You had to resort to the technique described in Technical Note #95, How to Add Items to the Print Dialogs. As you remember, it used a set of procedures that modified the Printing Manager's (that is, the selected print driver's) dialog item list (DITL) resource.

Remembering the actual code in Tech Note #95, you consider that the Standard File package shipped with 7.0 has a new call that allows you to append things to its dialog, including Help Manager resources. Feeling relieved, you think, "Ah, there must be a similar call in the new Pri . . ." But no, the new printing architecture has been delayed. A quick scan shows that there isn't even a Printing Manager chapter inInside Macintosh Volume VI! Help!!! It's not as bad as you might expect. If you consult Tech Note #95, you'll see the rather husky AppendDITL procedure. This procedure is called to append the items that you want to add to the dialog item list being used by the particular dialog (Page Setup or Print).

The sample code from Tech Note #95 calls some Printing Manager routines that let you get in after the DITL resource has been loaded, but before the dialog has been displayed. You add your items to the resource in memorywithout calling either ChangedResource or WriteResource. The driver then uses this DITL and displays your items. Once the dialog is dismissed, the resource is purged, and the driver doesn't even know you were there. Life is good.

As you've probably guessed by now, you're going to have to append to the Help Manager dialog item help ('hdlg') resource in the same way that you appended to the DITL resource. You simply scan the list to the end, and then append the appropriate items. The 'hdlg' resource is purged in the same way as the DITL resource, so once again you make no permanent changes.

On the next page is the definition of the Append2hdlg procedure. We start by getting both 'hdlg' resources into memory. It's safe to assume the source 'hdlg' resource hasn't been loaded yet, but we use the SetResLoad trick on the destination in case it has already been loaded. (The SetResLoad trick is a method for determining whether a resource has already been loaded. This trick is important, since in cases where the resource has already been loaded by the system, you don't want to unload it or permanently change any of its resource attributes.) The trick works like this: You SetResLoad to false so that the Resource Manager doesn't load the resource data; instead, it just creates an empty resource handle that can be passed to routines like GetResInfo. You then call GetResource on the resource you're looking for. If the handle returned is empty (that is, points to nil), you know the resource isn't already in memory. If the handle returned is not empty, something else (like the system) has already loaded it before you called GetResource. In this example, since we use HGetState and HSetState to preserve the resource attributes, and we want the resource to be left in memory when we're done, we don't really need to know if it was already loaded. The SetResLoad code is included for anyone who is planning on modifying this code to do more.

Next we initialize our locals. We want to point srcPtr to the place in the source resource that we want to start copying from. To do this, we need to point past the "missing item." The size of the item is stored in the resource just after the resource header. We first use srcPtr to get the size (in bytes) of the missing item. Using that size, we can calculate the starting location for the copy. We don't actually initialize srcPtr yet, since resizing the destination handle could move memory. Next we initialize dstPtr and dstLength. In the process, we resize dstHdl to make room for the items we're going to append. Once SetHandleSize has been called, we also initialize srcPtr. Now that srcPtr and dstPtr are set up, we use BlockMove to copy the new items into the destination resource. After unlocking the resource handles, we update the numItems field of the destination resource so that the Help Manager will know how many items we added. Finally, we release the source resource. We don't want to release the destination, since our changes would then be lost.

void Append2hdlg(srcResID, dstResID)
short   srcResID, dstResID;
{
    Handle              srcHdl, dstHdl;
    Ptr                 srcPtr, dstPtr;
    short               srcLength, dstLength;
    short               missingItmSz;
    SignedByte      dstHState;
    
    srcHdl = GetResource('hdlg', srcResID); 
    if (srcHdl != nil) {
        SetResLoad(false);  /* System resource, make sure it's not */
        dstHdl = GetResource('hdlg', dstResID); /* already loaded. */
        SetResLoad(true);
        if (*dstHdl == 0)
            dstHdl = GetResource('hdlg', dstResID);
        dstHState = HGetState(dstHdl);
        
        if (dstHdl != nil) {
            srcPtr = (Ptr)*srcHdl + sizeof(hdlgHeader);
            missingItmSz = *((IntPtr)srcPtr);
            srcLength = GetHandleSize(srcHdl) - (sizeof(hdlgHeader)
                - missingItmSz);

            dstLength = GetHandleSize(dstHdl);
            SetHandleSize(dstHdl, dstLength + srcLength);
            if (MemError() != noErr) {
                DebugStr("\pMemError");
                            /* Use this error handler, go to jail. */
                ExitToShell();              /* It's the law! */
            }
            dstPtr = (Ptr)*dstHdl + dstLength;
            srcPtr = (Ptr)*srcHdl + sizeof(hdlgHeader) +
                missingItmSz;

            HLock(srcHdl);
            HLock(dstHdl);

            BlockMove(srcPtr, dstPtr, srcLength);

            HUnlock(srcHdl);
            HSetState(dstHdl, dstHState);

            ((hdlgHeaderPtr)*dstHdl)->hdlgNumItems +=
                ((hdlgHeaderPtr)*srcHdl)->hdlgNumItems;
        }
    }
    ReleaseResource(srcHdl);
}

So that's about it. Append2hdlg is a lot smaller than AppendDITL because we don't actually need to parse the contents of the 'hdlg' resource. Although it's another piece of code to be added to your application, this should be quite painless, unlike other Printing Manager exercises. Don't forget to read the Help Manager chapter of Inside Macintosh Volume VI for guidelines on the contents of your Help Manager balloons. See ya next time . . .


SCOTT "ZZ" ZIMMERMAN loves Disneyland--we think it's because he's really a cartoon character at heart. When asked, he admitted to wanting to be Captain Hook when he grew up. His favorite ride is Peter Pan because it's romantic, cool, dark, and the main character is a kid who never grew up. Except for the romantic, cool, and dark parts, it reminds him a lot of life at Apple. When he's at Apple he makes sure he drinks at least 15 gallons of Mountain Dew a day--he says it powers the mechanism for his retractable Barbie Doll hair. In closing, we'll leave you with his favorite question, "How can I miss you if you won't leave?"*

For more information on the format and use of the "missing item" in an 'hdlg' resource, and much more about Balloon Help, see the Help Manager chapter in Inside Macintosh Volume VI. *

 
AAPL
$517.96
Apple Inc.
-3.72
MSFT
$39.75
Microsoft Corpora
+0.57
GOOG
$536.44
Google Inc.
+3.92

MacTech Search:
Community Search:

Software Updates via MacUpdate

Starcraft II: Wings of Liberty 1.1.1.180...
Download the patch by launching the Starcraft II game and downloading it through the Battle.net connection within the app. Starcraft II: Wings of Liberty is a strategy game played in real-time. You... Read more
Sibelius 7.5.0 - Music notation solution...
Sibelius is the world's best-selling music notation software for Mac. It is as intuitive to use as a pen, yet so powerful that it does most things in less than the blink of an eye. The demo includes... Read more
Typinator 5.9 - Speedy and reliable text...
Typinator turbo-charges your typing productivity. Type a little. Typinator does the rest. We've all faced projects that require repetitive typing tasks. With Typinator, you can store commonly used... Read more
MYStuff Pro 2.0.16 - Create inventories...
MYStuff Pro is the most flexible way to create detail-rich inventories for your home or small business. Add items to MYStuff by dragging and dropping existing information, uploading new images, or... Read more
TurboTax 2013.r17.002 - Manage your 2013...
TurboTax guides you through your tax return step by step, does all the calculations, and checks your return for errors and overlooked deductions. It lets you file your return electronically to get... Read more
TrailRunner 3.8.769 - Route planning for...
Note: While the software is classified as freeware, it is actually donationware. Please consider making a donation to help support development. TrailRunner is the perfect companion for runners,... Read more
Flavours 1.1.10 - Create and apply theme...
Flavours is a Mac application that allow users to create, apply and share beautifully designed themes. Classy Give your Mac a gorgeous new look by applying delicious themes! Easy Unleash your... Read more
Spotify 0.9.8.296. - Stream music, creat...
Spotify is a streaming music service that gives you on-demand access to millions of songs. Whether you like driving rock, silky R&B, or grandiose classical music, Spotify's massive catalogue... Read more
SlingPlayer Plugin 3.3.20.475 - Browser...
SlingPlayer is the screen interface software that works hand-in-hand with the hardware inside the Slingbox to make your TV viewing experience just like that at home. It features an array of... Read more
S.M.A.R.T. for USB and FireWire Drives 0...
S.M.A.R.T. for USB and FireWire Drives is a kernel driver for OS X external usb or firewire drives. It extends the standard driver behaviour by providing access to drive smart data. The interface to... Read more

Latest Forum Discussions

See All

148Apps Live on Twitch: Pivvot’s Looper...
On our latest Twitch stream, we’ll be playing a pair of minimalist arcade games, one that just got a big content update in Pivvot, and another that was inspired by it in 15 Coins. Whitaker Trebella, creator of Pivvot, will discuss the new modes... | Read more »
Word Cubes Review
Word Cubes Review By Jordan Minor on April 15th, 2014 Our Rating: :: SQUARESVILLEUniversal App - Designed for iPhone and iPad Word Cubes is fine, but it is barely any different from any other word game.   | Read more »
PAX East 2014 – Desert Fox: The Battle o...
PAX East 2014 – Desert Fox: The Battle of El Alamein is Coming to iOS Soon Posted by Rob Rich on April 15th, 2014 [ permalink ] Shenandoah Studio has become one of the go-to developers for war games on iOS, with | Read more »
Tank of Tanks Review
Tank of Tanks Review By Carter Dotson on April 15th, 2014 Our Rating: :: TANKS A LOT!iPad Only App - Designed for the iPad This multiplayer game played on a single iPad is simple, chaotic fun.   | Read more »
PAX East 2014 – Dungeon of the Endless J...
PAX East 2014 – Dungeon of the Endless Just Might Have a Shot at an iPad Release Posted by Rob Rich on April 15th, 2014 [ permalink ] I think it’s fair to say that | Read more »
SideSwype Review
SideSwype Review By Carter Dotson on April 15th, 2014 Our Rating: :: ON YOUR SIDEUniversal App - Designed for iPhone and iPad SideSwype is a puzzler that takes inspiration from Threes, but becomes its own incredibly fun game.   | Read more »
PAX East 2014 – Bigfoot Hunter Invites P...
PAX East 2014 – Bigfoot Hunter Invites Players on a Wild and Wooly Photo Safari Posted by Rob Rich on April 15th, 2014 [ permalink ] Yeti. Sasquatch. Wendigo. | Read more »
Dungeon Quest Review
Dungeon Quest Review By Cata Modorcea on April 15th, 2014 Our Rating: :: NO STORY, BUT GOOD FUNUniversal App - Designed for iPhone and iPad Dungeon Quest does a lot of things right, but ultimately forgets about one of the core... | Read more »
Tempo AI and Speek Join Forces to “Kill...
Tempo AI and Speek Join Forces to “Kill the Conference Call PIN” Posted by Rob Rich on April 15th, 2014 [ permalink ] Today Tempo AI, makers of Tempo Smart Calendar, and | Read more »
Fighting Fantasy: Starship Traveller Rev...
Fighting Fantasy: Starship Traveller Review By Jennifer Allen on April 15th, 2014 Our Rating: :: A SIGNIFICANT VOYAGEUniversal App - Designed for iPhone and iPad Continuing the release of Fighting Fantasy titles, Starship Traveller... | Read more »

Price Scanner via MacPrices.net

Save $50 on Mac mini Server
B&H Photo has the 2012 Mac mini Server on sale for $949 including free shipping plus NY sales tax only. Their price is $50 off MSRP. Read more
PhatWare’s “Ultimate Writing App For iOS” Ren...
PhatWare Corp. has announced it has renamed its new WritePro word processing app for iPhone and iPad: WritePad Pro. The decision to change the app’s name to leverages the strong brand awareness and... Read more
Full Resolution Photo Editor Tint Mint 1.0 Re...
California based independent developer, Jeffrey Sun, creator of the iOS app Modern Editor, has released Tint Mint, a new photography app for editing enthusiasts. The app costs a dollar, and it packs... Read more
16GB iPad mini (Apple refurbished) available...
The Apple Store has refurbished 1st generation 16GB iPad minis available for $249 including free shipping. Both black and white models are available. Read more
Save $120 on the 27-inch 3.2GHz Haswell iMac
B&H Photo has the 27″ 3.2GHz iMac on sale for $1679.99 including free shipping plus NY sales tax only. Their price is about $120 off MSRP. Read more
Using a Mac Doesn’t Eliminate The Heartbleed...
Low End Mac’s Dan Knight notes that any time you visit a website with an https: prefix or see that secure lock icon on your browser, some type of security software is busy trying to protect your data... Read more
AirPrint Basics Tutorial Posted
A new Apple Knowledge Base article helps get you started using AirPrint, the Apple protocol that enables instant printing from iPad, iPhone, iPod touch, and Mac without the need to install drivers or... Read more
Speed Tips For Running LibreOffice On The Mac
LibreOffice is my favorite of several free, open-source application suites, and the one I have configured on my Mac as my default app for Word documents that one frequently has to deal with. It also... Read more
Snag a 15-inch Retina MacBook Pro for $115 of...
B&H Photo has 2013 15″ Retina MacBook Pros on sale for up to $115 off MSRP for a limited time. Shipping is free, and B&H charges NY sales tax only: - 15″ 2.3GHz Retina MacBook Pro: $2489.99... Read more
MacBook Airs on sale for $50 to $100 off MSRP
Several resellers are offering $50-$100 discounts on 11″ and 13″ MacBook Airs today, including Amazon, Best Buy, B&H, and others. See the breakdown of deals on our MacBook Air Price Tracker,... Read more

Jobs Board

Position Opening at *Apple* - Apple (United...
**Job Summary** Every day, business customers come to the Apple Store to discover what powerful, easy-to-use Apple products can do for them. As a Business Leader, Read more
Position Opening at *Apple* - Apple (United...
…challenges of developing individuals, building teams, and affecting growth across Apple Stores. You demonstrate successful leadership ability - focusing on excellence Read more
Position Opening at *Apple* - Apple (United...
…Summary** As a Specialist, you help create the energy and excitement around Apple products, providing the right solutions and getting products into customers' hands. You Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** The Apple Store is a retail environment like no other - uniquely focused on delivering amazing customer experiences. As an Expert, you introduce people Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** Being a Business Manager at an Apple Store means you're the catalyst for businesses to discover and leverage the power, ease, and flexibility of Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.