internal void AddAdorner(
            AdornerLayer treeViewAdornerLayer, FrameworkElement adornedElement, ExplorerEFElement explorerElement,
            ExplorerFrame explorerFrame)
        {
            var adornerY = GetAdornerY(adornedElement, explorerElement, explorerFrame);

            if (adornerY >= 0)
            {
                SearchTickAdorner adorner;
                if (!_adorners.TryGetValue(adornerY, out adorner))
                {
                    adorner = new SearchTickAdorner(adornerY, adornedElement);
                    _adorners[adornerY] = adorner;
                    treeViewAdornerLayer.Add(adorner);

                    // adding adorners in batches of 100 - see bug: Windows OS Bugs 1750717 
                    if ((_adorners.Count % 100) == 0)
                    {
                        treeViewAdornerLayer.UpdateLayout();
                    }
                }

                adorner.AddExplorerElement(explorerElement);
            }
        }
예제 #2
0
        protected AdornerBase(UIElement adornedElement, UIElement core) : base(adornedElement)
        {
            Core = core;

            Layer = AdornerLayer.GetAdornerLayer(adornedElement);
            Layer?.Add(this);
        }
        /// <summary>
        /// 拖拽工具插头
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Plugitem_PreviewMouseMove(object sender,MouseEventArgs e) {
            if(e.LeftButton == MouseButtonState.Pressed) {
                try {
                    AbstractCableKit drogKit = Kits_ListBox.SelectedItem as AbstractCableKit;
                    AbstractCableKit kit = (AbstractCableKit)drogKit.Clone();
                    Grid grid = sender as Grid;
                    var dragData = new DataObject(typeof(AbstractCableKit), kit);

                    Point pos = e.GetPosition(Kits_ListBox);
                    HitTestResult result = VisualTreeHelper.HitTest(Kits_ListBox, pos);
                    if (result == null)
                        return;
                    ListBoxItem listBoxItem = EquipmentUtils.FindVisualParent<ListBoxItem>(result.VisualHit); // Find your actual visual you want to drag
                    DragDropAdorner adorner = new DragDropAdorner(listBoxItem);
                    adornerLayer = AdornerLayer.GetAdornerLayer(this);
                    adornerLayer.Add(adorner);

                    DragDrop.DoDragDrop(grid, dragData, DragDropEffects.Copy);
                    adornerLayer.Remove(adorner);
                    adornerLayer = null;
                }
                catch
                {

                }
            }
        }
예제 #4
0
 protected AdornerBase([CanBeNull] UIElement adornedElement)
     : base(adornedElement)
 {
     AdornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);
     Root         = new Grid();
     AdornerLayer?.Add(this);
 }
예제 #5
0
        public PasswordBoxHintAdorner(UIElement adornedElement, string hintText, Style hintStyle, VisibilityDelegate visibilityCallback)
            : base(adornedElement)
        {
            _visibilityCallback = visibilityCallback;

            _label = new Label()
            {
                Content = hintText,
                Style   = hintStyle,
            };

            IsHitTestVisible = true;
            Visibility       = Visibility.Visible;

            adornedElement.GotFocus         += Invalidate;
            adornedElement.LostFocus        += Invalidate;
            adornedElement.IsVisibleChanged += Invalidate;

            _visualCollection = new VisualCollection(this);
            _contentPresenter = new ContentPresenter();
            _visualCollection.Add(_contentPresenter);
            _contentPresenter.Content = _label;

            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);

            adornerLayer?.Add(this);

            IsHitTestVisible = false;
        }
예제 #6
0
        /// <summary>
        ///     Show the watermark on the specified control
        /// </summary>
        /// <param name="control">Control to show the watermark on</param>
        private static void ShowWatermark(Control control)
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(control);

            // layer could be null if control is no longer in the visual tree
            layer?.Add(new WatermarkAdorner(control, GetWatermark(control)));
        }
예제 #7
0
        // Handler for element selection on the canvas providing resizing adorner
        void myCanvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Remove selection on clicking anywhere the window
            if (selected)
            {
                selected = false;
                if (selectedElement != null)
                {
                    // Remove the adorner from the selected element
                    aLayer.Remove(aLayer.GetAdorners(selectedElement)[0]);
                    selectedElement = null;
                }
            }

            // If any element except canvas is clicked,
            // assign the selected element and add the adorner
            if (e.Source != myCanvas)
            {
                _isDown = true;
                _startPoint = e.GetPosition(myCanvas);

                selectedElement = e.Source as UIElement;

                _originalLeft = Canvas.GetLeft(selectedElement);
                _originalTop = Canvas.GetTop(selectedElement);

                aLayer = AdornerLayer.GetAdornerLayer(selectedElement);
                aLayer.Add(new ResizingAdorner(selectedElement));
                selected = true;
                e.Handled = true;
            }
        }
예제 #8
0
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            adornerLayer = AdornerLayer.GetAdornerLayer(elementsGrid);

            foreach (Panel toAdorn in elementsGrid.Children)
                adornerLayer.Add(new ResizingAdorner(toAdorn.Children[0]));
        }
예제 #9
0
        public static void TryAddAdorner <T>(this UIElement element, Adorner adorner)
            where T : Adorner
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(element);

            try { layer?.Add(adorner); }
            catch { }
        }
예제 #10
0
        public DragAdorner(object data, DataTemplate dataTemplate, UIElement adornedElement, AdornerLayer adornerLayer)
            : base(adornedElement)
        {
            _adornerLayer = adornerLayer;
            _contentPresenter = new ContentPresenter() { Content = data, ContentTemplate = dataTemplate, Opacity = 0.75 };

            _adornerLayer.Add(this);
        }
예제 #11
0
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            myAdornerLayer = AdornerLayer.GetAdornerLayer(win);
            myAdornerLayer.Add(new SimpleCircleAdorner(win));

            //myAdornerLayer = AdornerLayer.GetAdornerLayer(pnl);
            //foreach (UIElement toAdorn in pnl.Children)
            //    myAdornerLayer.Add(new SimpleCircleAdorner(toAdorn));
        }
예제 #12
0
        public PostionAdorner(UIElement adornedElement, AdornerLayer adornerLayer, DataTemplate dataTemplate)
            : base(adornedElement)
        {
            _adornerLayer = adornerLayer;
            _contentPresenter = new ContentPresenter();
            _contentPresenter.ContentTemplate = dataTemplate;

            //加入层中
            _adornerLayer.Add(this);
        }
예제 #13
0
 public HighLight_Adorner(UIElement adornedElement,
     Point startPosition, Size size,double opacity,
     AdornerLayer adornerLayer)
     : base(adornedElement)
 {
     this.opacity = opacity;
     this.size = size;
     this.adornerLayer = adornerLayer;
     adornerLayer.Add(this);
     this.position = startPosition;
 }
        private void Window_Loaded(object sender, RoutedEventArgs e) {
            aLayer = AdornerLayer.GetAdornerLayer(textBox1);
            aLayer.Add(new ScaleAdorner(textBox1));
            //this.MouseLeftButtonDown += new MouseButtonEventHandler(Window1_MouseLeftButtonDown);
            //this.MouseLeftButtonUp += new MouseButtonEventHandler(DragFinishedMouseHandler);
            //this.MouseMove += new MouseEventHandler(Window1_MouseMove);
            //this.MouseLeave += new MouseEventHandler(Window1_MouseLeave);

            //myCanvas.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(myCanvas_PreviewMouseLeftButtonDown);
            //myCanvas.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(DragFinishedMouseHandler);
        }
예제 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DragAdorner"/> class.
        /// </summary>
        /// <param name="data">The data that's being dragged.</param>
        /// <param name="dataTemplate">The data template to show while dragging.</param>
        /// <param name="adornedElement">The adorned element.</param>
        /// <param name="adornerLayer">The adorner layer.</param>
        public DragAdorner(object data, DataTemplate dataTemplate, UIElement adornedElement, AdornerLayer adornerLayer)
            : base(adornedElement)
        {
            Argument.IsNotNull("data", data);
            Argument.IsNotNull("adornerLayer", adornerLayer);

            _myAdornerLayer = adornerLayer;
            _myContentPresenter = new ContentPresenter { Content = data, ContentTemplate = dataTemplate, Opacity = 0.75 };

            _myAdornerLayer.Add(this);
        }
예제 #16
0
파일: ImageHelper.cs 프로젝트: alexiej/YATE
 public void AddImageResizers(RichTextBox editor)
 {
     var images = GetVisuals(editor).OfType<Image>();
     al = AdornerLayer.GetAdornerLayer(editor);
     foreach (var image in images)
     {
         current = new ResizingAdorner(new ResizingAdorner(image));
         //ResizingAdorner ral = new ResizingAdorner(image);
         al.Add(current);
         al.Update();
         //LIBTODO:
     }
 }
        private void SimDoubleClick(object sender, MouseButtonEventArgs e) {
            bool canDrawOutPlug = BackPanelUtil.SimDoubleClick(sender, e);
            if (canDrawOutPlug) {
                SocketAttatch.SetPlugOut(this, 1);
            } else {
                PlugInfoAdorner adorner = new PlugInfoAdorner(this);
                mAdornerLayer = AdornerLayer.GetAdornerLayer(this);
                mAdornerLayer.Add(adorner);

               // mAdornerLayer.Remove(adorner);
               // mAdornerLayer = null;
            }
        }
        public void Update(DropType dropType)
        {
            if (_layer == null)
            {
                _layer = AdornerLayer.GetAdornerLayer(AdornedElement);
                _layer.Add(this);
            }

            _parentAdorner?.Remove();
            _dropType = dropType;
            _layer.Update(AdornedElement);
            Visibility = Visibility.Visible;
        }
예제 #19
0
 public DraggedAdorner(object dragDropData, DataTemplate dragDropTemplate, UIElement adornedElement,
                       AdornerLayer adornerLayer)
     : base(adornedElement)
 {
     _adornerLayer = adornerLayer;
     _contentPresenter = new ContentPresenter
         {
             Content = dragDropData,
             ContentTemplate = dragDropTemplate,
             Opacity = AdornerOpacity
         };
     _adornerLayer.Add(this);
 }
 void dc_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "LeftPictureLocation")
     {
         var doesThisWork = VisualTreeHelper.GetChild(leftItemsControl, 0);
         var doesThisWorkt = VisualTreeHelper.GetChild(doesThisWork, 0);
         var doesThisWorktt = VisualTreeHelper.GetChild(doesThisWorkt, 0);
         canvasToTouch = (Canvas)doesThisWorktt;
         myAdornerLayer = AdornerLayer.GetAdornerLayer((Visual)doesThisWorktt);
         ad = new SimpleCircleAdorner((UIElement)doesThisWorktt);
         myAdornerLayer.Add(ad);
         myAdornerLayer.IsHitTestVisible = false;
     }
 }
