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: Sun, 23 Jul 2006 16:14:04 -0700
Pascal Pochet wrote on Sunday, July 23, 2006:
>
>Le 23-juil.-06 à 08:09, James Bucanek a écrit :
>
>> Is it possible (or even better yet, has someone already written it)
>> to implement a menu item like the Finder's color label selector?
>>
>> I'd like to do something similar in both the main menubar and a
>> contextual pop-menu.
>>
>> I assumed that this would be fait accompli, but several hours of
>> searching the Internet, list archives, and developer code examples
>> only resulted in two other posts asking the same question (both
>> went unanswered), no documentation on how one would accomplish
>> this, and no code samples.
>>
>> I did find an old Carbon project named MenuViews which purports to
>> implement this (I can't tell, because the project won't build). But
>> even if it did, I'm not optimistic that I could use it in a Cocoa
>> application.
>>
>
>MenuViews compiles fine as Universal binary…
>but it generates a lot of "deprecated" warning…
Well, let's say that MenuViews has the "potential" to be built. The project, as downloaded from developer.apple.com, has a lot of problems. Taking your word for it, I attacked it again this morning. I eventually got it working once I had tried three different version of HIFramework, fixed the file types for the .cp files, corrected the path references in the project, added the files that were missing(!), linked to the correct libstdc++ library, and updated the JAM-based target to an modern one. After those "minor" tweaks, it compiled and ran without a problem. :)
>To integrate it in a Cocoa project, you have to change
>LabelItemView.cp into a LabelItemView.mm to be able to mix with some
>Objective-C code…
>the other changes are quite minimal:
Pascal, this is awesome. Thanks for the detailed modifications. I was able to turn LayerTableView.cp into LayerTableView.m, add the necessary support for the target/action, and linked it into my application. For the record, I also had to add a #include <Cocoa/Cocoa.h> and an extern for objc_msgSend(). Ultimately I needed very little of the HIFramework, so the footprint was minimal.
Now I'm completely stuck. I can't seem to integrate this Carbon menu item into my Cocoa application. (I read the Apple guide on using Carbon UI elements in a Cocoa application, but that applies strictly to windows, not the menu bar).
I assumed that I could simply add the following code to my application to get started:
static void sInstallCarbonLabelMenuItem( void )
{
MenuRef layerMenuRef;
layerMenuRef = GetMenuHandle(MENU_LAYER);
// place a custom menu item view in the menu
HIViewRef view;
HIViewRef subview;
HIMenuGetContentView( layerMenuRef, kThemeMenuTypePullDown, &view );
HILabelViewCreate( layerMenuRef, 3, view, &subview, gAppDelegate, @selector(setLayerTint:) );
HIViewSetVisible( subview, true );
}
But the call to GetMenuHandle() returns NULL. I have a top-level submenu named "Layers" with a tag of 1300 defined in my NIB. From the Carbon documentation, GetMenuHandle(1300) should return me a MenuRef to that menu item. I also know that the menu is valid at this point becuase it is where I perform other modifications to the menu bar. Is there some other Carbon stuff I have to do first?
--
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