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/layout.hxx>
24 #include <sfx2/passwd.hxx>
25 #include "sfxtypes.hxx"
26 #include <sfx2/sfxresid.hxx>
32 IMPL_LINK( 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
);
63 IMPL_LINK_NOARG(SfxPasswordDialog
, OKHdl
)
65 bool bConfirmFailed
= bool( mnExtras
& SfxShowExtras::CONFIRM
) &&
66 ( GetConfirm() != GetPassword() );
67 if( ( mnExtras
& SfxShowExtras::CONFIRM2
) && ( GetConfirm2() != GetPassword2() ) )
68 bConfirmFailed
= true;
71 ScopedVclPtrInstance
< MessageDialog
> aBox(this, SfxResId(STR_ERROR_WRONG_CONFIRM
));
73 mpConfirm1ED
->SetText( OUString() );
74 mpConfirm1ED
->GrabFocus();
81 // CTOR / DTOR -----------------------------------------------------------
83 SfxPasswordDialog::SfxPasswordDialog(vcl::Window
* pParent
, const OUString
* pGroupText
)
84 : ModalDialog(pParent
, "PasswordDialog", "sfx/ui/password.ui")
85 , maMinLenPwdStr(SFX2_RESSTR(STR_PASSWD_MIN_LEN
))
86 , maMinLenPwdStr1(SFX2_RESSTR(STR_PASSWD_MIN_LEN1
))
87 , maEmptyPwdStr(SFX2_RESSTR(STR_PASSWD_EMPTY
))
89 , mnExtras(SfxShowExtras::NONE
)
92 get(mpPassword1Box
, "password1frame");
93 get(mpUserFT
, "userft");
94 get(mpUserED
, "usered");
95 get(mpPassword1FT
, "pass1ft");
96 get(mpPassword1ED
, "pass1ed");
97 get(mpConfirm1FT
, "confirm1ft");
98 get(mpConfirm1ED
, "confirm1ed");
100 get(mpPassword2Box
, "password2frame");
101 get(mpPassword2FT
, "pass2ft");
102 get(mpPassword2ED
, "pass2ed");
103 get(mpConfirm2FT
, "confirm2ft");
104 get(mpConfirm2ED
, "confirm2ed");
106 get(mpMinLengthFT
, "minlenft");
110 mpPassword1ED
->SetAccessibleName(SFX2_RESSTR(STR_PASSWD
));
112 Link
<> aLink
= LINK( this, SfxPasswordDialog
, EditModifyHdl
);
113 mpPassword1ED
->SetModifyHdl( aLink
);
114 mpPassword2ED
->SetModifyHdl( aLink
);
115 aLink
= LINK( this, SfxPasswordDialog
, OKHdl
);
116 mpOKBtn
->SetClickHdl( aLink
);
119 mpPassword1Box
->set_label(*pGroupText
);
121 //set the text to the password length
125 SfxPasswordDialog::~SfxPasswordDialog()
130 void SfxPasswordDialog::dispose()
132 mpPassword1Box
.clear();
135 mpPassword1FT
.clear();
136 mpPassword1ED
.clear();
137 mpConfirm1FT
.clear();
138 mpConfirm1ED
.clear();
139 mpPassword2Box
.clear();
140 mpPassword2FT
.clear();
141 mpPassword2ED
.clear();
142 mpConfirm2FT
.clear();
143 mpConfirm2ED
.clear();
144 mpMinLengthFT
.clear();
146 ModalDialog::dispose();
149 void SfxPasswordDialog::SetPasswdText( )
151 //set the new string to the minimum password length
153 mpMinLengthFT
->SetText(maEmptyPwdStr
);
157 mpMinLengthFT
->SetText(maMinLenPwdStr1
);
160 maMainPwdStr
= maMinLenPwdStr
;
161 maMainPwdStr
= maMainPwdStr
.replaceAll( "$(MINLEN)", OUString::number((sal_Int32
) mnMinLen
) );
162 mpMinLengthFT
->SetText(maMainPwdStr
);
169 void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen
)
173 EditModifyHdl( NULL
);
176 void SfxPasswordDialog::ShowMinLengthText(bool bShow
)
178 mpMinLengthFT
->Show(bShow
);
183 short SfxPasswordDialog::Execute()
187 mpConfirm1FT
->Hide();
188 mpConfirm1ED
->Hide();
189 mpPassword1FT
->Hide();
190 mpPassword2Box
->Hide();
191 mpPassword2FT
->Hide();
192 mpPassword2ED
->Hide();
193 mpPassword2FT
->Hide();
194 mpConfirm2FT
->Hide();
195 mpConfirm2ED
->Hide();
197 if (mnExtras
!= SfxShowExtras::NONE
)
198 mpPassword1FT
->Show();
199 if (mnExtras
& SfxShowExtras::USER
)
204 if (mnExtras
& SfxShowExtras::CONFIRM
)
206 mpConfirm1FT
->Show();
207 mpConfirm1ED
->Show();
209 if (mnExtras
& SfxShowExtras::PASSWORD2
)
211 mpPassword2Box
->Show();
212 mpPassword2FT
->Show();
213 mpPassword2ED
->Show();
215 if (mnExtras
& SfxShowExtras::CONFIRM2
)
217 mpConfirm2FT
->Show();
218 mpConfirm2ED
->Show();
221 return ModalDialog::Execute();
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */