1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
23 #include "document.hxx"
25 #include "scresid.hxx"
28 #include "tabpages.hxx"
30 // STATIC DATA -----------------------------------------------------------
32 const sal_uInt16
ScTabPageProtection::pProtectionRanges
[] =
34 SID_SCATTR_PROTECTION
,
35 SID_SCATTR_PROTECTION
,
39 // Zellschutz-Tabpage:
41 ScTabPageProtection::ScTabPageProtection(vcl::Window
* pParent
, const SfxItemSet
& rCoreAttrs
)
42 : SfxTabPage(pParent
, "CellProtectionPage",
43 "modules/scalc/ui/cellprotectionpage.ui", &rCoreAttrs
)
45 get(m_pBtnHideCell
,"checkHideAll");
46 get(m_pBtnProtect
,"checkProtected");
47 get(m_pBtnHideFormula
,"checkHideFormula");
48 get(m_pBtnHidePrint
,"checkHidePrinting");
50 // This Page need ExchangeSupport
53 // States will be set in Reset
54 bTriEnabled
= bDontCare
= bProtect
= bHideForm
= bHideCell
= bHidePrint
= false;
56 m_pBtnProtect
->SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
57 m_pBtnHideCell
->SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
58 m_pBtnHideFormula
->SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
59 m_pBtnHidePrint
->SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
62 ScTabPageProtection::~ScTabPageProtection()
67 void ScTabPageProtection::dispose()
69 m_pBtnHideCell
.clear();
70 m_pBtnProtect
.clear();
71 m_pBtnHideFormula
.clear();
72 m_pBtnHidePrint
.clear();
73 SfxTabPage::dispose();
76 VclPtr
<SfxTabPage
> ScTabPageProtection::Create( vcl::Window
* pParent
, const SfxItemSet
* rAttrSet
)
78 return VclPtr
<ScTabPageProtection
>::Create( pParent
, *rAttrSet
);
81 void ScTabPageProtection::Reset( const SfxItemSet
* rCoreAttrs
)
83 // Initialize variables
85 sal_uInt16 nWhich
= GetWhich( SID_SCATTR_PROTECTION
);
86 const ScProtectionAttr
* pProtAttr
= NULL
;
87 SfxItemState eItemState
= rCoreAttrs
->GetItemState( nWhich
, false,
88 reinterpret_cast<const SfxPoolItem
**>(&pProtAttr
) );
90 // Is this a Default-Item?
91 if ( eItemState
== SfxItemState::DEFAULT
)
92 pProtAttr
= static_cast<const ScProtectionAttr
*>(&(rCoreAttrs
->Get(nWhich
)));
93 // At SfxItemState::DONTCARE let to 0
95 bTriEnabled
= ( pProtAttr
== NULL
); // TriState, when DontCare
96 bDontCare
= bTriEnabled
;
99 // Defaults which appear when a TriState will be clicked away:
100 // (because everything combined is an attribute, and also only
101 // everything combined as DontCare can be available - #38543#)
104 bHideForm
= bHideCell
= bHidePrint
= false;
108 bProtect
= pProtAttr
->GetProtection();
109 bHideCell
= pProtAttr
->GetHideCell();
110 bHideForm
= pProtAttr
->GetHideFormula();
111 bHidePrint
= pProtAttr
->GetHidePrint();
116 m_pBtnProtect
->EnableTriState( bTriEnabled
);
117 m_pBtnHideCell
->EnableTriState( bTriEnabled
);
118 m_pBtnHideFormula
->EnableTriState( bTriEnabled
);
119 m_pBtnHidePrint
->EnableTriState( bTriEnabled
);
124 bool ScTabPageProtection::FillItemSet( SfxItemSet
* rCoreAttrs
)
126 bool bAttrsChanged
= false;
127 sal_uInt16 nWhich
= GetWhich( SID_SCATTR_PROTECTION
);
128 const SfxPoolItem
* pOldItem
= GetOldItem( *rCoreAttrs
, SID_SCATTR_PROTECTION
);
129 const SfxItemSet
& rOldSet
= GetItemSet();
130 SfxItemState eItemState
= rOldSet
.GetItemState( nWhich
, false );
131 ScProtectionAttr aProtAttr
;
135 aProtAttr
.SetProtection( bProtect
);
136 aProtAttr
.SetHideCell( bHideCell
);
137 aProtAttr
.SetHideFormula( bHideForm
);
138 aProtAttr
.SetHidePrint( bHidePrint
);
141 bAttrsChanged
= true; // DontCare -> properly value
143 bAttrsChanged
= !pOldItem
|| !( aProtAttr
== *static_cast<const ScProtectionAttr
*>(pOldItem
) );
147 rCoreAttrs
->Put( aProtAttr
);
148 else if ( eItemState
== SfxItemState::DEFAULT
)
149 rCoreAttrs
->ClearItem( nWhich
);
151 return bAttrsChanged
;
154 SfxTabPage::sfxpg
ScTabPageProtection::DeactivatePage( SfxItemSet
* pSetP
)
157 FillItemSet( pSetP
);
162 IMPL_LINK( ScTabPageProtection
, ButtonClickHdl
, TriStateBox
*, pBox
)
164 TriState eState
= pBox
->GetState();
165 if ( eState
== TRISTATE_INDET
)
166 bDontCare
= true; // everything combined at DontCare
169 bDontCare
= false; // DontCare from everywhere
170 bool bOn
= ( eState
== TRISTATE_TRUE
); // from a selected value
172 if ( pBox
== m_pBtnProtect
)
174 else if ( pBox
== m_pBtnHideCell
)
176 else if ( pBox
== m_pBtnHideFormula
)
178 else if ( pBox
== m_pBtnHidePrint
)
182 OSL_FAIL("falscher Button");
186 UpdateButtons(); // TriState and Logic-Enable
191 void ScTabPageProtection::UpdateButtons()
195 m_pBtnProtect
->SetState( TRISTATE_INDET
);
196 m_pBtnHideCell
->SetState( TRISTATE_INDET
);
197 m_pBtnHideFormula
->SetState( TRISTATE_INDET
);
198 m_pBtnHidePrint
->SetState( TRISTATE_INDET
);
202 m_pBtnProtect
->SetState( bProtect
? TRISTATE_TRUE
: TRISTATE_FALSE
);
203 m_pBtnHideCell
->SetState( bHideCell
? TRISTATE_TRUE
: TRISTATE_FALSE
);
204 m_pBtnHideFormula
->SetState( bHideForm
? TRISTATE_TRUE
: TRISTATE_FALSE
);
205 m_pBtnHidePrint
->SetState( bHidePrint
? TRISTATE_TRUE
: TRISTATE_FALSE
);
208 bool bEnable
= ( m_pBtnHideCell
->GetState() != TRISTATE_TRUE
);
210 m_pBtnProtect
->Enable( bEnable
);
211 m_pBtnHideFormula
->Enable( bEnable
);
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */