Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "tbunosearchcontrollers.hxx"
21 :
22 : #include <svx/dialogs.hrc>
23 : #include <svx/dialmgr.hxx>
24 :
25 : #include <comphelper/processfactory.hxx>
26 : #include <com/sun/star/beans/XPropertySet.hpp>
27 : #include <com/sun/star/frame/XLayoutManager.hpp>
28 : #include <com/sun/star/i18n/TransliterationModules.hpp>
29 : #include <com/sun/star/i18n/TransliterationModulesExtra.hpp>
30 : #include <com/sun/star/text/XTextRange.hpp>
31 : #include <com/sun/star/ui/XUIElement.hpp>
32 : #include <com/sun/star/util/URL.hpp>
33 : #include <com/sun/star/util/URLTransformer.hpp>
34 :
35 : #include <svl/ctloptions.hxx>
36 : #include <svl/srchitem.hxx>
37 : #include <toolkit/helper/vclunohelper.hxx>
38 : #include <vcl/toolbox.hxx>
39 : #include <vcl/svapp.hxx>
40 : #include <osl/mutex.hxx>
41 : #include <rtl/instance.hxx>
42 :
43 : namespace svx
44 : {
45 :
46 : static const char SEARCHITEM_COMMAND[] = "SearchItem.Command";
47 : static const char SEARCHITEM_SEARCHSTRING[] = "SearchItem.SearchString";
48 : static const char SEARCHITEM_SEARCHBACKWARD[] = "SearchItem.Backward";
49 : static const char SEARCHITEM_SEARCHFLAGS[] = "SearchItem.SearchFlags";
50 : static const char SEARCHITEM_TRANSLITERATEFLAGS[] = "SearchItem.TransliterateFlags";
51 : static const char SEARCHITEM_ALGORITHMTYPE[] = "SearchItem.AlgorithmType";
52 :
53 : static const char COMMAND_EXECUTESEARCH[] = ".uno:ExecuteSearch";
54 : static const char COMMAND_FINDTEXT[] = ".uno:FindText";
55 : static const char COMMAND_DOWNSEARCH[] = ".uno:DownSearch";
56 : static const char COMMAND_UPSEARCH[] = ".uno:UpSearch";
57 : static const char COMMAND_EXITSEARCH[] = ".uno:ExitSearch";
58 : static const char COMMAND_MATCHCASE[] = ".uno:MatchCase";
59 : static const char COMMAND_APPENDSEARCHHISTORY[] = "AppendSearchHistory";
60 :
61 : static const sal_Int32 REMEMBER_SIZE = 10;
62 :
63 0 : void impl_executeSearch( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
64 : const css::uno::Reference< css::frame::XFrame >& xFrame,
65 : const ToolBox* pToolBox,
66 : const sal_Bool aSearchBackwards = false,
67 : const sal_Bool aFindAll = false )
68 : {
69 0 : css::uno::Reference< css::util::XURLTransformer > xURLTransformer( css::util::URLTransformer::create( rxContext ) );
70 0 : css::util::URL aURL;
71 0 : aURL.Complete = OUString(COMMAND_EXECUTESEARCH);
72 0 : xURLTransformer->parseStrict(aURL);
73 :
74 0 : OUString sFindText;
75 0 : sal_Bool aMatchCase = false;
76 0 : if ( pToolBox )
77 : {
78 0 : sal_uInt16 nItemCount = pToolBox->GetItemCount();
79 0 : for ( sal_uInt16 i=0; i<nItemCount; ++i )
80 : {
81 0 : OUString sItemCommand = pToolBox->GetItemCommand(i);
82 0 : if ( sItemCommand == COMMAND_FINDTEXT )
83 : {
84 0 : Window* pItemWin = pToolBox->GetItemWindow(i);
85 0 : if (pItemWin)
86 0 : sFindText = pItemWin->GetText();
87 0 : } else if ( sItemCommand == COMMAND_MATCHCASE )
88 : {
89 0 : CheckBox* pItemWin = (CheckBox*) pToolBox->GetItemWindow(i);
90 0 : if (pItemWin)
91 0 : aMatchCase = pItemWin->IsChecked();
92 : }
93 0 : }
94 : }
95 :
96 0 : css::uno::Sequence< css::beans::PropertyValue > lArgs(6);
97 0 : lArgs[0].Name = OUString(SEARCHITEM_SEARCHSTRING);
98 0 : lArgs[0].Value <<= sFindText;
99 0 : lArgs[1].Name = OUString(SEARCHITEM_SEARCHBACKWARD);
100 0 : lArgs[1].Value <<= aSearchBackwards;
101 0 : lArgs[2].Name = OUString(SEARCHITEM_SEARCHFLAGS);
102 0 : lArgs[2].Value <<= (sal_Int32)0;
103 0 : lArgs[3].Name = OUString(SEARCHITEM_TRANSLITERATEFLAGS);
104 0 : SvtCTLOptions aCTLOptions;
105 0 : sal_Int32 nFlags = 0;
106 0 : nFlags |= (!aMatchCase ? com::sun::star::i18n::TransliterationModules_IGNORE_CASE : 0);
107 0 : nFlags |= (aCTLOptions.IsCTLFontEnabled() ? com::sun::star::i18n::TransliterationModulesExtra::ignoreDiacritics_CTL:0 );
108 0 : lArgs[3].Value <<= nFlags;
109 0 : lArgs[4].Name = OUString(SEARCHITEM_COMMAND);
110 0 : lArgs[4].Value <<= (sal_Int16)(aFindAll ?
111 0 : SVX_SEARCHCMD_FIND_ALL : SVX_SEARCHCMD_FIND );
112 0 : lArgs[5].Name = OUString(SEARCHITEM_ALGORITHMTYPE);
113 0 : lArgs[5].Value <<= (sal_Int16)0; // 0 == SearchAlgorithms_ABSOLUTE
114 :
115 0 : css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider(xFrame, css::uno::UNO_QUERY);
116 0 : if ( xDispatchProvider.is() )
117 : {
118 0 : css::uno::Reference< css::frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
119 0 : if ( xDispatch.is() && !aURL.Complete.isEmpty() )
120 0 : xDispatch->dispatch( aURL, lArgs );
121 0 : }
122 0 : }
123 :
124 0 : FindTextFieldControl::FindTextFieldControl( Window* pParent, WinBits nStyle,
125 : css::uno::Reference< css::frame::XFrame >& xFrame,
126 : const css::uno::Reference< css::uno::XComponentContext >& xContext) :
127 : ComboBox( pParent, nStyle ),
128 : m_xFrame(xFrame),
129 0 : m_xContext(xContext)
130 : {
131 0 : SetPlaceholderText(SVX_RESSTR(RID_SVXSTR_FINDBAR_FIND));
132 0 : EnableAutocomplete(sal_True, sal_True);
133 0 : }
134 :
135 0 : FindTextFieldControl::~FindTextFieldControl()
136 : {
137 0 : }
138 :
139 0 : void FindTextFieldControl::Remember_Impl(const String& rStr)
140 : {
141 0 : sal_uInt16 nCount = GetEntryCount();
142 :
143 0 : for (sal_uInt16 i=0; i<nCount; ++i)
144 : {
145 0 : if ( rStr == GetEntry(i))
146 0 : return;
147 : }
148 :
149 0 : if (nCount == REMEMBER_SIZE)
150 0 : RemoveEntry(REMEMBER_SIZE-1);
151 :
152 0 : InsertEntry(rStr, 0);
153 : }
154 :
155 0 : void FindTextFieldControl::SetTextToSelected_Impl()
156 : {
157 0 : OUString aString;
158 :
159 : try
160 : {
161 0 : css::uno::Reference<css::frame::XController> xController(m_xFrame->getController(), css::uno::UNO_QUERY_THROW);
162 0 : css::uno::Reference<css::frame::XModel> xModel(xController->getModel(), css::uno::UNO_QUERY_THROW);
163 0 : css::uno::Reference<css::container::XIndexAccess> xIndexAccess(xModel->getCurrentSelection(), css::uno::UNO_QUERY_THROW);
164 0 : if (xIndexAccess->getCount() > 0)
165 : {
166 0 : css::uno::Reference<css::text::XTextRange> xTextRange(xIndexAccess->getByIndex(0), css::uno::UNO_QUERY_THROW);
167 0 : aString = xTextRange->getString();
168 0 : }
169 : }
170 0 : catch ( ... )
171 : {
172 : }
173 :
174 0 : if ( !aString.isEmpty() )
175 : {
176 0 : SetText( aString );
177 0 : GetModifyHdl().Call(this); // FIXME why SetText doesn't trigger this?
178 0 : }
179 0 : }
180 :
181 0 : long FindTextFieldControl::PreNotify( NotifyEvent& rNEvt )
182 : {
183 0 : long nRet= ComboBox::PreNotify( rNEvt );
184 :
185 0 : switch ( rNEvt.GetType() )
186 : {
187 : case EVENT_KEYINPUT:
188 : {
189 0 : const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
190 0 : sal_Bool bShift = pKeyEvent->GetKeyCode().IsShift();
191 0 : sal_Bool bMod1 = pKeyEvent->GetKeyCode().IsMod1();
192 0 : sal_uInt16 nCode = pKeyEvent->GetKeyCode().GetCode();
193 :
194 0 : if ( KEY_ESCAPE == nCode || (bMod1 && (KEY_F == nCode)) )
195 : {
196 0 : nRet = 1;
197 0 : GrabFocusToDocument();
198 :
199 : // hide the findbar
200 0 : css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY);
201 0 : if (xPropSet.is())
202 : {
203 0 : css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
204 0 : css::uno::Any aValue = xPropSet->getPropertyValue("LayoutManager");
205 0 : aValue >>= xLayoutManager;
206 0 : if (xLayoutManager.is())
207 : {
208 0 : const OUString sResourceURL( "private:resource/toolbar/findbar" );
209 0 : xLayoutManager->hideElement( sResourceURL );
210 0 : xLayoutManager->destroyElement( sResourceURL );
211 0 : }
212 0 : }
213 : }
214 :
215 0 : if ( KEY_RETURN == nCode || (bMod1 && (KEY_G == nCode)) || (KEY_F3 == nCode) )
216 : {
217 0 : Remember_Impl(GetText());
218 :
219 0 : Window* pWindow = GetParent();
220 0 : ToolBox* pToolBox = (ToolBox*)pWindow;
221 :
222 0 : impl_executeSearch( m_xContext, m_xFrame, pToolBox, bShift);
223 0 : nRet = 1;
224 : }
225 0 : break;
226 : }
227 :
228 : case EVENT_GETFOCUS:
229 0 : SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
230 0 : break;
231 : }
232 :
233 0 : return nRet;
234 : }
235 :
236 :
237 : //-----------------------------------------------------------------------------------------------------------
238 : // SearchToolbarControllersManager
239 :
240 0 : SearchToolbarControllersManager::SearchToolbarControllersManager()
241 : {
242 0 : }
243 :
244 0 : SearchToolbarControllersManager::~SearchToolbarControllersManager()
245 : {
246 0 : }
247 :
248 : namespace
249 : {
250 : class theSearchToolbarControllersManager
251 : : public rtl::Static<SearchToolbarControllersManager,
252 : theSearchToolbarControllersManager>
253 : {
254 : };
255 : }
256 :
257 0 : SearchToolbarControllersManager& SearchToolbarControllersManager::createControllersManager()
258 : {
259 0 : return theSearchToolbarControllersManager::get();
260 : }
261 :
262 0 : void SearchToolbarControllersManager::saveSearchHistory(const FindTextFieldControl* pFindTextFieldControl)
263 : {
264 0 : sal_uInt16 nECount( pFindTextFieldControl->GetEntryCount() );
265 0 : m_aSearchStrings.resize( nECount );
266 0 : for( sal_uInt16 i=0; i<nECount; ++i )
267 : {
268 0 : m_aSearchStrings[i] = pFindTextFieldControl->GetEntry(i);
269 : }
270 0 : }
271 :
272 0 : void SearchToolbarControllersManager::loadSearchHistory(FindTextFieldControl* pFindTextFieldControl)
273 : {
274 0 : for( sal_uInt16 i=0; i<m_aSearchStrings.size(); ++i )
275 : {
276 0 : pFindTextFieldControl->InsertEntry(m_aSearchStrings[i],i);
277 : }
278 0 : }
279 :
280 0 : void SearchToolbarControllersManager::registryController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& xStatusListener, const OUString& sCommandURL )
281 : {
282 0 : SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame);
283 0 : if (pIt == aSearchToolbarControllersMap.end())
284 : {
285 0 : SearchToolbarControllersVec lControllers(1);
286 0 : lControllers[0].Name = sCommandURL;
287 0 : lControllers[0].Value <<= xStatusListener;
288 0 : aSearchToolbarControllersMap.insert(SearchToolbarControllersMap::value_type(xFrame, lControllers));
289 : }
290 : else
291 : {
292 0 : sal_Int32 nSize = pIt->second.size();
293 0 : for (sal_Int32 i=0; i<nSize; ++i)
294 : {
295 0 : if (pIt->second[i].Name.equals(sCommandURL))
296 0 : return;
297 : }
298 :
299 0 : pIt->second.resize(nSize+1);
300 0 : pIt->second[nSize].Name = sCommandURL;
301 0 : pIt->second[nSize].Value <<= xStatusListener;
302 : }
303 : }
304 :
305 0 : void SearchToolbarControllersManager::freeController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& /*xStatusListener*/, const OUString& sCommandURL )
306 : {
307 0 : SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame);
308 0 : if (pIt != aSearchToolbarControllersMap.end())
309 : {
310 0 : for (SearchToolbarControllersVec::iterator pItCtrl=pIt->second.begin(); pItCtrl!=pIt->second.end(); ++pItCtrl)
311 : {
312 0 : if (pItCtrl->Name.equals(sCommandURL))
313 : {
314 0 : pIt->second.erase(pItCtrl);
315 0 : break;
316 : }
317 : }
318 :
319 0 : if (pIt->second.empty())
320 0 : aSearchToolbarControllersMap.erase(pIt);
321 : }
322 0 : }
323 :
324 0 : css::uno::Reference< css::frame::XStatusListener > SearchToolbarControllersManager::findController( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL )
325 : {
326 0 : css::uno::Reference< css::frame::XStatusListener > xStatusListener;
327 :
328 0 : SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame);
329 0 : if (pIt != aSearchToolbarControllersMap.end())
330 : {
331 0 : for (SearchToolbarControllersVec::iterator pItCtrl =pIt->second.begin(); pItCtrl != pIt->second.end(); ++pItCtrl)
332 : {
333 0 : if (pItCtrl->Name.equals(sCommandURL))
334 : {
335 0 : pItCtrl->Value >>= xStatusListener;
336 0 : break;
337 : }
338 : }
339 : }
340 :
341 0 : return xStatusListener;
342 : }
343 :
344 : //-----------------------------------------------------------------------------------------------------------
345 : // FindTextToolbarController
346 :
347 0 : FindTextToolbarController::FindTextToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
348 : :svt::ToolboxController( rxContext,
349 : css::uno::Reference< css::frame::XFrame >(),
350 0 : OUString(COMMAND_FINDTEXT) )
351 : {
352 0 : }
353 :
354 0 : FindTextToolbarController::~FindTextToolbarController()
355 : {
356 0 : }
357 :
358 : // XInterface
359 0 : css::uno::Any SAL_CALL FindTextToolbarController::queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException )
360 : {
361 0 : css::uno::Any a = ToolboxController::queryInterface( aType );
362 0 : if ( a.hasValue() )
363 0 : return a;
364 :
365 0 : return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) );
366 : }
367 :
368 0 : void SAL_CALL FindTextToolbarController::acquire() throw ()
369 : {
370 0 : ToolboxController::acquire();
371 0 : }
372 :
373 0 : void SAL_CALL FindTextToolbarController::release() throw ()
374 : {
375 0 : ToolboxController::release();
376 0 : }
377 :
378 : // XServiceInfo
379 0 : OUString SAL_CALL FindTextToolbarController::getImplementationName() throw( css::uno::RuntimeException )
380 : {
381 0 : return getImplementationName_Static();
382 : }
383 :
384 0 : sal_Bool SAL_CALL FindTextToolbarController::supportsService( const OUString& ServiceName ) throw( css::uno::RuntimeException )
385 : {
386 0 : const css::uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
387 0 : const OUString * pArray = aSNL.getConstArray();
388 :
389 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
390 0 : if( pArray[i] == ServiceName )
391 0 : return true;
392 :
393 0 : return false;
394 : }
395 :
396 0 : css::uno::Sequence< OUString > SAL_CALL FindTextToolbarController::getSupportedServiceNames() throw( css::uno::RuntimeException )
397 : {
398 0 : return getSupportedServiceNames_Static();
399 : }
400 :
401 0 : css::uno::Sequence< OUString > FindTextToolbarController::getSupportedServiceNames_Static() throw()
402 : {
403 0 : css::uno::Sequence< OUString > aSNS( 1 );
404 0 : aSNS.getArray()[0] = OUString( "com.sun.star.frame.ToolbarController" );
405 0 : return aSNS;
406 : }
407 :
408 : // XComponent
409 0 : void SAL_CALL FindTextToolbarController::dispose() throw ( css::uno::RuntimeException )
410 : {
411 0 : SolarMutexGuard aSolarMutexGuard;
412 :
413 0 : SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL);
414 :
415 0 : svt::ToolboxController::dispose();
416 0 : SearchToolbarControllersManager::createControllersManager().saveSearchHistory(m_pFindTextFieldControl);
417 0 : delete m_pFindTextFieldControl;
418 0 : m_pFindTextFieldControl = 0;
419 0 : }
420 :
421 : // XInitialization
422 0 : void SAL_CALL FindTextToolbarController::initialize( const css::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException)
423 : {
424 0 : svt::ToolboxController::initialize(aArguments);
425 :
426 0 : Window* pWindow = VCLUnoHelper::GetWindow( getParent() );
427 0 : ToolBox* pToolBox = (ToolBox*)pWindow;
428 0 : if ( pToolBox )
429 : {
430 0 : sal_uInt16 nItemCount = pToolBox->GetItemCount();
431 0 : for ( sal_uInt16 i=0; i<nItemCount; ++i )
432 : {
433 0 : OUString sItemCommand = pToolBox->GetItemCommand(i);
434 0 : if ( sItemCommand == COMMAND_DOWNSEARCH )
435 : {
436 0 : pToolBox->EnableItem(i, sal_False);
437 0 : m_nDownSearchId = i;
438 : }
439 0 : else if ( sItemCommand == COMMAND_UPSEARCH )
440 : {
441 0 : pToolBox->EnableItem(i, sal_False);
442 0 : m_nUpSearchId = i;
443 : }
444 0 : }
445 : }
446 :
447 0 : SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL);
448 0 : }
449 :
450 : // XToolbarController
451 0 : void SAL_CALL FindTextToolbarController::execute( sal_Int16 /*KeyModifier*/ ) throw ( css::uno::RuntimeException )
452 : {
453 0 : }
454 :
455 0 : css::uno::Reference< css::awt::XWindow > SAL_CALL FindTextToolbarController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) throw ( css::uno::RuntimeException )
456 : {
457 0 : css::uno::Reference< css::awt::XWindow > xItemWindow;
458 :
459 0 : css::uno::Reference< css::awt::XWindow > xParent( Parent );
460 0 : Window* pParent = VCLUnoHelper::GetWindow( xParent );
461 0 : if ( pParent )
462 : {
463 0 : ToolBox* pToolbar = ( ToolBox* )pParent;
464 0 : m_pFindTextFieldControl = new FindTextFieldControl( pToolbar, WinBits( WB_DROPDOWN | WB_VSCROLL), m_xFrame, m_xContext );
465 :
466 0 : Size aSize(250, m_pFindTextFieldControl->GetTextHeight() + 200);
467 0 : m_pFindTextFieldControl->SetSizePixel( aSize );
468 0 : m_pFindTextFieldControl->SetModifyHdl(LINK(this, FindTextToolbarController, EditModifyHdl));
469 0 : SearchToolbarControllersManager::createControllersManager().loadSearchHistory(m_pFindTextFieldControl);
470 : }
471 0 : xItemWindow = VCLUnoHelper::GetInterface( m_pFindTextFieldControl );
472 :
473 0 : return xItemWindow;
474 : }
475 :
476 : // XStatusListener
477 0 : void SAL_CALL FindTextToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException )
478 : {
479 0 : SolarMutexGuard aSolarMutexGuard;
480 0 : if ( m_bDisposed )
481 0 : return;
482 :
483 0 : OUString aFeatureURL = rEvent.FeatureURL.Complete;
484 0 : if ( aFeatureURL == "AppendSearchHistory" )
485 : {
486 0 : m_pFindTextFieldControl->Remember_Impl(m_pFindTextFieldControl->GetText());
487 0 : }
488 : }
489 :
490 0 : IMPL_LINK_NOARG(FindTextToolbarController, EditModifyHdl)
491 : {
492 : // enable or disable item DownSearch/UpSearch of findbar
493 0 : Window* pWindow = VCLUnoHelper::GetWindow( getParent() );
494 0 : ToolBox* pToolBox = (ToolBox*)pWindow;
495 0 : if ( pToolBox && m_pFindTextFieldControl )
496 : {
497 0 : if (!m_pFindTextFieldControl->GetText().isEmpty())
498 : {
499 0 : if ( !pToolBox->IsItemEnabled(m_nDownSearchId) )
500 0 : pToolBox->EnableItem(m_nDownSearchId, sal_True);
501 0 : if ( !pToolBox->IsItemEnabled(m_nUpSearchId) )
502 0 : pToolBox->EnableItem(m_nUpSearchId, sal_True);
503 : }
504 : else
505 : {
506 0 : if ( pToolBox->IsItemEnabled(m_nDownSearchId) )
507 0 : pToolBox->EnableItem(m_nDownSearchId, sal_False);
508 0 : if ( pToolBox->IsItemEnabled(m_nUpSearchId) )
509 0 : pToolBox->EnableItem(m_nUpSearchId, sal_False);
510 : }
511 : }
512 :
513 0 : return 0;
514 : }
515 :
516 : //-----------------------------------------------------------------------------------------------------------
517 : // class UpDownSearchToolboxController
518 :
519 0 : UpDownSearchToolboxController::UpDownSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext, Type eType )
520 : : svt::ToolboxController( rxContext,
521 : css::uno::Reference< css::frame::XFrame >(),
522 : (eType == UP) ? OUString( COMMAND_UPSEARCH ): OUString( COMMAND_DOWNSEARCH ) ),
523 0 : meType( eType )
524 : {
525 0 : }
526 :
527 0 : UpDownSearchToolboxController::~UpDownSearchToolboxController()
528 : {
529 0 : }
530 :
531 : // XInterface
532 0 : css::uno::Any SAL_CALL UpDownSearchToolboxController::queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException )
533 : {
534 0 : css::uno::Any a = ToolboxController::queryInterface( aType );
535 0 : if ( a.hasValue() )
536 0 : return a;
537 :
538 0 : return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) );
539 : }
540 :
541 0 : void SAL_CALL UpDownSearchToolboxController::acquire() throw ()
542 : {
543 0 : ToolboxController::acquire();
544 0 : }
545 :
546 0 : void SAL_CALL UpDownSearchToolboxController::release() throw ()
547 : {
548 0 : ToolboxController::release();
549 0 : }
550 :
551 : // XServiceInfo
552 0 : OUString SAL_CALL UpDownSearchToolboxController::getImplementationName() throw( css::uno::RuntimeException )
553 : {
554 0 : return getImplementationName_Static( meType );
555 : }
556 :
557 0 : sal_Bool SAL_CALL UpDownSearchToolboxController::supportsService( const OUString& ServiceName ) throw( css::uno::RuntimeException )
558 : {
559 0 : const css::uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
560 0 : const OUString * pArray = aSNL.getConstArray();
561 :
562 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
563 0 : if( pArray[i] == ServiceName )
564 0 : return true;
565 :
566 0 : return false;
567 : }
568 :
569 0 : css::uno::Sequence< OUString > SAL_CALL UpDownSearchToolboxController::getSupportedServiceNames() throw( css::uno::RuntimeException )
570 : {
571 0 : return getSupportedServiceNames_Static();
572 : }
573 :
574 0 : css::uno::Sequence< OUString > UpDownSearchToolboxController::getSupportedServiceNames_Static() throw()
575 : {
576 0 : css::uno::Sequence< OUString > aSNS( 1 );
577 0 : aSNS.getArray()[0] = OUString("com.sun.star.frame.ToolbarController");
578 0 : return aSNS;
579 : }
580 :
581 : // XComponent
582 0 : void SAL_CALL UpDownSearchToolboxController::dispose() throw ( css::uno::RuntimeException )
583 : {
584 0 : SolarMutexGuard aSolarMutexGuard;
585 :
586 0 : SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL);
587 :
588 0 : svt::ToolboxController::dispose();
589 0 : }
590 :
591 : // XInitialization
592 0 : void SAL_CALL UpDownSearchToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException )
593 : {
594 0 : svt::ToolboxController::initialize( aArguments );
595 0 : SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL);
596 0 : }
597 :
598 : // XToolbarController
599 0 : void SAL_CALL UpDownSearchToolboxController::execute( sal_Int16 /*KeyModifier*/ ) throw ( css::uno::RuntimeException )
600 : {
601 0 : if ( m_bDisposed )
602 0 : throw css::lang::DisposedException();
603 :
604 0 : Window* pWindow = VCLUnoHelper::GetWindow( getParent() );
605 0 : ToolBox* pToolBox = (ToolBox*)pWindow;
606 :
607 0 : impl_executeSearch(m_xContext, m_xFrame, pToolBox, sal_Bool( meType == UP ));
608 :
609 0 : css::frame::FeatureStateEvent aEvent;
610 0 : aEvent.FeatureURL.Complete = OUString(COMMAND_APPENDSEARCHHISTORY);
611 0 : css::uno::Reference< css::frame::XStatusListener > xStatusListener = SearchToolbarControllersManager::createControllersManager().findController(m_xFrame, COMMAND_FINDTEXT);
612 0 : if (xStatusListener.is())
613 0 : xStatusListener->statusChanged( aEvent );
614 0 : }
615 :
616 : // XStatusListener
617 0 : void SAL_CALL UpDownSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ ) throw ( css::uno::RuntimeException )
618 : {
619 0 : SolarMutexGuard aSolarMutexGuard;
620 0 : if ( m_bDisposed )
621 0 : return;
622 : }
623 :
624 : //-----------------------------------------------------------------------------------------------------------
625 : // MatchCaseToolboxController
626 :
627 0 : MatchCaseToolboxController::MatchCaseToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
628 : :svt::ToolboxController( rxContext,
629 : css::uno::Reference< css::frame::XFrame >(),
630 0 : OUString(COMMAND_MATCHCASE) )
631 : {
632 0 : }
633 :
634 0 : MatchCaseToolboxController::~MatchCaseToolboxController()
635 : {
636 0 : }
637 :
638 : // XInterface
639 0 : css::uno::Any SAL_CALL MatchCaseToolboxController::queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException )
640 : {
641 0 : css::uno::Any a = ToolboxController::queryInterface( aType );
642 0 : if ( a.hasValue() )
643 0 : return a;
644 :
645 0 : return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) );
646 : }
647 :
648 0 : void SAL_CALL MatchCaseToolboxController::acquire() throw ()
649 : {
650 0 : ToolboxController::acquire();
651 0 : }
652 :
653 0 : void SAL_CALL MatchCaseToolboxController::release() throw ()
654 : {
655 0 : ToolboxController::release();
656 0 : }
657 :
658 : // XServiceInfo
659 0 : OUString SAL_CALL MatchCaseToolboxController::getImplementationName() throw( css::uno::RuntimeException )
660 : {
661 0 : return getImplementationName_Static();
662 : }
663 :
664 0 : sal_Bool SAL_CALL MatchCaseToolboxController::supportsService( const OUString& ServiceName ) throw( css::uno::RuntimeException )
665 : {
666 0 : const css::uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
667 0 : const OUString * pArray = aSNL.getConstArray();
668 :
669 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
670 0 : if( pArray[i] == ServiceName )
671 0 : return true;
672 :
673 0 : return false;
674 : }
675 :
676 0 : css::uno::Sequence< OUString > SAL_CALL MatchCaseToolboxController::getSupportedServiceNames() throw( css::uno::RuntimeException )
677 : {
678 0 : return getSupportedServiceNames_Static();
679 : }
680 :
681 0 : css::uno::Sequence< OUString > MatchCaseToolboxController::getSupportedServiceNames_Static() throw()
682 : {
683 0 : css::uno::Sequence< OUString > aSNS( 1 );
684 0 : aSNS.getArray()[0] = OUString( "com.sun.star.frame.ToolbarController" );
685 0 : return aSNS;
686 : }
687 :
688 : // XComponent
689 0 : void SAL_CALL MatchCaseToolboxController::dispose() throw ( css::uno::RuntimeException )
690 : {
691 0 : SolarMutexGuard aSolarMutexGuard;
692 :
693 0 : SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL);
694 :
695 0 : svt::ToolboxController::dispose();
696 :
697 0 : delete m_pMatchCaseControl;
698 0 : m_pMatchCaseControl = 0;
699 0 : }
700 :
701 : // XInitialization
702 0 : void SAL_CALL MatchCaseToolboxController::initialize( const css::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException)
703 : {
704 0 : svt::ToolboxController::initialize(aArguments);
705 :
706 0 : SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL);
707 0 : }
708 :
709 : // XToolbarController
710 0 : void SAL_CALL MatchCaseToolboxController::execute( sal_Int16 /*KeyModifier*/ ) throw ( css::uno::RuntimeException )
711 : {
712 0 : }
713 :
714 0 : css::uno::Reference< css::awt::XWindow > SAL_CALL MatchCaseToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) throw ( css::uno::RuntimeException )
715 : {
716 0 : css::uno::Reference< css::awt::XWindow > xItemWindow;
717 :
718 0 : css::uno::Reference< css::awt::XWindow > xParent( Parent );
719 0 : Window* pParent = VCLUnoHelper::GetWindow( xParent );
720 0 : if ( pParent )
721 : {
722 0 : ToolBox* pToolbar = (ToolBox* )pParent;
723 0 : m_pMatchCaseControl = new CheckBox( pToolbar, 0 );
724 0 : m_pMatchCaseControl->SetText( SVX_RESSTR( RID_SVXSTR_FINDBAR_MATCHCASE ) );
725 0 : Size aSize( m_pMatchCaseControl->GetOptimalSize() );
726 0 : m_pMatchCaseControl->SetSizePixel( aSize );
727 : }
728 0 : xItemWindow = VCLUnoHelper::GetInterface( m_pMatchCaseControl );
729 :
730 0 : return xItemWindow;
731 : }
732 :
733 : // XStatusListener
734 0 : void SAL_CALL MatchCaseToolboxController::statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException )
735 : {
736 : (void) rEvent;
737 0 : SolarMutexGuard aSolarMutexGuard;
738 0 : if ( m_bDisposed )
739 0 : return;
740 : }
741 :
742 : //-----------------------------------------------------------------------------------------------------------
743 : // class FindAllToolboxController
744 :
745 0 : FindAllToolboxController::FindAllToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext )
746 : : svt::ToolboxController( rxContext,
747 : css::uno::Reference< css::frame::XFrame >(),
748 0 : OUString( COMMAND_EXITSEARCH ) )
749 : {
750 0 : }
751 :
752 0 : FindAllToolboxController::~FindAllToolboxController()
753 : {
754 0 : }
755 :
756 : // XInterface
757 0 : css::uno::Any SAL_CALL FindAllToolboxController::queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException )
758 : {
759 0 : css::uno::Any a = ToolboxController::queryInterface( aType );
760 0 : if ( a.hasValue() )
761 0 : return a;
762 :
763 0 : return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) );
764 : }
765 :
766 0 : void SAL_CALL FindAllToolboxController::acquire() throw ()
767 : {
768 0 : ToolboxController::acquire();
769 0 : }
770 :
771 0 : void SAL_CALL FindAllToolboxController::release() throw ()
772 : {
773 0 : ToolboxController::release();
774 0 : }
775 :
776 : // XServiceInfo
777 0 : OUString SAL_CALL FindAllToolboxController::getImplementationName() throw( css::uno::RuntimeException )
778 : {
779 0 : return getImplementationName_Static( );
780 : }
781 :
782 :
783 0 : sal_Bool SAL_CALL FindAllToolboxController::supportsService( const OUString& ServiceName ) throw( css::uno::RuntimeException )
784 : {
785 0 : const css::uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
786 0 : const OUString * pArray = aSNL.getConstArray();
787 :
788 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
789 0 : if( pArray[i] == ServiceName )
790 0 : return true;
791 :
792 0 : return false;
793 :
794 : }
795 :
796 0 : css::uno::Sequence< OUString > SAL_CALL FindAllToolboxController::getSupportedServiceNames() throw( css::uno::RuntimeException )
797 : {
798 0 : return getSupportedServiceNames_Static();
799 : }
800 :
801 0 : css::uno::Sequence< OUString > FindAllToolboxController::getSupportedServiceNames_Static() throw()
802 : {
803 0 : css::uno::Sequence< OUString > aSNS( 1 );
804 0 : aSNS.getArray()[0] = OUString("com.sun.star.frame.ToolbarController");
805 0 : return aSNS;
806 : }
807 :
808 : // XComponent
809 0 : void SAL_CALL FindAllToolboxController::dispose() throw ( css::uno::RuntimeException )
810 : {
811 0 : SolarMutexGuard aSolarMutexGuard;
812 :
813 0 : SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL);
814 :
815 0 : svt::ToolboxController::dispose();
816 0 : }
817 :
818 : // XInitialization
819 0 : void SAL_CALL FindAllToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException )
820 : {
821 0 : svt::ToolboxController::initialize( aArguments );
822 0 : SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL);
823 0 : }
824 :
825 : // XToolbarController
826 0 : void SAL_CALL FindAllToolboxController::execute( sal_Int16 /*KeyModifier*/ ) throw ( css::uno::RuntimeException )
827 : {
828 0 : if ( m_bDisposed )
829 0 : throw css::lang::DisposedException();
830 :
831 0 : Window* pWindow = VCLUnoHelper::GetWindow( getParent() );
832 0 : ToolBox* pToolBox = (ToolBox*)pWindow;
833 :
834 0 : impl_executeSearch(m_xContext, m_xFrame, pToolBox, false, true);
835 0 : }
836 :
837 : // XStatusListener
838 0 : void SAL_CALL FindAllToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ ) throw ( css::uno::RuntimeException )
839 : {
840 0 : SolarMutexGuard aSolarMutexGuard;
841 0 : if ( m_bDisposed )
842 0 : return;
843 : }
844 :
845 : //-----------------------------------------------------------------------------------------------------------
846 : // class ExitSearchToolboxController
847 :
848 0 : ExitSearchToolboxController::ExitSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext )
849 : : svt::ToolboxController( rxContext,
850 : css::uno::Reference< css::frame::XFrame >(),
851 0 : OUString( COMMAND_EXITSEARCH ) )
852 : {
853 0 : }
854 :
855 0 : ExitSearchToolboxController::~ExitSearchToolboxController()
856 : {
857 0 : }
858 :
859 : // XInterface
860 0 : css::uno::Any SAL_CALL ExitSearchToolboxController::queryInterface( const css::uno::Type& aType ) throw ( css::uno::RuntimeException )
861 : {
862 0 : css::uno::Any a = ToolboxController::queryInterface( aType );
863 0 : if ( a.hasValue() )
864 0 : return a;
865 :
866 0 : return ::cppu::queryInterface( aType, static_cast< css::lang::XServiceInfo* >( this ) );
867 : }
868 :
869 0 : void SAL_CALL ExitSearchToolboxController::acquire() throw ()
870 : {
871 0 : ToolboxController::acquire();
872 0 : }
873 :
874 0 : void SAL_CALL ExitSearchToolboxController::release() throw ()
875 : {
876 0 : ToolboxController::release();
877 0 : }
878 :
879 : // XServiceInfo
880 0 : OUString SAL_CALL ExitSearchToolboxController::getImplementationName() throw( css::uno::RuntimeException )
881 : {
882 0 : return getImplementationName_Static( );
883 : }
884 :
885 :
886 0 : sal_Bool SAL_CALL ExitSearchToolboxController::supportsService( const OUString& ServiceName ) throw( css::uno::RuntimeException )
887 : {
888 0 : const css::uno::Sequence< OUString > aSNL( getSupportedServiceNames() );
889 0 : const OUString * pArray = aSNL.getConstArray();
890 :
891 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
892 0 : if( pArray[i] == ServiceName )
893 0 : return true;
894 :
895 0 : return false;
896 :
897 : }
898 :
899 0 : css::uno::Sequence< OUString > SAL_CALL ExitSearchToolboxController::getSupportedServiceNames() throw( css::uno::RuntimeException )
900 : {
901 0 : return getSupportedServiceNames_Static();
902 : }
903 :
904 0 : css::uno::Sequence< OUString > ExitSearchToolboxController::getSupportedServiceNames_Static() throw()
905 : {
906 0 : css::uno::Sequence< OUString > aSNS( 1 );
907 0 : aSNS.getArray()[0] = OUString("com.sun.star.frame.ToolbarController");
908 0 : return aSNS;
909 : }
910 :
911 : // XComponent
912 0 : void SAL_CALL ExitSearchToolboxController::dispose() throw ( css::uno::RuntimeException )
913 : {
914 0 : SolarMutexGuard aSolarMutexGuard;
915 :
916 0 : SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL);
917 :
918 0 : svt::ToolboxController::dispose();
919 0 : }
920 :
921 : // XInitialization
922 0 : void SAL_CALL ExitSearchToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException )
923 : {
924 0 : svt::ToolboxController::initialize( aArguments );
925 0 : SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY), m_aCommandURL);
926 0 : }
927 :
928 : // XToolbarController
929 0 : void SAL_CALL ExitSearchToolboxController::execute( sal_Int16 /*KeyModifier*/ ) throw ( css::uno::RuntimeException )
930 : {
931 0 : Window *pFocusWindow = Application::GetFocusWindow();
932 0 : if ( pFocusWindow )
933 0 : pFocusWindow->GrabFocusToDocument();
934 :
935 : // hide the findbar
936 0 : css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY);
937 0 : if (xPropSet.is())
938 : {
939 0 : css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
940 0 : css::uno::Any aValue = xPropSet->getPropertyValue("LayoutManager");
941 0 : aValue >>= xLayoutManager;
942 0 : if (xLayoutManager.is())
943 : {
944 0 : const OUString sResourceURL( "private:resource/toolbar/findbar" );
945 0 : xLayoutManager->hideElement( sResourceURL );
946 0 : xLayoutManager->destroyElement( sResourceURL );
947 0 : }
948 0 : }
949 0 : }
950 :
951 : // XStatusListener
952 0 : void SAL_CALL ExitSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ ) throw ( css::uno::RuntimeException )
953 : {
954 0 : SolarMutexGuard aSolarMutexGuard;
955 0 : if ( m_bDisposed )
956 0 : return;
957 : }
958 :
959 : //-----------------------------------------------------------------------------------------------------------
960 : // class FindbarDispatcher
961 :
962 2 : FindbarDispatcher::FindbarDispatcher()
963 : {
964 2 : }
965 :
966 6 : FindbarDispatcher::~FindbarDispatcher()
967 : {
968 2 : m_xFrame = NULL;
969 4 : }
970 :
971 : // XInterface
972 4 : css::uno::Any SAL_CALL FindbarDispatcher::queryInterface( const css::uno::Type& aType ) throw( css::uno::RuntimeException )
973 : {
974 : css::uno::Any aReturn( ::cppu::queryInterface( aType,
975 : static_cast< css::lang::XServiceInfo* >(this),
976 : static_cast< css::lang::XInitialization* >(this),
977 : static_cast< css::frame::XDispatchProvider* >(this),
978 4 : static_cast< css::frame::XDispatch* >(this)) );
979 :
980 4 : if ( aReturn.hasValue() )
981 4 : return aReturn;
982 :
983 0 : return OWeakObject::queryInterface( aType );
984 : }
985 :
986 28 : void SAL_CALL FindbarDispatcher::acquire() throw()
987 : {
988 28 : OWeakObject::acquire();
989 28 : }
990 :
991 28 : void SAL_CALL FindbarDispatcher::release() throw()
992 : {
993 28 : OWeakObject::release();
994 28 : }
995 :
996 : // XServiceInfo
997 0 : OUString SAL_CALL FindbarDispatcher::getImplementationName() throw( css::uno::RuntimeException )
998 : {
999 0 : return getImplementationName_Static();
1000 : }
1001 :
1002 0 : sal_Bool SAL_CALL FindbarDispatcher::supportsService( const OUString& ServiceName ) throw( css::uno::RuntimeException )
1003 : {
1004 : return (
1005 0 : ServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.comp.svx.FindbarDispatcher")) ||
1006 0 : ServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.frame.ProtocolHandler"))
1007 0 : );
1008 : }
1009 :
1010 0 : css::uno::Sequence< OUString > SAL_CALL FindbarDispatcher::getSupportedServiceNames() throw( css::uno::RuntimeException )
1011 : {
1012 0 : return getSupportedServiceNames_Static();
1013 : }
1014 :
1015 1 : css::uno::Sequence< OUString > FindbarDispatcher::getSupportedServiceNames_Static() throw()
1016 : {
1017 1 : css::uno::Sequence< OUString > aSNS( 2 );
1018 1 : aSNS.getArray()[0] = OUString( "com.sun.star.comp.svx.FindbarDispatcher" );
1019 1 : aSNS.getArray()[1] = OUString( "com.sun.star.frame.ProtocolHandler" );
1020 1 : return aSNS;
1021 : }
1022 :
1023 : // XInitialization
1024 2 : void SAL_CALL FindbarDispatcher::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException )
1025 : {
1026 2 : if ( aArguments.getLength() )
1027 2 : aArguments[0] >>= m_xFrame;
1028 2 : }
1029 :
1030 : // XDispatchProvider
1031 2 : css::uno::Reference< css::frame::XDispatch > SAL_CALL FindbarDispatcher::queryDispatch( const css::util::URL& aURL, const OUString& /*sTargetFrameName*/, sal_Int32 /*nSearchFlags*/ ) throw( css::uno::RuntimeException )
1032 : {
1033 2 : css::uno::Reference< css::frame::XDispatch > xDispatch;
1034 :
1035 2 : if ( aURL.Protocol == "vnd.sun.star.findbar:" )
1036 2 : xDispatch = this;
1037 :
1038 2 : return xDispatch;
1039 : }
1040 :
1041 0 : 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 )
1042 : {
1043 0 : sal_Int32 nCount = seqDescripts.getLength();
1044 0 : css::uno::Sequence < css::uno::Reference < XDispatch > > lDispatcher( nCount );
1045 :
1046 0 : for( sal_Int32 i=0; i<nCount; ++i )
1047 0 : lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags );
1048 :
1049 0 : return lDispatcher;
1050 : }
1051 :
1052 : // XDispatch
1053 0 : void SAL_CALL FindbarDispatcher::dispatch( const css::util::URL& aURL, const css::uno::Sequence < css::beans::PropertyValue >& /*lArgs*/ ) throw( css::uno::RuntimeException )
1054 : {
1055 : //vnd.sun.star.findbar:FocusToFindbar - set cursor to the FindTextFieldControl of the findbar
1056 0 : if ( aURL.Path == "FocusToFindbar" )
1057 : {
1058 0 : css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY);
1059 0 : if(!xPropSet.is())
1060 0 : return;
1061 :
1062 0 : css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
1063 0 : css::uno::Any aValue = xPropSet->getPropertyValue("LayoutManager");
1064 0 : aValue >>= xLayoutManager;
1065 0 : if (!xLayoutManager.is())
1066 0 : return;
1067 :
1068 0 : const OUString sResourceURL( "private:resource/toolbar/findbar" );
1069 0 : css::uno::Reference< css::ui::XUIElement > xUIElement = xLayoutManager->getElement(sResourceURL);
1070 0 : if (!xUIElement.is())
1071 : {
1072 : // show the findbar if necessary
1073 0 : xLayoutManager->createElement( sResourceURL );
1074 0 : xLayoutManager->showElement( sResourceURL );
1075 0 : xUIElement = xLayoutManager->getElement( sResourceURL );
1076 0 : if ( !xUIElement.is() )
1077 0 : return;
1078 : }
1079 :
1080 0 : css::uno::Reference< css::awt::XWindow > xWindow(xUIElement->getRealInterface(), css::uno::UNO_QUERY);
1081 0 : Window* pWindow = VCLUnoHelper::GetWindow( xWindow );
1082 0 : ToolBox* pToolBox = (ToolBox*)pWindow;
1083 0 : if ( pToolBox )
1084 : {
1085 0 : sal_uInt16 nItemCount = pToolBox->GetItemCount();
1086 0 : for ( sal_uInt16 i=0; i<nItemCount; ++i )
1087 : {
1088 0 : OUString sItemCommand = pToolBox->GetItemCommand(i);
1089 0 : if ( sItemCommand == COMMAND_FINDTEXT )
1090 : {
1091 0 : Window* pItemWin = pToolBox->GetItemWindow( i );
1092 0 : if ( pItemWin )
1093 : {
1094 0 : FindTextFieldControl* pFindTextFieldControl = dynamic_cast<FindTextFieldControl*>(pItemWin);
1095 0 : if ( pFindTextFieldControl )
1096 0 : pFindTextFieldControl->SetTextToSelected_Impl();
1097 0 : SolarMutexGuard aSolarMutexGuard;
1098 0 : pItemWin->GrabFocus();
1099 0 : return;
1100 : }
1101 : }
1102 0 : }
1103 0 : }
1104 : }
1105 : }
1106 :
1107 5 : void SAL_CALL FindbarDispatcher::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xControl*/, const css::util::URL& /*aURL*/ ) throw ( css::uno::RuntimeException )
1108 : {
1109 5 : }
1110 :
1111 7 : void SAL_CALL FindbarDispatcher::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xControl*/, const css::util::URL& /*aURL*/ ) throw ( css::uno::RuntimeException )
1112 : {
1113 7 : }
1114 :
1115 : //-----------------------------------------------------------------------------------------------------------
1116 : // create Instance
1117 :
1118 0 : css::uno::Reference< css::uno::XInterface > SAL_CALL FindTextToolbarController_createInstance(
1119 : const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr )
1120 : {
1121 : return static_cast< cppu::OWeakObject * >(
1122 0 : new FindTextToolbarController( comphelper::getComponentContext(rSMgr) ) );
1123 : }
1124 :
1125 0 : css::uno::Reference< css::uno::XInterface > SAL_CALL DownSearchToolboxController_createInstance(
1126 : const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr )
1127 : {
1128 : return static_cast< cppu::OWeakObject * >(
1129 : new UpDownSearchToolboxController(
1130 0 : comphelper::getComponentContext(rSMgr), UpDownSearchToolboxController::DOWN ) );
1131 : }
1132 :
1133 0 : css::uno::Reference< css::uno::XInterface > SAL_CALL UpSearchToolboxController_createInstance(
1134 : const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr )
1135 : {
1136 : return static_cast< cppu::OWeakObject * >(
1137 : new UpDownSearchToolboxController(
1138 0 : comphelper::getComponentContext(rSMgr), UpDownSearchToolboxController::UP ) );
1139 : }
1140 :
1141 0 : css::uno::Reference< css::uno::XInterface > SAL_CALL MatchCaseToolboxController_createInstance(
1142 : const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr )
1143 : {
1144 : return static_cast< cppu::OWeakObject * >(
1145 0 : new MatchCaseToolboxController( comphelper::getComponentContext(rSMgr) ) );
1146 : }
1147 :
1148 0 : css::uno::Reference< css::uno::XInterface > SAL_CALL FindAllToolboxController_createInstance(
1149 : const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr )
1150 : {
1151 : return static_cast< cppu::OWeakObject * >(
1152 0 : new FindAllToolboxController( comphelper::getComponentContext(rSMgr) ) );
1153 : }
1154 :
1155 0 : css::uno::Reference< css::uno::XInterface > SAL_CALL ExitFindbarToolboxController_createInstance(
1156 : const css::uno::Reference< css::lang::XMultiServiceFactory >& rSMgr )
1157 : {
1158 0 : return *new ExitSearchToolboxController( comphelper::getComponentContext(rSMgr) );
1159 : }
1160 :
1161 2 : css::uno::Reference< css::uno::XInterface > SAL_CALL FindbarDispatcher_createInstance(
1162 : const css::uno::Reference< css::lang::XMultiServiceFactory >& )
1163 : {
1164 2 : return static_cast< cppu::OWeakObject * >( new FindbarDispatcher );
1165 : }
1166 :
1167 : //-----------------------------------------------------------------------------------------------------------
1168 216 : }
1169 :
1170 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|