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/URL.hpp>
50 #include <com/sun/star/util/URLTransformer.hpp>
51 #include <com/sun/star/util/SearchAlgorithms.hpp>
52 #include <com/sun/star/util/SearchAlgorithms2.hpp>
54 #include <vcl/InterimItemWindow.hxx>
55 #include <svl/ctloptions.hxx>
56 #include <svl/srchitem.hxx>
57 #include <svtools/acceleratorexecute.hxx>
58 #include <svtools/toolboxcontroller.hxx>
59 #include <toolkit/helper/vclunohelper.hxx>
60 #include <vcl/toolbox.hxx>
61 #include <vcl/svapp.hxx>
62 #include <svx/labelitemwindow.hxx>
63 #include <svx/srchdlg.hxx>
64 #include <vcl/event.hxx>
66 #include <findtextfield.hxx>
72 constexpr OUString COMMAND_FINDTEXT
= u
".uno:FindText"_ustr
;
73 constexpr OUString COMMAND_DOWNSEARCH
= u
".uno:DownSearch"_ustr
;
74 constexpr OUString COMMAND_UPSEARCH
= u
".uno:UpSearch"_ustr
;
75 constexpr OUStringLiteral COMMAND_FINDALL
= u
".uno:FindAll";
76 constexpr OUString COMMAND_MATCHCASE
= u
".uno:MatchCase"_ustr
;
77 constexpr OUString COMMAND_SEARCHFORMATTED
= u
".uno:SearchFormattedDisplayString"_ustr
;
79 class CheckButtonItemWindow final
: public InterimItemWindow
82 CheckButtonItemWindow(vcl::Window
* pParent
, const OUString
& rLabel
)
83 : InterimItemWindow(pParent
, u
"svx/ui/checkbuttonbox.ui"_ustr
, u
"CheckButtonBox"_ustr
)
84 , m_xWidget(m_xBuilder
->weld_check_button(u
"checkbutton"_ustr
))
86 InitControlBase(m_xWidget
.get());
88 m_xWidget
->connect_key_press(LINK(this, CheckButtonItemWindow
, KeyInputHdl
));
89 m_xWidget
->set_label(rLabel
);
90 SetSizePixel(m_xWidget
->get_preferred_size());
93 bool get_active() const
95 return m_xWidget
->get_active();
98 virtual void dispose() override
101 InterimItemWindow::dispose();
104 virtual ~CheckButtonItemWindow() override
110 std::unique_ptr
<weld::CheckButton
> m_xWidget
;
112 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
115 IMPL_LINK(CheckButtonItemWindow
, KeyInputHdl
, const KeyEvent
&, rKeyEvent
, bool)
117 return ChildKeyInput(rKeyEvent
);
120 void impl_executeSearch( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
121 const css::uno::Reference
< css::frame::XFrame
>& xFrame
,
122 const ToolBox
* pToolBox
,
123 const bool aSearchBackwards
,
124 const bool aFindAll
= false )
126 css::uno::Reference
< css::util::XURLTransformer
> xURLTransformer( css::util::URLTransformer::create( rxContext
) );
128 aURL
.Complete
= ".uno:ExecuteSearch";
129 xURLTransformer
->parseStrict(aURL
);
132 bool aMatchCase
= false;
133 bool bSearchFormatted
= false;
136 ToolBox::ImplToolItems::size_type nItemCount
= pToolBox
->GetItemCount();
137 for ( ToolBox::ImplToolItems::size_type i
=0; i
<nItemCount
; ++i
)
139 ToolBoxItemId id
= pToolBox
->GetItemId(i
);
140 OUString sItemCommand
= pToolBox
->GetItemCommand(id
);
141 if ( sItemCommand
== COMMAND_FINDTEXT
)
143 FindTextFieldControl
* pItemWin
= static_cast<FindTextFieldControl
*>(pToolBox
->GetItemWindow(id
));
146 sFindText
= pItemWin
->get_active_text();
147 if (aFindAll
&& !pItemWin
->ControlHasFocus())
148 pItemWin
->GetFocus();
150 } else if ( sItemCommand
== COMMAND_MATCHCASE
)
152 CheckButtonItemWindow
* pItemWin
= static_cast<CheckButtonItemWindow
*>(pToolBox
->GetItemWindow(id
));
154 aMatchCase
= pItemWin
->get_active();
155 } else if ( sItemCommand
== COMMAND_SEARCHFORMATTED
)
157 CheckButtonItemWindow
* pItemWin
= static_cast<CheckButtonItemWindow
*>(pToolBox
->GetItemWindow(id
));
159 bSearchFormatted
= pItemWin
->get_active();
164 TransliterationFlags nFlags
= TransliterationFlags::NONE
;
166 nFlags
|= TransliterationFlags::IGNORE_CASE
;
167 if (SvtCTLOptions::IsCTLFontEnabled())
168 nFlags
|= TransliterationFlags::IGNORE_DIACRITICS_CTL
169 | TransliterationFlags::IGNORE_KASHIDA_CTL
;
171 auto aArgs( comphelper::InitPropertySequence( {
172 { "SearchItem.SearchString", css::uno::Any( sFindText
) },
173 // Related tdf#102506: make Find Bar Ctrl+F searching by value by default
174 { "SearchItem.CellType", css::uno::Any( sal_Int16(SvxSearchCellType::VALUE
) ) },
175 { "SearchItem.Backward", css::uno::Any( aSearchBackwards
) },
176 { "SearchItem.SearchFlags", css::uno::Any( sal_Int32(0) ) },
177 { "SearchItem.TransliterateFlags", css::uno::Any( static_cast<sal_Int32
>(nFlags
) ) },
178 { "SearchItem.Command", css::uno::Any( static_cast<sal_Int16
>(aFindAll
?SvxSearchCmd::FIND_ALL
: SvxSearchCmd::FIND
) ) },
179 { "SearchItem.AlgorithmType", css::uno::Any( sal_Int16(css::util::SearchAlgorithms_ABSOLUTE
) ) },
180 { "SearchItem.AlgorithmType2", css::uno::Any( sal_Int16(css::util::SearchAlgorithms2::ABSOLUTE
) ) },
181 { "SearchItem.SearchFormatted", css::uno::Any( bSearchFormatted
) },
182 { "UseAttrItemList", css::uno::Any(false) }
185 css::uno::Reference
< css::frame::XDispatchProvider
> xDispatchProvider(xFrame
, css::uno::UNO_QUERY
);
186 if ( xDispatchProvider
.is() )
188 css::uno::Reference
< css::frame::XDispatch
> xDispatch
= xDispatchProvider
->queryDispatch( aURL
, OUString(), 0 );
189 if ( xDispatch
.is() && !aURL
.Complete
.isEmpty() )
190 xDispatch
->dispatch( aURL
, aArgs
);
196 // tdf#154818 - remember last search string
197 OUString
FindTextFieldControl::m_sRememberedSearchString
;
199 FindTextFieldControl::FindTextFieldControl( vcl::Window
* pParent
,
200 css::uno::Reference
< css::frame::XFrame
> xFrame
,
201 css::uno::Reference
< css::uno::XComponentContext
> xContext
) :
202 InterimItemWindow(pParent
, u
"svx/ui/findbox.ui"_ustr
, u
"FindBox"_ustr
),
203 m_nAsyncGetFocusId(nullptr),
204 m_xWidget(m_xBuilder
->weld_combo_box(u
"find"_ustr
)),
205 m_xFrame(std::move(xFrame
)),
206 m_xContext(std::move(xContext
)),
207 m_pAcc(svt::AcceleratorExecute::createAcceleratorHelper())
209 InitControlBase(m_xWidget
.get());
211 m_xWidget
->set_entry_placeholder_text(SvxResId(RID_SVXSTR_FINDBAR_FIND
));
212 m_xWidget
->set_entry_completion(true, true);
213 m_pAcc
->init(m_xContext
, m_xFrame
);
215 m_xWidget
->connect_focus_in(LINK(this, FindTextFieldControl
, FocusInHdl
));
216 m_xWidget
->connect_key_press(LINK(this, FindTextFieldControl
, KeyInputHdl
));
217 m_xWidget
->connect_entry_activate(LINK(this, FindTextFieldControl
, ActivateHdl
));
219 m_xWidget
->set_size_request(250, -1);
220 SetSizePixel(m_xWidget
->get_preferred_size());
222 // tdf#154269 - respect FindReplaceRememberedSearches expert option
223 m_nRememberSize
= officecfg::Office::Common::Misc::FindReplaceRememberedSearches::get();
224 if (m_nRememberSize
< 1)
228 void FindTextFieldControl::Remember_Impl(const OUString
& rStr
)
233 // tdf#154818 - rearrange the search items
234 const auto nPos
= m_xWidget
->find_text(rStr
);
236 m_xWidget
->remove(nPos
);
237 else if (m_xWidget
->get_count() >= m_nRememberSize
)
238 m_xWidget
->remove(m_nRememberSize
- 1);
239 m_xWidget
->insert_text(0, rStr
);
242 void FindTextFieldControl::SetTextToSelected_Impl()
248 css::uno::Reference
<css::frame::XController
> xController(m_xFrame
->getController(), css::uno::UNO_SET_THROW
);
249 uno::Reference
<text::XTextViewCursorSupplier
> const xTVCS(xController
, uno::UNO_QUERY
);
252 uno::Reference
<text::XTextViewCursor
> const xTVC(xTVCS
->getViewCursor());
253 aString
= xTVC
->getString();
257 uno::Reference
<frame::XModel
> xModel(xController
->getModel(), uno::UNO_SET_THROW
);
258 uno::Reference
<uno::XInterface
> xSelection
= xModel
->getCurrentSelection();
259 uno::Reference
<container::XIndexAccess
> xIndexAccess(xSelection
, uno::UNO_QUERY
);
260 if (xIndexAccess
.is())
262 if (xIndexAccess
->getCount() > 0)
264 uno::Reference
<text::XTextRange
> xTextRange(xIndexAccess
->getByIndex(0), uno::UNO_QUERY_THROW
);
265 aString
= xTextRange
->getString();
270 // The Basic IDE returns a XEnumeration with a single item
271 uno::Reference
<container::XEnumeration
> xEnum(xSelection
, uno::UNO_QUERY_THROW
);
272 if (xEnum
->hasMoreElements())
273 xEnum
->nextElement() >>= aString
;
281 if ( !aString
.isEmpty() )
283 // If something is selected in the document, prepopulate with this
284 m_xWidget
->set_entry_text(aString
);
285 m_aChangeHdl
.Call(*m_xWidget
);
287 // tdf#154818 - reuse last search string
288 else if (!m_sRememberedSearchString
.isEmpty() || get_count() > 0)
290 // prepopulate with last search word (fdo#84256)
291 m_xWidget
->set_entry_text(m_sRememberedSearchString
.isEmpty() ? m_xWidget
->get_text(0)
292 : m_sRememberedSearchString
);
296 IMPL_LINK(FindTextFieldControl
, KeyInputHdl
, const KeyEvent
&, rKeyEvent
, bool)
303 bool bShift
= rKeyEvent
.GetKeyCode().IsShift();
304 bool bMod1
= rKeyEvent
.GetKeyCode().IsMod1();
305 sal_uInt16 nCode
= rKeyEvent
.GetKeyCode().GetCode();
307 // Close the search bar on Escape
308 if ( KEY_ESCAPE
== nCode
)
311 GrabFocusToDocument();
314 css::uno::Reference
< css::beans::XPropertySet
> xPropSet(m_xFrame
, css::uno::UNO_QUERY
);
317 css::uno::Reference
< css::frame::XLayoutManager
> xLayoutManager
;
318 css::uno::Any aValue
= xPropSet
->getPropertyValue(u
"LayoutManager"_ustr
);
319 aValue
>>= xLayoutManager
;
320 if (xLayoutManager
.is())
322 static constexpr OUString
sResourceURL( u
"private:resource/toolbar/findbar"_ustr
);
323 xLayoutManager
->hideElement( sResourceURL
);
324 xLayoutManager
->destroyElement( sResourceURL
);
330 auto awtKey
= svt::AcceleratorExecute::st_VCLKey2AWTKey(rKeyEvent
.GetKeyCode());
331 const OUString
aCommand(m_pAcc
->findCommand(awtKey
));
333 // Select text in the search box when Ctrl-F pressed
334 if ( bMod1
&& nCode
== KEY_F
)
335 m_xWidget
->select_entry_region(0, -1);
336 // Execute the search when Ctrl-G, F3 and Shift-RETURN pressed (in addition to ActivateHdl condition which handles bare RETURN)
337 else if ( (bMod1
&& KEY_G
== nCode
) || (bShift
&& KEY_RETURN
== nCode
) || (KEY_F3
== nCode
) )
339 ActivateFind(bShift
);
342 else if (aCommand
== ".uno:SearchDialog")
343 bRet
= m_pAcc
->execute(awtKey
);
345 // find-shortcut called with focus already in find
346 if (aCommand
== "vnd.sun.star.findbar:FocusToFindbar")
348 m_xWidget
->call_attention_to();
353 return bRet
|| ChildKeyInput(rKeyEvent
);
356 void FindTextFieldControl::ActivateFind(bool bShift
)
358 // tdf#154818 - remember last search string
359 m_sRememberedSearchString
= m_xWidget
->get_active_text();
360 Remember_Impl(m_sRememberedSearchString
);
362 vcl::Window
* pWindow
= GetParent();
363 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
);
365 impl_executeSearch(m_xContext
, m_xFrame
, pToolBox
, bShift
);
367 m_xWidget
->grab_focus();
370 // Execute the search when activated, typically due to "Return"
371 IMPL_LINK_NOARG(FindTextFieldControl
, ActivateHdl
, weld::ComboBox
&, bool)
381 IMPL_LINK_NOARG(FindTextFieldControl
, OnAsyncGetFocus
, void*, void)
383 m_nAsyncGetFocusId
= nullptr;
384 m_xWidget
->select_entry_region(0, -1);
387 void FindTextFieldControl::FocusIn()
389 if (m_nAsyncGetFocusId
|| !m_xWidget
)
392 // do it async to defeat entry in combobox having its own ideas about the focus
393 m_nAsyncGetFocusId
= Application::PostUserEvent(LINK(this, FindTextFieldControl
, OnAsyncGetFocus
));
395 GrabFocus(); // tdf#137993 ensure the toplevel vcl::Window is activated so SfxViewFrame::Current is valid
398 IMPL_LINK_NOARG(FindTextFieldControl
, FocusInHdl
, weld::Widget
&, void)
403 void FindTextFieldControl::dispose()
405 if (m_nAsyncGetFocusId
)
407 Application::RemoveUserEvent(m_nAsyncGetFocusId
);
408 m_nAsyncGetFocusId
= nullptr;
411 InterimItemWindow::dispose();
414 FindTextFieldControl::~FindTextFieldControl()
419 void FindTextFieldControl::connect_changed(const Link
<weld::ComboBox
&, void>& rLink
)
421 m_aChangeHdl
= rLink
;
422 m_xWidget
->connect_changed(rLink
);
425 int FindTextFieldControl::get_count() const
427 return m_xWidget
->get_count();
430 OUString
FindTextFieldControl::get_text(int nIndex
) const
432 return m_xWidget
->get_text(nIndex
);
435 OUString
FindTextFieldControl::get_active_text() const
437 return m_xWidget
->get_active_text();
440 void FindTextFieldControl::set_entry_message_type(weld::EntryMessageType eType
)
442 m_xWidget
->set_entry_message_type(eType
);
445 void FindTextFieldControl::append_text(const OUString
& rText
)
447 m_xWidget
->append_text(rText
);
452 class SearchToolbarControllersManager
456 SearchToolbarControllersManager();
458 static SearchToolbarControllersManager
& createControllersManager();
460 void registryController( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const css::uno::Reference
< css::frame::XStatusListener
>& xStatusListener
, const OUString
& sCommandURL
);
461 void freeController ( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const OUString
& sCommandURL
);
462 css::uno::Reference
< css::frame::XStatusListener
> findController( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const OUString
& sCommandURL
);
464 void saveSearchHistory(const FindTextFieldControl
* m_pFindTextFieldControl
);
465 void loadSearchHistory(FindTextFieldControl
* m_pFindTextFieldControl
);
469 typedef ::std::vector
< css::beans::PropertyValue
> SearchToolbarControllersVec
;
470 typedef ::std::map
< css::uno::Reference
< css::frame::XFrame
>, SearchToolbarControllersVec
> SearchToolbarControllersMap
;
471 SearchToolbarControllersMap aSearchToolbarControllersMap
;
472 std::vector
<OUString
> m_aSearchStrings
;
476 SearchToolbarControllersManager::SearchToolbarControllersManager()
480 SearchToolbarControllersManager
& SearchToolbarControllersManager::createControllersManager()
482 static SearchToolbarControllersManager theSearchToolbarControllersManager
;
483 return theSearchToolbarControllersManager
;
486 void SearchToolbarControllersManager::saveSearchHistory(const FindTextFieldControl
* pFindTextFieldControl
)
488 const sal_Int32
nECount( pFindTextFieldControl
->get_count() );
489 m_aSearchStrings
.resize( nECount
);
490 for( sal_Int32 i
=0; i
<nECount
; ++i
)
492 m_aSearchStrings
[i
] = pFindTextFieldControl
->get_text(i
);
496 void SearchToolbarControllersManager::loadSearchHistory(FindTextFieldControl
* pFindTextFieldControl
)
498 for( size_t i
=0; i
<m_aSearchStrings
.size(); ++i
)
500 pFindTextFieldControl
->append_text(m_aSearchStrings
[i
]);
504 void SearchToolbarControllersManager::registryController( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const css::uno::Reference
< css::frame::XStatusListener
>& xStatusListener
, const OUString
& sCommandURL
)
506 SearchToolbarControllersMap::iterator pIt
= aSearchToolbarControllersMap
.find(xFrame
);
507 if (pIt
== aSearchToolbarControllersMap
.end())
509 SearchToolbarControllersVec
lControllers(1);
510 lControllers
[0].Name
= sCommandURL
;
511 lControllers
[0].Value
<<= xStatusListener
;
512 aSearchToolbarControllersMap
.emplace(xFrame
, lControllers
);
516 sal_Int32 nSize
= pIt
->second
.size();
517 for (sal_Int32 i
=0; i
<nSize
; ++i
)
519 if (pIt
->second
[i
].Name
== sCommandURL
)
523 pIt
->second
.resize(nSize
+1);
524 pIt
->second
[nSize
].Name
= sCommandURL
;
525 pIt
->second
[nSize
].Value
<<= xStatusListener
;
529 void SearchToolbarControllersManager::freeController( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const OUString
& sCommandURL
)
531 SearchToolbarControllersMap::iterator pIt
= aSearchToolbarControllersMap
.find(xFrame
);
532 if (pIt
!= aSearchToolbarControllersMap
.end())
534 auto pItCtrl
= std::find_if(pIt
->second
.begin(), pIt
->second
.end(),
535 [&sCommandURL
](const css::beans::PropertyValue
& rCtrl
) { return rCtrl
.Name
== sCommandURL
; });
536 if (pItCtrl
!= pIt
->second
.end())
537 pIt
->second
.erase(pItCtrl
);
539 if (pIt
->second
.empty())
540 aSearchToolbarControllersMap
.erase(pIt
);
544 css::uno::Reference
< css::frame::XStatusListener
> SearchToolbarControllersManager::findController( const css::uno::Reference
< css::frame::XFrame
>& xFrame
, const OUString
& sCommandURL
)
546 css::uno::Reference
< css::frame::XStatusListener
> xStatusListener
;
548 SearchToolbarControllersMap::iterator pIt
= aSearchToolbarControllersMap
.find(xFrame
);
549 if (pIt
!= aSearchToolbarControllersMap
.end())
551 auto pItCtrl
= std::find_if(pIt
->second
.begin(), pIt
->second
.end(),
552 [&sCommandURL
](const css::beans::PropertyValue
& rCtrl
) { return rCtrl
.Name
== sCommandURL
; });
553 if (pItCtrl
!= pIt
->second
.end())
554 pItCtrl
->Value
>>= xStatusListener
;
557 return xStatusListener
;
560 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> FindTextToolbarController_Base
;
561 class FindTextToolbarController
: public FindTextToolbarController_Base
565 FindTextToolbarController( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
);
568 virtual OUString SAL_CALL
getImplementationName() override
;
569 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
570 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
573 virtual void SAL_CALL
dispose() override
;
576 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
578 // XToolbarController
579 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& Parent
) override
;
582 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& Event
) override
;
584 DECL_LINK(EditModifyHdl
, weld::ComboBox
&, void);
588 void textfieldChanged();
590 VclPtr
<FindTextFieldControl
> m_pFindTextFieldControl
;
592 ToolBoxItemId m_nDownSearchId
;
593 ToolBoxItemId m_nUpSearchId
;
594 ToolBoxItemId m_nFindAllId
;
598 FindTextToolbarController::FindTextToolbarController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
)
599 : FindTextToolbarController_Base(rxContext
, css::uno::Reference
< css::frame::XFrame
>(), COMMAND_FINDTEXT
)
600 , m_pFindTextFieldControl(nullptr)
608 OUString SAL_CALL
FindTextToolbarController::getImplementationName()
610 return u
"com.sun.star.svx.FindTextToolboxController"_ustr
;
613 sal_Bool SAL_CALL
FindTextToolbarController::supportsService( const OUString
& ServiceName
)
615 return cppu::supportsService(this, ServiceName
);
618 css::uno::Sequence
< OUString
> SAL_CALL
FindTextToolbarController::getSupportedServiceNames()
620 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
624 void SAL_CALL
FindTextToolbarController::dispose()
626 SolarMutexGuard aSolarMutexGuard
;
628 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
630 svt::ToolboxController::dispose();
631 if (m_pFindTextFieldControl
!= nullptr) {
632 SearchToolbarControllersManager::createControllersManager()
633 .saveSearchHistory(m_pFindTextFieldControl
);
634 m_pFindTextFieldControl
.disposeAndClear();
639 void SAL_CALL
FindTextToolbarController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
641 svt::ToolboxController::initialize(aArguments
);
643 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( getParent() );
644 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
.get());
647 m_nDownSearchId
= pToolBox
->GetItemId(COMMAND_DOWNSEARCH
);
648 m_nUpSearchId
= pToolBox
->GetItemId(COMMAND_UPSEARCH
);
649 m_nFindAllId
= pToolBox
->GetItemId(COMMAND_FINDALL
);
652 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
655 css::uno::Reference
< css::awt::XWindow
> SAL_CALL
FindTextToolbarController::createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& xParent
)
657 css::uno::Reference
< css::awt::XWindow
> xItemWindow
;
659 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow( xParent
);
662 ToolBox
* pToolbar
= static_cast<ToolBox
*>(pParent
.get());
663 m_pFindTextFieldControl
= VclPtr
<FindTextFieldControl
>::Create(pToolbar
, m_xFrame
, m_xContext
);
665 m_pFindTextFieldControl
->connect_changed(LINK(this, FindTextToolbarController
, EditModifyHdl
));
666 SearchToolbarControllersManager::createControllersManager().loadSearchHistory(m_pFindTextFieldControl
);
668 xItemWindow
= VCLUnoHelper::GetInterface( m_pFindTextFieldControl
);
674 void SAL_CALL
FindTextToolbarController::statusChanged( const css::frame::FeatureStateEvent
& rEvent
)
676 SolarMutexGuard aSolarMutexGuard
;
680 OUString aFeatureURL
= rEvent
.FeatureURL
.Complete
;
681 if ( aFeatureURL
== "AppendSearchHistory" )
683 m_pFindTextFieldControl
->Remember_Impl(m_pFindTextFieldControl
->get_active_text());
685 // enable up/down buttons in case there is already text (from the search history)
689 IMPL_LINK_NOARG(FindTextToolbarController
, EditModifyHdl
, weld::ComboBox
&, void)
691 // Clear SearchLabel when search string altered
692 #if HAVE_FEATURE_DESKTOP
693 SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::Empty
);
699 void FindTextToolbarController::textfieldChanged() {
700 // enable or disable item DownSearch/UpSearch/FindAll of findbar
701 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( getParent() );
702 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
.get());
703 if ( pToolBox
&& m_pFindTextFieldControl
)
705 bool enableButtons
= !m_pFindTextFieldControl
->get_active_text().isEmpty();
706 pToolBox
->EnableItem(m_nDownSearchId
, enableButtons
);
707 pToolBox
->EnableItem(m_nUpSearchId
, enableButtons
);
708 pToolBox
->EnableItem(m_nFindAllId
, enableButtons
);
712 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> UpDownSearchToolboxController_Base
;
713 class UpDownSearchToolboxController
: public UpDownSearchToolboxController_Base
716 enum Type
{ UP
, DOWN
};
718 UpDownSearchToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
, Type eType
);
721 virtual OUString SAL_CALL
getImplementationName() override
;
722 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
723 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
726 virtual void SAL_CALL
dispose() override
;
729 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
731 // XToolbarController
732 virtual void SAL_CALL
execute( sal_Int16 KeyModifier
) override
;
735 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
741 UpDownSearchToolboxController::UpDownSearchToolboxController( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
, Type eType
)
742 : UpDownSearchToolboxController_Base( rxContext
,
743 css::uno::Reference
< css::frame::XFrame
>(),
744 (eType
== UP
) ? COMMAND_UPSEARCH
: COMMAND_DOWNSEARCH
),
750 OUString SAL_CALL
UpDownSearchToolboxController::getImplementationName()
752 return meType
== UpDownSearchToolboxController::UP
?
753 u
"com.sun.star.svx.UpSearchToolboxController"_ustr
:
754 u
"com.sun.star.svx.DownSearchToolboxController"_ustr
;
757 sal_Bool SAL_CALL
UpDownSearchToolboxController::supportsService( const OUString
& ServiceName
)
759 return cppu::supportsService(this, ServiceName
);
762 css::uno::Sequence
< OUString
> SAL_CALL
UpDownSearchToolboxController::getSupportedServiceNames()
764 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
768 void SAL_CALL
UpDownSearchToolboxController::dispose()
770 SolarMutexGuard aSolarMutexGuard
;
772 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
774 svt::ToolboxController::dispose();
778 void SAL_CALL
UpDownSearchToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
780 svt::ToolboxController::initialize( aArguments
);
781 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
784 // XToolbarController
785 void SAL_CALL
UpDownSearchToolboxController::execute( sal_Int16
/*KeyModifier*/ )
788 throw css::lang::DisposedException();
790 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( getParent() );
791 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
.get());
793 impl_executeSearch(m_xContext
, m_xFrame
, pToolBox
, meType
== UP
);
795 css::frame::FeatureStateEvent aEvent
;
796 aEvent
.FeatureURL
.Complete
= "AppendSearchHistory";
797 css::uno::Reference
< css::frame::XStatusListener
> xStatusListener
= SearchToolbarControllersManager::createControllersManager().findController(m_xFrame
, COMMAND_FINDTEXT
);
798 if (xStatusListener
.is())
799 xStatusListener
->statusChanged( aEvent
);
803 void SAL_CALL
UpDownSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent
& /*rEvent*/ )
807 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> MatchCaseToolboxController_Base
;
808 class MatchCaseToolboxController
: public MatchCaseToolboxController_Base
811 MatchCaseToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
814 virtual OUString SAL_CALL
getImplementationName() override
;
815 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
816 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
819 virtual void SAL_CALL
dispose() override
;
822 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
824 // XToolbarController
825 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& Parent
) override
;
828 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
831 VclPtr
<CheckButtonItemWindow
> m_xMatchCaseControl
;
834 MatchCaseToolboxController::MatchCaseToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
)
835 : MatchCaseToolboxController_Base( rxContext
,
836 css::uno::Reference
< css::frame::XFrame
>(),
838 , m_xMatchCaseControl(nullptr)
843 OUString SAL_CALL
MatchCaseToolboxController::getImplementationName()
845 return u
"com.sun.star.svx.MatchCaseToolboxController"_ustr
;
848 sal_Bool SAL_CALL
MatchCaseToolboxController::supportsService( const OUString
& ServiceName
)
850 return cppu::supportsService(this, ServiceName
);
853 css::uno::Sequence
< OUString
> SAL_CALL
MatchCaseToolboxController::getSupportedServiceNames()
855 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
859 void SAL_CALL
MatchCaseToolboxController::dispose()
861 SolarMutexGuard aSolarMutexGuard
;
863 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
865 svt::ToolboxController::dispose();
867 m_xMatchCaseControl
.disposeAndClear();
871 void SAL_CALL
MatchCaseToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
873 svt::ToolboxController::initialize(aArguments
);
875 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
878 css::uno::Reference
< css::awt::XWindow
> SAL_CALL
MatchCaseToolboxController::createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& xParent
)
880 css::uno::Reference
< css::awt::XWindow
> xItemWindow
;
882 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow( xParent
);
885 ToolBox
* pToolbar
= static_cast<ToolBox
*>(pParent
.get());
886 m_xMatchCaseControl
= VclPtr
<CheckButtonItemWindow
>::Create(pToolbar
, SvxResId(RID_SVXSTR_FINDBAR_MATCHCASE
));
888 xItemWindow
= VCLUnoHelper::GetInterface(m_xMatchCaseControl
);
894 void SAL_CALL
MatchCaseToolboxController::statusChanged( const css::frame::FeatureStateEvent
& )
898 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> SearchFormattedToolboxController_Base
;
899 class SearchFormattedToolboxController
: public SearchFormattedToolboxController_Base
902 SearchFormattedToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
905 virtual OUString SAL_CALL
getImplementationName() override
;
906 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
907 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
910 virtual void SAL_CALL
dispose() override
;
913 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
915 // XToolbarController
916 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& Parent
) override
;
919 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
922 VclPtr
<CheckButtonItemWindow
> m_xSearchFormattedControl
;
925 SearchFormattedToolboxController::SearchFormattedToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
)
926 : SearchFormattedToolboxController_Base( rxContext
,
927 css::uno::Reference
< css::frame::XFrame
>(),
928 COMMAND_SEARCHFORMATTED
)
929 , m_xSearchFormattedControl(nullptr)
934 OUString SAL_CALL
SearchFormattedToolboxController::getImplementationName()
936 return u
"com.sun.star.svx.SearchFormattedToolboxController"_ustr
;
939 sal_Bool SAL_CALL
SearchFormattedToolboxController::supportsService( const OUString
& ServiceName
)
941 return cppu::supportsService(this, ServiceName
);
944 css::uno::Sequence
< OUString
> SAL_CALL
SearchFormattedToolboxController::getSupportedServiceNames()
946 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
950 void SAL_CALL
SearchFormattedToolboxController::dispose()
952 SolarMutexGuard aSolarMutexGuard
;
954 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
956 svt::ToolboxController::dispose();
958 m_xSearchFormattedControl
.disposeAndClear();
962 void SAL_CALL
SearchFormattedToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
964 svt::ToolboxController::initialize(aArguments
);
966 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
969 css::uno::Reference
< css::awt::XWindow
> SAL_CALL
SearchFormattedToolboxController::createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& xParent
)
971 css::uno::Reference
< css::awt::XWindow
> xItemWindow
;
973 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow( xParent
);
976 ToolBox
* pToolbar
= static_cast<ToolBox
*>(pParent
.get());
977 m_xSearchFormattedControl
= VclPtr
<CheckButtonItemWindow
>::Create(pToolbar
, SvxResId(RID_SVXSTR_FINDBAR_SEARCHFORMATTED
));
979 xItemWindow
= VCLUnoHelper::GetInterface(m_xSearchFormattedControl
);
985 void SAL_CALL
SearchFormattedToolboxController::statusChanged( const css::frame::FeatureStateEvent
& )
989 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> FindAllToolboxController_Base
;
990 class FindAllToolboxController
: public FindAllToolboxController_Base
993 FindAllToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
996 virtual OUString SAL_CALL
getImplementationName() override
;
997 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
998 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
1001 virtual void SAL_CALL
dispose() override
;
1004 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
1006 // XToolbarController
1007 virtual void SAL_CALL
execute( sal_Int16 KeyModifier
) override
;
1010 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
1013 FindAllToolboxController::FindAllToolboxController( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
)
1014 : FindAllToolboxController_Base( rxContext
,
1015 css::uno::Reference
< css::frame::XFrame
>(),
1021 OUString SAL_CALL
FindAllToolboxController::getImplementationName()
1023 return u
"com.sun.star.svx.FindAllToolboxController"_ustr
;
1027 sal_Bool SAL_CALL
FindAllToolboxController::supportsService( const OUString
& ServiceName
)
1029 return cppu::supportsService(this, ServiceName
);
1032 css::uno::Sequence
< OUString
> SAL_CALL
FindAllToolboxController::getSupportedServiceNames()
1034 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
1038 void SAL_CALL
FindAllToolboxController::dispose()
1040 SolarMutexGuard aSolarMutexGuard
;
1042 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
1044 svt::ToolboxController::dispose();
1048 void SAL_CALL
FindAllToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
1050 svt::ToolboxController::initialize( aArguments
);
1051 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
1054 // XToolbarController
1055 void SAL_CALL
FindAllToolboxController::execute( sal_Int16
/*KeyModifier*/ )
1058 throw css::lang::DisposedException();
1060 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( getParent() );
1061 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
.get());
1063 impl_executeSearch(m_xContext
, m_xFrame
, pToolBox
, false, true);
1067 void SAL_CALL
FindAllToolboxController::statusChanged( const css::frame::FeatureStateEvent
& /*rEvent*/ )
1071 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> ExitSearchToolboxController_Base
;
1072 class ExitSearchToolboxController
: public ExitSearchToolboxController_Base
1075 ExitSearchToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
1078 virtual OUString SAL_CALL
getImplementationName() override
;
1079 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
1080 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
1083 virtual void SAL_CALL
dispose() override
;
1086 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
1088 // XToolbarController
1089 virtual void SAL_CALL
execute( sal_Int16 KeyModifier
) override
;
1092 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
1095 ExitSearchToolboxController::ExitSearchToolboxController( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
)
1096 : ExitSearchToolboxController_Base( rxContext
,
1097 css::uno::Reference
< css::frame::XFrame
>(),
1103 OUString SAL_CALL
ExitSearchToolboxController::getImplementationName()
1105 return u
"com.sun.star.svx.ExitFindbarToolboxController"_ustr
;
1109 sal_Bool SAL_CALL
ExitSearchToolboxController::supportsService( const OUString
& ServiceName
)
1111 return cppu::supportsService(this, ServiceName
);
1114 css::uno::Sequence
< OUString
> SAL_CALL
ExitSearchToolboxController::getSupportedServiceNames()
1116 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
1120 void SAL_CALL
ExitSearchToolboxController::dispose()
1122 SolarMutexGuard aSolarMutexGuard
;
1124 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
1126 svt::ToolboxController::dispose();
1130 void SAL_CALL
ExitSearchToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
1132 svt::ToolboxController::initialize( aArguments
);
1133 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
1136 // XToolbarController
1137 void SAL_CALL
ExitSearchToolboxController::execute( sal_Int16
/*KeyModifier*/ )
1139 vcl::Window
*pFocusWindow
= Application::GetFocusWindow();
1141 pFocusWindow
->GrabFocusToDocument();
1144 css::uno::Reference
< css::beans::XPropertySet
> xPropSet(m_xFrame
, css::uno::UNO_QUERY
);
1147 css::uno::Reference
< css::frame::XLayoutManager
> xLayoutManager
;
1148 css::uno::Any aValue
= xPropSet
->getPropertyValue(u
"LayoutManager"_ustr
);
1149 aValue
>>= xLayoutManager
;
1150 if (xLayoutManager
.is())
1152 static constexpr OUString
sResourceURL( u
"private:resource/toolbar/findbar"_ustr
);
1153 xLayoutManager
->hideElement( sResourceURL
);
1154 xLayoutManager
->destroyElement( sResourceURL
);
1160 void SAL_CALL
ExitSearchToolboxController::statusChanged( const css::frame::FeatureStateEvent
& /*rEvent*/ )
1164 typedef cppu::ImplInheritanceHelper
< ::svt::ToolboxController
, css::lang::XServiceInfo
> SearchLabelToolboxController_Base
;
1165 class SearchLabelToolboxController
: public SearchLabelToolboxController_Base
1168 SearchLabelToolboxController( const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
1171 virtual OUString SAL_CALL
getImplementationName() override
;
1172 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
1173 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
1176 virtual void SAL_CALL
dispose() override
;
1179 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
1181 // XToolbarController
1182 virtual css::uno::Reference
< css::awt::XWindow
> SAL_CALL
createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& Parent
) override
;
1185 virtual void SAL_CALL
statusChanged( const css::frame::FeatureStateEvent
& rEvent
) override
;
1188 VclPtr
<LabelItemWindow
> m_xSL
;
1191 SearchLabelToolboxController::SearchLabelToolboxController( const css::uno::Reference
< css::uno::XComponentContext
> & rxContext
)
1192 : SearchLabelToolboxController_Base( rxContext
,
1193 css::uno::Reference
< css::frame::XFrame
>(),
1194 ".uno:SearchLabel" )
1199 OUString SAL_CALL
SearchLabelToolboxController::getImplementationName()
1201 return u
"com.sun.star.svx.SearchLabelToolboxController"_ustr
;
1205 sal_Bool SAL_CALL
SearchLabelToolboxController::supportsService( const OUString
& ServiceName
)
1207 return cppu::supportsService(this, ServiceName
);
1210 css::uno::Sequence
< OUString
> SAL_CALL
SearchLabelToolboxController::getSupportedServiceNames()
1212 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
1216 void SAL_CALL
SearchLabelToolboxController::dispose()
1218 SolarMutexGuard aSolarMutexGuard
;
1220 SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame
, m_aCommandURL
);
1222 svt::ToolboxController::dispose();
1223 m_xSL
.disposeAndClear();
1227 void SAL_CALL
SearchLabelToolboxController::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
1229 svt::ToolboxController::initialize( aArguments
);
1230 SearchToolbarControllersManager::createControllersManager().registryController(m_xFrame
, css::uno::Reference
< css::frame::XStatusListener
>(this), m_aCommandURL
);
1234 void SAL_CALL
SearchLabelToolboxController::statusChanged( const css::frame::FeatureStateEvent
& )
1238 OUString aStr
= SvxSearchDialogWrapper::GetSearchLabel();
1239 m_xSL
->set_label(aStr
);
1240 m_xSL
->SetOptimalSize();
1241 Size
aSize(m_xSL
->GetSizePixel());
1242 tools::Long nWidth
= !aStr
.isEmpty() ? aSize
.getWidth() : 16;
1243 m_xSL
->SetSizePixel(Size(nWidth
, aSize
.Height()));
1247 css::uno::Reference
< css::awt::XWindow
> SAL_CALL
SearchLabelToolboxController::createItemWindow( const css::uno::Reference
< css::awt::XWindow
>& Parent
)
1249 ToolBox
* pToolBox
= nullptr;
1251 if (getToolboxId(nId
, &pToolBox
))
1252 pToolBox
->SetItemWindowNonInteractive(nId
, true);
1254 m_xSL
= VclPtr
<LabelItemWindow
>::Create(VCLUnoHelper::GetWindow(Parent
), "");
1255 m_xSL
->SetSizePixel(Size(16, m_xSL
->GetSizePixel().Height()));
1256 return VCLUnoHelper::GetInterface(m_xSL
);
1259 // protocol handler for "vnd.sun.star.findbar:*" URLs
1260 // The dispatch object will be used for shortcut commands for findbar
1261 class FindbarDispatcher
: public css::lang::XServiceInfo
,
1262 public css::lang::XInitialization
,
1263 public css::frame::XDispatchProvider
,
1264 public css::frame::XDispatch
,
1265 public ::cppu::OWeakObject
1269 FindbarDispatcher();
1270 virtual ~FindbarDispatcher() override
;
1273 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& aType
) override
;
1274 virtual void SAL_CALL
acquire() noexcept override
;
1275 virtual void SAL_CALL
release() noexcept override
;
1278 virtual OUString SAL_CALL
getImplementationName() override
;
1279 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
1280 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
1283 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
1285 // XDispatchProvider
1286 virtual css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
queryDispatch( const css::util::URL
& aURL
, const OUString
& sTargetFrameName
, sal_Int32 nSearchFlags
) override
;
1287 virtual css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > SAL_CALL
queryDispatches( const css::uno::Sequence
< css::frame::DispatchDescriptor
>& lDescriptions
) override
;
1290 virtual void SAL_CALL
dispatch( const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) override
;
1291 virtual void SAL_CALL
addStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& xListener
, const css::util::URL
& aURL
) override
;
1292 virtual void SAL_CALL
removeStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& xListener
, const css::util::URL
& aURL
) override
;
1296 css::uno::Reference
< css::frame::XFrame
> m_xFrame
;
1300 FindbarDispatcher::FindbarDispatcher()
1304 FindbarDispatcher::~FindbarDispatcher()
1310 css::uno::Any SAL_CALL
FindbarDispatcher::queryInterface( const css::uno::Type
& aType
)
1312 css::uno::Any
aReturn( ::cppu::queryInterface( aType
,
1313 static_cast< css::lang::XServiceInfo
* >(this),
1314 static_cast< css::lang::XInitialization
* >(this),
1315 static_cast< css::frame::XDispatchProvider
* >(this),
1316 static_cast< css::frame::XDispatch
* >(this)) );
1318 if ( aReturn
.hasValue() )
1321 return OWeakObject::queryInterface( aType
);
1324 void SAL_CALL
FindbarDispatcher::acquire() noexcept
1326 OWeakObject::acquire();
1329 void SAL_CALL
FindbarDispatcher::release() noexcept
1331 OWeakObject::release();
1335 OUString SAL_CALL
FindbarDispatcher::getImplementationName()
1337 return u
"com.sun.star.comp.svx.Impl.FindbarDispatcher"_ustr
;
1340 sal_Bool SAL_CALL
FindbarDispatcher::supportsService( const OUString
& ServiceName
)
1342 return cppu::supportsService(this, ServiceName
);
1345 css::uno::Sequence
< OUString
> SAL_CALL
FindbarDispatcher::getSupportedServiceNames()
1347 return { u
"com.sun.star.comp.svx.FindbarDispatcher"_ustr
, u
"com.sun.star.frame.ProtocolHandler"_ustr
};
1351 void SAL_CALL
FindbarDispatcher::initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
)
1353 if ( aArguments
.hasElements() )
1354 aArguments
[0] >>= m_xFrame
;
1357 // XDispatchProvider
1358 css::uno::Reference
< css::frame::XDispatch
> SAL_CALL
FindbarDispatcher::queryDispatch( const css::util::URL
& aURL
, const OUString
& /*sTargetFrameName*/, sal_Int32
/*nSearchFlags*/ )
1360 css::uno::Reference
< css::frame::XDispatch
> xDispatch
;
1362 if ( aURL
.Protocol
== "vnd.sun.star.findbar:" )
1368 css::uno::Sequence
< css::uno::Reference
< css::frame::XDispatch
> > SAL_CALL
FindbarDispatcher::queryDispatches( const css::uno::Sequence
< css::frame::DispatchDescriptor
>& seqDescripts
)
1370 sal_Int32 nCount
= seqDescripts
.getLength();
1371 css::uno::Sequence
< css::uno::Reference
< XDispatch
> > lDispatcher( nCount
);
1373 std::transform(seqDescripts
.begin(), seqDescripts
.end(), lDispatcher
.getArray(),
1374 [this](const css::frame::DispatchDescriptor
& rDescript
) -> css::uno::Reference
< XDispatch
> {
1375 return queryDispatch( rDescript
.FeatureURL
, rDescript
.FrameName
, rDescript
.SearchFlags
); });
1381 void SAL_CALL
FindbarDispatcher::dispatch( const css::util::URL
& aURL
, const css::uno::Sequence
< css::beans::PropertyValue
>& /*lArgs*/ )
1383 //vnd.sun.star.findbar:FocusToFindbar - set cursor to the FindTextFieldControl of the findbar
1384 if ( aURL
.Path
!= "FocusToFindbar" )
1387 css::uno::Reference
< css::beans::XPropertySet
> xPropSet(m_xFrame
, css::uno::UNO_QUERY
);
1391 css::uno::Reference
< css::frame::XLayoutManager
> xLayoutManager
;
1392 css::uno::Any aValue
= xPropSet
->getPropertyValue(u
"LayoutManager"_ustr
);
1393 aValue
>>= xLayoutManager
;
1394 if (!xLayoutManager
.is())
1397 static constexpr OUString
sResourceURL( u
"private:resource/toolbar/findbar"_ustr
);
1398 css::uno::Reference
< css::ui::XUIElement
> xUIElement
= xLayoutManager
->getElement(sResourceURL
);
1399 if (!xUIElement
.is())
1401 // show the findbar if necessary
1402 xLayoutManager
->createElement( sResourceURL
);
1403 xLayoutManager
->showElement( sResourceURL
);
1404 xUIElement
= xLayoutManager
->getElement( sResourceURL
);
1405 if ( !xUIElement
.is() )
1409 css::uno::Reference
< css::awt::XWindow
> xWindow(xUIElement
->getRealInterface(), css::uno::UNO_QUERY
);
1410 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow( xWindow
);
1411 ToolBox
* pToolBox
= static_cast<ToolBox
*>(pWindow
.get());
1412 pToolBox
->set_id(u
"FindBar"_ustr
);
1416 ToolBox::ImplToolItems::size_type nItemCount
= pToolBox
->GetItemCount();
1417 for ( ToolBox::ImplToolItems::size_type i
=0; i
<nItemCount
; ++i
)
1419 ToolBoxItemId id
= pToolBox
->GetItemId(i
);
1420 OUString sItemCommand
= pToolBox
->GetItemCommand(id
);
1421 if ( sItemCommand
== COMMAND_FINDTEXT
)
1423 vcl::Window
* pItemWin
= pToolBox
->GetItemWindow( id
);
1426 SolarMutexGuard aSolarMutexGuard
;
1427 FindTextFieldControl
* pFindTextFieldControl
= dynamic_cast<FindTextFieldControl
*>(pItemWin
);
1428 if ( pFindTextFieldControl
)
1429 pFindTextFieldControl
->SetTextToSelected_Impl();
1430 pItemWin
->GrabFocus();
1437 void SAL_CALL
FindbarDispatcher::addStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& /*xControl*/, const css::util::URL
& /*aURL*/ )
1441 void SAL_CALL
FindbarDispatcher::removeStatusListener( const css::uno::Reference
< css::frame::XStatusListener
>& /*xControl*/, const css::util::URL
& /*aURL*/ )
1447 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1448 com_sun_star_svx_FindTextToolboxController_get_implementation(
1449 css::uno::XComponentContext
*context
,
1450 css::uno::Sequence
<css::uno::Any
> const &)
1452 return cppu::acquire(new FindTextToolbarController(context
));
1455 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1456 com_sun_star_svx_ExitFindbarToolboxController_get_implementation(
1457 css::uno::XComponentContext
*context
,
1458 css::uno::Sequence
<css::uno::Any
> const &)
1460 return cppu::acquire(new ExitSearchToolboxController(context
));
1463 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1464 com_sun_star_svx_UpSearchToolboxController_get_implementation(
1465 css::uno::XComponentContext
*context
,
1466 css::uno::Sequence
<css::uno::Any
> const &)
1468 return cppu::acquire(new UpDownSearchToolboxController(context
, UpDownSearchToolboxController::UP
));
1471 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1472 com_sun_star_svx_DownSearchToolboxController_get_implementation(
1473 css::uno::XComponentContext
*context
,
1474 css::uno::Sequence
<css::uno::Any
> const &)
1476 return cppu::acquire(new UpDownSearchToolboxController(context
, UpDownSearchToolboxController::DOWN
));
1479 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1480 com_sun_star_svx_MatchCaseToolboxController_get_implementation(
1481 css::uno::XComponentContext
*context
,
1482 css::uno::Sequence
<css::uno::Any
> const &)
1484 return cppu::acquire(new MatchCaseToolboxController(context
));
1487 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1488 com_sun_star_svx_SearchFormattedToolboxController_get_implementation(
1489 css::uno::XComponentContext
*context
,
1490 css::uno::Sequence
<css::uno::Any
> const &)
1492 return cppu::acquire(new SearchFormattedToolboxController(context
));
1495 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1496 com_sun_star_svx_FindAllToolboxController_get_implementation(
1497 css::uno::XComponentContext
*context
,
1498 css::uno::Sequence
<css::uno::Any
> const &)
1500 return cppu::acquire(new FindAllToolboxController(context
));
1503 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1504 com_sun_star_svx_SearchLabelToolboxController_get_implementation(
1505 css::uno::XComponentContext
*context
,
1506 css::uno::Sequence
<css::uno::Any
> const &)
1508 return cppu::acquire(new SearchLabelToolboxController(context
));
1511 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
1512 com_sun_star_comp_svx_Impl_FindbarDispatcher_get_implementation(
1513 SAL_UNUSED_PARAMETER
css::uno::XComponentContext
*,
1514 css::uno::Sequence
<css::uno::Any
> const &)
1516 return cppu::acquire(new FindbarDispatcher
);
1519 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */