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