xref: /trunk/main/filter/source/t602/t602filter.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
62 ::com::sun::star::uno::Sequence < ::rtl::OUString > getSupportedServiceNames();
63 
64 
65 ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > SAL_CALL
66     CreateInstance( const ::com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > &r);
67 
68 
69 //
70 // class T602ImportFilter
71 //
72 
73 struct inistruct
74 {
75         bool showcomm;      // true   show comment lines
76         bool forcecode;     // false  the user has changed the encoding with something else than @CT
77         tcode xcode;        // KAM    encoding set - forced
78         bool ruscode;       // false  Russian tables turned on
79         bool reformatpars;  // false  Reformat paragraphs (whitespaces and line breaks)
80         sal_Int16 fontsize;       // font size in points
81 
inistructT602ImportFilter::inistruct82         inistruct()
83             : showcomm( true )
84             , forcecode( false )
85             , xcode ( KAM )
86             , ruscode ( false )
87             , reformatpars ( false )
88             , fontsize (10)
89         {
90         };
91 };
92 
93 class T602ImportFilterDialog : public cppu::WeakImplHelper4 <
94         com::sun::star::ui::dialogs::XExecutableDialog,
95         com::sun::star::lang::XLocalizable,
96         com::sun::star::lang::XServiceInfo,
97         com::sun::star::beans::XPropertyAccess
98 >
99 {
100     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
101     com::sun::star::lang::Locale meLocale;
102     ResMgr *mpResMgr;
103     sal_Bool OptionsDlg();
104     ResMgr* getResMgr();
105     rtl::OUString getResStr( sal_Int16 resid );
106     void initLocale();
107 
108     ~T602ImportFilterDialog();
109 
110     // XExecutableDialog
111        virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle );
112        virtual sal_Int16 SAL_CALL execute();
113 
114     // XLocalizable
115         virtual void SAL_CALL setLocale( const com::sun::star::lang::Locale& eLocale );
116         virtual com::sun::star::lang::Locale SAL_CALL getLocale();
117 
118     // XServiceInfo
119         virtual ::rtl::OUString SAL_CALL getImplementationName(  );
120         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
121         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  );
122 
123     // XPropertyAccess
124         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >
125                             SAL_CALL getPropertyValues();
126         virtual void SAL_CALL   setPropertyValues( const ::com::sun::star::uno::Sequence<
127                                     ::com::sun::star::beans::PropertyValue >& aProps );
128 
129 public:
130     T602ImportFilterDialog(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r );
131 
132 };
133 
134 
135 class T602ImportFilter : public cppu::WeakImplHelper5 <
136     com::sun::star::document::XFilter,
137     com::sun::star::document::XImporter,
138     com::sun::star::document::XExtendedFilterDetection,
139     com::sun::star::lang::XInitialization,
140     com::sun::star::lang::XServiceInfo
141 >
142 {
143 private:
144 //    ::com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream;
145     ::com::sun::star::uno::Reference<com::sun::star::xml::sax::XDocumentHandler> mxHandler;
146     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF;
147     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mxDoc;
148     ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > mxInputStream;
149     ::rtl::OUString msFilterName;
150 
151     SvXMLAttributeList *mpAttrList;
152 
153     tnode node;         // START
154 
155     struct {
156         sal_Int16   mt;       // row for header
157         sal_Int16   mb;       // row for footer
158         sal_Int16   tb;       // tabs
159         sal_Int16   ct;       // encoding (0-kamenik, 1-latin2, 2-koi8)
160         sal_Int16   pn;       // from page number
161         sal_Int16   lh;       // linespacing 3-2x, 4-1.5x, 6-1x
162         sal_Int16   lm;       // left border
163         sal_Int16   rm;       // right border
164         sal_Int16   pl;       // page length
165     } format602;
166 
167     // Initialisation constants - they are not changed during the conversion
168 
169     inistruct ini;
170 
171     // Font state - changes based on font
172 
173     struct {
174         fonts nowfnt;     // current font
175         fonts oldfnt;     // previous font
176         bool uline;       // underlined
177         bool olduline;    // previous value of uline (font change)
178     } fst;
179 
180     // Paragraph state
181 
182     struct {
183         sal_Int16 pars;            //       the number of line endings times linespacing on the current page
184         bool comment;        //       in comments
185         sal_Int16 wasspace;        // 0     there was a space - for reformatting
186         bool wasfdash;       // 0     formatting dash
187         bool ccafterln;      // false
188         bool willbeeop;      // false
189         bool waspar;         // false
190     } pst;
191 
192     void Reset602();
193     unsigned char Readchar602();
194     void Read602();
195     void par602(bool endofpage);
196     void inschr(unsigned char ch);
197     void inschrdef(unsigned char ch);
198     unsigned char Setformat602(char *cmd);
199     sal_Int16 readnum(unsigned char *ch, bool show);
200     tnode PointCmd602(unsigned char *ch);
201     void setfnt(fonts fnt,bool mustwrite);
202     void wrtfnt();
203 
204     sal_Bool SAL_CALL importImpl( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor );
205 
206     public:
207         T602ImportFilter(const ::com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory > &r );
208         ~T602ImportFilter();
209 
210     // XFilter
211         virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor );
cancel()212         virtual void SAL_CALL cancel(  ) {};
213 
214     // XImporter
215         virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc );
216 
217     // XExtendedTypeDetection
218         virtual ::rtl::OUString SAL_CALL detect(
219             com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& Descriptor );
220 
221     // XInitialization
222         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments );
223 
224     // XServiceInfo
225         virtual ::rtl::OUString SAL_CALL getImplementationName(  );
226         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
227         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  );
228 };
229 
230 ::rtl::OUString T602ImportFilter_getImplementationName();
231 
232 sal_Bool SAL_CALL T602ImportFilter_supportsService( const ::rtl::OUString& ServiceName );
233 
234 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL T602ImportFilter_getSupportedServiceNames(  );
235 
236 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
237 SAL_CALL T602ImportFilter_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr);
238 
239 ::rtl::OUString T602ImportFilterDialog_getImplementationName();
240 
241 sal_Bool SAL_CALL T602ImportFilterDialog_supportsService( const ::rtl::OUString& ServiceName );
242 
243 ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL T602ImportFilterDialog_getSupportedServiceNames(  );
244 
245 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
246 SAL_CALL T602ImportFilterDialog_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr);
247 
248 }
249 
250 #endif
251