/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new picture, given a text representation (e.g., from the clipboard). /// NOTE: The caption is put into the default vernacular writing system. /// </summary> /// <param name="fcCache">FDO cache</param> /// <param name="sTextRepOfPicture">Clipboard representation of a picture</param> /// <param name="sFolder">The name of the CmFolder where picture should be stored</param> /// <param name="anchorLoc">The anchor location that can be used to determine (may be 0).</param> /// <param name="locationParser">The picture location parser (can be null).</param> /// ------------------------------------------------------------------------------------ public CmPicture(FdoCache fcCache, string sTextRepOfPicture, string sFolder, int anchorLoc, IPictureLocationBridge locationParser) : base(fcCache, fcCache.CreateObject(CmPicture.kclsidCmPicture)) { string[] tokens = sTextRepOfPicture.Split(new char[] {'|'}); if (tokens.Length < 9 || tokens[0] != "CmPicture") throw new ArgumentException("The clipboard format for a Picture was invalid"); string sDescription = tokens[1]; string srcFilename = tokens[2]; string sLayoutPos = tokens[3]; string sLocationRange = tokens[4]; string sCopyright = tokens[5]; string sCaption = tokens[6]; string sLocationRangeType = tokens[7]; string sScaleFactor = tokens[8]; PictureLocationRangeType locRangeType = ParseLocationRangeType(sLocationRangeType); InitializeNewPicture(sFolder, anchorLoc, locationParser, sDescription, srcFilename, sLayoutPos, sLocationRange, sCopyright, sCaption, locRangeType, sScaleFactor); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new picture, given string representations of most of the parameters. Used /// for creating a picture from a Toolbox-style Standard Format import. /// </summary> /// <param name="fcCache">FDO cache</param> /// <param name="sFolder">The name of the CmFolder where picture should be stored</param> /// <param name="anchorLoc">The anchor location that the locationParser can use if /// necessary (can be 0).</param> /// <param name="locationParser">The location parser.</param> /// <param name="descriptions">The descriptions in 0 or more writing systems.</param> /// <param name="srcFilename">The picture filename.</param> /// <param name="sLayoutPos">The layout position (as a string).</param> /// <param name="sLocationRange">The location range (as a string).</param> /// <param name="sCopyright">The copyright.</param> /// <param name="tssCaption">The caption, in the default vernacular writing system.</param> /// <param name="locRangeType">Assumed type of the location range.</param> /// <param name="sScaleFactor">The scale factor (as a string).</param> /// ------------------------------------------------------------------------------------ public CmPicture(FdoCache fcCache, string sFolder, int anchorLoc, IPictureLocationBridge locationParser, Dictionary<int, string> descriptions, string srcFilename, string sLayoutPos, string sLocationRange, string sCopyright, ITsString tssCaption, PictureLocationRangeType locRangeType, string sScaleFactor) : base(fcCache, fcCache.CreateObject(CmPicture.kclsidCmPicture)) { InitializeNewPicture(sFolder, anchorLoc, locationParser, null, srcFilename, sLayoutPos, sLocationRange, sCopyright, tssCaption, locRangeType, sScaleFactor); if (descriptions != null) { foreach (int ws in descriptions.Keys) Description.SetAlternative(descriptions[ws], ws); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a CmPicture for the given file, having the given caption, and located in /// the given folder. /// </summary> /// <param name="fcCache">FDO cache</param> /// <param name="srcFilename">The path to the original filename (an internal copy will /// be made in this method)</param> /// <param name="captionTss">The caption</param> /// <param name="sFolder">The name of the CmFolder where picture should be stored /// </param> /// ------------------------------------------------------------------------------------ public CmPicture(FdoCache fcCache, string srcFilename, ITsString captionTss, string sFolder) : base(fcCache, fcCache.CreateObject(CmPicture.kclsidCmPicture)) { InitializeNewPicture(srcFilename, captionTss, null, PictureLayoutPosition.CenterInColumn, 100, PictureLocationRangeType.AfterAnchor, 0, 0, null, sFolder); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new picture, given string representations of most of the parameters. Used /// for creating a picture from a USFM-style Standard Format import. /// </summary> /// <param name="fcCache">FDO cache</param> /// <param name="sFolder">The name of the CmFolder where picture should be stored</param> /// <param name="anchorLoc">The anchor location that can be used to determine (may be 0).</param> /// <param name="locationParser">The location parser.</param> /// <param name="sDescription">Illustration description in English.</param> /// <param name="srcFilename">The picture filename.</param> /// <param name="sLayoutPos">The layout position (as a string).</param> /// <param name="sLocationRange">The location range (as a string).</param> /// <param name="sCopyright">The copyright.</param> /// <param name="sCaption">The caption, in the default vernacular writing system.</param> /// <param name="locRangeType">Assumed type of the location range.</param> /// <param name="sScaleFactor">The scale factor (as a string).</param> /// ------------------------------------------------------------------------------------ public CmPicture(FdoCache fcCache, string sFolder, int anchorLoc, IPictureLocationBridge locationParser, string sDescription, string srcFilename, string sLayoutPos, string sLocationRange, string sCopyright, string sCaption, PictureLocationRangeType locRangeType, string sScaleFactor) : base(fcCache, fcCache.CreateObject(CmPicture.kclsidCmPicture)) { InitializeNewPicture(sFolder, anchorLoc, locationParser, sDescription, srcFilename, sLayoutPos, sLocationRange, sCopyright, sCaption, locRangeType, sScaleFactor); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a new entry. /// The caller is expected to call PropChanged on the cache to notify the record /// list of the new record. /// </summary> /// <param name="cache">The cache.</param> /// <param name="morphType">Type of the morph.</param> /// <param name="tssLexemeForm">The TSS lexeme form.</param> /// <param name="gloss">The gloss.</param> /// <param name="dummyMSA">The dummy MSA.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public static ILexEntry CreateEntry(FdoCache cache, IMoMorphType morphType, ITsString tssLexemeForm, string gloss, DummyGenericMSA dummyMSA) { using (new UndoRedoTaskHelper(cache, Strings.ksUndoCreateEntry, Strings.ksRedoCreateEntry)) { ILexEntry entry = null; // NO: Since this fires a PropChanged, and we do it ourselves later on. // entry = (LexEntry)entries.Add(new LexEntry()); // CreateObject creates the entry without a PropChanged. int entryHvo = cache.CreateObject(LexEntry.kClassId, cache.LangProject.LexDbOAHvo, (int)LexDb.LexDbTags.kflidEntries, 0); // 0 is fine, since the entries prop is not a sequence. entry = LexEntry.CreateFromDBObject(cache, entryHvo); ILexSense sense = LexSense.CreateSense(entry, dummyMSA, gloss); if (morphType.Guid.ToString() == MoMorphType.kguidMorphCircumfix) { // Set Lexeme form to lexeme form and circumfix SetCircumfixLexemeForm(cache, entry, tssLexemeForm, morphType); // Create two allomorphs, one for the left member and one for the right member. SplitCircumfixIntoLeftAndRightAllomorphs(cache, entry, tssLexemeForm, sense); } else { IMoForm allomorph = MoForm.CreateAllomorph(entry, sense.MorphoSyntaxAnalysisRA, tssLexemeForm, morphType, true); } (entry as LexEntry).UpdateHomographNumbersAccountingForNewEntry(); return entry; } }
static private void SetCircumfixLexemeForm(FdoCache cache, ILexEntry entry, ITsString tssLexemeForm, IMoMorphType morphType) { int iHvo = cache.CreateObject(MoAffixAllomorph.kClassId, entry.Hvo, (int)LexEntry.LexEntryTags.kflidLexemeForm, 0); MoAffixAllomorph lexemeAllo = new MoAffixAllomorph(cache, iHvo); lexemeAllo.Form.SetAlternativeTss(tssLexemeForm); lexemeAllo.MorphTypeRA = morphType; lexemeAllo.IsAbstract = true; }
/// <summary> /// This should be the preferred way to create CmBaseAnnotations that ought not to be owned: /// currently Wfics, Pfics, paragraph segments, free translations, literal translations, and notes. /// </summary> /// <param name="cache"></param> /// <returns></returns> public static ICmIndirectAnnotation CreateUnownedIndirectAnnotation(FdoCache cache) { int hvoNew = cache.CreateObject(kclsidCmIndirectAnnotation); return CmObject.CreateFromDBObject(cache, hvoNew, typeof(CmIndirectAnnotation), false, false) as ICmIndirectAnnotation; }
internal static CmObjectUi DefaultCreateNewUiObject(uint classId, int hvoOwner, int flid, int insertionPosition, FdoCache cache) { CmObjectUi newUiObj; cache.BeginUndoTask(FdoUiStrings.ksUndoInsert, FdoUiStrings.ksRedoInsert); int newHvo = cache.CreateObject((int)classId, hvoOwner, flid, insertionPosition); newUiObj = CmObjectUi.MakeUi(cache, newHvo, classId); cache.EndUndoTask(); cache.MainCacheAccessor.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoOwner, flid, insertionPosition, 1, 0); return newUiObj; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Static method to create a new structured text. It creates an StText object owned by /// hvoOwner in property tag, then creates an StTxtPara owned by the new StText. It /// sets the contents of the paragraph to be an empty string in the specified writing system, /// and Normal paragraph style. /// </summary> /// ENHANCE JohnT: probably we will identify styles by something other than name. /// REVIEW JohnT(TomB): Are we supposed to be supplying a style name rather than just /// using "Normal"? /// /// <param name="cache">FieldWorks database access</param> /// <param name="hvoOwner">id of object to own the new StText</param> /// <param name="propTag">property (field) type of the new StText</param> /// <param name="ws">language writing system of empty paragraph</param> /// <returns>HVO of the newly created StText object</returns> /// ----------------------------------------------------------------------------------- public static int MakeEmptyStText(FdoCache cache, int hvoOwner, int propTag, int ws) { // REVIEW TomB: Lastparm should really be null if Randy changes CreateObject. // Response from RandyR: I changed CreateObject. Null should work for // everything now. // Most of this code could be moved into the FDO objects, if desired. int hvoStText = cache.CreateObject(StText.kclsidStText, hvoOwner, propTag, 0); int hvoPara = cache.CreateObject(StTxtPara.kclsidStTxtPara, hvoStText, (int)StText.StTextTags.kflidParagraphs, 0); // Set the style of the paragraph to Normal ITsTextProps ttpNormal; ITsPropsBldr tsPropsBldr = TsPropsBldrClass.Create(); tsPropsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, StyleNames.ksNormal); ttpNormal = tsPropsBldr.GetTextProps(); cache.MainCacheAccessor.SetUnknown(hvoPara, (int)StPara.StParaTags.kflidStyleRules, ttpNormal); // Set its contents to an empty string in the right writing system. ITsStrFactory tsFactory = TsStrFactoryClass.Create(); cache.SetTsStringProperty(hvoPara, (int)StTxtPara.StTxtParaTags.kflidContents, tsFactory.MakeStringRgch("", 0, ws)); return hvoStText; }
/// ------------------------------------------------------------------------------------ ///<summary> ///Initialize a new ownerless FDO object, ///based on a newly created database object. ///Override this method to perform additional initialization. ///</summary> /// <param name="fcCache">The FDO cache object.</param> /// ------------------------------------------------------------------------------------ protected internal virtual void InitNew(FdoCache fcCache) { Debug.Assert(fcCache != null); Debug.Assert(m_hvo == (int)SpecialHVOValues.kHvoOwnerPending); m_hvo = fcCache.CreateObject(ClassID); m_cache = fcCache; Debug.Assert(m_hvo > 0); }
/// ------------------------------------------------------------------------------------ ///<summary> ///Initialize a new FDO object, based on a newly created database object. ///Override this method to perform additional initialization. ///</summary> /// <param name="fcCache">The FDO cache object.</param> /// <param name="hvoOwner">ID of the owning object.</param> /// <param name="flidOwning">Field ID that will own the new object.</param> ///<param name="ihvo">Index for where to insert new object in a sequence. ///[Note: This parameter is ignored when ft is not kcptOwningSequence.] ///</param> /// ------------------------------------------------------------------------------------ protected internal virtual void InitNew(FdoCache fcCache, int hvoOwner, int flidOwning, int ihvo) { Debug.Assert(fcCache != null); Debug.Assert(hvoOwner > 0); Debug.Assert(flidOwning > 0); Debug.Assert(m_hvo == (int)SpecialHVOValues.kHvoOwnerPending); m_hvo = fcCache.CreateObject(ClassID, hvoOwner, flidOwning, ihvo); m_cache = fcCache; Debug.Assert(m_hvo > 0); }