• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Carbon Menu in Cocoa app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Carbon Menu in Cocoa app


  • Subject: Re: Carbon Menu in Cocoa app
  • From: "Daniel zeilMal" <email@hidden>
  • Date: Tue, 18 Mar 2008 11:54:22 -0700

NO , I'm not going to use it on leopard . Cause in leopard , NSMenuItem
support setting custom views using API setView:.What I want , just using it
in Tiger .



extern MenuRef _NSGetCarbonMenu( NSMenu *menu);


@implementation MyController


OSStatus PictureHandler( EventHandlerCallRef caller, EventRef event,

 void* refcon )

{

    OSStatus    err = eventNotHandledErr;

    WindowRef   owner;

     GetEventParameter( event, kEventParamControlCurrentOwningWindow,

   typeWindowRef, NULL, sizeof( owner ), NULL, &owner );

     if ( owner != NULL )

    {

        // find the content view

        HIViewRef content;

        HIViewFindByID( HIViewGetRoot( owner ), kHIViewWindowContentID,

&content );

         // create a data provider for our image

        CFURLRef url = CFBundleCopyResourceURL( CFBundleGetMainBundle(),

CFSTR("NSApplication"), CFSTR(".icns"), NULL );

        CGDataProviderRef data = CGDataProviderCreateWithURL( url );

        CFRelease( url );

         // create our image

        CGImageRef image = CGImageCreateWithJPEGDataProvider( data, NULL,

  true, kCGRenderingIntentDefault );

        CFRelease( data );

         // create our image view

        HIViewRef imageView;

        HIImageViewCreate( image, &imageView );

        HIImageViewSetOpaque( imageView, false );

        HIImageViewSetAlpha( imageView, 0.3 );

        CFRelease( image );

         // position our image view below the content view's children

        HIViewAddSubview( content, imageView );

        HIViewSetZOrder( imageView, kHIViewZOrderBelow, NULL );

        HIViewSetVisible( imageView, true );

         // size our image view to match the content view

        HIRect bounds;

        HIViewGetBounds( content, &bounds );

        HIViewSetFrame( imageView, &bounds );

    }

    return err;

}


-(void) awakeFromNib

{

CFBundleRef bundleRef;

IBNibRef nibRef;

MenuRef myMenuRef;

HIViewRef theView;

EventTypeSpec myEvent;

 OSStatus err;

 //bundleRef = CFBundleGetMainBundle();

//err = CreateNibReferenceWithCFBundle(bundleRef,CFSTR("MainMenu"),
&nibRef);

//if(err)

// NSLog(@"load menu nib failed");

//CreateMenuFromNib(nibRef,CFSTR("myMain"),&myMenuRef);

//InsertMenu(myMenuRef,0);

 NSMenu *menu = [NSApp mainMenu];

myMenuRef = _NSGetCarbonMenu(menu);

 HIMenuGetContentView(myMenuRef,kThemeMenuTypePullDown,&theView);

myEvent.eventClass = kEventClassControl;

myEvent.eventKind  = kEventControlOwningWindowChanged;

/****************************************************************/

        EventHandlerUPP handlerUPP;

handlerUPP = NewEventHandlerUPP(PictureHandler);

InstallControlEventHandler(theView,handlerUPP,2,&myEvent,0,NULL);

}

@end

this is the piece of code . I take the example of HIView Programming Guide
- Manipulating menu views
http://developer.apple.com/documentation/Carbon/Conceptual/HIViewDoc/HIView_tasks/chapter_3_section_12.html#//apple_ref/doc/uid/TP30000923-CH205-BAJIDJDH


so After I call _NSGetCarbonMenu(menu); myMenuRef is always 0x0 .
Must I create the carbon menu in the NIb instead of cocoa menu if I want to
get the correct menuRef?

2008/3/18, Kyle Sluder <email@hidden>:
>
> On Tue, Mar 18, 2008 at 2:25 PM, Daniel zeilMal <email@hidden>
> wrote:
> > I have a custom view . And I have drew something on this view . I want
> to
> >  add a custom view to a menuItem . But this is not supported before
> Leopard .So
>
>
> Are you trying to use _NSGetCarbonMenu on Leopard?  If so, just go
> with the NSView in NSMenu approach.  Leave _NSGetCarbonMenu for Tiger
> only.  Since the symbol is still defined on Leopard (even though it's
> giving you NULL) a simple if statement should suffice.
>
>
> --Kyle Sluder
>
_______________________________________________

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

References: 
 >Carbon Menu in Cocoa app (From: "cai qin" <email@hidden>)
 >Re: Carbon Menu in Cocoa app (From: Nick Zitzmann <email@hidden>)
 >Re: Carbon Menu in Cocoa app (From: "Daniel zeilMal" <email@hidden>)
 >Re: Carbon Menu in Cocoa app (From: "Kyle Sluder" <email@hidden>)

  • Prev by Date: Re: NSTableView solution feedback and questions
  • Next by Date: Re: Getting notifications when any file in a folder change
  • Previous by thread: Re: Carbon Menu in Cocoa app
  • Next by thread: Re: Carbon Menu in Cocoa app
  • Index(es):
    • Date
    • Thread