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