mirror of
https://github.com/gnosygnu/xowa.git
synced 2026-03-02 03:49:30 +00:00
'v3.6.3.1'
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
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.controls.windows; import gplx.*; import gplx.gfui.*; import gplx.gfui.controls.*;
|
||||
import gplx.core.interfaces.*;
|
||||
import gplx.gfui.ipts.*; import gplx.gfui.controls.elems.*; import gplx.gfui.controls.tabs.*;
|
||||
public class GfuiFocusXferBnd implements InjectAble, Gfo_invk {
|
||||
public void Inject(Object owner) {
|
||||
GfuiElem elem = GfuiElem_.cast(owner);
|
||||
IptBnd_.cmd_to_(IptCfg_.Null, elem, this, Invk_FocusNext, IptKey_.Down);
|
||||
IptBnd_.cmd_to_(IptCfg_.Null, elem, this, Invk_FocusPrev, IptKey_.Up);
|
||||
}
|
||||
@gplx.Internal protected void Focus(GfuiElem cur, boolean fwd) {
|
||||
List_adp allElemsInOwnerWin = List_adp_.New(); AddSubs(cur.OwnerWin(), allElemsInOwnerWin);
|
||||
int curIdx = allElemsInOwnerWin.Idx_of(cur);
|
||||
GfuiElem target = cur;
|
||||
while (true) { // find next visible elem
|
||||
int cycle = TabBox_.Cycle(fwd, curIdx, allElemsInOwnerWin.Count());
|
||||
target = GfuiElem_.cast(allElemsInOwnerWin.Get_at(cycle));
|
||||
if (target.Visible()) break;
|
||||
if (cycle == curIdx) break; // either (a) one elem in allElemsInOwnerWin or (b) n elems, and cycled back to start; break, else infinite loop
|
||||
curIdx = cycle;
|
||||
}
|
||||
target.Focus();
|
||||
}
|
||||
void AddSubs(GfuiElem owner, List_adp allElemsInOwnerWin) {
|
||||
for (int i = 0; i < owner.SubElems().Count(); i++) {
|
||||
GfuiElemBase sub = (GfuiElemBase)owner.SubElems().Get_at(i);
|
||||
if (sub.Click_able()) allElemsInOwnerWin.Add(sub);
|
||||
AddSubs(sub, allElemsInOwnerWin);
|
||||
}
|
||||
}
|
||||
public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
|
||||
if (ctx.Match(k, Invk_FocusNext)) Focus(GfuiElem_.cast(ctx.MsgSrc()), true);
|
||||
else if (ctx.Match(k, Invk_FocusPrev)) Focus(GfuiElem_.cast(ctx.MsgSrc()), false);
|
||||
else return Gfo_invk_.Rv_unhandled;
|
||||
return this;
|
||||
} public static final String Invk_FocusNext = "FocusNext", Invk_FocusPrev = "FocusPrev";
|
||||
public static final GfuiFocusXferBnd Instance = new GfuiFocusXferBnd(); GfuiFocusXferBnd() {}
|
||||
}
|
||||
Reference in New Issue
Block a user