private void Initialize(IHostResourceProvider hostResources)
        {
            WantsLayer = true;
            Editors    = CreateEditors(hostResources, EditorType);

            this.hexLabel = new UnfocusableTextField {
                StringValue = "#:",
                Alignment   = NSTextAlignment.Right,
                ToolTip     = Properties.Resources.HexValue
            };
            AddSubview(this.hexLabel);

            this.hexEditor = new NSTextField {
                Alignment   = NSTextAlignment.Right,
                ControlSize = NSControlSize.Small,
                Font        = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small))
            };
            AddSubview(this.hexEditor);

            this.hexEditor.EditingEnded += (o, e) => {
                if (CommonColor.TryParseArgbHex(this.hexEditor.StringValue, out CommonColor c))
                {
                    ViewModel.Color            = c;
                    this.hexEditor.StringValue = c.ToString();
                }
            };
        }
예제 #2
0
        public BrushTabViewController(IHostResourceProvider hostResources)
            : base(hostResources)
        {
            TabBorderColor     = NamedResources.TabBorderColor;
            TabBackgroundColor = NamedResources.PadBackgroundColor;

            PreferredContentSize = new CGSize(450, 280);
            TransitionOptions    = NSViewControllerTransitionOptions.None;
            ContentPadding       = new NSEdgeInsets(8, 8, 8, 8);

            this.filterResource = new NSSearchField {
                ControlSize       = NSControlSize.Mini,
                Font              = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Mini)),
                PlaceholderString = Properties.Resources.SearchResourcesTitle,
            };

            this.filterResource.Changed += (sender, e) => {
                ViewModel.ResourceSelector.FilterText = this.filterResource.Cell.Title;
                this.resource.ReloadData();
            };

            this.filterResource.Hidden = true;

            TabStack.AddView(this.filterResource, NSStackViewGravity.Leading);
        }
예제 #3
0
        protected override void OnViewModelChanged(PropertyViewModel oldModel)
        {
            base.OnViewModelChanged(oldModel);

            if (ViewModel == null)
            {
                return;
            }

            RightEdgeConstraint.Active = !ViewModel.HasInputModes;
            if (ViewModel.HasInputModes)
            {
                if (this.inputModePopup == null)
                {
                    this.inputModePopup = new FocusablePopUpButton {
                        Menu        = new NSMenu(),
                        ControlSize = NSControlSize.Small,
                        Font        = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                        TranslatesAutoresizingMaskIntoConstraints = false
                    };

                    this.inputModePopup.Activated += (o, e) => {
                        var popupButton = o as NSPopUpButton;
                        ViewModel.InputMode = this.viewModelInputModes.FirstOrDefault(im => im.Identifier == popupButton.Title);
                    };

                    AddSubview(this.inputModePopup);

                    this.editorInputModeConstraint = NSLayoutConstraint.Create(Entry, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.inputModePopup, NSLayoutAttribute.Left, 1, -4);

                    AddConstraints(new[] {
                        this.editorInputModeConstraint,
                        NSLayoutConstraint.Create(this.inputModePopup, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f),
                        NSLayoutConstraint.Create(this.inputModePopup, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0),
                        NSLayoutConstraint.Create(this.inputModePopup, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, DefaultButtonWidth),
                        NSLayoutConstraint.Create(this.inputModePopup, NSLayoutAttribute.Height, NSLayoutRelation.Equal, Entry, NSLayoutAttribute.Height, 1, 0),
                    });

                    this.lastKeyView = this.inputModePopup;
                }

                this.inputModePopup.Menu.RemoveAllItems();
                this.viewModelInputModes = ViewModel.InputModes;
                foreach (InputMode item in this.viewModelInputModes)
                {
                    this.inputModePopup.Menu.AddItem(new NSMenuItem(item.Identifier));
                }
            }

            // If we are reusing the control we'll have to hid the inputMode if this doesn't have InputMode.
            if (this.inputModePopup != null)
            {
                this.inputModePopup.Hidden            = !ViewModel.HasInputModes;
                this.editorInputModeConstraint.Active = ViewModel.HasInputModes;
                UpdateAccessibilityValues();
            }

            SetEnabled();
        }
예제 #4
0
 void Initialize()
 {
     ControlSize     = NSControlSize.Regular;
     Font            = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(ControlSize));
     Bezeled         = false;
     DrawsBackground = false;
     Editable        = false;
     Selectable      = false;
 }
예제 #5
0
        void IView.SetViewModel(IViewModel viewModel)
        {
            this.viewModel = viewModel;

            this.graphicsResources = new GraphicsResources(
                viewModel,
                (fontData) => new LJD.Font(fontData.Name ?? "monaco",
                                           (float)NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                textFormat: null,
                images: (
                    error: new LJD.Image(NSImage.ImageNamed("ErrorLogSeverity.png")),
                    warn: new LJD.Image(NSImage.ImageNamed("WarnLogSeverity.png")),
                    bookmark: new LJD.Image(NSImage.ImageNamed("Bookmark.png")),
                    focusedMark: new LJD.Image(NSImage.ImageNamed("FocusedMsg.png"))
                    ),
                graphicsForMeasurmentFactory: () => graphicsForMeasurment
                );
            this.viewDrawing = new ViewDrawing(viewModel,
                                               graphicsResources,
                                               1f,
                                               () => 0,
                                               () => viewWidth
                                               );
            this.drawingPerfCounters       = new Profiling.Counters(viewModel.Trace, "drawing");
            this.graphicsCounters          = LJD.Graphics.CreateCounters(drawingPerfCounters);
            this.controlPaintTimeCounter   = this.drawingPerfCounters.AddCounter("paint", unit: "ms");
            this.controlPaintWidthCounter  = this.drawingPerfCounters.AddCounter("width", unit: "pixel");
            this.controlPaintHeightCounter = this.drawingPerfCounters.AddCounter("height", unit: "pixel");
            var viewUpdater = Updaters.Create(
                () => viewModel.ViewLines,
                () => viewModel.FocusedMessageMark,
                (_1, _2) => { this.InnerView.NeedsDisplay = true; }
                );
            var emptyViewMessageUpdater = Updaters.Create(
                () => viewModel.EmptyViewMessage,
                value => {
                drawDropMessage         = value;
                DragDropIconView.Hidden = value == null;
            }
                );
            var vScrollUpdater = Updaters.Create(
                () => viewModel.VerticalScrollerPosition,
                value => {
                VertScroller.Enabled        = value.HasValue;
                VertScroller.KnobProportion = 0.0001f;
                VertScroller.DoubleValue    = value.GetValueOrDefault();
            }
                );

            viewModel.ChangeNotification.CreateSubscription(() => {
                viewUpdater();
                emptyViewMessageUpdater();
                vScrollUpdater();
            });
        }
예제 #6
0
 public FocusableButton()
 {
     AllowsExpansionToolTips = true;
     AllowsMixedState        = true;
     Cell.LineBreakMode      = NSLineBreakMode.TruncatingTail;
     Cell.UsesSingleLineMode = true;
     ControlSize             = NSControlSize.Small;
     Font  = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small));
     Title = string.Empty;
     TranslatesAutoresizingMaskIntoConstraints = false;
 }
예제 #7
0
        protected override NSButton CreateView()
        {
            var button = new NSButton();

            button.Cell.ControlSize = NSControlSize.Regular;
            button.BezelStyle       = NSBezelStyle.Rounded;
            button.SetButtonType(NSButtonType.MomentaryPushIn);
            button.Font       = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Regular));
            button.Activated += HandleTouchUpInside;

            return(button);
        }
예제 #8
0
        protected override NSButton CreateView()
        {
            var button = NSButton.CreateRadioButton(VirtualView.Label?.CurrentValue, RadioAction);

            button.State = VirtualView.Selected
                                ? NSCellStateValue.On
                                : NSCellStateValue.Off;

            button.Font       = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Regular));
            button.Activated += HandleTouchUpInside;

            return(button);
        }
예제 #9
0
        public void ButtonShouldNotBeClipped()
        {
            ManualForm("All buttons should be fully visible without any clipping", form =>
            {
                form.Styles.Add <RadioButtonHandler>("small", c =>
                {
                    c.Control.Cell.ControlSize = NSControlSize.Small;
                    c.Control.Font             = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small));
                });
                form.Styles.Add <RadioButtonHandler>("mini", c =>
                {
                    c.Control.Cell.ControlSize = NSControlSize.Mini;
                    c.Control.Font             = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Mini));
                });

                return(new TableLayout
                {
                    Rows =
                    {
                        new Panel {
                            Height = 10, BackgroundColor = Colors.White
                        },
                        new TableLayout(new TableRow(null, new RadioButton{
                            Text = "Normal"
                        }, null)),
                        new Panel {
                            Height = 10, BackgroundColor = Colors.White
                        },
                        new TableLayout(new TableRow(null, new RadioButton{
                            Text = "Small", Style = "small"
                        }, null)),
                        new Panel {
                            Height = 10, BackgroundColor = Colors.White
                        },
                        new TableLayout(new TableRow(null, new RadioButton{
                            Text = "Mini", Style = "mini"
                        }, null)),
                        new Panel {
                            Height = 10, BackgroundColor = Colors.White
                        },
                    }
                });
            });
        }
