XpsDocumentEvent.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Print / Reach / Serialization / manager / XpsDocumentEvent.cs / 1 / XpsDocumentEvent.cs

                            /*++ 

    Copyright (C) 2004- 2006 Microsoft Corporation
    All rights reserved.
 
    Module Name:
        XpsDocumentEvent.cs 
 
    Abstract:
 
    Author:
        [....] ([....]) March 2006

    Revision History: 
--*/
using System; 
using System.Collections; 
using System.Collections.Generic;
using System.Collections.Specialized; 
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Xml; 
using System.IO;
using System.Security; 
using System.Security.Permissions; 
using System.ComponentModel.Design.Serialization;
using System.Windows.Xps.Packaging; 
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Markup; 
using System.Windows.Xps;
using System.Printing; 
 
#pragma warning disable 1634, 1691 //Allows suppression of certain PreSharp messages
 
namespace System.Windows.Xps.Serialization
{
    /// 
    /// Xps Document events definition 
    /// 
    internal enum XpsDocumentEventType 
    { 
        /// 
        /// No value 
        /// 
        None  = 0,
        /// 
        /// Xps Document events AddFixedDocumentSequencePre 
        /// 
        AddFixedDocumentSequencePre = 1, 
        ///  
        /// Xps Document events AddFixedDocumentSequencePost
        ///  
        AddFixedDocumentSequencePost = 13,
        /// 
        /// Xps Document events AddFixedDocumentPre
        ///  
        AddFixedDocumentPre = 2,
        ///  
        /// Xps Document events AddFixedDocumentPost 
        /// 
        AddFixedDocumentPost = 5, 
        /// 
        /// Xps Document events AddFixedPagePre
        /// 
        AddFixedPagePre = 3, 
        /// 
        /// Xps Document events AddFixedPagePost 
        ///  
        AddFixedPagePost = 4,
        ///  
        /// Xps Document events AddFixedDocumentSequencePrintTicketPre
        /// 
        AddFixedDocumentSequencePrintTicketPre = 7,
        ///  
        /// Xps Document events AddFixedDocumentSequencePrintTicketPost
        ///  
        AddFixedDocumentSequencePrintTicketPost = 12, 
        /// 
        /// Xps Document events AddFixedDocumentPrintTicketPre 
        /// 
        AddFixedDocumentPrintTicketPre = 8,
        /// 
        /// Xps Document events AddFixedDocumentPrintTicketPost 
        /// 
        AddFixedDocumentPrintTicketPost = 11, 
        ///  
        /// Xps Document events AddFixedPagePrintTicketPre
        ///  
        AddFixedPagePrintTicketPre = 9,
        /// 
        /// Xps Document events AddFixedPagePrintTicketPost
        ///  
        AddFixedPagePrintTicketPost = 10,
        ///  
        /// Xps serialization cancelled 
        /// 
        XpsDocumentCancel = 6, 

    };

    internal class XpsDriverDocEventManager 
    {
        #region Constructor 
        ///  
        /// Constructor to create and initialize the XpsDriverDocEventManager
        ///  
        public
        XpsDriverDocEventManager(
            XpsSerializationManager     manager
            ) 
        {
            this._manager = manager; 
 
            _documentEvent = XpsDocumentEventType.None;
            _currentCount  = 0; 
            _currentPage   = 0;
            _currentDocSequence = 0;
            _currentFixedDocument = 0;
            _printTicket = null; 
            _printTicketLevel = PrintTicketLevel.None;
        } 
        #endregion Constructor 

        internal 
        void
        ForwardPackagingProgressEvent(
            Object                     sender,
            PackagingProgressEventArgs e 
            )
        { 
            switch (e.Action) 
            {
                case PackagingAction.AddingDocumentSequence: 
                {
                    _currentDocSequence = 1;
                    _currentFixedDocument = 0;
                    _currentPage = 0; 

                    _currentCount = _currentDocSequence; 
                    _documentEvent = XpsDocumentEventType.AddFixedDocumentSequencePre; 

                    OnXpsDriverDocEvent(); 
                    break;
                }
                case PackagingAction.DocumentSequenceCompleted:
                { 
                    _currentCount = _currentDocSequence;
                    _documentEvent = XpsDocumentEventType.AddFixedDocumentSequencePost; 
 
                    OnXpsDriverDocEvent();
                    break; 
                }
                case PackagingAction.AddingFixedDocument:
                {
                    _currentFixedDocument++; 
                    _currentPage = 0;
 
                    _currentCount = _currentFixedDocument; 
                    _documentEvent = XpsDocumentEventType.AddFixedDocumentPre;
 
                    OnXpsDriverDocEvent();
                    break;
                }
                case PackagingAction.FixedDocumentCompleted: 
                {
                    _currentCount = _currentFixedDocument; 
                    _documentEvent = XpsDocumentEventType.AddFixedDocumentPost; 

                    OnXpsDriverDocEvent(); 
                    break;
                }
                case PackagingAction.AddingFixedPage:
                { 
                    _currentPage++;
 
                    _currentCount = _currentPage; 
                    _documentEvent = XpsDocumentEventType.AddFixedPagePre;
 
                    OnXpsDriverDocEvent();
                    break;
                }
                case PackagingAction.FixedPageCompleted: 
                {
                    _documentEvent = XpsDocumentEventType.AddFixedPagePost; 
                    for (int i = e.NumberCompleted; i > 0; i--) 
                    {
                        _currentCount = _currentPage - i + 1; 
                        OnXpsDriverDocEvent();
                    }
                    break;
                } 
                default:
                { 
                    break; 
                }
            } 
        }

        internal
        void 
        ForwardUserPrintTicket(
            Object                                          sender, 
            XpsSerializationPrintTicketRequiredEventArgs    e 
        )
        { 
            Boolean mustCallXpsDriverDocEvent = true;

            _printTicket = e.PrintTicket;
            _printTicketLevel = e.PrintTicketLevel; 

            switch (_printTicketLevel) 
            { 
                case PrintTicketLevel.FixedDocumentSequencePrintTicket:
                { 
                    _currentCount = _currentDocSequence;
                    _documentEvent = XpsDocumentEventType.AddFixedDocumentSequencePrintTicketPre;
                    break;
                } 
                case PrintTicketLevel.FixedDocumentPrintTicket:
                { 
                    _currentCount = _currentFixedDocument; 
                    _documentEvent = XpsDocumentEventType.AddFixedDocumentPrintTicketPre;
                    break; 
                }
                case PrintTicketLevel.FixedPagePrintTicket:
                {
                    _currentCount = _currentPage + 1; 
                    _documentEvent = XpsDocumentEventType.AddFixedPagePrintTicketPre;
                    break; 
                } 
                default:
                { 
                    mustCallXpsDriverDocEvent = false;
                    break;
                }
            } 

            if (mustCallXpsDriverDocEvent) 
            { 
                XpsSerializationXpsDriverDocEventArgs xpsEventArgs = OnXpsDriverDocEvent();
 
                if (xpsEventArgs.Modified)
                {
                    e.PrintTicket = xpsEventArgs.PrintTicket;
                } 
            }
        } 
 
        internal
        void 
        ForwardSerializationCompleted(
            object                              sender,
            XpsSerializationCompletedEventArgs e
            ) 
        {
            if (e.Cancelled == true) 
            { 
                _documentEvent = XpsDocumentEventType.XpsDocumentCancel;
 
                OnXpsDriverDocEvent();
            }
        }
 
        XpsSerializationXpsDriverDocEventArgs
        OnXpsDriverDocEvent( 
            ) 
        {
            XpsSerializationXpsDriverDocEventArgs e = new XpsSerializationXpsDriverDocEventArgs(_documentEvent, 
                                                                                                _currentCount,
                                                                                                _printTicket);
            _manager.OnXpsDriverDocEvent(e);
 
            return e;
        } 
 
        private
        XpsSerializationManager         _manager; 

        private
        XpsDocumentEventType            _documentEvent;
 
        private
        int                             _currentCount; 
 
        private
        int                             _currentPage; 

        private
        int                             _currentDocSequence;
 
        private
        int                             _currentFixedDocument; 
 
        private
        PrintTicket                     _printTicket; 

        private
        PrintTicketLevel                _printTicketLevel;
 
    };
 
    ///  
    /// To be used to subscribe for get the PT which the app sends in and call XpsDocEvent
    /// into the XPS driver 
    /// 
    internal
    delegate
    void 
    XpsSerializationXpsDriverDocEventHandler(
        object sender, 
        XpsSerializationXpsDriverDocEventArgs e 
        );
 
    /// 
    ///  EventArgs for XpsSerializationXpsDriverDocEvent
    /// 
    internal class XpsSerializationXpsDriverDocEventArgs : 
                   EventArgs
    { 
        ///  
        /// ctr for XpsSerializationXpsDriverDocEventArgs
        ///  
        public
        XpsSerializationXpsDriverDocEventArgs(
            XpsDocumentEventType    documentEvent,
            int                     currentCount, 
            PrintTicket             printTicket
            ) 
        { 
            _currentCount = currentCount;
            _documentEvent = documentEvent; 
            _printTicket = printTicket;
            _modified = false;
        }
 
        /// 
        /// Current Page/Doc Index 
        ///  
        public
        int 
        CurrentCount
        {
            get
            { 
                return _currentCount;
            } 
        } 

        ///  
        /// PrintTicket
        /// 
        public
        PrintTicket 
        PrintTicket
        { 
            set 
            {
                _printTicket = value; 
                _modified = true;
            }

            get 
            {
                return _printTicket; 
            } 
        }
 
        /// 
        /// DocumentEvent
        /// 
        public 
        XpsDocumentEventType
        DocumentEvent 
        { 
            get
            { 
                return _documentEvent;
            }
        }
 
        /// 
        /// Modified 
        ///  
        internal
        bool 
        Modified
        {
            get
            { 
                return _modified;
            } 
        } 

        private 
        XpsDocumentEventType _documentEvent;

        private
        int                 _currentCount; 

        private 
        PrintTicket         _printTicket; 

        private 
        bool                _modified;

    };
} 


// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK