33#include <com/sun/star/awt/XDockableWindow.hpp>
34#include <com/sun/star/frame/XLayoutManager.hpp>
35#include <com/sun/star/frame/XSubToolbarController.hpp>
36#include <com/sun/star/frame/status/Visibility.hpp>
37#include <com/sun/star/lang/XServiceInfo.hpp>
38#include <com/sun/star/ui/theUIElementFactoryManager.hpp>
39#include <com/sun/star/container/NoSuchElementException.hpp>
42 css::frame::XSubToolbarController,
49 OUString m_aSubTbName;
50 OUString m_aLastCommand;
51 css::uno::Reference< css::ui::XUIElement > m_xUIElement;
52 void disposeUIElement();
55 const css::uno::Sequence< css::uno::Any >& rxArgs );
56 virtual ~SubToolBarController()
override;
58 void PopoverDestroyed();
61 virtual void SAL_CALL initialize(
const css::uno::Sequence< css::uno::Any >& rxArgs )
override;
64 virtual void SAL_CALL statusChanged(
const css::frame::FeatureStateEvent& Event )
override;
67 virtual void SAL_CALL execute( sal_Int16 nKeyModifier )
override;
71 virtual std::unique_ptr<WeldToolbarPopup> weldPopupWindow()
override;
74 virtual sal_Bool SAL_CALL opensSubToolbar()
override;
75 virtual OUString SAL_CALL getSubToolbarName()
override;
76 virtual void SAL_CALL functionSelected(
const OUString& rCommand )
override;
77 virtual void SAL_CALL updateImage()
override;
80 virtual void SAL_CALL startDocking(
const css::awt::DockingEvent& e )
override;
81 virtual css::awt::DockingData SAL_CALL docking(
const css::awt::DockingEvent& e )
override;
82 virtual void SAL_CALL endDocking(
const css::awt::EndDockingEvent& e )
override;
83 virtual sal_Bool SAL_CALL prepareToggleFloatingMode(
const css::lang::EventObject& e )
override;
84 virtual void SAL_CALL toggleFloatingMode(
const css::lang::EventObject& e )
override;
85 virtual void SAL_CALL closed(
const css::lang::EventObject& e )
override;
86 virtual void SAL_CALL endPopupMode(
const css::awt::EndPopupModeEvent& e )
override;
89 virtual void SAL_CALL disposing(
const css::lang::EventObject& e )
override;
92 virtual void SAL_CALL
dispose()
override;
102SubToolBarController::SubToolBarController(
104 const css::uno::Sequence< css::uno::Any >& rxArgs
111 for ( css::uno::Any
const & arg : rxArgs )
113 css::beans::PropertyValue aPropValue;
115 if ( aPropValue.Name ==
"Value" )
119 aPropValue.Value >>= aValue;
120 m_aSubTbName = aValue.getToken(0,
';', nIdx);
121 m_aCommandURL = m_aSubTbName;
122 m_aLastCommand = aValue.getToken(0,
';', nIdx);
126 if ( !m_aLastCommand.isEmpty() )
127 addStatusListener( m_aLastCommand );
130SubToolBarController::~SubToolBarController()
133 m_xUIElement =
nullptr;
136void SubToolBarController::disposeUIElement()
138 if ( m_xUIElement.is() )
140 css::uno::Reference< css::lang::XComponent > xComponent( m_xUIElement, css::uno::UNO_QUERY );
141 xComponent->dispose();
145void SubToolBarController::statusChanged(
const css::frame::FeatureStateEvent& Event )
154 if ( !getToolboxId( nId, &pToolBox ) )
161 if ( Event.FeatureURL.Complete == m_aCommandURL )
166 css::frame::status::Visibility aItemVisibility;
167 if ( Event.State >>= aStrValue )
171 if ( m_aLastCommand == Concat2View( m_aCommandURL +
"." + aStrValue ) )
174 nItemBits |= ToolBoxItemBits::CHECKABLE;
177 else if ( Event.State >>= aItemVisibility )
179 pToolBox->
ShowItem( nId, aItemVisibility.bVisible );
185 if ( Event.State >>= bValue )
190 nItemBits |= ToolBoxItemBits::CHECKABLE;
198void SubToolBarController::execute( sal_Int16 nKeyModifier )
200 if ( !m_aLastCommand.isEmpty() )
203 {
"KeyModifier", css::uno::Any( nKeyModifier ) }
213 explicit SubToolbarControl(SubToolBarController& rController,
weld::Widget* pParent);
214 virtual ~SubToolbarControl()
override;
222 std::unique_ptr<weld::Container> m_xTargetContainer;
226SubToolbarControl::SubToolbarControl(SubToolBarController& rController,
228 :
WeldToolbarPopup(rController.getFrameInterface(), pParent,
"svt/ui/subtoolbar.ui",
"subtoolbar")
230 , m_xTargetContainer(m_xBuilder->weld_container(
"container"))
234void SubToolbarControl::GrabFocus()
239SubToolbarControl::~SubToolbarControl()
244std::unique_ptr<WeldToolbarPopup> SubToolBarController::weldPopupWindow()
248 auto pPopup = std::make_unique<SubToolbarControl>(*
this, m_pToolbar);
250 css::uno::Reference< css::frame::XFrame >
xFrame ( getFrameInterface() );
253 static css::uno::WeakReference< css::ui::XUIElementFactoryManager > xWeakUIElementFactory;
254 css::uno::Reference< css::ui::XUIElementFactoryManager > xUIElementFactory = xWeakUIElementFactory;
255 if ( !xUIElementFactory.is() )
257 xUIElementFactory = css::ui::theUIElementFactoryManager::get(
m_xContext );
258 xWeakUIElementFactory = xUIElementFactory;
264 {
"Frame", css::uno::Any( xFrame ) },
265 {
"ParentWindow", css::uno::Any( xParent ) },
266 {
"Persistent", css::uno::Any(
false ) },
267 {
"PopupMode", css::uno::Any(
true ) }
272 m_xUIElement = xUIElementFactory->createUIElement(
"private:resource/toolbar/" + m_aSubTbName, aPropSeq );
274 catch ( css::container::NoSuchElementException& )
276 catch ( css::lang::IllegalArgumentException& )
288 if ( getToolboxId( nId, &pToolBox ) )
290 css::uno::Reference< css::frame::XFrame >
xFrame ( getFrameInterface() );
293 static css::uno::WeakReference< css::ui::XUIElementFactoryManager > xWeakUIElementFactory;
294 css::uno::Reference< css::ui::XUIElement > xUIElement;
295 css::uno::Reference< css::ui::XUIElementFactoryManager > xUIElementFactory = xWeakUIElementFactory;
296 if ( !xUIElementFactory.is() )
298 xUIElementFactory = css::ui::theUIElementFactoryManager::get(
m_xContext );
299 xWeakUIElementFactory = xUIElementFactory;
303 {
"Frame", css::uno::Any( xFrame ) },
304 {
"ParentWindow", css::uno::Any( m_xParentWindow ) },
305 {
"Persistent", css::uno::Any(
false ) },
306 {
"PopupMode", css::uno::Any(
true ) }
311 xUIElement = xUIElementFactory->createUIElement(
"private:resource/toolbar/" + m_aSubTbName, aPropSeq );
313 catch ( css::container::NoSuchElementException& )
315 catch ( css::lang::IllegalArgumentException& )
318 if ( xUIElement.is() )
320 css::uno::Reference< css::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), css::uno::UNO_QUERY );
321 if ( xSubToolBar.is() )
323 css::uno::Reference< css::awt::XDockableWindow > xDockWindow( xSubToolBar, css::uno::UNO_QUERY );
324 xDockWindow->addDockableWindowListener( css::uno::Reference< css::awt::XDockableWindowListener >(
this) );
325 xDockWindow->enableDocking(
true );
329 m_xUIElement = xUIElement;
332 if ( pTbxWindow && pTbxWindow->GetType() == WindowType::TOOLBOX )
347sal_Bool SubToolBarController::opensSubToolbar()
349 return !m_aLastCommand.isEmpty();
352OUString SubToolBarController::getSubToolbarName()
357void SubToolBarController::functionSelected(
const OUString& rCommand )
359 if ( !m_aLastCommand.isEmpty() && m_aLastCommand != rCommand )
361 removeStatusListener( m_aLastCommand );
362 m_aLastCommand = rCommand;
363 addStatusListener( m_aLastCommand );
368void SubToolBarController::updateImage()
371 if ( !m_aLastCommand.isEmpty() )
375 if ( getToolboxId( nId, &pToolBox ) )
385void SubToolBarController::startDocking(
const css::awt::DockingEvent& )
389css::awt::DockingData SubToolBarController::docking(
const css::awt::DockingEvent& )
391 return css::awt::DockingData();
394void SubToolBarController::endDocking(
const css::awt::EndDockingEvent& )
398sal_Bool SubToolBarController::prepareToggleFloatingMode(
const css::lang::EventObject& )
403void SubToolBarController::toggleFloatingMode(
const css::lang::EventObject& )
407void SubToolBarController::closed(
const css::lang::EventObject& )
411void SubToolBarController::endPopupMode(
const css::awt::EndPopupModeEvent& e )
415 OUString aSubToolBarResName;
416 if ( m_xUIElement.is() )
418 css::uno::Reference< css::beans::XPropertySet > xPropSet( m_xUIElement, css::uno::UNO_QUERY );
423 xPropSet->getPropertyValue(
"ResourceURL") >>= aSubToolBarResName;
425 catch ( css::beans::UnknownPropertyException& )
427 catch ( css::lang::WrappedTargetException& )
432 m_xUIElement =
nullptr;
438 css::uno::Reference< css::ui::XUIElement > xUIElement;
439 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager = getLayoutManager();
441 if ( !xLayoutManager.is() )
444 xLayoutManager->createElement( aSubToolBarResName );
445 xUIElement = xLayoutManager->getElement( aSubToolBarResName );
446 if ( !xUIElement.is() )
449 css::uno::Reference< css::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), css::uno::UNO_QUERY );
450 css::uno::Reference< css::beans::XPropertySet > xProp( xUIElement, css::uno::UNO_QUERY );
451 if ( !(xSubToolBar.is() && xProp.is()) )
457 if ( pTbxWindow && pTbxWindow->GetType() == WindowType::TOOLBOX )
459 OUString aPersistentString(
"Persistent" );
460 css::uno::Any
a = xProp->getPropertyValue( aPersistentString );
461 xProp->setPropertyValue( aPersistentString, css::uno::Any(
false ) );
463 xLayoutManager->hideElement( aSubToolBarResName );
464 xLayoutManager->floatWindow( aSubToolBarResName );
466 xLayoutManager->setElementPos( aSubToolBarResName, e.FloatingPosition );
467 xLayoutManager->showElement( aSubToolBarResName );
469 xProp->setPropertyValue(
"Persistent", a );
472 catch ( css::uno::RuntimeException& )
476 catch ( css::uno::Exception& )
480void SubToolBarController::disposing(
const css::lang::EventObject& e )
485void SubToolBarController::initialize(
const css::uno::Sequence< css::uno::Any >& rxArgs )
487 svt::PopupWindowController::initialize( rxArgs );
491 if ( getToolboxId( nId, &pToolBox ) )
493 if ( m_aLastCommand.isEmpty() )
502 m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel());
508void SubToolBarController::PopoverDestroyed()
511 m_xUIElement =
nullptr;
514void SubToolBarController::dispose()
521 m_xUIElement =
nullptr;
524OUString SubToolBarController::getImplementationName()
526 return "com.sun.star.comp.framework.SubToolBarController";
529sal_Bool SubToolBarController::supportsService(
const OUString& rServiceName )
534css::uno::Sequence< OUString > SubToolBarController::getSupportedServiceNames()
536 return {
"com.sun.star.frame.ToolbarController"};
539extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
541 css::uno::XComponentContext* rxContext,
542 css::uno::Sequence<css::uno::Any>
const & rxArgs )
544 return cppu::acquire(
new SubToolBarController( rxContext, rxArgs ) );
void StartPopupMode(const vcl::Window *pWin, const tools::Rectangle &rRect, FloatWinPopupFlags nPopupModeFlags)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
reference_type * get() const
ClassificationCategoriesController & m_rController
virtual void SetSizePixel(const Size &rNewSize)
static DockingManager * GetDockingManager()
css::uno::Reference< css::uno::XComponentContext > m_xContext
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
Reference< XFrame > xFrame