2001-03-14 06:36:48 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2005-09-08 13:32:33 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-03-14 06:36:48 +00:00
|
|
|
*
|
2005-09-08 13:32:33 +00:00
|
|
|
* $RCSfile: SqlNameEdit.cxx,v $
|
2001-03-14 06:36:48 +00:00
|
|
|
*
|
2005-09-08 13:32:33 +00:00
|
|
|
* $Revision: 1.8 $
|
2001-03-14 06:36:48 +00:00
|
|
|
*
|
2005-09-08 13:32:33 +00:00
|
|
|
* last change: $Author: rt $ $Date: 2005-09-08 14:32:32 $
|
2001-03-14 06:36:48 +00:00
|
|
|
*
|
2005-09-08 13:32:33 +00:00
|
|
|
* The Contents of this file are made available subject to
|
|
|
|
* the terms of GNU Lesser General Public License Version 2.1.
|
2001-03-14 06:36:48 +00:00
|
|
|
*
|
|
|
|
*
|
2005-09-08 13:32:33 +00:00
|
|
|
* GNU Lesser General Public License Version 2.1
|
|
|
|
* =============================================
|
|
|
|
* Copyright 2005 by Sun Microsystems, Inc.
|
|
|
|
* 901 San Antonio Road, Palo Alto, CA 94303, USA
|
2001-03-14 06:36:48 +00:00
|
|
|
*
|
2005-09-08 13:32:33 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License version 2.1, as published by the Free Software Foundation.
|
2001-03-14 06:36:48 +00:00
|
|
|
*
|
2005-09-08 13:32:33 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-03-14 06:36:48 +00:00
|
|
|
*
|
2005-09-08 13:32:33 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
2001-03-14 06:36:48 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
#ifndef DBAUI_SQLNAMEEDIT_HXX
|
|
|
|
#include "SqlNameEdit.hxx"
|
|
|
|
#endif
|
|
|
|
namespace dbaui
|
|
|
|
{
|
|
|
|
//------------------------------------------------------------------
|
2001-03-27 12:05:17 +00:00
|
|
|
sal_Bool isCharOk(sal_Unicode _cChar,sal_Bool _bFirstChar,sal_Bool _bUpperCase,const ::rtl::OUString& _sAllowedChars)
|
2001-03-14 06:36:48 +00:00
|
|
|
{
|
2001-03-27 12:05:17 +00:00
|
|
|
return (_cChar >= 'A' && _cChar <= 'Z' ||
|
|
|
|
_cChar == '_' ||
|
|
|
|
_sAllowedChars.indexOf(_cChar) != -1 ||
|
|
|
|
(!_bFirstChar && (_cChar >= '0' && _cChar <= '9')) ||
|
|
|
|
(!_bUpperCase && (_cChar >= 'a' && _cChar <= 'z')));
|
|
|
|
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
2001-07-16 06:56:28 +00:00
|
|
|
sal_Bool OSQLNameChecker::checkString( const ::rtl::OUString& _sOldValue,
|
|
|
|
const ::rtl::OUString& _sToCheck,
|
|
|
|
::rtl::OUString& _rsCorrected)
|
2001-03-27 12:05:17 +00:00
|
|
|
{
|
2001-07-16 06:56:28 +00:00
|
|
|
sal_Bool bCorrected = sal_False;
|
2001-12-14 14:04:08 +00:00
|
|
|
if ( m_bCheck )
|
2001-03-14 06:36:48 +00:00
|
|
|
{
|
2001-07-16 06:56:28 +00:00
|
|
|
XubString sSavedValue = _sOldValue;
|
|
|
|
XubString sText = _sToCheck;
|
|
|
|
xub_StrLen nMatch = 0;
|
2001-12-14 14:04:08 +00:00
|
|
|
for ( xub_StrLen i=nMatch;i < sText.Len(); ++i )
|
2001-03-14 06:36:48 +00:00
|
|
|
{
|
2001-12-14 14:04:08 +00:00
|
|
|
if ( !isCharOk( sText.GetBuffer()[i], i == 0, m_bOnlyUpperCase, m_sAllowedChars ) )
|
2001-07-06 08:01:35 +00:00
|
|
|
{
|
2001-12-14 14:04:08 +00:00
|
|
|
_rsCorrected += sText.Copy( nMatch, i - nMatch );
|
2001-07-16 06:56:28 +00:00
|
|
|
bCorrected = sal_True;
|
2001-12-14 14:04:08 +00:00
|
|
|
nMatch = i + 1;
|
2001-07-06 08:01:35 +00:00
|
|
|
}
|
2001-03-14 06:36:48 +00:00
|
|
|
}
|
2001-12-14 14:04:08 +00:00
|
|
|
_rsCorrected += sText.Copy( nMatch, sText.Len() - nMatch );
|
2001-03-14 06:36:48 +00:00
|
|
|
}
|
2001-07-16 06:56:28 +00:00
|
|
|
return bCorrected;
|
|
|
|
}
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void OSQLNameEdit::Modify()
|
|
|
|
{
|
|
|
|
::rtl::OUString sCorrected;
|
2001-12-14 14:04:08 +00:00
|
|
|
if ( checkString( GetSavedValue(),GetText(),sCorrected ) )
|
|
|
|
{
|
|
|
|
Selection aSel = GetSelection();
|
|
|
|
aSel.setMax( aSel.getMin() );
|
|
|
|
SetText( sCorrected, aSel );
|
|
|
|
|
|
|
|
SaveValue();
|
|
|
|
}
|
2001-03-27 12:05:17 +00:00
|
|
|
Edit::Modify();
|
2001-03-14 06:36:48 +00:00
|
|
|
}
|
2001-07-16 06:56:28 +00:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
void OSQLNameComboBox::Modify()
|
|
|
|
{
|
|
|
|
::rtl::OUString sCorrected;
|
2001-12-14 14:04:08 +00:00
|
|
|
if ( checkString( GetSavedValue(),GetText(),sCorrected ) )
|
2001-07-16 06:56:28 +00:00
|
|
|
{
|
2001-12-14 14:04:08 +00:00
|
|
|
Selection aSel = GetSelection();
|
|
|
|
aSel.setMax( aSel.getMin() );
|
|
|
|
SetText( sCorrected );
|
|
|
|
|
2001-07-16 06:56:28 +00:00
|
|
|
SaveValue();
|
|
|
|
}
|
|
|
|
ComboBox::Modify();
|
|
|
|
}
|
2001-03-14 06:36:48 +00:00
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|