• 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: 13 (1997)
Issue Number: 5
Column Tag: develop

Macintosh Q & A

by Apple Developer Support Center

Q: How can I determine whether my 680x0 program is running on a PowerPC machine?

A: The best way to do this is to use the Gestalt selectors as described in the Universal Interface file Gestalt.h:

enum {
 gestaltSysArchitecture = 'sysa',  // Native system architecture
 gestalt68k = 1, // Motorola MC680x0 architecture
 gestaltPowerPC = 2// IBM PowerPC architecture
};

A snippet of code that uses this would look something like the following in your 680x0 program:

 long myattr;
 OSErr  err;

err = Gestalt( gestaltSysArchitecture, &myattr);
if (err == noErr) {
 if (myattr == gestaltPowerPC)
 // Do some PowerPC thing.
 ...
} else {
 // Handle the error condition.
 ...
}

Q: I've created a dialog box that has two editable text fields in it and I've used an 'ictb' resource to change the font and the size of the fields to 10-point Geneva. When I move the insertion point into the second field and delete a character, the character just before the one I deleted drops down a couple of pixels and overwrites itself. What can be done about this?

A: You've run into a problem with the Dialog Manager's support of 'ictb' resources. The Dialog Manager forgets to reset some of the fields of the TextEdit record when it swaps the font and font size information stored in the 'ictb'. You need to reset the fontAscent and lineHeight fields of the TextEdit record to match the size of the font specified in the 'ictb'. By default those fields are set to the lineHeight and fontAscent of 12-point Chicago.

The following code shows how to set up the TextEdit record properly.

static void SetUpEditField(DialogRef dlog, short fontNum, short fontSize)
{
 FontInfo info;
 DialogPeek dpeek = (DialogPeek)dlog;

 if (dpeek != nil) {
 TEHandle te = dpeek->textH;// Get the TEHandle.
 if (te != nil) {
 short  oldFont = dlog->txFont;    // Save old font info.
 short  oldSize = dlog->txSize;
 TextFont(fontNum);// Set correct font info.
 TextSize(fontSize);
 GetFontInfo(&info);
 // Fix the TE record.
 te[0]->txFont = fontNum; // Set font.
 te[0]->txSize = fontSize;
 // Calculate the correct line height.
 te[0]->lineHeight = info.ascent + info.descent + info.leading;
 te[0]->fontAscent = info.ascent;
 TextFont(oldFont);// Reset the font info.
 TextSize(oldSize);
 }
 }
}

Then call SetUpEditField in your dialog routine, like this:

static short DoDialog(short resID)
 {
 DialogRefdlog;
 GrafPtroldPort;
 short  itemHit = 0;

 GetPort(&oldPort);
 dlog = GetNewDialog(resID, nil, (WindowRef)-1);
 if (dlog) {
 SetPort(dlog);
 SelectDialogItemText(dlog, 2, 0x8000, 0x8000);
   // Set the cursor.
 SetUpEditField(dlog, geneva, 10); 
 // Set the edit field.
 (void)SetDialogDefaultItem(dlog, 1);// Highlight OK button.
 ShowWindow(dlog); // Show the dialog.
 while (itemHit != ok)
 ModalDialog(nil, &itemHit);
 SetPort(oldPort);
 DisposeDialog(dlog);
 }
 return itemHit;
}

Of course, an alternative to all this is to avoid the Dialog Manager altogether and thereby avoid these obscure Dialog Manager problems.

 
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