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 23 24 #ifndef _FRAMEWORK_TITLEHELPER_HXX_ 25 #define _FRAMEWORK_TITLEHELPER_HXX_ 26 27 //_______________________________________________ 28 // includes 29 30 #include <com/sun/star/uno/Reference.hxx> 31 #include <com/sun/star/uno/XInterface.hpp> 32 #include <com/sun/star/lang/IllegalArgumentException.hpp> 33 #include <com/sun/star/frame/XUntitledNumbers.hpp> 34 #include <com/sun/star/frame/XTitle.hpp> 35 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp> 36 #include <com/sun/star/frame/XModel.hpp> 37 #include <com/sun/star/frame/XController.hpp> 38 #include <com/sun/star/frame/XFrame.hpp> 39 #include <com/sun/star/frame/XFrameActionListener.hpp> 40 #include <com/sun/star/document/XEventListener.hpp> 41 42 #include <cppuhelper/basemutex.hxx> 43 #include <cppuhelper/weakref.hxx> 44 #include <cppuhelper/implbase5.hxx> 45 #include <cppuhelper/interfacecontainer.hxx> 46 47 #include <rtl/ustrbuf.hxx> 48 49 #include <hash_map> 50 #include <framework/fwedllapi.h> 51 52 //_______________________________________________ 53 // namespace 54 55 namespace framework{ 56 57 #ifdef css 58 #error "Ambigious namespace definition of css." 59 #else 60 #define css ::com::sun::star 61 #endif 62 63 //_______________________________________________ 64 // definitions 65 66 /** @short can be used as implementation helper of interface css.frame.XTitle 67 68 @threadsafe 69 */ 70 class FWE_DLLPUBLIC TitleHelper : private ::cppu::BaseMutex 71 , public ::cppu::WeakImplHelper5< css::frame::XTitle , 72 css::frame::XTitleChangeBroadcaster, 73 css::frame::XTitleChangeListener , 74 css::frame::XFrameActionListener , 75 css::document::XEventListener > 76 { 77 //------------------------------------------- 78 // interface 79 public: 80 81 //--------------------------------------- 82 /** @short lightweight constructor. 83 */ 84 TitleHelper(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); 85 86 //--------------------------------------- 87 /** @short free all internally used resources. 88 */ 89 virtual ~TitleHelper(); 90 91 //--------------------------------------- 92 /** set an outside component which uses this container and must be set 93 as source of all broadcasted messages, exceptions. 94 95 It's holded weak only so we do not need any complex dispose sessions. 96 97 Note: Passing NULL as parameter will be alloed. It will reset the internal 98 member reference only. 99 100 @param xOwner 101 the new owner of this collection. 102 */ 103 void setOwner (const css::uno::Reference< css::uno::XInterface >& xOwner); 104 105 //--------------------------------------- 106 /** set an outside component which provides the righht string and number for 107 an untitled component. 108 109 It's holded weak only so we do not need any complex dispose sessions. 110 111 Note: Passing NULL as parameter will be alloed. It will reset the internal 112 member reference only. 113 114 @param xNumbers 115 the right numbered collection for this helper. 116 */ 117 void connectWithUntitledNumbers (const css::uno::Reference< css::frame::XUntitledNumbers >& xNumbers); 118 119 //--------------------------------------- 120 /** @see XTitle */ 121 virtual ::rtl::OUString SAL_CALL getTitle() 122 throw (css::uno::RuntimeException); 123 124 //--------------------------------------- 125 /** @see XTitle */ 126 virtual void SAL_CALL setTitle(const ::rtl::OUString& sTitle) 127 throw (css::uno::RuntimeException); 128 129 //--------------------------------------- 130 /** @see XTitleChangeBroadcaster */ 131 virtual void SAL_CALL addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener) 132 throw (css::uno::RuntimeException); 133 134 //--------------------------------------- 135 /** @see XTitleChangeBroadcaster */ 136 virtual void SAL_CALL removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener) 137 throw (css::uno::RuntimeException); 138 139 //--------------------------------------- 140 /** @see XTitleChangeListener */ 141 virtual void SAL_CALL titleChanged(const css::frame::TitleChangedEvent& aEvent) 142 throw (css::uno::RuntimeException); 143 144 //--------------------------------------- 145 /** @see css.document.XEventListener */ 146 virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent) 147 throw (css::uno::RuntimeException); 148 149 //--------------------------------------- 150 /** @see css.lang.XEventListener */ 151 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) 152 throw (css::uno::RuntimeException); 153 154 //--------------------------------------- 155 /** @see css.frame.XFrameActionListener */ 156 virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent) 157 throw(css::uno::RuntimeException); 158 159 //------------------------------------------- 160 // internal 161 private: 162 163 void impl_sendTitleChangedEvent (); 164 165 void impl_updateTitle (); 166 void impl_updateTitleForModel (const css::uno::Reference< css::frame::XModel >& xModel); 167 void impl_updateTitleForController (const css::uno::Reference< css::frame::XController >& xController); 168 void impl_updateTitleForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame); 169 170 void impl_startListeningForModel (const css::uno::Reference< css::frame::XModel >& xModel); 171 void impl_startListeningForController (const css::uno::Reference< css::frame::XController >& xController); 172 void impl_startListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame); 173 void impl_updateListeningForFrame (const css::uno::Reference< css::frame::XFrame >& xFrame); 174 175 void impl_appendComponentTitle ( ::rtl::OUStringBuffer& sTitle , 176 const css::uno::Reference< css::uno::XInterface >& xComponent); 177 void impl_appendProductName (::rtl::OUStringBuffer& sTitle); 178 void impl_appendProductExtension (::rtl::OUStringBuffer& sTitle); 179 void impl_appendModuleName (::rtl::OUStringBuffer& sTitle); 180 void impl_appendDebugVersion (::rtl::OUStringBuffer& sTitle); 181 void impl_appendEvalVersion (::rtl::OUStringBuffer& sTitle); 182 183 void impl_setSubTitle (const css::uno::Reference< css::frame::XTitle >& xSubTitle); 184 ::rtl::OUString impl_getSubTitle (); 185 186 ::rtl::OUString impl_convertURL2Title(const ::rtl::OUString& sURL); 187 188 //------------------------------------------- 189 // member 190 private: 191 192 /** points to the global uno service manager. */ 193 css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 194 195 /** reference to the outside UNO class using this helper. */ 196 css::uno::WeakReference< css::uno::XInterface > m_xOwner; 197 198 /** used to know how an "Untitled X" string can be created right :-) */ 199 css::uno::WeakReference< css::frame::XUntitledNumbers > m_xUntitledNumbers; 200 201 /** provides parts of our own title and we listen there for changes too. */ 202 css::uno::WeakReference< css::frame::XTitle > m_xSubTitle; 203 204 /** if it's set to sal_True the member m_sTitle has not to be changed internally. 205 It was set from outside and so outside code has to make sure it will be 206 updated. 207 */ 208 ::sal_Bool m_bExternalTitle; 209 210 /** the actual title value */ 211 ::rtl::OUString m_sTitle; 212 213 /** knows the leased number which must be used for untitled components. */ 214 ::sal_Int32 m_nLeasedNumber; 215 216 /** contains all title change listener */ 217 ::cppu::OMultiTypeInterfaceContainerHelper m_aListener; 218 }; 219 220 #undef css 221 222 } // namespace framework 223 224 #endif // _FRAMEWORK_TITLEHELPER_HXX_ 225