22#include <com/sun/star/io/IOException.hpp>
23#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
25#include <com/sun/star/container/ElementExistException.hpp>
27#include <osl/diagnose.h>
28#include <rtl/character.hxx>
75 "SwXAutoTextContainer::getCount: too many items");
84 throw lang::IndexOutOfBoundsException();
104 uno::Reference< text::XAutoTextGroup > xGroup;
110 throw container::NoSuchElementException();
112 return css::uno::Any( xGroup );
120 "SwXAutoTextContainer::getElementNames: too many groups");
122 uno::Sequence< OUString > aGroupNames(
static_cast<sal_Int32
>(
nCount));
123 OUString *pArr = aGroupNames.getArray();
137 if(!sGroupName.isEmpty())
143 const OUString& aGroupName)
147 throw container::ElementExistException();
149 if(aGroupName.isEmpty())
151 lang::IllegalArgumentException aIllegal;
152 aIllegal.Message =
"group name must not be empty";
155 for(sal_Int32
nPos = 0;
nPos < aGroupName.getLength();
nPos++)
158 if (rtl::isAsciiAlphanumeric(cChar) ||
165 lang::IllegalArgumentException aIllegal;
166 aIllegal.Message =
"group name must contain a-z, A-z, '_', ' ' only";
169 OUString sGroup(aGroupName);
177 OSL_ENSURE( xGroup.is(),
"SwXAutoTextContainer::insertNewByName: no UNO object created? How this?" );
188 if(sGroupName.isEmpty())
189 throw container::NoSuchElementException();
195 return "SwXAutoTextContainer";
205 return {
"com.sun.star.text.AutoTextContainer" };
211 m_pGlossaries(pGlos),
215 OSL_ENSURE( -1 != rName.indexOf(
GLOS_DELIM ),
216 "SwXAutoTextGroup::SwXAutoTextGroup: to be constructed with a complete name only!" );
227 if (!pGlosGroup || pGlosGroup->GetError())
228 throw uno::RuntimeException();
229 const sal_uInt16
nCount = pGlosGroup->GetCount();
231 uno::Sequence< OUString > aEntryTitles(
nCount);
232 OUString *pArr = aEntryTitles.getArray();
234 for ( sal_uInt16
i = 0;
i <
nCount;
i++ )
235 pArr[
i] = pGlosGroup->GetLongName(
i);
240 const OUString& aNewElementName,
const OUString& aNewElementTitle)
244 if(aNewElementName != aElementName &&
hasByName(aNewElementName))
245 throw container::ElementExistException();
247 if(!pGlosGroup || pGlosGroup->GetError())
248 throw uno::RuntimeException();
250 const sal_uInt16 nIdx = pGlosGroup->GetIndex( aElementName);
251 if(USHRT_MAX == nIdx)
252 throw lang::IllegalArgumentException();
253 OUString aNewShort(aNewElementName);
254 OUString aNewName(aNewElementTitle);
255 sal_uInt16 nOldLongIdx = pGlosGroup->GetLongIndex( aNewShort );
256 sal_uInt16 nOldIdx = pGlosGroup->GetIndex( aNewName );
258 if ((nOldLongIdx == USHRT_MAX || nOldLongIdx == nIdx)
259 && (nOldIdx == USHRT_MAX || nOldIdx == nIdx))
261 pGlosGroup->Rename( nIdx, &aNewShort, &aNewName );
263 throw io::IOException();
279 SwDoc *
const pDoc(pxCursor ? pxCursor->GetDoc() : &pxRange->
GetDoc());
281 SwPaM * pPam(
nullptr);
284 pPam = pxCursor->GetPaM();
293 if (!pPam) {
return false; }
306 const OUString& aTitle,
const uno::Reference< text::XTextRange > & xTextRange)
310 throw container::ElementExistException();
312 throw uno::RuntimeException();
314 std::unique_ptr<SwTextBlocks> pGlosGroup;
317 const OUString& sShortName(
aName);
318 const OUString& sLongName(aTitle);
319 if (pGlosGroup && !pGlosGroup->GetError())
322 OTextCursorHelper* pxCursor =
dynamic_cast<OTextCursorHelper*
>(xTextRange.get());
325 OUString* pOnlyText =
nullptr;
326 bool bNoAttr = !pxCursor && !pxRange;
330 pOnlyText = &sOnlyText;
335 SwDoc* pGDoc = pGlosGroup->GetDoc();
344 pGlosGroup->SetBaseURL( OUString() );
346 sal_uInt16 nRet = USHRT_MAX;
348 nRet = pGlosGroup->PutText( sShortName, sLongName, *pOnlyText );
351 pGlosGroup->ClearDoc();
352 if( pGlosGroup->BeginPutDoc( sShortName, sLongName ) )
357 nRet = pGlosGroup->PutDoc();
361 if (nRet == USHRT_MAX)
363 throw uno::RuntimeException();
368 uno::Reference< text::XAutoTextEntry > xEntry;
374 uno::Reference< text::XAutoTextEntry >();
375 OSL_ENSURE( xEntry.is(),
"SwXAutoTextGroup::insertNewByName: no UNO object created? How this?" );
378 catch (
const container::ElementExistException&)
382 catch (
const uno::RuntimeException&)
386 catch (
const uno::Exception&)
389 throw css::lang::WrappedTargetRuntimeException(
390 "Error Getting AutoText!",
391 static_cast < OWeakObject *
> (
this ),
402 if(!pGlosGroup || pGlosGroup->GetError())
403 throw container::NoSuchElementException();
405 sal_uInt16 nIdx = pGlosGroup->GetIndex(
aEntryName);
406 if ( nIdx == USHRT_MAX )
407 throw container::NoSuchElementException();
409 pGlosGroup->Delete(nIdx);
422 throw uno::RuntimeException();
424 sal_Int32 nNewDelimPos = rName.lastIndexOf(
GLOS_DELIM );
428 if (nNewDelimPos > -1)
429 aNewSuffix = rName.copy( nNewDelimPos + 1 );
431 if (nOldDelimPos > -1)
432 aOldSuffix =
m_sName.copy( nOldDelimPos + 1 );
434 sal_Int32 nNewNumeric = aNewSuffix.toInt32();
435 sal_Int32 nOldNumeric = aOldSuffix.toInt32();
437 OUString aNewPrefix( (nNewDelimPos > 1) ? rName.copy( 0, nNewDelimPos ) : rName );
438 OUString aOldPrefix( (nOldDelimPos > 1) ?
m_sName.copy( 0, nOldDelimPos ) :
m_sName );
441 ( nNewNumeric == nOldNumeric && aNewPrefix == aOldPrefix ) )
443 OUString sNewGroup(rName);
454 throw uno::RuntimeException();
464 if (!pGlosGroup || pGlosGroup->GetError())
465 throw uno::RuntimeException();
466 return static_cast<sal_Int32
>(pGlosGroup->GetCount());
473 throw uno::RuntimeException();
475 if (!pGlosGroup || pGlosGroup->GetError())
476 throw uno::RuntimeException();
477 const sal_uInt16
nCount = pGlosGroup->GetCount();
479 throw lang::IndexOutOfBoundsException();
480 return getByName(pGlosGroup->GetShortName(o3tl::narrowing<sal_uInt16>(
nIndex)));
493 if (!pGlosGroup || pGlosGroup->GetError())
494 throw uno::RuntimeException();
495 return pGlosGroup->GetCount() > 0;
503 OSL_ENSURE( xEntry.is(),
"SwXAutoTextGroup::getByName: GetAutoTextEntry is fractious!" );
505 return css::uno::Any( xEntry );
512 if (!pGlosGroup || pGlosGroup->GetError())
513 throw uno::RuntimeException();
515 const sal_uInt16
nCount = pGlosGroup->GetCount();
516 uno::Sequence< OUString > aEntryNames(
nCount);
517 OUString *pArr = aEntryNames.getArray();
519 for ( sal_uInt16
i = 0;
i <
nCount;
i++ )
520 pArr[
i] = pGlosGroup->GetShortName(
i);
529 if (!pGlosGroup || pGlosGroup->GetError())
530 throw uno::RuntimeException();
532 const sal_uInt16
nCount = pGlosGroup->GetCount();
535 OUString sCompare(pGlosGroup->GetShortName(
i));
536 if(sCompare.equalsIgnoreAsciiCase(rName))
552 const OUString& rPropertyName,
const uno::Any& aValue)
558 throw beans::UnknownPropertyException(rPropertyName);
561 if(!pGlosGroup || pGlosGroup->GetError())
562 throw uno::RuntimeException();
568 aValue >>= sNewTitle;
569 if(sNewTitle.isEmpty())
570 throw lang::IllegalArgumentException();
571 bool bChanged = sNewTitle != pGlosGroup->GetName();
572 pGlosGroup->SetName(sNewTitle);
586 throw beans::UnknownPropertyException(rPropertyName);
588 if(!pGlosGroup || pGlosGroup->GetError())
589 throw uno::RuntimeException();
595 aAny <<= pGlosGroup->GetFileName();
598 aAny <<= pGlosGroup->GetName();
605 const OUString& ,
const uno::Reference< beans::XPropertyChangeListener > & )
610 const OUString& ,
const uno::Reference< beans::XPropertyChangeListener > & )
615 const OUString& ,
const uno::Reference< beans::XVetoableChangeListener > & )
620 const OUString& ,
const uno::Reference< beans::XVetoableChangeListener > & )
633 return "SwXAutoTextGroup";
643 uno::Sequence<OUString> aRet {
"com.sun.star.text.AutoTextGroup" };
648 OUString aEntryName) :
649 m_pGlossaries(pGlss),
650 m_sGroupName(
std::move(aGroupName)),
668 if (
m_xDocSh->GetDoc()->getIDocumentState().IsModified () )
689 if (SfxEventHintId::PrepareCloseDoc == pEventHint->GetEventId())
699 if ( SfxHintId::Deinitializing == _rHint.
GetId() )
716 OSL_ENSURE(
m_xDocSh.
is(),
"SwXAutoTextEntry::GetBodyText: unexpected: no doc returned by EditGroupDoc!" );
738 const uno::Reference< text::XTextRange > & aTextPosition)
742 return mxBodyText->createTextCursorByRange ( aTextPosition );
749 mxBodyText->insertString ( xRange, aString, bAbsorb );
753 sal_Int16 nControlCharacter,
sal_Bool bAbsorb)
757 mxBodyText->insertControlCharacter ( xRange, nControlCharacter, bAbsorb );
761 const uno::Reference< text::XTextRange > & xRange,
762 const uno::Reference< text::XTextContent > & xContent,
sal_Bool bAbsorb)
766 mxBodyText->insertTextContent ( xRange, xContent, bAbsorb );
770 const uno::Reference< text::XTextContent > & xContent)
780 uno::Reference< text::XText > xRet =
static_cast<text::XText*
>(
this);
830 auto xKeepAlive( xTextRange );
832 OTextCursorHelper* pCursor =
dynamic_cast<OTextCursorHelper*
>(xTextRange.get());
835 SwDoc* pDoc =
nullptr;
839 pDoc = pCursor->GetDoc();
840 else if ( pText && pText->
GetDoc() )
843 pCursor =
dynamic_cast<OTextCursorHelper*
>(xKeepAlive.get());
849 throw uno::RuntimeException();
856 throw uno::RuntimeException();
861 InsertPaM = *pCursor->GetPaM();
865 const bool bResult = pBlock && !pBlock->GetError()
869 throw uno::RuntimeException();
874 return "SwXAutoTextEntry";
884 uno::Sequence<OUString> aRet {
"com.sun.star.text.AutoTextEntry" };
895 { SvMacroItemId::SwStartInsGlossary,
"OnInsertStart" },
896 { SvMacroItemId::SwEndInsGlossary,
"OnInsertDone" },
897 { SvMacroItemId::NONE,
nullptr }
903 m_rAutoTextEntry(rAutoText)
913 return "SwAutoTextEventDescriptor";
921 "Strangely enough, the AutoText vanished!" );
922 OSL_ENSURE( (nEvent == SvMacroItemId::SwEndInsGlossary) ||
923 (nEvent == SvMacroItemId::SwStartInsGlossary) ,
924 "Unknown event ID" );
928 std::unique_ptr<SwTextBlocks> pBlocks(
931 "can't get autotext group; SwAutoTextEntry has illegal name?");
933 if( !pBlocks || pBlocks->GetError())
940 if( pBlocks->GetMacroTable(
nIndex, aMacroTable ) )
942 aMacroTable.
Insert( nEvent, rMacro );
943 pBlocks->SetMacroTable(
nIndex, aMacroTable );
954 OSL_ENSURE( (nEvent == SvMacroItemId::SwEndInsGlossary) ||
955 (nEvent == SvMacroItemId::SwStartInsGlossary) ,
956 "Unknown event ID" );
960 std::unique_ptr<SwTextBlocks> pBlocks(
963 "can't get autotext group; SwAutoTextEntry has illegal name?");
967 SvxMacro aEmptyMacro(sEmptyStr, sEmptyStr);
968 rMacro = aEmptyMacro;
970 if ( !pBlocks || pBlocks->GetError())
977 if( pBlocks->GetMacroTable(
nIndex, aMacroTable ) )
986extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
988 css::uno::Sequence<css::uno::Any>
const &)
@ CheckPosInFly
check if target position is in fly anchored at source range
virtual bool CopyRange(SwPaM &rPam, SwPosition &rPos, SwCopyFlags flags) const =0
Copy a selected content range to a position.
virtual void LockExpFields()=0
virtual bool IsExpFieldsLocked() const =0
virtual void UpdateExpFields(SwTextField *pField, bool bUpdateRefFields)=0
virtual void UnlockExpFields()=0
virtual void SetRedlineFlags_intern(RedlineFlags eMode)=0
Set a new redline mode.
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
const SfxItemPropertyMapEntry * getByName(std::u16string_view rName) const
const SfxItemPropertyMap & getPropertyMap() const
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
static SvxAutoCorrCfg & Get()
bool IsSaveRelFile() const
SvxMacro & Insert(SvMacroItemId nEvent, const SvxMacro &rMacro)
const SvxMacro * Get(SvMacroItemId nEvent) const
Implement the XNameAccess for the AutoText events.
SwXAutoTextEntry & m_rAutoTextEntry
virtual void getByName(SvxMacro &rMacro, const SvMacroItemId nEvent) override
item ID of event
SwAutoTextEventDescriptor(SwXAutoTextEntry &rAutoText)
virtual void replaceByName(const SvMacroItemId nEvent, const SvxMacro &rMacro) override
event (will be copied)
virtual ~SwAutoTextEventDescriptor() override
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Int32 Len() const
bool InsertGlossary(SwTextBlocks &rBlock, const OUString &rEntry, SwPaM &rPaM, SwCursorShell *pShell=nullptr)
inserts an AutoText block
IDocumentContentOperations const & getIDocumentContentOperations() const
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
bool NewGroupDoc(OUString &rGroupName, const OUString &rTitle)
OUString GetCompleteGroupName(std::u16string_view GroupName)
std::unique_ptr< SwTextBlocks > GetGroupDoc(const OUString &rName, bool bCreate=false)
SwDocShellRef EditGroupDoc(const OUString &rGrpName, const OUString &rShortName, bool bShow=true)
OUString GetGroupTitle(const OUString &rGroupName)
css::uno::Reference< css::text::XAutoTextEntry > GetAutoTextEntry(const OUString &_rCompleteGroupName, const OUString &_rGroupName, const OUString &_rEntryName)
returns the cached AutoTextEntry (if any) for the given group/with the given name The entry is create...
OUString const & GetGroupName(size_t)
css::uno::Reference< css::text::XAutoTextGroup > GetAutoTextGroup(std::u16string_view _rGroupName)
returns the cached AutoTextGroup (if any) for the given group name The group is created if it does no...
bool DelGroupDoc(std::u16string_view)
bool RenameGroupDoc(const OUString &sOldGroup, OUString &sNewGroup, const OUString &rNewTitle)
Marks a node in the document model.
SwContentNode * GetContentNode()
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
PaM is Point and Mark: a selection of the document model.
virtual css::uno::Reference< css::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString &aGroupName) override
virtual sal_Bool SAL_CALL hasElements() override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Any SAL_CALL getByName(const OUString &Name) override
virtual css::uno::Type SAL_CALL getElementType() override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
SwGlossaries * m_pGlossaries
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void SAL_CALL removeByName(const OUString &aGroupName) override
virtual sal_Bool SAL_CALL hasByName(const OUString &Name) override
virtual sal_Int32 SAL_CALL getCount() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual ~SwXAutoTextContainer() override
virtual OUString SAL_CALL getImplementationName() override
void implFlushDocument(bool _bCloseDoc=false)
ensure that the current content (which may only be in-memory so far) is flushed to the auto text grou...
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
virtual OUString SAL_CALL getString() override
rtl::Reference< SwXBodyText > mxBodyText
const OUString & GetGroupName() const
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override
virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > &xRange) override
virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
void disposing(std::unique_lock< std::mutex > &) override
const OUString & GetEntryName() const
SwXAutoTextEntry(SwGlossaries *, OUString aGroupName, OUString aEntryName)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL insertTextContent(const css::uno::Reference< css::text::XTextRange > &xRange, const css::uno::Reference< css::text::XTextContent > &xContent, sal_Bool bAbsorb) override
const SwGlossaries * GetGlossaries() const
SwGlossaries * m_pGlossaries
virtual void SAL_CALL setString(const OUString &aString) override
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > &xContent) override
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
virtual ~SwXAutoTextEntry() override
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
SwXAutoTextGroup(const OUString &rName, SwGlossaries *pGloss)
virtual void SAL_CALL setName(const OUString &Name_) override
const SfxItemPropertySet * m_pPropSet
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
SwGlossaries * m_pGlossaries
virtual css::uno::Type SAL_CALL getElementType() override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getTitles() override
virtual sal_Bool SAL_CALL hasByName(const OUString &Name) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual sal_Int32 SAL_CALL getCount() override
virtual sal_Bool SAL_CALL hasElements() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL removeByName(const OUString &aEntryName) override
virtual css::uno::Reference< css::text::XAutoTextEntry > SAL_CALL insertNewByName(const OUString &aName, const OUString &aTitle, const css::uno::Reference< css::text::XTextRange > &xTextRange) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual ~SwXAutoTextGroup() override
virtual css::uno::Any SAL_CALL getByName(const OUString &Name) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual OUString SAL_CALL getName() override
virtual void SAL_CALL renameByName(const OUString &aElementName, const OUString &aNewElementName, const OUString &aNewElementTitle) override
const SwDoc * GetDoc() const
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
css::uno::Type const & get()
static std::unique_ptr< SwGlossaries > pGlossaries
SwGlossaryList * GetGlossaryList()
SW_DLLPUBLIC SwGlossaries * GetGlossaries()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Any SAL_CALL getCaughtException()
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
Marks a position in the document model.
static bool lcl_CopySelToDoc(SwDoc &rInsDoc, OTextCursorHelper *pxCursor, SwXTextRange *pxRange)
const struct SvEventDescription aAutotextEvents[]
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SwXAutoTextContainer_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
SwUnoPropertyMapProvider aSwMapProvider
#define PROPERTY_MAP_AUTO_TEXT_GROUP