diff options
author | das <das> | 2002-08-31 06:12:19 (GMT) |
---|---|---|
committer | das <das> | 2002-08-31 06:12:19 (GMT) |
commit | e947c1d0d386b229818958dc12ea0cc20e4ec582 (patch) | |
tree | 303845583d22d9e5e5f3f53edf451167cb5847e6 /macosx/tkMacOSXColor.c | |
parent | 62d94160aed093a9505d60181a1509e69bd02bb6 (diff) | |
download | tk-e947c1d0d386b229818958dc12ea0cc20e4ec582.zip tk-e947c1d0d386b229818958dc12ea0cc20e4ec582.tar.gz tk-e947c1d0d386b229818958dc12ea0cc20e4ec582.tar.bz2 |
*** macosx-8-4-branch merged into the mainline [tcl patch #602770] ***macosx_8_4_merge_2002_08_31_trunk
* 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
Diffstat (limited to 'macosx/tkMacOSXColor.c')
-rw-r--r-- | macosx/tkMacOSXColor.c | 448 |
1 files changed, 448 insertions, 0 deletions
diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c new file mode 100644 index 0000000..492f098 --- /dev/null +++ b/macosx/tkMacOSXColor.c @@ -0,0 +1,448 @@ +/* + * tkMacOSXColor.c -- + * + * This file maintains a database of color values for the Tk + * toolkit, in order to avoid round-trips to the server to + * map color names to pixel values. + * + * Copyright (c) 1990-1994 The Regents of the University of California. + * Copyright (c) 1994-1996 Sun Microsystems, Inc. + * Copyright 2001, Apple Computer, Inc. + * + * See the file "license.terms" for information on usage and redistribution + * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * + * RCS: @(#) $Id: tkMacOSXColor.c,v 1.2 2002/08/31 06:12:29 das Exp $ + */ + +#include <tkColor.h> +#include "tkMacOSXInt.h" +#include <Carbon/Carbon.h> + +/* + * Default Auxillary Control Record for all controls. This is cached once + * and is updated by the system. We use this to get the default system + * colors used by controls. + */ +/* + * Stubbed out for OS X +static AuxCtlHandle defaultAuxCtlHandle = NULL; +*/ + +/* + * Forward declarations for procedures defined later in this file: + */ + +static int GetControlPartColor _ANSI_ARGS_((short part, RGBColor *macColor)); +static int GetMenuPartColor _ANSI_ARGS_((int part, RGBColor *macColor)); +static int GetWindowPartColor _ANSI_ARGS_((short part, RGBColor *macColor)); + +/* + *---------------------------------------------------------------------- + * + * TkSetMacColor -- + * + * Populates a Macintosh RGBColor structure from a X style + * pixel value. + * + * Results: + * Returns false if not a real pixel, true otherwise. + * + * Side effects: + * The variable macColor is updated to the pixels value. + * + *---------------------------------------------------------------------- + */ + +int +TkSetMacColor( + unsigned long pixel, /* Pixel value to convert. */ + RGBColor *macColor) /* Mac color struct to modify. */ +{ + switch (pixel >> 24) { + case HIGHLIGHT_PIXEL: + LMGetHiliteRGB(macColor); + return true; + case HIGHLIGHT_TEXT_PIXEL: + LMGetHiliteRGB(macColor); + if ((macColor->red == 0) && (macColor->green == 0) + && (macColor->blue == 0)) { + macColor->red = macColor->green = macColor->blue = 0xFFFF; + } else { + macColor->red = macColor->green = macColor->blue = 0; + } + return true; + case CONTROL_TEXT_PIXEL: + GetControlPartColor(cTextColor, macColor); + return true; + case CONTROL_BODY_PIXEL: + GetControlPartColor(cBodyColor, macColor); + return true; + case CONTROL_FRAME_PIXEL: + GetControlPartColor(cFrameColor, macColor); + return true; + case WINDOW_BODY_PIXEL: + GetWindowPartColor(wContentColor, macColor); + return true; + case MENU_ACTIVE_PIXEL: + case MENU_ACTIVE_TEXT_PIXEL: + case MENU_BACKGROUND_PIXEL: + case MENU_DISABLED_PIXEL: + case MENU_TEXT_PIXEL: + return GetMenuPartColor((pixel >> 24), macColor); + case APPEARANCE_PIXEL: + return false; + case PIXEL_MAGIC: + default: + macColor->blue = (unsigned short) ((pixel & 0xFF) << 8); + macColor->green = (unsigned short) (((pixel >> 8) & 0xFF) << 8); + macColor->red = (unsigned short) (((pixel >> 16) & 0xFF) << 8); + return true; + } +} + +/* + *---------------------------------------------------------------------- + * + * Stub functions -- + * + * These functions are just stubs for functions that either + * don't make sense on the Mac or have yet to be implemented. + * + * Results: + * None. + * + * Side effects: + * These calls do nothing - which may not be expected. + * + *---------------------------------------------------------------------- + */ + +Status +XAllocColor( + Display *display, /* Display. */ + Colormap map, /* Not used. */ + XColor *colorPtr) /* XColor struct to modify. */ +{ + display->request++; + colorPtr->pixel = TkpGetPixel(colorPtr); + return 1; +} + +Colormap +XCreateColormap( + Display *display, /* Display. */ + Window window, /* X window. */ + Visual *visual, /* Not used. */ + int alloc) /* Not used. */ +{ + static Colormap index = 1; + + /* + * Just return a new value each time. + */ + return index++; +} + +void +XFreeColormap( + Display* display, /* Display. */ + Colormap colormap) /* Colormap. */ +{ +} + +void +XFreeColors( + Display* display, /* Display. */ + Colormap colormap, /* Colormap. */ + unsigned long* pixels, /* Array of pixels. */ + int npixels, /* Number of pixels. */ + unsigned long planes) /* Number of pixel planes. */ +{ + /* + * The Macintosh version of Tk uses TrueColor. Nothing + * needs to be done to release colors as there really is + * no colormap in the Tk sense. + */ +} + +/* + *---------------------------------------------------------------------- + * + * TkpGetColor -- + * + * Allocate a new TkColor for the color with the given name. + * + * Results: + * Returns a newly allocated TkColor, or NULL on failure. + * + * Side effects: + * May invalidate the colormap cache associated with tkwin upon + * allocating a new colormap entry. Allocates a new TkColor + * structure. + * + *---------------------------------------------------------------------- + */ + +TkColor * +TkpGetColor( + Tk_Window tkwin, /* Window in which color will be used. */ + Tk_Uid name) /* Name of color to allocated (in form + * suitable for passing to XParseColor). */ +{ + Display *display = Tk_Display(tkwin); + Colormap colormap = Tk_Colormap(tkwin); + TkColor *tkColPtr; + XColor color; + + /* + * Check to see if this is a system color. Otherwise, XParseColor + * will do all the work. + */ + if (strncasecmp(name, "system", 6) == 0) { + int foundSystemColor = false; + RGBColor rgbValue; + char pixelCode = 0; + + if (!strcasecmp(name+6, "Highlight")) { + LMGetHiliteRGB(&rgbValue); + pixelCode = HIGHLIGHT_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "HighlightText")) { + LMGetHiliteRGB(&rgbValue); + if ((rgbValue.red == 0) && (rgbValue.green == 0) + && (rgbValue.blue == 0)) { + rgbValue.red = rgbValue.green = rgbValue.blue = 0xFFFF; + } else { + rgbValue.red = rgbValue.green = rgbValue.blue = 0; + } + pixelCode = HIGHLIGHT_TEXT_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "ButtonText")) { + GetControlPartColor(cTextColor, &rgbValue); + pixelCode = CONTROL_TEXT_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "ButtonFace")) { + GetControlPartColor(cBodyColor, &rgbValue); + pixelCode = CONTROL_BODY_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "ButtonFrame")) { + GetControlPartColor(cFrameColor, &rgbValue); + pixelCode = CONTROL_FRAME_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "WindowBody")) { + GetWindowPartColor(wContentColor, &rgbValue); + pixelCode = WINDOW_BODY_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "MenuActive")) { + GetMenuPartColor(MENU_ACTIVE_PIXEL, &rgbValue); + pixelCode = MENU_ACTIVE_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "MenuActiveText")) { + GetMenuPartColor(MENU_ACTIVE_TEXT_PIXEL, &rgbValue); + pixelCode = MENU_ACTIVE_TEXT_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "Menu")) { + GetMenuPartColor(MENU_BACKGROUND_PIXEL, &rgbValue); + pixelCode = MENU_BACKGROUND_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "MenuDisabled")) { + GetMenuPartColor(MENU_DISABLED_PIXEL, &rgbValue); + pixelCode = MENU_DISABLED_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "MenuText")) { + GetMenuPartColor(MENU_TEXT_PIXEL, &rgbValue); + pixelCode = MENU_TEXT_PIXEL; + foundSystemColor = true; + } else if (!strcasecmp(name+6, "AppearanceColor")) { + color.red = 0; + color.green = 0; + color.blue = 0; + pixelCode = APPEARANCE_PIXEL; + foundSystemColor = true; + } + + if (foundSystemColor) { + color.red = rgbValue.red; + color.green = rgbValue.green; + color.blue = rgbValue.blue; + color.pixel = ((((((pixelCode << 8) + | ((color.red >> 8) & 0xff)) << 8) + | ((color.green >> 8) & 0xff)) << 8) + | ((color.blue >> 8) & 0xff)); + + tkColPtr = (TkColor *) ckalloc(sizeof(TkColor)); + tkColPtr->color = color; + return tkColPtr; + } + } + + if (XParseColor(display, colormap, name, &color) == 0) { + return (TkColor *) NULL; + } + + tkColPtr = (TkColor *) ckalloc(sizeof(TkColor)); + tkColPtr->color = color; + + return tkColPtr; +} + +/* + *---------------------------------------------------------------------- + * + * TkpGetColorByValue -- + * + * Given a desired set of red-green-blue intensities for a color, + * locate a pixel value to use to draw that color in a given + * window. + * + * Results: + * The return value is a pointer to an TkColor structure that + * indicates the closest red, blue, and green intensities available + * to those specified in colorPtr, and also specifies a pixel + * value to use to draw in that color. + * + * Side effects: + * May invalidate the colormap cache for the specified window. + * Allocates a new TkColor structure. + * + *---------------------------------------------------------------------- + */ + +TkColor * +TkpGetColorByValue( + Tk_Window tkwin, /* Window in which color will be used. */ + XColor *colorPtr) /* Red, green, and blue fields indicate + * desired color. */ +{ + TkColor *tkColPtr = (TkColor *) ckalloc(sizeof(TkColor)); + + tkColPtr->color.red = colorPtr->red; + tkColPtr->color.green = colorPtr->green; + tkColPtr->color.blue = colorPtr->blue; + tkColPtr->color.pixel = TkpGetPixel(&tkColPtr->color); + return tkColPtr; +} + +/* + *---------------------------------------------------------------------- + * + * GetControlPartColor -- + * + * Given a part number this function will return the standard + * system default color for that part. It does this by looking + * in the system's 'cctb' resource. + * + * Results: + * True if a color is found, false otherwise. + * + * Side effects: + * If a color is found then the RGB variable will be changed to + * the parts color. + * + *---------------------------------------------------------------------- + */ + +static int +GetControlPartColor( + short part, /* Part code. */ + RGBColor *macColor) /* Pointer to Mac color. */ +{ +/* Stubbed out for OS X + short index; + CCTabHandle ccTab; + + if (defaultAuxCtlHandle == NULL) { + GetAuxiliaryControlRecord(NULL, &defaultAuxCtlHandle); + } + ccTab = (**defaultAuxCtlHandle).acCTable; + if(ccTab && (ResError() == noErr)) { + for(index = 0; index <= (**ccTab).ctSize; index++) { + if((**ccTab).ctTable[index].value == part) { + *macColor = (**ccTab).ctTable[index].rgb; + return true; + } + } + } +*/ + return false; +} + +/* + *---------------------------------------------------------------------- + * + * GetWindowPartColor -- + * + * Given a part number this function will return the standard + * system default color for that part. It does this by looking + * in the system's 'wctb' resource. + * + * Results: + * True if a color is found, false otherwise. + * + * Side effects: + * If a color is found then the RGB variable will be changed to + * the parts color. + * + *---------------------------------------------------------------------- + */ + +static int +GetWindowPartColor( + short part, /* Part code. */ + RGBColor *macColor) /* Pointer to Mac color. */ +{ + short index; + WCTabHandle wcTab; + + if (part == wContentColor) { + GetThemeBrushAsColor(kThemeBrushDocumentWindowBackground, + 0xFFFF, true, macColor); + return true; + } else { + wcTab = (WCTabHandle) GetResource('wctb', 0); + if(wcTab && (ResError() == noErr)) { + for(index = 0; index <= (**wcTab).ctSize; index++) { + if((**wcTab).ctTable[index].value == part) { + *macColor = (**wcTab).ctTable[index].rgb; + return true; + } + } + } + return false; + } +} + +/* + *---------------------------------------------------------------------- + * + * GetMenuPartColor -- + * + * Given a magic pixel value, returns the RGB color associated + * with it by looking the value up in the system's 'mctb' resource. + * + * Results: + * True if a color is found, false otherwise. + * + * Side effects: + * If a color is found then the RGB variable will be changed to + * the parts color. + * + *---------------------------------------------------------------------- + */ + +static int +GetMenuPartColor( + int pixel, /* The magic pixel value */ + RGBColor *macColor) /* Pointer to Mac color */ +{ + + /* Under Appearance, we don't want to set any menu colors when we + are asked for the standard menu colors. So we return false (which + means don't use this color... */ + + macColor->red = 0xFFFF; + macColor->green = 0; + macColor->blue = 0; + return false; +} |