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
26 #include "document.hxx"
28 #include "scresid.hxx"
31 #include "attrdlg.hrc"
32 #include "tabpages.hxx"
34 // STATIC DATA -----------------------------------------------------------
36 static sal_uInt16 pProtectionRanges
[] =
38 SID_SCATTR_PROTECTION
,
39 SID_SCATTR_PROTECTION
,
43 //========================================================================
44 // Zellschutz-Tabpage:
45 //========================================================================
47 ScTabPageProtection::ScTabPageProtection( Window
* pParent
,
48 const SfxItemSet
& rCoreAttrs
)
49 : SfxTabPage ( pParent
,
50 ScResId( RID_SCPAGE_PROTECTION
),
53 aFlProtect ( this, ScResId( FL_PROTECTION
) ),
54 aBtnHideCell ( this, ScResId( BTN_HIDE_ALL
) ),
55 aBtnProtect ( this, ScResId( BTN_PROTECTED
) ),
56 aBtnHideFormula ( this, ScResId( BTN_HIDE_FORMULAR
) ),
57 aTxtHint ( this, ScResId( FT_HINT
) ),
58 aFlPrint ( this, ScResId( FL_PRINT
) ),
59 aBtnHidePrint ( this, ScResId( BTN_HIDE_PRINT
) ),
60 aTxtHint2 ( this, ScResId( FT_HINT2
) )
62 // diese Page braucht ExchangeSupport
65 // States werden in Reset gesetzt
66 bTriEnabled
= bDontCare
= bProtect
= bHideForm
= bHideCell
= bHidePrint
= false;
68 aBtnProtect
.SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
69 aBtnHideCell
.SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
70 aBtnHideFormula
.SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
71 aBtnHidePrint
.SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
76 // -----------------------------------------------------------------------
78 ScTabPageProtection::~ScTabPageProtection()
82 //------------------------------------------------------------------------
84 sal_uInt16
* ScTabPageProtection::GetRanges()
86 return pProtectionRanges
;
89 // -----------------------------------------------------------------------
91 SfxTabPage
* ScTabPageProtection::Create( Window
* pParent
,
92 const SfxItemSet
& rAttrSet
)
94 return ( new ScTabPageProtection( pParent
, rAttrSet
) );
97 //------------------------------------------------------------------------
99 void ScTabPageProtection::Reset( const SfxItemSet
& rCoreAttrs
)
101 // Variablen initialisieren
103 sal_uInt16 nWhich
= GetWhich( SID_SCATTR_PROTECTION
);
104 const ScProtectionAttr
* pProtAttr
= NULL
;
105 SfxItemState eItemState
= rCoreAttrs
.GetItemState( nWhich
, false,
106 (const SfxPoolItem
**)&pProtAttr
);
108 // handelt es sich um ein Default-Item?
109 if ( eItemState
== SFX_ITEM_DEFAULT
)
110 pProtAttr
= (const ScProtectionAttr
*)&(rCoreAttrs
.Get(nWhich
));
111 // bei SFX_ITEM_DONTCARE auf 0 lassen
113 bTriEnabled
= ( pProtAttr
== NULL
); // TriState, wenn DontCare
114 bDontCare
= bTriEnabled
;
117 // Defaults, die erscheinen wenn ein TriState weggeklickt wird:
118 // (weil alles zusammen ein Attribut ist, kann auch nur alles zusammen
119 // auf DontCare stehen - #38543#)
121 bHideForm
= bHideCell
= bHidePrint
= false;
125 bProtect
= pProtAttr
->GetProtection();
126 bHideCell
= pProtAttr
->GetHideCell();
127 bHideForm
= pProtAttr
->GetHideFormula();
128 bHidePrint
= pProtAttr
->GetHidePrint();
131 // Controls initialisieren
133 aBtnProtect
.EnableTriState( bTriEnabled
);
134 aBtnHideCell
.EnableTriState( bTriEnabled
);
135 aBtnHideFormula
.EnableTriState( bTriEnabled
);
136 aBtnHidePrint
.EnableTriState( bTriEnabled
);
141 // -----------------------------------------------------------------------
143 sal_Bool
ScTabPageProtection::FillItemSet( SfxItemSet
& rCoreAttrs
)
145 sal_Bool bAttrsChanged
= false;
146 sal_uInt16 nWhich
= GetWhich( SID_SCATTR_PROTECTION
);
147 const SfxPoolItem
* pOldItem
= GetOldItem( rCoreAttrs
, SID_SCATTR_PROTECTION
);
148 const SfxItemSet
& rOldSet
= GetItemSet();
149 SfxItemState eItemState
= rOldSet
.GetItemState( nWhich
, false );
150 ScProtectionAttr aProtAttr
;
154 aProtAttr
.SetProtection( bProtect
);
155 aProtAttr
.SetHideCell( bHideCell
);
156 aProtAttr
.SetHideFormula( bHideForm
);
157 aProtAttr
.SetHidePrint( bHidePrint
);
160 bAttrsChanged
= sal_True
; // DontCare -> richtiger Wert
162 bAttrsChanged
= !pOldItem
|| !( aProtAttr
== *(const ScProtectionAttr
*)pOldItem
);
165 //--------------------------------------------------
168 rCoreAttrs
.Put( aProtAttr
);
169 else if ( eItemState
== SFX_ITEM_DEFAULT
)
170 rCoreAttrs
.ClearItem( nWhich
);
172 return bAttrsChanged
;
175 //------------------------------------------------------------------------
177 int ScTabPageProtection::DeactivatePage( SfxItemSet
* pSetP
)
180 FillItemSet( *pSetP
);
185 //------------------------------------------------------------------------
187 IMPL_LINK( ScTabPageProtection
, ButtonClickHdl
, TriStateBox
*, pBox
)
189 TriState eState
= pBox
->GetState();
190 if ( eState
== STATE_DONTKNOW
)
191 bDontCare
= sal_True
; // alles zusammen auf DontCare
194 bDontCare
= false; // DontCare ueberall aus
195 sal_Bool bOn
= ( eState
== STATE_CHECK
); // ausgewaehlter Wert
197 if ( pBox
== &aBtnProtect
)
199 else if ( pBox
== &aBtnHideCell
)
201 else if ( pBox
== &aBtnHideFormula
)
203 else if ( pBox
== &aBtnHidePrint
)
207 OSL_FAIL("falscher Button");
211 UpdateButtons(); // TriState und Enable-Logik
216 //------------------------------------------------------------------------
218 void ScTabPageProtection::UpdateButtons()
222 aBtnProtect
.SetState( STATE_DONTKNOW
);
223 aBtnHideCell
.SetState( STATE_DONTKNOW
);
224 aBtnHideFormula
.SetState( STATE_DONTKNOW
);
225 aBtnHidePrint
.SetState( STATE_DONTKNOW
);
229 aBtnProtect
.SetState( bProtect
? STATE_CHECK
: STATE_NOCHECK
);
230 aBtnHideCell
.SetState( bHideCell
? STATE_CHECK
: STATE_NOCHECK
);
231 aBtnHideFormula
.SetState( bHideForm
? STATE_CHECK
: STATE_NOCHECK
);
232 aBtnHidePrint
.SetState( bHidePrint
? STATE_CHECK
: STATE_NOCHECK
);
235 sal_Bool bEnable
= ( aBtnHideCell
.GetState() != STATE_CHECK
);
237 aBtnProtect
.Enable( bEnable
);
238 aBtnHideFormula
.Enable( bEnable
);
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */