1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include <svtools/filedlg.hxx> 25 #include <vcl/msgbox.hxx> 26 27 #ifndef UUI_IDS_HRC 28 #include <ids.hrc> 29 #endif 30 #ifndef UUI_MASTERPASSCRTDLG_HRC 31 #include <masterpasscrtdlg.hrc> 32 #endif 33 #include <masterpasscrtdlg.hxx> 34 35 // MasterPasswordCreateDialog--------------------------------------------------- 36 37 // ----------------------------------------------------------------------- 38 39 IMPL_LINK( MasterPasswordCreateDialog, EditHdl_Impl, Edit *, EMPTYARG ) 40 { 41 aOKBtn.Enable( aEDMasterPasswordCrt.GetText().Len() >= nMinLen ); 42 return 0; 43 } 44 45 // ----------------------------------------------------------------------- 46 47 IMPL_LINK( MasterPasswordCreateDialog, OKHdl_Impl, OKButton *, EMPTYARG ) 48 { 49 // compare both passwords and show message box if there are not equal!! 50 if( aEDMasterPasswordCrt.GetText() == aEDMasterPasswordRepeat.GetText() ) 51 EndDialog( RET_OK ); 52 else 53 { 54 String aErrorMsg( ResId( STR_ERROR_PASSWORDS_NOT_IDENTICAL, *pResourceMgr )); 55 ErrorBox aErrorBox( this, WB_OK, aErrorMsg ); 56 aErrorBox.Execute(); 57 aEDMasterPasswordCrt.SetText( String() ); 58 aEDMasterPasswordRepeat.SetText( String() ); 59 aEDMasterPasswordCrt.GrabFocus(); 60 } 61 return 1; 62 } 63 64 // ----------------------------------------------------------------------- 65 66 MasterPasswordCreateDialog::MasterPasswordCreateDialog 67 ( 68 Window* pParent, 69 ResMgr* pResMgr 70 ) : 71 72 ModalDialog( pParent, ResId( DLG_UUI_MASTERPASSWORD_CRT, *pResMgr ) ), 73 74 aFTInfoText ( this, ResId( FT_INFOTEXT, *pResMgr ) ), 75 aFLInfoText ( this, ResId( FL_INFOTEXT, *pResMgr ) ), 76 77 aFTMasterPasswordCrt ( this, ResId( FT_MASTERPASSWORD_CRT, *pResMgr ) ), 78 aEDMasterPasswordCrt ( this, ResId( ED_MASTERPASSWORD_CRT, *pResMgr ) ), 79 aFTMasterPasswordRepeat ( this, ResId( FT_MASTERPASSWORD_REPEAT, *pResMgr ) ), 80 aEDMasterPasswordRepeat ( this, ResId( ED_MASTERPASSWORD_REPEAT, *pResMgr ) ), 81 82 aFTCautionText ( this, ResId( FT_CAUTIONTEXT, *pResMgr ) ), 83 aFLCautionText ( this, ResId( FL_CAUTIONTEXT, *pResMgr ) ), 84 85 aFTMasterPasswordWarning ( this, ResId( FT_MASTERPASSWORD_WARNING, *pResMgr ) ), 86 aFL ( this, ResId( FL_FIXED_LINE, *pResMgr ) ), 87 aOKBtn ( this, ResId( BTN_MASTERPASSCRT_OK, *pResMgr ) ), 88 aCancelBtn ( this, ResId( BTN_MASTERPASSCRT_CANCEL, *pResMgr ) ), 89 aHelpBtn ( this, ResId( BTN_MASTERPASSCRT_HELP, *pResMgr ) ), 90 91 pResourceMgr ( pResMgr ), 92 nMinLen ( 1 ) 93 { 94 FreeResource(); 95 96 aOKBtn.Enable( sal_False ); 97 aOKBtn.SetClickHdl( LINK( this, MasterPasswordCreateDialog, OKHdl_Impl ) ); 98 aEDMasterPasswordCrt.SetModifyHdl( LINK( this, MasterPasswordCreateDialog, EditHdl_Impl ) ); 99 100 CalculateTextHeight(); 101 102 long nLableWidth = aFTMasterPasswordWarning.GetSizePixel().Width(); 103 long nLabelHeight = aFTMasterPasswordWarning.GetSizePixel().Height(); 104 long nTextWidth = aFTMasterPasswordWarning.GetCtrlTextWidth( aFTMasterPasswordWarning.GetText() ); 105 long nTextHeight = aFTMasterPasswordWarning.GetTextHeight(); 106 107 Rectangle aLabelRect( aFTMasterPasswordWarning.GetPosPixel(), aFTMasterPasswordWarning.GetSizePixel() ); 108 Rectangle aRect = aFTMasterPasswordWarning.GetTextRect( aLabelRect, aFTMasterPasswordWarning.GetText() ); 109 110 long nNewLabelHeight = 0; 111 if ( nTextWidth > 0 ) 112 { 113 for( nNewLabelHeight = ( nTextWidth / nLableWidth + 1 ) * nTextHeight; 114 nNewLabelHeight < aRect.GetHeight(); 115 nNewLabelHeight += nTextHeight ) {}; 116 } 117 118 long nDelta = nNewLabelHeight - nLabelHeight; 119 Size aNewDlgSize = GetSizePixel(); 120 aNewDlgSize.Height() += nDelta; 121 SetSizePixel( aNewDlgSize ); 122 123 Size aNewWarningSize = aFTMasterPasswordWarning.GetSizePixel(); 124 aNewWarningSize.Height() = nNewLabelHeight; 125 aFTMasterPasswordWarning.SetPosSizePixel( aFTMasterPasswordWarning.GetPosPixel(), aNewWarningSize ); 126 127 Window* pControls[] = { &aFL, &aOKBtn, &aCancelBtn, &aHelpBtn }; 128 const sal_Int32 nCCount = sizeof( pControls ) / sizeof( pControls[0] ); 129 for ( int i = 0; i < nCCount; ++i ) 130 { 131 Point aNewPos =(*pControls[i]).GetPosPixel(); 132 aNewPos.Y() += nDelta; 133 pControls[i]->SetPosSizePixel( aNewPos, pControls[i]->GetSizePixel() ); 134 } 135 }; 136 137 void MasterPasswordCreateDialog::CalculateTextHeight() 138 { 139 Size aSize = aFTInfoText.GetSizePixel(); 140 Size aMinSize = aFTInfoText.CalcMinimumSize( aSize.Width() ); 141 long nDelta = 0; 142 143 if ( aSize.Height() > aMinSize.Height() ) 144 { 145 aFTInfoText.SetSizePixel( aMinSize ); 146 nDelta = aSize.Height() - aMinSize.Height(); 147 Window* pWins[] = { &aFLInfoText, &aFTMasterPasswordCrt, &aEDMasterPasswordCrt, 148 &aFTMasterPasswordRepeat, &aEDMasterPasswordRepeat, &aFTCautionText, 149 &aFLCautionText, &aOKBtn, &aCancelBtn, &aHelpBtn }; 150 Window** pWindow = pWins; 151 const sal_Int32 nCount = sizeof( pWins ) / sizeof( pWins[0] ); 152 for ( sal_Int32 i = 0; i < nCount; ++i, ++pWindow ) 153 { 154 Point aNewPos = (*pWindow)->GetPosPixel(); 155 aNewPos.Y() -= nDelta; 156 (*pWindow)->SetPosPixel( aNewPos ); 157 } 158 } 159 160 aSize = aFTCautionText.GetSizePixel(); 161 aMinSize = aFTCautionText.CalcMinimumSize( aSize.Width() ); 162 163 if ( aSize.Height() > aMinSize.Height() ) 164 { 165 aFTCautionText.SetSizePixel( aMinSize ); 166 long nTemp = aSize.Height() - aMinSize.Height(); 167 nDelta += nTemp; 168 Window* pWins[] = { &aFLCautionText, &aOKBtn, &aCancelBtn, &aHelpBtn }; 169 Window** pWindow = pWins; 170 const sal_Int32 nCount = sizeof( pWins ) / sizeof( pWins[0] ); 171 for ( sal_Int32 i = 0; i < nCount; ++i, ++pWindow ) 172 { 173 Point aNewPos = (*pWindow)->GetPosPixel(); 174 aNewPos.Y() -= nTemp; 175 (*pWindow)->SetPosPixel( aNewPos ); 176 } 177 } 178 179 if ( nDelta > 0 ) 180 { 181 Size aDlgSize = GetOutputSizePixel(); 182 aDlgSize.Height() -= nDelta; 183 SetSizePixel( aDlgSize ); 184 } 185 } 186 187