1 /*
2   KeePass Password Safe - The Open-Source Password Manager
3   Copyright (C) 2003-2021 Dominik Reichl <dominik.reichl@t-online.de>
4 
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 2 of the License, or
8   (at your option) any later version.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19 
20 using System;
21 using System.Collections.Generic;
22 using System.Diagnostics;
23 using System.Drawing;
24 using System.Text;
25 using System.Windows.Forms;
26 
27 namespace KeePass.UI
28 {
29 	public sealed class ColorMenuItem : MenuItem
30 	{
31 		private Color m_clr;
32 		private int m_qSize;
33 
34 		public Color Color
35 		{
36 			get { return m_clr; }
37 		}
38 
ColorMenuItem(Color clr, int qSize)39 		public ColorMenuItem(Color clr, int qSize) : base()
40 		{
41 			m_clr = clr;
42 			m_qSize = qSize;
43 
44 			Debug.Assert(this.CanRaiseEvents);
45 			this.ShowShortcut = false;
46 			this.OwnerDraw = true;
47 		}
48 
OnDrawItem(DrawItemEventArgs e)49 		protected override void OnDrawItem(DrawItemEventArgs e)
50 		{
51 			// base.OnDrawItem(e);
52 
53 			Graphics g = e.Graphics;
54 			Rectangle rectBounds = e.Bounds;
55 			Rectangle rectFill = new Rectangle(rectBounds.Left + 2,
56 				rectBounds.Top + 2, rectBounds.Width - 4, rectBounds.Height - 4);
57 
58 			bool bFocused = (((e.State & DrawItemState.Focus) != DrawItemState.None) ||
59 				((e.State & DrawItemState.Selected) != DrawItemState.None));
60 
61 			// e.DrawBackground();
62 			// e.DrawFocusRectangle();
63 			using(SolidBrush sbBack = new SolidBrush(bFocused ?
64 				SystemColors.Highlight : SystemColors.Menu))
65 			{
66 				g.FillRectangle(sbBack, rectBounds);
67 			}
68 
69 			using(SolidBrush sb = new SolidBrush(m_clr))
70 			{
71 				g.FillRectangle(sb, rectFill);
72 			}
73 		}
74 
OnMeasureItem(MeasureItemEventArgs e)75 		protected override void OnMeasureItem(MeasureItemEventArgs e)
76 		{
77 			// base.OnMeasureItem(e);
78 
79 			e.ItemWidth = m_qSize;
80 			e.ItemHeight = m_qSize;
81 		}
82 	}
83 }
84