Posted to tcl by das at Tue Oct 30 01:49:47 GMT 2007view raw

  1. Index: macosx/ttkMacOSXTheme.c
  2. ===================================================================
  3. RCS file: /cvsroot/tktoolkit/tk/macosx/ttkMacOSXTheme.c,v
  4. retrieving revision 1.12
  5. diff -u -p -r1.12 ttkMacOSXTheme.c
  6. --- macosx/ttkMacOSXTheme.c 28 Oct 2007 18:56:51 -0000 1.12
  7. +++ macosx/ttkMacOSXTheme.c 30 Oct 2007 01:48:12 -0000
  8. @@ -36,6 +36,10 @@
  9. #define BEGIN_DRAWING(d) { \
  10. TkMacOSXDrawingContext dc; \
  11. if (!TkMacOSXSetupDrawingContext((d), NULL, 0, &dc)) {return;}
  12. +#define BEGIN_DRAWING_CG(d) { \
  13. + TkMacOSXDrawingContext dc; \
  14. + if (!TkMacOSXSetupDrawingContext((d), NULL, tkMacOSXUseCGDrawing, &dc)) \
  15. + {return;}
  16. #define END_DRAWING \
  17. TkMacOSXRestoreDrawingContext(&dc); }
  18.  
  19. @@ -47,7 +51,7 @@
  20. * Convert a Ttk_Box in Tk coordinates relative to the given Drawable
  21. * to a native Rect relative to the containing port.
  22. */
  23. -static Rect BoxToRect(Drawable d, Ttk_Box b)
  24. +static inline Rect BoxToRect(Drawable d, Ttk_Box b)
  25. {
  26. MacDrawable *md = (MacDrawable*)d;
  27. Rect rect;
  28. @@ -60,6 +64,19 @@ static Rect BoxToRect(Drawable d, Ttk_Bo
  29. return rect;
  30. }
  31.  
  32. +static inline CGRect BoxToCGRect(Drawable d, Ttk_Box b)
  33. +{
  34. + MacDrawable *md = (MacDrawable*)d;
  35. + CGRect rect;
  36. +
  37. + rect.origin.x = b.x + md->xOff;
  38. + rect.origin.y = b.y + md->yOff;
  39. + rect.size.width = b.width;
  40. + rect.size.height = b.height;
  41. +
  42. + return rect;
  43. +}
  44. +
  45. /* PatternOrigin --
  46. * Compute brush pattern origin for a Drawable relative to a Tk_Window.
  47. *
  48. @@ -122,11 +139,11 @@ typedef struct {
  49. } ThemeButtonParms;
  50.  
  51. static ThemeButtonParms
  52. - PushButtonParms = { kThemePushButton, NoThemeMetric },
  53. + PushButtonParms = { kThemePushButton, kThemeMetricPushButtonHeight },
  54. CheckBoxParms = { kThemeCheckBox, kThemeMetricCheckBoxHeight },
  55. RadioButtonParms = { kThemeRadioButton, kThemeMetricRadioButtonHeight },
  56. BevelButtonParms = { kThemeBevelButton, NoThemeMetric },
  57. - PopupButtonParms = { kThemePopupButton, NoThemeMetric },
  58. + PopupButtonParms = { kThemePopupButton, kThemeMetricPopupButtonHeight },
  59. DisclosureParms = { kThemeDisclosureButton, kThemeMetricDisclosureTriangleHeight },
  60. ListHeaderParms = { kThemeListHeaderButton, kThemeMetricListHeaderHeight };
  61.  
  62. @@ -157,6 +174,20 @@ static ThemeButtonDrawInfo computeButton
  63. info.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state);
  64. return info;
  65. }
  66. +static HIThemeButtonDrawInfo computeHIButtonDrawInfo(
  67. + ThemeButtonParms *parms, Ttk_State state)
  68. +{
  69. + HIThemeButtonDrawInfo info;
  70. +
  71. + info.version = 0;
  72. + info.state = Ttk_StateTableLookup(ThemeStateTable, state);
  73. + info.kind = parms->kind;
  74. + info.value = Ttk_StateTableLookup(ButtonValueTable, state);
  75. + info.adornment = Ttk_StateTableLookup(ButtonAdornmentTable, state);
  76. + info.animation.time.start = 0;
  77. + info.animation.time.current = 0;
  78. + return info;
  79. +}
  80.  
  81. static void ButtonElementSizeNoPadding(
  82. void *clientData, void *elementRecord, Tk_Window tkwin,
  83. @@ -165,10 +196,10 @@ static void ButtonElementSizeNoPadding(
  84. ThemeButtonParms *parms = clientData;
  85.  
  86. if (parms->heightMetric != NoThemeMetric) {
  87. - SInt32 gratuitouslyOverspecifiedType;
  88. + SInt32 height;
  89.  
  90. - GetThemeMetric(parms->heightMetric, &gratuitouslyOverspecifiedType);
  91. - *heightPtr = gratuitouslyOverspecifiedType;
  92. + ChkErr(GetThemeMetric, parms->heightMetric, &height);
  93. + *heightPtr = height;
  94. }
  95. }
  96.  
  97. @@ -177,47 +208,81 @@ static void ButtonElementSize(
  98. int *widthPtr, int *heightPtr, Ttk_Padding *paddingPtr)
  99. {
  100. ThemeButtonParms *parms = clientData;
  101. - ThemeButtonDrawInfo drawInfo = computeButtonDrawInfo(parms, 0);
  102. - Rect scratchRect, contentsRect;
  103. - const int scratchSize = 100;
  104. -
  105. - ButtonElementSizeNoPadding(
  106. - clientData, elementRecord, tkwin,
  107. - widthPtr, heightPtr, paddingPtr);
  108. -
  109. - /* To compute internal padding, query the appearance manager
  110. - * for the content bounds of a dummy rectangle, then use
  111. - * the difference as the padding.
  112. - */
  113. - scratchRect.top = scratchRect.left = 0;
  114. - scratchRect.bottom = scratchRect.right = scratchSize;
  115. -
  116. - GetThemeButtonContentBounds(
  117. - &scratchRect, parms->kind, &drawInfo, &contentsRect);
  118. + if (tkMacOSXUseCGDrawing) {
  119. + HIThemeButtonDrawInfo info = computeHIButtonDrawInfo(parms, 0);
  120. + static const CGRect scratchBounds = {{0, 0}, {100, 100}};
  121. + CGRect contentBounds, backgroundBounds;
  122. +
  123. + ButtonElementSizeNoPadding(
  124. + clientData, elementRecord, tkwin,
  125. + widthPtr, heightPtr, paddingPtr);
  126. +
  127. + /* To compute internal padding, query the appearance manager
  128. + * for the content bounds of a dummy rectangle, then use
  129. + * the difference as the padding.
  130. + */
  131. + ChkErr(HIThemeGetButtonContentBounds, &scratchBounds, &info,
  132. + &contentBounds);
  133. + ChkErr(HIThemeGetButtonBackgroundBounds, &scratchBounds, &info,
  134. + &backgroundBounds);
  135. +
  136. + paddingPtr->left = contentBounds.origin.x;
  137. + paddingPtr->top = contentBounds.origin.y;
  138. + paddingPtr->right = scratchBounds.size.width -
  139. + contentBounds.size.width + 1;
  140. + paddingPtr->bottom = scratchBounds.size.height -
  141. + contentBounds.size.height;
  142.  
  143. - paddingPtr->left = contentsRect.left;
  144. - paddingPtr->top = contentsRect.top;
  145. - paddingPtr->bottom = scratchSize - contentsRect.bottom;
  146. - paddingPtr->right = scratchSize - contentsRect.right + 1;
  147. -
  148. - /* Now add a little extra padding to account for drop shadows.
  149. - * @@@ SHOULD: call GetThemeButtonBackgroundBounds() instead.
  150. - */
  151. + *paddingPtr = Ttk_AddPadding(*paddingPtr, ButtonMargins);
  152. + } else {
  153. + ThemeButtonDrawInfo info = computeButtonDrawInfo(parms, 0);
  154. + static const Rect scratchBounds = {0, 0, 100, 100};
  155. + Rect contentBounds;
  156. +
  157. + ButtonElementSizeNoPadding(
  158. + clientData, elementRecord, tkwin,
  159. + widthPtr, heightPtr, paddingPtr);
  160. +
  161. + /* To compute internal padding, query the appearance manager
  162. + * for the content bounds of a dummy rectangle, then use
  163. + * the difference as the padding.
  164. + */
  165. + ChkErr(GetThemeButtonContentBounds, &scratchBounds, parms->kind, &info,
  166. + &contentBounds);
  167. +
  168. + paddingPtr->left = contentBounds.left;
  169. + paddingPtr->top = contentBounds.top;
  170. + paddingPtr->right = scratchBounds.right - contentBounds.right + 1;
  171. + paddingPtr->bottom = scratchBounds.bottom - contentBounds.bottom;
  172. +
  173. + /* Now add a little extra padding to account for drop shadows.
  174. + * @@@ SHOULD: call GetThemeButtonBackgroundBounds() instead.
  175. + */
  176.  
  177. - *paddingPtr = Ttk_AddPadding(*paddingPtr, ButtonMargins);
  178. + *paddingPtr = Ttk_AddPadding(*paddingPtr, ButtonMargins);
  179. + }
  180. }
  181.  
  182. static void ButtonElementDraw(
  183. void *clientData, void *elementRecord, Tk_Window tkwin,
  184. Drawable d, Ttk_Box b, Ttk_State state)
  185. {
  186. - Rect bounds = BoxToRect(d, Ttk_PadBox(b, ButtonMargins));
  187. ThemeButtonParms *parms = clientData;
  188. - ThemeButtonDrawInfo info = computeButtonDrawInfo(parms, state);
  189.  
  190. - BEGIN_DRAWING(d)
  191. - DrawThemeButton(&bounds, parms->kind, &info,
  192. - NULL/*prevInfo*/,NULL/*eraseProc*/,NULL/*labelProc*/,0/*userData*/);
  193. + BEGIN_DRAWING_CG(d)
  194. + if (dc.context) {
  195. + CGRect bounds = BoxToCGRect(d, Ttk_PadBox(b, ButtonMargins));
  196. + HIThemeButtonDrawInfo info = computeHIButtonDrawInfo(parms, state);
  197. +
  198. + ChkErr(HIThemeDrawButton, &bounds, &info, dc.context,
  199. + kHIThemeOrientationNormal, NULL);
  200. + } else {
  201. + Rect bounds = BoxToRect(d, Ttk_PadBox(b, ButtonMargins));
  202. + ThemeButtonDrawInfo info = computeButtonDrawInfo(parms, state);
  203. +
  204. + ChkErr(DrawThemeButton, &bounds, parms->kind, &info, NULL, NULL, NULL,
  205. + 0);
  206. + }
  207. END_DRAWING
  208. }
  209.  
  210.