home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / documentation / documents / a252clip < prev    next >
Encoding:
Internet Message Format  |  1999-04-27  |  11.9 KB

  1. From: pcolmer@acorn.co.uk (Philip Colmer)
  2. Subject: The RISC OS Selection Model and Clipboard
  3. Date: 2 Dec 1993 09:03:28 -0000
  4.  
  5. Support Group Application Note Number: 240
  6. Issue: 1.00
  7. Author: SH/(JB)
  8.  
  9.  
  10.           The RISC OS Selection Model and Clipboard
  11.  
  12.  
  13. Preface
  14. -------
  15.  
  16. The second edition of the RISC OS Style Guide recommends the use of
  17. clipboard-based (cut-copy-paste) data transfer. This application note
  18. describes how this could be implemented, and how to make sure that your
  19. applications co-operate with others to promote consistent data transfer
  20. facilities.
  21.  
  22. This application note is based on a protocol designed by Iota Software Ltd.
  23.  
  24. Applicable Hardware: All Acorn RISC OS based computers.
  25. Related Application Notes: The RISC OS Drag-and-Drop System.
  26.  
  27. Copyright (c) Acorn Computers Limited 1993.
  28.  
  29.  
  30. Definitions
  31. -----------
  32.  
  33. Selection: The portion of a document which the user has chosen as the target
  34. for subsequent  operations. This may be a contiguous selection (as in the
  35. case of selected text) or a non-contiguous selection (as in the case of a
  36. number of selected files in the Filer).
  37.  
  38. Caret: the position in a document where typed characters or pasted clipboard
  39. contents will be  placed. In textual documents, the caret is often shown by
  40. an I-beam, but other representations of the caret may be more appropriate for
  41. other kinds of data. Some editors, such as !Draw, do not have a visible
  42. insertion point, but still "grab the caret" in order to receive keystroke
  43. events.
  44.  
  45. Input focus: the window where keystroke events will be delivered.
  46.  
  47. Clipboard: a temporary storage area that holds data while the user is copying
  48. or moving it (either within one application or between applications).
  49.  
  50. Cut: the operation that the user invokes to transfer the current selection to
  51. the clipboard. The selection is deleted from the source document.
  52.  
  53. Copy: as cut, but does not delete the original.
  54.  
  55. Paste: the operation that the user invokes to transfer the clipboard contents
  56. into a document.
  57.  
  58.  
  59. The Selection Model
  60. -------------------
  61.  
  62. There should normally be one caret or selection active in each window. They
  63. are mutually exclusive; a window's caret and selection are not normally
  64. visible at the same time. When the user clicks to position the caret or makes
  65. a selection, any existing selection in the same window should be de-selected. 
  66. In text editors it is helpful to think of the caret as a zero-width
  67. selection; if the user makes a selection, then the caret becomes invisible,
  68. and if the user clicks to set the caret, then any selection is de-selected.
  69.  
  70. Each window has its own selection, even multiple views of the same document.
  71. Making a selection in one window should not affect any selections active in
  72. other windows.
  73.  
  74.  
  75. The Clipboard
  76. -------------
  77.  
  78. Copying and moving data within and between windows is accomplished by means
  79. of a temporary holding area known as the clipboard. The clipboard supports
  80. three operations. The Copy operation copies the selected data from the source
  81. window to the clipboard, leaving the selection intact. The Cut operation is
  82. similar to Copy, but deletes the selected data from the document. The Paste
  83. operation inserts a copy of the clipboard contents to the caret position of
  84. the destination window (or, if there is a selection rather than a caret, it
  85. replaces the selection with the contents of the clipboard). The user combines
  86. these operations as required to effect the copying and movement of data. The
  87. clipboard is a systemwide entity, so the operations work between applications
  88. as well as within one application.
  89.  
  90. From an implementation point of view, the clipboard is not a specific area of
  91. memory, but a notional entity  which applications claim and keep track of by
  92. means of messages. The data "on" the clipboard is held by the application
  93. that performed the last "cut" or "copy" operation.
  94.  
  95. Data entered from the keyboard, or pasted in from the clipboard, should
  96. replace the current selection if there  is one, or be inserted at the caret
  97. position if there is no selection. Graphical applications that do not have a
  98. visible caret must choose where to position pasted data in an appropriate
  99. way. In any case, the pasted data should be automatically selected so that
  100. the user can immediately cut it again should this be desired.
  101.  
  102. If the user replaces a selection by typing new data, the selection should be
  103. replaced by a caret and the  deleted data should be cut to the clipboard as a
  104. safety measure - the user can paste it back again if the operation was
  105. unintended. Do not do this if the selection is replaced by pasting from the
  106. clipboard, because it would prevent the same data being pasted multiple
  107. times.
  108.  
  109.  
  110. Caret / Selection / Clipboard control
  111. -------------------------------------
  112.  
  113.   Ownership of the caret / selection / clipboard
  114.  
  115. Each task keeps a separate record of the position of the caret/selection for
  116. each of its windows. It also stores flags to indicate whether it currently
  117. "owns" the input focus and the clipboard.
  118.  
  119. To enable applications to track changes in the status these entities, the
  120. following message is used:
  121.  
  122.   Message_ClaimEntity (15)
  123.     0 message size (24)
  124.     4 task handle of task making the claim
  125.     8 message id
  126.    12 your_ref (0)
  127.    16 Message_ClaimEntity
  128.    20 flags:
  129.         bits 0 and 1 set => caret or selection being claimed
  130.         bit 2 set => clipboard being claimed
  131.         all other bits reserved (must be 0)
  132.  
  133. This message should be broadcast to all tasks as the caret / selection or
  134. clipboard are claimed.
  135.  
  136. When the user positions the caret or makes a selection, the application
  137. should claim ownership of the input focus by broadcasting this message with
  138. bits 0 and 1 set. When positioning the caret, the application can choose
  139. whether to use the Wimp's caret or draw its own representation of the caret
  140. more appropriate to the type of data being edited. When making a selection,
  141. the application must hide the caret; it should do this by setting the Wimp's
  142. caret to the window containing the selection, but invisible. This is
  143. necessary to direct keystroke events to this window.
  144.  
  145. When a task receives this message with bits 0 or 1 set, it should check to
  146. see if any of its windows currently own the input focus. If so, it should
  147. update its flag to indicate that it no longer has the focus, and remove any
  148. representation of the caret which it has drawn (unless it uses the Wimp
  149. caret, which will be undrawn automatically.)  It may optionally alter the
  150. appearance of its window to emphasize the fact that it does not have the
  151. input focus, for example by shading the selection. A task that receives
  152. Message_ClaimEntity with only one of bits 0 and 1 set should act as if both
  153. bits were set.
  154.  
  155. When the user performs a Cut or Copy operation, the application should claim
  156. ownership of the clipboard by broadcasting this message with bit 2 set.
  157.  
  158. When a task receives this message with bit 2 set it should set a flag to
  159. indicate that the clipboard is held by another application and deallocate the
  160. memory being used to store the clipboard contents.
  161.  
  162. To improve performance, the following optimisation should be made:
  163.  
  164. When claiming the input focus or clipboard, a task should check to see if it
  165. already owns that entity, and if so, there is no need to issue the broadcast.
  166. It should then take care of updating the caret / selection / clipboard to the
  167. new value (updating the display in the case of the selection).
  168.  
  169.  
  170. LoseCaret / GainCaret events
  171. ----------------------------
  172.  
  173. As far as keeping track of whether they have the input focus is concerned,
  174. applications implementing the above protocols should ignore
  175. LoseCaret/GainCaret messages This is because the Wimp often `borrows' the
  176. caret to put it in writable menu icons and when this happens the application
  177. should not regard the input focus as being lost.
  178.  
  179. Older applications which claim the caret without using the claiming mechanism
  180. described will also not indulge in the cut/copy/paste protocol so, again, the
  181. LoseCaret event should be ignored.
  182.  
  183.  
  184. Selection History
  185. -----------------
  186.  
  187. To return to a window that does not currently have the input focus, the user
  188. clicks in it to set the caret. Because the caret and selection are mutually
  189. exclusive within each window, this causes any selection that was pending to
  190. be lost. However, the user may occasionally want to return the input focus to
  191. a window without losing its selection, particularly if re-making the
  192. selection would be fiddly or time-consuming.
  193.  
  194. Therefore a click within the current selection or in a "dead" area of the
  195. window (e.g. in a border) should be treated specially. It should cause the
  196. window to regain the input focus without setting the caret position and hence
  197. without losing the current selection. The application should broadcast
  198. Message_ClaimEntity with bits 0 and 1 set, and set the Wimp caret to the
  199. window. If there is a selection in the window then the caret should be made
  200. invisible. If there is no selection then the caret should be shown and
  201. restored to its previous position within the window.
  202.  
  203.  
  204. Cutting and pasting data
  205. ------------------------
  206.  
  207. Applications should provide menu entries for Cut, Copy and Paste operations.
  208. Refer to the Style Guide for details of where to place these in your menu
  209. tree and which keyboard shortcuts to assign to them.
  210.  
  211.   Cut
  212.  
  213. If the application does not have a selection, then this is a not possible and
  214. should be shaded on the menu.
  215.  
  216. If the application already owns the clipboard, it should free its current
  217. contents. If not, it should claim the clipboard by broadcasting
  218. Message_ClaimEntity setting flags bit 2. It should then set up its internal 
  219. representation of the clipboard contents to be a copy of the selected data,
  220. and delete the selection. 
  221.  
  222.   Copy
  223.  
  224. As Cut, but the selection should not be deleted.
  225.  
  226.   Paste
  227.  
  228. The application should first check to see if it owns the clipboard, and use
  229. the data directly if so. If is does not own it, it should broadcast the
  230. following message:
  231.  
  232.   Message_DataRequest (16)
  233.     0 message size
  234.     4 task handle of task requesting data
  235.     8 message id
  236.    12 your_ref (0)
  237.    16 Message_DataRequest
  238.    20 window handle
  239.    24 internal handle to indicate destination of data
  240.    28 x
  241.    32 y
  242.    36 flags:
  243.         bit 2 set => send data from clipboard (must be 1)
  244.         all other bits reserved (must be 0)
  245.    40 list of filetypes in order of preference,
  246.       terminated by -1
  247.  
  248. The sender must set flags bit 2, and the receiver must check this bit, and
  249. ignore the message if it is not set. All other flags bits must be cleared by
  250. the sender and ignored by the receiver.
  251.  
  252. If an application receiving this message owns the clipboard, it should choose
  253. the earliest filetype in the list that it can provide, and if none are
  254. possible it should provide the data its original (native) format. Note that
  255. the list can be null, to indicate that the native data should be sent. It
  256. should reply using the normal Message_DataSave protocol. Bytes 20 through 35
  257. of the DataSave block should be copied directly from the corresponding bytes
  258. of the Message_DataRequest block, whilst the estimated size field, filetype
  259. and filename must be filled in.
  260.  
  261. When the application that initiated the Paste receives the Message_DataSave,
  262. it should check the filetype to ensure that it knows how to deal with it - it
  263. may be the clipboard owner's native format. If it cannot, it may back out of
  264. the transaction by ignoring the message. Otherwise, it should continue with
  265. the DataSave protocol as detailed in the Programmer's Reference Manual.
  266.  
  267. If your application needs to find out whether there is data available to
  268. paste, but does not actually want to  receive the data, you should broadcast
  269. a Message_DataRequest as described above. If no task replies (i.e. you get
  270. the message back) then there is no clipboard data available. If a
  271. Message_DataSave is received, then you should ignore it (fail to reply),
  272. which will cause the operation to be silently aborted by the other task. You
  273. can then use the filetype field of the Message_DataSave to determine whether
  274. the data being offered by the other task is in a suitable format for you to
  275. receive.
  276.  
  277. This mechanism can be used if you want to shade out the Paste menu item when
  278. there is no suitable data for pasting.
  279.