TweetFollow Us on Twitter

January 93 - Customizing Views

Customizing Views

Angelika Peter

If you want to have subclasses of TView with additional fields, you face the problem that you can't initialize them from a 'View' resource if you want to use ViewEdit (or AdLib). With MacApp 2 style views it was relatively easy to derez the view resources, once the hierarchy was stable, and to maintain them as Rez sources.

With MacApp 3 style views, this becomes substantially more difficult. Not really impossible, but awkward enough to make me look for a workaround. Here it is:

THE SOLUTION

One of the (many) really good things about the new view format is the field fUserArea.

I am using it as a resource ID. The view subclass then reads a resource of a certain type with this ID and initializes its additional fields from this resource. Each subclass knows which resource type it has to use. Of course it is possible to have several levels of subclassing too. In this case every subclass would need it's own resource type.

All this happens in DoPostCreate, but one could probably do it in ReadFields if it is important that the fields are initialized before the DoPostCreate phase.

It is easy to maintain these resources either with ResEdit using own templates or with Rez, whichever is more convenient. And you have the additional advantage that the resources can be shared among several views.

AN EXAMPLE

My example is a TEditText subclass, used to enter numeric values. It is very much based on the old TExtendedText class from one of the MacApp 2 Goodies disks.

I want to initialize not only minimum and maximum from the resource but also the initial value, the precision and how it should behave when dimmed and whether to use scientific format.

The Pascal type template for the resource looks like this:

ExtTextDescribitor = RECORD
    minimum:                LongInt;
    maximum:                LongInt;
    divisor:                Integer;    
    precision:              Integer;
    maxMagnitude:           Integer;
    hideTextWhenDimmed:     Integer;  { 0 for false, <> 0 for true }
    initialValue:           Str255
    END; 
ExtTextDescribitorPtr       = ^ExtTextDescribitor;
ExtTextDescribitorHandle    = ^ExtTextDescribitorPtr;

The corresponding Rez template is:

type 'ExTx' {
    longint;    /* minimum value */ 
    longint;    /* maximum value */ 
    integer;    /* divisor (for minimum and maximum) */
    integer;    /* precision */ 
    integer     kNeverScientific=32000, kForceScientific=-1;
    integer     kShowTextWhenDimmed=0, kHideTextWhenDimmed =1;
    pstring;    /* initial value */
};

DoPostCreate would always look something like this:

PROCEDURE TExtendedText.DoPostCreate(itsDocument: TDocument);
OVERRIDE;

VAR
    itsDescribitor: Handle;
    fi: FailInfo;

    PROCEDURE HdlDoPostCreate(error: OSErr; message: LongInt);
    
    BEGIN
    SELF.Free
    END;

BEGIN { DoPostCreate }
INHERITED DoPostCreate(itsDocument);

IF fUserArea <> 0 THEN
    BEGIN
    CatchFailures(fi, HdlDoPostCreate);
    { !!! use your resource type here !!! }
    itsDescribitor := GetResource('foo ', fUserArea));
    FailNILResource(itsDescribitor);
    HLock(Handle(itsDescribitor));  { to make WITH safe }
    Success(fi);
    
    WITH MyDescribitorTypeHandle(itsDescribitor)^^ DO
        BEGIN
        { initialize your fields }
        END;    { with }
    
    ReleaseResource(itsDescribitor)
    END { if fUserArea… }
END; { DoPostCreate }

Initializing the fields is straightforward:

WITH itsDescribitor^^ DO
BEGIN
fPrecision := precision;        { digits after decimal point }
fMaxMagnitude := maxMagnitude;  { when to use scientific                                                                format }
fHideTextWhenDimmed := hideTextWhenDimmed <> 0;

IF minimum = - maxLongInt THEN  {to be able to express ±∞}
    fMinimum := - inf
ELSE
    fMinimum := minimum / divisor;  {for fractional minimum}
IF maximum = maxLongInt THEN
    fMaximum := + inf
ELSE
    fMaximum := maximum / divisor;  {for fractional maximum}

    fValue := initialValue;
SELF.SetModifiedText(initialValue, kRedraw)
END;    { with }
 
AAPL
$100.96
Apple Inc.
-0.83
MSFT
$47.52
Microsoft Corpora
+0.84
GOOG
$596.08
Google Inc.
+6.81

MacTech Search:
Community Search:

Software Updates via MacUpdate

Audio Hijack Pro 2.11.3 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Airfoil 4.8.9 - Send audio from any app...
Airfoil allows you to send any audio to AirPort Express units, Apple TVs, and even other Macs and PCs, all in sync! It's your audio - everywhere. With Airfoil you can take audio from any... Read more
WhatRoute 1.13.0 - Geographically trace...
WhatRoute is designed to find the names of all the routers an IP packet passes through on its way from your Mac to a destination host. It also measures the round-trip time from your Mac to the... Read more
Chromium 37.0.2062.122 - Fast and stable...
Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all Internet users to experience the web. FreeSMUG-Free OpenSource Mac User Group build is... Read more
Attachment Tamer 3.1.14b9 - Take control...
Attachment Tamer gives you control over attachment handling in Apple Mail. It fixes the most annoying Apple Mail flaws, ensures compatibility with other email software, and allows you to set up how... Read more
Duplicate Annihilator 5.0 - Find and del...
Duplicate Annihilator takes on the time-consuming task of comparing the images in your iPhoto library using effective algorithms to make sure that no duplicate escapes. Duplicate Annihilator detects... Read more
jAlbum Pro 12.2 - Organize your digital...
jAlbum Pro has all the features you love in jAlbum, but comes with a commercial license. With jAlbum, you can create gorgeous custom photo galleries for the Web without writing a line of code!... Read more
jAlbum 12.2 - Create custom photo galler...
With jAlbum, you can create gorgeous custom photo galleries for the Web without writing a line of code! Beginner-friendly, with pro results Simply drag and drop photos into groups, choose a design... Read more
Quicken 2015 2.0.4 - Complete personal f...
Quicken 2015 helps you manage all your personal finances in one place, so you can see where you're spending and where you can save. Quicken automatically categorizes your financial transactions,... Read more
iMazing 1.0 - Complete iOS device manage...
iMazing (formerly DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can: Copy music to and... Read more

Latest Forum Discussions

See All

View Source – HTML, JavaScript and CSS...
View Source – HTML, JavaScript and CSS 1.0 Device: iOS Universal Category: Utilities Price: $.99, Version: 1.0 (iTunes) Description: View Source is an app plus an iOS 8 Safari extension that makes it easy to do one key web developer... | Read more »
Avenged Sevenfold’s Hail To The King: De...
Avenged Sevenfold’s Hail To The King: Deathbat is Coming to iOS on October 16th Posted by Jessica Fisher on September 19th, 2014 [ permalink ] Just in time for Halloween, on October 16 Avenged Sevenfold will be launching | Read more »
Talisman Has Gone Universal – Can Now be...
Talisman Has Gone Universal – Can Now be Played on the iPhone Posted by Jessica Fisher on September 19th, 2014 [ permalink ] | Read more »
Tap Army Review
Tap Army Review By Jennifer Allen on September 19th, 2014 Our Rating: :: SHOOT EM ALLUniversal App - Designed for iPhone and iPad Mindless but fun, Tap Army is a lane-based shooter that should help you relieve some stress.   | Read more »
Monsters! Volcanoes! Loot! Epic Island f...
Monsters! Volcanoes! Loot! | Read more »
Plunder Pirates: Tips, Tricks, Strategie...
Ahoy There, Seadogs: Interested in knowing our thoughts on all this plundering and pirating? Check out our Plunder Pirates Review! Have you just downloaded the rather enjoyable pirate-em-up Plunder Pirates and are in need of some assistance? Never... | Read more »
Goat Simulator Review
Goat Simulator Review By Lee Hamlet on September 19th, 2014 Our Rating: :: THE GRUFFEST OF BILLY GOATSUniversal App - Designed for iPhone and iPad Unleash chaos as a grumpy goat in this humorous but short-lived casual game.   | Read more »
A New and Improved Wunderlist is Here fo...
A New and Improved Wunderlist is Here for iOS 8 Posted by Jessica Fisher on September 19th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Evernote Update for iOS 8 Adds Web Clipp...
Evernote Update for iOS 8 Adds Web Clipping, Quick Notes, and More Posted by Ellis Spice on September 19th, 2014 [ permalink ] | Read more »
Apple Names Ultimate Productivity Bundl...
Apple Names Ultimate Productivity Bundle by Readdle as the Essential Bundle on the App Store Posted by Jessica Fisher on September 19th, 2014 [ permalink | Read more »

Price Scanner via MacPrices.net

iFixIt Tears Down iPhone 6; Awards Respectabl...
iFixit notes that even the smaller 4.7″ iPhone 6 is a giant among iPhones; so big that Apple couldn’t fit it into the familiar iPhone form factor. In a welcome reversal of a recent trend to more or... Read more
Phone 6 Guide – Tips Book For Both iPhone 6...
iOS Guides has announced its latest eBook: iPhone 6 Guide. Brought to you by the expert team at iOS Guides, and written by best-selling technology author Tom Rudderham, iPhone 6 Guide is packed with... Read more
How to Upgrade iPhone iPad to iOS 8 without D...
PhoneClean, a iPhone cleaner utility offered by iMobie Inc., reveals a solution for upgrading iPhone and iPad to iOS 8 without deleting photos, apps, the new U2 album or anything. Thanks to more than... Read more
Inpaint 6 – Photo Retouching Tool Gets Faster...
TeoreX has announced Inpaint 6, a simple retouching tool for end users that helps remove scratches, watermarks, and timestamps as well as more complex objects like strangers, unwanted elements and... Read more
Worldwide PC Monitor Market Sees Growth in To...
Worldwide PC monitor shipments totaled 32.5 million units in the second quarter of 2014 (2Q14), a year-over-year decline of -2.9%, according to the International Data Corporation (IDC) Worldwide... Read more
Updated Price Trackers
We’ve updated our Mac Price Trackers with the latest information on prices, bundles, and availability on systems from Apple’s authorized internet/catalog resellers: - 15″ MacBook Pros - 13″ MacBook... Read more
Mac Pros available for up to $260 off MSRP
Adorama has Mac Pros on sale for up to $260 off MSRP. Shipping is free, and Adorama charges sales tax in NY & NJ only: - 4-core Mac Pro: $2839.99, $160 off MSRP - 6-core Mac Pro: $3739.99, $260... Read more
13-inch 2.6GHz/256GB Retina MacBook Pros avai...
B&H Photo has the 13″ 2.6GHz/256GB Retina MacBook Pro on sale for $1379 including free shipping plus NY sales tax only. Their price is $120 off MSRP. Read more
Previous-generation 15-inch 2.0GHz Retina Mac...
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
21″ 2.7GHz iMac available for $1179, save $12...
Adorama has 21″ 2.7GHz Hawell iMacs on sale for $1179.99 including free shipping. Their price is $120 off MSRP. NY and NJ sales tax only. Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the 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
Position Opening at *Apple* - Apple (United...
**Job Summary** As businesses discover the power of Apple computers and mobile devices, it's your job - as a Solutions Engineer - to show them how to introduce these Read more
Position Opening at *Apple* - Apple (United...
…Summary** As a Specialist, you help create the energy and excitement around Apple products, providing the right solutions and getting products into customers' hands. You Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.