File: KeyboardControl.cs

package info (click to toggle)
keepass2 2.28%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,844 kB
  • ctags: 16,038
  • sloc: cs: 96,726; xml: 5,333; cpp: 311; makefile: 49; sh: 10
file content (157 lines) | stat: -rw-r--r-- 4,168 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
  KeePass Password Safe - The Open-Source Password Manager
  Copyright (C) 2003-2014 Dominik Reichl <dominik.reichl@t-online.de>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

/*
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;

namespace KeePass.UI
{
	public sealed class KblButton
	{
		public string Text = null;
		public string Command = null;

		public Rectangle Position = Rectangle.Empty;

		public KblButton() { }
		public KblButton(string strText, string strCommand)
		{
			this.Text = strText;
			this.Command = strCommand;
		}
	}

	public sealed class KbcLayout
	{
		public List<List<KblButton>> Rows = new List<List<KblButton>>();

		public static KbcLayout Default
		{
			get
			{
				KbcLayout l = new KbcLayout();

				List<KblButton> r = new List<KblButton>();
				r.Add(new KblButton("1", null));
				r.Add(new KblButton("2", null));
				r.Add(new KblButton("3", null));
				r.Add(new KblButton("4", null));
				r.Add(new KblButton("5", null));
				r.Add(new KblButton("6", null));
				r.Add(new KblButton("7", null));
				r.Add(new KblButton("8", null));
				r.Add(new KblButton("9", null));
				r.Add(new KblButton("0", null));
				l.Rows.Add(r);

				return l;
			}
		}
	}

	public sealed class KeyboardControl : Control
	{
		private KbcLayout m_l = null;
		private int m_iLayoutW = -1, m_iLayoutH = -1;

		private CustomToolStripRendererEx m_renderer = new CustomToolStripRendererEx();

		public void InitEx(KbcLayout l)
		{
			m_l = l;
		}

		private void ComputeLayoutEx()
		{
			if(m_l == null) { Debug.Assert(false); return; }

			int w = this.ClientSize.Width, h = this.ClientSize.Height;

			int nRows = m_l.Rows.Count;
			float fBtnH = (float)h / (float)(nRows + 1);
			float fBtnHSkip = ((float)h - (fBtnH * (float)nRows)) /
				(float)(nRows + 1);
			float y = 0.0f;

			for(int iy = 0; iy < nRows; ++iy)
			{
				y += fBtnHSkip;

				int nColumns = m_l.Rows[iy].Count;
				float fBtnW = (float)w / (nColumns + 1);
				float fBtnWSkip = ((float)w - (fBtnW * (float)nColumns)) /
					(float)(nColumns + 1);
				float x = 0.0f;

				for(int ix = 0; ix < nColumns; ++ix)
				{
					x += fBtnWSkip;

					m_l.Rows[iy][ix].Position = new Rectangle((int)(x + 0.00001f),
						(int)(y + 0.00001f), (int)fBtnW, (int)fBtnH);
				}
			}
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint(e); // Required

			if(m_l == null) return;

			Size szCli = this.ClientSize;
			if((m_iLayoutW != szCli.Width) || (m_iLayoutH != szCli.Height))
				ComputeLayoutEx();

			Graphics g = e.Graphics;
			Rectangle rectClip = e.ClipRectangle;
			foreach(List<KblButton> vRow in m_l.Rows)
			{
				foreach(KblButton btn in vRow)
				{
					if(btn.Position.IntersectsWith(rectClip))
						DrawButtonEx(btn, g);
				}
			}
		}

		private void DrawButtonEx(KblButton btn, Graphics g)
		{
			string strText = ((btn.Text ?? btn.Command) ?? string.Empty);

			ToolStripItemRenderEventArgs e = new ToolStripItemRenderEventArgs(g,
				new ToolStripButton(strText));
			m_renderer.DrawMenuItemBackground(e);
		}

		protected override void OnPaintBackground(PaintEventArgs pevent)
		{
			using(SolidBrush brush = new SolidBrush(SystemColors.Control))
			{
				pevent.Graphics.FillRectangle(brush, pevent.ClipRectangle);
			}
		}
	}
}
*/