1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_dbaccess.hxx" 30 #ifndef DBAUI_SQLNAMEEDIT_HXX 31 #include "SqlNameEdit.hxx" 32 #endif 33 namespace dbaui 34 { 35 //------------------------------------------------------------------ 36 sal_Bool isCharOk(sal_Unicode _cChar,sal_Bool _bFirstChar,sal_Bool _bUpperCase,const ::rtl::OUString& _sAllowedChars) 37 { 38 return ( 39 (_cChar >= 'A' && _cChar <= 'Z') || 40 _cChar == '_' || 41 _sAllowedChars.indexOf(_cChar) != -1 || 42 (!_bFirstChar && (_cChar >= '0' && _cChar <= '9')) || 43 (!_bUpperCase && (_cChar >= 'a' && _cChar <= 'z')) 44 ); 45 } 46 //------------------------------------------------------------------ 47 sal_Bool OSQLNameChecker::checkString( const ::rtl::OUString& _sOldValue, 48 const ::rtl::OUString& _sToCheck, 49 ::rtl::OUString& _rsCorrected) 50 { 51 sal_Bool bCorrected = sal_False; 52 if ( m_bCheck ) 53 { 54 XubString sSavedValue = _sOldValue; 55 XubString sText = _sToCheck; 56 xub_StrLen nMatch = 0; 57 for ( xub_StrLen i=nMatch;i < sText.Len(); ++i ) 58 { 59 if ( !isCharOk( sText.GetBuffer()[i], i == 0, m_bOnlyUpperCase, m_sAllowedChars ) ) 60 { 61 _rsCorrected += sText.Copy( nMatch, i - nMatch ); 62 bCorrected = sal_True; 63 nMatch = i + 1; 64 } 65 } 66 _rsCorrected += sText.Copy( nMatch, sText.Len() - nMatch ); 67 } 68 return bCorrected; 69 } 70 //------------------------------------------------------------------ 71 void OSQLNameEdit::Modify() 72 { 73 ::rtl::OUString sCorrected; 74 if ( checkString( GetSavedValue(),GetText(),sCorrected ) ) 75 { 76 Selection aSel = GetSelection(); 77 aSel.setMax( aSel.getMin() ); 78 SetText( sCorrected, aSel ); 79 80 SaveValue(); 81 } 82 Edit::Modify(); 83 } 84 //------------------------------------------------------------------ 85 void OSQLNameComboBox::Modify() 86 { 87 ::rtl::OUString sCorrected; 88 if ( checkString( GetSavedValue(),GetText(),sCorrected ) ) 89 { 90 Selection aSel = GetSelection(); 91 aSel.setMax( aSel.getMin() ); 92 SetText( sCorrected ); 93 94 SaveValue(); 95 } 96 ComboBox::Modify(); 97 } 98 } 99 // ----------------------------------------------------------------------------- 100 101