1
/* vim:set et ts=4 sts=4:
3
* ibus-pinyin - The Chinese PinYin engine for IBus
5
* Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2, or (at your option)
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
#ifndef __PY_PHRASE_EDITOR_H_
22
#define __PY_PHRASE_EDITOR_H_
24
#include <boost/shared_ptr.hpp>
26
#include "PYPhraseArray.h"
27
#include "PYPinyinArray.h"
29
#define FILL_GRAN (12)
35
class PinyinProperties;
40
PhraseEditor (PinyinProperties & props, Config & config);
43
const String & selectedString (void) const { return m_selected_string; }
44
const PinyinArray & pinyin (void) const { return m_pinyin; }
45
const PhraseArray & candidates (void) const { return m_candidates; }
46
guint cursor (void) const { return m_cursor; }
48
guint cursorInChar (void) const
50
return m_cursor == 0 ? 0 : m_pinyin[m_cursor - 1].begin + m_pinyin[m_cursor - 1].len;
53
gboolean pinyinExistsAfterCursor (void) const
55
return m_pinyin.size () > m_cursor;
58
const Phrase & candidate (guint i) const
60
return m_candidates[i];
63
gboolean fillCandidates (void);
65
const PhraseArray & candidate0 (void) const
67
return m_candidate_0_phrases;
70
gboolean candidateIsUserPhease (guint i) const
72
const Phrase & phrase = m_candidates[i];
73
return phrase.len > 1 && phrase.user_freq > 0 && phrase.freq == 0;
76
gboolean unselectCandidates (void)
82
m_selected_phrases.clear ();
83
m_selected_string.truncate (0);
92
m_candidates.clear ();
93
m_selected_phrases.clear ();
94
m_selected_string.truncate (0);
95
m_candidate_0_phrases.clear ();
101
gboolean update (const PinyinArray &pinyin);
102
gboolean selectCandidate (guint i);
103
gboolean resetCandidate (guint i);
106
gboolean empty (void) const
108
return m_selected_string.empty () && m_candidate_0_phrases.empty ();
111
operator gboolean (void) const
117
void updateCandidates (void);
118
void updateTheFirstCandidate (void);
121
PhraseArray m_candidates; // candidates phrase array
122
PhraseArray m_selected_phrases; // selected phrases, before cursor
123
String m_selected_string; // selected phrases, in string format
124
PhraseArray m_candidate_0_phrases; // the first candidate in phrase array format
125
PinyinArray m_pinyin;
127
PinyinProperties & m_props;
128
boost::shared_ptr<Query> m_query;