Unnamed Fossil Project

Check-in [d99a640db0]
Login

Check-in [d99a640db0]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:generic/layout.c: Changed layout specification internals.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: d99a640db0ce8a7ec407ac880dc2bf9a8eb2de1647aceff230fa0afc5dc7d5d1
User & Date: jenglish 2003-10-21 00:53:56.000
Context
2003-10-21
02:13
Added [scrollbar elementstate] command; "pressed / !pressed" feedback for individual scrollbar elements. check-in: bc2de21276 user: jenglish tags: master, trunk
00:53
generic/layout.c: Changed layout specification internals. check-in: d99a640db0 user: jenglish tags: master, trunk
2003-10-20
22:34
* generic/altTheme.c: Implemented a Highlight element to allow * generic/tkElements.c: placing the highlight in different parts * library/tile.tcl: of the layout. check-in: 74052e64ce user: patthoyts tags: master, trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to ChangeLog.




1
2
3
4
5
6
7




2003-10-20  Joe English  <jenglish@users.sourceforge.net>
	* generic/layout.c: Quick and dirty hack to layout engine
	to overcome fundamental design flaws.  More comprehensive
	fix forthcoming...

2003-10-20  Pat Thoyts  <patthoyts@users.sourceforge.net>

>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
2003-10-20  Joe English  <jenglish@users.sourceforge.net>
	* generic/layout.c: Changed layout specification internals.
	This is still Not Quite Right, but closer now.

2003-10-20  Joe English  <jenglish@users.sourceforge.net>
	* generic/layout.c: Quick and dirty hack to layout engine
	to overcome fundamental design flaws.  More comprehensive
	fix forthcoming...

2003-10-20  Pat Thoyts  <patthoyts@users.sourceforge.net>

Changes to generic/Makefile.in.
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

### Build stuff section.
#

.SUFFIXES: .c .@OBJEXT@

.c.@OBJEXT@:
	@$(CC) $(CFLAGS) $(DEFS) $(INCLUDES) -c $< -o $@

$(tile_LIB_FILE): $(tile_OBJECTS)
	-rm -f $(tile_LIB_FILE)
	$(SHLIB_LD) @SHLIB_LD_OUT@$@ $(SHLIB_LDFLAGS) \
		$(tile_OBJECTS) $(tile_LIBRARIES) $(SHLIB_LD_LIBS) \
		$(TCL_STUB_LIB_SPEC) $(TK_STUB_LIB_SPEC) $(TK_LIB_SPEC)








|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

### Build stuff section.
#

.SUFFIXES: .c .@OBJEXT@

.c.@OBJEXT@:
	$(CC) $(CFLAGS) $(DEFS) $(INCLUDES) -c $< -o $@

$(tile_LIB_FILE): $(tile_OBJECTS)
	-rm -f $(tile_LIB_FILE)
	$(SHLIB_LD) @SHLIB_LD_OUT@$@ $(SHLIB_LDFLAGS) \
		$(tile_OBJECTS) $(tile_LIBRARIES) $(SHLIB_LD_LIBS) \
		$(TCL_STUB_LIB_SPEC) $(TK_STUB_LIB_SPEC) $(TK_LIB_SPEC)

Changes to generic/TODO.
1
2
3
4
5
6
7
8


9
10
11
12
13
14
15

@@@ [style configure] -- make sure changes get propagated to ElementImpl's.

@@@ change TTK_LAYOUT_AROUND to TTK_LAYOUT_BORDER; update WidgetGeometry()
   to use TTK_LAYOUT_BORDER-tagged element to set internal padding.

~~ Layout engine:
    + Reimplement; the current design is subtly but fatally flawed.



~~ General:
    + Implement WorldChanged() proc -- handle font (later color) changes.
    + add fallback fallback "null" element 
    + Need per-engine cleanup procedures.
    + Rethink resource allocation (AllocateResource,DeallocateResources)









>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

@@@ [style configure] -- make sure changes get propagated to ElementImpl's.

@@@ change TTK_LAYOUT_AROUND to TTK_LAYOUT_BORDER; update WidgetGeometry()
   to use TTK_LAYOUT_BORDER-tagged element to set internal padding.

~~ Layout engine:
    + Reimplement; the current design is subtly but fatally flawed.
    + Change ElementSpec draw procedure to take a TTK_Box * instead
      of separate x, y, width, height arguments.

~~ General:
    + Implement WorldChanged() proc -- handle font (later color) changes.
    + add fallback fallback "null" element 
    + Need per-engine cleanup procedures.
    + Rethink resource allocation (AllocateResource,DeallocateResources)

Changes to generic/altTheme.c.
1
2
3
4
5
6
7
8
/* $Id: altTheme.c,v 1.6 2003/10/19 18:36:10 jenglish Exp $
 *
 * Copyright (c) 2003, Joe English
 *
 * Tk alternate theme, intended to eventually match the MSUE
 * and GTk's default theme.  (Still have a long way to go...)
 *
 * @@@ I need a good name for this theme.  Calling it "new"
|







1
2
3
4
5
6
7
8
/* $Id: altTheme.c,v 1.7 2003/10/20 22:34:40 patthoyts Exp $
 *
 * Copyright (c) 2003, Joe English
 *
 * Tk alternate theme, intended to eventually match the MSUE
 * and GTk's default theme.  (Still have a long way to go...)
 *
 * @@@ I need a good name for this theme.  Calling it "new"
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
static void
BorderElementDraw(
    void *clientData, void *elementRecord,
    Tk_Window tkwin, Drawable d,
    int x, int y, int width, int height,
    unsigned int state)
{
    int options = *(int*)clientData;
    BorderElement *bd = elementRecord;
    Tk_3DBorder border = NULL;
    int borderWidth = 2, relief = TK_RELIEF_FLAT;
    int defaultState = TK_BUTTON_DEFAULT_DISABLED;
    int inset = 0;
    XColor *extraColor;








<







281
282
283
284
285
286
287

288
289
290
291
292
293
294
static void
BorderElementDraw(
    void *clientData, void *elementRecord,
    Tk_Window tkwin, Drawable d,
    int x, int y, int width, int height,
    unsigned int state)
{

    BorderElement *bd = elementRecord;
    Tk_3DBorder border = NULL;
    int borderWidth = 2, relief = TK_RELIEF_FLAT;
    int defaultState = TK_BUTTON_DEFAULT_DISABLED;
    int inset = 0;
    XColor *extraColor;

857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
    HThumbElementDraw
};

/*------------------------------------------------------------------------
 * Widget layouts:
 */

TK_BEGIN_LAYOUT(TileLayout)
    TK_LAYOUT_DRAW("Tile.background")
    TK_LAYOUT_AROUND("Tile.border",
	TK_LAYOUT_INSIDE("Tile.padding",
            TK_LAYOUT_INSIDE("Tile.highlight",
	        TK_LAYOUT_LEFT("Tile.indicator")
	        TK_LAYOUT_HFILL("Tile.compound"))))
TK_END_LAYOUT

TK_BEGIN_LAYOUT(ButtonLayout)
    TK_LAYOUT_DRAW("Button.background")
    TK_LAYOUT_AROUND("Button.border",
        TK_LAYOUT_AROUND("Button.highlight", 
	    TK_LAYOUT_INSIDE("Button.padding",
	        TK_LAYOUT_HFILL("Button.compound"))))
TK_END_LAYOUT

TK_BEGIN_LAYOUT(CheckbuttonLayout)
    TK_LAYOUT_DRAW("Checkbutton.background")
    TK_LAYOUT_AROUND("Checkbutton.border",
        TK_LAYOUT_INSIDE("Checkbutton.padding",
            TK_LAYOUT_LEFT("Checkbutton.indicator")
            TK_LAYOUT_INSIDE("Checkbutton.highlight",
                TK_LAYOUT_HFILL("Checkbutton.compound"))))
TK_END_LAYOUT

TK_BEGIN_LAYOUT(RadiobuttonLayout)
    TK_LAYOUT_DRAW("Radiobutton.background")
    TK_LAYOUT_AROUND("Radiobutton.border",
        TK_LAYOUT_INSIDE("Radiobutton.padding",
	    TK_LAYOUT_LEFT("Radiobutton.indicator")
            TK_LAYOUT_AROUND("Radiobutton.highlight",
	        TK_LAYOUT_HFILL("Radiobutton.compound"))))
TK_END_LAYOUT

/*------------------------------------------------------------------------
 * AltTheme_Init --
 * 	Install alternate theme.
 */
int AltTheme_Init(Tcl_Interp *interp)
{







|
|
|
|
|
|
|
|

|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|







856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
    HThumbElementDraw
};

/*------------------------------------------------------------------------
 * Widget layouts:
 */

TTK_BEGIN_LAYOUT(TileLayout)
    TTK_LAYOUT_DRAW("Tile.background")
    TTK_LAYOUT_BORDER("Tile.border",
	TTK_LAYOUT_INSIDE("Tile.padding",
            TTK_LAYOUT_INSIDE("Tile.highlight",
	        TTK_LAYOUT_LEFT("Tile.indicator")
	        TTK_LAYOUT_HFILL("Tile.compound"))))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(ButtonLayout)
    TTK_LAYOUT_DRAW("Button.background")
    TTK_LAYOUT_BORDER("Button.border",
        TTK_LAYOUT_INSIDE("Button.highlight", 
	    TTK_LAYOUT_INSIDE("Button.padding",
	        TTK_LAYOUT_HFILL("Button.compound"))))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(CheckbuttonLayout)
    TTK_LAYOUT_DRAW("Checkbutton.background")
    TTK_LAYOUT_BORDER("Checkbutton.border",
        TTK_LAYOUT_INSIDE("Checkbutton.padding",
            TTK_LAYOUT_LEFT("Checkbutton.indicator")
            TTK_LAYOUT_INSIDE("Checkbutton.highlight",
                TTK_LAYOUT_HFILL("Checkbutton.compound"))))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(RadiobuttonLayout)
    TTK_LAYOUT_DRAW("Radiobutton.background")
    TTK_LAYOUT_BORDER("Radiobutton.border",
        TTK_LAYOUT_INSIDE("Radiobutton.padding",
	    TTK_LAYOUT_LEFT("Radiobutton.indicator")
            TTK_LAYOUT_INSIDE("Radiobutton.highlight",
	        TTK_LAYOUT_HFILL("Radiobutton.compound"))))
TTK_END_LAYOUT

/*------------------------------------------------------------------------
 * AltTheme_Init --
 * 	Install alternate theme.
 */
int AltTheme_Init(Tcl_Interp *interp)
{
Changes to generic/layout.c.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * layout.c --
 *
 * Generic layout processing.
 *
 * Copyright (c) 2003 Joe English.  Freely redistributable.
 *
 * $Id: layout.c,v 1.4 2003/10/19 18:36:10 jenglish Exp $
 */

#include <tk.h>
#include "tkTheme.h"

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
 * layout.c --
 *
 * Generic layout processing.
 *
 * Copyright (c) 2003 Joe English.  Freely redistributable.
 *
 * $Id: layout.c,v 1.5 2003/10/20 20:33:37 jenglish Exp $
 */

#include <tk.h>
#include "tkTheme.h"

#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a < b ? a : b)
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
    *widthPtr = *heightPtr = diameter;
    return diameter;
}

/*
 * adjustPadding --
 * 	Adjust x, y, width and height according to the specified padding.

 */
void adjustPadding(
    TTK_Padding *p, int *xPtr, int *yPtr, int *widthPtr, int *heightPtr)
{
    *xPtr += p->left;
    *yPtr += p->top;
    *widthPtr -= (p->left + p->right);
    *heightPtr -= (p->top + p->bottom);
}

/*
 * Build a layout tree from a layout specification:
 */
static TTK_LayoutNode *NewLayoutNode(
    TTKLayoutOp opcode, TTK_Element element, const char *name)
{
    TTK_LayoutNode *node = (TTK_LayoutNode*)ckalloc(sizeof(TTK_LayoutNode));

    node->opcode = opcode;
    node->element = element;
    node->state = 0u;
    node->name = name;
    node->next = node->child = 0;
    /* parcel uninitialized */

    return node;







>














|



|







138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
    *widthPtr = *heightPtr = diameter;
    return diameter;
}

/*
 * adjustPadding --
 * 	Adjust x, y, width and height according to the specified padding.
 * 	See also: padBox()
 */
void adjustPadding(
    TTK_Padding *p, int *xPtr, int *yPtr, int *widthPtr, int *heightPtr)
{
    *xPtr += p->left;
    *yPtr += p->top;
    *widthPtr -= (p->left + p->right);
    *heightPtr -= (p->top + p->bottom);
}

/*
 * Build a layout tree from a layout specification:
 */
