StatusInfoItem.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 / TrustUi / MS / Internal / documents / Application / StatusInfoItem.cs / 1 / StatusInfoItem.cs

                            //---------------------------------------------------------------------------- 
//
// 
//    Copyright (C) Microsoft Corporation.  All rights reserved.
//  
//
// Description: Used to control an (RM or DigSig) InfoBar and ToolBar item in MongooseUI 
// 
// History:
//  06/22/2005 - [....] created 
//
//---------------------------------------------------------------------------

using MS.Internal.Documents; 
using System;
using System.Globalization; 
using System.Windows; 
using System.Windows.Controls;
using System.Windows.Shapes; 
using System.Windows.TrustUI;

namespace MS.Internal.Documents.Application
{ 

    ///  
    /// The type of StatusInfoItem (DigSig, RM) 
    /// 
    internal enum StatusInfoItemType 
    {
        Unknown,
        DigSig,
        RM, 
    }
 
    ///  
    /// Class used to control an item of the InfoBar, and the relevant ToolBar Button.
    ///  
    internal class StatusInfoItem
    {
        //-----------------------------------------------------
        // 
        //  Constructors
        // 
        //----------------------------------------------------- 
        /// 
        /// Constructs a new StatusInfoItem 
        /// 
        /// Type of Item
        /// InfoBar button to update
        /// ToolBar button to update 
        public StatusInfoItem(StatusInfoItemType type, Button infoBarButton, Control toolBarControl)
        { 
            // Set Type 
            _type = type;
 
            // If InfoBar button is not null, set references to the Icon and Text.
            if (infoBarButton != null)
            {
                _infoBarButton = infoBarButton; 
                _infoBarIcon = infoBarButton.Template.FindName("PUIInfoBarIcon", infoBarButton) as Rectangle;
                _infoBarText = infoBarButton.Template.FindName("PUIInfoBarText", infoBarButton) as TextBlock; 
            } 
            // Set ToolBar button reference.
            if (toolBarControl != null) 
            {
                _toolBarControl = toolBarControl;
            }
        } 

        //------------------------------------------------------ 
        // 
        //  Public Properties
        // 
        //-----------------------------------------------------

        /// 
        /// Controls the visibility of the InfoBar button. 
        /// 
        public Visibility Visibility 
        { 
            get
            { 
                return _infoBarButton.Visibility;
            }
            set
            { 
                _infoBarButton.Visibility = value;
                // When the Visibility is set, notify the DocumentViewer to check the visibility 
                // of the entire InfoBar 
                if (InfoBarVisibilityChanged != null)
                { 
                    InfoBarVisibilityChanged(this, new EventArgs());
                }
            }
        } 

        //------------------------------------------------------ 
        // 
        //  Public Events
        // 
        //------------------------------------------------------

        /// 
        /// Fired whenever the visibility has been set on the StatusInfoItem, useful for determining 
        /// if the InfoBar should be hidden.
        ///  
        public event EventHandler InfoBarVisibilityChanged; 

        //----------------------------------------------------- 
        //
        //  Public Methods
        //
        //------------------------------------------------------ 

        ///  
        /// Used to be notified of possible DigSig status changes. 
        /// 
        ///  
        /// 
        public void OnStatusChange(object sender, DocumentSignatureManager.SignatureStatusEventArgs args)
        {
            if ((args != null) && (_type == StatusInfoItemType.DigSig)) 
            {
                UpdateUI(args.StatusResources); 
 
                // If the Document is not signed, collapse the infobar button.
                if (args.SignatureStatus != SignatureStatus.NotSigned) 
                {
                    this.Visibility = Visibility.Visible;
                }
                else 
                {
                    this.Visibility = Visibility.Collapsed; 
                } 
            }
        } 

        /// 
        /// Used to be notified of possible RM status changes.
        ///  
        /// 
        ///  
        public void OnStatusChange(object sender, DocumentRightsManagementManager.RightsManagementStatusEventArgs args) 
        {
            if ((args != null) && (_type == StatusInfoItemType.RM)) 
            {
                UpdateUI(args.StatusResources);

                // If the Document is not RM protected, collapse the infobar button. 
                if (args.RMStatus == RightsManagementStatus.Protected)
                { 
                    this.Visibility = Visibility.Visible; 
                }
                else 
                {
                    this.Visibility = Visibility.Collapsed;
                }
            } 
        }
 
        //----------------------------------------------------- 
        //
        //  Private Methods 
        //
        //-----------------------------------------------------

        ///  
        /// Used to change the Icons and Text of the InfoBarItems and ToolBarButton.
        ///  
        ///  
        /// 
        /// This function directly updates the UI with information that may be 
        /// used for trust decisions by the user. Since the UI is displayed in
        /// Avalon controls, however, untrusted callers can directly modify the
        /// information displayed. As a result making this method critical does
        /// not add any protection. 
        /// 
        private void UpdateUI(DocumentStatusResources resources) 
        { 
            if (_infoBarIcon != null)
            { 
                // Set the InfoBar Image
                _infoBarIcon.Fill = resources.Image;
            }
 
            if (_infoBarText != null)
            { 
                // Set the InfoBar Text 
                _infoBarText.Text = resources.Text;
            } 

            if (_infoBarButton != null)
            {
                // Set the InfoBar ToolTip 
                _infoBarButton.ToolTip = resources.ToolTip;
            } 
 
            if (_toolBarControl != null)
            { 
                // Set the ToolBarButton Image and ToolTip
                _toolBarControl.Background = resources.Image;
                _toolBarControl.ToolTip = resources.ToolTip;
            } 
        }
 
 
        //-----------------------------------------------------
        // 
        //  Private Fields
        //
        //------------------------------------------------------
 
        private StatusInfoItemType      _type;
        private Rectangle               _infoBarIcon; 
        private TextBlock               _infoBarText; 
        private Button                  _infoBarButton;
        private Control                 _toolBarControl; 
    }

}

// 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