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 : #include "protectiondlg.hxx"
22 : #include "protectiondlg.hrc"
23 : #include "scresid.hxx"
24 : #include "tabprotection.hxx"
25 :
26 : #include <sal/macros.h>
27 : #include <vcl/msgbox.hxx>
28 :
29 :
30 : // The order must match that of the list box.
31 : static const ScTableProtection::Option aOptions[] = {
32 : ScTableProtection::SELECT_LOCKED_CELLS,
33 : ScTableProtection::SELECT_UNLOCKED_CELLS,
34 : };
35 : static const sal_uInt16 nOptionCount = sizeof(aOptions) / sizeof (aOptions[0]);
36 :
37 :
38 0 : ScTableProtectionDlg::ScTableProtectionDlg(Window* pParent) :
39 : ModalDialog(pParent, ScResId(RID_SCDLG_TABPROTECTION)),
40 :
41 : maBtnProtect (this, ScResId(BTN_PROTECT)),
42 : maPassword1Text (this, ScResId(FT_PASSWORD1)),
43 : maPassword1Edit (this, ScResId(ED_PASSWORD1)),
44 : maPassword2Text (this, ScResId(FT_PASSWORD2)),
45 : maPassword2Edit (this, ScResId(ED_PASSWORD2)),
46 : maOptionsLine (this, ScResId(FL_OPTIONS)),
47 : maOptionsText (this, ScResId(FT_OPTIONS)),
48 : maOptionsListBox(this, ScResId(CLB_OPTIONS)),
49 :
50 : maBtnOk (this, ScResId(BTN_OK)),
51 : maBtnCancel (this, ScResId(BTN_CANCEL)),
52 : maBtnHelp (this, ScResId(BTN_HELP)),
53 :
54 : maSelectLockedCells(ScResId(ST_SELECT_PROTECTED_CELLS)),
55 0 : maSelectUnlockedCells(ScResId(ST_SELECT_UNPROTECTED_CELLS))
56 : {
57 0 : Init();
58 0 : FreeResource();
59 0 : }
60 :
61 0 : ScTableProtectionDlg::~ScTableProtectionDlg()
62 : {
63 0 : }
64 :
65 0 : short ScTableProtectionDlg::Execute()
66 : {
67 0 : return ModalDialog::Execute();
68 : }
69 :
70 0 : void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData)
71 : {
72 0 : for (sal_uInt16 i = 0; i < nOptionCount; ++i)
73 0 : maOptionsListBox.CheckEntryPos(i, rData.isOptionEnabled(aOptions[i]));
74 0 : }
75 :
76 0 : void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const
77 : {
78 0 : rData.setProtected(maBtnProtect.IsChecked());
79 :
80 : // We assume that the two password texts match.
81 0 : rData.setPassword(maPassword1Edit.GetText());
82 :
83 0 : for (sal_uInt16 i = 0; i < nOptionCount; ++i)
84 0 : rData.setOption(aOptions[i], maOptionsListBox.IsChecked(i));
85 0 : }
86 :
87 0 : void ScTableProtectionDlg::Init()
88 : {
89 0 : Link aLink = LINK( this, ScTableProtectionDlg, CheckBoxHdl );
90 0 : maBtnProtect.SetClickHdl(aLink);
91 :
92 0 : aLink = LINK( this, ScTableProtectionDlg, OKHdl );
93 0 : maBtnOk.SetClickHdl(aLink);
94 :
95 0 : aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl );
96 0 : maPassword1Edit.SetModifyHdl(aLink);
97 0 : maPassword2Edit.SetModifyHdl(aLink);
98 :
99 0 : maOptionsListBox.SetUpdateMode(false);
100 0 : maOptionsListBox.Clear();
101 :
102 0 : maOptionsListBox.InsertEntry(maSelectLockedCells);
103 0 : maOptionsListBox.InsertEntry(maSelectUnlockedCells);
104 :
105 0 : maOptionsListBox.CheckEntryPos(0, true);
106 0 : maOptionsListBox.CheckEntryPos(1, true);
107 :
108 0 : maOptionsListBox.SetUpdateMode(true);
109 :
110 : // Set the default state of the dialog.
111 0 : maBtnProtect.Check(true);
112 0 : maPassword1Edit.GrabFocus();
113 0 : }
114 :
115 0 : void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable)
116 : {
117 0 : maPassword1Text.Enable(bEnable);
118 0 : maPassword1Edit.Enable(bEnable);
119 0 : maPassword2Text.Enable(bEnable);
120 0 : maPassword2Edit.Enable(bEnable);
121 0 : maOptionsLine.Enable(bEnable);
122 0 : maOptionsText.Enable(bEnable);
123 :
124 0 : maOptionsListBox.Enable(bEnable);
125 0 : maOptionsListBox.Invalidate();
126 0 : }
127 :
128 0 : IMPL_LINK( ScTableProtectionDlg, CheckBoxHdl, CheckBox*, pBtn )
129 : {
130 0 : if (pBtn == &maBtnProtect)
131 : {
132 0 : bool bChecked = maBtnProtect.IsChecked();
133 0 : EnableOptionalWidgets(bChecked);
134 0 : maBtnOk.Enable(bChecked);
135 : }
136 :
137 0 : return 0;
138 : }
139 :
140 0 : IMPL_LINK_NOARG(ScTableProtectionDlg, OKHdl)
141 : {
142 0 : EndDialog(RET_OK);
143 0 : return 0;
144 : }
145 :
146 0 : IMPL_LINK_NOARG(ScTableProtectionDlg, PasswordModifyHdl)
147 : {
148 0 : String aPass1 = maPassword1Edit.GetText();
149 0 : String aPass2 = maPassword2Edit.GetText();
150 0 : maBtnOk.Enable(aPass1.Equals(aPass2));
151 0 : return 0;
152 : }
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|