xref: /AOO41X/main/linguistic/source/dlistimp.hxx (revision 63ce064adffbff2897afdaa4d6906d07224572bb)
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_DLISTIMP_HXX_
25 #define _LINGUISTIC_DLISTIMP_HXX_
26 
27 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
28 #include <com/sun/star/lang/XComponent.hpp>
29 #include <com/sun/star/lang/XServiceInfo.hpp>
30 
31 #include <uno/lbnames.h>            // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
32 #include <cppuhelper/implbase1.hxx> // helper for implementations
33 #include <cppuhelper/implbase3.hxx> // helper for implementations
34 #include <cppuhelper/interfacecontainer.h>
35 #include <tools/debug.hxx>
36 
37 #include <vector>
38 #include <memory>
39 
40 #include "linguistic/misc.hxx"
41 #include "lngopt.hxx"
42 
43 class DicEvtListenerHelper;
44 
45 ///////////////////////////////////////////////////////////////////////////
46 
47 class DicList :
48     public cppu::WeakImplHelper3
49     <
50         ::com::sun::star::linguistic2::XSearchableDictionaryList,
51         ::com::sun::star::lang::XComponent,
52         ::com::sun::star::lang::XServiceInfo
53     >
54 {
55     class MyAppExitListener : public linguistic::AppExitListener
56     {
57         DicList & rMyDicList;
58 
59     public:
MyAppExitListener(DicList & rDicList)60         MyAppExitListener( DicList &rDicList ) : rMyDicList( rDicList ) {}
61         virtual void    AtExit();
62     };
63 
64     LinguOptions    aOpt;
65 
66     ::cppu::OInterfaceContainerHelper       aEvtListeners;
67 
68     typedef std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionary > >   DictionaryVec_t;
69     DictionaryVec_t                          aDicList;
70 
71     ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::
72                 XDictionaryEventListener >  xDicEvtLstnrHelper;
73     DicEvtListenerHelper                    *pDicEvtLstnrHelper;
74 
75     ::com::sun::star::uno::Reference< ::com::sun::star::frame::
76                 XTerminateListener >        xExitListener;
77     MyAppExitListener                       *pExitListener;
78 
79     sal_Bool    bDisposing;
80     sal_Bool    bInCreation;
81 
82     // disallow copy-constructor and assignment-operator for now
83     DicList( const DicList & );
84     DicList & operator = (const DicList &);
85 
86     void                _CreateDicList();
GetOrCreateDicList()87     DictionaryVec_t &   GetOrCreateDicList()
88                         {
89                             if (!bInCreation && aDicList.size() == 0)
90                                 _CreateDicList();
91                             return aDicList;
92                         }
93 
94     void            LaunchEvent(sal_Int16 nEvent, com::sun::star::uno::Sequence<
95                             ::com::sun::star::linguistic2::XDictionary > xDic);
96     void            SearchForDictionaries( DictionaryVec_t &rDicList,
97                                             const String &rDicDir, sal_Bool bIsWritePath );
98     sal_Int32           GetDicPos(const com::sun::star::uno::Reference<
99                             ::com::sun::star::linguistic2::XDictionary > &xDic);
100 
101 public:
102     DicList();
103     virtual ~DicList();
104 
105     // XDictionaryList
106     virtual ::sal_Int16 SAL_CALL getCount(  ) throw (::com::sun::star::uno::RuntimeException);
107     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionary > > SAL_CALL getDictionaries(  ) throw (::com::sun::star::uno::RuntimeException);
108     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionary > SAL_CALL getDictionaryByName( const ::rtl::OUString& aDictionaryName ) throw (::com::sun::star::uno::RuntimeException);
109     virtual ::sal_Bool SAL_CALL addDictionary( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionary >& xDictionary ) throw (::com::sun::star::uno::RuntimeException);
110     virtual ::sal_Bool SAL_CALL removeDictionary( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionary >& xDictionary ) throw (::com::sun::star::uno::RuntimeException);
111     virtual ::sal_Bool SAL_CALL addDictionaryListEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionaryListEventListener >& xListener, ::sal_Bool bReceiveVerbose ) throw (::com::sun::star::uno::RuntimeException);
112     virtual ::sal_Bool SAL_CALL removeDictionaryListEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionaryListEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
113     virtual ::sal_Int16 SAL_CALL beginCollectEvents(  ) throw (::com::sun::star::uno::RuntimeException);
114     virtual ::sal_Int16 SAL_CALL endCollectEvents(  ) throw (::com::sun::star::uno::RuntimeException);
115     virtual ::sal_Int16 SAL_CALL flushEvents(  ) throw (::com::sun::star::uno::RuntimeException);
116     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionary > SAL_CALL createDictionary( const ::rtl::OUString& aName, const ::com::sun::star::lang::Locale& aLocale, ::com::sun::star::linguistic2::DictionaryType eDicType, const ::rtl::OUString& aURL ) throw (::com::sun::star::uno::RuntimeException);
117 
118     // XSearchableDictionaryList
119     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XDictionaryEntry > SAL_CALL queryDictionaryEntry( const ::rtl::OUString& aWord, const ::com::sun::star::lang::Locale& aLocale, sal_Bool bSearchPosDics, sal_Bool bSpellEntry ) throw(::com::sun::star::uno::RuntimeException);
120 
121     // XComponent
122     virtual void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException);
123     virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
124     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException);
125 
126     // XServiceInfo
127     virtual ::rtl::OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
128     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
129     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
130 
131 
132     static inline ::rtl::OUString getImplementationName_Static() throw();
133     static com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static() throw();
134 
135     // non UNO-specific
136     void    SaveDics();
137 };
138 
getImplementationName_Static()139 inline ::rtl::OUString DicList::getImplementationName_Static() throw()
140 {
141     return A2OU( "com.sun.star.lingu2.DicList" );
142 }
143 
144 ///////////////////////////////////////////////////////////////////////////
145 
146 #endif
147 
148