1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.3.4.1'

This commit is contained in:
gnosygnu
2016-03-27 23:44:59 -04:00
parent de67253a9c
commit baaef32df2
903 changed files with 13339 additions and 8695 deletions

View File

@@ -16,6 +16,9 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui;
import gplx.Byte_ascii;
import gplx.String_;
import org.eclipse.swt.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.custom.*;
@@ -23,6 +26,8 @@ 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.*;
@@ -30,8 +35,10 @@ public class Swt_app_main {
public static void main(String[] args) {
// Drag_drop();
// List_fonts();
// keystrokes(args);
Permission_denied();
keystrokes(args);
// Permission_denied();
// Combo_default();
// Combo_composite();
}
static void Drag_drop() {
final Display display = new Display();
@@ -197,4 +204,226 @@ public class Swt_app_main {
}
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);
}
}
}

View File

@@ -41,7 +41,7 @@ import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
class Swt_btn implements GxwElem, Swt_control {
private Button btn;
public Swt_btn(Swt_control owner, KeyValHash ctorArgs) {
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));
@@ -58,7 +58,7 @@ class Swt_btn implements GxwElem, Swt_control {
}
class Swt_btn_no_border implements GxwElem, Swt_control {
private ImageAdp btn_img; private Composite box_grp; private Label box_btn;
public Swt_btn_no_border(Swt_control owner_control, KeyValHash ctorArgs) {
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);

View 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;
import gplx.GfoEvMgr;
import gplx.GfoEvMgrOwner;
import gplx.GfoEvMgr_;
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 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, GfoEvMgrOwner {
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 GfoEvMgr EvMgr() {return ev_mgr;} private GfoEvMgr ev_mgr; public void EvMgr_(GfoEvMgr 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) {
GfoEvMgr_.Pub(combo, GfuiComboBox.Evt__selected_changed);
}
@Override public void widgetDefaultSelected(SelectionEvent arg0) {}
}

View File

@@ -0,0 +1,394 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.gfui;
import gplx.*;
import gplx.core.envs.Op_sys;
import gplx.core.envs.Op_sys_;
import gplx.core.threads.Thread_adp_;
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, GfoEvMgrOwner { // 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 GfoEvMgr EvMgr() {return ev_mgr;} private GfoEvMgr ev_mgr; public void EvMgr_(GfoEvMgr 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());
}
GfoEvMgr_.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());
GfoEvMgr_.Pub(ctrl, GfuiComboBox.Evt__selected_changed);
GfoEvMgr_.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);
}
}

View File

@@ -82,6 +82,17 @@ class Swt_lnr_key implements KeyListener {
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;
@@ -90,6 +101,7 @@ class Swt_lnr_key implements KeyListener {
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;
@@ -104,11 +116,15 @@ class Swt_lnr_key implements KeyListener {
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 (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));

View File

@@ -37,11 +37,11 @@ import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
class Swt_html implements Gxw_html, Swt_control, FocusListener {
private Swt_html_lnr_location lnr_location; private Swt_html_lnr_status lnr_status;
public Swt_html(Swt_kit kit, Swt_control owner_control, KeyValHash ctorArgs) {
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.FetchValOr(Swt_kit.Cfg_Html_BrowserType, null);
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);
@@ -52,6 +52,7 @@ class Swt_html implements Gxw_html, Swt_control, FocusListener {
browser.addStatusTextListener(lnr_status);
browser.addFocusListener(this);
browser.addTitleListener(new Swt_html_lnr_title(this));
// browser.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;
@@ -251,6 +252,13 @@ class Swt_html_lnr_mouse implements MouseListener {
return IptEvtDataMouse.new_(btn, IptMouseWheel_.None, ev.x, ev.y);
}
}
//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

View File

@@ -25,7 +25,7 @@ import org.eclipse.swt.widgets.Label;
class Swt_lbl implements GxwElem, Swt_control {
private Label lbl;
public Swt_lbl(Swt_control owner, KeyValHash ctorArgs) {
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));

View File

@@ -28,7 +28,7 @@ import org.eclipse.swt.widgets.*;
public class Swt_tab_mgr implements Gxw_tab_mgr, Swt_control, FocusListener, GfoEvMgrOwner {
private GfuiInvkCmd cmd_sync;
// private GfuiInvkCmd cmd_async; // NOTE: async needed for some actions like responding to key_down and calling .setSelection; else app hangs; DATE:2014-04-30
public Swt_tab_mgr(Swt_kit kit, Swt_control owner_control, KeyValHash ctorArgs) {
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);
@@ -113,7 +113,7 @@ public class Swt_tab_mgr implements Gxw_tab_mgr, Swt_control, FocusListener, Gfo
Gfui_tab_itm_data trg_tab_data = Get_tab_data(trg_tab_itm);
int src_tab_idx = src_tab_data.Idx(), trg_tab_idx = trg_tab_data.Idx();
tab_folder.setSelection(trg_tab_itm);
GfoEvMgr_.PubVals(this, Gfui_tab_mgr.Evt_tab_switched, KeyVal_.new_("src", src_tab_data.Key()), KeyVal_.new_("trg", trg_tab_data.Key()));
GfoEvMgr_.PubVals(this, Gfui_tab_mgr.Evt_tab_switched, Keyval_.new_("src", src_tab_data.Key()), Keyval_.new_("trg", trg_tab_data.Key()));
return src_tab_idx < trg_tab_idx;
}
public void Tabs_select_by_itm(CTabItem itm) {

View File

@@ -32,7 +32,7 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
class Swt_text implements GxwTextFld, Swt_control {
private Text text_box;
public Swt_text(Swt_control owner_control, KeyValHash ctorArgs) {
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

View File

@@ -34,7 +34,7 @@ public class Swt_text_w_border implements GxwTextFld, Swt_control {
private Composite text_host;
private Composite text_margin;
private Text text_elem;
public Swt_text_w_border(Swt_control owner_control, Color color, KeyValHash ctorArgs) {
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);
@@ -72,7 +72,7 @@ public class Swt_text_w_border implements GxwTextFld, Swt_control {
text_host = new Composite(shell, SWT.FLAT);
text_margin = new Composite(text_host, SWT.FLAT);
text_elem = new Text(text_margin, style);
text_elem .addTraverseListener(Swt_lnr_traverse_ignore_ctrl._); // do not allow ctrl+tab to change focus when pressed in text box; allows ctrl+tab to be used by other bindings; DATE:2014-04-30
text_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));
@@ -85,5 +85,5 @@ class Swt_lnr_traverse_ignore_ctrl implements TraverseListener {
public void keyTraversed(TraverseEvent e) {
if (Swt_lnr_key.Has_ctrl(e.stateMask)) e.doit = false;
}
public static final Swt_lnr_traverse_ignore_ctrl _ = new Swt_lnr_traverse_ignore_ctrl();
public static final Swt_lnr_traverse_ignore_ctrl Instance = new Swt_lnr_traverse_ignore_ctrl();
}