merge the formfield patch from ooo-build
[ooovba.git] / uui / source / passcrtdlg.cxx
blob9a98bad6c1d12edac80c4a3ed5d40510cdddafe6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: passcrtdlg.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <svtools/filedlg.hxx>
32 #include <vcl/msgbox.hxx>
34 #ifndef UUI_IDS_HRC
35 #include <ids.hrc>
36 #endif
37 #ifndef UUI_PASSCRTDLG_HRC
38 #include <passcrtdlg.hrc>
39 #endif
40 #include <passcrtdlg.hxx>
42 // PasswordCreateDialog---------------------------------------------------
44 // -----------------------------------------------------------------------
46 IMPL_LINK( PasswordCreateDialog, EditHdl_Impl, Edit *, EMPTYARG )
48 aOKBtn.Enable( aEDPasswordCrt.GetText().Len() >= nMinLen );
49 return 0;
52 // -----------------------------------------------------------------------
54 IMPL_LINK( PasswordCreateDialog, OKHdl_Impl, OKButton *, EMPTYARG )
56 // compare both passwords and show message box if there are not equal!!
57 if( aEDPasswordCrt.GetText() == aEDPasswordRepeat.GetText() )
58 EndDialog( RET_OK );
59 else
61 String aErrorMsg( ResId( STR_ERROR_PASSWORDS_NOT_IDENTICAL, *pResourceMgr ));
62 ErrorBox aErrorBox( this, WB_OK, aErrorMsg );
63 aErrorBox.Execute();
64 aEDPasswordCrt.SetText( String() );
65 aEDPasswordRepeat.SetText( String() );
66 aEDPasswordCrt.GrabFocus();
68 return 1;
71 // -----------------------------------------------------------------------
73 PasswordCreateDialog::PasswordCreateDialog( Window* _pParent, ResMgr * pResMgr, bool bMSCryptoMode)
74 :ModalDialog( _pParent, ResId( DLG_UUI_PASSWORD_CRT, *pResMgr ) )
75 ,aFTPasswordCrt ( this, ResId( FT_PASSWORD_CRT, *pResMgr ) )
76 ,aEDPasswordCrt ( this, ResId( ED_PASSWORD_CRT, *pResMgr ) )
77 ,aFTPasswordRepeat ( this, ResId( FT_PASSWORD_REPEAT, *pResMgr ) )
78 ,aEDPasswordRepeat ( this, ResId( ED_PASSWORD_REPEAT, *pResMgr ) )
79 ,aFTWarning ( this, ResId( bMSCryptoMode ? FT_MSPASSWORD_WARNING : FT_PASSWORD_WARNING, *pResMgr ) )
80 ,aFixedLine1 ( this, ResId( FL_FIXED_LINE_1, *pResMgr ) )
81 ,aOKBtn ( this, ResId( BTN_PASSCRT_OK, *pResMgr ) )
82 ,aCancelBtn ( this, ResId( BTN_PASSCRT_CANCEL, *pResMgr ) )
83 ,aHelpBtn ( this, ResId( BTN_PASSCRT_HELP, *pResMgr ) )
84 ,pResourceMgr ( pResMgr )
85 ,nMinLen(1) // if it should be changed for ODF, it must stay 1 for bMSCryptoMode
87 FreeResource();
89 aOKBtn.SetClickHdl( LINK( this, PasswordCreateDialog, OKHdl_Impl ) );
90 aEDPasswordCrt.SetModifyHdl( LINK( this, PasswordCreateDialog, EditHdl_Impl ) );
92 aOKBtn.Enable( sal_False );
94 if ( bMSCryptoMode )
96 aEDPasswordCrt.SetMaxTextLen( 15 );
97 aEDPasswordRepeat.SetMaxTextLen( 15 );
100 long nLabelWidth = aFTWarning.GetSizePixel().Width();
101 long nLabelHeight = aFTWarning.GetSizePixel().Height();
102 long nTextWidth = aFTWarning.GetCtrlTextWidth( aFTWarning.GetText() );
103 long nTextHeight = aFTWarning.GetTextHeight();
105 Rectangle aLabelRect( aFTWarning.GetPosPixel(), aFTWarning.GetSizePixel() );
106 Rectangle aRect = aFTWarning.GetTextRect( aLabelRect, aFTWarning.GetText() );
108 long nNewLabelHeight = 0;
109 for( nNewLabelHeight = ( nTextWidth / nLabelWidth + 1 ) * nTextHeight;
110 nNewLabelHeight < aRect.GetHeight();
111 nNewLabelHeight += nTextHeight ) {} ;
113 long nDelta = nNewLabelHeight - nLabelHeight;
115 Size aNewDlgSize = GetSizePixel();
116 aNewDlgSize.Height() += nDelta;
117 SetSizePixel( aNewDlgSize );
119 Size aNewWarningSize = aFTWarning.GetSizePixel();
120 aNewWarningSize.Height() = nNewLabelHeight;
121 aFTWarning.SetPosSizePixel( aFTWarning.GetPosPixel(), aNewWarningSize );
123 Window* pControls[] = { &aFixedLine1, &aOKBtn, &aCancelBtn, &aHelpBtn };
124 const sal_Int32 nCCount = sizeof( pControls ) / sizeof( pControls[0] );
125 for ( int i = 0; i < nCCount; ++i )
127 Point aNewPos =(*pControls[i]).GetPosPixel();
128 aNewPos.Y() += nDelta;
129 pControls[i]->SetPosSizePixel( aNewPos, pControls[i]->GetSizePixel() );