summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjenglish <jenglish@flightlab.com>2009-11-01 18:12:44 (GMT)
committerjenglish <jenglish@flightlab.com>2009-11-01 18:12:44 (GMT)
commit0c58d63813ddb8805d9b12b877a47e2d66027897 (patch)
tree82d1b223559ec164d9a4b29d63dac1acfbaf507e /generic
parent0f2aa87192cc95c6095ccce0e517004664c2061f (diff)
downloadtk-0c58d63813ddb8805d9b12b877a47e2d66027897.zip
tk-0c58d63813ddb8805d9b12b877a47e2d66027897.tar.gz
tk-0c58d63813ddb8805d9b12b877a47e2d66027897.tar.bz2
Uniform, extensible syntax for [$w identify] methods:
[$w identify $component $x $y]. All ttk::* widgets support [$w identify element $x $y]; widgets with other identifiable parts may have additional subcommands. Notebook widgets support [$nb identify tab], Panedwindow widgets support [$w identify sash]. Older 2-argument form [$w identify $x $y] still supported, though it does different things depending on the widget.
Diffstat (limited to 'generic')
-rw-r--r--generic/ttk/ttkNotebook.c34
-rw-r--r--generic/ttk/ttkPanedwindow.c85
-rw-r--r--generic/ttk/ttkWidget.c24
3 files changed, 97 insertions, 46 deletions
diff --git a/generic/ttk/ttkNotebook.c b/generic/ttk/ttkNotebook.c
index 34a9c0a..e59801b 100644
--- a/generic/ttk/ttkNotebook.c
+++ b/generic/ttk/ttkNotebook.c
@@ -1,4 +1,4 @@
-/* $Id: ttkNotebook.c,v 1.20 2009/05/17 17:20:49 jenglish Exp $
+/* $Id: ttkNotebook.c,v 1.21 2009/11/01 18:12:44 jenglish Exp $
* Copyright (c) 2004, Joe English
*/
@@ -1046,18 +1046,24 @@ static int NotebookHideCommand(
static int NotebookIdentifyCommand(
Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], void *recordPtr)
{
+ static const char *whatTable[] = { "element", "tab", NULL };
+ enum { IDENTIFY_ELEMENT, IDENTIFY_TAB };
+ int what = IDENTIFY_ELEMENT;
Notebook *nb = recordPtr;
Ttk_Element element = NULL;
int x, y, tabIndex;
- if (objc != 4) {
- Tcl_WrongNumArgs(interp, 2, objv, "x y");
+ if (objc < 4 || objc > 5) {
+ Tcl_WrongNumArgs(interp, 2,objv, "?what? x y");
return TCL_ERROR;
}
- if ( Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK
- || Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)
- {
+ if ( Tcl_GetIntFromObj(interp, objv[objc-2], &x) != TCL_OK
+ || Tcl_GetIntFromObj(interp, objv[objc-1], &y) != TCL_OK
+ || (objc == 5 &&
+ Tcl_GetIndexFromObj(interp, objv[2], whatTable, "option", 0, &what)
+ != TCL_OK)
+ ) {
return TCL_ERROR;
}
@@ -1073,11 +1079,19 @@ static int NotebookIdentifyCommand(
element = Ttk_IdentifyElement(tabLayout, x, y);
}
- if (element) {
- const char *elementName = Ttk_ElementName(element);
- Tcl_SetObjResult(interp,Tcl_NewStringObj(elementName,-1));
+ switch (what) {
+ case IDENTIFY_ELEMENT:
+ if (element) {
+ const char *elementName = Ttk_ElementName(element);
+ Tcl_SetObjResult(interp,Tcl_NewStringObj(elementName,-1));
+ }
+ break;
+ case IDENTIFY_TAB:
+ if (tabIndex >= 0) {
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(tabIndex));
+ }
+ break;
}
-
return TCL_OK;
}
diff --git a/generic/ttk/ttkPanedwindow.c b/generic/ttk/ttkPanedwindow.c
index 4b93e9a..bd550a5 100644
--- a/generic/ttk/ttkPanedwindow.c
+++ b/generic/ttk/ttkPanedwindow.c
@@ -1,4 +1,4 @@
-/* $Id: ttkPanedwindow.c,v 1.17 2008/11/09 23:53:09 jenglish Exp $
+/* $Id: ttkPanedwindow.c,v 1.18 2009/11/01 18:12:44 jenglish Exp $
*
* Copyright (c) 2005, Joe English. Freely redistributable.
*
@@ -573,36 +573,40 @@ static Ttk_Layout PanedGetLayout(
* +++ Drawing routines.
*/
-static void DrawSash(Paned *pw, Drawable d, Ttk_Box b)
+/* SashLayout --
+ * Place the sash sublayout after the specified pane,
+ * in preparation for drawing.
+ */
+static Ttk_Layout SashLayout(Paned *pw, int index)
{
- Ttk_Layout sashLayout = pw->paned.sashLayout;
- Ttk_State state = pw->core.state;
+ Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
+ int thickness = pw->paned.sashThickness,
+ height = Tk_Height(pw->core.tkwin),
+ width = Tk_Width(pw->core.tkwin),
+ sashPos = pane->sashPos;
+
+ Ttk_PlaceLayout(
+ pw->paned.sashLayout, pw->core.state,
+ pw->paned.orient == TTK_ORIENT_HORIZONTAL
+ ? Ttk_MakeBox(sashPos, 0, thickness, height)
+ : Ttk_MakeBox(0, sashPos, width, thickness));
- Ttk_PlaceLayout(sashLayout, state, b);
- Ttk_DrawLayout(sashLayout, state, d);
+ return pw->paned.sashLayout;
+}
+
+static void DrawSash(Paned *pw, int index, Drawable d)
+{
+ Ttk_DrawLayout(SashLayout(pw, index), pw->core.state, d);
}
static void PanedDisplay(void *recordPtr, Drawable d)
{
Paned *pw = recordPtr;
- int nPanes = Ttk_NumberSlaves(pw->paned.mgr),
- horizontal = pw->paned.orient == TTK_ORIENT_HORIZONTAL,
- thickness = pw->paned.sashThickness,
- height = Tk_Height(pw->core.tkwin),
- width = Tk_Width(pw->core.tkwin);
- int i;
+ int i, nSashes = Ttk_NumberSlaves(pw->paned.mgr) - 1;
TtkWidgetDisplay(recordPtr, d);
-
- /* Draw sashes:
- */
- for (i = 0; i < nPanes; ++i) {
- Pane *pane = Ttk_SlaveData(pw->paned.mgr, i);
- if (horizontal) {
- DrawSash(pw, d, Ttk_MakeBox(pane->sashPos, 0, thickness, height));
- } else {
- DrawSash(pw, d, Ttk_MakeBox(0, pane->sashPos, width, thickness));
- }
+ for (i = 0; i < nSashes; ++i) {
+ DrawSash(pw, i, d);
}
}
@@ -703,24 +707,31 @@ static int PanedForgetCommand(
return TCL_OK;
}
-/* $pw identify $x $y --
+/* $pw identify ?what? $x $y --
* Return index of sash at $x,$y
*/
static int PanedIdentifyCommand(
Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], void *recordPtr)
{
+ const char *whatTable[] = { "element", "sash", NULL };
+ enum { IDENTIFY_ELEMENT, IDENTIFY_SASH };
+ int what = IDENTIFY_SASH;
Paned *pw = recordPtr;
int sashThickness = pw->paned.sashThickness;
int nSashes = Ttk_NumberSlaves(pw->paned.mgr) - 1;
int x, y, pos;
int index;
- if (objc != 4) {
- Tcl_WrongNumArgs(interp, 2,objv, "x y");
+ if (objc < 4 || objc > 5) {
+ Tcl_WrongNumArgs(interp, 2,objv, "?what? x y");
return TCL_ERROR;
}
- if ( Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK
- || Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK
+
+ if ( Tcl_GetIntFromObj(interp, objv[objc-2], &x) != TCL_OK
+ || Tcl_GetIntFromObj(interp, objv[objc-1], &y) != TCL_OK
+ || (objc == 5 &&
+ Tcl_GetIndexFromObj(interp, objv[2], whatTable, "option", 0, &what)
+ != TCL_OK)
) {
return TCL_ERROR;
}
@@ -729,12 +740,26 @@ static int PanedIdentifyCommand(
for (index = 0; index < nSashes; ++index) {
Pane *pane = Ttk_SlaveData(pw->paned.mgr, index);
if (pane->sashPos <= pos && pos <= pane->sashPos + sashThickness) {
- Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
- return TCL_OK;
+ /* Found it. */
+ switch (what) {
+ case IDENTIFY_SASH:
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(index));
+ return TCL_OK;
+ case IDENTIFY_ELEMENT:
+ {
+ Ttk_Element element =
+ Ttk_IdentifyElement(SashLayout(pw, index), x, y);
+ if (element) {
+ Tcl_SetObjResult(interp,
+ Tcl_NewStringObj(Ttk_ElementName(element), -1));
+ }
+ return TCL_OK;
+ }
+ }
}
}
- return TCL_OK; /* return empty string */
+ return TCL_OK; /* nothing found - return empty string */
}
/* $pw pane $pane ?-option ?value -option value ...??
diff --git a/generic/ttk/ttkWidget.c b/generic/ttk/ttkWidget.c
index a21125f..e64f1f1 100644
--- a/generic/ttk/ttkWidget.c
+++ b/generic/ttk/ttkWidget.c
@@ -1,4 +1,4 @@
-/* $Id: ttkWidget.c,v 1.21 2009/02/08 19:35:35 jenglish Exp $
+/* $Id: ttkWidget.c,v 1.22 2009/11/01 18:12:44 jenglish Exp $
* Copyright (c) 2003, Joe English
*
* Core widget utilities.
@@ -769,6 +769,7 @@ int TtkWidgetInstateCommand(
}
/* $w identify $x $y
+ * $w identify element $x $y
* Returns: name of element at $x, $y
*/
int TtkWidgetIdentifyCommand(
@@ -776,16 +777,27 @@ int TtkWidgetIdentifyCommand(
{
WidgetCore *corePtr = recordPtr;
Ttk_Element element;
- int x, y;
+ static const char *whatTable[] = { "element", NULL };
+ int x, y, what;
- if (objc != 4) {
- Tcl_WrongNumArgs(interp, 2, objv, "x y");
+ if (objc < 4 || objc > 5) {
+ Tcl_WrongNumArgs(interp, 2, objv, "?what? x y");
return TCL_ERROR;
}
+ if (objc == 5) {
+ /* $w identify element $x $y */
+ if (Tcl_GetIndexFromObj(interp,objv[2],whatTable,"option",0,&what)
+ != TCL_OK)
+ {
+ return TCL_ERROR;
+ }
+ }
- if (Tcl_GetIntFromObj(interp, objv[2], &x) != TCL_OK
- || Tcl_GetIntFromObj(interp, objv[3], &y) != TCL_OK)
+ if ( Tcl_GetIntFromObj(interp, objv[objc-2], &x) != TCL_OK
+ || Tcl_GetIntFromObj(interp, objv[objc-1], &y) != TCL_OK
+ ) {
return TCL_ERROR;
+ }
element = Ttk_IdentifyElement(corePtr->layout, x, y);
if (element) {