LibreOffice Module sc (master) 1
protectiondlg.cxx
Go to the documentation of this file.
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#include <protectiondlg.hxx>
21#include <tabprotection.hxx>
22
23#include <vector>
24
25namespace {
26
27// The order must match that of the list box.
28const std::vector<ScTableProtection::Option> aOptions = {
35};
36
37}
38
40 : weld::GenericDialogController(pParent, "modules/scalc/ui/protectsheetdlg.ui", "ProtectSheetDialog")
41 , m_xBtnProtect(m_xBuilder->weld_check_button("protect"))
42 , m_xPasswords(m_xBuilder->weld_container("passwords"))
43 , m_xOptions(m_xBuilder->weld_container("options"))
44 , m_xPassword1Edit(m_xBuilder->weld_entry("password1"))
45 , m_xPassword2Edit(m_xBuilder->weld_entry("password2"))
46 , m_xOptionsListBox(m_xBuilder->weld_tree_view("checklist"))
47 , m_xBtnOk(m_xBuilder->weld_button("ok"))
48 , m_xProtected(m_xBuilder->weld_label("protected"))
49 , m_xUnprotected(m_xBuilder->weld_label("unprotected"))
50 , m_xInsertColumns(m_xBuilder->weld_label("insert-columns"))
51 , m_xInsertRows(m_xBuilder->weld_label("insert-rows"))
52 , m_xDeleteColumns(m_xBuilder->weld_label("delete-columns"))
53 , m_xDeleteRows(m_xBuilder->weld_label("delete-rows"))
54{
58 m_aInsertRows = m_xInsertRows->get_label();
60 m_aDeleteRows = m_xDeleteRows->get_label();
61
63
64 Init();
65}
66
68{
69}
70
72{
73 for (size_t i = 0; i < aOptions.size(); ++i)
74 m_xOptionsListBox->set_toggle(i, rData.isOptionEnabled(aOptions[i]) ? TRISTATE_TRUE : TRISTATE_FALSE);
75}
76
78{
79 rData.setProtected(m_xBtnProtect->get_active());
80
81 // We assume that the two password texts match.
82 rData.setPassword(m_xPassword1Edit->get_text());
83
84 for (size_t i = 0; i < aOptions.size(); ++i)
85 rData.setOption(aOptions[i], m_xOptionsListBox->get_toggle(i) == TRISTATE_TRUE);
86}
87
88void ScTableProtectionDlg::InsertEntry(const OUString& rTxt)
89{
90 m_xOptionsListBox->append();
91 const int nRow = m_xOptionsListBox->n_children() - 1;
92 m_xOptionsListBox->set_toggle(nRow, TRISTATE_FALSE);
93 m_xOptionsListBox->set_text(nRow, rTxt, 0);
94}
95
97{
98 m_xBtnProtect->connect_toggled(LINK(this, ScTableProtectionDlg, CheckBoxHdl));
99
100 m_xBtnOk->connect_clicked(LINK(this, ScTableProtectionDlg, OKHdl));
101
102 Link<weld::Entry&,void> aLink = LINK(this, ScTableProtectionDlg, PasswordModifyHdl);
103 m_xPassword1Edit->connect_changed(aLink);
104 m_xPassword2Edit->connect_changed(aLink);
105
106 m_xOptionsListBox->freeze();
107 m_xOptionsListBox->clear();
108
115
116 m_xOptionsListBox->set_toggle(0, TRISTATE_TRUE);
117 m_xOptionsListBox->set_toggle(1, TRISTATE_TRUE);
118
119 m_xOptionsListBox->thaw();
120
121 // Set the default state of the dialog.
122 m_xBtnProtect->set_active(true);
123 m_xPassword1Edit->grab_focus();
124}
125
127{
128 m_xPasswords->set_sensitive(bEnable);
129 m_xOptions->set_sensitive(bEnable);
130}
131
133{
134 if (&rBtn == m_xBtnProtect.get())
135 {
136 bool bChecked = m_xBtnProtect->get_active();
137 EnableOptionalWidgets(bChecked);
138 m_xBtnOk->set_sensitive(bChecked);
139 }
140}
141
143{
144 m_xDialog->response(RET_OK);
145}
146
148{
149 OUString aPass1 = m_xPassword1Edit->get_text();
150 OUString aPass2 = m_xPassword2Edit->get_text();
151 m_xBtnOk->set_sensitive(aPass1 == aPass2);
152}
153
154/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
OUString m_aSelectUnlockedCells
std::unique_ptr< weld::Label > m_xInsertRows
std::unique_ptr< weld::Button > m_xBtnOk
std::unique_ptr< weld::Label > m_xDeleteColumns
std::unique_ptr< weld::CheckButton > m_xBtnProtect
std::unique_ptr< weld::Label > m_xProtected
void InsertEntry(const OUString &rTxt)
void SetDialogData(const ScTableProtection &rData)
std::unique_ptr< weld::Label > m_xDeleteRows
std::unique_ptr< weld::Container > m_xOptions
void EnableOptionalWidgets(bool bEnable)
void WriteData(ScTableProtection &rData) const
virtual ~ScTableProtectionDlg() override
std::unique_ptr< weld::TreeView > m_xOptionsListBox
ScTableProtectionDlg()=delete
std::unique_ptr< weld::Entry > m_xPassword1Edit
std::unique_ptr< weld::Label > m_xInsertColumns
std::unique_ptr< weld::Entry > m_xPassword2Edit
std::unique_ptr< weld::Label > m_xUnprotected
std::unique_ptr< weld::Container > m_xPasswords
sheet protection state container
bool isOptionEnabled(Option eOption) const
void setOption(Option eOption, bool bEnabled)
virtual void setPassword(const OUString &aPassText) override
virtual void setProtected(bool bProtected) override
TRISTATE_FALSE
TRISTATE_TRUE
int i
IMPL_LINK(ScTableProtectionDlg, CheckBoxHdl, weld::Toggleable &, rBtn, void)
IMPL_LINK_NOARG(ScTableProtectionDlg, OKHdl, weld::Button &, void)
RET_OK