summaryrefslogtreecommitdiffstats
path: root/generic/tkUtil.c
diff options
context:
space:
mode:
authordas <das>2008-12-10 00:34:51 (GMT)
committerdas <das>2008-12-10 00:34:51 (GMT)
commit14d9a1e2feaf5668b184e34e273d1f77a94f158a (patch)
treecd15d97e3ab9fcbe6b4b9228abf45bdbd3672b98 /generic/tkUtil.c
parent38e787d2a5bf25a1385bd7316b83c18523ae72b0 (diff)
downloadtk-14d9a1e2feaf5668b184e34e273d1f77a94f158a.zip
tk-14d9a1e2feaf5668b184e34e273d1f77a94f158a.tar.gz
tk-14d9a1e2feaf5668b184e34e273d1f77a94f158a.tar.bz2
* generic/tkInt.h: Turn [tk] into an ensemble (thoyts, steffen)
* generic/tkBusy.c: * generic/tkCmds.c: * generic/tkWindow.c:
Diffstat (limited to 'generic/tkUtil.c')
-rw-r--r--generic/tkUtil.c85
1 files changed, 84 insertions, 1 deletions
diff --git a/generic/tkUtil.c b/generic/tkUtil.c
index 84a448a..4007ae8 100644
--- a/generic/tkUtil.c
+++ b/generic/tkUtil.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkUtil.c,v 1.24 2008/11/08 18:44:40 dkf Exp $
+ * RCS: @(#) $Id: tkUtil.c,v 1.25 2008/12/10 00:34:51 das Exp $
*/
#include "tkInt.h"
@@ -978,6 +978,89 @@ TkFindStateNumObj(
}
/*
+ *----------------------------------------------------------------------
+ *
+ * TkMakeEnsemble --
+ *
+ * Create an ensemble from a table of implementation commands.
+ * This may be called recursively to create sub-ensembles.
+ *
+ * Results:
+ * Handle for the ensemble, or NULL if creation of it fails.
+ *
+ *----------------------------------------------------------------------
+ */
+
+Tcl_Command
+TkMakeEnsemble(
+ Tcl_Interp *interp,
+ const char *namespace,
+ const char *name,
+ ClientData clientData,
+ const TkEnsemble map[])
+{
+ Tcl_Namespace *namespacePtr = NULL;
+ Tcl_Command ensemble = NULL;
+ Tcl_Obj *dictObj = NULL;
+ Tcl_DString ds;
+ int i;
+
+ if (map == NULL) {
+ return NULL;
+ }
+
+ Tcl_DStringInit(&ds);
+
+ namespacePtr = Tcl_FindNamespace(interp, namespace, NULL, 0);
+ if (namespacePtr == NULL) {
+ namespacePtr = Tcl_CreateNamespace(interp, namespace, NULL, NULL);
+ if (namespacePtr == NULL) {
+ Tcl_Panic("failed to create namespace \"%s\"", namespace);
+ }
+ }
+
+ ensemble = Tcl_FindEnsemble(interp, Tcl_NewStringObj(name,-1), 0);
+ if (ensemble == NULL) {
+ ensemble = Tcl_CreateEnsemble(interp, name,
+ namespacePtr, TCL_ENSEMBLE_PREFIX);
+ if (ensemble == NULL) {
+ Tcl_Panic("failed to create ensemble \"%s\"", name);
+ }
+ }
+
+ Tcl_DStringSetLength(&ds, 0);
+ Tcl_DStringAppend(&ds, namespace, -1);
+ if (!(strlen(namespace) == 2 && namespace[1] == ':')) {
+ Tcl_DStringAppend(&ds, "::", -1);
+ }
+ Tcl_DStringAppend(&ds, name, -1);
+
+ dictObj = Tcl_NewObj();
+ for (i = 0; map[i].name != NULL ; ++i) {
+ Tcl_Obj *nameObj, *fqdnObj;
+
+ nameObj = Tcl_NewStringObj(map[i].name, -1);
+ fqdnObj = Tcl_NewStringObj(Tcl_DStringValue(&ds),
+ Tcl_DStringLength(&ds));
+ Tcl_AppendStringsToObj(fqdnObj, "::", map[i].name, NULL);
+ Tcl_DictObjPut(NULL, dictObj, nameObj, fqdnObj);
+ if (map[i].proc) {
+ Tcl_CreateObjCommand(interp, Tcl_GetString(fqdnObj),
+ map[i].proc, clientData, NULL);
+ } else {
+ TkMakeEnsemble(interp, Tcl_DStringValue(&ds),
+ map[i].name, clientData, map[i].subensemble);
+ }
+ }
+
+ if (ensemble) {
+ Tcl_SetEnsembleMappingDict(interp, ensemble, dictObj);
+ }
+
+ Tcl_DStringFree(&ds);
+ return ensemble;
+}
+/*
* Local Variables:
* mode: c
* c-basic-offset: 4