1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 // Include ---------------------------------------------------------------
22 #include <vcl/msgbox.hxx>
24 #include <sfx2/passwd.hxx>
25 #include "sfxtypes.hxx"
26 #include "sfx2/sfxresid.hxx"
30 // -----------------------------------------------------------------------
32 IMPL_LINK_INLINE_START( SfxPasswordDialog
, EditModifyHdl
, Edit
*, pEdit
)
34 if (mbAsciiOnly
&& (pEdit
== mpPassword1ED
|| pEdit
== mpPassword2ED
))
36 OUString
aTest( pEdit
->GetText() );
37 const sal_Unicode
* pTest
= aTest
.getStr();
38 sal_Int32 nLen
= aTest
.getLength();
39 OUStringBuffer
aFilter( nLen
);
41 for( sal_Int32 i
= 0; i
< nLen
; i
++ )
46 aFilter
.append( *pTest
);
51 pEdit
->SetSelection( Selection( 0, nLen
) );
52 pEdit
->ReplaceSelected( aFilter
.makeStringAndClear() );
56 bool bEnable
= mpPassword1ED
->GetText().getLength() >= mnMinLen
;
57 if( mpPassword2ED
->IsVisible() )
58 bEnable
= (bEnable
&& (mpPassword2ED
->GetText().getLength() >= mnMinLen
));
59 mpOKBtn
->Enable( bEnable
);
62 IMPL_LINK_INLINE_END(SfxPasswordDialog
, EditModifyHdl
, Edit
*, pEdit
)
64 // -----------------------------------------------------------------------
66 IMPL_LINK_NOARG(SfxPasswordDialog
, OKHdl
)
68 bool bConfirmFailed
= ( ( mnExtras
& SHOWEXTRAS_CONFIRM
) == SHOWEXTRAS_CONFIRM
) &&
69 ( GetConfirm() != GetPassword() );
70 if( ( mnExtras
& SHOWEXTRAS_CONFIRM2
) == SHOWEXTRAS_CONFIRM2
&& ( GetConfirm2() != GetPassword2() ) )
71 bConfirmFailed
= true;
74 ErrorBox
aBox( this, SfxResId( MSG_ERROR_WRONG_CONFIRM
) );
76 mpConfirm1ED
->SetText( OUString() );
77 mpConfirm1ED
->GrabFocus();
84 // CTOR / DTOR -----------------------------------------------------------
86 SfxPasswordDialog::SfxPasswordDialog(Window
* pParent
, const String
* pGroupText
)
87 : ModalDialog(pParent
, "PasswordDialog", "sfx/ui/password.ui")
88 , maMinLenPwdStr(SFX2_RESSTR(STR_PASSWD_MIN_LEN
))
89 , maEmptyPwdStr(SFX2_RESSTR(STR_PASSWD_EMPTY
))
94 get(mpPassword1Box
, "password1frame");
95 get(mpUserFT
, "userft");
96 get(mpUserED
, "usered");
97 get(mpPassword1FT
, "pass1ft");
98 get(mpPassword1ED
, "pass1ed");
99 get(mpConfirm1FT
, "confirm1ft");
100 get(mpConfirm1ED
, "confirm1ed");
102 get(mpPassword2Box
, "password2frame");
103 get(mpPassword2FT
, "pass2ft");
104 get(mpPassword2ED
, "pass2ed");
105 get(mpConfirm2FT
, "confirm2ft");
106 get(mpConfirm2ED
, "confirm2ed");
108 get(mpMinLengthFT
, "minlenft");
112 mpPassword1ED
->SetAccessibleName(SFX2_RESSTR(STR_PASSWD
));
114 Link aLink
= LINK( this, SfxPasswordDialog
, EditModifyHdl
);
115 mpPassword1ED
->SetModifyHdl( aLink
);
116 mpPassword2ED
->SetModifyHdl( aLink
);
117 aLink
= LINK( this, SfxPasswordDialog
, OKHdl
);
118 mpOKBtn
->SetClickHdl( aLink
);
121 mpPassword1Box
->set_label(*pGroupText
);
123 //set the text to the pasword length
127 // -----------------------------------------------------------------------
129 void SfxPasswordDialog::SetPasswdText( )
131 //set the new string to the minimum password length
133 mpMinLengthFT
->SetText(maEmptyPwdStr
);
136 maMainPwdStr
= maMinLenPwdStr
;
137 maMainPwdStr
.SearchAndReplace( OUString("$(MINLEN)"), OUString::number((sal_Int32
) mnMinLen
), 0);
138 mpMinLengthFT
->SetText(maMainPwdStr
);
142 // -----------------------------------------------------------------------
144 void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen
)
148 EditModifyHdl( NULL
);
151 void SfxPasswordDialog::ShowMinLengthText(bool bShow
)
153 mpMinLengthFT
->Show(bShow
);
156 // -----------------------------------------------------------------------
158 short SfxPasswordDialog::Execute()
162 mpConfirm1FT
->Hide();
163 mpConfirm1ED
->Hide();
164 mpPassword1FT
->Hide();
165 mpPassword2Box
->Hide();
166 mpPassword2FT
->Hide();
167 mpPassword2ED
->Hide();
168 mpPassword2FT
->Hide();
169 mpConfirm2FT
->Hide();
170 mpConfirm2ED
->Hide();
172 if (mnExtras
!= SHOWEXTRAS_NONE
)
173 mpPassword1FT
->Show();
174 if (mnExtras
& SHOWEXTRAS_USER
)
179 if (mnExtras
& SHOWEXTRAS_CONFIRM
)
181 mpConfirm1FT
->Show();
182 mpConfirm1ED
->Show();
184 if (mnExtras
& SHOWEXTRAS_PASSWORD2
)
186 mpPassword2Box
->Show();
187 mpPassword2FT
->Show();
188 mpPassword2ED
->Show();
190 if (mnExtras
& SHOWEXTRAS_CONFIRM2
)
192 mpConfirm2FT
->Show();
193 mpConfirm2ED
->Show();
196 return ModalDialog::Execute();
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */