summaryrefslogtreecommitdiff
path: root/gtk2_ardour/cocoacarbon.mm
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-11-13 05:14:48 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-11-13 05:14:48 +0000
commitb85b4d9e54caef0585d308ef3bffee21d0e5ae56 (patch)
treea1ebeec149a57be4589ad6cabcd26c597703407c /gtk2_ardour/cocoacarbon.mm
parent520bc1bed49720333eb1a2be3ea0f813ccaac182 (diff)
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
Diffstat (limited to 'gtk2_ardour/cocoacarbon.mm')
-rw-r--r--gtk2_ardour/cocoacarbon.mm215
1 files changed, 80 insertions, 135 deletions
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 <Carbon/Carbon.h>
-#undef check // stupid, stupid carbon
-#undef YES // stupid, stupid gtkmm and/or NSObjC
-#undef NO // ditto
-
-#ifdef GTKOSX
-#include <objc/objc.h>
-#ifdef nil
- /*Stupid OS X defining nil*/
-#undef nil
-#endif
-#endif
+#include <string>
+#include <ctype.h>
+#include <stdlib.h>
+#include <pbd/error.h>
+#include <gtkmm2ext/gtkapplication.h>
+#include <gdk/gdkquartz.h>
+#undef check
+#undef YES
+#undef NO
#include "ardour_ui.h"
#include "actions.h"
#include "opts.h"
-#include <gtkmm2ext/sync-menu.h>
-
-#include <Appkit/Appkit.h>
-#include <gdk/gdkquartz.h>
-sigc::signal<void,bool> ApplicationActivationChanged;
-static EventHandlerRef application_event_handler_ref;
+#include <CoreFoundation/CFLocale.h>
+#import <CoreFoundation/CFString.h>
+#import <Foundation/NSString.h>
+#import <Foundation/NSAutoreleasePool.h>
-/* 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);
}