replacing carbon menu with cocoa
-
Hi,
I'm new to the list -and to cocoa-, and I don't know if what I want to
do is possible: I'm writing a plugin for a previous existent
application made in carbon, the application will take over the old app
behavior, and for that, it needs to replace the menu with a new one...
I read documentation, saw examples and followed old threads on this
list, and no one is very clear about this... ¿Is it possible? ¿how?
I already tried
[ NSApp setMainMenu: myMenu ]
It does not fail, but nothing happens :(
Thanks in advance,
Esteban
"Querer es suscitar las paradojas"
Camus - El mito de SÃsifo -
On Oct 13, 2008, at 5:18 AM, Esteban Lorenzano wrote:> Hi,
> I'm new to the list -and to cocoa-, and I don't know if what I want
> to do is possible: I'm writing a plugin for a previous existent
> application made in carbon, the application will take over the old
> app behavior, and for that, it needs to replace the menu with a new
> one...
> I read documentation, saw examples and followed old threads on this
> list, and no one is very clear about this... ¿Is it possible? ¿how?
You should make a nib from the "Application" template in Interface
Builder, then load it via [NSBundle loadNibNamed:...]. Its main menu
will replace the current main menu.>
> I already tried
>
> [ NSApp setMainMenu: myMenu ]
>
> It does not fail, but nothing happens :(
It's hard to say what this would do without seeing the code that
creates myMenu. But there's some problems creating a main menu
programmatically; using a nib is the best approach.
-Peter -
On Mon, Oct 13, 2008 at 8:18 AM, Esteban Lorenzano <estebanlm...> wrote:> I'm new to the list -and to cocoa-, and I don't know if what I want to do is
> possible: I'm writing a plugin for a previous existent application made in
> carbon, the application will take over the old app behavior, and for that,
> it needs to replace the menu with a new one...
There are certain things that you must do to start using Cocoa in a
Carbon app -- like calling NSApplicationLoad() and creating an
autorelease pool. Have you done this?
--Kyle Sluder -
Hi,
I loaded from Nib, as you suggest, and something strange happens -
strange, but near what I need-
If I load a Nib, the new main menu overlaps the old one (and two menus
coexist)... but new Main Menu redraws "apple" menu too, and disappear
if I reload the Nib. Finally, if I first "clean" carbon menu, and then
load bundle twice, everything seems to be working. This is the code I
wrote:
static sqInt initializeCocoaMenu(void) {
MenuRef cleanMenu;
//First we clean the carbon menu
CreateNewMenu(menuId, 0, &cleanMenu);
SetMenuTitleWithCFString(cleanMenu, CFSTR(""));
SetRootMenu(cleanMenu);
//Then we load the bundle
[ NSBundle loadNibNamed: @"MarsPlugin" owner: [ NSApplication
sharedApplication ] ];
//... twice
[ NSBundle loadNibNamed: @"MarsPlugin" owner: [ NSApplication
sharedApplication ] ];
return sqNil;
}
... but this is ok?
Thanks,
Esteban
On 13/10/2008, at 4:27p.m., Peter Ammon wrote:>
> On Oct 13, 2008, at 5:18 AM, Esteban Lorenzano wrote:
>
>> Hi,
>> I'm new to the list -and to cocoa-, and I don't know if what I want
>> to do is possible: I'm writing a plugin for a previous existent
>> application made in carbon, the application will take over the old
>> app behavior, and for that, it needs to replace the menu with a new
>> one...
>> I read documentation, saw examples and followed old threads on this
>> list, and no one is very clear about this... ¿Is it possible? ¿how?
>
> You should make a nib from the "Application" template in Interface
> Builder, then load it via [NSBundle loadNibNamed:...]. Its main
> menu will replace the current main menu.
>
>>
>> I already tried
>>
>> [ NSApp setMainMenu: myMenu ]
>>
>> It does not fail, but nothing happens :(
>
> It's hard to say what this would do without seeing the code that
> creates myMenu. But there's some problems creating a main menu
> programmatically; using a nib is the best approach.
>
> -Peter
>
"Querer es suscitar las paradojas"
Camus - El mito de SÃsifo -
I honestly don't know - replacing a Carbon main menu with a Cocoa main
menu at runtime isn't a configuration I've ever tested. If what you
tried works and you're happy with the result, I guess go with it.
-Peter
On Oct 14, 2008, at 7:09 AM, Esteban Lorenzano wrote:> Hi,
> I loaded from Nib, as you suggest, and something strange happens -
> strange, but near what I need-
>
> If I load a Nib, the new main menu overlaps the old one (and two
> menus coexist)... but new Main Menu redraws "apple" menu too, and
> disappear if I reload the Nib. Finally, if I first "clean" carbon
> menu, and then load bundle twice, everything seems to be working.
> This is the code I wrote:
>
> static sqInt initializeCocoaMenu(void) {
> MenuRef cleanMenu;
>
> //First we clean the carbon menu
> CreateNewMenu(menuId, 0, &cleanMenu);
> SetMenuTitleWithCFString(cleanMenu, CFSTR(""));
> SetRootMenu(cleanMenu);
> //Then we load the bundle
> [ NSBundle loadNibNamed: @"MarsPlugin" owner: [ NSApplication
> sharedApplication ] ];
> //... twice
> [ NSBundle loadNibNamed: @"MarsPlugin" owner: [ NSApplication
> sharedApplication ] ];
> return sqNil;
> }
>
> ... but this is ok?
>
> Thanks,
> Esteban
>
> On 13/10/2008, at 4:27p.m., Peter Ammon wrote:
>
>>
>> On Oct 13, 2008, at 5:18 AM, Esteban Lorenzano wrote:
>>
>>> Hi,
>>> I'm new to the list -and to cocoa-, and I don't know if what I
>>> want to do is possible: I'm writing a plugin for a previous
>>> existent application made in carbon, the application will take
>>> over the old app behavior, and for that, it needs to replace the
>>> menu with a new one...
>>> I read documentation, saw examples and followed old threads on
>>> this list, and no one is very clear about this... ¿Is it possible?
>>> ¿how?
>>
>> You should make a nib from the "Application" template in Interface
>> Builder, then load it via [NSBundle loadNibNamed:...]. Its main
>> menu will replace the current main menu.
>>
>>>
>>> I already tried
>>>
>>> [ NSApp setMainMenu: myMenu ]
>>>
>>> It does not fail, but nothing happens :(
>>
>> It's hard to say what this would do without seeing the code that
>> creates myMenu. But there's some problems creating a main menu
>> programmatically; using a nib is the best approach.
>>
>> -Peter
>>
>
> "Querer es suscitar las paradojas"
> Camus - El mito de SÃsifo
>


