~ubuntu-branches/ubuntu/precise/fcitx-sunpinyin/precise

« back to all changes in this revision

Viewing changes to src/handler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Aron Xu
  • Date: 2010-11-28 00:10:22 UTC
  • Revision ID: james.westby@ubuntu.com-20101128001022-pwsvx36n5zuo0k87
Tags: upstream-0.2.1
ImportĀ upstreamĀ versionĀ 0.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  Copyright (C) 2010~2010 by CSSlayer
 
2
    wengxt@gmail.com 
 
3
 
 
4
   This program is free software: you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation; either version 3 of the License, or
 
7
   (at your option) any later version.
 
8
 
 
9
   This program is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
16
 
 
17
#include <sunpinyin.h>
 
18
#include "handler.h"
 
19
 
 
20
/**
 
21
 * @brief handler called while preedit updated
 
22
 *
 
23
 * @param ppd preedit string
 
24
 * @return void
 
25
 **/
 
26
void FcitxWindowHandler::updatePreedit(const IPreeditString* ppd)
 
27
{
 
28
    char *buf_ = eim->CodeInput;
 
29
    TIConvSrcPtr src = (TIConvSrcPtr) (ppd->string());
 
30
    memset(front_src, 0, BUF_SIZE * sizeof(TWCHAR));
 
31
    memset(end_src, 0, BUF_SIZE * sizeof(TWCHAR));
 
32
    
 
33
    memcpy(front_src, src, ppd->caret() * sizeof(TWCHAR));
 
34
    memcpy(end_src, src + ppd->caret() * sizeof(TWCHAR), 
 
35
           (ppd->size() - ppd->caret() + 1) * sizeof(TWCHAR));
 
36
    
 
37
    memset(buf_, 0, MAX_USER_INPUT + 1);
 
38
    
 
39
    WCSTOMBS(buf_, front_src, MAX_USER_INPUT);
 
40
    eim->CaretPos = strlen(buf_);
 
41
    WCSTOMBS(&buf_[strlen(buf_)], end_src, MAX_USER_INPUT);
 
42
    candidate_flag = true;
 
43
}
 
44
 
 
45
/**
 
46
 * @brief sunpinyin called this function while updating candidate words
 
47
 *
 
48
 * @param pcl candidate list
 
49
 * @return void
 
50
 **/
 
51
void FcitxWindowHandler::updateCandidates(const ICandidateList* pcl)
 
52
{
 
53
    wstring cand_str;
 
54
    for (int i = 0, sz = pcl->size(); i < sz; i++) {
 
55
        const TWCHAR* pcand = pcl->candiString(i);
 
56
        cand_str = pcand;
 
57
        TIConvSrcPtr src = (TIConvSrcPtr)(cand_str.c_str());
 
58
        WCSTOMBS(eim->CandTable[i], (const TWCHAR*) src, MAX_CAND_LEN);
 
59
    }
 
60
 
 
61
    eim->CandWordCount = pcl->size();
 
62
 
 
63
    candidate_flag = true;
 
64
}
 
65
 
 
66
/**
 
67
 * @brief sunpinyin called this function while commit the string
 
68
 *
 
69
 * @param str committed string
 
70
 * @return void
 
71
 **/
 
72
void FcitxWindowHandler::commit(const TWCHAR* str)
 
73
{
 
74
    char *buf_ = eim->StringGet;
 
75
    memset(buf_, 0, MAX_USER_INPUT);
 
76
    WCSTOMBS(buf_, str, MAX_USER_INPUT);
 
77
    commit_flag = true;
 
78
}