summaryrefslogtreecommitdiffstats
path: root/generic/ttk/ttkPanedwindow.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/ttk/ttkPanedwindow.c')
-rw-r--r--generic/ttk/ttkPanedwindow.c148
1 files changed, 85 insertions, 63 deletions
diff --git a/generic/ttk/ttkPanedwindow.c b/generic/ttk/ttkPanedwindow.c
index cac3d20..d0e5f89 100644
--- a/generic/ttk/ttkPanedwindow.c
+++ b/generic/ttk/ttkPanedwindow.c
@@ -1,4 +1,4 @@
-/* $Id: ttkPanedwindow.c,v 1.14 2008/02/23 17:35:28 jenglish Exp $
+/* $Id: ttkPanedwindow.c,v 1.14.2.1 2010/08/26 02:06:09 hobbs Exp $
*
* Copyright (c) 2005, Joe English. Freely redistributable.
*
@@ -142,7 +142,7 @@ static void DestroyPane(Paned *pw, Pane *pane)
*/
static int ConfigurePane(
Tcl_Interp *interp, Paned *pw, Pane *pane, Tk_Window slaveWindow,
- int objc, Tcl_Obj *CONST objv[])
+ int objc, Tcl_Obj *const objv[])
{
Ttk_Manager *mgr = pw->paned.mgr;
Tk_SavedOptions savedOptions;
@@ -493,7 +493,7 @@ static void PanedEventProc(ClientData clientData, XEvent *eventPtr)
* +++ Initialization and cleanup hooks.
*/
-static int PanedInitialize(Tcl_Interp *interp, void *recordPtr)
+static void PanedInitialize(Tcl_Interp *interp, void *recordPtr)
{
Paned *pw = recordPtr;
@@ -503,8 +503,6 @@ static int PanedInitialize(Tcl_Interp *interp, void *recordPtr)
pw->paned.paneOptionTable = Tk_CreateOptionTable(interp,PaneOptionSpecs);
pw->paned.sashLayout = 0;
pw->paned.sashThickness = 1;
-
- return TCL_OK;
}
static void PanedCleanup(void *recordPtr)
@@ -529,7 +527,7 @@ static int PanedPostConfigure(Tcl_Interp *interp, void *clientData, int mask)
* Recalculate sash positions based on requested size.
*/
Tk_Window tkwin = pw->core.tkwin;
- PlaceSashes(pw,
+ PlaceSashes(pw,
pw->paned.width > 0 ? pw->paned.width : Tk_Width(tkwin),
pw->paned.height > 0 ? pw->paned.height : Tk_Height(tkwin));
}
@@ -575,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);
}
}
@@ -615,7 +617,7 @@ static void PanedDisplay(void *recordPtr, Drawable d)
/* $pw add window [ options ... ]
*/
static int PanedAddCommand(
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], void *recordPtr)
+ void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
Paned *pw = recordPtr;
Tk_Window slaveWindow;
@@ -636,11 +638,11 @@ static int PanedAddCommand(
objc - 3, objv + 3);
}
-/* $pw insert $index $slave ?options...?
+/* $pw insert $index $slave ?-option value ...?
* Insert new slave, or move existing one.
*/
static int PanedInsertCommand(
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], void *recordPtr)
+ void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
Paned *pw = recordPtr;
int nSlaves = Ttk_NumberSlaves(pw->paned.mgr);
@@ -648,7 +650,7 @@ static int PanedInsertCommand(
Tk_Window slaveWindow;
if (objc < 4) {
- Tcl_WrongNumArgs(interp, 2,objv, "index slave ?options...?");
+ Tcl_WrongNumArgs(interp, 2,objv, "index slave ?-option value ...?");
return TCL_ERROR;
}
@@ -661,7 +663,7 @@ static int PanedInsertCommand(
if (!strcmp(Tcl_GetString(objv[2]), "end")) {
destIndex = Ttk_NumberSlaves(pw->paned.mgr);
} else if (TCL_OK != Ttk_GetSlaveIndexFromObj(
- interp,pw->paned.mgr,objv[2],&destIndex))
+ interp,pw->paned.mgr,objv[2],&destIndex))
{
return TCL_ERROR;
}
@@ -685,7 +687,7 @@ static int PanedInsertCommand(
/* $pw forget $pane
*/
static int PanedForgetCommand(
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], void *recordPtr)
+ void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
Paned *pw = recordPtr;
int paneIndex;
@@ -696,7 +698,7 @@ static int PanedForgetCommand(
}
if (TCL_OK != Ttk_GetSlaveIndexFromObj(
- interp, pw->paned.mgr, objv[2], &paneIndex))
+ interp, pw->paned.mgr, objv[2], &paneIndex))
{
return TCL_ERROR;
}
@@ -705,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)
+ void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
+ 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;
}
@@ -731,19 +740,33 @@ 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 ...??
* Query/modify pane options.
*/
static int PanedPaneCommand(
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], void *recordPtr)
+ void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
Paned *pw = recordPtr;
int paneIndex;
@@ -751,7 +774,7 @@ static int PanedPaneCommand(
Pane *pane;
if (objc < 3) {
- Tcl_WrongNumArgs(interp, 2,objv, "pane ?-option value...?");
+ Tcl_WrongNumArgs(interp, 2,objv, "pane ?-option value ...?");
return TCL_ERROR;
}
@@ -780,7 +803,7 @@ static int PanedPaneCommand(
* Return list of managed panes.
*/
static int PanedPanesCommand(
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], void *recordPtr)
+ void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
Paned *pw = recordPtr;
Ttk_Manager *mgr = pw->paned.mgr;
@@ -807,7 +830,7 @@ static int PanedPanesCommand(
* Query or modify sash position.
*/
static int PanedSashposCommand(
- Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], void *recordPtr)
+ void *recordPtr, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
Paned *pw = recordPtr;
int sashIndex, position = -1;
@@ -852,20 +875,19 @@ static int PanedSashposCommand(
return TCL_OK;
}
-static WidgetCommandSpec PanedCommands[] =
-{
- { "add", PanedAddCommand },
- { "configure", TtkWidgetConfigureCommand },
- { "cget", TtkWidgetCgetCommand },
- { "forget", PanedForgetCommand },
- { "identify", PanedIdentifyCommand },
- { "insert", PanedInsertCommand },
- { "instate", TtkWidgetInstateCommand },
- { "pane", PanedPaneCommand },
- { "panes", PanedPanesCommand },
- { "sashpos", PanedSashposCommand },
- { "state", TtkWidgetStateCommand },
- { 0,0 }
+static const Ttk_Ensemble PanedCommands[] = {
+ { "add", PanedAddCommand,0 },
+ { "configure", TtkWidgetConfigureCommand,0 },
+ { "cget", TtkWidgetCgetCommand,0 },
+ { "forget", PanedForgetCommand,0 },
+ { "identify", PanedIdentifyCommand,0 },
+ { "insert", PanedInsertCommand,0 },
+ { "instate", TtkWidgetInstateCommand,0 },
+ { "pane", PanedPaneCommand,0 },
+ { "panes", PanedPanesCommand,0 },
+ { "sashpos", PanedSashposCommand,0 },
+ { "state", TtkWidgetStateCommand,0 },
+ { 0,0,0 }
};
/*------------------------------------------------------------------------
@@ -901,7 +923,7 @@ typedef struct {
static Ttk_ElementOptionSpec SashElementOptions[] = {
{ "-sashthickness", TK_OPTION_INT,
Tk_Offset(SashElement,thicknessObj), "5" },
- {NULL}
+ { NULL, 0, 0, NULL }
};
static void SashElementSize(
@@ -937,7 +959,7 @@ TTK_END_LAYOUT
/*------------------------------------------------------------------------
* +++ Registration routine.
*/
-MODULE_SCOPE
+MODULE_SCOPE
void TtkPanedwindow_Init(Tcl_Interp *interp)
{
Ttk_Theme themePtr = Ttk_GetDefaultTheme(interp);