Пример #1
0
        // Settings paths taken from the example at:
        // http://msdn2.microsoft.com/en-us/library/system.componentmodel.design.idesigneroptionservice.aspx
        //
        public override void Initialize(IComponent component)
        {
            base.Initialize(component);

            this.Control.AllowDrop = true;

            // Initialize the default values of the Design-Time properties.
            //
            _defaultDrawGrid   = true;
            _defaultSnapToGrid = true;
            _defaultGridSize   = new Size(8, 8);

            // If the parent Control of the designed one has a ParentDesigner then inherit the values
            // from it's designer.
            //
            if (this.Control.Parent != null)
            {
                ParentControlDesigner parentDesigner = GetParentControlDesignerOf(Control.Parent);
                if (parentDesigner != null)
                {
                    _defaultDrawGrid   = (bool)GetValue(parentDesigner.Component, "DrawGrid");
                    _defaultSnapToGrid = (bool)GetValue(parentDesigner.Component, "SnapToGrid");
                    _defaultGridSize   = (Size)GetValue(parentDesigner.Component, "GridSize");
                }
            }
            else
            {
                // Else retrieve them through the IDesignerOptionService (if available)
                //
                IDesignerOptionService options = GetService(typeof(IDesignerOptionService)) as
                                                 IDesignerOptionService;
                if (options != null)
                {
                    object value = null;
                    value = options.GetOptionValue(@"WindowsFormsDesigner\General", "DrawGrid");
                    if (value is bool)
                    {
                        _defaultDrawGrid = (bool)value;
                    }

                    value = options.GetOptionValue(@"WindowsFormsDesigner\General", "SnapToGrid");
                    if (value is bool)
                    {
                        _defaultSnapToGrid = (bool)value;
                    }

                    value = options.GetOptionValue(@"WindowsFormsDesigner\General", "GridSize");
                    if (value is Size)
                    {
                        _defaultGridSize = (Size)value;
                    }
                }
            }

            // At the end set whatever we've managed to get
            //
            _drawGrid   = _defaultDrawGrid;
            _snapToGrid = _defaultSnapToGrid;
            _gridSize   = _defaultGridSize;
        }
Пример #2
0
        public void GetOptionValue_NotNested_ReturnsExpected()
        {
            var value = new TestClass {
                Value = "StringValue"
            };

            var service = new TestDesignerOptionService();
            IDesignerOptionService iService = service;

            service.DoCreateOptionCollection(service.Options, "Name", value);

            Assert.Equal("StringValue", iService.GetOptionValue("Name", "Value"));
        }
Пример #3
0
        public void SetOptionValue_NoSuchValue_Nop(string pageName, string valueName)
        {
            var value = new TestClass {
                Value = "StringValue"
            };

            var service = new TestDesignerOptionService();
            IDesignerOptionService iService = service;

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", null);
            service.DoCreateOptionCollection(options, "SubName", value);

            iService.SetOptionValue(pageName, valueName, "value");
        }
Пример #4
0
        // This utility method connects the designer to various
        // services it will use.
        private void InitializeServices()
        {
            // Acquire a reference to DesignerActionService.
            this.actionService = GetService(typeof(DesignerActionService)) as DesignerActionService;

            // Acquire a reference to DesignerActionUIService.
            this.actionUiService = GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;

            // Acquire a reference to IComponentChangeService.
            this.changeService = GetService(typeof(IComponentChangeService)) as IComponentChangeService;

            // Acquire a reference to IDesignerHost.
            this.host = GetService(typeof(IDesignerHost)) as IDesignerHost;

            // Acquire a reference to IDesignerOptionService.
            this.optionService =
                GetService(typeof(IDesignerOptionService)) as IDesignerOptionService;

            // Acquire a reference to IEventBindingService.
            this.eventBindingService =
                GetService(typeof(IEventBindingService)) as IEventBindingService;

            // Acquire a reference to IExtenderListService.
            this.listService =
                GetService(typeof(IExtenderListService)) as IExtenderListService;

            // Acquire a reference to IReferenceService.
            this.referenceService =
                GetService(typeof(IReferenceService)) as IReferenceService;

            // Acquire a reference to ITypeResolutionService.
            this.typeResService = GetService(typeof(ITypeResolutionService))
                                  as ITypeResolutionService;

            // Acquire a reference to IComponentDiscoveryService.
            this.componentDiscoveryService = GetService(typeof(IComponentDiscoveryService))
                                             as IComponentDiscoveryService;

            // Acquire a reference to IToolboxService.
            this.toolboxService = GetService(typeof(IToolboxService)) as IToolboxService;

            // Acquire a reference to UndoEngine.
            this.undoEng = GetService(typeof(UndoEngine)) as UndoEngine;

            if (this.undoEng != null)
            {
                //MessageBox.Show("UndoEngine");
            }
        }
