Пример #1
0
 public ComplexConcPatternModel(LcmCache cache, ComplexConcPatternNode root)
 {
     m_cache       = cache;
     m_root        = root;
     m_spanFactory = new ShapeSpanFactory();
     m_sda         = new ComplexConcPatternSda((ISilDataAccessManaged)cache.DomainDataByFlid, m_root);
 }
Пример #2
0
        private bool CanAddConstraint(object option)
        {
            if (m_patternModel.Root.IsLeaf)
            {
                return(true);
            }

            SelectionHelper        sel        = SelectionHelper.Create(m_view);
            ComplexConcPatternNode anchorNode = GetNode(sel, SelectionHelper.SelLimitType.Anchor);
            ComplexConcPatternNode endNode    = GetNode(sel, SelectionHelper.SelLimitType.End);

            if (anchorNode == null || endNode == null || anchorNode.Parent != endNode.Parent)
            {
                return(false);
            }

            ComplexConcPatternNode parent;
            int start, end;

            if (!sel.IsRange)
            {
                int index;
                GetInsertionIndex(sel, out parent, out index);
                start = index - 1;
                end   = index;
            }
            else
            {
                parent = anchorNode.Parent;
                start  = (sel.Selection.EndBeforeAnchor ? GetNodeIndex(endNode) : GetNodeIndex(anchorNode)) - 1;
                end    = (sel.Selection.EndBeforeAnchor ? GetNodeIndex(anchorNode) : GetNodeIndex(endNode)) + 1;
            }

            return((start == -1 || !(parent.Children[start] is ComplexConcWordBdryNode)) && (end == parent.Children.Count || !(parent.Children[end] is ComplexConcWordBdryNode)));
        }
		public ComplexConcPatternModel(FdoCache cache, ComplexConcPatternNode root)
		{
			m_cache = cache;
			m_root = root;
			m_spanFactory = new ShapeSpanFactory();
			m_sda = new ComplexConcPatternSda((ISilDataAccessManaged) cache.DomainDataByFlid, m_root);
		}
Пример #4
0
 public ComplexConcPatternSda(ISilDataAccessManaged domainDataByFlid, ComplexConcPatternNode root)
     : base(domainDataByFlid)
 {
     SetOverrideMdc(new ComplexConcordancePatternMdc((IFwMetaDataCacheManaged)domainDataByFlid.MetaDataCache));
     m_nodes    = new Dictionary <int, ComplexConcPatternNode>();
     m_root     = root;
     m_root.Sda = this;
 }
Пример #5
0
 private int GetNodeIndex(ComplexConcPatternNode node)
 {
     if (node.Parent == null)
     {
         return(0);
     }
     return(node.Parent.Children.IndexOf(node));
 }
Пример #6
0
		public ComplexConcPatternSda(ISilDataAccessManaged domainDataByFlid, ComplexConcPatternNode root)
			: base(domainDataByFlid)
		{
			SetOverrideMdc(new ComplexConcordancePatternMdc((IFwMetaDataCacheManaged) domainDataByFlid.MetaDataCache));
			m_nodes = new Dictionary<int, ComplexConcPatternNode>();
			m_root = root;
			m_root.Sda = this;
		}
Пример #7
0
        public bool OnPatternNodeGroup(object args)
        {
            CheckDisposed();
            ComplexConcPatternNode[] nodes = CurrentNodes;
            ComplexConcPatternNode   group = GroupNodes(nodes);

            ReconstructView(group, false);
            return(true);
        }
Пример #8
0
        public bool OnPatternNodeSetOccurrence(object args)
        {
            CheckDisposed();

            ComplexConcPatternNode[] nodes = CurrentNodes;

            int min, max;
            var cmd = (Command)args;

            if (cmd.Parameters.Count > 0)
            {
                string minStr = XmlUtils.GetManditoryAttributeValue(cmd.Parameters[0], "min");
                string maxStr = XmlUtils.GetManditoryAttributeValue(cmd.Parameters[0], "max");
                min = Int32.Parse(minStr);
                max = Int32.Parse(maxStr);
            }
            else
            {
                bool paren;
                if (nodes.Length > 1)
                {
                    min   = 1;
                    max   = 1;
                    paren = true;
                }
                else
                {
                    min   = nodes[0].Minimum;
                    max   = nodes[0].Maximum;
                    paren = !nodes[0].IsLeaf;
                }
                using (OccurrenceDlg dlg = new OccurrenceDlg(m_mediator.HelpTopicProvider, min, max, paren))
                {
                    dlg.SetHelpTopic("khtpCtxtOccurComplexConcordance");
                    if (dlg.ShowDialog((XWindow)m_mediator.PropertyTable.GetValue("window")) == DialogResult.OK)
                    {
                        min = dlg.Minimum;
                        max = dlg.Maximum;
                    }
                    else
                    {
                        return(true);
                    }
                }
            }

            ComplexConcPatternNode node = nodes.Length > 1 ? GroupNodes(nodes) : nodes[0];

            node.Minimum = min;
            node.Maximum = max;
            ReconstructView(node, false);
            return(true);
        }
Пример #9
0
        private ComplexConcPatternNode GroupNodes(ComplexConcPatternNode[] nodes)
        {
            ComplexConcPatternNode parent = nodes[0].Parent;
            int index = GetNodeIndex(nodes[0]);
            ComplexConcGroupNode group = new ComplexConcGroupNode();

            parent.Children.Insert(index, group);
            foreach (ComplexConcPatternNode node in nodes)
            {
                parent.Children.Remove(node);
                group.Children.Add(node);
            }
            return(group);
        }
Пример #10
0
        private IEnumerable <ComplexConcPatternNode> GetAllNodes(ComplexConcPatternNode node)
        {
            yield return(node);

            if (!node.IsLeaf)
            {
                foreach (ComplexConcPatternNode child in node.Children)
                {
                    foreach (ComplexConcPatternNode n in GetAllNodes(child))
                    {
                        yield return(n);
                    }
                }
            }
        }
Пример #11
0
        public override int get_VecSize(int hvo, int tag)
        {
            switch (tag)
            {
            case ktagChildren:
                ComplexConcPatternNode node = m_nodes[hvo];
                if (node.IsLeaf)
                {
                    return(0);
                }
                return(node.Children.Count);

            default:
                return(base.get_VecSize(hvo, tag));
            }
        }
Пример #12
0
        public override int[] VecProp(int hvo, int tag)
        {
            switch (tag)
            {
            case ktagChildren:
                ComplexConcPatternNode node = m_nodes[hvo];
                if (node.IsLeaf)
                {
                    return(new int[0]);
                }
                return(node.Children.Select(n => n.Hvo).ToArray());

            default:
                return(base.VecProp(hvo, tag));
            }
        }
Пример #13
0
        public SelLevInfo[] GetLevelInfo(object ctxt, int cellIndex)
        {
            List <SelLevInfo> levels = new List <SelLevInfo>();

            if (!m_patternModel.Root.IsLeaf)
            {
                ComplexConcPatternNode node = (ComplexConcPatternNode)ctxt;
                int i = cellIndex;
                while (node != null)
                {
                    levels.Add(new SelLevInfo {
                        tag = ComplexConcPatternSda.ktagChildren, ihvo = i
                    });
                    i    = GetNodeIndex(node);
                    node = node.Parent;
                }
            }
            return(levels.ToArray());
        }
Пример #14
0
        private bool CanAddMorph(object option)
        {
            if (m_patternModel.Root.IsLeaf)
            {
                return(true);
            }

            SelectionHelper sel = SelectionHelper.Create(m_view);

            if (sel.IsRange)
            {
                return(true);
            }

            ComplexConcPatternNode anchorNode = GetNode(sel, SelectionHelper.SelLimitType.Anchor);
            ComplexConcPatternNode endNode    = GetNode(sel, SelectionHelper.SelLimitType.End);

            return(anchorNode != null && endNode != null && anchorNode.Parent == endNode.Parent);
        }
Пример #15
0
        private void GetInsertionIndex(SelectionHelper sel, out ComplexConcPatternNode parent, out int index)
        {
            ComplexConcPatternNode curNode = GetNode(sel, SelectionHelper.SelLimitType.Top);

            if (m_patternModel.Root.IsLeaf || curNode == null)
            {
                parent = m_patternModel.Root;
                index  = 0;
                return;
            }

            parent = curNode.Parent;
            int ich = sel.GetIch(SelectionHelper.SelLimitType.Top);

            index = GetNodeIndex(curNode);
            if (ich != 0)
            {
                index++;
            }
        }
Пример #16
0
        private void ContextMenuRequested(object sender, ContextMenuRequestedEventArgs e)
        {
            SelectionHelper                  sh    = SelectionHelper.Create(e.Selection, m_view);
            ComplexConcPatternNode           node  = GetNode(sh, SelectionHelper.SelLimitType.Anchor);
            HashSet <ComplexConcPatternNode> nodes = new HashSet <ComplexConcPatternNode>(CurrentNodes.SelectMany(GetAllNodes));

            if (!nodes.Contains(node))
            {
                sh.Selection.Install();
            }
            if (nodes.Count > 0)
            {
                // we only bother to display the context menu if an item is selected
                XWindow window = (XWindow)m_mediator.PropertyTable.GetValue("window");

                window.ShowContextMenu("mnuComplexConcordance",
                                       new Point(Cursor.Position.X, Cursor.Position.Y),
                                       new TemporaryColleagueParameter(m_mediator, this, true),
                                       null, null);
            }
        }
Пример #17
0
		private void GetInsertionIndex(SelectionHelper sel, out ComplexConcPatternNode parent, out int index)
		{
			ComplexConcPatternNode curNode = GetNode(sel, SelectionHelper.SelLimitType.Top);
			if (m_patternModel.Root.IsLeaf || curNode == null)
			{
				parent = m_patternModel.Root;
				index = 0;
				return;
			}

			parent = curNode.Parent;
			int ich = sel.GetIch(SelectionHelper.SelLimitType.Top);
			index = GetNodeIndex(curNode);
			if (ich != 0)
				index++;
		}
Пример #18
0
		private IEnumerable<ComplexConcPatternNode> GetAllNodes(ComplexConcPatternNode node)
		{
			yield return node;
			if (!node.IsLeaf)
			{
				foreach (ComplexConcPatternNode child in node.Children)
				{
					foreach (ComplexConcPatternNode n in GetAllNodes(child))
						yield return n;
				}
			}
		}
Пример #19
0
		private int GetNodeIndex(ComplexConcPatternNode node)
		{
			if (node.Parent == null)
				return 0;
			return node.Parent.Children.IndexOf(node);
		}
Пример #20
0
		/// <summary>
		/// Moves the cursor to the specified position in the specified cell.
		/// </summary>
		/// <param name="parent"></param>
		/// <param name="index">Index of the item in the cell.</param>
		/// <param name="initial">if <c>true</c> move the cursor to the beginning of the specified item, otherwise it is moved to the end</param>
		/// <param name="editable">if <c>true</c> move the cursor to the first editable position</param>
		/// <param name="install">if <c>true</c> install the selection</param>
		/// <returns>The new selection</returns>
		private IVwSelection SelectAt(ComplexConcPatternNode parent, int index, bool initial, bool editable, bool install)
		{
			SelLevInfo[] levels = GetLevelInfo(parent, index);
			return m_view.RootBox.MakeTextSelInObj(0, levels.Length, levels, 0, null, initial, editable, false, false, install);
		}
Пример #21
0
        private int GetMaxNumLines(IVwEnv vwenv)
        {
            ComplexConcPatternNode root = ((ComplexConcPatternSda)vwenv.DataAccess).Root;

            return(GetNumLines(root));
        }
Пример #22
0
        private void DisplayFeatures(IVwEnv vwenv, ComplexConcPatternNode node)
        {
            vwenv.AddProp(ktagType, this, kfragFeatureLine);
            var morphNode = node as ComplexConcMorphNode;

            if (morphNode != null)
            {
                if (morphNode.Form != null)
                {
                    vwenv.AddProp(ktagForm, this, kfragFeatureLine);
                }
                if (morphNode.Entry != null)
                {
                    vwenv.AddProp(ktagEntry, this, kfragFeatureLine);
                }
                if (morphNode.Category != null)
                {
                    vwenv.AddProp(ktagCategory, this, kfragFeatureLine);
                }
                if (morphNode.Gloss != null)
                {
                    vwenv.AddProp(ktagGloss, this, kfragFeatureLine);
                }
                if (morphNode.InflFeatures.Count > 0)
                {
                    vwenv.OpenParagraph();
                    vwenv.AddProp(ktagInfl, this, kfragFeatureLine);
                    DisplayInflFeatures(vwenv, morphNode.InflFeatures);
                    vwenv.CloseParagraph();
                }
            }
            else
            {
                var wordNode = node as ComplexConcWordNode;
                if (wordNode != null)
                {
                    if (wordNode.Form != null)
                    {
                        vwenv.AddProp(ktagForm, this, kfragFeatureLine);
                    }
                    if (wordNode.Category != null)
                    {
                        vwenv.AddProp(ktagCategory, this, kfragFeatureLine);
                    }
                    if (wordNode.Gloss != null)
                    {
                        vwenv.AddProp(ktagGloss, this, kfragFeatureLine);
                    }
                    if (wordNode.InflFeatures.Count > 0)
                    {
                        vwenv.OpenParagraph();
                        vwenv.AddProp(ktagInfl, this, kfragFeatureLine);
                        DisplayInflFeatures(vwenv, wordNode.InflFeatures);
                        vwenv.CloseParagraph();
                    }
                }
                else
                {
                    var tagNode = node as ComplexConcTagNode;
                    if (tagNode != null)
                    {
                        if (tagNode.Tag != null)
                        {
                            vwenv.AddProp(ktagTag, this, kfragFeatureLine);
                        }
                    }
                }
            }
        }
Пример #23
0
        public object GetContext(SelectionHelper sel, SelectionHelper.SelLimitType limit)
        {
            ComplexConcPatternNode node = GetNode(sel, limit);

            return(node == null ? null : node.Parent);
        }
Пример #24
0
        private void RemoveItemsRequested(object sender, RemoveItemsRequestedEventArgs e)
        {
            if (m_patternModel.Root.IsLeaf)
            {
                return;
            }

            SelectionHelper        sel    = SelectionHelper.Create(m_view);
            ComplexConcPatternNode parent = null;
            int index = -1;

            if (sel.IsRange)
            {
                ComplexConcPatternNode[] nodes = CurrentNodes;
                if (nodes.Length > 0)
                {
                    parent = nodes[0].Parent;
                    index  = GetNodeIndex(nodes[0]);
                    foreach (ComplexConcPatternNode node in nodes)
                    {
                        node.Parent.Children.Remove(node);
                    }
                }
            }
            else
            {
                ComplexConcPatternNode n = GetNode(sel, SelectionHelper.SelLimitType.Top);
                parent = n.Parent;
                index  = GetNodeIndex(n);
                ITsString tss = sel.GetTss(SelectionHelper.SelLimitType.Anchor);
                // if the current ich is at the end of the current string, then we can safely assume
                // we are at the end of the current item, so remove it or the next item based on what
                // key was pressed, otherwise we are in the middle in which
                // case the entire item is selected, or at the beginning, so we remove it or the previous
                // item based on what key was pressed
                if (sel.IchAnchor == tss.Length)
                {
                    if (e.Forward)
                    {
                        if (index == n.Parent.Children.Count - 1)
                        {
                            index = -1;
                        }
                        else
                        {
                            index++;
                        }
                    }
                }
                else
                {
                    if (!e.Forward)
                    {
                        index--;
                    }
                }

                if (index != -1)
                {
                    parent.Children.RemoveAt(index);
                }
            }

            if (parent != null && index != -1)
            {
                if (!parent.IsLeaf)
                {
                    bool isFirstBdry = parent.Children[0] is ComplexConcWordBdryNode;
                    if ((parent.Children.Count == 1 && isFirstBdry) ||
                        (parent.Children.Count > 1 && isFirstBdry && !(parent.Children[1] is ComplexConcMorphNode)))
                    {
                        parent.Children.RemoveAt(0);
                        if (index > 0)
                        {
                            index--;
                        }
                    }
                }
                if (parent.Children.Count > 1 && parent.Children[parent.Children.Count - 1] is ComplexConcWordBdryNode &&
                    !(parent.Children[parent.Children.Count - 2] is ComplexConcMorphNode))
                {
                    parent.Children.RemoveAt(parent.Children.Count - 1);
                    if (index >= parent.Children.Count)
                    {
                        index--;
                    }
                }
                for (int i = parent.Children.Count - 1; i > 0; i--)
                {
                    if (parent.Children[i] is ComplexConcWordBdryNode)
                    {
                        if (parent.Children[i - 1] is ComplexConcWordBdryNode ||
                            (!(parent.Children[i - 1] is ComplexConcMorphNode) || (i + 1 < parent.Children.Count && !(parent.Children[i + 1] is ComplexConcMorphNode))))
                        {
                            parent.Children.RemoveAt(i);
                            if (index > i)
                            {
                                index--;
                            }
                        }
                    }
                }

                if (!parent.IsLeaf && parent.Children[0] is ComplexConcOrNode)
                {
                    parent.Children.RemoveAt(0);
                    if (index > 0)
                    {
                        index--;
                    }
                }
                if (!parent.IsLeaf && parent.Children[parent.Children.Count - 1] is ComplexConcOrNode)
                {
                    parent.Children.RemoveAt(parent.Children.Count - 1);
                    if (index >= parent.Children.Count)
                    {
                        index--;
                    }
                }
                for (int i = parent.Children.Count - 1; i > 0; i--)
                {
                    if (parent.Children[i] is ComplexConcOrNode && parent.Children[i - 1] is ComplexConcOrNode)
                    {
                        parent.Children.RemoveAt(i);
                        if (index > i)
                        {
                            index--;
                        }
                    }
                }

                if (parent.Parent != null && parent.Children.Count == 1)
                {
                    ComplexConcPatternNode p = parent.Parent;
                    int parentIndex          = GetNodeIndex(parent);
                    p.Children.RemoveAt(parentIndex);
                    p.Children.Insert(parentIndex, parent.Children[0]);
                    index = index == 1 ? parentIndex + 1 : parentIndex;
                }
                else
                {
                    while (parent.Parent != null && parent.IsLeaf)
                    {
                        ComplexConcPatternNode p = parent.Parent;
                        index = GetNodeIndex(parent);
                        p.Children.Remove(parent);
                        parent = p;
                    }
                }

                if (index >= parent.Children.Count)
                {
                    ReconstructView(parent, parent.Children.Count - 1, false);
                }
                else
                {
                    ReconstructView(parent, index, true);
                }
            }
        }
Пример #25
0
 private void ReconstructView(ComplexConcPatternNode node, bool initial)
 {
     ReconstructView(node.Parent, GetNodeIndex(node), initial);
 }
Пример #26
0
		private void SelectRightBoundary(ComplexConcPatternNode parent, int index, bool install)
		{
			try
			{
				SelLevInfo[] levels = GetLevelInfo(parent, index);
				m_view.RootBox.MakeTextSelection(0, levels.Length, levels, ComplexConcPatternVc.ktagRightBoundary, 0, 1, 1,
					0, false, -1, null, install);
			}
			catch
			{
			}
		}
Пример #27
0
        private void m_insertControl_Insert(object sender, InsertEventArgs e)
        {
            ComplexConcPatternNode node = null;

            switch (((InsertOption)e.Option).Type)
            {
            case ComplexConcordanceInsertType.Morph:
                using (ComplexConcMorphDlg dlg = new ComplexConcMorphDlg())
                {
                    ComplexConcMorphNode morphNode = new ComplexConcMorphNode();
                    dlg.SetDlgInfo(m_cache, m_mediator, morphNode);
                    if (dlg.ShowDialog((XWindow)m_mediator.PropertyTable.GetValue("window")) == DialogResult.OK)
                    {
                        node = morphNode;
                    }
                }
                break;

            case ComplexConcordanceInsertType.Word:
                using (ComplexConcWordDlg dlg = new ComplexConcWordDlg())
                {
                    ComplexConcWordNode wordNode = new ComplexConcWordNode();
                    dlg.SetDlgInfo(m_cache, m_mediator, wordNode);
                    if (dlg.ShowDialog((XWindow)m_mediator.PropertyTable.GetValue("window")) == DialogResult.OK)
                    {
                        node = wordNode;
                    }
                }
                break;

            case ComplexConcordanceInsertType.TextTag:
                using (ComplexConcTagDlg dlg = new ComplexConcTagDlg())
                {
                    ComplexConcTagNode tagNode = new ComplexConcTagNode();
                    dlg.SetDlgInfo(m_cache, m_mediator, tagNode);
                    if (dlg.ShowDialog((XWindow)m_mediator.PropertyTable.GetValue("window")) == DialogResult.OK)
                    {
                        node = tagNode;
                    }
                }
                break;

            case ComplexConcordanceInsertType.Or:
                node = new ComplexConcOrNode();
                break;

            case ComplexConcordanceInsertType.WordBoundary:
                node = new ComplexConcWordBdryNode();
                break;
            }

            m_view.Select();

            if (node == null)
            {
                return;
            }

            SelectionHelper sel = SelectionHelper.Create(m_view);

            ComplexConcPatternNode parent;
            int index;

            GetInsertionIndex(sel, out parent, out index);
            // if the current selection is a range remove the items we are overwriting
            if (sel.IsRange)
            {
                foreach (ComplexConcPatternNode n in CurrentNodes)
                {
                    n.Parent.Children.Remove(n);
                }
            }

            parent.Children.Insert(index, node);
            ReconstructView(parent, index, false);
        }
