1*6d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6d739b60SAndrew Rist * distributed with this work for additional information 6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance 9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6d739b60SAndrew Rist * software distributed under the License is distributed on an 15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the 17*6d739b60SAndrew Rist * specific language governing permissions and limitations 18*6d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*6d739b60SAndrew Rist *************************************************************/ 21*6d739b60SAndrew Rist 22*6d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_TOGGLEBUTTONTOOLBARCONTROLLER_HXX 28cdf0e10cSrcweir #include "uielement/togglebuttontoolbarcontroller.hxx" 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 32cdf0e10cSrcweir // my own includes 33cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34cdf0e10cSrcweir #include <framework/addonsoptions.hxx> 35cdf0e10cSrcweir #ifndef __FRAMEWORK_TOOLBAR_HXX_ 36cdf0e10cSrcweir #include "uielement/toolbar.hxx" 37cdf0e10cSrcweir #endif 38cdf0e10cSrcweir 39cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 40cdf0e10cSrcweir // interface includes 41cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 42cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 43cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 44cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 45cdf0e10cSrcweir #include <com/sun/star/frame/XControlNotificationListener.hpp> 46cdf0e10cSrcweir #include "com/sun/star/util/XMacroExpander.hpp" 47cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp" 48cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp" 49cdf0e10cSrcweir 50cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 51cdf0e10cSrcweir // other includes 52cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53cdf0e10cSrcweir 54cdf0e10cSrcweir #include <rtl/uri.hxx> 55cdf0e10cSrcweir #include <vos/mutex.hxx> 56cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 57cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 58cdf0e10cSrcweir #include <tools/urlobj.hxx> 59cdf0e10cSrcweir #include <vcl/svapp.hxx> 60cdf0e10cSrcweir #include <vcl/mnemonic.hxx> 61cdf0e10cSrcweir #include <vcl/window.hxx> 62cdf0e10cSrcweir #include <vcl/graph.hxx> 63cdf0e10cSrcweir #include <vcl/bitmap.hxx> 64cdf0e10cSrcweir #include <svtools/filter.hxx> 65cdf0e10cSrcweir #include <svtools/miscopt.hxx> 66cdf0e10cSrcweir 67cdf0e10cSrcweir using namespace ::com::sun::star; 68cdf0e10cSrcweir using namespace ::com::sun::star::awt; 69cdf0e10cSrcweir using namespace ::com::sun::star::uno; 70cdf0e10cSrcweir using namespace ::com::sun::star::beans; 71cdf0e10cSrcweir using namespace ::com::sun::star::lang; 72cdf0e10cSrcweir using namespace ::com::sun::star::frame; 73cdf0e10cSrcweir using namespace ::com::sun::star::util; 74cdf0e10cSrcweir 75cdf0e10cSrcweir namespace framework 76cdf0e10cSrcweir { 77cdf0e10cSrcweir 78cdf0e10cSrcweir // ------------------------------------------------------------------ 79cdf0e10cSrcweir 80cdf0e10cSrcweir ToggleButtonToolbarController::ToggleButtonToolbarController( 81cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rServiceManager, 82cdf0e10cSrcweir const Reference< XFrame >& rFrame, 83cdf0e10cSrcweir ToolBox* pToolbar, 84cdf0e10cSrcweir sal_uInt16 nID, 85cdf0e10cSrcweir Style eStyle, 86cdf0e10cSrcweir const ::rtl::OUString& aCommand ) : 87cdf0e10cSrcweir ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand ), 88cdf0e10cSrcweir m_eStyle( eStyle ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir if ( eStyle == STYLE_DROPDOWNBUTTON ) 91cdf0e10cSrcweir m_pToolbar->SetItemBits( m_nID, TIB_DROPDOWNONLY | m_pToolbar->GetItemBits( m_nID ) ); 92cdf0e10cSrcweir else if ( eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ) 93cdf0e10cSrcweir m_pToolbar->SetItemBits( m_nID, TIB_DROPDOWN | m_pToolbar->GetItemBits( m_nID ) ); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir // ------------------------------------------------------------------ 97cdf0e10cSrcweir 98cdf0e10cSrcweir ToggleButtonToolbarController::~ToggleButtonToolbarController() 99cdf0e10cSrcweir { 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir // ------------------------------------------------------------------ 103cdf0e10cSrcweir 104cdf0e10cSrcweir void SAL_CALL ToggleButtonToolbarController::dispose() 105cdf0e10cSrcweir throw ( RuntimeException ) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 108cdf0e10cSrcweir ComplexToolbarController::dispose(); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir 111cdf0e10cSrcweir // ------------------------------------------------------------------ 112cdf0e10cSrcweir Sequence<PropertyValue> ToggleButtonToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const 113cdf0e10cSrcweir { 114cdf0e10cSrcweir Sequence<PropertyValue> aArgs( 2 ); 115cdf0e10cSrcweir 116cdf0e10cSrcweir // Add key modifier to argument list 117cdf0e10cSrcweir aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" )); 118cdf0e10cSrcweir aArgs[0].Value <<= KeyModifier; 119cdf0e10cSrcweir aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" )); 120cdf0e10cSrcweir aArgs[1].Value <<= m_aCurrentSelection; 121cdf0e10cSrcweir return aArgs; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir // ------------------------------------------------------------------ 125cdf0e10cSrcweir 126cdf0e10cSrcweir uno::Reference< awt::XWindow > SAL_CALL ToggleButtonToolbarController::createPopupWindow() 127cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir uno::Reference< awt::XWindow > xWindow; 130cdf0e10cSrcweir 131cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 132cdf0e10cSrcweir if (( m_eStyle == STYLE_DROPDOWNBUTTON ) || 133cdf0e10cSrcweir ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON )) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir // create popup menu 136cdf0e10cSrcweir PopupMenu aPopup; 137cdf0e10cSrcweir const sal_uInt32 nCount = m_aDropdownMenuList.size(); 138cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < nCount; i++ ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir rtl::OUString aLabel( m_aDropdownMenuList[i] ); 141cdf0e10cSrcweir aPopup.InsertItem( sal_uInt16( i+1 ), aLabel ); 142cdf0e10cSrcweir if ( aLabel == m_aCurrentSelection ) 143cdf0e10cSrcweir aPopup.CheckItem( sal_uInt16( i+1 ), sal_True ); 144cdf0e10cSrcweir else 145cdf0e10cSrcweir aPopup.CheckItem( sal_uInt16( i+1 ), sal_False ); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir 148cdf0e10cSrcweir m_pToolbar->SetItemDown( m_nID, sal_True ); 149cdf0e10cSrcweir aPopup.SetSelectHdl( LINK( this, ToggleButtonToolbarController, MenuSelectHdl )); 150cdf0e10cSrcweir aPopup.Execute( m_pToolbar, m_pToolbar->GetItemRect( m_nID )); 151cdf0e10cSrcweir m_pToolbar->SetItemDown( m_nID, sal_False ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir 154cdf0e10cSrcweir return xWindow; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir // ------------------------------------------------------------------ 158cdf0e10cSrcweir 159cdf0e10cSrcweir void ToggleButtonToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 162cdf0e10cSrcweir 163cdf0e10cSrcweir if (( m_eStyle == STYLE_DROPDOWNBUTTON ) || 164cdf0e10cSrcweir ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON )) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir if ( rControlCommand.Command.equalsAsciiL( "SetList", 7 )) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "List", 4 )) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir Sequence< ::rtl::OUString > aList; 173cdf0e10cSrcweir m_aDropdownMenuList.clear(); 174cdf0e10cSrcweir 175cdf0e10cSrcweir rControlCommand.Arguments[i].Value >>= aList; 176cdf0e10cSrcweir for ( sal_Int32 j = 0; j < aList.getLength(); j++ ) 177cdf0e10cSrcweir m_aDropdownMenuList.push_back( aList[j] ); 178cdf0e10cSrcweir 179cdf0e10cSrcweir // send notification 180cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aInfo( 1 ); 181cdf0e10cSrcweir aInfo[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" )); 182cdf0e10cSrcweir aInfo[0].Value <<= aList; 183cdf0e10cSrcweir addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ListChanged" )), 184cdf0e10cSrcweir getDispatchFromCommand( m_aCommandURL ), 185cdf0e10cSrcweir aInfo ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir break; 188cdf0e10cSrcweir } 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir else if ( rControlCommand.Command.equalsAsciiL( "CheckItemPos", 12 )) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 )) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir sal_Int32 nPos( -1 ); 198cdf0e10cSrcweir 199cdf0e10cSrcweir rControlCommand.Arguments[i].Value >>= nPos; 200cdf0e10cSrcweir if ( nPos >= 0 && 201cdf0e10cSrcweir ( sal::static_int_cast< sal_uInt32 >(nPos) 202cdf0e10cSrcweir < m_aDropdownMenuList.size() ) ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir m_aCurrentSelection = m_aDropdownMenuList[nPos]; 205cdf0e10cSrcweir 206cdf0e10cSrcweir // send notification 207cdf0e10cSrcweir uno::Sequence< beans::NamedValue > aInfo( 1 ); 208cdf0e10cSrcweir aInfo[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ItemChecked" )); 209cdf0e10cSrcweir aInfo[0].Value <<= nPos; 210cdf0e10cSrcweir addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" )), 211cdf0e10cSrcweir getDispatchFromCommand( m_aCommandURL ), 212cdf0e10cSrcweir aInfo ); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir break; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir } 217cdf0e10cSrcweir } 218cdf0e10cSrcweir else if ( rControlCommand.Command.equalsAsciiL( "AddEntry", 8 )) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir rtl::OUString aText; 221cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 222cdf0e10cSrcweir { 223cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 )) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Value >>= aText ) 226cdf0e10cSrcweir m_aDropdownMenuList.push_back( aText ); 227cdf0e10cSrcweir break; 228cdf0e10cSrcweir } 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } 231cdf0e10cSrcweir else if ( rControlCommand.Command.equalsAsciiL( "InsertEntry", 11 )) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir sal_Int32 nPos( COMBOBOX_APPEND ); 234cdf0e10cSrcweir sal_Int32 nSize = sal_Int32( m_aDropdownMenuList.size() ); 235cdf0e10cSrcweir rtl::OUString aText; 236cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 )) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir sal_Int32 nTmpPos = 0; 241cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Value >>= nTmpPos ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir if (( nTmpPos >= 0 ) && ( nTmpPos < sal_Int32( nSize ))) 244cdf0e10cSrcweir nPos = nTmpPos; 245cdf0e10cSrcweir } 246cdf0e10cSrcweir } 247cdf0e10cSrcweir else if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 )) 248cdf0e10cSrcweir rControlCommand.Arguments[i].Value >>= aText; 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir std::vector< ::rtl::OUString >::iterator aIter = m_aDropdownMenuList.begin(); 252cdf0e10cSrcweir aIter += nPos; 253cdf0e10cSrcweir m_aDropdownMenuList.insert( aIter, aText ); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryPos", 14 )) 256cdf0e10cSrcweir { 257cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 258cdf0e10cSrcweir { 259cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 )) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir sal_Int32 nPos( -1 ); 262cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Value >>= nPos ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir if ( nPos < sal_Int32( m_aDropdownMenuList.size() )) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir std::vector< ::rtl::OUString >::iterator aIter = m_aDropdownMenuList.begin(); 267cdf0e10cSrcweir aIter += nPos; 268cdf0e10cSrcweir m_aDropdownMenuList.erase( aIter ); 269cdf0e10cSrcweir } 270cdf0e10cSrcweir } 271cdf0e10cSrcweir break; 272cdf0e10cSrcweir } 273cdf0e10cSrcweir } 274cdf0e10cSrcweir } 275cdf0e10cSrcweir else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryText", 15 )) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ ) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 )) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir rtl::OUString aText; 282cdf0e10cSrcweir if ( rControlCommand.Arguments[i].Value >>= aText ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir sal_Int32 nSize = sal_Int32( m_aDropdownMenuList.size() ); 285cdf0e10cSrcweir for ( sal_Int32 j = 0; j < nSize; j++ ) 286cdf0e10cSrcweir { 287cdf0e10cSrcweir if ( m_aDropdownMenuList[j] == aText ) 288cdf0e10cSrcweir { 289cdf0e10cSrcweir std::vector< ::rtl::OUString >::iterator aIter = m_aDropdownMenuList.begin(); 290cdf0e10cSrcweir aIter += j; 291cdf0e10cSrcweir m_aDropdownMenuList.erase( aIter ); 292cdf0e10cSrcweir break; 293cdf0e10cSrcweir } 294cdf0e10cSrcweir } 295cdf0e10cSrcweir } 296cdf0e10cSrcweir break; 297cdf0e10cSrcweir } 298cdf0e10cSrcweir } 299cdf0e10cSrcweir } 300cdf0e10cSrcweir } 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir IMPL_LINK( ToggleButtonToolbarController, MenuSelectHdl, Menu *, pMenu ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 306cdf0e10cSrcweir 307cdf0e10cSrcweir sal_uInt16 nItemId = pMenu->GetCurItemId(); 308cdf0e10cSrcweir if ( nItemId > 0 && nItemId <= m_aDropdownMenuList.size() ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir m_aCurrentSelection = m_aDropdownMenuList[nItemId-1]; 311cdf0e10cSrcweir 312cdf0e10cSrcweir execute( 0 ); 313cdf0e10cSrcweir } 314cdf0e10cSrcweir return 0; 315cdf0e10cSrcweir } 316cdf0e10cSrcweir 317cdf0e10cSrcweir } // namespace 318cdf0e10cSrcweir 319