summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXColor.c
diff options
context:
space:
mode:
authordas <das>2007-04-29 02:26:47 (GMT)
committerdas <das>2007-04-29 02:26:47 (GMT)
commit3d653839d0082e663196cd7d34738a73d9b99bca (patch)
treed8296fa62af852c5f2e743159973d854366b69fa /macosx/tkMacOSXColor.c
parentf56417828d72ab960fdc1268a1c126ca5da9fd89 (diff)
downloadtk-3d653839d0082e663196cd7d34738a73d9b99bca.zip
tk-3d653839d0082e663196cd7d34738a73d9b99bca.tar.gz
tk-3d653839d0082e663196cd7d34738a73d9b99bca.tar.bz2
* macosx/tkMacOSXCarbonEvents.c: add window event target carbon event
* macosx/tkMacOSXEvent.c: handler for all kEventClassWindow and * macosx/tkMacOSXEvent.h: kEventClassMouse events; move all * macosx/tkMacOSXNotify.c: remaining events except for * macosx/tkMacOSXWindowEvent.c: kEventClassKeyboard from dispatcher to application event handler; pass event handler callRef downstream; fix debug event tracing; process all tcl event types in carbon event timer; delay carbon event timer first fire; add TkMacOSXTrackingLoop() to mark enter/exit of event tracking loop during which all tcl events but only carbon update events should be processed by the timer (replaces various calls to Tcl_SetServiceMode()); rename TkMacOSXReceiveAndProcessEvent() to TkMacOSXReceiveAndDispatchEvent(), move it from tkMacOSXEvent.c to tkMacOSXCarbonEvents.c and modify it to dequeue only update events during a tracking loop; add TkMacOSXRunTclEventLoop() to standardize the various ways in use to run the tcl event loop; add handling of kEventClassAppearance events (for ScrollBarVariantChanged event). * macosx/tkMacOSXDialog.c: use new TkMacOSXTrackingLoop() around * macosx/tkMacOSXEvent.c: blocking API that puts up modal dialogs * macosx/tkMacOSXMenu.c: or when entering/exiting menu/control * macosx/tkMacOSXMouseEvent.c: tracking, window dragging and other * macosx/tkMacOSXScale.c: mouse tracking loops. * macosx/tkMacOSXScrlbr.c: * macosx/tkMacOSXWindowEvent.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXDialog.c: use new TkMacOSXRunTclEventLoop() * macosx/tkMacOSXScale.c: instead of Tcl_DoOneEvent(), * macosx/tkMacOSXScrlbr.c: Tcl_ServiceAll(), TclServiceIdle() * macosx/tkMacOSXWindowEvent.c: and Tcl_GlobalEval("update idletasks"). * macosx/tkMacOSXColor.c: make available as Tk system colors all * macosx/tkMacOSXPort.h: appearance manager brushes, text colors and backgrounds with new and legacy names, as well as the fully transparent color "systemTransparent"; add TkMacOSXSetColorIn{Port,Context}() to directly set an X pixel color value in the current QD port resp. the given CG context without requiring passage through rgb representation (lossy for most system colors); modernize/remove Classic-era code; replace crufty strcmp() elseifs by Tcl_GetIndexFromObjStruct(). * macosx/tkMacOSXButton.c: use new TkMacOSXSetColorInPort() * macosx/tkMacOSXDraw.c: instead of setting rgb color directly * macosx/tkMacOSXMenubutton.c: to allow for non-rgb system colors. * macosx/tkMacOSXCursor.c: implement "none" cursor as on other platforms [Patch 1615427]; add all missing appearance manager cursors. * macosx/tkMacOSXDefault.h: set SELECT_FG_COLORs to None to match aqua L&F; use standard system color names; use new 'menu' system font; correct default scrollbar width. * macosx/tkMacOSXDraw.c: standardize initialization, use and * macosx/tkMacOSXInt.h: emptying of various static temp rgns * macosx/tkMacOSXRegion.c: onto two global RgnHandles; in debug * macosx/tkMacOSXSubwindows.c: builds, verify emptiness of these temp * macosx/tkMacOSXWindowEvent.c: rgns before use. * macosx/tkMacOSXDraw.c: add TkMacOSX{Setup,Restore}DrawingContext() to * macosx/tkMacOSXInt.h: abstract common setup & teardown of drawing environment (for both CG and QD); save/restore QD theme drawing state; handle GC clip region; add TkpClipDrawableToRect() to allow clipped drawing into drawable regardless of GC used; use new system color "systemWindowHeaderBackground" to setup background in themed toplevels; correct implementation of TkMacOSXMakeStippleMap(). * macosx/tkMacOSXEntry.c: use new TkMacOSXSetupDrawingContext() and * macosx/tkMacOSXFont.c: TkMacOSXRestoreDrawingContext() instead of various setup/teardown procs like TkMacOSX{SetUp,Release}CGContext(), TkMacOSXQuarz{Start,End}Draw(), TkMacOSXSetUpGraphicsPort() etc. * macosx/tkMacOSXEmbed.c: add CG context and drawable clip rgn fields * macosx/tkMacOSXInt.h: to MacDrawable struct. * macosx/tkMacOSXSubwindows.c: * macosx/tkMacOSXDialog.c: make -parent option of tk_getOpenFile et al. use the sheet version of NavServices dialogs; ensure native parent win exists before using StandardSheet API for tk_messageBox [Bug 1677611]; force sheets to behave like app-modal dialogs via WindowModality() API; use more modern ColorPicker API. * macosx/tkAboutDlg.r: use themed movable modal dialog, fix (c) year. * macosx/tkMacOSXEntry.c: take xOff/yOff of MacDrawable into account when computing locations/bounds to ensure correct posititioning when not drawing into intermediate pixmap. * macosx/tkMacOSXFont.c: use appearance manager API to map system font * macosx/tkMacOSXFont.h: names to TkFonts; add "menu" system font for menu item text drawing from MDEF; disable broken QD stippling. * macosx/tkMacOSXMenu.c: large-scale rewrite of custom * macosx/tkMacOSXMenu.r (removed): MDEF and related code that * unix/Makefile.in: restores many longtime-MIA features to working order (e.g. images, custom colors & fonts in menus etc); implement compound menu items; use Appearance Mgr and ThemeText APIs to mimic native MDEF as closely as possible when default "menu" system font is used; remove now obsolete SICN drawing code and resources. * macosx/tkMacOSXCarbonEvents.c: handle additional menu carbon events * macosx/tkMacOSXEvent.c: in order to support <<MenuSelect>> in * macosx/tkMacOSXMenu.c: the menubar and in menus that are not * macosx/tkMacOSXMenus.c: using the custom MDEF [Bug 1620826]; fix early and missing clearing of current Tk active menu entry; fix extraneous sending of <<MenuSelect>> during active menu entry clearing. * macosx/tkMacOSXMouseEvent.c: add support for async window dragging by the window server; set the corresponding window attribute by default. * macosx/tkMacOSXMouseEvent.c: rationalized handling order of non-mousedown events; add TkMacOSXModifierState() to retrieve the current key modifiers in carbon format. * macosx/tkMacOSXScrlbr.c: use appearance manager API to retrieve scrollbar component metrics; add awareness of multiple possibilites for scrollbar arrow position in aqua and handle user changes to arrow position pref; handle difference in metrics of small & large scrollbar variants; handle aqua "jump to here" scrollbar behaviour; correct computation of scroll view size and position; enforce min scrollbar height to avoid scrollbar component overlap; erase scrollbar area outside of standard width; remove broken auto-adjust code; account for window class when leaving space for grow box; remove code to manually draw grow box; use modern API for thumb scroll proc; replace HiliteControl() by modern API; replace control mgr constants with appearance mgr equivalents. * macosx/tkMacOSXSubwindows.c: use SetWindowBounds() API instead of SizeWindow(); invalidate clip regions after X{Map,Unmap}Window as fix for [Bug 940117] made them dependent on mapping state; remove unneeded calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD port; use native-endian pixmap on intel; remove obsolete pixmap pix locking. * macosx/tkMacOSXWindowEvent.c: handle only the first of a batch of kEventAppAvailableWindowBoundsChanged events sent per transaction; handle kEventWindowBoundsChanged event to support live window resizing and centralized sending of location/size changed ConfigureNotify events; ensure HIGrowBox is redrawn after bounds change; constrain window after dragging to ensure titlebar is not inacessible offscreen or under dock/menubar; handle kEventWindowGetRegion and kEventWindowDrawContent for transparent windows to mark resp. paint content region as transparent; handle kEventWindowConstrain for fullscreen windows to ensure bounds match new screen size; enter/exit fullscreen UIMode upon activation/deactivation of fullscreen window. * macosx/tkMacOSXWm.c: use live-resize and async-drag carbon window * macosx/tkMacOSXWm.h: attributes for toplevels by default; implement new [wm attributes] -topmost, -transparent and -fullscreen; refactor WmAttributesCmd() parallelling the tkUnixWm.c implementation, use thus factored proc to set proxy icon from [wm iconbitmap]; dynamically determine default values for toplevel min and max sizes (similar to tkWinWm.c impl): min sizes depend on window class & attributes to ensure visibility of all titlebar widgets and grow box, max sizes depend on maximal window bounds for all active displays; factor out code that puts into effect changes to master or override_redirect; use RepositionWindow() API to determine staggered initial window bounds; correct resize limit calculations, handle gridding and use modern resize API in TkMacOSXGrowToplevel(); remove sending of ConfigureNotify after resize or zoom (now handled by BoundsChanged handler); correct composite carbon window attribute handling, remove currently unusable attributes and add new attributes in [tk::unsupported::MacWindowStyle]; ensure validity of window class and attributes before use; apply changes to window class when handling carbon window attribute changes (if HIWindowChangeClass() API available); add debug build warning message when deprecated window style is used instead of window class; use transparent HIGrowBox for resizable windows; avoid unnecessary calls to window structure width API; use tcl time API in TkpGetMS(); add TkMacOSXEnterExitFullscreen() to enter/exit UIMode with dock and menubar hidden; restrict wmTracing output to debug builds; remove unneeded calls to TkMacOSXInvalClipRgns() and unnecessary setting of QD port; workaround GetWindowStructureWidths() Carbon bug (bogus results for never-mapped floating windows). * macosx/tkMacOSXXStubs.c (TkMacOSXDisplayChanged): add maximal window bounds field to Screen record (in ext_data), computed as the union of available window positioning bounds of all graphics devices (displays). * macosx/tkMacOSXBitmap.c: fix macRoman encoding leak. * macosx/tkMacOSXCursor.c: * macosx/tkMacOSXDebug.c (TkMacOSXCarbonEventToAscii): use static * macosx/tkMacOSXDebug.h: buffer to simplify callers; const fixes. * macosx/tkMacOSXBitmap.c: use more efficient QDSwapPort() instead of * macosx/tkMacOSXButton.c: GetPort()/SetPort()/GetGWorld()/SetGWorld(). * macosx/tkMacOSXDraw.c: * macosx/tkMacOSXFont.c: * macosx/tkMacOSXMenubutton.c: * macosx/tkMacOSXScale.c: * macosx/tkMacOSXScrlbr.c: * macosx/tkMacOSXXStubs.c: * macosx/tkMacOSXColor.c: use kHIToolboxVersionNumber for runtime OS * macosx/tkMacOSXEntry.c: version check rather than Gestalt() etc. * macosx/tkMacOSXInt.h: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXDraw.c: remove obsolete and now incorrect * macosx/tkMacOSXInt.h: tkMenuCascadeRgn clipping code. * macosx/tkMacOSXMenu.c: * macosx/tkMacOSXHLEvents.c: replace Tcl_GlobalEval() resp. Tcl_Eval() * macosx/tkMacOSXScrlbr.c: by Tcl_EvalEx(). * macosx/tkMacOSXInit.c: * macosx/tkMacOSXInit.c (TkpInit): reorder initialization steps. * macosx/tkMacOSXKeyEvent.c: remove pre-10.2 support. * macosx/tkMacOSXMenus.c: remove now useless call to TkMacOSXHandleTearoffMenu(); use \x.. quoting for non-latin1 macroman literar chars to allow file to be edited as utf-8. * macosx/tkMacOSXScale.c: replace TrackControl() by modern * macosx/tkMacOSXScrlbr.c: HandleControlClick() API (using new TkMacOSXModifierState()). * macosx/tkMacOSXInt.h: move all constant #defines needed to * macosx/tkMacOSXColor.c: support building on older OS X releases * macosx/tkMacOSXEvent.h: to a central location in tkMacOSXInt.h. * macosx/tkMacOSXFont.c: * macosx/tkMacOSXMenu.c: * macosx/tkMacOSXMenubutton.c: * macosx/tkMacOSXMenus.c: * macosx/tkMacOSXMouseEvent.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXInt.h: add ChkErr() macro to factor out * macosx/tkMacOSXButton.c: Carbon OSStatus return value checking * macosx/tkMacOSXCarbonEvents.c: and TkMacOSXDbgMsg() macro to factour * macosx/tkMacOSXClipboard.c: out debug message output; use these * macosx/tkMacOSXColor.c: macros to replace #ifdef TK_MAC_DEBUG * macosx/tkMacOSXCursor.c: blocks & direct printing to stderr, * macosx/tkMacOSXDebug.c: and to do additional OSStatus return * macosx/tkMacOSXDialog.c: checking, and to standardize OSStatus * macosx/tkMacOSXDraw.c: usage. * macosx/tkMacOSXEntry.c: * macosx/tkMacOSXEvent.c: * macosx/tkMacOSXFont.c: * macosx/tkMacOSXHLEvents.c: * macosx/tkMacOSXInit.c: * macosx/tkMacOSXKeyEvent.c: * macosx/tkMacOSXMenu.c: * macosx/tkMacOSXMenubutton.c: * macosx/tkMacOSXMenus.c: * macosx/tkMacOSXMouseEvent.c: * macosx/tkMacOSXScrlbr.c: * macosx/tkMacOSXSubwindows.c: * macosx/tkMacOSXWindowEvent.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXXStubs.c: * macosx/tkMacOSXSend.c: remove duplicate/unused declarations. * macosx/tkMacOSXXStubs.c: * macosx/tkMacOSXDebug.c: const fixes. * macosx/tkMacOSXInit.c: * macosx/tkMacOSXTest.c: * macosx/tkMacOSXWm.c: * macosx/tkMacOSXXStubs.c: * macosx/Wish-Info.plist.in: add tcl document extensions/mime types and LSMinimumSystemVersion, LSRequiresCarbon & NSAppleScriptEnabled keys. * macosx/tkMacOSXAETE.r: fix whitespace. * macosx/tkMacOSXConfig.c: * macosx/tkMacOSXCursors.r: * macosx/tkMacOSXKeyboard.c: * macosx/tkMacOSXSend.c: * macosx/tkMacOSXXCursors.r: * macosx/README: * macosx/Makefile: fix/add copyright and license refs. * macosx/Tk-Info.plist.in: * macosx/Wish-Info.plist.in: * macosx/tkMacOSX.h:
Diffstat (limited to 'macosx/tkMacOSXColor.c')
-rw-r--r--macosx/tkMacOSXColor.c905
1 files changed, 553 insertions, 352 deletions
diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c
index 33e39a7..c3a5bc7 100644
--- a/macosx/tkMacOSXColor.c
+++ b/macosx/tkMacOSXColor.c
@@ -1,197 +1,527 @@
-/*
+/*
* 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.
+ * 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.
+ * Copyright (c) 2006-2007 Daniel A. Steffen <das@users.sourceforge.net>
*
* 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.2.4 2006/09/11 14:41:16 das Exp $
+ * RCS: @(#) $Id: tkMacOSXColor.c,v 1.2.2.5 2007/04/29 02:26:48 das Exp $
*/
#include "tkMacOSXInt.h"
#include "tkColor.h"
-/* Define constants only available on Mac OS X 10.3 or later */
-#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030
- #define kThemeBrushAlternatePrimaryHighlightColor -5
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040
+/* Undocumented CG API for creating CGPattern from CGImage */
+extern CGPatternRef CGPatternCreateWithImage(CGImageRef img, int i) WEAK_IMPORT_ATTRIBUTE;
#endif
+struct SystemColorMapEntry {
+ const char *name;
+ ThemeBrush brush;
+ ThemeTextColor textColor;
+ ThemeBackgroundKind background;
+}; /* unsigned char pixelCode; */
+
/*
- * 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.
+ * Array of system color definitions: the array index is required to equal the
+ * color's (pixelCode - MIN_PIXELCODE), i.e. the array order needs to be kept
+ * in sync with the public pixel code values in tkMacOSXPort.h !
*/
+
+#define MIN_PIXELCODE 30
+static const struct SystemColorMapEntry systemColorMap[] = {
+ { "Transparent", 0, 0, 0 }, /* 30: TRANSPARENT_PIXEL */
+ { "Highlight", kThemeBrushPrimaryHighlightColor, 0, 0 }, /* 31: HIGHLIGHT_PIXEL */
+ { "HighlightSecondary", kThemeBrushSecondaryHighlightColor, 0, 0 }, /* 32: HIGHLIGHT_SECONDARY_PIXEL */
+ { "HighlightText", kThemeBrushBlack, 0, 0 }, /* 33: HIGHLIGHT_TEXT_PIXEL */
+ { "HighlightAlternate", kThemeBrushAlternatePrimaryHighlightColor, 0, 0 }, /* 34: HIGHLIGHT_ALTERNATE_PIXEL */
+ { "ButtonText", 0, kThemeTextColorPushButtonActive, 0 }, /* 35: CONTROL_TEXT_PIXEL */
+ { "PrimaryHighlightColor", kThemeBrushPrimaryHighlightColor, 0, 0 }, /* 36 */
+ { "ButtonFace", kThemeBrushButtonFaceActive, 0, 0 }, /* 37: CONTROL_BODY_PIXEL */
+ { "SecondaryHighlightColor", kThemeBrushSecondaryHighlightColor, 0, 0 }, /* 38 */
+ { "ButtonFrame", kThemeBrushButtonFrameActive, 0, 0 }, /* 39: CONTROL_FRAME_PIXEL */
+ { "AlternatePrimaryHighlightColor", kThemeBrushAlternatePrimaryHighlightColor, 0, 0 }, /* 40 */
+ { "WindowBody", kThemeBrushDocumentWindowBackground, 0, 0 }, /* 41: WINDOW_BODY_PIXEL */
+ { "SheetBackground", kThemeBrushSheetBackground, 0, 0 }, /* 42 */
+ { "MenuActive", kThemeBrushMenuBackgroundSelected, 0, 0 }, /* 43: MENU_ACTIVE_PIXEL */
+ { "Black", kThemeBrushBlack, 0, 0 }, /* 44 */
+ { "MenuActiveText", 0, kThemeTextColorMenuItemSelected, 0 }, /* 45: MENU_ACTIVE_TEXT_PIXEL */
+ { "White", kThemeBrushWhite, 0, 0 }, /* 46 */
+ { "Menu", kThemeBrushMenuBackground, 0, 0 }, /* 47: MENU_BACKGROUND_PIXEL */
+ { "DialogBackgroundActive", kThemeBrushDialogBackgroundActive, 0, 0 }, /* 48 */
+ { "MenuDisabled", 0, kThemeTextColorMenuItemDisabled, 0 }, /* 49: MENU_DISABLED_PIXEL */
+ { "DialogBackgroundInactive", kThemeBrushDialogBackgroundInactive, 0, 0 }, /* 50 */
+ { "MenuText", 0, kThemeTextColorMenuItemActive, 0 }, /* 51: MENU_TEXT_PIXEL */
+ { "AppearanceColor", 0, 0, 0 }, /* 52: APPEARANCE_PIXEL */
+ { "AlertBackgroundActive", kThemeBrushAlertBackgroundActive, 0, 0 }, /* 53 */
+ { "AlertBackgroundInactive", kThemeBrushAlertBackgroundInactive, 0, 0 }, /* 54 */
+ { "ModelessDialogBackgroundActive", kThemeBrushModelessDialogBackgroundActive, 0, 0 }, /* 55 */
+ { "ModelessDialogBackgroundInactive", kThemeBrushModelessDialogBackgroundInactive, 0, 0 }, /* 56 */
+ { "UtilityWindowBackgroundActive", kThemeBrushUtilityWindowBackgroundActive, 0, 0 }, /* 57 */
+ { "UtilityWindowBackgroundInactive", kThemeBrushUtilityWindowBackgroundInactive, 0, 0 }, /* 58 */
+ { "ListViewSortColumnBackground", kThemeBrushListViewSortColumnBackground, 0, 0 }, /* 59 */
+ { "ListViewBackground", kThemeBrushListViewBackground, 0, 0 }, /* 60 */
+ { "IconLabelBackground", kThemeBrushIconLabelBackground, 0, 0 }, /* 61 */
+ { "ListViewSeparator", kThemeBrushListViewSeparator, 0, 0 }, /* 62 */
+ { "ChasingArrows", kThemeBrushChasingArrows, 0, 0 }, /* 63 */
+ { "DragHilite", kThemeBrushDragHilite, 0, 0 }, /* 64 */
+ { "DocumentWindowBackground", kThemeBrushDocumentWindowBackground, 0, 0 }, /* 65 */
+ { "FinderWindowBackground", kThemeBrushFinderWindowBackground, 0, 0 }, /* 66 */
+ { "ScrollBarDelimiterActive", kThemeBrushScrollBarDelimiterActive, 0, 0 }, /* 67 */
+ { "ScrollBarDelimiterInactive", kThemeBrushScrollBarDelimiterInactive, 0, 0 }, /* 68 */
+ { "FocusHighlight", kThemeBrushFocusHighlight, 0, 0 }, /* 69 */
+ { "PopupArrowActive", kThemeBrushPopupArrowActive, 0, 0 }, /* 70 */
+ { "PopupArrowPressed", kThemeBrushPopupArrowPressed, 0, 0 }, /* 71 */
+ { "PopupArrowInactive", kThemeBrushPopupArrowInactive, 0, 0 }, /* 72 */
+ { "AppleGuideCoachmark", kThemeBrushAppleGuideCoachmark, 0, 0 }, /* 73 */
+ { "IconLabelBackgroundSelected", kThemeBrushIconLabelBackgroundSelected, 0, 0 }, /* 74 */
+ { "StaticAreaFill", kThemeBrushStaticAreaFill, 0, 0 }, /* 75 */
+ { "ActiveAreaFill", kThemeBrushActiveAreaFill, 0, 0 }, /* 76 */
+ { "ButtonFrameActive", kThemeBrushButtonFrameActive, 0, 0 }, /* 77 */
+ { "ButtonFrameInactive", kThemeBrushButtonFrameInactive, 0, 0 }, /* 78 */
+ { "ButtonFaceActive", kThemeBrushButtonFaceActive, 0, 0 }, /* 79 */
+ { "ButtonFaceInactive", kThemeBrushButtonFaceInactive, 0, 0 }, /* 80 */
+ { "ButtonFacePressed", kThemeBrushButtonFacePressed, 0, 0 }, /* 81 */
+ { "ButtonActiveDarkShadow", kThemeBrushButtonActiveDarkShadow, 0, 0 }, /* 82 */
+ { "ButtonActiveDarkHighlight", kThemeBrushButtonActiveDarkHighlight, 0, 0 }, /* 83 */
+ { "ButtonActiveLightShadow", kThemeBrushButtonActiveLightShadow, 0, 0 }, /* 84 */
+ { "ButtonActiveLightHighlight", kThemeBrushButtonActiveLightHighlight, 0, 0 }, /* 85 */
+ { "ButtonInactiveDarkShadow", kThemeBrushButtonInactiveDarkShadow, 0, 0 }, /* 86 */
+ { "ButtonInactiveDarkHighlight", kThemeBrushButtonInactiveDarkHighlight, 0, 0 }, /* 87 */
+ { "ButtonInactiveLightShadow", kThemeBrushButtonInactiveLightShadow, 0, 0 }, /* 88 */
+ { "ButtonInactiveLightHighlight", kThemeBrushButtonInactiveLightHighlight, 0, 0 }, /* 89 */
+ { "ButtonPressedDarkShadow", kThemeBrushButtonPressedDarkShadow, 0, 0 }, /* 90 */
+ { "ButtonPressedDarkHighlight", kThemeBrushButtonPressedDarkHighlight, 0, 0 }, /* 91 */
+ { "ButtonPressedLightShadow", kThemeBrushButtonPressedLightShadow, 0, 0 }, /* 92 */
+ { "ButtonPressedLightHighlight", kThemeBrushButtonPressedLightHighlight, 0, 0 }, /* 93 */
+ { "BevelActiveLight", kThemeBrushBevelActiveLight, 0, 0 }, /* 94 */
+ { "BevelActiveDark", kThemeBrushBevelActiveDark, 0, 0 }, /* 95 */
+ { "BevelInactiveLight", kThemeBrushBevelInactiveLight, 0, 0 }, /* 96 */
+ { "BevelInactiveDark", kThemeBrushBevelInactiveDark, 0, 0 }, /* 97 */
+ { "NotificationWindowBackground", kThemeBrushNotificationWindowBackground, 0, 0 }, /* 98 */
+ { "MovableModalBackground", kThemeBrushMovableModalBackground, 0, 0 }, /* 99 */
+ { "SheetBackgroundOpaque", kThemeBrushSheetBackgroundOpaque, 0, 0 }, /* 100 */
+ { "DrawerBackground", kThemeBrushDrawerBackground, 0, 0 }, /* 101 */
+ { "ToolbarBackground", kThemeBrushToolbarBackground, 0, 0 }, /* 102 */
+ { "SheetBackgroundTransparent", kThemeBrushSheetBackgroundTransparent, 0, 0 }, /* 103 */
+ { "MenuBackground", kThemeBrushMenuBackground, 0, 0 }, /* 104 */
+ { "Pixel", 0, 0, 0 }, /* 105: PIXEL_MAGIC */
+ { "MenuBackgroundSelected", kThemeBrushMenuBackgroundSelected, 0, 0 }, /* 106 */
+ { "ListViewOddRowBackground", kThemeBrushListViewOddRowBackground, 0, 0 }, /* 107 */
+ { "ListViewEvenRowBackground", kThemeBrushListViewEvenRowBackground, 0, 0 }, /* 108 */
+ { "ListViewColumnDivider", kThemeBrushListViewColumnDivider, 0, 0 }, /* 109 */
+ { "BlackText", 0, kThemeTextColorBlack, 0 }, /* 110 */
+ { "DialogActiveText", 0, kThemeTextColorDialogActive, 0 }, /* 111 */
+ { "DialogInactiveText", 0, kThemeTextColorDialogInactive, 0 }, /* 112 */
+ { "AlertActiveText", 0, kThemeTextColorAlertActive, 0 }, /* 113 */
+ { "AlertInactiveText", 0, kThemeTextColorAlertInactive, 0 }, /* 114 */
+ { "ModelessDialogActiveText", 0, kThemeTextColorModelessDialogActive, 0 }, /* 115 */
+ { "ModelessDialogInactiveText", 0, kThemeTextColorModelessDialogInactive, 0 }, /* 116 */
+ { "WindowHeaderActiveText", 0, kThemeTextColorWindowHeaderActive, 0 }, /* 117 */
+ { "WindowHeaderInactiveText", 0, kThemeTextColorWindowHeaderInactive, 0 }, /* 118 */
+ { "PlacardActiveText", 0, kThemeTextColorPlacardActive, 0 }, /* 119 */
+ { "PlacardInactiveText", 0, kThemeTextColorPlacardInactive, 0 }, /* 120 */
+ { "PlacardPressedText", 0, kThemeTextColorPlacardPressed, 0 }, /* 121 */
+ { "PushButtonActiveText", 0, kThemeTextColorPushButtonActive, 0 }, /* 122 */
+ { "PushButtonInactiveText", 0, kThemeTextColorPushButtonInactive, 0 }, /* 123 */
+ { "PushButtonPressedText", 0, kThemeTextColorPushButtonPressed, 0 }, /* 124 */
+ { "BevelButtonActiveText", 0, kThemeTextColorBevelButtonActive, 0 }, /* 125 */
+ { "BevelButtonInactiveText", 0, kThemeTextColorBevelButtonInactive, 0 }, /* 126 */
+ { "BevelButtonPressedText", 0, kThemeTextColorBevelButtonPressed, 0 }, /* 127 */
+ { "PopupButtonActiveText", 0, kThemeTextColorPopupButtonActive, 0 }, /* 128 */
+ { "PopupButtonInactiveText", 0, kThemeTextColorPopupButtonInactive, 0 }, /* 129 */
+ { "PopupButtonPressedText", 0, kThemeTextColorPopupButtonPressed, 0 }, /* 130 */
+ { "IconLabelText", 0, kThemeTextColorIconLabel, 0 }, /* 131 */
+ { "ListViewText", 0, kThemeTextColorListView, 0 }, /* 132 */
+ { "DocumentWindowTitleActiveText", 0, kThemeTextColorDocumentWindowTitleActive, 0 }, /* 133 */
+ { "DocumentWindowTitleInactiveText", 0, kThemeTextColorDocumentWindowTitleInactive, 0 }, /* 134 */
+ { "MovableModalWindowTitleActiveText", 0, kThemeTextColorMovableModalWindowTitleActive, 0 }, /* 135 */
+ { "MovableModalWindowTitleInactiveText",0, kThemeTextColorMovableModalWindowTitleInactive, 0 }, /* 136 */
+ { "UtilityWindowTitleActiveText", 0, kThemeTextColorUtilityWindowTitleActive, 0 }, /* 137 */
+ { "UtilityWindowTitleInactiveText", 0, kThemeTextColorUtilityWindowTitleInactive, 0 }, /* 138 */
+ { "PopupWindowTitleActiveText", 0, kThemeTextColorPopupWindowTitleActive, 0 }, /* 139 */
+ { "PopupWindowTitleInactiveText", 0, kThemeTextColorPopupWindowTitleInactive, 0 }, /* 140 */
+ { "RootMenuActiveText", 0, kThemeTextColorRootMenuActive, 0 }, /* 141 */
+ { "RootMenuSelectedText", 0, kThemeTextColorRootMenuSelected, 0 }, /* 142 */
+ { "RootMenuDisabledText", 0, kThemeTextColorRootMenuDisabled, 0 }, /* 143 */
+ { "MenuItemActiveText", 0, kThemeTextColorMenuItemActive, 0 }, /* 144 */
+ { "MenuItemSelectedText", 0, kThemeTextColorMenuItemSelected, 0 }, /* 145 */
+ { "MenuItemDisabledText", 0, kThemeTextColorMenuItemDisabled, 0 }, /* 146 */
+ { "PopupLabelActiveText", 0, kThemeTextColorPopupLabelActive, 0 }, /* 147 */
+ { "PopupLabelInactiveText", 0, kThemeTextColorPopupLabelInactive, 0 }, /* 148 */
+ { "TabFrontActiveText", 0, kThemeTextColorTabFrontActive, 0 }, /* 149 */
+ { "TabNonFrontActiveText", 0, kThemeTextColorTabNonFrontActive, 0 }, /* 150 */
+ { "TabNonFrontPressedText", 0, kThemeTextColorTabNonFrontPressed, 0 }, /* 151 */
+ { "TabFrontInactiveText", 0, kThemeTextColorTabFrontInactive, 0 }, /* 152 */
+ { "TabNonFrontInactiveText", 0, kThemeTextColorTabNonFrontInactive, 0 }, /* 153 */
+ { "IconLabelSelectedText", 0, kThemeTextColorIconLabelSelected, 0 }, /* 154 */
+ { "BevelButtonStickyActiveText", 0, kThemeTextColorBevelButtonStickyActive, 0 }, /* 155 */
+ { "BevelButtonStickyInactiveText", 0, kThemeTextColorBevelButtonStickyInactive, 0 }, /* 156 */
+ { "NotificationText", 0, kThemeTextColorNotification, 0 }, /* 157 */
+ { "SystemDetailText", 0, kThemeTextColorSystemDetail, 0 }, /* 158 */
+ { "WhiteText", 0, kThemeTextColorWhite, 0 }, /* 159 */
+ { "TabPaneBackground", 0, 0, kThemeBackgroundTabPane }, /* 160 */
+ { "PlacardBackground", 0, 0, kThemeBackgroundPlacard }, /* 161 */
+ { "WindowHeaderBackground", 0, 0, kThemeBackgroundWindowHeader }, /* 162 */
+ { "ListViewWindowHeaderBackground", 0, 0, kThemeBackgroundListViewWindowHeader }, /* 163 */
+ { "SecondaryGroupBoxBackground", 0, 0, kThemeBackgroundSecondaryGroupBox }, /* 164 */
+ { "MetalBackground", 0, 0, kThemeBackgroundMetal }, /* 165 */
+ { NULL, 0, 0, 0 }
+};
+#define MAX_PIXELCODE 165
+
/*
- * Stubbed out for OS X
-static AuxCtlHandle defaultAuxCtlHandle = NULL;
-*/
+ *----------------------------------------------------------------------
+ *
+ * GetThemeFromPixelCode --
+ *
+ * When given a pixel code corresponding to a theme system color,
+ * set one of brush, textColor or background to the corresponding
+ * Appearance Mgr theme constant.
+ *
+ * Results:
+ * Returns false if not a real pixel, true otherwise.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+static int
+GetThemeFromPixelCode(unsigned char code, ThemeBrush *brush,
+ ThemeTextColor *textColor, ThemeBackgroundKind *background)
+{
+ if (code >= MIN_PIXELCODE && code <= MAX_PIXELCODE && code != PIXEL_MAGIC) {
+ *brush = systemColorMap[code - MIN_PIXELCODE].brush;
+ *textColor = systemColorMap[code - MIN_PIXELCODE].textColor;
+ *background = systemColorMap[code - MIN_PIXELCODE].background;
+ } else {
+ *brush = 0;
+ *textColor = 0;
+ *background = 0;
+ }
+ if (!*brush && !*textColor && !*background && code != PIXEL_MAGIC) {
+ return false;
+ } else {
+ return true;
+ }
+}
+
/*
- * Forward declarations for procedures defined later in this file:
+ *----------------------------------------------------------------------
+ *
+ * GetThemeColor --
+ *
+ * Get RGB color for a given system color or pixel value.
+ *
+ * Results:
+ * OSStatus
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
*/
-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));
+static OSStatus
+GetThemeColor(unsigned long pixel, ThemeBrush brush, ThemeTextColor textColor,
+ ThemeBackgroundKind background, RGBColor *c)
+{
+ OSStatus err = noErr;
+
+ if (brush) {
+ err = ChkErr(GetThemeBrushAsColor,
+ brush == kThemeBrushMenuBackgroundSelected ?
+ kThemeBrushFocusHighlight : brush, 32, true, c);
+ } else if (textColor) {
+ err = ChkErr(GetThemeTextColor, textColor, 32, true, c);
+ } else {
+ c->red = ((pixel >> 16) & 0xff) << 8;
+ c->green = ((pixel >> 8) & 0xff) << 8;
+ c->blue = ((pixel ) & 0xff) << 8;
+ }
+ return err;
+}
/*
*----------------------------------------------------------------------
*
* TkSetMacColor --
*
- * Populates a Macintosh RGBColor structure from a X style
- * pixel value.
+ * Populates a Macintosh RGBColor structure from a X style
+ * pixel value.
*
* Results:
- * Returns false if not a real pixel, true otherwise.
+ * Returns false if not a real pixel, true otherwise.
*
* Side effects:
- * The variable macColor is updated to the pixels value.
+ * 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. */
+ unsigned long pixel, /* Pixel value to convert. */
+ RGBColor *macColor) /* Mac color struct to modify. */
{
- OSStatus err;
+ OSStatus err = -1;
+ ThemeBrush brush;
+ ThemeTextColor textColor;
+ ThemeBackgroundKind background;
- switch (pixel >> 24) {
- case HIGHLIGHT_PIXEL:
- err = GetThemeBrushAsColor(kThemeBrushPrimaryHighlightColor,
- 32, true, macColor);
- if (err != noErr) {
- LMGetHiliteRGB(macColor);
- }
- return true;
- case HIGHLIGHT_SECONDARY_PIXEL:
- err = GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor,
- 32, true, macColor);
- if (err != noErr) {
- LMGetHiliteRGB(macColor);
- }
- return true;
- case HIGHLIGHT_ALTERNATE_PIXEL:
- err = GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor,
- 32, true, macColor);
- if (err != noErr) {
- LMGetHiliteRGB(macColor);
- }
- return true;
- case HIGHLIGHT_TEXT_PIXEL:
- err = GetThemeBrushAsColor(kThemeBrushPrimaryHighlightColor,
- 32, true, macColor);
- if (err != noErr) {
- 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;
+ if (GetThemeFromPixelCode((pixel >> 24) & 0xff, &brush, &textColor,
+ &background)) {
+ err = ChkErr(GetThemeColor, pixel, brush, textColor, background,
+ macColor);
}
+ return (err == noErr);
}
/*
*----------------------------------------------------------------------
*
- * Stub functions --
+ * TkMacOSXSetColorInPort --
*
- * These functions are just stubs for functions that either
- * don't make sense on the Mac or have yet to be implemented.
+ * Sets fore or back color in the current QD port from an X pixel
+ * value, and if the pixel code indicates a system color, sets
+ * the corresponding brush, textColor or background via
+ * Appearance mgr APIs.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * These calls do nothing - which may not be expected.
+ * If penPat is non-NULL it is set to the forground color/pattern.
*
*----------------------------------------------------------------------
*/
-Status
-XAllocColor(
- Display *display, /* Display. */
- Colormap map, /* Not used. */
- XColor *colorPtr) /* XColor struct to modify. */
+void
+TkMacOSXSetColorInPort(unsigned long pixel, int fg, PixPatHandle penPat)
{
- display->request++;
- colorPtr->pixel = TkpGetPixel(colorPtr);
- return 1;
-}
+ OSStatus err;
+ RGBColor c;
+ ThemeBrush brush;
+ ThemeTextColor textColor;
+ ThemeBackgroundKind background;
-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++;
-}
+ if (GetThemeFromPixelCode((pixel >> 24) & 0xff, &brush, &textColor,
+ &background)) {
+ CGrafPtr port;
-void
-XFreeColormap(
- Display* display, /* Display. */
- Colormap colormap) /* Colormap. */
-{
+ GetPort(&port);
+ err = ChkErr(GetThemeColor, pixel, brush, textColor, background, &c);
+ if (err == noErr) {
+ if (fg) {
+ RGBForeColor(&c);
+ if (penPat) {
+ MakeRGBPat(penPat, &c);
+ }
+ } else {
+ RGBBackColor(&c);
+ }
+ }
+ err = -1;
+ if (brush) {
+ err = ChkErr(SetThemeBackground,
+ brush == kThemeBrushMenuBackgroundSelected ?
+ kThemeBrushFocusHighlight : brush, 32, true);
+ } else if (textColor && fg) {
+ err = ChkErr(SetThemeTextColor, textColor, 32, true);
+ } else if (background) {
+ Rect bounds;
+
+ GetPortBounds(port, &bounds);
+ err = ChkErr(ApplyThemeBackground, background, &bounds,
+ kThemeStateActive, 32, true);
+ }
+ if (penPat && err == noErr && !textColor) {
+ GetPortBackPixPat(port, penPat);
+ }
+ }
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TkMacOSXSetColorInContext --
+ *
+ * Sets fill and stroke color in the given CG context from an X
+ * pixel value, or if the pixel code indicates a system color,
+ * sets the corresponding brush, textColor or background via
+ * HITheme APIs if available or Appearance mgr APIs.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
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. */
+TkMacOSXSetColorInContext(unsigned long pixel, CGContextRef context)
{
- /*
- * 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.
- */
+ OSStatus err = -1;
+ RGBColor c;
+ ThemeBrush brush;
+ ThemeTextColor textColor;
+ ThemeBackgroundKind background;
+
+ if (GetThemeFromPixelCode((pixel >> 24) & 0xff, &brush, &textColor,
+ &background)) {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
+ if (brush) {
+ if (1
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040
+ && HIThemeSetFill != NULL && HIThemeSetStroke != NULL
+#endif
+ ) {
+ err = ChkErr(HIThemeSetFill, brush, NULL, context,
+ kHIThemeOrientationNormal);
+ if (err == noErr) {
+ err = ChkErr(HIThemeSetStroke, brush, NULL, context,
+ kHIThemeOrientationNormal);
+ }
+ }
+ } else if (textColor) {
+ if (1
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040
+ && HIThemeSetTextFill != NULL
+#endif
+ ) {
+ err = ChkErr(HIThemeSetTextFill, textColor, NULL, context,
+ kHIThemeOrientationNormal);
+ }
+ } else
+#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 */
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
+ if (background) {
+ if (1
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030
+ && CGContextGetClipBoundingBox != NULL
+ && HIThemeApplyBackground != NULL
+ && &kHIToolboxVersionNumber != NULL /* c.f. QA1377 */
+ && kHIToolboxVersionNumber >= kHIToolboxVersionNumber10_3
+#endif
+ ) {
+ CGRect rect = CGContextGetClipBoundingBox(context);
+ HIThemeBackgroundDrawInfo info = { 0, kThemeStateActive,
+ background };
+
+ err = ChkErr(HIThemeApplyBackground, &rect, &info, context,
+ kHIThemeOrientationNormal);
+ }
+ }
+#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */
+ if (err == noErr) {
+ return;
+ }
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040
+ /*
+ * Convert Appearance theme pattern to CGPattern:
+ */
+ if ((brush || background) && CGPatternCreateWithImage != NULL) {
+ static PixPatHandle pixpat = NULL;
+ static GWorldPtr patGWorld = NULL;
+ static uint32_t bitmapInfo = 0;
+ const short patDim = 16;
+ const Rect bounds = {0, 0, patDim, patDim};
+ CGrafPtr savePort;
+ Boolean portChanged;
+ PixMapHandle pixmap;
+ long rowbytes;
+ CGImageRef img;
+ CGColorSpaceRef rgbCspace;
+ CGDataProviderRef provider;
+
+ if (!pixpat) {
+ pixpat = NewPixPat();
+ err = ChkErr(NewGWorld, &patGWorld, 32, &bounds, NULL, NULL, 0
+#ifdef __LITTLE_ENDIAN__
+ | kNativeEndianPixMap
+#endif
+ );
+ if (!pixpat || err != noErr || !patGWorld) {
+ Tcl_Panic("TkMacOSXSetColorInContext(): "
+ "pattern initialization failed !");
+ }
+ bitmapInfo =
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
+ (1
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040
+ && &kHIToolboxVersionNumber != NULL
+ && kHIToolboxVersionNumber >= kHIToolboxVersionNumber10_4
+#endif
+ ) ? kCGBitmapByteOrder32Host :
+#endif
+ 0;
+ }
+ portChanged = QDSwapPort(patGWorld, &savePort);
+ TkMacOSXSetColorInPort(pixel, 1, pixpat);
+#ifdef TK_MAC_DEBUG
+ Rect patBounds;
+ GetPixBounds((**pixpat).patMap, &patBounds);
+ if (patBounds.right > patDim || patBounds.bottom > patDim) {
+ Tcl_Panic("TkMacOSXSetColorInContext(): "
+ "pattern larger than expected !");
+ }
+#endif /* TK_MAC_DEBUG */
+ FillCRect(&bounds, pixpat);
+ if (portChanged) {
+ QDSwapPort(savePort, NULL);
+ }
+ pixmap = GetPortPixMap(patGWorld);
+ rowbytes = GetPixRowBytes(pixmap);
+ provider = CGDataProviderCreateWithData(&patGWorld,
+ GetPixBaseAddr(pixmap), rowbytes * patDim, NULL);
+ rgbCspace = CGColorSpaceCreateDeviceRGB();
+ img = CGImageCreate(patDim, patDim, 8, 32,
+ rowbytes, rgbCspace, kCGImageAlphaFirst | bitmapInfo,
+ provider, NULL, 0, kCGRenderingIntentDefault);
+ CGColorSpaceRelease(rgbCspace);
+ CGDataProviderRelease(provider);
+ if (img) {
+ CGPatternRef pat = CGPatternCreateWithImage(img, 2);
+ CGColorSpaceRef patCSpace = CGColorSpaceCreatePattern(NULL);
+ const float alpha = 1;
+
+ CGContextSetFillColorSpace(context, patCSpace);
+ CGContextSetFillPattern(context, pat, &alpha);
+ CGContextSetStrokeColorSpace(context, patCSpace);
+ CGContextSetStrokePattern(context, pat, &alpha);
+ CGColorSpaceRelease(patCSpace);
+ CGPatternRelease(pat);
+ CGImageRelease(img);
+ return;
+ }
+ }
+#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1040 */
+ err = ChkErr(GetThemeColor, pixel, brush, textColor, background, &c);
+ if (err == noErr) {
+ double r = c.red / 65535.0;
+ double g = c.green / 65535.0;
+ double b = c.blue / 65535.0;
+
+ CGContextSetRGBFillColor(context, r, g, b, 1.0);
+ CGContextSetRGBStrokeColor(context, r, g, b, 1.0);
+ }
+ } else if (((pixel >> 24) & 0xff) == TRANSPARENT_PIXEL) {
+ CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0);
+ CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.0);
+ }
}
/*
@@ -199,24 +529,24 @@ XFreeColors(
*
* TkpGetColor --
*
- * Allocate a new TkColor for the color with the given name.
+ * Allocate a new TkColor for the color with the given name.
*
* Results:
- * Returns a newly allocated TkColor, or NULL on failure.
+ * 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.
+ * 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). */
+ 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);
@@ -224,116 +554,43 @@ TkpGetColor(
XColor color;
/*
- * Check to see if this is a system color. Otherwise, XParseColor
+ * Check to see if this is a system color. Otherwise, XParseColor
* will do all the work.
*/
if (strncasecmp(name, "system", 6) == 0) {
- OSStatus err;
- int foundSystemColor = false;
- RGBColor rgbValue;
- char pixelCode = 0;
-
- if (!strcasecmp(name+6, "Highlight")) {
- err = GetThemeBrushAsColor(kThemeBrushPrimaryHighlightColor,
- 32, true, &rgbValue);
- if (err != noErr) {
- LMGetHiliteRGB(&rgbValue);
- }
- pixelCode = HIGHLIGHT_PIXEL;
- foundSystemColor = true;
- } else if (!strcasecmp(name+6, "HighlightSecondary")) {
- err = GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor,
- 32, true, &rgbValue);
- if (err != noErr) {
- LMGetHiliteRGB(&rgbValue);
- }
- pixelCode = HIGHLIGHT_SECONDARY_PIXEL;
- foundSystemColor = true;
- } else if (!strcasecmp(name+6, "HighlightAlternate")) {
- err = GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor,
- 32, true, &rgbValue);
- if (err != noErr) {
- LMGetHiliteRGB(&rgbValue);
- }
- pixelCode = HIGHLIGHT_ALTERNATE_PIXEL;
- foundSystemColor = true;
- } else if (!strcasecmp(name+6, "HighlightText")) {
- err = GetThemeBrushAsColor(kThemeBrushPrimaryHighlightColor,
- 32, true, &rgbValue);
- if (err != noErr) {
- LMGetHiliteRGB(&rgbValue);
+ Tcl_Obj *strPtr = Tcl_NewStringObj(name+6, -1);
+ int idx, result;
+
+ result = Tcl_GetIndexFromObjStruct(NULL, strPtr, systemColorMap,
+ sizeof(struct SystemColorMapEntry), NULL, TCL_EXACT, &idx);
+ Tcl_DecrRefCount(strPtr);
+ if (result == TCL_OK) {
+ OSStatus err;
+ RGBColor c;
+ unsigned char pixelCode = idx + MIN_PIXELCODE;
+ ThemeBrush brush = systemColorMap[idx].brush;
+ ThemeTextColor textColor = systemColorMap[idx].textColor;
+ ThemeBackgroundKind background = systemColorMap[idx].background;
+
+ err = ChkErr(GetThemeColor, 0, brush, textColor, background, &c);
+ if (err == noErr) {
+ color.red = c.red;
+ color.green = c.green;
+ color.blue = c.blue;
+ color.pixel = ((((((pixelCode << 8)
+ | ((color.red >> 8) & 0xff)) << 8)
+ | ((color.green >> 8) & 0xff)) << 8)
+ | ((color.blue >> 8) & 0xff));
+ goto validXColor;
}
- 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;
+ return (TkColor *) NULL;
}
-
+
+validXColor:
tkColPtr = (TkColor *) ckalloc(sizeof(TkColor));
tkColPtr->color = color;
@@ -345,28 +602,28 @@ TkpGetColor(
*
* 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.
+ * 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.
+ * 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.
+ * 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. */
+ 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));
@@ -380,120 +637,64 @@ TkpGetColorByValue(
/*
*----------------------------------------------------------------------
*
- * GetControlPartColor --
+ * Stub functions --
*
- * Given a part number this function will return the standard
- * system default color for that part. On MacOS X this uses the
- * Theme Brushes to find the active color, though for now, only
- * the "Text Color" is supported.
+ * These functions are just stubs for functions that either
+ * don't make sense on the Mac or have yet to be implemented.
*
* Results:
- * True if a color is found, false otherwise.
+ * None.
*
* Side effects:
- * If a color is found then the RGB variable will be changed to
- * the parts color.
+ * These calls do nothing - which may not be expected.
*
*----------------------------------------------------------------------
*/
-static int
-GetControlPartColor(
- short part, /* Part code. */
- RGBColor *macColor) /* Pointer to Mac color. */
+Status
+XAllocColor(
+ Display *display, /* Display. */
+ Colormap map, /* Not used. */
+ XColor *colorPtr) /* XColor struct to modify. */
{
- int retVal = false;
- OSErr err;
-
- switch (part) {
- case cTextColor:
- err = GetThemeTextColor(kThemeTextColorPushButtonActive, 32,
- true, macColor);
- if (err == noErr) {
- retVal = true;
- }
- break;
- default:
- retVal = false;
- }
- return retVal;
+ display->request++;
+ colorPtr->pixel = TkpGetPixel(colorPtr);
+ return 1;
}
-
-/*
- *----------------------------------------------------------------------
- *
- * 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. */
+Colormap
+XCreateColormap(
+ Display *display, /* Display. */
+ Window window, /* X window. */
+ Visual *visual, /* Not used. */
+ int alloc) /* Not used. */
{
- short index;
- WCTabHandle wcTab;
+ static Colormap index = 1;
- 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;
- }
+ /*
+ * Just return a new value each time.
+ */
+ return index++;
}
-
-/*
- *----------------------------------------------------------------------
- *
- * 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 */
+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. */
{
-
- /* 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;
+ /*
+ * 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.
+ */
}