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

Drama 2.0.7 - Prototyping, animation...
Drama's handy 3-in-1 functionality uniquely integrates design, animation and prototyping into a single familiar tool. No more frustrating switching between apps or learning new stuff. And by... Read more
Navicat Premium Essentials 15.0.11 - Pro...
Navicat Premium Essentials is a compact version of Navicat which provides basic and necessary features you will need to perform simple administration on a database. It supports the latest features... Read more
Delicious Library 3.9 - Import, browse a...
Delicious Library allows you to import, browse, and share all your books, movies, music, and video games with Delicious Library. Run your very own library from your home or office using our... Read more
ffWorks 2.0.1 - Convert multimedia files...
ffWorks, focused on simplicity, brings a fresh approach to the use of FFmpeg, allowing you to create ultra-high-quality movies without the need to write a single line of code on the command-line.... Read more
TeamViewer 15.3.2682 - Establish remote...
TeamViewer gives you remote control of any computer or Mac over the Internet within seconds or can be used for online meetings. Find out why more than 200 million users trust TeamViewer! Free for non... Read more
Affinity Designer 1.8.1 - Vector graphic...
Affinity Designer is an incredibly accurate vector illustrator that feels fast and at home in the hands of creative professionals. It intuitively combines rock solid and crisp vector art with... Read more
Wireshark 3.2.2 - Network protocol analy...
Wireshark is one of the world's foremost network protocol analyzers, and is the standard in many parts of the industry. It is the continuation of a project that started in 1998. Hundreds of... Read more
Affinity Photo 1.8.1 - Digital editing f...
Affinity Photo - redefines the boundaries for professional photo editing software for the Mac. With a meticulous focus on workflow it offers sophisticated tools for enhancing, editing and retouching... Read more
iShowU Instant 1.3.2 - Full-featured scr...
iShowU Instant gives you real-time screen recording like you've never seen before! It is the fastest, most feature-filled real-time screen capture tool from shinywhitebox yet. All of the features you... Read more
NeoFinder 7.5.1 - Catalog your external...
NeoFinder (formerly CDFinder) rapidly organizes your data, either on external or internal disks, or any other volumes. It catalogs and manages all your data, so you stay in control of your data... Read more

Latest Forum Discussions

See All

Amon Amarth Berserker is a side-scrollin...
Amon Amarth Berserker is the latest game from Ride & Crash and serves as a follow up to the previous title that was simply called Amon Amarth. It's available now as a premium title for both iOS and Android. [Read more] | Read more »
Team up with your guildmates to take on...
MU Origin 2's latest update is now live and brings with it two new Abyss-related events to challenge Guilds. There are also a few new features that will allow players to enhance their costumes, an increased level cap and more. [Read more] | Read more »
Build Your Own Apple Arcade, For $400
Apple Arcade has been out for a little over a month, and I’m not entirely thrilled with it. It’s definitely an interesting idea, but it leaves a lot to be desired, especially in fulfilling its commitment to letting folks “play anywhere.” Still, at... | Read more »
Creepy Little Monsters is a cute, monste...
Creepy Little Monsters is a retro throwback that sees you traversing tricky puzzle-platformer levels as a one-eyed monster. It aims to offer a fresh take on 80s and 90s classics of the genre, and it's out right now for iOS and Android. [Read more... | Read more »
Tyrant's Arena delivers intense her...
Tyrant's Arena is an intense midcore multiplayer actioner where you'll compete in tricky 3v3 matches to crush your opponents and earn neat rewards. It comes to us from developer Kroy Games, and it's now available for pre-registration on iOS and... | Read more »
Mobile Games Starter Kit
Over here at 148Apps, we regularly dive deep into the latest and greatest mobile games hitting the App Store, but that’s not always what people are looking for when searching for a new mobile game. Some folks just want to dip their toes into... | Read more »
Unresolved is a hard-hitting narrative a...
Ghofran Akil's Unresolved in an upcoming text-based adventure game that sees you playing as a mother attempting to find her disappeared husband during the Lebanese Civil War. [Read more] | Read more »
Marvel Strike Force introduces new brawl...
FoxNext's squad-based RPG Marvel Strike Force is set to receive some fresh characters from the X-Men and Iron Man series. They'll arrive as part of the game's latest update, which follows a sizable spending boycott on the title due to complaints... | Read more »
Speed Dating for Ghosts is a narrative a...
Speed Dating for Ghosts originally released on Steam back 2018, since then it has received honourable mentions for narrative during the Independent Games Festival. Now it's made its way over to iOS devices where it's available as a premium title... | Read more »
Fast-paced multiplayer title Tennis Star...
Tennis Stars: Ultimate Clash is the latest free-to-play tennis title to hit iOS and Android. It's said to be a fairly casual experience, offering easy-to-learn controls and fast-paced, mobile-friendly matches. [Read more] | Read more »

Price Scanner via MacPrices.net

Back in stock! Apple’s 4-core and 6-core 2018...
Apple has Certified Refurbished 2018 Mac minis available on their online store for $120-$170 off the cost of new models. Each mini comes with a new outer case plus a standard Apple one-year warranty... Read more
10″ 128GB iPads on sale today at Amazon for $...
Amazon has new 10.2″ 128GB WiFI iPads for $100 off Apple’s MSRP. These are the same iPads sold by Apple in their retail and online stores. Note that some sale prices may be restricted to certain... Read more
Orcam MyEye 2 Is Inspiration Apple Needs To M...
EDITORIAL: 02.28.20- It’s no secret that Apple is planning to further expand into the wearables segment, working quietly behind the scenes to create its own smart glasses — as rumors have suggested... Read more
Boost Mobile 1-day Flash Sale: $100 off all A...
Boost Mobile is offering Apple’s 2019 iPhone 11 and 11 Pro models for $100 off MSRP. Boost is also offering the same $100 discount on new previous-generation iPhone XS, XR, X, 8, and 7 models. For... Read more
13″ 1.4GHz Silver MacBook Pros on sale for $1...
B&H Photo has new 2019 13″ 1.4GHz Silver MacBook Pros on sale for $150 off Apple’s MSRP today with prices starting at $1149. Overnight shipping is free to many addresses in the US. These are the... Read more
Apple resellers offer $150-$170 discounts on...
Amazon has new 2019 13″ MacBook Airs on sale for $150-$170 off Apple’s MSRP, with prices starting at $949, each including free shipping. These are the same MacBook Airs Apple sells in their retail... Read more
B&H is again offering $100 discounts on M...
B&H Photo has 4-Core and 6-Core Mac minis on sale for $100 off Apple’s standard MSRP, with prices starting at only $699. Overnight shipping is free to many US addresses: – 3.6GHz Quad-Core mini... Read more
B&H Photo drops iMac prices, offers model...
B&H Photo has new 2019 21″ and 27″ 5K iMacs in stock today and on sale for up to $250 off Apple’s MSRP, with prices starting at only $999. These are the same iMacs sold by Apple in their retail... Read more
Flash sale! 11″ 64GB WiFi iPad Pro for $674,...
Walmart has the 11″ 64GB WiFi iPad Pro on sale on their online store today for $674. That’s $125 off Apple’s MSRP for this model and the cheapest price available from any Apple reseller. Choose free... Read more
Sale! Get the 256GB 13″ Silver MacBook Air fo...
Amazon has new 2019 13″ 1.6GHz/256GB MacBook Airs, in Silver, on sale today for only $999 shipped. Their price is $300 off Apple’s MSRP for this model, and it’s the cheapest price for a 256GB MacBook... Read more

Jobs Board

Windows/ *Apple* Technical Support Engineer...
Windows/ Apple Technical Support Engineer Key Role: Serve as a part of a dynamic corporate technical support group. Provide Tier III technical support and monthly Read more
Medical Assistant - *Apple* Valley Clinic -...
…professional, quality care to patients in the ambulatory setting at the M Health Fairview Apple Valley Clinic, located in Apple Valley, MN. Join the **M Health Read more
Medical Assistant - *Apple* Valley Clinic -...
…professional, quality care to patients in the ambulatory setting at the M Health Fairview Apple Valley Clinic, located in Apple Valley, MN. Join the **M Health Read more
Geek Squad Advanced Repair *Apple* Professi...
**764652BR** **Job Title:** Geek Squad Advanced Repair Apple Professional **Job Category:** Store Associates **Store NUmber or Department:** 000245- Apple Read more
Medical Assistant - *Apple* Valley Clinic -...
…professional, quality care to patients in the ambulatory setting at the M Health Fairview Apple Valley Clinic, located in Apple Valley, MN. Join the **M Health Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.