tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / cui / source / dialogs / srchxtra.cxx
blobefa37ecb945ce2900482c7f489938bc4b01c7ab0
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/flagsdef.hxx>
27 #include <svx/strarray.hxx>
28 #include <editeng/flstitem.hxx>
29 #include <chardlg.hxx>
30 #include <paragrph.hxx>
31 #include <backgrnd.hxx>
32 #include <editeng/editids.hrc>
33 #include <svx/svxids.hrc>
34 #include <tools/debug.hxx>
35 #include <tools/resary.hxx>
36 #include <vcl/svapp.hxx>
38 SvxSearchFormatDialog::SvxSearchFormatDialog(weld::Window* pParent, const SfxItemSet& rSet)
39 : SfxTabDialogController(pParent, u"cui/ui/searchformatdialog.ui"_ustr, u"SearchFormatDialog"_ustr, &rSet)
41 AddTabPage(u"font"_ustr, SvxCharNamePage::Create, nullptr);
42 AddTabPage(u"fonteffects"_ustr, SvxCharEffectsPage::Create, nullptr);
43 AddTabPage(u"position"_ustr, SvxCharPositionPage::Create, nullptr);
44 AddTabPage(u"asianlayout"_ustr, SvxCharTwoLinesPage::Create, nullptr);
45 AddTabPage(u"labelTP_PARA_STD"_ustr, SvxStdParagraphTabPage::Create, nullptr);
46 AddTabPage(u"labelTP_PARA_ALIGN"_ustr, SvxParaAlignTabPage::Create, nullptr);
47 AddTabPage(u"labelTP_PARA_EXT"_ustr, SvxExtParagraphTabPage::Create, nullptr);
48 AddTabPage(u"labelTP_PARA_ASIAN"_ustr, SvxAsianTabPage::Create, nullptr );
49 AddTabPage(u"background"_ustr, SvxBkgTabPage::Create, nullptr);
51 // remove asian tabpages if necessary
52 if ( !SvtCJKOptions::IsDoubleLinesEnabled() )
53 RemoveTabPage(u"asianlayout"_ustr);
54 if ( !SvtCJKOptions::IsAsianTypographyEnabled() )
55 RemoveTabPage(u"labelTP_PARA_ASIAN"_ustr);
58 SvxSearchFormatDialog::~SvxSearchFormatDialog()
62 void SvxSearchFormatDialog::PageCreated(const OUString& rId, SfxTabPage& rPage)
64 if (rId == "font")
66 const FontList* pApm_pFontList = nullptr;
67 if (SfxObjectShell* pSh = SfxObjectShell::Current())
69 const SvxFontListItem* pFLItem = static_cast<const SvxFontListItem*>(
70 pSh->GetItem( SID_ATTR_CHAR_FONTLIST ));
71 if ( pFLItem )
72 pApm_pFontList = pFLItem->GetFontList();
75 const FontList* pList = pApm_pFontList;
77 if ( !pList )
79 if ( !m_pFontList )
80 m_pFontList.reset(new FontList(Application::GetDefaultDevice()));
81 pList = m_pFontList.get();
84 static_cast<SvxCharNamePage&>(rPage).
85 SetFontList( SvxFontListItem( pList, SID_ATTR_CHAR_FONTLIST ) );
86 static_cast<SvxCharNamePage&>(rPage).EnableSearchMode();
88 else if (rId == "labelTP_PARA_STD")
90 static_cast<SvxStdParagraphTabPage&>(rPage).EnableAutoFirstLine();
92 else if (rId == "labelTP_PARA_ALIGN")
94 static_cast<SvxParaAlignTabPage&>(rPage).EnableJustifyExt();
96 else if (rId == "background")
98 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
99 aSet.Put(SfxUInt32Item(SID_FLAG_TYPE,static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_HIGHLIGHTING)));
100 rPage.PageCreated(aSet);
104 SvxSearchAttributeDialog::SvxSearchAttributeDialog(weld::Window* pParent,
105 SearchAttrItemList& rLst, const WhichRangesContainer& pWhRanges)
106 : GenericDialogController(pParent, u"cui/ui/searchattrdialog.ui"_ustr, u"SearchAttrDialog"_ustr)
107 , rList(rLst)
108 , m_xAttrLB(m_xBuilder->weld_tree_view(u"treeview"_ustr))
109 , m_xOKBtn(m_xBuilder->weld_button(u"ok"_ustr))
111 m_xAttrLB->set_size_request(m_xAttrLB->get_approximate_digit_width() * 50,
112 m_xAttrLB->get_height_rows(12));
114 m_xAttrLB->enable_toggle_buttons(weld::ColumnToggleType::Check);
116 m_xOKBtn->connect_clicked(LINK( this, SvxSearchAttributeDialog, OKHdl));
118 SfxObjectShell* pSh = SfxObjectShell::Current();
119 DBG_ASSERT( pSh, "No DocShell" );
120 if (pSh)
122 SfxItemPool& rPool = pSh->GetPool();
123 SfxItemSet aSet( rPool, pWhRanges );
124 SfxWhichIter aIter( aSet );
125 sal_uInt16 nWhich = aIter.FirstWhich();
127 while ( nWhich )
129 sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
130 if ( nSlot >= SID_SVX_START )
132 bool bChecked = false, bFound = false;
133 for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
135 if ( nSlot == rList[i].nSlot )
137 bFound = true;
138 if ( IsInvalidItem( rList[i].aItemPtr.getItem() ) )
139 bChecked = true;
143 // item resources are in svx
144 sal_uInt32 nId = SvxAttrNameTable::FindIndex(nSlot);
145 if (RESARRAY_INDEX_NOTFOUND != nId)
147 m_xAttrLB->append();
148 const int nRow = m_xAttrLB->n_children() - 1;
149 m_xAttrLB->set_toggle(nRow, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE);
150 m_xAttrLB->set_text(nRow, SvxAttrNameTable::GetString(nId), 0);
151 m_xAttrLB->set_id(nRow, OUString::number(nSlot));
153 else
154 SAL_WARN( "cui.dialogs", "no resource for slot id " << static_cast<sal_Int32>(nSlot) );
156 nWhich = aIter.NextWhich();
160 m_xAttrLB->make_sorted();
161 m_xAttrLB->select(0);
164 SvxSearchAttributeDialog::~SvxSearchAttributeDialog()
168 IMPL_LINK_NOARG(SvxSearchAttributeDialog, OKHdl, weld::Button&, void)
170 SfxObjectShell* pObjSh = SfxObjectShell::Current();
171 DBG_ASSERT( pObjSh, "No DocShell" );
172 if (!pObjSh)
173 return;
174 SfxItemPool& rPool(pObjSh->GetPool());
176 for (int i = 0, nCount = m_xAttrLB->n_children(); i < nCount; ++i)
178 const sal_uInt16 nSlot(m_xAttrLB->get_id(i).toUInt32());
179 const bool bChecked(TRISTATE_TRUE == m_xAttrLB->get_toggle(i));
181 sal_uInt16 j;
182 for ( j = rList.Count(); j; )
184 SearchAttrInfo& rItem = rList[ --j ];
185 if( rItem.nSlot == nSlot )
187 if( bChecked )
188 rItem.aItemPtr = SfxPoolItemHolder(rPool, INVALID_POOL_ITEM);
189 else if( IsInvalidItem( rItem.aItemPtr.getItem() ) )
190 rItem.aItemPtr = SfxPoolItemHolder();
191 j = 1;
192 break;
196 if ( !j && bChecked )
198 rList.Insert( { nSlot, SfxPoolItemHolder(rPool, INVALID_POOL_ITEM) });
202 // remove invalid items (pItem == NULL)
203 for ( sal_uInt16 n = rList.Count(); n; )
204 if ( !rList[ --n ].aItemPtr.getItem() )
205 rList.Remove( n );
207 m_xDialog->response(RET_OK);
210 // class SvxSearchSimilarityDialog ---------------------------------------
212 SvxSearchSimilarityDialog::SvxSearchSimilarityDialog(weld::Window* pParent, bool bRelax,
213 sal_uInt16 nOther, sal_uInt16 nShorter, sal_uInt16 nLonger)
214 : GenericDialogController(pParent, u"cui/ui/similaritysearchdialog.ui"_ustr, u"SimilaritySearchDialog"_ustr)
215 , m_xOtherFld(m_xBuilder->weld_spin_button(u"otherfld"_ustr))
216 , m_xLongerFld(m_xBuilder->weld_spin_button(u"longerfld"_ustr))
217 , m_xShorterFld(m_xBuilder->weld_spin_button(u"shorterfld"_ustr))
218 , m_xRelaxBox(m_xBuilder->weld_check_button(u"relaxbox"_ustr))
220 m_xOtherFld->set_value(nOther);
221 m_xShorterFld->set_value(nShorter);
222 m_xLongerFld->set_value(nLonger);
223 m_xRelaxBox->set_active(bRelax);
226 SvxSearchSimilarityDialog::~SvxSearchSimilarityDialog()
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */