Update git submodules
[LibreOffice.git] / sc / source / ui / attrdlg / tabpages.cxx
blob34931979499a7072e7e706c2c32de4a3a0241ec3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include <attrib.hxx>
23 #include <sc.hrc>
25 #include <tabpages.hxx>
26 #include <osl/diagnose.h>
28 const WhichRangesContainer ScTabPageProtection::pProtectionRanges(
29 svl::Items<SID_SCATTR_PROTECTION, SID_SCATTR_PROTECTION>);
31 // Zellschutz-Tabpage:
33 ScTabPageProtection::ScTabPageProtection(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs)
34 : SfxTabPage(pPage, pController, u"modules/scalc/ui/cellprotectionpage.ui"_ustr, u"CellProtectionPage"_ustr, &rCoreAttrs)
35 , m_xBtnHideCell(m_xBuilder->weld_check_button(u"checkHideAll"_ustr))
36 , m_xBtnProtect(m_xBuilder->weld_check_button(u"checkProtected"_ustr))
37 , m_xBtnHideFormula(m_xBuilder->weld_check_button(u"checkHideFormula"_ustr))
38 , m_xBtnHidePrint(m_xBuilder->weld_check_button(u"checkHidePrinting"_ustr))
40 // This Page need ExchangeSupport
41 SetExchangeSupport();
43 // States will be set in Reset
44 bTriEnabled = bDontCare = bProtect = bHideForm = bHideCell = bHidePrint = false;
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));
52 ScTabPageProtection::~ScTabPageProtection()
56 std::unique_ptr<SfxTabPage> ScTabPageProtection::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
58 return std::make_unique<ScTabPageProtection>(pPage, pController, *rAttrSet);
61 void ScTabPageProtection::Reset( const SfxItemSet* rCoreAttrs )
63 // Initialize variables
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) );
70 // Is this a Default-Item?
71 if ( eItemState == SfxItemState::DEFAULT )
72 pProtAttr = static_cast<const ScProtectionAttr*>(&(rCoreAttrs->Get(nWhich)));
73 // At SfxItemState::INVALID let to 0
75 bTriEnabled = ( pProtAttr == nullptr ); // TriState, when DontCare
76 bDontCare = bTriEnabled;
77 if (bTriEnabled)
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#)
83 bProtect = true;
84 bHideForm = bHideCell = bHidePrint = false;
86 else
88 bProtect = pProtAttr->GetProtection();
89 bHideCell = pProtAttr->GetHideCell();
90 bHideForm = pProtAttr->GetHideFormula();
91 bHidePrint = pProtAttr->GetHidePrint();
94 aHideCellState.bTriStateEnabled = bTriEnabled;
95 aProtectState.bTriStateEnabled = bTriEnabled;
96 aHideFormulaState.bTriStateEnabled = bTriEnabled;
97 aHidePrintState.bTriStateEnabled = bTriEnabled;
99 UpdateButtons();
102 bool ScTabPageProtection::FillItemSet( SfxItemSet* rCoreAttrs )
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;
111 if ( !bDontCare )
113 aProtAttr.SetProtection( bProtect );
114 aProtAttr.SetHideCell( bHideCell );
115 aProtAttr.SetHideFormula( bHideForm );
116 aProtAttr.SetHidePrint( bHidePrint );
118 if ( bTriEnabled )
119 bAttrsChanged = true; // DontCare -> properly value
120 else
121 bAttrsChanged = !pOldItem || aProtAttr != *static_cast<const ScProtectionAttr*>(pOldItem);
124 if ( bAttrsChanged )
125 rCoreAttrs->Put( aProtAttr );
126 else if ( eItemState == SfxItemState::DEFAULT )
127 rCoreAttrs->ClearItem( nWhich );
129 return bAttrsChanged;
132 DeactivateRC ScTabPageProtection::DeactivatePage( SfxItemSet* pSetP )
134 if ( pSetP )
135 FillItemSet( pSetP );
137 return DeactivateRC::LeavePage;
140 IMPL_LINK(ScTabPageProtection, ProtectClickHdl, weld::Toggleable&, rBox, void)
142 aProtectState.ButtonToggled(rBox);
143 ButtonClick(rBox);
146 IMPL_LINK(ScTabPageProtection, HideCellClickHdl, weld::Toggleable&, rBox, void)
148 aHideCellState.ButtonToggled(rBox);
149 ButtonClick(rBox);
152 IMPL_LINK(ScTabPageProtection, HideFormulaClickHdl, weld::Toggleable&, rBox, void)
154 aHideFormulaState.ButtonToggled(rBox);
155 ButtonClick(rBox);
158 IMPL_LINK(ScTabPageProtection, HidePrintClickHdl, weld::Toggleable&, rBox, void)
160 aHidePrintState.ButtonToggled(rBox);
161 ButtonClick(rBox);
164 void ScTabPageProtection::ButtonClick(const weld::Toggleable& rBox)
166 TriState eState = rBox.get_state();
167 if (eState == TRISTATE_INDET)
168 bDontCare = true; // everything combined at DontCare
169 else
171 bDontCare = false; // DontCare from everywhere
172 bool bOn = eState == TRISTATE_TRUE; // from a selected value
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
184 OSL_FAIL("Wrong button");
188 UpdateButtons(); // TriState and Logic-Enable
191 void ScTabPageProtection::UpdateButtons()
193 if (bDontCare)
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);
200 else
202 m_xBtnProtect->set_state(bProtect ? TRISTATE_TRUE : TRISTATE_FALSE);
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);
208 aHideCellState.eState = m_xBtnHideCell->get_state();
209 aProtectState.eState = m_xBtnProtect->get_state();
210 aHideFormulaState.eState = m_xBtnHideFormula->get_state();
211 aHidePrintState.eState = m_xBtnHidePrint->get_state();
213 bool bEnable = (m_xBtnHideCell->get_state() != TRISTATE_TRUE);
215 m_xBtnProtect->set_sensitive(bEnable);
216 m_xBtnHideFormula->set_sensitive(bEnable);
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */