1 /***************************************************************************
2  *   Copyright (C) 2004 by TAM(Teppei Tamra)                               *
3  *   tam-t@par.odn.ne.jp                                                   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20 #ifndef WNNCONVERSION_H
21 #define WNNCONVERSION_H
22 
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26 
27 #include <cstdio>
28 #include <cstdlib>
29 #include <cstring>
30 #include <vector>
31 #include <wnnproto.h>
32 #define Uses_SCIM_ICONV
33 #include <scim.h>
34 #include <scim_iconv.h>
35 #include <scim_attribute.h>
36 #include <convertor.h>
37 
38 
39 
40 #define HONOKA_CONFIG_JSERVERTYPE                  "/IMEngine/Honoka/Wnn/JServerType"
41 #ifdef HAVE_LIBWNN7
42   #define HONOKA_DEFAULT_JSERVERTYPE                  "Wnn7"
43 #else
44   #define HONOKA_DEFAULT_JSERVERTYPE                  "Wnn4"
45 #endif
46 
47 #define HONOKA_CONFIG_JSERVER                      "/IMEngine/Honoka/Wnn/JServer"
48 #define HONOKA_DEFAULT_JSERVER                     "localhost"
49 #define HONOKA_CONFIG_WNNENVRC                     "/IMEngine/Honoka/Wnn/Wnnenvrc"
50 #define HONOKA_DEFAULT_WNNENVRC                    "/usr/lib/wnn7/ja_JP/wnnenvrc"
51 
52 #define HONOKA_CONFIG_WNNYOSOKU                     "/IMEngine/Honoka/Wnn/Yosoku"
53 #ifdef HAVE_LIBWNN7
54   #define HONOKA_DEFAULT_WNNYOSOKU                   true
55 #else
56   #define HONOKA_DEFAULT_WNNYOSOKU                   false
57 #endif
58 
59 
60 
61 using namespace scim;
62 using namespace std;
63 
64 
65 /**
66 @author TAM(Teppei Tamra)
67 */
68 
69 namespace Honoka {
70 
71 
72 class WnnConversion : public Convertor {
73 public:
74     enum JServerType { Wnn4, Wnn6, Wnn7, Wnn8 };
75     WnnConversion(ConfigPointer cfg);
76 
77     ~WnnConversion();
78     virtual bool isConnected();
79     virtual void reset();
80     virtual void setYomiText(WideString yomi);
81     virtual int ren_conversion();
82     virtual int setPos(int p);
83     virtual int getPos();
84     virtual ResultList getResultList(int p = -1 ,ResultType kt = DEFAULT);
85     ResultList getYosokuList(const WideString &str);
86     virtual bool select(int p);
87     virtual bool resizeRegion(int w);
88     virtual void updateFrequency();
89     virtual bool connect();
90     virtual void disconnect();
91     virtual String getName();
92     virtual String getPropertyName();
93     virtual const vector<Segment> getSegmentList();
94     void updateYosoku(WideString text,const WideString yomi);
95 
96 
97 protected:
98     bool wnnConnect(String name,String host,String rc,JServerType type,int timeout);
99     void wnnDisconnect();
100     void wstostr(unsigned char *e,w_char *u);
101     void strtows(w_char *u,unsigned char *e);
102     static int wnn_message (char *s);
103     static int wnn_error (char *s);
104     void createText();
105 
106 protected:
107     struct wnn_buf *wnn;
108     String wnn_server;
109     String wnn_rc;
110     JServerType sType;
111     int wnn_timeout;
112     IConvert m_iconv;
113     WideString yomiText;
114     int pos;
115     int bunsetu;
116     int caretPos;
117     WideString text;
118     vector<WideString> bunList;
119     vector<WideString> yomiList;
120     AttributeList attr;
121     ResultList convList;
122     WideString pretext;
123 
124 };
125 
126 }
127 #endif
128