summaryrefslogtreecommitdiff
path: root/sc/source/ui/unoobj/viewuno.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/source/ui/unoobj/viewuno.cxx')
-rw-r--r--sc/source/ui/unoobj/viewuno.cxx132
1 files changed, 129 insertions, 3 deletions
diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx
index 15fb8183a88f..d10d3ba54f86 100644
--- a/sc/source/ui/unoobj/viewuno.cxx
+++ b/sc/source/ui/unoobj/viewuno.cxx
@@ -66,7 +66,9 @@
#include "scmod.hxx"
#include "appoptio.hxx"
#include "gridwin.hxx"
+#include "sheetevents.hxx"
#include <com/sun/star/view/DocumentZoomType.hpp>
+#include <com/sun/star/awt/MouseButton.hpp>
#include "AccessibilityHints.hxx"
#include <svx/sdrhittesthelper.hxx>
@@ -476,9 +478,11 @@ ScTabViewObj::ScTabViewObj( ScTabViewShell* pViewSh ) :
aPropSet( lcl_GetViewOptPropertyMap() ),
aMouseClickHandlers( 0 ),
aActivationListeners( 0 ),
+ nPreviousTab( 0 ),
bDrawSelModeSet(sal_False)
{
- //! Listening oder so
+ if (pViewSh)
+ nPreviousTab = pViewSh->GetViewData()->GetTabNo();
}
ScTabViewObj::~ScTabViewObj()
@@ -529,15 +533,44 @@ void SAL_CALL ScTabViewObj::release() throw()
SfxBaseController::release();
}
+void lcl_CallActivate( ScDocShell* pDocSh, SCTAB nTab, sal_Int32 nEvent )
+{
+ ScDocument* pDoc = pDocSh->GetDocument();
+ // when deleting a sheet, nPreviousTab can be invalid
+ // (could be handled with reference updates)
+ if (!pDoc->HasTable(nTab))
+ return;
+
+ const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
+ if (pEvents)
+ {
+ const rtl::OUString* pScript = pEvents->GetScript(nEvent);
+ if (pScript)
+ {
+ uno::Any aRet;
+ uno::Sequence<uno::Any> aParams;
+ uno::Sequence<sal_Int16> aOutArgsIndex;
+ uno::Sequence<uno::Any> aOutArgs;
+
+ /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
+ }
+ }
+}
+
void ScTabViewObj::SheetChanged()
{
- if (aActivationListeners.Count() > 0 && GetViewShell())
+ if ( !GetViewShell() )
+ return;
+
+ ScViewData* pViewData = GetViewShell()->GetViewData();
+ ScDocShell* pDocSh = pViewData->GetDocShell();
+ if (aActivationListeners.Count() > 0)
{
sheet::ActivationEvent aEvent;
uno::Reference< sheet::XSpreadsheetView > xView(this);
uno::Reference< uno::XInterface > xSource(xView, uno::UNO_QUERY);
aEvent.Source = xSource;
- aEvent.ActiveSheet = new ScTableSheetObj(GetViewShell()->GetViewData()->GetDocShell(), GetViewShell()->GetViewData()->GetTabNo());
+ aEvent.ActiveSheet = new ScTableSheetObj(pDocSh, pViewData->GetTabNo());
for ( USHORT n=0; n<aActivationListeners.Count(); n++ )
{
try
@@ -551,6 +584,15 @@ void ScTabViewObj::SheetChanged()
}
}
}
+
+ // handle sheet events
+ SCTAB nNewTab = pViewData->GetTabNo();
+ if ( nNewTab != nPreviousTab )
+ {
+ lcl_CallActivate( pDocSh, nPreviousTab, SC_SHEETEVENT_UNFOCUS );
+ lcl_CallActivate( pDocSh, nNewTab, SC_SHEETEVENT_FOCUS );
+ }
+ nPreviousTab = nNewTab;
}
uno::Sequence<uno::Type> SAL_CALL ScTabViewObj::getTypes() throw(uno::RuntimeException)
@@ -1194,6 +1236,22 @@ uno::Reference< uno::XInterface > ScTabViewObj::GetClickedObject(const Point& rP
return xTarget;
}
+bool ScTabViewObj::IsMouseListening() const
+{
+ if ( aMouseClickHandlers.Count() > 0 )
+ return true;
+
+ // also include sheet events, because MousePressed must be called for them
+ ScTabViewShell* pViewSh = GetViewShell();
+ ScViewData* pViewData = pViewSh->GetViewData();
+ const ScSheetEvents* pEvents = pViewData->GetDocument()->GetSheetEvents(pViewData->GetTabNo());
+ if ( pEvents && ( pEvents->GetScript(SC_SHEETEVENT_RIGHTCLICK) != NULL ||
+ pEvents->GetScript(SC_SHEETEVENT_DOUBLECLICK) != NULL ) )
+ return true;
+
+ return false;
+}
+
sal_Bool ScTabViewObj::MousePressed( const awt::MouseEvent& e )
throw (::uno::RuntimeException)
{
@@ -1229,6 +1287,50 @@ sal_Bool ScTabViewObj::MousePressed( const awt::MouseEvent& e )
}
}
}
+
+ // handle sheet events
+ bool bDoubleClick = ( e.Buttons == awt::MouseButton::LEFT && e.ClickCount == 2 );
+ bool bRightClick = ( e.Buttons == awt::MouseButton::RIGHT && e.ClickCount == 1 );
+ if ( ( bDoubleClick || bRightClick ) && !bReturn )
+ {
+ sal_Int32 nEvent = bDoubleClick ? SC_SHEETEVENT_DOUBLECLICK : SC_SHEETEVENT_RIGHTCLICK;
+
+ ScTabViewShell* pViewSh = GetViewShell();
+ ScViewData* pViewData = pViewSh->GetViewData();
+ ScDocShell* pDocSh = pViewData->GetDocShell();
+ ScDocument* pDoc = pDocSh->GetDocument();
+ SCTAB nTab = pViewData->GetTabNo();
+ const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
+ if (pEvents)
+ {
+ const rtl::OUString* pScript = pEvents->GetScript(nEvent);
+ if (pScript)
+ {
+ // the macro parameter is the clicked object, as in the mousePressed call above
+ uno::Reference< uno::XInterface > xTarget = GetClickedObject(Point(e.X, e.Y));
+ if (xTarget.is())
+ {
+ uno::Sequence<uno::Any> aParams(1);
+ aParams[0] <<= xTarget;
+
+ uno::Any aRet;
+ uno::Sequence<sal_Int16> aOutArgsIndex;
+ uno::Sequence<uno::Any> aOutArgs;
+
+ /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
+
+ // look for a boolean return value of true
+ sal_Bool bRetValue = sal_False;
+ if (aRet >>= bRetValue)
+ {
+ if (bRetValue)
+ bReturn = sal_True;
+ }
+ }
+ }
+ }
+ }
+
return bReturn;
}
@@ -1702,6 +1804,30 @@ void ScTabViewObj::SelectionChanged()
aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
for ( USHORT n=0; n<aSelectionListeners.Count(); n++ )
(*aSelectionListeners[n])->selectionChanged( aEvent );
+
+ // handle sheet events
+ ScTabViewShell* pViewSh = GetViewShell();
+ ScViewData* pViewData = pViewSh->GetViewData();
+ ScDocShell* pDocSh = pViewData->GetDocShell();
+ ScDocument* pDoc = pDocSh->GetDocument();
+ SCTAB nTab = pViewData->GetTabNo();
+ const ScSheetEvents* pEvents = pDoc->GetSheetEvents(nTab);
+ if (pEvents)
+ {
+ const rtl::OUString* pScript = pEvents->GetScript(SC_SHEETEVENT_SELECT);
+ if (pScript)
+ {
+ // the macro parameter is the selection as returned by getSelection
+ uno::Sequence<uno::Any> aParams(1);
+ aParams[0] = getSelection();
+
+ uno::Any aRet;
+ uno::Sequence<sal_Int16> aOutArgsIndex;
+ uno::Sequence<uno::Any> aOutArgs;
+
+ /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
+ }
+ }
}