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 _LINGUISTIC_LNGPROPHELP_HXX_ 25 #define _LINGUISTIC_LNGPROPHELP_HXX_ 26 27 #include <tools/solar.h> 28 #include <uno/lbnames.h> 29 #include <cppuhelper/implbase2.hxx> 30 #include <cppuhelper/interfacecontainer.h> 31 #include <com/sun/star/beans/XPropertyChangeListener.hpp> 32 #include <com/sun/star/beans/PropertyValues.hpp> 33 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp> 34 #include <linguistic/lngdllapi.h> 35 36 namespace com { namespace sun { namespace star { namespace beans { 37 class XPropertySet; 38 }}}} 39 40 namespace com { namespace sun { namespace star { namespace linguistic2 { 41 struct LinguServiceEvent; 42 }}}} 43 44 45 namespace linguistic 46 { 47 48 /////////////////////////////////////////////////////////////////////////// 49 // PropertyChgHelper 50 // Base class for all XPropertyChangeListener members of the 51 // various lingu services. 52 53 54 // Flags for type of events allowed to be launched 55 #define AE_SPELLCHECKER 1 56 #define AE_HYPHENATOR 2 57 //#define AE_THESAURUS 4 58 59 typedef cppu::WeakImplHelper2 60 < 61 ::com::sun::star::beans::XPropertyChangeListener, 62 ::com::sun::star::linguistic2::XLinguServiceEventBroadcaster 63 > PropertyChgHelperBase; 64 65 class PropertyChgHelper : 66 public PropertyChgHelperBase 67 { 68 ::com::sun::star::uno::Sequence< ::rtl::OUString > aPropNames; 69 ::com::sun::star::uno::Reference< 70 ::com::sun::star::uno::XInterface > xMyEvtObj; 71 ::cppu::OInterfaceContainerHelper aLngSvcEvtListeners; 72 ::com::sun::star::uno::Reference< 73 ::com::sun::star::beans::XPropertySet > xPropSet; 74 75 int nEvtFlags; // flags for event types allowed to be launched 76 77 // default values 78 sal_Bool bIsIgnoreControlCharacters; 79 sal_Bool bIsUseDictionaryList; 80 81 // return values, will be set to default value or current temporary value 82 sal_Bool bResIsIgnoreControlCharacters; 83 sal_Bool bResIsUseDictionaryList; 84 85 86 // disallow use of copy-constructor and assignment-operator 87 PropertyChgHelper( const PropertyChgHelper & ); 88 PropertyChgHelper & operator = ( const PropertyChgHelper & ); 89 90 protected: 91 virtual void SetDefaultValues(); 92 virtual void GetCurrentValues(); 93 94 ::com::sun::star::uno::Sequence< ::rtl::OUString > & GetPropNames()95 GetPropNames() { return aPropNames; } 96 ::com::sun::star::uno::Reference< 97 ::com::sun::star::beans::XPropertySet > & GetPropSet()98 GetPropSet() { return xPropSet; } 99 100 void AddPropNames( const char *pNewNames[], sal_Int32 nCount ); 101 102 virtual sal_Bool propertyChange_Impl( 103 const ::com::sun::star::beans::PropertyChangeEvent& rEvt ); 104 105 public: 106 PropertyChgHelper( 107 const ::com::sun::star::uno::Reference< 108 ::com::sun::star::uno::XInterface > &rxSource, 109 ::com::sun::star::uno::Reference< 110 ::com::sun::star::beans::XPropertySet > &rxPropSet, 111 int nAllowedEvents ); 112 virtual ~PropertyChgHelper(); 113 114 virtual void SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals ); 115 116 // XEventListener 117 virtual void SAL_CALL 118 disposing( const ::com::sun::star::lang::EventObject& rSource ); 119 120 // XPropertyChangeListener 121 virtual void SAL_CALL 122 propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvt ); 123 124 // XLinguServiceEventBroadcaster 125 virtual sal_Bool SAL_CALL 126 addLinguServiceEventListener( 127 const ::com::sun::star::uno::Reference< 128 ::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener ); 129 virtual sal_Bool SAL_CALL 130 removeLinguServiceEventListener( 131 const ::com::sun::star::uno::Reference< 132 ::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener ); 133 134 // non-UNO functions 135 void AddAsPropListener(); 136 void RemoveAsPropListener(); 137 void LaunchEvent( 138 const ::com::sun::star::linguistic2::LinguServiceEvent& rEvt ); 139 140 const ::com::sun::star::uno::Sequence< ::rtl::OUString > & GetPropNames() const141 GetPropNames() const { return aPropNames; } 142 const ::com::sun::star::uno::Reference< 143 ::com::sun::star::beans::XPropertySet > & GetPropSet() const144 GetPropSet() const { return xPropSet; } 145 const ::com::sun::star::uno::Reference< 146 ::com::sun::star::uno::XInterface > & GetEvtObj() const147 GetEvtObj() const { return xMyEvtObj; } 148 IsIgnoreControlCharacters() const149 sal_Bool IsIgnoreControlCharacters() const { return bResIsIgnoreControlCharacters; } IsUseDictionaryList() const150 sal_Bool IsUseDictionaryList() const { return bResIsUseDictionaryList; } 151 }; 152 153 154 /////////////////////////////////////////////////////////////////////////// 155 class PropertyHelper_Thes : 156 public PropertyChgHelper 157 { 158 // disallow use of copy-constructor and assignment-operator 159 PropertyHelper_Thes( const PropertyHelper_Thes & ); 160 PropertyHelper_Thes & operator = ( const PropertyHelper_Thes & ); 161 162 public: 163 PropertyHelper_Thes( 164 const ::com::sun::star::uno::Reference< 165 ::com::sun::star::uno::XInterface > &rxSource, 166 ::com::sun::star::uno::Reference< 167 ::com::sun::star::beans::XPropertySet > &rxPropSet ); 168 virtual ~PropertyHelper_Thes(); 169 170 // XPropertyChangeListener 171 virtual void SAL_CALL 172 propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvt ); 173 }; 174 175 class LNG_DLLPUBLIC PropertyHelper_Thesaurus 176 { 177 PropertyHelper_Thes* pInst; 178 com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener > xPropHelper; 179 180 // disallow use of copy-constructor and assignment-operator 181 PropertyHelper_Thesaurus( const PropertyHelper_Thes & ); 182 PropertyHelper_Thesaurus & operator = ( const PropertyHelper_Thes & ); 183 184 public: 185 PropertyHelper_Thesaurus( 186 const ::com::sun::star::uno::Reference< 187 ::com::sun::star::uno::XInterface > &rxSource, 188 ::com::sun::star::uno::Reference< 189 ::com::sun::star::beans::XPropertySet > &rxPropSet ); 190 ~PropertyHelper_Thesaurus(); 191 void AddAsPropListener(); 192 void RemoveAsPropListener(); 193 void SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals ); 194 }; 195 196 197 /////////////////////////////////////////////////////////////////////////// 198 199 class PropertyHelper_Spell : 200 public PropertyChgHelper 201 { 202 // default values 203 sal_Bool bIsSpellUpperCase; 204 sal_Bool bIsSpellWithDigits; 205 206 sal_Bool bIsSpellCapitalization; 207 208 // return values, will be set to default value or current temporary value 209 sal_Int16 nResMaxNumberOfSuggestions; // special value that is not part of the property set and thus needs to be handled differently 210 sal_Bool bResIsSpellUpperCase; 211 sal_Bool bResIsSpellWithDigits; 212 sal_Bool bResIsSpellCapitalization; 213 214 215 // disallow use of copy-constructor and assignment-operator 216 PropertyHelper_Spell( const PropertyHelper_Spell & ); 217 PropertyHelper_Spell & operator = ( const PropertyHelper_Spell & ); 218 219 protected: 220 // PropertyChgHelper 221 virtual void SetDefaultValues(); 222 virtual void GetCurrentValues(); 223 virtual sal_Bool propertyChange_Impl( 224 const ::com::sun::star::beans::PropertyChangeEvent& rEvt ); 225 226 public: 227 PropertyHelper_Spell( 228 const ::com::sun::star::uno::Reference< 229 ::com::sun::star::uno::XInterface > &rxSource, 230 ::com::sun::star::uno::Reference< 231 ::com::sun::star::beans::XPropertySet > &rxPropSet ); 232 virtual ~PropertyHelper_Spell(); 233 234 virtual void SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals ); 235 236 // XPropertyChangeListener 237 virtual void SAL_CALL 238 propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvt ); 239 240 virtual sal_Int16 GetDefaultNumberOfSuggestions() const; 241 GetMaxNumberOfSuggestions() const242 sal_Int16 GetMaxNumberOfSuggestions() const { return nResMaxNumberOfSuggestions; } IsSpellUpperCase() const243 sal_Bool IsSpellUpperCase() const { return bResIsSpellUpperCase; } IsSpellWithDigits() const244 sal_Bool IsSpellWithDigits() const { return bResIsSpellWithDigits; } IsSpellCapitalization() const245 sal_Bool IsSpellCapitalization() const { return bResIsSpellCapitalization; } 246 }; 247 248 249 class LNG_DLLPUBLIC PropertyHelper_Spelling 250 { 251 PropertyHelper_Spell* pInst; 252 com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener > xPropHelper; 253 254 // disallow use of copy-constructor and assignment-operator 255 PropertyHelper_Spelling( const PropertyHelper_Spell & ); 256 PropertyHelper_Spelling & operator = ( const PropertyHelper_Spell & ); 257 258 public: 259 PropertyHelper_Spelling( 260 const ::com::sun::star::uno::Reference< 261 ::com::sun::star::uno::XInterface > &rxSource, 262 ::com::sun::star::uno::Reference< 263 ::com::sun::star::beans::XPropertySet > &rxPropSet ); 264 ~PropertyHelper_Spelling(); 265 266 void AddAsPropListener(); 267 void RemoveAsPropListener(); 268 void SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals ); 269 sal_Int16 GetMaxNumberOfSuggestions() const; 270 sal_Bool IsSpellUpperCase() const; 271 sal_Bool IsSpellWithDigits() const; 272 sal_Bool IsSpellCapitalization() const; 273 sal_Bool addLinguServiceEventListener( 274 const ::com::sun::star::uno::Reference< 275 ::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener ); 276 sal_Bool removeLinguServiceEventListener( 277 const ::com::sun::star::uno::Reference< 278 ::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener ); 279 }; 280 281 /////////////////////////////////////////////////////////////////////////// 282 283 class PropertyHelper_Hyphen : 284 public PropertyChgHelper 285 { 286 // default values 287 sal_Int16 nHyphMinLeading, 288 nHyphMinTrailing, 289 nHyphMinWordLength; 290 291 // return values, will be set to default value or current temporary value 292 sal_Int16 nResHyphMinLeading, 293 nResHyphMinTrailing, 294 nResHyphMinWordLength; 295 296 // disallow use of copy-constructor and assignment-operator 297 PropertyHelper_Hyphen( const PropertyHelper_Hyphen & ); 298 PropertyHelper_Hyphen & operator = ( const PropertyHelper_Hyphen & ); 299 300 protected: 301 // PropertyChgHelper 302 virtual void SetDefaultValues(); 303 virtual void GetCurrentValues(); 304 virtual sal_Bool propertyChange_Impl( 305 const ::com::sun::star::beans::PropertyChangeEvent& rEvt ); 306 307 public: 308 PropertyHelper_Hyphen( 309 const ::com::sun::star::uno::Reference< 310 ::com::sun::star::uno::XInterface > &rxSource, 311 ::com::sun::star::uno::Reference< 312 ::com::sun::star::beans::XPropertySet > &rxPropSet); 313 virtual ~PropertyHelper_Hyphen(); 314 315 virtual void SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals ); 316 317 // XPropertyChangeListener 318 virtual void SAL_CALL 319 propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& rEvt ); 320 GetMinLeading() const321 sal_Int16 GetMinLeading() const { return nResHyphMinLeading; } GetMinTrailing() const322 sal_Int16 GetMinTrailing() const { return nResHyphMinTrailing; } GetMinWordLength() const323 sal_Int16 GetMinWordLength() const { return nResHyphMinWordLength; } 324 }; 325 326 class LNG_DLLPUBLIC PropertyHelper_Hyphenation 327 { 328 PropertyHelper_Hyphen* pInst; 329 com::sun::star::uno::Reference< com::sun::star::beans::XPropertyChangeListener > xPropHelper; 330 331 // disallow use of copy-constructor and assignment-operator 332 PropertyHelper_Hyphenation( const PropertyHelper_Hyphen & ); 333 PropertyHelper_Hyphenation & operator = ( const PropertyHelper_Hyphen & ); 334 335 public: 336 PropertyHelper_Hyphenation( 337 const ::com::sun::star::uno::Reference< 338 ::com::sun::star::uno::XInterface > &rxSource, 339 ::com::sun::star::uno::Reference< 340 ::com::sun::star::beans::XPropertySet > &rxPropSet); 341 ~PropertyHelper_Hyphenation(); 342 343 void AddAsPropListener(); 344 void RemoveAsPropListener(); 345 void SetTmpPropVals( const com::sun::star::beans::PropertyValues &rPropVals ); 346 sal_Int16 GetMinLeading() const; 347 sal_Int16 GetMinTrailing() const; 348 sal_Int16 GetMinWordLength() const; 349 sal_Bool addLinguServiceEventListener( 350 const ::com::sun::star::uno::Reference< 351 ::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener ); 352 sal_Bool removeLinguServiceEventListener( 353 const ::com::sun::star::uno::Reference< 354 ::com::sun::star::linguistic2::XLinguServiceEventListener >& rxListener ); 355 }; 356 357 /////////////////////////////////////////////////////////////////////////// 358 359 } // namespace linguistic 360 361 #endif 362