2010-10-12 15:59:00 +02:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-11-30 12:23:25 +00:00
/*
* This file is part of the LibreOffice project .
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License , v . 2.0 . If a copy of the MPL was not distributed with this
* file , You can obtain one at http : //mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice :
*
* Licensed to the Apache Software Foundation ( ASF ) under one or more
* contributor license agreements . See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership . The ASF licenses this file to you under the Apache
* License , Version 2.0 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 16:07:07 +00:00
coverity#1158232 Fix ownership of NamedDBs::insert argument
f70d03436b7b501e0ed1d745935a204b9b97b855 "coverity#1158232 have a stab at
silencing warning with function markup" claimed that NamedDBs::insert always
takes ownerhip of its argument, but boost::ptr_set::insert(std::auto_ptr<U> x)
simply calls insert(x.release()), so only takes ownership when it returns true.
ScDBDocFunc::AddDBRange (sc/source/ui/docshell/dbdocfun.cxx) relies on this
behavior, deleting the argument when insert failed.
ScDBDocFunc::RenameDBRange (sc/source/ui/docshell/dbdocfun.cxx) relied on this
behavior, deleting the argument when insert failed, until
f55cc330dec0dec60c755e2ce28a840c7fca1956 "Fixed the fallout of the changes in
ScDBCollection" removed the delete (presumably in error?). I put it back in
now.
All other uses of NamedDBs::insert ignored the return value (witnessed with
SAL_WARN_UNUSED_RESULT). Some are insert-if-not-found cases, where I added
asserts now (Sc10Import::LoadDataBaseCollection,
sc/source/filter/starcalc/scflt.cxx, is not entirely clear to me, so I added a
TODO), while others would have potentially leaked the argument, in which cases I
fixed the code.
Change-Id: Iad40fbeb625c8ce6b0a61cbf16298d71cdc7de80
2014-03-12 16:05:37 +01:00
# include <sal/config.h>
# include <cassert>
2012-06-11 13:15:18 +01:00
# include <comphelper/string.hxx>
2000-09-18 16:07:07 +00:00
# include <vcl/msgbox.hxx>
# include "reffact.hxx"
# include "document.hxx"
# include "scresid.hxx"
# include "globstr.hrc"
2013-10-22 15:58:57 +03:00
# include "rangenam.hxx"
2011-03-24 23:14:28 -04:00
# include "globalnames.hxx"
2000-09-18 16:07:07 +00:00
# include "dbnamdlg.hxx"
2014-02-25 19:58:48 +01:00
2000-09-18 16:07:07 +00:00
# define ABS_SREF SCA_VALID \
| SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
# define ABS_DREF ABS_SREF \
| SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
# define ABS_DREF3D ABS_DREF | SCA_TAB_3D
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
class DBSaveData ;
static DBSaveData * pSaveObj = NULL ;
# define ERRORBOX(s) ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),s).Execute()
2014-02-25 19:58:48 +01:00
2000-09-18 16:07:07 +00:00
// class DBSaveData
class DBSaveData
{
public :
DBSaveData ( Edit & rEd , CheckBox & rHdr , CheckBox & rSize , CheckBox & rFmt ,
CheckBox & rStrip , ScRange & rArea )
2014-03-10 12:47:38 +00:00
: rEdAssign ( rEd )
, rBtnHeader ( rHdr )
, rBtnSize ( rSize )
, rBtnFormat ( rFmt )
, rBtnStrip ( rStrip )
, rCurArea ( rArea )
, bHeader ( false )
, bSize ( false )
, bFormat ( false )
, bStrip ( false )
, bDirty ( false )
{
}
2000-09-18 16:07:07 +00:00
void Save ( ) ;
void Restore ( ) ;
private :
Edit & rEdAssign ;
CheckBox & rBtnHeader ;
CheckBox & rBtnSize ;
CheckBox & rBtnFormat ;
CheckBox & rBtnStrip ;
ScRange & rCurArea ;
2013-10-07 14:26:21 +02:00
OUString aStr ;
2000-09-18 16:07:07 +00:00
ScRange aArea ;
2011-01-17 13:20:22 +01:00
sal_Bool bHeader : 1 ;
sal_Bool bSize : 1 ;
sal_Bool bFormat : 1 ;
sal_Bool bStrip : 1 ;
sal_Bool bDirty : 1 ;
2000-09-18 16:07:07 +00:00
} ;
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
void DBSaveData : : Save ( )
{
aArea = rCurArea ;
aStr = rEdAssign . GetText ( ) ;
bHeader = rBtnHeader . IsChecked ( ) ;
bSize = rBtnSize . IsChecked ( ) ;
bFormat = rBtnFormat . IsChecked ( ) ;
bStrip = rBtnStrip . IsChecked ( ) ;
2011-01-17 13:20:22 +01:00
bDirty = sal_True ;
2000-09-18 16:07:07 +00:00
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
void DBSaveData : : Restore ( )
{
if ( bDirty )
{
rCurArea = aArea ;
rEdAssign . SetText ( aStr ) ;
rBtnHeader . Check ( bHeader ) ;
rBtnSize . Check ( bSize ) ;
rBtnFormat . Check ( bFormat ) ;
rBtnStrip . Check ( bStrip ) ;
2011-03-10 16:55:21 -05:00
bDirty = false ;
2000-09-18 16:07:07 +00:00
}
}
2014-02-25 19:58:48 +01:00
2000-09-18 16:07:07 +00:00
// class ScDbNameDlg
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
2013-07-26 09:30:13 +01:00
ScDbNameDlg : : ScDbNameDlg ( SfxBindings * pB , SfxChildWindow * pCW , Window * pParent ,
ScViewData * ptrViewData )
: ScAnyRefDlg ( pB , pCW , pParent ,
" DefineDatabaseRangeDialog " ,
" modules/scalc/ui/definedatabaserangedialog.ui " )
, pViewData ( ptrViewData )
, pDoc ( ptrViewData - > GetDocument ( ) )
, bRefInputMode ( false )
, aAddrDetails ( pDoc - > GetAddressConvention ( ) , 0 , 0 )
, aLocalDbCol ( * ( pDoc - > GetDBCollection ( ) ) )
2000-09-18 16:07:07 +00:00
{
2013-07-26 09:30:13 +01:00
get ( m_pEdName , " entry " ) ;
m_pEdName - > set_height_request ( m_pEdName - > GetOptimalSize ( ) . Height ( ) + m_pEdName - > GetTextHeight ( ) * 8 ) ;
get ( m_pEdAssign , " assign " ) ;
get ( m_pAssignFrame , " RangeFrame " ) ;
m_pEdAssign - > SetReferences ( this , m_pAssignFrame - > get_label_widget ( ) ) ;
get ( m_pRbAssign , " assignrb " ) ;
m_pRbAssign - > SetReferences ( this , m_pEdAssign ) ;
get ( m_pOptions , " Options " ) ;
get ( m_pBtnHeader , " ContainsColumnLabels " ) ;
get ( m_pBtnDoSize , " InsertOrDeleteCells " ) ;
get ( m_pBtnKeepFmt , " KeepFormatting " ) ;
get ( m_pBtnStripData , " DontSaveImportedData " ) ;
get ( m_pFTSource , " Source " ) ;
get ( m_pFTOperations , " Operations " ) ;
get ( m_pBtnOk , " ok " ) ;
get ( m_pBtnCancel , " cancel " ) ;
get ( m_pBtnAdd , " add " ) ;
aStrAdd = m_pBtnAdd - > GetText ( ) ;
aStrModify = get < Window > ( " modify " ) - > GetText ( ) ;
get ( m_pBtnRemove , " delete " ) ;
aStrInvalid = get < Window > ( " invalid " ) - > GetText ( ) ;
m_pFTSource - > SetStyle ( m_pFTSource - > GetStyle ( ) | WB_NOLABEL ) ;
m_pFTOperations - > SetStyle ( m_pFTOperations - > GetStyle ( ) | WB_NOLABEL ) ;
2000-10-23 13:58:48 +00:00
2000-09-18 16:07:07 +00:00
// damit die Strings in der Resource bei den FixedTexten bleiben koennen:
2013-07-26 09:30:13 +01:00
aStrSource = m_pFTSource - > GetText ( ) ;
aStrOperations = m_pFTOperations - > GetText ( ) ;
2000-09-18 16:07:07 +00:00
2013-07-26 09:30:13 +01:00
pSaveObj = new DBSaveData ( * m_pEdAssign , * m_pBtnHeader ,
* m_pBtnDoSize , * m_pBtnKeepFmt , * m_pBtnStripData , theCurArea ) ;
2000-09-18 16:07:07 +00:00
Init ( ) ;
2013-12-02 15:54:29 +00:00
SynFocusTimer . SetTimeout ( 150 ) ;
SynFocusTimer . SetTimeoutHdl ( LINK ( this , ScDbNameDlg , FocusToComoboxHdl ) ) ;
SynFocusTimer . Start ( ) ;
2000-09-18 16:07:07 +00:00
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
2010-12-11 23:25:30 +01:00
ScDbNameDlg : : ~ ScDbNameDlg ( )
2000-09-18 16:07:07 +00:00
{
DELETEZ ( pSaveObj ) ;
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
void ScDbNameDlg : : Init ( )
{
2014-02-21 12:53:51 +01:00
m_pBtnHeader - > Check ( true ) ; // Default: mit Spaltenkoepfen
m_pBtnDoSize - > Check ( true ) ;
m_pBtnKeepFmt - > Check ( true ) ;
2013-07-26 09:30:13 +01:00
m_pBtnOk - > SetClickHdl ( LINK ( this , ScDbNameDlg , OkBtnHdl ) ) ;
m_pBtnCancel - > SetClickHdl ( LINK ( this , ScDbNameDlg , CancelBtnHdl ) ) ;
m_pBtnAdd - > SetClickHdl ( LINK ( this , ScDbNameDlg , AddBtnHdl ) ) ;
m_pBtnRemove - > SetClickHdl ( LINK ( this , ScDbNameDlg , RemoveBtnHdl ) ) ;
m_pEdName - > SetModifyHdl ( LINK ( this , ScDbNameDlg , NameModifyHdl ) ) ;
m_pEdAssign - > SetModifyHdl ( LINK ( this , ScDbNameDlg , AssModifyHdl ) ) ;
2000-09-18 16:07:07 +00:00
UpdateNames ( ) ;
2013-10-07 14:26:21 +02:00
OUString theAreaStr ;
2010-11-24 23:17:13 -05:00
2000-09-18 16:07:07 +00:00
if ( pViewData & & pDoc )
{
2010-11-24 23:17:13 -05:00
SCCOL nStartCol = 0 ;
SCROW nStartRow = 0 ;
SCTAB nStartTab = 0 ;
SCCOL nEndCol = 0 ;
SCROW nEndRow = 0 ;
SCTAB nEndTab = 0 ;
2000-09-18 16:07:07 +00:00
ScDBCollection * pDBColl = pDoc - > GetDBCollection ( ) ;
ScDBData * pDBData = NULL ;
pViewData - > GetSimpleArea ( nStartCol , nStartRow , nStartTab ,
nEndCol , nEndRow , nEndTab ) ;
theCurArea = ScRange ( ScAddress ( nStartCol , nStartRow , nStartTab ) ,
ScAddress ( nEndCol , nEndRow , nEndTab ) ) ;
2013-08-29 20:44:22 +01:00
theAreaStr = theCurArea . Format ( ABS_DREF3D , pDoc , aAddrDetails ) ;
2000-09-18 16:07:07 +00:00
if ( pDBColl )
{
// Feststellen, ob definierter DB-Bereich markiert wurde:
2014-01-17 17:02:10 +02:00
pDBData = pDBColl - > GetDBAtCursor ( nStartCol , nStartRow , nStartTab , true ) ;
2000-09-18 16:07:07 +00:00
if ( pDBData )
{
ScAddress & rStart = theCurArea . aStart ;
ScAddress & rEnd = theCurArea . aEnd ;
2004-06-04 12:31:49 +00:00
SCCOL nCol1 ;
SCCOL nCol2 ;
SCROW nRow1 ;
SCROW nRow2 ;
SCTAB nTab ;
2000-09-18 16:07:07 +00:00
pDBData - > GetArea ( nTab , nCol1 , nRow1 , nCol2 , nRow2 ) ;
if ( ( rStart . Tab ( ) = = nTab )
& & ( rStart . Col ( ) = = nCol1 ) & & ( rStart . Row ( ) = = nRow1 )
& & ( rEnd . Col ( ) = = nCol2 ) & & ( rEnd . Row ( ) = = nRow2 ) )
{
2013-04-07 12:06:47 +02:00
OUString aDBName = pDBData - > GetName ( ) ;
2012-04-06 19:49:53 +02:00
if ( aDBName ! = STR_DB_LOCAL_NONAME )
2013-07-26 09:30:13 +01:00
m_pEdName - > SetText ( aDBName ) ;
2011-05-12 16:26:26 -04:00
2013-07-26 09:30:13 +01:00
m_pBtnHeader - > Check ( pDBData - > HasHeader ( ) ) ;
m_pBtnDoSize - > Check ( pDBData - > IsDoSize ( ) ) ;
m_pBtnKeepFmt - > Check ( pDBData - > IsKeepFmt ( ) ) ;
m_pBtnStripData - > Check ( pDBData - > IsStripData ( ) ) ;
2000-09-18 16:07:07 +00:00
SetInfoStrings ( pDBData ) ;
}
}
}
}
2013-07-26 09:30:13 +01:00
m_pEdAssign - > SetText ( theAreaStr ) ;
m_pEdName - > GrabFocus ( ) ;
2014-02-17 09:49:30 +02:00
bSaved = true ;
2000-09-18 16:07:07 +00:00
pSaveObj - > Save ( ) ;
NameModifyHdl ( 0 ) ;
}
void ScDbNameDlg : : SetInfoStrings ( const ScDBData * pDBData )
{
2013-04-07 12:06:47 +02:00
OUStringBuffer aBuf ;
2011-05-10 15:50:44 -04:00
aBuf . append ( aStrSource ) ;
2000-09-18 16:07:07 +00:00
if ( pDBData )
{
2013-11-13 15:03:52 +02:00
aBuf . append ( ' ' ) ;
2011-05-10 15:50:44 -04:00
aBuf . append ( pDBData - > GetSourceString ( ) ) ;
2000-09-18 16:07:07 +00:00
}
2013-07-26 09:30:13 +01:00
m_pFTSource - > SetText ( aBuf . makeStringAndClear ( ) ) ;
2000-09-18 16:07:07 +00:00
2011-05-10 15:50:44 -04:00
aBuf . append ( aStrOperations ) ;
2000-09-18 16:07:07 +00:00
if ( pDBData )
{
2013-11-13 15:03:52 +02:00
aBuf . append ( ' ' ) ;
2011-05-10 15:50:44 -04:00
aBuf . append ( pDBData - > GetOperations ( ) ) ;
2000-09-18 16:07:07 +00:00
}
2013-07-26 09:30:13 +01:00
m_pFTOperations - > SetText ( aBuf . makeStringAndClear ( ) ) ;
2000-09-18 16:07:07 +00:00
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
// Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
// neue Selektion im Referenz-Fenster angezeigt wird.
2007-02-27 12:02:23 +00:00
void ScDbNameDlg : : SetReference ( const ScRange & rRef , ScDocument * pDocP )
2000-09-18 16:07:07 +00:00
{
2013-07-26 09:30:13 +01:00
if ( m_pEdAssign - > IsEnabled ( ) )
2000-09-18 16:07:07 +00:00
{
if ( rRef . aStart ! = rRef . aEnd )
2013-07-26 09:30:13 +01:00
RefInputStart ( m_pEdAssign ) ;
2000-09-18 16:07:07 +00:00
theCurArea = rRef ;
2013-08-29 20:44:22 +01:00
OUString aRefStr ( theCurArea . Format ( ABS_DREF3D , pDocP , aAddrDetails ) ) ;
2013-07-26 09:30:13 +01:00
m_pEdAssign - > SetRefString ( aRefStr ) ;
m_pOptions - > Enable ( ) ;
m_pBtnAdd - > Enable ( ) ;
2014-02-17 09:49:30 +02:00
bSaved = true ;
2000-09-18 16:07:07 +00:00
pSaveObj - > Save ( ) ;
}
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
2014-02-21 12:53:51 +01:00
bool ScDbNameDlg : : Close ( )
2000-09-18 16:07:07 +00:00
{
return DoClose ( ScDbNameDlgWrapper : : GetChildWindowId ( ) ) ;
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
void ScDbNameDlg : : SetActive ( )
{
2013-07-26 09:30:13 +01:00
m_pEdAssign - > GrabFocus ( ) ;
2000-09-18 16:07:07 +00:00
// kein NameModifyHdl, weil sonst Bereiche nicht geaendert werden koennen
// (nach dem Aufziehen der Referenz wuerde der alte Inhalt wieder angezeigt)
// (der ausgewaehlte DB-Name hat sich auch nicht veraendert)
RefInputDone ( ) ;
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
void ScDbNameDlg : : UpdateNames ( )
{
2011-05-12 16:26:26 -04:00
typedef ScDBCollection : : NamedDBs DBsType ;
const DBsType & rDBs = aLocalDbCol . getNamedDBs ( ) ;
2000-09-18 16:07:07 +00:00
2013-07-26 09:30:13 +01:00
m_pEdName - > SetUpdateMode ( false ) ;
2014-02-22 21:20:15 +01:00
2013-07-26 09:30:13 +01:00
m_pEdName - > Clear ( ) ;
2013-10-16 14:27:58 +02:00
m_pEdAssign - > SetText ( EMPTY_OUSTRING ) ;
2000-09-18 16:07:07 +00:00
2011-05-12 16:26:26 -04:00
if ( ! rDBs . empty ( ) )
2000-09-18 16:07:07 +00:00
{
2011-05-12 16:26:26 -04:00
DBsType : : const_iterator itr = rDBs . begin ( ) , itrEnd = rDBs . end ( ) ;
for ( ; itr ! = itrEnd ; + + itr )
2013-07-26 09:30:13 +01:00
m_pEdName - > InsertEntry ( itr - > GetName ( ) ) ;
2000-09-18 16:07:07 +00:00
}
else
{
2013-07-26 09:30:13 +01:00
m_pBtnAdd - > SetText ( aStrAdd ) ;
m_pBtnAdd - > Disable ( ) ;
m_pBtnRemove - > Disable ( ) ;
2000-09-18 16:07:07 +00:00
}
2014-02-22 21:20:15 +01:00
2014-02-21 12:53:51 +01:00
m_pEdName - > SetUpdateMode ( true ) ;
2013-07-26 09:30:13 +01:00
m_pEdName - > Invalidate ( ) ;
2000-09-18 16:07:07 +00:00
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
2013-09-26 17:36:00 +02:00
void ScDbNameDlg : : UpdateDBData ( const OUString & rStrName )
2000-09-18 16:07:07 +00:00
{
2012-11-19 14:08:27 +01:00
const ScDBData * pData = aLocalDbCol . getNamedDBs ( ) . findByUpperName ( ScGlobal : : pCharClass - > uppercase ( rStrName ) ) ;
2000-09-18 16:07:07 +00:00
if ( pData )
{
2004-06-04 12:31:49 +00:00
SCCOL nColStart = 0 ;
SCROW nRowStart = 0 ;
SCCOL nColEnd = 0 ;
SCROW nRowEnd = 0 ;
SCTAB nTab = 0 ;
2000-09-18 16:07:07 +00:00
pData - > GetArea ( nTab , nColStart , nRowStart , nColEnd , nRowEnd ) ;
theCurArea = ScRange ( ScAddress ( nColStart , nRowStart , nTab ) ,
ScAddress ( nColEnd , nRowEnd , nTab ) ) ;
2013-08-29 20:44:22 +01:00
OUString theArea ( theCurArea . Format ( ABS_DREF3D , pDoc , aAddrDetails ) ) ;
2013-07-26 09:30:13 +01:00
m_pEdAssign - > SetText ( theArea ) ;
m_pBtnAdd - > SetText ( aStrModify ) ;
m_pBtnHeader - > Check ( pData - > HasHeader ( ) ) ;
m_pBtnDoSize - > Check ( pData - > IsDoSize ( ) ) ;
m_pBtnKeepFmt - > Check ( pData - > IsKeepFmt ( ) ) ;
m_pBtnStripData - > Check ( pData - > IsStripData ( ) ) ;
2000-09-18 16:07:07 +00:00
SetInfoStrings ( pData ) ;
}
2013-07-26 09:30:13 +01:00
m_pBtnAdd - > SetText ( aStrModify ) ;
m_pBtnAdd - > Enable ( ) ;
m_pBtnRemove - > Enable ( ) ;
m_pOptions - > Enable ( ) ;
2000-09-18 16:07:07 +00:00
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
2014-02-13 15:28:23 +02:00
bool ScDbNameDlg : : IsRefInputMode ( ) const
2000-09-18 16:07:07 +00:00
{
return bRefInputMode ;
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
// Handler:
2014-02-25 19:58:48 +01:00
2000-09-18 16:07:07 +00:00
2012-03-01 18:00:32 +01:00
IMPL_LINK_NOARG ( ScDbNameDlg , OkBtnHdl )
2000-09-18 16:07:07 +00:00
{
AddBtnHdl ( 0 ) ;
// Der View die Aenderungen und die Remove-Liste uebergeben:
// beide werden nur als Referenz uebergeben, so dass an dieser
// Stelle keine Speicherleichen entstehen koennen:
if ( pViewData )
pViewData - > GetView ( ) - >
NotifyCloseDbNameDlg ( aLocalDbCol , aRemoveList ) ;
Close ( ) ;
return 0 ;
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
2012-03-01 18:00:32 +01:00
IMPL_LINK_NOARG_INLINE_START ( ScDbNameDlg , CancelBtnHdl )
2000-09-18 16:07:07 +00:00
{
Close ( ) ;
return 0 ;
}
2012-03-01 18:00:32 +01:00
IMPL_LINK_NOARG_INLINE_END ( ScDbNameDlg , CancelBtnHdl )
2000-09-18 16:07:07 +00:00
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
2012-03-01 18:00:32 +01:00
IMPL_LINK_NOARG ( ScDbNameDlg , AddBtnHdl )
2000-09-18 16:07:07 +00:00
{
2013-10-07 14:26:21 +02:00
OUString aNewName = comphelper : : string : : strip ( m_pEdName - > GetText ( ) , ' ' ) ;
OUString aNewArea = m_pEdAssign - > GetText ( ) ;
2000-09-18 16:07:07 +00:00
2013-10-08 14:55:24 +02:00
if ( ! aNewName . isEmpty ( ) & & ! aNewArea . isEmpty ( ) )
2000-09-18 16:07:07 +00:00
{
2013-10-07 14:26:21 +02:00
if ( ScRangeData : : IsNameValid ( aNewName , pDoc ) & & ! aNewName . equalsAscii ( STR_DB_LOCAL_NONAME ) )
2000-09-18 16:07:07 +00:00
{
// weil jetzt editiert werden kann, muss erst geparst werden
ScRange aTmpRange ;
2013-10-07 14:26:21 +02:00
OUString aText = m_pEdAssign - > GetText ( ) ;
2008-05-14 08:54:42 +00:00
if ( aTmpRange . ParseAny ( aText , pDoc , aAddrDetails ) & SCA_VALID )
2000-09-18 16:07:07 +00:00
{
theCurArea = aTmpRange ;
ScAddress aStart = theCurArea . aStart ;
ScAddress aEnd = theCurArea . aEnd ;
2012-11-19 14:08:27 +01:00
ScDBData * pOldEntry = aLocalDbCol . getNamedDBs ( ) . findByUpperName ( ScGlobal : : pCharClass - > uppercase ( aNewName ) ) ;
2000-09-18 16:07:07 +00:00
if ( pOldEntry )
{
// Bereich veraendern
pOldEntry - > MoveTo ( aStart . Tab ( ) , aStart . Col ( ) , aStart . Row ( ) ,
aEnd . Col ( ) , aEnd . Row ( ) ) ;
2014-01-28 20:00:32 +01:00
pOldEntry - > SetByRow ( true ) ;
2013-07-26 09:30:13 +01:00
pOldEntry - > SetHeader ( m_pBtnHeader - > IsChecked ( ) ) ;
pOldEntry - > SetDoSize ( m_pBtnDoSize - > IsChecked ( ) ) ;
pOldEntry - > SetKeepFmt ( m_pBtnKeepFmt - > IsChecked ( ) ) ;
pOldEntry - > SetStripData ( m_pBtnStripData - > IsChecked ( ) ) ;
2000-09-18 16:07:07 +00:00
}
else
{
// neuen Bereich einfuegen
ScDBData * pNewEntry = new ScDBData ( aNewName , aStart . Tab ( ) ,
aStart . Col ( ) , aStart . Row ( ) ,
aEnd . Col ( ) , aEnd . Row ( ) ,
2014-01-28 20:00:32 +01:00
true , m_pBtnHeader - > IsChecked ( ) ) ;
2013-07-26 09:30:13 +01:00
pNewEntry - > SetDoSize ( m_pBtnDoSize - > IsChecked ( ) ) ;
pNewEntry - > SetKeepFmt ( m_pBtnKeepFmt - > IsChecked ( ) ) ;
pNewEntry - > SetStripData ( m_pBtnStripData - > IsChecked ( ) ) ;
2000-09-18 16:07:07 +00:00
coverity#1158232 Fix ownership of NamedDBs::insert argument
f70d03436b7b501e0ed1d745935a204b9b97b855 "coverity#1158232 have a stab at
silencing warning with function markup" claimed that NamedDBs::insert always
takes ownerhip of its argument, but boost::ptr_set::insert(std::auto_ptr<U> x)
simply calls insert(x.release()), so only takes ownership when it returns true.
ScDBDocFunc::AddDBRange (sc/source/ui/docshell/dbdocfun.cxx) relies on this
behavior, deleting the argument when insert failed.
ScDBDocFunc::RenameDBRange (sc/source/ui/docshell/dbdocfun.cxx) relied on this
behavior, deleting the argument when insert failed, until
f55cc330dec0dec60c755e2ce28a840c7fca1956 "Fixed the fallout of the changes in
ScDBCollection" removed the delete (presumably in error?). I put it back in
now.
All other uses of NamedDBs::insert ignored the return value (witnessed with
SAL_WARN_UNUSED_RESULT). Some are insert-if-not-found cases, where I added
asserts now (Sc10Import::LoadDataBaseCollection,
sc/source/filter/starcalc/scflt.cxx, is not entirely clear to me, so I added a
TODO), while others would have potentially leaked the argument, in which cases I
fixed the code.
Change-Id: Iad40fbeb625c8ce6b0a61cbf16298d71cdc7de80
2014-03-12 16:05:37 +01:00
bool ins = aLocalDbCol . getNamedDBs ( ) . insert ( pNewEntry ) ;
assert ( ins ) ; ( void ) ins ;
2000-09-18 16:07:07 +00:00
}
UpdateNames ( ) ;
2013-10-16 14:27:58 +02:00
m_pEdName - > SetText ( EMPTY_OUSTRING ) ;
2013-07-26 09:30:13 +01:00
m_pEdName - > GrabFocus ( ) ;
m_pBtnAdd - > SetText ( aStrAdd ) ;
m_pBtnAdd - > Disable ( ) ;
m_pBtnRemove - > Disable ( ) ;
2013-10-16 14:27:58 +02:00
m_pEdAssign - > SetText ( EMPTY_OUSTRING ) ;
2014-02-21 12:53:51 +01:00
m_pBtnHeader - > Check ( true ) ; // Default: mit Spaltenkoepfen
2013-07-26 09:30:13 +01:00
m_pBtnDoSize - > Check ( false ) ;
m_pBtnKeepFmt - > Check ( false ) ;
m_pBtnStripData - > Check ( false ) ;
2000-09-18 16:07:07 +00:00
SetInfoStrings ( NULL ) ; // leer
theCurArea = ScRange ( ) ;
2014-02-17 09:49:30 +02:00
bSaved = true ;
2000-09-18 16:07:07 +00:00
pSaveObj - > Save ( ) ;
NameModifyHdl ( 0 ) ;
}
else
{
ERRORBOX ( aStrInvalid ) ;
2013-07-26 09:30:13 +01:00
m_pEdAssign - > SetSelection ( Selection ( 0 , SELECTION_MAX ) ) ;
m_pEdAssign - > GrabFocus ( ) ;
2000-09-18 16:07:07 +00:00
}
}
else
{
ERRORBOX ( ScGlobal : : GetRscString ( STR_INVALIDNAME ) ) ;
2013-07-26 09:30:13 +01:00
m_pEdName - > SetSelection ( Selection ( 0 , SELECTION_MAX ) ) ;
m_pEdName - > GrabFocus ( ) ;
2000-09-18 16:07:07 +00:00
}
}
return 0 ;
}
2011-05-12 16:26:26 -04:00
namespace {
class FindByName : public : : std : : unary_function < ScDBData , bool >
{
2013-04-07 12:06:47 +02:00
const OUString & mrName ;
2011-05-12 16:26:26 -04:00
public :
2013-04-07 12:06:47 +02:00
FindByName ( const OUString & rName ) : mrName ( rName ) { }
2011-05-12 16:26:26 -04:00
bool operator ( ) ( const ScDBData & r ) const
{
return r . GetName ( ) . equals ( mrName ) ;
}
} ;
}
2000-09-18 16:07:07 +00:00
2012-03-01 18:00:32 +01:00
IMPL_LINK_NOARG ( ScDbNameDlg , RemoveBtnHdl )
2000-09-18 16:07:07 +00:00
{
2013-07-26 09:30:13 +01:00
OUString aStrEntry = m_pEdName - > GetText ( ) ;
2011-05-12 16:26:26 -04:00
ScDBCollection : : NamedDBs & rDBs = aLocalDbCol . getNamedDBs ( ) ;
ScDBCollection : : NamedDBs : : iterator itr =
: : std : : find_if ( rDBs . begin ( ) , rDBs . end ( ) , FindByName ( aStrEntry ) ) ;
2000-09-18 16:07:07 +00:00
2011-05-12 16:26:26 -04:00
if ( itr ! = rDBs . end ( ) )
2000-09-18 16:07:07 +00:00
{
2013-10-07 14:26:21 +02:00
OUString aStrDelMsg = ScGlobal : : GetRscString ( STR_QUERY_DELENTRY ) ;
2000-09-18 16:07:07 +00:00
2013-04-07 12:06:47 +02:00
OUStringBuffer aBuf ;
2013-10-07 14:26:21 +02:00
aBuf . append ( aStrDelMsg . getToken ( 0 , ' # ' ) ) ;
2011-05-12 16:26:26 -04:00
aBuf . append ( aStrEntry ) ;
2013-10-07 14:26:21 +02:00
aBuf . append ( aStrDelMsg . getToken ( 1 , ' # ' ) ) ;
2011-05-12 16:26:26 -04:00
QueryBox aBox ( this , WinBits ( WB_YES_NO | WB_DEF_YES ) , aBuf . makeStringAndClear ( ) ) ;
2000-09-18 16:07:07 +00:00
2011-05-12 16:26:26 -04:00
if ( RET_YES = = aBox . Execute ( ) )
2000-09-18 16:07:07 +00:00
{
2011-05-12 16:26:26 -04:00
SCTAB nTab ;
SCCOL nColStart , nColEnd ;
SCROW nRowStart , nRowEnd ;
itr - > GetArea ( nTab , nColStart , nRowStart , nColEnd , nRowEnd ) ;
2011-06-02 11:49:54 -04:30
aRemoveList . push_back (
ScRange ( ScAddress ( nColStart , nRowStart , nTab ) ,
ScAddress ( nColEnd , nRowEnd , nTab ) ) ) ;
2011-05-12 16:26:26 -04:00
rDBs . erase ( itr ) ;
2000-09-18 16:07:07 +00:00
UpdateNames ( ) ;
2013-10-16 14:27:58 +02:00
m_pEdName - > SetText ( EMPTY_OUSTRING ) ;
2013-07-26 09:30:13 +01:00
m_pEdName - > GrabFocus ( ) ;
m_pBtnAdd - > SetText ( aStrAdd ) ;
m_pBtnAdd - > Disable ( ) ;
m_pBtnRemove - > Disable ( ) ;
2013-10-16 14:27:58 +02:00
m_pEdAssign - > SetText ( EMPTY_OUSTRING ) ;
2000-09-18 16:07:07 +00:00
theCurArea = ScRange ( ) ;
2014-02-21 12:53:51 +01:00
m_pBtnHeader - > Check ( true ) ; // Default: mit Spaltenkoepfen
2013-07-26 09:30:13 +01:00
m_pBtnDoSize - > Check ( false ) ;
m_pBtnKeepFmt - > Check ( false ) ;
m_pBtnStripData - > Check ( false ) ;
2000-09-18 16:07:07 +00:00
SetInfoStrings ( NULL ) ; // leer
2011-03-10 16:55:21 -05:00
bSaved = false ;
2000-09-18 16:07:07 +00:00
pSaveObj - > Restore ( ) ;
NameModifyHdl ( 0 ) ;
}
}
return 0 ;
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
2012-03-01 18:00:32 +01:00
IMPL_LINK_NOARG ( ScDbNameDlg , NameModifyHdl )
2000-09-18 16:07:07 +00:00
{
2013-07-26 09:30:13 +01:00
OUString theName = m_pEdName - > GetText ( ) ;
2011-01-17 13:20:22 +01:00
sal_Bool bNameFound = ( COMBOBOX_ENTRY_NOTFOUND
2013-07-26 09:30:13 +01:00
! = m_pEdName - > GetEntryPos ( theName ) ) ;
2000-09-18 16:07:07 +00:00
2013-01-21 14:32:09 +01:00
if ( theName . isEmpty ( ) )
2000-09-18 16:07:07 +00:00
{
2013-07-26 09:30:13 +01:00
if ( m_pBtnAdd - > GetText ( ) ! = aStrAdd )
m_pBtnAdd - > SetText ( aStrAdd ) ;
m_pBtnAdd - > Disable ( ) ;
m_pBtnRemove - > Disable ( ) ;
m_pAssignFrame - > Disable ( ) ;
m_pOptions - > Disable ( ) ;
2011-01-17 13:20:22 +01:00
//bSaved=sal_False;
2000-09-18 16:07:07 +00:00
//pSaveObj->Restore();
//@BugID 54702 Enablen/Disablen nur noch in Basisklasse
2011-01-17 13:20:22 +01:00
//SFX_APPWINDOW->Disable(sal_False); //! allgemeine Methode im ScAnyRefDlg
2011-03-10 16:55:21 -05:00
bRefInputMode = false ;
2000-09-18 16:07:07 +00:00
}
else
{
if ( bNameFound )
{
2013-07-26 09:30:13 +01:00
if ( m_pBtnAdd - > GetText ( ) ! = aStrModify )
m_pBtnAdd - > SetText ( aStrModify ) ;
2000-09-18 16:07:07 +00:00
if ( ! bSaved )
{
2014-02-17 09:49:30 +02:00
bSaved = true ;
2000-09-18 16:07:07 +00:00
pSaveObj - > Save ( ) ;
}
UpdateDBData ( theName ) ;
}
else
{
2013-07-26 09:30:13 +01:00
if ( m_pBtnAdd - > GetText ( ) ! = aStrAdd )
m_pBtnAdd - > SetText ( aStrAdd ) ;
2000-09-18 16:07:07 +00:00
2011-03-10 16:55:21 -05:00
bSaved = false ;
2000-09-18 16:07:07 +00:00
pSaveObj - > Restore ( ) ;
2013-07-26 09:30:13 +01:00
if ( ! m_pEdAssign - > GetText ( ) . isEmpty ( ) )
2000-09-18 16:07:07 +00:00
{
2013-07-26 09:30:13 +01:00
m_pBtnAdd - > Enable ( ) ;
m_pOptions - > Enable ( ) ;
2000-09-18 16:07:07 +00:00
}
else
{
2013-07-26 09:30:13 +01:00
m_pBtnAdd - > Disable ( ) ;
m_pOptions - > Disable ( ) ;
2000-09-18 16:07:07 +00:00
}
2013-07-26 09:30:13 +01:00
m_pBtnRemove - > Disable ( ) ;
2000-09-18 16:07:07 +00:00
}
2013-07-26 09:30:13 +01:00
m_pAssignFrame - > Enable ( ) ;
2000-09-18 16:07:07 +00:00
//@BugID 54702 Enablen/Disablen nur noch in Basisklasse
//SFX_APPWINDOW->Enable();
2011-08-29 22:49:51 -04:00
bRefInputMode = true ;
2000-09-18 16:07:07 +00:00
}
return 0 ;
}
2014-02-22 21:20:15 +01:00
2000-09-18 16:07:07 +00:00
2012-03-01 18:00:32 +01:00
IMPL_LINK_NOARG ( ScDbNameDlg , AssModifyHdl )
2000-09-18 16:07:07 +00:00
{
// hier parsen fuer Save() etc.
ScRange aTmpRange ;
2013-10-07 14:26:21 +02:00
OUString aText = m_pEdAssign - > GetText ( ) ;
2008-05-14 08:54:42 +00:00
if ( aTmpRange . ParseAny ( aText , pDoc , aAddrDetails ) & SCA_VALID )
2000-09-18 16:07:07 +00:00
theCurArea = aTmpRange ;
2013-12-02 15:54:29 +00:00
if ( ! aText . isEmpty ( ) & & ! m_pEdName - > GetText ( ) . isEmpty ( ) )
{
m_pBtnAdd - > Enable ( ) ;
m_pBtnHeader - > Enable ( ) ;
m_pBtnDoSize - > Enable ( ) ;
m_pBtnKeepFmt - > Enable ( ) ;
m_pBtnStripData - > Enable ( ) ;
m_pFTSource - > Enable ( ) ;
m_pFTOperations - > Enable ( ) ;
}
else
{
m_pBtnAdd - > Disable ( ) ;
m_pBtnHeader - > Disable ( ) ;
m_pBtnDoSize - > Disable ( ) ;
m_pBtnKeepFmt - > Disable ( ) ;
m_pBtnStripData - > Disable ( ) ;
m_pFTSource - > Disable ( ) ;
m_pFTOperations - > Disable ( ) ;
}
2000-09-18 16:07:07 +00:00
return 0 ;
}
2013-12-02 15:54:29 +00:00
IMPL_LINK ( ScDbNameDlg , FocusToComoboxHdl , Timer * , pTi )
{
( void ) pTi ;
// CallEventListeners is still protected - figure out if we need to make it public, or if the focus stuff can be handled better in VCL directly. First see what AT is expecting...
// aEdName.CallEventListeners( VCLEVENT_CONTROL_GETFOCUS );
return 0 ;
}
2000-09-18 16:07:07 +00:00
2010-10-12 15:59:00 +02:00
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */