Beispiel #1
0
        /// <summary>
        /// Show <see cref="DockableContent"/> as docked pane
        /// </summary>
        public void Show(DockingManager manager, AnchorStyle desideredAnchor)
        {
            if (Manager != null && Manager != manager)
            {
                throw new InvalidOperationException("Please remove the content from previous DockingManager (using the Close method)");
            }

            if (manager == null && !CanExecuteCommand(ManagedContentCommands.Show))
            {
                throw new InvalidOperationException("This operation can be executed in this state");
            }

            if (State == DockableContentState.Docked)
            {
                //if already shown as docked content just activate it
                Activate();
            }
            else
            {
                if (SavedStateAndPosition != null && State == DockableContentState.Hidden)
                {
                    manager.Show(this, SavedStateAndPosition.State, desideredAnchor);
                }
                else
                {
                    manager.Show(this, DockableContentState.Docked, desideredAnchor);
                }
            }
        }
Beispiel #2
0
        public IDockPane ShowPane(string name, CreateDockPaneDelegate createDockPane)
        {
            IDockPane pane       = null;
            var       avalonPane = FindAvalonPane(name);

            if (avalonPane == null)
            {
                avalonPane = new DockableContent()
                {
                    Name = name
                };
                pane = createDockPane(avalonPane, name);

                BindingExtensions.CreateBinding(pane, "PaneTitle", avalonPane, DockableContent.TitleProperty, BindingMode.OneWay);

                avalonPane.Content = pane;

                avalonPane.Closing += AvalonPane_Closing;
                avalonPane.Closed  += AvalonPane_Closed;

                AnchorStyle anchor = AnchorStyle.None;
                switch (pane.DefaultPaneLocation)
                {
                case PaneLocation.Left:
                    anchor = AnchorStyle.Left;
                    break;

                case PaneLocation.Right:
                    anchor = AnchorStyle.Right;
                    break;

                case PaneLocation.Top:
                    anchor = AnchorStyle.Top;
                    break;

                case PaneLocation.Bottom:
                    anchor = AnchorStyle.Bottom;
                    break;
                }

                avalonPane.HideOnClose = pane.HidePaneOnClose;
                avalonPane.Show(dockingManager, anchor);
            }
            else
            {
                avalonPane.Show();
            }

            Dispatcher.BeginInvoke(new NoArgsDelegate(() => { avalonPane.Manager.ActiveDocument = avalonPane; }), null);

            return(pane);
        }
 public DockableContentStateAndPosition(
     Pane containerPane,
     int childIndex,
     double width,
     double height,
     AnchorStyle anchor)
 {
     ContainerPane = containerPane;
     ChildIndex    = childIndex;
     Width         = Math.Max(width, 100.0);
     Height        = Math.Max(height, 100.0);
     Anchor        = anchor;
 }
Beispiel #4
0
        public override void SetValue(object component, object value)
        {
            if (value is System.Drawing.Color)
            {
                System.Drawing.Color c = (System.Drawing.Color)value;

                this.property.FromString((String)"#" + c.R + "," + c.G + "," + c.B + "," + c.A, this.control.Window.Desktop.Theme);
            }
            else if (value is MousePointers)
            {
                this.property.FromString(ThW.UI.Utils.Converter.Convert((MousePointers)value), this.control.Window.Desktop.Theme);
            }
            else if (value is Font)
            {
                Font f = (Font)value;

                this.control.FontInfo.SetFontInfo(f.Name, (int)f.Size, f.Bold, f.Italic);
            }
            else if (value is AnchorStyles)
            {
                AnchorStyles s = (AnchorStyles)value;

                AnchorStyle result = AnchorStyle.None;

                if ((s & AnchorStyles.Top) > 0)
                {
                    result |= AnchorStyle.AnchorTop;
                }

                if ((s & AnchorStyles.Left) > 0)
                {
                    result |= AnchorStyle.AnchorLeft;
                }

                if ((s & AnchorStyles.Right) > 0)
                {
                    result |= AnchorStyle.AnchorRight;
                }

                if ((s & AnchorStyles.Bottom) > 0)
                {
                    result |= AnchorStyle.AnchorBottom;
                }

                this.property.Value = result;
            }
            else
            {
                this.property.Value = value;
            }
        }
Beispiel #5
0
 public DockableContentStateAndPosition(
     Guid containerPaneID,
     int childIndex,
     double width,
     double height,
     AnchorStyle anchor,
     DockableContentState state)
 {
     ContainerPaneID = containerPaneID;
     ChildIndex      = childIndex;
     Width           = Math.Max(width, 100.0);
     Height          = Math.Max(height, 100.0);
     Anchor          = anchor;
     State           = state;
 }
        public DockableContentStateAndPosition(
            DockableContent cntToSave)
        {
            ContainerPane = cntToSave.ContainerPane;
            ChildIndex    = ContainerPane.Items.IndexOf(cntToSave);
            Width         = Math.Max(ContainerPane.ActualWidth, 100.0);
            Height        = Math.Max(ContainerPane.ActualHeight, 100.0);
            State         = cntToSave.State;

            DockablePane dockablePane = ContainerPane as DockablePane;

            if (dockablePane != null)
            {
                Anchor = dockablePane.Anchor;
            }
        }
        static DockablePane FindChildDockablePane(UIElement parent, AnchorStyle desideredAnchor)
        {
            if (parent is DockablePane && ((DockablePane)parent).Anchor == desideredAnchor)
            {
                return(parent as DockablePane);
            }

            if (parent is ResizingPanel)
            {
                foreach (UIElement childObject in ((ResizingPanel)parent).Children)
                {
                    DockablePane foundPane = FindChildDockablePane(childObject, desideredAnchor);
                    if (foundPane != null)
                    {
                        return(foundPane);
                    }
                }
            }

            return(null);
        }
 /// <summary>
 /// Provides a secure method for setting the Anchor property.  
 /// This dependency property indicates the achor style of referenced content that is in autohidden state.
 /// </summary>
 /// <param name="value">The new value for the property.</param>
 protected void SetAnchor(AnchorStyle value)
 {
     SetValue(AnchorPropertyKey, value);
 }
        /// <summary>
        /// Show <see cref="DockableContent"/> as docked pane
        /// </summary>
        public void Show(DockingManager manager, AnchorStyle desideredAnchor)
        {
            if (Manager != null && Manager != manager)
                throw new InvalidOperationException("Please remove the content from previous DockingManager (using the Close method)");

            if (manager == null && !CanExecuteCommand(ManagedContentCommands.Show))
                throw new InvalidOperationException("This operation can be executed in this state");

            if (State == DockableContentState.Docked)
            {
                //if already shown as docked content just activate it
                Activate();
            }
            else
            {
                if (SavedStateAndPosition != null && State == DockableContentState.Hidden)
                    manager.Show(this, SavedStateAndPosition.State, desideredAnchor);
                else
                    manager.Show(this, DockableContentState.Docked, desideredAnchor);
            }
        }
        public static DockablePane FindChildDockablePane(this DockingManager manager, AnchorStyle desideredAnchor)
        {
            foreach (UIElement childObject in LogicalTreeHelper.GetChildren(manager))
            {
                DockablePane foundPane = FindChildDockablePane(childObject, desideredAnchor);
                if (foundPane != null)
                {
                    return(foundPane);
                }
            }

            return(null);
        }
