Posted to tcl by das at Tue Oct 30 01:49:47 GMT 2007view raw
- Index: macosx/ttkMacOSXTheme.c
- ===================================================================
- RCS file: /cvsroot/tktoolkit/tk/macosx/ttkMacOSXTheme.c,v
- retrieving revision 1.12
- diff -u -p -r1.12 ttkMacOSXTheme.c
- --- macosx/ttkMacOSXTheme.c 28 Oct 2007 18:56:51 -0000 1.12
- +++ macosx/ttkMacOSXTheme.c 30 Oct 2007 01:48:12 -0000
- @@ -36,6 +36,10 @@
- #define BEGIN_DRAWING(d) { \
- TkMacOSXDrawingContext dc; \
- if (!TkMacOSXSetupDrawingContext((d), NULL, 0, &dc)) {return;}
- +#define BEGIN_DRAWING_CG(d) { \
- + TkMacOSXDrawingContext dc; \
- + if (!TkMacOSXSetupDrawingContext((d), NULL, tkMacOSXUseCGDrawing, &dc)) \
- + {return;}
- #define END_DRAWING \
- TkMacOSXRestoreDrawingContext(&dc); }
- @@ -47,7 +51,7 @@
- * Convert a Ttk_Box in Tk coordinates relative to the given Drawable
- * to a native Rect relative to the containing port.
- */
- -static Rect BoxToRect(Drawable d, Ttk_Box b)
- +static inline Rect BoxToRect(Drawable d, Ttk_Box b)
- {
- MacDrawable *md = (MacDrawable*)d;
- Rect rect;
- @@ -60,6 +64,19 @@ static Rect BoxToRect(Drawable d, Ttk_Bo
- return rect;
- }
- +static inline CGRect BoxToCGRect(Drawable d, Ttk_Box b)
- +{
- + MacDrawable *md = (MacDrawable*)d;
- + CGRect rect;
- +
- + rect.origin.x = b.x + md->xOff;
- + rect.origin.y = b.y + md->yOff;
- + rect.size.width = b.width;
- + rect.size.height = b.height;
- +
- + return rect;
- +}
- +
- /* PatternOrigin --
- * Compute brush pattern origin for a Drawable relative to a Tk_Window.
- *
- @@ -122,11 +139,11 @@ typedef struct {
- } ThemeButtonParms;
- static ThemeButtonParms
- - PushButtonParms = { kThemePushButton, NoThemeMetric },
- + PushButtonParms = { kThemePushButton, kThemeMetricPushButtonHeight },
- CheckBoxParms = { kThemeCheckBox, kThemeMetricCheckBoxHeight },
- RadioButtonParms = { kThemeRadioButton, kThemeMetricRadioButtonHeight },
- BevelButtonParms = { kThemeBevelButton, NoThemeMetric },
- - PopupButtonParms = { kThemePopupButton, NoThemeMetric },
- + PopupButtonParms = { kThemePopupButton, kThemeMetricPopupButtonHeight },
- DisclosureParms = { kThemeDisclosureButton, kThemeMetricDisclosureTriangleHeight },
- ListHeaderParms = { kThemeListHeaderButton, kThemeMetricListHeaderHeight };
- @@ -157,6 +174,20 @@ static ThemeButtonDrawInfo computeButton
- info.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state);
- return info;
- }
- +static HIThemeButtonDrawInfo computeHIButtonDrawInfo(
- + ThemeButtonParms *parms, Ttk_State state)
- +{
- + HIThemeButtonDrawInfo info;
- +
- + info.version = 0;
- + info.state = Ttk_StateTableLookup(ThemeStateTable, state);
- + info.kind = parms->kind;
- + info.value = Ttk_StateTableLookup(ButtonValueTable, state);
- + info.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state);
- + info.animation.time.start = 0;
- + info.animation.time.current = 0;
- + return info;
- +}
- static void ButtonElementSizeNoPadding(
- void *clientData, void *elementRecord, Tk_Window tkwin,
- @@ -165,10 +196,10 @@ static void ButtonElementSizeNoPadding(
- ThemeButtonParms *parms = clientData;
- if (parms->heightMetric != NoThemeMetric) {
- - SInt32 gratuitouslyOverspecifiedType;
- + SInt32 height;
- - GetThemeMetric(parms->heightMetric, &gratuitouslyOverspecifiedType);
- - *heightPtr = gratuitouslyOverspecifiedType;
- + ChkErr(GetThemeMetric, parms->heightMetric, &height);
- + *heightPtr = height;
- }
- }
- @@ -177,47 +208,81 @@ static void ButtonElementSize(
- int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
- {
- ThemeButtonParms *parms = clientData;
- - ThemeButtonDrawInfo drawInfo = computeButtonDrawInfo(parms, 0);
- - Rect scratchRect, contentsRect;
- - const int scratchSize = 100;
- -
- - ButtonElementSizeNoPadding(
- - clientData, elementRecord, tkwin,
- - widthPtr, heightPtr, paddingPtr);
- -
- - /* To compute internal padding, query the appearance manager
- - * for the content bounds of a dummy rectangle, then use
- - * the difference as the padding.
- - */
- - scratchRect.top = scratchRect.left = 0;
- - scratchRect.bottom = scratchRect.right = scratchSize;
- -
- - GetThemeButtonContentBounds(
- - &scratchRect, parms->kind, &drawInfo, &contentsRect);
- + if (tkMacOSXUseCGDrawing) {
- + HIThemeButtonDrawInfo info = computeHIButtonDrawInfo(parms, 0);
- + static const CGRect scratchBounds = {{0, 0}, {100, 100}};
- + CGRect contentBounds, backgroundBounds;
- +
- + ButtonElementSizeNoPadding(
- + clientData, elementRecord, tkwin,
- + widthPtr, heightPtr, paddingPtr);
- +
- + /* To compute internal padding, query the appearance manager
- + * for the content bounds of a dummy rectangle, then use
- + * the difference as the padding.
- + */
- + ChkErr(HIThemeGetButtonContentBounds, &scratchBounds, &info,
- + &contentBounds);
- + ChkErr(HIThemeGetButtonBackgroundBounds, &scratchBounds, &info,
- + &backgroundBounds);
- +
- + paddingPtr->left = contentBounds.origin.x;
- + paddingPtr->top = contentBounds.origin.y;
- + paddingPtr->right = scratchBounds.size.width -
- + contentBounds.size.width + 1;
- + paddingPtr->bottom = scratchBounds.size.height -
- + contentBounds.size.height;
- - paddingPtr->left = contentsRect.left;
- - paddingPtr->top = contentsRect.top;
- - paddingPtr->bottom = scratchSize - contentsRect.bottom;
- - paddingPtr->right = scratchSize - contentsRect.right + 1;
- -
- - /* Now add a little extra padding to account for drop shadows.
- - * @@@ SHOULD: call GetThemeButtonBackgroundBounds() instead.
- - */
- + *paddingPtr = Ttk_AddPadding(*paddingPtr, ButtonMargins);
- + } else {
- + ThemeButtonDrawInfo info = computeButtonDrawInfo(parms, 0);
- + static const Rect scratchBounds = {0, 0, 100, 100};
- + Rect contentBounds;
- +
- + ButtonElementSizeNoPadding(
- + clientData, elementRecord, tkwin,
- + widthPtr, heightPtr, paddingPtr);
- +
- + /* To compute internal padding, query the appearance manager
- + * for the content bounds of a dummy rectangle, then use
- + * the difference as the padding.
- + */
- + ChkErr(GetThemeButtonContentBounds, &scratchBounds, parms->kind, &info,
- + &contentBounds);
- +
- + paddingPtr->left = contentBounds.left;
- + paddingPtr->top = contentBounds.top;
- + paddingPtr->right = scratchBounds.right - contentBounds.right + 1;
- + paddingPtr->bottom = scratchBounds.bottom - contentBounds.bottom;
- +
- + /* Now add a little extra padding to account for drop shadows.
- + * @@@ SHOULD: call GetThemeButtonBackgroundBounds() instead.
- + */
- - *paddingPtr = Ttk_AddPadding(*paddingPtr, ButtonMargins);
- + *paddingPtr = Ttk_AddPadding(*paddingPtr, ButtonMargins);
- + }
- }
- static void ButtonElementDraw(
- void *clientData, void *elementRecord, Tk_Window tkwin,
- Drawable d, Ttk_Box b, Ttk_State state)
- {
- - Rect bounds = BoxToRect(d, Ttk_PadBox(b, ButtonMargins));
- ThemeButtonParms *parms = clientData;
- - ThemeButtonDrawInfo info = computeButtonDrawInfo(parms, state);
- - BEGIN_DRAWING(d)
- - DrawThemeButton(&bounds, parms->kind, &info,
- - NULL/*prevInfo*/,NULL/*eraseProc*/,NULL/*labelProc*/,0/*userData*/);
- + BEGIN_DRAWING_CG(d)
- + if (dc.context) {
- + CGRect bounds = BoxToCGRect(d, Ttk_PadBox(b, ButtonMargins));
- + HIThemeButtonDrawInfo info = computeHIButtonDrawInfo(parms, state);
- +
- + ChkErr(HIThemeDrawButton, &bounds, &info, dc.context,
- + kHIThemeOrientationNormal, NULL);
- + } else {
- + Rect bounds = BoxToRect(d, Ttk_PadBox(b, ButtonMargins));
- + ThemeButtonDrawInfo info = computeButtonDrawInfo(parms, state);
- +
- + ChkErr(DrawThemeButton, &bounds, parms->kind, &info, NULL, NULL, NULL,
- + 0);
- + }
- END_DRAWING
- }