예제 #21
0
        public DragAdorner(UIElement adornedElement, UIElement adornment, DragDropEffects effects = DragDropEffects.None) : base(adornedElement)
        {
            Check.ArgumentNotNull(() => adornedElement);
            Check.ArgumentNotNull(() => adornment);

            adornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);

            adornerLayer?.Add(this);

            this.adornment   = adornment;
            IsHitTestVisible = false;

            Effects = effects;
        }
예제 #22
0
        public DragInsertAdorner(UIElement adornedElement, 
            Point startPosition, 
            Visual content, 
            AdornerLayer adornerLayer)
            : base(adornedElement)
        {
            this.adornerLayer = adornerLayer;

            _Visuals = new VisualCollection(this);
            _ContentPresenter = new ContentPresenter();
            _Visuals.Add(_ContentPresenter);
            this.Content = content;
            adornerLayer.Add(this);
            UpdatePosition(startPosition.X, startPosition.Y);
        }
        // Be sure to call the base class constructor.
        public BorderSelectionAdorner(TreeViewEx treeViewEx)
            : base(treeViewEx)
        {
            this.treeViewEx = treeViewEx;
            this.border = new Border { BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(1), Opacity = 0.5 };

            Binding brushBinding = new Binding("BorderBrushSelectionRectangle");
            brushBinding.Source = treeViewEx;
            border.SetBinding(Border.BorderBrushProperty, brushBinding);
            Binding backgroundBinding = new Binding("BackgroundSelectionRectangle");
            backgroundBinding.Source = treeViewEx;
            border.SetBinding(Border.BackgroundProperty, backgroundBinding);

            layer = AdornerLayer.GetAdornerLayer(treeViewEx);
            layer.Add(this);
        }
예제 #24
0
        private static void SetWatermarkVisibility(Control control, bool visibility)
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(control);

            if (visibility)
            {
                layer?.Add(new WatermarkAdorner(control, GetWatermark(control)));
            }
            else
            {
                layer
                ?.GetAdorners(control)
                ?.OfType <WatermarkAdorner>()
                .ForEach(adorner =>
                {
                    adorner.Hide(true);
                    layer.Remove(adorner);
                });
            }
        }
        private void ApplyContentAdorner(bool show)
        {
            if (show)
            {
                if (_adornerLayer == null)
                {
                    _adornerLayer = AdornerLayer.GetAdornerLayer(AdornedElement);

                    SetBinding(VisibilityProperty,
                               new Binding {
                        Source = AdornedElement, Path = new PropertyPath(AdornerVisibilityProperty)
                    });
                }
                _adornerLayer?.Add(this);
            }
            else
            {
                _adornerLayer?.Remove(this);
            }
        }
예제 #26
0
    /// <summary>
    ///  Handler for element selection on the canvas providing resizing adorner.
    /// </summary>
    private void Select_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        //Ignore this event if it's the same element.
        if (Equals(_selectedElement, sender as UIElement))
        {
            return;
        }

        #region Remove elsewhere before adding the layer.

        if (_selectedElement != null)
        {
            var adornerList = _adornerLayer.GetAdorners(_selectedElement);

            var adorner = adornerList?.OfType <ResizingAdorner>().FirstOrDefault();

            if (adorner != null)
            {
                adorner.Destroy();

                //Remove the adorner from the selected element
                _adornerLayer.Remove(adorner);
                _selectedElement = null;
            }
        }

        #endregion

        #region Add

        _selectedElement = e.Source as UIElement;

        if (_selectedElement != null)
        {
            _adornerLayer = AdornerLayer.GetAdornerLayer(_selectedElement);
            _adornerLayer?.Add(new ResizingAdorner(_selectedElement, _selectedElement is Image, ContentGrid, e.GetPosition(ContentGrid)));
        }

        #endregion
    }
예제 #27
0
 void Toggle()
 {
     try
     {
         if (IsAdornerVisible)
         {
             AddLogicalChild(Content);
             AddVisualChild(Content);
             AdornerLayer?.Add(this);
         }
         else
         {
             AdornerLayer?.Remove(this);
             RemoveLogicalChild(Content);
             RemoveVisualChild(Content);
         }
     }
     catch (Exception e)
     {
         Dev2Logger.Error("Error toggling adorner: ", e);
     }
 }
예제 #28
0
        private static void ShowWatermark(Control control)
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(control);

            layer?.Add(new WatermarkAdorner(control, GetWatermark(control)));
        }
        void InstallAdorner()
        {
            if (_isDeleted)
                return;

            _adornerLayer = AdornerLayer.GetAdornerLayer(_InkCanvas);
            if (_adornerLayer == null)
                throw new ArgumentException("InkCanvas does not have have an adorner layer.");

            // Add the adorner to the InkCanvas's adorner layer.
            _adornerLayer.Add(_adorner);
        }
예제 #30
0
 void DisplayEditPoints()
 {
     CreateEditPoints();
     adornerLayer = AdornerLayer.GetAdornerLayer(editedConnector);
     if (adornerLayer != null)
     {
         adornerLayer.Add(new EditPointAdorner(this, editedConnector, false));
     }
 }
예제 #31
0
 private void CreateScrollbars()
 {
     _adorner = AdornerLayer.GetAdornerLayer(this);
     if (_adorner == null) return;
     _adorner.Add(new PropertySheetScrollAdorner(this, _scrollVertical) { Visibility = Visibility.Visible });
     _scrollVertical.ValueChanged += (s, e) => DispatchInvalidateScroll();
 }
