Beispiel #1
0
        private void MouseClickEnd(System.Windows.Input.MouseButtonEventArgs e)
        {
            if (designerItem.ParentID == Guid.Empty)//common widget
            {
                e.Handled = false;
                designerItem.OnPageChildMouseUp();
                bIsMousePressMove = false;
            }
            else//group children
            {
                e.Handled = false;
                designerItem.OnGroupChildMouseUp();
                bIsMousePressMove = false;
            }

            #region handle Hamburger Menu Eidtor
            //shift/control key down, close hamburger menu  edit UI
            if ((Keyboard.Modifiers & (ModifierKeys.Shift | ModifierKeys.Control)) != ModifierKeys.None)
            {
                _selectionService.GetCurrentPage().CancelEditHamburgerPage();
            }
            else
            {
                //click hamburger, open edit hamburger menu  edit UI.
                WidgetViewModBase widgetVM = designerItem.DataContext as WidgetViewModBase;
                if (widgetVM != null && widgetVM.Type == ObjectType.HamburgerMenu)
                {
                    _selectionService.GetCurrentPage().EditHanburgerPage();
                }
            }
            #endregion
            return;
        }
        private void SelectionPageChangeEventHandler(Guid EventArg)
        {
            FirePropertyChanged("Top");
            FirePropertyChanged("Left");
            FirePropertyChanged("Width");
            FirePropertyChanged("Height");
            FirePropertyChanged("Content");
            FirePropertyChanged("RotateAngle");
            // FirePropertyChanged("Name");
            // FirePropertyChanged("Type");
            FirePropertyChanged("Opacity");
            FirePropertyChanged("IsHidden");
            FirePropertyChanged("ImgSource");
            FirePropertyChanged("Tooltip");

            ISelectionService _selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();
            IPagePropertyData page = _selectionService.GetCurrentPage();

            if (page == null)
            {
                return;
            }
            if (CmdTarget == page.EditorCanvas)
            {
                return;
            }
            CmdTarget = _selectionService.GetCurrentPage().EditorCanvas;
        }
Beispiel #3
0
        private void SelectionPageChangeEventHandler(Guid EventArg)
        {
            FirePropertyChanged("Top");
            FirePropertyChanged("Left");
            FirePropertyChanged("Width");
            FirePropertyChanged("Height");
            FirePropertyChanged("RotateAngle");
            FirePropertyChanged("CornerRadius");
            FirePropertyChanged("Opacity");
            FirePropertyChanged("IsHidden");
            FirePropertyChanged("IsFixed");
            FirePropertyChanged("IsFixedEnabled");
            FirePropertyChanged("TextRotate");

            //Fire Color
            //FirePropertyChanged("BackgroundColorView");
            ////FirePropertyChanged("BackgroundColor32");
            //FirePropertyChanged("FontColorView");
            //FirePropertyChanged("BorderLineColorView");
            GalleryData <StyleColor> cdata = _dataCollection["Background Color Gallery"] as GalleryData <StyleColor>;

            if (cdata != null)
            {
                cdata.SelectedItem = BackgroundColorView;
            }

            var Bdata = _dataCollection["Font Color Gallery"] as GalleryData <Brush>;

            if (Bdata != null)
            {
                Bdata.SelectedItem = FontColorView;
            }

            cdata = _dataCollection["BorderLine Color Gallery"] as GalleryData <StyleColor>;
            if (cdata != null)
            {
                cdata.SelectedItem = BorderLineColorView;
            }

            _selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();
            IPagePropertyData page = _selectionService.GetCurrentPage();

            if (page == null)
            {
                return;
            }
            if (CmdTarget == page.EditorCanvas)
            {
                return;
            }
            CmdTarget = _selectionService.GetCurrentPage().EditorCanvas;

            SetStyleCmdTarget(_selectionService.GetCurrentPage().EditorCanvas);

            UpdateCmdTarget(CmdTarget);
        }
Beispiel #4
0
        private void MoveThumb_DragStarted(object sender, DragStartedEventArgs e)
        {
            _isMousePressMove = false;
            ISelectionService selectService = ServiceLocator.Current.GetInstance <ISelectionService>();

            _page = selectService.GetCurrentPage();
        }
        private void WdgMgrHideSelectioHandler(object parameter)
        {
            WDMgrHideStatusChangeInfo info = (WDMgrHideStatusChangeInfo)parameter;

            if (info == null)
            {
                return;
            }
            ISelectionService   selsrv = ServiceLocator.Current.GetInstance <ISelectionService>();
            PageEditorViewModel page   = selsrv.GetCurrentPage() as PageEditorViewModel;

            if (page != null && page.ActivePage.Guid == info.PageID)
            {
                if (info.HideType == WDMgrHideEventEnum.NormalWidget)
                {
                    page.WdgMgrHideSelection(!info.HideFlag);
                }
                else if (info.HideType == WDMgrHideEventEnum.SwipeViewPanel)
                {
                    page.WdgMgrHideAllWidgets(!info.HideFlag);
                    _ListEventAggregator.GetEvent <SwipePanelHidddenEvent>().Publish(parameter);
                }
                else if (info.HideType == WDMgrHideEventEnum.ChildGroup)
                {
                    //
                }
            }
        }
Beispiel #6
0
        internal CheckAllTargetCommand(InteractionTabVM tabVM, Guid targetWidgetGuid, bool checkAll)
        {
            _tabVM    = tabVM;
            _checkAll = checkAll;

            if (_checkAll)
            {
                _list = new List <Guid>();
                // Only store target list if check all is checked.
                foreach (WidgetNode node in _tabVM.WidgetList)
                {
                    if (node.IsSelected)
                    {
                        _list.Add(node.TargetObject.Guid);
                    }
                }
            }

            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();

            if (selectionService != null)
            {
                _pageVM = selectionService.GetCurrentPage();
                if (_pageVM != null)
                {
                    IWidgetPropertyData widgetVM = _pageVM.GetSelectedwidgets().FirstOrDefault(x => x.WidgetID == targetWidgetGuid);
                    _widgetVM = widgetVM as WidgetViewModBase;
                }
            }
        }
        internal DeselectAllWidgetsCommand()
        {
            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();

            if (selectionService != null)
            {
                _pageVM = selectionService.GetCurrentPage();
            }
        }
        internal MoveFocusToEditCanvasCommand()
        {
            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();

            if (selectionService != null)
            {
                _pageVM = selectionService.GetCurrentPage();
            }
        }
        private void WdgMgrEditSelectioHandler(object parameter)
        {
            Guid pageID = (Guid)parameter;
            ISelectionService   selsrv = ServiceLocator.Current.GetInstance <ISelectionService>();
            PageEditorViewModel page   = selsrv.GetCurrentPage() as PageEditorViewModel;

            if (page != null && page.ActivePage.Guid == pageID)
            {
                page.WdgMgrEditSelection();
            }
        }
        private void WdgMgrReZOrderSelectionHandler(object parameter)
        {
            WDMgrZorderDragChangeInfo info = (WDMgrZorderDragChangeInfo)parameter;
            Guid pageID = info.PageID;
            ISelectionService   selsrv = ServiceLocator.Current.GetInstance <ISelectionService>();
            PageEditorViewModel page   = selsrv.GetCurrentPage() as PageEditorViewModel;

            if (page != null && page.ActivePage.Guid == pageID)
            {
                page.WdgMgrReZOrderSelection(info.zIndex, info.widgetID);
            }
        }
Beispiel #11
0
        internal ChangePageCommand()
        {
            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();

            if (selectionService != null)
            {
                _pageVM           = selectionService.GetCurrentPage();
                _activePage       = _pageVM.ActivePage;
                _acitveAdaptiveID = _pageVM.CurAdaptiveViewGID;
            }

            _listEventAggregator = ServiceLocator.Current.GetInstance <IEventAggregator>();
        }
        private void WdgMgrZChangeSelectioHandler(object parameter)
        {
            WDMgrZorderChangeInfo Info = (WDMgrZorderChangeInfo)parameter;
            Guid pageID                = Info.PageID;
            bool bIsForword            = Info.bForward;
            ISelectionService   selsrv = ServiceLocator.Current.GetInstance <ISelectionService>();
            PageEditorViewModel page   = selsrv.GetCurrentPage() as PageEditorViewModel;

            if (page != null && page.ActivePage.Guid == pageID)
            {
                page.WdgMgrZOrderChangeSelection(bIsForword);
            }
        }