예제 #10
0
        public NativeDragView()
        {
            WantsLayer            = true;
            Layer.BackgroundColor = NSColor.SystemBlueColor.CGColor;

            field = new NSTextField
            {
                StringValue     = "Click Me to Focus or Drag in Blue Rect",
                Alignment       = NSTextAlignment.Center,
                Font            = NSFont.UserFixedPitchFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Regular)),
                Bordered        = true,
                BezelStyle      = NSTextFieldBezelStyle.Square,
                DrawsBackground = true,
                BackgroundColor = NSColor.TextBackground,
                TextColor       = NSColor.ControlText,
                Editable        = false
            };

            AddSubview(field);

            field.TranslatesAutoresizingMaskIntoConstraints = false;
            field.LeadingAnchor.ConstraintEqualToAnchor(LeadingAnchor, Padding).Active    = true;
            field.TrailingAnchor.ConstraintEqualToAnchor(TrailingAnchor, -Padding).Active = true;
            field.CenterYAnchor.ConstraintEqualToAnchor(CenterYAnchor).Active             = true;

            NSEvent.AddLocalMonitorForEventsMatchingMask(
                NSEventMask.LeftMouseDragged | NSEventMask.LeftMouseUp,
                e =>
            {
                switch (e.Type)
                {
                case NSEventType.LeftMouseDragged when isDragging:
                    MouseDragged(e);
                    return(null);

                case NSEventType.LeftMouseUp:
                    isDragging = false;
                    break;
                }

                return(e);
            });
        }
예제 #11
0
        public EntryPropertyEditor(IHostResourceProvider hostResources)
            : base(hostResources)
        {
            Entry = new PropertyTextField {
                BackgroundColor = NSColor.Clear,
                ControlSize     = NSControlSize.Small,
                Font            = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                TranslatesAutoresizingMaskIntoConstraints = false,
            };
            AddSubview(Entry);

            RightEdgeConstraint = NSLayoutConstraint.Create(Entry, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1f, 0);
            AddConstraints(new[] {
                NSLayoutConstraint.Create(Entry, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0),
                NSLayoutConstraint.Create(Entry, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0),
                RightEdgeConstraint,
                NSLayoutConstraint.Create(Entry, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1, -6),
            });
        }
예제 #12
0
        public PredefinedValuesEditor(IHostResourceProvider hostResources)
            : base(hostResources)
        {
            base.TranslatesAutoresizingMaskIntoConstraints = false;

            this.comboBox = new FocusableComboBox {
                AllowsExpansionToolTips = true,
                BackgroundColor         = NSColor.Clear,
                Cell =
                {
                    LineBreakMode      = NSLineBreakMode.TruncatingTail,
                    UsesSingleLineMode = true,
                },
                ControlSize = NSControlSize.Small,
                Font        = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                TranslatesAutoresizingMaskIntoConstraints = false,
                StringValue = String.Empty,
            };

            this.comboBox.SelectionChanged += (sender, e) => {
                ViewModel.ValueName = this.comboBox.SelectedValue.ToString();
            };

            this.popUpButton = new FocusablePopUpButton {
                AllowsExpansionToolTips = true,
                Cell =
                {
                    LineBreakMode      = NSLineBreakMode.TruncatingTail,
                    UsesSingleLineMode = true,
                },
                ControlSize = NSControlSize.Small,
                Font        = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                TranslatesAutoresizingMaskIntoConstraints = false,
                StringValue = String.Empty,
            };

            popupButtonList       = new NSMenu();
            this.popUpButton.Menu = popupButtonList;

            this.popUpButton.Activated += (o, e) => {
                ViewModel.ValueName = (o as NSPopUpButton).Title;
            };
        }
