1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "protectiondlg.hxx"
28cdf0e10cSrcweir #include "protectiondlg.hrc"
29cdf0e10cSrcweir #include "scresid.hxx"
30cdf0e10cSrcweir #include "tabprotection.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <vcl/msgbox.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // The order must match that of the list box.
36cdf0e10cSrcweir static const ScTableProtection::Option aOptions[] = {
37cdf0e10cSrcweir     ScTableProtection::SELECT_LOCKED_CELLS,
38cdf0e10cSrcweir     ScTableProtection::SELECT_UNLOCKED_CELLS,
39cdf0e10cSrcweir };
40cdf0e10cSrcweir static const sal_uInt16 nOptionCount = sizeof(aOptions)/sizeof(aOptions[0]);
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
ScTableProtectionDlg(Window * pParent)43cdf0e10cSrcweir ScTableProtectionDlg::ScTableProtectionDlg(Window* pParent) :
44cdf0e10cSrcweir     ModalDialog(pParent, ScResId(RID_SCDLG_TABPROTECTION)),
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     maBtnProtect    (this, ScResId(BTN_PROTECT)),
47cdf0e10cSrcweir     maPassword1Text (this, ScResId(FT_PASSWORD1)),
48cdf0e10cSrcweir     maPassword1Edit (this, ScResId(ED_PASSWORD1)),
49cdf0e10cSrcweir     maPassword2Text (this, ScResId(FT_PASSWORD2)),
50cdf0e10cSrcweir     maPassword2Edit (this, ScResId(ED_PASSWORD2)),
51cdf0e10cSrcweir     maOptionsLine   (this, ScResId(FL_OPTIONS)),
52cdf0e10cSrcweir     maOptionsText   (this, ScResId(FT_OPTIONS)),
53cdf0e10cSrcweir     maOptionsListBox(this, ScResId(CLB_OPTIONS)),
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     maBtnOk     (this, ScResId(BTN_OK)),
56cdf0e10cSrcweir     maBtnCancel (this, ScResId(BTN_CANCEL)),
57cdf0e10cSrcweir     maBtnHelp   (this, ScResId(BTN_HELP)),
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     maSelectLockedCells(ScResId(ST_SELECT_LOCKED_CELLS)),
60cdf0e10cSrcweir     maSelectUnlockedCells(ScResId(ST_SELECT_UNLOCKED_CELLS))
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     Init();
63cdf0e10cSrcweir     FreeResource();
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
~ScTableProtectionDlg()66cdf0e10cSrcweir ScTableProtectionDlg::~ScTableProtectionDlg()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
Execute()70cdf0e10cSrcweir short ScTableProtectionDlg::Execute()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     return ModalDialog::Execute();
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
SetDialogData(const ScTableProtection & rData)75cdf0e10cSrcweir void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     for (sal_uInt16 i = 0; i < nOptionCount; ++i)
78cdf0e10cSrcweir         maOptionsListBox.CheckEntryPos(i, rData.isOptionEnabled(aOptions[i]));
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
WriteData(ScTableProtection & rData) const81cdf0e10cSrcweir void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     rData.setProtected(maBtnProtect.IsChecked());
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     // We assume that the two password texts match.
86cdf0e10cSrcweir     rData.setPassword(maPassword1Edit.GetText());
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     for (sal_uInt16 i = 0; i < nOptionCount; ++i)
89cdf0e10cSrcweir         rData.setOption(aOptions[i], maOptionsListBox.IsChecked(i));
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
Init()92cdf0e10cSrcweir void ScTableProtectionDlg::Init()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     Link aLink = LINK( this, ScTableProtectionDlg, CheckBoxHdl );
95cdf0e10cSrcweir     maBtnProtect.SetClickHdl(aLink);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     aLink = LINK( this, ScTableProtectionDlg, OKHdl );
98cdf0e10cSrcweir     maBtnOk.SetClickHdl(aLink);
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl );
101cdf0e10cSrcweir     maPassword1Edit.SetModifyHdl(aLink);
102cdf0e10cSrcweir     maPassword2Edit.SetModifyHdl(aLink);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     maOptionsListBox.SetUpdateMode(false);
105cdf0e10cSrcweir     maOptionsListBox.Clear();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     maOptionsListBox.InsertEntry(maSelectLockedCells);
108cdf0e10cSrcweir     maOptionsListBox.InsertEntry(maSelectUnlockedCells);
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     maOptionsListBox.CheckEntryPos(0, true);
111cdf0e10cSrcweir     maOptionsListBox.CheckEntryPos(1, true);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     maOptionsListBox.SetUpdateMode(true);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     // Set the default state of the dialog.
116cdf0e10cSrcweir     maBtnProtect.Check(true);
117cdf0e10cSrcweir     maPassword1Edit.GrabFocus();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
EnableOptionalWidgets(bool bEnable)120cdf0e10cSrcweir void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     maPassword1Text.Enable(bEnable);
123cdf0e10cSrcweir     maPassword1Edit.Enable(bEnable);
124cdf0e10cSrcweir     maPassword2Text.Enable(bEnable);
125cdf0e10cSrcweir     maPassword2Edit.Enable(bEnable);
126cdf0e10cSrcweir     maOptionsLine.Enable(bEnable);
127cdf0e10cSrcweir     maOptionsText.Enable(bEnable);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     maOptionsListBox.Enable(bEnable);
130cdf0e10cSrcweir     maOptionsListBox.Invalidate();
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
IMPL_LINK(ScTableProtectionDlg,CheckBoxHdl,CheckBox *,pBtn)133cdf0e10cSrcweir IMPL_LINK( ScTableProtectionDlg, CheckBoxHdl, CheckBox*, pBtn )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     if (pBtn == &maBtnProtect)
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         bool bChecked = maBtnProtect.IsChecked();
138cdf0e10cSrcweir         EnableOptionalWidgets(bChecked);
139cdf0e10cSrcweir         maBtnOk.Enable(bChecked);
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     return 0;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
IMPL_LINK(ScTableProtectionDlg,OKHdl,OKButton *,EMPTYARG)145cdf0e10cSrcweir IMPL_LINK( ScTableProtectionDlg, OKHdl, OKButton*, EMPTYARG )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     EndDialog(RET_OK);
148cdf0e10cSrcweir     return 0;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
IMPL_LINK(ScTableProtectionDlg,PasswordModifyHdl,Edit *,EMPTYARG)151cdf0e10cSrcweir IMPL_LINK( ScTableProtectionDlg, PasswordModifyHdl, Edit*, EMPTYARG )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     String aPass1 = maPassword1Edit.GetText();
154cdf0e10cSrcweir     String aPass2 = maPassword2Edit.GetText();
155cdf0e10cSrcweir     maBtnOk.Enable(aPass1.Equals(aPass2));
156cdf0e10cSrcweir     return 0;
157cdf0e10cSrcweir }
158