Пример #5
0
        public void SetOptionValue_Nested_ReturnsExpected()
        {
            var value = new TestClass {
                Value = "StringValue"
            };

            var service = new TestDesignerOptionService();
            IDesignerOptionService iService = service;

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", null);
            service.DoCreateOptionCollection(options, "SubName", value);

            iService.SetOptionValue("Name\\SubName", "Value", "abc");
            Assert.Equal("abc", value.Value);
        }
Пример #6
0
        public static object GetOptionValue(IServiceProvider provider, string name)
        {
            object optionValue = null;

            if (provider != null)
            {
                DesignerOptionService service = provider.GetService(typeof(DesignerOptionService)) as DesignerOptionService;
                if (service != null)
                {
                    PropertyDescriptor descriptor = service.Options.Properties[name];
                    if (descriptor != null)
                    {
                        optionValue = descriptor.GetValue(null);
                    }
                    return(optionValue);
                }
                IDesignerOptionService service2 = provider.GetService(typeof(IDesignerOptionService)) as IDesignerOptionService;
                if (service2 != null)
                {
                    optionValue = service2.GetOptionValue(@"WindowsFormsDesigner\General", name);
                }
            }
            return(optionValue);
        }
Пример #7
0
    // </snippet6>

    // <snippet7>
    // This utility method connects the designer to various
    // services it will use.
    private void InitializeServices()
    {
        // Acquire a reference to DesignerActionService.
        this.actionService =
            GetService(typeof(DesignerActionService))
            as DesignerActionService;

        // Acquire a reference to DesignerActionUIService.
        this.actionUiService =
            GetService(typeof(DesignerActionUIService))
            as DesignerActionUIService;

        // Acquire a reference to IComponentChangeService.
        this.changeService =
            GetService(typeof(IComponentChangeService))
            as IComponentChangeService;

        // <snippet14>
        // Hook the IComponentChangeService events.
        if (this.changeService != null)
        {
            this.changeService.ComponentChanged +=
                new ComponentChangedEventHandler(
                    ChangeService_ComponentChanged);

            this.changeService.ComponentAdded +=
                new ComponentEventHandler(
                    ChangeService_ComponentAdded);

            this.changeService.ComponentRemoved +=
                new ComponentEventHandler(
                    changeService_ComponentRemoved);
        }
        // </snippet14>

        // Acquire a reference to ISelectionService.
        this.selectionService =
            GetService(typeof(ISelectionService))
            as ISelectionService;

        // Hook the SelectionChanged event.
        if (this.selectionService != null)
        {
            this.selectionService.SelectionChanged +=
                new EventHandler(selectionService_SelectionChanged);
        }

        // Acquire a reference to IDesignerEventService.
        this.eventService =
            GetService(typeof(IDesignerEventService))
            as IDesignerEventService;

        if (this.eventService != null)
        {
            this.eventService.ActiveDesignerChanged +=
                new ActiveDesignerEventHandler(
                    eventService_ActiveDesignerChanged);
        }

        // Acquire a reference to IDesignerHost.
        this.host =
            GetService(typeof(IDesignerHost))
            as IDesignerHost;

        // Acquire a reference to IDesignerOptionService.
        this.optionService =
            GetService(typeof(IDesignerOptionService))
            as IDesignerOptionService;

        // Acquire a reference to IEventBindingService.
        this.eventBindingService =
            GetService(typeof(IEventBindingService))
            as IEventBindingService;

        // Acquire a reference to IExtenderListService.
        this.listService =
            GetService(typeof(IExtenderListService))
            as IExtenderListService;

        // Acquire a reference to IReferenceService.
        this.referenceService =
            GetService(typeof(IReferenceService))
            as IReferenceService;

        // Acquire a reference to ITypeResolutionService.
        this.typeResService =
            GetService(typeof(ITypeResolutionService))
            as ITypeResolutionService;

        // Acquire a reference to IComponentDiscoveryService.
        this.componentDiscoveryService =
            GetService(typeof(IComponentDiscoveryService))
            as IComponentDiscoveryService;

        // Acquire a reference to IToolboxService.
        this.toolboxService =
            GetService(typeof(IToolboxService))
            as IToolboxService;

        // Acquire a reference to UndoEngine.
        this.undoEng =
            GetService(typeof(UndoEngine))
            as UndoEngine;

        if (this.undoEng != null)
        {
            MessageBox.Show("UndoEngine");
        }
    }
        public override void Update(Graphics graphics, LayoutUpdateReason reason)
        {
            //do not recalculate pages when it's just a zoom change
            if (reason == LayoutUpdateReason.ZoomChanged)
            {
                return;
            }

            if (graphics == null)
            {
                throw new ArgumentException("graphics");
            }

            //Set the scaling, pageSize, margins, pageseparator by reserse scaling; so that when we actually scale
            //at the time of drawing things will be correctly calculated
            Size    margin           = WorkflowTheme.CurrentTheme.AmbientTheme.Margin;
            Size    paperSize        = GetPaperSize(graphics);
            Margins margins          = GetAdjustedMargins(graphics);
            Size    rootDesignerSize = (this.parentView.RootDesigner != null) ? this.parentView.RootDesigner.Size : Size.Empty;

            if (!rootDesignerSize.IsEmpty)
            {
                Size selectionSize = WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize;
                rootDesignerSize.Width  += 3 * selectionSize.Width;
                rootDesignerSize.Height += 3 * selectionSize.Height;
            }

            //STEP1 : Calculate the scaling factor
            if (this.printDocument.PageSetupData.AdjustToScaleFactor)
            {
                this.scaling = ((float)this.printDocument.PageSetupData.ScaleFactor / 100.0f);
            }
            else
            {
                Size printableArea = new Size(paperSize.Width - (margins.Left + margins.Right), paperSize.Height - (margins.Top + margins.Bottom));
                printableArea.Width  = Math.Max(printableArea.Width, 1);
                printableArea.Height = Math.Max(printableArea.Height, 1);

                PointF scaleFactor = new PointF(
                    ((float)this.printDocument.PageSetupData.PagesWide * (float)printableArea.Width / (float)rootDesignerSize.Width),
                    ((float)this.printDocument.PageSetupData.PagesTall * (float)printableArea.Height / (float)rootDesignerSize.Height));

                //Take the minimum scaling as we do not want to unevenly scale the bitmap
                this.scaling = Math.Min(scaleFactor.X, scaleFactor.Y);
                //leave just 3 digital points (also, that will remove potential problems with ceiling e.g. when the number of pages would be 3.00000000001 we'll get 4)
                this.scaling = (float)(Math.Floor((double)this.scaling * 1000.0d) / 1000.0d);
            }

            //STEP2 : Calculate the pagesize
            this.pageSize        = paperSize;
            this.pageSize.Width  = Convert.ToInt32(Math.Ceiling(((float)this.pageSize.Width) / this.scaling));
            this.pageSize.Height = Convert.ToInt32(Math.Ceiling(((float)this.pageSize.Height) / this.scaling));

            //STEP3 : Calculate the page separator
            IDesignerOptionService designerOptionService = this.serviceProvider.GetService(typeof(IDesignerOptionService)) as IDesignerOptionService;

            if (designerOptionService != null)
            {
                object separator = designerOptionService.GetOptionValue("WinOEDesigner", "PageSeparator");
                PageSeparator = (separator != null) ? (Size)separator : PrintPreviewLayout.DefaultPageSeparator;
            }
            PageSeparator = new Size(Convert.ToInt32(Math.Ceiling(((float)PageSeparator.Width) / this.scaling)), Convert.ToInt32(Math.Ceiling(((float)PageSeparator.Height) / this.scaling)));

            //STEP4: Calculate the margins after reverse scaling the margins, so that when we set the normal scalezoom we have correct margins
            PageMargins        = margins;
            PageMargins.Left   = Convert.ToInt32((float)PageMargins.Left / this.scaling);
            PageMargins.Right  = Convert.ToInt32((float)PageMargins.Right / this.scaling);
            PageMargins.Top    = Convert.ToInt32((float)PageMargins.Top / this.scaling);
            PageMargins.Bottom = Convert.ToInt32((float)PageMargins.Bottom / this.scaling);

            //STEP5: Calculate the header and footer margins
            this.headerFooterMargins.Top    = Convert.ToInt32((float)this.printDocument.PageSetupData.HeaderMargin / this.scaling);
            this.headerFooterMargins.Bottom = Convert.ToInt32((float)this.printDocument.PageSetupData.FooterMargin / this.scaling);
            this.previewTime = DateTime.Now;

            //STEP6: Calculate the the row columns
            Size viewablePageSize = new Size(this.pageSize.Width - (PageMargins.Left + PageMargins.Right), this.pageSize.Height - (PageMargins.Top + PageMargins.Bottom));

            viewablePageSize.Width  = Math.Max(viewablePageSize.Width, 1);
            viewablePageSize.Height = Math.Max(viewablePageSize.Height, 1);

            //We check for greater than 1 here as the division might introduce rounding factor
            //Columns
            this.rowColumns.Width  = rootDesignerSize.Width / viewablePageSize.Width;
            this.rowColumns.Width += ((rootDesignerSize.Width % viewablePageSize.Width) > 1) ? 1 : 0;
            this.rowColumns.Width  = Math.Max(1, this.rowColumns.Width);

            //Rows
            this.rowColumns.Height  = rootDesignerSize.Height / viewablePageSize.Height;
            this.rowColumns.Height += ((rootDesignerSize.Height % viewablePageSize.Height) > 1) ? 1 : 0;
            this.rowColumns.Height  = Math.Max(1, this.rowColumns.Height);

            //STEP7: Calculate the pagelayoutdata
            this.pageLayoutInfo.Clear();

            //Create the layout data
            for (int row = 0; row < this.rowColumns.Height; row++)
            {
                for (int column = 0; column < this.rowColumns.Width; column++)
                {
                    Point pageLocation = Point.Empty;
                    pageLocation.X = (column * this.pageSize.Width) + ((column + 1) * PageSeparator.Width);
                    pageLocation.Y = (row * this.pageSize.Height) + ((row + 1) * PageSeparator.Height);

                    Point viewablePageLocation = Point.Empty;
                    viewablePageLocation.X = pageLocation.X + PageMargins.Left;
                    viewablePageLocation.Y = pageLocation.Y + PageMargins.Top;

                    Rectangle logicalBounds      = new Rectangle(column * viewablePageSize.Width, row * viewablePageSize.Height, viewablePageSize.Width, viewablePageSize.Height);
                    Rectangle pageBounds         = new Rectangle(pageLocation, this.pageSize);
                    Rectangle viewablePageBounds = new Rectangle(viewablePageLocation, viewablePageSize);
                    this.pageLayoutInfo.Add(new PageLayoutData(logicalBounds, pageBounds, viewablePageBounds, new Point(column, row)));
                }
            }
        }
 public override void Update(Graphics graphics, WorkflowLayout.LayoutUpdateReason reason)
 {
     if (reason != WorkflowLayout.LayoutUpdateReason.ZoomChanged)
     {
         Size size5;
         if (graphics == null)
         {
             throw new ArgumentException("graphics");
         }
         Size    margin          = WorkflowTheme.CurrentTheme.AmbientTheme.Margin;
         Size    paperSize       = this.GetPaperSize(graphics);
         Margins adjustedMargins = this.GetAdjustedMargins(graphics);
         Size    size2           = (base.parentView.RootDesigner != null) ? base.parentView.RootDesigner.Size : Size.Empty;
         if (!size2.IsEmpty)
         {
             Size selectionSize = WorkflowTheme.CurrentTheme.AmbientTheme.SelectionSize;
             size2.Width  += 3 * selectionSize.Width;
             size2.Height += 3 * selectionSize.Height;
         }
         if (this.printDocument.PageSetupData.AdjustToScaleFactor)
         {
             this.scaling = ((float)this.printDocument.PageSetupData.ScaleFactor) / 100f;
         }
         else
         {
             Size size4;
             size4 = new Size(paperSize.Width - (adjustedMargins.Left + adjustedMargins.Right), paperSize.Height - (adjustedMargins.Top + adjustedMargins.Bottom))
             {
                 Width  = Math.Max(size4.Width, 1),
                 Height = Math.Max(size4.Height, 1)
             };
             PointF tf = new PointF((this.printDocument.PageSetupData.PagesWide * size4.Width) / ((float)size2.Width), (this.printDocument.PageSetupData.PagesTall * size4.Height) / ((float)size2.Height));
             this.scaling = Math.Min(tf.X, tf.Y);
             this.scaling = (float)(Math.Floor((double)(this.scaling * 1000.0)) / 1000.0);
         }
         this.pageSize        = paperSize;
         this.pageSize.Width  = Convert.ToInt32(Math.Ceiling((double)(((float)this.pageSize.Width) / this.scaling)));
         this.pageSize.Height = Convert.ToInt32(Math.Ceiling((double)(((float)this.pageSize.Height) / this.scaling)));
         IDesignerOptionService service = base.serviceProvider.GetService(typeof(IDesignerOptionService)) as IDesignerOptionService;
         if (service != null)
         {
             object optionValue = service.GetOptionValue("WinOEDesigner", "PageSeparator");
             this.PageSeparator = (optionValue != null) ? ((Size)optionValue) : DefaultPageSeparator;
         }
         this.PageSeparator              = new Size(Convert.ToInt32(Math.Ceiling((double)(((float)this.PageSeparator.Width) / this.scaling))), Convert.ToInt32(Math.Ceiling((double)(((float)this.PageSeparator.Height) / this.scaling))));
         this.PageMargins                = adjustedMargins;
         this.PageMargins.Left           = Convert.ToInt32((float)(((float)this.PageMargins.Left) / this.scaling));
         this.PageMargins.Right          = Convert.ToInt32((float)(((float)this.PageMargins.Right) / this.scaling));
         this.PageMargins.Top            = Convert.ToInt32((float)(((float)this.PageMargins.Top) / this.scaling));
         this.PageMargins.Bottom         = Convert.ToInt32((float)(((float)this.PageMargins.Bottom) / this.scaling));
         this.headerFooterMargins.Top    = Convert.ToInt32((float)(((float)this.printDocument.PageSetupData.HeaderMargin) / this.scaling));
         this.headerFooterMargins.Bottom = Convert.ToInt32((float)(((float)this.printDocument.PageSetupData.FooterMargin) / this.scaling));
         this.previewTime                = DateTime.Now;
         size5 = new Size(this.pageSize.Width - (this.PageMargins.Left + this.PageMargins.Right), this.pageSize.Height - (this.PageMargins.Top + this.PageMargins.Bottom))
         {
             Width  = Math.Max(size5.Width, 1),
             Height = Math.Max(size5.Height, 1)
         };
         this.rowColumns.Width   = size2.Width / size5.Width;
         this.rowColumns.Width  += ((size2.Width % size5.Width) > 1) ? 1 : 0;
         this.rowColumns.Width   = Math.Max(1, this.rowColumns.Width);
         this.rowColumns.Height  = size2.Height / size5.Height;
         this.rowColumns.Height += ((size2.Height % size5.Height) > 1) ? 1 : 0;
         this.rowColumns.Height  = Math.Max(1, this.rowColumns.Height);
         this.pageLayoutInfo.Clear();
         for (int i = 0; i < this.rowColumns.Height; i++)
         {
             for (int j = 0; j < this.rowColumns.Width; j++)
             {
                 Point empty = Point.Empty;
                 empty.X = (j * this.pageSize.Width) + ((j + 1) * this.PageSeparator.Width);
                 empty.Y = (i * this.pageSize.Height) + ((i + 1) * this.PageSeparator.Height);
                 Point location = Point.Empty;
                 location.X = empty.X + this.PageMargins.Left;
                 location.Y = empty.Y + this.PageMargins.Top;
                 Rectangle logicalPageBounds  = new Rectangle(j * size5.Width, i * size5.Height, size5.Width, size5.Height);
                 Rectangle pageBounds         = new Rectangle(empty, this.pageSize);
                 Rectangle viewablePageBounds = new Rectangle(location, size5);
                 this.pageLayoutInfo.Add(new PageLayoutData(logicalPageBounds, pageBounds, viewablePageBounds, new Point(j, i)));
             }
         }
     }
 }