Tizen 2.1 base
[framework/uifw/ise-engine-anthy.git] / src / scim_anthy_conversion.h
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  *  Copyright (C) 2005 Takuro Ashie
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, or (at your option)
8  *  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 Free Software
17  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifndef __SCIM_ANTHY_CONVERSION_H__
21 #define __SCIM_ANTHY_CONVERSION_H__
22
23 #define Uses_SCIM_ICONV
24 #define Uses_SCIM_ATTRIBUTE
25 #define Uses_SCIM_LOOKUP_TABLE
26 #include <scim.h>
27 #include <anthy/anthy.h>
28
29 #include "scim_anthy_reading.h"
30
31 using namespace scim;
32
33 class AnthyInstance;
34
35 namespace scim_anthy {
36
37 typedef enum {
38     SCIM_ANTHY_CANDIDATE_DEFAULT       = 0,
39     SCIM_ANTHY_CANDIDATE_LATIN         = -1,
40     SCIM_ANTHY_CANDIDATE_WIDE_LATIN    = -2,
41     SCIM_ANTHY_CANDIDATE_HIRAGANA      = -3,
42     SCIM_ANTHY_CANDIDATE_KATAKANA      = -4,
43     SCIM_ANTHY_CANDIDATE_HALF_KATAKANA = -5,
44     SCIM_ANTHY_CANDIDATE_HALF          = -6,
45     SCIM_ANTHY_LAST_SPECIAL_CANDIDATE  = -7,
46 } CandidateType;
47
48 class ConversionSegment
49 {
50 public:
51     ConversionSegment (WideString   str,
52                        int          cand_id,
53                        unsigned int reading_len);
54     virtual ~ConversionSegment ();
55
56     WideString & get_string         (void);
57     int          get_candidate_id   (void);
58     unsigned int get_reading_length (void);
59
60     void         set                (WideString   str,
61                                      int          cand_id);
62     void         set_reading_length (unsigned int len);
63
64 private:
65     WideString   m_string;
66     int          m_cand_id;
67     unsigned int m_reading_len;
68 };
69 typedef std::vector<ConversionSegment> ConversionSegments;
70
71 class Conversion
72 {
73 public:
74     Conversion (AnthyInstance &anthy, Reading &reading);
75     virtual ~Conversion ();
76
77     // starting and finishing
78     void          convert                (WideString    source,
79                                           CandidateType ctype,
80                                           bool          single_segment);
81     void          convert                (CandidateType type
82                                           = SCIM_ANTHY_CANDIDATE_DEFAULT,
83                                           bool          single_segment = false);
84     void          convert                (const WideString &source,
85                                           bool          single_segment = false);
86     void          predict                (void);
87     void          clear                  (int           segment_id = -1);
88     void          commit                 (int           segment_id = -1,
89                                           bool          learn      = true);
90
91     // getting status
92     bool          is_converting          (void);
93     bool          is_predicting          (void);
94
95     WideString    get                    (void);
96     unsigned int  get_length             (void);
97     AttributeList get_attribute_list     (void);
98
99     // segments of the converted sentence
100     int           get_nr_segments        (void);
101     WideString    get_segment_string     (int           segment_id = -1,
102                                           int           candidate_id
103                                           = SCIM_ANTHY_LAST_SPECIAL_CANDIDATE);
104     int           get_selected_segment   (void);
105     void          select_segment         (int           segment_id);
106     int           get_segment_size       (int           segment_id = -1);
107     void          resize_segment         (int           relative_size,
108                                           int           segment_id = -1);
109     unsigned int  get_segment_position   (int           segment_id = -1);
110
111     // candidates for a segment or prediction
112     void          get_candidates         (CommonLookupTable &table,
113                                           int           segment_id = -1);
114     int           get_selected_candidate (int           segment_id = -1);
115     void          select_candidate       (int           candidate_id,
116                                           int           segment_id = -1);
117
118     // prefereneces
119     bool          set_dict_encoding      (String        type);
120
121 private:
122     void          get_reading_substr     (WideString   &string,
123                                           int           segment_id,
124                                           int           candidate_id,
125                                           int           seg_start,
126                                           int           seg_len);
127     WideString    get_prediction_string  (int           candidate_id);
128     void          join_all_segments      (void);
129
130 private:
131     AnthyInstance      &m_anthy;
132
133     // convertors
134     IConvert            m_iconv;
135     Reading            &m_reading;
136     anthy_context_t     m_anthy_context;
137
138     // status variables
139     ConversionSegments  m_segments;
140     int                 m_start_id;    // number of commited segments
141     int                 m_cur_segment; // relative position from m_start_id
142     bool                m_predicting;
143 };
144
145 }
146
147 #endif /* __SCIM_ANTHY_READING_H__ */
148 /*
149 vi:ts=4:nowrap:ai:expandtab
150 */