1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00
This commit is contained in:
gnosygnu
2015-07-12 21:10:02 -04:00
commit 794b5a232f
3099 changed files with 238212 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
/*
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);
try {
System.setProperty("org.eclipse.swt.browser.XULRunnerPath", "E:\\موسوعات\\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();
} catch (SWTError e) {
Tfds.Write("a");
}
}
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("hello");
}
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) {}
}

View File

@@ -0,0 +1,200 @@
/*
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 org.eclipse.swt.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class Swt_app_main {
public static void main(String[] args) {
// Drag_drop();
// List_fonts();
// keystrokes(args);
Permission_denied();
}
static void Drag_drop() {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
final CTabFolder folder = new CTabFolder(shell, SWT.BORDER);
folder.setLayoutData(new GridData(GridData.FILL_BOTH));
for (int i = 0; i < 10; i++) {
CTabItem item = new CTabItem(folder, SWT.NONE);
item.setText("item "+i);
Text text = new Text(folder, SWT.BORDER | SWT.MULTI | SWT.VERTICAL);
text.setText("Text control for "+i);
item.setControl(text);
if (i == 9) {
item.setShowClose(false);
item.setText("+");
// item.setImage(new Image(Display.getDefault(), "J:\\gplx\\xowa\\user\\anonymous\\app\\img\\edit\\format-bold-A.png"));
}
}
ToolBar t = new ToolBar( folder, SWT.FLAT );
ToolItem i = new ToolItem( t, SWT.PUSH );
i.setText( "add" );
folder.setTopRight( t, SWT.RIGHT );
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
static void keystrokes(String[] args)
{
Display display = new Display ();
final Shell shell = new Shell (display);
// display.addFilter(SWT.KeyDown, new Listener() {
//
// public void handleEvent(Event e) {
// if(((e.stateMask & SWT.CTRL) == SWT.CTRL) && (e.keyCode == 'f'))
// {
// System.out.println("From Display I am the Key down !!" + e.keyCode);
// }
// }
// });
shell.addKeyListener(new KeyListener() {
public void keyReleased(KeyEvent e) {
// if(((e.stateMask & SWT.CTRL) == SWT.CTRL) && (e.keyCode == 'f'))
// {
// shell.setBackground(orig);
// System.out.println("Key up !!");
// }
System.out.println(e.stateMask + " " + e.keyCode);
}
public void keyPressed(KeyEvent e) {
// System.out.println(e.stateMask + " " + e.keyCode);
}
});
shell.addMouseListener(new MouseListener() {
@Override
public void mouseUp(MouseEvent arg0) {
// TODO Auto-generated method stub
System.out.println(arg0.button);
}
@Override
public void mouseDown(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseDoubleClick(MouseEvent arg0) {
// TODO Auto-generated method stub
}
});
shell.setSize (200, 200);
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
static void List_fonts() {
java.awt.GraphicsEnvironment e = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
java.awt.Font[] fonts = e.getAllFonts(); // Get the fonts
for (java.awt.Font f : fonts) {
System.out.println(f.getFontName());
}
}
static void Permission_denied() {
String html
= "<html>\n"
+ "<head>\n"
+ "<script>\n"
+ " function permissionDeniedExample() {\n"
+ " var sel = window.getSelection();\n"
+ " alert('calling sel.rangeCount');\n"
+ " alert('sel.rangeCount = ' + sel.rangeCount);\n"
+ " }\n"
+ "</script>\n"
+ "</head>\n"
+ "<body>\n"
+ " <a href='#direct_call_fails'/>click to call permissionDeniedExample -> will throw error and not show sel.rangeCount</a><br/>\n"
+ " <a href='#wrapped_call_works'/>click to call permissionDeniedExample inside a setTimeout -> will show sel.rangeCount</a><br/>\n"
+ "</body>\n"
+ "</html>\n"
;
System.setProperty
( "org.eclipse.swt.browser.XULRunnerPath"
// ADJUST THIS PATH AS NECESSARY ON YOUR MACHINE
, "C:\\xowa\\bin\\windows\\xulrunner"
);
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
final Browser browser;
try {
browser = new Browser(shell, SWT.MOZILLA); // changed from none
browser.addLocationListener(new LocationListener() {
@Override
public void changing(LocationEvent arg0) {
if (arg0.location.equals("about:blank")) return;
arg0.doit = false;
}
@Override
public void changed(LocationEvent arg0) {
String location = arg0.location;
if (location.equals("about:blank")) return;
// build code
String code = "alert('unknown_link:" + location + "')";
if (location.contains("direct_call_fails"))
code = "permissionDeniedExample();";
else if (location.contains("wrapped_call_works"))
code = "setTimeout(function(){permissionDeniedExample();}, 1);";
// evaluate code
try {
browser.evaluate(code);
} catch (Exception e) {
System.out.println(e);
}
arg0.doit = false;
}
});
} catch (SWTError e) {
System.out.println("Could not instantiate Browser: " + e.getMessage());
display.dispose();
return;
}
browser.setText(html);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}

View File

@@ -0,0 +1,100 @@
/*
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.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
class Swt_btn implements GxwElem, Swt_control {
private Button btn;
public Swt_btn(Swt_control owner, KeyValHash ctorArgs) {
btn = new Button(owner.Under_composite(), SWT.FLAT | SWT.PUSH);
core = new Swt_core_cmds(btn);
btn.addKeyListener(new Swt_lnr_key(this));
btn.addMouseListener(new Swt_lnr_mouse(this));
}
@Override public Control Under_control() {return btn;}
@Override public Control Under_menu_control() {return btn;}
@Override public String TextVal() {return btn.getText();} @Override public void TextVal_set(String v) {btn.setText(v);}
@Override public GxwCore_base Core() {return core;} GxwCore_base core;
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
@Override public Composite Under_composite() {return null;}
@Override public void EnableDoubleBuffering() {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return null;}
}
class Swt_btn_no_border implements GxwElem, Swt_control {
private ImageAdp btn_img; private Composite box_grp; private Label box_btn;
public Swt_btn_no_border(Swt_control owner_control, KeyValHash ctorArgs) {
Composite owner = owner_control.Under_composite();
Make_btn_no_border(owner.getDisplay(), owner.getShell(), owner);
this.core = new Swt_core_cmds(box_btn);
box_btn.addKeyListener(new Swt_lnr_key(this));
box_btn.addMouseListener(new Swt_lnr_mouse(this));
}
@Override public Control Under_control() {return box_btn;}
@Override public Control Under_menu_control() {return box_btn;}
@Override public String TextVal() {return box_btn.getText();} @Override public void TextVal_set(String v) {box_btn.setText(v);}
@Override public GxwCore_base Core() {return core;} private final Swt_core_cmds core;
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} private GxwCbkHost host;
@Override public Composite Under_composite() {return null;}
@Override public void EnableDoubleBuffering() {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, GfuiBtn.Invk_btn_img)) return btn_img;
else if (ctx.Match(k, GfuiBtn.Invk_btn_img_)) Btn_img_((ImageAdp)m.CastObj("v"));
return null;
}
void Btn_img_(ImageAdp v) {
if (box_btn == null || v == null) return;
SizeAdp size = core.Size();
int dif = 6;
box_btn.setImage((Image)v.Resize(size.Width() - dif, size.Height() - dif).Under());
}
void Make_btn_no_border(Display display, Shell shell, Control owner) {
box_grp = new Composite(shell, SWT.FLAT);
box_btn = new Label(shell, SWT.FLAT);
box_btn.setSize(25, 25);
box_btn.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
box_btn.addFocusListener(new Swt_clabel_lnr_focus(box_grp));
}
}
class Swt_clabel_lnr_focus implements FocusListener {
public Swt_clabel_lnr_focus(Control v) {this.surrogate = v;} Control surrogate;
@Override public void focusGained(org.eclipse.swt.events.FocusEvent e) {
surrogate.forceFocus();
}
@Override public void focusLost(org.eclipse.swt.events.FocusEvent arg0) {}
}

View File

@@ -0,0 +1,58 @@
/*
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.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
class Swt_clipboard implements Gfui_clipboard {
public Swt_clipboard(Display display) {
this.display = display;
clipboard = new Clipboard(display);
} Display display; Clipboard clipboard;
public void Copy(String v) {
if (String_.Len_eq_0(v)) return;
TextTransfer textTransfer = TextTransfer.getInstance();
clipboard.setContents(new Object[]{v}, new Transfer[]{textTransfer});
}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (ctx.Match(k, Gfui_clipboard_.Invk_copy)) Send_key(IptKey_.Ctrl, 'C');
else if (ctx.Match(k, Gfui_clipboard_.Invk_select_all)) Send_key(IptKey_.Ctrl, 'A');
else return GfoInvkAble_.Rv_unhandled;
return this;
}
@Override public void Rls() {clipboard.dispose();}
int Xto_keycode(IptKey modifier) {
switch (modifier.Val()) {
case IptKey_.KeyCode_Ctrl: return SWT.CTRL;
case IptKey_.KeyCode_Alt: return SWT.ALT;
case IptKey_.KeyCode_Shift: return SWT.SHIFT;
default: return SWT.NONE;
}
}
public void Send_key(IptKey mod, char key_press_char) {
Event event = new Event();
int modifier_key_code = Xto_keycode(mod);
event.keyCode = modifier_key_code; event.type = SWT.KeyDown; display.post(event);
event.keyCode = 0; event.character = key_press_char; display.post(event);
event.type = SWT.KeyUp; display.post(event);
event.keyCode = modifier_key_code; event.character = 0; display.post(event);
}
}

View File

@@ -0,0 +1,44 @@
/*
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 org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
interface Swt_control extends GxwElem {
Control Under_control();
Composite Under_composite();
Control Under_menu_control();
}
class Swt_control_ {
public static void X_set(Control c, int v) {Point point = c.getLocation(); c.setLocation(v, point.y);}
public static void Y_set(Control c, int v) {Point point = c.getLocation(); c.setLocation(point.x, v);}
public static void W_set(Control c, int v) {Point point = c.getSize(); c.setSize(v, point.y);}
public static void H_set(Control c, int v) {Point point = c.getSize(); c.setSize(point.x, v);}
public static void Pos_set(Control c, PointAdp v) {c.setLocation(v.X(), v.Y());}
public static void Pos_set(Control c, int x, int y) {c.setLocation(x, y);}
public static void Size_set(Control c, SizeAdp v) {c.setSize(v.Width(), v.Height());}
public static void Size_set(Control c, int w, int h) {c.setSize(w, h);}
public static void Rect_set(Control c, RectAdp v) {c.setBounds(Xto_rectangle(v));}
public static void Rect_set(Control c, int x, int y, int w, int h) {c.setBounds(Xto_rectangle(x, y, w, h));}
public static void Rect_add(Control c, RectAdp v, int x, int y, int w, int h) {c.setBounds(Xto_rectangle(v.X() + x, v.Y() + y, v.Width() + w, v.Height()+ h));}
public static Rectangle Xto_rectangle(int x, int y, int w, int h) {return new Rectangle(x, y, w, h);}
public static Rectangle Xto_rectangle(RectAdp v) {return new Rectangle(v.X(), v.Y(), v.Width(), v.Height());}
public static Swt_control cast_or_fail(GfuiElem elem) {return (Swt_control)elem.UnderElem();}
}

View File

@@ -0,0 +1,243 @@
/*
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.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
class Swt_core_cmds extends GxwCore_base {
Control control; private boolean compositeAble = false;
public Swt_core_cmds(Control control) {
this.compositeAble = control instanceof Composite;
this.control = control;
}
@Override public int Width() {return control.getSize().x;} @Override public void Width_set(int v) {if (Cfg_resize_disabled) return; control.setSize(v, this.Height());}
@Override public int Height() {return control.getSize().y;} @Override public void Height_set(int v) {if (Cfg_resize_disabled) return; control.setSize(this.Width(), v);}
@Override public int X() {return control.getLocation().x;} @Override public void X_set(int v) {control.setLocation(v, this.Y());}
@Override public int Y() {return control.getLocation().y;} @Override public void Y_set(int v) {control.setLocation(this.X(), v);}
@Override public SizeAdp Size() {return SizeAdp_.new_(this.Width(), this.Height());} @Override public void Size_set(SizeAdp v) {if (Cfg_resize_disabled) return; control.setSize(v.Width(), v.Height());}
@Override public PointAdp Pos() {return PointAdp_.new_(this.X(), this.Y());} @Override public void Pos_set(PointAdp v) {control.setLocation(v.X(), v.Y());}
@Override public RectAdp Rect() {return RectAdp_.new_(this.X(), this.Y(), this.Width(), this.Height());}
@Override public void Rect_set(RectAdp v) {
if (Cfg_resize_disabled)
control.setLocation(v.X(), v.Y());
else
control.setBounds(v.X(), v.Y(), v.Width(), v.Height());
}
@Override public boolean Visible() {return control.isVisible();}
@Override public void Visible_set(boolean v) {control.setVisible(v);}
@Override public ColorAdp BackColor() {return XtoColorAdp(control.getBackground());} @Override public void BackColor_set(ColorAdp v) {control.setBackground(XtoColor(v));}
@Override public ColorAdp ForeColor() {return XtoColorAdp(control.getForeground());} @Override public void ForeColor_set(ColorAdp v) {control.setForeground(XtoColor(v));}
public boolean Cfg_resize_disabled = false;
ColorAdp XtoColorAdp(Color v) {return ColorAdp_.new_(0, v.getRed(), v.getGreen(), v.getBlue());}
Color XtoColor(ColorAdp v) {return new Color(control.getDisplay(), v.Red(), v.Green(), v.Blue());}
@Override public FontAdp TextFont() {
if (prv_font != null) return prv_font;
prv_font = Swt_kit.Control_font_get(control.getFont(), this);
return prv_font;
} FontAdp prv_font;
@Override public void TextFont_set(FontAdp v) {
Swt_kit.Control_font_set(v, this, control);
prv_font = v;
}
@Override public String TipText() {return control.getToolTipText();} @Override public void TipText_set(String v) {control.setToolTipText(v);}
@Override public void Controls_add(GxwElem sub) {
if (!compositeAble) throw Exc_.new_("cannot add sub to control");
Composite owner_as_composite = (Composite)control;
Swt_control sub_as_WxSwt = (Swt_control)sub;
Control sub_as_swt = sub_as_WxSwt.Under_control();
sub_as_swt.setParent(owner_as_composite);
}
@Override public void Controls_del(GxwElem sub) {
if (!compositeAble) throw Exc_.new_("cannot add sub to control");
Swt_control sub_as_WxSwt = (Swt_control)sub;
Control sub_as_swt = sub_as_WxSwt.Under_control();
sub_as_swt.dispose(); // SWT_NOTE: no way to officially remove sub from control; can only dispose
}
@Override public boolean Focus_has() {return control.isFocusControl();}
@Override public boolean Focus_able() {return focus_able;} boolean focus_able;
@Override public void Focus_able_(boolean v) {focus_able = v;}
@Override public int Focus_index() {return focusIndex;} @Override public void Focus_index_set(int v) {focusIndex = v;} int focusIndex;
@Override public void Focus() {
if (Focus_able())
control.forceFocus();
}
@Override public void Select_exec() {
control.setFocus();
}
@Override public void Zorder_front() {
// Canvas c; c.moveAbove(arg0);
}
@Override public void Zorder_back() {
// Canvas c; c.moveBelow(arg0);
}
@Override public void Invalidate() {control.redraw(); control.update();}
@Override public void Dispose() {control.dispose();}
}
class Swt_core_cmds_dual extends GxwCore_base {
public Swt_core_cmds_dual(Composite outer, Control inner, int inner_adj_x, int inner_adj_y, int inner_adj_w, int inner_adj_h) {
this.outer = outer; this.inner = inner;
outer_is_composite = outer instanceof Composite;
this.inner_adj_x = inner_adj_x; this.inner_adj_y = inner_adj_y; this.inner_adj_w = inner_adj_w; this.inner_adj_h = inner_adj_h;
} Control outer, inner; boolean outer_is_composite = false; int inner_adj_x, inner_adj_y, inner_adj_w, inner_adj_h;
@Override public int X() {return outer.getLocation().x;} @Override public void X_set(int v) {Swt_control_.X_set(outer, v);}
@Override public int Y() {return outer.getLocation().y;} @Override public void Y_set(int v) {Swt_control_.Y_set(outer, v);}
@Override public int Width() {return outer.getSize().x;} @Override public void Width_set(int v) {Swt_control_.W_set(outer, v); Swt_control_.W_set(outer, v + inner_adj_w);}
@Override public int Height() {return outer.getSize().y;} @Override public void Height_set(int v) {Swt_control_.H_set(outer, v); Swt_control_.H_set(outer, v + inner_adj_h);}
@Override public SizeAdp Size() {return SizeAdp_.new_(this.Width(), this.Height());} @Override public void Size_set(SizeAdp v) {Swt_control_.Size_set(outer, v); Swt_control_.Size_set(inner, v.Width() + inner_adj_w, v.Height() + inner_adj_h);}
@Override public PointAdp Pos() {return PointAdp_.new_(this.X(), this.Y());} @Override public void Pos_set(PointAdp v) {Swt_control_.Pos_set(outer, v);}
@Override public RectAdp Rect() {return RectAdp_.new_(this.X(), this.Y(), this.Width(), this.Height());} @Override public void Rect_set(RectAdp v) {Swt_control_.Rect_set(outer, v); Swt_control_.Size_set(inner, v.Width() + inner_adj_w, v.Height() + inner_adj_h);}
@Override public boolean Visible() {return outer.isVisible();}
@Override public void Visible_set(boolean v) {outer.setVisible(v);}
@Override public ColorAdp BackColor() {return XtoColorAdp(inner.getBackground());} @Override public void BackColor_set(ColorAdp v) {inner.setBackground(XtoColor(v));}
@Override public ColorAdp ForeColor() {return XtoColorAdp(inner.getForeground());} @Override public void ForeColor_set(ColorAdp v) {inner.setForeground(XtoColor(v));}
ColorAdp XtoColorAdp(Color v) {return ColorAdp_.new_(0, v.getRed(), v.getGreen(), v.getBlue());}
Color XtoColor(ColorAdp v) {return new Color(outer.getDisplay(), v.Red(), v.Green(), v.Blue());}
@Override public FontAdp TextFont() {
if (prv_font != null) return prv_font;
prv_font = Swt_kit.Control_font_get(inner.getFont(), this);
return prv_font;
} FontAdp prv_font;
@Override public void TextFont_set(FontAdp v) {
Swt_kit.Control_font_set(v, this, inner);
prv_font = v;
}
@Override public String TipText() {return inner.getToolTipText();} @Override public void TipText_set(String v) {inner.setToolTipText(v);}
@Override public void Controls_add(GxwElem sub) {
if (!outer_is_composite) throw Exc_.new_("cannot add sub to outer");
Composite owner_as_composite = (Composite)outer;
Swt_control sub_as_WxSwt = (Swt_control)sub;
Control sub_as_swt = sub_as_WxSwt.Under_control();
sub_as_swt.setParent(owner_as_composite);
}
@Override public void Controls_del(GxwElem sub) {
if (!outer_is_composite) throw Exc_.new_("cannot add sub to outer");
Swt_control sub_as_WxSwt = (Swt_control)sub;
Control sub_as_swt = sub_as_WxSwt.Under_control();
sub_as_swt.dispose(); // SWT_NOTE: no way to officially remove sub from outer; can only dispose
}
@Override public boolean Focus_has() {return inner.isFocusControl();}
@Override public boolean Focus_able() {return focus_able;} boolean focus_able;
@Override public void Focus_able_(boolean v) {focus_able = v;}
@Override public int Focus_index() {return focusIndex;} @Override public void Focus_index_set(int v) {focusIndex = v;} int focusIndex;
@Override public void Focus() {
if (Focus_able())
inner.forceFocus();
}
@Override public void Select_exec() {
inner.setFocus();
}
@Override public void Zorder_front() {}
@Override public void Zorder_back() {}
@Override public void Invalidate() {outer.update(); inner.update();}
@Override public void Dispose() {outer.dispose(); inner.dispose();}
}
interface Swt_core_cmds_frames_itm {
Control Itm();
void Rect_set(int w, int h);
}
class Swt_core_cmds_frames_itm_manual implements Swt_core_cmds_frames_itm {
public Swt_core_cmds_frames_itm_manual(Control control, int x, int y, int w, int h) {
this.control = control; this.x = x; this.y = y; this.w = w; this.h = h;
} Control control; int x, y, w, h;
public Control Itm() {return control;}
public void Rect_set(int new_w, int new_h) {
Swt_control_.Rect_set(control, x, y, new_w + w, new_h + h);
}
}
class Swt_core_cmds_frames_itm_center_v implements Swt_core_cmds_frames_itm {
public Swt_core_cmds_frames_itm_center_v(Control control, Swt_text_w_border margin_owner) {this.control = control; this.margin_owner = margin_owner;} Control control; Swt_text_w_border margin_owner;
public Control Itm() {return control;}
public void Rect_set(int new_w, int new_h) {
int margin_t = margin_owner.margins_t;
int margin_b = margin_owner.margins_b;
Swt_control_.Rect_set(control, 0, margin_t, new_w, new_h - (margin_t + margin_b));
}
}
class Swt_core_cmds_frames extends GxwCore_base {
public Swt_core_cmds_frames(Composite outer, Swt_core_cmds_frames_itm[] frames) {
this.outer = outer; this.frames = frames;
frames_len = frames.length;
this.inner = frames[frames_len - 1].Itm();
} Composite outer; Control inner; Swt_core_cmds_frames_itm[] frames; int frames_len;
void Frames_w_set(int v) {
for (int i = 0; i < frames_len; i++)
frames[i].Rect_set(v, this.Height());
}
void Frames_h_set(int v) {
for (int i = 0; i < frames_len; i++)
frames[i].Rect_set(this.Width(), v);
}
void Frames_size_set(SizeAdp v) {
for (int i = 0; i < frames_len; i++)
frames[i].Rect_set(v.Width(), v.Height());
}
@Override public int X() {return outer.getLocation().x;} @Override public void X_set(int v) {Swt_control_.X_set(outer, v);}
@Override public int Y() {return outer.getLocation().y;} @Override public void Y_set(int v) {Swt_control_.Y_set(outer, v);}
@Override public int Width() {return outer.getSize().x;} @Override public void Width_set(int v) {Swt_control_.W_set(outer, v); Frames_w_set(v);}
@Override public int Height() {return outer.getSize().y;} @Override public void Height_set(int v) {Swt_control_.H_set(outer, v); Frames_h_set(v);}
@Override public SizeAdp Size() {return SizeAdp_.new_(this.Width(), this.Height());} @Override public void Size_set(SizeAdp v) {Swt_control_.Size_set(outer, v); Frames_size_set(v);}
@Override public PointAdp Pos() {return PointAdp_.new_(this.X(), this.Y());} @Override public void Pos_set(PointAdp v) {Swt_control_.Pos_set(outer, v);}
@Override public RectAdp Rect() {return RectAdp_.new_(this.X(), this.Y(), this.Width(), this.Height());} @Override public void Rect_set(RectAdp v) {Swt_control_.Rect_set(outer, v); Frames_size_set(v.Size());}
@Override public boolean Visible() {return outer.isVisible();}
@Override public void Visible_set(boolean v) {outer.setVisible(v);}
@Override public ColorAdp BackColor() {return XtoColorAdp(inner.getBackground());}
@Override public void BackColor_set(ColorAdp v) {
Color color = XtoColor(v);
// outer.setBackground(color);
for (int i = 0; i < frames_len; i++)
frames[i].Itm().setBackground(color);
}
@Override public ColorAdp ForeColor() {return XtoColorAdp(inner.getForeground());} @Override public void ForeColor_set(ColorAdp v) {inner.setForeground(XtoColor(v));}
ColorAdp XtoColorAdp(Color v) {return ColorAdp_.new_(0, v.getRed(), v.getGreen(), v.getBlue());}
Color XtoColor(ColorAdp v) {return new Color(outer.getDisplay(), v.Red(), v.Green(), v.Blue());}
@Override public FontAdp TextFont() {
if (prv_font != null) return prv_font;
prv_font = Swt_kit.Control_font_get(inner.getFont(), this);
return prv_font;
} FontAdp prv_font;
@Override public void TextFont_set(FontAdp v) {
Swt_kit.Control_font_set(v, this, inner);
prv_font = v;
}
@Override public String TipText() {return inner.getToolTipText();} @Override public void TipText_set(String v) {inner.setToolTipText(v);}
@Override public void Controls_add(GxwElem sub) {throw Exc_.new_unimplemented();}
@Override public void Controls_del(GxwElem sub) {}
@Override public boolean Focus_has() {return inner.isFocusControl();}
@Override public boolean Focus_able() {return focus_able;} boolean focus_able;
@Override public void Focus_able_(boolean v) {focus_able = v;}
@Override public int Focus_index() {return focusIndex;} @Override public void Focus_index_set(int v) {focusIndex = v;} int focusIndex;
@Override public void Focus() {
if (Focus_able())
inner.forceFocus();
}
@Override public void Select_exec() {
inner.setFocus();
}
@Override public void Zorder_front() {}
@Override public void Zorder_back() {}
@Override public void Invalidate() {
inner.redraw();
inner.update();
}
@Override public void Dispose() {outer.dispose(); inner.dispose();}
}

View File

@@ -0,0 +1,150 @@
/*
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.Byte_ascii;
import gplx.Enm_;
import gplx.Err_;
import gplx.GfoEvMgr_;
import gplx.GfoInvkAble_;
import gplx.GfoMsg_;
import gplx.GfsCtx;
import gplx.String_;
import gplx.Tfds;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ToolItem;
class Swt_lnr_show implements Listener {
boolean shown = false;
@Override public void handleEvent(Event ev) {
if (shown) return;
win.Opened();
}
public Swt_lnr_show(Swt_win win) {this.win = win;} Swt_win win;
}
class Swt_lnr_resize implements Listener {
@Override public void handleEvent(Event ev) {
// win.Host().SizeChangedCbk();
GfoEvMgr_.Pub((GfuiWin)win.Host(), Gfui_html.Evt_win_resized);
}
public Swt_lnr_resize(Swt_win win) {this.win = win;} Swt_win win;
}
class Swt_lnr_traverse implements Listener {
@Override public void handleEvent(Event e) {
if (e.detail == SWT.TRAVERSE_ESCAPE)
e.doit = false;
}
}
class Swt_lnr_key implements KeyListener {
public Swt_lnr_key(GxwElem elem) {this.elem = elem;} GxwElem elem;
// static int counter = 0;
@Override public void keyPressed(KeyEvent ev) {
IptEvtDataKey ipt_data = XtoKeyData(ev);
if (!elem.Host().KeyDownCbk(ipt_data) || ipt_data.Handled())
ev.doit = false;
}
@Override public void keyReleased(KeyEvent ev) {
IptEvtDataKey ipt_data = XtoKeyData(ev);
if (!elem.Host().KeyUpCbk(ipt_data) || ipt_data.Handled())
ev.doit = false;
}
IptEvtDataKey XtoKeyData(KeyEvent ev) {
int val = ev.keyCode;
switch (val) {
case Byte_ascii.Cr: val = 10; break; // enter key is 13 whereas .net/swing is 10
case Byte_ascii.Ltr_a: case Byte_ascii.Ltr_b: case Byte_ascii.Ltr_c: case Byte_ascii.Ltr_d: case Byte_ascii.Ltr_e:
case Byte_ascii.Ltr_f: case Byte_ascii.Ltr_g: case Byte_ascii.Ltr_h: case Byte_ascii.Ltr_i: case Byte_ascii.Ltr_j:
case Byte_ascii.Ltr_k: case Byte_ascii.Ltr_l: case Byte_ascii.Ltr_m: case Byte_ascii.Ltr_n: case Byte_ascii.Ltr_o:
case Byte_ascii.Ltr_p: case Byte_ascii.Ltr_q: case Byte_ascii.Ltr_r: case Byte_ascii.Ltr_s: case Byte_ascii.Ltr_t:
case Byte_ascii.Ltr_u: case Byte_ascii.Ltr_v: case Byte_ascii.Ltr_w: case Byte_ascii.Ltr_x: case Byte_ascii.Ltr_y: case Byte_ascii.Ltr_z:
val -= 32; // lowercase keys are transmitted as ascii value, instead of key value; EX: "a" is 97 instead of 65
break;
case 16777217: val = IptKey_.Up.Val(); break;
case 16777218: val = IptKey_.Down.Val(); break;
case 16777219: val = IptKey_.Left.Val(); break;
case 16777220: val = IptKey_.Right.Val(); break;
case 16777221: val = IptKey_.PageUp.Val(); break;
case 16777222: val = IptKey_.PageDown.Val(); break;
case 16777223: val = IptKey_.Home.Val(); break;
case 16777224: val = IptKey_.End.Val(); break;
case 16777226: val = IptKey_.F1.Val(); break;
case 16777227: val = IptKey_.F2.Val(); break;
case 16777228: val = IptKey_.F3.Val(); break;
case 16777229: val = IptKey_.F4.Val(); break;
case 16777230: val = IptKey_.F5.Val(); break;
case 16777231: val = IptKey_.F6.Val(); break;
case 16777232: val = IptKey_.F7.Val(); break;
case 16777233: val = IptKey_.F8.Val(); break;
case 16777234: val = IptKey_.F9.Val(); break;
case 16777235: val = IptKey_.F10.Val(); break;
case 16777236: val = IptKey_.F11.Val(); break;
case 16777237: val = IptKey_.F12.Val(); break;
case 16777259: val = IptKey_.Equal.Val(); break;
case 16777261: val = IptKey_.Minus.Val(); break;
case 16777300: val = IptKey_.ScrollLock.Val(); break;
case 16777301: val = IptKey_.Pause.Val(); break;
case 327680: val = IptKey_.Insert.Val(); break;
}
if (Has_ctrl(ev.stateMask)) val |= IptKey_.KeyCode_Ctrl;
if (Enm_.HasInt(ev.stateMask, IptKey_.KeyCode_Shift)) val |= IptKey_.KeyCode_Alt;
if (Enm_.HasInt(ev.stateMask, IptKey_.KeyCode_Ctrl)) val |= IptKey_.KeyCode_Shift;
// Tfds.Write(String_.Format("val={4} keyCode={0} stateMask={1} keyLocation={2} character={3}", ev.keyCode, ev.stateMask, ev.keyLocation, ev.character, val));
return IptEvtDataKey.int_(val);
}
public static boolean Has_ctrl(int val) {return Enm_.HasInt(val, IptKey_.KeyCode_Alt);} // NOTE:SWT's ctrl constant is different from SWING's
}
class Swt_lnr_mouse implements MouseListener {
public Swt_lnr_mouse(GxwElem elem) {this.elem = elem;} GxwElem elem;
@Override public void mouseDown(MouseEvent ev) {elem.Host().MouseDownCbk(XtoMouseData(ev));}
@Override public void mouseUp(MouseEvent ev) {elem.Host().MouseUpCbk(XtoMouseData(ev));}
@Override public void mouseDoubleClick(MouseEvent ev) {}
IptEvtDataMouse XtoMouseData(MouseEvent ev) {
IptMouseBtn btn = null;
switch (ev.button) {
case 1: btn = IptMouseBtn_.Left; break;
case 2: btn = IptMouseBtn_.Middle; break;
case 3: btn = IptMouseBtn_.Right; break;
case 4: btn = IptMouseBtn_.X1; break;
case 5: btn = IptMouseBtn_.X2; break;
}
return IptEvtDataMouse.new_(btn, IptMouseWheel_.None, ev.x, ev.y);
}
// private static int X_to_swing(int v) {
// switch (v) {
// case gplx.gfui.IptMouseBtn_.Tid_left : return java.awt.event.InputEvent.BUTTON1_MASK;
// case gplx.gfui.IptMouseBtn_.Tid_middle : return java.awt.event.InputEvent.BUTTON2_MASK;
// case gplx.gfui.IptMouseBtn_.Tid_right : return java.awt.event.InputEvent.BUTTON3_MASK;
// default : throw Err_.unhandled(v);
// }
// }
}
class Swt_lnr_toolitem implements Listener {
public Swt_lnr_toolitem(ToolItem itm, GxwElem elem) {this.itm = itm; this.elem = elem;} ToolItem itm; GxwElem elem;
@Override public void handleEvent(Event arg0) {
Rectangle rect = itm.getBounds();
elem.Host().MouseUpCbk(IptEvtDataMouse.new_(IptMouseBtn_.Left, IptMouseWheel_.None, rect.x, rect.y));
}
}

View File

@@ -0,0 +1,96 @@
/*
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.widgets.*;
import org.eclipse.swt.SWT;
class Swt_dlg_file implements Gfui_dlg_file {
private FileDialog under;
public Swt_dlg_file(byte type, Shell shell) {
int file_dialog_type
= type == Gfui_kit_.File_dlg_type_save
? SWT.SAVE
: SWT.OPEN
;
under = new FileDialog(shell, file_dialog_type);
}
public Gfui_dlg_file Init_msg_(String v) {under.setText(v); return this;}
public Gfui_dlg_file Init_file_(String v) {under.setFileName(v); return this;}
public Gfui_dlg_file Init_dir_(Io_url v) {under.setFilterPath(v.Xto_api()); return this;}
public Gfui_dlg_file Init_exts_(String... v) {under.setFilterExtensions(v); return this;}
public String Ask() {return under.open();}
}
class Swt_dlg_msg implements Gfui_dlg_msg, Runnable {
public Swt_dlg_msg(Shell shell) {this.shell = shell;} Shell shell;
public Gfui_dlg_msg Init_msg_(String v) {msg = v; return this;} String msg;
public Gfui_dlg_msg Init_ico_(int v) {ico = Xto_swt_ico(v); return this;} int ico = -1;
public Gfui_dlg_msg Init_btns_(int... ary) {
int ary_len = ary.length;
btns = -1;
for (int i = 0; i < ary_len; i++) {
int swt_btn = Xto_swt_btn(ary[i]);
if (btns == -1) btns = swt_btn;
else btns |= swt_btn;
}
return this;
} int btns = -1;
public int Ask_rslt;
@Override public void run() {
Ask_rslt = this.Ask();
}
public boolean Ask(int expd) {return Ask() == expd;}
public int Ask() {
int ctor_ico = ico == -1 ? SWT.ICON_INFORMATION : ico;
int ctor_btn = btns == -1 ? SWT.OK : btns;
MessageBox mb = new MessageBox(shell, ctor_ico | ctor_btn);
if (msg != null) mb.setMessage(msg);
int rv = mb.open();
return Xto_gfui_btn(rv);
}
int Xto_swt_ico(int v) {
switch (v) {
case Gfui_dlg_msg_.Ico_error: return SWT.ICON_ERROR;
case Gfui_dlg_msg_.Ico_information: return SWT.ICON_INFORMATION;
case Gfui_dlg_msg_.Ico_question: return SWT.ICON_QUESTION;
case Gfui_dlg_msg_.Ico_warning: return SWT.ICON_WARNING;
case Gfui_dlg_msg_.Ico_working: return SWT.ICON_WORKING;
default: throw Exc_.new_unhandled(v);
}
}
int Xto_swt_btn(int v) {
switch (v) {
case Gfui_dlg_msg_.Btn_ok: return SWT.OK;
case Gfui_dlg_msg_.Btn_yes: return SWT.YES;
case Gfui_dlg_msg_.Btn_no: return SWT.NO;
case Gfui_dlg_msg_.Btn_ignore: return SWT.IGNORE;
case Gfui_dlg_msg_.Btn_abort: return SWT.ABORT;
case Gfui_dlg_msg_.Btn_cancel: return SWT.CANCEL;
default: throw Exc_.new_unhandled(v);
}
}
int Xto_gfui_btn(int v) {
switch (v) {
case SWT.OK: return Gfui_dlg_msg_.Btn_ok;
case SWT.YES: return Gfui_dlg_msg_.Btn_yes;
case SWT.NO: return Gfui_dlg_msg_.Btn_no;
case SWT.IGNORE: return Gfui_dlg_msg_.Btn_ignore;
case SWT.ABORT: return Gfui_dlg_msg_.Btn_abort;
case SWT.CANCEL: return Gfui_dlg_msg_.Btn_cancel;
default: throw Exc_.new_unhandled(v);
}
}
}

View File

@@ -0,0 +1,271 @@
/*
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.core.primitives.*;
import gplx.core.threads.Thread_adp_;
import java.security.acl.Owner;
import gplx.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import java.security.acl.Owner;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
class Swt_html implements Gxw_html, Swt_control, FocusListener {
private Swt_html_lnr_location lnr_location; private Swt_html_lnr_status lnr_status;
public Swt_html(Swt_kit kit, Swt_control owner_control, KeyValHash ctorArgs) {
this.kit = kit;
lnr_location = new Swt_html_lnr_location(this);
lnr_status = new Swt_html_lnr_status(this);
Object browser_tid_obj = ctorArgs.FetchValOr(Swt_kit.Cfg_Html_BrowserType, null);
this.browser_tid = browser_tid_obj == null ? Browser_tid_none : Int_.cast_(browser_tid_obj);
browser = new Browser(owner_control.Under_composite(), browser_tid);
core = new Swt_core_cmds_html(this, browser);
browser.addKeyListener(new Swt_lnr_key(this));
browser.addMouseListener(new Swt_html_lnr_mouse(this, browser, kit));
browser.addLocationListener(lnr_location);
browser.addProgressListener(new Swt_html_lnr_progress(this));
browser.addStatusTextListener(lnr_status);
browser.addFocusListener(this);
browser.addTitleListener(new Swt_html_lnr_title(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 int Browser_tid() {return browser_tid;} private final int browser_tid;
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.I.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.I.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 void Html_js_enabled_(boolean v) {browser.setJavascriptEnabled(v);}
public void Html_js_cbks_add(String func_name, GfoInvkAble invk) {new Swt_html_func(browser, func_name, invk);}
public String Html_js_eval_script(String script) {return Eval_script_as_str(script);}
public boolean Html_js_eval_proc_as_bool(String proc, Object... args) {return Bool_.cast_(Html_js_eval_proc_as_obj(proc, args));}
public String Html_js_eval_proc_as_str(String proc, Object... args) {return Object_.Xto_str_strict_or_null(Html_js_eval_proc_as_obj(proc, args));}
private Object Html_js_eval_proc_as_obj(String proc, Object... args) {
Bry_bfr bfr = Bry_bfr.new_();
bfr.Add_str_a7("return ").Add_str_u8(proc).Add_byte(Byte_ascii.Paren_bgn);
int args_len = args.length;
for (int i = 0; i < args_len; ++i) {
Object arg = args[i];
if (i != 0) bfr.Add_byte(Byte_ascii.Comma);
boolean quote_val = true;
if ( ClassAdp_.Eq_typeSafe(arg, Bool_.Cls_ref_type)
|| ClassAdp_.Eq_typeSafe(arg, Int_.Cls_ref_type)
|| ClassAdp_.Eq_typeSafe(arg, Long_.Cls_ref_type)
) {
quote_val = false;
}
if (quote_val) bfr.Add_byte(Byte_ascii.Apos);
if (quote_val)
bfr.Add_str_u8(Escape_quote(Object_.Xto_str_strict_or_null_mark(arg)));
else
bfr.Add_obj_strict(arg);
if (quote_val) bfr.Add_byte(Byte_ascii.Apos);
}
bfr.Add_byte(Byte_ascii.Paren_end).Add_byte(Byte_ascii.Semic);
return Eval_script(bfr.Xto_str_and_clear());
}
private static String Escape_quote(String v) {
String rv = v;
rv = String_.Replace(rv, "'", "\\'");
rv = String_.Replace(rv, "\"", "\\\"");
rv = String_.Replace(rv, "\n", "\\n");
return rv;
}
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;
@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;
@Override public String TextVal() {return browser.getText();}
@Override public void TextVal_set(String v) {browser.setText(v);}
@Override public void EnableDoubleBuffering() {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return GfoInvkAble_.Rv_unhandled;}
private String Eval_script_as_str(String script) {return (String)Eval_script(script);}
public Object Eval_script(String script) {
eval_rslt.Clear();
try {
eval_rslt.Result_set(browser.evaluate(script));
return eval_rslt.Result();
}
catch (Exception e) {eval_rslt.Error_set(e.getMessage()); return eval_rslt.Error();}
} private Swt_html_eval_rslt eval_rslt = new Swt_html_eval_rslt();
@Override public void focusGained(FocusEvent arg0) {}
@Override public void focusLost(FocusEvent arg0) {}
public static final int
Browser_tid_none = SWT.NONE
, Browser_tid_mozilla = SWT.MOZILLA
, Browser_tid_webkit = SWT.WEBKIT
;
}
class Swt_core_cmds_html extends Swt_core_cmds {
public Swt_core_cmds_html(Swt_html html_box, Control control) {super(control);}
@Override public void Focus() {
if (Focus_able())
control.forceFocus();
}
@Override public void Select_exec() {
this.Focus();
}
}
class Swt_html_eval_rslt {
public void Clear() {error = null; result = null;}
public boolean Result_pass() {return error == null;}
public Object Result() {return result;} public void Result_set(Object v) {result = v; error = null;} private Object result;
public String Error () {return error;} public void Error_set(String v) {error = v; result = null;} private String error;
}
class Swt_html_lnr_traverse implements TraverseListener {
public Swt_html_lnr_traverse(Swt_html html_box) {}
@Override public void keyTraversed(TraverseEvent arg0) {}
}
class Swt_html_lnr_title implements TitleListener {
private Swt_html html_box;
public Swt_html_lnr_title(Swt_html html_box) {this.html_box = html_box;}
@Override public void changed(TitleEvent ev) {
try {UsrDlg_._.Note(ev.title);}
catch (Exception e) {html_box.Kit().Ask_ok("xowa.swt.html_box", "title.fail", Err_.Message_gplx_brief(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync
}
}
class Swt_html_func extends BrowserFunction {
private GfoInvkAble invk;
public Swt_html_func(Browser browser, String name, GfoInvkAble invk) {
super (browser, name);
this.invk = invk;
}
public Object function (Object[] args) {
try {
return gplx.gfui.Gfui_html.Js_args_exec(invk, args);
}
catch (Exception e) {
return Err_.Message_gplx_brief(e);
}
}
}
class Swt_html_lnr_status implements StatusTextListener {
public Swt_html_lnr_status(Swt_html html_box) {this.html_box = html_box;} private Swt_html html_box;
public void Host_set(GfoEvObj host) {this.host = host;} GfoEvObj host;
@Override public void changed(StatusTextEvent ev) {
if (html_box.Kit().Kit_mode__term())
return; // shutting down raises status changed events; ignore, else SWT exception thrown; DATE:2014-05-29
String ev_text = ev.text;
// if (String_.Has(ev_text, "Loading [MathJax]")) return; // suppress MathJax messages; // NOTE: disabled for 2.1 (which no longer outputs messages to status); DATE:2013-05-03
try {if (host != null) GfoEvMgr_.PubObj(host, Gfui_html.Evt_link_hover, "v", ev_text);}
catch (Exception e) {html_box.Kit().Ask_ok("xowa.gui.html_box", "status.fail", Err_.Message_gplx_brief(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync
}
}
class Swt_html_lnr_progress implements ProgressListener {
public Swt_html_lnr_progress(Swt_html html_box) {}
@Override public void changed(ProgressEvent arg0) {}
@Override public void completed(ProgressEvent arg0) {
// UsrDlg_._.Note("done");
}
}
class Swt_html_lnr_location implements LocationListener {
public Swt_html_lnr_location(Swt_html html_box) {this.html_box = html_box;} private Swt_html html_box;
public void Host_set(GfoEvObj host) {this.host = host;} private GfoEvObj host;
@Override public void changed(LocationEvent arg) {Pub_evt(arg, Gfui_html.Evt_location_changed);}
@Override public void changing(LocationEvent arg) {Pub_evt(arg, Gfui_html.Evt_location_changing);}
private 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.Browser_tid() == Swt_html.Browser_tid_webkit // webkit prefixes "about:blank" to anchors; causes TOC to fail when clicking on links; EX:about:blank#TOC1; DATE:2015-06-09
&& String_.Has_at_bgn(location, "about:blank")) {
location = String_.Mid(location, 11); // 11 = "about:blank".length
}
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_.Has_at_bgn(location, "file:")
&& String_.Has_at_end(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
}
catch (Exception e) {html_box.Kit().Ask_ok("xowa.gui.html_box", evt, Err_.Message_gplx_brief(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync
}
}
class Swt_html_lnr_mouse implements MouseListener {
private GxwElem elem; private Browser browser; private Swt_kit kit;
public Swt_html_lnr_mouse(GxwElem elem, Browser browser, Swt_kit kit) {this.elem = elem; this.browser = browser; this.kit = kit;}
@Override public void mouseDown(MouseEvent ev) {
if (Is_at_scrollbar_area()) return;
elem.Host().MouseDownCbk(XtoMouseData(ev));
}
@Override public void mouseUp(MouseEvent ev) {
if (Is_at_scrollbar_area()) return;
elem.Host().MouseUpCbk(XtoMouseData(ev));
}
private boolean Is_at_scrollbar_area() {
// WORKAROUND.SWT: SEE:NOTE_1:browser scrollbar and click
Point browser_size = browser.getSize();
Point click_pos = kit.Swt_display().getCursorLocation();
return click_pos.x >= browser_size.x - 12;
}
@Override public void mouseDoubleClick(MouseEvent ev) {}
IptEvtDataMouse XtoMouseData(MouseEvent ev) {
IptMouseBtn btn = null;
switch (ev.button) {
case 1: btn = IptMouseBtn_.Left; break;
case 2: btn = IptMouseBtn_.Middle; break;
case 3: btn = IptMouseBtn_.Right; break;
case 4: btn = IptMouseBtn_.X1; break;
case 5: btn = IptMouseBtn_.X2; break;
}
return IptEvtDataMouse.new_(btn, IptMouseWheel_.None, ev.x, ev.y);
}
}
/*
NOTE_1:browser scrollbar and click
a click in the scrollbar area will raise a mouse-down/mouse-up event in content-editable mode
. a click should be consumed by the scrollbar and not have any effect elsewhere on the window
. instead, a click event is raised, and counted twice
1) for the scroll bar this will scroll the area.
2) for the window. if keyboard-focus is set on a link, then it will activate the link.
swt does not expose any scrollbar information (visible, width), b/c the scrollbar is controlled by the underlying browser
so, assume:
. scrollbar is always present
. scrollbar has arbitrary width (currently 12)
. and discard if click is in this scrollbar area
two issues still occur with the workaround
1) even if the scrollbar is not present, any click on the right-hand edge of the screen will be ignored
2) click -> hold -> move mouse over to left -> release; the mouse up should be absorbed, but it is not due to position of release
*/

View File

@@ -0,0 +1,47 @@
/*
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.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
class Swt_img implements ImageAdp {
public Swt_img(Gfui_kit kit, Image under, int w, int h) {this.kit = kit; this.under = under; this.width = w; this.height = h;}
public Gfui_kit Kit() {return kit;} Gfui_kit kit;
public SizeAdp Size() {if (size == null) size = SizeAdp_.new_(width, height); return size;} SizeAdp size;
public int Width() {return width;} int width;
public int Height() {return height;} int height;
public Io_url Url() {return url;} public ImageAdp Url_(Io_url v) {url = v; return this;} Io_url url = Io_url_.Empty;
public Object Under() {return under;} Image under;
public boolean Disposed() {return under.isDisposed();}
public void Rls() {under.dispose();}
public void SaveAsBmp(Io_url url) {throw Exc_.new_unimplemented();}
public void SaveAsPng(Io_url url) {throw Exc_.new_unimplemented();}
public ImageAdp Resize(int trg_w, int trg_h) {return Extract_image(0, 0, width, height, trg_w, trg_h);}
public ImageAdp Extract_image(RectAdp src_rect, SizeAdp trg_size) {return Extract_image(src_rect.X(), src_rect.Y(), src_rect.Width(), src_rect.Height(), trg_size.Width(), trg_size.Height());}
public ImageAdp Extract_image(int src_x, int src_y, int src_w, int src_h, int trg_w, int trg_h) {
Image trg_img = new Image(Display.getDefault(), trg_w, trg_h);
GC gc = new GC(trg_img);
gc.setAntialias(SWT.ON);
gc.setInterpolation(SWT.HIGH);
gc.drawImage(under, src_x, src_y, src_w, src_h, 0, 0, trg_w, trg_h);
gc.dispose();
return new Swt_img(kit, trg_img, trg_w, trg_h);
}
}

View File

@@ -0,0 +1,44 @@
/*
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.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
class Swt_lbl implements GxwElem, Swt_control {
private Label lbl;
public Swt_lbl(Swt_control owner, KeyValHash ctorArgs) {
lbl = new Label(owner.Under_composite(), SWT.CENTER);
core = new Swt_core_cmds(lbl);
lbl.addKeyListener(new Swt_lnr_key(this));
lbl.addMouseListener(new Swt_lnr_mouse(this));
}
@Override public Control Under_control() {return lbl;}
@Override public Control Under_menu_control() {return lbl;}
@Override public String TextVal() {return lbl.getText();} @Override public void TextVal_set(String v) {
lbl.setText(v);
}
@Override public GxwCore_base Core() {return core;} GxwCore_base core;
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
@Override public Composite Under_composite() {return null;}
@Override public void EnableDoubleBuffering() {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return null;}
}

View File

@@ -0,0 +1,224 @@
/*
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 java.security.acl.Owner;
import gplx.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.events.MenuDetectEvent;
import org.eclipse.swt.events.MenuDetectListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
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;
if (v == ImageAdp_.Null)
menu_item.setImage(null);
else
menu_item.setImage((Image)v.Under());
} private ImageAdp img;
@Override public boolean Selected() {return menu_item.getSelection();} @Override public void Selected_(boolean v) {menu_item.setSelection(v);}
public String Root_key() {return root_key;} private String root_key;
public Menu Under_menu() {return menu;} private Menu menu;
public MenuItem Under_menu_item() {return menu_item;} private MenuItem menu_item;
public Object Under() {return menu;}
@Override public void Itms_clear() {
menu.dispose();
if (menu_is_bar) {
menu = new Menu(owner_win, SWT.BAR);
owner_win.setMenuBar(menu);
}
else {
menu = new Menu(owner_box);
owner_box.setMenu(menu);
}
}
@Override public Gfui_mnu_itm Itms_add_btn_cmd(String txt, ImageAdp img, GfoInvkAble invk, String cmd) {
Swt_popup_itm itm = new Swt_popup_itm(menu);
itm.Text_(txt);
if (img != null) itm.Img_(img);
itm.Invk_set_cmd(invk, cmd);
return itm;
}
@Override public Gfui_mnu_itm Itms_add_btn_msg(String txt, ImageAdp img, GfoInvkAble invk, GfoInvkRootWkr root_wkr, GfoMsg invk_msg) {
Swt_popup_itm itm = new Swt_popup_itm(menu);
itm.Text_(txt);
if (img != null) itm.Img_(img);
itm.Invk_set_msg(root_wkr, invk, invk_msg);
return itm;
}
@Override public Gfui_mnu_itm Itms_add_chk_msg(String txt, ImageAdp img, GfoInvkAble invk, GfoInvkRootWkr root_wkr, GfoMsg msg_n, GfoMsg msg_y) {
Swt_popup_itm itm = new Swt_popup_itm(menu, SWT.CHECK);
itm.Text_(txt);
if (img != null) itm.Img_(img);
itm.Invk_set_chk(root_wkr, invk, msg_n, msg_y);
return itm;
}
@Override public Gfui_mnu_itm Itms_add_rdo_msg(String txt, ImageAdp img, GfoInvkAble invk, GfoInvkRootWkr root_wkr, GfoMsg msg) {
Swt_popup_itm itm = new Swt_popup_itm(menu, SWT.RADIO);
itm.Text_(txt);
if (img != null) itm.Img_(img);
itm.Invk_set_msg(root_wkr, invk, msg);
return itm;
}
@Override public Gfui_mnu_itm Itms_add_separator() {
new MenuItem(menu, SWT.SEPARATOR);
return null;
}
@Override public Gfui_mnu_grp Itms_add_grp(String txt, ImageAdp img) {
Swt_popup_itm itm = new Swt_popup_itm(menu, SWT.CASCADE);
if (img != null) itm.Img_(img);
itm.Text_(txt);
Swt_popup_grp grp = new_grp(root_key, owner_win);
grp.menu_item = itm.Under_menu_item();
itm.Text_(txt);
itm.Under_menu_item().setMenu(grp.Under_menu());
return grp;
}
public static Swt_popup_grp new_popup(String key, GfuiElem owner_elem) {
Swt_popup_grp rv = new Swt_popup_grp(key);
Shell owner_win = cast_to_shell(owner_elem.OwnerWin());
Control owner_box = ((Swt_control)owner_elem.UnderElem()).Under_control();
rv.owner_win = owner_win; rv.owner_box = owner_box;
rv.menu = new Menu(owner_box);
owner_box.setMenu(rv.menu);
return rv;
}
private static Swt_popup_grp new_grp(String key, Decorations owner_win) {
Swt_popup_grp rv = new Swt_popup_grp(key);
rv.owner_win = owner_win;
rv.menu = new Menu(owner_win, SWT.DROP_DOWN);
return rv;
}
public static Swt_popup_grp new_bar(String key, GfuiWin win) {
Swt_popup_grp rv = new Swt_popup_grp(key);
Shell owner_win = cast_to_shell(win);
rv.owner_win = owner_win;
rv.menu_is_bar = true;
rv.menu = new Menu(owner_win, SWT.BAR);
owner_win.setMenuBar(rv.menu);
return rv;
}
private static Shell cast_to_shell(GfuiWin win) {
return ((Swt_win)win.UnderElem()).UnderShell();
}
}
class Swt_lnr__menu_detect implements MenuDetectListener {
private final Swt_kit kit; private final GfuiElem elem;
public Swt_lnr__menu_detect(Swt_kit kit, GfuiElem elem) {this.kit = kit; this.elem = elem;}
@Override public void menuDetected(MenuDetectEvent arg0) {
try {GfoEvMgr_.Pub(elem, GfuiElemKeys.Evt_menu_detected);}
catch (Exception e) {
kit.Ask_ok("", "", "error during right-click; err=~{0}", Err_.Message_gplx(e));
}
}
}
class Swt_popup_itm implements Gfui_mnu_itm {
private Menu menu;
public Swt_popup_itm(Menu menu) {
this.menu = menu; itm = new MenuItem(menu, SWT.NONE);
this.tid = Gfui_mnu_itm_.Tid_btn;
}
public Swt_popup_itm(Menu menu, int swt_type) {
this.menu = menu; itm = new MenuItem(menu, swt_type);
switch (swt_type) {
case SWT.CASCADE: this.tid = Gfui_mnu_itm_.Tid_grp; break;
case SWT.CHECK: this.tid = Gfui_mnu_itm_.Tid_chk; break;
case SWT.RADIO: this.tid = Gfui_mnu_itm_.Tid_rdo; break;
default: throw Exc_.new_unhandled(swt_type);
}
}
@Override public int Tid() {return tid;} private int tid;
@Override public String Uid() {return uid;} private String uid = Gfui_mnu_itm_.Gen_uid();
@Override public boolean Enabled() {return itm.getEnabled();} @Override public void Enabled_(boolean v) {itm.setEnabled(v);}
@Override public String Text() {return itm.getText();} @Override public void Text_(String v) {itm.setText(v);}
@Override public ImageAdp Img() {return img;} @Override public void Img_(ImageAdp v) {
img = v;
if (v != ImageAdp_.Null)
itm.setImage((Image)v.Under());
} private ImageAdp img;
@Override public boolean Selected() {return itm.getSelection();}
@Override public void Selected_(boolean v) {
selected_changing = true;
itm.setSelection(v);
selected_changing = false;
}
public boolean Selected_changing() {return selected_changing;} private boolean selected_changing;
@Override public Object Under() {return menu;}
public MenuItem Under_menu_item() {return itm;} private MenuItem itm;
public void Invk_set_cmd(GfoInvkAble invk, String cmd) {
itm.addListener(SWT.Selection, new Swt_lnr__menu_btn_cmd(invk, cmd));
}
public void Invk_set_msg(GfoInvkRootWkr root_wkr, GfoInvkAble invk, GfoMsg msg) {
itm.addListener(SWT.Selection, new Swt_lnr__menu_btn_msg(root_wkr, invk, msg));
}
public void Invk_set_chk(GfoInvkRootWkr root_wkr, GfoInvkAble invk, GfoMsg msg_n, GfoMsg msg_y) {
itm.addListener(SWT.Selection, new Swt_lnr__menu_chk_msg(this, root_wkr, invk, msg_n, msg_y));
}
}
class Swt_lnr__menu_btn_cmd implements Listener {
public Swt_lnr__menu_btn_cmd(GfoInvkAble invk, String cmd) {this.invk = invk; this.cmd = cmd;} GfoInvkAble invk; String cmd;
public void handleEvent(Event ev) {
try {GfoInvkAble_.InvkCmd(invk, cmd);}
catch (Exception e) {Swt_kit._.Ask_ok("", "", "error while invoking command: cmd=~{0} err=~{1}", cmd, Err_.Message_gplx_brief(e));}
}
}
class Swt_lnr__menu_btn_msg implements Listener {
private GfoInvkRootWkr root_wkr; private GfoInvkAble invk; private GfoMsg msg;
public Swt_lnr__menu_btn_msg(GfoInvkRootWkr root_wkr, GfoInvkAble invk, GfoMsg msg) {this.root_wkr = root_wkr; this.invk = invk; this.msg = msg;}
public void handleEvent(Event ev) {
try {
msg.Args_reset();
root_wkr.Run_str_for(invk, msg);
}
catch (Exception e) {Swt_kit._.Ask_ok("", "", "error while invoking command: cmd=~{0} err=~{1}", msg.Key(), Err_.Message_gplx_brief(e));}
}
}
class Swt_lnr__menu_chk_msg implements Listener {
private Swt_popup_itm mnu_itm; private GfoInvkRootWkr root_wkr; private GfoInvkAble invk; private GfoMsg msg_n, msg_y;
public Swt_lnr__menu_chk_msg(Swt_popup_itm mnu_itm, GfoInvkRootWkr root_wkr, GfoInvkAble invk, GfoMsg msg_n, GfoMsg msg_y) {
this.mnu_itm = mnu_itm;
this.root_wkr = root_wkr; this.invk = invk; this.msg_n = msg_n; this.msg_y = msg_y;
}
public void handleEvent(Event ev) {
if (mnu_itm.Selected_changing()) return;
GfoMsg msg = mnu_itm.Under_menu_item().getSelection() ? msg_y : msg_n;
try {
msg.Args_reset();
root_wkr.Run_str_for(invk, msg);
}
catch (Exception e) {Swt_kit._.Ask_ok("", "", "error while invoking command: cmd=~{0} err=~{1}", msg.Key(), Err_.Message_gplx_brief(e));}
}
}

View File

@@ -0,0 +1,55 @@
/*
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.custom.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class Swt_tab_itm implements Gxw_tab_itm, Swt_control, FocusListener {
public CTabFolder Tab_mgr() {return tab_mgr;} private CTabFolder tab_mgr;
public Swt_tab_mgr Tab_mgr_swt() {return tab_mgr_swt;} private Swt_tab_mgr tab_mgr_swt;
public Gfui_tab_itm_data Tab_data() {return (Gfui_tab_itm_data)tab_itm.getData();}
public Swt_tab_itm(Swt_tab_mgr tab_mgr_swt, Swt_kit kit, CTabFolder tab_mgr, Gfui_tab_itm_data tab_data) {
this.tab_mgr_swt = tab_mgr_swt; this.kit = kit; this.tab_mgr = tab_mgr;
tab_itm = new CTabItem(tab_mgr, SWT.CLOSE);
tab_itm.setData(tab_data);
// core = new Swt_core_cmds(tab_itm);
}
public Swt_kit Kit() {return kit;} private Swt_kit kit;
@Override public Control Under_control() {return null;}
@Override public Composite Under_composite() {return null;}
@Override public Control Under_menu_control() {throw Exc_.new_unimplemented();}
@Override public String Tab_name() {return tab_itm.getText();} @Override public void Tab_name_(String v) {tab_itm.setText(v);}
@Override public String Tab_tip_text() {return tab_itm.getToolTipText();} @Override public void Tab_tip_text_(String v) {tab_itm.setToolTipText(v);}
public void Subs_add(GfuiElem sub) {
Swt_control swt_control = Swt_control_.cast_or_fail(sub);
tab_itm.setControl(swt_control.Under_control());
}
public CTabItem Under_CTabItem() {return tab_itm;} private CTabItem tab_itm;
@Override public GxwCore_base Core() {return core;} GxwCore_base core;
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
@Override public String TextVal() {return "not implemented";}
@Override public void TextVal_set(String v) {}
@Override public void EnableDoubleBuffering() {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return GfoInvkAble_.Rv_unhandled;}
@Override public void focusGained(FocusEvent arg0) {}
@Override public void focusLost(FocusEvent arg0) {}
}
//#}

View File

@@ -0,0 +1,272 @@
/*
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 gplx.core.threads.Thread_adp_;
import org.eclipse.swt.*;
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_tab_mgr implements Gxw_tab_mgr, Swt_control, FocusListener, GfoEvMgrOwner {
private GfuiInvkCmd cmd_sync;
// private GfuiInvkCmd cmd_async; // NOTE: async needed for some actions like responding to key_down and calling .setSelection; else app hangs; DATE:2014-04-30
public Swt_tab_mgr(Swt_kit kit, Swt_control owner_control, KeyValHash ctorArgs) {
this.kit = kit;
tab_folder = new CTabFolder(owner_control.Under_composite(), SWT.BORDER);
tab_folder.setBorderVisible(false);
tab_folder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
tab_folder.setSimple(true);
tab_folder.addListener(SWT.Selection, new Swt_tab_mgr_lnr_selection(this));
tab_folder.addKeyListener(new Swt_lnr_key(this));
new Swt_tab_mgr_lnr_drag_drop(this, tab_folder);
tab_folder.addCTabFolder2Listener(new Swt_tab_mgr_lnr_close(this));
core = new Swt_core_cmds(tab_folder);
// cmd_async = kit.New_cmd_async(this);
cmd_sync = kit.New_cmd_sync(this);
}
public Swt_kit Kit() {return kit;} private Swt_kit kit;
public CTabFolder Under_ctabFolder() {return tab_folder;}
@Override public Control Under_control() {return tab_folder;} private CTabFolder tab_folder;
@Override public Composite Under_composite() {return tab_folder;}
@Override public Control Under_menu_control() {return tab_folder;}
public GfoEvMgr EvMgr() {return ev_mgr;} private GfoEvMgr ev_mgr;
public void EvMgr_(GfoEvMgr v) {ev_mgr = v;}
public ColorAdp Btns_selected_color() {return btns_selected_color;} private ColorAdp btns_selected_color;
public void Btns_selected_color_(ColorAdp v) {
btns_selected_color = v;
tab_folder.setSelectionBackground(kit.New_color(v));
}
public ColorAdp Btns_unselected_color() {return btns_unselected_color;}
public void Btns_unselected_color_(ColorAdp v) {
btns_unselected_color = v;
tab_folder.setBackground(kit.New_color(v));
} private ColorAdp btns_unselected_color;
@Override public boolean Btns_curved() {return tab_folder.getSimple();} @Override public void Btns_curved_(boolean v) {tab_folder.setSimple(!v);}
@Override public boolean Btns_place_on_top() {return tab_folder.getTabPosition() == SWT.TOP;}
@Override public void Btns_place_on_top_(boolean v) {tab_folder.setTabPosition(v ? SWT.TOP : SWT.BOTTOM); tab_folder.layout();}
@Override public int Btns_height() {return tab_folder.getTabHeight();} @Override public void Btns_height_(int v) {tab_folder.setTabHeight(v); tab_folder.layout();}
@Override public boolean Btns_close_visible() {return btns_close_visible;} private boolean btns_close_visible = true;
@Override public void Btns_close_visible_(boolean v) {
this.btns_close_visible = v;
CTabItem[] itms = tab_folder.getItems();
int len = itms.length;
for (int i = 0; i < len; i++)
itms[i].setShowClose(v);
}
@Override public boolean Btns_unselected_close_visible() {return tab_folder.getUnselectedCloseVisible();} @Override public void Btns_unselected_close_visible_(boolean v) {
tab_folder.setUnselectedCloseVisible(v);}
@Override public Gxw_tab_itm Tabs_add(Gfui_tab_itm_data tab_data) {
Swt_tab_itm rv = new Swt_tab_itm(this, kit, tab_folder, tab_data);
rv.Under_CTabItem().setData(tab_data);
CTabItem ctab_itm = rv.Under_CTabItem();
ctab_itm.setShowClose(btns_close_visible);
return rv;
}
@Override public void Tabs_close_by_idx(int i) {
CTabItem itm = tab_folder.getItems()[i];
Gfui_tab_itm_data tab_data = Get_tab_data(itm);
CTabItem next_tab = Tabs_select_after_closing_itm(tab_data); // NOTE: must calc next_tab before calling Pub_tab_closed; latter will recalc idx
this.Tabs_select_by_itm(next_tab); // NOTE: select tab before closing; DATE:2014-09-10
Pub_tab_closed(tab_data.Key()); // NOTE: dispose does not call event for .close; must manually raise event;
itm.dispose();
}
@Override public void Tabs_select_by_idx(int i) {
if (i == Gfui_tab_itm_data.Idx_null) return; // 0 tabs; return;
msg_tabs_select_by_idx_swt.Clear();
msg_tabs_select_by_idx_swt.Add("v", i);
cmd_sync.Invk(GfsCtx._, 0, Invk_tabs_select_by_idx_swt, msg_tabs_select_by_idx_swt);
} private GfoMsg msg_tabs_select_by_idx_swt = GfoMsg_.new_cast_(Invk_tabs_select_by_idx_swt);
@Override public void Tabs_switch(int src, int trg) {Tabs_switch(tab_folder.getItem(src), tab_folder.getItem(trg));}
public boolean Tabs_switch(CTabItem src_tab_itm, CTabItem trg_tab_itm) {
Control temp_control = src_tab_itm.getControl();
src_tab_itm.setControl(trg_tab_itm.getControl());
trg_tab_itm.setControl(temp_control);
String temp_str = src_tab_itm.getText();
src_tab_itm.setText(trg_tab_itm.getText());
trg_tab_itm.setText(temp_str);
temp_str = src_tab_itm.getToolTipText();
src_tab_itm.setToolTipText(trg_tab_itm.getToolTipText());
trg_tab_itm.setToolTipText(temp_str);
Gfui_tab_itm_data src_tab_data = Get_tab_data(src_tab_itm);
Gfui_tab_itm_data trg_tab_data = Get_tab_data(trg_tab_itm);
int src_tab_idx = src_tab_data.Idx(), trg_tab_idx = trg_tab_data.Idx();
tab_folder.setSelection(trg_tab_itm);
GfoEvMgr_.PubVals(this, Gfui_tab_mgr.Evt_tab_switched, KeyVal_.new_("src", src_tab_data.Key()), KeyVal_.new_("trg", trg_tab_data.Key()));
return src_tab_idx < trg_tab_idx;
}
public void Tabs_select_by_itm(CTabItem itm) {
if (itm == null) return; // 0 tabs; return;
msg_tabs_select_by_itm_swt.Clear();
msg_tabs_select_by_itm_swt.Add("v", itm);
cmd_sync.Invk(GfsCtx._, 0, Invk_tabs_select_by_itm_swt, msg_tabs_select_by_itm_swt);
} private GfoMsg msg_tabs_select_by_itm_swt = GfoMsg_.new_cast_(Invk_tabs_select_by_itm_swt);
private void Tabs_select_by_idx_swt(int idx) {
tab_folder.setSelection(idx);
CTabItem itm = tab_folder.getItem(idx);
Pub_tab_selected(Get_tab_key(itm)); // NOTE: setSelection does not call event for SWT.Selection; must manually raise event;
}
private void Tabs_select_by_itm_swt(CTabItem itm) {
tab_folder.setSelection(itm);
Pub_tab_selected(Get_tab_key(itm)); // NOTE: setSelection does not call event for SWT.Selection; must manually raise event;
}
public CTabItem Tabs_select_after_closing_itm(Gfui_tab_itm_data tab_data) {
int next_idx = Gfui_tab_itm_data.Get_idx_after_closing(tab_data.Idx(), tab_folder.getItemCount());
return next_idx == Gfui_tab_itm_data.Idx_null ? null : tab_folder.getItem(next_idx);
}
public void Pub_tab_selected(String key) {
GfoEvMgr_.PubObj(this, Gfui_tab_mgr.Evt_tab_selected, "key", key);
}
public void Pub_tab_closed(String key) {
GfoEvMgr_.PubObj(this, Gfui_tab_mgr.Evt_tab_closed, "key", key);
}
@Override public GxwCore_base Core() {return core;} GxwCore_base core;
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
@Override public String TextVal() {return "not implemented";}
@Override public void TextVal_set(String v) {}
@Override public void EnableDoubleBuffering() {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
if (String_.Eq(k, Invk_tabs_select_by_idx_swt)) Tabs_select_by_idx_swt(m.ReadInt("v"));
else if (String_.Eq(k, Invk_tabs_select_by_itm_swt)) Tabs_select_by_itm_swt((CTabItem)m.ReadObj("v", null));
else return GfoInvkAble_.Rv_unhandled;
return this;
}
@Override public void focusGained(FocusEvent arg0) {}
@Override public void focusLost(FocusEvent arg0) {}
private static String
Invk_tabs_select_by_idx_swt = "tabs_select_by_idx"
, Invk_tabs_select_by_itm_swt = "tabs_select_by_itm"
;
public static Gfui_tab_itm_data Get_tab_data_by_obj(Object data) {return (Gfui_tab_itm_data)data;}
public static Gfui_tab_itm_data Get_tab_data(CTabItem itm) {return (Gfui_tab_itm_data)itm.getData();}
public static String Get_tab_key(CTabItem itm) {return ((Gfui_tab_itm_data)itm.getData()).Key();}
}
class Swt_tab_mgr_lnr_selection implements Listener {
public Swt_tab_mgr_lnr_selection(Swt_tab_mgr tab_folder) {this.tab_folder = tab_folder;} private Swt_tab_mgr tab_folder;
public void handleEvent(Event ev) {
tab_folder.Pub_tab_selected(Swt_tab_mgr.Get_tab_data_by_obj(ev.item.getData()).Key());
}
}
class Swt_tab_mgr_lnr_close extends CTabFolder2Adapter { // handles close when tab x is clicked
public Swt_tab_mgr_lnr_close(Swt_tab_mgr tab_folder) {this.tab_folder = tab_folder;} private Swt_tab_mgr tab_folder;
@Override public void close(CTabFolderEvent ev) {
Gfui_tab_itm_data tab_data = Swt_tab_mgr.Get_tab_data_by_obj(ev.item.getData());
tab_folder.Tabs_close_by_idx(tab_data.Idx());
ev.doit = false; // mark ev handled, since Tabs_close_by_idx closes tab
}
}
class Swt_tab_mgr_lnr_drag_drop implements Listener {
private boolean dragging = false;
private boolean drag_stop = false;
private CTabItem drag_itm;
private final Swt_tab_mgr tab_mgr; private final CTabFolder tab_folder; private final Display display;
private Point prv_mouse;
private Point dead_zone = null;
public Swt_tab_mgr_lnr_drag_drop(Swt_tab_mgr tab_mgr, CTabFolder tab_folder) {
this.tab_mgr = tab_mgr; this.tab_folder = tab_folder; this.display = tab_folder.getDisplay();
tab_folder.addListener(SWT.DragDetect, this);
tab_folder.addListener(SWT.MouseUp, this);
tab_folder.addListener(SWT.MouseMove, this);
tab_folder.addListener(SWT.MouseExit, this);
tab_folder.addListener(SWT.MouseEnter, this);
}
private void Drag_drop_bgn(CTabItem itm) {
dragging = true;
drag_stop = false;
drag_itm = itm;
dead_zone = null;
}
private void Drag_drop_end() {
tab_folder.setInsertMark(null, false);
dragging = false;
drag_stop = false;
drag_itm = null;
}
public void handleEvent(Event e) {
Point cur_mouse = e.type == SWT.DragDetect
? tab_folder.toControl(display.getCursorLocation()) //see bug 43251
: new Point(e.x, e.y)
;
switch (e.type) {
case SWT.DragDetect: {
CTabItem itm = tab_folder.getItem(cur_mouse);
if (itm == null) return;
this.Drag_drop_bgn(itm);
break;
}
case SWT.MouseEnter:
if (drag_stop) {
dragging = e.button != 0;
drag_stop = false;
}
break;
case SWT.MouseExit:
if (dragging)
Drag_drop_end();
break;
case SWT.MouseUp: {
if (!dragging) return;
Drag_drop_end();
break;
}
case SWT.MouseMove: {
if (!dragging) return;
CTabItem curr_itm = tab_folder.getItem(cur_mouse);
if (curr_itm == null) {
tab_folder.setInsertMark(null, false);
return;
}
if (curr_itm == drag_itm) return; // curr_itm is same as drag_itm; ignore
int cur_mouse_x = cur_mouse.x;
int prv_mouse_x = prv_mouse == null ? 0 : prv_mouse.x;
prv_mouse = cur_mouse; // set prv_mouse now b/c of early return below; note that cur_mouse_x and prv_mouse_x are cached above
if ( dead_zone != null // dead_zone exists
&& Int_.Between(cur_mouse_x, dead_zone.x, dead_zone.y)) { // mouse is in dead_zone
int drag_idx = Swt_tab_mgr.Get_tab_data(drag_itm).Idx();
int curr_idx = Swt_tab_mgr.Get_tab_data(curr_itm).Idx();
if (drag_idx > curr_idx && cur_mouse_x < prv_mouse_x) {} // drag_itm is right of curr_itm, but mouse is moving left (direction reversed); cancel
else if (drag_idx < curr_idx && cur_mouse_x > prv_mouse_x) {} // drag_itm is left of curr_itm, but mouse is moving right (direction reversed); cancel
else
return; // in dead zone, and still moving in original direction; return early
}
boolean fwd = tab_mgr.Tabs_switch(drag_itm, curr_itm);
drag_itm = curr_itm;
Rectangle drag_rect = drag_itm.getBounds();
dead_zone = Calc_dead_zone(fwd, cur_mouse_x, drag_rect.x, drag_rect.width);
break;
}
}
}
public static Point Calc_dead_zone(boolean fwd, int mouse_x, int drag_l, int drag_w) {
if (fwd) { // drag_itm was moving fwd (moving right)
if (mouse_x < drag_l) return new Point(mouse_x, drag_l); // mouse_x < drag_l; create dead_zone until mouse_x reaches drag_l; occurs when moving drag is small_title and trg_itm is large_title
}
else { // drag_itm was moving bwd (moving left)
int drag_r = drag_l + drag_w;
if (mouse_x > drag_r) return new Point(drag_r, mouse_x); // mouse_x > drag_r; create dead_zone until mouse_x reaches drag_r
}
return null;
}
}
//#}

View File

@@ -0,0 +1,59 @@
/*
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.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
class Swt_text implements GxwTextFld, Swt_control {
private Text text_box;
public Swt_text(Swt_control owner_control, KeyValHash ctorArgs) {
int text_box_args = ctorArgs.Has(GfuiTextBox_.Ctor_Memo)
? SWT.MULTI | SWT.WRAP | SWT.V_SCROLL
: SWT.NONE
;
text_box = new Text(owner_control.Under_composite(), text_box_args);
core = new Swt_core_cmds(text_box);
text_box.addKeyListener(new Swt_lnr_key(this));
text_box.addMouseListener(new Swt_lnr_mouse(this));
}
@Override public Control Under_control() {return text_box;}
@Override public Composite Under_composite() {return null;}
@Override public Control Under_menu_control() {return text_box;}
@Override public int SelBgn() {return text_box.getCaretPosition();} @Override public void SelBgn_set(int v) {text_box.setSelection(v);}
@Override public int SelLen() {return text_box.getSelectionCount();} @Override public void SelLen_set(int v) {text_box.setSelection(this.SelBgn(), this.SelBgn() + v);}
@Override public String TextVal() {return text_box.getText();} @Override public void TextVal_set(String v) {text_box.setText(v);}
@Override public GxwCore_base Core() {return core;} GxwCore_base core;
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
@Override public void EnableDoubleBuffering() {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return null;}
public void Margins_set(int left, int top, int right, int bot) {}
@Override public boolean Border_on() {return false;} @Override public void Border_on_(boolean v) {} // SWT_TODO:borderWidth doesn't seem mutable
@Override public void CreateControlIfNeeded() {}
@Override public boolean OverrideTabKey() {return false;} @Override public void OverrideTabKey_(boolean v) {}
}

View File

@@ -0,0 +1,89 @@
/*
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.SWT;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TraverseListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class Swt_text_w_border implements GxwTextFld, Swt_control {
private Composite text_host;
private Composite text_margin;
private Text text_elem;
public Swt_text_w_border(Swt_control owner_control, Color color, KeyValHash ctorArgs) {
Composite owner = owner_control.Under_composite();
int text_elem_style = ctorArgs.Has(GfuiTextBox_.Ctor_Memo) ? SWT.MULTI | SWT.WRAP | SWT.V_SCROLL : SWT.FLAT;
New_box_text_w_border(owner.getDisplay(), owner.getShell(), text_elem_style, color);
core = new Swt_core_cmds_frames(text_host, new Swt_core_cmds_frames_itm[]
{ new Swt_core_cmds_frames_itm_manual(text_margin, 1, 1, -2, -2)
, new Swt_core_cmds_frames_itm_center_v(text_elem, this)
});
text_elem.addKeyListener(new Swt_lnr_key(this));
text_elem.addMouseListener(new Swt_lnr_mouse(this));
}
@Override public Control Under_control() {return text_host;}
@Override public Composite Under_composite() {return null;}
@Override public Control Under_menu_control() {return text_elem;}
public Text Under_text() {return text_elem;}
@Override public int SelBgn() {return text_elem.getCaretPosition();} @Override public void SelBgn_set(int v) {text_elem.setSelection(v);}
@Override public int SelLen() {return text_elem.getSelectionCount();} @Override public void SelLen_set(int v) {text_elem.setSelection(this.SelBgn(), this.SelBgn() + v);}
@Override public String TextVal() {return text_elem.getText();} @Override public void TextVal_set(String v) {text_elem.setText(v);}
@Override public GxwCore_base Core() {return core;} Swt_core_cmds_frames core;
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
@Override public void EnableDoubleBuffering() {}
@Override public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
return null;
}
public int Margins_l() {return margins_l;} int margins_l;
public int Margins_r() {return margins_r;} int margins_r;
public int Margins_t() {return margins_t;} int margins_t;
public int Margins_b() {return margins_b;} int margins_b;
public void Margins_set(int left, int top, int right, int bot) {
this.margins_l = left; this.margins_t = top; this.margins_r = right; this.margins_b = bot;
}
@Override public boolean Border_on() {return false;} @Override public void Border_on_(boolean v) {} // SWT_TODO:borderWidth doesn't seem mutable
@Override public void CreateControlIfNeeded() {}
@Override public boolean OverrideTabKey() {return false;} @Override public void OverrideTabKey_(boolean v) {}
void New_box_text_w_border(Display display, Shell shell, int style, Color color) {
text_host = new Composite(shell, SWT.FLAT);
text_margin = new Composite(text_host, SWT.FLAT);
text_elem = new Text(text_margin, style);
text_elem .addTraverseListener(Swt_lnr_traverse_ignore_ctrl._); // do not allow ctrl+tab to change focus when pressed in text box; allows ctrl+tab to be used by other bindings; DATE:2014-04-30
text_host.setSize(20, 20);
text_host.setBackground(color);
text_margin.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
text_margin.setSize(20, 20);
text_elem.setSize(20 - 2, 20 - 2);
text_elem.setLocation(1, 1);
}
}
class Swt_lnr_traverse_ignore_ctrl implements TraverseListener {
public void keyTraversed(TraverseEvent e) {
if (Swt_lnr_key.Has_ctrl(e.stateMask)) e.doit = false;
}
public static final Swt_lnr_traverse_ignore_ctrl _ = new Swt_lnr_traverse_ignore_ctrl();
}

View File

@@ -0,0 +1,114 @@
/*
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 java.io.FileInputStream;
import java.io.FileNotFoundException;
import gplx.Bool_;
import gplx.GfoInvkAbleCmd;
import gplx.GfoMsg;
import gplx.GfsCtx;
import gplx.Io_url_;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
class Swt_win implements GxwWin, Swt_control {
private Swt_lnr_resize resize_lnr; private Swt_lnr_show show_lnr; // use ptr to dispose later
void ctor(boolean window_is_dialog, Shell shell, Display display) {
this.shell = shell;
this.display = display;
this.ctrl_mgr = new Swt_core_cmds(shell);
this.show_lnr = new Swt_lnr_show(this);
this.resize_lnr = new Swt_lnr_resize(this);
shell.addListener(SWT.Show, show_lnr);
shell.addListener(SWT.Resize, resize_lnr);
if (window_is_dialog) {
shell.addListener(SWT.Traverse, new Swt_lnr_traverse());
}
}
public Display UnderDisplay() {return display;} private Display display;
public Shell UnderShell() {return shell;} private Shell shell;
@Override public Control Under_control() {return shell;}
@Override public Composite Under_composite() {return shell;}
@Override public Control Under_menu_control() {return shell;}
public Swt_win(Shell owner) {ctor(Bool_.Y, new Shell(owner, SWT.RESIZE | SWT.DIALOG_TRIM), owner.getDisplay());}
public Swt_win(Display display) {ctor(Bool_.N, new Shell(display), display); }
public void ShowWin() {shell.setVisible(true);}
public void HideWin() {shell.setVisible(false);}
public boolean Maximized() {return shell.getMaximized();} public void Maximized_(boolean v) {shell.setMaximized(v);}
public boolean Minimized() {return shell.getMinimized();} public void Minimized_(boolean v) {shell.setMinimized(v);}
public void CloseWin() {shell.close();}
public boolean Pin() {return pin;}
public void Pin_set(boolean val) {
// shell.setAlwaysOnTop(val);
pin = val;
} boolean pin = false;
public IconAdp IconWin() {return icon;} IconAdp icon;
public void IconWin_set(IconAdp i) {
if (i == null || i.Url() == Io_url_.Empty) return;
icon = i;
Image image = null;
try {
image = new Image(display, new FileInputStream(i.Url().Xto_api()));
} catch (FileNotFoundException e1) {e1.printStackTrace();}
shell.setImage(image);
}
public void OpenedCmd_set(GfoInvkAbleCmd v) {when_loaded_cmd = v;} private GfoInvkAbleCmd when_loaded_cmd = GfoInvkAbleCmd.Null;
public void Opened() {when_loaded_cmd.Invk();}
public GxwCore_base Core() {return ctrl_mgr;} private GxwCore_base ctrl_mgr;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} private GxwCbkHost host = GxwCbkHost_.Null;
public String TextVal() {return shell.getText();}
public void TextVal_set(String v) {shell.setText(v);}
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
public void SendKeyDown(IptKey key) {}
public void SendMouseMove(int x, int y) {}
public void SendMouseDown(IptMouseBtn btn) {}
//public void windowActivated(WindowEvent e) {}
//public void windowClosed(WindowEvent e) {}
//public void windowClosing(WindowEvent e) {host.DisposeCbk();}
//public void windowDeactivated(WindowEvent e) {}
//public void windowDeiconified(WindowEvent e) {host.SizeChangedCbk();}
//public void windowIconified(WindowEvent e) {host.SizeChangedCbk();}
//public void windowOpened(WindowEvent e) {when_loaded_cmd.Invk();}
//@Override public void processKeyEvent(KeyEvent e) {if (GxwCbkHost_.ExecKeyEvent(host, e)) super.processKeyEvent(e);}
//@Override public void processMouseEvent(MouseEvent e) {if (GxwCbkHost_.ExecMouseEvent(host, e)) super.processMouseEvent(e);}
//@Override public void processMouseWheelEvent(MouseWheelEvent e) {if (GxwCbkHost_.ExecMouseWheel(host, e)) super.processMouseWheelEvent(e);}
//@Override public void processMouseMotionEvent(MouseEvent e) {if (host.MouseMoveCbk(IptEvtDataMouse.new_(IptMouseBtn_.None, IptMouseWheel_.None, e.getX(), e.getY()))) super.processMouseMotionEvent(e);}
//@Override public void paint(Graphics g) {
// if (host.PaintCbk(PaintArgs.new_(GfxAdpBase.new_((Graphics2D)g), RectAdp_.Zero))) // ClipRect not used by any clients; implement when necessary
// super.paint(g);
//}
public void EnableDoubleBuffering() {}
public void TaskbarVisible_set(boolean val) {} public void TaskbarParkingWindowFix(GxwElem form) {}
void ctor_GxwForm() {
// this.setLayout(null); // use gfui layout
// this.ctrl_mgr.BackColor_set(ColorAdp_.White); // default form backColor to white
// this.setUndecorated(true); // remove icon, titleBar, minimize, maximize, close, border
// this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // JAVA: cannot cancel alt+f4; set Close to noop, and manually control closing by calling this.CloseForm
// enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_WHEEL_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
// this.addWindowListener(this);
// GxwBoxListener lnr = new GxwBoxListener(this);
// this.addComponentListener(lnr);
// this.addFocusListener(lnr);
}
}