head	1.13;
access;
symbols
	core-8-5-9:1.12
	core-8-5-8:1.12
	macosx-cocoa-merge:1.13
	macosx-cocoa-premerge:1.13
	macosx-carbon-freeze:1.13
	core-8-5-7:1.12
	core-8-5-6:1.12
	core-8-6-b1:1.13
	core-8-6-a3:1.12
	core-8-5-5:1.12
	core-8-6-a2:1.12
	core-8-5-4:1.12
	core-8-5-3:1.12
	core-8-6-a1:1.12
	core-8-4-19:1.7
	core-8-5-branch:1.12.0.2
	core-8-5-2:1.12
	core-8-4-18:1.7
	core-8-5-1:1.12
	core-8-4-17:1.7
	core-8-5-0:1.12
	core-8-5-b3:1.11
	core-8-5-b2:1.11
	core-8-4-16:1.7
	core-8-5-b1:1.11
	core-stablilizer-merge:1.10
	core-stabilizer-branch:1.10.0.2
	core-stabilizer-merge:1.12
	core-8-4-15:1.7
	core-8-5-a6:1.10
	core-8-5-a5:1.10
	core-8-4-14:1.7
	core-8-5-a4:1.10
	core-8-4-13:1.7
	core-8-4-12:1.7
	core-8-4-11:1.7
	core-8-5-a3:1.9
	core-8-4-10:1.7
	core-8-4-9-branch:1.7.0.6
	core-8-5-a2:1.9
	core-8-4-9:1.7
	core-8-4-8:1.7
	core-8-4-7:1.7
	core-8-5-a1:1.8
	core-8-4-6:1.7
	core-8-4-5:1.7
	mistachkin-dev-branch:1.7.0.4
	core-8-4-4:1.7
	core-8-4-3:1.7
	core-8-4-branch:1.7.0.2
	core-8-4-2:1.7
	core-8-4-1:1.7
	core-8-3-5:1.5
	core-8-4-0:1.7
	macosx-8-4-merge-2002-08-31-trunk:1.7
	macosx-8-4-premerge-2002-08-31-branch:1.5.8.3
	macosx-8-4-premerge-2002-08-31-trunk:1.6
	macosx-8-4-merge-2002-08-30-branch:1.5.8.3
	macosx-8-4-merge-2002-08-30-trunk:1.6
	macosx-8-4-merge-2002-08-20-branch:1.5.8.3
	macosx-8-4-merge-2002-08-20-trunk:1.6
	core-8-4-b2:1.6
	core-8-4-b1:1.6
	macosx-premerge-6-9-02:1.5.8.2
	core-8-4-a4:1.5
	core-8-3-4:1.5
	macosx-8-4-branch:1.5.0.8
	macosx-8-4-branchpoint:1.5
	core-8-4-a3:1.5
	core-8-3-3:1.5
	dgp-privates-into-namespace:1.5.0.6
	tclpro-1-5-0:1.5
	core-8-4-win-speedup:1.5.0.4
	core-8-4-a2:1.5
	tclpro-1-4-1:1.5
	tclpro-1-4-0:1.5
	core-8-3-2:1.5
	ajuba-ajuba2-2-1-base:1.5
	ajuba-ajuba2-2-0:1.5
	core-8-4-a1:1.5
	core-8-3-1-branch:1.5.0.2
	core-8-3-1:1.5
	scriptics-sc-2-0-b5:1.3
	scriptics-sc-2-0-fixed:1.3
	scriptics-sc-2-0-b2:1.3
	scriptics-sc-2-0-b1:1.3
	core-8-3-0:1.3
	core-8-3-b2:1.3
	core-8-3-b1:1.3
	scriptics-sc-1-1:1.3
	scriptics-sc-1-1-b1:1.3
	core-8-2-3:1.3
	scriptics-sc-1-1-branch:1.3.0.12
	scriptics-sc-1-1-base:1.3
	scriptics-sc-1-0:1.3
	scriptics-sc-1-0-branch:1.3.0.10
	scriptics-sc-1-0-base:1.3
	core-8-2-2:1.3
	core-8-2-1:1.3
	scriptics-bc-1-0-b1:1.3
	core-8-2-1-branch:1.3.0.8
	scriptics-tclpro-1-3-0:1.3
	core-8-2-0:1.3
	core-8-2-b3-branch:1.3.0.6
	core-8-2-b3-base:1.3
	scriptics-tclpro-1-3-b4:1.3
	core-8-2-b2:1.3
	scriptics-tclpro-1-3-b3:1.3
	core-8-2-b1:1.3
	scriptics-tclpro-1-3-b2:1.3
	merge-to-mainline-5/21/99:1.3
	scriptics-tclpro-1-3-b2-branch:1.3.0.4
	core-8-1-1:1.3
	scriptics-tclpro-1-3-b1:1.3
	core-8-1-1-base:1.3
	core-8-1-0:1.3
	merge-to-mainline-4-29-99:1.3
	merge-to-mainline-4-23-99:1.3
	core-8-1-branch-old:1.1.0.4
	core-8-0-6-branch:1.3.0.2
	core-8-0-6-base:1.3
	core-8-0-5:1.2
	core-8-1-b3:1.1.4.2
	core-8-1-b2:1.1.4.2
	dev-8-1-stubs-branch:1.1.4.1.0.2
	dev-stubs-branch:1.2.0.4
	scriptics-tclpro-1-2:1.2
	scriptics-tclpro-1-2-b2:1.2
	core-8-1-merge-2/10/99:1.2
	core-8-0-5-branch:1.2.0.2
	core-8-0-5-base:1.2
	scriptics-tclpro-1-2-b1:1.2
	scriptics-tclpro-1-2-a1:1.2
	core-8-1-b1:1.1.4.1
	core-8-0-4:1.2
	core-8-1-a2:1.1
	core-8-0-2:1.1
	core-8-0-3:1.2;
locks; strict;
comment	@ * @;


1.13
date	2008.12.09.22.58.30;	author dkf;	state Exp;
branches;
next	1.12;

1.12
date	2007.12.13.15.28.50;	author dgp;	state Exp;
branches;
next	1.11;

1.11
date	2007.09.07.00.34.57;	author dgp;	state Exp;
branches;
next	1.10;

1.10
date	2005.11.13.21.00.17;	author dkf;	state Exp;
branches
	1.10.2.1;
next	1.9;

1.9
date	2004.03.17.18.15.50;	author das;	state Exp;
branches;
next	1.8;

1.8
date	2004.01.13.02.06.01;	author davygrvy;	state Exp;
branches;
next	1.7;

1.7
date	2002.08.31.06.12.31;	author das;	state Exp;
branches;
next	1.6;

1.6
date	2002.04.23.00.20.35;	author hobbs;	state Exp;
branches;
next	1.5;

1.5
date	2000.04.14.01.36.35;	author ericm;	state Exp;
branches
	1.5.8.1;
next	1.4;

1.4
date	2000.04.13.18.25.44;	author ericm;	state Exp;
branches;
next	1.3;

1.3
date	99.03.10.07.04.45;	author stanton;	state Exp;
branches;
next	1.2;

1.2
date	98.09.14.18.23.55;	author stanton;	state Exp;
branches
	1.2.4.1;
next	1.1;

1.1
date	98.04.01.09.59.33;	author rjohnson;	state Exp;
branches
	1.1.4.1;
next	;

1.1.4.1
date	98.09.30.02.19.13;	author stanton;	state Exp;
branches
	1.1.4.1.2.1;
next	1.1.4.2;

1.1.4.2
date	99.03.10.07.13.50;	author stanton;	state Exp;
branches;
next	;

1.1.4.1.2.1
date	99.03.09.17.50.38;	author redman;	state Exp;
branches;
next	;

1.2.4.1
date	99.03.06.02.23.18;	author redman;	state Exp;
branches;
next	;

1.5.8.1
date	2001.10.15.09.22.00;	author wolfsuit;	state Exp;
branches;
next	1.5.8.2;

1.5.8.2
date	2001.10.17.07.02.02;	author wolfsuit;	state Exp;
branches;
next	1.5.8.3;

1.5.8.3
date	2002.06.10.05.38.27;	author wolfsuit;	state Exp;
branches;
next	;

1.10.2.1
date	2007.09.07.01.25.37;	author dgp;	state Exp;
branches;
next	;


desc
@@


1.13
log
@minor corrections to comments
@
text
@/*
 * tkUnix3d.c --
 *
 *	This file contains the platform specific routines for drawing 3d
 *	borders in the Motif style.
 *
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.12 2007/12/13 15:28:50 dgp Exp $
 */

#include "tkInt.h"
#include "tk3d.h"

#if !(defined(__WIN32__) || defined(MAC_OSX_TK))
#include "tkUnixInt.h"
#endif

/*
 * This structure is used to keep track of the extra colors used by Unix 3D
 * borders.
 */

typedef struct {
    TkBorder info;
    GC solidGC;		/* Used to draw solid relief. */
} UnixBorder;

/*
 *----------------------------------------------------------------------
 *
 * TkpGetBorder --
 *
 *	This function allocates a new TkBorder structure.
 *
 * Results:
 *	Returns a newly allocated TkBorder.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

TkBorder *
TkpGetBorder(void)
{
    UnixBorder *borderPtr = (UnixBorder *) ckalloc(sizeof(UnixBorder));
    borderPtr->solidGC = None;
    return (TkBorder *) borderPtr;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpFreeBorder --
 *
 *	This function frees any colors allocated by the platform specific part
 *	of this module.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	May deallocate some colors.
 *
 *----------------------------------------------------------------------
 */

void
TkpFreeBorder(
    TkBorder *borderPtr)
{
    UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr;
    Display *display = DisplayOfScreen(borderPtr->screen);

    if (unixBorderPtr->solidGC != None) {
	Tk_FreeGC(display, unixBorderPtr->solidGC);
    }
}
/*
 *--------------------------------------------------------------
 *
 * Tk_3DVerticalBevel --
 *
 *	This procedure draws a vertical bevel along one side of an object. The
 *	bevel is always rectangular in shape:
 *			|||
 *			|||
 *			|||
 *			|||
 *			|||
 *			|||
 *	An appropriate shadow color is chosen for the bevel based on the
 *	leftBevel and relief arguments. Normally this procedure is called
 *	first, then Tk_3DHorizontalBevel is called next to draw neat corners.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Graphics are drawn in drawable.
 *
 *--------------------------------------------------------------
 */

void
Tk_3DVerticalBevel(
    Tk_Window tkwin,		/* Window for which border was allocated. */
    Drawable drawable,		/* X window or pixmap in which to draw. */
    Tk_3DBorder border,		/* Token for border to draw. */
    int x, int y, int width, int height,
				/* Area of vertical bevel. */
    int leftBevel,		/* Non-zero means this bevel forms the left
				 * side of the object; 0 means it forms the
				 * right side. */
    int relief)			/* Kind of bevel to draw. For example,
				 * TK_RELIEF_RAISED means interior of object
				 * should appear higher than exterior. */
{
    TkBorder *borderPtr = (TkBorder *) border;
    GC left, right;
    Display *display = Tk_Display(tkwin);

    if ((borderPtr->lightGC == None) && (relief != TK_RELIEF_FLAT)) {
	TkpGetShadows(borderPtr, tkwin);
    }

    if (relief == TK_RELIEF_RAISED) {
	XFillRectangle(display, drawable,
		(leftBevel) ? borderPtr->lightGC : borderPtr->darkGC,
		x, y, (unsigned) width, (unsigned) height);
    } else if (relief == TK_RELIEF_SUNKEN) {
	XFillRectangle(display, drawable,
		(leftBevel) ? borderPtr->darkGC : borderPtr->lightGC,
		x, y, (unsigned) width, (unsigned) height);
    } else if (relief == TK_RELIEF_RIDGE) {
	int half;

	left = borderPtr->lightGC;
	right = borderPtr->darkGC;
    ridgeGroove:
	half = width/2;
	if (!leftBevel && (width & 1)) {
	    half++;
	}
	XFillRectangle(display, drawable, left, x, y, (unsigned) half,
		(unsigned) height);
	XFillRectangle(display, drawable, right, x+half, y,
		(unsigned) (width-half), (unsigned) height);
    } else if (relief == TK_RELIEF_GROOVE) {
	left = borderPtr->darkGC;
	right = borderPtr->lightGC;
	goto ridgeGroove;
    } else if (relief == TK_RELIEF_FLAT) {
	XFillRectangle(display, drawable, borderPtr->bgGC, x, y,
		(unsigned) width, (unsigned) height);
    } else if (relief == TK_RELIEF_SOLID) {
	UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr;
	if (unixBorderPtr->solidGC == None) {
	    XGCValues gcValues;

	    gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
	    unixBorderPtr->solidGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
	}
	XFillRectangle(display, drawable, unixBorderPtr->solidGC, x, y,
		(unsigned) width, (unsigned) height);
    }
}