예제 #13
0
 public override void DrawWithFrame(CGRect cellFrame, NSView inView)
 {
     if (NSGraphicsContext.IsCurrentContextDrawingToScreen)
     {
         base.DrawWithFrame(cellFrame, inView);
     }
     else
     {
         DrawTitle(AttributedTitle, TitleRectForBounds(cellFrame), inView);
         var state      = State;
         var text       = state == NSCellStateValue.On ? "⦿" : state == NSCellStateValue.Mixed ? "⊖" : "○";
         var font       = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(ControlSize));
         var attributes = NSDictionary.FromObjectAndKey(font, NSStringAttributeKey.Font);
         var str        = new NSAttributedString(text, attributes);
         var frame      = cellFrame;
         var size       = str.Size;
         var offset     = (nfloat)Math.Max(0, (frame.Height - size.Height) / 2);
         frame.Y      += offset;
         frame.Height -= offset;
         str.DrawString(frame);
     }
 }
        private void RequirePopup()
        {
            if (this.popupButton != null)
            {
                return;
            }

            RemoveComboBox();

            this.popupButton = new FocusablePopUpButton {
                AllowsExpansionToolTips = true,
                Cell =
                {
                    LineBreakMode      = NSLineBreakMode.TruncatingTail,
                    UsesSingleLineMode = true,
                },
                ControlSize = NSControlSize.Small,
                Font        = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                TranslatesAutoresizingMaskIntoConstraints = false,
                StringValue    = String.Empty,
                ProxyResponder = new ProxyResponder(this, ProxyRowType.SingleView)
            };
            this.popupButton.ProxyResponder = new ProxyResponder(this, ProxyRowType.SingleView);
            this.popupButtonList            = new NSMenu();
            this.popupButton.Menu           = this.popupButtonList;
            this.popupButton.Activated     += PopupButton_Activated;

            AddSubview(this.popupButton);

            AddConstraints(new[] {
                NSLayoutConstraint.Create(this.popupButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f),
                NSLayoutConstraint.Create(this.popupButton, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
                NSLayoutConstraint.Create(this.popupButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0),
            });

            this.firstKeyView = this.popupButton;
            this.lastKeyView  = this.popupButton;
        }
예제 #15
0
        public BrushEditorControl(IHostResourceProvider hostResources)
            : base(hostResources)
        {
            TranslatesAutoresizingMaskIntoConstraints = false;

            this.previewLayer = new CommonBrushLayer(hostResources)
            {
                Frame = new CGRect(0, 0, 30, 10)
            };

            this.popover = new AutoClosePopOver(hostResources, hostResources.GetVibrantAppearance(EffectiveAppearance))
            {
                ContentViewController = this.brushTabViewController = new BrushTabViewController(hostResources)
                {
                    PreferredContentSize = new CGSize(550, 363)
                }
            };

            this.popUpButton = new ColorPopUpButton {
                ControlSize = NSControlSize.Small,
                Font        = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                TranslatesAutoresizingMaskIntoConstraints = false,
                ProxyResponder = new ProxyResponder(this, ProxyRowType.SingleView)
            };

            this.popupButtonList  = new NSMenu();
            this.popUpButton.Menu = this.popupButtonList;

            AddSubview(this.popUpButton);

            this.AddConstraints(new[] {
                NSLayoutConstraint.Create(this.popUpButton, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0),
                NSLayoutConstraint.Create(this.popUpButton, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1f, 16),
                NSLayoutConstraint.Create(this.popUpButton, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0),
            });

            AppearanceChanged();
        }
        public DateTimeEditorControl(IHostResourceProvider hostResources)
            : base(hostResources)
        {
            this.datePicker = new NSDatePicker {
                ControlSize        = NSControlSize.Small,
                DatePickerElements = NSDatePickerElementFlags.HourMinuteSecond | NSDatePickerElementFlags.YearMonthDateDay,
                DatePickerStyle    = NSDatePickerStyle.TextFieldAndStepper,
                Font = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            // update the value on keypress
            this.datePicker.Activated += Editor_Activated;

            AddSubview(this.datePicker);

            AddConstraints(new[] {
                NSLayoutConstraint.Create(this.datePicker, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f),
                NSLayoutConstraint.Create(this.datePicker, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, this, NSLayoutAttribute.Leading, 1f, 0f),
                NSLayoutConstraint.Create(this.datePicker, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0),
                NSLayoutConstraint.Create(this.datePicker, NSLayoutAttribute.Height, NSLayoutRelation.Equal, this, NSLayoutAttribute.Height, 1f, -6f),
            });
        }
        private void RequireComboBox()
        {
            if (this.comboBox != null)
            {
                return;
            }

            RemovePopup();

            this.comboBox = new FocusableComboBox {
                AllowsExpansionToolTips = true,
                BackgroundColor         = NSColor.Clear,
                Cell =
                {
                    LineBreakMode      = NSLineBreakMode.TruncatingTail,
                    UsesSingleLineMode = true,
                },
                ProxyResponder = new ProxyResponder(this, ProxyRowType.SingleView),
                ControlSize    = NSControlSize.Small,
                Font           = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                TranslatesAutoresizingMaskIntoConstraints = false,
                StringValue = String.Empty,
            };
            this.comboBox.ProxyResponder    = new ProxyResponder(this, ProxyRowType.SingleView);
            this.comboBox.SelectionChanged += ComboBox_SelectionChanged;

            AddSubview(this.comboBox);

            AddConstraints(new[] {
                NSLayoutConstraint.Create(this.comboBox, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, this, NSLayoutAttribute.CenterY, 1f, 0f),
                NSLayoutConstraint.Create(this.comboBox, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1f, 0f),
                NSLayoutConstraint.Create(this.comboBox, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, 1f, 0),
            });

            this.firstKeyView = this.comboBox;
            this.lastKeyView  = this.comboBox;
        }
        public CollectionEditorControl(IHostResourceProvider hostResources)
        {
            if (hostResources == null)
            {
                throw new ArgumentNullException(nameof(hostResources));
            }

            this.hostResources = hostResources;

            this.collectionView = new NSTableView {
                HeaderView = null,
                RowHeight  = 24
            };

            this.collectionView.RegisterForDraggedTypes(new[] { "public.data" });
            this.collectionView.AddColumn(new NSTableColumn());

            var scroll = new NSScrollView {
                DocumentView          = this.collectionView,
                HasHorizontalScroller = false,
            };

            var header = new DynamicBox(hostResources, NamedResources.ControlBackground, NamedResources.FrameBoxBorderColor)
            {
                BoxType     = NSBoxType.NSBoxCustom,
                BorderWidth = 1,
                ContentView = new UnfocusableTextField {
                    StringValue = Properties.Resources.CollectionTargetsHeader
                },
                TranslatesAutoresizingMaskIntoConstraints = false,
                ContentViewMargins = new CGSize(8, 0),
            };

            AddSubview(header);

            var headerBorder = new DynamicBox(hostResources, borderName: NamedResources.ListHeaderSeparatorColor)
            {
                BoxType     = NSBoxType.NSBoxCustom,
                BorderWidth = 1,
                TranslatesAutoresizingMaskIntoConstraints = false,
                ContentViewMargins = new CGSize(0, 0)
            };

            AddSubview(headerBorder);

            var scrollBorder = new DynamicBox(hostResources, borderName: NamedResources.FrameBoxBorderColor)
            {
                BoxType     = NSBoxType.NSBoxCustom,
                BorderWidth = 1,
                ContentView = scroll,
                TranslatesAutoresizingMaskIntoConstraints = false,
                ContentViewMargins = new CGSize(0, 0)
            };

            AddSubview(scrollBorder);

            this.typeSelector = new NSComboBox {
                TranslatesAutoresizingMaskIntoConstraints = false,
                ControlSize        = NSControlSize.Mini,
                Font               = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Mini)),
                AccessibilityTitle = Properties.Resources.AccessibilityCollectionTypeSelector
            };
            this.typeSelector.SelectionChanged += OnSelectedTypeChanged;

            this.add = new NSButton {
                BezelStyle         = NSBezelStyle.SmallSquare,
                AccessibilityTitle = Properties.Resources.AccessibilityCollectionAddButton,
                Bordered           = false,
            };
            this.add.Activated += OnAddChild;

            var addBorder = new DynamicBox(hostResources, borderName: NamedResources.FrameBoxButtonBorderColor)
            {
                ContentView = this.add,
                TranslatesAutoresizingMaskIntoConstraints = false,
                BoxType            = NSBoxType.NSBoxCustom,
                BorderWidth        = 1,
                ContentViewMargins = new CGSize(0, 0)
            };

            this.remove = new NSButton {
                BezelStyle         = NSBezelStyle.SmallSquare,
                AccessibilityTitle = Properties.Resources.AccessibilityCollectionRemoveButton,
                Bordered           = false
            };
            this.remove.Activated += OnRemoveChild;

            var removeBorder = new DynamicBox(hostResources, borderName: NamedResources.FrameBoxButtonBorderColor)
            {
                ContentView = this.remove,
                TranslatesAutoresizingMaskIntoConstraints = false,
                BoxType            = NSBoxType.NSBoxCustom,
                BorderWidth        = 1,
                ContentViewMargins = new CGSize(0, 0)
            };

            var controlsBorder = new DynamicBox(hostResources, NamedResources.FrameBoxBackgroundColor, NamedResources.FrameBoxBorderColor)
            {
                BoxType     = NSBoxType.NSBoxCustom,
                BorderWidth = 1,
                TranslatesAutoresizingMaskIntoConstraints = false,
                ContentViewMargins = new CoreGraphics.CGSize(2.5, 0)
            };

            AddSubview(controlsBorder);

            controlsBorder.AddSubview(this.typeSelector);
            controlsBorder.AddSubview(addBorder);
            controlsBorder.AddSubview(removeBorder);

            this.propertyList = new PropertyList {
                HostResourceProvider = hostResources,
                ShowHeader           = false,
            };

            var listBorder = new DynamicBox(hostResources, borderName: NamedResources.FrameBoxBorderColor)
            {
                BoxType     = NSBoxType.NSBoxCustom,
                BorderWidth = 1,
                ContentView = propertyList,
                TranslatesAutoresizingMaskIntoConstraints = false,
                ContentViewMargins = new CoreGraphics.CGSize(0, 0)
            };

            AddSubview(listBorder);

            AddConstraints(new[] {
                NSLayoutConstraint.Create(header, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0),
                NSLayoutConstraint.Create(header, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 0),
                NSLayoutConstraint.Create(header, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, Mac.Layout.GoldenRatioLeft, 0),
                NSLayoutConstraint.Create(header, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, 21),

                NSLayoutConstraint.Create(headerBorder, NSLayoutAttribute.Top, NSLayoutRelation.Equal, header, NSLayoutAttribute.Bottom, 1, -1),
                NSLayoutConstraint.Create(headerBorder, NSLayoutAttribute.Width, NSLayoutRelation.Equal, header, NSLayoutAttribute.Width, 1, 0),
                NSLayoutConstraint.Create(headerBorder, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, 1),

                NSLayoutConstraint.Create(scrollBorder, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this, NSLayoutAttribute.Left, 1, 0),
                NSLayoutConstraint.Create(scrollBorder, NSLayoutAttribute.Top, NSLayoutRelation.Equal, header, NSLayoutAttribute.Bottom, 1, -1),
                NSLayoutConstraint.Create(scrollBorder, NSLayoutAttribute.Width, NSLayoutRelation.Equal, this, NSLayoutAttribute.Width, Mac.Layout.GoldenRatioLeft, 0),
                NSLayoutConstraint.Create(scrollBorder, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, controlsBorder, NSLayoutAttribute.Top, 1, 1),

                NSLayoutConstraint.Create(controlsBorder, NSLayoutAttribute.Width, NSLayoutRelation.Equal, scrollBorder, NSLayoutAttribute.Width, 1, 0),
                NSLayoutConstraint.Create(controlsBorder, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, 21),
                NSLayoutConstraint.Create(controlsBorder, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this, NSLayoutAttribute.Bottom, 1, 0),

                NSLayoutConstraint.Create(listBorder, NSLayoutAttribute.Left, NSLayoutRelation.Equal, scrollBorder, NSLayoutAttribute.Right, 1, 8),
                NSLayoutConstraint.Create(listBorder, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this, NSLayoutAttribute.Top, 1, 0),
                NSLayoutConstraint.Create(listBorder, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this, NSLayoutAttribute.Right, 1, 0),
                NSLayoutConstraint.Create(listBorder, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, controlsBorder, NSLayoutAttribute.Bottom, 1, 0),

                NSLayoutConstraint.Create(this.typeSelector, NSLayoutAttribute.Height, NSLayoutRelation.Equal, controlsBorder, NSLayoutAttribute.Height, 1, -7),
                NSLayoutConstraint.Create(this.typeSelector, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, controlsBorder, NSLayoutAttribute.CenterY, 1, 0),
                NSLayoutConstraint.Create(this.typeSelector, NSLayoutAttribute.Width, NSLayoutRelation.LessThanOrEqual, 1, 110),

                NSLayoutConstraint.Create(addBorder, NSLayoutAttribute.Height, NSLayoutRelation.Equal, controlsBorder, NSLayoutAttribute.Height, 1, 2),
                NSLayoutConstraint.Create(addBorder, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, 22),
                NSLayoutConstraint.Create(addBorder, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, controlsBorder, NSLayoutAttribute.CenterY, 1, 0),
                NSLayoutConstraint.Create(addBorder, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.typeSelector, NSLayoutAttribute.Right, 1, 1.5f),

                NSLayoutConstraint.Create(removeBorder, NSLayoutAttribute.Left, NSLayoutRelation.Equal, addBorder, NSLayoutAttribute.Right, 1, -1),
                NSLayoutConstraint.Create(removeBorder, NSLayoutAttribute.Height, NSLayoutRelation.Equal, controlsBorder, NSLayoutAttribute.Height, 1, 2),
                NSLayoutConstraint.Create(removeBorder, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, controlsBorder, NSLayoutAttribute.CenterY, 1, 0),
                NSLayoutConstraint.Create(removeBorder, NSLayoutAttribute.Width, NSLayoutRelation.Equal, 1, 22),
            });

            ViewDidChangeEffectiveAppearance();
        }
