Ticket #40795: patch-app-mac_integration.c.diff
File patch-app-mac_integration.c.diff, 6.1 KB (added by nano103, 11 years ago) |
---|
-
app/mac_integration.c
old new 1 1 /* 2 * @(#) $Id: mac_integration.c 1 2576 2011-07-11 14:51:57Z yeti-dn $2 * @(#) $Id: mac_integration.c 15469 2013-10-22 15:32:45Z yeti-dn $ 3 3 * Copyright (C) 2009 Andrey Gruzdev. 4 4 * E-mail: gruzdev@ntmdt.ru. 5 5 * … … 19 19 */ 20 20 21 21 #ifdef __APPLE__ 22 #include < Carbon/Carbon.h>22 #include <AppKit/AppKit.h> 23 23 #include <CoreFoundation/CoreFoundation.h> 24 24 #include <file.h> 25 #include "ige-mac-menu.h" 25 #include "config.h" 26 27 #ifdef HAVE_GTK_MAC_INTEGRATION 28 #include <gtkmacintegration/gtkosxapplication.h> 29 #endif 30 26 31 #define USE_MAC_INTEGRATION 27 32 #define USED_ON_MAC /* */ 28 33 #else 29 34 #define USED_ON_MAC G_GNUC_UNUSED 30 35 #endif 31 36 37 #ifdef HAVE_GTK_MAC_INTEGRATION 38 #define USED_ON_MAC_QUARTZ /* */ 39 #else 40 #define USED_ON_MAC_QUARTZ G_GNUC_UNUSED 41 #endif 42 32 43 #include "mac_integration.h" 33 44 34 45 #ifdef USE_MAC_INTEGRATION 35 46 int fileModulesReady = 0; 36 47 GPtrArray *files_array = NULL; 48 #ifdef HAVE_GTK_MAC_INTEGRATION 49 GtkosxApplication *theApp = NULL; 50 #endif 37 51 #endif 38 52 39 53 void 40 gwy_osx_get_menu_from_widget(USED_ON_MAC GtkWidget *container)54 gwy_osx_get_menu_from_widget(USED_ON_MAC_QUARTZ GtkWidget *container) 41 55 { 42 #ifdef GDK_WINDOWING_QUARTZ 43 #ifdef USE_MAC_INTEGRATION 56 #ifdef HAVE_GTK_MAC_INTEGRATION 44 57 GList *children; //,*subchildren,*subsubchildren; 45 58 GList *l, *ll, *lll; 46 59 GtkWidget *menubar = gtk_menu_bar_new(); … … 76 89 } 77 90 gtk_container_add(GTK_CONTAINER(container), menubar); 78 91 gtk_widget_hide(menubar); 79 ige_mac_menu_set_menu_bar(GTK_MENU_SHELL(menubar));80 #endif 92 gtkosx_application_set_menu_bar ( theApp, GTK_MENU_SHELL(menubar)); 93 gtkosx_application_ready (theApp); 81 94 #endif 82 95 } 83 96 84 97 85 98 #ifdef USE_MAC_INTEGRATION 99 86 100 static void 87 101 gwy_osx_open_file(gpointer data, 88 102 G_GNUC_UNUSED gpointer user_data) … … 90 104 gwy_app_file_load((const gchar*)data, (const gchar*)data, NULL); 91 105 } 92 106 93 static OSStatus 94 appleEventHandler(const AppleEvent * event, AppleEvent * event2, long param) 107 @interface GwyOSXEventHandler:NSObject 108 @end 109 110 @implementation GwyOSXEventHandler 111 - (void)handleOpenEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent 95 112 { 96 enum { BUFLEN = 1024 }; 97 AEDescList docs; 113 #pragma unused (replyEvent) 114 NSAppleEventDescriptor *descr = [event descriptorForKeyword:keyDirectObject]; 115 NSInteger i,count = [descr numberOfItems]; 116 117 for(i=0;i<count;i++) 118 { 119 NSAppleEventDescriptor *descr1 = i==0?descr:[descr descriptorAtIndex:i]; 120 NSString *url = [descr1 stringValue]; 121 NSString *filename = [[NSURL URLWithString:url] path]; 122 123 124 char * strBuffer = (char*)[filename UTF8String]; 125 126 if (fileModulesReady) 127 gwy_osx_open_file(strBuffer, NULL); 128 else { 129 if (!files_array) 130 files_array = g_ptr_array_new(); 131 g_ptr_array_add(files_array, g_strdup((gchar*)strBuffer)); 132 } 133 } 134 } 98 135 99 if (AEGetParamDesc(event, keyDirectObject, typeAEList, &docs) == noErr) { 100 long n = 0; 101 int i; 136 - (void)handleQuitEvent:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent 137 { 138 #pragma unused (event) 139 #pragma unused (replyEvent) 140 gtk_main_quit(); 141 } 102 142 103 AECountItems(&docs, &n); 104 static UInt8 strBuffer[BUFLEN]; 143 @end 105 144 106 for (i = 0; i < n; i++) { 107 FSRef ref; 145 GwyOSXEventHandler *eventHandler; 108 146 109 if (AEGetNthPtr(&docs, i + 1, typeFSRef, 0, 0, &ref, sizeof(ref), 0)110 != noErr)111 continue;112 if (FSRefMakePath(&ref, strBuffer, BUFLEN) == noErr) {113 if (fileModulesReady)114 gwy_osx_open_file(strBuffer, NULL);115 else {116 if (!files_array)117 files_array = g_ptr_array_new();118 g_ptr_array_add(files_array, g_strdup((gchar*)strBuffer));119 }120 }121 }122 }123 return noErr;124 }125 147 #endif 126 148 127 149 void 128 150 gwy_osx_init_handler(USED_ON_MAC int *argc) 129 151 { 130 152 #ifdef USE_MAC_INTEGRATION 153 NSAppleEventManager *appleEventManager; 131 154 CFURLRef res_url_ref = NULL, bundle_url_ref = NULL; 132 133 155 res_url_ref = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); 134 156 bundle_url_ref = CFBundleCopyBundleURL(CFBundleGetMainBundle()); 135 157 … … 142 164 if (bundle_url_ref) 143 165 CFRelease(bundle_url_ref); 144 166 145 AEInstallEventHandler(kCoreEventClass, // handle open file events 146 kAEOpenDocuments, 147 (AEEventHandlerUPP)appleEventHandler, 0, false); 167 168 eventHandler = [[GwyOSXEventHandler alloc] init]; 169 170 171 appleEventManager = [NSAppleEventManager sharedAppleEventManager]; 172 [appleEventManager setEventHandler:eventHandler 173 andSelector:@selector(handleOpenEvent:withReplyEvent:) 174 forEventClass:kCoreEventClass 175 andEventID:kAEOpenDocuments]; 176 177 [appleEventManager setEventHandler:eventHandler 178 andSelector:@selector(handleQuitEvent:withReplyEvent:) 179 forEventClass:kCoreEventClass 180 andEventID:kAEQuitApplication]; 181 182 #ifdef HAVE_GTK_MAC_INTEGRATION 183 theApp = g_object_new (GTKOSX_TYPE_APPLICATION, NULL); 184 #endif 148 185 #endif 149 186 } 150 187 … … 152 189 gwy_osx_remove_handler(void) 153 190 { 154 191 #ifdef USE_MAC_INTEGRATION 155 AERemoveEventHandler(kCoreEventClass, 156 kAEOpenDocuments, 157 (AEEventHandlerUPP)appleEventHandler, false); 192 NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager]; 193 [appleEventManager removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEOpenDocuments]; 194 [appleEventManager removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEQuitApplication]; 195 [eventHandler release]; 196 eventHandler = nil; 197 #ifdef HAVE_GTK_MAC_INTEGRATION 198 g_object_unref (theApp); 199 #endif 158 200 #endif 159 201 } 160 202