head	1.7;
access;
symbols
	core-8-4-19:1.6
	core-8-4-18:1.6
	core-8-4-17:1.6
	core-8-4-16:1.6
	core-8-4-15:1.6
	core-8-4-14:1.6
	core-8-4-13:1.6
	core-8-4-12:1.6
	core-8-4-11:1.6
	core-8-4-10:1.6
	core-8-4-9-branch:1.6.0.14
	core-8-4-9:1.6
	core-8-4-8:1.6
	core-8-4-7:1.6
	core-8-5-a1:1.6
	core-8-4-6:1.6
	core-8-4-5:1.6
	mistachkin-dev-branch:1.6.0.12
	core-8-4-4:1.6
	core-8-4-3:1.6
	core-8-4-branch:1.6.0.10
	core-8-4-2:1.6
	core-8-4-1:1.6
	core-8-3-5:1.6
	core-8-4-0:1.6
	macosx-8-4-merge-2002-08-31-trunk:1.6
	macosx-8-4-premerge-2002-08-31-branch:1.6
	macosx-8-4-premerge-2002-08-31-trunk:1.6
	macosx-8-4-merge-2002-08-30-branch:1.6
	macosx-8-4-merge-2002-08-30-trunk:1.6
	macosx-8-4-merge-2002-08-20-branch:1.6
	macosx-8-4-merge-2002-08-20-trunk:1.6
	core-8-4-b2:1.6
	core-8-4-b1:1.6
	macosx-premerge-6-9-02:1.6
	core-8-4-a4:1.6
	core-8-3-4:1.6
	macosx-8-4-branch:1.6.0.8
	macosx-8-4-branchpoint:1.6
	core-8-4-a3:1.6
	core-8-3-3:1.6
	dgp-privates-into-namespace:1.6.0.6
	tclpro-1-5-0:1.6
	core-8-4-win-speedup:1.6.0.4
	core-8-4-a2:1.6
	tclpro-1-4-1:1.6
	tclpro-1-4-0:1.6
	core-8-3-2:1.6
	ajuba-ajuba2-2-1-base:1.6
	ajuba-ajuba2-2-0:1.6
	core-8-4-a1:1.6
	core-8-3-1-branch:1.6.0.2
	core-8-3-1:1.6
	scriptics-sc-2-0-b5:1.6
	scriptics-sc-2-0-fixed:1.6
	scriptics-sc-2-0-b2:1.6
	scriptics-sc-2-0-b1:1.6
	core-8-3-0:1.6
	core-8-3-b2:1.5
	core-8-3-b1:1.4
	scriptics-sc-1-1:1.4
	scriptics-sc-1-1-b1:1.4
	core-8-2-3:1.4
	scriptics-sc-1-1-branch:1.4.0.8
	scriptics-sc-1-1-base:1.4
	scriptics-sc-1-0:1.4
	scriptics-sc-1-0-branch:1.4.0.6
	scriptics-sc-1-0-base:1.4
	core-8-2-2:1.4
	core-8-2-1:1.4
	scriptics-bc-1-0-b1:1.4
	core-8-2-1-branch:1.4.0.4
	scriptics-tclpro-1-3-0:1.4
	core-8-2-0:1.4
	core-8-2-b3-branch:1.4.0.2
	core-8-2-b3-base:1.4
	scriptics-tclpro-1-3-b4:1.4
	core-8-2-b2:1.4
	scriptics-tclpro-1-3-b3:1.4
	core-8-2-b1:1.4
	scriptics-tclpro-1-3-b2:1.3
	merge-to-mainline-5/21/99:1.3
	scriptics-tclpro-1-3-b2-branch:1.3.0.2
	core-8-1-1:1.3
	scriptics-tclpro-1-3-b1:1.3
	core-8-1-1-base:1.3
	core-8-1-0:1.3
	merge-to-mainline-4-29-99:1.3
	merge-to-mainline-4-23-99:1.3
	core-8-1-branch-old:1.1.0.4
	core-8-0-6-branch:1.2.0.6
	core-8-0-6-base:1.2
	core-8-0-5:1.2
	core-8-1-b3:1.1.4.3
	core-8-1-b2:1.1.4.3
	dev-8-1-stubs-branch:1.1.4.3.0.2
	dev-stubs-branch:1.2.0.4
	scriptics-tclpro-1-2:1.2
	scriptics-tclpro-1-2-b2:1.2
	core-8-1-merge-2/10/99:1.2
	core-8-0-5-branch:1.2.0.2
	core-8-0-5-base:1.2
	scriptics-tclpro-1-2-b1:1.2
	scriptics-tclpro-1-2-a1:1.2
	core-8-1-b1:1.1.4.2
	core-8-0-4:1.2
	core-8-1-a2:1.1.4.1
	core-8-0-2:1.1
	core-8-0-3:1.2;
