1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "passworddlg.hxx" 29*cdf0e10cSrcweir #include "passworddlg.hrc" 30*cdf0e10cSrcweir #include "ids.hrc" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <svtools/filedlg.hxx> 33*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir using namespace ::com::sun::star; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir // ----------------------------------------------------------------------- 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir static void lcl_Move( Window &rWin, long nOffset ) 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir Point aTmp( rWin.GetPosPixel() ); 44*cdf0e10cSrcweir aTmp.Y() += nOffset; 45*cdf0e10cSrcweir rWin.SetPosPixel( aTmp ); 46*cdf0e10cSrcweir } 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir // ----------------------------------------------------------------------- 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir PasswordDialog::PasswordDialog( 51*cdf0e10cSrcweir Window* _pParent, 52*cdf0e10cSrcweir task::PasswordRequestMode nDlgMode, 53*cdf0e10cSrcweir ResMgr * pResMgr, 54*cdf0e10cSrcweir rtl::OUString& aDocURL, 55*cdf0e10cSrcweir bool bOpenToModify, 56*cdf0e10cSrcweir bool bIsSimplePasswordRequest ) 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir :ModalDialog( _pParent, ResId( DLG_UUI_PASSWORD, *pResMgr ) ) 59*cdf0e10cSrcweir ,aFTPassword( this, ResId( FT_PASSWORD, *pResMgr )) 60*cdf0e10cSrcweir ,aEDPassword( this, ResId( ED_PASSWORD, *pResMgr )) 61*cdf0e10cSrcweir ,aFTConfirmPassword( this, ResId( FT_CONFIRM_PASSWORD, *pResMgr )) 62*cdf0e10cSrcweir ,aEDConfirmPassword( this, ResId( ED_CONFIRM_PASSWORD, *pResMgr )) 63*cdf0e10cSrcweir ,aOKBtn ( this, ResId( BTN_PASSWORD_OK, *pResMgr )) 64*cdf0e10cSrcweir ,aCancelBtn ( this, ResId( BTN_PASSWORD_CANCEL, *pResMgr )) 65*cdf0e10cSrcweir ,aHelpBtn ( this, ResId( BTN_PASSWORD_HELP, *pResMgr )) 66*cdf0e10cSrcweir ,aFixedLine1( this, ResId( FL_FIXED_LINE_1, *pResMgr )) 67*cdf0e10cSrcweir ,nMinLen(1) 68*cdf0e10cSrcweir ,aPasswdMismatch( ResId( STR_PASSWORD_MISMATCH, *pResMgr )) 69*cdf0e10cSrcweir ,nDialogMode( nDlgMode ) 70*cdf0e10cSrcweir ,pResourceMgr ( pResMgr ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir if( nDialogMode == task::PasswordRequestMode_PASSWORD_REENTER ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir const sal_uInt16 nOpenToModifyErrStrId = bOpenToModify ? STR_ERROR_PASSWORD_TO_MODIFY_WRONG : STR_ERROR_PASSWORD_TO_OPEN_WRONG; 75*cdf0e10cSrcweir const sal_uInt16 nErrStrId = bIsSimplePasswordRequest ? STR_ERROR_SIMPLE_PASSWORD_WRONG : nOpenToModifyErrStrId; 76*cdf0e10cSrcweir String aErrorMsg( ResId( nErrStrId, *pResourceMgr )); 77*cdf0e10cSrcweir ErrorBox aErrorBox( this, WB_OK, aErrorMsg ); 78*cdf0e10cSrcweir aErrorBox.Execute(); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // default settings for enter password or reenter passwd... 82*cdf0e10cSrcweir String aTitle( ResId( STR_TITLE_ENTER_PASSWORD, *pResourceMgr ) ); 83*cdf0e10cSrcweir aFTConfirmPassword.Hide(); 84*cdf0e10cSrcweir aEDConfirmPassword.Hide(); 85*cdf0e10cSrcweir aFTConfirmPassword.Enable( sal_False ); 86*cdf0e10cSrcweir aEDConfirmPassword.Enable( sal_False ); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // settings for create password 89*cdf0e10cSrcweir if (nDialogMode == task::PasswordRequestMode_PASSWORD_CREATE) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir aTitle = String( ResId( STR_TITLE_CREATE_PASSWORD, *pResourceMgr ) ); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir aFTConfirmPassword.SetText( String( ResId( STR_CONFIRM_SIMPLE_PASSWORD, *pResourceMgr ) ) ); 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir aFTConfirmPassword.Show(); 96*cdf0e10cSrcweir aEDConfirmPassword.Show(); 97*cdf0e10cSrcweir aFTConfirmPassword.Enable( sal_True ); 98*cdf0e10cSrcweir aEDConfirmPassword.Enable( sal_True ); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir else 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir // shrink dialog by size of hidden controls and move rest up accordingly 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir long nDelta = aFixedLine1.GetPosPixel().Y() - aFTConfirmPassword.GetPosPixel().Y(); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir lcl_Move( aFixedLine1, -nDelta ); 107*cdf0e10cSrcweir lcl_Move( aOKBtn, -nDelta ); 108*cdf0e10cSrcweir lcl_Move( aCancelBtn, -nDelta ); 109*cdf0e10cSrcweir lcl_Move( aHelpBtn, -nDelta ); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir Size aNewDlgSize = GetSizePixel(); 112*cdf0e10cSrcweir aNewDlgSize.Height() -= nDelta; 113*cdf0e10cSrcweir SetSizePixel( aNewDlgSize ); 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir SetText( aTitle ); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir sal_uInt16 nStrId = bOpenToModify ? STR_ENTER_PASSWORD_TO_MODIFY : STR_ENTER_PASSWORD_TO_OPEN; 119*cdf0e10cSrcweir aFTPassword.SetText( String( ResId( nStrId, *pResourceMgr ) ) ); 120*cdf0e10cSrcweir aFTPassword.SetText( aFTPassword.GetText() + aDocURL ); 121*cdf0e10cSrcweir if (bIsSimplePasswordRequest) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir DBG_ASSERT( aDocURL.getLength() == 0, "A simple password request should not have a document URL! Use document password request instead." ); 124*cdf0e10cSrcweir aFTPassword.SetText( String( ResId( STR_ENTER_SIMPLE_PASSWORD, *pResourceMgr ) ) ); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir FreeResource(); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir aOKBtn.SetClickHdl( LINK( this, PasswordDialog, OKHdl_Impl ) ); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir // 133*cdf0e10cSrcweir // move controls down by extra height needed for aFTPassword 134*cdf0e10cSrcweir // (usually only needed if a URL was provided) 135*cdf0e10cSrcweir // 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir long nLabelWidth = aFTPassword.GetSizePixel().Width(); 138*cdf0e10cSrcweir long nLabelHeight = aFTPassword.GetSizePixel().Height(); 139*cdf0e10cSrcweir long nTextWidth = aFTPassword.GetCtrlTextWidth( aFTPassword.GetText() ); 140*cdf0e10cSrcweir long nTextHeight = aFTPassword.GetTextHeight(); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir Rectangle aLabelRect( aFTPassword.GetPosPixel(), aFTPassword.GetSizePixel() ); 143*cdf0e10cSrcweir Rectangle aRect = aFTPassword.GetTextRect( aLabelRect, aFTPassword.GetText() ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir long nNewLabelHeight = 0; 146*cdf0e10cSrcweir for( nNewLabelHeight = ( nTextWidth / nLabelWidth + 1 ) * nTextHeight; 147*cdf0e10cSrcweir nNewLabelHeight < aRect.GetHeight(); 148*cdf0e10cSrcweir nNewLabelHeight += nTextHeight ) {} ; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir long nDelta = nNewLabelHeight - nLabelHeight; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir Size aNewDlgSize = GetSizePixel(); 153*cdf0e10cSrcweir aNewDlgSize.Height() += nDelta; 154*cdf0e10cSrcweir SetSizePixel( aNewDlgSize ); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir Size aNewLabelSize = aFTPassword.GetSizePixel(); 157*cdf0e10cSrcweir aNewLabelSize.Height() = nNewLabelHeight; 158*cdf0e10cSrcweir aFTPassword.SetPosSizePixel( aFTPassword.GetPosPixel(), aNewLabelSize ); 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir lcl_Move( aEDPassword, nDelta ); 161*cdf0e10cSrcweir lcl_Move( aFTConfirmPassword, nDelta ); 162*cdf0e10cSrcweir lcl_Move( aEDConfirmPassword, nDelta ); 163*cdf0e10cSrcweir lcl_Move( aFixedLine1, nDelta ); 164*cdf0e10cSrcweir lcl_Move( aOKBtn, nDelta ); 165*cdf0e10cSrcweir lcl_Move( aCancelBtn, nDelta ); 166*cdf0e10cSrcweir lcl_Move( aHelpBtn, nDelta ); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir IMPL_LINK( PasswordDialog, OKHdl_Impl, OKButton *, EMPTYARG ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir bool bEDPasswdValid = aEDPassword.GetText().Len() >= nMinLen; 173*cdf0e10cSrcweir bool bPasswdMismatch = aEDConfirmPassword.GetText() != aEDPassword.GetText(); 174*cdf0e10cSrcweir bool bValid = (!aEDConfirmPassword.IsVisible() && bEDPasswdValid) || 175*cdf0e10cSrcweir (aEDConfirmPassword.IsVisible() && bEDPasswdValid && !bPasswdMismatch); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir if (aEDConfirmPassword.IsVisible() && bPasswdMismatch) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir ErrorBox aErrorBox( this, WB_OK, aPasswdMismatch ); 180*cdf0e10cSrcweir aErrorBox.Execute(); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir else if (bValid) 183*cdf0e10cSrcweir EndDialog( RET_OK ); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir return 1; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188