示例#1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Updates the text displayed in the spin box
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void UpdateEditText()
        {
            switch (m_mode)
            {
            case DataUpDownMode.Normal:
                Text = m_currentValue.ToString();
                break;

            case DataUpDownMode.Letters:
                Text = AlphaOutline.NumToAlphaOutline(m_currentValue);
                break;

            case DataUpDownMode.LettersLowerCase:
                Text = AlphaOutline.NumToAlphaOutline(m_currentValue).ToLower();
                break;

            case DataUpDownMode.Roman:
                Text = RomanNumerals.IntToRoman(m_currentValue);
                break;

            case DataUpDownMode.RomanLowerCase:
                Text = RomanNumerals.IntToRoman(m_currentValue).ToLower();
                break;
            }
        }
示例#2
0
        private string GetOutlineStyle2biv(int[] rghvo, int ihvo)
        {
            // Top-level: Arabic numeral.
            // Second-level: lowercase letter.
            // Third-level (and lower): lowercase Roman numeral.
            string sNum;             // return result string
            var    sOutline   = m_cache.GetOutlineNumber(m_objRepo.GetObject(rghvo[ihvo]), false, true);
            var    cchPeriods = 0;
            var    ichPeriod  = sOutline.IndexOf('.');

            while (ichPeriod >= 0)
            {
                ++cchPeriods;
                ichPeriod = sOutline.IndexOf('.', ichPeriod + 1);
            }
            switch (cchPeriods)
            {
            case 0:
                sNum = string.Format("{0}", ihvo + 1);
                break;

            case 1:
                sNum = AlphaOutline.NumToAlphaOutline(ihvo + 1).ToLower();
                break;

            default:
                sNum = RomanNumerals.IntToRoman(ihvo + 1).ToLower();
                break;
            }
            return(sNum);
        }
示例#3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Builds a number string for the preview window based on the given values
        /// </summary>
        /// <param name="line">The line.</param>
        /// <param name="nStartAt">The number to start at.</param>
        /// <param name="iScheme">The i scheme.</param>
        /// <param name="textBefore">The text before.</param>
        /// <param name="textAfter">The text after.</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        private string GetNumberString(int line, int nStartAt, int iScheme, string textBefore,
                                       string textAfter)
        {
            int    number       = nStartAt + line;
            string numberString = string.Empty;

            switch (iScheme)
            {
            case 0:                             // 1, 2, 3'
                numberString = number.ToString();
                break;

            case 1:                             // I, II, III (Roman numerals)
                numberString = RomanNumerals.IntToRoman(number);
                break;

            case 2:                             // i, ii, iii (lower case Roman numerals)
                numberString = RomanNumerals.IntToRoman(number).ToLowerInvariant();
                break;

            case 3:                             // A, B, C
                numberString = AlphaOutline.NumToAlphaOutline(number);
                break;

            case 4:                             // a, b, c
                numberString = AlphaOutline.NumToAlphaOutline(number).ToLowerInvariant();
                break;

            case 5:                             // 01, 02, 03
                numberString = number.ToString("d2");
                break;
            }

            return(textBefore + numberString + textAfter);
        }
示例#4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Validates the text displayed in the spin box
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void ValidateEditText()
        {
            int    newValue = 0;
            string text     = Text;

            if (text == string.Empty)
            {
                return;
            }

            // don't allow validation to recurse
            if (m_validating)
            {
                return;
            }
            m_validating = true;

            switch (m_mode)
            {
            case DataUpDownMode.Normal:
                foreach (char ch in text)
                {
                    if (!Char.IsDigit(ch))
                    {
                        newValue = -1;
                        break;
                    }
                }
                if (newValue != -1)
                {
                    newValue = Int32.Parse(text);
                }
                break;

            case DataUpDownMode.Letters:
            case DataUpDownMode.LettersLowerCase:
                newValue = AlphaOutline.AlphaOutlineToNum(text);
                // If the text does not validate and the old text does not validate then
                // switch to a value of 1.
                if (newValue == -1 && AlphaOutline.AlphaOutlineToNum(m_previousText) == -1)
                {
                    newValue = 1;
                    text     = AlphaOutline.NumToAlphaOutline(newValue);
                }

                if (m_mode == DataUpDownMode.Letters)
                {
                    text = text.ToUpper();
                }
                else
                {
                    text = text.ToLower();
                }
                break;

            case DataUpDownMode.Roman:
            case DataUpDownMode.RomanLowerCase:
                newValue = RomanNumerals.RomanToInt(text);
                // If the text does not validate and the old text does not validate then
                // switch to a value of 1.
                if (newValue == -1 && RomanNumerals.RomanToInt(m_previousText) == -1)
                {
                    newValue = 1;
                    text     = RomanNumerals.IntToRoman(newValue);
                }

                if (m_mode == DataUpDownMode.Roman)
                {
                    text = text.ToUpper();
                }
                else
                {
                    text = text.ToLower();
                }
                break;
            }

            if (newValue >= 0 && newValue <= MaxValue)
            {
                m_previousText = text;
                Value          = newValue;
            }
            else
            {
                Text = m_previousText;
                Select(m_previousText.Length, 0);
            }

            m_validating = false;
        }
