summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjenglish <jenglish@flightlab.com>2007-12-02 04:32:22 (GMT)
committerjenglish <jenglish@flightlab.com>2007-12-02 04:32:22 (GMT)
commitb9257b2ca5a2c1098db948daf8a8b050caa0e96c (patch)
treedcc1e3b870946ba7a2888ef66bd97ad71aa71aa3 /generic
parent547f91bd5d798f6eb0d2993c410a0e4c6d31b8dd (diff)
downloadtk-b9257b2ca5a2c1098db948daf8a8b050caa0e96c.zip
tk-b9257b2ca5a2c1098db948daf8a8b050caa0e96c.tar.gz
tk-b9257b2ca5a2c1098db948daf8a8b050caa0e96c.tar.bz2
Improved macrology for statically-initialized layout template tables.
Diffstat (limited to 'generic')
-rw-r--r--generic/ttk/ttkClamTheme.c25
-rw-r--r--generic/ttk/ttkClassicTheme.c43
-rw-r--r--generic/ttk/ttkLayout.c22
-rw-r--r--generic/ttk/ttkTheme.c5
-rw-r--r--generic/ttk/ttkTheme.h26
-rw-r--r--generic/ttk/ttkThemeInt.h7
-rw-r--r--generic/ttk/ttkTreeview.c37
7 files changed, 90 insertions, 75 deletions
diff --git a/generic/ttk/ttkClamTheme.c b/generic/ttk/ttkClamTheme.c
index 39d38b4..a5b0392 100644
--- a/generic/ttk/ttkClamTheme.c
+++ b/generic/ttk/ttkClamTheme.c
@@ -1,5 +1,5 @@
/*
- * $Id: ttkClamTheme.c,v 1.7 2007/11/08 01:40:24 jenglish Exp $
+ * $Id: ttkClamTheme.c,v 1.8 2007/12/02 04:32:22 jenglish Exp $
*
* Copyright (C) 2004 Joe English
*
@@ -896,22 +896,23 @@ static Ttk_ElementSpec ClientElementSpec =
* +++ Modified widget layouts.
*/
-TTK_BEGIN_LAYOUT(ComboboxLayout)
+TTK_BEGIN_LAYOUT_TABLE(LayoutTable)
+
+TTK_LAYOUT("TCombobox",
TTK_NODE("Combobox.downarrow", TTK_PACK_RIGHT|TTK_FILL_Y)
TTK_GROUP("Combobox.field", TTK_PACK_LEFT|TTK_FILL_BOTH|TTK_EXPAND,
TTK_GROUP("Combobox.padding", TTK_FILL_BOTH,
- TTK_NODE("Combobox.textarea", TTK_FILL_BOTH)))
-TTK_END_LAYOUT
+ TTK_NODE("Combobox.textarea", TTK_FILL_BOTH))))
-TTK_BEGIN_LAYOUT(HorizontalSashLayout)
+TTK_LAYOUT("Horizontal.Sash",
TTK_GROUP("Sash.hsash", TTK_FILL_BOTH,
- TTK_NODE("Sash.hgrip", TTK_FILL_BOTH))
-TTK_END_LAYOUT
+ TTK_NODE("Sash.hgrip", TTK_FILL_BOTH)))
-TTK_BEGIN_LAYOUT(VerticalSashLayout)
+TTK_LAYOUT("Vertical.Sash",
TTK_GROUP("Sash.vsash", TTK_FILL_BOTH,
- TTK_NODE("Sash.vgrip", TTK_FILL_BOTH))
-TTK_END_LAYOUT
+ TTK_NODE("Sash.vgrip", TTK_FILL_BOTH)))
+
+TTK_END_LAYOUT_TABLE
/*------------------------------------------------------------------------
* +++ Initialization.
@@ -964,9 +965,7 @@ TtkClamTheme_Init(Tcl_Interp *interp)
Ttk_RegisterElement(interp, theme, "vgrip",
&GripElementSpec, &GripClientData[1]);
- Ttk_RegisterLayout(theme, "TCombobox", ComboboxLayout);
- Ttk_RegisterLayout(theme, "Horizontal.Sash", HorizontalSashLayout);
- Ttk_RegisterLayout(theme, "Vertical.Sash", VerticalSashLayout);
+ Ttk_RegisterLayouts(theme, LayoutTable);
Tcl_PkgProvide(interp, "ttk::theme::clam", TTK_VERSION);
diff --git a/generic/ttk/ttkClassicTheme.c b/generic/ttk/ttkClassicTheme.c
index c37b62e..6ca027b 100644
--- a/generic/ttk/ttkClassicTheme.c
+++ b/generic/ttk/ttkClassicTheme.c
@@ -1,5 +1,5 @@
/*
- * $Id: ttkClassicTheme.c,v 1.4 2007/10/25 07:08:26 jenglish Exp $
+ * $Id: ttkClassicTheme.c,v 1.5 2007/12/02 04:32:23 jenglish Exp $
*
* Copyright (c) 2004, Joe English
*
@@ -419,51 +419,49 @@ static Ttk_ElementSpec SashElementSpec = {
* +++ Widget layouts.
*/
-TTK_BEGIN_LAYOUT(ButtonLayout)
+TTK_BEGIN_LAYOUT_TABLE(LayoutTable)
+
+TTK_LAYOUT("TButton",
TTK_GROUP("Button.highlight", TTK_FILL_BOTH,
TTK_GROUP("Button.border", TTK_FILL_BOTH|TTK_BORDER,
TTK_GROUP("Button.padding", TTK_FILL_BOTH,
- TTK_NODE("Button.label", TTK_FILL_BOTH))))
-TTK_END_LAYOUT
+ TTK_NODE("Button.label", TTK_FILL_BOTH)))))
-TTK_BEGIN_LAYOUT(CheckbuttonLayout)
+TTK_LAYOUT("TCheckbutton",
TTK_GROUP("Checkbutton.highlight", TTK_FILL_BOTH,
TTK_GROUP("Checkbutton.border", TTK_FILL_BOTH,
TTK_GROUP("Checkbutton.padding", TTK_FILL_BOTH,
TTK_NODE("Checkbutton.indicator", TTK_PACK_LEFT)
- TTK_NODE("Checkbutton.label", TTK_PACK_LEFT|TTK_FILL_BOTH))))
-TTK_END_LAYOUT
+ TTK_NODE("Checkbutton.label", TTK_PACK_LEFT|TTK_FILL_BOTH)))))
-TTK_BEGIN_LAYOUT(RadiobuttonLayout)
+TTK_LAYOUT("TRadiobutton",
TTK_GROUP("Radiobutton.highlight", TTK_FILL_BOTH,
TTK_GROUP("Radiobutton.border", TTK_FILL_BOTH,
TTK_GROUP("Radiobutton.padding", TTK_FILL_BOTH,
TTK_NODE("Radiobutton.indicator", TTK_PACK_LEFT)
- TTK_NODE("Radiobutton.label", TTK_PACK_LEFT|TTK_FILL_BOTH))))
-TTK_END_LAYOUT
+ TTK_NODE("Radiobutton.label", TTK_PACK_LEFT|TTK_FILL_BOTH)))))
-TTK_BEGIN_LAYOUT(MenubuttonLayout)
+TTK_LAYOUT("TMenubutton",
TTK_GROUP("Menubutton.highlight", TTK_FILL_BOTH,
TTK_GROUP("Menubutton.border", TTK_FILL_BOTH,
TTK_NODE("Menubutton.indicator", TTK_PACK_RIGHT)
TTK_GROUP("Menubutton.padding", TTK_PACK_LEFT|TTK_EXPAND|TTK_FILL_X,
- TTK_NODE("Menubutton.label", 0))))
-TTK_END_LAYOUT
+ TTK_NODE("Menubutton.label", 0)))))
/* "classic" entry, includes highlight border */
-TTK_BEGIN_LAYOUT(EntryLayout)
+TTK_LAYOUT("TEntry",
TTK_GROUP("Entry.highlight", TTK_FILL_BOTH,
TTK_GROUP("Entry.field", TTK_FILL_BOTH|TTK_BORDER,
TTK_GROUP("Entry.padding", TTK_FILL_BOTH,
- TTK_NODE("Entry.textarea", TTK_FILL_BOTH))))
-TTK_END_LAYOUT
+ TTK_NODE("Entry.textarea", TTK_FILL_BOTH)))))
/* Notebook tabs -- omit focus ring */
-TTK_BEGIN_LAYOUT(TabLayout)
+TTK_LAYOUT("Tab",
TTK_GROUP("Notebook.tab", TTK_FILL_BOTH,
TTK_GROUP("Notebook.padding", TTK_FILL_BOTH,
- TTK_NODE("Notebook.label", TTK_FILL_BOTH)))
-TTK_END_LAYOUT
+ TTK_NODE("Notebook.label", TTK_FILL_BOTH))))
+
+TTK_END_LAYOUT_TABLE
/* POSSIBLY: include Scale layouts w/focus border
*/
@@ -509,12 +507,7 @@ MODULE_SCOPE int TtkClassicTheme_Init(Tcl_Interp *interp)
/*
* Register layouts:
*/
- Ttk_RegisterLayout(theme, "TButton", ButtonLayout);
- Ttk_RegisterLayout(theme, "TCheckbutton", CheckbuttonLayout);
- Ttk_RegisterLayout(theme, "TRadiobutton", RadiobuttonLayout);
- Ttk_RegisterLayout(theme, "TMenubutton", MenubuttonLayout);
- Ttk_RegisterLayout(theme, "TEntry", EntryLayout);
- Ttk_RegisterLayout(theme, "TNotebook.Tab", TabLayout);
+ Ttk_RegisterLayouts(theme, LayoutTable);
Tcl_PkgProvide(interp, "ttk::theme::classic", TTK_VERSION);
diff --git a/generic/ttk/ttkLayout.c b/generic/ttk/ttkLayout.c
index 76754e7..3606c59 100644
--- a/generic/ttk/ttkLayout.c
+++ b/generic/ttk/ttkLayout.c
@@ -5,7 +5,7 @@
*
* Copyright (c) 2003 Joe English. Freely redistributable.
*
- * $Id: ttkLayout.c,v 1.9 2007/11/18 17:28:02 jenglish Exp $
+ * $Id: ttkLayout.c,v 1.10 2007/12/02 04:32:23 jenglish Exp $
*/
#include <string.h>
@@ -722,7 +722,7 @@ Ttk_LayoutTemplate Ttk_BuildLayoutTemplate(Ttk_LayoutSpec spec)
{
Ttk_TemplateNode *first = 0, *last = 0;
- for ( ; !(spec->opcode & TTK_LAYOUT_END) ; ++spec) {
+ for ( ; !(spec->opcode & _TTK_LAYOUT_END) ; ++spec) {
if (spec->elementName) {
Ttk_TemplateNode *node =
Ttk_NewTemplateNode(spec->elementName, spec->opcode);
@@ -735,7 +735,7 @@ Ttk_LayoutTemplate Ttk_BuildLayoutTemplate(Ttk_LayoutSpec spec)
last = node;
}
- if (spec->opcode & TTK_CHILDREN) {
+ if (spec->opcode & _TTK_CHILDREN) {
int depth = 1;
last->child = Ttk_BuildLayoutTemplate(spec+1);
@@ -743,19 +743,31 @@ Ttk_LayoutTemplate Ttk_BuildLayoutTemplate(Ttk_LayoutSpec spec)
*/
while (depth) {
++spec;
- if (spec->opcode & TTK_CHILDREN) {
+ if (spec->opcode & _TTK_CHILDREN) {
++depth;
}
- if (spec->opcode & TTK_LAYOUT_END) {
+ if (spec->opcode & _TTK_LAYOUT_END) {
--depth;
}
}
}
+
} /* for */
return first;
}
+void Ttk_RegisterLayouts(Ttk_Theme theme, Ttk_LayoutSpec spec)
+{
+ while (!(spec->opcode & _TTK_LAYOUT_END)) {
+ Ttk_LayoutTemplate layoutTemplate = Ttk_BuildLayoutTemplate(spec+1);
+ Ttk_RegisterLayoutTemplate(theme, spec->elementName, layoutTemplate);
+ do {
+ ++spec;
+ } while (!(spec->opcode & _TTK_LAYOUT));
+ }
+}
+
Tcl_Obj *Ttk_UnparseLayoutTemplate(Ttk_TemplateNode *node)
{
Tcl_Obj *result = Tcl_NewListObj(0,0);
diff --git a/generic/ttk/ttkTheme.c b/generic/ttk/ttkTheme.c
index de63d71..3099f18 100644
--- a/generic/ttk/ttkTheme.c
+++ b/generic/ttk/ttkTheme.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * $Id: ttkTheme.c,v 1.8 2007/11/19 18:49:59 patthoyts Exp $
+ * $Id: ttkTheme.c,v 1.9 2007/12/02 04:32:23 jenglish Exp $
*/
#include <stdlib.h>
@@ -671,7 +671,8 @@ Ttk_GetResourceCache(Tcl_Interp *interp)
* Register a new layout specification with a style.
* @@@ TODO: Make sure layoutName is not ".", root style must not have a layout
*/
-static void Ttk_RegisterLayoutTemplate(
+MODULE_SCOPE
+void Ttk_RegisterLayoutTemplate(
Ttk_Theme theme, /* Target theme */
const char *layoutName, /* Name of new layout */
Ttk_LayoutTemplate layoutTemplate) /* Template */
diff --git a/generic/ttk/ttkTheme.h b/generic/ttk/ttkTheme.h
index adca259..a0be12e 100644
--- a/generic/ttk/ttkTheme.h
+++ b/generic/ttk/ttkTheme.h
@@ -1,4 +1,4 @@
-/* $Id: ttkTheme.h,v 1.11 2007/10/25 07:08:26 jenglish Exp $
+/* $Id: ttkTheme.h,v 1.12 2007/12/02 04:32:23 jenglish Exp $
* Copyright (c) 2003 Joe English. Freely redistributable.
*
* Declarations for Tk theme engine.
@@ -181,8 +181,9 @@ typedef unsigned int Ttk_PositionSpec; /* See below */
/*
* Extra bits for layout specifications
*/
-#define TTK_CHILDREN (0x1000)/* for LayoutSpecs -- children follow */
-#define TTK_LAYOUT_END (0x2000)/* for LayoutSpecs -- end of child list */
+#define _TTK_CHILDREN (0x1000)/* for LayoutSpecs -- children follow */
+#define _TTK_LAYOUT_END (0x2000)/* for LayoutSpecs -- end of child list */
+#define _TTK_LAYOUT (0x4000)/* for LayoutSpec tables -- define layout */
#define _TTK_MASK_STICK (0x0F) /* See Ttk_UnparseLayout() */
#define _TTK_MASK_PACK (0xF0) /* See Ttk_UnparseLayout(), packStrings */
@@ -285,17 +286,28 @@ typedef struct {
unsigned opcode;
} TTKLayoutInstruction, *Ttk_LayoutSpec;
-#define TTK_BEGIN_LAYOUT(name) static TTKLayoutInstruction name[] = {
+#define TTK_BEGIN_LAYOUT_TABLE(name) \
+ static TTKLayoutInstruction name[] = {
+#define TTK_LAYOUT(name, content) \
+ { name, _TTK_CHILDREN|_TTK_LAYOUT }, \
+ content \
+ { 0, _TTK_LAYOUT_END },
#define TTK_GROUP(name, flags, children) \
- { name, flags | TTK_CHILDREN }, \
+ { name, flags | _TTK_CHILDREN }, \
children \
- { 0, TTK_LAYOUT_END },
+ { 0, _TTK_LAYOUT_END },
#define TTK_NODE(name, flags) { name, flags },
-#define TTK_END_LAYOUT { 0, TTK_LAYOUT_END } };
+#define TTK_END_LAYOUT_TABLE { 0, _TTK_LAYOUT | _TTK_LAYOUT_END } };
+
+#define TTK_BEGIN_LAYOUT(name) static TTKLayoutInstruction name[] = {
+#define TTK_END_LAYOUT { 0, _TTK_LAYOUT_END } };
TTKAPI void Ttk_RegisterLayout(
Ttk_Theme theme, const char *className, Ttk_LayoutSpec layoutSpec);
+TTKAPI void Ttk_RegisterLayouts(
+ Ttk_Theme theme, Ttk_LayoutSpec layoutTable);
+
/*------------------------------------------------------------------------
* +++ Layout instances.
*/
diff --git a/generic/ttk/ttkThemeInt.h b/generic/ttk/ttkThemeInt.h
index 9a904de..0d94649 100644
--- a/generic/ttk/ttkThemeInt.h
+++ b/generic/ttk/ttkThemeInt.h
@@ -1,5 +1,5 @@
/*
- * $Id: ttkThemeInt.h,v 1.3 2006/12/10 19:19:44 jenglish Exp $
+ * $Id: ttkThemeInt.h,v 1.4 2007/12/02 04:32:23 jenglish Exp $
*
* Theme engine: private definitions.
*
@@ -28,10 +28,13 @@ MODULE_SCOPE void Ttk_DrawElement(
MODULE_SCOPE Tcl_Obj *Ttk_QueryStyle(
Ttk_Style, void *, Tk_OptionTable, const char *, Ttk_State state);
-MODULE_SCOPE Ttk_LayoutTemplate Ttk_ParseLayoutTemplate(Tcl_Interp *, Tcl_Obj *);
+MODULE_SCOPE Ttk_LayoutTemplate Ttk_ParseLayoutTemplate(
+ Tcl_Interp *, Tcl_Obj *);
MODULE_SCOPE Tcl_Obj *Ttk_UnparseLayoutTemplate(Ttk_LayoutTemplate);
MODULE_SCOPE Ttk_LayoutTemplate Ttk_BuildLayoutTemplate(Ttk_LayoutSpec);
MODULE_SCOPE void Ttk_FreeLayoutTemplate(Ttk_LayoutTemplate);
+MODULE_SCOPE void Ttk_RegisterLayoutTemplate(
+ Ttk_Theme theme, const char *layoutName, Ttk_LayoutTemplate);
MODULE_SCOPE Ttk_Style Ttk_GetStyle(Ttk_Theme themePtr, const char *styleName);
MODULE_SCOPE Ttk_LayoutTemplate Ttk_FindLayoutTemplate(
diff --git a/generic/ttk/ttkTreeview.c b/generic/ttk/ttkTreeview.c
index a9d53e3..bca2c10 100644
--- a/generic/ttk/ttkTreeview.c
+++ b/generic/ttk/ttkTreeview.c
@@ -1,4 +1,4 @@
-/* $Id: ttkTreeview.c,v 1.21 2007/11/08 01:40:25 jenglish Exp $
+/* $Id: ttkTreeview.c,v 1.22 2007/12/02 04:32:23 jenglish Exp $
* Copyright (c) 2004, Joe English
*
* ttk::treeview widget implementation.
@@ -3041,36 +3041,35 @@ static WidgetSpec TreeviewWidgetSpec =
* +++ Layout specifications.
*/
-TTK_BEGIN_LAYOUT(TreeviewLayout)
+TTK_BEGIN_LAYOUT_TABLE(LayoutTable)
+
+TTK_LAYOUT("Treeview",
TTK_GROUP("Treeview.field", TTK_FILL_BOTH|TTK_BORDER,
TTK_GROUP("Treeview.padding", TTK_FILL_BOTH,
- TTK_NODE("Treeview.treearea", TTK_FILL_BOTH)))
-TTK_END_LAYOUT
+ TTK_NODE("Treeview.treearea", TTK_FILL_BOTH))))
-TTK_BEGIN_LAYOUT(ItemLayout)
+TTK_LAYOUT("Item",
TTK_GROUP("Treeitem.padding", TTK_FILL_BOTH,
TTK_NODE("Treeitem.indicator", TTK_PACK_LEFT)
TTK_NODE("Treeitem.image", TTK_PACK_LEFT)
TTK_GROUP("Treeitem.focus", TTK_PACK_LEFT,
- TTK_NODE("Treeitem.text", TTK_PACK_LEFT)))
-TTK_END_LAYOUT
+ TTK_NODE("Treeitem.text", TTK_PACK_LEFT))))
-TTK_BEGIN_LAYOUT(CellLayout)
+TTK_LAYOUT("Cell",
TTK_GROUP("Treedata.padding", TTK_FILL_BOTH,
- TTK_NODE("Treeitem.text", TTK_FILL_BOTH))
-TTK_END_LAYOUT
+ TTK_NODE("Treeitem.text", TTK_FILL_BOTH)))
-TTK_BEGIN_LAYOUT(HeadingLayout)
+TTK_LAYOUT("Heading",
TTK_NODE("Treeheading.cell", TTK_FILL_BOTH)
TTK_GROUP("Treeheading.border", TTK_FILL_BOTH,
TTK_GROUP("Treeheading.padding", TTK_FILL_BOTH,
TTK_NODE("Treeheading.image", TTK_PACK_RIGHT)
- TTK_NODE("Treeheading.text", TTK_FILL_X)))
-TTK_END_LAYOUT
+ TTK_NODE("Treeheading.text", TTK_FILL_X))))
+
+TTK_LAYOUT("Row",
+ TTK_NODE("Treeitem.row", TTK_FILL_BOTH))
-TTK_BEGIN_LAYOUT(RowLayout)
- TTK_NODE("Treeitem.row", TTK_FILL_BOTH)
-TTK_END_LAYOUT
+TTK_END_LAYOUT_TABLE
/*------------------------------------------------------------------------
* +++ Tree indicator element.
@@ -3201,11 +3200,7 @@ void TtkTreeview_Init(Tcl_Interp *interp)
Ttk_RegisterElement(interp, theme, "Treeheading.cell", &RowElementSpec, 0);
Ttk_RegisterElement(interp, theme, "treearea", &ttkNullElementSpec, 0);
- Ttk_RegisterLayout(theme, TreeviewWidgetSpec.className, TreeviewLayout);
- Ttk_RegisterLayout(theme, "Item", ItemLayout);
- Ttk_RegisterLayout(theme, "Cell", CellLayout);
- Ttk_RegisterLayout(theme, "Heading", HeadingLayout);
- Ttk_RegisterLayout(theme, "Row", RowLayout);
+ Ttk_RegisterLayouts(theme, LayoutTable);
}
/*EOF*/