TweetFollow Us on Twitter

Dec 96 Tips
Volume Number:12
Issue Number:12
Column Tag:Tips & Tidbits

Tips & Tidbits

by Steve Sisak

For a program I recently wrote, I wanted to do user input checking for a dialog box as they were typing into an EditText field. I wrote a routine to figure out what the contents of a specific EditText box will be if the current event is allowed to be processed. I then called the routine from my custom dialog event process, and analyzed the results. That way, I could easily decide if the user’s action would produce valid results, or if I needed to abort the current event.

IsDlgControl is a simple check for control characters we always want to process. DivineNewItemString is the routine that does all the work. PStrCopy is a little routine for copying Pascal strings - I’m sure that other people have better ways of doing this.

// some control key constants.
#define kEnterKey3
#define kBackspace 8
#define kTab9
#define kReturnKey 13
#define kEscapeKey 27
#define kLeftKey 28
#define kRightKey29
#define kUpKey   30
#define kDownKey 31
#define kDelete  0xFF

/* IsDlgControl
 * Returns true if c is a special control key (say an arrow key, or escape).
 * Otherwise returns false. */
Boolean IsDlgControl(char c)
{
 if ((c >= kEscapeKey) && (c <= kDownKey)) return true;
 if ((c == kReturnKey) || (c == kEnterKey) || (c == kDelete)
 || (c == kBackspace) || (c == kTab)) return true;
 return false;
 }

/* PStrCpy
 * A little routine to copy Pascal strings. Provided for those people who don’t
 * already use BlockMove() to do this for them ...  */
