xref: /AOO41X/main/sw/inc/breakit.hxx (revision 1d2dbeb0b7301723c6d13094e87a8714ef81a328)
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 _BREAKIT_HXX
25 #define _BREAKIT_HXX
26 
27 #include <tools/solar.h>
28 #include <i18npool/lang.h>
29 #include <com/sun/star/uno/Reference.h>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/i18n/XBreakIterator.hpp>
32 #include <com/sun/star/i18n/XScriptTypeDetector.hpp>
33 #include <com/sun/star/i18n/ForbiddenCharacters.hdl>
34 #include <swdllapi.h>
35 
36 class String;
37 
38 /*************************************************************************
39  *                      class SwBreakIt
40  *************************************************************************/
41 
42 
43 class SW_DLLPUBLIC SwBreakIt
44 {
45     com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > m_xMSF;
46     mutable com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > xBreak;
47     com::sun::star::uno::Reference< com::sun::star::i18n::XScriptTypeDetector > xCTLDetect;
48 
49 
50     com::sun::star::lang::Locale * m_pLocale;
51     com::sun::star::i18n::ForbiddenCharacters * m_pForbidden;
52 
53     LanguageType aLast;          // language of the current locale
54     LanguageType aForbiddenLang; // language of the current forbiddenChar struct
55 
56     void _GetLocale( const LanguageType aLang );
57     void _GetForbidden( const LanguageType  aLang );
58 
59     void createBreakIterator() const;
60     void createScriptTypeDetector();
61 
62     // forbidden and not implemented.
63     SwBreakIt();
64     SwBreakIt( const SwBreakIt &);
65     SwBreakIt & operator= ( const SwBreakIt &);
66 
67     // private (see @ _Create, _Delete).
68     explicit SwBreakIt(
69         const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rxMSF);
70     ~SwBreakIt();
71 
72 public:
73     // private (see @ source/core/bastyp/init.cxx).
74     static void _Create(
75         const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > & rxMSF);
76     static void _Delete();
77 
78 public:
79     static SwBreakIt * Get();
80 
GetBreakIter()81     com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > GetBreakIter()
82     {
83         createBreakIterator();
84         return xBreak;
85     }
86 
GetScriptTypeDetector()87     com::sun::star::uno::Reference< com::sun::star::i18n::XScriptTypeDetector > GetScriptTypeDetector()
88     {
89         createScriptTypeDetector();
90         return xCTLDetect;
91     }
92 
GetLocale(const LanguageType aLang)93     const com::sun::star::lang::Locale& GetLocale( const LanguageType aLang )
94     {
95         if( !m_pLocale || aLast != aLang )
96             _GetLocale( aLang );
97         return *m_pLocale;
98     }
99 
GetForbidden(const LanguageType aLang)100     const com::sun::star::i18n::ForbiddenCharacters& GetForbidden( const LanguageType aLang )
101     {
102         if( !m_pForbidden || aForbiddenLang != aLang )
103             _GetForbidden( aLang );
104         return *m_pForbidden;
105     }
106 
107     sal_uInt16 GetRealScriptOfText( const String& rTxt, xub_StrLen nPos ) const;
108     sal_uInt16 GetAllScriptsOfText( const String& rTxt ) const;
109 };
110 
111 #define SW_BREAKITER()  SwBreakIt::Get()
112 #define SW_XBREAKITER() SW_BREAKITER()->GetBreakIter()
113 
114 // @@@ backward compatibility @@@
115 SW_DLLPUBLIC extern SwBreakIt* pBreakIt;
116 
117 #endif
118 
119