xref: /AOO41X/main/sfx2/source/dialog/passwd.cxx (revision d119d52d53d0b2180f2ae51341d882123be2af2b)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // Include ---------------------------------------------------------------
28cdf0e10cSrcweir #include <vcl/msgbox.hxx>
29cdf0e10cSrcweir #ifndef GCC
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <sfx2/passwd.hxx>
33cdf0e10cSrcweir #include "sfxtypes.hxx"
34cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "dialog.hrc"
37cdf0e10cSrcweir #include "passwd.hrc"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include "vcl/sound.hxx"
40cdf0e10cSrcweir #include "vcl/arrange.hxx"
41cdf0e10cSrcweir 
42cdf0e10cSrcweir // -----------------------------------------------------------------------
43cdf0e10cSrcweir 
IMPL_LINK_INLINE_START(SfxPasswordDialog,EditModifyHdl,Edit *,pEdit)44cdf0e10cSrcweir IMPL_LINK_INLINE_START( SfxPasswordDialog, EditModifyHdl, Edit *, pEdit )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     if( mbAsciiOnly && (pEdit == &maPasswordED || pEdit == &maPassword2ED) )
47cdf0e10cSrcweir     {
48cdf0e10cSrcweir         rtl::OUString aTest( pEdit->GetText() );
49cdf0e10cSrcweir         const sal_Unicode* pTest = aTest.getStr();
50cdf0e10cSrcweir         sal_Int32 nLen = aTest.getLength();
51cdf0e10cSrcweir         rtl::OUStringBuffer aFilter( nLen );
52cdf0e10cSrcweir         bool bReset = false;
53cdf0e10cSrcweir         for( sal_Int32 i = 0; i < nLen; i++ )
54cdf0e10cSrcweir         {
55cdf0e10cSrcweir             if( *pTest > 0x007f )
56cdf0e10cSrcweir                 bReset = true;
57cdf0e10cSrcweir             else
58cdf0e10cSrcweir                 aFilter.append( *pTest );
59cdf0e10cSrcweir             pTest++;
60cdf0e10cSrcweir         }
61cdf0e10cSrcweir         if( bReset )
62cdf0e10cSrcweir         {
63cdf0e10cSrcweir             Sound::Beep( SOUND_ERROR );
64cdf0e10cSrcweir             pEdit->SetSelection( Selection( 0, nLen ) );
65cdf0e10cSrcweir             pEdit->ReplaceSelected( aFilter.makeStringAndClear() );
66cdf0e10cSrcweir         }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     }
69cdf0e10cSrcweir     bool bEnable = maPasswordED.GetText().Len() >= mnMinLen;
70cdf0e10cSrcweir     if( maPassword2ED.IsVisible() )
71cdf0e10cSrcweir         bEnable = (bEnable && (maPassword2ED.GetText().Len() >= mnMinLen));
72cdf0e10cSrcweir 	maOKBtn.Enable( bEnable );
73cdf0e10cSrcweir 	return 0;
74cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(SfxPasswordDialog,EditModifyHdl,Edit *,EMPTYARG)75cdf0e10cSrcweir IMPL_LINK_INLINE_END( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG )
76cdf0e10cSrcweir 
77cdf0e10cSrcweir // -----------------------------------------------------------------------
78cdf0e10cSrcweir 
79cdf0e10cSrcweir IMPL_LINK( SfxPasswordDialog, OKHdl, OKButton *, EMPTYARG )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     bool bConfirmFailed = ( ( mnExtras & SHOWEXTRAS_CONFIRM ) == SHOWEXTRAS_CONFIRM ) &&
82cdf0e10cSrcweir 		                    ( GetConfirm() != GetPassword() );
83cdf0e10cSrcweir     if( ( mnExtras & SHOWEXTRAS_CONFIRM2 ) == SHOWEXTRAS_CONFIRM2 && ( GetConfirm2() != GetPassword2() ) )
84cdf0e10cSrcweir         bConfirmFailed = true;
85cdf0e10cSrcweir 	if ( bConfirmFailed )
86cdf0e10cSrcweir 	{
87cdf0e10cSrcweir 		ErrorBox aBox( this, SfxResId( MSG_ERROR_WRONG_CONFIRM ) );
88cdf0e10cSrcweir 		aBox.Execute();
89cdf0e10cSrcweir 		maConfirmED.SetText( String() );
90cdf0e10cSrcweir 		maConfirmED.GrabFocus();
91cdf0e10cSrcweir 	}
92cdf0e10cSrcweir 	else
93cdf0e10cSrcweir 		EndDialog( RET_OK );
94cdf0e10cSrcweir 	return 0;
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir // CTOR / DTOR -----------------------------------------------------------
98cdf0e10cSrcweir 
SfxPasswordDialog(Window * pParent,const String * pGroupText)99cdf0e10cSrcweir SfxPasswordDialog::SfxPasswordDialog( Window* pParent, const String* pGroupText ) :
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	ModalDialog( pParent, SfxResId ( DLG_PASSWD ) ),
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 	maPasswordBox	( this, SfxResId( GB_PASSWD_PASSWORD ) ),
104cdf0e10cSrcweir 	maUserFT		( this, SfxResId( FT_PASSWD_USER ) ),
105cdf0e10cSrcweir 	maUserED		( this, SfxResId( ED_PASSWD_USER ) ),
106cdf0e10cSrcweir 	maPasswordFT	( this, SfxResId( FT_PASSWD_PASSWORD ) ),
107cdf0e10cSrcweir 	maPasswordED	( this, SfxResId( ED_PASSWD_PASSWORD ) ),
108cdf0e10cSrcweir 	maConfirmFT		( this, SfxResId( FT_PASSWD_CONFIRM ) ),
109cdf0e10cSrcweir 	maConfirmED		( this, SfxResId( ED_PASSWD_CONFIRM ) ),
110cdf0e10cSrcweir 	maPassword2Box	( this, 0 ),
111cdf0e10cSrcweir 	maPassword2FT	( this, SfxResId( FT_PASSWD_PASSWORD2 ) ),
112cdf0e10cSrcweir 	maPassword2ED	( this, SfxResId( ED_PASSWD_PASSWORD2 ) ),
113cdf0e10cSrcweir 	maConfirm2FT	( this, SfxResId( FT_PASSWD_CONFIRM2 ) ),
114cdf0e10cSrcweir 	maConfirm2ED	( this, SfxResId( ED_PASSWD_CONFIRM2 ) ),
115cdf0e10cSrcweir 	maOKBtn			( this, SfxResId( BTN_PASSWD_OK ) ),
116cdf0e10cSrcweir 	maCancelBtn		( this, SfxResId( BTN_PASSWD_CANCEL ) ),
117cdf0e10cSrcweir 	maHelpBtn		( this, SfxResId( BTN_PASSWD_HELP ) ),
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	mnMinLen		( 1 ),
120cdf0e10cSrcweir 	mnExtras		( 0 ),
121cdf0e10cSrcweir     mbAsciiOnly     ( false )
122cdf0e10cSrcweir 
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	maPasswordED.SetAccessibleName(String(SfxResId(TEXT_PASSWD)));
125cdf0e10cSrcweir 	FreeResource();
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	// setup layout
128cdf0e10cSrcweir     boost::shared_ptr<vcl::RowOrColumn> xLayout =
129cdf0e10cSrcweir         boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
130cdf0e10cSrcweir     xLayout->setOuterBorder( 0 );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     // get edit size, should be used as minimum
133cdf0e10cSrcweir     Size aEditSize( maUserED.GetSizePixel() );
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     // add labelcolumn for the labeled edit fields
136cdf0e10cSrcweir     boost::shared_ptr<vcl::LabelColumn> xEdits( new vcl::LabelColumn( xLayout.get() ) );
137cdf0e10cSrcweir     size_t nChildIndex = xLayout->addChild( xEdits );
138cdf0e10cSrcweir     xLayout->setBorders( nChildIndex, -2, -2, -2, 0 );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     // add group box
141cdf0e10cSrcweir     xEdits->addWindow( &maPasswordBox );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     // add user line
144cdf0e10cSrcweir     xEdits->addRow( &maUserFT, &maUserED, -2, aEditSize );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     // add password line
147cdf0e10cSrcweir     xEdits->addRow( &maPasswordFT, &maPasswordED, -2, aEditSize );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     // add confirm line
150cdf0e10cSrcweir     xEdits->addRow( &maConfirmFT, &maConfirmED, -2, aEditSize );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     // add second group box
153cdf0e10cSrcweir     xEdits->addWindow( &maPassword2Box );
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     // add second password line
156cdf0e10cSrcweir     xEdits->addRow( &maPassword2FT, &maPassword2ED, -2, aEditSize );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     // add second confirm line
159cdf0e10cSrcweir     xEdits->addRow( &maConfirm2FT, &maConfirm2ED, -2, aEditSize );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     // add a FixedLine
162cdf0e10cSrcweir     FixedLine* pLine = new FixedLine( this, 0 );
163cdf0e10cSrcweir     pLine->Show();
164cdf0e10cSrcweir     addWindow( pLine, true );
165cdf0e10cSrcweir     xLayout->addWindow( pLine );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     // add button column
168cdf0e10cSrcweir     Size aBtnSize( maCancelBtn.GetSizePixel() );
169cdf0e10cSrcweir     boost::shared_ptr<vcl::RowOrColumn> xButtons( new vcl::RowOrColumn( xLayout.get(), false ) );
170cdf0e10cSrcweir     nChildIndex = xLayout->addChild( xButtons );
171cdf0e10cSrcweir     xLayout->setBorders( nChildIndex, -2, 0, -2, -2 );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     size_t nBtnIndex = xButtons->addWindow( &maHelpBtn, 0, aBtnSize );
174cdf0e10cSrcweir     xButtons->addChild( new vcl::Spacer( xButtons.get() ) );
175cdf0e10cSrcweir     nBtnIndex = xButtons->addWindow( &maOKBtn, 0, aBtnSize );
176cdf0e10cSrcweir     nBtnIndex = xButtons->addWindow( &maCancelBtn, 0, aBtnSize );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	Link aLink = LINK( this, SfxPasswordDialog, EditModifyHdl );
179cdf0e10cSrcweir 	maPasswordED.SetModifyHdl( aLink );
180cdf0e10cSrcweir 	maPassword2ED.SetModifyHdl( aLink );
181cdf0e10cSrcweir 	aLink = LINK( this, SfxPasswordDialog, OKHdl );
182cdf0e10cSrcweir 	maOKBtn.SetClickHdl( aLink );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	if ( pGroupText )
185cdf0e10cSrcweir 		  maPasswordBox.SetText( *pGroupText );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir // -----------------------------------------------------------------------
189cdf0e10cSrcweir 
SetMinLen(sal_uInt16 nLen)190cdf0e10cSrcweir void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir 	mnMinLen = nLen;
193cdf0e10cSrcweir 	EditModifyHdl( NULL );
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir // -----------------------------------------------------------------------
197cdf0e10cSrcweir 
SetMaxLen(sal_uInt16 nLen)198cdf0e10cSrcweir void SfxPasswordDialog::SetMaxLen( sal_uInt16 nLen )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     maPasswordED.SetMaxTextLen( nLen );
201cdf0e10cSrcweir     maConfirmED.SetMaxTextLen( nLen );
202cdf0e10cSrcweir 	EditModifyHdl( NULL );
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir // -----------------------------------------------------------------------
206cdf0e10cSrcweir 
Execute()207cdf0e10cSrcweir short SfxPasswordDialog::Execute()
208cdf0e10cSrcweir {
209cdf0e10cSrcweir     maUserFT.Hide();
210cdf0e10cSrcweir     maUserED.Hide();
211cdf0e10cSrcweir     maConfirmFT.Hide();
212cdf0e10cSrcweir     maConfirmED.Hide();
213cdf0e10cSrcweir     maPasswordFT.Hide();
214cdf0e10cSrcweir     maPassword2Box.Hide();
215cdf0e10cSrcweir     maPassword2FT.Hide();
216cdf0e10cSrcweir     maPassword2ED.Hide();
217cdf0e10cSrcweir     maPassword2FT.Hide();
218cdf0e10cSrcweir     maConfirm2FT.Hide();
219cdf0e10cSrcweir     maConfirm2ED.Hide();
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     if( mnExtras != SHOWEXTRAS_NONE )
222cdf0e10cSrcweir         maPasswordFT.Show();
223cdf0e10cSrcweir     if( (mnExtras & SHOWEXTRAS_USER ) )
224cdf0e10cSrcweir     {
225cdf0e10cSrcweir         maUserFT.Show();
226cdf0e10cSrcweir         maUserED.Show();
227cdf0e10cSrcweir     }
228cdf0e10cSrcweir     if( (mnExtras & SHOWEXTRAS_CONFIRM ) )
229cdf0e10cSrcweir     {
230cdf0e10cSrcweir         maConfirmFT.Show();
231cdf0e10cSrcweir         maConfirmED.Show();
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir     if( (mnExtras & SHOWEXTRAS_PASSWORD2) )
234cdf0e10cSrcweir     {
235cdf0e10cSrcweir         maPassword2Box.Show();
236cdf0e10cSrcweir         maPassword2FT.Show();
237cdf0e10cSrcweir         maPassword2ED.Show();
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir     if( (mnExtras & SHOWEXTRAS_CONFIRM2 ) )
240cdf0e10cSrcweir     {
241cdf0e10cSrcweir         maConfirm2FT.Show();
242cdf0e10cSrcweir         maConfirm2ED.Show();
243cdf0e10cSrcweir     }
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     boost::shared_ptr<vcl::RowOrColumn> xLayout =
246cdf0e10cSrcweir         boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() );
247cdf0e10cSrcweir 	SetSizePixel( xLayout->getOptimalSize( WINDOWSIZE_PREFERRED ) );
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 	return ModalDialog::Execute();
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 
253