1 /*
2  * Copyright © 2004 Joe English
3  *
4  * ttk::separator and ttk::sizegrip widgets.
5  */
6 
7 #include "tkInt.h"
8 #include "ttkTheme.h"
9 #include "ttkWidget.h"
10 
11 /* +++ Separator widget record:
12  */
13 typedef struct
14 {
15     Tcl_Obj	*orientObj;
16     int 	orient;
17 } SeparatorPart;
18 
19 typedef struct
20 {
21     WidgetCore core;
22     SeparatorPart separator;
23 } Separator;
24 
25 static const Tk_OptionSpec SeparatorOptionSpecs[] = {
26     {TK_OPTION_STRING_TABLE, "-orient", "orient", "Orient", "horizontal",
27 	offsetof(Separator,separator.orientObj),
28 	offsetof(Separator,separator.orient),
29 	0, (void *)ttkOrientStrings, STYLE_CHANGED },
30 
31     WIDGET_TAKEFOCUS_FALSE,
32     WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
33 };
34 
35 /*
36  * GetLayout hook --
37  * 	Choose layout based on -orient option.
38  */
SeparatorGetLayout(Tcl_Interp * interp,Ttk_Theme theme,void * recordPtr)39 static Ttk_Layout SeparatorGetLayout(
40     Tcl_Interp *interp, Ttk_Theme theme, void *recordPtr)
41 {
42     Separator *sep = (Separator *)recordPtr;
43     return TtkWidgetGetOrientedLayout(
44 	interp, theme, recordPtr, sep->separator.orientObj);
45 }
46 
47 /*
48  * Widget commands:
49  */
50 static const Ttk_Ensemble SeparatorCommands[] = {
51     { "cget",		TtkWidgetCgetCommand,0 },
52     { "configure",	TtkWidgetConfigureCommand,0 },
53     { "identify",	TtkWidgetIdentifyCommand,0 },
54     { "instate",	TtkWidgetInstateCommand,0 },
55     { "state",  	TtkWidgetStateCommand,0 },
56     { "style",		TtkWidgetStyleCommand,0 },
57     { 0,0,0 }
58 };
59 
60 /*
61  * Widget specification:
62  */
63 static const WidgetSpec SeparatorWidgetSpec =
64 {
65     "TSeparator",		/* className */
66     sizeof(Separator),		/* recordSize */
67     SeparatorOptionSpecs,	/* optionSpecs */
68     SeparatorCommands,		/* subcommands */
69     TtkNullInitialize,		/* initializeProc */
70     TtkNullCleanup,		/* cleanupProc */
71     TtkCoreConfigure,		/* configureProc */
72     TtkNullPostConfigure,	/* postConfigureProc */
73     SeparatorGetLayout,		/* getLayoutProc */
74     TtkWidgetSize, 		/* sizeProc */
75     TtkWidgetDoLayout,		/* layoutProc */
76     TtkWidgetDisplay		/* displayProc */
77 };
78 
79 TTK_BEGIN_LAYOUT(SeparatorLayout)
80     TTK_NODE("Separator.separator", TTK_FILL_BOTH)
81 TTK_END_LAYOUT
82 
83 /* +++ Sizegrip widget:
84  * 	Has no options or methods other than the standard ones.
85  */
86 
87 static const Tk_OptionSpec SizegripOptionSpecs[] = {
88     WIDGET_TAKEFOCUS_FALSE,
89     WIDGET_INHERIT_OPTIONS(ttkCoreOptionSpecs)
90 };
91 
92 static const Ttk_Ensemble SizegripCommands[] = {
93     { "cget",		TtkWidgetCgetCommand,0 },
94     { "configure",	TtkWidgetConfigureCommand,0 },
95     { "identify",	TtkWidgetIdentifyCommand,0 },
96     { "instate",	TtkWidgetInstateCommand,0 },
97     { "state",  	TtkWidgetStateCommand,0 },
98     { "style",		TtkWidgetStyleCommand,0 },
99     { 0,0,0 }
100 };
101 
102 static const WidgetSpec SizegripWidgetSpec =
103 {
104     "TSizegrip",		/* className */
105     sizeof(WidgetCore),		/* recordSize */
106     SizegripOptionSpecs, 	/* optionSpecs */
107     SizegripCommands,		/* subcommands */
108     TtkNullInitialize,		/* initializeProc */
109     TtkNullCleanup,		/* cleanupProc */
110     TtkCoreConfigure,		/* configureProc */
111     TtkNullPostConfigure,	/* postConfigureProc */
112     TtkWidgetGetLayout, 	/* getLayoutProc */
113     TtkWidgetSize, 		/* sizeProc */
114     TtkWidgetDoLayout,		/* layoutProc */
115     TtkWidgetDisplay		/* displayProc */
116 };
117 
118 TTK_BEGIN_LAYOUT(SizegripLayout)
119     TTK_NODE("Sizegrip.sizegrip", TTK_PACK_BOTTOM|TTK_STICK_S|TTK_STICK_E)
120 TTK_END_LAYOUT
121 
122 /* +++ Initialization:
123  */
124 
125 MODULE_SCOPE
TtkSeparator_Init(Tcl_Interp * interp)126 void TtkSeparator_Init(Tcl_Interp *interp)
127 {
128     Ttk_Theme theme = Ttk_GetDefaultTheme(interp);
129 
130     Ttk_RegisterLayout(theme, "TSeparator", SeparatorLayout);
131     Ttk_RegisterLayout(theme, "TSizegrip", SizegripLayout);
132 
133     RegisterWidget(interp, "ttk::separator", &SeparatorWidgetSpec);
134     RegisterWidget(interp, "ttk::sizegrip", &SizegripWidgetSpec);
135 }
136 
137 /*EOF*/
138