public void CalculateWidths(Pango.Layout layout, bool headerVisible, int headerHeight) { bool min_was_zero = MinWidth == 0; bool was_size_req = false; var sr_cell = cells[0] as ISizeRequestCell; if (sr_cell != null && sr_cell.RestrictSize) { int min_w, max_w; sr_cell.GetWidthRange(layout, out min_w, out max_w); MinWidth = min_w == -1 ? MinWidth : min_w; MaxWidth = max_w == -1 ? MaxWidth : max_w; was_size_req = true; } if (headerVisible && (min_was_zero || was_size_req) && !string.IsNullOrEmpty(Title)) { int w, h; layout.SetText(Title); //column_layout.SetText ("\u2026"); // ellipsis char layout.GetPixelSize(out w, out h); // Pretty sure the 3* is needed here only b/c of the " - 8" in ColumnCellText; // See TODO there w += 3 * (int)HeaderCell.Padding.Left; if (this is ISortableColumn) { w += ColumnHeaderCellText.GetArrowWidth(headerHeight); } MinWidth = Math.Max(MinWidth, w); // If the min/max are sufficiently close (arbitrarily choosen as < 8px) then // make them equal, so that the column doesn't appear resizable but in reality is on barely. if (MaxWidth - MinWidth < 8) { MinWidth = MaxWidth; } } }
private void RecalculateColumnSizes() { if (column_cache == null) { return; } ISortable sortable = Model as ISortable; sort_column_index = -1; int min_header_width = 0; for (int i = 0; i < column_cache.Length; i++) { if (sortable != null) { ColumnHeaderCellText column_cell = column_cache[i].Column.HeaderCell as ColumnHeaderCellText; if (column_cell != null) { ISortableColumn sort_column = column_cache[i].Column as ISortableColumn; column_cell.HasSort = sort_column != null && sortable.SortColumn == sort_column; if (column_cell.HasSort) { sort_column_index = i; } } } column_cache[i].Column.CalculateWidths(column_layout, HeaderVisible, HeaderHeight); column_cache[i].MaxWidth = column_cache[i].Column.MaxWidth; column_cache[i].MinWidth = column_cache[i].Column.MinWidth; min_header_width += column_cache[i].MinWidth; } if (column_cache.Length == 1) { column_cache[0].Column.Width = 1.0; } else if (min_header_width >= header_interaction_alloc.Width) { header_width = min_header_width; resizable = false; for (int i = 0; i < column_cache.Length; i++) { column_cache[i].Column.Width = (double)column_cache[i].MinWidth / (double)header_width; } } else { header_width = header_interaction_alloc.Width; resizable = true; if (elastic_columns == null) { elastic_columns = new List <int> (column_cache.Length); } elastic_columns.Clear(); for (int i = 0; i < column_cache.Length; i++) { elastic_columns.Add(i); column_cache[i].ElasticWidth = 0.0; column_cache[i].ElasticPercent = column_cache[i].Column.Width * header_width; } double remaining_width = RecalculateColumnSizes(header_width, header_width); while (Math.Round(remaining_width) != 0.0 && elastic_columns.Count > 0) { double total_elastic_width = 0.0; foreach (int i in elastic_columns) { total_elastic_width += column_cache[i].ElasticWidth; } remaining_width = RecalculateColumnSizes(remaining_width, total_elastic_width); } for (int i = 0; i < column_cache.Length; i++) { column_cache[i].Column.Width = column_cache[i].ElasticWidth / (double)header_width; } } double tmp_width = 0.0; double tmp_max = 0.0; foreach (var col in column_cache) { tmp_width += col.ElasticWidth; tmp_max += col.MaxWidth == Int32.MaxValue ? col.MinWidth : col.MaxWidth; } list_width = tmp_width; max_width = tmp_max; }