LCOV - code coverage report
Current view: top level - libreoffice/uui/source - masterpasscrtdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 76 0.0 %
Date: 2012-12-27 Functions: 0 6 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 <sal/macros.h>
      21             : #include <vcl/msgbox.hxx>
      22             : 
      23             : #include <ids.hrc>
      24             : #include <masterpasscrtdlg.hrc>
      25             : #include <masterpasscrtdlg.hxx>
      26             : 
      27             : // MasterPasswordCreateDialog---------------------------------------------------
      28             : 
      29             : // -----------------------------------------------------------------------
      30             : 
      31           0 : IMPL_LINK_NOARG(MasterPasswordCreateDialog, EditHdl_Impl)
      32             : {
      33           0 :     aOKBtn.Enable( aEDMasterPasswordCrt.GetText().Len() >= nMinLen );
      34           0 :     return 0;
      35             : }
      36             : 
      37             : // -----------------------------------------------------------------------
      38             : 
      39           0 : IMPL_LINK_NOARG(MasterPasswordCreateDialog, OKHdl_Impl)
      40             : {
      41             :     // compare both passwords and show message box if there are not equal!!
      42           0 :     if( aEDMasterPasswordCrt.GetText() == aEDMasterPasswordRepeat.GetText() )
      43           0 :         EndDialog( RET_OK );
      44             :     else
      45             :     {
      46           0 :         String aErrorMsg( ResId( STR_ERROR_PASSWORDS_NOT_IDENTICAL, *pResourceMgr ));
      47           0 :         ErrorBox aErrorBox( this, WB_OK, aErrorMsg );
      48           0 :         aErrorBox.Execute();
      49           0 :         aEDMasterPasswordCrt.SetText( String() );
      50           0 :         aEDMasterPasswordRepeat.SetText( String() );
      51           0 :         aEDMasterPasswordCrt.GrabFocus();
      52             :     }
      53           0 :     return 1;
      54             : }
      55             : 
      56             : // -----------------------------------------------------------------------
      57             : 
      58           0 : MasterPasswordCreateDialog::MasterPasswordCreateDialog
      59             : (
      60             :     Window*                                     pParent,
      61             :     ResMgr*                                     pResMgr
      62             : ) :
      63             : 
      64             :     ModalDialog( pParent, ResId( DLG_UUI_MASTERPASSWORD_CRT, *pResMgr ) ),
      65             : 
      66             :     aFTInfoText             ( this, ResId( FT_INFOTEXT, *pResMgr ) ),
      67             :     aFLInfoText             ( this, ResId( FL_INFOTEXT, *pResMgr ) ),
      68             : 
      69             :     aFTMasterPasswordCrt    ( this, ResId( FT_MASTERPASSWORD_CRT, *pResMgr ) ),
      70             :     aEDMasterPasswordCrt    ( this, ResId( ED_MASTERPASSWORD_CRT, *pResMgr ) ),
      71             :     aFTMasterPasswordRepeat ( this, ResId( FT_MASTERPASSWORD_REPEAT, *pResMgr ) ),
      72             :     aEDMasterPasswordRepeat ( this, ResId( ED_MASTERPASSWORD_REPEAT, *pResMgr ) ),
      73             : 
      74             :     aFTCautionText          ( this, ResId( FT_CAUTIONTEXT, *pResMgr ) ),
      75             :     aFLCautionText          ( this, ResId( FL_CAUTIONTEXT, *pResMgr ) ),
      76             : 
      77             :     aFTMasterPasswordWarning ( this, ResId( FT_MASTERPASSWORD_WARNING, *pResMgr ) ),
      78             :     aFL ( this, ResId( FL_FIXED_LINE, *pResMgr ) ),
      79             :     aOKBtn                  ( this, ResId( BTN_MASTERPASSCRT_OK, *pResMgr ) ),
      80             :     aCancelBtn              ( this, ResId( BTN_MASTERPASSCRT_CANCEL, *pResMgr ) ),
      81             :     aHelpBtn                ( this, ResId( BTN_MASTERPASSCRT_HELP, *pResMgr ) ),
      82             : 
      83             :     pResourceMgr            ( pResMgr ),
      84           0 :     nMinLen                 ( 1 )
      85             : {
      86           0 :     FreeResource();
      87             : 
      88           0 :     aOKBtn.Enable( sal_False );
      89           0 :     aOKBtn.SetClickHdl( LINK( this, MasterPasswordCreateDialog, OKHdl_Impl ) );
      90           0 :     aEDMasterPasswordCrt.SetModifyHdl( LINK( this, MasterPasswordCreateDialog, EditHdl_Impl ) );
      91             : 
      92           0 :     CalculateTextHeight();
      93             : 
      94           0 :     long nLableWidth = aFTMasterPasswordWarning.GetSizePixel().Width();
      95           0 :     long nLabelHeight = aFTMasterPasswordWarning.GetSizePixel().Height();
      96           0 :     long nTextWidth = aFTMasterPasswordWarning.GetCtrlTextWidth( aFTMasterPasswordWarning.GetText() );
      97           0 :     long nTextHeight = aFTMasterPasswordWarning.GetTextHeight();
      98             : 
      99           0 :     Rectangle aLabelRect( aFTMasterPasswordWarning.GetPosPixel(), aFTMasterPasswordWarning.GetSizePixel() );
     100           0 :     Rectangle aRect = aFTMasterPasswordWarning.GetTextRect( aLabelRect, aFTMasterPasswordWarning.GetText() );
     101             : 
     102           0 :     long nNewLabelHeight = 0;
     103           0 :     if ( nTextWidth > 0 )
     104             :     {
     105           0 :         for( nNewLabelHeight = ( nTextWidth / nLableWidth + 1 ) * nTextHeight;
     106           0 :             nNewLabelHeight < aRect.GetHeight();
     107             :         nNewLabelHeight += nTextHeight ) {};
     108             :     }
     109             : 
     110           0 :     long nDelta = nNewLabelHeight - nLabelHeight;
     111           0 :     Size aNewDlgSize = GetSizePixel();
     112           0 :     aNewDlgSize.Height() += nDelta;
     113           0 :     SetSizePixel( aNewDlgSize );
     114             : 
     115           0 :     Size aNewWarningSize = aFTMasterPasswordWarning.GetSizePixel();
     116           0 :     aNewWarningSize.Height() = nNewLabelHeight;
     117           0 :     aFTMasterPasswordWarning.SetPosSizePixel( aFTMasterPasswordWarning.GetPosPixel(), aNewWarningSize );
     118             : 
     119           0 :     Window* pControls[] = { &aFL, &aOKBtn, &aCancelBtn, &aHelpBtn };
     120           0 :     const sal_Int32 nCCount = sizeof( pControls ) / sizeof( pControls[0] );
     121           0 :     for ( int i = 0; i < nCCount; ++i )
     122             :     {
     123           0 :         Point aNewPos =(*pControls[i]).GetPosPixel();
     124           0 :         aNewPos.Y() += nDelta;
     125           0 :         pControls[i]->SetPosSizePixel( aNewPos, pControls[i]->GetSizePixel() );
     126             :     }
     127           0 : };
     128             : 
     129           0 : void MasterPasswordCreateDialog::CalculateTextHeight()
     130             : {
     131           0 :     Size aSize = aFTInfoText.GetSizePixel();
     132           0 :     Size aMinSize = aFTInfoText.CalcMinimumSize( aSize.Width() );
     133           0 :     long nDelta = 0;
     134             : 
     135           0 :     if ( aSize.Height() > aMinSize.Height() )
     136             :     {
     137           0 :         aFTInfoText.SetSizePixel( aMinSize );
     138           0 :         nDelta = aSize.Height() - aMinSize.Height();
     139             :         Window* pWins[] = { &aFLInfoText, &aFTMasterPasswordCrt, &aEDMasterPasswordCrt,
     140             :                             &aFTMasterPasswordRepeat, &aEDMasterPasswordRepeat, &aFTCautionText,
     141           0 :                             &aFLCautionText, &aOKBtn, &aCancelBtn, &aHelpBtn };
     142           0 :         Window** pWindow = pWins;
     143           0 :         const sal_Int32 nCount = sizeof( pWins ) / sizeof( pWins[0] );
     144           0 :         for ( sal_Int32 i = 0; i < nCount; ++i, ++pWindow )
     145             :         {
     146           0 :             Point aNewPos = (*pWindow)->GetPosPixel();
     147           0 :             aNewPos.Y() -= nDelta;
     148           0 :             (*pWindow)->SetPosPixel( aNewPos );
     149             :         }
     150             :     }
     151             : 
     152           0 :     aSize = aFTCautionText.GetSizePixel();
     153           0 :     aMinSize = aFTCautionText.CalcMinimumSize( aSize.Width() );
     154             : 
     155           0 :     if ( aSize.Height() > aMinSize.Height() )
     156             :     {
     157           0 :         aFTCautionText.SetSizePixel( aMinSize );
     158           0 :         long nTemp = aSize.Height() - aMinSize.Height();
     159           0 :         nDelta += nTemp;
     160           0 :         Window* pWins[] = { &aFLCautionText, &aOKBtn, &aCancelBtn, &aHelpBtn };
     161           0 :         Window** pWindow = pWins;
     162           0 :         const sal_Int32 nCount = sizeof( pWins ) / sizeof( pWins[0] );
     163           0 :         for ( sal_Int32 i = 0; i < nCount; ++i, ++pWindow )
     164             :         {
     165           0 :             Point aNewPos = (*pWindow)->GetPosPixel();
     166           0 :             aNewPos.Y() -= nTemp;
     167           0 :             (*pWindow)->SetPosPixel( aNewPos );
     168             :         }
     169             :     }
     170             : 
     171           0 :     if ( nDelta > 0 )
     172             :     {
     173           0 :         Size aDlgSize = GetOutputSizePixel();
     174           0 :         aDlgSize.Height() -= nDelta;
     175           0 :         SetSizePixel( aDlgSize );
     176             :     }
     177           0 : }
     178             : 
     179             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10