aboutsummaryrefslogtreecommitdiffstats
path: root/src/macselect.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/macselect.c')
-rw-r--r--src/macselect.c234
1 files changed, 218 insertions, 16 deletions
diff --git a/src/macselect.c b/src/macselect.c
index fe4a7c8eccc..1b6a1a46cc3 100644
--- a/src/macselect.c
+++ b/src/macselect.c
@@ -1,5 +1,5 @@
1/* Selection processing for Emacs on Mac OS. 1/* Selection processing for Emacs on Mac OS.
2 Copyright (C) 2005 Free Software Foundation, Inc. 2 Copyright (C) 2005, 2006 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -101,7 +101,7 @@ static Lisp_Object Qmac_scrap_name, Qmac_ostype;
101 101
102#ifdef MAC_OSX 102#ifdef MAC_OSX
103/* Selection name for communication via Services menu. */ 103/* Selection name for communication via Services menu. */
104static Lisp_Object Vmac_services_selection; 104static Lisp_Object Vmac_service_selection;
105#endif 105#endif
106 106
107/* Get a reference to the scrap corresponding to the symbol SYM. The 107/* Get a reference to the scrap corresponding to the symbol SYM. The
@@ -918,8 +918,8 @@ static struct
918 int size, count; 918 int size, count;
919} deferred_apple_events; 919} deferred_apple_events;
920extern Lisp_Object Qundefined; 920extern Lisp_Object Qundefined;
921extern OSErr mac_store_apple_event P_ ((Lisp_Object, Lisp_Object, 921extern void mac_store_apple_event P_ ((Lisp_Object, Lisp_Object,
922 const AEDesc *)); 922 const AEDesc *));
923 923
924struct apple_event_binding 924struct apple_event_binding
925{ 925{
@@ -1079,9 +1079,8 @@ mac_handle_apple_event (apple_event, reply, refcon)
1079 { 1079 {
1080 if (INTEGERP (binding)) 1080 if (INTEGERP (binding))
1081 return XINT (binding); 1081 return XINT (binding);
1082 err = mac_store_apple_event (class_key, id_key, apple_event); 1082 mac_store_apple_event (class_key, id_key, apple_event);
1083 if (err == noErr) 1083 return noErr;
1084 return noErr;
1085 } 1084 }
1086 } 1085 }
1087 return errAEEventNotHandled; 1086 return errAEEventNotHandled;
@@ -1146,6 +1145,198 @@ DEFUN ("mac-process-deferred-apple-events", Fmac_process_deferred_apple_events,
1146} 1145}
1147 1146
1148 1147
1148#if TARGET_API_MAC_CARBON
1149static Lisp_Object Vmac_dnd_known_types;
1150static pascal OSErr mac_do_track_drag P_ ((DragTrackingMessage, WindowRef,
1151 void *, DragRef));
1152static pascal OSErr mac_do_receive_drag P_ ((WindowRef, void *, DragRef));
1153static DragTrackingHandlerUPP mac_do_track_dragUPP = NULL;
1154static DragReceiveHandlerUPP mac_do_receive_dragUPP = NULL;
1155
1156extern void mac_store_drag_event P_ ((WindowRef, Point, SInt16,
1157 const AEDesc *));
1158
1159static pascal OSErr
1160mac_do_track_drag (message, window, refcon, drag)
1161 DragTrackingMessage message;
1162 WindowRef window;
1163 void *refcon;
1164 DragRef drag;
1165{
1166 OSErr err = noErr;
1167 static int can_accept;
1168 UInt16 num_items, index;
1169
1170 if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
1171 return dragNotAcceptedErr;
1172
1173 switch (message)
1174 {
1175 case kDragTrackingEnterHandler:
1176 err = CountDragItems (drag, &num_items);
1177 if (err != noErr)
1178 break;
1179 can_accept = 0;
1180 for (index = 1; index <= num_items; index++)
1181 {
1182 ItemReference item;
1183 FlavorFlags flags;
1184 Lisp_Object rest;
1185
1186 err = GetDragItemReferenceNumber (drag, index, &item);
1187 if (err != noErr)
1188 continue;
1189 for (rest = Vmac_dnd_known_types; CONSP (rest); rest = XCDR (rest))
1190 {
1191 Lisp_Object str;
1192 FlavorType type;
1193
1194 str = XCAR (rest);
1195 if (!(STRINGP (str) && SBYTES (str) == 4))
1196 continue;
1197 type = EndianU32_BtoN (*((UInt32 *) SDATA (str)));
1198
1199 err = GetFlavorFlags (drag, item, type, &flags);
1200 if (err == noErr)
1201 {
1202 can_accept = 1;
1203 break;
1204 }
1205 }
1206 }
1207 break;
1208
1209 case kDragTrackingEnterWindow:
1210 if (can_accept)
1211 {
1212 RgnHandle hilite_rgn = NewRgn ();
1213
1214 if (hilite_rgn)
1215 {
1216 Rect r;
1217
1218 GetWindowPortBounds (window, &r);
1219 OffsetRect (&r, -r.left, -r.top);
1220 RectRgn (hilite_rgn, &r);
1221 ShowDragHilite (drag, hilite_rgn, true);
1222 DisposeRgn (hilite_rgn);
1223 }
1224 SetThemeCursor (kThemeCopyArrowCursor);
1225 }
1226 break;
1227
1228 case kDragTrackingInWindow:
1229 break;
1230
1231 case kDragTrackingLeaveWindow:
1232 if (can_accept)
1233 {
1234 HideDragHilite (drag);
1235 SetThemeCursor (kThemeArrowCursor);
1236 }
1237 break;
1238
1239 case kDragTrackingLeaveHandler:
1240 break;
1241 }
1242
1243 if (err != noErr)
1244 return dragNotAcceptedErr;
1245 return noErr;
1246}
1247
1248static pascal OSErr
1249mac_do_receive_drag (window, refcon, drag)
1250 WindowRef window;
1251 void *refcon;
1252 DragRef drag;
1253{
1254 OSErr err;
1255 int num_types, i;
1256 Lisp_Object rest, str;
1257 FlavorType *types;
1258 AppleEvent apple_event;
1259 Point mouse_pos;
1260 SInt16 modifiers;
1261
1262 if (GetFrontWindowOfClass (kMovableModalWindowClass, false))
1263 return dragNotAcceptedErr;
1264
1265 num_types = 0;
1266 for (rest = Vmac_dnd_known_types; CONSP (rest); rest = XCDR (rest))
1267 {
1268 str = XCAR (rest);
1269 if (STRINGP (str) && SBYTES (str) == 4)
1270 num_types++;
1271 }
1272
1273 types = xmalloc (sizeof (FlavorType) * num_types);
1274 i = 0;
1275 for (rest = Vmac_dnd_known_types; CONSP (rest); rest = XCDR (rest))
1276 {
1277 str = XCAR (rest);
1278 if (STRINGP (str) && SBYTES (str) == 4)
1279 types[i++] = EndianU32_BtoN (*((UInt32 *) SDATA (str)));
1280 }
1281
1282 err = create_apple_event_from_drag_ref (drag, num_types, types,
1283 &apple_event);
1284 xfree (types);
1285
1286 if (err == noErr)
1287 err = GetDragMouse (drag, &mouse_pos, NULL);
1288 if (err == noErr)
1289 {
1290 GlobalToLocal (&mouse_pos);
1291 err = GetDragModifiers (drag, NULL, NULL, &modifiers);
1292 }
1293
1294 if (err == noErr)
1295 {
1296 mac_store_drag_event (window, mouse_pos, modifiers, &apple_event);
1297 AEDisposeDesc (&apple_event);
1298 /* Post a harmless event so as to wake up from ReceiveNextEvent. */
1299 mac_post_mouse_moved_event ();
1300 return noErr;
1301 }
1302 else
1303 return dragNotAcceptedErr;
1304}
1305#endif /* TARGET_API_MAC_CARBON */
1306
1307OSErr
1308install_drag_handler (window)
1309 WindowRef window;
1310{
1311 OSErr err = noErr;
1312
1313#if TARGET_API_MAC_CARBON
1314 if (mac_do_track_dragUPP == NULL)
1315 mac_do_track_dragUPP = NewDragTrackingHandlerUPP (mac_do_track_drag);
1316 if (mac_do_receive_dragUPP == NULL)
1317 mac_do_receive_dragUPP = NewDragReceiveHandlerUPP (mac_do_receive_drag);
1318
1319 err = InstallTrackingHandler (mac_do_track_dragUPP, window, NULL);
1320 if (err == noErr)
1321 err = InstallReceiveHandler (mac_do_receive_dragUPP, window, NULL);
1322#endif
1323
1324 return err;
1325}
1326
1327void
1328remove_drag_handler (window)
1329 WindowRef window;
1330{
1331#if TARGET_API_MAC_CARBON
1332 if (mac_do_track_dragUPP)
1333 RemoveTrackingHandler (mac_do_track_dragUPP, window);
1334 if (mac_do_receive_dragUPP)
1335 RemoveReceiveHandler (mac_do_receive_dragUPP, window);
1336#endif
1337}
1338
1339
1149#ifdef MAC_OSX 1340#ifdef MAC_OSX
1150void 1341void
1151init_service_handler () 1342init_service_handler ()
@@ -1158,7 +1349,7 @@ init_service_handler ()
1158 GetEventTypeCount (specs), specs, NULL, NULL); 1349 GetEventTypeCount (specs), specs, NULL, NULL);
1159} 1350}
1160 1351
1161extern OSErr mac_store_services_event P_ ((EventRef)); 1352extern OSStatus mac_store_service_event P_ ((EventRef));
1162 1353
1163static OSStatus 1354static OSStatus
1164copy_scrap_flavor_data (from_scrap, to_scrap, flavor_type) 1355copy_scrap_flavor_data (from_scrap, to_scrap, flavor_type)
@@ -1215,12 +1406,12 @@ mac_handle_service_event (call_ref, event, data)
1215 Lisp_Object rest; 1406 Lisp_Object rest;
1216 ScrapFlavorType flavor_type; 1407 ScrapFlavorType flavor_type;
1217 1408
1218 /* Check if Vmac_services_selection is a valid selection that has a 1409 /* Check if Vmac_service_selection is a valid selection that has a
1219 corresponding scrap. */ 1410 corresponding scrap. */
1220 if (!SYMBOLP (Vmac_services_selection)) 1411 if (!SYMBOLP (Vmac_service_selection))
1221 err = eventNotHandledErr; 1412 err = eventNotHandledErr;
1222 else 1413 else
1223 err = get_scrap_from_symbol (Vmac_services_selection, 0, &cur_scrap); 1414 err = get_scrap_from_symbol (Vmac_service_selection, 0, &cur_scrap);
1224 if (!(err == noErr && cur_scrap)) 1415 if (!(err == noErr && cur_scrap))
1225 return eventNotHandledErr; 1416 return eventNotHandledErr;
1226 1417
@@ -1257,7 +1448,7 @@ mac_handle_service_event (call_ref, event, data)
1257 if (err != noErr) 1448 if (err != noErr)
1258 break; 1449 break;
1259 1450
1260 if (NILP (Fx_selection_owner_p (Vmac_services_selection))) 1451 if (NILP (Fx_selection_owner_p (Vmac_service_selection)))
1261 break; 1452 break;
1262 else 1453 else
1263 goto copy_all_flavors; 1454 goto copy_all_flavors;
@@ -1267,7 +1458,7 @@ mac_handle_service_event (call_ref, event, data)
1267 typeScrapRef, NULL, 1458 typeScrapRef, NULL,
1268 sizeof (ScrapRef), NULL, &specific_scrap); 1459 sizeof (ScrapRef), NULL, &specific_scrap);
1269 if (err != noErr 1460 if (err != noErr
1270 || NILP (Fx_selection_owner_p (Vmac_services_selection))) 1461 || NILP (Fx_selection_owner_p (Vmac_service_selection)))
1271 { 1462 {
1272 err = eventNotHandledErr; 1463 err = eventNotHandledErr;
1273 break; 1464 break;
@@ -1342,7 +1533,7 @@ mac_handle_service_event (call_ref, event, data)
1342 if (!data_exists_p) 1533 if (!data_exists_p)
1343 err = eventNotHandledErr; 1534 err = eventNotHandledErr;
1344 else 1535 else
1345 err = mac_store_services_event (event); 1536 err = mac_store_service_event (event);
1346 } 1537 }
1347 break; 1538 break;
1348 } 1539 }
@@ -1408,10 +1599,21 @@ set to nil. */);
1408 doc: /* Keymap for Apple events handled by Emacs. */); 1599 doc: /* Keymap for Apple events handled by Emacs. */);
1409 Vmac_apple_event_map = Qnil; 1600 Vmac_apple_event_map = Qnil;
1410 1601
1602#if TARGET_API_MAC_CARBON
1603 DEFVAR_LISP ("mac-dnd-known-types", &Vmac_dnd_known_types,
1604 doc: /* The types accepted by default for dropped data.
1605The types are chosen in the order they appear in the list. */);
1606 Vmac_dnd_known_types = list4 (build_string ("hfs "), build_string ("utxt"),
1607 build_string ("TEXT"), build_string ("TIFF"));
1608#ifdef MAC_OSX
1609 Vmac_dnd_known_types = Fcons (build_string ("furl"), Vmac_dnd_known_types);
1610#endif
1611#endif
1612
1411#ifdef MAC_OSX 1613#ifdef MAC_OSX
1412 DEFVAR_LISP ("mac-services-selection", &Vmac_services_selection, 1614 DEFVAR_LISP ("mac-service-selection", &Vmac_service_selection,
1413 doc: /* Selection name for communication via Services menu. */); 1615 doc: /* Selection name for communication via Services menu. */);
1414 Vmac_services_selection = intern ("PRIMARY"); 1616 Vmac_service_selection = intern ("PRIMARY");
1415#endif 1617#endif
1416 1618
1417 QPRIMARY = intern ("PRIMARY"); staticpro (&QPRIMARY); 1619 QPRIMARY = intern ("PRIMARY"); staticpro (&QPRIMARY);