Back to index

lightning-sunbird  0.9+nobinonly
StripBar.cs
Go to the documentation of this file.
00001 /* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Manticore.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Silverstone Interactive.
00020  * Portions created by the Initial Developer are Copyright (C) 2001
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Ben Goodger <ben@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 namespace Silverstone.Manticore.Toolkit
00041 {
00042   using System;
00043   using System.Collections;
00044   using System.ComponentModel;
00045   using System.Drawing;
00046   using System.Drawing.Drawing2D;
00047   using System.Windows.Forms;
00048 
00049 
00053        public class StripBar : UserControl
00054        {
00055               public StripBar()
00056               {
00057               }
00058 
00059     public ArrayList Rows = new ArrayList();
00060     public ArrayList Bands = new ArrayList();
00061 
00063     // IStripBar Implementation
00064     public void AddBand (StripBand aBand)
00065     {
00066       Bands.Add(aBand);
00067       aBand.Bar = this;
00068 
00069       if (aBand.NewRow) 
00070       {
00071         StripRow row = new StripRow(this);
00072         Rows.Add(row);
00073         aBand.Row = row;
00074 
00075         row.Bands.Add(aBand);
00076 
00077         // TODO: Trigger Height-Changed Event
00078       }
00079       else 
00080       {
00081         StripRow row;
00082         if (Rows.Count >= 1) 
00083           row = Rows[Rows.Count-1] as StripRow;
00084         else 
00085         {
00086           row = new StripRow(this);
00087           Rows.Add(row);
00088         }
00089         row.Bands.Add(aBand);
00090         aBand.Row = row;
00091 
00092         // Invalidate Row
00093         Invalidate(row.Bounds);
00094       }
00095     }
00096 
00097     public void RemoveBand(StripBand aStripBand)
00098     {
00099 
00100     }
00101 
00103     // Overriden Methods
00104     protected override void OnPaint(PaintEventArgs aPea)
00105     {
00106       int rowCount = Rows.Count;
00107       for (int i = 0; i < rowCount; ++i) 
00108       {
00109         StripRow currRow = Rows[i] as StripRow;
00110         if (currRow.Bounds.IntersectsWith(aPea.ClipRectangle)) 
00111           currRow.PaintRow(aPea);
00112 
00113       }
00114     }
00115   }
00116 
00117   public class StripBand
00118   {
00119     public StripBand()
00120     {
00121     }
00122 
00124     // IStripBand Implementation
00125     protected StripRow mRow;
00126     public StripRow Row
00127     {
00128       get 
00129       {
00130         return mRow;
00131       }
00132       set 
00133       {
00134         if (value != mRow)
00135           mRow = value;
00136       }
00137     }
00138 
00139 
00140     protected StripBar mBar;
00141     public StripBar Bar
00142     {
00143       get 
00144       {
00145         return mBar;
00146       }
00147       set 
00148       {
00149         if (value != mBar) 
00150           mBar = value;
00151       }
00152     }
00153 
00154 
00155     protected int mWidth;
00156     public int Width
00157     {
00158       get 
00159       {
00160         return mWidth;
00161       }
00162       set 
00163       {
00164         if (value != mWidth) 
00165           mWidth = value;
00166       }
00167     }
00168 
00169 
00170     protected int mHeight = 24;
00171     public int Height
00172     {
00173       get 
00174       {
00175         // Compute height:
00176         // height = the larger of - decoration area (icon/text)
00177         //                        - client area (control)
00178         //          + nonclient, nondecoration area (borders)
00179         //
00180         return mHeight;
00181       }
00182     }
00183 
00184 
00185     protected bool mNewRow = false;
00186     public bool NewRow 
00187     {
00188       get 
00189       {
00190         return mNewRow;
00191       }
00192       set 
00193       {
00194         if (value != mNewRow) 
00195         {
00196           mNewRow = value;
00197         }
00198       }
00199     }
00200 
00201 
00202     protected Control mControl = null;
00203     public Control Child 
00204     {
00205       get 
00206       {
00207         return mControl;
00208       }
00209       set 
00210       {
00211         if (value != mControl) 
00212         {
00213           mControl = value;
00214         }
00215       }
00216     }
00217 
00218 
00219     protected Color mBackColor = Color.Red;
00220     public Color BackColor 
00221     {
00222       get 
00223       {
00224         return mBackColor;
00225       }
00226       set 
00227       {
00228         if (value != mBackColor) 
00229         {
00230           mBackColor = value;
00231           StripBar bar = mBar as StripBar;
00232           bar.Invalidate(Bounds);
00233         }
00234       }
00235     }
00236 
00237     public Rectangle Bounds
00238     {
00239       get 
00240       {
00241         int x, y, w, h, i;
00242 
00243         int bandCount = mRow.Bands.Count;
00244         for (i = 0, x = 0; i < bandCount; ++i) 
00245         {
00246           StripBand currBand = mRow.Bands[i] as StripBand;
00247           x += currBand.Bounds.Width;
00248         }
00249         y = mRow.Bounds.Y;
00250 
00251         h = Height;
00252         
00253         w = mBar.Width;
00254         int bandIndex = mRow.Bands.IndexOf(this);
00255         if (bandIndex == (mRow.Bands.Count - 1)) 
00256           w = mBar.ClientRectangle.Width - x;
00257 
00258         return new Rectangle(x, y, w, h);
00259       }
00260     }
00261 
00263     // 
00264     public void PaintBand(PaintEventArgs aPea)
00265     {
00266       SolidBrush sbr = new SolidBrush(BackColor);
00267       aPea.Graphics.FillRectangle(sbr, Bounds);
00268     }
00269   }
00270 
00271   public class StripRow
00272   {
00273     public StripRow(StripBar aStripBar)
00274     {
00275       mStripBar = aStripBar;
00276     }
00277 
00278     protected StripBar mStripBar;
00279 
00280     public ArrayList Bands = new ArrayList();
00281 
00282     public Rectangle Bounds
00283     {
00284       get 
00285       {
00286         int x, y, w, h;
00287         w = mStripBar.ClientRectangle.Width;
00288         h = Height;
00289 
00290         x = mStripBar.ClientRectangle.Left;
00291 
00292         int rowCount = mStripBar.Rows.Count;
00293         StripRow currRow = mStripBar.Rows[0] as StripRow; 
00294         int i = 0;
00295         for (y = 0; currRow != this; ++i) 
00296           y += currRow.Height;
00297 
00298         return new Rectangle(x, y, w, h);
00299       }
00300     }
00301 
00302     protected int mHeight = 24;
00303     public int Height 
00304     {
00305       get 
00306       {
00307         return mHeight;
00308       }
00309       set 
00310       {
00311         if (value != mHeight) 
00312           mHeight = value;
00313       }
00314     }
00315 
00316     public void AddBand(StripBand aBand)
00317     {
00318       if (aBand.Height > mHeight)
00319         mHeight = aBand.Height;
00320         
00321       Bands.Add(aBand);
00322     }
00323 
00324     public void PaintRow(PaintEventArgs aPea)
00325     {
00326       int bandCount = Bands.Count;
00327       for (int i = 0; i < bandCount; ++i) 
00328       {
00329         StripBand currBand = Bands[i] as StripBand;
00330         currBand.PaintBand(aPea);
00331       }
00332     }
00333   }
00334 }