mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-27 11:40:29 +02:00
Cocoa: decouple CocoaStatusBar from other control unit
This commit is contained in:
parent
f484dd2af3
commit
a0aa06e92c
@ -88,16 +88,6 @@ type
|
|||||||
property CocoaOnlyState: Boolean read IsCocoaOnlyState write SetCocoaOnlyState;
|
property CocoaOnlyState: Boolean read IsCocoaOnlyState write SetCocoaOnlyState;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCocoaStatusBar }
|
|
||||||
|
|
||||||
IStatusBarCallback = interface {(ICommonCallback) // not needed to inherit from ICommonCallback}
|
|
||||||
function GetBarsCount: Integer;
|
|
||||||
//todo: consider the use Cocoa native types, instead of FPC TAlignment
|
|
||||||
function GetBarItem(idx: Integer; var txt: String;
|
|
||||||
var width: Integer; var align: TAlignment): Boolean;
|
|
||||||
procedure DrawPanel(idx: Integer; const r: TRect);
|
|
||||||
end;
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -8,9 +8,21 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils,
|
Classes, SysUtils,
|
||||||
CocoaAll, CocoaPrivate, CocoaCallback, CocoaCustomControl, CocoaUtils;
|
LCLType, LMessages, LCLMessageGlue, ComCtrls,
|
||||||
|
CocoaAll, CocoaPrivate, CocoaCallback, CocoaGDIObjects ,CocoaWSCommon, CocoaUtils,
|
||||||
|
CocoaCustomControl;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
{ IStatusBarCallback }
|
||||||
|
|
||||||
|
IStatusBarCallback = interface {(ICommonCallback) // not needed to inherit from ICommonCallback}
|
||||||
|
function GetBarsCount: Integer;
|
||||||
|
//todo: consider the use Cocoa native types, instead of FPC TAlignment
|
||||||
|
function GetBarItem(idx: Integer; var txt: String;
|
||||||
|
var width: Integer; var align: TAlignment): Boolean;
|
||||||
|
procedure DrawPanel(idx: Integer; const r: TRect);
|
||||||
|
end;
|
||||||
|
|
||||||
TStatusItemData = record
|
TStatusItemData = record
|
||||||
Text : NSString;
|
Text : NSString;
|
||||||
Width : Integer;
|
Width : Integer;
|
||||||
@ -28,6 +40,14 @@ type
|
|||||||
procedure dealloc; override;
|
procedure dealloc; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TStatusBarCallback }
|
||||||
|
|
||||||
|
TStatusBarCallback = class(TLCLCommonCallback, IStatusBarCallback, ICommonCallback)
|
||||||
|
function GetBarsCount: Integer;
|
||||||
|
function GetBarItem(idx: Integer; var txt: String; var width: Integer; var align: TAlignment): Boolean;
|
||||||
|
procedure DrawPanel(idx: Integer; const r: TRect);
|
||||||
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{ TCocoaStatusBar }
|
{ TCocoaStatusBar }
|
||||||
@ -96,5 +116,71 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TStatusBarCallback }
|
||||||
|
|
||||||
|
function TStatusBarCallback.GetBarsCount: Integer;
|
||||||
|
begin
|
||||||
|
if TStatusBar(Target).SimplePanel
|
||||||
|
then Result := 1
|
||||||
|
else Result := TStatusBar(Target).Panels.Count;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TStatusBarCallback.GetBarItem(idx: Integer; var txt: String;
|
||||||
|
var width: Integer; var align: TAlignment): Boolean;
|
||||||
|
var
|
||||||
|
sb : TStatusBar;
|
||||||
|
begin
|
||||||
|
sb := TStatusBar(Target);
|
||||||
|
if sb.SimplePanel then begin
|
||||||
|
Result := idx = 0;
|
||||||
|
if not Result then Exit;
|
||||||
|
txt := sb.SimpleText;
|
||||||
|
width := sb.Width;
|
||||||
|
align := taLeftJustify; // todo: RTL?
|
||||||
|
end else begin
|
||||||
|
Result := (idx >= 0) and (idx < sb.Panels.Count);
|
||||||
|
if not Result then Exit;
|
||||||
|
if sb.Panels[idx].Style = psOwnerDraw
|
||||||
|
then txt := ''
|
||||||
|
else txt := sb.Panels[idx].Text;
|
||||||
|
width := sb.Panels[idx].Width;
|
||||||
|
align := sb.Panels[idx].Alignment;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TStatusBarCallback.DrawPanel(idx: Integer; const r: TRect);
|
||||||
|
var
|
||||||
|
sb : TStatusBar;
|
||||||
|
msg : TLMDrawItems;
|
||||||
|
ctx : TCocoaContext;
|
||||||
|
dr : TDrawItemStruct;
|
||||||
|
fr : TRect;
|
||||||
|
sv : Integer;
|
||||||
|
begin
|
||||||
|
sb := TStatusBar(Target);
|
||||||
|
if sb.SimplePanel then Exit;
|
||||||
|
if (idx<0) or (idx >= sb.Panels.Count) then Exit;
|
||||||
|
if sb.Panels[idx].Style <> psOwnerDraw then Exit;
|
||||||
|
|
||||||
|
ctx := TCocoaContext.Create(NSGraphicsContext.currentContext);
|
||||||
|
sv := ctx.SaveDC;
|
||||||
|
try
|
||||||
|
FillChar(msg, sizeof(msg), 0);
|
||||||
|
FillChar(dr, sizeof(dr), 0);
|
||||||
|
msg.Ctl := Target.Handle;
|
||||||
|
msg.Msg := LM_DRAWITEM;
|
||||||
|
msg.DrawItemStruct := @dr;
|
||||||
|
dr.itemID := idx;
|
||||||
|
dr._hDC := HDC(ctx);
|
||||||
|
dr.rcItem := r;
|
||||||
|
fr := NSView(Owner).lclFrame;
|
||||||
|
ctx.InitDraw(fr.Right-fr.Left, fr.Bottom-fr.Top);
|
||||||
|
LCLMessageGlue.DeliverMessage(Target, msg);
|
||||||
|
finally
|
||||||
|
ctx.RestoreDC(sv);
|
||||||
|
ctx.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -19,14 +19,6 @@ uses
|
|||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TStatusBarCallback }
|
|
||||||
|
|
||||||
TStatusBarCallback = class(TLCLCommonCallback, IStatusBarCallback, ICommonCallback)
|
|
||||||
function GetBarsCount: Integer;
|
|
||||||
function GetBarItem(idx: Integer; var txt: String; var width: Integer; var align: TAlignment): Boolean;
|
|
||||||
procedure DrawPanel(idx: Integer; const r: TRect);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TCocoaWSStatusBar }
|
{ TCocoaWSStatusBar }
|
||||||
|
|
||||||
TCocoaWSStatusBar = class(TWSStatusBar)
|
TCocoaWSStatusBar = class(TWSStatusBar)
|
||||||
@ -270,72 +262,6 @@ begin
|
|||||||
TCocoaStepper(AUpDown.Handle).setValueWraps(ADoWrap);
|
TCocoaStepper(AUpDown.Handle).setValueWraps(ADoWrap);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TStatusBarCallback }
|
|
||||||
|
|
||||||
function TStatusBarCallback.GetBarsCount: Integer;
|
|
||||||
begin
|
|
||||||
if TStatusBar(Target).SimplePanel
|
|
||||||
then Result := 1
|
|
||||||
else Result := TStatusBar(Target).Panels.Count;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TStatusBarCallback.GetBarItem(idx: Integer; var txt: String;
|
|
||||||
var width: Integer; var align: TAlignment): Boolean;
|
|
||||||
var
|
|
||||||
sb : TStatusBar;
|
|
||||||
begin
|
|
||||||
sb := TStatusBar(Target);
|
|
||||||
if sb.SimplePanel then begin
|
|
||||||
Result := idx = 0;
|
|
||||||
if not Result then Exit;
|
|
||||||
txt := sb.SimpleText;
|
|
||||||
width := sb.Width;
|
|
||||||
align := taLeftJustify; // todo: RTL?
|
|
||||||
end else begin
|
|
||||||
Result := (idx >= 0) and (idx < sb.Panels.Count);
|
|
||||||
if not Result then Exit;
|
|
||||||
if sb.Panels[idx].Style = psOwnerDraw
|
|
||||||
then txt := ''
|
|
||||||
else txt := sb.Panels[idx].Text;
|
|
||||||
width := sb.Panels[idx].Width;
|
|
||||||
align := sb.Panels[idx].Alignment;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TStatusBarCallback.DrawPanel(idx: Integer; const r: TRect);
|
|
||||||
var
|
|
||||||
sb : TStatusBar;
|
|
||||||
msg : TLMDrawItems;
|
|
||||||
ctx : TCocoaContext;
|
|
||||||
dr : TDrawItemStruct;
|
|
||||||
fr : TRect;
|
|
||||||
sv : Integer;
|
|
||||||
begin
|
|
||||||
sb := TStatusBar(Target);
|
|
||||||
if sb.SimplePanel then Exit;
|
|
||||||
if (idx<0) or (idx >= sb.Panels.Count) then Exit;
|
|
||||||
if sb.Panels[idx].Style <> psOwnerDraw then Exit;
|
|
||||||
|
|
||||||
ctx := TCocoaContext.Create(NSGraphicsContext.currentContext);
|
|
||||||
sv := ctx.SaveDC;
|
|
||||||
try
|
|
||||||
FillChar(msg, sizeof(msg), 0);
|
|
||||||
FillChar(dr, sizeof(dr), 0);
|
|
||||||
msg.Ctl := Target.Handle;
|
|
||||||
msg.Msg := LM_DRAWITEM;
|
|
||||||
msg.DrawItemStruct := @dr;
|
|
||||||
dr.itemID := idx;
|
|
||||||
dr._hDC := HDC(ctx);
|
|
||||||
dr.rcItem := r;
|
|
||||||
fr := NSView(Owner).lclFrame;
|
|
||||||
ctx.InitDraw(fr.Right-fr.Left, fr.Bottom-fr.Top);
|
|
||||||
LCLMessageGlue.DeliverMessage(Target, msg);
|
|
||||||
finally
|
|
||||||
ctx.RestoreDC(sv);
|
|
||||||
ctx.Free;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TLCLTabControlCallback }
|
{ TLCLTabControlCallback }
|
||||||
|
|
||||||
function TLCLTabControlCallback.shouldSelectTabViewItem(aTabIndex: Integer): Boolean;
|
function TLCLTabControlCallback.shouldSelectTabViewItem(aTabIndex: Integer): Boolean;
|
||||||
|
Loading…
Reference in New Issue
Block a user