1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "protectiondlg.hxx"
22 #include "protectiondlg.hrc"
23 #include "scresid.hxx"
24 #include "tabprotection.hxx"
26 #include <sal/macros.h>
27 #include <vcl/msgbox.hxx>
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
,
35 static const sal_uInt16 nOptionCount
= sizeof(aOptions
) / sizeof (aOptions
[0]);
38 ScTableProtectionDlg::ScTableProtectionDlg(Window
* pParent
) :
39 ModalDialog(pParent
, ScResId(RID_SCDLG_TABPROTECTION
)),
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
)),
50 maBtnOk (this, ScResId(BTN_OK
)),
51 maBtnCancel (this, ScResId(BTN_CANCEL
)),
52 maBtnHelp (this, ScResId(BTN_HELP
)),
54 maSelectLockedCells(ScResId(ST_SELECT_PROTECTED_CELLS
)),
55 maSelectUnlockedCells(ScResId(ST_SELECT_UNPROTECTED_CELLS
))
61 ScTableProtectionDlg::~ScTableProtectionDlg()
65 short ScTableProtectionDlg::Execute()
67 return ModalDialog::Execute();
70 void ScTableProtectionDlg::SetDialogData(const ScTableProtection
& rData
)
72 for (sal_uInt16 i
= 0; i
< nOptionCount
; ++i
)
73 maOptionsListBox
.CheckEntryPos(i
, rData
.isOptionEnabled(aOptions
[i
]));
76 void ScTableProtectionDlg::WriteData(ScTableProtection
& rData
) const
78 rData
.setProtected(maBtnProtect
.IsChecked());
80 // We assume that the two password texts match.
81 rData
.setPassword(maPassword1Edit
.GetText());
83 for (sal_uInt16 i
= 0; i
< nOptionCount
; ++i
)
84 rData
.setOption(aOptions
[i
], maOptionsListBox
.IsChecked(i
));
87 void ScTableProtectionDlg::Init()
89 Link aLink
= LINK( this, ScTableProtectionDlg
, CheckBoxHdl
);
90 maBtnProtect
.SetClickHdl(aLink
);
92 aLink
= LINK( this, ScTableProtectionDlg
, OKHdl
);
93 maBtnOk
.SetClickHdl(aLink
);
95 aLink
= LINK( this, ScTableProtectionDlg
, PasswordModifyHdl
);
96 maPassword1Edit
.SetModifyHdl(aLink
);
97 maPassword2Edit
.SetModifyHdl(aLink
);
99 maOptionsListBox
.SetUpdateMode(false);
100 maOptionsListBox
.Clear();
102 maOptionsListBox
.InsertEntry(maSelectLockedCells
);
103 maOptionsListBox
.InsertEntry(maSelectUnlockedCells
);
105 maOptionsListBox
.CheckEntryPos(0, true);
106 maOptionsListBox
.CheckEntryPos(1, true);
108 maOptionsListBox
.SetUpdateMode(true);
110 // Set the default state of the dialog.
111 maBtnProtect
.Check(true);
112 maPassword1Edit
.GrabFocus();
115 void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable
)
117 maPassword1Text
.Enable(bEnable
);
118 maPassword1Edit
.Enable(bEnable
);
119 maPassword2Text
.Enable(bEnable
);
120 maPassword2Edit
.Enable(bEnable
);
121 maOptionsLine
.Enable(bEnable
);
122 maOptionsText
.Enable(bEnable
);
124 maOptionsListBox
.Enable(bEnable
);
125 maOptionsListBox
.Invalidate();
128 IMPL_LINK( ScTableProtectionDlg
, CheckBoxHdl
, CheckBox
*, pBtn
)
130 if (pBtn
== &maBtnProtect
)
132 bool bChecked
= maBtnProtect
.IsChecked();
133 EnableOptionalWidgets(bChecked
);
134 maBtnOk
.Enable(bChecked
);
140 IMPL_LINK_NOARG(ScTableProtectionDlg
, OKHdl
)
146 IMPL_LINK_NOARG(ScTableProtectionDlg
, PasswordModifyHdl
)
148 String aPass1
= maPassword1Edit
.GetText();
149 String aPass2
= maPassword2Edit
.GetText();
150 maBtnOk
.Enable(aPass1
.Equals(aPass2
));
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */