1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <svtools/filedlg.hxx> 29 #include <vcl/msgbox.hxx> 30 31 #ifndef UUI_IDS_HRC 32 #include <ids.hrc> 33 #endif 34 #ifndef UUI_MASTERPASSCRTDLG_HRC 35 #include <masterpasscrtdlg.hrc> 36 #endif 37 #include <masterpasscrtdlg.hxx> 38 39 // MasterPasswordCreateDialog--------------------------------------------------- 40 41 // ----------------------------------------------------------------------- 42 43 IMPL_LINK( MasterPasswordCreateDialog, EditHdl_Impl, Edit *, EMPTYARG ) 44 { 45 aOKBtn.Enable( aEDMasterPasswordCrt.GetText().Len() >= nMinLen ); 46 return 0; 47 } 48 49 // ----------------------------------------------------------------------- 50 51 IMPL_LINK( MasterPasswordCreateDialog, OKHdl_Impl, OKButton *, EMPTYARG ) 52 { 53 // compare both passwords and show message box if there are not equal!! 54 if( aEDMasterPasswordCrt.GetText() == aEDMasterPasswordRepeat.GetText() ) 55 EndDialog( RET_OK ); 56 else 57 { 58 String aErrorMsg( ResId( STR_ERROR_PASSWORDS_NOT_IDENTICAL, *pResourceMgr )); 59 ErrorBox aErrorBox( this, WB_OK, aErrorMsg ); 60 aErrorBox.Execute(); 61 aEDMasterPasswordCrt.SetText( String() ); 62 aEDMasterPasswordRepeat.SetText( String() ); 63 aEDMasterPasswordCrt.GrabFocus(); 64 } 65 return 1; 66 } 67 68 // ----------------------------------------------------------------------- 69 70 MasterPasswordCreateDialog::MasterPasswordCreateDialog 71 ( 72 Window* pParent, 73 ResMgr* pResMgr 74 ) : 75 76 ModalDialog( pParent, ResId( DLG_UUI_MASTERPASSWORD_CRT, *pResMgr ) ), 77 78 aFTInfoText ( this, ResId( FT_INFOTEXT, *pResMgr ) ), 79 aFLInfoText ( this, ResId( FL_INFOTEXT, *pResMgr ) ), 80 81 aFTMasterPasswordCrt ( this, ResId( FT_MASTERPASSWORD_CRT, *pResMgr ) ), 82 aEDMasterPasswordCrt ( this, ResId( ED_MASTERPASSWORD_CRT, *pResMgr ) ), 83 aFTMasterPasswordRepeat ( this, ResId( FT_MASTERPASSWORD_REPEAT, *pResMgr ) ), 84 aEDMasterPasswordRepeat ( this, ResId( ED_MASTERPASSWORD_REPEAT, *pResMgr ) ), 85 86 aFTCautionText ( this, ResId( FT_CAUTIONTEXT, *pResMgr ) ), 87 aFLCautionText ( this, ResId( FL_CAUTIONTEXT, *pResMgr ) ), 88 89 aFTMasterPasswordWarning ( this, ResId( FT_MASTERPASSWORD_WARNING, *pResMgr ) ), 90 aFL ( this, ResId( FL_FIXED_LINE, *pResMgr ) ), 91 aOKBtn ( this, ResId( BTN_MASTERPASSCRT_OK, *pResMgr ) ), 92 aCancelBtn ( this, ResId( BTN_MASTERPASSCRT_CANCEL, *pResMgr ) ), 93 aHelpBtn ( this, ResId( BTN_MASTERPASSCRT_HELP, *pResMgr ) ), 94 95 pResourceMgr ( pResMgr ), 96 nMinLen ( 1 ) 97 { 98 FreeResource(); 99 100 aOKBtn.Enable( sal_False ); 101 aOKBtn.SetClickHdl( LINK( this, MasterPasswordCreateDialog, OKHdl_Impl ) ); 102 aEDMasterPasswordCrt.SetModifyHdl( LINK( this, MasterPasswordCreateDialog, EditHdl_Impl ) ); 103 104 CalculateTextHeight(); 105 106 long nLableWidth = aFTMasterPasswordWarning.GetSizePixel().Width(); 107 long nLabelHeight = aFTMasterPasswordWarning.GetSizePixel().Height(); 108 long nTextWidth = aFTMasterPasswordWarning.GetCtrlTextWidth( aFTMasterPasswordWarning.GetText() ); 109 long nTextHeight = aFTMasterPasswordWarning.GetTextHeight(); 110 111 Rectangle aLabelRect( aFTMasterPasswordWarning.GetPosPixel(), aFTMasterPasswordWarning.GetSizePixel() ); 112 Rectangle aRect = aFTMasterPasswordWarning.GetTextRect( aLabelRect, aFTMasterPasswordWarning.GetText() ); 113 114 long nNewLabelHeight = 0; 115 if ( nTextWidth > 0 ) 116 { 117 for( nNewLabelHeight = ( nTextWidth / nLableWidth + 1 ) * nTextHeight; 118 nNewLabelHeight < aRect.GetHeight(); 119 nNewLabelHeight += nTextHeight ) {}; 120 } 121 122 long nDelta = nNewLabelHeight - nLabelHeight; 123 Size aNewDlgSize = GetSizePixel(); 124 aNewDlgSize.Height() += nDelta; 125 SetSizePixel( aNewDlgSize ); 126 127 Size aNewWarningSize = aFTMasterPasswordWarning.GetSizePixel(); 128 aNewWarningSize.Height() = nNewLabelHeight; 129 aFTMasterPasswordWarning.SetPosSizePixel( aFTMasterPasswordWarning.GetPosPixel(), aNewWarningSize ); 130 131 Window* pControls[] = { &aFL, &aOKBtn, &aCancelBtn, &aHelpBtn }; 132 const sal_Int32 nCCount = sizeof( pControls ) / sizeof( pControls[0] ); 133 for ( int i = 0; i < nCCount; ++i ) 134 { 135 Point aNewPos =(*pControls[i]).GetPosPixel(); 136 aNewPos.Y() += nDelta; 137 pControls[i]->SetPosSizePixel( aNewPos, pControls[i]->GetSizePixel() ); 138 } 139 }; 140 141 void MasterPasswordCreateDialog::CalculateTextHeight() 142 { 143 Size aSize = aFTInfoText.GetSizePixel(); 144 Size aMinSize = aFTInfoText.CalcMinimumSize( aSize.Width() ); 145 long nDelta = 0; 146 147 if ( aSize.Height() > aMinSize.Height() ) 148 { 149 aFTInfoText.SetSizePixel( aMinSize ); 150 nDelta = aSize.Height() - aMinSize.Height(); 151 Window* pWins[] = { &aFLInfoText, &aFTMasterPasswordCrt, &aEDMasterPasswordCrt, 152 &aFTMasterPasswordRepeat, &aEDMasterPasswordRepeat, &aFTCautionText, 153 &aFLCautionText, &aOKBtn, &aCancelBtn, &aHelpBtn }; 154 Window** pWindow = pWins; 155 const sal_Int32 nCount = sizeof( pWins ) / sizeof( pWins[0] ); 156 for ( sal_Int32 i = 0; i < nCount; ++i, ++pWindow ) 157 { 158 Point aNewPos = (*pWindow)->GetPosPixel(); 159 aNewPos.Y() -= nDelta; 160 (*pWindow)->SetPosPixel( aNewPos ); 161 } 162 } 163 164 aSize = aFTCautionText.GetSizePixel(); 165 aMinSize = aFTCautionText.CalcMinimumSize( aSize.Width() ); 166 167 if ( aSize.Height() > aMinSize.Height() ) 168 { 169 aFTCautionText.SetSizePixel( aMinSize ); 170 long nTemp = aSize.Height() - aMinSize.Height(); 171 nDelta += nTemp; 172 Window* pWins[] = { &aFLCautionText, &aOKBtn, &aCancelBtn, &aHelpBtn }; 173 Window** pWindow = pWins; 174 const sal_Int32 nCount = sizeof( pWins ) / sizeof( pWins[0] ); 175 for ( sal_Int32 i = 0; i < nCount; ++i, ++pWindow ) 176 { 177 Point aNewPos = (*pWindow)->GetPosPixel(); 178 aNewPos.Y() -= nTemp; 179 (*pWindow)->SetPosPixel( aNewPos ); 180 } 181 } 182 183 if ( nDelta > 0 ) 184 { 185 Size aDlgSize = GetOutputSizePixel(); 186 aDlgSize.Height() -= nDelta; 187 SetSizePixel( aDlgSize ); 188 } 189 } 190 191