summaryrefslogtreecommitdiffstats
path: root/framework/source/fwe/helper/titlehelper.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'framework/source/fwe/helper/titlehelper.cxx')
-rw-r--r--framework/source/fwe/helper/titlehelper.cxx199
1 files changed, 102 insertions, 97 deletions
diff --git a/framework/source/fwe/helper/titlehelper.cxx b/framework/source/fwe/helper/titlehelper.cxx
index 740d98a753ec..58c28f8f8ef9 100644
--- a/framework/source/fwe/helper/titlehelper.cxx
+++ b/framework/source/fwe/helper/titlehelper.cxx
@@ -29,6 +29,7 @@
#include <com/sun/star/frame/XModel3.hpp>
#include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
+#include <comphelper/configuration.hxx>
#include <unotools/configmgr.hxx>
#include <unotools/bootstrap.hxx>
#include <unotools/mediadescriptor.hxx>
@@ -36,6 +37,7 @@
#include <rtl/ustrbuf.hxx>
#include <osl/mutex.hxx>
#include <tools/urlobj.hxx>
+#include <utility>
#include <vcl/svapp.hxx>
@@ -45,43 +47,28 @@ using namespace css::frame;
namespace framework{
-TitleHelper::TitleHelper(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
+TitleHelper::TitleHelper(css::uno::Reference< css::uno::XComponentContext > xContext,
const css::uno::Reference< css::uno::XInterface >& xOwner,
const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers)
- : ::cppu::BaseMutex ()
- , m_xContext (rxContext)
+ :
+ m_xContext (std::move(xContext))
+ , m_xOwner (xOwner)
+ , m_xUntitledNumbers(xNumbers)
, m_bExternalTitle (false)
, m_nLeasedNumber (css::frame::UntitledNumbersConst::INVALID_NUMBER)
- , m_aListener (m_aMutex)
{
- // SYNCHRONIZED ->
- {
- osl::MutexGuard aLock(m_aMutex);
-
- m_xOwner = xOwner;
- m_xUntitledNumbers = xNumbers;
- }
- // <- SYNCHRONIZED
-
- css::uno::Reference< css::frame::XModel > xModel(xOwner, css::uno::UNO_QUERY);
- if (xModel.is ())
+ if (css::uno::Reference<css::frame::XModel> xModel{ xOwner, css::uno::UNO_QUERY })
{
impl_startListeningForModel (xModel);
- return;
}
-
- css::uno::Reference< css::frame::XController > xController(xOwner, css::uno::UNO_QUERY);
- if (xController.is ())
+ else if (css::uno::Reference<css::frame::XController> xController{ xOwner,
+ css::uno::UNO_QUERY })
{
impl_startListeningForController (xController);
- return;
}
-
- css::uno::Reference< css::frame::XFrame > xFrame(xOwner, css::uno::UNO_QUERY);
- if (xFrame.is ())
+ else if (css::uno::Reference<css::frame::XFrame> xFrame{ xOwner, css::uno::UNO_QUERY })
{
impl_startListeningForFrame (xFrame);
- return;
}
}
@@ -92,7 +79,7 @@ TitleHelper::~TitleHelper()
OUString SAL_CALL TitleHelper::getTitle()
{
// SYNCHRONIZED ->
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
// An external title will win always and disable all internal logic about
// creating/using a title value.
@@ -104,8 +91,10 @@ OUString SAL_CALL TitleHelper::getTitle()
if (!m_sTitle.isEmpty())
return m_sTitle;
- // Title seems to be unused till now ... do bootstraping
+ // Title seems to be unused till now ... do bootstrapping
+ aLock.unlock();
impl_updateTitle (true);
+ aLock.lock();
return m_sTitle;
// <- SYNCHRONIZED
@@ -115,7 +104,7 @@ void SAL_CALL TitleHelper::setTitle(const OUString& sTitle)
{
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
m_bExternalTitle = true;
m_sTitle = sTitle;
@@ -127,14 +116,14 @@ void SAL_CALL TitleHelper::setTitle(const OUString& sTitle)
void SAL_CALL TitleHelper::addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
{
- // container is threadsafe by himself
- m_aListener.addInterface( cppu::UnoType<css::frame::XTitleChangeListener>::get(), xListener );
+ std::unique_lock aLock(m_aMutex);
+ m_aTitleChangeListeners.addInterface( aLock, xListener );
}
void SAL_CALL TitleHelper::removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
{
- // container is threadsafe by himself
- m_aListener.removeInterface( cppu::UnoType<css::frame::XTitleChangeListener>::get(), xListener );
+ std::unique_lock aLock(m_aMutex);
+ m_aTitleChangeListeners.removeInterface( aLock, xListener );
}
void SAL_CALL TitleHelper::titleChanged(const css::frame::TitleChangedEvent& aEvent)
@@ -142,9 +131,9 @@ void SAL_CALL TitleHelper::titleChanged(const css::frame::TitleChangedEvent& aEv
css::uno::Reference< css::frame::XTitle > xSubTitle;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
- xSubTitle.set(m_xSubTitle.get (), css::uno::UNO_QUERY);
+ xSubTitle = m_xSubTitle;
}
// <- SYNCHRONIZED
@@ -164,9 +153,9 @@ void SAL_CALL TitleHelper::documentEventOccured(const css::document::DocumentEve
css::uno::Reference< css::frame::XModel > xOwner;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
- xOwner.set(m_xOwner.get (), css::uno::UNO_QUERY);
+ xOwner.set(m_xOwner, css::uno::UNO_QUERY);
}
// <- SYNCHRONIZED
@@ -186,9 +175,9 @@ void SAL_CALL TitleHelper::frameAction(const css::frame::FrameActionEvent& aEven
css::uno::Reference< css::frame::XFrame > xOwner;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
- xOwner.set(m_xOwner.get (), css::uno::UNO_QUERY);
+ xOwner.set(m_xOwner, css::uno::UNO_QUERY);
}
// <- SYNCHRONIZED
@@ -215,10 +204,10 @@ void SAL_CALL TitleHelper::disposing(const css::lang::EventObject& aEvent)
::sal_Int32 nLeasedNumber;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
xOwner = m_xOwner;
- xNumbers.set(m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
+ xNumbers = m_xUntitledNumbers;
nLeasedNumber = m_nLeasedNumber;
}
// <- SYNCHRONIZED
@@ -241,10 +230,10 @@ void SAL_CALL TitleHelper::disposing(const css::lang::EventObject& aEvent)
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
- m_xOwner = nullptr;
- m_sTitle = OUString ();
+ m_xOwner.clear();
+ m_sTitle.clear();
m_nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
}
// <- SYNCHRONIZED
@@ -255,7 +244,7 @@ void TitleHelper::impl_sendTitleChangedEvent ()
css::uno::Reference<css::uno::XInterface> xOwner;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
xOwner = m_xOwner;
}
@@ -266,53 +255,60 @@ void TitleHelper::impl_sendTitleChangedEvent ()
if( ! aEvent.Source.is() )
return;
- comphelper::OInterfaceContainerHelper2* pContainer = m_aListener.getContainer( cppu::UnoType<css::frame::XTitleChangeListener>::get());
- if ( ! pContainer)
- return;
-
- comphelper::OInterfaceIteratorHelper2 pIt( *pContainer );
+ std::unique_lock aLock(m_aMutex);
+ comphelper::OInterfaceIteratorHelper4 pIt( aLock, m_aTitleChangeListeners );
while ( pIt.hasMoreElements() )
{
+ aLock.unlock();
try
{
- static_cast<css::frame::XTitleChangeListener*>(pIt.next())->titleChanged( aEvent );
+ uno::Reference<css::frame::XTitleChangeListener> i = pIt.next();
+ i->titleChanged( aEvent );
}
catch(const css::uno::Exception&)
{
- pIt.remove();
+ aLock.lock();
+ pIt.remove(aLock);
+ aLock.unlock();
}
+ aLock.lock();
}
}
void TitleHelper::impl_updateTitle (bool init)
{
- css::uno::Reference< css::frame::XModel3 > xModel;
- css::uno::Reference< css::frame::XController > xController;
- css::uno::Reference< css::frame::XFrame > xFrame;
+ css::uno::Reference<css::uno::XInterface> xOwner;
+
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
- xModel.set (m_xOwner.get(), css::uno::UNO_QUERY);
- xController.set(m_xOwner.get(), css::uno::UNO_QUERY);
- xFrame.set (m_xOwner.get(), css::uno::UNO_QUERY);
+ xOwner = m_xOwner;
}
// <- SYNCHRONIZED
- if (xModel.is ())
+ if (css::uno::Reference<css::frame::XModel3> xModel{ xOwner, css::uno::UNO_QUERY })
{
impl_updateTitleForModel (xModel, init);
}
- else if (xController.is ())
+ else if (css::uno::Reference<css::frame::XController> xController{ xOwner,
+ css::uno::UNO_QUERY })
{
impl_updateTitleForController (xController, init);
}
- else if (xFrame.is ())
+ else if (css::uno::Reference<css::frame::XFrame> xFrame{ xOwner, css::uno::UNO_QUERY })
{
impl_updateTitleForFrame (xFrame, init);
}
}
+static OUString getURLFromModel(const css::uno::Reference< css::frame::XModel3 >& xModel)
+{
+ if (css::uno::Reference<css::frame::XStorable> xURLProvider{ xModel, css::uno::UNO_QUERY })
+ return xURLProvider->getLocation();
+ return {};
+}
+
void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel3 >& xModel, bool init)
{
css::uno::Reference< css::uno::XInterface > xOwner;
@@ -320,7 +316,7 @@ void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::fram
::sal_Int32 nLeasedNumber;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
// external title won't be updated internally!
// It has to be set from outside new.
@@ -328,7 +324,7 @@ void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::fram
return;
xOwner = m_xOwner;
- xNumbers.set (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
+ xNumbers = m_xUntitledNumbers;
nLeasedNumber = m_nLeasedNumber;
}
// <- SYNCHRONIZED
@@ -341,24 +337,27 @@ void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::fram
return;
OUString sTitle;
- OUString sURL;
-
- css::uno::Reference< css::frame::XStorable > xURLProvider(xModel , css::uno::UNO_QUERY);
- if (xURLProvider.is())
- sURL = xURLProvider->getLocation ();
- utl::MediaDescriptor aDescriptor(xModel->getArgs2( { utl::MediaDescriptor::PROP_SUGGESTEDSAVEASNAME } ));
- const OUString sSuggestedSaveAsName = aDescriptor.getUnpackedValueOrDefault(
- utl::MediaDescriptor::PROP_SUGGESTEDSAVEASNAME, OUString());
+ utl::MediaDescriptor aDescriptor(
+ xModel->getArgs2({ utl::MediaDescriptor::PROP_DOCUMENTTITLE,
+ utl::MediaDescriptor::PROP_SUGGESTEDSAVEASNAME }));
- if (!sURL.isEmpty())
+ if (const OUString sMediaTitle = aDescriptor.getUnpackedValueOrDefault(
+ utl::MediaDescriptor::PROP_DOCUMENTTITLE, OUString());
+ !sMediaTitle.isEmpty())
+ {
+ sTitle = sMediaTitle;
+ }
+ else if (const OUString sURL = getURLFromModel(xModel); !sURL.isEmpty())
{
sTitle = impl_convertURL2Title(sURL);
if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
xNumbers->releaseNumber (nLeasedNumber);
nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
}
- else if (!sSuggestedSaveAsName.isEmpty())
+ else if (const OUString sSuggestedSaveAsName = aDescriptor.getUnpackedValueOrDefault(
+ utl::MediaDescriptor::PROP_SUGGESTEDSAVEASNAME, OUString());
+ !sSuggestedSaveAsName.isEmpty())
{
// tdf#121537 Use suggested save as name for title if file has not yet been saved
sTitle = sSuggestedSaveAsName;
@@ -368,20 +367,16 @@ void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::fram
if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
nLeasedNumber = xNumbers->leaseNumber (xOwner);
- OUStringBuffer sNewTitle(256);
- sNewTitle.append (xNumbers->getUntitledPrefix ());
if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
- sNewTitle.append(nLeasedNumber);
+ sTitle = xNumbers->getUntitledPrefix() + OUString::number(nLeasedNumber);
else
- sNewTitle.append("?");
-
- sTitle = sNewTitle.makeStringAndClear ();
+ sTitle = xNumbers->getUntitledPrefix() + "?";
}
bool bChanged;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
// WORKAROUND: the notification is currently sent always,
// can be changed after shared mode is supported per UNO API
@@ -403,7 +398,7 @@ void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css:
::sal_Int32 nLeasedNumber;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
// external title won't be updated internally!
// It has to be set from outside new.
@@ -411,7 +406,7 @@ void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css:
return;
xOwner = m_xOwner;
- xNumbers.set (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
+ xNumbers = m_xUntitledNumbers;
nLeasedNumber = m_nLeasedNumber;
}
// <- SYNCHRONIZED
@@ -437,8 +432,7 @@ void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css:
sTitle.append (xModelTitle->getTitle ());
if ( nLeasedNumber > 1 )
{
- sTitle.append(" : ");
- sTitle.append(nLeasedNumber);
+ sTitle.append(" : " + OUString::number(nLeasedNumber));
}
if (xModel.is ())
{
@@ -463,7 +457,7 @@ void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css:
bool bChanged;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
OUString sNewTitle = sTitle.makeStringAndClear ();
bChanged = !init && m_sTitle != sNewTitle;
@@ -483,7 +477,7 @@ void TitleHelper::impl_updateTitleForFrame (const css::uno::Reference< css::fram
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
// external title won't be updated internally!
// It has to be set from outside new.
@@ -500,18 +494,21 @@ void TitleHelper::impl_updateTitleForFrame (const css::uno::Reference< css::fram
impl_appendComponentTitle (sTitle, xComponent);
#ifndef MACOSX
- // fdo#70376: We want the window title to contain just the
- // document name (from the above "component title").
- impl_appendProductName (sTitle);
- impl_appendModuleName (sTitle);
- impl_appendDebugVersion (sTitle);
+ if (!comphelper::IsFuzzing())
+ {
+ // fdo#70376: We want the window title to contain just the
+ // document name (from the above "component title").
+ impl_appendProductName (sTitle);
+ impl_appendModuleName (sTitle);
+ impl_appendDebugVersion (sTitle);
+ }
#endif
impl_appendSafeMode (sTitle);
bool bChanged;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
OUString sNewTitle = sTitle.makeStringAndClear ();
bChanged = !init && m_sTitle != sNewTitle;
@@ -523,6 +520,7 @@ void TitleHelper::impl_updateTitleForFrame (const css::uno::Reference< css::fram
impl_sendTitleChangedEvent ();
}
+// static
void TitleHelper::impl_appendComponentTitle ( OUStringBuffer& sTitle ,
const css::uno::Reference< css::uno::XInterface >& xComponent)
{
@@ -533,13 +531,17 @@ void TitleHelper::impl_appendComponentTitle ( OUStringBuffer&
sTitle.append (xTitle->getTitle ());
}
+// static
void TitleHelper::impl_appendProductName (OUStringBuffer& sTitle)
{
OUString name(utl::ConfigManager::getProductName());
if (!name.isEmpty())
{
if (!sTitle.isEmpty())
- sTitle.append(" - ");
+ {
+ OUString separator (FwkResId (STR_EMDASH_SEPARATOR));
+ sTitle.append(separator);
+ }
sTitle.append(name);
}
}
@@ -550,9 +552,9 @@ void TitleHelper::impl_appendModuleName (OUStringBuffer& sTitle)
css::uno::Reference< css::uno::XComponentContext > xContext;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
- xOwner = m_xOwner.get();
+ xOwner = m_xOwner;
xContext = m_xContext;
}
// <- SYNCHRONIZED
@@ -579,6 +581,7 @@ void TitleHelper::impl_appendModuleName (OUStringBuffer& sTitle)
}
#ifdef DBG_UTIL
+// static
void TitleHelper::impl_appendDebugVersion (OUStringBuffer& sTitle)
{
OUString version(utl::ConfigManager::getProductVersion());
@@ -595,6 +598,7 @@ void TitleHelper::impl_appendDebugVersion (OUStringBuffer&)
}
#endif
+// static
void TitleHelper::impl_appendSafeMode (OUStringBuffer& sTitle)
{
if (Application::IsSafeModeEnabled())
@@ -634,10 +638,10 @@ void TitleHelper::impl_setSubTitle (const css::uno::Reference< css::frame::XTitl
css::uno::Reference< css::frame::XTitle > xOldSubTitle;
// SYNCHRONIZED ->
{
- osl::MutexGuard aLock(m_aMutex);
+ std::unique_lock aLock(m_aMutex);
// ignore duplicate calls. Makes outside using of this helper more easy :-)
- xOldSubTitle.set(m_xSubTitle.get(), css::uno::UNO_QUERY);
+ xOldSubTitle = m_xSubTitle;
if (xOldSubTitle == xSubTitle)
return;
@@ -656,7 +660,8 @@ void TitleHelper::impl_setSubTitle (const css::uno::Reference< css::frame::XTitl
xNewBroadcaster->addTitleChangeListener (xThis);
}
-OUString TitleHelper::impl_convertURL2Title(const OUString& sURL)
+// static
+OUString TitleHelper::impl_convertURL2Title(std::u16string_view sURL)
{
INetURLObject aURL (sURL);
OUString sTitle;