xdnd.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* xdnd.c, xdnd.h - C program library for handling the Xdnd protocol
  2. Copyright (C) 1996-2000 Paul Sheer
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307, USA.
  15. */
  16. #ifndef _X_DND_H
  17. #define _X_DND_H
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /* you can set this to either 2 (which support 0 and 1 as well) or 3 */
  22. /* #define XDND_VERSION 2 */
  23. #define XDND_VERSION 3
  24. /* XdndEnter */
  25. #define XDND_THREE 3
  26. #define XDND_ENTER_SOURCE_WIN(e) ((e)->xclient.data.l[0])
  27. #define XDND_ENTER_THREE_TYPES(e) (((e)->xclient.data.l[1] & 0x1UL) == 0)
  28. #define XDND_ENTER_THREE_TYPES_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
  29. #define XDND_ENTER_VERSION(e) ((e)->xclient.data.l[1] >> 24)
  30. #define XDND_ENTER_VERSION_SET(e,v) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~(0xFF << 24)) | ((v) << 24)
  31. #define XDND_ENTER_TYPE(e,i) ((e)->xclient.data.l[2 + i]) /* i => (0, 1, 2) */
  32. /* XdndPosition */
  33. #define XDND_POSITION_SOURCE_WIN(e) ((e)->xclient.data.l[0])
  34. #define XDND_POSITION_ROOT_X(e) ((e)->xclient.data.l[2] >> 16)
  35. #define XDND_POSITION_ROOT_Y(e) ((e)->xclient.data.l[2] & 0xFFFFUL)
  36. #define XDND_POSITION_ROOT_SET(e,x,y) (e)->xclient.data.l[2] = ((x) << 16) | ((y) & 0xFFFFUL)
  37. #define XDND_POSITION_TIME(e) ((e)->xclient.data.l[3])
  38. #define XDND_POSITION_ACTION(e) ((e)->xclient.data.l[4])
  39. /* XdndStatus */
  40. #define XDND_STATUS_TARGET_WIN(e) ((e)->xclient.data.l[0])
  41. #define XDND_STATUS_WILL_ACCEPT(e) ((e)->xclient.data.l[1] & 0x1L)
  42. #define XDND_STATUS_WILL_ACCEPT_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x1UL) | (((b) == 0) ? 0 : 0x1UL)
  43. #define XDND_STATUS_WANT_POSITION(e) ((e)->xclient.data.l[1] & 0x2UL)
  44. #define XDND_STATUS_WANT_POSITION_SET(e,b) (e)->xclient.data.l[1] = ((e)->xclient.data.l[1] & ~0x2UL) | (((b) == 0) ? 0 : 0x2UL)
  45. #define XDND_STATUS_RECT_X(e) ((e)->xclient.data.l[2] >> 16)
  46. #define XDND_STATUS_RECT_Y(e) ((e)->xclient.data.l[2] & 0xFFFFL)
  47. #define XDND_STATUS_RECT_WIDTH(e) ((e)->xclient.data.l[3] >> 16)
  48. #define XDND_STATUS_RECT_HEIGHT(e) ((e)->xclient.data.l[3] & 0xFFFFL)
  49. #define XDND_STATUS_RECT_SET(e,x,y,w,h) {(e)->xclient.data.l[2] = ((x) << 16) | ((y) & 0xFFFFUL); (e)->xclient.data.l[3] = ((w) << 16) | ((h) & 0xFFFFUL); }
  50. #define XDND_STATUS_ACTION(e) ((e)->xclient.data.l[4])
  51. /* XdndLeave */
  52. #define XDND_LEAVE_SOURCE_WIN(e) ((e)->xclient.data.l[0])
  53. /* XdndDrop */
  54. #define XDND_DROP_SOURCE_WIN(e) ((e)->xclient.data.l[0])
  55. #define XDND_DROP_TIME(e) ((e)->xclient.data.l[2])
  56. /* XdndFinished */
  57. #define XDND_FINISHED_TARGET_WIN(e) ((e)->xclient.data.l[0])
  58. struct _DndCursor {
  59. int width, height;
  60. int x, y;
  61. unsigned char *image_data, *mask_data;
  62. char *_action;
  63. Pixmap image_pixmap, mask_pixmap;
  64. Cursor cursor;
  65. Atom action;
  66. };
  67. typedef struct _DndCursor DndCursor;
  68. typedef struct _DndClass DndClass;
  69. struct _DndClass {
  70. /* insert chars sequentionally into the target widget, type will be the same as `desired_type'
  71. returned from widget_apply_position. This may be called several times in succession
  72. with sequention blocks of data. Must return non-zero on failure */
  73. int (*widget_insert_drop) (DndClass * dnd, unsigned char *data, int length, int remaining, Window into, Window from, Atom type);
  74. /* In response to DELETE requests : FIXME - not yet used */
  75. int (*widget_delete_selection) (DndClass * dnd, Window window, Window from);
  76. /* returns 1 if widget exists, zero otherwise. If this method is not
  77. set then the code assumes that no widgets have support for recieving drops.
  78. In this case none of the widget methods need be set. */
  79. int (*widget_exists) (DndClass * dnd, Window window);
  80. /* must update the widgets border to its default appearance */
  81. void (*widget_apply_leave) (DndClass * dnd, Window widgets_window);
  82. /* must update the widgets border to give the appearance of being able to recieve a drop,
  83. plus return all data to pointers. As per the protocol, if the widget cannot
  84. perform the action specified by `action' then it should return either XdndActionPrivate
  85. or XdndActionCopy into supported_action (leaving 0 supported_action unchanged is equivalent
  86. to XdndActionCopy). Returns 1 if ready to ok drop */
  87. int (*widget_apply_position) (DndClass * dnd, Window widgets_window, Window from,
  88. Atom action, int x, int y, Time t, Atom * typelist,
  89. int *want_position, Atom * supported_action, Atom * desired_type,
  90. XRectangle * rectangle);
  91. /* returns drag data of the specified type. This will be one of `typelist' given to xdnd_drag */
  92. void (*widget_get_data) (DndClass * dnd, Window window, unsigned char **data, int *length, Atom type);
  93. /* this is called from with the main event loop if an expose event is recieved and is optional */
  94. void (*handle_expose_events) (DndClass * dnd, XEvent * xevent);
  95. /* creates a chooser dialog if the action is XdndActionAsk. Returns non-zero on cancel */
  96. int (*action_choose_dialog) (DndClass * dnd, char **descriptions, Atom * actions, Atom * result);
  97. #if 0 /* implemented internally */
  98. /* returns a widget that is dnd aware within a parent widget that lies under the point x, y */
  99. Window (*widget_get_child_widget) (DndClass * dnd, Window parent, int x, int y);
  100. #endif
  101. void *pad1[8];
  102. DndCursor *cursors;
  103. Display *display;
  104. Atom XdndAware;
  105. Atom XdndSelection;
  106. Atom XdndEnter;
  107. Atom XdndLeave;
  108. Atom XdndPosition;
  109. Atom XdndDrop;
  110. Atom XdndFinished;
  111. Atom XdndStatus;
  112. Atom XdndActionCopy;
  113. Atom XdndActionMove;
  114. Atom XdndActionLink;
  115. Atom XdndActionAsk;
  116. Atom XdndActionPrivate;
  117. Atom XdndTypeList;
  118. Atom XdndActionList;
  119. Atom XdndActionDescription;
  120. Atom Xdnd_NON_PROTOCOL_ATOM;
  121. Atom version;
  122. Atom pad2[16];
  123. Window root_window;
  124. #define XDND_DROP_STAGE_IDLE 0
  125. #define XDND_DRAG_STAGE_DRAGGING 1
  126. #define XDND_DRAG_STAGE_ENTERED 2
  127. #define XDND_DROP_STAGE_CONVERTING 3
  128. #define XDND_DROP_STAGE_ENTERED 4
  129. int stage;
  130. int dragging_version;
  131. int internal_drag;
  132. int want_position;
  133. int ready_to_drop;
  134. int will_accept;
  135. XRectangle rectangle;
  136. Window dropper_window, dragger_window;
  137. Atom *dragger_typelist;
  138. Atom desired_type;
  139. Atom supported_action;
  140. Time time;
  141. /* drop position from last XdndPosition */
  142. int x, y;
  143. int pad3[16];
  144. /* move euclidian pixels before considering this to be an actual drag */
  145. float drag_threshold;
  146. /* block for only this many seconds on not receiving a XdndFinished from target, default : 10 */
  147. int time_out;
  148. #define XDND_OPTION_NO_HYSTERESIS (1<<0)
  149. int options;
  150. /* user hooks */
  151. void *user_hook1;
  152. void *user_hook2;
  153. void *user_hook3;
  154. Window dropper_toplevel;
  155. void *pad4[15];
  156. };
  157. void xdnd_init (DndClass * dnd, Display * display);
  158. void xdnd_shut (DndClass * dnd);
  159. /* for nested widgets where parent and child receive drops of different
  160. types; then always pass typelist as null */
  161. void xdnd_set_dnd_aware (DndClass * dnd, Window window, Atom * typelist);
  162. int xdnd_is_dnd_aware (DndClass * dnd, Window window, int *version, Atom * typelist);
  163. void xdnd_set_type_list (DndClass * dnd, Window window, Atom * typelist);
  164. void xdnd_set_actions (DndClass * dnd, Window window, Atom * actions, char **descriptions);
  165. int xdnd_get_actions (DndClass * dnd, Window window, Atom ** actions, char ***descriptions);
  166. int xdnd_choose_action_dialog (DndClass * dnd, Atom * actions, char **descriptions, Atom * result);
  167. Atom xdnd_drag (DndClass * dnd, Window from, Atom action, Atom * typelist);
  168. /* Returns 1 if event is handled, This must be placed in the widget
  169. libraries main event loop and be called if the event type is
  170. ClientMessage or SelectionNotify */
  171. int xdnd_handle_drop_events (DndClass * dnd, XEvent * xevent);
  172. Atom xdnd_get_drop (Display * display, XEvent * xevent, Atom * typelist, Atom * actionlist,
  173. unsigned char **data, int *length, Atom * type, int *x, int *y);
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #endif /* !_X_DND_H */