Beispiel #13
0
        public MoveThumb()
        {
            DragStarted   += MoveThumb_DragStarted;
            DragDelta     += MoveThumb_DragDelta;
            DragCompleted += new DragCompletedEventHandler(this.MoveThumb_DragCompleted);

            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();
            ISupportUndo      pageVM           = selectionService.GetCurrentPage() as ISupportUndo;

            if (pageVM != null)
            {
                pageUndoManager = pageVM.UndoManager;
            }
        }
        private void WdgMgrDeleteSelectioHandler(object parameter)
        {
            WDMgrWidgetDeleteInfo Info = parameter as WDMgrWidgetDeleteInfo;

            if (Info != null)
            {
                ISelectionService   selsrv = ServiceLocator.Current.GetInstance <ISelectionService>();
                PageEditorViewModel page   = selsrv.GetCurrentPage() as PageEditorViewModel;
                if (page != null && page.ActivePage.Guid == Info.PageID)
                {
                    page.WdgMgrDeleteSelection(Info.WidgetList);
                }
            }
        }
Beispiel #15
0
        internal DeleteTargetCommand(InteractionTabVM tabVM, Guid targetValue, Guid targetWidgetGuid)
        {
            _tabVM       = tabVM;
            _targetValue = targetValue;

            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();

            if (selectionService != null)
            {
                _pageVM = selectionService.GetCurrentPage();
                if (_pageVM != null)
                {
                    IWidgetPropertyData widgetVM = _pageVM.GetSelectedwidgets().FirstOrDefault(x => x.WidgetID == targetWidgetGuid);
                    _widgetVM = widgetVM as WidgetViewModBase;
                }
            }
        }
Beispiel #16
0
        internal UrlChangeCommand(InteractionTabVM tabVM, string oldUrl, string newUrl, Guid targetWidgetGuid)
        {
            _tabVM  = tabVM;
            _oldUrl = oldUrl;
            _newUrl = newUrl;

            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();

            if (selectionService != null)
            {
                _pageVM = selectionService.GetCurrentPage();
                if (_pageVM != null)
                {
                    IWidgetPropertyData widgetVM = _pageVM.GetSelectedwidgets().FirstOrDefault(x => x.WidgetID == targetWidgetGuid);
                    _widgetVM = widgetVM as WidgetViewModBase;
                }
            }
        }
Beispiel #17
0
        internal WidgetNoteCommand(NotesViewModel notesVM, string propertyName, string oldValue, string newValue, Guid targetWidgetGuid)
        {
            _notesVM      = notesVM;
            _propertyName = propertyName;
            _oldValue     = oldValue;
            _newValue     = newValue;

            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();

            if (selectionService != null)
            {
                _pageVM = selectionService.GetCurrentPage();
                if (_pageVM != null)
                {
                    IWidgetPropertyData widgetVM = _pageVM.GetSelectedwidgets().FirstOrDefault(x => x.WidgetID == targetWidgetGuid);
                    _widgetVM = widgetVM as WidgetViewModBase;
                }
            }
        }
Beispiel #18
0
        internal ExternalLinkCommand(InteractionTabVM tabVM, bool oldValue, bool newValue, Guid targetWidgetGuid, string externalLink)
        {
            _tabVM        = tabVM;
            _oldValue     = oldValue;
            _newValue     = newValue;
            _externalLink = externalLink;

            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();

            if (selectionService != null)
            {
                _pageVM = selectionService.GetCurrentPage();
                if (_pageVM != null)
                {
                    IWidgetPropertyData widgetVM = _pageVM.GetSelectedwidgets().FirstOrDefault(x => x.WidgetID == targetWidgetGuid);
                    _widgetVM = widgetVM as WidgetViewModBase;
                }
            }
        }
