From 816fc3b9718c8c407a41d7e0a5d400b5f3ed07b6 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Tue, 1 Feb 2011 21:31:57 +0000 Subject: Mac OS only: added class Fl_Mac_App_Menu to support localization of the application menu. Added corresponding Doxygen doc. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8357 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/mac.H | 41 ++++++++++++++++++++++++--- documentation/src/osissues.dox | 20 +++++++------ src/Fl_cocoa.mm | 64 ++++++++++++++++++++++++++++-------------- 3 files changed, 91 insertions(+), 34 deletions(-) diff --git a/FL/mac.H b/FL/mac.H index 98d7bb2c1..7190c8360 100644 --- a/FL/mac.H +++ b/FL/mac.H @@ -185,11 +185,13 @@ extern void fl_open_display(); #endif // FL_DOXYGEN -/** \defgroup group_macosx Mac OS X-specific functions - Mac OS X-specific functions declared in or +/** \defgroup group_macosx Mac OS X-specific symbols + Mac OS X-specific symbols declared in or @{ */ -/** @brief Register a function called for each file dropped onto an application icon +/** @brief Register a function called for each file dropped onto an application icon. + \e cb will be called with a single Unix-style file name and path. + If multiple files were dropped, \e cb will be called multiple times. */ extern void fl_open_callback(void (*cb)(const char *)); @@ -205,7 +207,38 @@ extern void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut = 0 /** \brief The version number of the running Mac OS X (e.g., 0x1064 for 10.6.4) */ -extern int fl_mac_os_version; +extern int fl_mac_os_version; + +/** To localize the application menu. + + These character strings are used to build the application menu. They can be localized + at run time to any UTF-8 text by placing instructions such as these \e very + early in the program: + \verbatim + #include + Fl_Mac_App_Menu::print = "Imprimer la fenĂȘtre"; + \endverbatim + */ +class Fl_Mac_App_Menu { +public: + /** Localizable text for the "About xxx" application menu item */ + static const char *about; + /** Localizable text for the "Print Front Window" application menu item. + This menu item won't be displayed if Fl_Mac_App_Menu::print + is set to an empty string. + */ + static const char *print; + /** Localizable text for the "Services" application menu item */ + static const char *services; + /** Localizable text for the "Hide xxx" application menu item */ + static const char *hide; + /** Localizable text for the "Hide Others" application menu item */ + static const char *hide_others; + /** Localizable text for the "Show All" application menu item */ + static const char *show; + /** Localizable text for the "Quit xxx" application menu item */ + static const char *quit; +}; /** @} */ diff --git a/documentation/src/osissues.dox b/documentation/src/osissues.dox index 45272ef71..363e278d7 100644 --- a/documentation/src/osissues.dox +++ b/documentation/src/osissues.dox @@ -2,7 +2,11 @@ \page osissues Operating System Issues -This appendix describes the operating system specific interfaces in FLTK. +This appendix describes the operating system specific interfaces in FLTK: +\li \ref osissues_accessing +\li \ref osissues_unit +\li \ref osissues_win32 +\li \ref osissues_macos \section osissues_accessing Accessing the OS Interfaces @@ -676,7 +680,8 @@ Apple "Open" Event \par Whenever the user drops a file onto an application icon, OS X generates an Apple Event of the type "Open". You can have FLTK -notify you of an Open event by setting the \c fl_open_callback +notify you of an Open event by calling the \ref fl_open_callback +function. void fl_open_display() @@ -699,19 +704,16 @@ Returns the Fl_Window that corresponds to the given window reference, or \c NULL if not found. FLTK windows that are children of top-level windows share the \c Window of the top-level window. -void \ref fl_open_callback(void (*cb)(const char *)) - -\par -\c cb will be called with a single Unix-style file name and path. -If multiple files were dropped, \c fl_open_callback() will be called -multiple times. - void fl_mac_set_about( Fl_Callback *cb, void *user_data, int shortcut) \par Attaches the callback \c cb to the "About myprog" item of the system application menu. \c cb will be called with NULL first argument and \c user_data second argument. +Fl_Mac_App_Menu class +\par +The Fl_Mac_App_Menu class allows to localize the application menu. + Fl_Sys_Menu_Bar class \par diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index fd9073e77..05eff18e7 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -2789,6 +2789,7 @@ int Fl_X::screen_init(XRectangle screens[], float dpi[]) if ((float)h/win->h() < scale) scale = (float)h/win->h(); printer.scale(scale, scale); } +//#define ROTATE 1 #ifdef ROTATE printer.scale(scale * 0.8, scale * 0.8); printer.printable_rect(&w, &h); @@ -2804,6 +2805,14 @@ int Fl_X::screen_init(XRectangle screens[], float dpi[]) } @end +const char *Fl_Mac_App_Menu::about = "About "; +const char *Fl_Mac_App_Menu::print = "Print Front Window"; +const char *Fl_Mac_App_Menu::services = "Services"; +const char *Fl_Mac_App_Menu::hide = "Hide "; +const char *Fl_Mac_App_Menu::hide_others = "Hide Others"; +const char *Fl_Mac_App_Menu::show = "Show All"; +const char *Fl_Mac_App_Menu::quit = "Quit "; + static NSMenu *appleMenu; static void createAppleMenu(void) { @@ -2813,41 +2822,55 @@ static void createAppleMenu(void) NSMenu *mainmenu, *services; NSMenuItem *menuItem; NSString *title; - CFStringRef nsappname; - - ProcessSerialNumber psn; - GetCurrentProcess(&psn); - CopyProcessName(&psn, &nsappname); + + NSString *nsappname = [[NSProcessInfo processInfo] processName]; appleMenu = [[NSMenu alloc] initWithTitle:@""]; /* Add menu items */ - title = [@"About " stringByAppendingString:(NSString*)nsappname]; + title = [[NSString stringWithUTF8String:Fl_Mac_App_Menu::about] stringByAppendingString:nsappname]; menuItem = [appleMenu addItemWithTitle:title action:@selector(showPanel) keyEquivalent:@""]; FLaboutItemTarget *about = [[FLaboutItemTarget alloc] init]; [menuItem setTarget:about]; [appleMenu addItem:[NSMenuItem separatorItem]]; // Print front window - menuItem = [appleMenu addItemWithTitle:@"Print front window" action:@selector(printPanel) keyEquivalent:@""]; - [menuItem setTarget:about]; - [appleMenu setAutoenablesItems:NO]; - [menuItem setEnabled:YES]; - [appleMenu addItem:[NSMenuItem separatorItem]]; + if (strlen(Fl_Mac_App_Menu::print) > 0) { + menuItem = [appleMenu + addItemWithTitle:[NSString stringWithUTF8String:Fl_Mac_App_Menu::print] + action:@selector(printPanel) + keyEquivalent:@""]; + [menuItem setTarget:about]; + [appleMenu setAutoenablesItems:NO]; + [menuItem setEnabled:YES]; + [appleMenu addItem:[NSMenuItem separatorItem]]; + } // Services Menu services = [[NSMenu alloc] init]; - [appleMenu addItemWithTitle:@"Services" action:nil keyEquivalent:@""]; - [appleMenu setSubmenu: services forItem: [appleMenu itemWithTitle: @"Services"]]; + menuItem = [appleMenu + addItemWithTitle:[NSString stringWithUTF8String:Fl_Mac_App_Menu::services] + action:nil + keyEquivalent:@""]; + [appleMenu setSubmenu:services forItem:menuItem]; + [appleMenu addItem:[NSMenuItem separatorItem]]; // Hide AppName - title = [@"Hide " stringByAppendingString:(NSString*)nsappname]; - [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"]; + title = [[NSString stringWithUTF8String:Fl_Mac_App_Menu::hide] stringByAppendingString:nsappname]; + [appleMenu addItemWithTitle:title + action:@selector(hide:) + keyEquivalent:@"h"]; // Hide Others - menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) - keyEquivalent:@"h"]; + menuItem = [appleMenu + addItemWithTitle:[NSString stringWithUTF8String:Fl_Mac_App_Menu::hide_others] + action:@selector(hideOtherApplications:) + keyEquivalent:@"h"]; [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; // Show All - [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; + [appleMenu addItemWithTitle:[NSString stringWithUTF8String:Fl_Mac_App_Menu::show] + action:@selector(unhideAllApplications:) keyEquivalent:@""]; [appleMenu addItem:[NSMenuItem separatorItem]]; // Quit AppName - title = [@"Quit " stringByAppendingString:(NSString*)nsappname]; - [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"]; + title = [[NSString stringWithUTF8String:Fl_Mac_App_Menu::quit] + stringByAppendingString:nsappname]; + [appleMenu addItemWithTitle:title + action:@selector(terminate:) + keyEquivalent:@"q"]; /* Put menu into the menubar */ menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; [menuItem setSubmenu:appleMenu]; @@ -2860,7 +2883,6 @@ static void createAppleMenu(void) } [NSApp setServicesMenu:services]; [NSApp setMainMenu:mainmenu]; - CFRelease(nsappname); [services release]; [mainmenu release]; [appleMenu release]; -- cgit v1.2.3