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 "modulepcr.hxx"
22 : #include "formresid.hrc"
23 :
24 : namespace pcr
25 : {
26 :
27 :
28 :
29 : //= NewDataTypeDialog
30 :
31 :
32 0 : NewDataTypeDialog::NewDataTypeDialog( vcl::Window* _pParent, const OUString& _rNameBase, const ::std::vector< OUString >& _rProhibitedNames )
33 : : ModalDialog( _pParent, "DataTypeDialog",
34 : "modules/spropctrlr/ui/datatypedialog.ui" )
35 0 : , m_aProhibitedNames( _rProhibitedNames.begin(), _rProhibitedNames.end() )
36 : {
37 0 : get(m_pName, "entry");
38 0 : get(m_pOK, "ok");
39 :
40 0 : m_pName->SetModifyHdl( LINK( this, NewDataTypeDialog, OnNameModified ) );
41 :
42 : // find an initial name
43 : // for this, first remove trailing digits
44 0 : sal_Int32 nStripUntil = _rNameBase.getLength();
45 0 : while ( nStripUntil > 0 )
46 : {
47 0 : sal_Unicode nChar = _rNameBase[ --nStripUntil ];
48 0 : if ( ( nChar < '0' ) || ( nChar > '9' ) )
49 : {
50 0 : if ( nChar == ' ' )
51 0 : --nStripUntil; // strip the space, too
52 0 : break;
53 : }
54 : }
55 :
56 0 : OUString sNameBase( _rNameBase.copy( 0, nStripUntil ? nStripUntil + 1 : 0 ) );
57 0 : sNameBase += " ";
58 0 : OUString sInitialName;
59 0 : sal_Int32 nPostfixNumber = 1;
60 0 : do
61 : {
62 0 : ( sInitialName = sNameBase ) += OUString::number(nPostfixNumber++);
63 : }
64 0 : while ( m_aProhibitedNames.find( sInitialName ) != m_aProhibitedNames.end() );
65 :
66 0 : m_pName->SetText( sInitialName );
67 0 : OnNameModified( NULL );
68 0 : }
69 :
70 0 : NewDataTypeDialog::~NewDataTypeDialog()
71 : {
72 0 : disposeOnce();
73 0 : }
74 :
75 0 : void NewDataTypeDialog::dispose()
76 : {
77 0 : m_pName.clear();
78 0 : m_pOK.clear();
79 0 : ModalDialog::dispose();
80 0 : }
81 :
82 0 : IMPL_LINK_NOARG( NewDataTypeDialog, OnNameModified )
83 : {
84 0 : OUString sCurrentName = GetName();
85 0 : bool bNameIsOK = ( !sCurrentName.isEmpty() )
86 0 : && ( m_aProhibitedNames.find( sCurrentName ) == m_aProhibitedNames.end() );
87 :
88 0 : m_pOK->Enable( bNameIsOK );
89 :
90 0 : return 0L;
91 : }
92 :
93 :
94 6 : } // namespace pcr
95 :
96 :
97 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|