Beispiel #11
0
        /// <summary>
        /// Anchor a document pane (<see cref="DocumentPane"/>) to a border of an other document pane
        /// </summary>
        /// <param name="paneToAnchor">Pane to anchor</param>
        /// <param name="relativePane">Pane relative</param>
        /// <param name="anchor"></param>
        public void Anchor(DocumentPane paneToAnchor, DocumentPane relativePane, AnchorStyle anchor)
        {
            //ensure that content property is not empty
            EnsureContentNotEmpty();

            if (anchor == AnchorStyle.None)
                anchor = AnchorStyle.Right;

            //get a reference to the resizingpanel container of relativePane
            ResizingPanel relativePaneContainer = LogicalTreeHelper.GetParent(relativePane) as ResizingPanel;
            DocumentPaneResizingPanel relativeDocumentPaneContainer = relativePane.GetParentDocumentPaneResizingPanel();
            Orientation requestedOrientation =
                (anchor == AnchorStyle.Bottom || anchor == AnchorStyle.Top) ? Orientation.Vertical : Orientation.Horizontal;

            if (relativePaneContainer == null)
            {
                Debug.Assert(relativePane.Parent == this);

                relativeDocumentPaneContainer = new DocumentPaneResizingPanel();
                relativePaneContainer = relativeDocumentPaneContainer;

                relativeDocumentPaneContainer.Orientation = requestedOrientation;
                this.Content = relativePaneContainer;

                relativePaneContainer.Children.Add(relativePane);

            }

            if (relativeDocumentPaneContainer == null)
            {
                relativeDocumentPaneContainer = new DocumentPaneResizingPanel();
                relativeDocumentPaneContainer.Orientation = requestedOrientation;

                int indexOfPaneToReplace = relativePaneContainer.Children.IndexOf(relativePane);
                relativePaneContainer.Children.RemoveAt(indexOfPaneToReplace);

                relativeDocumentPaneContainer.Children.Add(relativePane);

                relativePaneContainer.Children.Insert(indexOfPaneToReplace, relativeDocumentPaneContainer);

                relativePaneContainer = relativeDocumentPaneContainer;
            }

            Debug.Assert(relativePaneContainer != null, "By now we can't have a pane without a resizing panel containing it");

            #region Create and setup container panel
            if (relativePaneContainer != null)
            {
                //check if orientation is right
                if (relativePaneContainer.Orientation != requestedOrientation)
                {
                    //if the existing panel is not oriented as we want
                    //create a new one
                    DocumentPaneResizingPanel newPanel = new DocumentPaneResizingPanel();
                    newPanel.Orientation = requestedOrientation;

                    //replace relative pane in its' container panel
                    //with this new panel
                    int indexofRelativePane = relativePaneContainer.Children.IndexOf(relativePane);
                    relativePaneContainer.Children.Remove(relativePane);
                    relativePaneContainer.Children.Insert(indexofRelativePane, newPanel);

                    //now we have a panel correctly placed in the tree
                    newPanel.Children.Add(relativePane);

                    //use InsertChildRelativeTo function to add a resizingsplitter between
                    //the two children
                    newPanel.InsertChildRelativeTo(
                        paneToAnchor, relativePane, anchor == AnchorStyle.Right || anchor == AnchorStyle.Bottom);

                    relativePaneContainer = newPanel;
                }
                else
                {
                    if (anchor == AnchorStyle.Left ||
                        anchor == AnchorStyle.Top)
                    {
                        //add new child before first (prepend)
                        relativePaneContainer.InsertChildRelativeTo(paneToAnchor,
                            relativePane, false);
                    }
                    else
                    {
                        //add new child after last (append)
                        relativePaneContainer.InsertChildRelativeTo(paneToAnchor,
                            relativePane, true);
                    }

                    //if (relativePaneContainer.Orientation == Orientation.Horizontal)
                    //{
                    //    Size desideredSize = ResizingPanel.GetEffectiveSize(paneToAnchor);
                    //    double approxStarForNewPane = desideredSize.Width / relativePaneContainer.ActualWidth;
                    //    approxStarForNewPane = Math.Min(approxStarForNewPane, 1.0);
                    //    paneToAnchor.SetValue(ResizingPanel.ResizeWidthProperty, new GridLength(approxStarForNewPane, GridUnitType.Star));
                    //}
                }

                relativePaneContainer.InvalidateMeasure();
            }
            #endregion

            //paneToAnchor.Focus();

            //(paneToAnchor.SelectedItem as ManagedContent).Activate();
            //if (paneToAnchor.SelectedItem is DocumentContent)
            //    ActiveDocument = paneToAnchor.SelectedItem as DocumentContent;

            paneToAnchor.SelectedIndex = 0;
        }
Beispiel #12
0
        /// <summary>
        /// Initiate a closing animation
        /// </summary>
        void CloseWidthAnimation()
        {
            AnchorStyle CorrectedAnchor = Anchor;

            if (CorrectedAnchor == AnchorStyle.Left && FlowDirection == FlowDirection.RightToLeft)
            {
                CorrectedAnchor = AnchorStyle.Right;
            }
            else if (CorrectedAnchor == AnchorStyle.Right && FlowDirection == FlowDirection.RightToLeft)
            {
                CorrectedAnchor = AnchorStyle.Left;
            }

            double wnd_Width  = this.ActualWidth;
            double wnd_Height = this.ActualHeight;
            double wnd_Left   = this.Left;
            double wnd_Top    = this.Top;

            int wnd_TrimWidth  = (int)wnd_Width;
            int wnd_TrimHeight = (int)wnd_Height;

            int stepWidth  = (int)(wnd_Width / 4);
            int stepHeight = (int)(wnd_Height / 4);

            DispatcherTimer animTimer = new DispatcherTimer();

            animTimer.Interval = TimeSpan.FromMilliseconds(1);

            animTimer.Tick += (sender, eventArgs) =>
            {
                bool   stopTimer = false;
                double newLeft   = 0.0;
                double newTop    = 0.0;
                switch (CorrectedAnchor)
                {
                case AnchorStyle.Right:
                    newLeft = this.Left;
                    if (this.Left + stepWidth >= wnd_Left + wnd_Width)
                    {
                        newLeft       = wnd_Left + wnd_Width;
                        wnd_TrimWidth = 0;
                        stopTimer     = true;
                    }
                    else
                    {
                        newLeft       += stepWidth;
                        wnd_TrimWidth -= stepWidth;
                        wnd_TrimWidth  = Math.Max(wnd_TrimWidth, 0);
                    }

                    //SetWindowRgn(new WindowInteropHelper(this).Handle, CreateRectRgn(0, 0, wnd_TrimWidth, wnd_TrimHeight), true);
                    ApplyRegion(new Rect(0, 0, wnd_TrimWidth, wnd_TrimHeight));
                    this.Left = newLeft;
                    break;

                case AnchorStyle.Left:
                    newLeft = this.Left;
                    if (this.Left - stepWidth <= wnd_Left - wnd_Width)
                    {
                        newLeft       = wnd_Left - wnd_Width;
                        wnd_TrimWidth = 0;
                        stopTimer     = true;
                    }
                    else
                    {
                        newLeft       -= stepWidth;
                        wnd_TrimWidth -= stepWidth;
                        wnd_TrimWidth  = Math.Max(wnd_TrimWidth, 0);
                    }

                    this.Left = newLeft;
                    //SetWindowRgn(new WindowInteropHelper(this).Handle, CreateRectRgn((int)(wnd_Left - this.Left), 0, (int)(wnd_Width), wnd_TrimHeight), true);
                    ApplyRegion(
                        new Rect((int)(wnd_Left - this.Left), 0, (int)(wnd_Width), wnd_TrimHeight));
                    break;

                case AnchorStyle.Bottom:
                    newTop = this.Top;
                    if (this.Top + stepHeight >= wnd_Top + wnd_Height)
                    {
                        newTop         = wnd_Top + wnd_Height;
                        wnd_TrimHeight = 0;
                        stopTimer      = true;
                    }
                    else
                    {
                        newTop         += stepHeight;
                        wnd_TrimHeight -= stepHeight;
                        wnd_TrimHeight  = Math.Max(wnd_TrimHeight, 0);
                    }

                    //SetWindowRgn(new WindowInteropHelper(this).Handle, CreateRectRgn(0, 0, wnd_TrimWidth, wnd_TrimHeight), true);
                    ApplyRegion(
                        new Rect(0, 0, wnd_TrimWidth, wnd_TrimHeight));
                    this.Top = newTop;
                    break;

                case AnchorStyle.Top:
                    newTop = this.Top;
                    if (this.Top - stepHeight <= wnd_Top - wnd_Height)
                    {
                        newTop         = wnd_Top - wnd_Height;
                        wnd_TrimHeight = 0;
                        stopTimer      = true;
                    }
                    else
                    {
                        newTop         -= stepHeight;
                        wnd_TrimHeight -= stepHeight;
                        wnd_TrimHeight  = Math.Max(wnd_TrimWidth, 0);
                    }

                    this.Top = newTop;
                    ApplyRegion(
                        new Rect(0, (int)(wnd_Top - this.Top), wnd_TrimWidth, (int)(wnd_Height)));
                    //SetWindowRgn(new WindowInteropHelper(this).Handle, CreateRectRgn(0, (int)(wnd_Top - this.Top), wnd_TrimWidth, (int)(wnd_Height)), true);
                    break;
                }

                if (stopTimer)
                {
                    //window is being closed
                    Width  = 0.0;
                    Height = 0.0;
                    animTimer.Stop();
                    if (!IsClosed)
                    {
                        Close();
                    }
                    IsClosing = false;
                }
            };

            IsClosing = true;
            animTimer.Start();
        }
Beispiel #13
0
        private void _resizer_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            UIElement dragElement = sender as UIElement;

            if (dragElement.IsMouseCaptured)
            {
                Point       ptMoveDrag      = e.GetPosition(dragElement);
                AnchorStyle CorrectedAnchor = Anchor;

                if (CorrectedAnchor == AnchorStyle.Left && FlowDirection == FlowDirection.RightToLeft)
                {
                    CorrectedAnchor = AnchorStyle.Right;
                }
                else if (CorrectedAnchor == AnchorStyle.Right && FlowDirection == FlowDirection.RightToLeft)
                {
                    CorrectedAnchor = AnchorStyle.Left;
                }

                double deltaX = FlowDirection == FlowDirection.LeftToRight ? ptMoveDrag.X - ptStartDrag.X : ptStartDrag.X - ptMoveDrag.X;

                if (CorrectedAnchor == AnchorStyle.Left)
                {
                    if (Width + deltaX < 4.0)
                    {
                        Width = 4.0;
                    }
                    else
                    {
                        Width += deltaX;
                    }
                }
                else if (CorrectedAnchor == AnchorStyle.Top)
                {
                    if (Height + (ptMoveDrag.Y - ptStartDrag.Y) < 4.0)
                    {
                        Height = 4.0;
                    }
                    else
                    {
                        Height += ptMoveDrag.Y - ptStartDrag.Y;
                    }
                }
                else if (CorrectedAnchor == AnchorStyle.Right)
                {
                    if (Width - (deltaX) < 4)
                    {
                        Left  = originalLeft + originalWidth - 4;
                        Width = 4;
                    }
                    else
                    {
                        Left  += deltaX;
                        Width -= deltaX;
                    }
                }
                else if (CorrectedAnchor == AnchorStyle.Bottom)
                {
                    if (Height - (ptMoveDrag.Y - ptStartDrag.Y) < 4)
                    {
                        Top    = originalTop + originalHeight - 4;
                        Height = 4;
                    }
                    else
                    {
                        Top    += ptMoveDrag.Y - ptStartDrag.Y;
                        Height -= ptMoveDrag.Y - ptStartDrag.Y;
                    }
                }

                ResizingPanel.SetResizeHeight(ReferencedPane, ReferencedPane.ActualHeight);
                ResizingPanel.SetResizeWidth(ReferencedPane, ReferencedPane.ActualWidth);
            }
        }
Beispiel #14
0
        /// <summary>
        /// Anchor a dockable pane to a border
        /// </summary>
        /// <param name="paneToAnchor"></param>
        /// <param name="anchor"></param>
        public void Anchor(DockablePane paneToAnchor, AnchorStyle anchor)
        {
            //ensure that content property is not empty
            EnsureContentNotEmpty();

            if (Content == null)
                return;

            //remove the pane from its original children collection
            FrameworkElement parentElement = paneToAnchor.Parent as FrameworkElement;

            if (anchor == AnchorStyle.None)
                anchor = AnchorStyle.Right;

            //Change anchor border according to FlowDirection
            if (FlowDirection == FlowDirection.RightToLeft)
            {
                if (anchor == AnchorStyle.Right)
                    anchor = AnchorStyle.Left;
                else if (anchor == AnchorStyle.Left)
                    anchor = AnchorStyle.Right;
            }

            //parentElement should be a DockingManager or a ResizingPanel
            if (parentElement is ContentControl)
            {
                ((ContentControl)parentElement).Content = null;
            }

            //and insert in the top level panel if exist
            ResizingPanel toplevelPanel = Content as ResizingPanel;

            if (toplevelPanel != null && toplevelPanel.Children.Count == 0)
            {
                Content = null;
                toplevelPanel = null;
            }

            Orientation requestedOrientation =
                (anchor == AnchorStyle.Bottom || anchor == AnchorStyle.Top) ? Orientation.Vertical : Orientation.Horizontal;

            //if toplevel panel contains only one child then just override the orientation
            //as requested
            if (toplevelPanel != null && toplevelPanel.Children.Count == 1)
                toplevelPanel.Orientation = requestedOrientation;

            if (toplevelPanel == null ||
                toplevelPanel.Orientation != requestedOrientation)
            {
                //if toplevel panel doesn't exist or it has not the correct orientation
                //we have to create a new one and set it as content of docking manager
                toplevelPanel = new ResizingPanel();
                toplevelPanel.Orientation = requestedOrientation;

                FrameworkElement contentElement = Content as FrameworkElement;

                _allowRefreshContents = false;
                Content = null;

                if (anchor == AnchorStyle.Left ||
                    anchor == AnchorStyle.Top)
                {
                    toplevelPanel.Children.Add(paneToAnchor);
                    toplevelPanel.InsertChildRelativeTo(contentElement, paneToAnchor, true);
                }
                else
                {
                    toplevelPanel.Children.Add(paneToAnchor);
                    toplevelPanel.InsertChildRelativeTo(contentElement, paneToAnchor, false);
                }

                _allowRefreshContents = true;
                Content = toplevelPanel;
            }
            else
            {

                //here we have a docking manager content with the right orientation
                //so we have only to insert new child at correct position
                if (anchor == AnchorStyle.Left ||
                    anchor == AnchorStyle.Top)
                {
                    //add new child before first one (prepend)
                    toplevelPanel.InsertChildRelativeTo(paneToAnchor, toplevelPanel.Children[0] as FrameworkElement, false);
                }
                else
                {
                    //add new child after last one (append)
                    toplevelPanel.InsertChildRelativeTo(paneToAnchor, toplevelPanel.Children[toplevelPanel.Children.Count - 1] as FrameworkElement, true);
                }
            }

            //Refresh anchor style
            DockablePane paneToAnchorAsDockablePane = paneToAnchor as DockablePane;

            if (paneToAnchorAsDockablePane != null)
            {
                paneToAnchorAsDockablePane.Anchor = anchor;
            }

            if (anchor == AnchorStyle.Left ||
                anchor == AnchorStyle.Right)
            {
                double w = Math.Min(
                    ActualWidth / 2.0,
                    ResizingPanel.GetEffectiveSize(paneToAnchor).Width);
                ResizingPanel.SetResizeWidth(paneToAnchor, new GridLength(w, GridUnitType.Pixel));
                ResizingPanel.SetResizeHeight(paneToAnchor, new GridLength(1.0, GridUnitType.Star));
            }
            else
            {
                double h = Math.Min(
                    ActualHeight / 2.0,
                    ResizingPanel.GetEffectiveSize(paneToAnchor).Height);
                ResizingPanel.SetResizeWidth(paneToAnchor, new GridLength(1.0, GridUnitType.Star));
                ResizingPanel.SetResizeHeight(paneToAnchor, new GridLength(h, GridUnitType.Pixel));
            }

            //refresh contents state
            paneToAnchor.Items.OfType<DockableContent>().ForEach(dc =>
                {
                    dc.SetStateToDock();
                });

            //paneToAnchor.Focus();
            toplevelPanel.InvalidateMeasure();
        }
Beispiel #15
0
        internal void StartCloseAnimation()
        {
            AnchorStyle CorrectedAnchor = Anchor;

            if (CorrectedAnchor == AnchorStyle.Left && FlowDirection == FlowDirection.RightToLeft)
            {
                CorrectedAnchor = AnchorStyle.Right;
            }
            else if (CorrectedAnchor == AnchorStyle.Right && FlowDirection == FlowDirection.RightToLeft)
            {
                CorrectedAnchor = AnchorStyle.Left;
            }


            //Let closing animation to occur
            //Here we get a reference to a storyboard resource with a name ClosingStoryboard and
            //wait that it completes before closing the window
            FrameworkElement targetElement = GetTemplateChild("INT_pane") as FrameworkElement;

            if (targetElement != null)
            {
                Storyboard storyBoard = new Storyboard();

                if (CorrectedAnchor == AnchorStyle.Left || CorrectedAnchor == AnchorStyle.Right)
                {
                    DoubleAnimation anim = new DoubleAnimation(this.ActualWidth, 0.0, new Duration(TimeSpan.FromMilliseconds(500)));
                    Storyboard.SetTargetProperty(anim, new PropertyPath("Width"));
                    storyBoard.Children.Add(anim);
                }
                if (CorrectedAnchor == AnchorStyle.Right)
                {
                    DoubleAnimation anim = new DoubleAnimation(this.Left, this.Left + this.ActualWidth, new Duration(TimeSpan.FromMilliseconds(500)));
                    Storyboard.SetTargetProperty(anim, new PropertyPath("Left"));
                    storyBoard.Children.Add(anim);
                }
                if (CorrectedAnchor == AnchorStyle.Top || CorrectedAnchor == AnchorStyle.Bottom)
                {
                    DoubleAnimation anim = new DoubleAnimation(this.Height, 0.0, new Duration(TimeSpan.FromMilliseconds(500)));
                    Storyboard.SetTargetProperty(anim, new PropertyPath("Height"));
                    storyBoard.Children.Add(anim);
                }
                if (CorrectedAnchor == AnchorStyle.Bottom)
                {
                    DoubleAnimation anim = new DoubleAnimation(this.Top, this.Top + this.Height, new Duration(TimeSpan.FromMilliseconds(500)));
                    Storyboard.SetTargetProperty(anim, new PropertyPath("Top"));
                    storyBoard.Children.Add(anim);
                }

                {
                    //DoubleAnimation anim = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromMilliseconds(500)));
                    //Storyboard.SetTargetProperty(anim, new PropertyPath("Opacity"));
                    //AllowsTransparency slow down perfomance under XP/VISTA because rendering is enterely perfomed using CPU
                    //storyBoard.Children.Add(anim);
                }

                storyBoard.Completed += (animation, eventArgs) =>
                {
                    if (!IsClosed)
                    {
                        Close();
                    }
                };

                foreach (AnimationTimeline animTimeLine in storyBoard.Children)
                {
                    animTimeLine.FillBehavior = FillBehavior.Stop;
                }

                storyBoard.Begin(this);
            }
        }
Beispiel #16
0
 /// <summary>
 /// Show <see cref="DockableContent"/> as docked pane
 /// </summary>
 /// <param name="desideredAnchor">Desidered anchor position</param>
 public void Show(AnchorStyle desideredAnchor)
 {
     Show(Manager, desideredAnchor);
 }
        private void _resizer_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            UIElement dragElement = sender as UIElement;

            if (dragElement.IsMouseCaptured)
            {
                Point       ptMoveDrag      = e.GetPosition(dragElement);
                AnchorStyle CorrectedAnchor = Anchor;

                if (CorrectedAnchor == AnchorStyle.Left && FlowDirection == FlowDirection.RightToLeft)
                {
                    CorrectedAnchor = AnchorStyle.Right;
                }
                else if (CorrectedAnchor == AnchorStyle.Right && FlowDirection == FlowDirection.RightToLeft)
                {
                    CorrectedAnchor = AnchorStyle.Left;
                }

                double deltaX = FlowDirection == FlowDirection.LeftToRight ? ptMoveDrag.X - ptStartDrag.X : ptStartDrag.X - ptMoveDrag.X;

                double newWidth  = Width;
                double newHeight = Height;

                double newLeft = Left;
                double newTop  = Top;

                if (CorrectedAnchor == AnchorStyle.Left)
                {
                    if (newWidth + deltaX < 4.0)
                    {
                        newWidth = 4.0;
                    }
                    else
                    {
                        newWidth += deltaX;
                    }
                }
                else if (CorrectedAnchor == AnchorStyle.Top)
                {
                    if (newHeight + (ptMoveDrag.Y - ptStartDrag.Y) < 4.0)
                    {
                        newHeight = 4.0;
                    }
                    else
                    {
                        newHeight += ptMoveDrag.Y - ptStartDrag.Y;
                    }
                }
                else if (CorrectedAnchor == AnchorStyle.Right)
                {
                    if (newWidth - (deltaX) < 4)
                    {
                        newLeft  = originalLeft + originalWidth - 4;
                        newWidth = 4;
                    }
                    else
                    {
                        newLeft  += deltaX;
                        newWidth -= deltaX;
                    }
                }
                else if (CorrectedAnchor == AnchorStyle.Bottom)
                {
                    if (newHeight - (ptMoveDrag.Y - ptStartDrag.Y) < 4)
                    {
                        newTop    = originalTop + originalHeight - 4;
                        newHeight = 4;
                    }
                    else
                    {
                        newTop    += ptMoveDrag.Y - ptStartDrag.Y;
                        newHeight -= ptMoveDrag.Y - ptStartDrag.Y;
                    }
                }

                //ResizingPanel.SetResizeHeight(ReferencedPane, ReferencedPane.ActualHeight);
                //ResizingPanel.SetResizeWidth(ReferencedPane, ReferencedPane.ActualWidth);

                Width  = Math.Min(newWidth, MaxWidth);
                Height = Math.Min(newHeight, MaxHeight);

                Left = Math.Max(newLeft, MinLeft);
                Top  = Math.Max(newTop, MinTop);

                ApplyRegion(new Rect(0, 0, this.Width, this.Height));
            }
        }
