24#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
25#include <com/sun/star/document/XDocumentProperties.hpp>
26#include <com/sun/star/frame/XModel.hpp>
27#include <com/sun/star/frame/XStorable.hpp>
28#include <com/sun/star/frame/XTitle.hpp>
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::uno::UNO_QUERY;
39 using ::com::sun::star::uno::UNO_QUERY_THROW;
40 using ::com::sun::star::uno::Exception;
41 using ::com::sun::star::frame::XModel;
42 using ::com::sun::star::frame::XTitle;
43 using ::com::sun::star::frame::XController;
44 using ::com::sun::star::document::XDocumentPropertiesSupplier;
45 using ::com::sun::star::document::XDocumentProperties;
46 using ::com::sun::star::frame::XStorable;
47 using ::com::sun::star::uno::XInterface;
48 using ::com::sun::star::frame::XFrame;
52 OUString lcl_getTitle(
const Reference< XInterface >& _rxComponent )
54 Reference< XTitle > xTitle( _rxComponent, UNO_QUERY );
56 return xTitle->getTitle();
65 if ( !_rxDocument.is() )
71 sTitle = lcl_getTitle( _rxDocument );
72 if ( !sTitle.isEmpty() )
75 Reference< XController >
xController( _rxDocument->getCurrentController() );
76 sTitle = lcl_getTitle( xController );
77 if ( !sTitle.isEmpty() )
82 OUString sDocURL = _rxDocument->getURL();
83 if ( sDocURL.startsWithIgnoreAsciiCase(
"private:" ) )
87 if ( sDocURL.isEmpty() )
89 Reference< XFrame >
xFrame;
92 sTitle = lcl_getTitle( xFrame );
93 if ( !sTitle.isEmpty() )
98 Reference< XDocumentPropertiesSupplier > xDPS( _rxDocument, UNO_QUERY );
101 Reference< XDocumentProperties > xDocProps (
102 xDPS->getDocumentProperties(), css::uno::UNO_SET_THROW );
103 sTitle = xDocProps->getTitle();
104 if ( !sTitle.isEmpty() )
110 if ( !sTitle.isEmpty() )
118 if ( sDocURL.isEmpty() )
120 Reference< XStorable > xDocStorable( _rxDocument, UNO_QUERY_THROW );
121 sDocURL = xDocStorable->getLocation();
123 sal_Int32 nLastSepPos = sDocURL.lastIndexOf(
'/' );
124 if ( ( nLastSepPos != -1 ) && ( nLastSepPos == sDocURL.getLength() - 1 ) )
126 sDocURL = sDocURL.copy( 0, nLastSepPos );
127 nLastSepPos = sDocURL.lastIndexOf(
'/' );
129 sTitle = sDocURL.copy( nLastSepPos + 1 );
131 if ( !sTitle.isEmpty() )
137 Reference< XTitle > xTitle( _rxDocument, UNO_QUERY );
140 if ( !xTitle->getTitle().isEmpty() )
141 return xTitle->getTitle();
144 catch (
const Exception& )
147 css::uno::Any caught( ::cppu::getCaughtException() );
148 css::uno::Exception exception;
149 caught >>= exception;
150 SAL_WARN(
"comphelper",
"caught an exception!\ntype : " << caught.getValueTypeName()
151 <<
"\nmessage: " << exception
152 <<
"\nin function:\n" << __func__);
165 css::uno::Sequence<css::beans::PropertyValue> aMedDescr = rModel->getArgs();
166 sal_Int32 nNewLen = aMedDescr.getLength() + 1;
167 aMedDescr.realloc(nNewLen);
168 auto pMedDescr = aMedDescr.getArray();
169 pMedDescr[nNewLen-1].Name =
"MacroEventRead";
170 pMedDescr[nNewLen-1].Value <<=
true;
171 rModel->attachResource(rModel->getURL(), aMedDescr);
VALUE_TYPE getOrDefault(const OUString &_rValueName, const VALUE_TYPE &_rDefault) const
retrieves a value with a given name, or defaults it to a given value, if it's not present in the coll...
#define SAL_WARN(area, stream)
COMPHELPER_DLLPUBLIC void notifyMacroEventRead(const css::uno::Reference< css::frame::XModel > &_rxDocument)
notify that this document contains a macro event handler
COMPHELPER_DLLPUBLIC OUString getDocumentTitle(const css::uno::Reference< css::frame::XModel > &_rxDocument)
retrieves the UI title of the given document
Reference< XController > xController
Reference< XFrame > xFrame