Example #1
0
        private void InitiateDragDrop()
        {
            WorkflowView      parentView       = ParentView;
            ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService));
            IDesignerHost     designerHost     = (IDesignerHost)GetService(typeof(IDesignerHost));

            if (selectionService == null || designerHost == null)
            {
                return;
            }

            // check if we are cutting root component
            ICollection components = selectionService.GetSelectedComponents();

            if (components == null || components.Count < 1 || selectionService.GetComponentSelected(designerHost.RootComponent) || !Helpers.AreAllActivities(components))
            {
                return;
            }

            DragDropEffects effects = DragDropEffects.None;

            try
            {
                // get component serialization service
                this.existingDraggedActivities.AddRange(Helpers.GetTopLevelActivities(components));

                //IMPORTANT: FOR WITHIN DESIGNER COMPONENT MOVE WE REMOVE THE ACTIVITIES BEFORE WE ADD THEM WHICH IS IN
                //ONDRAGDROP FUNCTION. ALTHOUGH THIS VIOLATES THE DODRAGDROP FUNCTION SIMANTICS, WE NEED TO DO THIS
                //SO THAT WE CAN USE THE SAME IDS FOR THE ACTIVITIES
                DragDropEffects allowedEffects = (DesignerHelpers.AreAssociatedDesignersMovable(this.existingDraggedActivities)) ? DragDropEffects.Move | DragDropEffects.Copy : DragDropEffects.Copy;
                IDataObject     dataObject     = CompositeActivityDesigner.SerializeActivitiesToDataObject(ParentView, this.existingDraggedActivities.ToArray());
                effects = parentView.DoDragDrop(dataObject, allowedEffects);

                //
            }
            catch (Exception e)
            {
                DesignerHelpers.ShowError(ParentView, e.Message);
            }
            finally
            {
                //This means drag drop occurred across designer
                if (effects == DragDropEffects.Move && this.existingDraggedActivities.Count > 0)
                {
                    string transactionDescription = String.Empty;
                    if (this.existingDraggedActivities.Count > 1)
                    {
                        transactionDescription = SR.GetString(SR.MoveMultipleActivities, this.existingDraggedActivities.Count);
                    }
                    else
                    {
                        transactionDescription = SR.GetString(SR.MoveSingleActivity, this.existingDraggedActivities[0].GetType());
                    }

                    CompositeActivityDesigner.RemoveActivities(ParentView, this.existingDraggedActivities.AsReadOnly(), transactionDescription);
                }

                this.existingDraggedActivities.Clear();
            }
        }
Example #2
0
        internal static object EditValue(ITypeDescriptorContext context)
        {
            object value = null;

            if (context != null && context.PropertyDescriptor != null && context.Instance != null)
            {
                BindUITypeEditor bindTypeEditor = new BindUITypeEditor();
                value = context.PropertyDescriptor.GetValue(context.Instance);

                value = bindTypeEditor.EditValue(context, context, value);

                try
                {
                    context.PropertyDescriptor.SetValue(context.Instance, value);
                }
                catch (Exception e)
                {
                    string message = SR.GetString(SR.Error_CanNotBindProperty, context.PropertyDescriptor.Name);
                    if (!String.IsNullOrEmpty(e.Message))
                    {
                        message += "\n\n" + e.Message;
                    }
                    DesignerHelpers.ShowError(context, message);
                }
            }
            return(value);
        }
 private void OnMenuPrint(object sender, EventArgs e)
 {
     if (PrinterSettings.InstalledPrinters.Count < 1)
     {
         DesignerHelpers.ShowError(this.serviceProvider, DR.GetString("ThereIsNoPrinterInstalledErrorMessage", new object[0]));
     }
     else
     {
         PrintDocument printDocument = this.workflowView.PrintDocument;
         PrintDialog   dialog        = new PrintDialog {
             AllowPrintToFile = false,
             Document         = printDocument
         };
         try
         {
             if (DialogResult.OK == dialog.ShowDialog())
             {
                 PrinterSettings printerSettings     = printDocument.PrinterSettings;
                 PageSettings    defaultPageSettings = printDocument.DefaultPageSettings;
                 printDocument.PrinterSettings     = dialog.PrinterSettings;
                 printDocument.DefaultPageSettings = dialog.Document.DefaultPageSettings;
                 printDocument.Print();
                 printDocument.PrinterSettings     = printerSettings;
                 printDocument.DefaultPageSettings = defaultPageSettings;
             }
         }
         catch (Exception exception)
         {
             string message = DR.GetString("SelectedPrinterIsInvalidErrorMessage", new object[0]) + "\n" + exception.Message;
             DesignerHelpers.ShowError(this.serviceProvider, message);
         }
     }
 }
        internal static object EditValue(ITypeDescriptorContext context)
        {
            object obj2 = null;

            if (((context != null) && (context.PropertyDescriptor != null)) && (context.Instance != null))
            {
                BindUITypeEditor editor = new BindUITypeEditor();
                obj2 = context.PropertyDescriptor.GetValue(context.Instance);
                obj2 = editor.EditValue(context, context, obj2);
                try
                {
                    context.PropertyDescriptor.SetValue(context.Instance, obj2);
                }
                catch (Exception exception)
                {
                    string message = SR.GetString("Error_CanNotBindProperty", new object[] { context.PropertyDescriptor.Name });
                    if (!string.IsNullOrEmpty(exception.Message))
                    {
                        message = message + "\n\n" + exception.Message;
                    }
                    DesignerHelpers.ShowError(context, message);
                }
            }
            return(obj2);
        }
