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 <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>
37
38 #include <vcl/tabs.hrc>
39
SvxSearchFormatDialog(weld::Window * pParent,const SfxItemSet & rSet)40 SvxSearchFormatDialog::SvxSearchFormatDialog(weld::Window* pParent, const SfxItemSet& rSet)
41 : SfxTabDialogController(pParent, u"cui/ui/searchformatdialog.ui"_ustr, u"SearchFormatDialog"_ustr, &rSet)
42 {
43 AddTabPage(u"font"_ustr, TabResId(RID_TAB_FONT.aLabel), SvxCharNamePage::Create,
44 RID_M + RID_TAB_FONT.sIconName);
45 AddTabPage(u"fonteffects"_ustr, TabResId(RID_TAB_FONTEFFECTS.aLabel),
46 SvxCharEffectsPage::Create, RID_M + RID_TAB_FONTEFFECTS.sIconName);
47 AddTabPage(u"position"_ustr, TabResId(RID_TAB_POSITION.aLabel), SvxCharPositionPage::Create,
48 RID_M + RID_TAB_POSITION.sIconName);
49 if (SvtCJKOptions::IsDoubleLinesEnabled())
50 AddTabPage(u"asianlayout"_ustr, TabResId(RID_TAB_ASIANLAYOUT.aLabel),
51 SvxCharTwoLinesPage::Create, RID_M + RID_TAB_ASIANLAYOUT.sIconName);
52 AddTabPage(u"indents"_ustr, TabResId(RID_TAB_INDENTS.aLabel), SvxStdParagraphTabPage::Create,
53 RID_M + RID_TAB_INDENTS.sIconName);
54 AddTabPage(u"alignment"_ustr, TabResId(RID_TAB_ALIGNMENT.aLabel), SvxParaAlignTabPage::Create,
55 RID_M + RID_TAB_ALIGNMENT.sIconName);
56 AddTabPage(u"textflow"_ustr, TabResId(RID_TAB_TEXTFLOW.aLabel), SvxExtParagraphTabPage::Create,
57 RID_M + RID_TAB_TEXTFLOW.sIconName);
58 if (SvtCJKOptions::IsAsianTypographyEnabled())
59 AddTabPage(u"asiantypo"_ustr, TabResId(RID_TAB_ASIANTYPO.aLabel), SvxAsianTabPage::Create,
60 RID_M + RID_TAB_ASIANTYPO.sIconName);
61 AddTabPage(u"background"_ustr, TabResId(RID_TAB_HIGHLIGHTING.aLabel), SvxBkgTabPage::Create,
62 RID_M + RID_TAB_HIGHLIGHTING.sIconName);
63 }
64
~SvxSearchFormatDialog()65 SvxSearchFormatDialog::~SvxSearchFormatDialog()
66 {
67 }
68
PageCreated(const OUString & rId,SfxTabPage & rPage)69 void SvxSearchFormatDialog::PageCreated(const OUString& rId, SfxTabPage& rPage)
70 {
71 if (rId == "font")
72 {
73 const FontList* pApm_pFontList = nullptr;
74 if (SfxObjectShell* pSh = SfxObjectShell::Current())
75 {
76 const SvxFontListItem* pFLItem = static_cast<const SvxFontListItem*>(
77 pSh->GetItem( SID_ATTR_CHAR_FONTLIST ));
78 if ( pFLItem )
79 pApm_pFontList = pFLItem->GetFontList();
80 }
81
82 const FontList* pList = pApm_pFontList;
83
84 if ( !pList )
85 {
86 if ( !m_pFontList )
87 m_pFontList.reset(new FontList(Application::GetDefaultDevice()));
88 pList = m_pFontList.get();
89 }
90
91 static_cast<SvxCharNamePage&>(rPage).
92 SetFontList( SvxFontListItem( pList, SID_ATTR_CHAR_FONTLIST ) );
93 static_cast<SvxCharNamePage&>(rPage).EnableSearchMode();
94 }
95 else if (rId == "indents")
96 {
97 static_cast<SvxStdParagraphTabPage&>(rPage).EnableAutoFirstLine();
98 }
99 else if (rId == "alignment")
100 {
101 static_cast<SvxParaAlignTabPage&>(rPage).EnableJustifyExt();
102 }
103 else if (rId == "background")
104 {
105 SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
106 aSet.Put(SfxUInt32Item(SID_FLAG_TYPE,static_cast<sal_uInt32>(SvxBackgroundTabFlags::SHOW_HIGHLIGHTING)));
107 rPage.PageCreated(aSet);
108 }
109 }
110
SvxSearchAttributeDialog(weld::Window * pParent,SearchAttrItemList & rLst,const WhichRangesContainer & pWhRanges)111 SvxSearchAttributeDialog::SvxSearchAttributeDialog(weld::Window* pParent,
112 SearchAttrItemList& rLst, const WhichRangesContainer& pWhRanges)
113 : GenericDialogController(pParent, u"cui/ui/searchattrdialog.ui"_ustr, u"SearchAttrDialog"_ustr)
114 , rList(rLst)
115 , m_xAttrLB(m_xBuilder->weld_tree_view(u"treeview"_ustr))
116 , m_xOKBtn(m_xBuilder->weld_button(u"ok"_ustr))
117 {
118 m_xAttrLB->set_size_request(m_xAttrLB->get_approximate_digit_width() * 50,
119 m_xAttrLB->get_height_rows(12));
120
121 m_xAttrLB->enable_toggle_buttons(weld::ColumnToggleType::Check);
122
123 m_xOKBtn->connect_clicked(LINK( this, SvxSearchAttributeDialog, OKHdl));
124
125 SfxObjectShell* pSh = SfxObjectShell::Current();
126 DBG_ASSERT( pSh, "No DocShell" );
127 if (pSh)
128 {
129 SfxItemPool& rPool = pSh->GetPool();
130 SfxItemSet aSet( rPool, pWhRanges );
131 SfxWhichIter aIter( aSet );
132 sal_uInt16 nWhich = aIter.FirstWhich();
133
134 while ( nWhich )
135 {
136 sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
137 if ( nSlot >= SID_SVX_START )
138 {
139 bool bChecked = false, bFound = false;
140 for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
141 {
142 if ( nSlot == rList[i].nSlot )
143 {
144 bFound = true;
145 if ( IsInvalidItem( rList[i].aItemPtr.getItem() ) )
146 bChecked = true;
147 }
148 }
149
150 // item resources are in svx
151 sal_uInt32 nId = SvxAttrNameTable::FindIndex(nSlot);
152 if (RESARRAY_INDEX_NOTFOUND != nId)
153 {
154 m_xAttrLB->append();
155 const int nRow = m_xAttrLB->n_children() - 1;
156 m_xAttrLB->set_toggle(nRow, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE);
157 m_xAttrLB->set_text(nRow, SvxAttrNameTable::GetString(nId), 0);
158 m_xAttrLB->set_id(nRow, OUString::number(nSlot));
159 }
160 else
161 SAL_WARN( "cui.dialogs", "no resource for slot id " << static_cast<sal_Int32>(nSlot) );
162 }
163 nWhich = aIter.NextWhich();
164 }
165 }
166
167 m_xAttrLB->make_sorted();
168 m_xAttrLB->select(0);
169 }
170
~SvxSearchAttributeDialog()171 SvxSearchAttributeDialog::~SvxSearchAttributeDialog()
172 {
173 }
174
IMPL_LINK_NOARG(SvxSearchAttributeDialog,OKHdl,weld::Button &,void)175 IMPL_LINK_NOARG(SvxSearchAttributeDialog, OKHdl, weld::Button&, void)
176 {
177 SfxObjectShell* pObjSh = SfxObjectShell::Current();
178 DBG_ASSERT( pObjSh, "No DocShell" );
179 if (!pObjSh)
180 return;
181 SfxItemPool& rPool(pObjSh->GetPool());
182
183 for (int i = 0, nCount = m_xAttrLB->n_children(); i < nCount; ++i)
184 {
185 const sal_uInt16 nSlot(m_xAttrLB->get_id(i).toUInt32());
186 const bool bChecked(TRISTATE_TRUE == m_xAttrLB->get_toggle(i));
187
188 sal_uInt16 j;
189 for ( j = rList.Count(); j; )
190 {
191 SearchAttrInfo& rItem = rList[ --j ];
192 if( rItem.nSlot == nSlot )
193 {
194 if( bChecked )
195 rItem.aItemPtr = SfxPoolItemHolder(rPool, INVALID_POOL_ITEM);
196 else if( IsInvalidItem( rItem.aItemPtr.getItem() ) )
197 rItem.aItemPtr = SfxPoolItemHolder();
198 j = 1;
199 break;
200 }
201 }
202
203 if ( !j && bChecked )
204 {
205 rList.Insert( { nSlot, SfxPoolItemHolder(rPool, INVALID_POOL_ITEM) });
206 }
207 }
208
209 // remove invalid items (pItem == NULL)
210 for ( sal_uInt16 n = rList.Count(); n; )
211 if ( !rList[ --n ].aItemPtr.getItem() )
212 rList.Remove( n );
213
214 m_xDialog->response(RET_OK);
215 }
216
217 // class SvxSearchSimilarityDialog ---------------------------------------
218
SvxSearchSimilarityDialog(weld::Window * pParent,bool bRelax,sal_uInt16 nOther,sal_uInt16 nShorter,sal_uInt16 nLonger)219 SvxSearchSimilarityDialog::SvxSearchSimilarityDialog(weld::Window* pParent, bool bRelax,
220 sal_uInt16 nOther, sal_uInt16 nShorter, sal_uInt16 nLonger)
221 : GenericDialogController(pParent, u"cui/ui/similaritysearchdialog.ui"_ustr, u"SimilaritySearchDialog"_ustr)
222 , m_xOtherFld(m_xBuilder->weld_spin_button(u"otherfld"_ustr))
223 , m_xLongerFld(m_xBuilder->weld_spin_button(u"longerfld"_ustr))
224 , m_xShorterFld(m_xBuilder->weld_spin_button(u"shorterfld"_ustr))
225 , m_xRelaxBox(m_xBuilder->weld_check_button(u"relaxbox"_ustr))
226 {
227 m_xOtherFld->set_value(nOther);
228 m_xShorterFld->set_value(nShorter);
229 m_xLongerFld->set_value(nLonger);
230 m_xRelaxBox->set_active(bRelax);
231 }
232
~SvxSearchSimilarityDialog()233 SvxSearchSimilarityDialog::~SvxSearchSimilarityDialog()
234 {
235 }
236
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
238