tkClipboard.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/*
* tkClipboard.c --
*
* This file manages the clipboard for the Tk toolkit,
* maintaining a collection of data buffers that will be
* supplied on demand to requesting applications.
*
* Copyright (c) 1994 The Regents of the University of California.
* Copyright (c) 1994-1995 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* SCCS: @(#) tkClipboard.c 1.14 96/02/15 18:52:37
*/
#include "tkInt.h"
#include "tkSelect.h"
/*
* Prototypes for procedures used only in this file:
*/
static int ClipboardWindowHandler _ANSI_ARGS_((
int maxBytes));
/*
*----------------------------------------------------------------------
*
* ClipboardHandler --
*
* This procedure acts as selection handler for the
* clipboard manager. It extracts the required chunk of
* data from the buffer chain for a given selection target.
*
* Results:
* The return value is a count of the number of bytes
* actually stored at buffer.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
int offset; /* Return selection bytes starting at this
* offset. */
char *buffer; /* Place to store converted selection. */
int maxBytes; /* Maximum # of bytes to store at buffer. */
{
int count = 0;
int scanned = 0;
/*
* Skip to buffer containing offset byte
*/
return 0;
}
break;
}
}
/*
* Copy up to maxBytes or end of list, switching buffers as needed.
*/
while (1) {
return maxBytes;
} else {
}
break;
}
}
return count;
}
/*
*----------------------------------------------------------------------
*
* ClipboardAppHandler --
*
* This procedure acts as selection handler for retrievals of type
* TK_APPLICATION. It returns the name of the application that
* owns the clipboard. Note: we can't use the default Tk
* selection handler for this selection type, because the clipboard
* window isn't a "real" window and doesn't have the necessary
* information.
*
* Results:
* The return value is a count of the number of bytes
* actually stored at buffer.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
int offset; /* Return selection bytes starting at this
* offset. */
char *buffer; /* Place to store converted selection. */
int maxBytes; /* Maximum # of bytes to store at buffer. */
{
char *p;
if (length <= 0) {
return 0;
}
}
return length;
}
/*
*----------------------------------------------------------------------
*
* ClipboardWindowHandler --
*
* This procedure acts as selection handler for retrievals of
* type TK_WINDOW. Since the clipboard doesn't correspond to
* any particular window, we just return ".". We can't use Tk's
* default handler for this selection type, because the clipboard
* window isn't a valid window.
*
* Results:
* The return value is 1, the number of non-null bytes stored
* at buffer.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
static int
int offset; /* Return selection bytes starting at this
* offset. */
char *buffer; /* Place to store converted selection. */
int maxBytes; /* Maximum # of bytes to store at buffer. */
{
buffer[0] = '.';
buffer[1] = 0;
return 1;
}
/*
*----------------------------------------------------------------------
*
* ClipboardLostSel --
*
* This procedure is invoked whenever clipboard ownership is
* claimed by another window. It just sets a flag so that we
* know the clipboard was taken away.
*
* Results:
* None.
*
* Side effects:
* The clipboard is marked as inactive.
*
*----------------------------------------------------------------------
*/
static void
{
dispPtr->clipboardActive = 0;
}
/*
*----------------------------------------------------------------------
*
* Tk_ClipboardClear --
*
* Take control of the clipboard and clear out the previous
* contents. This procedure must be invoked before any
* calls to Tk_AppendToClipboard.
*
* Results:
* A standard Tcl result. If an error occurs, an error message is
* left in interp->result.
*
* Side effects:
* From now on, requests for the CLIPBOARD selection will be
* directed to the clipboard manager routines associated with
* clipWindow for the display of tkwin. In order to guarantee
* atomicity, no event handling should occur between
* Tk_ClipboardClear and the following Tk_AppendToClipboard
* calls. This procedure may cause a user-defined LostSel command
* to be invoked when the CLIPBOARD is claimed, so any calling
* function should be reentrant at the point Tk_ClipboardClear is
* invoked.
*
*----------------------------------------------------------------------
*/
int
* clipboard; identifies application and
* display. */
{
int result;
return result;
}
}
/*
* Discard any existing clipboard data and delete the selection
* handler(s) associated with that data.
*/
targetPtr = nextTargetPtr) {
}
}
/*
* Reclaim the clipboard selection if we lost it.
*/
if (!dispPtr->clipboardActive) {
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* Tk_ClipboardAppend --
*
* Append a buffer of data to the clipboard. The first buffer of
* a given type determines the format for that type. Any successive
* appends to that type must have the same format or an error will
* be returned. Tk_ClipboardClear must be called before a sequence
* of Tk_ClipboardAppend calls can be issued. In order to guarantee
* atomicity, no event handling should occur between Tk_ClipboardClear
* and the following Tk_AppendToClipboard calls.
*
* Results:
* A standard Tcl result. If an error is returned, an error message
* is left in interp->result.
*
* Side effects:
* The specified buffer will be copied onto the end of the clipboard.
* The clipboard maintains a list of buffers which will be used to
* supply the data for a selection get request. The first time a given
* type is appended, Tk_ClipboardAppend will register a selection
* handler of the appropriate type.
*
*----------------------------------------------------------------------
*/
int
* clipboard item, e.g. STRING or LENGTH. */
* information should be returned to
* the requestor. */
char* buffer; /* NULL terminated string containing the data
* to be added to the clipboard. */
{
/*
* If this application doesn't already own the clipboard, clear
* the clipboard. If we don't own the clipboard selection, claim it.
*/
} else if (!dispPtr->clipboardActive) {
}
/*
* Check to see if the specified target is already present on the
* clipboard. If it isn't, we need to create a new target; otherwise,
* we just append the new buffer to the clipboard list.
*/
break;
}
"\" does not match current format \"",
return TCL_ERROR;
}
/*
* Append a new buffer to the buffer chain.
*/
} else {
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* Tk_ClipboardCmd --
*
* This procedure is invoked to process the "clipboard" Tcl
* command. See the user documentation for details on what
* it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
*----------------------------------------------------------------------
*/
int
* interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
int count;
char c;
char **args;
if (argc < 2) {
" option ?arg arg ...?\"", (char *) NULL);
return TCL_ERROR;
}
c = argv[1][0];
char *targetName = NULL;
char *formatName = NULL;
if (args[0][0] != '-') {
break;
}
c = args[0][1];
args++;
count--;
break;
}
} else if ((c == 'f')
} else if ((c == 't')
} else {
"\"", (char *) NULL);
return TCL_ERROR;
}
}
if (count != 1) {
" append ?options? data\"", (char *) NULL);
return TCL_ERROR;
}
}
return TCL_ERROR;
}
if (targetName != NULL) {
} else {
}
if (formatName != NULL) {
} else {
}
if (args[0][0] != '-') {
break;
}
if (count < 2) {
"\" missing", (char *) NULL);
return TCL_ERROR;
}
c = args[0][1];
} else {
"\"", (char *) NULL);
return TCL_ERROR;
}
}
if (count > 0) {
" clear ?options?\"", (char *) NULL);
return TCL_ERROR;
}
}
return TCL_ERROR;
}
} else {
"bad option \"%.50s\": must be clear or append",
argv[1]);
return TCL_ERROR;
}
}
/*
*----------------------------------------------------------------------
*
* TkClipInit --
*
* This procedure is called to initialize the window for claiming
* clipboard ownership and for receiving selection get results. This
* function is called from tkSelect.c as well as tkClipboard.c.
*
* Results:
* The result is a standard Tcl return value, which is normally TCL_OK.
* If an error occurs then an error message is left in interp->result
* and TCL_ERROR is returned.
*
* Side effects:
* Sets up the clipWindow and related data structures.
*
*----------------------------------------------------------------------
*/
int
* reporting. */
{
dispPtr->clipboardActive = 0;
/*
* Create the window used for clipboard ownership and selection retrieval,
* and set up an event handler for it.
*/
return TCL_ERROR;
}
/*
* Need to invoke selection initialization to make sure that
* atoms we depend on below are defined.
*/
}
/*
* Create selection handlers for types TK_APPLICATION and TK_WINDOW
* on this window. Can't use the default handlers for these types
* because this isn't a full-fledged window.
*/
return TCL_OK;
}