cocoa: Implements basic TSpeedButton look

git-svn-id: trunk@49581 -
This commit is contained in:
sekelsenmat 2015-08-01 06:28:50 +00:00
parent 726931d294
commit c7486c896c

View File

@ -37,8 +37,8 @@ type
procedure InternalDrawParentBackground({%H-}Window: HWND; {%H-}Target: HDC; {%H-}Bounds: PRect); override; procedure InternalDrawParentBackground({%H-}Window: HWND; {%H-}Target: HDC; {%H-}Bounds: PRect); override;
*) *)
function GetDrawState(Details: TThemedElementDetails): ThemeDrawState; function GetDrawState(Details: TThemedElementDetails): ThemeDrawState;
(* function DrawButtonElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect; function DrawButtonElement(DC: TCocoaContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;
function DrawComboBoxElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect; (* function DrawComboBoxElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;
function DrawHeaderElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect; function DrawHeaderElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;
function DrawRebarElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;*) function DrawRebarElement(DC: TCarbonDeviceContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;*)
function DrawToolBarElement(DC: TCocoaContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect; function DrawToolBarElement(DC: TCocoaContext; Details: TThemedElementDetails; R: TRect; {%H-}ClipRect: PRect): TRect;
@ -141,64 +141,67 @@ begin
BoundsRect.size.height := NewHeight + 1; BoundsRect.size.height := NewHeight + 1;
BoundsRect.size.width := BoundsRect.size.width - BtnWidth; BoundsRect.size.width := BoundsRect.size.width - BtnWidth;
Result := CGRectToRect(BoundsRect); Result := CGRectToRect(BoundsRect);
end; end;*)
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCarbonThemeServices.DrawButtonElement Method: TCocoaThemeServices.DrawButtonElement
Params: DC - Carbon device context Params: DC - Carbon device context
Details - Details for themed element Details - Details for themed element
R - Bounding rectangle R - Bounding rectangle
ClipRect - Clipping rectangle ClipRect - Clipping rectangle
Returns: ClientRect Returns: ClientRect
Draws a button element with native Carbon look Draws a button element with native look
------------------------------------------------------------------------------} Button kinds:
function TCarbonThemeServices.DrawButtonElement(DC: TCarbonDeviceContext;
Details: TThemedElementDetails; R: TRect; ClipRect: PRect): TRect;
const
ButtonMap: array[BP_PUSHBUTTON..BP_USERBUTTON] of ThemeButtonKind =
(
{BP_PUSHBUTTON } kThemeRoundedBevelButton, {BP_PUSHBUTTON } kThemeRoundedBevelButton,
{BP_RADIOBUTTON} kThemeRadioButton, {BP_RADIOBUTTON} kThemeRadioButton,
{BP_CHECKBOX } kThemeCheckBox, {BP_CHECKBOX } kThemeCheckBox,
{BP_GROUPBOX } kHIThemeGroupBoxKindPrimary, // ?? {BP_GROUPBOX } kHIThemeGroupBoxKindPrimary,
{BP_USERBUTTON } kThemeRoundedBevelButton {BP_USERBUTTON } kThemeRoundedBevelButton
); ------------------------------------------------------------------------------}
function TCocoaThemeServices.DrawButtonElement(DC: TCocoaContext;
Details: TThemedElementDetails; R: TRect; ClipRect: PRect): TRect;
var var
ButtonDrawInfo: HIThemeButtonDrawInfo; lCanvas: TCanvas;
// we can do so because GroupDrawIndo have common fields with ButtonDrawInfo lSize: TSize;
GroupDrawInfo: HIThemeGroupBoxDrawInfo absolute ButtonDrawInfo; lCDButton: TCDButtonStateEx;
LabelRect: HIRect; lState: TCDControlState = [];
lDrawer: TCDDrawer;
lPt: TPoint;
begin begin
ButtonDrawInfo.version := 0; lCDButton := TCDButtonStateEx.Create;
ButtonDrawInfo.State := GetDrawState(Details); lCanvas := TCanvas.Create;
ButtonDrawInfo.kind := ButtonMap[Details.Part]; try
if IsMixed(Details) then lSize.CX := R.Right - R.Left;
ButtonDrawInfo.value := kThemeButtonMixed lSize.CY := R.Bottom - R.Top;
else
if IsHot(Details) then
lState += [csfMouseOver];
if IsPushed(Details) then
lState += [csfSunken];
if IsChecked(Details) then if IsChecked(Details) then
ButtonDrawInfo.value := kThemeButtonOn lState += [csfSunken];
else if not IsDisabled(Details) then
ButtonDrawInfo.value := kThemeButtonOff; lState += [csfEnabled];
ButtonDrawInfo.adornment := kThemeAdornmentNone;
LabelRect := RectToCGRect(R); lDrawer := GetDrawer(dsMacOSX);
lCanvas.Handle := HDC(DC);
lPt := Types.Point(R.Left, R.Top);
if Details.Part = BP_GROUPBOX then if Details.Part = BP_GROUPBOX then
OSError( lDrawer.DrawGroupBox(lCanvas, lPt, lSize, lState, lCDButton)
HIThemeDrawGroupBox(LabelRect, GroupDrawInfo, DC.CGContext,
kHIThemeOrientationNormal),
Self, 'DrawButtonElement', 'HIThemeDrawGroupBox')
else else
OSError( lDrawer.DrawButton(lCanvas, lPt, lSize, lState, lCDButton);
HIThemeDrawButton(LabelRect, ButtonDrawInfo, DC.CGContext,
kHIThemeOrientationNormal, @LabelRect),
Self, 'DrawButtonElement', 'HIThemeDrawButton');
Result := CGRectToRect(LabelRect); Result := R;
finally
lCDButton.Free;
lCanvas.Handle := 0;
lCanvas.Free;
end;
end; end;
{------------------------------------------------------------------------------ (*{------------------------------------------------------------------------------
Method: TCarbonThemeServices.DrawHeaderElement Method: TCarbonThemeServices.DrawHeaderElement
Params: DC - Carbon device context Params: DC - Carbon device context
Details - Details for themed element Details - Details for themed element
@ -581,9 +584,9 @@ begin
if CheckDC(DC, 'TCocoaThemeServices.DrawElement') then if CheckDC(DC, 'TCocoaThemeServices.DrawElement') then
begin begin
case Details.Element of case Details.Element of
{ teComboBox: DrawComboBoxElement(Context, Details, R, ClipRect); //teComboBox: DrawComboBoxElement(Context, Details, R, ClipRect);
teButton: DrawButtonElement(Context, Details, R, ClipRect); teButton: DrawButtonElement(Context, Details, R, ClipRect);
teHeader: DrawHeaderElement(Context, Details, R, ClipRect); {teHeader: DrawHeaderElement(Context, Details, R, ClipRect);
teRebar: DrawRebarElement(Context, Details, R, ClipRect);} teRebar: DrawRebarElement(Context, Details, R, ClipRect);}
teToolBar: DrawToolBarElement(Context, Details, R, ClipRect); teToolBar: DrawToolBarElement(Context, Details, R, ClipRect);
teTreeview: DrawTreeviewElement(Context, Details, R, ClipRect); teTreeview: DrawTreeviewElement(Context, Details, R, ClipRect);