Пример #28
0
 /// <summary>
 /// Reconstructs the view and moves the cursor the specified position.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="index">Index of the item in the cell.</param>
 /// <param name="initial">if <c>true</c> move the cursor to the beginning of the specified item, otherwise it is moved to the end</param>
 private void ReconstructView(ComplexConcPatternNode parent, int index, bool initial)
 {
     m_view.RootBox.Reconstruct();
     m_view.SelectAt(parent, index, initial, true, true);
 }
Пример #29
0
		private ComplexConcPatternNode GroupNodes(ComplexConcPatternNode[] nodes)
		{
			ComplexConcPatternNode parent = nodes[0].Parent;
			int index = GetNodeIndex(nodes[0]);
			ComplexConcGroupNode group = new ComplexConcGroupNode();
			parent.Children.Insert(index, group);
			foreach (ComplexConcPatternNode node in nodes)
			{
				parent.Children.Remove(node);
				group.Children.Add(node);
			}
			return group;
		}
Пример #30
0
        public override ITsString DisplayVariant(IVwEnv vwenv, int tag, int frag)
        {
            // we use display variant to display literal strings that are editable
            ITsString tss = null;

            switch (frag)
            {
            case kfragFeatureLine:
                ComplexConcPatternNode node = ((ComplexConcPatternSda)vwenv.DataAccess).Nodes[vwenv.CurrentObject()];
                switch (tag)
                {
                case ktagType:
                    string typeStr = null;
                    if (node is ComplexConcMorphNode)
                    {
                        typeStr = ITextStrings.ksComplexConcMorph;
                    }
                    else if (node is ComplexConcWordNode)
                    {
                        typeStr = ITextStrings.ksComplexConcWord;
                    }
                    else if (node is ComplexConcTagNode)
                    {
                        typeStr = ITextStrings.ksComplexConcTag;
                    }
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcType, typeStr, m_cache.DefaultUserWs);
                    break;

                case ktagForm:
                    ITsString form          = null;
                    var       formMorphNode = node as ComplexConcMorphNode;
                    if (formMorphNode != null)
                    {
                        form = formMorphNode.Form;
                    }
                    else
                    {
                        var formWordNode = node as ComplexConcWordNode;
                        if (formWordNode != null)
                        {
                            form = formWordNode.Form;
                        }
                    }
                    Debug.Assert(form != null);
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcForm, form, false);
                    break;

                case ktagEntry:
                    ITsString entry          = null;
                    var       entryMorphNode = node as ComplexConcMorphNode;
                    if (entryMorphNode != null)
                    {
                        entry = entryMorphNode.Entry;
                    }
                    Debug.Assert(entry != null);
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcEntry, entry, false);
                    break;

                case ktagGloss:
                    ITsString gloss          = null;
                    var       glossMorphNode = node as ComplexConcMorphNode;
                    if (glossMorphNode != null)
                    {
                        gloss = glossMorphNode.Gloss;
                    }
                    else
                    {
                        var glossWordNode = node as ComplexConcWordNode;
                        if (glossWordNode != null)
                        {
                            gloss = glossWordNode.Gloss;
                        }
                    }
                    Debug.Assert(gloss != null);
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcGloss, gloss, false);
                    break;

                case ktagCategory:
                    IPartOfSpeech category     = null;
                    bool          catNegated   = false;
                    var           catMorphNode = node as ComplexConcMorphNode;
                    if (catMorphNode != null)
                    {
                        category   = catMorphNode.Category;
                        catNegated = catMorphNode.NegateCategory;
                    }
                    else
                    {
                        var catWordNode = node as ComplexConcWordNode;
                        if (catWordNode != null)
                        {
                            category   = catWordNode.Category;
                            catNegated = catWordNode.NegateCategory;
                        }
                    }
                    Debug.Assert(category != null);
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcCategory, category.Abbreviation.BestAnalysisAlternative, catNegated);
                    break;

                case ktagTag:
                    ICmPossibility tagPoss = null;
                    var            tagNode = node as ComplexConcTagNode;
                    if (tagNode != null)
                    {
                        tagPoss = tagNode.Tag;
                    }
                    Debug.Assert(tagPoss != null);
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcTag, tagPoss.Abbreviation.BestAnalysisAlternative, false);
                    break;

                case ktagInfl:
                    tss = CreateFeatureLine(ITextStrings.ksComplexConcInflFeatures, null, false);
                    break;

                default:
                    IFsFeatDefn feature = m_curInflFeatures.Keys.Single(f => f.Hvo == tag);
                    if (feature is IFsComplexFeature)
                    {
                        tss = CreateFeatureLine(feature.Abbreviation.BestAnalysisAlternative, null, false);
                    }
                    else if (feature is IFsClosedFeature)
                    {
                        var value = (ClosedFeatureValue)m_curInflFeatures[feature];
                        tss = CreateFeatureLine(feature.Abbreviation.BestAnalysisAlternative, value.Symbol.Abbreviation.BestAnalysisAlternative, value.Negate);
                    }
                    break;
                }
                break;

            case kfragNodeMax:
                // if the max value is -1, it indicates that it is infinite
                ComplexConcPatternNode node1 = ((ComplexConcPatternSda)vwenv.DataAccess).Nodes[vwenv.CurrentObject()];
                tss = node1.Maximum == -1 ? m_infinity : m_cache.TsStrFactory.MakeString(node1.Maximum.ToString(CultureInfo.InvariantCulture), m_cache.DefaultUserWs);
                break;

            case kfragNodeMin:
                ComplexConcPatternNode node2 = ((ComplexConcPatternSda)vwenv.DataAccess).Nodes[vwenv.CurrentObject()];
                tss = m_cache.TsStrFactory.MakeString(node2.Minimum.ToString(CultureInfo.InvariantCulture), m_cache.DefaultUserWs);
                break;

            case kfragOR:
                tss = m_or;
                break;

            case kfragHash:
                tss = m_hash;
                break;

            default:
                tss = base.DisplayVariant(vwenv, tag, frag);
                break;
            }
            return(tss);
        }
Пример #31
0
		private void DisplayFeatures(IVwEnv vwenv, ComplexConcPatternNode node)
		{
			vwenv.AddProp(ktagType, this, kfragFeatureLine);
			var morphNode = node as ComplexConcMorphNode;
			if (morphNode != null)
			{
				if (morphNode.Form != null)
					vwenv.AddProp(ktagForm, this, kfragFeatureLine);
				if (morphNode.Entry != null)
					vwenv.AddProp(ktagEntry, this, kfragFeatureLine);
				if (morphNode.Category != null)
					vwenv.AddProp(ktagCategory, this, kfragFeatureLine);
				if (morphNode.Gloss != null)
					vwenv.AddProp(ktagGloss, this, kfragFeatureLine);
				if (morphNode.InflFeatures.Count > 0)
				{
					vwenv.OpenParagraph();
					vwenv.AddProp(ktagInfl, this, kfragFeatureLine);
					DisplayInflFeatures(vwenv, morphNode.InflFeatures);
					vwenv.CloseParagraph();
				}
			}
			else
			{
				var wordNode = node as ComplexConcWordNode;
				if (wordNode != null)
				{
					if (wordNode.Form != null)
						vwenv.AddProp(ktagForm, this, kfragFeatureLine);
					if (wordNode.Category != null)
						vwenv.AddProp(ktagCategory, this, kfragFeatureLine);
					if (wordNode.Gloss != null)
						vwenv.AddProp(ktagGloss, this, kfragFeatureLine);
					if (wordNode.InflFeatures.Count > 0)
					{
						vwenv.OpenParagraph();
						vwenv.AddProp(ktagInfl, this, kfragFeatureLine);
						DisplayInflFeatures(vwenv, wordNode.InflFeatures);
						vwenv.CloseParagraph();
					}
				}
				else
				{
					var tagNode = node as ComplexConcTagNode;
					if (tagNode != null)
					{
						if (tagNode.Tag != null)
							vwenv.AddProp(ktagTag, this, kfragFeatureLine);
					}
				}
			}
		}
