tkSelect.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * tkSelect.h --
  3. *
  4. * Declarations of types shared among the files that implement selection
  5. * support.
  6. *
  7. * Copyright (c) 1995 Sun Microsystems, Inc.
  8. *
  9. * See the file "license.terms" for information on usage and redistribution of
  10. * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11. */
  12. #ifndef _TKSELECT
  13. #define _TKSELECT
  14. /*
  15. * When a selection is owned by a window on a given display, one of the
  16. * following structures is present on a list of current selections in the
  17. * display structure. The structure is used to record the current owner of a
  18. * selection for use in later retrieval requests. There is a list of such
  19. * structures because a display can have multiple different selections active
  20. * at the same time.
  21. */
  22. typedef struct TkSelectionInfo {
  23. Atom selection; /* Selection name, e.g. XA_PRIMARY. */
  24. Tk_Window owner; /* Current owner of this selection. */
  25. int serial; /* Serial number of last XSelectionSetOwner
  26. * request made to server for this selection
  27. * (used to filter out redundant
  28. * SelectionClear events). */
  29. Time time; /* Timestamp used to acquire selection. */
  30. Tk_LostSelProc *clearProc; /* Procedure to call when owner loses
  31. * selection. */
  32. ClientData clearData; /* Info to pass to clearProc. */
  33. struct TkSelectionInfo *nextPtr;
  34. /* Next in list of current selections on this
  35. * display. NULL means end of list. */
  36. } TkSelectionInfo;
  37. /*
  38. * One of the following structures exists for each selection handler created
  39. * for a window by calling Tk_CreateSelHandler. The handlers are linked in a
  40. * list rooted in the TkWindow structure.
  41. */
  42. typedef struct TkSelHandler {
  43. Atom selection; /* Selection name, e.g. XA_PRIMARY. */
  44. Atom target; /* Target type for selection conversion, such
  45. * as TARGETS or STRING. */
  46. Atom format; /* Format in which selection info will be
  47. * returned, such as STRING or ATOM. */
  48. Tk_SelectionProc *proc; /* Procedure to generate selection in this
  49. * format. */
  50. ClientData clientData; /* Argument to pass to proc. */
  51. int size; /* Size of units returned by proc (8 for
  52. * STRING, 32 for almost anything else). */
  53. struct TkSelHandler *nextPtr;
  54. /* Next selection handler associated with same
  55. * window (NULL for end of list). */
  56. } TkSelHandler;
  57. /*
  58. * When the selection is being retrieved, one of the following structures is
  59. * present on a list of pending selection retrievals. The structure is used to
  60. * communicate between the background procedure that requests the selection
  61. * and the foreground event handler that processes the events in which the
  62. * selection is returned. There is a list of such structures so that there can
  63. * be multiple simultaneous selection retrievals (e.g. on different displays).
  64. */
  65. typedef struct TkSelRetrievalInfo {
  66. Tcl_Interp *interp; /* Interpreter for error reporting. */
  67. TkWindow *winPtr; /* Window used as requestor for selection. */
  68. Atom selection; /* Selection being requested. */
  69. Atom property; /* Property where selection will appear. */
  70. Atom target; /* Desired form for selection. */
  71. Tk_GetSelProc *proc; /* Procedure to call to handle pieces of
  72. * selection. */
  73. ClientData clientData; /* Argument for proc. */
  74. int result; /* Initially -1. Set to a Tcl return value
  75. * once the selection has been retrieved. */
  76. Tcl_TimerToken timeout; /* Token for current timeout procedure. */
  77. int idleTime; /* Number of seconds that have gone by without
  78. * hearing anything from the selection
  79. * owner. */
  80. Tcl_EncodingState encState; /* Holds intermediate state during translations
  81. * of data that cross buffer boundaries. */
  82. int encFlags; /* Encoding translation state flags. */
  83. Tcl_DString buf; /* Buffer to hold translation data. */
  84. struct TkSelRetrievalInfo *nextPtr;
  85. /* Next in list of all pending selection
  86. * retrievals. NULL means end of list. */
  87. } TkSelRetrievalInfo;
  88. /*
  89. * The clipboard contains a list of buffers of various types and formats. All
  90. * of the buffers of a given type will be returned in sequence when the
  91. * CLIPBOARD selection is retrieved. All buffers of a given type on the same
  92. * clipboard must have the same format. The TkClipboardTarget structure is
  93. * used to record the information about a chain of buffers of the same type.
  94. */
  95. typedef struct TkClipboardBuffer {
  96. char *buffer; /* Null terminated data buffer. */
  97. long length; /* Length of string in buffer. */
  98. struct TkClipboardBuffer *nextPtr;
  99. /* Next in list of buffers. NULL means end of
  100. * list . */
  101. } TkClipboardBuffer;
  102. typedef struct TkClipboardTarget {
  103. Atom type; /* Type conversion supported. */
  104. Atom format; /* Representation used for data. */
  105. TkClipboardBuffer *firstBufferPtr;
  106. /* First in list of data buffers. */
  107. TkClipboardBuffer *lastBufferPtr;
  108. /* Last in list of clipboard buffers. Used to
  109. * speed up appends. */
  110. struct TkClipboardTarget *nextPtr;
  111. /* Next in list of targets on clipboard. NULL
  112. * means end of list. */
  113. } TkClipboardTarget;
  114. /*
  115. * It is possible for a Tk_SelectionProc to delete the handler that it
  116. * represents. If this happens, the code that is retrieving the selection
  117. * needs to know about it so it doesn't use the now-defunct handler structure.
  118. * One structure of the following form is created for each retrieval in
  119. * progress, so that the retriever can find out if its handler is deleted. All
  120. * of the pending retrievals (if there are more than one) are linked into a
  121. * list.
  122. */
  123. typedef struct TkSelInProgress {
  124. TkSelHandler *selPtr; /* Handler being executed. If this handler is
  125. * deleted, the field is set to NULL. */
  126. struct TkSelInProgress *nextPtr;
  127. /* Next higher nested search. */
  128. } TkSelInProgress;
  129. /*
  130. * Chunk size for retrieving selection. It's defined both in words and in
  131. * bytes; the word size is used to allocate buffer space that's guaranteed to
  132. * be word-aligned and that has an extra character for the terminating NULL.
  133. */
  134. #define TK_SEL_BYTES_AT_ONCE 4000
  135. #define TK_SEL_WORDS_AT_ONCE 1001
  136. /*
  137. * Declarations for procedures that are used by the selection-related files
  138. * but shouldn't be used anywhere else in Tk (or by Tk clients):
  139. */
  140. MODULE_SCOPE TkSelInProgress *TkSelGetInProgress(void);
  141. MODULE_SCOPE void TkSelSetInProgress(TkSelInProgress *pendingPtr);
  142. MODULE_SCOPE void TkSelClearSelection(Tk_Window tkwin, XEvent *eventPtr);
  143. MODULE_SCOPE int TkSelDefaultSelection(TkSelectionInfo *infoPtr,
  144. Atom target, char *buffer, int maxBytes,
  145. Atom *typePtr);
  146. #ifndef TkSelUpdateClipboard
  147. MODULE_SCOPE void TkSelUpdateClipboard(TkWindow *winPtr,
  148. TkClipboardTarget *targetPtr);
  149. #endif
  150. #endif /* _TKSELECT */