Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : // Include ---------------------------------------------------------------
31 : : #include <vcl/msgbox.hxx>
32 : :
33 : : #include <sfx2/passwd.hxx>
34 : : #include "sfxtypes.hxx"
35 : : #include "sfx2/sfxresid.hxx"
36 : :
37 : : #include "dialog.hrc"
38 : : #include "passwd.hrc"
39 : :
40 : : #include "vcl/arrange.hxx"
41 : :
42 : : // -----------------------------------------------------------------------
43 : :
44 : 0 : IMPL_LINK_INLINE_START( SfxPasswordDialog, EditModifyHdl, Edit *, pEdit )
45 : : {
46 [ # # ][ # # ]: 0 : if( mbAsciiOnly && (pEdit == &maPasswordED || pEdit == &maPassword2ED) )
[ # # ]
47 : : {
48 [ # # ][ # # ]: 0 : rtl::OUString aTest( pEdit->GetText() );
[ # # ]
49 : 0 : const sal_Unicode* pTest = aTest.getStr();
50 : 0 : sal_Int32 nLen = aTest.getLength();
51 : 0 : rtl::OUStringBuffer aFilter( nLen );
52 : 0 : bool bReset = false;
53 [ # # ]: 0 : for( sal_Int32 i = 0; i < nLen; i++ )
54 : : {
55 [ # # ]: 0 : if( *pTest > 0x007f )
56 : 0 : bReset = true;
57 : : else
58 [ # # ]: 0 : aFilter.append( *pTest );
59 : 0 : pTest++;
60 : : }
61 [ # # ]: 0 : if( bReset )
62 : : {
63 [ # # ]: 0 : pEdit->SetSelection( Selection( 0, nLen ) );
64 [ # # ][ # # ]: 0 : pEdit->ReplaceSelected( aFilter.makeStringAndClear() );
[ # # ][ # # ]
65 : 0 : }
66 : :
67 : : }
68 : 0 : bool bEnable = maPasswordED.GetText().Len() >= mnMinLen;
69 [ # # ]: 0 : if( maPassword2ED.IsVisible() )
70 [ # # ][ # # ]: 0 : bEnable = (bEnable && (maPassword2ED.GetText().Len() >= mnMinLen));
[ # # ][ # # ]
[ # # ]
71 : 0 : maOKBtn.Enable( bEnable );
72 : 0 : return 0;
73 : : }
74 : 0 : IMPL_LINK_INLINE_END(SfxPasswordDialog, EditModifyHdl, Edit *, pEdit)
75 : :
76 : : // -----------------------------------------------------------------------
77 : :
78 : 0 : IMPL_LINK_NOARG(SfxPasswordDialog, OKHdl)
79 : : {
80 : : bool bConfirmFailed = ( ( mnExtras & SHOWEXTRAS_CONFIRM ) == SHOWEXTRAS_CONFIRM ) &&
81 [ # # ][ # # ]: 0 : ( GetConfirm() != GetPassword() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
82 [ # # ][ # # ]: 0 : if( ( mnExtras & SHOWEXTRAS_CONFIRM2 ) == SHOWEXTRAS_CONFIRM2 && ( GetConfirm2() != GetPassword2() ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # ]
83 : 0 : bConfirmFailed = true;
84 [ # # ]: 0 : if ( bConfirmFailed )
85 : : {
86 [ # # ][ # # ]: 0 : ErrorBox aBox( this, SfxResId( MSG_ERROR_WRONG_CONFIRM ) );
87 [ # # ]: 0 : aBox.Execute();
88 [ # # ][ # # ]: 0 : maConfirmED.SetText( String() );
[ # # ]
89 [ # # ][ # # ]: 0 : maConfirmED.GrabFocus();
90 : : }
91 : : else
92 : 0 : EndDialog( RET_OK );
93 : 0 : return 0;
94 : : }
95 : :
96 : : // CTOR / DTOR -----------------------------------------------------------
97 : :
98 : 0 : SfxPasswordDialog::SfxPasswordDialog( Window* pParent, const String* pGroupText ) :
99 : :
100 : : ModalDialog( pParent, SfxResId ( DLG_PASSWD ) ),
101 : :
102 : : maPasswordBox ( this, SfxResId( GB_PASSWD_PASSWORD ) ),
103 : : maUserFT ( this, SfxResId( FT_PASSWD_USER ) ),
104 : : maUserED ( this, SfxResId( ED_PASSWD_USER ) ),
105 : : maPasswordFT ( this, SfxResId( FT_PASSWD_PASSWORD ) ),
106 : : maPasswordED ( this, SfxResId( ED_PASSWD_PASSWORD ) ),
107 : : maConfirmFT ( this, SfxResId( FT_PASSWD_CONFIRM ) ),
108 : : maConfirmED ( this, SfxResId( ED_PASSWD_CONFIRM ) ),
109 : :
110 : : maMinLengthFT ( this, SfxResId( FT_PASSWD_MINLEN ) ),
111 : : maPassword2Box ( this, 0 ),
112 : : maPassword2FT ( this, SfxResId( FT_PASSWD_PASSWORD2 ) ),
113 : : maPassword2ED ( this, SfxResId( ED_PASSWD_PASSWORD2 ) ),
114 : : maConfirm2FT ( this, SfxResId( FT_PASSWD_CONFIRM2 ) ),
115 : : maConfirm2ED ( this, SfxResId( ED_PASSWD_CONFIRM2 ) ),
116 : : maOKBtn ( this, SfxResId( BTN_PASSWD_OK ) ),
117 : : maCancelBtn ( this, SfxResId( BTN_PASSWD_CANCEL ) ),
118 : : maHelpBtn ( this, SfxResId( BTN_PASSWD_HELP ) ),
119 : :
120 : : maMinLenPwdStr ( SfxResId( STR_PASSWD_MIN_LEN ).toString() ),
121 : : maEmptyPwdStr ( SfxResId( STR_PASSWD_EMPTY ).toString() ),
122 : : maMainPwdStr ( ),
123 : : mnMinLen ( 5 ),
124 : : mnExtras ( 0 ),
125 [ # # ][ # # ]: 0 : mbAsciiOnly ( false )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
126 : :
127 : : {
128 [ # # ][ # # ]: 0 : maPasswordED.SetAccessibleName(SfxResId(TEXT_PASSWD).toString());
[ # # ][ # # ]
[ # # ]
129 [ # # ]: 0 : FreeResource();
130 : :
131 : : // setup layout
132 : : boost::shared_ptr<vcl::RowOrColumn> xLayout =
133 [ # # ][ # # ]: 0 : boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
[ # # ]
134 [ # # ]: 0 : xLayout->setOuterBorder( 0 );
135 : :
136 : : // get edit size, should be used as minimum
137 [ # # ]: 0 : Size aEditSize( maUserED.GetSizePixel() );
138 : :
139 : : // add labelcolumn for the labeled edit fields
140 [ # # ][ # # ]: 0 : boost::shared_ptr<vcl::LabelColumn> xEdits( new vcl::LabelColumn( xLayout.get() ) );
[ # # ]
141 [ # # ][ # # ]: 0 : size_t nChildIndex = xLayout->addChild( xEdits );
[ # # ]
142 [ # # ]: 0 : xLayout->setBorders( nChildIndex, -2, -2, -2, 0 );
143 : :
144 : : // add group box
145 [ # # ]: 0 : xEdits->addWindow( &maPasswordBox );
146 : :
147 : : // add user line
148 [ # # ]: 0 : xEdits->addRow( &maUserFT, &maUserED, -2, aEditSize );
149 : :
150 : : // add password line
151 [ # # ]: 0 : xEdits->addRow( &maPasswordFT, &maPasswordED, -2, aEditSize );
152 : :
153 : : // add confirm line
154 [ # # ]: 0 : xEdits->addRow( &maConfirmFT, &maConfirmED, -2, aEditSize );
155 : :
156 : : // add second group box
157 [ # # ]: 0 : xEdits->addWindow( &maPassword2Box );
158 : :
159 : : // add second password line
160 [ # # ]: 0 : xEdits->addRow( &maPassword2FT, &maPassword2ED, -2, aEditSize );
161 : :
162 : : // add second confirm line
163 [ # # ]: 0 : xEdits->addRow( &maConfirm2FT, &maConfirm2ED, -2, aEditSize );
164 : :
165 : : // add password length warning line
166 [ # # ]: 0 : xEdits->addWindow( &maMinLengthFT );
167 : :
168 : : // add a FixedLine
169 [ # # ][ # # ]: 0 : FixedLine* pLine = new FixedLine( this, 0 );
170 [ # # ]: 0 : pLine->Show();
171 [ # # ]: 0 : addWindow( pLine, true );
172 [ # # ]: 0 : xLayout->addWindow( pLine );
173 : :
174 : : // add button column
175 [ # # ]: 0 : Size aBtnSize( maCancelBtn.GetSizePixel() );
176 [ # # ][ # # ]: 0 : boost::shared_ptr<vcl::RowOrColumn> xButtons( new vcl::RowOrColumn( xLayout.get(), false ) );
[ # # ]
177 [ # # ][ # # ]: 0 : nChildIndex = xLayout->addChild( xButtons );
[ # # ]
178 [ # # ]: 0 : xLayout->setBorders( nChildIndex, -2, 0, -2, -2 );
179 : :
180 [ # # ]: 0 : xButtons->addWindow( &maHelpBtn, 0, aBtnSize );
181 [ # # ][ # # ]: 0 : xButtons->addChild( new vcl::Spacer( xButtons.get() ) );
[ # # ]
182 [ # # ]: 0 : xButtons->addWindow( &maOKBtn, 0, aBtnSize );
183 [ # # ]: 0 : xButtons->addWindow( &maCancelBtn, 0, aBtnSize );
184 : :
185 [ # # ]: 0 : Link aLink = LINK( this, SfxPasswordDialog, EditModifyHdl );
186 : 0 : maPasswordED.SetModifyHdl( aLink );
187 : 0 : maPassword2ED.SetModifyHdl( aLink );
188 [ # # ]: 0 : aLink = LINK( this, SfxPasswordDialog, OKHdl );
189 : 0 : maOKBtn.SetClickHdl( aLink );
190 : :
191 [ # # ]: 0 : if ( pGroupText )
192 [ # # ]: 0 : maPasswordBox.SetText( *pGroupText );
193 : :
194 : : //set the text to the pasword length
195 [ # # ][ # # ]: 0 : SetPasswdText();
[ # # ][ # # ]
196 : 0 : }
197 : :
198 : : // -----------------------------------------------------------------------
199 : :
200 : 0 : void SfxPasswordDialog::SetPasswdText( )
201 : : {
202 : : //set the new string to the minimum password length
203 [ # # ]: 0 : if( mnMinLen == 0 )
204 : 0 : maMinLengthFT.SetText( maEmptyPwdStr );
205 : : else
206 : : {
207 : 0 : maMainPwdStr = maMinLenPwdStr;
208 [ # # ][ # # ]: 0 : maMainPwdStr.SearchAndReplace( rtl::OUString("$(MINLEN)"), String::CreateFromInt32((sal_Int32) mnMinLen ), 0);
[ # # ]
209 : 0 : maMinLengthFT.SetText( maMainPwdStr );
210 : 0 : maMinLengthFT.Show();
211 : : }
212 : 0 : }
213 : :
214 : : // -----------------------------------------------------------------------
215 : :
216 : 0 : void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen )
217 : : {
218 : 0 : mnMinLen = nLen;
219 : 0 : SetPasswdText();
220 : 0 : EditModifyHdl( NULL );
221 : 0 : }
222 : :
223 : : // -----------------------------------------------------------------------
224 : :
225 : 0 : short SfxPasswordDialog::Execute()
226 : : {
227 [ # # ]: 0 : maUserFT.Hide();
228 [ # # ]: 0 : maUserED.Hide();
229 [ # # ]: 0 : maConfirmFT.Hide();
230 [ # # ]: 0 : maConfirmED.Hide();
231 [ # # ]: 0 : maPasswordFT.Hide();
232 [ # # ]: 0 : maPassword2Box.Hide();
233 [ # # ]: 0 : maPassword2FT.Hide();
234 [ # # ]: 0 : maPassword2ED.Hide();
235 [ # # ]: 0 : maPassword2FT.Hide();
236 [ # # ]: 0 : maConfirm2FT.Hide();
237 [ # # ]: 0 : maConfirm2ED.Hide();
238 : :
239 [ # # ]: 0 : if( mnExtras != SHOWEXTRAS_NONE )
240 [ # # ]: 0 : maPasswordFT.Show();
241 [ # # ]: 0 : if( (mnExtras & SHOWEXTRAS_USER ) )
242 : : {
243 : : //TODO: Inevitably this layout logic will be wrong post merge until we can see the dialog to test it.
244 [ # # ][ # # ]: 0 : Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
[ # # ]
245 [ # # ][ # # ]: 0 : Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT );
[ # # ]
246 [ # # ]: 0 : long nMinHeight = maHelpBtn.GetPosPixel().Y() +
247 [ # # ]: 0 : maHelpBtn.GetSizePixel().Height() + a6Size.Height();
248 : 0 : sal_uInt16 nRowHided = 1;
249 : :
250 [ # # ]: 0 : if ( SHOWEXTRAS_NONE == mnExtras )
251 : : {
252 [ # # ]: 0 : maUserFT.Hide();
253 [ # # ]: 0 : maUserED.Hide();
254 [ # # ]: 0 : maConfirmFT.Hide();
255 [ # # ]: 0 : maConfirmED.Hide();
256 [ # # ]: 0 : maPasswordFT.Hide();
257 : :
258 [ # # ]: 0 : Point aPos = maUserFT.GetPosPixel();
259 [ # # ][ # # ]: 0 : long nEnd = maUserED.GetPosPixel().X() + maUserED.GetSizePixel().Width();
260 [ # # ]: 0 : maPasswordED.SetPosPixel( aPos );
261 [ # # ]: 0 : Size aSize = maPasswordED.GetSizePixel();
262 : 0 : aSize.Width() = nEnd - aPos.X();
263 [ # # ]: 0 : maPasswordED.SetSizePixel( aSize );
264 : :
265 : 0 : nRowHided = 2;
266 : : }
267 [ # # ]: 0 : else if ( SHOWEXTRAS_USER == mnExtras )
268 : : {
269 [ # # ]: 0 : maConfirmFT.Hide();
270 [ # # ]: 0 : maConfirmED.Hide();
271 : : }
272 [ # # ]: 0 : else if ( SHOWEXTRAS_CONFIRM == mnExtras )
273 : : {
274 [ # # ]: 0 : maUserFT.Hide();
275 [ # # ]: 0 : maUserED.Hide();
276 : :
277 [ # # ]: 0 : Point aPwdPos1 = maPasswordFT.GetPosPixel();
278 [ # # ]: 0 : Point aPwdPos2 = maPasswordED.GetPosPixel();
279 : :
280 [ # # ]: 0 : Point aPos = maUserFT.GetPosPixel();
281 [ # # ]: 0 : maPasswordFT.SetPosPixel( aPos );
282 [ # # ]: 0 : aPos = maUserED.GetPosPixel();
283 [ # # ]: 0 : maPasswordED.SetPosPixel( aPos );
284 : :
285 [ # # ]: 0 : aPos = maConfirmFT.GetPosPixel();
286 [ # # ]: 0 : maConfirmFT.SetPosPixel( aPwdPos1 );
287 [ # # ]: 0 : maConfirmED.SetPosPixel( aPwdPos2 );
288 [ # # ]: 0 : maMinLengthFT.SetPosPixel(aPos);
289 : : }
290 : :
291 [ # # ]: 0 : Size aBoxSize = maPasswordBox.GetSizePixel();
292 [ # # ]: 0 : aBoxSize.Height() -= ( nRowHided * maUserED.GetSizePixel().Height() );
293 : 0 : aBoxSize.Height() -= ( nRowHided * a3Size.Height() );
294 [ # # ]: 0 : maPasswordBox.SetSizePixel( aBoxSize );
295 : :
296 [ # # ]: 0 : long nDlgHeight = maPasswordBox.GetPosPixel().Y() + aBoxSize.Height() + a6Size.Height();
297 [ # # ]: 0 : if ( nDlgHeight < nMinHeight )
298 : 0 : nDlgHeight = nMinHeight;
299 : 0 : Size aDlgSize = GetOutputSizePixel();
300 : 0 : aDlgSize.Height() = nDlgHeight;
301 [ # # ]: 0 : SetOutputSizePixel( aDlgSize );
302 : :
303 [ # # ]: 0 : maUserFT.Show();
304 [ # # ]: 0 : maUserED.Show();
305 : : }
306 [ # # ]: 0 : if( (mnExtras & SHOWEXTRAS_CONFIRM ) )
307 : : {
308 [ # # ]: 0 : maConfirmFT.Show();
309 [ # # ]: 0 : maConfirmED.Show();
310 : : }
311 [ # # ]: 0 : if( (mnExtras & SHOWEXTRAS_PASSWORD2) )
312 : : {
313 [ # # ]: 0 : maPassword2Box.Show();
314 [ # # ]: 0 : maPassword2FT.Show();
315 [ # # ]: 0 : maPassword2ED.Show();
316 : : }
317 [ # # ]: 0 : if( (mnExtras & SHOWEXTRAS_CONFIRM2 ) )
318 : : {
319 [ # # ]: 0 : maConfirm2FT.Show();
320 [ # # ]: 0 : maConfirm2ED.Show();
321 : : }
322 : :
323 : : boost::shared_ptr<vcl::RowOrColumn> xLayout =
324 [ # # ][ # # ]: 0 : boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
[ # # ]
325 [ # # ][ # # ]: 0 : SetSizePixel( xLayout->getOptimalSize( WINDOWSIZE_PREFERRED ) );
326 : :
327 [ # # ][ # # ]: 0 : return ModalDialog::Execute();
328 : : }
329 : :
330 : :
331 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|