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 "scresid.hxx"
23 #include "tabprotection.hxx"
25 #include <sal/macros.h>
26 #include <vcl/msgbox.hxx>
29 // The order must match that of the list box.
30 static const ScTableProtection::Option aOptions
[] = {
31 ScTableProtection::SELECT_LOCKED_CELLS
,
32 ScTableProtection::SELECT_UNLOCKED_CELLS
,
34 static const sal_uInt16 nOptionCount
= sizeof(aOptions
) / sizeof (aOptions
[0]);
37 ScTableProtectionDlg::ScTableProtectionDlg(Window
* pParent
)
38 : ModalDialog( pParent
, "ProtectSheetDialog", "modules/scalc/ui/protectsheetdlg.ui" )
40 get(m_pPasswords
, "passwords");
41 get(m_pOptions
, "options");
42 get(m_pBtnProtect
, "protect");
43 get(m_pOptionsListBox
, "checklist");
44 get(m_pPassword1Edit
, "password1");
45 get(m_pPassword2Edit
, "password2");
48 m_aSelectLockedCells
= get
<FixedText
>("protected")->GetText();
49 m_aSelectUnlockedCells
= get
<FixedText
>("unprotected")->GetText();
54 ScTableProtectionDlg::~ScTableProtectionDlg()
58 short ScTableProtectionDlg::Execute()
60 return ModalDialog::Execute();
63 void ScTableProtectionDlg::SetDialogData(const ScTableProtection
& rData
)
65 for (sal_uInt16 i
= 0; i
< nOptionCount
; ++i
)
66 m_pOptionsListBox
->CheckEntryPos(i
, rData
.isOptionEnabled(aOptions
[i
]));
69 void ScTableProtectionDlg::WriteData(ScTableProtection
& rData
) const
71 rData
.setProtected(m_pBtnProtect
->IsChecked());
73 // We assume that the two password texts match.
74 rData
.setPassword(m_pPassword1Edit
->GetText());
76 for (sal_uInt16 i
= 0; i
< nOptionCount
; ++i
)
77 rData
.setOption(aOptions
[i
], m_pOptionsListBox
->IsChecked(i
));
80 void ScTableProtectionDlg::Init()
82 Link aLink
= LINK( this, ScTableProtectionDlg
, CheckBoxHdl
);
83 m_pBtnProtect
->SetClickHdl(aLink
);
85 aLink
= LINK( this, ScTableProtectionDlg
, OKHdl
);
86 m_pBtnOk
->SetClickHdl(aLink
);
88 aLink
= LINK( this, ScTableProtectionDlg
, PasswordModifyHdl
);
89 m_pPassword1Edit
->SetModifyHdl(aLink
);
90 m_pPassword2Edit
->SetModifyHdl(aLink
);
92 m_pOptionsListBox
->SetUpdateMode(false);
93 m_pOptionsListBox
->Clear();
95 m_pOptionsListBox
->InsertEntry(m_aSelectLockedCells
);
96 m_pOptionsListBox
->InsertEntry(m_aSelectUnlockedCells
);
98 m_pOptionsListBox
->CheckEntryPos(0, true);
99 m_pOptionsListBox
->CheckEntryPos(1, true);
101 m_pOptionsListBox
->SetUpdateMode(true);
103 // Set the default state of the dialog.
104 m_pBtnProtect
->Check(true);
105 m_pPassword1Edit
->GrabFocus();
108 void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable
)
110 m_pPasswords
->Enable(bEnable
);
111 m_pOptions
->Enable(bEnable
);
112 m_pOptionsListBox
->Invalidate();
115 IMPL_LINK( ScTableProtectionDlg
, CheckBoxHdl
, CheckBox
*, pBtn
)
117 if (pBtn
== m_pBtnProtect
)
119 bool bChecked
= m_pBtnProtect
->IsChecked();
120 EnableOptionalWidgets(bChecked
);
121 m_pBtnOk
->Enable(bChecked
);
127 IMPL_LINK_NOARG(ScTableProtectionDlg
, OKHdl
)
133 IMPL_LINK_NOARG(ScTableProtectionDlg
, PasswordModifyHdl
)
135 OUString aPass1
= m_pPassword1Edit
->GetText();
136 OUString aPass2
= m_pPassword2Edit
->GetText();
137 m_pBtnOk
->Enable(aPass1
== aPass2
);
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */