Branch libreoffice-5-0-4
[LibreOffice.git] / include / framework / titlehelper.hxx
bloba1653d7ceacb9d2637dcd2ceef55f3206806658f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/uno/XInterface.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 #include <com/sun/star/frame/XUntitledNumbers.hpp>
28 #include <com/sun/star/frame/XTitle.hpp>
29 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp>
30 #include <com/sun/star/frame/XModel.hpp>
31 #include <com/sun/star/frame/XController.hpp>
32 #include <com/sun/star/frame/XFrame.hpp>
33 #include <com/sun/star/frame/XFrameActionListener.hpp>
34 #include <com/sun/star/document/XDocumentEventListener.hpp>
36 #include <cppuhelper/basemutex.hxx>
37 #include <cppuhelper/weakref.hxx>
38 #include <cppuhelper/implbase5.hxx>
39 #include <cppuhelper/interfacecontainer.hxx>
41 #include <rtl/ustrbuf.hxx>
43 #include <framework/fwedllapi.h>
46 namespace framework{
49 /** @short can be used as implementation helper of interface css.frame.XTitle
51 @threadsafe
53 class FWE_DLLPUBLIC TitleHelper : private ::cppu::BaseMutex
54 , public ::cppu::WeakImplHelper5< css::frame::XTitle ,
55 css::frame::XTitleChangeBroadcaster,
56 css::frame::XTitleChangeListener ,
57 css::frame::XFrameActionListener ,
58 css::document::XDocumentEventListener >
61 // interface
62 public:
65 /** @short lightweight constructor.
67 TitleHelper(const css::uno::Reference< css::uno::XComponentContext >& rxContext);
70 /** @short free all internally used resources.
72 virtual ~TitleHelper();
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.
83 @param xOwner
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 righht 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.
97 @param xNumbers
98 the right numbered collection for this helper.
100 void connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers);
103 /** @see XTitle */
104 virtual OUString SAL_CALL getTitle()
105 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
108 /** @see XTitle */
109 virtual void SAL_CALL setTitle(const OUString& sTitle)
110 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
113 /** @see XTitleChangeBroadcaster */
114 virtual void SAL_CALL addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
115 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
118 /** @see XTitleChangeBroadcaster */
119 virtual void SAL_CALL removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
120 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
123 /** @see XTitleChangeListener */
124 virtual void SAL_CALL titleChanged(const css::frame::TitleChangedEvent& aEvent)
125 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
128 /** @see css.document.XDocumentEventListener */
129 virtual void SAL_CALL documentEventOccured(const css::document::DocumentEvent& aEvent)
130 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
133 /** @see css.lang.XEventListener */
134 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
135 throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
138 /** @see css.frame.XFrameActionListener */
139 virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent)
140 throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 // internal
144 private:
146 void impl_sendTitleChangedEvent ();
148 void impl_updateTitle (bool init = false);
149 void impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel, bool init);
150 void impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController, bool init);
151 void impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame, bool init);
153 void impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel);
154 void impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController);
155 void impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
156 void impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
158 void impl_appendComponentTitle ( OUStringBuffer& sTitle ,
159 const css::uno::Reference< css::uno::XInterface >& xComponent);
160 void impl_appendProductName (OUStringBuffer& sTitle);
161 void impl_appendProductExtension (OUStringBuffer& sTitle);
162 void impl_appendModuleName (OUStringBuffer& sTitle);
163 void impl_appendDebugVersion (OUStringBuffer& sTitle);
165 void impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle);
167 OUString impl_convertURL2Title(const OUString& sURL);
170 // member
171 private:
173 /** points to the global uno service manager. */
174 css::uno::Reference< css::uno::XComponentContext> m_xContext;
176 /** reference to the outside UNO class using this helper. */
177 css::uno::WeakReference< css::uno::XInterface > m_xOwner;
179 /** used to know how an "Untitled X" string can be created right :-) */
180 css::uno::WeakReference< css::frame::XUntitledNumbers > m_xUntitledNumbers;
182 /** provides parts of our own title and we listen there for changes too. */
183 css::uno::WeakReference< css::frame::XTitle > m_xSubTitle;
185 /** if it's set to sal_True the member m_sTitle has not to be changed internally.
186 It was set from outside and so outside code has to make sure it will be
187 updated.
189 bool m_bExternalTitle;
191 /** the actual title value */
192 OUString m_sTitle;
194 /** knows the leased number which must be used for untitled components. */
195 ::sal_Int32 m_nLeasedNumber;
197 /** contains all title change listener */
198 ::cppu::OMultiTypeInterfaceContainerHelper m_aListener;
201 } // namespace framework
203 #endif // INCLUDED_FRAMEWORK_TITLEHELPER_HXX
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */