summaryrefslogtreecommitdiffstats
path: root/generic/ttk/ttkFrame.c
diff options
context:
space:
mode:
authorjenglish <jenglish@flightlab.com>2007-11-18 19:20:24 (GMT)
committerjenglish <jenglish@flightlab.com>2007-11-18 19:20:24 (GMT)
commitaa5ebe3414405d7b4ad1a8271f395866e8a65f79 (patch)
treeaadad427b46a83b0e4b696481aba274e50fec32d /generic/ttk/ttkFrame.c
parentd9b51f4b71e2318378ed9a818970213c3b381894 (diff)
downloadtk-aa5ebe3414405d7b4ad1a8271f395866e8a65f79.zip
tk-aa5ebe3414405d7b4ad1a8271f395866e8a65f79.tar.gz
tk-aa5ebe3414405d7b4ad1a8271f395866e8a65f79.tar.bz2
* generic/ttk/ttkFrame.c: Use sublayout for ttk::labelframe labels
instead of single element. * generic/ttk/ttkLabel.c: Default -anchor for text and label elements is now "w" instead of "center". Fixes [Bug 1614540]. * library/ttk/defaults.tcl, library/ttk/*Theme.tcl: Button styles now need explicit "-anchor center".
Diffstat (limited to 'generic/ttk/ttkFrame.c')
-rw-r--r--generic/ttk/ttkFrame.c93
1 files changed, 58 insertions, 35 deletions
diff --git a/generic/ttk/ttkFrame.c b/generic/ttk/ttkFrame.c
index b6f8fe8..700288f 100644
--- a/generic/ttk/ttkFrame.c
+++ b/generic/ttk/ttkFrame.c
@@ -1,4 +1,4 @@
-/* $Id: ttkFrame.c,v 1.7 2007/10/25 07:08:26 jenglish Exp $
+/* $Id: ttkFrame.c,v 1.8 2007/11/18 19:20:25 jenglish Exp $
* Copyright (c) 2004, Joe English
*
* ttk::frame and ttk::labelframe widgets.
@@ -14,8 +14,7 @@
* +++ Frame widget:
*/
-typedef struct
-{
+typedef struct {
Tcl_Obj *borderWidthObj;
Tcl_Obj *paddingObj;
Tcl_Obj *reliefObj;
@@ -23,8 +22,7 @@ typedef struct
Tcl_Obj *heightObj;
} FramePart;
-typedef struct
-{
+typedef struct {
WidgetCore core;
FramePart frame;
} Frame;
@@ -241,11 +239,11 @@ typedef struct {
Tk_Window labelWidget;
Ttk_Manager *mgr;
+ Ttk_Layout labelLayout; /* Sublayout for label */
Ttk_Box labelParcel; /* Set in layoutProc */
} LabelframePart;
-typedef struct
-{
+typedef struct {
WidgetCore core;
FramePart frame;
LabelframePart label;
@@ -274,8 +272,7 @@ static Tk_OptionSpec LabelframeOptionSpecs[] =
/*
* Labelframe style parameters:
*/
-typedef struct
-{
+typedef struct {
int borderWidth; /* border width */
Ttk_Padding padding; /* internal padding */
Ttk_PositionSpec labelAnchor; /* corner/side to place label */
@@ -321,17 +318,13 @@ static void LabelframeStyleOptions(Labelframe *lf, LabelframeStyle *style)
static void
LabelframeLabelSize(Labelframe *lframePtr, int *widthPtr, int *heightPtr)
{
- WidgetCore *corePtr = &lframePtr->core;
Tk_Window labelWidget = lframePtr->label.labelWidget;
- Ttk_LayoutNode *textNode = Ttk_LayoutFindNode(corePtr->layout, "text");
if (labelWidget) {
*widthPtr = Tk_ReqWidth(labelWidget);
*heightPtr = Tk_ReqHeight(labelWidget);
- } else if (textNode) {
- Ttk_LayoutNodeReqSize(corePtr->layout, textNode, widthPtr, heightPtr);
} else {
- *widthPtr = *heightPtr = 0;
+ Ttk_LayoutSize(lframePtr->label.labelLayout, 0, widthPtr, heightPtr);
}
}
@@ -379,6 +372,36 @@ static int LabelframeSize(void *recordPtr, int *widthPtr, int *heightPtr)
return 0;
}
+/*
+ * LabelframeGetLayout --
+ * Getlayout widget hook.
+ */
+
+static Ttk_Layout LabelframeGetLayout(
+ Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr)
+{
+ Labelframe *lf = recordPtr;
+ Ttk_Layout frameLayout = TtkWidgetGetLayout(interp, theme, recordPtr);
+ Ttk_Layout labelLayout;
+
+ if (!frameLayout) {
+ return NULL;
+ }
+
+ labelLayout = Ttk_CreateSublayout(
+ interp, theme, frameLayout, ".Label", lf->core.optionTable);
+
+ if (labelLayout) {
+ if (lf->label.labelLayout) {
+ Ttk_FreeLayout(lf->label.labelLayout);
+ }
+ Ttk_RebindSublayout(labelLayout, recordPtr);
+ lf->label.labelLayout = labelLayout;
+ }
+
+ return frameLayout;
+}
+
/*
* LabelframeDoLayout --
* Labelframe layout hook.
@@ -390,20 +413,12 @@ static void LabelframeDoLayout(void *recordPtr)
{
Labelframe *lframePtr = recordPtr;
WidgetCore *corePtr = &lframePtr->core;
- Ttk_Box borderParcel = Ttk_WinBox(corePtr->tkwin);
- Ttk_LayoutNode
- *textNode = Ttk_LayoutFindNode(corePtr->layout, "text"),
- *borderNode = Ttk_LayoutFindNode(corePtr->layout, "border");
int lw, lh; /* Label width and height */
LabelframeStyle style;
+ Ttk_Box borderParcel = Ttk_WinBox(lframePtr->core.tkwin);
Ttk_Box labelParcel;
/*
- * Do base layout:
- */
- Ttk_PlaceLayout(corePtr->layout,corePtr->state,borderParcel);
-
- /*
* Compute label parcel:
*/
LabelframeStyleOptions(lframePtr, &style);
@@ -429,16 +444,22 @@ static void LabelframeDoLayout(void *recordPtr)
/*
* Place border and label:
*/
- if (borderNode) {
- Ttk_PlaceLayoutNode(corePtr->layout, borderNode, borderParcel);
- }
- if (textNode) {
- Ttk_PlaceLayoutNode(corePtr->layout, textNode, labelParcel);
- }
+ Ttk_PlaceLayout(corePtr->layout, corePtr->state, borderParcel);
+ Ttk_PlaceLayout(lframePtr->label.labelLayout, corePtr->state, labelParcel);
/* labelWidget placed in LabelframePlaceSlaves GM hook */
lframePtr->label.labelParcel = labelParcel;
}
+static void LabelframeDisplay(void *recordPtr, Drawable d)
+{
+ Labelframe *lframePtr = recordPtr;
+ Ttk_DrawLayout(lframePtr->core.layout, lframePtr->core.state, d);
+ Ttk_DrawLayout(lframePtr->label.labelLayout, lframePtr->core.state, d);
+}
+
+/* +++ Labelframe geometry manager hooks.
+ */
+
/* LabelframePlaceSlaves --
* Sets the position and size of the labelwidget.
*/
@@ -455,9 +476,6 @@ static void LabelframePlaceSlaves(void *recordPtr)
}
}
-/* Labelframe geometry manager:
- */
-
/* LabelRemoved --
* Unset the -labelwidget option.
*
@@ -489,6 +507,7 @@ static int LabelframeInitialize(Tcl_Interp *interp, void *recordPtr)
lframe->label.mgr = Ttk_CreateManager(
&LabelframeManagerSpec, lframe, lframe->core.tkwin);
lframe->label.labelWidget = 0;
+ lframe->label.labelLayout = 0;
lframe->label.labelParcel = Ttk_MakeBox(-1,-1,-1,-1);
return TCL_OK;
@@ -585,19 +604,22 @@ static WidgetSpec LabelframeWidgetSpec =
LabelframeCleanup, /* cleanupProc */
LabelframeConfigure, /* configureProc */
TtkNullPostConfigure, /* postConfigureProc */
- TtkWidgetGetLayout, /* getLayoutProc */
+ LabelframeGetLayout, /* getLayoutProc */
LabelframeSize, /* sizeProc */
LabelframeDoLayout, /* layoutProc */
- TtkWidgetDisplay /* displayProc */
+ LabelframeDisplay /* displayProc */
};
TTK_BEGIN_LAYOUT(LabelframeLayout)
TTK_NODE("Labelframe.border", TTK_FILL_BOTH)
+TTK_END_LAYOUT
+
+TTK_BEGIN_LAYOUT(LabelSublayout)
TTK_NODE("Labelframe.text", TTK_FILL_BOTH)
TTK_END_LAYOUT
/* ======================================================================
- * +++ Initialization:
+ * +++ Initialization.
*/
MODULE_SCOPE
@@ -607,6 +629,7 @@ void TtkFrame_Init(Tcl_Interp *interp)
Ttk_RegisterLayout(theme, "TFrame", FrameLayout);
Ttk_RegisterLayout(theme, "TLabelframe", LabelframeLayout);
+ Ttk_RegisterLayout(theme, "TLabelframe.Label", LabelSublayout);
RegisterWidget(interp, "ttk::frame", &FrameWidgetSpec);
RegisterWidget(interp, "ttk::labelframe", &LabelframeWidgetSpec);