LCOV - code coverage report
Current view: top level - libreoffice/uui/source - passworddlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 76 0.0 %
Date: 2012-12-27 Functions: 0 4 0.0 %
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 "passworddlg.hxx"
      21             : #include "passworddlg.hrc"
      22             : #include "ids.hrc"
      23             : 
      24             : #include <vcl/msgbox.hxx>
      25             : 
      26             : 
      27             : using namespace ::com::sun::star;
      28             : 
      29             : 
      30             : // -----------------------------------------------------------------------
      31             : 
      32           0 : static void lcl_Move( Window &rWin, long nOffset )
      33             : {
      34           0 :     Point aTmp( rWin.GetPosPixel() );
      35           0 :     aTmp.Y() += nOffset;
      36           0 :     rWin.SetPosPixel( aTmp );
      37           0 : }
      38             : 
      39             : // -----------------------------------------------------------------------
      40             : 
      41           0 : PasswordDialog::PasswordDialog(
      42             :     Window* _pParent,
      43             :     task::PasswordRequestMode nDlgMode,
      44             :     ResMgr * pResMgr,
      45             :     rtl::OUString& aDocURL,
      46             :     bool bOpenToModify,
      47             :     bool bIsSimplePasswordRequest )
      48             : 
      49             :     :ModalDialog( _pParent, ResId( DLG_UUI_PASSWORD, *pResMgr ) )
      50             :     ,aFTPassword( this, ResId( FT_PASSWORD, *pResMgr ))
      51             :     ,aEDPassword( this, ResId( ED_PASSWORD, *pResMgr ))
      52             :     ,aFTConfirmPassword( this, ResId( FT_CONFIRM_PASSWORD, *pResMgr ))
      53             :     ,aEDConfirmPassword( this, ResId( ED_CONFIRM_PASSWORD, *pResMgr ))
      54             :     ,aOKBtn ( this, ResId( BTN_PASSWORD_OK, *pResMgr ))
      55             :     ,aCancelBtn ( this, ResId( BTN_PASSWORD_CANCEL, *pResMgr ))
      56             :     ,aHelpBtn ( this, ResId( BTN_PASSWORD_HELP, *pResMgr ))
      57             :     ,aFixedLine1( this, ResId( FL_FIXED_LINE_1, *pResMgr ))
      58             :     ,nMinLen(1)
      59             :     ,aPasswdMismatch( ResId( STR_PASSWORD_MISMATCH, *pResMgr ))
      60             :     ,nDialogMode( nDlgMode )
      61           0 :     ,pResourceMgr ( pResMgr )
      62             : {
      63           0 :     if( nDialogMode == task::PasswordRequestMode_PASSWORD_REENTER )
      64             :     {
      65           0 :         const sal_uInt16 nOpenToModifyErrStrId = bOpenToModify ? STR_ERROR_PASSWORD_TO_MODIFY_WRONG : STR_ERROR_PASSWORD_TO_OPEN_WRONG;
      66           0 :         const sal_uInt16 nErrStrId = bIsSimplePasswordRequest ? STR_ERROR_SIMPLE_PASSWORD_WRONG : nOpenToModifyErrStrId;
      67           0 :         rtl::OUString aErrorMsg(ResId(nErrStrId, *pResourceMgr).toString());
      68           0 :         ErrorBox aErrorBox( GetParent(), WB_OK, aErrorMsg );
      69           0 :         aErrorBox.Execute();
      70             :     }
      71             : 
      72             :     // default settings for enter password or reenter passwd...
      73           0 :     rtl::OUString aTitle(ResId(STR_TITLE_ENTER_PASSWORD, *pResourceMgr).toString());
      74           0 :     aFTConfirmPassword.Hide();
      75           0 :     aEDConfirmPassword.Hide();
      76           0 :     aFTConfirmPassword.Enable( sal_False );
      77           0 :     aEDConfirmPassword.Enable( sal_False );
      78             : 
      79             :     // settings for create password
      80           0 :     if (nDialogMode == task::PasswordRequestMode_PASSWORD_CREATE)
      81             :     {
      82           0 :         aTitle = ResId(STR_TITLE_CREATE_PASSWORD, *pResourceMgr).toString();
      83             : 
      84           0 :         aFTConfirmPassword.SetText(ResId(STR_CONFIRM_SIMPLE_PASSWORD, *pResourceMgr).toString());
      85             : 
      86           0 :         aFTConfirmPassword.Show();
      87           0 :         aEDConfirmPassword.Show();
      88           0 :         aFTConfirmPassword.Enable( sal_True );
      89           0 :         aEDConfirmPassword.Enable( sal_True );
      90             :     }
      91             :     else
      92             :     {
      93             :         // shrink dialog by size of hidden controls and move rest up accordingly
      94             : 
      95           0 :         long nDelta = aFixedLine1.GetPosPixel().Y() - aFTConfirmPassword.GetPosPixel().Y();
      96             : 
      97           0 :         lcl_Move( aFixedLine1, -nDelta );
      98           0 :         lcl_Move( aOKBtn, -nDelta );
      99           0 :         lcl_Move( aCancelBtn, -nDelta );
     100           0 :         lcl_Move( aHelpBtn, -nDelta );
     101             : 
     102           0 :         Size aNewDlgSize = GetSizePixel();
     103           0 :         aNewDlgSize.Height() -= nDelta;
     104           0 :         SetSizePixel( aNewDlgSize );
     105             :     }
     106             : 
     107           0 :     SetText( aTitle );
     108             : 
     109           0 :     sal_uInt16 nStrId = bOpenToModify ? STR_ENTER_PASSWORD_TO_MODIFY : STR_ENTER_PASSWORD_TO_OPEN;
     110           0 :     aFTPassword.SetText(ResId(nStrId, *pResourceMgr).toString());
     111           0 :     aFTPassword.SetText( aFTPassword.GetText() + aDocURL );
     112           0 :     if (bIsSimplePasswordRequest)
     113             :     {
     114             :         DBG_ASSERT( aDocURL.isEmpty(), "A simple password request should not have a document URL! Use document password request instead." );
     115           0 :         aFTPassword.SetText(ResId(STR_ENTER_SIMPLE_PASSWORD, *pResourceMgr).toString());
     116             :     }
     117             : 
     118           0 :     FreeResource();
     119             : 
     120           0 :     aOKBtn.SetClickHdl( LINK( this, PasswordDialog, OKHdl_Impl ) );
     121             : 
     122             : 
     123             :     //
     124             :     // move controls down by extra height needed for aFTPassword
     125             :     // (usually only needed if a URL was provided)
     126             :     //
     127             : 
     128           0 :     long nLabelWidth    = aFTPassword.GetSizePixel().Width();
     129           0 :     long nLabelHeight   = aFTPassword.GetSizePixel().Height();
     130           0 :     long nTextWidth     = aFTPassword.GetCtrlTextWidth( aFTPassword.GetText() );
     131           0 :     long nTextHeight    = aFTPassword.GetTextHeight();
     132             : 
     133           0 :     Rectangle aLabelRect( aFTPassword.GetPosPixel(), aFTPassword.GetSizePixel() );
     134           0 :     Rectangle aRect = aFTPassword.GetTextRect( aLabelRect, aFTPassword.GetText() );
     135             : 
     136           0 :     long nNewLabelHeight = 0;
     137           0 :     for( nNewLabelHeight = ( nTextWidth / nLabelWidth + 1 ) * nTextHeight;
     138           0 :         nNewLabelHeight < aRect.GetHeight();
     139             :         nNewLabelHeight += nTextHeight ) {} ;
     140             : 
     141           0 :     long nDelta = nNewLabelHeight - nLabelHeight;
     142             : 
     143           0 :     Size aNewDlgSize = GetSizePixel();
     144           0 :     aNewDlgSize.Height() += nDelta;
     145           0 :     SetSizePixel( aNewDlgSize );
     146             : 
     147           0 :     Size aNewLabelSize = aFTPassword.GetSizePixel();
     148           0 :     aNewLabelSize.Height() = nNewLabelHeight;
     149           0 :     aFTPassword.SetPosSizePixel( aFTPassword.GetPosPixel(), aNewLabelSize );
     150             : 
     151           0 :     lcl_Move( aEDPassword, nDelta );
     152           0 :     lcl_Move( aFTConfirmPassword, nDelta );
     153           0 :     lcl_Move( aEDConfirmPassword, nDelta );
     154           0 :     lcl_Move( aFixedLine1, nDelta );
     155           0 :     lcl_Move( aOKBtn, nDelta );
     156           0 :     lcl_Move( aCancelBtn, nDelta );
     157           0 :     lcl_Move( aHelpBtn, nDelta );
     158           0 : }
     159             : 
     160             : 
     161           0 : IMPL_LINK_NOARG(PasswordDialog, OKHdl_Impl)
     162             : {
     163           0 :     bool bEDPasswdValid = aEDPassword.GetText().Len() >= nMinLen;
     164           0 :     bool bPasswdMismatch = aEDConfirmPassword.GetText() != aEDPassword.GetText();
     165           0 :     bool bValid = (!aEDConfirmPassword.IsVisible() && bEDPasswdValid) ||
     166           0 :             (aEDConfirmPassword.IsVisible() && bEDPasswdValid && !bPasswdMismatch);
     167             : 
     168           0 :     if (aEDConfirmPassword.IsVisible() && bPasswdMismatch)
     169             :     {
     170           0 :         ErrorBox aErrorBox( this, WB_OK, aPasswdMismatch );
     171           0 :         aErrorBox.Execute();
     172             :     }
     173           0 :     else if (bValid)
     174           0 :         EndDialog( RET_OK );
     175             : 
     176           0 :     return 1;
     177             : }
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
     180             : 

Generated by: LCOV version 1.10