It looks as if I'm (again) at my wit's end (and that's *without*
hearing my significant other observing that that's not all that far...)
with regards to Toolbars. Has anyone gotten them to work? I'm seeing
some *very* strange things, and if anyone can shed some light into
this, I'd be very, very happy indeed. I'm using XCode 1.5 with FPC
2.1.1
First, I created a window, and using 'HIToolbar Programming Guide' set
up all the relevant procs and callbacks. To test everything, I
initially simply set up a default set defining a bunch of
system-provided tools as follows
// below is the default set
Procedure GetToolBarDefaultItems(theArray : CFMutableArrayRef);
begin
CFArrayAppendValue(theArray,
Ptr(CFSTR(kHIToolbarCustomizeIdentifier)));
CFArrayAppendValue(theArray,
Ptr(CFSTR(kHIToolbarPrintItemIdentifier)));
CFArrayAppendValue(theArray,
PTR(CFSTR(kHIToolbarFontsItemIdentifier)));
// CFArrayAppendValue(theArray, PTR(CFSTR(cTool1ID))); // not yet
end;
The toolbar showed up, and displayed the 3 tools just as I wanted. I
was happy. The configure sheet worked fine as well, even though the
toolbar never saved.
I then proceeded to write my own Toolbar Item, and defined the
CreateToolbarForIdentifier, as suggested in the manual. For reference,
I included the code below. In any event, try as I might, I never got
any additional tool in my tool bar. That alone almost cost me my last
hair.
But then I noticed something really, really strange. Experimentally, I
reduced the number of items in both the default and allowable set to
two (only configure, and fonts). Still, the tool bar came up with THREE
items in exactly the order I originally programmed. I scoured my drive
to see if there were any configuration files this toolbar might have
written, but found none. The only way to change the set to two was
altering the toolbar's identifier. Then suddenly I *could* add and
remove standard items (still, only standard ones). Try as I might, I
can't change the toolbar for the original toolbar identifier, but for
all others I can come up with.
So my questions are as follows:
1) Does anyone know where OSX stores the configuration for a toolbar
(e.g. com.mycom.myapp.toolbar) or why the system loads a toolbar
configuration that is not current? The original one, that is. All
others are working as long as I use predefined values (e.g.
kHIToolbarPrintItemIdentifier)
2) Has anyone ever gotten the toolbar in Pascal to work as it should
(i.e added their own items)? My code (below) compiles, and should add a
tool item using the finder Icon, and the 'hubba' label. It adds
nothing. Any sharp eye spotting my glaring mistake? Is perhaps
something wrong with the calling convention (very unlikely, but should
I perhaps be using cdecl or safecall for the callbacks)?
Here's the code:
function CreateToolbarItemForIdentifier (identifier : CFStringRef;
configData : CFTypeRef)
: HIToolbarItemRef;
var
theItem : HIToolbarRef;
theErr : OSErr;
theIcon : IconRef;
theMenu : MenuRef;
theIndex : UInt16;
begin
theItem := nil;
// simply test the identifier against all known ids. cTool1ID is the
ID for the fourth tool
if CFStringCompare(CFSTR(cTool1ID), identifier, kCFCompareBackwards) =
kCFCompareEqualTo then begin
// create this item
theErr := HIToolbarItemCreate(CFSTR(cTool1ID), // Tool1 identifier
kHItoolbarItemAllowDuplicates, // attributes
theItem // the item to create
);
if theErr <> noErr then begin
theItem := nil;
Exit(CreateToolbarItemForIdentifier);
end;
GetIconRef(kOnSystemDisk, kSystemIconsCreator, kFinderIcon,
theIcon); //cTool1CommandID, theIcon); // gets finder icon
HIToolbarItemSetLabel(theItem, CFSTR('hubba')); // set the text to
'hubba'
HIToolbarItemSetIconRef(theItem, theIcon); // attach the icon to item
HIToolbarItemSetCommandID(theItem, cTool1CommandID); // HICoomand for
this toolbar item. currently 'TEsT'
ReleaseIconRef(theIcon); // as suggested in the manual
// theItem now contains the item as it should. it will be passed
back.
end else begin // we could do another compare now
end;
CreateToolbarItemForIdentifier := theItem;
end;
Please - anyone?
-ch
_______________________________________________
MacPascal mailing list
MacPascal@list...
http://lists.sonic.net/mailman/listinfo/macpascal
opensubscriber is not affiliated with the authors of this message nor responsible for its content.