Пример #32
0
        public override void Display(IVwEnv vwenv, int hvo, int frag)
        {
            switch (frag)
            {
            case kfragPattern:
                VwLength tableLen;
                tableLen.nVal = 10000;
                tableLen.unit = VwUnit.kunPercent100;
                vwenv.OpenTable(1, tableLen, 0, VwAlignment.kvaCenter, VwFramePosition.kvfpVoid, VwRule.kvrlNone, 0, 0, false);
                VwLength patternLen;
                patternLen.nVal = 1;
                patternLen.unit = VwUnit.kunRelative;
                vwenv.MakeColumns(1, patternLen);
                vwenv.OpenTableBody();
                vwenv.OpenTableRow();

                vwenv.set_IntProperty((int)FwTextPropType.ktptBorderBottom, (int)FwTextPropVar.ktpvMilliPoint, 1000);
                vwenv.set_IntProperty((int)FwTextPropType.ktptBorderColor, (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Gray));
                vwenv.set_IntProperty((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
                vwenv.set_IntProperty((int)FwTextPropType.ktptPadBottom, (int)FwTextPropVar.ktpvMilliPoint, 2000);
                vwenv.OpenTableCell(1, 1);
                vwenv.OpenParagraph();
                if (((ComplexConcPatternSda)vwenv.DataAccess).Root.IsLeaf)
                {
                    OpenSingleLinePile(vwenv, GetMaxNumLines(vwenv), false);
                    vwenv.Props = m_bracketProps;
                    vwenv.AddProp(ComplexConcPatternSda.ktagChildren, this, kfragEmpty);
                    CloseSingleLinePile(vwenv, false);
                }
                else
                {
                    vwenv.AddObjVecItems(ComplexConcPatternSda.ktagChildren, this, kfragNode);
                }
                vwenv.CloseParagraph();
                vwenv.CloseTableCell();

                vwenv.CloseTableRow();
                vwenv.CloseTableBody();
                vwenv.CloseTable();
                break;

            case kfragNode:
                ComplexConcPatternNode node = ((ComplexConcPatternSda)vwenv.DataAccess).Nodes[hvo];
                int maxNumLines             = GetMaxNumLines(vwenv);
                if (node is ComplexConcOrNode)
                {
                    OpenSingleLinePile(vwenv, maxNumLines);
                    vwenv.AddProp(ktagInnerNonBoundary, this, kfragOR);
                    CloseSingleLinePile(vwenv, false);
                }
                else if (node is ComplexConcWordBdryNode)
                {
                    OpenSingleLinePile(vwenv, maxNumLines);
                    vwenv.AddProp(ktagInnerNonBoundary, this, kfragHash);
                    CloseSingleLinePile(vwenv);
                }
                else if (node is ComplexConcGroupNode)
                {
                    int  numLines  = GetNumLines(node);
                    bool hasMinMax = node.Maximum != 1 || node.Minimum != 1;
                    if (numLines == 1)
                    {
                        OpenSingleLinePile(vwenv, maxNumLines, false);
                        // use normal parentheses for a single line group
                        vwenv.AddProp(ktagLeftBoundary, this, kfragLeftParen);

                        vwenv.AddObjVecItems(ComplexConcPatternSda.ktagChildren, this, kfragNode);

                        vwenv.AddProp(hasMinMax ? ktagInnerNonBoundary : ktagRightBoundary, this, kfragRightParen);
                        if (hasMinMax)
                        {
                            DisplayMinMax(numLines, vwenv);
                        }
                        CloseSingleLinePile(vwenv, false);
                    }
                    else
                    {
                        vwenv.Props = m_bracketProps;
                        vwenv.set_IntProperty((int)FwTextPropType.ktptMarginLeading, (int)FwTextPropVar.ktpvMilliPoint, PileMargin);
                        vwenv.OpenInnerPile();
                        AddExtraLines(maxNumLines - numLines, ktagLeftNonBoundary, vwenv);
                        vwenv.AddProp(ktagLeftNonBoundary, this, kfragLeftParenUpHook);
                        for (int i = 1; i < numLines - 1; i++)
                        {
                            vwenv.AddProp(ktagLeftNonBoundary, this, kfragLeftParenExt);
                        }
                        vwenv.AddProp(ktagLeftBoundary, this, kfragLeftParenLowHook);
                        vwenv.CloseInnerPile();

                        vwenv.AddObjVecItems(ComplexConcPatternSda.ktagChildren, this, kfragNode);

                        vwenv.Props = m_bracketProps;
                        vwenv.set_IntProperty((int)FwTextPropType.ktptMarginTrailing, (int)FwTextPropVar.ktpvMilliPoint, PileMargin);
                        vwenv.OpenInnerPile();
                        AddExtraLines(maxNumLines - numLines, hasMinMax ? ktagInnerNonBoundary : ktagRightNonBoundary, vwenv);
                        vwenv.AddProp(hasMinMax ? ktagInnerNonBoundary : ktagRightNonBoundary, this, kfragRightParenUpHook);
                        for (int i = 1; i < numLines - 1; i++)
                        {
                            vwenv.AddProp(hasMinMax ? ktagInnerNonBoundary : ktagRightNonBoundary, this, kfragRightParenExt);
                        }
                        vwenv.AddProp(hasMinMax ? ktagInnerNonBoundary : ktagRightBoundary, this, kfragRightParenLowHook);
                        vwenv.CloseInnerPile();
                        if (hasMinMax)
                        {
                            DisplayMinMax(numLines, vwenv);
                        }
                    }
                }
                else
                {
                    bool hasMinMax = node.Maximum != 1 || node.Minimum != 1;
                    int  numLines  = GetNumLines(node);
                    if (numLines == 1)
                    {
                        OpenSingleLinePile(vwenv, maxNumLines, false);
                        // use normal brackets for a single line constraint
                        vwenv.AddProp(ktagLeftBoundary, this, kfragLeftBracket);

                        DisplayFeatures(vwenv, node);

                        vwenv.AddProp(hasMinMax ? ktagInnerNonBoundary : ktagRightBoundary, this, kfragRightBracket);
                        if (hasMinMax)
                        {
                            DisplayMinMax(numLines, vwenv);
                        }
                        CloseSingleLinePile(vwenv, false);
                    }
                    else
                    {
                        // left bracket pile
                        vwenv.Props = m_bracketProps;
                        vwenv.set_IntProperty((int)FwTextPropType.ktptMarginLeading, (int)FwTextPropVar.ktpvMilliPoint, PileMargin);
                        vwenv.OpenInnerPile();
                        AddExtraLines(maxNumLines - numLines, ktagLeftNonBoundary, vwenv);
                        vwenv.AddProp(ktagLeftNonBoundary, this, kfragLeftBracketUpHook);
                        for (int i = 1; i < numLines - 1; i++)
                        {
                            vwenv.AddProp(ktagLeftNonBoundary, this, kfragLeftBracketExt);
                        }
                        vwenv.AddProp(ktagLeftBoundary, this, kfragLeftBracketLowHook);
                        vwenv.CloseInnerPile();

                        // feature pile
                        vwenv.set_IntProperty((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalLeft);
                        vwenv.OpenInnerPile();
                        AddExtraLines(maxNumLines - numLines, ktagInnerNonBoundary, vwenv);
                        DisplayFeatures(vwenv, node);
                        vwenv.CloseInnerPile();

                        // right bracket pile
                        vwenv.Props = m_bracketProps;
                        vwenv.set_IntProperty((int)FwTextPropType.ktptMarginTrailing, (int)FwTextPropVar.ktpvMilliPoint, PileMargin);
                        vwenv.OpenInnerPile();
                        AddExtraLines(maxNumLines - numLines, hasMinMax ? ktagInnerNonBoundary : ktagRightNonBoundary, vwenv);
                        vwenv.AddProp(hasMinMax ? ktagInnerNonBoundary : ktagRightNonBoundary, this, kfragRightBracketUpHook);
                        for (int i = 1; i < numLines - 1; i++)
                        {
                            vwenv.AddProp(hasMinMax ? ktagInnerNonBoundary : ktagRightNonBoundary, this, kfragRightBracketExt);
                        }
                        vwenv.AddProp(hasMinMax ? ktagInnerNonBoundary : ktagRightBoundary, this, kfragRightBracketLowHook);
                        vwenv.CloseInnerPile();
                        if (hasMinMax)
                        {
                            DisplayMinMax(numLines, vwenv);
                        }
                    }
                }
                break;
            }
        }
Пример #33
0
		private void ReconstructView(ComplexConcPatternNode node, bool initial)
		{
			ReconstructView(node.Parent, GetNodeIndex(node), initial);
		}
Пример #34
0
        private int GetNumLines(ComplexConcPatternNode node)
        {
            var morphNode = node as ComplexConcMorphNode;

            if (morphNode != null)
            {
                int numLines = 1;
                if (morphNode.Form != null)
                {
                    numLines++;
                }
                if (morphNode.Entry != null)
                {
                    numLines++;
                }
                if (morphNode.Gloss != null)
                {
                    numLines++;
                }
                if (morphNode.Category != null)
                {
                    numLines++;
                }
                numLines += GetNumLines(morphNode.InflFeatures);
                return(numLines);
            }

            var wordNode = node as ComplexConcWordNode;

            if (wordNode != null)
            {
                int numLines = 1;
                if (wordNode.Form != null)
                {
                    numLines++;
                }
                if (wordNode.Gloss != null)
                {
                    numLines++;
                }
                if (wordNode.Category != null)
                {
                    numLines++;
                }
                numLines += GetNumLines(wordNode.InflFeatures);
                return(numLines);
            }

            var tagNode = node as ComplexConcTagNode;

            if (tagNode != null)
            {
                int numLines = 1;
                if (tagNode.Tag != null)
                {
                    numLines++;
                }
                return(numLines);
            }

            if (!node.IsLeaf)
            {
                return(node.Children.Max(n => GetNumLines(n)));
            }

            return(1);
        }
Пример #35
0
		/// <summary>
		/// Reconstructs the view and moves the cursor the specified position.
		/// </summary>
		/// <param name="parent"></param>
		/// <param name="index">Index of the item in the cell.</param>
		/// <param name="initial">if <c>true</c> move the cursor to the beginning of the specified item, otherwise it is moved to the end</param>
		private void ReconstructView(ComplexConcPatternNode parent, int index, bool initial)
		{
			m_view.RootBox.Reconstruct();
			m_view.SelectAt(parent, index, initial, true, true);
		}
Пример #36
0
		private SelLevInfo[] GetLevelInfo(ComplexConcPatternNode parent, int index)
		{
			var levels = new List<SelLevInfo>();
			if (!m_patternModel.Root.IsLeaf)
			{
				ComplexConcPatternNode node = parent;
				int i = index;
				while (node != null)
				{
					levels.Add(new SelLevInfo {tag = ComplexConcPatternSda.ktagChildren, ihvo = i});
					i = GetNodeIndex(node);
					node = node.Parent;
				}
			}
			return levels.ToArray();
		}
Пример #37
0
		private int GetNumLines(ComplexConcPatternNode node)
		{
			var morphNode = node as ComplexConcMorphNode;
			if (morphNode != null)
			{
				int numLines = 1;
				if (morphNode.Form != null)
					numLines++;
				if (morphNode.Entry != null)
					numLines++;
				if (morphNode.Gloss != null)
					numLines++;
				if (morphNode.Category != null)
					numLines++;
				numLines += GetNumLines(morphNode.InflFeatures);
				return numLines;
			}

			var wordNode = node as ComplexConcWordNode;
			if (wordNode != null)
			{
				int numLines = 1;
				if (wordNode.Form != null)
					numLines++;
				if (wordNode.Gloss != null)
					numLines++;
				if (wordNode.Category != null)
					numLines++;
				numLines += GetNumLines(wordNode.InflFeatures);
				return numLines;
			}

			var tagNode = node as ComplexConcTagNode;
			if (tagNode != null)
			{
				int numLines = 1;
				if (tagNode.Tag != null)
					numLines++;
				return numLines;
			}

			if (!node.IsLeaf)
				return node.Children.Max(n => GetNumLines(n));

			return 1;
		}