Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "newdatatype.hxx"
21 : #include "newdatatype.hrc"
22 :
23 : #include "modulepcr.hxx"
24 : #include "formresid.hrc"
25 :
26 : //........................................................................
27 : namespace pcr
28 : {
29 : //........................................................................
30 :
31 : //====================================================================
32 : //= NewDataTypeDialog
33 : //====================================================================
34 : //--------------------------------------------------------------------
35 0 : NewDataTypeDialog::NewDataTypeDialog( Window* _pParent, const ::rtl::OUString& _rNameBase, const ::std::vector< ::rtl::OUString >& _rProhibitedNames )
36 : :ModalDialog( _pParent, PcrRes( RID_DLG_NEW_DATA_TYPE ) )
37 : ,m_aLabel ( this, PcrRes( FT_LABEL ) )
38 : ,m_aName ( this, PcrRes( ED_NAME ) )
39 : ,m_aOK ( this, PcrRes( PB_OK ) )
40 : ,m_aCancel ( this, PcrRes( PB_CANCEL ) )
41 0 : ,m_aProhibitedNames( _rProhibitedNames.begin(), _rProhibitedNames.end() )
42 : {
43 0 : FreeResource();
44 :
45 0 : m_aName.SetModifyHdl( LINK( this, NewDataTypeDialog, OnNameModified ) );
46 :
47 : // find an initial name
48 : // for this, first remove trailing digits
49 0 : sal_Int32 nStripUntil = _rNameBase.getLength();
50 0 : while ( nStripUntil > 0 )
51 : {
52 0 : sal_Unicode nChar = _rNameBase[ --nStripUntil ];
53 0 : if ( ( nChar < '0' ) || ( nChar > '9' ) )
54 : {
55 0 : if ( nChar == ' ' )
56 0 : --nStripUntil; // strip the space, too
57 0 : break;
58 : }
59 : }
60 :
61 0 : String sNameBase( _rNameBase.copy( 0, nStripUntil ? nStripUntil + 1 : 0 ) );
62 0 : sNameBase.Append( ' ' );
63 0 : String sInitialName;
64 0 : sal_Int32 nPostfixNumber = 1;
65 0 : do
66 : {
67 0 : ( sInitialName = sNameBase ) += rtl::OUString::valueOf(nPostfixNumber++);
68 : }
69 0 : while ( m_aProhibitedNames.find( sInitialName ) != m_aProhibitedNames.end() );
70 :
71 0 : m_aName.SetText( sInitialName );
72 0 : OnNameModified( NULL );
73 0 : }
74 :
75 : //--------------------------------------------------------------------
76 0 : IMPL_LINK( NewDataTypeDialog, OnNameModified, void*, /*_pNotInterestedIn*/ )
77 : {
78 0 : String sCurrentName = GetName();
79 0 : bool bNameIsOK = ( sCurrentName.Len() > 0 )
80 0 : && ( m_aProhibitedNames.find( sCurrentName ) == m_aProhibitedNames.end() );
81 :
82 0 : m_aOK.Enable( bNameIsOK );
83 :
84 0 : return 0L;
85 : }
86 :
87 : //........................................................................
88 : } // namespace pcr
89 : //........................................................................
90 :
91 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|