lazarus/lcl/interfaces/cocoa/cocoawscomctrls.pas
2014-01-25 21:49:49 +00:00

139 lines
3.9 KiB
ObjectPascal

unit CocoaWSComCtrls;
interface
{$mode delphi}
{$modeswitch objectivec1}
uses
CocoaAll
, LCLType
, WSComCtrls
, Controls, ComCtrls
, CocoaPrivate
, CocoaWSCommon;
type
{ TCocoaWSStatusBar }
TCocoaWSStatusBar = class(TWSStatusBar)
published
//class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
//class procedure PanelUpdate(const AStatusBar: TStatusBar; PanelIndex: integer); override;
//class procedure SetPanelText(const AStatusBar: TStatusBar; PanelIndex: integer); override;
//class procedure Update(const AStatusBar: TStatusBar); override;
end;
{ TCocoaWSProgressBar }
TCocoaWSProgressBar = class(TWSProgressBar)
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure ApplyChanges(const AProgressBar: TCustomProgressBar); override;
class procedure SetPosition(const AProgressBar: TCustomProgressBar; const NewPosition: integer); override;
class procedure SetStyle(const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle); override;
end;
implementation
type
{ TCocoaProgressIndicator }
TCocoaProgressIndicator = objcclass(NSProgressIndicator)
callback: ICommonCallback;
function acceptsFirstResponder: Boolean; override;
function becomeFirstResponder: Boolean; override;
function resignFirstResponder: Boolean; override;
function lclGetCallback: ICommonCallback; override;
procedure lclClearCallback; override;
procedure resetCursorRects; override;
end;
function AllocProgressIndicator(ATarget: TWinControl; const AParams: TCreateParams): TCocoaProgressIndicator;
begin
Result := TCocoaProgressIndicator.alloc.lclInitWithCreateParams(AParams);
if Assigned(Result) then
begin
Result.callback := TLCLCommonCallback.Create(Result, ATarget);
Result.startAnimation(nil);
//small constrol size looks like carbon
//Result.setControlSize(NSSmallControlSize);
end;
end;
{ TCocoaWSProgressBar }
class function TCocoaWSProgressBar.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle;
begin
Result:=TLCLIntfHandle(AllocProgressIndicator(AWinControl, AParams));
end;
class procedure TCocoaWSProgressBar.ApplyChanges(
const AProgressBar: TCustomProgressBar);
var
ind : NSProgressIndicator;
begin
if not Assigned(AProgressBar) or not AProgressBar.HandleAllocated then Exit;
ind:=NSProgressIndicator(AProgressBAr.Handle);
ind.setMaxValue(AProgressBar.Max);
ind.setMinValue(AProgressBar.Min);
ind.setDoubleValue(AProgressBar.Position);
ind.setIndeterminate(AProgressBar.Style = pbstMarquee);
end;
class procedure TCocoaWSProgressBar.SetPosition(
const AProgressBar: TCustomProgressBar; const NewPosition: integer);
begin
if AProgressBar.HandleAllocated then
NSProgressIndicator(AProgressBar.Handle).setDoubleValue(NewPosition);
end;
class procedure TCocoaWSProgressBar.SetStyle(
const AProgressBar: TCustomProgressBar; const NewStyle: TProgressBarStyle);
begin
if AProgressBar.HandleAllocated then
NSProgressIndicator(AProgressBar.Handle).setIndeterminate(NewStyle = pbstMarquee);
end;
{ TCocoaProgressIndicator }
function TCocoaProgressIndicator.acceptsFirstResponder: Boolean;
begin
Result:=True;
end;
function TCocoaProgressIndicator.becomeFirstResponder: Boolean;
begin
Result := inherited becomeFirstResponder;
callback.BecomeFirstResponder;
end;
function TCocoaProgressIndicator.resignFirstResponder: Boolean;
begin
Result := inherited resignFirstResponder;
callback.ResignFirstResponder;
end;
function TCocoaProgressIndicator.lclGetCallback: ICommonCallback;
begin
Result:=callback;
end;
procedure TCocoaProgressIndicator.lclClearCallback;
begin
callback:=nil;
end;
procedure TCocoaProgressIndicator.resetCursorRects;
begin
if not callback.resetCursorRects then
inherited resetCursorRects;
end;
end.