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-05-03 22:30:22 -04:00
parent f4b95f5ce6
commit 0b5aa9aefe
207 changed files with 2339 additions and 1460 deletions

View File

@@ -19,6 +19,8 @@ package gplx.gfui; import gplx.*;
public class IptArg_ {
public static final IptArg[] Ary_empty = new IptArg[0];
public static final IptArg Null = null;
public static final String Wildcard_key = "wildcard";
public static IptArg Wildcard = new IptKey(Int_.MaxValue, Wildcard_key);
public static boolean Is_null_or_none(IptArg arg) {return arg == Null || arg == IptKey_.None;}
public static IptArg[] Ary(IptArg... v) {return v;}
public static IptArg[] parse_ary_or_empty(String v) {

View File

@@ -21,7 +21,7 @@ public class IptBndMgr implements SrlAble {
public void EventsToFwd_set(IptEventType v) {eventsToFwd = v;} IptEventType eventsToFwd = IptEventType_.KeyDown;
public void EventsToFwd_add(IptEventType v) {eventsToFwd = eventsToFwd.Add(v);}
@gplx.Internal protected boolean Has(IptEventType type) {return IptEventType_.Has(curTypes, type);}
@gplx.Internal protected void Clear() {hash.Clear(); curTypes = IptEventType_.None; ClearLists(); chainMgr.Clear();}
public void Clear() {hash.Clear(); curTypes = IptEventType_.None; ClearLists(); chainMgr.Clear();}
public void Add(IptBnd bnd) {
for (IptBndHash list : regy)
if (IptEventType_.Has(bnd.EventTypes(), list.EventType()))
@@ -40,7 +40,7 @@ public class IptBndMgr implements SrlAble {
cfg.Owners_del(ptr.CfgKey());
for (IptBndHash list : regy) {
for (int j = 0; j < list.Count(); j++) {
IptBndListItm itmList = list.GetAt(j);
IptBndListItm itmList = list.Get_at(j);
for (int k = 0; k < itmList.Count(); k++) {
IptBnd bnd = itmList.FetchAt(k);
if (String_.Eq(ptr.BndKey(), bnd.Key())) {
@@ -60,7 +60,7 @@ public class IptBndMgr implements SrlAble {
IptBnd old = null;
for (IptBndHash list : regy) {
for (int j = 0; j < list.Count(); j++) {
IptBndListItm itmList = list.GetAt(j);
IptBndListItm itmList = list.Get_at(j);
for (int i = 0; i < itmList.Count(); i++) {
IptBnd bnd = itmList.FetchAt(i);
if (String_.Eq(key, bnd.Key())) {
@@ -89,7 +89,7 @@ public class IptBndMgr implements SrlAble {
IptBndHash list = regy[i];
int list_len = list.Count();
for (int j = 0; j < list_len; j++) {
IptBndListItm bnds = list.GetAt(j);
IptBndListItm bnds = list.Get_at(j);
int bnds_len = bnds.Count();
for (int k = 0; k < bnds_len; k++) {
IptBnd itm_bnd = bnds.FetchAt(k);
@@ -129,7 +129,7 @@ public class IptBndMgr implements SrlAble {
IptBndHash list = regy[AryIdx(evData.EventType())];
String key = evData.EventArg().Key();
if (!String_.Eq(chainMgr.ActiveKey(), "")) key = chainMgr.ActiveKey() + key;
IptBndListItm itm = list.Get(key);
IptBndListItm itm = list.Get_by(key);
String chainP = "";
if (evData.EventType() == IptEventType_.KeyDown) {
chainP = chainMgr.Process(evData.EventArg());
@@ -170,20 +170,27 @@ public class IptBndMgr implements SrlAble {
}
}
class IptBndHash implements SrlAble {
private IptBndListItm wildcard_list;
public IptEventType EventType() {return eventType;} IptEventType eventType;
public int Count() {return hash.Count();}
public IptBndListItm Get(String iptKey) {return (IptBndListItm)hash.Fetch(iptKey);}
public IptBndListItm GetAt(int i) {return (IptBndListItm)hash.FetchAt(i);}
public IptBndListItm Get_by(String key) {return wildcard_list == null ? (IptBndListItm)hash.Fetch(key) : wildcard_list;}
public IptBndListItm Get_at(int i) {return (IptBndListItm)hash.FetchAt(i);}
public void Add(IptBnd bnd) {
for (int i = 0; i < bnd.Ipts().Count(); i++) {
IptArg arg = (IptArg)bnd.Ipts().FetchAt(i);
if (!IptArg_.EventType_match(arg, eventType)) continue; // bnd may have multiple ipts of different evTypes; only add bnd if evType matches
IptBndListItm itm = (IptBndListItm)hash.Fetch(arg.Key());
if (itm == null) {
itm = new IptBndListItm(arg.Key());
hash.Add(arg.Key(), itm);
if (String_.Eq(arg.Key(), IptArg_.Wildcard_key)) {
if (wildcard_list == null) wildcard_list = new IptBndListItm(IptArg_.Wildcard_key);
wildcard_list.Add(bnd);
}
else {
IptBndListItm itm = (IptBndListItm)hash.Fetch(arg.Key());
if (itm == null) {
itm = new IptBndListItm(arg.Key());
hash.Add(arg.Key(), itm);
}
itm.Add(bnd);
}
itm.Add(bnd);
}
}
public void Del(IptBnd bnd) {

View File

@@ -17,13 +17,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
public class IptKey implements IptArg {
public String Key() {return key;} private String key;
@gplx.Internal protected IptKey(int val, String key) {this.val = val; this.key = key;}
public String Key() {return key;} private final String key;
public int Val() {return val;} private final int val;
public boolean Eq(IptArg comp) {return String_.Eq(key, comp.Key());}
public String XtoUiStr() {return IptKeyStrMgr._.XtoStr(this);}
public IptKey Add(IptKey comp) {return IptKey_.add_(this, comp);}
public boolean Mod_shift() {return Enm_.HasInt(val, IptKey_.Shift.Val());}
public boolean Mod_ctrl() {return Enm_.HasInt(val, IptKey_.Ctrl.Val());}
public boolean Mod_alt() {return Enm_.HasInt(val, IptKey_.Alt.Val());}
@gplx.Internal protected int Val() {return val;} int val;
@gplx.Internal protected IptKey(int val, String key) {this.val = val; this.key = key;}
}

View File

@@ -24,8 +24,8 @@ class IptKeyStrMgr {
}
public String XtoStr(IptKey key) {
if (literals == null) Init();
Object rvObj = literals.Fetch(key.Val());
return rvObj == null ? String_.Empty : (String)rvObj;
Object rv = literals.Fetch(key.Val());
return rv == null ? String_.Empty : (String)rv;
}
public void XtoIptKeyAry(ListAdp list) {
if (literals == null) Init();

View File

@@ -17,9 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import java.awt.event.KeyEvent;
public class IptKey_ {
import gplx.core.primitives.*;
public class IptKey_ {
private static EnmMgr enmMgr = EnmMgr.new_().BitRngBgn_(65536).BitRngEnd_(262144).Prefix_("key.");
public static IptKey[] Ary(IptKey... ary) {return ary;}
public static final IptKey[] Ary_empty = new IptKey[0];
public static IptKey as_(Object obj) {return obj instanceof IptKey ? (IptKey)obj : null;}
public static IptKey cast_(Object obj) {try {return (IptKey)obj;} catch(Exception exc) {throw Err_.type_mismatch_exc_(exc, IptKey.class, obj);}}
public static IptKey add_(IptKey... ary) {
@@ -99,4 +101,49 @@ public class IptKey_ {
, Quote = new_(222, "quote")
, Shift = new_(KeyCode_Shift, "shift"), Ctrl = new_(KeyCode_Ctrl, "ctrl"), Alt = new_(KeyCode_Alt, "alt")
;
private static OrderedHash ui_str_hash;
public static OrderedHash Ui_str_hash() {
if (ui_str_hash == null) {
ui_str_hash = OrderedHash_.new_();
All_add(ui_str_hash
, IptKey_.Back, IptKey_.Tab, IptKey_.Clear, IptKey_.Enter
, IptKey_.Pause, IptKey_.CapsLock, IptKey_.Escape, IptKey_.Space
, IptKey_.PageUp, IptKey_.PageDown, IptKey_.End, IptKey_.Home
, IptKey_.Left, IptKey_.Up, IptKey_.Right, IptKey_.Down
, IptKey_.PrintScreen, IptKey_.Insert, IptKey_.Delete
, IptKey_.D0, IptKey_.D1, IptKey_.D2, IptKey_.D3, IptKey_.D4
, IptKey_.D5, IptKey_.D6, IptKey_.D7, IptKey_.D8, IptKey_.D9
, IptKey_.A, IptKey_.B, IptKey_.C, IptKey_.D, IptKey_.E
, IptKey_.F, IptKey_.G, IptKey_.H, IptKey_.I, IptKey_.J
, IptKey_.K, IptKey_.L, IptKey_.M, IptKey_.N, IptKey_.O
, IptKey_.P, IptKey_.Q, IptKey_.R, IptKey_.S, IptKey_.T
, IptKey_.U, IptKey_.V, IptKey_.W, IptKey_.X, IptKey_.Y
, IptKey_.Z
, IptKey_.F1, IptKey_.F2, IptKey_.F3, IptKey_.F4, IptKey_.F5, IptKey_.F6
, IptKey_.F7, IptKey_.F8, IptKey_.F9, IptKey_.F10, IptKey_.F11, IptKey_.F12
, IptKey_.NumLock, IptKey_.ScrollLock
, IptKey_.Semicolon, IptKey_.Equal, IptKey_.Comma, IptKey_.Minus, IptKey_.Period, IptKey_.Slash, IptKey_.Tick
, IptKey_.OpenBracket, IptKey_.Back, IptKey_.CloseBracket, IptKey_.Quote
);
}
return ui_str_hash;
}
private static void All_add(OrderedHash hash, IptKey... ary) {
int len = ary.length;
for (int i = 0; i < len; ++i) {
IptKey key = ary[i];
hash.AddReplace(Int_obj_ref.new_(key.Val()), key);
}
}
public static String To_str(int val) {
String mod_str = "", rv = "";
boolean mod_c = Enm_.HasInt(val, IptKey_.Ctrl.Val()); if (mod_c) {mod_str += "c"; val = Enm_.FlipInt(Bool_.N, val, IptKey_.Ctrl.Val());}
boolean mod_a = Enm_.HasInt(val, IptKey_.Alt.Val()); if (mod_a) {mod_str += "a"; val = Enm_.FlipInt(Bool_.N, val, IptKey_.Alt.Val());}
boolean mod_s = Enm_.HasInt(val, IptKey_.Shift.Val()); if (mod_s) {mod_str += "s"; val = Enm_.FlipInt(Bool_.N, val, IptKey_.Shift.Val());}
if (String_.Len_gt_0(mod_str))
rv = "mod." + mod_str + "+";
IptKey key = (IptKey)IptKey_.Ui_str_hash().Fetch(Int_obj_ref.new_(val));
String key_str = key == null ? "key." + Int_.Xto_str(val) : key.Key();
return rv + key_str;
}
}

View File

@@ -0,0 +1,30 @@
/*
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.junit.*;
public class IptKey__tst {
private final IptKey__fxt fxt = new IptKey__fxt();
@Test public void To_str() {
fxt.Test_to_str(196608, "mod.cs+key.0");
}
}
class IptKey__fxt {
public void Test_to_str(int keycode, String expd) {
Tfds.Eq(expd, IptKey_.To_str(keycode));
}
}

View File

@@ -68,4 +68,5 @@ public class GfuiBtn extends GfuiElemBase {
} catch (Exception e) {GfuiEnv_.ShowMsg(Err_.Message_gplx(e));}
}
public static final String Invk_btn_img = "btn_img", Invk_btn_img_ = "btn_img_";
public static final String CFG_border_on_ = "border_on_";
}

View File

@@ -31,6 +31,9 @@ public class GfuiLbl extends GfuiElemBase { // standard label does not support t
super.ctor_GfuiBox_base(ctorArgs);
this.CustomDraw_set(true);
}
GfuiBorderMgr focusBorder = GfuiBorderMgr.new_();
@Override public void ctor_kit_GfuiElemBase(Gfui_kit kit, String key, GxwElem underElem, KeyValHash ctorArgs) {
super.ctor_kit_GfuiElemBase(kit, key, underElem, ctorArgs);
this.CustomDraw_set(true);
}
@Override public GxwElem UnderElem_make(KeyValHash ctorArgs) {return GxwElemFactory_._.lbl_();}
}

View File

@@ -23,6 +23,11 @@ public class GfuiLbl_ {
rv.TextMgr().AlignH_(GfuiAlign_.Mid);
return rv;
}
public static GfuiLbl kit_(Gfui_kit kit, String key, GxwElem elm, KeyValHash ctorArgs) {
GfuiLbl rv = new GfuiLbl();
rv.ctor_kit_GfuiElemBase(kit, key, elm, ctorArgs);
return rv;
}
public static GfuiLbl prefix_(String key, GfuiElem owner, String text) {
GfuiLbl rv = sub_(key, owner);
rv.Text_(text);

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui; import gplx.*;
import gplx.gfml.*;
import gplx.threads.*;
import gplx.core.threads.*;
import java.awt.AWTKeyStroke;
import java.awt.Font;
import java.awt.Graphics;
@@ -81,7 +81,7 @@ public class GfuiEnv_ {
public static void ShowMsg(String message) {javax.swing.JOptionPane.showMessageDialog(null, message, "", javax.swing.JOptionPane.INFORMATION_MESSAGE, null);}
public static void BringToFront(ProcessAdp process) {}
public static void DoEvents(int milliseconds) {
ThreadAdp_.Sleep(milliseconds);
Thread_adp_.Sleep(milliseconds);
}
public static void Run(GfuiWin form) {javax.swing.SwingUtilities.invokeLater(new GfuiFormRunner(form));}
public static FontAdp System_font() {

View File

@@ -38,6 +38,7 @@ public interface Gfui_kit extends GfoInvkAble {
Gfui_tab_mgr New_tab_mgr(String key, GfuiElem owner, KeyVal... args);
GfuiTextBox New_text_box(String key, GfuiElem owner, KeyVal... args);
GfuiBtn New_btn(String key, GfuiElem owner, KeyVal... args);
GfuiLbl New_lbl(String key, GfuiElem owner, KeyVal... args);
Gfui_dlg_file New_dlg_file(byte type, String msg);
Gfui_dlg_msg New_dlg_msg(String msg);
ImageAdp New_img_load(Io_url path);

View File

@@ -67,6 +67,11 @@ public abstract class Gfui_kit_base implements Gfui_kit {
owner.SubElems().Add(rv);
return rv;
}
@gplx.Virtual public GfuiLbl New_lbl(String key, GfuiElem owner, KeyVal... args) {
GfuiLbl rv = GfuiLbl_.kit_(this, key, New_btn_impl(), ctor_args);
owner.SubElems().Add(rv);
return rv;
}
@gplx.Virtual public GfuiStatusBox New_status_box(String key, GfuiElem owner, KeyVal... args) {
GfuiStatusBox rv = GfuiStatusBox_.kit_(this, key, this.Factory().text_memo_());
owner.SubElems().Add(rv);

View File

@@ -42,7 +42,9 @@ import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.omg.PortableServer.THREAD_POLICY_ID;
import gplx.threads.*;
import gplx.core.threads.Thread_adp_;
import gplx.core.threads.*;
public class Swt_kit implements Gfui_kit {
private final KeyValHash ctor_args = KeyValHash.new_(); private final KeyValHash ctor_args_null = KeyValHash.new_();
private final HashAdp kit_args = HashAdp_.new_(); private Swt_msg_wkr_stop msg_wkr_stop;
@@ -125,7 +127,9 @@ public class Swt_kit implements Gfui_kit {
}
public GfuiInvkCmd New_cmd_sync (GfoInvkAble invk) {return new Swt_gui_cmd(this, gui_wtr, display, invk, Bool_.N);}
public GfuiInvkCmd New_cmd_async(GfoInvkAble invk) {return new Swt_gui_cmd(this, gui_wtr, display, invk, Bool_.Y);}
public GfuiWin New_win_utl(String key, GfuiWin owner, KeyVal... args) {return GfuiWin_.kit_(this, key, new Swt_win(shell), ctor_args_null); }
public GfuiWin New_win_utl(String key, GfuiWin owner, KeyVal... args) {
return GfuiWin_.kit_(this, key, new Swt_win(shell), ctor_args_null);
}
public GfuiWin New_win_app(String key, KeyVal... args) {
Swt_win win = new Swt_win(display);
this.shell = win.UnderShell();
@@ -137,6 +141,11 @@ public class Swt_kit implements Gfui_kit {
owner.SubElems().Add(rv);
return rv;
}
public GfuiLbl New_lbl(String key, GfuiElem owner, KeyVal... args) {
GfuiLbl rv = GfuiLbl_.kit_(this, key, new Swt_lbl(Swt_control_.cast_or_fail(owner), ctor_args), ctor_args);
owner.SubElems().Add(rv);
return rv;
}
public Gfui_html New_html(String key, GfuiElem owner, KeyVal... args) {
ctor_args.Clear();
// check cfg for browser type
@@ -262,7 +271,7 @@ class Swt_shell_close_lnr implements Listener, GfoInvkAble {
}
if (kit.Kit_sync_cmd_exists()) { // sync cmd is running; cannot shut down app else app just hangs; DATE:2015-04-13
event.doit = false; // cancel shutdown
ThreadAdp_.invk_(this, Invk_wait_for_sync_cmd).Start(); // wait for sync_cmd to end in background thread; call shutdown again when it does
Thread_adp_.invk_(this, Invk_wait_for_sync_cmd).Start(); // wait for sync_cmd to end in background thread; call shutdown again when it does
}
}
private void Wait_for_sync_cmd() { // THREAD:non-GUI
@@ -273,7 +282,7 @@ class Swt_shell_close_lnr implements Listener, GfoInvkAble {
usr_dlg.Log_many("", "", "swt:sync cmd done; shutting down");
break;
}
ThreadAdp_.Sleep(loop_wait);
Thread_adp_.Sleep(loop_wait);
loop_count++;
}
if (loop_count == loop_max)

View File

@@ -57,18 +57,19 @@ class Swt_btn implements GxwElem, Swt_control {
@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);
core = new Swt_core_cmds(box_btn);
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;} Swt_core_cmds core;
@Override public GxwCbkHost Host() {return host;} @Override public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host;
@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) {
@@ -82,9 +83,6 @@ class Swt_btn_no_border implements GxwElem, Swt_control {
int dif = 6;
box_btn.setImage((Image)v.Resize(size.Width() - dif, size.Height() - dif).Under());
}
ImageAdp btn_img;
Composite box_grp;
Label box_btn;
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);

View File

@@ -26,10 +26,11 @@ 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) {
compositeAble = control instanceof Composite;
this.compositeAble = control instanceof Composite;
this.control = control;
} Control control; boolean compositeAble = false;
}
@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());}

View File

@@ -25,6 +25,8 @@ 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;
@@ -50,17 +52,24 @@ class Swt_lnr_resize implements Listener {
}
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 data = XtoKeyData(ev);
if (!elem.Host().KeyDownCbk(data)) {
IptEvtDataKey ipt_data = XtoKeyData(ev);
if (!elem.Host().KeyDownCbk(ipt_data) || ipt_data.Handled())
ev.doit = false;
}
}
@Override public void keyReleased(KeyEvent ev) {
if (!elem.Host().KeyUpCbk(XtoKeyData(ev))) ev.doit = false;
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;

View File

@@ -17,9 +17,10 @@ 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 gplx.threads.ThreadAdp_;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
@@ -28,7 +29,6 @@ import org.eclipse.swt.widgets.*;
import java.security.acl.Owner;
import gplx.*;
import gplx.threads.ThreadAdp_;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.events.*;
@@ -99,7 +99,7 @@ class Swt_html implements Gxw_html, Swt_control, FocusListener {
while (count < 5) {
boolean rv = Eval_script_as_bool(kit.Html_cfg().Elem_img_update(elem_id, elem_src, elem_width, elem_height));
if (rv) return rv;
ThreadAdp_.Sleep(100);
Thread_adp_.Sleep(100);
count++;
}
return false;

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

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui;
import gplx.*;
import gplx.threads.ThreadAdp_;
import gplx.core.threads.Thread_adp_;
import org.eclipse.swt.*;
import org.eclipse.swt.custom.*;

View File

@@ -20,6 +20,7 @@ package gplx.gfui;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import gplx.Bool_;
import gplx.GfoInvkAbleCmd;
import gplx.GfoMsg;
import gplx.GfsCtx;
@@ -32,24 +33,26 @@ 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(new Shell(owner, SWT.RESIZE | SWT.DIALOG_TRIM), owner.getDisplay());}
public Swt_win(Display display) {ctor(new Shell(display), display); }
Swt_lnr_show showLnr; // use ptr to dispose later
void ctor(Shell shell, Display display) {
this.shell = shell;
this.display = display;
ctrlMgr = new Swt_core_cmds(shell);
showLnr = new Swt_lnr_show(this);
resizeLnr = new Swt_lnr_resize(this);
shell.addListener(SWT.Show, showLnr);
shell.addListener(SWT.Resize, resizeLnr);
}
Swt_lnr_resize resizeLnr;
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);}
@@ -70,15 +73,12 @@ class Swt_win implements GxwWin, Swt_control {
} catch (FileNotFoundException e1) {e1.printStackTrace();}
shell.setImage(image);
}
public void OpenedCmd_set(GfoInvkAbleCmd v) {whenLoadedCmd = v;} GfoInvkAbleCmd whenLoadedCmd = GfoInvkAbleCmd.Null;
public void Opened() {whenLoadedCmd.Invk();}
public GxwCore_base Core() {return ctrlMgr;} GxwCore_base ctrlMgr;
public GxwCbkHost Host() {return host;} public void Host_set(GxwCbkHost host) {this.host = host;} GxwCbkHost host = GxwCbkHost_.Null;
public String TextVal() {
return shell.getText();}
public void TextVal_set(String v) {
shell.setText(v);
}
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) {}
@@ -89,7 +89,7 @@ class Swt_win implements GxwWin, Swt_control {
//public void windowDeactivated(WindowEvent e) {}
//public void windowDeiconified(WindowEvent e) {host.SizeChangedCbk();}
//public void windowIconified(WindowEvent e) {host.SizeChangedCbk();}
//public void windowOpened(WindowEvent e) {whenLoadedCmd.Invk();}
//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);}
@@ -102,7 +102,7 @@ class Swt_win implements GxwWin, Swt_control {
public void TaskbarVisible_set(boolean val) {} public void TaskbarParkingWindowFix(GxwElem form) {}
void ctor_GxwForm() {
// this.setLayout(null); // use gfui layout
// this.ctrlMgr.BackColor_set(ColorAdp_.White); // default form backColor to white
// 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);