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