merge the formfield patch from ooo-build
[ooovba.git] / framework / inc / helper / titlehelper.hxx
blob7c45980c62eb19f51c2da1e9a395d4872369365b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: titlehelper.hxx,v $
11 * $Revision: 1.3 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef _FRAMEWORK_TITLEHELPER_HXX_
33 #define _FRAMEWORK_TITLEHELPER_HXX_
35 //_______________________________________________
36 // includes
38 #include <com/sun/star/uno/Reference.hxx>
39 #include <com/sun/star/uno/XInterface.hpp>
40 #include <com/sun/star/lang/IllegalArgumentException.hpp>
41 #include <com/sun/star/frame/XUntitledNumbers.hpp>
42 #include <com/sun/star/frame/XTitle.hpp>
43 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp>
44 #include <com/sun/star/frame/XModel.hpp>
45 #include <com/sun/star/frame/XController.hpp>
46 #include <com/sun/star/frame/XFrame.hpp>
47 #include <com/sun/star/frame/XFrameActionListener.hpp>
48 #include <com/sun/star/document/XEventListener.hpp>
50 #include <cppuhelper/basemutex.hxx>
51 #include <cppuhelper/weakref.hxx>
52 #include <cppuhelper/implbase5.hxx>
53 #include <cppuhelper/interfacecontainer.hxx>
55 #include <rtl/ustrbuf.hxx>
57 #include <hash_map>
59 //_______________________________________________
60 // namespace
62 namespace framework{
64 #ifdef css
65 #error "Ambigious namespace definition of css."
66 #else
67 #define css ::com::sun::star
68 #endif
70 //_______________________________________________
71 // definitions
73 /** @short can be used as implementation helper of interface css.frame.XTitle
75 @threadsafe
77 class TitleHelper : private ::cppu::BaseMutex
78 , public ::cppu::WeakImplHelper5< css::frame::XTitle ,
79 css::frame::XTitleChangeBroadcaster,
80 css::frame::XTitleChangeListener ,
81 css::frame::XFrameActionListener ,
82 css::document::XEventListener >
84 //-------------------------------------------
85 // interface
86 public:
88 //---------------------------------------
89 /** @short lightweight constructor.
90 */
91 TitleHelper(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
93 //---------------------------------------
94 /** @short free all internaly used resources.
95 */
96 virtual ~TitleHelper();
98 //---------------------------------------
99 /** set an outside component which uses this container and must be set
100 as source of all broadcasted messages, exceptions.
102 It's holded weak only so we do not need any complex dispose sessions.
104 Note: Passing NULL as parameter will be alloed. It will reset the internal
105 member reference only.
107 @param xOwner
108 the new owner of this collection.
110 void setOwner (const css::uno::Reference< css::uno::XInterface >& xOwner);
112 //---------------------------------------
113 /** set an outside component which provides the righht string and number for
114 an untitled component.
116 It's holded weak only so we do not need any complex dispose sessions.
118 Note: Passing NULL as parameter will be alloed. It will reset the internal
119 member reference only.
121 @param xNumbers
122 the right numbered collection for this helper.
124 void connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers);
126 //---------------------------------------
127 /** @see XTitle */
128 virtual ::rtl::OUString SAL_CALL getTitle()
129 throw (css::uno::RuntimeException);
131 //---------------------------------------
132 /** @see XTitle */
133 virtual void SAL_CALL setTitle(const ::rtl::OUString& sTitle)
134 throw (css::uno::RuntimeException);
136 //---------------------------------------
137 /** @see XTitleChangeBroadcaster */
138 virtual void SAL_CALL addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
139 throw (css::uno::RuntimeException);
141 //---------------------------------------
142 /** @see XTitleChangeBroadcaster */
143 virtual void SAL_CALL removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
144 throw (css::uno::RuntimeException);
146 //---------------------------------------
147 /** @see XTitleChangeListener */
148 virtual void SAL_CALL titleChanged(const css::frame::TitleChangedEvent& aEvent)
149 throw (css::uno::RuntimeException);
151 //---------------------------------------
152 /** @see css.document.XEventListener */
153 virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent)
154 throw (css::uno::RuntimeException);
156 //---------------------------------------
157 /** @see css.lang.XEventListener */
158 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
159 throw (css::uno::RuntimeException);
161 //---------------------------------------
162 /** @see css.frame.XFrameActionListener */
163 virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent)
164 throw(css::uno::RuntimeException);
166 //-------------------------------------------
167 // internal
168 private:
170 void impl_sendTitleChangedEvent ();
172 void impl_updateTitle ();
173 void impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel);
174 void impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController);
175 void impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
177 void impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel);
178 void impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController);
179 void impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
180 void impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
182 void impl_appendComponentTitle ( ::rtl::OUStringBuffer& sTitle ,
183 const css::uno::Reference< css::uno::XInterface >& xComponent);
184 void impl_appendProductName (::rtl::OUStringBuffer& sTitle);
185 void impl_appendProductExtension (::rtl::OUStringBuffer& sTitle);
186 void impl_appendModuleName (::rtl::OUStringBuffer& sTitle);
187 void impl_appendDebugVersion (::rtl::OUStringBuffer& sTitle);
188 void impl_appendEvalVersion (::rtl::OUStringBuffer& sTitle);
190 void impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle);
191 ::rtl::OUString impl_getSubTitle ();
193 ::rtl::OUString impl_convertURL2Title(const ::rtl::OUString& sURL);
195 //-------------------------------------------
196 // member
197 private:
199 /** points to the global uno service manager. */
200 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
202 /** reference to the outside UNO class using this helper. */
203 css::uno::WeakReference< css::uno::XInterface > m_xOwner;
205 /** used to know how an "Untitled X" string can be created right :-) */
206 css::uno::WeakReference< css::frame::XUntitledNumbers > m_xUntitledNumbers;
208 /** provides parts of our own title and we listen there for changes too. */
209 css::uno::WeakReference< css::frame::XTitle > m_xSubTitle;
211 /** if it's set to TRUE the member m_sTitle has not to be changed internaly.
212 It was set from outside and so outside code has to make sure it will be
213 updated.
215 ::sal_Bool m_bExternalTitle;
217 /** the actual title value */
218 ::rtl::OUString m_sTitle;
220 /** knows the leased number which must be used for untitled components. */
221 ::sal_Int32 m_nLeasedNumber;
223 /** contains all title change listener */
224 ::cppu::OMultiTypeInterfaceContainerHelper m_aListener;
227 #undef css
229 } // namespace framework
231 #endif // _FRAMEWORK_TITLEHELPER_HXX_