/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public InternalFwMultiParaTextBox(IStText stText, IVwStylesheet styleSheet) { WritingSystemFactory = stText.Cache.WritingSystemFactory; CurrentWs = stText.Cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle; StyleSheet = styleSheet; AutoScroll = true; // Sandbox cache. m_sda = VwCacheDaClass.Create(); m_sda.WritingSystemFactory = WritingSystemFactory; m_sda.SetActionHandler(new SimpleActionHandler()); List <int> memHvos = new List <int>(); foreach (IStTxtPara para in stText.ParagraphsOS) { memHvos.Add(para.Hvo); m_sda.SetString(para.Hvo, StTxtParaTags.kflidContents, para.Contents); } // If no paragraphs were passed in, then create one to get the user started off. if (memHvos.Count == 0) { ITsStrFactory strFact = TsStrFactoryClass.Create(); ITsString paraStr = strFact.MakeString(String.Empty, CurrentWs); m_sda.SetString(kDummyParaHvo, StTxtParaTags.kflidContents, paraStr); memHvos.Add(kDummyParaHvo); } ((IVwCacheDa)m_sda).CacheVecProp(kMemTextHvo, StTextTags.kflidParagraphs, memHvos.ToArray(), memHvos.Count); }
/// <summary> /// Look for a secondary-cache object that corresponds to hvoReal. If one does not already exist, /// create it by appending to property flidOwn of object hvoOwner. /// Set its flidName property to a string name in writing system ws. /// If hvoReal is zero, just create an object, but don't look for or create an association. /// </summary> /// <param name="hvoReal"></param> /// <param name="clid"></param> /// <param name="hvoOwner"></param> /// <param name="flidOwn"></param> /// <param name="flidName"></param> /// <param name="tss"></param> /// <returns></returns> public int FindOrCreateSec(int hvoReal, int clid, int hvoOwner, int flidOwn, int flidName, ITsString tss) { CheckDisposed(); int hvoSec = FindOrCreateSec(hvoReal, clid, hvoOwner, flidOwn); m_sda.SetString(hvoSec, flidName, tss); return(hvoSec); }
/// <summary> /// Parse the text in hvoPara.Contents[vc.DestWs] and make words /// </summary> /// <param name="hvoPara"></param> public void Parse(int hvoPara) { ITsString tssSrc = m_sda.get_MultiStringAlt(hvoPara, ViewSampleVc.ktagParaContents, m_vc.DestWs); WordMaker wm = new WordMaker(tssSrc, m_wsf); int ichMin, ichLim; int cbundle = m_sda.get_VecSize(hvoPara, ViewSampleVc.ktagParaBundles); // Clean it out. This wouldn't normally be appropriate for an owning property, but we can get away // with it for a non-database cache. if (cbundle != 0) { m_sda.Replace(hvoPara, ViewSampleVc.ktagParaBundles, 0, cbundle, new int[0], 0); } int ibundle = 0; ITsPropsFactory tpf = (ITsPropsFactory) new FwKernelLib.TsPropsFactoryClass(); ITsTextProps ttp = tpf.MakeProps(null, m_vc.SourceWs, 0); for (ITsString tssWord = wm.NextWord(out ichMin, out ichLim); tssWord != null; tssWord = wm.NextWord(out ichMin, out ichLim)) { // 4 is an arbitrary classid; this kind of cache does nothing with it. int hvoBundle = m_sda.MakeNewObject(4, hvoPara, ViewSampleVc.ktagParaBundles, ibundle); ibundle++; m_sda.SetString(hvoBundle, ViewSampleVc.ktagBundleBase, tssWord); ITsStrBldr tsb = tssWord.GetBldr(); tsb.Replace(0, 0, "idiom(", ttp); tsb.Replace(tsb.get_Length(), tsb.get_Length(), ")", ttp); m_sda.SetString(hvoBundle, ViewSampleVc.ktagBundleIdiom, tsb.GetString()); tsb = tssWord.GetBldr(); tsb.Replace(0, 0, "ling(", ttp); tsb.Replace(tsb.get_Length(), tsb.get_Length(), ")", ttp); m_sda.SetString(hvoBundle, ViewSampleVc.ktagBundleLing, tsb.GetString()); } m_sda.PropChanged(null, (int)FwViews.PropChangeType.kpctNotifyAll, hvoPara, ViewSampleVc.ktagParaBundles, 0, ibundle, cbundle); }
public override void MakeRoot() { CheckDisposed(); if (m_fdoCache == null || DesignMode || m_slice.ContainingDataTree == null) { return; } m_rootb = VwRootBoxClass.Create(); m_rootb.SetSite(this); if (m_ws == 0) { m_ws = m_fdoCache.DefaultAnalWs; } m_hvoStText = m_fdoCache.GetObjProperty(m_hvoOwner, m_flid); // If we don't already have an StText in this field, make one now. if (m_hvoStText == 0) { ISilDataAccess sda = m_fdoCache.MainCacheAccessor; // Create one and initialize it. Don't use the FdoCache method, because it's important NOT to notify // our own data tree of the change...if we do, it could start a new regenerate in the middle of an // existing one with bad consequences. m_hvoStText = sda.MakeNewObject(StText.kclsidStText, m_hvoOwner, m_flid, -2); int hvoStTxtPara = sda.MakeNewObject(StTxtPara.kclsidStTxtPara, m_hvoStText, (int)StText.StTextTags.kflidParagraphs, 0); ITsStrFactory tsf = TsStrFactoryClass.Create(); sda.SetString(hvoStTxtPara, (int)StTxtPara.StTxtParaTags.kflidContents, tsf.MakeString("", m_ws)); // Notify change on the main property. The other properties we changed are part of the new object, and nothing // can know their previous state and need to see the change. sda.PropChanged(m_slice.ContainingDataTree, (int)PropChangeType.kpctNotifyAllButMe, m_hvoOwner, m_flid, 0, 1, 0); } m_vc = new StVc("Normal", m_ws); m_vc.Cache = m_fdoCache; m_vc.Editable = true; m_rootb.DataAccess = m_fdoCache.MainCacheAccessor; m_rootb.SetRootObject(m_hvoStText, m_vc, (int)StTextFrags.kfrText, m_styleSheet); base.MakeRoot(); m_dxdLayoutWidth = kForceLayout; // Don't try to draw until we get OnSize and do layout. //TODO: //ptmw->RegisterRootBox(qrootb); }
/// <summary> /// Insert breaks for the text in the indicated range of the indicate StTxtPara /// </summary> /// <param name="ichMin"></param> /// <param name="ichLim"></param> /// <param name="hvoPara"></param> public void Guess(int ichMin, int ichLim1, int hvoPara) { Setup(hvoPara); ITsString tss = m_sda.get_StringProp(hvoPara, (int)StTxtPara.StTxtParaTags.kflidContents); ITsStrBldr bldr = tss.GetBldr(); int ichLim = ichLim1; if (ichLim1 == -1) { ichLim = tss.Length; } string txt = tss.Text; int offset = 0; // offset in tsb caused by previously introduced spaces. for (int ichStart = 0; ichStart < ichLim;) // no advance! decide inside loop. { int cch = Match(ichStart, ichLim, txt); if (cch < 0) { // no match ichStart++; } else { // match, ensure spaces. if (ichStart > 0 && !SpaceAt(bldr, ichStart + offset - 1)) { InsertSpace(bldr, ichStart + offset); offset++; } if (ichStart + cch < ichLim && !SpaceAt(bldr, ichStart + cch + offset)) { InsertSpace(bldr, ichStart + cch + offset); offset++; } ichStart += cch; } } if (offset > 0) { m_sda.SetString(hvoPara, (int)StTxtPara.StTxtParaTags.kflidContents, bldr.GetString()); m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoPara, (int)StTxtPara.StTxtParaTags.kflidContents, 0, 0, 0); } }
/// <summary> /// /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="_tss"></param> public void SetString(int hvo, int tag, ITsString _tss) { VerifyUpdate(hvo, tag); m_sda.SetString(hvo, tag, _tss); }
int MakeRealObject(ITsString tssTyped) { // Figure whether owning atomic or owning collection or owning sequence. Throw if none. // Unless we're making an unowned IText for a Notebook Record. ISilDataAccess sdaReal = m_fdoCache.DomainDataByFlid; IFwMetaDataCache mdc = sdaReal.MetaDataCache; CellarPropertyType typeOwning = (CellarPropertyType)(mdc.GetFieldType(m_flidEmptyProp) & (int)CellarPropertyTypeFilter.VirtualMask); // Make a new object of the specified class in the specified property. int ord = 0; switch (typeOwning) { default: if (m_flidEmptyProp != RnGenericRecTags.kflidText) { throw new Exception("ghost string property must be owning object property"); } break; case CellarPropertyType.OwningAtomic: ord = -2; break; case CellarPropertyType.OwningCollection: ord = -1; break; case CellarPropertyType.OwningSequence: // ord = 0 set above (inserting the first and only object at position 0). break; } string sClassRaw = mdc.GetClassName(m_clidDst); string sClass = m_mediator.StringTbl.GetString(sClassRaw, "ClassNames"); string sUndo = String.Format(DetailControlsStrings.ksUndoCreate0, sClass); string sRedo = String.Format(DetailControlsStrings.ksRedoCreate0, sClass); int hvoNewObj = 0; int hvoStringObj = 0; UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(sUndo, sRedo, m_fdoCache.ServiceLocator.GetInstance <IActionHandler>(), () => { // Special case: if we just created a Text in RnGenericRecord, and we want to show the contents // of an StTxtPara, make the intermediate objects if (m_flidEmptyProp == RnGenericRecTags.kflidText) { var servLoc = Cache.ServiceLocator; var text = servLoc.GetInstance <ITextFactory>().Create(); var stText = servLoc.GetInstance <IStTextFactory>().Create(); text.ContentsOA = stText; var para = servLoc.GetInstance <IStTxtParaFactory>().Create(); stText.ParagraphsOS.Add(para); hvoNewObj = text.Hvo; hvoStringObj = para.Hvo; // Set the RnGenericRec's Text property to reference the new text sdaReal.SetObjProp(m_hvoObj, m_flidEmptyProp, hvoNewObj); } else { hvoNewObj = hvoStringObj = sdaReal.MakeNewObject(m_clidDst, m_hvoObj, m_flidEmptyProp, ord); } // Set its property m_flidStringProp to tssTyped. If it is multilingual, choose based on ghostWs. var typeString = (CellarPropertyType)(mdc.GetFieldType(m_flidStringProp) & (int)CellarPropertyTypeFilter.VirtualMask); switch (typeString) { default: throw new Exception("ghost property must store strings!"); case CellarPropertyType.MultiString: case CellarPropertyType.MultiUnicode: sdaReal.SetMultiStringAlt(hvoStringObj, m_flidStringProp, m_wsToCreate, tssTyped); break; case CellarPropertyType.String: sdaReal.SetString(hvoStringObj, m_flidStringProp, tssTyped); break; } string ghostInitMethod = XmlUtils.GetOptionalAttributeValue(m_nodeObjProp, "ghostInitMethod"); if (ghostInitMethod != null) { var obj = m_fdoCache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvoNewObj); Type objType = obj.GetType(); System.Reflection.MethodInfo mi = objType.GetMethod(ghostInitMethod); mi.Invoke(obj, null); } }); return(hvoNewObj); }
/// ------------------------------------------------------------------------------------ /// <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)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public InternalFwMultiParaTextBox(IStText stText, IVwStylesheet styleSheet) { WritingSystemFactory = stText.Cache.WritingSystemFactory; CurrentWs = stText.Cache.ServiceLocator.WritingSystems.DefaultAnalysisWritingSystem.Handle; StyleSheet = styleSheet; AutoScroll = true; // Sandbox cache. m_sda = VwCacheDaClass.Create(); m_sda.WritingSystemFactory = WritingSystemFactory; m_sda.SetActionHandler(new SimpleActionHandler()); List<int> memHvos = new List<int>(); foreach (IStTxtPara para in stText.ParagraphsOS) { memHvos.Add(para.Hvo); m_sda.SetString(para.Hvo, StTxtParaTags.kflidContents, para.Contents); } // If no paragraphs were passed in, then create one to get the user started off. if (memHvos.Count == 0) { ITsStrFactory strFact = TsStrFactoryClass.Create(); ITsString paraStr = strFact.MakeString(String.Empty, CurrentWs); m_sda.SetString(kDummyParaHvo, StTxtParaTags.kflidContents, paraStr); memHvos.Add(kDummyParaHvo); } ((IVwCacheDa)m_sda).CacheVecProp(kMemTextHvo, StTextTags.kflidParagraphs, memHvos.ToArray(), memHvos.Count); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// ------------------------------------------------------------------------------------ public InternalFwMultiParaTextBox(IStText stText, IVwStylesheet styleSheet) { WritingSystemFactory = stText.Cache.LanguageWritingSystemFactoryAccessor; CurrentWs = stText.Cache.DefaultAnalWs; StyleSheet = styleSheet; AutoScroll = true; m_sda = VwCacheDaClass.Create() as ISilDataAccess; m_sda.WritingSystemFactory = WritingSystemFactory; List<int> memHvos = new List<int>(); foreach (IStTxtPara para in stText.ParagraphsOS) { memHvos.Add(para.Hvo); m_sda.SetString(para.Hvo, (int)StTxtPara.StTxtParaTags.kflidContents, para.Contents.UnderlyingTsString); } // If no paragraphs were passed in, then create one to get the user started off. if (memHvos.Count == 0) { ITsStrFactory strFact = TsStrFactoryClass.Create(); ITsString paraStr = strFact.MakeString(String.Empty, CurrentWs); m_sda.SetString(kDummyParaHvo, (int)StTxtPara.StTxtParaTags.kflidContents, paraStr); memHvos.Add(kDummyParaHvo); } ((IVwCacheDa)m_sda).CacheVecProp(kMemTextHvo, (int)StText.StTextTags.kflidParagraphs, memHvos.ToArray(), memHvos.Count); }
/// <summary> /// Change a stringvalued property of an object. /// The caller should also call PropChanged to notify interested parties, /// except where the change is being made to a newly created object. ///</summary> /// <param name='hvo'> </param> /// <param name='tag'> </param> /// <param name='_tss'> </param> public virtual void SetString(int hvo, int tag, ITsString _tss) { m_baseSda.SetString(hvo, tag, _tss); }
int MakeRealObject(ITsString tssTyped) { // Figure whether owning atomic or owning collection or owning sequence. Throw if none. IFwMetaDataCache mdc = m_fdoCache.MetaDataCacheAccessor; FieldType iType = m_fdoCache.GetFieldType(m_flidEmptyProp); iType &= FieldType.kcptVirtualMask; ISilDataAccess sdaReal = m_fdoCache.MainCacheAccessor; // Make a new object of the specified class in the specified property. int ord = 0; switch (iType) { default: throw new Exception("ghost string property must be owning object property"); case FieldType.kcptOwningAtom: ord = -2; break; case FieldType.kcptOwningCollection: ord = -1; break; case FieldType.kcptOwningSequence: // ord = 0 set above (inserting the first and only object at position 0). break; } string sClassRaw = mdc.GetClassName((uint)m_clidDst); string sClass = m_mediator.StringTbl.GetString(sClassRaw, "ClassNames"); string sUndo = String.Format(DetailControlsStrings.ksUndoCreate0, sClass); string sRedo = String.Format(DetailControlsStrings.ksRedoCreate0, sClass); sdaReal.BeginUndoTask(sUndo, sRedo); int hvoNewObj = sdaReal.MakeNewObject((int)m_clidDst, m_hvoObj, m_flidEmptyProp, ord); // Set its property m_flidStringProp to tssTyped. If it is multilingual, choose based on ghostWs. FieldType iTypeString = m_fdoCache.GetFieldType(m_flidStringProp); iTypeString &= FieldType.kcptVirtualMask; switch (iTypeString) { default: throw new Exception("ghost property must store strings!"); case FieldType.kcptMultiString: case FieldType.kcptMultiBigString: case FieldType.kcptMultiUnicode: case FieldType.kcptMultiBigUnicode: sdaReal.SetMultiStringAlt(hvoNewObj, m_flidStringProp, m_wsToCreate, tssTyped); break; case FieldType.kcptString: case FieldType.kcptBigString: sdaReal.SetString(hvoNewObj, m_flidStringProp, tssTyped); break; } string ghostInitMethod = XmlUtils.GetOptionalAttributeValue(m_nodeObjProp, "ghostInitMethod"); if (ghostInitMethod != null) { ICmObject obj = CmObject.CreateFromDBObject(m_fdoCache, hvoNewObj); Type objType = obj.GetType(); System.Reflection.MethodInfo mi = objType.GetMethod(ghostInitMethod); mi.Invoke(obj, null); } // Issue PropChanged for the addition of the new object. (could destroy this). sdaReal.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoObj, m_flidEmptyProp, 0, 1, 0); sdaReal.EndUndoTask(); return(hvoNewObj); }