/// ----------------------------------------------------------------------------------- /// <summary> /// Return an indication of the behavior of some of the special keys (arrows, home, /// end). /// </summary> /// <param name="chw">Key value</param> /// <param name="ss">Shift status</param> /// <returns>Return <c>0</c> for physical behavior, <c>1</c> for logical behavior. /// </returns> /// <remarks>Physical behavior means that left arrow key goes to the left regardless /// of the direction of the text; logical behavior means that left arrow key always /// moves the IP one character (possibly plus diacritics, etc.) in the underlying text, /// in the direction that is to the left for text in the main paragraph direction. /// So, in a normal LTR paragraph, left arrow decrements the IP position; in an RTL /// paragraph, it increments it. Both produce a movement to the left in text whose /// direction matches the paragraph ("downstream" text). But where there is a segment /// of upstream text, logical behavior will jump almost to the other end of the /// segment and then move the 'wrong' way through it. /// </remarks> /// ----------------------------------------------------------------------------------- public virtual EditingHelper.CkBehavior ComplexKeyBehavior(int chw, VwShiftStatus ss) { CheckDisposed(); return EditingHelper.CkBehavior.Logical; }
/// ----------------------------------------------------------------------------------- /// <summary> /// If user presses Enter and a new style is applied to the following paragraph, we /// need to mark that style as being in use. If in a section Head, we might need to fix /// the structure. /// </summary> /// <param name="fCalledFromKeyDown">True if this method gets called from OnKeyDown</param> /// <param name="stuInput">input string</param> /// <param name="cchBackspace">number of backspace characters in stuInput</param> /// <param name="cchDelForward">number of delete characters in stuInput</param> /// <param name="ss">Status of Shift/Control/Alt key</param> /// <param name="graphics">graphics for processing input</param> /// <param name="modifiers">key modifiers - shift status, etc.</param> /// <remarks>I (EberhardB) added the parameter <paramref name="fCalledFromKeyDown"/> /// to be able to distinguish between Ctrl-Delete and Ctrl-Backspace.</remarks> /// ----------------------------------------------------------------------------------- protected void HandleEnterKey(bool fCalledFromKeyDown, string stuInput, int cchBackspace, int cchDelForward, VwShiftStatus ss, IVwGraphics graphics, Keys modifiers) { if (IsPictureSelected) // Enter should do nothing if a picture or caption is selected. return; SelLevInfo[] levInfo; // If we are at the end of a heading paragraph, we need to check the "next" style to // see if it is a body type. If it is not, then allow processing to proceed as normal. // If it is a body type, then don't create a new paragraph, just move down to the start // of the first body paragraph in the section. if (InSectionHead) { // if the selection is a range selection then try to delete the selected text first. if (CurrentSelection.Selection.IsRange) { ITsStrFactory factory = TsStrFactoryClass.Create(); CurrentSelection.Selection.ReplaceWithTsString( factory.MakeString("", m_cache.DefaultVernWs)); // If selection is still a range selection, the deletion failed and we don't // need to do anything else. if (CurrentSelection.Selection.IsRange || !InSectionHead) return; } // If the heading style has a following style that is a body style and we are at the // end of the paragraph then move the IP to the beginning of the body paragraph. levInfo = CurrentSelection.GetLevelInfo(SelectionHelper.SelLimitType.Anchor); // This is the paragraph that was originally selected ScrTxtPara headPara = new ScrTxtPara(m_cache, levInfo[0].hvo); IStStyle headParaStyle = m_scr.FindStyle(headPara.StyleName); IStStyle followStyle = headParaStyle != null ? headParaStyle.NextRA : null; if (followStyle != null && followStyle.Structure == StructureValues.Body && SelectionAtEndParagraph()) { // if there is another section head paragraph, then the section needs to be split ScrSection section = new ScrSection(m_cache, ((ITeView)Control).LocationTracker.GetSectionHvo(CurrentSelection, SelectionHelper.SelLimitType.Anchor)); if (CurrentSelection.LevelInfo[0].ihvo < section.HeadingOA.ParagraphsOS.Count - 1) { // Setting the style rules destroys the selection, so we have to remember // the current location before we change the style rules. int iBook = BookIndex; int iSection = SectionIndex; // break the section // create a new empty paragraph in the first section // set the IP to the start of the new paragraph CreateSection(BCVRef.GetVerseFromBcv(section.VerseRefMin) == 0); Debug.Assert(CurrentSelection != null && CurrentSelection.IsValid, "Creating the section didn't set a selection"); StTxtPara contentPara = new StTxtPara(m_cache, CurrentSelection.LevelInfo[0].hvo); contentPara.StyleRules = StyleUtils.ParaStyleTextProps(followStyle.Name); SetInsertionPoint(iBook, iSection, 0, 0, false); } else { SetInsertionPoint(BookIndex, SectionIndex, 0, 0, false); // If the first paragraph is not empty, then insert a new paragraph with the // follow-on style of the section head. StTxtPara contentPara = new StTxtPara(m_cache, CurrentSelection.LevelInfo[0].hvo); if (contentPara.Contents.Length > 0) { StTxtParaBldr bldr = new StTxtParaBldr(m_cache); bldr.ParaProps = StyleUtils.ParaStyleTextProps(followStyle.Name); bldr.AppendRun(String.Empty, StyleUtils.CharStyleTextProps(null, m_cache.DefaultVernWs)); bldr.CreateParagraph(contentPara.OwnerHVO, 0); SetInsertionPoint(BookIndex, SectionIndex, 0, 0, false); } } return; } } // Call the base to handle the key base.OnCharAux('\r', fCalledFromKeyDown, stuInput, cchBackspace, cchDelForward, ss, graphics, modifiers); try { levInfo = CurrentSelection.GetLevelInfo(SelectionHelper.SelLimitType.Anchor); ScrTxtPara para = new ScrTxtPara(m_cache, levInfo[0].hvo); IStStyle style = m_scr.FindStyle(para.StyleName); if (style != null) style.InUse = true; } catch { // Oh, well. We tried. } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Handle typed character /// </summary> /// <param name="stuInput">input string</param> /// <param name="ss">Status of Shift/Control/Alt key</param> /// <param name="modifiers">key modifiers - shift status, etc.</param> /// ----------------------------------------------------------------------------------- protected override void OnCharAux(string stuInput, VwShiftStatus ss, Keys modifiers) { if (string.IsNullOrEmpty(stuInput)) { return; } SelectionHelper currSel = CurrentSelection; if (modifiers != Keys.Control && modifiers != Keys.Alt && currSel != null) { ITsTextProps ttpTop = currSel.GetSelProps(SelectionHelper.SelLimitType.Top); if (ttpTop != null) { string sObjData = ttpTop.GetStrPropValue((int)FwTextPropType.ktptObjData); string urlTop = TsStringUtils.GetURL(sObjData); if (urlTop != null) { ITsTextProps ttpBottom = currSel.GetSelProps(SelectionHelper.SelLimitType.Bottom); if (ttpBottom != null) { sObjData = ttpBottom.GetStrPropValue((int)FwTextPropType.ktptObjData); string urlBottom = TsStringUtils.GetURL(sObjData); if (urlBottom != urlTop) { int nVar; ITsTextProps propsToUse = StyleUtils.CharStyleTextProps(null, ttpTop.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar)); currSel.Selection.SetTypingProps(propsToUse); } else if (stuInput[0] == (char)VwSpecialChars.kscDelForward || stuInput[0] == (char)VwSpecialChars.kscBackspace) { if (currSel.IsRange) { ITsTextProps ttpBefore = currSel.PropsBefore; string urlBefore = (ttpBefore == null) ? null : TsStringUtils.GetURL(ttpBefore.GetStrPropValue((int)FwTextPropType.ktptObjData)); ITsTextProps ttpAfter = currSel.PropsAfter; string urlAfter = (ttpAfter == null) ? null : TsStringUtils.GetURL(ttpAfter.GetStrPropValue((int)FwTextPropType.ktptObjData)); if (urlBefore != urlTop && urlAfter != urlTop) { int nVar; ITsTextProps propsToUse = ttpBefore ?? StyleUtils.CharStyleTextProps(null, ttpTop.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar)); currSel.Selection.SetTypingProps(propsToUse); } } } else if (!currSel.IsRange) { ITsTextProps ttpBefore = currSel.PropsBefore; string urlBefore = (ttpBefore == null) ? null : TsStringUtils.GetURL(ttpBefore.GetStrPropValue((int)FwTextPropType.ktptObjData)); if (urlBefore != urlTop) { int nVar; ITsTextProps propsToUse = ttpBefore ?? StyleUtils.CharStyleTextProps(null, ttpTop.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar)); currSel.Selection.SetTypingProps(propsToUse); } else { ITsTextProps ttpAfter = currSel.PropsAfter; string urlAfter = (ttpAfter == null) ? null : TsStringUtils.GetURL(ttpAfter.GetStrPropValue((int)FwTextPropType.ktptObjData)); if (urlAfter != urlBottom) { int nVar; ITsTextProps propsToUse = ttpAfter ?? StyleUtils.CharStyleTextProps(null, ttpTop.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar)); currSel.Selection.SetTypingProps(propsToUse); } } } } } } } base.OnCharAux(stuInput, ss, modifiers); }
/// <summary> /// Override to suppress tab key. The default implementation is designed to move between /// 'fields' by finding a subsequent selection in a different property. All the text in /// TE is in the same property, so it searches the whole document, which is very slow. /// See TE-8117 for other possible behaviors we might implement one day. /// </summary> protected override bool CallOnExtendedKey(int chw, VwShiftStatus ss) { if (chw == 9) // tab return false; return base.CallOnExtendedKey(chw, ss); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Enter, Delete, and Backspace require special handling in TE. /// </summary> /// <param name="ch">Typed character</param> /// <param name="fCalledFromKeyDown">True if this method gets called from OnKeyDown</param> /// <param name="stuInput">input string</param> /// <param name="cchBackspace">number of backspace characters in stuInput</param> /// <param name="cchDelForward">number of delete characters in stuInput</param> /// <param name="ss">Status of Shift/Control/Alt key</param> /// <param name="graphics">graphics for processing input</param> /// <param name="modifiers">key modifiers - shift status, etc.</param> /// <remarks>I (EberhardB) added the parameter <paramref name="fCalledFromKeyDown"/> /// to be able to distinguish between Ctrl-Delete and Ctrl-Backspace.</remarks> /// ----------------------------------------------------------------------------------- protected override void OnCharAux(char ch, bool fCalledFromKeyDown, string stuInput, int cchBackspace, int cchDelForward, VwShiftStatus ss, IVwGraphics graphics, Keys modifiers) { if (ch == '\r') { if (IsBackTranslation) GoToNextPara(); else HandleEnterKey(fCalledFromKeyDown, stuInput, cchBackspace, cchDelForward, ss, graphics, modifiers); return; } // Call the base to handle the key base.OnCharAux(ch, fCalledFromKeyDown, stuInput, cchBackspace, cchDelForward, ss, graphics, modifiers); if ((ch == 8 || ch == 127) && IsPictureReallySelected && CanDelete()) DeletePicture(); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Enter, Delete, and Backspace require special handling in TE. /// </summary> /// <param name="stuInput">input string</param> /// <param name="ss">Status of Shift/Control/Alt key</param> /// <param name="modifiers">key modifiers - shift status, etc.</param> /// ----------------------------------------------------------------------------------- protected override void OnCharAux(string stuInput, VwShiftStatus ss, Keys modifiers) { if (string.IsNullOrEmpty(stuInput)) return; if (stuInput[0] == '\r') { if ((IsBackTranslation || InBookTitle) && ss != VwShiftStatus.kfssShift) GoToNextPara(); else HandleEnterKey(stuInput, ss, modifiers); return; } // Call the base to handle the key base.OnCharAux(stuInput, ss, modifiers); if ((stuInput[0] == 8 || stuInput[0] == 127) && IsPictureReallySelected && CanDelete()) DeletePicture(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Special handling for Ctrl-Home/End and scrolling the selection into view /// </summary> /// <param name="e"></param> /// <param name="ss"></param> /// ------------------------------------------------------------------------------------ protected override void HandleKeyDown(KeyEventArgs e, VwShiftStatus ss) { // We dealt with Ctrl-Home/End already in OnKeyDown, so we just make sure that the // selection is visible here. PubControl.ScrollSelectionIntoView(null, VwScrollSelOpts.kssoDefault); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Overridden version of HandleKeyDown to get an undo task around key strokes that /// would change the database. /// </summary> /// <param name="e">key pressed</param> /// <param name="ss">whether control and/or shift is pressed along with key pressed</param> /// ----------------------------------------------------------------------------------- protected override void HandleKeyDown(KeyEventArgs e, VwShiftStatus ss) { base.HandleKeyDown(e, ss); string stUndo; string stRedo; ResourceHelper.MakeUndoRedoLabels("kstidUndoTyping", out stUndo, out stRedo); if (e.KeyValue == (char)Keys.Return) { stUndo = string.Format(stUndo, "LSEP"); stRedo = string.Format(stRedo, "LSEP"); } // The action handler can be null if we're using SimpleRootSite as a // textbox that is not connected to a BEP. IActionHandler actionHandler = EditedRootBox.DataAccess.GetActionHandler(); UndoTaskHelper undoHelper = (actionHandler != null && actionHandler.CurrentDepth == 0) ? new UndoTaskHelper(EditedRootBox.Site, stUndo, stRedo) : null; try { if (e.Shift && e.KeyValue == (int)Keys.Return) CallOnTyping("\u2028", Keys.None); // type a line separator if (undoHelper != null) undoHelper.RollBack = false; } finally { if (undoHelper != null) undoHelper.Dispose(); } }
/// <summary/> public void OnTyping(IVwGraphics _vg, string bstrInput, VwShiftStatus ss, ref int _wsPending) { throw new NotImplementedException(); }
public void OnTyping(IVwGraphics _vg, string bstrInput, VwShiftStatus ss, ref int _wsPending) { throw new NotImplementedException(); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Handle typed character /// </summary> /// <param name="stuInput">input string</param> /// <param name="ss">Status of Shift/Control/Alt key</param> /// <param name="modifiers">key modifiers - shift status, etc.</param> /// ----------------------------------------------------------------------------------- protected override void OnCharAux(string stuInput, VwShiftStatus ss, Keys modifiers) { if (string.IsNullOrEmpty(stuInput)) return; SelectionHelper currSel = CurrentSelection; if (modifiers != Keys.Control && modifiers != Keys.Alt && currSel != null) { ITsTextProps ttpTop = currSel.GetSelProps(SelectionHelper.SelLimitType.Top); if (ttpTop != null) { string sObjData = ttpTop.GetStrPropValue((int)FwTextPropType.ktptObjData); string urlTop = TsStringUtils.GetURL(sObjData); if (urlTop != null) { ITsTextProps ttpBottom = currSel.GetSelProps(SelectionHelper.SelLimitType.Bottom); if (ttpBottom != null) { sObjData = ttpBottom.GetStrPropValue((int)FwTextPropType.ktptObjData); string urlBottom = TsStringUtils.GetURL(sObjData); if (urlBottom != urlTop) { int nVar; ITsTextProps propsToUse = StyleUtils.CharStyleTextProps(null, ttpTop.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar)); currSel.Selection.SetTypingProps(propsToUse); } else if (stuInput[0] == (char)VwSpecialChars.kscDelForward || stuInput[0] == (char)VwSpecialChars.kscBackspace) { if (currSel.IsRange) { ITsTextProps ttpBefore = currSel.PropsBefore; string urlBefore = (ttpBefore == null) ? null : TsStringUtils.GetURL(ttpBefore.GetStrPropValue((int)FwTextPropType.ktptObjData)); ITsTextProps ttpAfter = currSel.PropsAfter; string urlAfter = (ttpAfter == null) ? null : TsStringUtils.GetURL(ttpAfter.GetStrPropValue((int)FwTextPropType.ktptObjData)); if (urlBefore != urlTop && urlAfter != urlTop) { int nVar; ITsTextProps propsToUse = ttpBefore ?? StyleUtils.CharStyleTextProps(null, ttpTop.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar)); currSel.Selection.SetTypingProps(propsToUse); } } } else if (!currSel.IsRange) { ITsTextProps ttpBefore = currSel.PropsBefore; string urlBefore = (ttpBefore == null) ? null : TsStringUtils.GetURL(ttpBefore.GetStrPropValue((int)FwTextPropType.ktptObjData)); if (urlBefore != urlTop) { int nVar; ITsTextProps propsToUse = ttpBefore ?? StyleUtils.CharStyleTextProps(null, ttpTop.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar)); currSel.Selection.SetTypingProps(propsToUse); } else { ITsTextProps ttpAfter = currSel.PropsAfter; string urlAfter = (ttpAfter == null) ? null : TsStringUtils.GetURL(ttpAfter.GetStrPropValue((int)FwTextPropType.ktptObjData)); if (urlAfter != urlBottom) { int nVar; ITsTextProps propsToUse = ttpAfter ?? StyleUtils.CharStyleTextProps(null, ttpTop.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar)); currSel.Selection.SetTypingProps(propsToUse); } } } } } } } base.OnCharAux(stuInput, ss, modifiers); }
public int OnExtendedKey(int chw, VwShiftStatus ss, int nFlags) { throw new NotImplementedException("The method or operation is not implemented."); }
/// <summary/> public int OnExtendedKey(int chw, VwShiftStatus ss, int nFlags) { throw new NotImplementedException(); }
/// ----------------------------------------------------------------------------------- /// <summary> /// If user presses Enter and a new style is applied to the following paragraph, we /// need to mark that style as being in use. If in a section Head, we might need to fix /// the structure. /// </summary> /// <param name="stuInput">input string</param> /// <param name="ss">Status of Shift/Control/Alt key</param> /// <param name="modifiers">key modifiers - shift status, etc.</param> /// ----------------------------------------------------------------------------------- protected void HandleEnterKey(string stuInput, VwShiftStatus ss, Keys modifiers) { if (IsPictureSelected) // Enter should do nothing if a picture or caption is selected. return; int defVernWs = m_cache.DefaultVernWs; SelLevInfo[] levInfo; // If we are at the end of a heading paragraph, we need to check the "next" style to // see if it is a body type. If it is not, then allow processing to proceed as normal. // If it is a body type, then don't create a new paragraph, just move down to the start // of the first body paragraph in the section. if (InSectionHead) { // if the selection is a range selection then try to delete the selected text first. if (CurrentSelection.Selection.IsRange) { levInfo = CurrentSelection.GetLevelInfo(SelectionHelper.SelLimitType.Top); ITsStrFactory factory = TsStrFactoryClass.Create(); CurrentSelection.Selection.ReplaceWithTsString( factory.MakeString(string.Empty, defVernWs)); // If selection is still a range selection, the deletion failed and we don't // need to do anything else. if (CurrentSelection == null || CurrentSelection.Selection.IsRange || !InSectionHead) return; } // If the heading style has a following style that is a body style and we are at the // end of the paragraph then move the IP to the beginning of the body paragraph. levInfo = CurrentSelection.GetLevelInfo(SelectionHelper.SelLimitType.Anchor); // This is the paragraph that was originally selected IStTxtPara headPara = m_repoScrTxtPara.GetObject(levInfo[0].hvo); IStStyle headParaStyle = m_scr.FindStyle(headPara.StyleName); IStStyle followStyle = headParaStyle != null ? headParaStyle.NextRA : null; if (followStyle != null && followStyle.Structure == StructureValues.Body && SelectionAtEndParagraph()) { // if there is another section head paragraph, then the section needs to be split IScrSection section = ((ITeView)Control).LocationTracker.GetSection(CurrentSelection, SelectionHelper.SelLimitType.Anchor); // Changes made to text will destroy the selection, so we have to remember // the current locations. int iBook = BookIndex; int iSection = SectionIndex; if (CurrentSelection.LevelInfo[0].ihvo < section.HeadingOA.ParagraphsOS.Count - 1) { // break the section // create a new empty paragraph in the first section // set the IP to the start of the new paragraph IScrSection newSection = CreateSection(BCVRef.GetVerseFromBcv(section.VerseRefMin) == 0); Debug.Assert(newSection != null, "Failed to create a new section"); IScrSection origSection = ((IScrBook) newSection.Owner).SectionsOS[iSection]; IStTxtPara contentPara = origSection.ContentOA[0]; contentPara.StyleRules = StyleUtils.ParaStyleTextProps(followStyle.Name); SetInsertionPoint(iBook, iSection, 0, 0, false); } else { SetInsertionPoint(iBook, iSection, 0, 0, false); // If the first paragraph is not empty, then insert a new paragraph with the // follow-on style of the section head. IStTxtPara contentPara = (IStTxtPara) section.ContentOA.ParagraphsOS[0]; if (contentPara.Contents.Length > 0) { StTxtParaBldr bldr = new StTxtParaBldr(m_cache); bldr.ParaStyleName = followStyle.Name; bldr.AppendRun(String.Empty, StyleUtils.CharStyleTextProps(null, defVernWs)); bldr.CreateParagraph((IStText)contentPara.Owner, 0); SetInsertionPoint(iBook, iSection, 0, 0, false); } } return; } } // Call the base to handle the key base.OnCharAux(stuInput, ss, modifiers); }
public void OnTyping(IVwGraphics _vg, string input, VwShiftStatus shiftStatus, ref int _wsPending) { const string BackSpace = "\b"; if (input == BackSpace) { if (this.Text.Length <= 0) return; m_dummySelection.Anchor -= 1; m_dummySelection.End -= 1; this.Text = this.Text.Substring(0, this.Text.Length - 1); return; } var ws = m_dummySimpleRootSite.WritingSystemFactory.UserWs; m_dummySelection.ReplaceWithTsString(TsStringHelper.MakeTSS(input, ws)); }
protected override void OnCharAux(string stuInput, VwShiftStatus ss, Keys modifiers) { if ((modifiers & Keys.Alt) != Keys.Alt && stuInput == "\r") stuInput = InnerFwTextBox.LineBreak; base.OnCharAux(stuInput, ss, modifiers); }
public int OnExtendedKey(int chw, VwShiftStatus ss, int nFlags) { throw new NotImplementedException(); }
public int OnExtendedKey(int chw, VwShiftStatus ss, int nFlags) { throw new Exception("The method or operation is not implemented."); }