ThemeBase.cs
1 /*=============================================================================
2 *
3 * (C) Copyright 2011, Michael Carlisle (mike.carlisle@thecodeking.co.uk)
4 *
5 * http://www.TheCodeKing.co.uk
6 *
7 * All rights reserved.
8 * The code and information is provided "as-is" without waranty of any kind,
9 * either expresed or implied.
10 *
11 *-----------------------------------------------------------------------------
12 * History:
13 * 01/09/2007 Michael Carlisle Version 1.0
14 *=============================================================================
15 */
16 using System;
17 using System.Drawing;
18 using System.Windows.Forms;
19 
20 namespace sage.ew.formul.ButtonTittle.Themes
21 {
22  internal class ThemeBase : ITheme
23  {
24  protected Color backColor = Color.Empty;
25  protected Point buttonOffset = new Point(0, 0);
26  protected Size controlBoxSize = Size.Empty;
27  protected Form form;
28  protected Size frameBorder = Size.Empty;
29  protected bool? isDisplayed;
30  protected bool? isToolbar;
31  protected Size systemButtonSize = Size.Empty;
32 
33  public ThemeBase(Form form)
34  {
35  this.form = form;
36  }
37 
38  protected bool IsToolbar
39  {
40  get
41  {
42  if (isToolbar == null)
43  {
44  isToolbar = form.FormBorderStyle == FormBorderStyle.FixedToolWindow ||
45  form.FormBorderStyle == FormBorderStyle.SizableToolWindow;
46  }
47  return (bool) isToolbar;
48  }
49  }
50 
51  #region ITheme Members
52 
53  public virtual Color BackColor
54  {
55  get
56  {
57  if (backColor == Color.Empty)
58  {
59  backColor = Color.FromKnownColor(KnownColor.Control);
60  }
61  return backColor;
62  }
63  }
64 
65 
66  public bool IsDisplayed
67  {
68  get
69  {
70  if (isDisplayed == null)
71  {
72  if ((!form.ControlBox && string.IsNullOrEmpty(form.Text))
73  || form.FormBorderStyle == FormBorderStyle.None
74  )
75  {
76  isDisplayed = false;
77  }
78  else
79  {
80  isDisplayed = true;
81  }
82  }
83  return (bool) isDisplayed;
84  }
85  }
86 
87  public virtual Size ControlBoxSize
88  {
89  get
90  {
91  if (controlBoxSize == Size.Empty)
92  {
93  if (IsToolbar)
94  {
95  if (form.ControlBox)
96  {
97  controlBoxSize = new Size(SystemButtonSize.Width, SystemButtonSize.Height);
98  }
99  else
100  {
101  controlBoxSize = new Size(0, 0);
102  }
103  }
104  else
105  {
106  int index;
107  if (!form.MaximizeBox && !form.MinimizeBox && form.ControlBox)
108  {
109  index = (form.HelpButton) ? 2 : 1;
110  }
111  else
112  {
113  index = (form.ControlBox) ? 3 : 0;
114  }
115  controlBoxSize = new Size(index*SystemButtonSize.Width, SystemButtonSize.Height);
116  }
117  }
118  return controlBoxSize;
119  }
120  }
121 
122  public virtual Point ButtonOffset
123  {
124  get { return buttonOffset; }
125  }
126 
127 
128  public virtual Size FrameBorder
129  {
130  get
131  {
132  if (frameBorder == Size.Empty)
133  {
134  switch (form.FormBorderStyle)
135  {
136  case FormBorderStyle.SizableToolWindow:
137  frameBorder = new Size(SystemInformation.FrameBorderSize.Width + 2,
138  SystemInformation.FrameBorderSize.Height + 2);
139  break;
140  case FormBorderStyle.Sizable:
141  frameBorder = new Size(SystemInformation.FrameBorderSize.Width,
142  SystemInformation.FrameBorderSize.Height + 2);
143  break;
144  case FormBorderStyle.FixedToolWindow:
145  frameBorder = new Size(SystemInformation.Border3DSize.Width + 3,
146  SystemInformation.Border3DSize.Height + 3);
147  break;
148  default:
149  frameBorder = new Size(SystemInformation.Border3DSize.Width + 1,
150  SystemInformation.Border3DSize.Height + 3);
151  break;
152  }
153  }
154  return frameBorder;
155  }
156  }
157 
158  public virtual Size SystemButtonSize
159  {
160  get
161  {
162  if (systemButtonSize == Size.Empty)
163  {
164  if (IsToolbar)
165  {
166  Size size = SystemInformation.ToolWindowCaptionButtonSize;
167  size.Height -= 4;
168  size.Width -= 1;
169  systemButtonSize = size;
170  }
171  else
172  {
173  systemButtonSize = new Size(SystemInformation.CaptionButtonSize.Width,
174  SystemInformation.CaptionHeight - 2
175  *
176  Math.Max(
177  SystemInformation.BorderSize.
178  Height,
179  SystemInformation.Border3DSize
180  .Height)
181  - 1);
182  }
183  }
184  return systemButtonSize;
185  }
186  }
187 
188  #endregion
189  }
190 }