LibreOffice Module sw (master) 1
optcomp.cxx
Go to the documentation of this file.
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 <optcomp.hxx>
21
22#include <cmdid.h>
23#include <docsh.hxx>
24#include <uiitems.hxx>
25#include <view.hxx>
26#include <wrtsh.hxx>
27
28#include <vcl/svapp.hxx>
29#include <vcl/weld.hxx>
30#include <sfx2/docfilt.hxx>
31#include <sfx2/fcontnr.hxx>
33#include <vector>
36#include <officecfg/Office/Compatibility.hxx>
37#include <osl/diagnose.h>
38
39using namespace ::com::sun::star::beans;
40using namespace ::com::sun::star::document;
41using namespace ::com::sun::star::uno;
42using namespace ::std;
43
45{
46 std::vector< SvtCompatibilityEntry > m_aList;
47};
48
50 : SfxTabPage(pPage, pController, "modules/swriter/ui/optcompatpage.ui", "OptCompatPage", &rSet)
51 , m_pWrtShell(nullptr)
53 , m_nSavedOptions(0)
54 , m_bSavedMSFormsMenuOption(false)
55 , m_xMain(m_xBuilder->weld_frame("compatframe"))
56 , m_xGlobalOptionsFrame(m_xBuilder->weld_frame("globalcompatframe"))
57 , m_xFormattingLB(m_xBuilder->weld_combo_box("format"))
58 , m_xGlobalOptionsLB(m_xBuilder->weld_combo_box("globaloptions"))
59 , m_xOptionsLB(m_xBuilder->weld_tree_view("options"))
60 , m_xGlobalOptionsCLB(m_xBuilder->weld_tree_view("globaloptioncheckbox"))
61 , m_xDefaultPB(m_xBuilder->weld_button("default"))
62{
63 m_xOptionsLB->enable_toggle_buttons(weld::ColumnToggleType::Check);
65
66 int nPos = 0;
67 for (int i = static_cast<int>(SvtCompatibilityEntry::Index::Module) + 1;
68 i < static_cast<int>(SvtCompatibilityEntry::Index::INVALID) - 1; // omit AddTableLineSpacing
69 ++i)
70 {
71 int nCoptIdx = i - 2; /* Do not consider "Name" & "Module" indexes */
72
73 const OUString sEntry = m_xFormattingLB->get_text(nCoptIdx);
74 m_xOptionsLB->append();
75 m_xOptionsLB->set_toggle(nPos, TRISTATE_FALSE);
76 m_xOptionsLB->set_text(nPos, sEntry, 0);
77 ++nPos;
78 }
79
80 m_sUserEntry = m_xFormattingLB->get_text(m_xFormattingLB->get_count() - 1);
81
82 m_xFormattingLB->clear();
83
84 // Set MSOCompatibleFormsMenu entry attributes
85 const bool bReadOnly = officecfg::Office::Compatibility::View::MSCompatibleFormsMenu::isReadOnly();
86 m_xGlobalOptionsCLB->set_sensitive(!bReadOnly);
87
88 m_xGlobalOptionsCLB->append();
90 m_xGlobalOptionsCLB->set_toggle(0, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE);
91 m_xGlobalOptionsCLB->set_text(0, m_xGlobalOptionsLB->get_text(0), 0);
92
93 m_xGlobalOptionsLB->clear();
94
95 // tdf#125799, we let only the doc options grow/shrink but give this one more than its bare
96 // min request height because there's only one row in it and that looks somewhat abrupt
97 m_xGlobalOptionsCLB->set_size_request(-1, m_xGlobalOptionsCLB->get_preferred_size().Height() * 2);
98
100
101 // set handler
102 m_xFormattingLB->connect_changed( LINK( this, SwCompatibilityOptPage, SelectHdl ) );
103 m_xDefaultPB->connect_clicked( LINK( this, SwCompatibilityOptPage, UseAsDefaultHdl ) );
104}
105
107{
108}
109
110static sal_uInt32 convertBools2Ulong_Impl
111(
112 bool _bAddSpacing,
113 bool _bAddSpacingAtPages,
114 bool _bUseOurTabStops,
115 bool _bNoExtLeading,
116 bool _bUseLineSpacing,
117 bool _bAddTableSpacing,
118 bool _bAddTableLineSpacing,
119 bool _bUseObjPos,
120 bool _bUseOurTextWrapping,
121 bool _bConsiderWrappingStyle,
122 bool _bExpandWordSpace,
123 bool _bProtectForm,
124 bool _bMsWordCompTrailingBlanks,
125 bool bSubtractFlysAnchoredAtFlys,
126 bool bEmptyDbFieldHidesPara
127)
128{
129 sal_uInt32 nRet = 0;
130 sal_uInt32 nSetBit = 1;
131
132 if ( _bAddSpacing )
133 nRet |= nSetBit;
134 nSetBit = nSetBit << 1;
135 if ( _bAddSpacingAtPages )
136 nRet |= nSetBit;
137 nSetBit = nSetBit << 1;
138 if ( _bUseOurTabStops )
139 nRet |= nSetBit;
140 nSetBit = nSetBit << 1;
141 if ( _bNoExtLeading )
142 nRet |= nSetBit;
143 nSetBit = nSetBit << 1;
144 if ( _bUseLineSpacing )
145 nRet |= nSetBit;
146 nSetBit = nSetBit << 1;
147 if ( _bAddTableSpacing )
148 nRet |= nSetBit;
149 nSetBit = nSetBit << 1;
150 if (_bAddTableLineSpacing)
151 nRet |= nSetBit;
152 nSetBit = nSetBit << 1;
153 if ( _bUseObjPos )
154 nRet |= nSetBit;
155 nSetBit = nSetBit << 1;
156 if ( _bUseOurTextWrapping )
157 nRet |= nSetBit;
158 nSetBit = nSetBit << 1;
159 if ( _bConsiderWrappingStyle )
160 nRet |= nSetBit;
161 nSetBit = nSetBit << 1;
162 if ( _bExpandWordSpace )
163 nRet |= nSetBit;
164 nSetBit = nSetBit << 1;
165 if ( _bProtectForm )
166 nRet |= nSetBit;
167 nSetBit = nSetBit << 1;
168 if ( _bMsWordCompTrailingBlanks )
169 nRet |= nSetBit;
170 nSetBit = nSetBit << 1;
171 if (bSubtractFlysAnchoredAtFlys)
172 nRet |= nSetBit;
173 nSetBit = nSetBit << 1;
174 if (bEmptyDbFieldHidesPara)
175 nRet |= nSetBit;
176
177 return nRet;
178}
179
181{
182 // init objectshell and detect document name
183 OUString sDocTitle;
184 SfxObjectShell* pObjShell = nullptr;
185 if ( const SwPtrItem* pItem = rSet.GetItemIfSet( FN_PARAM_WRTSHELL, false ) )
186 m_pWrtShell = static_cast<SwWrtShell*>(pItem->GetValue());
187 if ( m_pWrtShell )
188 {
189 pObjShell = m_pWrtShell->GetView().GetDocShell();
190 if ( pObjShell )
191 sDocTitle = pObjShell->GetTitle();
192 }
193 else
194 {
195 m_xMain->set_sensitive(false);
196 m_xGlobalOptionsFrame->set_sensitive(false);
197 }
198 const OUString& rText = m_xMain->get_label();
199 m_xMain->set_label(rText.replaceAll("%DOCNAME", sDocTitle));
200
201 // loading file formats
202 const std::vector< SvtCompatibilityEntry > aList = m_aConfigItem.GetList();
203
204 for ( const SvtCompatibilityEntry& rEntry : aList )
205 {
206 const OUString sEntryName = rEntry.getValue<OUString>( SvtCompatibilityEntry::Index::Name );
207 const bool bIsUserEntry = ( sEntryName == SvtCompatibilityEntry::USER_ENTRY_NAME );
208
209 m_pImpl->m_aList.push_back( rEntry );
210
211 if ( rEntry.isDefaultEntry() )
212 continue;
213
214 OUString sNewEntry;
215 if ( bIsUserEntry )
216 sNewEntry = m_sUserEntry;
217
218 else if ( pObjShell && !sEntryName.isEmpty() )
219 {
220 SfxFilterContainer* pFacCont = pObjShell->GetFactory().GetFilterContainer();
221 std::shared_ptr<const SfxFilter> pFilter = pFacCont->GetFilter4FilterName( sEntryName );
222 if ( pFilter )
223 sNewEntry = pFilter->GetUIName();
224 }
225
226 if ( sNewEntry.isEmpty() )
227 sNewEntry = sEntryName;
228
229 sal_uInt32 nOptions = convertBools2Ulong_Impl(
230 rEntry.getValue<bool>( SvtCompatibilityEntry::Index::AddSpacing ),
232 rEntry.getValue<bool>( SvtCompatibilityEntry::Index::UseOurTabStops ),
233 rEntry.getValue<bool>( SvtCompatibilityEntry::Index::NoExtLeading ),
234 rEntry.getValue<bool>( SvtCompatibilityEntry::Index::UseLineSpacing ),
235 rEntry.getValue<bool>( SvtCompatibilityEntry::Index::AddTableSpacing ),
240 rEntry.getValue<bool>( SvtCompatibilityEntry::Index::ExpandWordSpace ),
241 rEntry.getValue<bool>( SvtCompatibilityEntry::Index::ProtectForm ),
245 m_xFormattingLB->append(OUString::number(nOptions), sNewEntry);
246 }
247}
248
250{
251 sal_uInt32 nOptions = m_xFormattingLB->get_active_id().toUInt32();
252 SetCurrentOptions(nOptions);
253}
254
256{
257 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/querydefaultcompatdialog.ui"));
258 std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("QueryDefaultCompatDialog"));
259 if (xQueryBox->run() != RET_YES)
260 return;
261
262 auto pItem = std::find_if(m_pImpl->m_aList.begin(), m_pImpl->m_aList.end(),
263 [](const SvtCompatibilityEntry& rItem) { return rItem.isDefaultEntry(); });
264 if (pItem != m_pImpl->m_aList.end())
265 {
266 const sal_Int32 nCount = m_xOptionsLB->n_children();
267 for ( sal_Int32 i = 0; i < nCount; ++i )
268 {
269 bool bChecked = m_xOptionsLB->get_toggle(i);
270
271 int nCoptIdx = i + 2; /* Consider "Name" & "Module" indexes */
272 pItem->setValue<bool>( SvtCompatibilityEntry::Index(nCoptIdx), bChecked );
274 {
275 bool const isLineSpacing = m_xOptionsLB->get_toggle(i) == TRISTATE_TRUE;
276 pItem->setValue<bool>(SvtCompatibilityEntry::Index::AddTableLineSpacing, isLineSpacing);
277 }
278 else
279 {
280 assert(m_xOptionsLB->get_toggle(i) != TRISTATE_INDET);
281 }
282 }
283 }
284
285 WriteOptions();
286}
287
289{
290 const int nCount = m_xOptionsLB->n_children();
291 OSL_ENSURE( nCount <= 32, "SwCompatibilityOptPage::Reset(): entry overflow" );
292 for (int i = 0; i < nCount; ++i)
293 {
294 bool bChecked = ( ( nOptions & 0x00000001 ) == 0x00000001 );
297 { // hack: map 2 bools to 1 tristate
298 nOptions = nOptions >> 1;
299 if (value == TRISTATE_TRUE
300 && (nOptions & 0x00000001) != 0x00000001) // ADD_PARA_LINE_SPACING_TO_TABLE_CELLS
301 {
302 value = TRISTATE_INDET; // 3 values possible here
303 }
304 }
305 m_xOptionsLB->set_toggle(i, value);
306 nOptions = nOptions >> 1;
307 }
308}
309
311{
312 sal_uInt32 nRet = 0;
313 if ( m_pWrtShell )
314 {
315 const IDocumentSettingAccess& rIDocumentSettingAccess = m_pWrtShell->getIDocumentSettingAccess();
317 rIDocumentSettingAccess.get( DocumentSettingId::PARA_SPACE_MAX ),
318 rIDocumentSettingAccess.get( DocumentSettingId::PARA_SPACE_MAX_AT_PAGES ),
319 !rIDocumentSettingAccess.get( DocumentSettingId::TAB_COMPAT ),
320 !rIDocumentSettingAccess.get( DocumentSettingId::ADD_EXT_LEADING ),
321 rIDocumentSettingAccess.get( DocumentSettingId::OLD_LINE_SPACING ),
324 rIDocumentSettingAccess.get( DocumentSettingId::USE_FORMER_OBJECT_POS ),
325 rIDocumentSettingAccess.get( DocumentSettingId::USE_FORMER_TEXT_WRAPPING ),
328 rIDocumentSettingAccess.get( DocumentSettingId::PROTECT_FORM ),
329 rIDocumentSettingAccess.get( DocumentSettingId::MS_WORD_COMP_TRAILING_BLANKS ),
330 rIDocumentSettingAccess.get( DocumentSettingId::SUBTRACT_FLYS ),
331 rIDocumentSettingAccess.get( DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA ) );
332 }
333 return nRet;
334}
335
337{
339 for ( const auto& rItem : m_pImpl->m_aList )
341}
342
343std::unique_ptr<SfxTabPage> SwCompatibilityOptPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
344{
345 return std::make_unique<SwCompatibilityOptPage>(pPage, pController, *rAttrSet);
346}
347
349{
350 bool bModified = false;
351 if ( m_pWrtShell )
352 {
353 sal_uInt32 nSavedOptions = m_nSavedOptions;
354 const int nCount = m_xOptionsLB->n_children();
355 OSL_ENSURE( nCount <= 32, "SwCompatibilityOptPage::Reset(): entry overflow" );
356
357 for (int i = 0; i < nCount; ++i)
358 {
359 TriState const current = m_xOptionsLB->get_toggle(i);
360 TriState saved = ((nSavedOptions & 0x00000001) == 0x00000001) ? TRISTATE_TRUE : TRISTATE_FALSE;
362 { // hack: map 2 bools to 1 tristate
363 nSavedOptions = nSavedOptions >> 1;
364 if (saved == TRISTATE_TRUE
365 && ((nSavedOptions & 0x00000001) != 0x00000001))
366 {
367 saved = TRISTATE_INDET;
368 }
369 }
370 if (current != saved)
371 {
372 bool const bChecked(current != TRISTATE_FALSE);
373 assert(current != TRISTATE_INDET); // can't *change* it to that
374 int nCoptIdx = i + 2; /* Consider "Name" & "Module" indexes */
375 switch ( SvtCompatibilityEntry::Index(nCoptIdx) )
376 {
378 m_pWrtShell->SetParaSpaceMax( bChecked );
379 break;
380
383 break;
384
386 m_pWrtShell->SetTabCompat( !bChecked );
387 break;
388
390 m_pWrtShell->SetAddExtLeading( !bChecked );
391 break;
392
395 break;
396
399 break;
400
403 break;
404
407 break;
408
411 break;
412
415 break;
416
418 m_pWrtShell->SetProtectForm( bChecked );
419 break;
420
423 break;
424
427 break;
428
431 break;
432
433 default:
434 break;
435 }
436 bModified = true;
437 }
438
439 nSavedOptions = nSavedOptions >> 1;
440 }
441 }
442
443 if ( bModified )
444 WriteOptions();
445
446 bool bNewMSFormsMenuOption = m_xGlobalOptionsCLB->get_toggle(0);
447 if (m_bSavedMSFormsMenuOption != bNewMSFormsMenuOption)
448 {
449 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
450 officecfg::Office::Compatibility::View::MSCompatibleFormsMenu::set(bNewMSFormsMenuOption, batch);
451 batch->commit();
452
453 m_bSavedMSFormsMenuOption = bNewMSFormsMenuOption;
454 bModified = true;
455
456 // Show a message about that the option needs a restart to be applied
457 {
458 SolarMutexGuard aGuard;
461 {
462 GetDialogController()->response(RET_OK);
463 }
464 }
465 }
466
467 return bModified;
468}
469
471{
472 m_xOptionsLB->select(0);
473
474 sal_uInt32 nOptions = GetDocumentOptions();
475 SetCurrentOptions( nOptions );
476 m_nSavedOptions = nOptions;
477
480}
481
482/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ CONSIDER_WRAP_ON_OBJECT_POSITION
@ DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK
@ ADD_PARA_LINE_SPACING_TO_TABLE_CELLS
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
Provides access to settings of a document.
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
std::shared_ptr< const SfxFilter > GetFilter4FilterName(const OUString &rName, SfxFilterFlags nMust=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
SfxFilterContainer * GetFilterContainer() const
virtual SfxObjectFactory & GetFactory() const=0
OUString GetTitle(sal_uInt16 nMaxLen=0) const
SfxOkDialogController * GetDialogController() const
weld::Window * GetFrameWeld() const
static constexpr OUStringLiteral USER_ENTRY_NAME
std::vector< SvtCompatibilityEntry > GetList() const
void AppendItem(const SvtCompatibilityEntry &aItem)
std::unique_ptr< weld::ComboBox > m_xGlobalOptionsLB
Definition: optcomp.hxx:49
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
Definition: optcomp.cxx:343
std::unique_ptr< weld::TreeView > m_xGlobalOptionsCLB
Definition: optcomp.hxx:51
std::unique_ptr< weld::Frame > m_xGlobalOptionsFrame
Definition: optcomp.hxx:47
SvtCompatibilityOptions m_aConfigItem
Definition: optcomp.hxx:34
void SetCurrentOptions(sal_uInt32 nOptions)
Definition: optcomp.cxx:288
sal_uInt32 m_nSavedOptions
Definition: optcomp.hxx:42
sal_uInt32 GetDocumentOptions() const
Definition: optcomp.cxx:310
bool m_bSavedMSFormsMenuOption
Definition: optcomp.hxx:43
std::unique_ptr< weld::Frame > m_xMain
Definition: optcomp.hxx:46
SwCompatibilityOptPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optcomp.cxx:49
void InitControls(const SfxItemSet &rSet)
Definition: optcomp.cxx:180
std::unique_ptr< weld::TreeView > m_xOptionsLB
Definition: optcomp.hxx:50
std::unique_ptr< weld::Button > m_xDefaultPB
Definition: optcomp.hxx:52
SwWrtShell * m_pWrtShell
Definition: optcomp.hxx:38
std::unique_ptr< weld::ComboBox > m_xFormattingLB
Definition: optcomp.hxx:48
virtual ~SwCompatibilityOptPage() override
Definition: optcomp.cxx:106
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optcomp.cxx:348
virtual void Reset(const SfxItemSet *rSet) override
Definition: optcomp.cxx:470
std::unique_ptr< SwCompatibilityOptPage_Impl > m_pImpl
Definition: optcomp.hxx:40
void SetProtectForm(bool _bProtectForm)
Definition: viewsh.cxx:1003
void SetParaSpaceMax(bool bNew)
Definition: viewsh.cxx:863
void SetUseFormerTextWrapping(bool _bUseFormerTextWrapping)
Definition: viewsh.cxx:978
const IDocumentSettingAccess & getIDocumentSettingAccess() const
Provides access to the document setting interface.
Definition: viewsh.cxx:2803
void SetDoNotJustifyLinesWithManualBreak(bool _bDoNotJustifyLinesWithManualBreak)
Definition: viewsh.cxx:991
void SetUseFormerLineSpacing(bool _bUseFormerLineSpacing)
Sets if former formatting of text lines with proportional line spacing should used.
Definition: viewsh.cxx:938
void SetUseFormerObjectPositioning(bool _bUseFormerObjPos)
Sets IDocumentSettingAccess if former object positioning should be used.
Definition: viewsh.cxx:955
void SetParaSpaceMaxAtPages(bool bNew)
Definition: viewsh.cxx:875
void SetAddExtLeading(bool bNew)
Definition: viewsh.cxx:899
void SetConsiderWrapOnObjPos(bool _bConsiderWrapOnObjPos)
Definition: viewsh.cxx:967
void SetTabCompat(bool bNew)
Definition: viewsh.cxx:887
void SetMsWordCompTrailingBlanks(bool _bMsWordCompTrailingBlanks)
Definition: viewsh.cxx:1009
void SetSubtractFlysAnchoredAtFlys(bool bSubtractFlysAnchoredAtFlys)
Definition: viewsh.cxx:1021
void SetAddParaSpacingToTableCells(bool _bAddParaSpacingToTableCells)
Sets if paragraph and table spacing is added at bottom of table cells.
Definition: viewsh.cxx:918
void SetEmptyDbFieldHidesPara(bool bEmptyDbFieldHidesPara)
Definition: viewsh.cxx:1027
SwDocShell * GetDocShell()
Definition: view.cxx:1160
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
const SwView & GetView() const
Definition: wrtsh.hxx:438
static std::shared_ptr< ConfigurationChanges > create()
#define FN_PARAM_WRTSHELL
Definition: cmdid.h:810
Any value
int nCount
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
Definition: dialoghelp.cxx:19
bool bReadOnly
TriState
TRISTATE_FALSE
TRISTATE_INDET
TRISTATE_TRUE
sal_uInt16 nPos
Reference< XComponentContext > getProcessComponentContext()
int i
RESTART_REASON_MSCOMPATIBLE_FORMS_MENU
SVT_DLLPUBLIC bool executeRestartDialog(css::uno::Reference< css::uno::XComponentContext > const &context, weld::Window *parent, RestartReason reason)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
IMPL_LINK_NOARG(SwCompatibilityOptPage, SelectHdl, weld::ComboBox &, void)
Definition: optcomp.cxx:249
static sal_uInt32 convertBools2Ulong_Impl(bool _bAddSpacing, bool _bAddSpacingAtPages, bool _bUseOurTabStops, bool _bNoExtLeading, bool _bUseLineSpacing, bool _bAddTableSpacing, bool _bAddTableLineSpacing, bool _bUseObjPos, bool _bUseOurTextWrapping, bool _bConsiderWrappingStyle, bool _bExpandWordSpace, bool _bProtectForm, bool _bMsWordCompTrailingBlanks, bool bSubtractFlysAnchoredAtFlys, bool bEmptyDbFieldHidesPara)
Definition: optcomp.cxx:111
static SfxItemSet & rSet
std::vector< SvtCompatibilityEntry > m_aList
Definition: optcomp.cxx:46
RET_OK
RET_YES