masterfix DEV300: #i10000# build fix
[LibreOffice.git] / extensions / source / propctrlr / newdatatype.cxx
blob412048a9e7b284fc9fbc32bef115134fd5013b41
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "newdatatype.hxx"
31 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_NEWDATATYPE_HRC
32 #include "newdatatype.hrc"
33 #endif
35 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
36 #include "modulepcr.hxx"
37 #endif
38 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_
39 #include "formresid.hrc"
40 #endif
42 /** === begin UNO includes === **/
43 /** === end UNO includes === **/
45 //........................................................................
46 namespace pcr
48 //........................................................................
50 //====================================================================
51 //= NewDataTypeDialog
52 //====================================================================
53 //--------------------------------------------------------------------
54 NewDataTypeDialog::NewDataTypeDialog( Window* _pParent, const ::rtl::OUString& _rNameBase, const ::std::vector< ::rtl::OUString >& _rProhibitedNames )
55 :ModalDialog( _pParent, PcrRes( RID_DLG_NEW_DATA_TYPE ) )
56 ,m_aLabel ( this, PcrRes( FT_LABEL ) )
57 ,m_aName ( this, PcrRes( ED_NAME ) )
58 ,m_aOK ( this, PcrRes( PB_OK ) )
59 ,m_aCancel ( this, PcrRes( PB_CANCEL ) )
60 ,m_aProhibitedNames( _rProhibitedNames.begin(), _rProhibitedNames.end() )
62 FreeResource();
64 m_aName.SetModifyHdl( LINK( this, NewDataTypeDialog, OnNameModified ) );
66 // find an initial name
67 // for this, first remove trailing digits
68 sal_Int32 nStripUntil = _rNameBase.getLength();
69 while ( nStripUntil > 0 )
71 sal_Unicode nChar = _rNameBase[ --nStripUntil ];
72 if ( ( nChar < '0' ) || ( nChar > '9' ) )
74 if ( nChar == ' ' )
75 --nStripUntil; // strip the space, too
76 break;
80 String sNameBase( _rNameBase.copy( 0, nStripUntil ? nStripUntil + 1 : 0 ) );
81 sNameBase.Append( ' ' );
82 String sInitialName;
83 sal_Int32 nPostfixNumber = 1;
86 ( sInitialName = sNameBase ) += String::CreateFromInt32( nPostfixNumber++ );
88 while ( m_aProhibitedNames.find( sInitialName ) != m_aProhibitedNames.end() );
90 m_aName.SetText( sInitialName );
91 OnNameModified( NULL );
94 //--------------------------------------------------------------------
95 IMPL_LINK( NewDataTypeDialog, OnNameModified, void*, /*_pNotInterestedIn*/ )
97 String sCurrentName = GetName();
98 bool bNameIsOK = ( sCurrentName.Len() > 0 )
99 && ( m_aProhibitedNames.find( sCurrentName ) == m_aProhibitedNames.end() );
101 m_aOK.Enable( bNameIsOK );
103 return 0L;
106 //........................................................................
107 } // namespace pcr
108 //........................................................................