iup_drag_and_drop.e 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. deferred class IUP_DRAG_AND_DROP
  2. -- Commands related to drag & drop.
  3. inherit
  4. IUP_WIDGET_INTERNALS
  5. feature {ANY}
  6. -- Attributes at Drag Source
  7. set_drag_cursor (name: STRING)
  8. -- (non inheritable): name of an image to be used as cursor during drag.
  9. -- See also IUP_IMAGE.
  10. do
  11. iup_open.set_attribute(Current, "DRAGCURSOR", name)
  12. end
  13. set_drag_source (state: BOOLEAN)
  14. -- (non inheritable): Set up a control as a source for drag operations.
  15. -- Default: False.
  16. do
  17. iup_open.set_attribute(Current, "DRAGSOURCE", boolean_to_yesno(state))
  18. end
  19. set_drag_types (types: STRING)
  20. -- (non inheritable): A list of data types that are supported by the
  21. -- source. Accepts a string with one or more names separated by commas.
  22. -- Must be set.
  23. --
  24. -- Drag and Drop support can be set independently. A control can have
  25. -- drop without drag support and vice-versa.
  26. --
  27. -- Here are some common Drag&Drop types defined by existing applications:
  28. --
  29. -- * "TEXT" used for regular text without formatting. Automatically
  30. -- translated to CF_TEXT in Windows.
  31. -- * content MIME types, like "text/uri-list", "text/html", "image/png",
  32. -- "image/jpeg", "image/bmp" and "image/gif".
  33. -- * "UTF8_STRING" in GTK and "UNICODETEXT" in Windows.
  34. -- * "COMPOUND_TEXT" in GTK and "Rich Text Format" in Windows.
  35. -- * "BITMAP" and "DIB" in Windows. Automatically translated to CF_BITMAP
  36. -- and CF_DIB.
  37. do
  38. iup_open.set_attribute(Current, "DRAGTYPES", types)
  39. end
  40. set_drag_source_move (state: BOOLEAN)
  41. -- (non inheritable): Enables the move action. Default: False (only copy
  42. -- is enabled).
  43. do
  44. iup_open.set_attribute(Current, "DRAGSOURCEMOVE",
  45. boolean_to_yesno(state))
  46. end
  47. -- Attributes at Drop Target
  48. set_drop_target (state: BOOLEAN)
  49. -- (non inheritable): Set up a control as a destination for drop
  50. -- operations. Default: False.
  51. do
  52. iup_open.set_attribute(Current, "DROPTARGET",
  53. boolean_to_yesno(state))
  54. end
  55. set_drop_types (types: STRING)
  56. -- (non inheritable): A list of data types that are supported by the
  57. -- target. Accepts a string with one or more names separated by commas.
  58. -- Must be set.
  59. --
  60. -- Drag and Drop support can be set independently. A control can have
  61. -- drop without drag support and vice-versa.
  62. --
  63. -- Here are some common Drag&Drop types defined by existing applications:
  64. --
  65. -- * "TEXT" used for regular text without formatting. Automatically
  66. -- translated to CF_TEXT in Windows.
  67. -- * content MIME types, like "text/uri-list", "text/html", "image/png",
  68. -- "image/jpeg", "image/bmp" and "image/gif".
  69. -- * "UTF8_STRING" in GTK and "UNICODETEXT" in Windows.
  70. -- * "COMPOUND_TEXT" in GTK and "Rich Text Format" in Windows.
  71. -- * "BITMAP" and "DIB" in Windows. Automatically translated to CF_BITMAP
  72. -- and CF_DIB.
  73. do
  74. iup_open.set_attribute(Current, "DROPTYPES", types)
  75. end
  76. -- Callbacks at Drag Source (Must be set when DRAGSOURCE=True)
  77. set_cb_drag_begin (act: detachable FUNCTION[TUPLE[IUP_WIDGET, INTEGER, INTEGER], STRING])
  78. -- Notifies source that drag started. It is called when the mouse starts
  79. -- a drag operation.
  80. --
  81. -- ih: identifier of the element that activated the event.
  82. -- x, y: cursor position relative to the top-left corner of the element.
  83. --
  84. -- Returns: If IUP_IGNORE is returned the drag is aborted.
  85. local
  86. operation: INTEGER
  87. do
  88. cb_dragbegin := act
  89. if cb_dragbegin /= Void then
  90. operation := 1
  91. else
  92. operation := 0
  93. end
  94. iup_open.set_callback (Current, "DRAGBEGIN_CB", "NONEEDED", operation)
  95. end
  96. set_cb_drag_data_size (act: detachable FUNCTION[TUPLE[IUP_WIDGET, STRING], INTEGER])
  97. -- Request for size of drag data from source. It is called when the data
  98. -- is dropped, before the DRAGDATA_CB callback.
  99. --
  100. -- ih: identifier of the element that activated the event.
  101. -- type: type of the data. It is one of the registered types in DRAGTYPES.
  102. --
  103. -- Returns: the size in bytes for the data. It will be used to allocate
  104. -- the buffer size for the data in transfer.
  105. local
  106. operation: INTEGER
  107. do
  108. cb_dragdatasize := act
  109. if cb_dragdatasize /= Void then
  110. operation := 1
  111. else
  112. operation := 0
  113. end
  114. iup_open.set_callback (Current, "DRAGDATASIZE_CB", "NONEEDED", operation)
  115. end
  116. set_cb_drag_data (act: detachable FUNCTION[TUPLE[IUP_WIDGET, STRING, POINTER, INTEGER], STRING])
  117. -- Request for drag data from source. It is called when the data is
  118. -- dropped.
  119. --
  120. -- ih: identifier of the element that activated the event.
  121. -- type: type of the data. It is one of the registered types in DRAGTYPES.
  122. -- data: buffer to be filled by the application.
  123. -- size: buffer size in bytes. The same value returned by
  124. -- DRAGDATASIZE_CB.
  125. local
  126. operation: INTEGER
  127. do
  128. cb_dragdata := act
  129. if cb_dragdata /= Void then
  130. operation := 1
  131. else
  132. operation := 0
  133. end
  134. iup_open.set_callback (Current, "DRAGDATA_CB", "NONEEDED", operation)
  135. end
  136. set_cb_drag_end (act: detachable FUNCTION[TUPLE[IUP_WIDGET, INTEGER], STRING])
  137. -- Notifies source that drag is done. The only drag callback that is
  138. -- optional. It is called after the data has been dropped.
  139. --
  140. -- ih: identifier of the element that activated the event.
  141. -- action: action performed by the operation (1 = move, 0 = copy, -1 =
  142. -- drag failed or aborted)
  143. --
  144. -- If action is 1 it is responsibility of the application to remove the
  145. -- data from source.
  146. local
  147. operation: INTEGER
  148. do
  149. cb_dragend := act
  150. if cb_dragend /= Void then
  151. operation := 1
  152. else
  153. operation := 0
  154. end
  155. iup_open.set_callback (Current, "DRAGEND_CB", "NONEEDED", operation)
  156. end
  157. -- Callbacks at Drop Target (Must be set when DROPTARGET=True)
  158. set_cb_drop_data (act: detachable FUNCTION[TUPLE[IUP_WIDGET, STRING, POINTER, INTEGER, INTEGER, INTEGER], STRING])
  159. -- Source has sent target the requested data. It is called when the data
  160. -- is dropped. If both drag and drop would be in the same application it
  161. -- would be called after the DRAGDATA_CB callback.
  162. --
  163. -- ih: identifier of the element that activated the event.
  164. -- type: type of the data. It is one of the registered types in DROPTYPES.
  165. -- data: content data received in the drop operation. In Lua is a light
  166. -- userdata.
  167. -- size: data size in bytes.
  168. -- x, y: cursor position relative to the top-left corner of the element.
  169. local
  170. operation: INTEGER
  171. do
  172. cb_dropdata := act
  173. if cb_dropdata /= Void then
  174. operation := 1
  175. else
  176. operation := 0
  177. end
  178. iup_open.set_callback (Current, "DROPDATA_CB", "NONEEDED", operation)
  179. end
  180. set_cb_drop_motion (act: detachable FUNCTION[TUPLE[IUP_WIDGET, INTEGER, INTEGER, STRING], STRING])
  181. -- Notifies destination about drag pointer motion. The only drop callback
  182. -- that is optional. It is called when the mouse moves over any valid
  183. -- drop site.
  184. --
  185. -- ih: identifier of the element that activated the event.
  186. -- x, y: position in the canvas where the event has occurred, in pixels.
  187. -- status: status of mouse buttons and certain keyboard keys at the
  188. -- moment the event was generated. The same macros used for BUTTON_CB can
  189. -- be used for this status.
  190. local
  191. operation: INTEGER
  192. do
  193. cb_dropmotion := act
  194. if cb_dropmotion /= Void then
  195. operation := 1
  196. else
  197. operation := 0
  198. end
  199. iup_open.set_callback (Current, "DROPMOTION_CB", "NONEEDED", operation)
  200. end
  201. feature {IUP}
  202. -- Drag callbacks
  203. execute_dragbegin (x, y: INTEGER): STRING
  204. do
  205. if attached cb_dragbegin as int_cb then
  206. Result := int_cb.item([Current, x, y])
  207. else
  208. Result := "IUP_DEFAULT"
  209. end
  210. end
  211. execute_dragdatasize (type: STRING): INTEGER
  212. do
  213. if attached cb_dragdatasize as int_cb then
  214. Result := int_cb.item([Current, type])
  215. else
  216. Result := 0
  217. end
  218. end
  219. execute_dragdata (type: STRING; data: POINTER; size: INTEGER): STRING
  220. do
  221. if attached cb_dragdata as int_cb then
  222. Result := int_cb.item([Current, type, data, size])
  223. else
  224. Result := "IUP_DEFAULT"
  225. end
  226. end
  227. execute_dragend (action: INTEGER): STRING
  228. do
  229. if attached cb_dragend as int_cb then
  230. Result := int_cb.item([Current, action])
  231. else
  232. Result := "IUP_DEFAULT"
  233. end
  234. end
  235. -- Drop callbacks
  236. execute_dropdata (type: STRING; data: POINTER; size, x, y: INTEGER): STRING
  237. do
  238. if attached cb_dropdata as int_cb then
  239. Result := int_cb.item([Current, type, data, size, x, y])
  240. else
  241. Result := "IUP_DEFAULT"
  242. end
  243. end
  244. execute_dropmotion (x, y: INTEGER; status: STRING): STRING
  245. do
  246. if attached cb_dropmotion as int_cb then
  247. Result := int_cb.item([Current, x, y, status])
  248. else
  249. Result := "IUP_DEFAULT"
  250. end
  251. end
  252. feature {NONE}
  253. cb_dragbegin: detachable FUNCTION[TUPLE[IUP_WIDGET, INTEGER, INTEGER], STRING]
  254. cb_dragdatasize: detachable FUNCTION[TUPLE[IUP_WIDGET, STRING], INTEGER]
  255. cb_dragdata: detachable FUNCTION[TUPLE[IUP_WIDGET, STRING, POINTER, INTEGER], STRING]
  256. cb_dragend: detachable FUNCTION[TUPLE[IUP_WIDGET, INTEGER], STRING]
  257. cb_dropdata: detachable FUNCTION[TUPLE[IUP_WIDGET, STRING, POINTER, INTEGER, INTEGER, INTEGER], STRING]
  258. cb_dropmotion: detachable FUNCTION[TUPLE[IUP_WIDGET, INTEGER, INTEGER, STRING], STRING]
  259. end
  260. -- The MIT License (MIT)
  261. -- Copyright (c) 2016, 2019, 2020 by German A. Arias
  262. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  263. -- of this software and associated documentation files (the "Software"), to deal
  264. -- in the Software without restriction, including without limitation the rights
  265. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  266. -- copies of the Software, and to permit persons to whom the Software is
  267. -- furnished to do so, subject to the following conditions:
  268. --
  269. -- The above copyright notice and this permission notice shall be included in
  270. -- all copies or substantial portions of the Software.
  271. --
  272. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  273. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  274. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  275. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  276. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  277. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  278. -- SOFTWARE.