mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-10 20:42:05 +02:00
cocoa: implementing owner drawn for status bar panels. #34338
git-svn-id: trunk@59187 -
This commit is contained in:
parent
8d0fe522bb
commit
9c1f561955
@ -233,7 +233,7 @@ type
|
||||
//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;
|
||||
//todo: add a method for OwnerDraw Panels support
|
||||
procedure DrawPanel(idx: Integer; const r: TRect; var NeedDraw: Boolean);
|
||||
end;
|
||||
|
||||
TCocoaStatusBar = objcclass(TCocoaCustomControl)
|
||||
@ -1093,6 +1093,7 @@ var
|
||||
txt : string;
|
||||
cnt : Integer;
|
||||
w : Integer;
|
||||
nd : Boolean;
|
||||
const
|
||||
CocoaAlign: array [TAlignment] of Integer = (NSNaturalTextAlignment, NSRightTextAlignment, NSCenterTextAlignment);
|
||||
begin
|
||||
@ -1116,15 +1117,21 @@ begin
|
||||
|
||||
if not barcallback.GetBarItem(i, txt, w, al) then Continue;
|
||||
|
||||
|
||||
if i = cnt - 1 then w := r.Right - x;
|
||||
nr.size.width := w;
|
||||
nr.origin.x := x;
|
||||
|
||||
cs := NSStringUtf8(txt);
|
||||
panelCell.setTitle(cs);
|
||||
panelCell.setAlignment(CocoaAlign[al]);
|
||||
panelCell.drawWithFrame_inView(nr, Self);
|
||||
cs.release;
|
||||
nd := false;
|
||||
barcallback.DrawPanel(i, NSRectToRect(nr), nd);
|
||||
if nd then
|
||||
begin
|
||||
cs := NSStringUtf8(txt);
|
||||
panelCell.setTitle(cs);
|
||||
panelCell.setAlignment(CocoaAlign[al]);
|
||||
panelCell.drawWithFrame_inView(nr, Self);
|
||||
cs.release;
|
||||
end;
|
||||
inc(x, w);
|
||||
if x > r.Right then break; // no place left
|
||||
end;
|
||||
|
@ -29,6 +29,7 @@ type
|
||||
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; var NeedDraw: Boolean);
|
||||
end;
|
||||
|
||||
TCocoaWSStatusBar = class(TWSStatusBar)
|
||||
@ -320,6 +321,41 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TStatusBarCallback.DrawPanel(idx: Integer; const r: TRect;
|
||||
var NeedDraw: Boolean);
|
||||
var
|
||||
sb : TStatusBar;
|
||||
msg : TLMDrawItems;
|
||||
ctx : TCocoaContext;
|
||||
dr : TDrawItemStruct;
|
||||
fr : TRect;
|
||||
begin
|
||||
sb := TStatusBar(Target);
|
||||
NeedDraw := true;
|
||||
if sb.SimplePanel then Exit;
|
||||
if (idx<0) or (idx >= sb.Panels.Count) then Exit;
|
||||
|
||||
NeedDraw := sb.Panels[idx].Style <> psOwnerDraw;
|
||||
if NeedDraw then Exit;
|
||||
|
||||
ctx := TCocoaContext.Create(NSGraphicsContext.currentContext);
|
||||
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.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TLCLTabControlCallback }
|
||||
|
||||
procedure TLCLTabControlCallback.willSelectTabViewItem(aTabIndex: Integer);
|
||||
|
Loading…
Reference in New Issue
Block a user