Bump for 3.6-28
[LibreOffice.git] / uui / source / masterpasscrtdlg.cxx
blob5874cb9c6063aa09f8e7273b5c2acfc91b1fe60f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <sal/macros.h>
30 #include <vcl/msgbox.hxx>
32 #include <ids.hrc>
33 #include <masterpasscrtdlg.hrc>
34 #include <masterpasscrtdlg.hxx>
36 // MasterPasswordCreateDialog---------------------------------------------------
38 // -----------------------------------------------------------------------
40 IMPL_LINK_NOARG(MasterPasswordCreateDialog, EditHdl_Impl)
42 aOKBtn.Enable( aEDMasterPasswordCrt.GetText().Len() >= nMinLen );
43 return 0;
46 // -----------------------------------------------------------------------
48 IMPL_LINK_NOARG(MasterPasswordCreateDialog, OKHdl_Impl)
50 // compare both passwords and show message box if there are not equal!!
51 if( aEDMasterPasswordCrt.GetText() == aEDMasterPasswordRepeat.GetText() )
52 EndDialog( RET_OK );
53 else
55 String aErrorMsg( ResId( STR_ERROR_PASSWORDS_NOT_IDENTICAL, *pResourceMgr ));
56 ErrorBox aErrorBox( this, WB_OK, aErrorMsg );
57 aErrorBox.Execute();
58 aEDMasterPasswordCrt.SetText( String() );
59 aEDMasterPasswordRepeat.SetText( String() );
60 aEDMasterPasswordCrt.GrabFocus();
62 return 1;
65 // -----------------------------------------------------------------------
67 MasterPasswordCreateDialog::MasterPasswordCreateDialog
69 Window* pParent,
70 ResMgr* pResMgr
71 ) :
73 ModalDialog( pParent, ResId( DLG_UUI_MASTERPASSWORD_CRT, *pResMgr ) ),
75 aFTInfoText ( this, ResId( FT_INFOTEXT, *pResMgr ) ),
76 aFLInfoText ( this, ResId( FL_INFOTEXT, *pResMgr ) ),
78 aFTMasterPasswordCrt ( this, ResId( FT_MASTERPASSWORD_CRT, *pResMgr ) ),
79 aEDMasterPasswordCrt ( this, ResId( ED_MASTERPASSWORD_CRT, *pResMgr ) ),
80 aFTMasterPasswordRepeat ( this, ResId( FT_MASTERPASSWORD_REPEAT, *pResMgr ) ),
81 aEDMasterPasswordRepeat ( this, ResId( ED_MASTERPASSWORD_REPEAT, *pResMgr ) ),
83 aFTCautionText ( this, ResId( FT_CAUTIONTEXT, *pResMgr ) ),
84 aFLCautionText ( this, ResId( FL_CAUTIONTEXT, *pResMgr ) ),
86 aFTMasterPasswordWarning ( this, ResId( FT_MASTERPASSWORD_WARNING, *pResMgr ) ),
87 aFL ( this, ResId( FL_FIXED_LINE, *pResMgr ) ),
88 aOKBtn ( this, ResId( BTN_MASTERPASSCRT_OK, *pResMgr ) ),
89 aCancelBtn ( this, ResId( BTN_MASTERPASSCRT_CANCEL, *pResMgr ) ),
90 aHelpBtn ( this, ResId( BTN_MASTERPASSCRT_HELP, *pResMgr ) ),
92 pResourceMgr ( pResMgr ),
93 nMinLen ( 1 )
95 FreeResource();
97 aOKBtn.Enable( sal_False );
98 aOKBtn.SetClickHdl( LINK( this, MasterPasswordCreateDialog, OKHdl_Impl ) );
99 aEDMasterPasswordCrt.SetModifyHdl( LINK( this, MasterPasswordCreateDialog, EditHdl_Impl ) );
101 CalculateTextHeight();
103 long nLableWidth = aFTMasterPasswordWarning.GetSizePixel().Width();
104 long nLabelHeight = aFTMasterPasswordWarning.GetSizePixel().Height();
105 long nTextWidth = aFTMasterPasswordWarning.GetCtrlTextWidth( aFTMasterPasswordWarning.GetText() );
106 long nTextHeight = aFTMasterPasswordWarning.GetTextHeight();
108 Rectangle aLabelRect( aFTMasterPasswordWarning.GetPosPixel(), aFTMasterPasswordWarning.GetSizePixel() );
109 Rectangle aRect = aFTMasterPasswordWarning.GetTextRect( aLabelRect, aFTMasterPasswordWarning.GetText() );
111 long nNewLabelHeight = 0;
112 if ( nTextWidth > 0 )
114 for( nNewLabelHeight = ( nTextWidth / nLableWidth + 1 ) * nTextHeight;
115 nNewLabelHeight < aRect.GetHeight();
116 nNewLabelHeight += nTextHeight ) {};
119 long nDelta = nNewLabelHeight - nLabelHeight;
120 Size aNewDlgSize = GetSizePixel();
121 aNewDlgSize.Height() += nDelta;
122 SetSizePixel( aNewDlgSize );
124 Size aNewWarningSize = aFTMasterPasswordWarning.GetSizePixel();
125 aNewWarningSize.Height() = nNewLabelHeight;
126 aFTMasterPasswordWarning.SetPosSizePixel( aFTMasterPasswordWarning.GetPosPixel(), aNewWarningSize );
128 Window* pControls[] = { &aFL, &aOKBtn, &aCancelBtn, &aHelpBtn };
129 const sal_Int32 nCCount = sizeof( pControls ) / sizeof( pControls[0] );
130 for ( int i = 0; i < nCCount; ++i )
132 Point aNewPos =(*pControls[i]).GetPosPixel();
133 aNewPos.Y() += nDelta;
134 pControls[i]->SetPosSizePixel( aNewPos, pControls[i]->GetSizePixel() );
138 void MasterPasswordCreateDialog::CalculateTextHeight()
140 Size aSize = aFTInfoText.GetSizePixel();
141 Size aMinSize = aFTInfoText.CalcMinimumSize( aSize.Width() );
142 long nDelta = 0;
144 if ( aSize.Height() > aMinSize.Height() )
146 aFTInfoText.SetSizePixel( aMinSize );
147 nDelta = aSize.Height() - aMinSize.Height();
148 Window* pWins[] = { &aFLInfoText, &aFTMasterPasswordCrt, &aEDMasterPasswordCrt,
149 &aFTMasterPasswordRepeat, &aEDMasterPasswordRepeat, &aFTCautionText,
150 &aFLCautionText, &aOKBtn, &aCancelBtn, &aHelpBtn };
151 Window** pWindow = pWins;
152 const sal_Int32 nCount = sizeof( pWins ) / sizeof( pWins[0] );
153 for ( sal_Int32 i = 0; i < nCount; ++i, ++pWindow )
155 Point aNewPos = (*pWindow)->GetPosPixel();
156 aNewPos.Y() -= nDelta;
157 (*pWindow)->SetPosPixel( aNewPos );
161 aSize = aFTCautionText.GetSizePixel();
162 aMinSize = aFTCautionText.CalcMinimumSize( aSize.Width() );
164 if ( aSize.Height() > aMinSize.Height() )
166 aFTCautionText.SetSizePixel( aMinSize );
167 long nTemp = aSize.Height() - aMinSize.Height();
168 nDelta += nTemp;
169 Window* pWins[] = { &aFLCautionText, &aOKBtn, &aCancelBtn, &aHelpBtn };
170 Window** pWindow = pWins;
171 const sal_Int32 nCount = sizeof( pWins ) / sizeof( pWins[0] );
172 for ( sal_Int32 i = 0; i < nCount; ++i, ++pWindow )
174 Point aNewPos = (*pWindow)->GetPosPixel();
175 aNewPos.Y() -= nTemp;
176 (*pWindow)->SetPosPixel( aNewPos );
180 if ( nDelta > 0 )
182 Size aDlgSize = GetOutputSizePixel();
183 aDlgSize.Height() -= nDelta;
184 SetSizePixel( aDlgSize );
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */