summaryrefslogtreecommitdiff
path: root/sd/source/ui/unoidl/unomodel.cxx
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2023-05-30 14:09:25 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2023-07-12 07:56:37 +0200
commite78f60a369146774ca2a38ca121f294b562b2be5 (patch)
tree46eb6ec25611b03400c46cf089c7fa28563d6d5a /sd/source/ui/unoidl/unomodel.cxx
parent43c564da59d7d951ee9a903b80e82fd1159d0c71 (diff)
Categories for link targets in Impress
Writer and Calc presented possible link targets inside documents as a Tree, with items under their categories. This patch makes the same for Impress so we don't mix master pages with regular pages. Change-Id: Ifd98300b0d609c28d6c1880332fff7e750b5e1b2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152389 Reviewed-by: Gülşah Köse <gulsah.kose@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153985 Tested-by: Jenkins Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sd/source/ui/unoidl/unomodel.cxx')
-rw-r--r--sd/source/ui/unoidl/unomodel.cxx298
1 files changed, 240 insertions, 58 deletions
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 9e9845c3c3cd..3350da8b92e5 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -139,6 +139,14 @@ using namespace ::cppu;
using namespace ::com::sun::star;
using namespace ::sd;
+const TranslateId aTypeResIds[SdLinkTargetType::Count] =
+{
+ STR_SD_PAGE, // SdLinkTargetType::Page
+ STR_NOTES_MODE, // SdLinkTargetType::Notes
+ STR_HANDOUT, // SdLinkTargetType::Handout
+ STR_MASTERPAGE_NAME, // SdLinkTargetType::MasterPage
+};
+
TranslateId SdTPAction::GetClickActionSdResId( presentation::ClickAction eCA )
{
switch( eCA )
@@ -3386,6 +3394,8 @@ uno::Sequence< OUString > SAL_CALL SdMasterPagesAccess::getSupportedServiceNames
SdDocLinkTargets::SdDocLinkTargets( SdXImpressDocument& rMyModel ) noexcept
: mpModel( &rMyModel )
{
+ for (sal_uInt16 i=0; i < SdLinkTargetType::Count; i++)
+ aNames[i] = SdResId(aTypeResIds[i]);
}
SdDocLinkTargets::~SdDocLinkTargets() noexcept
@@ -3411,6 +3421,172 @@ void SAL_CALL SdDocLinkTargets::removeEventListener( const uno::Reference< lang:
// XNameAccess
uno::Any SAL_CALL SdDocLinkTargets::getByName( const OUString& aName )
{
+ if (mpModel)
+ {
+ for (sal_uInt16 i=0; i < SdLinkTargetType::Count; i++)
+ if ( aNames[i] == aName )
+ return uno::Any(uno::Reference< beans::XPropertySet >(new SdDocLinkTargetType( mpModel, i )));
+ }
+
+ throw container::NoSuchElementException();
+}
+
+uno::Sequence< OUString > SAL_CALL SdDocLinkTargets::getElementNames()
+{
+ uno::Sequence<OUString> aRet(SdLinkTargetType::Count);
+ OUString* pArray = aRet.getArray();
+ for (sal_uInt16 i=0; i < SdLinkTargetType::Count; i++)
+ pArray[i] = aNames[i];
+ return aRet;
+}
+
+sal_Bool SAL_CALL SdDocLinkTargets::hasByName( const OUString& aName )
+{
+ for (const auto & i : aNames)
+ if ( i == aName )
+ return true;
+ return false;
+}
+
+// container::XElementAccess
+uno::Type SAL_CALL SdDocLinkTargets::getElementType()
+{
+ return cppu::UnoType<beans::XPropertySet>::get();
+}
+
+sal_Bool SAL_CALL SdDocLinkTargets::hasElements()
+{
+ return true;
+}
+
+SdPage* SdDocLinkTarget::FindPage( std::u16string_view rName ) const
+{
+ SdDrawDocument* pDoc = mpModel->GetDoc();
+ if( pDoc == nullptr )
+ return nullptr;
+
+ const sal_uInt16 nMaxPages = pDoc->GetPageCount();
+ const sal_uInt16 nMaxMasterPages = pDoc->GetMasterPageCount();
+
+ sal_uInt16 nPage;
+ SdPage* pPage;
+
+ const bool bDraw = pDoc->GetDocumentType() == DocumentType::Draw;
+
+ // standard pages
+ for( nPage = 0; nPage < nMaxPages; nPage++ )
+ {
+ pPage = static_cast<SdPage*>(pDoc->GetPage( nPage ));
+ if( (pPage->GetName() == rName) && (!bDraw || (pPage->GetPageKind() == PageKind::Standard)) )
+ return pPage;
+ }
+
+ // master pages
+ for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
+ {
+ pPage = static_cast<SdPage*>(pDoc->GetMasterPage( nPage ));
+ if( (pPage->GetName() == rName) && (!bDraw || (pPage->GetPageKind() == PageKind::Standard)) )
+ return pPage;
+ }
+
+ return nullptr;
+}
+
+// XServiceInfo
+OUString SAL_CALL SdDocLinkTargets::getImplementationName()
+{
+ return "SdDocLinkTargets";
+}
+
+sal_Bool SAL_CALL SdDocLinkTargets::supportsService( const OUString& ServiceName )
+{
+ return cppu::supportsService( this, ServiceName );
+}
+
+uno::Sequence< OUString > SAL_CALL SdDocLinkTargets::getSupportedServiceNames()
+{
+ return { "com.sun.star.document.LinkTargets" };
+}
+
+SdDocLinkTargetType::SdDocLinkTargetType(SdXImpressDocument* pModel, sal_uInt16 nT) noexcept
+ : mpModel(pModel)
+ , mnType(nT)
+{
+ maName = SdResId(aTypeResIds[nT]);
+}
+
+// beans::XPropertySet
+
+uno::Reference< beans::XPropertySetInfo > SAL_CALL SdDocLinkTargetType::getPropertySetInfo()
+{
+ static uno::Reference< beans::XPropertySetInfo > aRef;//(new SfxItemPropertySetInfo( lcl_GetLinkTargetMap() ));
+ return aRef;
+}
+
+void SAL_CALL SdDocLinkTargetType::setPropertyValue(const OUString& /* aPropertyName */,
+ const uno::Any& /* aValue */)
+{
+ // everything is read-only
+}
+
+uno::Any SAL_CALL SdDocLinkTargetType::getPropertyValue(const OUString& PropertyName)
+{
+ uno::Any aRet;
+ if ( PropertyName == "LinkDisplayName" )
+ aRet <<= maName;
+
+ return aRet;
+}
+
+void SAL_CALL SdDocLinkTargetType::addPropertyChangeListener( const OUString&,
+ const uno::Reference<beans::XPropertyChangeListener>&)
+{ OSL_FAIL("not implemented"); }
+
+void SAL_CALL SdDocLinkTargetType::removePropertyChangeListener( const OUString&,
+ const uno::Reference<beans::XPropertyChangeListener>&)
+{ OSL_FAIL("not implemented"); }
+
+void SAL_CALL SdDocLinkTargetType::addVetoableChangeListener( const OUString&,
+ const uno::Reference<beans::XVetoableChangeListener>&)
+{ OSL_FAIL("not implemented"); }
+
+void SAL_CALL SdDocLinkTargetType::removeVetoableChangeListener( const OUString&,
+ const uno::Reference<beans::XVetoableChangeListener>&)
+{ OSL_FAIL("not implemented"); }
+
+// document::XLinkTargetSupplier
+
+uno::Reference< container::XNameAccess > SAL_CALL SdDocLinkTargetType::getLinks()
+{
+ return new SdDocLinkTarget( mpModel, mnType );
+}
+
+// XServiceInfo
+OUString SAL_CALL SdDocLinkTargetType::getImplementationName()
+{
+ return "SdDocLinkTargetType";
+}
+
+sal_Bool SAL_CALL SdDocLinkTargetType::supportsService( const OUString& ServiceName )
+{
+ return cppu::supportsService( this, ServiceName );
+}
+
+uno::Sequence< OUString > SAL_CALL SdDocLinkTargetType::getSupportedServiceNames()
+{
+ return { "com.sun.star.document.LinkTargetSupplier" };
+}
+
+SdDocLinkTarget::SdDocLinkTarget( SdXImpressDocument* pModel, sal_uInt16 nT )
+ : mpModel(pModel)
+ , mnType(nT)
+{
+}
+
+// container::XNameAccess
+
+uno::Any SAL_CALL SdDocLinkTarget::getByName(const OUString& aName)
+{
::SolarMutexGuard aGuard;
if( nullptr == mpModel )
@@ -3430,7 +3606,7 @@ uno::Any SAL_CALL SdDocLinkTargets::getByName( const OUString& aName )
return aAny;
}
-uno::Sequence< OUString > SAL_CALL SdDocLinkTargets::getElementNames()
+uno::Sequence<OUString> SAL_CALL SdDocLinkTarget::getElementNames()
{
::SolarMutexGuard aGuard;
@@ -3448,40 +3624,78 @@ uno::Sequence< OUString > SAL_CALL SdDocLinkTargets::getElementNames()
const sal_uInt16 nMaxPages = pDoc->GetSdPageCount( PageKind::Standard );
const sal_uInt16 nMaxMasterPages = pDoc->GetMasterSdPageCount( PageKind::Standard );
- uno::Sequence< OUString > aSeq( nMaxPages + nMaxMasterPages );
+ uno::Sequence< OUString > aSeq( mnType == SdLinkTargetType::Page ? nMaxPages : nMaxMasterPages );
OUString* pStr = aSeq.getArray();
sal_uInt16 nPage;
- // standard pages
- for( nPage = 0; nPage < nMaxPages; nPage++ )
- *pStr++ = pDoc->GetSdPage( nPage, PageKind::Standard )->GetName();
-
- // master pages
- for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
- *pStr++ = pDoc->GetMasterSdPage( nPage, PageKind::Standard )->GetName();
+ if (mnType == SdLinkTargetType::Page)
+ {
+ // standard pages
+ for( nPage = 0; nPage < nMaxPages; nPage++ )
+ *pStr++ = pDoc->GetSdPage( nPage, PageKind::Standard )->GetName();
+ }
+ else
+ {
+ // master pages
+ for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
+ *pStr++ = pDoc->GetMasterSdPage( nPage, PageKind::Standard )->GetName();
+ }
return aSeq;
}
else
{
- const sal_uInt16 nMaxPages = pDoc->GetPageCount();
+ PageKind eKind;
+ switch (mnType)
+ {
+ case SdLinkTargetType::Notes:
+ eKind = PageKind::Notes;
+ break;
+ case SdLinkTargetType::Handout:
+ eKind = PageKind::Handout;
+ break;
+ default:
+ eKind = PageKind::Standard;
+ break;
+ }
+ const sal_uInt16 nMaxPages = pDoc->GetSdPageCount( eKind );
const sal_uInt16 nMaxMasterPages = pDoc->GetMasterPageCount();
- uno::Sequence< OUString > aSeq( nMaxPages + nMaxMasterPages );
+ uno::Sequence< OUString > aSeq( mnType == SdLinkTargetType::MasterPage ? nMaxMasterPages : nMaxPages );
OUString* pStr = aSeq.getArray();
sal_uInt16 nPage;
- // standard pages
- for( nPage = 0; nPage < nMaxPages; nPage++ )
- *pStr++ = static_cast<SdPage*>(pDoc->GetPage( nPage ))->GetName();
-
- // master pages
- for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
- *pStr++ = static_cast<SdPage*>(pDoc->GetMasterPage( nPage ))->GetName();
+ switch (mnType)
+ {
+ case SdLinkTargetType::Page:
+ {
+ for( nPage = 0; nPage < nMaxPages; nPage++ )
+ *pStr++ = pDoc->GetSdPage( nPage, PageKind::Standard )->GetName();
+ break;
+ }
+ case SdLinkTargetType::Notes:
+ {
+ for( nPage = 0; nPage < nMaxPages; nPage++ )
+ *pStr++ = pDoc->GetSdPage( nPage, PageKind::Notes )->GetName();
+ break;
+ }
+ case SdLinkTargetType::Handout:
+ {
+ for( nPage = 0; nPage < nMaxPages; nPage++ )
+ *pStr++ = pDoc->GetSdPage( nPage, PageKind::Handout )->GetName();
+ break;
+ }
+ case SdLinkTargetType::MasterPage:
+ {
+ for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
+ *pStr++ = static_cast<SdPage*>(pDoc->GetMasterPage( nPage ))->GetName();
+ break;
+ }
+ }
return aSeq;
}
}
-sal_Bool SAL_CALL SdDocLinkTargets::hasByName( const OUString& aName )
+sal_Bool SAL_CALL SdDocLinkTarget::hasByName(const OUString& aName)
{
::SolarMutexGuard aGuard;
@@ -3492,12 +3706,13 @@ sal_Bool SAL_CALL SdDocLinkTargets::hasByName( const OUString& aName )
}
// container::XElementAccess
-uno::Type SAL_CALL SdDocLinkTargets::getElementType()
+
+uno::Type SAL_CALL SdDocLinkTarget::getElementType()
{
return cppu::UnoType<beans::XPropertySet>::get();
}
-sal_Bool SAL_CALL SdDocLinkTargets::hasElements()
+sal_Bool SAL_CALL SdDocLinkTarget::hasElements()
{
::SolarMutexGuard aGuard;
@@ -3507,51 +3722,18 @@ sal_Bool SAL_CALL SdDocLinkTargets::hasElements()
return mpModel->GetDoc() != nullptr;
}
-SdPage* SdDocLinkTargets::FindPage( std::u16string_view rName ) const
-{
- SdDrawDocument* pDoc = mpModel->GetDoc();
- if( pDoc == nullptr )
- return nullptr;
-
- const sal_uInt16 nMaxPages = pDoc->GetPageCount();
- const sal_uInt16 nMaxMasterPages = pDoc->GetMasterPageCount();
-
- sal_uInt16 nPage;
- SdPage* pPage;
-
- const bool bDraw = pDoc->GetDocumentType() == DocumentType::Draw;
-
- // standard pages
- for( nPage = 0; nPage < nMaxPages; nPage++ )
- {
- pPage = static_cast<SdPage*>(pDoc->GetPage( nPage ));
- if( (pPage->GetName() == rName) && (!bDraw || (pPage->GetPageKind() == PageKind::Standard)) )
- return pPage;
- }
-
- // master pages
- for( nPage = 0; nPage < nMaxMasterPages; nPage++ )
- {
- pPage = static_cast<SdPage*>(pDoc->GetMasterPage( nPage ));
- if( (pPage->GetName() == rName) && (!bDraw || (pPage->GetPageKind() == PageKind::Standard)) )
- return pPage;
- }
-
- return nullptr;
-}
-
// XServiceInfo
-OUString SAL_CALL SdDocLinkTargets::getImplementationName()
+OUString SAL_CALL SdDocLinkTarget::getImplementationName()
{
- return "SdDocLinkTargets";
+ return "SdDocLinkTarget";
}
-sal_Bool SAL_CALL SdDocLinkTargets::supportsService( const OUString& ServiceName )
+sal_Bool SAL_CALL SdDocLinkTarget::supportsService( const OUString& ServiceName )
{
return cppu::supportsService( this, ServiceName );
}
-uno::Sequence< OUString > SAL_CALL SdDocLinkTargets::getSupportedServiceNames()
+uno::Sequence< OUString > SAL_CALL SdDocLinkTarget::getSupportedServiceNames()
{
return { "com.sun.star.document.LinkTargets" };
}