TweetFollow Us on Twitter

Jun 97 - Macintosh Q and A

Volume Number: 13 (1997)
Issue Number: 6
Column Tag: develop

Macintosh Q&A

by Apple Developer Support Center

Q: When I used CopyBits to do a screen capture, the cursor isn't included. Why not?

A: CopyBits calls ShieldCursor to hide the cursor before it does its work. That's why you never see the cursor in your screen capture. The following code hides the cursor and decrements the cursor count in the low-memory global to fool CopyBits not to call ShieldCursor. Standard warning: Using low-memory globals is dangerous and is subject to future OS changes.

unsigned char   oldCrsrVis;
short           oldCrsrState;
      
// Hide the cursor.
oldCrsrVis = GetCrsrVis();
oldCrsrState = GetCrsrState();
SetCrsrVis((unsigned char) 0);
SetCrsrState(oldCrsrState - 1);   
// Do the screen capture.
CopyBits(...)
      
// Restore the old cursor.
SetCrsrState(oldCrsrState);
SetCrsrVis(oldCrsrVis);

You should define the cursor functions as follows:

enum {
   CrsrVis = 0x8CC,      // Cursor visible? [byte]
   CrsrState = 0x8D0      // Cursor nesting level [word]
};
   
void SetCrsrVis(unsigned char cursorVisible)   
{
   *(unsigned char*)CrsrVis = cursorVisible;
}

unsigned char GetCrsrVis(void)
{
   return ( *(unsigned char*)CrsrVis );
}   

short GetCrsrState(void)
{
   return ( *(unsigned char*)CrsrState );
}   

void SetCrsrState(short val)
{
   *(unsigned char*)CrsrState = val;
}

Q: How can I determine whether the cursor is hidden?

A: Currently the best way to determine this is to use a low-memory global that has been removed from LowMem.h. The reason it has been removed is that a future operating system may handle it differently.

Using low-memory globals has never really been sanctioned, though they were documented in older interface files. The Universal Interfaces were designed to make way for future operating systems; access to some low-memory globals was provided through accessor functions for safety, while access to others was removed.

The global you want, CrsrVis, is a byte-sized flag that tells whether the cursor is hidden. It was defined in an older interface file like this:

enum {
   CrsrVis = 0x8CC,   // Cursor visible? [byte]
};

You can simply check this global to see if the cursor is hidden. As always, the direct use of low-memory globals is not recommended and will probably cause your code to break in the future.


Q: I want to support dragging from my application to the Trash without having the Finder create a clipping file inside the Trash. I tried several options but they all failed. Is this possible?

A: There is no good way to prevent a clipping file from being created in the Trash, or to prevent the "zoomback" animation that signals a failed drag. The problem is that the Finder treats the Trash like a folder; the drag succeeds or fails according to the user's supposed intent with respect to a folder.

In our opinion, however, this is good, since it's consistent with the Trash metaphor. When the user drags an icon from a Finder window into the Trash, she expects the Trash to get fat so that she can later change her mind, open the Trash, and drag the icon back out. Creating a clipping file in the Trash merely extends the metaphor. The only problem this might cause is that the user ought to be able to reverse her decision and drag the clipping back into the application. If your application doesn't already support this action, you may have some work ahead.

We realize that other applications manage to avoid making the Trash fat. This is, in our opinion, a Bad Thing. A Hack. Wrong. Nevertheless, if you still feel you need to avoid making the Trash fat, it might be possible to do so. It would probably involve creating a file via flavorTypePromiseHFS, then deleting it before the Finder has a chance to make the Trash fat. Unfortunately, since this involves "fooling" the Finder, it isn't likely to work for future versions of the Finder even if it does work today.

In short, this is not recommended.


Q: When my application calls TrackDrag, it crashes in low memory at an illegal instruction. The MacsBug stack crawl doesn't produce any useful information. I've stared and stared at my application's calls to the Drag Manager, and all the parameters appear to be valid. My drag tracking handler is never called, incidentally. If I take all calls to the Drag Manager out of my application, it runs just fine. I've been investigating this crash for two months. Why is life so cruel?

A: You've unearthed a really ugly problem. The Drag Manager thinks the drag originated in the Finder, and makes some fatal assumptions based on that.

Early versions of the Drag Manager did not enjoy the benefits of a drag-enabled Finder, so the Drag Manager plays a little fast and loose with the Finder's jump table. Yes, that means what it sounds like: the Drag Manager calls the Finder routines through its jump table.

The even more interesting story concerns the method by which the Drag Manager decides that the current application is the Finder. When TrackDrag is called, the Drag Manager determines whether the drag originates in any of the windows in the window list of the current process. If not, the Drag Manager determines whether the drag originates in any Finder window. Since the desktop is a "window" for these purposes, there's a large area that qualifies.

Once the Drag Manager has decided the drag originated in a Finder window, it assumes that the Finder is the current process. (This is the fatal mistake.) Once this assumption is made, the next thing for the Drag Manager to do to coax the Finder into exhibiting the correct drag behavior is call an entry in whatever jump table can be found by offsetting the current value of register A5. This is valid if the Finder is the current process, but of course if the current process is your application instead, things go terribly astray: The Drag Manager calls a jump table entry in your application, thinking it's the Finder, and your application's routine doesn't do the same thing that the Finder routine would. Any number of spectacular effects can result.

"Now wait a minute," you're thinking, "the drag originated in one of my application's windows; how is this stuff about the Finder relevant?" The answer is in the event record you're passing to TrackDrag. An event record is supposed to contain a where field expressed in global coordinates. However, the where field your application is passing is in local coordinates. How did this happen? Well, that depends on your application, but often it can result from an application frameworks (like PowerPlant, MacApp, or THINK Class Library) modifying the event record before passing it to your code. There's no language-level way to specify that the record has been modified, so the compiler doesn't warn you. (Honestly, this is Not Your Fault.)

Your code blithely calls TrackDrag with what it assumes is a valid event record but is not. TrackDrag interprets the where field, which is actually in local coordinates, as global coordinates. This point is somewhere up and to the left of where your application expects, and quite often it's in the desktop, which as we said above is considered a Finder window for these purposes. The Drag Manager reacts by going through its ritual for drags originating in Finder windows and eventually crashes after calling some odd routine in your application, as described above.

To solve this problem, simply call LocalToGlobal on the where field of the event record before calling TrackDrag.


Q: When I drag from my application into a Finder window, the system crashes. I notice the Finder uses a windowKind value of 20 for its windows, and so does my application. When my application avoids windowKind 20, everything's hunky-dory. What's going on?

A: Through the Drag Manager, the Finder has gotten access to the windows in your application's window list (specifically, by using undocumented calls to obtain the source window of a drag). If your window's windowKind field is 20, the Finder assumes the window is one of its own (as opposed to a driver window, whose windowKind would be negative, or a dialog window, whose windowKind would be 2, and so on). The Finder grabs the value in the window's refCon field and type-casts it to a pointer to a C++ object in the Finder's heap. I think you can see where this is going: when the Finder attempts to dereference the pointer, many fascinating crashing behaviors can result.

The upshot of this Finder bug is that your application should not use windowKind values of 20.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

NeoOffice 2014.7 - Mac-tailored, OpenOff...
NeoOffice is a complete office suite for OS X. With NeoOffice, users can view, edit, and save OpenOffice documents, PDF files, and most Microsoft Word, Excel, and PowerPoint documents. NeoOffice 3.x... Read more
DesktopLyrics 2.6.6 - Displays current i...
DesktopLyrics is an application that displays the lyrics of the song currently playing in "iTunes" right on your desktop. The lyrics for the song have to be set in iTunes; DesktopLyrics does nothing... Read more
Ember 1.8.3 - Versatile digital scrapboo...
Ember (formerly LittleSnapper) is your digital scrapbook of things that inspire you: websites, photos, apps or other things. Just drag in images that you want to keep, organize them into relevant... Read more
Apple iTunes 12.1 - Manage your music, m...
Apple iTunes lets you organize and play digital music and video on your computer. It can automatically download new music, app, and book purchases across all your devices and computers. And it's a... Read more
LibreOffice 4.4.3 - Free, open-source of...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
FoldersSynchronizer 4.2.1 - Synchronize...
FoldersSynchronizer is a popular and useful utility that synchronizes and backs-up files, folders, disks and boot disks. On each session you can apply special options like Timers, Multiple Folders,... Read more
Simon 4.0.2 - Monitor changes and crashe...
Simon monitors websites and alerts you of crashes and changes. Select pages to monitor, choose your alert options, and customize your settings. Simon does the rest. Keep a watchful eye on your... Read more
Cocktail 8.1.2 - General maintenance and...
Cocktail is a general purpose utility for OS X that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
Cyberduck 4.6.4 - FTP and SFTP browser....
Cyberduck is a robust FTP/FTP-TLS/SFTP browser for the Mac whose lack of visual clutter and cleverly intuitive features make it easy to use. Support for external editors and system technologies such... Read more
Herald 5.0.2 - Notification plugin for M...
Note: Versions 2.1.3 (for OS X 10.7), 3.0.6 (for OS X 10.8), and 4.0.8 (for OS X 10.9) are no longer supported by the developer. Herald is a notification plugin for Mail.app, Apple's Mac OS X email... Read more

