fix mis-handling of button press events on rec-enable that ought to forward to Bindab...
[ardour2.git] / gtk2_ardour / cocoacarbon.mm
blobe4f833dd26e98131d544f677ff33d9213dd9aae7
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 <Carbon/Carbon.h>
20 #undef check // stupid, stupid carbon
21 #undef YES   // stupid, stupid gtkmm and/or NSObjC
22 #undef NO    // ditto
24 #include "ardour_ui.h"
25 #include "actions.h"
26 #include "opts.h"
27 #include <gtkmm2ext/sync-menu.h>
29 #include <Appkit/Appkit.h>
30 #include <gdk/gdkquartz.h>
32 sigc::signal<void,bool> ApplicationActivationChanged;
33 static EventHandlerRef  application_event_handler_ref;
35 /* Called for clicks on the dock icon. Can be used to unminimize or
36  * create a new window for example.
37  */
39 static OSErr
40 handle_reopen_application (const AppleEvent *inAppleEvent, 
41                            AppleEvent       *outAppleEvent, 
42                            long              inHandlerRefcon)
44         return noErr;
48 static OSErr
49 handle_print_documents (const AppleEvent *inAppleEvent, 
50                            AppleEvent       *outAppleEvent, 
51                            long              inHandlerRefcon)
53         return noErr;
57 static OSErr
58 handle_open_documents (const AppleEvent *inAppleEvent, 
59                        AppleEvent       *outAppleEvent, 
60                        long              inHandlerRefcon)
62         AEDescList docs;
64         if (AEGetParamDesc(inAppleEvent, keyDirectObject, typeAEList, &docs) == noErr) {
65                 long n = 0;
66                 AECountItems(&docs, &n);
67                 UInt8 strBuffer[PATH_MAX+1];
69                 /* ardour only opens 1 session at a time */
71                 FSRef ref;
73                 if (AEGetNthPtr(&docs, 1, typeFSRef, 0, 0, &ref, sizeof(ref), 0) == noErr) {
74                         if (FSRefMakePath(&ref, strBuffer, sizeof(strBuffer)) == noErr) {
75                                 Glib::ustring utf8_path ((const char*) strBuffer);
76                                 ARDOUR_UI::instance()->idle_load (utf8_path);
77                         }
78                 }
79         }
81         return noErr;
84 static OSErr
85 handle_open_application (const AppleEvent *inAppleEvent, 
86                          AppleEvent       *outAppleEvent, 
87                          long              inHandlerRefcon)
89         return noErr;
92 static OSStatus 
93 application_event_handler (EventHandlerCallRef nextHandlerRef, EventRef event, void *userData) 
95         UInt32 eventKind = GetEventKind (event);
96         
97         switch (eventKind) {
98         case kEventAppActivated:
99                 ApplicationActivationChanged (true); // EMIT SIGNAL
100                 return eventNotHandledErr;
102         case kEventAppDeactivated:
103                 ApplicationActivationChanged (false); // EMIT SIGNAL
104                 return eventNotHandledErr;
105                 
106         default:
107                 // pass-thru all kEventClassApplication events we're not interested in.
108                 break;
109         }
110         return eventNotHandledErr;
113 void
114 ARDOUR_UI::platform_specific ()
116         Gtk::Widget* widget = ActionManager::get_widget ("/ui/Main/Session/Quit");
117         if (widget) {
118                 ige_mac_menu_set_quit_menu_item ((GtkMenuItem*) widget->gobj());
119         }
121         IgeMacMenuGroup* group = ige_mac_menu_add_app_menu_group ();
123         widget = ActionManager::get_widget ("/ui/Main/Session/About");
124         if (widget) {
125                 ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0);
126         }
127         widget = ActionManager::get_widget ("/ui/Main/Session/ToggleOptionsEditor");
129         if (widget) {
130                 ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0);
131         }
134 void
135 ARDOUR_UI::platform_setup ()
137         AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments, 
138                                handle_open_documents, 0, true);
140         AEInstallEventHandler (kCoreEventClass, kAEOpenApplication, 
141                                handle_open_application, 0, true);
143         AEInstallEventHandler (kCoreEventClass, kAEReopenApplication, 
144                                handle_reopen_application, 0, true);
146         AEInstallEventHandler (kCoreEventClass, kAEPrintDocuments, 
147                                handle_print_documents, 0, true);
149         EventTypeSpec applicationEventTypes[] = {
150                 {kEventClassApplication, kEventAppActivated },
151                 {kEventClassApplication, kEventAppDeactivated }
152         };      
153         
154         EventHandlerUPP ehUPP = NewEventHandlerUPP (application_event_handler);
155         
156         InstallApplicationEventHandler (ehUPP, sizeof(applicationEventTypes) / sizeof(EventTypeSpec), 
157                                         applicationEventTypes, 0, &application_event_handler_ref);
158         if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) {
159                 
160                 /* if invoked from the command line, make sure we're visible */
161                 
162                 [NSApp activateIgnoringOtherApps:1];
163         } 
166 bool
167 cocoa_open_url (const char* uri)
169         NSString* struri = [[NSString alloc] initWithUTF8String:uri];
170         NSURL* nsurl = [[NSURL alloc] initWithString:struri];
172         bool ret = [[NSWorkspace sharedWorkspace] openURL:nsurl];
174         [struri release];
175         [nsurl release];
177         return ret;