Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Windows Mobile Password Safe

, 12 Jan 2009
A password safe with a touch screen UI introducing Fluid Controls.
PasswordSafeExe.zip
PasswordSafeSource.zip
PasswordSafe
Fluditity
bin
Classes
vssver2.scc
Controls
enums
vssver2.scc
Events
vssver2.scc
Interfaces
vssver2.scc
vssver2.scc
Fluid.csproj.user
GdiPlus
mssccprj.scc
NativeMethods
vssver2.scc
vssver2.scc
Native
vssver2.scc
obj
Properties
vssver2.scc
vssver2.scc
PasswordSafe
bin
Release
Fluid.dll
passwords.pws
PasswordSafe.exe
Classes
vssver2.scc
Encryption
vssver2.scc
EventArgs
vssver2.scc
ListBoxes
vssver2.scc
PasswordSafe.csproj.user
Properties
vssver2.scc
Resources
lock.bmp
minus.png
props.bmp
save.bmp
saved.bmp
search.bmp
searchd.bmp
undo24.bmp
undo24_d.bmp
Untitled.png
vssver2.scc
security.ico
Templates
vssver2.scc
Themes
vssver2.scc
vssver2.scc
Xml
vssver2.scc
vssver2.scc
using System;

using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using System.Drawing;
using PasswordSafe.Xml;
using System.Windows.Forms;
using PasswordSafe.Classes;

namespace PasswordSafe.Templates
{
    public class CategoryTemplate : FluidTemplate
    {

        public CategoryTemplate()
            : base()
        {
        }

        public CategoryTemplate(bool showCounter)
        {
            ShowCounter = showCounter;
        }

        private FluidLabel label;
        private FluidButton deleteBtn;
        private FluidButton confirmDeleteBtn;
        private FluidLabel countLabel;


        protected override void InitControl()
        {
            base.InitControl();
            ShowCounter = true;
            ButtonStretch = 100;

            Font buttonFont = new Font(FontFamily.GenericSansSerif, 8f, FontStyle.Bold);

            this.Bounds = new Rectangle(0, 0, 240, 50);
            FluidLabel l = new FluidLabel("", 8, 0, 224, 50);
            l.LineAlignment = StringAlignment.Center;
            l.Anchor = AnchorAll;
            label = l;
            l.Font = new Font(FontFamily.GenericSansSerif, 11f, FontStyle.Bold);

            Controls.Add(l);

            deleteBtn = new FluidButton("-", 4, 7, 20, 20);
            deleteBtn.ButtonSize = new Size(20, 20);
            deleteBtn.Shape = ButtonShape.Ellipse;
            deleteBtn.BackColor = Color.DarkRed; // Salmo, IndianRed Tomato
            deleteBtn.ForeColor = Color.White;
            deleteBtn.Font = buttonFont;
            deleteBtn.Click += new EventHandler(deleteBtn_Click);
            deleteBtn.Anchor = AnchorTL;
            deleteBtn.Visible = false;
            Controls.Add(deleteBtn);

            if (ShowCounter)
            {
                countLabel = new FluidLabel("", 240 - 40, 4, 36, 50 - 8);
                countLabel.Alignment = StringAlignment.Far;
                countLabel.LineAlignment = StringAlignment.Center;
                countLabel.ForeColor = Theme.Current.ListSecondaryForeColor;
                countLabel.Font = new Font(FontFamily.GenericSansSerif, 7f, FontStyle.Regular);
                countLabel.Anchor = AnchorRTB;
                Controls.Add(countLabel);
            }

            confirmDeleteBtn = new FluidButton("Delete", 240 - 50 - 4, 4, 50, 50 - 8);
            confirmDeleteBtn.ButtonSize = new Size(50, 24);
            confirmDeleteBtn.BackColor = Color.Red;
            confirmDeleteBtn.ForeColor = Color.White;
            confirmDeleteBtn.Font = buttonFont;
            confirmDeleteBtn.Anchor = AnchorRTB;
            confirmDeleteBtn.Click += new EventHandler(confirmDeleteBtn_Click);
            confirmDeleteBtn.Visible = false;
            Controls.Add(confirmDeleteBtn);


        }

        CategoriesListBox ListBox { get { return Parent as CategoriesListBox; } }

        int deleteIndex = -1;

        public int DeleteIndex
        {
            get { return deleteIndex; }
            set
            {
                if (deleteIndex != value)
                {
                    if (deleteIndex >= 0) ListBox.Invalidate(ListBox.GetItemBounds(deleteIndex));
                    deleteIndex = value;
                    if (value >= 0) ListBox.Invalidate(ListBox.GetItemBounds(deleteIndex));
                    ListBox.Invalidate();
                }
            }
        }

        void confirmDeleteBtn_Click(object sender, EventArgs e)
        {
            int deleteIndex = DeleteIndex;
            DeleteIndex = -1;
            ListBox.Categories.RemoveAt(deleteIndex);
        }

        public bool ShowCounter { get; set; }


        void deleteBtn_Click(object sender, EventArgs e)
        {
            int index = this.ItemIndex;
            ListBox.SelectedItemIndex = index;
            DeleteIndex = index;
        }

        protected override void OnBindValue(object value)
        {
            PasswordCategory c = value as PasswordCategory;
            if (c != null)
            {
                LayoutTemplate(c);
                label.Text = c.Title;
                
                if (ShowCounter)
                {
                    label.ForeColor = c.PasswordCount == 0 ? Theme.Current.GrayTextColor : Color.Empty;
                    countLabel.Text = c.PasswordCount.ToString();
                    confirmDeleteBtn.Visible = deleteIndex >= 0 && ItemIndex == deleteIndex;
                }
            }
            else
            {
                label.Text = "";
            }
        }

        public CategoriesListBox CategoryListBox { get { return Parent as CategoriesListBox; } }

        protected override void OnItemUpdate(object value)
        {
            base.OnItemUpdate(value);
            if (ShowCounter)
            {
                bool isSelected = this.CategoryListBox.SelectedItemIndex == this.ItemIndex;
                countLabel.ForeColor = isSelected ? Theme.Current.ListSecondarySelectedForeColor : Theme.Current.ListSecondaryForeColor;
            }
        }

        private void LayoutTemplate(PasswordCategory c)
        {
            if (c != null) deleteBtn.Visible = editMode && !c.ReadOnly;
        }

        private bool editMode;
        public bool EditMode
        {
            get { return editMode; }
            set
            {
                if (editMode != value)
                {
                    editMode = value;
                    OnEditModeChanged();
                }
            }
        }

        private int buttonStretch = 100;
        public int ButtonStretch
        {
            get { return buttonStretch; }
            set
            {
                if (buttonStretch != value)
                {
                    buttonStretch = value;
                    LayoutTemplate();
                }
            }
        }


        private void OnEditModeChanged()
        {
            if (!editMode) DeleteIndex = -1;
            LayoutTemplate();
        }

        private void LayoutTemplate()
        {
            BeginInit();
            deleteBtn.Visible = editMode;
            int w = Width;
            int h = Height;
            int distance = ScaleX(8);
            if (editMode) deleteBtn.Width = buttonStretch * ScaleX(20) / 100;
            int l = (editMode ? deleteBtn.Width : 0) + distance;
            label.Bounds = new Rectangle(l, 0, w - l, h);
            EndInit();
        }

    }
}

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)

Share

About the Author

Thomas Gerber
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

| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 12 Jan 2009
Article Copyright 2009 by Thomas Gerber
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid