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