Beispiel #18
0
        public override object GetValue(object component)
        {
            try
            {
                if (this.property is Property <MousePointers> )
                {
                    return(((Property <MousePointers>) this.property).Value);
                }
                else if (property is PropertyColor)
                {
                    ThW.UI.Utils.Color c = (ThW.UI.Utils.Color)((PropertyColor)this.property).Value;

                    if (null == c)
                    {
                        return(System.Drawing.Color.FromArgb(0));
                    }
                    else
                    {
                        return(System.Drawing.Color.FromArgb((int)(c.A * 255), (int)(c.R * 255), (int)(c.G * 255), (int)(c.B * 255)));
                    }
                }
                else if (this.property is PropertyFont)
                {
                    PropertyFont propertyFont = (PropertyFont)this.property;

                    FontInfo font = this.control.FontInfo;

                    FontStyle style = FontStyle.Regular;

                    if (true == font.Bold)
                    {
                        style |= FontStyle.Bold;
                    }

                    if (true == font.Italic)
                    {
                        style |= FontStyle.Italic;
                    }
                    try
                    {
                        return(new Font(font.Name, (float)font.Size, style));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                        return(new Font(font.Name, (float)font.Size));
                    }
                }
                else if (this.property is PropertyAnchor)
                {
                    AnchorStyle s = (AnchorStyle)this.property.Value;

                    AnchorStyles result = AnchorStyles.None;

                    if ((s & AnchorStyle.AnchorTop) > 0)
                    {
                        result |= AnchorStyles.Top;
                    }

                    if ((s & AnchorStyle.AnchorLeft) > 0)
                    {
                        result |= AnchorStyles.Left;
                    }

                    if ((s & AnchorStyle.AnchorRight) > 0)
                    {
                        result |= AnchorStyles.Right;
                    }

                    if ((s & AnchorStyle.AnchorBottom) > 0)
                    {
                        result |= AnchorStyles.Bottom;
                    }

                    return(result);
                }
                else if (null != this.property.Value)
                {
                    return(this.property.Value);
                }
                else
                {
                    return("");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return("");
            }
        }
 /// <summary>
 /// Provides a secure method for setting the Anchor property.
 /// This dependency property indicates the achor style of referenced content that is in autohidden state.
 /// </summary>
 /// <param name="value">The new value for the property.</param>
 protected void SetAnchor(AnchorStyle value)
 {
     SetValue(AnchorPropertyKey, value);
 }
Beispiel #20
0
        /// <summary>
        /// Show a dockable content in its container with a desidered state
        /// </summary>
        /// <param name="content">Content to show</param>
        /// <param name="desideredState">State desidered</param>
        /// <param name="desideredAnchor">Border to which anchor the newly created container pane</param>
        /// <remarks></remarks>
        internal void Show(DockableContent content, DockableContentState desideredState, AnchorStyle desideredAnchor)
        {
            Debug.WriteLine(string.Format("Show Content={0}, desideredState={1}, desideredAnchor={2}", content.Name, desideredState, desideredAnchor));

            #region Dockable content

            if (desideredState == DockableContentState.Hidden)//??!!show hidden?
                Hide(content);

            if (content.State == DockableContentState.AutoHide)
            {
                //first redock the content
                (content.ContainerPane as DockablePane).ToggleAutoHide();
                //then show it as desidered
                Show(content, desideredState, desideredAnchor);
            }
            else if (content.State == DockableContentState.Docked ||
                content.State == DockableContentState.Document ||
                content.State == DockableContentState.None)
            {
                if (content.ContainerPane == null ||
                    content.State == DockableContentState.None)
                {
                    //Problem!? try to rescue
                    if (content.State == DockableContentState.Docked ||
                        content.State == DockableContentState.None)
                    {
                        //find the the pane which the desidered anchor style
                        //DockablePane foundPane = this.FindChildDockablePane(desideredAnchor != AnchorStyle.None ? desideredAnchor : AnchorStyle.Right);
                        //first search for a pane with other contents (avoiding empty panes which are containers for hidden contents)
                        ILinqToTree<DependencyObject> itemFound = new LogicalTreeAdapter(this).Descendants().FirstOrDefault(el => el.Item is DockablePane && (el.Item as DockablePane).Anchor == desideredAnchor && (el.Item as DockablePane).IsDocked);

                        if (itemFound == null)//search for all panes (even empty)
                            itemFound = new LogicalTreeAdapter(this).Descendants().FirstOrDefault(el => el.Item is DockablePane && (el.Item as DockablePane).Anchor == desideredAnchor && (el.Item as DockablePane).Items.Count == 0);

                        DockablePane foundPane = itemFound != null ? itemFound.Item as DockablePane : null;

                        if (foundPane != null)
                        {
                            content.SetStateToDock();
                            foundPane.Items.Add(content);
                            var containerPanel = foundPane.Parent as ResizingPanel;
                            if (containerPanel != null)
                                containerPanel.InvalidateMeasure();
                        }
                        else
                        {
                            //if no suitable pane was found create e new one on the fly
                            if (content.ContainerPane != null)
                            {
                                content.ContainerPane.RemoveContent(content);
                            }

                            DockablePane pane = new DockablePane();
                            pane.Items.Add(content);
                            Anchor(pane, desideredAnchor);
                        }
                    }
                    else
                    {
                        //add to main document pane
                        MainDocumentPane.Items.Add(content);
                    }

                }

                if (content.ContainerPane.GetManager() == null)
                {
                    //disconnect the parent pane from previous panel
                    //((Panel)content.ContainerPane.Parent).Children.Remove(content.ContainerPane);
                    if (content.ContainerPane.Parent != null)
                    {
                        ((Panel)content.ContainerPane.Parent).Children.Remove(content.ContainerPane);
                    }

                    Anchor(content.ContainerPane as DockablePane, desideredAnchor);
                }

                if (desideredState == DockableContentState.DockableWindow ||
                     desideredState == DockableContentState.FloatingWindow)
                {
                    var floatingWindow = new DockableFloatingWindow(this);
                    floatingWindow.Content = content;

                    var mainWindow = Window.GetWindow(this);
                    if (mainWindow.IsVisible)
                        floatingWindow.Owner = mainWindow;

                    //floatingWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;
                    //if (content.Content != null)
                    //{
                    //    floatingWindow.Width = Math.Min(((FrameworkElement)content.Content).ActualWidth, ResizingPanel.GetResizeWidth(content.ContainerPane));
                    //    floatingWindow.Height = Math.Min(((FrameworkElement)content.Content).ActualHeight, ResizingPanel.GetResizeHeight(content.ContainerPane));
                    //}
                    //else
                    ////{
                    //    floatingWindow.Width = 400;
                    //    floatingWindow.Height = 400;
                    //}

                    floatingWindow.Show();

                }
                else if (desideredState == DockableContentState.AutoHide)
                {
                    var paneContainer = content.ContainerPane as DockablePane;
                    Debug.Assert(paneContainer != null);

                    if (paneContainer != null)
                        paneContainer.ToggleAutoHide();

                    content.Activate();
                }
                else if (desideredState == DockableContentState.Document)
                {
                    DocumentPane docPane = MainDocumentPane;
                    if (docPane != null)
                    {
                        docPane.Items.Add(content.DetachFromContainerPane());
                        docPane.SelectedItem = content;
                        content.SetStateToDocument();
                    }
                }
                else
                {
                    content.ContainerPane.SelectedItem = content;
                    content.Activate();

                    DockablePane dockParent = content.ContainerPane as DockablePane;
                    if (content.ActualWidth == 0.0 && (
                        dockParent.Anchor == AnchorStyle.Left || dockParent.Anchor == AnchorStyle.Right))
                    {
                        ResizingPanel.SetResizeWidth(dockParent, new GridLength(200));
                        ResizingPanel.SetEffectiveSize(dockParent, new Size(200, 0.0));
                    }
                    else if (content.ActualWidth == 0.0 && (
                        dockParent.Anchor == AnchorStyle.Top || dockParent.Anchor == AnchorStyle.Bottom))
                    {
                        ResizingPanel.SetResizeHeight(dockParent, new GridLength(200));
                        ResizingPanel.SetEffectiveSize(dockParent, new Size(200, 0.0));
                    }

                }
            }
            else if (content.State == DockableContentState.Document)
            {
                if (content.ContainerPane != null)
                    content.ContainerPane.SelectedItem = this;
                content.Activate();
            }
            else if (content.State == DockableContentState.Hidden ||
                content.State == DockableContentState.DockableWindow ||
                content.State == DockableContentState.FloatingWindow)
            {
                if (content.State == DockableContentState.Hidden)
                {
                    //Debug.Assert(HiddenContents.Contains(content));
                    //HiddenContents.Remove(content);
                }
                else
                {
                    FloatingWindow floatingWindow = null;
                    floatingWindow = (content.ContainerPane as FloatingDockablePane).FloatingWindow;
                    content.DetachFromContainerPane();

                    if (floatingWindow.HostedPane.Items.Count == 0)
                        floatingWindow.Close();
                }

                if (desideredState == DockableContentState.Docked ||
                    desideredState == DockableContentState.AutoHide)
                {

                    if (content.SavedStateAndPosition != null &&
                        content.SavedStateAndPosition.ContainerPane != null &&
                        content.SavedStateAndPosition.ChildIndex >= 0 &&
                        content.SavedStateAndPosition.ContainerPane.GetManager() == this &&
                        desideredState == DockableContentState.Docked)
                    {
                        //ok previous container pane is here..
                        Pane prevPane = content.SavedStateAndPosition.ContainerPane;

                        if (content.SavedStateAndPosition.ChildIndex < prevPane.Items.Count)
                        {
                            prevPane.Items.Insert(content.SavedStateAndPosition.ChildIndex, content);
                        }
                        else
                        {
                            prevPane.Items.Add(content);
                        }

                        if (prevPane.Items.Count == 1)
                        {
                            if (!double.IsNaN(content.SavedStateAndPosition.Width) ||
                                !double.IsInfinity(content.SavedStateAndPosition.Width))
                            {
                                ResizingPanel.SetResizeWidth(content,
                                    new GridLength(content.SavedStateAndPosition.Width));
                            }
                        }

                        DockablePane prevDockablePane = prevPane as DockablePane;
                        if (prevDockablePane != null && prevDockablePane.IsAutoHidden)
                        {
                            prevDockablePane.ToggleAutoHide();
                        }

                        content.SetStateToDock();
                        content.Activate();

                        (prevPane.Parent as UIElement).InvalidateMeasure();
                    }
                    else
                    {
                        if (desideredAnchor == AnchorStyle.None &&
                            content.SavedStateAndPosition != null &&
                            content.SavedStateAndPosition.Anchor != AnchorStyle.None)
                            desideredAnchor = content.SavedStateAndPosition.Anchor;

                        if (desideredAnchor == AnchorStyle.None)
                            desideredAnchor = AnchorStyle.Right;

                        DockablePane foundPane = null;

                        if (desideredState == DockableContentState.Docked)
                        {
                            //first not empty panes
                            ILinqToTree<DependencyObject> itemFound = new LogicalTreeAdapter(this).Descendants().FirstOrDefault(el => el.Item is DockablePane && (el.Item as DockablePane).Anchor == desideredAnchor && (el.Item as DockablePane).IsDocked);

                            if (itemFound == null)//look for all panes even empty
                                itemFound = new LogicalTreeAdapter(this).Descendants().FirstOrDefault(el => el.Item is DockablePane && (el.Item as DockablePane).Anchor == desideredAnchor && (el.Item as DockablePane).Items.Count == 0);

                            foundPane = itemFound != null ? itemFound.Item as DockablePane : null;
                        }

                        if (foundPane != null)
                        {
                            content.SetStateToDock();
                            foundPane.Items.Add(content);

                            if ((foundPane.IsAutoHidden && desideredState == DockableContentState.Docked) ||
                                 (!foundPane.IsAutoHidden && desideredState == DockableContentState.AutoHide))
                                foundPane.ToggleAutoHide();
                        }
                        else
                        {
                            DockablePane newHostpane = new DockablePane();
                            newHostpane.Items.Add(content);

                            if (desideredAnchor == AnchorStyle.Left ||
                                desideredAnchor == AnchorStyle.Right)
                            {
                                double w = 200;
                                if (content.SavedStateAndPosition != null &&
                                    !double.IsInfinity(content.SavedStateAndPosition.Width) &&
                                    !double.IsNaN(content.SavedStateAndPosition.Width))
                                    w = content.SavedStateAndPosition.Width;

                                ResizingPanel.SetResizeWidth(newHostpane, new GridLength(w));
                                ResizingPanel.SetEffectiveSize(newHostpane, new Size(w, 0.0));
                            }
                            else
                            {
                                double h = 200;
                                if (content.SavedStateAndPosition != null &&
                                    !double.IsInfinity(content.SavedStateAndPosition.Height) &&
                                    !double.IsNaN(content.SavedStateAndPosition.Height))
                                    h = content.SavedStateAndPosition.Height;

                                ResizingPanel.SetResizeHeight(newHostpane, new GridLength(h));
                                ResizingPanel.SetEffectiveSize(newHostpane, new Size(0.0, h));
                            }

                            Anchor(newHostpane, desideredAnchor);

                            if (desideredState == DockableContentState.AutoHide)
                            {
                                ToggleAutoHide(newHostpane);
                            }
                        }
                    }

                    ActiveContent = content;
                }
                else if (desideredState == DockableContentState.DockableWindow ||
                    desideredState == DockableContentState.FloatingWindow)
                {
                    DockablePane newHostpane = null;
                    FloatingDockablePane prevHostpane = null;
                    if (content.SavedStateAndPosition != null && content.SavedStateAndPosition.ContainerPane != null && content.SavedStateAndPosition.ContainerPane is FloatingDockablePane)
                    {
                        prevHostpane = content.SavedStateAndPosition.ContainerPane as FloatingDockablePane;
                        if (!prevHostpane.Items.Contains(content))
                            prevHostpane.Items.Add(content);
                    }
                    else
                    {
                        newHostpane = new DockablePane();
                        newHostpane.Items.Add(content);

                    }

                    if (desideredState == DockableContentState.DockableWindow)
                        content.SetStateToDockableWindow();
                    else if (desideredState == DockableContentState.FloatingWindow)
                        content.SetStateToFloatingWindow();

                    if (prevHostpane != null)
                    {
                        //check to see if floating window that host prevHostPane is already loaded (hosting other contents)
                        var floatingWindow = prevHostpane.Parent as DockableFloatingWindow;
                        if (floatingWindow != null && floatingWindow.IsLoaded)
                        {
                            floatingWindow.Activate();
                        }
                        else
                        {
                            floatingWindow = new DockableFloatingWindow(this);
                            floatingWindow.Content = content;
                            floatingWindow.WindowStartupLocation = WindowStartupLocation.Manual;
                            floatingWindow.Top = prevHostpane.FloatingWindow.Top;
                            floatingWindow.Left = prevHostpane.FloatingWindow.Left;
                            floatingWindow.Width = prevHostpane.FloatingWindow.Width;
                            floatingWindow.Height = prevHostpane.FloatingWindow.Height;
                            //floatingWindow.Owner = Window.GetWindow(this);
                            var mainWindow = Window.GetWindow(this);
                            if (mainWindow.IsVisible)
                                floatingWindow.Owner = mainWindow;

                            //now I've created a new pane to host the hidden content
                            //if a an hidden content is shown that has prevHostpane as saved pane
                            //I want that it is relocated in this new pane that I've created right now
                            var hiddenContents = DockableContents.Where(c => c.State == DockableContentState.Hidden).ToArray();
                            foreach (var hiddenContent in hiddenContents)
                            {
                                if (hiddenContent.SavedStateAndPosition.ContainerPane == prevHostpane)
                                {
                                    hiddenContent.SavedStateAndPosition = new DockableContentStateAndPosition(
                                        (floatingWindow.Content as Pane),
                                        hiddenContent.SavedStateAndPosition.ChildIndex,
                                        hiddenContent.SavedStateAndPosition.Width,
                                        hiddenContent.SavedStateAndPosition.Height,
                                        hiddenContent.SavedStateAndPosition.Anchor,
                                        hiddenContent.SavedStateAndPosition.State);
                                }
                            }

                            floatingWindow.Show();
                        }
                    }
                    else if (newHostpane != null)
                    {
                        var floatingWindow = new DockableFloatingWindow(this);
                        floatingWindow.Content = newHostpane;
                        floatingWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        floatingWindow.Width = 200;
                        floatingWindow.Height = 500;
                        //floatingWindow.Owner = Window.GetWindow(this);
                        var mainWindow = Window.GetWindow(this);
                        if (mainWindow.IsVisible)
                            floatingWindow.Owner = mainWindow;

                        floatingWindow.Show();
                    }

                }
                else if (desideredState == DockableContentState.Document)
                {
                    DocumentPane docPane = MainDocumentPane;
                    if (docPane != null)
                    {
                        docPane.Items.Add(content);
                        docPane.SelectedItem = content;
                        content.SetStateToDocument();
                    }
                }
            }

               #endregion
        }
Beispiel #21
0
        void FlyoutPaneWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Storyboard storyBoard   = new Storyboard();
            double     originalLeft = this.Left;
            double     originalTop  = this.Top;

            AnchorStyle CorrectedAnchor = Anchor;

            if (CorrectedAnchor == AnchorStyle.Left && FlowDirection == FlowDirection.RightToLeft)
            {
                CorrectedAnchor = AnchorStyle.Right;
            }
            else if (CorrectedAnchor == AnchorStyle.Right && FlowDirection == FlowDirection.RightToLeft)
            {
                CorrectedAnchor = AnchorStyle.Left;
            }


            if (CorrectedAnchor == AnchorStyle.Left || CorrectedAnchor == AnchorStyle.Right)
            {
                DoubleAnimation anim = new DoubleAnimation(0.0, _targetWidth, new Duration(TimeSpan.FromMilliseconds(200)));
                Storyboard.SetTargetProperty(anim, new PropertyPath("Width"));
                storyBoard.Children.Add(anim);
            }
            if (CorrectedAnchor == AnchorStyle.Right)
            {
                //DoubleAnimation anim = new DoubleAnimation(this.Left, this.Left + this.ActualWidth, new Duration(TimeSpan.FromMilliseconds(500)));

                DoubleAnimation anim = new DoubleAnimation(this.Left, Left - _targetWidth, new Duration(TimeSpan.FromMilliseconds(200)));
                Storyboard.SetTargetProperty(anim, new PropertyPath("Left"));
                storyBoard.Children.Add(anim);
            }

            if (CorrectedAnchor == AnchorStyle.Top || CorrectedAnchor == AnchorStyle.Bottom)
            {
                DoubleAnimation anim = new DoubleAnimation(0.0, _targetHeight, new Duration(TimeSpan.FromMilliseconds(200)));
                Storyboard.SetTargetProperty(anim, new PropertyPath("Height"));
                storyBoard.Children.Add(anim);
            }
            if (CorrectedAnchor == AnchorStyle.Bottom)
            {
                DoubleAnimation anim = new DoubleAnimation(originalTop, originalTop - _targetHeight, new Duration(TimeSpan.FromMilliseconds(200)));
                Storyboard.SetTargetProperty(anim, new PropertyPath("Top"));
                storyBoard.Children.Add(anim);
            }

            {
                DoubleAnimation anim = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromMilliseconds(100)));
                Storyboard.SetTargetProperty(anim, new PropertyPath("Opacity"));
                //AllowsTransparency slow down perfomance under XP/VISTA because rendering is enterely perfomed using CPU
                //storyBoard.Children.Add(anim);
            }

            storyBoard.Completed += (anim, eventargs) =>
            {
                if (CorrectedAnchor == AnchorStyle.Left)
                {
                    this.Left  = originalLeft;
                    this.Width = _targetWidth;
                }
                if (CorrectedAnchor == AnchorStyle.Right)
                {
                    this.Left  = originalLeft - _targetWidth;
                    this.Width = _targetWidth;
                }
                if (CorrectedAnchor == AnchorStyle.Top)
                {
                    this.Top    = originalTop;
                    this.Height = _targetHeight;
                }
                if (CorrectedAnchor == AnchorStyle.Bottom)
                {
                    this.Top    = originalTop - _targetHeight;
                    this.Height = _targetHeight;
                }
            };

            foreach (AnimationTimeline animTimeLine in storyBoard.Children)
            {
                animTimeLine.FillBehavior = FillBehavior.Stop;
            }

            storyBoard.Begin(this);
        }
