mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
Embeddable: Fix if_exists (restore)
This commit is contained in:
40
150_gfui/src/gplx/gfui/kits/core/GfoFactory_gfui.java
Normal file
40
150_gfui/src/gplx/gfui/kits/core/GfoFactory_gfui.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.controls.windows.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*; import gplx.gfui.controls.customs.*;
|
||||
public class GfoFactory_gfui {
|
||||
public static void Btn_MinWin(GfuiElem owner, GfoMsg appWinMsg) {
|
||||
GfuiBtn_.msg_("minWin", owner, GfoMsg_.chain_(appWinMsg, GfuiWin.Invk_Minimize)).Text_("_").TipText_("minmize window").Width_(20);
|
||||
}
|
||||
public static void Btn_MinWin2(GfuiElem owner) {
|
||||
GfuiBtn_.msg_("minWin", owner, GfoMsg_.root_(".", GfuiElemBase.Invk_OwnerWin_cmd, GfuiWin.Invk_Minimize)).Text_("_").TipText_("minmize window").Width_(20);
|
||||
}
|
||||
public static void Btn_MoveBox(GfuiElem owner, GfuiElem target) {
|
||||
GfuiElem rv = GfuiBtn_.new_("moveBox").Owner_(owner).Text_("*").TipText_("move box").Width_(20);
|
||||
GfuiMoveElemBnd bnd = GfuiMoveElemBnd.new_();
|
||||
bnd.TargetElem_set(target);
|
||||
rv.Inject_(bnd);
|
||||
}
|
||||
public static GfuiBtn Btn_QuitWin3(GfuiElem owner) {
|
||||
return (GfuiBtn)GfuiBtn_.msg_("quitWin", owner, GfoMsg_.root_(".", GfuiElemBase.Invk_OwnerWin_cmd, GfuiWin.Invk_Quit)).Text_("X").TipText_("quit win").Width_(20);
|
||||
}
|
||||
public static void Btn_QuitWin2(GfuiElem owner, GfoMsg quitMsg) {
|
||||
GfuiBtn_.msg_("quitWin", owner, quitMsg).Text_("X").TipText_("quit win").Width_(20);
|
||||
}
|
||||
public static final GfoFactory_gfui Instance = new GfoFactory_gfui(); GfoFactory_gfui() {}
|
||||
}
|
||||
26
150_gfui/src/gplx/gfui/kits/core/GfsLibIni_gfui.java
Normal file
26
150_gfui/src/gplx/gfui/kits/core/GfsLibIni_gfui.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.langs.gfs.*;
|
||||
import gplx.gfui.ipts.*;
|
||||
public class GfsLibIni_gfui implements GfsLibIni {
|
||||
public void Ini(GfsCore core) {
|
||||
core.AddCmd(IptCfgRegy.Instance, "IptBndMgr_");
|
||||
}
|
||||
public static final GfsLibIni_gfui Instance = new GfsLibIni_gfui(); GfsLibIni_gfui() {}
|
||||
}
|
||||
113
150_gfui/src/gplx/gfui/kits/core/GfuiEnv_.java
Normal file
113
150_gfui/src/gplx/gfui/kits/core/GfuiEnv_.java
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.draws.*; import gplx.gfui.ipts.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.windows.*;
|
||||
import gplx.gfml.*; import gplx.langs.gfs.*; import gplx.core.envs.*;
|
||||
import gplx.core.envs.Env_;
|
||||
import gplx.core.envs.Op_sys;
|
||||
import gplx.core.envs.Process_adp;
|
||||
import gplx.core.threads.*;
|
||||
import java.awt.AWTKeyStroke;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.KeyboardFocusManager;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
public class GfuiEnv_ {
|
||||
static FontAdp system_font;
|
||||
public static void Exit() {if (!Env_.Mode_testing()) System.exit(0);}
|
||||
public static void Init(String[] args, String appNameAndExt, Class<?> type) {Init(args, appNameAndExt, type, true);}
|
||||
public static void Init(String[] args, String appNameAndExt, Class<?> type, boolean swingHack) {
|
||||
Env_.Init(args, appNameAndExt, type);
|
||||
if (swingHack) { // TODO_OLD: move to kit dependent functionality; WHEN: swing kit
|
||||
if (Op_sys.Cur().Tid_is_wnt()) {
|
||||
try {UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");}
|
||||
catch (ClassNotFoundException e) {e.printStackTrace();}
|
||||
catch (InstantiationException e) {e.printStackTrace();}
|
||||
catch (IllegalAccessException e) {e.printStackTrace();}
|
||||
catch (UnsupportedLookAndFeelException e) {e.printStackTrace();}
|
||||
}
|
||||
Set<AWTKeyStroke> fwdSet = new HashSet<AWTKeyStroke>(); fwdSet.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
|
||||
Set<AWTKeyStroke> bwdSet = new HashSet<AWTKeyStroke>(); bwdSet.add(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, java.awt.event.InputEvent.SHIFT_DOWN_MASK ));
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, fwdSet);
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().setDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, bwdSet);
|
||||
}
|
||||
if (!Op_sys.Cur().Tid_is_drd())
|
||||
GxwElemFactory_.winForms_();
|
||||
|
||||
// reg interruptLnr
|
||||
if (swingHack) { // TODO_OLD: move to kit dependent functionality; WHEN: swing kit
|
||||
UsrDlg_.Instance.Reg(UsrMsgWkr_.Type_Warn, GfoConsoleWin.Instance);
|
||||
UsrDlg_.Instance.Reg(UsrMsgWkr_.Type_Stop, GfuiInterruptLnr.new_());
|
||||
}
|
||||
IptBndMgr_win = IptCfg_.new_("gplx.gfui.GfuiWin");
|
||||
|
||||
// alias default dirs
|
||||
Io_mgr.Instance.AliasDir_sysEngine("app:\\", Env_.AppUrl().OwnerDir().Raw());
|
||||
|
||||
GfsCore.Instance.MsgParser_(GfoMsgParser_gfml.Instance);
|
||||
GfsCore.Instance.AddLib(GfsLibIni_core.Instance);
|
||||
GfsCore.Instance.AddLib(GfsLibIni_gfui.Instance);
|
||||
Io_url iniFile = Env_.AppUrl().GenSubFil(".gfs");
|
||||
if (Io_mgr.Instance.ExistsFil(iniFile))
|
||||
GfsCore.Instance.ExecFile(iniFile);
|
||||
}
|
||||
public static void Init_swt(String[] args, Class<?> type) {
|
||||
Env_.Init_swt(args, type);
|
||||
if (!Op_sys.Cur().Tid_is_drd()) GxwElemFactory_.winForms_();
|
||||
GfsCore.Instance.MsgParser_(GfoMsgParser_gfml.Instance);
|
||||
}
|
||||
public static void Gfs_init() {GfsCore.Instance.MsgParser_(GfoMsgParser_gfml.Instance);}
|
||||
public static IptCfg IptBndMgr_win;
|
||||
public static void DoEvents() {;}
|
||||
public static void ShowMsg(String message) {javax.swing.JOptionPane.showMessageDialog(null, message, "", javax.swing.JOptionPane.INFORMATION_MESSAGE, null);}
|
||||
public static void BringToFront(Process_adp process) {}
|
||||
public static void DoEvents(int milliseconds) {
|
||||
Thread_adp_.Sleep(milliseconds);
|
||||
}
|
||||
public static void Run(GfuiWin form) {javax.swing.SwingUtilities.invokeLater(new GfuiFormRunner(form));}
|
||||
public static FontAdp System_font() {
|
||||
try {
|
||||
if (system_font == null) {
|
||||
Font label_font = (Font)UIManager.get("Label.font");
|
||||
system_font = FontAdp.new_(label_font.getFamily(), label_font.getSize(), FontStyleAdp_.Plain);
|
||||
}
|
||||
return system_font;
|
||||
} catch (Exception e) {return FontAdp.new_("Arial", 8, FontStyleAdp_.Plain);}
|
||||
}
|
||||
public static final String Quit_commit_evt = "quit_commit_evt", Quit_notify_evt = "quit_notify_evt";
|
||||
public static final String Err_GfuiException = "gplx.dbs.GfuiException"; // TODO_OLD: used in JAVA. move
|
||||
}
|
||||
class GfuiInterruptLnr implements UsrMsgWkr {
|
||||
public void ExecUsrMsg(int type, UsrMsg umsg) {GfuiEnv_.ShowMsg(umsg.To_str());}
|
||||
public static GfuiInterruptLnr new_() {return new GfuiInterruptLnr();} GfuiInterruptLnr() {}
|
||||
}
|
||||
class GfuiFormRunner implements Runnable {
|
||||
public GfuiFormRunner(GfuiWin form) {this.form = form;} GfuiWin form;
|
||||
public void run() {
|
||||
form.Show();
|
||||
}
|
||||
}
|
||||
//#}
|
||||
20
150_gfui/src/gplx/gfui/kits/core/GfuiInvkCmd.java
Normal file
20
150_gfui/src/gplx/gfui/kits/core/GfuiInvkCmd.java
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public interface GfuiInvkCmd extends Gfo_invk, Rls_able {
|
||||
}
|
||||
21
150_gfui/src/gplx/gfui/kits/core/GfuiInvkCmd_.java
Normal file
21
150_gfui/src/gplx/gfui/kits/core/GfuiInvkCmd_.java
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public class GfuiInvkCmd_ {
|
||||
public static final String Invk_sync = "Sync";
|
||||
}
|
||||
26
150_gfui/src/gplx/gfui/kits/core/Gfui_clipboard.java
Normal file
26
150_gfui/src/gplx/gfui/kits/core/Gfui_clipboard.java
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public interface Gfui_clipboard extends Gfo_invk, Rls_able {
|
||||
void Copy(String s);
|
||||
}
|
||||
class Gfui_clipboard_null implements Gfui_clipboard {
|
||||
public void Copy(String s) {}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {return this;}
|
||||
public void Rls() {}
|
||||
}
|
||||
22
150_gfui/src/gplx/gfui/kits/core/Gfui_clipboard_.java
Normal file
22
150_gfui/src/gplx/gfui/kits/core/Gfui_clipboard_.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public class Gfui_clipboard_ {
|
||||
public static final Gfui_clipboard Null = new Gfui_clipboard_null();
|
||||
public static final String Invk_copy = "copy", Invk_select_all = "select_all";
|
||||
}
|
||||
25
150_gfui/src/gplx/gfui/kits/core/Gfui_dlg_file.java
Normal file
25
150_gfui/src/gplx/gfui/kits/core/Gfui_dlg_file.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public interface Gfui_dlg_file {
|
||||
Gfui_dlg_file Init_msg_(String v);
|
||||
Gfui_dlg_file Init_file_(String v);
|
||||
Gfui_dlg_file Init_dir_(Io_url v);
|
||||
Gfui_dlg_file Init_exts_(String... v);
|
||||
String Ask();
|
||||
}
|
||||
28
150_gfui/src/gplx/gfui/kits/core/Gfui_dlg_file_.java
Normal file
28
150_gfui/src/gplx/gfui/kits/core/Gfui_dlg_file_.java
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public class Gfui_dlg_file_ {
|
||||
public static final Gfui_dlg_file Noop = new Gfui_dlg_file_noop();
|
||||
}
|
||||
class Gfui_dlg_file_noop implements Gfui_dlg_file {
|
||||
public Gfui_dlg_file Init_msg_(String v) {return this;}
|
||||
public Gfui_dlg_file Init_file_(String v) {return this;}
|
||||
public Gfui_dlg_file Init_dir_(Io_url v) {return this;}
|
||||
public Gfui_dlg_file Init_exts_(String... v) {return this;}
|
||||
public String Ask() {return "";}
|
||||
}
|
||||
25
150_gfui/src/gplx/gfui/kits/core/Gfui_dlg_msg.java
Normal file
25
150_gfui/src/gplx/gfui/kits/core/Gfui_dlg_msg.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public interface Gfui_dlg_msg {
|
||||
Gfui_dlg_msg Init_msg_(String v);
|
||||
Gfui_dlg_msg Init_ico_(int v);
|
||||
Gfui_dlg_msg Init_btns_(int... ary);
|
||||
int Ask();
|
||||
boolean Ask(int expd);
|
||||
}
|
||||
30
150_gfui/src/gplx/gfui/kits/core/Gfui_dlg_msg_.java
Normal file
30
150_gfui/src/gplx/gfui/kits/core/Gfui_dlg_msg_.java
Normal 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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public class Gfui_dlg_msg_ {
|
||||
public static final Gfui_dlg_msg Noop = new Gfui_dlg_msg_noop();
|
||||
public static final int Ico_error = 0, Ico_information = 1, Ico_question = 2, Ico_warning = 3, Ico_working = 4;
|
||||
public static final int Btn_ok = 0, Btn_cancel = 1, Btn_yes = 2, Btn_no = 3, Retry = 4, Btn_abort = 5, Btn_ignore = 6;
|
||||
}
|
||||
class Gfui_dlg_msg_noop implements Gfui_dlg_msg {
|
||||
public Gfui_dlg_msg Init_msg_(String v) {return this;}
|
||||
public Gfui_dlg_msg Init_ico_(int v) {return this;}
|
||||
public Gfui_dlg_msg Init_btns_(int... ary) {return this;}
|
||||
public boolean Ask(int expd) {return false;}
|
||||
public int Ask() {return Int_.Min_value;}
|
||||
}
|
||||
52
150_gfui/src/gplx/gfui/kits/core/Gfui_kit.java
Normal file
52
150_gfui/src/gplx/gfui/kits/core/Gfui_kit.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.imgs.*; import gplx.gfui.controls.windows.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
|
||||
public interface Gfui_kit extends Gfo_invk {
|
||||
byte Tid();
|
||||
String Key();
|
||||
void Cfg_set(String type, String key, Object val);
|
||||
boolean Kit_mode__ready();
|
||||
void Kit_init(Gfo_usr_dlg gui_wtr);
|
||||
void Kit_run();
|
||||
void Kit_term();
|
||||
void Kit_term_cbk_(Gfo_invk_cmd cmd);
|
||||
Gfui_clipboard Clipboard();
|
||||
void Ask_ok(String grp_key, String msg_key, String fmt, Object... args);
|
||||
boolean Ask_yes_no(String grp_key, String msg_key, String fmt, Object... args);
|
||||
boolean Ask_ok_cancel(String grp_key, String msg_key, String fmt, Object... args);
|
||||
int Ask_yes_no_cancel(String grp_key, String msg_key, String fmt, Object... args);
|
||||
GfuiInvkCmd New_cmd_sync(Gfo_invk invk);
|
||||
GfuiInvkCmd New_cmd_async(Gfo_invk invk);
|
||||
GfuiWin New_win_app(String key, Keyval... args);
|
||||
GfuiWin New_win_utl(String key, GfuiWin owner, Keyval... args);
|
||||
Gfui_html New_html(String key, GfuiElem owner, Keyval... args);
|
||||
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);
|
||||
GfuiComboBox New_combo(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);
|
||||
Object New_color(int a, int r, int g, int b);
|
||||
Gfui_mnu_grp New_mnu_popup(String key, GfuiElem owner);
|
||||
Gfui_mnu_grp New_mnu_bar(String key, GfuiWin owner);
|
||||
void Set_mnu_popup(GfuiElem owner, Gfui_mnu_grp grp);
|
||||
float Calc_font_height(GfuiElem elem, String s);
|
||||
}
|
||||
32
150_gfui/src/gplx/gfui/kits/core/Gfui_kit_.java
Normal file
32
150_gfui/src/gplx/gfui/kits/core/Gfui_kit_.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public class Gfui_kit_ {
|
||||
public static final byte Mem_tid = 0, Swing_tid = 1, Swt_tid = 2, Android_tid = 3;
|
||||
public static Gfui_kit Mem() {return mem_kit;} private static final Gfui_kit mem_kit = Mem_kit.Instance;
|
||||
public static Gfui_kit Swt() {if (swt_kit == null) swt_kit = Swt_kit.Instance; return swt_kit;} private static Gfui_kit swt_kit; // NOTE: late-binding else swing apps will fail (since swt jar is not deployed)
|
||||
public static Gfui_kit Swing() {if (swing_kit == null) swing_kit = Swing_kit.Instance; return swing_kit;} private static Gfui_kit swing_kit;
|
||||
public static Gfui_kit Get_by_key(String key) {
|
||||
if (String_.Eq(key, Mem().Key())) return Mem();
|
||||
else if (String_.Eq(key, Swt().Key())) return Swt();
|
||||
else if (String_.Eq(key, Swing().Key())) return Swing();
|
||||
else throw Err_.new_unhandled(key);
|
||||
}
|
||||
public static final String Cfg_HtmlBox = "HtmlBox";
|
||||
public static final byte File_dlg_type_open = 0, File_dlg_type_save = 1;
|
||||
}
|
||||
116
150_gfui/src/gplx/gfui/kits/core/Gfui_kit_base.java
Normal file
116
150_gfui/src/gplx/gfui/kits/core/Gfui_kit_base.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.imgs.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*; import gplx.gfui.controls.customs.*; import gplx.gfui.controls.windows.*;
|
||||
public abstract class Gfui_kit_base implements Gfui_kit {
|
||||
private Keyval_hash ctor_args = new Keyval_hash();
|
||||
public abstract byte Tid();
|
||||
public abstract String Key();
|
||||
public abstract GxwElemFactory_base Factory();
|
||||
public GfuiWin Main_win() {return main_win;} public Gfui_kit Main_win_(GfuiWin v) {main_win = v; return this;} private GfuiWin main_win;
|
||||
public Gfui_clipboard Clipboard() {return Gfui_clipboard_.Null;}
|
||||
public Gfo_invk_cmd Kit_term_cbk() {return kit_term_cbk;} public void Kit_term_cbk_(Gfo_invk_cmd v) {kit_term_cbk = v;} private Gfo_invk_cmd kit_term_cbk;
|
||||
public void Cfg_set(String type, String key, Object val) {}
|
||||
public boolean Kit_mode__ready() {return true;}
|
||||
public void Kit_init(Gfo_usr_dlg gui_wtr) {}
|
||||
@gplx.Virtual public void Kit_run() {}
|
||||
@gplx.Virtual public void Kit_term() {kit_term_cbk.Exec();}
|
||||
@gplx.Virtual public void Ask_ok(String grp_key, String msg_key, String fmt, Object... args) {}
|
||||
public boolean Ask_yes_no(String grp_key, String msg_key, String fmt, Object... args) {return false;}
|
||||
public int Ask_yes_no_cancel(String grp_key, String msg_key, String fmt, Object... args) {return Gfui_dlg_msg_.Btn_cancel;}
|
||||
public boolean Ask_ok_cancel(String grp_key, String msg_key, String fmt, Object... args) {return false;}
|
||||
public void Btn_img_(GfuiBtn btn, IconAdp v) {}
|
||||
public GfuiInvkCmd New_cmd_sync(Gfo_invk invk) {return new Gfui_kit_cmd_sync(invk);}
|
||||
public GfuiInvkCmd New_cmd_async(Gfo_invk invk) {return new Gfui_kit_cmd_async(invk);}
|
||||
public GfuiWin New_win_app(String key, Keyval... args) {
|
||||
GfuiWin rv = GfuiWin_.kit_(this, key, this.Factory().win_app_(), ctor_args);
|
||||
main_win = rv;
|
||||
return rv;
|
||||
}
|
||||
public GfuiWin New_win_utl(String key, GfuiWin owner, Keyval... args) {return GfuiWin_.kit_(this, key, this.Factory().win_tool_(ctor_args), ctor_args);}
|
||||
@gplx.Virtual public Gfui_html New_html(String key, GfuiElem owner, Keyval... args) {
|
||||
Gfui_html rv = Gfui_html.kit_(this, key, this.New_html_impl(), ctor_args);
|
||||
owner.SubElems().Add(rv);
|
||||
return rv;
|
||||
}
|
||||
public Gfui_tab_mgr New_tab_mgr(String key, GfuiElem owner, Keyval... args) {
|
||||
Gfui_tab_mgr rv = Gfui_tab_mgr.kit_(this, key, this.New_tab_mgr_impl(), ctor_args);
|
||||
owner.SubElems().Add(rv);
|
||||
return rv;
|
||||
}
|
||||
public Gfui_tab_itm New_tab_itm(String key, Gfui_tab_mgr owner, Keyval... args) {
|
||||
Gfui_tab_itm rv = Gfui_tab_itm.kit_(this, key, this.New_tab_itm_impl(), ctor_args);
|
||||
owner.SubElems().Add(rv);
|
||||
return rv;
|
||||
}
|
||||
public GfuiTextBox New_text_box(String key, GfuiElem owner, Keyval... args) {
|
||||
GfuiTextBox rv = GfuiTextBox_.kit_(this, key, this.Factory().text_fld_(), ctor_args);
|
||||
owner.SubElems().Add(rv);
|
||||
return rv;
|
||||
}
|
||||
@gplx.Virtual public GfuiBtn New_btn(String key, GfuiElem owner, Keyval... args) {
|
||||
GfuiBtn rv = GfuiBtn_.kit_(this, key, New_btn_impl(), ctor_args);
|
||||
owner.SubElems().Add(rv);
|
||||
return rv;
|
||||
}
|
||||
@gplx.Virtual public GfuiComboBox New_combo(String key, GfuiElem owner, Keyval... args) {
|
||||
GfuiComboBox rv = GfuiComboBox.kit_(this, key, New_combo_impl(), ctor_args);
|
||||
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);
|
||||
return rv;
|
||||
}
|
||||
public void Set_mnu_popup(GfuiElem owner, Gfui_mnu_grp grp) {}
|
||||
protected abstract Gxw_html New_html_impl();
|
||||
protected abstract Gxw_tab_mgr New_tab_mgr_impl();
|
||||
protected abstract Gxw_tab_itm New_tab_itm_impl();
|
||||
protected abstract GxwElem New_btn_impl();
|
||||
protected abstract GxwElem New_combo_impl();
|
||||
@gplx.Virtual public Gfui_dlg_file New_dlg_file(byte type, String msg) {return Gfui_dlg_file_.Noop;}
|
||||
@gplx.Virtual public Gfui_dlg_msg New_dlg_msg(String msg) {return Gfui_dlg_msg_.Noop;}
|
||||
@gplx.Virtual public Gfui_mnu_grp New_mnu_popup(String key, GfuiElem owner) {return Gfui_mnu_grp_.Noop;}
|
||||
@gplx.Virtual public Gfui_mnu_grp New_mnu_bar(String key, GfuiWin owner) {return Gfui_mnu_grp_.Noop;}
|
||||
public abstract ImageAdp New_img_load(Io_url url);
|
||||
public Object New_color(int a, int r, int g, int b) {return null;}
|
||||
public float Calc_font_height(GfuiElem elem, String s) {return 13;}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
class Gfui_kit_cmd_sync implements GfuiInvkCmd {
|
||||
public Gfui_kit_cmd_sync(Gfo_invk target) {this.target = target;} private Gfo_invk target;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
return target.Invk(ctx, ikey, k, m);
|
||||
}
|
||||
public void Rls() {target = null;}
|
||||
}
|
||||
class Gfui_kit_cmd_async implements GfuiInvkCmd {
|
||||
public Gfui_kit_cmd_async(Gfo_invk target) {this.target = target;} private Gfo_invk target;
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
return target.Invk(ctx, ikey, k, m);
|
||||
}
|
||||
public void Rls() {target = null;}
|
||||
}
|
||||
30
150_gfui/src/gplx/gfui/kits/core/Gfui_mnu_grp.java
Normal file
30
150_gfui/src/gplx/gfui/kits/core/Gfui_mnu_grp.java
Normal 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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.imgs.*;
|
||||
public interface Gfui_mnu_grp extends Gfui_mnu_itm {
|
||||
String Root_key();
|
||||
void Itms_clear();
|
||||
boolean Disposed();
|
||||
Gfui_mnu_itm Itms_add_btn_cmd (String txt, ImageAdp img, Gfo_invk invk, String invk_cmd);
|
||||
Gfui_mnu_itm Itms_add_btn_msg (String txt, ImageAdp img, Gfo_invk invk, Gfo_invk_root_wkr root_wkr, GfoMsg msg);
|
||||
Gfui_mnu_itm Itms_add_chk_msg (String txt, ImageAdp img, Gfo_invk invk, Gfo_invk_root_wkr root_wkr, GfoMsg msg_n, GfoMsg msg_y);
|
||||
Gfui_mnu_itm Itms_add_rdo_msg (String txt, ImageAdp img, Gfo_invk invk, Gfo_invk_root_wkr root_wkr, GfoMsg msg);
|
||||
Gfui_mnu_grp Itms_add_grp (String txt, ImageAdp img);
|
||||
Gfui_mnu_itm Itms_add_separator();
|
||||
}
|
||||
40
150_gfui/src/gplx/gfui/kits/core/Gfui_mnu_grp_.java
Normal file
40
150_gfui/src/gplx/gfui/kits/core/Gfui_mnu_grp_.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.imgs.*;
|
||||
public class Gfui_mnu_grp_ {
|
||||
public static final Gfui_mnu_grp Noop = new Gfui_mnu_grp_noop();
|
||||
}
|
||||
class Gfui_mnu_grp_noop implements Gfui_mnu_grp {
|
||||
public String Uid() {return "";}
|
||||
public int Tid() {return Gfui_mnu_itm_.Tid_grp;}
|
||||
public boolean Enabled() {return true;} public void Enabled_(boolean v) {}
|
||||
public boolean Disposed() {return false;}
|
||||
public String Text() {return null;} public void Text_(String v) {}
|
||||
public ImageAdp Img() {return null;} public void Img_(ImageAdp v) {}
|
||||
public boolean Selected() {return true;} public void Selected_(boolean v) {}
|
||||
public String Root_key() {return "null";}
|
||||
public Object Under() {return null;}
|
||||
public void Itms_clear() {}
|
||||
public Gfui_mnu_itm Itms_add_btn_cmd (String txt, ImageAdp img, Gfo_invk invk, String invk_cmd) {return Gfui_mnu_itm_null.Null;}
|
||||
public Gfui_mnu_itm Itms_add_btn_msg (String txt, ImageAdp img, Gfo_invk invk, Gfo_invk_root_wkr root_wkr, GfoMsg invk_msg) {return Gfui_mnu_itm_null.Null;}
|
||||
public Gfui_mnu_itm Itms_add_chk_msg (String txt, ImageAdp img, Gfo_invk invk, Gfo_invk_root_wkr root_wkr, GfoMsg msg_n, GfoMsg msg_y) {return Gfui_mnu_itm_null.Null;}
|
||||
public Gfui_mnu_itm Itms_add_rdo_msg (String txt, ImageAdp img, Gfo_invk invk, Gfo_invk_root_wkr root_wkr, GfoMsg msg) {return Gfui_mnu_itm_null.Null;}
|
||||
public Gfui_mnu_grp Itms_add_grp(String txt, ImageAdp img) {return Gfui_mnu_grp_.Noop;}
|
||||
public Gfui_mnu_itm Itms_add_separator() {return Gfui_mnu_itm_null.Null;}
|
||||
}
|
||||
38
150_gfui/src/gplx/gfui/kits/core/Gfui_mnu_itm.java
Normal file
38
150_gfui/src/gplx/gfui/kits/core/Gfui_mnu_itm.java
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.imgs.*;
|
||||
public interface Gfui_mnu_itm {
|
||||
int Tid();
|
||||
String Uid();
|
||||
boolean Enabled(); void Enabled_(boolean v);
|
||||
String Text(); void Text_(String v);
|
||||
ImageAdp Img(); void Img_(ImageAdp v);
|
||||
boolean Selected(); void Selected_(boolean v);
|
||||
Object Under();
|
||||
}
|
||||
class Gfui_mnu_itm_null implements Gfui_mnu_itm {
|
||||
public String Uid() {return "";}
|
||||
public int Tid() {return Gfui_mnu_itm_.Tid_btn;}
|
||||
public boolean Enabled() {return true;} public void Enabled_(boolean v) {}
|
||||
public String Text() {return text;} public void Text_(String v) {text = v;} private String text;
|
||||
public ImageAdp Img() {return img;} public void Img_(ImageAdp v) {img = v;} private ImageAdp img;
|
||||
public boolean Selected() {return true;} public void Selected_(boolean v) {}
|
||||
public Object Under() {return null;}
|
||||
public static final Gfui_mnu_itm_null Null = new Gfui_mnu_itm_null(); Gfui_mnu_itm_null() {}
|
||||
}
|
||||
22
150_gfui/src/gplx/gfui/kits/core/Gfui_mnu_itm_.java
Normal file
22
150_gfui/src/gplx/gfui/kits/core/Gfui_mnu_itm_.java
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public class Gfui_mnu_itm_ {
|
||||
public static String Gen_uid() {return "mnu_" + Int_.To_str(++uid_next);} private static int uid_next = 0;
|
||||
public static final int Tid_nil = 0, Tid_grp = 1, Tid_spr = 2, Tid_btn = 3, Tid_chk = 4, Tid_rdo = 5;
|
||||
}
|
||||
69
150_gfui/src/gplx/gfui/kits/core/Mem_html.java
Normal file
69
150_gfui/src/gplx/gfui/kits/core/Mem_html.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.draws.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
|
||||
class Mem_html extends GxwTextMemo_lang implements Gxw_html { public void Html_invk_src_(Gfo_evt_itm v) {}
|
||||
public void Html_doc_html_load_by_mem(String s) {
|
||||
// this.Core().ForeColor_set(plainText ? ColorAdp_.Black : ColorAdp_.Gray);
|
||||
s = String_.Replace(s, "\r", "");
|
||||
s = String_.Replace(s, "\n", "\r\n");
|
||||
this.TextVal_set(s);
|
||||
this.SelBgn_set(0);
|
||||
html_doc_html_load_tid = Gxw_html_load_tid_.Tid_mem;
|
||||
}
|
||||
public void Html_doc_html_load_by_url(Io_url path, String html) {
|
||||
html_doc_html_load_tid = Gxw_html_load_tid_.Tid_url;
|
||||
}
|
||||
public byte Html_doc_html_load_tid() {return html_doc_html_load_tid;} private byte html_doc_html_load_tid;
|
||||
public void Html_doc_html_load_tid_(byte v) {html_doc_html_load_tid = v;}
|
||||
public String Html_js_eval_script(String script) {return "";}
|
||||
public Object Html_js_eval_script_as_obj(String script) {return "";}
|
||||
public String Html_js_send_json(String name, String data) {return "";}
|
||||
String ExtractAtr(String key, String txt, int pos) {
|
||||
int key_pos = String_.FindBwd(txt, key, pos); if (key_pos == String_.Find_none) return null;
|
||||
int q0 = String_.FindFwd(txt, "\"", key_pos); if (q0 == String_.Find_none) return null;
|
||||
int q1 = String_.FindFwd(txt, "\"", q0 + 1); if (q1 == String_.Find_none) return null;
|
||||
if (!Int_.Between(pos, q0, q1)) return null; // current pos is not between nearest quotes
|
||||
return String_.Mid(txt, q0 + 1, q1);
|
||||
}
|
||||
public void Html_js_enabled_(boolean v) {}
|
||||
public String Html_js_eval_proc_as_str(String proc, Object... args) {return "not implemented by mem_html";}
|
||||
public boolean Html_js_eval_proc_as_bool(String proc, Object... args) {return false;}
|
||||
public void Html_js_cbks_add(String js_func_name, Gfo_invk invk) {}
|
||||
public void Html_dispose() {}
|
||||
public Mem_html() {
|
||||
this.ctor_MsTextBoxMultiline_();
|
||||
}
|
||||
}
|
||||
class Mem_tab_mgr extends GxwElem_mock_base implements Gxw_tab_mgr { public ColorAdp Btns_selected_color() {return btns_selected_color;} public void Btns_selected_color_(ColorAdp v) {btns_selected_color = v;} private ColorAdp btns_selected_color;
|
||||
public ColorAdp Btns_unselected_color() {return btns_unselected_color;} public void Btns_unselected_color_(ColorAdp v) {btns_unselected_color = v;} private ColorAdp btns_unselected_color;
|
||||
public Gxw_tab_itm Tabs_add(Gfui_tab_itm_data tab_data) {return new Mem_tab_itm();}
|
||||
public void Tabs_select_by_idx(int i) {}
|
||||
public void Tabs_close_by_idx(int i) {}
|
||||
public void Tabs_switch(int src, int trg) {}
|
||||
public int Btns_height() {return 0;} public void Btns_height_(int v) {}
|
||||
public boolean Btns_place_on_top() {return false;} public void Btns_place_on_top_(boolean v) {}
|
||||
public boolean Btns_curved() {return false;} public void Btns_curved_(boolean v) {}
|
||||
public boolean Btns_close_visible() {return false;} public void Btns_close_visible_(boolean v) {}
|
||||
public boolean Btns_unselected_close_visible() {return false;} public void Btns_unselected_close_visible_(boolean v) {}
|
||||
}
|
||||
class Mem_tab_itm extends GxwElem_mock_base implements Gxw_tab_itm { public void Subs_add(GfuiElem sub) {}
|
||||
public Gfui_tab_itm_data Tab_data() {return tab_data;} private Gfui_tab_itm_data tab_data = new Gfui_tab_itm_data("null", -1);
|
||||
public String Tab_name() {return tab_name;} public void Tab_name_(String v) {tab_name = v;} private String tab_name;
|
||||
public String Tab_tip_text() {return tab_tip_text;} public void Tab_tip_text_(String v) {tab_tip_text = v;} private String tab_tip_text;
|
||||
}
|
||||
40
150_gfui/src/gplx/gfui/kits/core/Mem_kit.java
Normal file
40
150_gfui/src/gplx/gfui/kits/core/Mem_kit.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.imgs.*; import gplx.gfui.controls.gxws.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*;
|
||||
public class Mem_kit extends Gfui_kit_base {
|
||||
@Override public byte Tid() {return Gfui_kit_.Mem_tid;}
|
||||
@Override public String Key() {return "mem";}
|
||||
@Override public GxwElemFactory_base Factory() {return factory;} private GxwElemFactory_cls_mock factory = new GxwElemFactory_cls_mock();
|
||||
public void New_html_impl_prototype_(Gxw_html v) {html_impl_prototype = v;} private Gxw_html html_impl_prototype;
|
||||
@Override public Gfui_html New_html(String key, GfuiElem owner, Keyval... args) {
|
||||
if (html_impl_prototype == null)
|
||||
return super.New_html(key, owner, args);
|
||||
else {
|
||||
Gfui_html rv = Gfui_html.mem_(key, html_impl_prototype);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
@Override protected Gxw_html New_html_impl() {return html_impl_prototype == null ? new Mem_html(): html_impl_prototype;}
|
||||
@Override protected Gxw_tab_mgr New_tab_mgr_impl() {return new Mem_tab_mgr();}
|
||||
@Override protected Gxw_tab_itm New_tab_itm_impl() {return new Mem_tab_itm();}
|
||||
@Override protected GxwElem New_btn_impl() {return factory.control_();}
|
||||
@Override protected GxwElem New_combo_impl() {return factory.comboBox_();}
|
||||
@Override public ImageAdp New_img_load(Io_url url) {return ImageAdp_null.Instance;}
|
||||
public static final Mem_kit Instance = new Mem_kit(); Mem_kit() {}
|
||||
}
|
||||
36
150_gfui/src/gplx/gfui/kits/core/Swing_kit.java
Normal file
36
150_gfui/src/gplx/gfui/kits/core/Swing_kit.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.imgs.*; import gplx.gfui.controls.gxws.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
public class Swing_kit extends Gfui_kit_base {
|
||||
private Bry_fmtr ask_fmtr = Bry_fmtr.new_(); private Bry_bfr ask_bfr = Bry_bfr_.New();
|
||||
@Override public byte Tid() {return Gfui_kit_.Swing_tid;}
|
||||
@Override public String Key() {return "swing";}
|
||||
@Override public GxwElemFactory_base Factory() {return factory;} private GxwElemFactory_cls_lang factory = new GxwElemFactory_cls_lang();
|
||||
@Override public void Ask_ok(String grp_key, String msg_key, String fmt, Object... args) {GfuiEnv_.ShowMsg(ask_fmtr.Bld_str_many(ask_bfr, fmt, args));}
|
||||
@Override public void Kit_run() {GfuiEnv_.Run(this.Main_win());}
|
||||
@Override public void Kit_term() {this.Kit_term_cbk().Exec(); GfuiEnv_.Exit();}
|
||||
@Override public ImageAdp New_img_load(Io_url url) {return ImageAdp_.file_(url);}
|
||||
@Override protected Gxw_html New_html_impl() {return new Mem_html();}
|
||||
@Override protected Gxw_tab_mgr New_tab_mgr_impl() {return new Mem_tab_mgr();}
|
||||
@Override protected Gxw_tab_itm New_tab_itm_impl() {return new Mem_tab_itm();}
|
||||
@Override protected GxwElem New_btn_impl() {return factory.control_();}
|
||||
@Override protected GxwElem New_combo_impl() {return factory.control_();}
|
||||
public static final Swing_kit Instance = new Swing_kit(); Swing_kit() {}
|
||||
}
|
||||
372
150_gfui/src/gplx/gfui/kits/core/Swt_kit.java
Normal file
372
150_gfui/src/gplx/gfui/kits/core/Swt_kit.java
Normal file
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.core.brys.fmtrs.*;
|
||||
import gplx.gfui.imgs.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.standards.*; import gplx.gfui.controls.customs.*; import gplx.gfui.controls.windows.*;
|
||||
import gplx.gfui.kits.swts.*;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.swt.widgets.ToolItem;
|
||||
import org.eclipse.swt.browser.Browser;
|
||||
import org.eclipse.swt.dnd.Clipboard;
|
||||
import org.eclipse.swt.dnd.TextTransfer;
|
||||
import org.eclipse.swt.dnd.Transfer;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Cursor;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
import org.eclipse.swt.graphics.FontData;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
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.core.threads.*;
|
||||
import gplx.gfui.controls.customs.GfuiStatusBox;
|
||||
import gplx.gfui.controls.customs.GfuiStatusBox_;
|
||||
import gplx.gfui.controls.elems.GfuiElem;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.GxwTextFld;
|
||||
import gplx.gfui.controls.standards.*;
|
||||
import gplx.gfui.controls.windows.GfoConsoleWin;
|
||||
import gplx.gfui.controls.windows.GfuiWin;
|
||||
import gplx.gfui.controls.windows.GfuiWin_;
|
||||
import gplx.gfui.draws.*;
|
||||
import gplx.gfui.imgs.*;
|
||||
public class Swt_kit implements Gfui_kit {
|
||||
private final Keyval_hash ctor_args = new Keyval_hash(); private final Keyval_hash ctor_args_null = new Keyval_hash();
|
||||
private final Hash_adp kit_args = Hash_adp_.New(); private Swt_msg_wkr_stop msg_wkr_stop;
|
||||
private Gfo_usr_dlg gui_wtr; private String xul_runner_path = null;
|
||||
private final Bry_fmtr ask_fmtr = Bry_fmtr.new_().Fail_when_invalid_escapes_(false); private final Bry_bfr ask_bfr = Bry_bfr_.New();
|
||||
private final Object thread_lock = new Object();
|
||||
public byte Tid() {return Gfui_kit_.Swt_tid;}
|
||||
public String Key() {return "swt";}
|
||||
public Display Swt_display() {return display;} private Display display;
|
||||
public Shell Swt_shell() {return shell;} private Shell shell;
|
||||
public Gfui_clipboard Clipboard() {return clipboard;} private Swt_clipboard clipboard;
|
||||
public int Kit_mode() {synchronized (thread_lock) {return mode;}} private int mode = Swt_kit_mode.Tid_ctor;
|
||||
public void Kit_mode_(int v) {synchronized (thread_lock) {mode = v;}}
|
||||
public boolean Kit_mode__ready() {return Kit_mode() == Swt_kit_mode.Tid_ready;}
|
||||
public boolean Kit_mode__term() {return Kit_mode() == Swt_kit_mode.Tid_term;}
|
||||
public boolean Kit_sync_cmd_exists() {synchronized (thread_lock) {return sync_cmd_list.Count() != 0;}} private final List_adp sync_cmd_list = List_adp_.New();
|
||||
public void Kit_sync_cmd_add(Swt_gui_cmd cmd) {synchronized (thread_lock) {sync_cmd_list.Add(cmd);}}
|
||||
public void Kit_sync_cmd_del(Swt_gui_cmd cmd) {synchronized (thread_lock) {sync_cmd_list.Del(cmd);}}
|
||||
public Gfo_invk_cmd Kit_term_cbk() {return term_cbk;} public void Kit_term_cbk_(Gfo_invk_cmd v) {this.term_cbk = v;} private Gfo_invk_cmd term_cbk = Gfo_invk_cmd.Noop;
|
||||
public void Kit_init(Gfo_usr_dlg gui_wtr) {
|
||||
this.gui_wtr = gui_wtr;
|
||||
this.msg_wkr_stop = new Swt_msg_wkr_stop(this, gui_wtr);
|
||||
this.display = new Display();
|
||||
this.clipboard = new Swt_clipboard(display);
|
||||
UsrDlg_.Instance.Reg(UsrMsgWkr_.Type_Warn, GfoConsoleWin.Instance);
|
||||
UsrDlg_.Instance.Reg(UsrMsgWkr_.Type_Stop, msg_wkr_stop);
|
||||
if (xul_runner_path != null) System.setProperty("org.eclipse.swt.browser.XULRunnerPath", xul_runner_path);
|
||||
this.Kit_mode_(Swt_kit_mode.Tid_ready);
|
||||
gui_wtr.Log_many("", "", "swt.kit.init.done");
|
||||
}
|
||||
public void Kit_run() {
|
||||
shell.addListener(SWT.Close, new Swt_shell_close_lnr(this, gui_wtr));
|
||||
shell.open();
|
||||
Cursor cursor = new Cursor(display, SWT.CURSOR_ARROW);
|
||||
shell.setCursor(cursor); // set cursor to hand else cursor defaults to Hourglass until mouse is moved; DATE: 2014-01-31
|
||||
boolean first = true;
|
||||
while (!shell.isDisposed()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
// shell.setMinimized(true);
|
||||
shell.setActive();
|
||||
shell.forceFocus();
|
||||
}
|
||||
if (!display.readAndDispatch())
|
||||
display.sleep();
|
||||
}
|
||||
gui_wtr.Log_many("", "", "swt.kit.term:bgn");
|
||||
cursor.dispose(); gui_wtr.Log_many("", "", "swt.kit.term:cursor");
|
||||
}
|
||||
public void Kit_term() {
|
||||
clipboard.Rls(); gui_wtr.Log_many("", "", "swt.kit.term:clipboard");
|
||||
shell.close();
|
||||
}
|
||||
public void Cfg_set(String type, String key, Object val) {
|
||||
// XulRunnerPath gets set immediately; do not add to widget_cfg_hash
|
||||
if (String_.Eq(type, Gfui_kit_.Cfg_HtmlBox) && String_.Eq(key, "XulRunnerPath")) {
|
||||
this.xul_runner_path = (String)val;
|
||||
return;
|
||||
}
|
||||
// add kv to widget_cfg_hash; new controls will get properties from cfg_hash
|
||||
Keyval_hash widget_cfg_hash = (Keyval_hash)kit_args.Get_by(type);
|
||||
if (widget_cfg_hash == null) {
|
||||
widget_cfg_hash = new Keyval_hash();
|
||||
kit_args.Add(type, widget_cfg_hash);
|
||||
}
|
||||
widget_cfg_hash.Add_if_dupe_use_nth(key, val);
|
||||
}
|
||||
public boolean Ask_yes_no(String grp_key, String msg_key, String fmt, Object... args) {
|
||||
Swt_dlg_msg dlg = (Swt_dlg_msg)New_dlg_msg(ask_fmtr.Bld_str_many(ask_bfr, fmt, args)).Init_btns_(Gfui_dlg_msg_.Btn_yes, Gfui_dlg_msg_.Btn_no).Init_ico_(Gfui_dlg_msg_.Ico_question);
|
||||
display.syncExec(dlg);
|
||||
return dlg.Ask_rslt == Gfui_dlg_msg_.Btn_yes;
|
||||
}
|
||||
public boolean Ask_ok_cancel(String grp_key, String msg_key, String fmt, Object... args) {
|
||||
Swt_dlg_msg dlg = (Swt_dlg_msg)New_dlg_msg(ask_fmtr.Bld_str_many(ask_bfr, fmt, args)).Init_btns_(Gfui_dlg_msg_.Btn_ok, Gfui_dlg_msg_.Btn_cancel).Init_ico_(Gfui_dlg_msg_.Ico_question);
|
||||
display.syncExec(dlg);
|
||||
return dlg.Ask_rslt == Gfui_dlg_msg_.Btn_ok;
|
||||
}
|
||||
public int Ask_yes_no_cancel(String grp_key, String msg_key, String fmt, Object... args) {
|
||||
Swt_dlg_msg dlg = (Swt_dlg_msg)New_dlg_msg(ask_fmtr.Bld_str_many(ask_bfr, fmt, args)).Init_btns_(Gfui_dlg_msg_.Btn_yes, Gfui_dlg_msg_.Btn_no, Gfui_dlg_msg_.Btn_cancel).Init_ico_(Gfui_dlg_msg_.Ico_question);
|
||||
display.syncExec(dlg);
|
||||
return dlg.Ask_rslt;
|
||||
}
|
||||
public void Ask_ok(String grp_key, String msg_key, String fmt, Object... args) {
|
||||
Swt_dlg_msg dlg = (Swt_dlg_msg)New_dlg_msg(ask_fmtr.Bld_str_many(ask_bfr, fmt, args)).Init_btns_(Gfui_dlg_msg_.Btn_ok).Init_ico_(Gfui_dlg_msg_.Ico_information);
|
||||
display.syncExec(dlg);
|
||||
}
|
||||
public GfuiInvkCmd New_cmd_sync (Gfo_invk invk) {return new Swt_gui_cmd(this, gui_wtr, display, invk, Bool_.N);}
|
||||
public GfuiInvkCmd New_cmd_async(Gfo_invk 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_app(String key, Keyval... args) {
|
||||
Swt_win win = new Swt_win(display);
|
||||
this.shell = win.UnderShell();
|
||||
shell.setLayout(null);
|
||||
return GfuiWin_.kit_(this, key, win, ctor_args_null);
|
||||
}
|
||||
public GfuiBtn New_btn(String key, GfuiElem owner, Keyval... args) {
|
||||
GfuiBtn rv = GfuiBtn_.kit_(this, key, new Swt_btn_no_border(Swt_control_.cast_or_fail(owner), ctor_args), ctor_args);
|
||||
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
|
||||
Keyval_hash html_cfg_args = (Keyval_hash)kit_args.Get_by(Gfui_kit_.Cfg_HtmlBox);
|
||||
if (html_cfg_args != null) {
|
||||
Keyval browser_type = html_cfg_args.Get_kvp_or_null(Cfg_Html_BrowserType);
|
||||
if (browser_type != null) ctor_args.Add(browser_type);
|
||||
}
|
||||
Swt_html swt_html = new Swt_html(this, Swt_control_.cast_or_fail(owner), ctor_args);
|
||||
Gfui_html gfui_html = Gfui_html.kit_(this, key, swt_html, ctor_args);
|
||||
swt_html.Under_control().addMenuDetectListener(new Swt_lnr__menu_detect(this, gfui_html));
|
||||
gfui_html.Owner_(owner);
|
||||
swt_html.Delete_elems_(owner, gfui_html);
|
||||
swt_html.Evt_mgr_(gfui_html.Evt_mgr());
|
||||
return gfui_html;
|
||||
}
|
||||
public Gfui_tab_mgr New_tab_mgr(String key, GfuiElem owner, Keyval... args) {
|
||||
ctor_args.Clear();
|
||||
Swt_tab_mgr rv_swt = new Swt_tab_mgr(this, Swt_control_.cast_or_fail(owner), ctor_args);
|
||||
Gfui_tab_mgr rv = Gfui_tab_mgr.kit_(this, key, rv_swt, ctor_args);
|
||||
rv.Owner_(owner);
|
||||
rv_swt.Evt_mgr_(rv.Evt_mgr());
|
||||
return rv;
|
||||
}
|
||||
public GfuiTextBox New_text_box(String key, GfuiElem owner, Keyval... args) {
|
||||
ctor_args.Clear();
|
||||
int args_len = args.length;
|
||||
for (int i = 0; i < args_len; i++)
|
||||
ctor_args.Add(args[i]);
|
||||
boolean border_on = Bool_.cast(ctor_args.Get_val_or(GfuiTextBox.CFG_border_on_, true));
|
||||
GxwTextFld under = new Swt_text_w_border(Swt_control_.cast_or_fail(owner), New_color(border_on ? ColorAdp_.LightGray : ColorAdp_.White), ctor_args);
|
||||
GfuiTextBox rv = GfuiTextBox_.kit_(this, key, under, ctor_args);
|
||||
rv.Owner_(owner);
|
||||
ctor_args.Clear();
|
||||
return rv;
|
||||
}
|
||||
public GfuiComboBox New_combo(String key, GfuiElem owner, Keyval... args) {
|
||||
Swt_combo_ctrl rv_swt = new Swt_combo_ctrl(Swt_control_.cast_or_fail(owner), this.New_color(ColorAdp_.LightGray), ctor_args);
|
||||
GfuiComboBox rv = GfuiComboBox.kit_(this, key, rv_swt, ctor_args);
|
||||
rv.Owner_(owner);
|
||||
rv_swt.Evt_mgr_(rv.Evt_mgr());
|
||||
return rv;
|
||||
}
|
||||
public GfuiStatusBox New_status_box(String key, GfuiElem owner, Keyval... args) {
|
||||
ctor_args.Clear();
|
||||
GfuiStatusBox rv = GfuiStatusBox_.kit_(this, key, new Swt_text(Swt_control_.cast_or_fail(owner), ctor_args));
|
||||
rv.Owner_(owner);
|
||||
return rv;
|
||||
}
|
||||
public Gfui_dlg_file New_dlg_file(byte type, String msg) {return new Swt_dlg_file(type, shell).Init_msg_(msg);}
|
||||
public Gfui_dlg_msg New_dlg_msg(String msg) {return new Swt_dlg_msg(shell).Init_msg_(msg);}
|
||||
public ImageAdp New_img_load(Io_url url) {
|
||||
if (url == Io_url_.Empty) return ImageAdp_.Null;
|
||||
Image img = new Image(display, url.Raw());
|
||||
Rectangle rect = img.getBounds();
|
||||
return new Swt_img(this, img, rect.width, rect.height).Url_(url);
|
||||
}
|
||||
public Color New_color(ColorAdp v) {return (Color)New_color(v.Alpha(), v.Red(), v.Green(), v.Blue());}
|
||||
public Object New_color(int a, int r, int g, int b) {return new Color(display, r, g, b);}
|
||||
public Gfui_mnu_grp New_mnu_popup(String key, GfuiElem owner) {return Swt_popup_grp.new_popup(key, owner);}
|
||||
public Gfui_mnu_grp New_mnu_bar(String key, GfuiWin owner) {return Swt_popup_grp.new_bar(key, owner);}
|
||||
public float Calc_font_height(GfuiElem elem, String s) {
|
||||
if (String_.Len_eq_0(s)) return 8;
|
||||
try {
|
||||
String old_text = elem.Text();
|
||||
elem.Text_(s);
|
||||
float rv = ((Swt_text_w_border)(elem.UnderElem())).Under_text().getFont().getFontData()[0].height;
|
||||
elem.Text_(old_text); // was shell.setText(old_text); DATE:2014-07-25
|
||||
return rv;
|
||||
}
|
||||
catch (Exception e) {
|
||||
Gfo_usr_dlg_.Instance.Warn_many("", "", "error while calculating font height; err=~{0}", Err_.Message_gplx_full(e));
|
||||
return 8;
|
||||
}
|
||||
}
|
||||
public void Set_mnu_popup(GfuiElem owner, Gfui_mnu_grp grp) {
|
||||
Control control = Swt_control_.cast_or_fail(owner).Under_menu_control();
|
||||
Swt_popup_grp popup = (Swt_popup_grp)grp;
|
||||
control.setMenu(popup.Under_menu());
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (String_.Eq(k, Invk_Cfg_add)) {
|
||||
String type = m.ReadStrOr("type", "");
|
||||
String key = m.ReadStrOr("key", "");
|
||||
String val = m.ReadStrOr("val", "");
|
||||
if (ctx.Deny()) return this;
|
||||
if (String_.Eq(type, Gfui_kit_.Cfg_HtmlBox)) {
|
||||
if (String_.Eq(key, "XulRunnerPath"))
|
||||
xul_runner_path = val;
|
||||
else if (String_.Eq(key, Swt_kit.Cfg_Html_BrowserType))
|
||||
Cfg_set(type, Swt_kit.Cfg_Html_BrowserType, Cfg_Html_BrowserType_parse(val));
|
||||
}
|
||||
}
|
||||
else if (String_.Eq(k, Invk_ask_file)) return this.New_dlg_file(Gfui_kit_.File_dlg_type_open, m.Args_getAt(0).Val_to_str_or_empty()).Ask();
|
||||
else if (String_.Eq(k, Invk_shell_close)) shell.close();
|
||||
return this;
|
||||
}
|
||||
public static final String Invk_Cfg_add = "Cfg_add", Invk_ask_file = "ask_file"; // private or public?
|
||||
public static final String Invk_shell_close = "shell_close"; // public
|
||||
public static final Swt_kit Instance = new Swt_kit(); private Swt_kit() {} // singleton b/c of following line "In particular, some platforms which SWT supports will not allow more than one active display" (http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/Display.html)
|
||||
public static final String Cfg_Html_BrowserType = "BrowserType";
|
||||
public static int Cfg_Html_BrowserType_parse(String v) {
|
||||
if (String_.Eq(v, "mozilla")) return Swt_html.Browser_tid_mozilla;
|
||||
else if (String_.Eq(v, "webkit")) return Swt_html.Browser_tid_webkit;
|
||||
else return Swt_html.Browser_tid_none;
|
||||
}
|
||||
public static FontAdp Control_font_get(Font font, GxwCore_base owner) {
|
||||
FontData fontData = font.getFontData()[0];
|
||||
FontAdp rv = FontAdp.new_(fontData.getName(), fontData.getHeight(), FontStyleAdp_.lang_(fontData.getStyle())); // NOTE: swt style constants match swing
|
||||
rv.OwnerGxwCore_(owner);
|
||||
return rv;
|
||||
}
|
||||
public static void Control_font_set(FontAdp font, GxwCore_base owner, Control control) {
|
||||
font.OwnerGxwCore_(owner);
|
||||
FontData fontData = new FontData(font.Name(), (int)font.Size(), font.Style().Val());
|
||||
Font rv = new Font(control.getDisplay(), fontData);
|
||||
control.setFont(rv);
|
||||
}
|
||||
}
|
||||
class Swt_shell_close_lnr implements Listener, Gfo_invk {
|
||||
private final Swt_kit kit; private final Gfo_usr_dlg usr_dlg;
|
||||
public Swt_shell_close_lnr(Swt_kit kit, Gfo_usr_dlg usr_dlg) {this.kit = kit; this.usr_dlg = usr_dlg;}
|
||||
@Override public void handleEvent(Event event) {
|
||||
if (kit.Kit_mode__term()) return; // NOTE: will be term if called again from wait_for_sync_cmd
|
||||
kit.Kit_mode_(Swt_kit_mode.Tid_term); // NOTE: must mark kit as shutting down, else writing to status_bar will create stack overflow; DATE:2014-05-05
|
||||
boolean rslt = Bool_.cast(kit.Kit_term_cbk().Exec()); // call bgn term
|
||||
if (!rslt) {
|
||||
event.doit = false; // cbk canceled term; stop close
|
||||
kit.Kit_mode_(Swt_kit_mode.Tid_ready); // reset kit back to "running" mode;
|
||||
return;
|
||||
}
|
||||
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
|
||||
Thread_adp_.Start_by_key(Invk_wait_for_sync_cmd, this, Invk_wait_for_sync_cmd); // wait for sync_cmd to end in background thread; call shutdown again when it does
|
||||
}
|
||||
}
|
||||
private void Wait_for_sync_cmd() { // THREAD:non-GUI
|
||||
int loop_count = 0, loop_max = 50, loop_wait = 100; // loop for 100 ms for no more than 5 seconds
|
||||
while (loop_count < loop_max) {
|
||||
usr_dlg.Log_many("", "", "swt:waiting for sync cmd; loop=~{0}", loop_count);
|
||||
if (!kit.Kit_sync_cmd_exists()) {
|
||||
usr_dlg.Log_many("", "", "swt:sync cmd done; shutting down");
|
||||
break;
|
||||
}
|
||||
Thread_adp_.Sleep(loop_wait);
|
||||
loop_count++;
|
||||
}
|
||||
if (loop_count == loop_max)
|
||||
usr_dlg.Log_many("", "", "swt:sync_wait failed", loop_count);
|
||||
Gfo_invk_.Invk_by_key(kit.New_cmd_sync(kit), Swt_kit.Invk_shell_close); // shutdown again; note that cmd must be called on GUI thread
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_wait_for_sync_cmd)) Wait_for_sync_cmd();
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} private static final String Invk_wait_for_sync_cmd = "wait_for_sync_cmd";
|
||||
}
|
||||
class Swt_kit_mode {
|
||||
public static final int
|
||||
Tid_ctor = 0
|
||||
, Tid_ready = 1
|
||||
, Tid_term = 2
|
||||
;
|
||||
}
|
||||
class Swt_gui_cmd implements GfuiInvkCmd, Runnable {
|
||||
private final Swt_kit kit; private final Gfo_usr_dlg usr_dlg; private final Display display; private final Gfo_invk target; private final boolean async;
|
||||
private GfsCtx invk_ctx; private int invk_ikey; private String invk_key; private GfoMsg invk_msg;
|
||||
private Object rv_obj;
|
||||
public Swt_gui_cmd(Swt_kit kit, Gfo_usr_dlg usr_dlg, Display display, Gfo_invk target, boolean async) {
|
||||
this.kit = kit; this.usr_dlg = usr_dlg; this.display = display; this.target = target; this.async = async;
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
this.invk_ctx = ctx; this.invk_ikey = ikey; this.invk_key = k; this.invk_msg = m;
|
||||
if (async)
|
||||
display.asyncExec(this);
|
||||
else {
|
||||
kit.Kit_sync_cmd_add(this);
|
||||
try {display.syncExec(this);}
|
||||
finally {kit.Kit_sync_cmd_del(this);}
|
||||
}
|
||||
return rv_obj;
|
||||
}
|
||||
@Override public void run() {
|
||||
synchronized (this) {// needed for Special:Search and async; DATE:2015-04-23
|
||||
try {rv_obj = target.Invk(invk_ctx, invk_ikey, invk_key, invk_msg);}
|
||||
catch (Exception e) {
|
||||
if (kit.Kit_mode__term()) return; // NOTE: if shutting down, don't warn; warn will try to write to status.bar, which will fail b/c SWT is shutting down; failures will try to write to status.bar again, causing StackOverflow exception; DATE:2014-05-04
|
||||
usr_dlg.Warn_many("", "", "fatal error while running; key=~{0} err=~{1}", invk_key, Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Rls() {
|
||||
this.invk_ctx = null; this.invk_key = null; this.invk_msg = null;
|
||||
}
|
||||
}
|
||||
class Swt_msg_wkr_stop implements UsrMsgWkr {
|
||||
private final Swt_kit kit; private final Gfo_usr_dlg gui_wtr;
|
||||
public Swt_msg_wkr_stop(Swt_kit kit, Gfo_usr_dlg gui_wtr) {this.kit = kit; this.gui_wtr = gui_wtr;}
|
||||
public void ExecUsrMsg(int type, UsrMsg umsg) {
|
||||
String msg = umsg.To_str();
|
||||
kit.Ask_ok("xowa.gui", "stop", msg);
|
||||
gui_wtr.Log_many("", "", msg);
|
||||
}
|
||||
}
|
||||
48
150_gfui/src/gplx/gfui/kits/core/TxtFindMgr.java
Normal file
48
150_gfui/src/gplx/gfui/kits/core/TxtFindMgr.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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.kits.core; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public class TxtFindMgr {
|
||||
public String Text() {return text;}
|
||||
public TxtFindMgr Text_(String v) {
|
||||
if (!caseSensitive) v = String_.Lower(v);
|
||||
text = v;
|
||||
return this;
|
||||
} String text;
|
||||
public boolean CaseSensitive() {return caseSensitive;} public TxtFindMgr CaseSensitive_(boolean v) {caseSensitive = v; return this;} private boolean caseSensitive = false;
|
||||
public int[] FindByUi(String findText, int selBgn, int selLen, boolean keyIsEnter) {
|
||||
int[] rv = new int[2];
|
||||
if (String_.Eq(findText, "")) return rv; // make newSel = 0 b/c all text deleted; else, find will continue from last selBgn; easy way to "reset"
|
||||
rv[0] = selBgn; rv[1] = selLen; // make newSel = curSel
|
||||
int adj = keyIsEnter ? 1 : 0; // if enter, search next, else search from cur; else will add to selLen if at match; ex: ab->c at abc will keep same selBgn, but increase selLen to 3
|
||||
int findPos = FindNext(findText, selBgn + adj);
|
||||
if (findPos == String_.Find_none) { // nothing found; set selLen to 0 and return
|
||||
rv[1] = 0;
|
||||
return rv;
|
||||
}
|
||||
rv[0] = findPos;
|
||||
rv[1] = String_.Len(findText);
|
||||
return rv;
|
||||
}
|
||||
public int FindNext(String find, int guiPos) {
|
||||
if (!caseSensitive) find = String_.Lower(find);
|
||||
int findPos = String_.FindFwd(text, find, guiPos);
|
||||
if (findPos == String_.Find_none && guiPos != 0)
|
||||
findPos = String_.FindFwd(text, find, 0);
|
||||
return findPos;
|
||||
}
|
||||
}
|
||||
99
150_gfui/src/gplx/gfui/kits/swts/Swt_app_browser.java
Normal file
99
150_gfui/src/gplx/gfui/kits/swts/Swt_app_browser.java
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.*;
|
||||
import gplx.core.envs.System_;
|
||||
|
||||
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) {
|
||||
new Swt_app_browser().start();
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
Display display = new Display();
|
||||
Shell shell = new Shell(display);
|
||||
shell.setLayout(new GridLayout(1, false));
|
||||
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
gridData.widthHint = SWT.DEFAULT;
|
||||
gridData.heightHint = SWT.DEFAULT;
|
||||
shell.setLayoutData(gridData);
|
||||
shell.setText("Firebug Lite for SWT ;)");
|
||||
|
||||
final Browser browser = new Browser(shell, SWT.NONE);
|
||||
GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true);
|
||||
gridData2.widthHint = SWT.DEFAULT;
|
||||
gridData2.heightHint = SWT.DEFAULT;
|
||||
browser.setLayoutData(gridData2);
|
||||
|
||||
Button button = new Button(shell, SWT.PUSH);
|
||||
button.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
|
||||
button.setText("Install");
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
browser.setUrl("javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');");
|
||||
}
|
||||
});
|
||||
|
||||
browser.setUrl("http://stackoverflow.com/questions/12003602/eclipse-swt-browser-and-firebug-lite");
|
||||
|
||||
shell.open();
|
||||
while (!shell.isDisposed()) {
|
||||
if (!display.readAndDispatch())
|
||||
display.sleep();
|
||||
}
|
||||
display.dispose();
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
System_.Garbage_collect();
|
||||
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) {}
|
||||
}
|
||||
429
150_gfui/src/gplx/gfui/kits/swts/Swt_app_main.java
Normal file
429
150_gfui/src/gplx/gfui/kits/swts/Swt_app_main.java
Normal file
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.Byte_ascii;
|
||||
import gplx.String_;
|
||||
|
||||
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.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
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();
|
||||
// Combo_default();
|
||||
// Combo_composite();
|
||||
}
|
||||
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();
|
||||
}
|
||||
public static void Combo_dflt() {
|
||||
Display display = new Display();
|
||||
Shell shell = new Shell(display);
|
||||
shell.setLayout(new FillLayout());
|
||||
|
||||
String[] ITEMS = { "A", "B", "C", "D" };
|
||||
|
||||
final Combo combo = new Combo(shell, SWT.DROP_DOWN);
|
||||
combo.setItems(ITEMS);
|
||||
combo.select(2);
|
||||
|
||||
combo.addSelectionListener(new SelectionListener() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
System.out.println(combo.getText());
|
||||
}
|
||||
|
||||
public void widgetDefaultSelected(SelectionEvent e) {
|
||||
System.out.println(combo.getText());
|
||||
}
|
||||
});
|
||||
combo.addKeyListener(new KeyListener() {
|
||||
@Override
|
||||
public void keyReleased(KeyEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent arg0) {
|
||||
System.out.println(combo.getText());
|
||||
if (arg0.keyCode == Byte_ascii.Ltr_a) {
|
||||
combo.setItem(0, "a");
|
||||
combo.setListVisible(true);
|
||||
}
|
||||
else if (arg0.keyCode == Byte_ascii.Ltr_b) {
|
||||
combo.setItem(0, "b");
|
||||
combo.setListVisible(true);
|
||||
}
|
||||
// System.out.println(combo.getText());
|
||||
}
|
||||
});
|
||||
|
||||
shell.open();
|
||||
combo.setListVisible(true);
|
||||
while (!shell.isDisposed()) {
|
||||
if (!display.readAndDispatch()) {
|
||||
display.sleep();
|
||||
}
|
||||
}
|
||||
display.dispose();
|
||||
}
|
||||
public static void Combo_composite() {
|
||||
final Display display = new Display();
|
||||
final Shell shell = new Shell(display);
|
||||
GridLayout gridLayout = new GridLayout();
|
||||
gridLayout.numColumns = 2;
|
||||
gridLayout.makeColumnsEqualWidth = true;
|
||||
shell.setLayout(gridLayout);
|
||||
final Text text = new Text(shell, SWT.BORDER);
|
||||
text.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
|
||||
Text text2 = new Text(shell, SWT.BORDER);
|
||||
text2.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_END));
|
||||
shell.pack();
|
||||
shell.open();
|
||||
|
||||
final Shell combo_shell = new Shell(display, SWT.ON_TOP);
|
||||
combo_shell.setLayout(new FillLayout());
|
||||
final Table combo_table = new Table(combo_shell, SWT.SINGLE);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
new TableItem(combo_table, SWT.NONE);
|
||||
}
|
||||
|
||||
text.addListener(SWT.KeyDown, new Listener() {
|
||||
@Override public void handleEvent(Event event) {
|
||||
int index = -1;
|
||||
switch (event.keyCode) {
|
||||
case SWT.ARROW_DOWN:
|
||||
if (event.stateMask == SWT.ALT) {
|
||||
Rectangle text_bounds = display.map(shell, null, text.getBounds());
|
||||
combo_shell.setBounds(text_bounds.x, text_bounds.y + text_bounds.height, text_bounds.width, (text_bounds.height - 1) * combo_table.getItems().length);
|
||||
combo_shell.setVisible(true);
|
||||
} else {
|
||||
index = (combo_table.getSelectionIndex() + 1) % combo_table.getItemCount();
|
||||
combo_table.setSelection(index);
|
||||
event.doit = false;
|
||||
}
|
||||
break;
|
||||
case SWT.ARROW_UP:
|
||||
if (event.stateMask == SWT.ALT) {
|
||||
combo_shell.setVisible(false);
|
||||
} else {
|
||||
index = combo_table.getSelectionIndex() - 1;
|
||||
if (index < 0) index = combo_table.getItemCount() - 1;
|
||||
combo_table.setSelection(index);
|
||||
event.doit = false;
|
||||
}
|
||||
break;
|
||||
case SWT.CR:
|
||||
if (combo_shell.isVisible() && combo_table.getSelectionIndex() != -1) {
|
||||
text.setText(combo_table.getSelection()[0].getText());
|
||||
combo_shell.setVisible(false);
|
||||
}
|
||||
break;
|
||||
case SWT.ESC:
|
||||
combo_shell.setVisible(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
text.addListener(SWT.Modify, new Listener() {
|
||||
@Override public void handleEvent(Event event) {
|
||||
String string = text.getText();
|
||||
if (string.length() == 0) {
|
||||
combo_shell.setVisible(false);
|
||||
} else {
|
||||
TableItem[] items = combo_table.getItems();
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].setText(string + '-' + i);
|
||||
}
|
||||
|
||||
Rectangle text_bounds = display.map(shell, null, text.getBounds());
|
||||
combo_shell.setBounds(text_bounds.x, text_bounds.y + text_bounds.height, text_bounds.width, (text_bounds.height - 1) * items.length);
|
||||
combo_shell.setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
combo_table.addListener(SWT.DefaultSelection, new Listener() {
|
||||
@Override public void handleEvent(Event arg0) {
|
||||
text.setText(combo_table.getSelection()[0].getText());
|
||||
combo_shell.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
combo_table.addListener(SWT.KeyDown, new Listener() {
|
||||
@Override public void handleEvent(Event event) {
|
||||
if (event.keyCode == SWT.ESC) {
|
||||
combo_shell.setVisible(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final Swt_shell_hider shell_hider = new Swt_shell_hider(combo_shell);
|
||||
Listener focus_out_listener = new Listener() {
|
||||
@Override public void handleEvent(Event arg0) {
|
||||
if (display.isDisposed()) return;
|
||||
Control control = display.getFocusControl();
|
||||
// if (control == null || (control != text && control != combo_table)) {
|
||||
// combo_shell.setVisible(false);
|
||||
// }
|
||||
if (control == null || (control == text || control == combo_table)) {
|
||||
// combo_shell.setVisible(false);
|
||||
shell_hider.Active = true;
|
||||
display.asyncExec(shell_hider);
|
||||
//Thread t = new Thread(shell_hider); t.start();
|
||||
//Swt_shell_hider
|
||||
}
|
||||
|
||||
// boolean combo_is_focus = combo_table.isFocusControl();
|
||||
// boolean text_is_focus = text.isFocusControl();
|
||||
// if (control == null || (control == text)) {
|
||||
// combo_shell.setVisible(false);
|
||||
// }
|
||||
// if (control == null || (control == combo_table)) {
|
||||
// combo_shell.setVisible(true);
|
||||
// }
|
||||
}
|
||||
};
|
||||
|
||||
combo_table.addListener(SWT.FocusOut, focus_out_listener);
|
||||
text.addListener(SWT.FocusOut, focus_out_listener);
|
||||
|
||||
Listener focus_in_listener = new Listener() {
|
||||
@Override public void handleEvent(Event arg0) {
|
||||
if (display.isDisposed()) return;
|
||||
Control control = display.getFocusControl();
|
||||
if (control == combo_table) {
|
||||
// combo_shell.setVisible(false);
|
||||
//display.asyncExec(shell_hider);
|
||||
shell_hider.Active = false;
|
||||
//Swt_shell_hider
|
||||
}
|
||||
// boolean combo_is_focus = combo_table.isFocusControl();
|
||||
// boolean text_is_focus = text.isFocusControl();
|
||||
// if (control == null || (control == text)) {
|
||||
// combo_shell.setVisible(false);
|
||||
// }
|
||||
// if (control == null || (control == combo_table)) {
|
||||
// combo_shell.setVisible(true);
|
||||
// }
|
||||
}
|
||||
};
|
||||
combo_table.addListener(SWT.FocusIn, focus_in_listener);
|
||||
|
||||
shell.addListener(SWT.Move, new Listener() {
|
||||
@Override public void handleEvent(Event arg0) {
|
||||
combo_shell.setVisible(false);
|
||||
}
|
||||
});
|
||||
|
||||
while (!shell.isDisposed()) {
|
||||
if (!display.readAndDispatch()) display.sleep();
|
||||
}
|
||||
display.dispose();
|
||||
}
|
||||
}
|
||||
class Swt_shell_hider implements Runnable {
|
||||
public boolean Active = true;
|
||||
|
||||
private Shell combo_shell;
|
||||
public Swt_shell_hider(Shell combo_shell) {this.combo_shell = combo_shell;}
|
||||
@Override public void run() {
|
||||
// try {
|
||||
// Thread.sleep(1000);
|
||||
// } catch (InterruptedException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
if (Active) {
|
||||
combo_shell.setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
69
150_gfui/src/gplx/gfui/kits/swts/Swt_btn.java
Normal file
69
150_gfui/src/gplx/gfui/kits/swts/Swt_btn.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.GxwElem;
|
||||
|
||||
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;
|
||||
public class Swt_btn implements GxwElem, Swt_control {
|
||||
private Button btn;
|
||||
public Swt_btn(Swt_control owner, Keyval_hash 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_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) {}
|
||||
}
|
||||
71
150_gfui/src/gplx/gfui/kits/swts/Swt_btn_no_border.java
Normal file
71
150_gfui/src/gplx/gfui/kits/swts/Swt_btn_no_border.java
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.GfoMsg;
|
||||
import gplx.GfsCtx;
|
||||
import gplx.Keyval_hash;
|
||||
import gplx.gfui.SizeAdp;
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.GxwElem;
|
||||
import gplx.gfui.controls.standards.GfuiBtn;
|
||||
import gplx.gfui.imgs.ImageAdp;
|
||||
|
||||
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.Label;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
public 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, Keyval_hash 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));
|
||||
}
|
||||
}
|
||||
62
150_gfui/src/gplx/gfui/kits/swts/Swt_clipboard.java
Normal file
62
150_gfui/src/gplx/gfui/kits/swts/Swt_clipboard.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.ipts.*;
|
||||
import gplx.gfui.kits.core.Gfui_clipboard;
|
||||
import gplx.gfui.kits.core.Gfui_clipboard_;
|
||||
|
||||
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;
|
||||
public 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 Gfo_invk_.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);
|
||||
}
|
||||
}
|
||||
104
150_gfui/src/gplx/gfui/kits/swts/Swt_combo.java
Normal file
104
150_gfui/src/gplx/gfui/kits/swts/Swt_combo.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.Gfo_evt_mgr;
|
||||
import gplx.Gfo_evt_mgr_owner;
|
||||
import gplx.Gfo_evt_mgr_;
|
||||
import gplx.GfoMsg;
|
||||
import gplx.GfsCtx;
|
||||
import gplx.Keyval_hash;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.core.threads.Thread_adp;
|
||||
import gplx.core.threads.Thread_adp_;
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost;
|
||||
import gplx.gfui.controls.gxws.GxwComboBox;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.GxwElem;
|
||||
import gplx.gfui.controls.standards.GfuiComboBox;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
class Swt_combo implements GxwElem, GxwComboBox, Swt_control, Gfo_evt_mgr_owner {
|
||||
private final Combo combo;
|
||||
public Swt_combo(Swt_control owner, Keyval_hash ctorArgs) {
|
||||
combo = new Combo(owner.Under_composite(), SWT.DROP_DOWN);
|
||||
core = new Swt_core_cmds(combo);
|
||||
combo.addKeyListener(new Swt_lnr_key(this));
|
||||
combo.addMouseListener(new Swt_lnr_mouse(this));
|
||||
combo.addSelectionListener(new Swt_combo__selection_listener(this));
|
||||
}
|
||||
@Override public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr; public void Evt_mgr_(Gfo_evt_mgr v) {ev_mgr = v;}
|
||||
@Override public Control Under_control() {return combo;}
|
||||
@Override public Control Under_menu_control() {return combo;}
|
||||
@Override public String TextVal() {return combo.getText();} @Override public void TextVal_set(String v) {combo.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;}
|
||||
@Override public Object SelectedItm() {return null;}
|
||||
@Override public int SelBgn() {return combo.getSelection().x;} @Override public void SelBgn_set(int v) {combo.setSelection(new Point(combo.getSelection().y, v));}
|
||||
@Override public int SelLen() {return combo.getSelection().y;} @Override public void SelLen_set(int v) {combo.setSelection(new Point(v, combo.getSelection().x));}
|
||||
@Override public void Sel_(int bgn, int end) {combo.setSelection(new Point(bgn, end));}
|
||||
@Override public void SelectedItm_set(Object v) {}
|
||||
@Override public String[] DataSource_as_str_ary() {return String_.Ary_empty;}
|
||||
@Override public void DataSource_set(Object... ary) {combo.setItems((String[])ary);}
|
||||
@Override public String Text_fallback() {return "";} @Override public void Text_fallback_(String v) {}
|
||||
@Override public int List_sel_idx() {return -1;} @Override public void List_sel_idx_(int v) {}
|
||||
@Override public void Items__update(String[] ary) {}
|
||||
@Override public void Items__size_to_fit(int count) {}
|
||||
@Override public void Items__visible_rows_(int v) {}
|
||||
@Override public void Items__jump_len_(int v) {}
|
||||
@Override public void Margins_set(int left, int top, int right, int bot) {}
|
||||
// @Override public void DataSource_update(Object... ary) {
|
||||
// String[] src = (String[])ary;
|
||||
// int trg_len = combo.getItems().length;
|
||||
// int src_len = src.length;
|
||||
// for (int i = 0; i < trg_len; ++i) {
|
||||
// combo.setItem(i, i < src_len ? src[i] : "");
|
||||
// }
|
||||
// }
|
||||
@Override public boolean List_visible() {return combo.getListVisible();}
|
||||
@Override public void List_visible_(boolean v) {
|
||||
String prv_text = combo.getText();
|
||||
combo.setListVisible(v);
|
||||
String cur_text = combo.getText();
|
||||
while (!String_.Eq(cur_text, prv_text)) { // NOTE: setting setListVisible to true may cause text to grab item from dropDown list; try to reset to original value; DATE:2016-03-14
|
||||
Thread_adp_.Sleep(1);
|
||||
combo.setText(prv_text);
|
||||
cur_text = combo.getText();
|
||||
}
|
||||
int text_len = prv_text == null ? 0 : prv_text.length();
|
||||
combo.setSelection(new Point(text_len, text_len));
|
||||
}
|
||||
}
|
||||
class Swt_combo__selection_listener implements SelectionListener {
|
||||
private final Swt_combo combo;
|
||||
public Swt_combo__selection_listener(Swt_combo combo) {this.combo = combo;}
|
||||
@Override public void widgetSelected(SelectionEvent arg0) {
|
||||
Gfo_evt_mgr_.Pub(combo, GfuiComboBox.Evt__selected_changed);
|
||||
}
|
||||
@Override public void widgetDefaultSelected(SelectionEvent arg0) {}
|
||||
}
|
||||
396
150_gfui/src/gplx/gfui/kits/swts/Swt_combo_ctrl.java
Normal file
396
150_gfui/src/gplx/gfui/kits/swts/Swt_combo_ctrl.java
Normal file
@@ -0,0 +1,396 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.*;
|
||||
import gplx.core.envs.Op_sys;
|
||||
import gplx.core.envs.Op_sys_;
|
||||
import gplx.core.threads.Thread_adp_;
|
||||
import gplx.gfui.controls.gxws.GxwComboBox;
|
||||
import gplx.gfui.controls.gxws.GxwElem;
|
||||
import gplx.gfui.controls.standards.GfuiComboBox;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.events.SelectionListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
public class Swt_combo_ctrl extends Swt_text_w_border implements GxwElem, GxwComboBox, Swt_control, Gfo_evt_mgr_owner { // REF: https://www.eclipse.org/forums/index.php/t/351029/; http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet320.java
|
||||
private final Text swt_text;
|
||||
private final Swt_combo_list list;
|
||||
public Swt_combo_ctrl(Swt_control owner, Color color, Keyval_hash ctorArgs) {
|
||||
super(owner, color, new Keyval_hash());
|
||||
Display display = owner.Under_control().getDisplay();
|
||||
Shell shell = owner.Under_control().getShell();
|
||||
this.swt_text = super.Under_text();
|
||||
this.list = new Swt_combo_list(display, shell, this);
|
||||
|
||||
swt_text.addListener(SWT.KeyDown, new Swt_combo_text__key_down(list));
|
||||
swt_text.addListener(SWT.MouseUp, new Swt_combo_text__mouse_up(list));
|
||||
|
||||
Table swt_list = list.Under_table_as_swt();
|
||||
swt_list.addListener(SWT.DefaultSelection, new Swt_combo_list__default_selection(this, list));
|
||||
swt_list.addListener(SWT.KeyDown, new Swt_combo_list__default_selection(this, list));
|
||||
swt_list.addListener(SWT.MouseDown, new Swt_combo_list__mouse_down(this, list));
|
||||
|
||||
// listeners to hide list-box when focus is transfered, shell is moved, text-box is clicked, etc
|
||||
Swt_combo_ctrl__list_hider_cmd list_hide_cmd = new Swt_combo_ctrl__list_hider_cmd(list);
|
||||
Swt_combo_ctrl__focus_out focus_out_lnr = new Swt_combo_ctrl__focus_out(display, this, list, list_hide_cmd);
|
||||
swt_text.addListener(SWT.FocusOut, focus_out_lnr);
|
||||
swt_list.addListener(SWT.FocusOut, focus_out_lnr);
|
||||
swt_text.addListener(SWT.FocusIn, new Swt_combo_text__focus_in(this, list));
|
||||
swt_list.addListener(SWT.FocusIn, new Swt_combo_ctrl__focus_in(display, list, list_hide_cmd));
|
||||
shell.addListener(SWT.Move, new Swt_combo_shell__move(list));
|
||||
}
|
||||
@Override public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr; public void Evt_mgr_(Gfo_evt_mgr v) {ev_mgr = v;}
|
||||
@Override public Object SelectedItm() {return null;}
|
||||
@Override public void SelectedItm_set(Object v) {}
|
||||
@Override public void Sel_(int bgn, int end) {swt_text.setSelection(new Point(bgn, end));}
|
||||
@Override public String[] DataSource_as_str_ary() {return list.Items_str_ary();}
|
||||
@Override public void DataSource_set(Object... ary) {list.Items_((String[])ary);}
|
||||
@Override public String Text_fallback() {return text_fallback;} private String text_fallback = "";// preserve original-text when using cursor keys in list-box
|
||||
@Override public void Text_fallback_(String v) {text_fallback = v;}
|
||||
public void Text_fallback_restore() {
|
||||
if (String_.Len_eq_0(text_fallback)) return; // handle escape pressed after dropdown is visible, but down / up not pressed
|
||||
this.Text_(text_fallback);
|
||||
this.text_fallback = "";
|
||||
}
|
||||
@Override public void Items__update(String[] ary) {list.Items_(ary);}
|
||||
@Override public void Items__size_to_fit(int count) {list.Resize_shell(count);}
|
||||
@Override public int List_sel_idx() {return list.Sel_idx();}
|
||||
@Override public void List_sel_idx_(int v) {list.Sel_idx_(v);}
|
||||
@Override public boolean List_visible() {return list.Visible();}
|
||||
@Override public void List_visible_(boolean v) {list.Visible_(v);}
|
||||
@Override public void Items__visible_rows_(int v) {list.Visible_rows = v;}
|
||||
@Override public void Items__jump_len_(int v) {list.Jump_len = v;}
|
||||
public Rectangle Bounds() {return super.Under_control().getBounds();}
|
||||
public String Text() {return swt_text.getText();} public void Text_(String v) {swt_text.setText(v);}
|
||||
public void Sel_all() {
|
||||
String text_text = swt_text.getText();
|
||||
this.Sel_(0, String_.Len(text_text));
|
||||
}
|
||||
}
|
||||
class Swt_combo_list {
|
||||
private final Display display; private final Shell owner_shell;
|
||||
private final Swt_combo_ctrl ctrl;
|
||||
private final Shell shell;
|
||||
private final Table table;
|
||||
private int list_len;
|
||||
public int Jump_len = 5;
|
||||
public int Visible_rows = 10;
|
||||
public Swt_combo_list(Display display, Shell owner_shell, Swt_combo_ctrl ctrl) {
|
||||
this.display = display; this.owner_shell = owner_shell; this.ctrl = ctrl;
|
||||
this.shell = new Shell(display, SWT.ON_TOP);
|
||||
shell.setLayout(new FillLayout());
|
||||
this.table = new Table(shell, SWT.SINGLE);
|
||||
}
|
||||
public Table Under_table_as_swt() {return table;}
|
||||
public int Items_len() {return table.getItemCount();}
|
||||
public TableItem[] Items() {return table.getItems();}
|
||||
public TableItem Sel_itm(int i) {return table.getSelection()[i];}
|
||||
public void Items_text_(int idx, String v) {table.getItem(idx).setText(v);}
|
||||
public String[] Items_str_ary() {return items_str_ary;} private String[] items_str_ary = String_.Ary_empty;
|
||||
public void Items_(String[] new_ary) {
|
||||
int new_len = new_ary.length;
|
||||
if (new_len == 0) Visible_(Bool_.N); // if new_ary is empty, then hide list box; else, brief flicker as items are removed
|
||||
|
||||
// remove all cur-items that are no longer needed b/c new_ary is smaller
|
||||
int cur_len = list_len;
|
||||
for (int i = new_len; i < cur_len; ++i) {
|
||||
table.remove(new_len);
|
||||
}
|
||||
|
||||
// update new_ary;
|
||||
for (int i = 0; i < new_len; ++i) {
|
||||
TableItem item = null;
|
||||
if (i < cur_len) // existing item; reuse it
|
||||
item = table.getItem(i);
|
||||
else // no ite; create a new one
|
||||
item = new TableItem(table, SWT.NONE);
|
||||
String cur_text = item.getText();
|
||||
String new_text = new_ary[i];
|
||||
if (!String_.Eq(cur_text, new_text) && new_text != null) {
|
||||
item.setText(new_text);
|
||||
}
|
||||
}
|
||||
this.list_len = new_len;
|
||||
|
||||
// resize list-shell to # of items
|
||||
int max_len = this.Visible_rows;
|
||||
if ( new_len == cur_len // do not resize if same #
|
||||
|| new_len > max_len && cur_len > max_len // do not resize if new_len and cur_len are both off-screen
|
||||
) {}
|
||||
this.items_str_ary = new_ary;
|
||||
// else
|
||||
// Resize_shell(list_len);
|
||||
}
|
||||
public int Sel_idx() {return table.getSelectionIndex();}
|
||||
public void Sel_idx_(int v) {table.setSelection(v);}
|
||||
public void Sel_idx_nudge(boolean fwd) {Sel_idx_adj(fwd, 1);}
|
||||
public void Sel_idx_jump(boolean fwd) {Sel_idx_adj(fwd, Jump_len);}
|
||||
private void Sel_idx_adj(boolean fwd, int adj) {
|
||||
if (!Visible()) Visible_(Bool_.Y); // these are called by cursor keys; always make visible
|
||||
int cur_idx = table.getSelectionIndex();
|
||||
int new_idx = cur_idx;
|
||||
int idx_n = list_len - 1;
|
||||
if (fwd) {
|
||||
if (cur_idx == idx_n)
|
||||
new_idx = -1;
|
||||
else if (cur_idx == -1)
|
||||
new_idx = 0;
|
||||
else {
|
||||
new_idx = cur_idx + adj;
|
||||
if (new_idx >= idx_n)
|
||||
new_idx = idx_n;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (cur_idx == 0)
|
||||
new_idx = -1;
|
||||
else if (cur_idx == -1)
|
||||
new_idx = idx_n;
|
||||
else {
|
||||
new_idx = cur_idx - adj;
|
||||
if (new_idx < 0)
|
||||
new_idx = 0;
|
||||
}
|
||||
}
|
||||
Sel_idx_by_key(new_idx);
|
||||
}
|
||||
public void Sel_idx_by_key(int v) {
|
||||
table.setSelection(v);
|
||||
if (v == -1) { // nothing selected; restore orig
|
||||
ctrl.Text_fallback_restore();
|
||||
} else { // something selected; transfer selected item to text
|
||||
String sel_text = table.getItem(v).getText();
|
||||
ctrl.Text_(sel_text);
|
||||
ctrl.Sel_(sel_text.length(), sel_text.length());
|
||||
}
|
||||
Gfo_evt_mgr_.Pub(ctrl, GfuiComboBox.Evt__selected_changed);
|
||||
}
|
||||
public boolean Visible() {return shell.isVisible();}
|
||||
public void Visible_(boolean v) {
|
||||
if (v && list_len == 0) return; // never show if 0 items; occurs when users presses alt+down or down when in combo-box
|
||||
shell.setVisible(v);
|
||||
}
|
||||
public void Resize_shell(int len) {
|
||||
Rectangle text_bounds = display.map(owner_shell, null, ctrl.Bounds());
|
||||
int adj = Op_sys.Cur().Tid() == Op_sys.Lnx.Tid() ? 9 : 2; // NOTE: magic-numbers from gnosygnu's Windows-7, OS-X and openSUSE; Linux # is not correct for different number of items, but looks acceptable for 25;
|
||||
int max_len = this.Visible_rows;
|
||||
int height = (table.getItemHeight() * (len > max_len ? max_len : len)) + adj;
|
||||
if (height != shell.getSize().y) // only resize if height is different
|
||||
shell.setBounds(text_bounds.x, text_bounds.y + text_bounds.height - 1, text_bounds.width, height);
|
||||
}
|
||||
}
|
||||
class Swt_combo_text__key_down implements Listener { // for list-box, highlight item or toggle visiblility based on keys
|
||||
private final Swt_combo_list list;
|
||||
public Swt_combo_text__key_down(Swt_combo_list list) {
|
||||
this.list = list;
|
||||
}
|
||||
@Override public void handleEvent(Event event) {
|
||||
try {
|
||||
int mask = event.stateMask;
|
||||
boolean no_modifier = false;
|
||||
boolean ctrl_modifier = false;
|
||||
boolean alt_modifier = false;
|
||||
if ((mask & SWT.ALT) == SWT.ALT) {alt_modifier = true;}
|
||||
else if ((mask & SWT.CTRL) == SWT.CTRL){ctrl_modifier = true;}
|
||||
else if ((mask & SWT.SHIFT) == SWT.SHIFT){}
|
||||
else
|
||||
no_modifier = true;
|
||||
switch (event.keyCode) {
|
||||
case SWT.ARROW_DOWN:
|
||||
if (event.stateMask == SWT.ALT) {
|
||||
list.Visible_(true);
|
||||
} else {
|
||||
list.Sel_idx_nudge(Bool_.Y);
|
||||
}
|
||||
event.doit = false;
|
||||
break;
|
||||
case SWT.ARROW_UP:
|
||||
if (event.stateMask == SWT.ALT) {
|
||||
list.Visible_(false);
|
||||
} else {
|
||||
list.Sel_idx_nudge(Bool_.N);
|
||||
}
|
||||
event.doit = false;
|
||||
break;
|
||||
case SWT.PAGE_DOWN:
|
||||
if (no_modifier) {
|
||||
list.Sel_idx_jump(Bool_.Y);
|
||||
event.doit = false;
|
||||
}
|
||||
else if (ctrl_modifier || alt_modifier) {
|
||||
list.Visible_(Bool_.N);
|
||||
event.doit = false;
|
||||
}
|
||||
break;
|
||||
case SWT.PAGE_UP:
|
||||
if (no_modifier) {
|
||||
list.Sel_idx_jump(Bool_.N);
|
||||
event.doit = false;
|
||||
}
|
||||
else if (ctrl_modifier || alt_modifier) {
|
||||
list.Visible_(Bool_.N);
|
||||
event.doit = false;
|
||||
}
|
||||
break;
|
||||
case SWT.CR:
|
||||
if (list.Visible() && list.Sel_idx() != -1) {
|
||||
list.Visible_(false);
|
||||
}
|
||||
break;
|
||||
case SWT.ESC:
|
||||
list.Sel_idx_by_key(-1);
|
||||
list.Visible_(false);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
class Swt_combo_text__mouse_up implements Listener { // if list-box is visible, left-click on text-box should hide list-box; note that left-click does not fire focus-in event; EX: focus html-box; click on url-box; focus-in event not fired
|
||||
private final Swt_combo_list list;
|
||||
public Swt_combo_text__mouse_up(Swt_combo_list list) {
|
||||
this.list = list;
|
||||
}
|
||||
@Override public void handleEvent(Event event) {
|
||||
if (event.button == 1) { // left-click
|
||||
if (list.Visible()) {
|
||||
list.Visible_(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
class Swt_combo_list__default_selection implements Listener { // transfer list-box's selected to text-box
|
||||
private final Swt_combo_ctrl ctrl; private final Swt_combo_list list;
|
||||
public Swt_combo_list__default_selection(Swt_combo_ctrl ctrl, Swt_combo_list list) {
|
||||
this.ctrl = ctrl; this.list = list;
|
||||
}
|
||||
@Override public void handleEvent(Event arg0) {
|
||||
ctrl.Text_(list.Sel_itm(0).getText());
|
||||
list.Visible_(false);
|
||||
}
|
||||
}
|
||||
class Swt_combo_list__key_down implements Listener { // hide list-box if escape pressed
|
||||
private final Swt_combo_ctrl ctrl; private final Swt_combo_list list;
|
||||
public Swt_combo_list__key_down(Swt_combo_ctrl ctrl, Swt_combo_list list) {
|
||||
this.ctrl = ctrl;
|
||||
this.list = list;
|
||||
}
|
||||
@Override public void handleEvent(Event event) {
|
||||
if (event.keyCode == SWT.ESC) {
|
||||
ctrl.Text_fallback_restore();
|
||||
list.Visible_(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Swt_combo_list__mouse_down implements Listener { // left-click on list-box should transfer item to text-box and publish "accepted" event
|
||||
private final Swt_combo_ctrl ctrl;
|
||||
private final Swt_combo_list list;
|
||||
public Swt_combo_list__mouse_down(Swt_combo_ctrl ctrl, Swt_combo_list list) {
|
||||
this.ctrl = ctrl;
|
||||
this.list = list;
|
||||
}
|
||||
@Override public void handleEvent(Event event) {
|
||||
if (event.button == 1) { // left-click
|
||||
ctrl.Text_(list.Sel_itm(0).getText());
|
||||
Gfo_evt_mgr_.Pub(ctrl, GfuiComboBox.Evt__selected_changed);
|
||||
Gfo_evt_mgr_.Pub(ctrl, GfuiComboBox.Evt__selected_accepted);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Swt_combo_ctrl__focus_out implements Listener { // run hide-cmd when list-box when text-box / list-box loses focus
|
||||
private final Display display;
|
||||
private final Control text_as_swt, list_as_swt;
|
||||
private final Swt_combo_ctrl__list_hider_cmd list_hide_cmd;
|
||||
public Swt_combo_ctrl__focus_out(Display display, Swt_combo_ctrl ctrl, Swt_combo_list list, Swt_combo_ctrl__list_hider_cmd list_hide_cmd) {
|
||||
this.list_hide_cmd = list_hide_cmd;
|
||||
this.display = display;
|
||||
this.text_as_swt = ctrl.Under_text();
|
||||
this.list_as_swt = list.Under_table_as_swt();
|
||||
}
|
||||
@Override public void handleEvent(Event arg0) {
|
||||
if (display.isDisposed()) return;
|
||||
Control control = display.getFocusControl();
|
||||
if (control == null || control == text_as_swt || control == list_as_swt) {
|
||||
list_hide_cmd.Active = true;
|
||||
display.asyncExec(list_hide_cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
class Swt_combo_ctrl__focus_in implements Listener { // cancel hide-cmd if list-box gains focus
|
||||
private final Display display;
|
||||
private final Swt_combo_ctrl__list_hider_cmd list_hide_cmd;
|
||||
private final Control list_as_swt;
|
||||
|
||||
public Swt_combo_ctrl__focus_in(Display display, Swt_combo_list list, Swt_combo_ctrl__list_hider_cmd list_hide_cmd) {
|
||||
this.display = display;
|
||||
this.list_as_swt = list.Under_table_as_swt();
|
||||
this.list_hide_cmd = list_hide_cmd;
|
||||
}
|
||||
@Override public void handleEvent(Event arg0) {
|
||||
if (display.isDisposed()) return;
|
||||
Control control = display.getFocusControl();
|
||||
if (control == list_as_swt)
|
||||
list_hide_cmd.Active = false;
|
||||
}
|
||||
}
|
||||
class Swt_combo_text__focus_in implements Listener { // hide list-box when text-box is focused
|
||||
private final Swt_combo_ctrl ctrl; private final Swt_combo_list list;
|
||||
public Swt_combo_text__focus_in(Swt_combo_ctrl ctrl, Swt_combo_list list) {
|
||||
this.ctrl = ctrl; this.list = list;
|
||||
}
|
||||
@Override public void handleEvent(Event arg0) {
|
||||
if (list.Visible())
|
||||
list.Visible_(false);
|
||||
else
|
||||
ctrl.Sel_all();
|
||||
}
|
||||
}
|
||||
class Swt_combo_shell__move implements Listener { // hide list-box when shell is moved
|
||||
private final Swt_combo_list list;
|
||||
public Swt_combo_shell__move(Swt_combo_list list) {this.list = list;}
|
||||
@Override public void handleEvent(Event arg0) {
|
||||
list.Visible_(false);
|
||||
}
|
||||
}
|
||||
class Swt_combo_ctrl__list_hider_cmd implements Runnable { // hide list-box; can be "canceled"
|
||||
private final Swt_combo_list list;
|
||||
public boolean Active = true;
|
||||
public Swt_combo_ctrl__list_hider_cmd(Swt_combo_list list) {
|
||||
this.list = list;
|
||||
}
|
||||
@Override public void run() {
|
||||
if (Active)
|
||||
list.Visible_(false);
|
||||
}
|
||||
}
|
||||
29
150_gfui/src/gplx/gfui/kits/swts/Swt_control.java
Normal file
29
150_gfui/src/gplx/gfui/kits/swts/Swt_control.java
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.controls.gxws.GxwElem;
|
||||
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
public interface Swt_control extends GxwElem {
|
||||
Control Under_control();
|
||||
Composite Under_composite();
|
||||
Control Under_menu_control();
|
||||
}
|
||||
43
150_gfui/src/gplx/gfui/kits/swts/Swt_control_.java
Normal file
43
150_gfui/src/gplx/gfui/kits/swts/Swt_control_.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.PointAdp;
|
||||
import gplx.gfui.RectAdp;
|
||||
import gplx.gfui.SizeAdp;
|
||||
import gplx.gfui.controls.elems.GfuiElem;
|
||||
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
|
||||
public 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();}
|
||||
}
|
||||
255
150_gfui/src/gplx/gfui/kits/swts/Swt_core_cmds.java
Normal file
255
150_gfui/src/gplx/gfui/kits/swts/Swt_core_cmds.java
Normal file
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.PointAdp;
|
||||
import gplx.gfui.PointAdp_;
|
||||
import gplx.gfui.RectAdp;
|
||||
import gplx.gfui.RectAdp_;
|
||||
import gplx.gfui.SizeAdp;
|
||||
import gplx.gfui.SizeAdp_;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.GxwElem;
|
||||
import gplx.gfui.draws.*;
|
||||
import gplx.gfui.kits.core.Swt_kit;
|
||||
|
||||
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 Err_.new_wo_type("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 Err_.new_wo_type("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 Err_.new_wo_type("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 Err_.new_wo_type("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 Err_.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();}
|
||||
}
|
||||
172
150_gfui/src/gplx/gfui/kits/swts/Swt_core_lnrs.java
Normal file
172
150_gfui/src/gplx/gfui/kits/swts/Swt_core_lnrs.java
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.Byte_ascii;
|
||||
|
||||
import gplx.Enm_;
|
||||
import gplx.Gfo_evt_mgr_;
|
||||
import gplx.Gfo_invk_;
|
||||
import gplx.GfoMsg_;
|
||||
import gplx.GfsCtx;
|
||||
import gplx.String_;
|
||||
import gplx.Tfds;
|
||||
import gplx.core.bits.Bitmask_;
|
||||
import gplx.gfui.controls.gxws.GxwElem;
|
||||
import gplx.gfui.controls.standards.Gfui_html;
|
||||
import gplx.gfui.controls.windows.GfuiWin;
|
||||
import gplx.gfui.ipts.*;
|
||||
|
||||
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();
|
||||
Gfo_evt_mgr_.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 39: val = IptKey_.Quote.Val(); break;
|
||||
case 44: val = IptKey_.Comma.Val(); break;
|
||||
case 45: val = IptKey_.Minus.Val(); break;
|
||||
case 46: val = IptKey_.Period.Val(); break;
|
||||
case 47: val = IptKey_.Slash.Val(); break;
|
||||
case 59: val = IptKey_.Semicolon.Val(); break;
|
||||
case 61: val = IptKey_.Equal.Val(); break;
|
||||
case 91: val = IptKey_.OpenBracket.Val(); break;
|
||||
case 93: val = IptKey_.CloseBracket.Val(); break;
|
||||
case 96: val = IptKey_.Tick.Val(); break;
|
||||
case 127: val = IptKey_.Delete.Val(); 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 16777225: val = IptKey_.Insert.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 16777298: val = IptKey_.CapsLock.Val(); break;
|
||||
case 16777299: val = IptKey_.NumLock.Val(); break;
|
||||
case 16777300: val = IptKey_.ScrollLock.Val(); break;
|
||||
case 16777301: val = IptKey_.Pause.Val(); break;
|
||||
case 16777303: val = IptKey_.PrintScreen.Val(); break;
|
||||
case 327680: val = IptKey_.Insert.Val(); break;
|
||||
}
|
||||
|
||||
if (Has_ctrl(ev.stateMask)) val |= IptKey_.KeyCode_Ctrl;
|
||||
if (Bitmask_.Has_int(ev.stateMask, IptKey_.KeyCode_Shift)) val |= IptKey_.KeyCode_Alt;
|
||||
if (Bitmask_.Has_int(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 Bitmask_.Has_int(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));
|
||||
}
|
||||
}
|
||||
40
150_gfui/src/gplx/gfui/kits/swts/Swt_dlg_file.java
Normal file
40
150_gfui/src/gplx/gfui/kits/swts/Swt_dlg_file.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.kits.*;
|
||||
import gplx.gfui.kits.core.Gfui_dlg_file;
|
||||
import gplx.gfui.kits.core.Gfui_kit_;
|
||||
|
||||
import org.eclipse.swt.widgets.*;
|
||||
import org.eclipse.swt.SWT;
|
||||
public 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();}
|
||||
}
|
||||
86
150_gfui/src/gplx/gfui/kits/swts/Swt_dlg_msg.java
Normal file
86
150_gfui/src/gplx/gfui/kits/swts/Swt_dlg_msg.java
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.*;
|
||||
import gplx.gfui.kits.*;
|
||||
import gplx.gfui.kits.core.Gfui_dlg_msg;
|
||||
import gplx.gfui.kits.core.Gfui_dlg_msg_;
|
||||
|
||||
import org.eclipse.swt.widgets.*;
|
||||
import org.eclipse.swt.SWT;
|
||||
|
||||
public 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 Err_.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 Err_.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 Err_.new_unhandled(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
312
150_gfui/src/gplx/gfui/kits/swts/Swt_html.java
Normal file
312
150_gfui/src/gplx/gfui/kits/swts/Swt_html.java
Normal file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.core.envs.System_;
|
||||
import gplx.core.primitives.*;
|
||||
import gplx.core.threads.Thread_adp_;
|
||||
import gplx.gfui.controls.elems.GfuiElem;
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.GxwElem;
|
||||
import gplx.gfui.controls.gxws.Gxw_html;
|
||||
import gplx.gfui.controls.gxws.Gxw_html_load_tid_;
|
||||
import gplx.gfui.controls.standards.Gfui_html;
|
||||
import gplx.gfui.controls.standards.Gfui_tab_mgr;
|
||||
import gplx.gfui.ipts.*;
|
||||
import gplx.gfui.kits.core.Swt_kit;
|
||||
|
||||
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.*;
|
||||
|
||||
public class Swt_html implements Gxw_html, Swt_control, FocusListener, Gfo_evt_mgr_owner {
|
||||
private Swt_html_lnr_location lnr_location; private Swt_html_lnr_status lnr_status;
|
||||
public Swt_html(Swt_kit kit, Swt_control owner_control, Keyval_hash 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.Get_val_or(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.addMouseWheelListener(new Swt_html_lnr_wheel(this));
|
||||
// browser.addOpenWindowListener(new Swt_open_window_listener(this)); // handle target='blank'
|
||||
// browser.addTraverseListener(new Swt_html_lnr_Traverse(this));
|
||||
}
|
||||
public Swt_kit Kit() {return kit;} private Swt_kit kit;
|
||||
public Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr; public void Evt_mgr_(Gfo_evt_mgr v) {ev_mgr = v;}
|
||||
@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 String Load_by_url_path() {return load_by_url_path;} private String load_by_url_path;
|
||||
public void Html_doc_html_load_by_mem(String html) {
|
||||
this.html_doc_html_load_tid = Gxw_html_load_tid_.Tid_mem;
|
||||
this.load_by_url_path = null;
|
||||
browser.setText(html); // DBG: Io_mgr.I.SaveFilStr(Io_url_.new_fil_("C:\\temp.txt"), s)
|
||||
}
|
||||
public void Html_doc_html_load_by_url(Io_url path, String html) {
|
||||
this.html_doc_html_load_tid = Gxw_html_load_tid_.Tid_url;
|
||||
this.load_by_url_path = path.To_http_file_str();
|
||||
Io_mgr.Instance.SaveFilStr(path, html);
|
||||
browser.setUrl(path.Xto_api());
|
||||
}
|
||||
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, Gfo_invk invk) {new Swt_html_func(browser, func_name, invk);}
|
||||
public String Html_js_eval_script(String script) {return Eval_script_as_str(script);}
|
||||
public Object Html_js_eval_script_as_obj(String script) {return Eval_script(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));}
|
||||
public String Html_js_send_json(String name, String data) {
|
||||
String script = String_.Format("return {0}('{1}');", name, String_.Replace(data, "\n", "") );
|
||||
return (String)Eval_script(script);
|
||||
}
|
||||
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 ( Type_adp_.Eq_typeSafe(arg, Bool_.Cls_ref_type)
|
||||
|| Type_adp_.Eq_typeSafe(arg, Int_.Cls_ref_type)
|
||||
|| Type_adp_.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.To_str_and_clear());
|
||||
}
|
||||
public 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_(Gfo_evt_itm 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
|
||||
System_.Garbage_collect();
|
||||
}
|
||||
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 Gfo_invk_.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_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_.Instance.Note(ev.title);}
|
||||
catch (Exception e) {html_box.Kit().Ask_ok("xowa.swt.html_box", "title.fail", Err_.Message_gplx_full(e));} // NOTE: must catch error or will cause app to lock; currently called inside displaySync
|
||||
}
|
||||
}
|
||||
class Swt_html_func extends BrowserFunction {
|
||||
private final Gfo_invk invk;
|
||||
private final Browser browser;
|
||||
public Swt_html_func(Browser browser, String name, Gfo_invk invk) {
|
||||
super (browser, name);
|
||||
this.browser = browser;
|
||||
this.invk = invk;
|
||||
}
|
||||
public Object function (Object[] args) {
|
||||
try {
|
||||
return gplx.gfui.controls.standards.Gfui_html.Js_args_exec(invk, args);
|
||||
}
|
||||
catch (Exception e) {
|
||||
String rv = Err_.Message_gplx_full(e);
|
||||
browser.execute("alert('" + Swt_html.Escape_quote(rv) + "')");
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
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(Gfo_evt_itm host) {this.host = host;} Gfo_evt_itm 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;
|
||||
String load_by_url_path = html_box.Load_by_url_path();
|
||||
if (load_by_url_path != null) ev_text = String_.Replace(ev_text, load_by_url_path, ""); // remove "C:/xowa/tab_1.html"
|
||||
// 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) Gfo_evt_mgr_.Pub_obj(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_full(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(Gfo_evt_itm host) {this.host = host;} private Gfo_evt_itm 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 {
|
||||
Gfo_evt_mgr_.Pub_obj(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_full(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);
|
||||
}
|
||||
}
|
||||
class Swt_html_lnr_wheel implements MouseWheelListener {
|
||||
private final Swt_html html_box;
|
||||
public Swt_html_lnr_wheel(Swt_html html_box) {
|
||||
this.html_box = html_box;
|
||||
}
|
||||
@Override public void mouseScrolled(MouseEvent evt) {
|
||||
if (evt.stateMask == SWT.CTRL) { // ctrl held;
|
||||
Gfo_evt_mgr_.Pub_obj(html_box, Gfui_html.Evt_zoom_changed, "clicks_is_positive", evt.count > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
//class Swt_open_window_listener implements OpenWindowListener {
|
||||
// private final Swt_html html_box;
|
||||
// public Swt_open_window_listener(Swt_html html_box) {this.html_box = html_box;}
|
||||
// @Override public void open(WindowEvent arg0) {
|
||||
// Tfds.Write();
|
||||
// }
|
||||
//}
|
||||
/*
|
||||
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
|
||||
*/
|
||||
24
150_gfui/src/gplx/gfui/kits/swts/Swt_html_eval_rslt.java
Normal file
24
150_gfui/src/gplx/gfui/kits/swts/Swt_html_eval_rslt.java
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
public 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;
|
||||
}
|
||||
53
150_gfui/src/gplx/gfui/kits/swts/Swt_img.java
Normal file
53
150_gfui/src/gplx/gfui/kits/swts/Swt_img.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.RectAdp;
|
||||
import gplx.gfui.SizeAdp;
|
||||
import gplx.gfui.SizeAdp_;
|
||||
import gplx.gfui.imgs.ImageAdp;
|
||||
import gplx.gfui.kits.core.Gfui_kit;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
|
||||
public 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 Err_.new_unimplemented();}
|
||||
public void SaveAsPng(Io_url url) {throw Err_.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);
|
||||
}
|
||||
}
|
||||
47
150_gfui/src/gplx/gfui/kits/swts/Swt_lbl.java
Normal file
47
150_gfui/src/gplx/gfui/kits/swts/Swt_lbl.java
Normal 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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.GxwElem;
|
||||
|
||||
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;
|
||||
|
||||
public class Swt_lbl implements GxwElem, Swt_control {
|
||||
private Label lbl;
|
||||
public Swt_lbl(Swt_control owner, Keyval_hash 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;}
|
||||
}
|
||||
37
150_gfui/src/gplx/gfui/kits/swts/Swt_lnr__menu_detect.java
Normal file
37
150_gfui/src/gplx/gfui/kits/swts/Swt_lnr__menu_detect.java
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.Err_;
|
||||
import gplx.Gfo_evt_mgr_;
|
||||
import gplx.gfui.controls.elems.GfuiElem;
|
||||
import gplx.gfui.controls.elems.GfuiElemKeys;
|
||||
import gplx.gfui.kits.core.Swt_kit;
|
||||
|
||||
import org.eclipse.swt.events.MenuDetectEvent;
|
||||
import org.eclipse.swt.events.MenuDetectListener;
|
||||
|
||||
public 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 {Gfo_evt_mgr_.Pub(elem, GfuiElemKeys.Evt_menu_detected);}
|
||||
catch (Exception e) {
|
||||
kit.Ask_ok("", "", "error during right-click; err=~{0}", Err_.Message_gplx_full(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
221
150_gfui/src/gplx/gfui/kits/swts/Swt_popup_grp.java
Normal file
221
150_gfui/src/gplx/gfui/kits/swts/Swt_popup_grp.java
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.*;
|
||||
import gplx.gfui.controls.elems.GfuiElem;
|
||||
import gplx.gfui.controls.windows.GfuiWin;
|
||||
import gplx.gfui.imgs.ImageAdp;
|
||||
import gplx.gfui.imgs.ImageAdp_;
|
||||
import gplx.gfui.kits.core.Gfui_mnu_grp;
|
||||
import gplx.gfui.kits.core.Gfui_mnu_itm;
|
||||
import gplx.gfui.kits.core.Gfui_mnu_itm_;
|
||||
import gplx.gfui.kits.core.Swt_kit;
|
||||
|
||||
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, Gfo_invk 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, Gfo_invk invk, Gfo_invk_root_wkr 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, Gfo_invk invk, Gfo_invk_root_wkr 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, Gfo_invk invk, Gfo_invk_root_wkr 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_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 Err_.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(Gfo_invk invk, String cmd) {
|
||||
itm.addListener(SWT.Selection, new Swt_lnr__menu_btn_cmd(invk, cmd));
|
||||
}
|
||||
public void Invk_set_msg(Gfo_invk_root_wkr root_wkr, Gfo_invk invk, GfoMsg msg) {
|
||||
itm.addListener(SWT.Selection, new Swt_lnr__menu_btn_msg(root_wkr, invk, msg));
|
||||
}
|
||||
public void Invk_set_chk(Gfo_invk_root_wkr root_wkr, Gfo_invk 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(Gfo_invk invk, String cmd) {this.invk = invk; this.cmd = cmd;} Gfo_invk invk; String cmd;
|
||||
public void handleEvent(Event ev) {
|
||||
try {Gfo_invk_.Invk_by_key(invk, cmd);}
|
||||
catch (Exception e) {Swt_kit.Instance.Ask_ok("", "", "error while invoking command: cmd=~{0} err=~{1}", cmd, Err_.Message_gplx_full(e));}
|
||||
}
|
||||
}
|
||||
class Swt_lnr__menu_btn_msg implements Listener {
|
||||
private Gfo_invk_root_wkr root_wkr; private Gfo_invk invk; private GfoMsg msg;
|
||||
public Swt_lnr__menu_btn_msg(Gfo_invk_root_wkr root_wkr, Gfo_invk 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.Instance.Ask_ok("", "", "error while invoking command: cmd=~{0} err=~{1}", msg.Key(), Err_.Message_gplx_full(e));}
|
||||
}
|
||||
}
|
||||
class Swt_lnr__menu_chk_msg implements Listener {
|
||||
private Swt_popup_itm mnu_itm; private Gfo_invk_root_wkr root_wkr; private Gfo_invk invk; private GfoMsg msg_n, msg_y;
|
||||
public Swt_lnr__menu_chk_msg(Swt_popup_itm mnu_itm, Gfo_invk_root_wkr root_wkr, Gfo_invk 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.Instance.Ask_ok("", "", "error while invoking command: cmd=~{0} err=~{1}", msg.Key(), Err_.Message_gplx_full(e));}
|
||||
}
|
||||
}
|
||||
62
150_gfui/src/gplx/gfui/kits/swts/Swt_tab_itm.java
Normal file
62
150_gfui/src/gplx/gfui/kits/swts/Swt_tab_itm.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.*;
|
||||
import gplx.gfui.controls.elems.GfuiElem;
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.Gxw_tab_itm;
|
||||
import gplx.gfui.controls.standards.Gfui_tab_itm_data;
|
||||
import gplx.gfui.kits.core.Swt_kit;
|
||||
|
||||
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 Err_.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 Gfo_invk_.Rv_unhandled;}
|
||||
@Override public void focusGained(FocusEvent arg0) {}
|
||||
@Override public void focusLost(FocusEvent arg0) {}
|
||||
}
|
||||
283
150_gfui/src/gplx/gfui/kits/swts/Swt_tab_mgr.java
Normal file
283
150_gfui/src/gplx/gfui/kits/swts/Swt_tab_mgr.java
Normal file
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
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.*;
|
||||
|
||||
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.Gxw_tab_itm;
|
||||
import gplx.gfui.controls.gxws.Gxw_tab_mgr;
|
||||
import gplx.gfui.controls.standards.Gfui_tab_itm_data;
|
||||
import gplx.gfui.controls.standards.Gfui_tab_mgr;
|
||||
import gplx.gfui.draws.*;
|
||||
import gplx.gfui.kits.core.GfuiInvkCmd;
|
||||
import gplx.gfui.kits.core.Swt_kit;
|
||||
|
||||
public class Swt_tab_mgr implements Gxw_tab_mgr, Swt_control, FocusListener, Gfo_evt_mgr_owner {
|
||||
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, Keyval_hash 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 Gfo_evt_mgr Evt_mgr() {return ev_mgr;} private Gfo_evt_mgr ev_mgr;
|
||||
public void Evt_mgr_(Gfo_evt_mgr 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.Instance, 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);
|
||||
Gfo_evt_mgr_.Pub_vals(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.Instance, 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) {
|
||||
Gfo_evt_mgr_.Pub_obj(this, Gfui_tab_mgr.Evt_tab_selected, "key", key);
|
||||
}
|
||||
public void Pub_tab_closed(String key) {
|
||||
Gfo_evt_mgr_.Pub_obj(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 Gfo_invk_.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;
|
||||
}
|
||||
}
|
||||
65
150_gfui/src/gplx/gfui/kits/swts/Swt_text.java
Normal file
65
150_gfui/src/gplx/gfui/kits/swts/Swt_text.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.GxwTextFld;
|
||||
import gplx.gfui.controls.standards.GfuiTextBox_;
|
||||
|
||||
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;
|
||||
|
||||
public class Swt_text implements GxwTextFld, Swt_control {
|
||||
private Text text_box;
|
||||
public Swt_text(Swt_control owner_control, Keyval_hash 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) {}
|
||||
}
|
||||
94
150_gfui/src/gplx/gfui/kits/swts/Swt_text_w_border.java
Normal file
94
150_gfui/src/gplx/gfui/kits/swts/Swt_text_w_border.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.GxwTextFld;
|
||||
import gplx.gfui.controls.standards.GfuiTextBox_;
|
||||
|
||||
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, Keyval_hash 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.Instance); // 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 Instance = new Swt_lnr_traverse_ignore_ctrl();
|
||||
}
|
||||
119
150_gfui/src/gplx/gfui/kits/swts/Swt_win.java
Normal file
119
150_gfui/src/gplx/gfui/kits/swts/Swt_win.java
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
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.kits.swts; import gplx.*; import gplx.gfui.*; import gplx.gfui.kits.*;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import gplx.Bool_;
|
||||
import gplx.Gfo_invk_cmd;
|
||||
import gplx.GfoMsg;
|
||||
import gplx.GfsCtx;
|
||||
import gplx.Io_url_;
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost;
|
||||
import gplx.gfui.controls.gxws.GxwCbkHost_;
|
||||
import gplx.gfui.controls.gxws.GxwCore_base;
|
||||
import gplx.gfui.controls.gxws.GxwElem;
|
||||
import gplx.gfui.controls.gxws.GxwWin;
|
||||
import gplx.gfui.imgs.IconAdp;
|
||||
import gplx.gfui.ipts.*;
|
||||
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;
|
||||
public 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(Gfo_invk_cmd v) {when_loaded_cmd = v;} private Gfo_invk_cmd when_loaded_cmd = Gfo_invk_cmd.Noop;
|
||||
public void Opened() {when_loaded_cmd.Exec();}
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user