LibreOffice Module sc (master)  1
tabpages.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 #undef SC_DLLIMPLEMENTATION
21 
22 #include <attrib.hxx>
23 #include <sc.hrc>
24 
25 #include <tabpages.hxx>
26 #include <osl/diagnose.h>
27 
29  svl::Items<SID_SCATTR_PROTECTION, SID_SCATTR_PROTECTION>);
30 
31 // Zellschutz-Tabpage:
32 
34  : SfxTabPage(pPage, pController, "modules/scalc/ui/cellprotectionpage.ui", "CellProtectionPage", &rCoreAttrs)
35  , m_xBtnHideCell(m_xBuilder->weld_check_button("checkHideAll"))
36  , m_xBtnProtect(m_xBuilder->weld_check_button("checkProtected"))
37  , m_xBtnHideFormula(m_xBuilder->weld_check_button("checkHideFormula"))
38  , m_xBtnHidePrint(m_xBuilder->weld_check_button("checkHidePrinting"))
39 {
40  // This Page need ExchangeSupport
42 
43  // States will be set in Reset
45 
46  m_xBtnProtect->connect_toggled(LINK(this, ScTabPageProtection, ProtectClickHdl));
47  m_xBtnHideCell->connect_toggled(LINK(this, ScTabPageProtection, HideCellClickHdl));
48  m_xBtnHideFormula->connect_toggled(LINK(this, ScTabPageProtection, HideFormulaClickHdl));
49  m_xBtnHidePrint->connect_toggled(LINK(this, ScTabPageProtection, HidePrintClickHdl));
50 }
51 
53 {
54 }
55 
56 std::unique_ptr<SfxTabPage> ScTabPageProtection::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
57 {
58  return std::make_unique<ScTabPageProtection>(pPage, pController, *rAttrSet);
59 }
60 
61 void ScTabPageProtection::Reset( const SfxItemSet* rCoreAttrs )
62 {
63  // Initialize variables
64 
65  sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION );
66  const ScProtectionAttr* pProtAttr = nullptr;
67  SfxItemState eItemState = rCoreAttrs->GetItemState( nWhich, false,
68  reinterpret_cast<const SfxPoolItem**>(&pProtAttr) );
69 
70  // Is this a Default-Item?
71  if ( eItemState == SfxItemState::DEFAULT )
72  pProtAttr = static_cast<const ScProtectionAttr*>(&(rCoreAttrs->Get(nWhich)));
73  // At SfxItemState::DONTCARE let to 0
74 
75  bTriEnabled = ( pProtAttr == nullptr ); // TriState, when DontCare
77  if (bTriEnabled)
78  {
79  // Defaults which appear when a TriState will be clicked away:
80  // (because everything combined is an attribute, and also only
81  // everything combined as DontCare can be available - #38543#)
82 
83  bProtect = true;
84  bHideForm = bHideCell = bHidePrint = false;
85  }
86  else
87  {
88  bProtect = pProtAttr->GetProtection();
89  bHideCell = pProtAttr->GetHideCell();
90  bHideForm = pProtAttr->GetHideFormula();
91  bHidePrint = pProtAttr->GetHidePrint();
92  }
93 
98 
99  UpdateButtons();
100 }
101 
103 {
104  bool bAttrsChanged = false;
105  sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION );
106  const SfxPoolItem* pOldItem = GetOldItem( *rCoreAttrs, SID_SCATTR_PROTECTION );
107  const SfxItemSet& rOldSet = GetItemSet();
108  SfxItemState eItemState = rOldSet.GetItemState( nWhich, false );
109  ScProtectionAttr aProtAttr;
110 
111  if ( !bDontCare )
112  {
113  aProtAttr.SetProtection( bProtect );
114  aProtAttr.SetHideCell( bHideCell );
115  aProtAttr.SetHideFormula( bHideForm );
116  aProtAttr.SetHidePrint( bHidePrint );
117 
118  if ( bTriEnabled )
119  bAttrsChanged = true; // DontCare -> properly value
120  else
121  bAttrsChanged = !pOldItem || aProtAttr != *static_cast<const ScProtectionAttr*>(pOldItem);
122  }
123 
124  if ( bAttrsChanged )
125  rCoreAttrs->Put( aProtAttr );
126  else if ( eItemState == SfxItemState::DEFAULT )
127  rCoreAttrs->ClearItem( nWhich );
128 
129  return bAttrsChanged;
130 }
131 
133 {
134  if ( pSetP )
135  FillItemSet( pSetP );
136 
137  return DeactivateRC::LeavePage;
138 }
139 
140 IMPL_LINK(ScTabPageProtection, ProtectClickHdl, weld::Toggleable&, rBox, void)
141 {
142  aProtectState.ButtonToggled(rBox);
143  ButtonClick(rBox);
144 }
145 
146 IMPL_LINK(ScTabPageProtection, HideCellClickHdl, weld::Toggleable&, rBox, void)
147 {
148  aHideCellState.ButtonToggled(rBox);
149  ButtonClick(rBox);
150 }
151 
152 IMPL_LINK(ScTabPageProtection, HideFormulaClickHdl, weld::Toggleable&, rBox, void)
153 {
154  aHideFormulaState.ButtonToggled(rBox);
155  ButtonClick(rBox);
156 }
157 
158 IMPL_LINK(ScTabPageProtection, HidePrintClickHdl, weld::Toggleable&, rBox, void)
159 {
160  aHidePrintState.ButtonToggled(rBox);
161  ButtonClick(rBox);
162 }
163 
165 {
166  TriState eState = rBox.get_state();
167  if (eState == TRISTATE_INDET)
168  bDontCare = true; // everything combined at DontCare
169  else
170  {
171  bDontCare = false; // DontCare from everywhere
172  bool bOn = eState == TRISTATE_TRUE; // from a selected value
173 
174  if (&rBox == m_xBtnProtect.get())
175  bProtect = bOn;
176  else if (&rBox == m_xBtnHideCell.get())
177  bHideCell = bOn;
178  else if (&rBox == m_xBtnHideFormula.get())
179  bHideForm = bOn;
180  else if (&rBox == m_xBtnHidePrint.get())
181  bHidePrint = bOn;
182  else
183  {
184  OSL_FAIL("Wrong button");
185  }
186  }
187 
188  UpdateButtons(); // TriState and Logic-Enable
189 }
190 
192 {
193  if (bDontCare)
194  {
195  m_xBtnProtect->set_state(TRISTATE_INDET);
196  m_xBtnHideCell->set_state(TRISTATE_INDET);
197  m_xBtnHideFormula->set_state(TRISTATE_INDET);
198  m_xBtnHidePrint->set_state(TRISTATE_INDET);
199  }
200  else
201  {
203  m_xBtnHideCell->set_state(bHideCell ? TRISTATE_TRUE : TRISTATE_FALSE);
204  m_xBtnHideFormula->set_state(bHideForm ? TRISTATE_TRUE : TRISTATE_FALSE);
205  m_xBtnHidePrint->set_state(bHidePrint ? TRISTATE_TRUE : TRISTATE_FALSE);
206  }
207 
208  aHideCellState.eState = m_xBtnHideCell->get_state();
209  aProtectState.eState = m_xBtnProtect->get_state();
211  aHidePrintState.eState = m_xBtnHidePrint->get_state();
212 
213  bool bEnable = (m_xBtnHideCell->get_state() != TRISTATE_TRUE);
214  {
215  m_xBtnProtect->set_sensitive(bEnable);
216  m_xBtnHideFormula->set_sensitive(bEnable);
217  }
218 }
219 
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::CheckButton > m_xBtnProtect
Definition: tabpages.hxx:55
void SetHidePrint(bool bHPrint)
Definition: attrib.cxx:365
std::unique_ptr< weld::CheckButton > m_xBtnHideCell
Definition: tabpages.hxx:54
TRISTATE_TRUE
void SetProtection(bool bProtect)
Definition: attrib.cxx:350
weld::TriStateEnabled aHideCellState
Definition: tabpages.hxx:49
weld::TriStateEnabled aProtectState
Definition: tabpages.hxx:50
void SetExchangeSupport()
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tabpages.cxx:132
static const WhichRangesContainer pProtectionRanges
Definition: tabpages.hxx:26
ScTabPageProtection(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rCoreAttrs)
Definition: tabpages.cxx:33
std::unique_ptr< weld::CheckButton > m_xBtnHidePrint
Definition: tabpages.hxx:57
TRISTATE_INDET
const SfxItemSet & GetItemSet() const
bool GetHideCell() const
Definition: attrib.hxx:147
const SfxPoolItem * GetOldItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
bool GetHideFormula() const
Definition: attrib.hxx:145
TRISTATE_FALSE
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
Definition: tabpages.cxx:56
void ButtonClick(const weld::Toggleable &rBox)
Definition: tabpages.cxx:164
virtual ~ScTabPageProtection() override
Definition: tabpages.cxx:52
bool GetHidePrint() const
Definition: attrib.hxx:149
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
SfxItemState
TriState get_state() const
void SetHideCell(bool bHCell)
Definition: attrib.cxx:360
weld::TriStateEnabled aHideFormulaState
Definition: tabpages.hxx:51
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual bool FillItemSet(SfxItemSet *rCoreAttrs) override
Definition: tabpages.cxx:102
weld::TriStateEnabled aHidePrintState
Definition: tabpages.hxx:52
bool GetProtection() const
Definition: attrib.hxx:143
void SetHideFormula(bool bHFormula)
Definition: attrib.cxx:355
IMPL_LINK(ScTabPageProtection, ProtectClickHdl, weld::Toggleable &, rBox, void)
Definition: tabpages.cxx:140
DeactivateRC
virtual void Reset(const SfxItemSet *) override
Definition: tabpages.cxx:61
std::unique_ptr< weld::CheckButton > m_xBtnHideFormula
Definition: tabpages.hxx:56
TriState
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const