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
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
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.
19*6d739b60SAndrew Rist  *
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 
27cdf0e10cSrcweir //_______________________________________________
28cdf0e10cSrcweir // includes
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <framework/titlehelper.hxx>
31cdf0e10cSrcweir #include <services.h>
32cdf0e10cSrcweir #include <properties.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <com/sun/star/frame/UntitledNumbersConst.hpp>
35cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
36cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp>
37cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
38cdf0e10cSrcweir #include <com/sun/star/document/XEventBroadcaster.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/XMaterialHolder.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <unotools/configmgr.hxx>
42cdf0e10cSrcweir #include <unotools/bootstrap.hxx>
43cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
44cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
45cdf0e10cSrcweir #include <osl/mutex.hxx>
46cdf0e10cSrcweir #include <tools/urlobj.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //_______________________________________________
49cdf0e10cSrcweir // namespace
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace framework{
52cdf0e10cSrcweir 
53cdf0e10cSrcweir namespace css = ::com::sun::star;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir //_______________________________________________
56cdf0e10cSrcweir // definitions
57cdf0e10cSrcweir 
58cdf0e10cSrcweir static const ::rtl::OUString ERRMSG_INVALID_COMPONENT_PARAM = ::rtl::OUString::createFromAscii("NULL as component reference not allowed.");
59cdf0e10cSrcweir static const ::rtl::OUString ERRMSG_INVALID_NUMBER_PARAM    = ::rtl::OUString::createFromAscii("Special valkud INVALID_NUMBER not allowed as input parameter.");
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //-----------------------------------------------
TitleHelper(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)62cdf0e10cSrcweir TitleHelper::TitleHelper(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
63cdf0e10cSrcweir     : ::cppu::BaseMutex ()
64cdf0e10cSrcweir     , m_xSMGR           (xSMGR)
65cdf0e10cSrcweir     , m_xOwner          ()
66cdf0e10cSrcweir     , m_xUntitledNumbers()
67cdf0e10cSrcweir     , m_xSubTitle       ()
68cdf0e10cSrcweir     , m_bExternalTitle  (sal_False)
69cdf0e10cSrcweir     , m_sTitle          ()
70cdf0e10cSrcweir     , m_nLeasedNumber   (css::frame::UntitledNumbersConst::INVALID_NUMBER)
71cdf0e10cSrcweir     , m_aListener       (m_aMutex)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir //-----------------------------------------------
~TitleHelper()76cdf0e10cSrcweir TitleHelper::~TitleHelper()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir //-----------------------------------------------
setOwner(const css::uno::Reference<css::uno::XInterface> & xOwner)81cdf0e10cSrcweir void TitleHelper::setOwner(const css::uno::Reference< css::uno::XInterface >& xOwner)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     // SYNCHRONIZED ->
84cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         m_xOwner = xOwner;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     aLock.clear ();
89cdf0e10cSrcweir     // <- SYNCHRONIZED
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     css::uno::Reference< css::frame::XModel > xModel(xOwner, css::uno::UNO_QUERY);
92cdf0e10cSrcweir     if (xModel.is ())
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         impl_startListeningForModel (xModel);
95cdf0e10cSrcweir         return;
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     css::uno::Reference< css::frame::XController > xController(xOwner, css::uno::UNO_QUERY);
99cdf0e10cSrcweir     if (xController.is ())
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         impl_startListeningForController (xController);
102cdf0e10cSrcweir         return;
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xFrame(xOwner, css::uno::UNO_QUERY);
106cdf0e10cSrcweir     if (xFrame.is ())
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir         impl_startListeningForFrame (xFrame);
109cdf0e10cSrcweir         return;
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir //-----------------------------------------------
getTitle()114cdf0e10cSrcweir ::rtl::OUString SAL_CALL TitleHelper::getTitle()
115cdf0e10cSrcweir     throw (css::uno::RuntimeException)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir     // SYNCHRONIZED ->
118cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         // An external title will win always and disable all internal logic about
121cdf0e10cSrcweir         // creating/using a title value.
122cdf0e10cSrcweir         // Even an empty string will be accepted as valid title !
123cdf0e10cSrcweir         if (m_bExternalTitle)
124cdf0e10cSrcweir             return m_sTitle;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         // Title seams to be up-to-date. Return it directly.
127cdf0e10cSrcweir         if (m_sTitle.getLength() > 0)
128cdf0e10cSrcweir             return m_sTitle;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         // Title seams to be unused till now ... do bootstraping
131cdf0e10cSrcweir         impl_updateTitle ();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         return m_sTitle;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     // <- SYNCHRONIZED
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir //-----------------------------------------------
connectWithUntitledNumbers(const css::uno::Reference<css::frame::XUntitledNumbers> & xNumbers)139cdf0e10cSrcweir void TitleHelper::connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir     // SYNCHRONIZED ->
142cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         m_xUntitledNumbers = xNumbers;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     // <- SYNCHRONIZED
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir //-----------------------------------------------
setTitle(const::rtl::OUString & sTitle)150cdf0e10cSrcweir void SAL_CALL TitleHelper::setTitle(const ::rtl::OUString& sTitle)
151cdf0e10cSrcweir     throw (css::uno::RuntimeException)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     // SYNCHRONIZED ->
154cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         m_bExternalTitle = sal_True;
157cdf0e10cSrcweir         m_sTitle         = sTitle;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     aLock.clear ();
160cdf0e10cSrcweir     // <- SYNCHRONIZED
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     impl_sendTitleChangedEvent ();
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir //-----------------------------------------------
addTitleChangeListener(const css::uno::Reference<css::frame::XTitleChangeListener> & xListener)166cdf0e10cSrcweir void SAL_CALL TitleHelper::addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
167cdf0e10cSrcweir     throw (css::uno::RuntimeException)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     // container is threadsafe by himself
170cdf0e10cSrcweir     m_aListener.addInterface( ::getCppuType( (const css::uno::Reference< css::frame::XTitleChangeListener >*)NULL ), xListener );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir //-----------------------------------------------
removeTitleChangeListener(const css::uno::Reference<css::frame::XTitleChangeListener> & xListener)174cdf0e10cSrcweir void SAL_CALL TitleHelper::removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
175cdf0e10cSrcweir     throw (css::uno::RuntimeException)
176cdf0e10cSrcweir {
177cdf0e10cSrcweir     // container is threadsafe by himself
178cdf0e10cSrcweir     m_aListener.removeInterface( ::getCppuType( (const css::uno::Reference< css::frame::XTitleChangeListener >*)NULL ), xListener );
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir //-----------------------------------------------
titleChanged(const css::frame::TitleChangedEvent & aEvent)182cdf0e10cSrcweir void SAL_CALL TitleHelper::titleChanged(const css::frame::TitleChangedEvent& aEvent)
183cdf0e10cSrcweir     throw (css::uno::RuntimeException)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir     // SYNCHRONIZED ->
186cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         css::uno::Reference< css::frame::XTitle > xSubTitle(m_xSubTitle.get (), css::uno::UNO_QUERY);
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     aLock.clear ();
191cdf0e10cSrcweir     // <- SYNCHRONIZED
192cdf0e10cSrcweir 
193cdf0e10cSrcweir     if (aEvent.Source != xSubTitle)
194cdf0e10cSrcweir         return;
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     impl_updateTitle ();
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir //-----------------------------------------------
notifyEvent(const css::document::EventObject & aEvent)200cdf0e10cSrcweir void SAL_CALL TitleHelper::notifyEvent(const css::document::EventObject& aEvent)
201cdf0e10cSrcweir     throw (css::uno::RuntimeException)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     if ( ! aEvent.EventName.equalsIgnoreAsciiCaseAscii ("OnSaveAsDone")
204cdf0e10cSrcweir       && ! aEvent.EventName.equalsIgnoreAsciiCaseAscii ("OnTitleChanged"))
205cdf0e10cSrcweir         return;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     // SYNCHRONIZED ->
208cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         css::uno::Reference< css::frame::XModel > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     aLock.clear ();
213cdf0e10cSrcweir     // <- SYNCHRONIZED
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     if (
216cdf0e10cSrcweir          aEvent.Source != xOwner ||
217cdf0e10cSrcweir          (aEvent.EventName.equalsIgnoreAsciiCaseAscii ("OnTitleChanged") && !xOwner.is())
218cdf0e10cSrcweir        )
219cdf0e10cSrcweir     {
220cdf0e10cSrcweir         return;
221cdf0e10cSrcweir     }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     impl_updateTitle ();
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir //-----------------------------------------------
frameAction(const css::frame::FrameActionEvent & aEvent)227cdf0e10cSrcweir void SAL_CALL TitleHelper::frameAction(const css::frame::FrameActionEvent& aEvent)
228cdf0e10cSrcweir     throw(css::uno::RuntimeException)
229cdf0e10cSrcweir {
230cdf0e10cSrcweir     // SYNCHRONIZED ->
231cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         css::uno::Reference< css::frame::XFrame > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     aLock.clear ();
236cdf0e10cSrcweir     // <- SYNCHRONIZED
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 	if (aEvent.Source != xOwner)
239cdf0e10cSrcweir 		return;
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     // we are interested on events only, which must trigger a title bar update
242cdf0e10cSrcweir     // because component was changed.
243cdf0e10cSrcweir     if (
244cdf0e10cSrcweir         (aEvent.Action == css::frame::FrameAction_COMPONENT_ATTACHED  ) ||
245cdf0e10cSrcweir         (aEvent.Action == css::frame::FrameAction_COMPONENT_REATTACHED) ||
246cdf0e10cSrcweir         (aEvent.Action == css::frame::FrameAction_COMPONENT_DETACHING )
247cdf0e10cSrcweir        )
248cdf0e10cSrcweir     {
249cdf0e10cSrcweir 		impl_updateListeningForFrame (xOwner);
250cdf0e10cSrcweir 		impl_updateTitle ();
251cdf0e10cSrcweir     }
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir //-----------------------------------------------
disposing(const css::lang::EventObject & aEvent)255cdf0e10cSrcweir void SAL_CALL TitleHelper::disposing(const css::lang::EventObject& aEvent)
256cdf0e10cSrcweir     throw (css::uno::RuntimeException)
257cdf0e10cSrcweir {
258cdf0e10cSrcweir     // SYNCHRONIZED ->
259cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
260cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
261cdf0e10cSrcweir         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
262cdf0e10cSrcweir         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
263cdf0e10cSrcweir     aLock.clear ();
264cdf0e10cSrcweir     // <- SYNCHRONIZED
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     if ( ! xOwner.is ())
267cdf0e10cSrcweir         return;
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     if (xOwner != aEvent.Source)
270cdf0e10cSrcweir         return;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     if (
273cdf0e10cSrcweir         (xNumbers.is ()                                                   ) &&
274cdf0e10cSrcweir         (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
275cdf0e10cSrcweir        )
276cdf0e10cSrcweir        xNumbers->releaseNumber (nLeasedNumber);
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     // SYNCHRONIZED ->
279cdf0e10cSrcweir     aLock.reset ();
280cdf0e10cSrcweir 
281cdf0e10cSrcweir          m_sTitle        = ::rtl::OUString ();
282cdf0e10cSrcweir          m_nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     aLock.clear ();
285cdf0e10cSrcweir     // <- SYNCHRONIZED
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     impl_sendTitleChangedEvent ();
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir //-----------------------------------------------
impl_sendTitleChangedEvent()291cdf0e10cSrcweir void TitleHelper::impl_sendTitleChangedEvent ()
292cdf0e10cSrcweir {
293cdf0e10cSrcweir     // SYNCHRONIZED ->
294cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
295cdf0e10cSrcweir 
296cdf0e10cSrcweir         css::frame::TitleChangedEvent aEvent(m_xOwner.get (), m_sTitle);
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     aLock.clear ();
299cdf0e10cSrcweir     // <- SYNCHRONIZED
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     ::cppu::OInterfaceContainerHelper* pContainer = m_aListener.getContainer( ::getCppuType( ( const css::uno::Reference< css::frame::XTitleChangeListener >*) NULL ) );
302cdf0e10cSrcweir 	if ( ! pContainer)
303cdf0e10cSrcweir         return;
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     ::cppu::OInterfaceIteratorHelper pIt( *pContainer );
306cdf0e10cSrcweir     while ( pIt.hasMoreElements() )
307cdf0e10cSrcweir     {
308cdf0e10cSrcweir         try
309cdf0e10cSrcweir         {
310cdf0e10cSrcweir             ((css::frame::XTitleChangeListener*)pIt.next())->titleChanged( aEvent );
311cdf0e10cSrcweir         }
312cdf0e10cSrcweir         catch(const css::uno::Exception&)
313cdf0e10cSrcweir         {
314cdf0e10cSrcweir             pIt.remove();
315cdf0e10cSrcweir         }
316cdf0e10cSrcweir     }
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir //-----------------------------------------------
impl_updateTitle()320cdf0e10cSrcweir void TitleHelper::impl_updateTitle ()
321cdf0e10cSrcweir {
322cdf0e10cSrcweir     // SYNCHRONIZED ->
323cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
324cdf0e10cSrcweir 
325cdf0e10cSrcweir         css::uno::Reference< css::frame::XModel >      xModel     (m_xOwner.get(), css::uno::UNO_QUERY);
326cdf0e10cSrcweir         css::uno::Reference< css::frame::XController > xController(m_xOwner.get(), css::uno::UNO_QUERY);
327cdf0e10cSrcweir         css::uno::Reference< css::frame::XFrame >      xFrame     (m_xOwner.get(), css::uno::UNO_QUERY);
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     aLock.clear ();
330cdf0e10cSrcweir     // <- SYNCHRONIZED
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     if (xModel.is ())
333cdf0e10cSrcweir     {
334cdf0e10cSrcweir         impl_updateTitleForModel (xModel);
335cdf0e10cSrcweir         return;
336cdf0e10cSrcweir     }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     if (xController.is ())
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         impl_updateTitleForController (xController);
341cdf0e10cSrcweir         return;
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir     if (xFrame.is ())
345cdf0e10cSrcweir     {
346cdf0e10cSrcweir         impl_updateTitleForFrame (xFrame);
347cdf0e10cSrcweir         return;
348cdf0e10cSrcweir     }
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir //-----------------------------------------------
impl_updateTitleForModel(const css::uno::Reference<css::frame::XModel> & xModel)352cdf0e10cSrcweir void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel)
353cdf0e10cSrcweir {
354cdf0e10cSrcweir     // SYNCHRONIZED ->
355cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
356cdf0e10cSrcweir 
357cdf0e10cSrcweir         // external title wont be updated internaly !
358cdf0e10cSrcweir         // It has to be set from outside new.
359cdf0e10cSrcweir         if (m_bExternalTitle)
360cdf0e10cSrcweir             return;
361cdf0e10cSrcweir 
362cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
363cdf0e10cSrcweir         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
364cdf0e10cSrcweir         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     aLock.clear ();
367cdf0e10cSrcweir     // <- SYNCHRONIZED
368cdf0e10cSrcweir 
369cdf0e10cSrcweir     if (
370cdf0e10cSrcweir         ( ! xOwner.is    ()) ||
371cdf0e10cSrcweir         ( ! xNumbers.is  ()) ||
372cdf0e10cSrcweir         ( ! xModel.is    ())
373cdf0e10cSrcweir        )
374cdf0e10cSrcweir         return;
375cdf0e10cSrcweir 
376cdf0e10cSrcweir     ::rtl::OUString sTitle;
377cdf0e10cSrcweir     ::rtl::OUString sURL  ;
378cdf0e10cSrcweir 
379cdf0e10cSrcweir     css::uno::Reference< css::frame::XStorable > xURLProvider(xModel , css::uno::UNO_QUERY);
380cdf0e10cSrcweir     if (xURLProvider.is())
381cdf0e10cSrcweir         sURL = xURLProvider->getLocation ();
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     if (sURL.getLength () > 0)
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         sTitle = impl_convertURL2Title(sURL);
386cdf0e10cSrcweir         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
387cdf0e10cSrcweir             xNumbers->releaseNumber (nLeasedNumber);
388cdf0e10cSrcweir 		nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
389cdf0e10cSrcweir     }
390cdf0e10cSrcweir     else
391cdf0e10cSrcweir     {
392cdf0e10cSrcweir         if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
393cdf0e10cSrcweir             nLeasedNumber = xNumbers->leaseNumber (xOwner);
394cdf0e10cSrcweir 
395cdf0e10cSrcweir         ::rtl::OUStringBuffer sNewTitle(256);
396cdf0e10cSrcweir         sNewTitle.append (xNumbers->getUntitledPrefix ());
397cdf0e10cSrcweir         if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
398cdf0e10cSrcweir             sNewTitle.append ((::sal_Int32)nLeasedNumber);
399cdf0e10cSrcweir         else
400cdf0e10cSrcweir             sNewTitle.appendAscii ("?");
401cdf0e10cSrcweir 
402cdf0e10cSrcweir         sTitle = sNewTitle.makeStringAndClear ();
403cdf0e10cSrcweir     }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir     // SYNCHRONIZED ->
406cdf0e10cSrcweir     aLock.reset ();
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     // WORKAROUND: the notification is currently sent always,
409cdf0e10cSrcweir     //             can be changed after shared mode is supported per UNO API
410cdf0e10cSrcweir     sal_Bool bChanged        = sal_True; // (! m_sTitle.equals(sTitle));
411cdf0e10cSrcweir 
412cdf0e10cSrcweir              m_sTitle        = sTitle;
413cdf0e10cSrcweir              m_nLeasedNumber = nLeasedNumber;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir     aLock.clear ();
416cdf0e10cSrcweir     // <- SYNCHRONIZED
417cdf0e10cSrcweir 
418cdf0e10cSrcweir     if (bChanged)
419cdf0e10cSrcweir         impl_sendTitleChangedEvent ();
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
422cdf0e10cSrcweir //-----------------------------------------------
impl_updateTitleForController(const css::uno::Reference<css::frame::XController> & xController)423cdf0e10cSrcweir void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController)
424cdf0e10cSrcweir {
425cdf0e10cSrcweir     // SYNCHRONIZED ->
426cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
427cdf0e10cSrcweir 
428cdf0e10cSrcweir         // external title wont be updated internaly !
429cdf0e10cSrcweir         // It has to be set from outside new.
430cdf0e10cSrcweir         if (m_bExternalTitle)
431cdf0e10cSrcweir             return;
432cdf0e10cSrcweir 
433cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface >         xOwner        (m_xOwner.get()          , css::uno::UNO_QUERY);
434cdf0e10cSrcweir         css::uno::Reference< css::frame::XUntitledNumbers > xNumbers      (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
435cdf0e10cSrcweir         ::sal_Int32                                         nLeasedNumber = m_nLeasedNumber;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     aLock.clear ();
438cdf0e10cSrcweir     // <- SYNCHRONIZED
439cdf0e10cSrcweir 
440cdf0e10cSrcweir     if (
441cdf0e10cSrcweir         ( ! xOwner.is      ()) ||
442cdf0e10cSrcweir         ( ! xNumbers.is    ()) ||
443cdf0e10cSrcweir         ( ! xController.is ())
444cdf0e10cSrcweir        )
445cdf0e10cSrcweir         return;
446cdf0e10cSrcweir 
447cdf0e10cSrcweir     ::rtl::OUStringBuffer sTitle(256);
448cdf0e10cSrcweir 
449cdf0e10cSrcweir     if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
450cdf0e10cSrcweir         nLeasedNumber = xNumbers->leaseNumber (xOwner);
451cdf0e10cSrcweir 
452cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitle > xModelTitle(xController->getModel (), css::uno::UNO_QUERY);
453cdf0e10cSrcweir     if (!xModelTitle.is ())
454cdf0e10cSrcweir         xModelTitle.set(xController, css::uno::UNO_QUERY);
455cdf0e10cSrcweir     if (xModelTitle.is ())
456cdf0e10cSrcweir     {
457cdf0e10cSrcweir         sTitle.append      (xModelTitle->getTitle ());
458cdf0e10cSrcweir         if ( nLeasedNumber > 1 )
459cdf0e10cSrcweir         {
460cdf0e10cSrcweir             sTitle.appendAscii (" : ");
461cdf0e10cSrcweir             sTitle.append      ((::sal_Int32)nLeasedNumber);
462cdf0e10cSrcweir         }
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir     else
465cdf0e10cSrcweir     {
466cdf0e10cSrcweir         sTitle.append (xNumbers->getUntitledPrefix ());
467cdf0e10cSrcweir         if ( nLeasedNumber > 1 )
468cdf0e10cSrcweir         {
469cdf0e10cSrcweir             sTitle.append ((::sal_Int32)nLeasedNumber  );
470cdf0e10cSrcweir         }
471cdf0e10cSrcweir     }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     // SYNCHRONIZED ->
474cdf0e10cSrcweir     aLock.reset ();
475cdf0e10cSrcweir 
476cdf0e10cSrcweir         ::rtl::OUString sNewTitle       = sTitle.makeStringAndClear ();
477cdf0e10cSrcweir         sal_Bool        bChanged        = (! m_sTitle.equals(sNewTitle));
478cdf0e10cSrcweir                         m_sTitle        = sNewTitle;
479cdf0e10cSrcweir                         m_nLeasedNumber = nLeasedNumber;
480cdf0e10cSrcweir 
481cdf0e10cSrcweir     aLock.clear ();
482cdf0e10cSrcweir     // <- SYNCHRONIZED
483cdf0e10cSrcweir 
484cdf0e10cSrcweir     if (bChanged)
485cdf0e10cSrcweir         impl_sendTitleChangedEvent ();
486cdf0e10cSrcweir }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir //-----------------------------------------------
impl_updateTitleForFrame(const css::uno::Reference<css::frame::XFrame> & xFrame)489cdf0e10cSrcweir void TitleHelper::impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
490cdf0e10cSrcweir {
491cdf0e10cSrcweir     if ( ! xFrame.is ())
492cdf0e10cSrcweir         return;
493cdf0e10cSrcweir 
494cdf0e10cSrcweir     // SYNCHRONIZED ->
495cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
496cdf0e10cSrcweir 
497cdf0e10cSrcweir         // external title wont be updated internaly !
498cdf0e10cSrcweir         // It has to be set from outside new.
499cdf0e10cSrcweir         if (m_bExternalTitle)
500cdf0e10cSrcweir             return;
501cdf0e10cSrcweir 
502cdf0e10cSrcweir     aLock.clear ();
503cdf0e10cSrcweir     // <- SYNCHRONIZED
504cdf0e10cSrcweir 
505cdf0e10cSrcweir     css::uno::Reference< css::uno::XInterface > xComponent;
506cdf0e10cSrcweir     xComponent = xFrame->getController ();
507cdf0e10cSrcweir     if ( ! xComponent.is ())
508cdf0e10cSrcweir         xComponent = xFrame->getComponentWindow ();
509cdf0e10cSrcweir 
510cdf0e10cSrcweir     ::rtl::OUStringBuffer sTitle (256);
511cdf0e10cSrcweir 
512cdf0e10cSrcweir     impl_appendComponentTitle   (sTitle, xComponent);
513cdf0e10cSrcweir     impl_appendProductName      (sTitle);
514cdf0e10cSrcweir     impl_appendModuleName       (sTitle);
515cdf0e10cSrcweir     impl_appendProductExtension (sTitle);
516cdf0e10cSrcweir     //impl_appendEvalVersion      (sTitle);
517cdf0e10cSrcweir     impl_appendDebugVersion     (sTitle);
518cdf0e10cSrcweir 
519cdf0e10cSrcweir     // SYNCHRONIZED ->
520cdf0e10cSrcweir     aLock.reset ();
521cdf0e10cSrcweir 
522cdf0e10cSrcweir         ::rtl::OUString sNewTitle = sTitle.makeStringAndClear ();
523cdf0e10cSrcweir         sal_Bool        bChanged  = (! m_sTitle.equals(sNewTitle));
524cdf0e10cSrcweir                         m_sTitle  = sNewTitle;
525cdf0e10cSrcweir 
526cdf0e10cSrcweir     aLock.clear ();
527cdf0e10cSrcweir     // <- SYNCHRONIZED
528cdf0e10cSrcweir 
529cdf0e10cSrcweir     if (bChanged)
530cdf0e10cSrcweir         impl_sendTitleChangedEvent ();
531cdf0e10cSrcweir }
532cdf0e10cSrcweir 
533cdf0e10cSrcweir //*****************************************************************************************************************
impl_appendComponentTitle(::rtl::OUStringBuffer & sTitle,const css::uno::Reference<css::uno::XInterface> & xComponent)534cdf0e10cSrcweir void TitleHelper::impl_appendComponentTitle (      ::rtl::OUStringBuffer&                       sTitle    ,
535cdf0e10cSrcweir                                              const css::uno::Reference< css::uno::XInterface >& xComponent)
536cdf0e10cSrcweir {
537cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitle > xTitle(xComponent, css::uno::UNO_QUERY);
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 	// Note: Title has to be used (even if it's empty) if the right interface is supported.
540cdf0e10cSrcweir     if (xTitle.is ())
541cdf0e10cSrcweir         sTitle.append (xTitle->getTitle ());
542cdf0e10cSrcweir }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir //*****************************************************************************************************************
impl_appendProductName(::rtl::OUStringBuffer & sTitle)545cdf0e10cSrcweir void TitleHelper::impl_appendProductName (::rtl::OUStringBuffer& sTitle)
546cdf0e10cSrcweir {
547cdf0e10cSrcweir     ::rtl::OUString sProductName;
548cdf0e10cSrcweir     ::utl::ConfigManager::GetDirectConfigProperty(::utl::ConfigManager::PRODUCTNAME) >>= sProductName;
549cdf0e10cSrcweir 
550cdf0e10cSrcweir     if (sProductName.getLength ())
551cdf0e10cSrcweir     {
552cdf0e10cSrcweir         if (sTitle.getLength() > 0)
553cdf0e10cSrcweir             sTitle.appendAscii (" - ");
554cdf0e10cSrcweir 
555cdf0e10cSrcweir         sTitle.append (sProductName);
556cdf0e10cSrcweir     }
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir //*****************************************************************************************************************
impl_appendProductExtension(::rtl::OUStringBuffer & sTitle)560cdf0e10cSrcweir void TitleHelper::impl_appendProductExtension (::rtl::OUStringBuffer& sTitle)
561cdf0e10cSrcweir {
562cdf0e10cSrcweir     ::rtl::OUString sProductExtension;
563cdf0e10cSrcweir     ::utl::ConfigManager::GetDirectConfigProperty(::utl::ConfigManager::PRODUCTEXTENSION) >>= sProductExtension;
564cdf0e10cSrcweir 
565cdf0e10cSrcweir     if (sProductExtension.getLength ())
566cdf0e10cSrcweir     {
567cdf0e10cSrcweir         sTitle.appendAscii (" ");
568cdf0e10cSrcweir         sTitle.append      (sProductExtension);
569cdf0e10cSrcweir     }
570cdf0e10cSrcweir }
571cdf0e10cSrcweir 
572cdf0e10cSrcweir //*****************************************************************************************************************
impl_appendModuleName(::rtl::OUStringBuffer & sTitle)573cdf0e10cSrcweir void TitleHelper::impl_appendModuleName (::rtl::OUStringBuffer& sTitle)
574cdf0e10cSrcweir {
575cdf0e10cSrcweir     // SYNCHRONIZED ->
576cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
577cdf0e10cSrcweir 
578cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface >            xOwner = m_xOwner.get();
579cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR  = m_xSMGR;
580cdf0e10cSrcweir 
581cdf0e10cSrcweir     aLock.clear ();
582cdf0e10cSrcweir     // <- SYNCHRONIZED
583cdf0e10cSrcweir 
584cdf0e10cSrcweir     try
585cdf0e10cSrcweir     {
586cdf0e10cSrcweir         css::uno::Reference< css::frame::XModuleManager > xModuleManager(
587cdf0e10cSrcweir             xSMGR->createInstance(SERVICENAME_MODULEMANAGER),
588cdf0e10cSrcweir             css::uno::UNO_QUERY_THROW);
589cdf0e10cSrcweir 
590cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > xConfig(
591cdf0e10cSrcweir             xModuleManager,
592cdf0e10cSrcweir             css::uno::UNO_QUERY_THROW);
593cdf0e10cSrcweir 
594cdf0e10cSrcweir         const ::rtl::OUString                 sID     = xModuleManager->identify(xOwner);
595cdf0e10cSrcweir               ::comphelper::SequenceAsHashMap lProps  = xConfig->getByName (sID);
596cdf0e10cSrcweir         const ::rtl::OUString                 sUIName = lProps.getUnpackedValueOrDefault (OFFICEFACTORY_PROPNAME_UINAME, ::rtl::OUString());
597cdf0e10cSrcweir 
598cdf0e10cSrcweir         // An UIname property is an optional value !
599cdf0e10cSrcweir         // So please add it to the title in case it does realy exists only.
600cdf0e10cSrcweir         if (sUIName.getLength() > 0)
601cdf0e10cSrcweir         {
602cdf0e10cSrcweir             sTitle.appendAscii (" "    );
603cdf0e10cSrcweir             sTitle.append      (sUIName);
604cdf0e10cSrcweir         }
605cdf0e10cSrcweir     }
606cdf0e10cSrcweir     catch(const css::uno::Exception&)
607cdf0e10cSrcweir     {}
608cdf0e10cSrcweir }
609cdf0e10cSrcweir 
610cdf0e10cSrcweir //*****************************************************************************************************************
611cdf0e10cSrcweir #ifdef DBG_UTIL
impl_appendDebugVersion(::rtl::OUStringBuffer & sTitle)612cdf0e10cSrcweir void TitleHelper::impl_appendDebugVersion (::rtl::OUStringBuffer& sTitle)
613cdf0e10cSrcweir {
614cdf0e10cSrcweir         ::rtl::OUString sDefault ;
615cdf0e10cSrcweir 		::rtl::OUString sVersion = ::utl::Bootstrap::getBuildIdData( sDefault );
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 		sTitle.appendAscii (" ["    );
618cdf0e10cSrcweir 		sTitle.append      (sVersion);
619cdf0e10cSrcweir 		sTitle.appendAscii ("]"     );
620cdf0e10cSrcweir }
621cdf0e10cSrcweir #else
impl_appendDebugVersion(::rtl::OUStringBuffer &)622cdf0e10cSrcweir void TitleHelper::impl_appendDebugVersion (::rtl::OUStringBuffer&)
623cdf0e10cSrcweir {
624cdf0e10cSrcweir }
625cdf0e10cSrcweir #endif
626cdf0e10cSrcweir 
627cdf0e10cSrcweir //*****************************************************************************************************************
impl_appendEvalVersion(::rtl::OUStringBuffer &)628cdf0e10cSrcweir void TitleHelper::impl_appendEvalVersion (::rtl::OUStringBuffer& /*sTitle*/)
629cdf0e10cSrcweir {
630cdf0e10cSrcweir     // SYNCHRONIZED ->
631cdf0e10cSrcweir  //   ::osl::ResettableMutexGuard aLock(m_aMutex);
632cdf0e10cSrcweir  //   css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR ;
633cdf0e10cSrcweir 	//aLock.clear ();
634cdf0e10cSrcweir 	//// <- SYNCHRONIZED
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 	//css::uno::Reference< css::beans::XMaterialHolder > xHolder(
637cdf0e10cSrcweir  //       xSMGR->createInstance(SERVICENAME_TABREG),
638cdf0e10cSrcweir 	//	css::uno::UNO_QUERY);
639cdf0e10cSrcweir 
640cdf0e10cSrcweir  //   if ( ! xHolder.is())
641cdf0e10cSrcweir 	//	return;
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 	//	  ::comphelper::SequenceAsHashMap aMaterial(xHolder->getMaterial());
644cdf0e10cSrcweir 	//const ::rtl::OUString				  sEvalTitle = aMaterial.getUnpackedValueOrDefault(TABREG_PROPNAME_TITLE, ::rtl::OUString());
645cdf0e10cSrcweir 
646cdf0e10cSrcweir 	//if (sEvalTitle.getLength())
647cdf0e10cSrcweir 	//{
648cdf0e10cSrcweir 	//	sTitle.appendAscii (" "		  );
649cdf0e10cSrcweir 	//	sTitle.append	   (sEvalTitle);
650cdf0e10cSrcweir 	//}
651cdf0e10cSrcweir }
652cdf0e10cSrcweir 
653cdf0e10cSrcweir //-----------------------------------------------
impl_startListeningForModel(const css::uno::Reference<css::frame::XModel> & xModel)654cdf0e10cSrcweir void TitleHelper::impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel)
655cdf0e10cSrcweir {
656cdf0e10cSrcweir     css::uno::Reference< css::document::XEventBroadcaster > xBroadcaster(xModel, css::uno::UNO_QUERY);
657cdf0e10cSrcweir     if ( ! xBroadcaster.is ())
658cdf0e10cSrcweir         return;
659cdf0e10cSrcweir 
660cdf0e10cSrcweir     xBroadcaster->addEventListener (static_cast< css::document::XEventListener* >(this));
661cdf0e10cSrcweir }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir //-----------------------------------------------
impl_startListeningForController(const css::uno::Reference<css::frame::XController> & xController)664cdf0e10cSrcweir void TitleHelper::impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController)
665cdf0e10cSrcweir {
666cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitle > xSubTitle(xController->getModel (), css::uno::UNO_QUERY);
667cdf0e10cSrcweir     impl_setSubTitle (xSubTitle);
668cdf0e10cSrcweir }
669cdf0e10cSrcweir 
670cdf0e10cSrcweir //-----------------------------------------------
impl_startListeningForFrame(const css::uno::Reference<css::frame::XFrame> & xFrame)671cdf0e10cSrcweir void TitleHelper::impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
672cdf0e10cSrcweir {
673cdf0e10cSrcweir 	xFrame->addFrameActionListener(this  );
674cdf0e10cSrcweir 	impl_updateListeningForFrame  (xFrame);
675cdf0e10cSrcweir }
676cdf0e10cSrcweir 
677cdf0e10cSrcweir //-----------------------------------------------
impl_updateListeningForFrame(const css::uno::Reference<css::frame::XFrame> & xFrame)678cdf0e10cSrcweir void TitleHelper::impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
679cdf0e10cSrcweir {
680cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitle > xSubTitle(xFrame->getController (), css::uno::UNO_QUERY);
681cdf0e10cSrcweir     impl_setSubTitle (xSubTitle);
682cdf0e10cSrcweir }
683cdf0e10cSrcweir 
684cdf0e10cSrcweir //-----------------------------------------------
impl_setSubTitle(const css::uno::Reference<css::frame::XTitle> & xSubTitle)685cdf0e10cSrcweir void TitleHelper::impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle)
686cdf0e10cSrcweir {
687cdf0e10cSrcweir     // SYNCHRONIZED ->
688cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
689cdf0e10cSrcweir 
690cdf0e10cSrcweir         // ignore duplicate calls. Makes outside using of this helper more easy :-)
691cdf0e10cSrcweir         css::uno::Reference< css::frame::XTitle > xOldSubTitle(m_xSubTitle.get(), css::uno::UNO_QUERY);
692cdf0e10cSrcweir         if (xOldSubTitle == xSubTitle)
693cdf0e10cSrcweir             return;
694cdf0e10cSrcweir 
695cdf0e10cSrcweir         m_xSubTitle = xSubTitle;
696cdf0e10cSrcweir 
697cdf0e10cSrcweir     aLock.clear ();
698cdf0e10cSrcweir     // <- SYNCHRONIZED
699cdf0e10cSrcweir 
700cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xOldBroadcaster(xOldSubTitle                                          , css::uno::UNO_QUERY      );
701cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xNewBroadcaster(xSubTitle                                             , css::uno::UNO_QUERY      );
702cdf0e10cSrcweir     css::uno::Reference< css::frame::XTitleChangeListener >    xThis          (static_cast< css::frame::XTitleChangeListener* >(this), css::uno::UNO_QUERY_THROW);
703cdf0e10cSrcweir 
704cdf0e10cSrcweir     if (xOldBroadcaster.is())
705cdf0e10cSrcweir         xOldBroadcaster->removeTitleChangeListener (xThis);
706cdf0e10cSrcweir 
707cdf0e10cSrcweir     if (xNewBroadcaster.is())
708cdf0e10cSrcweir         xNewBroadcaster->addTitleChangeListener (xThis);
709cdf0e10cSrcweir }
710cdf0e10cSrcweir 
711cdf0e10cSrcweir //-----------------------------------------------
impl_getSubTitle()712cdf0e10cSrcweir ::rtl::OUString TitleHelper::impl_getSubTitle ()
713cdf0e10cSrcweir {
714cdf0e10cSrcweir     // SYNCHRONIZED ->
715cdf0e10cSrcweir     ::osl::ResettableMutexGuard aLock(m_aMutex);
716cdf0e10cSrcweir 
717cdf0e10cSrcweir         css::uno::Reference< css::frame::XTitle > xSubTitle(m_xSubTitle.get (), css::uno::UNO_QUERY);
718cdf0e10cSrcweir 
719cdf0e10cSrcweir     aLock.clear ();
720cdf0e10cSrcweir     // <- SYNCHRONIZED
721cdf0e10cSrcweir 
722cdf0e10cSrcweir     if (xSubTitle.is ())
723cdf0e10cSrcweir         return xSubTitle->getTitle ();
724cdf0e10cSrcweir 
725cdf0e10cSrcweir     return ::rtl::OUString ();
726cdf0e10cSrcweir }
727cdf0e10cSrcweir 
728cdf0e10cSrcweir //-----------------------------------------------
impl_convertURL2Title(const::rtl::OUString & sURL)729cdf0e10cSrcweir ::rtl::OUString TitleHelper::impl_convertURL2Title(const ::rtl::OUString& sURL)
730cdf0e10cSrcweir {
731cdf0e10cSrcweir     INetURLObject   aURL (sURL);
732cdf0e10cSrcweir     ::rtl::OUString sTitle;
733cdf0e10cSrcweir 
734cdf0e10cSrcweir     if (aURL.GetProtocol() == INET_PROT_FILE)
735cdf0e10cSrcweir     {
736cdf0e10cSrcweir         if (aURL.HasMark())
737cdf0e10cSrcweir             aURL = INetURLObject(aURL.GetURLNoMark());
738cdf0e10cSrcweir 
739cdf0e10cSrcweir         sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::DECODE_WITH_CHARSET);
740cdf0e10cSrcweir     }
741cdf0e10cSrcweir     else
742cdf0e10cSrcweir     {
743cdf0e10cSrcweir         if (aURL.hasExtension(INetURLObject::LAST_SEGMENT))
744cdf0e10cSrcweir             sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::DECODE_WITH_CHARSET);
745cdf0e10cSrcweir 
746cdf0e10cSrcweir         if ( ! sTitle.getLength() )
747cdf0e10cSrcweir 		    sTitle = aURL.GetHostPort(INetURLObject::DECODE_WITH_CHARSET);
748cdf0e10cSrcweir 
749cdf0e10cSrcweir         if ( ! sTitle.getLength() )
750cdf0e10cSrcweir             sTitle = aURL.GetURLNoPass(INetURLObject::DECODE_WITH_CHARSET);
751cdf0e10cSrcweir     }
752cdf0e10cSrcweir 
753cdf0e10cSrcweir     return sTitle;
754cdf0e10cSrcweir }
755cdf0e10cSrcweir 
756cdf0e10cSrcweir } // namespace framework
757