Example #1
0
        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);
        }
Example #2
0
        static void UpdatePlaceholder(CellNSView cell, EntryCell entryCell)
        {
            var nsTextField = cell.AccessoryView.Subviews[0] as NSTextField;

            if (nsTextField != null)
            {
                nsTextField.PlaceholderString = entryCell.Placeholder ?? "";
            }
        }
Example #3
0
        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;
            }
        }
Example #4
0
        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;
            }
        }
Example #5
0
        static void SetImage(ImageCell cell, CellNSView target)
        {
            target.ImageView.Image = null;

            _ = cell.ApplyNativeImageAsync(ImageCell.ImageSourceProperty, image =>
            {
                target.ImageView.Image = image;
                target.NeedsLayout     = true;
            });
        }
Example #6
0
        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));
            }
        }
Example #7
0
        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 ?? "";
            }
        }
Example #8
0
        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);
        }
Example #9
0
        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);
        }
Example #10
0
        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);
        }
Example #11
0
        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;
            }
        }
Example #12
0
        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;
            }
        }
Example #13
0
 static void UpdateIsEnabled(CellNSView cell, TextCell entryCell)
 {
     cell.TextLabel.Enabled       = entryCell.IsEnabled;
     cell.DetailTextLabel.Enabled = entryCell.IsEnabled;
 }
Example #14
0
 static void UpdateLabelColor(CellNSView cell, EntryCell entryCell)
 {
     cell.TextLabel.TextColor = entryCell.LabelColor.ToNSColor(s_defaultTextColor);
 }
Example #15
0
 static void UpdateLabel(CellNSView cell, EntryCell entryCell)
 {
     cell.TextLabel.StringValue = entryCell.Label ?? "";
 }