1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "newdatatype.hxx"
30 #include "newdatatype.hrc"
32 #include "modulepcr.hxx"
33 #include "formresid.hrc"
35 /** === begin UNO includes === **/
36 /** === end UNO includes === **/
38 //........................................................................
41 //........................................................................
43 //====================================================================
45 //====================================================================
46 //--------------------------------------------------------------------
47 NewDataTypeDialog::NewDataTypeDialog( Window
* _pParent
, const ::rtl::OUString
& _rNameBase
, const ::std::vector
< ::rtl::OUString
>& _rProhibitedNames
)
48 :ModalDialog( _pParent
, PcrRes( RID_DLG_NEW_DATA_TYPE
) )
49 ,m_aLabel ( this, PcrRes( FT_LABEL
) )
50 ,m_aName ( this, PcrRes( ED_NAME
) )
51 ,m_aOK ( this, PcrRes( PB_OK
) )
52 ,m_aCancel ( this, PcrRes( PB_CANCEL
) )
53 ,m_aProhibitedNames( _rProhibitedNames
.begin(), _rProhibitedNames
.end() )
57 m_aName
.SetModifyHdl( LINK( this, NewDataTypeDialog
, OnNameModified
) );
59 // find an initial name
60 // for this, first remove trailing digits
61 sal_Int32 nStripUntil
= _rNameBase
.getLength();
62 while ( nStripUntil
> 0 )
64 sal_Unicode nChar
= _rNameBase
[ --nStripUntil
];
65 if ( ( nChar
< '0' ) || ( nChar
> '9' ) )
68 --nStripUntil
; // strip the space, too
73 String
sNameBase( _rNameBase
.copy( 0, nStripUntil
? nStripUntil
+ 1 : 0 ) );
74 sNameBase
.Append( ' ' );
76 sal_Int32 nPostfixNumber
= 1;
79 ( sInitialName
= sNameBase
) += rtl::OUString::valueOf(nPostfixNumber
++);
81 while ( m_aProhibitedNames
.find( sInitialName
) != m_aProhibitedNames
.end() );
83 m_aName
.SetText( sInitialName
);
84 OnNameModified( NULL
);
87 //--------------------------------------------------------------------
88 IMPL_LINK( NewDataTypeDialog
, OnNameModified
, void*, /*_pNotInterestedIn*/ )
90 String sCurrentName
= GetName();
91 bool bNameIsOK
= ( sCurrentName
.Len() > 0 )
92 && ( m_aProhibitedNames
.find( sCurrentName
) == m_aProhibitedNames
.end() );
94 m_aOK
.Enable( bNameIsOK
);
99 //........................................................................
101 //........................................................................
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */