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