1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_extensions.hxx" 26 #include "newdatatype.hxx" 27 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_NEWDATATYPE_HRC 28 #include "newdatatype.hrc" 29 #endif 30 31 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_ 32 #include "modulepcr.hxx" 33 #endif 34 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_ 35 #include "formresid.hrc" 36 #endif 37 38 /** === begin UNO includes === **/ 39 /** === end UNO includes === **/ 40 41 //........................................................................ 42 namespace pcr 43 { 44 //........................................................................ 45 46 //==================================================================== 47 //= NewDataTypeDialog 48 //==================================================================== 49 //-------------------------------------------------------------------- NewDataTypeDialog(Window * _pParent,const::rtl::OUString & _rNameBase,const::std::vector<::rtl::OUString> & _rProhibitedNames)50 NewDataTypeDialog::NewDataTypeDialog( Window* _pParent, const ::rtl::OUString& _rNameBase, const ::std::vector< ::rtl::OUString >& _rProhibitedNames ) 51 :ModalDialog( _pParent, PcrRes( RID_DLG_NEW_DATA_TYPE ) ) 52 ,m_aLabel ( this, PcrRes( FT_LABEL ) ) 53 ,m_aName ( this, PcrRes( ED_NAME ) ) 54 ,m_aOK ( this, PcrRes( PB_OK ) ) 55 ,m_aCancel ( this, PcrRes( PB_CANCEL ) ) 56 ,m_aProhibitedNames( _rProhibitedNames.begin(), _rProhibitedNames.end() ) 57 { 58 FreeResource(); 59 60 m_aName.SetModifyHdl( LINK( this, NewDataTypeDialog, OnNameModified ) ); 61 62 // find an initial name 63 // for this, first remove trailing digits 64 sal_Int32 nStripUntil = _rNameBase.getLength(); 65 while ( nStripUntil > 0 ) 66 { 67 sal_Unicode nChar = _rNameBase[ --nStripUntil ]; 68 if ( ( nChar < '0' ) || ( nChar > '9' ) ) 69 { 70 if ( nChar == ' ' ) 71 --nStripUntil; // strip the space, too 72 break; 73 } 74 } 75 76 String sNameBase( _rNameBase.copy( 0, nStripUntil ? nStripUntil + 1 : 0 ) ); 77 sNameBase.Append( ' ' ); 78 String sInitialName; 79 sal_Int32 nPostfixNumber = 1; 80 do 81 { 82 ( sInitialName = sNameBase ) += String::CreateFromInt32( nPostfixNumber++ ); 83 } 84 while ( m_aProhibitedNames.find( sInitialName ) != m_aProhibitedNames.end() ); 85 86 m_aName.SetText( sInitialName ); 87 OnNameModified( NULL ); 88 } 89 90 //-------------------------------------------------------------------- 91 IMPL_LINK( NewDataTypeDialog, OnNameModified, void*, /*_pNotInterestedIn*/ ) 92 { 93 String sCurrentName = GetName(); 94 bool bNameIsOK = ( sCurrentName.Len() > 0 ) 95 && ( m_aProhibitedNames.find( sCurrentName ) == m_aProhibitedNames.end() ); 96 97 m_aOK.Enable( bNameIsOK ); 98 99 return 0L; 100 } 101 102 //........................................................................ 103 } // namespace pcr 104 //........................................................................ 105 106