Beispiel #19
0
        private void UploadHtmlEventHandler(bool isNormal = true)
        {
            // Make textbox update source data.
            ISelectionService _selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();
            IPagePropertyData page = _selectionService.GetCurrentPage();

            if (page != null && page.EditorCanvas != null)
            {
                page.EditorCanvas.Focus();
            }

            if (_uploadState == UploadState.upload_End)
            {
                _uploadState = UploadState.upload_Init;

                _upLoadPara = new UploadParameter();

                if (!InitParameter(_upLoadPara))
                {
                    _uploadState = UploadState.upload_End;
                    return;
                }

                if (!ShowPeUploadWindow(_upLoadPara))
                {
                    _uploadState = UploadState.upload_End;
                    return;
                }

                _outputFolder = _upLoadPara.ProjectPath;
                string imgPath = _outputFolder + @"\images\";

                _htmlService.ImagesStreamManager.WorkingDirectory = imgPath;

                _ListEventAggregator.GetEvent <SynUploadEvent>().Publish(_upLoadPara);

                ShowProgressWindow();
            }
            else
            {
                ReShowProgressWindow();
            }
        }
Beispiel #20
0
        public void OnAdaptiveViewChange(Guid ID)
        {
            //  IDocumentService doc = ServiceLocator.Current.GetInstance<IDocumentService>();
            IPagePropertyData pageVM = _selectionService.GetCurrentPage();

            if (pageVM != null && pageVM.ActivePage != null)
            {
                WidgetListItem.CurViewID = ID;

                foreach (WidgetListItem Item in _allWidgets)
                {
                    Item.UpdateAllFlagByViewChange();
                }
            }
        }
Beispiel #21
0
        public void BuildCompositeCommandAndPush(IUndoableCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException();
            }

            CompositeCommand commandToPush = command as CompositeCommand;

            if (commandToPush == null)
            {
                // If the push command is not CompositeCommand, then build a  CompositeCommand
                // to hold it as we should change to the page in which target widgets located first when undo/redo
                CompositeCommand cmds = new CompositeCommand();
                cmds.AddCommand(command);
                commandToPush = cmds;
            }


            ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();

            if (selectionService != null && null != selectionService.GetCurrentPage())
            {
                // Add change page command in the first item.
                commandToPush.InsertCommand(0, new ChangePageCommand());
            }


            if (_undoStack.Count >= _undoLimit)
            {
                _undoStack.RemoveAt(0);
            }

            _undoStack.Add(commandToPush);

            Debug.WriteLine("Pushed a IUndoableCommand into undo stack. Undo stack count is : {0}.", _undoStack.Count);

            // New command is pushed in, clear the redo stack.
            _redoStack.Clear();
        }
        private void WdgMgrPlacewidgetSelectioHandler(object parameter)
        {
            WDMgrPlaceStatusChangeInfo data = (WDMgrPlaceStatusChangeInfo)parameter;

            if (data == null || data.WidgetList.Count == 0)
            {
                return;
            }

            ISelectionService   selsrv = ServiceLocator.Current.GetInstance <ISelectionService>();
            PageEditorViewModel page   = selsrv.GetCurrentPage() as PageEditorViewModel;

            if (page != null)
            {
                if (data.bPlace)
                {
                    page.WdgMgrPlaceTargets(data.WidgetList);
                }
                else
                {
                    page.UnplaceWidgetsFromView(data.WidgetList);
                }
            }
        }
Beispiel #23
0
        public async void GenerateHTMLEventHandler(object data)
        {
            PreviewParameter para     = data as PreviewParameter;
            string           filePath = para.SavePath;
            // Make textbox update source data.
            ISelectionService _selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();
            IPagePropertyData page = _selectionService.GetCurrentPage();

            if (para.IsPreviewCurrentPage == true && page == null)
            {
                return;
            }

            if (page != null && page.EditorCanvas != null)
            {
                page.EditorCanvas.Focus();
            }

            if ((_currentPageGID != Guid.Empty))
            {
                return;
            }

            IDocumentService doc = ServiceLocator.Current.GetInstance <IDocumentService>();

            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }
            if (doc == null || doc.Document == null)
            {
                return;
            }

            //Get Image save path;
            //doc.Document.GeneratorConfigurationSet.DefaultHtmlConfiguration.OutputFolder = @"D:\pic";
            _outputFolder = filePath;
            string imgPath = filePath + @"\images\";

            try
            {
                if (Directory.Exists(imgPath) == false)
                {
                    Directory.CreateDirectory(imgPath);
                }
                _htmlService.ImagesStreamManager.WorkingDirectory = imgPath;
            }
            catch (Exception ex)
            {
                MessageBox.Show(GlobalData.FindResource("Error_Generate_Html") + ex.Message);
                return;
            }

            if (para.IsPreviewCurrentPage)
            {
                Guid currentPageGuid = page.PageGID;
                if (page.ActivePage is IEmbeddedPage)
                {
                    IEmbeddedPage embeddedPage = page.ActivePage as IEmbeddedPage;
                    currentPageGuid = embeddedPage.ParentWidget.ParentPage.Guid;
                }

                doc.Document.GeneratorConfigurationSet.DefaultHtmlConfiguration.CurrentPage = currentPageGuid;
            }
            else
            {
                doc.Document.GeneratorConfigurationSet.DefaultHtmlConfiguration.CurrentPage = Guid.Empty;
            }


            Debug.WriteLine("----->HtmlGen----->Start All Convert");
            //Async operation to Generate Html and open it
            await AsyncGenerateHtml(para.IsBrowerOpen);

            // Reset image working directory.
            _htmlService.ImagesStreamManager.WorkingDirectory = string.Empty;
        }
        private PageEditorViewModel OpenWidgetPage(IWidget widget, Guid SelWdgGID, bool bIsSelect, bool bIsgroup)
        {
            PageEditorViewModel newPage           = null;
            ISelectionService   _selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();
            IPagePropertyData   activePage        = _selectionService.GetCurrentPage();

            Guid parentGID = widget.ParentPage.Guid;

            switch (widget.WidgetType)
            {
            case WidgetType.DynamicPanel:
            {
                //Active an exist page editor,20140220
                foreach (var pageItem in EditPages.OfType <DynamicPageEditorViewModel>())
                {
                    if (pageItem.ContentId == widget.Guid.ToString())
                    {
                        pageItem.IsActive = true;
                        return(pageItem);
                    }
                }

                ////Create a new page editor,20140220
                newPage = new DynamicPageEditorViewModel(widget);
                newPage.WdgMgrSetTargeComponent(SelWdgGID, bIsSelect, bIsgroup);
                break;
            }

            case WidgetType.Toast:
            {
                foreach (var pageItem in EditPages.OfType <ToastPageEditorViewModel>())
                {
                    if (pageItem.ContentId == widget.Guid.ToString())
                    {
                        pageItem.IsActive = true;
                        return(pageItem);
                    }
                }

                newPage = new ToastPageEditorViewModel(widget);
                newPage.WdgMgrSetTargeComponent(SelWdgGID, bIsSelect, bIsgroup);
                break;
            }

            case WidgetType.HamburgerMenu:
            {
                //Active an exist page editor,20140220
                foreach (var pageItem in EditPages.OfType <HamburgerPageEditorViewModel>())
                {
                    if (pageItem.ContentId == widget.Guid.ToString())
                    {
                        pageItem.IsActive = true;
                        return(pageItem);
                    }
                }
                //Create a new page editor,20140220
                newPage = new HamburgerPageEditorViewModel(widget);
                newPage.WdgMgrSetTargeComponent(SelWdgGID, bIsSelect, bIsgroup);
                break;
            }
            }

            DeselectAllPages();

            //if child page is not set(value is 100%)
            //Set scale the same as parent page(only create child page, not active child page)
            if (newPage.EditorScale == 1)
            {
                newPage.EditorScale = activePage.EditorScale;
            }
            newPage.Open();
            EditPages.Add(newPage);
            newPage.IsActive = true;
            newPage.Update();
            return(null);
        }
        private PageEditorViewModel OpenSwipePage(IWidget widget, Guid childPageGID, Guid SelWdgGID, bool bIsSelect, bool bIsGroup)
        {
            PageEditorViewModel newPage           = null;
            ISelectionService   _selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>();
            IPagePropertyData   activePage        = _selectionService.GetCurrentPage();

            Guid parentGID = widget.ParentPage.Guid;

            if (widget.WidgetType != WidgetType.DynamicPanel)
            {
                return(null);
            }


            //Active an exist page editor,20140220
            DynamicPageEditorViewModel CurrentDynmicPanel = null;

            foreach (var pageItem in EditPages.OfType <DynamicPageEditorViewModel>())
            {
                if (pageItem.ContentId == widget.Guid.ToString())
                {
                    CurrentDynmicPanel = pageItem;
                    if (pageItem.ActivePage.Guid == childPageGID)
                    {
                        pageItem.IsActive = true;
                        return(pageItem);
                    }
                    break;
                }
            }

            //Only Update the target panel
            if (CurrentDynmicPanel != null)
            {
                //TODO:???????
                CurrentDynmicPanel.IsActive = true;
                foreach (DynamicChildNodViewModel item in CurrentDynmicPanel.DynamicChildren)
                {
                    if (item.GID == childPageGID)
                    {
                        CurrentDynmicPanel.WdgMgrSetTargeComponent(SelWdgGID, bIsSelect, bIsGroup);
                        item.IsChecked = true;
                        break;
                    }
                }
                return(null);
            }

            DeselectAllPages();

            //Create a new page with target panel
            newPage = new DynamicPageEditorViewModel(widget, childPageGID);
            newPage.WdgMgrSetTargeComponent(SelWdgGID, bIsSelect, bIsGroup);

            //if child page is not set(value is 100%)
            //Set scale the same as parent page(only create child page, not active child page)
            if (newPage.EditorScale == 1)
            {
                newPage.EditorScale = activePage.EditorScale;
            }
            newPage.Open();
            EditPages.Add(newPage);
            newPage.IsActive = true;
            newPage.Update();
            return(null);
        }
Beispiel #26
0
        private double CalculateSnapChangeDelta(double valueToSnap, Service.Document.Orientation guideOrientation)
        {
            //Snap to Guide
            if (GlobalData.IsSnapToGuide)
            {
                IPageView pageView = _page.ActivePage.PageViews.GetPageView(_selectionService.GetCurrentPage().CurAdaptiveViewGID);
                if (pageView == null)
                {
                    return(0);
                }

                foreach (IGuide item in pageView.Guides)
                {
                    if (guideOrientation == Service.Document.Orientation.Horizontal &&
                        item.Orientation == Service.Document.Orientation.Horizontal)
                    {
                        if (Math.Abs(valueToSnap - item.Y) < CommonDefine.SnapMargin)
                        {
                            return(item.Y - valueToSnap);
                        }
                    }
                    else if (guideOrientation == Service.Document.Orientation.Vertical &&
                             item.Orientation == Service.Document.Orientation.Vertical)
                    {
                        if (Math.Abs(valueToSnap - item.X) < CommonDefine.SnapMargin)
                        {
                            return(item.X - valueToSnap);
                        }
                    }
                }

                foreach (IGuide item in _document.GlobalGuides)
                {
                    if (guideOrientation == Service.Document.Orientation.Horizontal &&
                        item.Orientation == Service.Document.Orientation.Horizontal)
                    {
                        if (Math.Abs(valueToSnap - item.Y) < CommonDefine.SnapMargin)
                        {
                            return(item.Y - valueToSnap);
                        }
                    }
                    else if (guideOrientation == Service.Document.Orientation.Vertical &&
                             item.Orientation == Service.Document.Orientation.Vertical)
                    {
                        if (Math.Abs(valueToSnap - item.X) < CommonDefine.SnapMargin)
                        {
                            return(item.X - valueToSnap);
                        }
                    }
                }
            }

            //Snap to grid
            if (GlobalData.IsSnapToGrid)
            {
                double snap = valueToSnap % GlobalData.GRID_SIZE;
                if (snap <= CommonDefine.SnapMargin)
                {
                    snap = -snap;
                }
                else
                {
                    double temp = (valueToSnap + CommonDefine.SnapMargin) % GlobalData.GRID_SIZE;
                    if (temp < CommonDefine.SnapMargin)
                    {
                        snap = GlobalData.GRID_SIZE - snap;
                    }
                    else
                    {
                        snap = 0;
                    }
                }

                return(snap);
            }

            return(0);
        }
