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: passwd.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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 // Include ---------------------------------------------------------------
35 #include <vcl/msgbox.hxx>
39 #include <sfx2/passwd.hxx>
40 #include "sfxtypes.hxx"
41 #include "sfxresid.hxx"
46 // -----------------------------------------------------------------------
48 IMPL_LINK_INLINE_START( SfxPasswordDialog
, EditModifyHdl
, Edit
*, EMPTYARG
)
50 maOKBtn
.Enable( maPasswordED
.GetText().Len() >= mnMinLen
);
53 IMPL_LINK_INLINE_END( SfxPasswordDialog
, EditModifyHdl
, Edit
*, EMPTYARG
)
55 // -----------------------------------------------------------------------
57 IMPL_LINK( SfxPasswordDialog
, OKHdl
, OKButton
*, EMPTYARG
)
59 if ( ( ( mnExtras
& SHOWEXTRAS_CONFIRM
) == SHOWEXTRAS_CONFIRM
) &&
60 ( GetConfirm() != GetPassword() ) )
62 ErrorBox
aBox( this, SfxResId( MSG_ERROR_WRONG_CONFIRM
) );
64 maConfirmED
.SetText( String() );
65 maConfirmED
.GrabFocus();
72 // CTOR / DTOR -----------------------------------------------------------
74 SfxPasswordDialog::SfxPasswordDialog( Window
* pParent
, const String
* pGroupText
) :
76 ModalDialog( pParent
, SfxResId ( DLG_PASSWD
) ),
78 maUserFT ( this, SfxResId( FT_PASSWD_USER
) ),
79 maUserED ( this, SfxResId( ED_PASSWD_USER
) ),
80 maPasswordFT ( this, SfxResId( FT_PASSWD_PASSWORD
) ),
81 maPasswordED ( this, SfxResId( ED_PASSWD_PASSWORD
) ),
82 maConfirmFT ( this, SfxResId( FT_PASSWD_CONFIRM
) ),
83 maConfirmED ( this, SfxResId( ED_PASSWD_CONFIRM
) ),
84 maMinLengthFT ( this, SfxResId( FT_PASSWD_MINLEN
) ),
85 maPasswordBox ( this, SfxResId( GB_PASSWD_PASSWORD
) ),
86 maOKBtn ( this, SfxResId( BTN_PASSWD_OK
) ),
87 maCancelBtn ( this, SfxResId( BTN_PASSWD_CANCEL
) ),
88 maHelpBtn ( this, SfxResId( BTN_PASSWD_HELP
) ),
89 maConfirmStr ( SfxResId( STR_PASSWD_CONFIRM
) ),
92 maMinLenPwdStr ( SfxResId( STR_PASSWD_MIN_LEN
) ),
93 maEmptyPwdStr ( SfxResId( STR_PASSWD_EMPTY
) ),
100 Link aLink
= LINK( this, SfxPasswordDialog
, EditModifyHdl
);
101 maPasswordED
.SetModifyHdl( aLink
);
102 aLink
= LINK( this, SfxPasswordDialog
, OKHdl
);
103 maOKBtn
.SetClickHdl( aLink
);
106 maPasswordBox
.SetText( *pGroupText
);
108 //set the text to the pasword length
112 // -----------------------------------------------------------------------
114 void SfxPasswordDialog::SetPasswdText( )
116 //set the new string to the minimum password length
118 maMinLengthFT
.SetText( maEmptyPwdStr
);
121 maMainPwdStr
= maMinLenPwdStr
;
122 maMainPwdStr
.SearchAndReplace( String::CreateFromAscii( "$(MINLEN)" ), String::CreateFromInt32((sal_Int32
) mnMinLen
), 0);
123 maMinLengthFT
.SetText( maMainPwdStr
);
124 maMinLengthFT
.Show();
128 // -----------------------------------------------------------------------
130 void SfxPasswordDialog::SetMinLen( USHORT nLen
)
134 EditModifyHdl( NULL
);
137 // -----------------------------------------------------------------------
139 void SfxPasswordDialog::SetMaxLen( USHORT nLen
)
141 maPasswordED
.SetMaxTextLen( nLen
);
142 maConfirmED
.SetMaxTextLen( nLen
);
143 EditModifyHdl( NULL
);
146 // -----------------------------------------------------------------------
148 short SfxPasswordDialog::Execute()
150 if ( mnExtras
< SHOWEXTRAS_ALL
)
152 Size a3Size
= LogicToPixel( Size( 3, 3 ), MAP_APPFONT
);
153 Size a6Size
= LogicToPixel( Size( 6, 6 ), MAP_APPFONT
);
154 long nMinHeight
= maHelpBtn
.GetPosPixel().Y() +
155 maHelpBtn
.GetSizePixel().Height() + a6Size
.Height();
156 USHORT nRowHided
= 1;
158 if ( SHOWEXTRAS_NONE
== mnExtras
)
166 Point aPos
= maUserFT
.GetPosPixel();
167 long nEnd
= maUserED
.GetPosPixel().X() + maUserED
.GetSizePixel().Width();
168 maPasswordED
.SetPosPixel( aPos
);
169 Size aSize
= maPasswordED
.GetSizePixel();
170 aSize
.Width() = nEnd
- aPos
.X();
171 maPasswordED
.SetSizePixel( aSize
);
175 else if ( SHOWEXTRAS_USER
== mnExtras
)
180 else if ( SHOWEXTRAS_CONFIRM
== mnExtras
)
185 Point aPwdPos1
= maPasswordFT
.GetPosPixel();
186 Point aPwdPos2
= maPasswordED
.GetPosPixel();
188 Point aPos
= maUserFT
.GetPosPixel();
189 maPasswordFT
.SetPosPixel( aPos
);
190 aPos
= maUserED
.GetPosPixel();
191 maPasswordED
.SetPosPixel( aPos
);
193 aPos
= maConfirmFT
.GetPosPixel();
194 maConfirmFT
.SetPosPixel( aPwdPos1
);
195 maConfirmED
.SetPosPixel( aPwdPos2
);
196 maMinLengthFT
.SetPosPixel(aPos
);
199 Size aBoxSize
= maPasswordBox
.GetSizePixel();
200 aBoxSize
.Height() -= ( nRowHided
* maUserED
.GetSizePixel().Height() );
201 aBoxSize
.Height() -= ( nRowHided
* a3Size
.Height() );
202 maPasswordBox
.SetSizePixel( aBoxSize
);
204 long nDlgHeight
= maPasswordBox
.GetPosPixel().Y() + aBoxSize
.Height() + a6Size
.Height();
205 if ( nDlgHeight
< nMinHeight
)
206 nDlgHeight
= nMinHeight
;
207 Size aDlgSize
= GetOutputSizePixel();
208 aDlgSize
.Height() = nDlgHeight
;
209 SetOutputSizePixel( aDlgSize
);
212 return ModalDialog::Execute();