xref: /trunk/main/framework/inc/framework/titlehelper.hxx (revision 537d918930a77db9c28916ebc25c79ea73c289a1)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef _FRAMEWORK_TITLEHELPER_HXX_
23 #define _FRAMEWORK_TITLEHELPER_HXX_
24 
25 //_______________________________________________
26 // includes
27 
28 #include <com/sun/star/uno/Reference.hxx>
29 #include <com/sun/star/uno/XInterface.hpp>
30 #include <com/sun/star/lang/IllegalArgumentException.hpp>
31 #include <com/sun/star/frame/XUntitledNumbers.hpp>
32 #include <com/sun/star/frame/XTitle.hpp>
33 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp>
34 #include <com/sun/star/frame/XModel.hpp>
35 #include <com/sun/star/frame/XController.hpp>
36 #include <com/sun/star/frame/XFrame.hpp>
37 #include <com/sun/star/frame/XFrameActionListener.hpp>
38 #include <com/sun/star/document/XEventListener.hpp>
39 
40 #include <cppuhelper/basemutex.hxx>
41 #include <cppuhelper/weakref.hxx>
42 #include <cppuhelper/implbase5.hxx>
43 #include <cppuhelper/interfacecontainer.hxx>
44 
45 #include <rtl/ustrbuf.hxx>
46 
47 #include <hash_map>
48 #include <framework/fwedllapi.h>
49 
50 //_______________________________________________
51 // namespace
52 
53 namespace framework{
54 
55 #ifdef css
56     #error "Ambigious namespace definition of css."
57 #else
58     #define css ::com::sun::star
59 #endif
60 
61 //_______________________________________________
62 // definitions
63 
64 /** @short  can be used as implementation helper of interface css.frame.XTitle
65 
66     @threadsafe
67  */
68 class FWE_DLLPUBLIC TitleHelper : private ::cppu::BaseMutex
69                   , public  ::cppu::WeakImplHelper5< css::frame::XTitle                 ,
70                                                      css::frame::XTitleChangeBroadcaster,
71                                                      css::frame::XTitleChangeListener   ,
72                                                      css::frame::XFrameActionListener   ,
73                                                      css::document::XEventListener      >
74 {
75     //-------------------------------------------
76     // interface
77     public:
78 
79         //---------------------------------------
80         /** @short  lightweight constructor.
81          */
82         TitleHelper(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
83 
84         //---------------------------------------
85         /** @short  free all internally used resources.
86          */
87         virtual ~TitleHelper();
88 
89         //---------------------------------------
90         /** set an outside component which uses this container and must be set
91             as source of all broadcasted messages, exceptions.
92 
93             It's held weak only so we do not need any complex dispose sessions.
94 
95             Note: Passing NULL as parameter will be allowed. It will reset the internal
96             member reference only.
97 
98             @param  xOwner
99                     the new owner of this collection.
100          */
101         void setOwner (const css::uno::Reference< css::uno::XInterface >& xOwner);
102 
103         //---------------------------------------
104         /** set an outside component which provides the right string and number for
105             an untitled component.
106 
107             It's held weak only so we do not need any complex dispose sessions.
108 
109             Note: Passing NULL as parameter will be allowed. It will reset the internal
110             member reference only.
111 
112             @param  xNumbers
113                     the right numbered collection for this helper.
114          */
115         void connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers);
116 
117         //---------------------------------------
118         /** @see XTitle */
119         virtual ::rtl::OUString SAL_CALL getTitle()
120             throw (css::uno::RuntimeException);
121 
122         //---------------------------------------
123         /** @see XTitle */
124         virtual void SAL_CALL setTitle(const ::rtl::OUString& sTitle)
125             throw (css::uno::RuntimeException);
126 
127         //---------------------------------------
128         /** @see XTitleChangeBroadcaster */
129         virtual void SAL_CALL addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
130             throw (css::uno::RuntimeException);
131 
132         //---------------------------------------
133         /** @see XTitleChangeBroadcaster */
134         virtual void SAL_CALL removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
135             throw (css::uno::RuntimeException);
136 
137         //---------------------------------------
138         /** @see XTitleChangeListener */
139         virtual void SAL_CALL titleChanged(const css::frame::TitleChangedEvent& aEvent)
140             throw (css::uno::RuntimeException);
141 
142         //---------------------------------------
143         /** @see css.document.XEventListener */
144         virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent)
145             throw (css::uno::RuntimeException);
146 
147         //---------------------------------------
148         /** @see css.lang.XEventListener */
149         virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
150             throw (css::uno::RuntimeException);
151 
152         //---------------------------------------
153         /** @see css.frame.XFrameActionListener */
154         virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent)
155             throw(css::uno::RuntimeException);
156 
157     //-------------------------------------------
158     // internal
159     private:
160 
161         void impl_sendTitleChangedEvent ();
162 
163         void impl_updateTitle ();
164         void impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel);
165         void impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController);
166         void impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
167 
168         void impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel);
169         void impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController);
170         void impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
171         void impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
172 
173         void impl_appendComponentTitle (      ::rtl::OUStringBuffer&                       sTitle    ,
174                                         const css::uno::Reference< css::uno::XInterface >& xComponent);
175         void impl_appendProductName (::rtl::OUStringBuffer& sTitle);
176         void impl_appendProductExtension (::rtl::OUStringBuffer& sTitle);
177         void impl_appendModuleName (::rtl::OUStringBuffer& sTitle);
178         void impl_appendDebugVersion (::rtl::OUStringBuffer& sTitle);
179         void impl_appendEvalVersion (::rtl::OUStringBuffer& sTitle);
180 
181         void impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle);
182         ::rtl::OUString impl_getSubTitle ();
183 
184         ::rtl::OUString impl_convertURL2Title(const ::rtl::OUString& sURL);
185 
186     //-------------------------------------------
187     // member
188     private:
189 
190         /** points to the global uno service manager. */
191         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
192 
193         /** reference to the outside UNO class using this helper. */
194         css::uno::WeakReference< css::uno::XInterface > m_xOwner;
195 
196         /** used to know how an "Untitled X" string can be created right :-) */
197         css::uno::WeakReference< css::frame::XUntitledNumbers > m_xUntitledNumbers;
198 
199         /** provides parts of our own title and we listen there for changes too. */
200         css::uno::WeakReference< css::frame::XTitle > m_xSubTitle;
201 
202         /** if it's set to sal_True the member m_sTitle has not to be changed internally.
203             It was set from outside and so outside code has to make sure it will be
204             updated.
205          */
206         ::sal_Bool m_bExternalTitle;
207 
208         /** the actual title value */
209         ::rtl::OUString m_sTitle;
210 
211         /** knows the leased number which must be used for untitled components. */
212         ::sal_Int32 m_nLeasedNumber;
213 
214         /** contains all title change listener */
215         ::cppu::OMultiTypeInterfaceContainerHelper m_aListener;
216 };
217 
218 #undef css
219 
220 } // namespace framework
221 
222 #endif // _FRAMEWORK_TITLEHELPER_HXX_
223 
224 /* vim: set noet sw=4 ts=4: */
225