From b85b4d9e54caef0585d308ef3bffee21d0e5ae56 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 13 Nov 2010 05:14:48 +0000 Subject: make ardour3 build and link on OS X (tiger, at least) git-svn-id: svn://localhost/ardour2/branches/3.0@8018 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/cocoacarbon.mm | 215 +++++++++++++++++---------------------------- 1 file changed, 80 insertions(+), 135 deletions(-) (limited to 'gtk2_ardour/cocoacarbon.mm') diff --git a/gtk2_ardour/cocoacarbon.mm b/gtk2_ardour/cocoacarbon.mm index 84e34bd74d..072008e9a1 100644 --- a/gtk2_ardour/cocoacarbon.mm +++ b/gtk2_ardour/cocoacarbon.mm @@ -16,171 +16,116 @@ 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 - -#ifdef GTKOSX -#include -#ifdef nil - /*Stupid OS X defining nil*/ -#undef nil -#endif -#endif +#include +#include +#include +#include +#include +#include +#undef check +#undef YES +#undef NO #include "ardour_ui.h" #include "actions.h" #include "opts.h" -#include - -#include -#include -sigc::signal ApplicationActivationChanged; -static EventHandlerRef application_event_handler_ref; +#include +#import +#import +#import -/* Called for clicks on the dock icon. Can be used to unminimize or - * create a new window for example. - */ +using namespace std; +using namespace PBD; -static OSErr -handle_reopen_application (const AppleEvent *inAppleEvent, - AppleEvent *outAppleEvent, - long inHandlerRefcon) +void +ARDOUR_UI::platform_specific () { - return noErr; -} + gtk_application_ready (); + if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) { + + /* if invoked from the command line, make sure we're visible */ + + [NSApp activateIgnoringOtherApps:1]; + } +} -static OSErr -handle_print_documents (const AppleEvent *inAppleEvent, - AppleEvent *outAppleEvent, - long inHandlerRefcon) +void +ARDOUR_UI::platform_setup () { - return noErr; } - -static OSErr -handle_open_documents (const AppleEvent *inAppleEvent, - AppleEvent *outAppleEvent, - long inHandlerRefcon) +bool +cocoa_open_url (const char* uri) { - AEDescList docs; - - if (AEGetParamDesc(inAppleEvent, keyDirectObject, typeAEList, &docs) == noErr) { - long n = 0; - AECountItems(&docs, &n); - UInt8 strBuffer[PATH_MAX+1]; - - /* ardour only opens 1 session at a time */ - - FSRef ref; - - if (AEGetNthPtr(&docs, 1, typeFSRef, 0, 0, &ref, sizeof(ref), 0) == noErr) { - if (FSRefMakePath(&ref, strBuffer, sizeof(strBuffer)) == noErr) { - Glib::ustring utf8_path ((const char*) strBuffer); - ARDOUR_UI::instance()->idle_load (utf8_path); - } - } - } + NSString* struri = [[NSString alloc] initWithUTF8String:uri]; + NSURL* nsurl = [[NSURL alloc] initWithString:struri]; - return noErr; -} + bool ret = [[NSWorkspace sharedWorkspace] openURL:nsurl]; -static OSErr -handle_open_application (const AppleEvent *inAppleEvent, - AppleEvent *outAppleEvent, - long inHandlerRefcon) -{ - 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 () { - 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 (); - IgeMacMenuGroup* group = ige_mac_menu_add_app_menu_group (); - - widget = ActionManager::get_widget ("/ui/Main/Session/About"); - if (widget) { - ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0); + if (g_getenv ("LANGUAGE") || g_getenv ("LC_ALL") || g_getenv ("LANG")) { + return; } - widget = ActionManager::get_widget ("/ui/Main/Session/ToggleOptionsEditor"); - if (widget) { - ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0); + if (g_getenv ("ARDOUR_EN")) { + return; } -} -void -ARDOUR_UI::platform_setup () -{ - AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments, - handle_open_documents, 0, true); - - AEInstallEventHandler (kCoreEventClass, kAEOpenApplication, - handle_open_application, 0, true); - - AEInstallEventHandler (kCoreEventClass, kAEReopenApplication, - handle_reopen_application, 0, true); + /* 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 */ - AEInstallEventHandler (kCoreEventClass, kAEPrintDocuments, - handle_print_documents, 0, true); + if (languages && [languages count] > 0) { - EventTypeSpec applicationEventTypes[] = { - {kEventClassApplication, kEventAppActivated }, - {kEventClassApplication, kEventAppDeactivated } - }; - - EventHandlerUPP ehUPP = NewEventHandlerUPP (application_event_handler); - - InstallApplicationEventHandler (ehUPP, sizeof(applicationEventTypes) / sizeof(EventTypeSpec), - applicationEventTypes, 0, &application_event_handler_ref); - if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) { - - /* if invoked from the command line, make sure we're visible */ - - [NSApp activateIgnoringOtherApps:1]; - } -} + int i, count = [languages count]; + for (i = 0; i < count; ++i) { + if ([[languages objectAtIndex:i] + isEqualToString:@"en"]) { + count = i+1; + break; + } + } + NSRange r = { 0, count }; + setenv ("LANGUAGE", [[[languages subarrayWithRange:r] componentsJoinedByString:@":"] UTF8String], 0); + cout << "LANGUAGE set to " << getenv ("LANGUAGE") << endl; + } -bool -cocoa_open_url (const char* uri) -{ - NSString* struri = [[NSString alloc] initWithUTF8String:uri]; - NSURL* nsurl = [[NSURL alloc] initWithString:struri]; + /* now get AppleLocale value and use that for LANG */ - bool ret = [[NSWorkspace sharedWorkspace] openURL:nsurl]; + CFLocaleRef cflocale = CFLocaleCopyCurrent(); + NSString* nslocale = (NSString*) CFLocaleGetValue (cflocale, kCFLocaleIdentifier); - [struri release]; - [nsurl release]; + /* the full POSIX locale specification allows for lots of things. that could be an issue. Silly Apple. + */ - return ret; + cout << "LANG set to " << [nslocale UTF8String] << endl; + setenv ("LANG", [nslocale UTF8String], 0); + CFRelease (cflocale); } -- cgit v1.2.3