Ejemplo n.º 1
0
        public void StringPropWrongLengthFmtTest()
        {
            CheckDisposed();

            // Set class first, or it will throw an exception.
            int  hvo  = 1;
            uint clid = SilDataAccess.MetaDataCache.GetClassId("PhEnvironment");

            SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, (int)clid);
            int tag = (int)SilDataAccess.MetaDataCache.GetFieldId("PhEnvironment", "StringRepresentation", false);

            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse");
            ITsStrBldr strBldr = TsStrBldrClass.Create();

            // Test StringFields (which are basically the same, except that the
            // format of the parameters is different)
            strBldr.Replace(0, 0, "Third", propsBldr.GetTextProps());
            ITsString tsString = strBldr.GetString();
            int       cbFmt;

            byte[] rgbFmt;
            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(1000, typeof(byte)))
            {
                cbFmt  = tsString.SerializeFmtRgb(arrayPtr, 1000);
                rgbFmt = (byte[])MarshalEx.NativeToArray(arrayPtr, cbFmt, typeof(byte));
            }
            VwCacheDa.CacheStringFields(hvo, tag, tsString.Text,
                                        tsString.Length, rgbFmt, cbFmt - 1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Override to filter the specified properties.
        /// </summary>
        public override int get_VecItem(int hvo, int tag, int index)
        {
            ITestItem tester;

            if (!m_filterFlids.TryGetValue(tag, out tester))
            {
                return(base.get_VecItem(hvo, tag, index));
            }
            int chvoReal = BaseSda.get_VecSize(hvo, tag);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoReal, typeof(int)))
            {
                BaseSda.VecProp(hvo, tag, chvoReal, out chvoReal, arrayPtr);
                int[] candidates = (int[])MarshalEx.NativeToArray(arrayPtr, chvoReal, typeof(int));
                int   iresult    = 0;
                for (int icandidate = 0; icandidate < candidates.Length; icandidate++)
                {
                    if (tester.Test(candidates[icandidate], BaseSda, m_validHvos))
                    {
                        if (iresult == index)
                        {
                            return(candidates[icandidate]);
                        }
                        iresult++;
                    }
                }
                throw new IndexOutOfRangeException("filtered vector does not contain that many items (wanted " + index +
                                                   " but have only " + iresult + ")");
            }
        }
Ejemplo n.º 3
0
        public void StringFields_Replace()
        {
            CheckDisposed();
            ITsPropsBldr propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Verse");
            ITsStrBldr strBldr = TsStrBldrClass.Create();

            // Test StringFields (which are basically the same, except that the
            // format of the parameters is different)
            strBldr.Replace(0, 0, "Third", propsBldr.GetTextProps());
            ITsString tsString = strBldr.GetString();

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(1000, typeof(byte)))
            {
                int    cbFmt  = tsString.SerializeFmtRgb(arrayPtr, 1000);
                byte[] rgbFmt = (byte[])MarshalEx.NativeToArray(arrayPtr, cbFmt, typeof(byte));
                m_IVwCacheDa.CacheStringFields(1118, 2228, tsString.Text,
                                               tsString.Length, rgbFmt, cbFmt);
                strBldr.Replace(0, 5, "Fourth", propsBldr.GetTextProps());
                tsString = strBldr.GetString();

                m_IVwCacheDa.CacheStringFields(1118, 2228, tsString.Text,
                                               tsString.Length, rgbFmt, cbFmt);

                ITsString tsStringNew = m_ISilDataAccess.get_StringProp(1118, 2228);

                Assert.AreEqual(tsString.Text, tsStringNew.Text);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets all subclasses of the given class,
        /// including itself (which is always the first result in the list,
        /// so it can easily be skipped if desired).
        /// </summary>
        /// <param name='clid'>Class indentifier to work with.</param>
        /// <param name='countMaximumToReturn'>Count of the maximum number of subclass IDs to return (Size of the array.)
        /// When set to zero, countAllSubclasses will contain the full count, so a second call can use the right sized array.</param>
        /// <param name='countAllSubclasses'>Count of how many subclass IDs are the output array.</param>
        /// <param name='subclasses'>Array of subclass IDs.</param>
        /// <remarks>
        /// The list is therefore a complete list of the classes which are valid to store in a property whose
        /// signature is the class identified by 'clid'.
        /// </remarks>
        public void GetAllSubclasses(System.UInt32 clid,
                                     int countMaximumToReturn, out int countAllSubclasses,
                                     [MarshalAs(UnmanagedType.CustomMarshaler,
                                                MarshalTypeRef = typeof(ArrayPtrMarshaler),
                                                SizeParamIndex = 1)] ArrayPtr /*ULONG[]*/ subclasses)
        {
            countAllSubclasses = 0;             // Start with 0 for output parameter.
            // It's easier to just use the maximum than to fret about the right count.
            int countAllClasses = m_metaClassRecords.Count;

            uint[]      uIds             = new uint[countMaximumToReturn];
            List <uint> allSubclassClids = new List <uint>(countMaximumToReturn);

            allSubclassClids.Add(clid);
            GetAllSubclassesForClid(clid, allSubclassClids);
            int iSubclassClid = 0;

            countAllSubclasses = allSubclassClids.Count;
            while (iSubclassClid < countMaximumToReturn && iSubclassClid < countAllSubclasses)
            {
                uIds[iSubclassClid] = allSubclassClids[iSubclassClid];
                ++iSubclassClid;
            }
            MarshalEx.ArrayToNative(subclasses, countMaximumToReturn, uIds);
        }
Ejemplo n.º 5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Used by constructor.
        /// Sets the text property vars for this proxy, from the name, type, and ws
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void SetTextProps()
        {
            if (m_Context == ContextValues.EndMarker || m_sStyleName == null || m_sStyleName == string.Empty)
            {                   // props are not relevant for end markers or markers with no style name
                m_ttpRunProps  = m_ws == 0 ? null : StyleUtils.CharStyleTextProps(null, m_ws);
                m_rgbParaProps = null;
                return;
            }
            Debug.Assert(m_StyleType == StyleType.kstCharacter || m_StyleType == StyleType.kstParagraph);
            Debug.Assert(m_ws != 0);

            // For char style, the run props contain writing system & char style name; for para
            // style, they contain only the writing system.
            m_ttpRunProps = StyleUtils.CharStyleTextProps(
                (m_StyleType == StyleType.kstCharacter) ? m_sStyleName : null, m_ws);

            // For char style, the paragraph props are empty; for para style, they contain the
            // para style name.
            if (m_StyleType == StyleType.kstParagraph)
            {
                ITsTextProps props = StyleUtils.ParaStyleTextProps(m_sStyleName);
                using (ArrayPtr rgbFmtBufPtr = MarshalEx.ArrayToNative <byte>(kcbFmtBufMax))
                {
                    int nBytes = props.SerializeRgb(rgbFmtBufPtr, kcbFmtBufMax);
                    m_rgbParaProps = MarshalEx.NativeToArray <byte>(rgbFmtBufPtr, nBytes);
                }
            }
            else
            {
                m_rgbParaProps = null;
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get a value determining if the new writing systems should be created as a side-effect
        /// of a paste operation.
        /// </summary>
        /// <param name="wsf">writing system factory containing the new writing systems</param>
        /// <param name="destWs">The destination writing system (writing system used at the
        /// selection).</param>
        /// <returns>
        ///     an indication of how the paste should be handled.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public override PasteStatus DeterminePasteWs(ILgWritingSystemFactory wsf, out int destWs)
        {
            // Determine writing system at selection (destination for paste).
            destWs = 0;
            if (CurrentSelection != null)
            {
                destWs = CurrentSelection.GetWritingSystem(SelectionHelper.SelLimitType.Anchor);
            }
            if (destWs <= 0)
            {
                destWs = Cache.DefaultAnalWs;                 // set to default analysis, if 0.
            }
            int cws = wsf.NumberOfWs;

            using (ArrayPtr ptr = MarshalEx.ArrayToNative <int>(cws))
            {
                wsf.GetWritingSystems(ptr, cws);
                int[] vws = MarshalEx.NativeToArray <int>(ptr, cws);

                for (int iws = 0; iws < cws; iws++)
                {
                    if (vws[iws] != 0 && wsf.get_EngineOrNull(vws[iws]) == null)
                    {
                        // found corrupt writing system--don't want to use any ws in this pasted string
                        return(PasteStatus.UseDestWs);
                    }
                }
            }

            return(PasteStatus.PreserveWs);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Override to filter the specified properties.
        /// </summary>
        public override int get_VecSize(int hvo, int tag)
        {
            ITestItem tester;

            if (!m_filterFlids.TryGetValue(tag, out tester))
            {
                return(base.get_VecSize(hvo, tag));
            }
            int chvoReal = BaseSda.get_VecSize(hvo, tag);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoReal, typeof(int)))
            {
                BaseSda.VecProp(hvo, tag, chvoReal, out chvoReal, arrayPtr);
                int[] candidates = (int[])MarshalEx.NativeToArray(arrayPtr, chvoReal, typeof(int));
                int   iresult    = 0;
                for (int icandidate = 0; icandidate < candidates.Length; icandidate++)
                {
                    if (tester.Test(candidates[icandidate], BaseSda, m_validHvos))
                    {
                        iresult++;
                    }
                }
                return(iresult);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Override to filter the specified properties.
        /// </summary>
        public override void VecProp(int hvo, int tag, int chvoMax, out int chvo, ArrayPtr rghvo)
        {
            ITestItem tester;

            if (!m_filterFlids.TryGetValue(tag, out tester))
            {
                base.VecProp(hvo, tag, chvoMax, out chvo, rghvo);
                return;
            }
            int chvoReal = BaseSda.get_VecSize(hvo, tag);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoReal, typeof(int)))
            {
                BaseSda.VecProp(hvo, tag, chvoReal, out chvoReal, arrayPtr);
                int[] candidates = (int[])MarshalEx.NativeToArray(arrayPtr, chvoReal, typeof(int));
                int[] results    = new int[chvoMax];
                int   iresult    = 0;
                for (int icandidate = 0; icandidate < candidates.Length; icandidate++)
                {
                    if (tester.Test(candidates[icandidate], BaseSda, m_validHvos))
                    {
                        results[iresult++] = candidates[icandidate];
                    }
                }
                chvo = iresult;
                MarshalEx.ArrayToNative(rghvo, chvoMax, results);
            }
        }
Ejemplo n.º 9
0
        /// <summary>Gets the direct subclasses of the given class (not including itself).</summary>
        /// <param name='clid'>Class indentifier to work with.</param>
        /// <param name='countMaximumToReturn'>Count of the maximum number of subclass IDs to return (Size of the array.)
        /// When set to zero, countDirectSubclasses will contain the full count, so a second call can use the right sized array.</param>
        /// <param name='countDirectSubclasses'>Count of how many subclass IDs are the output array.</param>
        /// <param name='subclasses'>Array of subclass IDs.</param>
        public void GetDirectSubclasses(int clid,
                                        int countMaximumToReturn, out int countDirectSubclasses,
                                        [MarshalAs(UnmanagedType.CustomMarshaler,
                                                   MarshalTypeRef = typeof(ArrayPtrMarshaler),
                                                   SizeParamIndex = 1)] ArrayPtr /*ULONG[]*/ subclasses)
        {
            countDirectSubclasses = 0;             // Start with 0 for output parameter.
            var ids = new int[countMaximumToReturn];

            if (!m_metaClassRecords.ContainsKey(clid))
            {
                throw new ArgumentException("Class not found.");
            }
            var mcr = m_metaClassRecords[clid];

            countDirectSubclasses = mcr.m_directSubclasses.Count;
            if (countMaximumToReturn == 0)
            {
                return;                 // Client only wanted the count.
            }
            if (countMaximumToReturn < countDirectSubclasses)
            {
                throw new ArgumentException("Output array is too small.", "countMaximumToReturn");
            }
            var iSubclassClid = 0;

            for (var i = 0; i < mcr.m_directSubclasses.Count; ++i)
            {
                ids[iSubclassClid++] = mcr.m_directSubclasses[i];
            }
            MarshalEx.ArrayToNative(subclasses, countMaximumToReturn, ids);
        }
Ejemplo n.º 10
0
        public void BinaryPropTest()
        {
            CheckDisposed();

            // ScrImportSet::ImportSettings:Binary
            // Set class first, or it will throw an exception.
            int  hvo      = 1;
            uint clidAnal = SilDataAccess.MetaDataCache.GetClassId("ScrImportSet");

            SilDataAccess.SetInt(hvo, (int)CmObjectFields.kflidCmObject_Class, (int)clidAnal);
            int tag = (int)SilDataAccess.MetaDataCache.GetFieldId("ScrImportSet", "ImportSettings", false);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(3, typeof(int)))
            {
                int    chvo;
                byte[] prgb = new byte[] { 3, 4, 5 };
                SilDataAccess.SetBinary(hvo, tag, prgb, prgb.Length);
                SilDataAccess.BinaryPropRgb(hvo, tag, arrayPtr, 3, out chvo);
                byte[] prgbNew = (byte[])MarshalEx.NativeToArray(arrayPtr, chvo, typeof(byte));
                Assert.AreEqual(prgb.Length, prgbNew.Length);
                for (int i = 0; i < prgbNew.Length; i++)
                {
                    Assert.AreEqual(prgb[i], prgbNew[i]);
                }
            }
        }
Ejemplo n.º 11
0
        public void BinaryProp()
        {
            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative <int>(10))
            {
                int chvo = 99;
                m_ISilDataAccess.BinaryPropRgb(1112, 2221, ArrayPtr.Null, 0, out chvo);
                Assert.AreEqual(0, chvo);

                byte[] prgb = new byte[] { 3, 4, 5 };
                m_IVwCacheDa.CacheBinaryProp(1112, 2221, prgb, prgb.Length);
                m_ISilDataAccess.BinaryPropRgb(1112, 2221, arrayPtr, 10, out chvo);
                byte[] prgbNew = MarshalEx.NativeToArray <byte>(arrayPtr, chvo);
                Assert.AreEqual(prgb.Length, prgbNew.Length);
                for (int i = 0; i < prgbNew.Length; i++)
                {
                    Assert.AreEqual(prgb[i], prgbNew[i]);
                }

                byte[] prgb2 = new byte[] { 6, 7, 8, 9 };
                m_IVwCacheDa.CacheBinaryProp(1112, 2221, prgb2, prgb2.Length);
                m_ISilDataAccess.BinaryPropRgb(1112, 2221, arrayPtr, 10, out chvo);
                prgbNew = MarshalEx.NativeToArray <byte>(arrayPtr, chvo);
                Assert.AreEqual(prgb2.Length, prgbNew.Length);
                for (int i = 0; i < prgbNew.Length; i++)
                {
                    Assert.AreEqual(prgb2[i], prgbNew[i]);
                }
            }
        }
Ejemplo n.º 12
0
 public void GetFieldsBadTest()
 {
     using (var flids = MarshalEx.ArrayToNative <int>(500))
     {
         int countAllFlidsOut = 1;
         m_metaDataCache.GetFields(49, true, (int)CellarPropertyTypeFilter.All, countAllFlidsOut, flids);
     }
 }
Ejemplo n.º 13
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Retrieve properties for all data types and verify that we only get the expected
        /// values, i.e. the expected data type that we put in the cache.
        /// </summary>
        /// <param name="hvo">HVO part of the key</param>
        /// <param name="tag">tag part of the key</param>
        /// <param name="expValues">Expected values</param>
        /// ------------------------------------------------------------------------------------
        private void VerifyCache(int hvo, int tag, object[] expValues)
        {
            int hvoVal = m_ISilDataAccess.get_ObjectProp(hvo, tag);

            Assert.AreEqual(expValues[0], hvoVal);

            int chvo = 99;

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative <int>(10))
            {
                m_ISilDataAccess.VecProp(hvo, tag, 10, out chvo, arrayPtr);
                if (expValues[1] is int[])
                {
                    Assert.AreEqual(((int[])expValues[1]).Length, chvo);
                }
                else
                {
                    Assert.AreEqual(expValues[1], chvo);
                }

                m_ISilDataAccess.BinaryPropRgb(hvo, tag, arrayPtr, 10, out chvo);
                if (expValues[2] is byte[])
                {
                    Assert.AreEqual(((byte[])expValues[2]).Length, chvo);
                }
                else
                {
                    Assert.AreEqual(expValues[2], chvo);
                }

                Guid guidNew = m_ISilDataAccess.get_GuidProp(hvo, tag);
                Assert.AreEqual(expValues[3], guidNew);

                long valLong = m_ISilDataAccess.get_Int64Prop(hvo, tag);
                Assert.AreEqual(expValues[4], valLong);

                // Int64 and TimeProp use the same cache
                valLong = m_ISilDataAccess.get_TimeProp(hvo, tag);
                Assert.AreEqual(expValues[4], valLong);

                int valInt = m_ISilDataAccess.get_IntProp(hvo, tag);
                Assert.AreEqual(expValues[5], valInt);

                ITsString tsStringNew = m_ISilDataAccess.get_MultiStringAlt(hvo, tag, 12345);
                Assert.AreEqual(expValues[6], tsStringNew.Text);

                tsStringNew = m_ISilDataAccess.get_StringProp(hvo, tag);
                Assert.AreEqual(expValues[7], tsStringNew.Text);

                string strNew = m_ISilDataAccess.get_UnicodeProp(hvo, tag);
                Assert.AreEqual(expValues[8], strNew);

                object obj = m_ISilDataAccess.get_UnknownProp(hvo, tag);
                Assert.AreEqual(expValues[9], obj);

                CheckIsPropInCache(hvo, tag, expValues);
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets a list of the fields for the specified class.
        /// Fields of superclasses are also returned, if the relevant flag is true.
        /// </summary>
        /// <param name='clid'>Class identification number.</param>
        /// <param name='includeSuperclasses'>'True' to also get superclass fields.</param>
        /// <param name='fieldTypes'>
        /// Gets all fields whose types match the specified argument,
        /// which should be a combination of the fcpt values defined in CmTypes.h, e.g.,
        /// to get all owning properties pass kfcptOwningCollection | kfcptOwningAtom | kfcptOwningSequence.
        /// </param>
        /// <param name='countFlidMax'>
        /// Size of the 'flids' array.
        /// (Use 0 to get the size to use in a second call to actually get them.)</param>
        /// <param name='flids'>Array of flids.</param>
        /// <returns>
        /// Count of flids that are returned,
        /// or that could be returned, if 'countFlidMax' is 0.</returns>
        /// <exception cref="ArgumentException">
        /// Thrown if the output array is too small.
        /// </exception>
        public int GetFields(int clid, bool includeSuperclasses, int fieldTypes, int countFlidMax,
                             [MarshalAs(UnmanagedType.CustomMarshaler,
                                        MarshalTypeRef = typeof(ArrayPtrMarshaler),
                                        SizeParamIndex = 3)] ArrayPtr /*ULONG[]*/ flids)
        {
            var countFlids  = 0;
            var iflid       = 0;
            var currentClid = clid;
            var ids         = new int[countFlidMax];

            // This loop executes once if fIncludeSuperclasses is false, otherwise over clid
            // and all superclasses.
            for (; ;)
            {
                var mcr = m_metaClassRecords[currentClid];
                for (var i = 0; i < mcr.m_fields.Count; ++i)
                {
                    var flid = mcr.m_fields[i];
                    var mfr  = m_metaFieldRecords[flid];
                    if (fieldTypes != (int)CellarPropertyTypeFilter.All)
                    {
                        // Look up field type and see if it matches
                        var fcpt = 1 << (int)mfr.m_fieldType;
                        if ((fieldTypes & fcpt) == 0)
                        {
                            continue;                             // don't return this one
                        }
                    }
                    countFlids++;
                    if (countFlidMax <= 0)
                    {
                        continue;
                    }

                    if (countFlids > countFlidMax)
                    {
                        throw new ArgumentException("Output array is too small.", "countFlidMax");
                    }
                    ids[iflid++] = flid;
                }

                if (!includeSuperclasses)
                {
                    break;
                }
                if (currentClid == 0)                 // just processed the base object
                {
                    break;
                }
                currentClid = mcr.m_baseClsid;
            }
            if (iflid > 0)
            {
                MarshalEx.ArrayToNative(flids, countFlidMax, ids);
            }

            return(countFlids);
        }
Ejemplo n.º 15
0
        public void GetFieldIdsTest()
        {
            var flidSize = m_mdc.FieldCount;

            int[] uIds;
            var   testFlidSize = flidSize - 1;

            using (var flidsPtr = MarshalEx.ArrayToNative <int>(testFlidSize))
            {
                m_mdc.GetFieldIds(testFlidSize, flidsPtr);
                uIds = MarshalEx.NativeToArray <int>(flidsPtr, testFlidSize);
                Assert.AreEqual(testFlidSize, uIds.Length, "Wrong size of fields returned.");
                foreach (var flid in uIds)
                {
                    Assert.IsTrue(flid > 0, "Wrong flid value: " + flid);
                }
            }

            testFlidSize = flidSize;
            using (var flidsPtr = MarshalEx.ArrayToNative <int>(testFlidSize))
            {
                m_mdc.GetFieldIds(testFlidSize, flidsPtr);
                uIds = MarshalEx.NativeToArray <int>(flidsPtr, testFlidSize);
                var uIdsNonCOM = m_mdc.GetFieldIds();
                Assert.AreEqual(uIds.Length, uIdsNonCOM.Length, "COM non-COM GetFieldIds different sizes.");
                for (var i = 0; i < uIdsNonCOM.Length; ++i)
                {
                    Assert.AreEqual(uIdsNonCOM[i], uIds[i], "");
                }
                Assert.AreEqual(testFlidSize, uIds.Length, "Wrong size of fields returned.");
                foreach (var flid in uIds)
                {
                    Assert.IsTrue(flid > 0, "Wrong flid value: " + flid);
                }
            }


            testFlidSize = flidSize + 1;
            using (var flidsPtr = MarshalEx.ArrayToNative <int>(testFlidSize))
            {
                m_mdc.GetFieldIds(testFlidSize, flidsPtr);
                uIds = MarshalEx.NativeToArray <int>(flidsPtr, testFlidSize);
                Assert.AreEqual(testFlidSize, uIds.Length, "Wrong size of fields returned.");
                for (var iflid = 0; iflid < uIds.Length; ++iflid)
                {
                    var flid = uIds[iflid];
                    if (iflid < uIds.Length - 1)
                    {
                        Assert.IsTrue(flid > 0, "Wrong flid value: " + flid);
                    }
                    else
                    {
                        Assert.AreEqual(0, flid, "Wrong value for flid beyond actual length.");
                    }
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Gets a list of the fields for the specified class.
        /// Fields of superclasses are also returned, if the relevant flag is true.
        /// </summary>
        /// <param name='clid'>Class identification number.</param>
        /// <param name='includeSuperclasses'>'True' to also get superclass fields.</param>
        /// <param name='fieldTypes'>
        /// Gets all fields whose types match the specified argument,
        /// which should be a combination of the fcpt values defined in CmTypes.h, e.g.,
        /// to get all owning properties pass kfcptOwningCollection | kfcptOwningAtom | kfcptOwningSequence.
        /// </param>
        /// <param name='countFlidMax'>
        /// Size of the 'flids' array.
        /// (Use 0 to get the size to use in a second call to actually get them.)</param>
        /// <param name='flids'>Array of flids.</param>
        /// <returns>
        /// Count of flids that are returned,
        /// or that could be returned, if 'countFlidMax' is 0.</returns>
        /// <exception cref="ArgumentException">
        /// Thrown if the output array is too small.
        /// </exception>
        public int GetFields(System.UInt32 clid, bool includeSuperclasses, int fieldTypes, int countFlidMax,
                             [MarshalAs(UnmanagedType.CustomMarshaler,
                                        MarshalTypeRef = typeof(ArrayPtrMarshaler),
                                        SizeParamIndex = 3)] ArrayPtr /*ULONG[]*/ flids)
        {
            int  countFlids  = 0;
            int  iflid       = 0;
            uint currentClid = clid;

            uint[] uIds = new uint[countFlidMax];
            // This loop executes once if fIncludeSuperclasses is false, otherwise over clid
            // and all superclasses.
            for (; ;)
            {
                MetaClassRec mcr = m_metaClassRecords[currentClid];
                for (int i = 0; i < mcr.m_fields.Count; ++i)
                {
                    uint         flid = mcr.m_fields[i];
                    MetaFieldRec mfr  = m_metaFieldRecords[flid];
                    if (fieldTypes != (int)CellarModuleDefns.kgrfcptAll)
                    {
                        // Look up field type and see if it matches
                        int flidType = mfr.m_fieldType;
                        int fcpt     = 1 << flidType;
                        if ((fieldTypes & fcpt) == 0)
                        {
                            continue;                             // don't return this one
                        }
                    }
                    countFlids++;
                    if (countFlidMax > 0)
                    {
                        if (countFlids > countFlidMax)
                        {
                            throw new ArgumentException("Output array is too small.", "countFlidMax");
                        }
                        uIds[iflid++] = flid;
                    }
                }

                if (!includeSuperclasses)
                {
                    break;
                }
                if (currentClid == 0)                 // just processed CmObject
                {
                    break;
                }
                currentClid = mcr.m_baseClsid;
            }
            if (iflid > 0)
            {
                MarshalEx.ArrayToNative(flids, countFlidMax, uIds);
            }

            return(countFlids);
        }
Ejemplo n.º 17
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Setups the font features.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void SetupFontFeatures()
        {
            if (m_fontName == null || m_fontName == "")
            {
                Enabled = false;
                return;
            }
            IRenderEngine renderer;

            if (FontHasGraphiteTables(m_fontName, false, false))
            {
                renderer = FwGrEngineClass.Create();
            }
            else
            {
                renderer = UniscribeEngineClass.Create();
            }
            renderer.WritingSystemFactory = m_wsf;
            HoldDummyGraphics hdg = new HoldDummyGraphics(m_fontName, false, false, CreateGraphics());

            renderer.InitRenderer(hdg.m_vwGraphics, m_fontFeatures);
            m_featureEngine = renderer as IRenderingFeatures;
            if (m_featureEngine == null)
            {
                Enabled = false;
                hdg.Close();
                return;
            }
            int cfid;

            m_featureEngine.GetFeatureIDs(0, null, out cfid);
            if (cfid == 0)
            {
                Enabled = false;
                hdg.Close();
                return;
            }
            if (cfid == 1)
            {
                // What if it's the dummy built-in graphite feature that we ignore?
                // Get the list of features (only 1).
                using (ArrayPtr idsM = MarshalEx.ArrayToNative(cfid, typeof(int)))
                {
                    m_featureEngine.GetFeatureIDs(cfid, idsM, out cfid);
                    int [] ids = (int[])MarshalEx.NativeToArray(idsM, cfid, typeof(int));
                    if (ids[0] == kGrLangFeature)
                    {
                        Enabled = false;
                        hdg.Close();
                        return;
                    }
                }
            }
            Enabled = true;
            hdg.Close();
        }
Ejemplo n.º 18
0
 public void GetAllSubclasses_ClassL_Limited()
 {
     using (var clids = MarshalEx.ArrayToNative <int>(2))
     {
         // Check ClassL (but get it and only 1 of its subclasses).
         int countAllSubclasses;
         m_metaDataCache.GetAllSubclasses(35, 2, out countAllSubclasses, clids);
         Assert.AreEqual(2, countAllSubclasses, "Wrong number of subclasses returned.");
     }
 }
Ejemplo n.º 19
0
 public void GetAllSubclasses_ClassL()
 {
     using (var clids = MarshalEx.ArrayToNative <int>(10))
     {
         // Check ClassL (all of its direct subclasses).
         int countAllSubclasses;
         m_metaDataCache.GetAllSubclasses(35, 10, out countAllSubclasses, clids);
         Assert.AreEqual(3, countAllSubclasses, "Wrong number of subclasses returned.");
     }
 }
Ejemplo n.º 20
0
 public void GetAllSubclasses_None()
 {
     using (var clids = MarshalEx.ArrayToNative <int>(10))
     {
         // Check ClassC.
         int countAllSubclasses;
         m_metaDataCache.GetAllSubclasses(26, 10, out countAllSubclasses, clids);
         Assert.AreEqual(1, countAllSubclasses, "Wrong number of subclasses returned.");
     }
 }
Ejemplo n.º 21
0
        internal static int ComVecPropFromManagedVecProp(int[] hvos, int hvo, int tag, ArrayPtr rghvo, int chvoMax)
        {
            if (hvos.Length > chvoMax)
            {
                throw new ArgumentException("The count is greater than the parameter 'chvo'.");
            }

            MarshalEx.ArrayToNative(rghvo, chvoMax, hvos);
            return(hvos.Length);
        }
Ejemplo n.º 22
0
 public void BinaryProp_BufferToSmall()
 {
     byte[] prgb2 = new byte[] { 6, 7, 8, 9 };
     m_IVwCacheDa.CacheBinaryProp(1112, 2221, prgb2, prgb2.Length);
     using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative <int>(10))
     {
         int chvo;
         m_ISilDataAccess.BinaryPropRgb(1112, 2221, arrayPtr, 2, out chvo);
     }
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Get the items from a vector property.
        /// </summary>
        private static int[] GetVector(ISilDataAccess sda, int hvo, int tag)
        {
            var chvo = sda.get_VecSize(hvo, tag);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative <int>(chvo))
            {
                sda.VecProp(hvo, tag, chvo, out chvo, arrayPtr);
                return(MarshalEx.NativeToArray <int>(arrayPtr, chvo));
            }
        }
Ejemplo n.º 24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Setups the font features.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void SetupFontFeatures()
        {
            CheckDisposed();

            if (string.IsNullOrEmpty(m_fontName))
            {
                Enabled          = false;
                m_isGraphiteFont = false;
                return;
            }

            using (var hdg = new HoldDummyGraphics(m_fontName, false, false, this))
            {
                IRenderEngine renderer = GraphiteEngineClass.Create();
                renderer.InitRenderer(hdg.m_vwGraphics, m_fontFeatures);
                // check if the font is a valid Graphite font
                if (!renderer.FontIsValid)
                {
                    m_isGraphiteFont = false;
                    Enabled          = false;
                    return;
                }
                renderer.WritingSystemFactory = m_wsf;
                m_isGraphiteFont = true;
                m_featureEngine  = renderer as IRenderingFeatures;
                if (m_featureEngine == null)
                {
                    Enabled = false;
                    return;
                }
                int cfid;
                m_featureEngine.GetFeatureIDs(0, null, out cfid);
                if (cfid == 0)
                {
                    Enabled = false;
                    return;
                }
                if (cfid == 1)
                {
                    // What if it's the dummy built-in graphite feature that we ignore?
                    // Get the list of features (only 1).
                    using (ArrayPtr idsM = MarshalEx.ArrayToNative <int>(cfid))
                    {
                        m_featureEngine.GetFeatureIDs(cfid, idsM, out cfid);
                        int [] ids = MarshalEx.NativeToArray <int>(idsM, cfid);
                        if (ids[0] == kGrLangFeature)
                        {
                            Enabled = false;
                            return;
                        }
                    }
                }
                Enabled = true;
            }
        }
Ejemplo n.º 25
0
        public void GetFieldsTest()
        {
            using (var flids = MarshalEx.ArrayToNative <int>(500))
            {
                var countAllFlidsOut = m_mdc.GetFields(0, true, (int)CellarPropertyTypeFilter.All, 0, flids);
                countAllFlidsOut = m_mdc.GetFields(0, true, (int)CellarPropertyTypeFilter.All, countAllFlidsOut, flids);

                MarshalEx.NativeToArray <int>(flids, countAllFlidsOut);
                Assert.AreEqual(7, countAllFlidsOut, "Wrong number of fields returned for CmObject.");
            }
        }
Ejemplo n.º 26
0
        public void GetDirectSubclasses_None()
        {
            int countDirectSubclasses;

            using (var clids = MarshalEx.ArrayToNative <int>(10))
            {
                // Check ClassB.
                m_metaDataCache.GetDirectSubclasses(45, 10, out countDirectSubclasses, clids);
                Assert.AreEqual(0, countDirectSubclasses, "Wrong number of subclasses returned.");
            }
        }
Ejemplo n.º 27
0
        public void GetFieldsDoesNotIncludeBaseFields()
        {
            using (var flids = MarshalEx.ArrayToNative <int>(500))
            {
                var countAllFlidsOut = m_mdc.GetFields(MoStemAllomorphTags.kClassId, false, (int)CellarPropertyTypeFilter.All, 0, flids);
                countAllFlidsOut = m_mdc.GetFields(MoStemAllomorphTags.kClassId, false, (int)CellarPropertyTypeFilter.All, countAllFlidsOut, flids);

                var fields = new List <int>(MarshalEx.NativeToArray <int>(flids, countAllFlidsOut));
                Assert.That(fields, Has.Member(MoStemAllomorphTags.kflidPhoneEnv));       // not inherited
                Assert.That(fields, Has.No.Member(MoFormTags.kflidForm));                 // inherited
            }
        }
Ejemplo n.º 28
0
        public void GetAllSubclasses_BaseClass()
        {
            var countAllClasses = m_metaDataCache.ClassCount;

            using (var clids = MarshalEx.ArrayToNative <int>(countAllClasses))
            {
                // Check BaseClass.
                int countAllSubclasses;
                m_metaDataCache.GetAllSubclasses(0, countAllClasses, out countAllSubclasses, clids);
                Assert.AreEqual(countAllClasses, countAllSubclasses, "Wrong number of subclasses returned.");
            }
        }
Ejemplo n.º 29
0
        public override void Load(int hvo, int tag, int ws, IVwCacheDa cda)
        {
            ISilDataAccess sda  = cda as ISilDataAccess;
            int            cobj = sda.get_VecSize(hvo, m_tagReal);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(cobj + 1, typeof(int)))             // one longer to leave room for dummy
            {
                sda.VecProp(hvo, m_tagReal, cobj, out cobj, arrayPtr);
                int [] rgHvo = (int[])MarshalEx.NativeToArray(arrayPtr, cobj, typeof(int));
                rgHvo[cobj] = TypeAheadSupportVc.kBaseFakeObj;
                cda.CacheVecProp(hvo, tag, rgHvo, cobj + 1);
            }
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Make one that wraps the specified cache and passes items in the specified property of the specified root object.
        /// </summary>
        public FilterSdaDecorator(ISilDataAccess domainDataByFlid, int mainFlid, int hvoRoot)
            : base(domainDataByFlid)
        {
            m_mainFlid = mainFlid;
            m_hvoRoot  = hvoRoot;
            int chvoReal = BaseSda.get_VecSize(m_hvoRoot, m_mainFlid);

            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoReal, typeof(int)))
            {
                BaseSda.VecProp(m_hvoRoot, m_mainFlid, chvoReal, out chvoReal, arrayPtr);
                m_validHvos = new Set <int>((int[])MarshalEx.NativeToArray(arrayPtr, chvoReal, typeof(int)));
            }
        }