OSC: Changed gainVCA to gainfader as VCA is already used.
[ardour.git] / gtk2_ardour / cocoacarbon.mm
1 /*
2     Copyright (C) 2007 Paul Davis 
3
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.
8
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.
13
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.
17 */
18
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
28 #ifdef verify
29 #undef verify
30 #endif
31
32 #include "ardour_ui.h"
33 #include "actions.h"
34 #include "opts.h"
35
36 #include <CoreFoundation/CFLocale.h>
37 #import <CoreFoundation/CFString.h>
38 #import <Foundation/NSString.h>
39 #import <Foundation/NSAutoreleasePool.h>
40
41 using namespace std;
42 using namespace PBD;
43
44 void
45 ARDOUR_UI::platform_specific ()
46 {
47         gtk_application_ready ();
48
49         if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) {
50                 
51                 /* if invoked from the command line, make sure we're visible */
52                 
53                 [NSApp activateIgnoringOtherApps:1];
54         } 
55 }
56
57 void
58 ARDOUR_UI::platform_setup ()
59 {
60 }
61
62 bool
63 cocoa_open_url (const char* uri)
64 {
65         NSString* struri = [[NSString alloc] initWithUTF8String:uri];
66         NSURL* nsurl = [[NSURL alloc] initWithString:struri];
67
68         bool ret = [[NSWorkspace sharedWorkspace] openURL:nsurl];
69
70         [struri release];
71         [nsurl release];
72
73         return ret;
74 }
75
76 void
77 set_language_preference ()
78 {
79         gtk_disable_setlocale ();
80
81         /* the gettext manual is potentially misleading about the utility of
82            LANGUAGE.  It notes that if LANGUAGE is set to include a dialect/region-free
83            language code, like "it", it will assume that you mean the main
84            dialect (e.g. "it_IT"). But in reality, it doesn't bother looking for
85            locale dirs with the full name, only the short code (it doesn't
86            know any better).
87            
88            Since Apple's preferred language list only consists of short language codes,
89            if we set LANGUAGE then gettext will not look for the relevant long-form
90            variants.
91         */
92
93         /* how to get language preferences with CoreFoundation
94          */
95
96         NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
97         
98         /* push into LANGUAGE */
99
100         if (languages && [languages count] > 0) {
101
102                 int i, count = [languages count];
103                 for (i = 0; i < count; ++i) {
104                         if ([[languages objectAtIndex:i]
105                              isEqualToString:@"en"]) {
106                                 count = i+1;
107                                 break;
108                         }
109                 }
110                 NSRange r = { 0, static_cast<NSUInteger> (count) };
111                 setenv ("LANGUAGE", [[[languages subarrayWithRange:r] componentsJoinedByString:@":"] UTF8String], 0);
112                 cout << "LANGUAGE set to " << getenv ("LANGUAGE") << endl;
113         }
114
115         /* now get AppleLocale value and use that for LANG */
116
117         CFLocaleRef cflocale = CFLocaleCopyCurrent();
118         NSString* nslocale = (NSString*) CFLocaleGetValue (cflocale, kCFLocaleIdentifier);
119
120         /* the full POSIX locale specification allows for lots of things. that could be an issue. Silly Apple.
121          */
122
123         cout << "LANG set to " << [nslocale UTF8String] << endl;
124         setenv ("LANG", [nslocale UTF8String], 0);
125         CFRelease (cflocale);
126 }