Re: Finder-like color label menu item in Cocoa?
Re: Finder-like color label menu item in Cocoa?
- Subject: Re: Finder-like color label menu item in Cocoa?
- From: James Bucanek <email@hidden>
- Date: Mon, 24 Jul 2006 09:09:58 -0700
Pascal Pochet wrote on Monday, July 24, 2006:
>> Doesn't seem to help/work. I tried
>>
>> extern MenuRef _NSGetCarbonMenu( NSMenu* menu );
>> MenuRef mainMenuRef = _NSGetCarbonMenu([NSApp mainMenu]);
>>
>> and mainMenuRef is set to 0.
>>
>> Thinking that you might have meant NSMenuItem, I tried
>>
>> extern MenuRef _NSGetCarbonMenu( NSMenuItem* menu );
>> NSMenuItem* layersMenuItem = [[NSApp mainMenu]
>> itemWithTag:MENU_LAYER];
>> MenuRef layerMenuRef = _NSGetCarbonMenu(layersMenuItem);
>>
>> and layerMenuRef gets set to 0.
>>
>> Besides, "private" functions make me really nervous.
>>
>>> I'm interested in the end product once you get it working. :)
>>
>> So am I. :)
>>
>
>
>yes because the right function to call is now (d
> extern MenuRef _NSGetCarbonMenu2(id);
Yea, success!
OK, for anyone else who is interested in this, I've posted the modified version of LabelItemView.cp (now LabelItemView.mm) at <ftp://ftp.twilightandbarking.com/Public/Software/Cocoa/LabelItemView.zip>
To add it to my Cocoa application, I added those files, the .png images resources (red.png, orange.png, ... which you can get by downloading the MenuViews project), and by adding the following HIFramework files to the Cocoa application target. These came from the HIFramework, found in the /Developer/Examples/Carbon/HIFramework. I copied the entire framework into my project, so as to have all of the headers, then added these specific files to the target.
TCarbonEvent.cp
TEventHandler.cp
TObject.cp
TView.cp
To add the label view to the menu, I used the following code
static void gInstallCarbonLabelMenuItem( void )
{
extern MenuRef _NSGetCarbonMenu2( NSMenu* menu );
MenuRef mainMenuRef = _NSGetCarbonMenu2([NSApp mainMenu]);
NSCAssert(mainMenuRef,@"mainMenuRef==NULL");
// I "know" that the Layer menu is #5 in the main menubar -- change this as needed
MenuRef layersMenuRef = NULL;
GetMenuItemHierarchicalMenu(mainMenuRef,5,&layersMenuRef);
NSCAssert(layersMenuRef,@"layersMenuRef==NULL");
// place a custom menu item view in the menu
HIViewRef view;
HIViewRef subview;
HIMenuGetContentView( layersMenuRef, kThemeMenuTypePullDown, &view );
NSCAssert(view,@"view==NULL");
HILabelViewCreate( layersMenuRef, 3, view, &subview, nil, @selector(setLayerTint:) );
NSCAssert(subview,@"subview==NULL");
HIViewSetVisible( subview, true );
}
Now I have to figure out how to enable/disable the item and set its fSelected value based on the currently active selection....
Oh, one more thing. I modified Pascal's original code for sending the Objective-C message from
objc_msgSend(fTarget,fSelector,[NSNumber numberWithInt:fSelected]);
to
[NSApp sendAction:fSelector to:fTarget from:[NSNumber numberWithInt:fSelected]];
It's a bit of an abuse of the (id)sender parameter, but I wanted have the option of sending the message to the first responder by passing nil for the target.
Thanks everyone for all of the help.
James
--
James Bucanek
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden