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.

 
AAPL
$99.76
Apple Inc.
+2.09
MSFT
$44.08
Microsoft Corpora
+0.45
GOOG
$520.84
Google Inc.
+9.67

MacTech Search:
Community Search:

Software Updates via MacUpdate

Macgo Blu-ray Player 2.10.9.1750 - Blu-r...
Macgo Mac Blu-ray Player can bring you the most unforgettable Blu-ray experience on your Mac. Overview Macgo Mac Blu-ray Player can satisfy just about every need you could possibly have in a Blu-ray... Read more
Apple iOS 8.1 - The latest version of Ap...
The latest version of iOS can be downloaded through iTunes. Apple iOS 8 comes with big updates to apps you use every day, like Messages and Photos. A whole new way to share content with your family.... Read more
TechTool Pro 7.0.5 - Hard drive and syst...
TechTool Pro is now 7, and this is the most advanced version of the acclaimed Macintosh troubleshooting utility created in its 20-year history. Micromat has redeveloped TechTool Pro 7 to be fully 64... Read more
PDFKey Pro 4.0.2 - Edit and print passwo...
PDFKey Pro can unlock PDF documents protected for printing and copying when you've forgotten your password. It can now also protect your PDF files with a password to prevent unauthorized access and/... Read more
Yasu 2.9.1 - System maintenance app; per...
Yasu was originally created with System Administrators who service large groups of workstations in mind, Yasu (Yet Another System Utility) was made to do a specific group of maintenance tasks... Read more
Hazel 3.3 - Create rules for organizing...
Hazel is your personal housekeeper, organizing and cleaning folders based on rules you define. Hazel can also manage your trash and uninstall your applications. Organize your files using a... Read more
Autopano Giga 3.7 - Stitch multiple imag...
Autopano Giga allows you to stitch 2, 20, or 2,000 images. Version 3.0 integrates impressive new features that will definitely make you adopt Autopano Pro or Autopano Giga: Choose between 9... Read more
MenuMeters 1.8 - CPU, memory, disk, and...
MenuMeters is a set of CPU, memory, disk, and network monitoring tools for Mac OS X. Although there are numerous other programs which do the same thing, none had quite the feature set I was looking... Read more
Coda 2.5 - One-window Web development su...
Coda is a powerful Web editor that puts everything in one place. An editor. Terminal. CSS. Files. With Coda 2, we went beyond expectations. With loads of new, much-requested features, a few... Read more
Arq 4.6.1 - Online backup to Google Driv...
Arq is super-easy online backup for the Mac. Back up to your own Google Drive storage (15GB free storage), your own Amazon Glacier ($.01/GB per month storage) or S3, or any SFTP server. Arq backs up... Read more

Latest Forum Discussions

See All

This Week at 148Apps: October 13-17, 201...
Expert App Reviewers   So little time and so very many apps. What’s a poor iPhone/iPad lover to do? Fortunately, 148Apps is here to give you the rundown on the latest and greatest releases. And we even have a tremendous back catalog of reviews; just... | Read more »
Angry Birds Transformers Review
Angry Birds Transformers Review By Jennifer Allen on October 20th, 2014 Our Rating: :: TRANSFORMED BIRDSUniversal App - Designed for iPhone and iPad Transformed in a way you wouldn’t expect, Angry Birds Transformers is a quite... | Read more »
GAMEVIL Announces the Upcoming Launch of...
GAMEVIL Announces the Upcoming Launch of Mark of the Dragon Posted by Jessica Fisher on October 20th, 2014 [ permalink ] Mark of the Dragon, by GAMEVIL, put | Read more »
Interview With the Angry Birds Transform...
Angry Birds Transformers recently transformed and rolled out worldwide. This run-and-gun title is a hit with young Transformers fans, but the ample references to classic Transformers fandom has also earned it a place in the hearts of long-time... | Read more »
Find Free Food on Campus with Ypay
Find Free Food on Campus with Ypay Posted by Jessica Fisher on October 20th, 2014 [ permalink ] iPhone App - Designed for the iPhone, compatible with the iPad | Read more »
Strung Along Review
Strung Along Review By Jordan Minor on October 20th, 2014 Our Rating: :: GOT NO STRINGSUniversal App - Designed for iPhone and iPad A cool gimmick and a great art style keep Strung Along from completely falling apart.   | Read more »
P2P file transferring app Send Anywhere...
File sharing services like Dropbox have security issues. Email attachments can be problematic when it comes to sharing large files. USB dongles don’t fit into your phone. Send Anywhere, a peer-to-peer file transferring application, solves all of... | Read more »
Zero Age Review
Zero Age Review By Jordan Minor on October 20th, 2014 Our Rating: :: MORE THAN ZEROiPad Only App - Designed for the iPad With its mind-bending puzzles and spellbinding visuals, Zero Age has it all.   | Read more »
Hay Ewe Review
Hay Ewe Review By Campbell Bird on October 20th, 2014 Our Rating: :: SAVE YOUR SHEEPLEUniversal App - Designed for iPhone and iPad Pave the way for your flock in this line drawing puzzle game from the creators of Worms.   | Read more »
My Very Hungry Caterpillar (Education)
My Very Hungry Caterpillar 1.0.0 Device: iOS Universal Category: Education Price: $3.99, Version: 1.0.0 (iTunes) Description: Care for your very own Very Hungry Caterpillar! My Very Hungry Caterpillar will captivate you as he crawls... | Read more »

