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
24 #include "ardour_ui.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.
40 handle_reopen_application (const AppleEvent *inAppleEvent,
41 AppleEvent *outAppleEvent,
49 handle_print_documents (const AppleEvent *inAppleEvent,
50 AppleEvent *outAppleEvent,
58 handle_open_documents (const AppleEvent *inAppleEvent,
59 AppleEvent *outAppleEvent,
64 if (AEGetParamDesc(inAppleEvent, keyDirectObject, typeAEList, &docs) == noErr) {
66 AECountItems(&docs, &n);
67 UInt8 strBuffer[PATH_MAX+1];
69 /* ardour only opens 1 session at a time */
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);
85 handle_open_application (const AppleEvent *inAppleEvent,
86 AppleEvent *outAppleEvent,
93 application_event_handler (EventHandlerCallRef nextHandlerRef, EventRef event, void *userData)
95 UInt32 eventKind = GetEventKind (event);
98 case kEventAppActivated:
99 ApplicationActivationChanged (true); // EMIT SIGNAL
100 return eventNotHandledErr;
102 case kEventAppDeactivated:
103 ApplicationActivationChanged (false); // EMIT SIGNAL
104 return eventNotHandledErr;
107 // pass-thru all kEventClassApplication events we're not interested in.
110 return eventNotHandledErr;
114 ARDOUR_UI::platform_specific ()
116 Gtk::Widget* widget = ActionManager::get_widget ("/ui/Main/Session/Quit");
118 ige_mac_menu_set_quit_menu_item ((GtkMenuItem*) widget->gobj());
121 IgeMacMenuGroup* group = ige_mac_menu_add_app_menu_group ();
123 widget = ActionManager::get_widget ("/ui/Main/Session/About");
125 ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0);
127 widget = ActionManager::get_widget ("/ui/Main/Session/ToggleOptionsEditor");
130 ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0);
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 }
154 EventHandlerUPP ehUPP = NewEventHandlerUPP (application_event_handler);
156 InstallApplicationEventHandler (ehUPP, sizeof(applicationEventTypes) / sizeof(EventTypeSpec),
157 applicationEventTypes, 0, &application_event_handler_ref);
158 if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) {
160 /* if invoked from the command line, make sure we're visible */
162 [NSApp activateIgnoringOtherApps:1];
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];