update dev300-m58
[ooovba.git] / uui / source / passworddlg.cxx
blob77707d3b9b627bf7483943dc97f109736e08c8f4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: passworddlg.cxx,v $
10 * $Revision: 1.7 $
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>
34 #ifndef UUI_IDS_HRC
35 #include <ids.hrc>
36 #endif
37 #ifndef UUI_PASSWORDDLG_HRC
38 #include <passworddlg.hrc>
39 #endif
40 #include <passworddlg.hxx>
42 // PasswordDialog---------------------------------------------------------
44 // -----------------------------------------------------------------------
46 IMPL_LINK( PasswordDialog, OKHdl_Impl, OKButton *, EMPTYARG )
48 EndDialog( RET_OK );
49 return 1;
52 // -----------------------------------------------------------------------
54 PasswordDialog::PasswordDialog
56 Window* _pParent,
57 ::com::sun::star::task::PasswordRequestMode nDlgMode,
58 ResMgr * pResMgr,
59 rtl::OUString& aDocURL
61 :ModalDialog( _pParent, ResId( DLG_UUI_PASSWORD, *pResMgr ) )
62 ,aFTPassword ( this, ResId( FT_PASSWORD, *pResMgr ) )
63 ,aEDPassword ( this, ResId( ED_PASSWORD, *pResMgr ) )
64 ,aOKBtn ( this, ResId( BTN_PASSWORD_OK, *pResMgr ) )
65 ,aCancelBtn ( this, ResId( BTN_PASSWORD_CANCEL, *pResMgr ) )
66 ,aHelpBtn ( this, ResId( BTN_PASSWORD_HELP, *pResMgr ) )
67 ,aFixedLine1 ( this, ResId( FL_FIXED_LINE_1, *pResMgr ) )
68 ,nDialogMode ( nDlgMode )
69 ,pResourceMgr ( pResMgr )
71 if( nDialogMode == ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER )
73 String aErrorMsg( ResId( STR_ERROR_PASSWORD_WRONG, *pResourceMgr ));
74 ErrorBox aErrorBox( _pParent, WB_OK, aErrorMsg );
75 aErrorBox.Execute();
78 FreeResource();
80 aFTPassword.SetText( aFTPassword.GetText() + aDocURL );
82 aOKBtn.SetClickHdl( LINK( this, PasswordDialog, OKHdl_Impl ) );
84 long nLabelWidth = aFTPassword.GetSizePixel().Width();
85 long nLabelHeight = aFTPassword.GetSizePixel().Height();
86 long nTextWidth = aFTPassword.GetCtrlTextWidth( aFTPassword.GetText() );
87 long nTextHeight = aFTPassword.GetTextHeight();
89 Rectangle aLabelRect( aFTPassword.GetPosPixel(), aFTPassword.GetSizePixel() );
90 Rectangle aRect = aFTPassword.GetTextRect( aLabelRect, aFTPassword.GetText() );
92 long nNewLabelHeight = 0;
93 for( nNewLabelHeight = ( nTextWidth / nLabelWidth + 1 ) * nTextHeight;
94 nNewLabelHeight < aRect.GetHeight();
95 nNewLabelHeight += nTextHeight ) {} ;
97 long nDelta = nNewLabelHeight - nLabelHeight;
99 Size aNewDlgSize = GetSizePixel();
100 aNewDlgSize.Height() += nDelta;
101 SetSizePixel( aNewDlgSize );
103 Size aNewLabelSize = aFTPassword.GetSizePixel();
104 aNewLabelSize.Height() = nNewLabelHeight;
105 aFTPassword.SetPosSizePixel( aFTPassword.GetPosPixel(), aNewLabelSize );
107 Window* pControls[] = { &aEDPassword, &aFixedLine1, &aOKBtn, &aCancelBtn, &aHelpBtn };
108 const sal_Int32 nCCount = sizeof( pControls ) / sizeof( pControls[0] );
109 for ( int i = 0; i < nCCount; ++i )
111 Point aNewPos =(*pControls[i]).GetPosPixel();
112 aNewPos.Y() += nDelta;
113 pControls[i]->SetPosSizePixel( aNewPos, pControls[i]->GetSizePixel() );