OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [generic/] [tkGC.c] - Diff between revs 578 and 579

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 578 Rev 579
/*
/*
 * tkGC.c --
 * tkGC.c --
 *
 *
 *      This file maintains a database of read-only graphics contexts
 *      This file maintains a database of read-only graphics contexts
 *      for the Tk toolkit, in order to allow GC's to be shared.
 *      for the Tk toolkit, in order to allow GC's to be shared.
 *
 *
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1990-1994 The Regents of the University of California.
 * Copyright (c) 1994 Sun Microsystems, Inc.
 * Copyright (c) 1994 Sun Microsystems, Inc.
 *
 *
 * See the file "license.terms" for information on usage and redistribution
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 *
 * RCS: @(#) $Id: tkGC.c,v 1.1.1.1 2002-01-16 10:25:51 markom Exp $
 * RCS: @(#) $Id: tkGC.c,v 1.1.1.1 2002-01-16 10:25:51 markom Exp $
 */
 */
 
 
#include "tkPort.h"
#include "tkPort.h"
#include "tk.h"
#include "tk.h"
 
 
/* CYGNUS LOCAL, for TkRegisterColorGC.  */
/* CYGNUS LOCAL, for TkRegisterColorGC.  */
#include "tkInt.h"
#include "tkInt.h"
 
 
/*
/*
 * One of the following data structures exists for each GC that is
 * One of the following data structures exists for each GC that is
 * currently active.  The structure is indexed with two hash tables,
 * currently active.  The structure is indexed with two hash tables,
 * one based on the values in the graphics context and the other
 * one based on the values in the graphics context and the other
 * based on the display and GC identifier.
 * based on the display and GC identifier.
 */
 */
 
 
typedef struct {
typedef struct {
    GC gc;                      /* Graphics context. */
    GC gc;                      /* Graphics context. */
    Display *display;           /* Display to which gc belongs. */
    Display *display;           /* Display to which gc belongs. */
    int refCount;               /* Number of active uses of gc. */
    int refCount;               /* Number of active uses of gc. */
    Tcl_HashEntry *valueHashPtr;/* Entry in valueTable (needed when deleting
    Tcl_HashEntry *valueHashPtr;/* Entry in valueTable (needed when deleting
                                 * this structure). */
                                 * this structure). */
    /* CYGNUS LOCAL.  */
    /* CYGNUS LOCAL.  */
    XColor *foreground;         /* Foreground color.  */
    XColor *foreground;         /* Foreground color.  */
    XColor *background;         /* Background color.  */
    XColor *background;         /* Background color.  */
} TkGC;
} TkGC;
 
 
/*
/*
 * Hash table to map from a GC's values to a TkGC structure describing
 * Hash table to map from a GC's values to a TkGC structure describing
 * a GC with those values (used by Tk_GetGC).
 * a GC with those values (used by Tk_GetGC).
 */
 */
 
 
static Tcl_HashTable valueTable;
static Tcl_HashTable valueTable;
typedef struct {
typedef struct {
    XGCValues values;           /* Desired values for GC. */
    XGCValues values;           /* Desired values for GC. */
    Display *display;           /* Display for which GC is valid. */
    Display *display;           /* Display for which GC is valid. */
    int screenNum;              /* screen number of display */
    int screenNum;              /* screen number of display */
    int depth;                  /* and depth for which GC is valid. */
    int depth;                  /* and depth for which GC is valid. */
    /* CYGNUS LOCAL.  */
    /* CYGNUS LOCAL.  */
    XColor *foreground;         /* Foreground color.  */
    XColor *foreground;         /* Foreground color.  */
    XColor *background;         /* Background color.  */
    XColor *background;         /* Background color.  */
} ValueKey;
} ValueKey;
 
 
/*
/*
 * Hash table for <display + GC> -> TkGC mapping. This table is used by
 * Hash table for <display + GC> -> TkGC mapping. This table is used by
 * Tk_FreeGC.
 * Tk_FreeGC.
 */
 */
 
 
