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 <swmodule.hxx>
25 #include <swtypes.hxx>
26 #include <uiitems.hxx>
27 #include <view.hxx>
28 #include <wrtsh.hxx>
29 
30 #include <globals.hrc>
31 #include <unotools/configmgr.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/weld.hxx>
34 #include <sfx2/docfile.hxx>
35 #include <sfx2/docfilt.hxx>
36 #include <sfx2/fcontnr.hxx>
37 #include <vcl/treelistentry.hxx>
39 #include <vector>
42 #include <officecfg/Office/Compatibility.hxx>
43 #include <vcl/svlbitm.hxx>
44 
45 #include <com/sun/star/beans/PropertyValue.hpp>
46 
47 using namespace ::com::sun::star::beans;
48 using namespace ::com::sun::star::document;
49 using namespace ::com::sun::star::uno;
50 using namespace ::std;
51 
53 {
54  std::vector< SvtCompatibilityEntry > m_aList;
55 };
56 
58  : SfxTabPage(pParent, "modules/swriter/ui/optcompatpage.ui", "OptCompatPage", &rSet)
59  , m_pWrtShell(nullptr)
60  , m_pImpl(new SwCompatibilityOptPage_Impl)
61  , m_nSavedOptions(0)
62  , m_bSavedMSFormsMenuOption(false)
63  , m_xMain(m_xBuilder->weld_frame("compatframe"))
64  , m_xGlobalOptionsFrame(m_xBuilder->weld_frame("globalcompatframe"))
65  , m_xFormattingLB(m_xBuilder->weld_combo_box("format"))
66  , m_xGlobalOptionsLB(m_xBuilder->weld_combo_box("globaloptions"))
67  , m_xOptionsLB(m_xBuilder->weld_tree_view("options"))
68  , m_xGlobalOptionsCLB(m_xBuilder->weld_tree_view("globaloptioncheckbox"))
69  , m_xDefaultPB(m_xBuilder->weld_button("default"))
70 {
71  std::vector<int> aWidths;
72  aWidths.push_back(m_xOptionsLB->get_checkbox_column_width());
73  m_xOptionsLB->set_column_fixed_widths(aWidths);
74  m_xGlobalOptionsCLB->set_column_fixed_widths(aWidths);
75 
76  int nPos = 0;
77  for ( int i = static_cast<int>(SvtCompatibilityEntry::Index::Module) + 1; i < static_cast<int>(SvtCompatibilityEntry::Index::INVALID); ++i )
78  {
79  int nCoptIdx = i - 2; /* Do not consider "Name" & "Module" indexes */
80 
81  const OUString sEntry = m_xFormattingLB->get_text(nCoptIdx);
82  m_xOptionsLB->append();
83  m_xOptionsLB->set_toggle(nPos, TRISTATE_FALSE, 0);
84  m_xOptionsLB->set_text(nPos, sEntry, 1);
85  ++nPos;
86  }
87 
88  m_sUserEntry = m_xFormattingLB->get_text(m_xFormattingLB->get_count() - 1);
89 
90  m_xFormattingLB->clear();
91 
92  // Set MSOCompatibleFormsMenu entry attributes
93  const bool bReadOnly = officecfg::Office::Compatibility::View::MSCompatibleFormsMenu::isReadOnly();
94  m_xGlobalOptionsCLB->set_sensitive(!bReadOnly);
95 
96  m_xGlobalOptionsCLB->append();
97  const bool bChecked = m_aViewConfigItem.HasMSOCompatibleFormsMenu();
98  m_xGlobalOptionsCLB->set_toggle(0, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
99  m_xGlobalOptionsCLB->set_text(0, m_xGlobalOptionsLB->get_text(0), 1);
100 
101  m_xGlobalOptionsLB->clear();
102 
103  // tdf#125799, we let only the doc options grow/shrink but give this one more than its bare
104  // min request height because there's only one row in it and that looks somewhat abrupt
105  m_xGlobalOptionsCLB->set_size_request(-1, m_xGlobalOptionsCLB->get_preferred_size().Height() * 2);
106 
107  InitControls( rSet );
108 
109  // set handler
110  m_xFormattingLB->connect_changed( LINK( this, SwCompatibilityOptPage, SelectHdl ) );
111  m_xDefaultPB->connect_clicked( LINK( this, SwCompatibilityOptPage, UseAsDefaultHdl ) );
112 }
113 
115 {
116 }
117 
119 (
120  bool _bUsePrtMetrics,
121  bool _bAddSpacing,
122  bool _bAddSpacingAtPages,
123  bool _bUseOurTabStops,
124  bool _bNoExtLeading,
125  bool _bUseLineSpacing,
126  bool _bAddTableSpacing,
127  bool _bUseObjPos,
128  bool _bUseOurTextWrapping,
129  bool _bConsiderWrappingStyle,
130  bool _bExpandWordSpace,
131  bool _bProtectForm,
132  bool _bMsWordCompTrailingBlanks,
133  bool bSubtractFlysAnchoredAtFlys,
134  bool bEmptyDbFieldHidesPara
135 )
136 {
137  sal_uLong nRet = 0;
138  sal_uLong nSetBit = 1;
139 
140  if ( _bUsePrtMetrics )
141  nRet |= nSetBit;
142  nSetBit = nSetBit << 1;
143  if ( _bAddSpacing )
144  nRet |= nSetBit;
145  nSetBit = nSetBit << 1;
146  if ( _bAddSpacingAtPages )
147  nRet |= nSetBit;
148  nSetBit = nSetBit << 1;
149  if ( _bUseOurTabStops )
150  nRet |= nSetBit;
151  nSetBit = nSetBit << 1;
152  if ( _bNoExtLeading )
153  nRet |= nSetBit;
154  nSetBit = nSetBit << 1;
155  if ( _bUseLineSpacing )
156  nRet |= nSetBit;
157  nSetBit = nSetBit << 1;
158  if ( _bAddTableSpacing )
159  nRet |= nSetBit;
160  nSetBit = nSetBit << 1;
161  if ( _bUseObjPos )
162  nRet |= nSetBit;
163  nSetBit = nSetBit << 1;
164  if ( _bUseOurTextWrapping )
165  nRet |= nSetBit;
166  nSetBit = nSetBit << 1;
167  if ( _bConsiderWrappingStyle )
168  nRet |= nSetBit;
169  nSetBit = nSetBit << 1;
170  if ( _bExpandWordSpace )
171  nRet |= nSetBit;
172  nSetBit = nSetBit << 1;
173  if ( _bProtectForm )
174  nRet |= nSetBit;
175  nSetBit = nSetBit << 1;
176  if ( _bMsWordCompTrailingBlanks )
177  nRet |= nSetBit;
178  nSetBit = nSetBit << 1;
179  if (bSubtractFlysAnchoredAtFlys)
180  nRet |= nSetBit;
181  nSetBit = nSetBit << 1;
182  if (bEmptyDbFieldHidesPara)
183  nRet |= nSetBit;
184 
185  return nRet;
186 }
187 
189 {
190  // init objectshell and detect document name
191  OUString sDocTitle;
192  const SfxPoolItem* pItem = nullptr;
193  SfxObjectShell* pObjShell = nullptr;
194  if ( SfxItemState::SET == rSet.GetItemState( FN_PARAM_WRTSHELL, false, &pItem ) )
195  m_pWrtShell = static_cast<SwWrtShell*>(static_cast<const SwPtrItem*>(pItem)->GetValue());
196  if ( m_pWrtShell )
197  {
198  pObjShell = m_pWrtShell->GetView().GetDocShell();
199  if ( pObjShell )
200  sDocTitle = pObjShell->GetTitle();
201  }
202  else
203  {
204  m_xMain->set_sensitive(false);
205  m_xGlobalOptionsFrame->set_sensitive(false);
206  }
207  const OUString& rText = m_xMain->get_label();
208  m_xMain->set_label(rText.replaceAll("%DOCNAME", sDocTitle));
209 
210  // loading file formats
211  Sequence< Sequence< PropertyValue > > aList = m_aConfigItem.GetList();
212 
213  SvtCompatibilityEntry aEntry;
215 
216  for ( const Sequence< PropertyValue >& rEntry : aList )
217  {
218  for ( const PropertyValue& aValue : rEntry )
219  {
220  aEntry.setValue( SvtCompatibilityEntry::getIndex(aValue.Name), aValue.Value );
221  }
222 
223  const OUString sEntryName = aEntry.getValue<OUString>( SvtCompatibilityEntry::Index::Name );
224 
225  const bool bIsUserEntry = ( sEntryName == SvtCompatibilityEntry::getUserEntryName() );
226  const bool bIsDefaultEntry = ( sEntryName == SvtCompatibilityEntry::getDefaultEntryName() );
227 
228  aEntry.setDefaultEntry( bIsDefaultEntry );
229 
230  m_pImpl->m_aList.push_back( aEntry );
231 
232  if ( aEntry.isDefaultEntry() )
233  continue;
234 
235  OUString sNewEntry;
236  if ( bIsUserEntry )
237  sNewEntry = m_sUserEntry;
238 
239  else if ( pObjShell && !sEntryName.isEmpty() )
240  {
241  SfxFilterContainer* pFacCont = pObjShell->GetFactory().GetFilterContainer();
242  std::shared_ptr<const SfxFilter> pFilter = pFacCont->GetFilter4FilterName( sEntryName );
243  if ( pFilter )
244  sNewEntry = pFilter->GetUIName();
245  }
246 
247  if ( sNewEntry.isEmpty() )
248  sNewEntry = sEntryName;
249 
250  sal_uInt32 nOptions = convertBools2Ulong_Impl(
261  aEntry.getValue<bool>( SvtCompatibilityEntry::Index::ExpandWordSpace ),
266  m_xFormattingLB->append(OUString::number(nOptions), sNewEntry);
267  }
268 }
269 
271 {
272  sal_uInt32 nOptions = m_xFormattingLB->get_active_id().toUInt32();
273  SetCurrentOptions(nOptions);
274 }
275 
277 {
278  std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDialogFrameWeld(), "modules/swriter/ui/querydefaultcompatdialog.ui"));
279  std::unique_ptr<weld::MessageDialog> xQueryBox(xBuilder->weld_message_dialog("QueryDefaultCompatDialog"));
280  if (xQueryBox->run() == RET_YES)
281  {
282  auto pItem = std::find_if(m_pImpl->m_aList.begin(), m_pImpl->m_aList.end(),
283  [](const SvtCompatibilityEntry& rItem) { return rItem.isDefaultEntry(); });
284  if (pItem != m_pImpl->m_aList.end())
285  {
286  const sal_Int32 nCount = m_xOptionsLB->n_children();
287  for ( sal_Int32 i = 0; i < nCount; ++i )
288  {
289  bool bChecked = m_xOptionsLB->get_toggle(i, 0);
290 
291  int nCoptIdx = i + 2; /* Consider "Name" & "Module" indexes */
292  pItem->setValue<bool>( SvtCompatibilityEntry::Index(nCoptIdx), bChecked );
293  }
294  }
295 
296  WriteOptions();
297  }
298 }
299 
301 {
302  const int nCount = m_xOptionsLB->n_children();
303  OSL_ENSURE( nCount <= 32, "SwCompatibilityOptPage::Reset(): entry overflow" );
304  for (int i = 0; i < nCount; ++i)
305  {
306  bool bChecked = ( ( nOptions & 0x00000001 ) == 0x00000001 );
307  m_xOptionsLB->set_toggle(i, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE, 0);
308  nOptions = nOptions >> 1;
309  }
310 }
311 
313 {
314  sal_uLong nRet = 0;
315  if ( m_pWrtShell )
316  {
317  const IDocumentSettingAccess& rIDocumentSettingAccess = m_pWrtShell->getIDocumentSettingAccess();
319  !rIDocumentSettingAccess.get( DocumentSettingId::USE_VIRTUAL_DEVICE ),
320  rIDocumentSettingAccess.get( DocumentSettingId::PARA_SPACE_MAX ),
321  rIDocumentSettingAccess.get( DocumentSettingId::PARA_SPACE_MAX_AT_PAGES ),
322  !rIDocumentSettingAccess.get( DocumentSettingId::TAB_COMPAT ),
323  !rIDocumentSettingAccess.get( DocumentSettingId::ADD_EXT_LEADING ),
324  rIDocumentSettingAccess.get( DocumentSettingId::OLD_LINE_SPACING ),
325  rIDocumentSettingAccess.get( DocumentSettingId::ADD_PARA_SPACING_TO_TABLE_CELLS ),
326  rIDocumentSettingAccess.get( DocumentSettingId::USE_FORMER_OBJECT_POS ),
327  rIDocumentSettingAccess.get( DocumentSettingId::USE_FORMER_TEXT_WRAPPING ),
328  rIDocumentSettingAccess.get( DocumentSettingId::CONSIDER_WRAP_ON_OBJECT_POSITION ),
330  rIDocumentSettingAccess.get( DocumentSettingId::PROTECT_FORM ),
331  rIDocumentSettingAccess.get( DocumentSettingId::MS_WORD_COMP_TRAILING_BLANKS ),
332  rIDocumentSettingAccess.get( DocumentSettingId::SUBTRACT_FLYS ),
333  rIDocumentSettingAccess.get( DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA ) );
334  }
335  return nRet;
336 }
337 
339 {
341  for ( const auto& rItem : m_pImpl->m_aList )
342  m_aConfigItem.AppendItem(rItem);
343 }
344 
346 {
347  return VclPtr<SwCompatibilityOptPage>::Create( pParent, *rAttrSet );
348 }
349 
351 {
352  bool bModified = false;
353  if ( m_pWrtShell )
354  {
355  sal_uLong nSavedOptions = m_nSavedOptions;
356  const int nCount = m_xOptionsLB->n_children();
357  OSL_ENSURE( nCount <= 32, "SwCompatibilityOptPage::Reset(): entry overflow" );
358 
359  for (int i = 0; i < nCount; ++i)
360  {
361  bool bChecked = m_xOptionsLB->get_toggle(i, 0) == TRISTATE_TRUE;
362  bool bSavedChecked = ( ( nSavedOptions & 0x00000001 ) == 0x00000001 );
363  if ( bChecked != bSavedChecked )
364  {
365  int nCoptIdx = i + 2; /* Consider "Name" & "Module" indexes */
366  switch ( SvtCompatibilityEntry::Index(nCoptIdx) )
367  {
369  m_pWrtShell->SetUseVirDev( !bChecked );
370  break;
371 
373  m_pWrtShell->SetParaSpaceMax( bChecked );
374  break;
375 
377  m_pWrtShell->SetParaSpaceMaxAtPages( bChecked );
378  break;
379 
381  m_pWrtShell->SetTabCompat( !bChecked );
382  break;
383 
385  m_pWrtShell->SetAddExtLeading( !bChecked );
386  break;
387 
390  break;
391 
394  break;
395 
398  break;
399 
402  break;
403 
406  break;
407 
410  break;
411 
413  m_pWrtShell->SetProtectForm( bChecked );
414  break;
415 
418  break;
419 
422  break;
423 
426  break;
427 
428  default:
429  break;
430  }
431  bModified = true;
432  }
433 
434  nSavedOptions = nSavedOptions >> 1;
435  }
436  }
437 
438  if ( bModified )
439  WriteOptions();
440 
441  bool bNewMSFormsMenuOption = m_xGlobalOptionsCLB->get_toggle(0, 0);
442  if (m_bSavedMSFormsMenuOption != bNewMSFormsMenuOption)
443  {
444  m_aViewConfigItem.SetMSOCompatibleFormsMenu(bNewMSFormsMenuOption);
445  m_bSavedMSFormsMenuOption = bNewMSFormsMenuOption;
446  bModified = true;
447 
448  // Show a message about that the option needs a restart to be applied
449  {
450  SolarMutexGuard aGuard;
453  {
454  GetParentDialog()->EndDialog(RET_OK);
455  }
456  }
457  }
458 
459  return bModified;
460 }
461 
463 {
464  m_xOptionsLB->select(0);
465 
466  sal_uLong nOptions = GetDocumentOptions();
467  SetCurrentOptions( nOptions );
468  m_nSavedOptions = nOptions;
469 
472 }
473 
474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMSOCompatibleFormsMenu(bool bSet)
void SetAddExtLeading(bool bNew)
Definition: viewsh.cxx:801
virtual SfxObjectFactory & GetFactory() const =0
void SetMsWordCompTrailingBlanks(bool _bMsWordCompTrailingBlanks)
Definition: viewsh.cxx:920
SvtCompatibilityOptions m_aConfigItem
Definition: optcomp.hxx:35
OUString GetTitle(sal_uInt16 nMaxLen=0) const
void SetDoNotJustifyLinesWithManualBreak(bool _bDoNotJustifyLinesWithManualBreak)
Definition: viewsh.cxx:902
void SetParaSpaceMaxAtPages(bool bNew)
Definition: viewsh.cxx:777
void SetAddParaSpacingToTableCells(bool _bAddParaSpacingToTableCells)
Sets if paragraph and table spacing is added at bottom of table cells.
Definition: viewsh.cxx:832
css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > GetList() const
sal_uLong m_nSavedOptions
Definition: optcomp.hxx:45
sal_uIntPtr sal_uLong
std::unique_ptr< weld::ComboBox > m_xGlobalOptionsLB
Definition: optcomp.hxx:52
void SetCurrentOptions(sal_uLong nOptions)
Definition: optcomp.cxx:300
static Index getIndex(const OUString &rName)
const IDocumentSettingAccess & getIDocumentSettingAccess() const
Provides access to the document setting interface.
Definition: viewsh.cxx:2588
static OUString getUserEntryName()
IMPL_LINK_NOARG(SwCompatibilityOptPage, SelectHdl, weld::ComboBox &, void)
Definition: optcomp.cxx:270
TRISTATE_TRUE
std::unique_ptr< weld::TreeView > m_xGlobalOptionsCLB
Definition: optcomp.hxx:54
virtual ~SwCompatibilityOptPage() override
Definition: optcomp.cxx:114
virtual void Reset(const SfxItemSet *rSet) override
Definition: optcomp.cxx:462
void SetUseFormerTextWrapping(bool _bUseFormerTextWrapping)
Definition: viewsh.cxx:889
const SwView & GetView() const
Definition: wrtsh.hxx:426
RET_YES
std::unique_ptr< weld::Frame > m_xGlobalOptionsFrame
Definition: optcomp.hxx:50
void SetEmptyDbFieldHidesPara(bool bEmptyDbFieldHidesPara)
Definition: viewsh.cxx:938
std::vector< SvtCompatibilityEntry > m_aList
Definition: optcomp.cxx:54
std::unique_ptr< weld::Button > m_xDefaultPB
Definition: optcomp.hxx:55
bool HasMSOCompatibleFormsMenu() const
SVT_DLLPUBLIC bool executeRestartDialog(css::uno::Reference< css::uno::XComponentContext > const &context, weld::Window *parent, RestartReason reason)
weld::Window * GetDialogFrameWeld() const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
#define FN_PARAM_WRTSHELL
Definition: cmdid.h:769
int i
TRISTATE_FALSE
bool isDefaultEntry() const
std::unique_ptr< weld::Frame > m_xMain
Definition: optcomp.hxx:49
void setValue(const Index rIdx, css::uno::Any const &rValue)
Provides access to settings of a document.
bool m_bSavedMSFormsMenuOption
Definition: optcomp.hxx:46
static OUString getDefaultEntryName()
sal_uLong GetDocumentOptions() const
Definition: optcomp.cxx:312
SwWrtShell * m_pWrtShell
Definition: optcomp.hxx:41
std::unique_ptr< weld::ComboBox > m_xFormattingLB
Definition: optcomp.hxx:51
void InitControls(const SfxItemSet &rSet)
Definition: optcomp.cxx:188
void AppendItem(const SvtCompatibilityEntry &aItem)
SwDocShell * GetDocShell()
Definition: view.cxx:1115
void SetConsiderWrapOnObjPos(bool _bConsiderWrapOnObjPos)
Definition: viewsh.cxx:878
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rAttrSet)
Definition: optcomp.cxx:345
void SetUseFormerLineSpacing(bool _bUseFormerLineSpacing)
Sets if former formatting of text lines with proportional line spacing should used.
Definition: viewsh.cxx:849
std::unique_ptr< SwCompatibilityOptPage_Impl > m_pImpl
Definition: optcomp.hxx:43
void SetUseFormerObjectPositioning(bool _bUseFormerObjPos)
Sets IDocumentSettingAccess if former object positioning should be used.
Definition: viewsh.cxx:866
SwCompatibilityOptPage(TabPageParent pParent, const SfxItemSet &rSet)
Definition: optcomp.cxx:57
std::shared_ptr< const SfxFilter > GetFilter4FilterName(const OUString &rName, SfxFilterFlags nMust=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
RET_OK
static VclPtr< reference_type > Create(Arg &&...arg)
Reference< XComponentContext > getProcessComponentContext()
void SetUseVirDev(bool bNew)
Definition: viewsh.cxx:816
static sal_uLong convertBools2Ulong_Impl(bool _bUsePrtMetrics, bool _bAddSpacing, bool _bAddSpacingAtPages, bool _bUseOurTabStops, bool _bNoExtLeading, bool _bUseLineSpacing, bool _bAddTableSpacing, bool _bUseObjPos, bool _bUseOurTextWrapping, bool _bConsiderWrappingStyle, bool _bExpandWordSpace, bool _bProtectForm, bool _bMsWordCompTrailingBlanks, bool bSubtractFlysAnchoredAtFlys, bool bEmptyDbFieldHidesPara)
Definition: optcomp.cxx:119
void SetParaSpaceMax(bool bNew)
Definition: viewsh.cxx:765
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
std::unique_ptr< weld::TreeView > m_xOptionsLB
Definition: optcomp.hxx:53
static weld::Builder * CreateBuilder(weld::Widget *pParent, const OUString &rUIFile)
void SetSubtractFlysAnchoredAtFlys(bool bSubtractFlysAnchoredAtFlys)
Definition: viewsh.cxx:932
css::uno::Any getValue(const Index rIdx) const
RESTART_REASON_MSCOMPATIBLE_FORMS_MENU
void setDefaultEntry(bool rValue)
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optcomp.cxx:350
SvtCompatibilityViewOptions m_aViewConfigItem
Definition: optcomp.hxx:37
SfxFilterContainer * GetFilterContainer() const
void SetProtectForm(bool _bProtectForm)
Definition: viewsh.cxx:914
void SetTabCompat(bool bNew)
Definition: viewsh.cxx:789
sal_Int32 nPos