private static Xex.Symbol Qtitle = "title";
private static Xex.Symbol Qeq = "=";
private static Xex.Symbol Qeqeq = "==";
+ private static Xex.Symbol Qcandidates_group_size = "candidates-group-size";
private static Xex.Term Tnil = new Xex.Term ((Xex.Symbol) "nil");
private static Xex.Term Tcatch_tag = new Xex.Term ((Xex.Symbol) "@mimtag");
group = new object[column];
}
- public Candidates (List<Xex.Term> list, int column)
+ public Candidates (Xex.Term[] candidates, int column)
{
- int nblocks = list.Count;
+ int nblocks = candidates.Length;
blocks = new Block[nblocks];
for (int i = 0, start = 0; i < nblocks; i++)
- start += (blocks[i] = new Block (index, list[i])).Count;
+ start += (blocks[i] = new Block (index, candidates[i])).Count;
if (column > 0)
group = new object[column];
}
if (branch_actions != null)
foreach (Xex.Term term in branch_actions)
mt.Cat (' ').Cat (term.ToString ());
- mt.Cat (')');
+ mt.Cat (')');
}
if (submaps != null)
foreach (KeyValuePair<Key, Keymap> kv in submaps)
KeySeq keyseq = new KeySeq ();
describe (mt, keyseq);
- mt.Cat (')');
return (string) mt;
}
}
XmlAttribute attr = node.Attributes[Qtitle];
if (attr != null)
title = (MText) attr.Value;
+ else
+ title = im.title;
keymap = new Keymap ();
for (node = node.FirstChild; node != null; node = node.NextSibling)
{
plist = plist.next;
if (plist.IsMText)
{
- this.title = plist.Text;
+ title = plist.Text;
plist = plist.next;
}
+ else
+ title = im.title;
keymap = new Keymap ();
for (; ! plist.IsEmpty; plist = plist.next)
{
private void add_default_state ()
{
Xex.Symbol Qinit = "init";
- State state = new State (Qinit, null);
+ State state = new State (Qinit, im.title);
foreach (KeyValuePair<MSymbol, Map>kv in maps)
state.keymap.AddMap (kv.Value, null);
states[Qinit] = initial_state = state;
private static Xex.Term Finsert (Xex.Domain domain, Xex.Variable vari,
Xex.Term[] args)
{
- ((Context) domain.context).insert (args[0]);
+ if (args[0].IsInt)
+ ((Context) domain.context).insert (args[0].Intval);
+ else
+ ((Context) domain.context).insert (args[0].Strval);
return args[0];
}
Xex.Variable vari,
Xex.Term[] args)
{
- ((Context) domain.context).insert_candidates (args[0]);
+ Context ic = (Context) domain.context;
+ Xex.Variable v = ic.domain.GetVar (Qcandidates_group_size, false);
+ int column = (v == null ? 0 : v.Value.Intval);
+
+ ic.insert_candidates (new Candidates (args, column));
return args[0];
}
}
private static Xex.Term Fdelete (Xex.Domain domain, Xex.Variable vari,
- Xex.Term[] args)
+ Xex.Term[] args)
{
- ((Context) domain.context).delete ((int) args[0].Intval);
+ Context ic = (Context) domain.context;
+ int pos;
+
+ if (args[0].IsInt)
+ pos = args[0].Intval;
+ else
+ {
+ Marker m = (Marker) args[0].Objval;
+ pos = m.Position (ic);
+ }
+ ic.delete (pos);
return args[0];
}
}
private static Xex.Term Fshow (Xex.Domain domain, Xex.Variable vari,
- Xex.Term[] args)
+ Xex.Term[] args)
{
((Context) domain.context).show ();
return Tnil;
}
private static Xex.Term Fhide (Xex.Domain domain, Xex.Variable vari,
- Xex.Term[] args)
+ Xex.Term[] args)
{
((Context) domain.context).hide ();
return Tnil;
}
private static Xex.Term Fmove (Xex.Domain domain, Xex.Variable vari,
- Xex.Term[] args)
+ Xex.Term[] args)
{
- if (args[0].IsInt)
- ((Context) domain.context).move (args[0].Intval);
- else
- {
- Marker m = (Marker) args[0].Objval;
- Context ic = (Context) domain.context;
- ((Context) domain.context).move (m.Position (ic));
- }
+ Context ic = (Context) domain.context;
+ int pos = (args[0].IsInt ? args[0].Intval
+ : ((Marker) args[0].Objval).Position (ic));
+ ic.move (pos);
return args[0];
}
public class Context
{
- internal static Xex.Symbol Qcandidates_group_size
- = "candidates-group-size";
internal MInputMethod im;
+ internal Xex.Domain domain;
private Dictionary<MSymbol, Callback> callbacks
= new Dictionary<MSymbol, Callback> ();
-
- private MText produced;
private bool active;
+
private MText status;
- internal MText preedit;
+ private MText produced = new MText ();
+ internal MText preedit = new MText ();
internal int cursor_pos;
internal Dictionary<Marker, int> marker_positions
= new Dictionary<Marker, int> ();
// Index into KEYS specifying the next key to handle.
internal int key_head;
-
private int state_key_head;
private object state_var_values;
private int commit_key_head;
// 'key_unhandled' is true.
private Key unhandled_key;
- internal Xex.Domain domain;
-
internal ChangedStatus changed;
+ internal void reset ()
+ {
+ status = im.initial_state.title;
+ produced.Del ();
+ preedit.Del ();
+ cursor_pos = 0;
+ marker_positions.Clear ();
+ candidates = null;
+ candidate_show = false;
+ keys.keyseq.Clear ();
+ state_preedit.Del ();
+ key_head = commit_key_head = 0;
+ state_list.Clear ();
+ state_list.Add (im.initial_state);
+ keymap = im.initial_state.keymap;
+ key_head = state_key_head = 0;
+ state_pos = 0;
+ }
+
static MPlist callback_arg = new MPlist ();
static Xex.Term[] catch_args = new Xex.Term[2];
adjust_markers (from, to, mt);
}
- internal void insert (Xex.Term arg)
+ internal void insert (int c)
{
- if (arg.IsInt)
- preedit_replace (cursor_pos, cursor_pos, arg.Intval);
- else
- preedit_replace (cursor_pos, cursor_pos, new MText (arg.Strval));
+ preedit_replace (cursor_pos, cursor_pos, c);
+ changed |= ChangedStatus.Preedit | ChangedStatus.CursorPos;
+ }
+
+ internal void insert (string str)
+ {
+ preedit_replace (cursor_pos, cursor_pos, (MText) str);
changed |= ChangedStatus.Preedit | ChangedStatus.CursorPos;
}
| CandidateAll);
}
- internal void insert_candidates (Xex.Term arg)
+ internal void insert_candidates (Candidates candidates)
{
- int column = 0;
- Xex.Variable v = domain.GetVar (Qcandidates_group_size, false);
-
- if (v != null)
- column = v.Value.Intval;
- candidates = new Candidates (arg.Listval, column);
+ this.candidates = candidates;
candidate_from = candidate_to = cursor_pos;
update_candidate ();
}
if (changed)
{
status = state.title;
- if (status == null)
- status = im.title;
this.changed |= ChangedStatus.StateTitle;
if (state.enter_actions != null)
take_action (state.enter_actions);
}
}
- internal void reset ()
- {
- preedit.Del ();
- state_preedit.Del ();
- produced.Del ();
- marker_positions.Clear ();
- cursor_pos = 0;
- keys.keyseq.Clear ();
- key_head = commit_key_head = 0;
- state_list.Clear ();
- state_list.Add (im.initial_state);
- keymap = im.initial_state.keymap;
- key_head = state_key_head = 0;
- state_pos = 0;
- }
-
public Context (MInputMethod im)
{
this.im = im;
domain = new Xex.Domain (im.domain, this);
reset ();
+ active = true;
}
public ChangedStatus Changed { get { return changed; } }
public bool Filter (Key key)
{
+ if (! active)
+ {
+ key_unhandled = true;
+ unhandled_key = key;
+ return false;
+ }
if (key == Key.Reload)
return true;
changed = ChangedStatus.None;