Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / tbxctrls / tbunosearchcontrollers.cxx
blob9ae446b50346c64ff5b33a7d029e2299b1220886
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <map>
23 #include <utility>
24 #include <vector>
26 #include <config_feature_desktop.h>
27 #include <officecfg/Office/Common.hxx>
29 #include <svx/strings.hrc>
30 #include <svx/dialmgr.hxx>
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/ui/XUIElement.hpp>
47 #include <com/sun/star/util/URL.hpp>
48 #include <com/sun/star/util/URLTransformer.hpp>
49 #include <com/sun/star/util/SearchAlgorithms.hpp>
50 #include <com/sun/star/util/SearchAlgorithms2.hpp>
52 #include <vcl/InterimItemWindow.hxx>
53 #include <svl/ctloptions.hxx>
54 #include <svl/srchitem.hxx>
55 #include <svtools/acceleratorexecute.hxx>
56 #include <svtools/toolboxcontroller.hxx>
57 #include <toolkit/helper/vclunohelper.hxx>
58 #include <vcl/toolbox.hxx>
59 #include <vcl/svapp.hxx>
60 #include <svx/labelitemwindow.hxx>
61 #include <svx/srchdlg.hxx>
62 #include <vcl/event.hxx>
64 #include <findtextfield.hxx>
66 using namespace css;
68 namespace {
70 constexpr OUStringLiteral COMMAND_FINDTEXT = u".uno:FindText";
71 constexpr OUStringLiteral COMMAND_DOWNSEARCH = u".uno:DownSearch";
72 constexpr OUStringLiteral COMMAND_UPSEARCH = u".uno:UpSearch";
73 constexpr OUStringLiteral COMMAND_FINDALL = u".uno:FindAll";
74 constexpr OUStringLiteral COMMAND_MATCHCASE = u".uno:MatchCase";
75 constexpr OUStringLiteral COMMAND_SEARCHFORMATTED = u".uno:SearchFormattedDisplayString";
77 class CheckButtonItemWindow final : public InterimItemWindow
79 public:
80 CheckButtonItemWindow(vcl::Window* pParent, const OUString& rLabel)
81 : InterimItemWindow(pParent, "svx/ui/checkbuttonbox.ui", "CheckButtonBox")
82 , m_xWidget(m_xBuilder->weld_check_button("checkbutton"))
84 InitControlBase(m_xWidget.get());
86 m_xWidget->connect_key_press(LINK(this, CheckButtonItemWindow, KeyInputHdl));
87 m_xWidget->set_label(rLabel);
88 SetSizePixel(m_xWidget->get_preferred_size());
91 bool get_active() const
93 return m_xWidget->get_active();
96 virtual void dispose() override
98 m_xWidget.reset();
99 InterimItemWindow::dispose();
102 virtual ~CheckButtonItemWindow() override
104 disposeOnce();
107 private:
108 std::unique_ptr<weld::CheckButton> m_xWidget;
110 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
113 IMPL_LINK(CheckButtonItemWindow, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
115 return ChildKeyInput(rKeyEvent);
118 void impl_executeSearch( const css::uno::Reference< css::uno::XComponentContext >& rxContext,
119 const css::uno::Reference< css::frame::XFrame >& xFrame,
120 const ToolBox* pToolBox,
121 const bool aSearchBackwards,
122 const bool aFindAll = false )
124 css::uno::Reference< css::util::XURLTransformer > xURLTransformer( css::util::URLTransformer::create( rxContext ) );
125 css::util::URL aURL;
126 aURL.Complete = ".uno:ExecuteSearch";
127 xURLTransformer->parseStrict(aURL);
129 OUString sFindText;
130 bool aMatchCase = false;
131 bool bSearchFormatted = false;
132 if ( pToolBox )
134 ToolBox::ImplToolItems::size_type nItemCount = pToolBox->GetItemCount();
135 for ( ToolBox::ImplToolItems::size_type i=0; i<nItemCount; ++i )
137 ToolBoxItemId id = pToolBox->GetItemId(i);
138 OUString sItemCommand = pToolBox->GetItemCommand(id);
139 if ( sItemCommand == COMMAND_FINDTEXT )
141 FindTextFieldControl* pItemWin = static_cast<FindTextFieldControl*>(pToolBox->GetItemWindow(id));
142 if (pItemWin)
144 sFindText = pItemWin->get_active_text();
145 if (aFindAll && !pItemWin->ControlHasFocus())
146 pItemWin->GetFocus();
148 } else if ( sItemCommand == COMMAND_MATCHCASE )
150 CheckButtonItemWindow* pItemWin = static_cast<CheckButtonItemWindow*>(pToolBox->GetItemWindow(id));
151 if (pItemWin)
152 aMatchCase = pItemWin->get_active();
153 } else if ( sItemCommand == COMMAND_SEARCHFORMATTED )
155 CheckButtonItemWindow* pItemWin = static_cast<CheckButtonItemWindow*>(pToolBox->GetItemWindow(id));
156 if (pItemWin)
157 bSearchFormatted = pItemWin->get_active();
162 TransliterationFlags nFlags = TransliterationFlags::NONE;
163 if (!aMatchCase)
164 nFlags |= TransliterationFlags::IGNORE_CASE;
165 if (SvtCTLOptions::IsCTLFontEnabled())
166 nFlags |= TransliterationFlags::IGNORE_DIACRITICS_CTL
167 | TransliterationFlags::IGNORE_KASHIDA_CTL;
169 auto aArgs( comphelper::InitPropertySequence( {
170 { "SearchItem.SearchString", css::uno::Any( sFindText ) },
171 // Related tdf#102506: make Find Bar Ctrl+F searching by value by default
172 { "SearchItem.CellType", css::uno::Any( sal_Int16(SvxSearchCellType::VALUE) ) },
173 { "SearchItem.Backward", css::uno::Any( aSearchBackwards ) },
174 { "SearchItem.SearchFlags", css::uno::Any( sal_Int32(0) ) },
175 { "SearchItem.TransliterateFlags", css::uno::Any( static_cast<sal_Int32>(nFlags) ) },
176 { "SearchItem.Command", css::uno::Any( static_cast<sal_Int16>(aFindAll ?SvxSearchCmd::FIND_ALL : SvxSearchCmd::FIND ) ) },
177 { "SearchItem.AlgorithmType", css::uno::Any( sal_Int16(css::util::SearchAlgorithms_ABSOLUTE) ) },
178 { "SearchItem.AlgorithmType2", css::uno::Any( sal_Int16(css::util::SearchAlgorithms2::ABSOLUTE) ) },
179 { "SearchItem.SearchFormatted", css::uno::Any( bSearchFormatted ) }
180 } ) );
182 css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider(xFrame, css::uno::UNO_QUERY);
183 if ( xDispatchProvider.is() )
185 css::uno::Reference< css::frame::XDispatch > xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
186 if ( xDispatch.is() && !aURL.Complete.isEmpty() )
187 xDispatch->dispatch( aURL, aArgs );
193 // tdf#154818 - remember last search string
194 OUString FindTextFieldControl::m_sRememberedSearchString;
196 FindTextFieldControl::FindTextFieldControl( vcl::Window* pParent,
197 css::uno::Reference< css::frame::XFrame > xFrame,
198 css::uno::Reference< css::uno::XComponentContext > xContext) :
199 InterimItemWindow(pParent, "svx/ui/findbox.ui", "FindBox"),
200 m_nAsyncGetFocusId(nullptr),
201 m_xWidget(m_xBuilder->weld_combo_box("find")),
202 m_xFrame(std::move(xFrame)),
203 m_xContext(std::move(xContext)),
204 m_pAcc(svt::AcceleratorExecute::createAcceleratorHelper())
206 InitControlBase(m_xWidget.get());
208 m_xWidget->set_entry_placeholder_text(SvxResId(RID_SVXSTR_FINDBAR_FIND));
209 m_xWidget->set_entry_completion(true, true);
210 m_pAcc->init(m_xContext, m_xFrame);
212 m_xWidget->connect_focus_in(LINK(this, FindTextFieldControl, FocusInHdl));
213 m_xWidget->connect_key_press(LINK(this, FindTextFieldControl, KeyInputHdl));
214 m_xWidget->connect_entry_activate(LINK(this, FindTextFieldControl, ActivateHdl));
216 m_xWidget->set_size_request(250, -1);
217 SetSizePixel(m_xWidget->get_preferred_size());
219 // tdf#154269 - respect FindReplaceRememberedSearches expert option
220 m_nRememberSize = officecfg::Office::Common::Misc::FindReplaceRememberedSearches::get();
221 if (m_nRememberSize < 1)
222 m_nRememberSize = 1;
225 void FindTextFieldControl::Remember_Impl(const OUString& rStr)
227 if (rStr.isEmpty())
228 return;
230 // tdf#154818 - rearrange the search items
231 const auto nPos = m_xWidget->find_text(rStr);
232 if (nPos != -1)
233 m_xWidget->remove(nPos);
234 else if (m_xWidget->get_count() >= m_nRememberSize)
235 m_xWidget->remove(m_nRememberSize - 1);
236 m_xWidget->insert_text(0, rStr);
239 void FindTextFieldControl::SetTextToSelected_Impl()
241 OUString aString;
245 css::uno::Reference<css::frame::XController> xController(m_xFrame->getController(), css::uno::UNO_SET_THROW);
246 css::uno::Reference<css::frame::XModel> xModel(xController->getModel(), css::uno::UNO_SET_THROW);
247 css::uno::Reference<css::container::XIndexAccess> xIndexAccess(xModel->getCurrentSelection(), css::uno::UNO_QUERY_THROW);
248 if (xIndexAccess->getCount() > 0)
250 css::uno::Reference<css::text::XTextRange> xTextRange(xIndexAccess->getByIndex(0), css::uno::UNO_QUERY_THROW);
251 aString = xTextRange->getString();
254 catch ( ... )
258 if ( !aString.isEmpty() )
260 // If something is selected in the document, prepopulate with this
261 m_xWidget->set_entry_text(aString);
262 m_aChangeHdl.Call(*m_xWidget);
264 // tdf#154818 - reuse last search string
265 else if (!m_sRememberedSearchString.isEmpty() || get_count() > 0)
267 // prepopulate with last search word (fdo#84256)
268 m_xWidget->set_entry_text(m_sRememberedSearchString.isEmpty() ? m_xWidget->get_text(0)
269 : m_sRememberedSearchString);
273 IMPL_LINK(FindTextFieldControl, KeyInputHdl, const KeyEvent&, rKeyEvent, bool)
275 if (isDisposed())
276 return true;
278 bool bRet = false;
280 bool bShift = rKeyEvent.GetKeyCode().IsShift();
281 bool bMod1 = rKeyEvent.GetKeyCode().IsMod1();
282 sal_uInt16 nCode = rKeyEvent.GetKeyCode().GetCode();
284 // Close the search bar on Escape
285 if ( KEY_ESCAPE == nCode )
287 bRet = true;
288 GrabFocusToDocument();
290 // hide the findbar
291 css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY);
292 if (xPropSet.is())
294 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
295 css::uno::Any aValue = xPropSet->getPropertyValue("LayoutManager");
296 aValue >>= xLayoutManager;
297 if (xLayoutManager.is())
299 static const OUStringLiteral sResourceURL( u"private:resource/toolbar/findbar" );
300 xLayoutManager->hideElement( sResourceURL );
301 xLayoutManager->destroyElement( sResourceURL );
305 else
307 auto awtKey = svt::AcceleratorExecute::st_VCLKey2AWTKey(rKeyEvent.GetKeyCode());
308 const OUString aCommand(m_pAcc->findCommand(awtKey));
310 // Select text in the search box when Ctrl-F pressed
311 if ( bMod1 && nCode == KEY_F )
312 m_xWidget->select_entry_region(0, -1);
313 // Execute the search when Ctrl-G, F3 and Shift-RETURN pressed (in addition to ActivateHdl condition which handles bare RETURN)
314 else if ( (bMod1 && KEY_G == nCode) || (bShift && KEY_RETURN == nCode) || (KEY_F3 == nCode) )
316 ActivateFind(bShift);
317 bRet = true;
319 else if (aCommand == ".uno:SearchDialog")
320 bRet = m_pAcc->execute(awtKey);
322 // find-shortcut called with focus already in find
323 if (aCommand == "vnd.sun.star.findbar:FocusToFindbar")
325 m_xWidget->call_attention_to();
326 bRet = true;
330 return bRet || ChildKeyInput(rKeyEvent);
333 void FindTextFieldControl::ActivateFind(bool bShift)
335 // tdf#154818 - remember last search string
336 m_sRememberedSearchString = m_xWidget->get_active_text();
337 Remember_Impl(m_sRememberedSearchString);
339 vcl::Window* pWindow = GetParent();
340 ToolBox* pToolBox = static_cast<ToolBox*>(pWindow);
342 impl_executeSearch(m_xContext, m_xFrame, pToolBox, bShift);
344 m_xWidget->grab_focus();
347 // Execute the search when activated, typically due to "Return"
348 IMPL_LINK_NOARG(FindTextFieldControl, ActivateHdl, weld::ComboBox&, bool)
350 if (isDisposed())
351 return true;
353 ActivateFind(false);
355 return true;
358 IMPL_LINK_NOARG(FindTextFieldControl, OnAsyncGetFocus, void*, void)
360 m_nAsyncGetFocusId = nullptr;
361 m_xWidget->select_entry_region(0, -1);
364 void FindTextFieldControl::FocusIn()
366 if (m_nAsyncGetFocusId || !m_xWidget)
367 return;
369 // do it async to defeat entry in combobox having its own ideas about the focus
370 m_nAsyncGetFocusId = Application::PostUserEvent(LINK(this, FindTextFieldControl, OnAsyncGetFocus));
372 GrabFocus(); // tdf#137993 ensure the toplevel vcl::Window is activated so SfxViewFrame::Current is valid
375 IMPL_LINK_NOARG(FindTextFieldControl, FocusInHdl, weld::Widget&, void)
377 FocusIn();
380 void FindTextFieldControl::dispose()
382 if (m_nAsyncGetFocusId)
384 Application::RemoveUserEvent(m_nAsyncGetFocusId);
385 m_nAsyncGetFocusId = nullptr;
387 m_xWidget.reset();
388 InterimItemWindow::dispose();
391 FindTextFieldControl::~FindTextFieldControl()
393 disposeOnce();
396 void FindTextFieldControl::connect_changed(const Link<weld::ComboBox&, void>& rLink)
398 m_aChangeHdl = rLink;
399 m_xWidget->connect_changed(rLink);
402 int FindTextFieldControl::get_count() const
404 return m_xWidget->get_count();
407 OUString FindTextFieldControl::get_text(int nIndex) const
409 return m_xWidget->get_text(nIndex);
412 OUString FindTextFieldControl::get_active_text() const
414 return m_xWidget->get_active_text();
417 void FindTextFieldControl::append_text(const OUString& rText)
419 m_xWidget->append_text(rText);
422 void FindTextFieldControl::set_entry_message_type(weld::EntryMessageType eType)
424 m_xWidget->set_entry_message_type(eType);
427 namespace {
429 class SearchToolbarControllersManager
431 public:
433 SearchToolbarControllersManager();
435 static SearchToolbarControllersManager& createControllersManager();
437 void registryController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& xStatusListener, const OUString& sCommandURL );
438 void freeController ( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL );
439 css::uno::Reference< css::frame::XStatusListener > findController( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL );
441 void saveSearchHistory(const FindTextFieldControl* m_pFindTextFieldControl);
442 void loadSearchHistory(FindTextFieldControl* m_pFindTextFieldControl);
444 private:
446 typedef ::std::vector< css::beans::PropertyValue > SearchToolbarControllersVec;
447 typedef ::std::map< css::uno::Reference< css::frame::XFrame >, SearchToolbarControllersVec > SearchToolbarControllersMap;
448 SearchToolbarControllersMap aSearchToolbarControllersMap;
449 std::vector<OUString> m_aSearchStrings;
453 SearchToolbarControllersManager::SearchToolbarControllersManager()
457 SearchToolbarControllersManager& SearchToolbarControllersManager::createControllersManager()
459 static SearchToolbarControllersManager theSearchToolbarControllersManager;
460 return theSearchToolbarControllersManager;
463 void SearchToolbarControllersManager::saveSearchHistory(const FindTextFieldControl* pFindTextFieldControl)
465 const sal_Int32 nECount( pFindTextFieldControl->get_count() );
466 m_aSearchStrings.resize( nECount );
467 for( sal_Int32 i=0; i<nECount; ++i )
469 m_aSearchStrings[i] = pFindTextFieldControl->get_text(i);
473 void SearchToolbarControllersManager::loadSearchHistory(FindTextFieldControl* pFindTextFieldControl)
475 for( size_t i=0; i<m_aSearchStrings.size(); ++i )
477 pFindTextFieldControl->append_text(m_aSearchStrings[i]);
481 void SearchToolbarControllersManager::registryController( const css::uno::Reference< css::frame::XFrame >& xFrame, const css::uno::Reference< css::frame::XStatusListener >& xStatusListener, const OUString& sCommandURL )
483 SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame);
484 if (pIt == aSearchToolbarControllersMap.end())
486 SearchToolbarControllersVec lControllers(1);
487 lControllers[0].Name = sCommandURL;
488 lControllers[0].Value <<= xStatusListener;
489 aSearchToolbarControllersMap.emplace(xFrame, lControllers);
491 else
493 sal_Int32 nSize = pIt->second.size();
494 for (sal_Int32 i=0; i<nSize; ++i)
496 if (pIt->second[i].Name == sCommandURL)
497 return;
500 pIt->second.resize(nSize+1);
501 pIt->second[nSize].Name = sCommandURL;
502 pIt->second[nSize].Value <<= xStatusListener;
506 void SearchToolbarControllersManager::freeController( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL )
508 SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame);
509 if (pIt != aSearchToolbarControllersMap.end())
511 auto pItCtrl = std::find_if(pIt->second.begin(), pIt->second.end(),
512 [&sCommandURL](const css::beans::PropertyValue& rCtrl) { return rCtrl.Name == sCommandURL; });
513 if (pItCtrl != pIt->second.end())
514 pIt->second.erase(pItCtrl);
516 if (pIt->second.empty())
517 aSearchToolbarControllersMap.erase(pIt);
521 css::uno::Reference< css::frame::XStatusListener > SearchToolbarControllersManager::findController( const css::uno::Reference< css::frame::XFrame >& xFrame, const OUString& sCommandURL )
523 css::uno::Reference< css::frame::XStatusListener > xStatusListener;
525 SearchToolbarControllersMap::iterator pIt = aSearchToolbarControllersMap.find(xFrame);
526 if (pIt != aSearchToolbarControllersMap.end())
528 auto pItCtrl = std::find_if(pIt->second.begin(), pIt->second.end(),
529 [&sCommandURL](const css::beans::PropertyValue& rCtrl) { return rCtrl.Name == sCommandURL; });
530 if (pItCtrl != pIt->second.end())
531 pItCtrl->Value >>= xStatusListener;
534 return xStatusListener;
537 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> FindTextToolbarController_Base;
538 class FindTextToolbarController : public FindTextToolbarController_Base
540 public:
542 FindTextToolbarController( const css::uno::Reference< css::uno::XComponentContext > & rxContext );
544 // XServiceInfo
545 virtual OUString SAL_CALL getImplementationName() override;
546 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
547 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
549 // XComponent
550 virtual void SAL_CALL dispose() override;
552 // XInitialization
553 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
555 // XToolbarController
556 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
558 // XStatusListener
559 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
561 DECL_LINK(EditModifyHdl, weld::ComboBox&, void);
563 private:
565 void textfieldChanged();
567 VclPtr<FindTextFieldControl> m_pFindTextFieldControl;
569 ToolBoxItemId m_nDownSearchId;
570 ToolBoxItemId m_nUpSearchId;
571 ToolBoxItemId m_nFindAllId;
575 FindTextToolbarController::FindTextToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
576 : FindTextToolbarController_Base(rxContext, css::uno::Reference< css::frame::XFrame >(), COMMAND_FINDTEXT)
577 , m_pFindTextFieldControl(nullptr)
578 , m_nDownSearchId(0)
579 , m_nUpSearchId(0)
580 , m_nFindAllId(0)
584 // XServiceInfo
585 OUString SAL_CALL FindTextToolbarController::getImplementationName()
587 return "com.sun.star.svx.FindTextToolboxController";
590 sal_Bool SAL_CALL FindTextToolbarController::supportsService( const OUString& ServiceName )
592 return cppu::supportsService(this, ServiceName);
595 css::uno::Sequence< OUString > SAL_CALL FindTextToolbarController::getSupportedServiceNames()
597 return { "com.sun.star.frame.ToolbarController" };
600 // XComponent
601 void SAL_CALL FindTextToolbarController::dispose()
603 SolarMutexGuard aSolarMutexGuard;
605 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
607 svt::ToolboxController::dispose();
608 if (m_pFindTextFieldControl != nullptr) {
609 SearchToolbarControllersManager::createControllersManager()
610 .saveSearchHistory(m_pFindTextFieldControl);
611 m_pFindTextFieldControl.disposeAndClear();
615 // XInitialization
616 void SAL_CALL FindTextToolbarController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
618 svt::ToolboxController::initialize(aArguments);
620 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() );
621 ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
622 if ( pToolBox )
624 m_nDownSearchId = pToolBox->GetItemId(COMMAND_DOWNSEARCH);
625 m_nUpSearchId = pToolBox->GetItemId(COMMAND_UPSEARCH);
626 m_nFindAllId = pToolBox->GetItemId(COMMAND_FINDALL);
629 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
632 css::uno::Reference< css::awt::XWindow > SAL_CALL FindTextToolbarController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& xParent )
634 css::uno::Reference< css::awt::XWindow > xItemWindow;
636 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
637 if ( pParent )
639 ToolBox* pToolbar = static_cast<ToolBox*>(pParent.get());
640 m_pFindTextFieldControl = VclPtr<FindTextFieldControl>::Create(pToolbar, m_xFrame, m_xContext);
642 m_pFindTextFieldControl->connect_changed(LINK(this, FindTextToolbarController, EditModifyHdl));
643 SearchToolbarControllersManager::createControllersManager().loadSearchHistory(m_pFindTextFieldControl);
645 xItemWindow = VCLUnoHelper::GetInterface( m_pFindTextFieldControl );
647 return xItemWindow;
650 // XStatusListener
651 void SAL_CALL FindTextToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
653 SolarMutexGuard aSolarMutexGuard;
654 if ( m_bDisposed )
655 return;
657 OUString aFeatureURL = rEvent.FeatureURL.Complete;
658 if ( aFeatureURL == "AppendSearchHistory" )
660 m_pFindTextFieldControl->Remember_Impl(m_pFindTextFieldControl->get_active_text());
662 // enable up/down buttons in case there is already text (from the search history)
663 textfieldChanged();
666 IMPL_LINK_NOARG(FindTextToolbarController, EditModifyHdl, weld::ComboBox&, void)
668 // Clear SearchLabel when search string altered
669 #if HAVE_FEATURE_DESKTOP
670 SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::Empty);
671 #endif
673 textfieldChanged();
676 void FindTextToolbarController::textfieldChanged() {
677 // enable or disable item DownSearch/UpSearch/FindAll of findbar
678 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() );
679 ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
680 if ( pToolBox && m_pFindTextFieldControl )
682 bool enableButtons = !m_pFindTextFieldControl->get_active_text().isEmpty();
683 pToolBox->EnableItem(m_nDownSearchId, enableButtons);
684 pToolBox->EnableItem(m_nUpSearchId, enableButtons);
685 pToolBox->EnableItem(m_nFindAllId, enableButtons);
689 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> UpDownSearchToolboxController_Base;
690 class UpDownSearchToolboxController : public UpDownSearchToolboxController_Base
692 public:
693 enum Type { UP, DOWN };
695 UpDownSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, Type eType );
697 // XServiceInfo
698 virtual OUString SAL_CALL getImplementationName() override;
699 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
700 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
702 // XComponent
703 virtual void SAL_CALL dispose() override;
705 // XInitialization
706 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
708 // XToolbarController
709 virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override;
711 // XStatusListener
712 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
714 private:
715 Type meType;
718 UpDownSearchToolboxController::UpDownSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext, Type eType )
719 : UpDownSearchToolboxController_Base( rxContext,
720 css::uno::Reference< css::frame::XFrame >(),
721 (eType == UP) ? OUString( COMMAND_UPSEARCH ): OUString( COMMAND_DOWNSEARCH ) ),
722 meType( eType )
726 // XServiceInfo
727 OUString SAL_CALL UpDownSearchToolboxController::getImplementationName()
729 return meType == UpDownSearchToolboxController::UP?
730 OUString( "com.sun.star.svx.UpSearchToolboxController" ) :
731 OUString( "com.sun.star.svx.DownSearchToolboxController" );
734 sal_Bool SAL_CALL UpDownSearchToolboxController::supportsService( const OUString& ServiceName )
736 return cppu::supportsService(this, ServiceName);
739 css::uno::Sequence< OUString > SAL_CALL UpDownSearchToolboxController::getSupportedServiceNames()
741 return { "com.sun.star.frame.ToolbarController" };
744 // XComponent
745 void SAL_CALL UpDownSearchToolboxController::dispose()
747 SolarMutexGuard aSolarMutexGuard;
749 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
751 svt::ToolboxController::dispose();
754 // XInitialization
755 void SAL_CALL UpDownSearchToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
757 svt::ToolboxController::initialize( aArguments );
758 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
761 // XToolbarController
762 void SAL_CALL UpDownSearchToolboxController::execute( sal_Int16 /*KeyModifier*/ )
764 if ( m_bDisposed )
765 throw css::lang::DisposedException();
767 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() );
768 ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
770 impl_executeSearch(m_xContext, m_xFrame, pToolBox, meType == UP );
772 css::frame::FeatureStateEvent aEvent;
773 aEvent.FeatureURL.Complete = "AppendSearchHistory";
774 css::uno::Reference< css::frame::XStatusListener > xStatusListener = SearchToolbarControllersManager::createControllersManager().findController(m_xFrame, COMMAND_FINDTEXT);
775 if (xStatusListener.is())
776 xStatusListener->statusChanged( aEvent );
779 // XStatusListener
780 void SAL_CALL UpDownSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ )
784 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> MatchCaseToolboxController_Base;
785 class MatchCaseToolboxController : public MatchCaseToolboxController_Base
787 public:
788 MatchCaseToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
790 // XServiceInfo
791 virtual OUString SAL_CALL getImplementationName() override;
792 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
793 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
795 // XComponent
796 virtual void SAL_CALL dispose() override;
798 // XInitialization
799 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
801 // XToolbarController
802 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
804 // XStatusListener
805 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
807 private:
808 VclPtr<CheckButtonItemWindow> m_xMatchCaseControl;
811 MatchCaseToolboxController::MatchCaseToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
812 : MatchCaseToolboxController_Base( rxContext,
813 css::uno::Reference< css::frame::XFrame >(),
814 COMMAND_MATCHCASE )
815 , m_xMatchCaseControl(nullptr)
819 // XServiceInfo
820 OUString SAL_CALL MatchCaseToolboxController::getImplementationName()
822 return "com.sun.star.svx.MatchCaseToolboxController";
825 sal_Bool SAL_CALL MatchCaseToolboxController::supportsService( const OUString& ServiceName )
827 return cppu::supportsService(this, ServiceName);
830 css::uno::Sequence< OUString > SAL_CALL MatchCaseToolboxController::getSupportedServiceNames()
832 return { "com.sun.star.frame.ToolbarController" };
835 // XComponent
836 void SAL_CALL MatchCaseToolboxController::dispose()
838 SolarMutexGuard aSolarMutexGuard;
840 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
842 svt::ToolboxController::dispose();
844 m_xMatchCaseControl.disposeAndClear();
847 // XInitialization
848 void SAL_CALL MatchCaseToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
850 svt::ToolboxController::initialize(aArguments);
852 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
855 css::uno::Reference< css::awt::XWindow > SAL_CALL MatchCaseToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& xParent )
857 css::uno::Reference< css::awt::XWindow > xItemWindow;
859 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
860 if ( pParent )
862 ToolBox* pToolbar = static_cast<ToolBox*>(pParent.get());
863 m_xMatchCaseControl = VclPtr<CheckButtonItemWindow>::Create(pToolbar, SvxResId(RID_SVXSTR_FINDBAR_MATCHCASE));
865 xItemWindow = VCLUnoHelper::GetInterface(m_xMatchCaseControl);
867 return xItemWindow;
870 // XStatusListener
871 void SAL_CALL MatchCaseToolboxController::statusChanged( const css::frame::FeatureStateEvent& )
875 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> SearchFormattedToolboxController_Base;
876 class SearchFormattedToolboxController : public SearchFormattedToolboxController_Base
878 public:
879 SearchFormattedToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
881 // XServiceInfo
882 virtual OUString SAL_CALL getImplementationName() override;
883 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
884 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
886 // XComponent
887 virtual void SAL_CALL dispose() override;
889 // XInitialization
890 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
892 // XToolbarController
893 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
895 // XStatusListener
896 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
898 private:
899 VclPtr<CheckButtonItemWindow> m_xSearchFormattedControl;
902 SearchFormattedToolboxController::SearchFormattedToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
903 : SearchFormattedToolboxController_Base( rxContext,
904 css::uno::Reference< css::frame::XFrame >(),
905 COMMAND_SEARCHFORMATTED )
906 , m_xSearchFormattedControl(nullptr)
910 // XServiceInfo
911 OUString SAL_CALL SearchFormattedToolboxController::getImplementationName()
913 return "com.sun.star.svx.SearchFormattedToolboxController";
916 sal_Bool SAL_CALL SearchFormattedToolboxController::supportsService( const OUString& ServiceName )
918 return cppu::supportsService(this, ServiceName);
921 css::uno::Sequence< OUString > SAL_CALL SearchFormattedToolboxController::getSupportedServiceNames()
923 return { "com.sun.star.frame.ToolbarController" };
926 // XComponent
927 void SAL_CALL SearchFormattedToolboxController::dispose()
929 SolarMutexGuard aSolarMutexGuard;
931 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
933 svt::ToolboxController::dispose();
935 m_xSearchFormattedControl.disposeAndClear();
938 // XInitialization
939 void SAL_CALL SearchFormattedToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
941 svt::ToolboxController::initialize(aArguments);
943 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
946 css::uno::Reference< css::awt::XWindow > SAL_CALL SearchFormattedToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& xParent )
948 css::uno::Reference< css::awt::XWindow > xItemWindow;
950 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
951 if ( pParent )
953 ToolBox* pToolbar = static_cast<ToolBox*>(pParent.get());
954 m_xSearchFormattedControl = VclPtr<CheckButtonItemWindow>::Create(pToolbar, SvxResId(RID_SVXSTR_FINDBAR_SEARCHFORMATTED));
956 xItemWindow = VCLUnoHelper::GetInterface(m_xSearchFormattedControl);
958 return xItemWindow;
961 // XStatusListener
962 void SAL_CALL SearchFormattedToolboxController::statusChanged( const css::frame::FeatureStateEvent& )
966 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> FindAllToolboxController_Base;
967 class FindAllToolboxController : public FindAllToolboxController_Base
969 public:
970 FindAllToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
972 // XServiceInfo
973 virtual OUString SAL_CALL getImplementationName() override;
974 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
975 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
977 // XComponent
978 virtual void SAL_CALL dispose() override;
980 // XInitialization
981 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
983 // XToolbarController
984 virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override;
986 // XStatusListener
987 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
990 FindAllToolboxController::FindAllToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext )
991 : FindAllToolboxController_Base( rxContext,
992 css::uno::Reference< css::frame::XFrame >(),
993 ".uno:FindAll" )
997 // XServiceInfo
998 OUString SAL_CALL FindAllToolboxController::getImplementationName()
1000 return "com.sun.star.svx.FindAllToolboxController";
1004 sal_Bool SAL_CALL FindAllToolboxController::supportsService( const OUString& ServiceName )
1006 return cppu::supportsService(this, ServiceName);
1009 css::uno::Sequence< OUString > SAL_CALL FindAllToolboxController::getSupportedServiceNames()
1011 return { "com.sun.star.frame.ToolbarController" };
1014 // XComponent
1015 void SAL_CALL FindAllToolboxController::dispose()
1017 SolarMutexGuard aSolarMutexGuard;
1019 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
1021 svt::ToolboxController::dispose();
1024 // XInitialization
1025 void SAL_CALL FindAllToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
1027 svt::ToolboxController::initialize( aArguments );
1028 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
1031 // XToolbarController
1032 void SAL_CALL FindAllToolboxController::execute( sal_Int16 /*KeyModifier*/ )
1034 if ( m_bDisposed )
1035 throw css::lang::DisposedException();
1037 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( getParent() );
1038 ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
1040 impl_executeSearch(m_xContext, m_xFrame, pToolBox, false, true);
1043 // XStatusListener
1044 void SAL_CALL FindAllToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ )
1048 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> ExitSearchToolboxController_Base;
1049 class ExitSearchToolboxController : public ExitSearchToolboxController_Base
1051 public:
1052 ExitSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
1054 // XServiceInfo
1055 virtual OUString SAL_CALL getImplementationName() override;
1056 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1057 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
1059 // XComponent
1060 virtual void SAL_CALL dispose() override;
1062 // XInitialization
1063 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
1065 // XToolbarController
1066 virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override;
1068 // XStatusListener
1069 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
1072 ExitSearchToolboxController::ExitSearchToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext )
1073 : ExitSearchToolboxController_Base( rxContext,
1074 css::uno::Reference< css::frame::XFrame >(),
1075 ".uno:ExitSearch" )
1079 // XServiceInfo
1080 OUString SAL_CALL ExitSearchToolboxController::getImplementationName()
1082 return "com.sun.star.svx.ExitFindbarToolboxController";
1086 sal_Bool SAL_CALL ExitSearchToolboxController::supportsService( const OUString& ServiceName )
1088 return cppu::supportsService(this, ServiceName);
1091 css::uno::Sequence< OUString > SAL_CALL ExitSearchToolboxController::getSupportedServiceNames()
1093 return { "com.sun.star.frame.ToolbarController" };
1096 // XComponent
1097 void SAL_CALL ExitSearchToolboxController::dispose()
1099 SolarMutexGuard aSolarMutexGuard;
1101 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
1103 svt::ToolboxController::dispose();
1106 // XInitialization
1107 void SAL_CALL ExitSearchToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
1109 svt::ToolboxController::initialize( aArguments );
1110 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
1113 // XToolbarController
1114 void SAL_CALL ExitSearchToolboxController::execute( sal_Int16 /*KeyModifier*/ )
1116 vcl::Window *pFocusWindow = Application::GetFocusWindow();
1117 if ( pFocusWindow )
1118 pFocusWindow->GrabFocusToDocument();
1120 // hide the findbar
1121 css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY);
1122 if (xPropSet.is())
1124 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
1125 css::uno::Any aValue = xPropSet->getPropertyValue("LayoutManager");
1126 aValue >>= xLayoutManager;
1127 if (xLayoutManager.is())
1129 static const OUStringLiteral sResourceURL( u"private:resource/toolbar/findbar" );
1130 xLayoutManager->hideElement( sResourceURL );
1131 xLayoutManager->destroyElement( sResourceURL );
1136 // XStatusListener
1137 void SAL_CALL ExitSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent& /*rEvent*/ )
1141 typedef cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo> SearchLabelToolboxController_Base;
1142 class SearchLabelToolboxController : public SearchLabelToolboxController_Base
1144 public:
1145 SearchLabelToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
1147 // XServiceInfo
1148 virtual OUString SAL_CALL getImplementationName() override;
1149 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1150 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
1152 // XComponent
1153 virtual void SAL_CALL dispose() override;
1155 // XInitialization
1156 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
1158 // XToolbarController
1159 virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) override;
1161 // XStatusListener
1162 virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
1164 private:
1165 VclPtr<LabelItemWindow> m_xSL;
1168 SearchLabelToolboxController::SearchLabelToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext )
1169 : SearchLabelToolboxController_Base( rxContext,
1170 css::uno::Reference< css::frame::XFrame >(),
1171 ".uno:SearchLabel" )
1175 // XServiceInfo
1176 OUString SAL_CALL SearchLabelToolboxController::getImplementationName()
1178 return "com.sun.star.svx.SearchLabelToolboxController";
1182 sal_Bool SAL_CALL SearchLabelToolboxController::supportsService( const OUString& ServiceName )
1184 return cppu::supportsService(this, ServiceName);
1187 css::uno::Sequence< OUString > SAL_CALL SearchLabelToolboxController::getSupportedServiceNames()
1189 return { "com.sun.star.frame.ToolbarController" };
1192 // XComponent
1193 void SAL_CALL SearchLabelToolboxController::dispose()
1195 SolarMutexGuard aSolarMutexGuard;
1197 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL);
1199 svt::ToolboxController::dispose();
1200 m_xSL.disposeAndClear();
1203 // XInitialization
1204 void SAL_CALL SearchLabelToolboxController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
1206 svt::ToolboxController::initialize( aArguments );
1207 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame, css::uno::Reference< css::frame::XStatusListener >(this), m_aCommandURL);
1210 // XStatusListener
1211 void SAL_CALL SearchLabelToolboxController::statusChanged( const css::frame::FeatureStateEvent& )
1213 if (m_xSL)
1215 OUString aStr = SvxSearchDialogWrapper::GetSearchLabel();
1216 m_xSL->set_label(aStr);
1217 m_xSL->SetOptimalSize();
1218 Size aSize(m_xSL->GetSizePixel());
1219 tools::Long nWidth = !aStr.isEmpty() ? aSize.getWidth() : 16;
1220 m_xSL->SetSizePixel(Size(nWidth, aSize.Height()));
1224 css::uno::Reference< css::awt::XWindow > SAL_CALL SearchLabelToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent )
1226 ToolBox* pToolBox = nullptr;
1227 ToolBoxItemId nId;
1228 if (getToolboxId(nId, &pToolBox))
1229 pToolBox->SetItemWindowNonInteractive(nId, true);
1231 m_xSL = VclPtr<LabelItemWindow>::Create(VCLUnoHelper::GetWindow(Parent), "");
1232 m_xSL->SetSizePixel(Size(16, m_xSL->GetSizePixel().Height()));
1233 return VCLUnoHelper::GetInterface(m_xSL);
1236 // protocol handler for "vnd.sun.star.findbar:*" URLs
1237 // The dispatch object will be used for shortcut commands for findbar
1238 class FindbarDispatcher : public css::lang::XServiceInfo,
1239 public css::lang::XInitialization,
1240 public css::frame::XDispatchProvider,
1241 public css::frame::XDispatch,
1242 public ::cppu::OWeakObject
1244 public:
1246 FindbarDispatcher();
1247 virtual ~FindbarDispatcher() override;
1249 // XInterface
1250 virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override;
1251 virtual void SAL_CALL acquire() noexcept override;
1252 virtual void SAL_CALL release() noexcept override;
1254 // XServiceInfo
1255 virtual OUString SAL_CALL getImplementationName() override;
1256 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1257 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
1259 // XInitialization
1260 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
1262 // XDispatchProvider
1263 virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch( const css::util::URL& aURL, const OUString& sTargetFrameName , sal_Int32 nSearchFlags ) override;
1264 virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches( const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptions ) override;
1266 // XDispatch
1267 virtual void SAL_CALL dispatch( const css::util::URL& aURL, const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) override;
1268 virtual void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xListener, const css::util::URL& aURL ) override;
1269 virtual void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& xListener, const css::util::URL& aURL ) override;
1271 private:
1273 css::uno::Reference< css::frame::XFrame > m_xFrame;
1277 FindbarDispatcher::FindbarDispatcher()
1281 FindbarDispatcher::~FindbarDispatcher()
1283 m_xFrame = nullptr;
1286 // XInterface
1287 css::uno::Any SAL_CALL FindbarDispatcher::queryInterface( const css::uno::Type& aType )
1289 css::uno::Any aReturn( ::cppu::queryInterface( aType,
1290 static_cast< css::lang::XServiceInfo* >(this),
1291 static_cast< css::lang::XInitialization* >(this),
1292 static_cast< css::frame::XDispatchProvider* >(this),
1293 static_cast< css::frame::XDispatch* >(this)) );
1295 if ( aReturn.hasValue() )
1296 return aReturn;
1298 return OWeakObject::queryInterface( aType );
1301 void SAL_CALL FindbarDispatcher::acquire() noexcept
1303 OWeakObject::acquire();
1306 void SAL_CALL FindbarDispatcher::release() noexcept
1308 OWeakObject::release();
1311 // XServiceInfo
1312 OUString SAL_CALL FindbarDispatcher::getImplementationName()
1314 return "com.sun.star.comp.svx.Impl.FindbarDispatcher";
1317 sal_Bool SAL_CALL FindbarDispatcher::supportsService( const OUString& ServiceName )
1319 return cppu::supportsService(this, ServiceName);
1322 css::uno::Sequence< OUString > SAL_CALL FindbarDispatcher::getSupportedServiceNames()
1324 return { "com.sun.star.comp.svx.FindbarDispatcher", "com.sun.star.frame.ProtocolHandler" };
1327 // XInitialization
1328 void SAL_CALL FindbarDispatcher::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
1330 if ( aArguments.hasElements() )
1331 aArguments[0] >>= m_xFrame;
1334 // XDispatchProvider
1335 css::uno::Reference< css::frame::XDispatch > SAL_CALL FindbarDispatcher::queryDispatch( const css::util::URL& aURL, const OUString& /*sTargetFrameName*/, sal_Int32 /*nSearchFlags*/ )
1337 css::uno::Reference< css::frame::XDispatch > xDispatch;
1339 if ( aURL.Protocol == "vnd.sun.star.findbar:" )
1340 xDispatch = this;
1342 return xDispatch;
1345 css::uno::Sequence < css::uno::Reference< css::frame::XDispatch > > SAL_CALL FindbarDispatcher::queryDispatches( const css::uno::Sequence < css::frame::DispatchDescriptor >& seqDescripts )
1347 sal_Int32 nCount = seqDescripts.getLength();
1348 css::uno::Sequence < css::uno::Reference < XDispatch > > lDispatcher( nCount );
1350 std::transform(seqDescripts.begin(), seqDescripts.end(), lDispatcher.getArray(),
1351 [this](const css::frame::DispatchDescriptor& rDescript) -> css::uno::Reference < XDispatch > {
1352 return queryDispatch( rDescript.FeatureURL, rDescript.FrameName, rDescript.SearchFlags ); });
1354 return lDispatcher;
1357 // XDispatch
1358 void SAL_CALL FindbarDispatcher::dispatch( const css::util::URL& aURL, const css::uno::Sequence < css::beans::PropertyValue >& /*lArgs*/ )
1360 //vnd.sun.star.findbar:FocusToFindbar - set cursor to the FindTextFieldControl of the findbar
1361 if ( aURL.Path != "FocusToFindbar" )
1362 return;
1364 css::uno::Reference< css::beans::XPropertySet > xPropSet(m_xFrame, css::uno::UNO_QUERY);
1365 if(!xPropSet.is())
1366 return;
1368 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
1369 css::uno::Any aValue = xPropSet->getPropertyValue("LayoutManager");
1370 aValue >>= xLayoutManager;
1371 if (!xLayoutManager.is())
1372 return;
1374 static const OUStringLiteral sResourceURL( u"private:resource/toolbar/findbar" );
1375 css::uno::Reference< css::ui::XUIElement > xUIElement = xLayoutManager->getElement(sResourceURL);
1376 if (!xUIElement.is())
1378 // show the findbar if necessary
1379 xLayoutManager->createElement( sResourceURL );
1380 xLayoutManager->showElement( sResourceURL );
1381 xUIElement = xLayoutManager->getElement( sResourceURL );
1382 if ( !xUIElement.is() )
1383 return;
1386 css::uno::Reference< css::awt::XWindow > xWindow(xUIElement->getRealInterface(), css::uno::UNO_QUERY);
1387 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
1388 ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
1389 pToolBox->set_id("FindBar");
1390 if ( !pToolBox )
1391 return;
1393 ToolBox::ImplToolItems::size_type nItemCount = pToolBox->GetItemCount();
1394 for ( ToolBox::ImplToolItems::size_type i=0; i<nItemCount; ++i )
1396 ToolBoxItemId id = pToolBox->GetItemId(i);
1397 OUString sItemCommand = pToolBox->GetItemCommand(id);
1398 if ( sItemCommand == COMMAND_FINDTEXT )
1400 vcl::Window* pItemWin = pToolBox->GetItemWindow( id );
1401 if ( pItemWin )
1403 SolarMutexGuard aSolarMutexGuard;
1404 FindTextFieldControl* pFindTextFieldControl = dynamic_cast<FindTextFieldControl*>(pItemWin);
1405 if ( pFindTextFieldControl )
1406 pFindTextFieldControl->SetTextToSelected_Impl();
1407 pItemWin->GrabFocus();
1408 return;
1414 void SAL_CALL FindbarDispatcher::addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xControl*/, const css::util::URL& /*aURL*/ )
1418 void SAL_CALL FindbarDispatcher::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& /*xControl*/, const css::util::URL& /*aURL*/ )
1424 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1425 com_sun_star_svx_FindTextToolboxController_get_implementation(
1426 css::uno::XComponentContext *context,
1427 css::uno::Sequence<css::uno::Any> const &)
1429 return cppu::acquire(new FindTextToolbarController(context));
1432 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1433 com_sun_star_svx_ExitFindbarToolboxController_get_implementation(
1434 css::uno::XComponentContext *context,
1435 css::uno::Sequence<css::uno::Any> const &)
1437 return cppu::acquire(new ExitSearchToolboxController(context));
1440 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1441 com_sun_star_svx_UpSearchToolboxController_get_implementation(
1442 css::uno::XComponentContext *context,
1443 css::uno::Sequence<css::uno::Any> const &)
1445 return cppu::acquire(new UpDownSearchToolboxController(context, UpDownSearchToolboxController::UP));
1448 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1449 com_sun_star_svx_DownSearchToolboxController_get_implementation(
1450 css::uno::XComponentContext *context,
1451 css::uno::Sequence<css::uno::Any> const &)
1453 return cppu::acquire(new UpDownSearchToolboxController(context, UpDownSearchToolboxController::DOWN));
1456 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1457 com_sun_star_svx_MatchCaseToolboxController_get_implementation(
1458 css::uno::XComponentContext *context,
1459 css::uno::Sequence<css::uno::Any> const &)
1461 return cppu::acquire(new MatchCaseToolboxController(context));
1464 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1465 com_sun_star_svx_SearchFormattedToolboxController_get_implementation(
1466 css::uno::XComponentContext *context,
1467 css::uno::Sequence<css::uno::Any> const &)
1469 return cppu::acquire(new SearchFormattedToolboxController(context));
1472 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1473 com_sun_star_svx_FindAllToolboxController_get_implementation(
1474 css::uno::XComponentContext *context,
1475 css::uno::Sequence<css::uno::Any> const &)
1477 return cppu::acquire(new FindAllToolboxController(context));
1480 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1481 com_sun_star_svx_SearchLabelToolboxController_get_implementation(
1482 css::uno::XComponentContext *context,
1483 css::uno::Sequence<css::uno::Any> const &)
1485 return cppu::acquire(new SearchLabelToolboxController(context));
1488 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1489 com_sun_star_comp_svx_Impl_FindbarDispatcher_get_implementation(
1490 SAL_UNUSED_PARAMETER css::uno::XComponentContext *,
1491 css::uno::Sequence<css::uno::Any> const &)
1493 return cppu::acquire(new FindbarDispatcher);
1496 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */