1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: passcrtdlg.cxx,v $
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>
37 #ifndef UUI_PASSCRTDLG_HRC
38 #include <passcrtdlg.hrc>
40 #include <passcrtdlg.hxx>
42 // PasswordCreateDialog---------------------------------------------------
44 // -----------------------------------------------------------------------
46 IMPL_LINK( PasswordCreateDialog
, EditHdl_Impl
, Edit
*, EMPTYARG
)
48 aOKBtn
.Enable( aEDPasswordCrt
.GetText().Len() >= nMinLen
);
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() )
61 String
aErrorMsg( ResId( STR_ERROR_PASSWORDS_NOT_IDENTICAL
, *pResourceMgr
));
62 ErrorBox
aErrorBox( this, WB_OK
, aErrorMsg
);
64 aEDPasswordRepeat
.SetText( String() );
65 aEDPasswordCrt
.GrabFocus();
70 // -----------------------------------------------------------------------
72 PasswordCreateDialog::PasswordCreateDialog( Window
* _pParent
, ResMgr
* pResMgr
, bool bMSCryptoMode
)
73 :ModalDialog( _pParent
, ResId( DLG_UUI_PASSWORD_CRT
, *pResMgr
) )
74 ,aFTPasswordCrt ( this, ResId( FT_PASSWORD_CRT
, *pResMgr
) )
75 ,aEDPasswordCrt ( this, ResId( ED_PASSWORD_CRT
, *pResMgr
) )
76 ,aFTPasswordRepeat ( this, ResId( FT_PASSWORD_REPEAT
, *pResMgr
) )
77 ,aEDPasswordRepeat ( this, ResId( ED_PASSWORD_REPEAT
, *pResMgr
) )
78 ,aFTWarning ( this, ResId( bMSCryptoMode
? FT_MSPASSWORD_WARNING
: FT_PASSWORD_WARNING
, *pResMgr
) )
79 ,aFixedLine1 ( this, ResId( FL_FIXED_LINE_1
, *pResMgr
) )
80 ,aOKBtn ( this, ResId( BTN_PASSCRT_OK
, *pResMgr
) )
81 ,aCancelBtn ( this, ResId( BTN_PASSCRT_CANCEL
, *pResMgr
) )
82 ,aHelpBtn ( this, ResId( BTN_PASSCRT_HELP
, *pResMgr
) )
83 ,pResourceMgr ( pResMgr
)
84 ,nMinLen( bMSCryptoMode
? 1 : 5 )
88 aOKBtn
.SetClickHdl( LINK( this, PasswordCreateDialog
, OKHdl_Impl
) );
89 aEDPasswordCrt
.SetModifyHdl( LINK( this, PasswordCreateDialog
, EditHdl_Impl
) );
91 aOKBtn
.Enable( sal_False
);
95 aEDPasswordCrt
.SetMaxTextLen( 15 );
96 aEDPasswordRepeat
.SetMaxTextLen( 15 );
99 long nLabelWidth
= aFTWarning
.GetSizePixel().Width();
100 long nLabelHeight
= aFTWarning
.GetSizePixel().Height();
101 long nTextWidth
= aFTWarning
.GetCtrlTextWidth( aFTWarning
.GetText() );
102 long nTextHeight
= aFTWarning
.GetTextHeight();
104 Rectangle
aLabelRect( aFTWarning
.GetPosPixel(), aFTWarning
.GetSizePixel() );
105 Rectangle aRect
= aFTWarning
.GetTextRect( aLabelRect
, aFTWarning
.GetText() );
107 long nNewLabelHeight
= 0;
108 for( nNewLabelHeight
= ( nTextWidth
/ nLabelWidth
+ 1 ) * nTextHeight
;
109 nNewLabelHeight
< aRect
.GetHeight();
110 nNewLabelHeight
+= nTextHeight
) {} ;
112 long nDelta
= nNewLabelHeight
- nLabelHeight
;
114 Size aNewDlgSize
= GetSizePixel();
115 aNewDlgSize
.Height() += nDelta
;
116 SetSizePixel( aNewDlgSize
);
118 Size aNewWarningSize
= aFTWarning
.GetSizePixel();
119 aNewWarningSize
.Height() = nNewLabelHeight
;
120 aFTWarning
.SetPosSizePixel( aFTWarning
.GetPosPixel(), aNewWarningSize
);
122 Window
* pControls
[] = { &aFixedLine1
, &aOKBtn
, &aCancelBtn
, &aHelpBtn
};
123 const sal_Int32 nCCount
= sizeof( pControls
) / sizeof( pControls
[0] );
124 for ( int i
= 0; i
< nCCount
; ++i
)
126 Point aNewPos
=(*pControls
[i
]).GetPosPixel();
127 aNewPos
.Y() += nDelta
;
128 pControls
[i
]->SetPosSizePixel( aNewPos
, pControls
[i
]->GetSizePixel() );