Example #1
0
        public override void DisplayEmbeddedObject(IVwEnv vwenv, int hvo)
        {
            // See if it is a CmPicture.
            ISilDataAccess sda   = vwenv.DataAccess;
            int            clsid = sda.get_IntProp(hvo, (int)CmObjectFields.kflidCmObject_Class);

            if (clsid != CmPictureTags.kClassId)
            {
                // don't know how to deal with it. Maybe the base implementation does.
                base.DisplayEmbeddedObject(vwenv, hvo);
                return;
            }
            int hvoFile = sda.get_ObjectProp(hvo, CmPictureTags.kflidPictureFile);

            if (hvoFile == 0)
            {
                return;
            }
            string path;
            string fileName = sda.get_UnicodeProp(hvoFile, CmFileTags.kflidInternalPath);

            if (Path.IsPathRooted(fileName))
            {
                path = fileName;
            }
            else
            {
                if (m_hvoLangProject == 0)
                {
                    // REVIEW (TimS/TomB): Hvo is for a CmPicture which means it might not be owned.
                    // If it's not owned, there will be no way to walk up the owner tree to find the
                    // Language Project. Review all clients to see if they have embedded objects.
                    // If so, they need to set the cache.
                    TryToSetLangProjectHvo(sda, hvo);
                }
                string linkedFilesRoot = sda.get_UnicodeProp(m_hvoLangProject, LangProjectTags.kflidLinkedFilesRootDir);
                if (String.IsNullOrEmpty(linkedFilesRoot))
                {
                    path = Path.Combine(DirectoryFinder.FWDataDirectory, fileName);
                }
                else
                {
                    path = Path.Combine(linkedFilesRoot, fileName);
                }
            }
            vwenv.set_IntProperty((int)FwTextPropType.ktptAlign,
                                  (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);

            IPicture picture = new PictureWrapper(path);

            // -1 is ktagNotAnAttr. 0 width & height mean use natural width/height.
            vwenv.AddPictureWithCaption(picture, -1, CaptionProps, hvoFile, m_wsDefault, 0, 0, this);
        }
Example #2
0
        /// <summary>
        /// Get the Linked Files Root Directory value from the language project represented by the
        /// ISilDataAccess argument.
        /// </summary>
        protected string GetLinkedFilesRootDir(ISilDataAccess sda)
        {
            var linkedFilesRootDirID = sda.MetaDataCache.GetFieldId("LangProject", "LinkedFilesRootDir", false);
            int hvo = GetHvoOfProject(sda);

            return(sda.get_UnicodeProp(hvo, linkedFilesRootDirID));
        }
Example #3
0
        public void UnicodeProp()
        {
            string strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);

            Assert.IsNull(strNew);

            string str = "UnicodeTest";

            m_IVwCacheDa.CacheUnicodeProp(1119, 2229, str, str.Length);
            strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);
            Assert.AreEqual(str, strNew);

            str = "SecondUnicodeTest";
            m_IVwCacheDa.CacheUnicodeProp(1119, 2229, str, str.Length);
            strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);
            Assert.AreEqual(str, strNew);
        }
Example #4
0
        public void UnicodeProp()
        {
            CheckDisposed();
            string strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);

            Assert.IsNull(strNew);
            Assert.IsFalse(m_ISilDataAccess.IsDirty());

            string str = "UnicodeTest";

            m_ISilDataAccess.SetUnicode(1119, 2229, str, str.Length);
            strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);
            Assert.AreEqual(str, strNew);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            str = "SecondUnicodeTest";
            m_ISilDataAccess.SetUnicode(1119, 2229, str, str.Length);
            strNew = m_ISilDataAccess.get_UnicodeProp(1119, 2229);
            Assert.AreEqual(str, strNew);
            Assert.IsTrue(m_ISilDataAccess.IsDirty());

            str = "ThirdUnicodeTest";
            m_ISilDataAccess.set_UnicodeProp(1119, 2229, str);
            int cch;

            using (ArrayPtr arrayPtr = MarshalEx.StringToNative(100, true))
            {
                m_ISilDataAccess.UnicodePropRgch(1119, 2229, arrayPtr, 100, out cch);
                strNew = MarshalEx.NativeToString(arrayPtr, cch, true);
                Assert.AreEqual(str, strNew);
                Assert.AreEqual(str.Length, cch);
                Assert.IsTrue(m_ISilDataAccess.IsDirty());

                m_ISilDataAccess.UnicodePropRgch(1119, 2229, ArrayPtr.Null, 0, out cch);
                Assert.AreEqual(str.Length, cch);

                CheckProp(1119, 2229, str, CellarModuleDefns.kcptUnicode);
            }
        }
Example #5
0
        public void AutoLoad()
        {
            // Get the language project as an FDO object
            ILangProject lp = m_fdoCache.LangProject;

            // Use it to get the HVO of the data notebook, but without making an FDO object
            // and thus loading data.
            Assert.IsTrue(m_sda.get_IsPropInCache(lp.Hvo,
                                                  (int)LangProject.LangProjectTags.kflidResearchNotebook,
                                                  (int)CellarModuleDefns.kcptOwningAtom, 0),
                          "LP notebook loaded by FDO");
            int hvoNotebook = m_fdoCache.GetObjProperty(lp.Hvo,
                                                        (int)LangProject.LangProjectTags.kflidResearchNotebook);

            // Owning atomic
            Assert.IsFalse(m_sda.get_IsPropInCache(hvoNotebook,
                                                   (int)RnResearchNbk.RnResearchNbkTags.kflidEventTypes,
                                                   (int)CellarModuleDefns.kcptOwningAtom, 0),
                           "Notebook event types not preloaded");
            int hvoEventTypes = m_sda.get_ObjectProp(hvoNotebook,
                                                     (int)RnResearchNbk.RnResearchNbkTags.kflidEventTypes);

            Assert.IsTrue(m_sda.get_IsPropInCache(hvoNotebook,
                                                  (int)RnResearchNbk.RnResearchNbkTags.kflidEventTypes,
                                                  (int)CellarModuleDefns.kcptOwningAtom, 0),
                          "Notebook event types autoloaded");
            Assert.IsTrue(hvoEventTypes != 0, "got real event types");
            int flidET = m_sda.get_IntProp(hvoEventTypes, (int)CmObjectFields.kflidCmObject_OwnFlid);

            Assert.AreEqual((int)RnResearchNbk.RnResearchNbkTags.kflidEventTypes, flidET,
                            "owning flid loaded correctly");
            int clsidET = m_sda.get_IntProp(hvoEventTypes, (int)CmObjectFields.kflidCmObject_Class);

            Assert.AreEqual((int)CmPossibilityList.kClassId, clsidET,
                            "class autoloaded");
            int ownerET = m_sda.get_ObjectProp(hvoEventTypes, (int)CmObjectFields.kflidCmObject_Owner);

            Assert.AreEqual(hvoNotebook, ownerET,
                            "owner auto-loaded");
            // Todo: test ref atomic.

            // Owning collection.
            Assert.IsFalse(m_sda.get_IsPropInCache(hvoNotebook,
                                                   (int)RnResearchNbk.RnResearchNbkTags.kflidRecords,
                                                   (int)CellarModuleDefns.kcptOwningCollection, 0),
                           "Nb records not preloaded");
            // Forces a load
            int chvoRecs = m_sda.get_VecSize(hvoNotebook,
                                             (int)RnResearchNbk.RnResearchNbkTags.kflidRecords);

            Assert.IsTrue(m_sda.get_IsPropInCache(hvoNotebook,
                                                  (int)RnResearchNbk.RnResearchNbkTags.kflidRecords,
                                                  (int)CellarModuleDefns.kcptOwningCollection, 0),
                          "Nb records autoloaded");
            // Be careful what we assert...don't want it too dependent on the exact data.
            // Should be OK to assume at least a few records.
            Assert.IsTrue(chvoRecs > 4, "at least 4 recs");

            int hvoRec3 = m_sda.get_VecItem(hvoNotebook,
                                            (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, 3);
            int clsIDR3 = m_sda.get_IntProp(hvoRec3, (int)CmObjectFields.kflidCmObject_Class);

            Assert.IsTrue((int)RnEvent.kClassId == clsIDR3 || (int)RnAnalysis.kClassId == clsIDR3,
                          "class of rec 3 valid");
            Assert.IsFalse(m_sda.get_IsPropInCache(hvoRec3,
                                                   (int)RnGenericRec.RnGenericRecTags.kflidResearchers,
                                                   (int)CellarModuleDefns.kcptReferenceCollection, 0),
                           "R3 researchers not preloaded");
            int chvoR3Researchers = m_sda.get_VecSize(hvoRec3,
                                                      (int)RnGenericRec.RnGenericRecTags.kflidResearchers);

            Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec3,
                                                  (int)RnGenericRec.RnGenericRecTags.kflidResearchers,
                                                  (int)CellarModuleDefns.kcptReferenceCollection, 0),
                          "R3 researchers autoloaded");
            // We can't assume anything about any one record, but we should be able to find
            // at least one where researchers is non-empty. Along the way we do at least
            // some testing of VecProp and also make sure we can load a string that is a
            // BigString
            bool fGotEmpty    = false;
            bool fGotNonEmpty = false;
            bool fGotEvent    = false;
            int  hvoEvent     = 0;       // some record will be an event...
            int  hvoText      = 0;       // that has a non-empty structured text...
            int  hvoPara      = 0;       // that has a non-empty paragraph with a label.

            for (int ihvo = 0; ihvo < chvoRecs &&
                 ((!fGotEmpty) || (!fGotNonEmpty) || (!fGotEvent) || hvoText == 0); ihvo++)
            {
                int hvoRec = m_sda.get_VecItem(hvoNotebook,
                                               (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, ihvo);
                int chvoResearchers = m_sda.get_VecSize(hvoRec,
                                                        (int)RnGenericRec.RnGenericRecTags.kflidResearchers);
                if (chvoResearchers > 0)
                {
                    if (!fGotNonEmpty)
                    {
                        fGotNonEmpty = true;
                        // Try this on the first non-empty list.
                        int hvoResearcher = m_sda.get_VecItem(hvoRec,
                                                              (int)RnGenericRec.RnGenericRecTags.kflidResearchers, 0);
                        int clsidResearcher = m_sda.get_IntProp(hvoResearcher,
                                                                (int)CmObjectFields.kflidCmObject_Class);
                        Assert.AreEqual(CmPerson.kClassId, clsidResearcher, "class of researcher");
                    }
                }
                else
                {
                    fGotEmpty = true;
                    // should now be considered cached anyway.
                    Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec,
                                                          (int)RnGenericRec.RnGenericRecTags.kflidResearchers,
                                                          (int)CellarModuleDefns.kcptReferenceCollection, 0),
                                  "empty researchers autoloaded");
                }
                int clsIDRec = m_sda.get_IntProp(hvoRec, (int)CmObjectFields.kflidCmObject_Class);
                if (clsIDRec == (int)RnEvent.kClassId && !fGotEvent)
                {
                    hvoEvent = hvoRec;
                    hvoText  = m_sda.get_ObjectProp(hvoEvent, (int)RnEvent.RnEventTags.kflidDescription);
                    if (hvoText != 0)
                    {
                        int chvo;
                        using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(1000, typeof(int)))
                        {
                            // if there's a description with more than 1000 paragraphs this will break and
                            // we'll fix it then.
                            m_sda.VecProp(hvoText, (int)StText.StTextTags.kflidParagraphs,
                                          1000, out chvo, arrayPtr);
                            int[] rgHvo = (int[])MarshalEx.NativeToArray(arrayPtr, chvo, typeof(int));
                            // search for the paragraph that has non-empty label (there are a couple).
                            for (int ihvoPara = 0; ihvoPara < chvo; ++ihvoPara)
                            {
                                hvoPara = rgHvo[ihvoPara];
                                // BigString
                                ITsString tssPara = m_sda.get_StringProp(hvoPara,
                                                                         (int)StTxtPara.StTxtParaTags.kflidContents);
                                if (tssPara.Length > 0)
                                {
                                    string sname = m_sda.get_UnicodeProp(hvoPara,
                                                                         (int)StPara.StParaTags.kflidStyleName);
                                    if (sname != null && sname.Length > 0)
                                    {
                                        fGotEvent = true;
                                    }
                                    // Todo: it would be nice to test UnicodePropRgch, but we can't test
                                    // on the same prop because it's already loaded. Also, the modification
                                    // for data loading is shared code. We could make another cache instance
                                    // to test from, maybe? Or keep searching till we find another instance?
                                    // Could also look for a kcptBigUnicode, but implementation is identical.
                                }
                            }
                        }
                    }
                }
            }
            Assert.IsTrue(fGotEmpty && fGotNonEmpty, "found both empty and non-empty researcher lists");
            Assert.IsTrue(hvoEvent != 0, "got at least one event");
            // todo: test sequence (somehow verify order).
            // todo: test ref seq/collection (verify it does NOT set the owner to the referring obj).

            // Ref atomic
            Assert.IsFalse(m_sda.get_IsPropInCache(hvoRec3,
                                                   (int)RnGenericRec.RnGenericRecTags.kflidConfidence,
                                                   (int)CellarModuleDefns.kcptReferenceAtom, 0),
                           "R3 confidence not preloaded");
            int hvoConfidence = m_sda.get_ObjectProp(hvoRec3,
                                                     (int)RnGenericRec.RnGenericRecTags.kflidConfidence);

            Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec3,
                                                  (int)RnGenericRec.RnGenericRecTags.kflidConfidence,
                                                  (int)CellarModuleDefns.kcptReferenceAtom, 0),
                          "R3 confidence autoloaded");
            if (hvoConfidence != 0)
            {
                int clsidConfidence = m_sda.get_IntProp(hvoConfidence,
                                                        (int)CmObjectFields.kflidCmObject_Class);
                Assert.AreEqual(CmPossibility.kClassId, clsidConfidence, "class of confidence");
            }


            // TsString.
            Assert.IsFalse(m_sda.get_IsPropInCache(hvoRec3,
                                                   (int)RnGenericRec.RnGenericRecTags.kflidTitle,
                                                   (int)CellarModuleDefns.kcptString, 0),
                           "title of rec 3 not preloaded");
            ITsString qtssRec3Title = m_sda.get_StringProp(hvoRec3,
                                                           (int)RnGenericRec.RnGenericRecTags.kflidTitle);

            Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec3,
                                                  (int)RnGenericRec.RnGenericRecTags.kflidTitle,
                                                  (int)CellarModuleDefns.kcptString, 0),
                          "autoloaded title of rec 3");

            // Int (e.g., gendate)
            Assert.IsFalse(m_sda.get_IsPropInCache(hvoEvent,
                                                   (int)RnEvent.RnEventTags.kflidDateOfEvent,
                                                   (int)CellarModuleDefns.kcptInteger, 0),
                           "date of event not preloaded");
            int nDateEvent = m_sda.get_IntProp(hvoEvent,
                                               (int)RnEvent.RnEventTags.kflidDateOfEvent);

            Assert.IsTrue(m_sda.get_IsPropInCache(hvoEvent,
                                                  (int)RnEvent.RnEventTags.kflidDateOfEvent,
                                                  (int)CellarModuleDefns.kcptInteger, 0),
                          "autoloaded date of event");

            // Todo: find example of int64 prop and test.

            // Test loading of binary data (into a TsTextProps).
            object obj = m_sda.get_UnknownProp(hvoPara, (int)StPara.StParaTags.kflidStyleRules);

            Assert.IsNotNull(obj as ITsTextProps);

            // Also loading of raw binary data, using the same prop.
            using (ArrayPtr rgbData = MarshalEx.ArrayToNative(10000, typeof(byte)))
            {
                int cb = -1;
                m_sda.BinaryPropRgb(hvoPara, (int)StPara.StParaTags.kflidStyleRules,
                                    rgbData, 10000, out cb);
                Assert.IsTrue(cb > 0, "got some bytes using BinaryPropRgb");
                // Enhance JohnT: wish I could figure what they ought to be and test...

                // Get a UserView object (they have no owner, so go direct)
                SqlConnection con = new SqlConnection(string.Format("Server={0}; Database={1}; User ID = fwdeveloper;"
                                                                    + "Password=careful; Pooling=false;",
                                                                    m_fdoCache.ServerName, m_fdoCache.DatabaseName));
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandText = "select top 2 id from UserView";
                SqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                int hvoUv = reader.GetInt32(0);
                reader.Close();
                con.Close();

                // Guid prop
                Guid guidUv = m_sda.get_GuidProp(hvoUv, (int)UserView.UserViewTags.kflidApp);
                Assert.IsFalse(guidUv == Guid.Empty, "got non-empty guid");

                // Time prop
                long lEventTime = m_sda.get_TimeProp(hvoEvent,
                                                     (int)RnGenericRec.RnGenericRecTags.kflidDateCreated);
                Assert.IsFalse(lEventTime == 0, "got meaningful time");                 // Enhance JohnT: really verify.

                // Int prop
                int viewSubtype = m_sda.get_IntProp(hvoUv, (int)UserView.UserViewTags.kflidSubType);
                // Enhance JohnT: think of a way to verify...

                // get_Prop: Time
                object objMod = m_sda.get_Prop(hvoRec3,
                                               (int)RnGenericRec.RnGenericRecTags.kflidDateModified);
                Assert.IsTrue(objMod is long);
                // get_Prop: String
                int hvoRec0 = m_sda.get_VecItem(hvoNotebook,
                                                (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, 0);
                object objTitle = m_sda.get_Prop(hvoRec0,
                                                 (int)RnGenericRec.RnGenericRecTags.kflidTitle);
                Assert.IsTrue(objTitle is ITsString, "get_Prop title is string");
                // get_Prop: Int
                object objType = m_sda.get_Prop(hvoUv, (int)UserView.UserViewTags.kflidType);
                Assert.IsTrue(objType is int, "get_Prop type is integer");

                // Confirm some more results by loading through FDO
                ICmObject objRec3 = CmObject.CreateFromDBObject(m_fdoCache, hvoRec3);
                Assert.IsTrue(objRec3 is IRnGenericRec, "object of correct type");
                IRnGenericRec grRec3 = (IRnGenericRec)objRec3;
                // I'd prefer to use full ITsString equality test, but not sure how to get
                // a regular ITsString from FDO obj.
                Assert.AreEqual(qtssRec3Title.Text, grRec3.Title.Text,
                                "two ways to retrieve R3 title match");

                // Can't try this yet because FDO GenDate not yet implemented. The data type might not
                // be right anyway.
                //			CmObject objEvent = CmObject.CreateFromDBObject(m_fdoCache, hvoEvent);
                //			Assert.IsTrue(objEvent is RnEvent, "type of event");
                //			RnEvent ev1 = (RnEvent) objEvent;
                //			Assert.AreEqual(ev1.DateOfEvent, nDateEvent, "date of event matches");
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="tag"></param>
 /// <returns></returns>
 public string get_UnicodeProp(int obj, int tag)
 {
     return(m_sda.get_UnicodeProp(obj, tag));
 }
Example #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the flids for basic data (bool, string, int, etc.)
        /// </summary>
        /// <param name="thisFlid">The object type flid.</param>
        /// <param name="flidType">The owning flid type.</param>
        /// <param name="hvoSrc">The hvo of the source object.</param>
        /// <param name="hvoNew">The hvo of the new object.</param>
        /// ------------------------------------------------------------------------------------
        private void HandleBasicOrStringFlid(int thisFlid, int flidType, int hvoSrc, int hvoNew)
        {
            // Basic and String properties are copied
            switch (flidType)
            {
            // Basic Properties follow

            case (int)CellarPropertyType.Binary:
                string flidName = m_mdc.GetFieldName(thisFlid);
                if (flidName == "Rules" || flidName == "StyleRules")
                {
                    CopyBinaryAsTextProps(thisFlid, hvoSrc, hvoNew);
                }
                else
                {
                    CopyBinaryAsBinary(thisFlid, hvoSrc, hvoNew);
                }
                break;

            case (int)CellarPropertyType.Boolean:
                // Copy boolean value
                m_sda.SetBoolean(hvoNew, thisFlid, m_sda.get_BooleanProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.Guid:
                // Copy guid value
                // These are currently used as the ID for an application, or a version number, or a Scripture Check ID)
                m_sda.SetGuid(hvoNew, thisFlid, m_sda.get_GuidProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.GenDate:                     // Fall through, since a GenDate is an int.
            case (int)CellarPropertyType.Integer:
                // Copy integer value
                m_sda.SetInt(hvoNew, thisFlid, m_sda.get_IntProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.Time:
                // Copy time value
                m_sda.SetTime(hvoNew, thisFlid, m_sda.get_TimeProp(hvoSrc, thisFlid));
                break;

            // String Properties follow

            case (int)CellarPropertyType.String:
                // Copy string value
                // Review: Please check these next three!
                m_sda.SetString(hvoNew, thisFlid, m_sda.get_StringProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.Unicode:
                // Copy Unicode string
                m_sda.set_UnicodeProp(hvoNew, thisFlid, m_sda.get_UnicodeProp(hvoSrc, thisFlid));
                break;

            case (int)CellarPropertyType.MultiString:                     // Fall through
            case (int)CellarPropertyType.MultiUnicode:
                ITsMultiString sMulti = m_sda.get_MultiStringProp(hvoSrc, thisFlid);
                for (int i = 0; i < sMulti.StringCount; i++)
                {
                    int       ws;
                    ITsString tss = sMulti.GetStringFromIndex(i, out ws);
                    m_sda.SetMultiStringAlt(hvoNew, thisFlid, ws, tss);
                }
                break;

            default:
                throw new FDOInvalidFieldTypeException(String.Format("CopyObject: Unsupported field type {0}.", flidType));
            }
        }
Example #8
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Display the specified object (from an ORC embedded in a string). The default
        /// here knows how to display IPictures.
        /// </summary>
        /// <param name="vwenv"></param>
        /// <param name="hvo"></param>
        /// -----------------------------------------------------------------------------------
        public virtual void DisplayEmbeddedObject(IVwEnv vwenv, int hvo)
        {
            CheckDisposed();
            // See if it is a CmPicture.
            ISilDataAccess sda   = vwenv.DataAccess;
            int            clsid = sda.get_IntProp(hvo, (int)CmObjectFields.kflidCmObject_Class);

            if (clsid != CmPicture.kclsidCmPicture)
            {
                return;                 // don't know how to deal with it.
            }
            int hvoFile = sda.get_ObjectProp(hvo, (int)CmPicture.CmPictureTags.kflidPictureFile);

            if (hvoFile == 0)
            {
                return;
            }
            string path;
            string fileName = sda.get_UnicodeProp(hvoFile, (int)CmFile.CmFileTags.kflidInternalPath);

            if (Path.IsPathRooted(fileName))
            {
                path = fileName;
            }
            else
            {
                if (m_hvoLangProject == 0)
                {
                    TryToSetLangProjectHvo(sda, hvo);
                }
                string externalRoot = sda.get_UnicodeProp(m_hvoLangProject, (int)LangProject.LangProjectTags.kflidExtLinkRootDir);
                if (String.IsNullOrEmpty(externalRoot))
                {
                    path = Path.Combine(DirectoryFinder.FWDataDirectory, fileName);
                }
                else
                {
                    path = Path.Combine(externalRoot, fileName);
                }
            }
            vwenv.set_IntProperty((int)FwTextPropType.ktptAlign,
                                  (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
            Image image;

            try
            {
                image = Image.FromFile(FileUtils.ActualFilePath(path));
            }
            catch
            {
                // unable to read image. set to default image that indicates an invalid image.
                image = ResourceHelper.ImageNotFoundX;
            }
            stdole.IPicture picture;
            try
            {
                picture = (stdole.IPicture)OLECvt.ToOLE_IPictureDisp(image);
            }
            catch
            {
                // conversion to OLE format from current image format is not supported (e.g. WMF file)
                // try to convert it to a bitmap and convert it to OLE format again.
                // TODO: deal with transparency
                // We could just do the following line (creating a new bitmap) instead of going
                // through a memory stream, but then we end up with an image that is too big.
                //image = new Bitmap(image, image.Size);
                using (MemoryStream imageStream = new MemoryStream())
                {
                    image.Save(imageStream, ImageFormat.Png);
                    image = Image.FromStream(imageStream, true);
                }
                picture = (stdole.IPicture)OLECvt.ToOLE_IPictureDisp(image);
            }
            // -1 is ktagNotAnAttr. 0 width & height mean use natural width/height.
            vwenv.AddPictureWithCaption(picture, -1, CaptionProps, hvoFile, m_wsDefault, 0, 0, this);
            image.Dispose();
        }
Example #9
0
        private void AddHeadwordWithHomograph(IVwEnv vwenv, int hvo)
        {
            ISilDataAccess sda   = vwenv.DataAccess;
            int            hvoLf = sda.get_ObjectProp(hvo,
                                                      LexEntryTags.kflidLexemeForm);
            int hvoType = 0;

            if (hvoLf != 0)
            {
                hvoType = sda.get_ObjectProp(hvoLf,
                                             MoFormTags.kflidMorphType);
            }

            // If we have a type of morpheme, show the appropriate prefix that indicates it.
            // We want vernacular so it will match the point size of any aligned vernacular text.
            // (The danger is that the vernacular font doesn't have these characters...not sure what
            // we can do about that, but most do, and it looks awful in analysis if that is a
            // much different size from vernacular.)
            string sPrefix = null;

            if (hvoType != 0)
            {
                sPrefix = sda.get_UnicodeProp(hvoType, MoMorphTypeTags.kflidPrefix);
            }

            // Show homograph number if non-zero.
            int defUserWs  = m_cache.WritingSystemFactory.UserWs;
            int nHomograph = sda.get_IntProp(hvo, LexEntryTags.kflidHomographNumber);
            var hc         = m_cache.ServiceLocator.GetInstance <HomographConfiguration>();

            //Insert HomographNumber when position is Before
            if (hc.HomographNumberBefore)
            {
                InsertHomographNumber(vwenv, hc, nHomograph, defUserWs);
            }

            // LexEntry.ShortName1; basically tries for form of the lexeme form, then the citation form.
            bool fGotLabel = false;
            int  wsActual  = 0;

            if (hvoLf != 0)
            {
                // if we have a lexeme form and its label is non-empty, use it.
                if (TryMultiStringAlt(sda, hvoLf, MoFormTags.kflidForm, out wsActual))
                {
                    m_wsActual = wsActual;
                    fGotLabel  = true;
                    if (sPrefix != null)
                    {
                        vwenv.AddString(TsStringUtils.MakeString(sPrefix, wsActual));
                    }
                    vwenv.AddObjProp(LexEntryTags.kflidLexemeForm, this, kfragFormForm);
                }
            }
            if (!fGotLabel)
            {
                // If we didn't get a useful form from the lexeme form try the citation form.
                if (TryMultiStringAlt(sda, hvo, LexEntryTags.kflidCitationForm, out wsActual))
                {
                    m_wsActual = wsActual;
                    if (sPrefix != null)
                    {
                        vwenv.AddString(TsStringUtils.MakeString(sPrefix, wsActual));
                    }
                    vwenv.AddStringAltMember(LexEntryTags.kflidCitationForm, wsActual, this);
                    fGotLabel = true;
                }
            }

            if (!fGotLabel)
            {
                // If that fails just show two questions marks.
                if (sPrefix != null)
                {
                    vwenv.AddString(TsStringUtils.MakeString(sPrefix, wsActual));
                }
                vwenv.AddString(TsStringUtils.MakeString(FdoUiStrings.ksQuestions, defUserWs));                                 // was "??", not "???"
            }

            // If we have a lexeme form type show the appropriate postfix.
            if (hvoType != 0)
            {
                vwenv.AddString(TsStringUtils.MakeString(
                                    sda.get_UnicodeProp(hvoType, MoMorphTypeTags.kflidPostfix), wsActual));
            }

            vwenv.NoteDependency(new[] { hvo }, new[] { LexEntryTags.kflidHomographNumber }, 1);
            //Insert HomographNumber when position is After
            if (!hc.HomographNumberBefore)
            {
                InsertHomographNumber(vwenv, hc, nHomograph, defUserWs);
            }
        }
Example #10
0
		internal static string[] AddStringFromOtherObj(XmlNode frag, int hvoTarget, FdoCache cache, ISilDataAccess sda)
		{
			int flid = XmlVc.GetFlid(frag, hvoTarget, sda);
			ITsStrFactory tsf = cache.TsStrFactory;
			CellarPropertyType itype = (CellarPropertyType)sda.MetaDataCache.GetFieldType(flid);
			if (itype == CellarPropertyType.Unicode)
			{
				return new[] { sda.get_UnicodeProp(hvoTarget, flid) };
			}
			else if (itype == CellarPropertyType.String)
			{
				return new[] { sda.get_StringProp(hvoTarget, flid).Text };
			}
			else // multistring of some type
			{
				int wsid = 0;
				string sep = "";
				if (s_cwsMulti > 1)
				{
					string sLabelWs = XmlUtils.GetOptionalAttributeValue(frag, "ws");
					if (sLabelWs != null && sLabelWs == "current")
					{
						sep = DisplayMultiSep(frag)
							+ DisplayWsLabel(s_qwsCurrent, cache);
						wsid = s_qwsCurrent.Handle;
					}
				}
				if (wsid == 0)
					wsid = WritingSystemServices.GetWritingSystem(cache,
						frag, null, WritingSystemServices.kwsAnal).Handle;
				if (itype == CellarPropertyType.MultiUnicode)
				{
					return new[] { sep, sda.get_MultiStringAlt(hvoTarget, flid, wsid).Text };
				}
				else
				{
					return new[] { sep, sda.get_MultiStringAlt(hvoTarget, flid, wsid).Text };
				}
			}
		}
Example #11
0
		/// <summary>
		/// Get the Linked Files Root Directory value from the language project represented by the
		/// ISilDataAccess argument.
		/// </summary>
		protected string GetLinkedFilesRootDir(ISilDataAccess sda)
		{
			var linkedFilesRootDirID = sda.MetaDataCache.GetFieldId("LangProject", "LinkedFilesRootDir", false);
			int hvo = GetHvoOfProject(sda);
			return sda.get_UnicodeProp(hvo, linkedFilesRootDirID);
		}
Example #12
0
        private void AddHeadwordWithHomograph(IVwEnv vwenv, int hvo)
        {
            ISilDataAccess sda   = vwenv.DataAccess;
            int            hvoLf = sda.get_ObjectProp(hvo,
                                                      LexEntryTags.kflidLexemeForm);
            int hvoType = 0;

            if (hvoLf != 0)
            {
                hvoType = sda.get_ObjectProp(hvoLf,
                                             MoFormTags.kflidMorphType);
            }

            // If we have a type of morpheme, show the appropriate prefix that indicates it.
            // We want vernacular so it will match the point size of any aligned vernacular text.
            // (The danger is that the vernacular font doesn't have these characters...not sure what
            // we can do about that, but most do, and it looks awful in analysis if that is a
            // much different size from vernacular.)
            string sPrefix = null;

            if (hvoType != 0)
            {
                sPrefix = sda.get_UnicodeProp(hvoType, MoMorphTypeTags.kflidPrefix);
            }

            // LexEntry.ShortName1; basically tries for form of the lexeme form, then the citation form.
            bool fGotLabel = false;
            int  wsActual  = 0;

            if (hvoLf != 0)
            {
                // if we have a lexeme form and its label is non-empty, use it.
                if (TryMultiStringAlt(sda, hvoLf, MoFormTags.kflidForm, out wsActual))
                {
                    m_wsActual = wsActual;
                    fGotLabel  = true;
                    if (sPrefix != null)
                    {
                        vwenv.AddString(TsStringUtils.MakeTss(sPrefix, wsActual));
                    }
                    vwenv.AddObjProp(LexEntryTags.kflidLexemeForm, this, kfragFormForm);
                }
            }
            if (!fGotLabel)
            {
                // If we didn't get a useful form from the lexeme form try the citation form.
                if (TryMultiStringAlt(sda, hvo, LexEntryTags.kflidCitationForm, out wsActual))
                {
                    m_wsActual = wsActual;
                    if (sPrefix != null)
                    {
                        vwenv.AddString(TsStringUtils.MakeTss(sPrefix, wsActual));
                    }
                    vwenv.AddStringAltMember(LexEntryTags.kflidCitationForm, wsActual, this);
                    fGotLabel = true;
                }
            }
            int defUserWs = m_cache.WritingSystemFactory.UserWs;

            if (!fGotLabel)
            {
                // If that fails just show two questions marks.
                if (sPrefix != null)
                {
                    vwenv.AddString(TsStringUtils.MakeTss(sPrefix, wsActual));
                }
                vwenv.AddString(m_cache.TsStrFactory.MakeString(FdoUiStrings.ksQuestions, defUserWs));                                  // was "??", not "???"
            }

            // If we have a lexeme form type show the appropriate postfix.
            if (hvoType != 0)
            {
                vwenv.AddString(TsStringUtils.MakeTss(
                                    sda.get_UnicodeProp(hvoType, MoMorphTypeTags.kflidPostfix), wsActual));
            }

            // Show homograph number if non-zero.
            int nHomograph = sda.get_IntProp(hvo,
                                             LexEntryTags.kflidHomographNumber);

            vwenv.NoteDependency(new[] { hvo }, new[] { LexEntryTags.kflidHomographNumber }, 1);
            if (nHomograph > 0)
            {
                // Use a string builder to embed the properties in with the TsString.
                // this allows our TsStringCollectorEnv to properly encode the superscript.
                // ideally, TsStringCollectorEnv could be made smarter to handle SetIntPropValues
                // since AppendTss treats the given Tss as atomic.
                ITsIncStrBldr tsBldr = TsIncStrBldrClass.Create();
                tsBldr.SetIntPropValues((int)FwTextPropType.ktptSuperscript,
                                        (int)FwTextPropVar.ktpvEnum,
                                        (int)FwSuperscriptVal.kssvSub);
                tsBldr.SetIntPropValues((int)FwTextPropType.ktptBold,
                                        (int)FwTextPropVar.ktpvEnum,
                                        (int)FwTextToggleVal.kttvForceOn);
                tsBldr.SetIntPropValues((int)FwTextPropType.ktptWs,
                                        (int)FwTextPropVar.ktpvDefault, defUserWs);
                var hc = m_cache.ServiceLocator.GetInstance <HomographConfiguration>();
                StringServices.InsertHomographNumber(tsBldr, nHomograph, hc, HomographConfiguration.HeadwordVariant.Main, m_cache);
                vwenv.AddString(tsBldr.GetString());
            }
        }
Example #13
0
 /// <summary>
 /// Read a Unicode string property. (Note also ${#UnicodePropRgch} if you don't want
 /// a BSTR allocated.
 /// NULL, S_FALSE if property not found. Some implementations may return
 /// S_OK and empty string if property not found.
 /// Sets a Unicode string property.
 ///</summary>
 /// <param name='hvo'> </param>
 /// <param name='tag'> </param>
 /// <returns></returns>
 public virtual string get_UnicodeProp(int hvo, int tag)
 {
     return(m_baseSda.get_UnicodeProp(hvo, tag));
 }