/// ------------------------------------------------------------------------------------ /// <summary> /// Shows the Format Styles dialog. /// </summary> /// <param name="paraStyleName">Name of the initially selected paragraph style.</param> /// <param name="charStyleName">Name of the initially selected character style.</param> /// <returns> /// true if a refresh is needed to reload the cache /// </returns> /// ------------------------------------------------------------------------------------ public bool ShowStylesDialog(string paraStyleName, string charStyleName) { StVc vc = null; IVwRootSite activeViewSite = null; if (ActiveView != null) { vc = ActiveView.EditingHelper.ViewConstructor as StVc; activeViewSite = ActiveView.CastAsIVwRootSite(); } using (FwStylesDlg stylesDlg = new FwStylesDlg(activeViewSite, Cache, StyleSheet, (vc == null) ? false : vc.RightToLeft, Cache.ProjectIncludesRightToLeftWs, StyleSheet.GetDefaultBasedOnStyleName(), MaxStyleLevelToShow, FwApp.MeasurementSystem, paraStyleName, charStyleName, HvoAppRootObject, FwApp.App, FwApp.App)) { stylesDlg.StylesRenamedOrDeleted += new FwStylesDlg.StylesRenOrDelDelegate(m_callbacks.OnStylesRenamedOrDeleted); stylesDlg.AllowSelectStyleTypes = m_callbacks.ShowSelectStylesComboInStylesDialog; stylesDlg.CanSelectParagraphBackgroundColor = m_callbacks.CanSelectParagraphBackgroundColor; return(stylesDlg.ShowDialog(m_callbacks) == DialogResult.OK && ((stylesDlg.ChangeType & StyleChangeType.DefChanged) > 0 || (stylesDlg.ChangeType & StyleChangeType.Added) > 0)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Verifies the args sent to the RequestSelectionAtEndOfUow method. /// </summary> /// <param name="rootsite">The (mocked) rootsite on which RequestSelectionAtEndOfUow /// should have been called.</param> /// <param name="rootb">The (mocked) rootbox.</param> /// <param name="wsAlt">The ws of the back translation (or 0 if vernacular).</param> /// <param name="cLevels">The expected number of selection levels.</param> /// <param name="tagTextProp">The expected text prop flid.</param> /// <param name="text">The text that was typed or pasted to replace the prompt.</param> /// ------------------------------------------------------------------------------------ private static void VerifyArgsSentToRequestSelectionAtEndOfUow(IVwRootSite rootsite, IVwRootBox rootb, int wsAlt, int cLevels, int tagTextProp, string text) { IList <object[]> argsSentToRequestSelectionAtEndOfUow = rootsite.GetArgumentsForCallsMadeOn(rs => rs.RequestSelectionAtEndOfUow(Arg <IVwRootBox> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything, Arg <SelLevInfo[]> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything, Arg <int> .Is.Anything, Arg <bool> .Is.Anything, Arg <ITsTextProps> .Is.Anything)); Assert.AreEqual(1, argsSentToRequestSelectionAtEndOfUow.Count); Assert.AreEqual(10, argsSentToRequestSelectionAtEndOfUow[0].Length); Assert.AreEqual(rootb, argsSentToRequestSelectionAtEndOfUow[0][0]); Assert.AreEqual(0, argsSentToRequestSelectionAtEndOfUow[0][1]); Assert.AreEqual(cLevels, argsSentToRequestSelectionAtEndOfUow[0][2]); SelLevInfo[] levInfo = (SelLevInfo[])argsSentToRequestSelectionAtEndOfUow[0][3]; Assert.AreEqual(cLevels, levInfo.Length); Assert.AreEqual(tagTextProp, argsSentToRequestSelectionAtEndOfUow[0][4]); Assert.AreEqual(0, argsSentToRequestSelectionAtEndOfUow[0][5]); Assert.AreEqual(text.Length, argsSentToRequestSelectionAtEndOfUow[0][6]); Assert.AreEqual(wsAlt, argsSentToRequestSelectionAtEndOfUow[0][7]); Assert.AreEqual(true, argsSentToRequestSelectionAtEndOfUow[0][8]); ITsTextProps props = (ITsTextProps)argsSentToRequestSelectionAtEndOfUow[0][9]; Assert.AreEqual(1, props.IntPropCount); Assert.AreEqual(0, props.StrPropCount); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Selects the paragraph in the DraftView or FootnoteView associated with the style. /// </summary> /// <param name="origSelection">selection user originally made</param> /// <param name="view">The DraftView or FootnoteView</param> /// ------------------------------------------------------------------------------------ private void SelectAssociatedPara(SelectionHelper origSelection, IVwRootSite view) { SelLevInfo paraInfoAnchor = origSelection.GetLevelInfoForTag( StTextTags.kflidParagraphs, SelectionHelper.SelLimitType.Top); SelLevInfo paraInfoEnd = origSelection.GetLevelInfoForTag( StTextTags.kflidParagraphs, SelectionHelper.SelLimitType.Bottom); if (paraInfoAnchor.hvo != m_prevPara1Hvo || paraInfoEnd.hvo != m_prevPara2Hvo) { // The selection changed paragraphs, so update the selection in the // DraftView or FootnoteView IStTxtPara para1 = m_fdoCache.ServiceLocator.GetInstance <IStTxtParaRepository>().GetObject(paraInfoAnchor.hvo); IStTxtPara para2 = m_fdoCache.ServiceLocator.GetInstance <IStTxtParaRepository>().GetObject(paraInfoEnd.hvo); SelectionHelper helper = MakeSelection(para1, para2, view); IVwSelection sel = helper.SetSelection(view, true, false); // If the selection fails then try selecting the user prompt. if (sel == null) { AdjustSelectionForPrompt(helper, para1, para2); sel = helper.SetSelection(view, true, false); } Debug.Assert(sel != null || ((SimpleRootSite)view).ReadOnlyView); m_prevPara1Hvo = paraInfoAnchor.hvo; m_prevPara2Hvo = paraInfoEnd.hvo; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:FwApplyStyleDlg"/> class. /// </summary> /// <param name="rootSite">The root site.</param> /// <param name="cache">The cache.</param> /// <param name="hvoStylesOwner">The hvo of the object which owns the style.</param> /// <param name="stylesTag">The "flid" in which the styles are owned.</param> /// <param name="normalStyleName">Name of the normal style.</param> /// <param name="customUserLevel">The custom user level.</param> /// <param name="paraStyleName">Name of the currently selected paragraph style.</param> /// <param name="charStyleName">Name of the currently selected character style.</param> /// <param name="hvoRootObject">The hvo of the root object in the current view.</param> /// <param name="app">The application.</param> /// <param name="helpTopicProvider">The help topic provider.</param> /// ------------------------------------------------------------------------------------ public FwApplyStyleDlg(IVwRootSite rootSite, FdoCache cache, int hvoStylesOwner, int stylesTag, string normalStyleName, int customUserLevel, string paraStyleName, string charStyleName, int hvoRootObject, IApp app, IHelpTopicProvider helpTopicProvider) { m_rootSite = rootSite; InitializeComponent(); m_customUserLevel = customUserLevel; m_helpTopicProvider = helpTopicProvider; m_paraStyleName = paraStyleName; m_charStyleName = charStyleName; // Cache is null in tests if (cache == null) return; m_cboTypes.SelectedIndex = 1; // All Styles // Load the style information m_styleTable = new StyleInfoTable(normalStyleName, cache.ServiceLocator.WritingSystemManager); m_styleSheet = new FwStyleSheet(); m_styleSheet.Init(cache, hvoStylesOwner, stylesTag); m_styleListHelper = new StyleListBoxHelper(m_lstStyles); m_styleListHelper.ShowInternalStyles = false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:FwApplyStyleDlg"/> class. /// </summary> /// <param name="rootSite">The root site.</param> /// <param name="cache">The cache.</param> /// <param name="hvoStylesOwner">The hvo of the object which owns the style.</param> /// <param name="stylesTag">The "flid" in which the styles are owned.</param> /// <param name="normalStyleName">Name of the normal style.</param> /// <param name="customUserLevel">The custom user level.</param> /// <param name="paraStyleName">Name of the currently selected paragraph style.</param> /// <param name="charStyleName">Name of the currently selected character style.</param> /// <param name="hvoRootObject">The hvo of the root object in the current view.</param> /// <param name="app">The application.</param> /// <param name="helpTopicProvider">The help topic provider.</param> /// ------------------------------------------------------------------------------------ public FwApplyStyleDlg(IVwRootSite rootSite, FdoCache cache, int hvoStylesOwner, int stylesTag, string normalStyleName, int customUserLevel, string paraStyleName, string charStyleName, int hvoRootObject, IApp app, IHelpTopicProvider helpTopicProvider) { m_rootSite = rootSite; InitializeComponent(); m_customUserLevel = customUserLevel; m_helpTopicProvider = helpTopicProvider; m_paraStyleName = paraStyleName; m_charStyleName = charStyleName; // Cache is null in tests if (cache == null) { return; } m_cboTypes.SelectedIndex = 1; // All Styles // Load the style information m_styleTable = new StyleInfoTable(normalStyleName, cache.ServiceLocator.WritingSystemManager); m_styleSheet = new FwStyleSheet(); m_styleSheet.Init(cache, hvoStylesOwner, stylesTag); m_styleListHelper = new StyleListBoxHelper(m_lstStyles); m_styleListHelper.ShowInternalStyles = false; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Ensures the annotation is mostly visible by making an uninstalled selection /// toward the end of the modified date. /// </summary> /// ------------------------------------------------------------------------------------ internal void EnsureNoteIsVisible(TeNotesVc vc, int bookIndex, int iAnnotation, IVwRootSite notesDataEntryView) { SelectionHelper selHelper = new SelectionHelper(); selHelper.NumberOfLevels = 2; selHelper.LevelInfo[0].cpropPrevious = 0; selHelper.LevelInfo[0].ich = -1; selHelper.LevelInfo[0].ihvo = iAnnotation; selHelper.LevelInfo[0].tag = ScrBookAnnotationsTags.kflidNotes; selHelper.LevelInfo[0].ws = 0; selHelper.LevelInfo[1].cpropPrevious = 0; selHelper.LevelInfo[1].ich = -1; selHelper.LevelInfo[1].ihvo = bookIndex; selHelper.LevelInfo[1].tag = ScriptureTags.kflidBookAnnotations; selHelper.LevelInfo[1].ws = 0; selHelper.AssocPrev = false; // Put the selection at the end of the shortest possible date value. It doesn't // have to be right at the end, but the closer it is, the more reliable it will // be that it is fully scrolled into view. selHelper.IchAnchor = 8; selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, CmAnnotationTags.kflidDateModified); selHelper.SetSelection(notesDataEntryView, false, true, VwScrollSelOpts.kssoDefault); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Start the undo task /// </summary> /// <param name="rootSite">The view (required)</param> /// <param name="stid">String resource id used for Undo/Redo labels</param> /// <param name="fCommit"><c>true</c> to call commit (and thus end all outstanding /// transactions). If an <see cref="UndoTaskHelper"/> object is created as part of an /// inner task, you probably want to set this to <c>false</c>. Default is <c>true</c>. /// </param> /// ------------------------------------------------------------------------------------ public UndoTaskHelper(IVwRootSite rootSite, string stid, bool fCommit) { Debug.Assert(rootSite != null); string stUndo, stRedo; ResourceHelper.MakeUndoRedoLabels(stid, out stUndo, out stRedo); Init(rootSite.RootBox.DataAccess, rootSite, stUndo, stRedo, fCommit); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Start the undo task /// </summary> /// <param name="dataAccess">The ISilDataAccess to start the undo task on</param> /// <param name="rootSite">The view (can be <c>null</c>)</param> /// <param name="stid">String resource id used for Undo/Redo labels</param> /// <param name="fCommit"><c>true</c> to call commit (and thus end all outstanding /// transactions). If an <see cref="UndoTaskHelper"/> object is created as part of an /// inner task, you probably want to set this to <c>false</c>. Default is <c>true</c>. /// </param> /// ------------------------------------------------------------------------------------ public UndoTaskHelper(ISilDataAccess dataAccess, IVwRootSite rootSite, string stid, bool fCommit) { string stUndo, stRedo; ResourceHelper.MakeUndoRedoLabels(stid, out stUndo, out stRedo); Init(dataAccess, rootSite, stUndo, stRedo, fCommit); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Start the undo task /// </summary> /// <param name="actionHandler">The IActionHandler to start the undo task on</param> /// <param name="rootSite">The view (can be <c>null</c>)</param> /// <param name="stid">String resource id used for Undo/Redo labels</param> /// ------------------------------------------------------------------------------------ public UndoTaskHelper(IActionHandler actionHandler, IVwRootSite rootSite, string stid) : base(actionHandler) { m_vwRootSite = rootSite; string stUndo, stRedo; ResourceHelper.MakeUndoRedoLabels(stid, out stUndo, out stRedo); Init(stUndo, stRedo); }
/// <inheritdoc/> public DummyFwStylesDlg(IVwRootSite rootSite, LcmCache cache, LcmStyleSheet styleSheet, bool defaultRightToLeft, bool showBiDiLabels, string normalStyleName, int customUserLevel, MsrSysType userMeasurementType, string paraStyleName, string charStyleName, int hvoRootObject, IApp app, IHelpTopicProvider helpTopicProvider) : base(rootSite, cache, styleSheet, defaultRightToLeft, showBiDiLabels, normalStyleName, customUserLevel, userMeasurementType, paraStyleName, charStyleName, hvoRootObject, app, helpTopicProvider) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Start the undo task /// </summary> /// <param name="actionHandler">The IActionHandler to start the undo task on</param> /// <param name="rootSite">The view (can be <c>null</c>)</param> /// <param name="stid">String resource id used for Undo/Redo labels</param> /// ------------------------------------------------------------------------------------ public UndoTaskHelper(IActionHandler actionHandler, IVwRootSite rootSite, string stid) : base(actionHandler) { m_vwRootSite = rootSite; string stUndo, stRedo; ResourceHelper.MakeUndoRedoLabels(stid, out stUndo, out stRedo); Init(stUndo, stRedo); }
/// <summary> /// Create one. /// </summary> /// <param name="owner"></param> /// <param name="sda"></param> /// <param name="site"></param> /// <param name="updateDescription"></param> /// <param name="fTurnOnMonitor">if true, start monitoring. if false, suspend/disable monitoring.</param> /// <param name="fSuppressRecordingPriorSelection">True for operations (currently only ReplaceAll) /// where we do not want to record the prior selection. This prevents calling editinghelper.OnAboutToEdit, /// which therefore doesn't save info about the current selection. The current actual effect /// is to suppress the work of the AnnotationAdjuster for the selected paragraphs.</param> public DataUpdateMonitor(Control owner, ISilDataAccess sda, IVwRootSite site, string updateDescription, bool fTurnOnMonitor, bool fSuppressRecordingPriorSelection) { // DataUpdateMonitor may be nested, so make sure we're not already monitoring the site. m_fTurnOnMonitor = fTurnOnMonitor && (site == null || !s_sitesMonitoring.Contains(site)); if (!m_fTurnOnMonitor) { return; } // register this site as being monitored. if (site != null) { s_sitesMonitoring.Add(site); } Debug.Assert(sda != null); if (s_UpdateSemaphores.ContainsKey(sda)) { UpdateSemaphore semaphore = s_UpdateSemaphores[sda]; if (semaphore.fDataUpdateInProgress) { throw new Exception("Concurrent access on Database detected"); } // Set ((static semaphore) members) for this data update semaphore.fDataUpdateInProgress = true; semaphore.sDescr = updateDescription; } else { s_UpdateSemaphores[sda] = new UpdateSemaphore(true, updateDescription); } m_Owner = owner; m_sda = sda; m_rootSite = site; if (m_rootSite != null) { m_editingHelper = ((IRootSite)m_rootSite).EditingHelper; } // store original selection info. // Note, some of its internals are computed from the actual selection // which can get changed during the life of DataUpdateMonitor. // But its properties and Hvo(fEndPoint) should remain the same. if (m_editingHelper != null && !fSuppressRecordingPriorSelection) { m_tsi = new TextSelInfo(m_editingHelper.EditedRootBox); m_editingHelper.OnAboutToEdit(); } // Set wait cursor if (owner != null) { m_oldCursor = owner.Cursor; owner.Cursor = Cursors.WaitCursor; } }
/// <summary> /// Draws the Root into a memory buffer, then rotates it 90deg clockwise while drawing /// the memory buffer to the screen. /// See C++ documentation for more info. /// </summary> public void DrawTheRootRotated(IVwRootBox rootb, IntPtr hdc, Rect rcpDraw, uint bkclr, bool fDrawSel, IVwRootSite vrs, int nHow) { IVwGraphicsWin32 qvg32 = VwGraphicsWin32Class.Create(); Rectangle rcp = new Rectangle(rcpDraw.top, rcpDraw.left, rcpDraw.bottom, rcpDraw.right); Rectangle rcFill = new Rect(0, 0, rcp.Width, rcp.Height); using (Graphics screen = Graphics.FromHdc(hdc)) using (var memoryBuffer = new MemoryBuffer(rcp.Width, rcp.Height)) { memoryBuffer.Graphics.FillRectangle(new SolidBrush(ColorUtil.ConvertBGRtoColor(bkclr)), rcFill); qvg32.Initialize(memoryBuffer.Graphics.GetHdc()); IVwGraphics qvgDummy = null; try { Rect rcDst, rcSrc; vrs.GetGraphics(rootb, out qvgDummy, out rcSrc, out rcDst); Rectangle temp = rcDst; temp.Offset(-rcp.Left, -rcp.Top); rcDst = temp; qvg32.XUnitsPerInch = qvgDummy.XUnitsPerInch; qvg32.YUnitsPerInch = qvgDummy.YUnitsPerInch; rootb.DrawRoot(qvg32, rcSrc, rcDst, fDrawSel); vrs.ReleaseGraphics(rootb, qvgDummy); qvgDummy = null; } catch (Exception) { if (qvgDummy != null) { vrs.ReleaseGraphics(rootb, qvgDummy); } qvg32.ReleaseDC(); throw; } Point[] rgptTransform = new Point[3]; rgptTransform[0] = new Point(rcpDraw.right, rcpDraw.top); // upper left of actual drawing maps to top right of rotated drawing rgptTransform[1] = new Point(rcpDraw.right, rcpDraw.bottom); // upper right of actual drawing maps to bottom right of rotated drawing. rgptTransform[2] = new Point(rcpDraw.left, rcpDraw.top); // bottom left of actual drawing maps to top left of rotated drawing. screen.DrawImage((Image)memoryBuffer.Bitmap, rgptTransform, new Rectangle(0, 0, rcp.Width, rcp.Height), GraphicsUnit.Pixel); qvg32.ReleaseDC(); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Scroll new note into view. /// </summary> /// <param name="sender">The sender.</param> /// <param name="fromUndoRedo">True if the event was fired from an undo (or rollback) or /// redo, false otherwise.</param> /// ------------------------------------------------------------------------------------ private void ScrollAfterPropChangedCompleted(object sender, bool fromUndoRedo) { // In test teardown, cache may already have been cleared if (Cache == null) { return; } ((IActionHandlerExtensions)Cache.ActionHandlerAccessor).PropChangedCompleted -= ScrollAfterPropChangedCompleted; IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[m_bookNewNote - 1]; IScrScriptureNote annotation = annotations.NotesOS[m_indexNewNote]; TeNotesVc notesVc = CurrentNotesVc; if (notesVc != null) { // tell the VC that the newly inserted item should be expanded. That will cause // the view to be updated to show the new note. notesVc.ExpandItem(annotation.Hvo, EditedRootBox); notesVc.ExpandItem(annotation.DiscussionOA.Hvo, EditedRootBox); } if (Control != null) { Control.Focus(); } // Make a selection in the discussion so the user can start to type int iPos = m_indexNewNote; if (notesVc != null) { // Get the corresponding index in the virtual property. iPos = ((FilteredDomainDataByFlidDecorator)EditedRootBox.DataAccess). GetFilteredIndexOfItem(annotations.Hvo, iPos); // New note doesn't match current filter - need to turn it off if (iPos < 0) { // Turn off the filter so the new note will show ((NotesDataEntryView)Control).OnChangeFilter(null); iPos = ((FilteredDomainDataByFlidDecorator)EditedRootBox.DataAccess). GetFilteredIndexOfItem(annotations.Hvo, m_indexNewNote); Debug.Assert(iPos >= 0); } } IVwRootSite rootSite = Control as IVwRootSite; MakeSelectionInNote(notesVc, m_bookNewNote - 1, iPos, rootSite, true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialization /// </summary> /// <param name="dataAccess">The ISilDataAccess to start the undo task on</param> /// <param name="rootSite">The view (can be <c>null</c>)</param> /// <param name="stUndo">Undo label</param> /// <param name="stRedo">Redo label</param> /// <param name="fCommit"><c>true</c> to call commit (and thus end all outstanding /// transactions). If an <see cref="UndoTaskHelper"/> object is created as part of an /// inner task, you probably want to set this to <c>false</c>. Default is <c>true</c>. /// </param> /// ------------------------------------------------------------------------------------ private void Init(ISilDataAccess dataAccess, IVwRootSite rootSite, string stUndo, string stRedo, bool fCommit) { Debug.Assert(dataAccess != null); m_vwRootSite = rootSite; m_fCommit = fCommit; m_dataAccess = dataAccess; if (ActionHandlerAccessor != null) { m_nDepth = ActionHandlerAccessor.CurrentDepth; m_dataAccess.BeginUndoTask(stUndo, stRedo); } // Record an action that will handle replacing the selection on undo. SetupUndoSelection(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// We override this method to select the corresponding paragraph in the draft or /// footnote view. /// </summary> /// <param name="prootb"></param> /// <param name="vwselNew"></param> /// ------------------------------------------------------------------------------------ protected override void HandleSelectionChange(IVwRootBox prootb, IVwSelection vwselNew) { CheckDisposed(); base.HandleSelectionChange(prootb, vwselNew); if (s_fInSelectionChanged) { return; } SelectionHelper origSelection = SelectionHelper.Create(vwselNew, this); if (origSelection != null && Group.Slaves[DraftViewSlaveIndex] is IVwRootSite) { IVwRootSite view = (IVwRootSite)Group.Slaves[DraftViewSlaveIndex]; SelectAssociatedPara(origSelection, view); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Shows the Format Styles dialog. /// </summary> /// <param name="paraStyleName">Name of the initially selected paragraph style.</param> /// <param name="charStyleName">Name of the initially selected character style.</param> /// <param name="setPropsToFactorySettings">Delegate to set style info properties back /// to the default facotry settings</param> /// <returns> /// true if a refresh is needed to reload the cache /// </returns> /// ------------------------------------------------------------------------------------ public bool ShowStylesDialog(string paraStyleName, string charStyleName, Action <StyleInfo> setPropsToFactorySettings) { StVc vc = null; IVwRootSite activeViewSite = null; if (EditingHelper == null) // If the calling location doesn't provide this just bring up the dialog with normal selected { paraStyleName = "Normal"; } if (ActiveView != null) { vc = ActiveView.EditingHelper.ViewConstructor as StVc; activeViewSite = ActiveView.CastAsIVwRootSite(); } if (paraStyleName == null && charStyleName == null && EditingHelper.CurrentSelection != null && EditingHelper.CurrentSelection.Selection != null) { // If the caller didn't know the default style, try to figure it out from // the selection. GetStyleNames(ActiveView as SimpleRootSite, EditingHelper.CurrentSelection.Selection, ref paraStyleName, ref charStyleName); } using (FwStylesDlg stylesDlg = new FwStylesDlg(activeViewSite, Cache, ActiveStyleSheet, (vc == null) ? false : vc.RightToLeft, Cache.ServiceLocator.WritingSystems.AllWritingSystems.Any(ws => ws.RightToLeftScript), ActiveStyleSheet.GetDefaultBasedOnStyleName(), MaxStyleLevelToShow, m_app.MeasurementSystem, paraStyleName, charStyleName, HvoAppRootObject, m_app, m_app)) { stylesDlg.SetPropsToFactorySettings = setPropsToFactorySettings; stylesDlg.StylesRenamedOrDeleted += m_callbacks.OnStylesRenamedOrDeleted; stylesDlg.AllowSelectStyleTypes = true; stylesDlg.ShowTEStyleTypes = m_callbacks.ShowTEStylesComboInStylesDialog; stylesDlg.CanSelectParagraphBackgroundColor = m_callbacks.CanSelectParagraphBackgroundColor; return(stylesDlg.ShowDialog(m_callbacks) == DialogResult.OK && ((stylesDlg.ChangeType & StyleChangeType.DefChanged) > 0 || (stylesDlg.ChangeType & StyleChangeType.Added) > 0)); } }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected virtual void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) { return; } if (disposing) { if (EndUndoTask) { EndTheUndoTask(); } else { Rollback(); } } // Dispose unmanaged resources here, whether disposing is true or false. // If our action handler is a COM object and it we received it through // a COM object we have to release it. If it is a COM object but we // received it from a managed object then the managed object will/should // take care to release it. if (Marshal.IsComObject(m_dataAccess)) { if (m_actionHandler != null && Marshal.IsComObject(m_actionHandler)) { Marshal.ReleaseComObject(m_actionHandler); } } m_actionHandler = null; m_vwRootSite = null; m_dataAccess = null; m_isDisposed = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes a selection from one paragraph to another paragraph. /// NOTE: This selects the entirety of both paragraphs. /// </summary> /// <param name="para1">The first paragraph.</param> /// <param name="para2">The last paragraph (could be same as first).</param> /// <param name="view">DraftView or FootnoteView</param> /// ------------------------------------------------------------------------------------ private SelectionHelper MakeSelection(IStTxtPara para1, IStTxtPara para2, IVwRootSite view) { Debug.Assert(view != null); Debug.Assert(para1.OwningFlid == StTextTags.kflidParagraphs); Debug.Assert(para2.OwningFlid == StTextTags.kflidParagraphs); SelectionHelper helper = new SelectionHelper(); IStText text1 = (IStText)para1.Owner; IStText text2 = (IStText)para2.Owner; // build the anchor part of the selection SetupSelectionFor(helper, text1, para1, SelectionHelper.SelLimitType.Anchor, (FwRootSite)view); // build the end part of the selection SetupSelectionFor(helper, text2, para2, SelectionHelper.SelLimitType.End, (FwRootSite)view); helper.IchAnchor = 0; helper.IchEnd = para2.Contents.Length; return(helper); }
/// -------------------------------------------------------------------------------- /// <summary> /// Makes a selection in the discussion of an annotation after first scrolling the /// annotation to near the top of the view. /// </summary> /// <param name="vc">The notes view constructor</param> /// <param name="bookIndex">Index of the book.</param> /// <param name="iAnnotation">Index of the annotation.</param> /// <param name="rootSite">The root site.</param> /// <param name="fNoteIsExpanded">if <c>true</c> make a selection at the start and end so /// that the whole annotation can be scrolled into view. if set to <c>false</c> only /// make a selection at the start of the annotation.</param> /// -------------------------------------------------------------------------------- internal void MakeSelectionInNote(TeNotesVc vc, int bookIndex, int iAnnotation, IVwRootSite rootSite, bool fNoteIsExpanded) { MakeSelectionInNote(vc, true, bookIndex, iAnnotation, 0, ScrScriptureNote.ScrScriptureNoteTags.kflidDiscussion, rootSite, fNoteIsExpanded); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Executes in two distinct scenarios. /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing">if set to <c>true</c> [disposing].</param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// If subclasses override this method, they should call the base implementation. /// </remarks> /// ------------------------------------------------------------------------------------ protected virtual void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (m_isDisposed) { return; } if (disposing && m_fTurnOnMonitor) { try { // Dispose managed resources here. if (m_sda != null) { UpdateSemaphore semaphore = s_UpdateSemaphores[m_sda]; Debug.Assert(semaphore.fDataUpdateInProgress); // Remember selection so that we can try to reconstruct it after the PropChangeds SelectionHelper selection = SelectionHelper.Create(m_rootSite); TextSelInfo tsiAfterEdit = null; if (selection != null) { tsiAfterEdit = new TextSelInfo(selection.Selection); } bool fAdjustedChangeInfo = false; foreach (VwChangeInfo changeInfo in semaphore.changeInfoQueue) { int ivIns = changeInfo.ivIns; int cvDel = changeInfo.cvDel; int cvIns = changeInfo.cvIns; // Note: m_sda.MetaDataCache increments an internal com object // ref count that may not get cleared until you do // Marshal.FinalReleaseComObject on it. if it doesn't get cleared // it may hang tests. IFwMetaDataCache mdc = m_sda.MetaDataCache; if (!fAdjustedChangeInfo && mdc != null && tsiAfterEdit != null && m_editingHelper != null && m_editingHelper.MonitorTextEdits) { // if the selection-edit resulted in keeping the cursor in the same paragraph // we may need to do some more adjustments because views code // calculates VwChangeInfo based upon a string comparison, which does not // accurately tell us where the string was actually changed if the inserted // characters match those character positions in the original string. // For example changing "this is the old text" by inserting "this is the new text, but " // at the beginning results in the string "this is the old text, but this is the new text" // In that example the views code StringCompare would say ivIns started at "old text" // rather than the beginning of the string, since "this is the " matches the old string. // The first condition prevents our trying to make these adjustments when we have a multi-para // (end-before-anchor) selection. if (m_tsi.Hvo(true) == m_tsi.Hvo(false) && m_tsi.HvoAnchor == tsiAfterEdit.HvoAnchor && m_tsi.HvoAnchor == changeInfo.hvo && m_tsi.TagAnchor == changeInfo.tag) { // Our insertion point can be at the beginning or end of the range. int ichInsertionPointOrig = Math.Min(m_tsi.IchAnchor, m_tsi.IchEnd); // we may need to adjust ivIns, but not for MultiStrings, since // ivIns in that case is a ws, not an offset. int flidtype = mdc.GetFieldType((uint)changeInfo.tag); if (flidtype == (int)CellarModuleDefns.kcptBigString || flidtype == (int)CellarModuleDefns.kcptString) { // if the anchor has moved back after a delete, use it as a starting point if (!m_tsi.IsRange && cvDel > 0 && ivIns < m_tsi.IchAnchor) { if (ivIns + cvDel == m_tsi.IchAnchor) { // user did backspace from insertion point, so effectively // move the IP back the number of characters deleted. ivIns = Math.Max(m_tsi.IchAnchor - cvDel, 0); } // ctrl-del can also cause this, but in that case, characters // after the IP may have been deleted, too. Seems best not to try to adjust. } else { // use the original IP, since changeInfo uses CompareStrings // to calculate it, and that can be wrong when pasted string has // characters that coincidentally match the original string. ivIns = ichInsertionPointOrig; } } // if the initial selection is a range selection in the same paragraph // set the number of deleted characters to be the difference between // the begin and end offsets. if (m_tsi.HvoAnchor == m_tsi.Hvo(true) && m_tsi.IsRange) { cvDel = Math.Abs(m_tsi.IchEnd - m_tsi.IchAnchor); } // Review: do we expect this string to be Normalized already? // Review: should we do nothing if the pasted string contains newline, or set cvIns to the // length of the text after the last newline, or what?? if (InsertedTss != null && InsertedTss.Text != null && InsertedTss.Text.IndexOf(Environment.NewLine) == -1) { cvIns = InsertedTss.Length; } // indicate we've adjusted the changeInfo for the next PropChange. // this should be done only once per edit action. fAdjustedChangeInfo = true; } } m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, changeInfo.hvo, changeInfo.tag, ivIns, cvIns, cvDel); } semaphore.fDataUpdateInProgress = false; semaphore.sDescr = string.Empty; semaphore.changeInfoQueue.Clear(); // It is possible that the PropChanged caused a regenerate of the view. This // turned our selection invalid. Try to recover it. if (selection != null && !selection.IsValid) { selection.SetSelection(false); } // This needs to be called after setting the selection. It can cause // AnnotationAdjuster.EndKeyPressed() to be called which expects a // selection to be set. if (m_editingHelper != null) { m_editingHelper.OnFinishedEdit(); } // It is possible that OnFinishedEdit() caused a regenerate of the view. This // turned our selection invalid. Try to recover it. if (selection != null && !selection.IsValid) { selection.SetSelection(false); } } } finally { // In case anything goes wrong, if we possibly can, do this anyway, other wise the pane // may be more-or-less permanently locked. if (m_rootSite != null) { s_sitesMonitoring.Remove(m_rootSite); } // end Wait Cursor // Since it needs m_Owner, this must be done when 'disposing' is true, // as that is a disposable object, which may be gone in // Finalizer mode. if (m_Owner != null) { m_Owner.Cursor = m_oldCursor; } } } // Dispose unmanaged resources here, whether disposing is true or false. m_sda = null; m_Owner = null; m_rootSite = null; m_oldCursor = null; m_tsi = null; m_tssIns = null; m_isDisposed = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Execute the command...that is, run the change spelling dialog on the specified wordform. /// </summary> /// <param name="site">The rootsite.</param> /// ------------------------------------------------------------------------------------ public void DoIt(IVwRootSite site) { IWfiWordform wf = null; using (new SuppressSubTasks(m_cache)) { wf = WfiWordform.CreateFromDBObject(m_cache, WfiWordform.FindOrCreateWordform(m_cache, m_word, m_ws, true)); } string stUndo, stRedo; TeResourceHelper.MakeUndoRedoLabels("kstidChangeSpellingItem", out stUndo, out stRedo); using (new UndoTaskHelper(site, stUndo, stRedo, false)) { object respellerDlg = ReflectionHelper.CreateObject("MorphologyEditorDll.dll", "SIL.FieldWorks.XWorks.MorphologyEditor.RespellerDlg", new object[0]); try { ReflectionHelper.CallMethod(respellerDlg, "SetDlgInfo", new object[] { wf }); ReflectionHelper.CallMethod(respellerDlg, "ShowDialog", new object[] { Form.ActiveForm }); ReflectionHelper.CallMethod(respellerDlg, "SaveSettings", new object[] { }); } finally { ReflectionHelper.CallMethod(respellerDlg, "Dispose", new object[] { }); } } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Sets the selection by calling <c>IVwRootBox.MakeRangeSelection</c>. /// </summary> /// <param name="rootSite">The root site</param> /// <param name="fInstall">Makes the selection the current selection</param> /// <param name="fMakeVisible">Determines whether or not to make the selection visible. /// </param> /// <param name="scrollOption">Where to scroll the selection</param> /// <returns>The selection, null if it could not return a valid one.</returns> /// ----------------------------------------------------------------------------------- public virtual IVwSelection SetSelection(IVwRootSite rootSite, bool fInstall, bool fMakeVisible, VwScrollSelOpts scrollOption) { if (rootSite == null || rootSite.RootBox == null) return null; m_rootSite = rootSite; try { IVwSelection sel = MakeRangeSelection(rootSite.RootBox, fInstall); if (sel == null) return null; if (fInstall && !sel.IsValid) { // We rarely expect to have an invalid selection after we install a new selection, // but it's possible for selection side-effects to have invalidated it // (e.g. highlighting a row in a browse view cf. LT-5033.) sel = MakeRangeSelection(rootSite, fInstall); } if (sel.IsValid) m_vwSel = sel; else m_vwSel = null; if (fMakeVisible && m_vwSel != null) rootSite.ScrollSelectionIntoView(m_vwSel, scrollOption); return m_vwSel; } catch (COMException) { return null; } catch(Exception) { Debug.Assert(false, "Exceptional condition encountered while making selection."); // ReSharper disable HeuristicUnreachableCode return null; //Um, asserts don't happen in release you overzealous Heuristic. // ReSharper restore HeuristicUnreachableCode } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Reduce a range selection to a simple insertion point, specifying which limit of /// the range selection to use as the position for the new IP. /// </summary> /// <param name="rootSite">The root site</param> /// <param name="limit">Specify Top to place the IP at the top-most limit of the /// selection. Specify Bottom to place the IP at the bottom-most limit of the selection. /// Specify Anchor to place the IP at the point where the user initiated the selection. /// Specify End to place the IP at the point where the user completed the selection. Be /// aware the user may select text in either direction, thus the end of the selection\ /// could be visually before the anchor. For a simple insertion point or a selection /// entirely within a single StText, this parameter doesn't actually make any /// difference.</param> /// <param name="fMakeVisible">Indicates whether to scroll the IP into view.</param> /// <param name="fInstall">True to install the created selection, false otherwise</param> /// ------------------------------------------------------------------------------------ public static SelectionHelper ReduceSelectionToIp(IVwRootSite rootSite, SelLimitType limit, bool fMakeVisible, bool fInstall) { SelectionHelper helper = SelectionHelper.Create(rootSite); if (helper == null) return null; return helper.ReduceSelectionToIp(limit, fMakeVisible, fInstall); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Gets all information about a selection by calling <c>IVwSelection.AllTextSelInfo</c>. /// </summary> /// <param name="vwSel">The selection to get info for, or <c>null</c> to get current /// selection.</param> /// <param name="rootSite">The root site</param> /// <returns>A new <see cref="SelectionHelper"/> object</returns> /// ----------------------------------------------------------------------------------- public static SelectionHelper GetSelectionInfo(IVwSelection vwSel, IVwRootSite rootSite) { if (s_mockedSelectionHelper != null) return s_mockedSelectionHelper; if (vwSel == null || !vwSel.IsValid) { if (rootSite == null || rootSite.RootBox == null) return null; vwSel = rootSite.RootBox.Selection; if (vwSel == null || !vwSel.IsValid) return null; } Debug.Assert(vwSel.IsValid); SelectionHelper helper = new SelectionHelper(vwSel, rootSite); if (!helper.GetSelEndInfo(false)) return null; if (!helper.GetSelEndInfo(true)) return null; return helper; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:FwStylesDlg"/> class. /// </summary> /// <param name="rootSite">The root site.</param> /// <param name="cache">The cache.</param> /// <param name="hvoStylesOwner">The hvo of the object which owns the style.</param> /// <param name="stylesTag">The "flid" in which the styles are owned.</param> /// <param name="defaultRightToLeft">Indicates whether current context (typically the /// default direction of the view from which this dialog is invoked) is right to left.</param> /// <param name="showBiDiLabels">Indicates whether to show labels that are meaningful /// for both left-to-right and right-to-left. If <c>defaultRightToLeft</c> is set to /// <c>true</c> the passed-in value for this parameter will be ignored and the display /// will automatically be BiDi enabled. If this value is false, then simple "Left" and /// "Right" labels will be used in the display, rather than "Leading" and "Trailing".</param> /// <param name="normalStyleName">Name of the normal style.</param> /// <param name="customUserLevel">The custom user level.</param> /// <param name="userMeasurementType">User's prefered measurement units.</param> /// <param name="paraStyleName">Name of the currently selected paragraph style.</param> /// <param name="charStyleName">Name of the currently selected character style.</param> /// <param name="hvoRootObject">The hvo of the root object in the current view.</param> /// <param name="app">The application.</param> /// <param name="helpTopicProvider">The help topic provider.</param> /// ------------------------------------------------------------------------------------ void IFwStylesDlg.Init(IVwRootSite rootSite, FdoCache cache, int hvoStylesOwner, int stylesTag, bool defaultRightToLeft, bool showBiDiLabels, string normalStyleName, int customUserLevel, MsrSysType userMeasurementType, string paraStyleName, string charStyleName, int hvoRootObject, IApp app, IHelpTopicProvider helpTopicProvider) { FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(cache, hvoStylesOwner, stylesTag, true); Init(rootSite, cache, styleSheet, defaultRightToLeft, showBiDiLabels, normalStyleName, customUserLevel, userMeasurementType, paraStyleName, charStyleName, hvoRootObject, app, helpTopicProvider); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a new instance of the <see cref="UndoSelectionAction"/> object. /// </summary> /// <param name="rootSite">The view that has the rootbox (and probably a selection) /// </param> /// <param name="fForUndo"><c>true</c> for Undo, <c>false</c> for Redo.</param> /// <param name="vwSel">The selection for the action</param> /// ------------------------------------------------------------------------------------ public UndoSelectionAction(IVwRootSite rootSite, bool fForUndo, IVwSelection vwSel) { m_fForUndo = fForUndo; m_selHelper = SelectionHelper.Create(vwSel, rootSite); m_rootSite = rootSite; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Start the undo task /// </summary> /// <param name="actionHandler">The IActionHandler to start the undo task on</param> /// <param name="rootSite">The view (can be <c>null</c>)</param> /// <param name="stUndo">Undo label</param> /// <param name="stRedo">Redo label</param> /// ------------------------------------------------------------------------------------ public UndoTaskHelper(IActionHandler actionHandler, IVwRootSite rootSite, string stUndo, string stRedo) : base(actionHandler) { m_vwRootSite = rootSite; Init(stUndo, stRedo); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Start the undo task /// </summary> /// <param name="rootSite">The view (required)</param> /// <param name="stUndo">Undo label</param> /// <param name="stRedo">Redo label</param> /// ------------------------------------------------------------------------------------ public UndoTaskHelper(IVwRootSite rootSite, string stUndo, string stRedo) : this(rootSite.RootBox.DataAccess.GetActionHandler(), rootSite, stUndo, stRedo) { }
/// ----------------------------------------------------------------------------------- /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged /// resources; <c>false</c> to release only unmanaged resources. /// </param> /// ----------------------------------------------------------------------------------- protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; m_lastTextBoxInFocus = null; if (disposing) { if (components != null) components.Dispose(); if (m_cacheMadeLocally && m_cache != null) m_cache.Dispose(); //if (m_helpTopicProvider != null && (m_helpTopicProvider is IDisposable)) // No, since the client provides it. // (m_helpTopicProvider as IDisposable).Dispose(); if (m_htNamedWS != null) m_htNamedWS.Clear(); if (m_messageFilterInstalled) { Application.RemoveMessageFilter(this); m_messageFilterInstalled = false; } } m_htNamedWS = null; m_helpTopicProvider = null; m_searchKiller = null; m_prevSearchText = null; m_vwRootsite = null; m_vwPattern = null; m_cache = null; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the initial values for the dialog controls, prior to displaying the dialog. /// This method should be called after creating, but prior to calling DoModeless. This /// overload is meant to be called from unmanaged code. /// </summary> /// <param name="mdc"></param> /// <param name="ode"></param> /// <param name="oleDbAccess"></param> /// <param name="rootSite">view</param> /// <param name="hwnd">The window handle of the main window that owns the rootsite /// </param> /// <param name="findPattern">The find/replace pattern.</param> /// <remarks>ENHANCE JohnT: it may need more arguments, for example, the name of the /// kind of object we can restrict the search to, a list of fields.</remarks> /// ------------------------------------------------------------------------------------ public void SetOwner(IOleDbEncap ode, IFwMetaDataCache mdc, IVwOleDbDa oleDbAccess, IVwRootSite rootSite, IntPtr hwnd, IVwPattern findPattern) { CheckDisposed(); SetOwner(new FdoCache(ode, mdc, oleDbAccess), rootSite, hwnd, findPattern); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Ensures the annotation is mostly visible by making an uninstalled selection /// toward the end of the modified date. /// </summary> /// ------------------------------------------------------------------------------------ internal void EnsureNoteIsVisible(TeNotesVc vc, int bookIndex, int iAnnotation, IVwRootSite notesDataEntryView) { SelectionHelper selHelper = new SelectionHelper(); selHelper.NumberOfLevels = 2; selHelper.LevelInfo[0].cpropPrevious = 0; selHelper.LevelInfo[0].ich = -1; selHelper.LevelInfo[0].ihvo = iAnnotation; selHelper.LevelInfo[0].tag = vc.NotesSequenceHandler.Tag; selHelper.LevelInfo[0].ws = 0; selHelper.LevelInfo[1].cpropPrevious = 0; selHelper.LevelInfo[1].ich = -1; selHelper.LevelInfo[1].ihvo = bookIndex; selHelper.LevelInfo[1].tag = (int)Scripture.ScriptureTags.kflidBookAnnotations; selHelper.LevelInfo[1].ws = 0; selHelper.AssocPrev = false; // Put the selection at the end of the shortest possible date value. It doesn't // have to be right at the end, but the closer it is, the more reliable it will // be that it is fully scrolled into view. selHelper.IchAnchor = 8; selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, (int)CmAnnotation.CmAnnotationTags.kflidDateModified); selHelper.SetSelection(notesDataEntryView, false, true, VwScrollSelOpts.kssoDefault); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Change the main window which owns this dialog. Since this dialog attempts to stay /// alive as long as the app is alive (or, as long as there is a main window open), /// the app should call this to re-assign an owner any time the existing owner is /// closing. /// </summary> /// <param name="cache">The cache belonging to the view.</param> /// <param name="rootSite">view</param> /// <param name="hwnd">The window handle of the main window that owns the rootsite /// </param> /// <param name="findPattern">The find/replace pattern of the new owner.</param> /// <param name="wsEdit">writing system for the find and replace edit boxes</param> /// ------------------------------------------------------------------------------------ public void SetOwner(FdoCache cache, IVwRootSite rootSite, IntPtr hwnd, IVwPattern findPattern, int wsEdit) { CheckDisposed(); m_vwRootsite = rootSite; if (m_vwRootsite != null && rootSite.RootBox != null) fweditFindText.StyleSheet = fweditReplaceText.StyleSheet = rootSite.RootBox.Stylesheet; bool fChangingCache = (m_cache != cache); m_cache = cache; if (m_cache != null && fChangingCache) { ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor; fweditFindText.WritingSystemFactory = fweditReplaceText.WritingSystemFactory = wsf; ITsStrFactory strFact = TsStrFactoryClass.Create(); FindText = strFact.MakeString(string.Empty, m_cache.DefaultVernWs); ReplaceText = strFact.MakeString(string.Empty, m_cache.DefaultVernWs); // Make sure each of the edit boxes has a reasonable writing system assigned. // (See LT-5130 for what can happen otherwise.) // The default verncular is not always reasonable enough. fweditFindText.WritingSystemCode = wsEdit; // m_cache.DefaultVernWs; fweditReplaceText.WritingSystemCode = wsEdit; // m_cache.DefaultVernWs; FindText = EnsureValidWs(wsEdit, findPattern.Pattern); ReplaceText = EnsureValidWs(wsEdit, findPattern.ReplaceWith); SetCheckboxStates(findPattern); m_vwPattern = findPattern; } Control newOwner = Form.FromHandle(hwnd); if (newOwner != null && Owner != newOwner && newOwner is Form) { Owner = (Form)newOwner; m_vwselPattern = null; m_findEnvironment = null; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:FwStylesDlg"/> class. This version /// can be used by C# clients. There is no need for the client to call Init if this /// constructor is used. /// </summary> /// <param name="rootSite">The root site.</param> /// <param name="cache">The cache.</param> /// <param name="styleSheet">The style sheet.</param> /// <param name="defaultRightToLeft">Indicates whether current context (typically the /// default direction of the view from which this dialog is invoked) is right to left.</param> /// <param name="showBiDiLabels">Indicates whether to show labels that are meaningful /// for both left-to-right and right-to-left. If <c>defaultRightToLeft</c> is set to /// <c>true</c> the passed-in value for this parameter will be ignored and the display /// will automatically be BiDi enabled. If this value is false, then simple "Left" and /// "Right" labels will be used in the display, rather than "Leading" and "Trailing".</param> /// <param name="normalStyleName">Name of the normal style.</param> /// <param name="customUserLevel">The custom user level.</param> /// <param name="userMeasurementType">User's prefered measurement units.</param> /// <param name="paraStyleName">Name of the currently selected paragraph style.</param> /// <param name="charStyleName">Name of the currently selected character style.</param> /// <param name="hvoRootObject">The hvo of the root object in the current view.</param> /// <param name="app">The application.</param> /// <param name="helpTopicProvider">The help topic provider.</param> /// ------------------------------------------------------------------------------------ public FwStylesDlg(IVwRootSite rootSite, FdoCache cache, FwStyleSheet styleSheet, bool defaultRightToLeft, bool showBiDiLabels, string normalStyleName, int customUserLevel, MsrSysType userMeasurementType, string paraStyleName, string charStyleName, int hvoRootObject, IApp app, IHelpTopicProvider helpTopicProvider) : this() { Init(rootSite, cache, styleSheet, defaultRightToLeft, showBiDiLabels, normalStyleName, customUserLevel, userMeasurementType, paraStyleName, charStyleName, hvoRootObject, app, helpTopicProvider); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Reduce a range selection to a simple insertion point, specifying which limit of /// the range selection to use as the position for the new IP. /// </summary> /// <param name="rootSite">The root site</param> /// <param name="limit">Specify Top to place the IP at the top-most limit of the /// selection. Specify Bottom to place the IP at the bottom-most limit of the selection. /// Specify Anchor to place the IP at the point where the user initiated the selection. /// Specify End to place the IP at the point where the user completed the selection. Be /// aware the user may select text in either direction, thus the end of the selection\ /// could be visually before the anchor. For a simple insertion point or a selection /// entirely within a single StText, this parameter doesn't actually make any /// difference.</param> /// <param name="fMakeVisible">Indicates whether to scroll the IP into view.</param> /// ------------------------------------------------------------------------------------ public static SelectionHelper ReduceSelectionToIp(IVwRootSite rootSite, SelLimitType limit, bool fMakeVisible) { return ReduceSelectionToIp(rootSite, limit, fMakeVisible, true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:FwStylesDlg"/> class. /// </summary> /// <param name="rootSite">The root site.</param> /// <param name="cache">The cache.</param> /// <param name="styleSheet">The style sheet.</param> /// <param name="defaultRightToLeft">Indicates whether current context (typically the /// default direction of the view from which this dialog is invoked) is right to left.</param> /// <param name="showBiDiLabels">Indicates whether to show labels that are meaningful /// for both left-to-right and right-to-left. If <c>defaultRightToLeft</c> is set to /// <c>true</c> the passed-in value for this parameter will be ignored and the display /// will automatically be BiDi enabled. If this value is false, then simple "Left" and /// "Right" labels will be used in the display, rather than "Leading" and "Trailing".</param> /// <param name="normalStyleName">Name of the normal style.</param> /// <param name="customUserLevel">The custom user level.</param> /// <param name="userMeasurementType">User's prefered measurement units.</param> /// <param name="paraStyleName">Name of the currently selected paragraph style.</param> /// <param name="charStyleName">Name of the currently selected character style.</param> /// <param name="hvoRootObject">The hvo of the root object in the current view.</param> /// <param name="app">The application.</param> /// <param name="helpTopicProvider">The help topic provider.</param> /// ------------------------------------------------------------------------------------ protected void Init(IVwRootSite rootSite, FdoCache cache, FwStyleSheet styleSheet, bool defaultRightToLeft, bool showBiDiLabels, string normalStyleName, int customUserLevel, MsrSysType userMeasurementType, string paraStyleName, string charStyleName, int hvoRootObject, IApp app, IHelpTopicProvider helpTopicProvider) { CheckDisposed(); m_rootSite = rootSite; m_cache = cache; m_customUserLevel = customUserLevel; m_hvoRootObject = hvoRootObject; m_app = app; showBiDiLabels |= defaultRightToLeft; m_fShowBidiLabels = showBiDiLabels; m_userMeasurementType = userMeasurementType; m_helpTopicProvider = helpTopicProvider; // Cache is null in tests if (cache == null) return; m_cboTypes.SelectedIndex = 1; // All Styles // Load the style information m_styleTable = new StyleInfoTable(normalStyleName, cache.LanguageWritingSystemFactoryAccessor); m_styleSheet = styleSheet; FillStyleTable(m_styleSheet); m_normalStyleInfo = (StyleInfo)m_styleTable[normalStyleName]; Debug.Assert(m_normalStyleInfo != null); m_styleListHelper = new StyleListBoxHelper(m_lstStyles); m_styleListHelper.AddStyles(m_styleTable, null); m_styleListHelper.ShowInternalStyles = true; m_styleListHelper.StyleChosen += new StyleChosenHandler(m_styleListHelper_StyleChosen); m_styleListHelper.Refresh(); // Mark the current styles m_styleListHelper.MarkCurrentStyle(paraStyleName); m_styleListHelper.MarkCurrentStyle(charStyleName); // General tab m_generalTab.StyleListHelper = m_styleListHelper; m_generalTab.StyleTable = m_styleTable; m_generalTab.ShowBiDiLabels = showBiDiLabels; m_generalTab.UserMeasurementType = m_userMeasurementType; m_generalTab.RenamedStyles = m_renamedStyles; // Load the font information m_fontTab.WritingSystemFactory = cache.LanguageWritingSystemFactoryAccessor; m_fontTab.FillFontInfo(cache); // Disable the background color on the paragraph tab. m_paragraphTab.DefaultTextDirectionRtoL = defaultRightToLeft; m_paragraphTab.ShowBiDiLabels = showBiDiLabels; m_paragraphTab.MeasureType = userMeasurementType; m_bulletsTab.DefaultTextDirectionRtoL = defaultRightToLeft; m_bulletsTab.StyleSheet = m_styleSheet; m_borderTab.DefaultTextDirectionRtoL = defaultRightToLeft; m_borderTab.ShowBiDiLabels = showBiDiLabels; // Select the current paragraph style in the list (or fall back to Normal) if (!string.IsNullOrEmpty(paraStyleName)) m_styleListHelper.SelectedStyleName = paraStyleName; else m_styleListHelper.SelectedStyleName = normalStyleName; m_styleListHelper_StyleChosen(null, m_styleListHelper.SelectedStyle); // Default is not to show the style type selection combo. if (!DesignMode) AllowSelectStyleTypes = false; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Sets the selection by calling <c>IVwRootBox.MakeRangeSelection</c>. /// </summary> /// <param name="rootSite">The root site</param> /// <param name="fInstall">Makes the selection the current selection</param> /// <param name="fMakeVisible">Determines whether or not to make the selection visible. /// </param> /// <returns>The selection</returns> /// ----------------------------------------------------------------------------------- public virtual IVwSelection SetSelection(IVwRootSite rootSite, bool fInstall, bool fMakeVisible) { return SetSelection(rootSite, fInstall, fMakeVisible, VwScrollSelOpts.kssoDefault); }
public void SetSite(IVwRootSite _vrs) { throw new NotImplementedException(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Start the undo task /// </summary> /// <param name="dataAccess">The ISilDataAccess to start the undo task on</param> /// <param name="rootSite">The view (can be <c>null</c>)</param> /// <param name="stid">String resource id used for Undo/Redo labels</param> /// ------------------------------------------------------------------------------------ public UndoTaskHelper(ISilDataAccess dataAccess, IVwRootSite rootSite, string stid) : this(dataAccess, rootSite, stid, true) { }
/// <summary> /// See C++ documentation /// </summary> public void DrawTheRoot(IVwRootBox prootb, IntPtr hdc, Rect rcpDraw, uint bkclr, bool fDrawSel, IVwRootSite pvrs) { IVwSynchronizer synchronizer = prootb.Synchronizer; if (synchronizer != null) { try { if (synchronizer.IsExpandingLazyItems) { return; } } catch (Exception e) { Console.WriteLine("call to IsExpandingLazyItems caused exceptionException e ={0}", e); } } IVwGraphicsWin32 qvg = VwGraphicsWin32Class.Create(); Rectangle rcp = rcpDraw; using (Graphics screen = Graphics.FromHdc(hdc)) using (var memoryBuffer = new MemoryBuffer(rcp.Width, rcp.Height)) { memoryBuffer.Graphics.FillRectangle(new SolidBrush(ColorUtil.ConvertBGRtoColor(bkclr)), 0, 0, rcp.Width, rcp.Height); qvg.Initialize(memoryBuffer.Graphics.GetHdc()); VwPrepDrawResult xpdr = VwPrepDrawResult.kxpdrAdjust; IVwGraphics qvgDummy = null; try { Rect rcDst, rcSrc; while (xpdr == VwPrepDrawResult.kxpdrAdjust) { pvrs.GetGraphics(prootb, out qvgDummy, out rcSrc, out rcDst); Rectangle temp = rcDst; temp.Offset(-rcp.Left, -rcp.Top); rcDst = temp; qvg.XUnitsPerInch = qvgDummy.XUnitsPerInch; qvg.YUnitsPerInch = qvgDummy.YUnitsPerInch; xpdr = prootb.PrepareToDraw(qvg, rcSrc, rcDst); pvrs.ReleaseGraphics(prootb, qvgDummy); qvgDummy = null; } if (xpdr != VwPrepDrawResult.kxpdrInvalidate) { pvrs.GetGraphics(prootb, out qvgDummy, out rcSrc, out rcDst); Rectangle temp = rcDst; temp.Offset(-rcp.Left, -rcp.Top); rcDst = temp; qvg.XUnitsPerInch = qvgDummy.XUnitsPerInch; qvg.YUnitsPerInch = qvgDummy.YUnitsPerInch; try { prootb.DrawRoot(qvg, rcSrc, rcDst, fDrawSel); } catch (Exception e) { Console.WriteLine("DrawRoot e = {0} qvg = {1} rcSrc = {2} rcDst = {3} fDrawSel = {4}", e, qvg, rcSrc, rcDst, fDrawSel); } pvrs.ReleaseGraphics(prootb, qvgDummy); qvgDummy = null; } } catch (Exception) { if (qvgDummy != null) pvrs.ReleaseGraphics(prootb, qvgDummy); qvg.ReleaseDC(); throw; } if (xpdr != VwPrepDrawResult.kxpdrInvalidate) { screen.DrawImageUnscaled(memoryBuffer.Bitmap, rcp.Left, rcp.Top, rcp.Width, rcp.Height); } qvg.ReleaseDC(); } }
public void SetSite(IVwRootSite _vrs) { throw new NotImplementedException("The method or operation is not implemented."); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes a selection in the specified annotation (without scrolling the annotation in /// the view). /// </summary> /// <param name="vc">The notes view constructor</param> /// <param name="fScrollNearTop">if set to <c>true</c> scrolls the specified note to a /// position near the top of the view.</param> /// <param name="bookIndex">Index of the book.</param> /// <param name="iAnnotation">Index of the annotation.</param> /// <param name="iResponse">Index of the response (0 if setting the selection in one of /// the StJournalText fields rather than in a response.</param> /// <param name="noteTag">The tag indicating the field of the annotation where the /// selection is to be made.</param> /// <param name="rootSite">The root site.</param> /// <param name="fNoteIsExpanded">if <c>true</c> make a selection at the start and end so /// that the whole annotation can be scrolled into view. if set to <c>false</c> only /// make a selection at the start of the annotation.</param> /// ------------------------------------------------------------------------------------ internal void MakeSelectionInNote(TeNotesVc vc, bool fScrollNearTop, int bookIndex, int iAnnotation, int iResponse, int noteTag, IVwRootSite rootSite, bool fNoteIsExpanded) { if (vc == null) { return; } SelectionHelper selHelper; if (fScrollNearTop) { // Make an un-installed selection at the top of the annotation in order to scroll the // annotation to the top of the view. selHelper = new SelectionHelper(); selHelper.NumberOfLevels = 2; selHelper.LevelInfo[0].cpropPrevious = 0; selHelper.LevelInfo[0].ich = -1; selHelper.LevelInfo[0].ihvo = iAnnotation; selHelper.LevelInfo[0].tag = ScrBookAnnotationsTags.kflidNotes; selHelper.LevelInfo[0].ws = 0; selHelper.LevelInfo[1].cpropPrevious = 0; selHelper.LevelInfo[1].ich = -1; selHelper.LevelInfo[1].ihvo = bookIndex; selHelper.LevelInfo[1].tag = ScriptureTags.kflidBookAnnotations; selHelper.LevelInfo[1].ws = 0; selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, -2); selHelper.IchAnchor = 0; selHelper.AssocPrev = false; selHelper.NumberOfPreviousProps = 2; if (fNoteIsExpanded) { selHelper.SetSelection(rootSite, true, true, VwScrollSelOpts.kssoNearTop); } else { // Annotation is collapsed. Only attempt a selection at the start of it. selHelper.SetSelection(rootSite, true, true); return; } } else { EnsureNoteIsVisible(vc, bookIndex, iAnnotation, rootSite); } // Now make the real (installed) selection in the desired field of the annotation. bool fIsResponse = (noteTag == ScrScriptureNoteTags.kflidResponses); selHelper = new SelectionHelper(); selHelper.NumberOfLevels = 4; selHelper.LevelInfo[0].tag = StTextTags.kflidParagraphs; selHelper.LevelInfo[0].ihvo = 0; selHelper.LevelInfo[1].tag = (int)noteTag; selHelper.LevelInfo[1].ihvo = iResponse; selHelper.LevelInfo[1].cpropPrevious = (fIsResponse ? 0 : 1); selHelper.LevelInfo[2].tag = ScrBookAnnotationsTags.kflidNotes; selHelper.LevelInfo[2].ihvo = iAnnotation; selHelper.LevelInfo[3].tag = ScriptureTags.kflidBookAnnotations; selHelper.LevelInfo[3].ihvo = bookIndex; selHelper.IchAnchor = 0; selHelper.AssocPrev = false; selHelper.TextPropId = StTxtParaTags.kflidContents; selHelper.SetSelection(rootSite, true, true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets up results for user prompt change tests (mostly creates and sets up mock /// objects to stub out methods). /// </summary> /// <param name="cLevels">The count of selection levels.</param> /// <param name="text">The text that was typed or pasted to replace the prompt.</param> /// <param name="rootb">The (mocked) root box.</param> /// <param name="vwsel">The (mocked) vw selection.</param> /// <param name="rootsite">The (mocked) rootsite.</param> /// ------------------------------------------------------------------------------------ private static void SetUpResultsForUpdateUserPromptTests(int cLevels, string text, out IVwRootBox rootb, out IVwSelection vwsel, out IVwRootSite rootsite) { Options.ShowEmptyParagraphPromptsSetting = true; IVwRootBox rootbox = rootb = MockRepository.GenerateMock <IVwRootBox>(); rootb.Stub(x => x.IsCompositionInProgress).Return(false); rootsite = MockRepository.GenerateMock <IVwRootSite>(); rootb.Stub(x => x.Site).Return(rootsite); vwsel = MockRepository.GenerateMock <IVwSelection>(); vwsel.Stub(x => x.RootBox).Return(rootb); // The number of levels CLevels reports includes one for the string property, so we add that here (production code subtracts it) vwsel.Stub(x => x.CLevels(Arg <bool> .Is.Anything)).Return(cLevels + 1); vwsel.Stub(x => x.AllTextSelInfo(out Arg <int> .Out(0).Dummy, Arg <int> .Is.Equal(cLevels), Arg <ArrayPtr> .Is.Anything, out Arg <int> .Out(0).Dummy, out Arg <int> .Out(0).Dummy, out Arg <int> .Out(0).Dummy, out Arg <int> .Out(text.Length).Dummy, out Arg <int> .Out(0).Dummy, out Arg <bool> .Out(false).Dummy, out Arg <int> .Out(0).Dummy, out Arg <ITsTextProps> .Out(null).Dummy)); #if DEBUG vwsel.Stub(x => x.IsValid).Return(true); #endif }
/// ------------------------------------------------------------------------------------ /// <summary> /// Constructor /// </summary> /// <param name="owner">The object that creates this DataUpdateMonitor</param> /// <param name="sda">Data access object (corresponds to a DB connection)</param> /// <param name="site">Root site used to recover the selection after the update</param> /// <param name="updateDescription">description of the data update being done, /// for debugging.</param> /// ------------------------------------------------------------------------------------ public DataUpdateMonitor(Control owner, ISilDataAccess sda, IVwRootSite site, string updateDescription) : this(owner, sda, site, updateDescription, true, false) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a new instance of the <see cref="UndoSelectionAction"/> object. /// </summary> /// <param name="rootSite">The view that has the rootbox (and probably a selection) /// </param> /// <param name="fForUndo"><c>true</c> for Undo, <c>false</c> for Redo.</param> /// <param name="vwSel">The selection for the action</param> /// ------------------------------------------------------------------------------------ public UndoSelectionAction(IVwRootSite rootSite, bool fForUndo, IVwSelection vwSel) { m_fForUndo = fForUndo; m_selHelper = SelectionHelper.Create(vwSel, rootSite); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Create a selection helper based on an existing selection /// </summary> /// ----------------------------------------------------------------------------------- protected SelectionHelper(IVwSelection vwSel, IVwRootSite rootSite) { m_vwSel = vwSel; if (vwSel != null) m_fEndSet = vwSel.IsRange; RootSite = rootSite; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes a selection in the specified annotation (without scrolling the annotation in /// the view). /// </summary> /// <param name="vc">The notes view constructor</param> /// <param name="fScrollNearTop">if set to <c>true</c> scrolls the specified note to a /// position near the top of the view.</param> /// <param name="bookIndex">Index of the book.</param> /// <param name="iAnnotation">Index of the annotation.</param> /// <param name="iResponse">Index of the response (0 if setting the selection in one of /// the StJournalText fields rather than in a response.</param> /// <param name="noteTag">The tag indicating the field of the annotation where the /// selection is to be made.</param> /// <param name="rootSite">The root site.</param> /// <param name="fNoteIsExpanded">if <c>true</c> make a selection at the start and end so /// that the whole annotation can be scrolled into view. if set to <c>false</c> only /// make a selection at the start of the annotation.</param> /// ------------------------------------------------------------------------------------ internal void MakeSelectionInNote(TeNotesVc vc, bool fScrollNearTop, int bookIndex, int iAnnotation, int iResponse, ScrScriptureNote.ScrScriptureNoteTags noteTag, IVwRootSite rootSite, bool fNoteIsExpanded) { if (vc == null || vc.NotesSequenceHandler == null) return; SelectionHelper selHelper; if (fScrollNearTop) { // Make an un-installed selection at the top of the annotation in order to scroll the // annotation to the top of the view. selHelper = new SelectionHelper(); selHelper.NumberOfLevels = 2; selHelper.LevelInfo[0].cpropPrevious = 0; selHelper.LevelInfo[0].ich = -1; selHelper.LevelInfo[0].ihvo = iAnnotation; selHelper.LevelInfo[0].tag = vc.NotesSequenceHandler.Tag; selHelper.LevelInfo[0].ws = 0; selHelper.LevelInfo[1].cpropPrevious = 0; selHelper.LevelInfo[1].ich = -1; selHelper.LevelInfo[1].ihvo = bookIndex; selHelper.LevelInfo[1].tag = (int)Scripture.ScriptureTags.kflidBookAnnotations; selHelper.LevelInfo[1].ws = 0; selHelper.SetTextPropId(SelectionHelper.SelLimitType.Anchor, -2); selHelper.IchAnchor = 0; selHelper.AssocPrev = false; selHelper.NumberOfPreviousProps = 2; if (fNoteIsExpanded) { selHelper.SetSelection(rootSite, true, true, VwScrollSelOpts.kssoNearTop); } else { // Annotation is collapsed. Only attempt a selection at the start of it. selHelper.SetSelection(rootSite, true, true); return; } } else EnsureNoteIsVisible(vc, bookIndex, iAnnotation, rootSite); // Now make the real (installed) selection in the desired field of the annotation. bool fIsResponse = (noteTag == ScrScriptureNote.ScrScriptureNoteTags.kflidResponses); selHelper = new SelectionHelper(); selHelper.NumberOfLevels = 4; selHelper.LevelInfo[0].tag = (int)StText.StTextTags.kflidParagraphs; selHelper.LevelInfo[0].ihvo = 0; selHelper.LevelInfo[1].tag = (int)noteTag; selHelper.LevelInfo[1].ihvo = iResponse; selHelper.LevelInfo[1].cpropPrevious = (fIsResponse ? 0 : 1); selHelper.LevelInfo[2].tag = vc.NotesSequenceHandler.Tag; selHelper.LevelInfo[2].ihvo = iAnnotation; selHelper.LevelInfo[3].tag = (int)Scripture.ScriptureTags.kflidBookAnnotations; selHelper.LevelInfo[3].ihvo = bookIndex; selHelper.IchAnchor = 0; selHelper.AssocPrev = false; selHelper.SetSelection(rootSite, true, true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create a SelectionHelper with the information about the current selection. /// </summary> /// <param name="vwSel">The selection to create a SelectionHelper object from or /// null to create it from the given RootSite</param> /// <param name="rootSite">The root site</param> /// <returns>A new <see cref="SelectionHelper"/> object</returns> /// ------------------------------------------------------------------------------------ public static SelectionHelper Create(IVwSelection vwSel, IVwRootSite rootSite) { return GetSelectionInfo(vwSel, rootSite); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Start the undo task /// </summary> /// <param name="rootSite">The view (required)</param> /// <param name="stUndo">Undo label</param> /// <param name="stRedo">Redo label</param> /// <param name="fCommit"><c>true</c> to call commit (and thus end all outstanding /// transactions). If an <see cref="UndoTaskHelper"/> object is created as part of an /// inner task, you probably want to set this to <c>false</c>. Default is <c>true</c>. /// </param> /// ------------------------------------------------------------------------------------ public UndoTaskHelper(IVwRootSite rootSite, string stUndo, string stRedo, bool fCommit) { Debug.Assert(rootSite != null); Init(rootSite.RootBox.DataAccess, rootSite, stUndo, stRedo, fCommit); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Change the main window which owns this dialog. Since this dialog attempts to stay /// alive as long as the app is alive (or, as long as there is a main window open), /// the app should call this to re-assign an owner any time the existing owner is /// closing. This assumes that the find and replace edit boxes use the default /// vernacular writing system. /// </summary> public void SetOwner(FdoCache cache, IVwRootSite rootSite, IntPtr hwnd, IVwPattern findPattern) { SetOwner(cache, rootSite, hwnd, findPattern, cache.DefaultVernWs); }
/// -------------------------------------------------------------------------------- /// <summary> /// Makes a selection in the discussion of an annotation after first scrolling the /// annotation to near the top of the view. /// </summary> /// <param name="vc">The notes view constructor</param> /// <param name="bookIndex">Index of the book.</param> /// <param name="iAnnotation">Index of the annotation.</param> /// <param name="rootSite">The root site.</param> /// <param name="fNoteIsExpanded">if <c>true</c> make a selection at the start and end so /// that the whole annotation can be scrolled into view. if set to <c>false</c> only /// make a selection at the start of the annotation.</param> /// -------------------------------------------------------------------------------- internal void MakeSelectionInNote(TeNotesVc vc, int bookIndex, int iAnnotation, IVwRootSite rootSite, bool fNoteIsExpanded) { MakeSelectionInNote(vc, true, bookIndex, iAnnotation, 0, ScrScriptureNoteTags.kflidDiscussion, rootSite, fNoteIsExpanded); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Called when the root site gets disposed. We can't use m_rootSite any more. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event /// data.</param> /// ------------------------------------------------------------------------------------ private void OnRootSiteDisposed(object sender, EventArgs e) { m_rootSite = null; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Make a range selection based upon our saved selection info. /// NOTE: Installing the selection may trigger side effects that will invalidate the selection. /// Callers should check to make sure the selection is still valid before using it. /// </summary> /// <param name="rootSite"></param> /// <param name="fInstall"></param> /// <exception cref="Exception">overload throws if unable to make an end selection</exception> /// <returns>a range selection (could become invalid as a side-effect of installing.)</returns> /// ----------------------------------------------------------------------------------- private IVwSelection MakeRangeSelection(IVwRootSite rootSite, bool fInstall) { return MakeRangeSelection(rootSite.RootBox, fInstall); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Start the undo task /// </summary> /// <param name="rootSite">The view (can be <c>null</c>)</param> /// <param name="stid">String resource id used for Undo/Redo labels</param> /// ----------------------------------------------------------------------------------- public UndoTaskHelper(IVwRootSite rootSite, string stid) : this(rootSite, stid, true) { }
/// <summary> /// Draws the Root into a memory buffer, then rotates it 90deg clockwise while drawing /// the memory buffer to the screen. /// See C++ documentation for more info. /// </summary> public void DrawTheRootRotated(IVwRootBox rootb, IntPtr hdc, Rect rcpDraw, uint bkclr, bool fDrawSel, IVwRootSite vrs, int nHow) { IVwGraphicsWin32 qvg32 = VwGraphicsWin32Class.Create(); Rectangle rcp = new Rectangle(rcpDraw.top, rcpDraw.left, rcpDraw.bottom, rcpDraw.right); Rectangle rcFill = new Rect(0, 0, rcp.Width, rcp.Height); using (Graphics screen = Graphics.FromHdc(hdc)) using (var memoryBuffer = new MemoryBuffer(rcp.Width, rcp.Height)) { memoryBuffer.Graphics.FillRectangle(new SolidBrush(ColorUtil.ConvertBGRtoColor(bkclr)), rcFill); qvg32.Initialize(memoryBuffer.Graphics.GetHdc()); IVwGraphics qvgDummy = null; try { Rect rcDst, rcSrc; vrs.GetGraphics(rootb, out qvgDummy, out rcSrc, out rcDst); Rectangle temp = rcDst; temp.Offset(-rcp.Left, -rcp.Top); rcDst = temp; qvg32.XUnitsPerInch = qvgDummy.XUnitsPerInch; qvg32.YUnitsPerInch = qvgDummy.YUnitsPerInch; rootb.DrawRoot(qvg32, rcSrc, rcDst, fDrawSel); vrs.ReleaseGraphics(rootb, qvgDummy); qvgDummy = null; } catch (Exception) { if (qvgDummy != null) vrs.ReleaseGraphics(rootb, qvgDummy); qvg32.ReleaseDC(); throw; } Point[] rgptTransform = new Point[3]; rgptTransform[0] = new Point(rcpDraw.right, rcpDraw.top); // upper left of actual drawing maps to top right of rotated drawing rgptTransform[1] = new Point(rcpDraw.right, rcpDraw.bottom); // upper right of actual drawing maps to bottom right of rotated drawing. rgptTransform[2] = new Point(rcpDraw.left, rcpDraw.top); // bottom left of actual drawing maps to top left of rotated drawing. screen.DrawImage((Image)memoryBuffer.Bitmap, rgptTransform, new Rectangle(0, 0, rcp.Width, rcp.Height), GraphicsUnit.Pixel); qvg32.ReleaseDC(); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Make an insertion point based upon our saved anchor selection info. It will not be /// set until after the unit of work. /// </summary> /// <param name="rootSite"></param> /// ----------------------------------------------------------------------------------- public virtual void SetIPAfterUOW(IVwRootSite rootSite) { int iAnchor = 0; rootSite.RequestSelectionAtEndOfUow(rootSite.RootBox, m_selInfo[iAnchor].ihvoRoot, m_selInfo[iAnchor].rgvsli.Length, m_selInfo[iAnchor].rgvsli, m_selInfo[iAnchor].tagTextProp, m_selInfo[iAnchor].cpropPrevious, m_selInfo[iAnchor].ich, m_selInfo[iAnchor].ws, m_selInfo[iAnchor].fAssocPrev, m_selInfo[iAnchor].ttpSelProps); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:FwStylesDlg"/> class. This version /// can be used by C# clients. There is no need for the client to call Init if this /// constructor is used. /// </summary> /// <param name="rootSite">The root site.</param> /// <param name="cache">The cache.</param> /// <param name="styleSheet">The style sheet.</param> /// <param name="defaultRightToLeft">Indicates whether current context (typically the /// default direction of the view from which this dialog is invoked) is right to left.</param> /// <param name="showBiDiLabels">Indicates whether to show labels that are meaningful /// for both left-to-right and right-to-left. If <c>defaultRightToLeft</c> is set to /// <c>true</c> the passed-in value for this parameter will be ignored and the display /// will automatically be BiDi enabled. If this value is false, then simple "Left" and /// "Right" labels will be used in the display, rather than "Leading" and "Trailing".</param> /// <param name="normalStyleName">Name of the normal style.</param> /// <param name="customUserLevel">The custom user level.</param> /// <param name="userMeasurementType">User's prefered measurement units.</param> /// <param name="paraStyleName">Name of the currently selected paragraph style.</param> /// <param name="charStyleName">Name of the currently selected character style.</param> /// <param name="hvoRootObject">The hvo of the root object in the current view.</param> /// <param name="app">The application.</param> /// <param name="helpTopicProvider">The help topic provider.</param> /// ------------------------------------------------------------------------------------ public FwStylesDlg(IVwRootSite rootSite, FdoCache cache, FwStyleSheet styleSheet, bool defaultRightToLeft, bool showBiDiLabels, string normalStyleName, int customUserLevel, MsrSysType userMeasurementType, string paraStyleName, string charStyleName, int hvoRootObject, IApp app, IHelpTopicProvider helpTopicProvider) : this() { m_rootSite = rootSite; m_cache = cache; m_customUserLevel = customUserLevel; m_hvoRootObject = hvoRootObject; m_app = app; showBiDiLabels |= defaultRightToLeft; m_userMeasurementType = userMeasurementType; m_helpTopicProvider = helpTopicProvider; // Cache is null in tests if (cache == null) return; m_cboTypes.SelectedIndex = 1; // All Styles // Load the style information m_styleTable = new StyleInfoTable(normalStyleName, cache.ServiceLocator.WritingSystemManager); m_styleSheet = styleSheet; FillStyleTable(m_styleSheet); m_normalStyleInfo = (StyleInfo)m_styleTable[normalStyleName]; Debug.Assert(m_normalStyleInfo != null); m_styleListHelper = new StyleListBoxHelper(m_lstStyles); m_styleListHelper.AddStyles(m_styleTable, null); m_styleListHelper.ShowInternalStyles = true; m_styleListHelper.StyleChosen += new StyleChosenHandler(m_styleListHelper_StyleChosen); m_styleListHelper.Refresh(); // Mark the current styles m_styleListHelper.MarkCurrentStyle(paraStyleName); m_styleListHelper.MarkCurrentStyle(charStyleName); // General tab m_generalTab.Application = m_app; m_generalTab.StyleListHelper = m_styleListHelper; m_generalTab.StyleTable = m_styleTable; m_generalTab.ShowBiDiLabels = showBiDiLabels; m_generalTab.UserMeasurementType = m_userMeasurementType; m_generalTab.RenamedStyles = m_renamedStyles; // Load the font information m_fontTab.WritingSystemFactory = cache.WritingSystemFactory; m_fontTab.FillFontInfo(cache); // Disable the background color on the paragraph tab. m_paragraphTab.DefaultTextDirectionRtoL = defaultRightToLeft; m_paragraphTab.ShowBiDiLabels = showBiDiLabels; m_paragraphTab.MeasureType = userMeasurementType; m_bulletsTab.DefaultTextDirectionRtoL = defaultRightToLeft; m_bulletsTab.StyleSheet = m_styleSheet; m_borderTab.DefaultTextDirectionRtoL = defaultRightToLeft; m_borderTab.ShowBiDiLabels = showBiDiLabels; // Select the current paragraph style in the list (or fall back to Normal) CurrentStyle = (!string.IsNullOrEmpty(paraStyleName)) ? paraStyleName : normalStyleName; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the selection /// </summary> /// <param name="rootSite">The root site</param> /// <returns>The selection</returns> /// ------------------------------------------------------------------------------------ public virtual IVwSelection SetSelection(IVwRootSite rootSite) { return SetSelection(rootSite, true, true, VwScrollSelOpts.kssoDefault); }
/// <summary> /// See C++ documentation /// </summary> public void DrawTheRoot(IVwRootBox prootb, IntPtr hdc, Rect rcpDraw, uint bkclr, bool fDrawSel, IVwRootSite pvrs) { IVwSynchronizer synchronizer = prootb.Synchronizer; if (synchronizer != null) { try { if (synchronizer.IsExpandingLazyItems) { return; } } catch (Exception e) { Console.WriteLine("call to IsExpandingLazyItems caused exceptionException e ={0}", e); } } IVwGraphicsWin32 qvg = VwGraphicsWin32Class.Create(); Rectangle rcp = rcpDraw; using (Graphics screen = Graphics.FromHdc(hdc)) using (var memoryBuffer = new MemoryBuffer(rcp.Width, rcp.Height)) { memoryBuffer.Graphics.FillRectangle(new SolidBrush(ColorUtil.ConvertBGRtoColor(bkclr)), 0, 0, rcp.Width, rcp.Height); qvg.Initialize(memoryBuffer.Graphics.GetHdc()); VwPrepDrawResult xpdr = VwPrepDrawResult.kxpdrAdjust; IVwGraphics qvgDummy = null; try { Rect rcDst, rcSrc; while (xpdr == VwPrepDrawResult.kxpdrAdjust) { pvrs.GetGraphics(prootb, out qvgDummy, out rcSrc, out rcDst); Rectangle temp = rcDst; temp.Offset(-rcp.Left, -rcp.Top); rcDst = temp; qvg.XUnitsPerInch = qvgDummy.XUnitsPerInch; qvg.YUnitsPerInch = qvgDummy.YUnitsPerInch; xpdr = prootb.PrepareToDraw(qvg, rcSrc, rcDst); pvrs.ReleaseGraphics(prootb, qvgDummy); qvgDummy = null; } if (xpdr != VwPrepDrawResult.kxpdrInvalidate) { pvrs.GetGraphics(prootb, out qvgDummy, out rcSrc, out rcDst); Rectangle temp = rcDst; temp.Offset(-rcp.Left, -rcp.Top); rcDst = temp; qvg.XUnitsPerInch = qvgDummy.XUnitsPerInch; qvg.YUnitsPerInch = qvgDummy.YUnitsPerInch; try { prootb.DrawRoot(qvg, rcSrc, rcDst, fDrawSel); } catch (Exception e) { Console.WriteLine("DrawRoot e = {0} qvg = {1} rcSrc = {2} rcDst = {3} fDrawSel = {4}", e, qvg, rcSrc, rcDst, fDrawSel); } pvrs.ReleaseGraphics(prootb, qvgDummy); qvgDummy = null; } } catch (Exception) { if (qvgDummy != null) { pvrs.ReleaseGraphics(prootb, qvgDummy); } qvg.ReleaseDC(); throw; } if (xpdr != VwPrepDrawResult.kxpdrInvalidate) { screen.DrawImageUnscaled(memoryBuffer.Bitmap, rcp.Left, rcp.Top, rcp.Width, rcp.Height); } qvg.ReleaseDC(); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// The requested anchor and endpoint may be beyond the end of the string. Try to make /// a selection as near the end of the string as possible. /// </summary> /// <param name="fMakeVisible">Indicates whether to scroll the selection into view /// </param> /// <param name="rootsite">The rootsite that will try take the selection</param> /// <returns>The selection</returns> /// ------------------------------------------------------------------------------------ public virtual IVwSelection MakeBest(IVwRootSite rootsite, bool fMakeVisible) { //SelInfo ichAnchorOrig = m_selInfo[0]; //SelInfo ichEndOrig = m_selInfo[1]; // Try setting original selection IVwSelection vwsel = SetSelection(rootsite, true, fMakeVisible, VwScrollSelOpts.kssoDefault); if (vwsel != null) return vwsel; // Otherwise try endpoint = anchor (if the endpoint is set) if (m_fEndSet) { try { if (m_selInfo[1] == null || m_selInfo[0] < m_selInfo[1]) m_selInfo[1] = m_selInfo[0]; else m_selInfo[0] = m_selInfo[1]; } catch (ArgumentException) { // comparison failed due to selection points being at different text levels, // e.g., section heading and section content. Assume first selection point // is top m_selInfo[1] = m_selInfo[0]; } vwsel = SetSelection(rootsite, true, fMakeVisible); if (vwsel != null) return vwsel; } // If we can't find a selection try to create a selection at the end of the // current paragraph. IchAnchor = 0; IVwSelection sel = SetSelection(rootsite, false, false); if (sel == null) return null; bool fAssocPrev; int hvoObj, tag, ws, ich; ITsString tss; sel.TextSelInfo(false, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out ws); if (tss != null) IchAnchor = tss.Length; return SetSelection(rootsite, true, fMakeVisible, VwScrollSelOpts.kssoDefault); }