public override NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, nint row) { int sectionIndex; bool isHeader; int itemIndexInSection; GetComputedIndexes(row, out sectionIndex, out itemIndexInSection, out isHeader); string id; Cell cell; if (isHeader) { id = HeaderIdentifier; cell = _tableView.Model.GetHeaderCell(sectionIndex) ?? new TextCell { Text = _tableView.Model.GetSectionTitle(sectionIndex) }; } else { id = ItemIdentifier; cell = _tableView.Model.GetCell(sectionIndex, itemIndexInSection); } var nativeCell = CellNSView.GetNativeCell(tableView, cell, id, isHeader); return(nativeCell); }
static void UpdatePlaceholder(CellNSView cell, EntryCell entryCell) { var nsTextField = cell.AccessoryView.Subviews[0] as NSTextField; if (nsTextField != null) { nsTextField.PlaceholderString = entryCell.Placeholder ?? ""; } }
static void UpdateIsEnabled(CellNSView cell, EntryCell entryCell) { cell.TextLabel.Enabled = entryCell.IsEnabled; var nsTextField = cell.AccessoryView.Subviews[0] as NSTextField; if (nsTextField != null) { nsTextField.Enabled = entryCell.IsEnabled; } }
static void UpdateIsEnabled(CellNSView cell, SwitchCell switchCell) { cell.TextLabel.Enabled = switchCell.IsEnabled; var uiSwitch = cell.AccessoryView.Subviews[0] as NSButton; if (uiSwitch != null) { uiSwitch.Enabled = switchCell.IsEnabled; } }
static void SetImage(ImageCell cell, CellNSView target) { target.ImageView.Image = null; _ = cell.ApplyNativeImageAsync(ImageCell.ImageSourceProperty, image => { target.ImageView.Image = image; target.NeedsLayout = true; }); }
static void UpdateHorizontalTextAlignment(CellNSView cell, EntryCell entryCell) { IVisualElementController viewController = entryCell.Parent as VisualElement; var nsTextField = cell.AccessoryView.Subviews[0] as NSTextField; if (nsTextField != null) { nsTextField.Alignment = entryCell.HorizontalTextAlignment.ToNativeTextAlignment(viewController?.EffectiveFlowDirection ?? default(EffectiveFlowDirection)); } }
static void UpdateText(CellNSView cell, EntryCell entryCell) { var nsTextField = cell.AccessoryView.Subviews[0] as NSTextField; if (nsTextField != null && nsTextField.StringValue == entryCell.Text) { return; } if (nsTextField != null) { nsTextField.StringValue = entryCell.Text ?? ""; } }
public override NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, nint row) { var sectionIndex = 0; var itemIndexInSection = (int)row; Cell cell; var isHeader = false; if (IsGroupingEnabled) { GetComputedIndexes(row, out sectionIndex, out itemIndexInSection, out isHeader); } var indexPath = NSIndexPath.FromItemSection(itemIndexInSection, sectionIndex); var templateId = isHeader ? "headerCell" : TemplateIdForPath(indexPath).ToString(); NSView nativeCell; var cachingStrategy = List.CachingStrategy; if (cachingStrategy == ListViewCachingStrategy.RetainElement) { cell = GetCellForPath(indexPath, isHeader); nativeCell = CellNSView.GetNativeCell(tableView, cell, templateId, isHeader); } else if ((cachingStrategy & ListViewCachingStrategy.RecycleElement) != 0) { nativeCell = tableView.MakeView(templateId, tableView); if (nativeCell == null) { cell = GetCellForPath(indexPath, isHeader); nativeCell = CellNSView.GetNativeCell(tableView, cell, templateId, isHeader, true); } else { var templatedList = TemplatedItemsView.TemplatedItems.GetGroup(sectionIndex); cell = (Cell)((INativeElementView)nativeCell).Element; cell.SendDisappearing(); templatedList.UpdateContent(cell, itemIndexInSection); cell.SendAppearing(); } } else { throw new NotSupportedException(); } return(nativeCell); }
public override NSView GetCell(Cell item, NSView reusableView, NSTableView tv) { NSTextField nsEntry = null; var tvc = reusableView as CellNSView; if (tvc == null) { tvc = new CellNSView(NSTableViewCellStyle.Value2); } else { tvc.Cell.PropertyChanged -= OnCellPropertyChanged; nsEntry = tvc.AccessoryView.Subviews[0] as NSTextField; if (nsEntry != null) { nsEntry.RemoveFromSuperview(); nsEntry.Changed -= OnTextFieldTextChanged; } } SetRealCell(item, tvc); if (nsEntry == null) { tvc.AccessoryView.AddSubview(nsEntry = new NSTextField()); } var entryCell = (EntryCell)item; tvc.Cell = item; tvc.Cell.PropertyChanged += OnCellPropertyChanged; nsEntry.Changed += OnTextFieldTextChanged; WireUpForceUpdateSizeRequested(item, tvc, tv); UpdateBackground(tvc, entryCell); UpdateLabel(tvc, entryCell); UpdateText(tvc, entryCell); UpdatePlaceholder(tvc, entryCell); UpdateLabelColor(tvc, entryCell); UpdateHorizontalTextAlignment(tvc, entryCell); UpdateIsEnabled(tvc, entryCell); return(tvc); }
public override NSView GetCell(Cell item, NSView reusableView, NSTableView tv) { var tvc = reusableView as CellNSView; NSButton nsSwitch = null; if (tvc == null) { tvc = new CellNSView(NSTableViewCellStyle.Value1); } else { nsSwitch = tvc.AccessoryView.Subviews[0] as NSButton; if (nsSwitch != null) { nsSwitch.RemoveFromSuperview(); nsSwitch.Activated -= OnSwitchValueChanged; } tvc.Cell.PropertyChanged -= OnCellPropertyChanged; } SetRealCell(item, tvc); if (nsSwitch == null) { nsSwitch = new NSButton { AllowsMixedState = false, Title = string.Empty }; nsSwitch.SetButtonType(NSButtonType.Switch); } var boolCell = (SwitchCell)item; tvc.Cell = item; tvc.Cell.PropertyChanged += OnCellPropertyChanged; tvc.AccessoryView.AddSubview(nsSwitch); tvc.TextLabel.StringValue = boolCell.Text ?? ""; nsSwitch.State = boolCell.On ? NSCellStateValue.On : NSCellStateValue.Off; nsSwitch.Activated += OnSwitchValueChanged; WireUpForceUpdateSizeRequested(item, tvc, tv); UpdateBackground(tvc, item); UpdateIsEnabled(tvc, boolCell); return(tvc); }
void OnSwitchValueChanged(object sender, EventArgs eventArgs) { var view = (NSView)sender; var sw = (NSButton)view; CellNSView realCell = null; while (view.Superview != null && realCell == null) { view = view.Superview; realCell = view as CellNSView; } if (realCell != null) { ((SwitchCell)realCell.Cell).On = sw.State == NSCellStateValue.On; } }
static void OnTextFieldTextChanged(object sender, EventArgs eventArgs) { var notification = (NSNotification)sender; var view = (NSView)notification.Object; var field = (NSTextField)view; CellNSView realCell = null; while (view.Superview != null && realCell == null) { view = view.Superview; realCell = view as CellNSView; } if (realCell != null) { ((EntryCell)realCell.Cell).Text = field.StringValue; } }
static void UpdateIsEnabled(CellNSView cell, TextCell entryCell) { cell.TextLabel.Enabled = entryCell.IsEnabled; cell.DetailTextLabel.Enabled = entryCell.IsEnabled; }
static void UpdateLabelColor(CellNSView cell, EntryCell entryCell) { cell.TextLabel.TextColor = entryCell.LabelColor.ToNSColor(s_defaultTextColor); }
static void UpdateLabel(CellNSView cell, EntryCell entryCell) { cell.TextLabel.StringValue = entryCell.Label ?? ""; }