1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "tbunosearchcontrollers.hxx" 28cdf0e10cSrcweir #include <svx/dialogs.hrc> 29cdf0e10cSrcweir #include <svx/dialmgr.hxx> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 32cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp> 33cdf0e10cSrcweir #include <com/sun/star/ui/XUIElement.hpp> 34cdf0e10cSrcweir #include <com/sun/star/util/URL.hpp> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 37cdf0e10cSrcweir #include <vcl/toolbox.hxx> 38cdf0e10cSrcweir #include <vcl/svapp.hxx> 39cdf0e10cSrcweir #include <vos/mutex.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir namespace svx 42cdf0e10cSrcweir { 43cdf0e10cSrcweir 44cdf0e10cSrcweir static const ::rtl::OUString SEARCHITEM_SEARCHSTRING = ::rtl::OUString::createFromAscii("SearchItem.SearchString"); 45cdf0e10cSrcweir static const ::rtl::OUString SEARCHITEM_SEARCHBACKWARD = ::rtl::OUString::createFromAscii("SearchItem.Backward"); 46cdf0e10cSrcweir 47cdf0e10cSrcweir static const ::rtl::OUString COMMAND_EXECUTESEARCH = ::rtl::OUString::createFromAscii(".uno:ExecuteSearch"); 48cdf0e10cSrcweir static const ::rtl::OUString COMMAND_FINDTEXT = ::rtl::OUString::createFromAscii(".uno:FindText") ; 49cdf0e10cSrcweir static const ::rtl::OUString COMMAND_DOWNSEARCH = ::rtl::OUString::createFromAscii(".uno:DownSearch"); 50cdf0e10cSrcweir static const ::rtl::OUString COMMAND_UPSEARCH = ::rtl::OUString::createFromAscii(".uno:UpSearch") ; 51cdf0e10cSrcweir static const ::rtl::OUString COMMAND_APPENDSEARCHHISTORY = ::rtl::OUString::createFromAscii("AppendSearchHistory"); 52cdf0e10cSrcweir 53cdf0e10cSrcweir static const ::rtl::OUString SERVICENAME_URLTRANSFORMER = ::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer"); 54cdf0e10cSrcweir static const sal_Int32 REMEMBER_SIZE = 10; 55cdf0e10cSrcweir 56cdf0e10cSrcweir void impl_executeSearch( const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr, const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Sequence< css::beans::PropertyValue >& lArgs ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir css::uno::Reference< css::util::XURLTransformer > xURLTransformer( rSMgr->createInstance(SERVICENAME_URLTRANSFORMER), css::uno::UNO_QUERY ); 59cdf0e10cSrcweir if ( xURLTransformer.is() ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir css::util::URL aURL; 62cdf0e10cSrcweir aURL.Complete = COMMAND_EXECUTESEARCH; 63cdf0e10cSrcweir xURLTransformer->parseStrict(aURL); 64cdf0e10cSrcweir 65cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider(xFrame, css::uno::UNO_QUERY); 66cdf0e10cSrcweir if ( xDispatchProvider.is() ) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch( aURL, ::rtl::OUString(), 0 ); 69cdf0e10cSrcweir if ( xDispatch.is() && aURL.Complete.getLength() > 0 ) 70cdf0e10cSrcweir xDispatch->dispatch( aURL, lArgs ); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir } 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir FindTextFieldControl::FindTextFieldControl( Window* pParent, WinBits nStyle, 76cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame >& xFrame, 77cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceManager) : 78cdf0e10cSrcweir ComboBox( pParent, nStyle ), 79cdf0e10cSrcweir m_xFrame(xFrame), 80cdf0e10cSrcweir m_xServiceManager(xServiceManager), 81cdf0e10cSrcweir m_bToClearTextField(sal_True) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir InitControls_Impl(); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir FindTextFieldControl::~FindTextFieldControl() 87cdf0e10cSrcweir { 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir void FindTextFieldControl::InitControls_Impl() 91cdf0e10cSrcweir { 92cdf0e10cSrcweir SetText( SVX_RESSTR( RID_SVXSTR_FINDBAR_FIND ) ); 93cdf0e10cSrcweir SetControlForeground(GetSettings().GetStyleSettings().GetDisableColor()); 94cdf0e10cSrcweir 95cdf0e10cSrcweir EnableAutocomplete(sal_True, sal_True); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir 98cdf0e10cSrcweir void FindTextFieldControl::Remember_Impl(const String& rStr) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir sal_uInt16 nCount = GetEntryCount(); 101cdf0e10cSrcweir 102cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; ++i) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir if ( rStr == GetEntry(i)) 105cdf0e10cSrcweir return; 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir if (nCount == REMEMBER_SIZE) 109cdf0e10cSrcweir RemoveEntry(REMEMBER_SIZE-1); 110cdf0e10cSrcweir 111cdf0e10cSrcweir InsertEntry(rStr, 0); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir void FindTextFieldControl::Modify() 115cdf0e10cSrcweir { 116cdf0e10cSrcweir ComboBox::Modify(); 117cdf0e10cSrcweir 118cdf0e10cSrcweir SetControlForeground( GetSettings().GetStyleSettings().GetWindowTextColor() ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir long FindTextFieldControl::PreNotify( NotifyEvent& rNEvt ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir long nRet= ComboBox::PreNotify( rNEvt ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir switch ( rNEvt.GetType() ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir case EVENT_KEYINPUT: 128cdf0e10cSrcweir { 129cdf0e10cSrcweir const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent(); 130cdf0e10cSrcweir sal_Bool bCtrl = pKeyEvent->GetKeyCode().IsMod1(); 131cdf0e10cSrcweir sal_Bool bAlt = pKeyEvent->GetKeyCode().IsMod2(); 132cdf0e10cSrcweir sal_Bool bShift = pKeyEvent->GetKeyCode().IsShift(); 133cdf0e10cSrcweir sal_uInt16 nCode = pKeyEvent->GetKeyCode().GetCode(); 134cdf0e10cSrcweir 135cdf0e10cSrcweir if ( (bCtrl && bAlt && KEY_F == nCode) || KEY_ESCAPE == nCode ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir nRet = 1; 138cdf0e10cSrcweir GrabFocusToDocument(); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir if ( KEY_RETURN == nCode ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir Remember_Impl(GetText()); 144cdf0e10cSrcweir 145cdf0e10cSrcweir ::rtl::OUString sFindText = GetText(); 146cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > lArgs(2); 147cdf0e10cSrcweir 148cdf0e10cSrcweir lArgs[0].Name = SEARCHITEM_SEARCHSTRING; 149cdf0e10cSrcweir lArgs[0].Value <<= sFindText; 150cdf0e10cSrcweir 151cdf0e10cSrcweir lArgs[1].Name = SEARCHITEM_SEARCHBACKWARD; 152cdf0e10cSrcweir if (bShift) 153cdf0e10cSrcweir lArgs[1].Value <<= sal_True; 154cdf0e10cSrcweir else 155cdf0e10cSrcweir lArgs[1].Value <<= sal_False; 156cdf0e10cSrcweir 157cdf0e10cSrcweir impl_executeSearch(m_xServiceManager, m_xFrame, lArgs); 158cdf0e10cSrcweir nRet = 1; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir break; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir case EVENT_GETFOCUS: 164cdf0e10cSrcweir if ( m_bToClearTextField ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir SetText( String() ); 167cdf0e10cSrcweir m_bToClearTextField = sal_False; 168cdf0e10cSrcweir } 169cdf0e10cSrcweir SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) ); 170cdf0e10cSrcweir break; 171cdf0e10cSrcweir 172cdf0e10cSrcweir case EVENT_LOSEFOCUS: 173cdf0e10cSrcweir if ( GetText().Len() == 0 ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir SetText( SVX_RESSTR( RID_SVXSTR_FINDBAR_FIND ) ); 176cdf0e10cSrcweir SetControlForeground(GetSettings().GetStyleSettings().GetDisableColor()); 177cdf0e10cSrcweir m_bToClearTextField = sal_True; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir break; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir return nRet; 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir 186cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------- 187cdf0e10cSrcweir // SearchToolbarControllersManager 188cdf0e10cSrcweir 189cdf0e10cSrcweir SearchToolbarControllersManager* SearchToolbarControllersManager::m_pInstance = 0; 190cdf0e10cSrcweir 191cdf0e10cSrcweir SearchToolbarControllersManager::SearchToolbarControllersManager() 192cdf0e10cSrcweir { 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir SearchToolbarControllersManager::~SearchToolbarControllersManager() 196cdf0e10cSrcweir { 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir SearchToolbarControllersManager* SearchToolbarControllersManager::createControllersManager() 200cdf0e10cSrcweir { 201cdf0e10cSrcweir if (!m_pInstance) 202cdf0e10cSrcweir m_pInstance = new SearchToolbarControllersManager(); 203cdf0e10cSrcweir 204cdf0e10cSrcweir return m_pInstance; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir void SearchToolbarControllersManager::registryController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& xStatusListener, const ::rtl::OUString& sCommandURL ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame); 210cdf0e10cSrcweir if (pIt == aSearchToolbarControllersMap.end()) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir SearchToolbarControllersVec lControllers(1); 213cdf0e10cSrcweir lControllers[0].Name = sCommandURL; 214cdf0e10cSrcweir lControllers[0].Value <<= xStatusListener; 215cdf0e10cSrcweir aSearchToolbarControllersMap.insert(SearchToolbarControllersMap::value_type(xFrame, lControllers)); 216cdf0e10cSrcweir } 217cdf0e10cSrcweir else 218cdf0e10cSrcweir { 219cdf0e10cSrcweir sal_Int32 nSize = pIt->second.size(); 220cdf0e10cSrcweir for (sal_Int32 i=0; i<nSize; ++i) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir if (pIt->second[i].Name.equals(sCommandURL)) 223cdf0e10cSrcweir return; 224cdf0e10cSrcweir } 225cdf0e10cSrcweir 226cdf0e10cSrcweir pIt->second.resize(nSize+1); 227cdf0e10cSrcweir pIt->second[nSize].Name = sCommandURL; 228cdf0e10cSrcweir pIt->second[nSize].Value <<= xStatusListener; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir } 231cdf0e10cSrcweir 232cdf0e10cSrcweir void SearchToolbarControllersManager::freeController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& /*xStatusListener*/, const ::rtl::OUString& sCommandURL ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame); 235cdf0e10cSrcweir if (pIt != aSearchToolbarControllersMap.end()) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir for (SearchToolbarControllersVec::iterator pItCtrl=pIt->second.begin(); pItCtrl!=pIt->second.end(); ++pItCtrl) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir if (pItCtrl->Name.equals(sCommandURL)) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir pIt->second.erase(pItCtrl); 242cdf0e10cSrcweir break; 243cdf0e10cSrcweir } 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir if (pIt->second.empty()) 247cdf0e10cSrcweir aSearchToolbarControllersMap.erase(pIt); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir css::uno::Reference< css::frame::XStatusListener > SearchToolbarControllersManager::findController( const css::uno::Reference< css::frame::XFrame >& xFrame, const ::rtl::OUString& sCommandURL ) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir css::uno::Reference< css::frame::XStatusListener > xStatusListener; 254cdf0e10cSrcweir 255cdf0e10cSrcweir SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame); 256cdf0e10cSrcweir if (pIt != aSearchToolbarControllersMap.end()) 257cdf0e10cSrcweir { 258cdf0e10cSrcweir for (SearchToolbarControllersVec::iterator pItCtrl =pIt->second.begin(); pItCtrl != pIt->second.end(); ++pItCtrl) 259cdf0e10cSrcweir { 260cdf0e10cSrcweir if (pItCtrl->Name.equals(sCommandURL)) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir pItCtrl->Value >>= xStatusListener; 263cdf0e10cSrcweir break; 264cdf0e10cSrcweir } 265cdf0e10cSrcweir } 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir return xStatusListener; 269cdf0e10cSrcweir } 270cdf0e10cSrcweir 271cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------- 272cdf0e10cSrcweir // FindTextToolbarController 273cdf0e10cSrcweir 274cdf0e10cSrcweir FindTextToolbarController::FindTextToolbarController( const css::uno::Reference< css::lang::XMultiServiceFactory >& rServiceManager ) 275cdf0e10cSrcweir :svt::ToolboxController( rServiceManager, 276cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame >(), 277cdf0e10cSrcweir COMMAND_FINDTEXT ) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir FindTextToolbarController::~FindTextToolbarController() 282cdf0e10cSrcweir { 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir // XInterface 286cdf0e10cSrcweir css::uno::Any SAL_CALL FindTextToolbarController::queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException ) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir css::uno::Any a = ToolboxController::queryInterface( aType ); 289cdf0e10cSrcweir if ( a.hasValue() ) 290cdf0e10cSrcweir return a; 291cdf0e10cSrcweir 292cdf0e10cSrcweir return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) ); 293cdf0e10cSrcweir } 294cdf0e10cSrcweir 295cdf0e10cSrcweir void SAL_CALL FindTextToolbarController::acquire() throw () 296cdf0e10cSrcweir { 297cdf0e10cSrcweir ToolboxController::acquire(); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir void SAL_CALL FindTextToolbarController::release() throw () 301cdf0e10cSrcweir { 302cdf0e10cSrcweir ToolboxController::release(); 303cdf0e10cSrcweir } 304cdf0e10cSrcweir 305cdf0e10cSrcweir // XServiceInfo 306cdf0e10cSrcweir ::rtl::OUString SAL_CALL FindTextToolbarController::getImplementationName() throw( css::uno::RuntimeException ) 307cdf0e10cSrcweir { 308cdf0e10cSrcweir return getImplementationName_Static(); 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir sal_Bool SAL_CALL FindTextToolbarController::supportsService( const ::rtl::OUString& ServiceName ) throw( css::uno::RuntimeException ) 312cdf0e10cSrcweir { 313cdf0e10cSrcweir const css::uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() ); 314cdf0e10cSrcweir const ::rtl::OUString * pArray = aSNL.getConstArray(); 315cdf0e10cSrcweir 316cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 317cdf0e10cSrcweir if( pArray[i] == ServiceName ) 318cdf0e10cSrcweir return true; 319cdf0e10cSrcweir 320cdf0e10cSrcweir return false; 321cdf0e10cSrcweir } 322cdf0e10cSrcweir 323cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL FindTextToolbarController::getSupportedServiceNames() throw( css::uno::RuntimeException ) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir return getSupportedServiceNames_Static(); 326cdf0e10cSrcweir } 327cdf0e10cSrcweir 328cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > FindTextToolbarController::getSupportedServiceNames_Static() throw() 329cdf0e10cSrcweir { 330cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > aSNS( 1 ); 331cdf0e10cSrcweir aSNS.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ) ); 332cdf0e10cSrcweir return aSNS; 333cdf0e10cSrcweir } 334cdf0e10cSrcweir 335cdf0e10cSrcweir // XComponent 336cdf0e10cSrcweir void SAL_CALL FindTextToolbarController::dispose() throw ( css::uno::RuntimeException ) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 339cdf0e10cSrcweir 340cdf0e10cSrcweir SearchToolbarControllersManager::createControllersManager()->freeController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); 341cdf0e10cSrcweir 342cdf0e10cSrcweir svt::ToolboxController::dispose(); 343cdf0e10cSrcweir delete m_pFindTextFieldControl; 344cdf0e10cSrcweir m_pFindTextFieldControl = 0; 345cdf0e10cSrcweir } 346cdf0e10cSrcweir 347cdf0e10cSrcweir // XInitialization 348cdf0e10cSrcweir void SAL_CALL FindTextToolbarController::initialize( const css::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException) 349cdf0e10cSrcweir { 350cdf0e10cSrcweir svt::ToolboxController::initialize(aArguments); 351cdf0e10cSrcweir 352cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( getParent() ); 353cdf0e10cSrcweir ToolBox* pToolBox = (ToolBox*)pWindow; 354cdf0e10cSrcweir if ( pToolBox ) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir sal_uInt16 nItemCount = pToolBox->GetItemCount(); 357cdf0e10cSrcweir for ( sal_uInt16 i=0; i<nItemCount; ++i ) 358cdf0e10cSrcweir { 359cdf0e10cSrcweir ::rtl::OUString sItemCommand = pToolBox->GetItemCommand(i); 360cdf0e10cSrcweir if ( sItemCommand.equals( COMMAND_DOWNSEARCH ) ) 361cdf0e10cSrcweir m_nDownSearchId = i; 362cdf0e10cSrcweir else if (sItemCommand.equals( COMMAND_UPSEARCH )) 363cdf0e10cSrcweir m_nUpSearchId = i; 364cdf0e10cSrcweir } 365cdf0e10cSrcweir } 366cdf0e10cSrcweir 367cdf0e10cSrcweir SearchToolbarControllersManager::createControllersManager()->registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir // XToolbarController 371cdf0e10cSrcweir void SAL_CALL FindTextToolbarController::execute( sal_Int16 /*KeyModifier*/ ) throw ( css::uno::RuntimeException ) 372cdf0e10cSrcweir { 373cdf0e10cSrcweir } 374cdf0e10cSrcweir 375cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > SAL_CALL FindTextToolbarController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) throw ( css::uno::RuntimeException ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xItemWindow; 378cdf0e10cSrcweir 379cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xParent( Parent ); 380cdf0e10cSrcweir Window* pParent = VCLUnoHelper::GetWindow( xParent ); 381cdf0e10cSrcweir if ( pParent ) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir ToolBox* pToolbar = ( ToolBox* )pParent; 384cdf0e10cSrcweir m_pFindTextFieldControl = new FindTextFieldControl( pToolbar, WinBits( WB_DROPDOWN | WB_VSCROLL), m_xFrame, m_xServiceManager ); 385cdf0e10cSrcweir 386cdf0e10cSrcweir Size aSize(100, m_pFindTextFieldControl->GetTextHeight() + 200); 387cdf0e10cSrcweir m_pFindTextFieldControl->SetSizePixel( aSize ); 388cdf0e10cSrcweir m_pFindTextFieldControl->SetModifyHdl(LINK(this, FindTextToolbarController, EditModifyHdl)); 389cdf0e10cSrcweir } 390cdf0e10cSrcweir xItemWindow = VCLUnoHelper::GetInterface( m_pFindTextFieldControl ); 391cdf0e10cSrcweir 392cdf0e10cSrcweir return xItemWindow; 393cdf0e10cSrcweir } 394cdf0e10cSrcweir 395cdf0e10cSrcweir // XStatusListener 396cdf0e10cSrcweir void SAL_CALL FindTextToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException ) 397cdf0e10cSrcweir { 398cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 399cdf0e10cSrcweir if ( m_bDisposed ) 400cdf0e10cSrcweir return; 401cdf0e10cSrcweir 402cdf0e10cSrcweir ::rtl::OUString aFeatureURL = rEvent.FeatureURL.Complete; 403cdf0e10cSrcweir if (aFeatureURL.equalsAscii("AppendSearchHistory")) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir m_pFindTextFieldControl->Remember_Impl(m_pFindTextFieldControl->GetText()); 406cdf0e10cSrcweir } 407cdf0e10cSrcweir } 408cdf0e10cSrcweir 409cdf0e10cSrcweir IMPL_LINK( FindTextToolbarController, EditModifyHdl, void *, EMPTYARG ) 410cdf0e10cSrcweir { 411cdf0e10cSrcweir // enable or disable item DownSearch/UpSearch of findbar 412cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( getParent() ); 413cdf0e10cSrcweir ToolBox* pToolBox = (ToolBox*)pWindow; 414cdf0e10cSrcweir if ( pToolBox && m_pFindTextFieldControl ) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir if (m_pFindTextFieldControl->GetText().Len()>0) 417cdf0e10cSrcweir { 418cdf0e10cSrcweir if ( !pToolBox->IsItemEnabled(m_nDownSearchId) ) 419cdf0e10cSrcweir pToolBox->EnableItem(m_nDownSearchId, sal_True); 420cdf0e10cSrcweir if ( !pToolBox->IsItemEnabled(m_nUpSearchId) ) 421cdf0e10cSrcweir pToolBox->EnableItem(m_nUpSearchId, sal_True); 422cdf0e10cSrcweir } 423cdf0e10cSrcweir else 424cdf0e10cSrcweir { 425cdf0e10cSrcweir if ( pToolBox->IsItemEnabled(m_nDownSearchId) ) 426cdf0e10cSrcweir pToolBox->EnableItem(m_nDownSearchId, sal_False); 427cdf0e10cSrcweir if ( pToolBox->IsItemEnabled(m_nUpSearchId) ) 428cdf0e10cSrcweir pToolBox->EnableItem(m_nUpSearchId, sal_False); 429cdf0e10cSrcweir } 430cdf0e10cSrcweir } 431cdf0e10cSrcweir 432cdf0e10cSrcweir return 0; 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------- 436cdf0e10cSrcweir // class DownSearchToolboxController 437cdf0e10cSrcweir 438cdf0e10cSrcweir DownSearchToolboxController::DownSearchToolboxController(const css::uno::Reference< css::lang::XMultiServiceFactory >& rServiceManager ) 439cdf0e10cSrcweir : svt::ToolboxController( rServiceManager, 440cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame >(), 441cdf0e10cSrcweir COMMAND_DOWNSEARCH ) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir } 444cdf0e10cSrcweir 445cdf0e10cSrcweir DownSearchToolboxController::~DownSearchToolboxController() 446cdf0e10cSrcweir { 447cdf0e10cSrcweir } 448cdf0e10cSrcweir 449cdf0e10cSrcweir // XInterface 450cdf0e10cSrcweir css::uno::Any SAL_CALL DownSearchToolboxController::queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir css::uno::Any a = ToolboxController::queryInterface( aType ); 453cdf0e10cSrcweir if ( a.hasValue() ) 454cdf0e10cSrcweir return a; 455cdf0e10cSrcweir 456cdf0e10cSrcweir return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) ); 457cdf0e10cSrcweir } 458cdf0e10cSrcweir 459cdf0e10cSrcweir void SAL_CALL DownSearchToolboxController::acquire() throw () 460cdf0e10cSrcweir { 461cdf0e10cSrcweir ToolboxController::acquire(); 462cdf0e10cSrcweir } 463cdf0e10cSrcweir 464cdf0e10cSrcweir void SAL_CALL DownSearchToolboxController::release() throw () 465cdf0e10cSrcweir { 466cdf0e10cSrcweir ToolboxController::release(); 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir // XServiceInfo 470cdf0e10cSrcweir ::rtl::OUString SAL_CALL DownSearchToolboxController::getImplementationName() throw( css::uno::RuntimeException ) 471cdf0e10cSrcweir { 472cdf0e10cSrcweir return getImplementationName_Static(); 473cdf0e10cSrcweir } 474cdf0e10cSrcweir 475cdf0e10cSrcweir sal_Bool SAL_CALL DownSearchToolboxController::supportsService( const ::rtl::OUString& ServiceName ) throw( css::uno::RuntimeException ) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir const css::uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() ); 478cdf0e10cSrcweir const ::rtl::OUString * pArray = aSNL.getConstArray(); 479cdf0e10cSrcweir 480cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 481cdf0e10cSrcweir if( pArray[i] == ServiceName ) 482cdf0e10cSrcweir return true; 483cdf0e10cSrcweir 484cdf0e10cSrcweir return false; 485cdf0e10cSrcweir } 486cdf0e10cSrcweir 487cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL DownSearchToolboxController::getSupportedServiceNames() throw( css::uno::RuntimeException ) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir return getSupportedServiceNames_Static(); 490cdf0e10cSrcweir } 491cdf0e10cSrcweir 492cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > DownSearchToolboxController::getSupportedServiceNames_Static() throw() 493cdf0e10cSrcweir { 494cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > aSNS( 1 ); 495cdf0e10cSrcweir aSNS.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" )); 496cdf0e10cSrcweir return aSNS; 497cdf0e10cSrcweir } 498cdf0e10cSrcweir 499cdf0e10cSrcweir // XComponent 500cdf0e10cSrcweir void SAL_CALL DownSearchToolboxController::dispose() throw ( css::uno::RuntimeException ) 501cdf0e10cSrcweir { 502cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 503cdf0e10cSrcweir 504cdf0e10cSrcweir SearchToolbarControllersManager::createControllersManager()->freeController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); 505cdf0e10cSrcweir 506cdf0e10cSrcweir svt::ToolboxController::dispose(); 507cdf0e10cSrcweir } 508cdf0e10cSrcweir 509cdf0e10cSrcweir // XInitialization 510cdf0e10cSrcweir void SAL_CALL DownSearchToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException ) 511cdf0e10cSrcweir { 512cdf0e10cSrcweir svt::ToolboxController::initialize( aArguments ); 513cdf0e10cSrcweir SearchToolbarControllersManager::createControllersManager()->registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); 514cdf0e10cSrcweir } 515cdf0e10cSrcweir 516cdf0e10cSrcweir // XToolbarController 517cdf0e10cSrcweir void SAL_CALL DownSearchToolboxController::execute( sal_Int16 /*KeyModifier*/ ) throw ( css::uno::RuntimeException) 518cdf0e10cSrcweir { 519cdf0e10cSrcweir if ( m_bDisposed ) 520cdf0e10cSrcweir throw css::lang::DisposedException(); 521cdf0e10cSrcweir 522cdf0e10cSrcweir ::rtl::OUString sFindText; 523cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( getParent() ); 524cdf0e10cSrcweir ToolBox* pToolBox = (ToolBox*)pWindow; 525cdf0e10cSrcweir if ( pToolBox ) 526cdf0e10cSrcweir { 527cdf0e10cSrcweir sal_uInt16 nItemCount = pToolBox->GetItemCount(); 528cdf0e10cSrcweir for ( sal_uInt16 i=0; i<nItemCount; ++i ) 529cdf0e10cSrcweir { 530cdf0e10cSrcweir ::rtl::OUString sItemCommand = pToolBox->GetItemCommand(i); 531cdf0e10cSrcweir if ( sItemCommand.equals( COMMAND_FINDTEXT ) ) 532cdf0e10cSrcweir { 533cdf0e10cSrcweir Window* pItemWin = pToolBox->GetItemWindow(i); 534cdf0e10cSrcweir if (pItemWin) 535cdf0e10cSrcweir sFindText = pItemWin->GetText(); 536cdf0e10cSrcweir break; 537cdf0e10cSrcweir } 538cdf0e10cSrcweir } 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > lArgs(2); 542cdf0e10cSrcweir lArgs[0].Name = SEARCHITEM_SEARCHSTRING; 543cdf0e10cSrcweir lArgs[0].Value <<= sFindText; 544cdf0e10cSrcweir lArgs[1].Name = SEARCHITEM_SEARCHBACKWARD; 545cdf0e10cSrcweir lArgs[1].Value <<= sal_False; 546cdf0e10cSrcweir 547cdf0e10cSrcweir impl_executeSearch(m_xServiceManager, m_xFrame, lArgs); 548cdf0e10cSrcweir 549cdf0e10cSrcweir css::frame::FeatureStateEvent aEvent; 550cdf0e10cSrcweir aEvent.FeatureURL.Complete = COMMAND_APPENDSEARCHHISTORY; 551cdf0e10cSrcweir css::uno::Reference< css::frame::XStatusListener > xStatusListener = SearchToolbarControllersManager::createControllersManager()->findController(m_xFrame, COMMAND_FINDTEXT); 552cdf0e10cSrcweir if (xStatusListener.is()) 553cdf0e10cSrcweir xStatusListener->statusChanged( aEvent ); 554cdf0e10cSrcweir } 555cdf0e10cSrcweir 556cdf0e10cSrcweir // XStatusListener 557cdf0e10cSrcweir void SAL_CALL DownSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ ) throw ( css::uno::RuntimeException ) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 560cdf0e10cSrcweir if ( m_bDisposed ) 561cdf0e10cSrcweir return; 562cdf0e10cSrcweir } 563cdf0e10cSrcweir 564cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------- 565cdf0e10cSrcweir // class UpSearchToolboxController 566cdf0e10cSrcweir 567cdf0e10cSrcweir UpSearchToolboxController::UpSearchToolboxController( const css::uno::Reference< css::lang::XMultiServiceFactory > & rServiceManager ) 568cdf0e10cSrcweir :svt::ToolboxController( rServiceManager, 569cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame >(), 570cdf0e10cSrcweir COMMAND_UPSEARCH ) 571cdf0e10cSrcweir { 572cdf0e10cSrcweir } 573cdf0e10cSrcweir 574cdf0e10cSrcweir UpSearchToolboxController::~UpSearchToolboxController() 575cdf0e10cSrcweir { 576cdf0e10cSrcweir } 577cdf0e10cSrcweir 578cdf0e10cSrcweir // XInterface 579cdf0e10cSrcweir css::uno::Any SAL_CALL UpSearchToolboxController::queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException ) 580cdf0e10cSrcweir { 581cdf0e10cSrcweir css::uno::Any a = ToolboxController::queryInterface( aType ); 582cdf0e10cSrcweir if ( a.hasValue() ) 583cdf0e10cSrcweir return a; 584cdf0e10cSrcweir 585cdf0e10cSrcweir return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) ); 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir void SAL_CALL UpSearchToolboxController::acquire() throw () 589cdf0e10cSrcweir { 590cdf0e10cSrcweir ToolboxController::acquire(); 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir void SAL_CALL UpSearchToolboxController::release() throw () 594cdf0e10cSrcweir { 595cdf0e10cSrcweir ToolboxController::release(); 596cdf0e10cSrcweir } 597cdf0e10cSrcweir 598cdf0e10cSrcweir // XServiceInfo 599cdf0e10cSrcweir ::rtl::OUString SAL_CALL UpSearchToolboxController::getImplementationName() throw( css::uno::RuntimeException ) 600cdf0e10cSrcweir { 601cdf0e10cSrcweir return getImplementationName_Static(); 602cdf0e10cSrcweir } 603cdf0e10cSrcweir 604cdf0e10cSrcweir sal_Bool SAL_CALL UpSearchToolboxController::supportsService( const ::rtl::OUString& ServiceName ) throw( css::uno::RuntimeException ) 605cdf0e10cSrcweir { 606cdf0e10cSrcweir const css::uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() ); 607cdf0e10cSrcweir const ::rtl::OUString * pArray = aSNL.getConstArray(); 608cdf0e10cSrcweir 609cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) 610cdf0e10cSrcweir if( pArray[i] == ServiceName ) 611cdf0e10cSrcweir return true; 612cdf0e10cSrcweir 613cdf0e10cSrcweir return false; 614cdf0e10cSrcweir } 615cdf0e10cSrcweir 616cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL UpSearchToolboxController::getSupportedServiceNames() throw( css::uno::RuntimeException ) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir return getSupportedServiceNames_Static(); 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > UpSearchToolboxController::getSupportedServiceNames_Static() throw() 622cdf0e10cSrcweir { 623cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > aSNS( 1 ); 624cdf0e10cSrcweir aSNS.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ) ); 625cdf0e10cSrcweir return aSNS; 626cdf0e10cSrcweir } 627cdf0e10cSrcweir 628cdf0e10cSrcweir // XComponent 629cdf0e10cSrcweir void SAL_CALL UpSearchToolboxController::dispose() throw ( css::uno::RuntimeException ) 630cdf0e10cSrcweir { 631cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 632cdf0e10cSrcweir 633cdf0e10cSrcweir SearchToolbarControllersManager::createControllersManager()->freeController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); 634cdf0e10cSrcweir 635cdf0e10cSrcweir svt::ToolboxController::dispose(); 636cdf0e10cSrcweir } 637cdf0e10cSrcweir 638cdf0e10cSrcweir // XInitialization 639cdf0e10cSrcweir void SAL_CALL UpSearchToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException ) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir svt::ToolboxController::initialize( aArguments ); 642cdf0e10cSrcweir SearchToolbarControllersManager::createControllersManager()->registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL); 643cdf0e10cSrcweir } 644cdf0e10cSrcweir 645cdf0e10cSrcweir // XToolbarController 646cdf0e10cSrcweir void SAL_CALL UpSearchToolboxController::execute( sal_Int16 /*KeyModifier*/ ) throw ( css::uno::RuntimeException ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir if ( m_bDisposed ) 649cdf0e10cSrcweir throw css::lang::DisposedException(); 650cdf0e10cSrcweir 651cdf0e10cSrcweir ::rtl::OUString sFindText; 652cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( getParent() ); 653cdf0e10cSrcweir ToolBox* pToolBox = (ToolBox*)pWindow; 654cdf0e10cSrcweir if ( pToolBox ) 655cdf0e10cSrcweir { 656cdf0e10cSrcweir sal_uInt16 nItemCount = pToolBox->GetItemCount(); 657cdf0e10cSrcweir for ( sal_uInt16 i=0; i<nItemCount; ++i ) 658cdf0e10cSrcweir { 659cdf0e10cSrcweir ::rtl::OUString sItemCommand = pToolBox->GetItemCommand(i); 660cdf0e10cSrcweir if ( sItemCommand.equals( COMMAND_FINDTEXT ) ) 661cdf0e10cSrcweir { 662cdf0e10cSrcweir Window* pItemWin = pToolBox->GetItemWindow(i); 663cdf0e10cSrcweir if (pItemWin) 664cdf0e10cSrcweir sFindText = pItemWin->GetText(); 665cdf0e10cSrcweir break; 666cdf0e10cSrcweir } 667cdf0e10cSrcweir } 668cdf0e10cSrcweir } 669cdf0e10cSrcweir 670cdf0e10cSrcweir css::uno::Sequence< css::beans::PropertyValue > lArgs(2); 671cdf0e10cSrcweir lArgs[0].Name = SEARCHITEM_SEARCHSTRING; 672cdf0e10cSrcweir lArgs[0].Value <<= sFindText; 673cdf0e10cSrcweir lArgs[1].Name = SEARCHITEM_SEARCHBACKWARD; 674cdf0e10cSrcweir lArgs[1].Value <<= sal_True; 675cdf0e10cSrcweir 676cdf0e10cSrcweir impl_executeSearch(m_xServiceManager, m_xFrame, lArgs); 677cdf0e10cSrcweir 678cdf0e10cSrcweir css::frame::FeatureStateEvent aEvent; 679cdf0e10cSrcweir aEvent.FeatureURL.Complete = COMMAND_APPENDSEARCHHISTORY; 680cdf0e10cSrcweir css::uno::Reference< css::frame::XStatusListener > xStatusListener = SearchToolbarControllersManager::createControllersManager()->findController(m_xFrame, COMMAND_FINDTEXT); 681cdf0e10cSrcweir if (xStatusListener.is()) 682cdf0e10cSrcweir xStatusListener->statusChanged( aEvent ); 683cdf0e10cSrcweir } 684cdf0e10cSrcweir 685cdf0e10cSrcweir // XStatusListener 686cdf0e10cSrcweir void SAL_CALL UpSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ ) throw ( css::uno::RuntimeException ) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 689cdf0e10cSrcweir if ( m_bDisposed ) 690cdf0e10cSrcweir return; 691cdf0e10cSrcweir } 692cdf0e10cSrcweir 693cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------- 694cdf0e10cSrcweir // class FindbarDispatcher 695cdf0e10cSrcweir 696cdf0e10cSrcweir FindbarDispatcher::FindbarDispatcher(const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory) 697cdf0e10cSrcweir : m_xFactory( xFactory ) 698cdf0e10cSrcweir { 699cdf0e10cSrcweir } 700cdf0e10cSrcweir 701cdf0e10cSrcweir FindbarDispatcher::~FindbarDispatcher() 702cdf0e10cSrcweir { 703cdf0e10cSrcweir m_xFactory = NULL; 704cdf0e10cSrcweir m_xFrame = NULL; 705cdf0e10cSrcweir } 706cdf0e10cSrcweir 707cdf0e10cSrcweir // XInterface 708cdf0e10cSrcweir css::uno::Any SAL_CALL FindbarDispatcher::queryInterface( const css::uno::Type& aType ) throw( css::uno::RuntimeException ) 709cdf0e10cSrcweir { 710cdf0e10cSrcweir css::uno::Any aReturn( ::cppu::queryInterface( aType, 711cdf0e10cSrcweir static_cast< css::lang::XServiceInfo* >(this), 712cdf0e10cSrcweir static_cast< css::lang::XInitialization* >(this), 713cdf0e10cSrcweir static_cast< css::frame::XDispatchProvider* >(this), 714cdf0e10cSrcweir static_cast< css::frame::XDispatch* >(this)) ); 715cdf0e10cSrcweir 716cdf0e10cSrcweir if ( aReturn.hasValue() ) 717cdf0e10cSrcweir return aReturn; 718cdf0e10cSrcweir 719cdf0e10cSrcweir return OWeakObject::queryInterface( aType ); 720cdf0e10cSrcweir } 721cdf0e10cSrcweir 722cdf0e10cSrcweir void SAL_CALL FindbarDispatcher::acquire() throw() 723cdf0e10cSrcweir { 724cdf0e10cSrcweir OWeakObject::acquire(); 725cdf0e10cSrcweir } 726cdf0e10cSrcweir 727cdf0e10cSrcweir void SAL_CALL FindbarDispatcher::release() throw() 728cdf0e10cSrcweir { 729cdf0e10cSrcweir OWeakObject::release(); 730cdf0e10cSrcweir } 731cdf0e10cSrcweir 732cdf0e10cSrcweir // XServiceInfo 733cdf0e10cSrcweir ::rtl::OUString SAL_CALL FindbarDispatcher::getImplementationName() throw( css::uno::RuntimeException ) 734cdf0e10cSrcweir { 735cdf0e10cSrcweir return getImplementationName_Static(); 736cdf0e10cSrcweir } 737cdf0e10cSrcweir 738cdf0e10cSrcweir sal_Bool SAL_CALL FindbarDispatcher::supportsService( const ::rtl::OUString& ServiceName ) throw( css::uno::RuntimeException ) 739cdf0e10cSrcweir { 740cdf0e10cSrcweir return ( 741cdf0e10cSrcweir ServiceName.equalsAscii("com.sun.star.comp.svx.FindbarDispatcher") || 742cdf0e10cSrcweir ServiceName.equalsAscii("com.sun.star.frame.ProtocolHandler") 743cdf0e10cSrcweir ); 744cdf0e10cSrcweir } 745cdf0e10cSrcweir 746cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL FindbarDispatcher::getSupportedServiceNames() throw( css::uno::RuntimeException ) 747cdf0e10cSrcweir { 748cdf0e10cSrcweir return getSupportedServiceNames_Static(); 749cdf0e10cSrcweir } 750cdf0e10cSrcweir 751cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > FindbarDispatcher::getSupportedServiceNames_Static() throw() 752cdf0e10cSrcweir { 753cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > aSNS( 2 ); 754cdf0e10cSrcweir aSNS.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svx.FindbarDispatcher" )); 755cdf0e10cSrcweir aSNS.getArray()[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ProtocolHandler" )); 756cdf0e10cSrcweir return aSNS; 757cdf0e10cSrcweir } 758cdf0e10cSrcweir 759cdf0e10cSrcweir // XInitialization 760cdf0e10cSrcweir void SAL_CALL FindbarDispatcher::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException ) 761cdf0e10cSrcweir { 762cdf0e10cSrcweir if ( aArguments.getLength() ) 763cdf0e10cSrcweir aArguments[0] >>= m_xFrame; 764cdf0e10cSrcweir } 765cdf0e10cSrcweir 766cdf0e10cSrcweir // XDispatchProvider 767cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > SAL_CALL FindbarDispatcher::queryDispatch( const css::util::URL& aURL, const ::rtl::OUString& /*sTargetFrameName*/, sal_Int32 /*nSearchFlags*/ ) throw( css::uno::RuntimeException ) 768cdf0e10cSrcweir { 769cdf0e10cSrcweir css::uno::Reference< css::frame::XDispatch > xDispatch; 770cdf0e10cSrcweir 771cdf0e10cSrcweir if ( aURL.Protocol.equalsAscii("vnd.sun.star.findbar:") ) 772cdf0e10cSrcweir xDispatch = this; 773cdf0e10cSrcweir 774cdf0e10cSrcweir return xDispatch; 775cdf0e10cSrcweir } 776cdf0e10cSrcweir 777cdf0e10cSrcweir css::uno::Sequence < css::uno::Reference< css::frame::XDispatch > > SAL_CALL FindbarDispatcher::queryDispatches( const css::uno::Sequence < css::frame::DispatchDescriptor >& seqDescripts ) throw( css::uno::RuntimeException ) 778cdf0e10cSrcweir { 779cdf0e10cSrcweir sal_Int32 nCount = seqDescripts.getLength(); 780cdf0e10cSrcweir css::uno::Sequence < css::uno::Reference < XDispatch > > lDispatcher( nCount ); 781cdf0e10cSrcweir 782cdf0e10cSrcweir for( sal_Int32 i=0; i<nCount; ++i ) 783cdf0e10cSrcweir lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags ); 784cdf0e10cSrcweir 785cdf0e10cSrcweir return lDispatcher; 786cdf0e10cSrcweir } 787cdf0e10cSrcweir 788cdf0e10cSrcweir // XDispatch 789cdf0e10cSrcweir void SAL_CALL FindbarDispatcher::dispatch( const css::util::URL& aURL, const css::uno::Sequence < css::beans::PropertyValue >& /*lArgs*/ ) throw( css::uno::RuntimeException ) 790cdf0e10cSrcweir { 791cdf0e10cSrcweir //vnd.sun.star.findbar:FocusToFindbar - set cursor to the FindTextFieldControl of the findbar 792cdf0e10cSrcweir if ( aURL.Path.equalsAscii("FocusToFindbar") ) 793cdf0e10cSrcweir { 794cdf0e10cSrcweir css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY); 795cdf0e10cSrcweir if(!xPropSet.is()) 796cdf0e10cSrcweir return; 797cdf0e10cSrcweir 798cdf0e10cSrcweir css::uno::Reference< css::frame::XLayoutManager > xLayoutManager; 799cdf0e10cSrcweir css::uno::Any aValue = xPropSet->getPropertyValue( ::rtl::OUString::createFromAscii("LayoutManager") ); 800cdf0e10cSrcweir aValue >>= xLayoutManager; 801cdf0e10cSrcweir if (!xLayoutManager.is()) 802cdf0e10cSrcweir return; 803cdf0e10cSrcweir 804cdf0e10cSrcweir const ::rtl::OUString sResourceURL = ::rtl::OUString::createFromAscii("private:resource/toolbar/findbar"); 805cdf0e10cSrcweir css::uno::Reference< css::ui::XUIElement > xUIElement = xLayoutManager->getElement(sResourceURL); 806cdf0e10cSrcweir if (!xUIElement.is()) 807cdf0e10cSrcweir return; 808cdf0e10cSrcweir 809cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xWindow(xUIElement->getRealInterface(), css::uno::UNO_QUERY); 810cdf0e10cSrcweir Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); 811cdf0e10cSrcweir ToolBox* pToolBox = (ToolBox*)pWindow; 812cdf0e10cSrcweir if ( pToolBox ) 813cdf0e10cSrcweir { 814cdf0e10cSrcweir sal_uInt16 nItemCount = pToolBox->GetItemCount(); 815cdf0e10cSrcweir for ( sal_uInt16 i=0; i<nItemCount; ++i ) 816cdf0e10cSrcweir { 817cdf0e10cSrcweir ::rtl::OUString sItemCommand = pToolBox->GetItemCommand(i); 818cdf0e10cSrcweir if ( sItemCommand.equalsAscii(".uno:FindText") ) 819cdf0e10cSrcweir { 820cdf0e10cSrcweir Window* pItemWin = pToolBox->GetItemWindow( i ); 821cdf0e10cSrcweir if ( pItemWin ) 822cdf0e10cSrcweir { 823cdf0e10cSrcweir pItemWin->GrabFocus(); 824cdf0e10cSrcweir return; 825cdf0e10cSrcweir } 826cdf0e10cSrcweir } 827cdf0e10cSrcweir } 828cdf0e10cSrcweir } 829cdf0e10cSrcweir 830cdf0e10cSrcweir } 831cdf0e10cSrcweir } 832cdf0e10cSrcweir 833cdf0e10cSrcweir void SAL_CALL FindbarDispatcher::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xControl*/, const css::util::URL& /*aURL*/ ) throw ( css::uno::RuntimeException ) 834cdf0e10cSrcweir { 835cdf0e10cSrcweir } 836cdf0e10cSrcweir 837cdf0e10cSrcweir void SAL_CALL FindbarDispatcher::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xControl*/, const css::util::URL& /*aURL*/ ) throw ( css::uno::RuntimeException ) 838cdf0e10cSrcweir { 839cdf0e10cSrcweir } 840cdf0e10cSrcweir 841cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------- 842cdf0e10cSrcweir // create Instance 843cdf0e10cSrcweir 844cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL FindTextToolbarController_createInstance( 845cdf0e10cSrcweir const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr ) 846cdf0e10cSrcweir { 847cdf0e10cSrcweir return *new FindTextToolbarController( rSMgr ); 848cdf0e10cSrcweir } 849cdf0e10cSrcweir 850cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL DownSearchToolboxController_createInstance( 851cdf0e10cSrcweir const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr ) 852cdf0e10cSrcweir { 853cdf0e10cSrcweir return *new DownSearchToolboxController( rSMgr ); 854cdf0e10cSrcweir } 855cdf0e10cSrcweir 856cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL UpSearchToolboxController_createInstance( 857cdf0e10cSrcweir const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr ) 858cdf0e10cSrcweir { 859cdf0e10cSrcweir return *new UpSearchToolboxController( rSMgr ); 860cdf0e10cSrcweir } 861cdf0e10cSrcweir 862cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL FindbarDispatcher_createInstance( 863cdf0e10cSrcweir const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr ) 864cdf0e10cSrcweir { 865cdf0e10cSrcweir return *new FindbarDispatcher( rSMgr ); 866cdf0e10cSrcweir } 867cdf0e10cSrcweir 868cdf0e10cSrcweir //----------------------------------------------------------------------------------------------------------- 869cdf0e10cSrcweir } 870