Beispiel #22
0
 /// <summary>
 /// Called by <see cref="UpdateAnchorStyle"/> whene a <see cref="DocumentContent"/> object has been found
 /// </summary>
 /// <param name="panel"></param>
 /// <param name="forcedAnchor"></param>
 void ForceAnchorStyle(ResizingPanel panel, AnchorStyle forcedAnchor)
 {
     foreach (FrameworkElement child in panel.Children)
     {
         if (child is ResizingPanel)
         {
             ForceAnchorStyle((child as ResizingPanel), forcedAnchor);
         }
         else if ((child is DockablePane))
         {
             ((DockablePane)child).Anchor = forcedAnchor;
         }
     }
 }
       public DockableContentStateAndPosition(
            DockableContent cntToSave)
        {
            ContainerPane = cntToSave.ContainerPane;
            ChildIndex = ContainerPane.Items.IndexOf(cntToSave);
            Width = Math.Max(ContainerPane.ActualWidth, 100.0);
            Height = Math.Max(ContainerPane.ActualHeight, 100.0);
            State = cntToSave.State;

            DockablePane dockablePane = ContainerPane as DockablePane;
            if (dockablePane != null)
            {
                Anchor = dockablePane.Anchor;
            }
        }
Beispiel #24
0
        /// <summary>
        /// Anchor a pane (<see cref="DockablePane"/> and <see cref="DocumentPane"/>) to a border of a another pane
        /// </summary>
        /// <param name="paneToAnchor">Pane to anchor</param>
        /// <param name="relativePane">Pane relative</param>
        /// <param name="anchor">Position relative to the target pane</param>
        public void Anchor(Pane paneToAnchor, Pane relativePane, AnchorStyle anchor)
        {
            //ensure that content property is not empty
            EnsureContentNotEmpty();

            if (anchor == AnchorStyle.None)
                anchor = AnchorStyle.Right;

            //Change anchor border according to FlowDirection
            if (FlowDirection == FlowDirection.RightToLeft)
            {
                if (anchor == AnchorStyle.Right)
                    anchor = AnchorStyle.Left;
                else if (anchor == AnchorStyle.Left)
                    anchor = AnchorStyle.Right;
            }

            if (paneToAnchor is DockablePane &&
                relativePane is DockablePane)
                Anchor(paneToAnchor as DockablePane, relativePane as DockablePane, anchor);
            else if (paneToAnchor is DockablePane &&
                relativePane is DocumentPane)
                Anchor(paneToAnchor as DockablePane, relativePane as DocumentPane, anchor);
            else if (paneToAnchor is DocumentPane &&
                relativePane is DocumentPane)
                Anchor(paneToAnchor as DocumentPane, relativePane as DocumentPane, anchor);
            else
                throw new InvalidOperationException();

            CheckForSingleChildPanels();
        }
 /// <summary>
 /// Show <see cref="DockableContent"/> as docked pane
 /// </summary>
 /// <param name="desideredAnchor">Desidered anchor position</param>
 public void Show(AnchorStyle desideredAnchor)
 {
     Show(Manager, desideredAnchor);
 }
Beispiel #26
0
        /// <summary>
        /// Anchor a dockable pane (<see cref="DockablePane"/>) to a border of an other dockable pane
        /// </summary>
        /// <param name="paneToAnchor">Pane to anchor</param>
        /// <param name="relativePane">Pane relative</param>
        /// <param name="anchor"></param>
        public void Anchor(DockablePane paneToAnchor, DockablePane relativePane, AnchorStyle anchor)
        {
            //ensure that content property is not empty
            EnsureContentNotEmpty();

            if (anchor == AnchorStyle.None)
                anchor = AnchorStyle.Right;

            //get a refernce to the resizingpanel container of relativePane
            ResizingPanel relativePaneContainer = LogicalTreeHelper.GetParent(relativePane) as ResizingPanel;
            Orientation requestedOrientation =
                (anchor == AnchorStyle.Bottom || anchor == AnchorStyle.Top) ? Orientation.Vertical : Orientation.Horizontal;

            if (relativePaneContainer == null)
            {
                Debug.Assert(relativePane.Parent == this);

                relativePaneContainer = new ResizingPanel();
                relativePaneContainer.Orientation = requestedOrientation;
                this.Content = relativePaneContainer;
                relativePaneContainer.Children.Add(relativePane);
            }

            Debug.Assert(relativePaneContainer != null, "By now we can't have a pane without a resizing panel containing it");

            #region Create and setup container panel
            if (relativePaneContainer != null)
            {
                //check if orientation is right
                if (relativePaneContainer.Orientation != requestedOrientation)
                {
                    //if the existing panel is not oriented as we want
                    //create a new one
                    ResizingPanel newPanel = new ResizingPanel();
                    newPanel.Orientation = requestedOrientation;

                    if (newPanel.Orientation == Orientation.Horizontal)
                        ResizingPanel.SetResizeHeight(newPanel, ResizingPanel.GetResizeHeight(relativePane));
                    else
                        ResizingPanel.SetResizeWidth(newPanel, ResizingPanel.GetResizeWidth(relativePane));

                    //replace relative pane in its' container panel
                    //with this new panel
                    int indexofRelativePane = relativePaneContainer.Children.IndexOf(relativePane);
                    relativePaneContainer.Children.Remove(relativePane);
                    relativePaneContainer.Children.Insert(indexofRelativePane, newPanel);

                    //now we have a panel correctly placed in the tree
                    newPanel.Children.Add(relativePane);
                    newPanel.InsertChildRelativeTo(
                        paneToAnchor, relativePane, anchor == AnchorStyle.Right || anchor == AnchorStyle.Bottom);

                    relativePaneContainer = newPanel;
                }
                else
                {
                    if (anchor == AnchorStyle.Left ||
                        anchor == AnchorStyle.Top)
                    {
                        //add new child before first (prepend)
                        relativePaneContainer.InsertChildRelativeTo(paneToAnchor,
                            relativePane, false);
                    }
                    else
                    {
                        //add new child after last (append)
                        relativePaneContainer.InsertChildRelativeTo(paneToAnchor,
                            relativePane, true);
                    }
                }

                relativePaneContainer.InvalidateMeasure();
            }
            #endregion

            //than set the new anchor style for the pane
            paneToAnchor.Anchor = relativePane.Anchor;

            if (anchor == AnchorStyle.Left ||
                anchor == AnchorStyle.Right)
            {
                double w = Math.Min(
                    ResizingPanel.GetEffectiveSize(relativePane).Width / 2.0,
                    ResizingPanel.GetEffectiveSize(paneToAnchor).Width);
                ResizingPanel.SetResizeWidth(paneToAnchor, new GridLength(w, GridUnitType.Pixel));
                ResizingPanel.SetResizeHeight(paneToAnchor, new GridLength(1.0, GridUnitType.Star));
            }
            else
            {
                double h = Math.Min(
                    ResizingPanel.GetEffectiveSize(relativePane).Height / 2.0,
                    ResizingPanel.GetEffectiveSize(paneToAnchor).Height);
                ResizingPanel.SetResizeWidth(paneToAnchor, new GridLength(1.0, GridUnitType.Star));
                ResizingPanel.SetResizeHeight(paneToAnchor, new GridLength(h, GridUnitType.Pixel));
            }

            //refresh contents state
            foreach (DockableContent draggedContent in paneToAnchor.Items)
            {
                draggedContent.SetStateToDock();
            }

            if (relativePaneContainer != null)
                relativePaneContainer.AdjustPanelSizes();

            //paneToAnchor.Focus();
        }
        internal void StartOpenAnimation()
        {
            AnchorStyle CorrectedAnchor = Anchor;

            if (CorrectedAnchor == AnchorStyle.Left && FlowDirection == FlowDirection.RightToLeft)
            {
                CorrectedAnchor = AnchorStyle.Right;
            }
            else if (CorrectedAnchor == AnchorStyle.Right && FlowDirection == FlowDirection.RightToLeft)
            {
                CorrectedAnchor = AnchorStyle.Left;
            }

            double wnd_Width  = this._targetWidth > 0.0 ? this._targetWidth : this.ActualWidth;
            double wnd_Height = this._targetHeight > 0.0 ? this._targetHeight : this.ActualHeight;
            double wnd_Left   = this.Left;
            double wnd_Top    = this.Top;


            int wnd_TrimWidth  = 0;
            int wnd_TrimHeight = 0;

            int stepWidth  = (int)(wnd_Width / 8);
            int stepHeight = (int)(wnd_Height / 8);

            if (CorrectedAnchor == AnchorStyle.Left)
            {
                SetWindowRgn(new WindowInteropHelper(this).Handle, CreateRectRgn(0, 0, 0, (int)wnd_Height - wnd_TrimHeight), true);
                this.Left = wnd_Left - wnd_Width;
            }
            else if (CorrectedAnchor == AnchorStyle.Top)
            {
                SetWindowRgn(new WindowInteropHelper(this).Handle, CreateRectRgn(0, 0, (int)wnd_Width - wnd_TrimWidth, 0), true);
                this.Top = wnd_Top - wnd_Height;
            }

            DispatcherTimer animTimer = new DispatcherTimer();

            animTimer.Interval = TimeSpan.FromMilliseconds(2);

            animTimer.Tick += (sender, eventArgs) =>
            {
                bool stopTimer = false;
                switch (CorrectedAnchor)
                {
                case AnchorStyle.Right:
                    double newLeft = this.Left;
                    if (this.Left - stepWidth <= wnd_Left - wnd_Width)
                    {
                        newLeft       = wnd_Left - wnd_Width;
                        wnd_TrimWidth = (int)wnd_Width;
                        stopTimer     = true;
                    }
                    else
                    {
                        newLeft       -= stepWidth;
                        wnd_TrimWidth += stepWidth;
                    }

                    //SetWindowRgn(new WindowInteropHelper(this).Handle, CreateRectRgn(0, 0, wnd_TrimWidth, (int)wnd_Height - wnd_TrimHeight), true);
                    Width     = _targetWidth;
                    this.Left = newLeft;
                    ApplyRegion(new Rect(0, 0, wnd_TrimWidth, (int)wnd_Height - wnd_TrimHeight));
                    break;

                case AnchorStyle.Left:
                    if (this.Left + stepWidth >= wnd_Left)
                    {
                        this.Left     = wnd_Left;
                        wnd_TrimWidth = (int)wnd_Width;
                        stopTimer     = true;
                    }
                    else
                    {
                        this.Left     += stepWidth;
                        wnd_TrimWidth += stepWidth;
                    }

                    //SetWindowRgn(new WindowInteropHelper(this).Handle, CreateRectRgn((int)(wnd_Left - this.Left), 0, (int)(wnd_Width), (int)wnd_Height - wnd_TrimHeight), true);
                    ApplyRegion(
                        new Rect((int)(wnd_Left - this.Left), 0, (int)(wnd_Width), (int)wnd_Height - wnd_TrimHeight));
                    Width = _targetWidth;
                    break;

                case AnchorStyle.Bottom:
                    double newTop = this.Top;
                    if (this.Top - stepHeight <= wnd_Top - wnd_Height)
                    {
                        newTop         = wnd_Top - wnd_Height;
                        wnd_TrimHeight = (int)wnd_Height;
                        stopTimer      = true;
                    }
                    else
                    {
                        newTop         -= stepHeight;
                        wnd_TrimHeight += stepHeight;
                    }

                    //SetWindowRgn(new WindowInteropHelper(this).Handle, CreateRectRgn(0, 0, (int)wnd_Width - wnd_TrimWidth, wnd_TrimHeight), true);
                    ApplyRegion(
                        new Rect(0, 0, (int)wnd_Width - wnd_TrimWidth, wnd_TrimHeight));

                    Height   = _targetHeight;
                    this.Top = newTop;
                    break;

                case AnchorStyle.Top:
                    if (this.Top + stepHeight >= wnd_Top)
                    {
                        this.Top       = wnd_Top;
                        wnd_TrimHeight = (int)wnd_Height;
                        stopTimer      = true;
                    }
                    else
                    {
                        this.Top       += stepHeight;
                        wnd_TrimHeight += stepHeight;
                    }

                    //SetWindowRgn(new WindowInteropHelper(this).Handle, CreateRectRgn(0, (int)(wnd_Top - this.Top), (int)wnd_Width - wnd_TrimWidth, (int)(wnd_Height)), true);
                    ApplyRegion(
                        new Rect(0, (int)(wnd_Top - this.Top), (int)wnd_Width - wnd_TrimWidth, (int)(wnd_Height)));

                    Height = _targetHeight;
                    break;
                }

                if (stopTimer)
                {
                    //SetWindowRgn(new WindowInteropHelper(this).Handle, IntPtr.Zero, false);
                    UpdateClipRegion();
                    animTimer.Stop();
                    IsOpening = false;
                }
            };

            IsOpening = true;
            animTimer.Start();
        }
 public DockableContentStateAndPosition(
     Guid containerPaneID,
     int childIndex,
     double width,
     double height,
     AnchorStyle anchor,
     DockableContentState state)
 {
     ContainerPaneID = containerPaneID;
     ChildIndex = childIndex;
     Width = Math.Max(width, 100.0);
     Height = Math.Max(height, 100.0);
     Anchor = anchor;
     State = state;
 }
Beispiel #29
0
        private void UpdateStateFromUI(Control sender, EventArgs args)
        {
            this.selectedAnchor = 0;

            if (true == this.top.Checked)
            {
                this.selectedAnchor |= AnchorStyle.AnchorTop;
            }

            if (true == this.bottom.Checked)
            {
                this.selectedAnchor |= AnchorStyle.AnchorBottom;
            }

            if (true == this.left.Checked)
            {
                this.selectedAnchor |= AnchorStyle.AnchorLeft;
            }

            if (true == this.right.Checked)
            {
                this.selectedAnchor |= AnchorStyle.AnchorRight;
            }
        }