Esempio n. 1
0
        private void Initialize()
        {
            WantsLayer = true;
            DoubleClick += (sender, e) => { };
            MenuItemClicked += (menuItemType) => { };

            // Add tracking area to receive mouse move and mouse dragged events
            var opts = NSTrackingAreaOptions.ActiveAlways | NSTrackingAreaOptions.InVisibleRect | NSTrackingAreaOptions.MouseMoved | NSTrackingAreaOptions.MouseEnteredAndExited | NSTrackingAreaOptions.EnabledDuringMouseDrag;
            var trackingArea = new NSTrackingArea(Bounds, opts, this, new NSDictionary());
            AddTrackingArea(trackingArea);

            _horizontalScrollBar = new HorizontalScrollBarWrapper();
            AddSubview(_horizontalScrollBar);

            _verticalScrollBar = new VerticalScrollBarWrapper();
            AddSubview(_verticalScrollBar);

            var disposableImageFactory = Bootstrapper.GetContainer().Resolve<IDisposableImageFactory>();
            _control = new SongGridViewControl(_horizontalScrollBar, _verticalScrollBar, disposableImageFactory);   
            _control.OnChangeMouseCursorType += GenericControlHelper.ChangeMouseCursor;
            _control.OnItemDoubleClick += (id, index) => DoubleClick(this, new EventArgs());
            _control.OnInvalidateVisual += () => InvokeOnMainThread(() => SetNeedsDisplayInRect(Bounds));
            _control.OnInvalidateVisualInRect += (rect) => InvokeOnMainThread(() => SetNeedsDisplayInRect(GenericControlHelper.ToRect(rect)));
            _control.OnDisplayContextMenu += (contextMenuType, x, y) => 
            { 
                switch (contextMenuType)
                {
                    case SongGridViewControl.ContextMenuType.Item:
                        NSMenu.PopUpContextMenu(_menuItems, _rightClickEvent, this);
                        break;
                    case SongGridViewControl.ContextMenuType.Header:
                        NSMenu.PopUpContextMenu(_menuHeader, _rightClickEvent, this);
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            };

            SetFrame();
            PostsBoundsChangedNotifications = true;
            NSNotificationCenter.DefaultCenter.AddObserver(NSView.FrameChangedNotification, FrameDidChangeNotification, this);

            CreateContextualMenu();
        }
Esempio n. 2
0
        public SongGridView()
            : base()
        {
            DoubleClick += (sender, e) => { };
            MenuItemClicked += type => { };
            Focusable = true;

            // Add dummy control so the scrollbar can be placed on the right
            var dummy = new Control();
            DockPanel.SetDock(dummy, Dock.Left);
            Children.Add(dummy);

            // Create wrappers for scrollbars so the generic control can interact with them
            _verticalScrollBar = new VerticalScrollBarWrapper();
            _verticalScrollBar.Width = 16;
            _verticalScrollBar.Height = Double.NaN;
            _verticalScrollBar.Minimum = 1;
            _verticalScrollBar.Maximum = 100;
            _verticalScrollBar.Margin = new Thickness(0, 20, 0, 20);
            DockPanel.SetDock(_verticalScrollBar, Dock.Right);
            Children.Add(_verticalScrollBar);

            _horizontalScrollBar = new HorizontalScrollBarWrapper();
            _horizontalScrollBar.Width = Double.NaN;
            _horizontalScrollBar.Height = 16;
            _horizontalScrollBar.Minimum = 1;
            _horizontalScrollBar.Maximum = 100;
            _horizontalScrollBar.VerticalAlignment = VerticalAlignment.Bottom;                
            DockPanel.SetDock(_horizontalScrollBar, Dock.Bottom);
            Children.Add(_horizontalScrollBar);

            var disposableImageFactory = Bootstrapper.GetContainer().Resolve<IDisposableImageFactory>();
            _control = new SongGridViewControl(_horizontalScrollBar, _verticalScrollBar, disposableImageFactory);
            _control.OnChangeMouseCursorType += GenericControlHelper.ChangeMouseCursor;
            _control.OnItemDoubleClick += (id, index) => DoubleClick(this, new EventArgs());
            _control.OnDisplayContextMenu += (type, x, y) => 
            {            
                // Create contextual menu
                //_menuColumns = new System.Windows.Forms.ContextMenuStrip();

                //// Loop through columns
                //foreach (SongGridViewColumn column in _columns)
                //{
                //    // Add menu item                               
                //    ToolStripMenuItem menuItem = (ToolStripMenuItem)_menuColumns.Items.Add(column.Title);
                //    menuItem.Tag = column.Title;
                //    menuItem.Checked = column.Visible;
                //    menuItem.Click += new EventHandler(menuItemColumns_Click);
                //}

                switch (type)
                {
                    case SongGridViewControl.ContextMenuType.Item:
                        _contextMenuItems.Placement = PlacementMode.MousePoint;
                        _contextMenuItems.PlacementTarget = this;
                        _contextMenuItems.Visibility = Visibility.Visible;
                        _contextMenuItems.IsOpen = true;
                        break;
                    case SongGridViewControl.ContextMenuType.Header:
                        _contextMenuHeader.Placement = PlacementMode.MousePoint;
                        _contextMenuHeader.PlacementTarget = this;
                        _contextMenuHeader.Visibility = Visibility.Visible;
                        _contextMenuHeader.IsOpen = true;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException("type");
                }
            };
            _control.OnInvalidateVisual += () => Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
            {
                //Console.WriteLine("SongGridView - OnInvalidateVisual");
                InvalidateVisual();
            }));
            _control.OnInvalidateVisualInRect += (rect) => Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
            {
                //Console.WriteLine("SongGridView - OnInvalidateVisualInRect");
                InvalidateVisual();
                // TODO: It seems you can't invalidate a specific rect in WPF? What?
                // http://stackoverflow.com/questions/2576599/possible-to-invalidatevisual-on-a-given-region-instead-of-entire-wpf-control                                                                                                                       
            }));

            // Create context menu at the end to add columns from control
            CreateContextualMenu();
        }