MyProtocolHandler.cxx (cdf0e10c) MyProtocolHandler.cxx (cb2654af)
1/*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *

--- 11 unchanged lines hidden (view full) ---

20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27
1/*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *

--- 11 unchanged lines hidden (view full) ---

20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27
28
29#include "ListenerHelper.h"
30#include "MyProtocolHandler.h"
28#include "ListenerHelper.h"
29#include "MyProtocolHandler.h"
31#include <com/sun/star/beans/PropertyValue.hpp>
32#include <com/sun/star/frame/XFrame.hpp>
33#include <com/sun/star/frame/XController.hpp>
34#include <com/sun/star/frame/DispatchDescriptor.hpp>
30
31#include <com/sun/star/awt/MessageBoxButtons.hpp>
32#include <com/sun/star/awt/XMessageBoxFactory.hpp>
33#include <com/sun/star/frame/ControlCommand.hpp>
35#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
34#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
36#include <com/sun/star/text/XTextViewCursor.hpp>
37#include <com/sun/star/text/XTextCursor.hpp>
38#include <com/sun/star/text/XTextDocument.hpp>
39#include <com/sun/star/sheet/XSpreadsheetView.hpp>
35#include <com/sun/star/sheet/XSpreadsheetView.hpp>
40#include <com/sun/star/frame/ControlCommand.hpp>
41#include <com/sun/star/frame/ControlEvent.hpp>
42#include <com/sun/star/frame/XModel.hpp>
43#include <com/sun/star/frame/XControlNotificationListener.hpp>
44#include <com/sun/star/beans/PropertyValue.hpp>
45#include <com/sun/star/awt/XWindowPeer.hpp>
46#include <com/sun/star/awt/WindowAttribute.hpp>
47#include <com/sun/star/awt/XMessageBox.hpp>
48#include <com/sun/star/frame/XComponentLoader.hpp>
49#include <com/sun/star/view/XSelectionSupplier.hpp>
50#include <com/sun/star/system/XSystemShellExecute.hpp>
51#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
36#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
52#include <com/sun/star/frame/XStorable.hpp>
53#include <com/sun/star/container/XContainerQuery.hpp>
37#include <com/sun/star/system/XSystemShellExecute.hpp>
54
38
55#include <osl/file.hxx>
56
39
57using namespace com::sun::star::uno;
40using namespace com::sun::star::awt;
58using namespace com::sun::star::frame;
41using namespace com::sun::star::frame;
59using com::sun::star::lang::XMultiServiceFactory;
42using namespace com::sun::star::system;
43using namespace com::sun::star::uno;
44
45using com::sun::star::beans::NamedValue;
60using com::sun::star::beans::PropertyValue;
46using com::sun::star::beans::PropertyValue;
61using com::sun::star::util::URL;
62using com::sun::star::text::XTextViewCursorSupplier;
63using com::sun::star::text::XTextViewCursor;
64using com::sun::star::text::XTextCursor;
47using com::sun::star::lang::XMultiServiceFactory;
65using com::sun::star::sheet::XSpreadsheetView;
48using com::sun::star::sheet::XSpreadsheetView;
66using com::sun::star::frame::XModel;
67using com::sun::star::text::XTextRange;
68using com::sun::star::text::XTextDocument;
69using com::sun::star::beans::NamedValue;
70using namespace com::sun::star::awt;
71using com::sun::star::view::XSelectionSupplier;
72using namespace com::sun::star::system;
49using com::sun::star::text::XTextViewCursorSupplier;
50using com::sun::star::util::URL;
73
74ListenerHelper aListenerHelper;
75
76void BaseDispatch::ShowMessageBox( const Reference< XFrame >& rFrame, const ::rtl::OUString& aTitle, const ::rtl::OUString& aMsgText )
77{
78 if ( !mxToolkit.is() )
79 mxToolkit = Reference< XToolkit > ( mxMSF->createInstance(
51
52ListenerHelper aListenerHelper;
53
54void BaseDispatch::ShowMessageBox( const Reference< XFrame >& rFrame, const ::rtl::OUString& aTitle, const ::rtl::OUString& aMsgText )
55{
56 if ( !mxToolkit.is() )
57 mxToolkit = Reference< XToolkit > ( mxMSF->createInstance(
80 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
81 "com.sun.star.awt.Toolkit" ))), UNO_QUERY );
82 if ( rFrame.is() && mxToolkit.is() )
58 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" ))), UNO_QUERY );
59
60 Reference< XMessageBoxFactory > xMsgBoxFactory( mxToolkit, UNO_QUERY );
61 if ( rFrame.is() && xMsgBoxFactory.is() )
83 {
62 {
84 // describe window properties.
85 WindowDescriptor aDescriptor;
86 aDescriptor.Type = WindowClass_MODALTOP;
87 aDescriptor.WindowServiceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "infobox" ));
88 aDescriptor.ParentIndex = -1;
89 aDescriptor.Parent = Reference< XWindowPeer >( rFrame->getContainerWindow(), UNO_QUERY );
90 aDescriptor.Bounds = Rectangle(0,0,300,200);
91 aDescriptor.WindowAttributes = WindowAttribute::BORDER | WindowAttribute::MOVEABLE | WindowAttribute::CLOSEABLE;
63 Reference< XMessageBox > xMsgBox = xMsgBoxFactory->createMessageBox(
64 Reference< XWindowPeer >( rFrame->getContainerWindow(), UNO_QUERY ),
65 Rectangle(0,0,300,200),
66 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "infobox" ) ),
67 MessageBoxButtons::BUTTONS_OK,
68 aTitle,
69 aMsgText );
92
70
93 Reference< XWindowPeer > xPeer = mxToolkit->createWindow( aDescriptor );
94 if ( xPeer.is() )
95 {
96 Reference< XMessageBox > xMsgBox( xPeer, UNO_QUERY );
97 if ( xMsgBox.is() )
98 {
99 xMsgBox->setCaptionText( aTitle );
100 xMsgBox->setMessageText( aMsgText );
101 xMsgBox->execute();
102 }
103 }
71 if ( xMsgBox.is() )
72 xMsgBox->execute();
104 }
105}
106
107void BaseDispatch::SendCommand( const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const Sequence< NamedValue >& rArgs, sal_Bool bEnabled )
108{
109 Reference < XDispatch > xDispatch =
110 aListenerHelper.GetDispatch( mxFrame, aURL.Path );
111

--- 44 unchanged lines hidden (view full) ---

156Reference< XDispatch > SAL_CALL MyProtocolHandler::queryDispatch( const URL& aURL, const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags )
157 throw( RuntimeException )
158{
159 Reference < XDispatch > xRet;
160 if ( !mxFrame.is() )
161 return 0;
162
163 Reference < XController > xCtrl = mxFrame->getController();
73 }
74}
75
76void BaseDispatch::SendCommand( const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const Sequence< NamedValue >& rArgs, sal_Bool bEnabled )
77{
78 Reference < XDispatch > xDispatch =
79 aListenerHelper.GetDispatch( mxFrame, aURL.Path );
80

--- 44 unchanged lines hidden (view full) ---

125Reference< XDispatch > SAL_CALL MyProtocolHandler::queryDispatch( const URL& aURL, const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags )
126 throw( RuntimeException )
127{
128 Reference < XDispatch > xRet;
129 if ( !mxFrame.is() )
130 return 0;
131
132 Reference < XController > xCtrl = mxFrame->getController();
164 if ( xCtrl.is() && !aURL.Protocol.compareToAscii("vnd.demo.complextoolbarcontrols.demoaddon:") )
133 if ( xCtrl.is() && !aURL.Protocol.compareToAscii(
134 RTL_CONSTASCII_STRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) ) )
165 {
166 Reference < XTextViewCursorSupplier > xCursor( xCtrl, UNO_QUERY );
167 Reference < XSpreadsheetView > xView( xCtrl, UNO_QUERY );
168 if ( !xCursor.is() && !xView.is() )
169 // ohne ein entsprechendes Dokument funktioniert der Handler nicht
170 return xRet;
171
135 {
136 Reference < XTextViewCursorSupplier > xCursor( xCtrl, UNO_QUERY );
137 Reference < XSpreadsheetView > xView( xCtrl, UNO_QUERY );
138 if ( !xCursor.is() && !xView.is() )
139 // ohne ein entsprechendes Dokument funktioniert der Handler nicht
140 return xRet;
141
172 if ( aURL.Path.equalsAscii("Command1" ) ||
173 aURL.Path.equalsAscii("Command2" ) ||
174 aURL.Path.equalsAscii("Command3" ) ||
175 aURL.Path.equalsAscii("Command4" ) ||
176 aURL.Path.equalsAscii("Command5" ) ||
177 aURL.Path.equalsAscii("Command6" ) ||
178 aURL.Path.equalsAscii("Command7" ) )
142 if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ImageButtonCmd" ) ) ||
143 aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ComboboxCmd" ) ) ||
144 aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ToggleDropdownButtonCmd" ) ) ||
145 aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DropdownButtonCmd" ) ) ||
146 aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "SpinfieldCmd" ) ) ||
147 aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EditfieldCmd" ) ) ||
148 aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DropdownboxCmd" ) ) )
179 {
180 xRet = aListenerHelper.GetDispatch( mxFrame, aURL.Path );
181 if ( !xRet.is() )
182 {
183 xRet = xCursor.is() ? (BaseDispatch*) new WriterDispatch( mxMSF, mxFrame ) :
184 (BaseDispatch*) new CalcDispatch( mxMSF, mxFrame );
185 aListenerHelper.AddDispatch( xRet, mxFrame, aURL.Path );
186 }

--- 13 unchanged lines hidden (view full) ---

200 lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags );
201
202 return lDispatcher;
203}
204
205::rtl::OUString MyProtocolHandler_getImplementationName ()
206 throw (RuntimeException)
207{
149 {
150 xRet = aListenerHelper.GetDispatch( mxFrame, aURL.Path );
151 if ( !xRet.is() )
152 {
153 xRet = xCursor.is() ? (BaseDispatch*) new WriterDispatch( mxMSF, mxFrame ) :
154 (BaseDispatch*) new CalcDispatch( mxMSF, mxFrame );
155 aListenerHelper.AddDispatch( xRet, mxFrame, aURL.Path );
156 }

--- 13 unchanged lines hidden (view full) ---

170 lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags );
171
172 return lDispatcher;
173}
174
175::rtl::OUString MyProtocolHandler_getImplementationName ()
176 throw (RuntimeException)
177{
208 return ::rtl::OUString::createFromAscii(MYPROTOCOLHANDLER_IMPLEMENTATIONNAME);
178 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MYPROTOCOLHANDLER_IMPLEMENTATIONNAME ) );
209}
210
211sal_Bool SAL_CALL MyProtocolHandler_supportsService( const ::rtl::OUString& ServiceName )
212 throw (RuntimeException)
213{
214 return (
179}
180
181sal_Bool SAL_CALL MyProtocolHandler_supportsService( const ::rtl::OUString& ServiceName )
182 throw (RuntimeException)
183{
184 return (
215 ServiceName.equalsAscii(MYPROTOCOLHANDLER_SERVICENAME ) ||
216 ServiceName.equalsAscii("com.sun.star.frame.ProtocolHandler")
185 ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MYPROTOCOLHANDLER_SERVICENAME ) ) ||
186 ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.frame.ProtocolHandler" ) )
217 );
218}
219
220Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler_getSupportedServiceNames( )
221 throw (RuntimeException)
222{
223 Sequence < ::rtl::OUString > aRet(1);
187 );
188}
189
190Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler_getSupportedServiceNames( )
191 throw (RuntimeException)
192{
193 Sequence < ::rtl::OUString > aRet(1);
224 aRet[0] = ::rtl::OUString::createFromAscii(MYPROTOCOLHANDLER_SERVICENAME);
194 aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MYPROTOCOLHANDLER_SERVICENAME ) );
225 return aRet;
226}
227
228#undef SERVICE_NAME
229
230Reference< XInterface > SAL_CALL MyProtocolHandler_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
231 throw( Exception )
232{

--- 25 unchanged lines hidden (view full) ---

258 May the outside dispatch cache (implemented by the menu/toolbar!)
259 forget this instance during de-/activation of frames (focus!).
260
261 E.g. An open db beamer in combination with the My-Dialog
262 can force such strange situation :-(
263 */
264 Reference< XInterface > xSelfHold(static_cast< XDispatch* >(this), UNO_QUERY);
265
195 return aRet;
196}
197
198#undef SERVICE_NAME
199
200Reference< XInterface > SAL_CALL MyProtocolHandler_createInstance( const Reference< XMultiServiceFactory > & rSMgr)
201 throw( Exception )
202{

--- 25 unchanged lines hidden (view full) ---

228 May the outside dispatch cache (implemented by the menu/toolbar!)
229 forget this instance during de-/activation of frames (focus!).
230
231 E.g. An open db beamer in combination with the My-Dialog
232 can force such strange situation :-(
233 */
234 Reference< XInterface > xSelfHold(static_cast< XDispatch* >(this), UNO_QUERY);
235
266 if ( !aURL.Protocol.compareToAscii("vnd.demo.complextoolbarcontrols.demoaddon:") )
236 if ( !aURL.Protocol.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) ) )
267 {
237 {
268 if ( !aURL.Path.compareToAscii("Command1" ) )
238 if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ImageButtonCmd" ) ) )
269 {
270 // open the OpenOffice.org web page
239 {
240 // open the OpenOffice.org web page
271 ::rtl::OUString sURL(::rtl::OUString::createFromAscii("http://www.openoffice.org"));
241 ::rtl::OUString sURL( RTL_CONSTASCII_USTRINGPARAM( "http://www.openoffice.org" ) );
272 Reference< XSystemShellExecute > xSystemShellExecute( mxMSF->createInstance(
242 Reference< XSystemShellExecute > xSystemShellExecute( mxMSF->createInstance(
273 ::rtl::OUString::createFromAscii( "com.sun.star.system.SystemShellExecute" )), UNO_QUERY );
243 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.system.SystemShellExecute" ) ) ), UNO_QUERY );
274 if ( xSystemShellExecute.is() )
244 if ( xSystemShellExecute.is() )
275 {
245 {
276 try
246 try
277
278 {
279 xSystemShellExecute->execute( sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
247 {
248 xSystemShellExecute->execute( sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
280 }
249 }
281 catch( Exception& rEx )
282 {
283 (void)rEx;
284 }
285 }
286 }
250 catch( Exception& rEx )
251 {
252 (void)rEx;
253 }
254 }
255 }
287 else if ( !aURL.Path.compareToAscii("Command2" ) )
256 else if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ComboboxCmd" ) ) )
288 {
289 // remove the text if it's in our list
290 Sequence< NamedValue > aRemoveArgs( 1 );
291 aRemoveArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
292 aRemoveArgs[0].Value <<= maComboBoxText;
257 {
258 // remove the text if it's in our list
259 Sequence< NamedValue > aRemoveArgs( 1 );
260 aRemoveArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
261 aRemoveArgs[0].Value <<= maComboBoxText;
293 SendCommand( aURL, ::rtl::OUString::createFromAscii( "RemoveEntryText" ), aRemoveArgs, sal_True );
262 SendCommand( aURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RemoveEntryText" ) ), aRemoveArgs, sal_True );
294
295 // add the new text to the start of the list
296 Sequence< NamedValue > aInsertArgs( 2 );
297 aInsertArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" ));
298 aInsertArgs[0].Value <<= sal_Int32( 0 );
299 aInsertArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
300 aInsertArgs[1].Value <<= maComboBoxText;
263
264 // add the new text to the start of the list
265 Sequence< NamedValue > aInsertArgs( 2 );
266 aInsertArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" ));
267 aInsertArgs[0].Value <<= sal_Int32( 0 );
268 aInsertArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
269 aInsertArgs[1].Value <<= maComboBoxText;
301 SendCommand( aURL, ::rtl::OUString::createFromAscii( "InsertEntry" ), aInsertArgs, sal_True );
270 SendCommand( aURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InsertEntry" ) ), aInsertArgs, sal_True );
302 }
271 }
303 else if ( !aURL.Path.compareToAscii("Command3" ) )
272 else if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ToggleDropdownButtonCmd" ) ) )
304 {
305 // Retrieve the text argument from the sequence property value
306 rtl::OUString aText;
307 for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ )
308 {
273 {
274 // Retrieve the text argument from the sequence property value
275 rtl::OUString aText;
276 for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ )
277 {
309 if ( lArgs[i].Name.equalsAsciiL( "Text", 4 ))
278 if ( lArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Text" ) ) )
310 {
311 lArgs[i].Value >>= aText;
312 break;
313 }
314 }
315
316 // create new URL to address the combox box
317 URL aCmdURL;
279 {
280 lArgs[i].Value >>= aText;
281 break;
282 }
283 }
284
285 // create new URL to address the combox box
286 URL aCmdURL;
318 aCmdURL.Path = rtl::OUString::createFromAscii( "Command2" );
319 aCmdURL.Protocol = rtl::OUString::createFromAscii( "vnd.demo.complextoolbarcontrols.demoaddon:" );
287 aCmdURL.Path = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ComboboxCmd" ) );
288 aCmdURL.Protocol = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) );
320 aCmdURL.Complete = aCmdURL.Path + aCmdURL.Protocol;
289 aCmdURL.Complete = aCmdURL.Path + aCmdURL.Protocol;
321
290
322 // set the selected item as text into the combobox
323 Sequence< NamedValue > aArgs( 1 );
291 // set the selected item as text into the combobox
292 Sequence< NamedValue > aArgs( 1 );
324 aArgs[0].Name = rtl::OUString::createFromAscii( "Text" );
293 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) );
325 aArgs[0].Value <<= aText;
294 aArgs[0].Value <<= aText;
326 SendCommand( aCmdURL, ::rtl::OUString::createFromAscii( "SetText" ), aArgs, sal_True );
295 SendCommand( aCmdURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SetText" ) ), aArgs, sal_True );
327 }
296 }
328 else if ( !aURL.Path.compareToAscii("Command4" ) )
297 else if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "DropdownButtonCmd" ) ) )
329 {
330 // Retrieve the text argument from the sequence property value
331 rtl::OUString aText;
332 for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ )
333 {
298 {
299 // Retrieve the text argument from the sequence property value
300 rtl::OUString aText;
301 for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ )
302 {
334 if ( lArgs[i].Name.equalsAsciiL( "Text", 4 ))
303 if ( lArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Text" ) ) )
335 {
336 lArgs[i].Value >>= aText;
337 break;
338 }
339 }
340
341 // just enable this command
342
343 // set enable flag according to selection
304 {
305 lArgs[i].Value >>= aText;
306 break;
307 }
308 }
309
310 // just enable this command
311
312 // set enable flag according to selection
344 if ( aText.equalsAscii( "Button Disabled" ))
313 if ( aText.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Button Disabled" ) ))
345 mbButtonEnabled = sal_False;
346 else
347 mbButtonEnabled = sal_True;
348
349 // create new URL to address the image button
350 URL aCmdURL;
314 mbButtonEnabled = sal_False;
315 else
316 mbButtonEnabled = sal_True;
317
318 // create new URL to address the image button
319 URL aCmdURL;
351 aCmdURL.Path = rtl::OUString::createFromAscii( "Command1" );
352 aCmdURL.Protocol = rtl::OUString::createFromAscii( "vnd.demo.complextoolbarcontrols.demoaddon:" );
320 aCmdURL.Path = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ImageButtonCmd" ) );
321 aCmdURL.Protocol = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) );
353 aCmdURL.Complete = aCmdURL.Path + aCmdURL.Protocol;
322 aCmdURL.Complete = aCmdURL.Path + aCmdURL.Protocol;
354
323
355 // create and initialize FeatureStateEvent with IsEnabled
356 ::com::sun::star::frame::FeatureStateEvent aEvent;
357 aEvent.FeatureURL = aCmdURL;
358 aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
359 aEvent.IsEnabled = mbButtonEnabled;
360 aEvent.Requery = sal_False;
361 aEvent.State <<= Any();
324 // create and initialize FeatureStateEvent with IsEnabled
325 ::com::sun::star::frame::FeatureStateEvent aEvent;
326 aEvent.FeatureURL = aCmdURL;
327 aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
328 aEvent.IsEnabled = mbButtonEnabled;
329 aEvent.Requery = sal_False;
330 aEvent.State <<= Any();
362
331
363 // Notify listener about new state
364 Reference < XDispatch > xDispatch = aListenerHelper.GetDispatch( mxFrame, aURL.Path );
365 aListenerHelper.Notify( mxFrame, aEvent.FeatureURL.Path, aEvent );
366 }
332 // Notify listener about new state
333 Reference < XDispatch > xDispatch = aListenerHelper.GetDispatch( mxFrame, aURL.Path );
334 aListenerHelper.Notify( mxFrame, aEvent.FeatureURL.Path, aEvent );
335 }
367 else if ( !aURL.Path.compareToAscii("Command5" ) )
336 else if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "SpinfieldCmd" ) ) )
368 {
369 }
337 {
338 }
339 else if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "DropdownboxCmd" ) ) )
340 {
341 // Retrieve the text argument from the sequence property value
342 rtl::OUString aText;
343 for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ )
344 {
345 if ( lArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Text" ) ) )
346 {
347 lArgs[i].Value >>= aText;
348 break;
349 }
350 }
351 OSL_TRACE( "Dropdownbox control - selected entry text : %s",
352 rtl::OUStringToOString( aText, RTL_TEXTENCODING_UTF8 ).getStr() );
353 }
370 }
371}
372
373void SAL_CALL BaseDispatch::addStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL ) throw (RuntimeException)
374{
354 }
355}
356
357void SAL_CALL BaseDispatch::addStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL ) throw (RuntimeException)
358{
375 if ( aURL.Protocol.equalsAscii("vnd.demo.complextoolbarcontrols.demoaddon:") )
359 if ( aURL.Protocol.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) ) )
376 {
360 {
377 if ( aURL.Path.equalsAscii("Command1" ) )
361 if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ImageButtonCmd" ) ) )
378 {
379 // just enable this command
380 ::com::sun::star::frame::FeatureStateEvent aEvent;
381 aEvent.FeatureURL = aURL;
382 aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
383 aEvent.IsEnabled = mbButtonEnabled;
384 aEvent.Requery = sal_False;
385 aEvent.State <<= Any();
386 xControl->statusChanged( aEvent );
387 }
362 {
363 // just enable this command
364 ::com::sun::star::frame::FeatureStateEvent aEvent;
365 aEvent.FeatureURL = aURL;
366 aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
367 aEvent.IsEnabled = mbButtonEnabled;
368 aEvent.Requery = sal_False;
369 aEvent.State <<= Any();
370 xControl->statusChanged( aEvent );
371 }
388 else if ( aURL.Path.equalsAscii("Command2" ) )
372 else if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ComboboxCmd" ) ) )
389 {
390 // just enable this command
391 ::com::sun::star::frame::FeatureStateEvent aEvent;
392 aEvent.FeatureURL = aURL;
393 aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
394 aEvent.IsEnabled = sal_True;
395 aEvent.Requery = sal_False;
396 aEvent.State <<= Any();
397 xControl->statusChanged( aEvent );
398 }
373 {
374 // just enable this command
375 ::com::sun::star::frame::FeatureStateEvent aEvent;
376 aEvent.FeatureURL = aURL;
377 aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
378 aEvent.IsEnabled = sal_True;
379 aEvent.Requery = sal_False;
380 aEvent.State <<= Any();
381 xControl->statusChanged( aEvent );
382 }
399 else if ( aURL.Path.equalsAscii("Command3" ) )
383 else if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ToggleDropdownButtonCmd" ) ) )
400 {
401 // A toggle dropdown box is normally used for a group of commands
402 // where the user can select the last issued command easily.
403 // E.g. a typical command group would be "Insert shape"
404 Sequence< NamedValue > aArgs( 1 );
384 {
385 // A toggle dropdown box is normally used for a group of commands
386 // where the user can select the last issued command easily.
387 // E.g. a typical command group would be "Insert shape"
388 Sequence< NamedValue > aArgs( 1 );
405
389
406 // send command to set context menu content
407 Sequence< rtl::OUString > aContextMenu( 3 );
390 // send command to set context menu content
391 Sequence< rtl::OUString > aContextMenu( 3 );
408 aContextMenu[0] = rtl::OUString::createFromAscii( "Command 1" );
409 aContextMenu[1] = rtl::OUString::createFromAscii( "Command 2" );
410 aContextMenu[2] = rtl::OUString::createFromAscii( "Command 3" );
411
412 aArgs[0].Name = rtl::OUString::createFromAscii( "List" );
392 aContextMenu[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Command 1" ) );
393 aContextMenu[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Command 2" ) );
394 aContextMenu[2] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Command 3" ) );
395
396 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ) );
413 aArgs[0].Value <<= aContextMenu;
397 aArgs[0].Value <<= aContextMenu;
414 SendCommandTo( xControl, aURL, rtl::OUString::createFromAscii( "SetList" ), aArgs, sal_True );
415
398 SendCommandTo( xControl, aURL, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SetList" ) ), aArgs, sal_True );
399
416 // send command to check item on pos=0
417 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" ));
400 // send command to check item on pos=0
401 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" ));
418 aArgs[0].Value <<= sal_Int32( 0 );
419 SendCommandTo( xControl, aURL, ::rtl::OUString::createFromAscii( "CheckItemPos" ), aArgs, sal_True );
402 aArgs[0].Value <<= sal_Int32( 0 );
403 SendCommandTo( xControl, aURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CheckItemPos" ) ), aArgs, sal_True );
420 }
404 }
421 else if ( aURL.Path.equalsAscii("Command4" ) )
405 else if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DropdownButtonCmd" ) ) )
422 {
423 // A dropdown box is normally used for a group of dependent modes, where
424 // the user can only select one. The modes cannot be combined.
425 // E.g. a typical group would be left,right,center,block.
426 Sequence< NamedValue > aArgs( 1 );
406 {
407 // A dropdown box is normally used for a group of dependent modes, where
408 // the user can only select one. The modes cannot be combined.
409 // E.g. a typical group would be left,right,center,block.
410 Sequence< NamedValue > aArgs( 1 );
427
411
428 // send command to set context menu content
429 Sequence< rtl::OUString > aContextMenu( 2 );
412 // send command to set context menu content
413 Sequence< rtl::OUString > aContextMenu( 2 );
430 aContextMenu[0] = rtl::OUString::createFromAscii( "Button Enabled" );
431 aContextMenu[1] = rtl::OUString::createFromAscii( "Button Disabled" );
432
433 aArgs[0].Name = rtl::OUString::createFromAscii( "List" );
414 aContextMenu[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Button Enabled" ) );
415 aContextMenu[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Button Disabled" ) );
416
417 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ) );
434 aArgs[0].Value <<= aContextMenu;
418 aArgs[0].Value <<= aContextMenu;
435 SendCommandTo( xControl, aURL, rtl::OUString::createFromAscii( "SetList" ), aArgs, sal_True );
419 SendCommandTo( xControl, aURL, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SetList" ) ), aArgs, sal_True );
436
437 // set position according to enable/disable state of button
438 sal_Int32 nPos( mbButtonEnabled ? 0 : 1 );
420
421 // set position according to enable/disable state of button
422 sal_Int32 nPos( mbButtonEnabled ? 0 : 1 );
439
423
440 // send command to check item on pos=0
424 // send command to check item on pos=0
441 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" ));
425 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" ) );
442 aArgs[0].Value <<= nPos;
426 aArgs[0].Value <<= nPos;
443 SendCommandTo( xControl, aURL, ::rtl::OUString::createFromAscii( "CheckItemPos" ), aArgs, sal_True );
427 SendCommandTo( xControl, aURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CheckItemPos" ) ), aArgs, sal_True );
444 }
428 }
445 else if ( aURL.Path.equalsAscii("Command5" ) )
429 else if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "SpinfieldCmd" ) ) )
446 {
447 // A spin button
448 Sequence< NamedValue > aArgs( 5 );
430 {
431 // A spin button
432 Sequence< NamedValue > aArgs( 5 );
449
433
450 // send command to initialize spin button
434 // send command to initialize spin button
451 aArgs[0].Name = rtl::OUString::createFromAscii( "Value" );
435 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Value" ) );
452 aArgs[0].Value <<= double( 0.0 );
436 aArgs[0].Value <<= double( 0.0 );
453 aArgs[1].Name = rtl::OUString::createFromAscii( "UpperLimit" );
437 aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UpperLimit" ) );
454 aArgs[1].Value <<= double( 10.0 );
438 aArgs[1].Value <<= double( 10.0 );
455 aArgs[2].Name = rtl::OUString::createFromAscii( "LowerLimit" );
439 aArgs[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LowerLimit" ) );
456 aArgs[2].Value <<= double( 0.0 );
440 aArgs[2].Value <<= double( 0.0 );
457 aArgs[3].Name = rtl::OUString::createFromAscii( "Step" );
441 aArgs[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Step" ) );
458 aArgs[3].Value <<= double( 0.1 );
442 aArgs[3].Value <<= double( 0.1 );
459 aArgs[4].Name = rtl::OUString::createFromAscii( "OutputFormat" );
460 aArgs[4].Value <<= rtl::OUString::createFromAscii( "%.2f cm" );
443 aArgs[4].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OutputFormat" ) );
444 aArgs[4].Value <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "%.2f cm" ) );
461
445
462 SendCommandTo( xControl, aURL, rtl::OUString::createFromAscii( "SetValues" ), aArgs, sal_True );
446 SendCommandTo( xControl, aURL, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SetValues" ) ), aArgs, sal_True );
463 }
447 }
464 else if ( aURL.Path.equalsAscii("Command7" ) )
448 else if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DropdownboxCmd" ) ) )
465 {
466 // A dropdown box is normally used for a group of commands
467 // where the user can select one of a defined set.
468 Sequence< NamedValue > aArgs( 1 );
449 {
450 // A dropdown box is normally used for a group of commands
451 // where the user can select one of a defined set.
452 Sequence< NamedValue > aArgs( 1 );
469
453
470 // send command to set context menu content
471 Sequence< rtl::OUString > aList( 10 );
454 // send command to set context menu content
455 Sequence< rtl::OUString > aList( 10 );
472 aList[0] = rtl::OUString::createFromAscii( "White" );
473 aList[1] = rtl::OUString::createFromAscii( "Black" );
474 aList[2] = rtl::OUString::createFromAscii( "Red" );
475 aList[3] = rtl::OUString::createFromAscii( "Blue" );
476 aList[4] = rtl::OUString::createFromAscii( "Green" );
477 aList[5] = rtl::OUString::createFromAscii( "Grey" );
478 aList[6] = rtl::OUString::createFromAscii( "Yellow" );
479 aList[7] = rtl::OUString::createFromAscii( "Orange" );
480 aList[8] = rtl::OUString::createFromAscii( "Brown" );
481 aList[9] = rtl::OUString::createFromAscii( "Pink" );
482
483 aArgs[0].Name = rtl::OUString::createFromAscii( "List" );
456 aList[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "White" ) );
457 aList[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Black" ) );
458 aList[2] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Red" ) );
459 aList[3] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Blue" ) );
460 aList[4] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Green" ) );
461 aList[5] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Grey" ) );
462 aList[6] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Yellow" ) );
463 aList[7] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Orange" ) );
464 aList[8] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Brown" ) );
465 aList[9] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pink" ) );
466
467 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ) );
484 aArgs[0].Value <<= aList;
468 aArgs[0].Value <<= aList;
485 SendCommandTo( xControl, aURL, rtl::OUString::createFromAscii( "SetList" ), aArgs, sal_True );
469 SendCommandTo( xControl, aURL, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SetList" ) ), aArgs, sal_True );
486 }
487
488 aListenerHelper.AddListener( mxFrame, xControl, aURL.Path );
489 }
490}
491
492void SAL_CALL BaseDispatch::removeStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL ) throw (RuntimeException)
493{
494 aListenerHelper.RemoveListener( mxFrame, xControl, aURL.Path );
495}
496
497void SAL_CALL BaseDispatch::controlEvent( const ControlEvent& Event ) throw (RuntimeException)
498{
470 }
471
472 aListenerHelper.AddListener( mxFrame, xControl, aURL.Path );
473 }
474}
475
476void SAL_CALL BaseDispatch::removeStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL ) throw (RuntimeException)
477{
478 aListenerHelper.RemoveListener( mxFrame, xControl, aURL.Path );
479}
480
481void SAL_CALL BaseDispatch::controlEvent( const ControlEvent& Event ) throw (RuntimeException)
482{
499 if ( Event.aURL.Protocol.equalsAscii("vnd.demo.complextoolbarcontrols.demoaddon:" ))
483 if ( Event.aURL.Protocol.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) ) )
500 {
484 {
501 if ( Event.aURL.Path.equalsAscii( "Command2" ))
485 if ( Event.aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ComboboxCmd" ) ) )
502 {
503 // We get notifications whenever the text inside the combobox has been changed.
504 // We store the new text into a member.
486 {
487 // We get notifications whenever the text inside the combobox has been changed.
488 // We store the new text into a member.
505 if ( Event.Event.equalsAscii( "TextChanged" ))
489 if ( Event.Event.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "TextChanged" ) ) )
506 {
507 rtl::OUString aNewText;
508 sal_Bool bHasText( sal_False );
509 for ( sal_Int32 i = 0; i < Event.aInformation.getLength(); i++ )
510 {
490 {
491 rtl::OUString aNewText;
492 sal_Bool bHasText( sal_False );
493 for ( sal_Int32 i = 0; i < Event.aInformation.getLength(); i++ )
494 {
511 if ( Event.aInformation[i].Name.equalsAsciiL( "Text", 4 ))
495 if ( Event.aInformation[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Text" ) ) )
512 {
513 bHasText = Event.aInformation[i].Value >>= aNewText;
514 break;
515 }
516 }
496 {
497 bHasText = Event.aInformation[i].Value >>= aNewText;
498 break;
499 }
500 }
517
501
518 if ( bHasText )
519 maComboBoxText = aNewText;
520 }
521 }
522 }
523}
502 if ( bHasText )
503 maComboBoxText = aNewText;
504 }
505 }
506 }
507}
524
525BaseDispatch::BaseDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF,
526 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const ::rtl::OUString& rServiceName )
508
509BaseDispatch::BaseDispatch( const Reference< XMultiServiceFactory > &rxMSF,
510 const Reference< XFrame >& xFrame, const rtl::OUString& rServiceName )
527 : mxMSF( rxMSF )
528 , mxFrame( xFrame )
529 , msDocService( rServiceName )
530 , mbButtonEnabled( sal_True )
531{
532}
533
534
535BaseDispatch::~BaseDispatch()
536{
537 mxFrame.clear();
538 mxMSF.clear();
539}
511 : mxMSF( rxMSF )
512 , mxFrame( xFrame )
513 , msDocService( rServiceName )
514 , mbButtonEnabled( sal_True )
515{
516}
517
518
519BaseDispatch::~BaseDispatch()
520{
521 mxFrame.clear();
522 mxMSF.clear();
523}