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 : #include "toolboxcontroller.hxx"
20 : #include <com/sun/star/ui/ImageType.hpp>
21 : #include <com/sun/star/frame/XDispatchProvider.hpp>
22 : #include <com/sun/star/beans/PropertyValue.hpp>
23 : #include <toolkit/helper/vclunohelper.hxx>
24 : #include <vcl/menu.hxx>
25 : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
26 : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
27 : #include <com/sun/star/ui/XImageManager.hpp>
28 : #include <com/sun/star/graphic/XGraphic.hpp>
29 : #include <com/sun/star/util/Color.hpp>
30 : #include <vcl/svapp.hxx>
31 : #include <vcl/toolbox.hxx>
32 : #include <svtools/miscopt.hxx>
33 : #include <unotools/moduleoptions.hxx>
34 : #include <svtools/menuoptions.hxx>
35 : #include <osl/mutex.hxx>
36 : #include <svx/svxids.hrc>
37 : #define ITEMID_FONT 3
38 : #include <editeng/fontitem.hxx>
39 : #include <editeng/fhgtitem.hxx>
40 : #include <svx/tbcontrl.hxx>
41 : #include <editeng/colritem.hxx>
42 : #include <svx/tbxcustomshapes.hxx>
43 :
44 : #include <comphelper/sequence.hxx>
45 :
46 : #include <memory>
47 :
48 : namespace rptui
49 : {
50 : using namespace svt;
51 : using namespace com::sun::star;
52 : using namespace com::sun::star::uno;
53 : using namespace com::sun::star::beans;
54 : using namespace com::sun::star::lang;
55 : using namespace frame;
56 : using namespace util;
57 : using namespace ui;
58 :
59 0 : OUString SAL_CALL OToolboxController::getImplementationName() throw( RuntimeException )
60 : {
61 0 : return getImplementationName_Static();
62 : }
63 :
64 : //------------------------------------------------------------------------------
65 0 : OUString OToolboxController::getImplementationName_Static() throw( RuntimeException )
66 : {
67 0 : return OUString("com.sun.star.report.comp.ReportToolboxController");
68 : }
69 : //------------------------------------------------------------------------------
70 0 : Sequence< OUString> OToolboxController::getSupportedServiceNames_Static(void) throw( RuntimeException )
71 : {
72 0 : Sequence< OUString> aSupported(1);
73 0 : aSupported.getArray()[0] = OUString("com.sun.star.report.ReportToolboxController");
74 0 : return aSupported;
75 : }
76 : // -----------------------------------------------------------------------------
77 0 : ::sal_Bool SAL_CALL OToolboxController::supportsService( const OUString& ServiceName ) throw (uno::RuntimeException)
78 : {
79 0 : return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_Static());
80 : }
81 : //-------------------------------------------------------------------------
82 0 : Sequence< OUString> SAL_CALL OToolboxController::getSupportedServiceNames() throw(RuntimeException)
83 : {
84 0 : return getSupportedServiceNames_Static();
85 : }
86 : // -------------------------------------------------------------------------
87 0 : Reference< XInterface > OToolboxController::create(Reference< XComponentContext > const & xContext)
88 : {
89 0 : return * new OToolboxController(xContext);
90 : }
91 : // -----------------------------------------------------------------------------
92 : DBG_NAME(rpt_OToolboxController)
93 0 : OToolboxController::OToolboxController(const Reference< XComponentContext >& _rxORB)
94 : : m_pToolbarController(NULL)
95 : ,m_nToolBoxId(1)
96 0 : ,m_nSlotId(0)
97 : {
98 : DBG_CTOR(rpt_OToolboxController,NULL);
99 0 : osl_atomic_increment(&m_refCount);
100 0 : m_xContext = _rxORB;
101 0 : osl_atomic_decrement(&m_refCount);
102 :
103 0 : }
104 : // -----------------------------------------------------------------------------
105 0 : OToolboxController::~OToolboxController()
106 : {
107 : DBG_DTOR(rpt_OToolboxController,NULL);
108 0 : }
109 : // -----------------------------------------------------------------------------
110 : // XInterface
111 0 : Any SAL_CALL OToolboxController::queryInterface( const Type& _rType ) throw (RuntimeException)
112 : {
113 0 : Any aReturn = ToolboxController::queryInterface(_rType);
114 0 : if (!aReturn.hasValue())
115 0 : aReturn = TToolboxController_BASE::queryInterface(_rType);
116 0 : return aReturn;
117 : }
118 : // -----------------------------------------------------------------------------
119 0 : void SAL_CALL OToolboxController::acquire() throw ()
120 : {
121 0 : ToolboxController::acquire();
122 0 : }
123 : // -----------------------------------------------------------------------------
124 0 : void SAL_CALL OToolboxController::release() throw ()
125 : {
126 0 : ToolboxController::release();
127 0 : }
128 : // -----------------------------------------------------------------------------
129 0 : void SAL_CALL OToolboxController::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
130 : {
131 0 : ToolboxController::initialize(_rArguments);
132 0 : SolarMutexGuard aSolarMutexGuard;
133 0 : ::osl::MutexGuard aGuard(m_aMutex);
134 :
135 0 : ToolBox* pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
136 0 : if ( pToolBox )
137 : {
138 0 : const sal_uInt16 nCount = pToolBox->GetItemCount();
139 0 : for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
140 : {
141 0 : const sal_uInt16 nItemId = pToolBox->GetItemId(nPos);
142 0 : if ( pToolBox->GetItemCommand(nItemId) == String(m_aCommandURL) )
143 : {
144 0 : m_nToolBoxId = nItemId;
145 0 : break;
146 : }
147 : }
148 0 : if ( m_aCommandURL == ".uno:BasicShapes" )
149 : {
150 0 : m_aStates.insert(TCommandState::value_type(OUString(".uno:BasicShapes"),sal_True));
151 0 : m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_BASIC,m_nToolBoxId,*pToolBox));
152 : }
153 0 : else if ( m_aCommandURL == ".uno:SymbolShapes" )
154 : {
155 0 : m_aStates.insert(TCommandState::value_type(OUString(".uno:SymbolShapes"),sal_True));
156 0 : m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_SYMBOL,m_nToolBoxId,*pToolBox));
157 : }
158 0 : else if ( m_aCommandURL == ".uno:ArrowShapes" )
159 : {
160 0 : m_aStates.insert(TCommandState::value_type(OUString(".uno:ArrowShapes"),sal_True));
161 0 : m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_ARROW,m_nToolBoxId,*pToolBox));
162 : }
163 0 : else if ( m_aCommandURL == ".uno:FlowChartShapes" )
164 : {
165 0 : m_aStates.insert(TCommandState::value_type(OUString(".uno:FlowChartShapes"),sal_True));
166 0 : m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_FLOWCHART,m_nToolBoxId,*pToolBox));
167 : }
168 0 : else if ( m_aCommandURL == ".uno:CalloutShapes" )
169 : {
170 0 : m_aStates.insert(TCommandState::value_type(OUString(".uno:CalloutShapes"),sal_True));
171 0 : m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_CALLOUT,m_nToolBoxId,*pToolBox));
172 : }
173 0 : else if ( m_aCommandURL == ".uno:StarShapes" )
174 : {
175 0 : m_aStates.insert(TCommandState::value_type(OUString(".uno:StarShapes"),sal_True));
176 0 : m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_STAR,m_nToolBoxId,*pToolBox));
177 : }
178 0 : else if ( m_aCommandURL == ".uno:CharFontName" )
179 : {
180 0 : m_aStates.insert(TCommandState::value_type(OUString(".uno:CharFontName"),sal_True));
181 0 : m_pToolbarController = TToolbarHelper::createFromQuery(new SvxFontNameToolBoxControl/*SvxStyleToolBoxControl*/(m_nSlotId = SID_ATTR_CHAR_FONT,m_nToolBoxId,*pToolBox));
182 : }
183 0 : else if ( m_aCommandURL.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(".uno:FontColor")) || m_aCommandURL.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(".uno:Color")) )
184 : {
185 0 : m_aStates.insert(TCommandState::value_type(OUString(".uno:FontColor"),sal_True));
186 0 : m_aStates.insert(TCommandState::value_type(OUString(".uno:Color"),sal_True));
187 0 : m_pToolbarController = TToolbarHelper::createFromQuery(new SvxColorExtToolBoxControl(m_nSlotId = SID_ATTR_CHAR_COLOR2,m_nToolBoxId,*pToolBox));
188 : }
189 : else
190 : {
191 0 : m_aStates.insert(TCommandState::value_type(OUString(".uno:BackgroundColor"),sal_True));
192 0 : m_pToolbarController = TToolbarHelper::createFromQuery(new SvxColorToolBoxControl(m_nSlotId = SID_BACKGROUND_COLOR,m_nToolBoxId,*pToolBox));
193 : }
194 :
195 0 : TCommandState::iterator aIter = m_aStates.begin();
196 0 : for (; aIter != m_aStates.end(); ++aIter)
197 0 : addStatusListener(aIter->first);
198 :
199 0 : if ( m_pToolbarController.is() )
200 0 : m_pToolbarController->initialize(_rArguments);
201 : // check if paste special is allowed, when not don't add DROPDOWN
202 0 : pToolBox->SetItemBits(m_nToolBoxId,pToolBox->GetItemBits(m_nToolBoxId) | TIB_DROPDOWN);
203 0 : }
204 0 : }
205 : // -----------------------------------------------------------------------------
206 0 : void SAL_CALL OToolboxController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
207 : {
208 0 : ::osl::MutexGuard aGuard(m_aMutex);
209 0 : TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
210 0 : if ( aFind != m_aStates.end() )
211 : {
212 0 : aFind->second = Event.IsEnabled;
213 0 : if ( m_pToolbarController.is() )
214 : {
215 : // All other status events will be processed here
216 0 : sal_Bool bSetCheckmark = sal_False;
217 0 : sal_Bool bCheckmark = sal_False;
218 : //m_pToolbarController->GetToolBox().Enable(Event.IsEnabled);
219 0 : ToolBox& rTb = m_pToolbarController->GetToolBox();
220 0 : for ( sal_uInt16 i = 0; i < rTb.GetItemCount(); i++ )
221 : {
222 0 : sal_uInt16 nId = rTb.GetItemId( i );
223 0 : if ( nId == 0 )
224 0 : continue;
225 :
226 0 : OUString aCmd = rTb.GetItemCommand( nId );
227 0 : if ( aCmd == Event.FeatureURL.Complete )
228 : {
229 : // Enable/disable item
230 0 : rTb.EnableItem( nId, Event.IsEnabled );
231 :
232 : // Checkmark
233 0 : if ( Event.State >>= bCheckmark )
234 0 : bSetCheckmark = sal_True;
235 :
236 0 : if ( bSetCheckmark )
237 0 : rTb.CheckItem( nId, bCheckmark );
238 : else
239 : {
240 0 : OUString aItemText;
241 :
242 0 : if ( Event.State >>= aItemText )
243 0 : rTb.SetItemText( nId, aItemText );
244 : }
245 : }
246 0 : }
247 :
248 0 : switch(m_nSlotId)
249 : {
250 : case SID_ATTR_CHAR_COLOR2:
251 : case SID_BACKGROUND_COLOR:
252 : {
253 0 : util::Color nColor(COL_TRANSPARENT);
254 0 : Event.State >>= nColor;
255 0 : ::Color aGcc3WorkaroundTemporary( nColor);
256 0 : SvxColorItem aColorItem(aGcc3WorkaroundTemporary,1);
257 0 : if ( SID_ATTR_CHAR_COLOR2 == m_nSlotId )
258 0 : static_cast<SvxColorExtToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SFX_ITEM_SET : SFX_ITEM_DISABLED,&aColorItem);
259 : else
260 0 : static_cast<SvxColorToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SFX_ITEM_SET : SFX_ITEM_DISABLED,&aColorItem);
261 : }
262 0 : break;
263 : case SID_ATTR_CHAR_FONT:
264 : {
265 0 : SvxFontItem aItem(ITEMID_FONT);
266 0 : aItem.PutValue(Event.State);
267 0 : static_cast<SvxFontNameToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SFX_ITEM_AVAILABLE : SFX_ITEM_DISABLED,&aItem);
268 : }
269 0 : break;
270 : }
271 : }
272 0 : }
273 0 : }
274 : // -----------------------------------------------------------------------------
275 0 : Reference< awt::XWindow > SAL_CALL OToolboxController::createPopupWindow() throw (RuntimeException)
276 : {
277 : // execute the menu
278 0 : SolarMutexGuard aSolarMutexGuard;
279 0 : ::osl::MutexGuard aGuard(m_aMutex);
280 :
281 0 : Reference< awt::XWindow > xRet;
282 0 : if ( m_pToolbarController.is() )
283 0 : xRet = m_pToolbarController.getRef()->createPopupWindow();
284 :
285 0 : return xRet;
286 : }
287 : // -----------------------------------------------------------------------------
288 0 : ::sal_Bool SAL_CALL OToolboxController::opensSubToolbar() throw (uno::RuntimeException)
289 : {
290 0 : return m_nSlotId == SID_DRAWTBX_CS_BASIC;
291 : }
292 : // -----------------------------------------------------------------------------
293 0 : OUString SAL_CALL OToolboxController::getSubToolbarName() throw (uno::RuntimeException)
294 : {
295 0 : SolarMutexGuard aSolarMutexGuard;
296 0 : ::osl::MutexGuard aGuard(m_aMutex);
297 0 : uno::Reference< frame::XSubToolbarController> xSub(m_pToolbarController.getRef(),uno::UNO_QUERY);
298 0 : if ( xSub.is() )
299 0 : return xSub->getSubToolbarName();
300 0 : return OUString();
301 : }
302 : // -----------------------------------------------------------------------------
303 0 : void SAL_CALL OToolboxController::functionSelected( const OUString& rCommand ) throw (uno::RuntimeException)
304 : {
305 0 : SolarMutexGuard aSolarMutexGuard;
306 0 : ::osl::MutexGuard aGuard(m_aMutex);
307 :
308 0 : uno::Reference< frame::XSubToolbarController> xSub(m_pToolbarController.getRef(),uno::UNO_QUERY);
309 0 : if ( xSub.is() )
310 : {
311 0 : xSub->functionSelected(m_aCommandURL = rCommand);
312 0 : }
313 0 : }
314 : // -----------------------------------------------------------------------------
315 0 : void SAL_CALL OToolboxController::updateImage( ) throw (uno::RuntimeException)
316 : {
317 0 : SolarMutexGuard aSolarMutexGuard;
318 0 : ::osl::MutexGuard aGuard(m_aMutex);
319 :
320 0 : uno::Reference< frame::XSubToolbarController> xSub(m_pToolbarController.getRef(),uno::UNO_QUERY);
321 0 : if ( xSub.is() )
322 0 : xSub->updateImage();
323 0 : }
324 : // -----------------------------------------------------------------------------
325 0 : uno::Reference< awt::XWindow > SAL_CALL OToolboxController::createItemWindow( const uno::Reference< awt::XWindow >& _xParent)
326 : throw (uno::RuntimeException)
327 : {
328 0 : uno::Reference< awt::XWindow > xWindow;
329 0 : if ( m_pToolbarController.is() )
330 : {
331 0 : switch(m_nSlotId)
332 : {
333 : case SID_ATTR_CHAR_FONT:
334 0 : xWindow = VCLUnoHelper::GetInterface(static_cast<SvxFontNameToolBoxControl*>(m_pToolbarController.get())->CreateItemWindow(VCLUnoHelper::GetWindow(_xParent)));
335 0 : break;
336 : default:
337 : ;
338 : }
339 : }
340 0 : return xWindow;
341 : }
342 : // -----------------------------------------------------------------------------
343 : //..........................................................................
344 0 : } // rptui
345 : //..........................................................................
346 :
347 :
348 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|