1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <officecfg/Office/Common.hxx>
22 #include <officecfg/Office/Calc.hxx>
23 #include <officecfg/Office/Writer.hxx>
24 #include <officecfg/Office/Impress.hxx>
25 #include "optfltr.hxx"
26 #include <strings.hrc>
27 #include <dialmgr.hxx>
29 enum class MSFltrPg2_CheckBoxEntries
{
41 OfaMSFilterTabPage::OfaMSFilterTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
42 : SfxTabPage(pPage
, pController
, u
"cui/ui/optfltrpage.ui"_ustr
, u
"OptFltrPage"_ustr
, &rSet
)
43 , m_xWBasicCodeCB(m_xBuilder
->weld_check_button(u
"wo_basic"_ustr
))
44 , m_xWBasicCodeImg(m_xBuilder
->weld_widget(u
"lockwo_basic"_ustr
))
45 , m_xWBasicWbctblCB(m_xBuilder
->weld_check_button(u
"wo_exec"_ustr
))
46 , m_xWBasicWbctblImg(m_xBuilder
->weld_widget(u
"lockwo_exec"_ustr
))
47 , m_xWBasicStgCB(m_xBuilder
->weld_check_button(u
"wo_saveorig"_ustr
))
48 , m_xWBasicStgImg(m_xBuilder
->weld_widget(u
"lockwo_saveorig"_ustr
))
49 , m_xEBasicCodeCB(m_xBuilder
->weld_check_button(u
"ex_basic"_ustr
))
50 , m_xEBasicCodeImg(m_xBuilder
->weld_widget(u
"lockex_basic"_ustr
))
51 , m_xEBasicExectblCB(m_xBuilder
->weld_check_button(u
"ex_exec"_ustr
))
52 , m_xEBasicExectblImg(m_xBuilder
->weld_widget(u
"lockex_exec"_ustr
))
53 , m_xEBasicStgCB(m_xBuilder
->weld_check_button(u
"ex_saveorig"_ustr
))
54 , m_xEBasicStgImg(m_xBuilder
->weld_widget(u
"lockex_saveorig"_ustr
))
55 , m_xPBasicCodeCB(m_xBuilder
->weld_check_button(u
"pp_basic"_ustr
))
56 , m_xPBasicCodeImg(m_xBuilder
->weld_widget(u
"lockpp_basic"_ustr
))
57 , m_xPBasicStgCB(m_xBuilder
->weld_check_button(u
"pp_saveorig"_ustr
))
58 , m_xPBasicStgImg(m_xBuilder
->weld_widget(u
"lockpp_saveorig"_ustr
))
60 m_xWBasicCodeCB
->connect_toggled( LINK( this, OfaMSFilterTabPage
, LoadWordBasicCheckHdl_Impl
) );
61 m_xEBasicCodeCB
->connect_toggled( LINK( this, OfaMSFilterTabPage
, LoadExcelBasicCheckHdl_Impl
) );
64 OfaMSFilterTabPage::~OfaMSFilterTabPage()
68 IMPL_LINK_NOARG(OfaMSFilterTabPage
, LoadWordBasicCheckHdl_Impl
, weld::Toggleable
&, void)
70 m_xWBasicWbctblCB
->set_sensitive(m_xWBasicCodeCB
->get_active() && !officecfg::Office::Writer::Filter::Import::VBA::Executable::isReadOnly());
71 m_xWBasicWbctblImg
->set_visible(officecfg::Office::Writer::Filter::Import::VBA::Executable::isReadOnly());
74 IMPL_LINK_NOARG(OfaMSFilterTabPage
, LoadExcelBasicCheckHdl_Impl
, weld::Toggleable
&, void)
76 m_xEBasicExectblCB
->set_sensitive(m_xEBasicCodeCB
->get_active() && !officecfg::Office::Calc::Filter::Import::VBA::Executable::isReadOnly());
77 m_xEBasicExectblImg
->set_visible(officecfg::Office::Calc::Filter::Import::VBA::Executable::isReadOnly());
80 std::unique_ptr
<SfxTabPage
> OfaMSFilterTabPage::Create( weld::Container
* pPage
, weld::DialogController
* pController
,
81 const SfxItemSet
* rAttrSet
)
83 return std::make_unique
<OfaMSFilterTabPage
>(pPage
, pController
, *rAttrSet
);
86 OUString
OfaMSFilterTabPage::GetAllStrings()
89 OUString labels
[] = { u
"label1"_ustr
, u
"label2"_ustr
, u
"label3"_ustr
};
91 for (const auto& label
: labels
)
93 if (const auto pString
= m_xBuilder
->weld_label(label
))
94 sAllStrings
+= pString
->get_label() + " ";
97 OUString checkButton
[] = { u
"wo_basic"_ustr
, u
"wo_exec"_ustr
, u
"wo_saveorig"_ustr
, u
"ex_basic"_ustr
,
98 u
"ex_exec"_ustr
, u
"ex_saveorig"_ustr
, u
"pp_basic"_ustr
, u
"pp_saveorig"_ustr
};
100 for (const auto& check
: checkButton
)
102 if (const auto pString
= m_xBuilder
->weld_check_button(check
))
103 sAllStrings
+= pString
->get_label() + " ";
106 return sAllStrings
.replaceAll("_", "");
109 bool OfaMSFilterTabPage::FillItemSet( SfxItemSet
* )
111 auto batch
= comphelper::ConfigurationChanges::create();
113 if( m_xWBasicCodeCB
->get_state_changed_from_saved() )
114 officecfg::Office::Writer::Filter::Import::VBA::Load::set(m_xWBasicCodeCB
->get_active(), batch
);
115 if( m_xWBasicWbctblCB
->get_state_changed_from_saved() )
116 officecfg::Office::Writer::Filter::Import::VBA::Executable::set(m_xWBasicWbctblCB
->get_active(), batch
);
117 if( m_xWBasicStgCB
->get_state_changed_from_saved() )
118 officecfg::Office::Writer::Filter::Import::VBA::Save::set(m_xWBasicStgCB
->get_active(), batch
);
120 if( m_xEBasicCodeCB
->get_state_changed_from_saved())
121 officecfg::Office::Calc::Filter::Import::VBA::Load::set(m_xEBasicCodeCB
->get_active(), batch
);
122 if( m_xEBasicExectblCB
->get_state_changed_from_saved())
123 officecfg::Office::Calc::Filter::Import::VBA::Executable::set(m_xEBasicExectblCB
->get_active(), batch
);
124 if( m_xEBasicStgCB
->get_state_changed_from_saved())
125 officecfg::Office::Calc::Filter::Import::VBA::Save::set(m_xEBasicStgCB
->get_active(), batch
);
127 if( m_xPBasicCodeCB
->get_state_changed_from_saved())
128 officecfg::Office::Impress::Filter::Import::VBA::Load::set(m_xPBasicCodeCB
->get_active(), batch
);
129 if( m_xPBasicStgCB
->get_state_changed_from_saved())
130 officecfg::Office::Impress::Filter::Import::VBA::Save::set(m_xPBasicStgCB
->get_active(), batch
);
137 void OfaMSFilterTabPage::Reset( const SfxItemSet
* )
139 m_xWBasicCodeCB
->set_active(officecfg::Office::Writer::Filter::Import::VBA::Load::get());
140 m_xWBasicCodeCB
->set_sensitive(!officecfg::Office::Writer::Filter::Import::VBA::Load::isReadOnly());
141 m_xWBasicCodeImg
->set_visible(officecfg::Office::Writer::Filter::Import::VBA::Load::isReadOnly());
142 m_xWBasicCodeCB
->save_state();
143 m_xWBasicWbctblCB
->set_active(officecfg::Office::Writer::Filter::Import::VBA::Executable::get());
144 m_xWBasicWbctblCB
->set_sensitive(!officecfg::Office::Writer::Filter::Import::VBA::Executable::isReadOnly());
145 m_xWBasicWbctblImg
->set_visible(officecfg::Office::Writer::Filter::Import::VBA::Executable::isReadOnly());
146 m_xWBasicWbctblCB
->save_state();
147 m_xWBasicStgCB
->set_active(officecfg::Office::Writer::Filter::Import::VBA::Save::get());
148 m_xWBasicStgCB
->set_sensitive(!officecfg::Office::Writer::Filter::Import::VBA::Save::isReadOnly());
149 m_xWBasicStgImg
->set_visible(officecfg::Office::Writer::Filter::Import::VBA::Save::isReadOnly());
150 m_xWBasicStgCB
->save_state();
151 LoadWordBasicCheckHdl_Impl( *m_xWBasicCodeCB
);
153 m_xEBasicCodeCB
->set_active(officecfg::Office::Calc::Filter::Import::VBA::Load::get());
154 m_xEBasicCodeCB
->set_sensitive(!officecfg::Office::Calc::Filter::Import::VBA::Load::isReadOnly());
155 m_xEBasicCodeImg
->set_visible(officecfg::Office::Calc::Filter::Import::VBA::Load::isReadOnly());
156 m_xEBasicCodeCB
->save_state();
157 m_xEBasicExectblCB
->set_active(officecfg::Office::Calc::Filter::Import::VBA::Executable::get());
158 m_xEBasicExectblCB
->set_sensitive(!officecfg::Office::Calc::Filter::Import::VBA::Executable::isReadOnly());
159 m_xEBasicExectblImg
->set_visible(officecfg::Office::Calc::Filter::Import::VBA::Executable::isReadOnly());
160 m_xEBasicExectblCB
->save_state();
161 m_xEBasicStgCB
->set_active(officecfg::Office::Calc::Filter::Import::VBA::Save::get());
162 m_xEBasicStgCB
->set_sensitive(!officecfg::Office::Calc::Filter::Import::VBA::Save::isReadOnly());
163 m_xEBasicStgImg
->set_visible(officecfg::Office::Calc::Filter::Import::VBA::Save::isReadOnly());
164 m_xEBasicStgCB
->save_state();
165 LoadExcelBasicCheckHdl_Impl( *m_xEBasicCodeCB
);
167 m_xPBasicCodeCB
->set_active(officecfg::Office::Impress::Filter::Import::VBA::Load::get());
168 m_xPBasicCodeCB
->set_sensitive(!officecfg::Office::Impress::Filter::Import::VBA::Load::isReadOnly());
169 m_xPBasicCodeImg
->set_visible(officecfg::Office::Impress::Filter::Import::VBA::Load::isReadOnly());
170 m_xPBasicCodeCB
->save_state();
171 m_xPBasicStgCB
->set_active(officecfg::Office::Impress::Filter::Import::VBA::Save::get());
172 m_xPBasicStgCB
->set_sensitive(!officecfg::Office::Impress::Filter::Import::VBA::Save::isReadOnly());
173 m_xPBasicStgImg
->set_visible(officecfg::Office::Impress::Filter::Import::VBA::Save::isReadOnly());
174 m_xPBasicStgCB
->save_state();
177 OfaMSFilterTabPage2::OfaMSFilterTabPage2(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
178 : SfxTabPage(pPage
, pController
, u
"cui/ui/optfltrembedpage.ui"_ustr
, u
"OptFilterPage"_ustr
, &rSet
)
179 , sChgToFromMath(CuiResId(RID_CUISTR_CHG_MATH
))
180 , sChgToFromWriter(CuiResId(RID_CUISTR_CHG_WRITER
))
181 , sChgToFromCalc(CuiResId(RID_CUISTR_CHG_CALC
))
182 , sChgToFromImpress(CuiResId(RID_CUISTR_CHG_IMPRESS
))
183 , sChgToFromSmartArt(CuiResId(RID_CUISTR_CHG_SMARTART
))
184 , sChgToFromVisio(CuiResId(RID_CUISTR_CHG_VISIO
))
185 , sChgToFromPDF(CuiResId(RID_CUISTR_CHG_PDF
))
186 , m_xCheckLB(m_xBuilder
->weld_tree_view(u
"checklbcontainer"_ustr
))
187 , m_xHighlightingFT(m_xBuilder
->weld_label(u
"label5"_ustr
))
188 , m_xHighlightingRB(m_xBuilder
->weld_radio_button(u
"highlighting"_ustr
))
189 , m_xShadingRB(m_xBuilder
->weld_radio_button(u
"shading"_ustr
))
190 , m_xShadingImg(m_xBuilder
->weld_widget(u
"lockbuttonbox1"_ustr
))
191 , m_xMSOLockFileCB(m_xBuilder
->weld_check_button(u
"mso_lockfile"_ustr
))
192 , m_xMSOLockFileImg(m_xBuilder
->weld_widget(u
"lockmso_lockfile"_ustr
))
194 std::vector
<int> aWidths
196 m_xCheckLB
->get_checkbox_column_width(),
197 m_xCheckLB
->get_checkbox_column_width()
199 m_xCheckLB
->set_column_fixed_widths(aWidths
);
202 OfaMSFilterTabPage2::~OfaMSFilterTabPage2()
206 std::unique_ptr
<SfxTabPage
> OfaMSFilterTabPage2::Create( weld::Container
* pPage
, weld::DialogController
* pController
,
207 const SfxItemSet
* rAttrSet
)
209 return std::make_unique
<OfaMSFilterTabPage2
>( pPage
, pController
, *rAttrSet
);
212 OUString
OfaMSFilterTabPage2::GetAllStrings()
214 OUString sAllStrings
;
215 OUString labels
[] = { u
"label1"_ustr
, u
"label2"_ustr
, u
"label3"_ustr
, u
"label4"_ustr
, u
"label5"_ustr
, u
"label6"_ustr
};
217 for (const auto& label
: labels
)
219 if (const auto pString
= m_xBuilder
->weld_label(label
))
220 sAllStrings
+= pString
->get_label() + " ";
223 OUString radioButton
[] = { u
"highlighting"_ustr
, u
"shading"_ustr
};
225 for (const auto& radio
: radioButton
)
227 if (const auto pString
= m_xBuilder
->weld_radio_button(radio
))
228 sAllStrings
+= pString
->get_label() + " ";
231 sAllStrings
+= m_xMSOLockFileCB
->get_label() + " ";
233 return sAllStrings
.replaceAll("_", "");
240 bool (*FnIs
)(css::uno::Reference
<css::uno::XComponentContext
> const &);
241 bool (*FnIsReadOnly
)(css::uno::Reference
<css::uno::XComponentContext
> const &);
242 void (*FnSet
)(const bool& bFlag
, const std::shared_ptr
<comphelper::ConfigurationChanges
>&);
243 template <class reg
> static constexpr Functions
fromReg()
245 return { reg::get
, reg::isReadOnly
, reg::set
};
250 MSFltrPg2_CheckBoxEntries eType
;
254 template <class regLoad
, class regSave
> constexpr ChkCBoxPair
Pair(MSFltrPg2_CheckBoxEntries eType
)
256 return { eType
, Functions::fromReg
<regLoad
>(), Functions::fromReg
<regSave
>() };
258 template <class regLoad
> constexpr ChkCBoxPair
Load(MSFltrPg2_CheckBoxEntries eType
)
260 return { eType
, Functions::fromReg
<regLoad
>(), {} };
262 constexpr ChkCBoxPair aChkArr
[] = {
263 Pair
<officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath
,
264 officecfg::Office::Common::Filter::Microsoft::Export::MathToMathType
>(
265 MSFltrPg2_CheckBoxEntries::Math
),
266 Pair
<officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter
,
267 officecfg::Office::Common::Filter::Microsoft::Export::WriterToWinWord
>(
268 MSFltrPg2_CheckBoxEntries::Writer
),
269 Pair
<officecfg::Office::Common::Filter::Microsoft::Import::ExcelToCalc
,
270 officecfg::Office::Common::Filter::Microsoft::Export::CalcToExcel
>(
271 MSFltrPg2_CheckBoxEntries::Calc
),
272 Pair
<officecfg::Office::Common::Filter::Microsoft::Import::PowerPointToImpress
,
273 officecfg::Office::Common::Filter::Microsoft::Export::ImpressToPowerPoint
>(
274 MSFltrPg2_CheckBoxEntries::Impress
),
275 Load
<officecfg::Office::Common::Filter::Microsoft::Import::SmartArtToShapes
>(
276 MSFltrPg2_CheckBoxEntries::SmartArt
),
277 Load
<officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw
>(
278 MSFltrPg2_CheckBoxEntries::Visio
),
279 Load
<officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw
>(
280 MSFltrPg2_CheckBoxEntries::PDF
),
284 bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet
* )
287 auto pBatch
= comphelper::ConfigurationChanges::create();
288 for (const ChkCBoxPair
& rEntry
: aChkArr
)
290 // we loop through the list, alternating reading the first/second column,
291 // each row appears twice in the list (except for smartart and later entries, which are
293 int nEntry
= GetEntry4Type(rEntry
.eType
);
296 bool bCheck
= m_xCheckLB
->get_toggle(nEntry
, 0);
297 if (bCheck
!= (rEntry
.load
.FnIs
)(css::uno::Reference
<css::uno::XComponentContext
>()))
298 (rEntry
.load
.FnSet
)(bCheck
, pBatch
);
300 if (rEntry
.save
.FnIs
)
302 bCheck
= m_xCheckLB
->get_toggle(nEntry
, 1);
303 if (bCheck
!= (rEntry
.save
.FnIs
)(
304 css::uno::Reference
<css::uno::XComponentContext
>()))
305 (rEntry
.save
.FnSet
)(bCheck
, pBatch
);
310 if( m_xHighlightingRB
->get_state_changed_from_saved() )
312 officecfg::Office::Common::Filter::Microsoft::Export::CharBackgroundToHighlighting::set(
313 m_xHighlightingRB
->get_active(), pBatch
);
316 if (m_xMSOLockFileCB
->get_state_changed_from_saved())
318 officecfg::Office::Common::Filter::Microsoft::Import::CreateMSOLockFiles::set(
319 m_xMSOLockFileCB
->get_active(), pBatch
);
326 void OfaMSFilterTabPage2::Reset( const SfxItemSet
* )
328 m_xCheckLB
->freeze();
331 SvtModuleOptions aModuleOpt
;
333 // int the same sequence as the enums of MSFltrPg2_CheckBoxEntries
334 if (aModuleOpt
.IsMathInstalled())
335 InsertEntry( sChgToFromMath
, MSFltrPg2_CheckBoxEntries::Math
);
336 if (aModuleOpt
.IsWriterInstalled())
337 InsertEntry( sChgToFromWriter
, MSFltrPg2_CheckBoxEntries::Writer
);
338 if (aModuleOpt
.IsCalcInstalled())
339 InsertEntry( sChgToFromCalc
, MSFltrPg2_CheckBoxEntries::Calc
);
340 if (aModuleOpt
.IsImpressInstalled())
341 InsertEntry( sChgToFromImpress
, MSFltrPg2_CheckBoxEntries::Impress
);
342 InsertEntry( sChgToFromSmartArt
, MSFltrPg2_CheckBoxEntries::SmartArt
, false );
343 if (aModuleOpt
.IsDrawInstalled())
345 InsertEntry(sChgToFromVisio
, MSFltrPg2_CheckBoxEntries::Visio
, false);
346 InsertEntry(sChgToFromPDF
, MSFltrPg2_CheckBoxEntries::PDF
, false);
349 for (const ChkCBoxPair
& rArr
: aChkArr
)
351 // we loop through the list, alternating reading the first/second column,
352 // each row appears twice in the list (except for smartart and later entries, which are
354 int nEntry
= GetEntry4Type( rArr
.eType
);
357 bool bCheck
= (rArr
.load
.FnIs
)(css::uno::Reference
<css::uno::XComponentContext
>());
358 bool bReadOnly
= (rArr
.load
.FnIsReadOnly
)(
359 css::uno::Reference
<css::uno::XComponentContext
>());
360 m_xCheckLB
->set_toggle(nEntry
, bCheck
? TRISTATE_TRUE
: TRISTATE_FALSE
, 0);
361 m_xCheckLB
->set_sensitive(nEntry
, !bReadOnly
, 0);
365 bCheck
= (rArr
.save
.FnIs
)(css::uno::Reference
<css::uno::XComponentContext
>());
366 bReadOnly
= (rArr
.save
.FnIsReadOnly
)(
367 css::uno::Reference
<css::uno::XComponentContext
>());
368 m_xCheckLB
->set_toggle(nEntry
, bCheck
? TRISTATE_TRUE
: TRISTATE_FALSE
, 1);
369 m_xCheckLB
->set_sensitive(nEntry
, !bReadOnly
, 1);
375 if (officecfg::Office::Common::Filter::Microsoft::Export::CharBackgroundToHighlighting::get())
376 m_xHighlightingRB
->set_active(true);
378 m_xShadingRB
->set_active(true);
380 if (officecfg::Office::Common::Filter::Microsoft::Export::CharBackgroundToHighlighting::isReadOnly())
382 m_xHighlightingRB
->set_sensitive(false);
383 m_xShadingRB
->set_sensitive(false);
384 m_xHighlightingFT
->set_sensitive(false);
385 m_xShadingImg
->set_visible(true);
388 m_xHighlightingRB
->save_state();
390 m_xMSOLockFileCB
->set_active(officecfg::Office::Common::Filter::Microsoft::Import::CreateMSOLockFiles::get());
391 m_xMSOLockFileCB
->save_state();
392 m_xMSOLockFileCB
->set_sensitive(!officecfg::Office::Common::Filter::Microsoft::Import::CreateMSOLockFiles::isReadOnly());
393 m_xMSOLockFileImg
->set_visible(officecfg::Office::Common::Filter::Microsoft::Import::CreateMSOLockFiles::isReadOnly());
396 void OfaMSFilterTabPage2::InsertEntry( const OUString
& _rTxt
, MSFltrPg2_CheckBoxEntries _nType
)
398 InsertEntry( _rTxt
, _nType
, true );
401 void OfaMSFilterTabPage2::InsertEntry( const OUString
& _rTxt
, MSFltrPg2_CheckBoxEntries _nType
,
404 int nPos
= m_xCheckLB
->n_children();
405 m_xCheckLB
->append();
406 m_xCheckLB
->set_toggle(nPos
, TRISTATE_FALSE
, 0);
408 m_xCheckLB
->set_toggle(nPos
, TRISTATE_FALSE
, 1);
409 m_xCheckLB
->set_text(nPos
, _rTxt
, 2);
410 m_xCheckLB
->set_id(nPos
, OUString::number(static_cast<sal_Int32
>(_nType
)));
413 int OfaMSFilterTabPage2::GetEntry4Type( MSFltrPg2_CheckBoxEntries _nType
) const
415 for (int i
= 0, nEntryCount
= m_xCheckLB
->n_children(); i
< nEntryCount
; ++i
)
417 if (_nType
== static_cast<MSFltrPg2_CheckBoxEntries
>(m_xCheckLB
->get_id(i
).toInt32()))
423 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */