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