зеркало из https://github.com/mozilla/gecko-dev.git
Initial revision of Manticore. r=hyatt. NOT PART OF BUILD.
This commit is contained in:
Родитель
681b0e8a1b
Коммит
fb581de799
|
@ -0,0 +1,41 @@
|
|||
|
||||
namespace Silverstone.Manticore.App
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using System.Collections;
|
||||
|
||||
using Silverstone.Manticore.BrowserWindow;
|
||||
|
||||
public class ManticoreApp
|
||||
{
|
||||
// XXX Need to do something here more similar
|
||||
// to what mozilla does here for parameterized
|
||||
// window types.
|
||||
private Queue browserWindows;
|
||||
|
||||
public ManticoreApp()
|
||||
{
|
||||
browserWindows = new Queue();
|
||||
|
||||
OpenNewBrowser();
|
||||
|
||||
Application.Run();
|
||||
}
|
||||
|
||||
// Opens and displays a new browser window
|
||||
public void OpenNewBrowser()
|
||||
{
|
||||
BrowserWindow window = new BrowserWindow(this);
|
||||
browserWindows.Enqueue(window);
|
||||
window.Show();
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
ManticoreApp app = new ManticoreApp();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
namespace Silverstone.Manticore.AboutDialog
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
public class AboutDialog : System.Windows.Forms.Form
|
||||
{
|
||||
private System.ComponentModel.Container components;
|
||||
|
||||
private Form parentWindow;
|
||||
|
||||
public AboutDialog(Form parent)
|
||||
{
|
||||
parentWindow = parent;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
// Show the about dialog modally.
|
||||
this.ShowDialog();
|
||||
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
components.Dispose();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
|
||||
this.Width = 253;
|
||||
this.Height = 195;
|
||||
|
||||
this.Left = parentWindow.Left + ((parentWindow.Width / 2) - (this.Width / 2));
|
||||
this.Top = parentWindow.Top + ((parentWindow.Height / 2) - (this.Height / 2));
|
||||
|
||||
// Borderless dialog
|
||||
this.FormBorderStyle = FormBorderStyle.None;
|
||||
|
||||
this.BackgroundImage = Image.FromFile("manticore.png");
|
||||
|
||||
this.Text = "About Manticore"; // XXX localize
|
||||
|
||||
this.Click += new EventHandler(this.CloseAboutDialog);
|
||||
}
|
||||
|
||||
public void CloseAboutDialog(Object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<menubar id="mainMenu"
|
||||
xmlns="http://www.silverstone.net.nz/2001/manticore/uidl">
|
||||
|
||||
<menu label="File" accesskey="f">
|
||||
<menu label="New Window" accesskey="n" command="file-new-window"/>
|
||||
<menu label="Open..." accesskey="o" command="file-open"/>
|
||||
<menuseparator/>
|
||||
<menu label="Close" accesskey="c" command="file-close"/>
|
||||
<menu label="Save As..." accesskey="a" command="file-save-as"/>
|
||||
<menu label="Save" accesskey="s">
|
||||
<menu label="Images..." accesskey="i" command="file-save-images"/>
|
||||
<menu label="Form..." accesskey="f" command="file-save-form"/>
|
||||
</menu>
|
||||
<menuseparator/>
|
||||
<menu label="Send Page..." accesskey="g" command="file-send-page"/>
|
||||
<menu label="Send Link..." accesskey="l" command="file-send-link"/>
|
||||
<menuseparator/>
|
||||
<menu label="Page Setup" acccesskey="u" command="file-page-setup"/>
|
||||
<menu label="Print..." accesskey="p" command="file-print"/>
|
||||
<menu label="Print Preview" accesskey="v" command="file-print-preview"/>
|
||||
<menuseparator/>
|
||||
<menu label="Properties" accesskey="r" command="file-properties"/>
|
||||
<menuseparator/>
|
||||
<menu label="Exit" accesskey="x" command="file-exit"/>
|
||||
</menu>
|
||||
|
||||
<menu label="Edit" accesskey="e">
|
||||
<menu label="Undo" accesskey="u" command="edit-undo"/>
|
||||
<menu label="Redo" accesskey="r" command="edit-redo"/>
|
||||
<menuseparator/>
|
||||
<menu label="Cut" accesskey="t" command="edit-cut"/>
|
||||
<menu label="Copy" accesskey="c" command="edit-copy"/>
|
||||
<menu label="Paste" accesskey="p" command="edit-paste"/>
|
||||
<menu label="Delete" accesskey="d" command="edit-delete"/>
|
||||
<menuseparator/>
|
||||
<menu label="Select All" accesskey="a" command="edit-select-all"/>
|
||||
<menuseparator/>
|
||||
<menu label="Find..." accesskey="f" command="edit-find"/>
|
||||
<menu label="Find Again" accesskey="g" command="edit-find-again"/>
|
||||
</menu>
|
||||
|
||||
<menu label="View" accesskey="view">
|
||||
<menu label="Toolbars" accesskey="t">
|
||||
<menu label="Navigation Toolbar"/>
|
||||
<menu label="Location Toolbar"/>
|
||||
<menu label="Personal Toolbar"/>
|
||||
</menu>
|
||||
<menu label="Status Bar" accesskey="b" command="view-statusbar"/>
|
||||
<menu label="SideBar" accesskey="i">
|
||||
<menu label="Bookmarks"/>
|
||||
<menu label="History"/>
|
||||
</menu>
|
||||
<menuseparator/>
|
||||
<menu label="Go" accesskey="g">
|
||||
<menu label="Back" accesskey="b" command="view-go=back"/>
|
||||
<menu label="Back to"/>
|
||||
<menu label="Forward" accesskey="f" command="view-go-forward"/>
|
||||
<menu label="Forward to"/>
|
||||
<menuseparator/>
|
||||
<menu label="Home" accesskey="h" command="view-go-home"/>
|
||||
<menuseparator/>
|
||||
<menu label="History" accesskey="i" command="view-go-history"/>
|
||||
</menu>
|
||||
<menu label="Reload" accesskey="r" command="view-reload"/>
|
||||
<menu label="Stop" accesskey="s" command="view-stop"/>
|
||||
<menuseparator/>
|
||||
<menu label="Text Size" accesskey="t">
|
||||
<menu label="50%" accesskey="5" command="view-text-50%"/>
|
||||
<menu label="75%" accesskey="7" command="view-text-75%"/>
|
||||
<menu label="90%" accesskey="9" command="view-text-90%"/>
|
||||
<menu label="100% (Original size)" accesskey="o" command="view-text-100%"/>
|
||||
<menu label="125%" accesskey="1" command="view-text-125%"/>
|
||||
<menu label="175%" accesskey="5" command="view-text-175%"/>
|
||||
<menu label="200%" accesskey="2" command="view-text-200%"/>
|
||||
<menuseparator/>
|
||||
<menu label="Larger" accesskey="l" command="view-text-larger"/>
|
||||
<menu label="Smaller" accesskey="s" command="view-text-smaller"/>
|
||||
<menuseparator/>
|
||||
<menu label="Other (#%)" accesskey="t" command="view-text-other"/>
|
||||
</menu>
|
||||
<menu label="Use Stylesheet" accesskey="y"/>
|
||||
<menuseparator/>
|
||||
<menu label="Encoding" accesskey="e"/>
|
||||
</menu>
|
||||
<menu label="Bookmarks" accesskey="b">
|
||||
<menu label="Add Bookmark" accesskey="a" command="bookmarks-add"/>
|
||||
<menu label="File Bookmark..." accesskey="i" command="bookmarks-file"/>
|
||||
<menuseparator/>
|
||||
<menu label="Find in Bookmarks..." accesskey="f" command="bookmarks-find"/>
|
||||
<menu label="Manage Bookmarks" accesskey="m" command="bookmarks-manage"/>
|
||||
</menu>
|
||||
<menu label="Tools" accesskey="t">
|
||||
<menu label="Mail" accesskey="m" command="tools-mail"/>
|
||||
<menuseparator/>
|
||||
<menu label="Search the Web" accesskey="s" command="tools-search"/>
|
||||
<menuseparator/>
|
||||
<menu label="History" accesskey="h" command="tools-history"/>
|
||||
<menu label="JavaScript Console" accesskey="j" command="tools-jsconsole"/>
|
||||
<menu label="Java Console" accesskey="c" command="tools-jconsole"/>
|
||||
<menuseparator/>
|
||||
<menu label="Options" accesskey="o" command="tools-options"/>
|
||||
</menu>
|
||||
<menu label="Help" accesskey="h">
|
||||
<menu label="About Manticore..." accesskey="a" command="help-about"/>
|
||||
</menu>
|
||||
</menubar>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<toolbox id="mainToolbox"
|
||||
xmlns="http://www.silverstone.net.nz/2001/manticore/uidl">
|
||||
<toolstrip>
|
||||
<toolbar id="navigation-toolbar" label="Navigation Toolbar">
|
||||
<toolbarbutton label="Back" command="view-go-back"/>
|
||||
<toolbarbutton label="Forward" command="view-go-forward"/>
|
||||
<toolbarbutton label="Stop" command="view-stop"/>
|
||||
<toolbarbutton label="Reload" command="view-reload"/>
|
||||
</toolbar>
|
||||
</toolstrip>
|
||||
</toolbox>
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
|
||||
namespace Silverstone.Manticore.BrowserWindow
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Silverstone.Manticore.App;
|
||||
using Silverstone.Manticore.Toolkit.Menus;
|
||||
using Silverstone.Manticore.AboutDialog;
|
||||
using Silverstone.Manticore.OpenDialog;
|
||||
|
||||
using Silverstone.Manticore.LayoutAbstraction;
|
||||
|
||||
public class BrowserWindow : System.Windows.Forms.Form
|
||||
{
|
||||
private System.ComponentModel.Container components;
|
||||
|
||||
protected internal BrowserMenuBuilder menuBuilder;
|
||||
protected internal WebBrowser webBrowser;
|
||||
|
||||
protected internal StatusBar statusBar;
|
||||
|
||||
protected internal ManticoreApp application;
|
||||
|
||||
public BrowserWindow(ManticoreApp app)
|
||||
{
|
||||
application = app;
|
||||
|
||||
// Set up UI
|
||||
InitializeComponent();
|
||||
|
||||
// Perform post-window show startup tasks
|
||||
LayoutStartup();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
components.Dispose();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
|
||||
// XXX read these from a settings file
|
||||
this.Width = 640;
|
||||
this.Height = 480;
|
||||
|
||||
this.Text = "Manticore"; // XXX localize
|
||||
|
||||
menuBuilder = new BrowserMenuBuilder("browser\\browser-menu.xml", this);
|
||||
menuBuilder.Build();
|
||||
this.Menu = menuBuilder.mainMenu;
|
||||
|
||||
// Show the resize handle
|
||||
this.SizeGripStyle = SizeGripStyle.Auto;
|
||||
|
||||
webBrowser = new WebBrowser();
|
||||
this.Controls.Add(webBrowser);
|
||||
|
||||
// Set up the Status Bar
|
||||
statusBar = new StatusBar();
|
||||
|
||||
StatusBarPanel docStatePanel = new StatusBarPanel();
|
||||
StatusBarPanel statusPanel = new StatusBarPanel();
|
||||
StatusBarPanel progressPanel = new StatusBarPanel();
|
||||
StatusBarPanel zonePanel = new StatusBarPanel();
|
||||
|
||||
docStatePanel.Text = "X";
|
||||
progressPanel.Text = "[||||| ]";
|
||||
zonePanel.Text = "Internet Region";
|
||||
statusPanel.Text = "Document Done";
|
||||
statusPanel.AutoSize = StatusBarPanelAutoSize.Spring;
|
||||
|
||||
statusBar.Panels.AddRange(new StatusBarPanel[] {docStatePanel, statusPanel, progressPanel, zonePanel});
|
||||
statusBar.ShowPanels = true;
|
||||
|
||||
this.Controls.Add(statusBar);
|
||||
}
|
||||
|
||||
private void LayoutStartup()
|
||||
{
|
||||
// XXX - add a pref to control this, blank, or last page visited.
|
||||
// Visit the homepage
|
||||
String homepageURL = "http://www.silverstone.net.nz/";
|
||||
webBrowser.LoadURL(homepageURL, false);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Menu Command Handlers
|
||||
public void OpenNewBrowser()
|
||||
{
|
||||
application.OpenNewBrowser();
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
OpenDialog dlg = new OpenDialog(0);
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
Console.WriteLine(dlg.URL);
|
||||
}
|
||||
}
|
||||
|
||||
public class BrowserMenuBuilder : MenuBuilder
|
||||
{
|
||||
private BrowserWindow browserWindow;
|
||||
|
||||
public BrowserMenuBuilder(String file, BrowserWindow window) : base(file)
|
||||
{
|
||||
browserWindow = window;
|
||||
}
|
||||
|
||||
public override void OnCommand(Object sender, EventArgs e)
|
||||
{
|
||||
CommandMenuItem menuitem = (CommandMenuItem) sender;
|
||||
Console.WriteLine(menuitem.Command);
|
||||
switch (menuitem.Command) {
|
||||
case "file-new-window":
|
||||
browserWindow.OpenNewBrowser();
|
||||
break;
|
||||
case "file-open":
|
||||
browserWindow.Open();
|
||||
break;
|
||||
case "help-about":
|
||||
AboutDialog dlg = new AboutDialog(browserWindow);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
namespace Silverstone.Manticore.LayoutAbstraction
|
||||
{
|
||||
using System;
|
||||
using Microsoft.Win32;
|
||||
using System.Drawing;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Trident
|
||||
using AxSHDocVw;
|
||||
using MSHTML;
|
||||
|
||||
// Gecko
|
||||
using AxMOZILLACONTROLLib;
|
||||
using MOZILLACONTROLLib;
|
||||
|
||||
public class WebBrowser : ContainerControl
|
||||
{
|
||||
private IWebBrowser2 browser;
|
||||
|
||||
public WebBrowser()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
// XXX - remember this setting in a pref
|
||||
SwitchLayoutEngine("gecko");
|
||||
|
||||
this.Dock = DockStyle.Fill;
|
||||
}
|
||||
|
||||
public void SwitchLayoutEngine(String id)
|
||||
{
|
||||
AxHost host;
|
||||
switch (id) {
|
||||
case "trident":
|
||||
host = new AxWebBrowser() as AxHost;
|
||||
break;
|
||||
default:
|
||||
host = new AxMozillaBrowser() as AxHost;
|
||||
break;
|
||||
}
|
||||
|
||||
host.BeginInit();
|
||||
host.Size = new Size(600, 200);
|
||||
host.TabIndex = 1;
|
||||
host.Dock = DockStyle.Fill;
|
||||
host.EndInit();
|
||||
this.Controls.Add(host);
|
||||
|
||||
browser = host as IWebBrowser2;
|
||||
}
|
||||
|
||||
public void LoadURL(String url, Boolean bypassCache)
|
||||
{
|
||||
// XXX - neither IE nor Mozilla implement all of the
|
||||
// load flags properly. Mozilla should at least be
|
||||
// made to support ignore-cache and ignore-history.
|
||||
// This will require modification to the ActiveX
|
||||
// control.
|
||||
Object o = null;
|
||||
// browser.Navigate(url, ref o, ref o, ref o, ref o);
|
||||
}
|
||||
|
||||
public void GoHome()
|
||||
{
|
||||
// XXX - need to implement "Home" preference
|
||||
browser.GoHome();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
DEPTH=..\..
|
||||
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
|
||||
#--------------------------------------------------
|
||||
CLEANUP = *.exe *.pdb
|
||||
#--------------------------------------------------
|
||||
|
||||
DEBUG=FALSE
|
||||
|
||||
_CS_WINFORMS_IMPORTS=/R:System.DLL /R:System.Windows.Forms.DLL \
|
||||
/R:System.Drawing.DLL
|
||||
_CS_XML_IMPORTS=/R:System.DLL /R:System.Data.DLL /R:System.XML.DLL
|
||||
_CS_LAYOUT_IMPORTS=/R:AxSHDocVw.DLL /R:MSHTML.DLL /R:AxMOZILLACONTROLLib.DLL /R:MOZILLACONTROLLib.dll
|
||||
|
||||
_IMPORTS=$(_CS_WINFORMS_IMPORTS) $(_CS_XMLIMPORTS) $(_CS_LAYOUT_IMPORTS)
|
||||
|
||||
_COMPILE_CMD=csc /nologo /t:exe /debug+ $(_IMPORTS)
|
||||
|
||||
FILES = app.cs \
|
||||
browser\browserwindow.cs \
|
||||
toolkit\toolkit.menus.cs \
|
||||
browser\aboutdialog.cs \
|
||||
layout\layoutabstraction.cs \
|
||||
browser\opendialog.cs
|
||||
|
||||
SUBDIR = WIN32_O.OBJ
|
||||
!if defined(MOZ_DEBUG)
|
||||
SUBDIR = WIN32_D.OBJ
|
||||
!endif
|
||||
|
||||
|
||||
app:
|
||||
$(_COMPILE_CMD) $(FILES)
|
||||
|
||||
bindings:
|
||||
aximp c:\WINNT\system32\shdocvw.dll
|
||||
tlbimp mshtml.tlb
|
||||
aximp $(MOZ_SRC)\mozilla\dist\$(SUBDIR)\bin\mozctl.dll
|
||||
tlbimp $(MOZ_SRC)\mozilla\dist\$(SUBDIR)\bin\mozctl.dll
|
||||
|
||||
# XXX fix me
|
||||
clean:
|
||||
for %i in ( $(CLEANUP) ) do del %i
|
||||
|
||||
#--------------------------------------------------
|
||||
|
||||
|
||||
|
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 100 KiB |
Двоичный файл не отображается.
|
@ -0,0 +1,114 @@
|
|||
|
||||
namespace Silverstone.Manticore.Toolkit.Menus
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using System.Collections;
|
||||
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public class MenuBuilder
|
||||
{
|
||||
protected internal String menuDefinitionFile;
|
||||
|
||||
public MainMenu mainMenu;
|
||||
public Hashtable items;
|
||||
|
||||
public MenuBuilder(String file)
|
||||
{
|
||||
menuDefinitionFile = file;
|
||||
mainMenu = new MainMenu();
|
||||
items = new Hashtable();
|
||||
}
|
||||
|
||||
public void Build()
|
||||
{
|
||||
XmlTextReader reader;
|
||||
reader = new XmlTextReader(menuDefinitionFile);
|
||||
|
||||
reader.WhitespaceHandling = WhitespaceHandling.None;
|
||||
reader.MoveToContent();
|
||||
|
||||
Recurse(reader, mainMenu);
|
||||
}
|
||||
|
||||
protected void Recurse(XmlTextReader reader, Menu root)
|
||||
{
|
||||
String inner = reader.ReadInnerXml();
|
||||
|
||||
NameTable nt = new NameTable();
|
||||
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
|
||||
XmlParserContext ctxt = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
|
||||
XmlTextReader reader2 = new XmlTextReader(inner, XmlNodeType.Element, ctxt);
|
||||
|
||||
MenuItem menuitem;
|
||||
|
||||
while (reader2.Read()) {
|
||||
if (reader2.NodeType == XmlNodeType.Element) {
|
||||
switch (reader2.LocalName) {
|
||||
case "menu":
|
||||
// Menuitem. Find the name, accesskey, command and id strings
|
||||
String[] values = new String[3] {"", "", ""};
|
||||
String[] names = new String[3] {"label", "accesskey", "command"};
|
||||
for (Byte i = 0; i < names.Length; ++i) {
|
||||
if (reader2.MoveToAttribute(names[i]) &&
|
||||
reader2.ReadAttributeValue())
|
||||
values[i] = reader2.Value; // XXX need to handle entities
|
||||
reader2.MoveToElement();
|
||||
}
|
||||
|
||||
// Handle Accesskey
|
||||
int idx = values[0].ToLower().IndexOf(values[1].ToLower());
|
||||
if (idx != -1)
|
||||
values[0] = values[0].Insert(idx, "&");
|
||||
else
|
||||
values[0] += " (&" + values[1].ToUpper() + ")";
|
||||
|
||||
// Create menu item and attach an event handler
|
||||
menuitem = new CommandMenuItem(values[0],
|
||||
new EventHandler(OnCommand),
|
||||
values[2]);
|
||||
if (values[2] != "")
|
||||
items.Add(values[2], menuitem);
|
||||
root.MenuItems.Add(menuitem);
|
||||
Recurse(reader2, menuitem);
|
||||
break;
|
||||
case "menuseparator":
|
||||
menuitem = new MenuItem("-");
|
||||
root.MenuItems.Add(menuitem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnCommand(Object sender, EventArgs e)
|
||||
{
|
||||
// Implement in derived classes
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandMenuItem : MenuItem
|
||||
{
|
||||
private string command;
|
||||
public string Command
|
||||
{
|
||||
get {
|
||||
return command;
|
||||
}
|
||||
}
|
||||
|
||||
public CommandMenuItem(String label,
|
||||
EventHandler handler,
|
||||
String cmd) : base(label, handler)
|
||||
{
|
||||
command = cmd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
|
||||
namespace Silverstone.Manticore.Toolkit.Toolbars
|
||||
{
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using System.Collections;
|
||||
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
public class MToolbox : ContainerControl
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class MToolstrip : ContainerControl
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class MToolbar : ContainerControl
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class MToolbarButton : ToolbarButton
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class ToolbarBuilder
|
||||
{
|
||||
protected internal String toolbarDefinitionFile;
|
||||
|
||||
public MToolbox toolbox;
|
||||
public Hashtable items;
|
||||
|
||||
public ToolbarBuilder(String file)
|
||||
{
|
||||
toolbarDefinitionFile = file;
|
||||
toolbox = new MToolbox();
|
||||
items = new Hashtable();
|
||||
}
|
||||
|
||||
public void Build()
|
||||
{
|
||||
XmlTextReader reader;
|
||||
reader = new XmlTextReader(toolbarDefinitionFile);
|
||||
|
||||
reader.WhitespaceHandling = WhitespaceHandling.None;
|
||||
reader.MoveToContent();
|
||||
|
||||
Recurse(reader, toolbox);
|
||||
}
|
||||
|
||||
protected void Recurse(XmlTextReader reader, Menu root)
|
||||
{
|
||||
String inner = reader.ReadInnerXml();
|
||||
|
||||
NameTable nt = new NameTable();
|
||||
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
|
||||
XmlParserContext ctxt = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
|
||||
XmlTextReader reader2 = new XmlTextReader(inner, XmlNodeType.Element, ctxt);
|
||||
|
||||
MenuItem menuitem;
|
||||
|
||||
while (reader2.Read()) {
|
||||
if (reader2.NodeType == XmlNodeType.Element) {
|
||||
switch (reader2.LocalName) {
|
||||
case "menu":
|
||||
// Menuitem. Find the name, accesskey, command and id strings
|
||||
String[] values = new String[3] {"", "", ""};
|
||||
String[] names = new String[3] {"label", "accesskey", "command"};
|
||||
for (Byte i = 0; i < names.Length; ++i) {
|
||||
if (reader2.MoveToAttribute(names[i]) &&
|
||||
reader2.ReadAttributeValue())
|
||||
values[i] = reader2.Value; // XXX need to handle entities
|
||||
reader2.MoveToElement();
|
||||
}
|
||||
|
||||
// Handle Accesskey
|
||||
int idx = values[0].ToLower().IndexOf(values[1].ToLower());
|
||||
if (idx != -1)
|
||||
values[0] = values[0].Insert(idx, "&");
|
||||
else
|
||||
values[0] += " (&" + values[1].ToUpper() + ")";
|
||||
|
||||
// Create menu item and attach an event handler
|
||||
menuitem = new CommandMenuItem(values[0],
|
||||
new EventHandler(OnCommand),
|
||||
values[2]);
|
||||
if (values[2] != "")
|
||||
items.Add(values[2], menuitem);
|
||||
root.MenuItems.Add(menuitem);
|
||||
Recurse(reader2, menuitem);
|
||||
break;
|
||||
case "menuseparator":
|
||||
menuitem = new MenuItem("-");
|
||||
root.MenuItems.Add(menuitem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnCommand(Object sender, EventArgs e)
|
||||
{
|
||||
// Implement in derived classes
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче