diff options
author | Kevin Walzer <kw@codebykevin.com> | 2012-09-12 03:05:29 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2012-09-12 03:05:29 (GMT) |
commit | 4d00df90e7901e55bc22ae2b9589a9c005f6d9f7 (patch) | |
tree | 531b9edd57ee78802a71cb6c0fd09a0367f59211 /macosx/ttkMacOSXTheme.c | |
parent | 799666382d309825a9bd5d7205fd05662a742391 (diff) | |
download | tk-4d00df90e7901e55bc22ae2b9589a9c005f6d9f7.zip tk-4d00df90e7901e55bc22ae2b9589a9c005f6d9f7.tar.gz tk-4d00df90e7901e55bc22ae2b9589a9c005f6d9f7.tar.bz2 |
Review branch for merge of Tk-Cocoa into Tk 8.5 main branch
Diffstat (limited to 'macosx/ttkMacOSXTheme.c')
-rw-r--r-- | macosx/ttkMacOSXTheme.c | 546 |
1 files changed, 307 insertions, 239 deletions
diff --git a/macosx/ttkMacOSXTheme.c b/macosx/ttkMacOSXTheme.c index e5ae257..80f00f7 100644 --- a/macosx/ttkMacOSXTheme.c +++ b/macosx/ttkMacOSXTheme.c @@ -5,7 +5,9 @@ * * Copyright (c) 2004 Joe English * Copyright (c) 2005 Neil Madden - * Copyright (c) 2006-2007 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright 2008-2009, Apple Inc. + * Copyright 2009 Kevin Walzer/WordTech Communications LLC. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -26,33 +28,23 @@ * The QuickDraw/Carbon coordinate system is relative to the * top-level window, not to the Tk_Window. BoxToRect() * accounts for this. + * + * RCS: @(#) $Id$ */ #include "tkMacOSXPrivate.h" #include "ttk/ttkTheme.h" -#if !defined(BUILD_tile) /* * Use this version in the core: */ #define BEGIN_DRAWING(d) { \ TkMacOSXDrawingContext dc; \ - if (!TkMacOSXSetupDrawingContext((d), NULL, 0, &dc)) {return;} + if (!TkMacOSXSetupDrawingContext((d), NULL, 1, &dc)) {return;} #define END_DRAWING \ TkMacOSXRestoreDrawingContext(&dc); } -#else /* BUILD_tile */ -/* - * TkMacOSXSetupDrawingContext is not available to extensions, - * need to do this the hard way in Tile: - */ -#define BEGIN_DRAWING(d) { \ - CGrafPtr saveWorld; GDHandle saveDevice; \ - GetGWorld(&saveWorld, &saveDevice); \ - SetGWorld(TkMacOSXGetDrawablePort(d), 0); \ - TkMacOSXSetUpClippingRgn(d); -#define END_DRAWING \ - SetGWorld(saveWorld,saveDevice); } -#endif /* defined(BUILD_TILE) */ + +#define HIOrientation kHIThemeOrientationNormal #ifdef __LP64__ #define RangeToFactor(maximum) (((double) (INT_MAX >> 1)) / (maximum)) @@ -69,48 +61,20 @@ * Convert a Ttk_Box in Tk coordinates relative to the given Drawable * to a native Rect relative to the containing port. */ -static inline Rect BoxToRect(Drawable d, Ttk_Box b) +static inline CGRect BoxToRect(Drawable d, Ttk_Box b) { MacDrawable *md = (MacDrawable*)d; - Rect rect; + CGRect rect; - rect.top = b.y + md->yOff; - rect.left = b.x + md->xOff; - rect.bottom = rect.top + b.height; - rect.right = rect.left + b.width; + rect.origin.y = b.y + md->yOff; + rect.origin.x = b.x + md->xOff; + rect.size.height = b.height; + rect.size.width = b.width; return rect; } /* - * PatternOrigin -- - * Compute brush pattern origin for a Drawable relative to a Tk_Window. - * - * Notes: This will only be nonzero if the Drawable is an off-screen pixmap. - * See also SF bug #1157739. - */ -static Point PatternOrigin(Tk_Window tkwin, Drawable d) -{ - MacDrawable *md = (MacDrawable*)d; - Rect bounds; - Point origin; - - TkMacOSXWinBounds((TkWindow *) tkwin, &bounds); - origin.h = md->xOff - bounds.left; - origin.v = md->yOff - bounds.top; - - return origin; -} - -/* - * DontErase -- - * No-op ThemeEraseProc, can be passed to DrawThemeButton &c. - */ -static void DontErase( - const Rect *bounds, UInt32 eraseData, SInt16 depth, Boolean isColorDev) -{ } - -/* * Table mapping Tk states to Appearance manager ThemeStates */ @@ -145,16 +109,16 @@ static Ttk_Padding ButtonMargins = {2,2,2,2}; typedef struct { ThemeButtonKind kind; ThemeMetric heightMetric; -} ThemeButtonParms; +} ThemeButtonParams; -static ThemeButtonParms - PushButtonParms = { kThemePushButton, kThemeMetricPushButtonHeight }, - CheckBoxParms = { kThemeCheckBox, kThemeMetricCheckBoxHeight }, - RadioButtonParms = { kThemeRadioButton, kThemeMetricRadioButtonHeight }, - BevelButtonParms = { kThemeBevelButton, NoThemeMetric }, - PopupButtonParms = { kThemePopupButton, kThemeMetricPopupButtonHeight }, - DisclosureParms = { kThemeDisclosureButton, kThemeMetricDisclosureTriangleHeight }, - ListHeaderParms = { kThemeListHeaderButton, kThemeMetricListHeaderHeight }; +static ThemeButtonParams + PushButtonParams = { kThemePushButton, kThemeMetricPushButtonHeight }, + CheckBoxParams = { kThemeCheckBox, kThemeMetricCheckBoxHeight }, + RadioButtonParams = { kThemeRadioButton, kThemeMetricRadioButtonHeight }, + BevelButtonParams = { kThemeBevelButton, NoThemeMetric }, + PopupButtonParams = { kThemePopupButton, kThemeMetricPopupButtonHeight }, + DisclosureParams = { kThemeDisclosureButton, kThemeMetricDisclosureTriangleHeight }, + ListHeaderParams = { kThemeListHeaderButton, kThemeMetricListHeaderHeight }; static Ttk_StateTable ButtonValueTable[] = { { kThemeButtonMixed, TTK_STATE_ALTERNATE, 0 }, @@ -173,16 +137,18 @@ static Ttk_StateTable ButtonAdornmentTable[] = { /* * computeButtonDrawInfo -- - * Fill in an appearance manager ThemeButtonDrawInfo record. + * Fill in an appearance manager HIThemeButtonDrawInfo record. */ -static ThemeButtonDrawInfo computeButtonDrawInfo( - ThemeButtonParms *parms, Ttk_State state) +static inline HIThemeButtonDrawInfo computeButtonDrawInfo( + ThemeButtonParams *params, Ttk_State state) { - ThemeButtonDrawInfo info; - - info.state = Ttk_StateTableLookup(ThemeStateTable, state); - info.value = Ttk_StateTableLookup(ButtonValueTable, state); - info.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state); + const HIThemeButtonDrawInfo info = { + .version = 0, + .state = Ttk_StateTableLookup(ThemeStateTable, state), + .kind = params ? params->kind : 0, + .value = Ttk_StateTableLookup(ButtonValueTable, state), + .adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state), + }; return info; } @@ -190,12 +156,12 @@ static void ButtonElementSizeNoPadding( void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - ThemeButtonParms *parms = clientData; + ThemeButtonParams *params = clientData; - if (parms->heightMetric != NoThemeMetric) { + if (params->heightMetric != NoThemeMetric) { SInt32 height; - ChkErr(GetThemeMetric, parms->heightMetric, &height); + ChkErr(GetThemeMetric, params->heightMetric, &height); *heightPtr = height; } } @@ -204,10 +170,10 @@ static void ButtonElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - ThemeButtonParms *parms = clientData; - ThemeButtonDrawInfo info = computeButtonDrawInfo(parms, 0); - static const Rect scratchBounds = {0, 0, 100, 100}; - Rect contentBounds; + ThemeButtonParams *params = clientData; + const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, 0); + static const CGRect scratchBounds = {{0, 0}, {100, 100}}; + CGRect contentBounds; ButtonElementSizeNoPadding( clientData, elementRecord, tkwin, @@ -218,13 +184,13 @@ static void ButtonElementSize( * for the content bounds of a dummy rectangle, then use * the difference as the padding. */ - ChkErr(GetThemeButtonContentBounds, - &scratchBounds, parms->kind, &info, &contentBounds); + ChkErr(HIThemeGetButtonContentBounds, + &scratchBounds, &info, &contentBounds); - paddingPtr->left = contentBounds.left; - paddingPtr->top = contentBounds.top; - paddingPtr->right = scratchBounds.right - contentBounds.right + 1; - paddingPtr->bottom = scratchBounds.bottom - contentBounds.bottom; + paddingPtr->left = CGRectGetMinX(contentBounds); + paddingPtr->top = CGRectGetMinY(contentBounds); + paddingPtr->right = CGRectGetMaxX(scratchBounds) - CGRectGetMaxX(contentBounds) + 1; + paddingPtr->bottom = CGRectGetMaxY(scratchBounds) - CGRectGetMaxY(contentBounds); /* * Now add a little extra padding to account for drop shadows. @@ -240,12 +206,12 @@ static void ButtonElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - ThemeButtonParms *parms = clientData; - ThemeButtonDrawInfo info = computeButtonDrawInfo(parms, state); - Rect bounds = BoxToRect(d, Ttk_PadBox(b, ButtonMargins)); + ThemeButtonParams *params = clientData; + CGRect bounds = BoxToRect(d, Ttk_PadBox(b, ButtonMargins)); + const HIThemeButtonDrawInfo info = computeButtonDrawInfo(params, state); BEGIN_DRAWING(d) - ChkErr(DrawThemeButton, &bounds, parms->kind, &info, NULL, NULL, NULL, 0); + ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); END_DRAWING } @@ -261,26 +227,77 @@ static Ttk_ElementSpec ButtonElementSpec = { * +++ Notebook elements. */ + +/* Tab position logic, c.f. ttkNotebook.c TabState() */ + +#define TTK_STATE_NOTEBOOK_FIRST TTK_STATE_USER1 +#define TTK_STATE_NOTEBOOK_LAST TTK_STATE_USER2 static Ttk_StateTable TabStyleTable[] = { - { kThemeTabFrontInactive, TTK_STATE_SELECTED|TTK_STATE_BACKGROUND, 0 }, - { kThemeTabNonFrontInactive, TTK_STATE_BACKGROUND, 0 }, - { kThemeTabFrontUnavailable, TTK_STATE_DISABLED|TTK_STATE_SELECTED, 0 }, - { kThemeTabNonFrontUnavailable, TTK_STATE_DISABLED, 0 }, - { kThemeTabFront, TTK_STATE_SELECTED, 0 }, - { kThemeTabNonFrontPressed, TTK_STATE_PRESSED, 0 }, - { kThemeTabNonFront, 0,0 } + { kThemeTabFrontInactive, TTK_STATE_SELECTED|TTK_STATE_BACKGROUND}, + { kThemeTabNonFrontInactive, TTK_STATE_BACKGROUND}, + { kThemeTabFrontUnavailable, TTK_STATE_DISABLED|TTK_STATE_SELECTED}, + { kThemeTabNonFrontUnavailable, TTK_STATE_DISABLED}, + { kThemeTabFront, TTK_STATE_SELECTED}, + { kThemeTabNonFrontPressed, TTK_STATE_PRESSED}, + { kThemeTabNonFront, 0} +}; + +static Ttk_StateTable TabAdornmentTable[] = { + { kHIThemeTabAdornmentNone, + TTK_STATE_NOTEBOOK_FIRST|TTK_STATE_NOTEBOOK_LAST}, + {kHIThemeTabAdornmentTrailingSeparator, TTK_STATE_NOTEBOOK_FIRST}, + {kHIThemeTabAdornmentNone, TTK_STATE_NOTEBOOK_LAST}, + {kHIThemeTabAdornmentTrailingSeparator, 0 }, +}; + +static Ttk_StateTable TabPositionTable[] = { + { kHIThemeTabPositionOnly, + TTK_STATE_NOTEBOOK_FIRST|TTK_STATE_NOTEBOOK_LAST}, + { kHIThemeTabPositionFirst, TTK_STATE_NOTEBOOK_FIRST}, + { kHIThemeTabPositionLast, TTK_STATE_NOTEBOOK_LAST}, + { kHIThemeTabPositionMiddle, 0 }, }; /* - * Quoth DrawThemeTab() reference manual: - * "Small tabs have a height of 16 pixels large tabs have a height of - * 21 pixels. (The widths of tabs are variable.) Additionally, the - * distance that the tab overlaps the pane must be included in the tab - * rectangle this overlap distance is always 3 pixels, although the - * 3-pixel overlap is only drawn for the front tab." + * Apple XHIG Tab View Specifications: + * + * Control sizes: Tab views are available in regular, small, and mini sizes. + * The tab height is fixed for each size, but you control the size of the pane + * area. The tab heights for each size are listed below: + * - Regular size: 20 pixels. + * - Small: 17 pixels. + * - Mini: 15 pixels. + * + * Label spacing and fonts: The tab labels should be in a font that’s + * proportional to the size of the tab view control. In addition, the label + * should be placed so that there are equal margins of space before and after + * it. The guidelines below provide the specifications you should use for tab + * labels: + * - Regular size: System font. Center in tab, leaving 12 pixels on each side. + * - Small: Small system font. Center in tab, leaving 10 pixels on each side. + * - Mini: Mini system font. Center in tab, leaving 8 pixels on each side. + * + * Control spacing: Whether you decide to inset a tab view in a window or + * extend its edges to the window sides and bottom, you should place the top + * edge of the tab view 12 or 14 pixels below the bottom edge of the title bar + * (or toolbar, if there is one). If you choose to inset a tab view in a + * window, you should leave a margin of 20 pixels between the sides and bottom + * of the tab view and the sides and bottom of the window (although 16 pixels + * is also an acceptable margin-width). If you need to provide controls below + * the tab view, leave enough space below the tab view so the controls are 20 + * pixels above the bottom edge of the window and 12 pixels between the tab + * view and the controls. + * If you choose to extend the tab view sides and bottom so that they meet the + * window sides and bottom, you should leave a margin of at least 20 pixels + * between the content in the tab view and the tab-view edges. + * + * <URL: http://developer.apple.com/documentation/userexperience/Conceptual/ + * AppleHIGuidelines/XHIGControls/XHIGControls.html#//apple_ref/doc/uid/ + * TP30000359-TPXREF116> */ -static const int TAB_HEIGHT = 21; -static const int TAB_OVERLAP = 3; + +static const int TAB_HEIGHT = 10; +static const int TAB_OVERLAP = 10; static void TabElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, @@ -293,12 +310,20 @@ static void TabElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - Rect bounds = BoxToRect(d, b); - ThemeTabStyle tabStyle = Ttk_StateTableLookup(TabStyleTable, state); - - bounds.bottom += TAB_OVERLAP; + CGRect bounds = BoxToRect(d, b); + HIThemeTabDrawInfo info = { + .version = 1, + .style = Ttk_StateTableLookup(TabStyleTable, state), + .direction = kThemeTabNorth, + .size = kHIThemeTabSizeNormal, + .adornment = Ttk_StateTableLookup(TabAdornmentTable, state), + .kind = kHIThemeTabKindNormal, + .position = Ttk_StateTableLookup(TabPositionTable, state), + }; + + bounds.size.height += TAB_OVERLAP; BEGIN_DRAWING(d) - ChkErr(DrawThemeTab, &bounds, tabStyle, kThemeTabNorth, 0, 0); + ChkErr(HIThemeDrawTab, &bounds, &info, dc.context, HIOrientation, NULL); END_DRAWING } @@ -317,19 +342,27 @@ static void PaneElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - /* Padding determined by trial-and-error */ - *paddingPtr = Ttk_MakePadding(2, 8, 2, 2); + *paddingPtr = Ttk_MakePadding(9, 5, 9, 9); } static void PaneElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - Rect bounds = BoxToRect(d, b); - ThemeDrawState drawState = Ttk_StateTableLookup(ThemeStateTable, state); - + CGRect bounds = BoxToRect(d, b); + HIThemeTabPaneDrawInfo info = { + .version = 1, + .state = Ttk_StateTableLookup(ThemeStateTable, state), + .direction = kThemeTabNorth, + .size = kHIThemeTabSizeNormal, + .kind = kHIThemeTabKindNormal, + .adornment = kHIThemeTabPaneAdornmentNormal, + }; + + bounds.origin.y -= TAB_OVERLAP; + bounds.size.height += TAB_OVERLAP; BEGIN_DRAWING(d) - ChkErr(DrawThemeTabPane, &bounds, drawState); + ChkErr(HIThemeDrawTabPane, &bounds, &info, dc.context, HIOrientation); END_DRAWING } @@ -362,11 +395,15 @@ static void GroupElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - Rect bounds = BoxToRect(d, b); - ThemeDrawState drawState = Ttk_StateTableLookup(ThemeStateTable, state); + CGRect bounds = BoxToRect(d, b); + const HIThemeGroupBoxDrawInfo info = { + .version = 0, + .state = Ttk_StateTableLookup(ThemeStateTable, state), + .kind = kHIThemeGroupBoxKindPrimaryOpaque, + }; BEGIN_DRAWING(d) - ChkErr(DrawThemePrimaryGroup, &bounds, drawState); + ChkErr(HIThemeDrawGroupBox, &bounds, &info, dc.context, HIOrientation); END_DRAWING } @@ -408,8 +445,13 @@ static void EntryElementDraw( EntryElement *e = elementRecord; Tk_3DBorder backgroundPtr = Tk_Get3DBorderFromObj(tkwin,e->backgroundObj); Ttk_Box inner = Ttk_PadBox(b, Ttk_UniformPadding(3)); - Rect bounds = BoxToRect(d, inner); - ThemeDrawState drawState = Ttk_StateTableLookup(ThemeStateTable, state); + CGRect bounds = BoxToRect(d, inner); + const HIThemeFrameDrawInfo info = { + .version = 0, + .kind = kHIThemeFrameTextFieldSquare, + .state = Ttk_StateTableLookup(ThemeStateTable, state), + .isFocused = state & TTK_STATE_FOCUS, + }; /* * Erase w/background color: @@ -419,10 +461,10 @@ static void EntryElementDraw( inner.x,inner.y, inner.width, inner.height); BEGIN_DRAWING(d) - ChkErr(DrawThemeEditTextFrame, &bounds, drawState); - if (state & TTK_STATE_FOCUS) { + ChkErr(HIThemeDrawFrame, &bounds, &info, dc.context, HIOrientation); + /*if (state & TTK_STATE_FOCUS) { ChkErr(DrawThemeFocusRect, &bounds, 1); - } + }*/ END_DRAWING } @@ -458,13 +500,17 @@ static void ComboboxElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - ThemeButtonParms *parms = clientData; - ThemeButtonDrawInfo info = computeButtonDrawInfo(parms, state); - Rect bounds = BoxToRect(d, Ttk_PadBox(b, ComboboxMargins)); + CGRect bounds = BoxToRect(d, Ttk_PadBox(b, ComboboxMargins)); + const HIThemeButtonDrawInfo info = { + .version = 0, + .state = Ttk_StateTableLookup(ThemeStateTable, state), + .kind = kThemeComboBox, + .value = Ttk_StateTableLookup(ButtonValueTable, state), + .adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state), + }; BEGIN_DRAWING(d) - ChkErr(DrawThemeButton, - &bounds, kThemeComboBox, &info, NULL, NULL, NULL, 0); + ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); END_DRAWING } @@ -501,20 +547,20 @@ static void SpinButtonElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - Rect bounds = BoxToRect(d, Ttk_PadBox(b, SpinbuttonMargins)); - ThemeButtonDrawInfo info; - + CGRect bounds = BoxToRect(d, Ttk_PadBox(b, SpinbuttonMargins)); /* @@@ can't currently distinguish PressedUp (== Pressed) from PressedDown; * ignore this bit for now [see #2219588] */ - info.state = Ttk_StateTableLookup(ThemeStateTable, - state & ~TTK_STATE_PRESSED); - info.value = Ttk_StateTableLookup(ButtonValueTable, state); - info.adornment = kThemeAdornmentNone; + const HIThemeButtonDrawInfo info = { + .version = 0, + .state = Ttk_StateTableLookup(ThemeStateTable, state & ~TTK_STATE_PRESSED), + .kind = kThemeIncDecButton, + .value = Ttk_StateTableLookup(ButtonValueTable, state), + .adornment = kThemeAdornmentNone, + }; BEGIN_DRAWING(d) - ChkErr(DrawThemeButton, - &bounds, kThemeIncDecButton, &info, NULL, NULL, NULL, 0); + ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); END_DRAWING } @@ -580,40 +626,37 @@ static void TrackElementDraw( { TrackElementData *data = clientData; TrackElement *elem = elementRecord; - double from = 0, to = 100, value = 0, factor; int orientation = TTK_ORIENT_HORIZONTAL; - ThemeTrackDrawInfo info; + double from = 0, to = 100, value = 0, factor; + Ttk_GetOrientFromObj(NULL, elem->orientObj, &orientation); Tcl_GetDoubleFromObj(NULL, elem->fromObj, &from); Tcl_GetDoubleFromObj(NULL, elem->toObj, &to); Tcl_GetDoubleFromObj(NULL, elem->valueObj, &value); - Ttk_GetOrientFromObj(NULL, elem->orientObj, &orientation); factor = RangeToFactor(to - from); - info.kind = data->kind; - info.bounds = BoxToRect(d, b); - info.min = (int) from * factor; - info.max = (int) to * factor; - info.value = (int) value * factor; - - info.attributes = orientation == TTK_ORIENT_HORIZONTAL - ? kThemeTrackHorizontal : 0; - info.attributes |= kThemeTrackShowThumb; - info.enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state); - - switch (data->kind) { - case kThemeProgressBar: - info.trackInfo.progress.phase = 0; /* 1-4: animation phase */ - break; - case kThemeSlider: - info.trackInfo.slider.pressState = 0; /* @@@ fill this in */ - info.trackInfo.slider.thumbDir = kThemeThumbPlain; - /* kThemeThumbUpward, kThemeThumbDownward, kThemeThumbPlain */ - break; + HIThemeTrackDrawInfo info = { + .version = 0, + .kind = data->kind, + .bounds = BoxToRect(d, b), + .min = from * factor, + .max = to * factor, + .value = value * factor, + .attributes = kThemeTrackShowThumb | + (orientation == TTK_ORIENT_HORIZONTAL ? + kThemeTrackHorizontal : 0), + .enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state), + .trackInfo.progress.phase = 0, + }; + + if (info.kind == kThemeSlider) { + info.trackInfo.slider.pressState = state & TTK_STATE_PRESSED ? + kThemeThumbPressed : 0; + info.trackInfo.slider.thumbDir = kThemeThumbPlain; } BEGIN_DRAWING(d) - ChkErr(DrawThemeTrack, &info, NULL, NULL, 0); + ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation); END_DRAWING } @@ -695,10 +738,8 @@ static void PbarElementDraw( Drawable d, Ttk_Box b, Ttk_State state) { PbarElement *pbar = elementRecord; - int orientation = TTK_ORIENT_HORIZONTAL; + int orientation = TTK_ORIENT_HORIZONTAL, phase = 0; double value = 0, maximum = 100, factor; - int phase = 0; - ThemeTrackDrawInfo info; Ttk_GetOrientFromObj(NULL, pbar->orientObj, &orientation); Tcl_GetDoubleFromObj(NULL, pbar->valueObj, &value); @@ -706,23 +747,23 @@ static void PbarElementDraw( Tcl_GetIntFromObj(NULL, pbar->phaseObj, &phase); factor = RangeToFactor(maximum); - if (!strcmp("indeterminate", Tcl_GetString(pbar->modeObj)) && value) { - info.kind = kThemeIndeterminateBar; - } else { - info.kind = kThemeProgressBar; - } - info.bounds = BoxToRect(d, b); - info.min = 0; - info.max = (int) maximum * factor; - info.value = (int) value * factor; - info.attributes = orientation == TTK_ORIENT_HORIZONTAL - ? kThemeTrackHorizontal : 0; - info.attributes |= kThemeTrackShowThumb; - info.enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state); - info.trackInfo.progress.phase = phase; + HIThemeTrackDrawInfo info = { + .version = 0, + .kind = (!strcmp("indeterminate", Tcl_GetString(pbar->modeObj)) && value) ? + kThemeIndeterminateBar : kThemeProgressBar, + .bounds = BoxToRect(d, b), + .min = 0, + .max = maximum * factor, + .value = value * factor, + .attributes = kThemeTrackShowThumb | + (orientation == TTK_ORIENT_HORIZONTAL ? + kThemeTrackHorizontal : 0), + .enableState = Ttk_StateTableLookup(ThemeTrackEnableTable, state), + .trackInfo.progress.phase = phase, + }; BEGIN_DRAWING(d) - ChkErr(DrawThemeTrack, &info, NULL, NULL, 0); + ChkErr(HIThemeDrawTrack, &info, NULL, dc.context, HIOrientation); END_DRAWING } @@ -753,16 +794,15 @@ static void SeparatorElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - Rect bounds = BoxToRect(d, b); - ThemeDrawState drawState; + CGRect bounds = BoxToRect(d, b); + const HIThemeSeparatorDrawInfo info = { + .version = 0, + /* Separator only supports kThemeStateActive, kThemeStateInactive */ + .state = Ttk_StateTableLookup(ThemeStateTable, state & TTK_STATE_BACKGROUND), + }; - /* - * DrawThemeSeparator only supports kThemeStateActive / kThemeStateInactive - */ - state &= TTK_STATE_BACKGROUND; - drawState = Ttk_StateTableLookup(ThemeStateTable, state); BEGIN_DRAWING(d) - ChkErr(DrawThemeSeparator, &bounds, drawState); + ChkErr(HIThemeDrawSeparator, &bounds, &info, dc.context, HIOrientation); END_DRAWING } @@ -784,29 +824,36 @@ static void SizegripElementSize( void *clientData, void *elementRecord, Tk_Window tkwin, int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr) { - Point origin = {0, 0}; - Rect bounds; - - ChkErr(GetThemeStandaloneGrowBoxBounds, - origin, sizegripGrowDirection, false, &bounds); - *widthPtr = bounds.right - bounds.left; - *heightPtr = bounds.bottom - bounds.top; + HIThemeGrowBoxDrawInfo info = { + .version = 0, + .state = kThemeStateActive, + .kind = kHIThemeGrowBoxKindNormal, + .direction = sizegripGrowDirection, + .size = kHIThemeGrowBoxSizeNormal, + }; + CGRect bounds = CGRectZero; + + ChkErr(HIThemeGetGrowBoxBounds, &bounds.origin, &info, &bounds); + *widthPtr = bounds.size.width; + *heightPtr = bounds.size.height; } static void SizegripElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { - Rect bounds = BoxToRect(d, b); - Point origin = {bounds.top, bounds.left}; - - /* Grow box only supports kThemeStateActive, kThemeStateInactive */ - state &= TTK_STATE_BACKGROUND; + CGRect bounds = BoxToRect(d, b); + HIThemeGrowBoxDrawInfo info = { + .version = 0, + /* Grow box only supports kThemeStateActive, kThemeStateInactive */ + .state = Ttk_StateTableLookup(ThemeStateTable, state & TTK_STATE_BACKGROUND), + .kind = kHIThemeGrowBoxKindNormal, + .direction = sizegripGrowDirection, + .size = kHIThemeGrowBoxSizeNormal, + }; BEGIN_DRAWING(d) - ChkErr(DrawThemeStandaloneGrowBox, - origin, sizegripGrowDirection, false, - Ttk_StateTableLookup(ThemeStateTable, state)); + ChkErr(HIThemeDrawGrowBox, &bounds.origin, &info, dc.context, HIOrientation); END_DRAWING } @@ -834,15 +881,15 @@ static void FillElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - Rect bounds = BoxToRect(d, b); + CGRect bounds = BoxToRect(d, b); ThemeBrush brush = (state & TTK_STATE_BACKGROUND) ? kThemeBrushModelessDialogBackgroundInactive : kThemeBrushModelessDialogBackgroundActive; BEGIN_DRAWING(d) - ChkErr(SetThemeBackground, brush, 32, true); - QDSetPatternOrigin(PatternOrigin(tkwin, d)); - EraseRect(&bounds); + ChkErr(HIThemeSetFill, brush, NULL, dc.context, HIOrientation); + //QDSetPatternOrigin(PatternOrigin(tkwin, d)); + CGContextFillRect(dc.context, bounds); END_DRAWING } @@ -889,12 +936,12 @@ static void ToolbarBackgroundElementDraw( Drawable d, Ttk_Box b, Ttk_State state) { ThemeBrush brush = kThemeBrushToolbarBackground; - Rect bounds = BoxToRect(d, Ttk_WinBox(tkwin)); + CGRect bounds = BoxToRect(d, Ttk_WinBox(tkwin)); BEGIN_DRAWING(d) - ChkErr(SetThemeBackground, brush, 32, true); - QDSetPatternOrigin(PatternOrigin(tkwin, d)); - EraseRect(&bounds); + ChkErr(HIThemeSetFill, brush, NULL, dc.context, HIOrientation); + //QDSetPatternOrigin(PatternOrigin(tkwin, d)); + CGContextFillRect(dc.context, bounds); END_DRAWING } @@ -911,26 +958,39 @@ static Ttk_ElementSpec ToolbarBackgroundElementSpec = { * Redefine the header to use a kThemeListHeaderButton. */ +#define TTK_TREEVIEW_STATE_SORTARROW TTK_STATE_USER1 +static Ttk_StateTable TreeHeaderValueTable[] = { + { kThemeButtonOn, TTK_STATE_ALTERNATE}, + { kThemeButtonOn, TTK_STATE_SELECTED}, + { kThemeButtonOff, 0} +}; static Ttk_StateTable TreeHeaderAdornmentTable[] = { - { kThemeAdornmentHeaderButtonSortUp, TTK_STATE_ALTERNATE, 0 }, - { kThemeAdornmentFocus, TTK_STATE_FOCUS, 0 }, - { kThemeAdornmentNone, 0, 0 } + { kThemeAdornmentHeaderButtonSortUp, + TTK_STATE_ALTERNATE|TTK_TREEVIEW_STATE_SORTARROW}, + { kThemeAdornmentDefault, + TTK_STATE_SELECTED|TTK_TREEVIEW_STATE_SORTARROW}, + { kThemeAdornmentHeaderButtonNoSortArrow, TTK_STATE_ALTERNATE}, + { kThemeAdornmentHeaderButtonNoSortArrow, TTK_STATE_SELECTED}, + { kThemeAdornmentFocus, TTK_STATE_FOCUS}, + { kThemeAdornmentNone, 0} }; static void TreeHeaderElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - ThemeButtonParms *parms = clientData; - Rect bounds = BoxToRect(d, b); - ThemeButtonDrawInfo info; - - info.state = Ttk_StateTableLookup(ThemeStateTable, state); - info.value = Ttk_StateTableLookup(ButtonValueTable, state); - info.adornment = Ttk_StateTableLookup(TreeHeaderAdornmentTable, state); + ThemeButtonParams *params = clientData; + CGRect bounds = BoxToRect(d, b); + const HIThemeButtonDrawInfo info = { + .version = 0, + .state = Ttk_StateTableLookup(ThemeStateTable, state), + .kind = params->kind, + .value = Ttk_StateTableLookup(TreeHeaderValueTable, state), + .adornment = Ttk_StateTableLookup(TreeHeaderAdornmentTable, state), + }; BEGIN_DRAWING(d) - ChkErr(DrawThemeButton, &bounds, parms->kind, &info, NULL, NULL, NULL, 0); + ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); END_DRAWING } @@ -945,8 +1005,8 @@ static Ttk_ElementSpec TreeHeaderElementSpec = { /* * Disclosure triangle: */ -#define TTK_TREEVIEW_STATE_OPEN TTK_STATE_USER1 -#define TTK_TREEVIEW_STATE_LEAF TTK_STATE_USER2 +#define TTK_TREEVIEW_STATE_OPEN TTK_STATE_USER1 +#define TTK_TREEVIEW_STATE_LEAF TTK_STATE_USER2 static Ttk_StateTable DisclosureValueTable[] = { { kThemeDisclosureDown, TTK_TREEVIEW_STATE_OPEN, 0 }, { kThemeDisclosureRight, 0, 0 }, @@ -968,21 +1028,20 @@ static void DisclosureElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, Ttk_State state) { - Rect bounds = BoxToRect(d, b); - ThemeButtonDrawInfo info; - - if (state & TTK_TREEVIEW_STATE_LEAF) { - return; + if (!(state & TTK_TREEVIEW_STATE_LEAF)) { + CGRect bounds = BoxToRect(d, b); + const HIThemeButtonDrawInfo info = { + .version = 0, + .state = Ttk_StateTableLookup(ThemeStateTable, state), + .kind = kThemeDisclosureTriangle, + .value = Ttk_StateTableLookup(DisclosureValueTable, state), + .adornment = kThemeAdornmentDrawIndicatorOnly, + }; + + BEGIN_DRAWING(d) + ChkErr(HIThemeDrawButton, &bounds, &info, dc.context, HIOrientation, NULL); + END_DRAWING } - - info.state = Ttk_StateTableLookup(ThemeStateTable, state); - info.value = Ttk_StateTableLookup(DisclosureValueTable, state); - info.adornment = kThemeAdornmentDrawIndicatorOnly; - - BEGIN_DRAWING(d) - ChkErr(DrawThemeButton, - &bounds, kThemeDisclosureTriangle, &info, NULL, DontErase, NULL, 0); - END_DRAWING } static Ttk_ElementSpec DisclosureElementSpec = { @@ -1078,23 +1137,23 @@ static int AquaTheme_Init(Tcl_Interp *interp) &ToolbarBackgroundElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Button.button", - &ButtonElementSpec, &PushButtonParms); + &ButtonElementSpec, &PushButtonParams); Ttk_RegisterElementSpec(themePtr, "Checkbutton.button", - &ButtonElementSpec, &CheckBoxParms); + &ButtonElementSpec, &CheckBoxParams); Ttk_RegisterElementSpec(themePtr, "Radiobutton.button", - &ButtonElementSpec, &RadioButtonParms); + &ButtonElementSpec, &RadioButtonParams); Ttk_RegisterElementSpec(themePtr, "Toolbutton.border", - &ButtonElementSpec, &BevelButtonParms); + &ButtonElementSpec, &BevelButtonParams); Ttk_RegisterElementSpec(themePtr, "Menubutton.button", - &ButtonElementSpec, &PopupButtonParms); + &ButtonElementSpec, &PopupButtonParams); Ttk_RegisterElementSpec(themePtr, "Spinbox.spinbutton", &SpinButtonElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Combobox.button", &ComboboxElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Treeitem.indicator", - &DisclosureElementSpec, &DisclosureParms); + &DisclosureElementSpec, &DisclosureParams); Ttk_RegisterElementSpec(themePtr, "Treeheading.cell", - &TreeHeaderElementSpec, &ListHeaderParms); + &TreeHeaderElementSpec, &ListHeaderParams); Ttk_RegisterElementSpec(themePtr, "Notebook.tab", &TabElementSpec, 0); Ttk_RegisterElementSpec(themePtr, "Notebook.client", &PaneElementSpec, 0); @@ -1134,4 +1193,13 @@ int Ttk_MacOSXPlatformInit(Tcl_Interp *interp) { return AquaTheme_Init(interp); } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 79 + * coding: utf-8 + * End: + */ |