LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - protectiondlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 76 1.3 %
Date: 2015-06-13 12:38:46 Functions: 2 17 11.8 %
Legend: Lines: hit not hit

          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             : #include "protectiondlg.hxx"
      21             : #include "scresid.hxx"
      22             : #include "tabprotection.hxx"
      23             : 
      24             : #include <sal/macros.h>
      25             : #include <vcl/msgbox.hxx>
      26             : 
      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,
      31             : };
      32             : static const sal_uInt16 nOptionCount = sizeof(aOptions) / sizeof (aOptions[0]);
      33             : 
      34           0 : ScTableProtectionDlg::ScTableProtectionDlg(vcl::Window* pParent)
      35           0 :     : ModalDialog( pParent, "ProtectSheetDialog", "modules/scalc/ui/protectsheetdlg.ui" )
      36             : {
      37           0 :     get(m_pPasswords, "passwords");
      38           0 :     get(m_pOptions, "options");
      39           0 :     get(m_pBtnProtect, "protect");
      40           0 :     get(m_pOptionsListBox, "checklist");
      41           0 :     get(m_pPassword1Edit, "password1");
      42           0 :     get(m_pPassword2Edit, "password2");
      43           0 :     get(m_pBtnOk, "ok");
      44             : 
      45           0 :     m_aSelectLockedCells = get<FixedText>("protected")->GetText();
      46           0 :     m_aSelectUnlockedCells = get<FixedText>("unprotected")->GetText();
      47             : 
      48           0 :     Init();
      49           0 : }
      50             : 
      51           0 : ScTableProtectionDlg::~ScTableProtectionDlg()
      52             : {
      53           0 :     disposeOnce();
      54           0 : }
      55             : 
      56           0 : void ScTableProtectionDlg::dispose()
      57             : {
      58           0 :     m_pBtnProtect.clear();
      59           0 :     m_pPasswords.clear();
      60           0 :     m_pOptions.clear();
      61           0 :     m_pPassword1Edit.clear();
      62           0 :     m_pPassword2Edit.clear();
      63           0 :     m_pOptionsListBox.clear();
      64           0 :     m_pBtnOk.clear();
      65           0 :     ModalDialog::dispose();
      66           0 : }
      67             : 
      68           0 : short ScTableProtectionDlg::Execute()
      69             : {
      70           0 :     return ModalDialog::Execute();
      71             : }
      72             : 
      73           0 : void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData)
      74             : {
      75           0 :     for (sal_uInt16 i = 0; i < nOptionCount; ++i)
      76           0 :         m_pOptionsListBox->CheckEntryPos(i, rData.isOptionEnabled(aOptions[i]));
      77           0 : }
      78             : 
      79           0 : void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const
      80             : {
      81           0 :     rData.setProtected(m_pBtnProtect->IsChecked());
      82             : 
      83             :     // We assume that the two password texts match.
      84           0 :     rData.setPassword(m_pPassword1Edit->GetText());
      85             : 
      86           0 :     for (sal_uInt16 i = 0; i < nOptionCount; ++i)
      87           0 :         rData.setOption(aOptions[i], m_pOptionsListBox->IsChecked(i));
      88           0 : }
      89             : 
      90           0 : void ScTableProtectionDlg::Init()
      91             : {
      92           0 :     Link<> aLink = LINK( this, ScTableProtectionDlg, CheckBoxHdl );
      93           0 :     m_pBtnProtect->SetClickHdl(aLink);
      94             : 
      95           0 :     aLink = LINK( this, ScTableProtectionDlg, OKHdl );
      96           0 :     m_pBtnOk->SetClickHdl(aLink);
      97             : 
      98           0 :     aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl );
      99           0 :     m_pPassword1Edit->SetModifyHdl(aLink);
     100           0 :     m_pPassword2Edit->SetModifyHdl(aLink);
     101             : 
     102           0 :     m_pOptionsListBox->SetUpdateMode(false);
     103           0 :     m_pOptionsListBox->Clear();
     104             : 
     105           0 :     m_pOptionsListBox->InsertEntry(m_aSelectLockedCells);
     106           0 :     m_pOptionsListBox->InsertEntry(m_aSelectUnlockedCells);
     107             : 
     108           0 :     m_pOptionsListBox->CheckEntryPos(0, true);
     109           0 :     m_pOptionsListBox->CheckEntryPos(1, true);
     110             : 
     111           0 :     m_pOptionsListBox->SetUpdateMode(true);
     112             : 
     113             :     // Set the default state of the dialog.
     114           0 :     m_pBtnProtect->Check(true);
     115           0 :     m_pPassword1Edit->GrabFocus();
     116           0 : }
     117             : 
     118           0 : void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable)
     119             : {
     120           0 :     m_pPasswords->Enable(bEnable);
     121           0 :     m_pOptions->Enable(bEnable);
     122           0 :     m_pOptionsListBox->Invalidate();
     123           0 : }
     124             : 
     125           0 : IMPL_LINK( ScTableProtectionDlg, CheckBoxHdl, CheckBox*, pBtn )
     126             : {
     127           0 :     if (pBtn == m_pBtnProtect)
     128             :     {
     129           0 :         bool bChecked = m_pBtnProtect->IsChecked();
     130           0 :         EnableOptionalWidgets(bChecked);
     131           0 :         m_pBtnOk->Enable(bChecked);
     132             :     }
     133             : 
     134           0 :     return 0;
     135             : }
     136             : 
     137           0 : IMPL_LINK_NOARG(ScTableProtectionDlg, OKHdl)
     138             : {
     139           0 :     EndDialog(RET_OK);
     140           0 :     return 0;
     141             : }
     142             : 
     143           0 : IMPL_LINK_NOARG(ScTableProtectionDlg, PasswordModifyHdl)
     144             : {
     145           0 :     OUString aPass1 = m_pPassword1Edit->GetText();
     146           0 :     OUString aPass2 = m_pPassword2Edit->GetText();
     147           0 :     m_pBtnOk->Enable(aPass1 == aPass2);
     148           0 :     return 0;
     149         156 : }
     150             : 
     151             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11