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: protectiondlg.cxx,v $
10 * $Revision: 1.1.2.6 $
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 #include "protectiondlg.hxx"
35 #include "protectiondlg.hrc"
36 #include "scresid.hxx"
37 #include "tabprotection.hxx"
39 #include <vcl/msgbox.hxx>
42 // The order must match that of the list box.
43 static const ScTableProtection::Option aOptions
[] = {
44 ScTableProtection::SELECT_LOCKED_CELLS
,
45 ScTableProtection::SELECT_UNLOCKED_CELLS
,
47 static const USHORT nOptionCount
= sizeof(aOptions
)/sizeof(aOptions
[0]);
50 ScTableProtectionDlg::ScTableProtectionDlg(Window
* pParent
) :
51 ModalDialog(pParent
, ScResId(RID_SCDLG_TABPROTECTION
)),
53 maBtnProtect (this, ScResId(BTN_PROTECT
)),
54 maPassword1Text (this, ScResId(FT_PASSWORD1
)),
55 maPassword1Edit (this, ScResId(ED_PASSWORD1
)),
56 maPassword2Text (this, ScResId(FT_PASSWORD2
)),
57 maPassword2Edit (this, ScResId(ED_PASSWORD2
)),
58 maOptionsLine (this, ScResId(FL_OPTIONS
)),
59 maOptionsText (this, ScResId(FT_OPTIONS
)),
60 maOptionsListBox(this, ScResId(CLB_OPTIONS
)),
62 maBtnOk (this, ScResId(BTN_OK
)),
63 maBtnCancel (this, ScResId(BTN_CANCEL
)),
64 maBtnHelp (this, ScResId(BTN_HELP
)),
66 maSelectLockedCells(ScResId(ST_SELECT_LOCKED_CELLS
)),
67 maSelectUnlockedCells(ScResId(ST_SELECT_UNLOCKED_CELLS
))
73 ScTableProtectionDlg::~ScTableProtectionDlg()
77 short ScTableProtectionDlg::Execute()
79 return ModalDialog::Execute();
82 void ScTableProtectionDlg::SetDialogData(const ScTableProtection
& rData
)
84 for (USHORT i
= 0; i
< nOptionCount
; ++i
)
85 maOptionsListBox
.CheckEntryPos(i
, rData
.isOptionEnabled(aOptions
[i
]));
88 void ScTableProtectionDlg::WriteData(ScTableProtection
& rData
) const
90 rData
.setProtected(maBtnProtect
.IsChecked());
92 // We assume that the two password texts match.
93 rData
.setPassword(maPassword1Edit
.GetText());
95 for (USHORT i
= 0; i
< nOptionCount
; ++i
)
96 rData
.setOption(aOptions
[i
], maOptionsListBox
.IsChecked(i
));
99 void ScTableProtectionDlg::Init()
101 Link aLink
= LINK( this, ScTableProtectionDlg
, CheckBoxHdl
);
102 maBtnProtect
.SetClickHdl(aLink
);
104 aLink
= LINK( this, ScTableProtectionDlg
, OKHdl
);
105 maBtnOk
.SetClickHdl(aLink
);
107 aLink
= LINK( this, ScTableProtectionDlg
, PasswordModifyHdl
);
108 maPassword1Edit
.SetModifyHdl(aLink
);
109 maPassword2Edit
.SetModifyHdl(aLink
);
111 maOptionsListBox
.SetUpdateMode(false);
112 maOptionsListBox
.Clear();
114 maOptionsListBox
.InsertEntry(maSelectLockedCells
);
115 maOptionsListBox
.InsertEntry(maSelectUnlockedCells
);
117 maOptionsListBox
.CheckEntryPos(0, true);
118 maOptionsListBox
.CheckEntryPos(1, true);
120 maOptionsListBox
.SetUpdateMode(true);
122 // Set the default state of the dialog.
123 maBtnProtect
.Check(true);
124 maPassword1Edit
.GrabFocus();
127 void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable
)
129 maPassword1Text
.Enable(bEnable
);
130 maPassword1Edit
.Enable(bEnable
);
131 maPassword2Text
.Enable(bEnable
);
132 maPassword2Edit
.Enable(bEnable
);
133 maOptionsLine
.Enable(bEnable
);
134 maOptionsText
.Enable(bEnable
);
136 maOptionsListBox
.Enable(bEnable
);
137 maOptionsListBox
.Invalidate();
140 IMPL_LINK( ScTableProtectionDlg
, CheckBoxHdl
, CheckBox
*, pBtn
)
142 if (pBtn
== &maBtnProtect
)
144 bool bChecked
= maBtnProtect
.IsChecked();
145 EnableOptionalWidgets(bChecked
);
146 maBtnOk
.Enable(bChecked
);
152 IMPL_LINK( ScTableProtectionDlg
, OKHdl
, OKButton
*, EMPTYARG
)
158 IMPL_LINK( ScTableProtectionDlg
, PasswordModifyHdl
, Edit
*, EMPTYARG
)
160 String aPass1
= maPassword1Edit
.GetText();
161 String aPass2
= maPassword2Edit
.GetText();
162 maBtnOk
.Enable(aPass1
.Equals(aPass2
));