Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "protectiondlg.hxx"
31 : : #include "protectiondlg.hrc"
32 : : #include "scresid.hxx"
33 : : #include "tabprotection.hxx"
34 : :
35 : : #include <sal/macros.h>
36 : : #include <vcl/msgbox.hxx>
37 : :
38 : :
39 : : // The order must match that of the list box.
40 : : static const ScTableProtection::Option aOptions[] = {
41 : : ScTableProtection::SELECT_LOCKED_CELLS,
42 : : ScTableProtection::SELECT_UNLOCKED_CELLS,
43 : : };
44 : : static const sal_uInt16 nOptionCount = sizeof(aOptions) / sizeof (aOptions[0]);
45 : :
46 : :
47 : 0 : ScTableProtectionDlg::ScTableProtectionDlg(Window* pParent) :
48 : : ModalDialog(pParent, ScResId(RID_SCDLG_TABPROTECTION)),
49 : :
50 : : maBtnProtect (this, ScResId(BTN_PROTECT)),
51 : : maPassword1Text (this, ScResId(FT_PASSWORD1)),
52 : : maPassword1Edit (this, ScResId(ED_PASSWORD1)),
53 : : maPassword2Text (this, ScResId(FT_PASSWORD2)),
54 : : maPassword2Edit (this, ScResId(ED_PASSWORD2)),
55 : : maOptionsLine (this, ScResId(FL_OPTIONS)),
56 : : maOptionsText (this, ScResId(FT_OPTIONS)),
57 : : maOptionsListBox(this, ScResId(CLB_OPTIONS)),
58 : :
59 : : maBtnOk (this, ScResId(BTN_OK)),
60 : : maBtnCancel (this, ScResId(BTN_CANCEL)),
61 : : maBtnHelp (this, ScResId(BTN_HELP)),
62 : :
63 : : maSelectLockedCells(ScResId(ST_SELECT_PROTECTED_CELLS)),
64 [ # # ][ # # ]: 0 : maSelectUnlockedCells(ScResId(ST_SELECT_UNPROTECTED_CELLS))
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
65 : : {
66 [ # # ]: 0 : Init();
67 [ # # ]: 0 : FreeResource();
68 : 0 : }
69 : :
70 [ # # ][ # # ]: 0 : ScTableProtectionDlg::~ScTableProtectionDlg()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
71 : : {
72 [ # # ]: 0 : }
73 : :
74 : 0 : short ScTableProtectionDlg::Execute()
75 : : {
76 : 0 : return ModalDialog::Execute();
77 : : }
78 : :
79 : 0 : void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData)
80 : : {
81 [ # # ]: 0 : for (sal_uInt16 i = 0; i < nOptionCount; ++i)
82 : 0 : maOptionsListBox.CheckEntryPos(i, rData.isOptionEnabled(aOptions[i]));
83 : 0 : }
84 : :
85 : 0 : void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const
86 : : {
87 : 0 : rData.setProtected(maBtnProtect.IsChecked());
88 : :
89 : : // We assume that the two password texts match.
90 [ # # ]: 0 : rData.setPassword(maPassword1Edit.GetText());
91 : :
92 [ # # ]: 0 : for (sal_uInt16 i = 0; i < nOptionCount; ++i)
93 : 0 : rData.setOption(aOptions[i], maOptionsListBox.IsChecked(i));
94 : 0 : }
95 : :
96 : 0 : void ScTableProtectionDlg::Init()
97 : : {
98 [ # # ]: 0 : Link aLink = LINK( this, ScTableProtectionDlg, CheckBoxHdl );
99 : 0 : maBtnProtect.SetClickHdl(aLink);
100 : :
101 [ # # ]: 0 : aLink = LINK( this, ScTableProtectionDlg, OKHdl );
102 : 0 : maBtnOk.SetClickHdl(aLink);
103 : :
104 [ # # ]: 0 : aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl );
105 : 0 : maPassword1Edit.SetModifyHdl(aLink);
106 : 0 : maPassword2Edit.SetModifyHdl(aLink);
107 : :
108 [ # # ]: 0 : maOptionsListBox.SetUpdateMode(false);
109 [ # # ]: 0 : maOptionsListBox.Clear();
110 : :
111 [ # # ]: 0 : maOptionsListBox.InsertEntry(maSelectLockedCells);
112 [ # # ]: 0 : maOptionsListBox.InsertEntry(maSelectUnlockedCells);
113 : :
114 [ # # ]: 0 : maOptionsListBox.CheckEntryPos(0, true);
115 [ # # ]: 0 : maOptionsListBox.CheckEntryPos(1, true);
116 : :
117 [ # # ]: 0 : maOptionsListBox.SetUpdateMode(true);
118 : :
119 : : // Set the default state of the dialog.
120 [ # # ]: 0 : maBtnProtect.Check(true);
121 [ # # ]: 0 : maPassword1Edit.GrabFocus();
122 : 0 : }
123 : :
124 : 0 : void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable)
125 : : {
126 : 0 : maPassword1Text.Enable(bEnable);
127 : 0 : maPassword1Edit.Enable(bEnable);
128 : 0 : maPassword2Text.Enable(bEnable);
129 : 0 : maPassword2Edit.Enable(bEnable);
130 : 0 : maOptionsLine.Enable(bEnable);
131 : 0 : maOptionsText.Enable(bEnable);
132 : :
133 : 0 : maOptionsListBox.Enable(bEnable);
134 : 0 : maOptionsListBox.Invalidate();
135 : 0 : }
136 : :
137 : 0 : IMPL_LINK( ScTableProtectionDlg, CheckBoxHdl, CheckBox*, pBtn )
138 : : {
139 [ # # ]: 0 : if (pBtn == &maBtnProtect)
140 : : {
141 : 0 : bool bChecked = maBtnProtect.IsChecked();
142 : 0 : EnableOptionalWidgets(bChecked);
143 : 0 : maBtnOk.Enable(bChecked);
144 : : }
145 : :
146 : 0 : return 0;
147 : : }
148 : :
149 : 0 : IMPL_LINK_NOARG(ScTableProtectionDlg, OKHdl)
150 : : {
151 : 0 : EndDialog(RET_OK);
152 : 0 : return 0;
153 : : }
154 : :
155 : 0 : IMPL_LINK_NOARG(ScTableProtectionDlg, PasswordModifyHdl)
156 : : {
157 [ # # ]: 0 : String aPass1 = maPassword1Edit.GetText();
158 [ # # ]: 0 : String aPass2 = maPassword2Edit.GetText();
159 [ # # ][ # # ]: 0 : maBtnOk.Enable(aPass1.Equals(aPass2));
160 [ # # ][ # # ]: 0 : return 0;
161 : : }
162 : :
163 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|