Unnamed Fossil Project

Diff
Login

Diff

Differences From Artifact [b289fe439c]:

To Artifact [0d4e470da9]:


1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6

7
8
9
10
11
12
13
14






-
+







/*
 * cache.c --
 *      Tile theme engine, resource cache.
 *
 * Copyright (c) 2004, Joe English
 *
 * $Id: cache.c,v 1.4 2004/02/18 22:16:24 jenglish Exp $
 * $Id: cache.c,v 1.5 2004/02/23 01:30:22 jenglish Exp $
 *
 * The problem:
 *
 * Tk maintains reference counts for fonts, colors, and images,
 * and deallocates them when the reference count goes to zero.
 * With the theme engine, resources are allocated right before
 * drawing an element and released immediately after.
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52

53
54
55
56

57
58
59
60
61
62
63
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

53
54
55
56
57
58
59
60
61
62
63
64
65







+













-
+




+







 */

#include <stdio.h>	/* for sprintf */
#include <tk.h>
#include "tkTheme.h"

struct TTK_ResourceCache_ {
    Tcl_Interp	  *interp;	/* Interpreter for TTK_UseImage err reports */
    Tk_Window	  tkwin;	/* Cache window. */
    Tcl_HashTable fontTable;	/* Entries: Tcl_Obj* holding FontObjs */
    Tcl_HashTable colorTable;	/* Entries: Tcl_Obj* holding ColorObjs */
    Tcl_HashTable borderTable;	/* Entries: Tcl_Obj* holding BorderObjs */
    Tcl_HashTable imageTable;	/* Entries: Tk_Images */

    Tcl_HashTable namedColors;	/* Entries: RGB values as Tcl_StringObjs */
};

/*
 * TTK_CreateResourceCache --
 * 	Initialize a new resource cache.
 */
TTK_ResourceCache TTK_CreateResourceCache(void)
TTK_ResourceCache TTK_CreateResourceCache(Tcl_Interp *interp)
{
    TTK_ResourceCache cache = (TTK_ResourceCache)ckalloc(sizeof(*cache));

    cache->tkwin = NULL;	/* initialized later */
    cache->interp = interp;
    Tcl_InitHashTable(&cache->fontTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&cache->colorTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&cache->borderTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&cache->imageTable, TCL_STRING_KEYS);
    Tcl_InitHashTable(&cache->namedColors, TCL_STRING_KEYS);

    return cache;
325
326
327
328
329
330
331
332

333




334
335
336
337
338
327
328
329
330
331
332
333

334
335
336
337
338
339
340
341
342
343
344







-
+

+
+
+
+






    InitCacheWindow(cache, tkwin);

    if (!newEntry) {
	return (Tk_Image)Tcl_GetHashValue(entryPtr);
    }

    image = Tk_GetImage(NULL, tkwin, imageName, 0,0);
    image = Tk_GetImage(cache->interp, tkwin, imageName, 0,0);
    Tcl_SetHashValue(entryPtr, image);

    if (!image) {
	Tcl_BackgroundError(cache->interp);
    }

    return image;
}

/*EOF*/