summaryrefslogtreecommitdiffstats
path: root/generic/tkTreeUtils.c
diff options
context:
space:
mode:
authortreectrl <treectrl>2006-11-30 03:29:44 (GMT)
committertreectrl <treectrl>2006-11-30 03:29:44 (GMT)
commitd06d46b9d793a14d301e135e6fd76a0c77bbb7b5 (patch)
tree4541a1618e4849901c37e986a011d8301e69c2f2 /generic/tkTreeUtils.c
parent6137f8797b9b058e0cf9b93cf6b8708e42aeacde (diff)
downloadtktreectrl-d06d46b9d793a14d301e135e6fd76a0c77bbb7b5.zip
tktreectrl-d06d46b9d793a14d301e135e6fd76a0c77bbb7b5.tar.gz
tktreectrl-d06d46b9d793a14d301e135e6fd76a0c77bbb7b5.tar.bz2
The item option -button may now be "auto" in which case a button is drawn only when the item has a child whose -visible option is true.
Diffstat (limited to 'generic/tkTreeUtils.c')
-rw-r--r--generic/tkTreeUtils.c146
1 files changed, 145 insertions, 1 deletions
diff --git a/generic/tkTreeUtils.c b/generic/tkTreeUtils.c
index 5df3261..4217ed7 100644
--- a/generic/tkTreeUtils.c
+++ b/generic/tkTreeUtils.c
@@ -5,7 +5,7 @@
*
* Copyright (c) 2002-2006 Tim Baker
*
- * RCS: @(#) $Id: tkTreeUtils.c,v 1.54 2006/11/22 03:34:05 treectrl Exp $
+ * RCS: @(#) $Id: tkTreeUtils.c,v 1.55 2006/11/30 03:29:44 treectrl Exp $
*/
#include "tkTreeCtrl.h"
@@ -5966,3 +5966,147 @@ BooleanFlagCO_Init(
return TCL_OK;
}
+/*
+ *----------------------------------------------------------------------
+ *
+ * ItemButtonCO_Set --
+ * ItemButtonCO_Get --
+ * ItemButtonCO_Restore --
+ *
+ * These procedures implement a TK_OPTION_CUSTOM where the custom
+ * option is a boolean value or "auto"; the internal rep is two
+ * bits of an int: one bit for the boolean, and one for "auto".
+ * This is used for the item option -button.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+struct ItemButtonCOClientData {
+ int flag1; /* Bit to set when object is "true". */
+ int flag2; /* Bit to set when object is "auto". */
+};
+
+static int
+ItemButtonCO_Set(
+ ClientData clientData,
+ Tcl_Interp *interp,
+ Tk_Window tkwin,
+ Tcl_Obj **value,
+ char *recordPtr,
+ int internalOffset,
+ char *saveInternalPtr,
+ int flags
+ )
+{
+ struct ItemButtonCOClientData *cd = clientData;
+ int new, *internalPtr, on, off;
+ char *s;
+ int length;
+
+ if (internalOffset >= 0)
+ internalPtr = (int *) (recordPtr + internalOffset);
+ else
+ internalPtr = NULL;
+
+ s = Tcl_GetStringFromObj((*value), &length);
+ if (s[0] == 'a' && strncmp(s, "auto", length) == 0) {
+ on = cd->flag2;
+ off = cd->flag1;
+ } else {
+ if (Tcl_GetBooleanFromObj(interp, (*value), &new) != TCL_OK) {
+ FormatResult(interp, "expected boolean or auto but got \"%s\"", s);
+ return TCL_ERROR;
+ }
+ if (new) {
+ on = cd->flag1;
+ off = cd->flag2;
+ } else {
+ on = 0;
+ off = cd->flag1 | cd->flag2;
+ }
+ }
+
+ if (internalPtr != NULL) {
+ *((int *) saveInternalPtr) = *internalPtr;
+ *internalPtr |= on;
+ *internalPtr &= ~off;
+ }
+
+ return TCL_OK;
+}
+
+static Tcl_Obj *
+ItemButtonCO_Get(
+ ClientData clientData,
+ Tk_Window tkwin,
+ char *recordPtr,
+ int internalOffset
+ )
+{
+ struct ItemButtonCOClientData *cd = clientData;
+ int value = *(int *) (recordPtr + internalOffset);
+
+ if (value & cd->flag2)
+ return Tcl_NewStringObj("auto", -1);
+ return Tcl_NewBooleanObj((value & cd->flag2) != 0);
+}
+
+static void
+ItemButtonCO_Restore(
+ ClientData clientData,
+ Tk_Window tkwin,
+ char *internalPtr,
+ char *saveInternalPtr
+ )
+{
+ struct ItemButtonCOClientData *cd = clientData;
+ int value = *(int *) saveInternalPtr;
+
+ *((int *) internalPtr) &= ~(cd->flag1 | cd->flag2);
+ *((int *) internalPtr) |= value & (cd->flag1 | cd->flag2);
+}
+
+int
+ItemButtonCO_Init(
+ Tk_OptionSpec *optionTable,
+ CONST char *optionName,
+ int flag1,
+ int flag2
+ )
+{
+ Tk_OptionSpec *specPtr;
+ Tk_ObjCustomOption *co;
+ struct ItemButtonCOClientData *cd;
+
+ specPtr = OptionSpec_Find(optionTable, optionName);
+ if (specPtr->type != TK_OPTION_CUSTOM)
+ panic("IntegerCO_Init: %s is not TK_OPTION_CUSTOM", optionName);
+ if (specPtr->clientData != NULL)
+ return TCL_OK;
+
+ /* ClientData for the Tk custom option record */
+ cd = (struct ItemButtonCOClientData *)ckalloc(
+ sizeof(struct ItemButtonCOClientData));
+ cd->flag1 = flag1;
+ cd->flag2 = flag2;
+
+ /* The Tk custom option record */
+ co = (Tk_ObjCustomOption *) ckalloc(sizeof(Tk_ObjCustomOption));
+ co->name = "button option";
+ co->setProc = ItemButtonCO_Set;
+ co->getProc = ItemButtonCO_Get;
+ co->restoreProc = ItemButtonCO_Restore;
+ co->freeProc = NULL;
+ co->clientData = cd;
+
+ specPtr->clientData = co;
+
+ return TCL_OK;
+}
+