2 * Copyright (c) 2010 Mike Qin <mikeandmore@gmail.com>
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
15 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
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.
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.
38 #include "sunpinyin_preedit_ui.h"
40 GtkPreeditUI::GtkPreeditUI()
41 : PreeditUI("classic")
43 main_wnd_ = ui_create_window();
44 GtkWidget* box = gtk_vbox_new(FALSE, 1);
45 gtk_container_add(GTK_CONTAINER(main_wnd_), box);
47 preedit_area_ = gtk_label_new("");
48 candidate_area_ = gtk_label_new("");
50 gtk_misc_set_alignment(GTK_MISC(preedit_area_), 0, 0.5);
51 gtk_misc_set_alignment(GTK_MISC(candidate_area_), 0, 0.5);
53 gtk_box_pack_start(GTK_BOX(box), preedit_area_,
55 gtk_box_pack_start(GTK_BOX(box), candidate_area_,
57 gtk_widget_show_all(box);
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);
63 gtk_widget_set_colormap(main_wnd_, cmap);
65 gtk_widget_realize(main_wnd_);
68 GtkPreeditUI::~GtkPreeditUI()
70 gtk_widget_destroy(main_wnd_);
76 gtk_widget_show(main_wnd_);
82 gtk_widget_hide(main_wnd_);
86 GtkPreeditUI::move(int x, int y)
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);
95 GtkPreeditUI::reload()
101 settings_get(PREEDIT_COLOR, value);
102 gdk_color_parse(value, &color);
103 gtk_widget_modify_bg(main_wnd_, GTK_STATE_NORMAL, &color);
105 settings_get(PREEDIT_FONT, value);
106 gtk_widget_modify_font(candidate_area_,
107 pango_font_description_from_string(value));
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);
114 settings_get(PREEDIT_OPACITY, &opa);
116 // setting the opacity
117 if (opa > 1.0) opa = 1.0;
118 gtk_window_set_opacity(GTK_WINDOW(main_wnd_), opa);
122 GtkPreeditUI::update_preedit_string(const char* utf_str)
124 gtk_label_set_text(GTK_LABEL(preedit_area_), utf_str);
128 GtkPreeditUI::update_candidates_string(const char* utf_str)
130 gtk_label_set(GTK_LABEL(candidate_area_), utf_str);
132 PangoLayout* pre_lay = gtk_label_get_layout(GTK_LABEL(preedit_area_));
133 PangoLayout* can_lay = gtk_label_get_layout(GTK_LABEL(candidate_area_));
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);
139 gtk_window_resize(GTK_WINDOW(main_wnd_), MAX(pre_wid, can_wid) + 1, 1);
141 gtk_window_get_position(GTK_WINDOW(main_wnd_), &x, &y);