Back to index

lightning-sunbird  0.9+nobinonly
BrowserDisplayPanel.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 
00049   using Silverstone.Manticore.Core;
00050 
00054        public class BrowserDisplayPanel : PrefPanel
00055        {
00056     private GroupBox groupBox1;
00057     private Button button2;
00058     private Label label2;
00059     private Button button1;
00060     private TextBox textBox1;
00061     private Label label1;
00062     private GroupBox groupBox2;
00063     private Button restoreSessionSettingsButton;
00064     private RadioButton radioButton3;
00065     private RadioButton radioButton2;
00066     private RadioButton radioButton1;
00070               private System.ComponentModel.Container components = null;
00071 
00075     private Form mOpener = null;
00076 
00077     private int mWindowOpenMode = 1;
00078     private bool mSaveSessionHistory = false;
00079 
00092               public BrowserDisplayPanel(Form aParent, Form aOpener, Preferences aPrefs) : base(aParent, aPrefs)
00093               {
00094                      // This call is required by the Windows.Forms Form Designer.
00095                      InitializeComponent();
00096 
00097       mOpener = aOpener;
00098 
00099       restoreSessionSettingsButton.Enabled = false;
00100 
00101       radioButton3.Click += new EventHandler(OnStartupModeRadio);
00102       radioButton2.Click += new EventHandler(OnStartupModeRadio);
00103       radioButton1.Click += new EventHandler(OnStartupModeRadio);
00104 
00105       restoreSessionSettingsButton.Click += new EventHandler(OnRestoreSessionSettings);
00106 
00107       button2.Click += new EventHandler(OnUseCurrent);
00108       button1.Click += new EventHandler(OnBrowseForHomepage);
00109     }
00110 
00111     protected internal void OnUseCurrent(object sender, EventArgs e)
00112     {
00113       // XXX what we really want to do here is use a window-mediator like
00114       //     entity to find the most recent browser window. This will surely
00115       //     fail miserably if the opening window isn't a browser. 
00116       BrowserWindow window = mOpener as BrowserWindow;
00117       if (window != null)
00118         textBox1.Text = window.URL;
00119     }
00120 
00121     protected internal void OnBrowseForHomepage(object sender, EventArgs e)
00122     {
00123       OpenFileDialog ofd = new OpenFileDialog();
00124       // Initially set directory to "My Documents";
00125       ofd.InitialDirectory = FileLocator.GetFolderPath(FileLocator.SpecialFolders.ssfPERSONAL);
00126       ofd.Filter = "HTML documents (*.html;*.htm)|*.html;*.htm|All files (*.*)|*.*";
00127       ofd.FilterIndex = 1;
00128       ofd.RestoreDirectory = true;
00129       ofd.Title = "Browse for Home Page";
00130 
00131       if(ofd.ShowDialog() == DialogResult.OK)
00132         textBox1.Text = ofd.FileName;
00133     }
00134 
00135     public void OnRestoreSessionSettings(object sender, EventArgs e)
00136     {
00137       RestoreSessionSettings dlg = new RestoreSessionSettings(mParent);
00138       dlg.WindowOpenMode = mWindowOpenMode;
00139       dlg.SaveSessionHistory = mSaveSessionHistory;
00140       if (dlg.ShowDialog() == DialogResult.OK) {
00141         mWindowOpenMode = dlg.WindowOpenMode;
00142         mSaveSessionHistory = dlg.SaveSessionHistory;
00143       }
00144     }
00145 
00146     public void OnStartupModeRadio(object sender, EventArgs e)
00147     {
00148       // Enable the Restore Session Settings button when the Restore Settings
00149       // startup mode is enabled. 
00150       restoreSessionSettingsButton.Enabled = radioButton3.Checked;
00151     }
00152 
00153     public override void Load()
00154     {
00155       mWindowOpenMode = mPrefs.GetIntPref("browser.session.windowmode");
00156       mSaveSessionHistory = mPrefs.GetBoolPref("browser.session.savesessionhistory");
00157 
00158       String homepageURL = mPrefs.GetStringPref("browser.homepage");
00159       textBox1.Text = homepageURL;
00160 
00161       int startMode = mPrefs.GetIntPref("browser.homepage.mode");
00162       switch (startMode) {
00163         case 2:
00164           radioButton3.Checked = true;
00165           restoreSessionSettingsButton.Enabled = true;
00166           break;
00167         case 0:
00168           radioButton2.Checked = true;
00169           break;
00170         case 1:
00171         default:
00172           radioButton1.Checked = true;
00173           break;
00174       }
00175     }
00176 
00177     public override void Save()
00178     {
00179       mPrefs.SetStringPref("browser.homepage", textBox1.Text != "" ? textBox1.Text : "about:blank");
00180 
00181       int mode = 1;
00182       if (radioButton3.Checked) 
00183         mode = 2;
00184       else if (radioButton2.Checked)
00185         mode = 0;
00186       mPrefs.SetIntPref("browser.homepage.mode", mode);
00187 
00188       mPrefs.SetIntPref("browser.session.windowmode", mWindowOpenMode);
00189       mPrefs.SetBoolPref("browser.session.savesessionhistory", mSaveSessionHistory);
00190     }
00191 
00195               protected override void Dispose( bool disposing )
00196               {
00197       if (disposing && components != null)
00198         components.Dispose();
00199       base.Dispose(disposing);
00200               }
00201 
00202               #region Component Designer generated code
00203 
00204 
00205 
00206 
00207               private void InitializeComponent()
00208               {
00209       this.groupBox1 = new GroupBox();
00210       this.button2 = new Button();
00211       this.label2 = new Label();
00212       this.button1 = new Button();
00213       this.textBox1 = new TextBox();
00214       this.label1 = new Label();
00215       this.groupBox2 = new GroupBox();
00216       this.restoreSessionSettingsButton = new Button();
00217       this.radioButton3 = new RadioButton();
00218       this.radioButton2 = new RadioButton();
00219       this.radioButton1 = new RadioButton();
00220       this.groupBox1.SuspendLayout();
00221       this.groupBox2.SuspendLayout();
00222       this.SuspendLayout();
00223       // 
00224       // groupBox1
00225       // 
00226       this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
00227                                                                             this.button2,
00228                                                                             this.label2,
00229                                                                             this.button1,
00230                                                                             this.textBox1,
00231                                                                             this.label1});
00232       this.groupBox1.Location = new System.Drawing.Point(8, 112);
00233       this.groupBox1.Name = "groupBox1";
00234       this.groupBox1.Size = new System.Drawing.Size(312, 104);
00235       this.groupBox1.TabIndex = 0;
00236       this.groupBox1.TabStop = false;
00237       this.groupBox1.Text = "Home Page";
00238       // 
00239       // button2
00240       // 
00241       this.button2.Location = new System.Drawing.Point(136, 72);
00242       this.button2.Name = "button2";
00243       this.button2.TabIndex = 4;
00244       this.button2.Text = "Use Current";
00245       this.button2.FlatStyle = FlatStyle.System;
00246       // 
00247       // label2
00248       // 
00249       this.label2.Location = new System.Drawing.Point(8, 48);
00250       this.label2.Name = "label2";
00251       this.label2.Size = new System.Drawing.Size(56, 16);
00252       this.label2.TabIndex = 3;
00253       this.label2.Text = "Location:";
00254       // 
00255       // button1
00256       // 
00257       this.button1.Location = new System.Drawing.Point(221, 72);
00258       this.button1.Name = "button1";
00259       this.button1.Size = new System.Drawing.Size(75, 24);
00260       this.button1.TabIndex = 2;
00261       this.button1.Text = "Browse...";
00262       this.button2.FlatStyle = FlatStyle.System;
00263       // 
00264       // textBox1
00265       // 
00266       this.textBox1.Location = new System.Drawing.Point(64, 48);
00267       this.textBox1.Name = "textBox1";
00268       this.textBox1.Size = new System.Drawing.Size(232, 20);
00269       this.textBox1.TabIndex = 1;
00270       this.textBox1.Text = "http://www.silverstone.net.nz/";
00271       // 
00272       // label1
00273       // 
00274       this.label1.Location = new System.Drawing.Point(8, 24);
00275       this.label1.Name = "label1";
00276       this.label1.Size = new System.Drawing.Size(280, 16);
00277       this.label1.TabIndex = 0;
00278       this.label1.Text = "Clicking the Home button takes you to this page:";
00279       // 
00280       // groupBox2
00281       // 
00282       this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
00283                                                                             this.restoreSessionSettingsButton,
00284                                                                             this.radioButton3,
00285                                                                             this.radioButton2,
00286                                                                             this.radioButton1});
00287       this.groupBox2.Location = new System.Drawing.Point(8, 0);
00288       this.groupBox2.Name = "startupModeGroup";
00289       this.groupBox2.Size = new System.Drawing.Size(312, 104);
00290       this.groupBox2.TabIndex = 1;
00291       this.groupBox2.TabStop = false;
00292       this.groupBox2.Text = "When Manticore starts, ";
00293       // 
00294       // restoreSessionSettingsButton
00295       // 
00296       this.restoreSessionSettingsButton.Location = new Point(224, 72);
00297       this.restoreSessionSettingsButton.Name = "restoreSessionSettingsButton";
00298       this.restoreSessionSettingsButton.TabIndex = 3;
00299       this.restoreSessionSettingsButton.Text = "Settings...";
00300       this.restoreSessionSettingsButton.FlatStyle = FlatStyle.System;
00301       // 
00302       // radioButton3
00303       // 
00304       this.radioButton3.Location = new System.Drawing.Point(16, 72);
00305       this.radioButton3.Name = "restoreSessionRadio";
00306       this.radioButton3.Size = new System.Drawing.Size(152, 16);
00307       this.radioButton3.TabIndex = 2;
00308       this.radioButton3.Text = "Restore previous session";
00309       this.radioButton3.FlatStyle = FlatStyle.System;
00310       // 
00311       // radioButton2
00312       // 
00313       this.radioButton2.Location = new System.Drawing.Point(16, 48);
00314       this.radioButton2.Name = "blankPageRadio";
00315       this.radioButton2.Size = new System.Drawing.Size(112, 16);
00316       this.radioButton2.TabIndex = 1;
00317       this.radioButton2.Text = "Show blank page";
00318       this.radioButton2.FlatStyle = FlatStyle.System;
00319       // 
00320       // radioButton1
00321       // 
00322       this.radioButton1.Location = new System.Drawing.Point(16, 24);
00323       this.radioButton1.Name = "homePageRadio";
00324       this.radioButton1.Size = new System.Drawing.Size(120, 16);
00325       this.radioButton1.TabIndex = 0;
00326       this.radioButton1.Text = "Show home page";
00327       this.radioButton1.FlatStyle = FlatStyle.System;
00328       // 
00329       // BrowserDisplayPanel
00330       // 
00331       this.Controls.AddRange(new System.Windows.Forms.Control[] { this.groupBox1,
00332                                                                   this.groupBox2});
00333       this.Name = "BrowserDisplayPanel";
00334       this.Size = new System.Drawing.Size(320, 280);
00335       this.groupBox1.ResumeLayout(false);
00336       this.groupBox2.ResumeLayout(false);
00337       this.ResumeLayout(false);
00338 
00339     }
00340               #endregion
00341        }
00342 }