diff options
Diffstat (limited to 'win/tkWinClipboard.c')
-rw-r--r-- | win/tkWinClipboard.c | 183 |
1 files changed, 91 insertions, 92 deletions
diff --git a/win/tkWinClipboard.c b/win/tkWinClipboard.c index b08147a..093280c 100644 --- a/win/tkWinClipboard.c +++ b/win/tkWinClipboard.c @@ -1,4 +1,4 @@ -/* +/* * tkWinClipboard.c -- * * This file contains functions for managing the clipboard. @@ -6,30 +6,30 @@ * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright (c) 1998-2000 by Scriptics Corporation. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkWinClipboard.c,v 1.7 2000/04/12 18:51:11 hobbs Exp $ + * RCS: @(#) $Id: tkWinClipboard.c,v 1.9 2007/01/11 15:35:40 dkf Exp $ */ #include "tkWinInt.h" #include "tkSelect.h" -static void UpdateClipboard _ANSI_ARGS_((HWND hwnd)); +static void UpdateClipboard(HWND hwnd); /* *---------------------------------------------------------------------- * * TkSelGetSelection -- * - * Retrieve the specified selection from another process. For - * now, only fetching XA_STRING from CLIPBOARD is supported. - * Eventually other types should be allowed. - * + * 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. + * 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. @@ -38,18 +38,17 @@ static void UpdateClipboard _ANSI_ARGS_((HWND hwnd)); */ int -TkSelGetSelection(interp, tkwin, selection, target, proc, clientData) - 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. */ +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. */ { char *data, *destPtr; Tcl_DString ds; @@ -64,8 +63,8 @@ TkSelGetSelection(interp, tkwin, selection, target, proc, clientData) } /* - * Attempt to get the data in Unicode form if available as this is - * less work that CF_TEXT. + * Attempt to get the data in Unicode form if available as this is less + * work that CF_TEXT. */ result = TCL_ERROR; @@ -93,19 +92,17 @@ TkSelGetSelection(interp, tkwin, selection, target, proc, clientData) } /* - * Get the locale identifier, determine the proper code page - * to use, and find the corresponding encoding. + * Get the locale identifier, determine the proper code page to + * use, and find the corresponding encoding. */ Tcl_DStringInit(&ds); Tcl_DStringAppend(&ds, "cp######", -1); data = GlobalLock(handle); - /* - * Even though the documentation claims that GetLocaleInfo - * expects an LCID, on Windows 9x it really seems to expect - * a LanguageID. + * Even though the documentation claims that GetLocaleInfo expects + * an LCID, on Windows 9x it really seems to expect a LanguageID. */ locale = LANGIDFROMLCID(*((int*)data)); @@ -146,7 +143,7 @@ TkSelGetSelection(interp, tkwin, selection, target, proc, clientData) /* * Translate CR/LF to LF. */ - + data = destPtr = Tcl_DStringValue(&ds); while (*data) { if (data[0] == '\r' && data[1] == '\n') { @@ -165,12 +162,11 @@ TkSelGetSelection(interp, tkwin, selection, target, proc, clientData) Tcl_DStringFree(&ds); CloseClipboard(); return result; - -error: + + error: Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection), " selection doesn't exist or form \"", - Tk_GetAtomName(tkwin, target), - "\" not defined", (char *) NULL); + Tk_GetAtomName(tkwin, target), "\" not defined", NULL); return TCL_ERROR; } @@ -179,9 +175,8 @@ error: * * TkSetSelectionOwner -- * - * This function claims ownership of the specified selection. - * If the selection is CLIPBOARD, then we empty the system - * clipboard. + * This function claims ownership of the specified selection. If the + * selection is CLIPBOARD, then we empty the system clipboard. * * Results: * None. @@ -193,27 +188,26 @@ error: */ void -XSetSelectionOwner(display, selection, owner, time) - Display* display; - Atom selection; - Window owner; - Time time; +XSetSelectionOwner( + Display *display, + Atom selection, + Window owner, + Time time) { HWND hwnd = owner ? TkWinGetHWND(owner) : NULL; Tk_Window tkwin; /* - * 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. + * 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. + * Only claim and empty the clipboard if we aren't already the owner + * of the clipboard. */ if (GetClipboardOwner() != hwnd) { @@ -227,8 +221,8 @@ XSetSelectionOwner(display, selection, owner, time) * * TkWinClipboardRender -- * - * This function supplies the contents of the clipboard in - * response to a WM_RENDERFORMAT message. + * This function supplies the contents of the clipboard in response to a + * WM_RENDERFORMAT message. * * Results: * None. @@ -240,9 +234,9 @@ XSetSelectionOwner(display, selection, owner, time) */ void -TkWinClipboardRender(dispPtr, format) - TkDisplay *dispPtr; - UINT format; +TkWinClipboardRender( + TkDisplay *dispPtr, + UINT format) { TkClipboardTarget *targetPtr; TkClipboardBuffer *cbPtr; @@ -253,13 +247,14 @@ TkWinClipboardRender(dispPtr, format) for (targetPtr = dispPtr->clipTargetPtr; targetPtr != NULL; targetPtr = targetPtr->nextPtr) { - if (targetPtr->type == XA_STRING) + if (targetPtr->type == XA_STRING) { break; + } } /* - * Count the number of newlines so we can add space for them in - * the resulting string. + * Count the number of newlines so we can add space for them in the + * resulting string. */ length = 0; @@ -280,7 +275,7 @@ TkWinClipboardRender(dispPtr, format) * Copy the data and change EOL characters. */ - buffer = rawText = ckalloc(length + 1); + buffer = rawText = ckalloc((unsigned)length + 1); if (targetPtr != NULL) { for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL; cbPtr = cbPtr->nextPtr) { @@ -296,8 +291,8 @@ TkWinClipboardRender(dispPtr, format) *buffer = '\0'; /* - * Depending on the platform, turn the data into Unicode or the - * system encoding before placing it on the clipboard. + * Depending on the platform, turn the data into Unicode or the system + * encoding before placing it on the clipboard. */ if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) { @@ -305,13 +300,14 @@ TkWinClipboardRender(dispPtr, format) Tcl_UtfToUniCharDString(rawText, -1, &ds); ckfree(rawText); handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, - Tcl_DStringLength(&ds)+2); + (unsigned) Tcl_DStringLength(&ds) + 2); if (!handle) { Tcl_DStringFree(&ds); return; } buffer = GlobalLock(handle); - memcpy(buffer, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds) + 2); + memcpy(buffer, Tcl_DStringValue(&ds), + (unsigned) Tcl_DStringLength(&ds) + 2); GlobalUnlock(handle); Tcl_DStringFree(&ds); SetClipboardData(CF_UNICODETEXT, handle); @@ -319,19 +315,18 @@ TkWinClipboardRender(dispPtr, format) Tcl_UtfToExternalDString(NULL, rawText, -1, &ds); ckfree(rawText); handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, - Tcl_DStringLength(&ds)+1); + (unsigned) Tcl_DStringLength(&ds) + 1); if (!handle) { Tcl_DStringFree(&ds); return; } buffer = GlobalLock(handle); - memcpy(buffer, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds) + 1); + memcpy(buffer, Tcl_DStringValue(&ds), + (unsigned) Tcl_DStringLength(&ds) + 1); GlobalUnlock(handle); Tcl_DStringFree(&ds); SetClipboardData(CF_TEXT, handle); } - - return; } /* @@ -339,8 +334,8 @@ TkWinClipboardRender(dispPtr, format) * * TkSelUpdateClipboard -- * - * This function is called to force the clipboard to be updated - * after new data is added. + * This function is called to force the clipboard to be updated after new + * data is added. * * Results: * None. @@ -352,9 +347,9 @@ TkWinClipboardRender(dispPtr, format) */ void -TkSelUpdateClipboard(winPtr, targetPtr) - TkWindow *winPtr; - TkClipboardTarget *targetPtr; +TkSelUpdateClipboard( + TkWindow *winPtr, + TkClipboardTarget *targetPtr) { HWND hwnd = TkWinGetHWND(winPtr->window); UpdateClipboard(hwnd); @@ -365,8 +360,8 @@ TkSelUpdateClipboard(winPtr, targetPtr) * * UpdateClipboard -- * - * Take ownership of the clipboard, clear it, and indicate to the - * system the supported formats. + * Take ownership of the clipboard, clear it, and indicate to the system + * the supported formats. * * Results: * None. @@ -378,16 +373,16 @@ TkSelUpdateClipboard(winPtr, targetPtr) */ static void -UpdateClipboard(hwnd) - HWND hwnd; +UpdateClipboard( + HWND hwnd) { TkWinUpdatingClipboard(TRUE); OpenClipboard(hwnd); EmptyClipboard(); /* - * CF_UNICODETEXT is only supported on NT, but it it is prefered - * when possible. + * CF_UNICODETEXT is only supported on NT, but it it is prefered when + * possible. */ if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) { @@ -404,25 +399,22 @@ UpdateClipboard(hwnd) * * TkSelEventProc -- * - * This procedure is invoked whenever a selection-related - * event occurs. + * This procedure is invoked whenever a selection-related event occurs. * * Results: * None. * * Side effects: - * Lots: depends on the type of event. + * Lots: depends on the type of event. * *-------------------------------------------------------------- */ void -TkSelEventProc(tkwin, eventPtr) - Tk_Window tkwin; /* Window for which event was - * targeted. */ - register XEvent *eventPtr; /* X event: either SelectionClear, - * SelectionRequest, or - * SelectionNotify. */ +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); @@ -434,9 +426,8 @@ TkSelEventProc(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. + * 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. @@ -448,7 +439,15 @@ TkSelEventProc(tkwin, eventPtr) */ void -TkSelPropProc(eventPtr) - register XEvent *eventPtr; /* X PropertyChange event. */ +TkSelPropProc( + register XEvent *eventPtr) /* X PropertyChange event. */ { } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ |