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: masterpasscrtdlg.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_MASTERPASSCRTDLG_HRC
38 #include <masterpasscrtdlg.hrc>
40 #include <masterpasscrtdlg.hxx>
42 // MasterPasswordCreateDialog---------------------------------------------------
44 // -----------------------------------------------------------------------
46 IMPL_LINK( MasterPasswordCreateDialog
, EditHdl_Impl
, Edit
*, EMPTYARG
)
48 aOKBtn
.Enable( aEDMasterPasswordCrt
.GetText().Len() >= nMinLen
);
52 // -----------------------------------------------------------------------
54 IMPL_LINK( MasterPasswordCreateDialog
, OKHdl_Impl
, OKButton
*, EMPTYARG
)
56 // compare both passwords and show message box if there are not equal!!
57 if( aEDMasterPasswordCrt
.GetText() == aEDMasterPasswordRepeat
.GetText() )
61 String
aErrorMsg( ResId( STR_ERROR_PASSWORDS_NOT_IDENTICAL
, *pResourceMgr
));
62 ErrorBox
aErrorBox( this, WB_OK
, aErrorMsg
);
64 aEDMasterPasswordCrt
.SetText( String() );
65 aEDMasterPasswordRepeat
.SetText( String() );
66 aEDMasterPasswordCrt
.GrabFocus();
71 // -----------------------------------------------------------------------
73 MasterPasswordCreateDialog::MasterPasswordCreateDialog
79 ModalDialog( pParent
, ResId( DLG_UUI_MASTERPASSWORD_CRT
, *pResMgr
) ),
81 aFTInfoText ( this, ResId( FT_INFOTEXT
, *pResMgr
) ),
82 aFLInfoText ( this, ResId( FL_INFOTEXT
, *pResMgr
) ),
84 aFTMasterPasswordCrt ( this, ResId( FT_MASTERPASSWORD_CRT
, *pResMgr
) ),
85 aEDMasterPasswordCrt ( this, ResId( ED_MASTERPASSWORD_CRT
, *pResMgr
) ),
86 aFTMasterPasswordRepeat ( this, ResId( FT_MASTERPASSWORD_REPEAT
, *pResMgr
) ),
87 aEDMasterPasswordRepeat ( this, ResId( ED_MASTERPASSWORD_REPEAT
, *pResMgr
) ),
89 aFTCautionText ( this, ResId( FT_CAUTIONTEXT
, *pResMgr
) ),
90 aFLCautionText ( this, ResId( FL_CAUTIONTEXT
, *pResMgr
) ),
92 aFTMasterPasswordWarning ( this, ResId( FT_MASTERPASSWORD_WARNING
, *pResMgr
) ),
93 aFL ( this, ResId( FL_FIXED_LINE
, *pResMgr
) ),
94 aOKBtn ( this, ResId( BTN_MASTERPASSCRT_OK
, *pResMgr
) ),
95 aCancelBtn ( this, ResId( BTN_MASTERPASSCRT_CANCEL
, *pResMgr
) ),
96 aHelpBtn ( this, ResId( BTN_MASTERPASSCRT_HELP
, *pResMgr
) ),
98 pResourceMgr ( pResMgr
),
103 aOKBtn
.Enable( sal_False
);
104 aOKBtn
.SetClickHdl( LINK( this, MasterPasswordCreateDialog
, OKHdl_Impl
) );
105 aEDMasterPasswordCrt
.SetModifyHdl( LINK( this, MasterPasswordCreateDialog
, EditHdl_Impl
) );
107 CalculateTextHeight();
109 long nLableWidth
= aFTMasterPasswordWarning
.GetSizePixel().Width();
110 long nLabelHeight
= aFTMasterPasswordWarning
.GetSizePixel().Height();
111 long nTextWidth
= aFTMasterPasswordWarning
.GetCtrlTextWidth( aFTMasterPasswordWarning
.GetText() );
112 long nTextHeight
= aFTMasterPasswordWarning
.GetTextHeight();
114 Rectangle
aLabelRect( aFTMasterPasswordWarning
.GetPosPixel(), aFTMasterPasswordWarning
.GetSizePixel() );
115 Rectangle aRect
= aFTMasterPasswordWarning
.GetTextRect( aLabelRect
, aFTMasterPasswordWarning
.GetText() );
117 long nNewLabelHeight
= 0;
118 if ( nTextWidth
> 0 )
120 for( nNewLabelHeight
= ( nTextWidth
/ nLableWidth
+ 1 ) * nTextHeight
;
121 nNewLabelHeight
< aRect
.GetHeight();
122 nNewLabelHeight
+= nTextHeight
) {};
125 long nDelta
= nNewLabelHeight
- nLabelHeight
;
126 Size aNewDlgSize
= GetSizePixel();
127 aNewDlgSize
.Height() += nDelta
;
128 SetSizePixel( aNewDlgSize
);
130 Size aNewWarningSize
= aFTMasterPasswordWarning
.GetSizePixel();
131 aNewWarningSize
.Height() = nNewLabelHeight
;
132 aFTMasterPasswordWarning
.SetPosSizePixel( aFTMasterPasswordWarning
.GetPosPixel(), aNewWarningSize
);
134 Window
* pControls
[] = { &aFL
, &aOKBtn
, &aCancelBtn
, &aHelpBtn
};
135 const sal_Int32 nCCount
= sizeof( pControls
) / sizeof( pControls
[0] );
136 for ( int i
= 0; i
< nCCount
; ++i
)
138 Point aNewPos
=(*pControls
[i
]).GetPosPixel();
139 aNewPos
.Y() += nDelta
;
140 pControls
[i
]->SetPosSizePixel( aNewPos
, pControls
[i
]->GetSizePixel() );
144 void MasterPasswordCreateDialog::CalculateTextHeight()
146 Size aSize
= aFTInfoText
.GetSizePixel();
147 Size aMinSize
= aFTInfoText
.CalcMinimumSize( aSize
.Width() );
150 if ( aSize
.Height() > aMinSize
.Height() )
152 aFTInfoText
.SetSizePixel( aMinSize
);
153 nDelta
= aSize
.Height() - aMinSize
.Height();
154 Window
* pWins
[] = { &aFLInfoText
, &aFTMasterPasswordCrt
, &aEDMasterPasswordCrt
,
155 &aFTMasterPasswordRepeat
, &aEDMasterPasswordRepeat
, &aFTCautionText
,
156 &aFLCautionText
, &aOKBtn
, &aCancelBtn
, &aHelpBtn
};
157 Window
** pWindow
= pWins
;
158 const sal_Int32 nCount
= sizeof( pWins
) / sizeof( pWins
[0] );
159 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pWindow
)
161 Point aNewPos
= (*pWindow
)->GetPosPixel();
162 aNewPos
.Y() -= nDelta
;
163 (*pWindow
)->SetPosPixel( aNewPos
);
167 aSize
= aFTCautionText
.GetSizePixel();
168 aMinSize
= aFTCautionText
.CalcMinimumSize( aSize
.Width() );
170 if ( aSize
.Height() > aMinSize
.Height() )
172 aFTCautionText
.SetSizePixel( aMinSize
);
173 long nTemp
= aSize
.Height() - aMinSize
.Height();
175 Window
* pWins
[] = { &aFLCautionText
, &aOKBtn
, &aCancelBtn
, &aHelpBtn
};
176 Window
** pWindow
= pWins
;
177 const sal_Int32 nCount
= sizeof( pWins
) / sizeof( pWins
[0] );
178 for ( sal_Int32 i
= 0; i
< nCount
; ++i
, ++pWindow
)
180 Point aNewPos
= (*pWindow
)->GetPosPixel();
181 aNewPos
.Y() -= nTemp
;
182 (*pWindow
)->SetPosPixel( aNewPos
);
188 Size aDlgSize
= GetOutputSizePixel();
189 aDlgSize
.Height() -= nDelta
;
190 SetSizePixel( aDlgSize
);