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 #ifndef _SVTOOLS_UNOEVENT_HXX_ 24 #define _SVTOOLS_UNOEVENT_HXX_ 25 26 #include "svtools/svtdllapi.h" 27 #include <com/sun/star/container/XNameReplace.hpp> 28 #include <com/sun/star/lang/XServiceInfo.hpp> 29 #include <com/sun/star/uno/XInterface.hpp> 30 #include <cppuhelper/implbase2.hxx> 31 32 class SvxMacroTableDtor; 33 class SvxMacroItem; 34 class SvxMacro; 35 36 /** SvEventDescription: Description of a single event. 37 mnEvent is the id used by SvxMacroItem 38 mpEventName is the api name for this event 39 40 the last event in an array is indicated by mnEvent && mpEventName == 0 41 */ 42 struct SvEventDescription 43 { 44 sal_uInt16 mnEvent; 45 const sal_Char* mpEventName; 46 }; 47 48 /** 49 * SvBaseEventDescriptor: Abstract class that implements the basics 50 * of an XNameReplace that is delivered by the 51 * XEventsSupplier::getEvents() method. 52 * 53 * The functionality this class provides is: 54 * 1) Which elements are in the XNameReplace? 55 * 2) Mapping from Api names to item IDs. 56 * 3) conversion from SvxMacroItem to Any and vice versa. 57 * 58 * All details of how to actually get and set SvxMacroItem(s) have to 59 * be supplied by the base class. 60 */ 61 class SVT_DLLPUBLIC SvBaseEventDescriptor : public cppu::WeakImplHelper2 62 < 63 ::com::sun::star::container::XNameReplace, 64 ::com::sun::star::lang::XServiceInfo 65 > 66 { 67 const ::rtl::OUString sEventType; 68 const ::rtl::OUString sMacroName; 69 const ::rtl::OUString sLibrary; 70 const ::rtl::OUString sStarBasic; 71 const ::rtl::OUString sJavaScript; 72 const ::rtl::OUString sScript; 73 const ::rtl::OUString sNone; 74 75 76 /// name of own service 77 const ::rtl::OUString sServiceName; 78 79 protected: 80 const ::rtl::OUString sEmpty; 81 82 /// last element is 0, 0 83 const SvEventDescription* mpSupportedMacroItems; 84 sal_Int16 mnMacroItems; 85 86 public: 87 88 SvBaseEventDescriptor(const SvEventDescription* pSupportedMacroItems); 89 90 virtual ~SvBaseEventDescriptor(); 91 92 93 // XNameReplace 94 /// calls replaceByName(const sal_uInt16, const SvxMacro&) 95 virtual void SAL_CALL replaceByName( 96 const ::rtl::OUString& rName, /// API name of event 97 const ::com::sun::star::uno::Any& rElement ) /// event (PropertyValues) 98 throw( 99 ::com::sun::star::lang::IllegalArgumentException, 100 ::com::sun::star::container::NoSuchElementException, 101 ::com::sun::star::lang::WrappedTargetException, 102 ::com::sun::star::uno::RuntimeException); 103 104 // XNameAccess (via XNameReplace) 105 /// calls getByName(sal_uInt16) 106 virtual ::com::sun::star::uno::Any SAL_CALL getByName( 107 const ::rtl::OUString& rName ) /// API name of event 108 throw( 109 ::com::sun::star::container::NoSuchElementException, 110 ::com::sun::star::lang::WrappedTargetException, 111 ::com::sun::star::uno::RuntimeException); 112 113 // XNameAxcess (via XNameReplace) 114 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 115 getElementNames() 116 throw(::com::sun::star::uno::RuntimeException); 117 118 // XNameAccess (via XNameReplace) 119 virtual sal_Bool SAL_CALL hasByName( 120 const ::rtl::OUString& rName ) 121 throw(::com::sun::star::uno::RuntimeException); 122 123 // XElementAccess (via XNameReplace) 124 virtual ::com::sun::star::uno::Type SAL_CALL getElementType() 125 throw(::com::sun::star::uno::RuntimeException); 126 127 // XElementAccess (via XNameReplace) 128 virtual sal_Bool SAL_CALL hasElements() 129 throw(::com::sun::star::uno::RuntimeException); 130 131 // XServiceInfo 132 /// must be implemented in subclass 133 virtual rtl::OUString SAL_CALL getImplementationName(void) 134 throw( ::com::sun::star::uno::RuntimeException ) = 0; 135 136 // XServiceInfo 137 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) 138 throw( ::com::sun::star::uno::RuntimeException ); 139 140 // XServiceInfo 141 virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL 142 getSupportedServiceNames(void) 143 throw( ::com::sun::star::uno::RuntimeException ); 144 145 protected: 146 147 /// Must be implemented in subclass. 148 virtual void replaceByName( 149 const sal_uInt16 nEvent, /// item ID of event 150 const SvxMacro& rMacro) /// event (will be copied) 151 throw( 152 ::com::sun::star::lang::IllegalArgumentException, 153 ::com::sun::star::container::NoSuchElementException, 154 ::com::sun::star::lang::WrappedTargetException, 155 ::com::sun::star::uno::RuntimeException) = 0; 156 157 /// Must be implemented in subclass. 158 virtual void getByName( 159 SvxMacro& rMacro, 160 const sal_uInt16 nEvent ) 161 throw( 162 ::com::sun::star::container::NoSuchElementException, 163 ::com::sun::star::lang::WrappedTargetException, 164 ::com::sun::star::uno::RuntimeException) = 0; 165 166 /// convert an API event name to the event ID as used by SvxMacroItem 167 sal_uInt16 mapNameToEventID(const ::rtl::OUString& rName) const; 168 169 /// convert an event ID to an API event name 170 ::rtl::OUString mapEventIDToName(sal_uInt16 nPoolID) const; 171 172 /// get the event ID for the name; return 0 if not supported 173 sal_uInt16 getMacroID(const ::rtl::OUString& rName) const; 174 175 /// create PropertyValues and Any from macro 176 void getAnyFromMacro( 177 ::com::sun::star::uno::Any& aAny, // Any to be filled by Macro values 178 const SvxMacro& rMacro); 179 180 /// create macro from PropertyValues (in an Any) 181 void getMacroFromAny( 182 SvxMacro& aMacro, // reference to be filled by Any 183 const ::com::sun::star::uno::Any& rAny) 184 throw ( 185 ::com::sun::star::lang::IllegalArgumentException); 186 187 }; 188 189 190 191 192 /** 193 * SvEventDescriptor: Implement the XNameReplace that is delivered by 194 * the XEventsSupplier::getEvents() method. The SvEventDescriptor has 195 * to be subclassed to implement the events for a specific 196 * objects. The subclass has to 197 * 1) supply the super class constructor with a list of known events (item IDs) 198 * 2) supply the super class constructor with a reference of it's parent object 199 * (to prevent destruction) 200 * 3) implement getItem() and setItem(...) methods. 201 * 202 * If no object is available to which the SvEventDescriptor can attach itself, 203 * the class SvDetachedEventDescriptor should be used. 204 */ 205 class SVT_DLLPUBLIC SvEventDescriptor : public SvBaseEventDescriptor 206 { 207 /// keep reference to parent to prevent it from being destroyed 208 ::com::sun::star::uno::Reference< 209 ::com::sun::star::uno::XInterface > xParentRef; 210 211 public: 212 213 SvEventDescriptor(::com::sun::star::uno::XInterface& rParent, 214 const SvEventDescription* pSupportedMacroItems); 215 216 virtual ~SvEventDescriptor(); 217 218 219 protected: 220 221 222 using SvBaseEventDescriptor::replaceByName; 223 virtual void replaceByName( 224 const sal_uInt16 nEvent, /// item ID of event 225 const SvxMacro& rMacro) /// event (will be copied) 226 throw( 227 ::com::sun::star::lang::IllegalArgumentException, 228 ::com::sun::star::container::NoSuchElementException, 229 ::com::sun::star::lang::WrappedTargetException, 230 ::com::sun::star::uno::RuntimeException); 231 232 using SvBaseEventDescriptor::getByName; 233 virtual void getByName( 234 SvxMacro& rMacros, /// macro to be filled with values 235 const sal_uInt16 nEvent ) /// item ID of event 236 throw( 237 ::com::sun::star::container::NoSuchElementException, 238 ::com::sun::star::lang::WrappedTargetException, 239 ::com::sun::star::uno::RuntimeException); 240 241 242 /// Get the SvxMacroItem from the parent. 243 /// must be implemented by subclass 244 virtual const SvxMacroItem& getMacroItem() = 0; 245 246 /// Set the SvxMacroItem at the parent. 247 /// must be implemented by subclass 248 virtual void setMacroItem(const SvxMacroItem& rItem) = 0; 249 250 /// Get the SvxMacroItem Which Id needed for the current application 251 /// must be implemented by subclass 252 virtual sal_uInt16 getMacroItemWhich() const = 0; 253 }; 254 255 256 /** 257 * SvDetachedEventDescriptor: 258 */ 259 class SVT_DLLPUBLIC SvDetachedEventDescriptor : public SvBaseEventDescriptor 260 { 261 // the macros; aMacros[i] is the value for aSupportedMacroItemIDs[i] 262 SvxMacro** aMacros; 263 264 const ::rtl::OUString sImplName; 265 266 public: 267 268 SvDetachedEventDescriptor(const SvEventDescription* pSupportedMacroItems); 269 270 virtual ~SvDetachedEventDescriptor(); 271 272 //XServiceInfo 273 virtual rtl::OUString SAL_CALL getImplementationName(void) 274 throw( ::com::sun::star::uno::RuntimeException ); 275 276 protected: 277 278 sal_Int16 getIndex(const sal_uInt16 nID) const; 279 280 using SvBaseEventDescriptor::replaceByName; 281 virtual void replaceByName( 282 const sal_uInt16 nEvent, /// item ID of event 283 const SvxMacro& rMacro) /// event (will be copied) 284 throw( 285 ::com::sun::star::lang::IllegalArgumentException, 286 ::com::sun::star::container::NoSuchElementException, 287 ::com::sun::star::lang::WrappedTargetException, 288 ::com::sun::star::uno::RuntimeException); 289 290 using SvBaseEventDescriptor::getByName; 291 virtual void getByName( 292 SvxMacro& rMacro, /// macro to be filled 293 const sal_uInt16 nEvent ) /// item ID of event 294 throw( 295 ::com::sun::star::container::NoSuchElementException, 296 ::com::sun::star::lang::WrappedTargetException, 297 ::com::sun::star::uno::RuntimeException); 298 299 /// do we have an event? 300 /// return sal_True: we have a macro for the event 301 /// return sal_False: no macro; getByName() will return an empty macro 302 /// IllegalArgumentException: the event is not supported 303 using SvBaseEventDescriptor::hasByName; 304 virtual sal_Bool hasByName( 305 const sal_uInt16 nEvent ) const /// item ID of event 306 throw( 307 ::com::sun::star::lang::IllegalArgumentException); 308 309 }; 310 311 class SVT_DLLPUBLIC SvMacroTableEventDescriptor : public SvDetachedEventDescriptor 312 { 313 public: 314 315 SvMacroTableEventDescriptor(const SvEventDescription* pSupportedMacroItems); 316 SvMacroTableEventDescriptor(const SvxMacroTableDtor& aFmt, 317 const SvEventDescription* pSupportedMacroItems); 318 319 virtual ~SvMacroTableEventDescriptor(); 320 321 void copyMacrosFromTable(const SvxMacroTableDtor& aFmt); 322 void copyMacrosIntoTable(SvxMacroTableDtor& aFmt); 323 }; 324 325 #endif 326