summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-11-18 03:08:28 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-11-23 06:25:31 +0100
commit411d95598f4e5acd0d8cb16b5db1edf57a20469d (patch)
tree5ba40c90ed1e529dacb9a89a3abdd2dd691a6aab /sc
parent7f8deb4f90b129183778f977da2d22a147b5eb3f (diff)
Manage Names: add most logic to Define Name dialog
missing are: -undo -range options -help -test for correct expression is not working
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/document.hxx1
-rw-r--r--sc/inc/globalnames.hxx2
-rw-r--r--sc/inc/rangenam.hxx6
-rw-r--r--sc/inc/scabstdlg.hxx3
-rw-r--r--sc/source/core/data/documen3.cxx12
-rw-r--r--sc/source/ui/attrdlg/scdlgfact.cxx4
-rw-r--r--sc/source/ui/attrdlg/scdlgfact.hxx3
-rw-r--r--sc/source/ui/inc/namedefdlg.hrc3
-rw-r--r--sc/source/ui/inc/namedefdlg.hxx22
-rw-r--r--sc/source/ui/namedlg/namedefdlg.cxx146
-rw-r--r--sc/source/ui/src/namedefdlg.src13
-rw-r--r--sc/source/ui/view/cellsh1.cxx5
-rw-r--r--sc/source/ui/view/editsh.cxx5
13 files changed, 211 insertions, 14 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 02cc60d7ff71..3095f0c6cd36 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -467,6 +467,7 @@ public:
SC_DLLPUBLIC void GetAllTabRangeNames(ScRangeName::TabNameCopyMap& rRangeNames) const;
SC_DLLPUBLIC void SetAllTabRangeNames(const ScRangeName::TabNameCopyMap& rRangeNames);
void GetTabRangeNameMap(std::map<rtl::OUString, ScRangeName*>& rRangeName);
+ void GetRangeNameMap(std::map<rtl::OUString, ScRangeName*>& rRangeName);
SC_DLLPUBLIC ScRangeName* GetRangeName(SCTAB nTab) const;
SC_DLLPUBLIC ScRangeName* GetRangeName() const;
void SetRangeName(SCTAB nTab, ScRangeName* pNew);
diff --git a/sc/inc/globalnames.hxx b/sc/inc/globalnames.hxx
index a36fa5b93f12..33ac520c8a5f 100644
--- a/sc/inc/globalnames.hxx
+++ b/sc/inc/globalnames.hxx
@@ -32,6 +32,8 @@
#define STR_DB_LOCAL_NONAME "__Anonymous_Sheet_DB__"
#define STR_DB_GLOBAL_NONAME "__Anonymous_DB__"
+#define STR_GLOBAL_RANGE_NAME "__Global_Range_Name__"
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/rangenam.hxx b/sc/inc/rangenam.hxx
index 32d31ff0e0b2..04a77c422811 100644
--- a/sc/inc/rangenam.hxx
+++ b/sc/inc/rangenam.hxx
@@ -124,7 +124,7 @@ public:
sal_uInt16 GetIndex() const { return nIndex; }
ScTokenArray* GetCode() { return pCode; }
const ScTokenArray* GetCode() const { return pCode; }
- sal_uInt16 GetErrCode() const;
+ SC_DLLPUBLIC sal_uInt16 GetErrCode() const;
bool HasReferences() const;
void SetDocument( ScDocument* pDocument){ pDoc = pDocument; }
ScDocument* GetDocument() const { return pDoc; }
@@ -204,8 +204,8 @@ public:
SC_DLLPUBLIC const ScRangeData* findByRange(const ScRange& rRange) const;
SC_DLLPUBLIC ScRangeData* findByName(const rtl::OUString& rName);
SC_DLLPUBLIC const ScRangeData* findByName(const rtl::OUString& rName) const;
- ScRangeData* findByUpperName(const rtl::OUString& rName);
- const ScRangeData* findByUpperName(const rtl::OUString& rName) const;
+ SC_DLLPUBLIC ScRangeData* findByUpperName(const rtl::OUString& rName);
+ SC_DLLPUBLIC const ScRangeData* findByUpperName(const rtl::OUString& rName) const;
SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i);
void UpdateReference(UpdateRefMode eUpdateRefMode, const ScRange& rRange,
SCsCOL nDx, SCsROW nDy, SCsTAB nDz);
diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx
index c62a2eb80484..ecb6fe610915 100644
--- a/sc/inc/scabstdlg.hxx
+++ b/sc/inc/scabstdlg.hxx
@@ -424,7 +424,8 @@ public:
virtual AbstractScNamePasteDlg * CreateScNamePasteDlg ( Window * pParent, const ScRangeName* pList, //add for ScNamePasteDlg
const ScRangeName* pLocalList, int nId , bool bInsList=true ) = 0;
- virtual AbstractScNameAddDlg* CreateScNameAddDlg ( Window* pParent, ScDocument* pDoc, int nId) = 0;
+ virtual AbstractScNameAddDlg* CreateScNameAddDlg ( Window* pParent, ScDocument* pDoc, std::map<rtl::OUString, ScRangeName*> aRangeMap,
+ const ScAddress& aCursorPos, const bool bUndo, int nId) = 0;
virtual AbstractScPivotFilterDlg * CreateScPivotFilterDlg ( Window* pParent, //add for ScPivotFilterDlg
const SfxItemSet& rArgSet, sal_uInt16 nSourceTab , int nId ) = 0;
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 273af5f20815..1aabd9f7dd6a 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -85,6 +85,7 @@
#include "sheetevents.hxx"
#include "queryentry.hxx"
+#include "globalnames.hxx"
#include <memory>
using namespace com::sun::star;
@@ -143,6 +144,17 @@ void ScDocument::GetTabRangeNameMap(std::map<rtl::OUString, ScRangeName*>& aRang
}
}
+void ScDocument::GetRangeNameMap(std::map<rtl::OUString, ScRangeName*>& aRangeNameMap)
+{
+ GetTabRangeNameMap(aRangeNameMap);
+ if (!pRangeName)
+ {
+ pRangeName = new ScRangeName();
+ }
+ rtl::OUString aGlobal(RTL_CONSTASCII_USTRINGPARAM(STR_GLOBAL_RANGE_NAME));
+ aRangeNameMap.insert(std::pair<rtl::OUString, ScRangeName*>(aGlobal, pRangeName));
+}
+
ScRangeName* ScDocument::GetRangeName(SCTAB nTab) const
{
if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || !maTabs[nTab])
diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx
index b0052cc806dd..bcfee55a5416 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -1152,13 +1152,13 @@ AbstractScNamePasteDlg * ScAbstractDialogFactory_Impl::CreateScNamePasteDlg ( Wi
}
-AbstractScNameAddDlg* ScAbstractDialogFactory_Impl::CreateScNameAddDlg( Window* pParent, ScDocument* pDoc, int nId)
+AbstractScNameAddDlg* ScAbstractDialogFactory_Impl::CreateScNameAddDlg( Window* pParent, ScDocument* pDoc, std::map<rtl::OUString, ScRangeName*> aRangeMap, const ScAddress& aCursorPos, const bool bUndo, int nId)
{
ScNameDefDlg* pDlg = NULL;
switch ( nId )
{
case RID_SCDLG_NAMES_DEFINE :
- pDlg = new ScNameDefDlg( pParent, pDoc );
+ pDlg = new ScNameDefDlg( pParent, pDoc, aRangeMap, aCursorPos, bUndo );
break;
default:
break;
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx
index 66fd48064f8c..59ef68e08a31 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -492,7 +492,8 @@ public:
virtual AbstractScNamePasteDlg * CreateScNamePasteDlg ( Window * pParent, const ScRangeName* pList, //add for ScNamePasteDlg
const ScRangeName* pLocalList, int nId , bool bInsList=true );
- virtual AbstractScNameAddDlg* CreateScNameAddDlg ( Window* pParent, ScDocument* pDoc, int nId);
+ virtual AbstractScNameAddDlg* CreateScNameAddDlg ( Window* pParent, ScDocument* pDoc, std::map<rtl::OUString, ScRangeName*> aRangeMap,
+ const ScAddress& aCursorPos, const bool bUndo, int nId);
virtual AbstractScPivotFilterDlg * CreateScPivotFilterDlg ( Window* pParent, //add for ScPivotFilterDlg
const SfxItemSet& rArgSet, sal_uInt16 nSourceTab , int nId );
diff --git a/sc/source/ui/inc/namedefdlg.hrc b/sc/source/ui/inc/namedefdlg.hrc
index e87ef62bdd5c..864d689f2824 100644
--- a/sc/source/ui/inc/namedefdlg.hrc
+++ b/sc/source/ui/inc/namedefdlg.hrc
@@ -15,3 +15,6 @@
#define BTN_COLHEADER 13
#define STR_GLOBAL_SCOPE 14
#define FL_DIV 15
+#define STR_INVALIDSYMBOL 16
+#define STR_ERR_NAME_EXISTS 17
+#define STR_ERR_NAME_INVALID 18
diff --git a/sc/source/ui/inc/namedefdlg.hxx b/sc/source/ui/inc/namedefdlg.hxx
index 52af90620020..2ab03b18997b 100644
--- a/sc/source/ui/inc/namedefdlg.hxx
+++ b/sc/source/ui/inc/namedefdlg.hxx
@@ -33,6 +33,9 @@
#include <vcl/edit.hxx>
#include <vcl/lstbox.hxx>
+#include <map>
+
+class ScRangeName;
class ScDocument;
class ScNameDefDlg : public ModalDialog
@@ -51,13 +54,30 @@ private:
ListBox maLbScope;
+ CheckBox maBtnRowHeader;
+ CheckBox maBtnColHeader;
+ CheckBox maBtnPrintArea;
+ CheckBox maBtnCriteria;
+
+
+ bool mbUndo; //if true we need to add an undo action after creating a range name
+ ScDocument* mpDoc;
+
+ ScAddress maCursorPos;
rtl::OUString maGlobalNameStr;
+ std::map<rtl::OUString, ScRangeName*> maRangeMap;
+
void CancelPushed();
+ void AddPushed();
+
+ bool IsNameValid();
DECL_LINK( CancelBtnHdl, void * );
+ DECL_LINK( AddBtnHdl, void* );
+ DECL_LINK( NameModifyHdl, void* );
public:
- ScNameDefDlg(Window* pParent, ScDocument* pDoc);
+ ScNameDefDlg(Window* pParent, ScDocument* pDoc, std::map<rtl::OUString, ScRangeName*> aRangeMap, const ScAddress& aCursorPos, const bool bUndo);
};
diff --git a/sc/source/ui/namedlg/namedefdlg.cxx b/sc/source/ui/namedlg/namedefdlg.cxx
index 32c331839d3c..bc7d9fac087b 100644
--- a/sc/source/ui/namedlg/namedefdlg.cxx
+++ b/sc/source/ui/namedlg/namedefdlg.cxx
@@ -1,9 +1,15 @@
#include "namedefdlg.hxx"
+#include <vcl/msgbox.hxx>
+#include <sfx2/app.hxx>
+
#include "document.hxx"
+#include "globalnames.hxx"
+#include "rangenam.hxx"
+
-ScNameDefDlg::ScNameDefDlg( Window* pParent, ScDocument* pDoc ) :
+ScNameDefDlg::ScNameDefDlg( Window* pParent, ScDocument* pDoc, std::map<rtl::OUString, ScRangeName*> aRangeMap, const ScAddress& aCursorPos, const bool bUndo ) :
ModalDialog( pParent, ScResId( RID_SCDLG_NAMES_DEFINE) ),
maBtnAdd( this, ScResId( BTN_ADD ) ),
maBtnCancel( this, ScResId( BTN_CANCEL ) ),
@@ -15,7 +21,15 @@ ScNameDefDlg::ScNameDefDlg( Window* pParent, ScDocument* pDoc ) :
maEdName( this, ScResId( ED_NAME ) ),
maEdRange( this, ScResId( ED_RANGE ) ),
maLbScope( this, ScResId( LB_SCOPE ) ),
- maGlobalNameStr( ResId::toString( ScResId( STR_GLOBAL_SCOPE ) ) )
+ maBtnRowHeader( this, ScResId( BTN_ROWHEADER ) ),
+ maBtnColHeader( this, ScResId( BTN_COLHEADER ) ),
+ maBtnPrintArea( this, ScResId( BTN_PRINTAREA ) ),
+ maBtnCriteria( this, ScResId( BTN_CRITERIA ) ),
+ mbUndo( bUndo ),
+ mpDoc( pDoc ),
+ maCursorPos( aCursorPos ),
+ maGlobalNameStr( ResId::toString( ScResId( STR_GLOBAL_SCOPE ) ) ),
+ maRangeMap( aRangeMap )
{
// Initialize scope list.
maLbScope.InsertEntry(maGlobalNameStr);
@@ -27,7 +41,11 @@ ScNameDefDlg::ScNameDefDlg( Window* pParent, ScDocument* pDoc ) :
pDoc->GetName(i, aTabName);
maLbScope.InsertEntry(aTabName);
}
- maBtnCancel.SetClickHdl(LINK( this, ScNameDefDlg, CancelBtnHdl));
+ maBtnCancel.SetClickHdl( LINK( this, ScNameDefDlg, CancelBtnHdl));
+ maBtnAdd.SetClickHdl( LINK( this, ScNameDefDlg, AddBtnHdl ));
+ maEdName.SetModifyHdl( LINK( this, ScNameDefDlg, NameModifyHdl ));
+
+ maBtnAdd.Disable(); // empty name is invalid
}
void ScNameDefDlg::CancelPushed()
@@ -35,8 +53,130 @@ void ScNameDefDlg::CancelPushed()
Close();
}
+bool ScNameDefDlg::IsNameValid()
+{
+ rtl::OUString aScope = maLbScope.GetSelectEntry();
+ rtl::OUString aName = maEdName.GetText();
+
+ ScRangeName* pRangeName = NULL;
+ if(aScope == maGlobalNameStr)
+ {
+ pRangeName = maRangeMap.find(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_GLOBAL_RANGE_NAME)))->second;
+ }
+ else
+ {
+ pRangeName = maRangeMap.find(aScope)->second;
+ }
+
+ if (!ScRangeData::IsNameValid( aName, mpDoc ))
+ {
+ maFtInfo.SetText(ResId::toString(ScResId( STR_ERR_NAME_INVALID )));
+ maBtnAdd.Disable();
+ return false;
+ }
+ else if (pRangeName->findByUpperName(ScGlobal::pCharClass->upper(aName)))
+ {
+ maFtInfo.SetText(ResId::toString(ScResId( STR_ERR_NAME_EXISTS )));
+ maBtnAdd.Disable();
+ return false;
+ }
+ maBtnAdd.Enable();
+ return true;
+}
+
+void ScNameDefDlg::AddPushed()
+{
+ rtl::OUString aScope = maLbScope.GetSelectEntry();
+ rtl::OUString aName = maEdName.GetText();
+ rtl::OUString aExpression = maEdRange.GetText();
+
+ if (!aName.getLength())
+ {
+ return;
+ }
+ if (!aScope.getLength())
+ {
+ return;
+ }
+
+ ScRangeName* pRangeName = NULL;
+ if(aScope == maGlobalNameStr)
+ {
+ pRangeName = maRangeMap.find(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STR_GLOBAL_RANGE_NAME)))->second;
+ }
+ else
+ {
+ pRangeName = maRangeMap.find(aScope)->second;
+ }
+ if (!pRangeName)
+ return;
+
+ if (!IsNameValid()) //should not happen, but make sure we don't break anything
+ return;
+ else
+ {
+ if ( mpDoc )
+ {
+ ScRangeData* pNewEntry = NULL;
+ RangeType nType = RT_NAME;
+
+ pNewEntry = new ScRangeData( mpDoc,
+ aName,
+ aExpression,
+ maCursorPos,
+ nType );
+ if (pNewEntry)
+ {
+ nType = nType
+ | (maBtnRowHeader .IsChecked() ? RT_ROWHEADER : RangeType(0))
+ | (maBtnColHeader .IsChecked() ? RT_COLHEADER : RangeType(0))
+ | (maBtnPrintArea .IsChecked() ? RT_PRINTAREA : RangeType(0))
+ | (maBtnCriteria .IsChecked() ? RT_CRITERIA : RangeType(0));
+ pNewEntry->AddType(nType);
+ }
+
+ // aExpression valid?
+ if ( 0 == pNewEntry->GetErrCode() )
+ {
+ if ( !pRangeName->insert( pNewEntry ) )
+ pNewEntry = NULL;
+
+ if (mbUndo)
+ {
+ //this means we called directly through the menu
+ //add a new ScUndoInsertName entry to undo
+ //
+ //TODO:FIXME need to add the undo code here
+ }
+ }
+ else
+ {
+ delete pNewEntry;
+ ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),ResId::toString(ScResId(STR_INVALIDSYMBOL))).Execute();
+ Selection aCurSel = Selection( 0, SELECTION_MAX );
+ maEdRange.GrabFocus();
+ maEdRange.SetSelection( aCurSel );
+ }
+ }
+ }
+ SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
+ Close();
+}
+
IMPL_LINK( ScNameDefDlg, CancelBtnHdl, void*, EMPTYARG)
{
CancelPushed();
return 0;
}
+
+IMPL_LINK( ScNameDefDlg, AddBtnHdl, void*, EMPTYARG)
+{
+ AddPushed();
+ return 0;
+};
+
+IMPL_LINK( ScNameDefDlg, NameModifyHdl, void*, EMPTYARG)
+{
+ IsNameValid();
+ return 0;
+}
diff --git a/sc/source/ui/src/namedefdlg.src b/sc/source/ui/src/namedefdlg.src
index 26ce3425be9e..4519c3747ca2 100644
--- a/sc/source/ui/src/namedefdlg.src
+++ b/sc/source/ui/src/namedefdlg.src
@@ -113,6 +113,17 @@ ModalDialog RID_SCDLG_NAMES_DEFINE
{
Text [ en-US ] = "Document (Global)" ;
};
-
+ String STR_INVALIDSYMBOL
+ {
+ Text [ en-US ] = "Invalid expression" ;
+ };
+ String STR_ERR_NAME_EXISTS
+ {
+ Text [ en-US ] = "Invalid name. Already in use for the selected scope.";
+ };
+ String STR_ERR_NAME_INVALID
+ {
+ Text [ en-US ] = "Invalid name. Only use letters, numbers and underscore and don't use names like cell addresses";
+ };
};
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 15ff79084aa3..c5939759d069 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -1844,7 +1844,10 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
std::cout << "Create Dialog in cellsh1.cxx" << std::endl;
ScDocument* pDoc = GetViewData()->GetDocument();
- AbstractScNameAddDlg* pDlg = pFact->CreateScNameAddDlg( pTabViewShell->GetDialogParent(), pDoc, RID_SCDLG_NAMES_DEFINE );
+ std::map<rtl::OUString, ScRangeName*> aRangeMap;
+ pDoc->GetRangeNameMap(aRangeMap);
+ ScAddress aPos( GetViewData()->GetCurX(), GetViewData()->GetCurY(), GetViewData()->GetTabNo() );
+ AbstractScNameAddDlg* pDlg = pFact->CreateScNameAddDlg( pTabViewShell->GetDialogParent(), pDoc, aRangeMap, aPos, true, RID_SCDLG_NAMES_DEFINE );
pDlg->Execute();
delete pDlg;
}
diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx
index 5146ab7eb502..61a36a71e70b 100644
--- a/sc/source/ui/view/editsh.cxx
+++ b/sc/source/ui/view/editsh.cxx
@@ -456,7 +456,10 @@ void ScEditShell::Execute( SfxRequest& rReq )
ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
ScDocument* pDoc = pViewData->GetDocument();
- AbstractScNameAddDlg* pDlg = pFact->CreateScNameAddDlg( pViewData->GetDialogParent(), pDoc, RID_SCDLG_NAMES_DEFINE );
+ std::map<rtl::OUString, ScRangeName*> aRangeMap;
+ pDoc->GetRangeNameMap(aRangeMap);
+ ScAddress aPos( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() );
+ AbstractScNameAddDlg* pDlg = pFact->CreateScNameAddDlg( pViewData->GetDialogParent(), pDoc, aRangeMap, aPos, true, RID_SCDLG_NAMES_DEFINE );
pDlg->Execute();
delete pDlg;
}