OSDN Git Service

Please enter the commit message for your changes. Lines starting
[eos/base.git] / util / src / TclTk / tk8.6.12 / generic / ttk / ttkTheme.h
1 /*
2  * Copyright (c) 2003 Joe English.  Freely redistributable.
3  *
4  * Declarations for Tk theme engine.
5  */
6
7 #ifndef _TTKTHEME
8 #define _TTKTHEME
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 #ifndef MODULE_SCOPE
15 #   ifdef __cplusplus
16 #       define MODULE_SCOPE extern "C"
17 #   else
18 #       define MODULE_SCOPE extern
19 #   endif
20 #endif
21
22 #define TTKAPI MODULE_SCOPE
23
24 /* Ttk syncs to the Tk version & patchlevel */
25 #define TTK_VERSION    TK_VERSION
26 #define TTK_PATCH_LEVEL TK_PATCH_LEVEL
27
28 /*------------------------------------------------------------------------
29  * +++ Defaults for element option specifications.
30  */
31 #define DEFAULT_FONT            "TkDefaultFont"
32 #ifdef MAC_OSX_TK
33 #define DEFAULT_BACKGROUND      "systemTextBackgroundColor"
34 #define DEFAULT_FOREGROUND      "systemTextColor"
35 #else
36 #define DEFAULT_BACKGROUND      "#d9d9d9"
37 #define DEFAULT_FOREGROUND      "black"
38 #endif
39 /*------------------------------------------------------------------------
40  * +++ Widget states.
41  *      Keep in sync with stateNames[] in tkstate.c.
42  */
43
44 typedef unsigned int Ttk_State;
45
46 #define TTK_STATE_ACTIVE        (1<<0)
47 #define TTK_STATE_DISABLED      (1<<1)
48 #define TTK_STATE_FOCUS         (1<<2)
49 #define TTK_STATE_PRESSED       (1<<3)
50 #define TTK_STATE_SELECTED      (1<<4)
51 #define TTK_STATE_BACKGROUND    (1<<5)
52 #define TTK_STATE_ALTERNATE     (1<<6)
53 #define TTK_STATE_INVALID       (1<<7)
54 #define TTK_STATE_READONLY      (1<<8)
55 #define TTK_STATE_HOVER         (1<<9)
56 #define TTK_STATE_USER6         (1<<10)
57 #define TTK_STATE_USER5         (1<<11)
58 #define TTK_STATE_USER4         (1<<12)
59 #define TTK_STATE_USER3         (1<<13)
60 #define TTK_STATE_USER2         (1<<14)
61 #define TTK_STATE_USER1         (1<<15)
62
63 /* Maintenance note: if you get all the way to "USER1",
64  * see tkstate.c
65  */
66 typedef struct
67 {
68     unsigned int onbits;        /* bits to turn on */
69     unsigned int offbits;       /* bits to turn off */
70 } Ttk_StateSpec;
71
72 #define Ttk_StateMatches(state, spec) \
73     (((state) & ((spec)->onbits|(spec)->offbits)) == (spec)->onbits)
74
75 #define Ttk_ModifyState(state, spec) \
76     (((state) & ~(spec)->offbits) | (spec)->onbits)
77
78 TTKAPI int Ttk_GetStateSpecFromObj(Tcl_Interp *, Tcl_Obj *, Ttk_StateSpec *);
79 TTKAPI Tcl_Obj *Ttk_NewStateSpecObj(unsigned int onbits,unsigned int offbits);
80
81 /*------------------------------------------------------------------------
82  * +++ State maps and state tables.
83  */
84 typedef Tcl_Obj *Ttk_StateMap;
85
86 TTKAPI Ttk_StateMap Ttk_GetStateMapFromObj(Tcl_Interp *, Tcl_Obj *);
87 TTKAPI Tcl_Obj *Ttk_StateMapLookup(Tcl_Interp*, Ttk_StateMap, Ttk_State);
88
89 /*
90  * Table for looking up an integer index based on widget state:
91  */
92 typedef struct
93 {
94     int index;                  /* Value to return if this entry matches */
95     unsigned int onBits;        /* Bits which must be set */
96     unsigned int offBits;       /* Bits which must be cleared */
97 } Ttk_StateTable;
98
99 TTKAPI int Ttk_StateTableLookup(Ttk_StateTable map[], Ttk_State);
100
101 /*------------------------------------------------------------------------
102  * +++ Padding.
103  *      Used to represent internal padding and borders.
104  */
105 typedef struct
106 {
107     short left;
108     short top;
109     short right;
110     short bottom;
111 } Ttk_Padding;
112
113 TTKAPI int Ttk_GetPaddingFromObj(Tcl_Interp*,Tk_Window,Tcl_Obj*,Ttk_Padding*);
114 TTKAPI int Ttk_GetBorderFromObj(Tcl_Interp*,Tcl_Obj*,Ttk_Padding*);
115
116 TTKAPI Ttk_Padding Ttk_MakePadding(short l, short t, short r, short b);
117 TTKAPI Ttk_Padding Ttk_UniformPadding(short borderWidth);
118 TTKAPI Ttk_Padding Ttk_AddPadding(Ttk_Padding, Ttk_Padding);
119 TTKAPI Ttk_Padding Ttk_RelievePadding(Ttk_Padding, int relief, int n);
120
121 #define Ttk_PaddingWidth(p) ((p).left + (p).right)
122 #define Ttk_PaddingHeight(p) ((p).top + (p).bottom)
123
124 #define Ttk_SetMargins(tkwin, pad) \
125     Tk_SetInternalBorderEx(tkwin, pad.left, pad.right, pad.top, pad.bottom)
126
127 /*------------------------------------------------------------------------
128  * +++ Boxes.
129  *      Used to represent rectangular regions
130  */
131 typedef struct  /* Hey, this is an XRectangle! */
132 {
133     int x;
134     int y;
135     int width;
136     int height;
137 } Ttk_Box;
138
139 TTKAPI Ttk_Box Ttk_MakeBox(int x, int y, int width, int height);
140 TTKAPI int Ttk_BoxContains(Ttk_Box, int x, int y);
141
142 #define Ttk_WinBox(tkwin) Ttk_MakeBox(0,0,Tk_Width(tkwin),Tk_Height(tkwin))
143
144 /*------------------------------------------------------------------------
145  * +++ Layout utilities.
146  */
147 typedef enum {
148     TTK_SIDE_LEFT, TTK_SIDE_TOP, TTK_SIDE_RIGHT, TTK_SIDE_BOTTOM
149 } Ttk_Side;
150
151 typedef unsigned int Ttk_Sticky;
152
153 /*
154  * -sticky bits for Ttk_StickBox:
155  */
156 #define TTK_STICK_W     (0x1)
157 #define TTK_STICK_E     (0x2)
158 #define TTK_STICK_N     (0x4)
159 #define TTK_STICK_S     (0x8)
160
161 /*
162  * Aliases and useful combinations:
163  */
164 #define TTK_FILL_X      (0x3)   /* -sticky ew */
165 #define TTK_FILL_Y      (0xC)   /* -sticky ns */
166 #define TTK_FILL_BOTH   (0xF)   /* -sticky nswe */
167
168 TTKAPI int Ttk_GetStickyFromObj(Tcl_Interp *, Tcl_Obj *, Ttk_Sticky *);
169 TTKAPI Tcl_Obj *Ttk_NewStickyObj(Ttk_Sticky);
170
171 /*
172  * Extra bits for position specifications (combine -side and -sticky)
173  */
174
175 typedef unsigned int Ttk_PositionSpec;  /* See below */
176
177 #define TTK_PACK_LEFT   (0x10)  /* pack at left of current parcel */
178 #define TTK_PACK_RIGHT  (0x20)  /* pack at right of current parcel */
179 #define TTK_PACK_TOP    (0x40)  /* pack at top of current parcel */
180 #define TTK_PACK_BOTTOM (0x80)  /* pack at bottom of current parcel */
181 #define TTK_EXPAND      (0x100) /* use entire parcel */
182 #define TTK_BORDER      (0x200) /* draw this element after children */
183 #define TTK_UNIT        (0x400) /* treat descendants as a part of element */
184
185 /*
186  * Extra bits for layout specifications
187  */
188 #define _TTK_CHILDREN   (0x1000)/* for LayoutSpecs -- children follow */
189 #define _TTK_LAYOUT_END (0x2000)/* for LayoutSpecs -- end of child list */
190 #define _TTK_LAYOUT     (0x4000)/* for LayoutSpec tables -- define layout */
191
192 #define _TTK_MASK_STICK (0x0F)  /* See Ttk_UnparseLayout() */
193 #define _TTK_MASK_PACK  (0xF0)  /* See Ttk_UnparseLayout(), packStrings */
194
195 TTKAPI Ttk_Box Ttk_PackBox(Ttk_Box *cavity, int w, int h, Ttk_Side side);
196 TTKAPI Ttk_Box Ttk_StickBox(Ttk_Box parcel, int w, int h, Ttk_Sticky sticky);
197 TTKAPI Ttk_Box Ttk_AnchorBox(Ttk_Box parcel, int w, int h, Tk_Anchor anchor);
198 TTKAPI Ttk_Box Ttk_PadBox(Ttk_Box b, Ttk_Padding p);
199 TTKAPI Ttk_Box Ttk_ExpandBox(Ttk_Box b, Ttk_Padding p);
200 TTKAPI Ttk_Box Ttk_PlaceBox(Ttk_Box *cavity, int w,int h, Ttk_Side,Ttk_Sticky);
201 TTKAPI Ttk_Box Ttk_PositionBox(Ttk_Box *cavity, int w, int h, Ttk_PositionSpec);
202
203 /*------------------------------------------------------------------------
204  * +++ Themes.
205  */
206 MODULE_SCOPE void Ttk_StylePkgInit(Tcl_Interp *);
207
208 typedef struct Ttk_Theme_ *Ttk_Theme;
209 typedef struct Ttk_ElementClass_ Ttk_ElementClass;
210 typedef struct Ttk_Layout_ *Ttk_Layout;
211 typedef struct Ttk_LayoutNode_ *Ttk_Element;
212 typedef struct Ttk_Style_ *Ttk_Style;
213
214 TTKAPI Ttk_Theme Ttk_GetTheme(Tcl_Interp *interp, const char *name);
215 TTKAPI Ttk_Theme Ttk_GetDefaultTheme(Tcl_Interp *interp);
216 TTKAPI Ttk_Theme Ttk_GetCurrentTheme(Tcl_Interp *interp);
217
218 TTKAPI Ttk_Theme Ttk_CreateTheme(
219     Tcl_Interp *interp, const char *name, Ttk_Theme parent);
220
221 typedef int (Ttk_ThemeEnabledProc)(Ttk_Theme theme, void *clientData);
222 MODULE_SCOPE void Ttk_SetThemeEnabledProc(Ttk_Theme, Ttk_ThemeEnabledProc, void *);
223
224 MODULE_SCOPE int Ttk_UseTheme(Tcl_Interp *, Ttk_Theme);
225
226 typedef void (Ttk_CleanupProc)(void *clientData);
227 TTKAPI void Ttk_RegisterCleanup(
228     Tcl_Interp *interp, void *deleteData, Ttk_CleanupProc *cleanupProc);
229
230 /*------------------------------------------------------------------------
231  * +++ Elements.
232  */
233
234 enum TTKStyleVersion2 { TK_STYLE_VERSION_2 = 2 };
235
236 typedef void (Ttk_ElementSizeProc)(void *clientData, void *elementRecord,
237         Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding*);
238 typedef void (Ttk_ElementDrawProc)(void *clientData, void *elementRecord,
239         Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state);
240
241 typedef struct Ttk_ElementOptionSpec
242 {
243     const char *optionName;             /* Command-line name of the widget option */
244     Tk_OptionType type;         /* Accepted option types */
245     int offset;                 /* Offset of Tcl_Obj* field in element record */
246     const char *defaultValue;           /* Default value to used if resource missing */
247 } Ttk_ElementOptionSpec;
248
249 #define TK_OPTION_ANY TK_OPTION_STRING
250
251 typedef struct Ttk_ElementSpec {
252     enum TTKStyleVersion2 version;      /* Version of the style support. */
253     size_t elementSize;                 /* Size of element record */
254     Ttk_ElementOptionSpec *options;     /* List of options, NULL-terminated */
255     Ttk_ElementSizeProc *size;          /* Compute min size and padding */
256     Ttk_ElementDrawProc *draw;          /* Draw the element */
257 } Ttk_ElementSpec;
258
259 TTKAPI Ttk_ElementClass *Ttk_RegisterElement(
260         Tcl_Interp *interp, Ttk_Theme theme, const char *elementName,
261         Ttk_ElementSpec *, void *clientData);
262
263 typedef int (*Ttk_ElementFactory)
264         (Tcl_Interp *, void *clientData,
265          Ttk_Theme, const char *elementName, int objc, Tcl_Obj *const objv[]);
266
267 TTKAPI int Ttk_RegisterElementFactory(
268         Tcl_Interp *, const char *name, Ttk_ElementFactory, void *clientData);
269
270 /*
271  * Null element implementation:
272  * has no geometry or layout; may be used as a stub or placeholder.
273  */
274
275 typedef struct {
276     Tcl_Obj     *unused;
277 } NullElement;
278
279 MODULE_SCOPE void TtkNullElementSize
280         (void *, void *, Tk_Window, int *, int *, Ttk_Padding *);
281 MODULE_SCOPE void TtkNullElementDraw
282         (void *, void *, Tk_Window, Drawable, Ttk_Box, Ttk_State);
283 MODULE_SCOPE Ttk_ElementOptionSpec TtkNullElementOptions[];
284 MODULE_SCOPE Ttk_ElementSpec ttkNullElementSpec;
285
286 /*------------------------------------------------------------------------
287  * +++ Layout templates.
288  */
289 typedef struct {
290     const char *        elementName;
291     unsigned            opcode;
292 } TTKLayoutInstruction, *Ttk_LayoutSpec;
293
294 #define TTK_BEGIN_LAYOUT_TABLE(name) \
295                                 static TTKLayoutInstruction name[] = {
296 #define TTK_LAYOUT(name, content) \
297                                 { name, _TTK_CHILDREN|_TTK_LAYOUT }, \
298                                 content \
299                                 { 0, _TTK_LAYOUT_END },
300 #define TTK_GROUP(name, flags, children) \
301                                 { name, flags | _TTK_CHILDREN }, \
302                                 children \
303                                 { 0, _TTK_LAYOUT_END },
304 #define TTK_NODE(name, flags)   { name, flags },
305 #define TTK_END_LAYOUT_TABLE    { 0, _TTK_LAYOUT | _TTK_LAYOUT_END } };
306
307 #define TTK_BEGIN_LAYOUT(name)  static TTKLayoutInstruction name[] = {
308 #define TTK_END_LAYOUT          { 0, _TTK_LAYOUT_END } };
309
310 TTKAPI void Ttk_RegisterLayout(
311     Ttk_Theme theme, const char *className, Ttk_LayoutSpec layoutSpec);
312
313 TTKAPI void Ttk_RegisterLayouts(
314     Ttk_Theme theme, Ttk_LayoutSpec layoutTable);
315
316 /*------------------------------------------------------------------------
317  * +++ Layout instances.
318  */
319
320 MODULE_SCOPE Ttk_Layout Ttk_CreateLayout(
321     Tcl_Interp *, Ttk_Theme, const char *name,
322     void *recordPtr, Tk_OptionTable, Tk_Window tkwin);
323
324 MODULE_SCOPE Ttk_Layout Ttk_CreateSublayout(
325     Tcl_Interp *, Ttk_Theme, Ttk_Layout, const char *name, Tk_OptionTable);
326
327 MODULE_SCOPE void Ttk_FreeLayout(Ttk_Layout);
328
329 MODULE_SCOPE void Ttk_LayoutSize(Ttk_Layout,Ttk_State,int *widthPtr,int *heightPtr);
330 MODULE_SCOPE void Ttk_PlaceLayout(Ttk_Layout, Ttk_State, Ttk_Box);
331 MODULE_SCOPE void Ttk_DrawLayout(Ttk_Layout, Ttk_State, Drawable);
332
333 MODULE_SCOPE void Ttk_RebindSublayout(Ttk_Layout, void *recordPtr);
334
335 MODULE_SCOPE Ttk_Element Ttk_IdentifyElement(Ttk_Layout, int x, int y);
336 MODULE_SCOPE Ttk_Element Ttk_FindElement(Ttk_Layout, const char *nodeName);
337
338 MODULE_SCOPE const char *Ttk_ElementName(Ttk_Element);
339 MODULE_SCOPE Ttk_Box Ttk_ElementParcel(Ttk_Element);
340
341 MODULE_SCOPE Ttk_Box Ttk_ClientRegion(Ttk_Layout, const char *elementName);
342
343 MODULE_SCOPE Ttk_Box Ttk_LayoutNodeInternalParcel(Ttk_Layout,Ttk_Element);
344 MODULE_SCOPE Ttk_Padding Ttk_LayoutNodeInternalPadding(Ttk_Layout,Ttk_Element);
345 MODULE_SCOPE void Ttk_LayoutNodeReqSize(Ttk_Layout, Ttk_Element, int *w, int *h);
346
347 MODULE_SCOPE void Ttk_PlaceElement(Ttk_Layout, Ttk_Element, Ttk_Box);
348 MODULE_SCOPE void Ttk_ChangeElementState(Ttk_Element,unsigned set,unsigned clr);
349
350 MODULE_SCOPE Tcl_Obj *Ttk_QueryOption(Ttk_Layout, const char *, Ttk_State);
351
352 TTKAPI Ttk_Style Ttk_LayoutStyle(Ttk_Layout);
353 TTKAPI Tcl_Obj *Ttk_StyleDefault(Ttk_Style, const char *optionName);
354 TTKAPI Tcl_Obj *Ttk_StyleMap(Ttk_Style, const char *optionName, Ttk_State);
355
356 /*------------------------------------------------------------------------
357  * +++ Resource cache.
358  *      See resource.c for explanation.
359  */
360
361 typedef struct Ttk_ResourceCache_ *Ttk_ResourceCache;
362 MODULE_SCOPE Ttk_ResourceCache Ttk_CreateResourceCache(Tcl_Interp *);
363 MODULE_SCOPE void Ttk_FreeResourceCache(Ttk_ResourceCache);
364
365 MODULE_SCOPE Ttk_ResourceCache Ttk_GetResourceCache(Tcl_Interp*);
366 MODULE_SCOPE Tcl_Obj *Ttk_UseFont(Ttk_ResourceCache, Tk_Window, Tcl_Obj *);
367 MODULE_SCOPE Tcl_Obj *Ttk_UseColor(Ttk_ResourceCache, Tk_Window, Tcl_Obj *);
368 MODULE_SCOPE Tcl_Obj *Ttk_UseBorder(Ttk_ResourceCache, Tk_Window, Tcl_Obj *);
369 MODULE_SCOPE Tk_Image Ttk_UseImage(Ttk_ResourceCache, Tk_Window, Tcl_Obj *);
370
371 MODULE_SCOPE void Ttk_RegisterNamedColor(Ttk_ResourceCache, const char *, XColor *);
372
373 /*------------------------------------------------------------------------
374  * +++ Image specifications.
375  */
376
377 typedef struct TtkImageSpec Ttk_ImageSpec;
378 TTKAPI Ttk_ImageSpec *TtkGetImageSpec(Tcl_Interp *, Tk_Window, Tcl_Obj *);
379 TTKAPI Ttk_ImageSpec *TtkGetImageSpecEx(Tcl_Interp *, Tk_Window, Tcl_Obj *,
380                                         Tk_ImageChangedProc *, ClientData);
381 TTKAPI void TtkFreeImageSpec(Ttk_ImageSpec *);
382 TTKAPI Tk_Image TtkSelectImage(Ttk_ImageSpec *, Ttk_State);
383
384 /*------------------------------------------------------------------------
385  * +++ Miscellaneous enumerations.
386  *      Other stuff that element implementations need to know about.
387  */
388 typedef enum                    /* -default option values */
389 {
390     TTK_BUTTON_DEFAULT_NORMAL,  /* widget defaultable */
391     TTK_BUTTON_DEFAULT_ACTIVE,  /* currently the default widget */
392     TTK_BUTTON_DEFAULT_DISABLED /* not defaultable */
393 } Ttk_ButtonDefaultState;
394
395 TTKAPI int Ttk_GetButtonDefaultStateFromObj(Tcl_Interp *, Tcl_Obj *, int *);
396
397 typedef enum                    /* -compound option values */
398 {
399     TTK_COMPOUND_NONE,          /* image if specified, otherwise text */
400     TTK_COMPOUND_TEXT,          /* text only */
401     TTK_COMPOUND_IMAGE,         /* image only */
402     TTK_COMPOUND_CENTER,        /* text overlays image */
403     TTK_COMPOUND_TOP,           /* image above text */
404     TTK_COMPOUND_BOTTOM,        /* image below text */
405     TTK_COMPOUND_LEFT,          /* image to left of text */
406     TTK_COMPOUND_RIGHT          /* image to right of text */
407 } Ttk_Compound;
408
409 TTKAPI int Ttk_GetCompoundFromObj(Tcl_Interp *, Tcl_Obj *, int *);
410
411 typedef enum {          /* -orient option values */
412     TTK_ORIENT_HORIZONTAL,
413     TTK_ORIENT_VERTICAL
414 } Ttk_Orient;
415
416 /*------------------------------------------------------------------------
417  * +++ Utilities.
418  */
419
420 typedef struct TtkEnsemble {
421     const char *name;                   /* subcommand name */
422     Tcl_ObjCmdProc *command;            /* subcommand implementation, OR: */
423     const struct TtkEnsemble *ensemble; /* subcommand ensemble */
424 } Ttk_Ensemble;
425
426 MODULE_SCOPE int Ttk_InvokeEnsemble(    /* Run an ensemble command */
427     const Ttk_Ensemble *commands, int cmdIndex,
428     void *clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
429
430 MODULE_SCOPE int TtkEnumerateHashTable(Tcl_Interp *, Tcl_HashTable *);
431
432 /*------------------------------------------------------------------------
433  * +++ Stub table declarations.
434  */
435
436 #include "ttkDecls.h"
437
438 /*
439  * Drawing utilities for theme code:
440  * (@@@ find a better home for this)
441  */
442 typedef enum { ARROW_UP, ARROW_DOWN, ARROW_LEFT, ARROW_RIGHT } ArrowDirection;
443 MODULE_SCOPE void TtkArrowSize(int h, ArrowDirection, int *widthPtr, int *heightPtr);
444 MODULE_SCOPE void TtkDrawArrow(Display *, Drawable, GC, Ttk_Box, ArrowDirection);
445 MODULE_SCOPE void TtkFillArrow(Display *, Drawable, GC, Ttk_Box, ArrowDirection);
446
447 #ifdef __cplusplus
448 }
449 #endif
450 #endif /* _TTKTHEME */