Skip to content

Commit

Permalink
Merge pull request #2741 from cwensley/curtis/mac-expose-cell-formatt…
Browse files Browse the repository at this point in the history
…ing-for-fontset

Mac: Make MacCell/RowGridFormatEventArgs public
  • Loading branch information
cwensley authored Feb 6, 2025
2 parents 17010cf + e750083 commit 820306e
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Eto.Mac/Forms/Cells/CheckBoxCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
view.Tag = row;
view.Item = obj;
SetDefaults(view);
var args = new MacCellFormatArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
var args = new MacGridCellFormatEventArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
ColumnHandler.DataViewHandler.OnCellFormatting(args);
return view;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Eto.Mac/Forms/Cells/ComboBoxCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static bool IsDifferent(EtoPopUpButton field, NSMenu menu)

public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row, object dataItem)
{
var args = new MacCellFormatArgs(ColumnHandler.Widget, dataItem, row, field);
var args = new MacGridCellFormatEventArgs(ColumnHandler.Widget, dataItem, row, field);
ColumnHandler.DataViewHandler.OnCellFormatting(args);

field.Font = defaultFont;
Expand Down Expand Up @@ -263,7 +263,7 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
view.Tag = row;
view.Item = obj;
SetDefaults(view);
var formatArgs = new MacCellFormatArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
var formatArgs = new MacGridCellFormatEventArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
ColumnHandler.DataViewHandler.OnCellFormatting(formatArgs);
return view;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Mac/Forms/Cells/CustomCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
}

SetDefaults(view);
var formatArgs = new MacCellFormatArgs(ColumnHandler.Widget, item, row, view);
var formatArgs = new MacGridCellFormatEventArgs(ColumnHandler.Widget, item, row, view);
ColumnHandler.DataViewHandler.OnCellFormatting(formatArgs);
Callback.OnConfigureCell(Widget, view.Args, view.EtoControl);
return view;
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Mac/Forms/Cells/DrawableCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
view.Bind(enabledBinding, tableColumn, "editable", null);
}
SetDefaults(view);
var args = new MacCellFormatArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
var args = new MacGridCellFormatEventArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
ColumnHandler.DataViewHandler.OnCellFormatting(args);
return view;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Eto.Mac/Forms/Cells/ImageTextCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row,

field.ObjectValue = value as NSObject;

var args = new MacCellFormatArgs(ColumnHandler.Widget, dataItem, row, field);
var args = new MacGridCellFormatEventArgs(ColumnHandler.Widget, dataItem, row, field);
ColumnHandler.DataViewHandler.OnCellFormatting(args);

return field.FittingSize.Width;
Expand Down Expand Up @@ -232,7 +232,7 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
view.Tag = row;
view.Item = obj;
SetDefaults(view);
var args = new MacCellFormatArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
var args = new MacGridCellFormatEventArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
ColumnHandler.DataViewHandler.OnCellFormatting(args);
return view;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Eto.Mac/Forms/Cells/ImageViewCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
view = new EtoImageView { Identifier = tableColumn.Identifier };
}
SetDefaults(view);
var args = new MacCellFormatArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
var args = new MacGridCellFormatEventArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
ColumnHandler.DataViewHandler.OnCellFormatting(args);
return view;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Eto.Mac/Forms/Cells/ProgressCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override void SetObjectValue(object dataItem, NSObject value)

public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row, object dataItem)
{
var args = new MacCellFormatArgs(ColumnHandler.Widget, dataItem, row, field);
var args = new MacGridCellFormatEventArgs(ColumnHandler.Widget, dataItem, row, field);
ColumnHandler.DataViewHandler.OnCellFormatting(args);

field.Font = args.Font.ToNS() ?? NSFont.BoldSystemFontOfSize(NSFont.SystemFontSize);
Expand Down Expand Up @@ -78,7 +78,7 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
}

SetDefaults(view);
var args = new MacCellFormatArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
var args = new MacGridCellFormatEventArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
ColumnHandler.DataViewHandler.OnCellFormatting(args);
return view;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Eto.Mac/Forms/Cells/TextBoxCellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row,
field.ObjectValue = value as NSObject ?? new NSString(string.Empty);

SetDefaults(field);
var args = new MacCellFormatArgs(ColumnHandler.Widget, dataItem, row, field);
var args = new MacGridCellFormatEventArgs(ColumnHandler.Widget, dataItem, row, field);
ColumnHandler.DataViewHandler.OnCellFormatting(args);

