Exemplo n.º 1
0
        /// <summary>
        /// Places the handle from a calculated offset using Mouse Positon
        /// </summary>
        /// <param name="text"></param>
        /// <param name="e"></param>
        void PlaceEditor(Visual text, MouseEventArgs e)
        {
            textBlock = text as TextBlock;
            Debug.Assert(textBlock != null);

            /* Gets the offset between the top-left corners of the element and the editor*/
            placement.XOffset = e.GetPosition(element).X - e.GetPosition(textBlock).X - 2.8;
            placement.YOffset = e.GetPosition(element).Y - e.GetPosition(textBlock).Y - 1;
            placement.XRelativeToAdornerWidth  = 0;
            placement.XRelativeToContentWidth  = 0;
            placement.YRelativeToAdornerHeight = 0;
            placement.YRelativeToContentHeight = 0;
            editor.SetBinding(textBlock);

            /* Change data context of the editor to the TextBlock */
            editor.DataContext = textBlock;

            /* Set MaxHeight and MaxWidth so that editor doesn't cross the boundaries of the control */
            var height = ModelTools.GetHeight(element);
            var width  = ModelTools.GetWidth(element);

            editor.MaxHeight = Math.Max((height - placement.YOffset), 0);
            editor.MaxWidth  = Math.Max((width - placement.XOffset), 0);

            /* Hides the TextBlock in control because of some minor offset in placement, overlaping makes text look fuzzy */
            textBlock.Visibility = Visibility.Hidden;             //
            AdornerPanel.SetPlacement(editor, placement);

            RemoveBorder();             // Remove the highlight border.
        }
Exemplo n.º 2
0
        private void drawRaster()
        {
            if (!rasterDrawn)
            {
                rasterDrawn = true;

                var w    = ModelTools.GetWidth(ExtendedItem.View);
                var h    = ModelTools.GetHeight(ExtendedItem.View);
                var dash = new DoubleCollection()
                {
                    1, raster - 1
                };
                for (int i = 0; i <= h; i += raster)
                {
                    var line = new Line()
                    {
                        X1 = 0,
                        Y1 = i,
                        X2 = w,
                        Y2 = i,
                        StrokeThickness = 1,
                        Stroke          = Brushes.Black,
                        StrokeDashArray = dash,
                    };
                    surface.Children.Add(line);
                }
            }
        }
        void BuildMaps(PlacementOperation operation)
        {
            horizontalMap = new List <Snapline>();
            verticalMap   = new List <Snapline>();

            var containerRect = new Rect(0, 0, ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));

            AddLines(containerRect, -Margin, false);

            AddLines(containerRect, 0, false);

            if (!CanPlace(operation.PlacedItems.Select(x => x.Item), operation.Type, PlacementAlignment.Center))
            {
                return;
            }

            foreach (var item in AllDesignItems()             /* ExtendedItem.ContentProperty.CollectionElements */
                     .Except(operation.PlacedItems.Select(f => f.Item))
                     .Where(x => x.View != null && !GetDisableSnaplines(x.View)))
            {
                if (item != null)
                {
                    var bounds = GetPosition(operation, item);

                    AddLines(bounds, 0, false);
                    AddLines(bounds, Margin, true);
                    AddBaseline(item, bounds, horizontalMap);
                }
            }
        }
        // TODO : Remove all hide/show extensions from here.
        void drag_Started(DragListener drag)
        {
            /* Abort editing Text if it was editing, because it interferes with the undo stack. */
            foreach (var extension in this.ExtendedItem.Extensions)
            {
                if (extension is InPlaceEditorExtension)
                {
                    ((InPlaceEditorExtension)extension).AbortEdit();
                }
            }

            drag.Transform = this.ExtendedItem.GetCompleteAppliedTransformationToView();

            oldSize = new Size(ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));
            if (resizeBehavior != null)
            {
                operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
            }
            else
            {
                changeGroup = this.ExtendedItem.Context.OpenGroup("Resize", extendedItemArray);
            }
            _isResizing = true;
            ShowSizeAndHideHandles();
        }
Exemplo n.º 5
0
        // TODO : Remove all hide/show extensions from here.
        void drag_Started(DragListener drag)
        {
            var designPanel = ExtendedItem.Services.DesignPanel as DesignPanel;

            if (designPanel != null)
            {
                var p = VisualTreeHelper.GetParent(designPanel);
                while (p != null && !(p is ZoomControl))
                {
                    p = VisualTreeHelper.GetParent(p);
                }
                zoom = p as ZoomControl;
            }

            /* Abort editing Text if it was editing, because it interferes with the undo stack. */
            foreach (var extension in this.ExtendedItem.Extensions)
            {
                if (extension is InPlaceEditorExtension)
                {
                    ((InPlaceEditorExtension)extension).AbortEdit();
                }
            }

            oldSize = new Size(ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));
            if (resizeBehavior != null)
            {
                operation = PlacementOperation.Start(extendedItemArray, PlacementType.Resize);
            }
            else
            {
                changeGroup = this.ExtendedItem.Context.OpenGroup("Resize", extendedItemArray);
            }
            _isResizing = true;
            ShowSizeAndHideHandles();
        }
Exemplo n.º 6
0
 /// <summary>
 /// Checks whether heigth/width have changed and updates the position of editor
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (textBlock != null)
     {
         if (e.PropertyName == "Width")
         {
             placement.XOffset = Mouse.GetPosition((IInputElement)element).X - Mouse.GetPosition(textBlock).X - 2.8;
             editor.MaxWidth   = Math.Max((ModelTools.GetWidth(element) - placement.XOffset), 0);
         }
         if (e.PropertyName == "Height")
         {
             placement.YOffset = Mouse.GetPosition((IInputElement)element).Y - Mouse.GetPosition(textBlock).Y - 1;
             editor.MaxHeight  = Math.Max((ModelTools.GetHeight(element) - placement.YOffset), 0);
         }
         AdornerPanel.SetPlacement(editor, placement);
     }
 }
Exemplo n.º 7
0
        void BuildMaps(PlacementOperation operation)
        {
            horizontalMap = new List <Snapline>();
            verticalMap   = new List <Snapline>();

            var containerRect = new Rect(0, 0, ModelTools.GetWidth(ExtendedItem.View), ModelTools.GetHeight(ExtendedItem.View));

            AddLines(containerRect, -Margin, false);

            foreach (var item in ExtendedItem.ContentProperty.CollectionElements
                     .Except(operation.PlacedItems.Select(f => f.Item)))
            {
                var bounds = GetPosition(operation, item);

                AddLines(bounds, 0, false);
                AddLines(bounds, Margin, true);
                AddBaseline(item, bounds, horizontalMap);
            }
        }