Files
libreoffice/sfx2/source/dialog/passwd.cxx
Stephan Bergmann 3ead3ad52f Gradually typed Link
Turn the Link class into a template abstracting over the link's argument and
return types, but provide default template arguments that keep the generic,
unsafe "void* in, sal_IntPtr out" behvior.  That way, individual uses of the
Link class can be updated over time.

All the related macros are duplicated with ..._TYPED counterparts, that
additionally take the RetType (except for LINK_TYPED, which manages to infer the
relevant types from the supplied Member).

(It would have been attractive to change the "untyped" LinkStubs from taking a
void* to a properly typed ArgType parameter, too, but that would cause
-fsanitize=function to flag uses of "untyped" Link::Call.)

Change-Id: I3b0140378bad99abbf240140ebb4a46a05d2d2f8
2015-04-30 10:20:00 +02:00

226 lines
6.1 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// Include ---------------------------------------------------------------
#include <vcl/layout.hxx>
#include <sfx2/passwd.hxx>
#include "sfxtypes.hxx"
#include <sfx2/sfxresid.hxx>
#include "dialog.hrc"
IMPL_LINK( SfxPasswordDialog, EditModifyHdl, Edit *, pEdit )
{
if (mbAsciiOnly && (pEdit == mpPassword1ED || pEdit == mpPassword2ED))
{
OUString aTest( pEdit->GetText() );
const sal_Unicode* pTest = aTest.getStr();
sal_Int32 nLen = aTest.getLength();
OUStringBuffer aFilter( nLen );
bool bReset = false;
for( sal_Int32 i = 0; i < nLen; i++ )
{
if( *pTest > 0x007f )
bReset = true;
else
aFilter.append( *pTest );
pTest++;
}
if( bReset )
{
pEdit->SetSelection( Selection( 0, nLen ) );
pEdit->ReplaceSelected( aFilter.makeStringAndClear() );
}
}
bool bEnable = mpPassword1ED->GetText().getLength() >= mnMinLen;
if( mpPassword2ED->IsVisible() )
bEnable = (bEnable && (mpPassword2ED->GetText().getLength() >= mnMinLen));
mpOKBtn->Enable( bEnable );
return 0;
}
IMPL_LINK_NOARG(SfxPasswordDialog, OKHdl)
{
bool bConfirmFailed = bool( mnExtras & SfxShowExtras::CONFIRM ) &&
( GetConfirm() != GetPassword() );
if( ( mnExtras & SfxShowExtras::CONFIRM2 ) && ( GetConfirm2() != GetPassword2() ) )
bConfirmFailed = true;
if ( bConfirmFailed )
{
ScopedVclPtrInstance< MessageDialog > aBox(this, SfxResId(STR_ERROR_WRONG_CONFIRM));
aBox->Execute();
mpConfirm1ED->SetText( OUString() );
mpConfirm1ED->GrabFocus();
}
else
EndDialog( RET_OK );
return 0;
}
// CTOR / DTOR -----------------------------------------------------------
SfxPasswordDialog::SfxPasswordDialog(vcl::Window* pParent, const OUString* pGroupText)
: ModalDialog(pParent, "PasswordDialog", "sfx/ui/password.ui")
, maMinLenPwdStr(SFX2_RESSTR(STR_PASSWD_MIN_LEN))
, maMinLenPwdStr1(SFX2_RESSTR(STR_PASSWD_MIN_LEN1))
, maEmptyPwdStr(SFX2_RESSTR(STR_PASSWD_EMPTY))
, mnMinLen(5)
, mnExtras(SfxShowExtras::NONE)
, mbAsciiOnly(false)
{
get(mpPassword1Box, "password1frame");
get(mpUserFT, "userft");
get(mpUserED, "usered");
get(mpPassword1FT, "pass1ft");
get(mpPassword1ED, "pass1ed");
get(mpConfirm1FT, "confirm1ft");
get(mpConfirm1ED, "confirm1ed");
get(mpPassword2Box, "password2frame");
get(mpPassword2FT, "pass2ft");
get(mpPassword2ED, "pass2ed");
get(mpConfirm2FT, "confirm2ft");
get(mpConfirm2ED, "confirm2ed");
get(mpMinLengthFT, "minlenft");
get(mpOKBtn, "ok");
mpPassword1ED->SetAccessibleName(SFX2_RESSTR(STR_PASSWD));
Link<> aLink = LINK( this, SfxPasswordDialog, EditModifyHdl );
mpPassword1ED->SetModifyHdl( aLink );
mpPassword2ED->SetModifyHdl( aLink );
aLink = LINK( this, SfxPasswordDialog, OKHdl );
mpOKBtn->SetClickHdl( aLink );
if (pGroupText)
mpPassword1Box->set_label(*pGroupText);
//set the text to the password length
SetPasswdText();
}
SfxPasswordDialog::~SfxPasswordDialog()
{
disposeOnce();
}
void SfxPasswordDialog::dispose()
{
mpPassword1Box.clear();
mpUserFT.clear();
mpUserED.clear();
mpPassword1FT.clear();
mpPassword1ED.clear();
mpConfirm1FT.clear();
mpConfirm1ED.clear();
mpPassword2Box.clear();
mpPassword2FT.clear();
mpPassword2ED.clear();
mpConfirm2FT.clear();
mpConfirm2ED.clear();
mpMinLengthFT.clear();
mpOKBtn.clear();
ModalDialog::dispose();
}
void SfxPasswordDialog::SetPasswdText( )
{
//set the new string to the minimum password length
if( mnMinLen == 0 )
mpMinLengthFT->SetText(maEmptyPwdStr);
else
{
if( mnMinLen == 1 )
mpMinLengthFT->SetText(maMinLenPwdStr1);
else
{
maMainPwdStr = maMinLenPwdStr;
maMainPwdStr = maMainPwdStr.replaceAll( "$(MINLEN)", OUString::number((sal_Int32) mnMinLen ) );
mpMinLengthFT->SetText(maMainPwdStr);
}
}
}
void SfxPasswordDialog::SetMinLen( sal_uInt16 nLen )
{
mnMinLen = nLen;
SetPasswdText();
EditModifyHdl( NULL );
}
void SfxPasswordDialog::ShowMinLengthText(bool bShow)
{
mpMinLengthFT->Show(bShow);
}
short SfxPasswordDialog::Execute()
{
mpUserFT->Hide();
mpUserED->Hide();
mpConfirm1FT->Hide();
mpConfirm1ED->Hide();
mpPassword1FT->Hide();
mpPassword2Box->Hide();
mpPassword2FT->Hide();
mpPassword2ED->Hide();
mpPassword2FT->Hide();
mpConfirm2FT->Hide();
mpConfirm2ED->Hide();
if (mnExtras != SfxShowExtras::NONE)
mpPassword1FT->Show();
if (mnExtras & SfxShowExtras::USER)
{
mpUserFT->Show();
mpUserED->Show();
}
if (mnExtras & SfxShowExtras::CONFIRM)
{
mpConfirm1FT->Show();
mpConfirm1ED->Show();
}
if (mnExtras & SfxShowExtras::PASSWORD2)
{
mpPassword2Box->Show();
mpPassword2FT->Show();
mpPassword2ED->Show();
}
if (mnExtras & SfxShowExtras::CONFIRM2)
{
mpConfirm2FT->Show();
mpConfirm2ED->Show();
}
return ModalDialog::Execute();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */