Click here to Skip to main content
15,895,011 members
Articles / Mobile Apps

Windows Mobile Password Safe

Rate me:
Please Sign up or sign in to vote.
4.87/5 (58 votes)
12 Jan 2009CPOL16 min read 161.2K   3.1K   139  
A password safe with a touch screen UI introducing Fluid Controls.
using System;

using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Fluid.Controls
{
    // TODO: Make System.ComponentModel.Generic.BindingList derived!!
    public class FluidControlCollection : IList<FluidControl>
    {
        public FluidControlCollection(IContainer container)
            : base()
        {
            this.container = container;
        }

        private IContainer container;

        private List<FluidControl> controls = new List<FluidControl>();

        /// <summary>
        /// Occurs when the collection has changed.
        /// </summary>
        protected virtual void OnNotifyChanged()
        {
            if (NotifyChanged != null) NotifyChanged(this, EventArgs.Empty);
        }

        /// <summary>
        /// Notify that something has happened to the collection or it's ITouchControl properties.
        /// </summary>
        public void NotifyChange()
        {
            OnNotifyChanged();
        }

        /// <summary>
        /// Occurs when the collection has changed.
        /// </summary>
        public event EventHandler NotifyChanged;

        #region ICollection<ISmartControl> Members

        public void Add(FluidControl item)
        {
            controls.Add(item);
            item.Container = container;
            OnControlAdded(item);
            OnNotifyChanged();
        }

        public void Insert(int index, FluidControl control)
        {
            controls.Insert(index, control);
            control.Container = container;
            OnControlAdded(control);
            OnNotifyChanged();
        }

        public event EventHandler<ControlEventArgs> ControlAdded;


        private void OnControlAdded(FluidControl control)
        {
            Size size = container.Bounds.Size;
            control.Container = container;
            control.Scale(container.ScaleFactor);
            control.OnControlAdded(container);
            INotifyControlAdded notify = container as INotifyControlAdded;
            if (notify != null) notify.ControlAdded(control);
            if (ControlAdded != null)
            {
                ControlEventArgs e = new ControlEventArgs(control);
                ControlAdded(this, e);
            }
        }

        private void OnControlRemoved(FluidControl control)
        {
            SizeF f = container.ScaleFactor;
            SizeF scale = new SizeF(1f / f.Width, 1f / f.Height);
            control.Container = null;
            control.Scale(scale);
        }

        private void RemoveControls()
        {
            SizeF f = container.ScaleFactor;
            SizeF scale = new SizeF(1f / f.Width, 1f / f.Height);
            foreach (FluidControl c in this)
            {
                c.Scale(scale);
                c.Container = null;
            }
        }

        public void Clear()
        {
            RemoveControls();
            controls.Clear();
            OnNotifyChanged();
        }

        public bool Contains(FluidControl item)
        {
            return controls.Contains(item);
        }

        public void CopyTo(FluidControl[] array, int arrayIndex)
        {
            controls.CopyTo(array, arrayIndex);
            OnNotifyChanged();
        }

        public int Count
        {
            get { return controls.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(FluidControl control)
        {
            OnControlRemoved(control);
            bool result = controls.Remove(control);
            if (result) OnNotifyChanged();
            return result;
        }

        #endregion

        #region IEnumerable<ISmartControl> Members

        public IEnumerator<FluidControl> GetEnumerator()
        {
            return controls.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return controls.GetEnumerator();
        }

        #endregion

        internal int IndexOf(FluidControl control)
        {
            return controls.IndexOf(control);
        }

        #region IList<ISmartControl> Members

        int IList<FluidControl>.IndexOf(FluidControl item)
        {
            return controls.IndexOf(item);
        }



        public void RemoveAt(int index)
        {
            FluidControl c = this[index];
            OnControlRemoved(c);
            controls.RemoveAt(index);
        }

        public FluidControl this[int index]
        {
            get { return controls[index]; }
            set { controls[index] = value; }
        }

        #endregion
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Germany Germany
MCPD
Enterprise Application Developer 3.5
Windows Developer 3.5
.ASP.NET Developer 3.5
.NET 2.0 Windows Developer
.NET 2.0 Web Developer
.NET 2.0 Enterprise Application Developer


MCTS
.NET 3.5 Windows Forms Applications
.NET 3.5 ASP.NET Applications
.NET 3.5, ADO.NET Application Development
.NET 3.5 WCF
.NET 3.5 WPF
.NET 3.5 WF
Microsoft SQL Server 2008, Database Development
.NET 2.0 Windows Applications
.NET 2.0 Web Applications
.NET 2.0 Distributed Applications
SQL Server 2005
Sharepoint Services 3.0 Application Development
Windows Vista Client Configuration

Comments and Discussions