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 _FRAMEWORK_TITLEHELPER_HXX_
21 #define _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/XEventListener.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 <boost/unordered_map.hpp>
44 #include <framework/fwedllapi.h>
50 /** @short can be used as implementation helper of interface css.frame.XTitle
54 class FWE_DLLPUBLIC TitleHelper
: private ::cppu::BaseMutex
55 , public ::cppu::WeakImplHelper5
< css::frame::XTitle
,
56 css::frame::XTitleChangeBroadcaster
,
57 css::frame::XTitleChangeListener
,
58 css::frame::XFrameActionListener
,
59 css::document::XEventListener
>
61 //-------------------------------------------
65 //---------------------------------------
66 /** @short lightweight constructor.
68 TitleHelper(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
);
70 //---------------------------------------
71 /** @short free all internaly used resources.
73 virtual ~TitleHelper();
75 //---------------------------------------
76 /** set an outside component which uses this container and must be set
77 as source of all broadcasted messages, exceptions.
79 It's holded weak only so we do not need any complex dispose sessions.
81 Note: Passing NULL as parameter will be alloed. It will reset the internal
82 member reference only.
85 the new owner of this collection.
87 void setOwner (const css::uno::Reference
< css::uno::XInterface
>& xOwner
);
89 //---------------------------------------
90 /** set an outside component which provides the righht string and number for
91 an untitled component.
93 It's holded weak only so we do not need any complex dispose sessions.
95 Note: Passing NULL as parameter will be alloed. It will reset the internal
96 member reference only.
99 the right numbered collection for this helper.
101 void connectWithUntitledNumbers (const css::uno::Reference
< css::frame::XUntitledNumbers
>& xNumbers
);
103 //---------------------------------------
105 virtual OUString SAL_CALL
getTitle()
106 throw (css::uno::RuntimeException
);
108 //---------------------------------------
110 virtual void SAL_CALL
setTitle(const OUString
& sTitle
)
111 throw (css::uno::RuntimeException
);
113 //---------------------------------------
114 /** @see XTitleChangeBroadcaster */
115 virtual void SAL_CALL
addTitleChangeListener(const css::uno::Reference
< css::frame::XTitleChangeListener
>& xListener
)
116 throw (css::uno::RuntimeException
);
118 //---------------------------------------
119 /** @see XTitleChangeBroadcaster */
120 virtual void SAL_CALL
removeTitleChangeListener(const css::uno::Reference
< css::frame::XTitleChangeListener
>& xListener
)
121 throw (css::uno::RuntimeException
);
123 //---------------------------------------
124 /** @see XTitleChangeListener */
125 virtual void SAL_CALL
titleChanged(const css::frame::TitleChangedEvent
& aEvent
)
126 throw (css::uno::RuntimeException
);
128 //---------------------------------------
129 /** @see css.document.XEventListener */
130 virtual void SAL_CALL
notifyEvent(const css::document::EventObject
& aEvent
)
131 throw (css::uno::RuntimeException
);
133 //---------------------------------------
134 /** @see css.lang.XEventListener */
135 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
)
136 throw (css::uno::RuntimeException
);
138 //---------------------------------------
139 /** @see css.frame.XFrameActionListener */
140 virtual void SAL_CALL
frameAction(const css::frame::FrameActionEvent
& aEvent
)
141 throw(css::uno::RuntimeException
);
143 //-------------------------------------------
147 void impl_sendTitleChangedEvent ();
149 void impl_updateTitle (bool init
= false);
150 void impl_updateTitleForModel (const css::uno::Reference
< css::frame::XModel
>& xModel
, bool init
);
151 void impl_updateTitleForController (const css::uno::Reference
< css::frame::XController
>& xController
, bool init
);
152 void impl_updateTitleForFrame (const css::uno::Reference
< css::frame::XFrame
>& xFrame
, bool init
);
154 void impl_startListeningForModel (const css::uno::Reference
< css::frame::XModel
>& xModel
);
155 void impl_startListeningForController (const css::uno::Reference
< css::frame::XController
>& xController
);
156 void impl_startListeningForFrame (const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
157 void impl_updateListeningForFrame (const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
159 void impl_appendComponentTitle ( OUStringBuffer
& sTitle
,
160 const css::uno::Reference
< css::uno::XInterface
>& xComponent
);
161 void impl_appendProductName (OUStringBuffer
& sTitle
);
162 void impl_appendProductExtension (OUStringBuffer
& sTitle
);
163 void impl_appendModuleName (OUStringBuffer
& sTitle
);
164 void impl_appendDebugVersion (OUStringBuffer
& sTitle
);
166 void impl_setSubTitle (const css::uno::Reference
< css::frame::XTitle
>& xSubTitle
);
168 OUString
impl_convertURL2Title(const OUString
& sURL
);
170 //-------------------------------------------
174 /** points to the global uno service manager. */
175 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
177 /** reference to the outside UNO class using this helper. */
178 css::uno::WeakReference
< css::uno::XInterface
> m_xOwner
;
180 /** used to know how an "Untitled X" string can be created right :-) */
181 css::uno::WeakReference
< css::frame::XUntitledNumbers
> m_xUntitledNumbers
;
183 /** provides parts of our own title and we listen there for changes too. */
184 css::uno::WeakReference
< css::frame::XTitle
> m_xSubTitle
;
186 /** if it's set to sal_True the member m_sTitle has not to be changed internaly.
187 It was set from outside and so outside code has to make sure it will be
190 ::sal_Bool m_bExternalTitle
;
192 /** the actual title value */
195 /** knows the leased number which must be used for untitled components. */
196 ::sal_Int32 m_nLeasedNumber
;
198 /** contains all title change listener */
199 ::cppu::OMultiTypeInterfaceContainerHelper m_aListener
;
202 } // namespace framework
204 #endif // _FRAMEWORK_TITLEHELPER_HXX_
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */