fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / main / ShapeToolbarController.cxx
blob999c9bacdd5c149588daea815df1ae6758286027
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ShapeToolbarController.hxx"
22 #include <osl/mutex.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/toolbox.hxx>
26 #include <toolkit/helper/vclunohelper.hxx>
27 #include <svx/svxids.hrc>
28 #include <svx/tbxcustomshapes.hxx>
29 #include <comphelper/propertysequence.hxx>
31 using namespace com::sun::star;
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::Sequence;
36 namespace chart
39 OUString ShapeToolbarController::getImplementationName() throw (uno::RuntimeException, std::exception)
41 return getImplementationName_Static();
44 OUString ShapeToolbarController::getImplementationName_Static() throw (uno::RuntimeException)
46 return OUString( "com.sun.star.comp.chart2.ShapeToolbarController" );
49 Sequence< OUString > ShapeToolbarController::getSupportedServiceNames_Static() throw (uno::RuntimeException)
51 Sequence< OUString > aSupported(1);
52 aSupported.getArray()[0] = "com.sun.star.chart2.ShapeToolbarController";
53 return aSupported;
56 sal_Bool ShapeToolbarController::supportsService( const OUString& ServiceName ) throw (uno::RuntimeException, std::exception)
58 return cppu::supportsService( this, ServiceName );
61 Sequence< OUString > ShapeToolbarController::getSupportedServiceNames() throw (uno::RuntimeException, std::exception)
63 return getSupportedServiceNames_Static();
66 ShapeToolbarController::ShapeToolbarController( const Reference< uno::XComponentContext >& xContext )
67 :m_pToolbarController( NULL )
68 ,m_nToolBoxId( 1 )
69 ,m_nSlotId( 0 )
71 osl_atomic_increment( &m_refCount );
72 m_xContext = xContext;
73 osl_atomic_decrement( &m_refCount );
76 ShapeToolbarController::~ShapeToolbarController()
80 // ::com::sun::star::uno::XInterface
81 uno::Any ShapeToolbarController::queryInterface( const uno::Type& rType ) throw (uno::RuntimeException, std::exception)
83 uno::Any aReturn = ToolboxController::queryInterface( rType );
84 if ( !aReturn.hasValue() )
86 aReturn = ShapeToolbarController_Base::queryInterface( rType );
88 return aReturn;
91 void ShapeToolbarController::acquire() throw ()
93 ToolboxController::acquire();
96 void ShapeToolbarController::release() throw ()
98 ToolboxController::release();
101 // ::com::sun::star::lang::XInitialization
102 void ShapeToolbarController::initialize( const Sequence< uno::Any >& rArguments ) throw (uno::Exception, uno::RuntimeException, std::exception)
104 ToolboxController::initialize( rArguments );
105 SolarMutexGuard aSolarMutexGuard;
106 ::osl::MutexGuard aGuard( m_aMutex );
108 VclPtr< ToolBox > pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ).get() );
109 if ( pToolBox )
111 const sal_uInt16 nCount = pToolBox->GetItemCount();
112 for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
114 const sal_uInt16 nItemId = pToolBox->GetItemId( nPos );
115 if ( pToolBox->GetItemCommand( nItemId ) == m_aCommandURL )
117 m_nToolBoxId = nItemId;
118 break;
121 if ( m_aCommandURL == ".uno:BasicShapes" )
123 m_aStates.insert( TCommandState::value_type( ".uno:BasicShapes", sal_True ) );
124 m_nSlotId = SID_DRAWTBX_CS_BASIC;
125 m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox );
127 else if ( m_aCommandURL == ".uno:SymbolShapes" )
129 m_aStates.insert( TCommandState::value_type( ".uno:SymbolShapes", sal_True ) );
130 m_nSlotId = SID_DRAWTBX_CS_SYMBOL;
131 m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox );
133 else if ( m_aCommandURL == ".uno:ArrowShapes" )
135 m_aStates.insert( TCommandState::value_type( ".uno:ArrowShapes", sal_True ) );
136 m_nSlotId = SID_DRAWTBX_CS_ARROW;
137 m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox);
139 else if ( m_aCommandURL == ".uno:FlowChartShapes" )
141 m_aStates.insert( TCommandState::value_type( ".uno:FlowChartShapes", sal_True ) );
142 m_nSlotId = SID_DRAWTBX_CS_FLOWCHART;
143 m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox );
145 else if ( m_aCommandURL == ".uno:CalloutShapes" )
147 m_aStates.insert( TCommandState::value_type( ".uno:CalloutShapes", sal_True ) );
148 m_nSlotId = SID_DRAWTBX_CS_CALLOUT;
149 m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox );
151 else if ( m_aCommandURL == ".uno:StarShapes" )
153 m_aStates.insert( TCommandState::value_type( ".uno:StarShapes" , sal_True ) );
154 m_nSlotId = SID_DRAWTBX_CS_STAR;
155 m_pToolbarController = new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox );
158 for ( TCommandState::iterator aIter( m_aStates.begin() ); aIter != m_aStates.end(); ++aIter )
160 addStatusListener( aIter->first );
163 if ( m_pToolbarController.is() )
165 m_pToolbarController->initialize( rArguments );
168 // check if paste special is allowed, when not don't add DROPDOWN
169 pToolBox->SetItemBits( m_nToolBoxId, pToolBox->GetItemBits( m_nToolBoxId ) | ToolBoxItemBits::DROPDOWN );
173 // ::com::sun::star::frame::XStatusListener
174 void ShapeToolbarController::statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException, std::exception )
176 ::osl::MutexGuard aGuard( m_aMutex );
177 TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
178 if ( aFind != m_aStates.end() )
180 aFind->second = Event.IsEnabled;
181 if ( m_pToolbarController.is() )
183 bool bCheckmark = false;
184 ToolBox& rTb = m_pToolbarController->GetToolBox();
186 for ( sal_uInt16 i = 0; i < rTb.GetItemCount(); ++i )
188 sal_uInt16 nId = rTb.GetItemId( i );
189 if ( nId == 0 )
191 continue;
193 OUString aCmd = rTb.GetItemCommand( nId );
194 if ( aCmd == Event.FeatureURL.Complete )
196 rTb.EnableItem( nId, Event.IsEnabled );
197 if ( Event.State >>= bCheckmark )
199 rTb.CheckItem( nId, bCheckmark );
201 else
203 OUString aItemText;
204 if ( Event.State >>= aItemText )
206 rTb.SetItemText( nId, aItemText );
215 // ::com::sun::star::frame::XToolbarController
216 Reference< awt::XWindow > ShapeToolbarController::createPopupWindow() throw (uno::RuntimeException, std::exception)
218 SolarMutexGuard aSolarMutexGuard;
219 ::osl::MutexGuard aGuard( m_aMutex );
221 Reference< awt::XWindow > xRet;
222 if ( m_pToolbarController.is() )
224 xRet = m_pToolbarController->createPopupWindow();
227 return xRet;
230 void ShapeToolbarController::execute( sal_Int16 KeyModifier ) throw (uno::RuntimeException, std::exception)
232 auto aArgs(::comphelper::InitPropertySequence({
233 { "KeyModifier", uno::makeAny(KeyModifier) }
234 }));
235 dispatchCommand( m_aCommandURL, aArgs );
238 // ::com::sun::star::frame::XSubToolbarController
239 sal_Bool ShapeToolbarController::opensSubToolbar() throw (uno::RuntimeException, std::exception)
241 return ( m_nSlotId == SID_DRAWTBX_CS_BASIC ||
242 m_nSlotId == SID_DRAWTBX_CS_SYMBOL ||
243 m_nSlotId == SID_DRAWTBX_CS_ARROW ||
244 m_nSlotId == SID_DRAWTBX_CS_FLOWCHART ||
245 m_nSlotId == SID_DRAWTBX_CS_CALLOUT ||
246 m_nSlotId == SID_DRAWTBX_CS_STAR );
249 OUString ShapeToolbarController::getSubToolbarName() throw (uno::RuntimeException, std::exception)
251 SolarMutexGuard aSolarMutexGuard;
252 ::osl::MutexGuard aGuard(m_aMutex);
253 if ( m_pToolbarController.is() )
255 return m_pToolbarController->getSubToolbarName();
257 return OUString();
260 void ShapeToolbarController::functionSelected( const OUString& rCommand ) throw (uno::RuntimeException, std::exception)
262 SolarMutexGuard aSolarMutexGuard;
263 ::osl::MutexGuard aGuard( m_aMutex );
264 if ( m_pToolbarController.is() )
266 m_aCommandURL = rCommand;
267 m_pToolbarController->functionSelected( rCommand );
271 void ShapeToolbarController::updateImage() throw (uno::RuntimeException, std::exception)
273 SolarMutexGuard aSolarMutexGuard;
274 ::osl::MutexGuard aGuard( m_aMutex );
275 if ( m_pToolbarController.is() )
277 m_pToolbarController->updateImage();
281 } // namespace chart
283 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
284 com_sun_star_comp_chart2_ShapeToolbarController_get_implementation(css::uno::XComponentContext *context,
285 css::uno::Sequence<css::uno::Any> const &)
287 return cppu::acquire(new ::chart::ShapeToolbarController(context));
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */