/// <summary> /// Removes all grid columns, and cleans up any associated event handlers /// </summary> private void ClearGridColumns() { if (refColWidget != null) { refColWidget.SizeAllocated -= RefColWidget_SizeAllocated; refColWidget = null; } while (Fixedcolview.Columns.Length > 0) { TreeViewColumn col = Fixedcolview.GetColumn(0); foreach (CellRenderer render in col.Cells) { if (render is CellRendererText) { CellRendererText textRender = render as CellRendererText; col.SetCellDataFunc(textRender, (CellLayoutDataFunc)null); } } Fixedcolview.RemoveColumn(Fixedcolview.GetColumn(0)); } while (Grid.Columns.Length > 0) { TreeViewColumn col = Grid.GetColumn(0); foreach (CellRenderer render in col.Cells) { if (render is CellRendererText) { CellRendererText textRender = render as CellRendererText; col.SetCellDataFunc(textRender, (CellLayoutDataFunc)null); } else if (render is CellRendererPixbuf) { CellRendererPixbuf pixRender = render as CellRendererPixbuf; col.SetCellDataFunc(pixRender, (CellLayoutDataFunc)null); } render.Dispose(); } Grid.RemoveColumn(Grid.GetColumn(0)); } }
/// <summary> /// Removes all grid columns, and cleans up any associated event handlers /// </summary> private void ClearGridColumns() { while (Grid.Columns.Length > 0) { TreeViewColumn col = Grid.GetColumn(0); #if NETFRAMEWORK foreach (CellRenderer render in col.CellRenderers) #else foreach (CellRenderer render in col.Cells) #endif { if (render is CellRendererText) { CellRendererText textRender = render as CellRendererText; col.SetCellDataFunc(textRender, (CellLayoutDataFunc)null); } else if (render is CellRendererPixbuf) { CellRendererPixbuf pixRender = render as CellRendererPixbuf; col.SetCellDataFunc(pixRender, (CellLayoutDataFunc)null); } render.Dispose(); } Grid.RemoveColumn(Grid.GetColumn(0)); } while (Fixedcolview.Columns.Length > 0) { TreeViewColumn col = Fixedcolview.GetColumn(0); foreach (CellRenderer render in col.GetCells()) { if (render is CellRendererText) { CellRendererText textRender = render as CellRendererText; col.SetCellDataFunc(textRender, (CellLayoutDataFunc)null); } } Fixedcolview.RemoveColumn(Fixedcolview.GetColumn(0)); } }
/// <summary> /// Populate the grid from the DataSource. /// Note that we don't statically set the contents of the grid cells, but rather do this /// dynamically in OnSetCellData. However, we do set up appropriate attributes for /// cell columns, and a set of cell renderers. /// </summary> private void PopulateGrid() { // WaitCursor = true; // Set the cursor directly rather than via the WaitCursor property, as the property setter // runs a message loop. This is normally desirable, but in this case, we have lots // of events associated with the grid data, and it's best to let them be handled in the // main message loop. if (MasterView.MainWindow != null) { MasterView.MainWindow.Cursor = new Gdk.Cursor(Gdk.CursorType.Watch); } ClearGridColumns(); Fixedcolview.Visible = false; colLookup.Clear(); // Begin by creating a new ListStore with the appropriate number of // columns. Use the string column type for everything. int nCols = DataSource != null ? this.DataSource.Columns.Count : 0; Type[] colTypes = new Type[nCols]; for (int i = 0; i < nCols; i++) { colTypes[i] = typeof(string); } gridmodel = new ListStore(colTypes); image1.Visible = false; // Now set up the grid columns for (int i = 0; i < nCols; i++) { // Design plan: include renderers for text, toggles and combos, but hide all but one of them CellRendererText textRender = new Gtk.CellRendererText(); CellRendererPixbuf pixbufRender = new CellRendererPixbuf(); pixbufRender.Pixbuf = new Gdk.Pixbuf(null, "ApsimNG.Resources.MenuImages.Save.svg"); pixbufRender.Xalign = 0.5f; if (i == 0 || i == nCols - 1) { colLookup.Add(textRender, i); } else { colLookup.Add(pixbufRender, i); } textRender.FixedHeightFromFont = 1; // 1 line high pixbufRender.Height = 19; //TODO change based on zoom rate of UI //previously 23 before smaller UI font textRender.Editable = !isReadOnly; textRender.Xalign = ((i == 0) || (i == 1) && isPropertyMode) ? 0.0f : 1.0f; // For right alignment of text cell contents; left align the first column TreeViewColumn column = new TreeViewColumn(); column.Title = this.DataSource.Columns[i].Caption; if (i == 0 || i == nCols - 1) { column.PackStart(textRender, true); // 0 } else { column.PackStart(pixbufRender, false); // 3 } if (i == 0 || i == nCols - 1) { column.SetCellDataFunc(textRender, OnSetCellData); } else { column.SetCellDataFunc(pixbufRender, RenderActivityStatus); } if (i == 1 && isPropertyMode) { column.Alignment = 0.0f; } else { column.Alignment = 0.5f; // For centered alignment of the column header } Grid.AppendColumn(column); // Gtk Treeview doesn't support "frozen" columns, so we fake it by creating a second, identical, TreeView to display // the columns we want frozen // For now, these frozen columns will be treated as read-only text TreeViewColumn fixedColumn = new TreeViewColumn(this.DataSource.Columns[i].ColumnName, textRender, "text", i); //fixedColumn.Sizing = TreeViewColumnSizing.GrowOnly; fixedColumn.Resizable = false; fixedColumn.SetCellDataFunc(textRender, OnSetCellData); fixedColumn.Alignment = 0.0f; // For centered alignment of the column header fixedColumn.Visible = true; Fixedcolview.AppendColumn(fixedColumn); } if (!isPropertyMode) { // Add an empty column at the end; auto-sizing will give this any "leftover" space TreeViewColumn fillColumn = new TreeViewColumn(); Grid.AppendColumn(fillColumn); fillColumn.Sizing = TreeViewColumnSizing.Autosize; } int nRows = DataSource != null ? this.DataSource.Rows.Count : 0; Grid.Model = null; Fixedcolview.Model = null; for (int row = 0; row < nRows; row++) { // We could store data into the grid model, but we don't. // Instead, we retrieve the data from our datastore when the OnSetCellData function is called gridmodel.Append(); } Grid.Model = gridmodel; SetColumnHeaders(Grid); SetColumnHeaders(Fixedcolview); Grid.EnableSearch = false; Fixedcolview.EnableSearch = false; Grid.Show(); Fixedcolview.WidthRequest = 150; if (MasterView.MainWindow != null) { MasterView.MainWindow.Cursor = null; } }
/// <summary>Lock the left most number of columns.</summary> /// <param name="number"></param> public void LockLeftMostColumns(int number) { if (number == numberLockedCols || !Grid.IsMapped) { return; } for (int i = 0; i < gridmodel.NColumns; i++) { if (Fixedcolview.Columns.Length > i) { Fixedcolview.Columns[i].Visible = i < number; } if (Grid.Columns.Length > i) { Grid.Columns[i].Visible = i >= number; } } if (number > 0) { if (numberLockedCols == 0) { Grid.Vadjustment.ValueChanged += Gridview_Vadjustment_Changed; Grid.Selection.Changed += Gridview_CursorChanged; Fixedcolview.Vadjustment.ValueChanged += Fixedcolview_Vadjustment_Changed1; Fixedcolview.Selection.Changed += Fixedcolview_CursorChanged; Gridview_CursorChanged(this, EventArgs.Empty); Gridview_Vadjustment_Changed(this, EventArgs.Empty); } if (!splitter.Child1.Visible) { //Grid.Vadjustment.ValueChanged += GridviewVadjustmentChanged; //Grid.Selection.Changed += GridviewCursorChanged; //fixedcolview.Vadjustment.ValueChanged += FixedcolviewVadjustmentChanged; //fixedcolview.Selection.Changed += FixedcolviewCursorChanged; //GridviewCursorChanged(this, EventArgs.Empty); //GridviewVadjustmentChanged(this, EventArgs.Empty); } Fixedcolview.Model = gridmodel; Fixedcolview.Visible = true; splitter.Child1.NoShowAll = false; splitter.ShowAll(); splitter.PositionSet = true; int splitterWidth = (int)splitter.StyleGetProperty("handle-size"); if (splitter.Allocation.Width > 1) { splitter.Position = Math.Min(Fixedcolview.SizeRequest().Width + splitterWidth, splitter.Allocation.Width / 2); } else { splitter.Position = Fixedcolview.SizeRequest().Width + splitterWidth; } } else { Grid.Vadjustment.ValueChanged -= Gridview_Vadjustment_Changed; Grid.Selection.Changed -= Gridview_CursorChanged; Fixedcolview.Vadjustment.ValueChanged -= Fixedcolview_Vadjustment_Changed1; Fixedcolview.Selection.Changed -= Fixedcolview_CursorChanged; Fixedcolview.Visible = false; splitter.Position = 0; splitter.Child1.HideAll(); } numberLockedCols = number; }