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 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)
256 nIndex = rOrigText.getLength();
259 if (
nPos == nConvTextLen ||
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)
348 const sal_Int32 nUnitStart,
const sal_Int32 nUnitEnd,
349 const OUString& rOrigText,
350 const OUString& rReplaceWith,
351 const uno::Sequence< sal_Int32 > &rOffsets,
355 OSL_ENSURE( nUnitStart >= 0 && nUnitEnd >= nUnitStart,
"wrong arguments" );
356 if (nUnitStart < 0 || nUnitEnd < nUnitStart)
368 OUString aNewText( rReplaceWith );
369 OSL_ENSURE( aOrigText == rOrigText,
"!! text mismatch !!" );
370 std::unique_ptr<SwFormatRuby> pRuby;
371 bool bRubyBelow =
false;
372 OUString aNewOrigText;
379 aNewText = aOrigText +
"(" + rReplaceWith +
")";
384 aNewText = rReplaceWith +
"(" + aOrigText +
")";
395 aNewOrigText = rReplaceWith;
407 aNewOrigText = rReplaceWith;
412 OSL_FAIL(
"unexpected case" );
419 if (!aNewOrigText.isEmpty())
423 ChangeText( aNewOrigText, rOrigText,
nullptr,
nullptr );
437 pRuby->SetPosition( o3tl::narrowing<sal_uInt16>(bRubyBelow) );
438 pRuby->SetAdjustment( RubyAdjust_CENTER );
452 if (bIsChineseConversion)
455 ChangeText( aNewText, rOrigText,
nullptr,
nullptr );
458 if (bIsChineseConversion)
464 "SwHHCWrapper::ReplaceUnit : unexpected target language" );
470 if (pNewUnitLanguage)
476 OSL_ENSURE( pTargetFont,
"target font missing?" );
477 if (pTargetFont && pNewUnitLanguage)
485 aSet.Put( aFontItem );
506 OSL_ENSURE(
m_pConvArgs ==
nullptr,
"NULL pointer expected" );
536 "failed to get proper start text node" );
538 "failed to get proper end text node" );
542 "source and target language mismatch?" );
547 m_pConvArgs->bAllowImplicitChangesForNotConvertibleText =
true;
564 sal_Int32 nStartIdx = -1;
569 OUString aText(
m_pConvArgs->pStartNode->GetText() );
573 WordType::DICTIONARY_WORD,
true ) );
576 if (aBoundary.startPos < aText.getLength() &&
577 aBoundary.startPos != aBoundary.endPos)
579 nStartIdx = aBoundary.startPos;
683 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, const OUString &rOrigText, 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
SwIndex & Assign(SwIndexReg *, sal_Int32)
sal_Int32 GetIndex() const
Marks a node in the document model.
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.
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
const SwPosition * End() const
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 Left(sal_uInt16 nMode, bool bSelect, sal_uInt16 nCount, bool bBasicCall, bool bVisual=false)
void Insert(const OUString &)
bool Right(sal_uInt16 nMode, bool bSelect, sal_uInt16 nCount, bool bBasicCall, bool bVisual=false)
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.
const sal_uInt16 CRSR_SKIP_CHARS