xref: /trunk/main/filter/source/t602/t602filter.hxx (revision 22e87013)
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 _T602FILTER_HXX
25 #define _T602FILTER_HXX
26 
27 #include <com/sun/star/document/XFilter.hpp>
28 #include <com/sun/star/document/XImporter.hpp>
29 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
30 #include <com/sun/star/io/XInputStream.hpp>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/lang/XLocalizable.hpp>
34 #include <com/sun/star/beans/XPropertyAccess.hpp>
35 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
36 #include <cppuhelper/implbase5.hxx>
37 #include <cppuhelper/implbase4.hxx>
38 #include <xmloff/attrlist.hxx>
39 #include <tools/resmgr.hxx>
40 
41 namespace T602ImportFilter {
42 
43 typedef enum {L2,KAM,KOI} tcode;
44 
45 typedef enum {
46         standard,   // default
47         fat,        // bold
48         cursive,    // italic
49         bold,       // wide
50         tall,       // high
51         big,        // big
52         lindex,     // lower index
53         hindex,     // upper index
54         err,        // not set yet
55         chngul      // change underline
56 } fonts;
57 
58 typedef enum {START,READCH,EOL,POCMD,EXPCMD,SETCMD,SETCH,WRITE,EEND,QUIT} tnode;
59 
60 ::rtl::OUString getImplementationName()
61     throw ( ::com::sun::star::uno::RuntimeException );
62 
63 ::com::sun::star::uno::Sequence < ::rtl::OUString > getSupportedServiceNames()
64     throw ( ::com::sun::star::uno::RuntimeException );
65 
66 
67 ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > SAL_CALL
68     CreateInstance( const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &r)
69     throw ( ::com::sun::star::uno::Exception );
70 
71 
72 //
73 // class T602ImportFilter
74 //
75 
76 struct inistruct
77 {
78         bool showcomm;      // true   show comment lines
79         bool forcecode;     // false  the user has changed the encoding with something else than @CT
80         tcode xcode;        // KAM    encoding set - forced
81         bool ruscode;       // false  Russian tables turned on
82         bool reformatpars;  // false  Reformat paragraphs (whitespaces and line breaks)
83         sal_Int16 fontsize;       // font size in points
84 
inistructT602ImportFilter::inistruct85 		inistruct()
86 			: showcomm( true )
87 			, forcecode( false )
88 			, xcode ( KAM )
89 			, ruscode ( false )
90 			, reformatpars ( false )
91 			, fontsize (10)
92 		{
93 		};
94 };
95 
96 class T602ImportFilterDialog : public cppu::WeakImplHelper4 <
97 		com::sun::star::ui::dialogs::XExecutableDialog,
98 		com::sun::star::lang::XLocalizable,
99 		com::sun::star::lang::XServiceInfo,
100 		com::sun::star::beans::XPropertyAccess
101 >
102 {
103     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
104 	com::sun::star::lang::Locale meLocale;
105     ResMgr *mpResMgr;
106     sal_Bool OptionsDlg();
107     ResMgr* getResMgr();
108     rtl::OUString getResStr( sal_Int16 resid );
109     void initLocale();
110 
111     ~T602ImportFilterDialog();
112 
113 	// XExecutableDialog
114        virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
115             throw (::com::sun::star::uno::RuntimeException);
116        virtual sal_Int16 SAL_CALL execute()
117             throw (::com::sun::star::uno::RuntimeException);
118 
119 	// XLocalizable
120         virtual void SAL_CALL setLocale( const com::sun::star::lang::Locale& eLocale )
121             throw(::com::sun::star::uno::RuntimeException);
122         virtual com::sun::star::lang::Locale SAL_CALL getLocale()
123             throw(::com::sun::star::uno::RuntimeException);
124 
125     // XServiceInfo
126         virtual ::rtl::OUString SAL_CALL getImplementationName(  )
127             throw (::com::sun::star::uno::RuntimeException);
128         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
129             throw (::com::sun::star::uno::RuntimeException);
130         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
131             throw (::com::sun::star::uno::RuntimeException);
132 
133 	// XPropertyAccess
134 		virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
135 							SAL_CALL getPropertyValues() throw (::com::sun::star::uno::RuntimeException);
136 		virtual void SAL_CALL	setPropertyValues( const ::com::sun::star::uno::Sequence<
137 									::com::sun::star::beans::PropertyValue >& aProps )
138 								throw (::com::sun::star::beans::UnknownPropertyException,
139 										::com::sun::star::beans::PropertyVetoException,
140 										::com::sun::star::lang::IllegalArgumentException,
141 										::com::sun::star::lang::WrappedTargetException,
142 										::com::sun::star::uno::RuntimeException);
143 
144 public:
145 	T602ImportFilterDialog(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r );
146 
147 };
148 
149 
150 class T602ImportFilter : public cppu::WeakImplHelper5 <
151     com::sun::star::document::XFilter,
152     com::sun::star::document::XImporter,
153     com::sun::star::document::XExtendedFilterDetection,
154     com::sun::star::lang::XInitialization,
155     com::sun::star::lang::XServiceInfo
156 >
157 {
158 private:
159 //    ::com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream;
160     ::com::sun::star::uno::Reference<com::sun::star::xml::sax::XDocumentHandler> mxHandler;
161     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
162     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc;
163     ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > mxInputStream;
164     ::rtl::OUString msFilterName;
165 
166     SvXMLAttributeList *mpAttrList;
167 
168     tnode node;         // START
169 
170     struct {
171         sal_Int16   mt;       // row for header
172         sal_Int16   mb;       // row for footer
173         sal_Int16   tb;       // tabs
174         sal_Int16   ct;       // encoding (0-kamenik, 1-latin2, 2-koi8)
175         sal_Int16   pn;       // from page number
176         sal_Int16   lh;       // linespacing 3-2x, 4-1.5x, 6-1x
177         sal_Int16   lm;       // left border
178         sal_Int16   rm;       // right border
179         sal_Int16   pl;       // page length
180     } format602;
181 
182     // Initialisation constants - they are not changed during the conversion
183 
184     inistruct ini;
185 
186     // Font state - changes based on font
187 
188     struct {
189         fonts nowfnt;     // current font
190         fonts oldfnt;     // previous font
191         bool uline;       // underlined
192         bool olduline;    // previous value of uline (font change)
193     } fst;
194 
195     // Paragraph state
196 
197     struct {
198         sal_Int16 pars;            //       the number of line endings times linespacing on the current page
199         bool comment;        //       in comments
200         sal_Int16 wasspace;        // 0     there was a space - for reformatting
201         bool wasfdash;       // 0     formatting dash
202         bool ccafterln;      // false
203         bool willbeeop;      // false
204         bool waspar;         // false
205     } pst;
206 
207     void Reset602();
208     unsigned char Readchar602();
209     void Read602();
210     void par602(bool endofpage);
211     void inschr(unsigned char ch);
212     void inschrdef(unsigned char ch);
213     unsigned char Setformat602(char *cmd);
214     sal_Int16 readnum(unsigned char *ch, bool show);
215     tnode PointCmd602(unsigned char *ch);
216     void setfnt(fonts fnt,bool mustwrite);
217     void wrtfnt();
218 
219     sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
220         throw (::com::sun::star::uno::RuntimeException);
221 
222     public:
223         T602ImportFilter(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r );
224         ~T602ImportFilter();
225 
226     // XFilter
227         virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
228             throw (::com::sun::star::uno::RuntimeException);
cancel()229         virtual void SAL_CALL cancel(  )
230             throw (::com::sun::star::uno::RuntimeException) {};
231 
232     // XImporter
233         virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
234             throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
235 
236     // XExtendedTypeDetection
237         virtual ::rtl::OUString SAL_CALL detect(
238             com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Descriptor )
239             throw( com::sun::star::uno::RuntimeException );
240 
241     // XInitialization
242         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
243             throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
244 
245     // XServiceInfo
246         virtual ::rtl::OUString SAL_CALL getImplementationName(  )
247             throw (::com::sun::star::uno::RuntimeException);
248         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
249             throw (::com::sun::star::uno::RuntimeException);
250         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
251             throw (::com::sun::star::uno::RuntimeException);
252 };
253 
254 ::rtl::OUString T602ImportFilter_getImplementationName()
255     throw ( ::com::sun::star::uno::RuntimeException );
256 
257 sal_Bool SAL_CALL T602ImportFilter_supportsService( const ::rtl::OUString& ServiceName )
258     throw ( ::com::sun::star::uno::RuntimeException );
259 
260 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL T602ImportFilter_getSupportedServiceNames(  )
261     throw ( ::com::sun::star::uno::RuntimeException );
262 
263 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
264 SAL_CALL T602ImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
265     throw ( ::com::sun::star::uno::Exception );
266 
267 ::rtl::OUString T602ImportFilterDialog_getImplementationName()
268     throw ( ::com::sun::star::uno::RuntimeException );
269 
270 sal_Bool SAL_CALL T602ImportFilterDialog_supportsService( const ::rtl::OUString& ServiceName )
271     throw ( ::com::sun::star::uno::RuntimeException );
272 
273 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL T602ImportFilterDialog_getSupportedServiceNames(  )
274     throw ( ::com::sun::star::uno::RuntimeException );
275 
276 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
277 SAL_CALL T602ImportFilterDialog_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr)
278     throw ( ::com::sun::star::uno::Exception );
279 
280 }
281 
282 #endif
283