1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_FRAMEWORK_TITLEHELPER_HXX
21 #define INCLUDED_FRAMEWORK_TITLEHELPER_HXX
23 #include <config_options.h>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/frame/XTitle.hpp>
26 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp>
27 #include <com/sun/star/frame/XFrameActionListener.hpp>
28 #include <com/sun/star/document/XDocumentEventListener.hpp>
30 #include <cppuhelper/weakref.hxx>
31 #include <comphelper/compbase.hxx>
32 #include <comphelper/interfacecontainer4.hxx>
34 #include <rtl/ustrbuf.hxx>
36 #include <framework/fwkdllapi.h>
38 namespace com::sun::star::frame
{ class XController
; }
39 namespace com::sun::star::frame
{ class XFrame
; }
40 namespace com::sun::star::frame
{ class XModel3
; }
41 namespace com::sun::star::frame
{ class XUntitledNumbers
; }
42 namespace com::sun::star::uno
{ class XComponentContext
; }
43 namespace com::sun::star::uno
{ class XInterface
; }
49 /** @short can be used as implementation helper of interface css.frame.XTitle
53 class UNLESS_MERGELIBS_MORE(FWK_DLLPUBLIC
) TitleHelper final
:
54 public ::comphelper::WeakImplHelper
< css::frame::XTitle
,
55 css::frame::XTitleChangeBroadcaster
,
56 css::frame::XTitleChangeListener
,
57 css::frame::XFrameActionListener
,
58 css::document::XDocumentEventListener
>
65 /** set an outside component which uses this container and must be set
66 as source of all broadcasted messages, exceptions.
68 It's holded weak only so we do not need any complex dispose sessions.
70 Note: Passing NULL as parameter will be allowed. It will reset the internal
71 member reference only.
74 the new owner of this collection.
76 provides the right string and number for an untitled component.
78 TitleHelper(css::uno::Reference
< css::uno::XComponentContext
> xContext
,
79 const css::uno::Reference
< css::uno::XInterface
>& xOwner
,
80 const css::uno::Reference
< css::frame::XUntitledNumbers
>& xNumbers
);
82 /** @short free all internally used resources.
84 virtual ~TitleHelper() override
;
88 virtual OUString SAL_CALL
getTitle() override
;
92 virtual void SAL_CALL
setTitle(const OUString
& sTitle
) override
;
95 /** @see XTitleChangeBroadcaster */
96 virtual void SAL_CALL
addTitleChangeListener(const css::uno::Reference
< css::frame::XTitleChangeListener
>& xListener
) override
;
99 /** @see XTitleChangeBroadcaster */
100 virtual void SAL_CALL
removeTitleChangeListener(const css::uno::Reference
< css::frame::XTitleChangeListener
>& xListener
) override
;
103 /** @see XTitleChangeListener */
104 virtual void SAL_CALL
titleChanged(const css::frame::TitleChangedEvent
& aEvent
) override
;
107 /** @see css.document.XDocumentEventListener */
108 virtual void SAL_CALL
documentEventOccured(const css::document::DocumentEvent
& aEvent
) override
;
111 /** @see css.lang.XEventListener */
112 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
) override
;
115 /** @see css.frame.XFrameActionListener */
116 virtual void SAL_CALL
frameAction(const css::frame::FrameActionEvent
& aEvent
) override
;
122 void impl_sendTitleChangedEvent ();
124 void impl_updateTitle (bool init
= false);
125 void impl_updateTitleForModel (const css::uno::Reference
< css::frame::XModel3
>& xModel
, bool init
);
126 void impl_updateTitleForController (const css::uno::Reference
< css::frame::XController
>& xController
, bool init
);
127 void impl_updateTitleForFrame (const css::uno::Reference
< css::frame::XFrame
>& xFrame
, bool init
);
129 void impl_startListeningForModel (const css::uno::Reference
< css::frame::XModel
>& xModel
);
130 void impl_startListeningForController (const css::uno::Reference
< css::frame::XController
>& xController
);
131 void impl_startListeningForFrame (const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
132 void impl_updateListeningForFrame (const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
134 static void impl_appendComponentTitle ( OUStringBuffer
& sTitle
,
135 const css::uno::Reference
< css::uno::XInterface
>& xComponent
);
136 static void impl_appendProductName (OUStringBuffer
& sTitle
);
137 void impl_appendModuleName (OUStringBuffer
& sTitle
);
138 static void impl_appendDebugVersion (OUStringBuffer
& sTitle
);
139 static void impl_appendSafeMode (OUStringBuffer
& sTitle
);
141 void impl_setSubTitle (const css::uno::Reference
< css::frame::XTitle
>& xSubTitle
);
143 static OUString
impl_convertURL2Title(std::u16string_view sURL
);
149 /** points to the global uno service manager. */
150 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
152 /** reference to the outside UNO class using this helper. */
153 css::uno::WeakReference
< css::uno::XInterface
> m_xOwner
;
155 /** used to know how an "Untitled X" string can be created right :-) */
156 css::uno::WeakReference
< css::frame::XUntitledNumbers
> m_xUntitledNumbers
;
158 /** provides parts of our own title and we listen there for changes too. */
159 css::uno::WeakReference
< css::frame::XTitle
> m_xSubTitle
;
161 /** if it's set to sal_True the member m_sTitle has not to be changed internally.
162 It was set from outside and so outside code has to make sure it will be
165 bool m_bExternalTitle
;
167 /** the actual title value */
170 /** knows the leased number which must be used for untitled components. */
171 ::sal_Int32 m_nLeasedNumber
;
173 /** contains all title change listener */
174 comphelper::OInterfaceContainerHelper4
<css::frame::XTitleChangeListener
> m_aTitleChangeListeners
;
177 } // namespace framework
179 #endif // INCLUDED_FRAMEWORK_TITLEHELPER_HXX
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */