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"
41 SkinPreeditUI::SkinPreeditUI(std::string name) throw()
44 info_ = ui_skin_new(name.c_str());
46 throw SkinLoaderException();
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,
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);
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);
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);
71 SkinPreeditUI::~SkinPreeditUI()
73 ui_skin_destroy(info_);
74 skin_label_destroy(preedit_label_);
75 skin_label_destroy(candidate_label_);
76 skin_window_destroy(main_wnd_);
82 gtk_widget_show(main_wnd_->widget);
89 gtk_widget_hide(main_wnd_->widget);
93 SkinPreeditUI::move(int x, int y)
95 internal_move(x - info_->offset_x, y - info_->offset_y);
98 void SkinPreeditUI::internal_move(int x, int y)
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);
107 SkinPreeditUI::reload()
113 SkinPreeditUI::update_preedit_string(const char* utf_str)
115 skin_label_set_text(preedit_label_, utf_str);
119 #define BUFSIZE (4096*2)
122 SkinPreeditUI::update_candidates_string(const char* utf_str)
124 skin_label_set_text(candidate_label_, utf_str);
129 SkinPreeditUI::adjust_size()
131 if (candidate_label_->layout && preedit_label_->layout) {
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;
138 pango_layout_get_pixel_size(preedit_label_->layout, &pre_wid, NULL);
139 pango_layout_get_pixel_size(candidate_label_->layout, &can_wid,
141 width = MAX(pre_wid, can_wid);
143 gtk_window_resize(GTK_WINDOW(main_wnd_->widget), width + hmargin,
145 gtk_window_get_position(GTK_WINDOW(main_wnd_->widget), &x, &y);