Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / miscdlgs / protectiondlg.cxx
blobb7e5e0eea0e3742c366fba135d54495d335ea452
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "protectiondlg.hxx"
21 #include "scresid.hxx"
22 #include "tabprotection.hxx"
24 #include <sal/macros.h>
25 #include <vcl/msgbox.hxx>
27 // The order must match that of the list box.
28 static const ScTableProtection::Option aOptions[] = {
29 ScTableProtection::SELECT_LOCKED_CELLS,
30 ScTableProtection::SELECT_UNLOCKED_CELLS,
32 static const sal_uInt16 nOptionCount = SAL_N_ELEMENTS(aOptions);
34 ScTableProtectionDlg::ScTableProtectionDlg(vcl::Window* pParent)
35 : ModalDialog( pParent, "ProtectSheetDialog", "modules/scalc/ui/protectsheetdlg.ui" )
37 get(m_pPasswords, "passwords");
38 get(m_pOptions, "options");
39 get(m_pBtnProtect, "protect");
40 get(m_pOptionsListBox, "checklist");
41 get(m_pPassword1Edit, "password1");
42 get(m_pPassword2Edit, "password2");
43 get(m_pBtnOk, "ok");
45 m_aSelectLockedCells = get<FixedText>("protected")->GetText();
46 m_aSelectUnlockedCells = get<FixedText>("unprotected")->GetText();
48 Init();
51 ScTableProtectionDlg::~ScTableProtectionDlg()
53 disposeOnce();
56 void ScTableProtectionDlg::dispose()
58 m_pBtnProtect.clear();
59 m_pPasswords.clear();
60 m_pOptions.clear();
61 m_pPassword1Edit.clear();
62 m_pPassword2Edit.clear();
63 m_pOptionsListBox.clear();
64 m_pBtnOk.clear();
65 ModalDialog::dispose();
68 short ScTableProtectionDlg::Execute()
70 return ModalDialog::Execute();
73 void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData)
75 for (sal_uInt16 i = 0; i < nOptionCount; ++i)
76 m_pOptionsListBox->CheckEntryPos(i, rData.isOptionEnabled(aOptions[i]));
79 void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const
81 rData.setProtected(m_pBtnProtect->IsChecked());
83 // We assume that the two password texts match.
84 rData.setPassword(m_pPassword1Edit->GetText());
86 for (sal_uInt16 i = 0; i < nOptionCount; ++i)
87 rData.setOption(aOptions[i], m_pOptionsListBox->IsChecked(i));
90 void ScTableProtectionDlg::Init()
92 m_pBtnProtect->SetClickHdl(LINK( this, ScTableProtectionDlg, CheckBoxHdl ));
94 m_pBtnOk->SetClickHdl(LINK( this, ScTableProtectionDlg, OKHdl ));
96 Link<Edit&,void> aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl );
97 m_pPassword1Edit->SetModifyHdl(aLink);
98 m_pPassword2Edit->SetModifyHdl(aLink);
100 m_pOptionsListBox->SetUpdateMode(false);
101 m_pOptionsListBox->Clear();
103 m_pOptionsListBox->InsertEntry(m_aSelectLockedCells);
104 m_pOptionsListBox->InsertEntry(m_aSelectUnlockedCells);
106 m_pOptionsListBox->CheckEntryPos(0);
107 m_pOptionsListBox->CheckEntryPos(1);
109 m_pOptionsListBox->SetUpdateMode(true);
111 // Set the default state of the dialog.
112 m_pBtnProtect->Check();
113 m_pPassword1Edit->GrabFocus();
116 void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable)
118 m_pPasswords->Enable(bEnable);
119 m_pOptions->Enable(bEnable);
120 m_pOptionsListBox->Invalidate();
123 IMPL_LINK_TYPED( ScTableProtectionDlg, CheckBoxHdl, Button*, pBtn, void )
125 if (pBtn == m_pBtnProtect)
127 bool bChecked = m_pBtnProtect->IsChecked();
128 EnableOptionalWidgets(bChecked);
129 m_pBtnOk->Enable(bChecked);
133 IMPL_LINK_NOARG_TYPED(ScTableProtectionDlg, OKHdl, Button*, void)
135 EndDialog(RET_OK);
138 IMPL_LINK_NOARG_TYPED(ScTableProtectionDlg, PasswordModifyHdl, Edit&, void)
140 OUString aPass1 = m_pPassword1Edit->GetText();
141 OUString aPass2 = m_pPassword2Edit->GetText();
142 m_pBtnOk->Enable(aPass1 == aPass2);
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */