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_extensions.hxx"
30 #include "newdatatype.hxx"
31 #ifndef EXTENSIONS_SOURCE_PROPCTRLR_NEWDATATYPE_HRC
32 #include "newdatatype.hrc"
33 #endif
34 
35 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_
36 #include "modulepcr.hxx"
37 #endif
38 #ifndef _EXTENSIONS_FORMCTRLR_PROPRESID_HRC_
39 #include "formresid.hrc"
40 #endif
41 
42 /** === begin UNO includes === **/
43 /** === end UNO includes === **/
44 
45 //........................................................................
46 namespace pcr
47 {
48 //........................................................................
49 
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() )
61     {
62         FreeResource();
63 
64         m_aName.SetModifyHdl( LINK( this, NewDataTypeDialog, OnNameModified ) );
65 
66         // find an initial name
67         // for this, first remove trailing digits
68         sal_Int32 nStripUntil = _rNameBase.getLength();
69         while ( nStripUntil > 0 )
70         {
71             sal_Unicode nChar = _rNameBase[ --nStripUntil ];
72             if ( ( nChar < '0' ) || ( nChar > '9' ) )
73             {
74                 if ( nChar == ' ' )
75                     --nStripUntil;  // strip the space, too
76                 break;
77             }
78         }
79 
80         String sNameBase( _rNameBase.copy( 0, nStripUntil ? nStripUntil + 1 : 0 ) );
81         sNameBase.Append( ' ' );
82         String sInitialName;
83         sal_Int32 nPostfixNumber = 1;
84         do
85         {
86             ( sInitialName = sNameBase ) += String::CreateFromInt32( nPostfixNumber++ );
87         }
88         while ( m_aProhibitedNames.find( sInitialName ) != m_aProhibitedNames.end() );
89 
90         m_aName.SetText( sInitialName );
91         OnNameModified( NULL );
92     }
93 
94 	//--------------------------------------------------------------------
95     IMPL_LINK( NewDataTypeDialog, OnNameModified, void*, /*_pNotInterestedIn*/ )
96     {
97         String sCurrentName = GetName();
98         bool bNameIsOK = ( sCurrentName.Len() > 0 )
99                       && ( m_aProhibitedNames.find( sCurrentName ) == m_aProhibitedNames.end() );
100 
101         m_aOK.Enable( bNameIsOK );
102 
103         return 0L;
104     }
105 
106 //........................................................................
107 } // namespace pcr
108 //........................................................................
109 
110