static Tcl_HashTable idTable;
static Tcl_HashTable idTable;
typedef struct {
typedef struct {
    Display *display;           /* Display for which GC was allocated. */
    Display *display;           /* Display for which GC was allocated. */
    GC gc;                      /* X's identifier for GC. */
    GC gc;                      /* X's identifier for GC. */
} IdKey;
} IdKey;
 
 
static int initialized = 0;      /* 0 means static structures haven't been
static int initialized = 0;      /* 0 means static structures haven't been
                                 * initialized yet. */
                                 * initialized yet. */
 
 
/*
/*
 * Forward declarations for procedures defined in this file:
 * Forward declarations for procedures defined in this file:
 */
 */
 
 
static void             GCInit _ANSI_ARGS_((void));
static void             GCInit _ANSI_ARGS_((void));


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * Tk_GetGC --
 * Tk_GetGC --
 *
 *
 *      Given a desired set of values for a graphics context, find
 *      Given a desired set of values for a graphics context, find
 *      a read-only graphics context with the desired values.
 *      a read-only graphics context with the desired values.
 *
 *
 * Results:
 * Results:
 *      The return value is the X identifer for the desired graphics
 *      The return value is the X identifer for the desired graphics
 *      context.  The caller should never modify this GC, and should
 *      context.  The caller should never modify this GC, and should
 *      call Tk_FreeGC when the GC is no longer needed.
 *      call Tk_FreeGC when the GC is no longer needed.
 *
 *
 * Side effects:
 * Side effects:
 *      The GC is added to an internal database with a reference count.
 *      The GC is added to an internal database with a reference count.
 *      For each call to this procedure, there should eventually be a call
 *      For each call to this procedure, there should eventually be a call
 *      to Tk_FreeGC, so that the database can be cleaned up when GC's
 *      to Tk_FreeGC, so that the database can be cleaned up when GC's
 *      aren't needed anymore.
 *      aren't needed anymore.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
/* CYGNUS LOCAL: Rename this to Tk_GetGCColor.  The new Tk_GetGC is
/* CYGNUS LOCAL: Rename this to Tk_GetGCColor.  The new Tk_GetGC is
   below.  */
   below.  */
 
 
GC
GC
Tk_GetGCColor(tkwin, valueMask, valuePtr, foreground, background)
Tk_GetGCColor(tkwin, valueMask, valuePtr, foreground, background)
    Tk_Window tkwin;            /* Window in which GC will be used. */
    Tk_Window tkwin;            /* Window in which GC will be used. */
    register unsigned long valueMask;
    register unsigned long valueMask;
                                /* 1 bits correspond to values specified
                                /* 1 bits correspond to values specified
                                 * in *valuesPtr;  other values are set
                                 * in *valuesPtr;  other values are set
                                 * from defaults. */
                                 * from defaults. */
    register XGCValues *valuePtr;
    register XGCValues *valuePtr;
                                /* Values are specified here for bits set
                                /* Values are specified here for bits set
                                 * in valueMask. */
                                 * in valueMask. */
    /* CYGNUS LOCAL.  */
    /* CYGNUS LOCAL.  */
    XColor *foreground;         /* Foreground color. */
    XColor *foreground;         /* Foreground color. */
    XColor *background;         /* Background color. */
    XColor *background;         /* Background color. */
{
{
    ValueKey valueKey;
    ValueKey valueKey;
    IdKey idKey;
    IdKey idKey;
    Tcl_HashEntry *valueHashPtr, *idHashPtr;
    Tcl_HashEntry *valueHashPtr, *idHashPtr;
    register TkGC *gcPtr;
    register TkGC *gcPtr;
    int new;
    int new;
    Drawable d, freeDrawable;
    Drawable d, freeDrawable;
 
 
    if (!initialized) {
    if (!initialized) {
        GCInit();
        GCInit();
    }
    }
 
 
#if !defined(__WIN32__) && !defined(_WIN32)
#if !defined(__WIN32__) && !defined(_WIN32)
    /* CYGNUS LOCAL.  We only care about special foreground and
    /* CYGNUS LOCAL.  We only care about special foreground and
       background colors on Windows.  If we are on some other
       background colors on Windows.  If we are on some other
       platform, just ignore them.  If we don't do this, we may
       platform, just ignore them.  If we don't do this, we may
       allocate an unnecessary GC if we have two colors with different
       allocate an unnecessary GC if we have two colors with different
       names but the same pixel value.  */
       names but the same pixel value.  */
    foreground = NULL;
    foreground = NULL;
    background = NULL;
    background = NULL;
#endif
#endif
 
 
    /*
    /*
     * Must zero valueKey at start to clear out pad bytes that may be
     * Must zero valueKey at start to clear out pad bytes that may be
     * part of structure on some systems.
     * part of structure on some systems.
     */
     */
 
 
    memset((VOID *) &valueKey, 0, sizeof(valueKey));
    memset((VOID *) &valueKey, 0, sizeof(valueKey));
 
 
    /*
    /*
     * First, check to see if there's already a GC that will work
     * First, check to see if there's already a GC that will work
     * for this request (exact matches only, sorry).
     * for this request (exact matches only, sorry).
     */
     */
 
 
    if (valueMask & GCFunction) {
    if (valueMask & GCFunction) {
        valueKey.values.function = valuePtr->function;
        valueKey.values.function = valuePtr->function;
    } else {
    } else {
        valueKey.values.function = GXcopy;
        valueKey.values.function = GXcopy;
    }
    }
    if (valueMask & GCPlaneMask) {
    if (valueMask & GCPlaneMask) {
        valueKey.values.plane_mask = valuePtr->plane_mask;
        valueKey.values.plane_mask = valuePtr->plane_mask;
    } else {
    } else {
        valueKey.values.plane_mask = (unsigned) ~0;
        valueKey.values.plane_mask = (unsigned) ~0;
    }
    }
    if (valueMask & GCForeground) {
    if (valueMask & GCForeground) {
        valueKey.values.foreground = valuePtr->foreground;
        valueKey.values.foreground = valuePtr->foreground;
    } else {
    } else {
        valueKey.values.foreground = 0;
        valueKey.values.foreground = 0;
    }
    }
    if (valueMask & GCBackground) {
    if (valueMask & GCBackground) {
        valueKey.values.background = valuePtr->background;
        valueKey.values.background = valuePtr->background;
    } else {
    } else {
        valueKey.values.background = 1;
        valueKey.values.background = 1;
    }
    }
    if (valueMask & GCLineWidth) {
    if (valueMask & GCLineWidth) {
        valueKey.values.line_width = valuePtr->line_width;
        valueKey.values.line_width = valuePtr->line_width;
    } else {
    } else {
        valueKey.values.line_width = 0;
        valueKey.values.line_width = 0;
    }
    }
    if (valueMask & GCLineStyle) {
    if (valueMask & GCLineStyle) {
        valueKey.values.line_style = valuePtr->line_style;
        valueKey.values.line_style = valuePtr->line_style;
    } else {
    } else {
        valueKey.values.line_style = LineSolid;
        valueKey.values.line_style = LineSolid;
    }
    }
    if (valueMask & GCCapStyle) {
    if (valueMask & GCCapStyle) {
        valueKey.values.cap_style = valuePtr->cap_style;
        valueKey.values.cap_style = valuePtr->cap_style;
    } else {
    } else {
        valueKey.values.cap_style = CapButt;
        valueKey.values.cap_style = CapButt;
    }
    }
    if (valueMask & GCJoinStyle) {
    if (valueMask & GCJoinStyle) {
        valueKey.values.join_style = valuePtr->join_style;
        valueKey.values.join_style = valuePtr->join_style;
    } else {
    } else {
        valueKey.values.join_style = JoinMiter;
        valueKey.values.join_style = JoinMiter;
    }
    }
    if (valueMask & GCFillStyle) {
    if (valueMask & GCFillStyle) {
        valueKey.values.fill_style = valuePtr->fill_style;
        valueKey.values.fill_style = valuePtr->fill_style;
    } else {
    } else {
        valueKey.values.fill_style = FillSolid;
        valueKey.values.fill_style = FillSolid;
    }
    }
    if (valueMask & GCFillRule) {
    if (valueMask & GCFillRule) {
        valueKey.values.fill_rule = valuePtr->fill_rule;
        valueKey.values.fill_rule = valuePtr->fill_rule;
    } else {
    } else {
        valueKey.values.fill_rule = EvenOddRule;
        valueKey.values.fill_rule = EvenOddRule;
    }
    }
    if (valueMask & GCArcMode) {
    if (valueMask & GCArcMode) {
        valueKey.values.arc_mode = valuePtr->arc_mode;
        valueKey.values.arc_mode = valuePtr->arc_mode;
    } else {
    } else {
        valueKey.values.arc_mode = ArcPieSlice;
        valueKey.values.arc_mode = ArcPieSlice;
    }
    }
    if (valueMask & GCTile) {
    if (valueMask & GCTile) {
        valueKey.values.tile = valuePtr->tile;
        valueKey.values.tile = valuePtr->tile;
    } else {
    } else {
        valueKey.values.tile = None;
        valueKey.values.tile = None;
    }
    }
    if (valueMask & GCStipple) {
    if (valueMask & GCStipple) {
        valueKey.values.stipple = valuePtr->stipple;
        valueKey.values.stipple = valuePtr->stipple;
    } else {
    } else {
        valueKey.values.stipple = None;
        valueKey.values.stipple = None;
    }
    }
    if (valueMask & GCTileStipXOrigin) {
    if (valueMask & GCTileStipXOrigin) {
        valueKey.values.ts_x_origin = valuePtr->ts_x_origin;
        valueKey.values.ts_x_origin = valuePtr->ts_x_origin;
    } else {
    } else {
        valueKey.values.ts_x_origin = 0;
        valueKey.values.ts_x_origin = 0;
    }
    }
    if (valueMask & GCTileStipYOrigin) {
    if (valueMask & GCTileStipYOrigin) {
        valueKey.values.ts_y_origin = valuePtr->ts_y_origin;
        valueKey.values.ts_y_origin = valuePtr->ts_y_origin;
    } else {
    } else {
        valueKey.values.ts_y_origin = 0;
        valueKey.values.ts_y_origin = 0;
    }
    }
    if (valueMask & GCFont) {
    if (valueMask & GCFont) {
        valueKey.values.font = valuePtr->font;
        valueKey.values.font = valuePtr->font;
    } else {
    } else {
        valueKey.values.font = None;
        valueKey.values.font = None;
    }
    }
    if (valueMask & GCSubwindowMode) {
    if (valueMask & GCSubwindowMode) {
        valueKey.values.subwindow_mode = valuePtr->subwindow_mode;
        valueKey.values.subwindow_mode = valuePtr->subwindow_mode;
    } else {
    } else {
        valueKey.values.subwindow_mode = ClipByChildren;
        valueKey.values.subwindow_mode = ClipByChildren;
    }
    }
    if (valueMask & GCGraphicsExposures) {
    if (valueMask & GCGraphicsExposures) {
        valueKey.values.graphics_exposures = valuePtr->graphics_exposures;
        valueKey.values.graphics_exposures = valuePtr->graphics_exposures;
    } else {
    } else {
        valueKey.values.graphics_exposures = True;
        valueKey.values.graphics_exposures = True;
    }
    }
    if (valueMask & GCClipXOrigin) {
    if (valueMask & GCClipXOrigin) {
        valueKey.values.clip_x_origin = valuePtr->clip_x_origin;
        valueKey.values.clip_x_origin = valuePtr->clip_x_origin;
    } else {
    } else {
        valueKey.values.clip_x_origin = 0;
        valueKey.values.clip_x_origin = 0;
    }
    }
    if (valueMask & GCClipYOrigin) {
    if (valueMask & GCClipYOrigin) {
        valueKey.values.clip_y_origin = valuePtr->clip_y_origin;
        valueKey.values.clip_y_origin = valuePtr->clip_y_origin;
    } else {
    } else {
        valueKey.values.clip_y_origin = 0;
        valueKey.values.clip_y_origin = 0;
    }
    }
    if (valueMask & GCClipMask) {
    if (valueMask & GCClipMask) {
        valueKey.values.clip_mask = valuePtr->clip_mask;
        valueKey.values.clip_mask = valuePtr->clip_mask;
    } else {
    } else {
        valueKey.values.clip_mask = None;
        valueKey.values.clip_mask = None;
    }
    }
    if (valueMask & GCDashOffset) {
    if (valueMask & GCDashOffset) {
        valueKey.values.dash_offset = valuePtr->dash_offset;
        valueKey.values.dash_offset = valuePtr->dash_offset;
    } else {
    } else {
        valueKey.values.dash_offset = 0;
        valueKey.values.dash_offset = 0;
    }
    }
    if (valueMask & GCDashList) {
    if (valueMask & GCDashList) {
        valueKey.values.dashes = valuePtr->dashes;
        valueKey.values.dashes = valuePtr->dashes;
    } else {
    } else {
        valueKey.values.dashes = 4;
        valueKey.values.dashes = 4;
    }
    }
    valueKey.display = Tk_Display(tkwin);
    valueKey.display = Tk_Display(tkwin);
    valueKey.screenNum = Tk_ScreenNumber(tkwin);
    valueKey.screenNum = Tk_ScreenNumber(tkwin);
    valueKey.depth = Tk_Depth(tkwin);
    valueKey.depth = Tk_Depth(tkwin);
 
 
    /* CYGNUS LOCAL.  Set colors.  */
    /* CYGNUS LOCAL.  Set colors.  */
    valueKey.foreground = foreground;
    valueKey.foreground = foreground;
    valueKey.background = background;
    valueKey.background = background;
 
 
    valueHashPtr = Tcl_CreateHashEntry(&valueTable, (char *) &valueKey, &new);
    valueHashPtr = Tcl_CreateHashEntry(&valueTable, (char *) &valueKey, &new);
    if (!new) {
    if (!new) {
        gcPtr = (TkGC *) Tcl_GetHashValue(valueHashPtr);
        gcPtr = (TkGC *) Tcl_GetHashValue(valueHashPtr);
        gcPtr->refCount++;
        gcPtr->refCount++;
        return gcPtr->gc;
        return gcPtr->gc;
    }
    }
 
 
    /*
    /*
     * No GC is currently available for this set of values.  Allocate a
     * No GC is currently available for this set of values.  Allocate a
     * new GC and add a new structure to the database.
     * new GC and add a new structure to the database.
     */
     */
 
 
    gcPtr = (TkGC *) ckalloc(sizeof(TkGC));
    gcPtr = (TkGC *) ckalloc(sizeof(TkGC));
 
 
    /*
    /*
     * Find or make a drawable to use to specify the screen and depth
     * Find or make a drawable to use to specify the screen and depth
     * of the GC.  We may have to make a small pixmap, to avoid doing
     * of the GC.  We may have to make a small pixmap, to avoid doing
     * Tk_MakeWindowExist on the window.
     * Tk_MakeWindowExist on the window.
     */
     */
 
 
    freeDrawable = None;
    freeDrawable = None;
    if (Tk_WindowId(tkwin) != None) {
    if (Tk_WindowId(tkwin) != None) {
        d = Tk_WindowId(tkwin);
        d = Tk_WindowId(tkwin);
    } else if (valueKey.depth ==
    } else if (valueKey.depth ==
            DefaultDepth(valueKey.display, valueKey.screenNum)) {
            DefaultDepth(valueKey.display, valueKey.screenNum)) {
        d = RootWindow(valueKey.display, valueKey.screenNum);
        d = RootWindow(valueKey.display, valueKey.screenNum);
    } else {
    } else {
        d = Tk_GetPixmap(valueKey.display,
        d = Tk_GetPixmap(valueKey.display,
                RootWindow(valueKey.display, valueKey.screenNum),
                RootWindow(valueKey.display, valueKey.screenNum),
                1, 1, valueKey.depth);
                1, 1, valueKey.depth);
        freeDrawable = d;
        freeDrawable = d;
    }
    }
 
 
    gcPtr->gc = XCreateGC(valueKey.display, d, valueMask, &valueKey.values);
    gcPtr->gc = XCreateGC(valueKey.display, d, valueMask, &valueKey.values);
    gcPtr->display = valueKey.display;
    gcPtr->display = valueKey.display;
    gcPtr->refCount = 1;
    gcPtr->refCount = 1;
    gcPtr->valueHashPtr = valueHashPtr;
    gcPtr->valueHashPtr = valueHashPtr;
    idKey.display = valueKey.display;
    idKey.display = valueKey.display;
    idKey.gc = gcPtr->gc;
    idKey.gc = gcPtr->gc;
    idHashPtr = Tcl_CreateHashEntry(&idTable, (char *) &idKey, &new);
    idHashPtr = Tcl_CreateHashEntry(&idTable, (char *) &idKey, &new);
    if (!new) {
    if (!new) {
        panic("GC already registered in Tk_GetGC");
        panic("GC already registered in Tk_GetGC");
    }
    }
    Tcl_SetHashValue(valueHashPtr, gcPtr);
    Tcl_SetHashValue(valueHashPtr, gcPtr);
    Tcl_SetHashValue(idHashPtr, gcPtr);
    Tcl_SetHashValue(idHashPtr, gcPtr);
    if (freeDrawable != None) {
    if (freeDrawable != None) {
        Tk_FreePixmap(valueKey.display, freeDrawable);
        Tk_FreePixmap(valueKey.display, freeDrawable);
    }
    }
 
 
    /* CYGNUS LOCAL.  Record and register the colors.  */
    /* CYGNUS LOCAL.  Record and register the colors.  */
    gcPtr->foreground = foreground;
    gcPtr->foreground = foreground;
    gcPtr->background = background;
    gcPtr->background = background;
    if (foreground != NULL) {
    if (foreground != NULL) {
        TkRegisterColorGC(foreground, valueKey.display, gcPtr->gc,
        TkRegisterColorGC(foreground, valueKey.display, gcPtr->gc,
                          GCForeground);
                          GCForeground);
    }
    }
    if (background != NULL) {
    if (background != NULL) {
        TkRegisterColorGC(background, valueKey.display, gcPtr->gc,
        TkRegisterColorGC(background, valueKey.display, gcPtr->gc,
                          GCBackground);
                          GCBackground);
    }
    }
 
 
    return gcPtr->gc;
    return gcPtr->gc;
}
}
 
 
/* CYGNUS LOCAL.  Tk_GetGC now just calls Tk_GetGCColor.  */
/* CYGNUS LOCAL.  Tk_GetGC now just calls Tk_GetGCColor.  */
 
 
GC
GC
Tk_GetGC(tkwin, valueMask, valuePtr)
Tk_GetGC(tkwin, valueMask, valuePtr)
    Tk_Window tkwin;            /* Window in which GC will be used. */
    Tk_Window tkwin;            /* Window in which GC will be used. */
    register unsigned long valueMask;
    register unsigned long valueMask;
                                /* 1 bits correspond to values specified
                                /* 1 bits correspond to values specified
                                 * in *valuesPtr;  other values are set
                                 * in *valuesPtr;  other values are set
                                 * from defaults. */
                                 * from defaults. */
    register XGCValues *valuePtr;
    register XGCValues *valuePtr;
                                /* Values are specified here for bits set
                                /* Values are specified here for bits set
                                 * in valueMask. */
                                 * in valueMask. */
{
{
    return Tk_GetGCColor(tkwin, valueMask, valuePtr, NULL, NULL);
    return Tk_GetGCColor(tkwin, valueMask, valuePtr, NULL, NULL);
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * Tk_FreeGC --
 * Tk_FreeGC --
 *
 *
 *      This procedure is called to release a graphics context allocated by
 *      This procedure is called to release a graphics context allocated by
 *      Tk_GetGC.
 *      Tk_GetGC.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      The reference count associated with gc is decremented, and
 *      The reference count associated with gc is decremented, and
 *      gc is officially deallocated if no-one is using it anymore.
 *      gc is officially deallocated if no-one is using it anymore.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
Tk_FreeGC(display, gc)
Tk_FreeGC(display, gc)
    Display *display;           /* Display for which gc was allocated. */
    Display *display;           /* Display for which gc was allocated. */
    GC gc;                      /* Graphics context to be released. */
    GC gc;                      /* Graphics context to be released. */
{
{
    IdKey idKey;
    IdKey idKey;
    Tcl_HashEntry *idHashPtr;
    Tcl_HashEntry *idHashPtr;
    register TkGC *gcPtr;
    register TkGC *gcPtr;
 
 
    if (!initialized) {
    if (!initialized) {
        panic("Tk_FreeGC called before Tk_GetGC");
        panic("Tk_FreeGC called before Tk_GetGC");
    }
    }
 
 
    idKey.display = display;
    idKey.display = display;
    idKey.gc = gc;
    idKey.gc = gc;
    idHashPtr = Tcl_FindHashEntry(&idTable, (char *) &idKey);
    idHashPtr = Tcl_FindHashEntry(&idTable, (char *) &idKey);
    if (idHashPtr == NULL) {
    if (idHashPtr == NULL) {
        panic("Tk_FreeGC received unknown gc argument");
        panic("Tk_FreeGC received unknown gc argument");
    }
    }
    gcPtr = (TkGC *) Tcl_GetHashValue(idHashPtr);
    gcPtr = (TkGC *) Tcl_GetHashValue(idHashPtr);
    gcPtr->refCount--;
    gcPtr->refCount--;
    if (gcPtr->refCount == 0) {
    if (gcPtr->refCount == 0) {
        /* CYGNUS LOCAL: Deregister the colors.  */
        /* CYGNUS LOCAL: Deregister the colors.  */
        if (gcPtr->foreground != NULL) {
        if (gcPtr->foreground != NULL) {
            TkDeregisterColorGC(gcPtr->foreground, gcPtr->gc,
            TkDeregisterColorGC(gcPtr->foreground, gcPtr->gc,
                                GCForeground);
                                GCForeground);
        }
        }
        if (gcPtr->background != NULL) {
        if (gcPtr->background != NULL) {
            TkDeregisterColorGC(gcPtr->background, gcPtr->gc,
            TkDeregisterColorGC(gcPtr->background, gcPtr->gc,
                                GCBackground);
                                GCBackground);
        }
        }
 
 
        Tk_FreeXId(gcPtr->display, (XID) XGContextFromGC(gcPtr->gc));
        Tk_FreeXId(gcPtr->display, (XID) XGContextFromGC(gcPtr->gc));
        XFreeGC(gcPtr->display, gcPtr->gc);
        XFreeGC(gcPtr->display, gcPtr->gc);
        Tcl_DeleteHashEntry(gcPtr->valueHashPtr);
        Tcl_DeleteHashEntry(gcPtr->valueHashPtr);
        Tcl_DeleteHashEntry(idHashPtr);
        Tcl_DeleteHashEntry(idHashPtr);
        ckfree((char *) gcPtr);
        ckfree((char *) gcPtr);
    }
    }
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * GCInit --
 * GCInit --
 *
 *
 *      Initialize the structures used for GC management.
 *      Initialize the structures used for GC management.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Read the code.
 *      Read the code.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
static void
static void
GCInit()
GCInit()
{
{
    initialized = 1;
    initialized = 1;
    Tcl_InitHashTable(&valueTable, sizeof(ValueKey)/sizeof(int));
    Tcl_InitHashTable(&valueTable, sizeof(ValueKey)/sizeof(int));
    Tcl_InitHashTable(&idTable, sizeof(IdKey)/sizeof(int));
    Tcl_InitHashTable(&idTable, sizeof(IdKey)/sizeof(int));
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.