bump product version to 7.6.3.2-android
[LibreOffice.git] / cui / source / options / optfltr.cxx
blob48840b17ea33ca300a1a819a256368bf236924cb
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 <unotools/moduleoptions.hxx>
21 #include <unotools/fltrcfg.hxx>
22 #include <officecfg/Office/Common.hxx>
23 #include "optfltr.hxx"
24 #include <strings.hrc>
25 #include <dialmgr.hxx>
27 enum class MSFltrPg2_CheckBoxEntries {
28 Math,
29 Writer,
30 Calc,
31 Impress,
32 SmartArt,
33 Visio,
34 PDF,
35 InvalidCBEntry
39 OfaMSFilterTabPage::OfaMSFilterTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
40 : SfxTabPage(pPage, pController, "cui/ui/optfltrpage.ui", "OptFltrPage", &rSet)
41 , m_xWBasicCodeCB(m_xBuilder->weld_check_button("wo_basic"))
42 , m_xWBasicWbctblCB(m_xBuilder->weld_check_button("wo_exec"))
43 , m_xWBasicStgCB(m_xBuilder->weld_check_button("wo_saveorig"))
44 , m_xEBasicCodeCB(m_xBuilder->weld_check_button("ex_basic"))
45 , m_xEBasicExectblCB(m_xBuilder->weld_check_button("ex_exec"))
46 , m_xEBasicStgCB(m_xBuilder->weld_check_button("ex_saveorig"))
47 , m_xPBasicCodeCB(m_xBuilder->weld_check_button("pp_basic"))
48 , m_xPBasicStgCB(m_xBuilder->weld_check_button("pp_saveorig"))
50 m_xWBasicCodeCB->connect_toggled( LINK( this, OfaMSFilterTabPage, LoadWordBasicCheckHdl_Impl ) );
51 m_xEBasicCodeCB->connect_toggled( LINK( this, OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl ) );
54 OfaMSFilterTabPage::~OfaMSFilterTabPage()
58 IMPL_LINK_NOARG(OfaMSFilterTabPage, LoadWordBasicCheckHdl_Impl, weld::Toggleable&, void)
60 m_xWBasicWbctblCB->set_sensitive(m_xWBasicCodeCB->get_active());
63 IMPL_LINK_NOARG(OfaMSFilterTabPage, LoadExcelBasicCheckHdl_Impl, weld::Toggleable&, void)
65 m_xEBasicExectblCB->set_sensitive(m_xEBasicCodeCB->get_active());
68 std::unique_ptr<SfxTabPage> OfaMSFilterTabPage::Create( weld::Container* pPage, weld::DialogController* pController,
69 const SfxItemSet* rAttrSet )
71 return std::make_unique<OfaMSFilterTabPage>(pPage, pController, *rAttrSet);
74 bool OfaMSFilterTabPage::FillItemSet( SfxItemSet* )
76 SvtFilterOptions& rOpt = SvtFilterOptions::Get();
78 if( m_xWBasicCodeCB->get_state_changed_from_saved() )
79 rOpt.SetLoadWordBasicCode( m_xWBasicCodeCB->get_active() );
80 if( m_xWBasicWbctblCB->get_state_changed_from_saved() )
81 rOpt.SetLoadWordBasicExecutable( m_xWBasicWbctblCB->get_active() );
82 if( m_xWBasicStgCB->get_state_changed_from_saved() )
83 rOpt.SetLoadWordBasicStorage( m_xWBasicStgCB->get_active() );
85 if( m_xEBasicCodeCB->get_state_changed_from_saved())
86 rOpt.SetLoadExcelBasicCode( m_xEBasicCodeCB->get_active() );
87 if( m_xEBasicExectblCB->get_state_changed_from_saved())
88 rOpt.SetLoadExcelBasicExecutable( m_xEBasicExectblCB->get_active() );
89 if( m_xEBasicStgCB->get_state_changed_from_saved())
90 rOpt.SetLoadExcelBasicStorage( m_xEBasicStgCB->get_active() );
92 if( m_xPBasicCodeCB->get_state_changed_from_saved())
93 rOpt.SetLoadPPointBasicCode( m_xPBasicCodeCB->get_active() );
94 if( m_xPBasicStgCB->get_state_changed_from_saved())
95 rOpt.SetLoadPPointBasicStorage( m_xPBasicStgCB->get_active() );
97 return false;
100 void OfaMSFilterTabPage::Reset( const SfxItemSet* )
102 const SvtFilterOptions& rOpt = SvtFilterOptions::Get();
104 m_xWBasicCodeCB->set_active( rOpt.IsLoadWordBasicCode() );
105 m_xWBasicCodeCB->save_state();
106 m_xWBasicWbctblCB->set_active( rOpt.IsLoadWordBasicExecutable() );
107 m_xWBasicWbctblCB->save_state();
108 m_xWBasicStgCB->set_active( rOpt.IsLoadWordBasicStorage() );
109 m_xWBasicStgCB->save_state();
110 LoadWordBasicCheckHdl_Impl( *m_xWBasicCodeCB );
112 m_xEBasicCodeCB->set_active( rOpt.IsLoadExcelBasicCode() );
113 m_xEBasicCodeCB->save_state();
114 m_xEBasicExectblCB->set_active( rOpt.IsLoadExcelBasicExecutable() );
115 m_xEBasicExectblCB->save_state();
116 m_xEBasicStgCB->set_active( rOpt.IsLoadExcelBasicStorage() );
117 m_xEBasicStgCB->save_state();
118 LoadExcelBasicCheckHdl_Impl( *m_xEBasicCodeCB );
120 m_xPBasicCodeCB->set_active( rOpt.IsLoadPPointBasicCode() );
121 m_xPBasicCodeCB->save_state();
122 m_xPBasicStgCB->set_active( rOpt.IsLoadPPointBasicStorage() );
123 m_xPBasicStgCB->save_state();
126 OfaMSFilterTabPage2::OfaMSFilterTabPage2(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
127 : SfxTabPage(pPage, pController, "cui/ui/optfltrembedpage.ui", "OptFilterPage", &rSet)
128 , sChgToFromMath(CuiResId(RID_CUISTR_CHG_MATH))
129 , sChgToFromWriter(CuiResId(RID_CUISTR_CHG_WRITER))
130 , sChgToFromCalc(CuiResId(RID_CUISTR_CHG_CALC))
131 , sChgToFromImpress(CuiResId(RID_CUISTR_CHG_IMPRESS))
132 , sChgToFromSmartArt(CuiResId(RID_CUISTR_CHG_SMARTART))
133 , sChgToFromVisio(CuiResId(RID_CUISTR_CHG_VISIO))
134 , sChgToFromPDF(CuiResId(RID_CUISTR_CHG_PDF))
135 , m_xCheckLB(m_xBuilder->weld_tree_view("checklbcontainer"))
136 , m_xHighlightingRB(m_xBuilder->weld_radio_button("highlighting"))
137 , m_xShadingRB(m_xBuilder->weld_radio_button("shading"))
138 , m_xMSOLockFileCB(m_xBuilder->weld_check_button("mso_lockfile"))
140 std::vector<int> aWidths
142 m_xCheckLB->get_checkbox_column_width(),
143 m_xCheckLB->get_checkbox_column_width()
145 m_xCheckLB->set_column_fixed_widths(aWidths);
148 OfaMSFilterTabPage2::~OfaMSFilterTabPage2()
152 std::unique_ptr<SfxTabPage> OfaMSFilterTabPage2::Create( weld::Container* pPage, weld::DialogController* pController,
153 const SfxItemSet* rAttrSet )
155 return std::make_unique<OfaMSFilterTabPage2>( pPage, pController, *rAttrSet );
158 bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet* )
160 SvtFilterOptions& rOpt = SvtFilterOptions::Get();
162 static struct ChkCBoxEntries{
163 MSFltrPg2_CheckBoxEntries eType;
164 bool (SvtFilterOptions::*FnIs)() const;
165 void (SvtFilterOptions::*FnSet)( bool bFlag );
166 } const aChkArr[] = {
167 { MSFltrPg2_CheckBoxEntries::Math, &SvtFilterOptions::IsMathType2Math,
168 &SvtFilterOptions::SetMathType2Math },
169 { MSFltrPg2_CheckBoxEntries::Math, &SvtFilterOptions::IsMath2MathType,
170 &SvtFilterOptions::SetMath2MathType },
171 { MSFltrPg2_CheckBoxEntries::Writer, &SvtFilterOptions::IsWinWord2Writer,
172 &SvtFilterOptions::SetWinWord2Writer },
173 { MSFltrPg2_CheckBoxEntries::Writer, &SvtFilterOptions::IsWriter2WinWord,
174 &SvtFilterOptions::SetWriter2WinWord },
175 { MSFltrPg2_CheckBoxEntries::Calc, &SvtFilterOptions::IsExcel2Calc,
176 &SvtFilterOptions::SetExcel2Calc },
177 { MSFltrPg2_CheckBoxEntries::Calc, &SvtFilterOptions::IsCalc2Excel,
178 &SvtFilterOptions::SetCalc2Excel },
179 { MSFltrPg2_CheckBoxEntries::Impress, &SvtFilterOptions::IsPowerPoint2Impress,
180 &SvtFilterOptions::SetPowerPoint2Impress },
181 { MSFltrPg2_CheckBoxEntries::Impress, &SvtFilterOptions::IsImpress2PowerPoint,
182 &SvtFilterOptions::SetImpress2PowerPoint },
183 { MSFltrPg2_CheckBoxEntries::SmartArt, &SvtFilterOptions::IsSmartArt2Shape,
184 &SvtFilterOptions::SetSmartArt2Shape },
185 { MSFltrPg2_CheckBoxEntries::Visio, &SvtFilterOptions::IsVisio2Draw,
186 &SvtFilterOptions::SetVisio2Draw },
189 bool bFirstCol = true;
190 for( const ChkCBoxEntries & rEntry : aChkArr )
192 // we loop through the list, alternating reading the first/second column,
193 // each row appears twice in the list (except for smartart and later entries, which are
194 // import only)
195 sal_uInt16 nCol = bFirstCol ? 0 : 1;
196 bFirstCol = !bFirstCol;
197 int nEntry = GetEntry4Type(rEntry.eType);
198 if (nEntry != -1)
200 bool bCheck = m_xCheckLB->get_toggle(nEntry, nCol);
201 if( bCheck != (rOpt.*rEntry.FnIs)() )
202 (rOpt.*rEntry.FnSet)( bCheck );
204 if (rEntry.eType == MSFltrPg2_CheckBoxEntries::SmartArt)
206 bFirstCol = !bFirstCol;
209 int nPDFEntry = GetEntry4Type(MSFltrPg2_CheckBoxEntries::PDF);
210 bool bPDFCheck = m_xCheckLB->get_toggle(nPDFEntry, 0);
211 if (bPDFCheck != officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::get())
213 std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
214 comphelper::ConfigurationChanges::create());
215 officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(bPDFCheck, pBatch);
216 pBatch->commit();
219 if( m_xHighlightingRB->get_state_changed_from_saved() )
221 if (m_xHighlightingRB->get_active())
222 rOpt.SetCharBackground2Highlighting();
223 else
224 rOpt.SetCharBackground2Shading();
227 if (m_xMSOLockFileCB->get_state_changed_from_saved())
229 rOpt.EnableMSOLockFileCreation(m_xMSOLockFileCB->get_active());
232 return true;
235 void OfaMSFilterTabPage2::Reset( const SfxItemSet* )
237 SvtFilterOptions& rOpt = SvtFilterOptions::Get();
239 m_xCheckLB->freeze();
240 m_xCheckLB->clear();
242 SvtModuleOptions aModuleOpt;
244 // int the same sequence as the enums of MSFltrPg2_CheckBoxEntries
245 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::MATH ) )
246 InsertEntry( sChgToFromMath, MSFltrPg2_CheckBoxEntries::Math );
247 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::WRITER ) )
248 InsertEntry( sChgToFromWriter, MSFltrPg2_CheckBoxEntries::Writer );
249 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::CALC ) )
250 InsertEntry( sChgToFromCalc, MSFltrPg2_CheckBoxEntries::Calc );
251 if ( aModuleOpt.IsModuleInstalled( SvtModuleOptions::EModule::IMPRESS ) )
252 InsertEntry( sChgToFromImpress, MSFltrPg2_CheckBoxEntries::Impress );
253 InsertEntry( sChgToFromSmartArt, MSFltrPg2_CheckBoxEntries::SmartArt, false );
254 if (aModuleOpt.IsModuleInstalled(SvtModuleOptions::EModule::DRAW))
256 InsertEntry(sChgToFromVisio, MSFltrPg2_CheckBoxEntries::Visio, false);
257 InsertEntry(sChgToFromPDF, MSFltrPg2_CheckBoxEntries::PDF, false);
260 static struct ChkCBoxEntries{
261 MSFltrPg2_CheckBoxEntries eType;
262 bool (SvtFilterOptions::*FnIs)() const;
263 } const aChkArr[] = {
264 { MSFltrPg2_CheckBoxEntries::Math, &SvtFilterOptions::IsMathType2Math },
265 { MSFltrPg2_CheckBoxEntries::Math, &SvtFilterOptions::IsMath2MathType },
266 { MSFltrPg2_CheckBoxEntries::Writer, &SvtFilterOptions::IsWinWord2Writer },
267 { MSFltrPg2_CheckBoxEntries::Writer, &SvtFilterOptions::IsWriter2WinWord },
268 { MSFltrPg2_CheckBoxEntries::Calc, &SvtFilterOptions::IsExcel2Calc },
269 { MSFltrPg2_CheckBoxEntries::Calc, &SvtFilterOptions::IsCalc2Excel },
270 { MSFltrPg2_CheckBoxEntries::Impress, &SvtFilterOptions::IsPowerPoint2Impress },
271 { MSFltrPg2_CheckBoxEntries::Impress, &SvtFilterOptions::IsImpress2PowerPoint },
272 { MSFltrPg2_CheckBoxEntries::SmartArt, &SvtFilterOptions::IsSmartArt2Shape },
273 { MSFltrPg2_CheckBoxEntries::Visio, &SvtFilterOptions::IsVisio2Draw },
274 { MSFltrPg2_CheckBoxEntries::PDF, nullptr },
277 bool bFirstCol = true;
278 for( const ChkCBoxEntries & rArr : aChkArr )
280 // we loop through the list, alternating reading the first/second column,
281 // each row appears twice in the list (except for smartart and later entries, which are
282 // import only)
283 sal_uInt16 nCol = bFirstCol ? 0 : 1;
284 bFirstCol = !bFirstCol;
285 int nEntry = GetEntry4Type( rArr.eType );
286 if (nEntry != -1)
288 bool bCheck = false;
289 if (rArr.eType != MSFltrPg2_CheckBoxEntries::PDF)
291 bCheck = (rOpt.*rArr.FnIs)();
293 else
295 bCheck = officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::get();
296 nCol = 0;
298 m_xCheckLB->set_toggle(nEntry, bCheck ? TRISTATE_TRUE : TRISTATE_FALSE, nCol);
300 if (rArr.eType == MSFltrPg2_CheckBoxEntries::SmartArt)
302 bFirstCol = !bFirstCol;
305 m_xCheckLB->thaw();
307 if (rOpt.IsCharBackground2Highlighting())
308 m_xHighlightingRB->set_active(true);
309 else
310 m_xShadingRB->set_active(true);
312 m_xHighlightingRB->save_state();
314 m_xMSOLockFileCB->set_active(rOpt.IsMSOLockFileCreationIsEnabled());
315 m_xMSOLockFileCB->save_state();
316 m_xMSOLockFileCB->set_sensitive(!officecfg::Office::Common::Filter::Microsoft::Import::CreateMSOLockFiles::isReadOnly());
319 void OfaMSFilterTabPage2::InsertEntry( const OUString& _rTxt, MSFltrPg2_CheckBoxEntries _nType )
321 InsertEntry( _rTxt, _nType, true );
324 void OfaMSFilterTabPage2::InsertEntry( const OUString& _rTxt, MSFltrPg2_CheckBoxEntries _nType,
325 bool saveEnabled )
327 int nPos = m_xCheckLB->n_children();
328 m_xCheckLB->append();
329 m_xCheckLB->set_toggle(nPos, TRISTATE_FALSE, 0);
330 if (saveEnabled)
331 m_xCheckLB->set_toggle(nPos, TRISTATE_FALSE, 1);
332 m_xCheckLB->set_text(nPos, _rTxt, 2);
333 m_xCheckLB->set_id(nPos, OUString::number(static_cast<sal_Int32>(_nType)));
336 int OfaMSFilterTabPage2::GetEntry4Type( MSFltrPg2_CheckBoxEntries _nType ) const
338 for (int i = 0, nEntryCount = m_xCheckLB->n_children(); i < nEntryCount; ++i)
340 if (_nType == static_cast<MSFltrPg2_CheckBoxEntries>(m_xCheckLB->get_id(i).toInt32()))
341 return i;
343 return -1;
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */