X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fcocoacarbon.mm;h=592a55d09dc97a619c1c00f0d9e85ad8a653d398;hb=b64dcac17ec6ab503198d933ef893760fb02ae22;hp=6317cec6c6a393e1e43fac8747d320f9542d231a;hpb=9f63ab9931e6478472853bdda58da47ea29ac125;p=ardour.git diff --git a/gtk2_ardour/cocoacarbon.mm b/gtk2_ardour/cocoacarbon.mm index 6317cec6c6..592a55d09d 100644 --- a/gtk2_ardour/cocoacarbon.mm +++ b/gtk2_ardour/cocoacarbon.mm @@ -16,109 +16,93 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include -#undef check // stupid, stupid carbon -#undef YES // stupid, stupid gtkmm and/or NSObjC -#undef NO // ditto +#include +#include +#include +#include +#include +#include +#undef check +#undef YES +#undef NO +#ifdef verify +#undef verify +#endif #include "ardour_ui.h" #include "actions.h" #include "opts.h" -#include "sync-menu.h" -#include +#include +#import +#import +#import -sigc::signal ApplicationActivationChanged; -static EventHandlerRef application_event_handler_ref; +using namespace std; +using namespace PBD; -/* Called for clicks on the dock icon. Can be used to unminimize or - * create a new window for example. - */ - -static OSErr -handle_reopen_application (const AppleEvent *inAppleEvent, - AppleEvent *outAppleEvent, - long inHandlerRefcon) +bool +cocoa_open_url (const char* uri) { - cerr << "reopen app\n"; - return noErr; -} + NSString* struri = [[NSString alloc] initWithUTF8String:uri]; + NSURL* nsurl = [[NSURL alloc] initWithString:struri]; -static OSErr -handle_quit_application (const AppleEvent *inAppleEvent, - AppleEvent *outAppleEvent, - long inHandlerRefcon) -{ - cerr << "quit app\n"; - ARDOUR_UI::instance()->quit (); + bool ret = [[NSWorkspace sharedWorkspace] openURL:nsurl]; - return noErr; -} + [struri release]; + [nsurl release]; -static OSStatus -application_event_handler (EventHandlerCallRef nextHandlerRef, EventRef event, void *userData) -{ - UInt32 eventKind = GetEventKind (event); - - switch (eventKind) { - case kEventAppActivated: - ApplicationActivationChanged (true); // EMIT SIGNAL - return eventNotHandledErr; - - case kEventAppDeactivated: - ApplicationActivationChanged (false); // EMIT SIGNAL - return eventNotHandledErr; - - default: - // pass-thru all kEventClassApplication events we're not interested in. - break; - } - return eventNotHandledErr; + return ret; } void -ARDOUR_UI::platform_specific () +set_language_preference () { - AEInstallEventHandler (kCoreEventClass, kAEReopenApplication, - handle_reopen_application, 0, true); - - AEInstallEventHandler (kCoreEventClass, kAEQuitApplication, - handle_quit_application, 0, true); - - Gtk::Widget* widget = ActionManager::get_widget ("/ui/Main/Session/Quit"); - if (widget) { - ige_mac_menu_set_quit_menu_item ((GtkMenuItem*) widget->gobj()); + gtk_disable_setlocale (); + + /* the gettext manual is potentially misleading about the utility of + LANGUAGE. It notes that if LANGUAGE is set to include a dialect/region-free + language code, like "it", it will assume that you mean the main + dialect (e.g. "it_IT"). But in reality, it doesn't bother looking for + locale dirs with the full name, only the short code (it doesn't + know any better). + + Since Apple's preferred language list only consists of short language codes, + if we set LANGUAGE then gettext will not look for the relevant long-form + variants. + */ + + /* how to get language preferences with CoreFoundation + */ + + NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]; + + /* push into LANGUAGE */ + + if (languages && [languages count] > 0) { + + int i, count = [languages count]; + for (i = 0; i < count; ++i) { + if ([[languages objectAtIndex:i] + isEqualToString:@"en"]) { + count = i+1; + break; + } + } + NSRange r = { 0, static_cast (count) }; + setenv ("LANGUAGE", [[[languages subarrayWithRange:r] componentsJoinedByString:@":"] UTF8String], 0); + cout << "LANGUAGE set to " << getenv ("LANGUAGE") << endl; } - IgeMacMenuGroup* group = ige_mac_menu_add_app_menu_group (); + /* now get AppleLocale value and use that for LANG */ - widget = ActionManager::get_widget ("/ui/Main/Session/About"); - if (widget) { - ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0); - } - widget = ActionManager::get_widget ("/ui/Main/Session/ToggleOptionsEditor"); - if (widget) { - ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0); - } + CFLocaleRef cflocale = CFLocaleCopyCurrent(); + NSString* nslocale = (NSString*) CFLocaleGetValue (cflocale, kCFLocaleIdentifier); - EventTypeSpec applicationEventTypes[] = { - {kEventClassApplication, kEventAppActivated }, - {kEventClassApplication, kEventAppDeactivated } - }; - - EventHandlerUPP ehUPP = NewEventHandlerUPP (application_event_handler); - - InstallApplicationEventHandler (ehUPP, sizeof(applicationEventTypes) / sizeof(EventTypeSpec), - applicationEventTypes, 0, &application_event_handler_ref); -} + /* the full POSIX locale specification allows for lots of things. that could be an issue. Silly Apple. + */ -void -ARDOUR_UI::platform_setup () -{ - if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) { - - /* if invoked from the command line, make sure we're visible */ - - [NSApp activateIgnoringOtherApps:1]; - } + cout << "LANG set to " << [nslocale UTF8String] << endl; + setenv ("LANG", [nslocale UTF8String], 0); + CFRelease (cflocale); }