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
25 #include <objc/objc.h>
27 /*Stupid OS X defining nil*/
32 #include "ardour_ui.h"
35 #include <gtkmm2ext/sync-menu.h>
37 #include <Appkit/Appkit.h>
38 #include <gdk/gdkquartz.h>
40 sigc::signal<void,bool> ApplicationActivationChanged;
41 static EventHandlerRef application_event_handler_ref;
43 /* Called for clicks on the dock icon. Can be used to unminimize or
44 * create a new window for example.
48 handle_reopen_application (const AppleEvent *inAppleEvent,
49 AppleEvent *outAppleEvent,
57 handle_print_documents (const AppleEvent *inAppleEvent,
58 AppleEvent *outAppleEvent,
66 handle_open_documents (const AppleEvent *inAppleEvent,
67 AppleEvent *outAppleEvent,
72 if (AEGetParamDesc(inAppleEvent, keyDirectObject, typeAEList, &docs) == noErr) {
74 AECountItems(&docs, &n);
75 UInt8 strBuffer[PATH_MAX+1];
77 /* ardour only opens 1 session at a time */
81 if (AEGetNthPtr(&docs, 1, typeFSRef, 0, 0, &ref, sizeof(ref), 0) == noErr) {
82 if (FSRefMakePath(&ref, strBuffer, sizeof(strBuffer)) == noErr) {
83 Glib::ustring utf8_path ((const char*) strBuffer);
84 ARDOUR_UI::instance()->idle_load (utf8_path);
93 handle_open_application (const AppleEvent *inAppleEvent,
94 AppleEvent *outAppleEvent,
101 application_event_handler (EventHandlerCallRef nextHandlerRef, EventRef event, void *userData)
103 UInt32 eventKind = GetEventKind (event);
106 case kEventAppActivated:
107 ApplicationActivationChanged (true); // EMIT SIGNAL
108 return eventNotHandledErr;
110 case kEventAppDeactivated:
111 ApplicationActivationChanged (false); // EMIT SIGNAL
112 return eventNotHandledErr;
115 // pass-thru all kEventClassApplication events we're not interested in.
118 return eventNotHandledErr;
122 ARDOUR_UI::platform_specific ()
124 Gtk::Widget* widget = ActionManager::get_widget ("/ui/Main/Session/Quit");
126 ige_mac_menu_set_quit_menu_item ((GtkMenuItem*) widget->gobj());
129 IgeMacMenuGroup* group = ige_mac_menu_add_app_menu_group ();
131 widget = ActionManager::get_widget ("/ui/Main/Session/About");
133 ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0);
135 widget = ActionManager::get_widget ("/ui/Main/Session/ToggleOptionsEditor");
138 ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0);
143 ARDOUR_UI::platform_setup ()
145 AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments,
146 handle_open_documents, 0, true);
148 AEInstallEventHandler (kCoreEventClass, kAEOpenApplication,
149 handle_open_application, 0, true);
151 AEInstallEventHandler (kCoreEventClass, kAEReopenApplication,
152 handle_reopen_application, 0, true);
154 AEInstallEventHandler (kCoreEventClass, kAEPrintDocuments,
155 handle_print_documents, 0, true);
157 EventTypeSpec applicationEventTypes[] = {
158 {kEventClassApplication, kEventAppActivated },
159 {kEventClassApplication, kEventAppDeactivated }
162 EventHandlerUPP ehUPP = NewEventHandlerUPP (application_event_handler);
164 InstallApplicationEventHandler (ehUPP, sizeof(applicationEventTypes) / sizeof(EventTypeSpec),
165 applicationEventTypes, 0, &application_event_handler_ref);
166 if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) {
168 /* if invoked from the command line, make sure we're visible */
170 [NSApp activateIgnoringOtherApps:1];
175 cocoa_open_url (const char* uri)
177 NSString* struri = [[NSString alloc] initWithUTF8String:uri];
178 NSURL* nsurl = [[NSURL alloc] initWithString:struri];
180 bool ret = [[NSWorkspace sharedWorkspace] openURL:nsurl];