gtk-sharp0.0.0.0Gtk# is thread aware, but not thread safe; See the Gtk# Thread Programming for details.Lightweight HTML rendering widget.
Gtk.HTML is a lightweight HTML rendering widget, as well as as
simple graphical HTML editor.
Developers can also be used as a widget container (). It is an easy way for viewing HTML
documents in your application and for layout UI of your
application throught HTML.
Gtk.HTML does not have support for CSS or JavaScript.
The following sample is a very minimal web browser.
using System;
using System.Net;
using System.IO;
using Gtk;
using GtkSharp;
namespace HtmlTest
{
class HtmlTest
{
HTML html;
Entry entry;
string currentUrl;
static void Main (string[] args)
{
new HtmlTest();
}
HtmlTest()
{
Application.Init ();
Window win = new Window ("HtmlTest");
win.SetDefaultSize (800, 600);
win.DeleteEvent += new DeleteEventHandler (OnWindowDelete);
VBox vbox = new VBox (false, 1);
win.Add (vbox);
HBox hbox = new HBox (false, 1);
Label label = new Label ("Address:");
entry = new Entry ("");
entry.Activated += new EventHandler (OnEntryActivated);
Button button = new Button ("Go!");
button.Clicked += new EventHandler (OnButtonClicked);
hbox.PackStart (label, false, false, 1);
hbox.PackStart (entry, true, true, 1);
hbox.PackStart (button, false, false, 1);
vbox.PackStart (hbox, false, false, 1);
ScrolledWindow sw = new ScrolledWindow ();
sw.VscrollbarPolicy = PolicyType.Always;
sw.HscrollbarPolicy = PolicyType.Always;
vbox.PackStart(sw, true, true, 1);
html = new HTML ();
html.LinkClicked += new LinkClickedHandler (OnLinkClicked);
sw.Add (html);
win.ShowAll();
Application.Run ();
}
void OnWindowDelete (object obj, DeleteEventArgs args)
{
Application.Quit();
}
void OnButtonClicked (object obj, EventArgs args)
{
currentUrl = entry.Text.Trim();
LoadHtml (currentUrl);
}
void OnEntryActivated (object obj, EventArgs args)
{
OnButtonClicked (obj, args);
}
void OnLinkClicked (object obj, LinkClickedArgs args)
{
string newUrl;
// decide absolute or relative
if (args.Url.StartsWith("http://"))
newUrl = args.Url;
else
newUrl = currentUrl + args.Url;
try {
LoadHtml (newUrl);
} catch { }
currentUrl = newUrl;
}
void LoadHtml (string URL)
{
HttpWebRequest web_request = (HttpWebRequest) WebRequest.Create (URL);
HttpWebResponse web_response = (HttpWebResponse) web_request.GetResponse ();
Stream stream = web_response.GetResponseStream ();
byte [] buffer = new byte [8192];
HTMLStream html_stream = html.Begin ();
int count;
while ((count = stream.Read (buffer, 0, 8192)) != 0){
html_stream.Write (buffer, count);
}
html.End (html_stream, HTMLStreamStatus.Ok);
}
}
}
Gtk.LayoutAtk.ImplementorGLib.IWrapperGLib.IWrapperSystem.IDisposableMethodSystem.VoidConstructs an instance of a Gtk.HTML widget
A Gtk.HTML derivative object.
This is a low-level routine, and should only be used
to initialize an instance of a Gtk.HTML derivative class.MethodSystem.IntPtrLocates an object whose id is provided
The id assigned to an object in the HTML stream
An IntPtr to the internal HTMLObjectMethodSystem.BooleanTo be added
To be added: an object of type 'string'
To be added: an object of type 'Gtk.HTMLSaveReceiverFn'
To be added: an object of type 'bool'To be addedMethodSystem.VoidCopies the selection to the clipboard.Copies the selection into the clipboard.MethodSystem.VoidSelects the word under the cursor.This routine selects the word under the cursor.MethodSystem.VoidTo be added
To be added: an object of type 'Gtk.HTMLFontStyle'
To be addedMethodSystem.VoidTo be addedTo be addedMethodSystem.VoidTo be addedTo be addedMethodSystem.VoidTo be added
To be added: an object of type 'Gtk.HTMLStream'
To be added: an object of type 'string'
To be added: an object of type 'int'
To be addedMethodSystem.VoidUndoes the last operation.If the widget is Editable, this undoes the last operation.MethodSystem.VoidCuts the selection into the clipboard.If the widget is editable, this cuts the selection
into the clipboard; Otherwise it just copies the selection
into the clipboard.MethodSystem.StringComputes url from widget base url.
The new component of the url.
The new base-relative url.MethodSystem.VoidTo be addedTo be addedMethodGtk.HTMLStreamStarts incremental content updating.A handle to push content.
Use the Begin method to push new HTML content into the
widget. The content type is expected to be in the format
defined by ,
which by default is "html/text; charset=utf-8".
using System;
using Gtk;
class X {
static void Main ()
{
Application.Init ();
Window w = new Window ("Sample");
HTML html = new HTML ();
w.Add (html);
w.ShowAll ();
HTMLStream s = html.Begin ();
string line;
while ((line = Console.ReadLine ()) != null)
s.Write (line);
html.End (s, HTMLStreamStatus.Ok);
Application.Run ();
}
}
Compile and run:
mcs sample.cs -r:gtk-sharp
echo "
Hello World
" | mono sample.exe
MethodSystem.VoidTo be addedTo be addedMethodSystem.VoidPaste clipboard contents into editor
Whether to paste as a citation.
If the widget is in editing mode (see ), the contents of the clipboard
are pasted into the HTML editor. If the value of is true, then the contents are pasted
as a citation.
MethodSystem.VoidTo be addedTo be addedMethodSystem.BooleanTo be addedTo be added: an object of type 'bool'To be addedMethodSystem.VoidEnds incremental updating
The to close.
The representing the state of the stream when closed.
Closes the represented
by and notifies the HTML widget that
it should not expect any more content from that stream.
using System;
using Gtk;
class X {
static void Main ()
{
Application.Init ();
Window w = new Window ("Sample");
HTML html = new HTML ();
w.Add (html);
w.ShowAll ();
HTMLStream s = html.Begin ();
string line;
while ((line = Console.ReadLine ()) != null)
s.Write (line);
html.End (s, HTMLStreamStatus.Ok);
Application.Run ();
}
}
Compile and run:
mcs sample.cs -r:gtk-sharp
echo "
Hello World
" | mono sample.exe
MethodSystem.VoidRedoes the last Undone operationIf the widget is editable, this redoes the last
undone operation.MethodSystem.VoidTo be added
To be added: an object of type 'string'
To be addedMethodSystem.VoidTo be addedTo be addedMethodSystem.VoidTo be addedTo be addedMethodSystem.VoidSelects all the contents.Selects all of the contents of the HTML widget.MethodGtk.HTMLStreamTo be added
To be added: an object of type 'string'
To be added: an object of type 'string'
To be added: an object of type 'Gtk.HTMLBeginFlags'
To be added: an object of type 'Gtk.HTMLStream'To be addedMethodSystem.VoidTo be added
To be added: an object of type 'bool'
To be addedMethodSystem.BooleanTo be addedTo be added: an object of type 'bool'To be addedMethodSystem.VoidUnsupported in Gtk#. Installs hooks for the editor.
To be added: an object of type 'Gtk.HTMLEditorAPI'
To be added: an object of type 'IntPtr'
This API is currently not supported.MethodSystem.VoidTo be added
To be added: an object of type 'Gtk.HTML'
To be addedMethodSystem.VoidZooms in.Zooms in the view.MethodSystem.VoidTo be added
To be added: an object of type 'string'
To be addedMethodSystem.VoidTo be added
To be added: an object of type 'Gtk.HTMLFontStyle'
To be added: an object of type 'Gtk.HTMLFontStyle'
To be addedMethodSystem.VoidTo be added
To be added: an object of type 'string'
To be addedMethodSystem.VoidTo be added
To be added: an object of type 'string'
To be addedMethodSystem.BooleanJumps to an anchor by name, making it visible.
The anchor to locate.
if the anchor is found.Scroll the document display to show the HTML anchor requested.MethodSystem.VoidTo be added
To be added: an object of type 'string'
To be addedMethodSystem.Int32To be added
To be added: an object of type 'Gdk.Atom'
To be added: an object of type 'int'
To be added: an object of type 'int'
To be added: an object of type 'bool'
To be added: an object of type 'int'To be addedMethodSystem.VoidTo be addedTo be addedMethodSystem.BooleanTo be added
To be added: an object of type 'Gtk.HTMLSaveReceiverFn'
To be added: an object of type 'bool'To be addedMethodGtk.HTMLStreamStarts incremental content updating. With a specific
content type.
The content type for the data to be
streamed.
A handle to push content.
Use the Begin method to push new HTML content into the
widget. The content type has to be specified (like this
for example: "html/text; charset=utf-8").
using System;
using Gtk;
class X {
static void Main ()
{
Application.Init ();
Window w = new Window ("Sample");
HTML html = new HTML ();
w.Add (html);
w.ShowAll ();
HTMLStream s = html.Begin ("text/html; charset=utf-8");
string line;
while ((line = Console.ReadLine ()) != null)
s.Write (line);
html.End (s, HTMLStreamStatus.Ok);
Application.Run ();
}
}
Compile and run:
mcs sample.cs -r:gtk-sharp
echo "
Hello World
" | mono sample.exe
MethodSystem.VoidTo be added
To be added: an object of type 'bool'
To be addedMethodSystem.VoidDrops all the undo information.Drops all the Undo and Redo information from the widget.MethodSystem.VoidTo be addedTo be addedMethodSystem.VoidZooms out.Zooms out the view.MethodSystem.BooleanTo be added
To be added: an object of type 'string'
To be added: an object of type 'bool'To be addedMethodSystem.VoidDisposes the resources associated with the object.ConstructorInternal constructor
Pointer to the C object.
An instance of HTML, wrapping the C object.This is an internal constructor, and should not be used by user code.ConstructorCreates an empty GtkHTML widget.The new constructed widget.
It creates an empty widget. The
returned widget is empty, and defaults to not be editable.
PropertySystem.UInt32The GLib Type for Gtk.HTMLThe GLib Type for the Gtk.HTML class.PropertySystem.BooleanWhether the contents can be edited.
Editing state.
if the contents are editable,
otherwise.
Whether this Gtk.HTML instance can be used as an HTML
editor.
PropertySystem.UInt32To be addedTo be added: an object of type 'uint'To be addedPropertySystem.StringTo be added
To be added: an object of type 'string'
To be added: an object of type 'string'To be addedPropertySystem.StringTo be added
To be added: an object of type 'string'
To be added: an object of type 'string'To be addedPropertySystem.StringTo be added
To be added: an object of type 'string'
To be added: an object of type 'string'To be addedPropertyGtk.HTMLParagraphStyleTo be added
To be added: an object of type 'Gtk.HTMLParagraphStyle'
To be added: an object of type 'Gtk.HTMLParagraphStyle'To be addedPropertySystem.BooleanTo be added
To be added: an object of type 'bool'
To be added: an object of type 'bool'To be addedPropertySystem.DoubleTo be added
To be added: an object of type 'double'
To be added: an object of type 'double'To be addedPropertyGtk.HTMLParagraphAlignmentTo be added
To be added: an object of type 'Gtk.HTMLParagraphAlignment'
To be added: an object of type 'Gtk.HTMLParagraphAlignment'To be addedPropertySystem.BooleanTo be added
To be added: an object of type 'bool'
To be added: an object of type 'bool'To be addedEventGtkSharp.InsertionFontStyleChangedHandlerTo be addedTo be addedEventGtkSharp.TitleChangedHandlerOccurs when the title changes in HTML
This event is raised when the HTML parser encounters the
<title> tag on the HTML stream. To get the title, use
the property.
EventGtkSharp.SetBaseHandlerTo be addedTo be addedEventSystem.EventHandlerTo be addedTo be addedEventGtkSharp.CurrentParagraphStyleChangedHandlerTo be addedTo be addedEventSystem.EventHandlerTo be addedTo be addedEventGtkSharp.CursorMoveHandlerOccurs when the cursor moves.
This event is raised when the widget is in editing mode and
the cursor has moved.
EventGtkSharp.OnCommandHandlerTo be addedTo be addedEventGtkSharp.UrlRequestedHandlerOccurs when a url is Requested
This event is raised when an URL is requested (typically
an image).
The following example shows how a simple HTML source that
requests an image (hello.png). If the file is found, then
it will be streamed into the HTML widget. The model
allows for data to be delivered as it comes, and when the
data has all arrived, the End method can be invoked on the
html stream provided by the .
using System;
using System.IO;
using Gtk;
using GtkSharp;
class X {
static void Main ()
{
Application.Init ();
Window w = new Window ("Sample");
HTML html = new HTML ();
html.UrlRequested += new UrlRequestedHandler (LoadFromDisk);
w.Add (html);
w.ShowAll ();
HTMLStream s = html.Begin ();
s.Write ("<html><body>My image: <img src=\"hello.png\"></body></html>");
html.End (s, HTMLStreamStatus.Ok);
Application.Run ();
}
static void LoadFromDisk (object sender, UrlRequestedArgs args)
{
try {
FileStream s = File.OpenRead (args.Url);
byte [] buffer = new byte [8192];
int n;
while ((n = s.Read (buffer, 0, 8192)) != 0) {
args.Handle.Write (buffer, n);
}
args.Handle.Close (HTMLStreamStatus.Ok);
} catch {
// Ignore errors.
}
}
}
Make sure there is a "hello.png" file in your directory to
see it, otherwise the sample will show the "broken image
link" image.
mcs sample.cs -r:gtk-sharp
mono sample.exe
EventGtkSharp.IframeCreatedHandlerTo be addedTo be addedEventGtkSharp.ScrollHandlerTo be addedTo be addedEventGtkSharp.CurrentParagraphIndentationChangedHandlerTo be addedTo be addedEventGtkSharp.CurrentParagraphAlignmentChangedHandlerTo be addedTo be addedEventGtkSharp.InsertionColorChangedHandlerTo be addedTo be addedEventGtkSharp.LinkClickedHandlerOccurs when the user clicks on a hyperlink
This event is raised when the user clicks on a hyperlink
in the HTML widget.
using System;
using System.IO;
using Gtk;
using GtkSharp;
class X {
static void Main ()
{
Application.Init ();
Window w = new Window ("Sample");
HTML html = new HTML ("<html><body>Click <a href=\"http://www.go-mono.com\">me</a>");
html.LinkClicked += new LinkClickedHandler (OnLinkClicked);
w.Add (html);
w.ShowAll ();
Application.Run ();
}
static void OnLinkClicked (object o, LinkClickedArgs args)
{
Console.WriteLine ("The link clicked url is: " + args.Url);
}
}
mcs sample.cs -r:gtk-sharp
mono sample.exe
Click on the "me" link to see the message on the console.
EventGtkSharp.SubmitHandlerTo be addedTo be addedEventGtkSharp.RedirectHandlerTo be addedTo be addedEventGtkSharp.OnUrlHandlerOccurs when the user hovers over a hyper-link.
This event is raised when the mouse pointer hovers over a
hyper link or leaves a link. In the former case the value
of is the link
target, and in the later the empty string.
using System;
using System.IO;
using Gtk;
using GtkSharp;
class X {
static void Main ()
{
Application.Init ();
Window w = new Window ("Sample");
HTML html = new HTML ("<html><body>Click <a href=\"http://www.go-mono.com\">me</a>");
html.OnUrl += new OnUrlHandler (OnUrl);
w.Add (html);
w.ShowAll ();
Application.Run ();
}
static void OnUrl (object o, OnUrlArgs args)
{
Console.WriteLine ("The mouse is over: " + args.Url);
}
}
mcs sample.cs -r:gtk-sharp
mono sample.exe
Hover in and out of the link to see the effects on the console.
EventGtkSharp.SetBaseTargetHandlerTo be addedTo be addedMethodSystem.VoidTo be added
To be added: an object of type 'string'
To be addedConstructorInternal constructor
GLib type for the type
Creates a new instance of HTML, using the GLib-provided typeThis is a constructor used by derivative types of that would have their own GLib type assigned to it. This is not typically used by C# code.ConstructorTo be added
To be added: an object of type 'string'
To be added: an object of type 'Gtk.HTML'To be addedPropertySystem.StringTo be added
To be added: an object of type 'string'
To be added: an object of type 'string'To be addedPropertySystem.StringTo be added
To be added: an object of type 'string'
To be added: an object of type 'string'To be addedPropertySystem.BooleanTo be added
a a To be addedPropertySystem.BooleanTo be added
a a To be addedPropertySystem.BooleanTo be added
a a To be addedPropertySystem.BooleanTo be added
a a To be added