mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
v1.7.2.1
This commit is contained in:
81
150_gfui/xtn/gplx/gfui/Swt_app_browser.java
Normal file
81
150_gfui/xtn/gplx/gfui/Swt_app_browser.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
XOWA: the XOWA Offline Wiki Application
|
||||
Copyright (C) 2012 gnosygnu@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui;
|
||||
import gplx.*;
|
||||
import org.eclipse.swt.*;
|
||||
import org.eclipse.swt.browser.*; import org.eclipse.swt.custom.*; import org.eclipse.swt.events.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*;
|
||||
public class Swt_app_browser {
|
||||
public static void main(String[] args) {
|
||||
Display display = new Display();
|
||||
Shell shell = new Shell(display);
|
||||
System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "C:\\xowa\\bin\\windows\\xulrunner");
|
||||
Swt_app_browser_mgr mgr = new Swt_app_browser_mgr(shell);
|
||||
New_btn(shell, 0, "loa&d", new Swt_app_browser_cmd_load(mgr));
|
||||
New_btn(shell, 1, "&free", new Swt_app_browser_cmd_free(mgr));
|
||||
shell.open();
|
||||
while (!shell.isDisposed()) {
|
||||
if (!display.readAndDispatch()) {
|
||||
display.sleep();
|
||||
}
|
||||
}
|
||||
mgr.Free();
|
||||
display.dispose();
|
||||
}
|
||||
private static Button New_btn(Shell shell, int idx, String text, SelectionListener lnr) {
|
||||
Button rv = new Button(shell, SWT.BORDER);
|
||||
rv.setText(text);
|
||||
rv.setBounds(idx * 80, 0, 80, 40);
|
||||
rv.addSelectionListener(lnr);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
class Swt_app_browser_mgr {
|
||||
private Shell shell; private Browser browser;
|
||||
public Swt_app_browser_mgr(Shell shell) {this.shell = shell;}
|
||||
public void Load() {
|
||||
// this.Free();
|
||||
if (browser == null) {
|
||||
browser = new Browser(shell, SWT.MOZILLA);
|
||||
Point size = shell.getSize();
|
||||
browser.setBounds(0, 40, size.x, size.y - 40);
|
||||
}
|
||||
// browser.setUrl("about:blank");
|
||||
browser.setUrl("file:///C:/temp.html");
|
||||
// browser.setText(Io_mgr._.LoadFilStr("C:\\temp.html"));
|
||||
}
|
||||
public void Free() {
|
||||
if (browser != null) {
|
||||
// browser.setUrl("about:blank");
|
||||
browser.dispose();
|
||||
}
|
||||
Env_.GarbageCollect();
|
||||
browser = null;
|
||||
}
|
||||
}
|
||||
class Swt_app_browser_cmd_load implements SelectionListener {
|
||||
private Swt_app_browser_mgr mgr;
|
||||
public Swt_app_browser_cmd_load(Swt_app_browser_mgr mgr) {this.mgr = mgr;}
|
||||
public void widgetSelected(SelectionEvent event) {mgr.Load();}
|
||||
public void widgetDefaultSelected(SelectionEvent event) {}
|
||||
}
|
||||
class Swt_app_browser_cmd_free implements SelectionListener {
|
||||
private Swt_app_browser_mgr mgr;
|
||||
public Swt_app_browser_cmd_free(Swt_app_browser_mgr mgr) {this.mgr = mgr;}
|
||||
public void widgetSelected(SelectionEvent event) {mgr.Free();}
|
||||
public void widgetDefaultSelected(SelectionEvent event) {}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import org.eclipse.swt.events.MouseListener;
|
||||
import org.eclipse.swt.graphics.*;
|
||||
import org.eclipse.swt.layout.*;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
public class Swt_demo_main {
|
||||
public class Swt_app_main {
|
||||
public static void main(String[] args) {
|
||||
// Drag_drop();
|
||||
// List_fonts();
|
||||
@@ -16,6 +16,8 @@ You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package gplx.gfui;
|
||||
import java.security.acl.Owner;
|
||||
|
||||
import gplx.*;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.browser.*;
|
||||
@@ -40,14 +42,24 @@ class Swt_html implements Gxw_html, Swt_control, FocusListener {
|
||||
browser.addStatusTextListener(lnr_status);
|
||||
browser.addFocusListener(this);
|
||||
browser.addTitleListener(new Swt_html_lnr_title(this));
|
||||
// browser.addTraverseListener(new Swt_html_lnr_Traverse(this));
|
||||
// browser.addTraverseListener(new Swt_html_lnr_Traverse(this));
|
||||
}
|
||||
public Swt_kit Kit() {return kit;} private Swt_kit kit;
|
||||
@Override public Control Under_control() {return browser;} private Browser browser;
|
||||
@Override public Composite Under_composite() {return null;}
|
||||
@Override public Control Under_menu_control() {return browser;}
|
||||
public String Html_doc_html() {return Eval_script_as_str(kit.Html_cfg().Doc_html());}
|
||||
public void Html_doc_html_(String s) {browser.setText(s);} // DBG: Io_mgr._.SaveFilStr(Io_url_.new_fil_("C:\\temp.txt"), s)
|
||||
public void Html_doc_html_load_by_mem(String html) {
|
||||
html_doc_html_load_tid = Gxw_html_load_tid_.Tid_mem;
|
||||
browser.setText(html); // DBG: Io_mgr._.SaveFilStr(Io_url_.new_fil_("C:\\temp.txt"), s)
|
||||
}
|
||||
public void Html_doc_html_load_by_url(String path, String html) {
|
||||
html_doc_html_load_tid = Gxw_html_load_tid_.Tid_url;
|
||||
Io_mgr._.SaveFilStr(path, html);
|
||||
browser.setUrl(path);
|
||||
}
|
||||
public byte Html_doc_html_load_tid() {return html_doc_html_load_tid;} private byte html_doc_html_load_tid;
|
||||
public void Html_doc_html_load_tid_(byte v) {html_doc_html_load_tid = v;}
|
||||
public String Html_doc_selected_get_text_or_href() {return Eval_script_as_str(kit.Html_cfg().Doc_selected_get_text_or_href());}
|
||||
public String Html_doc_selected_get_href_or_text() {return Eval_script_as_str(kit.Html_cfg().Doc_selected_get_href_or_text());}
|
||||
public String Html_doc_selected_get_src_or_empty() {return Eval_script_as_str(kit.Html_cfg().Doc_selected_get_src_or_empty());}
|
||||
@@ -102,6 +114,13 @@ class Swt_html implements Gxw_html, Swt_control, FocusListener {
|
||||
return true;
|
||||
} private String prv_find_str = ""; private int prv_find_bgn;
|
||||
public void Html_invk_src_(GfoEvObj invk) {lnr_location.Host_set(invk); lnr_status.Host_set(invk);}
|
||||
public void Html_dispose() {
|
||||
browser.dispose();
|
||||
delete_owner.SubElems().DelOrFail(delete_cur); // NOTE: must delete cur from owner, else new tab will fail after closing one; DATE:2014-07-09
|
||||
Env_.GarbageCollect();
|
||||
}
|
||||
private GfuiElem delete_owner, delete_cur;
|
||||
public void Delete_elems_(GfuiElem delete_owner, GfuiElem delete_cur) {this.delete_owner = delete_owner; this.delete_cur = delete_cur;} // HACK: set owner / cur so delete can work;
|
||||
private String Escape_quotes(String v) {return String_.Replace(String_.Replace(v, "'", "\\'"), "\"", "\\\"");}
|
||||
@Override public GxwCore_base Core() {return core;} private GxwCore_base core;
|
||||
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
|
||||
@@ -208,6 +227,9 @@ class Swt_html_lnr_location implements LocationListener {
|
||||
void Pub_evt(LocationEvent arg, String evt) {
|
||||
String location = arg.location;
|
||||
if (String_.Eq(location, "about:blank")) return; // location changing event fires once when page is loaded; ignore
|
||||
if ( html_box.Html_doc_html_load_tid() == Gxw_html_load_tid_.Tid_url // navigating to file://page.html will fire location event; ignore if url mode
|
||||
&& String_.HasAtEnd(location, ".html"))
|
||||
return;
|
||||
try {
|
||||
GfoEvMgr_.PubObj(host, evt, "v", location);
|
||||
arg.doit = false; // cancel navigation event, else there will be an error when trying to go to invalid location
|
||||
|
||||
@@ -31,12 +31,13 @@ import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
class Swt_popup_grp implements Gfui_mnu_grp {
|
||||
public class Swt_popup_grp implements Gfui_mnu_grp {
|
||||
private Decorations owner_win; private Control owner_box; private boolean menu_is_bar = false;
|
||||
Swt_popup_grp(String root_key){this.root_key = root_key;}
|
||||
@Override public int Tid() {return Gfui_mnu_itm_.Tid_grp;}
|
||||
@Override public String Uid() {return uid;} private String uid = Gfui_mnu_itm_.Gen_uid();
|
||||
@Override public boolean Enabled() {return menu.getEnabled();} @Override public void Enabled_(boolean v) {menu.setEnabled(v);}
|
||||
@Override public boolean Disposed() {return menu.isDisposed();}
|
||||
@Override public String Text() {return menu_item.getText();} @Override public void Text_(String v) {menu_item.setText(v);}
|
||||
@Override public ImageAdp Img() {return img;} @Override public void Img_(ImageAdp v) {
|
||||
img = v;
|
||||
|
||||
Reference in New Issue
Block a user