Bump version to 6.4.7.2.M8
[LibreOffice.git] / svx / source / dialog / srchdlg.cxx
blob6d98fd4ad8df3a8a254fb3f75ec364ca7bab2ca9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/macros.h>
21 #include <osl/diagnose.h>
22 #include <vcl/timer.hxx>
23 #include <svl/slstitm.hxx>
24 #include <svl/itemiter.hxx>
25 #include <svl/style.hxx>
26 #include <unotools/intlwrapper.hxx>
27 #include <unotools/moduleoptions.hxx>
28 #include <unotools/searchopt.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/objsh.hxx>
31 #include <sfx2/module.hxx>
32 #include <sfx2/viewsh.hxx>
33 #include <sfx2/basedlgs.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <svl/cjkoptions.hxx>
36 #include <svl/ctloptions.hxx>
37 #include <com/sun/star/awt/XWindow.hpp>
38 #include <com/sun/star/container/XNameAccess.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/beans/PropertyValue.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/configuration/theDefaultProvider.hpp>
45 #include <com/sun/star/frame/ModuleManager.hpp>
46 #include <com/sun/star/ui/XUIElement.hpp>
47 #include <comphelper/processfactory.hxx>
48 #include <comphelper/scopeguard.hxx>
49 #include <svl/itempool.hxx>
50 #include <svl/intitem.hxx>
52 #include <sfx2/app.hxx>
53 #include <toolkit/helper/vclunohelper.hxx>
55 #include <svx/srchdlg.hxx>
56 #include <svx/strarray.hxx>
58 #include <svx/strings.hrc>
59 #include <svx/svxids.hrc>
60 #include <svx/svxitems.hrc>
62 #include <svl/srchitem.hxx>
63 #include <svx/pageitem.hxx>
64 #include "srchctrl.hxx"
65 #include <svx/dialmgr.hxx>
66 #include <svx/dlgutil.hxx>
67 #include <editeng/brushitem.hxx>
68 #include <tools/resary.hxx>
69 #include <svx/svxdlg.hxx>
70 #include <vcl/toolbox.hxx>
71 #include <o3tl/typed_flags_set.hxx>
72 #include <vcl/combobox.hxx>
74 #include <cstdlib>
75 #include <memory>
77 #include <svx/xdef.hxx>
78 #include <officecfg/Office/Common.hxx>
80 using namespace com::sun::star::i18n;
81 using namespace com::sun::star::uno;
82 using namespace com::sun::star::accessibility;
83 using namespace com::sun::star;
84 using namespace comphelper;
86 enum class ModifyFlags {
87 NONE = 0x000000,
88 Search = 0x000001,
89 Replace = 0x000002,
90 Word = 0x000004,
91 Exact = 0x000008,
92 Backwards = 0x000010,
93 Selection = 0x000020,
94 Regexp = 0x000040,
95 Layout = 0x000080,
96 Similarity = 0x000100,
97 Formulas = 0x000200,
98 Values = 0x000400,
99 CalcNotes = 0x000800,
100 Rows = 0x001000,
101 Columns = 0x002000,
102 AllTables = 0x004000,
103 Notes = 0x008000,
104 Wildcard = 0x010000
106 namespace o3tl {
107 template<> struct typed_flags<ModifyFlags> : is_typed_flags<ModifyFlags, 0x01ffff> {};
110 namespace
112 bool GetCheckBoxValue(const weld::CheckButton& rBox)
114 return rBox.get_sensitive() && rBox.get_active();
117 bool GetNegatedCheckBoxValue(const weld::CheckButton& rBox)
119 return rBox.get_sensitive() && !rBox.get_active();
123 struct SearchDlg_Impl
125 bool bSaveToModule : 1,
126 bFocusOnSearch : 1;
127 std::unique_ptr<sal_uInt16[]> pRanges;
128 Timer aSelectionTimer;
130 uno::Reference< frame::XDispatch > xCommand1Dispatch;
131 uno::Reference< frame::XDispatch > xCommand2Dispatch;
132 util::URL aCommand1URL;
133 util::URL aCommand2URL;
135 SearchDlg_Impl()
136 : bSaveToModule(true)
137 , bFocusOnSearch(true)
139 aCommand1URL.Complete = aCommand1URL.Main = "vnd.sun.search:SearchViaComponent1";
140 aCommand1URL.Protocol = "vnd.sun.search:";
141 aCommand1URL.Path = "SearchViaComponent1";
142 aCommand2URL.Complete = aCommand2URL.Main = "vnd.sun.search:SearchViaComponent2";
143 aCommand2URL.Protocol = "vnd.sun.search:";
144 aCommand2URL.Path = "SearchViaComponent2";
148 static void ListToStrArr_Impl(sal_uInt16 nId, std::vector<OUString>& rStrLst, weld::ComboBox& rCBox, sal_uInt16 nRememberSize)
150 const SfxStringListItem* pSrchItem =
151 static_cast<const SfxStringListItem*>(SfxGetpApp()->GetItem( nId ));
153 if (pSrchItem)
155 std::vector<OUString> aLst = pSrchItem->GetList();
157 if (aLst.size() > nRememberSize)
158 aLst.resize(nRememberSize);
160 for (const OUString & s : aLst)
162 rStrLst.push_back(s);
163 rCBox.append_text(s);
168 static void StrArrToList_Impl( sal_uInt16 nId, const std::vector<OUString>& rStrLst )
170 DBG_ASSERT( !rStrLst.empty(), "check in advance");
171 SfxGetpApp()->PutItem( SfxStringListItem( nId, &rStrLst ) );
174 SearchAttrItemList::SearchAttrItemList( const SearchAttrItemList& rList ) :
175 SrchAttrItemList(rList)
177 for ( size_t i = 0; i < size(); ++i )
178 if ( !IsInvalidItem( (*this)[i].pItem ) )
179 (*this)[i].pItem = (*this)[i].pItem->Clone();
182 SearchAttrItemList::~SearchAttrItemList()
184 Clear();
187 void SearchAttrItemList::Put( const SfxItemSet& rSet )
189 if ( !rSet.Count() )
190 return;
192 SfxItemPool* pPool = rSet.GetPool();
193 SfxItemIter aIter( rSet );
194 SearchAttrItem aItem;
195 const SfxPoolItem* pItem = aIter.GetCurItem();
196 sal_uInt16 nWhich;
200 // only test that it is available?
201 if( IsInvalidItem( pItem ) )
203 nWhich = rSet.GetWhichByPos( aIter.GetCurPos() );
204 aItem.pItem = const_cast<SfxPoolItem*>(pItem);
206 else
208 nWhich = pItem->Which();
209 aItem.pItem = pItem->Clone();
212 aItem.nSlot = pPool->GetSlotId( nWhich );
213 Insert( aItem );
215 pItem = aIter.NextItem();
216 } while (pItem);
220 SfxItemSet& SearchAttrItemList::Get( SfxItemSet& rSet )
222 SfxItemPool* pPool = rSet.GetPool();
224 for ( size_t i = 0; i < size(); ++i )
225 if ( IsInvalidItem( (*this)[i].pItem ) )
226 rSet.InvalidateItem( pPool->GetWhich( (*this)[i].nSlot ) );
227 else
228 rSet.Put( *(*this)[i].pItem );
229 return rSet;
233 void SearchAttrItemList::Clear()
235 for ( size_t i = 0; i < size(); ++i )
236 if ( !IsInvalidItem( (*this)[i].pItem ) )
237 delete (*this)[i].pItem;
238 SrchAttrItemList::clear();
242 // Deletes the pointer to the items
243 void SearchAttrItemList::Remove(size_t nPos)
245 size_t nLen = 1;
246 if ( nPos + nLen > size() )
247 nLen = size() - nPos;
249 for ( size_t i = nPos; i < nPos + nLen; ++i )
250 if ( !IsInvalidItem( (*this)[i].pItem ) )
251 delete (*this)[i].pItem;
253 SrchAttrItemList::erase( begin() + nPos, begin() + nPos + nLen );
256 SvxSearchDialog::SvxSearchDialog(weld::Window* pParent, SfxChildWindow* pChildWin, SfxBindings& rBind)
257 : SfxModelessDialogController(&rBind, pChildWin, pParent,
258 "svx/ui/findreplacedialog.ui", "FindReplaceDialog")
259 , rBindings(rBind)
260 , bWriter(false)
261 , bSearch(true)
262 , bFormat(false)
263 , bReplaceBackwards(false)
264 , nOptions(SearchOptionFlags::ALL)
265 , bSet(false)
266 , bConstruct(true)
267 , nModifyFlag(ModifyFlags::NONE)
268 , pReplaceList(new SearchAttrItemList)
269 , nTransliterationFlags(TransliterationFlags::NONE)
270 , m_xSearchFrame(m_xBuilder->weld_frame("searchframe"))
271 , m_xSearchLB(m_xBuilder->weld_combo_box("searchterm"))
272 , m_xSearchTmplLB(m_xBuilder->weld_combo_box("searchlist"))
273 , m_xSearchAttrText(m_xBuilder->weld_label("searchdesc"))
274 , m_xSearchLabel(m_xBuilder->weld_label("searchlabel"))
275 , m_xReplaceFrame(m_xBuilder->weld_frame("replaceframe"))
276 , m_xReplaceLB(m_xBuilder->weld_combo_box("replaceterm"))
277 , m_xReplaceTmplLB(m_xBuilder->weld_combo_box("replacelist"))
278 , m_xReplaceAttrText(m_xBuilder->weld_label("replacedesc"))
279 , m_xSearchBtn(m_xBuilder->weld_button("search"))
280 , m_xBackSearchBtn(m_xBuilder->weld_button("backsearch"))
281 , m_xSearchAllBtn(m_xBuilder->weld_button("searchall"))
282 , m_xReplaceBtn(m_xBuilder->weld_button("replace"))
283 , m_xReplaceAllBtn(m_xBuilder->weld_button("replaceall"))
284 , m_xComponentFrame(m_xBuilder->weld_frame("componentframe"))
285 , m_xSearchComponent1PB(m_xBuilder->weld_button("component1"))
286 , m_xSearchComponent2PB(m_xBuilder->weld_button("component2"))
287 , m_xMatchCaseCB(m_xBuilder->weld_check_button("matchcase"))
288 , m_xSearchFormattedCB(m_xBuilder->weld_check_button("searchformatted"))
289 , m_xWordBtn(m_xBuilder->weld_check_button("wholewords"))
290 , m_xCloseBtn(m_xBuilder->weld_button("close"))
291 , m_xIncludeDiacritics(m_xBuilder->weld_check_button("includediacritics"))
292 , m_xIncludeKashida(m_xBuilder->weld_check_button("includekashida"))
293 , m_xOtherOptionsExpander(m_xBuilder->weld_expander("OptionsExpander"))
294 , m_xSelectionBtn(m_xBuilder->weld_check_button("selection"))
295 , m_xRegExpBtn(m_xBuilder->weld_check_button("regexp"))
296 , m_xWildcardBtn(m_xBuilder->weld_check_button("wildcard"))
297 , m_xSimilarityBox(m_xBuilder->weld_check_button("similarity"))
298 , m_xSimilarityBtn(m_xBuilder->weld_button("similaritybtn"))
299 , m_xLayoutBtn(m_xBuilder->weld_check_button("layout"))
300 , m_xNotesBtn(m_xBuilder->weld_check_button("notes"))
301 , m_xJapMatchFullHalfWidthCB(m_xBuilder->weld_check_button("matchcharwidth"))
302 , m_xJapOptionsCB(m_xBuilder->weld_check_button("soundslike"))
303 , m_xReplaceBackwardsCB(m_xBuilder->weld_check_button("replace_backwards"))
304 , m_xJapOptionsBtn(m_xBuilder->weld_button("soundslikebtn"))
305 , m_xAttributeBtn(m_xBuilder->weld_button("attributes"))
306 , m_xFormatBtn(m_xBuilder->weld_button("format"))
307 , m_xNoFormatBtn(m_xBuilder->weld_button("noformat"))
308 , m_xCalcGrid(m_xBuilder->weld_widget("calcgrid"))
309 , m_xCalcSearchInFT(m_xBuilder->weld_label("searchinlabel"))
310 , m_xCalcSearchInLB(m_xBuilder->weld_combo_box("calcsearchin"))
311 , m_xCalcSearchDirFT(m_xBuilder->weld_label("searchdir"))
312 , m_xRowsBtn(m_xBuilder->weld_radio_button("rows"))
313 , m_xColumnsBtn(m_xBuilder->weld_radio_button("cols"))
314 , m_xAllSheetsCB(m_xBuilder->weld_check_button("allsheets"))
315 , m_xCalcStrFT(m_xBuilder->weld_label("entirecells"))
317 m_xSearchTmplLB->make_sorted();
318 m_xSearchAttrText->hide();
319 m_xSearchLabel->show();
321 m_xReplaceTmplLB->make_sorted();
322 m_xReplaceAttrText->hide();
324 aCalcStr = m_xCalcStrFT->get_label();
326 // m_xSimilarityBtn->set_height_request(m_xSimilarityBox->get_preferred_size().Height());
327 // m_xJapOptionsBtn->set_height_request(m_xJapOptionsCB->get_preferred_size().Height());
329 //tdf#122322
330 nRememberSize = officecfg::Office::Common::Misc::FindReplaceRememberedSearches::get();
331 if (nRememberSize<1)
332 nRememberSize = 1; //0 crashes with no results found
334 auto nTermWidth = m_xSearchLB->get_approximate_digit_width() * 28;
335 m_xSearchLB->set_size_request(nTermWidth, -1);
336 m_xSearchTmplLB->set_size_request(nTermWidth, -1);
337 m_xReplaceLB->set_size_request(nTermWidth, -1);
338 m_xReplaceTmplLB->set_size_request(nTermWidth, -1);
340 Construct_Impl();
343 void SvxSearchDialog::ChildWinDispose()
345 rBindings.EnterRegistrations();
346 pSearchController.reset();
347 pOptionsController.reset();
348 pFamilyController.reset();
349 rBindings.LeaveRegistrations();
350 SfxModelessDialogController::ChildWinDispose();
353 SvxSearchDialog::~SvxSearchDialog()
357 void SvxSearchDialog::Construct_Impl()
359 pImpl.reset( new SearchDlg_Impl() );
360 pImpl->aSelectionTimer.SetTimeout( 500 );
361 pImpl->aSelectionTimer.SetInvokeHandler(
362 LINK( this, SvxSearchDialog, TimeoutHdl_Impl ) );
363 EnableControls_Impl( SearchOptionFlags::NONE );
365 // Store old Text from m_xWordBtn
366 aCalcStr += "#";
367 aCalcStr += m_xWordBtn->get_label();
369 aLayoutStr = SvxResId( RID_SVXSTR_SEARCH_STYLES );
370 aLayoutWriterStr = SvxResId( RID_SVXSTR_WRITER_STYLES );
371 aLayoutCalcStr = SvxResId( RID_SVXSTR_CALC_STYLES );
372 aStylesStr = m_xLayoutBtn->get_label();
374 // Get stored search-strings from the application
375 ListToStrArr_Impl(SID_SEARCHDLG_SEARCHSTRINGS,
376 aSearchStrings, *m_xSearchLB, nRememberSize);
377 ListToStrArr_Impl(SID_SEARCHDLG_REPLACESTRINGS,
378 aReplaceStrings, *m_xReplaceLB, nRememberSize);
380 InitControls_Impl();
382 // Get attribute sets only once in constructor()
383 const SfxPoolItem* ppArgs[] = { pSearchItem.get(), nullptr };
384 const SvxSetItem* pSrchSetItem =
385 static_cast<const SvxSetItem*>( rBindings.GetDispatcher()->Execute( FID_SEARCH_SEARCHSET, SfxCallMode::SLOT, ppArgs ) );
387 if ( pSrchSetItem )
388 InitAttrList_Impl( &pSrchSetItem->GetItemSet(), nullptr );
390 const SvxSetItem* pReplSetItem =
391 static_cast<const SvxSetItem*>( rBindings.GetDispatcher()->Execute( FID_SEARCH_REPLACESET, SfxCallMode::SLOT, ppArgs ) );
393 if ( pReplSetItem )
394 InitAttrList_Impl( nullptr, &pReplSetItem->GetItemSet() );
396 // Create controller and update at once
397 rBindings.EnterRegistrations();
398 pSearchController.reset(
399 new SvxSearchController( SID_SEARCH_ITEM, rBindings, *this ) );
400 pOptionsController.reset(
401 new SvxSearchController( SID_SEARCH_OPTIONS, rBindings, *this ) );
402 rBindings.LeaveRegistrations();
403 rBindings.GetDispatcher()->Execute( FID_SEARCH_ON, SfxCallMode::SLOT, ppArgs );
404 pImpl->aSelectionTimer.Start();
407 SvtCJKOptions aCJKOptions;
408 if(!aCJKOptions.IsJapaneseFindEnabled())
410 m_xJapOptionsCB->set_active( false );
411 m_xJapOptionsCB->hide();
412 m_xJapOptionsBtn->hide();
414 if(!aCJKOptions.IsCJKFontEnabled())
416 m_xJapMatchFullHalfWidthCB->hide();
418 SvtCTLOptions aCTLOptions;
419 // Do not disable and hide the m_xIncludeDiacritics button.
420 // Include Diacritics == Not Ignore Diacritics => A does not match A-Umlaut (Diaeresis).
421 // Confusingly these have negated names (following the UI) but the actual
422 // transliteration is to *ignore* diacritics if "included" (sensitive) is
423 // _not_ checked.
424 if(!aCTLOptions.IsCTLFontEnabled())
426 m_xIncludeDiacritics->set_active( true );
427 m_xIncludeKashida->set_active( true );
428 m_xIncludeKashida->hide();
430 //component extension - show component search buttons if the commands
431 // vnd.sun.star::SearchViaComponent1 and 2 are supported
432 const uno::Reference< frame::XFrame >xFrame = rBindings.GetActiveFrame();
433 const uno::Reference< frame::XDispatchProvider > xDispatchProv(xFrame, uno::UNO_QUERY);
434 OUString sTarget("_self");
436 bool bSearchComponent1 = false;
437 bool bSearchComponent2 = false;
438 if(xDispatchProv.is() &&
439 (pImpl->xCommand1Dispatch = xDispatchProv->queryDispatch(pImpl->aCommand1URL, sTarget, 0)).is())
441 bSearchComponent1 = true;
443 if(xDispatchProv.is() &&
444 (pImpl->xCommand2Dispatch = xDispatchProv->queryDispatch(pImpl->aCommand2URL, sTarget, 0)).is())
446 bSearchComponent2 = true;
449 if( bSearchComponent1 || bSearchComponent2 )
453 uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider =
454 configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() );
455 uno::Sequence< uno::Any > aArgs {
456 Any(OUString( "/org.openoffice.Office.Common/SearchOptions/")) };
458 uno::Reference< uno::XInterface > xIFace = xConfigurationProvider->createInstanceWithArguments(
459 "com.sun.star.configuration.ConfigurationUpdateAccess",
460 aArgs);
461 uno::Reference< container::XNameAccess> xDirectAccess(xIFace, uno::UNO_QUERY);
462 if(xDirectAccess.is())
464 OUString sTemp;
465 uno::Any aRet = xDirectAccess->getByName("ComponentSearchGroupLabel");
466 aRet >>= sTemp;
467 m_xComponentFrame->set_label(sTemp);
468 aRet = xDirectAccess->getByName("ComponentSearchCommandLabel1");
469 aRet >>= sTemp;
470 m_xSearchComponent1PB->set_label( sTemp );
471 aRet = xDirectAccess->getByName("ComponentSearchCommandLabel2");
472 aRet >>= sTemp;
473 m_xSearchComponent2PB->set_label( sTemp );
476 catch(uno::Exception&){}
478 if(!m_xSearchComponent1PB->get_label().isEmpty() && bSearchComponent1 )
480 m_xComponentFrame->show();
481 m_xSearchComponent1PB->show();
483 if( !m_xSearchComponent2PB->get_label().isEmpty() )
485 m_xComponentFrame->show();
486 m_xSearchComponent2PB->show();
491 void SvxSearchDialog::Close()
493 // remember strings
494 if (!aSearchStrings.empty())
495 StrArrToList_Impl( SID_SEARCHDLG_SEARCHSTRINGS, aSearchStrings );
497 if (!aReplaceStrings.empty())
498 StrArrToList_Impl( SID_SEARCHDLG_REPLACESTRINGS, aReplaceStrings );
500 // save settings to configuration
501 SvtSearchOptions aOpt;
502 aOpt.SetWholeWordsOnly ( m_xWordBtn->get_active() );
503 aOpt.SetBackwards ( m_xReplaceBackwardsCB->get_active() );
504 aOpt.SetUseRegularExpression ( m_xRegExpBtn->get_active() );
505 aOpt.SetUseWildcard ( m_xWildcardBtn->get_active() );
506 aOpt.SetSearchForStyles ( m_xLayoutBtn->get_active() );
507 aOpt.SetSimilaritySearch ( m_xSimilarityBox->get_active() );
508 aOpt.SetUseAsianOptions ( m_xJapOptionsCB->get_active() );
509 aOpt.SetNotes ( m_xNotesBtn->get_active() );
510 aOpt.SetIgnoreDiacritics_CTL ( !m_xIncludeDiacritics->get_active() );
511 aOpt.SetIgnoreKashida_CTL ( !m_xIncludeKashida->get_active() );
512 aOpt.SetSearchFormatted ( m_xSearchFormattedCB->get_active() );
513 aOpt.Commit();
515 if (IsClosing())
516 return;
518 const SfxPoolItem* ppArgs[] = { pSearchItem.get(), nullptr };
519 rBindings.GetDispatcher()->Execute( FID_SEARCH_OFF, SfxCallMode::SLOT, ppArgs );
520 rBindings.Invalidate(SID_SEARCH_DLG);
522 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
523 if (pViewFrame)
524 pViewFrame->ToggleChildWindow(SID_SEARCH_DLG);
527 TransliterationFlags SvxSearchDialog::GetTransliterationFlags() const
529 if (!m_xMatchCaseCB->get_active())
530 nTransliterationFlags |= TransliterationFlags::IGNORE_CASE;
531 else
532 nTransliterationFlags &= ~TransliterationFlags::IGNORE_CASE;
533 if ( !m_xJapMatchFullHalfWidthCB->get_active())
534 nTransliterationFlags |= TransliterationFlags::IGNORE_WIDTH;
535 else
536 nTransliterationFlags &= ~TransliterationFlags::IGNORE_WIDTH;
537 return nTransliterationFlags;
540 void SvxSearchDialog::SetSaveToModule(bool b)
542 pImpl->bSaveToModule = b;
545 void SvxSearchDialog::SetSearchLabel(const OUString& rStr)
547 m_xSearchLabel->set_label(rStr);
549 if (rStr == SvxResId(RID_SVXSTR_SEARCH_NOT_FOUND))
550 m_xSearchLB->set_entry_message_type(weld::EntryMessageType::Error);
553 void SvxSearchDialog::ApplyTransliterationFlags_Impl( TransliterationFlags nSettings )
555 nTransliterationFlags = nSettings;
556 bool bVal(nSettings & TransliterationFlags::IGNORE_CASE);
557 m_xMatchCaseCB->set_active( !bVal );
558 bVal = bool(nSettings & TransliterationFlags::IGNORE_WIDTH);
559 m_xJapMatchFullHalfWidthCB->set_active( !bVal );
563 bool SvxSearchDialog::IsOtherOptionsExpanded() const
565 return m_xReplaceBackwardsCB->get_active() ||
566 m_xSelectionBtn->get_active() ||
567 m_xRegExpBtn->get_active() ||
568 m_xLayoutBtn->get_active() ||
569 m_xSimilarityBox->get_active() ||
570 m_xJapMatchFullHalfWidthCB->get_active() ||
571 m_xJapOptionsCB->get_active() ||
572 m_xWildcardBtn->get_active() ||
573 m_xNotesBtn->get_active() ||
574 m_xIncludeKashida->get_active() ||
575 m_xIncludeDiacritics->get_active();
578 void SvxSearchDialog::Activate()
580 // apply possible transliteration changes of the SvxSearchItem member
581 DBG_ASSERT( pSearchItem, "SearchItem missing" );
582 if (pSearchItem)
584 m_xMatchCaseCB->set_active( pSearchItem->GetExact() );
585 m_xJapMatchFullHalfWidthCB->set_active( !pSearchItem->IsMatchFullHalfWidthForms() );
588 SfxModelessDialogController::Activate();
591 void SvxSearchDialog::InitControls_Impl()
593 // CaseSensitives AutoComplete
594 m_xSearchLB->set_entry_completion( true, true );
595 m_xSearchLB->show();
596 m_xReplaceLB->set_entry_completion( true, true );
597 m_xReplaceLB->show();
599 m_xFormatBtn->set_sensitive(false);
600 m_xAttributeBtn->set_sensitive(false);
602 m_xSearchLB->connect_changed( LINK( this, SvxSearchDialog, ModifyHdl_Impl ) );
603 m_xReplaceLB->connect_changed( LINK( this, SvxSearchDialog, ModifyHdl_Impl ) );
605 Link<weld::Widget&,void> aLink = LINK( this, SvxSearchDialog, FocusHdl_Impl );
606 m_xSearchLB->connect_focus_in( aLink );
607 m_xReplaceLB->connect_focus_in( aLink );
609 aLink = LINK( this, SvxSearchDialog, LoseFocusHdl_Impl );
610 m_xSearchLB->connect_focus_out( aLink );
611 m_xReplaceLB->connect_focus_out( aLink );
613 m_xSearchTmplLB->connect_focus_out( aLink );
614 m_xReplaceTmplLB->connect_focus_out( aLink );
616 Link<weld::Button&,void> aLink2 = LINK( this, SvxSearchDialog, CommandHdl_Impl );
617 m_xSearchBtn->connect_clicked( aLink2 );
618 m_xBackSearchBtn->connect_clicked( aLink2 );
619 m_xSearchAllBtn->connect_clicked( aLink2 );
620 m_xReplaceBtn->connect_clicked( aLink2 );
621 m_xReplaceAllBtn->connect_clicked( aLink2 );
622 m_xCloseBtn->connect_clicked( aLink2 );
623 m_xSimilarityBtn->connect_clicked( aLink2 );
624 m_xJapOptionsBtn->connect_clicked( aLink2 );
625 m_xSearchComponent1PB->connect_clicked( aLink2 );
626 m_xSearchComponent2PB->connect_clicked( aLink2 );
628 aLink2 = LINK( this, SvxSearchDialog, FlagHdl_Impl );
629 m_xReplaceBackwardsCB->connect_clicked( aLink2 );
630 m_xWordBtn->connect_clicked( aLink2 );
631 m_xSelectionBtn->connect_clicked( aLink2 );
632 m_xMatchCaseCB->connect_clicked( aLink2 );
633 m_xRegExpBtn->connect_clicked( aLink2 );
634 m_xWildcardBtn->connect_clicked( aLink2 );
635 m_xNotesBtn->connect_clicked( aLink2 );
636 m_xSimilarityBox->connect_clicked( aLink2 );
637 m_xJapOptionsCB->connect_clicked( aLink2 );
638 m_xJapMatchFullHalfWidthCB->connect_clicked( aLink2 );
639 m_xIncludeDiacritics->connect_clicked( aLink2 );
640 m_xIncludeKashida->connect_clicked( aLink2 );
641 m_xLayoutBtn->connect_clicked( LINK( this, SvxSearchDialog, TemplateHdl_Impl ) );
642 m_xFormatBtn->connect_clicked( LINK( this, SvxSearchDialog, FormatHdl_Impl ) );
643 m_xNoFormatBtn->connect_clicked(
644 LINK( this, SvxSearchDialog, NoFormatHdl_Impl ) );
645 m_xAttributeBtn->connect_clicked(
646 LINK( this, SvxSearchDialog, AttributeHdl_Impl ) );
649 namespace
651 SvtModuleOptions::EFactory getModule(SfxBindings const & rBindings)
653 SvtModuleOptions::EFactory eFactory(SvtModuleOptions::EFactory::UNKNOWN_FACTORY);
656 const uno::Reference< frame::XFrame > xFrame =
657 rBindings.GetActiveFrame();
658 uno::Reference< frame::XModuleManager2 > xModuleManager(
659 frame::ModuleManager::create(::comphelper::getProcessComponentContext()));
661 OUString aModuleIdentifier = xModuleManager->identify( xFrame );
662 eFactory = SvtModuleOptions::ClassifyFactoryByServiceName(aModuleIdentifier);
664 catch (const uno::Exception&)
667 return eFactory;
671 void SvxSearchDialog::ShowOptionalControls_Impl()
673 DBG_ASSERT( pSearchItem, "no search item" );
675 SvtCJKOptions aCJKOptions;
676 SvtCTLOptions aCTLOptions;
677 SvtModuleOptions::EFactory eFactory = getModule(rBindings);
678 bool bDrawApp = eFactory == SvtModuleOptions::EFactory::DRAW;
679 bool bWriterApp =
680 eFactory == SvtModuleOptions::EFactory::WRITER ||
681 eFactory == SvtModuleOptions::EFactory::WRITERWEB ||
682 eFactory == SvtModuleOptions::EFactory::WRITERGLOBAL;
683 bool bCalcApp = eFactory == SvtModuleOptions::EFactory::CALC;
685 m_xLayoutBtn->set_visible(!bDrawApp);
686 m_xNotesBtn->set_visible(bWriterApp);
687 m_xRegExpBtn->set_visible(!bDrawApp);
688 m_xWildcardBtn->set_visible(bCalcApp); /* TODO:WILDCARD enable for other apps if hey handle it */
689 m_xReplaceBackwardsCB->show();
690 m_xSimilarityBox->show();
691 m_xSimilarityBtn->show();
692 m_xSelectionBtn->show();
693 m_xIncludeDiacritics->show();
694 m_xIncludeKashida->set_visible(aCTLOptions.IsCTLFontEnabled());
695 m_xJapMatchFullHalfWidthCB->set_visible(aCJKOptions.IsCJKFontEnabled());
696 m_xJapOptionsCB->set_visible(aCJKOptions.IsJapaneseFindEnabled());
697 m_xJapOptionsBtn->set_visible(aCJKOptions.IsJapaneseFindEnabled());
699 if (bWriter)
701 m_xAttributeBtn->show();
702 m_xFormatBtn->show();
703 m_xNoFormatBtn->show();
706 if (bCalcApp)
708 m_xCalcSearchInFT->show();
709 m_xCalcSearchInLB->show();
710 m_xCalcSearchDirFT->show();
711 m_xRowsBtn->show();
712 m_xColumnsBtn->show();
713 m_xAllSheetsCB->show();
714 m_xSearchFormattedCB->show();
719 namespace {
721 class ToggleSaveToModule
723 public:
724 ToggleSaveToModule(SvxSearchDialog& rDialog, bool bValue) :
725 mrDialog(rDialog), mbValue(bValue)
727 mrDialog.SetSaveToModule(mbValue);
730 ~ToggleSaveToModule()
732 mrDialog.SetSaveToModule(!mbValue);
734 private:
735 SvxSearchDialog& mrDialog;
736 bool const mbValue;
741 void SvxSearchDialog::Init_Impl( bool bSearchPattern )
743 DBG_ASSERT( pSearchItem, "SearchItem == 0" );
745 // We don't want to save any intermediate state to the module while the
746 // dialog is being initialized.
747 ToggleSaveToModule aNoModuleSave(*this, false);
748 SvtSearchOptions aOpt;
750 bWriter = ( pSearchItem->GetAppFlag() == SvxSearchApp::WRITER );
752 if ( !( nModifyFlag & ModifyFlags::Word ) )
753 m_xWordBtn->set_active( pSearchItem->GetWordOnly() );
754 if ( !( nModifyFlag & ModifyFlags::Exact ) )
755 m_xMatchCaseCB->set_active( pSearchItem->GetExact() );
756 if ( !( nModifyFlag & ModifyFlags::Backwards ) )
757 m_xReplaceBackwardsCB->set_active( bReplaceBackwards ); //adjustment to replace backwards
758 if ( !( nModifyFlag & ModifyFlags::Notes ) )
759 m_xNotesBtn->set_active( pSearchItem->GetNotes() );
760 if ( !( nModifyFlag & ModifyFlags::Selection ) )
761 m_xSelectionBtn->set_active( pSearchItem->GetSelection() );
762 if ( !( nModifyFlag & ModifyFlags::Regexp ) )
763 m_xRegExpBtn->set_active( pSearchItem->GetRegExp() );
764 if ( !( nModifyFlag & ModifyFlags::Wildcard ) )
765 m_xWildcardBtn->set_active( pSearchItem->GetWildcard() );
766 if ( !( nModifyFlag & ModifyFlags::Layout ) )
767 m_xLayoutBtn->set_active( pSearchItem->GetPattern() );
768 if (m_xNotesBtn->get_active())
769 m_xLayoutBtn->set_sensitive(false);
770 m_xSimilarityBox->set_active( pSearchItem->IsLevenshtein() );
771 if ( m_xJapOptionsCB->get_visible() )
772 m_xJapOptionsCB->set_active( pSearchItem->IsUseAsianOptions() );
773 m_xIncludeDiacritics->set_active( !aOpt.IsIgnoreDiacritics_CTL() );
774 if ( m_xIncludeKashida->get_visible() )
775 m_xIncludeKashida->set_active( !aOpt.IsIgnoreKashida_CTL() );
776 if ( SvxSearchDialog::IsOtherOptionsExpanded() )
777 m_xOtherOptionsExpander->set_expanded( true );
778 ApplyTransliterationFlags_Impl( pSearchItem->GetTransliterationFlags() );
780 ShowOptionalControls_Impl();
782 if ( pSearchItem->GetAppFlag() == SvxSearchApp::CALC )
784 m_xCalcGrid->show();
785 m_xSearchFormattedCB->set_active( aOpt.IsSearchFormatted() );
786 Link<weld::Button&,void> aLink = LINK( this, SvxSearchDialog, FlagHdl_Impl );
787 m_xCalcSearchInLB->connect_changed( LINK( this, SvxSearchDialog, LBSelectHdl_Impl ) );
788 m_xRowsBtn->connect_clicked( aLink );
789 m_xColumnsBtn->connect_clicked( aLink );
790 m_xAllSheetsCB->connect_clicked( aLink );
791 m_xSearchFormattedCB->connect_clicked( aLink );
793 ModifyFlags nModifyFlagCheck;
794 switch ( pSearchItem->GetCellType() )
796 case SvxSearchCellType::FORMULA:
797 nModifyFlagCheck = ModifyFlags::Formulas;
798 break;
800 case SvxSearchCellType::VALUE:
801 nModifyFlagCheck = ModifyFlags::Values;
802 break;
804 case SvxSearchCellType::NOTE:
805 nModifyFlagCheck = ModifyFlags::CalcNotes;
806 break;
808 default:
809 std::abort(); // cannot happen
811 if ( !(nModifyFlag & nModifyFlagCheck) )
812 m_xCalcSearchInLB->set_active( static_cast<sal_Int32>(pSearchItem->GetCellType()) );
814 m_xWordBtn->set_label( aCalcStr.getToken( 0, '#' ) );
816 if ( pSearchItem->GetRowDirection() &&
817 !( nModifyFlag & ModifyFlags::Rows ) )
818 m_xRowsBtn->set_active(true);
819 else if ( !pSearchItem->GetRowDirection() &&
820 !( nModifyFlag & ModifyFlags::Columns ) )
821 m_xColumnsBtn->set_active(true);
823 if ( !( nModifyFlag & ModifyFlags::AllTables ) )
824 m_xAllSheetsCB->set_active( pSearchItem->IsAllTables() );
826 // only look for formatting in Writer
827 m_xFormatBtn->hide();
828 m_xNoFormatBtn->hide();
829 m_xAttributeBtn->hide();
831 else
833 m_xSearchFormattedCB->hide();
834 m_xWordBtn->set_label( aCalcStr.getToken( 1, '#' ) );
836 if ( pSearchItem->GetAppFlag() == SvxSearchApp::DRAW )
838 m_xSearchAllBtn->hide();
840 m_xRegExpBtn->hide();
841 m_xWildcardBtn->hide();
842 m_xLayoutBtn->hide();
844 // only look for formatting in Writer
845 m_xFormatBtn->hide();
846 m_xNoFormatBtn->hide();
847 m_xAttributeBtn->hide();
849 else
851 m_xWildcardBtn->hide(); /* TODO:WILDCARD do not hide for other apps if they handle it */
853 if ( !pSearchList )
855 // Get attribute sets, if it not has been done already
856 const SfxPoolItem* ppArgs[] = { pSearchItem.get(), nullptr };
857 const SvxSetItem* pSrchSetItem =
858 static_cast<const SvxSetItem*>(rBindings.GetDispatcher()->Execute( FID_SEARCH_SEARCHSET, SfxCallMode::SLOT, ppArgs ));
860 if ( pSrchSetItem )
861 InitAttrList_Impl( &pSrchSetItem->GetItemSet(), nullptr );
863 const SvxSetItem* pReplSetItem =
864 static_cast<const SvxSetItem*>( rBindings.GetDispatcher()->Execute( FID_SEARCH_REPLACESET, SfxCallMode::SLOT, ppArgs ) );
866 if ( pReplSetItem )
867 InitAttrList_Impl( nullptr, &pReplSetItem->GetItemSet() );
872 // similarity search?
873 if ( !( nModifyFlag & ModifyFlags::Similarity ) )
874 m_xSimilarityBox->set_active( pSearchItem->IsLevenshtein() );
875 bSet = true;
877 FlagHdl_Impl(*m_xSimilarityBox);
878 FlagHdl_Impl(*m_xJapOptionsCB);
880 bool bDisableSearch = false;
881 SfxViewShell* pViewShell = SfxViewShell::Current();
883 if ( pViewShell )
885 bool bText = !bSearchPattern;
887 if ( pViewShell->HasSelection( bText ) )
888 EnableControl_Impl(*m_xSelectionBtn);
889 else
891 m_xSelectionBtn->set_active( false );
892 m_xSelectionBtn->set_sensitive(false);
896 // Pattern Search and there were no AttrSets given
897 if ( bSearchPattern )
899 SfxObjectShell* pShell = SfxObjectShell::Current();
901 if ( pShell && pShell->GetStyleSheetPool() )
903 // Templates designed
904 m_xSearchTmplLB->clear();
905 m_xReplaceTmplLB->clear();
906 SfxStyleSheetBasePool* pStylePool = pShell->GetStyleSheetPool();
907 pStylePool->SetSearchMask( pSearchItem->GetFamily() );
908 SfxStyleSheetBase* pBase = pStylePool->First();
910 while ( pBase )
912 if ( pBase->IsUsed() )
913 m_xSearchTmplLB->append_text( pBase->GetName() );
914 m_xReplaceTmplLB->append_text( pBase->GetName() );
915 pBase = pStylePool->Next();
917 m_xSearchTmplLB->set_active_text( pSearchItem->GetSearchString() );
918 m_xReplaceTmplLB->set_active_text( pSearchItem->GetReplaceString() );
921 m_xSearchTmplLB->show();
923 if ( bConstruct )
924 // Grab focus only after creating
925 m_xSearchTmplLB->grab_focus();
926 m_xReplaceTmplLB->show();
927 m_xSearchLB->hide();
928 m_xReplaceLB->hide();
930 m_xWordBtn->set_sensitive(false);
931 m_xRegExpBtn->set_sensitive(false);
932 m_xWildcardBtn->set_sensitive(false);
933 m_xMatchCaseCB->set_sensitive(false);
935 bDisableSearch = !m_xSearchTmplLB->get_count();
937 else
939 bool bSetSearch = !( nModifyFlag & ModifyFlags::Search );
940 bool bSetReplace = !( nModifyFlag & ModifyFlags::Replace );
942 if ( !(pSearchItem->GetSearchString().isEmpty()) && bSetSearch )
943 m_xSearchLB->set_entry_text( pSearchItem->GetSearchString() );
944 else if (!aSearchStrings.empty())
946 bool bAttributes =
947 ( ( pSearchList && pSearchList->Count() ) ||
948 ( pReplaceList && pReplaceList->Count() ) );
950 if ( bSetSearch && !bAttributes )
951 m_xSearchLB->set_entry_text(aSearchStrings[0]);
953 OUString aReplaceTxt = pSearchItem->GetReplaceString();
955 if (!aReplaceStrings.empty())
956 aReplaceTxt = aReplaceStrings[0];
958 if ( bSetReplace && !bAttributes )
959 m_xReplaceLB->set_entry_text( aReplaceTxt );
961 m_xSearchLB->show();
963 if ( bConstruct )
964 // Grab focus only after creating
965 m_xSearchLB->grab_focus();
966 m_xReplaceLB->show();
967 m_xSearchTmplLB->hide();
968 m_xReplaceTmplLB->hide();
970 EnableControl_Impl(*m_xRegExpBtn);
971 EnableControl_Impl(*m_xWildcardBtn);
972 EnableControl_Impl(*m_xMatchCaseCB);
974 if ( m_xRegExpBtn->get_active() )
975 m_xWordBtn->set_sensitive(false);
976 else
977 EnableControl_Impl(*m_xWordBtn);
979 bDisableSearch = m_xSearchLB->get_active_text().isEmpty() &&
980 m_xSearchAttrText->get_label().isEmpty();
982 FocusHdl_Impl(*m_xSearchLB);
984 if ( bDisableSearch )
986 m_xSearchBtn->set_sensitive(false);
987 m_xBackSearchBtn->set_sensitive(false);
988 m_xSearchAllBtn->set_sensitive(false);
989 m_xReplaceBtn->set_sensitive(false);
990 m_xReplaceAllBtn->set_sensitive(false);
991 m_xComponentFrame->set_sensitive(false);
993 else
995 EnableControl_Impl(*m_xSearchBtn);
996 EnableControl_Impl(*m_xBackSearchBtn);
997 EnableControl_Impl(*m_xReplaceBtn);
998 if (!bWriter || !m_xNotesBtn->get_active())
1000 EnableControl_Impl(*m_xSearchAllBtn);
1001 EnableControl_Impl(*m_xReplaceAllBtn);
1003 if (bWriter && pSearchItem->GetNotes())
1005 m_xSearchAllBtn->set_sensitive(false);
1006 m_xReplaceAllBtn->set_sensitive(false);
1010 if (!m_xSearchAttrText->get_label().isEmpty())
1011 EnableControl_Impl(*m_xNoFormatBtn);
1012 else
1013 m_xNoFormatBtn->set_sensitive(false);
1015 if ( !pSearchList )
1017 m_xAttributeBtn->set_sensitive(false);
1018 m_xFormatBtn->set_sensitive(false);
1021 if ( m_xLayoutBtn->get_active() )
1023 pImpl->bSaveToModule = false;
1024 TemplateHdl_Impl(*m_xLayoutBtn);
1025 pImpl->bSaveToModule = true;
1030 void SvxSearchDialog::InitAttrList_Impl( const SfxItemSet* pSSet,
1031 const SfxItemSet* pRSet )
1033 if ( !pSSet && !pRSet )
1034 return;
1036 if ( !pImpl->pRanges && pSSet )
1038 const sal_uInt16* pPtr = pSSet->GetRanges();
1039 const sal_uInt16* pTmp = pPtr;
1041 while( *pPtr )
1043 pPtr += 2;
1045 sal_sSize nCnt = pPtr - pTmp + 1;
1046 pImpl->pRanges.reset( new sal_uInt16[nCnt] );
1047 memcpy( pImpl->pRanges.get(), pTmp, sizeof(sal_uInt16) * nCnt );
1050 bool bSetOptimalLayoutSize = false;
1052 // See to it that are the texts of the attributes are correct
1053 OUString aDesc;
1055 if ( pSSet )
1057 pSearchList.reset(new SearchAttrItemList);
1059 if ( pSSet->Count() )
1061 pSearchList->Put( *pSSet );
1063 m_xSearchAttrText->set_label( BuildAttrText_Impl( aDesc, true ) );
1065 if ( !aDesc.isEmpty() )
1067 if (!m_xSearchAttrText->get_visible())
1069 m_xSearchAttrText->show();
1070 bSetOptimalLayoutSize = true;
1072 bFormat |= true;
1077 if ( pRSet )
1079 pReplaceList.reset(new SearchAttrItemList);
1081 if ( pRSet->Count() )
1083 pReplaceList->Put( *pRSet );
1085 m_xReplaceAttrText->set_label( BuildAttrText_Impl( aDesc, false ) );
1087 if ( !aDesc.isEmpty() )
1089 if (!m_xReplaceAttrText->get_visible())
1091 m_xReplaceAttrText->show();
1092 bSetOptimalLayoutSize = true;
1094 bFormat |= true;
1099 if (bSetOptimalLayoutSize)
1100 m_xDialog->resize_to_request();
1103 IMPL_LINK( SvxSearchDialog, LBSelectHdl_Impl, weld::ComboBox&, rCtrl, void )
1105 ClickHdl_Impl(&rCtrl);
1108 IMPL_LINK( SvxSearchDialog, FlagHdl_Impl, weld::Button&, rCtrl, void )
1110 ClickHdl_Impl(&rCtrl);
1113 void SvxSearchDialog::ClickHdl_Impl(const weld::Widget* pCtrl)
1115 if ( pCtrl && !bSet )
1116 SetModifyFlag_Impl(pCtrl);
1117 else
1118 bSet = false;
1120 if (pCtrl == m_xSimilarityBox.get())
1122 bool bIsChecked = m_xSimilarityBox->get_active();
1124 if ( bIsChecked )
1126 m_xSimilarityBtn->set_sensitive(true);
1127 m_xRegExpBtn->set_active( false );
1128 m_xRegExpBtn->set_sensitive(false);
1129 m_xWildcardBtn->set_active( false );
1130 m_xWildcardBtn->set_sensitive(false);
1131 EnableControl_Impl(*m_xWordBtn);
1133 if ( m_xLayoutBtn->get_active() )
1135 EnableControl_Impl(*m_xMatchCaseCB);
1136 m_xLayoutBtn->set_active( false );
1138 m_xRegExpBtn->set_sensitive(false);
1139 m_xWildcardBtn->set_sensitive(false);
1140 m_xLayoutBtn->set_sensitive(false);
1141 m_xFormatBtn->set_sensitive(false);
1142 m_xNoFormatBtn->set_sensitive(false);
1143 m_xAttributeBtn->set_sensitive(false);
1145 else
1147 EnableControl_Impl(*m_xRegExpBtn);
1148 EnableControl_Impl(*m_xWildcardBtn);
1149 if (!m_xNotesBtn->get_active())
1150 EnableControl_Impl(*m_xLayoutBtn);
1151 EnableControl_Impl(*m_xFormatBtn);
1152 EnableControl_Impl(*m_xAttributeBtn);
1153 m_xSimilarityBtn->set_sensitive(false);
1155 pSearchItem->SetLevenshtein( bIsChecked );
1157 else if (pCtrl == m_xNotesBtn.get())
1159 if (m_xNotesBtn->get_active())
1161 m_xLayoutBtn->set_sensitive(false);
1162 m_xSearchAllBtn->set_sensitive(false);
1163 m_xReplaceAllBtn->set_sensitive(false);
1165 else
1167 EnableControl_Impl(*m_xLayoutBtn);
1168 ModifyHdl_Impl(*m_xSearchLB);
1171 else
1173 if ( m_xLayoutBtn->get_active() && !bFormat )
1175 m_xWordBtn->set_active( false );
1176 m_xWordBtn->set_sensitive(false);
1177 m_xRegExpBtn->set_active( false );
1178 m_xRegExpBtn->set_sensitive(false);
1179 m_xWildcardBtn->set_active( false );
1180 m_xWildcardBtn->set_sensitive(false);
1181 m_xMatchCaseCB->set_active( false );
1182 m_xMatchCaseCB->set_sensitive(false);
1183 m_xNotesBtn->set_sensitive(false);
1185 if ( m_xSearchTmplLB->get_count() )
1187 EnableControl_Impl(*m_xSearchBtn);
1188 EnableControl_Impl(*m_xBackSearchBtn);
1189 EnableControl_Impl(*m_xSearchAllBtn);
1190 EnableControl_Impl(*m_xReplaceBtn);
1191 EnableControl_Impl(*m_xReplaceAllBtn);
1194 else
1196 EnableControl_Impl(*m_xRegExpBtn);
1197 EnableControl_Impl(*m_xWildcardBtn);
1198 EnableControl_Impl(*m_xMatchCaseCB);
1199 EnableControl_Impl(*m_xNotesBtn);
1201 if ( m_xRegExpBtn->get_active() )
1203 m_xWordBtn->set_active( false );
1204 m_xWordBtn->set_sensitive(false);
1205 m_xWildcardBtn->set_active( false );
1206 m_xWildcardBtn->set_sensitive(false);
1207 m_xSimilarityBox->set_active( false );
1208 m_xSimilarityBox->set_sensitive(false);
1209 m_xSimilarityBtn->set_sensitive(false);
1211 else if ( m_xWildcardBtn->get_active() )
1213 m_xRegExpBtn->set_active( false );
1214 m_xRegExpBtn->set_sensitive(false);
1215 m_xSimilarityBox->set_active( false );
1216 m_xSimilarityBox->set_sensitive(false);
1217 m_xSimilarityBtn->set_sensitive(false);
1219 else
1221 EnableControl_Impl(*m_xWordBtn);
1222 EnableControl_Impl(*m_xSimilarityBox);
1225 // Search-string in place? then enable Buttons
1226 bSet = true;
1227 ModifyHdl_Impl(*m_xSearchLB);
1231 if (pCtrl == m_xAllSheetsCB.get())
1233 bSet = true;
1234 ModifyHdl_Impl(*m_xSearchLB);
1237 if (pCtrl == m_xJapOptionsCB.get())
1239 bool bEnableJapOpt = m_xJapOptionsCB->get_active();
1240 m_xMatchCaseCB->set_sensitive(!bEnableJapOpt );
1241 m_xJapMatchFullHalfWidthCB->set_sensitive(!bEnableJapOpt );
1242 m_xJapOptionsBtn->set_sensitive( bEnableJapOpt );
1245 if ( pImpl->bSaveToModule )
1246 SaveToModule_Impl();
1249 IMPL_LINK(SvxSearchDialog, CommandHdl_Impl, weld::Button&, rBtn, void)
1251 bool bInclusive = ( m_xLayoutBtn->get_label() == aLayoutStr );
1253 if ( ( &rBtn == m_xSearchBtn.get() ) ||
1254 (&rBtn == m_xBackSearchBtn.get()) ||
1255 ( &rBtn == m_xSearchAllBtn.get() )||
1256 ( &rBtn == m_xReplaceBtn.get() ) ||
1257 ( &rBtn == m_xReplaceAllBtn.get() ) )
1259 if ( m_xLayoutBtn->get_active() && !bInclusive )
1261 pSearchItem->SetSearchString ( m_xSearchTmplLB->get_active_text() );
1262 pSearchItem->SetReplaceString( m_xReplaceTmplLB->get_active_text() );
1264 else
1266 pSearchItem->SetSearchString ( m_xSearchLB->get_active_text() );
1267 pSearchItem->SetReplaceString( m_xReplaceLB->get_active_text() );
1269 if ( &rBtn == m_xReplaceBtn.get() )
1270 Remember_Impl( m_xReplaceLB->get_active_text(), false );
1271 else
1273 Remember_Impl( m_xSearchLB->get_active_text(), true );
1275 if ( &rBtn == m_xReplaceAllBtn.get() )
1276 Remember_Impl( m_xReplaceLB->get_active_text(), false );
1280 pSearchItem->SetRegExp( false );
1281 pSearchItem->SetWildcard( false );
1282 pSearchItem->SetLevenshtein( false );
1283 if (GetCheckBoxValue(*m_xRegExpBtn))
1284 pSearchItem->SetRegExp( true );
1285 else if (GetCheckBoxValue(*m_xWildcardBtn))
1286 pSearchItem->SetWildcard( true );
1287 else if (GetCheckBoxValue(*m_xSimilarityBox))
1288 pSearchItem->SetLevenshtein( true );
1290 pSearchItem->SetWordOnly(GetCheckBoxValue(*m_xWordBtn));
1292 bool bSetBackwards = false;
1293 if( &rBtn == m_xBackSearchBtn.get())
1295 bSetBackwards = true;
1297 else if( &rBtn == m_xReplaceBtn.get())
1299 bSetBackwards = GetCheckBoxValue(*m_xReplaceBackwardsCB);
1300 bReplaceBackwards = GetCheckBoxValue(*m_xReplaceBackwardsCB);
1303 pSearchItem->SetBackward(bSetBackwards);
1305 pSearchItem->SetNotes(GetCheckBoxValue(*m_xNotesBtn));
1306 pSearchItem->SetPattern(GetCheckBoxValue(*m_xLayoutBtn));
1307 pSearchItem->SetSelection(GetCheckBoxValue(*m_xSelectionBtn));
1308 pSearchItem->SetUseAsianOptions(GetCheckBoxValue(*m_xJapOptionsCB));
1309 TransliterationFlags nFlags = GetTransliterationFlags();
1310 if( !pSearchItem->IsUseAsianOptions())
1311 nFlags &= TransliterationFlags::IGNORE_CASE |
1312 TransliterationFlags::IGNORE_WIDTH;
1313 if (GetNegatedCheckBoxValue(*m_xIncludeDiacritics))
1314 nFlags |= TransliterationFlags::IGNORE_DIACRITICS_CTL;
1315 if (GetNegatedCheckBoxValue(*m_xIncludeKashida))
1316 nFlags |= TransliterationFlags::IGNORE_KASHIDA_CTL;
1317 pSearchItem->SetTransliterationFlags( nFlags );
1319 if ( !bWriter )
1321 if ( m_xCalcSearchInLB->get_active() != -1)
1322 pSearchItem->SetCellType( static_cast<SvxSearchCellType>(m_xCalcSearchInLB->get_active()) );
1324 pSearchItem->SetRowDirection( m_xRowsBtn->get_active() );
1325 pSearchItem->SetAllTables( m_xAllSheetsCB->get_active() );
1326 pSearchItem->SetSearchFormatted( m_xSearchFormattedCB->get_active() );
1329 if ((&rBtn == m_xSearchBtn.get()) || (&rBtn == m_xBackSearchBtn.get()))
1330 pSearchItem->SetCommand( SvxSearchCmd::FIND );
1331 else if ( &rBtn == m_xSearchAllBtn.get() )
1332 pSearchItem->SetCommand( SvxSearchCmd::FIND_ALL );
1333 else if ( &rBtn == m_xReplaceBtn.get() )
1334 pSearchItem->SetCommand( SvxSearchCmd::REPLACE );
1335 else if ( &rBtn == m_xReplaceAllBtn.get() )
1336 pSearchItem->SetCommand( SvxSearchCmd::REPLACE_ALL );
1338 // when looking for templates, delete format lists
1339 if ( !bFormat && pSearchItem->GetPattern() )
1341 if ( pSearchList )
1342 pSearchList->Clear();
1344 if ( pReplaceList )
1345 pReplaceList->Clear();
1347 nModifyFlag = ModifyFlags::NONE;
1348 const SfxPoolItem* ppArgs[] = { pSearchItem.get(), nullptr };
1349 rBindings.ExecuteSynchron( FID_SEARCH_NOW, ppArgs );
1351 else if ( &rBtn == m_xCloseBtn.get() )
1353 if ( !m_xLayoutBtn->get_active() || bInclusive )
1355 OUString aStr( m_xSearchLB->get_active_text() );
1357 if ( !aStr.isEmpty() )
1358 Remember_Impl( aStr, true );
1359 aStr = m_xReplaceLB->get_active_text();
1361 if ( !aStr.isEmpty() )
1362 Remember_Impl( aStr, false );
1364 SaveToModule_Impl();
1365 Close();
1367 else if (&rBtn == m_xSimilarityBtn.get())
1369 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1370 ScopedVclPtr<AbstractSvxSearchSimilarityDialog> pDlg(pFact->CreateSvxSearchSimilarityDialog(m_xDialog.get(),
1371 pSearchItem->IsLEVRelaxed(),
1372 pSearchItem->GetLEVOther(),
1373 pSearchItem->GetLEVShorter(),
1374 pSearchItem->GetLEVLonger() ));
1375 if ( executeSubDialog(pDlg.get()) == RET_OK )
1377 pSearchItem->SetLEVRelaxed( pDlg->IsRelaxed() );
1378 pSearchItem->SetLEVOther( pDlg->GetOther() );
1379 pSearchItem->SetLEVShorter( pDlg->GetShorter() );
1380 pSearchItem->SetLEVLonger( pDlg->GetLonger() );
1381 SaveToModule_Impl();
1384 else if (&rBtn == m_xJapOptionsBtn.get())
1386 SfxItemSet aSet( SfxGetpApp()->GetPool() );
1387 pSearchItem->SetTransliterationFlags( GetTransliterationFlags() );
1388 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1389 ScopedVclPtr<AbstractSvxJSearchOptionsDialog> aDlg(pFact->CreateSvxJSearchOptionsDialog(m_xDialog.get(), aSet,
1390 pSearchItem->GetTransliterationFlags() ));
1391 int nRet = executeSubDialog(aDlg.get());
1392 if (RET_OK == nRet) //! true only if FillItemSet of SvxJSearchOptionsPage returns true
1394 TransliterationFlags nFlags = aDlg->GetTransliterationFlags();
1395 pSearchItem->SetTransliterationFlags( nFlags );
1396 ApplyTransliterationFlags_Impl( nFlags );
1399 else if (&rBtn == m_xSearchComponent1PB.get() || &rBtn == m_xSearchComponent2PB.get())
1401 uno::Sequence < beans::PropertyValue > aArgs(2);
1402 beans::PropertyValue* pArgs = aArgs.getArray();
1403 pArgs[0].Name = "SearchString";
1404 pArgs[0].Value <<= m_xSearchLB->get_active_text();
1405 pArgs[1].Name = "ParentWindow";
1406 pArgs[1].Value <<= m_xDialog->GetXWindow();
1407 if (&rBtn == m_xSearchComponent1PB.get())
1409 if ( pImpl->xCommand1Dispatch.is() )
1410 pImpl->xCommand1Dispatch->dispatch(pImpl->aCommand1URL, aArgs);
1412 else
1414 if ( pImpl->xCommand2Dispatch.is() )
1415 pImpl->xCommand2Dispatch->dispatch(pImpl->aCommand2URL, aArgs);
1421 IMPL_LINK( SvxSearchDialog, ModifyHdl_Impl, weld::ComboBox&, rEd, void )
1423 if ( !bSet )
1424 SetModifyFlag_Impl( &rEd );
1425 else
1426 bSet = false;
1428 // Calc allows searching for empty cells.
1429 bool bAllowEmptySearch = (pSearchItem->GetAppFlag() == SvxSearchApp::CALC);
1431 if (&rEd == m_xSearchLB.get() || &rEd == m_xReplaceLB.get())
1433 sal_Int32 nSrchTxtLen = m_xSearchLB->get_active_text().getLength();
1434 sal_Int32 nReplTxtLen = 0;
1435 if (bAllowEmptySearch)
1436 nReplTxtLen = m_xReplaceLB->get_active_text().getLength();
1437 sal_Int32 nAttrTxtLen = m_xSearchAttrText->get_label().getLength();
1439 if (nSrchTxtLen || nReplTxtLen || nAttrTxtLen)
1441 EnableControl_Impl(*m_xSearchBtn);
1442 EnableControl_Impl(*m_xBackSearchBtn);
1443 EnableControl_Impl(*m_xReplaceBtn);
1444 if (!bWriter || !m_xNotesBtn->get_active())
1446 EnableControl_Impl(*m_xSearchAllBtn);
1447 EnableControl_Impl(*m_xReplaceAllBtn);
1450 else
1452 m_xComponentFrame->set_sensitive(false);
1453 m_xSearchBtn->set_sensitive(false);
1454 m_xBackSearchBtn->set_sensitive(false);
1455 m_xSearchAllBtn->set_sensitive(false);
1456 m_xReplaceBtn->set_sensitive(false);
1457 m_xReplaceAllBtn->set_sensitive(false);
1462 IMPL_LINK_NOARG(SvxSearchDialog, TemplateHdl_Impl, weld::Button&, void)
1464 if ( pImpl->bSaveToModule )
1465 SaveToModule_Impl();
1467 if ( bFormat )
1468 return;
1469 OUString sDesc;
1471 if ( m_xLayoutBtn->get_active() )
1473 if ( !pFamilyController )
1475 sal_uInt16 nId = 0;
1477 // Enable templates controller
1478 switch ( pSearchItem->GetFamily() )
1480 case SfxStyleFamily::Char:
1481 nId = SID_STYLE_FAMILY1; break;
1483 case SfxStyleFamily::Para:
1484 nId = SID_STYLE_FAMILY2; break;
1486 case SfxStyleFamily::Frame:
1487 nId = SID_STYLE_FAMILY3; break;
1489 case SfxStyleFamily::Page:
1490 nId = SID_STYLE_FAMILY4; break;
1492 case SfxStyleFamily::All:
1493 break;
1495 default:
1496 OSL_FAIL( "StyleSheetFamily was changed?" );
1499 rBindings.EnterRegistrations();
1500 pFamilyController.reset(
1501 new SvxSearchController( nId, rBindings, *this ) );
1502 rBindings.LeaveRegistrations();
1503 m_xSearchTmplLB->clear();
1504 m_xReplaceTmplLB->clear();
1506 m_xSearchTmplLB->show();
1507 m_xReplaceTmplLB->show();
1508 m_xSearchLB->hide();
1509 m_xReplaceLB->hide();
1511 m_xSearchAttrText->set_label( sDesc );
1512 m_xReplaceAttrText->set_label( sDesc );
1514 if(!sDesc.isEmpty())
1516 if (!m_xReplaceAttrText->get_visible() || !m_xReplaceAttrText->get_visible())
1518 m_xSearchAttrText->show();
1519 m_xReplaceAttrText->show();
1520 m_xDialog->resize_to_request();
1524 m_xFormatBtn->set_sensitive(false);
1525 m_xNoFormatBtn->set_sensitive(false);
1526 m_xAttributeBtn->set_sensitive(false);
1527 m_xSimilarityBox->set_sensitive(false);
1528 m_xSimilarityBtn->set_sensitive(false);
1530 else
1532 // Disable templates controller
1533 rBindings.EnterRegistrations();
1534 pFamilyController.reset();
1535 rBindings.LeaveRegistrations();
1537 m_xSearchLB->show();
1538 m_xReplaceLB->show();
1539 m_xSearchTmplLB->hide();
1540 m_xReplaceTmplLB->hide();
1542 m_xSearchAttrText->set_label( BuildAttrText_Impl( sDesc, true ) );
1543 m_xReplaceAttrText->set_label( BuildAttrText_Impl( sDesc, false ) );
1545 if(!sDesc.isEmpty())
1547 if (!m_xReplaceAttrText->get_visible() || !m_xReplaceAttrText->get_visible())
1549 m_xSearchAttrText->show();
1550 m_xReplaceAttrText->show();
1551 m_xDialog->resize_to_request();
1555 EnableControl_Impl(*m_xFormatBtn);
1556 EnableControl_Impl(*m_xAttributeBtn);
1557 EnableControl_Impl(*m_xSimilarityBox);
1559 FocusHdl_Impl( bSearch ? *m_xSearchLB : *m_xReplaceLB );
1561 bSet = true;
1562 pImpl->bSaveToModule = false;
1563 FlagHdl_Impl(*m_xLayoutBtn);
1564 pImpl->bSaveToModule = true;
1567 void SvxSearchDialog::Remember_Impl( const OUString &rStr, bool _bSearch )
1569 if ( rStr.isEmpty() )
1570 return;
1572 std::vector<OUString>* pArr = _bSearch ? &aSearchStrings : &aReplaceStrings;
1573 weld::ComboBox* pListBox = _bSearch ? m_xSearchLB.get() : m_xReplaceLB.get();
1575 // ignore identical strings
1576 if (std::find(pArr->begin(), pArr->end(), rStr) != pArr->end())
1577 return;
1579 pArr->insert(pArr->begin(), rStr);
1580 pListBox->insert_text(0, rStr);
1582 // delete oldest entry at maximum occupancy (ListBox and Array)
1583 size_t nArrSize = pArr->size();
1584 if (nArrSize > nRememberSize)
1586 pListBox->remove(nArrSize - 1);
1587 pArr->erase(pArr->begin() + nArrSize - 1);
1591 void SvxSearchDialog::TemplatesChanged_Impl( SfxStyleSheetBasePool& rPool )
1593 OUString aOldSrch( m_xSearchTmplLB->get_active_text() );
1594 OUString aOldRepl( m_xReplaceTmplLB->get_active_text() );
1595 m_xSearchTmplLB->clear();
1596 m_xReplaceTmplLB->clear();
1597 rPool.SetSearchMask( pSearchItem->GetFamily() );
1598 m_xSearchTmplLB->freeze();
1599 m_xReplaceTmplLB->freeze();
1600 SfxStyleSheetBase* pBase = rPool.First();
1602 while ( pBase )
1604 if ( pBase->IsUsed() )
1605 m_xSearchTmplLB->append_text( pBase->GetName() );
1606 m_xReplaceTmplLB->append_text( pBase->GetName() );
1607 pBase = rPool.Next();
1609 m_xSearchTmplLB->thaw();
1610 m_xReplaceTmplLB->thaw();
1611 m_xSearchTmplLB->set_active(0);
1613 if ( !aOldSrch.isEmpty() )
1614 m_xSearchTmplLB->set_active_text( aOldSrch );
1615 m_xReplaceTmplLB->set_active(0);
1617 if ( !aOldRepl.isEmpty() )
1618 m_xReplaceTmplLB->set_active_text( aOldRepl );
1620 if ( m_xSearchTmplLB->get_count() )
1622 EnableControl_Impl(*m_xSearchBtn);
1623 EnableControl_Impl(*m_xBackSearchBtn);
1624 EnableControl_Impl(*m_xSearchAllBtn);
1625 EnableControl_Impl(*m_xReplaceBtn);
1626 EnableControl_Impl(*m_xReplaceAllBtn);
1631 void SvxSearchDialog::EnableControls_Impl( const SearchOptionFlags nFlags )
1633 if ( nFlags == nOptions )
1634 return;
1635 else
1636 nOptions = nFlags;
1638 bool bNoSearch = true;
1640 bool bEnableSearch = bool( SearchOptionFlags::SEARCH & nOptions );
1641 m_xSearchBtn->set_sensitive(bEnableSearch);
1642 m_xBackSearchBtn->set_sensitive(bEnableSearch);
1644 if( bEnableSearch )
1645 bNoSearch = false;
1648 if ( SearchOptionFlags::SEARCHALL & nOptions )
1650 m_xSearchAllBtn->set_sensitive(true);
1651 bNoSearch = false;
1653 else
1654 m_xSearchAllBtn->set_sensitive(false);
1655 if ( SearchOptionFlags::REPLACE & nOptions )
1657 m_xReplaceBtn->set_sensitive(true);
1658 m_xReplaceFrame->set_sensitive(true);
1659 m_xReplaceLB->set_sensitive(true);
1660 m_xReplaceTmplLB->set_sensitive(true);
1661 bNoSearch = false;
1663 else
1665 m_xReplaceBtn->set_sensitive(false);
1666 m_xReplaceFrame->set_sensitive(false);
1667 m_xReplaceLB->set_sensitive(false);
1668 m_xReplaceTmplLB->set_sensitive(false);
1670 if ( SearchOptionFlags::REPLACE_ALL & nOptions )
1672 m_xReplaceAllBtn->set_sensitive(true);
1673 bNoSearch = false;
1675 else
1676 m_xReplaceAllBtn->set_sensitive(false);
1677 m_xComponentFrame->set_sensitive(!bNoSearch);
1678 m_xSearchBtn->set_sensitive( !bNoSearch );
1679 m_xBackSearchBtn->set_sensitive( !bNoSearch );
1680 m_xSearchFrame->set_sensitive( !bNoSearch );
1681 m_xSearchLB->set_sensitive( !bNoSearch );
1682 m_xNotesBtn->set_sensitive(true);
1684 if ( SearchOptionFlags::WHOLE_WORDS & nOptions )
1685 m_xWordBtn->set_sensitive(true);
1686 else
1687 m_xWordBtn->set_sensitive(false);
1688 if ( SearchOptionFlags::BACKWARDS & nOptions )
1690 m_xBackSearchBtn->set_sensitive(true);
1691 m_xReplaceBackwardsCB->set_sensitive(true);
1693 else
1695 m_xBackSearchBtn->set_sensitive(false);
1696 m_xReplaceBackwardsCB->set_sensitive(false);
1698 if ( SearchOptionFlags::REG_EXP & nOptions )
1699 m_xRegExpBtn->set_sensitive(true);
1700 else
1701 m_xRegExpBtn->set_sensitive(false);
1702 if ( SearchOptionFlags::WILDCARD & nOptions )
1703 m_xWildcardBtn->set_sensitive(true);
1704 else
1705 m_xWildcardBtn->set_sensitive(false);
1706 if ( SearchOptionFlags::EXACT & nOptions )
1707 m_xMatchCaseCB->set_sensitive(true);
1708 else
1709 m_xMatchCaseCB->set_sensitive(false);
1710 if ( SearchOptionFlags::SELECTION & nOptions )
1711 m_xSelectionBtn->set_sensitive(true);
1712 else
1713 m_xSelectionBtn->set_sensitive(false);
1714 if ( SearchOptionFlags::FAMILIES & nOptions )
1715 m_xLayoutBtn->set_sensitive(true);
1716 else
1717 m_xLayoutBtn->set_sensitive(false);
1718 if ( SearchOptionFlags::FORMAT & nOptions )
1720 m_xAttributeBtn->set_sensitive(true);
1721 m_xFormatBtn->set_sensitive(true);
1722 m_xNoFormatBtn->set_sensitive(true);
1724 else
1726 m_xAttributeBtn->set_sensitive(false);
1727 m_xFormatBtn->set_sensitive(false);
1728 m_xNoFormatBtn->set_sensitive(false);
1731 if ( SearchOptionFlags::SIMILARITY & nOptions )
1733 m_xSimilarityBox->set_sensitive(true);
1734 m_xSimilarityBtn->set_sensitive(true);
1736 else
1738 m_xSimilarityBox->set_sensitive(false);
1739 m_xSimilarityBtn->set_sensitive(false);
1742 if ( pSearchItem )
1743 Init_Impl( pSearchItem->GetPattern() &&
1744 ( !pSearchList || !pSearchList->Count() ) );
1747 void SvxSearchDialog::EnableControl_Impl(const weld::Widget& rCtrl)
1749 if (m_xSearchBtn.get() == &rCtrl && ( SearchOptionFlags::SEARCH & nOptions ) )
1751 m_xComponentFrame->set_sensitive(true);
1752 m_xSearchBtn->set_sensitive(true);
1753 return;
1755 if ( m_xSearchAllBtn.get() == &rCtrl &&
1756 ( SearchOptionFlags::SEARCHALL & nOptions ) )
1758 m_xSearchAllBtn->set_sensitive(true);
1759 return;
1761 if ( m_xReplaceBtn.get() == &rCtrl && ( SearchOptionFlags::REPLACE & nOptions ) )
1763 m_xReplaceBtn->set_sensitive(true);
1764 return;
1766 if ( m_xReplaceAllBtn.get() == &rCtrl &&
1767 ( SearchOptionFlags::REPLACE_ALL & nOptions ) )
1769 m_xReplaceAllBtn->set_sensitive(true);
1770 return;
1772 if ( m_xWordBtn.get() == &rCtrl && ( SearchOptionFlags::WHOLE_WORDS & nOptions ) )
1774 m_xWordBtn->set_sensitive(true);
1775 return;
1777 if ( SearchOptionFlags::BACKWARDS & nOptions )
1779 if( m_xBackSearchBtn.get() == &rCtrl )
1781 m_xBackSearchBtn->set_sensitive(true);
1782 return;
1784 else if ( m_xReplaceBackwardsCB.get() == &rCtrl )
1786 m_xReplaceBackwardsCB->set_sensitive(true);
1787 return;
1790 if (m_xNotesBtn.get() == &rCtrl)
1792 m_xNotesBtn->set_sensitive(true);
1793 return;
1795 if ( m_xRegExpBtn.get() == &rCtrl && ( SearchOptionFlags::REG_EXP & nOptions )
1796 && !m_xSimilarityBox->get_active() && !m_xWildcardBtn->get_active())
1798 m_xRegExpBtn->set_sensitive(true);
1799 return;
1801 if ( m_xWildcardBtn.get() == &rCtrl && ( SearchOptionFlags::WILDCARD & nOptions )
1802 && !m_xSimilarityBox->get_active() && !m_xRegExpBtn->get_active())
1804 m_xWildcardBtn->set_sensitive(true);
1805 return;
1807 if ( m_xMatchCaseCB.get() == &rCtrl && ( SearchOptionFlags::EXACT & nOptions ) )
1809 if (!m_xJapOptionsCB->get_active())
1810 m_xMatchCaseCB->set_sensitive(true);
1811 return;
1813 if ( m_xSelectionBtn.get() == &rCtrl && ( SearchOptionFlags::SELECTION & nOptions ) )
1815 m_xSelectionBtn->set_sensitive(true);
1816 return;
1818 if ( m_xLayoutBtn.get() == &rCtrl && ( SearchOptionFlags::FAMILIES & nOptions ) )
1820 m_xLayoutBtn->set_sensitive(true);
1821 return;
1823 if ( m_xAttributeBtn.get() == &rCtrl
1824 && ( SearchOptionFlags::FORMAT & nOptions )
1825 && pSearchList )
1827 m_xAttributeBtn->set_sensitive( pImpl->bFocusOnSearch );
1829 if ( m_xFormatBtn.get() == &rCtrl && ( SearchOptionFlags::FORMAT & nOptions ) )
1831 m_xFormatBtn->set_sensitive(true);
1832 return;
1834 if ( m_xNoFormatBtn.get() == &rCtrl && ( SearchOptionFlags::FORMAT & nOptions ) )
1836 m_xNoFormatBtn->set_sensitive(true);
1837 return;
1839 if ( m_xSimilarityBox.get() == &rCtrl && ( SearchOptionFlags::SIMILARITY & nOptions )
1840 && !m_xRegExpBtn->get_active() && !m_xWildcardBtn->get_active())
1842 m_xSimilarityBox->set_sensitive(true);
1844 if ( m_xSimilarityBox->get_active() )
1845 m_xSimilarityBtn->set_sensitive(true);
1849 void SvxSearchDialog::SetItem_Impl( const SvxSearchItem* pItem )
1851 //TODO: save pItem and process later if m_executingSubDialog?
1852 if ( pItem && !m_executingSubDialog )
1854 pSearchItem.reset(static_cast<SvxSearchItem*>(pItem->Clone()));
1855 Init_Impl( pSearchItem->GetPattern() &&
1856 ( !pSearchList || !pSearchList->Count() ) );
1860 IMPL_LINK(SvxSearchDialog, FocusHdl_Impl, weld::Widget&, rControl, void)
1862 sal_Int32 nTxtLen = m_xSearchAttrText->get_label().getLength();
1863 weld::Widget* pCtrl = &rControl;
1864 if (pCtrl == m_xSearchLB.get())
1866 if (pCtrl->has_focus())
1867 pImpl->bFocusOnSearch = true;
1868 pCtrl = m_xSearchLB.get();
1869 bSearch = true;
1871 if( nTxtLen )
1872 EnableControl_Impl(*m_xNoFormatBtn);
1873 else
1874 m_xNoFormatBtn->set_sensitive(false);
1875 EnableControl_Impl(*m_xAttributeBtn);
1877 else
1879 pImpl->bFocusOnSearch = false;
1880 pCtrl = m_xReplaceLB.get();
1881 bSearch = false;
1883 if (!m_xReplaceAttrText->get_label().isEmpty())
1884 EnableControl_Impl(*m_xNoFormatBtn);
1885 else
1886 m_xNoFormatBtn->set_sensitive(false);
1887 m_xAttributeBtn->set_sensitive(false);
1889 bSet = true;
1891 weld::ComboBox &rComboBox = dynamic_cast<weld::ComboBox&>(*pCtrl);
1892 rComboBox.select_entry_region(0, -1);
1893 ModifyHdl_Impl(rComboBox);
1895 if (bFormat && nTxtLen)
1896 m_xLayoutBtn->set_label(aLayoutStr);
1897 else
1899 SvtModuleOptions::EFactory eFactory = getModule(rBindings);
1900 bool bWriterApp =
1901 eFactory == SvtModuleOptions::EFactory::WRITER ||
1902 eFactory == SvtModuleOptions::EFactory::WRITERWEB ||
1903 eFactory == SvtModuleOptions::EFactory::WRITERGLOBAL;
1904 bool bCalcApp = eFactory == SvtModuleOptions::EFactory::CALC;
1906 if (bWriterApp)
1907 m_xLayoutBtn->set_label(aLayoutWriterStr);
1908 else
1910 if (bCalcApp)
1911 m_xLayoutBtn->set_label(aLayoutCalcStr);
1912 else
1913 m_xLayoutBtn->set_label(aStylesStr);
1918 IMPL_LINK_NOARG(SvxSearchDialog, LoseFocusHdl_Impl, weld::Widget&, void)
1920 SaveToModule_Impl();
1923 IMPL_LINK_NOARG(SvxSearchDialog, FormatHdl_Impl, weld::Button&, void)
1925 SfxObjectShell* pSh = SfxObjectShell::Current();
1927 DBG_ASSERT( pSh, "no DocShell" );
1929 if ( !pSh || !pImpl->pRanges )
1930 return;
1932 SfxItemPool& rPool = pSh->GetPool();
1933 SfxItemSet aSet(rPool, pImpl->pRanges.get());
1935 aSet.MergeRange(SID_ATTR_PARA_MODEL, SID_ATTR_PARA_MODEL);
1937 sal_uInt16 nBrushWhich = pSh->GetPool().GetWhich(SID_ATTR_BRUSH);
1938 aSet.MergeRange(nBrushWhich, nBrushWhich);
1940 aSet.MergeRange(XATTR_FILL_FIRST, XATTR_FILL_LAST);
1942 OUString aTxt;
1944 aSet.InvalidateAllItems();
1945 aSet.Put(SvxBrushItem(nBrushWhich));
1947 if ( bSearch )
1949 aTxt = SvxResId( RID_SVXSTR_SEARCH );
1950 pSearchList->Get( aSet );
1952 else
1954 aTxt = SvxResId( RID_SVXSTR_REPLACE );
1955 pReplaceList->Get( aSet );
1957 aSet.DisableItem(SID_ATTR_PARA_MODEL);
1958 aSet.DisableItem(rPool.GetWhich(SID_ATTR_PARA_PAGEBREAK));
1959 aSet.DisableItem(rPool.GetWhich(SID_ATTR_PARA_KEEP));
1962 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1963 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTabItemDialog(m_xDialog.get(), aSet));
1964 pDlg->SetText( aTxt );
1966 if ( executeSubDialog(pDlg.get()) == RET_OK )
1968 DBG_ASSERT( pDlg->GetOutputItemSet(), "invalid Output-Set" );
1969 SfxItemSet aOutSet( *pDlg->GetOutputItemSet() );
1971 SearchAttrItemList* pList = bSearch ? pSearchList.get() : pReplaceList.get();
1973 const SfxPoolItem* pItem;
1974 for( sal_uInt16 n = 0; n < pList->Count(); ++n )
1976 SearchAttrItem* pAItem;
1977 if( !IsInvalidItem( (pAItem = &pList->GetObject(n))->pItem ) &&
1978 SfxItemState::SET == aOutSet.GetItemState(
1979 pAItem->pItem->Which(), false, &pItem ) )
1981 delete pAItem->pItem;
1982 pAItem->pItem = pItem->Clone();
1983 aOutSet.ClearItem( pAItem->pItem->Which() );
1987 if( aOutSet.Count() )
1988 pList->Put( aOutSet );
1990 PaintAttrText_Impl(); // Set AttributText in GroupBox
1994 IMPL_LINK_NOARG(SvxSearchDialog, NoFormatHdl_Impl, weld::Button&, void)
1996 SvtModuleOptions::EFactory eFactory = getModule(rBindings);
1997 bool bWriterApp =
1998 eFactory == SvtModuleOptions::EFactory::WRITER ||
1999 eFactory == SvtModuleOptions::EFactory::WRITERWEB ||
2000 eFactory == SvtModuleOptions::EFactory::WRITERGLOBAL;
2001 bool bCalcApp = eFactory == SvtModuleOptions::EFactory::CALC;
2003 if (bCalcApp)
2004 m_xLayoutBtn->set_label( aLayoutCalcStr );
2005 else
2007 if (bWriterApp)
2008 m_xLayoutBtn->set_label( aLayoutWriterStr);
2009 else
2010 m_xLayoutBtn->set_label( aStylesStr );
2013 bFormat = false;
2014 m_xLayoutBtn->set_active( false );
2016 bool bSetOptimalLayoutSize = false;
2018 if ( bSearch )
2020 pSearchList->Clear();
2021 m_xSearchAttrText->set_label( "" );
2022 if (m_xSearchAttrText->get_visible())
2024 m_xSearchAttrText->hide();
2025 bSetOptimalLayoutSize = true;
2028 else
2030 pReplaceList->Clear();
2031 m_xReplaceAttrText->set_label( "" );
2032 if (m_xReplaceAttrText->get_visible())
2034 m_xReplaceAttrText->hide();
2035 bSetOptimalLayoutSize = true;
2039 if (bSetOptimalLayoutSize)
2040 m_xDialog->resize_to_request();
2042 pImpl->bSaveToModule = false;
2043 TemplateHdl_Impl(*m_xLayoutBtn);
2044 pImpl->bSaveToModule = true;
2045 m_xNoFormatBtn->set_sensitive(false);
2048 IMPL_LINK_NOARG(SvxSearchDialog, AttributeHdl_Impl, weld::Button&, void)
2050 if ( !pSearchList || !pImpl->pRanges )
2051 return;
2053 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2054 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateSvxSearchAttributeDialog(m_xDialog.get(), *pSearchList, pImpl->pRanges.get()));
2055 executeSubDialog(pDlg.get());
2056 PaintAttrText_Impl();
2059 IMPL_LINK( SvxSearchDialog, TimeoutHdl_Impl, Timer *, pTimer, void )
2061 SfxViewShell* pViewShell = SfxViewShell::Current();
2063 if ( pViewShell )
2065 if ( pViewShell->HasSelection( m_xSearchLB->get_visible() ) )
2066 EnableControl_Impl(*m_xSelectionBtn);
2067 else
2069 m_xSelectionBtn->set_active( false );
2070 m_xSelectionBtn->set_sensitive(false);
2074 pTimer->Start();
2077 OUString& SvxSearchDialog::BuildAttrText_Impl( OUString& rStr,
2078 bool bSrchFlag ) const
2080 rStr.clear();
2082 SfxObjectShell* pSh = SfxObjectShell::Current();
2083 DBG_ASSERT( pSh, "no DocShell" );
2085 if ( !pSh )
2086 return rStr;
2088 SfxItemPool& rPool = pSh->GetPool();
2089 SearchAttrItemList* pList = bSrchFlag ? pSearchList.get() : pReplaceList.get();
2091 if ( !pList )
2092 return rStr;
2094 // Metric query
2095 MapUnit eMapUnit = MapUnit::MapCM;
2096 FieldUnit eFieldUnit = pSh->GetModule()->GetFieldUnit();
2097 switch ( eFieldUnit )
2099 case FieldUnit::MM: eMapUnit = MapUnit::MapMM; break;
2100 case FieldUnit::CM:
2101 case FieldUnit::M:
2102 case FieldUnit::KM: eMapUnit = MapUnit::MapCM; break;
2103 case FieldUnit::TWIP: eMapUnit = MapUnit::MapTwip; break;
2104 case FieldUnit::POINT:
2105 case FieldUnit::PICA: eMapUnit = MapUnit::MapPoint; break;
2106 case FieldUnit::INCH:
2107 case FieldUnit::FOOT:
2108 case FieldUnit::MILE: eMapUnit = MapUnit::MapInch; break;
2109 case FieldUnit::MM_100TH: eMapUnit = MapUnit::Map100thMM; break;
2110 default: ;//prevent warning
2113 IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag());
2114 for ( sal_uInt16 i = 0; i < pList->Count(); ++i )
2116 const SearchAttrItem& rItem = pList->GetObject(i);
2118 if ( !rStr.isEmpty() )
2119 rStr += ", ";
2121 if ( !IsInvalidItem( rItem.pItem ) )
2123 OUString aStr;
2124 rPool.GetPresentation(*rItem.pItem, eMapUnit, aStr, aIntlWrapper);
2125 rStr += aStr;
2127 else if ( rItem.nSlot == SID_ATTR_BRUSH_CHAR )
2129 // Special treatment for text background
2130 rStr += SvxResId( RID_SVXITEMS_BRUSH_CHAR );
2132 else
2134 sal_uInt32 nId = SvxAttrNameTable::FindIndex(rItem.nSlot);
2135 if ( RESARRAY_INDEX_NOTFOUND != nId )
2136 rStr += SvxAttrNameTable::GetString(nId);
2139 return rStr;
2143 void SvxSearchDialog::PaintAttrText_Impl()
2145 OUString aDesc;
2146 BuildAttrText_Impl( aDesc, bSearch );
2148 if ( !bFormat && !aDesc.isEmpty() )
2149 bFormat = true;
2151 bool bSetOptimalLayoutSize = false;
2153 if ( bSearch )
2155 m_xSearchAttrText->set_label( aDesc );
2156 if (!aDesc.isEmpty() && !m_xSearchAttrText->get_visible())
2158 m_xSearchAttrText->show();
2159 bSetOptimalLayoutSize = true;
2162 FocusHdl_Impl(*m_xSearchLB);
2164 else
2166 m_xReplaceAttrText->set_label( aDesc );
2167 if (!aDesc.isEmpty() && !m_xReplaceAttrText->get_visible())
2169 m_xReplaceAttrText->show();
2170 bSetOptimalLayoutSize = true;
2173 FocusHdl_Impl(*m_xReplaceLB);
2176 if (bSetOptimalLayoutSize)
2177 m_xDialog->resize_to_request();
2180 void SvxSearchDialog::SetModifyFlag_Impl( const weld::Widget* pCtrl )
2182 if (m_xSearchLB.get() == pCtrl)
2184 nModifyFlag |= ModifyFlags::Search;
2185 m_xSearchLB->set_entry_message_type(weld::EntryMessageType::Normal);
2186 SvxSearchDialogWrapper::SetSearchLabel("");
2188 else if ( m_xReplaceLB.get() == pCtrl )
2189 nModifyFlag |= ModifyFlags::Replace;
2190 else if ( m_xWordBtn.get() == pCtrl )
2191 nModifyFlag |= ModifyFlags::Word;
2192 else if ( m_xMatchCaseCB.get() == pCtrl )
2193 nModifyFlag |= ModifyFlags::Exact;
2194 else if ( m_xReplaceBackwardsCB.get() == pCtrl )
2195 nModifyFlag |= ModifyFlags::Backwards;
2196 else if ( m_xNotesBtn.get() == pCtrl )
2197 nModifyFlag |= ModifyFlags::Notes;
2198 else if ( m_xSelectionBtn.get() == pCtrl )
2199 nModifyFlag |= ModifyFlags::Selection;
2200 else if ( m_xRegExpBtn.get() == pCtrl )
2201 nModifyFlag |= ModifyFlags::Regexp;
2202 else if ( m_xWildcardBtn.get() == pCtrl )
2203 nModifyFlag |= ModifyFlags::Wildcard;
2204 else if ( m_xLayoutBtn.get() == pCtrl )
2205 nModifyFlag |= ModifyFlags::Layout;
2206 else if ( m_xSimilarityBox.get() == pCtrl )
2207 nModifyFlag |= ModifyFlags::Similarity;
2208 else if ( m_xCalcSearchInLB.get() == pCtrl )
2210 nModifyFlag |= ModifyFlags::Formulas;
2211 nModifyFlag |= ModifyFlags::Values;
2212 nModifyFlag |= ModifyFlags::CalcNotes;
2214 else if ( m_xRowsBtn.get() == pCtrl )
2215 nModifyFlag |= ModifyFlags::Rows;
2216 else if ( m_xColumnsBtn.get() == pCtrl )
2217 nModifyFlag |= ModifyFlags::Columns;
2218 else if ( m_xAllSheetsCB.get() == pCtrl )
2219 nModifyFlag |= ModifyFlags::AllTables;
2222 void SvxSearchDialog::SaveToModule_Impl()
2224 if ( !pSearchItem )
2225 return;
2227 if ( m_xLayoutBtn->get_active() )
2229 pSearchItem->SetSearchString ( m_xSearchTmplLB->get_active_text() );
2230 pSearchItem->SetReplaceString( m_xReplaceTmplLB->get_active_text() );
2232 else
2234 pSearchItem->SetSearchString ( m_xSearchLB->get_active_text() );
2235 pSearchItem->SetReplaceString( m_xReplaceLB->get_active_text() );
2236 Remember_Impl( m_xSearchLB->get_active_text(), true );
2239 pSearchItem->SetRegExp( false );
2240 pSearchItem->SetWildcard( false );
2241 pSearchItem->SetLevenshtein( false );
2242 if (GetCheckBoxValue(*m_xRegExpBtn))
2243 pSearchItem->SetRegExp( true );
2244 else if (GetCheckBoxValue(*m_xWildcardBtn))
2245 pSearchItem->SetWildcard( true );
2246 else if (GetCheckBoxValue(*m_xSimilarityBox))
2247 pSearchItem->SetLevenshtein( true );
2249 pSearchItem->SetWordOnly(GetCheckBoxValue(*m_xWordBtn));
2250 pSearchItem->SetBackward(GetCheckBoxValue(*m_xReplaceBackwardsCB));
2251 pSearchItem->SetNotes(GetCheckBoxValue(*m_xNotesBtn));
2252 pSearchItem->SetPattern(GetCheckBoxValue(*m_xLayoutBtn));
2253 pSearchItem->SetSelection(GetCheckBoxValue(*m_xSelectionBtn));
2254 pSearchItem->SetUseAsianOptions(GetCheckBoxValue(*m_xJapOptionsCB));
2256 SvtSearchOptions aOpt;
2257 aOpt.SetIgnoreDiacritics_CTL(GetNegatedCheckBoxValue(*m_xIncludeDiacritics));
2258 aOpt.SetIgnoreKashida_CTL(GetNegatedCheckBoxValue(*m_xIncludeKashida));
2259 aOpt.Commit();
2261 TransliterationFlags nFlags = GetTransliterationFlags();
2262 if( !pSearchItem->IsUseAsianOptions())
2263 nFlags &= TransliterationFlags::IGNORE_CASE |
2264 TransliterationFlags::IGNORE_WIDTH;
2265 if (GetNegatedCheckBoxValue(*m_xIncludeDiacritics))
2266 nFlags |= TransliterationFlags::IGNORE_DIACRITICS_CTL;
2267 if (GetNegatedCheckBoxValue(*m_xIncludeKashida))
2268 nFlags |= TransliterationFlags::IGNORE_KASHIDA_CTL;
2269 pSearchItem->SetTransliterationFlags( nFlags );
2271 if ( !bWriter )
2273 if (m_xCalcSearchInLB->get_active() != -1)
2274 pSearchItem->SetCellType( static_cast<SvxSearchCellType>(m_xCalcSearchInLB->get_active()) );
2276 pSearchItem->SetRowDirection( m_xRowsBtn->get_active() );
2277 pSearchItem->SetAllTables( m_xAllSheetsCB->get_active() );
2278 pSearchItem->SetSearchFormatted( m_xSearchFormattedCB->get_active() );
2281 pSearchItem->SetCommand( SvxSearchCmd::FIND );
2282 nModifyFlag = ModifyFlags::NONE;
2283 const SfxPoolItem* ppArgs[] = { pSearchItem.get(), nullptr };
2284 rBindings.GetDispatcher()->Execute( SID_SEARCH_ITEM, SfxCallMode::SLOT, ppArgs );
2287 short SvxSearchDialog::executeSubDialog(VclAbstractDialog * dialog) {
2288 assert(!m_executingSubDialog);
2289 comphelper::ScopeGuard g([this] { m_executingSubDialog = false; });
2290 m_executingSubDialog = true;
2291 return dialog->Execute();
2294 SFX_IMPL_CHILDWINDOW_WITHID(SvxSearchDialogWrapper, SID_SEARCH_DLG);
2297 SvxSearchDialogWrapper::SvxSearchDialogWrapper( vcl::Window* _pParent, sal_uInt16 nId,
2298 SfxBindings* pBindings,
2299 SfxChildWinInfo const * pInfo )
2300 : SfxChildWindow( _pParent, nId )
2301 , dialog(new SvxSearchDialog(_pParent->GetFrameWeld(), this, *pBindings))
2303 SetController(dialog);
2304 dialog->Initialize( pInfo );
2306 pBindings->Update( SID_SEARCH_ITEM );
2307 pBindings->Update( SID_SEARCH_OPTIONS );
2308 pBindings->Update( SID_SEARCH_SEARCHSET );
2309 pBindings->Update( SID_SEARCH_REPLACESET );
2310 dialog->bConstruct = false;
2313 SvxSearchDialogWrapper::~SvxSearchDialogWrapper ()
2318 SfxChildWinInfo SvxSearchDialogWrapper::GetInfo() const
2320 SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
2321 aInfo.bVisible = false;
2322 return aInfo;
2325 static void lcl_SetSearchLabelWindow(const OUString& rStr)
2327 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
2328 if (!pViewFrame)
2329 return;
2331 bool bNotFound = rStr == SvxResId(RID_SVXSTR_SEARCH_NOT_FOUND);
2333 css::uno::Reference< css::beans::XPropertySet > xPropSet(
2334 pViewFrame->GetFrame().GetFrameInterface(), css::uno::UNO_QUERY_THROW);
2335 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
2336 xPropSet->getPropertyValue("LayoutManager") >>= xLayoutManager;
2337 css::uno::Reference< css::ui::XUIElement > xUIElement =
2338 xLayoutManager->getElement("private:resource/toolbar/findbar");
2339 if (!xUIElement.is())
2340 return;
2341 css::uno::Reference< css::awt::XWindow > xWindow(
2342 xUIElement->getRealInterface(), css::uno::UNO_QUERY_THROW);
2343 VclPtr< ToolBox > pToolBox = static_cast<ToolBox*>( VCLUnoHelper::GetWindow(xWindow).get() );
2344 for (ToolBox::ImplToolItems::size_type i = 0; pToolBox && i < pToolBox->GetItemCount(); ++i)
2346 sal_uInt16 id = pToolBox->GetItemId(i);
2347 if (pToolBox->GetItemCommand(id) == ".uno:SearchLabel")
2349 vcl::Window* pSearchLabel = pToolBox->GetItemWindow(id);
2350 assert(pSearchLabel);
2351 pSearchLabel->SetText(rStr);
2352 if (rStr.isEmpty())
2353 pSearchLabel->SetSizePixel(Size(16, pSearchLabel->get_preferred_size().Height()));
2354 else
2355 pSearchLabel->SetSizePixel(pSearchLabel->get_preferred_size());
2358 if (pToolBox->GetItemCommand(id) == ".uno:FindText")
2360 ComboBox* pFindText = dynamic_cast<ComboBox*>(pToolBox->GetItemWindow(id));
2361 assert(pFindText);
2362 Edit* pEdit = pFindText->GetSubEdit();
2363 if (bNotFound)
2364 pEdit->SetControlForeground(COL_LIGHTRED);
2365 else
2366 pEdit->SetControlForeground();
2369 xLayoutManager->doLayout();
2370 pToolBox->Resize();
2373 OUString SvxSearchDialogWrapper::GetSearchLabel()
2375 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
2376 if (!pViewFrame)
2377 return OUString();
2379 css::uno::Reference< css::beans::XPropertySet > xPropSet(
2380 pViewFrame->GetFrame().GetFrameInterface(), css::uno::UNO_QUERY_THROW);
2381 css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
2382 xPropSet->getPropertyValue("LayoutManager") >>= xLayoutManager;
2383 if (!xLayoutManager.is())
2384 return OUString();
2385 css::uno::Reference< css::ui::XUIElement > xUIElement =
2386 xLayoutManager->getElement("private:resource/toolbar/findbar");
2387 if (!xUIElement.is())
2388 return OUString();
2389 css::uno::Reference< css::awt::XWindow > xWindow(
2390 xUIElement->getRealInterface(), css::uno::UNO_QUERY_THROW);
2391 VclPtr< ToolBox > pToolBox = static_cast<ToolBox*>( VCLUnoHelper::GetWindow(xWindow).get() );
2392 for (ToolBox::ImplToolItems::size_type i = 0; pToolBox && i < pToolBox->GetItemCount(); ++i)
2394 sal_uInt16 id = pToolBox->GetItemId(i);
2395 if (pToolBox->GetItemCommand(id) == ".uno:SearchLabel")
2397 vcl::Window* pSearchLabel = pToolBox->GetItemWindow(id);
2398 return pSearchLabel ? pSearchLabel->GetText() : OUString();
2401 return OUString();
2404 void SvxSearchDialogWrapper::SetSearchLabel(const SearchLabel& rSL)
2406 OUString sStr;
2407 if (rSL == SearchLabel::End)
2408 sStr = SvxResId(RID_SVXSTR_SEARCH_END);
2409 else if (rSL == SearchLabel::Start)
2410 sStr = SvxResId(RID_SVXSTR_SEARCH_START);
2411 else if (rSL == SearchLabel::EndWrapped)
2412 sStr = SvxResId(RID_SVXSTR_SEARCH_END_WRAPPED);
2413 else if (rSL == SearchLabel::StartWrapped)
2414 sStr = SvxResId(RID_SVXSTR_SEARCH_START_WRAPPED);
2415 else if (rSL == SearchLabel::EndSheet)
2416 sStr = SvxResId(RID_SVXSTR_SEARCH_END_SHEET);
2417 else if (rSL == SearchLabel::NotFound)
2418 sStr = SvxResId(RID_SVXSTR_SEARCH_NOT_FOUND);
2419 else if (rSL == SearchLabel::NavElementNotFound)
2420 sStr = SvxResId(RID_SVXSTR_SEARCH_NAV_ELEMENT_NOT_FOUND);
2422 lcl_SetSearchLabelWindow(sStr);
2423 if (SvxSearchDialogWrapper *pWrp = static_cast<SvxSearchDialogWrapper*>( SfxViewFrame::Current()->
2424 GetChildWindow( SvxSearchDialogWrapper::GetChildWindowId() )))
2425 pWrp->getDialog()->SetSearchLabel(sStr);
2428 void SvxSearchDialogWrapper::SetSearchLabel(const OUString& sStr)
2431 lcl_SetSearchLabelWindow(sStr);
2432 if (SvxSearchDialogWrapper *pWrp = static_cast<SvxSearchDialogWrapper*>( SfxViewFrame::Current()->
2433 GetChildWindow( SvxSearchDialogWrapper::GetChildWindowId() )))
2434 pWrp->getDialog()->SetSearchLabel(sStr);
2437 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */