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 : :
29 : : #include <uifactory/addonstoolboxfactory.hxx>
30 : :
31 : : #include <uielement/addonstoolbarwrapper.hxx>
32 : : #include <threadhelp/resetableguard.hxx>
33 : :
34 : : #include <com/sun/star/util/XURLTransformer.hpp>
35 : : #include <com/sun/star/frame/XFrame.hpp>
36 : : #include <com/sun/star/frame/XModel.hpp>
37 : : #include <com/sun/star/lang/XInitialization.hpp>
38 : : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
39 : :
40 : : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
41 : :
42 : : #include <vcl/svapp.hxx>
43 : : #include <rtl/ustrbuf.hxx>
44 : :
45 : : //_________________________________________________________________________________________________________________
46 : : // Defines
47 : : //_________________________________________________________________________________________________________________
48 : :
49 : : using namespace com::sun::star::uno;
50 : : using namespace com::sun::star::lang;
51 : : using namespace com::sun::star::frame;
52 : : using namespace com::sun::star::beans;
53 : : using namespace com::sun::star::util;
54 : : using namespace ::com::sun::star::ui;
55 : :
56 : : namespace framework
57 : : {
58 : :
59 : : //*****************************************************************************************************************
60 : : // XInterface, XTypeProvider, XServiceInfo
61 : : //*****************************************************************************************************************
62 [ # # ][ # # ]: 1274 : DEFINE_XSERVICEINFO_ONEINSTANCESERVICE ( AddonsToolBoxFactory ,
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
63 : : ::cppu::OWeakObject ,
64 : : SERVICENAME_TOOLBARFACTORY ,
65 : : IMPLEMENTATIONNAME_ADDONSTOOLBARFACTORY
66 : : )
67 : :
68 : 0 : DEFINE_INIT_SERVICE ( AddonsToolBoxFactory, {} )
69 : :
70 : 0 : AddonsToolBoxFactory::AddonsToolBoxFactory(
71 : : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
72 : 0 : ThreadHelpBase( &Application::GetSolarMutex() )
73 : : , m_xServiceManager( xServiceManager )
74 [ # # ][ # # ]: 0 : , m_xModuleManager( xServiceManager->createInstance(SERVICENAME_MODULEMANAGER),UNO_QUERY )
[ # # ][ # # ]
[ # # ]
75 : : {
76 : 0 : }
77 : :
78 [ # # ]: 0 : AddonsToolBoxFactory::~AddonsToolBoxFactory()
79 : : {
80 [ # # ]: 0 : }
81 : :
82 : 0 : static sal_Bool IsCorrectContext( const ::rtl::OUString& rModuleIdentifier, const rtl::OUString& aContextList )
83 : : {
84 [ # # ]: 0 : if ( aContextList.isEmpty() )
85 : 0 : return sal_True;
86 : :
87 [ # # ]: 0 : if ( !rModuleIdentifier.isEmpty() )
88 : : {
89 : 0 : sal_Int32 nIndex = aContextList.indexOf( rModuleIdentifier );
90 : 0 : return ( nIndex >= 0 );
91 : : }
92 : :
93 : 0 : return sal_False;
94 : : }
95 : :
96 : 0 : sal_Bool AddonsToolBoxFactory::hasButtonsInContext(
97 : : const Sequence< Sequence< PropertyValue > >& rPropSeqSeq,
98 : : const Reference< XFrame >& rFrame )
99 : : {
100 : 0 : ::rtl::OUString aModuleIdentifier;
101 : : try
102 : : {
103 [ # # ][ # # ]: 0 : aModuleIdentifier = m_xModuleManager->identify( rFrame );
104 : : }
105 [ # # # ]: 0 : catch ( const RuntimeException& )
106 : : {
107 : 0 : throw;
108 : : }
109 [ # # ]: 0 : catch ( const Exception& )
110 : : {
111 : : }
112 : :
113 : : // Check before we create a toolbar that we have at least one button in
114 : : // the current frame context.
115 [ # # ]: 0 : for ( sal_uInt32 i = 0; i < (sal_uInt32)rPropSeqSeq.getLength(); i++ )
116 : : {
117 : 0 : sal_Bool bIsButton( sal_True );
118 : 0 : sal_Bool bIsCorrectContext( sal_False );
119 : 0 : sal_uInt32 nPropChecked( 0 );
120 : :
121 : 0 : const Sequence< PropertyValue >& rPropSeq = rPropSeqSeq[i];
122 [ # # ]: 0 : for ( sal_uInt32 j = 0; j < (sal_uInt32)rPropSeq.getLength(); j++ )
123 : : {
124 [ # # ]: 0 : if ( rPropSeq[j].Name.equalsAsciiL( "Context", 7 ))
125 : : {
126 : 0 : ::rtl::OUString aContextList;
127 [ # # ]: 0 : if ( rPropSeq[j].Value >>= aContextList )
128 : 0 : bIsCorrectContext = IsCorrectContext( aModuleIdentifier, aContextList );
129 : 0 : nPropChecked++;
130 : : }
131 [ # # ]: 0 : else if ( rPropSeq[j].Name.equalsAsciiL( "URL", 3 ))
132 : : {
133 : 0 : ::rtl::OUString aURL;
134 : 0 : rPropSeq[j].Value >>= aURL;
135 : 0 : bIsButton = !aURL.equalsAsciiL( "private:separator", 17 );
136 : 0 : nPropChecked++;
137 : : }
138 : :
139 [ # # ]: 0 : if ( nPropChecked == 2 )
140 : 0 : break;
141 : : }
142 : :
143 [ # # ][ # # ]: 0 : if ( bIsButton && bIsCorrectContext )
144 : 0 : return sal_True;
145 : : }
146 : :
147 : 0 : return sal_False;
148 : : }
149 : :
150 : : // XUIElementFactory
151 : 0 : Reference< XUIElement > SAL_CALL AddonsToolBoxFactory::createUIElement(
152 : : const ::rtl::OUString& ResourceURL,
153 : : const Sequence< PropertyValue >& Args )
154 : : throw ( ::com::sun::star::container::NoSuchElementException,
155 : : ::com::sun::star::lang::IllegalArgumentException,
156 : : ::com::sun::star::uno::RuntimeException )
157 : : {
158 : : // SAFE
159 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
160 : :
161 [ # # ]: 0 : Sequence< Sequence< PropertyValue > > aConfigData;
162 : 0 : Reference< XFrame > xFrame;
163 : 0 : rtl::OUString aResourceURL( ResourceURL );
164 : :
165 [ # # ]: 0 : for ( sal_Int32 n = 0; n < Args.getLength(); n++ )
166 : : {
167 [ # # ]: 0 : if ( Args[n].Name == "ConfigurationData" )
168 [ # # ]: 0 : Args[n].Value >>= aConfigData;
169 [ # # ]: 0 : else if ( Args[n].Name == "Frame" )
170 [ # # ]: 0 : Args[n].Value >>= xFrame;
171 [ # # ]: 0 : else if ( Args[n].Name == "ResourceURL" )
172 : 0 : Args[n].Value >>= aResourceURL;
173 : : }
174 : :
175 [ # # ]: 0 : if ( aResourceURL.indexOf( "private:resource/toolbar/addon_" ) != 0 )
176 [ # # ]: 0 : throw IllegalArgumentException();
177 : :
178 : : // Identify frame and determine module identifier to look for context based buttons
179 : 0 : Reference< ::com::sun::star::ui::XUIElement > xToolBar;
180 [ # # ][ # # ]: 0 : if ( xFrame.is() &&
[ # # # # ]
181 : 0 : ( aConfigData.getLength()> 0 ) &&
182 [ # # ]: 0 : hasButtonsInContext( aConfigData, xFrame ))
183 : : {
184 : 0 : PropertyValue aPropValue;
185 [ # # ]: 0 : Sequence< Any > aPropSeq( 3 );
186 [ # # ]: 0 : aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
187 [ # # ]: 0 : aPropValue.Value <<= xFrame;
188 [ # # ][ # # ]: 0 : aPropSeq[0] <<= aPropValue;
189 [ # # ]: 0 : aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationData" ));
190 [ # # ]: 0 : aPropValue.Value <<= aConfigData;
191 [ # # ][ # # ]: 0 : aPropSeq[1] <<= aPropValue;
192 [ # # ]: 0 : aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ));
193 [ # # ]: 0 : aPropValue.Value <<= aResourceURL;
194 [ # # ][ # # ]: 0 : aPropSeq[2] <<= aPropValue;
195 : :
196 [ # # ]: 0 : SolarMutexGuard aGuard;
197 [ # # ]: 0 : AddonsToolBarWrapper* pToolBarWrapper = new AddonsToolBarWrapper( m_xServiceManager );
198 [ # # ][ # # ]: 0 : xToolBar = Reference< ::com::sun::star::ui::XUIElement >( (OWeakObject *)pToolBarWrapper, UNO_QUERY );
[ # # ]
199 [ # # ]: 0 : Reference< XInitialization > xInit( xToolBar, UNO_QUERY );
200 [ # # ][ # # ]: 0 : xInit->initialize( aPropSeq );
[ # # ][ # # ]
201 : : }
202 : :
203 [ # # ][ # # ]: 0 : return xToolBar;
204 : : }
205 : :
206 : : }
207 : :
208 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|