From 0c58d63813ddb8805d9b12b877a47e2d66027897 Mon Sep 17 00:00:00 2001 From: jenglish Date: Sun, 1 Nov 2009 18:12:44 +0000 Subject: 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. --- ChangeLog | 14 ++++++++ doc/ttk_notebook.n | 30 ++++++++-------- doc/ttk_panedwindow.n | 65 +++++++++++++++++++-------------- doc/ttk_widget.n | 77 +++++++++++++++++++-------------------- generic/ttk/ttkNotebook.c | 34 ++++++++++++------ generic/ttk/ttkPanedwindow.c | 85 ++++++++++++++++++++++++++++---------------- generic/ttk/ttkWidget.c | 24 +++++++++---- 7 files changed, 201 insertions(+), 128 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7655b57..643df5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2009-11-01 Joe English + + * generic/ttk/ttkWidget.c, doc/ttk_widget.n: + 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. + * generic/ttk/ttkNotebook.c, doc/ttk_notebook.n: + Notebook widgets support [$nb identify tab]. + * generic/ttk/ttkPanedwindow.c, doc/ttk_panedwindow.n: + 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. + 2009-10-29 Pat Thoyts * win/tkWinFont.c: [Bug 1825353]: This patch reverts a previous diff --git a/doc/ttk_notebook.n b/doc/ttk_notebook.n index 699225f..b3eda25 100644 --- a/doc/ttk_notebook.n +++ b/doc/ttk_notebook.n @@ -4,7 +4,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: ttk_notebook.n,v 1.15 2008/09/23 13:36:57 dkf Exp $ +'\" RCS: @(#) $Id: ttk_notebook.n,v 1.16 2009/11/01 18:12:44 jenglish Exp $ '\" .so man.macros .TH ttk::notebook n 8.5 Tk "Tk Themed Widget" @@ -13,14 +13,13 @@ ttk::notebook \- Multi-paned container widget .SH SYNOPSIS .nf -\fBttk::notebook\fR \fIpathName \fR?\fIoptions...\fR? +\fBttk::notebook\fR \fIpathname \fR?\fIoptions...\fR? .br -\fIpathName \fBadd\fR \fIwindow\fR ?\fIoptions...\fR? -\fIpathName \fBinsert\fR \fIindex\fR \fIwindow\fR ?\fIoptions...\fR? +\fIpathname \fBadd\fR \fIwindow\fR ?\fIoptions...\fR? +\fIpathname \fBinsert\fR \fIindex\fR \fIwindow\fR ?\fIoptions...\fR? .fi .BE .SH DESCRIPTION -.PP A \fBttk::notebook\fR widget manages a collection of windows and displays a single one at a time. Each slave window is associated with a \fItab\fR, @@ -50,7 +49,6 @@ specifies the desired width of the pane area (not including internal padding). Otherwise, the maximum width of all panes is used. .SH "TAB OPTIONS" -.PP The following options may be specified for individual notebook panes: .OP \-state state State Either \fBnormal\fR, \fBdisabled\fR or \fBhidden\fR. @@ -82,7 +80,6 @@ in the text string. The underlined character is used for mnemonic activation if \fBttk::notebook::enableTraversal\fR is called. .SH "TAB IDENTIFIERS" -.PP The \fItabid\fR argument to the following commands may take any of the following forms: .IP \(bu @@ -104,7 +101,6 @@ which returns the number of tabs (only valid for .QW "\fIpathname \fBindex\fR" ). .SH "WIDGET COMMAND" -.PP .TP \fIpathname \fBadd\fR \fIwindow\fR ?\fIoptions...\fR? Adds a new tab to the notebook. @@ -128,9 +124,18 @@ The tab will not be displayed, but the associated window remains managed by the notebook and its configuration remembered. Hidden tabs may be restored with the \fBadd\fR command. .TP -\fIpathName \fBidentify\fR \fIx y\fR -Returns the name of the element at position \fIx\fR, \fIy\fR. -See \fIttk::widget(n)\fR. +\fIpathname \fBidentify\fR \fIcomponent\fR \fIx\fR \fIy\fR +Returns the name of the element under the point given by \fIx\fR and \fIy\fR, +or the empty string if no component is present at that location. +The following subcommands are supported: +.RS +.TP +\fIpathname \fBidentify\fR \fBelement\fR \fIx\fR \fIy\fR +Returns the name of the element at the specified location. +.TP +\fIpathname \fBidentify\fR \fBtab\fR \fIx\fR \fIy\fR +Returns the index of the tab at the specified location. +.RE .TP \fIpathname \fBindex\fR \fItabid\fR Returns the numeric index of the tab specified by \fItabid\fR, @@ -170,7 +175,6 @@ See \fBTAB OPTIONS\fR for the available options. \fIpathname \fBtabs\fR Returns the list of windows managed by the notebook. .SH "KEYBOARD TRAVERSAL" -.PP To enable keyboard traversal for a toplevel window containing a notebook widget \fI$nb\fR, call: .CS @@ -192,11 +196,9 @@ including nested notebooks. However, notebook traversal only works properly if all panes are direct children of the notebook. .SH "VIRTUAL EVENTS" -.PP The notebook widget generates a \fB<>\fR virtual event after a new tab is selected. .SH "EXAMPLE" -.PP .CS pack [\fBttk::notebook\fR .nb] \.nb add [frame .nb.f1] \-text "First tab" diff --git a/doc/ttk_panedwindow.n b/doc/ttk_panedwindow.n index d6f7e47..472761e 100644 --- a/doc/ttk_panedwindow.n +++ b/doc/ttk_panedwindow.n @@ -3,9 +3,9 @@ '\" '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. -'\" -'\" RCS: @(#) $Id: ttk_panedwindow.n,v 1.19 2008/11/19 20:17:34 jenglish Exp $ -'\" +'\" +'\" RCS: @(#) $Id: ttk_panedwindow.n,v 1.20 2009/11/01 18:12:44 jenglish Exp $ +'\" .so man.macros .TH ttk::panedwindow n 8.5 Tk "Tk Themed Widget" .BS @@ -13,17 +13,17 @@ ttk::panedwindow \- Multi-pane container window .SH SYNOPSIS .nf -\fBttk::panedwindow\fR \fIpathName \fR?\fIoptions\fR? +\fBttk::panedwindow\fR \fIpathname \fR?\fIoptions\fR? .br -\fIpathName \fBadd\fR \fIwindow\fR ?\fIoptions...\fR? -\fIpathName \fBinsert\fR \fIindex\fR \fIwindow\fR ?\fIoptions...\fR? +\fIpathname \fBadd\fR \fIwindow\fR ?\fIoptions...\fR? +\fIpathname \fBinsert\fR \fIindex\fR \fIwindow\fR ?\fIoptions...\fR? .fi .BE .SH DESCRIPTION -.PP -A \fBttk::panedwindow\fR widget displays a number of subwindows, stacked -either vertically or horizontally. The user may adjust the relative sizes -of the subwindows by dragging the sash between panes. +A \fBttk::panedwindow\fR widget displays a number of subwindows, +stacked either vertically or horizontally. +The user may adjust the relative sizes of the subwindows +by dragging the sash between panes. .SO ttk_widget \-class \-cursor \-takefocus \-style @@ -34,62 +34,73 @@ Specifies the orientation of the window. If \fBvertical\fR, subpanes are stacked top-to-bottom; if \fBhorizontal\fR, subpanes are stacked left-to-right. .OP \-width width Width -If present and greater than zero, +If present and greater than zero, specifies the desired width of the widget in pixels. Otherwise, the requested width is determined by the width of the managed windows. .OP \-height height Height -If present and greater than zero, +If present and greater than zero, specifies the desired height of the widget in pixels. Otherwise, the requested height is determined by the height of the managed windows. .SH "PANE OPTIONS" -.PP The following options may be specified for each pane: .OP \-weight weight Weight An integer specifying the relative stretchability of the pane. When the paned window is resized, the extra space is added or subtracted to each pane proportionally to its \fB\-weight\fR. .SH "WIDGET COMMAND" -.PP -Supports the standard \fBconfigure\fR, \fBcget\fR, \fBstate\fR, +Supports the standard \fBconfigure\fR, \fBcget\fR, \fBstate\fR, and \fBinstate\fR commands; see \fIttk::widget(n)\fR for details. Additional commands: .TP -\fIpathname \fBadd\fR \fIsubwindow\fR \fIoptions...\fR +\fIpathname\fR \fBadd\fR \fIsubwindow\fR \fIoptions...\fR Adds a new pane to the window. See \fBPANE OPTIONS\fR for the list of available options. .TP -\fIpathname \fBforget\fR \fIpane\fR +\fIpathname\fR \fBforget\fR \fIpane\fR Removes the specified subpane from the widget. \fIpane\fR is either an integer index or the name of a managed subwindow. .TP -\fIpathname\fR \fBidentify\fR \fIx y\fR -Returns the index of the sash at point \fIx,y\fR, -or the empty string if \fIx,y\fR is not over a sash. +\fIpathname\fR \fBidentify\fR \fIcomponent\fR \fIx\fR \fIy\fR +Returns the name of the element under the point given by \fIx\fR and \fIy\fR, +or the empty string if no component is present at that location. +If \fIcomponent\fR is omitted, it defaults to \fBsash\fR. +The following subcommands are supported: +.RS +.TP +\fIpathname\fR \fBidentify\fR \fBelement\fR \fIx\fR \fIy\fR +Returns the name of the element at the specified location. .TP -\fIpathname \fBinsert\fR \fIpos\fR \fIsubwindow\fR \fIoptions...\fR +\fIpathname\fR \fBidentify\fR \fBsash\fR \fIx\fR \fIy\fR +Returns the index of the sash at the specified location. +.RE +.TP +\fIpathname\fR \fBinsert\fR \fIpos\fR \fIsubwindow\fR \fIoptions...\fR Inserts a pane at the specified position. -\fIpos\fR is either the string \fBend\fR, an integer index, +\fIpos\fR is either the string \fBend\fR, an integer index, or the name of a managed subwindow. -If \fIsubwindow\fR is already managed by the paned window, +If \fIsubwindow\fR is already managed by the paned window, moves it to the specified position. See \fBPANE OPTIONS\fR for the list of available options. .TP -\fIpathname \fBpane\fR \fIpane \-option \fR?\fIvalue \fR?\fI\-option value...\fR +\fIpathname\fR \fBpane\fR \fIpane \-option \fR?\fIvalue \fR?\fI\-option value...\fR Query or modify the options of the specified \fIpane\fR, where \fIpane\fR is either an integer index or the name of a managed subwindow. -If no \fI\-option\fR is specified, returns a dictionary of the pane +If no \fI\-option\fR is specified, returns a dictionary of the pane option values. If one \fI\-option\fR is specified, returns the value of that \fIoption\fR. Otherwise, sets the \fI\-option\fRs to the corresponding \fIvalue\fRs. .TP +\fIpathname\fR \fBpanes\fR +Returns the list of all windows managed by the widget. +.TP \fIpathname\fR \fBsashpos\fR \fIindex\fR ?\fInewpos\fR? -If \fInewpos\fR is specified, sets the position +If \fInewpos\fR is specified, sets the position of sash number \fIindex\fR. May adjust the positions of adjacent sashes to ensure that positions are monotonically increasing. -Sash positions are further constrained to be between 0 +Sash positions are further constrained to be between 0 and the total size of the widget. .\" Full story: "total size" is either the -height (resp -width), .\" or the actual window height (resp actual window width), diff --git a/doc/ttk_widget.n b/doc/ttk_widget.n index ca6080d..45788b9 100644 --- a/doc/ttk_widget.n +++ b/doc/ttk_widget.n @@ -1,11 +1,11 @@ '\" '\" Copyright (c) 2004 Joe English -'\" +'\" '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. -'\" -'\" RCS: @(#) $Id: ttk_widget.n,v 1.17 2008/12/03 18:44:49 jenglish Exp $ -'\" +'\" +'\" RCS: @(#) $Id: ttk_widget.n,v 1.18 2009/11/01 18:12:44 jenglish Exp $ +'\" .so man.macros .TH ttk::widget n 8.5 Tk "Tk Themed Widget" .BS @@ -13,17 +13,16 @@ ttk::widget \- Standard options and commands supported by Tk themed widgets .BE .SH DESCRIPTION -.PP This manual describes common widget options and commands. .SH "STANDARD OPTIONS" The following options are supported by all Tk themed widgets: .OP \-class undefined undefined Specifies the window class. -The class is used when querying the option database +The class is used when querying the option database for the window's other options, to determine the default bindtags for the window, and to select the widget's default layout and style. -This is a read-only option: +This is a read-only option: it may only be specified when the window is created, and may not be changed with the \fBconfigure\fR widget command. .OP \-cursor cursor Cursor @@ -33,17 +32,16 @@ for the legal values. If set to the empty string (the default), the cursor is inherited from the parent widget. .OP \-takefocus takeFocus TakeFocus -Determines whether the window accepts the focus during keyboard traversal. +Determines whether the window accepts the focus during keyboard traversal. Either \fB0\fR, \fB1\fR, a command prefix (to which the widget path -is appended, and which should return \fB0\fR or \fB1\fR), +is appended, and which should return \fB0\fR or \fB1\fR), or the empty string. See \fIoptions(n)\fR in the Tk reference manual for the full description. .OP \-style style Style May be used to specify a custom widget style. .SH "SCROLLABLE WIDGET OPTIONS" -.PP The following options are supported by widgets that -are controllable by a scrollbar. +are controllable by a scrollbar. See \fIscrollbar(n)\fR for more information .OP \-xscrollcommand xScrollCommand ScrollCommand A command prefix, used to communicate with horizontal scrollbars. @@ -58,12 +56,12 @@ The first fraction indicates the first information in the widget that is visible in the window, and the second fraction indicates the information just after the last portion that is visible. .PP -Typically the \fBxScrollCommand\fR option consists of the path name +Typically the \fBxScrollCommand\fR option consists of the path name of a \fBscrollbar\fR widget followed by .QW set , e.g. .QW ".x.scrollbar set" . -This will cause the scrollbar to be updated whenever the view in the +This will cause the scrollbar to be updated whenever the view in the window changes. .PP If this option is set to the empty string (the default), @@ -73,7 +71,6 @@ then no command will be executed. A command prefix, used to communicate with vertical scrollbars. See the description of \fB\-xscrollcommand\fR above for details. .SH "LABEL OPTIONS" -.PP The following options are supported by labels, buttons, and other button-like widgets: .OP \-text text Text @@ -83,7 +80,7 @@ Specifies a text string to be displayed inside the widget Specifies the name of variable whose value will be used in place of the \fB\-text\fR resource. .OP \-underline underline Underline -If set, specifies the integer index (0-based) of a character to underline +If set, specifies the integer index (0-based) of a character to underline in the text string. The underlined character is used for mnemonic activation. .OP \-image image Image @@ -97,7 +94,7 @@ All images in the list should have the same size. .OP \-compound compound Compound Specifies how to display the image relative to the text, in the case both \fB\-text\fR and \fB\-image\fR are present. -Valid values are: +Valid values are: .RS .IP text Display text only. @@ -114,8 +111,8 @@ Display image above, below, left of, or right of the text, respectively. The default; display the image if present, otherwise the text. .RE .OP \-width width Width -If greater than zero, specifies how much space, in character widths, -to allocate for the text label. +If greater than zero, specifies how much space, in character widths, +to allocate for the text label. If less than zero, specifies a minimum width. If zero or unspecified, the natural width of the text label is used. .SH "COMPATIBILITY OPTIONS" @@ -123,11 +120,10 @@ If zero or unspecified, the natural width of the text label is used. May be set to \fBnormal\fR or \fBdisabled\fR to control the \fBdisabled\fR state bit. This is a write-only option: -setting it changes the widget state, -but the \fBstate\fR widget command +setting it changes the widget state, +but the \fBstate\fR widget command does not affect the \fB\-state\fR option. .SH COMMANDS -.PP .TP \fIpathName \fBcget\fR \fIoption\fR Returns the current value of the configuration option given @@ -136,36 +132,37 @@ by \fIoption\fR. \fIpathName \fBconfigure\fR ?\fIoption\fR? ?\fIvalue option value ...\fR? Query or modify the configuration options of the widget. If one or more \fIoption\-value\fR pairs are specified, -then the command modifies the given widget option(s) -to have the given value(s); +then the command modifies the given widget option(s) +to have the given value(s); in this case the command returns an empty string. -If \fIoption\fR is specified with no \fIvalue\fR, +If \fIoption\fR is specified with no \fIvalue\fR, then the command returns a list describing the named option: -the elements of the list are the -option name, database name, database class, default value, +the elements of the list are the +option name, database name, database class, default value, and current value. .\" Note: Ttk widgets don't use TK_OPTION_SYNONYM. If no \fIoption\fR is specified, returns a list describing all of the available options for \fIpathName\fR. .TP -\fIpathName \fBidentify\fR \fIx y\fR -Returns the name of the element under the point given +\fIpathName \fBidentify\fR \fBelement\fR \fIx y\fR +Returns the name of the element under the point given by \fIx\fR and \fIy\fR, or an empty string if the point does not lie within any element. \fIx\fR and \fIy\fR are pixel coordinates relative to the widget. -.TP +Some widgets accept other \fBidentify\fR subcommands. +.TP \fIpathName \fBinstate\fR \fIstatespec\fR ?\fIscript\fR? Test the widget's state. -If \fIscript\fR is not specified, returns 1 if +If \fIscript\fR is not specified, returns 1 if the widget state matches \fIstatespec\fR and 0 otherwise. If \fIscript\fR is specified, equivalent to .CS if {[\fIpathName\fR instate \fIstateSpec\fR]} \fIscript\fR .CE -.TP +.TP \fIpathName \fBstate\fR ?\fIstateSpec\fR? Modify or inquire widget state. -If \fIstateSpec\fR is present, sets the widget state: +If \fIstateSpec\fR is present, sets the widget state: for each flag in \fIstateSpec\fR, sets the corresponding flag or clears it if prefixed by an exclamation point. .RS @@ -175,16 +172,15 @@ set changes [\fIpathName \fRstate \fIspec\fR] \fIpathName \fRstate $changes .CE will restore \fIpathName\fR to the original state. -If \fIstateSpec\fR is not specified, +If \fIstateSpec\fR is not specified, returns a list of the currently-enabled state flags. .RE .SH "WIDGET STATES" -.PP The widget state is a bitmap of independent state flags. Widget state flags include: .TP \fBactive\fR -The mouse cursor is over the widget +The mouse cursor is over the widget and pressing a mouse button will cause some action to occur. (aka .QW prelight (Gnome), @@ -195,22 +191,22 @@ and pressing a mouse button will cause some action to occur. (aka \fBdisabled\fR Widget is disabled under program control (aka .QW unavailable , -.QW inactive ) +.QW inactive ) .TP \fBfocus\fR -Widget has keyboard focus +Widget has keyboard focus .TP \fBpressed\fR Widget is being pressed (aka .QW armed -in Motif). +in Motif). .TP \fBselected\fR .QW On , .QW true , or .QW current -for things like checkbuttons and radiobuttons. +for things like checkbuttons and radiobuttons. .TP \fBbackground\fR Windows and the Mac have a notion of an @@ -232,7 +228,7 @@ state, and for buttons with \fB\-default active\fR. .TP \fBinvalid\fR The widget's value is invalid. -(Potential uses: scale widget value out of bounds, +(Potential uses: scale widget value out of bounds, entry widget value failed validation.) .TP \fBhover\fR @@ -247,7 +243,6 @@ A \fIstate specification\fR or \fIstateSpec\fR is a list of state names, optionally prefixed with an exclamation point (!) indicating that the bit is off. .SH EXAMPLES -.PP .CS set b [ttk::button .b] 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) { -- cgit v0.12