21#include <com/sun/star/container/XNamed.hpp>
22#include <com/sun/star/lang/XMultiServiceFactory.hpp>
23#include <com/sun/star/text/XTextDocument.hpp>
24#include <com/sun/star/text/XTextViewCursor.hpp>
25#include <ooo/vba/word/WdBookmarkSortBy.hpp>
38 uno::Reference< frame::XModel >
mxModel;
41 BookmarksEnumeration(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< uno::XComponentContext >& xContext,
const uno::Reference< container::XEnumeration >& xEnumeration, uno::Reference< frame::XModel > xModel ) :
EnumerationHelperImpl( xParent, xContext, xEnumeration ),
mxModel(
std::move(
xModel )) {}
43 virtual uno::Any SAL_CALL nextElement( )
override
45 uno::Reference< container::XNamed > xNamed( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
46 OUString
aName = xNamed->getName();
47 return uno::Any( uno::Reference< word::XBookmark > (
new SwVbaBookmark( m_xParent, m_xContext, mxModel, aName ) ) );
53class BookmarkCollectionHelper :
public ::cppu::WeakImplHelper< container::XNameAccess,
54 container::XIndexAccess >
57 uno::Reference< container::XNameAccess > mxNameAccess;
58 uno::Reference< container::XIndexAccess > mxIndexAccess;
62 explicit BookmarkCollectionHelper( uno::Reference< container::XIndexAccess > xIndexAccess ) : mxIndexAccess(
std::move( xIndexAccess ))
64 mxNameAccess.set( mxIndexAccess, uno::UNO_QUERY_THROW );
67 virtual uno::Type SAL_CALL getElementType( )
override {
return mxIndexAccess->getElementType(); }
68 virtual sal_Bool SAL_CALL hasElements( )
override {
return mxIndexAccess->hasElements(); }
70 virtual uno::Any SAL_CALL getByName(
const OUString& aName )
override
72 if ( !hasByName(aName) )
73 throw container::NoSuchElementException();
76 virtual uno::Sequence< OUString > SAL_CALL getElementNames( )
override
78 return mxNameAccess->getElementNames();
80 virtual sal_Bool SAL_CALL hasByName(
const OUString& aName )
override
82 if( mxNameAccess->hasByName( aName ) )
84 m_cachePos = mxNameAccess->getByName( aName );
89 for( sal_Int32 nIndex = 0;
nIndex < mxIndexAccess->getCount();
nIndex++ )
91 uno::Reference< container::XNamed > xNamed( mxIndexAccess->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
92 OUString aBookmarkName = xNamed->getName();
93 if(
aName.equalsIgnoreAsciiCase( aBookmarkName ) )
95 m_cachePos <<= xNamed;
103 virtual ::sal_Int32 SAL_CALL getCount( )
override
105 return mxIndexAccess->getCount();
107 virtual uno::Any SAL_CALL getByIndex( ::sal_Int32
Index )
override
109 return mxIndexAccess->getByIndex(
Index );
115SwVbaBookmarks::SwVbaBookmarks(
const uno::Reference< XHelperInterface >& xParent,
const uno::Reference< css::uno::XComponentContext > & xContext,
const uno::Reference< container::XIndexAccess >& xBookmarks, uno::Reference< frame::XModel > xModel ):
SwVbaBookmarks_BASE( xParent, xContext,
uno::
Reference< container::XIndexAccess >( new BookmarkCollectionHelper( xBookmarks ) ) ),
mxModel(
std::move(
xModel ))
118 uno::Reference< text::XTextDocument > xDocument(
mxModel, uno::UNO_QUERY_THROW );
126uno::Reference< container::XEnumeration >
129 uno::Reference< container::XEnumerationAccess > xEnumAccess(
m_xIndexAccess, uno::UNO_QUERY_THROW );
136 uno::Reference< container::XNamed > xNamed( aSource, uno::UNO_QUERY_THROW );
137 OUString
aName = xNamed->getName();
143 uno::Reference< text::XTextContent > xBookmark(
m_xNameAccess->getByName( rName ), uno::UNO_QUERY_THROW );
149 uno::Reference< lang::XMultiServiceFactory > xDocMSF(
xModel, uno::UNO_QUERY_THROW );
150 uno::Reference< text::XTextContent > xBookmark( xDocMSF->createInstance(
"com.sun.star.text.Bookmark"), uno::UNO_QUERY_THROW );
151 uno::Reference< container::XNamed > xNamed( xBookmark, uno::UNO_QUERY_THROW );
152 xNamed->setName( rName );
153 rTextRange->getText()->insertTextContent( rTextRange, xBookmark,
false );
159 uno::Reference< text::XTextRange > xTextRange;
160 uno::Reference< word::XRange > xRange;
161 if( rRange >>= xRange )
185 return word::WdBookmarkSortBy::wdSortByName;
216 return "SwVbaBookmarks";
219css::uno::Sequence<OUString>
222 static uno::Sequence< OUString >
const sNames
224 "ooo.vba.word.Bookmarks"
css::uno::Reference< css::frame::XModel2 > mxModel
css::uno::Reference< css::uno::XComponentContext > mxContext
virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent() override
css::uno::Reference< css::container::XNameAccess > m_xNameAccess
css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess
SwVbaBookmarks(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::container::XIndexAccess > &xBookmarks, css::uno::Reference< css::frame::XModel > xModel)
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual sal_Bool SAL_CALL getShowHidden() override
void removeBookmarkByName(const OUString &rName)
virtual sal_Int32 SAL_CALL getDefaultSorting() override
static void addBookmarkByName(const css::uno::Reference< css::frame::XModel > &xModel, const OUString &rName, const css::uno::Reference< css::text::XTextRange > &rTextRange)
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Type SAL_CALL getElementType() override
css::uno::Reference< css::frame::XModel > mxModel
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual void SAL_CALL setShowHidden(sal_Bool _hidden) override
virtual css::uno::Any SAL_CALL Add(const OUString &rName, const css::uno::Any &rRange) override
virtual void SAL_CALL setDefaultSorting(sal_Int32 _type) override
virtual OUString getServiceImplName() override
css::uno::Reference< css::text::XBookmarksSupplier > mxBookmarksSupplier
virtual sal_Bool SAL_CALL Exists(const OUString &rName) override
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getXTextRange() override
css::uno::Type const & get()
uno::Reference< text::XTextViewCursor > getXTextViewCursor(const uno::Reference< frame::XModel > &xModel)
Reference< XModel > xModel