xref: /core/svx/source/tbxctrls/tbunosearchcontrollers.cxx (revision e5e491c3dbfdc5a51d7df0230191fd8d4aa39177)
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 <sal/config.h>
21 
22 #include <map>
23 #include <utility>
24 #include <vector>
25 
26 #include <config_feature_desktop.h>
27 #include <officecfg/Office/Common.hxx>
28 
29 #include <svx/strings.hrc>
30 #include <svx/dialmgr.hxx>
31 
32 #include <comphelper/propertysequence.hxx>
33 #include <cppuhelper/queryinterface.hxx>
34 #include <cppuhelper/supportsservice.hxx>
35 #include <cppuhelper/weak.hxx>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/frame/DispatchDescriptor.hpp>
39 #include <com/sun/star/frame/XDispatch.hpp>
40 #include <com/sun/star/frame/XDispatchProvider.hpp>
41 #include <com/sun/star/frame/XLayoutManager.hpp>
42 #include <com/sun/star/frame/XStatusListener.hpp>
43 #include <com/sun/star/lang/XInitialization.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/text/XTextRange.hpp>
46 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
47 #include <com/sun/star/ui/XUIElement.hpp>
48 #include <com/sun/star/container/XEnumeration.hpp>
49 #include <com/sun/star/util/URLTransformer.hpp>
50 #include <com/sun/star/util/SearchAlgorithms.hpp>
51 #include <com/sun/star/util/SearchAlgorithms2.hpp>
52 
53 #include <vcl/InterimItemWindow.hxx>
54 #include <svl/ctloptions.hxx>
55 #include <svl/srchitem.hxx>
56 #include <svtools/acceleratorexecute.hxx>
57 #include <svtools/toolboxcontroller.hxx>
58 #include <toolkit/helper/vclunohelper.hxx>
59 #include <vcl/svapp.hxx>
60 #include <svx/labelitemwindow.hxx>
61 #include <svx/srchdlg.hxx>
62 #include <vcl/event.hxx>
63 
64 #include <findtextfield.hxx>
65 
66 using namespace css;
67 
68 namespace {
69 
70 constexpr OUString COMMAND_FINDTEXT = u".uno:FindText"_ustr;
71 constexpr OUString COMMAND_DOWNSEARCH = u".uno:DownSearch"_ustr;
72 constexpr OUString COMMAND_UPSEARCH = u".uno:UpSearch"_ustr;
73 constexpr OUStringLiteral COMMAND_FINDALL = u".uno:FindAll";
74 constexpr OUString COMMAND_MATCHCASE = u".uno:MatchCase"_ustr;
75 constexpr OUString COMMAND_MATCHDIACRITICS = u".uno:MatchDiacritics"_ustr;
76 constexpr OUString COMMAND_SEARCHFORMATTED = u".uno:SearchFormattedDisplayString"_ustr;
77 
78 class CheckButtonItemWindow final : public InterimItemWindow
79 {
80 public:
CheckButtonItemWindow(vcl::Window * pParent,const OUString & rLabel)81     CheckButtonItemWindow(vcl::Window* pParent, const OUString& rLabel)
82         : InterimItemWindow(pParent, u"svx/ui/checkbuttonbox.ui"_ustr, u"CheckButtonBox"_ustr)
83         , m_xWidget(m_xBuilder->weld_check_button(u"checkbutton"_ustr))
84     {
85         InitControlBase(m_xWidget.get());
86 
87         m_xWidget->connect_key_press(LINK(this, CheckButtonItemWindow, KeyInputHdl));
88         m_xWidget->set_label(rLabel);
89         SetSizePixel(m_xContainer->get_preferred_size());
90     }
91 
get_active() const92     bool get_active() const
93     {
94         return m_xWidget->get_active();
95     }
96 
set_active(bool bActive)97     void set_active(bool bActive)
98     {
99         if (m_xWidget)
100             m_xWidget->set_active(bActive);
101     }
102 
dispose()103     virtual void dispose() override
104     {
105         m_xWidget.reset();
106         InterimItemWindow::dispose();
107     }
108 
~CheckButtonItemWindow()109     virtual ~CheckButtonItemWindow() override
110     {
111         disposeOnce();
112     }
113 
114 private:
115     std::unique_ptr<weld::CheckButton> m_xWidget;
116 
117     DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
118 };
119 
IMPL_LINK(CheckButtonItemWindow,KeyInputHdl,const KeyEvent &,rKeyEvent,bool)120 IMPL_LINK(CheckButtonItemWindow, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
121 {
122     return ChildKeyInput(rKeyEvent);
123 }
124 
impl_executeSearch(const css::uno::Reference<css::uno::XComponentContext> & rxContext,const css::uno::Reference<css::frame::XFrame> & xFrame,const ToolBox * pToolBox,const bool aSearchBackwards,const bool aFindAll=false)125 void impl_executeSearch( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
126                          const css::uno::Reference< css::frame::XFrame >& xFrame,
127                          const ToolBox* pToolBox,
128                          const bool aSearchBackwards,
129                          const bool aFindAll = false )
130 {
131     css::uno::Reference< css::util::XURLTransformer > xURLTransformer( css::util::URLTransformer::create( rxContext ) );
132     css::util::URL aURL;
133     aURL.Complete = ".uno:ExecuteSearch";
134     xURLTransformer->parseStrict(aURL);
135 
136     OUString sFindText;
137     bool aMatchCase = false;
138     bool aMatchDiacritics = false;
139     bool bSearchFormatted = false;
140     if ( pToolBox )
141     {
142         ToolBox::ImplToolItems::size_type nItemCount = pToolBox->GetItemCount();
143         for ( ToolBox::ImplToolItems::size_type i=0; i<nItemCount; ++i )
144         {
145             ToolBoxItemId id = pToolBox->GetItemId(i);
146             OUString sItemCommand = pToolBox->GetItemCommand(id);
147             if ( sItemCommand == COMMAND_FINDTEXT )
148             {
149                 FindTextFieldControl* pItemWin = static_cast<FindTextFieldControl*>(pToolBox->GetItemWindow(id));
150                 if (pItemWin)
151                 {
152                     sFindText = pItemWin->get_active_text();
153                     if (aFindAll && !pItemWin->ControlHasFocus())
154                         pItemWin->GetFocus();
155                 }
156             } else if ( sItemCommand == COMMAND_MATCHCASE )
157             {
158                 CheckButtonItemWindow* pItemWin = static_cast<CheckButtonItemWindow*>(pToolBox->GetItemWindow(id));
159                 if (pItemWin)
160                     aMatchCase = pItemWin->get_active();
161             } else if ( sItemCommand == COMMAND_MATCHDIACRITICS )
162             {
163                 CheckButtonItemWindow* pItemWin = static_cast<CheckButtonItemWindow*>(pToolBox->GetItemWindow(id));
164                 if (pItemWin)
165                     aMatchDiacritics = pItemWin->get_active();
166             } else if ( sItemCommand == COMMAND_SEARCHFORMATTED )
167             {
168                 CheckButtonItemWindow* pItemWin = static_cast<CheckButtonItemWindow*>(pToolBox->GetItemWindow(id));
169                 if (pItemWin)
170                     bSearchFormatted = pItemWin->get_active();
171             }
172         }
173     }
174 
175     TransliterationFlags nFlags = TransliterationFlags::NONE;
176     if (!aMatchCase)
177         nFlags |= TransliterationFlags::IGNORE_CASE;
178     if (!aMatchDiacritics)
179         nFlags |= TransliterationFlags::IGNORE_DIACRITICS_CTL;
180     if (SvtCTLOptions::IsCTLFontEnabled())
181         nFlags |= TransliterationFlags::IGNORE_KASHIDA_CTL;
182 
183     auto aArgs( comphelper::InitPropertySequence( {
184         { "SearchItem.SearchString", css::uno::Any( sFindText ) },
185         // Related tdf#102506: make Find Bar Ctrl+F searching by value by default
186         { "SearchItem.CellType", css::uno::Any( sal_Int16(SvxSearchCellType::VALUE) ) },
187         { "SearchItem.Backward", css::uno::Any( aSearchBackwards ) },
188         { "SearchItem.SearchFlags", css::uno::Any( sal_Int32(0) ) },
189         { "SearchItem.TransliterateFlags", css::uno::Any( static_cast<sal_Int32>(nFlags) ) },
190         { "SearchItem.Command", css::uno::Any( static_cast<sal_Int16>(aFindAll ?SvxSearchCmd::FIND_ALL : SvxSearchCmd::FIND ) ) },
191         { "SearchItem.AlgorithmType", css::uno::Any( sal_Int16(css::util::SearchAlgorithms_ABSOLUTE) ) },
192         { "SearchItem.AlgorithmType2", css::uno::Any( sal_Int16(css::util::SearchAlgorithms2::ABSOLUTE) ) },
193         { "SearchItem.SearchFormatted", css::uno::Any( bSearchFormatted ) },
194         { "UseAttrItemList", css::uno::Any(false) }
195     } ) );
196 
197     css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider(xFrame, css::uno::UNO_QUERY);
198     if ( xDispatchProvider.is() )
199     {
200         css::uno::Reference< css::frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
201         if ( xDispatch.is() && !aURL.Complete.isEmpty() )
202             xDispatch->dispatch( aURL, aArgs );
203     }
204 }
205 
206 }
207 
208 // tdf#154818 - remember last search string
209 OUString FindTextFieldControl::m_sRememberedSearchString;
210 
FindTextFieldControl(ToolBox * pParent,css::uno::Reference<css::frame::XFrame> xFrame,css::uno::Reference<css::uno::XComponentContext> xContext)211 FindTextFieldControl::FindTextFieldControl(ToolBox* pParent,
212     css::uno::Reference< css::frame::XFrame > xFrame,
213     css::uno::Reference< css::uno::XComponentContext > xContext) :
214     InterimItemWindow(pParent, u"svx/ui/findbox.ui"_ustr, u"FindBox"_ustr),
215     m_nAsyncGetFocusId(nullptr),
216     m_xWidget(m_xBuilder->weld_combo_box(u"find"_ustr)),
217     m_xFrame(std::move(xFrame)),
218     m_xContext(std::move(xContext)),
219     m_pAcc(svt::AcceleratorExecute::createAcceleratorHelper())
220 {
221     InitControlBase(m_xWidget.get());
222 
223     m_xWidget->set_entry_placeholder_text(SvxResId(RID_SVXSTR_FINDBAR_FIND));
224     m_xWidget->set_entry_completion(true, true);
225     m_pAcc->init(m_xContext, m_xFrame);
226 
227     m_xWidget->connect_focus_in(LINK(this, FindTextFieldControl, FocusInHdl));
228     m_xWidget->connect_key_press(LINK(this, FindTextFieldControl, KeyInputHdl));
229     m_xWidget->connect_entry_activate(LINK(this, FindTextFieldControl, ActivateHdl));
230 
231     m_xWidget->set_size_request(250, -1);
232     SetSizePixel(m_xContainer->get_preferred_size());
233 
234     // tdf#154269 - respect FindReplaceRememberedSearches expert option
235     m_nRememberSize = officecfg::Office::Common::Misc::FindReplaceRememberedSearches::get();
236     if (m_nRememberSize < 1)
237         m_nRememberSize = 1;
238 }
239 
Remember_Impl(const OUString & rStr)240 void FindTextFieldControl::Remember_Impl(const OUString& rStr)
241 {
242     if (rStr.isEmpty())
243         return;
244 
245     // tdf#154818 - rearrange the search items
246     const auto nPos = m_xWidget->find_text(rStr);
247     if (nPos != -1)
248         m_xWidget->remove(nPos);
249     else if (m_xWidget->get_count() >= m_nRememberSize)
250         m_xWidget->remove(m_nRememberSize - 1);
251     m_xWidget->insert_text(0, rStr);
252 }
253 
SetTextToSelected_Impl()254 void FindTextFieldControl::SetTextToSelected_Impl()
255 {
256     OUString aString;
257 
258     try
259     {
260         css::uno::Reference<css::frame::XController> xController(m_xFrame->getController(), css::uno::UNO_SET_THROW);
261         uno::Reference<text::XTextViewCursorSupplier> const xTVCS(xController, uno::UNO_QUERY);
262         if (xTVCS.is())
263         {
264             uno::Reference<text::XTextViewCursor> const xTVC(xTVCS->getViewCursor());
265             aString = xTVC->getString();
266         }
267         else
268         {
269             uno::Reference<frame::XModel> xModel(xController->getModel(), uno::UNO_SET_THROW);
270             uno::Reference<uno::XInterface> xSelection = xModel->getCurrentSelection();
271             uno::Reference<container::XIndexAccess> xIndexAccess(xSelection, uno::UNO_QUERY);
272             if (xIndexAccess.is())
273             {
274                 if (xIndexAccess->getCount() > 0)
275                 {
276                     uno::Reference<text::XTextRange> xTextRange(xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW);
277                     aString = xTextRange->getString();
278                 }
279             }
280             else
281             {
282                 // The Basic IDE returns a XEnumeration with a single item
283                 uno::Reference<container::XEnumeration> xEnum(xSelection, uno::UNO_QUERY_THROW);
284                 if (xEnum->hasMoreElements())
285                     xEnum->nextElement() >>= aString;
286             }
287         }
288     }
289     catch ( ... )
290     {
291     }
292 
293     if ( !aString.isEmpty() )
294     {
295         // If something is selected in the document, prepopulate with this
296         m_xWidget->set_entry_text(aString);
297         m_aChangeHdl.Call(*m_xWidget);
298     }
299     // tdf#154818 - reuse last search string
300     else if (!m_sRememberedSearchString.isEmpty() || get_count() > 0)
301     {
302         // prepopulate with last search word (fdo#84256)
303         m_xWidget->set_entry_text(m_sRememberedSearchString.isEmpty() ? m_xWidget->get_text(0)
304                                                                       : m_sRememberedSearchString);
305     }
306 }
307 
IMPL_LINK(FindTextFieldControl,KeyInputHdl,const KeyEvent &,rKeyEvent,bool)308 IMPL_LINK(FindTextFieldControl, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
309 {
310     if (isDisposed())
311         return true;
312 
313     bool bRet = false;
314 
315     bool bShift = rKeyEvent.GetKeyCode().IsShift();
316     bool bMod1 = rKeyEvent.GetKeyCode().IsMod1();
317     sal_uInt16 nCode = rKeyEvent.GetKeyCode().GetCode();
318 
319     // Close the search bar on Escape
320     if ( KEY_ESCAPE == nCode )
321     {
322         bRet = true;
323         GrabFocusToDocument();
324 
325         // hide the findbar
326         css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY);
327         if (xPropSet.is())
328         {
329             css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
330             css::uno::Any aValue = xPropSet->getPropertyValue(u"LayoutManager"_ustr);
331             aValue >>= xLayoutManager;
332             if (xLayoutManager.is())
333             {
334                 static constexpr OUString sResourceURL( u"private:resource/toolbar/findbar"_ustr );
335                 xLayoutManager->hideElement( sResourceURL );
336                 xLayoutManager->destroyElement( sResourceURL );
337             }
338         }
339     }
340     else
341     {
342         auto awtKey = svt::AcceleratorExecute::st_VCLKey2AWTKey(rKeyEvent.GetKeyCode());
343         const OUString aCommand(m_pAcc->findCommand(awtKey));
344 
345         // Select text in the search box when Ctrl-F pressed
346         if ( bMod1 && nCode == KEY_F )
347             m_xWidget->select_entry_region(0, -1);
348         // Execute the search when Ctrl-G, F3 and Shift-RETURN pressed (in addition to ActivateHdl condition which handles bare RETURN)
349         else if ( (bMod1 && KEY_G == nCode) || (bShift && KEY_RETURN == nCode) || (KEY_F3 == nCode) )
350         {
351             ActivateFind(bShift);
352             bRet = true;
353         }
354         else if (aCommand == ".uno:SearchDialog")
355             bRet = m_pAcc->execute(awtKey);
356 
357         // find-shortcut called with focus already in find
358         if (aCommand == "vnd.sun.star.findbar:FocusToFindbar")
359         {
360             m_xWidget->call_attention_to();
361             bRet = true;
362         }
363     }
364 
365     return bRet || ChildKeyInput(rKeyEvent);
366 }
367 
ActivateFind(bool bShift)368 void FindTextFieldControl::ActivateFind(bool bShift)
369 {
370     // tdf#154818 - remember last search string
371     m_sRememberedSearchString = m_xWidget->get_active_text();
372     Remember_Impl(m_sRememberedSearchString);
373 
374     vcl::Window* pWindow = GetParent();
375     ToolBox* pToolBox = static_cast<ToolBox*>(pWindow);
376 
377     impl_executeSearch(m_xContext, m_xFrame, pToolBox, bShift);
378 
379     m_xWidget->grab_focus();
380 }
381 
382 // Execute the search when activated, typically due to "Return"
IMPL_LINK_NOARG(FindTextFieldControl,ActivateHdl,weld::ComboBox &,bool)383 IMPL_LINK_NOARG(FindTextFieldControl, ActivateHdl, weld::ComboBox&, bool)
384 {
385     if (isDisposed())
386         return true;
387 
388     ActivateFind(false);
389 
390     return true;
391 }
392 
IMPL_LINK_NOARG(FindTextFieldControl,OnAsyncGetFocus,void *,void)393 IMPL_LINK_NOARG(FindTextFieldControl, OnAsyncGetFocus, void*, void)
394 {
395     m_nAsyncGetFocusId = nullptr;
396     m_xWidget->select_entry_region(0, -1);
397 }
398 
FocusIn()399 void FindTextFieldControl::FocusIn()
400 {
401     if (m_nAsyncGetFocusId || !m_xWidget)
402         return;
403 
404     // do it async to defeat entry in combobox having its own ideas about the focus
405     m_nAsyncGetFocusId = Application::PostUserEvent(LINK(this, FindTextFieldControl, OnAsyncGetFocus));
406 
407     GrabFocus(); // tdf#137993 ensure the toplevel vcl::Window is activated so SfxViewFrame::Current is valid
408 }
409 
IMPL_LINK_NOARG(FindTextFieldControl,FocusInHdl,weld::Widget &,void)410 IMPL_LINK_NOARG(FindTextFieldControl, FocusInHdl, weld::Widget&, void)
411 {
412     FocusIn();
413 }
414 
dispose()415 void FindTextFieldControl::dispose()
416 {
417     if (m_nAsyncGetFocusId)
418     {
419         Application::RemoveUserEvent(m_nAsyncGetFocusId);
420         m_nAsyncGetFocusId = nullptr;
421     }
422     m_xWidget.reset();
423     InterimItemWindow::dispose();
424 }
425 
~FindTextFieldControl()426 FindTextFieldControl::~FindTextFieldControl()
427 {
428     disposeOnce();
429 }
430 
connect_changed(const Link<weld::ComboBox &,void> & rLink)431 void FindTextFieldControl::connect_changed(const Link<weld::ComboBox&, void>& rLink)
432 {
433     m_aChangeHdl = rLink;
434     m_xWidget->connect_changed(rLink);
435 }
436 
get_count() const437 int FindTextFieldControl::get_count() const
438 {
439     return m_xWidget->get_count();
440 }
441 
get_text(int nIndex) const442 OUString FindTextFieldControl::get_text(int nIndex) const
443 {
444     return m_xWidget->get_text(nIndex);
445 }
446 
get_active_text() const447 OUString FindTextFieldControl::get_active_text() const
448 {
449     return m_xWidget->get_active_text();
450 }
451 
set_entry_message_type(weld::EntryMessageType eType)452 void FindTextFieldControl::set_entry_message_type(weld::EntryMessageType eType)
453 {
454     m_xWidget->set_entry_message_type(eType);
455 }
456 
append_text(const OUString & rText)457 void FindTextFieldControl::append_text(const OUString& rText)
458 {
459     m_xWidget->append_text(rText);
460 }
461 
462 namespace {
463 
464 class SearchToolbarControllersManager
465 {
466 public:
467 
468     SearchToolbarControllersManager();
469 
470     static SearchToolbarControllersManager& createControllersManager();
471 
472     void registryController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& xStatusListener, const OUString& sCommandURL );
473     void freeController ( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL );
474     css::uno::Reference< css::frame::XStatusListener > findController( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL );
475 
476     void saveSearchHistory(const FindTextFieldControl* m_pFindTextFieldControl);
477     void loadSearchHistory(FindTextFieldControl* m_pFindTextFieldControl);
478 
479 private:
480 
481     typedef ::std::vector< css::beans::PropertyValue > SearchToolbarControllersVec;
482     typedef ::std::map< css::uno::Reference< css::frame::XFrame >, SearchToolbarControllersVec > SearchToolbarControllersMap;
483     SearchToolbarControllersMap aSearchToolbarControllersMap;
484     std::vector<OUString> m_aSearchStrings;
485 
486 };
487 
SearchToolbarControllersManager()488 SearchToolbarControllersManager::SearchToolbarControllersManager()
489 {
490 }
491 
createControllersManager()492 SearchToolbarControllersManager& SearchToolbarControllersManager::createControllersManager()
493 {
494     static SearchToolbarControllersManager theSearchToolbarControllersManager;
495     return theSearchToolbarControllersManager;
496 }
497 
saveSearchHistory(const FindTextFieldControl * pFindTextFieldControl)498 void SearchToolbarControllersManager::saveSearchHistory(const FindTextFieldControl* pFindTextFieldControl)
499 {
500     const sal_Int32 nECount( pFindTextFieldControl->get_count() );
501     m_aSearchStrings.resize( nECount );
502     for( sal_Int32 i=0; i<nECount; ++i )
503     {
504         m_aSearchStrings[i] = pFindTextFieldControl->get_text(i);
505     }
506 }
507 
loadSearchHistory(FindTextFieldControl * pFindTextFieldControl)508 void SearchToolbarControllersManager::loadSearchHistory(FindTextFieldControl* pFindTextFieldControl)
509 {
510     for( size_t i=0; i<m_aSearchStrings.size(); ++i )
511     {
512         pFindTextFieldControl->append_text(m_aSearchStrings[i]);
513     }
514 }
515 
registryController(const css::uno::Reference<css::frame::XFrame> & xFrame,const css::uno::Reference<css::frame::XStatusListener> & xStatusListener,const OUString & sCommandURL)516 void SearchToolbarControllersManager::registryController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& xStatusListener, const OUString& sCommandURL )
517 {
518     SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame);
519     if (pIt == aSearchToolbarControllersMap.end())
520     {
521         SearchToolbarControllersVec lControllers(1);
522         lControllers[0].Name = sCommandURL;
523         lControllers[0].Value <<= xStatusListener;
524         aSearchToolbarControllersMap.emplace(xFrame, lControllers);
525     }
526     else
527     {
528         sal_Int32 nSize = pIt->second.size();
529         for (sal_Int32 i=0; i<nSize; ++i)
530         {
531             if (pIt->second[i].Name == sCommandURL)
532                 return;
533         }
534 
535         pIt->second.resize(nSize+1);
536         pIt->second[nSize].Name = sCommandURL;
537         pIt->second[nSize].Value <<= xStatusListener;
538     }
539 }
540 
freeController(const css::uno::Reference<css::frame::XFrame> & xFrame,const OUString & sCommandURL)541 void SearchToolbarControllersManager::freeController( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL )
542 {
543     SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame);
544     if (pIt != aSearchToolbarControllersMap.end())
545     {
546         auto pItCtrl = std::find_if(pIt->second.begin(), pIt->second.end(),
547             [&sCommandURL](const css::beans::PropertyValue& rCtrl) { return rCtrl.Name == sCommandURL; });
548         if (pItCtrl != pIt->second.end())
549             pIt->second.erase(pItCtrl);
550 
551         if (pIt->second.empty())
552             aSearchToolbarControllersMap.erase(pIt);
553     }
554 }
555 
findController(const css::uno::Reference<css::frame::XFrame> & xFrame,const OUString & sCommandURL)556 css::uno::Reference< css::frame::XStatusListener > SearchToolbarControllersManager::findController( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL )
557 {
558     css::uno::Reference< css::frame::XStatusListener > xStatusListener;
559 
560     SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame);
561     if (pIt != aSearchToolbarControllersMap.end())
562     {
563         auto pItCtrl = std::find_if(pIt->second.begin(), pIt->second.end(),
564             [&sCommandURL](const css::beans::PropertyValue& rCtrl) { return rCtrl.Name == sCommandURL; });
565         if (pItCtrl != pIt->second.end())
566             pItCtrl->Value >>= xStatusListener;
567     }
568 
569     return xStatusListener;
570 }
571 
572 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> FindTextToolbarController_Base;
573 class FindTextToolbarController : public FindTextToolbarController_Base
574 {
575 public:
576 
577     FindTextToolbarController( const css::uno::Reference< css::uno::XComponentContext > & rxContext );
578 
579     // XServiceInfo
580     virtual OUString SAL_CALL getImplementationName() override;
581     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
582     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
583 
584     // XComponent
585     virtual void SAL_CALL dispose() override;
586 
587     // XInitialization
588     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
589 
590     // XToolbarController
591     virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
592 
593     // XStatusListener
594     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
595 
596     DECL_LINK(EditModifyHdl, weld::ComboBox&, void);
597 
598 private:
599 
600     void textfieldChanged();
601 
602     VclPtr<FindTextFieldControl> m_pFindTextFieldControl;
603 
604     ToolBoxItemId m_nDownSearchId;
605     ToolBoxItemId m_nUpSearchId;
606     ToolBoxItemId m_nFindAllId;
607 
608 };
609 
FindTextToolbarController(const css::uno::Reference<css::uno::XComponentContext> & rxContext)610 FindTextToolbarController::FindTextToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
611     : FindTextToolbarController_Base(rxContext, css::uno::Reference< css::frame::XFrame >(), COMMAND_FINDTEXT)
612     , m_pFindTextFieldControl(nullptr)
613     , m_nDownSearchId(0)
614     , m_nUpSearchId(0)
615     , m_nFindAllId(0)
616 {
617 }
618 
619 // XServiceInfo
getImplementationName()620 OUString SAL_CALL FindTextToolbarController::getImplementationName()
621 {
622     return u"com.sun.star.svx.FindTextToolboxController"_ustr;
623 }
624 
supportsService(const OUString & ServiceName)625 sal_Bool SAL_CALL FindTextToolbarController::supportsService( const OUString& ServiceName )
626 {
627     return cppu::supportsService(this, ServiceName);
628 }
629 
getSupportedServiceNames()630 css::uno::Sequence< OUString > SAL_CALL FindTextToolbarController::getSupportedServiceNames()
631 {
632     return { u"com.sun.star.frame.ToolbarController"_ustr };
633 }
634 
635 // XComponent
dispose()636 void SAL_CALL FindTextToolbarController::dispose()
637 {
638     SolarMutexGuard aSolarMutexGuard;
639 
640     SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
641 
642     svt::ToolboxController::dispose();
643     if (m_pFindTextFieldControl != nullptr) {
644         SearchToolbarControllersManager::createControllersManager()
645             .saveSearchHistory(m_pFindTextFieldControl);
646         m_pFindTextFieldControl.disposeAndClear();
647     }
648 }
649 
650 // XInitialization
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)651 void SAL_CALL FindTextToolbarController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
652 {
653     svt::ToolboxController::initialize(aArguments);
654 
655     VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() );
656     ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
657     if ( pToolBox )
658     {
659         m_nDownSearchId = pToolBox->GetItemId(COMMAND_DOWNSEARCH);
660         m_nUpSearchId = pToolBox->GetItemId(COMMAND_UPSEARCH);
661         m_nFindAllId = pToolBox->GetItemId(COMMAND_FINDALL);
662     }
663 
664     SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
665 }
666 
createItemWindow(const css::uno::Reference<css::awt::XWindow> & xParent)667 css::uno::Reference< css::awt::XWindow > SAL_CALL FindTextToolbarController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& xParent )
668 {
669     css::uno::Reference< css::awt::XWindow > xItemWindow;
670 
671     VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
672     if ( pParent )
673     {
674         ToolBox* pToolbar = static_cast<ToolBox*>(pParent.get());
675         m_pFindTextFieldControl = VclPtr<FindTextFieldControl>::Create(pToolbar, m_xFrame, m_xContext);
676 
677         m_pFindTextFieldControl->connect_changed(LINK(this, FindTextToolbarController, EditModifyHdl));
678         SearchToolbarControllersManager::createControllersManager().loadSearchHistory(m_pFindTextFieldControl);
679     }
680     xItemWindow = VCLUnoHelper::GetInterface( m_pFindTextFieldControl );
681 
682     return xItemWindow;
683 }
684 
685 // XStatusListener
statusChanged(const css::frame::FeatureStateEvent & rEvent)686 void SAL_CALL FindTextToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
687 {
688     SolarMutexGuard aSolarMutexGuard;
689     if ( m_bDisposed )
690         return;
691 
692     OUString aFeatureURL = rEvent.FeatureURL.Complete;
693     if ( aFeatureURL == "AppendSearchHistory" )
694     {
695         m_pFindTextFieldControl->Remember_Impl(m_pFindTextFieldControl->get_active_text());
696     }
697     // enable up/down buttons in case there is already text (from the search history)
698     textfieldChanged();
699 }
700 
IMPL_LINK_NOARG(FindTextToolbarController,EditModifyHdl,weld::ComboBox &,void)701 IMPL_LINK_NOARG(FindTextToolbarController, EditModifyHdl, weld::ComboBox&, void)
702 {
703     // Clear SearchLabel when search string altered
704     #if HAVE_FEATURE_DESKTOP
705     SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::Empty);
706     #endif
707 
708     textfieldChanged();
709 }
710 
textfieldChanged()711 void FindTextToolbarController::textfieldChanged() {
712     // enable or disable item DownSearch/UpSearch/FindAll of findbar
713     VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() );
714     ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
715     if ( pToolBox && m_pFindTextFieldControl )
716     {
717         bool enableButtons = !m_pFindTextFieldControl->get_active_text().isEmpty();
718         pToolBox->EnableItem(m_nDownSearchId, enableButtons);
719         pToolBox->EnableItem(m_nUpSearchId, enableButtons);
720         pToolBox->EnableItem(m_nFindAllId, enableButtons);
721     }
722 }
723 
724 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> UpDownSearchToolboxController_Base;
725 class UpDownSearchToolboxController : public UpDownSearchToolboxController_Base
726 {
727 public:
728     enum Type { UP, DOWN };
729 
730     UpDownSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, Type eType );
731 
732     // XServiceInfo
733     virtual OUString SAL_CALL getImplementationName() override;
734     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
735     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
736 
737     // XComponent
738     virtual void SAL_CALL dispose() override;
739 
740     // XInitialization
741     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
742 
743     // XToolbarController
744     virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override;
745 
746     // XStatusListener
747     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
748 
749 private:
750     Type meType;
751 };
752 
UpDownSearchToolboxController(const css::uno::Reference<css::uno::XComponentContext> & rxContext,Type eType)753 UpDownSearchToolboxController::UpDownSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext, Type eType )
754     : UpDownSearchToolboxController_Base( rxContext,
755             css::uno::Reference< css::frame::XFrame >(),
756             (eType == UP) ? COMMAND_UPSEARCH:  COMMAND_DOWNSEARCH ),
757       meType( eType )
758 {
759 }
760 
761 // XServiceInfo
getImplementationName()762 OUString SAL_CALL UpDownSearchToolboxController::getImplementationName()
763 {
764     return meType == UpDownSearchToolboxController::UP?
765         u"com.sun.star.svx.UpSearchToolboxController"_ustr :
766         u"com.sun.star.svx.DownSearchToolboxController"_ustr;
767 }
768 
supportsService(const OUString & ServiceName)769 sal_Bool SAL_CALL UpDownSearchToolboxController::supportsService( const OUString& ServiceName )
770 {
771     return cppu::supportsService(this, ServiceName);
772 }
773 
getSupportedServiceNames()774 css::uno::Sequence< OUString > SAL_CALL UpDownSearchToolboxController::getSupportedServiceNames()
775 {
776     return { u"com.sun.star.frame.ToolbarController"_ustr };
777 }
778 
779 // XComponent
dispose()780 void SAL_CALL UpDownSearchToolboxController::dispose()
781 {
782     SolarMutexGuard aSolarMutexGuard;
783 
784     SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
785 
786     svt::ToolboxController::dispose();
787 }
788 
789 // XInitialization
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)790 void SAL_CALL UpDownSearchToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
791 {
792     svt::ToolboxController::initialize( aArguments );
793     SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
794 }
795 
796 // XToolbarController
execute(sal_Int16)797 void SAL_CALL UpDownSearchToolboxController::execute( sal_Int16 /*KeyModifier*/ )
798 {
799     if ( m_bDisposed )
800         throw css::lang::DisposedException();
801 
802     VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() );
803     ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
804 
805     impl_executeSearch(m_xContext, m_xFrame, pToolBox, meType == UP );
806 
807     css::frame::FeatureStateEvent aEvent;
808     aEvent.FeatureURL.Complete = "AppendSearchHistory";
809     css::uno::Reference< css::frame::XStatusListener > xStatusListener = SearchToolbarControllersManager::createControllersManager().findController(m_xFrame, COMMAND_FINDTEXT);
810     if (xStatusListener.is())
811         xStatusListener->statusChanged( aEvent );
812 }
813 
814 // XStatusListener
statusChanged(const css::frame::FeatureStateEvent &)815 void SAL_CALL UpDownSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ )
816 {
817 }
818 
819 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> MatchCaseToolboxController_Base;
820 class MatchCaseToolboxController : public MatchCaseToolboxController_Base
821 {
822 public:
823     MatchCaseToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
824 
825     // XServiceInfo
826     virtual OUString SAL_CALL getImplementationName() override;
827     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
828     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
829 
830     // XComponent
831     virtual void SAL_CALL dispose() override;
832 
833     // XInitialization
834     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
835 
836     // XToolbarController
837     virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
838 
839     // XStatusListener
840     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
841 
842     virtual void SAL_CALL click() override;
843 
844 private:
845     VclPtr<CheckButtonItemWindow> m_xMatchCaseControl;
846 };
847 
MatchCaseToolboxController(const css::uno::Reference<css::uno::XComponentContext> & rxContext)848 MatchCaseToolboxController::MatchCaseToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
849     : MatchCaseToolboxController_Base( rxContext,
850         css::uno::Reference< css::frame::XFrame >(),
851         COMMAND_MATCHCASE )
852     , m_xMatchCaseControl(nullptr)
853 {
854 }
855 
856 // XServiceInfo
getImplementationName()857 OUString SAL_CALL MatchCaseToolboxController::getImplementationName()
858 {
859     return u"com.sun.star.svx.MatchCaseToolboxController"_ustr;
860 }
861 
supportsService(const OUString & ServiceName)862 sal_Bool SAL_CALL MatchCaseToolboxController::supportsService( const OUString& ServiceName )
863 {
864     return cppu::supportsService(this, ServiceName);
865 }
866 
getSupportedServiceNames()867 css::uno::Sequence< OUString > SAL_CALL MatchCaseToolboxController::getSupportedServiceNames()
868 {
869     return { u"com.sun.star.frame.ToolbarController"_ustr };
870 }
871 
872 // XComponent
dispose()873 void SAL_CALL MatchCaseToolboxController::dispose()
874 {
875     SolarMutexGuard aSolarMutexGuard;
876 
877     SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
878 
879     svt::ToolboxController::dispose();
880 
881     m_xMatchCaseControl.disposeAndClear();
882 }
883 
884 // XInitialization
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)885 void SAL_CALL MatchCaseToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
886 {
887     svt::ToolboxController::initialize(aArguments);
888 
889     SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
890 }
891 
createItemWindow(const css::uno::Reference<css::awt::XWindow> & xParent)892 css::uno::Reference< css::awt::XWindow > SAL_CALL MatchCaseToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& xParent )
893 {
894     css::uno::Reference< css::awt::XWindow > xItemWindow;
895 
896     VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
897     if ( pParent )
898     {
899         ToolBox* pToolbar = static_cast<ToolBox*>(pParent.get());
900         m_xMatchCaseControl = VclPtr<CheckButtonItemWindow>::Create(pToolbar, SvxResId(RID_SVXSTR_FINDBAR_MATCHCASE));
901     }
902     xItemWindow = VCLUnoHelper::GetInterface(m_xMatchCaseControl);
903 
904     return xItemWindow;
905 }
906 
907 // XStatusListener
statusChanged(const css::frame::FeatureStateEvent &)908 void SAL_CALL MatchCaseToolboxController::statusChanged( const css::frame::FeatureStateEvent& )
909 {
910 }
911 
click()912 void SAL_CALL MatchCaseToolboxController::click()
913 {
914     if (m_xMatchCaseControl)
915     {
916         bool bCurrent = m_xMatchCaseControl->get_active();
917         m_xMatchCaseControl->set_active(!bCurrent);
918     }
919 }
920 
921 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> MatchDiacriticsToolboxController_Base;
922 class MatchDiacriticsToolboxController : public MatchDiacriticsToolboxController_Base
923 {
924 public:
925     MatchDiacriticsToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
926 
927     // XServiceInfo
928     virtual OUString SAL_CALL getImplementationName() override;
929     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
930     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
931 
932     // XComponent
933     virtual void SAL_CALL dispose() override;
934 
935     // XInitialization
936     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
937 
938     // XToolbarController
939     virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
940 
941     // XStatusListener
942     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
943 
944     virtual void SAL_CALL click() override;
945 
946 private:
947     VclPtr<CheckButtonItemWindow> m_xMatchDiacriticsControl;
948 };
949 
MatchDiacriticsToolboxController(const css::uno::Reference<css::uno::XComponentContext> & rxContext)950 MatchDiacriticsToolboxController::MatchDiacriticsToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
951     : MatchDiacriticsToolboxController_Base( rxContext,
952         css::uno::Reference< css::frame::XFrame >(),
953         COMMAND_MATCHDIACRITICS )
954     , m_xMatchDiacriticsControl(nullptr)
955 {
956 }
957 
958 // XServiceInfo
getImplementationName()959 OUString SAL_CALL MatchDiacriticsToolboxController::getImplementationName()
960 {
961     return u"com.sun.star.svx.MatchDiacriticsToolboxController"_ustr;
962 }
963 
supportsService(const OUString & ServiceName)964 sal_Bool SAL_CALL MatchDiacriticsToolboxController::supportsService( const OUString& ServiceName )
965 {
966     return cppu::supportsService(this, ServiceName);
967 }
968 
getSupportedServiceNames()969 css::uno::Sequence< OUString > SAL_CALL MatchDiacriticsToolboxController::getSupportedServiceNames()
970 {
971     return { u"com.sun.star.frame.ToolbarController"_ustr };
972 }
973 
974 // XComponent
dispose()975 void SAL_CALL MatchDiacriticsToolboxController::dispose()
976 {
977     SolarMutexGuard aSolarMutexGuard;
978 
979     SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
980 
981     svt::ToolboxController::dispose();
982 
983     m_xMatchDiacriticsControl.disposeAndClear();
984 }
985 
986 // XInitialization
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)987 void SAL_CALL MatchDiacriticsToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
988 {
989     svt::ToolboxController::initialize(aArguments);
990 
991     SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
992 }
993 
createItemWindow(const css::uno::Reference<css::awt::XWindow> & xParent)994 css::uno::Reference< css::awt::XWindow > SAL_CALL MatchDiacriticsToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& xParent )
995 {
996     css::uno::Reference< css::awt::XWindow > xItemWindow;
997 
998     VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
999     if ( pParent )
1000     {
1001         ToolBox* pToolbar = static_cast<ToolBox*>(pParent.get());
1002         m_xMatchDiacriticsControl = VclPtr<CheckButtonItemWindow>::Create(pToolbar, SvxResId(RID_SVXSTR_FINDBAR_MATCHDIACRITICS));
1003     }
1004     xItemWindow = VCLUnoHelper::GetInterface(m_xMatchDiacriticsControl);
1005 
1006     return xItemWindow;
1007 }
1008 
1009 // XStatusListener
statusChanged(const css::frame::FeatureStateEvent &)1010 void SAL_CALL MatchDiacriticsToolboxController::statusChanged( const css::frame::FeatureStateEvent& )
1011 {
1012 }
1013 
click()1014 void SAL_CALL MatchDiacriticsToolboxController::click()
1015 {
1016     if (m_xMatchDiacriticsControl)
1017     {
1018         bool bCurrent = m_xMatchDiacriticsControl->get_active();
1019         m_xMatchDiacriticsControl->set_active(!bCurrent);
1020     }
1021 }
1022 
1023 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> SearchFormattedToolboxController_Base;
1024 class SearchFormattedToolboxController : public SearchFormattedToolboxController_Base
1025 {
1026 public:
1027     SearchFormattedToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
1028 
1029     // XServiceInfo
1030     virtual OUString SAL_CALL getImplementationName() override;
1031     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1032     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
1033 
1034     // XComponent
1035     virtual void SAL_CALL dispose() override;
1036 
1037     // XInitialization
1038     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
1039 
1040     // XToolbarController
1041     virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
1042 
1043     // XStatusListener
1044     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
1045 
1046 private:
1047     VclPtr<CheckButtonItemWindow> m_xSearchFormattedControl;
1048 };
1049 
SearchFormattedToolboxController(const css::uno::Reference<css::uno::XComponentContext> & rxContext)1050 SearchFormattedToolboxController::SearchFormattedToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
1051     : SearchFormattedToolboxController_Base( rxContext,
1052         css::uno::Reference< css::frame::XFrame >(),
1053         COMMAND_SEARCHFORMATTED )
1054     , m_xSearchFormattedControl(nullptr)
1055 {
1056 }
1057 
1058 // XServiceInfo
getImplementationName()1059 OUString SAL_CALL SearchFormattedToolboxController::getImplementationName()
1060 {
1061     return u"com.sun.star.svx.SearchFormattedToolboxController"_ustr;
1062 }
1063 
supportsService(const OUString & ServiceName)1064 sal_Bool SAL_CALL SearchFormattedToolboxController::supportsService( const OUString& ServiceName )
1065 {
1066     return cppu::supportsService(this, ServiceName);
1067 }
1068 
getSupportedServiceNames()1069 css::uno::Sequence< OUString > SAL_CALL SearchFormattedToolboxController::getSupportedServiceNames()
1070 {
1071     return { u"com.sun.star.frame.ToolbarController"_ustr };
1072 }
1073 
1074 // XComponent
dispose()1075 void SAL_CALL SearchFormattedToolboxController::dispose()
1076 {
1077     SolarMutexGuard aSolarMutexGuard;
1078 
1079     SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
1080 
1081     svt::ToolboxController::dispose();
1082 
1083     m_xSearchFormattedControl.disposeAndClear();
1084 }
1085 
1086 // XInitialization
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)1087 void SAL_CALL SearchFormattedToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
1088 {
1089     svt::ToolboxController::initialize(aArguments);
1090 
1091     SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
1092 }
1093 
createItemWindow(const css::uno::Reference<css::awt::XWindow> & xParent)1094 css::uno::Reference< css::awt::XWindow > SAL_CALL SearchFormattedToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& xParent )
1095 {
1096     css::uno::Reference< css::awt::XWindow > xItemWindow;
1097 
1098     VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
1099     if ( pParent )
1100     {
1101         ToolBox* pToolbar = static_cast<ToolBox*>(pParent.get());
1102         m_xSearchFormattedControl = VclPtr<CheckButtonItemWindow>::Create(pToolbar, SvxResId(RID_SVXSTR_FINDBAR_SEARCHFORMATTED));
1103     }
1104     xItemWindow = VCLUnoHelper::GetInterface(m_xSearchFormattedControl);
1105 
1106     return xItemWindow;
1107 }
1108 
1109 // XStatusListener
statusChanged(const css::frame::FeatureStateEvent &)1110 void SAL_CALL SearchFormattedToolboxController::statusChanged( const css::frame::FeatureStateEvent& )
1111 {
1112 }
1113 
1114 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> FindAllToolboxController_Base;
1115 class FindAllToolboxController : public FindAllToolboxController_Base
1116 {
1117 public:
1118     FindAllToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
1119 
1120     // XServiceInfo
1121     virtual OUString SAL_CALL getImplementationName() override;
1122     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1123     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
1124 
1125     // XComponent
1126     virtual void SAL_CALL dispose() override;
1127 
1128     // XInitialization
1129     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
1130 
1131     // XToolbarController
1132     virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override;
1133 
1134     // XStatusListener
1135     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
1136 };
1137 
FindAllToolboxController(const css::uno::Reference<css::uno::XComponentContext> & rxContext)1138 FindAllToolboxController::FindAllToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext )
1139     : FindAllToolboxController_Base( rxContext,
1140             css::uno::Reference< css::frame::XFrame >(),
1141             ".uno:FindAll" )
1142 {
1143 }
1144 
1145 // XServiceInfo
getImplementationName()1146 OUString SAL_CALL FindAllToolboxController::getImplementationName()
1147 {
1148     return u"com.sun.star.svx.FindAllToolboxController"_ustr;
1149 }
1150 
1151 
supportsService(const OUString & ServiceName)1152 sal_Bool SAL_CALL FindAllToolboxController::supportsService( const OUString& ServiceName )
1153 {
1154     return cppu::supportsService(this, ServiceName);
1155 }
1156 
getSupportedServiceNames()1157 css::uno::Sequence< OUString > SAL_CALL FindAllToolboxController::getSupportedServiceNames()
1158 {
1159     return { u"com.sun.star.frame.ToolbarController"_ustr };
1160 }
1161 
1162 // XComponent
dispose()1163 void SAL_CALL FindAllToolboxController::dispose()
1164 {
1165     SolarMutexGuard aSolarMutexGuard;
1166 
1167     SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
1168 
1169     svt::ToolboxController::dispose();
1170 }
1171 
1172 // XInitialization
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)1173 void SAL_CALL FindAllToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
1174 {
1175     svt::ToolboxController::initialize( aArguments );
1176     SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
1177 }
1178 
1179 // XToolbarController
execute(sal_Int16)1180 void SAL_CALL FindAllToolboxController::execute( sal_Int16 /*KeyModifier*/ )
1181 {
1182     if ( m_bDisposed )
1183         throw css::lang::DisposedException();
1184 
1185     VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() );
1186     ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
1187 
1188     impl_executeSearch(m_xContext, m_xFrame, pToolBox, false, true);
1189 }
1190 
1191 // XStatusListener
statusChanged(const css::frame::FeatureStateEvent &)1192 void SAL_CALL FindAllToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ )
1193 {
1194 }
1195 
1196 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> ExitSearchToolboxController_Base;
1197 class ExitSearchToolboxController : public ExitSearchToolboxController_Base
1198 {
1199 public:
1200     ExitSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
1201 
1202     // XServiceInfo
1203     virtual OUString SAL_CALL getImplementationName() override;
1204     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1205     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
1206 
1207     // XComponent
1208     virtual void SAL_CALL dispose() override;
1209 
1210     // XInitialization
1211     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
1212 
1213     // XToolbarController
1214     virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override;
1215 
1216     // XStatusListener
1217     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
1218 };
1219 
ExitSearchToolboxController(const css::uno::Reference<css::uno::XComponentContext> & rxContext)1220 ExitSearchToolboxController::ExitSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext )
1221     : ExitSearchToolboxController_Base( rxContext,
1222             css::uno::Reference< css::frame::XFrame >(),
1223             ".uno:ExitSearch" )
1224 {
1225 }
1226 
1227 // XServiceInfo
getImplementationName()1228 OUString SAL_CALL ExitSearchToolboxController::getImplementationName()
1229 {
1230     return u"com.sun.star.svx.ExitFindbarToolboxController"_ustr;
1231 }
1232 
1233 
supportsService(const OUString & ServiceName)1234 sal_Bool SAL_CALL ExitSearchToolboxController::supportsService( const OUString& ServiceName )
1235 {
1236     return cppu::supportsService(this, ServiceName);
1237 }
1238 
getSupportedServiceNames()1239 css::uno::Sequence< OUString > SAL_CALL ExitSearchToolboxController::getSupportedServiceNames()
1240 {
1241     return { u"com.sun.star.frame.ToolbarController"_ustr };
1242 }
1243 
1244 // XComponent
dispose()1245 void SAL_CALL ExitSearchToolboxController::dispose()
1246 {
1247     SolarMutexGuard aSolarMutexGuard;
1248 
1249     SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
1250 
1251     svt::ToolboxController::dispose();
1252 }
1253 
1254 // XInitialization
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)1255 void SAL_CALL ExitSearchToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
1256 {
1257     svt::ToolboxController::initialize( aArguments );
1258     SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
1259 }
1260 
1261 // XToolbarController
execute(sal_Int16)1262 void SAL_CALL ExitSearchToolboxController::execute( sal_Int16 /*KeyModifier*/ )
1263 {
1264     vcl::Window *pFocusWindow = Application::GetFocusWindow();
1265     if ( pFocusWindow )
1266         pFocusWindow->GrabFocusToDocument();
1267 
1268     // hide the findbar
1269     css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY);
1270     if (xPropSet.is())
1271     {
1272         css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
1273         css::uno::Any aValue = xPropSet->getPropertyValue(u"LayoutManager"_ustr);
1274         aValue >>= xLayoutManager;
1275         if (xLayoutManager.is())
1276         {
1277             static constexpr OUString sResourceURL( u"private:resource/toolbar/findbar"_ustr );
1278             xLayoutManager->hideElement( sResourceURL );
1279             xLayoutManager->destroyElement( sResourceURL );
1280         }
1281     }
1282 }
1283 
1284 // XStatusListener
statusChanged(const css::frame::FeatureStateEvent &)1285 void SAL_CALL ExitSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ )
1286 {
1287 }
1288 
1289 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> SearchLabelToolboxController_Base;
1290 class SearchLabelToolboxController : public SearchLabelToolboxController_Base
1291 {
1292 public:
1293     SearchLabelToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
1294 
1295     // XServiceInfo
1296     virtual OUString SAL_CALL getImplementationName() override;
1297     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1298     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
1299 
1300     // XComponent
1301     virtual void SAL_CALL dispose() override;
1302 
1303     // XInitialization
1304     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
1305 
1306     // XToolbarController
1307     virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
1308 
1309     // XStatusListener
1310     virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
1311 
1312 private:
1313     VclPtr<LabelItemWindow> m_xSL;
1314 };
1315 
SearchLabelToolboxController(const css::uno::Reference<css::uno::XComponentContext> & rxContext)1316 SearchLabelToolboxController::SearchLabelToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext )
1317     : SearchLabelToolboxController_Base( rxContext,
1318             css::uno::Reference< css::frame::XFrame >(),
1319             ".uno:SearchLabel" )
1320 {
1321 }
1322 
1323 // XServiceInfo
getImplementationName()1324 OUString SAL_CALL SearchLabelToolboxController::getImplementationName()
1325 {
1326     return u"com.sun.star.svx.SearchLabelToolboxController"_ustr;
1327 }
1328 
1329 
supportsService(const OUString & ServiceName)1330 sal_Bool SAL_CALL SearchLabelToolboxController::supportsService( const OUString& ServiceName )
1331 {
1332     return cppu::supportsService(this, ServiceName);
1333 }
1334 
getSupportedServiceNames()1335 css::uno::Sequence< OUString > SAL_CALL SearchLabelToolboxController::getSupportedServiceNames()
1336 {
1337     return { u"com.sun.star.frame.ToolbarController"_ustr };
1338 }
1339 
1340 // XComponent
dispose()1341 void SAL_CALL SearchLabelToolboxController::dispose()
1342 {
1343     SolarMutexGuard aSolarMutexGuard;
1344 
1345     SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
1346 
1347     svt::ToolboxController::dispose();
1348     m_xSL.disposeAndClear();
1349 }
1350 
1351 // XInitialization
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)1352 void SAL_CALL SearchLabelToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
1353 {
1354     svt::ToolboxController::initialize( aArguments );
1355     SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
1356 }
1357 
1358 // XStatusListener
statusChanged(const css::frame::FeatureStateEvent &)1359 void SAL_CALL SearchLabelToolboxController::statusChanged( const css::frame::FeatureStateEvent& )
1360 {
1361     if (m_xSL)
1362     {
1363         OUString aStr = SvxSearchDialogWrapper::GetSearchLabel();
1364         m_xSL->set_label(aStr);
1365         m_xSL->SetOptimalSize();
1366         Size aSize(m_xSL->GetSizePixel());
1367         tools::Long nWidth = !aStr.isEmpty() ? aSize.getWidth() : 16;
1368         m_xSL->SetSizePixel(Size(nWidth, aSize.Height()));
1369     }
1370 }
1371 
createItemWindow(const css::uno::Reference<css::awt::XWindow> & Parent)1372 css::uno::Reference< css::awt::XWindow > SAL_CALL SearchLabelToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent )
1373 {
1374     ToolBox* pToolBox = nullptr;
1375     ToolBoxItemId nId;
1376     if (getToolboxId(nId, &pToolBox))
1377         pToolBox->SetItemWindowNonInteractive(nId, true);
1378 
1379     m_xSL = VclPtr<LabelItemWindow>::Create(VCLUnoHelper::GetWindow(Parent), "");
1380     m_xSL->SetSizePixel(Size(16, m_xSL->GetSizePixel().Height()));
1381     return VCLUnoHelper::GetInterface(m_xSL);
1382 }
1383 
1384 // protocol handler for "vnd.sun.star.findbar:*" URLs
1385 // The dispatch object will be used for shortcut commands for findbar
1386 class FindbarDispatcher : public css::lang::XServiceInfo,
1387                           public css::lang::XInitialization,
1388                           public css::frame::XDispatchProvider,
1389                           public css::frame::XDispatch,
1390                           public ::cppu::OWeakObject
1391 {
1392 public:
1393 
1394     FindbarDispatcher();
1395     virtual ~FindbarDispatcher() override;
1396 
1397     // XInterface
1398     virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
1399     virtual void SAL_CALL acquire() noexcept override;
1400     virtual void SAL_CALL release() noexcept override;
1401 
1402     // XServiceInfo
1403     virtual OUString SAL_CALL getImplementationName() override;
1404     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1405     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
1406 
1407     // XInitialization
1408     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
1409 
1410     // XDispatchProvider
1411     virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch( const css::util::URL& aURL, const OUString& sTargetFrameName , sal_Int32 nSearchFlags ) override;
1412     virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptions    ) override;
1413 
1414     // XDispatch
1415     virtual void SAL_CALL dispatch( const css::util::URL& aURL, const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) override;
1416     virtual void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xListener, const css::util::URL& aURL ) override;
1417     virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xListener, const css::util::URL& aURL ) override;
1418 
1419 private:
1420 
1421     css::uno::Reference< css::frame::XFrame > m_xFrame;
1422 
1423 };
1424 
FindbarDispatcher()1425 FindbarDispatcher::FindbarDispatcher()
1426 {
1427 }
1428 
~FindbarDispatcher()1429 FindbarDispatcher::~FindbarDispatcher()
1430 {
1431     m_xFrame = nullptr;
1432 }
1433 
1434 // XInterface
queryInterface(const css::uno::Type & aType)1435 css::uno::Any SAL_CALL FindbarDispatcher::queryInterface( const css::uno::Type& aType )
1436 {
1437     css::uno::Any aReturn( ::cppu::queryInterface( aType,
1438         static_cast< css::lang::XServiceInfo* >(this),
1439         static_cast< css::lang::XInitialization* >(this),
1440         static_cast< css::frame::XDispatchProvider* >(this),
1441         static_cast< css::frame::XDispatch* >(this)) );
1442 
1443     if ( aReturn.hasValue() )
1444         return aReturn;
1445 
1446     return OWeakObject::queryInterface( aType );
1447 }
1448 
acquire()1449 void SAL_CALL FindbarDispatcher::acquire() noexcept
1450 {
1451     OWeakObject::acquire();
1452 }
1453 
release()1454 void SAL_CALL FindbarDispatcher::release() noexcept
1455 {
1456     OWeakObject::release();
1457 }
1458 
1459 // XServiceInfo
getImplementationName()1460 OUString SAL_CALL FindbarDispatcher::getImplementationName()
1461 {
1462     return u"com.sun.star.comp.svx.Impl.FindbarDispatcher"_ustr;
1463 }
1464 
supportsService(const OUString & ServiceName)1465 sal_Bool SAL_CALL FindbarDispatcher::supportsService( const OUString& ServiceName )
1466 {
1467     return cppu::supportsService(this, ServiceName);
1468 }
1469 
getSupportedServiceNames()1470 css::uno::Sequence< OUString > SAL_CALL FindbarDispatcher::getSupportedServiceNames()
1471 {
1472     return { u"com.sun.star.comp.svx.FindbarDispatcher"_ustr, u"com.sun.star.frame.ProtocolHandler"_ustr };
1473 }
1474 
1475 // XInitialization
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)1476 void SAL_CALL FindbarDispatcher::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
1477 {
1478     if ( aArguments.hasElements() )
1479         aArguments[0] >>= m_xFrame;
1480 }
1481 
1482 // XDispatchProvider
queryDispatch(const css::util::URL & aURL,const OUString &,sal_Int32)1483 css::uno::Reference< css::frame::XDispatch > SAL_CALL FindbarDispatcher::queryDispatch( const css::util::URL& aURL, const OUString& /*sTargetFrameName*/, sal_Int32 /*nSearchFlags*/ )
1484 {
1485     css::uno::Reference< css::frame::XDispatch > xDispatch;
1486 
1487     if ( aURL.Protocol == "vnd.sun.star.findbar:" )
1488         xDispatch = this;
1489 
1490     return xDispatch;
1491 }
1492 
queryDispatches(const css::uno::Sequence<css::frame::DispatchDescriptor> & seqDescripts)1493 css::uno::Sequence < css::uno::Reference< css::frame::XDispatch > > SAL_CALL FindbarDispatcher::queryDispatches( const css::uno::Sequence < css::frame::DispatchDescriptor >& seqDescripts )
1494 {
1495     sal_Int32 nCount = seqDescripts.getLength();
1496     css::uno::Sequence < css::uno::Reference < XDispatch > > lDispatcher( nCount );
1497 
1498     std::transform(seqDescripts.begin(), seqDescripts.end(), lDispatcher.getArray(),
1499         [this](const css::frame::DispatchDescriptor& rDescript) -> css::uno::Reference < XDispatch > {
1500             return queryDispatch( rDescript.FeatureURL, rDescript.FrameName, rDescript.SearchFlags ); });
1501 
1502     return lDispatcher;
1503 }
1504 
1505 // XDispatch
dispatch(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> &)1506 void SAL_CALL FindbarDispatcher::dispatch( const css::util::URL& aURL, const css::uno::Sequence < css::beans::PropertyValue >& /*lArgs*/ )
1507 {
1508     //vnd.sun.star.findbar:FocusToFindbar  - set cursor to the FindTextFieldControl of the findbar
1509     if ( aURL.Path != "FocusToFindbar" )
1510         return;
1511 
1512     css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY);
1513     if(!xPropSet.is())
1514         return;
1515 
1516     css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
1517     css::uno::Any aValue = xPropSet->getPropertyValue(u"LayoutManager"_ustr);
1518     aValue >>= xLayoutManager;
1519     if (!xLayoutManager.is())
1520         return;
1521 
1522     static constexpr OUString sResourceURL( u"private:resource/toolbar/findbar"_ustr );
1523     css::uno::Reference< css::ui::XUIElement > xUIElement = xLayoutManager->getElement(sResourceURL);
1524     if (!xUIElement.is())
1525     {
1526         // show the findbar if necessary
1527         xLayoutManager->createElement( sResourceURL );
1528         xLayoutManager->showElement( sResourceURL );
1529         xUIElement = xLayoutManager->getElement( sResourceURL );
1530         if ( !xUIElement.is() )
1531             return;
1532     }
1533 
1534     css::uno::Reference< css::awt::XWindow > xWindow(xUIElement->getRealInterface(), css::uno::UNO_QUERY);
1535     VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
1536     ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
1537     pToolBox->set_id(u"FindBar"_ustr);
1538     if ( !pToolBox )
1539         return;
1540 
1541     ToolBox::ImplToolItems::size_type nItemCount = pToolBox->GetItemCount();
1542     for ( ToolBox::ImplToolItems::size_type i=0; i<nItemCount; ++i )
1543     {
1544         ToolBoxItemId id = pToolBox->GetItemId(i);
1545         OUString sItemCommand = pToolBox->GetItemCommand(id);
1546         if ( sItemCommand == COMMAND_FINDTEXT )
1547         {
1548             vcl::Window* pItemWin = pToolBox->GetItemWindow( id );
1549             if ( pItemWin )
1550             {
1551                 SolarMutexGuard aSolarMutexGuard;
1552                 FindTextFieldControl* pFindTextFieldControl = dynamic_cast<FindTextFieldControl*>(pItemWin);
1553                 if ( pFindTextFieldControl )
1554                     pFindTextFieldControl->SetTextToSelected_Impl();
1555                 pItemWin->GrabFocus();
1556                 return;
1557             }
1558         }
1559     }
1560 }
1561 
addStatusListener(const css::uno::Reference<css::frame::XStatusListener> &,const css::util::URL &)1562 void SAL_CALL FindbarDispatcher::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xControl*/, const css::util::URL& /*aURL*/ )
1563 {
1564 }
1565 
removeStatusListener(const css::uno::Reference<css::frame::XStatusListener> &,const css::util::URL &)1566 void SAL_CALL FindbarDispatcher::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xControl*/, const css::util::URL& /*aURL*/ )
1567 {
1568 }
1569 
1570 }
1571 
1572 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_svx_FindTextToolboxController_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)1573 com_sun_star_svx_FindTextToolboxController_get_implementation(
1574     css::uno::XComponentContext *context,
1575     css::uno::Sequence<css::uno::Any> const &)
1576 {
1577     return cppu::acquire(new FindTextToolbarController(context));
1578 }
1579 
1580 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_svx_ExitFindbarToolboxController_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)1581 com_sun_star_svx_ExitFindbarToolboxController_get_implementation(
1582     css::uno::XComponentContext *context,
1583     css::uno::Sequence<css::uno::Any> const &)
1584 {
1585     return cppu::acquire(new ExitSearchToolboxController(context));
1586 }
1587 
1588 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_svx_UpSearchToolboxController_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)1589 com_sun_star_svx_UpSearchToolboxController_get_implementation(
1590     css::uno::XComponentContext *context,
1591     css::uno::Sequence<css::uno::Any> const &)
1592 {
1593     return cppu::acquire(new UpDownSearchToolboxController(context, UpDownSearchToolboxController::UP));
1594 }
1595 
1596 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_svx_DownSearchToolboxController_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)1597 com_sun_star_svx_DownSearchToolboxController_get_implementation(
1598     css::uno::XComponentContext *context,
1599     css::uno::Sequence<css::uno::Any> const &)
1600 {
1601     return cppu::acquire(new UpDownSearchToolboxController(context, UpDownSearchToolboxController::DOWN));
1602 }
1603 
1604 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_svx_MatchCaseToolboxController_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)1605 com_sun_star_svx_MatchCaseToolboxController_get_implementation(
1606     css::uno::XComponentContext *context,
1607     css::uno::Sequence<css::uno::Any> const &)
1608 {
1609     return cppu::acquire(new MatchCaseToolboxController(context));
1610 }
1611 
1612 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_svx_MatchDiacriticsToolboxController_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)1613 com_sun_star_svx_MatchDiacriticsToolboxController_get_implementation(
1614     css::uno::XComponentContext *context,
1615     css::uno::Sequence<css::uno::Any> const &)
1616 {
1617     return cppu::acquire(new MatchDiacriticsToolboxController(context));
1618 }
1619 
1620 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_svx_SearchFormattedToolboxController_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)1621 com_sun_star_svx_SearchFormattedToolboxController_get_implementation(
1622     css::uno::XComponentContext *context,
1623     css::uno::Sequence<css::uno::Any> const &)
1624 {
1625     return cppu::acquire(new SearchFormattedToolboxController(context));
1626 }
1627 
1628 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_svx_FindAllToolboxController_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)1629 com_sun_star_svx_FindAllToolboxController_get_implementation(
1630     css::uno::XComponentContext *context,
1631     css::uno::Sequence<css::uno::Any> const &)
1632 {
1633     return cppu::acquire(new FindAllToolboxController(context));
1634 }
1635 
1636 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_svx_SearchLabelToolboxController_get_implementation(css::uno::XComponentContext * context,css::uno::Sequence<css::uno::Any> const &)1637 com_sun_star_svx_SearchLabelToolboxController_get_implementation(
1638     css::uno::XComponentContext *context,
1639     css::uno::Sequence<css::uno::Any> const &)
1640 {
1641     return cppu::acquire(new SearchLabelToolboxController(context));
1642 }
1643 
1644 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_svx_Impl_FindbarDispatcher_get_implementation(SAL_UNUSED_PARAMETER css::uno::XComponentContext *,css::uno::Sequence<css::uno::Any> const &)1645 com_sun_star_comp_svx_Impl_FindbarDispatcher_get_implementation(
1646     SAL_UNUSED_PARAMETER css::uno::XComponentContext *,
1647     css::uno::Sequence<css::uno::Any> const &)
1648 {
1649     return cppu::acquire(new FindbarDispatcher);
1650 }
1651 
1652 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1653