| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* Copyright (C) 2005 Takuro Ashie |
| 4 |
* Copyright (C) 2012 CSSlayer |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2, or (at your option) |
| 9 |
* any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#ifndef __FCITX_ANTHY_READING_H__ |
| 22 |
#define __FCITX_ANTHY_READING_H__ |
| 23 |
|
| 24 |
#include "key2kana.h" |
| 25 |
#include "kana.h" |
| 26 |
#include "nicola.h" |
| 27 |
#include "factory.h" |
| 28 |
|
| 29 |
class AnthyInstance; |
| 30 |
|
| 31 |
typedef enum { |
| 32 |
FCITX_ANTHY_STRING_LATIN, |
| 33 |
FCITX_ANTHY_STRING_WIDE_LATIN, |
| 34 |
FCITX_ANTHY_STRING_HIRAGANA, |
| 35 |
FCITX_ANTHY_STRING_KATAKANA, |
| 36 |
FCITX_ANTHY_STRING_HALF_KATAKANA, |
| 37 |
} StringType; |
| 38 |
|
| 39 |
class Reading; |
| 40 |
class ReadingSegment; |
| 41 |
typedef std::vector<ReadingSegment> ReadingSegments; |
| 42 |
|
| 43 |
class ReadingSegment |
| 44 |
{ |
| 45 |
friend class Reading; |
| 46 |
|
| 47 |
public: |
| 48 |
ReadingSegment (void); |
| 49 |
virtual ~ReadingSegment (); |
| 50 |
|
| 51 |
const std::string & get (void) { return kana; } |
| 52 |
const std::string & get_raw (void) { return raw; } |
| 53 |
|
| 54 |
void split (ReadingSegments &segments); |
| 55 |
|
| 56 |
private: |
| 57 |
std::string raw; |
| 58 |
std::string kana; |
| 59 |
}; |
| 60 |
|
| 61 |
class Reading |
| 62 |
{ |
| 63 |
public: |
| 64 |
Reading (AnthyInstance &anthy); |
| 65 |
virtual ~Reading (); |
| 66 |
|
| 67 |
bool can_process_key_event (const KeyEvent & key); |
| 68 |
bool process_key_event (const KeyEvent & key); |
| 69 |
void finish (void); |
| 70 |
void clear (void); |
| 71 |
|
| 72 |
std::string get_by_char (unsigned int start = 0, |
| 73 |
int length = -1, |
| 74 |
StringType type |
| 75 |
= FCITX_ANTHY_STRING_HIRAGANA); |
| 76 |
std::string get_raw_by_char (unsigned int start = 0, |
| 77 |
int length = -1); |
| 78 |
bool append (const KeyEvent & key, |
| 79 |
const std::string & string); |
| 80 |
void erase (unsigned int start = 0, |
| 81 |
int length = -1, |
| 82 |
bool allow_split = false); |
| 83 |
|
| 84 |
unsigned int get_length (void); |
| 85 |
unsigned int get_length_by_char (void); |
| 86 |
unsigned int get_caret_pos (void); |
| 87 |
unsigned int get_caret_pos_by_char (void); |
| 88 |
void set_caret_pos_by_char (unsigned int pos); |
| 89 |
void move_caret (int step, |
| 90 |
bool allow_split = false); |
| 91 |
|
| 92 |
void set_typing_method (TypingMethod method); |
| 93 |
TypingMethod get_typing_method (void); |
| 94 |
void set_period_style (PeriodStyle style); |
| 95 |
PeriodStyle get_period_style (void); |
| 96 |
void set_comma_style (CommaStyle style); |
| 97 |
CommaStyle get_comma_style (void); |
| 98 |
void set_bracket_style (BracketStyle style); |
| 99 |
BracketStyle get_bracket_style (void); |
| 100 |
void set_slash_style (SlashStyle style); |
| 101 |
SlashStyle get_slash_style (void); |
| 102 |
void set_symbol_width (bool half); |
| 103 |
bool get_symbol_width (void); |
| 104 |
void set_number_width (bool half); |
| 105 |
bool get_number_width (void); |
| 106 |
void set_pseudo_ascii_mode (int mode); |
| 107 |
bool is_pseudo_ascii_mode (void); |
| 108 |
void reset_pseudo_ascii_mode (void); |
| 109 |
|
| 110 |
private: |
| 111 |
void reset_pending (void); |
| 112 |
void split_segment (unsigned int seg_id); |
| 113 |
|
| 114 |
private: |
| 115 |
AnthyInstance &m_anthy; |
| 116 |
|
| 117 |
// tables |
| 118 |
Key2KanaTableSet m_key2kana_tables; |
| 119 |
Key2KanaTableSet m_nicola_tables; |
| 120 |
|
| 121 |
// convertors |
| 122 |
Key2KanaConvertor m_key2kana_normal; |
| 123 |
KanaConvertor m_kana; |
| 124 |
NicolaConvertor m_nicola; |
| 125 |
Key2KanaConvertorBase *m_key2kana; |
| 126 |
|
| 127 |
// state |
| 128 |
ReadingSegments m_segments; |
| 129 |
unsigned int m_segment_pos; |
| 130 |
unsigned int m_caret_offset; |
| 131 |
}; |
| 132 |
|
| 133 |
#endif /* __FCITX_ANTHY_READING_H__ */ |
| 134 |
/* |
| 135 |
vi:ts=4:nowrap:ai:expandtab |
| 136 |
*/ |