28#include <rtl/ustring.hxx>
29#include <com/sun/star/text/RubyAdjust.hpp>
30#include <com/sun/star/i18n/XBreakIterator.hpp>
31#include <osl/diagnose.h>
61class SwKeepConversionDirectionStateContext
64 SwKeepConversionDirectionStateContext()
72 ~SwKeepConversionDirectionStateContext()
82 const uno::Reference< uno::XComponentContext >& rxContext,
86 sal_Int32 nConvOptions,
88 bool bStart,
bool bOther,
bool bSelection )
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;
182 o3tl::narrowing<sal_uInt16>(
m_nUnitOffset + nUnitStart),
true );
185 o3tl::narrowing<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 std::u16string_view aOrigText,
211 const uno::Sequence< sal_Int32 > *pOffsets,
217 OSL_ENSURE( !rNewText.isEmpty(),
"unexpected empty string" );
218 if (rNewText.isEmpty())
221 if (pOffsets && pCursor)
228 const sal_Int32 nIndices = pOffsets->getLength();
229 const sal_Int32 *pIndices = pOffsets->getConstArray();
230 sal_Int32 nConvTextLen = rNewText.getLength();
232 sal_Int32 nChgPos = -1;
233 sal_Int32 nChgLen = 0;
234 sal_Int32 nConvChgPos = -1;
235 sal_Int32 nConvChgLen = 0;
242 OSL_ENSURE(nIndices == 0 || nIndices == nConvTextLen,
243 "mismatch between string length and sequence length!" );
250 if (
nPos < nConvTextLen)
255 nIndex = aOrigText.size();
258 if (
nPos == nConvTextLen ||
262 if (nChgPos != -1 && nConvChgPos != -1)
264 nChgLen =
nIndex - nChgPos;
265 nConvChgLen =
nPos - nConvChgPos;
266 OUString aInNew( rNewText.copy( nConvChgPos, nConvChgLen ) );
269 sal_Int32 nChgInNodeStartIndex = nStartIndex + nCorrectionOffset + nChgPos;
279 nCorrectionOffset += nConvChgLen - nChgLen;
288 if (nChgPos == -1 && nConvChgPos == -1)
294 if (
nPos >= nConvTextLen)
347 const sal_Int32 nUnitStart,
const sal_Int32 nUnitEnd,
348 const OUString& rOrigText,
349 const OUString& rReplaceWith,
350 const uno::Sequence< sal_Int32 > &rOffsets,
354 OSL_ENSURE( nUnitStart >= 0 && nUnitEnd >= nUnitStart,
"wrong arguments" );
355 if (nUnitStart < 0 || nUnitEnd < nUnitStart)
367 OUString aNewText( rReplaceWith );
368 OSL_ENSURE( aOrigText == rOrigText,
"!! text mismatch !!" );
369 std::unique_ptr<SwFormatRuby> pRuby;
370 bool bRubyBelow =
false;
371 OUString aNewOrigText;
378 aNewText = aOrigText +
"(" + rReplaceWith +
")";
383 aNewText = rReplaceWith +
"(" + aOrigText +
")";
394 aNewOrigText = rReplaceWith;
406 aNewOrigText = rReplaceWith;
411 OSL_FAIL(
"unexpected case" );
418 if (!aNewOrigText.isEmpty())
422 ChangeText( aNewOrigText, rOrigText,
nullptr,
nullptr );
436 pRuby->SetPosition( o3tl::narrowing<sal_uInt16>(bRubyBelow) );
437 pRuby->SetAdjustment( RubyAdjust_CENTER );
451 if (bIsChineseConversion)
454 ChangeText( aNewText, rOrigText,
nullptr,
nullptr );
457 if (bIsChineseConversion)
463 "SwHHCWrapper::ReplaceUnit : unexpected target language" );
469 if (pNewUnitLanguage)
475 OSL_ENSURE( pTargetFont,
"target font missing?" );
476 if (pTargetFont && pNewUnitLanguage)
484 aSet.Put( aFontItem );
505 OSL_ENSURE(
m_pConvArgs ==
nullptr,
"NULL pointer expected" );
508 auto [pSttPos, pEndPos] = pCursor->
StartEnd();
510 if (pSttPos->GetNode().IsTextNode() &&
511 pEndPos->GetNode().IsTextNode())
530 "failed to get proper start text node" );
532 "failed to get proper end text node" );
536 "source and target language mismatch?" );
541 m_pConvArgs->bAllowImplicitChangesForNotConvertibleText =
true;
558 sal_Int32 nStartIdx = -1;
563 OUString aText(
m_pConvArgs->pStartPos->GetNode().GetTextNode()->GetText() );
567 WordType::DICTIONARY_WORD,
true ) );
570 if (aBoundary.startPos < aText.getLength() &&
571 aBoundary.startPos != aBoundary.endPos)
573 nStartIdx = aBoundary.startPos;
677 return !pConversionArgs->
aConvText.isEmpty();
void StartTextConversion()
vcl::Window * GetWindow() const
void SetStyleName(const OUString &rStyleName)
void SetFamily(FontFamily _eFamily)
void SetPitch(FontPitch _ePitch)
void SetFamilyName(const OUString &rFamilyName)
void SetCharSet(rtl_TextEncoding _eEncoding)
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
const css::lang::Locale & GetLocale(const LanguageType aLang)
SwCursor * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
OUString GetSelText() const
get selected text of a node at current cursor
SwDoc * GetDoc()
returns Doc. But be careful!
void SetDefault(const SfxPoolItem &)
Set attribute as new default attribute in current document.
bool GetCurAttr(SfxItemSet &, const bool bMergeIndentValuesOfNumRule=false) const
void StartAllAction()
For all views of this document.
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
bool Delete(bool isArtificialSelection=false)
Delete content of all ranges.
void SetAttrItem(const SfxPoolItem &, SetAttrMode nFlags=SetAttrMode::DEFAULT, const bool bParagraphSetting=false)
void SetAttrSet(const SfxItemSet &, SetAttrMode nFlags=SetAttrMode::DEFAULT, SwPaM *pCursor=nullptr, const bool bParagraphSetting=false)
css::uno::Any SpellContinue(sal_uInt16 *pPageCnt, sal_uInt16 *pPageSt, SwConversionArgs const *pConvArgs)
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
bool HasOtherCnt() const
Are there frames, footnotes, etc.
void ResetAttr(const o3tl::sorted_vector< sal_uInt16 > &attrs=o3tl::sorted_vector< sal_uInt16 >(), SwPaM *pCursor=nullptr)
size_t IsObjSelected() const
void ChangeText_impl(const OUString &rNewText, bool bKeepAttributes)
virtual bool HasRubySupport() const override
sal_uInt16 m_nPageCount
page count for progress bar
void SelectNewUnit_impl(const sal_Int32 nUnitStart, const sal_Int32 nUnitEnd)
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
virtual void HandleNewUnit(const sal_Int32 nUnitStart, const sal_Int32 nUnitEnd) override
virtual void GetNextPortion(OUString &rNextPortion, LanguageType &rLangOfPortion, bool bAllowImplicitChangesForNotConvertibleText) override
void ConvEnd_impl(SwConversionArgs const *pConvArgs)
former SpellEnd
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)
bool m_bIsSelection
true if only the selected text should be converted
bool ConvContinue_impl(SwConversionArgs *pConvArgs)
former SpellContinue
void ChangeText(const OUString &rNewText, std::u16string_view aOrigText, const css::uno::Sequence< sal_Int32 > *pOffsets, SwPaM *pCursor)
sal_Int32 m_nLastPos
starting position of the last found text part (needs to be sth that gets not moved like SwPaM or SwPo...
void ConvStart_impl(SwConversionArgs *pConvArgs, SvxSpellArea eSpell)
former SpellStart
void FindConvText_impl()
former FindSpellError
bool ConvNext_impl()
from SvxSpellWrapper copied and modified
std::unique_ptr< SwConversionArgs > m_pConvArgs
object for arguments (and results) needed to find of next convertible text portion
virtual ~SwHHCWrapper() COVERITY_NOEXCEPT_FALSE override
sal_uInt16 m_nPageStart
first checked page
Base class of the Writer document model elements.
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
PaM is Point and Mark: a selection of the document model.
const SwPosition * GetMark() const
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
std::pair< const SwPosition *, const SwPosition * > StartEnd() const
Because sometimes the cost of the operator<= can add up.
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
const SwPosition * GetPoint() const
const SwPosition * Start() const
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
SwTextNode is a paragraph in the document model.
static void SetCareDialog(const std::shared_ptr< weld::Window > &rNew)
const SfxItemPool & GetAttrPool() const
SwWrtShell & GetWrtShell() const
SAL_DLLPRIVATE void SpellStart(SvxSpellArea eSpell, bool bStartDone, bool bEndDone, SwConversionArgs *pConvArgs)
SwDocShell * GetDocShell()
SAL_DLLPRIVATE void SpellEnd(SwConversionArgs const *pConvArgs)
Used by the UI to modify the document model.
bool IsSelFrameMode() const
bool Right(SwCursorSkipMode nMode, bool bSelect, sal_uInt16 nCount, bool bBasicCall, bool bVisual=false)
bool Left(SwCursorSkipMode nMode, bool bSelect, sal_uInt16 nCount, bool bBasicCall, bool bVisual=false)
void Insert(const OUString &)
const vcl::Font * GetTargetFont() const
weld::Widget * GetUIParent() const
static void SetUseSavedConversionDirectionState(bool bVal)
bool IsInteractive() const
LanguageType GetSourceLanguage() const
static bool IsChinese(LanguageType nLang)
sal_Int32 GetConversionOptions() const
LanguageType GetTargetLanguage() const
FontFamily GetFamilyType()
const OUString & GetStyleName() const
const OUString & GetFamilyName() const
rtl_TextEncoding GetCharSet() const
void SetCursor(vcl::Cursor *pCursor)
vcl::Cursor * GetCursor() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
static void lcl_ActivateTextShell(SwWrtShell &rWrtSh)
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CJK_FONT(22)
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_CJK_LANGUAGE(24)
#define LANGUAGE_CHINESE_TRADITIONAL
#define LANGUAGE_CHINESE_SIMPLIFIED
void EndProgress(SwDocShell const *pDocShell)
bool GoInDoc(SwPaM &rPam, SwMoveFnCollection const &fnMove)
SwMoveFnCollection const & fnMoveBackward
LanguageType nConvTextLang
Marks a position in the document model.
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
sal_Int32 GetContentIndex() const
void AdjustContent(sal_Int32 nDelta)
Adjust content index, only valid to call this if the position points to a SwContentNode subclass.