locks; strict;
comment	@ * @;


1.7
date	2004.03.17.18.15.45;	author das;	state dead;
branches;
next	1.6;

1.6
date	2000.02.10.08.53.11;	author jingham;	state Exp;
branches;
next	1.5;

1.5
date	2000.01.06.02.22.36;	author hobbs;	state Exp;
branches;
next	1.4;

1.4
date	99.05.22.06.32.32;	author jingham;	state Exp;
branches;
next	1.3;

1.3
date	99.04.16.01.51.30;	author stanton;	state Exp;
branches;
next	1.2;

1.2
date	98.09.14.18.23.34;	author stanton;	state Exp;
branches;
next	1.1;

1.1
date	98.04.01.09.57.00;	author rjohnson;	state Exp;
branches
	1.1.4.1;
next	;

1.1.4.1
date	98.09.29.00.25.37;	author stanton;	state Exp;
branches;
next	1.1.4.2;

1.1.4.2
date	98.09.30.02.18.03;	author stanton;	state Exp;
branches;
next	1.1.4.3;

1.1.4.3
date	98.12.13.08.16.12;	author lfb;	state Exp;
branches;
next	;


desc
@@


1.7
log
@Removed support for Mac OS Classic platform [Patch 918139]
@
text
@/*
 * tkMacClipboard.c --
 *
 * 	This file manages the clipboard for the Tk toolkit.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @@(#) $Id: tkMacClipboard.c,v 1.6 2000/02/10 08:53:11 jingham Exp $
 */

#include "tkInt.h"
#include "tkPort.h"
#include "tkMacInt.h"

#include <Scrap.h>
#include <Events.h>

#include "tkSelect.h"

/*
 *----------------------------------------------------------------------
 *
 * TkSelGetSelection --
 *
 *	Retrieve the specified selection from another process.  For
 *	now, only fetching XA_STRING from CLIPBOARD is supported.
 *	Eventually other types should be allowed.
 * 
 * Results:
 *	The return value is a standard Tcl return value.
 *	If an error occurs (such as no selection exists)
 *	then an error message is left in the interp's result.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkSelGetSelection(
    Tcl_Interp *interp,		/* Interpreter to use for reporting
				 * errors. */
    Tk_Window tkwin,		/* Window on whose behalf to retrieve
				 * the selection (determines display
				 * from which to retrieve). */
    Atom selection,		/* Selection to retrieve. */
    Atom target,		/* Desired form in which selection
				 * is to be returned. */
    Tk_GetSelProc *proc,	/* Procedure to call to process the
				 * selection, once it has been retrieved. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    int result;
    long length, offset = 0;
    Handle handle;

    if ((selection == Tk_InternAtom(tkwin, "CLIPBOARD"))
	    && (target == XA_STRING)) {
	/* 
	 * Get the scrap from the Macintosh global clipboard.
	 */
	handle = NewHandle(1);
	length = GetScrap(handle, 'TEXT', &offset);
	if (length > 0) {
	    Tcl_DString encodedText;

	    SetHandleSize(handle, (Size) length + 1);
	    HLock(handle);
	    (*handle)[length] = '\0';

	    Tcl_ExternalToUtfDString(NULL, *handle, length, &encodedText);
	    result = (*proc)(clientData, interp,
		    Tcl_DStringValue(&encodedText));
	    Tcl_DStringFree(&encodedText);

	    HUnlock(handle);
	    DisposeHandle(handle);
	    return result;
	}
	
	DisposeHandle(handle);
    }
    
    Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
	" selection doesn't exist or form \"", Tk_GetAtomName(tkwin, target),
	"\" not defined", (char *) NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * TkSetSelectionOwner --
 *
 *	This function claims ownership of the specified selection.
 *	If the selection is CLIPBOARD, then we empty the system
 *	clipboard.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
