xref: /trunk/main/framework/inc/framework/titlehelper.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
121         //---------------------------------------
122         /** @see XTitle */
123         virtual void SAL_CALL setTitle(const ::rtl::OUString& sTitle);
124 
125         //---------------------------------------
126         /** @see XTitleChangeBroadcaster */
127         virtual void SAL_CALL addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener);
128 
129         //---------------------------------------
130         /** @see XTitleChangeBroadcaster */
131         virtual void SAL_CALL removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener);
132 
133         //---------------------------------------
134         /** @see XTitleChangeListener */
135         virtual void SAL_CALL titleChanged(const css::frame::TitleChangedEvent& aEvent);
136 
137         //---------------------------------------
138         /** @see css.document.XEventListener */
139         virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent);
140 
141         //---------------------------------------
142         /** @see css.lang.XEventListener */
143         virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent);
144 
145         //---------------------------------------
146         /** @see css.frame.XFrameActionListener */
147         virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent);
148 
149     //-------------------------------------------
150     // internal
151     private:
152 
153         void impl_sendTitleChangedEvent ();
154 
155         void impl_updateTitle ();
156         void impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel);
157         void impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController);
158         void impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
159 
160         void impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel);
161         void impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController);
162         void impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
163         void impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame);
164 
165         void impl_appendComponentTitle (      ::rtl::OUStringBuffer&                       sTitle    ,
166                                         const css::uno::Reference< css::uno::XInterface >& xComponent);
167         void impl_appendProductName (::rtl::OUStringBuffer& sTitle);
168         void impl_appendProductExtension (::rtl::OUStringBuffer& sTitle);
169         void impl_appendModuleName (::rtl::OUStringBuffer& sTitle);
170         void impl_appendDebugVersion (::rtl::OUStringBuffer& sTitle);
171         void impl_appendEvalVersion (::rtl::OUStringBuffer& sTitle);
172 
173         void impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle);
174         ::rtl::OUString impl_getSubTitle ();
175 
176         ::rtl::OUString impl_convertURL2Title(const ::rtl::OUString& sURL);
177 
178     //-------------------------------------------
179     // member
180     private:
181 
182         /** points to the global uno service manager. */
183         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
184 
185         /** reference to the outside UNO class using this helper. */
186         css::uno::WeakReference< css::uno::XInterface > m_xOwner;
187 
188         /** used to know how an "Untitled X" string can be created right :-) */
189         css::uno::WeakReference< css::frame::XUntitledNumbers > m_xUntitledNumbers;
190 
191         /** provides parts of our own title and we listen there for changes too. */
192         css::uno::WeakReference< css::frame::XTitle > m_xSubTitle;
193 
194         /** if it's set to sal_True the member m_sTitle has not to be changed internally.
195             It was set from outside and so outside code has to make sure it will be
196             updated.
197          */
198         ::sal_Bool m_bExternalTitle;
199 
200         /** the actual title value */
201         ::rtl::OUString m_sTitle;
202 
203         /** knows the leased number which must be used for untitled components. */
204         ::sal_Int32 m_nLeasedNumber;
205 
206         /** contains all title change listener */
207         ::cppu::OMultiTypeInterfaceContainerHelper m_aListener;
208 };
209 
210 #undef css
211 
212 } // namespace framework
213 
214 #endif // _FRAMEWORK_TITLEHELPER_HXX_
215 
216 /* vim: set noet sw=4 ts=4: */
217