25#include <com/sun/star/frame/UntitledNumbersConst.hpp>
26#include <com/sun/star/frame/XStorable.hpp>
27#include <com/sun/star/frame/ModuleManager.hpp>
28#include <com/sun/star/frame/XUntitledNumbers.hpp>
29#include <com/sun/star/frame/XModel3.hpp>
30#include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
36#include <rtl/ustrbuf.hxx>
37#include <osl/mutex.hxx>
44using namespace css::uno;
45using namespace css::frame;
50 const css::uno::Reference< css::uno::XInterface >& xOwner,
51 const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers)
52 : ::
cppu::BaseMutex ()
54 , m_bExternalTitle (false)
55 , m_nLeasedNumber (css::frame::UntitledNumbersConst::INVALID_NUMBER)
67 css::uno::Reference< css::frame::XModel >
xModel(xOwner, css::uno::UNO_QUERY);
74 css::uno::Reference< css::frame::XController >
xController(xOwner, css::uno::UNO_QUERY);
81 css::uno::Reference< css::frame::XFrame >
xFrame(xOwner, css::uno::UNO_QUERY);
143 css::uno::Reference< css::frame::XTitle > xSubTitle;
148 xSubTitle.set(
m_xSubTitle.get (), css::uno::UNO_QUERY);
152 if (
aEvent.Source != xSubTitle)
160 if ( !
aEvent.EventName.equalsIgnoreAsciiCase(
"OnSaveAsDone")
161 && !
aEvent.EventName.equalsIgnoreAsciiCase(
"OnModeChanged")
162 && !
aEvent.EventName.equalsIgnoreAsciiCase(
"OnTitleChanged"))
165 css::uno::Reference< css::frame::XModel > xOwner;
170 xOwner.set(
m_xOwner.get (), css::uno::UNO_QUERY);
174 if (
aEvent.Source != xOwner
175 || ((
aEvent.EventName.equalsIgnoreAsciiCase(
"OnModeChanged")
176 ||
aEvent.EventName.equalsIgnoreAsciiCase(
"OnTitleChanged"))
187 css::uno::Reference< css::frame::XFrame > xOwner;
192 xOwner.set(
m_xOwner.get (), css::uno::UNO_QUERY);
196 if (
aEvent.Source != xOwner)
202 (
aEvent.Action == css::frame::FrameAction_COMPONENT_ATTACHED ) ||
203 (
aEvent.Action == css::frame::FrameAction_COMPONENT_REATTACHED) ||
204 (
aEvent.Action == css::frame::FrameAction_COMPONENT_DETACHING )
214 css::uno::Reference< css::uno::XInterface > xOwner;
215 css::uno::Reference< css::frame::XUntitledNumbers > xNumbers;
216 ::sal_Int32 nLeasedNumber;
230 css::uno::Reference< css::frame::XFrame >
xFrame(xOwner, css::uno::UNO_QUERY);
232 xFrame->removeFrameActionListener(
this);
234 if (xOwner !=
aEvent.Source)
239 (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
241 xNumbers->releaseNumber (nLeasedNumber);
256 css::uno::Reference<css::uno::XInterface> xOwner;
267 if( !
aEvent.Source.is() )
281 catch(
const css::uno::Exception&)
290 css::uno::Reference< css::frame::XModel3 >
xModel;
291 css::uno::Reference< css::frame::XController >
xController;
292 css::uno::Reference< css::frame::XFrame >
xFrame;
319 css::uno::Reference< css::uno::XInterface > xOwner;
320 css::uno::Reference< css::frame::XUntitledNumbers > xNumbers;
321 ::sal_Int32 nLeasedNumber;
339 ( ! xNumbers.is ()) ||
347 css::uno::Reference< css::frame::XStorable > xURLProvider(
xModel , css::uno::UNO_QUERY);
348 if (xURLProvider.is())
349 sURL = xURLProvider->getLocation ();
358 if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
359 xNumbers->releaseNumber (nLeasedNumber);
360 nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
369 if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
370 nLeasedNumber = xNumbers->leaseNumber (xOwner);
372 if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
373 sTitle = xNumbers->getUntitledPrefix() + OUString::number(nLeasedNumber);
375 sTitle = xNumbers->getUntitledPrefix() +
"?";
398 css::uno::Reference< css::uno::XInterface > xOwner;
399 css::uno::Reference< css::frame::XUntitledNumbers > xNumbers;
400 ::sal_Int32 nLeasedNumber;
418 ( ! xNumbers.is ()) ||
423 OUStringBuffer sTitle(256);
425 if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
426 nLeasedNumber = xNumbers->leaseNumber (xOwner);
428 css::uno::Reference< css::frame::XTitle > xModelTitle(
xController->getModel (), css::uno::UNO_QUERY);
430 if (!xModelTitle.is ())
432 if (xModelTitle.is ())
434 sTitle.append (xModelTitle->getTitle ());
435 if ( nLeasedNumber > 1 )
437 sTitle.append(
" : " + OUString::number(nLeasedNumber));
442 if (
aURL.GetProtocol () != INetProtocol::File
443 &&
aURL.GetProtocol () != INetProtocol::NotValid)
445 OUString sRemoteText (
FwkResId (STR_REMOTE_TITLE));
446 sTitle.append (sRemoteText);
452 sTitle.append (xNumbers->getUntitledPrefix ());
453 if ( nLeasedNumber > 1 )
455 sTitle.append(nLeasedNumber );
464 OUString sNewTitle = sTitle.makeStringAndClear ();
491 css::uno::Reference< css::uno::XInterface > xComponent =
xFrame->getController ();
492 if ( ! xComponent.is ())
493 xComponent =
xFrame->getComponentWindow ();
495 OUStringBuffer sTitle (256);
515 OUString sNewTitle = sTitle.makeStringAndClear ();
526 const css::uno::Reference< css::uno::XInterface >& xComponent)
528 css::uno::Reference< css::frame::XTitle > xTitle(xComponent, css::uno::UNO_QUERY);
532 sTitle.append (xTitle->getTitle ());
540 if (!sTitle.isEmpty())
551 css::uno::Reference< css::uno::XInterface > xOwner;
552 css::uno::Reference< css::uno::XComponentContext > xContext;
564 css::uno::Reference< css::frame::XModuleManager2 > xModuleManager =
565 css::frame::ModuleManager::create(xContext);
567 const OUString sID = xModuleManager->identify(xOwner);
573 if (!sUIName.isEmpty())
575 sTitle.append (
" " );
576 sTitle.append (sUIName);
579 catch(
const css::uno::Exception&)
588 sTitle.append(version);
591 sTitle.append(sVersion);
603 sTitle.append(
FwkResId (STR_SAFEMODE_TITLE));
608 css::uno::Reference< css::document::XDocumentEventBroadcaster > xBroadcaster(
xModel, css::uno::UNO_QUERY);
609 if ( ! xBroadcaster.is ())
612 xBroadcaster->addDocumentEventListener (
static_cast< css::document::XDocumentEventListener*
>(
this));
617 xController->addEventListener (
static_cast< css::lang::XEventListener*
> (
static_cast< css::frame::XFrameActionListener*
> (
this) ) );
618 css::uno::Reference< css::frame::XTitle > xSubTitle(
xController->getModel (), css::uno::UNO_QUERY);
624 xFrame->addFrameActionListener(
this );
630 css::uno::Reference< css::frame::XTitle > xSubTitle(
xFrame->getController (), css::uno::UNO_QUERY);
636 css::uno::Reference< css::frame::XTitle > xOldSubTitle;
642 xOldSubTitle.set(
m_xSubTitle.get(), css::uno::UNO_QUERY);
643 if (xOldSubTitle == xSubTitle)
650 css::uno::Reference< css::frame::XTitleChangeBroadcaster > xOldBroadcaster(xOldSubTitle , css::uno::UNO_QUERY );
651 css::uno::Reference< css::frame::XTitleChangeBroadcaster > xNewBroadcaster(xSubTitle , css::uno::UNO_QUERY );
652 css::uno::Reference< css::frame::XTitleChangeListener > xThis(
this);
654 if (xOldBroadcaster.is())
655 xOldBroadcaster->removeTitleChangeListener (xThis);
657 if (xNewBroadcaster.is())
658 xNewBroadcaster->addTitleChangeListener (xThis);
666 if (
aURL.GetProtocol() == INetProtocol::File)
675 if (
aURL.hasExtension())
678 if ( sTitle.isEmpty() )
681 if ( sTitle.isEmpty() )
constexpr OUStringLiteral sSuggestedSaveAsName
FILE * init(int, char **)
static bool IsSafeModeEnabled()
css::uno::XInterface * next()
bool hasMoreElements() const
OInterfaceContainerHelper2 * getContainer(const css::uno::Type &rKey) const
sal_Int32 removeInterface(const css::uno::Type &rKey, const css::uno::Reference< css::uno::XInterface > &rxIFace)
sal_Int32 addInterface(const css::uno::Type &rKey, const css::uno::Reference< css::uno::XInterface > &r)
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
mutable::osl::Mutex m_aMutex
void impl_startListeningForModel(const css::uno::Reference< css::frame::XModel > &xModel)
virtual void SAL_CALL removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener > &xListener) override
TitleHelper(css::uno::Reference< css::uno::XComponentContext > xContext, const css::uno::Reference< css::uno::XInterface > &xOwner, const css::uno::Reference< css::frame::XUntitledNumbers > &xNumbers)
set an outside component which uses this container and must be set as source of all broadcasted messa...
void impl_startListeningForController(const css::uno::Reference< css::frame::XController > &xController)
comphelper::OMultiTypeInterfaceContainerHelper2 m_aListener
contains all title change listener
::sal_Int32 m_nLeasedNumber
knows the leased number which must be used for untitled components.
virtual ~TitleHelper() override
free all internally used resources.
void impl_appendProductName(OUStringBuffer &sTitle)
css::uno::Reference< css::uno::XComponentContext > m_xContext
points to the global uno service manager.
void impl_updateTitle(bool init=false)
virtual OUString SAL_CALL getTitle() override
void impl_updateListeningForFrame(const css::uno::Reference< css::frame::XFrame > &xFrame)
bool m_bExternalTitle
if it's set to sal_True the member m_sTitle has not to be changed internally.
css::uno::WeakReference< css::frame::XTitle > m_xSubTitle
provides parts of our own title and we listen there for changes too.
virtual void SAL_CALL documentEventOccured(const css::document::DocumentEvent &aEvent) override
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
void impl_updateTitleForController(const css::uno::Reference< css::frame::XController > &xController, bool init)
void impl_updateTitleForModel(const css::uno::Reference< css::frame::XModel3 > &xModel, bool init)
OUString impl_convertURL2Title(std::u16string_view sURL)
void impl_appendDebugVersion(OUStringBuffer &sTitle)
void impl_startListeningForFrame(const css::uno::Reference< css::frame::XFrame > &xFrame)
virtual void SAL_CALL addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener > &xListener) override
void impl_appendComponentTitle(OUStringBuffer &sTitle, const css::uno::Reference< css::uno::XInterface > &xComponent)
void impl_setSubTitle(const css::uno::Reference< css::frame::XTitle > &xSubTitle)
css::uno::WeakReference< css::uno::XInterface > m_xOwner
reference to the outside UNO class using this helper.
void impl_appendModuleName(OUStringBuffer &sTitle)
void impl_updateTitleForFrame(const css::uno::Reference< css::frame::XFrame > &xFrame, bool init)
virtual void SAL_CALL setTitle(const OUString &sTitle) override
css::uno::WeakReference< css::frame::XUntitledNumbers > m_xUntitledNumbers
used to know how an "Untitled X" string can be created right :-)
void impl_sendTitleChangedEvent()
void impl_appendSafeMode(OUStringBuffer &sTitle)
virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent &aEvent) override
OUString m_sTitle
the actual title value
virtual void SAL_CALL titleChanged(const css::frame::TitleChangedEvent &aEvent) override
static OUString getBuildIdData(OUString const &_sDefault)
static OUString getProductVersion()
static OUString getProductName()
WeakReference< XFlushListener > m_aListener
OUString FwkResId(TranslateId aId)
css::uno::Reference< css::uno::XComponentContext > m_xContext
constexpr OUStringLiteral OFFICEFACTORY_PROPNAME_ASCII_UINAME
properties for office module config (Setup.xcu)
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel