• MacTech Network:
  • Tech Support
  • |
  • MacForge.net
  • |
  • Apple News
  • |
  • Register Domains
  • |
  • SSL Certificates
  • |
  • iPod Deals
  • |
  • Mac Deals
  • |
  • Mac Book Shelf

MAC TECH

  • Home
  • Magazine
    • About MacTech in Print
    • Issue Table of Contents
    • Subscribe
    • Risk Free Sample
    • Back Issues
    • MacTech DVD
  • Archives
    • MacTech Print Archives
    • MacMod
    • MacTutor
    • FrameWorks
    • develop
  • Forums
  • News
    • MacTech News
    • MacTech Blog
    • MacTech Reviews and KoolTools
    • Whitepapers, Screencasts, Videos and Books
    • News Scanner
    • Rumors Scanner
    • Documentation Scanner
    • Submit News or PR
    • MacTech News List
  • Store
  • Apple Expo
    • by Category
    • by Company
    • by Product
  • Job Board
  • Editorial
    • Submit News or PR
    • Writer's Kit
    • Editorial Staff
    • Editorial Calendar
  • Advertising
    • Benefits of MacTech
    • Mechanicals and Submission
    • Dates and Deadlines
    • Submit Apple Expo Entry
  • User
    • Register for Ongoing Raffles
    • Register new user
    • Edit User Settings
    • Logout
  • Contact
    • Customer Service
    • Webmaster Feedback
    • Submit News or PR
    • Suggest an article
  • Connect Tools
    • MacTech Live Podcast
    • RSS Feeds
    • Twitter

ADVERTISEMENT

Volume Number: 14 (1998)
Issue Number: 1
Column Tag: Tips & Tidbits

Jan 98 - Tips and Tidbits

by Steve Sisak

Here is a tip about the use of the GetScrap Scrap Manager trap. When your application is starting up, you may want to check the contents of the scrap or transfer it into your private scrap. However, you should be careful not to call GetScrap until after you've made a couple calls to WaitNextEvent.

This delay is required to allow the Process Manager to move the contents of the clipboard from the previously active application into your application's process context. Also, don't forget that TEFromScrap is just a wrapper around GetScrap, and has the same requirement.

Here is some code to illustrate the problem. Don't do this:

    InitGraf(&qd.thePort);
    ...
    InitDialogs(0);
    TEFromScrap();
 
    for (;;)
       WaitNextEvent(...);

Instead, do something like this:

    switch (event.what)
    {
       case nullEvent:
       {
          static int      idleCount;
          static Boolean      gotBootScrap;
 
          if (++idleCount == 3 && !gotBootScrap)
          {
             TEFromScrap();
             gotBootScrap = true;
          }
       }
    }

You're probably wondering why the Process Manager doesn't just set up the scrap correctly when it launches a new application? Actually it can't because the current application might have data in a private scrap, which won't be moved into the system scrap until that application receives a suspend event. The suspend event won't be received, however, until after the LaunchApplication trap has created the new process and returned back to the caller. The Process Manager has to wait until the original frontmost application has received that suspend event before it can safely move the contents of the system scrap into the launched application's context.

Eric Schlegel
ericsc@apple.com

"Rather than trying to guess how many nullEvents to wait for, it may be more reliable to hold off importing the scrap (and other initialization) until you receive your first Apple event. That first Apple event will be either 'aevt'/'oapp', 'aevt'/' odoc', or 'ascr'/' noop' and will not be sent until the Process Manager has fully suspended the previous frontmost application."

--ed sgs

Eric replys: "That would have the same effect. It might not always be a better choice than just waiting for the null events, though, depending on whether you already have Apple event handlers. Stickies opens its data file immediately without waiting for an oapp event, so for Stickies and similar apps it makes sense to just use the idle count." --eric

 
MacTech Only Search:
Community Search:

 
 
 

 
 
 
 
 
  • SPREAD THE WORD:
  • Slashdot
  • Digg
  • Del.icio.us
  • Reddit
  • Newsvine
  • Generate a short URL for this page:



MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797
MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders.
All contents are Copyright 1984-2010 by Xplain Corporation. All rights reserved. Theme designed by Icreon.
 
Nov. 20: Take Control of Syncing Data in Sow Leopard' released
Nov. 19: Cocktail 4.5 (Leopard Edition) released
Nov. 19: macProVideo offers new Cubase tutorials
Nov. 18: S Stardom anounces Safe Capsule, a companion piece for Apple's
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live