Ejemplo n.º 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 = Controller.Model.GetHeaderCell(sectionIndex) ??
                       new TextCell {
                    Text = Controller.Model.GetSectionTitle(sectionIndex)
                };
            }
            else
            {
                id   = ItemIdentifier;
                cell = Controller.Model.GetCell(sectionIndex, itemIndexInSection);
            }

            var nativeCell = CellNSView.GetNativeCell(tableView, cell, id, isHeader);

            return(nativeCell);
        }
Ejemplo n.º 2
0
        static async Task SetImage(ImageCell cell, CellNSView target)
        {
            var source = cell.ImageSource;

            target.ImageView.Image = null;

            IImageSourceHandler handler;

            if (source != null && (handler = Internals.Registrar.Registered.GetHandlerForObject <IImageSourceHandler>(source)) != null)
            {
                NSImage uiimage;
                try
                {
                    uiimage = await handler.LoadImageAsync(source).ConfigureAwait(false);
                }
                catch (TaskCanceledException)
                {
                    uiimage = null;
                }

                NSRunLoop.Main.BeginInvokeOnMainThread(() =>
                {
                    target.ImageView.Image = uiimage;
                    target.NeedsLayout     = true;
                });
            }
            else
            {
                target.ImageView.Image = null;
            }
        }
Ejemplo n.º 3
0
        static void UpdatePlaceholder(CellNSView cell, EntryCell entryCell)
        {
            var nsTextField = cell.AccessoryView.Subviews[0] as NSTextField;

            if (nsTextField != null)
            {
                nsTextField.PlaceholderString = entryCell.Placeholder ?? "";
            }
        }
Ejemplo n.º 4
0
        static void UpdateHorizontalTextAlignment(CellNSView cell, EntryCell entryCell)
        {
            var nsTextField = cell.AccessoryView.Subviews[0] as NSTextField;

            if (nsTextField != null)
            {
                nsTextField.Alignment = entryCell.HorizontalTextAlignment.ToNativeTextAlignment();
            }
        }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
0
        static void SetImage(ImageCell cell, CellNSView target)
        {
            target.ImageView.Image = null;

            _ = cell.ApplyNativeImageAsync(ImageCell.ImageSourceProperty, image =>
            {
                target.ImageView.Image = image;
                target.NeedsLayout     = true;
            });
        }
Ejemplo n.º 7
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;
            }
        }
Ejemplo n.º 8
0
        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));
            }
        }
Ejemplo n.º 9
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 ?? "";
            }
        }
Ejemplo n.º 10
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 = Controller.CachingStrategy;

            if (cachingStrategy == ListViewCachingStrategy.RetainElement)
            {
                cell       = GetCellForPath(indexPath, isHeader);
                nativeCell = CellNSView.GetNativeCell(tableView, cell, templateId, isHeader);
            }
            else if (cachingStrategy == ListViewCachingStrategy.RecycleElement)
            {
                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;
                    ICellController controller = cell;
                    controller.SendDisappearing();
                    templatedList.UpdateContent(cell, itemIndexInSection);
                    controller.SendAppearing();
                }
            }
            else
            {
                throw new NotSupportedException();
            }
            return(nativeCell);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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;
            }
        }
Ejemplo n.º 14
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;
            }
        }
Ejemplo n.º 15
0
 static void UpdateIsEnabled(CellNSView cell, TextCell entryCell)
 {
     cell.TextLabel.Enabled       = entryCell.IsEnabled;
     cell.DetailTextLabel.Enabled = entryCell.IsEnabled;
 }
Ejemplo n.º 16
0
 static void UpdateLabelColor(CellNSView cell, EntryCell entryCell)
 {
     cell.TextLabel.TextColor = entryCell.LabelColor.ToNSColor(s_defaultTextColor);
 }
Ejemplo n.º 17
0
 static void UpdateLabel(CellNSView cell, EntryCell entryCell)
 {
     cell.TextLabel.StringValue = entryCell.Label ?? "";
 }