Tk
view release on metacpan or search on metacpan
pTk/mTk/generic/tkSelect.c view on Meta::CPAN
};
enum ownOptions { OWN_COMMAND, OWN_DISPLAYOF, OWN_SELECTION };
int ownIndex;
for (count = objc-2, objs = ((Tcl_Obj **)objv)+2; count > 0;
count-=2, objs+=2) {
string = Tcl_GetString(objs[0]);
if (string[0] != '-') {
break;
}
if (count < 2) {
Tcl_AppendResult(interp, "value for \"", string,
"\" missing", (char *) NULL);
return TCL_ERROR;
}
if (Tcl_GetIndexFromObj(interp, objs[0], ownOptionStrings,
"option", 0, &ownIndex) != TCL_OK) {
return TCL_ERROR;
}
switch ((enum ownOptions) ownIndex) {
case OWN_COMMAND:
script = objs[1];
break;
case OWN_DISPLAYOF:
path = Tcl_GetString(objs[1]);
break;
case OWN_SELECTION:
selName = Tcl_GetString(objs[1]);
break;
}
}
if (count > 2) {
Tcl_WrongNumArgs(interp, 2, objv, "?options? ?window?");
return TCL_ERROR;
}
if (selName != NULL) {
selection = Tk_InternAtom(tkwin, selName);
} else {
selection = XA_PRIMARY;
}
if (count == 0) {
TkSelectionInfo *infoPtr;
TkWindow *winPtr;
if (path != NULL) {
tkwin = Tk_NameToWindow(interp, path, tkwin);
}
if (tkwin == NULL) {
return TCL_ERROR;
}
winPtr = (TkWindow *)tkwin;
for (infoPtr = winPtr->dispPtr->selectionInfoPtr;
infoPtr != NULL; infoPtr = infoPtr->nextPtr) {
if (infoPtr->selection == selection)
break;
}
/*
* Ignore the internal clipboard window.
*/
if ((infoPtr != NULL)
&& (infoPtr->owner != winPtr->dispPtr->clipWindow)) {
Tcl_SetResult(interp, Tk_PathName(infoPtr->owner),
TCL_STATIC);
}
return TCL_OK;
}
tkwin = Tk_NameToWindow(interp, Tcl_GetString(objs[0]), tkwin);
if (tkwin == NULL) {
return TCL_ERROR;
}
if (count == 2) {
if (!LangNull(objs[1])) {
script = objs[1];
}
}
if (script == NULL) {
Tk_OwnSelection(tkwin, selection, (Tk_LostSelProc *) NULL,
(ClientData) NULL);
return TCL_OK;
}
#ifndef _LANG
cmdLength = strlen(Tcl_GetString(script));
lostPtr = (LostCommand *) ckalloc((unsigned) (sizeof(LostCommand)
-3 + cmdLength));
strcpy(lostPtr->command, Tcl_GetString(script));
#else
lostPtr = (LostCommand *) ckalloc((unsigned) (sizeof(LostCommand)));
lostPtr->command = LangMakeCallback(script);
#endif
lostPtr->interp = interp;
Tk_OwnSelection(tkwin, selection, LostSelection,
(ClientData) lostPtr);
return TCL_OK;
}
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* TkSelGetInProgress --
*
* This procedure returns a pointer to the thread-local
* list of pending searches.
*
* Results:
* The return value is a pointer to the first search in progress,
* or NULL if there are none.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
TkSelInProgress *
pTk/mTk/generic/tkSelect.c view on Meta::CPAN
}
/*
* Remove selections owned by window being deleted.
*/
for (infoPtr = winPtr->dispPtr->selectionInfoPtr, prevPtr = NULL;
infoPtr != NULL; infoPtr = nextPtr) {
nextPtr = infoPtr->nextPtr;
if (infoPtr->owner == (Tk_Window) winPtr) {
if (infoPtr->clearProc == LostSelection) {
FreeLost(infoPtr->clearData);
}
ckfree((char *) infoPtr);
infoPtr = prevPtr;
if (prevPtr == NULL) {
winPtr->dispPtr->selectionInfoPtr = nextPtr;
} else {
prevPtr->nextPtr = nextPtr;
}
}
prevPtr = infoPtr;
}
}
/*
*----------------------------------------------------------------------
*
* TkSelInit --
*
* Initialize selection-related information for a display.
*
* Results:
* None.
*
* Side effects:
* Selection-related information is initialized.
*
*----------------------------------------------------------------------
*/
void
TkSelInit(tkwin)
Tk_Window tkwin; /* Window token (used to find
* display to initialize). */
{
register TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr;
/*
* Fetch commonly-used atoms.
*/
dispPtr->multipleAtom = Tk_InternAtom(tkwin, "MULTIPLE");
dispPtr->incrAtom = Tk_InternAtom(tkwin, "INCR");
dispPtr->targetsAtom = Tk_InternAtom(tkwin, "TARGETS");
dispPtr->timestampAtom = Tk_InternAtom(tkwin, "TIMESTAMP");
dispPtr->textAtom = Tk_InternAtom(tkwin, "TEXT");
dispPtr->compoundTextAtom = Tk_InternAtom(tkwin, "COMPOUND_TEXT");
dispPtr->applicationAtom = Tk_InternAtom(tkwin, "TK_APPLICATION");
dispPtr->windowAtom = Tk_InternAtom(tkwin, "TK_WINDOW");
dispPtr->clipboardAtom = Tk_InternAtom(tkwin, "CLIPBOARD");
/*
* Using UTF8_STRING instead of the XA_UTF8_STRING macro allows us
* to support older X servers that didn't have UTF8_STRING yet.
* This is necessary on Unix systems.
* For more information, see:
* http://www.cl.cam.ac.uk/~mgk25/unicode.html#x11
*/
#if !(defined(__WIN32__) || defined(MAC_TCL) || defined(MAC_OSX_TK))
dispPtr->utf8Atom = Tk_InternAtom(tkwin, "UTF8_STRING");
#else
dispPtr->utf8Atom = (Atom) NULL;
#endif
}
/*
*----------------------------------------------------------------------
*
* TkSelClearSelection --
*
* This procedure is invoked to process a SelectionClear event.
*
* Results:
* None.
*
* Side effects:
* Invokes the clear procedure for the window which lost the
* selection.
*
*----------------------------------------------------------------------
*/
void
TkSelClearSelection(tkwin, eventPtr)
Tk_Window tkwin; /* Window for which event was targeted. */
register XEvent *eventPtr; /* X SelectionClear event. */
{
register TkWindow *winPtr = (TkWindow *) tkwin;
TkDisplay *dispPtr = winPtr->dispPtr;
TkSelectionInfo *infoPtr;
TkSelectionInfo *prevPtr;
/*
* Invoke clear procedure for window that just lost the selection. This
* code is a bit tricky, because any callbacks due to selection changes
* between windows managed by the process have already been made. Thus,
* ignore the event unless it refers to the window that's currently the
* selection owner and the event was generated after the server saw the
* SetSelectionOwner request.
*/
for (infoPtr = dispPtr->selectionInfoPtr, prevPtr = NULL;
infoPtr != NULL; infoPtr = infoPtr->nextPtr) {
if (infoPtr->selection == eventPtr->xselectionclear.selection) {
break;
}
prevPtr = infoPtr;
}
( run in 0.531 second using v1.01-cache-2.11-cpan-84e82930d8c )