TIP:		264
Title:		Add Function to Retrieve the Interpreter of a Window
State:		Final
Type:		Project
Tcl-Version:	8.5
Vote:		Done
Post-History:	
Version:	$Revision: 1.8 $
Author:		George Petasis <petasis@iit.demokritos.gr>
Created:	01-Apr-2006
Keywords:	Tk, C API

~ Abstract

This TIP proposes the addition of a new function in the Tk public API, for
retrieving a pointer to the Tcl interpreter that was used for creating a
window.

~ Rationale

During the development of a Tk extension that adds a ClientMessage handler
under unix (tkdnd), I needed to get the pointer of the Tcl interpreter that is
associated with a window. When the ClientMessage handler is called, only a
Tk_Window pointer is passed, for the window the ClientMessage is for. But if
you want to execute Tcl code, you don't have a Tcl interpreter...

Of course, you can try use any (cached) interpreter, but this can lead to
various problems, if it is not the interpreter that was used for creating the
window. Since Tk already has this information, adding a function to return the
associated interpreter for a Tk_Window pointer will be relatively easy.

~ Proposed Change

A new public function (with signature ''Tcl_Interp *''
'''Tk_Interp'''''(Tk_Window tkwin)'') is proposed to be added to the public C
API of Tk. This function can be implemented as follows:

| Tcl_Interp *
| Tk_Interp(Tk_Window tkwin) {
|     if (tkwin != NULL && ((TkWindow *) tkwin)->mainPtr != NULL) {
|         return ((TkWindow *) tkwin)->mainPtr->interp;
|     }
|     return NULL;
| }

~ Copyright

This document has been placed in the public domain.
