LibreOffice Module sc (master)  1
defaultsoptions.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 
10 #include <com/sun/star/uno/Sequence.hxx>
11 #include <osl/diagnose.h>
12 
13 #include <defaultsoptions.hxx>
14 #include <globstr.hrc>
15 #include <scresid.hxx>
16 #include <sc.hrc>
17 
18 using namespace utl;
19 using namespace com::sun::star::uno;
20 
21 
23 {
24  SetDefaults();
25 }
26 
28 {
29  nInitTabCount = 1;
30  aInitTabPrefix = ScResId(STR_TABLE_DEF); // Default Prefix "Sheet"
31  bJumboSheets = false;
32 }
33 
35 {
36  return rOpt.nInitTabCount == nInitTabCount
37  && rOpt.aInitTabPrefix == aInitTabPrefix
38  && rOpt.bJumboSheets == bJumboSheets;
39 }
40 
42  SfxPoolItem ( SID_SCDEFAULTSOPTIONS ),
43  theOptions ( rOpt )
44 {
45 }
46 
48 {
49 }
50 
51 bool ScTpDefaultsItem::operator==( const SfxPoolItem& rItem ) const
52 {
53  assert(SfxPoolItem::operator==(rItem));
54 
55  const ScTpDefaultsItem& rPItem = static_cast<const ScTpDefaultsItem&>(rItem);
56  return ( theOptions == rPItem.theOptions );
57 }
58 
60 {
61  return new ScTpDefaultsItem( *this );
62 }
63 
64 constexpr OUStringLiteral CFGPATH_FORMULA = u"Office.Calc/Defaults";
65 
66 #define SCDEFAULTSOPT_TAB_COUNT 0
67 #define SCDEFAULTSOPT_TAB_PREFIX 1
68 #define SCDEFAULTSOPT_JUMBO_SHEETS 2
69 
71 {
72  return {"Sheet/SheetCount", // SCDEFAULTSOPT_TAB_COUNT
73  "Sheet/SheetPrefix", // SCDEFAULTSOPT_TAB_PREFIX
74  "Sheet/JumboSheets"}; // SCDEFAULTSOPT_JUMBO_SHEETS
75 
76 }
77 
80 {
81  OUString aPrefix;
82  bool bValue;
83 
85  Sequence<Any> aValues = GetProperties(aNames);
86  const Any* pValues = aValues.getConstArray();
87  OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
88  if(aValues.getLength() != aNames.getLength())
89  return;
90 
91  sal_Int32 nIntVal = 0;
92  for(int nProp = 0; nProp < aNames.getLength(); nProp++)
93  {
94  if(pValues[nProp].hasValue())
95  {
96  switch (nProp)
97  {
99  if (pValues[nProp] >>= nIntVal)
100  SetInitTabCount( static_cast<SCTAB>(nIntVal) );
101  break;
103  if (pValues[nProp] >>= aPrefix)
104  SetInitTabPrefix(aPrefix);
105  break;
107  if (pValues[nProp] >>= bValue)
108  SetInitJumboSheets(bValue);
109  break;
110  }
111  }
112  }
113 }
114 
116 {
118  Sequence<Any> aValues(aNames.getLength());
119  Any* pValues = aValues.getArray();
120 
121  for (int nProp = 0; nProp < aNames.getLength(); ++nProp)
122  {
123  switch(nProp)
124  {
126  pValues[nProp] <<= static_cast<sal_Int32>(GetInitTabCount());
127  break;
129  pValues[nProp] <<= GetInitTabPrefix();
130  break;
132  pValues[nProp] <<= GetInitJumboSheets();
133  break;
134  }
135  }
136  PutProperties(aNames, aValues);
137 }
138 
140 {
141  *static_cast<ScDefaultsOptions*>(this) = rNew;
142  SetModified();
143 }
144 
145 void ScDefaultsCfg::Notify( const css::uno::Sequence< OUString >& ) {}
146 
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCTAB GetInitTabCount() const
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
static css::uno::Sequence< OUString > GetPropertyNames()
void SetInitTabPrefix(const OUString &aPrefix)
bool operator==(const ScDefaultsOptions &rOpt) const
bool GetInitJumboSheets() const
static bool PutProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues, bool bAllLocales)
void SetOptions(const ScDefaultsOptions &rNew)
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
virtual ScTpDefaultsItem * Clone(SfxItemPool *pPool=nullptr) const override
#define SCDEFAULTSOPT_JUMBO_SHEETS
constexpr OUStringLiteral CFGPATH_FORMULA
ScTpDefaultsItem(const ScDefaultsOptions &rOpt)
const OUString & GetInitTabPrefix() const
float u
void SetInitJumboSheets(bool b)
ScDefaultsOptions theOptions
#define SCDEFAULTSOPT_TAB_PREFIX
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
virtual void ImplCommit() override
const PropertyValue * pValues
virtual bool operator==(const SfxPoolItem &) const override
virtual ~ScTpDefaultsItem() override
void SetInitTabCount(SCTAB nTabs)
#define SCDEFAULTSOPT_TAB_COUNT