bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cui / source / dialogs / srchxtra.cxx
blobf6e5de27d0a557fa0e776ce109815842d68e4993
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 <srchxtra.hxx>
21 #include <sal/log.hxx>
22 #include <svl/cjkoptions.hxx>
23 #include <svl/intitem.hxx>
24 #include <svl/whiter.hxx>
25 #include <sfx2/objsh.hxx>
26 #include <svx/svxitems.hrc>
27 #include <svx/strarray.hxx>
28 #include <editeng/flstitem.hxx>
29 #include <chardlg.hxx>
30 #include <paragrph.hxx>
31 #include <backgrnd.hxx>
32 #include <svx/dialogs.hrc>
33 #include <tools/debug.hxx>
34 #include <tools/resary.hxx>
35 #include <rtl/strbuf.hxx>
36 #include <vcl/svapp.hxx>
38 SvxSearchFormatDialog::SvxSearchFormatDialog(weld::Window* pParent, const SfxItemSet& rSet)
39 : SfxTabDialogController(pParent, "cui/ui/searchformatdialog.ui", "SearchFormatDialog", &rSet)
41 AddTabPage("font", SvxCharNamePage::Create, nullptr);
42 AddTabPage("fonteffects", SvxCharEffectsPage::Create, nullptr);
43 AddTabPage("position", SvxCharPositionPage::Create, nullptr);
44 AddTabPage("asianlayout", SvxCharTwoLinesPage::Create, nullptr);
45 AddTabPage("labelTP_PARA_STD", SvxStdParagraphTabPage::Create, nullptr);
46 AddTabPage("labelTP_PARA_ALIGN", SvxParaAlignTabPage::Create, nullptr);
47 AddTabPage("labelTP_PARA_EXT", SvxExtParagraphTabPage::Create, nullptr);
48 AddTabPage("labelTP_PARA_ASIAN", SvxAsianTabPage::Create, nullptr );
49 AddTabPage("background", SvxBkgTabPage::Create, nullptr);
51 // remove asian tabpages if necessary
52 SvtCJKOptions aCJKOptions;
53 if ( !aCJKOptions.IsDoubleLinesEnabled() )
54 RemoveTabPage("asianlayout");
55 if ( !aCJKOptions.IsAsianTypographyEnabled() )
56 RemoveTabPage("labelTP_PARA_ASIAN");
59 SvxSearchFormatDialog::~SvxSearchFormatDialog()
63 void SvxSearchFormatDialog::PageCreated(const OString& rId, SfxTabPage& rPage)
65 if (rId == "font")
67 const FontList* pApm_pFontList = nullptr;
68 SfxObjectShell* pSh = SfxObjectShell::Current();
70 if ( pSh )
72 const SvxFontListItem* pFLItem = static_cast<const SvxFontListItem*>(
73 pSh->GetItem( SID_ATTR_CHAR_FONTLIST ));
74 if ( pFLItem )
75 pApm_pFontList = pFLItem->GetFontList();
78 const FontList* pList = pApm_pFontList;
80 if ( !pList )
82 if ( !m_pFontList )
83 m_pFontList.reset(new FontList(Application::GetDefaultDevice()));
84 pList = m_pFontList.get();
87 static_cast<SvxCharNamePage&>(rPage).
88 SetFontList( SvxFontListItem( pList, SID_ATTR_CHAR_FONTLIST ) );
89 static_cast<SvxCharNamePage&>(rPage).EnableSearchMode();
91 else if (rId == "labelTP_PARA_STD")
93 static_cast<SvxStdParagraphTabPage&>(rPage).EnableAutoFirstLine();
95 else if (rId == "labelTP_PARA_ALIGN")
97 static_cast<SvxParaAlignTabPage&>(rPage).EnableJustifyExt();
99 else if (rId == "background")
101 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
102 aSet.Put(SfxUInt32Item(SID_FLAG_TYPE,static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_HIGHLIGHTING)));
103 rPage.PageCreated(aSet);
107 SvxSearchAttributeDialog::SvxSearchAttributeDialog(weld::Window* pParent,
108 SearchAttrItemList& rLst, const sal_uInt16* pWhRanges)
109 : GenericDialogController(pParent, "cui/ui/searchattrdialog.ui", "SearchAttrDialog")
110 , rList(rLst)
111 , m_xAttrLB(m_xBuilder->weld_tree_view("treeview"))
112 , m_xOKBtn(m_xBuilder->weld_button("ok"))
114 m_xAttrLB->set_size_request(m_xAttrLB->get_approximate_digit_width() * 50,
115 m_xAttrLB->get_height_rows(12));
117 std::vector<int> aWidths;
118 aWidths.push_back(m_xAttrLB->get_checkbox_column_width());
119 m_xAttrLB->set_column_fixed_widths(aWidths);
121 m_xOKBtn->connect_clicked(LINK( this, SvxSearchAttributeDialog, OKHdl));
123 SfxObjectShell* pSh = SfxObjectShell::Current();
124 DBG_ASSERT( pSh, "No DocShell" );
126 SfxItemPool& rPool = pSh->GetPool();
127 SfxItemSet aSet( rPool, pWhRanges );
128 SfxWhichIter aIter( aSet );
129 sal_uInt16 nWhich = aIter.FirstWhich();
131 while ( nWhich )
133 sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
134 if ( nSlot >= SID_SVX_START )
136 bool bChecked = false, bFound = false;
137 for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
139 if ( nSlot == rList[i].nSlot )
141 bFound = true;
142 if ( IsInvalidItem( rList[i].pItem ) )
143 bChecked = true;
147 // item resources are in svx
148 sal_uInt32 nId = SvxAttrNameTable::FindIndex(nSlot);
149 if (RESARRAY_INDEX_NOTFOUND != nId)
151 m_xAttrLB->append();
152 const int nRow = m_xAttrLB->n_children() - 1;
153 m_xAttrLB->set_toggle(nRow, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
154 m_xAttrLB->set_text(nRow, SvxAttrNameTable::GetString(nId), 1);
155 m_xAttrLB->set_id(nRow, OUString::number(nSlot));
157 else
158 SAL_WARN( "cui.dialogs", "no resource for slot id " << static_cast<sal_Int32>(nSlot) );
160 nWhich = aIter.NextWhich();
163 m_xAttrLB->make_sorted();
164 m_xAttrLB->select(0);
167 SvxSearchAttributeDialog::~SvxSearchAttributeDialog()
171 IMPL_LINK_NOARG(SvxSearchAttributeDialog, OKHdl, weld::Button&, void)
173 SearchAttrItem aInvalidItem;
174 aInvalidItem.pItem = INVALID_POOL_ITEM;
176 for (int i = 0, nCount = m_xAttrLB->n_children(); i < nCount; ++i)
178 sal_uInt16 nSlot = m_xAttrLB->get_id(i).toUInt32();
179 bool bChecked = m_xAttrLB->get_toggle(i, 0) == TRISTATE_TRUE;
181 sal_uInt16 j;
182 for ( j = rList.Count(); j; )
184 SearchAttrItem& rItem = rList[ --j ];
185 if( rItem.nSlot == nSlot )
187 if( bChecked )
189 if( !IsInvalidItem( rItem.pItem ) )
190 delete rItem.pItem;
191 rItem.pItem = INVALID_POOL_ITEM;
193 else if( IsInvalidItem( rItem.pItem ) )
194 rItem.pItem = nullptr;
195 j = 1;
196 break;
200 if ( !j && bChecked )
202 aInvalidItem.nSlot = nSlot;
203 rList.Insert( aInvalidItem );
207 // remove invalid items (pItem == NULL)
208 for ( sal_uInt16 n = rList.Count(); n; )
209 if ( !rList[ --n ].pItem )
210 rList.Remove( n );
212 m_xDialog->response(RET_OK);
215 // class SvxSearchSimilarityDialog ---------------------------------------
217 SvxSearchSimilarityDialog::SvxSearchSimilarityDialog(weld::Window* pParent, bool bRelax,
218 sal_uInt16 nOther, sal_uInt16 nShorter, sal_uInt16 nLonger)
219 : GenericDialogController(pParent, "cui/ui/similaritysearchdialog.ui", "SimilaritySearchDialog")
220 , m_xOtherFld(m_xBuilder->weld_spin_button("otherfld"))
221 , m_xLongerFld(m_xBuilder->weld_spin_button("longerfld"))
222 , m_xShorterFld(m_xBuilder->weld_spin_button("shorterfld"))
223 , m_xRelaxBox(m_xBuilder->weld_check_button("relaxbox"))
225 m_xOtherFld->set_value(nOther);
226 m_xShorterFld->set_value(nShorter);
227 m_xLongerFld->set_value(nLonger);
228 m_xRelaxBox->set_active(bRelax);
231 SvxSearchSimilarityDialog::~SvxSearchSimilarityDialog()
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */