~ubuntu-branches/ubuntu/raring/sunpinyin/raring

« back to all changes in this revision

Viewing changes to wrapper/xim/sunpinyin_preedit_skin.cc

  • Committer: Package Import Robot
  • Author(s): YunQiang Su
  • Date: 2012-03-30 15:31:55 UTC
  • mfrom: (1.1.3) (1.2.7 sid)
  • Revision ID: package-import@ubuntu.com-20120330153155-qgls77sogzgtg9zp
Tags: 2.0.3+git20120222-1
* Team upload: git snapshot 20120222.
   - fix breaks if LDFLAGS in environment contains
       multiple words (Closese #646001).
   - rm patches merged to upstream:
       append-os-environ-toenv.patch
       fix-ftbfs-on-sh.patch
       remove-10-candidate-words-limitation.patch
   - refresh disable-lm-dict-compile.patch.
* Bump stardard version to 3.9.3: no modify needed.
* add libsunpinyin3-dbg and python-sunpinyin packages.
* debian/compat to 9, multiarch it.
* rewrite debian/rules with dh 7 format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2010 Mike Qin <mikeandmore@gmail.com>
 
3
 *
 
4
 * The contents of this file are subject to the terms of either the GNU Lesser
 
5
 * General Public License Version 2.1 only ("LGPL") or the Common Development and
 
6
 * Distribution License ("CDDL")(collectively, the "License"). You may not use this
 
7
 * file except in compliance with the License. You can obtain a copy of the CDDL at
 
8
 * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at
 
9
 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the
 
10
 * specific language governing permissions and limitations under the License. When
 
11
 * distributing the software, include this License Header Notice in each file and
 
12
 * include the full text of the License in the License file as well as the
 
13
 * following notice:
 
14
 *
 
15
 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
 
16
 * (CDDL)
 
17
 * For Covered Software in this distribution, this License shall be governed by the
 
18
 * laws of the State of California (excluding conflict-of-law provisions).
 
19
 * Any litigation relating to this License shall be subject to the jurisdiction of
 
20
 * the Federal Courts of the Northern District of California and the state courts
 
21
 * of the State of California, with venue lying in Santa Clara County, California.
 
22
 *
 
23
 * Contributor(s):
 
24
 *
 
25
 * If you wish your version of this file to be governed by only the CDDL or only
 
26
 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to
 
27
 * include this software in this distribution under the [CDDL or LGPL Version 2.1]
 
28
 * license." If you don't indicate a single choice of license, a recipient has the
 
29
 * option to distribute your version of this file under either the CDDL or the LGPL
 
30
 * Version 2.1, or to extend the choice of license to its licensees as provided
 
31
 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL
 
32
 * Version 2 license, then the option applies only if the new code is made subject
 
33
 * to such option by the copyright holder.
 
34
 */
 
35
 
 
36
#include "ui.h"
 
37
#include "settings.h"
 
38
#include "sunpinyin_preedit_ui.h"
 
39
#include "skin.h"
 
40
 
 
41
SkinPreeditUI::SkinPreeditUI(std::string name) throw()
 
42
    : PreeditUI(name)
 
43
{
 
44
    info_ = ui_skin_new(name.c_str());
 
45
    if (!info_) {
 
46
        throw SkinLoaderException();
 
47
    }
 
48
    main_wnd_ = skin_window_new(GTK_WINDOW(ui_create_window()),
 
49
                                info_->preedit_background,
 
50
                                info_->top, info_->left,
 
51
                                info_->bottom, info_->right,
 
52
                                1);
 
53
    preedit_label_ = skin_label_new(info_->preedit_label.font, NULL,
 
54
                                    info_->preedit_label.color_r,
 
55
                                    info_->preedit_label.color_g,
 
56
                                    info_->preedit_label.color_b,
 
57
                                    info_->preedit_label.color_a);
 
58
 
 
59
    candidate_label_ = skin_label_new(info_->candidate_label.font, NULL,
 
60
                                      info_->candidate_label.color_r,
 
61
                                      info_->candidate_label.color_g,
 
62
                                      info_->candidate_label.color_b,
 
63
                                      info_->candidate_label.color_a);
 
64
 
 
65
    skin_window_add_label(main_wnd_, preedit_label_,
 
66
                          info_->preedit_label.x, info_->preedit_label.y);
 
67
    skin_window_add_label(main_wnd_, candidate_label_,
 
68
                          info_->candidate_label.x, info_->candidate_label.y);
 
69
}
 
70
 
 
71
SkinPreeditUI::~SkinPreeditUI()
 
72
{
 
73
    ui_skin_destroy(info_);
 
74
    skin_label_destroy(preedit_label_);
 
75
    skin_label_destroy(candidate_label_);
 
76
    skin_window_destroy(main_wnd_);
 
77
}
 
78
 
 
79
void
 
80
SkinPreeditUI::show()
 
81
{
 
82
    gtk_widget_show(main_wnd_->widget);
 
83
    adjust_size();
 
84
}
 
85
 
 
86
void
 
87
SkinPreeditUI::hide()
 
88
{
 
89
    gtk_widget_hide(main_wnd_->widget);
 
90
}
 
91
 
 
92
void
 
93
SkinPreeditUI::move(int x, int y)
 
94
{
 
95
    internal_move(x - info_->offset_x, y - info_->offset_y);
 
96
}
 
97
 
 
98
void SkinPreeditUI::internal_move(int x, int y)
 
99
{
 
100
    int width, height;
 
101
    gtk_window_get_size(GTK_WINDOW(main_wnd_->widget), &width, &height);
 
102
    adjust_position(&x, &y, width, height);
 
103
    gtk_window_move(GTK_WINDOW(main_wnd_->widget), x, y);
 
104
}
 
105
 
 
106
void
 
107
SkinPreeditUI::reload()
 
108
{
 
109
    // Nothing?
 
110
}
 
111
 
 
112
void
 
113
SkinPreeditUI::update_preedit_string(const char* utf_str)
 
114
{
 
115
    skin_label_set_text(preedit_label_, utf_str);
 
116
    adjust_size();
 
117
}
 
118
 
 
119
#define BUFSIZE (4096*2)
 
120
 
 
121
void
 
122
SkinPreeditUI::update_candidates_string(const char* utf_str)
 
123
{
 
124
    skin_label_set_text(candidate_label_, utf_str);
 
125
    adjust_size();
 
126
}
 
127
 
 
128
void
 
129
SkinPreeditUI::adjust_size()
 
130
{
 
131
    if (candidate_label_->layout && preedit_label_->layout) {
 
132
        int x = 0, y = 0;
 
133
        int can_wid = 0, pre_wid = 0, width = 0, height = 0;
 
134
        int hmargin, vmargin;
 
135
        hmargin = info_->candidate_label.x + info_->right;
 
136
        vmargin = info_->candidate_label.y + info_->bottom;
 
137
 
 
138
        pango_layout_get_pixel_size(preedit_label_->layout, &pre_wid, NULL);
 
139
        pango_layout_get_pixel_size(candidate_label_->layout, &can_wid,
 
140
                                    &height);
 
141
        width = MAX(pre_wid, can_wid);
 
142
 
 
143
        gtk_window_resize(GTK_WINDOW(main_wnd_->widget), width + hmargin,
 
144
                          height + vmargin);
 
145
        gtk_window_get_position(GTK_WINDOW(main_wnd_->widget), &x, &y);
 
146
        internal_move(x, y);
 
147
    }
 
148
}