diff options
Diffstat (limited to 'sfx2/source/dialog/passwd.cxx')
-rw-r--r-- | sfx2/source/dialog/passwd.cxx | 179 |
1 files changed, 111 insertions, 68 deletions
diff --git a/sfx2/source/dialog/passwd.cxx b/sfx2/source/dialog/passwd.cxx index e7cc73ca04bf..52c6acedd4ea 100644 --- a/sfx2/source/dialog/passwd.cxx +++ b/sfx2/source/dialog/passwd.cxx @@ -41,14 +41,15 @@ #include "passwd.hrc" #include "vcl/sound.hxx" +#include "vcl/arrange.hxx" // ----------------------------------------------------------------------- -IMPL_LINK_INLINE_START( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG ) +IMPL_LINK_INLINE_START( SfxPasswordDialog, EditModifyHdl, Edit *, pEdit ) { - if( mbAsciiOnly ) + if( mbAsciiOnly && (pEdit == &maPasswordED || pEdit == &maPassword2ED) ) { - rtl::OUString aTest( maPasswordED.GetText() ); + rtl::OUString aTest( pEdit->GetText() ); const sal_Unicode* pTest = aTest.getStr(); sal_Int32 nLen = aTest.getLength(); rtl::OUStringBuffer aFilter( nLen ); @@ -64,12 +65,15 @@ IMPL_LINK_INLINE_START( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG ) if( bReset ) { Sound::Beep( SOUND_ERROR ); - maPasswordED.SetSelection( Selection( 0, nLen ) ); - maPasswordED.ReplaceSelected( aFilter.makeStringAndClear() ); + pEdit->SetSelection( Selection( 0, nLen ) ); + pEdit->ReplaceSelected( aFilter.makeStringAndClear() ); } } - maOKBtn.Enable( maPasswordED.GetText().Len() >= mnMinLen ); + bool bEnable = maPasswordED.GetText().Len() >= mnMinLen; + if( maPassword2ED.IsVisible() ) + bEnable = (bEnable && (maPassword2ED.GetText().Len() >= mnMinLen)); + maOKBtn.Enable( bEnable ); return 0; } IMPL_LINK_INLINE_END( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG ) @@ -78,8 +82,11 @@ IMPL_LINK_INLINE_END( SfxPasswordDialog, EditModifyHdl, Edit *, EMPTYARG ) IMPL_LINK( SfxPasswordDialog, OKHdl, OKButton *, EMPTYARG ) { - if ( ( ( mnExtras & SHOWEXTRAS_CONFIRM ) == SHOWEXTRAS_CONFIRM ) && - ( GetConfirm() != GetPassword() ) ) + bool bConfirmFailed = ( ( mnExtras & SHOWEXTRAS_CONFIRM ) == SHOWEXTRAS_CONFIRM ) && + ( GetConfirm() != GetPassword() ); + if( ( mnExtras & SHOWEXTRAS_CONFIRM2 ) == SHOWEXTRAS_CONFIRM2 && ( GetConfirm2() != GetPassword2() ) ) + bConfirmFailed = true; + if ( bConfirmFailed ) { ErrorBox aBox( this, SfxResId( MSG_ERROR_WRONG_CONFIRM ) ); aBox.Execute(); @@ -97,27 +104,83 @@ SfxPasswordDialog::SfxPasswordDialog( Window* pParent, const String* pGroupText ModalDialog( pParent, SfxResId ( DLG_PASSWD ) ), + maPasswordBox ( this, SfxResId( GB_PASSWD_PASSWORD ) ), maUserFT ( this, SfxResId( FT_PASSWD_USER ) ), maUserED ( this, SfxResId( ED_PASSWD_USER ) ), maPasswordFT ( this, SfxResId( FT_PASSWD_PASSWORD ) ), maPasswordED ( this, SfxResId( ED_PASSWD_PASSWORD ) ), maConfirmFT ( this, SfxResId( FT_PASSWD_CONFIRM ) ), maConfirmED ( this, SfxResId( ED_PASSWD_CONFIRM ) ), - maPasswordBox ( this, SfxResId( GB_PASSWD_PASSWORD ) ), + maPassword2Box ( this, 0 ), + maPassword2FT ( this, SfxResId( FT_PASSWD_PASSWORD2 ) ), + maPassword2ED ( this, SfxResId( ED_PASSWD_PASSWORD2 ) ), + maConfirm2FT ( this, SfxResId( FT_PASSWD_CONFIRM2 ) ), + maConfirm2ED ( this, SfxResId( ED_PASSWD_CONFIRM2 ) ), maOKBtn ( this, SfxResId( BTN_PASSWD_OK ) ), maCancelBtn ( this, SfxResId( BTN_PASSWD_CANCEL ) ), maHelpBtn ( this, SfxResId( BTN_PASSWD_HELP ) ), - maConfirmStr ( SfxResId( STR_PASSWD_CONFIRM ) ), - mnMinLen ( 5 ), + mnMinLen ( 1 ), mnExtras ( 0 ), mbAsciiOnly ( false ) { FreeResource(); + // setup layout + boost::shared_ptr<vcl::RowOrColumn> xLayout = + boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() ); + xLayout->setOuterBorder( 0 ); + + // get edit size, should be used as minimum + Size aEditSize( maUserED.GetSizePixel() ); + + // add labelcolumn for the labeled edit fields + boost::shared_ptr<vcl::LabelColumn> xEdits( new vcl::LabelColumn( xLayout.get() ) ); + size_t nChildIndex = xLayout->addChild( xEdits ); + xLayout->setBorders( nChildIndex, -2, -2, -2, 0 ); + + // add group box + xEdits->addWindow( &maPasswordBox ); + + // add user line + xEdits->addRow( &maUserFT, &maUserED, -2, aEditSize ); + + // add password line + xEdits->addRow( &maPasswordFT, &maPasswordED, -2, aEditSize ); + + // add confirm line + xEdits->addRow( &maConfirmFT, &maConfirmED, -2, aEditSize ); + + // add second group box + xEdits->addWindow( &maPassword2Box ); + + // add second password line + xEdits->addRow( &maPassword2FT, &maPassword2ED, -2, aEditSize ); + + // add second confirm line + xEdits->addRow( &maConfirm2FT, &maConfirm2ED, -2, aEditSize ); + + // add a FixedLine + FixedLine* pLine = new FixedLine( this, 0 ); + pLine->Show(); + addWindow( pLine, true ); + xLayout->addWindow( pLine ); + + // add button column + Size aBtnSize( maCancelBtn.GetSizePixel() ); + boost::shared_ptr<vcl::RowOrColumn> xButtons( new vcl::RowOrColumn( xLayout.get(), false ) ); + nChildIndex = xLayout->addChild( xButtons ); + xLayout->setBorders( nChildIndex, -2, 0, -2, -2 ); + + size_t nBtnIndex = xButtons->addWindow( &maHelpBtn, 0, aBtnSize ); + xButtons->addChild( new vcl::Spacer( xButtons.get() ) ); + nBtnIndex = xButtons->addWindow( &maOKBtn, 0, aBtnSize ); + nBtnIndex = xButtons->addWindow( &maCancelBtn, 0, aBtnSize ); + Link aLink = LINK( this, SfxPasswordDialog, EditModifyHdl ); maPasswordED.SetModifyHdl( aLink ); + maPassword2ED.SetModifyHdl( aLink ); aLink = LINK( this, SfxPasswordDialog, OKHdl ); maOKBtn.SetClickHdl( aLink ); @@ -146,66 +209,46 @@ void SfxPasswordDialog::SetMaxLen( USHORT nLen ) short SfxPasswordDialog::Execute() { - if ( mnExtras < SHOWEXTRAS_ALL ) + maUserFT.Hide(); + maUserED.Hide(); + maConfirmFT.Hide(); + maConfirmED.Hide(); + maPasswordFT.Hide(); + maPassword2Box.Hide(); + maPassword2FT.Hide(); + maPassword2ED.Hide(); + maPassword2FT.Hide(); + maConfirm2FT.Hide(); + maConfirm2ED.Hide(); + + if( mnExtras != SHOWEXTRAS_NONE ) + maPasswordFT.Show(); + if( (mnExtras & SHOWEXTRAS_USER ) ) { - Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT ); - Size a6Size = LogicToPixel( Size( 6, 6 ), MAP_APPFONT ); - long nMinHeight = maHelpBtn.GetPosPixel().Y() + - maHelpBtn.GetSizePixel().Height() + a6Size.Height(); - USHORT nRowHided = 1; - - if ( SHOWEXTRAS_NONE == mnExtras ) - { - maUserFT.Hide(); - maUserED.Hide(); - maConfirmFT.Hide(); - maConfirmED.Hide(); - maPasswordFT.Hide(); - - Point aPos = maUserFT.GetPosPixel(); - long nEnd = maUserED.GetPosPixel().X() + maUserED.GetSizePixel().Width(); - maPasswordED.SetPosPixel( aPos ); - Size aSize = maPasswordED.GetSizePixel(); - aSize.Width() = nEnd - aPos.X(); - maPasswordED.SetSizePixel( aSize ); - - nRowHided = 2; - } - else if ( SHOWEXTRAS_USER == mnExtras ) - { - maConfirmFT.Hide(); - maConfirmED.Hide(); - } - else if ( SHOWEXTRAS_CONFIRM == mnExtras ) - { - maUserFT.Hide(); - maUserED.Hide(); - - Point aPwdPos1 = maPasswordFT.GetPosPixel(); - Point aPwdPos2 = maPasswordED.GetPosPixel(); - - Point aPos = maUserFT.GetPosPixel(); - maPasswordFT.SetPosPixel( aPos ); - aPos = maUserED.GetPosPixel(); - maPasswordED.SetPosPixel( aPos ); - - maConfirmFT.SetPosPixel( aPwdPos1 ); - maConfirmED.SetPosPixel( aPwdPos2 ); - } - - Size aBoxSize = maPasswordBox.GetSizePixel(); - aBoxSize.Height() -= ( nRowHided * maUserED.GetSizePixel().Height() ); - aBoxSize.Height() -= ( nRowHided * a3Size.Height() ); - maPasswordBox.SetSizePixel( aBoxSize ); - - long nDlgHeight = maPasswordBox.GetPosPixel().Y() + aBoxSize.Height() + a6Size.Height(); - if ( nDlgHeight < nMinHeight ) - nDlgHeight = nMinHeight; - Size aDlgSize = GetOutputSizePixel(); - aDlgSize.Height() = nDlgHeight; - SetOutputSizePixel( aDlgSize ); + maUserFT.Show(); + maUserED.Show(); + } + if( (mnExtras & SHOWEXTRAS_CONFIRM ) ) + { + maConfirmFT.Show(); + maConfirmED.Show(); + } + if( (mnExtras & SHOWEXTRAS_PASSWORD2) ) + { + maPassword2Box.Show(); + maPassword2FT.Show(); + maPassword2ED.Show(); + } + if( (mnExtras & SHOWEXTRAS_CONFIRM2 ) ) + { + maConfirm2FT.Show(); + maConfirm2ED.Show(); } + boost::shared_ptr<vcl::RowOrColumn> xLayout = + boost::dynamic_pointer_cast<vcl::RowOrColumn>( getLayout() ); + SetSizePixel( xLayout->getOptimalSize( WINDOWSIZE_PREFERRED ) ); + return ModalDialog::Execute(); } |