update ooo310-m15
[ooovba.git] / applied_patches / 0439-vba-fix-workbook-resize-core.diff
blob11797641a46d65a573fb03439dabab8c0451d1ad
1 Index: sc/source/ui/vba/vbaeventshelper.hxx
2 ===================================================================
3 --- sc/source/ui/vba/vbaeventshelper.hxx (revision 271848)
4 +++ sc/source/ui/vba/vbaeventshelper.hxx (working copy)
5 @@ -40,6 +40,7 @@
6 #include <cppuhelper/implbase1.hxx>
7 #include <com/sun/star/document/VbaEventId.hpp>
8 #include <com/sun/star/document/XVbaEventsHelper.hpp>
9 +#include <com/sun/star/awt/XWindowListener.hpp>
10 #include "excelvbahelper.hxx"
12 #define INVALID_TAB -1
13 @@ -54,7 +55,7 @@
14 ScDocument* pDoc;
15 ScDocShell* pDocShell;
16 css::uno::Reference< css::uno::XComponentContext > m_xContext;
17 - VbaEventsListener* mpVbaEventsListener;
18 + css::uno::Reference< css::awt::XWindowListener > m_xVbaEventsListener;
19 sal_Bool mbOpened;
20 sal_Bool mbIgnoreEvents;
22 @@ -69,7 +70,7 @@
23 sal_Bool processVbaEvent( const sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs, const SCTAB nTab = INVALID_TAB );
25 public:
26 - ScVbaEventsHelper( ScDocument* pDocument ):pDoc( pDocument ), mpVbaEventsListener( NULL ), mbOpened( sal_False ){};
27 + ScVbaEventsHelper( ScDocument* pDocument ):pDoc( pDocument ), mbOpened( sal_False ){};
28 ScVbaEventsHelper( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext > const& xContext );
29 ~ScVbaEventsHelper();
30 ScDocument* getDocument() { return pDoc; };
31 Index: sc/source/ui/vba/vbaeventshelper.cxx
32 ===================================================================
33 --- sc/source/ui/vba/vbaeventshelper.cxx (revision 271848)
34 +++ sc/source/ui/vba/vbaeventshelper.cxx (working copy)
35 @@ -49,7 +49,6 @@
36 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
37 #include <com/sun/star/sheet/XSpreadsheet.hpp>
38 #include <com/sun/star/container/XNamed.hpp>
39 -#include <com/sun/star/awt/XWindowListener.hpp>
40 #include <com/sun/star/awt/WindowEvent.hpp>
41 #include <com/sun/star/lang/EventObject.hpp>
42 #include <com/sun/star/util/XCloseListener.hpp>
43 @@ -64,6 +63,7 @@
44 #include <convuno.hxx>
45 #include <map>
46 #include <svx/msvbahelper.hxx>
47 +#include <vcl/svapp.hxx>
49 using namespace std;
50 using namespace com::sun::star;
51 @@ -140,19 +140,20 @@
52 // This class is to process Workbook window related event
53 class VbaEventsListener : public WindowListener_BASE
55 + ::osl::Mutex m_aMutex;
56 ScVbaEventsHelper* pVbaEventsHelper;
57 uno::Reference< frame::XModel > m_xModel;
58 - sal_Bool m_bPrepare;
59 sal_Bool m_bWindowResized;
60 sal_Bool m_bBorderChanged;
61 protected :
62 uno::Reference< awt::XWindow > GetContainerWindow();
63 uno::Reference< frame::XFrame > GetFrame();
64 sal_Bool IsMouseReleased();
65 - DECL_LINK( fireResizeMacro, Timer* );
66 + DECL_LINK( fireResizeMacro, void* );
67 void processWindowResizeMacro();
68 public :
69 VbaEventsListener( ScVbaEventsHelper* pHelper );
70 + ~VbaEventsListener();
71 void startEventsLinstener();
72 void stopEventsLinstener();
73 // XWindowListener
74 @@ -169,11 +170,16 @@
76 VbaEventsListener::VbaEventsListener( ScVbaEventsHelper* pHelper ) : pVbaEventsHelper( pHelper )
78 + OSL_TRACE("VbaEventsListener::VbaEventsListener( 0x%x ) - ctor ", this );
79 m_xModel.set( pVbaEventsHelper->getDocument()->GetDocumentShell()->GetModel(), uno::UNO_QUERY );
80 - m_bPrepare = sal_False;
81 m_bWindowResized = sal_False;
82 m_bBorderChanged = sal_False;
85 +VbaEventsListener::~VbaEventsListener()
87 + OSL_TRACE("VbaEventsListener::~VbaEventsListener( 0x%x ) - dtor ", this );
89 uno::Reference< frame::XFrame >
90 VbaEventsListener::GetFrame()
92 @@ -286,41 +292,39 @@
93 pVbaEventsHelper = NULL;
97 void
98 VbaEventsListener::processWindowResizeMacro()
100 + OSL_TRACE("**** Attempt to FIRE MACRO **** ");
101 if( pVbaEventsHelper )
102 pVbaEventsHelper->ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_WINDOWRESIZE, uno::Sequence< uno::Any >() );
104 -IMPL_LINK( VbaEventsListener, fireResizeMacro, Timer*, pTimer )
106 +IMPL_LINK( VbaEventsListener, fireResizeMacro, void*, pParam )
108 - if( pVbaEventsHelper && m_bPrepare && pTimer )
109 + if ( pVbaEventsHelper )
111 if( IsMouseReleased() )
113 - pTimer->Stop();
114 - delete pTimer;
115 - pTimer = 0;
116 - m_bPrepare = sal_False;
117 - processWindowResizeMacro();
119 + processWindowResizeMacro();
121 + release();
122 return 0;
125 void SAL_CALL
126 VbaEventsListener::windowResized( const awt::WindowEvent& /*aEvent*/ ) throw ( uno::RuntimeException )
128 + ::osl::MutexGuard aGuard( m_aMutex );
129 // Workbook_window_resize event
130 - OSL_TRACE("VbaEventsListener::windowResized");
131 m_bWindowResized = sal_True;
132 Window* pWindow = (VCLUnoHelper::GetWindow( GetContainerWindow() ) );
133 - if( pWindow && !m_bPrepare && m_bBorderChanged )
135 + if( pWindow && m_bBorderChanged )
137 - m_bPrepare = sal_True;
138 m_bBorderChanged = m_bWindowResized = sal_False;
139 - AutoTimer* pTimer = new AutoTimer();
140 - pTimer->SetTimeoutHdl( LINK( this, VbaEventsListener, fireResizeMacro ) );
141 - pTimer->Start();
142 + acquire(); // ensure we don't get deleted before the event is handled
143 + Application::PostUserEvent( LINK( this, VbaEventsListener, fireResizeMacro ), NULL );
146 void SAL_CALL
147 @@ -341,6 +345,8 @@
148 void SAL_CALL
149 VbaEventsListener::disposing( const lang::EventObject& /*aEvent*/ ) throw ( uno::RuntimeException )
151 + ::osl::MutexGuard aGuard( m_aMutex );
152 + OSL_TRACE("VbaEventsListener::disposing(0x%x)", this);
153 pVbaEventsHelper = NULL;
155 void SAL_CALL
156 @@ -351,23 +357,21 @@
157 void SAL_CALL
158 VbaEventsListener::notifyClosing( const lang::EventObject& Source ) throw (uno::RuntimeException)
160 - OSL_TRACE("VbaEventsListener::notifyClosing");
161 + ::osl::MutexGuard aGuard( m_aMutex );
162 stopEventsLinstener();
164 void SAL_CALL
165 VbaEventsListener::borderWidthsChanged( const uno::Reference< uno::XInterface >& aObject, const frame::BorderWidths& aNewSize ) throw (uno::RuntimeException)
167 + ::osl::MutexGuard aGuard( m_aMutex );
168 // work with WindowResized event to guard Window Resize event.
169 - OSL_TRACE("VbaEventsListener::borderWidthsChanged");
170 m_bBorderChanged = sal_True;
171 Window* pWindow = (VCLUnoHelper::GetWindow( GetContainerWindow() ) );
172 - if( pWindow && !m_bPrepare && m_bWindowResized )
173 + if( pWindow && m_bWindowResized )
175 - m_bPrepare = sal_True;
176 m_bWindowResized = m_bBorderChanged = sal_False;
177 - AutoTimer* pTimer = new AutoTimer();
178 - pTimer->SetTimeoutHdl( LINK( this, VbaEventsListener, fireResizeMacro ) );
179 - pTimer->Start();
180 + acquire(); // ensure we don't get deleted before the timer fires.
181 + Application::PostUserEvent( LINK( this, VbaEventsListener, fireResizeMacro ), NULL );
185 @@ -456,7 +460,7 @@
188 ScVbaEventsHelper::ScVbaEventsHelper( uno::Sequence< css::uno::Any > const& aArgs, uno::Reference< uno::XComponentContext > const& xContext )
189 - : m_xContext( xContext ), mpVbaEventsListener( NULL ), mbOpened( sal_False ), mbIgnoreEvents( sal_False )
190 + : m_xContext( xContext ), mbOpened( sal_False ), mbIgnoreEvents( sal_False )
192 uno::Reference< frame::XModel > xModel ( getXSomethingFromArgs< frame::XModel >( aArgs, 0 ), uno::UNO_QUERY );
193 pDocShell = excel::getDocShell( xModel );
194 @@ -469,10 +473,6 @@
196 ScVbaEventsHelper::~ScVbaEventsHelper()
198 - if( mpVbaEventsListener )
200 - mpVbaEventsListener = NULL;
204 rtl::OUString
205 @@ -993,10 +993,11 @@
206 ProcessCompatibleVbaEvent( VBAEVENT_WORKBOOK_ACTIVATE, aArgs );
208 // register the window listener.
209 - if( !mpVbaEventsListener )
210 + if( !m_xVbaEventsListener.is() )
212 - mpVbaEventsListener = new VbaEventsListener( this );
213 - mpVbaEventsListener->startEventsLinstener();
214 + m_xVbaEventsListener = new VbaEventsListener( this );
215 + VbaEventsListener* pEventsListener = dynamic_cast< VbaEventsListener* >( m_xVbaEventsListener.get() );
216 + pEventsListener->startEventsLinstener();
218 break;
220 @@ -1006,10 +1007,11 @@
221 case VBAEVENT_WORKBOOK_BEFORECLOSE:
223 sal_Bool bCancel = processVbaEvent( nEventId, aArgs );
224 - if( mpVbaEventsListener && !bCancel )
225 + if( m_xVbaEventsListener.is() && !bCancel )
227 - mpVbaEventsListener->stopEventsLinstener();
228 - mpVbaEventsListener = NULL;
229 + VbaEventsListener* pEventsListener = dynamic_cast< VbaEventsListener* >( m_xVbaEventsListener.get() );
230 + pEventsListener->stopEventsLinstener();
231 + m_xVbaEventsListener = NULL;
233 return bCancel;