Click here to Skip to main content
15,895,746 members
Articles / Programming Languages / C#

SharpPrivacy - OpenPGP for C#

Rate me:
Please Sign up or sign in to vote.
4.92/5 (86 votes)
7 Jun 200314 min read 354.3K   8.4K   227  
SharpPrivacy is an OpenPGP implementation in C#. It can be used to encrypt and sign data, created OpenPGP compatible keys, and a lot more. This article explains how to use the library in your own .NET application or webpage to encrypt, sign, decrypt or verify OpenPGP messages.
// *****************************************************************************
// 
//  (c) Crownwood Consulting Limited 2002-2003
//  All rights reserved. The software and associated documentation 
//  supplied hereunder are the proprietary information of Crownwood Consulting 
//	Limited, Crownwood, Bracknell, Berkshire, England and are supplied subject 
//  to licence terms.
// 
//  Magic Version 1.7.4.0 	www.dotnetmagic.com
// *****************************************************************************

using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
using Crownwood.Magic.Collections;

namespace Crownwood.Magic.Docking
{
    [ToolboxItem(false)]
    public class Window : ContainerControl
    {
        // Instance fields
        protected State _state;
        protected Zone _parentZone;
        protected WindowDetailCollection _windowDetails;
        protected Decimal _zoneArea;
        protected Size _minimalSize;
        protected DockingManager _manager;
        protected bool _autoDispose;
        protected bool _redockAllowed;
        protected bool _floatingCaption;
        protected bool _contentCaption;
        protected string _fullTitle;

        // Instance events
        public event EventHandler FullTitleChanged; 

        public Window(DockingManager manager)
        {
            // Must provide a valid manager instance
            if (manager == null)
                throw new ArgumentNullException("DockingManager");

            // Default object state
            _state = State.Floating;
            _parentZone = null;
            _zoneArea = 100m;
            _minimalSize = new Size(0,0);
            _manager = manager;
            _autoDispose = true;
            _fullTitle = "";
            _redockAllowed = true;
            _floatingCaption = true;
            _contentCaption = true;

            // Create collection of window details
            _windowDetails = new WindowDetailCollection();

            // We want notification when window details are added/removed/cleared
            _windowDetails.Clearing += new CollectionClear(OnDetailsClearing);
            _windowDetails.Inserted += new CollectionChange(OnDetailInserted);
            _windowDetails.Removing += new CollectionChange(OnDetailRemoving);
        }

        public DockingManager DockingManager
        {
            get { return _manager; }
        }

        public State State
        {
            get { return _state; }
			
            set 
            {
                if (_state != value)
                {
                    _state = value;

                    // Inform each window detail of the change in state
                    foreach(WindowDetail wd in _windowDetails)
                        wd.ParentStateChanged(_state);
                }
            }
        }

        public Zone ParentZone
        {
            get { return _parentZone; }
			
            set 
            { 
                if (_parentZone != value)
                {
                    _parentZone = value; 

                    // Inform each window detail of the change in zone
                    foreach(WindowDetail wd in _windowDetails)
                        wd.ParentZone = _parentZone;
                }
            }
        }

        public WindowDetailCollection WindowDetails
        {
            get { return _windowDetails; }
			
            set
            {
                _windowDetails.Clear();
                _windowDetails = value;
            }
        }

        public Decimal ZoneArea
        {
            get { return _zoneArea; }
            set { _zoneArea = value; }
        }

        public Size MinimalSize
        {
            get { return _minimalSize; }
            set { _minimalSize = value; }
        }

        public bool AutoDispose
        {
            get { return _autoDispose; }
            set { _autoDispose = value; }
        }

        public string FullTitle
        {
            get { return _fullTitle; }
        }

        public bool RedockAllowed
        {
            get { return _redockAllowed; }
            set { _redockAllowed = value; }
        }

        protected void OnDetailsClearing()
        {
            // Inform each detail it no longer has a parent
            foreach(WindowDetail wd in _windowDetails)
            {
                // Inform each detail it no longer has a parent
                wd.ParentWindow = null;

                // Inform object that it is no longer in a Zone
                wd.ParentZone = null;
            }
        }

        protected void OnDetailInserted(int index, object value)
        {
            WindowDetail wd = value as WindowDetail;

            // Inform object we are the new parent
            wd.ParentWindow = this;

            // Inform object that it is in a Zone
            wd.ParentZone = _parentZone;
        }

        protected void OnDetailRemoving(int index, object value)
        {
            WindowDetail wd = value as WindowDetail;

            // Inform object it no longer has a parent
            wd.ParentWindow = null;
			
            // Inform object that it is no longer in a Zone
            wd.ParentZone = null;
        }
		
        public virtual void NotifyFullTitleText(string title)
        {
            // Inform each detail of change in focus
            foreach(WindowDetail wd in _windowDetails)
                wd.NotifyFullTitleText(title);
                
            OnFullTitleChanged(title);
        }

        public virtual void NotifyAutoHideImage(bool autoHidden)
        {
            // Inform each detail of change in caption bar
            foreach(WindowDetail wd in _windowDetails)
                wd.NotifyAutoHideImage(autoHidden);
        }

        public virtual void NotifyShowCaptionBar(bool show)
        {
            // Remember the per-content requested caption
            _contentCaption = show;
        
            // If priority value always showing then we can let the
            // individual content decide on visibility. Otherwise
            // the priority forces it to remain hidden
            if (_floatingCaption)
            {
                // Inform each detail of change in caption bar
                foreach(WindowDetail wd in _windowDetails)
                    wd.NotifyShowCaptionBar(show);
            }
        }

        public virtual void NotifyCloseButton(bool show)
        {
            // Inform each detail of change close button
            foreach(WindowDetail wd in _windowDetails)
                wd.NotifyCloseButton(show);
        }

        public virtual void NotifyHideButton(bool show)
        {
            // Inform each detail of change close button
            foreach(WindowDetail wd in _windowDetails)
                wd.NotifyHideButton(show);
        }

        public virtual void NotifyContentGotFocus()
        {
            // Inform each detail of change in focus
            foreach(WindowDetail wd in _windowDetails)
                wd.WindowGotFocus();
        }

        public virtual void NotifyContentLostFocus()
        {
            // Inform each detail of change in focus
            foreach(WindowDetail wd in _windowDetails)
                wd.WindowLostFocus();
        }

        public virtual void WindowDetailGotFocus(WindowDetail wd)
        {
            NotifyContentGotFocus();
        }
		
        public virtual void WindowDetailLostFocus(WindowDetail wd)
        {
            NotifyContentLostFocus();
        }
        
        public void HideDetails()
        {
            // Inform each detail of change in visibility
            foreach(WindowDetail wd in _windowDetails)
                wd.Hide();
                
            // Remember priority state for caption
            _floatingCaption = false;
        }

        public void ShowDetails()
        {
            // Inform each detail of change in visibility
            foreach(WindowDetail wd in _windowDetails)
                wd.Show();

            // Remember priority state for caption
            _floatingCaption = true;
            
            // If the content requested the caption be hidden
            if (!_contentCaption)
                NotifyShowCaptionBar(_contentCaption);
        }
        
        public virtual void OnFullTitleChanged(String fullTitle)
        {
            _fullTitle = fullTitle;
            
            if (FullTitleChanged != null)
                FullTitleChanged((object)fullTitle, EventArgs.Empty);
        }

		public virtual Restore RecordRestore(object child) 
		{
			// Do we have a Zone as our parent?
			if (_parentZone != null)
			{
				// Delegate to the Zone as we cannot help out
				return _parentZone.RecordRestore(this, child, null);
			}

			return null;
		}

        public virtual void PropogateNameValue(PropogateName name, object value)
        {
            if (name == PropogateName.BackColor)
            {
                this.BackColor = (Color)value;
                Invalidate();
            }

            // Pass onto each of our child Windows
            foreach(WindowDetail wd in _windowDetails)
                wd.PropogateNameValue(name, value);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Austria Austria
My name is Daniel and I am from Austria.
When I was in High School, all I wanted to do was programming. After finishing High School, I joined a company for which I wrote a project management utility in Visual Basic 6. It was then that I realised that programming all day long was nothing I wanted to do for the rest of my life.

I quit the job and started to study computer and media security at polytechnical university in Hagenberg/Austria.

As of now, I'm still studying. I still like to program, as long as I can do something else too. Recently I switched my favorite programming language to c#. Together with a friend from university, we started a project where we implement OpenPGP (RFC2440) in c#.

Comments and Discussions