Price Scanner via MacPrices.net

2013 15-inch 2.0GHz Retina MacBook Pro availa...
B&H Photo has leftover previous-generation 15″ 2.0GHz Retina MacBook Pros now available for $1599 including free shipping plus NY sales tax only. Their price is $400 off original MSRP. B&H... Read more
Updated iPad Prices
We’ve updated our iPad Air Price Tracker and our iPad mini Price Tracker with the latest information on prices and availability from Apple and other resellers, including the new iPad Air 2 and the... Read more
Apple Pay Available to Millions of Visa Cardh...
Visa Inc. brings secure, convenient payments to iPad Air 2 and iPad mini 3as well as iPhone 6 and 6 Plus. Starting October 20th, eligible Visa cardholders in the U.S. will be able to use Apple Pay,... Read more
Textkraft Pocket – the missing TextEdit for i...
infovole GmbH has announced the release and immediate availability of Textkraft Pocket 1.0, a professional text editor and note taking app for Apple’s iPhone. In March 2014 rumors were all about... Read more
C Spire to offer iPad Air 2 and iPad mini 3,...
C Spire on Friday announced that it will offer iPad Air 2 and iPad mini 3, both with Wi-Fi + Cellular, on its 4G+ LTE network in the coming weeks. C Spire will offer the new iPads with a range of... Read more
Belkin Announces Full Line of Keyboards and C...
Belkin International has unveiled a new lineup of keyboard cases and accessories for Apple’s newest iPads, featuring three QODE keyboards and a collection of thin, lightweight folios for both the... Read more
Verizon offers new iPad Air 2 preorders for $...
Verizon Wireless is accepting preorders for the new iPad Air 2, cellular models, for $100 off MSRP with a 2-year service agreement: - 16GB iPad Air 2 WiFi + Cellular: $529.99 - 64GB iPad Air 2 WiFi... Read more
Price drops on refurbished Mac minis, now ava...
The Apple Store has dropped prices on Apple Certified Refurbished previous-generation Mac minis, with models now available starting at $419. Apple’s one-year warranty is included with each mini, and... Read more
Apple refurbished 2014 MacBook Airs available...
The Apple Store has Apple Certified Refurbished 2014 MacBook Airs available for up to $180 off the cost of new models. An Apple one-year warranty is included with each MacBook, and shipping is free.... Read more
Refurbished 2013 MacBook Pros available for u...
The Apple Store has Apple Certified Refurbished 13″ and 15″ MacBook Pros available starting at $929. Apple’s one-year warranty is standard, and shipping is free: - 13″ 2.5GHz MacBook Pros (4GB RAM/... Read more

Jobs Board

Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
Position Opening at *Apple* - Apple (United...
…customers purchase our products, you're the one who helps them get more out of their new Apple technology. Your day in the Apple Store is filled with a range of Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** At the Apple Store, you connect business professionals and entrepreneurs with the tools they need in order to put Apple solutions to work in their 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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.