xref: /trunk/main/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "ListenerHelper.h"
25 #include "MyProtocolHandler.h"
26 
27 #include <com/sun/star/awt/MessageBoxButtons.hpp>
28 #include <com/sun/star/awt/XMessageBoxFactory.hpp>
29 #include <com/sun/star/frame/ControlCommand.hpp>
30 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
31 #include <com/sun/star/sheet/XSpreadsheetView.hpp>
32 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
33 #include <com/sun/star/system/SystemShellExecute.hpp>
34 
35 
36 using namespace com::sun::star::awt;
37 using namespace com::sun::star::frame;
38 using namespace com::sun::star::system;
39 using namespace com::sun::star::uno;
40 
41 using com::sun::star::beans::NamedValue;
42 using com::sun::star::beans::PropertyValue;
43 using com::sun::star::uno::XComponentContext;
44 using com::sun::star::sheet::XSpreadsheetView;
45 using com::sun::star::text::XTextViewCursorSupplier;
46 using com::sun::star::util::URL;
47 
48 ListenerHelper aListenerHelper;
49 
ShowMessageBox(const Reference<XFrame> & rFrame,const::rtl::OUString & aTitle,const::rtl::OUString & aMsgText)50 void BaseDispatch::ShowMessageBox( const Reference< XFrame >& rFrame, const ::rtl::OUString& aTitle, const ::rtl::OUString& aMsgText )
51 {
52     if ( !mxToolkit.is() )
53         mxToolkit = Reference< XToolkit > (
54             mxContext->getServiceManager()->createInstanceWithContext(
55             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.Toolkit" )), mxContext), UNO_QUERY );
56 
57     Reference< XMessageBoxFactory > xMsgBoxFactory( mxToolkit, UNO_QUERY );
58     if ( rFrame.is() && xMsgBoxFactory.is() )
59     {
60         Reference< XMessageBox > xMsgBox = xMsgBoxFactory->createMessageBox(
61             Reference< XWindowPeer >( rFrame->getContainerWindow(), UNO_QUERY ),
62             com::sun::star::awt::MessageBoxType_INFOBOX,
63             MessageBoxButtons::BUTTONS_OK,
64             aTitle,
65             aMsgText );
66 
67         if ( xMsgBox.is() )
68             xMsgBox->execute();
69     }
70 }
71 
SendCommand(const com::sun::star::util::URL & aURL,const::rtl::OUString & rCommand,const Sequence<NamedValue> & rArgs,sal_Bool bEnabled)72 void BaseDispatch::SendCommand( const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const Sequence< NamedValue >& rArgs, sal_Bool bEnabled )
73 {
74     Reference < XDispatch > xDispatch =
75             aListenerHelper.GetDispatch( mxFrame, aURL.Path );
76 
77     FeatureStateEvent aEvent;
78 
79     aEvent.FeatureURL = aURL;
80     aEvent.Source     = xDispatch;
81     aEvent.IsEnabled  = bEnabled;
82     aEvent.Requery    = sal_False;
83 
84     ControlCommand aCtrlCmd;
85     aCtrlCmd.Command   = rCommand;
86     aCtrlCmd.Arguments = rArgs;
87 
88     aEvent.State <<= aCtrlCmd;
89     aListenerHelper.Notify( mxFrame, aEvent.FeatureURL.Path, aEvent );
90 }
91 
SendCommandTo(const Reference<XStatusListener> & xControl,const URL & aURL,const::rtl::OUString & rCommand,const Sequence<NamedValue> & rArgs,sal_Bool bEnabled)92 void BaseDispatch::SendCommandTo( const Reference< XStatusListener >& xControl, const URL& aURL, const ::rtl::OUString& rCommand, const Sequence< NamedValue >& rArgs, sal_Bool bEnabled )
93 {
94     FeatureStateEvent aEvent;
95 
96     aEvent.FeatureURL = aURL;
97     aEvent.Source     = (::com::sun::star::frame::XDispatch*) this;
98     aEvent.IsEnabled  = bEnabled;
99     aEvent.Requery    = sal_False;
100 
101     ControlCommand aCtrlCmd;
102     aCtrlCmd.Command   = rCommand;
103     aCtrlCmd.Arguments = rArgs;
104 
105     aEvent.State <<= aCtrlCmd;
106     xControl->statusChanged( aEvent );
107 }
108 
initialize(const Sequence<Any> & aArguments)109 void SAL_CALL MyProtocolHandler::initialize( const Sequence< Any >& aArguments )
110 {
111     Reference < XFrame > xFrame;
112     if ( aArguments.getLength() )
113     {
114         // das erste Argument ist immer der Frame, da ein ProtocolHandler den braucht um Zugriff
115         // auf den Context zu haben, in dem er aufgerufen wird
116         aArguments[0] >>= xFrame;
117         mxFrame = xFrame;
118     }
119 }
120 
queryDispatch(const URL & aURL,const::rtl::OUString & sTargetFrameName,sal_Int32 nSearchFlags)121 Reference< XDispatch > SAL_CALL MyProtocolHandler::queryDispatch(   const URL& aURL, const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags )
122 {
123     Reference < XDispatch > xRet;
124     if ( !mxFrame.is() )
125         return 0;
126 
127     Reference < XController > xCtrl = mxFrame->getController();
128     if ( xCtrl.is() && !aURL.Protocol.compareToAscii(
129         RTL_CONSTASCII_STRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) ) )
130     {
131         Reference < XTextViewCursorSupplier > xCursor( xCtrl, UNO_QUERY );
132         Reference < XSpreadsheetView > xView( xCtrl, UNO_QUERY );
133         if ( !xCursor.is() && !xView.is() )
134             // ohne ein entsprechendes Dokument funktioniert der Handler nicht
135             return xRet;
136 
137         if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ImageButtonCmd" ) ) ||
138              aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ComboboxCmd" ) ) ||
139              aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ToggleDropdownButtonCmd" ) ) ||
140              aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DropdownButtonCmd" ) ) ||
141              aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "SpinfieldCmd" ) ) ||
142              aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EditfieldCmd" ) ) ||
143              aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DropdownboxCmd" ) ) )
144         {
145             xRet = aListenerHelper.GetDispatch( mxFrame, aURL.Path );
146             if ( !xRet.is() )
147             {
148                 xRet = xCursor.is() ? (BaseDispatch*) new WriterDispatch( mxContext, mxFrame ) :
149                     (BaseDispatch*) new CalcDispatch( mxContext, mxFrame );
150                 aListenerHelper.AddDispatch( xRet, mxFrame, aURL.Path );
151             }
152         }
153     }
154 
155     return xRet;
156 }
157 
queryDispatches(const Sequence<DispatchDescriptor> & seqDescripts)158 Sequence < Reference< XDispatch > > SAL_CALL MyProtocolHandler::queryDispatches( const Sequence < DispatchDescriptor >& seqDescripts )
159 {
160     sal_Int32 nCount = seqDescripts.getLength();
161     Sequence < Reference < XDispatch > > lDispatcher( nCount );
162 
163     for( sal_Int32 i=0; i<nCount; ++i )
164         lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags );
165 
166     return lDispatcher;
167 }
168 
MyProtocolHandler_getImplementationName()169 ::rtl::OUString MyProtocolHandler_getImplementationName ()
170 {
171     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MYPROTOCOLHANDLER_IMPLEMENTATIONNAME ) );
172 }
173 
MyProtocolHandler_supportsService(const::rtl::OUString & ServiceName)174 sal_Bool SAL_CALL MyProtocolHandler_supportsService( const ::rtl::OUString& ServiceName )
175 {
176     return (
177             ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MYPROTOCOLHANDLER_SERVICENAME ) ) ||
178             ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.frame.ProtocolHandler" ) )
179            );
180 }
181 
MyProtocolHandler_getSupportedServiceNames()182 Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler_getSupportedServiceNames(  )
183 {
184     Sequence < ::rtl::OUString > aRet(1);
185     aRet[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MYPROTOCOLHANDLER_SERVICENAME ) );
186     return aRet;
187 }
188 
189 #undef SERVICE_NAME
190 
MyProtocolHandler_createInstance(const Reference<XComponentContext> & rContext)191 Reference< XInterface > SAL_CALL MyProtocolHandler_createInstance( const Reference< XComponentContext > & rContext)
192 {
193     return (cppu::OWeakObject*) new MyProtocolHandler( rContext );
194 }
195 
196 // XServiceInfo
getImplementationName()197 ::rtl::OUString SAL_CALL MyProtocolHandler::getImplementationName(  )
198 {
199     return MyProtocolHandler_getImplementationName();
200 }
201 
supportsService(const::rtl::OUString & rServiceName)202 sal_Bool SAL_CALL MyProtocolHandler::supportsService( const ::rtl::OUString& rServiceName )
203 {
204     return MyProtocolHandler_supportsService( rServiceName );
205 }
206 
getSupportedServiceNames()207 Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler::getSupportedServiceNames(  )
208 {
209     return MyProtocolHandler_getSupportedServiceNames();
210 }
211 
dispatch(const URL & aURL,const Sequence<PropertyValue> & lArgs)212 void SAL_CALL BaseDispatch::dispatch( const URL& aURL, const Sequence < PropertyValue >& lArgs )
213 {
214     /* Its necessary to hold this object alive, till this method finish.
215        May the outside dispatch cache (implemented by the menu/toolbar!)
216        forget this instance during de-/activation of frames (focus!).
217 
218         E.g. An open db beamer in combination with the My-Dialog
219         can force such strange situation :-(
220      */
221     Reference< XInterface > xSelfHold(static_cast< XDispatch* >(this), UNO_QUERY);
222 
223     if ( !aURL.Protocol.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) ) )
224     {
225         if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ImageButtonCmd" ) ) )
226         {
227             // open the Apache OpenOffice web page
228             ::rtl::OUString sURL( RTL_CONSTASCII_USTRINGPARAM( "http://www.openoffice.org" ) );
229             Reference< XSystemShellExecute > xSystemShellExecute(
230                 com::sun::star::system::SystemShellExecute::create( mxContext ) );
231             try
232             {
233                 xSystemShellExecute->execute( sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS );
234             }
235             catch( Exception& rEx )
236             {
237                 (void)rEx;
238             }
239         }
240         else if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ComboboxCmd" ) ) )
241         {
242             // remove the text if it's in our list
243             Sequence< NamedValue > aRemoveArgs( 1 );
244             aRemoveArgs[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
245             aRemoveArgs[0].Value <<= maComboBoxText;
246             SendCommand( aURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RemoveEntryText" ) ), aRemoveArgs, sal_True );
247 
248             // add the new text to the start of the list
249             Sequence< NamedValue > aInsertArgs( 2 );
250             aInsertArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" ));
251             aInsertArgs[0].Value <<= sal_Int32( 0 );
252             aInsertArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
253             aInsertArgs[1].Value <<= maComboBoxText;
254             SendCommand( aURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InsertEntry" ) ), aInsertArgs, sal_True );
255         }
256         else if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ToggleDropdownButtonCmd" ) ) )
257         {
258             // Retrieve the text argument from the sequence property value
259             rtl::OUString aText;
260             for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ )
261             {
262                 if ( lArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Text" ) ) )
263                 {
264                     lArgs[i].Value >>= aText;
265                     break;
266                 }
267             }
268 
269             // create new URL to address the combox box
270             URL aCmdURL;
271             aCmdURL.Path = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ComboboxCmd" ) );
272             aCmdURL.Protocol = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) );
273             aCmdURL.Complete = aCmdURL.Path + aCmdURL.Protocol;
274 
275             // set the selected item as text into the combobox
276             Sequence< NamedValue > aArgs( 1 );
277             aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) );
278             aArgs[0].Value <<= aText;
279             SendCommand( aCmdURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SetText" ) ), aArgs, sal_True );
280         }
281         else if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "DropdownButtonCmd" ) ) )
282         {
283             // Retrieve the text argument from the sequence property value
284             rtl::OUString aText;
285             for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ )
286             {
287                 if ( lArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Text" ) ) )
288                 {
289                     lArgs[i].Value >>= aText;
290                     break;
291                 }
292             }
293 
294             // just enable this command
295 
296             // set enable flag according to selection
297             if ( aText.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Button Disabled" ) ))
298                 mbButtonEnabled = sal_False;
299             else
300                 mbButtonEnabled = sal_True;
301 
302             // create new URL to address the image button
303             URL aCmdURL;
304             aCmdURL.Path = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ImageButtonCmd" ) );
305             aCmdURL.Protocol = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) );
306             aCmdURL.Complete = aCmdURL.Path + aCmdURL.Protocol;
307 
308             // create and initialize FeatureStateEvent with IsEnabled
309             ::com::sun::star::frame::FeatureStateEvent aEvent;
310             aEvent.FeatureURL = aCmdURL;
311             aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
312             aEvent.IsEnabled = mbButtonEnabled;
313             aEvent.Requery = sal_False;
314             aEvent.State <<= Any();
315 
316             // Notify listener about new state
317             Reference < XDispatch > xDispatch = aListenerHelper.GetDispatch( mxFrame, aURL.Path );
318             aListenerHelper.Notify( mxFrame, aEvent.FeatureURL.Path, aEvent );
319         }
320         else if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "SpinfieldCmd" ) ) )
321         {
322         }
323         else if ( !aURL.Path.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "DropdownboxCmd" ) ) )
324         {
325             // Retrieve the text argument from the sequence property value
326             rtl::OUString aText;
327             for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ )
328             {
329                 if ( lArgs[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Text" ) ) )
330                 {
331                     lArgs[i].Value >>= aText;
332                     break;
333                 }
334             }
335             OSL_TRACE( "Dropdownbox control - selected entry text : %s",
336                        rtl::OUStringToOString( aText, RTL_TEXTENCODING_UTF8 ).getStr() );
337         }
338     }
339 }
340 
addStatusListener(const Reference<XStatusListener> & xControl,const URL & aURL)341 void SAL_CALL BaseDispatch::addStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL )
342 {
343     if ( aURL.Protocol.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) ) )
344     {
345         if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ImageButtonCmd" ) ) )
346         {
347             // just enable this command
348             ::com::sun::star::frame::FeatureStateEvent aEvent;
349             aEvent.FeatureURL = aURL;
350             aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
351             aEvent.IsEnabled = mbButtonEnabled;
352             aEvent.Requery = sal_False;
353             aEvent.State <<= Any();
354             xControl->statusChanged( aEvent );
355         }
356         else if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ComboboxCmd" ) ) )
357         {
358             // just enable this command
359             ::com::sun::star::frame::FeatureStateEvent aEvent;
360             aEvent.FeatureURL = aURL;
361             aEvent.Source = (::com::sun::star::frame::XDispatch*) this;
362             aEvent.IsEnabled = sal_True;
363             aEvent.Requery = sal_False;
364             aEvent.State <<= Any();
365             xControl->statusChanged( aEvent );
366         }
367         else if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ToggleDropdownButtonCmd" ) ) )
368         {
369             // A toggle dropdown box is normally used for a group of commands
370             // where the user can select the last issued command easily.
371             // E.g. a typical command group would be "Insert shape"
372             Sequence< NamedValue > aArgs( 1 );
373 
374             // send command to set context menu content
375             Sequence< rtl::OUString > aContextMenu( 3 );
376             aContextMenu[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Command 1" ) );
377             aContextMenu[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Command 2" ) );
378             aContextMenu[2] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Command 3" ) );
379 
380             aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ) );
381             aArgs[0].Value <<= aContextMenu;
382             SendCommandTo( xControl, aURL, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SetList" ) ), aArgs, sal_True );
383 
384             // send command to check item on pos=0
385             aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" ));
386             aArgs[0].Value <<= sal_Int32( 0 );
387             SendCommandTo( xControl, aURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CheckItemPos" ) ), aArgs, sal_True );
388         }
389         else if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DropdownButtonCmd" ) ) )
390         {
391             // A dropdown box is normally used for a group of dependent modes, where
392             // the user can only select one. The modes cannot be combined.
393             // E.g. a typical group would be left,right,center,block.
394             Sequence< NamedValue > aArgs( 1 );
395 
396             // send command to set context menu content
397             Sequence< rtl::OUString > aContextMenu( 2 );
398             aContextMenu[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Button Enabled" ) );
399             aContextMenu[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Button Disabled" ) );
400 
401             aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ) );
402             aArgs[0].Value <<= aContextMenu;
403             SendCommandTo( xControl, aURL, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SetList" ) ), aArgs, sal_True );
404 
405             // set position according to enable/disable state of button
406             sal_Int32 nPos( mbButtonEnabled ? 0 : 1 );
407 
408             // send command to check item on pos=0
409             aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" ) );
410             aArgs[0].Value <<= nPos;
411             SendCommandTo( xControl, aURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CheckItemPos" ) ), aArgs, sal_True );
412         }
413         else if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "SpinfieldCmd" ) ) )
414         {
415             // A spin button
416             Sequence< NamedValue > aArgs( 5 );
417 
418             // send command to initialize spin button
419             aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Value" ) );
420             aArgs[0].Value <<= double( 0.0 );
421             aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UpperLimit" ) );
422             aArgs[1].Value <<= double( 10.0 );
423             aArgs[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LowerLimit" ) );
424             aArgs[2].Value <<= double( 0.0 );
425             aArgs[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Step" ) );
426             aArgs[3].Value <<= double( 0.1 );
427             aArgs[4].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OutputFormat" ) );
428             aArgs[4].Value <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "%.2f cm" ) );
429 
430             SendCommandTo( xControl, aURL, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SetValues" ) ), aArgs, sal_True );
431         }
432         else if ( aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "DropdownboxCmd" ) ) )
433         {
434             // A dropdown box is normally used for a group of commands
435             // where the user can select one of a defined set.
436             Sequence< NamedValue > aArgs( 1 );
437 
438             // send command to set context menu content
439             Sequence< rtl::OUString > aList( 10 );
440             aList[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "White" ) );
441             aList[1] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Black" ) );
442             aList[2] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Red" ) );
443             aList[3] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Blue" ) );
444             aList[4] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Green" ) );
445             aList[5] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Grey" ) );
446             aList[6] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Yellow" ) );
447             aList[7] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Orange" ) );
448             aList[8] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Brown" ) );
449             aList[9] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pink" ) );
450 
451             aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ) );
452             aArgs[0].Value <<= aList;
453             SendCommandTo( xControl, aURL, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SetList" ) ), aArgs, sal_True );
454         }
455 
456         aListenerHelper.AddListener( mxFrame, xControl, aURL.Path );
457     }
458 }
459 
removeStatusListener(const Reference<XStatusListener> & xControl,const URL & aURL)460 void SAL_CALL BaseDispatch::removeStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL )
461 {
462     aListenerHelper.RemoveListener( mxFrame, xControl, aURL.Path );
463 }
464 
controlEvent(const ControlEvent & Event)465 void SAL_CALL BaseDispatch::controlEvent( const ControlEvent& Event )
466 {
467     if ( Event.aURL.Protocol.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "vnd.demo.complextoolbarcontrols.demoaddon:" ) ) )
468     {
469         if ( Event.aURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ComboboxCmd" ) ) )
470         {
471             // We get notifications whenever the text inside the combobox has been changed.
472             // We store the new text into a member.
473             if ( Event.Event.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "TextChanged" ) ) )
474             {
475                 rtl::OUString aNewText;
476                 sal_Bool      bHasText( sal_False );
477                 for ( sal_Int32 i = 0; i < Event.aInformation.getLength(); i++ )
478                 {
479                     if ( Event.aInformation[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Text" ) ) )
480                     {
481                         bHasText = Event.aInformation[i].Value >>= aNewText;
482                         break;
483                     }
484                 }
485 
486                 if ( bHasText )
487                     maComboBoxText = aNewText;
488             }
489         }
490     }
491 }
492 
BaseDispatch(const Reference<XComponentContext> & rxContext,const Reference<XFrame> & xFrame,const rtl::OUString & rServiceName)493 BaseDispatch::BaseDispatch( const Reference< XComponentContext > &rxContext,
494         const Reference< XFrame >& xFrame, const rtl::OUString& rServiceName )
495         : mxContext( rxContext )
496         , mxFrame( xFrame )
497         , msDocService( rServiceName )
498         , mbButtonEnabled( sal_True )
499 {
500 }
501 
502 
~BaseDispatch()503 BaseDispatch::~BaseDispatch()
504 {
505     mxFrame.clear();
506     mxContext.clear();
507 }
508