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 .
21 #undef SC_DLLIMPLEMENTATION
25 #include "document.hxx"
27 #include "scresid.hxx"
30 #include "tabpages.hxx"
32 // STATIC DATA -----------------------------------------------------------
34 static sal_uInt16 pProtectionRanges
[] =
36 SID_SCATTR_PROTECTION
,
37 SID_SCATTR_PROTECTION
,
41 //========================================================================
42 // Zellschutz-Tabpage:
43 //========================================================================
45 ScTabPageProtection::ScTabPageProtection(Window
* pParent
, const SfxItemSet
& rCoreAttrs
)
46 : SfxTabPage(pParent
, "CellProtectionPage",
47 "modules/scalc/ui/cellprotectionpage.ui", rCoreAttrs
)
49 get(m_pBtnHideCell
,"checkHideAll");
50 get(m_pBtnProtect
,"checkProtected");
51 get(m_pBtnHideFormula
,"checkHideFormula");
52 get(m_pBtnHidePrint
,"checkHidePrinting");
54 // This Page need ExchangeSupport
57 // States will be set in Reset
58 bTriEnabled
= bDontCare
= bProtect
= bHideForm
= bHideCell
= bHidePrint
= false;
60 m_pBtnProtect
->SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
61 m_pBtnHideCell
->SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
62 m_pBtnHideFormula
->SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
63 m_pBtnHidePrint
->SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
66 sal_uInt16
* ScTabPageProtection::GetRanges()
68 return pProtectionRanges
;
71 // -----------------------------------------------------------------------
73 SfxTabPage
* ScTabPageProtection::Create( Window
* pParent
, const SfxItemSet
& rAttrSet
)
75 return ( new ScTabPageProtection( pParent
, rAttrSet
) );
78 //------------------------------------------------------------------------
80 void ScTabPageProtection::Reset( const SfxItemSet
& rCoreAttrs
)
82 // Initialize variables
84 sal_uInt16 nWhich
= GetWhich( SID_SCATTR_PROTECTION
);
85 const ScProtectionAttr
* pProtAttr
= NULL
;
86 SfxItemState eItemState
= rCoreAttrs
.GetItemState( nWhich
, false,
87 (const SfxPoolItem
**)&pProtAttr
);
89 // Is this a Default-Item?
90 if ( eItemState
== SFX_ITEM_DEFAULT
)
91 pProtAttr
= (const ScProtectionAttr
*)&(rCoreAttrs
.Get(nWhich
));
92 // At SFX_ITEM_DONTCARE let to 0
94 bTriEnabled
= ( pProtAttr
== NULL
); // TriState, when DontCare
95 bDontCare
= bTriEnabled
;
98 // Defaults which appear when a TriState will be clicked away:
99 // (because everything combined is an attribute, and also only
100 // everything combined as DontCare can be available - #38543#)
103 bHideForm
= bHideCell
= bHidePrint
= false;
107 bProtect
= pProtAttr
->GetProtection();
108 bHideCell
= pProtAttr
->GetHideCell();
109 bHideForm
= pProtAttr
->GetHideFormula();
110 bHidePrint
= pProtAttr
->GetHidePrint();
115 m_pBtnProtect
->EnableTriState( bTriEnabled
);
116 m_pBtnHideCell
->EnableTriState( bTriEnabled
);
117 m_pBtnHideFormula
->EnableTriState( bTriEnabled
);
118 m_pBtnHidePrint
->EnableTriState( bTriEnabled
);
123 // -----------------------------------------------------------------------
125 sal_Bool
ScTabPageProtection::FillItemSet( SfxItemSet
& rCoreAttrs
)
127 sal_Bool bAttrsChanged
= false;
128 sal_uInt16 nWhich
= GetWhich( SID_SCATTR_PROTECTION
);
129 const SfxPoolItem
* pOldItem
= GetOldItem( rCoreAttrs
, SID_SCATTR_PROTECTION
);
130 const SfxItemSet
& rOldSet
= GetItemSet();
131 SfxItemState eItemState
= rOldSet
.GetItemState( nWhich
, false );
132 ScProtectionAttr aProtAttr
;
136 aProtAttr
.SetProtection( bProtect
);
137 aProtAttr
.SetHideCell( bHideCell
);
138 aProtAttr
.SetHideFormula( bHideForm
);
139 aProtAttr
.SetHidePrint( bHidePrint
);
142 bAttrsChanged
= sal_True
; // DontCare -> properly value
144 bAttrsChanged
= !pOldItem
|| !( aProtAttr
== *(const ScProtectionAttr
*)pOldItem
);
147 //--------------------------------------------------
150 rCoreAttrs
.Put( aProtAttr
);
151 else if ( eItemState
== SFX_ITEM_DEFAULT
)
152 rCoreAttrs
.ClearItem( nWhich
);
154 return bAttrsChanged
;
157 //------------------------------------------------------------------------
159 int ScTabPageProtection::DeactivatePage( SfxItemSet
* pSetP
)
162 FillItemSet( *pSetP
);
167 //------------------------------------------------------------------------
169 IMPL_LINK( ScTabPageProtection
, ButtonClickHdl
, TriStateBox
*, pBox
)
171 TriState eState
= pBox
->GetState();
172 if ( eState
== STATE_DONTKNOW
)
173 bDontCare
= sal_True
; // everything combined at DontCare
176 bDontCare
= false; // DontCare from everywhere
177 sal_Bool bOn
= ( eState
== STATE_CHECK
); // from a selected value
179 if ( pBox
== m_pBtnProtect
)
181 else if ( pBox
== m_pBtnHideCell
)
183 else if ( pBox
== m_pBtnHideFormula
)
185 else if ( pBox
== m_pBtnHidePrint
)
189 OSL_FAIL("falscher Button");
193 UpdateButtons(); // TriState and Logic-Enable
198 //------------------------------------------------------------------------
200 void ScTabPageProtection::UpdateButtons()
204 m_pBtnProtect
->SetState( STATE_DONTKNOW
);
205 m_pBtnHideCell
->SetState( STATE_DONTKNOW
);
206 m_pBtnHideFormula
->SetState( STATE_DONTKNOW
);
207 m_pBtnHidePrint
->SetState( STATE_DONTKNOW
);
211 m_pBtnProtect
->SetState( bProtect
? STATE_CHECK
: STATE_NOCHECK
);
212 m_pBtnHideCell
->SetState( bHideCell
? STATE_CHECK
: STATE_NOCHECK
);
213 m_pBtnHideFormula
->SetState( bHideForm
? STATE_CHECK
: STATE_NOCHECK
);
214 m_pBtnHidePrint
->SetState( bHidePrint
? STATE_CHECK
: STATE_NOCHECK
);
217 sal_Bool bEnable
= ( m_pBtnHideCell
->GetState() != STATE_CHECK
);
219 m_pBtnProtect
->Enable( bEnable
);
220 m_pBtnHideFormula
->Enable( bEnable
);
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */