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