Example #5
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider serviceProvider, object value)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            this.serviceProvider = serviceProvider;

            object returnValue = value;

            if (context != null && context.PropertyDescriptor is DynamicPropertyDescriptor)
            {
                try
                {
                    using (ActivityBindForm bindDialog = new ActivityBindForm(this.serviceProvider, context))
                    {
                        if (DialogResult.OK == bindDialog.ShowDialog())
                        {
                            //Now that OK has been pressed in the dialog we need to create members if necessary
                            if (bindDialog.CreateNew)
                            {
                                //Emit the field / property as required
                                if (bindDialog.CreateNewProperty)
                                {
                                    List <CustomProperty> properties = CustomActivityDesignerHelper.GetCustomProperties(context);
                                    if (properties != null)
                                    {
                                        properties.Add(CustomProperty.CreateCustomProperty(this.serviceProvider, bindDialog.NewMemberName, context.PropertyDescriptor, context.Instance));
                                        CustomActivityDesignerHelper.SetCustomProperties(properties, context);
                                    }
                                }
                                else
                                {
                                    ActivityBindPropertyDescriptor.CreateField(context, bindDialog.Binding, true);
                                }
                            }
                            returnValue = bindDialog.Binding;
                        }
                    }
                }
                catch (Exception e)
                {
                    string message = SR.GetString(SR.Error_CanNotBindProperty, context.PropertyDescriptor.Name);
                    if (!String.IsNullOrEmpty(e.Message))
                    {
                        message += "\n\n" + e.Message;
                    }
                    DesignerHelpers.ShowError(context, message);
                }
            }
            else
            {
                DesignerHelpers.ShowError(this.serviceProvider, SR.GetString(SR.Error_MultipleSelectNotSupportedForBindAndPromote));
            }

            return(returnValue);
        }
        protected override void OnBeginPrint(PrintEventArgs printArgs)
        {
            base.OnBeginPrint(printArgs);
            this.currentPrintablePage = Point.Empty;
            bool flag = (base.PrinterSettings.IsValid && (PrinterSettings.InstalledPrinters.Count > 0)) && new ArrayList(PrinterSettings.InstalledPrinters).Contains(base.PrinterSettings.PrinterName);

            if (!flag)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString("SelectedPrinterIsInvalidErrorMessage", new object[0]));
            }
            printArgs.Cancel = !flag || (this.workflowView.RootDesigner == null);
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider serviceProvider, object value)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            this.serviceProvider = serviceProvider;
            object obj2 = value;

            if ((context != null) && (context.PropertyDescriptor is DynamicPropertyDescriptor))
            {
                try
                {
                    using (ActivityBindForm form = new ActivityBindForm(this.serviceProvider, context))
                    {
                        if (DialogResult.OK != form.ShowDialog())
                        {
                            return(obj2);
                        }
                        if (form.CreateNew)
                        {
                            if (form.CreateNewProperty)
                            {
                                List <CustomProperty> customProperties = CustomActivityDesignerHelper.GetCustomProperties(context);
                                if (customProperties != null)
                                {
                                    customProperties.Add(CustomProperty.CreateCustomProperty(this.serviceProvider, form.NewMemberName, context.PropertyDescriptor, context.Instance));
                                    CustomActivityDesignerHelper.SetCustomProperties(customProperties, context);
                                }
                            }
                            else
                            {
                                ActivityBindPropertyDescriptor.CreateField(context, form.Binding, true);
                            }
                        }
                        return(form.Binding);
                    }
                }
                catch (Exception exception)
                {
                    string message = SR.GetString("Error_CanNotBindProperty", new object[] { context.PropertyDescriptor.Name });
                    if (!string.IsNullOrEmpty(exception.Message))
                    {
                        message = message + "\n\n" + exception.Message;
                    }
                    DesignerHelpers.ShowError(context, message);
                }
                return(obj2);
            }
            DesignerHelpers.ShowError(this.serviceProvider, SR.GetString("Error_MultipleSelectNotSupportedForBindAndPromote"));
            return(obj2);
        }
 private void OnMenuPageSetup(object sender, EventArgs e)
 {
     if (PrinterSettings.InstalledPrinters.Count < 1)
     {
         DesignerHelpers.ShowError(this.serviceProvider, DR.GetString("ThereIsNoPrinterInstalledErrorMessage", new object[0]));
     }
     else
     {
         WorkflowPageSetupDialog dialog = new WorkflowPageSetupDialog(this.serviceProvider);
         if (DialogResult.OK == dialog.ShowDialog())
         {
             this.workflowView.PerformLayout(false);
         }
     }
 }
Example #9
0
        protected override void OnBeginPrint(PrintEventArgs printArgs)
        {
            base.OnBeginPrint(printArgs);

            this.currentPrintablePage = Point.Empty;

            //Validate the printer
            bool validPrinter = (PrinterSettings.IsValid &&
                                 PrinterSettings.InstalledPrinters.Count > 0 &&
                                 new ArrayList(PrinterSettings.InstalledPrinters).Contains(PrinterSettings.PrinterName));

            if (!validPrinter)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString(DR.SelectedPrinterIsInvalidErrorMessage));
            }

            printArgs.Cancel = (!validPrinter || this.workflowView.RootDesigner == null);
        }
        private void InitiateDragDrop()
        {
            WorkflowView      parentView = base.ParentView;
            ISelectionService service    = (ISelectionService)base.GetService(typeof(ISelectionService));
            IDesignerHost     host       = (IDesignerHost)base.GetService(typeof(IDesignerHost));

            if ((service != null) && (host != null))
            {
                ICollection selectedComponents = service.GetSelectedComponents();
                if (((selectedComponents != null) && (selectedComponents.Count >= 1)) && (!service.GetComponentSelected(host.RootComponent) && Helpers.AreAllActivities(selectedComponents)))
                {
                    DragDropEffects none = DragDropEffects.None;
                    try
                    {
                        this.existingDraggedActivities.AddRange(Helpers.GetTopLevelActivities(selectedComponents));
                        DragDropEffects allowedEffects = DesignerHelpers.AreAssociatedDesignersMovable(this.existingDraggedActivities) ? (DragDropEffects.Move | DragDropEffects.Copy) : DragDropEffects.Copy;
                        IDataObject     data           = CompositeActivityDesigner.SerializeActivitiesToDataObject(base.ParentView, this.existingDraggedActivities.ToArray());
                        none = parentView.DoDragDrop(data, allowedEffects);
                    }
                    catch (Exception exception)
                    {
                        DesignerHelpers.ShowError(base.ParentView, exception.Message);
                    }
                    finally
                    {
                        if ((none == DragDropEffects.Move) && (this.existingDraggedActivities.Count > 0))
                        {
                            string transactionDescription = string.Empty;
                            if (this.existingDraggedActivities.Count > 1)
                            {
                                transactionDescription = SR.GetString("MoveMultipleActivities", new object[] { this.existingDraggedActivities.Count });
                            }
                            else
                            {
                                transactionDescription = SR.GetString("MoveSingleActivity", new object[] { this.existingDraggedActivities[0].GetType() });
                            }
                            CompositeActivityDesigner.RemoveActivities(base.ParentView, this.existingDraggedActivities.AsReadOnly(), transactionDescription);
                        }
                        this.existingDraggedActivities.Clear();
                    }
                }
            }
        }
Example #11
0
        protected override bool OnDragDrop(DragEventArgs eventArgs)
        {
            //Invalidate the entire rectangle so that we draw active placement glyphs on connectors
            WorkflowView parentView = ParentView;

            parentView.InvalidateClientRectangle(Rectangle.Empty);

            //By default we do not allow any drag drop operation
            eventArgs.Effect = DragDropEffects.None;

            DestroyDragFeedbackImages();

            //Get the coordinates
            Point clientPoint  = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y));
            Point logicalPoint = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y));

            //Now we check if the drag drop was in any valid area, if not then do not proceed further
            if (!parentView.IsClientPointInActiveLayout(clientPoint))
            {
                if (this.dropTargetDesigner != null)
                {
                    ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                }
                this.wasCtrlKeyPressed  = false;
                this.dropTargetDesigner = null;
                this.draggedActivities.Clear();
                return(false);
            }

            //Now we have a potential for successful drag drop, so construct drag event arguments with logical coordinates
            this.wasCtrlKeyPressed = ((eventArgs.KeyState & 8) == 8);
            ActivityDragEventArgs dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, this.draggedActivities);

            //Now check which designer is under the cursor, if we have the same designer as the old one
            //If not then we set the new one as drop target and pump in messages
            HitTestInfo hitTestInfo = MessageHitTestContext;

            if (this.dropTargetDesigner != hitTestInfo.AssociatedDesigner)
            {
                if (this.dropTargetDesigner != null)
                {
                    ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                    this.dropTargetDesigner = null;
                }

                if (hitTestInfo.AssociatedDesigner != null)
                {
                    this.dropTargetDesigner = hitTestInfo.AssociatedDesigner;
                    if (this.dropTargetDesigner != null)
                    {
                        ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(dragdropEventArgs);
                    }
                }
            }

            //We now have appropriate droptarget designer
            try
            {
                if (this.dropTargetDesigner != null)
                {
                    //We do not allow recursive drag and drop
                    if (!this.wasCtrlKeyPressed && IsRecursiveDropOperation(this.dropTargetDesigner) ||
                        (this.dropTargetDesigner is CompositeActivityDesigner && !((CompositeActivityDesigner)this.dropTargetDesigner).IsEditable))
                    {
                        ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                        dragdropEventArgs.Effect = DragDropEffects.None;
                    }
                    else
                    {
                        // IMPORTANT: Don't use draggedActivities variable, because components which are
                        // there may not be created using the assembly references  added to ITypeResultionService
                        // this.workflowView.time the components will be created using the assembly references got added to the project
                        List <Activity> droppedActivities      = new List <Activity>();
                        string          transactionDescription = SR.GetString(SR.DragDropActivities);

                        //This means that we are trying to move activities so we use the same activities for drop
                        if (!this.wasCtrlKeyPressed && this.existingDraggedActivities.Count > 0)
                        {
                            droppedActivities.AddRange(this.existingDraggedActivities);
                            if (droppedActivities.Count > 1)
                            {
                                transactionDescription = SR.GetString(SR.MoveMultipleActivities, droppedActivities.Count);
                            }
                            else if (droppedActivities.Count == 1)
                            {
                                transactionDescription = SR.GetString(SR.MoveSingleActivity, droppedActivities[0].GetType());
                            }
                        }
                        else
                        {
                            droppedActivities.AddRange(CompositeActivityDesigner.DeserializeActivitiesFromDataObject(ParentView, eventArgs.Data, true));
                            if (droppedActivities.Count > 0)
                            {
                                transactionDescription = SR.GetString(SR.CreateActivityFromToolbox, droppedActivities[0].GetType());
                            }
                        }

                        //Now that we have what needs to be dropped, we start the actual drag and drop
                        IDesignerHost       designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost;
                        DesignerTransaction transaction  = null;
                        if (droppedActivities.Count > 0)
                        {
                            transaction = designerHost.CreateTransaction(transactionDescription);
                        }

                        dragdropEventArgs = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, logicalPoint, droppedActivities);

                        try
                        {
                            ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragDrop(dragdropEventArgs);

                            if (dragdropEventArgs.Effect == DragDropEffects.Move)
                            {
                                this.existingDraggedActivities.Clear();
                            }

                            if (transaction != null)
                            {
                                transaction.Commit();
                            }
                        }
                        catch (Exception e)
                        {
                            if (transaction != null)
                            {
                                transaction.Cancel();
                            }
                            throw e;
                        }

                        //We deserialize the designers and try to store the designer states
                        if (droppedActivities.Count > 0)
                        {
                            Stream componentStateStream = eventArgs.Data.GetData(DragDropManager.CF_DESIGNERSTATE) as Stream;
                            if (componentStateStream != null)
                            {
                                Helpers.DeserializeDesignersFromStream(droppedActivities, componentStateStream);
                            }

                            //Set the current selection
                            ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService));
                            if (selectionService != null)
                            {
                                selectionService.SetSelectedComponents(droppedActivities, SelectionTypes.Replace);
                            }
                        }

                        //Active the design surface
                        if (designerHost != null)
                        {
                            designerHost.Activate();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //We purposely consume application thrown exception which are result of user cancelling the action
                //during dragdrop where we popup UI Wizards during drag drop. Ref: InvokeWebService
                ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                dragdropEventArgs.Effect = DragDropEffects.None;

                string dragDropException = ex.Message;
                if (ex.InnerException != null && !String.IsNullOrEmpty(ex.InnerException.Message))
                {
                    dragDropException = ex.InnerException.Message;
                }

                string errorMessage = DR.GetString(DR.Error_FailedToDeserializeComponents);
                errorMessage += "\r\n" + DR.GetString(DR.Error_Reason, dragDropException);
                DesignerHelpers.ShowError(ParentView, errorMessage);

                if (ex != CheckoutException.Canceled)
                {
                    throw new Exception(errorMessage, ex);
                }
            }
            finally
            {
                //Make sure that mouse over designer is set to null
                this.wasCtrlKeyPressed = false;
                this.draggedActivities.Clear();
                this.dropTargetDesigner  = null;
                this.exceptionInDragDrop = false;
                eventArgs.Effect         = dragdropEventArgs.Effect;
            }

            return(true);
        }
        protected override bool OnDragDrop(DragEventArgs eventArgs)
        {
            WorkflowView parentView = base.ParentView;

            parentView.InvalidateClientRectangle(Rectangle.Empty);
            eventArgs.Effect = DragDropEffects.None;
            this.DestroyDragFeedbackImages();
            Point clientPoint = parentView.PointToClient(new Point(eventArgs.X, eventArgs.Y));
            Point point       = parentView.ScreenPointToLogical(new Point(eventArgs.X, eventArgs.Y));

            if (!parentView.IsClientPointInActiveLayout(clientPoint))
            {
                if (this.dropTargetDesigner != null)
                {
                    ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                }
                this.wasCtrlKeyPressed  = false;
                this.dropTargetDesigner = null;
                this.draggedActivities.Clear();
                return(false);
            }
            this.wasCtrlKeyPressed = (eventArgs.KeyState & 8) == 8;
            ActivityDragEventArgs e = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, point, this.draggedActivities);

            System.Workflow.ComponentModel.Design.HitTestInfo messageHitTestContext = base.MessageHitTestContext;
            if (this.dropTargetDesigner != messageHitTestContext.AssociatedDesigner)
            {
                if (this.dropTargetDesigner != null)
                {
                    ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                    this.dropTargetDesigner = null;
                }
                if (messageHitTestContext.AssociatedDesigner != null)
                {
                    this.dropTargetDesigner = messageHitTestContext.AssociatedDesigner;
                    if (this.dropTargetDesigner != null)
                    {
                        ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragEnter(e);
                    }
                }
            }
            try
            {
                if (this.dropTargetDesigner != null)
                {
                    if ((!this.wasCtrlKeyPressed && this.IsRecursiveDropOperation(this.dropTargetDesigner)) || ((this.dropTargetDesigner is CompositeActivityDesigner) && !((CompositeActivityDesigner)this.dropTargetDesigner).IsEditable))
                    {
                        ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                        e.Effect = DragDropEffects.None;
                    }
                    else
                    {
                        List <Activity> draggedActivities = new List <Activity>();
                        string          description       = SR.GetString("DragDropActivities");
                        if (!this.wasCtrlKeyPressed && (this.existingDraggedActivities.Count > 0))
                        {
                            draggedActivities.AddRange(this.existingDraggedActivities);
                            if (draggedActivities.Count > 1)
                            {
                                description = SR.GetString("MoveMultipleActivities", new object[] { draggedActivities.Count });
                            }
                            else if (draggedActivities.Count == 1)
                            {
                                description = SR.GetString("MoveSingleActivity", new object[] { draggedActivities[0].GetType() });
                            }
                        }
                        else
                        {
                            draggedActivities.AddRange(CompositeActivityDesigner.DeserializeActivitiesFromDataObject(base.ParentView, eventArgs.Data, true));
                            if (draggedActivities.Count > 0)
                            {
                                description = SR.GetString("CreateActivityFromToolbox", new object[] { draggedActivities[0].GetType() });
                            }
                        }
                        IDesignerHost       host        = base.GetService(typeof(IDesignerHost)) as IDesignerHost;
                        DesignerTransaction transaction = null;
                        if (draggedActivities.Count > 0)
                        {
                            transaction = host.CreateTransaction(description);
                        }
                        e = new ActivityDragEventArgs(eventArgs, this.dragInitiationPoint, point, draggedActivities);
                        try
                        {
                            ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragDrop(e);
                            if (e.Effect == DragDropEffects.Move)
                            {
                                this.existingDraggedActivities.Clear();
                            }
                            if (transaction != null)
                            {
                                transaction.Commit();
                            }
                        }
                        catch (Exception exception)
                        {
                            if (transaction != null)
                            {
                                transaction.Cancel();
                            }
                            throw exception;
                        }
                        if (draggedActivities.Count > 0)
                        {
                            Stream data = eventArgs.Data.GetData("CF_WINOEDESIGNERCOMPONENTSSTATE") as Stream;
                            if (data != null)
                            {
                                Helpers.DeserializeDesignersFromStream(draggedActivities, data);
                            }
                            ISelectionService service = (ISelectionService)base.GetService(typeof(ISelectionService));
                            if (service != null)
                            {
                                service.SetSelectedComponents(draggedActivities, SelectionTypes.Replace);
                            }
                        }
                        if (host != null)
                        {
                            host.Activate();
                        }
                    }
                }
            }
            catch (Exception exception2)
            {
                ((IWorkflowDesignerMessageSink)this.dropTargetDesigner).OnDragLeave();
                e.Effect = DragDropEffects.None;
                string message = exception2.Message;
                if ((exception2.InnerException != null) && !string.IsNullOrEmpty(exception2.InnerException.Message))
                {
                    message = exception2.InnerException.Message;
                }
                string str3 = DR.GetString("Error_FailedToDeserializeComponents", new object[0]) + "\r\n" + DR.GetString("Error_Reason", new object[] { message });
                DesignerHelpers.ShowError(base.ParentView, str3);
                if (exception2 != CheckoutException.Canceled)
                {
                    throw new Exception(str3, exception2);
                }
            }
            finally
            {
                this.wasCtrlKeyPressed = false;
                this.draggedActivities.Clear();
                this.dropTargetDesigner  = null;
                this.exceptionInDragDrop = false;
                eventArgs.Effect         = e.Effect;
            }
            return(true);
        }
        protected override void OnPrintPage(PrintPageEventArgs printPageArg)
        {
            base.OnPrintPage(printPageArg);
            AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
            Graphics     graphics     = printPageArg.Graphics;

            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode     = SmoothingMode.HighQuality;
            if (this.currentPrintablePage.IsEmpty)
            {
                this.PrepareToPrint(printPageArg);
            }
            Margins   hardMargins = this.GetHardMargins(graphics);
            Margins   margins2    = new Margins(Math.Max(printPageArg.PageSettings.Margins.Left, hardMargins.Left), Math.Max(printPageArg.PageSettings.Margins.Right, hardMargins.Right), Math.Max(printPageArg.PageSettings.Margins.Top, hardMargins.Top), Math.Max(printPageArg.PageSettings.Margins.Bottom, hardMargins.Bottom));
            Size      size        = new Size(printPageArg.PageBounds.Size.Width - (margins2.Left + margins2.Right), printPageArg.PageBounds.Size.Height - (margins2.Top + margins2.Bottom));
            Rectangle rect        = new Rectangle(margins2.Left, margins2.Top, size.Width, size.Height);
            Region    region      = new Region(rect);

            try
            {
                graphics.TranslateTransform((float)-hardMargins.Left, (float)-hardMargins.Top);
                graphics.FillRectangle(ambientTheme.BackgroundBrush, rect);
                graphics.DrawRectangle(ambientTheme.ForegroundPen, rect);
                if (ambientTheme.WorkflowWatermarkImage != null)
                {
                    ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, rect, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, 0.25f, false);
                }
                Matrix transform = graphics.Transform;
                Region clip      = graphics.Clip;
                graphics.Clip = region;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                Point point = new Point((this.currentPrintablePage.X * size.Width) - this.workflowAlignment.X, (this.currentPrintablePage.Y * size.Height) - this.workflowAlignment.Y);
                graphics.TranslateTransform((float)(rect.Left - point.X), (float)(rect.Top - point.Y));
                graphics.ScaleTransform(this.scaling, this.scaling);
                Size empty = Size.Empty;
                empty.Width  = Convert.ToInt32(Math.Ceiling((double)(((float)size.Width) / this.scaling)));
                empty.Height = Convert.ToInt32(Math.Ceiling((double)(((float)size.Height) / this.scaling)));
                Point point2 = Point.Empty;
                point2.X = Convert.ToInt32(Math.Ceiling((double)(((float)this.workflowAlignment.X) / this.scaling)));
                point2.Y = Convert.ToInt32(Math.Ceiling((double)(((float)this.workflowAlignment.Y) / this.scaling)));
                Rectangle viewPort = new Rectangle((this.currentPrintablePage.X * empty.Width) - point2.X, (this.currentPrintablePage.Y * empty.Height) - point2.Y, empty.Width, empty.Height);
                using (PaintEventArgs args = new PaintEventArgs(graphics, this.workflowView.RootDesigner.Bounds))
                {
                    ((IWorkflowDesignerMessageSink)this.workflowView.RootDesigner).OnPaint(args, viewPort);
                }
                graphics.Clip      = clip;
                graphics.Transform = transform;
                HeaderFooterData headerFooterPrintData = new HeaderFooterData {
                    Font       = ambientTheme.Font,
                    PageBounds = printPageArg.PageBounds,
                    PageBoundsWithoutMargin = rect,
                    HeaderFooterMargins     = new Margins(0, 0, this.pageSetupData.HeaderMargin, this.pageSetupData.FooterMargin),
                    PrintTime   = this.printTime,
                    CurrentPage = (this.currentPrintablePage.X + (this.currentPrintablePage.Y * this.totalPrintablePages.X)) + 1,
                    TotalPages  = this.totalPrintablePages.X * this.totalPrintablePages.Y,
                    Scaling     = this.scaling
                };
                WorkflowDesignerLoader service = ((IServiceProvider)this.workflowView).GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                headerFooterPrintData.FileName = (service != null) ? service.FileName : string.Empty;
                if (this.pageSetupData.HeaderTemplate.Length > 0)
                {
                    this.PrintHeaderFooter(graphics, true, headerFooterPrintData);
                }
                if (this.pageSetupData.FooterTemplate.Length > 0)
                {
                    this.PrintHeaderFooter(graphics, false, headerFooterPrintData);
                }
                printPageArg.HasMorePages = this.MoveNextPage();
            }
            catch (Exception exception)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString("SelectedPrinterIsInvalidErrorMessage", new object[0]) + "\n" + exception.Message);
                printPageArg.Cancel       = true;
                printPageArg.HasMorePages = false;
            }
            finally
            {
                region.Dispose();
            }
            if (!printPageArg.HasMorePages)
            {
                this.workflowView.PerformLayout();
            }
        }
