extensions/source/propctrlr/browserline.cxx | 571 ++++++------ extensions/source/propctrlr/browserline.hxx | 160 +-- extensions/source/propctrlr/browserlistbox.cxx | 1163 ++++++++++++------------- extensions/source/propctrlr/browserlistbox.hxx | 192 +--- solenv/clang-format/excludelist | 4 5 files changed, 1034 insertions(+), 1056 deletions(-)
New commits: commit f27a7a675ef6c18085bd7a3b969eb78952ff6111 Author: Michael Weghorn <[email protected]> AuthorDate: Tue Jan 20 08:51:57 2026 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Thu Jan 22 11:13:33 2026 +0100 propctrlr: clang-format OBrowserListBox code This in particular gets rid of an extra indentation level. Change-Id: I7eadb3ff0f653bc3dd9c15f2fcffabdea8d89c3f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197627 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/extensions/source/propctrlr/browserlistbox.cxx b/extensions/source/propctrlr/browserlistbox.cxx index 7a3f04249ae6..aaeef509d10e 100644 --- a/extensions/source/propctrlr/browserlistbox.cxx +++ b/extensions/source/propctrlr/browserlistbox.cxx @@ -36,783 +36,780 @@ #include <vcl/weld/Entry.hxx> #include <osl/mutex.hxx> - namespace pcr { - using ::com::sun::star::uno::Any; - using ::com::sun::star::uno::Exception; - using ::com::sun::star::inspection::XPropertyControlContext; - using ::com::sun::star::uno::Reference; - using ::com::sun::star::inspection::XPropertyControl; - using ::com::sun::star::lang::DisposedException; - using ::com::sun::star::lang::XComponent; - using ::com::sun::star::uno::UNO_QUERY; - - namespace PropertyControlType = ::com::sun::star::inspection::PropertyControlType; - - namespace { - - enum ControlEventType - { - FOCUS_GAINED, - VALUE_CHANGED, - ACTIVATE_NEXT - }; - - struct ControlEvent : public ::comphelper::AnyEvent - { - Reference< XPropertyControl > xControl; - ControlEventType eType; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::inspection::XPropertyControlContext; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::inspection::XPropertyControl; +using ::com::sun::star::lang::DisposedException; +using ::com::sun::star::lang::XComponent; +using ::com::sun::star::uno::UNO_QUERY; + +namespace PropertyControlType = ::com::sun::star::inspection::PropertyControlType; + +namespace +{ +enum ControlEventType +{ + FOCUS_GAINED, + VALUE_CHANGED, + ACTIVATE_NEXT +}; - ControlEvent( const Reference< XPropertyControl >& _rxControl, ControlEventType _eType ) - :xControl( _rxControl ) - ,eType( _eType ) - { - } - }; +struct ControlEvent : public ::comphelper::AnyEvent +{ + Reference<XPropertyControl> xControl; + ControlEventType eType; - class SharedNotifier + ControlEvent(const Reference<XPropertyControl>& _rxControl, ControlEventType _eType) + : xControl(_rxControl) + , eType(_eType) { - private: - static ::osl::Mutex& getMutex(); - static ::rtl::Reference< ::comphelper::AsyncEventNotifier > s_pNotifier; - - public: - SharedNotifier(const SharedNotifier&) = delete; - SharedNotifier& operator=(const SharedNotifier&) = delete; - static const ::rtl::Reference< ::comphelper::AsyncEventNotifier >& - getNotifier(); - }; - } +}; - ::rtl::Reference< ::comphelper::AsyncEventNotifier > SharedNotifier::s_pNotifier; +class SharedNotifier +{ +private: + static ::osl::Mutex& getMutex(); + static ::rtl::Reference<::comphelper::AsyncEventNotifier> s_pNotifier; +public: + SharedNotifier(const SharedNotifier&) = delete; + SharedNotifier& operator=(const SharedNotifier&) = delete; + static const ::rtl::Reference<::comphelper::AsyncEventNotifier>& getNotifier(); +}; +} - ::osl::Mutex& SharedNotifier::getMutex() - { - static ::osl::Mutex s_aMutex; - return s_aMutex; - } +::rtl::Reference<::comphelper::AsyncEventNotifier> SharedNotifier::s_pNotifier; +::osl::Mutex& SharedNotifier::getMutex() +{ + static ::osl::Mutex s_aMutex; + return s_aMutex; +} - const ::rtl::Reference< ::comphelper::AsyncEventNotifier >& SharedNotifier::getNotifier() +const ::rtl::Reference<::comphelper::AsyncEventNotifier>& SharedNotifier::getNotifier() +{ + ::osl::MutexGuard aGuard(getMutex()); + if (!s_pNotifier.is()) { - ::osl::MutexGuard aGuard( getMutex() ); - if ( !s_pNotifier.is() ) - { - s_pNotifier.set( - new ::comphelper::AsyncEventNotifier("browserlistbox")); - s_pNotifier->launch(); - //TODO: a protocol is missing how to join with the launched - // thread before exit(3), to ensure the thread is no longer - // relying on any infrastructure while that infrastructure is - // being shut down in atexit handlers - } - return s_pNotifier; + s_pNotifier.set(new ::comphelper::AsyncEventNotifier("browserlistbox")); + s_pNotifier->launch(); + //TODO: a protocol is missing how to join with the launched + // thread before exit(3), to ensure the thread is no longer + // relying on any infrastructure while that infrastructure is + // being shut down in atexit handlers } + return s_pNotifier; +} - - /** implementation for of <type scope="css::inspection">XPropertyControlContext</type> +/** implementation for of <type scope="css::inspection">XPropertyControlContext</type> which forwards all events to a non-UNO version of this interface */ - typedef ::cppu::WeakImplHelper< XPropertyControlContext > PropertyControlContext_Impl_Base; - class PropertyControlContext_Impl :public PropertyControlContext_Impl_Base - ,public ::comphelper::IEventProcessor +typedef ::cppu::WeakImplHelper<XPropertyControlContext> PropertyControlContext_Impl_Base; +class PropertyControlContext_Impl : public PropertyControlContext_Impl_Base, + public ::comphelper::IEventProcessor +{ +public: + enum NotificationMode { - public: - enum NotificationMode - { - eSynchronously, - eAsynchronously - }; + eSynchronously, + eAsynchronously + }; - private: - OBrowserListBox* m_pContext; - NotificationMode m_eMode; +private: + OBrowserListBox* m_pContext; + NotificationMode m_eMode; - public: - /** creates an instance +public: + /** creates an instance @param _rContextImpl the instance to delegate events to */ - explicit PropertyControlContext_Impl( OBrowserListBox& _rContextImpl ); + explicit PropertyControlContext_Impl(OBrowserListBox& _rContextImpl); - /** disposes the context. + /** disposes the context. When you call this method, all subsequent callbacks to the <type scope="css::inspection">XPropertyControlContext</type> methods will throw a <type scope="css::lang">DisposedException</type>. */ - void dispose(); + void dispose(); - /** sets the notification mode, so that notifications received from the controls are + /** sets the notification mode, so that notifications received from the controls are forwarded to our OBrowserListBox either synchronously or asynchronously @param _eMode the new notification mode */ - void setNotificationMode( NotificationMode _eMode ); + void setNotificationMode(NotificationMode _eMode); - virtual void SAL_CALL acquire() noexcept override; - virtual void SAL_CALL release() noexcept override; + virtual void SAL_CALL acquire() noexcept override; + virtual void SAL_CALL release() noexcept override; - protected: - virtual ~PropertyControlContext_Impl() override; +protected: + virtual ~PropertyControlContext_Impl() override; - // XPropertyControlObserver - virtual void SAL_CALL focusGained( const Reference< XPropertyControl >& Control ) override; - virtual void SAL_CALL valueChanged( const Reference< XPropertyControl >& Control ) override; - // XPropertyControlContext - virtual void SAL_CALL activateNextControl( const Reference< XPropertyControl >& CurrentControl ) override; + // XPropertyControlObserver + virtual void SAL_CALL focusGained(const Reference<XPropertyControl>& Control) override; + virtual void SAL_CALL valueChanged(const Reference<XPropertyControl>& Control) override; + // XPropertyControlContext + virtual void SAL_CALL + activateNextControl(const Reference<XPropertyControl>& CurrentControl) override; - // IEventProcessor - virtual void processEvent( const ::comphelper::AnyEvent& _rEvent ) override; + // IEventProcessor + virtual void processEvent(const ::comphelper::AnyEvent& _rEvent) override; - private: - /** processes the given event, i.e. notifies it to our OBrowserListBox +private: + /** processes the given event, i.e. notifies it to our OBrowserListBox @param _rEvent the event no notify @precond our mutex (well, the SolarMutex) is locked */ - void impl_processEvent_throw( const ::comphelper::AnyEvent& _rEvent ); + void impl_processEvent_throw(const ::comphelper::AnyEvent& _rEvent); - /** checks whether the instance is already disposed + /** checks whether the instance is already disposed */ - bool impl_isDisposed_nothrow() const { return m_pContext == nullptr; } + bool impl_isDisposed_nothrow() const { return m_pContext == nullptr; } - /** notifies the given event originating from the given control + /** notifies the given event originating from the given control @throws DisposedException @param _rxControl @param _eType */ - void impl_notify_throw( const Reference< XPropertyControl >& _rxControl, ControlEventType _eType ); - }; + void impl_notify_throw(const Reference<XPropertyControl>& _rxControl, ControlEventType _eType); +}; - PropertyControlContext_Impl::PropertyControlContext_Impl( OBrowserListBox& _rContextImpl ) - : m_pContext( &_rContextImpl ) - , m_eMode( eAsynchronously ) - { - } +PropertyControlContext_Impl::PropertyControlContext_Impl(OBrowserListBox& _rContextImpl) + : m_pContext(&_rContextImpl) + , m_eMode(eAsynchronously) +{ +} - PropertyControlContext_Impl::~PropertyControlContext_Impl() - { - if ( !impl_isDisposed_nothrow() ) - dispose(); - } +PropertyControlContext_Impl::~PropertyControlContext_Impl() +{ + if (!impl_isDisposed_nothrow()) + dispose(); +} - void PropertyControlContext_Impl::dispose() - { - SolarMutexGuard aGuard; - if ( impl_isDisposed_nothrow() ) - return; +void PropertyControlContext_Impl::dispose() +{ + SolarMutexGuard aGuard; + if (impl_isDisposed_nothrow()) + return; - SharedNotifier::getNotifier()->removeEventsForProcessor( this ); - m_pContext = nullptr; - } + SharedNotifier::getNotifier()->removeEventsForProcessor(this); + m_pContext = nullptr; +} - void PropertyControlContext_Impl::setNotificationMode( NotificationMode _eMode ) - { - SolarMutexGuard aGuard; - m_eMode = _eMode; - } +void PropertyControlContext_Impl::setNotificationMode(NotificationMode _eMode) +{ + SolarMutexGuard aGuard; + m_eMode = _eMode; +} + +void PropertyControlContext_Impl::impl_notify_throw(const Reference<XPropertyControl>& _rxControl, + ControlEventType _eType) +{ + ::comphelper::AnyEventRef pEvent; - void PropertyControlContext_Impl::impl_notify_throw( const Reference< XPropertyControl >& _rxControl, ControlEventType _eType ) { - ::comphelper::AnyEventRef pEvent; + SolarMutexGuard aGuard; + if (impl_isDisposed_nothrow()) + throw DisposedException(OUString(), *this); + pEvent = new ControlEvent(_rxControl, _eType); + if (m_eMode == eSynchronously) { - SolarMutexGuard aGuard; - if ( impl_isDisposed_nothrow() ) - throw DisposedException( OUString(), *this ); - pEvent = new ControlEvent( _rxControl, _eType ); - - if ( m_eMode == eSynchronously ) - { - impl_processEvent_throw( *pEvent ); - return; - } + impl_processEvent_throw(*pEvent); + return; } - - SharedNotifier::getNotifier()->addEvent( pEvent, this ); } - void SAL_CALL PropertyControlContext_Impl::focusGained( const Reference< XPropertyControl >& Control ) - { - impl_notify_throw( Control, FOCUS_GAINED ); - } + SharedNotifier::getNotifier()->addEvent(pEvent, this); +} - void SAL_CALL PropertyControlContext_Impl::valueChanged( const Reference< XPropertyControl >& Control ) - { - impl_notify_throw( Control, VALUE_CHANGED ); - } +void SAL_CALL PropertyControlContext_Impl::focusGained(const Reference<XPropertyControl>& Control) +{ + impl_notify_throw(Control, FOCUS_GAINED); +} - void SAL_CALL PropertyControlContext_Impl::activateNextControl( const Reference< XPropertyControl >& CurrentControl ) - { - impl_notify_throw( CurrentControl, ACTIVATE_NEXT ); - } +void SAL_CALL PropertyControlContext_Impl::valueChanged(const Reference<XPropertyControl>& Control) +{ + impl_notify_throw(Control, VALUE_CHANGED); +} - void SAL_CALL PropertyControlContext_Impl::acquire() noexcept - { - PropertyControlContext_Impl_Base::acquire(); - } +void SAL_CALL +PropertyControlContext_Impl::activateNextControl(const Reference<XPropertyControl>& CurrentControl) +{ + impl_notify_throw(CurrentControl, ACTIVATE_NEXT); +} - void SAL_CALL PropertyControlContext_Impl::release() noexcept +void SAL_CALL PropertyControlContext_Impl::acquire() noexcept +{ + PropertyControlContext_Impl_Base::acquire(); +} + +void SAL_CALL PropertyControlContext_Impl::release() noexcept +{ + PropertyControlContext_Impl_Base::release(); +} + +void PropertyControlContext_Impl::processEvent(const ::comphelper::AnyEvent& _rEvent) +{ + SolarMutexGuard aGuard; + if (impl_isDisposed_nothrow()) + return; + + try { - PropertyControlContext_Impl_Base::release(); + impl_processEvent_throw(_rEvent); } - - void PropertyControlContext_Impl::processEvent( const ::comphelper::AnyEvent& _rEvent ) + catch (const Exception&) { - SolarMutexGuard aGuard; - if ( impl_isDisposed_nothrow() ) - return; - - try - { - impl_processEvent_throw( _rEvent ); - } - catch( const Exception& ) - { - // can't handle otherwise, since our caller (the notification thread) does not allow - // for exceptions (it could itself abort only) - DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); - } + // can't handle otherwise, since our caller (the notification thread) does not allow + // for exceptions (it could itself abort only) + DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); } +} - void PropertyControlContext_Impl::impl_processEvent_throw( const ::comphelper::AnyEvent& _rEvent ) +void PropertyControlContext_Impl::impl_processEvent_throw(const ::comphelper::AnyEvent& _rEvent) +{ + const ControlEvent& rControlEvent = static_cast<const ControlEvent&>(_rEvent); + switch (rControlEvent.eType) { - const ControlEvent& rControlEvent = static_cast< const ControlEvent& >( _rEvent ); - switch ( rControlEvent.eType ) - { case FOCUS_GAINED: - m_pContext->focusGained( rControlEvent.xControl ); + m_pContext->focusGained(rControlEvent.xControl); break; case VALUE_CHANGED: - m_pContext->valueChanged( rControlEvent.xControl ); + m_pContext->valueChanged(rControlEvent.xControl); break; case ACTIVATE_NEXT: - m_pContext->activateNextControl( rControlEvent.xControl ); + m_pContext->activateNextControl(rControlEvent.xControl); break; - } } +} + +OBrowserListBox::OBrowserListBox(weld::Builder& rBuilder, weld::Container* pContainer) + : m_xScrolledWindow(rBuilder.weld_scrolled_window(u"scrolledwindow"_ustr)) + , m_xLinesPlayground(rBuilder.weld_box(u"playground"_ustr)) + , m_xSizeGroup(rBuilder.create_size_group()) + , m_xHelpWindow(new InspectorHelpWindow(rBuilder)) + , m_pInitialControlParent(pContainer) + , m_pLineListener(nullptr) + , m_pControlObserver(nullptr) + , m_nTheNameSize(0) + , m_nRowHeight(0) + , m_pControlContextImpl(new PropertyControlContext_Impl(*this)) +{ + m_xScrolledWindow->set_size_request(-1, m_xScrolledWindow->get_text_height() * 20); +} - OBrowserListBox::OBrowserListBox(weld::Builder& rBuilder, weld::Container* pContainer) - : m_xScrolledWindow(rBuilder.weld_scrolled_window(u"scrolledwindow"_ustr)) - , m_xLinesPlayground(rBuilder.weld_box(u"playground"_ustr)) - , m_xSizeGroup(rBuilder.create_size_group()) - , m_xHelpWindow(new InspectorHelpWindow(rBuilder)) - , m_pInitialControlParent(pContainer) - , m_pLineListener(nullptr) - , m_pControlObserver( nullptr ) - , m_nTheNameSize(0) - , m_nRowHeight(0) - , m_pControlContextImpl( new PropertyControlContext_Impl( *this ) ) - { - m_xScrolledWindow->set_size_request(-1, m_xScrolledWindow->get_text_height() * 20); - } +OBrowserListBox::~OBrowserListBox() +{ + OSL_ENSURE( + !IsModified(), + "OBrowserListBox::~OBrowserListBox: still modified - should have been committed before!"); - OBrowserListBox::~OBrowserListBox() - { - OSL_ENSURE( !IsModified(), "OBrowserListBox::~OBrowserListBox: still modified - should have been committed before!" ); + // doing the commit here, while we, as well as our owner, as well as some other components, + // are already "half dead" (means within their dtor) is potentially dangerous. + // By definition, CommitModified has to be called (if necessary) before destruction + m_pControlContextImpl->dispose(); + m_pControlContextImpl.clear(); - // doing the commit here, while we, as well as our owner, as well as some other components, - // are already "half dead" (means within their dtor) is potentially dangerous. - // By definition, CommitModified has to be called (if necessary) before destruction - m_pControlContextImpl->dispose(); - m_pControlContextImpl.clear(); + Clear(); +} - Clear(); - } +bool OBrowserListBox::IsModified() const +{ + bool bModified = false; - bool OBrowserListBox::IsModified() const - { - bool bModified = false; + if (m_xScrolledWindow->get_visible() && m_xActiveControl.is()) + bModified = m_xActiveControl->isModified(); - if (m_xScrolledWindow->get_visible() && m_xActiveControl.is()) - bModified = m_xActiveControl->isModified(); + return bModified; +} - return bModified; - } +void OBrowserListBox::CommitModified() +{ + if (!(IsModified() && m_xActiveControl.is())) + return; - void OBrowserListBox::CommitModified( ) + // for the time of this commit, notify all events synchronously + // #i63814# + m_pControlContextImpl->setNotificationMode(PropertyControlContext_Impl::eSynchronously); + try { - if ( !(IsModified() && m_xActiveControl.is()) ) - return; - - // for the time of this commit, notify all events synchronously - // #i63814# - m_pControlContextImpl->setNotificationMode( PropertyControlContext_Impl::eSynchronously ); - try - { - m_xActiveControl->notifyModifiedValue(); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); - } - m_pControlContextImpl->setNotificationMode( PropertyControlContext_Impl::eAsynchronously ); + m_xActiveControl->notifyModifiedValue(); } - - void OBrowserListBox::SetListener( IPropertyLineListener* _pListener ) + catch (const Exception&) { - m_pLineListener = _pListener; + DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); } + m_pControlContextImpl->setNotificationMode(PropertyControlContext_Impl::eAsynchronously); +} - void OBrowserListBox::SetObserver( IPropertyControlObserver* _pObserver ) - { - m_pControlObserver = _pObserver; - } +void OBrowserListBox::SetListener(IPropertyLineListener* _pListener) +{ + m_pLineListener = _pListener; +} - void OBrowserListBox::EnableHelpSection( bool _bEnable ) - { - m_xHelpWindow->Show( _bEnable ); - } +void OBrowserListBox::SetObserver(IPropertyControlObserver* _pObserver) +{ + m_pControlObserver = _pObserver; +} - bool OBrowserListBox::HasHelpSection() const - { - return m_xHelpWindow->IsVisible(); - } +void OBrowserListBox::EnableHelpSection(bool _bEnable) { m_xHelpWindow->Show(_bEnable); } - void OBrowserListBox::SetHelpText( const OUString& _rHelpText ) - { - OSL_ENSURE( HasHelpSection(), "OBrowserListBox::SetHelpText: help section not visible!" ); - m_xHelpWindow->SetText( _rHelpText ); - } +bool OBrowserListBox::HasHelpSection() const { return m_xHelpWindow->IsVisible(); } - void OBrowserListBox::UpdatePlayGround() - { - for (auto& line : m_aLines) - line.pLine->SetTitleWidth(m_nTheNameSize); - } +void OBrowserListBox::SetHelpText(const OUString& _rHelpText) +{ + OSL_ENSURE(HasHelpSection(), "OBrowserListBox::SetHelpText: help section not visible!"); + m_xHelpWindow->SetText(_rHelpText); +} - void OBrowserListBox::SetPropertyValue(const OUString& _rEntryName, const Any& _rValue, bool _bUnknownValue ) - { - ListBoxLines::iterator line = std::find_if(m_aLines.begin(), m_aLines.end(), - [&_rEntryName](const ListBoxLine& rLine) { return rLine.aName == _rEntryName; }); +void OBrowserListBox::UpdatePlayGround() +{ + for (auto& line : m_aLines) + line.pLine->SetTitleWidth(m_nTheNameSize); +} + +void OBrowserListBox::SetPropertyValue(const OUString& _rEntryName, const Any& _rValue, + bool _bUnknownValue) +{ + ListBoxLines::iterator line + = std::find_if(m_aLines.begin(), m_aLines.end(), [&_rEntryName](const ListBoxLine& rLine) { + return rLine.aName == _rEntryName; + }); - if ( line != m_aLines.end() ) + if (line != m_aLines.end()) + { + if (_bUnknownValue) { - if ( _bUnknownValue ) - { - Reference< XPropertyControl > xControl( line->pLine->getControl() ); - OSL_ENSURE( xControl.is(), "OBrowserListBox::SetPropertyValue: illegal control!" ); - if ( xControl.is() ) - xControl->setValue( Any() ); - } - else - impl_setControlAsPropertyValue( *line, _rValue ); + Reference<XPropertyControl> xControl(line->pLine->getControl()); + OSL_ENSURE(xControl.is(), "OBrowserListBox::SetPropertyValue: illegal control!"); + if (xControl.is()) + xControl->setValue(Any()); } + else + impl_setControlAsPropertyValue(*line, _rValue); } +} - sal_uInt16 OBrowserListBox::GetPropertyPos( std::u16string_view _rEntryName ) const +sal_uInt16 OBrowserListBox::GetPropertyPos(std::u16string_view _rEntryName) const +{ + sal_uInt16 nPos = 0; + for (auto const& line : m_aLines) { - sal_uInt16 nPos = 0; - for (auto const& line : m_aLines) + if (line.aName == _rEntryName) { - if ( line.aName == _rEntryName ) - { - return nPos; - } - ++nPos; + return nPos; } - - return EDITOR_LIST_ENTRY_NOTFOUND; + ++nPos; } - bool OBrowserListBox::impl_getBrowserLineForName( const OUString& _rEntryName, BrowserLinePointer& _out_rpLine ) const - { - ListBoxLines::const_iterator line = std::find_if(m_aLines.begin(), m_aLines.end(), - [&_rEntryName](const ListBoxLine& rLine) { return rLine.aName == _rEntryName; }); + return EDITOR_LIST_ENTRY_NOTFOUND; +} - if ( line != m_aLines.end() ) - _out_rpLine = line->pLine; - else - _out_rpLine.reset(); - return bool(_out_rpLine); - } +bool OBrowserListBox::impl_getBrowserLineForName(const OUString& _rEntryName, + BrowserLinePointer& _out_rpLine) const +{ + ListBoxLines::const_iterator line + = std::find_if(m_aLines.begin(), m_aLines.end(), [&_rEntryName](const ListBoxLine& rLine) { + return rLine.aName == _rEntryName; + }); + + if (line != m_aLines.end()) + _out_rpLine = line->pLine; + else + _out_rpLine.reset(); + return bool(_out_rpLine); +} + +void OBrowserListBox::EnablePropertyControls(const OUString& _rEntryName, sal_Int16 _nControls, + bool _bEnable) +{ + BrowserLinePointer pLine; + if (impl_getBrowserLineForName(_rEntryName, pLine)) + pLine->EnablePropertyControls(_nControls, _bEnable); +} - void OBrowserListBox::EnablePropertyControls( const OUString& _rEntryName, sal_Int16 _nControls, bool _bEnable ) - { - BrowserLinePointer pLine; - if ( impl_getBrowserLineForName( _rEntryName, pLine ) ) - pLine->EnablePropertyControls( _nControls, _bEnable ); - } +void OBrowserListBox::EnablePropertyLine(const OUString& _rEntryName, bool _bEnable) +{ + BrowserLinePointer pLine; + if (impl_getBrowserLineForName(_rEntryName, pLine)) + pLine->EnablePropertyLine(_bEnable); +} - void OBrowserListBox::EnablePropertyLine( const OUString& _rEntryName, bool _bEnable ) - { - BrowserLinePointer pLine; - if ( impl_getBrowserLineForName( _rEntryName, pLine ) ) - pLine->EnablePropertyLine( _bEnable ); - } +Reference<XPropertyControl> OBrowserListBox::GetPropertyControl(const OUString& _rEntryName) +{ + BrowserLinePointer pLine; + if (impl_getBrowserLineForName(_rEntryName, pLine)) + return pLine->getControl(); + return nullptr; +} - Reference< XPropertyControl > OBrowserListBox::GetPropertyControl( const OUString& _rEntryName ) - { - BrowserLinePointer pLine; - if ( impl_getBrowserLineForName( _rEntryName, pLine ) ) - return pLine->getControl(); - return nullptr; - } +void OBrowserListBox::InsertEntry(const OLineDescriptor& rPropertyData, sal_uInt16 _nPos) +{ + // create a new line + BrowserLinePointer pBrowserLine = std::make_shared<OBrowserLine>( + rPropertyData.sName, m_xLinesPlayground.get(), m_xSizeGroup.get(), m_pInitialControlParent); - void OBrowserListBox::InsertEntry(const OLineDescriptor& rPropertyData, sal_uInt16 _nPos) + // check that the name is unique + for (auto const& line : m_aLines) { - // create a new line - BrowserLinePointer pBrowserLine = std::make_shared<OBrowserLine>(rPropertyData.sName, m_xLinesPlayground.get(), - m_xSizeGroup.get(), m_pInitialControlParent); - - // check that the name is unique - for (auto const& line : m_aLines) + if (line.aName == rPropertyData.sName) { - if (line.aName == rPropertyData.sName) - { - // already have another line for this name! - assert(false); - } + // already have another line for this name! + assert(false); } + } - ListBoxLine aNewLine( rPropertyData.sName, pBrowserLine, rPropertyData.xPropertyHandler ); - ListBoxLines::size_type nInsertPos = _nPos; - if ( _nPos >= m_aLines.size() ) - { - nInsertPos = m_aLines.size(); - m_aLines.push_back(std::move(aNewLine)); - } - else - m_aLines.insert( m_aLines.begin() + _nPos, aNewLine ); + ListBoxLine aNewLine(rPropertyData.sName, pBrowserLine, rPropertyData.xPropertyHandler); + ListBoxLines::size_type nInsertPos = _nPos; + if (_nPos >= m_aLines.size()) + { + nInsertPos = m_aLines.size(); + m_aLines.push_back(std::move(aNewLine)); + } + else + m_aLines.insert(m_aLines.begin() + _nPos, aNewLine); - pBrowserLine->SetTitleWidth(m_nTheNameSize); + pBrowserLine->SetTitleWidth(m_nTheNameSize); - // initialize the entry - ChangeEntry(rPropertyData, nInsertPos); + // initialize the entry + ChangeEntry(rPropertyData, nInsertPos); - m_nRowHeight = std::max(m_nRowHeight, pBrowserLine->GetRowHeight() + 6); // 6 is spacing of the "playground" in browserpage.ui - m_xScrolledWindow->vadjustment_set_step_increment(m_nRowHeight); - } + m_nRowHeight + = std::max(m_nRowHeight, pBrowserLine->GetRowHeight() + + 6); // 6 is spacing of the "playground" in browserpage.ui + m_xScrolledWindow->vadjustment_set_step_increment(m_nRowHeight); +} - void OBrowserListBox::ShowEntry(sal_uInt16 nPos) +void OBrowserListBox::ShowEntry(sal_uInt16 nPos) +{ + if (nPos == 0) { - if (nPos == 0) - { - // special case the simple entry 0 situation - m_xScrolledWindow->vadjustment_set_value(0); - return; - } + // special case the simple entry 0 situation + m_xScrolledWindow->vadjustment_set_value(0); + return; + } - if (nPos >= m_aLines.size()) - return; + if (nPos >= m_aLines.size()) + return; - unsigned const nWinHeight = m_xScrolledWindow->vadjustment_get_page_size(); + unsigned const nWinHeight = m_xScrolledWindow->vadjustment_get_page_size(); - auto nThumbPos = m_xScrolledWindow->vadjustment_get_value(); - int const nWinTop = nThumbPos; - int const nWinBottom = nWinTop + nWinHeight; + auto nThumbPos = m_xScrolledWindow->vadjustment_get_value(); + int const nWinTop = nThumbPos; + int const nWinBottom = nWinTop + nWinHeight; - auto nCtrlPosY = nPos * m_nRowHeight; + auto nCtrlPosY = nPos * m_nRowHeight; - int const nSelectedItemTop = nCtrlPosY; - int const nSelectedItemBottom = nCtrlPosY + m_nRowHeight; - bool const shouldScrollDown = nSelectedItemBottom >= nWinBottom; - bool const shouldScrollUp = nSelectedItemTop <= nWinTop; - bool const isNeedToScroll = shouldScrollDown || shouldScrollUp; + int const nSelectedItemTop = nCtrlPosY; + int const nSelectedItemBottom = nCtrlPosY + m_nRowHeight; + bool const shouldScrollDown = nSelectedItemBottom >= nWinBottom; + bool const shouldScrollUp = nSelectedItemTop <= nWinTop; + bool const isNeedToScroll = shouldScrollDown || shouldScrollUp; - if (!isNeedToScroll) - return; + if (!isNeedToScroll) + return; - if (shouldScrollDown) - { - int nOffset = nSelectedItemBottom - nWinBottom; - nThumbPos += nOffset; - } - else - { - int nOffset = nWinTop - nSelectedItemTop; - nThumbPos -= nOffset; - if(nThumbPos < 0) - nThumbPos = 0; - } - m_xScrolledWindow->vadjustment_set_value(nThumbPos); + if (shouldScrollDown) + { + int nOffset = nSelectedItemBottom - nWinBottom; + nThumbPos += nOffset; } - - void OBrowserListBox::buttonClicked( OBrowserLine* _pLine, bool _bPrimary ) + else { - DBG_ASSERT( _pLine, "OBrowserListBox::buttonClicked: invalid browser line!" ); - if ( _pLine && m_pLineListener ) - { - m_pLineListener->Clicked( _pLine->GetEntryName(), _bPrimary ); - } + int nOffset = nWinTop - nSelectedItemTop; + nThumbPos -= nOffset; + if (nThumbPos < 0) + nThumbPos = 0; } + m_xScrolledWindow->vadjustment_set_value(nThumbPos); +} - void OBrowserListBox::impl_setControlAsPropertyValue( const ListBoxLine& _rLine, const Any& _rPropertyValue ) +void OBrowserListBox::buttonClicked(OBrowserLine* _pLine, bool _bPrimary) +{ + DBG_ASSERT(_pLine, "OBrowserListBox::buttonClicked: invalid browser line!"); + if (_pLine && m_pLineListener) { - Reference< XPropertyControl > xControl( _rLine.pLine->getControl() ); - try - { - if ( _rPropertyValue.getValueType().equals( _rLine.pLine->getControl()->getValueType() ) ) - { - xControl->setValue( _rPropertyValue ); - } - else - { - SAL_WARN_IF( !_rLine.xHandler.is(), "extensions.propctrlr", - "OBrowserListBox::impl_setControlAsPropertyValue: no handler -> no conversion (property: '" - << _rLine.pLine->GetEntryName() << "')!" ); - if ( _rLine.xHandler.is() ) - { - Any aControlValue = _rLine.xHandler->convertToControlValue( - _rLine.pLine->GetEntryName(), _rPropertyValue, xControl->getValueType() ); - xControl->setValue( aControlValue ); - } - } - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); - } + m_pLineListener->Clicked(_pLine->GetEntryName(), _bPrimary); } +} - Any OBrowserListBox::impl_getControlAsPropertyValue( const ListBoxLine& _rLine ) +void OBrowserListBox::impl_setControlAsPropertyValue(const ListBoxLine& _rLine, + const Any& _rPropertyValue) +{ + Reference<XPropertyControl> xControl(_rLine.pLine->getControl()); + try { - Reference< XPropertyControl > xControl( _rLine.pLine->getControl() ); - Any aPropertyValue; - try + if (_rPropertyValue.getValueType().equals(_rLine.pLine->getControl()->getValueType())) { - SAL_WARN_IF( !_rLine.xHandler.is(), "extensions.propctrlr", - "OBrowserListBox::impl_getControlAsPropertyValue: no handler -> no conversion (property: '" - << _rLine.pLine->GetEntryName() << "')!" ); - if ( _rLine.xHandler.is() ) - aPropertyValue = _rLine.xHandler->convertToPropertyValue( _rLine.pLine->GetEntryName(), xControl->getValue() ); - else - aPropertyValue = xControl->getValue(); + xControl->setValue(_rPropertyValue); } - catch( const Exception& ) + else { - DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); + SAL_WARN_IF(!_rLine.xHandler.is(), "extensions.propctrlr", + "OBrowserListBox::impl_setControlAsPropertyValue: no handler -> no " + "conversion (property: '" + << _rLine.pLine->GetEntryName() << "')!"); + if (_rLine.xHandler.is()) + { + Any aControlValue = _rLine.xHandler->convertToControlValue( + _rLine.pLine->GetEntryName(), _rPropertyValue, xControl->getValueType()); + xControl->setValue(aControlValue); + } } - return aPropertyValue; } - - sal_uInt16 OBrowserListBox::impl_getControlPos( const Reference< XPropertyControl >& _rxControl ) const + catch (const Exception&) { - sal_uInt16 nPos = 0; - for (auto const& search : m_aLines) - { - if ( search.pLine->getControl().get() == _rxControl.get() ) - return nPos; - ++nPos; - } - OSL_FAIL( "OBrowserListBox::impl_getControlPos: invalid control - not part of any of our lines!" ); - return sal_uInt16(-1); + DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); } +} +Any OBrowserListBox::impl_getControlAsPropertyValue(const ListBoxLine& _rLine) +{ + Reference<XPropertyControl> xControl(_rLine.pLine->getControl()); + Any aPropertyValue; + try + { + SAL_WARN_IF(!_rLine.xHandler.is(), "extensions.propctrlr", + "OBrowserListBox::impl_getControlAsPropertyValue: no handler -> no conversion " + "(property: '" + << _rLine.pLine->GetEntryName() << "')!"); + if (_rLine.xHandler.is()) + aPropertyValue = _rLine.xHandler->convertToPropertyValue(_rLine.pLine->GetEntryName(), + xControl->getValue()); + else + aPropertyValue = xControl->getValue(); + } + catch (const Exception&) + { + DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); + } + return aPropertyValue; +} - void OBrowserListBox::focusGained( const Reference< XPropertyControl >& _rxControl ) +sal_uInt16 OBrowserListBox::impl_getControlPos(const Reference<XPropertyControl>& _rxControl) const +{ + sal_uInt16 nPos = 0; + for (auto const& search : m_aLines) { - DBG_TESTSOLARMUTEX(); + if (search.pLine->getControl().get() == _rxControl.get()) + return nPos; + ++nPos; + } + OSL_FAIL( + "OBrowserListBox::impl_getControlPos: invalid control - not part of any of our lines!"); + return sal_uInt16(-1); +} - DBG_ASSERT( _rxControl.is(), "OBrowserListBox::focusGained: invalid event source!" ); - if ( !_rxControl.is() ) - return; +void OBrowserListBox::focusGained(const Reference<XPropertyControl>& _rxControl) +{ + DBG_TESTSOLARMUTEX(); - if ( m_pControlObserver ) - m_pControlObserver->focusGained( _rxControl ); + DBG_ASSERT(_rxControl.is(), "OBrowserListBox::focusGained: invalid event source!"); + if (!_rxControl.is()) + return; - m_xActiveControl = _rxControl; - ShowEntry( impl_getControlPos( m_xActiveControl ) ); - } + if (m_pControlObserver) + m_pControlObserver->focusGained(_rxControl); + m_xActiveControl = _rxControl; + ShowEntry(impl_getControlPos(m_xActiveControl)); +} - void OBrowserListBox::valueChanged( const Reference< XPropertyControl >& _rxControl ) - { - DBG_TESTSOLARMUTEX(); +void OBrowserListBox::valueChanged(const Reference<XPropertyControl>& _rxControl) +{ + DBG_TESTSOLARMUTEX(); - DBG_ASSERT( _rxControl.is(), "OBrowserListBox::valueChanged: invalid event source!" ); - if ( !_rxControl.is() ) - return; + DBG_ASSERT(_rxControl.is(), "OBrowserListBox::valueChanged: invalid event source!"); + if (!_rxControl.is()) + return; - if ( m_pControlObserver ) - m_pControlObserver->valueChanged( _rxControl ); + if (m_pControlObserver) + m_pControlObserver->valueChanged(_rxControl); - if ( m_pLineListener ) - { - const ListBoxLine& rLine = m_aLines[ impl_getControlPos( _rxControl ) ]; - m_pLineListener->Commit( - rLine.pLine->GetEntryName(), - impl_getControlAsPropertyValue( rLine ) - ); - } + if (m_pLineListener) + { + const ListBoxLine& rLine = m_aLines[impl_getControlPos(_rxControl)]; + m_pLineListener->Commit(rLine.pLine->GetEntryName(), impl_getControlAsPropertyValue(rLine)); } +} +void OBrowserListBox::activateNextControl(const Reference<XPropertyControl>& _rxCurrentControl) +{ + DBG_TESTSOLARMUTEX(); - void OBrowserListBox::activateNextControl( const Reference< XPropertyControl >& _rxCurrentControl ) - { - DBG_TESTSOLARMUTEX(); - - sal_uInt16 nLine = impl_getControlPos( _rxCurrentControl ); + sal_uInt16 nLine = impl_getControlPos(_rxCurrentControl); - // cycle forwards, 'til we've the next control which can grab the focus + // cycle forwards, 'til we've the next control which can grab the focus + ++nLine; + while (static_cast<size_t>(nLine) < m_aLines.size()) + { + if (m_aLines[nLine].pLine->GrabFocus()) + break; ++nLine; - while ( static_cast< size_t >( nLine ) < m_aLines.size() ) - { - if ( m_aLines[nLine].pLine->GrabFocus() ) - break; - ++nLine; - } - - // wrap around? - if ( ( static_cast< size_t >( nLine ) >= m_aLines.size() ) && ( !m_aLines.empty() ) ) - m_aLines[0].pLine->GrabFocus(); } + // wrap around? + if ((static_cast<size_t>(nLine) >= m_aLines.size()) && (!m_aLines.empty())) + m_aLines[0].pLine->GrabFocus(); +} - namespace +namespace +{ +void lcl_implDisposeControl_nothrow(const Reference<XPropertyControl>& _rxControl) +{ + if (!_rxControl.is()) + return; + try { - - void lcl_implDisposeControl_nothrow( const Reference< XPropertyControl >& _rxControl ) - { - if ( !_rxControl.is() ) - return; - try - { - _rxControl->setControlContext( nullptr ); - Reference< XComponent > xControlComponent( _rxControl, UNO_QUERY ); - if ( xControlComponent.is() ) - xControlComponent->dispose(); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); - } - } + _rxControl->setControlContext(nullptr); + Reference<XComponent> xControlComponent(_rxControl, UNO_QUERY); + if (xControlComponent.is()) + xControlComponent->dispose(); } - - void OBrowserListBox::Clear() + catch (const Exception&) { - for (auto const& line : m_aLines) - { - // hide the line - line.pLine->Hide(); - // reset the listener - lcl_implDisposeControl_nothrow( line.pLine->getControl() ); - } - - clearContainer( m_aLines ); + DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); } +} +} - bool OBrowserListBox::RemoveEntry( const OUString& _rName ) +void OBrowserListBox::Clear() +{ + for (auto const& line : m_aLines) { - ListBoxLines::iterator it = std::find_if(m_aLines.begin(), m_aLines.end(), - [&_rName](const ListBoxLine& rLine) { return rLine.aName == _rName; }); + // hide the line + line.pLine->Hide(); + // reset the listener + lcl_implDisposeControl_nothrow(line.pLine->getControl()); + } - if ( it == m_aLines.end() ) - return false; + clearContainer(m_aLines); +} - m_aLines.erase( it ); +bool OBrowserListBox::RemoveEntry(const OUString& _rName) +{ + ListBoxLines::iterator it + = std::find_if(m_aLines.begin(), m_aLines.end(), + [&_rName](const ListBoxLine& rLine) { return rLine.aName == _rName; }); - return true; - } + if (it == m_aLines.end()) + return false; - void OBrowserListBox::ChangeEntry( const OLineDescriptor& rPropertyData, ListBoxLines::size_type nPos ) - { - OSL_PRECOND( rPropertyData.Control.is(), "OBrowserListBox::ChangeEntry: invalid control!" ); - if ( !rPropertyData.Control.is() ) - return; + m_aLines.erase(it); - if ( nPos == EDITOR_LIST_REPLACE_EXISTING ) - nPos = GetPropertyPos( rPropertyData.sName ); + return true; +} - if ( nPos >= m_aLines.size() ) - return; +void OBrowserListBox::ChangeEntry(const OLineDescriptor& rPropertyData, + ListBoxLines::size_type nPos) +{ + OSL_PRECOND(rPropertyData.Control.is(), "OBrowserListBox::ChangeEntry: invalid control!"); + if (!rPropertyData.Control.is()) + return; - // the current line and control - ListBoxLine& rLine = m_aLines[nPos]; + if (nPos == EDITOR_LIST_REPLACE_EXISTING) + nPos = GetPropertyPos(rPropertyData.sName); - // the old control and some data about it - Reference< XPropertyControl > xControl = rLine.pLine->getControl(); + if (nPos >= m_aLines.size()) + return; - // clean up the old control - lcl_implDisposeControl_nothrow( xControl ); + // the current line and control + ListBoxLine& rLine = m_aLines[nPos]; - // set the new control at the line - rLine.pLine->setControl( rPropertyData.Control ); - xControl = rLine.pLine->getControl(); + // the old control and some data about it + Reference<XPropertyControl> xControl = rLine.pLine->getControl(); - if ( xControl.is() ) - xControl->setControlContext( m_pControlContextImpl ); + // clean up the old control + lcl_implDisposeControl_nothrow(xControl); - // the initial property value - if ( rPropertyData.bUnknownValue ) - xControl->setValue( Any() ); - else - impl_setControlAsPropertyValue( rLine, rPropertyData.aValue ); + // set the new control at the line + rLine.pLine->setControl(rPropertyData.Control); + xControl = rLine.pLine->getControl(); - rLine.pLine->SetTitle(rPropertyData.DisplayName); - rLine.xHandler = rPropertyData.xPropertyHandler; + if (xControl.is()) + xControl->setControlContext(m_pControlContextImpl); - if ( rPropertyData.HasPrimaryButton ) - { - if ( !rPropertyData.PrimaryButtonImageURL.isEmpty() ) - rLine.pLine->ShowBrowseButton( rPropertyData.PrimaryButtonImageURL, true ); - else if ( rPropertyData.PrimaryButtonImage.is() ) - rLine.pLine->ShowBrowseButton( rPropertyData.PrimaryButtonImage, true ); - else - rLine.pLine->ShowBrowseButton( true ); + // the initial property value + if (rPropertyData.bUnknownValue) + xControl->setValue(Any()); + else + impl_setControlAsPropertyValue(rLine, rPropertyData.aValue); - if ( rPropertyData.HasSecondaryButton ) - { - if ( !rPropertyData.SecondaryButtonImageURL.isEmpty() ) - rLine.pLine->ShowBrowseButton( rPropertyData.SecondaryButtonImageURL, false ); - else if ( rPropertyData.SecondaryButtonImage.is() ) - rLine.pLine->ShowBrowseButton( rPropertyData.SecondaryButtonImage, false ); - else - rLine.pLine->ShowBrowseButton( false ); - } - else - rLine.pLine->HideBrowseButton( false ); + rLine.pLine->SetTitle(rPropertyData.DisplayName); + rLine.xHandler = rPropertyData.xPropertyHandler; - rLine.pLine->SetClickListener( this ); - } + if (rPropertyData.HasPrimaryButton) + { + if (!rPropertyData.PrimaryButtonImageURL.isEmpty()) + rLine.pLine->ShowBrowseButton(rPropertyData.PrimaryButtonImageURL, true); + else if (rPropertyData.PrimaryButtonImage.is()) + rLine.pLine->ShowBrowseButton(rPropertyData.PrimaryButtonImage, true); else + rLine.pLine->ShowBrowseButton(true); + + if (rPropertyData.HasSecondaryButton) { - rLine.pLine->HideBrowseButton( true ); - rLine.pLine->HideBrowseButton( false ); + if (!rPropertyData.SecondaryButtonImageURL.isEmpty()) + rLine.pLine->ShowBrowseButton(rPropertyData.SecondaryButtonImageURL, false); + else if (rPropertyData.SecondaryButtonImage.is()) + rLine.pLine->ShowBrowseButton(rPropertyData.SecondaryButtonImage, false); + else + rLine.pLine->ShowBrowseButton(false); } + else + rLine.pLine->HideBrowseButton(false); - DBG_ASSERT( ( rPropertyData.IndentLevel == 0 ) || ( rPropertyData.IndentLevel == 1 ), - "OBrowserListBox::ChangeEntry: unsupported indent level!" ); - rLine.pLine->IndentTitle( rPropertyData.IndentLevel > 0 ); + rLine.pLine->SetClickListener(this); + } + else + { + rLine.pLine->HideBrowseButton(true); + rLine.pLine->HideBrowseButton(false); + } - rLine.pLine->SetComponentHelpIds( - HelpIdUrl::getHelpId( rPropertyData.HelpURL ) - ); + DBG_ASSERT((rPropertyData.IndentLevel == 0) || (rPropertyData.IndentLevel == 1), + "OBrowserListBox::ChangeEntry: unsupported indent level!"); + rLine.pLine->IndentTitle(rPropertyData.IndentLevel > 0); - if ( rPropertyData.bReadOnly ) - { - rLine.pLine->SetReadOnly( true ); - - // user controls (i.e. the ones not provided by the usual - // XPropertyControlFactory) have no chance to know that they should be read-only, - // since XPropertyHandler::describePropertyLine does not transport this - // information. - // So, we manually switch this to read-only. - if ( xControl.is() && ( xControl->getControlType() == PropertyControlType::Unknown ) ) - { - weld::Widget* pWindow = rLine.pLine->getControlWindow(); - weld::Entry* pControlWindowAsEdit = dynamic_cast<weld::Entry*>(pWindow); - if (pControlWindowAsEdit) - pControlWindowAsEdit->set_editable(false); - else - pWindow->set_sensitive(false); - } - } + rLine.pLine->SetComponentHelpIds(HelpIdUrl::getHelpId(rPropertyData.HelpURL)); - sal_uInt16 nTextWidth = m_xLinesPlayground->get_pixel_size(rPropertyData.DisplayName).Width(); - if (m_nTheNameSize< nTextWidth) + if (rPropertyData.bReadOnly) + { + rLine.pLine->SetReadOnly(true); + + // user controls (i.e. the ones not provided by the usual + // XPropertyControlFactory) have no chance to know that they should be read-only, + // since XPropertyHandler::describePropertyLine does not transport this + // information. + // So, we manually switch this to read-only. + if (xControl.is() && (xControl->getControlType() == PropertyControlType::Unknown)) { - m_nTheNameSize = nTextWidth; - UpdatePlayGround(); + weld::Widget* pWindow = rLine.pLine->getControlWindow(); + weld::Entry* pControlWindowAsEdit = dynamic_cast<weld::Entry*>(pWindow); + if (pControlWindowAsEdit) + pControlWindowAsEdit->set_editable(false); + else + pWindow->set_sensitive(false); } } -} // namespace pcr + sal_uInt16 nTextWidth = m_xLinesPlayground->get_pixel_size(rPropertyData.DisplayName).Width(); + if (m_nTheNameSize < nTextWidth) + { + m_nTheNameSize = nTextWidth; + UpdatePlayGround(); + } +} +} // namespace pcr /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/extensions/source/propctrlr/browserlistbox.hxx b/extensions/source/propctrlr/browserlistbox.hxx index 0a7bafb03a0a..bfac638e1ac2 100644 --- a/extensions/source/propctrlr/browserlistbox.hxx +++ b/extensions/source/propctrlr/browserlistbox.hxx @@ -32,121 +32,117 @@ #include <memory> #include <vector> -#define EDITOR_LIST_REPLACE_EXISTING \ - std::numeric_limits<ListBoxLines::size_type>::max() +#define EDITOR_LIST_REPLACE_EXISTING std::numeric_limits<ListBoxLines::size_type>::max() namespace pcr { +class IPropertyLineListener; +class IPropertyControlObserver; +struct OLineDescriptor; +class InspectorHelpWindow; +class PropertyControlContext_Impl; +// administrative structures for OBrowserListBox - class IPropertyLineListener; - class IPropertyControlObserver; - struct OLineDescriptor; - class InspectorHelpWindow; - class PropertyControlContext_Impl; - - - // administrative structures for OBrowserListBox - - typedef std::shared_ptr< OBrowserLine > BrowserLinePointer; - struct ListBoxLine - { - OUString aName; - BrowserLinePointer pLine; - css::uno::Reference< css::inspection::XPropertyHandler > - xHandler; - - ListBoxLine( OUString _aName, BrowserLinePointer _pLine, css::uno::Reference< css::inspection::XPropertyHandler > _xHandler ) - : aName(std::move( _aName )), - pLine(std::move( _pLine )), - xHandler(std::move( _xHandler )) - { - } - }; - typedef std::vector< ListBoxLine > ListBoxLines; - - - class OBrowserListBox final : public IButtonClickListener +typedef std::shared_ptr<OBrowserLine> BrowserLinePointer; +struct ListBoxLine +{ + OUString aName; + BrowserLinePointer pLine; + css::uno::Reference<css::inspection::XPropertyHandler> xHandler; + + ListBoxLine(OUString _aName, BrowserLinePointer _pLine, + css::uno::Reference<css::inspection::XPropertyHandler> _xHandler) + : aName(std::move(_aName)) + , pLine(std::move(_pLine)) + , xHandler(std::move(_xHandler)) { - std::unique_ptr<weld::ScrolledWindow> m_xScrolledWindow; - std::unique_ptr<weld::Box> m_xLinesPlayground; - std::unique_ptr<weld::SizeGroup> m_xSizeGroup; - std::unique_ptr<InspectorHelpWindow> m_xHelpWindow; - weld::Container* m_pInitialControlParent; - ListBoxLines m_aLines; - IPropertyLineListener* m_pLineListener; - IPropertyControlObserver* m_pControlObserver; - css::uno::Reference< css::inspection::XPropertyControl > - m_xActiveControl; - sal_uInt16 m_nTheNameSize; - int m_nRowHeight; - ::rtl::Reference< PropertyControlContext_Impl > - m_pControlContextImpl; - - void UpdatePlayGround(); - void ShowEntry(sal_uInt16 nPos); - - public: - explicit OBrowserListBox(weld::Builder& rBuilder, weld::Container* pContainer); - ~OBrowserListBox(); - - void SetListener( IPropertyLineListener* _pListener ); - void SetObserver( IPropertyControlObserver* _pObserver ); - - void EnableHelpSection( bool _bEnable ); - bool HasHelpSection() const; - void SetHelpText( const OUString& _rHelpText ); - - void Clear(); - - void InsertEntry( const OLineDescriptor&, sal_uInt16 nPos ); - bool RemoveEntry( const OUString& _rName ); - void ChangeEntry( const OLineDescriptor&, ListBoxLines::size_type nPos ); - - void SetPropertyValue( const OUString& rEntryName, const css::uno::Any& rValue, bool _bUnknownValue ); - sal_uInt16 GetPropertyPos( std::u16string_view rEntryName ) const; - css::uno::Reference< css::inspection::XPropertyControl > - GetPropertyControl( const OUString& rEntryName ); - void EnablePropertyControls( const OUString& _rEntryName, sal_Int16 _nControls, bool _bEnable ); - void EnablePropertyLine( const OUString& _rEntryName, bool _bEnable ); - - bool IsModified( ) const; - void CommitModified( ); - - /// @throws css::uno::RuntimeException - void focusGained( const css::uno::Reference< css::inspection::XPropertyControl >& Control ); - /// @throws css::uno::RuntimeException - void valueChanged( const css::uno::Reference< css::inspection::XPropertyControl >& Control ); - /// @throws css::uno::RuntimeException - void activateNextControl( const css::uno::Reference< css::inspection::XPropertyControl >& CurrentControl ); - - private: - // IButtonClickListener - void buttonClicked( OBrowserLine* _pLine, bool _bPrimary ) override; - - /** retrieves the index of a given control in our line list + } +}; +typedef std::vector<ListBoxLine> ListBoxLines; + +class OBrowserListBox final : public IButtonClickListener +{ + std::unique_ptr<weld::ScrolledWindow> m_xScrolledWindow; + std::unique_ptr<weld::Box> m_xLinesPlayground; + std::unique_ptr<weld::SizeGroup> m_xSizeGroup; + std::unique_ptr<InspectorHelpWindow> m_xHelpWindow; + weld::Container* m_pInitialControlParent; + ListBoxLines m_aLines; + IPropertyLineListener* m_pLineListener; + IPropertyControlObserver* m_pControlObserver; + css::uno::Reference<css::inspection::XPropertyControl> m_xActiveControl; + sal_uInt16 m_nTheNameSize; + int m_nRowHeight; + ::rtl::Reference<PropertyControlContext_Impl> m_pControlContextImpl; + + void UpdatePlayGround(); + void ShowEntry(sal_uInt16 nPos); + +public: + explicit OBrowserListBox(weld::Builder& rBuilder, weld::Container* pContainer); + ~OBrowserListBox(); + + void SetListener(IPropertyLineListener* _pListener); + void SetObserver(IPropertyControlObserver* _pObserver); + + void EnableHelpSection(bool _bEnable); + bool HasHelpSection() const; + void SetHelpText(const OUString& _rHelpText); + + void Clear(); + + void InsertEntry(const OLineDescriptor&, sal_uInt16 nPos); + bool RemoveEntry(const OUString& _rName); + void ChangeEntry(const OLineDescriptor&, ListBoxLines::size_type nPos); + + void SetPropertyValue(const OUString& rEntryName, const css::uno::Any& rValue, + bool _bUnknownValue); + sal_uInt16 GetPropertyPos(std::u16string_view rEntryName) const; + css::uno::Reference<css::inspection::XPropertyControl> + GetPropertyControl(const OUString& rEntryName); + void EnablePropertyControls(const OUString& _rEntryName, sal_Int16 _nControls, bool _bEnable); + void EnablePropertyLine(const OUString& _rEntryName, bool _bEnable); + + bool IsModified() const; + void CommitModified(); + + /// @throws css::uno::RuntimeException + void focusGained(const css::uno::Reference<css::inspection::XPropertyControl>& Control); + /// @throws css::uno::RuntimeException + void valueChanged(const css::uno::Reference<css::inspection::XPropertyControl>& Control); + /// @throws css::uno::RuntimeException + void activateNextControl( + const css::uno::Reference<css::inspection::XPropertyControl>& CurrentControl); + +private: + // IButtonClickListener + void buttonClicked(OBrowserLine* _pLine, bool _bPrimary) override; + + /** retrieves the index of a given control in our line list @param _rxControl The control to lookup. Must denote a control of one of the lines in ->m_aLines */ - sal_uInt16 impl_getControlPos( const css::uno::Reference< css::inspection::XPropertyControl >& _rxControl ) const; + sal_uInt16 impl_getControlPos( + const css::uno::Reference<css::inspection::XPropertyControl>& _rxControl) const; - /** sets the given property value at the given control, after converting it as necessary + /** sets the given property value at the given control, after converting it as necessary @param _rLine The line whose at which the value is to be set. @param _rPropertyValue the property value to set. If it's not compatible with the control value, it will be converted, using <member>XPropertyHandler::convertToControlValue</member> */ - static void impl_setControlAsPropertyValue( const ListBoxLine& _rLine, const css::uno::Any& _rPropertyValue ); + static void impl_setControlAsPropertyValue(const ListBoxLine& _rLine, + const css::uno::Any& _rPropertyValue); - /** retrieves the value for the given control, as a property value, after converting it as necessary + /** retrieves the value for the given control, as a property value, after converting it as necessary @param _rLine The line whose at which the value is to be set. */ - static css::uno::Any - impl_getControlAsPropertyValue( const ListBoxLine& _rLine ); + static css::uno::Any impl_getControlAsPropertyValue(const ListBoxLine& _rLine); - /** retrieves the ->BrowserLinePointer for a given entry name + /** retrieves the ->BrowserLinePointer for a given entry name @param _rEntryName the name whose line is to be looked up @param _out_rpLine @@ -155,12 +151,10 @@ namespace pcr <TRUE/> if and only if a non-<NULL/> line for the given entry name could be found. */ - bool impl_getBrowserLineForName( const OUString& _rEntryName, BrowserLinePointer& _out_rpLine ) const; - }; - + bool impl_getBrowserLineForName(const OUString& _rEntryName, + BrowserLinePointer& _out_rpLine) const; +}; } // namespace pcr - - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index a26209942f72..491658fb0734 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -3491,8 +3491,6 @@ extensions/source/ole/unotypewrapper.hxx extensions/source/ole/windata.hxx extensions/source/propctrlr/MasterDetailLinkDialog.cxx extensions/source/propctrlr/MasterDetailLinkDialog.hxx -extensions/source/propctrlr/browserlistbox.cxx -extensions/source/propctrlr/browserlistbox.hxx extensions/source/propctrlr/browserpage.cxx extensions/source/propctrlr/browserpage.hxx extensions/source/propctrlr/browserview.cxx commit c2994afa9e09a48ffc484b0922f0b9413a953151 Author: Michael Weghorn <[email protected]> AuthorDate: Tue Jan 20 08:44:22 2026 +0100 Commit: Michael Weghorn <[email protected]> CommitDate: Thu Jan 22 11:13:24 2026 +0100 propctrlr: clang-format OBrowserLine code This in particular gets rid of an extra indentation level. Change-Id: I18f3e429aaa9c4ffbdb8caf55525f1fc672c9999 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197626 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/extensions/source/propctrlr/browserline.cxx b/extensions/source/propctrlr/browserline.cxx index a227f5859543..eb18b2692f61 100644 --- a/extensions/source/propctrlr/browserline.cxx +++ b/extensions/source/propctrlr/browserline.cxx @@ -37,367 +37,368 @@ namespace pcr { +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::XComponentContext; +using ::com::sun::star::inspection::XPropertyControl; +using ::com::sun::star::inspection::XPropertyControlContext; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::graphic::GraphicProvider; +using ::com::sun::star::graphic::XGraphicProvider; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::graphic::XGraphic; + +namespace PropertyLineElement = ::com::sun::star::inspection::PropertyLineElement; + +OBrowserLine::OBrowserLine(OUString aEntryName, weld::Box* pParent, weld::SizeGroup* pLabelGroup, + weld::Container* pInitialControlParent) + : m_sEntryName(std::move(aEntryName)) + , m_xBuilder(Application::CreateBuilder(pParent, u"modules/spropctrlr/ui/browserline.ui"_ustr)) + , m_xGrid(m_xBuilder->weld_grid(u"BrowserLine"_ustr)) + , m_xFtTitle(m_xBuilder->weld_label(u"label"_ustr)) + , m_xBrowseButton(m_xBuilder->weld_button(u"browse"_ustr)) + , m_xAdditionalBrowseButton(m_xBuilder->weld_button(u"morebrowse"_ustr)) + // controls start with this as their parent and need to be moved into m_xGrid + , m_pInitialControlParent(pInitialControlParent) + , m_pParent(pParent) + , m_pControlWindow(nullptr) + , m_pBrowseButton(nullptr) + , m_pAdditionalBrowseButton(nullptr) + , m_pClickListener(nullptr) + , m_nNameWidth(0) + , m_nEnableFlags(0xFFFF) + , m_bIndentTitle(false) + , m_bReadOnly(false) +{ + pLabelGroup->add_widget(m_xFtTitle.get()); +} +OBrowserLine::~OBrowserLine() +{ + implHideBrowseButton(true); + implHideBrowseButton(false); + m_pParent->move(m_xGrid.get(), nullptr); +} - using ::com::sun::star::uno::Reference; - using ::com::sun::star::uno::XComponentContext; - using ::com::sun::star::inspection::XPropertyControl; - using ::com::sun::star::inspection::XPropertyControlContext; - using ::com::sun::star::uno::Exception; - using ::com::sun::star::graphic::GraphicProvider; - using ::com::sun::star::graphic::XGraphicProvider; - using ::com::sun::star::uno::Sequence; - using ::com::sun::star::graphic::XGraphic; - - namespace PropertyLineElement = ::com::sun::star::inspection::PropertyLineElement; - - OBrowserLine::OBrowserLine(OUString aEntryName, weld::Box* pParent, weld::SizeGroup* pLabelGroup, - weld::Container* pInitialControlParent) - : m_sEntryName(std::move(aEntryName)) - , m_xBuilder(Application::CreateBuilder(pParent, u"modules/spropctrlr/ui/browserline.ui"_ustr)) - , m_xGrid(m_xBuilder->weld_grid(u"BrowserLine"_ustr)) - , m_xFtTitle(m_xBuilder->weld_label(u"label"_ustr)) - , m_xBrowseButton(m_xBuilder->weld_button(u"browse"_ustr)) - , m_xAdditionalBrowseButton(m_xBuilder->weld_button(u"morebrowse"_ustr)) - , m_pInitialControlParent(pInitialControlParent) // controls start with this as their parent and need to be moved into m_xGrid - , m_pParent(pParent) - , m_pControlWindow( nullptr ) - , m_pBrowseButton(nullptr) - , m_pAdditionalBrowseButton( nullptr ) - , m_pClickListener( nullptr ) - , m_nNameWidth(0) - , m_nEnableFlags( 0xFFFF ) - , m_bIndentTitle( false ) - , m_bReadOnly( false ) - { - pLabelGroup->add_widget(m_xFtTitle.get()); - } - - OBrowserLine::~OBrowserLine() +void OBrowserLine::IndentTitle(bool _bIndent) +{ + if (m_bIndentTitle != _bIndent) { - implHideBrowseButton(true); - implHideBrowseButton(false); - m_pParent->move(m_xGrid.get(), nullptr); + m_bIndentTitle = _bIndent; } +} - void OBrowserLine::IndentTitle( bool _bIndent ) - { - if ( m_bIndentTitle != _bIndent ) - { - m_bIndentTitle = _bIndent; - } - } +void OBrowserLine::SetComponentHelpIds(const OUString& rHelpId) +{ + if (m_pControlWindow) + m_pControlWindow->set_help_id(rHelpId); - void OBrowserLine::SetComponentHelpIds(const OUString& rHelpId) + if (m_pBrowseButton) { - if (m_pControlWindow) - m_pControlWindow->set_help_id(rHelpId); + m_pBrowseButton->set_help_id(rHelpId); - if ( m_pBrowseButton ) + if (m_pAdditionalBrowseButton) { - m_pBrowseButton->set_help_id(rHelpId); - - if ( m_pAdditionalBrowseButton ) - { - m_pAdditionalBrowseButton->set_help_id(rHelpId); - } + m_pAdditionalBrowseButton->set_help_id(rHelpId); } } +} - void OBrowserLine::setControl( const Reference< XPropertyControl >& rxControl ) +void OBrowserLine::setControl(const Reference<XPropertyControl>& rxControl) +{ + m_xControl = rxControl; + auto xWindow = m_xControl->getControlWindow(); + if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xWindow.get())) + m_pControlWindow = pTunnel->getWidget(); + else + m_pControlWindow = nullptr; + DBG_ASSERT(m_pControlWindow, + "OBrowserLine::setControl: setting NULL controls/windows is not allowed!"); + + if (m_pControlWindow) { - m_xControl = rxControl; - auto xWindow = m_xControl->getControlWindow(); - if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xWindow.get())) - m_pControlWindow = pTunnel->getWidget(); - else - m_pControlWindow = nullptr; - DBG_ASSERT( m_pControlWindow, "OBrowserLine::setControl: setting NULL controls/windows is not allowed!" ); - - if ( m_pControlWindow ) - { - m_pInitialControlParent->move(m_pControlWindow, m_xGrid.get()); - m_xGrid->set_child_left_attach(*m_pControlWindow, 1); - m_xFtTitle->set_mnemonic_widget(m_pControlWindow); - m_pControlWindow->show(); - } + m_pInitialControlParent->move(m_pControlWindow, m_xGrid.get()); + m_xGrid->set_child_left_attach(*m_pControlWindow, 1); + m_xFtTitle->set_mnemonic_widget(m_pControlWindow); + m_pControlWindow->show(); } +} - bool OBrowserLine::GrabFocus() - { - bool bRes=false; - - if (m_pControlWindow && m_pControlWindow->get_sensitive()) - { - m_pControlWindow->grab_focus(); - bRes = true; - } - else if ( m_pAdditionalBrowseButton && m_pAdditionalBrowseButton->get_sensitive() ) - { - m_pAdditionalBrowseButton->grab_focus(); - bRes = true; - } - else if ( m_pBrowseButton && m_pBrowseButton->get_sensitive() ) - { - m_pBrowseButton->grab_focus(); - bRes = true; - } - return bRes; - } +bool OBrowserLine::GrabFocus() +{ + bool bRes = false; - void OBrowserLine::Show(bool bFlag) + if (m_pControlWindow && m_pControlWindow->get_sensitive()) { - m_xFtTitle->set_visible(bFlag); - if (m_pControlWindow) - m_pControlWindow->set_visible( bFlag ); - if ( m_pBrowseButton ) - m_pBrowseButton->set_visible( bFlag ); - if ( m_pAdditionalBrowseButton ) - m_pAdditionalBrowseButton->set_visible( bFlag ); + m_pControlWindow->grab_focus(); + bRes = true; } - - void OBrowserLine::Hide() + else if (m_pAdditionalBrowseButton && m_pAdditionalBrowseButton->get_sensitive()) { - Show(false); + m_pAdditionalBrowseButton->grab_focus(); + bRes = true; } - - void OBrowserLine::SetTitle(const OUString& rNewTitle ) + else if (m_pBrowseButton && m_pBrowseButton->get_sensitive()) { - if ( GetTitle() == rNewTitle ) - return; - m_xFtTitle->set_label( rNewTitle ); - if (m_pControlWindow) - m_pControlWindow->set_accessible_name(rNewTitle); - if ( m_pBrowseButton ) - m_pBrowseButton->set_accessible_name( rNewTitle ); - FullFillTitleString(); + m_pBrowseButton->grab_focus(); + bRes = true; } + return bRes; +} - void OBrowserLine::FullFillTitleString() - { - OUStringBuffer aText(m_xFtTitle->get_label()); - - int n10DotsWidth = m_xFtTitle->get_pixel_size(u".........."_ustr).Width(); - int nTextWidth = m_xFtTitle->get_pixel_size(OUString::unacquired(aText)).Width(); - int nDiff = m_nNameWidth - nTextWidth; - int nExtraChars = (nDiff * 10) / n10DotsWidth; - for (int i = 0; i < nExtraChars; ++i) - aText.append("."); +void OBrowserLine::Show(bool bFlag) +{ + m_xFtTitle->set_visible(bFlag); + if (m_pControlWindow) + m_pControlWindow->set_visible(bFlag); + if (m_pBrowseButton) + m_pBrowseButton->set_visible(bFlag); + if (m_pAdditionalBrowseButton) + m_pAdditionalBrowseButton->set_visible(bFlag); +} + +void OBrowserLine::Hide() { Show(false); } + +void OBrowserLine::SetTitle(const OUString& rNewTitle) +{ + if (GetTitle() == rNewTitle) + return; + m_xFtTitle->set_label(rNewTitle); + if (m_pControlWindow) + m_pControlWindow->set_accessible_name(rNewTitle); + if (m_pBrowseButton) + m_pBrowseButton->set_accessible_name(rNewTitle); + FullFillTitleString(); +} + +void OBrowserLine::FullFillTitleString() +{ + OUStringBuffer aText(m_xFtTitle->get_label()); - // for Issue 69452 - if (AllSettings::GetLayoutRTL()) - { - sal_Unicode const cRTL_mark = 0x200F; - aText.append( cRTL_mark ); - } + int n10DotsWidth = m_xFtTitle->get_pixel_size(u".........."_ustr).Width(); + int nTextWidth = m_xFtTitle->get_pixel_size(OUString::unacquired(aText)).Width(); + int nDiff = m_nNameWidth - nTextWidth; + int nExtraChars = (nDiff * 10) / n10DotsWidth; + for (int i = 0; i < nExtraChars; ++i) + aText.append("."); - m_xFtTitle->set_label(aText.makeStringAndClear()); + // for Issue 69452 + if (AllSettings::GetLayoutRTL()) + { + sal_Unicode const cRTL_mark = 0x200F; + aText.append(cRTL_mark); } - OUString OBrowserLine::GetTitle() const + m_xFtTitle->set_label(aText.makeStringAndClear()); +} + +OUString OBrowserLine::GetTitle() const +{ + OUString sDisplayName = m_xFtTitle->get_label(); + + // for Issue 69452 + if (AllSettings::GetLayoutRTL()) { - OUString sDisplayName = m_xFtTitle->get_label(); + sal_Unicode const cRTL_mark = 0x200F; + sDisplayName = comphelper::string::stripEnd(sDisplayName, cRTL_mark); + } - // for Issue 69452 - if (AllSettings::GetLayoutRTL()) - { - sal_Unicode const cRTL_mark = 0x200F; - sDisplayName = comphelper::string::stripEnd(sDisplayName, cRTL_mark); - } + sDisplayName = comphelper::string::stripEnd(sDisplayName, '.'); - sDisplayName = comphelper::string::stripEnd(sDisplayName, '.'); + return sDisplayName; +} - return sDisplayName; +void OBrowserLine::SetReadOnly(bool _bReadOnly) +{ + if (m_bReadOnly != _bReadOnly) + { + m_bReadOnly = _bReadOnly; + implUpdateEnabledDisabled(); } +} - void OBrowserLine::SetReadOnly( bool _bReadOnly ) +namespace +{ +void implSetBitIfAffected(sal_uInt16& nEnabledBits, sal_Int16 _nAffectedMask, sal_Int16 _nTestBit, + bool _bSet) +{ + if (_nAffectedMask & _nTestBit) { - if ( m_bReadOnly != _bReadOnly ) - { - m_bReadOnly = _bReadOnly; - implUpdateEnabledDisabled(); - } + if (_bSet) + nEnabledBits |= _nTestBit; + else + nEnabledBits &= ~_nTestBit; } +} - namespace - { - void implSetBitIfAffected(sal_uInt16& nEnabledBits, sal_Int16 _nAffectedMask, sal_Int16 _nTestBit, bool _bSet) - { - if ( _nAffectedMask & _nTestBit ) - { - if ( _bSet ) - nEnabledBits |= _nTestBit; - else - nEnabledBits &= ~_nTestBit; - } - } +void implEnable(weld::Widget* pWindow, bool bEnable) +{ + // tdf#138131 get_sensitive comparison as bodge for + // vcl's recursive Enable behavior + if (pWindow && pWindow->get_sensitive() != bEnable) + pWindow->set_sensitive(bEnable); +} - void implEnable(weld::Widget* pWindow, bool bEnable) - { - // tdf#138131 get_sensitive comparison as bodge for - // vcl's recursive Enable behavior - if (pWindow && pWindow->get_sensitive() != bEnable) - pWindow->set_sensitive(bEnable); - } +void implEnable(weld::Widget* pWindow, sal_uInt16 nEnabledBits, sal_uInt16 nMatchBits) +{ + bool bEnable = ((nEnabledBits & nMatchBits) == nMatchBits); + implEnable(pWindow, bEnable); +} +} - void implEnable(weld::Widget* pWindow, sal_uInt16 nEnabledBits, sal_uInt16 nMatchBits) - { - bool bEnable = ((nEnabledBits & nMatchBits) == nMatchBits); - implEnable(pWindow, bEnable); - } - } +void OBrowserLine::implUpdateEnabledDisabled() +{ + implEnable(m_xFtTitle.get(), m_nEnableFlags, PropertyLineElement::CompleteLine); + if (m_pControlWindow) + implEnable(m_pControlWindow, m_nEnableFlags, + PropertyLineElement::CompleteLine | PropertyLineElement::InputControl); - void OBrowserLine::implUpdateEnabledDisabled() + if (m_bReadOnly) { - implEnable( m_xFtTitle.get(), m_nEnableFlags, PropertyLineElement::CompleteLine ); - if ( m_pControlWindow ) - implEnable( m_pControlWindow, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::InputControl ); - - if ( m_bReadOnly ) - { - implEnable( m_pBrowseButton, false ); - implEnable( m_pAdditionalBrowseButton, false ); - } - else - { - implEnable( m_pBrowseButton, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::PrimaryButton ); - implEnable( m_pAdditionalBrowseButton, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::SecondaryButton ); - } + implEnable(m_pBrowseButton, false); + implEnable(m_pAdditionalBrowseButton, false); } - - void OBrowserLine::EnablePropertyLine( bool _bEnable ) + else { - implSetBitIfAffected( m_nEnableFlags, PropertyLineElement::CompleteLine, PropertyLineElement::CompleteLine, _bEnable ); - implUpdateEnabledDisabled(); + implEnable(m_pBrowseButton, m_nEnableFlags, + PropertyLineElement::CompleteLine | PropertyLineElement::PrimaryButton); + implEnable(m_pAdditionalBrowseButton, m_nEnableFlags, + PropertyLineElement::CompleteLine | PropertyLineElement::SecondaryButton); } +} +void OBrowserLine::EnablePropertyLine(bool _bEnable) +{ + implSetBitIfAffected(m_nEnableFlags, PropertyLineElement::CompleteLine, + PropertyLineElement::CompleteLine, _bEnable); + implUpdateEnabledDisabled(); +} - void OBrowserLine::EnablePropertyControls( sal_Int16 _nControls, bool _bEnable ) - { - implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::InputControl, _bEnable ); - implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::PrimaryButton, _bEnable ); - implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::SecondaryButton, _bEnable ); - implUpdateEnabledDisabled(); - } +void OBrowserLine::EnablePropertyControls(sal_Int16 _nControls, bool _bEnable) +{ + implSetBitIfAffected(m_nEnableFlags, _nControls, PropertyLineElement::InputControl, _bEnable); + implSetBitIfAffected(m_nEnableFlags, _nControls, PropertyLineElement::PrimaryButton, _bEnable); + implSetBitIfAffected(m_nEnableFlags, _nControls, PropertyLineElement::SecondaryButton, + _bEnable); + implUpdateEnabledDisabled(); +} + +weld::Button& OBrowserLine::impl_ensureButton(bool bPrimary) +{ + weld::Button* pButton; + if (bPrimary) + pButton = m_pBrowseButton; + else + pButton = m_pAdditionalBrowseButton; - weld::Button& OBrowserLine::impl_ensureButton(bool bPrimary) + if (!pButton) { - weld::Button* pButton; if (bPrimary) - pButton = m_pBrowseButton; + pButton = m_pBrowseButton = m_xBrowseButton.get(); else - pButton = m_pAdditionalBrowseButton; + pButton = m_pAdditionalBrowseButton = m_xAdditionalBrowseButton.get(); + pButton->connect_focus_in(LINK(this, OBrowserLine, OnButtonFocus)); + pButton->connect_clicked(LINK(this, OBrowserLine, OnButtonClicked)); + } - if (!pButton ) - { - if (bPrimary) - pButton = m_pBrowseButton = m_xBrowseButton.get(); - else - pButton = m_pAdditionalBrowseButton = m_xAdditionalBrowseButton.get(); - pButton->connect_focus_in(LINK(this, OBrowserLine, OnButtonFocus)); - pButton->connect_clicked(LINK(this, OBrowserLine, OnButtonClicked)); - } + pButton->show(); - pButton->show(); + return *pButton; +} - return *pButton; - } +void OBrowserLine::ShowBrowseButton(const OUString& rImageURL, bool bPrimary) +{ + weld::Button& rButton(impl_ensureButton(bPrimary)); - void OBrowserLine::ShowBrowseButton( const OUString& rImageURL, bool bPrimary ) + OSL_PRECOND( + !rImageURL.isEmpty(), + "OBrowserLine::ShowBrowseButton: use the other version if you don't have an image!"); + Reference<XGraphic> xGraphic; + try { - weld::Button& rButton( impl_ensureButton( bPrimary ) ); - - OSL_PRECOND( !rImageURL.isEmpty(), "OBrowserLine::ShowBrowseButton: use the other version if you don't have an image!" ); - Reference<XGraphic> xGraphic; - try - { - const Reference< XComponentContext >& xContext( ::comphelper::getProcessComponentContext() ); - Reference< XGraphicProvider > xGraphicProvider( GraphicProvider::create(xContext) ); + const Reference<XComponentContext>& xContext(::comphelper::getProcessComponentContext()); + Reference<XGraphicProvider> xGraphicProvider(GraphicProvider::create(xContext)); - Sequence aMediaProperties{ comphelper::makePropertyValue(u"URL"_ustr, rImageURL) }; - - xGraphic = Reference<XGraphic>(xGraphicProvider->queryGraphic(aMediaProperties), css::uno::UNO_SET_THROW); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); - } + Sequence aMediaProperties{ comphelper::makePropertyValue(u"URL"_ustr, rImageURL) }; - rButton.set_image(xGraphic); + xGraphic = Reference<XGraphic>(xGraphicProvider->queryGraphic(aMediaProperties), + css::uno::UNO_SET_THROW); } - - void OBrowserLine::ShowBrowseButton(const css::uno::Reference<css::graphic::XGraphic>& rGraphic, bool bPrimary) + catch (const Exception&) { - weld::Button& rButton( impl_ensureButton( bPrimary ) ); - rButton.set_image(rGraphic); + DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); } - void OBrowserLine::ShowBrowseButton( bool bPrimary ) - { - impl_ensureButton(bPrimary); - } + rButton.set_image(xGraphic); +} + +void OBrowserLine::ShowBrowseButton(const css::uno::Reference<css::graphic::XGraphic>& rGraphic, + bool bPrimary) +{ + weld::Button& rButton(impl_ensureButton(bPrimary)); + rButton.set_image(rGraphic); +} + +void OBrowserLine::ShowBrowseButton(bool bPrimary) { impl_ensureButton(bPrimary); } - void OBrowserLine::implHideBrowseButton(bool bPrimary) +void OBrowserLine::implHideBrowseButton(bool bPrimary) +{ + if (bPrimary) { - if (bPrimary) + if (m_pBrowseButton) { - if (m_pBrowseButton) - { - m_pBrowseButton->hide(); - m_pBrowseButton->connect_focus_in(Link<weld::Widget&, void>()); - m_pBrowseButton = nullptr; - } + m_pBrowseButton->hide(); + m_pBrowseButton->connect_focus_in(Link<weld::Widget&, void>()); + m_pBrowseButton = nullptr; } - else + } + else + { + if (m_pAdditionalBrowseButton) { - if (m_pAdditionalBrowseButton) - { - m_pAdditionalBrowseButton->hide(); - m_pAdditionalBrowseButton->connect_focus_in(Link<weld::Widget&, void>()); - m_pAdditionalBrowseButton = nullptr; - } + m_pAdditionalBrowseButton->hide(); + m_pAdditionalBrowseButton->connect_focus_in(Link<weld::Widget&, void>()); + m_pAdditionalBrowseButton = nullptr; } } +} - void OBrowserLine::HideBrowseButton(bool bPrimary) - { - implHideBrowseButton(bPrimary); - } +void OBrowserLine::HideBrowseButton(bool bPrimary) { implHideBrowseButton(bPrimary); } - void OBrowserLine::SetTitleWidth(sal_uInt16 nWidth) - { - int nMinDotsWidth = m_xFtTitle->get_pixel_size(u"..."_ustr).Width(); - if (m_nNameWidth != nWidth + nMinDotsWidth) - m_nNameWidth = nWidth + nMinDotsWidth; - FullFillTitleString(); - } +void OBrowserLine::SetTitleWidth(sal_uInt16 nWidth) +{ + int nMinDotsWidth = m_xFtTitle->get_pixel_size(u"..."_ustr).Width(); + if (m_nNameWidth != nWidth + nMinDotsWidth) + m_nNameWidth = nWidth + nMinDotsWidth; + FullFillTitleString(); +} - void OBrowserLine::SetClickListener( IButtonClickListener* _pListener ) - { - m_pClickListener = _pListener; - } +void OBrowserLine::SetClickListener(IButtonClickListener* _pListener) +{ + m_pClickListener = _pListener; +} - IMPL_LINK(OBrowserLine, OnButtonClicked, weld::Button&, rButton, void) - { - if ( m_pClickListener ) - m_pClickListener->buttonClicked(this, &rButton == m_pBrowseButton); - } +IMPL_LINK(OBrowserLine, OnButtonClicked, weld::Button&, rButton, void) +{ + if (m_pClickListener) + m_pClickListener->buttonClicked(this, &rButton == m_pBrowseButton); +} - IMPL_LINK_NOARG( OBrowserLine, OnButtonFocus, weld::Widget&, void ) +IMPL_LINK_NOARG(OBrowserLine, OnButtonFocus, weld::Widget&, void) +{ + if (m_xControl.is()) { - if ( m_xControl.is() ) + try { - try - { - Reference< XPropertyControlContext > xContext( m_xControl->getControlContext(), css::uno::UNO_SET_THROW ); - xContext->focusGained( m_xControl ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); - } + Reference<XPropertyControlContext> xContext(m_xControl->getControlContext(), + css::uno::UNO_SET_THROW); + xContext->focusGained(m_xControl); + } + catch (const Exception&) + { + DBG_UNHANDLED_EXCEPTION("extensions.propctrlr"); } } +} } // namespace pcr diff --git a/extensions/source/propctrlr/browserline.hxx b/extensions/source/propctrlr/browserline.hxx index 78f8f02b6f45..29e5dfa65c7d 100644 --- a/extensions/source/propctrlr/browserline.hxx +++ b/extensions/source/propctrlr/browserline.hxx @@ -25,104 +25,94 @@ namespace com::sun::star::inspection::PropertyLineElement { - const sal_Int16 CompleteLine = 0x4000; +const sal_Int16 CompleteLine = 0x4000; } - namespace pcr { +class OBrowserLine; +class IButtonClickListener +{ +public: + virtual void buttonClicked(OBrowserLine* pLine, bool bPrimary) = 0; - class OBrowserLine; - +protected: + ~IButtonClickListener() {} +}; - class IButtonClickListener +class OBrowserLine +{ +private: + OUString m_sEntryName; + std::unique_ptr<weld::Builder> m_xBuilder; + std::unique_ptr<weld::Grid> m_xGrid; + std::unique_ptr<weld::Label> m_xFtTitle; + std::unique_ptr<weld::Button> m_xBrowseButton; + std::unique_ptr<weld::Button> m_xAdditionalBrowseButton; + css::uno::Reference<css::inspection::XPropertyControl> m_xControl; + weld::Container* m_pInitialControlParent; + weld::Box* m_pParent; + weld::Widget* m_pControlWindow; + weld::Button* m_pBrowseButton; + weld::Button* m_pAdditionalBrowseButton; + IButtonClickListener* m_pClickListener; + sal_uInt16 m_nNameWidth; + sal_uInt16 m_nEnableFlags; + bool m_bIndentTitle; + bool m_bReadOnly; + +public: + OBrowserLine(OUString aEntryName, weld::Box* pParent, weld::SizeGroup* pLabelGroup, + weld::Container* pInitialControlParent); + ~OBrowserLine(); + + void setControl(const css::uno::Reference<css::inspection::XPropertyControl>& rxControl); + const css::uno::Reference<css::inspection::XPropertyControl>& getControl() const { - public: - virtual void buttonClicked( OBrowserLine* pLine, bool bPrimary ) = 0; + return m_xControl; + } + weld::Widget* getControlWindow() const { return m_pControlWindow; } - protected: - ~IButtonClickListener() {} - }; + const OUString& GetEntryName() const { return m_sEntryName; } + void SetComponentHelpIds(const OUString& rHelpId); - class OBrowserLine - { - private: - OUString m_sEntryName; - std::unique_ptr<weld::Builder> m_xBuilder; - std::unique_ptr<weld::Grid> m_xGrid; - std::unique_ptr<weld::Label> m_xFtTitle; - std::unique_ptr<weld::Button> m_xBrowseButton; - std::unique_ptr<weld::Button> m_xAdditionalBrowseButton; - css::uno::Reference< css::inspection::XPropertyControl > - m_xControl; - weld::Container* m_pInitialControlParent; - weld::Box* m_pParent; - weld::Widget* m_pControlWindow; - weld::Button* m_pBrowseButton; - weld::Button* m_pAdditionalBrowseButton; - IButtonClickListener* m_pClickListener; - sal_uInt16 m_nNameWidth; - sal_uInt16 m_nEnableFlags; - bool m_bIndentTitle; - bool m_bReadOnly; - - public: - OBrowserLine(OUString aEntryName, weld::Box* pParent, weld::SizeGroup* pLabelGroup, - weld::Container* pInitialControlParent); - ~OBrowserLine(); - - void setControl( const css::uno::Reference< css::inspection::XPropertyControl >& rxControl ); - const css::uno::Reference< css::inspection::XPropertyControl >& getControl() const - { - return m_xControl; - } - weld::Widget* getControlWindow() const - { - return m_pControlWindow; - } - - const OUString& GetEntryName() const { return m_sEntryName; } - - void SetComponentHelpIds(const OUString& rHelpId); - - void SetTitle(const OUString& rString ); - void FullFillTitleString(); - OUString GetTitle() const; - void SetTitleWidth(sal_uInt16); - - int GetRowHeight() const { return m_xGrid->get_preferred_size().Height(); } - void Show(bool bFlag=true); - void Hide(); - - bool GrabFocus(); - void ShowBrowseButton( const OUString& rImageURL, bool bPrimary ); - void ShowBrowseButton( const css::uno::Reference<css::graphic::XGraphic>& rGraphic, bool bPrimary ); - void ShowBrowseButton( bool bPrimary ); - void HideBrowseButton( bool bPrimary ); - - void EnablePropertyControls( sal_Int16 nControls, bool bEnable ); - void EnablePropertyLine( bool bEnable ); - - void SetReadOnly( bool bReadOnly ); - - void SetClickListener( IButtonClickListener* pListener ); - - void IndentTitle( bool bIndent ); - - private: - DECL_LINK( OnButtonClicked, weld::Button&, void ); - DECL_LINK( OnButtonFocus, weld::Widget&, void ); - - void implHideBrowseButton(bool bPrimary); - void implUpdateEnabledDisabled(); - - weld::Button& impl_ensureButton(bool bPrimary); - }; + void SetTitle(const OUString& rString); + void FullFillTitleString(); + OUString GetTitle() const; + void SetTitleWidth(sal_uInt16); + int GetRowHeight() const { return m_xGrid->get_preferred_size().Height(); } + void Show(bool bFlag = true); + void Hide(); -} // namespace pcr + bool GrabFocus(); + void ShowBrowseButton(const OUString& rImageURL, bool bPrimary); + void ShowBrowseButton(const css::uno::Reference<css::graphic::XGraphic>& rGraphic, + bool bPrimary); + void ShowBrowseButton(bool bPrimary); + void HideBrowseButton(bool bPrimary); + + void EnablePropertyControls(sal_Int16 nControls, bool bEnable); + void EnablePropertyLine(bool bEnable); + void SetReadOnly(bool bReadOnly); + + void SetClickListener(IButtonClickListener* pListener); + + void IndentTitle(bool bIndent); + +private: + DECL_LINK(OnButtonClicked, weld::Button&, void); + DECL_LINK(OnButtonFocus, weld::Widget&, void); + + void implHideBrowseButton(bool bPrimary); + void implUpdateEnabledDisabled(); + + weld::Button& impl_ensureButton(bool bPrimary); +}; + +} // namespace pcr /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist index 55f3e4a38c3d..a26209942f72 100644 --- a/solenv/clang-format/excludelist +++ b/solenv/clang-format/excludelist @@ -3491,8 +3491,6 @@ extensions/source/ole/unotypewrapper.hxx extensions/source/ole/windata.hxx extensions/source/propctrlr/MasterDetailLinkDialog.cxx extensions/source/propctrlr/MasterDetailLinkDialog.hxx -extensions/source/propctrlr/browserline.cxx -extensions/source/propctrlr/browserline.hxx extensions/source/propctrlr/browserlistbox.cxx extensions/source/propctrlr/browserlistbox.hxx extensions/source/propctrlr/browserpage.cxx
