1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#undef SC_DLLIMPLEMENTATION
#include <attrib.hxx>
#include <sc.hrc>
#include <tabpages.hxx>
#include <osl/diagnose.h>
const WhichRangesContainer ScTabPageProtection::pProtectionRanges(
svl::Items<SID_SCATTR_PROTECTION, SID_SCATTR_PROTECTION>);
// Zellschutz-Tabpage:
ScTabPageProtection::ScTabPageProtection(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs)
: SfxTabPage(pPage, pController, "modules/scalc/ui/cellprotectionpage.ui", "CellProtectionPage", &rCoreAttrs)
, m_xBtnHideCell(m_xBuilder->weld_check_button("checkHideAll"))
, m_xBtnProtect(m_xBuilder->weld_check_button("checkProtected"))
, m_xBtnHideFormula(m_xBuilder->weld_check_button("checkHideFormula"))
, m_xBtnHidePrint(m_xBuilder->weld_check_button("checkHidePrinting"))
{
// This Page need ExchangeSupport
SetExchangeSupport();
// States will be set in Reset
bTriEnabled = bDontCare = bProtect = bHideForm = bHideCell = bHidePrint = false;
m_xBtnProtect->connect_toggled(LINK(this, ScTabPageProtection, ProtectClickHdl));
m_xBtnHideCell->connect_toggled(LINK(this, ScTabPageProtection, HideCellClickHdl));
m_xBtnHideFormula->connect_toggled(LINK(this, ScTabPageProtection, HideFormulaClickHdl));
m_xBtnHidePrint->connect_toggled(LINK(this, ScTabPageProtection, HidePrintClickHdl));
}
ScTabPageProtection::~ScTabPageProtection()
{
}
std::unique_ptr<SfxTabPage> ScTabPageProtection::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
{
return std::make_unique<ScTabPageProtection>(pPage, pController, *rAttrSet);
}
void ScTabPageProtection::Reset( const SfxItemSet* rCoreAttrs )
{
// Initialize variables
sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION );
const ScProtectionAttr* pProtAttr = nullptr;
SfxItemState eItemState = rCoreAttrs->GetItemState( nWhich, false,
reinterpret_cast<const SfxPoolItem**>(&pProtAttr) );
// Is this a Default-Item?
if ( eItemState == SfxItemState::DEFAULT )
pProtAttr = static_cast<const ScProtectionAttr*>(&(rCoreAttrs->Get(nWhich)));
// At SfxItemState::DONTCARE let to 0
bTriEnabled = ( pProtAttr == nullptr ); // TriState, when DontCare
bDontCare = bTriEnabled;
if (bTriEnabled)
{
// Defaults which appear when a TriState will be clicked away:
// (because everything combined is an attribute, and also only
// everything combined as DontCare can be available - #38543#)
bProtect = true;
bHideForm = bHideCell = bHidePrint = false;
}
else
{
bProtect = pProtAttr->GetProtection();
bHideCell = pProtAttr->GetHideCell();
bHideForm = pProtAttr->GetHideFormula();
bHidePrint = pProtAttr->GetHidePrint();
}
aHideCellState.bTriStateEnabled = bTriEnabled;
aProtectState.bTriStateEnabled = bTriEnabled;
aHideFormulaState.bTriStateEnabled = bTriEnabled;
aHidePrintState.bTriStateEnabled = bTriEnabled;
UpdateButtons();
}
bool ScTabPageProtection::FillItemSet( SfxItemSet* rCoreAttrs )
{
bool bAttrsChanged = false;
sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION );
const SfxPoolItem* pOldItem = GetOldItem( *rCoreAttrs, SID_SCATTR_PROTECTION );
const SfxItemSet& rOldSet = GetItemSet();
SfxItemState eItemState = rOldSet.GetItemState( nWhich, false );
ScProtectionAttr aProtAttr;
if ( !bDontCare )
{
aProtAttr.SetProtection( bProtect );
aProtAttr.SetHideCell( bHideCell );
aProtAttr.SetHideFormula( bHideForm );
aProtAttr.SetHidePrint( bHidePrint );
if ( bTriEnabled )
bAttrsChanged = true; // DontCare -> properly value
else
bAttrsChanged = !pOldItem || aProtAttr != *static_cast<const ScProtectionAttr*>(pOldItem);
}
if ( bAttrsChanged )
rCoreAttrs->Put( aProtAttr );
else if ( eItemState == SfxItemState::DEFAULT )
rCoreAttrs->ClearItem( nWhich );
return bAttrsChanged;
}
DeactivateRC ScTabPageProtection::DeactivatePage( SfxItemSet* pSetP )
{
if ( pSetP )
FillItemSet( pSetP );
return DeactivateRC::LeavePage;
}
IMPL_LINK(ScTabPageProtection, ProtectClickHdl, weld::Toggleable&, rBox, void)
{
aProtectState.ButtonToggled(rBox);
ButtonClick(rBox);
}
IMPL_LINK(ScTabPageProtection, HideCellClickHdl, weld::Toggleable&, rBox, void)
{
aHideCellState.ButtonToggled(rBox);
ButtonClick(rBox);
}
IMPL_LINK(ScTabPageProtection, HideFormulaClickHdl, weld::Toggleable&, rBox, void)
{
aHideFormulaState.ButtonToggled(rBox);
ButtonClick(rBox);
}
IMPL_LINK(ScTabPageProtection, HidePrintClickHdl, weld::Toggleable&, rBox, void)
{
aHidePrintState.ButtonToggled(rBox);
ButtonClick(rBox);
}
void ScTabPageProtection::ButtonClick(const weld::Toggleable& rBox)
{
TriState eState = rBox.get_state();
if (eState == TRISTATE_INDET)
bDontCare = true; // everything combined at DontCare
else
{
bDontCare = false; // DontCare from everywhere
bool bOn = eState == TRISTATE_TRUE; // from a selected value
if (&rBox == m_xBtnProtect.get())
bProtect = bOn;
else if (&rBox == m_xBtnHideCell.get())
bHideCell = bOn;
else if (&rBox == m_xBtnHideFormula.get())
bHideForm = bOn;
else if (&rBox == m_xBtnHidePrint.get())
bHidePrint = bOn;
else
{
OSL_FAIL("Wrong button");
}
}
UpdateButtons(); // TriState and Logic-Enable
}
void ScTabPageProtection::UpdateButtons()
{
if (bDontCare)
{
m_xBtnProtect->set_state(TRISTATE_INDET);
m_xBtnHideCell->set_state(TRISTATE_INDET);
m_xBtnHideFormula->set_state(TRISTATE_INDET);
m_xBtnHidePrint->set_state(TRISTATE_INDET);
}
else
{
m_xBtnProtect->set_state(bProtect ? TRISTATE_TRUE : TRISTATE_FALSE);
m_xBtnHideCell->set_state(bHideCell ? TRISTATE_TRUE : TRISTATE_FALSE);
m_xBtnHideFormula->set_state(bHideForm ? TRISTATE_TRUE : TRISTATE_FALSE);
m_xBtnHidePrint->set_state(bHidePrint ? TRISTATE_TRUE : TRISTATE_FALSE);
}
aHideCellState.eState = m_xBtnHideCell->get_state();
aProtectState.eState = m_xBtnProtect->get_state();
aHideFormulaState.eState = m_xBtnHideFormula->get_state();
aHidePrintState.eState = m_xBtnHidePrint->get_state();
bool bEnable = (m_xBtnHideCell->get_state() != TRISTATE_TRUE);
{
m_xBtnProtect->set_sensitive(bEnable);
m_xBtnHideFormula->set_sensitive(bEnable);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|