Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Custom Controls and collections and all that
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Custom Controls and collections and all that



On Thu, 31 Jul 2003 04:14:04 +0400:
Mike Kluev <email@hidden> said:

I do not have sources handy, but I remember I just call RegisterControlDefinition with NULL ControlCNTLToCollectionUPP.

The problem with this is when you want to use the min/max/val in the nib or CNTL to provide special init values. One of the things we're supposed to be doing as we move to OS X is to treat refs for various things opaquely. So, one of the first things I did to bring my CDEFs into the 21st century was to change all direct access to ControlRecord structures to use the appropriate access calls. When you call GetControlValue the first time (rather than reading the record directly), you won't get your special init value if it's bigger than the init max. It is really not that hard to supply a ControlCNTLToCollectionProc and if you want do nothing other than access the val/min/max then you only need to create one and use it with all your CDEFs.

Anyone who wants a copy of my standard one is welcome, I've pasted it at the end of this message.

If you want to pass other things in there on a by CDEF basis then you make up your own tags and use the ProcID to figure out which CDEF and variation it is.

pascal OSStatus MyStandardCNTLToCollectionProc
(
const Rect* iBounds,
SInt16 iValue,
Boolean iVisible,
SInt16 iMaximum,
SInt16 iMinimum,
SInt16 iProcID,
SInt32 iRefCon,
ConstStr255Param iTitle,
Collection oCollection
)
{
OSStatus vError = noErr;

// These are necessary to match the pointer types when passing to the collection
SInt32 vValue = iValue;
SInt32 vMaximum = iMaximum;
SInt32 vMinimum = iMinimum;

vError = AddCollectionItem(oCollection, kControlCollectionTagBounds, 0,
sizeof(Rect), (void*)iBounds);
if (vError != noErr) goto xCantAddCollectionItem;

vError = AddCollectionItem(oCollection, kControlCollectionTagValue, 0,
sizeof(SInt32), &vValue);
if (vError != noErr) goto xCantAddCollectionItem;

vError = AddCollectionItem(oCollection, kControlCollectionTagVisibility, 0,
sizeof(Boolean), &iVisible);
if (vError != noErr) goto xCantAddCollectionItem;

vError = AddCollectionItem(oCollection, kControlCollectionTagMaximum, 0,
sizeof(SInt32), &vMaximum);
if (vError != noErr) goto xCantAddCollectionItem;

vError = AddCollectionItem(oCollection, kControlCollectionTagMinimum, 0,
sizeof(SInt32), &vMinimum);
if (vError != noErr) goto xCantAddCollectionItem;

vError = AddCollectionItem(oCollection, kControlCollectionTagRefCon, 0,
sizeof(SInt32), &iRefCon);
if (vError != noErr) goto xCantAddCollectionItem;

vError = AddCollectionItem(oCollection, kControlCollectionTagTitle, 0,
iTitle[0], (void*)&iTitle[1]);
if (vError != noErr) goto xCantAddCollectionItem;

xCantAddCollectionItem:

return vError;
}

Cheers Geoff %^>
_______________________________________________
carbon-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/carbon-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.