Playworld Superheroes Review
Playworld Superheroes Review By Tre Lawrence on January 30th, 2015 Our Rating: :: HERO CRAFTINGUniversal App - Designed for iPhone and iPad It’s all about the imagination, fighting bad creatures — and looking good while doing so.   | Read more »
Join the SpongeBob Bubble Party in this...
Join the SpongeBob Bubble Party in this New Match 3 Bubble Poppin’ Frenzy Posted by Jessica Fisher on January 30th, 2015 [ permalink ] | Read more »
Handpick Review
Handpick Review By Jennifer Allen on January 30th, 2015 Our Rating: :: TANTALIZING SUGGESTIONSiPhone App - Designed for the iPhone, compatible with the iPad Handpick will make you hungry, as well as inspire you to cook something... | Read more »
Storm the Halls of Echo Base in First St...
Storm the Halls of Echo Base in First Star Wars: Galactic Defense Event Posted by Jessica Fisher on January 30th, 2015 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Contradiction Review
Contradiction Review By Tre Lawrence on January 30th, 2015 Our Rating: :: SPOT THE LIEiPad Only App - Designed for the iPad Contradiction is a live action point and click adventure that’s pretty engaging.   Developer: Tim Follin... | Read more »
Unlock Sunshine Girl in Ironkill with th...
Unlock Sunshine Girl in Ironkill with this special 148Apps code Posted by Rob Rich on January 29th, 2015 [ permalink ] Robo-fighter Ironkill has been out on iOS a | Read more »
Crossroad Zombies Review
Crossroad Zombies Review By Jordan Minor on January 29th, 2015 Our Rating: :: CROSSWALKING DEADiPad Only App - Designed for the iPad Crossroad Zombies is a rough draft of a cool genre mash-up.   | Read more »
Blood Brothers 2 – Tips, Cheats, and Str...
War is hell: Is it the kind of hell you want to check out? Read our Blood Brothers 2 review to find out! Blood Brothers 2, DeNA’s follow-up to the original Blood Brothers, is an intriguing card collecting / role-playing / strategy hybrid. There’s... | Read more »
Blood Brothers 2 Review
Blood Brothers 2 Review By Nadia Oxford on January 29th, 2015 Our Rating: :: AN AGGRAVATING RELATIVEUniversal App - Designed for iPhone and iPad Blood Brothers 2 is built on a simple, solid foundation, but its free-to-play system... | Read more »
I AM BREAD, the Toast of the Town, is Ro...
Have you ever dreamt of being deliciously gluten-y? Do you feel passionate about Rye and Wheat? The guys at Bossa Studios do and that is why they are bringing I AM BREAD to iOS soon. The loafy app will feature all the new content that is being... | Read more »

Price Scanner via MacPrices.net

Intel Aims to Transform Workplace With 5th-Ge...
Intel Corporation today announced the availability of its 5th generation Intel Core vPro processor family that provides cutting-edge features to enable a new and rapidly shifting workplace. To meet... Read more
iOS App Sharalike Introduces New Instant Smar...
Sharalike slideshow and photo management software for iOS, is making it easier than ever to create shareable meaningful moments with its new instant SmartShow technology. Staying organized is a goal... Read more
Apple Becomes World’s Largest Smartphone Vend...
According to the latest research data from Strategy Analytics, as global smartphone shipments grew 31 percent annually to reach a record 380 million units in the fourth quarter of 2014. Apple became... Read more
Cut the Cord: OtterBox Resurgence Power Case...
Dead batteries and broken phones are two of the biggest issues for smartphone users today. Otterbox addresses both with the new Resurgence Power Case for Apple iPhone 6, promising to make those panic... Read more
13-inch Retina MacBook Pros on sale for up to...
B&H Photo has 13″ Retina MacBook Pros on sale for $200 off MSRP. Shipping is free, and B&H charges NY sales tax only: - 13″ 2.6GHz/128GB Retina MacBook Pro: $1199.99 save $100 - 13″ 2.6GHz/... Read more
15-inch 2.5GHz Retina MacBook Pro on sale for...
 B&H Photo has the 15″ 2.5GHz Retina MacBook Pro on sale for $2319.99 including free shipping plus NY sales tax only. Their price is $180 off MSRP, and it’s the lowest price available for this... Read more
Back in stock: Refurbished iPod nanos for $99...
The Apple Store has Apple Certified Refurbished 16GB iPod nanos available for $99 including free shipping and Apple’s standard one-year warranty. That’s $50 off the cost of new nanos. Most colors are... Read more
Apple lowers price on refurbished 256GB MacBo...
The Apple Store has lowered prices on Apple Certified Refurbished 2014 MacBook Airs with 256GB SSDs, now available for up to $200 off the cost of new models. An Apple one-year warranty is included... Read more
New Good Management Suite Simplifies Enterpri...
Good Technology has announced the availability of the Good Management Suite, a comprehensive cross-platform solution for organizations getting started with mobile business initiatives. Built on the... Read more
15-inch 2.0GHz Retina MacBook Pro (refurbishe...
The Apple Store has Apple Certified Refurbished previous-generation 15″ 2.0GHz Retina MacBook Pros available for $1489 including free shipping plus Apple’s standard one-year warranty. Their price is... Read more

Jobs Board

*Apple* Solutions Consultant- Retail Sales (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Event Director, *Apple* Retail Marketing -...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global engagement strategy and team. Delivering an overarching brand Read more
At-Home Chat Specialist- *Apple* Online Stor...
**Job Summary** At Apple , we believe in hard work, a fun environment, and the kind of creativity and innovation that only comes about when talented people from diverse Read more
SW QA Engineer - *Apple* TV - Apple (United...
**Job Summary** The Apple TV team is looking for experienced Quality Assurance Engineers with a passion for delivering first in class home entertainment solutions. **Key Read more
*Apple* Retail - Multiple Positions(US) - Ap...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you re also the Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.