Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 244 lines (204 sloc) 6.819 kb
fbe1024 2008-05-12 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
1 //
2 // WebKit# - WebKit bindings for Mono
3 //
4 // Author:
5 // Everaldo Canuto <ecanuto@novell.com>
6 //
7 // Copyright (c) 2008 Novell, Inc. All rights reserved.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29
f3e70e5 Initial import
Everaldo Canuto authored
30 using System;
31 using Gtk;
32 using GtkSharp;
33 using WebKit;
34
35 namespace FunnyBrowser
36 {
37 public class MainClass
38 {
39 public static void Main (string[] args)
40 {
41 string url = (args.Length > 0) ? args[0] : "";
42
43 Application.Init ();
44 MainWindow window = new MainWindow (url);
45 window.Show ();
46 Application.Run ();
47 }
48 }
49
50 public class MainWindow: Gtk.Window
51 {
fbe1024 2008-05-12 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
52 const string APP_NAME = "FunnyBrowser";
53
f3e70e5 Initial import
Everaldo Canuto authored
54 private string url = "http://www.google.com/";
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
55
56 private Gtk.VBox vbox = null;
57 private Gtk.Toolbar toolbar = null;
58 private Gtk.Toolbar findbar = null;
59 private Gtk.Entry uri_entry = null;
60 private Gtk.Entry find_entry = null;
f3e70e5 Initial import
Everaldo Canuto authored
61 private WebKit.WebView webview = null;
62 private Gtk.Statusbar statusbar = null;
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
63
64 private Gtk.Action action_back;
65 private Gtk.Action action_forward;
66 private Gtk.Action action_reload;
67 private Gtk.Action action_stop;
68 private Gtk.Action action_jump;
f3e70e5 Initial import
Everaldo Canuto authored
69
70 public MainWindow (string url): base (Gtk.WindowType.Toplevel)
71 {
72 if (url != "")
73 this.url = url;
74
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
75 CreateWidgets ();
f3e70e5 Initial import
Everaldo Canuto authored
76 webview.Open (this.url);
77 }
78
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
79 private void CreateWidgets ()
f3e70e5 Initial import
Everaldo Canuto authored
80 {
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
81 this.Title = APP_NAME;
fbe1024 2008-05-12 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
82 this.SetDefaultSize (700, 500);
83 this.DeleteEvent += new DeleteEventHandler (OnDeleteEvent);
f3e70e5 Initial import
Everaldo Canuto authored
84
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
85 CreateActions ();
86 CreateToolbar ();
87 CreateWebView ();
88 CreateFindbar ();
89 CreateStatusBar ();
90
91 Gtk.ScrolledWindow scroll = new Gtk.ScrolledWindow ();
92 scroll.Add (webview);
f3e70e5 Initial import
Everaldo Canuto authored
93
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
94 vbox = new Gtk.VBox (false, 1);
95 vbox.PackStart (toolbar, false, false, 0);
96 vbox.PackStart (scroll);
97 //vbox.PackStart (findbar, false, false, 0);
98 vbox.PackEnd (statusbar, false, true, 0);
99
100 this.Add (vbox);
101 this.ShowAll ();
102 }
103
104 private void CreateActions ()
105 {
106 action_back = new Gtk.Action("go-back", "Go Back", null, "gtk-go-back");
107 action_forward = new Gtk.Action("go-forward", "Go Forward", null, "gtk-go-forward");
108 action_reload = new Gtk.Action("reload", "Reload", null, "gtk-refresh");
109 action_stop = new Gtk.Action("stop", "Stop", null, "gtk-stop");
110 action_jump = new Gtk.Action("jump", "Jump", null, "gtk-jump-to");
111
112 action_back.Activated += new EventHandler(on_back_activate);
113 action_forward.Activated += new EventHandler(on_forward_activate);
114 action_reload.Activated += new EventHandler(on_reload_activate);
115 action_stop.Activated += new EventHandler(on_stop_activate);
116 action_jump.Activated += new EventHandler(on_uri_activate);
117 }
118
119 private void CreateToolbar ()
120 {
121 // UrlEntry
122 uri_entry = new Gtk.Entry ();
123 uri_entry.Activated += new EventHandler(on_uri_activate);
124
125 Gtk.ToolItem uri_item = new Gtk.ToolItem ();
126 uri_item.Expand = true;
127 uri_item.Add (uri_entry);
128
129 // Toolbar
f3e70e5 Initial import
Everaldo Canuto authored
130 toolbar = new Toolbar ();
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
131 toolbar.ToolbarStyle = ToolbarStyle.Icons;
f3e70e5 Initial import
Everaldo Canuto authored
132 toolbar.Orientation = Orientation.Horizontal;
133 toolbar.ShowArrow = true;
134
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
135 // Toolbar Itens
136 toolbar.Add (action_back.CreateToolItem());
137 toolbar.Add (action_forward.CreateToolItem());
138 toolbar.Add (action_reload.CreateToolItem());
139 toolbar.Add (action_stop.CreateToolItem());
140 toolbar.Add (uri_item);
141 toolbar.Add (action_jump.CreateToolItem());
142 }
143
144 private void CreateWebView ()
145 {
f3e70e5 Initial import
Everaldo Canuto authored
146 webview = new WebView ();
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
147 webview.Editable = false;
148 webview.TitleChanged += new TitleChangedHandler (OnTitleChanged);
149 webview.HoveringOverLink += new HoveringOverLinkHandler (OnHoveringOverLink);
150 webview.LoadCommitted += new LoadCommittedHandler (OnLoadCommitted);
151 webview.LoadFinished += new LoadFinishedHandler (OnLoadFinished);
152 }
f3e70e5 Initial import
Everaldo Canuto authored
153
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
154 private void CreateStatusBar ()
155 {
f3e70e5 Initial import
Everaldo Canuto authored
156 statusbar = new Gtk.Statusbar ();
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
157 }
f3e70e5 Initial import
Everaldo Canuto authored
158
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
159 private void CreateFindbar ()
160 {
161 // FindEntry
162 find_entry = new Gtk.Entry ();
163 //find_entry.Activated += new EventHandler(on_uri_activate);
164
165 Gtk.ToolItem find_item = new Gtk.ToolItem ();
166 //find_item.Expand = true;
167 find_item.Add (find_entry);
168
169 // Toolbar
170 findbar = new Toolbar ();
171 findbar.ToolbarStyle = ToolbarStyle.Icons;
172 findbar.Orientation = Orientation.Horizontal;
173 findbar.ShowArrow = true;
174
175 // Toolbar Itens
176 findbar.Add (action_stop.CreateToolItem());
177 findbar.Add (find_item);
178 findbar.Add (action_back.CreateToolItem());
179 findbar.Add (action_forward.CreateToolItem());
180 }
181
182 protected void OnDeleteEvent (object sender, DeleteEventArgs args)
183 {
184 Application.Quit ();
185 args.RetVal = true;
186 }
187
188 private void OnTitleChanged (object o, TitleChangedArgs args)
189 {
190 if (args.Title == String.Empty)
191 this.Title = APP_NAME;
192 else
193 this.Title = String.Format ("{0} - {1}", args.Title, APP_NAME);
f3e70e5 Initial import
Everaldo Canuto authored
194 }
fbe1024 2008-05-12 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
195
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
196 private void OnHoveringOverLink (object o, HoveringOverLinkArgs args)
fbe1024 2008-05-12 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
197 {
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
198 statusbar.Pop (1);
199 if (args.Link != null) {
200 statusbar.Push (1, args.Link);
fbe1024 2008-05-12 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
201 }
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
202 }
203
204 private void OnLoadCommitted (object o, LoadCommittedArgs args)
f3e70e5 Initial import
Everaldo Canuto authored
205 {
5c356ce 2008-05-16 Everaldo Canuto <ecanuto@novell.com>
Everaldo Canuto authored
206 action_back.Sensitive = webview.CanGoBack ();
207 action_forward.Sensitive = webview.CanGoForward ();
208
209 uri_entry.Text = args.Frame.Uri;
210 }
211
212 private void OnLoadFinished (object o, LoadFinishedArgs args)
213 {
214 //
215 }
216
217 private void on_back_activate (object o, EventArgs args)
218 {
219 webview.GoBack ();
220 }
221
222 private void on_forward_activate (object o, EventArgs args)
223 {
224 webview.GoForward ();
225 }
226
227 private void on_reload_activate (object o, EventArgs args)
228 {
229 webview.Reload ();
230 }
231
232 private void on_stop_activate (object o, EventArgs args)
233 {
234 webview.StopLoading ();
235 }
236
237 private void on_uri_activate (object o, EventArgs args)
238 {
239 webview.Open (uri_entry.Text);
f3e70e5 Initial import
Everaldo Canuto authored
240 }
241 }
242 }
243
Something went wrong with that request. Please try again.