diff options
| author | YAMAMOTO Mitsuharu | 2006-05-05 06:44:29 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2006-05-05 06:44:29 +0000 |
| commit | 044f1b64634008a6590d563eccc9b1e1cff994ad (patch) | |
| tree | 03fd7fab6d5bce8145d8e8562033d60d77f02b7b /src | |
| parent | 0e530e3b3621737b02a1da2be74848013e57b11d (diff) | |
| download | emacs-044f1b64634008a6590d563eccc9b1e1cff994ad.tar.gz emacs-044f1b64634008a6590d563eccc9b1e1cff994ad.zip | |
Update copyright year.
(mac_store_apple_event): Change return type to void in extern.
(mac_handle_apple_event): Don't get return value from
mac_store_apple_event.
[TARGET_API_MAC_CARBON] (Vmac_dnd_known_types): New variable.
(syms_of_macselect) [TARGET_API_MAC_CARBON]: Defvar it.
[TARGET_API_MAC_CARBON] (mac_do_track_drag): Move function from
macterm.c. Use Vmac_dnd_known_types as acceptable flavors.
[TARGET_API_MAC_CARBON] (mac_do_receive_drag): Likewise. New
implementation using create_apple_event_from_drag_ref.
[TARGET_API_MAC_CARBON] (mac_do_track_dragUPP)
(mac_do_receive_dragUPP): Move variables from macterm.c.
(install_drag_handler, remove_drag_handler): New functions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/macselect.c | 215 |
1 files changed, 209 insertions, 6 deletions
diff --git a/src/macselect.c b/src/macselect.c index fe4a7c8eccc..845af2a4870 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 | ||
| 4 | This file is part of GNU Emacs. | 4 | This file is part of GNU Emacs. |
| 5 | 5 | ||
| @@ -918,8 +918,8 @@ static struct | |||
| 918 | int size, count; | 918 | int size, count; |
| 919 | } deferred_apple_events; | 919 | } deferred_apple_events; |
| 920 | extern Lisp_Object Qundefined; | 920 | extern Lisp_Object Qundefined; |
| 921 | extern OSErr mac_store_apple_event P_ ((Lisp_Object, Lisp_Object, | 921 | extern void mac_store_apple_event P_ ((Lisp_Object, Lisp_Object, |
| 922 | const AEDesc *)); | 922 | const AEDesc *)); |
| 923 | 923 | ||
| 924 | struct apple_event_binding | 924 | struct 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,199 @@ DEFUN ("mac-process-deferred-apple-events", Fmac_process_deferred_apple_events, | |||
| 1146 | } | 1145 | } |
| 1147 | 1146 | ||
| 1148 | 1147 | ||
| 1148 | #if TARGET_API_MAC_CARBON | ||
| 1149 | static Lisp_Object Vmac_dnd_known_types; | ||
| 1150 | static pascal OSErr mac_do_track_drag P_ ((DragTrackingMessage, WindowRef, | ||
| 1151 | void *, DragRef)); | ||
| 1152 | static pascal OSErr mac_do_receive_drag P_ ((WindowRef, void *, DragRef)); | ||
| 1153 | static DragTrackingHandlerUPP mac_do_track_dragUPP = NULL; | ||
| 1154 | static DragReceiveHandlerUPP mac_do_receive_dragUPP = NULL; | ||
| 1155 | |||
| 1156 | extern void mac_store_drag_event P_ ((WindowRef, Point, SInt16, | ||
| 1157 | const AEDesc *)); | ||
| 1158 | |||
| 1159 | static pascal OSErr | ||
| 1160 | mac_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 | |||
| 1248 | static pascal OSErr | ||
| 1249 | mac_do_receive_drag (window, refcon, drag) | ||
| 1250 | WindowRef window; | ||
| 1251 | void *refcon; | ||
| 1252 | DragRef drag; | ||
| 1253 | { | ||
| 1254 | OSErr err; | ||
| 1255 | UInt16 index; | ||
| 1256 | int num_types, i; | ||
| 1257 | Lisp_Object rest, str; | ||
| 1258 | FlavorType *types; | ||
| 1259 | AppleEvent apple_event; | ||
| 1260 | Point mouse_pos; | ||
| 1261 | SInt16 modifiers; | ||
| 1262 | |||
| 1263 | if (GetFrontWindowOfClass (kMovableModalWindowClass, false)) | ||
| 1264 | return dragNotAcceptedErr; | ||
| 1265 | |||
| 1266 | num_types = 0; | ||
| 1267 | for (rest = Vmac_dnd_known_types; CONSP (rest); rest = XCDR (rest)) | ||
| 1268 | { | ||
| 1269 | str = XCAR (rest); | ||
| 1270 | if (STRINGP (str) && SBYTES (str) == 4) | ||
| 1271 | num_types++; | ||
| 1272 | } | ||
| 1273 | |||
| 1274 | types = xmalloc (sizeof (FlavorType) * num_types); | ||
| 1275 | i = 0; | ||
| 1276 | for (rest = Vmac_dnd_known_types; CONSP (rest); rest = XCDR (rest)) | ||
| 1277 | { | ||
| 1278 | str = XCAR (rest); | ||
| 1279 | if (STRINGP (str) && SBYTES (str) == 4) | ||
| 1280 | types[i++] = EndianU32_BtoN (*((UInt32 *) SDATA (str))); | ||
| 1281 | } | ||
| 1282 | |||
| 1283 | err = create_apple_event_from_drag_ref (drag, num_types, types, | ||
| 1284 | &apple_event); | ||
| 1285 | xfree (types); | ||
| 1286 | |||
| 1287 | if (err == noErr) | ||
| 1288 | err = GetDragMouse (drag, &mouse_pos, NULL); | ||
| 1289 | if (err == noErr) | ||
| 1290 | { | ||
| 1291 | GlobalToLocal (&mouse_pos); | ||
| 1292 | err = GetDragModifiers (drag, NULL, NULL, &modifiers); | ||
| 1293 | } | ||
| 1294 | |||
| 1295 | if (err == noErr) | ||
| 1296 | { | ||
| 1297 | mac_store_drag_event (window, mouse_pos, modifiers, &apple_event); | ||
| 1298 | AEDisposeDesc (&apple_event); | ||
| 1299 | /* Post a harmless event so as to wake up from ReceiveNextEvent. */ | ||
| 1300 | mac_post_mouse_moved_event (); | ||
| 1301 | return noErr; | ||
| 1302 | } | ||
| 1303 | else | ||
| 1304 | return dragNotAcceptedErr; | ||
| 1305 | } | ||
| 1306 | #endif /* TARGET_API_MAC_CARBON */ | ||
| 1307 | |||
| 1308 | OSErr | ||
| 1309 | install_drag_handler (window) | ||
| 1310 | WindowRef window; | ||
| 1311 | { | ||
| 1312 | OSErr err = noErr; | ||
| 1313 | |||
| 1314 | #if TARGET_API_MAC_CARBON | ||
| 1315 | if (mac_do_track_dragUPP == NULL) | ||
| 1316 | mac_do_track_dragUPP = NewDragTrackingHandlerUPP (mac_do_track_drag); | ||
| 1317 | if (mac_do_receive_dragUPP == NULL) | ||
| 1318 | mac_do_receive_dragUPP = NewDragReceiveHandlerUPP (mac_do_receive_drag); | ||
| 1319 | |||
| 1320 | err = InstallTrackingHandler (mac_do_track_dragUPP, window, NULL); | ||
| 1321 | if (err == noErr) | ||
| 1322 | err = InstallReceiveHandler (mac_do_receive_dragUPP, window, NULL); | ||
| 1323 | #endif | ||
| 1324 | |||
| 1325 | return err; | ||
| 1326 | } | ||
| 1327 | |||
| 1328 | void | ||
| 1329 | remove_drag_handler (window) | ||
| 1330 | WindowRef window; | ||
| 1331 | { | ||
| 1332 | #if TARGET_API_MAC_CARBON | ||
| 1333 | if (mac_do_track_dragUPP) | ||
| 1334 | RemoveTrackingHandler (mac_do_track_dragUPP, window); | ||
| 1335 | if (mac_do_receive_dragUPP) | ||
| 1336 | RemoveReceiveHandler (mac_do_receive_dragUPP, window); | ||
| 1337 | #endif | ||
| 1338 | } | ||
| 1339 | |||
| 1340 | |||
| 1149 | #ifdef MAC_OSX | 1341 | #ifdef MAC_OSX |
| 1150 | void | 1342 | void |
| 1151 | init_service_handler () | 1343 | init_service_handler () |
| @@ -1408,6 +1600,17 @@ set to nil. */); | |||
| 1408 | doc: /* Keymap for Apple events handled by Emacs. */); | 1600 | doc: /* Keymap for Apple events handled by Emacs. */); |
| 1409 | Vmac_apple_event_map = Qnil; | 1601 | Vmac_apple_event_map = Qnil; |
| 1410 | 1602 | ||
| 1603 | #if TARGET_API_MAC_CARBON | ||
| 1604 | DEFVAR_LISP ("mac-dnd-known-types", &Vmac_dnd_known_types, | ||
| 1605 | doc: /* The types accepted by default for dropped data. | ||
| 1606 | The types are chosen in the order they appear in the list. */); | ||
| 1607 | Vmac_dnd_known_types = list4 (build_string ("hfs "), build_string ("utxt"), | ||
| 1608 | build_string ("TEXT"), build_string ("TIFF")); | ||
| 1609 | #ifdef MAC_OSX | ||
| 1610 | Vmac_dnd_known_types = Fcons (build_string ("furl"), Vmac_dnd_known_types); | ||
| 1611 | #endif | ||
| 1612 | #endif | ||
| 1613 | |||
| 1411 | #ifdef MAC_OSX | 1614 | #ifdef MAC_OSX |
| 1412 | DEFVAR_LISP ("mac-services-selection", &Vmac_services_selection, | 1615 | DEFVAR_LISP ("mac-services-selection", &Vmac_services_selection, |
| 1413 | doc: /* Selection name for communication via Services menu. */); | 1616 | doc: /* Selection name for communication via Services menu. */); |