本文整理汇总了C#中IVwSelection.CLevels方法的典型用法代码示例。如果您正苦于以下问题:C# IVwSelection.CLevels方法的具体用法?C# IVwSelection.CLevels怎么用?C# IVwSelection.CLevels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IVwSelection
的用法示例。
在下文中一共展示了IVwSelection.CLevels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeCombo
// Call this to create the appropriate subclass and set up the combo and return it.
// May return null if no appropriate combo can be created at the current position.
// Caller should hide all combos before calling, then
// call Activate to add the combo to its controls (thus making it visible)
// or display the ComboListBox if a non-null value
// is returned.
static internal IComboHandler MakeCombo(IHelpTopicProvider helpTopicProvider,
IVwSelection vwselNew, SandboxBase sandbox, bool fMouseDown)
{
// Figure what property is selected and create a suitable class if appropriate.
int cvsli = vwselNew.CLevels(false);
// CLevels includes the string property itself, but AllTextSelInfo doesn't need
// it.
cvsli--;
// Out variables for AllTextSelInfo.
int ihvoRoot;
int tagTextProp;
int cpropPrevious;
int ichAnchor;
int ichEnd;
int ws;
bool fAssocPrev;
int ihvoEnd;
ITsTextProps ttpBogus;
// Main array of information retrived from sel that made combo.
SelLevInfo[] rgvsli;
// Analysis can now be zero (e.g., displaying alterate case form for non-existent WfiWordform)
// and I don't believe it's a problem for the code below (JohnT).
// if (sandbox.Analysis == 0)
// {
// // We aren't fully initialized yet, so don't do anything.
// return null;
// }
if (cvsli < 0)
return null;
try
{
rgvsli = SelLevInfo.AllTextSelInfo(vwselNew, cvsli,
out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);
}
catch
{
// If anything goes wrong just give up.
return null;
}
int hvoMorph = 0;
int hvoSelObject = 0;
if (tagTextProp >= ktagMinIcon && tagTextProp < ktagLimIcon) // its an icon
{
// If we're just hovering don't launch the pull-down.
if (!fMouseDown)
return null;
if (rgvsli.Length >= 1)
hvoMorph = hvoSelObject = rgvsli[0].hvo;
return MakeCombo(helpTopicProvider, tagTextProp, sandbox, hvoMorph, rgvsli, hvoSelObject);
}
return null;
}
示例2: GetAnalysisFromSelection
protected AnalysisOccurrence GetAnalysisFromSelection(IVwSelection sel)
{
AnalysisOccurrence result = null;
var cvsli = sel.CLevels(false);
cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it.
// Out variables for AllTextSelInfo.
int ihvoRoot;
int tagTextProp;
int cpropPrevious;
int ichAnchor;
int ichEnd;
int ws;
bool fAssocPrev;
int ihvoEnd;
ITsTextProps ttpBogus;
// Main array of information retrieved from sel.
var rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli,
out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);
if (rgvsli.Length > 1)
{
// Need to loop backwards until we get down to index 1 or index produces a valid Segment.
var i = rgvsli.Length - 1;
ISegment seg = null;
for (; i > 0; i--)
{
// get the container for whatever is selected at this level.
ICmObject container;
if (!m_objRepo.TryGetObject(rgvsli[i].hvo, out container))
return null; // may fail, e.g., trying to get bookmark for text just deleted.
seg = container as ISegment;
if (seg != null)
break;
}
if (seg != null && i > 0) // This checks the case where there is no Segment in the selection at all
{
// Make a new AnalysisOccurrence
var selObject = m_objRepo.GetObject(rgvsli[i-1].hvo);
if (selObject is IAnalysis)
{
var indexInContainer = rgvsli[i-1].ihvo;
result = new AnalysisOccurrence(seg, indexInContainer);
}
if (result == null || !result.IsValid)
result = new AnalysisOccurrence(seg, 0);
}
else
{
// TODO: other possibilities?!
Debug.Assert(false, "Reached 'other' situation in OccurrenceContainingSelection().");
}
}
return result;
}
示例3: HandleSelectionChange
/// ------------------------------------------------------------------------------------
/// <summary>
/// We override this method to make a selection in all of the views that are in a
/// synced group. This fixes problems where the user changes the selection in one of
/// the slaves, but the master is not updated. Thus the view is not scrolled as the
/// groups scroll position only scrolls the master's selection into view. (TE-3380)
/// </summary>
/// <param name="rootb">The rootbox whose selection changed</param>
/// <param name="vwselNew">The new selection</param>
/// ------------------------------------------------------------------------------------
protected override void HandleSelectionChange(IVwRootBox rootb, IVwSelection vwselNew)
{
CheckDisposed();
// Guard against recursive calls, typically caused by the MakeTextSelection call below.
if (m_fInSelectionChanged)
return;
try
{
m_fInSelectionChanged = true;
// Make sure we're not handling MouseDown since it
// handles SelectionChanged and DoSelectionSideEffects.
// No need to do it again.
if (!ReadOnlySelect && !m_fHandlingMouseUp)
{
if (vwselNew == null)
return;
// The selection can apparently be invalid on rare occasions, and will lead
// to a crash below trying to call CLevels. See LT-10301. Treat it the
// same as a null selection.
if (!vwselNew.IsValid)
return;
base.HandleSelectionChange(rootb, vwselNew);
m_wantScrollIntoView = false; // It should already be visible here.
// Collect all the information we can about the selection.
int ihvoRoot = 0;
int tagTextProp = 0;
int cpropPrevious = 0;
int ichAnchor = 0;
int ichEnd = 0;
int ws = 0;
bool fAssocPrev = false;
int ihvoEnd = 0;
ITsTextProps ttpBogus = null;
SelLevInfo[] rgvsli = new SelLevInfo[0];
int cvsli = vwselNew.CLevels(false) - 1;
if (cvsli < 0)
return;// Nothing useful we can do.
// Main array of information retrived from sel that made combo.
rgvsli = SelLevInfo.AllTextSelInfo(vwselNew, cvsli,
out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);
//for (int i = 0; i < cvsli; ++i)
//{
// Debug.Write(String.Format("XmlBrowseView.SelectionChanged(): rgvsli[{0}].hvo={1}, ivho={2}, tag={3}, cpropPrevious={4}, ich={5}, ws={6}",
// i, rgvsli[i].hvo, rgvsli[i].ihvo, rgvsli[i].tag, rgvsli[i].cpropPrevious, rgvsli[i].ich, rgvsli[i].ws));
// Debug.WriteLine(String.Format("; ihvoRoot={0}, ihvoEnd={1}, ichEnd={2}",
// ihvoRoot, ihvoEnd, ichEnd));
//}
// The call to the base implementation can invalidate the selection. It's rare, but quite
// possible. (See the comment in EditingHelper.SelectionChanged() following
// Commit().) This test fixes LT-4731.
if (vwselNew.IsValid)
{
DoSelectionSideEffects(vwselNew);
}
else
{
// But if the selection is invalid, and we do nothing about it, then we can
// type only one character at a time in a browse cell because we no longer
// have a valid selection. See LT-6443.
rootb.MakeTextSelection(ihvoRoot, cvsli, rgvsli, tagTextProp, cpropPrevious,
ichAnchor, ichEnd, ws, fAssocPrev, ihvoEnd, ttpBogus, true);
DoSelectionSideEffects(rootb.Selection);
}
m_wantScrollIntoView = true;
}
}
finally
{
m_fInSelectionChanged = false;
}
}
示例4: GetRowIndexFromSelection
/// <summary>
/// Given a selection in the view, return the row index. Rarely may return -1 if unable to
/// identify a row.
/// </summary>
/// <param name="sel"></param>
/// <param name="fEndPoint">true to get index based on end of selection, false based on anchor.
/// deafault is true, so in a long drag we get the mouse-up row.</param>
/// <returns></returns>
internal int GetRowIndexFromSelection(IVwSelection sel, bool fEndPoint)
{
if (sel == null)
return -1;
try
{
int clev = sel.CLevels(fEndPoint);
int hvoRoot, tag, ihvo, cpropPrevious;
IVwPropertyStore vps;
sel.PropInfo(fEndPoint, clev - 1, out hvoRoot, out tag, out ihvo, out cpropPrevious, out vps);
if (tag != m_fakeFlid) // not sure how this could happen, but the precaution was in an earlier version.
return -1;
return ihvo;
}
catch (System.Runtime.InteropServices.COMException)
{
// This shouldn't happen, but don't let it be catastrophic if it does.
}
return -1;
}
示例5: UpdateProp
/// -----------------------------------------------------------------------------------
/// <summary>
/// Replace the user prompt with the text the user typed. This method is called from
/// the views code when the user prompt is edited.
/// </summary>
/// <param name="vwsel">Current selection in rootbox where this prop was updated</param>
/// <param name="hvo">Hvo of the paragraph/string/segment whose contents are being
/// changed</param>
/// <param name="tag">Tag (must be SimpleRootSite.kTagUserPrompt)</param>
/// <param name="frag">Owning flid of the text/object that owns the paragraph/string/
/// segment whose user prompt is being replaced with typed text</param>
/// <param name="tssVal">Text the user just typed</param>
/// <returns>possibly modified ITsString.</returns>
/// <remarks>The return value is currently ignored in production code, but we use it
/// in our tests.</remarks>
/// -----------------------------------------------------------------------------------
public override ITsString UpdateProp(IVwSelection vwsel, int hvo, int tag, int frag,
ITsString tssVal)
{
Debug.Assert(tag == SimpleRootSite.kTagUserPrompt, "Got an unexpected tag");
Debug.Assert(vwsel != null, "Got a null selection!");
Debug.Assert(vwsel.IsValid, "Got an invalid selection!");
IVwRootBox rootbox = vwsel.RootBox;
// If a (typically Chinese) character composition is in progress, replacing the prompt will
// destroy the selection and end the composition, causing weird typing problems (TE-8267).
// Ending the composition does another Commit, which ensures that this will eventually be
// called when there is NOT a composition in progress.
if (rootbox.IsCompositionInProgress)
return tssVal;
// Remove the UserPrompt pseudo-property from the text the user typed.
// when appropriate also ensure the correct writing system.
// The correct WS is m_wsDefault in the view constructor
ITsStrBldr bldr = tssVal.GetBldr();
if (frag != SegmentTags.kflidFreeTranslation)
{
bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptWs,
(int)FwTextPropVar.ktpvDefault, m_wsDefault);
}
// Delete the user prompt property from the string (TE-3994)
bldr.SetIntPropValues(0, bldr.Length, SimpleRootSite.ktptUserPrompt, -1, -1);
tssVal = bldr.GetString();
// Get information about current selection
int cvsli = vwsel.CLevels(false);
cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it.
int ihvoRoot;
int tagTextProp_Ignore;
int cpropPrevious;
int ichAnchor;
int ichEnd;
int ihvoEnd;
// Prior to the Commit in selection changed which causes this UpdateProp to be called,
// earlier selection changed code has expanded the selection (because it is in a user prompt)
// to the whole prompt. It is therefore a range selection, and the value of fAssocPrev we got
// is useless.
bool fAssocPrev_Ignore;
int ws;
ITsTextProps ttp;
SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(vwsel, cvsli,
out ihvoRoot, out tagTextProp_Ignore, out cpropPrevious, out ichAnchor, out ichEnd,
out ws, out fAssocPrev_Ignore, out ihvoEnd, out ttp);
int tagTextProp;
ITsTextProps props = null;
if (frag == SegmentTags.kflidFreeTranslation)
{
// If the length is zero...we need to suppress replacing the comment with a prompt.
if (tssVal.Length == 0)
m_hvoOfSegmentWhoseBtPromptIsToBeSupressed = hvo;
ISegment seg = Cache.ServiceLocator.GetInstance<ISegmentRepository>().GetObject(hvo);
if (seg.FreeTranslation.get_String(BackTranslationWS).Length == 0)
{
// Undo needs to unset suppressing the comment prompt.
Cache.ActionHandlerAccessor.AddAction(new UndoSuppressBtPrompt(this, seg));
}
ws = BackTranslationWS;
tagTextProp = frag;
seg.FreeTranslation.set_String(ws, tssVal);
rootbox.PropChanged(seg.Paragraph.Owner.Hvo, StTextTags.kflidParagraphs,
seg.Paragraph.IndexInOwner, 1, 1);
}
else
{
ReplacePromptUndoAction undoAction = new ReplacePromptUndoAction(hvo, rootbox, m_updatedPrompts);
if (m_cache.ActionHandlerAccessor != null)
{
m_cache.ActionHandlerAccessor.AddAction( new UndoSelectionAction(rootbox.Site, true, vwsel));
m_cache.ActionHandlerAccessor.AddAction(undoAction);
}
// Mark the user prompt as having been updated - will not show prompt again.
// Note: ReplacePromptUndoAction:Undo removes items from the Set.
m_updatedPrompts.Add(hvo);
// Replace the ITsString in the paragraph or translation
//.........这里部分代码省略.........
示例6: HandleSelectionChange
/// ------------------------------------------------------------------------------------
/// <summary>
/// Selections the changed.
/// </summary>
/// <param name="prootb">The prootb.</param>
/// <param name="sel">The sel.</param>
/// ------------------------------------------------------------------------------------
protected override void HandleSelectionChange(IVwRootBox prootb, IVwSelection sel)
{
CheckDisposed();
if (m_fInChangeSelectedObjects)
return;
m_fInChangeSelectedObjects = true;
try
{
int cvsli = 0;
// Out variables for AllTextSelInfo.
int ihvoRoot = 0;
int tagTextProp = 0;
int cpropPrevious = 0;
int ichAnchor = 0;
int ichEnd = 0;
int ws = 0;
bool fAssocPrev = false;
int ihvoEnd = 0;
ITsTextProps ttpBogus = null;
SelLevInfo[] rgvsli = new SelLevInfo[0];
List<int> newSelectedObjects = new List<int>(4);
newSelectedObjects.Add(XmlVc.FocusHvo);
if (sel != null)
{
cvsli = sel.CLevels(false) - 1;
// Main array of information retrived from sel that made combo.
rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli,
out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);
for (int i = 0; i < cvsli; i++)
{
newSelectedObjects.Add(rgvsli[i].hvo);
}
}
var changed = new HashSet<int>(m_xmlVc.SelectedObjects);
changed.SymmetricExceptWith(newSelectedObjects);
if (changed.Count != 0)
{
m_xmlVc.SelectedObjects = newSelectedObjects;
// Generate propChanged calls that force the relevant parts of the view to redraw
// to indicate which command icons should be visible.
foreach (int hvo in changed)
m_rootb.PropChanged(hvo, XmlVc.IsObjectSelectedTag, 0, 1, 1);
if (sel != null && !sel.IsValid)
{
// we wiped it out by regenerating parts of the display in our PropChanged calls! Restore it if we can.
sel = m_rootb.MakeTextSelection(ihvoRoot, cvsli, rgvsli, tagTextProp,
cpropPrevious, ichAnchor, ichEnd, ws, fAssocPrev, ihvoEnd, ttpBogus, true);
}
}
}
finally
{
m_fInChangeSelectedObjects = false;
}
base.HandleSelectionChange(prootb, sel);
}
示例7: GetOneEndPointOfSelection
/// <summary>
/// Get the array of SelLevInfo corresponding to one end point of a selection.
/// </summary>
/// <param name="vwselNew"></param>
/// <param name="fEndPoint">True if we want the end of the selection. False if we want the anchor.</param>
/// <returns></returns>
protected static SelLevInfo[] GetOneEndPointOfSelection(IVwSelection vwselNew, bool fEndPoint)
{
// Get the info about the other end of the selection.
int ihvoRoot, tagTextProp, cpropPrevious, ich, ws;
bool fAssocPrev;
ITsTextProps ttpSelProps;
int cvsli = vwselNew.CLevels(fEndPoint) - 1;
SelLevInfo[] rgvsliEnd;
using (ArrayPtr prgvsli = MarshalEx.ArrayToNative(cvsli, typeof(SelLevInfo)))
{
vwselNew.AllSelEndInfo(fEndPoint, out ihvoRoot, cvsli, prgvsli,
out tagTextProp, out cpropPrevious, out ich,
out ws, out fAssocPrev, out ttpSelProps);
rgvsliEnd = (SelLevInfo[])MarshalEx.NativeToArray(prgvsli, cvsli,
typeof(SelLevInfo));
}
return rgvsliEnd;
}
示例8: SelectionChanged
/// -----------------------------------------------------------------------------------
/// <summary>
/// Notifies the site that something about the selection has changed.
/// </summary>
/// <param name="prootb"></param>
/// <param name="vwselNew">Selection</param>
/// <remarks>When overriding you should call the base class first.</remarks>
/// -----------------------------------------------------------------------------------
public override void SelectionChanged(IVwRootBox prootb, IVwSelection vwselNew)
{
CheckDisposed();
base.SelectionChanged(prootb, vwselNew);
if (vwselNew == null)
return;
int clev = vwselNew.CLevels(false); // anchor
int hvoRoot, tag, ihvo, cpropPrevious;
IVwPropertyStore vps;
vwselNew.PropInfo(false, clev - 1, out hvoRoot, out tag, out ihvo,
out cpropPrevious, out vps);
Debug.Assert(hvoRoot == m_hvoRoot);
int hvoObjNewSel = m_fdoCache.MainCacheAccessor.get_VecItem(hvoRoot, tag, ihvo);
if (hvoObjNewSel != 0)
{
// Notify any delegates that the selection of the main object in the vector
// may have changed.
if (SelectionChangedEvent != null)
SelectionChangedEvent(this, new FwObjectSelectionEventArgs(hvoObjNewSel, ihvo));
}
}
示例9: SelectionChanged
public override void SelectionChanged(IVwRootBox rootb, IVwSelection vwselNew)
{
CheckDisposed();
if (m_handlingSelectionChanged)
return;
m_handlingSelectionChanged = true;
try
{
m_selectedSenseHvo = 0;
if (vwselNew == null)
return;
base.SelectionChanged(rootb, vwselNew);
// Get the Id of the selected snes, and store it.
int cvsli = vwselNew.CLevels(false);
// CLevels includes the string property itself, but AllTextSelInfo doesn't need it.
cvsli--;
if (cvsli == 0)
{
// No objects in selection: don't allow a selection.
m_rootb.DestroySelection();
// Enhance: invoke launcher's selection dialog.
return;
}
ITsString tss;
int ichAnchor;
int ichEnd;
bool fAssocPrev;
int hvoObj;
int hvoObjEnd;
int tag;
int ws;
vwselNew.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj,
out tag, out ws);
vwselNew.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd,
out tag, out ws);
if (hvoObj != hvoObjEnd)
return;
m_selectedSenseHvo = hvoObj;
}
finally
{
m_handlingSelectionChanged = false;
}
}
示例10: CheckForFreeOrLitAnnotations
/// <summary>
/// Check whether Free Translation and/or Literal Translation annotations already exist
/// for the segment containing the given selection.
/// </summary>
/// <param name="vwsel"></param>
private void CheckForFreeOrLitAnnotations(IVwSelection sel)
{
m_fCanAddFreeTrans = false;
m_fCanAddLitTrans = false;
m_fCanAddNote = false;
if (sel == null || !m_fForEditing)
return;
int cvsli = sel.CLevels(false);
// CLevels includes the string property itself, but AllTextSelInfo doesn't need
// it.
cvsli--;
// Out variables for AllTextSelInfo.
int ihvoRoot;
int tagTextProp;
int cpropPrevious;
int ichAnchor;
int ichEnd;
int ws;
bool fAssocPrev;
int ihvoEnd;
ITsTextProps ttpBogus;
// Main array of information retrived from sel that made combo.
SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli,
out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);
// Identify the segment.
// This is important because although we are currently displaying just an
// StTxtPara, eventually it might be part of a higher level structure. We want
// this to work no matter how much higher level structure there is.
int itagSegments = -1;
for (int i = rgvsli.Length; --i >= 0; )
{
if (rgvsli[i].tag == m_vc.ktagParaSegments)
{
itagSegments = i;
break;
}
}
if (itagSegments == -1)
return;
// All the above, just to get hvoSeg!
int hvoSeg = rgvsli[itagSegments].hvo;
ISilDataAccess sda = Cache.MainCacheAccessor;
int cFreeForm = sda.get_VecSize(hvoSeg, m_vc.ktagSegFF);
m_fCanAddFreeTrans = true;
m_fCanAddLitTrans = true;
m_fCanAddNote = true;
for (int i = 0; i < cFreeForm; i++)
{
int hvoAnn = sda.get_VecItem(hvoSeg, m_vc.ktagSegFF, i);
int hvo = sda.get_ObjectProp(hvoAnn,
(int)CmAnnotation.CmAnnotationTags.kflidAnnotationType);
// Only one Free Translation annotation and one Literal Translation annotation
// is allowed for each segment!
if (hvo == m_vc.FtSegmentDefn)
m_fCanAddFreeTrans = false;
if (hvo == m_vc.LtSegmentDefn)
m_fCanAddLitTrans = false;
}
}
示例11: GetInfoForJumpToTool
/// <summary>
/// Given a selection (typically from a click), determine the object that should be the target for jumping to,
/// and return the property that was clicked (which in the case of a right-click may generate a spelling menu instead).
/// </summary>
/// <param name="sel"></param>
/// <param name="hvoReal"></param>
/// <returns></returns>
private int GetInfoForJumpToTool(IVwSelection sel, out int hvoReal)
{
int ws;
int tagRightClickTextProp;
bool fAssocPrev;
ITsString tss;
int ichAnchorDum;
int hvoRightClickObject = 0;
sel.TextSelInfo(false, out tss, out ichAnchorDum, out fAssocPrev,
out hvoRightClickObject, out tagRightClickTextProp, out ws);
switch (tagRightClickTextProp)
{
case ktagSbMorphPrefix:
case ktagSbMorphPostfix:
m_hvoRightClickMorph = hvoRightClickObject;
// Pretend we clicked on the morph form. (See LT-7590.)
hvoRightClickObject = Caches.DataAccess.get_ObjectProp(hvoRightClickObject, ktagSbMorphForm);
break;
case ktagSbNamedObjName:
if (sel.CLevels(false) < 2)
break;
int hvoOuterObj, tagOuter, ihvoOuter, cpropPreviousOuter;
IVwPropertyStore vpsDummy;
sel.PropInfo(false, 1, out hvoOuterObj, out tagOuter, out ihvoOuter, out cpropPreviousOuter, out vpsDummy);
if (tagOuter == ktagSbMorphGloss || tagOuter == ktagSbMorphPos || tagOuter == ktagSbMorphForm
|| tagOuter == ktagSbMorphEntry)
{
m_hvoRightClickMorph = hvoOuterObj;
}
break;
default:
m_hvoRightClickMorph = 0;
break;
}
hvoReal = m_caches.RealHvo(hvoRightClickObject);
return tagRightClickTextProp;
}
示例12: SelectionChanged
/// ------------------------------------------------------------------------------------
/// <summary>
/// Selections the changed.
/// </summary>
/// <param name="prootb">The prootb.</param>
/// <param name="sel">The sel.</param>
/// ------------------------------------------------------------------------------------
public override void SelectionChanged(IVwRootBox prootb, IVwSelection sel)
{
CheckDisposed();
if (m_fInChangeSelectedObjects)
return;
m_fInChangeSelectedObjects = true;
try
{
int cvsli = 0;
// Out variables for AllTextSelInfo.
int ihvoRoot = 0;
int tagTextProp = 0;
int cpropPrevious = 0;
int ichAnchor = 0;
int ichEnd = 0;
int ws = 0;
bool fAssocPrev = false;
int ihvoEnd = 0;
ITsTextProps ttpBogus = null;
SelLevInfo[] rgvsli = new SelLevInfo[0];
List<int> newSelectedObjects = new List<int>(4);
newSelectedObjects.Add(XmlVc.FocusHvo);
if (sel != null)
{
cvsli = sel.CLevels(false) - 1;
// Main array of information retrived from sel that made combo.
rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli,
out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);
for (int i = 0; i < cvsli; i++)
{
newSelectedObjects.Add(rgvsli[i].hvo);
}
}
ISilDataAccess sda = Cache.MainCacheAccessor;
IVwCacheDa cda = Cache.VwCacheDaAccessor;
foreach (int hvo in m_selectedObjects)
{
if (!newSelectedObjects.Contains(hvo))
{
cda.CacheIntProp(hvo, m_xmlVc.IsObjectSelectedTag, 0);
sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvo, m_xmlVc.IsObjectSelectedTag, 0, 1, 1);
}
}
foreach (int hvo in newSelectedObjects)
{
if (!m_selectedObjects.Contains(hvo))
{
cda.CacheIntProp(hvo, m_xmlVc.IsObjectSelectedTag, 1);
sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvo, m_xmlVc.IsObjectSelectedTag, 0, 1, 1);
}
}
m_selectedObjects = newSelectedObjects;
if (sel != null && !sel.IsValid)
{
// we wiped it out by regenerating parts of the display in our PropChanged calls! Restore it if we can.
sel = m_rootb.MakeTextSelection(ihvoRoot, cvsli, rgvsli, tagTextProp,
cpropPrevious, ichAnchor, ichEnd, ws, fAssocPrev, ihvoEnd, ttpBogus, true);
}
}
finally
{
m_fInChangeSelectedObjects = false;
}
base.SelectionChanged(prootb, sel);
}
示例13: HandleSelectionChange
/// -----------------------------------------------------------------------------------
/// <summary>
/// Notifies the site that something about the selection has changed.
/// </summary>
/// <param name="prootb"></param>
/// <param name="vwselNew">Selection</param>
/// <remarks>When overriding you should call the base class first.</remarks>
/// -----------------------------------------------------------------------------------
protected override void HandleSelectionChange(IVwRootBox prootb, IVwSelection vwselNew)
{
CheckDisposed();
base.HandleSelectionChange(prootb, vwselNew);
if (vwselNew == null)
return;
int clev = vwselNew.CLevels(false); // anchor
int clevEnd = vwselNew.CLevels(true);
if (clev < 2 || clevEnd < 2)
return; // paranoia
int hvoRoot, tag, ihvo, ihvoEnd, cpropPrevious;
IVwPropertyStore vps;
vwselNew.PropInfo(true, clevEnd - 1, out hvoRoot, out tag, out ihvoEnd,
out cpropPrevious, out vps);
vwselNew.PropInfo(false, clev - 1, out hvoRoot, out tag, out ihvo,
out cpropPrevious, out vps);
// Give up if the selection doesn't indicate any top-level object; I think this can happen with pictures.
// selection larger than a top-level object, maybe select all, side effects are confusing.
if (ihvo != ihvoEnd || ihvo < 0)
return;
if (hvoRoot == 0)
return;
Debug.Assert(hvoRoot == m_hvoRoot);
int hvoObjNewSel = m_sdaSource.get_VecItem(hvoRoot, tag, ihvo);
if (hvoObjNewSel != 0)
{
// Notify any delegates that the selection of the main object in the vector
// may have changed.
if (SelectionChangedEvent != null)
SelectionChangedEvent(this, new FwObjectSelectionEventArgs(hvoObjNewSel, ihvo));
}
}
示例14: UpdateProp
/// ------------------------------------------------------------------------------------
/// <summary>
///
/// </summary>
/// ------------------------------------------------------------------------------------
public override ITsString UpdateProp(IVwSelection vwsel, int hvo, int tag, int frag, ITsString tssVal)
{
Debug.Assert(tag == kTagUserPrompt, "Got an unexpected tag");
// Get information about current selection
int cvsli = vwsel.CLevels(false);
cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it.
int ihvoRoot;
int tagTextProp;
int cpropPrevious;
int ichAnchor;
int ichEnd;
int ihvoEnd;
bool fAssocPrev;
int ws;
ITsTextProps ttp;
SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(vwsel, cvsli,
out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
out ws, out fAssocPrev, out ihvoEnd, out ttp);
// get para info
IStTxtPara para = Cache.ServiceLocator.GetInstance<IStTxtParaRepository>().GetObject(hvo);
// ITsTextProps props = StyleUtils.CharStyleTextProps(null, Cache.DefaultVernWs);
//
// // set string info based on the para info
// ITsStrBldr bldr = (ITsStrBldr)tssVal.GetBldr();
// bldr.SetProperties(0, bldr.Length, props);
// tssVal = bldr.GetString();
// Add the text the user just typed to the paragraph - this destroys the selection
// because we replace the user prompt.
para.Contents = tssVal;
// now restore the selection
m_rootb.MakeTextSelection(ihvoRoot, cvsli, rgvsli,
StTxtParaTags.kflidContents, cpropPrevious, ichAnchor, ichEnd,
Cache.DefaultVernWs, fAssocPrev, ihvoEnd, null, true);
return tssVal;
}
示例15: HandleClickSelection
/// <summary>
/// Handles a view selection produced by a click. Return true to suppress normal
/// mouse down handling, indicating that an interlinear bundle has been clicked and the Sandbox
/// moved.
/// </summary>
/// <param name="vwselNew"></param>
/// <param name="fBundleOnly"></param>
/// <param name="fSaveGuess">if true, saves guesses; if false, skips guesses but still saves edits.</param>
/// <returns></returns>
protected virtual bool HandleClickSelection(IVwSelection vwselNew, bool fBundleOnly, bool fSaveGuess)
{
if (vwselNew == null)
return false; // couldn't select a bundle!
// The basic idea is to find the level at which we are displaying the TagAnalysis property.
int cvsli = vwselNew.CLevels(false);
cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it.
// Out variables for AllTextSelInfo.
int ihvoRoot;
int tagTextProp;
int cpropPrevious;
int ichAnchor;
int ichEnd;
int ws;
bool fAssocPrev;
int ihvoEnd;
ITsTextProps ttpBogus;
// Main array of information retrived from sel that made combo.
SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(vwselNew, cvsli,
out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);
if (tagTextProp == (int)CmAnnotation.CmAnnotationTags.kflidComment)
{
bool fWasFocusBoxInstalled = IsFocusBoxInstalled;
Rect oldSelLoc = GetPrimarySelRect(vwselNew);
if (!fBundleOnly)
DestroyFocusBoxAndSetFocus(fSaveGuess);
// If the selection resulting from the click is still valid, and we just closed the focus box, go ahead and install it;
// continuing to process the click may not produce the intended result, because
// removing the focus box can re-arrange things substantially (LT-9220).
// (However, if we didn't change anything it is necesary to process it normally, otherwise, dragging
// and shift-clicking in the free translation don't work.)
if (!vwselNew.IsValid || !fWasFocusBoxInstalled)
return false;
// We have destroyed a focus box...but we may not have moved the free translation we clicked enough
// to cause problems. If not, we'd rather do a normal click, because installing a selection that
// the root box doesn't think is from mouse down does not allow dragging.
Rect selLoc = GetPrimarySelRect(vwselNew);
if (selLoc.top == oldSelLoc.top)
return false;
vwselNew.Install();
return true;
}
// Identify the twfic, and the position in m_rgvsli of the property holding it.
// It is also possible that the twfic is the root object.
// This is important because although we are currently displaying just an StTxtPara,
// eventually it might be part of a higher level structure. We want to be able to
// reproduce everything that gets us down to the twfic.
int itagAnalysis = -1;
for (int i = rgvsli.Length; --i >= 0; )
{
if (rgvsli[i].tag == TagAnalysis)
{
itagAnalysis = i;
break;
}
}
if (itagAnalysis < 0)
{
// Go ahead and hide the focus box, since it could try to still the selection back (cf. LT-7968)
if (!fBundleOnly)
DestroyFocusBoxAndSetFocus(fSaveGuess);
return false; // Selection is somewhere we can't handle.
}
int hvoAnalysis = rgvsli[itagAnalysis].hvo; // The current analyis object.
Debug.Assert(itagAnalysis < rgvsli.Length - 1); // Need different approach if the twfic is the root.
int hvoAnnotation = rgvsli[itagAnalysis + 1].hvo;
// Launch a combo on the base line.
// if (tagTextProp == (int)WfiWordform.WfiWordformTags.kflidForm)
// {
// // First line: display the in-place combo.
// analysisHandler = new ChooseAnalysisHandler(m_fdoCache, hvoSrc, hvoAnalysis);
// analysisHandler.AnalysisChosen += analysisChosenDelegate;
// analysisHandler.SetupCombo();
// analysisHandler.Show(m_site, m_vwselNew);
// return;
// }
// Enhance JohnT: if click was on word gloss line, put cursor there instead of default.
TriggerAnnotationSelected(hvoAnnotation, hvoAnalysis, fSaveGuess);
// new HandleSelectionChangeMethod(vwselNew, this)
// .Run(ref m_analysisHandler, m_vc.ListManager,
// new EventHandler(m_analysisHandler_AnalysisChosen), new AdvanceWordEventHandler(scope_AdvanceWord));
return true;
}