예제 #32
0
        // Handler for element selection on the canvas providing resizing adorner
        void myCanvas_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            // Remove selection on clicking anywhere the window
            if (selected)
            {
                selected = false;
                if (selectedElement != null && aLayer.GetAdorners(selectedElement) != null)
                {
                    // Remove the adorner from the selected element
                    aLayer.Remove(aLayer.GetAdorners(selectedElement)[0]);
                    selectedElement = null;
                }
            }
            //If adding a new link
            if (e.Source.GetType() == typeof(SystemBasicView))
            {
                if (e.Source.GetType() == typeof(SystemBasicView) && _isAddNewLink)
                {
                    if (!_isLinkStarted)
                    {
                        if (_link == null || _link.EndPoint != _link.StartPoint)
                        {
                            _isLinkStarted = true;
                            _linkedSystem = e.Source as SystemBasicView;
                            SystemViewModel svm = (_linkedSystem.DataContext) as SystemViewModel;
                            _tempLink = new TemporaryConnectorViewModel(svm);
                            _tempLink.StartPostion = _linkedSystem.Position;
                            e.Handled = true;
                        }
                    }
                }
                // If a componentView is selected, add adorner layer to it
                else
                {
                    _isDown = true;
                    _startPoint = e.GetPosition(myCanvas);

                    selectedElement = e.Source as UIElement;
                    _originalPoint = selectedElement.TranslatePoint(new Point(0, 0), myCanvas);

                    aLayer = AdornerLayer.GetAdornerLayer(selectedElement);
                    aLayer.Add(new ResizingAdorner(selectedElement, myCanvas));

                    selected = true;
                    e.Handled = true;
                }
            }
        }
예제 #33
0
        public void DisplayInsertIndicator(Card source, int idx)
        {
            // If the index corresponds to the card being dragged, it's a NOP so don't provide any visual feedback
            if (idx < VisualChildrenCount)
            {
                var frameworkElement = (FrameworkElement)GetVisualChild(idx);
                if (frameworkElement != null && frameworkElement.DataContext == source)
                {
                    HideInsertIndicator();
                    return;
                }
                var visualChild = (FrameworkElement)GetVisualChild(idx);
                if (visualChild != null && (idx > 0 && visualChild.DataContext == source))
                {
                    HideInsertIndicator();
                    return;
                }
            }

            // Create an adorner if none exists yet
            if (_insertAdorner == null)
            {
                _insertAdorner = new InsertAdorner(this)
                {
                    Height = 106, ClippingVisual = ClippingVisual
                };
                // HACK: currently WarpPanel is only used by the group window, but card height should be a property and not hard-coded like that
                AdornerLayer layer = AdornerLayer.GetAdornerLayer(AdornerLayerVisual ?? this);
                layer.Add(_insertAdorner);
            }

            // Assuming all items are same height. Otherwise shit would be wild as FUUUUCK.
            var location = new Point();

            if (this.VisualChildrenCount > 0)
            {
                if (idx > VisualChildrenCount)
                {
                    idx = VisualChildrenCount;
                }
                if (idx != 0)
                {
                    var elem = (FrameworkElement)this.GetVisualChild(idx - 1);
                    location = elem.TranslatePoint(new Point(elem.DesiredSize.Width - elem.RenderTransform.Value.OffsetX, 0), this);
                }
            }

            _insertAdorner.MoveTo(new Point(location.X, location.Y));

            CancelSpacing();

            // Space neighbors
            if (idx >= VisualChildrenCount)
            {
                return;
            }
            _spacedItem2 = (UIElement)GetVisualChild(idx);
            SetSpacing(_spacedItem2, SpacingWidth);
            if (idx <= 0)
            {
                return;
            }
            _spacedItem1 = (UIElement)GetVisualChild(idx - 1);
            SetSpacing(_spacedItem1, -SpacingWidth);
        }
예제 #34
0
        void ModalDialogHost_Loaded(object sender, RoutedEventArgs e)
        {
            flagIsLoaded = true;
                dialog.Opened += new EventHandler(dialog_Opened);
                dialog.Closed += new EventHandler(dialog_Closed);

                EnsureRootElement();
                if (!IsDesignMode)
                {
                    if (shell == null)
                    {
                        shell = ((Window)rootElement.Parent);
                        shell.LocationChanged += new System.EventHandler(Shell_LocationChanged);
                        shell.SizeChanged += new SizeChangedEventHandler(shell_SizeChanged);
                        shell.StateChanged += new EventHandler(shell_StateChanged);
                        shell.Deactivated += new EventHandler(shell_Deactivated);
                        shell.Activated += new EventHandler(shell_Activated);
                        oldLeft = shell.Left;
                        oldTop = shell.Top;
                    }

                    if (myAdorner == null)
                    {
                        myAdorner = AdornerLayer.GetAdornerLayer(rootElement);
                        myAdorner.Visibility = Visibility.Hidden;
                        myAdorner.Add(this.Shader);
                    }
                }
                //first set PlacementTarget and Placement
                if (rootElement != null)
                {
                    dialog.PlacementTarget = rootElement;
                    dialog.Placement = PlacementMode.Relative;
                }

                //and then only attempt to open and reposition, otherwise
                //only a portion of the dialog is rendered
                IsOpen = isOpenCache;
                if (IsOpen)
                {
                    Show();
                }
        }
예제 #35
0
        public Task <DialogResult> ShowAsync(FrameworkElement dialogContainer)
        {
            if (dialogContainer == null)
            {
                throw new ArgumentNullException("Dialog Container Must Be Not Null!");
            }
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(dialogContainer);

            if (layer == null)
            {
                throw new ArgumentNullException("Dialog Container Must Have AdornerLayer!");
            }
            //Add this to adorner
            CustomAdorner adorner = null;

            Dispatcher.BeginInvoke(new Action(() =>
            {
                adorner = new CustomAdorner(dialogContainer, this);
                layer.Add(adorner);
                Keyboard.Focus(this);
            }));
            //Wait for loaded
            return(WaitForLoadedAsync().ContinueWith(x =>
            {
                //Wait for ContentDialog button click
                var tcsOfResult = new TaskCompletionSource <DialogResult>();
                //Initilize event handler
                Func <object, RoutedEventArgs, DialogResult, Task> cleanExitWith = null;
                RoutedEventHandler primaryHandler = null, secondaryHandler = null, closeHandler = null;
                cleanExitWith = (sender, e, result) =>
                {
                    var taskOfClosed = WaitForCloseAsync();
                    return taskOfClosed.ContinueWith(a =>
                    {
                        //UnRegister Event Handler
                        if (primaryButton != null)
                        {
                            primaryButton.Click -= primaryHandler;
                        }
                        if (secondButton != null)
                        {
                            secondButton.Click -= secondaryHandler;
                        }
                        if (closeButton != null)
                        {
                            closeButton.Click -= closeHandler;
                        }
                        //Invoke Closing Event Handler
                        Closing?.Invoke(sender, e);
                        dialogContainer.Dispatcher.Invoke(() =>
                        {
                            adorner.DisconnectChild();
                            //Remove ContentDialog
                            if (layer != null)
                            {
                                layer.Remove(adorner);
                            }
                            Keyboard.ClearFocus();
                        });
                        tcsOfResult.TrySetResult(result);
                    });
                };
                primaryHandler = (sender, e) => { cleanExitWith(sender, e, DialogResult.Primary); };
                secondaryHandler = (sender, e) => { cleanExitWith(sender, e, DialogResult.Secondary); };
                closeHandler = (sender, e) => { cleanExitWith(sender, e, DialogResult.Dismiss); };
                //Delegate
                if (primaryButton != null)
                {
                    primaryButton.Click += primaryHandler;
                }
                if (secondButton != null)
                {
                    secondButton.Click += secondaryHandler;
                }
                if (closeButton != null)
                {
                    closeButton.Click += closeHandler;
                }
                return tcsOfResult.Task;
            }).Unwrap());
        }
예제 #36
0
        public TimeLineDragAdorner(TimeLineItemControl uiElement, DataTemplate template)
            : base(uiElement)
        {
            _adorningContentPresenter = new ContentPresenter();
            _adorningContentPresenter.Content = uiElement.DataContext;
            _adorningContentPresenter.ContentTemplate = template;
            _adorningContentPresenter.Opacity = 0.5;
            _layer = AdornerLayer.GetAdornerLayer(uiElement);

            _layer.Add(this);
            IsHitTestVisible = false;
        }
예제 #37
0
        void WidgetDragOverHandler(object sender, System.Windows.DragEventArgs e)
        {
            if (Adorner != null) {
                var w = GetParentWindow ();
                var v = (UIElement)w.Content;

                if (w != AdornedWindow) {
                    AdornedLayer.Remove (Adorner);

                    AdornedWindow.AllowDrop = false;
                    AdornedWindow.DragOver -= AdornedWindowOnDragOver;

                    AdornedWindow = w;
                    AdornedWindow.AllowDrop = true;
                    AdornedWindow.DragOver += AdornedWindowOnDragOver;

                    AdornedLayer = AdornerLayer.GetAdornerLayer (v);
                    AdornedLayer.Add (Adorner);
                }

                Adorner.Offset = e.GetPosition (v);
            }
            CheckDrop (sender, e);
        }
예제 #38
0
        //=================================================
        // コンストラクター
        //=================================================

        #region コンストラクター
        /// <summary>コンストラクター</summary>
        /// <param name="adornedElement">修飾エレメント</param>
        protected UIElementAdornerBase(UIElement adornedElement) : base(adornedElement)
        {
            // 装飾描画サーフェースの初期化
            AdornerLayer = AdornerLayer.GetAdornerLayer(adornedElement);
            AdornerLayer?.Add(this);
        }
예제 #39
0
 private void CreateScrollbars()
 {
     _adorner = AdornerLayer.GetAdornerLayer(this);
     if (_adorner == null) return;
     _adorner.Add(new EditFormScrollAdorner(this, _scrollHorizontal, _scrollVertical) {Visibility = Visibility.Visible});
     _scrollHorizontal.ValueChanged += (s, e) => Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(DispatchInvalidateScroll));
     _scrollVertical.ValueChanged += (s, e) => Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(DispatchInvalidateScroll));
 }
예제 #40
0
        /// <summary>
        /// Initializing constructor
        /// </summary>
        /// <param name="adornedElement">Element whose UI is to be converted into an adorner</param>
        /// <param name="offset">Location within 'adornedElement' where mouse cursor was actually clicked</param>
        public DragDropAdorner( FrameworkElement adornedElement, Point offset )
            : base(adornedElement)
        {
            DrawingVisual   dv = new DrawingVisual();
            Visual          childVisual = (Visual)VisualTreeHelper.GetChild( adornedElement, 0 );
            VisualBrush     brush = new VisualBrush( childVisual );
            DrawingContext  dc = dv.RenderOpen();

            _offset = offset;

            dc.DrawRectangle( brush, null, new Rect( 0, 0, adornedElement.ActualWidth, adornedElement.ActualHeight ) );
            dc.Close();

            _translateTransform = new TranslateTransform();
            dv.Transform = _translateTransform;
            _childVisual = dv;

            AddVisualChild( _childVisual );

            _layer = AdornerLayer.GetAdornerLayer( adornedElement );
            _layer.Add( this );

            IsHitTestVisible = false;

            adornedElement.Visibility = Visibility.Hidden;
        }
 public static void AddScaleAdorner(ref AdornerLayer aLayer, ref Viewbox inst) {
     aLayer = AdornerLayer.GetAdornerLayer(inst);
     aLayer.Add(new ScaleAdorner(inst));
 }
예제 #42
0
        void WidgetDragOverHandler(object sender, System.Windows.DragEventArgs e)
        {
            var types          = e.Data.GetFormats().Select(t => t.ToXwtTransferType()).ToArray();
            var pos            = e.GetPosition(Widget).ToXwtPoint();
            var proposedAction = DetectDragAction(e.KeyStates);

            e.Handled = true;             // Prevent default handlers from being used.

            if (Adorner != null)
            {
                var w = GetParentWindow();
                var v = (UIElement)w.Content;

                if (w != AdornedWindow)
                {
                    AdornedLayer.Remove(Adorner);

                    AdornedWindow.AllowDrop = false;
                    AdornedWindow.DragOver -= AdornedWindowOnDragOver;

                    AdornedWindow           = w;
                    AdornedWindow.AllowDrop = true;
                    AdornedWindow.DragOver += AdornedWindowOnDragOver;

                    AdornedLayer = AdornerLayer.GetAdornerLayer(v);
                    AdornedLayer.Add(Adorner);
                }

                Adorner.Offset = e.GetPosition(v);
            }

            if ((enabledEvents & WidgetEvent.DragOverCheck) > 0)
            {
                var checkArgs = new DragOverCheckEventArgs(pos, types, proposedAction);
                Toolkit.Invoke(delegate {
                    eventSink.OnDragOverCheck(checkArgs);
                });
                if (checkArgs.AllowedAction == DragDropAction.None)
                {
                    e.Effects = currentDragEffect = DragDropEffects.None;
                    return;
                }
                if (checkArgs.AllowedAction != DragDropAction.Default)
                {
                    e.Effects = currentDragEffect = checkArgs.AllowedAction.ToWpfDropEffect();
                    return;
                }
            }

            if ((enabledEvents & WidgetEvent.DragOver) > 0)
            {
                var store = new TransferDataStore();
                FillDataStore(store, e.Data, DragDropInfo.TargetTypes);

                var args = new DragOverEventArgs(pos, store, proposedAction);
                OnDragOver(sender, args);
                if (args.AllowedAction == DragDropAction.None)
                {
                    e.Effects = currentDragEffect = DragDropEffects.None;
                    return;
                }
                if (args.AllowedAction != DragDropAction.Default)
                {
                    e.Effects = currentDragEffect = args.AllowedAction.ToWpfDropEffect();
                    return;
                }
            }

            e.Effects = currentDragEffect = proposedAction.ToWpfDropEffect();
        }
예제 #43
0
        /// <summary>
        ///  Handler for element selection on the canvas providing resizing adorner.
        /// </summary>
        private void Select_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            #region Remove elsewhere before adding the layer.

            if (_selectedElement != null)
            {
                //Remove the adorner from the selected element
                _adornerLayer.Remove(_adornerLayer.GetAdorners(_selectedElement)[0]);
                _selectedElement = null;
            }

            #endregion

            _selectedElement = e.Source as UIElement;

            if (_selectedElement != null)
            {
                _adornerLayer = AdornerLayer.GetAdornerLayer(_selectedElement);
                _adornerLayer.Add(new ResizingAdorner(_selectedElement));

                if (_selectedElement.GetType() == typeof(Image) && _selectedElement.CaptureMouse())
                {
                    _lastPosition = e.GetPosition(ContentGrid);
                }
            }

            e.Handled = true;
        }
예제 #44
0
        private void AdornOperationContainer(OperationContainer container, IDictionary <int, int> lineMap, AdornerLayer layer)
        {
            foreach (Operation operation in container.Operations)
            {
                int ln;
                if (!lineMap.TryGetValue(operation.Id, out ln))
                {
                    continue;
                }

                ln -= 1;

                int ch      = GetCharacterIndexFromLineIndex(ln);
                int len     = GetLineLength(ln);
                var endRect = GetRectFromCharacterIndex(ch + len - 1, true);

                Adorner adorner = null;

                if (operation is Loop)
                {
                    var loop = (Loop)operation;

                    int iteration;
                    if (!this.currentIterations.TryGetValue(loop.Id, out iteration))
                    {
                        iteration = 0;
                    }

                    var loopadorner = new LoopAdorner(this, loop);
                    if (iteration >= loopadorner.Iterations.Length)
                    {
                        this.currentIterations[loop.Id] = iteration = 0;
                    }

                    loopadorner.CurrentIteration  = iteration;
                    loopadorner.IterationChanged += (s, e) =>
                    {
                        this.currentIterations[loop.Id] = loopadorner.CurrentIteration;
                        OnMethodCallChanged();
                    };

                    adorner = loopadorner;

                    if (loopadorner.Iterations.Length > 0)
                    {
                        AdornOperationContainer(loopadorner.Iterations[iteration], lineMap, layer);
                    }
                }
                else if (operation is StateChange)
                {
                    adorner = new StateChangeAdorner(this, (StateChange)operation);
                }
                else if (operation is ReturnValue)
                {
                    adorner = new ReturnAdorner(this, (ReturnValue)operation);
                }

                if (adorner != null)
                {
                    double delta = endRect.Height - (endRect.Height * 0.8);

                    adorner.Margin    = new Thickness(endRect.X + 2, endRect.Y + (delta / 2), 0, 0);
                    adorner.MaxHeight = endRect.Height;

                    this.adorners.Add(operation.Id, adorner);
                    layer.Add(adorner);
                }
            }
        }
