コード例 #1
0
        protected override void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);

            // usual selection business
            ViewModelDesignerCanvas designer = VisualTreeHelper.GetParent(this) as ViewModelDesignerCanvas;

            if (designer != null)
            {
                if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None)
                {
                    if (this.IsSelected)
                    {
                        designer.SelectionService.RemoveFromSelection(this);
                    }
                    else
                    {
                        designer.SelectionService.AddToSelection(this);
                    }
                }
                else if (!this.IsSelected)
                {
                    // designer.SelectionService.SelectItem(this);
                }

                Focus();
            }
            e.Handled = false;
        }
コード例 #2
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            // if mouse button is not pressed we have no drag operation, ...
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                this.dragStartPoint = null;
            }

            // but if mouse button is pressed and start point value is set we do have one
            if (this.dragStartPoint.HasValue)
            {
                // create connection adorner
                ViewModelDesignerCanvas canvas = GetDesignerCanvas(this);
                if (canvas != null)
                {
                    AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(canvas);
                    if (adornerLayer != null)
                    {
                        ViewModelConnectorAdorner adorner = new ViewModelConnectorAdorner(canvas, this);
                        if (adorner != null)
                        {
                            adornerLayer.Add(adorner);
                            e.Handled = true;
                        }
                    }
                }
            }
        }
コード例 #3
0
 public ViewModelRubberbandAdorner(ViewModelDesignerCanvas designerCanvas, Point?dragStartPoint)
     : base(designerCanvas)
 {
     this.designerCanvas     = designerCanvas;
     this.startPoint         = dragStartPoint;
     rubberbandPen           = new Pen(Brushes.LightSlateGray, 1);
     rubberbandPen.DashStyle = new DashStyle(new double[] { 2 }, 1);
 }
コード例 #4
0
 public ViewModelConnectorAdorner(ViewModelDesignerCanvas designer, ViewModelConnector sourceConnector)
     : base(designer)
 {
     this.designerCanvas  = designer;
     this.sourceConnector = sourceConnector;
     drawingPen           = new Pen(Brushes.LightSlateGray, 2);
     drawingPen.LineJoin  = PenLineJoin.Miter;
     this.Cursor          = Cursors.Cross;
 }
コード例 #5
0
        // when the layout changes we update the position property
        void Connector_LayoutUpdated(object sender, EventArgs e)
        {
            ViewModelDesignerCanvas designer = GetDesignerCanvas(this);

            if (designer != null)
            {
                //get centre position of this Connector relative to the DesignerCanvas
                this.Position = this.TransformToAncestor(designer).Transform(new Point(this.Width / 2, this.Height / 2));
            }
        }
コード例 #6
0
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            ViewModelDesignerCanvas canvas = GetDesignerCanvas(this);

            if (canvas != null)
            {
                // position relative to DesignerCanvas
                this.dragStartPoint = new Point?(e.GetPosition(canvas));
                e.Handled           = true;
            }
        }
コード例 #7
0
        internal ModelConnectorInfo GetInfo()
        {
            ModelConnectorInfo info = new ModelConnectorInfo();

            info.DesignerItemLeft = ViewModelDesignerCanvas.GetLeft(this.ParentDesignerItem);
            info.DesignerItemTop  = ViewModelDesignerCanvas.GetTop(this.ParentDesignerItem);
            info.DesignerItemSize = new Size(this.ParentDesignerItem.ActualWidth, this.ParentDesignerItem.ActualHeight);
            info.Orientation      = this.Orientation;
            info.Position         = this.Position;
            info.ToolTip          = this.ToolTip.ToString();
            return(info);
        }
コード例 #8
0
        private void ShowAdorner()
        {
            // the ConnectionAdorner is created once for each Connection
            if (this.connectionAdorner == null)
            {
                ViewModelDesignerCanvas designer = VisualTreeHelper.GetParent(this) as ViewModelDesignerCanvas;

                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
                if (adornerLayer != null)
                {
                    this.connectionAdorner = new ViewModelConnectionAdorner(designer, this);
                    adornerLayer.Add(this.connectionAdorner);
                }
            }
            this.connectionAdorner.Visibility = Visibility.Visible;
        }
コード例 #9
0
        void Connection_Unloaded(object sender, RoutedEventArgs e)
        {
            this.Source = null;
            this.Sink   = null;

            // remove adorner
            if (this.connectionAdorner != null)
            {
                ViewModelDesignerCanvas designer = VisualTreeHelper.GetParent(this) as ViewModelDesignerCanvas;

                AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this);
                if (adornerLayer != null)
                {
                    adornerLayer.Remove(this.connectionAdorner);
                    this.connectionAdorner = null;
                }
            }
        }
コード例 #10
0
        public ViewModelConnectionAdorner(ViewModelDesignerCanvas designer, ViewModelConnection connection)
            : base(designer)
        {
            this.designerCanvas = designer;
            adornerCanvas       = new Canvas();
            this.visualChildren = new VisualCollection(this);
            this.visualChildren.Add(adornerCanvas);

            this.connection = connection;
            this.connection.PropertyChanged += new PropertyChangedEventHandler(AnchorPositionChanged);

            InitializeDragThumbs();

            drawingPen          = new Pen(Brushes.LightSlateGray, 1);
            drawingPen.LineJoin = PenLineJoin.Round;

            base.Unloaded += new RoutedEventHandler(ConnectionAdorner_Unloaded);
        }
コード例 #11
0
 public ViewModelSelectionService(ViewModelDesignerCanvas canvas)
 {
     this.designerCanvas = canvas;
 }
コード例 #12
0
        protected override void OnDrop(DragEventArgs e)
        {
            Type t = e.GetType();

            base.OnDrop(e);
            ModelDragObject        dragObject    = e.Data.GetData(typeof(ModelDragObject)) as ModelDragObject;
            ModelCanvasStateObject state         = new ModelCanvasStateObject();
            PropertyGrid           SelectedPgrid = new PropertyGrid();

            if (dragObject != null && !String.IsNullOrEmpty(dragObject.Xaml))
            {
                ViewModelDesignerItem newItem = null;
                Object content = XamlReader.Load(XmlReader.Create(new StringReader(dragObject.Xaml)));
                if (content != null)
                {
                    newItem = new ViewModelDesignerItem();
                    DockPanel pnl = (DockPanel)content;

                    string StateBrandName = pnl.ToolTip.ToString();
                    if (StateBrandName != "P" && StateBrandName != "GENERIC")
                    {
                        string StateBrandId = ConfigurationManager.AppSettings[StateBrandName];
                        if (CurrentBrandId != StateBrandId)
                        {
                            return;
                        }
                    }


                    state.Id = avaliableStateNumberList[0].ToString();
                    avaliableStateNumberList.Remove(state.Id);
                    // GetStateType(pnl.Tag.ToString());
                    state.Type      = pnl.Tag.ToString();
                    pnl.Name        = state.Type + state.Id.ToString();
                    pnl.Uid         = state.Id;
                    state.dockPanel = pnl;
                    content         = pnl;

                    Type   ClassType     = Type.GetType("ATMDesigner.UI.States.State" + pnl.Tag.ToString());
                    Object ClassInstance = Activator.CreateInstance(ClassType, this);

                    PropertyInfo StateNo = ClassType.GetProperty("StateNumber");
                    StateNo.SetValue(ClassInstance, state.Id, null);
                    PropertyInfo BrandId = ClassType.GetProperty("BrandId");
                    BrandId.SetValue(ClassInstance, CurrentBrandId, null);
                    PropertyInfo ConfigId = ClassType.GetProperty("ConfigId");
                    ConfigId.SetValue(ClassInstance, CurrentConfigId, null);

                    SelectedPgrid.SelectedObject     = ClassInstance;
                    SelectedPgrid.SelectedObjectName = state.Id;

                    state.PropertyGrid    = SelectedPgrid;
                    state.TransactionName = CurrentTransactionName;
                    state.BrandId         = CurrentBrandId;
                    state.ConfigId        = CurrentConfigId;
                    newItem.Content       = content;
                    Point position = e.GetPosition(this);

                    if (dragObject.DesiredSize.HasValue)
                    {
                        Size desiredSize = dragObject.DesiredSize.Value;
                        newItem.Width  = desiredSize.Width;
                        newItem.Height = desiredSize.Height;

                        ViewModelDesignerCanvas.SetLeft(newItem, Math.Max(0, position.X - newItem.Width / 2));
                        ViewModelDesignerCanvas.SetTop(newItem, Math.Max(0, position.Y - newItem.Height / 2));
                    }
                    else
                    {
                        ViewModelDesignerCanvas.SetLeft(newItem, Math.Max(0, position.X));
                        ViewModelDesignerCanvas.SetTop(newItem, Math.Max(0, position.Y));
                    }
                    newItem.StateName   = state.Type;
                    newItem.StateNumber = state.Id;
                    TransactionList.Add(state);
                    Canvas.SetZIndex(newItem, this.Children.Count);
                    this.Children.Add(newItem);
                    SetConnectorDecoratorTemplate(newItem);
                    this.SelectionService.SelectItem(newItem);
                    newItem.Focus();
                }

                e.Handled = true;
            }
        }