XSetSelectionOwner(
    Display* display,	/* X Display. */
    Atom selection,	/* What selection to own. */
    Window owner,	/* Window to be the owner. */
    Time time)		/* The current time? */
{
    Tk_Window tkwin;
    TkDisplay *dispPtr;

    /*
     * This is a gross hack because the Tk_InternAtom interface is broken.
     * It expects a Tk_Window, even though it only needs a Tk_Display.
     */

    tkwin = (Tk_Window) TkGetMainInfoList()->winPtr;

    if (selection == Tk_InternAtom(tkwin, "CLIPBOARD")) {

	/*
	 * Only claim and empty the clipboard if we aren't already the
	 * owner of the clipboard.
	 */

	dispPtr = TkGetMainInfoList()->winPtr->dispPtr;
	if (dispPtr->clipboardActive) {
	    return;
	}
	ZeroScrap();
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkSelUpdateClipboard --
 *
 *	This function is called to force the clipboard to be updated
 *	after new data is added.  On the Mac we don't need to do
 *	anything.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkSelUpdateClipboard(
    TkWindow *winPtr,			/* Window associated with clipboard. */
    TkClipboardTarget *targetPtr)	/* Info about the content. */
{
}

/*
 *--------------------------------------------------------------
 *
 * TkSelEventProc --
 *
 *	This procedure is invoked whenever a selection-related
 *	event occurs. 
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Lots:  depends on the type of event.
 *
 *--------------------------------------------------------------
 */

void
TkSelEventProc(
    Tk_Window tkwin,		/* Window for which event was
				 * targeted. */
    register XEvent *eventPtr)	/* X event:  either SelectionClear,
				 * SelectionRequest, or
				 * SelectionNotify. */
{
    if (eventPtr->type == SelectionClear) {
	TkSelClearSelection(tkwin, eventPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkSelPropProc --
 *
 *	This procedure is invoked when property-change events
 *	occur on windows not known to the toolkit.  This is a stub
 *	function under Windows.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkSelPropProc(
    register XEvent *eventPtr)		/* X PropertyChange event. */
{
}

/*
 *----------------------------------------------------------------------
 *
 * TkSuspendClipboard --
 *
 *	Handle clipboard conversion as required by the suppend event.
 *	This function is also called on exit.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The local scrap is moved to the global scrap.
 *
 *----------------------------------------------------------------------
 */

void
TkSuspendClipboard()
{
    TkClipboardTarget *targetPtr;
    TkClipboardBuffer *cbPtr;
    TkDisplay *dispPtr;
    char *buffer, *p, *endPtr, *buffPtr;
    long length;

    dispPtr = TkGetDisplayList();
    if ((dispPtr == NULL) || !dispPtr->clipboardActive) {
	return;
    }

    for (targetPtr = dispPtr->clipTargetPtr; targetPtr != NULL;
	    targetPtr = targetPtr->nextPtr) {
	if (targetPtr->type == XA_STRING)
	    break;
    }
    if (targetPtr != NULL) {
	Tcl_DString encodedText;

	length = 0;
	for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
		cbPtr = cbPtr->nextPtr) {
	    length += cbPtr->length;
	}

	buffer = ckalloc(length);
	buffPtr = buffer;
	for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
		cbPtr = cbPtr->nextPtr) {
	    for (p = cbPtr->buffer, endPtr = p + cbPtr->length;
		    p < endPtr; p++) {
		if (*p == '\n') {
		    *buffPtr++ = '\r';
		} else {
		    *buffPtr++ = *p;
		}
	    }
	}

	ZeroScrap();
	Tcl_UtfToExternalDString(NULL, buffer, length, &encodedText);
	PutScrap(Tcl_DStringLength(&encodedText), 'TEXT',
		Tcl_DStringValue(&encodedText));
	Tcl_DStringFree(&encodedText);
	ckfree(buffer);
    }

    /*
     * The system now owns the scrap.  We tell Tk that it has
     * lost the selection so that it will look for it the next time
     * it needs it.  (Window list NULL if quiting.)
     */

    if (TkGetMainInfoList() != NULL) {
	Tk_ClearSelection((Tk_Window) TkGetMainInfoList()->winPtr, 
		Tk_InternAtom((Tk_Window) TkGetMainInfoList()->winPtr,
			"CLIPBOARD"));
    }

    return;
}
@


1.6
log
@Add support for Appearance Manager 1.2 Floating windows, and the new window classes in unsupported1
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id: tkMacClipboard.c,v 1.5 2000/01/06 02:22:36 hobbs Exp $
@


1.5
log
@	* mac/tkMacClipboard.c: fixed i18n problems with clipboard [Bug: 3544]
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id: tkMacClipboard.c,v 1.4 1999/05/22 06:32:32 jingham Exp $
d77 1
a77 1
		    Tcl_DStringValue(encodedText));
@


1.4
log
@Changes needed to get Tk8.1 to compile with stubs on the Mac
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id: tkMacClipboard.c,v 1.3 1999/04/16 01:51:30 stanton Exp $
d69 2
d74 6
a79 3
	    
	    result = (*proc)(clientData, interp, *handle);
	    
d260 2
d283 4
a286 1
	PutScrap(length, 'TEXT', buffer);
@


1.3
log
@* Merged 8.1 branch into the main trunk
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id$
d122 1
a122 1
    tkwin = (Tk_Window)tkMainWindowList->winPtr;
d131 1
a131 1
	dispPtr = tkMainWindowList->winPtr->dispPtr;
d286 3
a288 3
    if (tkMainWindowList != NULL) {
	Tk_ClearSelection((Tk_Window) tkMainWindowList->winPtr, 
		Tk_InternAtom((Tk_Window) tkMainWindowList->winPtr,
@


1.2
log
@Replaced SCCS strings, fixed binary files
@
text
@d35 1
a35 1
 *	then an error message is left in interp->result.
d244 1
a244 1
    dispPtr = tkDisplayList;
@


1.1
log
@Initial revision
@
text
@d11 1
a11 1
 * SCCS: @@(#) tkMacClipboard.c 1.18 97/05/01 15:41:17
@


1.1.4.1
log
@initial tk8.1a2 version
@
text
@d11 1
a11 1
 * SCCS: @@(#) tkMacClipboard.c 1.19 97/11/07 21:21:42
d35 1
a35 1
 *	then an error message is left in the interp's result.
@


1.1.4.2
log
@Merged 8.0.3 changes into 8.1
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id: tkMacClipboard.c,v 1.2 1998/09/14 18:23:34 stanton Exp $
@


1.1.4.3
log
@
Tk 8.1 Muti-threading changes.

Moved static and global data elements into thread-local storage,
or introduced locks where not possible, as first stage of adding
thread safety to Tk.
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id: tkMacClipboard.c,v 1.1.4.2 1998/09/30 02:18:03 stanton Exp $
d244 1
a244 1
    dispPtr = TkGetDisplayList();
@


