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 <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/frame/XTitle.hpp>
25 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp>
26 #include <com/sun/star/frame/XFrameActionListener.hpp>
27 #include <com/sun/star/document/XDocumentEventListener.hpp>
29 #include <cppuhelper/basemutex.hxx>
30 #include <cppuhelper/weakref.hxx>
31 #include <cppuhelper/implbase.hxx>
32 #include <cppuhelper/interfacecontainer.hxx>
34 #include <rtl/ustrbuf.hxx>
36 #include <framework/fwedllapi.h>
38 namespace com::sun::star::frame
{ class XController
; }
39 namespace com::sun::star::frame
{ class XFrame
; }
40 namespace com::sun::star::frame
{ class XModel
; }
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 FWE_DLLPUBLIC TitleHelper
: private ::cppu::BaseMutex
54 , public ::cppu::WeakImplHelper
< css::frame::XTitle
,
55 css::frame::XTitleChangeBroadcaster
,
56 css::frame::XTitleChangeListener
,
57 css::frame::XFrameActionListener
,
58 css::document::XDocumentEventListener
>
65 /** @short lightweight constructor.
67 TitleHelper(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
70 /** @short free all internally used resources.
72 virtual ~TitleHelper() override
;
75 /** set an outside component which uses this container and must be set
76 as source of all broadcasted messages, exceptions.
78 It's holded weak only so we do not need any complex dispose sessions.
80 Note: Passing NULL as parameter will be allowed. It will reset the internal
81 member reference only.
84 the new owner of this collection.
86 void setOwner (const css::uno::Reference
< css::uno::XInterface
>& xOwner
);
89 /** set an outside component which provides the right string and number for
90 an untitled component.
92 It's holded weak only so we do not need any complex dispose sessions.
94 Note: Passing NULL as parameter will be allowed. It will reset the internal
95 member reference only.
98 the right numbered collection for this helper.
100 void connectWithUntitledNumbers (const css::uno::Reference
< css::frame::XUntitledNumbers
>& xNumbers
);
104 virtual OUString SAL_CALL
getTitle() override
;
108 virtual void SAL_CALL
setTitle(const OUString
& sTitle
) override
;
111 /** @see XTitleChangeBroadcaster */
112 virtual void SAL_CALL
addTitleChangeListener(const css::uno::Reference
< css::frame::XTitleChangeListener
>& xListener
) override
;
115 /** @see XTitleChangeBroadcaster */
116 virtual void SAL_CALL
removeTitleChangeListener(const css::uno::Reference
< css::frame::XTitleChangeListener
>& xListener
) override
;
119 /** @see XTitleChangeListener */
120 virtual void SAL_CALL
titleChanged(const css::frame::TitleChangedEvent
& aEvent
) override
;
123 /** @see css.document.XDocumentEventListener */
124 virtual void SAL_CALL
documentEventOccured(const css::document::DocumentEvent
& aEvent
) override
;
127 /** @see css.lang.XEventListener */
128 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
) override
;
131 /** @see css.frame.XFrameActionListener */
132 virtual void SAL_CALL
frameAction(const css::frame::FrameActionEvent
& aEvent
) override
;
138 void impl_sendTitleChangedEvent ();
140 void impl_updateTitle (bool init
= false);
141 void impl_updateTitleForModel (const css::uno::Reference
< css::frame::XModel
>& xModel
, bool init
);
142 void impl_updateTitleForController (const css::uno::Reference
< css::frame::XController
>& xController
, bool init
);
143 void impl_updateTitleForFrame (const css::uno::Reference
< css::frame::XFrame
>& xFrame
, bool init
);
145 void impl_startListeningForModel (const css::uno::Reference
< css::frame::XModel
>& xModel
);
146 void impl_startListeningForController (const css::uno::Reference
< css::frame::XController
>& xController
);
147 void impl_startListeningForFrame (const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
148 void impl_updateListeningForFrame (const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
150 void impl_appendComponentTitle ( OUStringBuffer
& sTitle
,
151 const css::uno::Reference
< css::uno::XInterface
>& xComponent
);
152 void impl_appendProductName (OUStringBuffer
& sTitle
);
153 void impl_appendModuleName (OUStringBuffer
& sTitle
);
154 void impl_appendDebugVersion (OUStringBuffer
& sTitle
);
155 void impl_appendSafeMode (OUStringBuffer
& sTitle
);
157 void impl_setSubTitle (const css::uno::Reference
< css::frame::XTitle
>& xSubTitle
);
159 OUString
impl_convertURL2Title(const OUString
& sURL
);
165 /** points to the global uno service manager. */
166 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
168 /** reference to the outside UNO class using this helper. */
169 css::uno::WeakReference
< css::uno::XInterface
> m_xOwner
;
171 /** used to know how an "Untitled X" string can be created right :-) */
172 css::uno::WeakReference
< css::frame::XUntitledNumbers
> m_xUntitledNumbers
;
174 /** provides parts of our own title and we listen there for changes too. */
175 css::uno::WeakReference
< css::frame::XTitle
> m_xSubTitle
;
177 /** if it's set to sal_True the member m_sTitle has not to be changed internally.
178 It was set from outside and so outside code has to make sure it will be
181 bool m_bExternalTitle
;
183 /** the actual title value */
186 /** knows the leased number which must be used for untitled components. */
187 ::sal_Int32 m_nLeasedNumber
;
189 /** contains all title change listener */
190 ::cppu::OMultiTypeInterfaceContainerHelper m_aListener
;
193 } // namespace framework
195 #endif // INCLUDED_FRAMEWORK_TITLEHELPER_HXX
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */