home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / windows / x / 19093 < prev    next >
Encoding:
Text File  |  1992-11-13  |  10.9 KB  |  243 lines

  1. Newsgroups: comp.windows.x
  2. Path: sparky!uunet!snorkelwacker.mit.edu!bloom-beacon!INTERNET!dont-send-mail-to-path-lines
  3. From: adrian@ora.COM (adrian)
  4. Subject: Re: Drag-and-Drop in Motif
  5. Message-ID: <9211121517.AA00554@spike.ora.com>
  6. Sender: root@athena.mit.edu (Wizard A. Root)
  7. Organization: The Internet
  8. Date: Thu, 12 Nov 1992 10:17:50 GMT
  9. Lines: 232
  10.  
  11.  
  12. > What specific drag-and-drop functionality is provided in 1.2?  We are running
  13. > 1.1.x on Suns, and are contemplating bidding on a contract which would
  14. > neccessitate d-n-d, but we have no docs to know what we can promise.  Is 
  15. > 1.2 covered in Volume 6, or should we order a new programmer's manual from
  16. > OSF? ... duh. 
  17.  
  18. The 1.2 edition of Vol 6 is not done yet.
  19.  
  20. Here is the conceptual discussion from Vol4M (1.2 edition) about drag 
  21. and drop.  There are no examples of drag and drop in vol4M.
  22. (This is copyrighted material.)
  23.  
  24. .Ah "Drag and Drop"
  25. Motif 1.2 introduces a new user interface for transferring data within
  26. an application or between applications,
  27. called \fIdrag and drop\fR.  From the user's perspective,
  28. data can be moved or copied by dragging an iconic representation of the
  29. data.\(dg
  30. .FS
  31. \(dgDragging is the act of pressing a mouse button with the pointer
  32. over the object, moving the mouse with the button held down, and
  33. releasing the object in a new location by releasing the mouse button.
  34. .FE
  35. .LP
  36. Mouse button 2 is reserved for drag-and-drop.  When the user
  37. begins a drag with button two over a "drag source", the
  38. pointer is replaced with a special drag icon.  This icon
  39. indicates the type of data being dragged (text, pixmap,
  40. etc.), the drag operation (copy, move, or "link"), and
  41. whether the pointer is over a valid "drop site", an invalid
  42. drop site or no drop site.  The drag icon may change as it
  43. enters and leaves drop sites, and drop sites themselves may
  44. change their visuals when the
  45. drop icon is within them.  These changing graphics in drag
  46. icon and drop site are referred to as "drag over" and "drag
  47. under" visuals, respectively.
  48. .LP
  49. The type of data being dragged and the default operation
  50. (copy, move, or link) depends on the drag source.  If the
  51. drag source supports multiple operations, the user can
  52. select an operation other than the default with the Shift
  53. and Ctrl modifiers.
  54. .LP
  55. The user can cancel a drag by pressing the Escape key.  The
  56. user can request help on a drop site before dropping by pressing
  57. the F1 key.
  58. .LP
  59. Text, List, Label and Button widgets support drag and drop as
  60. drag sources, which means that text can be dragged from them.  Text
  61. and TextField widget support drag and drop as drop sites, which means
  62. that text can be dragged to them.
  63. The Label class also supports dragging of \f(CWPixmap\fP data.
  64. If you use existing widgets, therefore, there is no extra programming
  65. necessary to provide drag and drop.
  66. Custom drag and drop support can be added to any widget.  Custom drag
  67. icons and drop site visuals can also be implemented.
  68. The details of implementing drag and drop in an application are
  69. beyond the scope of this book.  See the \fIOSF/Motif Programming
  70. Manual\fR for more information.
  71. .\"
  72. .\"
  73. .Bh "Drag Protocol"
  74. In order to implement drag-over effects, the originator of
  75. the drag must know when it has entered a valid drop site.
  76. In order to implement customized drag-under effects, the
  77. process controlling the drop site must know when there is a
  78. drag icon inside of it.  It is not possible to gracefully
  79. satisfy all of these requirements with X.  To work around
  80. this, Motif drag-and-drop supports two different drag
  81. protocols with different tradeoffs.  The protocol used
  82. depends on the preference of the user and on
  83. which protocols are supported by the initiating client
  84. and the drop site.
  85. .LP
  86. \fBPreregister Protocol.  \fP In the "preregister" protocol,
  87. the client that initiated the drag is in complete control of
  88. the drag, and the clients controlling drop sites are never
  89. notified when the drag icon enters those drop sites.
  90. Therefore this protocol does not allow a drop site to
  91. implement custom drag-under visuals.  In this protocol, the
  92. client that initiated the drag grabs the X server and
  93. implements the drag icon with a shaped window it moves
  94. around the screen.  When the icon enters a top-level window,
  95. the initiating client reads a server property to determine
  96. the (preregistered) list of valid drop sites within that
  97. window.  The initiating client can implement drag-over
  98. visuals when the icon enters a drop site, and can also
  99. implement simple drag-under visuals (such as highlighting
  100. the drop-site border) for the drop site.
  101. .LP
  102. \fBDynamic Protocol.  \fP In the "dynamic" drag protocol, the
  103. initiating client communicates (dynamically) with other
  104. clients to determine the list of valid drop sites and to
  105. notify then when the drag icon enters one of these drop
  106. sites.  This notification allows these clients to implement
  107. custom drag-under visuals (which can include animation). The
  108. initiating client does not perform a server grab in this
  109. protocol, and the drag icon is implemented by specifying it
  110. as the hardware pointer.  Many X servers restrict the
  111. maximum size of the pointer cursor, so this protocol may not
  112. work with large drag icons.
  113. .\"
  114. .\"
  115. .Bh "Drop Protocol"
  116. The drop protocol is primarily concerned with transferring the
  117. data from initiator to receiver, and is much simpler than
  118. the drag protocol.  It is based directly on the Xt Selection
  119. mechanism used to implement standard Xt cut-and-paste.
  120. .LP
  121. The drag initiator registers a "convert proc" (of type
  122. \f(CWXtConvertSelectionIncrProc\fP) when it starts the drag
  123. with \f(CWXmDragStart()\fP.  In Xt selection terms, starting
  124. a drag is analogous to calling \f(CWXtOwnSelection()\fP.
  125. .LP
  126. The receiving process registers each drop site along with a
  127. callback to invoke when something is dropped on that site.
  128. This callback registers a "transfer proc" (of type
  129. \f(CWXtSelectionCallbackProc\fP) as well as a list of target
  130. types that it would like the dragged data to be converted to
  131. and calls \f(CWXmDropTransferStart()\fP.  In terms of the Xt
  132. selection mechanism, \f(CWXmDropTransferStart()\fP is
  133. analogous to \f(CWXtGetSelectionValues()\fP.
  134. \f(CWXmDropTransferStart()\fP uses the underlying Xt
  135. Selection mechanism to transfer the data.  The drag source's
  136. convert proc is called once for each target type, and the
  137. drop site's transfer proc is called once with the converted
  138. data for each target.
  139. .LP
  140. The drop protocol is also responsible for providing help.
  141. Each drop site should recognize when the user has requested
  142. help and post a dialog box explaining the consequences of
  143. dropping on that site.  This dialog box must give the user
  144. the explicit options to continue with or cancel the drop.
  145. .\"
  146. .\"
  147. .Bh "Operations"
  148. Motif allows three drag-and-drop operations: copy, move, and
  149. link.  The precise semantics of each operation will of
  150. course depend on the dragged data and the drop site.  After
  151. a copy operation there should be two copies of the dragged
  152. data or object.
  153. .LP
  154. After a move, there should only be one copy.  Note that the
  155. drop site is responsible for telling the drag source to
  156. delete its copy of moved data.  It does this by sending a
  157. request to convert the data to the special target "DELETE".
  158. (This target is standardized by the ICCCM, described in Chapter 11.)
  159. .LP
  160. The semantics of the "link" operation are vague: "At the end
  161. of the operation, there is only one copy of the data,
  162. belonging to the initiator, but both applications have
  163. access to it".  In the absence of shared memory, it is not
  164. clear what this means, but the link operation should
  165. presumably be used to establish any sort of "live link",
  166. or to enable dynamic data sharing between applications.
  167. .\"
  168. .\"
  169. .Bh "Application Programming Interface"
  170. Initiating a drag or registering a drop site or initiating a
  171. transfer once a drop has occurred each require a number of
  172. parameters (many of which are optional) to be specified.  To
  173. avoid having functions with large number of arguments, Motif
  174. uses Xt Objects and allows these parameters to be specified
  175. with standard Xt arglists.  Starting a drag with
  176. \f(CWXmDragStart()\fP creates an object of type
  177. \f(CWXmDragContext\fP.  Registering a drop site with
  178. \f(CWXmDropSiteRegister()\fP creates an object of type
  179. \f(CWXmDropSite\fP.  Initiating a data transfer with
  180. \f(CWXmDropTransferStart()\fP creates an object of type
  181. \f(CWXmDropTransfer\fP.  These objects have resources that control
  182. many of the visual effects of drag-and-drop, and also have
  183. callback list resources that provide hooks at many points
  184. during both the drag and the drop.
  185. .\"
  186. .\"
  187. .Bh "Summary: Drag and Drop in Applications"
  188. Programming with Motif drag-and-drop can become almost
  189. arbitrarily complex (the code for a single example in OSF's book is
  190. 65 pages).  There are three general approaches to incorporating
  191. drag-and-drop into applications:
  192. .LP
  193. \fBDo Nothing.  \fP
  194. Many of the standard Motif primitive widgets support
  195. drag-and-drop.  Even if you do nothing, users will be able
  196. to perform basic drag-and-drop of text.
  197. .LP
  198. \fBAdd New Drag Sources and Drop Types.  \fP
  199. You can support additional drag sources by adding a
  200. translation/action pair that calls \f(CWXmDragStart()\fP and
  201. registers a convert proc to handle requests for the data
  202. once it is dropped.  For example you might want to allow the
  203. user to drag the value from a Slider widget, or if you
  204. implemented a custom spreadsheet widget, you might want to
  205. allow the user to drag a column of numbers.  To add a new
  206. drop site, call \f(CWXmDropSiteRegister()\fP and specify a
  207. callback to be called when a drop occurs.  This callback
  208. should register a transfer proc to handle the dropped data
  209. and then call \f(CWXmDropTransferStart()\fP to fetch that
  210. data.
  211. .LP
  212. \fBCustomize Drag-and-Drop.  \fP There are many ways that
  213. you can customize drag-and-drop, most of which can be
  214. controlled through resources and callbacks. You can change
  215. the components of the default drag icon, or specify custom
  216. drag icon components for a particular drag source.  You can
  217. also change the way that the components of the drag icon are
  218. combined or "blended."  Using the \f(CWXtNdragCallback\fP
  219. callback list of the \f(CWXmDragContext\fP 
  220. and \f(CWXmDropSite\fP objects,
  221. you can implements custom drag-over and drag-under visuals.
  222. If a drag site implements custom visuals, you can set
  223. resources to express a preference for the dynamic drag
  224. protocol which allows these visuals.  You can specify a
  225. non-rectangular outline for a drag site, and specify the
  226. sort of highlighting should be done on that border when a
  227. drag icon enters it.  You can specifying a stacking order
  228. for overlapping drop sites.  You can only have one drop site
  229. for a widget, but with some extra coding work, you can
  230. .ne 2
  231. implement a single drop site that appears and functions as a
  232. number of separate sites within the widget.
  233. .\"
  234.  
  235.  
  236. *************************************************************
  237. Adrian Nye (314) 531-1231    Editor, The X Resource
  238. O'Reilly & Associates, Inc., Publishers of Nutshell Handbooks
  239. 4466 West Pine Blvd.  20-G   St. Louis MO 63108
  240. Internet:   adrian@ora.com        UUCP:   uunet!ora!adrian      
  241. *************************************************************
  242.  
  243.