summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-12-03 18:42:04 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2011-12-03 20:15:01 +0100
commit3b0d01a8cb6f9230db400c92a59bf805bcd5bc05 (patch)
treeaa1bf43fb02a86c8a1dd64e616969d1349fe434c
parentc8fd64a7d909036c4b701d3aaee11b37f378bcce (diff)
ManageNames: make the add button usable
the concept is not perfect and the code looks ugly but we have no way at the moment to open two Refdialogs at the same time REVERT this hack as soon as this is possible!
-rw-r--r--sc/source/ui/inc/namedefdlg.hxx6
-rw-r--r--sc/source/ui/inc/namedlg.hxx7
-rw-r--r--sc/source/ui/inc/tabvwsh.hxx12
-rw-r--r--sc/source/ui/namedlg/namedefdlg.cxx26
-rw-r--r--sc/source/ui/namedlg/namedlg.cxx48
-rw-r--r--sc/source/ui/view/tabvwsh4.cxx3
-rw-r--r--sc/source/ui/view/tabvwshc.cxx83
7 files changed, 157 insertions, 28 deletions
diff --git a/sc/source/ui/inc/namedefdlg.hxx b/sc/source/ui/inc/namedefdlg.hxx
index c08de891cee4..ddccd3707ab9 100644
--- a/sc/source/ui/inc/namedefdlg.hxx
+++ b/sc/source/ui/inc/namedefdlg.hxx
@@ -75,6 +75,10 @@ private:
const rtl::OUString maErrNameInUse;
const rtl::OUString maStrInfoDefault;
+ //hack to call this dialog from Manage Names
+ rtl::OUString maName;
+ rtl::OUString maScope;
+
std::map<rtl::OUString, ScRangeName*> maRangeMap;
void CancelPushed();
@@ -106,6 +110,8 @@ public:
virtual void SetActive();
virtual sal_Bool Close();
+
+ void GetNewData( rtl::OUString& rName, rtl::OUString& rScope );
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/namedlg.hxx b/sc/source/ui/inc/namedlg.hxx
index 90252c5164db..cd2af4cf8e5f 100644
--- a/sc/source/ui/inc/namedlg.hxx
+++ b/sc/source/ui/inc/namedlg.hxx
@@ -94,6 +94,8 @@ private:
bool mbNeedUpdate;
bool mbDataChanged;
+ //ugly hack to call DefineNames from ManageNames
+ bool mbCloseWithoutUndo;
typedef boost::ptr_map<rtl::OUString, ScRangeName> RangeNameContainer;
@@ -141,7 +143,7 @@ protected:
public:
ScNameDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
ScViewData* ptrViewData,
- const ScAddress& aCursorPos );
+ const ScAddress& aCursorPos, boost::ptr_map<rtl::OUString, ScRangeName>* pRangeMap = NULL );
virtual ~ScNameDlg();
virtual void SetReference( const ScRange& rRef, ScDocument* pDoc );
@@ -150,6 +152,9 @@ public:
virtual void SetActive();
virtual sal_Bool Close();
+ void GetRangeNames(boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap);
+ void SetEntry(const rtl::OUString& rName, const rtl::OUString& rScope);
+
};
diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx
index e03ab7a36420..791bbc332bbd 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -40,6 +40,8 @@
#include "shellids.hxx"
#include "tabprotection.hxx" // for ScPasswordHash
+#include <boost/ptr_container/ptr_map.hpp>
+
class FmFormShell;
class SbxObject;
class SdrOle2Obj;
@@ -66,6 +68,7 @@ class ScChartShell;
class ScPageBreakShell;
class ScDPObject;
class ScNavigatorSettings;
+class ScRangeName;
struct ScHeaderFieldData;
@@ -182,6 +185,12 @@ private:
static const int MASTERENUMCOMMANDS = 6;
String aCurrShapeEnumCommand[ MASTERENUMCOMMANDS ];
+ // ugly hack for Add button in ScNameDlg
+ boost::ptr_map<rtl::OUString, ScRangeName> maRangeMap;
+ bool mbInSwitch;
+ rtl::OUString maName;
+ rtl::OUString maScope;
+
private:
void Construct( sal_uInt8 nForceDesignMode = SC_FORCEMODE_NONE );
@@ -416,6 +425,9 @@ public:
bool ExecuteRetypePassDlg(ScPasswordHash eDesiredHash);
using ScTabView::ShowCursor;
+
+ // ugly hack to call Define Names from Manage Names
+ void SwitchBetweenRefDialogs(SfxModelessDialog* pDialog);
};
//==================================================================
diff --git a/sc/source/ui/namedlg/namedefdlg.cxx b/sc/source/ui/namedlg/namedefdlg.cxx
index 90473fda9ab9..b373a1b19d6f 100644
--- a/sc/source/ui/namedlg/namedefdlg.cxx
+++ b/sc/source/ui/namedlg/namedefdlg.cxx
@@ -37,6 +37,7 @@
#include "rangenam.hxx"
#include "reffact.hxx"
#include "undorangename.hxx"
+#include "tabvwsh.hxx"
// defines -------------------------------------------------------------------
@@ -121,7 +122,13 @@ ScNameDefDlg::ScNameDefDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParen
void ScNameDefDlg::CancelPushed()
{
- Close();
+ if (mbUndo)
+ Close();
+ else
+ {
+ ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
+ pViewSh->SwitchBetweenRefDialogs(this);
+ }
}
bool ScNameDefDlg::IsFormulaValid()
@@ -254,9 +261,16 @@ void ScNameDefDlg::AddPushed()
// call invalidates the stream
if (nTab != -1)
mpDoc->SetStreamValid(nTab, false);
+ SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
+ Close();
+ }
+ else
+ {
+ maName = aName;
+ maScope = aScope;
+ ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
+ pViewSh->SwitchBetweenRefDialogs(this);
}
- SFX_APP()->Broadcast( SfxSimpleHint( SC_HINT_AREAS_CHANGED ) );
- Close();
}
else
{
@@ -269,6 +283,12 @@ void ScNameDefDlg::AddPushed()
}
}
+void ScNameDefDlg::GetNewData(rtl::OUString& rName, rtl::OUString& rScope)
+{
+ rName = maName;
+ rScope = maScope;
+}
+
sal_Bool ScNameDefDlg::IsRefInputMode() const
{
return maEdRange.IsEnabled();
diff --git a/sc/source/ui/namedlg/namedlg.cxx b/sc/source/ui/namedlg/namedlg.cxx
index 19eb1694a2dd..93456b551433 100644
--- a/sc/source/ui/namedlg/namedlg.cxx
+++ b/sc/source/ui/namedlg/namedlg.cxx
@@ -42,6 +42,7 @@
#include "namedlg.hrc"
#include "namedlg.hxx"
#include "viewdata.hxx"
+#include "tabvwsh.hxx"
#include "globalnames.hxx"
@@ -68,7 +69,7 @@
ScNameDlg::ScNameDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
ScViewData* ptrViewData,
- const ScAddress& aCursorPos )
+ const ScAddress& aCursorPos, boost::ptr_map<rtl::OUString, ScRangeName>* pRangeMap )
: ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_NAMES ),
//
@@ -107,8 +108,24 @@ ScNameDlg::ScNameDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
mpDoc ( ptrViewData->GetDocument() ),
maCursorPos ( aCursorPos ),
mbNeedUpdate ( true ),
- mbDataChanged ( false )
+ mbDataChanged ( false ),
+ mbCloseWithoutUndo( false )
{
+ if (!pRangeMap)
+ {
+ std::map<rtl::OUString, ScRangeName*> aRangeMap;
+ mpDoc->GetRangeNameMap(aRangeMap);
+ std::map<rtl::OUString, ScRangeName*>::iterator itr = aRangeMap.begin(), itrEnd = aRangeMap.end();
+ for (; itr != itrEnd; ++itr)
+ {
+ rtl::OUString aTemp(itr->first);
+ maRangeMap.insert(aTemp, new ScRangeName(*itr->second));
+ }
+ }
+ else
+ {
+ maRangeMap.swap(*pRangeMap);
+ }
Init();
FreeResource();
}
@@ -125,14 +142,7 @@ void ScNameDlg::Init()
OSL_ENSURE( mpViewData && mpDoc, "ViewData oder Document nicht gefunden!" );
//init UI
- std::map<rtl::OUString, ScRangeName*> aRangeMap;
- mpDoc->GetRangeNameMap(aRangeMap);
- std::map<rtl::OUString, ScRangeName*>::iterator itr = aRangeMap.begin(), itrEnd = aRangeMap.end();
- for (; itr != itrEnd; ++itr)
- {
- rtl::OUString aTemp(itr->first);
- maRangeMap.insert(aTemp, new ScRangeName(*itr->second));
- }
+
mpRangeManagerTable = new ScRangeManagerTable(&maNameMgrCtrl, maRangeMap);
mpRangeManagerTable->SetSelectHdl( LINK( this, ScNameDlg, SelectionChangedHdl_Impl ) );
@@ -178,7 +188,7 @@ void ScNameDlg::Init()
CheckForEmptyTable();
//TODO: fix the Add Button
- maBtnAdd.Disable();
+ //maBtnAdd.Disable();
}
sal_Bool ScNameDlg::IsRefInputMode() const
@@ -207,7 +217,7 @@ void ScNameDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
sal_Bool ScNameDlg::Close()
{
- if (mbDataChanged)
+ if (mbDataChanged && !mbCloseWithoutUndo)
{
ScDocFunc aFunc(*mpViewData->GetDocShell());
aFunc.ModifyAllRangeNames(maRangeMap);
@@ -345,9 +355,18 @@ void ScNameDlg::ShowOptions(const ScRangeNameLine& rLine)
bool ScNameDlg::AddPushed()
{
+ mbCloseWithoutUndo = true;
+ ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
+ pViewSh->SwitchBetweenRefDialogs(this);
return false;
}
+void ScNameDlg::SetEntry(const rtl::OUString& rName, const rtl::OUString& rScope)
+{
+ if (!rName.isEmpty())
+ mbDataChanged = true;
+}
+
void ScNameDlg::RemovePushed()
{
std::vector<ScRangeNameLine> maEntries = mpRangeManagerTable->GetSelectedEntries();
@@ -511,6 +530,11 @@ void ScNameDlg::MorePushed()
MoveWindow(maFlDiv, nPixel);
}
+void ScNameDlg::GetRangeNames(boost::ptr_map<rtl::OUString, ScRangeName>& rRangeMap)
+{
+ maRangeMap.swap(rRangeMap);
+}
+
IMPL_LINK( ScNameDlg, OkBtnHdl, void *, EMPTYARG )
{
Close();
diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx
index 5dc459d31215..f8e2ab84d788 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -1495,7 +1495,8 @@ bool ScTabViewShell::KeyInput( const KeyEvent &rKeyEvent )
pScSbxObject(NULL), \
bChartAreaValid(false), \
nCurRefDlgId(0), \
- pAccessibilityBroadcaster(NULL)
+ pAccessibilityBroadcaster(NULL), \
+ mbInSwitch(false)
//------------------------------------------------------------------
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index e9a50ad6e134..24302258bbb4 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -69,6 +69,7 @@
#include "funcdesc.hxx"
#include "dpobject.hxx"
#include "markdata.hxx"
+#include "reffact.hxx"
#include <iostream>
@@ -81,6 +82,37 @@ void ScTabViewShell::SetCurRefDlgId( sal_uInt16 nNew )
nCurRefDlgId = nNew;
}
+//ugly hack to call Define Name from Manage Names
+void ScTabViewShell::SwitchBetweenRefDialogs(SfxModelessDialog* pDialog)
+{
+ sal_uInt16 nSlotId = SC_MOD()->GetCurRefDlgId();
+ if (nSlotId == FID_DEFINE_NAME)
+ {
+ mbInSwitch = true;
+ static_cast<ScNameDlg*>(pDialog)->GetRangeNames(maRangeMap);
+ static_cast<ScNameDlg*>(pDialog)->Close();
+ sal_uInt16 nId = ScNameDefDlgWrapper::GetChildWindowId();
+ SfxViewFrame* pViewFrm = GetViewFrame();
+ SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
+
+ SC_MOD()->SetRefDialog( nId, pWnd ? false : sal_True );
+ }
+ else if( nSlotId == FID_ADD_NAME )
+ {
+ static_cast<ScNameDefDlg*>(pDialog)->GetNewData(maName, maScope);
+ static_cast<ScNameDlg*>(pDialog)->Close();
+ sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
+ SfxViewFrame* pViewFrm = GetViewFrame();
+ SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
+
+ SC_MOD()->SetRefDialog( nId, pWnd ? false : sal_True );
+ }
+ else
+ {
+
+ }
+}
+
SfxModelessDialog* ScTabViewShell::CreateRefDialog(
SfxBindings* pB, SfxChildWindow* pCW, SfxChildWinInfo* pInfo,
Window* pParent, sal_uInt16 nSlotId )
@@ -110,21 +142,50 @@ SfxModelessDialog* ScTabViewShell::CreateRefDialog(
switch( nSlotId )
{
case FID_DEFINE_NAME:
- pResult = new ScNameDlg( pB, pCW, pParent, GetViewData(),
- ScAddress( GetViewData()->GetCurX(),
- GetViewData()->GetCurY(),
- GetViewData()->GetTabNo() ) );
+ {
+ if (!mbInSwitch)
+ {
+ pResult = new ScNameDlg( pB, pCW, pParent, GetViewData(),
+ ScAddress( GetViewData()->GetCurX(),
+ GetViewData()->GetCurY(),
+ GetViewData()->GetTabNo() ) );
+ }
+ else
+ {
+ pResult = new ScNameDlg( pB, pCW, pParent, GetViewData(),
+ ScAddress( GetViewData()->GetCurX(),
+ GetViewData()->GetCurY(),
+ GetViewData()->GetTabNo() ), &maRangeMap);
+ static_cast<ScNameDlg*>(pResult)->SetEntry( maName, maScope);
+ mbInSwitch = false;
+ }
+ }
break;
case FID_ADD_NAME:
{
- std::cout << "tabvwsh" << std::endl;
- std::map<rtl::OUString, ScRangeName*> aRangeMap;
- pDoc->GetRangeNameMap(aRangeMap);
- pResult = new ScNameDefDlg( pB, pCW, pParent, GetViewData(), aRangeMap,
- ScAddress( GetViewData()->GetCurX(),
- GetViewData()->GetCurY(),
- GetViewData()->GetTabNo() ), true );
+ if (!mbInSwitch)
+ {
+ std::map<rtl::OUString, ScRangeName*> aRangeMap;
+ pDoc->GetRangeNameMap(aRangeMap);
+ pResult = new ScNameDefDlg( pB, pCW, pParent, GetViewData(), aRangeMap,
+ ScAddress( GetViewData()->GetCurX(),
+ GetViewData()->GetCurY(),
+ GetViewData()->GetTabNo() ), true );
+ }
+ else
+ {
+ std::map<rtl::OUString, ScRangeName*> aRangeMap;
+ for (boost::ptr_map<rtl::OUString, ScRangeName>::iterator itr = maRangeMap.begin();
+ itr != maRangeMap.end(); ++itr)
+ {
+ aRangeMap.insert(std::pair<rtl::OUString, ScRangeName*>(itr->first, itr->second));
+ }
+ pResult = new ScNameDefDlg( pB, pCW, pParent, GetViewData(), aRangeMap,
+ ScAddress( GetViewData()->GetCurX(),
+ GetViewData()->GetCurY(),
+ GetViewData()->GetTabNo() ), false );
+ }
}
break;