colinf's patch to make the cursor be the dbl vertical arrow when over the track resiz...
[ardour2.git] / gtk2_ardour / cocoacarbon.mm
blob3036eb0ab61bc77d76b1e552ac6af861fab176ff
1 /*
2     Copyright (C) 2007 Paul Davis 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <string>
20 #include <ctype.h>
21 #include <stdlib.h>
22 #include <pbd/error.h>
23 #include <gtkmm2ext/gtkapplication.h>
24 #include <gdk/gdkquartz.h>
25 #undef check
26 #undef YES
27 #undef NO
29 #include "ardour_ui.h"
30 #include "actions.h"
31 #include "opts.h"
33 #include <CoreFoundation/CFLocale.h>
34 #import <CoreFoundation/CFString.h>
35 #import <Foundation/NSString.h>
36 #import <Foundation/NSAutoreleasePool.h>
38 using namespace std;
39 using namespace PBD;
41 void
42 ARDOUR_UI::platform_specific ()
44         gtk_application_ready ();
46         if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) {
47                 
48                 /* if invoked from the command line, make sure we're visible */
49                 
50                 [NSApp activateIgnoringOtherApps:1];
51         } 
54 void
55 ARDOUR_UI::platform_setup ()
59 bool
60 cocoa_open_url (const char* uri)
62         NSString* struri = [[NSString alloc] initWithUTF8String:uri];
63         NSURL* nsurl = [[NSURL alloc] initWithString:struri];
65         bool ret = [[NSWorkspace sharedWorkspace] openURL:nsurl];
67         [struri release];
68         [nsurl release];
70         return ret;
73 void
74 set_language_preference ()
76         if (g_getenv ("LANGUAGE") || g_getenv ("LC_ALL") || g_getenv ("LANG")) {
77                 return;
78         }
80         if (g_getenv ("ARDOUR_EN")) {
81                 return;
82         }
84         /* the gettext manual is potentially misleading about the utility of
85            LANGUAGE.  It notes that if LANGUAGE is set to include a dialect/region-free
86            language code, like "it", it will assume that you mean the main
87            dialect (e.g. "it_IT"). But in reality, it doesn't bother looking for
88            locale dirs with the full name, only the short code (it doesn't
89            know any better).
90            
91            Since Apple's preferred language list only consists of short language codes,
92            if we set LANGUAGE then gettext will not look for the relevant long-form
93            variants.
94         */
96         /* how to get language preferences with CoreFoundation
97          */
99         NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
100         
101         /* push into LANGUAGE */
103         if (languages && [languages count] > 0) {
105                 int i, count = [languages count];
106                 for (i = 0; i < count; ++i) {
107                         if ([[languages objectAtIndex:i]
108                              isEqualToString:@"en"]) {
109                                 count = i+1;
110                                 break;
111                         }
112                 }
113                 NSRange r = { 0, count };
114                 setenv ("LANGUAGE", [[[languages subarrayWithRange:r] componentsJoinedByString:@":"] UTF8String], 0);
115                 cout << "LANGUAGE set to " << getenv ("LANGUAGE") << endl;
116         }
118         /* now get AppleLocale value and use that for LANG */
120         CFLocaleRef cflocale = CFLocaleCopyCurrent();
121         NSString* nslocale = (NSString*) CFLocaleGetValue (cflocale, kCFLocaleIdentifier);
123         /* the full POSIX locale specification allows for lots of things. that could be an issue. Silly Apple.
124          */
126         cout << "LANG set to " << [nslocale UTF8String] << endl;
127         setenv ("LANG", [nslocale UTF8String], 0);
128         CFRelease (cflocale);