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

« back to all changes in this revision

Viewing changes to wrapper/xim/sunpinyin_preedit_gtk.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
 
 
40
GtkPreeditUI::GtkPreeditUI()
 
41
    : PreeditUI("classic")
 
42
{
 
43
    main_wnd_ = ui_create_window();
 
44
    GtkWidget* box = gtk_vbox_new(FALSE, 1);
 
45
    gtk_container_add(GTK_CONTAINER(main_wnd_), box);
 
46
 
 
47
    preedit_area_ = gtk_label_new("");
 
48
    candidate_area_ = gtk_label_new("");
 
49
 
 
50
    gtk_misc_set_alignment(GTK_MISC(preedit_area_), 0, 0.5);
 
51
    gtk_misc_set_alignment(GTK_MISC(candidate_area_), 0, 0.5);
 
52
 
 
53
    gtk_box_pack_start(GTK_BOX(box), preedit_area_,
 
54
                       FALSE, FALSE, 1);
 
55
    gtk_box_pack_start(GTK_BOX(box), candidate_area_,
 
56
                       FALSE, FALSE, 1);
 
57
    gtk_widget_show_all(box);
 
58
 
 
59
    // set the colormap before realized the window
 
60
    GdkScreen* screen = gtk_widget_get_screen(main_wnd_);
 
61
    GdkColormap* cmap = gdk_screen_get_rgba_colormap(screen);
 
62
    if (cmap) {
 
63
        gtk_widget_set_colormap(main_wnd_, cmap);
 
64
    }
 
65
    gtk_widget_realize(main_wnd_);
 
66
}
 
67
 
 
68
GtkPreeditUI::~GtkPreeditUI()
 
69
{
 
70
    gtk_widget_destroy(main_wnd_);
 
71
}
 
72
 
 
73
void
 
74
GtkPreeditUI::show()
 
75
{
 
76
    gtk_widget_show(main_wnd_);
 
77
}
 
78
 
 
79
void
 
80
GtkPreeditUI::hide()
 
81
{
 
82
    gtk_widget_hide(main_wnd_);
 
83
}
 
84
 
 
85
void
 
86
GtkPreeditUI::move(int x, int y)
 
87
{
 
88
    int width = 0, height = 0;
 
89
    gtk_window_get_size(GTK_WINDOW(main_wnd_), &width, &height);
 
90
    adjust_position(&x, &y, width, height);
 
91
    gtk_window_move(GTK_WINDOW(main_wnd_), x, y);
 
92
}
 
93
 
 
94
void
 
95
GtkPreeditUI::reload()
 
96
{
 
97
    GdkColor color;
 
98
    varchar value;
 
99
    double opa = 1.0;
 
100
 
 
101
    settings_get(PREEDIT_COLOR, value);
 
102
    gdk_color_parse(value, &color);
 
103
    gtk_widget_modify_bg(main_wnd_, GTK_STATE_NORMAL, &color);
 
104
 
 
105
    settings_get(PREEDIT_FONT, value);
 
106
    gtk_widget_modify_font(candidate_area_,
 
107
                           pango_font_description_from_string(value));
 
108
 
 
109
    settings_get(PREEDIT_FONT_COLOR, value);
 
110
    gdk_color_parse(value, &color);
 
111
    gtk_widget_modify_fg(candidate_area_, GTK_STATE_NORMAL, &color);
 
112
    gtk_widget_modify_fg(preedit_area_, GTK_STATE_NORMAL, &color);
 
113
 
 
114
    settings_get(PREEDIT_OPACITY, &opa);
 
115
 
 
116
    // setting the opacity
 
117
    if (opa > 1.0) opa = 1.0;
 
118
    gtk_window_set_opacity(GTK_WINDOW(main_wnd_), opa);
 
119
}
 
120
 
 
121
void
 
122
GtkPreeditUI::update_preedit_string(const char* utf_str)
 
123
{
 
124
    gtk_label_set_text(GTK_LABEL(preedit_area_), utf_str);
 
125
}
 
126
 
 
127
void
 
128
GtkPreeditUI::update_candidates_string(const char* utf_str)
 
129
{
 
130
    gtk_label_set(GTK_LABEL(candidate_area_), utf_str);
 
131
 
 
132
    PangoLayout* pre_lay = gtk_label_get_layout(GTK_LABEL(preedit_area_));
 
133
    PangoLayout* can_lay = gtk_label_get_layout(GTK_LABEL(candidate_area_));
 
134
    int x = 0, y = 0;
 
135
    int pre_wid = -1, can_wid = -1;
 
136
    pango_layout_get_pixel_size(pre_lay, &pre_wid, NULL);
 
137
    pango_layout_get_pixel_size(can_lay, &can_wid, NULL);
 
138
 
 
139
    gtk_window_resize(GTK_WINDOW(main_wnd_), MAX(pre_wid, can_wid) + 1, 1);
 
140
 
 
141
    gtk_window_get_position(GTK_WINDOW(main_wnd_), &x, &y);
 
142
    move(x, y);
 
143
}
 
144