1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabpages.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
39 #include "document.hxx"
41 #include "scresid.hxx"
44 #include "attrdlg.hrc"
45 #include "tabpages.hxx"
47 // STATIC DATA -----------------------------------------------------------
49 static USHORT pProtectionRanges
[] =
51 SID_SCATTR_PROTECTION
,
52 SID_SCATTR_PROTECTION
,
56 //========================================================================
57 // Zellschutz-Tabpage:
58 //========================================================================
60 ScTabPageProtection::ScTabPageProtection( Window
* pParent
,
61 const SfxItemSet
& rCoreAttrs
)
62 : SfxTabPage ( pParent
,
63 ScResId( RID_SCPAGE_PROTECTION
),
66 aFlProtect ( this, ScResId( FL_PROTECTION
) ),
67 aBtnHideCell ( this, ScResId( BTN_HIDE_ALL
) ),
68 aBtnProtect ( this, ScResId( BTN_PROTECTED
) ),
69 aBtnHideFormula ( this, ScResId( BTN_HIDE_FORMULAR
) ),
70 aTxtHint ( this, ScResId( FT_HINT
) ),
71 aFlPrint ( this, ScResId( FL_PRINT
) ),
72 aBtnHidePrint ( this, ScResId( BTN_HIDE_PRINT
) ),
73 aTxtHint2 ( this, ScResId( FT_HINT2
) )
75 // diese Page braucht ExchangeSupport
78 // States werden in Reset gesetzt
79 bTriEnabled
= bDontCare
= bProtect
= bHideForm
= bHideCell
= bHidePrint
= FALSE
;
81 aBtnProtect
.SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
82 aBtnHideCell
.SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
83 aBtnHideFormula
.SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
84 aBtnHidePrint
.SetClickHdl( LINK( this, ScTabPageProtection
, ButtonClickHdl
) );
89 // -----------------------------------------------------------------------
91 __EXPORT
ScTabPageProtection::~ScTabPageProtection()
95 //------------------------------------------------------------------------
97 USHORT
* __EXPORT
ScTabPageProtection::GetRanges()
99 return pProtectionRanges
;
102 // -----------------------------------------------------------------------
104 SfxTabPage
* __EXPORT
ScTabPageProtection::Create( Window
* pParent
,
105 const SfxItemSet
& rAttrSet
)
107 return ( new ScTabPageProtection( pParent
, rAttrSet
) );
110 //------------------------------------------------------------------------
112 void __EXPORT
ScTabPageProtection::Reset( const SfxItemSet
& rCoreAttrs
)
114 // Variablen initialisieren
116 USHORT nWhich
= GetWhich( SID_SCATTR_PROTECTION
);
117 const ScProtectionAttr
* pProtAttr
= NULL
;
118 SfxItemState eItemState
= rCoreAttrs
.GetItemState( nWhich
, FALSE
,
119 (const SfxPoolItem
**)&pProtAttr
);
121 // handelt es sich um ein Default-Item?
122 if ( eItemState
== SFX_ITEM_DEFAULT
)
123 pProtAttr
= (const ScProtectionAttr
*)&(rCoreAttrs
.Get(nWhich
));
124 // bei SFX_ITEM_DONTCARE auf 0 lassen
126 bTriEnabled
= ( pProtAttr
== NULL
); // TriState, wenn DontCare
127 bDontCare
= bTriEnabled
;
130 // Defaults, die erscheinen wenn ein TriState weggeklickt wird:
131 // (weil alles zusammen ein Attribut ist, kann auch nur alles zusammen
132 // auf DontCare stehen - #38543#)
134 bHideForm
= bHideCell
= bHidePrint
= FALSE
;
138 bProtect
= pProtAttr
->GetProtection();
139 bHideCell
= pProtAttr
->GetHideCell();
140 bHideForm
= pProtAttr
->GetHideFormula();
141 bHidePrint
= pProtAttr
->GetHidePrint();
144 // Controls initialisieren
146 aBtnProtect
.EnableTriState( bTriEnabled
);
147 aBtnHideCell
.EnableTriState( bTriEnabled
);
148 aBtnHideFormula
.EnableTriState( bTriEnabled
);
149 aBtnHidePrint
.EnableTriState( bTriEnabled
);
154 // -----------------------------------------------------------------------
156 BOOL __EXPORT
ScTabPageProtection::FillItemSet( SfxItemSet
& rCoreAttrs
)
158 BOOL bAttrsChanged
= FALSE
;
159 USHORT nWhich
= GetWhich( SID_SCATTR_PROTECTION
);
160 const SfxPoolItem
* pOldItem
= GetOldItem( rCoreAttrs
, SID_SCATTR_PROTECTION
);
161 const SfxItemSet
& rOldSet
= GetItemSet();
162 SfxItemState eItemState
= rOldSet
.GetItemState( nWhich
, FALSE
);
163 ScProtectionAttr aProtAttr
;
167 aProtAttr
.SetProtection( bProtect
);
168 aProtAttr
.SetHideCell( bHideCell
);
169 aProtAttr
.SetHideFormula( bHideForm
);
170 aProtAttr
.SetHidePrint( bHidePrint
);
173 bAttrsChanged
= TRUE
; // DontCare -> richtiger Wert
175 bAttrsChanged
= !pOldItem
|| !( aProtAttr
== *(const ScProtectionAttr
*)pOldItem
);
178 //--------------------------------------------------
181 rCoreAttrs
.Put( aProtAttr
);
182 else if ( eItemState
== SFX_ITEM_DEFAULT
)
183 rCoreAttrs
.ClearItem( nWhich
);
185 return bAttrsChanged
;
188 //------------------------------------------------------------------------
190 int __EXPORT
ScTabPageProtection::DeactivatePage( SfxItemSet
* pSetP
)
193 FillItemSet( *pSetP
);
198 //------------------------------------------------------------------------
200 IMPL_LINK( ScTabPageProtection
, ButtonClickHdl
, TriStateBox
*, pBox
)
202 TriState eState
= pBox
->GetState();
203 if ( eState
== STATE_DONTKNOW
)
204 bDontCare
= TRUE
; // alles zusammen auf DontCare
207 bDontCare
= FALSE
; // DontCare ueberall aus
208 BOOL bOn
= ( eState
== STATE_CHECK
); // ausgewaehlter Wert
210 if ( pBox
== &aBtnProtect
)
212 else if ( pBox
== &aBtnHideCell
)
214 else if ( pBox
== &aBtnHideFormula
)
216 else if ( pBox
== &aBtnHidePrint
)
220 DBG_ERRORFILE("falscher Button");
224 UpdateButtons(); // TriState und Enable-Logik
229 //------------------------------------------------------------------------
231 void ScTabPageProtection::UpdateButtons()
235 aBtnProtect
.SetState( STATE_DONTKNOW
);
236 aBtnHideCell
.SetState( STATE_DONTKNOW
);
237 aBtnHideFormula
.SetState( STATE_DONTKNOW
);
238 aBtnHidePrint
.SetState( STATE_DONTKNOW
);
242 aBtnProtect
.SetState( bProtect
? STATE_CHECK
: STATE_NOCHECK
);
243 aBtnHideCell
.SetState( bHideCell
? STATE_CHECK
: STATE_NOCHECK
);
244 aBtnHideFormula
.SetState( bHideForm
? STATE_CHECK
: STATE_NOCHECK
);
245 aBtnHidePrint
.SetState( bHidePrint
? STATE_CHECK
: STATE_NOCHECK
);
248 BOOL bEnable
= ( aBtnHideCell
.GetState() != STATE_CHECK
);
250 aBtnProtect
.Enable( bEnable
);
251 aBtnHideFormula
.Enable( bEnable
);