Import from 1.9a8 tarball
[mozilla-extra.git] / extensions / manticore / toolkit / StripBar.cs
blob37360708f7ac23cac7f76f63c86dc51841bae241
1 /* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Manticore.
18 * The Initial Developer of the Original Code is
19 * Silverstone Interactive.
20 * Portions created by the Initial Developer are Copyright (C) 2001
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Ben Goodger <ben@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 namespace Silverstone.Manticore.Toolkit
42 using System;
43 using System.Collections;
44 using System.ComponentModel;
45 using System.Drawing;
46 using System.Drawing.Drawing2D;
47 using System.Windows.Forms;
50 /// <summary>
51 /// Summary description for StripBar.
52 /// </summary>
53 public class StripBar : UserControl
55 public StripBar()
59 public ArrayList Rows = new ArrayList();
60 public ArrayList Bands = new ArrayList();
62 ///////////////////////////////////////////////////////////////////////////
63 // IStripBar Implementation
64 public void AddBand (StripBand aBand)
66 Bands.Add(aBand);
67 aBand.Bar = this;
69 if (aBand.NewRow)
71 StripRow row = new StripRow(this);
72 Rows.Add(row);
73 aBand.Row = row;
75 row.Bands.Add(aBand);
77 // TODO: Trigger Height-Changed Event
79 else
81 StripRow row;
82 if (Rows.Count >= 1)
83 row = Rows[Rows.Count-1] as StripRow;
84 else
86 row = new StripRow(this);
87 Rows.Add(row);
89 row.Bands.Add(aBand);
90 aBand.Row = row;
92 // Invalidate Row
93 Invalidate(row.Bounds);
97 public void RemoveBand(StripBand aStripBand)
102 ///////////////////////////////////////////////////////////////////////////
103 // Overriden Methods
104 protected override void OnPaint(PaintEventArgs aPea)
106 int rowCount = Rows.Count;
107 for (int i = 0; i < rowCount; ++i)
109 StripRow currRow = Rows[i] as StripRow;
110 if (currRow.Bounds.IntersectsWith(aPea.ClipRectangle))
111 currRow.PaintRow(aPea);
117 public class StripBand
119 public StripBand()
123 ///////////////////////////////////////////////////////////////////////////
124 // IStripBand Implementation
125 protected StripRow mRow;
126 public StripRow Row
128 get
130 return mRow;
132 set
134 if (value != mRow)
135 mRow = value;
140 protected StripBar mBar;
141 public StripBar Bar
143 get
145 return mBar;
147 set
149 if (value != mBar)
150 mBar = value;
155 protected int mWidth;
156 public int Width
158 get
160 return mWidth;
162 set
164 if (value != mWidth)
165 mWidth = value;
170 protected int mHeight = 24;
171 public int Height
173 get
175 // Compute height:
176 // height = the larger of - decoration area (icon/text)
177 // - client area (control)
178 // + nonclient, nondecoration area (borders)
180 return mHeight;
185 protected bool mNewRow = false;
186 public bool NewRow
188 get
190 return mNewRow;
192 set
194 if (value != mNewRow)
196 mNewRow = value;
202 protected Control mControl = null;
203 public Control Child
205 get
207 return mControl;
209 set
211 if (value != mControl)
213 mControl = value;
219 protected Color mBackColor = Color.Red;
220 public Color BackColor
222 get
224 return mBackColor;
226 set
228 if (value != mBackColor)
230 mBackColor = value;
231 StripBar bar = mBar as StripBar;
232 bar.Invalidate(Bounds);
237 public Rectangle Bounds
239 get
241 int x, y, w, h, i;
243 int bandCount = mRow.Bands.Count;
244 for (i = 0, x = 0; i < bandCount; ++i)
246 StripBand currBand = mRow.Bands[i] as StripBand;
247 x += currBand.Bounds.Width;
249 y = mRow.Bounds.Y;
251 h = Height;
253 w = mBar.Width;
254 int bandIndex = mRow.Bands.IndexOf(this);
255 if (bandIndex == (mRow.Bands.Count - 1))
256 w = mBar.ClientRectangle.Width - x;
258 return new Rectangle(x, y, w, h);
262 ///////////////////////////////////////////////////////////////////////////
264 public void PaintBand(PaintEventArgs aPea)
266 SolidBrush sbr = new SolidBrush(BackColor);
267 aPea.Graphics.FillRectangle(sbr, Bounds);
271 public class StripRow
273 public StripRow(StripBar aStripBar)
275 mStripBar = aStripBar;
278 protected StripBar mStripBar;
280 public ArrayList Bands = new ArrayList();
282 public Rectangle Bounds
284 get
286 int x, y, w, h;
287 w = mStripBar.ClientRectangle.Width;
288 h = Height;
290 x = mStripBar.ClientRectangle.Left;
292 int rowCount = mStripBar.Rows.Count;
293 StripRow currRow = mStripBar.Rows[0] as StripRow;
294 int i = 0;
295 for (y = 0; currRow != this; ++i)
296 y += currRow.Height;
298 return new Rectangle(x, y, w, h);
302 protected int mHeight = 24;
303 public int Height
305 get
307 return mHeight;
309 set
311 if (value != mHeight)
312 mHeight = value;
316 public void AddBand(StripBand aBand)
318 if (aBand.Height > mHeight)
319 mHeight = aBand.Height;
321 Bands.Add(aBand);
324 public void PaintRow(PaintEventArgs aPea)
326 int bandCount = Bands.Count;
327 for (int i = 0; i < bandCount; ++i)
329 StripBand currBand = Bands[i] as StripBand;
330 currBand.PaintBand(aPea);