예제 #19
0
        private CGRect GetTitleFrame(out NSDictionary titleTextStyles, AppStoreWindow window)
        {
            var drawsAsMainWindow = window.DrawsAsMainWindow();
            var titleTextShadow   = drawsAsMainWindow ? window.TitleTextShadow : window.InactiveTitleTextShadow;

            if (titleTextShadow == null)
            {
                titleTextShadow = new NSShadow
                {
                    ShadowBlurRadius = 0f,
                    ShadowOffset     = new CGSize(0f, -1.0f),
                    ShadowColor      = NSColor.FromDeviceWhite(1.0f, 0.5f),
                };
            }

            var titleTextColor = drawsAsMainWindow ? window.TitleTextColor : window.InactiveTitleTextColor;

            if (titleTextColor == default(NSColor))
            {
                titleTextColor = AppStoreWindow.DefaultTitleTextColor(drawsAsMainWindow);
            }
            var titleFont = window.TitleFont ??
                            NSFont.TitleBarFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Regular));

            var titleParagraphStyle = (NSParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy();//new NSParagraphStyle { LineBreakMode = NSLineBreakMode.TruncatingTail };

            titleParagraphStyle.LineBreakMode = NSLineBreakMode.TruncatingTail;

            titleTextStyles = NSDictionary.FromObjectsAndKeys(
                new object[]
            {
                titleFont, titleTextColor,
                titleTextShadow, titleParagraphStyle
            },
                new object[]
            {
                NSStringAttributeKey.Font, NSStringAttributeKey.ForegroundColor,
                NSStringAttributeKey.Shadow, NSStringAttributeKey.ParagraphStyle
            });

            var titleSize     = new NSAttributedString(window.Title, titleTextStyles).Size;
            var titleTextRect = new CGRect(0, 0, titleSize.Width, titleSize.Height);

            var docIconButton  = window.StandardWindowButton(NSWindowButton.DocumentIconButton);
            var versionButton  = window.StandardWindowButton(NSWindowButton.DocumentVersionsButton);
            var closeButton    = window.ButtonToLayout(NSWindowButton.CloseButton);
            var minimizeButton = window.ButtonToLayout(NSWindowButton.MiniaturizeButton);
            var zoomButton     = window.ButtonToLayout(NSWindowButton.ZoomButton);

            if (docIconButton != null)
            {
                var docIconButtonFrame = ConvertRectFromView(docIconButton.Frame, docIconButton.Superview);
                titleTextRect.X = docIconButtonFrame.GetMaxX() + TITLE_DOCUMENT_BUTTON_OFFSET.Width;
                titleTextRect.Y = docIconButtonFrame.GetMidY() - titleSize.Height / 2f +
                                  TITLE_DOCUMENT_BUTTON_OFFSET.Height;
            }
            else if (versionButton != null)
            {
                var versionsButtonFrame = ConvertRectFromView(versionButton.Frame, versionButton.Superview);
                titleTextRect.X = versionsButtonFrame.GetMinX() - titleSize.Width + TITLE_VERSIONS_BUTTON_OFFSET;

                var document = ((NSWindowController)window.WindowController).Document;
                if (document.HasUnautosavedChanges || document.IsDocumentEdited)
                {
                    titleTextRect.X += TITLE_DOCUMENT_STATUS_X_OFFSET;
                }
            }
            else if (closeButton != null || minimizeButton != null || zoomButton != null)
            {
                var closeMaxX    = closeButton == null ? 0f : closeButton.Frame.GetMaxX();
                var minimizeMaxX = minimizeButton == null ? 0f : minimizeButton.Frame.GetMaxX();
                var zoomMaxX     = zoomButton == null ? 0f : zoomButton.Frame.GetMaxX();

                var adjustedX = NMath.Max(NMath.Max(closeMaxX, minimizeMaxX), zoomMaxX) + TITLE_MARGINS.Width;
                var proposedX = Bounds.GetMidX() - titleSize.Width / 2f;
                titleTextRect.X = NMath.Max(proposedX, adjustedX);
            }
            else
            {
                titleTextRect.X = Bounds.GetMidX() - titleSize.Width / 2f;
            }

            var fullScreenButton = window.ButtonToLayout(NSWindowButton.FullScreenButton);

            if (fullScreenButton != null)
            {
                var fullScreenX = fullScreenButton.Frame.X;
                var maxTitleX   = titleTextRect.GetMaxX();
                if ((fullScreenX - TITLE_MARGINS.Width) < titleTextRect.GetMaxX())
                {
                    titleTextRect.Width = titleTextRect.Size.Width - (maxTitleX - fullScreenX) - TITLE_MARGINS.Width;
                }
            }

            titleTextRect.Y = Bounds.GetMaxY() - titleSize.Height - TITLE_MARGINS.Height;

            return(titleTextRect);
        }
