1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*6d739b60SAndrew Rist * distributed with this work for additional information
6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the
17*6d739b60SAndrew Rist * specific language governing permissions and limitations
18*6d739b60SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*6d739b60SAndrew Rist *************************************************************/
21*6d739b60SAndrew Rist
22*6d739b60SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir #include <dispatch/helpagentdispatcher.hxx>
27cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
28cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
29cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp>
30cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
31cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
32cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp>
33cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
34cdf0e10cSrcweir #include <svtools/helpopt.hxx>
35cdf0e10cSrcweir #include <vcl/svapp.hxx>
36cdf0e10cSrcweir #include <vcl/help.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir namespace css = ::com::sun::star;
39cdf0e10cSrcweir
40cdf0e10cSrcweir //........................................................................
41cdf0e10cSrcweir namespace framework
42cdf0e10cSrcweir {
43cdf0e10cSrcweir
44cdf0e10cSrcweir //-----------------------------------------------
DEFINE_XINTERFACE_4(HelpAgentDispatcher,OWeakObject,DIRECT_INTERFACE (css::lang::XTypeProvider),DIRECT_INTERFACE (css::frame::XDispatch),DIRECT_INTERFACE (css::awt::XWindowListener),DIRECT_INTERFACE (css::lang::XEventListener))45cdf0e10cSrcweir DEFINE_XINTERFACE_4(HelpAgentDispatcher ,
46cdf0e10cSrcweir OWeakObject ,
47cdf0e10cSrcweir DIRECT_INTERFACE (css::lang::XTypeProvider ),
48cdf0e10cSrcweir DIRECT_INTERFACE (css::frame::XDispatch ),
49cdf0e10cSrcweir DIRECT_INTERFACE (css::awt::XWindowListener),
50cdf0e10cSrcweir DIRECT_INTERFACE (css::lang::XEventListener))
51cdf0e10cSrcweir
52cdf0e10cSrcweir //-----------------------------------------------
53cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_2(HelpAgentDispatcher ,
54cdf0e10cSrcweir css::lang::XTypeProvider,
55cdf0e10cSrcweir css::frame::XDispatch )
56cdf0e10cSrcweir
57cdf0e10cSrcweir //--------------------------------------------------------------------
58cdf0e10cSrcweir HelpAgentDispatcher::HelpAgentDispatcher( const css::uno::Reference< css::frame::XFrame >& xParentFrame)
59cdf0e10cSrcweir : ThreadHelpBase (&Application::GetSolarMutex())
60cdf0e10cSrcweir , m_sCurrentURL ( )
61cdf0e10cSrcweir , m_xContainerWindow( )
62cdf0e10cSrcweir , m_xAgentWindow ( )
63cdf0e10cSrcweir , m_aTimer ( )
64cdf0e10cSrcweir , m_xSelfHold ( )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir // It's required that this class has to be contructed with a valid frame.
67cdf0e10cSrcweir // And "valid" means: the frame must already bound to a valid container window.
68cdf0e10cSrcweir m_xContainerWindow = xParentFrame->getContainerWindow();
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
71cdf0e10cSrcweir //--------------------------------------------------------------------
~HelpAgentDispatcher()72cdf0e10cSrcweir HelpAgentDispatcher::~HelpAgentDispatcher()
73cdf0e10cSrcweir {
74cdf0e10cSrcweir implts_stopTimer();
75cdf0e10cSrcweir implts_ignoreCurrentURL();
76cdf0e10cSrcweir
77cdf0e10cSrcweir // Needed ... because it was create as "new VCLWindow()" ! Such windows must be disposed explicitly.
78cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent > xAgentWindow(m_xAgentWindow, css::uno::UNO_QUERY);
79cdf0e10cSrcweir if (xAgentWindow.is())
80cdf0e10cSrcweir xAgentWindow->dispose();
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
83cdf0e10cSrcweir //--------------------------------------------------------------------
dispatch(const css::util::URL & aURL,const css::uno::Sequence<css::beans::PropertyValue> &)84cdf0e10cSrcweir void SAL_CALL HelpAgentDispatcher::dispatch(const css::util::URL& aURL ,
85cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >&)
86cdf0e10cSrcweir throw(css::uno::RuntimeException)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir // silently drop the request if the new URL was marked to be ignored next time.
89cdf0e10cSrcweir sal_Int32 nAllowedToIgnore = SvtHelpOptions().getAgentIgnoreURLCounter(aURL.Complete);
90cdf0e10cSrcweir if (nAllowedToIgnore < 1)
91cdf0e10cSrcweir return;
92cdf0e10cSrcweir
93cdf0e10cSrcweir // stop the expiration timer for the old URL
94cdf0e10cSrcweir // The timer will add the old URL to the list of ignorable URLs.
95cdf0e10cSrcweir // So m_sCurrentURL must be set AFTER the timer was stopped !!!
96cdf0e10cSrcweir implts_stopTimer();
97cdf0e10cSrcweir
98cdf0e10cSrcweir // SAFE ->
99cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
100cdf0e10cSrcweir m_sCurrentURL = aURL.Complete;
101cdf0e10cSrcweir aWriteLock.unlock();
102cdf0e10cSrcweir // <- SAFE
103cdf0e10cSrcweir
104cdf0e10cSrcweir // start the expiration timer for the new URL
105cdf0e10cSrcweir implts_startTimer();
106cdf0e10cSrcweir
107cdf0e10cSrcweir // make sure the agent window is shown
108cdf0e10cSrcweir implts_showAgentWindow();
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
111cdf0e10cSrcweir //--------------------------------------------------------------------
addStatusListener(const css::uno::Reference<css::frame::XStatusListener> &,const css::util::URL &)112cdf0e10cSrcweir void SAL_CALL HelpAgentDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >&,
113cdf0e10cSrcweir const css::util::URL&)
114cdf0e10cSrcweir throw(css::uno::RuntimeException)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir // no status available
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir //--------------------------------------------------------------------
removeStatusListener(const css::uno::Reference<css::frame::XStatusListener> &,const css::util::URL &)120cdf0e10cSrcweir void SAL_CALL HelpAgentDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >&,
121cdf0e10cSrcweir const css::util::URL&)
122cdf0e10cSrcweir throw(css::uno::RuntimeException)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir // no status available
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
127cdf0e10cSrcweir //--------------------------------------------------------------------
windowResized(const css::awt::WindowEvent &)128cdf0e10cSrcweir void SAL_CALL HelpAgentDispatcher::windowResized(const css::awt::WindowEvent&)
129cdf0e10cSrcweir throw(css::uno::RuntimeException)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir implts_positionAgentWindow();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir //--------------------------------------------------------------------
windowMoved(const css::awt::WindowEvent &)135cdf0e10cSrcweir void SAL_CALL HelpAgentDispatcher::windowMoved(const css::awt::WindowEvent&)
136cdf0e10cSrcweir throw(css::uno::RuntimeException)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir implts_positionAgentWindow();
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir //--------------------------------------------------------------------
windowShown(const css::lang::EventObject &)142cdf0e10cSrcweir void SAL_CALL HelpAgentDispatcher::windowShown(const css::lang::EventObject&)
143cdf0e10cSrcweir throw(css::uno::RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir implts_showAgentWindow();
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir //--------------------------------------------------------------------
windowHidden(const css::lang::EventObject &)149cdf0e10cSrcweir void SAL_CALL HelpAgentDispatcher::windowHidden(const css::lang::EventObject&)
150cdf0e10cSrcweir throw(css::uno::RuntimeException)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir implts_hideAgentWindow();
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155cdf0e10cSrcweir //--------------------------------------------------------------------
disposing(const css::lang::EventObject & aEvent)156cdf0e10cSrcweir void SAL_CALL HelpAgentDispatcher::disposing(const css::lang::EventObject& aEvent)
157cdf0e10cSrcweir throw(css::uno::RuntimeException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir // SAFE ->
160cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
161cdf0e10cSrcweir
162cdf0e10cSrcweir // Already disposed ?!
163cdf0e10cSrcweir if (! m_xContainerWindow.is())
164cdf0e10cSrcweir return;
165cdf0e10cSrcweir // Wrong broadcaster ?!
166cdf0e10cSrcweir if (aEvent.Source != m_xContainerWindow)
167cdf0e10cSrcweir return;
168cdf0e10cSrcweir
169cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xSelfHoldUntilMethodEnds(static_cast< css::frame::XDispatch* >(this), css::uno::UNO_QUERY_THROW);
170cdf0e10cSrcweir m_xSelfHold.clear();
171cdf0e10cSrcweir
172cdf0e10cSrcweir aWriteLock.unlock();
173cdf0e10cSrcweir // <- SAFE
174cdf0e10cSrcweir
175cdf0e10cSrcweir implts_stopTimer();
176cdf0e10cSrcweir implts_hideAgentWindow();
177cdf0e10cSrcweir implts_ignoreCurrentURL();
178cdf0e10cSrcweir
179cdf0e10cSrcweir // SAFE ->
180cdf0e10cSrcweir aWriteLock.lock();
181cdf0e10cSrcweir m_xContainerWindow.clear();
182cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent > xAgentWindow(m_xAgentWindow, css::uno::UNO_QUERY);
183cdf0e10cSrcweir m_xAgentWindow.clear();
184cdf0e10cSrcweir aWriteLock.unlock();
185cdf0e10cSrcweir // <- SAFE
186cdf0e10cSrcweir
187cdf0e10cSrcweir // Needed ... because it was create as "new VCLWindow()" ! Such windows must be disposed explicitly.
188cdf0e10cSrcweir if (xAgentWindow.is())
189cdf0e10cSrcweir xAgentWindow->dispose();
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir //--------------------------------------------------------------------
helpRequested()193cdf0e10cSrcweir void HelpAgentDispatcher::helpRequested()
194cdf0e10cSrcweir {
195cdf0e10cSrcweir implts_stopTimer();
196cdf0e10cSrcweir implts_hideAgentWindow();
197cdf0e10cSrcweir implts_acceptCurrentURL();
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir //-----------------------------------------------
closeAgent()201cdf0e10cSrcweir void HelpAgentDispatcher::closeAgent()
202cdf0e10cSrcweir {
203cdf0e10cSrcweir implts_stopTimer();
204cdf0e10cSrcweir implts_hideAgentWindow();
205cdf0e10cSrcweir implts_ignoreCurrentURL();
206cdf0e10cSrcweir }
207cdf0e10cSrcweir
208cdf0e10cSrcweir //--------------------------------------------------------------------
implts_acceptCurrentURL()209cdf0e10cSrcweir void HelpAgentDispatcher::implts_acceptCurrentURL()
210cdf0e10cSrcweir {
211cdf0e10cSrcweir // SAFE ->
212cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
213cdf0e10cSrcweir
214cdf0e10cSrcweir ::rtl::OUString sAcceptedURL = m_sCurrentURL;
215cdf0e10cSrcweir m_sCurrentURL = ::rtl::OUString();
216cdf0e10cSrcweir
217cdf0e10cSrcweir aWriteLock.unlock();
218cdf0e10cSrcweir // <- SAFE
219cdf0e10cSrcweir
220cdf0e10cSrcweir // We must make sure that this URL isnt marked as ignored by the user.
221cdf0e10cSrcweir // Otherwhise the user wont see the corresponding help content in the future.
222cdf0e10cSrcweir SvtHelpOptions().resetAgentIgnoreURLCounter(sAcceptedURL);
223cdf0e10cSrcweir
224cdf0e10cSrcweir // show the right help content
225cdf0e10cSrcweir // SOLAR SAFE ->
226cdf0e10cSrcweir {
227cdf0e10cSrcweir ::vos::OGuard aSolarLock(Application::GetSolarMutex());
228cdf0e10cSrcweir Help* pHelp = Application::GetHelp();
229cdf0e10cSrcweir if (pHelp)
230cdf0e10cSrcweir pHelp->Start(sAcceptedURL, NULL);
231cdf0e10cSrcweir }
232cdf0e10cSrcweir // <- SOLAR SAFE
233cdf0e10cSrcweir }
234cdf0e10cSrcweir
235cdf0e10cSrcweir //--------------------------------------------------------------------
implts_ignoreCurrentURL()236cdf0e10cSrcweir void HelpAgentDispatcher::implts_ignoreCurrentURL()
237cdf0e10cSrcweir {
238cdf0e10cSrcweir // SAFE ->
239cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
240cdf0e10cSrcweir
241cdf0e10cSrcweir ::rtl::OUString sIgnoredURL = m_sCurrentURL;
242cdf0e10cSrcweir m_sCurrentURL = ::rtl::OUString();
243cdf0e10cSrcweir
244cdf0e10cSrcweir aWriteLock.unlock();
245cdf0e10cSrcweir // <- SAFE
246cdf0e10cSrcweir
247cdf0e10cSrcweir if (sIgnoredURL.getLength())
248cdf0e10cSrcweir SvtHelpOptions().decAgentIgnoreURLCounter(sIgnoredURL);
249cdf0e10cSrcweir }
250cdf0e10cSrcweir
251cdf0e10cSrcweir //--------------------------------------------------------------------
implts_stopTimer()252cdf0e10cSrcweir void HelpAgentDispatcher::implts_stopTimer()
253cdf0e10cSrcweir {
254cdf0e10cSrcweir // SAFE ->
255cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
256cdf0e10cSrcweir m_xSelfHold.clear();
257cdf0e10cSrcweir aWriteLock.unlock();
258cdf0e10cSrcweir // <- SAFE
259cdf0e10cSrcweir
260cdf0e10cSrcweir // SOLAR SAFE ->
261cdf0e10cSrcweir // Timer access needs no "own lock" ! It lives if we live ...
262cdf0e10cSrcweir // But it requires locking of the solar mutex ... because it's a vcl based timer.
263cdf0e10cSrcweir {
264cdf0e10cSrcweir ::vos::OGuard aSolarLock(Application::GetSolarMutex());
265cdf0e10cSrcweir if (! m_aTimer.IsActive())
266cdf0e10cSrcweir return;
267cdf0e10cSrcweir m_aTimer.Stop();
268cdf0e10cSrcweir }
269cdf0e10cSrcweir // <- SOLAR SAFE
270cdf0e10cSrcweir }
271cdf0e10cSrcweir
272cdf0e10cSrcweir //--------------------------------------------------------------------
implts_startTimer()273cdf0e10cSrcweir void HelpAgentDispatcher::implts_startTimer()
274cdf0e10cSrcweir {
275cdf0e10cSrcweir // SOLAR SAFE ->
276cdf0e10cSrcweir // Timer access needs no "own lock" ! It lives if we live ...
277cdf0e10cSrcweir // But it requires locking of the solar mutex ... because it's a vcl based timer.
278cdf0e10cSrcweir {
279cdf0e10cSrcweir ::vos::OGuard aSolarLock(Application::GetSolarMutex());
280cdf0e10cSrcweir if (m_aTimer.IsActive())
281cdf0e10cSrcweir return;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir // <- SOLAR SAFE
284cdf0e10cSrcweir
285cdf0e10cSrcweir // SAFE ->
286cdf0e10cSrcweir // Timer uses pointer to this help agent dispatcher ...
287cdf0e10cSrcweir // But normaly we are ref counted. So we must make sure that this
288cdf0e10cSrcweir // dispatcher isnt killed during the timer runs .-)
289cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
290cdf0e10cSrcweir m_xSelfHold = css::uno::Reference< css::uno::XInterface >(static_cast< css::frame::XDispatch* >(this), css::uno::UNO_QUERY_THROW);
291cdf0e10cSrcweir aWriteLock.unlock();
292cdf0e10cSrcweir // <- SAFE
293cdf0e10cSrcweir
294cdf0e10cSrcweir sal_Int32 nTime = SvtHelpOptions().GetHelpAgentTimeoutPeriod();
295cdf0e10cSrcweir
296cdf0e10cSrcweir // SOLAR SAFE ->
297cdf0e10cSrcweir // Timer access needs no "own lock" ! It lives if we live ...
298cdf0e10cSrcweir // But it requires locking of the solar mutex ... because it's a vcl based timer.
299cdf0e10cSrcweir {
300cdf0e10cSrcweir ::vos::OGuard aSolarLock(Application::GetSolarMutex());
301cdf0e10cSrcweir m_aTimer.SetTimeout(nTime*1000); // sec => ms !
302cdf0e10cSrcweir m_aTimer.Start();
303cdf0e10cSrcweir }
304cdf0e10cSrcweir }
305cdf0e10cSrcweir
306cdf0e10cSrcweir //-----------------------------------------------
307cdf0e10cSrcweir IMPL_LINK(HelpAgentDispatcher, implts_timerExpired, void*,)
308cdf0e10cSrcweir {
309cdf0e10cSrcweir // This method is called by using a pointer to us.
310cdf0e10cSrcweir // But we must be aware that we can be destroyed hardly
311cdf0e10cSrcweir // if our uno reference will be gone!
312cdf0e10cSrcweir // => Hold this object alive till this method finish its work.
313cdf0e10cSrcweir // SAFE ->
314cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
315cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xSelfHoldUntilMethodEnds(static_cast< css::frame::XDispatch* >(this), css::uno::UNO_QUERY_THROW);
316cdf0e10cSrcweir m_xSelfHold.clear();
317cdf0e10cSrcweir aWriteLock.unlock();
318cdf0e10cSrcweir // <- SAFE
319cdf0e10cSrcweir
320cdf0e10cSrcweir implts_hideAgentWindow();
321cdf0e10cSrcweir implts_ignoreCurrentURL();
322cdf0e10cSrcweir
323cdf0e10cSrcweir return 0;
324cdf0e10cSrcweir }
325cdf0e10cSrcweir
326cdf0e10cSrcweir //--------------------------------------------------------------------
implts_showAgentWindow()327cdf0e10cSrcweir void HelpAgentDispatcher::implts_showAgentWindow()
328cdf0e10cSrcweir {
329cdf0e10cSrcweir // SAFE ->
330cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
331cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow2 > xContainerWindow(m_xContainerWindow, css::uno::UNO_QUERY_THROW);
332cdf0e10cSrcweir aReadLock.unlock();
333cdf0e10cSrcweir // <- SAFE
334cdf0e10cSrcweir
335cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xAgentWindow = implts_ensureAgentWindow();
336cdf0e10cSrcweir
337cdf0e10cSrcweir if (
338cdf0e10cSrcweir (xContainerWindow.is() ) &&
339cdf0e10cSrcweir (xAgentWindow.is() ) &&
340cdf0e10cSrcweir (xContainerWindow->isVisible())
341cdf0e10cSrcweir )
342cdf0e10cSrcweir {
343cdf0e10cSrcweir // make sure that agent window resists at the right place .-)
344cdf0e10cSrcweir implts_positionAgentWindow();
345cdf0e10cSrcweir xAgentWindow->setVisible(sal_True);
346cdf0e10cSrcweir }
347cdf0e10cSrcweir }
348cdf0e10cSrcweir
349cdf0e10cSrcweir //--------------------------------------------------------------------
implts_hideAgentWindow()350cdf0e10cSrcweir void HelpAgentDispatcher::implts_hideAgentWindow()
351cdf0e10cSrcweir {
352cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xAgentWindow = implts_ensureAgentWindow();
353cdf0e10cSrcweir if (xAgentWindow.is())
354cdf0e10cSrcweir xAgentWindow->setVisible(sal_False);
355cdf0e10cSrcweir }
356cdf0e10cSrcweir
357cdf0e10cSrcweir //--------------------------------------------------------------------
implts_positionAgentWindow()358cdf0e10cSrcweir void HelpAgentDispatcher::implts_positionAgentWindow()
359cdf0e10cSrcweir {
360cdf0e10cSrcweir // SAFE ->
361cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
362cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xContainerWindow = m_xContainerWindow;
363cdf0e10cSrcweir aReadLock.unlock();
364cdf0e10cSrcweir // <- SAFE
365cdf0e10cSrcweir
366cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xAgentWindow = implts_ensureAgentWindow();
367cdf0e10cSrcweir if (
368cdf0e10cSrcweir (! xContainerWindow.is()) ||
369cdf0e10cSrcweir (! xAgentWindow.is() )
370cdf0e10cSrcweir )
371cdf0e10cSrcweir return;
372cdf0e10cSrcweir
373cdf0e10cSrcweir ::svt::HelpAgentWindow* pAgentWindow = (::svt::HelpAgentWindow*)VCLUnoHelper::GetWindow(xAgentWindow);
374cdf0e10cSrcweir const css::awt::Rectangle aContainerSize = xContainerWindow->getPosSize();
375cdf0e10cSrcweir const Size aAgentSize = pAgentWindow->getPreferredSizePixel();
376cdf0e10cSrcweir
377cdf0e10cSrcweir sal_Int32 nW = aAgentSize.Width() ;
378cdf0e10cSrcweir sal_Int32 nH = aAgentSize.Height();
379cdf0e10cSrcweir
380cdf0e10cSrcweir if (nW < 1)
381cdf0e10cSrcweir nW = 100;
382cdf0e10cSrcweir if (nH < 1)
383cdf0e10cSrcweir nH = 100;
384cdf0e10cSrcweir
385cdf0e10cSrcweir sal_Int32 nX = aContainerSize.Width - nW;
386cdf0e10cSrcweir sal_Int32 nY = aContainerSize.Height - nH;
387cdf0e10cSrcweir
388cdf0e10cSrcweir // TODO: use a surrogate if the container window is too small to contain the full-sized agent window
389cdf0e10cSrcweir xAgentWindow->setPosSize(nX, nY, nW, nH, css::awt::PosSize::POSSIZE);
390cdf0e10cSrcweir }
391cdf0e10cSrcweir
392cdf0e10cSrcweir //--------------------------------------------------------------------
implts_ensureAgentWindow()393cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > HelpAgentDispatcher::implts_ensureAgentWindow()
394cdf0e10cSrcweir {
395cdf0e10cSrcweir // SAFE ->
396cdf0e10cSrcweir ReadGuard aReadLock(m_aLock);
397cdf0e10cSrcweir if (m_xAgentWindow.is())
398cdf0e10cSrcweir return m_xAgentWindow;
399cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xContainerWindow = m_xContainerWindow;
400cdf0e10cSrcweir aReadLock.unlock();
401cdf0e10cSrcweir // <- SAFE
402cdf0e10cSrcweir
403cdf0e10cSrcweir if (!xContainerWindow.is())
404cdf0e10cSrcweir return css::uno::Reference< css::awt::XWindow >();
405cdf0e10cSrcweir
406cdf0e10cSrcweir ::svt::HelpAgentWindow* pAgentWindow = 0;
407cdf0e10cSrcweir // SOLAR SAFE ->
408cdf0e10cSrcweir {
409cdf0e10cSrcweir ::vos::OGuard aSolarLock(Application::GetSolarMutex());
410cdf0e10cSrcweir // create the agent window
411cdf0e10cSrcweir Window* pContainerWindow = VCLUnoHelper::GetWindow(xContainerWindow);
412cdf0e10cSrcweir pAgentWindow = new ::svt::HelpAgentWindow(pContainerWindow);
413cdf0e10cSrcweir pAgentWindow->setCallback(this);
414cdf0e10cSrcweir }
415cdf0e10cSrcweir // <- SOLAR SAFE
416cdf0e10cSrcweir
417cdf0e10cSrcweir // SAFE ->
418cdf0e10cSrcweir WriteGuard aWriteLock(m_aLock);
419cdf0e10cSrcweir m_xAgentWindow = VCLUnoHelper::GetInterface(pAgentWindow);
420cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > xAgentWindow = m_xAgentWindow;
421cdf0e10cSrcweir aWriteLock.unlock();
422cdf0e10cSrcweir // <- SAFE
423cdf0e10cSrcweir
424cdf0e10cSrcweir // add as window listener to the container window so we can maintain the property position of the agent window
425cdf0e10cSrcweir xContainerWindow->addWindowListener(this);
426cdf0e10cSrcweir
427cdf0e10cSrcweir // SOLAR SAFE ->
428cdf0e10cSrcweir {
429cdf0e10cSrcweir ::vos::OGuard aSolarLock(Application::GetSolarMutex());
430cdf0e10cSrcweir // establish callback for our internal used timer.
431cdf0e10cSrcweir // Note: Its only active, if the timer will be started ...
432cdf0e10cSrcweir m_aTimer.SetTimeoutHdl(LINK(this, HelpAgentDispatcher, implts_timerExpired));
433cdf0e10cSrcweir }
434cdf0e10cSrcweir // <- SOLAR SAFE
435cdf0e10cSrcweir
436cdf0e10cSrcweir return xAgentWindow;
437cdf0e10cSrcweir }
438cdf0e10cSrcweir
439cdf0e10cSrcweir } // namespace framework
440cdf0e10cSrcweir
441