Recent

Author Topic: Add a menu item to the application menu  (Read 11884 times)

havezet

  • New Member
  • *
  • Posts: 26
Add a menu item to the application menu
« on: November 16, 2010, 08:27:38 am »
This is probably a newbie question so my apologies if I overlooked the obvious.

How can I add a menu item to the application menu in MacOS? So I mean the menu titled after the application that appears at the far left, directly next to the apple menu when my application is running. I'd like to include an About menu entry there as is common in MacOS applications.

Thank you

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Add a menu item to the application menu
« Reply #1 on: November 16, 2010, 12:56:17 pm »
If you're doing cross-platform development and already have an About menu item elsewhere (e.g., on Help menu as in Windows), here's example code from this project:

http://wiki.lazarus.freepascal.org/THtmlPort

In main form declaration:

{$IFDEF LCLCarbon}
    AppMenu : TMenuItem;
{$ENDIF}

In FormCreate handler:

{$IFDEF LCLCarbon}
  AppMenu := TMenuItem.Create(Self);  //Application menu
  AppMenu.Caption := #$EF#$A3#$BF;  //Unicode Apple logo char
  MainMenu1.Items.Insert(0, AppMenu);
  MainMenu1.Items.Remove(About1);  //Remove About as separate menu
  AppMenu.Add(About1);  //Add About as item in application menu
{$ENDIF}


I'm preparing an article on this and other things that need to be done specially on Mac with Lazarus.

Thanks.

-Phil

havezet

  • New Member
  • *
  • Posts: 26
Re: Add a menu item to the application menu
« Reply #2 on: November 16, 2010, 01:50:59 pm »
Thanks Phil. Works like a charm!

kamischi

  • Full Member
  • ***
  • Posts: 177
Re: Add a menu item to the application menu
« Reply #3 on: November 16, 2010, 03:19:21 pm »
My code snippet for the about menu:

http://developer.berlios.de/snippet/detail.php?type=snippet&id=100054

Have fun.

Mischi
fpc 2.6.4, lazarus 1.4.0, Mac OS X, fink

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Add a menu item to the application menu
« Reply #4 on: November 16, 2010, 03:26:55 pm »
http://developer.berlios.de/snippet/detail.php?type=snippet&id=100054

1. You could use VK_OEM_COMMA instead of $BC to make it clearer.

2. Preferences item normally does not have an ellipsis.

3. About item should include bundle name (app name).

Thanks.

-Phil
« Last Edit: November 17, 2010, 01:02:41 am by Phil »

kamischi

  • Full Member
  • ***
  • Posts: 177
Re: Add a menu item to the application menu
« Reply #5 on: November 17, 2010, 07:19:30 pm »
Hi Phil

Thanks for the feedback. I'll fix number 1 and 3, but it may take some time :-)

However, regarding point 2, the ellipsis (...), I checked a number of programs (Safari, iTunes, iCal, Mail, Colloquy, ...) on Mac OS X 10.6, German, and all have "..." after Preferences or the localized version "Einstellungen". The only one without "..." was good old Appleworks :-) The only difference I found is that some have a blank before "..." and some don't. Is this a localization thing?

Greetings Michael
fpc 2.6.4, lazarus 1.4.0, Mac OS X, fink

Phil

  • Hero Member
  • *****
  • Posts: 2737
Re: Add a menu item to the application menu
« Reply #6 on: November 17, 2010, 10:04:05 pm »
Yes, you're right and I'm wrong. I guess I shouldn't try to recall anything from memory (wasn't at my Mac when I wrote that).

Thanks.

-Phil

 

TinyPortal © 2005-2018