static TTK_LayoutNode *NewLayoutNode(
    unsigned pack, TTK_Element element, const char *name)
{
    TTK_LayoutNode *node = (TTK_LayoutNode*)ckalloc(sizeof(TTK_LayoutNode));

    node->pack = pack;
    node->element = element;
    node->state = 0u;
    node->name = name;
    node->next = node->child = 0;
    /* parcel uninitialized */

    return node;
185
186
187
188
189
190
191
192
193


194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285

286
287
288
289
290

291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316

317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340

341




342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358

359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
TTK_BuildLayout(
    TTK_LayoutSpec spec,
    TTK_Theme theme,
    Tk_OptionTable optionTable)
{
    TTK_LayoutNode *first = 0, *last = 0, *node;

    for ( ; spec->opcode != TTKLayoutEND ; ++spec)
    {


	TTK_Element element = 
	    TTK_GetElement(theme, spec->elementName, optionTable);
	if (!element) continue;	/* @@@ error? */

	node = NewLayoutNode(spec->opcode, element, spec->elementName);

	if (last) {
	    last->next = node;
	    last = node;
	} else {
	    last = first = node;
	}

	switch (spec->opcode) {
	    case TTKLayoutINSIDE:
	    case TTKLayoutAROUND:
		node->child = TTK_BuildLayout(spec+1, theme, optionTable);
		while (spec->opcode != TTKLayoutEND)
		    ++spec;
		break;

	    case TTKLayoutHFILL:
	    case TTKLayoutVFILL:
	    case TTKLayoutDRAW:
	    case TTKLayoutTOP:
	    case TTKLayoutLEFT:
	    case TTKLayoutBOTTOM:
	    case TTKLayoutRIGHT:
		break;

	    case TTKLayoutEND:
		/* can't happen */
		break;
	}
    } /* for */

    return first;
}

/*
 * TTK_LayoutReqSize --
 * 	Compute minimum requested width & height of a layout tree
 */
void TTK_LayoutReqSize(
    TTK_Layout layout,
    char *recordPtr,
    Tk_Window tkwin,
    int *widthPtr,
    int *heightPtr)
{
    int width = 0, height = 0;
    unsigned int orient = 0x3;	/* @@@ Quick hack */ 

    for ( ; layout != 0; layout = layout->next)
    {
	int elementWidth, elementHeight;
	TTK_Padding padding;

	TTK_ElementGeometry(layout->element, recordPtr, tkwin, layout->state,
			&elementWidth, &elementHeight, &padding);

	switch (layout->opcode)
	{
	    case TTKLayoutDRAW:
		width = MAX(elementWidth, width);
		height = MAX(elementHeight, height);
		break;
	    case TTKLayoutTOP:
	    case TTKLayoutBOTTOM:
	    case TTKLayoutVFILL:
		orient = 0x1;
		width = MAX(width, elementWidth);
		height += elementHeight;
		break;
	    case TTKLayoutLEFT:
	    case TTKLayoutRIGHT:
	    case TTKLayoutHFILL:
		orient = 0x2;
		width += elementWidth;
		height = MAX(height, elementHeight);
		break;
	    case TTKLayoutAROUND:
	    case TTKLayoutINSIDE:
	    {
		int subWidth = 0, subHeight = 0;
		TTK_LayoutReqSize(layout->child, recordPtr, tkwin,
			&subWidth, &subHeight);

		subWidth += padding.left + padding.right;
		subHeight += padding.top + padding.bottom;

		if (orient & 0x1)

		    height += subHeight;
	    	else
		    height = MAX(height, subHeight);

		if (orient & 0x2)

		    width += subWidth;
	    	else
		    width = MAX(width, subWidth);

		break;
	    }
	    case TTKLayoutEND:
		/* can't happen */
		break;
	}
    }
    *widthPtr = width;
    *heightPtr = height;
}

void TTK_LayoutGeometry(TTK_Layout layout,
	char *recordPtr, Tk_Window tkwin, 
	int x, int y, int width, int height, unsigned int state)
{
    TTK_Box cavity = makeBox(x, y, width, height);

    for ( ; layout; layout = layout->next)
    {
	int elementWidth, elementHeight;
	TTK_Padding padding;


	TTK_ElementGeometry(layout->element, recordPtr, tkwin, state,
		    &elementWidth, &elementHeight, &padding);

	switch (layout->opcode)
	{
	    case TTKLayoutHFILL:
	    case TTKLayoutVFILL:
	    case TTKLayoutDRAW:
		layout->parcel = cavity;
		break;
	    case TTKLayoutTOP:
		layout->parcel = packTop(&cavity, elementHeight);
		break;
	    case TTKLayoutLEFT:
		layout->parcel = packLeft(&cavity, elementWidth);
		break;
	    case TTKLayoutBOTTOM:
		layout->parcel = packBottom(&cavity, elementHeight);
		break;
	    case TTKLayoutRIGHT:
		layout->parcel = packRight(&cavity, elementWidth);
		break;
	    case TTKLayoutAROUND:
	    case TTKLayoutINSIDE:

		layout->parcel = cavity;




		cavity = padBox(cavity, padding);
		TTK_LayoutGeometry(layout->child,recordPtr,tkwin,
			cavity.x, cavity.y, cavity.w, cavity.h, state);
		continue;
	    case TTKLayoutEND:
		/* can't happen */
		break;
	}
    }
}

void TTK_LayoutDraw(
    TTK_Layout layout, char *recordPtr, Tk_Window tkwin,
    Drawable d, unsigned int state)
{
    for (; layout ; layout = layout->next) 
    {

	if (layout->child && layout->opcode == TTKLayoutAROUND)
	    TTK_LayoutDraw(layout->child, recordPtr, tkwin, d, state);

	TTK_DrawElement(layout->element, recordPtr, tkwin, d,
		layout->parcel.x, layout->parcel.y, 
		layout->parcel.w, layout->parcel.h, 
		state);

	if (layout->child && layout->opcode != TTKLayoutAROUND)
	    TTK_LayoutDraw(layout->child, recordPtr, tkwin, d, state);
    }
}

TTK_LayoutNode *TTK_LayoutIdentify(TTK_Layout layout, int x, int y)
{
    TTK_LayoutNode *closest = NULL;







|

>
>
|
|
|

|

|
|
|
|
|
|
|
|
|
<
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<


















<




|


|

|

<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
|
|

|
|
|
|
>
|
|
|
|
|
>
|
|
|
<
<
<
<
<
<

















>



|

<
<
<
<
<
|


|


|


|


<
<
>

>
>
>
>
|
|
|
<
<
<
<










>
|







|







186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

212
213
214
215













216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233

234
235
236
237
238
239
240
241
242
243
244


245

















246

247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263






264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286





287
288
289
290
291
292
293
294
295
296
297
298


299
300
301
302
303
304
305
306
307




308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
TTK_BuildLayout(
    TTK_LayoutSpec spec,
    TTK_Theme theme,
    Tk_OptionTable optionTable)
{
    TTK_LayoutNode *first = 0, *last = 0, *node;

    for ( ; spec->opcode != TTKLAYOUT_END ; ++spec)
    {
	if (spec->elementName) 
	{
	    TTK_Element element = 
		TTK_GetElement(theme, spec->elementName, optionTable);
	    if (!element) continue;	/* @@@ error? OOPS: this will crash. */

	    node = NewLayoutNode(spec->opcode, element, spec->elementName);

	    if (last) {
		last->next = node;
		last = node;
	    } else {
		last = first = node;
	    }
	} 

	if (spec->opcode & TTKLAYOUT_CHILDREN) {

	    last->child = TTK_BuildLayout(spec+1, theme, optionTable);
	    while (spec->opcode != TTKLAYOUT_END)
		++spec;
	    break;













	}
    } /* for */

    return first;
}

/*
 * TTK_LayoutReqSize --
 * 	Compute minimum requested width & height of a layout tree
 */
void TTK_LayoutReqSize(
    TTK_Layout layout,
    char *recordPtr,
    Tk_Window tkwin,
    int *widthPtr,
    int *heightPtr)
{
    int width = 0, height = 0;


    for ( ; layout != 0; layout = layout->next)
    {
	int elementWidth, elementHeight;
	TTK_Padding elementPadding;

	TTK_ElementGeometry(layout->element, recordPtr, tkwin, layout->state,
			&elementWidth, &elementHeight, &elementPadding);

	if (layout->child) 
	{


	    int subWidth = 0, subHeight = 0;



















	    TTK_LayoutReqSize(layout->child, recordPtr, tkwin,
		    &subWidth, &subHeight);

	    elementWidth = subWidth+elementPadding.left+elementPadding.right;
	    elementHeight = subHeight+elementPadding.top+elementPadding.bottom;
	}

	if (layout->pack & TTKLAYOUT_VFILL) {
	    height += elementHeight;
	} else {
	    height = MAX(height, elementHeight);
	}

	if (layout->pack & TTKLAYOUT_HFILL) {
	    width += elementWidth;
	} else {
	    width = MAX(width, elementWidth);






	}
    }
    *widthPtr = width;
    *heightPtr = height;
}

void TTK_LayoutGeometry(TTK_Layout layout,
	char *recordPtr, Tk_Window tkwin, 
	int x, int y, int width, int height, unsigned int state)
{
    TTK_Box cavity = makeBox(x, y, width, height);

    for ( ; layout; layout = layout->next)
    {
	int elementWidth, elementHeight;
	TTK_Padding padding;

	/* @@@ Does not account for child nodes: */
	TTK_ElementGeometry(layout->element, recordPtr, tkwin, state,
		    &elementWidth, &elementHeight, &padding);

	switch (layout->pack)
	{





	    case TTKLAYOUT_TOP:
		layout->parcel = packTop(&cavity, elementHeight);
		break;
	    case TTKLAYOUT_LEFT:
		layout->parcel = packLeft(&cavity, elementWidth);
		break;
	    case TTKLAYOUT_BOTTOM:
		layout->parcel = packBottom(&cavity, elementHeight);
		break;
	    case TTKLAYOUT_RIGHT:
		layout->parcel = packRight(&cavity, elementWidth);
		break;


	    default:
		layout->parcel = cavity;
		break;
	}

	if (layout->child) {
	    cavity = padBox(cavity, padding);
	    TTK_LayoutGeometry(layout->child,recordPtr,tkwin,
		    cavity.x, cavity.y, cavity.w, cavity.h, state);




	}
    }
}

void TTK_LayoutDraw(
    TTK_Layout layout, char *recordPtr, Tk_Window tkwin,
    Drawable d, unsigned int state)
{
    for (; layout ; layout = layout->next) 
    {
	int border = layout->pack & TTKLAYOUT_BORDER;
	if (layout->child && border)
	    TTK_LayoutDraw(layout->child, recordPtr, tkwin, d, state);

	TTK_DrawElement(layout->element, recordPtr, tkwin, d,
		layout->parcel.x, layout->parcel.y, 
		layout->parcel.w, layout->parcel.h, 
		state);

	if (layout->child && !border)
	    TTK_LayoutDraw(layout->child, recordPtr, tkwin, d, state);
    }
}

TTK_LayoutNode *TTK_LayoutIdentify(TTK_Layout layout, int x, int y)
{
    TTK_LayoutNode *closest = NULL;
Changes to generic/stepTheme.c.
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* ----------------------------------------------------------------------
 *
 * Widget specifications
 *
 * ----------------------------------------------------------------------
 */

TK_BEGIN_LAYOUT(VerticalStepScrollbarLayout)
    TK_LAYOUT_DRAW("Scrollbar.background")
    TK_LAYOUT_AROUND("Scrollbar.border",
	TK_LAYOUT_DRAW("Scrollbar.trough")
	TK_LAYOUT_BOTTOM("Scrollbar.downarrow")
	TK_LAYOUT_BOTTOM("Scrollbar.uparrow")
	TK_LAYOUT_VFILL("Scrollbar.vthumb")   )
TK_END_LAYOUT

TK_BEGIN_LAYOUT(HorizontalStepScrollbarLayout)
    TK_LAYOUT_DRAW("Scrollbar.background")
    TK_LAYOUT_AROUND("Scrollbar.border",
	TK_LAYOUT_DRAW("Scrollbar.trough")
	TK_LAYOUT_RIGHT("Scrollbar.rightarrow")
	TK_LAYOUT_RIGHT("Scrollbar.leftarrow")
	TK_LAYOUT_HFILL("Scrollbar.hthumb")   )
TK_END_LAYOUT


int DLLEXPORT
StepTheme_Init(Tcl_Interp *interp)
{
    TTK_Theme themePtr = NULL;








|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|







139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* ----------------------------------------------------------------------
 *
 * Widget specifications
 *
 * ----------------------------------------------------------------------
 */

TTK_BEGIN_LAYOUT(VerticalStepScrollbarLayout)
    TTK_LAYOUT_DRAW("Scrollbar.background")
    TTK_LAYOUT_BORDER("Scrollbar.border",
	TTK_LAYOUT_DRAW("Scrollbar.trough")
	TTK_LAYOUT_BOTTOM("Scrollbar.downarrow")
	TTK_LAYOUT_BOTTOM("Scrollbar.uparrow")
	TTK_LAYOUT_VFILL("Scrollbar.vthumb")   )
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(HorizontalStepScrollbarLayout)
    TTK_LAYOUT_DRAW("Scrollbar.background")
    TTK_LAYOUT_BORDER("Scrollbar.border",
	TTK_LAYOUT_DRAW("Scrollbar.trough")
	TTK_LAYOUT_RIGHT("Scrollbar.rightarrow")
	TTK_LAYOUT_RIGHT("Scrollbar.leftarrow")
	TTK_LAYOUT_HFILL("Scrollbar.hthumb")   )
TTK_END_LAYOUT


int DLLEXPORT
StepTheme_Init(Tcl_Interp *interp)
{
    TTK_Theme themePtr = NULL;

Changes to generic/tkElements.c.
1
2
3
4
5
6
7
8
/* $Id: tkElements.c,v 1.7 2003/10/19 18:36:10 jenglish Exp $
 *
 * Copyright (c) 2003, Joe English
 *
 * Default implementation for themed elements.
 *
 * Implements the "classic" Motif-like Tk look.
 * Also provides default fallback elements for other themes.
|







1
2
3
4
5
6
7
8
/* $Id: tkElements.c,v 1.8 2003/10/20 22:34:40 patthoyts Exp $
 *
 * Copyright (c) 2003, Joe English
 *
 * Default implementation for themed elements.
 *
 * Implements the "classic" Motif-like Tk look.
 * Also provides default fallback elements for other themes.
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409


1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
    HThumbElementDraw
};

/*------------------------------------------------------------------------
 * Layouts:
 */

TK_BEGIN_LAYOUT(TileLayout)
    TK_LAYOUT_DRAW("Tile.background")
    TK_LAYOUT_DRAW("Tile.border")
TK_END_LAYOUT

TK_BEGIN_LAYOUT(ButtonLayout)
    TK_LAYOUT_DRAW("Button.background")
    TK_LAYOUT_AROUND("Button.highlight", 
        TK_LAYOUT_AROUND("Button.border",
	    TK_LAYOUT_INSIDE("Button.padding",
	        TK_LAYOUT_HFILL("Button.compound"))))
TK_END_LAYOUT

TK_BEGIN_LAYOUT(CheckbuttonLayout)
    TK_LAYOUT_DRAW("Checkbutton.background")
    TK_LAYOUT_AROUND("Checkbutton.highlight",
        TK_LAYOUT_AROUND("Checkbutton.border",
	    TK_LAYOUT_INSIDE("Checkbutton.padding",
	        TK_LAYOUT_LEFT("Checkbutton.indicator")
	        TK_LAYOUT_HFILL("Checkbutton.compound"))))
TK_END_LAYOUT

TK_BEGIN_LAYOUT(RadiobuttonLayout)
    TK_LAYOUT_DRAW("Radiobutton.background")
    TK_LAYOUT_AROUND("Radiobutton.highlight",
        TK_LAYOUT_AROUND("Radiobutton.border",


            TK_LAYOUT_INSIDE("Radiobutton.padding",
	        TK_LAYOUT_LEFT("Radiobutton.indicator")
	        TK_LAYOUT_HFILL("Radiobutton.compound"))))
TK_END_LAYOUT

TK_BEGIN_LAYOUT(VerticalScrollbarLayout)
    TK_LAYOUT_DRAW("Scrollbar.background")
    TK_LAYOUT_AROUND("Scrollbar.border",
	TK_LAYOUT_DRAW("Scrollbar.trough")
	TK_LAYOUT_TOP("Scrollbar.uparrow")
	TK_LAYOUT_BOTTOM("Scrollbar.downarrow")
	TK_LAYOUT_VFILL("Scrollbar.vthumb")   )
TK_END_LAYOUT

TK_BEGIN_LAYOUT(HorizontalScrollbarLayout)
    TK_LAYOUT_DRAW("Scrollbar.background")
    TK_LAYOUT_AROUND("Scrollbar.border",
	TK_LAYOUT_DRAW("Scrollbar.trough")
	TK_LAYOUT_LEFT("Scrollbar.leftarrow")
	TK_LAYOUT_RIGHT("Scrollbar.rightarrow")
	TK_LAYOUT_HFILL("Scrollbar.hthumb")   )
TK_END_LAYOUT

/*----------------------------------------------------------------------
 * RegisterElements --
 *
 *	Register all elements and layouts defined in this package.
 */
void RegisterElements(Tcl_Interp *interp)







|
|
|
|

|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
<
<
>
>
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|







1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407


1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
    HThumbElementDraw
};

/*------------------------------------------------------------------------
 * Layouts:
 */

TTK_BEGIN_LAYOUT(TileLayout)
    TTK_LAYOUT_DRAW("Tile.background")
    TTK_LAYOUT_DRAW("Tile.border")
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(ButtonLayout)
    TTK_LAYOUT_DRAW("Button.background")
    TTK_LAYOUT_INSIDE("Button.highlight", 
        TTK_LAYOUT_INSIDE("Button.border",
	    TTK_LAYOUT_INSIDE("Button.padding",
	        TTK_LAYOUT_HFILL("Button.compound"))))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(CheckbuttonLayout)
    TTK_LAYOUT_DRAW("Checkbutton.background")
    TTK_LAYOUT_INSIDE("Checkbutton.highlight",
        TTK_LAYOUT_INSIDE("Checkbutton.border",
	    TTK_LAYOUT_INSIDE("Checkbutton.padding",
	        TTK_LAYOUT_LEFT("Checkbutton.indicator")
	        TTK_LAYOUT_HFILL("Checkbutton.compound"))))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(RadiobuttonLayout)
    TTK_LAYOUT_DRAW("Radiobutton.background")


    TTK_LAYOUT_INSIDE("Radiobutton.highlight",
        TTK_LAYOUT_INSIDE("Radiobutton.border",
            TTK_LAYOUT_INSIDE("Radiobutton.padding",
	        TTK_LAYOUT_LEFT("Radiobutton.indicator")
	        TTK_LAYOUT_HFILL("Radiobutton.compound"))))
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(VerticalScrollbarLayout)
    TTK_LAYOUT_DRAW("Scrollbar.background")
    TTK_LAYOUT_BORDER("Scrollbar.border",
	TTK_LAYOUT_DRAW("Scrollbar.trough")
	TTK_LAYOUT_TOP("Scrollbar.uparrow")
	TTK_LAYOUT_BOTTOM("Scrollbar.downarrow")
	TTK_LAYOUT_VFILL("Scrollbar.vthumb")   )
TTK_END_LAYOUT

TTK_BEGIN_LAYOUT(HorizontalScrollbarLayout)
    TTK_LAYOUT_DRAW("Scrollbar.background")
    TTK_LAYOUT_BORDER("Scrollbar.border",
	TTK_LAYOUT_DRAW("Scrollbar.trough")
	TTK_LAYOUT_LEFT("Scrollbar.leftarrow")
	TTK_LAYOUT_RIGHT("Scrollbar.rightarrow")
	TTK_LAYOUT_HFILL("Scrollbar.hthumb")   )
TTK_END_LAYOUT

/*----------------------------------------------------------------------
 * RegisterElements --
 *
 *	Register all elements and layouts defined in this package.
 */
void RegisterElements(Tcl_Interp *interp)
Changes to generic/tkTheme.h.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
 * tkTheme.h --
 *      Declarations for Tk style engine.
 *
 * Copyright (c) 2003 Joe English.  Freely redistributable.
 *
 * $Id: tkTheme.h,v 1.8 2003/10/19 18:13:08 jenglish Exp $
 */

#ifndef TKTHEME_H
#define TKTHEME_H 1

#ifndef WIN32
#define NO_PRIVATE_HEADERS 1






|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
 * tkTheme.h --
 *      Declarations for Tk style engine.
 *
 * Copyright (c) 2003 Joe English.  Freely redistributable.
 *
 * $Id: tkTheme.h,v 1.9 2003/10/19 18:36:10 jenglish Exp $
 */

#ifndef TKTHEME_H
#define TKTHEME_H 1

#ifndef WIN32
#define NO_PRIVATE_HEADERS 1
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194


195

196
197
198

199

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215


216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
TTK_RegisterElementSpec(
	TTK_Theme style, const char *elementName,
	TTK_ElementSpec *, void *clientData);

/*
 * Layout specifications:
 */

typedef enum
{
    TTKLayoutDRAW,	/* draw current element; don't adjust parcel */
    TTKLayoutTOP,	/* pack at top of current parcel */
    TTKLayoutLEFT,	/* pack at left of current parcel */
    TTKLayoutBOTTOM,	/* pack at bottom of current parcel */
    TTKLayoutRIGHT,	/* pack at right of current parcel */
    TTKLayoutHFILL,	/* fill remaining parcel, horizontally */


    TTKLayoutVFILL,	/* fill remaining parcel, vertically */

    TTKLayoutINSIDE,	/* subsequent elements drawn inside current element */
    TTKLayoutAROUND,	/* draw this element around subsequent elements */
    TTKLayoutEND,	/* end of INSIDE, AROUND, or overall layout */

} TTKLayoutOp;


typedef struct
{
    TTKLayoutOp		opcode;
    const char *	elementName;
} TTKLayoutInstruction, *TTKLayout, *TTK_LayoutSpec;

#define TK_BEGIN_LAYOUT(name) \
	static TTKLayoutInstruction name[] = {
#define TK_LAYOUT_DRAW(el)  	{ TTKLayoutDRAW, el },
#define TK_LAYOUT_TOP(el)   	{ TTKLayoutTOP, el },
#define TK_LAYOUT_LEFT(el)   	{ TTKLayoutLEFT, el },
#define TK_LAYOUT_BOTTOM(el)   	{ TTKLayoutBOTTOM, el },
#define TK_LAYOUT_RIGHT(el)   	{ TTKLayoutRIGHT, el },
#define TK_LAYOUT_HFILL(el)   	{ TTKLayoutHFILL, el },
#define TK_LAYOUT_VFILL(el)   	{ TTKLayoutVFILL, el },


#define TK_LAYOUT_INSIDE(el, children) \
	{ TTKLayoutINSIDE, el }, children { TTKLayoutEND, 0 },
#define TK_LAYOUT_AROUND(el, children) \
	{ TTKLayoutAROUND, el }, children { TTKLayoutEND, 0 },
#define TK_END_LAYOUT 		{ TTKLayoutEND, 0 } };


/*
 * Layout instances:
 */
typedef struct TTK_LayoutNode_ TTK_LayoutNode, *TTK_Layout;

struct TTK_LayoutNode_
{
    TTKLayoutOp		opcode;
    TTK_Element 	element;
    const char		*name;
    unsigned int 	state;
    TTK_Box 		parcel;
    TTK_LayoutNode	*next, *child;
};








>
|

|
<
|
<
|
|
>
>
|
>
|
<
<
>
|
>



|



|

|
|
|
|
|
|
|
>
>
|
|
|
|
|
<








|







180
181
182
183
184
185
186
187
188
189
190

191

192
193
194
195
196
197
198


199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224

225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
TTK_RegisterElementSpec(
	TTK_Theme style, const char *elementName,
	TTK_ElementSpec *, void *clientData);

/*
 * Layout specifications:
 */

enum 
{
    TTKLAYOUT_DRAW	= 0x0,	/* draw current element; don't adjust parcel */

    TTKLAYOUT_LEFT	= 0x1,	/* pack at left of current parcel */

    TTKLAYOUT_RIGHT	= 0x2,	/* pack at right of current parcel */
    TTKLAYOUT_HFILL	= 0x3,	/* fill remaining parcel, horizontally */
    TTKLAYOUT_TOP	= 0x4,	/* pack at top of current parcel */
    TTKLAYOUT_BOTTOM	= 0x8,	/* pack at bottom of current parcel */
    TTKLAYOUT_VFILL	= 0xC,	/* fill remaining parcel, vertically */
};



#define TTKLAYOUT_CHILDREN	0x10
#define TTKLAYOUT_BORDER	0x20
#define TTKLAYOUT_END 		0xFF

typedef struct
{
    unsigned		opcode;
    const char *	elementName;
} TTKLayoutInstruction, *TTKLayout, *TTK_LayoutSpec;

#define TTK_BEGIN_LAYOUT(name) \
	static TTKLayoutInstruction name[] = {
#define TTK_LAYOUT_DRAW(el)  	{ TTKLAYOUT_DRAW, el },
#define TTK_LAYOUT_TOP(el)   	{ TTKLAYOUT_TOP, el },
#define TTK_LAYOUT_LEFT(el)   	{ TTKLAYOUT_LEFT, el },
#define TTK_LAYOUT_BOTTOM(el)   { TTKLAYOUT_BOTTOM, el },
#define TTK_LAYOUT_RIGHT(el)   	{ TTKLAYOUT_RIGHT, el },
#define TTK_LAYOUT_HFILL(el)   	{ TTKLAYOUT_HFILL, el },
#define TTK_LAYOUT_VFILL(el)   	{ TTKLAYOUT_VFILL, el },
#define TTK_LAYOUT_CHILDREN(children) \
	{ TTKLAYOUT_CHILDREN, 0 }, children { TTKLAYOUT_END },
#define TTK_LAYOUT_INSIDE(el, children) \
	{ TTKLAYOUT_CHILDREN, el }, children { TTKLAYOUT_END },
#define TTK_LAYOUT_BORDER(el, children) \
	{ TTKLAYOUT_BORDER|TTKLAYOUT_CHILDREN, el }, children { TTKLAYOUT_END },
#define TTK_END_LAYOUT 		{ TTKLAYOUT_END, 0 } };


/*
 * Layout instances:
 */
typedef struct TTK_LayoutNode_ TTK_LayoutNode, *TTK_Layout;

struct TTK_LayoutNode_
{
    unsigned		pack;
    TTK_Element 	element;
    const char		*name;
    unsigned int 	state;
    TTK_Box 		parcel;
    TTK_LayoutNode	*next, *child;
};