/*
 *--------------------------------------------------------------
 *
 * Tk_3DHorizontalBevel --
 *
 *	This procedure draws a horizontal bevel along one side of an object.
 *	The bevel has mitered corners (depending on leftIn and rightIn
 *	arguments).
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *--------------------------------------------------------------
 */

void
Tk_3DHorizontalBevel(
    Tk_Window tkwin,		/* Window for which border was allocated. */
    Drawable drawable,		/* X window or pixmap in which to draw. */
    Tk_3DBorder border,		/* Token for border to draw. */
    int x, int y, int width, int height,
				/* Bounding box of area of bevel. Height gives
				 * width of border. */
    int leftIn, int rightIn,	/* Describes whether the left and right edges
				 * of the bevel angle in or out as they go
				 * down. For example, if "leftIn" is true, the
				 * left side of the bevel looks like this:
				 *	___________
				 *	 __________
				 *	  _________
				 *	   ________
				 */
    int topBevel,		/* Non-zero means this bevel forms the top
				 * side of the object; 0 means it forms the
				 * bottom side. */
    int relief)			/* Kind of bevel to draw. For example,
				 * TK_RELIEF_RAISED means interior of object
				 * should appear higher than exterior. */
{
    TkBorder *borderPtr = (TkBorder *) border;
    Display *display = Tk_Display(tkwin);
    int bottom, halfway, x1, x2, x1Delta, x2Delta;
    UnixBorder *unixBorderPtr = (UnixBorder *) borderPtr;
    GC topGC = None, bottomGC = None;
				/* Initializations needed only to prevent
				 * compiler warnings. */

    if ((borderPtr->lightGC == None) && (relief != TK_RELIEF_FLAT) &&
	    (relief != TK_RELIEF_SOLID)) {
	TkpGetShadows(borderPtr, tkwin);
    }

    /*
     * Compute a GC for the top half of the bevel and a GC for the bottom half
     * (they're the same in many cases).
     */

    switch (relief) {
    case TK_RELIEF_FLAT:
	topGC = bottomGC = borderPtr->bgGC;
	break;
    case TK_RELIEF_GROOVE:
	topGC = borderPtr->darkGC;
	bottomGC = borderPtr->lightGC;
	break;
    case TK_RELIEF_RAISED:
	topGC = bottomGC = (topBevel? borderPtr->lightGC : borderPtr->darkGC);
	break;
    case TK_RELIEF_RIDGE:
	topGC = borderPtr->lightGC;
	bottomGC = borderPtr->darkGC;
	break;
    case TK_RELIEF_SOLID:
	if (unixBorderPtr->solidGC == None) {
	    XGCValues gcValues;

	    gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
	    unixBorderPtr->solidGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
	}
	XFillRectangle(display, drawable, unixBorderPtr->solidGC, x, y,
		(unsigned) width, (unsigned) height);
	return;
    case TK_RELIEF_SUNKEN:
	topGC = bottomGC = (topBevel? borderPtr->darkGC : borderPtr->lightGC);
	break;
    }

    /*
     * Compute various other geometry-related stuff.
     */

    x1 = x;
    if (!leftIn) {
	x1 += height;
    }
    x2 = x+width;
    if (!rightIn) {
	x2 -= height;
    }
    x1Delta = (leftIn) ? 1 : -1;
    x2Delta = (rightIn) ? -1 : 1;
    halfway = y + height/2;
    if (!topBevel && (height & 1)) {
	halfway++;
    }
    bottom = y + height;

    /*
     * Draw one line for each y-coordinate covered by the bevel.
     */

    for ( ; y < bottom; y++) {
	/*
	 * X Dimensions are 16-bit, so avoid wraparound or display errors by
	 * limiting these here.
	 */

	if (x1 < -32767) {
	    x1 = -32767;
	}
	if (x2 > 32767) {
	    x2 = 32767;
	}

	/*
	 * In some weird cases (such as large border widths for skinny
	 * rectangles) x1 can be >= x2. Don't draw the lines in these cases.
	 */

	if (x1 < x2) {
	    XFillRectangle(display, drawable,
		    (y < halfway) ? topGC : bottomGC, x1, y,
		    (unsigned) (x2-x1), (unsigned) 1);
	}
	x1 += x1Delta;
	x2 += x2Delta;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkpGetShadows --
 *
 *	This procedure computes the shadow colors for a 3-D border and fills
 *	in the corresponding fields of the Border structure. It's called
 *	lazily, so that the colors aren't allocated until something is
 *	actually drawn with them. That way, if a border is only used for flat
 *	backgrounds the shadow colors will never be allocated.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The lightGC and darkGC fields in borderPtr get filled in, if they
 *	weren't already.
 *
 *----------------------------------------------------------------------
 */

void
TkpGetShadows(
    TkBorder *borderPtr,	/* Information about border. */
    Tk_Window tkwin)		/* Window where border will be used for
				 * drawing. */
{
    XColor lightColor, darkColor;
    int stressed, tmp1, tmp2;
    int r, g, b;
    XGCValues gcValues;

    if (borderPtr->lightGC != None) {
	return;
    }
    stressed = TkpCmapStressed(tkwin, borderPtr->colormap);

    /*
     * First, handle the case of a color display with lots of colors. The
     * shadow colors get computed using whichever formula results in the
     * greatest change in color:
     * 1. Lighter shadow is half-way to white, darker shadow is half way to
     *    dark.
     * 2. Lighter shadow is 40% brighter than background, darker shadow is 40%
     *    darker than background.
     */

    if (!stressed && (Tk_Depth(tkwin) >= 6)) {
	/*
	 * This is a color display with lots of colors. For the dark shadow,
	 * cut 40% from each of the background color components. But if the
	 * background is already very dark, make the dark color a little
	 * lighter than the background by increasing each color component
	 * 1/4th of the way to MAX_INTENSITY.
	 *
	 * For the light shadow, boost each component by 40% or half-way to
	 * white, whichever is greater (the first approach works better for
	 * unsaturated colors, the second for saturated ones). But if the
	 * background is already very bright, instead choose a slightly darker
	 * color for the light shadow by reducing each color component by 10%.
	 *
	 * Compute the colors using integers, not using lightColor.red etc.:
	 * these are shorts and may have problems with integer overflow.
	 */

	/*
	 * Compute the dark shadow color.
	 */

	r = (int) borderPtr->bgColorPtr->red;
	g = (int) borderPtr->bgColorPtr->green;
	b = (int) borderPtr->bgColorPtr->blue;

	if (r*0.5*r + g*1.0*g + b*0.28*b < MAX_INTENSITY*0.05*MAX_INTENSITY) {
	    darkColor.red = (MAX_INTENSITY + 3*r)/4;
	    darkColor.green = (MAX_INTENSITY + 3*g)/4;
	    darkColor.blue = (MAX_INTENSITY + 3*b)/4;
	} else {
	    darkColor.red = (60 * r)/100;
	    darkColor.green = (60 * g)/100;
	    darkColor.blue = (60 * b)/100;
	}

	/*
	 * Allocate the dark shadow color and its GC.
	 */

	borderPtr->darkColorPtr = Tk_GetColorByValue(tkwin, &darkColor);
	gcValues.foreground = borderPtr->darkColorPtr->pixel;
	borderPtr->darkGC = Tk_GetGC(tkwin, GCForeground, &gcValues);

	/*
	 * Compute the light shadow color.
	 */

	if (g > MAX_INTENSITY*0.95) {
	    lightColor.red = (90 * r)/100;
	    lightColor.green = (90 * g)/100;
	    lightColor.blue = (90 * b)/100;
	} else {
	    tmp1 = (14 * r)/10;
	    if (tmp1 > MAX_INTENSITY) {
		tmp1 = MAX_INTENSITY;
	    }
	    tmp2 = (MAX_INTENSITY + r)/2;
	    lightColor.red = (tmp1 > tmp2) ? tmp1 : tmp2;
	    tmp1 = (14 * g)/10;
	    if (tmp1 > MAX_INTENSITY) {
		tmp1 = MAX_INTENSITY;
	    }
	    tmp2 = (MAX_INTENSITY + g)/2;
	    lightColor.green = (tmp1 > tmp2) ? tmp1 : tmp2;
	    tmp1 = (14 * b)/10;
	    if (tmp1 > MAX_INTENSITY) {
		tmp1 = MAX_INTENSITY;
	    }
	    tmp2 = (MAX_INTENSITY + b)/2;
	    lightColor.blue = (tmp1 > tmp2) ? tmp1 : tmp2;
	}

	/*
	 * Allocate the light shadow color and its GC.
	 */

	borderPtr->lightColorPtr = Tk_GetColorByValue(tkwin, &lightColor);
	gcValues.foreground = borderPtr->lightColorPtr->pixel;
	borderPtr->lightGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
	return;
    }

    if (borderPtr->shadow == None) {
	borderPtr->shadow = Tk_GetBitmap((Tcl_Interp *) NULL, tkwin,
		Tk_GetUid("gray50"));
	if (borderPtr->shadow == None) {
	    Tcl_Panic("TkpGetShadows couldn't allocate bitmap for border");
	}
    }
    if (borderPtr->visual->map_entries > 2) {
	/*
	 * This isn't a monochrome display, but the colormap either ran out of
	 * entries or didn't have very many to begin with. Generate the light
	 * shadows with a white stipple and the dark shadows with a black
	 * stipple.
	 */

	gcValues.foreground = borderPtr->bgColorPtr->pixel;
	gcValues.background = BlackPixelOfScreen(borderPtr->screen);
	gcValues.stipple = borderPtr->shadow;
	gcValues.fill_style = FillOpaqueStippled;
	borderPtr->darkGC = Tk_GetGC(tkwin,
		GCForeground|GCBackground|GCStipple|GCFillStyle, &gcValues);
	gcValues.background = WhitePixelOfScreen(borderPtr->screen);
	borderPtr->lightGC = Tk_GetGC(tkwin,
		GCForeground|GCBackground|GCStipple|GCFillStyle, &gcValues);
	return;
    }

    /*
     * This is just a measly monochrome display, hardly even worth its
     * existence on this earth. Make one shadow a 50% stipple and the other
     * the opposite of the background.
     */

    gcValues.foreground = WhitePixelOfScreen(borderPtr->screen);
    gcValues.background = BlackPixelOfScreen(borderPtr->screen);
    gcValues.stipple = borderPtr->shadow;
    gcValues.fill_style = FillOpaqueStippled;
    borderPtr->lightGC = Tk_GetGC(tkwin,
	    GCForeground|GCBackground|GCStipple|GCFillStyle, &gcValues);
    if (borderPtr->bgColorPtr->pixel
	    == WhitePixelOfScreen(borderPtr->screen)) {
	gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
	borderPtr->darkGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
    } else {
	borderPtr->darkGC = borderPtr->lightGC;
	borderPtr->lightGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
    }
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */
@


1.12
log
@merge stable branch onto HEAD
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.10.2.1 2007/09/07 01:25:37 dgp Exp $
d382 1
a382 1
	 * Compute the dark shadow color
d400 1
a400 1
	 * Allocate the dark shadow color and its GC
d408 1
a408 1
	 * Compute the light shadow color
d436 3
a438 3
       /*
        * Allocate the light shadow color and its GC
        */
@


1.11
log
@header cleanup
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.10 2005/11/13 21:00:17 dkf Exp $
@


1.10
log
@ANSIfy
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.9 2004/03/17 18:15:50 das Exp $
d15 2
a16 1
#include <tk3d.h>
@


1.10.2.1
log
@merge updates from HEAD
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.10 2005/11/13 21:00:17 dkf Exp $
d15 1
a15 2
#include "tkInt.h"
#include "tk3d.h"
@


1.9
log
@Removed support for Mac OS Classic platform [Patch 918139]
@
text
@d1 1
a1 1
/* 
d4 2
a5 2
 *	This file contains the platform specific routines for
 *	drawing 3d borders in the Motif style.
d9 2
a10 2
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.8 2004/01/13 02:06:01 davygrvy Exp $
d22 2
a23 2
 * This structure is used to keep track of the extra colors used
 * by Unix 3d borders.
d48 1
a48 1
TkpGetBorder()
a54 1

d60 2
a61 2
 *	This function frees any colors allocated by the platform
 *	specific part of this module.
d73 2
a74 2
TkpFreeBorder(borderPtr)
    TkBorder *borderPtr;
d88 2
a89 2
 *	This procedure draws a vertical bevel along one side of
 *	an object.  The bevel is always rectangular in shape:
d96 3
a98 4
 *	An appropriate shadow color is chosen for the bevel based
 *	on the leftBevel and relief arguments.  Normally this
 *	procedure is called first, then Tk_3DHorizontalBevel is
 *	called next to draw neat corners.
d110 12
a121 13
Tk_3DVerticalBevel(tkwin, drawable, border, x, y, width, height,
	leftBevel, relief)
    Tk_Window tkwin;		/* Window for which border was allocated. */
    Drawable drawable;		/* X window or pixmap in which to draw. */
    Tk_3DBorder border;		/* Token for border to draw. */
    int x, y, width, height;	/* Area of vertical bevel. */
    int leftBevel;		/* Non-zero means this bevel forms the
				 * left side of the object;  0 means it
				 * forms the right side. */
    int relief;			/* Kind of bevel to draw.  For example,
				 * TK_RELIEF_RAISED means interior of
				 * object should appear higher than
				 * exterior. */
d132 1
a132 1
	XFillRectangle(display, drawable, 
d136 1
a136 1
	XFillRectangle(display, drawable, 
d144 1
a144 1
	ridgeGroove:
d178 3
a180 3
 *	This procedure draws a horizontal bevel along one side of
 *	an object.  The bevel has mitered corners (depending on
 *	leftIn and rightIn arguments).
d192 11
a202 12
Tk_3DHorizontalBevel(tkwin, drawable, border, x, y, width, height,
	leftIn, rightIn, topBevel, relief)
    Tk_Window tkwin;		/* Window for which border was allocated. */
    Drawable drawable;		/* X window or pixmap in which to draw. */
    Tk_3DBorder border;		/* Token for border to draw. */
    int x, y, width, height;	/* Bounding box of area of bevel.  Height
				 * gives width of border. */
    int leftIn, rightIn;	/* Describes whether the left and right
				 * edges of the bevel angle in or out as
				 * they go down.  For example, if "leftIn"
				 * is true, the left side of the bevel
				 * looks like this:
d208 6
a213 7
    int topBevel;		/* Non-zero means this bevel forms the
				 * top side of the object;  0 means it
				 * forms the bottom side. */
    int relief;			/* Kind of bevel to draw.  For example,
				 * TK_RELIEF_RAISED means interior of
				 * object should appear higher than
				 * exterior. */
d229 2
a230 2
     * Compute a GC for the top half of the bevel and a GC for the
     * bottom half (they're the same in many cases).
d234 22
a255 24
	case TK_RELIEF_FLAT:
	    topGC = bottomGC = borderPtr->bgGC;
	    break;
	case TK_RELIEF_GROOVE:
	    topGC = borderPtr->darkGC;
	    bottomGC = borderPtr->lightGC;
	    break;
	case TK_RELIEF_RAISED:
	    topGC = bottomGC =
		    (topBevel) ? borderPtr->lightGC : borderPtr->darkGC;
	    break;
	case TK_RELIEF_RIDGE:
	    topGC = borderPtr->lightGC;
	    bottomGC = borderPtr->darkGC;
	    break;
	case TK_RELIEF_SOLID:
	    if (unixBorderPtr->solidGC == None) {
		XGCValues gcValues;

		gcValues.foreground = BlackPixelOfScreen(borderPtr->screen);
		unixBorderPtr->solidGC = Tk_GetGC(tkwin, GCForeground,
			&gcValues);
	    }
	    XFillRectangle(display, drawable, unixBorderPtr->solidGC, x, y,
d257 4
a260 5
	    return;
	case TK_RELIEF_SUNKEN:
	    topGC = bottomGC =
		    (topBevel) ? borderPtr->darkGC : borderPtr->lightGC;
	    break;
d289 2
a290 2
	 * X Dimensions are 16-bit, so avoid wraparound or display errors
	 * by limiting these here.
d292 2
a293 1
	if (x1 < -32767)
d295 2
a296 1
	if (x2 > 32767)
d298 1
d302 1
a302 2
	 * rectangles) x1 can be >= x2.  Don't draw the lines
	 * in these cases.
d307 2
a308 2
		(y < halfway) ? topGC : bottomGC, x1, y,
		(unsigned) (x2-x1), (unsigned) 1);
d320 5
a324 6
 *	This procedure computes the shadow colors for a 3-D border
 *	and fills in the corresponding fields of the Border structure.
 *	It's called lazily, so that the colors aren't allocated until
 *	something is actually drawn with them.  That way, if a border
 *	is only used for flat backgrounds the shadow colors will
 *	never be allocated.
d330 2
a331 2
 *	The lightGC and darkGC fields in borderPtr get filled in,
 *	if they weren't already.
d337 3
a339 3
TkpGetShadows(borderPtr, tkwin)
    TkBorder *borderPtr;		/* Information about border. */
    Tk_Window tkwin;		/* Window where border will be used for
d353 7
a359 7
     * First, handle the case of a color display with lots of colors.
     * The shadow colors get computed using whichever formula results
     * in the greatest change in color:
     * 1. Lighter shadow is half-way to white, darker shadow is half
     *    way to dark.
     * 2. Lighter shadow is 40% brighter than background, darker shadow
     *    is 40% darker than background.
d364 5
a368 5
	 * This is a color display with lots of colors.  For the dark
	 * shadow, cut 40% from each of the background color components.
	 * But if the background is already very dark, make the
	 * dark color a little lighter than the background by increasing
	 * each color component 1/4th of the way to MAX_INTENSITY.
d370 5
a374 6
	 * For the light shadow, boost each component by 40% or half-way
	 * to white, whichever is greater (the first approach works
	 * better for unsaturated colors, the second for saturated ones).
	 * But if the background is already very bright, instead choose a
	 * slightly darker color for the light shadow by reducing each
	 * color component by 10%.
d376 2
a377 3
	 * Compute the colors using integers, not using lightColor.red
	 * etc.: these are shorts and may have problems with integer
	 * overflow.
d434 1
a434 1
	
d454 4
a457 4
	 * This isn't a monochrome display, but the colormap either
	 * ran out of entries or didn't have very many to begin with.
	 * Generate the light shadows with a white stipple and the
	 * dark shadows with a black stipple.
d474 2
a475 2
     * existence on this earth.  Make one shadow a 50% stipple and the
     * other the opposite of the background.
d493 8
@


1.8
log
@	* generic/tk3d.c:	All uses of 'panic' (the macro) changed
	* generic/tkBind.c:	to 'Tcl_Panic' (the function).  The #define
	* generic/tkBitmap.c:	of panic in tcl.h clearly states it is
	* generic/tkCanvArc.c:	deprecated in the comments.
	* generic/tkCanvBmap.c: [Tcl Patch 865264]
	* generic/tkCanvImg.c:
	* generic/tkCanvLine.c:
	* generic/tkCanvPoly.c:
	* generic/tkCanvText.c:
	* generic/tkCanvWind.c:
	* generic/tkColor.c:
	* generic/tkConfig.c:
	* generic/tkCursor.c:
	* generic/tkError.c:
	* generic/tkEvent.c:
	* generic/tkFocus.c:
	* generic/tkFont.c:
	* generic/tkFrame.c:
	* generic/tkGC.c:
	* generic/tkGrid.c:
	* generic/tkImgBmap.c:
	* generic/tkImgPhoto.c:
	* generic/tkImgUtil.c:
	* generic/tkMenu.c:
	* generic/tkObj.c:
	* generic/tkPack.c:
	* generic/tkPlace.c:
	* generic/tkRectOval.c:
	* generic/tkSelect.c:
	* generic/tkText.c:
	* generic/tkTextBTree.c:
	* generic/tkTextDisp.c:
	* generic/tkTextImage.c:
	* generic/tkTextIndex.c:
	* generic/tkTextMark.c:
	* generic/tkTextWind.c:
	* generic/tkVisual.c:
	* generic/tkWindow.c:
	* mac/tkMacAppInit.c:
	* mac/tkMacAppearanceStubs.c:
	* mac/tkMacButton.c:
	* mac/tkMacDraw.c:
	* mac/tkMacEmbed.c:
	* mac/tkMacFont.c:
	* mac/tkMacInit.c:
	* mac/tkMacMenus.c:
	* mac/tkMacPort.h:
	* mac/tkMacSubwindows.c:
	* mac/tkMacWm.c:
	* mac/tkMacXStubs.c:
	* macosx/tkMacOSXEmbed.c:
	* macosx/tkMacOSXFont.c:
	* macosx/tkMacOSXMenus.c:
	* macosx/tkMacOSXNotify.c:
	* macosx/tkMacOSXPort.h:
	* macosx/tkMacOSXSubwindows.c:
	* macosx/tkMacOSXWm.c:
	* macosx/tkMacOSXXStubs.c:
	* unix/tkUnix3d.c:
	* unix/tkUnixColor.c:
	* unix/tkUnixEmbed.c:
	* unix/tkUnixEvent.c:
	* unix/tkUnixFocus.c:
	* unix/tkUnixFont.c:
	* unix/tkUnixSelect.c:
	* unix/tkUnixSend.c:
	* unix/tkUnixWm.c:
	* win/tkWin3d.c:
	* win/tkWinButton.c:
	* win/tkWinColor.c:
	* win/tkWinDialog.c:
	* win/tkWinDraw.c:
	* win/tkWinEmbed.c:
	* win/tkWinFont.c:
	* win/tkWinPixmap.c:
	* win/tkWinPointer.c:
	* win/tkWinScrlbr.c:
	* win/tkWinWm.c:
	* win/tkWinX.c:
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.7 2002/08/31 06:12:31 das Exp $
d17 1
a17 1
#if !(defined(__WIN32__) || defined(MAC_TCL) || defined(MAC_OSX_TK))
@


1.7
log
@	*** macosx-8-4-branch merged into the mainline [tcl patch #602770] ***

	* generic/tk.decls:
	* generic/tkInt.decls: added new "aqua" specific entries to the
	stubs tables. Changed all "unix" entries to "x11" to allow us to
	distinguish and build both "aqua" on MacOSX and "x11" on MacOSX.

	* generic/tk.h: added a #ifnded RESOURCE_INCLUDED so that tk.h can
	be passed to the resource compiler.

	* generic/tkCmds.c (Tk_TkObjCmd): added [tk windowingsystem]
	subcommand: returns "x11" when running on X11, "win32" on Windows,
	"classic" on MacOS9 and "aqua" on MacOSX Aqua (i.e. Carbon)

	* generic/tkFont.c (TkFontGetFirstTextLayout): new private function
	returning the first chunk of a Tk_TextLayout, i.e. until the first
	font change on the first line (or the whole first line if there is
	no such font change).

	* generic/tkMain.c: made Tcl_ThreadDataKey static

	* library/demos/puzzle.tcl: fixed button metrics for aqua

	* tests/cursor.test: check for presence of arrow cursor instead of
	heart cursor

	* xlib/xcolors.c: changed xColors static initialization to more
	standard C

	* macosx/Wish.pbproj/jingham.pbxuser (new):
	* macosx/Wish.pbproj/project.pbxproj (new): project for Apple's
	ProjectBuilder IDE.

	* macosx/Makefile (new): simple makefile for building the project
	from the command line via the ProjectBuilder tool 'pbxbuild'.

	* macosx/tkMacOSXAppInit.c (new): macosx specific AppInit looking
	for a AppMain.tcl file in its bundled Resources/Scripts folder. If
	present, argv[1] is set to that file and the Scripts folder is
	added to the auto_path. This allows tk apps to embed scripts within
	their bundle directory structure.

	* macosx/tkMacOSXInit.c (new): macosx adapted version of
	tkUnixInit.c: we initialize & cache the Carbon native encoding
	(e.g. 'macRoman') and try to find the tk script library files
	inside Tk packaged as a framework.

	* macosx/tkMacOSXNotify.c (new): new macosx specific merged
	Carbon/select-based notifier.

	* macosx/tkMacOSXEvent.c (new):
	* macosx/tkMacOSXEvent.h (new):
	* macosx/tkMacOSXKeyEvent.c (new):
	* macosx/tkMacOSXMouseEvent.c (new):
	* macosx/tkMacOSXWindowEvent.c (new): new macosx specific event
	handling functionality.

	* macosx/tkMacOSX.h (new):
	* macosx/tkMacOSXBitmap.c (new):
	* macosx/tkMacOSXButton.c (new):
	* macosx/tkMacOSXClipboard.c (new):
	* macosx/tkMacOSXColor.c (new):
	* macosx/tkMacOSXConfig.c (new):
	* macosx/tkMacOSXCursor.c (new):
	* macosx/tkMacOSXDefault.h (new):
	* macosx/tkMacOSXDialog.c (new):
	* macosx/tkMacOSXDraw.c (new):
	* macosx/tkMacOSXEmbed.c (new):
	* macosx/tkMacOSXFont.c (new):
	* macosx/tkMacOSXHLEvents.c (new):
	* macosx/tkMacOSXInt.h (new):
	* macosx/tkMacOSXKeyboard.c (new):
	* macosx/tkMacOSXMenu.c (new):
	* macosx/tkMacOSXMenubutton.c (new):
	* macosx/tkMacOSXMenus.c (new):
	* macosx/tkMacOSXPort.h (new):
	* macosx/tkMacOSXRegion.c (new):
	* macosx/tkMacOSXScale.c (new):
	* macosx/tkMacOSXScrlbr.c (new):
	* macosx/tkMacOSXSubwindows.c (new):
	* macosx/tkMacOSXTest.c (new):
	* macosx/tkMacOSXUtil.c (new):
	* macosx/tkMacOSXUtil.h (new):
	* macosx/tkMacOSXWm.c (new):
	* macosx/tkMacOSXWm.h (new):
	* macosx/tkMacOSXXStubs.c (new): macosx ports of classic mac Tk
	implementation in tk/mac.

	* macosx/tkMacOSXSend.c (new): only send to local interp
	implemented currently.

	* macosx/tkMacOSXDebug.h (new):
	* macosx/tkMacOSXDebug.c (new): new macosx specific functions for
	debugging MacOS events, regions, etc.

	* macosx/tkAboutDlg.r (new):
	* macosx/tkMacOSXApplication.r (new):
	* macosx/tkMacOSXCursors.r (new):
	* macosx/tkMacOSXLibrary.r (new):
	* macosx/tkMacOSXMenu.r (new):
	* macosx/tkMacOSXResource.r (new):
	* macosx/tkMacOSXXCursors.r (new):
	* macosx/tclets.r (new): sources for Rez resource compiler.

	* macosx/Wish.icns (new): Wish application icon.

	* generic/tk.h:
	* generic/default.h:
	* generic/tkBind.c:
	* generic/tkCmds.c:
	* generic/tkGrab.c:
	* generic/tkPointer.c:
	* generic/tkPort.h:
	* generic/tkSelect.c:
	* generic/tkStubLib.c:
	* generic/tkTest.c:
	* generic/tkText.c:
	* generic/tkWindow.c:
	* unix/tkUnix3d.c:
	* xlib/xgc.c:
	* xlib/X11/X.h:
	* xlib/X11/Xlib.h:
	* xlib/X11/Xutil.h: added #includes and #ifdefs for macosx

	* library/bgerror.tcl:
	* library/button.tcl:
	* library/console.tcl:
	* library/dialog.tcl:
	* library/entry.tcl:
	* library/listbox.tcl:
	* library/menu.tcl:
	* library/msgbox.tcl:
	* library/scrlbar.tcl:
	* library/spinbox.tcl:
	* library/text.tcl:
	* library/tk.tcl:
	* library/demos/menu.tcl:
	* library/demos/menubu.tcl:
	* library/demos/widget: check [tk windowingsystem] instead of
	and/or in addition to $tcl_platform(platform).

	* generic/tkInt.h:
	* mac/tkMacBitmap.c:
	* mac/tkMacWm.c: added missing CONSTification

	* generic/tkIntDecls.h:
	* generic/tkIntPlatDecls.h:
	* generic/tkIntXlibDecls.h:
	* generic/tkPlatDecls.h:
	* generic/tkStubInit.c: regen
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id$
d458 1
a458 1
	    panic("TkpGetShadows couldn't allocate bitmap for border");
@


1.6
log
@	* generic/tkTextDisp.c (DisplayLineBackground):
	* unix/tkUnix3d.c (Tk_3DHorizontalBevel):
	* unix/tkUnixFont.c (Tk_DrawChars): applied fixes to not overrun
	the X window 16-bit size limit. [Patch #541999] (bonfield)
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.5 2000/04/14 01:36:35 ericm Exp $
d17 1
a17 1
#if !defined(__WIN32__) && !defined(MAC_TCL)
@


1.5
log
@* win/tkWinKey.c: Added smarts to check whether the left or right
Control, Shift, or Alt key was pressed.  [Bug: 870].

* win/tkWin3d.c:
* unix/tkUnix3d.c: Tweaked threshhold for using different highlight
computation.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.4 2000/04/13 18:25:44 ericm Exp $
d296 9
@


1.5.8.1
log
@First checkin of support for Tk on Mac OS X.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id$
d17 1
a17 1
#if !(defined(__WIN32__) || defined(MAC_TCL) || defined(MAC_OSX_TCL))
@


1.5.8.2
log
@Replace MAC_OSX_TCL with MAC_OSX_TK for all windowing specific things.  This is so we can separate the macosx specific additions to Tcl (which are added ON to the Unix core) from the Aqua additions (which are orthogonal to Unix - which itself is overloaded to mean X11 as well...)
@
text
@d17 1
a17 1
#if !(defined(__WIN32__) || defined(MAC_TCL) || defined(MAC_OSX_TK))
@


1.5.8.3
log
@Merging with TOT as of 06/09/2002.
@
text
@a296 9
	 * X Dimensions are 16-bit, so avoid wraparound or display errors
	 * by limiting these here.
	 */
	if (x1 < -32767)
	    x1 = -32767;
	if (x2 > 32767)
	    x2 = 32767;

	/*
@


1.4
log
@* win/tkWin3d.c:
* unix/tkUnix3d.c: Applied patch from [RFE: 2501]: adds more
sophisticated smarts to TkpGetShadows, so that the highlight of a
very bright color is actually distinguishable from the color, and
the shadow of a very dark color is similarly distinguishable from
the color.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.3 1999/03/10 07:04:45 stanton Exp $
d410 1
a410 1
	if (g > MAX_INTENSITY*85/100) {
@


1.3
log
@integrated stubs into 8.0 main branch
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.2.4.1 1999/03/06 02:23:18 redman Exp $
d342 1
d364 4
d371 29
a401 3
	darkColor.red = (60 * (int) borderPtr->bgColorPtr->red)/100;
	darkColor.green = (60 * (int) borderPtr->bgColorPtr->green)/100;
	darkColor.blue = (60 * (int) borderPtr->bgColorPtr->blue)/100;
d407 1
a407 3
	 * Compute the colors using integers, not using lightColor.red
	 * etc.: these are shorts and may have problems with integer
	 * overflow.
d410 23
a432 3
	tmp1 = (14 * (int) borderPtr->bgColorPtr->red)/10;
	if (tmp1 > MAX_INTENSITY) {
	    tmp1 = MAX_INTENSITY;
d434 5
a438 14
	tmp2 = (MAX_INTENSITY + (int) borderPtr->bgColorPtr->red)/2;
	lightColor.red = (tmp1 > tmp2) ? tmp1 : tmp2;
	tmp1 = (14 * (int) borderPtr->bgColorPtr->green)/10;
	if (tmp1 > MAX_INTENSITY) {
	    tmp1 = MAX_INTENSITY;
	}
	tmp2 = (MAX_INTENSITY + (int) borderPtr->bgColorPtr->green)/2;
	lightColor.green = (tmp1 > tmp2) ? tmp1 : tmp2;
	tmp1 = (14 * (int) borderPtr->bgColorPtr->blue)/10;
	if (tmp1 > MAX_INTENSITY) {
	    tmp1 = MAX_INTENSITY;
	}
	tmp2 = (MAX_INTENSITY + (int) borderPtr->bgColorPtr->blue)/2;
	lightColor.blue = (tmp1 > tmp2) ? tmp1 : tmp2;
@


1.2
log
@Replaced SCCS strings, fixed binary files
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id$
d16 4
@


1.2.4.1
log
@Modified stubs code to work on Unix.  Modified makefile and configure
to add stub support and build against libtclstub.a.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.2 1998/09/14 18:23:55 stanton Exp $
a15 4

#if !defined(__WIN32__) && !defined(MAC_TCL)
#include "tkUnixInt.h"
#endif
@


1.1
log
@Initial revision
@
text
@d12 1
a12 1
 * SCCS: @@(#) tkUnix3d.c 1.3 96/11/20 14:24:38
@


1.1.4.1
log
@Merged 8.0.3 changes into 8.1
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.2 1998/09/14 18:23:55 stanton Exp $
@


1.1.4.2
log
@integrated stubs from development branch
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.1.4.1 1998/09/30 02:19:13 stanton Exp $
a15 4

#if !defined(__WIN32__) && !defined(MAC_TCL)
#include "tkUnixInt.h"
#endif
@


1.1.4.1.2.1
log
@Changes to support stubs in 8.1. Merged from 8.0.6 code base.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkUnix3d.c,v 1.1.4.1 1998/09/30 02:19:13 stanton Exp $
a15 4

#if !defined(__WIN32__) && !defined(MAC_TCL)
#include "tkUnixInt.h"
#endif
@


