Back to index

lightning-sunbird  0.9+nobinonly
LocationBar.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.Browser
00041 {
00042   using System;
00043   using System.Collections;
00044   using System.ComponentModel;
00045   using System.Drawing;
00046   using System.Data;
00047   using System.Windows.Forms;
00048 
00052        public class LocationBar : System.Windows.Forms.UserControl
00053        {
00054     private System.Windows.Forms.Label mAddressLabel;
00055     private System.Windows.Forms.TextBox mAddressBar;
00056     private System.Windows.Forms.Button mGoButton;
00060               private System.ComponentModel.Container components = null;
00061 
00062               public LocationBar()
00063               {
00064                      // This call is required by the Windows.Forms Form Designer.
00065                      InitializeComponent();
00066 
00067                      mAddressBar.KeyDown += new KeyEventHandler(OnKeyDown);
00068       mAddressBar.ModifiedChanged += new EventHandler(OnAddressBarModified);
00069       mGoButton.Click += new EventHandler(OnGoButtonClick);
00070               }
00071 
00072     public string Text 
00073     {
00074       get 
00075       {
00076         return mAddressBar.Text;
00077       }
00078       set 
00079       {
00080         if (value != mAddressBar.Text)
00081           mAddressBar.Text = value;
00082       }
00083     }
00084 
00085     public delegate void LocationBarEventHandler(Object sender, LocationBarEventArgs e);
00086     
00087     public event LocationBarEventHandler LocationBarCommit;
00088 
00089     protected void OnKeyDown(Object aSender, KeyEventArgs aKea)
00090     {
00091       if (aKea.KeyCode == Keys.Enter) 
00092         FireLocationBarCommit();
00093     }
00094 
00095     protected void OnGoButtonClick(Object aSender, EventArgs aEa)
00096     {
00097       FireLocationBarCommit();      
00098     }
00099 
00100     protected void FireLocationBarCommit()
00101     {
00102       if (LocationBarCommit != null) 
00103       {
00104         LocationBarEventArgs lbea = new LocationBarEventArgs(mAddressBar.Text);
00105         LocationBarCommit(this, lbea);
00106       }
00107     }
00108 
00109     public event LocationBarEventHandler LocationBarModified;
00110     protected void OnAddressBarModified(Object aSender, EventArgs aEa)
00111     {
00112       if (LocationBarModified != null) 
00113       {
00114         LocationBarEventArgs lbea = new LocationBarEventArgs(mAddressBar.Text);
00115         LocationBarModified(this, lbea);
00116       }
00117     }
00118 
00119     protected override void OnPaint(PaintEventArgs aPea)
00120     {
00121       Graphics g = aPea.Graphics;
00122       g.DrawLine(SystemPens.ControlDark, 0, 0, ClientRectangle.Width, 0);
00123       g.DrawLine(SystemPens.ControlLight, 0, 1, ClientRectangle.Width, 1);
00124     }
00125 
00126               #region Component Designer generated code
00127 
00128 
00129 
00130 
00131               private void InitializeComponent()
00132               {
00133       this.mAddressLabel = new System.Windows.Forms.Label();
00134       this.mAddressBar = new System.Windows.Forms.TextBox();
00135       this.mGoButton = new System.Windows.Forms.Button();
00136       this.SuspendLayout();
00137       // 
00138       // mAddressLabel
00139       // 
00140       this.mAddressLabel.AutoSize = true;
00141       this.mAddressLabel.Location = new System.Drawing.Point(8, 6);
00142       this.mAddressLabel.Name = "mAddressLabel";
00143       this.mAddressLabel.Size = new System.Drawing.Size(49, 13);
00144       this.mAddressLabel.TabIndex = 0;
00145       this.mAddressLabel.Text = "A&ddress:";
00146       // 
00147       // mAddressBar
00148       // 
00149       this.mAddressBar.Anchor = (System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right);
00150       this.mAddressBar.Location = new System.Drawing.Point(64, 3);
00151       this.mAddressBar.Name = "mAddressBar";
00152       this.mAddressBar.Size = new System.Drawing.Size(336, 20);
00153       this.mAddressBar.TabIndex = 1;
00154       this.mAddressBar.Text = "";
00155       // 
00156       // mGoButton
00157       // 
00158       this.mGoButton.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
00159       this.mGoButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
00160       this.mGoButton.Location = new System.Drawing.Point(408, 2);
00161       this.mGoButton.Name = "mGoButton";
00162       this.mGoButton.Size = new System.Drawing.Size(32, 23);
00163       this.mGoButton.TabIndex = 2;
00164       this.mGoButton.Text = "Go";
00165       // 
00166       // LocationBar
00167       // 
00168       this.Controls.AddRange(new System.Windows.Forms.Control[] {
00169                                                                   this.mGoButton,
00170                                                                   this.mAddressBar,
00171                                                                   this.mAddressLabel});
00172       this.Name = "LocationBar";
00173       this.Size = new System.Drawing.Size(448, 25);
00174       this.ResumeLayout(false);
00175 
00176     }
00177               #endregion
00178        }
00179 
00180   public class LocationBarEventArgs : EventArgs
00181   {
00182     public LocationBarEventArgs(string aText)
00183     {
00184       mText = aText;
00185     }
00186 
00187     protected string mText;
00188     public string Text
00189     {
00190       get 
00191       {
00192         return mText;
00193       }
00194     }
00195   }
00196 }