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 cerr << "\n\n\n\n HANDLE DOCUMENT\n\n\n";
66 if (AEGetParamDesc(inAppleEvent, keyDirectObject, typeAEList, &docs) == noErr) {
68 AECountItems(&docs, &n);
69 UInt8 strBuffer[PATH_MAX+1];
71 /* ardour only opens 1 session at a time */
75 if (AEGetNthPtr(&docs, 1, typeFSRef, 0, 0, &ref, sizeof(ref), 0) == noErr) {
76 if (FSRefMakePath(&ref, strBuffer, sizeof(strBuffer)) == noErr) {
77 Glib::ustring utf8_path ((const char*) strBuffer);
78 ARDOUR_UI::instance()->idle_load (utf8_path);
87 handle_open_application (const AppleEvent *inAppleEvent,
88 AppleEvent *outAppleEvent,
95 application_event_handler (EventHandlerCallRef nextHandlerRef, EventRef event, void *userData)
97 UInt32 eventKind = GetEventKind (event);
100 case kEventAppActivated:
101 ApplicationActivationChanged (true); // EMIT SIGNAL
102 return eventNotHandledErr;
104 case kEventAppDeactivated:
105 ApplicationActivationChanged (false); // EMIT SIGNAL
106 return eventNotHandledErr;
109 // pass-thru all kEventClassApplication events we're not interested in.
112 return eventNotHandledErr;
116 ARDOUR_UI::platform_specific ()
118 Gtk::Widget* widget = ActionManager::get_widget ("/ui/Main/Session/Quit");
120 ige_mac_menu_set_quit_menu_item ((GtkMenuItem*) widget->gobj());
123 IgeMacMenuGroup* group = ige_mac_menu_add_app_menu_group ();
125 widget = ActionManager::get_widget ("/ui/Main/Session/About");
127 ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0);
129 widget = ActionManager::get_widget ("/ui/Main/Session/ToggleOptionsEditor");
132 ige_mac_menu_add_app_menu_item (group, (GtkMenuItem*) widget->gobj(), 0);
137 ARDOUR_UI::platform_setup ()
139 AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments,
140 handle_open_documents, 0, true);
142 AEInstallEventHandler (kCoreEventClass, kAEOpenApplication,
143 handle_open_application, 0, true);
145 AEInstallEventHandler (kCoreEventClass, kAEReopenApplication,
146 handle_reopen_application, 0, true);
148 AEInstallEventHandler (kCoreEventClass, kAEPrintDocuments,
149 handle_print_documents, 0, true);
151 EventTypeSpec applicationEventTypes[] = {
152 {kEventClassApplication, kEventAppActivated },
153 {kEventClassApplication, kEventAppDeactivated }
156 EventHandlerUPP ehUPP = NewEventHandlerUPP (application_event_handler);
158 InstallApplicationEventHandler (ehUPP, sizeof(applicationEventTypes) / sizeof(EventTypeSpec),
159 applicationEventTypes, 0, &application_event_handler_ref);
160 if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) {
162 /* if invoked from the command line, make sure we're visible */
164 [NSApp activateIgnoringOtherApps:1];