28 #include <rtl/ustring.hxx>
29 #include <com/sun/star/text/RubyAdjust.hpp>
30 #include <com/sun/star/i18n/XBreakIterator.hpp>
60 class SwKeepConversionDirectionStateContext
63 SwKeepConversionDirectionStateContext()
71 ~SwKeepConversionDirectionStateContext()
81 const uno::Reference< uno::XComponentContext >& rxContext,
85 sal_Int32 nConvOptions,
87 bool bStart,
bool bOther,
bool bSelection )
95 , m_pWin( &pSwView->GetEditWin() )
96 , m_rWrtShell( pSwView->GetWrtShell() )
101 , m_bIsDrawObj( false )
102 , m_bIsOtherContent( bOther )
103 , m_bStartChk( bOther )
104 , m_bIsSelection( bSelection )
105 , m_bStartDone( bOther || bStart )
106 , m_bEndDone( false )
123 SwKeepConversionDirectionStateContext aContext;
158 OUString& rNextPortion,
162 m_pConvArgs->bAllowImplicitChangesForNotConvertibleText = bAllowChanges;
185 static_cast<sal_uInt16>(nUnitEnd - nUnitStart),
true );
193 const sal_Int32 nUnitStart,
const sal_Int32 nUnitEnd )
195 OSL_ENSURE( nUnitStart >= 0 && nUnitEnd >= nUnitStart,
"wrong arguments" );
196 if (0 > nUnitStart || nUnitStart > nUnitEnd)
210 const OUString& rOrigText,
211 const uno::Sequence< sal_Int32 > *pOffsets,
217 OSL_ENSURE( !rNewText.isEmpty(),
"unexpected empty string" );
218 if (rNewText.isEmpty())
221 if (pOffsets && pCursor)
229 const sal_Int32 nIndices = pOffsets->getLength();
230 const sal_Int32 *pIndices = pOffsets->getConstArray();
231 sal_Int32 nConvTextLen = rNewText.getLength();
233 sal_Int32 nChgPos = -1;
234 sal_Int32 nChgLen = 0;
235 sal_Int32 nConvChgPos = -1;
236 sal_Int32 nConvChgLen = 0;
243 OSL_ENSURE(nIndices == 0 || nIndices == nConvTextLen,
244 "mismatch between string length and sequence length!" );
251 if (nPos < nConvTextLen)
252 nIndex = nPos < nIndices ? pIndices[nPos] : nPos;
256 nIndex = rOrigText.getLength();
259 if (nPos == nConvTextLen ||
260 rOrigText[nIndex] == rNewText[nPos])
263 if (nChgPos != -1 && nConvChgPos != -1)
265 nChgLen = nIndex - nChgPos;
266 nConvChgLen = nPos - nConvChgPos;
267 OUString aInNew( rNewText.copy( nConvChgPos, nConvChgLen ) );
270 sal_Int32 nChgInNodeStartIndex = nStartIndex + nCorrectionOffset + nChgPos;
280 nCorrectionOffset += nConvChgLen - nChgLen;
289 if (nChgPos == -1 && nConvChgPos == -1)
295 if (nPos >= nConvTextLen)
317 sal_uInt16
const aRanges[] {
351 const sal_Int32 nUnitStart,
const sal_Int32 nUnitEnd,
352 const OUString& rOrigText,
353 const OUString& rReplaceWith,
354 const uno::Sequence< sal_Int32 > &rOffsets,
358 OSL_ENSURE( nUnitStart >= 0 && nUnitEnd >= nUnitStart,
"wrong arguments" );
359 if (nUnitStart < 0 || nUnitEnd < nUnitStart)
371 OUString aNewText( rReplaceWith );
372 OSL_ENSURE( aOrigText == rOrigText,
"!! text mismatch !!" );
373 std::unique_ptr<SwFormatRuby> pRuby;
374 bool bRubyBelow =
false;
375 OUString aNewOrigText;
382 aNewText = aOrigText +
"(" + rReplaceWith +
")";
387 aNewText = rReplaceWith +
"(" + aOrigText +
")";
398 aNewOrigText = rReplaceWith;
410 aNewOrigText = rReplaceWith;
415 OSL_FAIL(
"unexpected case" );
422 if (!aNewOrigText.isEmpty())
426 ChangeText( aNewOrigText, rOrigText,
nullptr,
nullptr );
440 pRuby->SetPosition( static_cast<sal_uInt16>(bRubyBelow) );
441 pRuby->SetAdjustment( RubyAdjust_CENTER );
455 if (bIsChineseConversion)
458 ChangeText( aNewText, rOrigText,
nullptr,
nullptr );
461 if (bIsChineseConversion)
467 "SwHHCWrapper::ReplaceUnit : unexpected target language" );
469 sal_uInt16
const aRanges[] {
475 if (pNewUnitLanguage)
481 OSL_ENSURE( pTargetFont,
"target font missing?" );
482 if (pTargetFont && pNewUnitLanguage)
488 aFontItem.SetPitch( pTargetFont->
GetPitch());
489 aFontItem.SetCharSet( pTargetFont->
GetCharSet() );
490 aSet.Put( aFontItem );
511 OSL_ENSURE(
m_pConvArgs ==
nullptr,
"NULL pointer expected" );
541 "failed to get proper start text node" );
543 "failed to get proper end text node" );
547 "source and target language mismatch?" );
552 m_pConvArgs->bAllowImplicitChangesForNotConvertibleText =
true;
569 sal_Int32 nStartIdx = -1;
574 OUString aText(
m_pConvArgs->pStartNode->GetText() );
578 WordType::DICTIONARY_WORD, true ) );
581 if (aBoundary.startPos < aText.getLength() &&
582 aBoundary.startPos != aBoundary.endPos)
584 nStartIdx = aBoundary.startPos;
689 return !pConversionArgs->
aConvText.isEmpty();
void ChangeText_impl(const OUString &rNewText, bool bKeepAttributes)
bool Right(sal_uInt16 nMode, bool bSelect, sal_uInt16 nCount, bool bBasicCall, bool bVisual=false)
Marks a position in the document model.
const OUString & GetFamilyName() const
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
const OUString & GetStyleName() const
SAL_DLLPRIVATE void SpellStart(SvxSpellArea eSpell, bool bStartDone, bool bEndDone, SwConversionArgs *pConvArgs)
const SwPosition * GetMark() const
void SetAttrSet(const SfxItemSet &, SetAttrMode nFlags=SetAttrMode::DEFAULT, SwPaM *pCursor=nullptr, const bool bParagraphSetting=false)
void ConvEnd_impl(SwConversionArgs const *pConvArgs)
former SpellEnd
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
void EndProgress(SwDocShell const *pDocShell)
FontFamily GetFamilyType()
SwWrtShell & GetWrtShell() const
void SetFamilyName(const OUString &rFamilyName)
Used by the UI to modify the document model.
sal_Int32 m_nLastPos
starting position of the last found text part (needs to be sth that gets not moved like SwPaM or SwPo...
SwHHCWrapper(SwView *pView, const css::uno::Reference< css::uno::XComponentContext > &rxContext, LanguageType nSourceLanguage, LanguageType nTargetLanguage, const vcl::Font *pTargetFont, sal_Int32 nConvOptions, bool bIsInteractive, bool bStart, bool bOther, bool bSelection)
virtual void GetNextPortion(OUString &rNextPortion, LanguageType &rLangOfPortion, bool bAllowImplicitChangesForNotConvertibleText) override
bool ConvNext_impl()
from SvxSpellWrapper copied and modified
static void lcl_ActivateTextShell(SwWrtShell &rWrtSh)
void Insert(SwField const &, SwPaM *pAnnotationRange=nullptr)
void FindConvText_impl()
former FindSpellError
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
LanguageType GetSourceLanguage() const
SwDoc * GetDoc()
returns Doc. But be careful!
PaM is Point and Mark: a selection of the document model.
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
const SfxItemPool & GetAttrPool() const
LanguageType nConvTextLang
bool HasOtherCnt() const
Are there frames, footnotes, etc.
virtual bool HasRubySupport() const override
sal_uInt16 m_nPageStart
first checked page
void SelectNewUnit_impl(const sal_Int32 nUnitStart, const sal_Int32 nUnitEnd)
const SwPosition * GetPoint() const
SwIndex & Assign(SwIndexReg *, sal_Int32)
void SetAttrItem(const SfxPoolItem &, SetAttrMode nFlags=SetAttrMode::DEFAULT, const bool bParagraphSetting=false)
static bool IsChinese(LanguageType nLang)
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
sal_Int32 GetConversionOptions() const
css::uno::Any SpellContinue(sal_uInt16 *pPageCnt, sal_uInt16 *pPageSt, SwConversionArgs const *pConvArgs)
const vcl::Font * GetTargetFont() const
VclPtr< vcl::Window > m_pWin
#define LANGUAGE_CHINESE_SIMPLIFIED
vcl::Cursor * GetCursor() const
Marks a node in the document model.
bool GoInDoc(SwPaM &rPam, SwMoveFnCollection const &fnMove)
void ConvStart_impl(SwConversionArgs *pConvArgs, SvxSpellArea eSpell)
former SpellStart
const SwPosition * Start() const
SwDocShell * GetDocShell()
bool Delete()
Delete content of all ranges.
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
void StartTextConversion()
virtual void HandleNewUnit(const sal_Int32 nUnitStart, const sal_Int32 nUnitEnd) override
void ResetAttr(const o3tl::sorted_vector< sal_uInt16 > &attrs=o3tl::sorted_vector< sal_uInt16 >(), SwPaM *pCursor=nullptr)
constexpr sal_uInt16 RES_FRMATR_END(131)
const css::lang::Locale & GetLocale(const LanguageType aLang)
void SetDefault(const SfxPoolItem &)
Set attribute as new default attribute in current document.
SwTextNode is a paragraph in the document model.
constexpr sal_uInt16 RES_CHRATR_BEGIN(HINT_BEGIN)
static void SetCareDialog(const std::shared_ptr< weld::Window > &rNew)
bool Left(sal_uInt16 nMode, bool bSelect, sal_uInt16 nCount, bool bBasicCall, bool bVisual=false)
void SetCursor(vcl::Cursor *pCursor)
OUString GetSelText() const
get selected text of a node at current cursor
sal_Int32 GetIndex() const
LanguageType GetTargetLanguage() const
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CJK_FONT(22)
const SwPosition * End() const
size_t IsObjSelected() const
virtual ~SwHHCWrapper() override
sal_uInt16 m_nPageCount
page count for progress bar
vcl::Window * GetWindow() const
void ChangeText(const OUString &rNewText, const OUString &rOrigText, const css::uno::Sequence< sal_Int32 > *pOffsets, SwPaM *pCursor)
bool GetCurAttr(SfxItemSet &, const bool bMergeIndentValuesOfNumRule=false) const
SwMoveFnCollection const & fnMoveBackward
const sal_uInt16 CRSR_SKIP_CHARS
#define LANGUAGE_CHINESE_TRADITIONAL
bool ConvContinue_impl(SwConversionArgs *pConvArgs)
former SpellContinue
SAL_DLLPRIVATE void SpellEnd(SwConversionArgs const *pConvArgs)
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
bool m_bIsSelection
true if only the selected text should be converted
std::unique_ptr< SwConversionArgs > m_pConvArgs
object for arguments (and results) needed to find of next convertible text portion ...
virtual void ReplaceUnit(const sal_Int32 nUnitStart, const sal_Int32 nUnitEnd, const OUString &rOrigText, const OUString &rReplaceWith, const css::uno::Sequence< sal_Int32 > &rOffsets, ReplacementAction eAction, LanguageType *pNewUnitLanguage) override
void StartAllAction()
For all views of this document.
bool IsInteractive() const
static void SetUseSavedConversionDirectionState(bool bVal)
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_CJK_LANGUAGE(24)
rtl_TextEncoding GetCharSet() const
bool IsSelFrameMode() const
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Base class of the Writer document model elements.