示例#5
0
        /// <summary>
        /// Takes a coded number string and interprets it.
        /// Only the first code in the string is interpreted.
        /// The emedded codes are:
        /// %d for an integer
        /// %A, %a for upper and lower alpha,
        /// %I, %i for upper and lower roman numerals,
        /// %O for outline number (a real number)
        /// %z is short for %d.%a.%i; the lowest level is incremented or set.
        /// </summary>
        /// <param name="rghvo">hvo array of senses</param>
        /// <param name="ihvo">A sequence number or index (into rghvo).</param>
        /// <param name="xaNum">The sequence number format to apply</param>
        /// <returns>The format filled in with the sequence number</returns>
        private string CalculateAndFormatSenseLabel(int[] rghvo, int ihvo, XmlAttribute xaNum)
        {
            var sNum = "";
            var sTag = xaNum.Value;
            int ich;

            for (ich = 0; ich < sTag.Length; ++ich)
            {
                if (sTag[ich] != '%' || sTag.Length <= ich + 1)
                {
                    continue;
                }
                ++ich;
                switch (sTag[ich])
                {
                case 'd':
                    sNum = string.Format("{0}", ihvo + 1);
                    break;

                case 'A':
                    sNum = AlphaOutline.NumToAlphaOutline(ihvo + 1);
                    break;

                case 'a':
                    sNum = AlphaOutline.NumToAlphaOutline(ihvo + 1).ToLower();
                    break;

                case 'I':
                    sNum = RomanNumerals.IntToRoman(ihvo + 1);
                    break;

                case 'i':
                    sNum = RomanNumerals.IntToRoman(ihvo + 1).ToLower();
                    break;

                case 'O':
                    if (m_cache.MetaDataCacheAccessor.get_IsVirtual(m_flid))
                    {
                        sNum = String.Format("{0}", ihvo + 1);
                    }
                    else
                    {
                        sNum = m_cache.GetOutlineNumber(m_objRepo.GetObject(rghvo[ihvo]), false, true);
                    }
                    break;

                case 'z':
                    sNum = GetOutlineStyle2biv(rghvo, ihvo);
                    break;

                // MDL: can only get to this case for "%%" - does it mean anything?
                case '%':
                    sTag.Remove(ich, 1);                             // removes the 2nd %
                    --ich;
                    break;
                }
                break;                 // ich is the position of the code character after the last %
            }
            // sNum is the ordinate that will replace the 2-letter code.
            if (sNum.Length != 0)
            {
                sTag = (sTag.Remove(ich - 1, 2)).Insert(ich - 1, sNum);
            }
            return(sTag);
        }
示例#6
0
        /// <summary>
        /// Takes a coded number string and interprets it.
        /// Only the first code in the string is interpreted.
        /// The emedded codes are:
        /// %d for an integer
        /// %A, %a for upper and lower alpha
        /// %I, %i for upper and lower roman numerals
        /// %O for outline number (a real number)
        /// %z for %d at the top level, %a at the next level, and %i at all subsequent levels
        /// </summary>
        /// <param name="hvo">the sense itself</param>
        /// <param name="ihvo">A sequence number or index (of hvo in its containing sequence).</param>
        /// <param name="sTag">The sequence number format to apply</param>
        /// <returns>The format filled in with the sequence number</returns>
        internal string CalculateAndFormatSenseLabel(int hvo, int ihvo, string sTag)
        {
            var sNum = "";
            int ich;

            for (ich = 0; ich < sTag.Length; ++ich)
            {
                if (sTag[ich] != '%' || sTag.Length <= ich + 1)
                {
                    continue;
                }
                ++ich;
                switch (sTag[ich])
                {
                case 'd':
                    sNum = string.Format("{0}", ihvo + 1);
                    break;

                case 'A':
                    sNum = AlphaOutline.NumToAlphaOutline(ihvo + 1);
                    break;

                case 'a':
                    sNum = AlphaOutline.NumToAlphaOutline(ihvo + 1).ToLower();
                    break;

                case 'I':
                    sNum = RomanNumerals.IntToRoman(ihvo + 1);
                    break;

                case 'i':
                    sNum = RomanNumerals.IntToRoman(ihvo + 1).ToLower();
                    break;

                case 'O':
                    if (m_cache.MetaDataCacheAccessor.get_IsVirtual(m_flid))
                    {
                        sNum = String.Format("{0}", ihvo + 1);
                    }
                    else
                    {
                        var item = m_objRepo.GetObject(hvo);
                        if (item is ILexSense)
                        {
                            // Need to use a virtual property which can be overridden by DictionaryPublicationDecorator
                            // So the numbering excludes any hidden senses.
                            var senseOutlineFlid = item.Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "LexSenseOutline", false);
                            sNum = m_sda.get_StringProp(item.Hvo, senseOutlineFlid).Text;
                        }
                        else
                        {
                            // Not sure this can ever happen (since the method name indicates is it supposed to make
                            // labels for senses), but it seemed safest to keep the old generic behavior for any other cases.
                            sNum = m_cache.GetOutlineNumber(item, false, true);
                        }
                    }
                    break;

                case 'z':
                    sNum = GetOutlineStyle2biv(hvo, ihvo);
                    break;

                // MDL: can only get to this case for "%%" - does it mean anything?
                case '%':
                    sTag.Remove(ich, 1);                             // removes the 2nd %
                    --ich;
                    break;
                }
                break;                 // ich is the position of the code character after the last %
            }
            // sNum is the ordinate that will replace the 2-letter code.
            if (sNum.Length != 0)
            {
                sTag = (sTag.Remove(ich - 1, 2)).Insert(ich - 1, sNum);
            }
            return(sTag);
        }