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