예제 #20
0
        private void Initialize(PropertyViewModel propertyViewModel)
        {
            this.ShowPreview = true;
            TranslatesAutoresizingMaskIntoConstraints = false;

            var FrameWidthThird = Frame.Width / 3;
            var FrameWidthHalf  = Frame.Width / 2;
            var FrameHeightHalf = Frame.Height / 2;

            NSControlSize controlSize = NSControlSize.Small;

            this.searchResources = new NSSearchField {
                ControlSize       = controlSize,
                Font              = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small)),
                PlaceholderString = Properties.Resources.SearchResourcesTitle,
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            this.searchResources.Changed += OnSearchResourcesChanged;

            AddSubview(this.searchResources);

            var vmType            = propertyViewModel.GetType();
            var valuePropertyInfo = vmType.GetProperty("Value");
            var resourceValue     = valuePropertyInfo.GetValue(propertyViewModel);

            this.resourceSelectorPanel = new RequestResourcePanel(HostResources, new ResourceSelectorViewModel(propertyViewModel.TargetPlatform.ResourceProvider, propertyViewModel.Editors.Select(ed => ed.Target), propertyViewModel.Property), resourceValue);
            this.resourceSelectorPanel.ResourceSelected += (sender, e) => {
                propertyViewModel.Resource = this.resourceSelectorPanel.SelectedResource;
            };
            this.resourceSelectorPanel.DoubleClicked += (sender, e) => {
                PopOver.Close();
            };

            AddSubview(this.resourceSelectorPanel);

            segmentedControl = NSSegmentedControl.FromLabels(new string[] { Properties.Resources.AllResources, Properties.Resources.Local, Properties.Resources.Shared }, NSSegmentSwitchTracking.SelectOne, () => {
                //Switch Resource Types
                switch (this.segmentedControl.SelectedSegment)
                {
                case 0:
                    this.resourceSelectorPanel.ViewModel.ShowBothResourceTypes = true;
                    this.segmentedControl.SetImage(HostResources.GetNamedImage("pe-resource-editor-16"), 2);
                    break;

                case 1:
                    this.resourceSelectorPanel.ViewModel.ShowOnlyLocalResources = true;
                    this.segmentedControl.SetImage(HostResources.GetNamedImage("pe-resource-editor-16"), 2);
                    break;

                case 2:
                    this.resourceSelectorPanel.ViewModel.ShowOnlySystemResources = true;
                    this.segmentedControl.SetImage(HostResources.GetNamedImage("pe-resource-editor-16~sel"), 2);
                    break;
                }

                this.resourceSelectorPanel.ReloadData();
            });
            this.segmentedControl.SetImage(HostResources.GetNamedImage("pe-resource-editor-16"), 2);
            this.segmentedControl.Frame = new CGRect((FrameWidthThird - (segmentedControl.Bounds.Width) / 2), 5, (Frame.Width - (FrameWidthThird)) - 10, 24);
            this.segmentedControl.Font  = NSFont.SystemFontOfSize(NSFont.SystemFontSizeForControlSize(NSControlSize.Small));
            this.segmentedControl.TranslatesAutoresizingMaskIntoConstraints = false;
            this.segmentedControl.SetSelected(true, 0);
            this.resourceSelectorPanel.ViewModel.ShowBothResourceTypes = true;

            AddSubview(this.segmentedControl);

            this.showPreviewImage = new NSButton {
                Bordered    = false,
                ControlSize = controlSize,
                Image       = NSImage.ImageNamed(NSImageName.QuickLookTemplate),
                Title       = string.Empty,
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            this.showPreviewImage.Activated += (o, e) => {
                ShowPreview = !ShowPreview;
                RepositionControls();
            };

            AddSubview(this.showPreviewImage);

            OnSearchResourcesChanged(null, null);

            RepositionControls();
        }