~registry/scim-bridge/trunk

« back to all changes in this revision

Viewing changes to scim-pinyin/tags/scim-pinyin-0.5.92/src/scim_native_lookup_table.cpp

  • Committer: tzhuan
  • Date: 2012-07-15 15:18:50 UTC
  • Revision ID: svn-v4:1ec84b21-7132-0410-a32e-e68a3534c3c7::413
Wrong commit, remove tags/scim-pinyin-0.5.92.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/** @file scim_lookup_table.cpp
2
 
 * implementation of class LookupTable.
3
 
 */
4
 
 
5
 
/*
6
 
 * Smart Pinyin Input Method
7
 
 * 
8
 
 * Copyright (c) 2005 James Su <suzhe@tsinghua.org.cn>
9
 
 *
10
 
 * $Id: scim_native_lookup_table.cpp,v 1.1.1.1 2005/01/06 13:30:58 suzhe Exp $
11
 
 *
12
 
 */
13
 
 
14
 
#define Uses_STL_AUTOPTR
15
 
#define Uses_STL_FUNCTIONAL
16
 
#define Uses_STL_VECTOR
17
 
#define Uses_STL_IOSTREAM
18
 
#define Uses_STL_FSTREAM
19
 
#define Uses_STL_ALGORITHM
20
 
#define Uses_STL_MAP
21
 
#define Uses_STL_UTILITY
22
 
#define Uses_STL_IOMANIP
23
 
#define Uses_C_STDIO
24
 
#define Uses_SCIM_UTILITY
25
 
#define Uses_SCIM_IMENGINE
26
 
#define Uses_SCIM_ICONV
27
 
#define Uses_SCIM_CONFIG_BASE
28
 
#define Uses_SCIM_CONFIG_PATH
29
 
#define Uses_SCIM_LOOKUP_TABLE
30
 
 
31
 
#include <scim.h>
32
 
#include "scim_pinyin_private.h"
33
 
#include "scim_phrase.h"
34
 
#include "scim_native_lookup_table.h"
35
 
 
36
 
//implementation of NativeLookupTable
37
 
NativeLookupTable::NativeLookupTable (int page_size)
38
 
    : LookupTable (page_size)
39
 
{
40
 
    std::vector <WideString> labels;
41
 
    char buf [2] = { 0, 0 };
42
 
    for (int i = 0; i < 9; ++i) {
43
 
        buf [0] = '1' + i;
44
 
        labels.push_back (utf8_mbstowcs (buf));
45
 
    }
46
 
    buf [0] = '0';
47
 
    labels.push_back (utf8_mbstowcs (buf));
48
 
 
49
 
    set_candidate_labels (labels);
50
 
}
51
 
 
52
 
bool
53
 
NativeLookupTable::append_entry (const WideString &entry)
54
 
{
55
 
    if (entry.length () > 0) {
56
 
        m_strings.push_back (entry);
57
 
        return true;
58
 
    }
59
 
    return false;
60
 
}
61
 
 
62
 
bool
63
 
NativeLookupTable::append_entry (const Phrase& entry)
64
 
{
65
 
    if (entry.is_enable ()) {
66
 
        m_phrases.push_back (entry);
67
 
        return true;
68
 
    }
69
 
    return false;
70
 
}
71
 
 
72
 
bool
73
 
NativeLookupTable::append_entry (const ucs4_t& entry)
74
 
{
75
 
    if (entry != 0) {
76
 
        m_chars.push_back (entry);
77
 
        return true;
78
 
    }
79
 
    return false;
80
 
}
81
 
 
82
 
WideString
83
 
NativeLookupTable::get_candidate (int index) const
84
 
{
85
 
    if (index < 0 || index >= (int) number_of_candidates ())
86
 
        return WideString ();
87
 
 
88
 
    if (index < (int) m_strings.size ()) {
89
 
        return m_strings [index];
90
 
    } else if (index < (int) (m_strings.size () + m_phrases.size ())) {
91
 
        return m_phrases [index - m_strings.size ()].get_content ();
92
 
    } else {
93
 
        return WideString (m_chars.begin () + index - m_strings.size () - m_phrases.size (), 
94
 
                        m_chars.begin () + index - m_strings.size () - m_phrases.size () + 1);
95
 
    }
96
 
    return WideString ();
97
 
}
98
 
 
99
 
AttributeList
100
 
NativeLookupTable::get_attributes (int index) const
101
 
{
102
 
    AttributeList attrs;
103
 
 
104
 
#if 0
105
 
    if (index >= 0 && index < (int) m_strings.size ())
106
 
        attrs.push_back (Attribute (0, m_strings [index].length (), SCIM_ATTR_FOREGROUND, SCIM_RGB_COLOR(32, 32, 255)));
107
 
#endif
108
 
 
109
 
    return attrs;
110
 
}
111
 
 
112
 
/*
113
 
vi:ts=4:nowrap:ai:expandtab
114
 
*/