1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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/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>
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/toolbox.hxx>
60 #include <vcl/svapp.hxx>
61 #include <svx/labelitemwindow.hxx>
62 #include <svx/srchdlg.hxx>
63 #include <vcl/event.hxx>
65 #include <findtextfield.hxx>
71 constexpr OUString COMMAND_FINDTEXT
= u
".uno:FindText"_ustr
;
72 constexpr OUString COMMAND_DOWNSEARCH
= u
".uno:DownSearch"_ustr
;
73 constexpr OUString COMMAND_UPSEARCH
= u
".uno:UpSearch"_ustr
;
74 constexpr OUStringLiteral COMMAND_FINDALL
= u
".uno:FindAll";
75 constexpr OUString COMMAND_MATCHCASE
= u
".uno:MatchCase"_ustr
;
76 constexpr OUString COMMAND_SEARCHFORMATTED
= u
".uno:SearchFormattedDisplayString"_ustr
;
78 class CheckButtonItemWindow final
: public InterimItemWindow
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
))
85 InitControlBase(m_xWidget
.get());
87 m_xWidget
->connect_key_press(LINK(this, CheckButtonItemWindow
, KeyInputHdl
));
88 m_xWidget
->set_label(rLabel
);
89 SetSizePixel(m_xWidget
->get_preferred_size());
92 bool get_active() const
94 return m_xWidget
->get_active();
97 virtual void dispose() override
100 InterimItemWindow::dispose();
103 virtual ~CheckButtonItemWindow() override
109 std::unique_ptr
<weld::CheckButton
> m_xWidget
;
111 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
114 IMPL_LINK(CheckButtonItemWindow
, KeyInputHdl
, const KeyEvent
&, rKeyEvent
, bool)
116 return ChildKeyInput(rKeyEvent
);
119 void impl_executeSearch( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
120 const css::uno::Reference
< css::frame::XFrame
>& xFrame
,
121 const ToolBox
* pToolBox
,
122 const bool aSearchBackwards
,
123 const bool aFindAll
= false )
125 css::uno::Reference
< css::util::XURLTransformer
> xURLTransformer( css::util::URLTransformer::create( rxContext
) );
127 aURL
.Complete
= ".uno:ExecuteSearch";
128 xURLTransformer
->parseStrict(aURL
);
131 bool aMatchCase
= false;
132 bool bSearchFormatted
= false;
135 ToolBox::ImplToolItems::size_type nItemCount
= pToolBox
->GetItemCount();
136 for ( ToolBox::ImplToolItems::size_type i
=0; i
<nItemCount
; ++i
)
138 ToolBoxItemId id
= pToolBox
->GetItemId(i
);
139 OUString sItemCommand
= pToolBox
->GetItemCommand(id
);
140 if ( sItemCommand
== COMMAND_FINDTEXT
)
142 FindTextFieldControl
* pItemWin
= static_cast<FindTextFieldControl
*>(pToolBox
->GetItemWindow(id
));
145 sFindText
= pItemWin
->get_active_text();
146 if (aFindAll
&& !pItemWin
->ControlHasFocus())
147 pItemWin
->GetFocus();
149 } else if ( sItemCommand
== COMMAND_MATCHCASE
)
151 CheckButtonItemWindow
* pItemWin
= static_cast<CheckButtonItemWindow
*>(pToolBox
->GetItemWindow(id
));
153 aMatchCase
= pItemWin
->get_active();
154 } else if ( sItemCommand
== COMMAND_SEARCHFORMATTED
)
156 CheckButtonItemWindow
* pItemWin
= static_cast<CheckButtonItemWindow
*>(pToolBox
->GetItemWindow(id
));
158 bSearchFormatted
= pItemWin
->get_active();
163 TransliterationFlags nFlags
= TransliterationFlags::NONE
;
165 nFlags
|= TransliterationFlags::IGNORE_CASE
;
166 if (SvtCTLOptions::IsCTLFontEnabled())
167 nFlags
|= TransliterationFlags::IGNORE_DIACRITICS_CTL
168 | TransliterationFlags::IGNORE_KASHIDA_CTL
;
170 auto aArgs( comphelper::InitPropertySequence( {
171 { "SearchItem.SearchString", css::uno::Any( sFindText
) },
172 // Related tdf#102506: make Find Bar Ctrl+F searching by value by default
173 { "SearchItem.CellType", css::uno::Any( sal_Int16(SvxSearchCellType::VALUE
) ) },
174 { "SearchItem.Backward", css::uno::Any( aSearchBackwards
) },
175 { "SearchItem.SearchFlags", css::uno::Any( sal_Int32(0) ) },
176 { "SearchItem.TransliterateFlags", css::uno::Any( static_cast<sal_Int32
>(nFlags
) ) },
177 { "SearchItem.Command", css::uno::Any( static_cast<sal_Int16
>(aFindAll
?SvxSearchCmd::FIND_ALL
: SvxSearchCmd::FIND
) ) },
178 { "SearchItem.AlgorithmType", css::uno::Any( sal_Int16(css::util::SearchAlgorithms_ABSOLUTE
) ) },
179 { "SearchItem.AlgorithmType2", css::uno::Any( sal_Int16(css::util::SearchAlgorithms2::ABSOLUTE
) ) },
180 { "SearchItem.SearchFormatted", css::uno::Any( bSearchFormatted
) },
181 { "UseAttrItemList", css::uno::Any(false) }
184 css::uno::Reference
< css::frame::XDispatchProvider
> xDispatchProvider(xFrame
, css::uno::UNO_QUERY
);
185 if ( xDispatchProvider
.is() )
187 css::uno::Reference
< css::frame::XDispatch
> xDispatch
= xDispatchProvider
->queryDispatch( aURL
, OUString(), 0 );
188 if ( xDispatch
.is() && !aURL
.Complete
.isEmpty() )
189 xDispatch
->dispatch( aURL
, aArgs
);
195 // tdf#154818 - remember last search string
196 OUString
FindTextFieldControl::m_sRememberedSearchString
;
198 FindTextFieldControl::FindTextFieldControl( vcl::Window
* pParent
,
199 css::uno::Reference
< css::frame::XFrame
> xFrame
,
200 css::uno::Reference
< css::uno::XComponentContext
> xContext
) :
201 InterimItemWindow(pParent
, u
"svx/ui/findbox.ui"_ustr
, u
"FindBox"_ustr
),
202 m_nAsyncGetFocusId(nullptr),
203 m_xWidget(m_xBuilder
->weld_combo_box(u
"find"_ustr
)),
204 m_xFrame(std::move(xFrame
)),
205 m_xContext(std::move(xContext
)),
206 m_pAcc(svt::AcceleratorExecute::createAcceleratorHelper())
208 InitControlBase(m_xWidget
.get());
210 m_xWidget
->set_entry_placeholder_text(SvxResId(RID_SVXSTR_FINDBAR_FIND
));
211 m_xWidget
->set_entry_completion(true, true);
212 m_pAcc
->init(m_xContext
, m_xFrame
);
214 m_xWidget
->connect_focus_in(LINK(this, FindTextFieldControl
, FocusInHdl
));
215 m_xWidget
->connect_key_press(LINK(this, FindTextFieldControl
, KeyInputHdl
));
216 m_xWidget
->connect_entry_activate(LINK(this, FindTextFieldControl
, ActivateHdl
));
218 m_xWidget
->set_size_request(250, -1);
219 SetSizePixel(m_xWidget
->get_preferred_size());
221 // tdf#154269 - respect FindReplaceRememberedSearches expert option
222 m_nRememberSize
= officecfg::Office::Common::Misc::FindReplaceRememberedSearches::get();
223 if (m_nRememberSize
< 1)
227 void FindTextFieldControl::Remember_Impl(const OUString
& rStr
)
232 // tdf#154818 - rearrange the search items
233 const auto nPos
= m_xWidget
->find_text(rStr
);
235 m_xWidget
->remove(nPos
);
236 else if (m_xWidget
->get_count() >= m_nRememberSize
)
237 m_xWidget
->remove(m_nRememberSize
- 1);
238 m_xWidget
->insert_text(0, rStr
);
241 void FindTextFieldControl::SetTextToSelected_Impl()
247 css::uno::Reference
<css::frame::XController
> xController(m_xFrame
->getController(), css::uno::UNO_SET_THROW
);
248 uno::Reference
<text::XTextViewCursorSupplier
> const xTVCS(xController
, uno::UNO_QUERY
);
251 uno::Reference
<text::XTextViewCursor
> const xTVC(xTVCS
->getViewCursor());
252 aString
= xTVC
->getString();
256 uno::Reference
<frame::XModel
> xModel(xController
->getModel(), uno::UNO_SET_THROW
);
257 uno::Reference
<uno::XInterface
> xSelection
= xModel
->getCurrentSelection();
258 uno::Reference
<container::XIndexAccess
> xIndexAccess(xSelection
, uno::UNO_QUERY
);
259 if (xIndexAccess
.is())
261 if (xIndexAccess
->getCount() > 0)
263 uno::Reference
<text::XTextRange
> xTextRange(xIndexAccess
->getByIndex(0), uno::UNO_QUERY_THROW
);
264 aString
= xTextRange
->getString();
269 // The Basic IDE returns a XEnumeration with a single item
270 uno::Reference
<container::XEnumeration
> xEnum(xSelection
, uno::UNO_QUERY_THROW
);
271 if (xEnum
->hasMoreElements())
272 xEnum
->nextElement() >>= aString
;
280 if ( !aString
.isEmpty() )
282 // If something is selected in the document, prepopulate with this
283 m_xWidget
->set_entry_text(aString
);
284 m_aChangeHdl
.Call(*m_xWidget
);
286 // tdf#154818 - reuse last search string
287 else if (!m_sRememberedSearchString
.isEmpty() || get_count() > 0)
289 // prepopulate with last search word (fdo#84256)
290 m_xWidget
->set_entry_text(m_sRememberedSearchString
.isEmpty() ? m_xWidget
->get_text(0)
291 : m_sRememberedSearchString
);
295 IMPL_LINK(FindTextFieldControl
, KeyInputHdl
, const KeyEvent
&, rKeyEvent
, bool)
302 bool bShift
= rKeyEvent
.GetKeyCode().IsShift();
303 bool bMod1
= rKeyEvent
.GetKeyCode().IsMod1();
304 sal_uInt16 nCode
= rKeyEvent
.GetKeyCode().GetCode();
306 // Close the search bar on Escape
307 if ( KEY_ESCAPE
== nCode
)
310 GrabFocusToDocument();
313 css::uno::Reference
< css::beans::XPropertySet
> xPropSet(m_xFrame
, css::uno::UNO_QUERY
);
316 css::uno::Reference
< css::frame::XLayoutManager
> xLayoutManager
;
317 css::uno::Any aValue
= xPropSet
->getPropertyValue(u
"LayoutManager"_ustr
);
318 aValue
>>= xLayoutManager
;
319 if (xLayoutManager
.is())
321 static constexpr OUString
sResourceURL( u
"private:resource/toolbar/findbar"_ustr
);
322 xLayoutManager
->hideElement( sResourceURL
);
323 xLayoutManager
->destroyElement( sResourceURL
);
329 auto awtKey
= svt::AcceleratorExecute::st_VCLKey2AWTKey(rKeyEvent
.GetKeyCode());
330 const OUString
aCommand(m_pAcc
->findCommand(awtKey
));
332 // Select text in the search box when Ctrl-F pressed
333 if ( bMod1
&& nCode
== KEY_F
)
334 m_xWidget
->select_entry_region(0, -1);
335 // Execute the search when Ctrl-G, F3 and Shift-RETURN pressed (in addition to ActivateHdl condition which handles bare RETURN)
336 else if ( (bMod1
&& KEY_G
== nCode
) || (bShift
&& KEY_RETURN
== nCode
) || (KEY_F3
== nCode
) )
338 ActivateFind(bShift
);
341 else if (aCommand
== ".uno:SearchDialog")
342 bRet
= m_pAcc
->execute(awtKey
);
344 // find-shortcut called with focus already in find
345 if (aCommand
== "vnd.sun.star.findbar:FocusToFindbar")
347 m_xWidget
->call_attention_to();
352 return bRet
|| ChildKeyInput(rKeyEvent
);
355 void FindTextFieldControl::ActivateFind(bool bShift
)
357 // tdf#154818 - remember last search string
358 m_sRememberedSearchString
= m_xWidget
->get_active_text();
359 Remember_Impl(m_sRememberedSearchString
);
361 vcl::Window
* pWindow
= GetParent();
362 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
);
364 impl_executeSearch(m_xContext
, m_xFrame
, pToolBox
, bShift
);
366 m_xWidget
->grab_focus();
369 // Execute the search when activated, typically due to "Return"
370 IMPL_LINK_NOARG(FindTextFieldControl
, ActivateHdl
, weld::ComboBox
&, bool)
380 IMPL_LINK_NOARG(FindTextFieldControl
, OnAsyncGetFocus
, void*, void)
382 m_nAsyncGetFocusId
= nullptr;
383 m_xWidget
->select_entry_region(0, -1);
386 void FindTextFieldControl::FocusIn()
388 if (m_nAsyncGetFocusId
|| !m_xWidget
)
391 // do it async to defeat entry in combobox having its own ideas about the focus
392 m_nAsyncGetFocusId
= Application::PostUserEvent(LINK(this, FindTextFieldControl
, OnAsyncGetFocus
));
394 GrabFocus(); // tdf#137993 ensure the toplevel vcl::Window is activated so SfxViewFrame::Current is valid
397 IMPL_LINK_NOARG(FindTextFieldControl
, FocusInHdl
, weld::Widget
&, void)
402 void FindTextFieldControl::dispose()
404 if (m_nAsyncGetFocusId
)
406 Application::RemoveUserEvent(m_nAsyncGetFocusId
);
407 m_nAsyncGetFocusId
= nullptr;
410 InterimItemWindow::dispose();
413 FindTextFieldControl::~FindTextFieldControl()
418 void FindTextFieldControl::connect_changed(const Link
<weld::ComboBox
&, void>& rLink
)
420 m_aChangeHdl
= rLink
;
421 m_xWidget
->connect_changed(rLink
);
424 int FindTextFieldControl::get_count() const
426 return m_xWidget
->get_count();
429 OUString
FindTextFieldControl::get_text(int nIndex
) const
431 return m_xWidget
->get_text(nIndex
);
434 OUString
FindTextFieldControl::get_active_text() const
436 return m_xWidget
->get_active_text();
439 void FindTextFieldControl::set_entry_message_type(weld::EntryMessageType eType
)
441 m_xWidget
->set_entry_message_type(eType
);
444 void FindTextFieldControl::append_text(const OUString
& rText
)
446 m_xWidget
->append_text(rText
);
451 class SearchToolbarControllersManager
455 SearchToolbarControllersManager();
457 static SearchToolbarControllersManager
& createControllersManager();
459 void registryController( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const css::uno::Reference
< css::frame::XStatusListener
>& xStatusListener
, const OUString
& sCommandURL
);
460 void freeController ( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const OUString
& sCommandURL
);
461 css::uno::Reference
< css::frame::XStatusListener
> findController( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const OUString
& sCommandURL
);
463 void saveSearchHistory(const FindTextFieldControl
* m_pFindTextFieldControl
);
464 void loadSearchHistory(FindTextFieldControl
* m_pFindTextFieldControl
);
468 typedef ::std::vector
< css::beans::PropertyValue
> SearchToolbarControllersVec
;
469 typedef ::std::map
< css::uno::Reference
< css::frame::XFrame
>, SearchToolbarControllersVec
> SearchToolbarControllersMap
;
470 SearchToolbarControllersMap aSearchToolbarControllersMap
;
471 std::vector
<OUString
> m_aSearchStrings
;
475 SearchToolbarControllersManager::SearchToolbarControllersManager()
479 SearchToolbarControllersManager
& SearchToolbarControllersManager::createControllersManager()
481 static SearchToolbarControllersManager theSearchToolbarControllersManager
;
482 return theSearchToolbarControllersManager
;
485 void SearchToolbarControllersManager::saveSearchHistory(const FindTextFieldControl
* pFindTextFieldControl
)
487 const sal_Int32
nECount( pFindTextFieldControl
->get_count() );
488 m_aSearchStrings
.resize( nECount
);
489 for( sal_Int32 i
=0; i
<nECount
; ++i
)
491 m_aSearchStrings
[i
] = pFindTextFieldControl
->get_text(i
);
495 void SearchToolbarControllersManager::loadSearchHistory(FindTextFieldControl
* pFindTextFieldControl
)
497 for( size_t i
=0; i
<m_aSearchStrings
.size(); ++i
)
499 pFindTextFieldControl
->append_text(m_aSearchStrings
[i
]);
503 void SearchToolbarControllersManager::registryController( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const css::uno::Reference
< css::frame::XStatusListener
>& xStatusListener
, const OUString
& sCommandURL
)
505 SearchToolbarControllersMap::iterator pIt
= aSearchToolbarControllersMap
.find(xFrame
);
506 if (pIt
== aSearchToolbarControllersMap
.end())
508 SearchToolbarControllersVec
lControllers(1);
509 lControllers
[0].Name
= sCommandURL
;
510 lControllers
[0].Value
<<= xStatusListener
;
511 aSearchToolbarControllersMap
.emplace(xFrame
, lControllers
);
515 sal_Int32 nSize
= pIt
->second
.size();
516 for (sal_Int32 i
=0; i
<nSize
; ++i
)
518 if (pIt
->second
[i
].Name
== sCommandURL
)
522 pIt
->second
.resize(nSize
+1);
523 pIt
->second
[nSize
].Name
= sCommandURL
;
524 pIt
->second
[nSize
].Value
<<= xStatusListener
;
528 void SearchToolbarControllersManager::freeController( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const OUString
& sCommandURL
)
530 SearchToolbarControllersMap::iterator pIt
= aSearchToolbarControllersMap
.find(xFrame
);
531 if (pIt
!= aSearchToolbarControllersMap
.end())
533 auto pItCtrl
= std::find_if(pIt
->second
.begin(), pIt
->second
.end(),
534 [&sCommandURL
](const css::beans::PropertyValue
& rCtrl
) { return rCtrl
.Name
== sCommandURL
; });
535 if (pItCtrl
!= pIt
->second
.end())
536 pIt
->second
.erase(pItCtrl
);
538 if (pIt
->second
.empty())
539 aSearchToolbarControllersMap
.erase(pIt
);
543 css::uno::Reference
< css::frame::XStatusListener
> SearchToolbarControllersManager::findController( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const OUString
& sCommandURL
)
545 css::uno::Reference
< css::frame::XStatusListener
> xStatusListener
;
547 SearchToolbarControllersMap::iterator pIt
= aSearchToolbarControllersMap
.find(xFrame
);
548 if (pIt
!= aSearchToolbarControllersMap
.end())
550 auto pItCtrl
= std::find_if(pIt
->second
.begin(), pIt
->second
.end(),
551 [&sCommandURL
](const css::beans::PropertyValue
& rCtrl
) { return rCtrl
.Name
== sCommandURL
; });
552 if (pItCtrl
!= pIt
->second
.end())
553 pItCtrl
->Value
>>= xStatusListener
;
556 return xStatusListener
;
559 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> FindTextToolbarController_Base
;
560 class FindTextToolbarController
: public FindTextToolbarController_Base
564 FindTextToolbarController( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
);
567 virtual OUString SAL_CALL
getImplementationName() override
;
568 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
569 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
572 virtual void SAL_CALL
dispose() override
;
575 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
577 // XToolbarController
578 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& Parent
) override
;
581 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& Event
) override
;
583 DECL_LINK(EditModifyHdl
, weld::ComboBox
&, void);
587 void textfieldChanged();
589 VclPtr
<FindTextFieldControl
> m_pFindTextFieldControl
;
591 ToolBoxItemId m_nDownSearchId
;
592 ToolBoxItemId m_nUpSearchId
;
593 ToolBoxItemId m_nFindAllId
;
597 FindTextToolbarController::FindTextToolbarController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
)
598 : FindTextToolbarController_Base(rxContext
, css::uno::Reference
< css::frame::XFrame
>(), COMMAND_FINDTEXT
)
599 , m_pFindTextFieldControl(nullptr)
607 OUString SAL_CALL
FindTextToolbarController::getImplementationName()
609 return u
"com.sun.star.svx.FindTextToolboxController"_ustr
;
612 sal_Bool SAL_CALL
FindTextToolbarController::supportsService( const OUString
& ServiceName
)
614 return cppu::supportsService(this, ServiceName
);
617 css::uno::Sequence
< OUString
> SAL_CALL
FindTextToolbarController::getSupportedServiceNames()
619 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
623 void SAL_CALL
FindTextToolbarController::dispose()
625 SolarMutexGuard aSolarMutexGuard
;
627 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
629 svt::ToolboxController::dispose();
630 if (m_pFindTextFieldControl
!= nullptr) {
631 SearchToolbarControllersManager::createControllersManager()
632 .saveSearchHistory(m_pFindTextFieldControl
);
633 m_pFindTextFieldControl
.disposeAndClear();
638 void SAL_CALL
FindTextToolbarController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
640 svt::ToolboxController::initialize(aArguments
);
642 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( getParent() );
643 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
.get());
646 m_nDownSearchId
= pToolBox
->GetItemId(COMMAND_DOWNSEARCH
);
647 m_nUpSearchId
= pToolBox
->GetItemId(COMMAND_UPSEARCH
);
648 m_nFindAllId
= pToolBox
->GetItemId(COMMAND_FINDALL
);
651 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
654 css::uno::Reference
< css::awt::XWindow
> SAL_CALL
FindTextToolbarController::createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& xParent
)
656 css::uno::Reference
< css::awt::XWindow
> xItemWindow
;
658 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow( xParent
);
661 ToolBox
* pToolbar
= static_cast<ToolBox
*>(pParent
.get());
662 m_pFindTextFieldControl
= VclPtr
<FindTextFieldControl
>::Create(pToolbar
, m_xFrame
, m_xContext
);
664 m_pFindTextFieldControl
->connect_changed(LINK(this, FindTextToolbarController
, EditModifyHdl
));
665 SearchToolbarControllersManager::createControllersManager().loadSearchHistory(m_pFindTextFieldControl
);
667 xItemWindow
= VCLUnoHelper::GetInterface( m_pFindTextFieldControl
);
673 void SAL_CALL
FindTextToolbarController::statusChanged( const css::frame::FeatureStateEvent
& rEvent
)
675 SolarMutexGuard aSolarMutexGuard
;
679 OUString aFeatureURL
= rEvent
.FeatureURL
.Complete
;
680 if ( aFeatureURL
== "AppendSearchHistory" )
682 m_pFindTextFieldControl
->Remember_Impl(m_pFindTextFieldControl
->get_active_text());
684 // enable up/down buttons in case there is already text (from the search history)
688 IMPL_LINK_NOARG(FindTextToolbarController
, EditModifyHdl
, weld::ComboBox
&, void)
690 // Clear SearchLabel when search string altered
691 #if HAVE_FEATURE_DESKTOP
692 SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::Empty
);
698 void FindTextToolbarController::textfieldChanged() {
699 // enable or disable item DownSearch/UpSearch/FindAll of findbar
700 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( getParent() );
701 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
.get());
702 if ( pToolBox
&& m_pFindTextFieldControl
)
704 bool enableButtons
= !m_pFindTextFieldControl
->get_active_text().isEmpty();
705 pToolBox
->EnableItem(m_nDownSearchId
, enableButtons
);
706 pToolBox
->EnableItem(m_nUpSearchId
, enableButtons
);
707 pToolBox
->EnableItem(m_nFindAllId
, enableButtons
);
711 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> UpDownSearchToolboxController_Base
;
712 class UpDownSearchToolboxController
: public UpDownSearchToolboxController_Base
715 enum Type
{ UP
, DOWN
};
717 UpDownSearchToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
, Type eType
);
720 virtual OUString SAL_CALL
getImplementationName() override
;
721 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
722 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
725 virtual void SAL_CALL
dispose() override
;
728 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
730 // XToolbarController
731 virtual void SAL_CALL
execute( sal_Int16 KeyModifier
) override
;
734 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
740 UpDownSearchToolboxController::UpDownSearchToolboxController( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
, Type eType
)
741 : UpDownSearchToolboxController_Base( rxContext
,
742 css::uno::Reference
< css::frame::XFrame
>(),
743 (eType
== UP
) ? COMMAND_UPSEARCH
: COMMAND_DOWNSEARCH
),
749 OUString SAL_CALL
UpDownSearchToolboxController::getImplementationName()
751 return meType
== UpDownSearchToolboxController::UP
?
752 u
"com.sun.star.svx.UpSearchToolboxController"_ustr
:
753 u
"com.sun.star.svx.DownSearchToolboxController"_ustr
;
756 sal_Bool SAL_CALL
UpDownSearchToolboxController::supportsService( const OUString
& ServiceName
)
758 return cppu::supportsService(this, ServiceName
);
761 css::uno::Sequence
< OUString
> SAL_CALL
UpDownSearchToolboxController::getSupportedServiceNames()
763 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
767 void SAL_CALL
UpDownSearchToolboxController::dispose()
769 SolarMutexGuard aSolarMutexGuard
;
771 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
773 svt::ToolboxController::dispose();
777 void SAL_CALL
UpDownSearchToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
779 svt::ToolboxController::initialize( aArguments
);
780 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
783 // XToolbarController
784 void SAL_CALL
UpDownSearchToolboxController::execute( sal_Int16
/*KeyModifier*/ )
787 throw css::lang::DisposedException();
789 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( getParent() );
790 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
.get());
792 impl_executeSearch(m_xContext
, m_xFrame
, pToolBox
, meType
== UP
);
794 css::frame::FeatureStateEvent aEvent
;
795 aEvent
.FeatureURL
.Complete
= "AppendSearchHistory";
796 css::uno::Reference
< css::frame::XStatusListener
> xStatusListener
= SearchToolbarControllersManager::createControllersManager().findController(m_xFrame
, COMMAND_FINDTEXT
);
797 if (xStatusListener
.is())
798 xStatusListener
->statusChanged( aEvent
);
802 void SAL_CALL
UpDownSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent
& /*rEvent*/ )
806 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> MatchCaseToolboxController_Base
;
807 class MatchCaseToolboxController
: public MatchCaseToolboxController_Base
810 MatchCaseToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
813 virtual OUString SAL_CALL
getImplementationName() override
;
814 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
815 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
818 virtual void SAL_CALL
dispose() override
;
821 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
823 // XToolbarController
824 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& Parent
) override
;
827 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
830 VclPtr
<CheckButtonItemWindow
> m_xMatchCaseControl
;
833 MatchCaseToolboxController::MatchCaseToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
)
834 : MatchCaseToolboxController_Base( rxContext
,
835 css::uno::Reference
< css::frame::XFrame
>(),
837 , m_xMatchCaseControl(nullptr)
842 OUString SAL_CALL
MatchCaseToolboxController::getImplementationName()
844 return u
"com.sun.star.svx.MatchCaseToolboxController"_ustr
;
847 sal_Bool SAL_CALL
MatchCaseToolboxController::supportsService( const OUString
& ServiceName
)
849 return cppu::supportsService(this, ServiceName
);
852 css::uno::Sequence
< OUString
> SAL_CALL
MatchCaseToolboxController::getSupportedServiceNames()
854 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
858 void SAL_CALL
MatchCaseToolboxController::dispose()
860 SolarMutexGuard aSolarMutexGuard
;
862 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
864 svt::ToolboxController::dispose();
866 m_xMatchCaseControl
.disposeAndClear();
870 void SAL_CALL
MatchCaseToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
872 svt::ToolboxController::initialize(aArguments
);
874 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
877 css::uno::Reference
< css::awt::XWindow
> SAL_CALL
MatchCaseToolboxController::createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& xParent
)
879 css::uno::Reference
< css::awt::XWindow
> xItemWindow
;
881 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow( xParent
);
884 ToolBox
* pToolbar
= static_cast<ToolBox
*>(pParent
.get());
885 m_xMatchCaseControl
= VclPtr
<CheckButtonItemWindow
>::Create(pToolbar
, SvxResId(RID_SVXSTR_FINDBAR_MATCHCASE
));
887 xItemWindow
= VCLUnoHelper::GetInterface(m_xMatchCaseControl
);
893 void SAL_CALL
MatchCaseToolboxController::statusChanged( const css::frame::FeatureStateEvent
& )
897 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> SearchFormattedToolboxController_Base
;
898 class SearchFormattedToolboxController
: public SearchFormattedToolboxController_Base
901 SearchFormattedToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
904 virtual OUString SAL_CALL
getImplementationName() override
;
905 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
906 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
909 virtual void SAL_CALL
dispose() override
;
912 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
914 // XToolbarController
915 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& Parent
) override
;
918 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
921 VclPtr
<CheckButtonItemWindow
> m_xSearchFormattedControl
;
924 SearchFormattedToolboxController::SearchFormattedToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
)
925 : SearchFormattedToolboxController_Base( rxContext
,
926 css::uno::Reference
< css::frame::XFrame
>(),
927 COMMAND_SEARCHFORMATTED
)
928 , m_xSearchFormattedControl(nullptr)
933 OUString SAL_CALL
SearchFormattedToolboxController::getImplementationName()
935 return u
"com.sun.star.svx.SearchFormattedToolboxController"_ustr
;
938 sal_Bool SAL_CALL
SearchFormattedToolboxController::supportsService( const OUString
& ServiceName
)
940 return cppu::supportsService(this, ServiceName
);
943 css::uno::Sequence
< OUString
> SAL_CALL
SearchFormattedToolboxController::getSupportedServiceNames()
945 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
949 void SAL_CALL
SearchFormattedToolboxController::dispose()
951 SolarMutexGuard aSolarMutexGuard
;
953 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
955 svt::ToolboxController::dispose();
957 m_xSearchFormattedControl
.disposeAndClear();
961 void SAL_CALL
SearchFormattedToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
963 svt::ToolboxController::initialize(aArguments
);
965 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
968 css::uno::Reference
< css::awt::XWindow
> SAL_CALL
SearchFormattedToolboxController::createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& xParent
)
970 css::uno::Reference
< css::awt::XWindow
> xItemWindow
;
972 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow( xParent
);
975 ToolBox
* pToolbar
= static_cast<ToolBox
*>(pParent
.get());
976 m_xSearchFormattedControl
= VclPtr
<CheckButtonItemWindow
>::Create(pToolbar
, SvxResId(RID_SVXSTR_FINDBAR_SEARCHFORMATTED
));
978 xItemWindow
= VCLUnoHelper::GetInterface(m_xSearchFormattedControl
);
984 void SAL_CALL
SearchFormattedToolboxController::statusChanged( const css::frame::FeatureStateEvent
& )
988 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> FindAllToolboxController_Base
;
989 class FindAllToolboxController
: public FindAllToolboxController_Base
992 FindAllToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
995 virtual OUString SAL_CALL
getImplementationName() override
;
996 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
997 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
1000 virtual void SAL_CALL
dispose() override
;
1003 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
1005 // XToolbarController
1006 virtual void SAL_CALL
execute( sal_Int16 KeyModifier
) override
;
1009 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
1012 FindAllToolboxController::FindAllToolboxController( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
)
1013 : FindAllToolboxController_Base( rxContext
,
1014 css::uno::Reference
< css::frame::XFrame
>(),
1020 OUString SAL_CALL
FindAllToolboxController::getImplementationName()
1022 return u
"com.sun.star.svx.FindAllToolboxController"_ustr
;
1026 sal_Bool SAL_CALL
FindAllToolboxController::supportsService( const OUString
& ServiceName
)
1028 return cppu::supportsService(this, ServiceName
);
1031 css::uno::Sequence
< OUString
> SAL_CALL
FindAllToolboxController::getSupportedServiceNames()
1033 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
1037 void SAL_CALL
FindAllToolboxController::dispose()
1039 SolarMutexGuard aSolarMutexGuard
;
1041 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
1043 svt::ToolboxController::dispose();
1047 void SAL_CALL
FindAllToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
1049 svt::ToolboxController::initialize( aArguments
);
1050 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
1053 // XToolbarController
1054 void SAL_CALL
FindAllToolboxController::execute( sal_Int16
/*KeyModifier*/ )
1057 throw css::lang::DisposedException();
1059 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( getParent() );
1060 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
.get());
1062 impl_executeSearch(m_xContext
, m_xFrame
, pToolBox
, false, true);
1066 void SAL_CALL
FindAllToolboxController::statusChanged( const css::frame::FeatureStateEvent
& /*rEvent*/ )
1070 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> ExitSearchToolboxController_Base
;
1071 class ExitSearchToolboxController
: public ExitSearchToolboxController_Base
1074 ExitSearchToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
1077 virtual OUString SAL_CALL
getImplementationName() override
;
1078 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
1079 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
1082 virtual void SAL_CALL
dispose() override
;
1085 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
1087 // XToolbarController
1088 virtual void SAL_CALL
execute( sal_Int16 KeyModifier
) override
;
1091 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
1094 ExitSearchToolboxController::ExitSearchToolboxController( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
)
1095 : ExitSearchToolboxController_Base( rxContext
,
1096 css::uno::Reference
< css::frame::XFrame
>(),
1102 OUString SAL_CALL
ExitSearchToolboxController::getImplementationName()
1104 return u
"com.sun.star.svx.ExitFindbarToolboxController"_ustr
;
1108 sal_Bool SAL_CALL
ExitSearchToolboxController::supportsService( const OUString
& ServiceName
)
1110 return cppu::supportsService(this, ServiceName
);
1113 css::uno::Sequence
< OUString
> SAL_CALL
ExitSearchToolboxController::getSupportedServiceNames()
1115 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
1119 void SAL_CALL
ExitSearchToolboxController::dispose()
1121 SolarMutexGuard aSolarMutexGuard
;
1123 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
1125 svt::ToolboxController::dispose();
1129 void SAL_CALL
ExitSearchToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
1131 svt::ToolboxController::initialize( aArguments
);
1132 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
1135 // XToolbarController
1136 void SAL_CALL
ExitSearchToolboxController::execute( sal_Int16
/*KeyModifier*/ )
1138 vcl::Window
*pFocusWindow
= Application::GetFocusWindow();
1140 pFocusWindow
->GrabFocusToDocument();
1143 css::uno::Reference
< css::beans::XPropertySet
> xPropSet(m_xFrame
, css::uno::UNO_QUERY
);
1146 css::uno::Reference
< css::frame::XLayoutManager
> xLayoutManager
;
1147 css::uno::Any aValue
= xPropSet
->getPropertyValue(u
"LayoutManager"_ustr
);
1148 aValue
>>= xLayoutManager
;
1149 if (xLayoutManager
.is())
1151 static constexpr OUString
sResourceURL( u
"private:resource/toolbar/findbar"_ustr
);
1152 xLayoutManager
->hideElement( sResourceURL
);
1153 xLayoutManager
->destroyElement( sResourceURL
);
1159 void SAL_CALL
ExitSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent
& /*rEvent*/ )
1163 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> SearchLabelToolboxController_Base
;
1164 class SearchLabelToolboxController
: public SearchLabelToolboxController_Base
1167 SearchLabelToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
1170 virtual OUString SAL_CALL
getImplementationName() override
;
1171 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
1172 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
1175 virtual void SAL_CALL
dispose() override
;
1178 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
1180 // XToolbarController
1181 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& Parent
) override
;
1184 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
1187 VclPtr
<LabelItemWindow
> m_xSL
;
1190 SearchLabelToolboxController::SearchLabelToolboxController( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
)
1191 : SearchLabelToolboxController_Base( rxContext
,
1192 css::uno::Reference
< css::frame::XFrame
>(),
1193 ".uno:SearchLabel" )
1198 OUString SAL_CALL
SearchLabelToolboxController::getImplementationName()
1200 return u
"com.sun.star.svx.SearchLabelToolboxController"_ustr
;
1204 sal_Bool SAL_CALL
SearchLabelToolboxController::supportsService( const OUString
& ServiceName
)
1206 return cppu::supportsService(this, ServiceName
);
1209 css::uno::Sequence
< OUString
> SAL_CALL
SearchLabelToolboxController::getSupportedServiceNames()
1211 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
1215 void SAL_CALL
SearchLabelToolboxController::dispose()
1217 SolarMutexGuard aSolarMutexGuard
;
1219 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
1221 svt::ToolboxController::dispose();
1222 m_xSL
.disposeAndClear();
1226 void SAL_CALL
SearchLabelToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
1228 svt::ToolboxController::initialize( aArguments
);
1229 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
1233 void SAL_CALL
SearchLabelToolboxController::statusChanged( const css::frame::FeatureStateEvent
& )
1237 OUString aStr
= SvxSearchDialogWrapper::GetSearchLabel();
1238 m_xSL
->set_label(aStr
);
1239 m_xSL
->SetOptimalSize();
1240 Size
aSize(m_xSL
->GetSizePixel());
1241 tools::Long nWidth
= !aStr
.isEmpty() ? aSize
.getWidth() : 16;
1242 m_xSL
->SetSizePixel(Size(nWidth
, aSize
.Height()));
1246 css::uno::Reference
< css::awt::XWindow
> SAL_CALL
SearchLabelToolboxController::createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& Parent
)
1248 ToolBox
* pToolBox
= nullptr;
1250 if (getToolboxId(nId
, &pToolBox
))
1251 pToolBox
->SetItemWindowNonInteractive(nId
, true);
1253 m_xSL
= VclPtr
<LabelItemWindow
>::Create(VCLUnoHelper::GetWindow(Parent
), "");
1254 m_xSL
->SetSizePixel(Size(16, m_xSL
->GetSizePixel().Height()));
1255 return VCLUnoHelper::GetInterface(m_xSL
);
1258 // protocol handler for "vnd.sun.star.findbar:*" URLs
1259 // The dispatch object will be used for shortcut commands for findbar
1260 class FindbarDispatcher
: public css::lang::XServiceInfo
,
1261 public css::lang::XInitialization
,
1262 public css::frame::XDispatchProvider
,
1263 public css::frame::XDispatch
,
1264 public ::cppu::OWeakObject
1268 FindbarDispatcher();
1269 virtual ~FindbarDispatcher() override
;
1272 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& aType
) override
;
1273 virtual void SAL_CALL
acquire() noexcept override
;
1274 virtual void SAL_CALL
release() noexcept override
;
1277 virtual OUString SAL_CALL
getImplementationName() override
;
1278 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
1279 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
1282 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
1284 // XDispatchProvider
1285 virtual css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
queryDispatch( const css::util::URL
& aURL
, const OUString
& sTargetFrameName
, sal_Int32 nSearchFlags
) override
;
1286 virtual css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > SAL_CALL
queryDispatches( const css::uno::Sequence
< css::frame::DispatchDescriptor
>& lDescriptions
) override
;
1289 virtual void SAL_CALL
dispatch( const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) override
;
1290 virtual void SAL_CALL
addStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& xListener
, const css::util::URL
& aURL
) override
;
1291 virtual void SAL_CALL
removeStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& xListener
, const css::util::URL
& aURL
) override
;
1295 css::uno::Reference
< css::frame::XFrame
> m_xFrame
;
1299 FindbarDispatcher::FindbarDispatcher()
1303 FindbarDispatcher::~FindbarDispatcher()
1309 css::uno::Any SAL_CALL
FindbarDispatcher::queryInterface( const css::uno::Type
& aType
)
1311 css::uno::Any
aReturn( ::cppu::queryInterface( aType
,
1312 static_cast< css::lang::XServiceInfo
* >(this),
1313 static_cast< css::lang::XInitialization
* >(this),
1314 static_cast< css::frame::XDispatchProvider
* >(this),
1315 static_cast< css::frame::XDispatch
* >(this)) );
1317 if ( aReturn
.hasValue() )
1320 return OWeakObject::queryInterface( aType
);
1323 void SAL_CALL
FindbarDispatcher::acquire() noexcept
1325 OWeakObject::acquire();
1328 void SAL_CALL
FindbarDispatcher::release() noexcept
1330 OWeakObject::release();
1334 OUString SAL_CALL
FindbarDispatcher::getImplementationName()
1336 return u
"com.sun.star.comp.svx.Impl.FindbarDispatcher"_ustr
;
1339 sal_Bool SAL_CALL
FindbarDispatcher::supportsService( const OUString
& ServiceName
)
1341 return cppu::supportsService(this, ServiceName
);
1344 css::uno::Sequence
< OUString
> SAL_CALL
FindbarDispatcher::getSupportedServiceNames()
1346 return { u
"com.sun.star.comp.svx.FindbarDispatcher"_ustr
, u
"com.sun.star.frame.ProtocolHandler"_ustr
};
1350 void SAL_CALL
FindbarDispatcher::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
1352 if ( aArguments
.hasElements() )
1353 aArguments
[0] >>= m_xFrame
;
1356 // XDispatchProvider
1357 css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
FindbarDispatcher::queryDispatch( const css::util::URL
& aURL
, const OUString
& /*sTargetFrameName*/, sal_Int32
/*nSearchFlags*/ )
1359 css::uno::Reference
< css::frame::XDispatch
> xDispatch
;
1361 if ( aURL
.Protocol
== "vnd.sun.star.findbar:" )
1367 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > SAL_CALL
FindbarDispatcher::queryDispatches( const css::uno::Sequence
< css::frame::DispatchDescriptor
>& seqDescripts
)
1369 sal_Int32 nCount
= seqDescripts
.getLength();
1370 css::uno::Sequence
< css::uno::Reference
< XDispatch
> > lDispatcher( nCount
);
1372 std::transform(seqDescripts
.begin(), seqDescripts
.end(), lDispatcher
.getArray(),
1373 [this](const css::frame::DispatchDescriptor
& rDescript
) -> css::uno::Reference
< XDispatch
> {
1374 return queryDispatch( rDescript
.FeatureURL
, rDescript
.FrameName
, rDescript
.SearchFlags
); });
1380 void SAL_CALL
FindbarDispatcher::dispatch( const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& /*lArgs*/ )
1382 //vnd.sun.star.findbar:FocusToFindbar - set cursor to the FindTextFieldControl of the findbar
1383 if ( aURL
.Path
!= "FocusToFindbar" )
1386 css::uno::Reference
< css::beans::XPropertySet
> xPropSet(m_xFrame
, css::uno::UNO_QUERY
);
1390 css::uno::Reference
< css::frame::XLayoutManager
> xLayoutManager
;
1391 css::uno::Any aValue
= xPropSet
->getPropertyValue(u
"LayoutManager"_ustr
);
1392 aValue
>>= xLayoutManager
;
1393 if (!xLayoutManager
.is())
1396 static constexpr OUString
sResourceURL( u
"private:resource/toolbar/findbar"_ustr
);
1397 css::uno::Reference
< css::ui::XUIElement
> xUIElement
= xLayoutManager
->getElement(sResourceURL
);
1398 if (!xUIElement
.is())
1400 // show the findbar if necessary
1401 xLayoutManager
->createElement( sResourceURL
);
1402 xLayoutManager
->showElement( sResourceURL
);
1403 xUIElement
= xLayoutManager
->getElement( sResourceURL
);
1404 if ( !xUIElement
.is() )
1408 css::uno::Reference
< css::awt::XWindow
> xWindow(xUIElement
->getRealInterface(), css::uno::UNO_QUERY
);
1409 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( xWindow
);
1410 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
.get());
1411 pToolBox
->set_id(u
"FindBar"_ustr
);
1415 ToolBox::ImplToolItems::size_type nItemCount
= pToolBox
->GetItemCount();
1416 for ( ToolBox::ImplToolItems::size_type i
=0; i
<nItemCount
; ++i
)
1418 ToolBoxItemId id
= pToolBox
->GetItemId(i
);
1419 OUString sItemCommand
= pToolBox
->GetItemCommand(id
);
1420 if ( sItemCommand
== COMMAND_FINDTEXT
)
1422 vcl::Window
* pItemWin
= pToolBox
->GetItemWindow( id
);
1425 SolarMutexGuard aSolarMutexGuard
;
1426 FindTextFieldControl
* pFindTextFieldControl
= dynamic_cast<FindTextFieldControl
*>(pItemWin
);
1427 if ( pFindTextFieldControl
)
1428 pFindTextFieldControl
->SetTextToSelected_Impl();
1429 pItemWin
->GrabFocus();
1436 void SAL_CALL
FindbarDispatcher::addStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& /*xControl*/, const css::util::URL
& /*aURL*/ )
1440 void SAL_CALL
FindbarDispatcher::removeStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& /*xControl*/, const css::util::URL
& /*aURL*/ )
1446 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1447 com_sun_star_svx_FindTextToolboxController_get_implementation(
1448 css::uno::XComponentContext
*context
,
1449 css::uno::Sequence
<css::uno::Any
> const &)
1451 return cppu::acquire(new FindTextToolbarController(context
));
1454 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1455 com_sun_star_svx_ExitFindbarToolboxController_get_implementation(
1456 css::uno::XComponentContext
*context
,
1457 css::uno::Sequence
<css::uno::Any
> const &)
1459 return cppu::acquire(new ExitSearchToolboxController(context
));
1462 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1463 com_sun_star_svx_UpSearchToolboxController_get_implementation(
1464 css::uno::XComponentContext
*context
,
1465 css::uno::Sequence
<css::uno::Any
> const &)
1467 return cppu::acquire(new UpDownSearchToolboxController(context
, UpDownSearchToolboxController::UP
));
1470 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1471 com_sun_star_svx_DownSearchToolboxController_get_implementation(
1472 css::uno::XComponentContext
*context
,
1473 css::uno::Sequence
<css::uno::Any
> const &)
1475 return cppu::acquire(new UpDownSearchToolboxController(context
, UpDownSearchToolboxController::DOWN
));
1478 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1479 com_sun_star_svx_MatchCaseToolboxController_get_implementation(
1480 css::uno::XComponentContext
*context
,
1481 css::uno::Sequence
<css::uno::Any
> const &)
1483 return cppu::acquire(new MatchCaseToolboxController(context
));
1486 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1487 com_sun_star_svx_SearchFormattedToolboxController_get_implementation(
1488 css::uno::XComponentContext
*context
,
1489 css::uno::Sequence
<css::uno::Any
> const &)
1491 return cppu::acquire(new SearchFormattedToolboxController(context
));
1494 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1495 com_sun_star_svx_FindAllToolboxController_get_implementation(
1496 css::uno::XComponentContext
*context
,
1497 css::uno::Sequence
<css::uno::Any
> const &)
1499 return cppu::acquire(new FindAllToolboxController(context
));
1502 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1503 com_sun_star_svx_SearchLabelToolboxController_get_implementation(
1504 css::uno::XComponentContext
*context
,
1505 css::uno::Sequence
<css::uno::Any
> const &)
1507 return cppu::acquire(new SearchLabelToolboxController(context
));
1510 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1511 com_sun_star_comp_svx_Impl_FindbarDispatcher_get_implementation(
1512 SAL_UNUSED_PARAMETER
css::uno::XComponentContext
*,
1513 css::uno::Sequence
<css::uno::Any
> const &)
1515 return cppu::acquire(new FindbarDispatcher
);
1518 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */