From e9e8c4141f02fb149da9772aeb0d7271ce542fff Mon Sep 17 00:00:00 2001 From: handa Date: Thu, 8 Oct 2009 13:05:15 +0000 Subject: [PATCH] *** empty log message *** --- MInputMethod.cs | 139 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 60 deletions(-) diff --git a/MInputMethod.cs b/MInputMethod.cs index 9e180d6..bd93150 100644 --- a/MInputMethod.cs +++ b/MInputMethod.cs @@ -75,6 +75,7 @@ namespace M17N.Input 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"); @@ -804,13 +805,13 @@ namespace M17N.Input group = new object[column]; } - public Candidates (List 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]; } @@ -1103,7 +1104,7 @@ namespace M17N.Input 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 kv in submaps) @@ -1120,7 +1121,6 @@ namespace M17N.Input KeySeq keyseq = new KeySeq (); describe (mt, keyseq); - mt.Cat (')'); return (string) mt; } } @@ -1144,6 +1144,8 @@ namespace M17N.Input 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) { @@ -1172,9 +1174,11 @@ namespace M17N.Input 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) { @@ -1378,7 +1382,7 @@ namespace M17N.Input private void add_default_state () { Xex.Symbol Qinit = "init"; - State state = new State (Qinit, null); + State state = new State (Qinit, im.title); foreach (KeyValuePairkv in maps) state.keymap.AddMap (kv.Value, null); states[Qinit] = initial_state = state; @@ -2071,7 +2075,10 @@ namespace M17N.Input 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]; } @@ -2079,7 +2086,11 @@ namespace M17N.Input 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]; } @@ -2093,9 +2104,19 @@ namespace M17N.Input } 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]; } @@ -2110,30 +2131,26 @@ namespace M17N.Input } 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]; } @@ -2259,16 +2276,15 @@ namespace M17N.Input public class Context { - internal static Xex.Symbol Qcandidates_group_size - = "candidates-group-size"; internal MInputMethod im; + internal Xex.Domain domain; private Dictionary callbacks = new Dictionary (); - - 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_positions = new Dictionary (); @@ -2286,7 +2302,6 @@ namespace M17N.Input // 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; @@ -2303,10 +2318,27 @@ namespace M17N.Input // '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]; @@ -2398,12 +2430,15 @@ namespace M17N.Input 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; } @@ -2428,14 +2463,9 @@ namespace M17N.Input | 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 (); } @@ -2604,8 +2634,6 @@ namespace M17N.Input 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); @@ -2613,27 +2641,12 @@ namespace M17N.Input } } - 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; } } @@ -2737,6 +2750,12 @@ namespace M17N.Input public bool Filter (Key key) { + if (! active) + { + key_unhandled = true; + unhandled_key = key; + return false; + } if (key == Key.Reload) return true; changed = ChangedStatus.None; -- 1.7.10.4