1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: newdatatype.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "newdatatype.hxx"
34 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_NEWDATATYPE_HRC
35 #include "newdatatype.hrc"
38 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
39 #include "modulepcr.hxx"
41 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_
42 #include "formresid.hrc"
45 /** === begin UNO includes === **/
46 /** === end UNO includes === **/
48 //........................................................................
51 //........................................................................
53 //====================================================================
55 //====================================================================
56 //--------------------------------------------------------------------
57 NewDataTypeDialog::NewDataTypeDialog( Window
* _pParent
, const ::rtl::OUString
& _rNameBase
, const ::std::vector
< ::rtl::OUString
>& _rProhibitedNames
)
58 :ModalDialog( _pParent
, PcrRes( RID_DLG_NEW_DATA_TYPE
) )
59 ,m_aLabel ( this, PcrRes( FT_LABEL
) )
60 ,m_aName ( this, PcrRes( ED_NAME
) )
61 ,m_aOK ( this, PcrRes( PB_OK
) )
62 ,m_aCancel ( this, PcrRes( PB_CANCEL
) )
63 ,m_aProhibitedNames( _rProhibitedNames
.begin(), _rProhibitedNames
.end() )
67 m_aName
.SetModifyHdl( LINK( this, NewDataTypeDialog
, OnNameModified
) );
69 // find an initial name
70 // for this, first remove trailing digits
71 sal_Int32 nStripUntil
= _rNameBase
.getLength();
72 while ( nStripUntil
> 0 )
74 sal_Unicode nChar
= _rNameBase
[ --nStripUntil
];
75 if ( ( nChar
< '0' ) || ( nChar
> '9' ) )
78 --nStripUntil
; // strip the space, too
83 String
sNameBase( _rNameBase
.copy( 0, nStripUntil
? nStripUntil
+ 1 : 0 ) );
84 sNameBase
.Append( ' ' );
86 sal_Int32 nPostfixNumber
= 1;
89 ( sInitialName
= sNameBase
) += String::CreateFromInt32( nPostfixNumber
++ );
91 while ( m_aProhibitedNames
.find( sInitialName
) != m_aProhibitedNames
.end() );
93 m_aName
.SetText( sInitialName
);
94 OnNameModified( NULL
);
97 //--------------------------------------------------------------------
98 IMPL_LINK( NewDataTypeDialog
, OnNameModified
, void*, /*_pNotInterestedIn*/ )
100 String sCurrentName
= GetName();
101 bool bNameIsOK
= ( sCurrentName
.Len() > 0 )
102 && ( m_aProhibitedNames
.find( sCurrentName
) == m_aProhibitedNames
.end() );
104 m_aOK
.Enable( bNameIsOK
);
109 //........................................................................
111 //........................................................................