Update to m13
[ooovba.git] / applied_patches / 0371-vba-workbook-worksheet-events.diff
blobad96fe08af6dc0eb50a3f65e77037cd37e9bd93b
1 --- offapi/com/sun/star/document/VbaEventId.idl.old 1970-01-01 00:00:00.000000000 +0000
2 +++ offapi/com/sun/star/document/VbaEventId.idl 2009-04-06 16:42:00.000000000 +0000
3 @@ -0,0 +1,82 @@
4 +/*************************************************************************
5 + *
6 + * OpenOffice.org - a multi-platform office productivity suite
7 + *
8 + * $RCSfile$
9 + *
10 + * $Revision$
11 + *
12 + * last change: $Author$ $Date$
13 + *
14 + * The Contents of this file are made available subject to
15 + * the terms of GNU Lesser General Public License Version 2.1.
16 + *
17 + *
18 + * GNU Lesser General Public License Version 2.1
19 + * =============================================
20 + * Copyright 2005 by Sun Microsystems, Inc.
21 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
22 + *
23 + * This library is free software; you can redistribute it and/or
24 + * modify it under the terms of the GNU Lesser General Public
25 + * License version 2.1, as published by the Free Software Foundation.
26 + *
27 + * This library is distributed in the hope that it will be useful,
28 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 + * Lesser General Public License for more details.
31 + *
32 + * You should have received a copy of the GNU Lesser General Public
33 + * License along with this library; if not, write to the Free Software
34 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
35 + * MA 02111-1307 USA
36 + *
37 + ************************************************************************/
38 +#ifndef __org_openoffice_vba_VbaEventId_idl__
39 +#define __org_openoffice_vba_VbaEventId_idl__
41 +//=============================================================================
43 +module com { module sun { module star { module document {
44 +//=============================================================================
46 +/* VBA compatibility event id */
47 +constants VbaEventId
49 + // Worksheet
50 + const long VBAEVENT_WORKSHEET_ACTIVATE = 1;
51 + const long VBAEVENT_WORKSHEET_BEFOREDOUBLECLICK = 2;
52 + const long VBAEVENT_WORKSHEET_BEFORERIGHTCLICK = 3;
53 + const long VBAEVENT_WORKSHEET_CALCULATE = 4;
54 + const long VBAEVENT_WORKSHEET_CHANGE = 5;
55 + const long VBAEVENT_WORKSHEET_DEACTIVATE = 6;
56 + const long VBAEVENT_WORKSHEET_FOLLOWHYPERLINK = 7;
57 + const long VBAEVENT_WORKSHEET_PIVOTTABLEUPDATE = 8;
58 + const long VBAEVENT_WORKSHEET_SELECTIONCHANGE = 9;
59 + // Workbook
60 + const long VBAEVENT_WORKBOOK_ACTIVATE = 20;
61 + const long VBAEVENT_WORKBOOK_DEACTIVATE = 21;
62 + const long VBAEVENT_WORKBOOK_OPEN = 22;
63 + const long VBAEVENT_WORKBOOK_AUTOOPEN = 23;
64 + const long VBAEVENT_WORKBOOK_BEFORECLOSE = 24;
65 + const long VBAEVENT_WORKBOOK_BEFOREPRINT = 25;
66 + const long VBAEVENT_WORKBOOK_BEFORESAVE = 26;
67 + const long VBAEVENT_WORKBOOK_NEWSHEET = 27;
68 + const long VBAEVENT_WORKBOOK_WINDOWACTIVATE = 28;
69 + const long VBAEVENT_WORKBOOK_WINDOWDEACTIVATE = 29;
70 + const long VBAEVENT_WORKBOOK_WINDOWRESIZE = 30;
71 + // Workbook_sheet
72 + const long VBAEVENT_WORKBOOK_SHEET_ACTIVATE = 51;
73 + const long VBAEVENT_WORKBOOK_SHEET_BEFOREDOUBLECLICK = 52;
74 + const long VBAEVENT_WORKBOOK_SHEET_BEFORERIGHTCLICK = 53;
75 + const long VBAEVENT_WORKBOOK_SHEET_CALCULATE = 54;
76 + const long VBAEVENT_WORKBOOK_SHEET_CHANGE = 55;
77 + const long VBAEVENT_WORKBOOK_SHEET_DEACTIVATE = 56;
78 + const long VBAEVENT_WORKBOOK_SHEET_FOLLOWHYPERLINK = 57;
79 + const long VBAEVENT_WORKBOOK_SHEET_PIVOTTABLEUPDATE = 58;
80 + const long VBAEVENT_WORKBOOK_SHEET_SELECTIONCHANGE = 59;
81 +};
83 +}; }; }; };
85 +#endif
86 --- offapi/com/sun/star/document/XVbaEventsHelper.idl.old 1970-01-01 00:00:00.000000000 +0000
87 +++ offapi/com/sun/star/document/XVbaEventsHelper.idl 2009-04-06 16:42:00.000000000 +0000
88 @@ -0,0 +1,60 @@
89 +/*************************************************************************
90 + *
91 + * OpenOffice.org - a multi-platform office productivity suite
92 + *
93 + * $RCSfile$
94 + *
95 + * $Revision$
96 + *
97 + * last change: $Author$ $Date$
98 + *
99 + * The Contents of this file are made available subject to
100 + * the terms of GNU Lesser General Public License Version 2.1.
103 + * GNU Lesser General Public License Version 2.1
104 + * =============================================
105 + * Copyright 2005 by Sun Microsystems, Inc.
106 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
108 + * This library is free software; you can redistribute it and/or
109 + * modify it under the terms of the GNU Lesser General Public
110 + * License version 2.1, as published by the Free Software Foundation.
112 + * This library is distributed in the hope that it will be useful,
113 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
114 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
115 + * Lesser General Public License for more details.
117 + * You should have received a copy of the GNU Lesser General Public
118 + * License along with this library; if not, write to the Free Software
119 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
120 + * MA 02111-1307 USA
122 + ************************************************************************/
123 +#ifndef __org_openoffice_vba_XVbaEventsHelper_idl__
124 +#define __org_openoffice_vba_XVbaEventsHelper_idl__
126 +#ifndef __com_sun_star_uno_XInterface_idl__
127 +#include <com/sun/star/uno/XInterface.idl>
128 +#endif
129 +//=============================================================================
131 +module com { module sun { module star { module document {
132 +//=============================================================================
134 +interface XVbaEventsHelper
136 + /**
137 + Execute VBA compatible event.
138 + VbaEvent: Compatible VBA event id.
139 + aArgs: the array of input arguments.
140 + return: True if execute successfully, or False.
141 + **/
142 + boolean ProcessCompatibleVbaEvent( [in] long nEventId, [in] sequence< any > aArgs );
143 + [attribute ] boolean IgnoreEvents;
146 +}; }; }; };
148 +#endif
149 --- offapi/com/sun/star/document/VbaEventsHelper.idl.old 1970-01-01 00:00:00.000000000 +0000
150 +++ offapi/com/sun/star/document/VbaEventsHelper.idl 2009-04-06 16:42:00.000000000 +0000
151 @@ -0,0 +1,55 @@
152 +/*************************************************************************
154 + * OpenOffice.org - a multi-platform office productivity suite
156 + * $RCSfile$
158 + * $Revision$
160 + * last change: $Author$ $Date$
162 + * The Contents of this file are made available subject to
163 + * the terms of GNU Lesser General Public License Version 2.1.
166 + * GNU Lesser General Public License Version 2.1
167 + * =============================================
168 + * Copyright 2005 by Sun Microsystems, Inc.
169 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
171 + * This library is free software; you can redistribute it and/or
172 + * modify it under the terms of the GNU Lesser General Public
173 + * License version 2.1, as published by the Free Software Foundation.
175 + * This library is distributed in the hope that it will be useful,
176 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
177 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
178 + * Lesser General Public License for more details.
180 + * You should have received a copy of the GNU Lesser General Public
181 + * License along with this library; if not, write to the Free Software
182 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
183 + * MA 02111-1307 USA
185 + ************************************************************************/
186 +#ifndef __org_openoffice_vba_VbaEventsHelper_idl__
187 +#define __org_openoffice_vba_VbaEventsHelper_idl__
189 +#ifndef __com_sun_star_uno_XInterface_idl__
190 +#include <com/sun/star/uno/XInterface.idl>
191 +#endif
192 +#include <com/sun/star/frame/XModel.idl>
193 +#include <com/sun/star/document/XVbaEventsHelper.idl>
194 +//=============================================================================
196 +module com { module sun { module star { module document {
197 +//=============================================================================
199 +service VbaEventsHelper : XVbaEventsHelper
201 + createVbaEventsHelper( [in] ::com::sun::star::frame::XModel xModel );
204 +}; }; }; };
206 +#endif
207 --- offapi/com/sun/star/document/XDocumentEventCompatibleHelper.idl.old 1970-01-01 00:00:00.000000000 +0000
208 +++ offapi/com/sun/star/document/XDocumentEventCompatibleHelper.idl 2009-04-06 16:42:00.000000000 +0000
209 @@ -0,0 +1,53 @@
210 +/*************************************************************************
212 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
213 + *
214 + * Copyright 2008 by Sun Microsystems, Inc.
216 + * OpenOffice.org - a multi-platform office productivity suite
218 + * $RCSfile: XVbaEventHelper.idl,v $
219 + * $Revision: 1.0 $
221 + * This file is part of OpenOffice.org.
223 + * OpenOffice.org is free software: you can redistribute it and/or modify
224 + * it under the terms of the GNU Lesser General Public License version 3
225 + * only, as published by the Free Software Foundation.
227 + * OpenOffice.org is distributed in the hope that it will be useful,
228 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
229 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
230 + * GNU Lesser General Public License version 3 for more details
231 + * (a copy is included in the LICENSE file that accompanied this code).
233 + * You should have received a copy of the GNU Lesser General Public License
234 + * version 3 along with OpenOffice.org. If not, see
235 + * <http://www.openoffice.org/license.html>
236 + * for a copy of the LGPLv3 License.
238 + ************************************************************************/
239 +#ifndef __com_sun_star_document_XDocumentEventCompatibleHelper_idl__
240 +#define __com_sun_star_document_XDocumentEventCompatibleHelper_idl__
242 +#ifndef __com_sun_star_uno_XInterface_idl__
243 +#include <com/sun/star/uno/XInterface.idl>
244 +#endif
245 +//=============================================================================
247 +module com { module sun { module star { module document {
249 +//=============================================================================
250 +interface XDocumentEventCompatibleHelper
252 + /* Execute some compatible VBA event related to document, such as document save, document print.
253 + nEventId: event id.
254 + */
255 + boolean processCompatibleEvent( [in] short nEventId );
258 +//=============================================================================
260 +}; }; }; };
262 +#endif
263 --- offapi/com/sun/star/document/makefile.mk.old 2009-04-06 16:41:59.000000000 +0000
264 +++ offapi/com/sun/star/document/makefile.mk 2009-04-06 16:42:00.000000000 +0000
265 @@ -117,6 +117,10 @@ IDLFILES=\
266 DocumentRevisionListPersistence.idl \
267 XDocumentLanguages.idl \
268 XCodeNameQuery.idl \
269 + XDocumentEventCompatibleHelper.idl \
270 + VbaEventId.idl \
271 + XVbaEventsHelper.idl \
272 + VbaEventsHelper.idl \
275 # ------------------------------------------------------------------
276 --- sc/source/ui/vba/vbaeventshelper.hxx.old 1970-01-01 00:00:00.000000000 +0000
277 +++ sc/source/ui/vba/vbaeventshelper.hxx 2009-04-06 16:42:00.000000000 +0000
278 @@ -0,0 +1,83 @@
279 +/*************************************************************************
281 + * OpenOffice.org - a multi-platform office productivity suite
283 + * $RCSfile: vbaeventshelper.hxx,v $
285 + * $Revision: 1.0 $
287 + * last change: $Author: vg $ $Date: 2007/12/07 10:42:26 $
289 + * The Contents of this file are made available subject to
290 + * the terms of GNU Lesser General Public License Version 2.1.
293 + * GNU Lesser General Public License Version 2.1
294 + * =============================================
295 + * Copyright 2005 by Sun Microsystems, Inc.
296 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
298 + * This library is free software; you can redistribute it and/or
299 + * modify it under the terms of the GNU Lesser General Public
300 + * License version 2.1, as published by the Free Software Foundation.
302 + * This library is distributed in the hope that it will be useful,
303 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
304 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
305 + * Lesser General Public License for more details.
307 + * You should have received a copy of the GNU Lesser General Public
308 + * License along with this library; if not, write to the Free Software
309 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
310 + * MA 02111-1307 USA
312 + ************************************************************************/
314 +#ifndef SC_VBAEVENTS_HXX
315 +#define SC_VBAEVENTS_HXX
317 +#include "document.hxx"
318 +#include <cppuhelper/implbase1.hxx>
319 +#include <com/sun/star/document/VbaEventId.hpp>
320 +#include <com/sun/star/document/XVbaEventsHelper.hpp>
321 +#include "vbahelper.hxx"
323 +#define INVALID_TAB -1
325 +typedef ::cppu::WeakImplHelper1< com::sun::star::document::XVbaEventsHelper > VBAWorkbookEvent_BASE;
327 +class VbaEventsListener;
328 +class ScVbaEventsHelper : public VBAWorkbookEvent_BASE
330 +private:
331 + ScDocument* pDoc;
332 + css::uno::Reference< css::uno::XComponentContext > m_xContext;
333 + VbaEventsListener* mpVbaEventsListener;
334 + sal_Bool mbOpened;
335 + sal_Bool mbIgnoreEvents;
337 + String getSheetModuleName( SCTAB nTab );
338 + String workbookMacroExists( SfxObjectShell* pShell, const String& sMod, const String& sMacro );
339 + css::uno::Any createWorkSheet( SfxObjectShell* pShell, SCTAB nTab );
340 + css::uno::Any createRange( const css::uno::Any& aRange );
341 + css::uno::Any createHyperlink( const css::uno::Any& rCell );
342 + css::uno::Any createWindow( SfxObjectShell* pShell );
343 + sal_Bool executeMacro( SfxObjectShell* pShell, const String& sMacroName, css::uno::Sequence< css::uno::Any >& aArgs, css::uno::Any& aRet );
344 + SCTAB getTabFromArgs( const css::uno::Sequence< css::uno::Any > aArgs, const sal_Int32 nPos = 0 );
345 + rtl::OUString getEventName( const sal_Int32 nEventId );
346 + rtl::OUString getMacroPath( const sal_Int32 nEventId, const SCTAB nTab = INVALID_TAB );
347 + sal_Bool processVbaEvent( const sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs, const SCTAB nTab = INVALID_TAB );
349 +public:
350 + ScVbaEventsHelper( ScDocument* pDocument ):pDoc( pDocument ), mpVbaEventsListener( NULL ), mbOpened( sal_False ){};
351 + ScVbaEventsHelper( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext > const& xContext );
352 + ~ScVbaEventsHelper();
353 + ScDocument* getDocument() { return pDoc; };
354 + // XVBAWorkbookEventHelper
355 + virtual sal_Bool SAL_CALL ProcessCompatibleVbaEvent( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& aArgs ) throw (css::uno::RuntimeException);
356 + virtual void SAL_CALL setIgnoreEvents( ::sal_Bool _ignoreevents ) throw (css::uno::RuntimeException);
357 + virtual ::sal_Bool SAL_CALL getIgnoreEvents() throw (css::uno::RuntimeException);
360 +#endif
362 --- sc/source/ui/vba/vbaeventshelper.cxx.old 1970-01-01 00:00:00.000000000 +0000
363 +++ sc/source/ui/vba/vbaeventshelper.cxx 2009-04-06 16:42:00.000000000 +0000
364 @@ -0,0 +1,1066 @@
365 +/*************************************************************************
367 + * OpenOffice.org - a multi-platform office productivity suite
369 + * $RCSfile: vbaeventshelper.cxx,v $
371 + * $Revision: 1.0 $
373 + * last change: $Author: vg $ $Date: 2007/12/07 10:42:26 $
375 + * The Contents of this file are made available subject to
376 + * the terms of GNU Lesser General Public License Version 2.1.
379 + * GNU Lesser General Public License Version 2.1
380 + * =============================================
381 + * Copyright 2005 by Sun Microsystems, Inc.
382 + * 901 San Antonio Road, Palo Alto, CA 94303, USA
384 + * This library is free software; you can redistribute it and/or
385 + * modify it under the terms of the GNU Lesser General Public
386 + * License version 2.1, as published by the Free Software Foundation.
388 + * This library is distributed in the hope that it will be useful,
389 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
390 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
391 + * Lesser General Public License for more details.
393 + * You should have received a copy of the GNU Lesser General Public
394 + * License along with this library; if not, write to the Free Software
395 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
396 + * MA 02111-1307 USA
398 + ************************************************************************/
399 +#include "vbaeventshelper.hxx"
400 +#include "helperdecl.hxx"
401 +#include <sfx2/objsh.hxx>
402 +#include <basic/basmgr.hxx>
403 +#include <basic/sbmod.hxx>
404 +#include <basic/sbmeth.hxx>
405 +#include <basic/sbx.hxx>
406 +#include "scextopt.hxx"
407 +#include <sfx2/evntconf.hxx>
408 +#include <sfx2/event.hxx>
409 +#include <sfx2/sfx.hrc>
410 +#include <toolkit/unohlp.hxx>
411 +#include <comphelper/processfactory.hxx>
412 +#include <cppuhelper/implbase1.hxx>
413 +#include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
414 +#include <com/sun/star/document/XEventsSupplier.hpp>
415 +#include <com/sun/star/sheet/XCellRangeReferrer.hpp>
416 +#include <com/sun/star/table/XCell.hpp>
417 +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
418 +#include <com/sun/star/sheet/XSpreadsheet.hpp>
419 +#include <com/sun/star/container/XNamed.hpp>
420 +#include <com/sun/star/awt/XWindowListener.hpp>
421 +#include <com/sun/star/awt/WindowEvent.hpp>
422 +#include <com/sun/star/lang/EventObject.hpp>
423 +#include <com/sun/star/util/XCloseListener.hpp>
424 +#include <com/sun/star/util/XCloseBroadcaster.hpp>
425 +#include <com/sun/star/frame/XControllerBorder.hpp>
426 +#include <com/sun/star/frame/XBorderResizeListener.hpp>
427 +#include "cellsuno.hxx"
429 +#include <map>
431 +using namespace std;
432 +using namespace com::sun::star;
433 +using namespace ooo::vba;
434 +using namespace com::sun::star::document::VbaEventId;
436 +const static String sLibrary( RTL_CONSTASCII_USTRINGPARAM("Standard"));
438 +const static rtl::OUString sUrlPart0 = rtl::OUString::createFromAscii( "vnd.sun.star.script:");
439 +const static rtl::OUString sUrlPart1 = rtl::OUString::createFromAscii( "vnd.sun.star.script:Standard.");
440 +const static rtl::OUString sUrlPart2 = rtl::OUString::createFromAscii( "?language=Basic&location=document");
443 +typedef ::cppu::WeakImplHelper3< awt::XWindowListener, util::XCloseListener, frame::XBorderResizeListener > WindowListener_BASE;
445 +// This class is to process Workbook window related event
446 +class VbaEventsListener : public WindowListener_BASE
448 + ScVbaEventsHelper* pVbaEventsHelper;
449 + uno::Reference< frame::XModel > m_xModel;
450 + sal_Bool m_bPrepare;
451 + sal_Bool m_bWindowResized;
452 + sal_Bool m_bBorderChanged;
453 +protected :
454 + uno::Reference< awt::XWindow > GetContainerWindow();
455 + uno::Reference< frame::XFrame > GetFrame();
456 + sal_Bool IsMouseReleased();
457 + DECL_LINK( fireResizeMacro, Timer* );
458 + void processWindowResizeMacro();
459 +public :
460 + VbaEventsListener( ScVbaEventsHelper* pHelper );
461 + void startEventsLinstener();
462 + void stopEventsLinstener();
463 + // XWindowListener
464 + virtual void SAL_CALL windowResized( const awt::WindowEvent& aEvent ) throw ( uno::RuntimeException );
465 + virtual void SAL_CALL windowMoved( const awt::WindowEvent& aEvent ) throw ( uno::RuntimeException );
466 + virtual void SAL_CALL windowShown( const lang::EventObject& aEvent ) throw ( uno::RuntimeException );
467 + virtual void SAL_CALL windowHidden( const lang::EventObject& aEvent ) throw ( uno::RuntimeException );
468 + virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException );
469 + // XCloseListener
470 + virtual void SAL_CALL queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException);
471 + virtual void SAL_CALL notifyClosing( const lang::EventObject& Source ) throw (uno::RuntimeException);
472 + // XBorderResizeListener
473 + virtual void SAL_CALL borderWidthsChanged( const uno::Reference< uno::XInterface >& aObject, const frame::BorderWidths& aNewSize ) throw (uno::RuntimeException);
475 +VbaEventsListener::VbaEventsListener( ScVbaEventsHelper* pHelper ) : pVbaEventsHelper( pHelper )
477 + m_xModel.set( pVbaEventsHelper->getDocument()->GetDocumentShell()->GetModel(), uno::UNO_QUERY );
478 + m_bPrepare = sal_False;
479 + m_bWindowResized = sal_False;
480 + m_bBorderChanged = sal_False;
482 +uno::Reference< frame::XFrame >
483 +VbaEventsListener::GetFrame()
485 + try
487 + if( pVbaEventsHelper )
489 + if( m_xModel.is() )
491 + uno::Reference< frame::XController > xController( m_xModel->getCurrentController(), uno::UNO_QUERY );
492 + if( xController.is() )
494 + uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_QUERY );
495 + if( xFrame.is() )
497 + return xFrame;
503 + catch( uno::Exception& /*e*/ )
506 + return uno::Reference< frame::XFrame >();
508 +uno::Reference< awt::XWindow >
509 +VbaEventsListener::GetContainerWindow()
511 + try
513 + uno::Reference< frame::XFrame > xFrame( GetFrame(), uno::UNO_QUERY );
514 + if( xFrame.is() )
516 + uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow(), uno::UNO_QUERY );
517 + if( xWindow.is() )
518 + return xWindow;
521 + catch( uno::Exception& /*e*/ )
524 + return uno::Reference< awt::XWindow >();
526 +sal_Bool
527 +VbaEventsListener::IsMouseReleased()
529 + Window* pWindow = (VCLUnoHelper::GetWindow( GetContainerWindow() ) );
530 + if( pWindow )
532 + Window::PointerState aPointerState = pWindow->GetPointerState();
533 + if( !aPointerState.mnState & ( MOUSE_LEFT | MOUSE_MIDDLE | MOUSE_RIGHT ) )
534 + return sal_True;
536 + return sal_False;
538 +void
539 +VbaEventsListener::startEventsLinstener()
541 + if( m_xModel.is() )
543 + // add window listener
544 + uno::Reference< awt::XWindow > xWindow( GetContainerWindow(), uno::UNO_QUERY );
545 + if( xWindow.is() )
546 + xWindow->addWindowListener( this );
547 + // add close listener
548 + //uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( GetFrame(), uno::UNO_QUERY );
549 + uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xModel, uno::UNO_QUERY );
550 + if( xCloseBroadcaster.is() )
552 + xCloseBroadcaster->addCloseListener( this );
554 + // add Border resize listener
555 + uno::Reference< frame::XController > xController( m_xModel->getCurrentController(), uno::UNO_QUERY );
556 + if( xController.is() )
558 + uno::Reference< frame::XControllerBorder > xControllerBorder( xController, uno::UNO_QUERY );
559 + if( xControllerBorder.is() )
561 + xControllerBorder->addBorderResizeListener( this );
566 +void
567 +VbaEventsListener::stopEventsLinstener()
569 + if( m_xModel.is() )
571 + uno::Reference< awt::XWindow > xWindow( GetContainerWindow(), uno::UNO_QUERY );
572 + if( xWindow.is() )
574 + xWindow->removeWindowListener( this );
576 + //uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( GetFrame(), uno::UNO_QUERY );
577 + uno::Reference< util::XCloseBroadcaster > xCloseBroadcaster( m_xModel, uno::UNO_QUERY );
578 + if( xCloseBroadcaster.is() )
580 + xCloseBroadcaster->removeCloseListener( this );
582 + uno::Reference< frame::XController > xController( m_xModel->getCurrentController(), uno::UNO_QUERY );
583 + if( xController.is() )
585 + uno::Reference< frame::XControllerBorder > xControllerBorder( xController, uno::UNO_QUERY );
586 + if( xControllerBorder.is() )
588 + xControllerBorder->removeBorderResizeListener( this );
591 + pVbaEventsHelper = NULL;
594 +void
595 +VbaEventsListener::processWindowResizeMacro()
597 + if( pVbaEventsHelper )
598 + pVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_WINDOWRESIZE, uno::Sequence< uno::Any >() );
600 +IMPL_LINK( VbaEventsListener, fireResizeMacro, Timer*, pTimer )
602 + if( pVbaEventsHelper && m_bPrepare && pTimer )
604 + if( IsMouseReleased() )
606 + pTimer->Stop();
607 + delete pTimer;
608 + pTimer = 0;
609 + m_bPrepare = sal_False;
610 + processWindowResizeMacro();
613 + return 0;
615 +void SAL_CALL
616 +VbaEventsListener::windowResized( const awt::WindowEvent& /*aEvent*/ ) throw ( uno::RuntimeException )
618 + // Workbook_window_resize event
619 + OSL_TRACE("VbaEventsListener::windowResized");
620 + m_bWindowResized = sal_True;
621 + Window* pWindow = (VCLUnoHelper::GetWindow( GetContainerWindow() ) );
622 + if( pWindow && !m_bPrepare && m_bBorderChanged )
624 + m_bPrepare = sal_True;
625 + m_bBorderChanged = m_bWindowResized = sal_False;
626 + AutoTimer* pTimer = new AutoTimer();
627 + pTimer->SetTimeoutHdl( LINK( this, VbaEventsListener, fireResizeMacro ) );
628 + pTimer->Start();
631 +void SAL_CALL
632 +VbaEventsListener::windowMoved( const awt::WindowEvent& /*aEvent*/ ) throw ( uno::RuntimeException )
634 + // not interest this time
636 +void SAL_CALL
637 +VbaEventsListener::windowShown( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException )
639 + // not interest this time
641 +void SAL_CALL
642 +VbaEventsListener::windowHidden( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException )
644 + // not interest this time
646 +void SAL_CALL
647 +VbaEventsListener::disposing( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException )
649 + pVbaEventsHelper = NULL;
651 +void SAL_CALL
652 +VbaEventsListener::queryClosing( const lang::EventObject& Source, ::sal_Bool GetsOwnership ) throw (util::CloseVetoException, uno::RuntimeException)
654 + // it can cancel the close, but need to throw a CloseVetoException, and it will be transmit to caller.
656 +void SAL_CALL
657 +VbaEventsListener::notifyClosing( const lang::EventObject& Source ) throw (uno::RuntimeException)
659 + OSL_TRACE("VbaEventsListener::notifyClosing");
660 + stopEventsLinstener();
662 +void SAL_CALL
663 +VbaEventsListener::borderWidthsChanged( const uno::Reference< uno::XInterface >& aObject, const frame::BorderWidths& aNewSize ) throw (uno::RuntimeException)
665 + // work with WindowResized event to guard Window Resize event.
666 + OSL_TRACE("VbaEventsListener::borderWidthsChanged");
667 + m_bBorderChanged = sal_True;
668 + Window* pWindow = (VCLUnoHelper::GetWindow( GetContainerWindow() ) );
669 + if( pWindow && !m_bPrepare && m_bWindowResized )
671 + m_bPrepare = sal_True;
672 + m_bWindowResized = m_bBorderChanged = sal_False;
673 + AutoTimer* pTimer = new AutoTimer();
674 + pTimer->SetTimeoutHdl( LINK( this, VbaEventsListener, fireResizeMacro ) );
675 + pTimer->Start();
679 +class ImplVbaEventNameInfo
681 +private:
682 + map< sal_Int32, rtl::OUString > m_aEventNameMap;
684 +protected:
685 + static ImplVbaEventNameInfo* pImplVbaEventNameInfo;
686 + ImplVbaEventNameInfo() { InitImplVbaEventNameInfo(); }
687 +private:
688 + void insert( const sal_Int32 nId, const rtl::OUString sEventName )
690 + m_aEventNameMap.insert( make_pair( nId, sEventName ) );
692 + void InitImplVbaEventNameInfo();
693 +public:
694 + virtual ~ImplVbaEventNameInfo();
695 + rtl::OUString getEventName( const sal_Int32 nId )
697 + map< sal_Int32, rtl::OUString >::iterator iter = m_aEventNameMap.find( nId );
698 + if( iter != m_aEventNameMap.end() )
699 + return iter->second;
700 + return rtl::OUString();
702 + static ImplVbaEventNameInfo* GetImplVbaEventNameInfo();
704 +ImplVbaEventNameInfo* ImplVbaEventNameInfo::pImplVbaEventNameInfo = NULL;
706 +ImplVbaEventNameInfo::~ImplVbaEventNameInfo()
708 + if( pImplVbaEventNameInfo )
710 + delete pImplVbaEventNameInfo;
711 + pImplVbaEventNameInfo = NULL;
715 +ImplVbaEventNameInfo*
716 +ImplVbaEventNameInfo::GetImplVbaEventNameInfo()
718 + if( !pImplVbaEventNameInfo )
720 + pImplVbaEventNameInfo = new ImplVbaEventNameInfo;
722 + return pImplVbaEventNameInfo;
725 +#define CREATEOUSTRING(asciistr) rtl::OUString::createFromAscii(asciistr)
727 +#define INSERT_EVENT_INFO( Object, Event, ObjectName, EventName ) \
728 + insert( VBAEVENT_##Object##_##Event, ObjectName + CREATEOUSTRING( EventName ) )
730 +#define INSERT_WORKSHEET_EVENT_INFO( Event, EventName ) \
731 + INSERT_EVENT_INFO( WORKSHEET, Event,CREATEOUSTRING("Worksheet_"), EventName ); \
732 + INSERT_EVENT_INFO( WORKBOOK_SHEET, Event, CREATEOUSTRING("Workbook_Sheet"), EventName )
734 +#define INSERT_WORKBOOK_EVENT_INFO( Event, EventName ) \
735 + INSERT_EVENT_INFO( WORKBOOK, Event, CREATEOUSTRING("Workbook_"), EventName )
737 +void ImplVbaEventNameInfo::InitImplVbaEventNameInfo()
739 + INSERT_WORKSHEET_EVENT_INFO( ACTIVATE, "Activate");
740 + INSERT_WORKSHEET_EVENT_INFO( BEFOREDOUBLECLICK, "BeforeDoubleClick" );
741 + INSERT_WORKSHEET_EVENT_INFO( BEFORERIGHTCLICK, "BeforeRightClick" );
742 + INSERT_WORKSHEET_EVENT_INFO( CALCULATE, "Calculate" );
743 + INSERT_WORKSHEET_EVENT_INFO( CHANGE, "Change" );
744 + INSERT_WORKSHEET_EVENT_INFO( DEACTIVATE, "Deactivate" );
745 + INSERT_WORKSHEET_EVENT_INFO( FOLLOWHYPERLINK, "FollowHyperlink" );
746 + INSERT_WORKSHEET_EVENT_INFO( PIVOTTABLEUPDATE, "PivotTableUpdate" );
747 + INSERT_WORKSHEET_EVENT_INFO( SELECTIONCHANGE, "SelectionChange" );
749 + // Workbook
750 + INSERT_WORKBOOK_EVENT_INFO( ACTIVATE, "Activate" );
751 + INSERT_WORKBOOK_EVENT_INFO( DEACTIVATE, "Deactivate" );
752 + INSERT_WORKBOOK_EVENT_INFO( OPEN, "Open" );
753 + // AUTOOPEN doesn't be used. TODO, this should be "auto_open"
754 + INSERT_WORKBOOK_EVENT_INFO( BEFORECLOSE, "BeforeClose" );
755 + INSERT_WORKBOOK_EVENT_INFO( BEFOREPRINT, "BeforePrint" );
756 + INSERT_WORKBOOK_EVENT_INFO( BEFORESAVE, "BeforeSave" );
757 + INSERT_WORKBOOK_EVENT_INFO( NEWSHEET, "NewSheet" );
758 + INSERT_WORKBOOK_EVENT_INFO( WINDOWACTIVATE, "WindowActivate" );
759 + INSERT_WORKBOOK_EVENT_INFO( WINDOWDEACTIVATE, "WindowDeactivate" );
760 + INSERT_WORKBOOK_EVENT_INFO( WINDOWRESIZE, "WindowResize" );
763 +ScVbaEventsHelper::ScVbaEventsHelper( uno::Sequence< css::uno::Any > const& aArgs, uno::Reference< uno::XComponentContext > const& xContext )
764 + : m_xContext( xContext ), mpVbaEventsListener( NULL ), mbOpened( sal_False ), mbIgnoreEvents( sal_False )
766 + uno::Reference< frame::XModel > xModel ( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ), uno::UNO_QUERY );
767 + ScDocShell* pDocShell = getDocShell( xModel );
768 + pDoc = pDocShell->GetDocument();
771 +ScVbaEventsHelper::~ScVbaEventsHelper()
773 + if( mpVbaEventsListener )
775 + mpVbaEventsListener = NULL;
779 +rtl::OUString
780 +ScVbaEventsHelper::getEventName( const sal_Int32 nId )
782 + rtl::OUString sEventName;
783 + ImplVbaEventNameInfo* pEventInfo = ImplVbaEventNameInfo::GetImplVbaEventNameInfo();
784 + if( pEventInfo )
785 + sEventName = pEventInfo->getEventName( nId );
786 + return sEventName;
789 +// Treat the args as possible inouts ( convertion at bottom of method )
790 +sal_Bool ScVbaEventsHelper::executeMacro( SfxObjectShell* pShell, const String& sMacroName, uno::Sequence< uno::Any >& aArgs, uno::Any& aRet )
792 + // until ObjectModules ( and persisting of codenames ) is supported, if this is a
793 + // document saved from XL then we won't be able to determine the codename for the Workbook
794 + // Module, so... we have no choice but to search all modules for the moment, thus the macro
795 + // passed in should be the fully specified name.
796 + rtl::OUString sUrl = sUrlPart0.concat( sMacroName ).concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".") ) ).concat( sUrlPart2 ) ;
797 + uno::Sequence< sal_Int16 > aOutArgsIndex;
798 + uno::Sequence< uno::Any > aOutArgs;
799 + ErrCode nErr = pShell->CallXScript( sUrl, aArgs, aRet,
800 + aOutArgsIndex, aOutArgs, sal_False );
802 + // Script Executed?
803 + if ( nErr != ERRCODE_NONE )
804 + return sal_False;
806 + sal_Int32 nLen = aOutArgs.getLength();
807 + // convert any out params to seem like they were inouts
808 + if ( nLen )
810 + for ( sal_Int32 index=0; index < nLen; ++index )
812 + sal_Int32 nOutIndex = aOutArgsIndex[ index ];
813 + aArgs[ nOutIndex ] = aOutArgs[ index ];
817 + return sal_True;
819 +String ScVbaEventsHelper::workbookMacroExists( SfxObjectShell* pShell, const String& sMod, const String& sMacro )
821 + String sFullName;
822 + // would use the script provider to see if the macro exists but
823 + // called at this stage tdoc content handler stuff is not set up
824 + // so it fails
826 + BasicManager* pBasicMgr = pShell-> GetBasicManager();
827 + if ( pBasicMgr )
829 + StarBASIC* pBasic = pBasicMgr->GetLib( sLibrary );
830 + if ( !pBasic )
832 + USHORT nId = pBasicMgr->GetLibId( sLibrary );
833 + pBasicMgr->LoadLib( nId );
834 + pBasic = pBasicMgr->GetLib( sLibrary );
836 + if ( pBasic )
838 + if ( sMod.Len() ) // we wish to find the macro is a specific module
840 + SbModule* pModule = pBasic->FindModule( sMod );
841 + if ( pModule )
843 + SbxArray* pMethods = pModule->GetMethods();
844 + if ( pMethods )
846 + SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Find( sMacro, SbxCLASS_METHOD ) );
847 + if ( pMethod )
849 + sFullName = sMacro;
850 + sFullName.Insert( '.', 0 ).Insert( sMod, 0 ).Insert( '.', 0 ).Insert( sLibrary, 0 );
855 + else if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pBasic->Find( sMacro, SbxCLASS_METHOD ) ) )
857 + if( SbModule* pModule = pMethod->GetModule() )
859 + sFullName = sMacro;
860 + sFullName.Insert( '.', 0 ).Insert( pModule->GetName(), 0).Insert( '.', 0 ).Insert( sLibrary, 0 );
862 + }
866 + return sFullName;
869 +uno::Any ScVbaEventsHelper::createWorkSheet( SfxObjectShell* pShell, SCTAB nTab )
871 + uno::Any aRet;
872 + try
874 + uno::Reference< lang::XMultiComponentFactory > xSMgr( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
875 + uno::Reference< beans::XPropertySet > xProps( xSMgr, uno::UNO_QUERY_THROW );
876 + uno::Reference<uno::XComponentContext > xCtx( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
877 + // Eventually we will be able to pull the Workbook/Worksheet objects
878 + // directly from basic and register them as listeners
880 + // create Workbook
881 + uno::Sequence< uno::Any > aArgs(2);
882 + aArgs[0] = uno::Any( uno::Reference< uno::XInterface >() );
883 + aArgs[1] = uno::Any( pShell->GetModel() );
884 + uno::Reference< uno::XInterface > xWorkbook( xSMgr->createInstanceWithArgumentsAndContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Workbook") ), aArgs, xCtx ), uno::UNO_QUERY );
886 + // create WorkSheet
887 + String sSheetName;
888 + pDoc->GetName( nTab, sSheetName );
889 + aArgs = uno::Sequence< uno::Any >(3);
890 + aArgs[ 0 ] <<= xWorkbook;
891 + aArgs[ 1 ] <<= pShell->GetModel();
892 + aArgs[ 2 ] = uno::makeAny( rtl::OUString( sSheetName ) );
893 + aRet <<= xSMgr->createInstanceWithArgumentsAndContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Worksheet") ), aArgs, xCtx );
895 + catch( uno::Exception& e )
898 + return aRet;
901 +uno::Any ScVbaEventsHelper::createRange( const uno::Any& aRange )
903 + uno::Any aRet;
904 + try
906 + uno::Reference< sheet::XSheetCellRangeContainer > xRanges( aRange, uno::UNO_QUERY );
907 + uno::Reference< table::XCellRange > xRange( aRange, uno::UNO_QUERY );
908 + uno::Reference< lang::XMultiComponentFactory > xSMgr( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
909 + uno::Reference< beans::XPropertySet > xProps( xSMgr, uno::UNO_QUERY_THROW );
910 + if ( xRanges.is() || xRange.is() )
912 + uno::Reference<uno::XComponentContext > xCtx( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
913 + uno::Sequence< uno::Any > aArgs(2);
914 + aArgs[0] = uno::Any( uno::Reference< uno::XInterface >() ); // dummy parent
915 + if ( xRanges.is() )
917 + aArgs[1] <<= xRanges;
919 + else if ( xRange.is() )
921 + aArgs[1] <<= xRange;
923 + else
925 + throw uno::RuntimeException(); //
927 + aRet <<= xSMgr->createInstanceWithArgumentsAndContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Range") ), aArgs, xCtx );
930 + catch( uno::Exception& e )
933 + return aRet;
936 +uno::Any ScVbaEventsHelper::createHyperlink( const uno::Any& rCell )
938 + uno::Any aRet;
939 + try
941 + uno::Reference< lang::XMultiComponentFactory > xSMgr( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
942 + uno::Reference< beans::XPropertySet > xProps( xSMgr, uno::UNO_QUERY_THROW );
943 + uno::Reference< table::XCell > xCell( rCell, uno::UNO_QUERY );
944 + if( xCell.is() )
946 + uno::Reference<uno::XComponentContext > xCtx( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
947 + uno::Sequence< uno::Any > aArgs(2);
948 + aArgs[0] = uno::Any( uno::Reference< uno::XInterface >() ); // dummy parent
949 + aArgs[1] <<= rCell;
951 + aRet <<= xSMgr->createInstanceWithArgumentsAndContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Hyperlink") ), aArgs, xCtx );
953 + else
955 + throw uno::RuntimeException(); //
958 + catch( uno::Exception& e )
961 + return aRet;
964 +uno::Any ScVbaEventsHelper::createWindow( SfxObjectShell* pShell )
966 + try
968 + uno::Reference< lang::XMultiServiceFactory > xSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
969 + uno::Reference< frame::XModel > xModel( pShell->GetModel(), uno::UNO_QUERY );
970 + uno::Sequence< uno::Any > aWindowArgs(2);
971 + aWindowArgs[0] = uno::Any( uno::Reference< uno::XInterface > () );
972 + aWindowArgs[1] = uno::Any( xModel );
973 + uno::Reference< uno::XInterface > xWindow( xSF->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Window" ) ), aWindowArgs ), uno::UNO_QUERY );
974 + if( xWindow.is() )
975 + return uno::makeAny( xWindow );
977 + catch( uno::Exception& e )
980 + return uno::Any();
983 +String ScVbaEventsHelper::getSheetModuleName( SCTAB nTab )
985 + ScExtDocOptions* pExtOptions = pDoc->GetExtDocOptions();
986 + String aCodeName;
987 + pDoc->GetName( nTab, aCodeName);
988 + // Use code name if that exists
989 + if ( pExtOptions )
990 + aCodeName = pExtOptions->GetCodeName( nTab );
991 + return aCodeName;
994 +rtl::OUString
995 +ScVbaEventsHelper::getMacroPath( const sal_Int32 nEventId, const SCTAB nTab )
997 + SfxObjectShell* pShell = pDoc->GetDocumentShell();
998 + rtl::OUString sMacroPath;
999 + rtl::OUString sMacroName = getEventName( nEventId );
1000 + switch( nEventId )
1002 + // Worksheet
1003 + case VBAEVENT_WORKSHEET_ACTIVATE :
1004 + case VBAEVENT_WORKSHEET_BEFOREDOUBLECLICK :
1005 + case VBAEVENT_WORKSHEET_BEFORERIGHTCLICK :
1006 + case VBAEVENT_WORKSHEET_CALCULATE :
1007 + case VBAEVENT_WORKSHEET_CHANGE :
1008 + case VBAEVENT_WORKSHEET_DEACTIVATE :
1009 + case VBAEVENT_WORKSHEET_FOLLOWHYPERLINK :
1010 + case VBAEVENT_WORKSHEET_PIVOTTABLEUPDATE :
1011 + case VBAEVENT_WORKSHEET_SELECTIONCHANGE :
1013 + rtl::OUString aSheetModuleName = getSheetModuleName( nTab );
1014 + sMacroPath = workbookMacroExists( pShell, aSheetModuleName, sMacroName );
1015 + break;
1017 + // Workbook
1018 + case VBAEVENT_WORKBOOK_ACTIVATE :
1019 + case VBAEVENT_WORKBOOK_DEACTIVATE :
1020 + case VBAEVENT_WORKBOOK_OPEN :
1021 + case VBAEVENT_WORKBOOK_AUTOOPEN :
1022 + case VBAEVENT_WORKBOOK_BEFORECLOSE :
1023 + case VBAEVENT_WORKBOOK_BEFOREPRINT :
1024 + case VBAEVENT_WORKBOOK_BEFORESAVE :
1025 + case VBAEVENT_WORKBOOK_NEWSHEET :
1026 + case VBAEVENT_WORKBOOK_WINDOWACTIVATE :
1027 + case VBAEVENT_WORKBOOK_WINDOWDEACTIVATE :
1028 + case VBAEVENT_WORKBOOK_WINDOWRESIZE :
1029 + // Workbook_sheet
1030 + case VBAEVENT_WORKBOOK_SHEET_ACTIVATE :
1031 + case VBAEVENT_WORKBOOK_SHEET_BEFOREDOUBLECLICK :
1032 + case VBAEVENT_WORKBOOK_SHEET_BEFORERIGHTCLICK :
1033 + case VBAEVENT_WORKBOOK_SHEET_CALCULATE :
1034 + case VBAEVENT_WORKBOOK_SHEET_CHANGE :
1035 + case VBAEVENT_WORKBOOK_SHEET_DEACTIVATE :
1036 + case VBAEVENT_WORKBOOK_SHEET_FOLLOWHYPERLINK :
1037 + case VBAEVENT_WORKBOOK_SHEET_PIVOTTABLEUPDATE :
1038 + case VBAEVENT_WORKBOOK_SHEET_SELECTIONCHANGE :
1040 + ScExtDocOptions* pExtOptions = pDoc->GetExtDocOptions();
1041 + String sWorkbookModuleName = pDoc->GetCodeName();
1042 + if( pExtOptions )
1044 + ScExtDocSettings aExtDocSettings = pExtOptions->GetDocSettings();
1045 + sWorkbookModuleName = aExtDocSettings.maGlobCodeName;
1048 + sMacroPath = workbookMacroExists( pShell, sWorkbookModuleName, sMacroName );
1049 + break;
1051 + default:
1052 + break;
1054 + return sMacroPath;
1057 +sal_Bool ScVbaEventsHelper::processVbaEvent( const sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs, const SCTAB nTab )
1059 + SfxObjectShell* pShell = pDoc->GetDocumentShell();
1061 + sal_Bool result = sal_False;
1062 + sal_Bool bCancel = sal_False;
1063 + uno::Sequence< uno::Any > aArgs;
1064 + uno::Any aRet;
1066 + // For most cases, there is no corresponsible event macro in the document.
1067 + // It is better fo check if the event macro exists before process the arguments to improve performance.
1068 + rtl::OUString sMacroPath = getMacroPath( nEventId, nTab );
1069 + if( sMacroPath.getLength() )
1071 + switch( nEventId )
1073 + case VBAEVENT_WORKSHEET_ACTIVATE:
1074 + case VBAEVENT_WORKSHEET_CALCULATE:
1075 + case VBAEVENT_WORKSHEET_DEACTIVATE:
1076 + case VBAEVENT_WORKBOOK_ACTIVATE:
1077 + case VBAEVENT_WORKBOOK_DEACTIVATE:
1078 + case VBAEVENT_WORKBOOK_OPEN:
1080 + // no arguments
1081 + break;
1083 + case VBAEVENT_WORKBOOK_SHEET_DEACTIVATE:
1084 + case VBAEVENT_WORKBOOK_SHEET_CALCULATE:
1085 + case VBAEVENT_WORKBOOK_SHEET_ACTIVATE:
1086 + case VBAEVENT_WORKBOOK_NEWSHEET:
1088 + aArgs = uno::Sequence< uno::Any >(1);
1089 + aArgs[0] = createWorkSheet( pShell, nTab );
1090 + break;
1092 + case VBAEVENT_WORKSHEET_CHANGE:
1093 + case VBAEVENT_WORKSHEET_SELECTIONCHANGE:
1095 + // one argument: range
1096 + uno::Any aRange = createRange( rArgs[0] );
1097 + aArgs = uno::Sequence< uno::Any >(1);
1098 + aArgs[0] = aRange;
1099 + break;
1101 + case VBAEVENT_WORKBOOK_SHEET_CHANGE:
1102 + case VBAEVENT_WORKBOOK_SHEET_SELECTIONCHANGE:
1104 + uno::Any aRange = createRange( rArgs[0] );
1105 + aArgs = uno::Sequence< uno::Any >(2);
1106 + aArgs[0] = createWorkSheet( pShell, nTab );
1107 + aArgs[1] = aRange;
1108 + break;
1110 + case VBAEVENT_WORKSHEET_BEFOREDOUBLECLICK:
1111 + case VBAEVENT_WORKSHEET_BEFORERIGHTCLICK:
1113 + // two aruments: range and cancel
1114 + uno::Any aRange = createRange( rArgs[0] );
1115 + aArgs = uno::Sequence< uno::Any >(2);
1116 + aArgs[0] = aRange;
1117 + aArgs[1] <<= bCancel;
1118 + // TODO: process "cancel" action
1119 + break;
1121 + case VBAEVENT_WORKBOOK_SHEET_BEFOREDOUBLECLICK:
1122 + case VBAEVENT_WORKBOOK_SHEET_BEFORERIGHTCLICK:
1124 + uno::Any aRange = createRange( rArgs[0] );
1125 + aArgs = uno::Sequence< uno::Any >(3);
1126 + aArgs[0] = createWorkSheet( pShell, nTab );
1127 + aArgs[1] = aRange;
1128 + aArgs[2] <<= bCancel;
1129 + // TODO: process "cancel" action
1130 + break;
1132 + case VBAEVENT_WORKSHEET_FOLLOWHYPERLINK:
1134 + // one argument: hyperlink
1135 + uno::Any aHyperlink = createHyperlink( rArgs[0] );
1136 + aArgs = uno::Sequence< uno::Any >(1);
1137 + aArgs[0] = aHyperlink;
1138 + break;
1140 + case VBAEVENT_WORKBOOK_SHEET_FOLLOWHYPERLINK:
1142 + uno::Any aHyperlink = createHyperlink( rArgs[0] );
1143 + aArgs = uno::Sequence< uno::Any >(2);
1144 + aArgs[0] = createWorkSheet( pShell, nTab );
1145 + aArgs[1] = aHyperlink;
1146 + break;
1148 + case VBAEVENT_WORKSHEET_PIVOTTABLEUPDATE:
1149 + case VBAEVENT_WORKBOOK_SHEET_PIVOTTABLEUPDATE:
1151 + // one argument: pivottable
1152 + // TODO: not support yet
1153 + return result;
1155 + case VBAEVENT_WORKBOOK_BEFORECLOSE:
1156 + case VBAEVENT_WORKBOOK_BEFOREPRINT:
1158 + // process Cancel argument
1159 + aArgs = uno::Sequence< uno::Any >(1);
1160 + aArgs[0] <<= bCancel;
1161 + executeMacro( pShell, sMacroPath, aArgs, aRet );
1162 + aArgs[0] >>= bCancel;
1163 + return bCancel;
1165 + case VBAEVENT_WORKBOOK_BEFORESAVE:
1167 + // two arguments: SaveAs and Cancel
1168 + aArgs = uno::Sequence< uno::Any >(2);
1169 + aArgs[0] = rArgs[0];
1170 + aArgs[1] <<= bCancel;
1171 + executeMacro( pShell, sMacroPath, aArgs, aRet );
1172 + aArgs[1] >>= bCancel;
1173 + return bCancel;
1175 + case VBAEVENT_WORKBOOK_WINDOWACTIVATE:
1176 + case VBAEVENT_WORKBOOK_WINDOWDEACTIVATE:
1177 + case VBAEVENT_WORKBOOK_WINDOWRESIZE:
1179 + // one argument: windows
1180 + aArgs = uno::Sequence< uno::Any >(1);
1181 + aArgs[0] = createWindow( pShell );
1182 + break;
1184 + default:
1185 + return result;
1188 + // excute the macro
1189 + result = executeMacro( pShell, sMacroPath, aArgs, aRet );
1192 + return result;
1195 +SCTAB ScVbaEventsHelper::getTabFromArgs( const uno::Sequence< uno::Any > aArgs, const sal_Int32 nPos )
1197 + SCTAB nTab = -1;
1198 + uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable( getXSomethingFromArgs< sheet::XCellRangeAddressable >( aArgs, nPos ), uno::UNO_QUERY );
1199 + if( xCellRangeAddressable.is() )
1201 + table::CellRangeAddress aAddress = xCellRangeAddressable->getRangeAddress();
1202 + nTab = aAddress.Sheet;
1204 + return nTab;
1207 +sal_Bool SAL_CALL
1208 +ScVbaEventsHelper::ProcessCompatibleVbaEvent( sal_Int32 nEventId, const uno::Sequence< uno::Any >& aArgs ) throw (uno::RuntimeException)
1210 + SfxObjectShell* pShell = pDoc->GetDocumentShell();
1211 + if( !pShell || mbIgnoreEvents)
1212 + return sal_False;
1214 + // In order to better support "withevents" in the future,
1215 + // it is better to process a event at a time
1216 + SCTAB nTab = INVALID_TAB;
1217 + switch( nEventId )
1219 + // Worksheet
1220 + case VBAEVENT_WORKSHEET_ACTIVATE:
1222 + aArgs[0] >>= nTab;
1223 + if( nTab != INVALID_TAB )
1225 + // process the event
1226 + processVbaEvent( nEventId, aArgs, nTab );
1227 + // recursive process related workbook sheet event.
1228 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_SHEET_ACTIVATE, aArgs );
1230 + break;
1232 + case VBAEVENT_WORKSHEET_BEFOREDOUBLECLICK:
1234 + nTab = getTabFromArgs( aArgs );
1235 + if( nTab != INVALID_TAB )
1237 + processVbaEvent( nEventId, aArgs, nTab );
1238 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_SHEET_BEFOREDOUBLECLICK, aArgs );
1240 + break;
1242 + case VBAEVENT_WORKSHEET_BEFORERIGHTCLICK:
1244 + nTab = getTabFromArgs( aArgs );
1245 + if( nTab != INVALID_TAB )
1247 + processVbaEvent( nEventId, aArgs, nTab );
1248 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_SHEET_BEFORERIGHTCLICK, aArgs );
1250 + break;
1252 + case VBAEVENT_WORKSHEET_CALCULATE:
1254 + aArgs[0] >>= nTab;
1255 + if( nTab != INVALID_TAB )
1257 + processVbaEvent( nEventId, aArgs, nTab );
1258 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_SHEET_CALCULATE, aArgs );
1260 + break;
1262 + case VBAEVENT_WORKSHEET_CHANGE:
1264 + nTab = getTabFromArgs( aArgs );
1265 + if( nTab != INVALID_TAB )
1267 + processVbaEvent( nEventId, aArgs, nTab );
1268 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_SHEET_CHANGE, aArgs );
1270 + break;
1272 + case VBAEVENT_WORKSHEET_DEACTIVATE:
1274 + aArgs[0] >>= nTab;
1275 + if( nTab != INVALID_TAB )
1277 + processVbaEvent( nEventId, aArgs, nTab );
1278 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_SHEET_DEACTIVATE, aArgs );
1280 + break;
1282 + case VBAEVENT_WORKSHEET_FOLLOWHYPERLINK:
1284 + nTab = getTabFromArgs( aArgs );
1285 + if( nTab != INVALID_TAB )
1287 + processVbaEvent( nEventId, aArgs, nTab );
1288 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_SHEET_FOLLOWHYPERLINK, aArgs );
1290 + break;
1292 + case VBAEVENT_WORKSHEET_PIVOTTABLEUPDATE:
1293 + // TODO
1294 + break;
1295 + case VBAEVENT_WORKSHEET_SELECTIONCHANGE:
1297 + nTab = getTabFromArgs( aArgs );
1298 + if( nTab != INVALID_TAB )
1300 + processVbaEvent( nEventId, aArgs, nTab );
1301 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_SHEET_SELECTIONCHANGE, aArgs );
1303 + break;
1305 + // Workbook_sheet
1306 + case VBAEVENT_WORKBOOK_SHEET_ACTIVATE:
1307 + case VBAEVENT_WORKBOOK_SHEET_CALCULATE:
1308 + case VBAEVENT_WORKBOOK_SHEET_DEACTIVATE:
1310 + aArgs[0] >>= nTab;
1311 + if( nTab != INVALID_TAB )
1313 + processVbaEvent( nEventId, aArgs, nTab );
1315 + break;
1317 + case VBAEVENT_WORKBOOK_SHEET_BEFOREDOUBLECLICK:
1318 + case VBAEVENT_WORKBOOK_SHEET_BEFORERIGHTCLICK:
1319 + case VBAEVENT_WORKBOOK_SHEET_CHANGE:
1320 + case VBAEVENT_WORKBOOK_SHEET_FOLLOWHYPERLINK:
1321 + case VBAEVENT_WORKBOOK_SHEET_SELECTIONCHANGE:
1323 + nTab = getTabFromArgs( aArgs );
1324 + if( nTab != INVALID_TAB )
1326 + processVbaEvent( nEventId, aArgs, nTab );
1328 + break;
1330 + case VBAEVENT_WORKBOOK_SHEET_PIVOTTABLEUPDATE:
1331 + // TODO
1332 + break;
1333 + // Workbook
1334 + case VBAEVENT_WORKBOOK_ACTIVATE:
1336 + // if workbook open event do not be fired. fired it before
1337 + // workbook activate event to compatible with MSO.
1338 + if( mbOpened )
1340 + // process workbook activate event
1341 + processVbaEvent( nEventId, aArgs );
1342 + // process workbook window activate event at the same time
1343 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_WINDOWACTIVATE, aArgs );
1345 + break;
1347 + case VBAEVENT_WORKBOOK_DEACTIVATE:
1349 + processVbaEvent( nEventId, aArgs );
1350 + // same as workbook window deactivate
1351 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_WINDOWDEACTIVATE, aArgs );
1352 + break;
1354 + case VBAEVENT_WORKBOOK_OPEN:
1356 + // process workbook open macro
1357 + // does auto open work here?
1358 + if( !mbOpened )
1360 + processVbaEvent( nEventId, aArgs );
1361 + mbOpened = sal_True;
1362 + ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_ACTIVATE, aArgs );
1364 + // register the window listener.
1365 + if( !mpVbaEventsListener )
1367 + mpVbaEventsListener = new VbaEventsListener( this );
1368 + mpVbaEventsListener->startEventsLinstener();
1370 + break;
1372 + case VBAEVENT_WORKBOOK_AUTOOPEN:
1373 + // TODO
1374 + break;
1375 + case VBAEVENT_WORKBOOK_BEFORECLOSE:
1377 + sal_Bool bCancel = processVbaEvent( nEventId, aArgs );
1378 + if( mpVbaEventsListener && !bCancel )
1380 + mpVbaEventsListener->stopEventsLinstener();
1381 + mpVbaEventsListener = NULL;
1383 + return bCancel;
1385 + case VBAEVENT_WORKBOOK_BEFOREPRINT:
1386 + case VBAEVENT_WORKBOOK_BEFORESAVE:
1387 + case VBAEVENT_WORKBOOK_WINDOWACTIVATE:
1388 + case VBAEVENT_WORKBOOK_WINDOWDEACTIVATE:
1389 + case VBAEVENT_WORKBOOK_WINDOWRESIZE:
1391 + return processVbaEvent( nEventId, aArgs );
1393 + case VBAEVENT_WORKBOOK_NEWSHEET:
1395 + aArgs[0] >>= nTab;
1396 + if( nTab != INVALID_TAB )
1398 + processVbaEvent( nEventId, aArgs, nTab );
1400 + break;
1402 + default:
1403 + OSL_TRACE( "Invalid Event" );
1406 + return sal_True;
1409 +::sal_Bool SAL_CALL
1410 +ScVbaEventsHelper::getIgnoreEvents() throw (uno::RuntimeException)
1412 + return mbIgnoreEvents;
1415 +void SAL_CALL
1416 +ScVbaEventsHelper::setIgnoreEvents( ::sal_Bool _ignoreevents ) throw (uno::RuntimeException)
1418 + mbIgnoreEvents = _ignoreevents;
1422 +namespace vbaeventshelper
1424 +namespace sdecl = comphelper::service_decl;
1425 +sdecl::class_<ScVbaEventsHelper, sdecl::with_args<true> > serviceImpl;
1426 +extern sdecl::ServiceDecl const serviceDecl(
1427 + serviceImpl,
1428 + "ScVbaEventsHelper",
1429 + "com.sun.star.document.VbaEventsHelper" );
1431 --- sc/inc/document.hxx.old 2009-04-06 16:41:59.000000000 +0000
1432 +++ sc/inc/document.hxx 2009-04-06 16:42:00.000000000 +0000
1433 @@ -157,6 +157,9 @@ namespace com { namespace sun { namespac
1435 } } }
1437 +namespace com { namespace sun { namespace star { namespace document {
1438 + class XVbaEventsHelper;
1439 +} } } }
1440 #include <svtools/zforlist.hxx>
1442 #ifdef _ZFORLIST_DECLARE_TABLE
1443 @@ -319,6 +322,8 @@ private:
1445 Timer aTrackTimer;
1447 + com::sun::star::uno::Reference< com::sun::star::document::XVbaEventsHelper > mxVbaEventsHelper;
1449 public:
1450 ScTabOpList aTableOpList; // list of ScInterpreterTableOpParams currently in use
1451 ScInterpreterTableOpParams aLastTableOpParams; // remember last params
1452 @@ -1707,6 +1712,8 @@ public:
1453 void GetSortParam( ScSortParam& rParam, SCTAB nTab );
1454 void SetSortParam( ScSortParam& rParam, SCTAB nTab );
1456 + com::sun::star::uno::Reference< com::sun::star::document::XVbaEventsHelper > GetVbaEventsHelper();
1458 /** Should only be GRAM_PODF or GRAM_ODFF. */
1459 void SetStorageGrammar( formula::FormulaGrammar::Grammar eGrammar );
1460 formula::FormulaGrammar::Grammar GetStorageGrammar() const
1461 --- sc/source/core/data/documen2.cxx.old 2009-04-06 16:41:50.000000000 +0000
1462 +++ sc/source/core/data/documen2.cxx 2009-04-06 16:42:00.000000000 +0000
1463 @@ -96,6 +96,7 @@
1464 #include "externalrefmgr.hxx"
1465 #include "tabprotection.hxx"
1466 #include "clipparam.hxx"
1467 +#include <com/sun/star/document/XVbaEventsHelper.hpp>
1469 // pImpl because including lookupcache.hxx in document.hxx isn't wanted, and
1470 // dtor plus helpers are convenient.
1471 @@ -1267,6 +1268,29 @@ void ScDocument::RemoveLookupCache( ScLo
1475 +using namespace com::sun::star;
1476 +uno::Reference< document::XVbaEventsHelper >
1477 +ScDocument::GetVbaEventsHelper()
1479 + if( !mxVbaEventsHelper.is() )
1481 + try
1483 + uno::Reference< lang::XMultiServiceFactory > xSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
1484 + uno::Reference< frame::XModel > xModel( pShell ? pShell->GetModel() : NULL, uno::UNO_QUERY );
1485 + uno::Sequence< uno::Any > aArgs(1);
1486 + aArgs[0] = uno::Any( xModel );
1487 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper( xSF->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.VbaEventsHelper" ) ), aArgs ), uno::UNO_QUERY );
1488 + // helper will always be created successfully.
1489 + mxVbaEventsHelper.set( xVbaEventsHelper, uno::UNO_QUERY );
1491 + catch( uno::Exception& e )
1495 + return mxVbaEventsHelper;
1498 void ScDocument::ClearLookupCaches()
1500 if( pLookupCacheMapImpl )
1501 --- sc/source/ui/docshell/docsh.cxx.old 2009-04-06 16:41:50.000000000 +0000
1502 +++ sc/source/ui/docshell/docsh.cxx 2009-04-06 16:42:00.000000000 +0000
1503 @@ -127,6 +127,13 @@
1504 #include <rtl/logfile.hxx>
1506 #include <comphelper/processfactory.hxx>
1507 +#include "uiitems.hxx"
1508 +#include "cellsuno.hxx"
1509 +#include <com/sun/star/document/XVbaEventsHelper.hpp>
1510 +#include <com/sun/star/document/VbaEventId.hpp>
1512 +using namespace com::sun::star;
1513 +using namespace com::sun::star::document::VbaEventId;
1515 using namespace com::sun::star;
1517 @@ -272,7 +279,11 @@ sal_uInt16 ScDocShell::GetHiddenInformat
1518 void ScDocShell::BeforeXMLLoading()
1520 aDocument.DisableIdle( TRUE );
1522 + // suppress VBA events when loading the xml
1523 + uno::Reference< document::XVbaEventsHelper > xEvt( aDocument.GetVbaEventsHelper() );
1524 + if ( xEvt.is() )
1525 + xEvt->setIgnoreEvents( sal_True );
1527 // prevent unnecessary broadcasts and updates
1528 DBG_ASSERT(pModificator == NULL, "The Modificator should not exist");
1529 pModificator = new ScDocShellModificator( *this );
1530 @@ -357,6 +368,10 @@ void ScDocShell::AfterXMLLoading(sal_Boo
1531 else
1532 aDocument.SetInsertingFromOtherDoc( FALSE );
1534 + // suppress VBA events when loading the xml
1535 + uno::Reference< document::XVbaEventsHelper > xEvt( aDocument.GetVbaEventsHelper() );
1536 + if ( xEvt.is() )
1537 + xEvt->setIgnoreEvents( sal_False );
1538 aDocument.SetImportingXML( FALSE );
1539 aDocument.EnableUndo( TRUE );
1540 bIsEmpty = FALSE;
1541 @@ -498,9 +513,71 @@ BOOL __EXPORT ScDocShell::Load( SfxMediu
1542 return bRet;
1545 +void lcl_processCompatibleSfxHint( uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper, const SfxHint& rHint )
1547 + if (rHint.ISA(ScTablesHint) )
1549 + USHORT nId = ((ScTablesHint&)rHint).GetId();
1550 + SCTAB nTab = ((ScTablesHint&)rHint).GetTab1();
1551 + if( nId == SC_TAB_INSERTED )
1553 + uno::Sequence< uno::Any > aArgs(1);
1554 + aArgs[0] <<= nTab;
1555 + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_NEWSHEET, aArgs );
1558 + else if ( rHint.ISA( SfxEventHint ) )
1560 + ULONG nEventId = ((SfxEventHint&)rHint).GetEventId();
1561 + switch ( nEventId )
1563 + case SFX_EVENT_ACTIVATEDOC:
1565 + uno::Sequence< uno::Any > aArgs;
1566 + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_ACTIVATE, aArgs );
1568 + break;
1569 + case SFX_EVENT_DEACTIVATEDOC:
1571 + uno::Sequence< uno::Any > aArgs;
1572 + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_DEACTIVATE, aArgs );
1574 + break;
1575 + /*case SFX_EVENT_CLOSEDOC :
1577 + uno::Sequence< uno::Any > aArgs;
1578 + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_CLOSE, aArgs );
1580 + break;
1581 + case SFX_EVENT_CLOSEVIEW :
1583 + uno::Sequence< uno::Any > aArgs;
1584 + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_WINDOWCOLSE, aArgs );
1586 + break;
1587 + */
1588 + case SFX_EVENT_OPENDOC:
1590 + // some later than workbook activate.
1591 + uno::Sequence< uno::Any > aArgs;
1592 + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_OPEN, aArgs );
1594 + break;
1595 + default:
1598 + break;
1603 void __EXPORT ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint )
1605 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper ( aDocument.GetVbaEventsHelper(), uno::UNO_QUERY );
1606 + if ( xVbaEventsHelper.is() )
1608 + lcl_processCompatibleSfxHint( xVbaEventsHelper, rHint );
1610 if (rHint.ISA(SfxSimpleHint)) // ohne Parameter
1612 ULONG nSlot = ((const SfxSimpleHint&)rHint).GetId();
1613 @@ -2144,6 +2221,16 @@ USHORT __EXPORT ScDocShell::PrepareClose
1615 DoEnterHandler();
1617 + // start handler for possible veto from DocBefore_Close
1618 + uno::Sequence< uno::Any > aArgs;
1619 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper ( aDocument.GetVbaEventsHelper(), uno::UNO_QUERY );
1620 + if ( !IsInPrepareClose() && xVbaEventsHelper.is() )
1622 + if ( xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_BEFORECLOSE, aArgs ) )
1623 + return sal_False;
1625 + // end handler code
1627 USHORT nRet = SfxObjectShell::PrepareClose( bUI, bForBrowsing );
1628 if (nRet == TRUE) // TRUE = schliessen
1629 aDocument.DisableIdle(TRUE); // nicht mehr drin rumpfuschen !!!
1630 --- sc/source/ui/inc/docsh.hxx.old 2009-04-06 16:41:53.000000000 +0000
1631 +++ sc/source/ui/inc/docsh.hxx 2009-04-06 16:42:00.000000000 +0000
1632 @@ -47,6 +47,7 @@
1633 #include "refreshtimer.hxx"
1635 #include <hash_map>
1636 +#include <cppuhelper/implbase1.hxx>
1638 class ScEditEngineDefaulter;
1639 class FontList;
1640 --- sc/source/ui/unoobj/viewuno.cxx.old 2009-04-06 16:41:58.000000000 +0000
1641 +++ sc/source/ui/unoobj/viewuno.cxx 2009-04-06 16:42:00.000000000 +0000
1642 @@ -71,8 +71,12 @@
1643 #include "gridwin.hxx"
1644 #include <com/sun/star/view/DocumentZoomType.hpp>
1645 #include "AccessibilityHints.hxx"
1646 +#include <com/sun/star/awt/MouseButton.hpp>
1647 +#include <com/sun/star/document/XVbaEventsHelper.hpp>
1648 +#include <com/sun/star/document/VbaEventId.hpp>
1650 using namespace com::sun::star;
1651 +using namespace com::sun::star::document::VbaEventId;
1653 //------------------------------------------------------------------------
1655 @@ -458,6 +462,78 @@ void SAL_CALL ScViewPaneObj::release() t
1656 OWeakObject::release();
1659 +// To process sheet compatibile event
1660 +typedef ::cppu::WeakImplHelper2< awt::XEnhancedMouseClickHandler, view::XSelectionChangeListener > TabViewEventListener_BASE;
1661 +class ScTabViewEventListener: public TabViewEventListener_BASE
1663 +private:
1664 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper;
1665 + ScTabViewObj* pViewObj;
1667 +public:
1668 + ScTabViewEventListener( ScTabViewObj* pObj, uno::Reference< document::XVbaEventsHelper >& rVbaEventsHelper);
1669 + ~ScTabViewEventListener();
1670 + // XEnhancedMouseClickHandler
1671 + virtual sal_Bool SAL_CALL mousePressed( const awt::EnhancedMouseEvent& e ) throw (uno::RuntimeException);
1672 + virtual sal_Bool SAL_CALL mouseReleased( const awt::EnhancedMouseEvent& e ) throw (uno::RuntimeException);
1674 + // XSelectionChangeListener
1675 + virtual void SAL_CALL selectionChanged( const lang::EventObject& aEvent ) throw ( uno::RuntimeException );
1676 + // XEventListener
1677 + virtual void SAL_CALL disposing( const lang::EventObject& aEvent ) throw ( uno::RuntimeException );
1680 +ScTabViewEventListener::ScTabViewEventListener(ScTabViewObj* pObj, uno::Reference< document::XVbaEventsHelper >& rVbaEventsHelper):
1681 + pViewObj( pObj ),xVbaEventsHelper( rVbaEventsHelper )
1685 +ScTabViewEventListener::~ScTabViewEventListener()
1689 +void SAL_CALL ScTabViewEventListener::disposing( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException )
1693 +sal_Bool SAL_CALL ScTabViewEventListener::mousePressed( const awt::EnhancedMouseEvent& e ) throw (uno::RuntimeException)
1695 + sal_Bool result = sal_False;
1696 + // process BeforeDoubleClick and BeforeRightClick events
1697 + if( e.ClickCount == 2 || e.Buttons == ::com::sun::star::awt::MouseButton::RIGHT )
1699 + // ensure the target is a cell
1700 + uno::Reference< table::XCell > xCell( e.Target, uno::UNO_QUERY );
1701 + if( xCell.is() && xVbaEventsHelper.is() && pViewObj)
1703 + uno::Sequence< uno::Any > aArgs(1);
1704 + aArgs[0] = pViewObj->getSelection();
1705 + sal_Int32 nEventId = VBAEVENT_WORKSHEET_BEFORERIGHTCLICK;
1706 + if( e.ClickCount == 2 )
1707 + nEventId = VBAEVENT_WORKSHEET_BEFOREDOUBLECLICK;
1709 + result = xVbaEventsHelper->ProcessCompatibleVbaEvent( nEventId, aArgs );
1710 + // TODO: process Cancel argument
1713 + return result;
1716 +sal_Bool SAL_CALL ScTabViewEventListener::mouseReleased( const awt::EnhancedMouseEvent&/*e*/) throw (uno::RuntimeException)
1718 + return sal_False;
1721 +void SAL_CALL ScTabViewEventListener::selectionChanged( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException )
1723 + if ( xVbaEventsHelper.is() && pViewObj)
1725 + uno::Sequence< uno::Any > aArgs(1);
1726 + aArgs[0] = pViewObj->getSelection();
1727 + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKSHEET_SELECTIONCHANGE, aArgs );
1731 //------------------------------------------------------------------------
1733 // Default-ctor wird fuer SMART_REFLECTION_IMPLEMENTATION gebraucht
1734 @@ -482,7 +558,19 @@ ScTabViewObj::ScTabViewObj( ScTabViewShe
1735 bDrawSelModeSet(sal_False),
1736 bFilteredRangeSelection(sal_True)
1738 - //! Listening oder so
1739 + if( pViewSh )
1741 + ScViewData* pViewData = pViewSh->GetViewData();
1742 + if( pViewData )
1744 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper (pViewData->GetDocument()->GetVbaEventsHelper(), uno::UNO_QUERY );
1745 + ScTabViewEventListener* pEventListener = new ScTabViewEventListener( this, xVbaEventsHelper );
1746 + uno::Reference< awt::XEnhancedMouseClickHandler > aMouseClickHandler( *pEventListener, uno::UNO_QUERY );
1747 + addEnhancedMouseClickHandler( aMouseClickHandler );
1748 + uno::Reference< view::XSelectionChangeListener > aSelectionChangeListener( *pEventListener, uno::UNO_QUERY );
1749 + addSelectionChangeListener( aSelectionChangeListener );
1754 ScTabViewObj::~ScTabViewObj()
1755 --- sc/source/ui/unoobj/docuno.cxx.old 2009-04-06 16:41:59.000000000 +0000
1756 +++ sc/source/ui/unoobj/docuno.cxx 2009-04-06 16:42:00.000000000 +0000
1757 @@ -97,7 +97,10 @@
1758 #include <svx/unoshape.hxx>
1759 #endif
1761 +#include <com/sun/star/document/XVbaEventsHelper.hpp>
1762 +#include <com/sun/star/document/VbaEventId.hpp>
1763 using namespace com::sun::star;
1764 +using namespace com::sun::star::document::VbaEventId;
1766 //------------------------------------------------------------------------
1768 @@ -313,6 +316,7 @@ uno::Any SAL_CALL ScModelObj::queryInter
1769 SC_QUERYINTERFACE( document::XLinkTargetSupplier )
1770 SC_QUERYINTERFACE( beans::XPropertySet )
1771 SC_QUERYINTERFACE( document::XCodeNameQuery )
1772 + SC_QUERYINTERFACE( document::XDocumentEventCompatibleHelper)
1773 SC_QUERYINTERFACE( lang::XMultiServiceFactory )
1774 SC_QUERYINTERFACE( lang::XServiceInfo )
1775 SC_QUERYINTERFACE( util::XChangesNotifier )
1776 @@ -1762,6 +1766,39 @@ ScModelObj::getCodeNameForObject( const
1777 // Probably should throw here ( if !bMatched )
1778 return sCodeName;
1780 +// XVbaEventHelper
1781 +// For Vba Event
1782 +sal_Bool SAL_CALL
1783 +ScModelObj::processCompatibleEvent( sal_Int16 nSlotId ) throw( ::com::sun::star::uno::RuntimeException )
1785 + USHORT nId = (USHORT)nSlotId;
1786 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper( GetDocument()->GetVbaEventsHelper(), uno::UNO_QUERY );
1787 + if( xVbaEventsHelper.is() )
1789 + switch( nId )
1791 + case SID_SAVEDOC:
1793 + uno::Sequence< uno::Any > aArgs(1);
1794 + aArgs[0] <<= sal_False;
1795 + return xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_BEFORESAVE, aArgs );
1797 + case SID_SAVEASDOC:
1799 + uno::Sequence< uno::Any > aArgs(1);
1800 + aArgs[0] <<= sal_True;
1801 + return xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_BEFORESAVE, aArgs );
1803 + case SID_PRINTDOC:
1804 + case SID_PRINTDOCDIRECT:
1806 + uno::Sequence< uno::Any > aArgs;
1807 + return xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_BEFOREPRINT, aArgs );
1811 + return sal_False;
1813 // XServiceInfo
1815 rtl::OUString SAL_CALL ScModelObj::getImplementationName() throw(uno::RuntimeException)
1816 --- sc/inc/docuno.hxx.old 2009-04-06 16:41:59.000000000 +0000
1817 +++ sc/inc/docuno.hxx 2009-04-06 16:42:00.000000000 +0000
1818 @@ -56,6 +56,7 @@
1819 #include <com/sun/star/beans/XPropertySet.hpp>
1820 #include <com/sun/star/sheet/XCellRangesAccess.hpp>
1821 #include <com/sun/star/util/XChangesNotifier.hpp>
1822 +#include <com/sun/star/document/XDocumentEventCompatibleHelper.hpp>
1823 #include <cppuhelper/implbase2.hxx>
1824 #include <cppuhelper/implbase3.hxx>
1825 #include <cppuhelper/implbase4.hxx>
1826 @@ -92,6 +93,7 @@ class SC_DLLPUBLIC ScModelObj : public S
1827 public com::sun::star::document::XLinkTargetSupplier,
1828 public com::sun::star::beans::XPropertySet,
1829 public com::sun::star::document::XCodeNameQuery,
1830 + public com::sun::star::document::XDocumentEventCompatibleHelper,
1831 public SvxFmMSFactory, // derived from XMultiServiceFactory
1832 public com::sun::star::lang::XServiceInfo,
1833 public ::com::sun::star::util::XChangesNotifier
1834 @@ -320,6 +322,8 @@ public:
1835 throw (::com::sun::star::uno::RuntimeException);
1836 virtual rtl::OUString SAL_CALL getCodeNameForObject( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& aObj )
1837 throw(::com::sun::star::uno::RuntimeException);
1838 + // XVbaEventHelper
1839 + virtual sal_Bool SAL_CALL processCompatibleEvent( sal_Int16 nEventId ) throw (::com::sun::star::uno::RuntimeException);
1843 --- sc/source/ui/view/gridwin.cxx.old 2009-04-06 16:41:50.000000000 +0000
1844 +++ sc/source/ui/view/gridwin.cxx 2009-04-06 16:42:00.000000000 +0000
1845 @@ -130,7 +130,13 @@
1846 #include <svx/sdr/overlay/overlaymanager.hxx>
1847 #include <vcl/svapp.hxx>
1849 +#include "cellsuno.hxx"
1851 +#include <com/sun/star/document/XVbaEventsHelper.hpp>
1852 +#include <com/sun/star/document/VbaEventId.hpp>
1854 using namespace com::sun::star;
1855 +using namespace com::sun::star::document::VbaEventId;
1856 using ::com::sun::star::uno::Sequence;
1857 using ::com::sun::star::uno::Any;
1859 @@ -356,6 +362,32 @@ void lcl_UnLockComment( ScDrawView* pVie
1863 +sal_Bool lcl_GetHyperlinkCell(ScDocument* pDoc, SCCOL& rPosX, SCROW& rPosY, SCTAB nTab, ScBaseCell*& rpCell )
1865 + BOOL bFound = FALSE;
1866 + do
1868 + pDoc->GetCell( rPosX, rPosY, nTab, rpCell );
1869 + if ( !rpCell || rpCell->GetCellType() == CELLTYPE_NOTE )
1871 + if ( rPosX <= 0 )
1872 + return FALSE; // alles leer bis links
1873 + else
1874 + --rPosX; // weitersuchen
1876 + else if ( rpCell->GetCellType() == CELLTYPE_EDIT)
1877 + bFound = TRUE;
1878 + else if (rpCell->GetCellType() == CELLTYPE_FORMULA &&
1879 + static_cast<ScFormulaCell*>(rpCell)->IsHyperLinkCell())
1880 + bFound = TRUE;
1881 + else
1882 + return FALSE; // andere Zelle
1884 + while ( !bFound );
1886 + return bFound;
1889 //==================================================================
1891 // WB_DIALOGCONTROL noetig fuer UNO-Controls
1892 @@ -1403,6 +1435,7 @@ void ScGridWindow::HandleMouseButtonDown
1893 SCCOL nOldColFBox = bWasFilterBox ? pFilterBox->GetCol() : 0;
1894 SCROW nOldRowFBox = bWasFilterBox ? pFilterBox->GetRow() : 0;
1895 #endif
1896 +#include "cellsuno.hxx"
1898 ClickExtern(); // loescht FilterBox, wenn vorhanden
1900 @@ -2085,6 +2118,26 @@ void __EXPORT ScGridWindow::MouseButtonU
1902 nMouseStatus = SC_GM_NONE; // keinen Doppelklick anfangen
1903 ScGlobal::OpenURL( aUrl, aTarget );
1905 + // fire worksheet_followhyperlink event
1906 + Point aPos = rMEvt.GetPosPixel();
1907 + SCsCOL nPosX;
1908 + SCsROW nPosY;
1909 + SCTAB nTab = pViewData->GetTabNo();
1910 + pViewData->GetPosFromPixel( aPos.X(), aPos.Y(), eWhich, nPosX, nPosY );
1911 + ScBaseCell* pCell = NULL;
1913 + BOOL bFound = lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell );
1914 + if( bFound )
1916 + ScAddress aCellPos( nPosX, nPosY, nTab );
1917 + ScCellObj* pObj = new ScCellObj( pViewData->GetDocShell(), aCellPos );
1918 + uno::Sequence< uno::Any > aArgs(1);
1919 + aArgs[0] = uno::makeAny(uno::Reference<uno::XInterface>(static_cast<cppu::OWeakObject*>(pObj)));
1920 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper ( pViewData->GetDocument()->GetVbaEventsHelper(), uno::UNO_QUERY );
1921 + if( xVbaEventsHelper.is() )
1922 + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKSHEET_FOLLOWHYPERLINK, aArgs );
1924 return;
1927 @@ -2412,7 +2465,7 @@ long ScGridWindow::PreNotify( NotifyEven
1928 lcl_InitMouseEvent( aEvent, *rNEvt.GetMouseEvent() );
1929 if ( rNEvt.GetWindow() )
1930 aEvent.Source = rNEvt.GetWindow()->GetComponentInterface();
1931 - if ( nType == EVENT_MOUSEBUTTONDOWN)
1932 + if ( nType == EVENT_MOUSEBUTTONDOWN )
1933 pImp->MousePressed( aEvent );
1934 else
1935 pImp->MouseReleased( aEvent );
1936 @@ -4827,26 +4880,9 @@ BOOL ScGridWindow::GetEditUrlOrError( BO
1937 ScDocument* pDoc = pDocSh->GetDocument();
1938 ScBaseCell* pCell = NULL;
1940 - BOOL bFound = FALSE;
1941 - do
1943 - pDoc->GetCell( nPosX, nPosY, nTab, pCell );
1944 - if ( !pCell || pCell->GetCellType() == CELLTYPE_NOTE )
1946 - if ( nPosX <= 0 )
1947 - return FALSE; // alles leer bis links
1948 - else
1949 - --nPosX; // weitersuchen
1951 - else if ( pCell->GetCellType() == CELLTYPE_EDIT)
1952 - bFound = TRUE;
1953 - else if (pCell->GetCellType() == CELLTYPE_FORMULA &&
1954 - static_cast<ScFormulaCell*>(pCell)->IsHyperLinkCell())
1955 - bFound = TRUE;
1956 - else
1957 - return FALSE; // andere Zelle
1959 - while ( !bFound );
1960 + BOOL bFound = lcl_GetHyperlinkCell( pDoc, nPosX, nPosY, nTab, pCell );
1961 + if( !bFound )
1962 + return FALSE;
1964 ScHideTextCursor aHideCursor( pViewData, eWhich ); // before GetEditArea (MapMode is changed)
1966 --- sc/source/ui/view/tabview3.cxx.old 2009-04-06 16:41:50.000000000 +0000
1967 +++ sc/source/ui/view/tabview3.cxx 2009-04-06 16:42:00.000000000 +0000
1968 @@ -82,6 +82,10 @@
1969 #include "tabprotection.hxx"
1971 #include <com/sun/star/chart2/data/HighlightedRange.hpp>
1972 +#include <com/sun/star/document/XVbaEventsHelper.hpp>
1973 +#include <com/sun/star/document/VbaEventId.hpp>
1975 +using namespace com::sun::star::document::VbaEventId;
1977 namespace
1979 @@ -1600,6 +1604,17 @@ void ScTabView::SetTabNo( SCTAB nTab, BO
1980 // nicht InputEnterHandler wegen Referenzeingabe !
1982 ScDocument* pDoc = aViewData.GetDocument();
1983 + if( !bNew )
1985 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper ( pDoc->GetVbaEventsHelper(), uno::UNO_QUERY );
1986 + if( xVbaEventsHelper.is() )
1988 + uno::Sequence< uno::Any > aArgs(1);
1989 + aArgs[0] <<= aViewData.GetTabNo();
1990 + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKSHEET_DEACTIVATE, aArgs );
1994 pDoc->MakeTable( nTab );
1996 SCTAB nTabCount = pDoc->GetTableCount();
1997 @@ -1698,8 +1713,20 @@ void ScTabView::SetTabNo( SCTAB nTab, BO
1998 if ( pGridWin[i]->IsVisible() )
1999 pGridWin[i]->UpdateEditViewPos();
2003 TabChanged(); // DrawView
2005 + if( !bNew )
2007 + uno::Reference< document::XVbaEventsHelper > xVbaEventsHelper ( pDoc->GetVbaEventsHelper(), uno::UNO_QUERY );
2008 + if( xVbaEventsHelper.is() )
2010 + uno::Sequence< uno::Any > aArgs(1);
2011 + aArgs[0] <<= aViewData.GetTabNo();
2012 + xVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKSHEET_ACTIVATE, aArgs );
2016 aViewData.GetViewShell()->WindowChanged(); // falls das aktive Fenster anders ist
2017 if ( !bUnoRefDialog )
2018 aViewData.GetViewShell()->DisconnectAllClients(); // important for floating frames
2019 --- sc/source/ui/vba/makefile.mk.old 2009-04-06 16:41:59.000000000 +0000
2020 +++ sc/source/ui/vba/makefile.mk 2009-04-06 16:42:00.000000000 +0000
2021 @@ -134,7 +134,8 @@ SLOFILES= \
2022 $(SLO)$/vbapagebreaks.obj \
2023 $(SLO)$/vbaspinbutton.obj \
2024 $(SLO)$/vbaimage.obj \
2025 - $(SLO)$/service.obj
2026 + $(SLO)$/service.obj \
2027 + $(SLO)$/vbaeventshelper.obj
2029 # --- Targets ------------------------------------------------------
2031 --- sc/source/ui/vba/service.cxx.old 2009-04-02 10:45:35.000000000 +0000
2032 +++ sc/source/ui/vba/service.cxx 2009-04-06 16:42:00.000000000 +0000
2033 @@ -69,6 +69,10 @@ namespace hyperlink
2035 extern sdecl::ServiceDecl const serviceDecl;
2037 +namespace vbaeventshelper
2039 +extern sdecl::ServiceDecl const serviceDecl;
2042 extern "C"
2044 @@ -86,7 +90,7 @@ extern "C"
2046 // Component registration
2047 if ( component_writeInfoHelper( pServiceManager, pRegistryKey,
2048 - range::serviceDecl, workbook::serviceDecl, worksheet::serviceDecl, globals::serviceDecl, userform::serviceDecl, window::serviceDecl, hyperlink::serviceDecl ) )
2049 + range::serviceDecl, workbook::serviceDecl, worksheet::serviceDecl, globals::serviceDecl, userform::serviceDecl, window::serviceDecl, hyperlink::serviceDecl ) && component_writeInfoHelper( pServiceManager, pRegistryKey, vbaeventshelper::serviceDecl ) )
2051 // Singleton registration
2053 @@ -115,6 +119,8 @@ extern "C"
2054 OSL_TRACE("In component_getFactory for %s", pImplName );
2055 void* pRet = component_getFactoryHelper(
2056 pImplName, pServiceManager, pRegistryKey, range::serviceDecl, workbook::serviceDecl, worksheet::serviceDecl, globals::serviceDecl, userform::serviceDecl, window::serviceDecl, hyperlink::serviceDecl );
2057 + if( !pRet )
2058 + pRet = component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey, vbaeventshelper::serviceDecl );
2059 OSL_TRACE("Ret is 0x%x", pRet);
2060 return pRet;
2062 --- sfx2/inc/sfx2/objsh.hxx.old 2009-04-06 16:41:53.000000000 +0000
2063 +++ sfx2/inc/sfx2/objsh.hxx 2009-04-06 16:42:00.000000000 +0000
2064 @@ -308,6 +308,7 @@ public:
2065 void SetNoName();
2066 sal_Bool IsInModalMode() const;
2067 sal_Bool HasModalViews() const;
2068 + sal_Bool IsInPrepareClose() const;
2069 sal_Bool IsHelpDocument() const;
2071 sal_Bool IsDocShared() const;
2072 @@ -408,7 +409,8 @@ public:
2073 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams,
2074 ::com::sun::star::uno::Any& aRet,
2075 ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex,
2076 - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam
2077 + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam,
2078 + bool bRaiseError = true
2081 static ErrCode CallXScript(
2082 @@ -417,7 +419,8 @@ public:
2083 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams,
2084 ::com::sun::star::uno::Any& aRet,
2085 ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex,
2086 - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam
2087 + ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam,
2088 + bool bRaiseError = true
2091 /** adjusts the internal macro mode, according to the current security settings
2092 --- sfx2/source/doc/objmisc.cxx.old 2009-04-02 10:43:58.000000000 +0000
2093 +++ sfx2/source/doc/objmisc.cxx 2009-04-06 16:42:00.000000000 +0000
2094 @@ -1632,7 +1632,7 @@ namespace
2097 ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptContext, const ::rtl::OUString& _rScriptURL,
2098 - const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam )
2099 + const Sequence< Any >& aParams, Any& aRet, Sequence< sal_Int16 >& aOutParamIndex, Sequence< Any >& aOutParam, bool bRaiseError )
2101 OSL_TRACE( "in CallXScript" );
2102 ErrCode nErr = ERRCODE_NONE;
2103 @@ -1673,7 +1673,7 @@ ErrCode SfxObjectShell::CallXScript( con
2104 nErr = ERRCODE_BASIC_INTERNAL_ERROR;
2107 - if ( bCaughtException )
2108 + if ( bCaughtException && bRaiseError )
2110 ::std::auto_ptr< VclAbstractDialog > pScriptErrDlg;
2111 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
2112 @@ -1697,9 +1697,9 @@ ErrCode SfxObjectShell::CallXScript( con
2113 ::com::sun::star::uno::Any& aRet,
2114 ::com::sun::star::uno::Sequence< sal_Int16 >& aOutParamIndex,
2115 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&
2116 - aOutParam)
2117 + aOutParam, bool bRaiseError )
2119 - return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam );
2120 + return CallXScript( GetModel(), rScriptURL, aParams, aRet, aOutParamIndex, aOutParam, bRaiseError );
2123 //-------------------------------------------------------------------------
2124 --- sfx2/source/doc/objserv.cxx.old 2009-04-06 16:41:53.000000000 +0000
2125 +++ sfx2/source/doc/objserv.cxx 2009-04-06 16:42:00.000000000 +0000
2126 @@ -103,6 +103,7 @@
2127 #include <com/sun/star/embed/XTransactedObject.hpp>
2128 #include <com/sun/star/util/XCloneable.hpp>
2129 #include <com/sun/star/document/XDocumentProperties.hpp>
2130 +#include <com/sun/star/document/XDocumentEventCompatibleHelper.hpp>
2132 #include "helpid.hrc"
2134 @@ -507,6 +508,18 @@ void SfxObjectShell::ExecFile_Impl(SfxRe
2135 case SID_SAVEASDOC:
2136 case SID_SAVEDOC:
2138 + if( nId == SID_SAVEDOC || nId == SID_SAVEASDOC )
2140 + uno::Reference< document::XDocumentEventCompatibleHelper > xVbaEventHelper( GetModel(), uno::UNO_QUERY );
2141 + if( xVbaEventHelper.is() )
2143 + if( xVbaEventHelper->processCompatibleEvent( nId ) )
2145 + rReq.SetReturnValue( SfxBoolItem( 0, sal_True ) );
2146 + return;
2150 //!! detaillierte Auswertung eines Fehlercodes
2151 SfxObjectShellRef xLock( this );
2153 --- sfx2/source/view/viewprn.cxx.old 2009-04-02 10:44:00.000000000 +0000
2154 +++ sfx2/source/view/viewprn.cxx 2009-04-06 16:42:00.000000000 +0000
2155 @@ -32,6 +32,7 @@
2156 #include "precompiled_sfx2.hxx"
2158 #include <com/sun/star/document/XDocumentProperties.hpp>
2159 +#include <com/sun/star/document/XDocumentEventCompatibleHelper.hpp>
2160 #include <com/sun/star/view/PrintableState.hpp>
2161 #include <svtools/itempool.hxx>
2162 #ifndef _MSGBOX_HXX //autogen
2163 @@ -67,6 +68,8 @@
2164 #include "view.hrc"
2165 #include "helpid.hrc"
2167 +using namespace com::sun::star;
2169 TYPEINIT1(SfxPrintingHint, SfxHint);
2171 // -----------------------------------------------------------------------
2172 @@ -405,6 +408,22 @@ void SfxViewShell::ExecPrint_Impl( SfxRe
2173 case SID_SETUPPRINTER:
2174 case SID_PRINTER_NAME :
2176 + if( nId == SID_PRINTDOC )
2178 + SfxObjectShell* pDoc = GetObjectShell();
2179 + if( pDoc )
2181 + uno::Reference< document::XDocumentEventCompatibleHelper > xVbaEventHelper( pDoc->GetModel(), uno::UNO_QUERY );
2182 + if( xVbaEventHelper.is() )
2184 + if( xVbaEventHelper->processCompatibleEvent( nId ) )
2186 + rReq.SetReturnValue(SfxBoolItem(0,FALSE));
2187 + return;
2192 // quiet mode (AppEvent, API call)
2193 SFX_REQUEST_ARG(rReq, pSilentItem, SfxBoolItem, SID_SILENT, FALSE);
2194 bSilent = pSilentItem && pSilentItem->GetValue();
2195 @@ -717,6 +736,15 @@ void SfxViewShell::ExecPrint_Impl( SfxRe
2196 if ( SID_PRINTDOCDIRECT == nId )
2198 SfxObjectShell* pDoc = GetObjectShell();
2199 + uno::Reference< document::XDocumentEventCompatibleHelper > xVbaEventHelper( pDoc->GetModel(), uno::UNO_QUERY );
2200 + if( xVbaEventHelper.is() )
2202 + if( xVbaEventHelper->processCompatibleEvent( nId ) )
2204 + rReq.SetReturnValue(SfxBoolItem(0,FALSE));
2205 + return;
2208 bool bDetectHidden = ( !bSilent && pDoc );
2209 if ( bDetectHidden && pDoc->QueryHiddenInformation( WhenPrinting, NULL ) != RET_YES )
2210 return;
2211 --- sfx2/source/doc/objxtor.cxx.old 2009-04-02 10:43:58.000000000 +0000
2212 +++ sfx2/source/doc/objxtor.cxx 2009-04-06 16:42:00.000000000 +0000
2213 @@ -579,6 +579,13 @@ SfxObjectShell* SfxObjectShell::Current(
2214 return pFrame ? pFrame->GetObjectShell() : 0;
2217 +//-------------------------------------------------------------------------
2219 +sal_Bool SfxObjectShell::IsInPrepareClose() const
2221 + return pImp->bInPrepareClose;
2224 //------------------------------------------------------------------------
2226 struct BoolEnv_Impl