LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - retypepassdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 267 0.0 %
Date: 2012-08-25 Functions: 0 36 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 497 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "retypepassdlg.hxx"
      31                 :            : #include "retypepassdlg.hrc"
      32                 :            : #include "scresid.hxx"
      33                 :            : #include "document.hxx"
      34                 :            : #include "tabprotection.hxx"
      35                 :            : 
      36                 :            : #include <stdio.h>
      37                 :            : 
      38                 :            : #include <vcl/msgbox.hxx>
      39                 :            : 
      40                 :          0 : ScRetypePassDlg::ScRetypePassDlg(Window* pParent) :
      41                 :            :     ModalDialog(pParent, ScResId(RID_SCDLG_RETYPEPASS)),
      42                 :            : 
      43                 :            :     maBtnOk     (this, ScResId(BTN_OK)),
      44                 :            :     maBtnCancel (this, ScResId(BTN_CANCEL)),
      45                 :            :     maBtnHelp   (this, ScResId(BTN_HELP)),
      46                 :            : 
      47                 :            :     maTextDescription(this, ScResId(FT_DESC)),
      48                 :            :     maLineDocument(this, ScResId(FL_DOCUMENT)),
      49                 :            :     maTextDocStatus(this, ScResId(FT_DOCSTATUS)),
      50                 :            :     maBtnRetypeDoc(this, ScResId(BTN_RETYPE_DOC)),
      51                 :            : 
      52                 :            :     maLineSheet(this, ScResId(FL_SHEET)),
      53                 :            :     maTextSheetName1(this, ScResId(FT_SHEETNAME1)),
      54                 :            :     maTextSheetStatus1(this, ScResId(FT_SHEETSTATUS1)),
      55                 :            :     maBtnRetypeSheet1(this, ScResId(BTN_RETYPE_SHEET1)),
      56                 :            : 
      57                 :            :     maTextSheetName2(this, ScResId(FT_SHEETNAME2)),
      58                 :            :     maTextSheetStatus2(this, ScResId(FT_SHEETSTATUS2)),
      59                 :            :     maBtnRetypeSheet2(this, ScResId(BTN_RETYPE_SHEET2)),
      60                 :            : 
      61                 :            :     maTextSheetName3(this, ScResId(FT_SHEETNAME3)),
      62                 :            :     maTextSheetStatus3(this, ScResId(FT_SHEETSTATUS3)),
      63                 :            :     maBtnRetypeSheet3(this, ScResId(BTN_RETYPE_SHEET3)),
      64                 :            : 
      65                 :            :     maTextSheetName4(this, ScResId(FT_SHEETNAME4)),
      66                 :            :     maTextSheetStatus4(this, ScResId(FT_SHEETSTATUS4)),
      67                 :            :     maBtnRetypeSheet4(this, ScResId(BTN_RETYPE_SHEET4)),
      68                 :            : 
      69                 :            :     maScrollBar (this, ScResId(SB_SCROLL)),
      70                 :            : 
      71                 :            :     maTextNotProtected(ScResId(STR_NOT_PROTECTED)),
      72                 :            :     maTextNotPassProtected(ScResId(STR_NOT_PASS_PROTECTED)),
      73                 :            :     maTextHashBad(ScResId(STR_HASH_BAD)),
      74                 :            :     maTextHashGood(ScResId(STR_HASH_GOOD)),
      75                 :            :     maTextHashRegen(ScResId(STR_HASH_REGENERATED)),
      76                 :            : 
      77                 :            :     mpDocItem(static_cast<ScDocProtection*>(NULL)),
      78                 :            :     mnCurScrollPos(0),
      79 [ #  # ][ #  # ]:          0 :     meDesiredHash(PASSHASH_SHA1)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      80                 :            : {
      81         [ #  # ]:          0 :     Init();
      82                 :          0 : }
      83                 :            : 
      84 [ #  # ][ #  # ]:          0 : ScRetypePassDlg::~ScRetypePassDlg()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      85                 :            : {
      86         [ #  # ]:          0 : }
      87                 :            : 
      88                 :          0 : short ScRetypePassDlg::Execute()
      89                 :            : {
      90                 :          0 :     PopulateDialog();
      91                 :          0 :     CheckHashStatus();
      92                 :          0 :     return ModalDialog::Execute();
      93                 :            : }
      94                 :            : 
      95                 :          0 : void ScRetypePassDlg::SetDataFromDocument(const ScDocument& rDoc)
      96                 :            : {
      97                 :          0 :     const ScDocProtection* pDocProtect = rDoc.GetDocProtection();
      98 [ #  # ][ #  # ]:          0 :     if (pDocProtect && pDocProtect->isProtected())
                 [ #  # ]
      99         [ #  # ]:          0 :         mpDocItem.reset(new ScDocProtection(*pDocProtect));
     100                 :            : 
     101                 :          0 :     SCTAB nTabCount = rDoc.GetTableCount();
     102                 :          0 :     maTableItems.reserve(nTabCount);
     103         [ #  # ]:          0 :     for (SCTAB i = 0; i < nTabCount; ++i)
     104                 :            :     {
     105         [ #  # ]:          0 :         TableItem aTabItem;
     106         [ #  # ]:          0 :         rDoc.GetName(i, aTabItem.maName);
     107                 :            : 
     108         [ #  # ]:          0 :         const ScTableProtection* pTabProtect = rDoc.GetTabProtection(i);
     109 [ #  # ][ #  # ]:          0 :         if (pTabProtect && pTabProtect->isProtected())
         [ #  # ][ #  # ]
     110 [ #  # ][ #  # ]:          0 :             aTabItem.mpProtect.reset(new ScTableProtection(*pTabProtect));
                 [ #  # ]
     111                 :            : 
     112         [ #  # ]:          0 :         maTableItems.push_back(aTabItem);
     113         [ #  # ]:          0 :     }
     114                 :          0 : }
     115                 :            : 
     116                 :          0 : void ScRetypePassDlg::SetDesiredHash(ScPasswordHash eHash)
     117                 :            : {
     118                 :          0 :     meDesiredHash = eHash;
     119                 :          0 : }
     120                 :            : 
     121                 :          0 : void ScRetypePassDlg::WriteNewDataToDocument(ScDocument& rDoc) const
     122                 :            : {
     123         [ #  # ]:          0 :     if (mpDocItem.get())
     124                 :          0 :         rDoc.SetDocProtection(mpDocItem.get());
     125                 :            : 
     126                 :          0 :     size_t nTabCount = static_cast<size_t>(rDoc.GetTableCount());
     127                 :          0 :     size_t n = maTableItems.size();
     128         [ #  # ]:          0 :     for (size_t i = 0; i < n; ++i)
     129                 :            :     {
     130         [ #  # ]:          0 :         if (i >= nTabCount)
     131                 :          0 :             break;
     132                 :            : 
     133                 :          0 :         ScTableProtection* pTabProtect = maTableItems[i].mpProtect.get();
     134         [ #  # ]:          0 :         if (pTabProtect)
     135                 :          0 :             rDoc.SetTabProtection(static_cast<SCTAB>(i), pTabProtect);
     136                 :            :     }
     137                 :          0 : }
     138                 :            : 
     139                 :          0 : void ScRetypePassDlg::Init()
     140                 :            : {
     141         [ #  # ]:          0 :     Link aLink = LINK( this, ScRetypePassDlg, OKHdl );
     142                 :          0 :     maBtnOk.SetClickHdl(aLink);
     143                 :            : 
     144         [ #  # ]:          0 :     aLink = LINK( this, ScRetypePassDlg, RetypeBtnHdl );
     145                 :          0 :     maBtnRetypeDoc.SetClickHdl(aLink);
     146                 :          0 :     maBtnRetypeSheet1.SetClickHdl(aLink);
     147                 :          0 :     maBtnRetypeSheet2.SetClickHdl(aLink);
     148                 :          0 :     maBtnRetypeSheet3.SetClickHdl(aLink);
     149                 :          0 :     maBtnRetypeSheet4.SetClickHdl(aLink);
     150                 :            : 
     151         [ #  # ]:          0 :     maTextDocStatus.SetText(maTextNotProtected);
     152         [ #  # ]:          0 :     maTextSheetStatus1.SetText(maTextNotProtected);
     153         [ #  # ]:          0 :     maTextSheetStatus2.SetText(maTextNotProtected);
     154         [ #  # ]:          0 :     maTextSheetStatus3.SetText(maTextNotProtected);
     155         [ #  # ]:          0 :     maTextSheetStatus4.SetText(maTextNotProtected);
     156         [ #  # ]:          0 :     maBtnRetypeDoc.Disable();
     157                 :            : 
     158                 :            :     // Make all sheet rows invisible.
     159                 :            : 
     160         [ #  # ]:          0 :     maTextSheetName1.Show(false);
     161         [ #  # ]:          0 :     maTextSheetStatus1.Show(false);
     162         [ #  # ]:          0 :     maBtnRetypeSheet1.Show(false);
     163         [ #  # ]:          0 :     maBtnRetypeSheet1.Disable();
     164                 :            : 
     165         [ #  # ]:          0 :     maTextSheetName2.Show(false);
     166         [ #  # ]:          0 :     maTextSheetStatus2.Show(false);
     167         [ #  # ]:          0 :     maBtnRetypeSheet2.Show(false);
     168         [ #  # ]:          0 :     maBtnRetypeSheet2.Disable();
     169                 :            : 
     170         [ #  # ]:          0 :     maTextSheetName3.Show(false);
     171         [ #  # ]:          0 :     maTextSheetStatus3.Show(false);
     172         [ #  # ]:          0 :     maBtnRetypeSheet3.Show(false);
     173         [ #  # ]:          0 :     maBtnRetypeSheet3.Disable();
     174                 :            : 
     175         [ #  # ]:          0 :     maTextSheetName4.Show(false);
     176         [ #  # ]:          0 :     maTextSheetStatus4.Show(false);
     177         [ #  # ]:          0 :     maBtnRetypeSheet4.Show(false);
     178         [ #  # ]:          0 :     maBtnRetypeSheet4.Disable();
     179                 :            : 
     180         [ #  # ]:          0 :     maScrollBar.Show(false);
     181                 :            : 
     182         [ #  # ]:          0 :     maScrollBar.SetEndScrollHdl( LINK( this, ScRetypePassDlg, ScrollHdl ) );
     183         [ #  # ]:          0 :     maScrollBar.SetScrollHdl( LINK( this, ScRetypePassDlg, ScrollHdl ) );
     184                 :            : 
     185                 :          0 :     maScrollBar.SetPageSize(4);
     186         [ #  # ]:          0 :     maScrollBar.SetVisibleSize(4);
     187                 :          0 :     maScrollBar.SetLineSize(1);
     188                 :          0 : }
     189                 :            : 
     190                 :          0 : void ScRetypePassDlg::PopulateDialog()
     191                 :            : {
     192                 :            :     // Document protection first.
     193                 :          0 :     SetDocData();
     194                 :            : 
     195                 :            :     // Sheet protection next.  We're only interested in the first 4 sheets
     196                 :            :     // (or less).
     197                 :          0 :     size_t n = maTableItems.size();
     198 [ #  # ][ #  # ]:          0 :     for (size_t i = 0; i < n && i < 4; ++i)
                 [ #  # ]
     199                 :          0 :         SetTableData(i, static_cast< SCTAB >( i ));
     200                 :            : 
     201         [ #  # ]:          0 :     if (n > 4)
     202                 :            :     {
     203                 :          0 :         maScrollBar.Show(true);
     204         [ #  # ]:          0 :         maScrollBar.SetRange(Range(0, n));
     205                 :            :     }
     206                 :          0 : }
     207                 :            : 
     208                 :          0 : void ScRetypePassDlg::SetDocData()
     209                 :            : {
     210                 :          0 :     bool bBtnEnabled = false;
     211 [ #  # ][ #  # ]:          0 :     if (mpDocItem.get() && mpDocItem->isProtected())
                 [ #  # ]
     212                 :            :     {
     213         [ #  # ]:          0 :         if (mpDocItem->isPasswordEmpty())
     214                 :          0 :             maTextDocStatus.SetText(maTextNotPassProtected);
     215         [ #  # ]:          0 :         else if (mpDocItem->hasPasswordHash(meDesiredHash))
     216                 :          0 :             maTextDocStatus.SetText(maTextHashGood);
     217                 :            :         else
     218                 :            :         {
     219                 :            :             // incompatible hash
     220                 :          0 :             maTextDocStatus.SetText(maTextHashBad);
     221                 :          0 :             bBtnEnabled = true;
     222                 :            :         }
     223                 :            :     }
     224                 :          0 :     maBtnRetypeDoc.Enable(bBtnEnabled);
     225                 :          0 : }
     226                 :            : 
     227                 :          0 : void ScRetypePassDlg::SetTableData(size_t nRowPos, SCTAB nTab)
     228                 :            : {
     229         [ #  # ]:          0 :     if (nRowPos >= 4)
     230                 :          0 :         return;
     231                 :            : 
     232                 :          0 :     FixedText* pName = NULL;
     233                 :          0 :     FixedText* pStatus = NULL;
     234                 :          0 :     PushButton* pBtn = NULL;
     235   [ #  #  #  #  :          0 :     switch (nRowPos)
                      # ]
     236                 :            :     {
     237                 :            :         case 0:
     238                 :          0 :             pName = &maTextSheetName1;
     239                 :          0 :             pStatus = &maTextSheetStatus1;
     240                 :          0 :             pBtn = &maBtnRetypeSheet1;
     241                 :          0 :         break;
     242                 :            :         case 1:
     243                 :          0 :             pName = &maTextSheetName2;
     244                 :          0 :             pStatus = &maTextSheetStatus2;
     245                 :          0 :             pBtn = &maBtnRetypeSheet2;
     246                 :          0 :         break;
     247                 :            :         case 2:
     248                 :          0 :             pName = &maTextSheetName3;
     249                 :          0 :             pStatus = &maTextSheetStatus3;
     250                 :          0 :             pBtn = &maBtnRetypeSheet3;
     251                 :          0 :         break;
     252                 :            :         case 3:
     253                 :          0 :             pName = &maTextSheetName4;
     254                 :          0 :             pStatus = &maTextSheetStatus4;
     255                 :          0 :             pBtn = &maBtnRetypeSheet4;
     256                 :          0 :         break;
     257                 :            :         default:
     258                 :          0 :             return;
     259                 :            :     }
     260                 :            : 
     261                 :          0 :     bool bBtnEnabled = false;
     262         [ #  # ]:          0 :     pName->SetText(maTableItems[nTab].maName);
     263                 :          0 :     pName->Show(true);
     264                 :          0 :     const ScTableProtection* pTabProtect = maTableItems[nTab].mpProtect.get();
     265 [ #  # ][ #  # ]:          0 :     if (pTabProtect && pTabProtect->isProtected())
                 [ #  # ]
     266                 :            :     {
     267         [ #  # ]:          0 :         if (pTabProtect->isPasswordEmpty())
     268                 :          0 :             pStatus->SetText(maTextNotPassProtected);
     269         [ #  # ]:          0 :         else if (pTabProtect->hasPasswordHash(meDesiredHash))
     270                 :          0 :             pStatus->SetText(maTextHashGood);
     271                 :            :         else
     272                 :            :         {
     273                 :            :             // incompatible hash
     274                 :          0 :             pStatus->SetText(maTextHashBad);
     275                 :          0 :             bBtnEnabled = true;
     276                 :            :         }
     277                 :            :     }
     278                 :            :     else
     279                 :          0 :         pStatus->SetText(maTextNotProtected);
     280                 :            : 
     281                 :          0 :     pStatus->Show(true);
     282                 :          0 :     pBtn->Show(true);
     283                 :          0 :     pBtn->Enable(bBtnEnabled);
     284                 :            : }
     285                 :            : 
     286                 :          0 : void ScRetypePassDlg::ResetTableRows()
     287                 :            : {
     288                 :          0 :     long nScrollPos = maScrollBar.GetThumbPos();
     289                 :          0 :     mnCurScrollPos = nScrollPos < 0 ? 0 : nScrollPos;
     290                 :          0 :     size_t nRowCount = maTableItems.size() - nScrollPos;
     291         [ #  # ]:          0 :     for (size_t i = 0; i < nRowCount; ++i)
     292                 :          0 :         SetTableData(i, static_cast< SCTAB >( i + nScrollPos ));
     293                 :          0 : }
     294                 :            : 
     295                 :          0 : bool lcl_IsInGoodStatus(ScPassHashProtectable* pProtected, ScPasswordHash eDesiredHash)
     296                 :            : {
     297 [ #  # ][ #  # ]:          0 :     if (!pProtected || !pProtected->isProtected())
                 [ #  # ]
     298                 :            :         // Not protected.
     299                 :          0 :         return true;
     300                 :            : 
     301         [ #  # ]:          0 :     if (pProtected->isPasswordEmpty())
     302                 :          0 :         return true;
     303                 :            : 
     304         [ #  # ]:          0 :     if (pProtected->hasPasswordHash(eDesiredHash))
     305                 :          0 :         return true;
     306                 :            : 
     307                 :          0 :     return false;
     308                 :            : }
     309                 :            : 
     310                 :          0 : void ScRetypePassDlg::CheckHashStatus()
     311                 :            : {
     312                 :            :     do
     313                 :            :     {
     314         [ #  # ]:          0 :         if (!lcl_IsInGoodStatus(mpDocItem.get(), meDesiredHash))
     315                 :          0 :             break;
     316                 :            : 
     317                 :          0 :         bool bStatusGood = true;
     318                 :          0 :         size_t nTabCount = maTableItems.size();
     319 [ #  # ][ #  # ]:          0 :         for (size_t i = 0; i < nTabCount && bStatusGood; ++i)
                 [ #  # ]
     320                 :            :         {
     321         [ #  # ]:          0 :             if (!lcl_IsInGoodStatus(maTableItems[i].mpProtect.get(), meDesiredHash))
     322                 :          0 :                 bStatusGood = false;
     323                 :            :         }
     324         [ #  # ]:          0 :         if (!bStatusGood)
     325                 :          0 :             break;
     326                 :            : 
     327                 :          0 :         maBtnOk.Enable();
     328                 :          0 :         return;
     329                 :            :     }
     330                 :            :     while (false);
     331                 :            : 
     332                 :          0 :     maBtnOk.Disable();
     333                 :            : }
     334                 :            : 
     335                 :          0 : IMPL_LINK_NOARG(ScRetypePassDlg, OKHdl)
     336                 :            : {
     337                 :          0 :     EndDialog(RET_OK);
     338                 :          0 :     return 0;
     339                 :            : }
     340                 :            : 
     341                 :          0 : IMPL_LINK( ScRetypePassDlg, RetypeBtnHdl, PushButton*, pBtn )
     342                 :            : {
     343                 :          0 :     ScPassHashProtectable* pProtected = NULL;
     344         [ #  # ]:          0 :     if (pBtn == &maBtnRetypeDoc)
     345                 :            :     {
     346                 :            :         // document protection.
     347                 :          0 :         pProtected = mpDocItem.get();
     348                 :            :     }
     349                 :            :     else
     350                 :            :     {
     351                 :            :         // sheet protection.
     352                 :          0 :         size_t nTabPos = mnCurScrollPos;
     353         [ #  # ]:          0 :         if (pBtn == &maBtnRetypeSheet2)
     354                 :          0 :             nTabPos += 1;
     355         [ #  # ]:          0 :         else if (pBtn == &maBtnRetypeSheet3)
     356                 :          0 :             nTabPos += 2;
     357         [ #  # ]:          0 :         else if (pBtn == &maBtnRetypeSheet4)
     358                 :          0 :             nTabPos += 3;
     359         [ #  # ]:          0 :         else if (pBtn != &maBtnRetypeSheet1)
     360                 :            :             // This should never happen !
     361                 :          0 :             return 0;
     362                 :            : 
     363         [ #  # ]:          0 :         if (nTabPos >= maTableItems.size())
     364                 :            :             // Likewise, this should never happen !
     365                 :          0 :             return 0;
     366                 :            : 
     367                 :          0 :         pProtected = maTableItems[nTabPos].mpProtect.get();
     368                 :            :     }
     369                 :            : 
     370         [ #  # ]:          0 :     if (!pProtected)
     371                 :            :         // What the ... !?
     372                 :          0 :         return 0;
     373                 :            : 
     374         [ #  # ]:          0 :     ScRetypePassInputDlg aDlg(this, pProtected);
     375 [ #  # ][ #  # ]:          0 :     if (aDlg.Execute() == RET_OK)
     376                 :            :     {
     377                 :            :         // OK is pressed.  Update the protected item.
     378         [ #  # ]:          0 :         if (aDlg.IsRemovePassword())
     379                 :            :         {
     380                 :            :             // Remove password from this item.
     381 [ #  # ][ #  # ]:          0 :             pProtected->setPassword(String());
                 [ #  # ]
     382                 :            :         }
     383                 :            :         else
     384                 :            :         {
     385                 :            :             // Set a new password.
     386         [ #  # ]:          0 :             String aNewPass = aDlg.GetNewPassword();
     387 [ #  # ][ #  # ]:          0 :             pProtected->setPassword(aNewPass);
     388                 :            :         }
     389                 :            : 
     390         [ #  # ]:          0 :         SetDocData();
     391         [ #  # ]:          0 :         ResetTableRows();
     392         [ #  # ]:          0 :         CheckHashStatus();
     393                 :            :     }
     394         [ #  # ]:          0 :     return 0;
     395                 :            : }
     396                 :            : 
     397                 :          0 : IMPL_LINK_NOARG(ScRetypePassDlg, ScrollHdl)
     398                 :            : {
     399                 :          0 :     ResetTableRows();
     400                 :          0 :     return 0;
     401                 :            : }
     402                 :            : 
     403                 :            : // ============================================================================
     404                 :            : 
     405                 :          0 : ScRetypePassInputDlg::ScRetypePassInputDlg(Window* pParent, ScPassHashProtectable* pProtected) :
     406                 :            :     ModalDialog(pParent, ScResId(RID_SCDLG_RETYPEPASS_INPUT)),
     407                 :            : 
     408                 :            :     maBtnOk     (this, ScResId(BTN_OK)),
     409                 :            :     maBtnCancel (this, ScResId(BTN_CANCEL)),
     410                 :            :     maBtnHelp   (this, ScResId(BTN_HELP)),
     411                 :            : 
     412                 :            :     maBtnRetypePassword(this, ScResId(BTN_RETYPE_PASSWORD)),
     413                 :            : 
     414                 :            :     maPassword1Text (this, ScResId(FT_PASSWORD1)),
     415                 :            :     maPassword1Edit (this, ScResId(ED_PASSWORD1)),
     416                 :            :     maPassword2Text (this, ScResId(FT_PASSWORD2)),
     417                 :            :     maPassword2Edit (this, ScResId(ED_PASSWORD2)),
     418                 :            :     maBtnMatchOldPass(this, ScResId(BTN_MATCH_OLD_PASSWORD)),
     419                 :            : 
     420                 :            :     maBtnRemovePassword(this, ScResId(BTN_REMOVE_PASSWORD)),
     421                 :            : 
     422 [ #  # ][ #  # ]:          0 :     mpProtected(pProtected)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     423                 :            : {
     424         [ #  # ]:          0 :     Init();
     425                 :          0 : }
     426                 :            : 
     427 [ #  # ][ #  # ]:          0 : ScRetypePassInputDlg::~ScRetypePassInputDlg()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     428                 :            : {
     429         [ #  # ]:          0 : }
     430                 :            : 
     431                 :          0 : short ScRetypePassInputDlg::Execute()
     432                 :            : {
     433                 :          0 :     return ModalDialog::Execute();
     434                 :            : }
     435                 :            : 
     436                 :          0 : bool ScRetypePassInputDlg::IsRemovePassword() const
     437                 :            : {
     438                 :          0 :     return maBtnRemovePassword.IsChecked();
     439                 :            : }
     440                 :            : 
     441                 :          0 : String ScRetypePassInputDlg::GetNewPassword() const
     442                 :            : {
     443                 :          0 :     return maPassword1Edit.GetText();
     444                 :            : }
     445                 :            : 
     446                 :          0 : void ScRetypePassInputDlg::Init()
     447                 :            : {
     448         [ #  # ]:          0 :     Link aLink = LINK( this, ScRetypePassInputDlg, OKHdl );
     449                 :          0 :     maBtnOk.SetClickHdl(aLink);
     450         [ #  # ]:          0 :     aLink = LINK( this, ScRetypePassInputDlg, RadioBtnHdl );
     451                 :          0 :     maBtnRetypePassword.SetClickHdl(aLink);
     452                 :          0 :     maBtnRemovePassword.SetClickHdl(aLink);
     453         [ #  # ]:          0 :     aLink = LINK( this, ScRetypePassInputDlg, CheckBoxHdl );
     454                 :          0 :     maBtnMatchOldPass.SetClickHdl(aLink);
     455         [ #  # ]:          0 :     aLink = LINK( this, ScRetypePassInputDlg, PasswordModifyHdl );
     456                 :          0 :     maPassword1Edit.SetModifyHdl(aLink);
     457                 :          0 :     maPassword2Edit.SetModifyHdl(aLink);
     458                 :            : 
     459         [ #  # ]:          0 :     maBtnOk.Disable();
     460         [ #  # ]:          0 :     maBtnRetypePassword.Check(true);
     461         [ #  # ]:          0 :     maBtnMatchOldPass.Check(true);
     462         [ #  # ]:          0 :     maPassword1Edit.GrabFocus();
     463                 :          0 : }
     464                 :            : 
     465                 :          0 : void ScRetypePassInputDlg::CheckPasswordInput()
     466                 :            : {
     467         [ #  # ]:          0 :     String aPass1 = maPassword1Edit.GetText();
     468         [ #  # ]:          0 :     String aPass2 = maPassword2Edit.GetText();
     469                 :            : 
     470 [ #  # ][ #  # ]:          0 :     if (!aPass1.Len() || !aPass2.Len())
                 [ #  # ]
     471                 :            :     {
     472                 :            :         // Empty password is not allowed.
     473         [ #  # ]:          0 :         maBtnOk.Disable();
     474                 :            :         return;
     475                 :            :     }
     476                 :            : 
     477 [ #  # ][ #  # ]:          0 :     if (!aPass1.Equals(aPass2))
     478                 :            :     {
     479                 :            :         // The two passwords differ.
     480         [ #  # ]:          0 :         maBtnOk.Disable();
     481                 :            :         return;
     482                 :            :     }
     483                 :            : 
     484 [ #  # ][ #  # ]:          0 :     if (!maBtnMatchOldPass.IsChecked())
     485                 :            :     {
     486         [ #  # ]:          0 :         maBtnOk.Enable();
     487                 :            :         return;
     488                 :            :     }
     489                 :            : 
     490         [ #  # ]:          0 :     if (!mpProtected)
     491                 :            :     {
     492                 :            :         // This should never happen!
     493         [ #  # ]:          0 :         maBtnOk.Disable();
     494                 :            :         return;
     495                 :            :     }
     496                 :            : 
     497         [ #  # ]:          0 :     bool bPassGood = mpProtected->verifyPassword(aPass1);
     498 [ #  # ][ #  # ]:          0 :     maBtnOk.Enable(bPassGood);
         [ #  # ][ #  # ]
                 [ #  # ]
     499                 :            : }
     500                 :            : 
     501                 :          0 : IMPL_LINK_NOARG(ScRetypePassInputDlg, OKHdl)
     502                 :            : {
     503                 :          0 :     EndDialog(RET_OK);
     504                 :          0 :     return 0;
     505                 :            : }
     506                 :            : 
     507                 :          0 : IMPL_LINK( ScRetypePassInputDlg, RadioBtnHdl, RadioButton*, pBtn )
     508                 :            : {
     509         [ #  # ]:          0 :     if (pBtn == &maBtnRetypePassword)
     510                 :            :     {
     511                 :          0 :         maBtnRemovePassword.Check(false);
     512                 :          0 :         maPassword1Text.Enable();
     513                 :          0 :         maPassword1Edit.Enable();
     514                 :          0 :         maPassword2Text.Enable();
     515                 :          0 :         maPassword2Edit.Enable();
     516                 :          0 :         maBtnMatchOldPass.Enable();
     517                 :          0 :         CheckPasswordInput();
     518                 :            :     }
     519         [ #  # ]:          0 :     else if (pBtn == &maBtnRemovePassword)
     520                 :            :     {
     521                 :          0 :         maBtnRetypePassword.Check(false);
     522                 :          0 :         maPassword1Text.Disable();
     523                 :          0 :         maPassword1Edit.Disable();
     524                 :          0 :         maPassword2Text.Disable();
     525                 :          0 :         maPassword2Edit.Disable();
     526                 :          0 :         maBtnMatchOldPass.Disable();
     527                 :          0 :         maBtnOk.Enable();
     528                 :            :     }
     529                 :            : 
     530                 :          0 :     return 0;
     531                 :            : }
     532                 :            : 
     533                 :          0 : IMPL_LINK_NOARG(ScRetypePassInputDlg, CheckBoxHdl)
     534                 :            : {
     535                 :          0 :     CheckPasswordInput();
     536                 :          0 :     return 0;
     537                 :            : }
     538                 :            : 
     539                 :          0 : IMPL_LINK_NOARG(ScRetypePassInputDlg, PasswordModifyHdl)
     540                 :            : {
     541                 :          0 :     CheckPasswordInput();
     542                 :          0 :     return 0;
     543                 :            : }
     544                 :            : 
     545                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10