Beispiel #27
0
        private void Snap(Rect boundingRect, ref double deltaX, ref double deltaY)
        {
            Rect   newRect   = new Rect(boundingRect.Left + deltaX, boundingRect.Top + deltaY, boundingRect.Width, boundingRect.Height);
            double oriDeltaX = deltaX;
            double oriDeltaY = deltaY;

            if (GlobalData.IsSnapToGuide)
            {
                IPageView pageView = _page.ActivePage.PageViews.GetPageView(_selectionService.GetCurrentPage().CurAdaptiveViewGID);
                if (pageView == null)
                {
                    return;
                }
                foreach (IGuide item in pageView.Guides)
                {
                    if (deltaY == oriDeltaY && item.Orientation == Service.Document.Orientation.Horizontal)
                    {
                        Snap2Guide(item, newRect, boundingRect, ref deltaY);
                    }
                    if (deltaX == oriDeltaX && item.Orientation == Service.Document.Orientation.Vertical)
                    {
                        Snap2Guide(item, newRect, boundingRect, ref deltaX);
                    }
                    if (deltaX != oriDeltaX && deltaY != oriDeltaY)
                    {
                        return;
                    }
                }

                foreach (IGuide item in _document.GlobalGuides)
                {
                    if (deltaY == oriDeltaY && item.Orientation == Service.Document.Orientation.Horizontal)
                    {
                        Snap2Guide(item, newRect, boundingRect, ref deltaY);
                    }
                    if (deltaX == oriDeltaX && item.Orientation == Service.Document.Orientation.Vertical)
                    {
                        Snap2Guide(item, newRect, boundingRect, ref deltaX);
                    }
                    if (deltaX != oriDeltaX && deltaY != oriDeltaY)
                    {
                        return;
                    }
                }
            }

            //snap to grid.
            if (GlobalData.IsSnapToGrid)
            {
                double xSnap, ySnap;
                //Horizontal
                if (deltaX == oriDeltaX)
                {
                    xSnap = newRect.Left % GlobalData.GRID_SIZE;
                    if (xSnap <= CommonDefine.SnapMargin)
                    {
                        xSnap   = -xSnap;
                        deltaX += xSnap;
                    }
                    else
                    {
                        double temp = (newRect.Left + CommonDefine.SnapMargin) % GlobalData.GRID_SIZE;
                        if (temp < CommonDefine.SnapMargin)
                        {
                            xSnap   = GlobalData.GRID_SIZE - xSnap;
                            deltaX += xSnap;
                        }
                    }
                }
                //Vertical
                if (deltaY == oriDeltaY)
                {
                    ySnap = newRect.Top % GlobalData.GRID_SIZE;
                    if (ySnap <= CommonDefine.SnapMargin)
                    {
                        ySnap   = -ySnap;
                        deltaY += ySnap;
                    }
                    else
                    {
                        double temp = (newRect.Top + CommonDefine.SnapMargin) % GlobalData.GRID_SIZE;
                        if (temp < CommonDefine.SnapMargin)
                        {
                            ySnap   = GlobalData.GRID_SIZE - ySnap;
                            deltaY += ySnap;
                        }
                    }
                }
            }
        }