1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 #ifndef _LINGU2_HYPHENIMP_HXX_
30 #define _LINGU2_HYPHENIMP_HXX_
31 
32 #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
33 #include <cppuhelper/implbase1.hxx>	// helper for implementations
34 #include <cppuhelper/implbase6.hxx>	// helper for implementations
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <com/sun/star/lang/XServiceDisplayName.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/beans/PropertyValues.hpp>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/linguistic2/XHyphenator.hpp>
42 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
43 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
44 #include <tools/table.hxx>
45 
46 #include <unotools/charclass.hxx>
47 
48 #include <linguistic/misc.hxx>
49 #include <linguistic/lngprophelp.hxx>
50 
51 #include <lingutil.hxx>
52 #include <stdio.h>
53 
54 using namespace ::rtl;
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::beans;
57 using namespace ::com::sun::star::lang;
58 using namespace ::com::sun::star::linguistic2;
59 
60 
61 ///////////////////////////////////////////////////////////////////////////
62 
63 
64 struct HDInfo {
65   HyphenDict *     aPtr;
66   OUString         aName;
67   Locale           aLoc;
68   rtl_TextEncoding eEnc;
69   CharClass *      apCC;
70 };
71 
72 
73 
74 class Hyphenator :
75 	public cppu::WeakImplHelper6
76 	<
77 		XHyphenator,
78 		XLinguServiceEventBroadcaster,
79 		XInitialization,
80 		XComponent,
81 		XServiceInfo,
82 		XServiceDisplayName
83 	>
84 {
85 	Sequence< Locale >						aSuppLocales;
86     HDInfo * aDicts;
87     sal_Int32 numdict;
88 
89 	::cppu::OInterfaceContainerHelper		aEvtListeners;
90 	Reference< XPropertyChangeListener >	xPropHelper;
91     Reference< XMultiServiceFactory >       rSMgr;
92     linguistic::PropertyHelper_Hyphen *     pPropHelper;
93 	sal_Bool									bDisposing;
94 
95 	// disallow copy-constructor and assignment-operator for now
96 	Hyphenator(const Hyphenator &);
97 	Hyphenator & operator = (const Hyphenator &);
98 
99     linguistic::PropertyHelper_Hyphen & GetPropHelper_Impl();
100     linguistic::PropertyHelper_Hyphen & GetPropHelper()
101 	{
102 		return pPropHelper ? *pPropHelper : GetPropHelper_Impl();
103 	}
104 
105 public:
106 	Hyphenator();
107 
108 	virtual ~Hyphenator();
109 
110 	// XSupportedLocales (for XHyphenator)
111     virtual Sequence< Locale > SAL_CALL getLocales() throw(RuntimeException);
112     virtual sal_Bool SAL_CALL hasLocale( const Locale& rLocale ) throw(RuntimeException);
113 
114 	// XHyphenator
115     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL hyphenate( const ::rtl::OUString& aWord, const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nMaxLeading, const ::com::sun::star::beans::PropertyValues& aProperties ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
116     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XHyphenatedWord > SAL_CALL queryAlternativeSpelling( const ::rtl::OUString& aWord, const ::com::sun::star::lang::Locale& aLocale, sal_Int16 nIndex, const ::com::sun::star::beans::PropertyValues& aProperties ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
117     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XPossibleHyphens > SAL_CALL createPossibleHyphens( const ::rtl::OUString& aWord, const ::com::sun::star::lang::Locale& aLocale, const ::com::sun::star::beans::PropertyValues& aProperties ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
118 
119     // XLinguServiceEventBroadcaster
120     virtual sal_Bool SAL_CALL addLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
121     virtual sal_Bool SAL_CALL removeLinguServiceEventListener( const Reference< XLinguServiceEventListener >& rxLstnr ) throw(RuntimeException);
122 
123 	// XServiceDisplayName
124     virtual OUString SAL_CALL getServiceDisplayName( const Locale& rLocale ) throw(RuntimeException);
125 
126 	// XInitialization
127     virtual void SAL_CALL initialize( const Sequence< Any >& rArguments ) throw(Exception, RuntimeException);
128 
129 	// XComponent
130     virtual void SAL_CALL dispose() throw(RuntimeException);
131     virtual void SAL_CALL addEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
132     virtual void SAL_CALL removeEventListener( const Reference< XEventListener >& rxListener ) throw(RuntimeException);
133 
134 	// XServiceInfo
135     virtual OUString SAL_CALL getImplementationName() throw(RuntimeException);
136     virtual sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) throw(RuntimeException);
137     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
138 
139 
140     static inline OUString  getImplementationName_Static() throw();
141     static Sequence< OUString > getSupportedServiceNames_Static() throw();
142 
143 
144 private:
145         sal_uInt16 SAL_CALL capitalType(const OUString&, CharClass *);
146         OUString SAL_CALL makeLowerCase(const OUString&, CharClass *);
147         OUString SAL_CALL makeUpperCase(const OUString&, CharClass *);
148         OUString SAL_CALL makeInitCap(const OUString&, CharClass *);
149 };
150 
151 inline OUString Hyphenator::getImplementationName_Static() throw()
152 {
153 	return A2OU( "org.openoffice.lingu.LibHnjHyphenator" );
154 }
155 
156 
157 ///////////////////////////////////////////////////////////////////////////
158 
159 #endif
160 
161