void PStrCpy(Str255 s, const Str255 t)
{
 short i;

 for (i=0; i<=s[0]; i++) {
 s[i]=t[i];
 }

/* DivineNewItemString
 * Given a DialogPtr, EventPtr and an item number for the active EditText DLOG
 * Item, it returns what the string will be if the current event is processed.
 * It should be called from a custom dialog event proc. */
void DivineNewItemString (DialogPtr d, EventRecord *e, short item, Str255
output)
{
 short  *TEScrpLength = (short *)0x0AB0;
 DialogRecord    *dr;
 TEHandle teh;
 char   c;
 Str255 input, text;
 short  selStart, selEnd;
 short  i;
 short  outStrIdx=0;
 short  iType;
 Handle iHandle;
 Rect   iRect;
    // get the text string
 GetDItem(d,item,&iType,&iHandle,&iRect);
 GetIText(iHandle,text);  // Set the input string
 c = (e->message & charCodeMask);
 if (IsDlgControl(c)) {  
    // if it’s a control char, return the item’s text.
 PStrCpy(output,text);
 return;
 } else if (e->modifiers & cmdKey) {
 if  ((c == ‘v’) || (c == ‘V’)) {
    // if pasting, get the pasted string.
 (void)TEFromScrap();
 HLock(iHandle);
 iHandle = TEScrapHandle();
 for (i=0; i< *TEScrpLength; i++) {
 input[i+1]=((unsigned char *)(*iHandle))[i];
 }
 input[0]=*TEScrpLength;
 HUnlock(iHandle);
 } else { // if any other command stroke ä
 PStrCpy(output,text);
 return;
 }
 } else { // else, set the input string equal to the new character
    // else, set the input string equal to the new character
 input[0]=1;
 input[1]=(unsigned char) c;
 }
    // get the selection point from the TERec
 dr = (DialogRecord *)d;
 teh = dr->textH;
 selStart=(*teh)->selStart;
 selEnd=(*teh)->selEnd;
    // generate output string: copy the first bit of text
 for (i=1; i<=selStart; i++) {
 output[++outStrIdx]=text[i];
 }
    //   copy the input string
 for (i=1; i<=input[0]; i++) {
 output[++outStrIdx]=input[i];
 }
    // copy the last part of text
 for (i=selEnd+1; i<=text[0]; i++) {
 output[++outStrIdx]=text[i];
 } // lastly, set the length
 output[0] = outStrIdx;
 }

Michael Trent

mtrent@msn.fullfeed.com

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Smooth Operator! (Games)
Smooth Operator! 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Smooth Operator is a weird, weird two-player kissing game. Squeeze in for 2 player fun on a single iPad, creating awkward... | Read more »
_PRISM Guide - How to solve those puzzle...
_PRISM is a rather delightful puzzle game that’s been tailor made for touch screens. While part of the fun is figuring things out as you go along, we thought we’d offer you a helping hand at getting in the right mindset. Don’t worry about messing... | Read more »
Set off on an adventure through the Cand...
Like match three puzzlers? If so, Jelly Blast, the innovative iOS and Android game which launched last year, is worth a look. Jelly Blast sees you head off on an epic adventure through the Candy Kingdom with your friends Lily, Mr. Hare, and Mr.... | Read more »
Ellipsis - Touch. Explore. Survive. (...
Ellipsis - Touch. Explore. Survive. 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: | Read more »
Ys Chronicles II (Games)
Ys Chronicles II 1.0.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0.0 (iTunes) Description: After a hard fight to recover the six sacred books in Ys Chronicles I, Adol is back for a sequel! | Read more »
FINAL FANTASY Ⅸ (Games)
FINAL FANTASY Ⅸ 1.0.4 Device: iOS Universal Category: Games Price: $16.99, Version: 1.0.4 (iTunes) Description: ==========●Special sale price for the FINAL FANTASY IX release! ●20% off from February 10 to February 21, 2016... | Read more »
Tennis Club Story (Games)
Tennis Club Story 1.03 Device: iOS Universal Category: Games Price: $4.99, Version: 1.03 (iTunes) Description: Aim for the ace position of tennis club prestige in this simulation! Your leadership decides if players make it to the big... | Read more »
Juggernaut Wars guide - How to use skill...
Juggernaut Warsis a brand new auto-RPG on iOS and Android that challenges you to build a team of heroes, send them out into various different missions to defeat waves of heroes, and level them up to increase their power. The actual combat itself... | Read more »
Check out the new Pirate Attack update i...
Love pirates and board games? Well, you'll love the new Pirate Attack themed update that just launched in Game of Dice. It adds a bunch of new content themed around pirates, like an all new event map based on a pirate ship which revamps the toll... | Read more »
Splash Cars guide - How to paint the tow...
Splash Cars is an arcade driving game that feels like a hybrid between Dawn of the Plow and Splatoon. In it, you'll need to drive a car around to repaint areas of a town that have lost all of their color. Check out these tips to help you perform... | Read more »

Price Scanner via MacPrices.net

Sale! B&H Photo offers 12-inch Retina Mac...
B&H Photo has 12″ Retina MacBooks on sale for $300 off MSRP for a limited time. Shipping is free, and B&H charges NY tax only: - 12″ 1.1GHz Gray Retina MacBook: $999 $300 off MSRP - 12″ 1.... Read more
App Annie Reveals Future of the App Economy:...
App Annie, a San Francisco based mobile app data and insights platform, has launched its first comprehensive app economy forecast. This new offering will provide brands, agencies, investors and app... Read more
Apple restocks Certified Refurbished Mac mini...
Apple has restocked Certified Refurbished 2014 Mac minis, with models available starting at $419. Apple’s one-year warranty is included with each mini, and shipping is free: - 1.4GHz Mac mini: $419 $... Read more
What iPad Pro Still Needs To Make It Truly Pr...
I love my iPad Air 2. So much that I’m grudgingly willing to put up with its compromises and limitations as a production tool in order to take advantage of its virtues. However, since a computer for... Read more
21-inch 3.1GHz 4K on sale for $1399, $100 off...
B&H Photo has the 21″ 3.1GHz 4K iMac on sale $1399 for a limited time. Shipping is free, and B&H charges NY sales tax only. Their price is $100 off MSRP: - 21″ 3.1GHz 4K iMac (MK452LL/A): $... Read more
Apple price trackers, updated continuously
Scan our Apple Price Trackers for the latest information on sales, bundles, and availability on systems from Apple’s authorized internet/catalog resellers. We update the trackers continuously: - 15″... Read more
Save up to $240 with Apple Certified Refurbis...
Apple is now offering Certified Refurbished 12″ Retina MacBooks for up to $240 off the cost of new models. Apple will include a standard one-year warranty with each MacBook, and shipping is free. The... Read more
Apple refurbished 13-inch Retina MacBook Pros...
Apple has Certified Refurbished 13″ Retina MacBook Pros available for up to $270 off the cost of new models. An Apple one-year warranty is included with each model, and shipping is free: - 13″ 2.7GHz... Read more
Apple refurbished Time Capsules available for...
Apple has certified refurbished Time Capsules available for $120 off MSRP. Apple’s one-year warranty is included with each Time Capsule, and shipping is free: - 2TB Time Capsule: $179, $120 off - 3TB... Read more
13-inch 2.5GHz MacBook Pro (refurbished) avai...
Apple has Certified Refurbished 13″ 2.5GHz MacBook Pros available for $829, or $270 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free: - 13″ 2.5GHz MacBook Pros... Read more

Jobs Board

Infrastructure Engineer - *Apple* /Mac - Rem...
…part of a team Requires proven problem solving skills Preferred Additional: Apple Certified System Administrator (ACSA) Apple Certified Technical Coordinator (ACTC) Read more
Lead Engineer - *Apple* OSX & Hardware...
Lead Engineer - Apple OSX & Hardware **Job ID:** 3125919 **Full/Part\-Time:** Full\-time **Regular/Temporary:** Regular **Listed:** 2016\-02\-10 **Location:** Cary, Read more
Simply Mac *Apple* Specialist- Service Repa...
Simply Mac is the largest premier retailer of Apple products in the nation. In order to support our growing customer base, we are currently looking for a driven Read more
Infrastructure Engineer - *Apple* /Mac - Rem...
…part of a team Requires proven problem solving skills Preferred Additional: Apple Certified System Administrator (ACSA) Apple Certified Technical Coordinator (ACTC) Read more
Lead Engineer - *Apple* OSX & Hardware...
Lead Engineer - Apple OSX & Hardware **Job ID:** 3125919 **Full/Part\-Time:** Full\-time **Regular/Temporary:** Regular **Listed:** 2016\-02\-10 **Location:** Cary, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.