return field.Cell.CellSizeForBounds(new CGRect(0, 0, nfloat.MaxValue, cellSize.Height)).Width;
Expand Down Expand Up @@ -190,7 +190,7 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
view.Item = obj;
view.Tag = row;
SetDefaults(view);
var args = new MacCellFormatArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
var args = new MacGridCellFormatEventArgs(ColumnHandler.Widget, getItem(obj, row), row, view);
ColumnHandler.DataViewHandler.OnCellFormatting(args);
return view;
}
Expand Down
64 changes: 41 additions & 23 deletions src/Eto.Mac/Forms/Controls/GridHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ public override void DrawRect(CGRect dirtyRect)
}
}

class MacCellFormatArgs : GridCellFormatEventArgs
public class MacGridCellFormatEventArgs : GridCellFormatEventArgs
{
public ICellHandler CellHandler { get { return Column.DataCell.Handler as ICellHandler; } }

public NSView View { get; private set; }

public MacCellFormatArgs(GridColumn column, object item, int row, NSView view)
public MacGridCellFormatEventArgs(GridColumn column, object item, int row, NSView view)
: base(column, item, row)
{
View = view;
}

public bool FontSet { get; set; }
public bool FontSet { get; private set; }

Font font;

Expand All @@ -121,25 +121,58 @@ public override Font Font
}
}

public bool BackgroundColorSet { get; private set; }

public override Color BackgroundColor
{
get { return CellHandler.GetBackgroundColor(View); }
set { CellHandler.SetBackgroundColor(View, value); }
set
{
CellHandler.SetBackgroundColor(View, value);
BackgroundColorSet = true;
}
}

public bool ForegroundColorSet { get; private set; }

public override Color ForegroundColor
{
get { return CellHandler.GetForegroundColor(View); }
set { CellHandler.SetForegroundColor(View, value); }
set
{
CellHandler.SetForegroundColor(View, value);
ForegroundColorSet = true;
}
}
}

public class MacGridRowFormatEventArgs : GridRowFormatEventArgs
{
NSTableRowView _rowView;
public MacGridRowFormatEventArgs(NSTableRowView rowView, object item, int row) : base(item, row)
{
_rowView = rowView;
}

public bool BackgroundColorSet { get; private set; }

public override Color BackgroundColor
{
get => _rowView.BackgroundColor.ToEto();
set
{
_rowView.BackgroundColor = value.ToNSUI();
BackgroundColorSet = true;
}
}
}

class GridDragInfo
{
public NSDragOperation AllowedOperation { get; set; }
public NSImage DragImage { get; set; }
public PointF ImageOffset { get; set; }

public DataObject Data { get; set; }

public CGPoint GetDragImageOffset()
Expand Down Expand Up @@ -695,7 +728,7 @@ protected override SizeF GetNaturalSize(SizeF availableSize)
public void OnCellFormatting(GridCellFormatEventArgs args)
{
var tooltipBinding = args.Column?.CellToolTipBinding;
if (tooltipBinding != null && args is MacCellFormatArgs macargs && macargs.View != null)
if (tooltipBinding != null && args is MacGridCellFormatEventArgs macargs && macargs.View != null)
macargs.View.ToolTip = tooltipBinding.GetValue(args.Item) ?? string.Empty;

Callback.OnCellFormatting(Widget, args);
Expand Down Expand Up @@ -962,25 +995,10 @@ protected override void SetBackgroundColor(Color? color)
}
}

class RowFormatEventArgs : GridRowFormatEventArgs
{
NSTableRowView _rowView;
public RowFormatEventArgs(NSTableRowView rowView, object item, int row) : base(item, row)
{
_rowView = rowView;
}

public override Color BackgroundColor
{
get => _rowView.BackgroundColor.ToEto();
set => _rowView.BackgroundColor = value.ToNSUI();
}
}

protected virtual void OnDidAddRowView(NSTableRowView rowView, nint row)
{
var item = GetItem((int)row);
Callback.OnRowFormatting(Widget, new RowFormatEventArgs(rowView, item, (int)row));
Callback.OnRowFormatting(Widget, new MacGridRowFormatEventArgs(rowView, item, (int)row));
}
}
}
Expand Down

0 comments on commit 820306e

Please sign in to comment.