merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / dialog / passwd.cxx
blob05a593246c63cad89bad33d1c8d7762dd03559c4
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: passwd.cxx,v $
10 * $Revision: 1.9 $
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>
36 #ifndef GCC
37 #endif
39 #include <sfx2/passwd.hxx>
40 #include "sfxtypes.hxx"
41 #include "sfxresid.hxx"
43 #include "dialog.hrc"
44 #include "passwd.hrc"
46 // -----------------------------------------------------------------------
48 IMPL_LINK_INLINE_START( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG )
50 maOKBtn.Enable( maPasswordED.GetText().Len() >= mnMinLen );
51 return 0;
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 ) );
63 aBox.Execute();
64 maConfirmED.SetText( String() );
65 maConfirmED.GrabFocus();
67 else
68 EndDialog( RET_OK );
69 return 0;
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 ) ),
91 mnMinLen ( 1 ),
92 maMinLenPwdStr ( SfxResId( STR_PASSWD_MIN_LEN ) ),
93 maEmptyPwdStr ( SfxResId( STR_PASSWD_EMPTY ) ),
94 maMainPwdStr ( ),
95 mnExtras ( 0 )
98 FreeResource();
100 Link aLink = LINK( this, SfxPasswordDialog, EditModifyHdl );
101 maPasswordED.SetModifyHdl( aLink );
102 aLink = LINK( this, SfxPasswordDialog, OKHdl );
103 maOKBtn.SetClickHdl( aLink );
105 if ( pGroupText )
106 maPasswordBox.SetText( *pGroupText );
108 //set the text to the pasword length
109 SetPasswdText();
112 // -----------------------------------------------------------------------
114 void SfxPasswordDialog::SetPasswdText( )
116 //set the new string to the minimum password length
117 if( mnMinLen == 0 )
118 maMinLengthFT.SetText( maEmptyPwdStr );
119 else
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 )
132 mnMinLen = nLen;
133 SetPasswdText();
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 )
160 maUserFT.Hide();
161 maUserED.Hide();
162 maConfirmFT.Hide();
163 maConfirmED.Hide();
164 maPasswordFT.Hide();
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 );
173 nRowHided = 2;
175 else if ( SHOWEXTRAS_USER == mnExtras )
177 maConfirmFT.Hide();
178 maConfirmED.Hide();
180 else if ( SHOWEXTRAS_CONFIRM == mnExtras )
182 maUserFT.Hide();
183 maUserED.Hide();
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();