Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include "ShapeToolbarController.hxx"
22 : :
23 : : #include <osl/mutex.hxx>
24 : : #include <comphelper/sequence.hxx>
25 : : #include <vcl/svapp.hxx>
26 : : #include <vcl/toolbox.hxx>
27 : : #include <toolkit/helper/vclunohelper.hxx>
28 : : #include <svx/svxids.hrc>
29 : : #include <svx/tbxcustomshapes.hxx>
30 : :
31 : :
32 : : using namespace com::sun::star;
33 : :
34 : : using ::com::sun::star::uno::Reference;
35 : : using ::com::sun::star::uno::Sequence;
36 : :
37 : : //.............................................................................
38 : : namespace chart
39 : : {
40 : : //.............................................................................
41 : :
42 : 0 : ::rtl::OUString ShapeToolbarController::getImplementationName() throw (uno::RuntimeException)
43 : : {
44 : 0 : return getImplementationName_Static();
45 : : }
46 : :
47 : 32 : ::rtl::OUString ShapeToolbarController::getImplementationName_Static() throw (uno::RuntimeException)
48 : : {
49 : 32 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ShapeToolbarController" ) );
50 : : }
51 : :
52 : 4 : Sequence< ::rtl::OUString > ShapeToolbarController::getSupportedServiceNames_Static() throw (uno::RuntimeException)
53 : : {
54 : 4 : Sequence< ::rtl::OUString > aSupported(1);
55 [ + - ][ + - ]: 4 : aSupported.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ShapeToolbarController" ) );
56 : 4 : return aSupported;
57 : : }
58 : :
59 : 0 : ::sal_Bool ShapeToolbarController::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
60 : : {
61 [ # # ]: 0 : return ::comphelper::existsValue( ServiceName, getSupportedServiceNames_Static() );
62 : : }
63 : :
64 : 0 : Sequence< ::rtl::OUString> ShapeToolbarController::getSupportedServiceNames() throw (uno::RuntimeException)
65 : : {
66 : 0 : return getSupportedServiceNames_Static();
67 : : }
68 : :
69 : 204 : Reference< uno::XInterface > ShapeToolbarController::create( const Reference< uno::XComponentContext >& xContext )
70 : : {
71 [ + - ][ + - ]: 204 : return *( new ShapeToolbarController( Reference< lang::XMultiServiceFactory >( xContext->getServiceManager(), uno::UNO_QUERY ) ) );
[ + - ]
72 : : }
73 : :
74 : 204 : ShapeToolbarController::ShapeToolbarController( const Reference< lang::XMultiServiceFactory >& rxFact )
75 : : :m_pToolbarController( NULL )
76 : : ,m_nToolBoxId( 1 )
77 [ + - ][ + - ]: 204 : ,m_nSlotId( 0 )
78 : : {
79 [ + - ]: 204 : osl_incrementInterlockedCount( &m_refCount );
80 [ + - ]: 204 : m_xServiceManager = rxFact;
81 [ + - ]: 204 : osl_decrementInterlockedCount( &m_refCount );
82 : 204 : }
83 : :
84 [ + - ]: 204 : ShapeToolbarController::~ShapeToolbarController()
85 : : {
86 [ - + ]: 408 : }
87 : :
88 : : // ::com::sun::star::uno::XInterface
89 : 2244 : uno::Any ShapeToolbarController::queryInterface( const uno::Type& rType ) throw (uno::RuntimeException)
90 : : {
91 : 2244 : uno::Any aReturn = ToolboxController::queryInterface( rType );
92 [ + + ]: 2244 : if ( !aReturn.hasValue() )
93 : : {
94 [ + - ]: 204 : aReturn = ShapeToolbarController_Base::queryInterface( rType );
95 : : }
96 : 2244 : return aReturn;
97 : : }
98 : :
99 : 6528 : void ShapeToolbarController::acquire() throw ()
100 : : {
101 : 6528 : ToolboxController::acquire();
102 : 6528 : }
103 : :
104 : 6528 : void ShapeToolbarController::release() throw ()
105 : : {
106 : 6528 : ToolboxController::release();
107 : 6528 : }
108 : :
109 : : // ::com::sun::star::lang::XInitialization
110 : 204 : void ShapeToolbarController::initialize( const Sequence< uno::Any >& rArguments ) throw (uno::Exception, uno::RuntimeException)
111 : : {
112 [ + - ]: 204 : ToolboxController::initialize( rArguments );
113 [ + - ]: 204 : SolarMutexGuard aSolarMutexGuard;
114 [ + - ]: 204 : ::osl::MutexGuard aGuard( m_aMutex );
115 : :
116 [ + - ][ + - ]: 204 : ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
117 [ + - ]: 204 : if ( pToolBox )
118 : : {
119 [ + - ]: 204 : const sal_uInt16 nCount = pToolBox->GetItemCount();
120 [ + - ]: 2754 : for ( sal_uInt16 nPos = 0; nPos < nCount; ++nPos )
121 : : {
122 [ + - ]: 2754 : const sal_uInt16 nItemId = pToolBox->GetItemId( nPos );
123 [ + - ][ + - ]: 2754 : if ( pToolBox->GetItemCommand( nItemId ) == String( m_aCommandURL ) )
[ + - ][ + - ]
[ + + ]
124 : : {
125 : 204 : m_nToolBoxId = nItemId;
126 : 204 : break;
127 : : }
128 : : }
129 [ + + ]: 204 : if ( m_aCommandURL == ".uno:BasicShapes" )
130 : : {
131 [ + - ][ + - ]: 34 : m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BasicShapes" ) ), sal_True ) );
132 : 34 : m_nSlotId = SID_DRAWTBX_CS_BASIC;
133 [ + - ][ + - ]: 34 : m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
[ + - ][ + - ]
134 : : }
135 [ + + ]: 170 : else if ( m_aCommandURL == ".uno:SymbolShapes" )
136 : : {
137 [ + - ][ + - ]: 34 : m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:SymbolShapes" ) ), sal_True ) );
138 : 34 : m_nSlotId = SID_DRAWTBX_CS_SYMBOL;
139 [ + - ][ + - ]: 34 : m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
[ + - ][ + - ]
140 : : }
141 [ + + ]: 136 : else if ( m_aCommandURL == ".uno:ArrowShapes" )
142 : : {
143 [ + - ][ + - ]: 34 : m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ArrowShapes" ) ), sal_True ) );
144 : 34 : m_nSlotId = SID_DRAWTBX_CS_ARROW;
145 [ + - ][ + - ]: 34 : m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox) );
[ + - ][ + - ]
146 : : }
147 [ + + ]: 102 : else if ( m_aCommandURL == ".uno:FlowChartShapes" )
148 : : {
149 [ + - ][ + - ]: 34 : m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FlowChartShapes" ) ), sal_True ) );
150 : 34 : m_nSlotId = SID_DRAWTBX_CS_FLOWCHART;
151 [ + - ][ + - ]: 34 : m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
[ + - ][ + - ]
152 : : }
153 [ + + ]: 68 : else if ( m_aCommandURL == ".uno:CalloutShapes" )
154 : : {
155 [ + - ][ + - ]: 34 : m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CalloutShapes" ) ), sal_True ) );
156 : 34 : m_nSlotId = SID_DRAWTBX_CS_CALLOUT;
157 [ + - ][ + - ]: 34 : m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
[ + - ][ + - ]
158 : : }
159 [ + - ]: 34 : else if ( m_aCommandURL == ".uno:StarShapes" )
160 : : {
161 [ + - ][ + - ]: 34 : m_aStates.insert( TCommandState::value_type( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:StarShapes" ) ), sal_True ) );
162 : 34 : m_nSlotId = SID_DRAWTBX_CS_STAR;
163 [ + - ][ + - ]: 34 : m_pToolbarController = TToolbarHelper::createFromQuery( new SvxTbxCtlCustomShapes( m_nSlotId, m_nToolBoxId, *pToolBox ) );
[ + - ][ + - ]
164 : : }
165 : :
166 [ + + ]: 408 : for ( TCommandState::iterator aIter( m_aStates.begin() ); aIter != m_aStates.end(); ++aIter )
167 : : {
168 [ + - ]: 204 : addStatusListener( aIter->first );
169 : : }
170 : :
171 [ + - ]: 204 : if ( m_pToolbarController.is() )
172 : : {
173 [ + - ]: 204 : m_pToolbarController->initialize( rArguments );
174 : : }
175 : :
176 : : // check if paste special is allowed, when not don't add DROPDOWN
177 [ + - ][ + - ]: 204 : pToolBox->SetItemBits( m_nToolBoxId, pToolBox->GetItemBits( m_nToolBoxId ) | TIB_DROPDOWN );
178 [ + - ][ + - ]: 204 : }
179 : 204 : }
180 : :
181 : : // ::com::sun::star::frame::XStatusListener
182 : 204 : void ShapeToolbarController::statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException )
183 : : {
184 [ + - ]: 204 : ::osl::MutexGuard aGuard( m_aMutex );
185 [ + - ]: 204 : TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
186 [ + - ]: 204 : if ( aFind != m_aStates.end() )
187 : : {
188 : 204 : aFind->second = Event.IsEnabled;
189 [ + - ]: 204 : if ( m_pToolbarController.is() )
190 : : {
191 : 204 : sal_Bool bCheckmark = sal_False;
192 [ + - ]: 204 : ToolBox& rTb = m_pToolbarController->GetToolBox();
193 : :
194 [ + - ][ + + ]: 3468 : for ( sal_uInt16 i = 0; i < rTb.GetItemCount(); ++i )
195 : : {
196 [ + - ]: 3264 : sal_uInt16 nId = rTb.GetItemId( i );
197 [ + + ]: 3264 : if ( nId == 0 )
198 : : {
199 : 408 : continue;
200 : : }
201 [ + - ][ + - ]: 2856 : ::rtl::OUString aCmd = rTb.GetItemCommand( nId );
202 [ + + ]: 2856 : if ( aCmd == Event.FeatureURL.Complete )
203 : : {
204 [ + - ]: 204 : rTb.EnableItem( nId, Event.IsEnabled );
205 [ + - ]: 204 : if ( Event.State >>= bCheckmark )
206 : : {
207 [ + - ]: 204 : rTb.CheckItem( nId, bCheckmark );
208 : : }
209 : : else
210 : : {
211 : 0 : ::rtl::OUString aItemText;
212 [ # # ]: 0 : if ( Event.State >>= aItemText )
213 : : {
214 [ # # ][ # # ]: 0 : rTb.SetItemText( nId, aItemText );
[ # # ]
215 : 0 : }
216 : : }
217 : : }
218 : 2856 : }
219 : : }
220 [ + - ]: 204 : }
221 : 204 : }
222 : :
223 : : // ::com::sun::star::frame::XToolbarController
224 : 0 : Reference< awt::XWindow > ShapeToolbarController::createPopupWindow() throw (uno::RuntimeException)
225 : : {
226 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
227 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
228 : :
229 : 0 : Reference< awt::XWindow > xRet;
230 [ # # ]: 0 : if ( m_pToolbarController.is() )
231 : : {
232 [ # # ][ # # ]: 0 : xRet = m_pToolbarController.getRef()->createPopupWindow();
[ # # ][ # # ]
233 : : }
234 : :
235 [ # # ][ # # ]: 0 : return xRet;
236 : : }
237 : :
238 : : // ::com::sun::star::frame::XSubToolbarController
239 : 204 : ::sal_Bool ShapeToolbarController::opensSubToolbar() throw (uno::RuntimeException)
240 : : {
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 [ + + ][ + + ]: 204 : m_nSlotId == SID_DRAWTBX_CS_STAR );
[ + + ][ + + ]
[ + + ][ + - ]
247 : : }
248 : :
249 : 204 : ::rtl::OUString ShapeToolbarController::getSubToolbarName() throw (uno::RuntimeException)
250 : : {
251 [ + - ]: 204 : SolarMutexGuard aSolarMutexGuard;
252 [ + - ]: 204 : ::osl::MutexGuard aGuard(m_aMutex);
253 [ + - ][ + - ]: 204 : uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
254 [ + - ]: 204 : if ( xSub.is() )
255 : : {
256 [ + - ][ + - ]: 204 : return xSub->getSubToolbarName();
257 : : }
258 [ + - ][ + - ]: 204 : return ::rtl::OUString();
259 : : }
260 : :
261 : 0 : void ShapeToolbarController::functionSelected( const ::rtl::OUString& rCommand ) throw (uno::RuntimeException)
262 : : {
263 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
264 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
265 : :
266 [ # # ][ # # ]: 0 : uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
267 [ # # ]: 0 : if ( xSub.is() )
268 : : {
269 : 0 : m_aCommandURL = rCommand;
270 [ # # ][ # # ]: 0 : xSub->functionSelected( rCommand );
271 [ # # ][ # # ]: 0 : }
272 : 0 : }
273 : :
274 : 0 : void ShapeToolbarController::updateImage() throw (uno::RuntimeException)
275 : : {
276 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
277 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
278 : :
279 [ # # ][ # # ]: 0 : uno::Reference< frame::XSubToolbarController > xSub( m_pToolbarController.getRef(), uno::UNO_QUERY );
280 [ # # ]: 0 : if ( xSub.is() )
281 : : {
282 [ # # ][ # # ]: 0 : xSub->updateImage();
283 [ # # ][ # # ]: 0 : }
284 : 0 : }
285 : :
286 : : //.............................................................................
287 : : } // namespace chart
288 : : //.............................................................................
289 : :
290 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|