Cannot see toolbar buttons
Cannot see toolbar buttons
- Subject: Cannot see toolbar buttons
- From: "Felipe Monteiro de Carvalho" <email@hidden>
- Date: Sun, 5 Oct 2008 21:56:06 -0300
Hello,
I have created a toolbar, but I cannot see the buttons inside it. They
actually work, because if I click in the place where the buttons
should be the callback is actually executed. Any ideas?
Here is my toolbar code:
constructor TMyToolbarController.Create;
begin
{ The class is registered on the Objective-C runtime before the
NSObject constructor is called }
if not CreateClassDefinition(ClassName(), Str_NSObject) then
WriteLn('Failed to create objc class ' + ClassName());
inherited Create;
{ Prepare CFStringRefs for the constants }
OpenToolbarItemIdentifier := CFStringCreateWithPascalString(nil,
'OpenID', kCFStringEncodingUTF8);
SaveToolbarItemIdentifier := CFStringCreateWithPascalString(nil,
'SaveID', kCFStringEncodingUTF8);
CloseToolbarItemIdentifier := CFStringCreateWithPascalString(nil,
'CloseID', kCFStringEncodingUTF8);
{ Create toolbar items }
OpenToolbarItem :=
NSToolbarItem.initWithItemIdentifier(OpenToolbarItemIdentifier);
// [toolbarItem setLabel:@"Save"];
// [toolbarItem setPaletteLabel:[toolbarItem label]];
// [toolbarItem setToolTip:@"Save Your Passwords"];}
OpenToolbarItem.setImage(myModel.imgOpen.Handle);
SaveToolbarItem :=
NSToolbarItem.initWithItemIdentifier(SaveToolbarItemIdentifier);
SaveToolbarItem.setImage(myModel.imgSave.Handle);
CloseToolbarItem :=
NSToolbarItem.initWithItemIdentifier(CloseToolbarItemIdentifier);
CloseToolbarItem.setImage(myModel.imgClose.Handle);
end;
procedure TMyToolbarController.AddMethods;
begin
AddMethod(Str_toolbarAllowedItemIdentifiers, '@@:@',
Pointer(toolbarAllowedItemIdentifiers));
AddMethod(Str_toolbarDefaultItemIdentifiers, '@@:@',
Pointer(toolbarDefaultItemIdentifiers));
AddMethod(Str_toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar,
'@@:@@c', @toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar);
end;
procedure TMyToolbarController.AttachEvents;
begin
OpenToolbarItem.setTarget(myController.Handle);
OpenToolbarItem.setAction(sel_registerName(PChar('doOpenFile:')));
SaveToolbarItem.setTarget(myController.Handle);
SaveToolbarItem.setAction(sel_registerName(PChar('doSaveFile:')));
CloseToolbarItem.setTarget(myController.Handle);
CloseToolbarItem.setAction(sel_registerName(PChar('doCloseFile:')));
end;
class function TMyToolbarController.toolbarAllowedItemIdentifiers(_self:
objc.id;
_cmd: SEL; toolbar: objc.id): CFArrayRef; cdecl;
var
toolbarItems: array[0..4] of CFStringRef;
begin
toolbarItems[0] := OpenToolbarItemIdentifier;
toolbarItems[1] := SaveToolbarItemIdentifier;
toolbarItems[2] := NSToolbarSpaceItemIdentifier;
toolbarItems[3] := CloseToolbarItemIdentifier;
toolbarItems[4] := nil;
Result := CFArrayCreate(nil, @toolbarItems[0], 4, nil);
end;
class function TMyToolbarController.toolbarDefaultItemIdentifiers(_self:
objc.id;
_cmd: SEL; toolbar: objc.id): CFArrayRef; cdecl;
begin
Result := toolbarAllowedItemIdentifiers(_self, _cmd, toolbar);
end;
function toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar(_self: objc.id;
_cmd: SEL; toolbar: objc.id {NSToolbar}; itemIdentifier: CFStringRef;
flag: OBJC_BOOL): objc.id {NSToolbarItem}; cdecl;
begin
WriteLn('toolbar_itemForItemIdentifier_willBeInsertedIntoToolbar: ',
IntToHex(Cardinal(itemIdentifier), 8));
with ToolbarController do
begin
if CFStringCompare(itemIdentifier, OpenToolbarItemIdentifier,
kCFCompareCaseInsensitive) = kCFCompareEqualTo then
Result := OpenToolbarItem.autorelease
else if CFStringCompare(itemIdentifier, SaveToolbarItemIdentifier,
kCFCompareCaseInsensitive) = kCFCompareEqualTo then
Result := SaveToolbarItem.autorelease
else if CFStringCompare(itemIdentifier, CloseToolbarItemIdentifier,
kCFCompareCaseInsensitive) = kCFCompareEqualTo then
Result := CloseToolbarItem.autorelease
else
Result := nil;
end;
end;
--
Felipe Monteiro de Carvalho
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden