Skip to content

Commit

Permalink
Merge pull request #2240 from cwensley/curtis/grid-column-width-and-g…
Browse files Browse the repository at this point in the history
…etcellat-improvements

Tree/GridView column width and cell types for GetCellAt
  • Loading branch information
cwensley authored Jun 10, 2022
2 parents 11caf99 + 1d67324 commit d7955de
Show file tree
Hide file tree
Showing 26 changed files with 761 additions and 340 deletions.
57 changes: 34 additions & 23 deletions src/Eto.Gtk/Forms/Controls/GridColumnHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface IGridHandler
void ColumnClicked(GridColumnHandler column);
int GetColumnDisplayIndex(GridColumnHandler column);
void SetColumnDisplayIndex(GridColumnHandler column, int index);
void ColumnWidthChanged(GridColumnHandler h);
}

public class GridColumnHandler : WidgetHandler<Gtk.TreeViewColumn, GridColumn>, GridColumn.IHandler
Expand All @@ -31,32 +32,32 @@ public GridColumnHandler()
AutoSize = true;
Resizable = true;
DataCell = new TextBoxCell();
Control.Clickable = true;
}

public string HeaderText
{
get { return Control.Title; }
set { Control.Title = value; }
get => Control.Title;
set => Control.Title = value;
}

public bool Resizable
{
get { return Control.Resizable; }
set { Control.Resizable = value; }
get => Control.Resizable;
set => Control.Resizable = value;
}

static readonly object Sortable_Key = new object();

public bool Sortable
{
get { return Control.Clickable; }
set { Control.Clickable = value; }
get => Widget.Properties.Get<bool>(Sortable_Key);
set => Widget.Properties.Set(Sortable_Key, value);
}

public bool AutoSize
{
get
{
return autoSize;
}
get => Control.Sizing == Gtk.TreeViewColumnSizing.Fixed ? false : true;
set
{
autoSize = value;
Expand Down Expand Up @@ -90,7 +91,7 @@ public bool Editable

public int Width
{
get { return Control.Width; }
get => Control.Width;
set
{
autoSize = value == -1;
Expand All @@ -101,20 +102,14 @@ public int Width

public Cell DataCell
{
get
{
return dataCell;
}
set
{
dataCell = value;
}
get => dataCell;
set => dataCell = value;
}

public bool Visible
{
get { return Control.Visible; }
set { Control.Visible = value; }
get => Control.Visible;
set => Control.Visible = value;
}

public void SetupCell(IGridHandler grid, ICellDataSource source, int columnIndex, ref int dataIndex)
Expand Down Expand Up @@ -146,6 +141,8 @@ public void SetupEvents()
HandleEvent(Grid.ColumnHeaderClickEvent);
if (grid.IsEventHandled(Grid.CellFormattingEvent))
HandleEvent(Grid.CellFormattingEvent);
if (grid.IsEventHandled(Grid.ColumnWidthChangedEvent))
HandleEvent(Grid.ColumnWidthChangedEvent);
}

public override void AttachEvent(string id)
Expand All @@ -157,10 +154,24 @@ public override void AttachEvent(string id)
Control.Clicked += (sender, e) =>
{
var h = ((GridColumnHandler)handler.Target);
if (h != null && h.grid != null)
if (h != null && h.grid != null && h.Sortable)
h.grid.ColumnClicked(h);
};
break;
case Grid.ColumnWidthChangedEvent:
var handler2 = new WeakReference(this);
var lastWidth = -1;
Control.AddNotification("width", (o, args) =>
{
var h = (GridColumnHandler)handler2.Target;
if (h == null)
return;
if (lastWidth == h.Width)
return;
lastWidth = h.Width;
h.grid?.ColumnWidthChanged(h);
});
break;
default:
((ICellHandler)dataCell.Handler).HandleEvent(id);
break;
Expand Down Expand Up @@ -202,7 +213,7 @@ public int MaxWidth
GridHandler?.Tree?.ColumnsAutosize();
}
}

int? displayIndex;

public int DisplayIndex
Expand Down
Loading

0 comments on commit d7955de

Please sign in to comment.