sync master with lastest vba changes
[ooovba.git] / reportdesign / source / ui / misc / toolboxcontroller.cxx
blob20cc4d2316b9ea5e9aabb10d99f439f62228bf97
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: toolboxcontroller.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
31 #include "toolboxcontroller.hxx"
32 #include <com/sun/star/ui/ImageType.hpp>
33 #include <com/sun/star/frame/XDispatchProvider.hpp>
34 #include <com/sun/star/beans/PropertyValue.hpp>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <vcl/menu.hxx>
37 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
38 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
39 #include <com/sun/star/ui/XImageManager.hpp>
40 #include <com/sun/star/ui/ImageType.hpp>
41 #include <com/sun/star/graphic/XGraphic.hpp>
42 #include <com/sun/star/util/Color.hpp>
43 #include <vcl/svapp.hxx>
44 #include <vcl/toolbox.hxx>
45 #include <svtools/miscopt.hxx>
46 #include <svtools/moduleoptions.hxx>
47 #include <svtools/menuoptions.hxx>
48 #include <vos/mutex.hxx>
49 #include <svx/svxids.hrc>
50 #define ITEMID_COLOR 1
51 #define ITEMID_BRUSH 2
52 #define ITEMID_FONT 3
53 #define ITEMID_FONTHEIGHT 4
54 #include <svx/fontitem.hxx>
55 #include <svx/fhgtitem.hxx>
56 #include <svx/tbcontrl.hxx>
57 #include <svx/colritem.hxx>
58 #include <svx/tbxcustomshapes.hxx>
60 #include <comphelper/sequence.hxx>
62 #include <memory>
64 namespace rptui
66 using namespace svt;
67 using namespace com::sun::star;
68 using namespace com::sun::star::uno;
69 using namespace com::sun::star::beans;
70 using namespace com::sun::star::lang;
71 using namespace frame;
72 using namespace util;
73 using namespace ui;
75 ::rtl::OUString SAL_CALL OToolboxController::getImplementationName() throw( RuntimeException )
77 return getImplementationName_Static();
80 //------------------------------------------------------------------------------
81 ::rtl::OUString OToolboxController::getImplementationName_Static() throw( RuntimeException )
83 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.comp.ReportToolboxController"));
85 //------------------------------------------------------------------------------
86 Sequence< ::rtl::OUString> OToolboxController::getSupportedServiceNames_Static(void) throw( RuntimeException )
88 Sequence< ::rtl::OUString> aSupported(1);
89 aSupported.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.ReportToolboxController"));
90 return aSupported;
92 // -----------------------------------------------------------------------------
93 ::sal_Bool SAL_CALL OToolboxController::supportsService( const ::rtl::OUString& ServiceName ) throw (uno::RuntimeException)
95 return ::comphelper::existsValue(ServiceName,getSupportedServiceNames_Static());
97 //-------------------------------------------------------------------------
98 Sequence< ::rtl::OUString> SAL_CALL OToolboxController::getSupportedServiceNames() throw(RuntimeException)
100 return getSupportedServiceNames_Static();
102 // -------------------------------------------------------------------------
103 Reference< XInterface > OToolboxController::create(Reference< XComponentContext > const & xContext)
105 return *(new OToolboxController(Reference< XMultiServiceFactory >(xContext->getServiceManager(),UNO_QUERY)));
107 // -----------------------------------------------------------------------------
108 DBG_NAME(rpt_OToolboxController)
109 OToolboxController::OToolboxController(const Reference< XMultiServiceFactory >& _rxORB)
110 : m_pToolbarController(NULL)
111 ,m_nToolBoxId(1)
112 ,m_nSlotId(0)
114 DBG_CTOR(rpt_OToolboxController,NULL);
115 osl_incrementInterlockedCount(&m_refCount);
116 m_xServiceManager = _rxORB;
117 osl_decrementInterlockedCount(&m_refCount);
120 // -----------------------------------------------------------------------------
121 OToolboxController::~OToolboxController()
123 DBG_DTOR(rpt_OToolboxController,NULL);
125 // -----------------------------------------------------------------------------
126 // XInterface
127 Any SAL_CALL OToolboxController::queryInterface( const Type& _rType ) throw (RuntimeException)
129 Any aReturn = ToolboxController::queryInterface(_rType);
130 if (!aReturn.hasValue())
131 aReturn = TToolboxController_BASE::queryInterface(_rType);
132 return aReturn;
134 // -----------------------------------------------------------------------------
135 void SAL_CALL OToolboxController::acquire() throw ()
137 ToolboxController::acquire();
139 // -----------------------------------------------------------------------------
140 void SAL_CALL OToolboxController::release() throw ()
142 ToolboxController::release();
144 // -----------------------------------------------------------------------------
145 void SAL_CALL OToolboxController::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
147 ToolboxController::initialize(_rArguments);
148 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
149 ::osl::MutexGuard aGuard(m_aMutex);
151 ToolBox* pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
152 if ( pToolBox )
154 const USHORT nCount = pToolBox->GetItemCount();
155 for (USHORT nPos = 0; nPos < nCount; ++nPos)
157 const USHORT nItemId = pToolBox->GetItemId(nPos);
158 if ( pToolBox->GetItemCommand(nItemId) == String(m_aCommandURL) )
160 m_nToolBoxId = nItemId;
161 break;
164 if ( m_aCommandURL.equalsAscii(".uno:BasicShapes") )
166 m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:BasicShapes")),sal_True));
167 m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_BASIC,m_nToolBoxId,*pToolBox));
169 else if ( m_aCommandURL.equalsAscii(".uno:SymbolShapes") )
171 m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:SymbolShapes")),sal_True));
172 m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_SYMBOL,m_nToolBoxId,*pToolBox));
174 else if ( m_aCommandURL.equalsAscii(".uno:ArrowShapes") )
176 m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:ArrowShapes")),sal_True));
177 m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_ARROW,m_nToolBoxId,*pToolBox));
179 else if ( m_aCommandURL.equalsAscii(".uno:FlowChartShapes") )
181 m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FlowChartShapes")),sal_True));
182 m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_FLOWCHART,m_nToolBoxId,*pToolBox));
184 else if ( m_aCommandURL.equalsAscii(".uno:CalloutShapes") )
186 m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:CalloutShapes")),sal_True));
187 m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_CALLOUT,m_nToolBoxId,*pToolBox));
189 else if ( m_aCommandURL.equalsAscii(".uno:StarShapes") )
191 m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:StarShapes")),sal_True));
192 m_pToolbarController = TToolbarHelper::createFromQuery(new SvxTbxCtlCustomShapes(m_nSlotId = SID_DRAWTBX_CS_STAR,m_nToolBoxId,*pToolBox));
194 else if ( m_aCommandURL.equalsAscii(".uno:CharFontName") )
196 m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:CharFontName")),sal_True));
197 m_pToolbarController = TToolbarHelper::createFromQuery(new SvxFontNameToolBoxControl/*SvxStyleToolBoxControl*/(m_nSlotId = SID_ATTR_CHAR_FONT,m_nToolBoxId,*pToolBox));
199 else if ( m_aCommandURL.equalsAscii(".uno:FontColor") || m_aCommandURL.equalsAscii(".uno:Color") )
201 m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FontColor")),sal_True));
202 m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Color")),sal_True));
203 m_pToolbarController = TToolbarHelper::createFromQuery(new SvxFontColorExtToolBoxControl/*SvxFontColorToolBoxControl*/(m_nSlotId = SID_ATTR_CHAR_COLOR2,m_nToolBoxId,*pToolBox));
205 else
207 m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:BackgroundColor")),sal_True));
208 m_pToolbarController = TToolbarHelper::createFromQuery(new SvxColorToolBoxControl(m_nSlotId = SID_BACKGROUND_COLOR,m_nToolBoxId,*pToolBox));
211 TCommandState::iterator aIter = m_aStates.begin();
212 for (; aIter != m_aStates.end(); ++aIter)
213 addStatusListener(aIter->first);
215 if ( m_pToolbarController.is() )
216 m_pToolbarController->initialize(_rArguments);
217 // check if paste special is allowed, when not don't add DROPDOWN
218 pToolBox->SetItemBits(m_nToolBoxId,pToolBox->GetItemBits(m_nToolBoxId) | TIB_DROPDOWN);
221 // -----------------------------------------------------------------------------
222 void SAL_CALL OToolboxController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
224 ::osl::MutexGuard aGuard(m_aMutex);
225 TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
226 if ( aFind != m_aStates.end() )
228 aFind->second = Event.IsEnabled;
229 if ( m_pToolbarController.is() )
231 // All other status events will be processed here
232 sal_Bool bSetCheckmark = sal_False;
233 sal_Bool bCheckmark = sal_False;
234 //m_pToolbarController->GetToolBox().Enable(Event.IsEnabled);
235 ToolBox& rTb = m_pToolbarController->GetToolBox();
236 for ( USHORT i = 0; i < rTb.GetItemCount(); i++ )
238 USHORT nId = rTb.GetItemId( i );
239 if ( nId == 0 )
240 continue;
242 rtl::OUString aCmd = rTb.GetItemCommand( nId );
243 if ( aCmd == Event.FeatureURL.Complete )
245 // Enable/disable item
246 rTb.EnableItem( nId, Event.IsEnabled );
248 // Checkmark
249 if ( Event.State >>= bCheckmark )
250 bSetCheckmark = sal_True;
252 if ( bSetCheckmark )
253 rTb.CheckItem( nId, bCheckmark );
254 else
256 rtl::OUString aItemText;
258 if ( Event.State >>= aItemText )
259 rTb.SetItemText( nId, aItemText );
264 switch(m_nSlotId)
266 case SID_ATTR_CHAR_COLOR2:
267 case SID_BACKGROUND_COLOR:
269 util::Color nColor(COL_TRANSPARENT);
270 Event.State >>= nColor;
271 ::Color aGcc3WorkaroundTemporary( nColor);
272 SvxColorItem aColorItem(aGcc3WorkaroundTemporary,1);
273 if ( SID_ATTR_CHAR_COLOR2 == m_nSlotId )
274 static_cast<SvxFontColorExtToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SFX_ITEM_SET : SFX_ITEM_DISABLED,&aColorItem);
275 else
276 static_cast<SvxColorToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SFX_ITEM_SET : SFX_ITEM_DISABLED,&aColorItem);
278 break;
279 case SID_ATTR_CHAR_FONT:
281 SvxFontItem aItem(ITEMID_FONT);
282 aItem.PutValue(Event.State);
283 static_cast<SvxFontNameToolBoxControl*>(m_pToolbarController.get())->StateChanged(m_nSlotId,Event.IsEnabled ? SFX_ITEM_AVAILABLE : SFX_ITEM_DISABLED,&aItem);
285 break;
290 // -----------------------------------------------------------------------------
291 Reference< awt::XWindow > SAL_CALL OToolboxController::createPopupWindow() throw (RuntimeException)
293 // execute the menu
294 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
295 ::osl::MutexGuard aGuard(m_aMutex);
297 Reference< awt::XWindow > xRet;
298 if ( m_pToolbarController.is() )
299 xRet = m_pToolbarController.getRef()->createPopupWindow();
301 return xRet;
303 // -----------------------------------------------------------------------------
304 ::sal_Bool SAL_CALL OToolboxController::opensSubToolbar() throw (uno::RuntimeException)
306 return m_nSlotId == SID_DRAWTBX_CS_BASIC;
308 // -----------------------------------------------------------------------------
309 ::rtl::OUString SAL_CALL OToolboxController::getSubToolbarName() throw (uno::RuntimeException)
311 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
312 ::osl::MutexGuard aGuard(m_aMutex);
313 uno::Reference< frame::XSubToolbarController> xSub(m_pToolbarController.getRef(),uno::UNO_QUERY);
314 if ( xSub.is() )
315 return xSub->getSubToolbarName();
316 return ::rtl::OUString();
318 // -----------------------------------------------------------------------------
319 void SAL_CALL OToolboxController::functionSelected( const ::rtl::OUString& rCommand ) throw (uno::RuntimeException)
321 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
322 ::osl::MutexGuard aGuard(m_aMutex);
324 uno::Reference< frame::XSubToolbarController> xSub(m_pToolbarController.getRef(),uno::UNO_QUERY);
325 if ( xSub.is() )
327 xSub->functionSelected(m_aCommandURL = rCommand);
330 // -----------------------------------------------------------------------------
331 void SAL_CALL OToolboxController::updateImage( ) throw (uno::RuntimeException)
333 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
334 ::osl::MutexGuard aGuard(m_aMutex);
336 uno::Reference< frame::XSubToolbarController> xSub(m_pToolbarController.getRef(),uno::UNO_QUERY);
337 if ( xSub.is() )
338 xSub->updateImage();
340 // -----------------------------------------------------------------------------
341 uno::Reference< awt::XWindow > SAL_CALL OToolboxController::createItemWindow( const uno::Reference< awt::XWindow >& _xParent)
342 throw (uno::RuntimeException)
344 uno::Reference< awt::XWindow > xWindow;
345 if ( m_pToolbarController.is() )
347 switch(m_nSlotId)
349 case SID_ATTR_CHAR_FONT:
350 xWindow = VCLUnoHelper::GetInterface(static_cast<SvxFontNameToolBoxControl*>(m_pToolbarController.get())->CreateItemWindow(VCLUnoHelper::GetWindow(_xParent)));
351 break;
352 default:
356 return xWindow;
358 // -----------------------------------------------------------------------------
359 //..........................................................................
360 } // rptui
361 //..........................................................................