Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #undef SC_DLLIMPLEMENTATION
22 :
23 :
24 : #include "global.hxx"
25 : #include "document.hxx"
26 : #include "attrib.hxx"
27 : #include "scresid.hxx"
28 : #include "sc.hrc"
29 :
30 : #include "tabpages.hxx"
31 :
32 : // STATIC DATA -----------------------------------------------------------
33 :
34 : static sal_uInt16 pProtectionRanges[] =
35 : {
36 : SID_SCATTR_PROTECTION,
37 : SID_SCATTR_PROTECTION,
38 : 0
39 : };
40 :
41 :
42 : // Zellschutz-Tabpage:
43 :
44 :
45 0 : ScTabPageProtection::ScTabPageProtection(Window* pParent, const SfxItemSet& rCoreAttrs)
46 : : SfxTabPage(pParent, "CellProtectionPage",
47 0 : "modules/scalc/ui/cellprotectionpage.ui", rCoreAttrs)
48 : {
49 0 : get(m_pBtnHideCell,"checkHideAll");
50 0 : get(m_pBtnProtect,"checkProtected");
51 0 : get(m_pBtnHideFormula,"checkHideFormula");
52 0 : get(m_pBtnHidePrint,"checkHidePrinting");
53 :
54 : // This Page need ExchangeSupport
55 0 : SetExchangeSupport();
56 :
57 : // States will be set in Reset
58 0 : bTriEnabled = bDontCare = bProtect = bHideForm = bHideCell = bHidePrint = false;
59 :
60 0 : m_pBtnProtect->SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
61 0 : m_pBtnHideCell->SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
62 0 : m_pBtnHideFormula->SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
63 0 : m_pBtnHidePrint->SetClickHdl( LINK( this, ScTabPageProtection, ButtonClickHdl ) );
64 0 : }
65 :
66 0 : sal_uInt16* ScTabPageProtection::GetRanges()
67 : {
68 0 : return pProtectionRanges;
69 : }
70 :
71 0 : SfxTabPage* ScTabPageProtection::Create( Window* pParent, const SfxItemSet& rAttrSet )
72 : {
73 0 : return ( new ScTabPageProtection( pParent, rAttrSet ) );
74 : }
75 :
76 0 : void ScTabPageProtection::Reset( const SfxItemSet& rCoreAttrs )
77 : {
78 : // Initialize variables
79 :
80 0 : sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION );
81 0 : const ScProtectionAttr* pProtAttr = NULL;
82 : SfxItemState eItemState = rCoreAttrs.GetItemState( nWhich, false,
83 0 : (const SfxPoolItem**)&pProtAttr );
84 :
85 : // Is this a Default-Item?
86 0 : if ( eItemState == SFX_ITEM_DEFAULT )
87 0 : pProtAttr = (const ScProtectionAttr*)&(rCoreAttrs.Get(nWhich));
88 : // At SFX_ITEM_DONTCARE let to 0
89 :
90 0 : bTriEnabled = ( pProtAttr == NULL ); // TriState, when DontCare
91 0 : bDontCare = bTriEnabled;
92 0 : if (bTriEnabled)
93 : {
94 : // Defaults which appear when a TriState will be clicked away:
95 : // (because everything combined is an attribute, and also only
96 : // everything combined as DontCare can be available - #38543#)
97 :
98 0 : bProtect = true;
99 0 : bHideForm = bHideCell = bHidePrint = false;
100 : }
101 : else
102 : {
103 0 : bProtect = pProtAttr->GetProtection();
104 0 : bHideCell = pProtAttr->GetHideCell();
105 0 : bHideForm = pProtAttr->GetHideFormula();
106 0 : bHidePrint = pProtAttr->GetHidePrint();
107 : }
108 :
109 : // Start Controls
110 :
111 0 : m_pBtnProtect->EnableTriState( bTriEnabled );
112 0 : m_pBtnHideCell->EnableTriState( bTriEnabled );
113 0 : m_pBtnHideFormula->EnableTriState( bTriEnabled );
114 0 : m_pBtnHidePrint->EnableTriState( bTriEnabled );
115 :
116 0 : UpdateButtons();
117 0 : }
118 :
119 0 : bool ScTabPageProtection::FillItemSet( SfxItemSet& rCoreAttrs )
120 : {
121 0 : sal_Bool bAttrsChanged = false;
122 0 : sal_uInt16 nWhich = GetWhich( SID_SCATTR_PROTECTION );
123 0 : const SfxPoolItem* pOldItem = GetOldItem( rCoreAttrs, SID_SCATTR_PROTECTION );
124 0 : const SfxItemSet& rOldSet = GetItemSet();
125 0 : SfxItemState eItemState = rOldSet.GetItemState( nWhich, false );
126 0 : ScProtectionAttr aProtAttr;
127 :
128 0 : if ( !bDontCare )
129 : {
130 0 : aProtAttr.SetProtection( bProtect );
131 0 : aProtAttr.SetHideCell( bHideCell );
132 0 : aProtAttr.SetHideFormula( bHideForm );
133 0 : aProtAttr.SetHidePrint( bHidePrint );
134 :
135 0 : if ( bTriEnabled )
136 0 : bAttrsChanged = sal_True; // DontCare -> properly value
137 : else
138 0 : bAttrsChanged = !pOldItem || !( aProtAttr == *(const ScProtectionAttr*)pOldItem );
139 : }
140 :
141 0 : if ( bAttrsChanged )
142 0 : rCoreAttrs.Put( aProtAttr );
143 0 : else if ( eItemState == SFX_ITEM_DEFAULT )
144 0 : rCoreAttrs.ClearItem( nWhich );
145 :
146 0 : return bAttrsChanged;
147 : }
148 :
149 0 : int ScTabPageProtection::DeactivatePage( SfxItemSet* pSetP )
150 : {
151 0 : if ( pSetP )
152 0 : FillItemSet( *pSetP );
153 :
154 0 : return LEAVE_PAGE;
155 : }
156 :
157 0 : IMPL_LINK( ScTabPageProtection, ButtonClickHdl, TriStateBox*, pBox )
158 : {
159 0 : TriState eState = pBox->GetState();
160 0 : if ( eState == TRISTATE_INDET )
161 0 : bDontCare = true; // everything combined at DontCare
162 : else
163 : {
164 0 : bDontCare = false; // DontCare from everywhere
165 0 : sal_Bool bOn = ( eState == TRISTATE_TRUE ); // from a selected value
166 :
167 0 : if ( pBox == m_pBtnProtect )
168 0 : bProtect = bOn;
169 0 : else if ( pBox == m_pBtnHideCell )
170 0 : bHideCell = bOn;
171 0 : else if ( pBox == m_pBtnHideFormula )
172 0 : bHideForm = bOn;
173 0 : else if ( pBox == m_pBtnHidePrint )
174 0 : bHidePrint = bOn;
175 : else
176 : {
177 : OSL_FAIL("falscher Button");
178 : }
179 : }
180 :
181 0 : UpdateButtons(); // TriState and Logic-Enable
182 :
183 0 : return 0;
184 : }
185 :
186 0 : void ScTabPageProtection::UpdateButtons()
187 : {
188 0 : if ( bDontCare )
189 : {
190 0 : m_pBtnProtect->SetState( TRISTATE_INDET );
191 0 : m_pBtnHideCell->SetState( TRISTATE_INDET );
192 0 : m_pBtnHideFormula->SetState( TRISTATE_INDET );
193 0 : m_pBtnHidePrint->SetState( TRISTATE_INDET );
194 : }
195 : else
196 : {
197 0 : m_pBtnProtect->SetState( bProtect ? TRISTATE_TRUE : TRISTATE_FALSE );
198 0 : m_pBtnHideCell->SetState( bHideCell ? TRISTATE_TRUE : TRISTATE_FALSE );
199 0 : m_pBtnHideFormula->SetState( bHideForm ? TRISTATE_TRUE : TRISTATE_FALSE );
200 0 : m_pBtnHidePrint->SetState( bHidePrint ? TRISTATE_TRUE : TRISTATE_FALSE );
201 : }
202 :
203 0 : sal_Bool bEnable = ( m_pBtnHideCell->GetState() != TRISTATE_TRUE );
204 : {
205 0 : m_pBtnProtect->Enable( bEnable );
206 0 : m_pBtnHideFormula->Enable( bEnable );
207 : }
208 0 : }
209 :
210 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|