Example #14
0
        protected override void OnPrintPage(PrintPageEventArgs printPageArg)
        {
            base.OnPrintPage(printPageArg);

            AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;

            Graphics graphics = printPageArg.Graphics;

            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            graphics.SmoothingMode     = SmoothingMode.HighQuality;

            //STEP1: We get the printer graphics only in the OnPrintPage function hence for layouting we need to call this function
            if (this.currentPrintablePage.IsEmpty)
            {
                PrepareToPrint(printPageArg);
            }

            //STEP2: GET ALL THE VALUES NEEDED FOR CALCULATION
            Margins hardMargins = GetHardMargins(graphics);
            Margins margins     = new Margins(Math.Max(printPageArg.PageSettings.Margins.Left, hardMargins.Left),
                                              Math.Max(printPageArg.PageSettings.Margins.Right, hardMargins.Right),
                                              Math.Max(printPageArg.PageSettings.Margins.Top, hardMargins.Top),
                                              Math.Max(printPageArg.PageSettings.Margins.Bottom, hardMargins.Bottom));
            Size      printableArea     = new Size(printPageArg.PageBounds.Size.Width - (margins.Left + margins.Right), printPageArg.PageBounds.Size.Height - (margins.Top + margins.Bottom));
            Rectangle boundingRectangle = new Rectangle(margins.Left, margins.Top, printableArea.Width, printableArea.Height);
            Region    clipRegion        = new Region(boundingRectangle);

            try
            {
                graphics.TranslateTransform(-hardMargins.Left, -hardMargins.Top);
                graphics.FillRectangle(ambientTheme.BackgroundBrush, boundingRectangle);
                graphics.DrawRectangle(ambientTheme.ForegroundPen, boundingRectangle);

                //Draw the watermark image
                if (ambientTheme.WorkflowWatermarkImage != null)
                {
                    ActivityDesignerPaint.DrawImage(graphics, ambientTheme.WorkflowWatermarkImage, boundingRectangle, new Rectangle(Point.Empty, ambientTheme.WorkflowWatermarkImage.Size), ambientTheme.WatermarkAlignment, AmbientTheme.WatermarkTransparency, false);
                }

                Matrix oldTransform  = graphics.Transform;
                Region oldClipRegion = graphics.Clip;
                graphics.Clip = clipRegion;
                graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                //STEP3: PRINT
                //Printer bitmap starts at the unprintable top left corner, hence, need to take it into account - move by the unprintable area:
                //Setup the translation and scaling for the page printing
                Point pageOffset = new Point(this.currentPrintablePage.X * printableArea.Width - this.workflowAlignment.X, this.currentPrintablePage.Y * printableArea.Height - this.workflowAlignment.Y);
                graphics.TranslateTransform(boundingRectangle.Left - pageOffset.X, boundingRectangle.Top - pageOffset.Y);
                graphics.ScaleTransform(this.scaling, this.scaling);

                //Calculate the viewport by reverse scaling the printable area size
                Size viewPortSize = Size.Empty;
                viewPortSize.Width  = Convert.ToInt32(Math.Ceiling((float)printableArea.Width / this.scaling));
                viewPortSize.Height = Convert.ToInt32(Math.Ceiling((float)printableArea.Height / this.scaling));

                Point scaledAlignment = Point.Empty;
                scaledAlignment.X = Convert.ToInt32(Math.Ceiling((float)this.workflowAlignment.X / this.scaling));
                scaledAlignment.Y = Convert.ToInt32(Math.Ceiling((float)this.workflowAlignment.Y / this.scaling));

                Rectangle viewPort = new Rectangle(this.currentPrintablePage.X * viewPortSize.Width - scaledAlignment.X, this.currentPrintablePage.Y * viewPortSize.Height - scaledAlignment.Y, viewPortSize.Width, viewPortSize.Height);

                using (PaintEventArgs paintEventArgs = new PaintEventArgs(graphics, this.workflowView.RootDesigner.Bounds))
                {
                    ((IWorkflowDesignerMessageSink)this.workflowView.RootDesigner).OnPaint(paintEventArgs, viewPort);
                }

                graphics.Clip      = oldClipRegion;
                graphics.Transform = oldTransform;

                //Now prepare the graphics for header footer printing
                HeaderFooterData headerFooterData = new HeaderFooterData();
                headerFooterData.Font       = ambientTheme.Font;
                headerFooterData.PageBounds = printPageArg.PageBounds;
                headerFooterData.PageBoundsWithoutMargin = boundingRectangle;
                headerFooterData.HeaderFooterMargins     = new Margins(0, 0, this.pageSetupData.HeaderMargin, this.pageSetupData.FooterMargin);
                headerFooterData.PrintTime   = this.printTime;
                headerFooterData.CurrentPage = this.currentPrintablePage.X + this.currentPrintablePage.Y * this.totalPrintablePages.X + 1;
                headerFooterData.TotalPages  = this.totalPrintablePages.X * this.totalPrintablePages.Y;
                headerFooterData.Scaling     = this.scaling;
                WorkflowDesignerLoader serviceDesignerLoader = ((IServiceProvider)this.workflowView).GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;
                headerFooterData.FileName = (serviceDesignerLoader != null) ? serviceDesignerLoader.FileName : String.Empty;

                //Print the header
                if (this.pageSetupData.HeaderTemplate.Length > 0)
                {
                    PrintHeaderFooter(graphics, true, headerFooterData);
                }

                //footer
                if (this.pageSetupData.FooterTemplate.Length > 0)
                {
                    PrintHeaderFooter(graphics, false, headerFooterData);
                }

                //are there more pages left?
                printPageArg.HasMorePages = MoveNextPage();
            }
            catch (Exception exception)
            {
                DesignerHelpers.ShowError(this.workflowView, DR.GetString(DR.SelectedPrinterIsInvalidErrorMessage) + "\n" + exception.Message);
                printPageArg.Cancel       = true;
                printPageArg.HasMorePages = false;
            }
            finally
            {
                clipRegion.Dispose();
            }

            if (!printPageArg.HasMorePages)
            {
                this.workflowView.PerformLayout(); //no more pages - redo regular layout using screen graphics
            }
        }