summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/ttk/ttkLabel.c117
-rw-r--r--generic/ttk/ttkProgress.c2
2 files changed, 118 insertions, 1 deletions
diff --git a/generic/ttk/ttkLabel.c b/generic/ttk/ttkLabel.c
index 46243b0..6311b71 100644
--- a/generic/ttk/ttkLabel.c
+++ b/generic/ttk/ttkLabel.c
@@ -243,6 +243,122 @@ static const Ttk_ElementSpec TextElementSpec = {
};
/*----------------------------------------------------------------------
+ * +++ cText (collapsing text) element.
+ *
+ * This element is the same as the Text element, except its dimensions
+ * become 0,0 when the text to display is "".
+ */
+
+typedef struct {
+ /*
+ * Element options:
+ */
+ Tcl_Obj *textObj;
+ Tcl_Obj *fontObj;
+ Tcl_Obj *foregroundObj;
+ Tcl_Obj *underlineObj;
+ Tcl_Obj *widthObj;
+ Tcl_Obj *anchorObj;
+ Tcl_Obj *justifyObj;
+ Tcl_Obj *wrapLengthObj;
+ Tcl_Obj *embossedObj;
+
+ /*
+ * Computed resources:
+ */
+ Tk_Font tkfont;
+ Tk_TextLayout textLayout;
+ int width;
+ int height;
+ int embossed;
+
+} cTextElement;
+
+static const Ttk_ElementOptionSpec cTextElementOptions[] = {
+ { "-text", TK_OPTION_STRING,
+ offsetof(cTextElement,textObj), "" },
+ { "-font", TK_OPTION_FONT,
+ offsetof(cTextElement,fontObj), DEFAULT_FONT },
+ { "-foreground", TK_OPTION_COLOR,
+ offsetof(cTextElement,foregroundObj), "black" },
+ { "-underline", TK_OPTION_INDEX,
+#if !defined(TK_NO_DEPRECATED) && (TCL_MAJOR_VERSION < 9)
+ offsetof(cTextElement,underlineObj), "-1"},
+#else
+ offsetof(cTextElement,underlineObj), NULL},
+#endif
+ { "-width", TK_OPTION_INT,
+ offsetof(cTextElement,widthObj), "-1"},
+ { "-anchor", TK_OPTION_ANCHOR,
+ offsetof(cTextElement,anchorObj), "w"},
+ { "-justify", TK_OPTION_JUSTIFY,
+ offsetof(cTextElement,justifyObj), "left" },
+ { "-wraplength", TK_OPTION_PIXELS,
+ offsetof(cTextElement,wrapLengthObj), "0" },
+ { "-embossed", TK_OPTION_INT,
+ offsetof(cTextElement,embossedObj), "0"},
+ { NULL, TK_OPTION_BOOLEAN, 0, NULL }
+};
+
+static int cTextSetup(cTextElement *text, Tk_Window tkwin)
+{
+ if (*Tcl_GetString(text->textObj) == '\0') {
+ return 0;
+ } else {
+ return TextSetup((TextElement *) text, tkwin);
+ }
+}
+
+static int cTextReqWidth(cTextElement *text)
+{
+ return TextReqWidth((TextElement *) text);
+}
+
+static void cTextCleanup(cTextElement *text)
+{
+ TextCleanup((TextElement *) text);
+}
+
+static void cTextDraw(cTextElement *text, Tk_Window tkwin, Drawable d, Ttk_Box b)
+{
+ TextDraw((TextElement *) text, tkwin, d, b);
+}
+
+static void cTextElementSize(
+ void *dummy, void *elementRecord, Tk_Window tkwin,
+ int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
+{
+ cTextElement *text = (cTextElement *)elementRecord;
+ (void)dummy;
+ (void)paddingPtr;
+
+ if (!cTextSetup(text, tkwin))
+ return;
+
+ *heightPtr = text->height;
+ *widthPtr = cTextReqWidth(text);
+
+ cTextCleanup(text);
+
+ return;
+}
+
+static void cTextElementDraw(
+ void *dummy, void *elementRecord, Tk_Window tkwin,
+ Drawable d, Ttk_Box b, Ttk_State state)
+{
+ TextElementDraw(dummy, elementRecord, tkwin, d, b, state);
+}
+
+static const Ttk_ElementSpec cTextElementSpec = {
+ TK_STYLE_VERSION_2,
+ sizeof(cTextElement),
+ cTextElementOptions,
+ cTextElementSize,
+ cTextElementDraw
+};
+
+/*----------------------------------------------------------------------
* +++ Image element.
* Draws an image.
*/
@@ -720,6 +836,7 @@ void TtkLabel_Init(Tcl_Interp *interp)
Ttk_Theme theme = Ttk_GetDefaultTheme(interp);
Ttk_RegisterElement(interp, theme, "text", &TextElementSpec, NULL);
+ Ttk_RegisterElement(interp, theme, "ctext", &cTextElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "image", &ImageElementSpec, NULL);
Ttk_RegisterElement(interp, theme, "label", &LabelElementSpec, NULL);
}
diff --git a/generic/ttk/ttkProgress.c b/generic/ttk/ttkProgress.c
index 89b3d90..177cc69 100644
--- a/generic/ttk/ttkProgress.c
+++ b/generic/ttk/ttkProgress.c
@@ -561,7 +561,7 @@ TTK_END_LAYOUT
TTK_BEGIN_LAYOUT(HorizontalProgressbarLayout)
TTK_GROUP("Horizontal.Progressbar.trough", TTK_FILL_BOTH,
TTK_NODE("Horizontal.Progressbar.pbar", TTK_PACK_LEFT|TTK_FILL_Y)
- TTK_NODE("Horizontal.Progressbar.text", TTK_PACK_LEFT))
+ TTK_NODE("Horizontal.Progressbar.ctext", TTK_PACK_LEFT))
TTK_END_LAYOUT
/*