예제 #45
0
파일: WidgetBackend.cs 프로젝트: garuma/xwt
        public void DragStart(DragStartData data)
        {
            if (data.Data == null)
                throw new ArgumentNullException ("data");

            DataObject dataObj = data.Data.ToDataObject();

            if (data.ImageBackend != null) {
                AdornedWindow = GetParentWindow ();
                AdornedWindow.AllowDrop = true;

                var e = (UIElement)AdornedWindow.Content;

                Adorner = new ImageAdorner (e, data.ImageBackend);

                AdornedLayer = AdornerLayer.GetAdornerLayer (e);
                AdornedLayer.Add (Adorner);

                AdornedWindow.DragOver += AdornedWindowOnDragOver;
            }

            Widget.Dispatcher.BeginInvoke ((Action)(() => {
                var effect = DragDrop.DoDragDrop (Widget, dataObj, data.DragAction.ToWpfDropEffect ());

                OnDragFinished (this, new DragFinishedEventArgs (effect == DragDropEffects.Move));

                if (Adorner != null) {
                    AdornedLayer.Remove (Adorner);
                    AdornedLayer = null;
                    Adorner = null;

                    AdornedWindow.AllowDrop = false;
                    AdornedWindow.DragOver -= AdornedWindowOnDragOver;
                    AdornedWindow = null;
                }
            }));
        }
예제 #46
0
파일: WrapPanel.cs 프로젝트: traemyn/OCTGN
        public void DisplayInsertIndicator(Card source, int idx)
        {
            // If the index corresponds to the card being dragged, it's a NOP so don't provide any visual feedback
            if (idx < VisualChildrenCount)
            {
                var frameworkElement = (FrameworkElement)GetVisualChild(idx);
                if (frameworkElement != null && frameworkElement.DataContext == source)
                {
                    HideInsertIndicator();
                    return;
                }
                var visualChild = (FrameworkElement)GetVisualChild(idx);
                if (visualChild != null && (idx > 0 && visualChild.DataContext == source))
                {
                    HideInsertIndicator();
                    return;
                }
            }

            // Create an adorner if none exists yet
            if (_insertAdorner == null)
            {
                _insertAdorner = new InsertAdorner(this)
                {
                    Height = 106, ClippingVisual = ClippingVisual
                };
                // HACK: currently WarpPanel is only used by the group window, but card height should be a property and not hard-coded like that
                AdornerLayer layer = AdornerLayer.GetAdornerLayer(AdornerLayerVisual ?? this);
                layer.Add(_insertAdorner);
            }

            // Assuming all items are same height. Otherwise shit would be wild as FUUUUCK.
            var curY = 0d;
            var curX = 0d;

            if (this.VisualChildrenCount > 0)
            {
                var firstElem     = (FrameworkElement)this.GetVisualChild(0);
                var defaultHeight = firstElem.ActualHeight + firstElem.Margin.Top + firstElem.Margin.Bottom;
                for (var i = 0; i < idx; i++)
                {
                    var cur      = (FrameworkElement)this.GetVisualChild(i);
                    var addWidth = cur.ActualWidth + cur.Margin.Left + cur.Margin.Right;
                    curX += addWidth;
                    if (curX > this.ActualWidth && i != idx - 1)
                    {
                        curX  = cur.ActualWidth + cur.Margin.Left + cur.Margin.Right;
                        curY += defaultHeight;
                    }
                }
                //var newCardWidth = source.Size.Width + firstElem.Margin.Left + firstElem.Margin.Right;
                //if (idx < VisualChildrenCount)
                //{
                //    var nextElem = (FrameworkElement) this.GetVisualChild(idx);
                //    var nx = curX += nextElem.ActualWidth + nextElem.Margin.Left + nextElem.Margin.Right;
                //    if (nx > this.ActualWidth)
                //    {
                //        curX = ;
                //        curY = curY += defaultHeight;
                //        //_insertAtEndOfRow = true;
                //    }
                //}
            }
            _insertAdorner.MoveTo(new Point(curX, curY));

            // Assuming all items have the same size, get the size of the first one
            //double itemHeight = 0;
            //Double itemWidth = 0;
            //int rowSize;
            //if (VisualChildrenCount == 0)
            //{
            //    itemHeight = itemWidth = 0;
            //    rowSize = int.MaxValue;
            //}
            //else
            //{
            //    var firstChild = (FrameworkElement) GetVisualChild(0);
            //    if (firstChild != null)
            //    {
            //        itemHeight = firstChild.ActualHeight + firstChild.Margin.Top + firstChild.Margin.Bottom;
            //        itemWidth = firstChild.ActualWidth + firstChild.Margin.Left + firstChild.Margin.Right;
            //    }
            //    rowSize = Math.Max(1, (int) (ActualWidth/itemWidth));
            //}

            //// Position the adorner correctly
            //int hOffset, vOffset = Math.DivRem(idx, rowSize, out hOffset);
            //if (hOffset == 0 && _insertAtEndOfRow)
            //{
            //    vOffset -= 1;
            //    hOffset = rowSize;
            //}
            //_insertAdorner.MoveTo(new Point(hOffset*itemWidth, vOffset*itemHeight));

            CancelSpacing();

            // Space neighbors
            if (idx >= VisualChildrenCount)
            {
                return;
            }
            _spacedItem2 = (UIElement)GetVisualChild(idx);
            SetSpacing(_spacedItem2, SpacingWidth);
            if (idx <= 0)
            {
                return;
            }
            _spacedItem1 = (UIElement)GetVisualChild(idx - 1);
            SetSpacing(_spacedItem1, -SpacingWidth);
        }
예제 #47
0
 public FrameworkElementAdorner(UIElement adornedElement)
     : base(adornedElement)
 {
     adornerLayer = AdornerLayer.GetAdornerLayer(AdornedElement);
     adornerLayer.Add(this);
 }
예제 #48
0
 void AddLayer()
 {
     _layer.Add(_adorner);
 }
예제 #49
0
파일: WidgetBackend.cs 프로젝트: garuma/xwt
        void WidgetDragOverHandler(object sender, System.Windows.DragEventArgs e)
        {
            var types = e.Data.GetFormats ().Select (t => t.ToXwtTransferType ()).ToArray ();
            var pos = e.GetPosition (Widget).ToXwtPoint ();
            var proposedAction = DetectDragAction (e.KeyStates);

            e.Handled = true; // Prevent default handlers from being used.

            if (Adorner != null) {
                var w = GetParentWindow ();
                var v = (UIElement)w.Content;

                if (w != AdornedWindow) {
                    AdornedLayer.Remove (Adorner);

                    AdornedWindow.AllowDrop = false;
                    AdornedWindow.DragOver -= AdornedWindowOnDragOver;

                    AdornedWindow = w;
                    AdornedWindow.AllowDrop = true;
                    AdornedWindow.DragOver += AdornedWindowOnDragOver;

                    AdornedLayer = AdornerLayer.GetAdornerLayer (v);
                    AdornedLayer.Add (Adorner);
                }

                Adorner.Offset = e.GetPosition (v);
            }

            if ((enabledEvents & WidgetEvent.DragOverCheck) > 0) {
                var checkArgs = new DragOverCheckEventArgs (pos, types, proposedAction);
                Context.InvokeUserCode (delegate {
                    eventSink.OnDragOverCheck (checkArgs);
                });
                if (checkArgs.AllowedAction == DragDropAction.None) {
                    e.Effects = currentDragEffect = DragDropEffects.None;
                    return;
                }
                if (checkArgs.AllowedAction != DragDropAction.Default) {
                    e.Effects = currentDragEffect = checkArgs.AllowedAction.ToWpfDropEffect ();
                    return;
                }
            }

            if ((enabledEvents & WidgetEvent.DragOver) > 0) {
                var store = new TransferDataStore ();
                FillDataStore (store, e.Data, DragDropInfo.TargetTypes);

                var args = new DragOverEventArgs (pos, store, proposedAction);
                OnDragOver (sender, args);
                if (args.AllowedAction == DragDropAction.None) {
                    e.Effects = currentDragEffect = DragDropEffects.None;
                    return;
                }
                if (args.AllowedAction != DragDropAction.Default) {
                    e.Effects = currentDragEffect = args.AllowedAction.ToWpfDropEffect ();
                    return;
                }
            }

            e.Effects = currentDragEffect = proposedAction.ToWpfDropEffect ();
        }
예제 #50
0
        /// <summary>
        /// Attaches this adorner to the adorned element
        /// </summary>
        public void Attach()
        {
            if (attached)
            {
                return;
            }
            Log("Attach begin");

            if (!oneOfAssociatedElements.IsLoaded)
            {
                // Delay attaching
                oneOfAssociatedElements.Loaded += OnDelayAttach;
                return;
            }

            adornerLayer = GetAdornerLayer(oneOfAssociatedElements);
            if (adornerLayer == null)
            {
                return;
            }

            // Focus current adorned element
            // Keyboard.Focus(adornedElement);
            focusedElement = Keyboard.FocusedElement;
            if (focusedElement != null)
            {
                Log("Focus Attached to " + focusedElement.ToString());
                focusedElement.LostKeyboardFocus += OnFocusLost;
                focusedElement.PreviewKeyDown    += OnPreviewKeyDown;
                focusedElement.PreviewTextInput  += this.OnFocusedElementPreviewTextInput;
            }
            else
            {
                Log("[!] Focus Setup Failed");
            }
            GetTopLevelElement(oneOfAssociatedElements).PreviewMouseDown += OnInputActionOccured;

            // Show this adorner
            adornerLayer.Add(this);

            // Clears previous user input
            enteredKeys = "";
            FilterKeyTips();


            // Hookup window activation
            attachedHwndSource = ((HwndSource)PresentationSource.FromVisual(oneOfAssociatedElements));
            if (attachedHwndSource != null)
            {
                attachedHwndSource.AddHook(WindowProc);
            }

            // Start timer to track focus changing
            if (timerFocusTracking == null)
            {
                timerFocusTracking          = new DispatcherTimer(DispatcherPriority.ApplicationIdle, Dispatcher.CurrentDispatcher);
                timerFocusTracking.Interval = TimeSpan.FromMilliseconds(50);
                timerFocusTracking.Tick    += OnTimerFocusTrackingTick;
            }
            timerFocusTracking.Start();

            attached = true;
            Log("Attach end");
        }