Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <framework/titlehelper.hxx>
21 : #include <services.h>
22 : #include <properties.h>
23 :
24 : #include <com/sun/star/frame/UntitledNumbersConst.hpp>
25 : #include <com/sun/star/frame/XStorable.hpp>
26 : #include <com/sun/star/frame/ModuleManager.hpp>
27 : #include <com/sun/star/container/XNameAccess.hpp>
28 : #include <com/sun/star/document/XEventBroadcaster.hpp>
29 : #include <com/sun/star/beans/XMaterialHolder.hpp>
30 :
31 : #include <unotools/configmgr.hxx>
32 : #include <unotools/bootstrap.hxx>
33 : #include <comphelper/sequenceashashmap.hxx>
34 : #include <rtl/ustrbuf.hxx>
35 : #include <osl/mutex.hxx>
36 : #include <tools/urlobj.hxx>
37 :
38 :
39 : namespace framework{
40 :
41 : //-----------------------------------------------
42 3575 : TitleHelper::TitleHelper(const css::uno::Reference< css::uno::XComponentContext >& rxContext)
43 : : ::cppu::BaseMutex ()
44 : , m_xContext (rxContext)
45 : , m_xOwner ()
46 : , m_xUntitledNumbers()
47 : , m_xSubTitle ()
48 : , m_bExternalTitle (sal_False)
49 : , m_sTitle ()
50 : , m_nLeasedNumber (css::frame::UntitledNumbersConst::INVALID_NUMBER)
51 3575 : , m_aListener (m_aMutex)
52 : {
53 3575 : }
54 :
55 : //-----------------------------------------------
56 6654 : TitleHelper::~TitleHelper()
57 : {
58 6654 : }
59 :
60 : //-----------------------------------------------
61 3575 : void TitleHelper::setOwner(const css::uno::Reference< css::uno::XInterface >& xOwner)
62 : {
63 : // SYNCHRONIZED ->
64 3575 : ::osl::ResettableMutexGuard aLock(m_aMutex);
65 :
66 3575 : m_xOwner = xOwner;
67 :
68 3575 : aLock.clear ();
69 : // <- SYNCHRONIZED
70 :
71 3575 : css::uno::Reference< css::frame::XModel > xModel(xOwner, css::uno::UNO_QUERY);
72 3575 : if (xModel.is ())
73 : {
74 1378 : impl_startListeningForModel (xModel);
75 1378 : return;
76 : }
77 :
78 2197 : css::uno::Reference< css::frame::XController > xController(xOwner, css::uno::UNO_QUERY);
79 2197 : if (xController.is ())
80 : {
81 1091 : impl_startListeningForController (xController);
82 1091 : return;
83 : }
84 :
85 1106 : css::uno::Reference< css::frame::XFrame > xFrame(xOwner, css::uno::UNO_QUERY);
86 1106 : if (xFrame.is ())
87 : {
88 1106 : impl_startListeningForFrame (xFrame);
89 1106 : return;
90 0 : }
91 : }
92 :
93 : //-----------------------------------------------
94 12756 : OUString SAL_CALL TitleHelper::getTitle()
95 : throw (css::uno::RuntimeException)
96 : {
97 : // SYNCHRONIZED ->
98 12756 : ::osl::ResettableMutexGuard aLock(m_aMutex);
99 :
100 : // An external title will win always and disable all internal logic about
101 : // creating/using a title value.
102 : // Even an empty string will be accepted as valid title !
103 12756 : if (m_bExternalTitle)
104 8 : return m_sTitle;
105 :
106 : // Title seams to be up-to-date. Return it directly.
107 12748 : if (!m_sTitle.isEmpty())
108 8084 : return m_sTitle;
109 :
110 : // Title seams to be unused till now ... do bootstraping
111 4664 : impl_updateTitle (true);
112 :
113 4664 : return m_sTitle;
114 :
115 : // <- SYNCHRONIZED
116 : }
117 :
118 : //-----------------------------------------------
119 2469 : void TitleHelper::connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers)
120 : {
121 : // SYNCHRONIZED ->
122 2469 : ::osl::ResettableMutexGuard aLock(m_aMutex);
123 :
124 2469 : m_xUntitledNumbers = xNumbers;
125 :
126 : // <- SYNCHRONIZED
127 2469 : }
128 :
129 : //-----------------------------------------------
130 2 : void SAL_CALL TitleHelper::setTitle(const OUString& sTitle)
131 : throw (css::uno::RuntimeException)
132 : {
133 : // SYNCHRONIZED ->
134 2 : ::osl::ResettableMutexGuard aLock(m_aMutex);
135 :
136 2 : m_bExternalTitle = sal_True;
137 2 : m_sTitle = sTitle;
138 :
139 2 : aLock.clear ();
140 : // <- SYNCHRONIZED
141 :
142 2 : impl_sendTitleChangedEvent ();
143 2 : }
144 :
145 : //-----------------------------------------------
146 3284 : void SAL_CALL TitleHelper::addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
147 : throw (css::uno::RuntimeException)
148 : {
149 : // container is threadsafe by himself
150 3284 : m_aListener.addInterface( ::getCppuType( (const css::uno::Reference< css::frame::XTitleChangeListener >*)NULL ), xListener );
151 3284 : }
152 :
153 : //-----------------------------------------------
154 9 : void SAL_CALL TitleHelper::removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
155 : throw (css::uno::RuntimeException)
156 : {
157 : // container is threadsafe by himself
158 9 : m_aListener.removeInterface( ::getCppuType( (const css::uno::Reference< css::frame::XTitleChangeListener >*)NULL ), xListener );
159 9 : }
160 :
161 : //-----------------------------------------------
162 3724 : void SAL_CALL TitleHelper::titleChanged(const css::frame::TitleChangedEvent& aEvent)
163 : throw (css::uno::RuntimeException)
164 : {
165 : // SYNCHRONIZED ->
166 3724 : ::osl::ResettableMutexGuard aLock(m_aMutex);
167 :
168 7439 : css::uno::Reference< css::frame::XTitle > xSubTitle(m_xSubTitle.get (), css::uno::UNO_QUERY);
169 :
170 3724 : aLock.clear ();
171 : // <- SYNCHRONIZED
172 :
173 3724 : if (aEvent.Source != xSubTitle)
174 3715 : return;
175 :
176 7448 : impl_updateTitle ();
177 : }
178 :
179 : //-----------------------------------------------
180 14321 : void SAL_CALL TitleHelper::notifyEvent(const css::document::EventObject& aEvent)
181 : throw (css::uno::RuntimeException)
182 : {
183 28642 : if ( ! aEvent.EventName.equalsIgnoreAsciiCase("OnSaveAsDone")
184 14311 : && ! aEvent.EventName.equalsIgnoreAsciiCase("OnModeChanged")
185 28182 : && ! aEvent.EventName.equalsIgnoreAsciiCase("OnTitleChanged"))
186 20258 : return;
187 :
188 : // SYNCHRONIZED ->
189 4192 : ::osl::ResettableMutexGuard aLock(m_aMutex);
190 :
191 8384 : css::uno::Reference< css::frame::XModel > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
192 :
193 4192 : aLock.clear ();
194 : // <- SYNCHRONIZED
195 :
196 8384 : if (aEvent.Source != xOwner
197 4192 : || ((aEvent.EventName.equalsIgnoreAsciiCase("OnModeChanged")
198 3742 : || aEvent.EventName.equalsIgnoreAsciiCase("OnTitleChanged"))
199 4182 : && !xOwner.is()))
200 : {
201 0 : return;
202 : }
203 :
204 8384 : impl_updateTitle ();
205 : }
206 :
207 : //-----------------------------------------------
208 5891 : void SAL_CALL TitleHelper::frameAction(const css::frame::FrameActionEvent& aEvent)
209 : throw(css::uno::RuntimeException)
210 : {
211 : // SYNCHRONIZED ->
212 5891 : ::osl::ResettableMutexGuard aLock(m_aMutex);
213 :
214 11782 : css::uno::Reference< css::frame::XFrame > xOwner(m_xOwner.get (), css::uno::UNO_QUERY);
215 :
216 5891 : aLock.clear ();
217 : // <- SYNCHRONIZED
218 :
219 5891 : if (aEvent.Source != xOwner)
220 5891 : return;
221 :
222 : // we are interested on events only, which must trigger a title bar update
223 : // because component was changed.
224 5891 : if (
225 10680 : (aEvent.Action == css::frame::FrameAction_COMPONENT_ATTACHED ) ||
226 9569 : (aEvent.Action == css::frame::FrameAction_COMPONENT_REATTACHED) ||
227 4780 : (aEvent.Action == css::frame::FrameAction_COMPONENT_DETACHING )
228 : )
229 : {
230 2215 : impl_updateListeningForFrame (xOwner);
231 2215 : impl_updateTitle ();
232 5891 : }
233 : }
234 :
235 : //-----------------------------------------------
236 2459 : void SAL_CALL TitleHelper::disposing(const css::lang::EventObject& aEvent)
237 : throw (css::uno::RuntimeException)
238 : {
239 : // SYNCHRONIZED ->
240 2459 : ::osl::ResettableMutexGuard aLock(m_aMutex);
241 4918 : css::uno::Reference< css::uno::XInterface > xOwner (m_xOwner.get() , css::uno::UNO_QUERY);
242 4918 : css::uno::Reference< css::frame::XUntitledNumbers > xNumbers (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
243 2459 : ::sal_Int32 nLeasedNumber = m_nLeasedNumber;
244 2459 : aLock.clear ();
245 : // <- SYNCHRONIZED
246 :
247 2459 : if ( ! xOwner.is ())
248 0 : return;
249 :
250 2459 : if (xOwner != aEvent.Source)
251 0 : return;
252 :
253 2459 : if (
254 2459 : (xNumbers.is () ) &&
255 : (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
256 : )
257 766 : xNumbers->releaseNumber (nLeasedNumber);
258 :
259 : // SYNCHRONIZED ->
260 2459 : aLock.reset ();
261 :
262 2459 : m_sTitle = OUString ();
263 2459 : m_nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
264 :
265 2459 : aLock.clear ();
266 : // <- SYNCHRONIZED
267 :
268 4918 : impl_sendTitleChangedEvent ();
269 : }
270 :
271 : //-----------------------------------------------
272 6707 : void TitleHelper::impl_sendTitleChangedEvent ()
273 : {
274 : // SYNCHRONIZED ->
275 6707 : ::osl::ResettableMutexGuard aLock(m_aMutex);
276 :
277 11541 : css::frame::TitleChangedEvent aEvent(m_xOwner.get (), m_sTitle);
278 :
279 6707 : aLock.clear ();
280 : // <- SYNCHRONIZED
281 :
282 6707 : ::cppu::OInterfaceContainerHelper* pContainer = m_aListener.getContainer( ::getCppuType( ( const css::uno::Reference< css::frame::XTitleChangeListener >*) NULL ) );
283 6707 : if ( ! pContainer)
284 8580 : return;
285 :
286 9668 : ::cppu::OInterfaceIteratorHelper pIt( *pContainer );
287 14525 : while ( pIt.hasMoreElements() )
288 : {
289 : try
290 : {
291 4857 : ((css::frame::XTitleChangeListener*)pIt.next())->titleChanged( aEvent );
292 : }
293 9 : catch(const css::uno::Exception&)
294 : {
295 9 : pIt.remove();
296 : }
297 4834 : }
298 : }
299 :
300 : //-----------------------------------------------
301 14795 : void TitleHelper::impl_updateTitle (bool init)
302 : {
303 : // SYNCHRONIZED ->
304 14795 : ::osl::ResettableMutexGuard aLock(m_aMutex);
305 :
306 29590 : css::uno::Reference< css::frame::XModel > xModel (m_xOwner.get(), css::uno::UNO_QUERY);
307 29590 : css::uno::Reference< css::frame::XController > xController(m_xOwner.get(), css::uno::UNO_QUERY);
308 29581 : css::uno::Reference< css::frame::XFrame > xFrame (m_xOwner.get(), css::uno::UNO_QUERY);
309 :
310 14795 : aLock.clear ();
311 : // <- SYNCHRONIZED
312 :
313 14795 : if (xModel.is ())
314 : {
315 5570 : impl_updateTitleForModel (xModel, init);
316 : }
317 9225 : else if (xController.is ())
318 : {
319 4796 : impl_updateTitleForController (xController, init);
320 : }
321 4429 : else if (xFrame.is ())
322 : {
323 4429 : impl_updateTitleForFrame (xFrame, init);
324 14795 : }
325 14786 : }
326 :
327 : //-----------------------------------------------
328 5570 : void TitleHelper::impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel, bool init)
329 : {
330 : // SYNCHRONIZED ->
331 5570 : ::osl::ResettableMutexGuard aLock(m_aMutex);
332 :
333 : // external title wont be updated internaly !
334 : // It has to be set from outside new.
335 5570 : if (m_bExternalTitle)
336 6 : return;
337 :
338 11128 : css::uno::Reference< css::uno::XInterface > xOwner (m_xOwner.get() , css::uno::UNO_QUERY);
339 11128 : css::uno::Reference< css::frame::XUntitledNumbers > xNumbers (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
340 5564 : ::sal_Int32 nLeasedNumber = m_nLeasedNumber;
341 :
342 5564 : aLock.clear ();
343 : // <- SYNCHRONIZED
344 :
345 5564 : if (
346 11128 : ( ! xOwner.is ()) ||
347 11128 : ( ! xNumbers.is ()) ||
348 5564 : ( ! xModel.is ())
349 : )
350 0 : return;
351 :
352 11128 : OUString sTitle;
353 11128 : OUString sURL ;
354 :
355 11128 : css::uno::Reference< css::frame::XStorable > xURLProvider(xModel , css::uno::UNO_QUERY);
356 5564 : if (xURLProvider.is())
357 5564 : sURL = xURLProvider->getLocation ();
358 :
359 5564 : if (!sURL.isEmpty())
360 : {
361 1671 : sTitle = impl_convertURL2Title(sURL);
362 1671 : if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
363 6 : xNumbers->releaseNumber (nLeasedNumber);
364 1671 : nLeasedNumber = css::frame::UntitledNumbersConst::INVALID_NUMBER;
365 : }
366 : else
367 : {
368 3893 : if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
369 778 : nLeasedNumber = xNumbers->leaseNumber (xOwner);
370 :
371 3893 : OUStringBuffer sNewTitle(256);
372 3893 : sNewTitle.append (xNumbers->getUntitledPrefix ());
373 3893 : if (nLeasedNumber != css::frame::UntitledNumbersConst::INVALID_NUMBER)
374 3893 : sNewTitle.append ((::sal_Int32)nLeasedNumber);
375 : else
376 0 : sNewTitle.appendAscii ("?");
377 :
378 3893 : sTitle = sNewTitle.makeStringAndClear ();
379 : }
380 :
381 : // SYNCHRONIZED ->
382 5564 : aLock.reset ();
383 :
384 : // WORKAROUND: the notification is currently sent always,
385 : // can be changed after shared mode is supported per UNO API
386 5564 : sal_Bool bChanged = !init; // && m_sTitle != sTitle
387 :
388 5564 : m_sTitle = sTitle;
389 5564 : m_nLeasedNumber = nLeasedNumber;
390 :
391 5564 : aLock.clear ();
392 : // <- SYNCHRONIZED
393 :
394 5564 : if (bChanged)
395 9750 : impl_sendTitleChangedEvent ();
396 : }
397 :
398 : //-----------------------------------------------
399 4796 : void TitleHelper::impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController, bool init)
400 : {
401 : // SYNCHRONIZED ->
402 4796 : ::osl::ResettableMutexGuard aLock(m_aMutex);
403 :
404 : // external title wont be updated internaly !
405 : // It has to be set from outside new.
406 4796 : if (m_bExternalTitle)
407 0 : return;
408 :
409 9590 : css::uno::Reference< css::uno::XInterface > xOwner (m_xOwner.get() , css::uno::UNO_QUERY);
410 9590 : css::uno::Reference< css::frame::XUntitledNumbers > xNumbers (m_xUntitledNumbers.get(), css::uno::UNO_QUERY);
411 4796 : ::sal_Int32 nLeasedNumber = m_nLeasedNumber;
412 :
413 4796 : aLock.clear ();
414 : // <- SYNCHRONIZED
415 :
416 4796 : if (
417 9592 : ( ! xOwner.is ()) ||
418 9590 : ( ! xNumbers.is ()) ||
419 4794 : ( ! xController.is ())
420 : )
421 2 : return;
422 :
423 9588 : OUStringBuffer sTitle(256);
424 :
425 4794 : if (nLeasedNumber == css::frame::UntitledNumbersConst::INVALID_NUMBER)
426 1090 : nLeasedNumber = xNumbers->leaseNumber (xOwner);
427 :
428 9588 : css::uno::Reference< css::frame::XTitle > xModelTitle(xController->getModel (), css::uno::UNO_QUERY);
429 4794 : if (!xModelTitle.is ())
430 1097 : xModelTitle.set(xController, css::uno::UNO_QUERY);
431 4794 : if (xModelTitle.is ())
432 : {
433 4794 : sTitle.append (xModelTitle->getTitle ());
434 4794 : if ( nLeasedNumber > 1 )
435 : {
436 32 : sTitle.appendAscii (" : ");
437 32 : sTitle.append ((::sal_Int32)nLeasedNumber);
438 : }
439 : }
440 : else
441 : {
442 0 : sTitle.append (xNumbers->getUntitledPrefix ());
443 0 : if ( nLeasedNumber > 1 )
444 : {
445 0 : sTitle.append ((::sal_Int32)nLeasedNumber );
446 : }
447 : }
448 :
449 : // SYNCHRONIZED ->
450 4794 : aLock.reset ();
451 :
452 9588 : OUString sNewTitle = sTitle.makeStringAndClear ();
453 4794 : sal_Bool bChanged = !init && m_sTitle != sNewTitle;
454 4794 : m_sTitle = sNewTitle;
455 4794 : m_nLeasedNumber = nLeasedNumber;
456 :
457 4794 : aLock.clear ();
458 : // <- SYNCHRONIZED
459 :
460 4794 : if (bChanged)
461 4814 : impl_sendTitleChangedEvent ();
462 : }
463 :
464 : //-----------------------------------------------
465 4429 : void TitleHelper::impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame, bool init)
466 : {
467 4429 : if ( ! xFrame.is ())
468 1 : return;
469 :
470 : // SYNCHRONIZED ->
471 4429 : ::osl::ResettableMutexGuard aLock(m_aMutex);
472 :
473 : // external title wont be updated internaly !
474 : // It has to be set from outside new.
475 4429 : if (m_bExternalTitle)
476 1 : return;
477 :
478 4428 : aLock.clear ();
479 : // <- SYNCHRONIZED
480 :
481 8856 : css::uno::Reference< css::uno::XInterface > xComponent;
482 4428 : xComponent = xFrame->getController ();
483 4428 : if ( ! xComponent.is ())
484 1104 : xComponent = xFrame->getComponentWindow ();
485 :
486 8838 : OUStringBuffer sTitle (256);
487 :
488 4419 : impl_appendComponentTitle (sTitle, xComponent);
489 4419 : impl_appendProductName (sTitle);
490 4419 : impl_appendModuleName (sTitle);
491 4419 : impl_appendDebugVersion (sTitle);
492 :
493 : // SYNCHRONIZED ->
494 4419 : aLock.reset ();
495 :
496 8838 : OUString sNewTitle = sTitle.makeStringAndClear ();
497 4419 : sal_Bool bChanged = !init && m_sTitle != sNewTitle;
498 4419 : m_sTitle = sNewTitle;
499 :
500 4419 : aLock.clear ();
501 : // <- SYNCHRONIZED
502 :
503 4419 : if (bChanged)
504 4468 : impl_sendTitleChangedEvent ();
505 : }
506 :
507 : //*****************************************************************************************************************
508 4419 : void TitleHelper::impl_appendComponentTitle ( OUStringBuffer& sTitle ,
509 : const css::uno::Reference< css::uno::XInterface >& xComponent)
510 : {
511 4419 : css::uno::Reference< css::frame::XTitle > xTitle(xComponent, css::uno::UNO_QUERY);
512 :
513 : // Note: Title has to be used (even if it's empty) if the right interface is supported.
514 4419 : if (xTitle.is ())
515 3267 : sTitle.append (xTitle->getTitle ());
516 4419 : }
517 :
518 : //*****************************************************************************************************************
519 4419 : void TitleHelper::impl_appendProductName (OUStringBuffer& sTitle)
520 : {
521 4419 : OUString name(utl::ConfigManager::getProductName());
522 4419 : if (!name.isEmpty())
523 : {
524 4419 : if (!sTitle.isEmpty())
525 3266 : sTitle.appendAscii(RTL_CONSTASCII_STRINGPARAM(" - "));
526 4419 : sTitle.append(name);
527 4419 : }
528 4419 : }
529 :
530 : //*****************************************************************************************************************
531 4419 : void TitleHelper::impl_appendModuleName (OUStringBuffer& sTitle)
532 : {
533 : // SYNCHRONIZED ->
534 4419 : ::osl::ResettableMutexGuard aLock(m_aMutex);
535 :
536 8838 : css::uno::Reference< css::uno::XInterface > xOwner = m_xOwner.get();
537 8838 : css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext;
538 :
539 4419 : aLock.clear ();
540 : // <- SYNCHRONIZED
541 :
542 : try
543 : {
544 : css::uno::Reference< css::frame::XModuleManager2 > xModuleManager =
545 4419 : css::frame::ModuleManager::create(xContext);
546 :
547 7723 : const OUString sID = xModuleManager->identify(xOwner);
548 6600 : ::comphelper::SequenceAsHashMap lProps = xModuleManager->getByName (sID);
549 6592 : const OUString sUIName = lProps.getUnpackedValueOrDefault (OFFICEFACTORY_PROPNAME_UINAME, OUString());
550 :
551 : // An UIname property is an optional value !
552 : // So please add it to the title in case it does realy exists only.
553 3296 : if (!sUIName.isEmpty())
554 : {
555 3294 : sTitle.appendAscii (" " );
556 3294 : sTitle.append (sUIName);
557 4419 : }
558 : }
559 1123 : catch(const css::uno::Exception&)
560 4419 : {}
561 4419 : }
562 :
563 : //*****************************************************************************************************************
564 : #ifdef DBG_UTIL
565 : void TitleHelper::impl_appendDebugVersion (OUStringBuffer& sTitle)
566 : {
567 : OUString version(utl::ConfigManager::getProductVersion());
568 : sTitle.append(' ');
569 : sTitle.append(version);
570 : OUString sDefault("development");
571 : OUString sVersion = ::utl::Bootstrap::getBuildIdData(sDefault);
572 : sTitle.appendAscii(RTL_CONSTASCII_STRINGPARAM(" ["));
573 : sTitle.append(sVersion);
574 : sTitle.appendAscii(RTL_CONSTASCII_STRINGPARAM("]"));
575 : }
576 : #else
577 4419 : void TitleHelper::impl_appendDebugVersion (OUStringBuffer&)
578 : {
579 4419 : }
580 : #endif
581 :
582 : //-----------------------------------------------
583 1378 : void TitleHelper::impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel)
584 : {
585 1378 : css::uno::Reference< css::document::XEventBroadcaster > xBroadcaster(xModel, css::uno::UNO_QUERY);
586 1378 : if ( ! xBroadcaster.is ())
587 1378 : return;
588 :
589 1378 : xBroadcaster->addEventListener (static_cast< css::document::XEventListener* >(this));
590 : }
591 :
592 : //-----------------------------------------------
593 1091 : void TitleHelper::impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController)
594 : {
595 1091 : css::uno::Reference< css::frame::XTitle > xSubTitle(xController->getModel (), css::uno::UNO_QUERY);
596 1091 : impl_setSubTitle (xSubTitle);
597 1091 : }
598 :
599 : //-----------------------------------------------
600 1106 : void TitleHelper::impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
601 : {
602 1106 : xFrame->addFrameActionListener(this );
603 1106 : impl_updateListeningForFrame (xFrame);
604 1106 : }
605 :
606 : //-----------------------------------------------
607 3321 : void TitleHelper::impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame)
608 : {
609 3321 : css::uno::Reference< css::frame::XTitle > xSubTitle(xFrame->getController (), css::uno::UNO_QUERY);
610 3321 : impl_setSubTitle (xSubTitle);
611 3321 : }
612 :
613 : //-----------------------------------------------
614 4412 : void TitleHelper::impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle)
615 : {
616 : // SYNCHRONIZED ->
617 4412 : ::osl::ResettableMutexGuard aLock(m_aMutex);
618 :
619 : // ignore duplicate calls. Makes outside using of this helper more easy :-)
620 6594 : css::uno::Reference< css::frame::XTitle > xOldSubTitle(m_xSubTitle.get(), css::uno::UNO_QUERY);
621 4412 : if (xOldSubTitle == xSubTitle)
622 6642 : return;
623 :
624 2182 : m_xSubTitle = xSubTitle;
625 :
626 2182 : aLock.clear ();
627 : // <- SYNCHRONIZED
628 :
629 4364 : css::uno::Reference< css::frame::XTitleChangeBroadcaster > xOldBroadcaster(xOldSubTitle , css::uno::UNO_QUERY );
630 4364 : css::uno::Reference< css::frame::XTitleChangeBroadcaster > xNewBroadcaster(xSubTitle , css::uno::UNO_QUERY );
631 4364 : css::uno::Reference< css::frame::XTitleChangeListener > xThis (static_cast< css::frame::XTitleChangeListener* >(this), css::uno::UNO_QUERY_THROW);
632 :
633 2182 : if (xOldBroadcaster.is())
634 9 : xOldBroadcaster->removeTitleChangeListener (xThis);
635 :
636 2182 : if (xNewBroadcaster.is())
637 4363 : xNewBroadcaster->addTitleChangeListener (xThis);
638 : }
639 :
640 : //-----------------------------------------------
641 1671 : OUString TitleHelper::impl_convertURL2Title(const OUString& sURL)
642 : {
643 1671 : INetURLObject aURL (sURL);
644 1671 : OUString sTitle;
645 :
646 1671 : if (aURL.GetProtocol() == INET_PROT_FILE)
647 : {
648 1671 : if (aURL.HasMark())
649 0 : aURL = INetURLObject(aURL.GetURLNoMark());
650 :
651 1671 : sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::DECODE_WITH_CHARSET);
652 : }
653 : else
654 : {
655 0 : if (aURL.hasExtension(INetURLObject::LAST_SEGMENT))
656 0 : sTitle = aURL.getName(INetURLObject::LAST_SEGMENT, sal_True, INetURLObject::DECODE_WITH_CHARSET);
657 :
658 0 : if ( sTitle.isEmpty() )
659 0 : sTitle = aURL.GetHostPort(INetURLObject::DECODE_WITH_CHARSET);
660 :
661 0 : if ( sTitle.isEmpty() )
662 0 : sTitle = aURL.GetURLNoPass(INetURLObject::DECODE_WITH_CHARSET);
663 : }
664 :
665 1671 : return sTitle;
666 : }
667 :
668 : } // namespace framework
669 :
670 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|