LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - protectiondlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 65 1.5 %
Date: 2014-11-03 Functions: 2 16 12.5 %
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 : }
      54             : 
      55           0 : short ScTableProtectionDlg::Execute()
      56             : {
      57           0 :     return ModalDialog::Execute();
      58             : }
      59             : 
      60           0 : void ScTableProtectionDlg::SetDialogData(const ScTableProtection& rData)
      61             : {
      62           0 :     for (sal_uInt16 i = 0; i < nOptionCount; ++i)
      63           0 :         m_pOptionsListBox->CheckEntryPos(i, rData.isOptionEnabled(aOptions[i]));
      64           0 : }
      65             : 
      66           0 : void ScTableProtectionDlg::WriteData(ScTableProtection& rData) const
      67             : {
      68           0 :     rData.setProtected(m_pBtnProtect->IsChecked());
      69             : 
      70             :     // We assume that the two password texts match.
      71           0 :     rData.setPassword(m_pPassword1Edit->GetText());
      72             : 
      73           0 :     for (sal_uInt16 i = 0; i < nOptionCount; ++i)
      74           0 :         rData.setOption(aOptions[i], m_pOptionsListBox->IsChecked(i));
      75           0 : }
      76             : 
      77           0 : void ScTableProtectionDlg::Init()
      78             : {
      79           0 :     Link aLink = LINK( this, ScTableProtectionDlg, CheckBoxHdl );
      80           0 :     m_pBtnProtect->SetClickHdl(aLink);
      81             : 
      82           0 :     aLink = LINK( this, ScTableProtectionDlg, OKHdl );
      83           0 :     m_pBtnOk->SetClickHdl(aLink);
      84             : 
      85           0 :     aLink = LINK( this, ScTableProtectionDlg, PasswordModifyHdl );
      86           0 :     m_pPassword1Edit->SetModifyHdl(aLink);
      87           0 :     m_pPassword2Edit->SetModifyHdl(aLink);
      88             : 
      89           0 :     m_pOptionsListBox->SetUpdateMode(false);
      90           0 :     m_pOptionsListBox->Clear();
      91             : 
      92           0 :     m_pOptionsListBox->InsertEntry(m_aSelectLockedCells);
      93           0 :     m_pOptionsListBox->InsertEntry(m_aSelectUnlockedCells);
      94             : 
      95           0 :     m_pOptionsListBox->CheckEntryPos(0, true);
      96           0 :     m_pOptionsListBox->CheckEntryPos(1, true);
      97             : 
      98           0 :     m_pOptionsListBox->SetUpdateMode(true);
      99             : 
     100             :     // Set the default state of the dialog.
     101           0 :     m_pBtnProtect->Check(true);
     102           0 :     m_pPassword1Edit->GrabFocus();
     103           0 : }
     104             : 
     105           0 : void ScTableProtectionDlg::EnableOptionalWidgets(bool bEnable)
     106             : {
     107           0 :     m_pPasswords->Enable(bEnable);
     108           0 :     m_pOptions->Enable(bEnable);
     109           0 :     m_pOptionsListBox->Invalidate();
     110           0 : }
     111             : 
     112           0 : IMPL_LINK( ScTableProtectionDlg, CheckBoxHdl, CheckBox*, pBtn )
     113             : {
     114           0 :     if (pBtn == m_pBtnProtect)
     115             :     {
     116           0 :         bool bChecked = m_pBtnProtect->IsChecked();
     117           0 :         EnableOptionalWidgets(bChecked);
     118           0 :         m_pBtnOk->Enable(bChecked);
     119             :     }
     120             : 
     121           0 :     return 0;
     122             : }
     123             : 
     124           0 : IMPL_LINK_NOARG(ScTableProtectionDlg, OKHdl)
     125             : {
     126           0 :     EndDialog(RET_OK);
     127           0 :     return 0;
     128             : }
     129             : 
     130           0 : IMPL_LINK_NOARG(ScTableProtectionDlg, PasswordModifyHdl)
     131             : {
     132           0 :     OUString aPass1 = m_pPassword1Edit->GetText();
     133           0 :     OUString aPass2 = m_pPassword2Edit->GetText();
     134           0 :     m_pBtnOk->Enable(aPass1 == aPass2);
     135           0 :     return 0;
     136         228 : }
     137             : 
     138             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10