~ubuntu-branches/ubuntu/precise/hime/precise

« back to all changes in this revision

Viewing changes to src/modules/win-int.c

  • Committer: Package Import Robot
  • Author(s): Yao Wei (魏銘廷)
  • Date: 2012-01-14 00:24:08 UTC
  • Revision ID: package-import@ubuntu.com-20120114002408-e79gagbeg1rt8npv
Tags: upstream-0.9.9
Import upstream version 0.9.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2011 Edward Der-Hua Liu, Hsin-Chu, Taiwan
 
2
 *
 
3
 * This library is free software; you can redistribute it and/or
 
4
 * modify it under the terms of the GNU Lesser General Public
 
5
 * License as published by the Free Software Foundation; either
 
6
 * version 2.1 of the License, or (at your option) any later version.
 
7
 *
 
8
 * This library is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public
 
14
 * License along with this library; if not, write to the Free Software
 
15
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
16
 */
 
17
 
 
18
#include "hime.h"
 
19
#include "intcode.h"
 
20
#include "pho.h"
 
21
#include "gst.h"
 
22
#include "im-client/hime-im-client-attr.h"
 
23
#include "hime-module.h"
 
24
#include "hime-module-cb.h"
 
25
 
 
26
GtkWidget *gwin_int;
 
27
extern HIME_module_main_functions gmf;
 
28
extern int current_intcode;
 
29
void module_show_win();
 
30
 
 
31
static GtkWidget *button_int;
 
32
static GtkWidget *labels_int[MAX_INTCODE];
 
33
 
 
34
static struct {
 
35
  char *name;
 
36
} int_sel[]={
 
37
  {"Big5"},
 
38
  {"UTF-32(U+)"},
 
39
};
 
40
static int int_selN = sizeof(int_sel)/sizeof(int_sel[0]);
 
41
 
 
42
static GtkWidget *opt_int_opts;
 
43
 
 
44
static void minimize_win()
 
45
{
 
46
  gtk_window_resize(GTK_WINDOW(gwin_int), 1, 1);
 
47
}
 
48
 
 
49
static void adj_intcode_buttons()
 
50
{
 
51
  int i;
 
52
 
 
53
  if (current_intcode==INTCODE_UTF32) {
 
54
    for(i=4;i < MAX_INTCODE; i++)
 
55
      gtk_widget_show(labels_int[i]);
 
56
  } else {
 
57
    for(i=4;i < MAX_INTCODE; i++)
 
58
      gtk_widget_hide(labels_int[i]);
 
59
  }
 
60
 
 
61
  minimize_win();
 
62
}
 
63
 
 
64
 
 
65
static void cb_select( GtkWidget *widget, gpointer data)
 
66
{
 
67
  current_intcode = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
 
68
  adj_intcode_buttons();
 
69
}
 
70
 
 
71
static GtkWidget *create_int_opts()
 
72
{
 
73
 
 
74
  GtkWidget *hbox = gtk_hbox_new (FALSE, 1);
 
75
 
 
76
  opt_int_opts = gtk_combo_box_new_text ();
 
77
  gtk_box_pack_start (GTK_BOX (hbox), opt_int_opts, FALSE, FALSE, 0);
 
78
 
 
79
  int i;
 
80
  for(i=0; i < int_selN; i++) {
 
81
    gtk_combo_box_append_text (GTK_COMBO_BOX_TEXT (opt_int_opts), int_sel[i].name);
 
82
  }
 
83
 
 
84
  gtk_combo_box_set_active (GTK_COMBO_BOX (opt_int_opts), current_intcode);
 
85
  g_signal_connect (G_OBJECT (opt_int_opts), "changed", G_CALLBACK (cb_select), NULL);
 
86
 
 
87
  return hbox;
 
88
}
 
89
 
 
90
 
 
91
void disp_int(int index, char *intcode)
 
92
{
 
93
  gtk_label_set_text(GTK_LABEL(labels_int[index]), intcode);
 
94
}
 
95
 
 
96
static unich_t full_space[] = " ";
 
97
 
 
98
void clear_int_code(int index)
 
99
{
 
100
  gtk_label_set_text(GTK_LABEL(labels_int[index]), _(full_space));
 
101
}
 
102
 
 
103
 
 
104
void clear_int_code_all()
 
105
{
 
106
  int i;
 
107
 
 
108
  for(i=0; i < MAX_INTCODE; i++)
 
109
    clear_int_code(i);
 
110
}
 
111
 
 
112
void module_hide_win()
 
113
{
 
114
  if (!gwin_int)
 
115
    return;
 
116
  gtk_widget_hide(gwin_int);
 
117
  dbg("hide_win_int\n");
 
118
}
 
119
 
 
120
extern gboolean force_show;
 
121
extern int intcode_cin;
 
122
 
 
123
void module_move_win(int x, int y)
 
124
{
 
125
  if (!gwin_int)
 
126
    return;
 
127
 
 
128
//  dbg("move_win_int %d %d\n",x,y);
 
129
 
 
130
  gtk_window_get_size(GTK_WINDOW(gwin_int), gmf.mf_win_xl, gmf.mf_win_yl);
 
131
 
 
132
  if (x + *gmf.mf_win_xl > *gmf.mf_dpy_xl)
 
133
    x = *gmf.mf_dpy_xl - *gmf.mf_win_xl;
 
134
  if (x < 0)
 
135
    x = 0;
 
136
 
 
137
  if (y + *gmf.mf_win_yl > *gmf.mf_dpy_yl)
 
138
    y = *gmf.mf_dpy_yl - *gmf.mf_win_yl;
 
139
  if (y < 0)
 
140
    y = 0;
 
141
 
 
142
  *gmf.mf_win_x = x;  *gmf.mf_win_y = y;
 
143
  gtk_window_move(GTK_WINDOW(gwin_int), x, y);
 
144
}
 
145
 
 
146
 
 
147
void create_win_intcode()
 
148
{
 
149
  if (gwin_int) {
 
150
    module_show_win();
 
151
    return;
 
152
  }
 
153
 
 
154
  gwin_int = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
155
  gtk_window_set_has_resize_grip(GTK_WINDOW(gwin_int), FALSE);
 
156
 
 
157
//  gtk_window_set_default_size(GTK_WINDOW (gwin_int), 1, 1);
 
158
  gtk_container_set_border_width (GTK_CONTAINER (gwin_int), 0);
 
159
 
 
160
 
 
161
  GtkWidget *frame = gtk_frame_new(NULL);
 
162
  gtk_container_set_border_width (GTK_CONTAINER (frame), 0);
 
163
  gtk_container_add (GTK_CONTAINER(gwin_int), frame);
 
164
 
 
165
 
 
166
  GtkWidget *hbox_top = gtk_hbox_new (FALSE, 0);
 
167
  gtk_container_add (GTK_CONTAINER (frame), hbox_top);
 
168
 
 
169
  GtkWidget *button_intcode = gtk_button_new_with_label(_("內碼"));
 
170
  g_signal_connect_swapped (GTK_OBJECT (button_intcode), "button_press_event",
 
171
        G_CALLBACK (gmf.mf_inmd_switch_popup_handler), NULL);
 
172
  gtk_box_pack_start (GTK_BOX (hbox_top), button_intcode, FALSE, FALSE, 0);
 
173
 
 
174
  button_int = gtk_button_new();
 
175
  gtk_container_set_border_width (GTK_CONTAINER (button_int), 0);
 
176
  gtk_box_pack_start (GTK_BOX (hbox_top), button_int, FALSE, FALSE, 0);
 
177
  GtkWidget *hbox_int = gtk_hbox_new (FALSE, 0);
 
178
  gtk_container_add (GTK_CONTAINER (button_int), hbox_int);
 
179
 
 
180
  int i;
 
181
  for(i=0; i < MAX_INTCODE;i ++) {
 
182
    GtkWidget *label = gtk_label_new(_(full_space));
 
183
    labels_int[i] = label;
 
184
    gtk_box_pack_start (GTK_BOX (hbox_int), label, FALSE, FALSE, 0);
 
185
    gmf.mf_set_label_font_size(label, *gmf.mf_hime_font_size);
 
186
  }
 
187
 
 
188
  GtkWidget *intsel = create_int_opts();
 
189
  gtk_box_pack_start (GTK_BOX (hbox_top), intsel, FALSE, FALSE, 0);
 
190
 
 
191
  gtk_widget_show_all (gwin_int);
 
192
 
 
193
  gtk_widget_realize (gwin_int);
 
194
  set_no_focus(gwin_int);
 
195
 
 
196
  adj_intcode_buttons();
 
197
  minimize_win();
 
198
 
 
199
//  dbg("create %x\n",gwin_int);
 
200
}
 
201
 
 
202
void module_show_win()
 
203
{
 
204
  if (!gwin_int) {
 
205
    create_win_intcode();
 
206
//    return;
 
207
  }
 
208
 
 
209
#if 0
 
210
  if (hime_pop_up_win && !intcode_cin && !force_show)
 
211
    return;
 
212
#endif
 
213
 
 
214
  if (!GTK_WIDGET_VISIBLE(gwin_int)) {
 
215
    gtk_widget_show(gwin_int);
 
216
  }
 
217
 
 
218
//  dbg("show_win_int %x\n", gwin_int);
 
219
  gtk_widget_show(gwin_int);
 
220
  module_move_win(*gmf.mf_win_x, *gmf.mf_win_y);
 
221
  gtk_window_present(GTK_WINDOW(gwin_int));
 
222
}
 
223
 
 
224
 
 
225
void module_win_geom()
 
226
{
 
227
  if (!gwin_int)
 
228
    return;
 
229
  gtk_window_get_position(GTK_WINDOW(gwin_int), gmf.mf_win_x, gmf.mf_win_y);
 
230
 
 
231
  gmf.mf_get_win_size(gwin_int, gmf.mf_win_xl, gmf.mf_win_yl);
 
232
}
 
233
 
 
234
 
 
235
int module_win_visible()
 
236
{
 
237
  return GTK_WIDGET_VISIBLE(gwin_int);
 
238
}
 
239
 
 
240
 
 
241
void module_change_font_size()
 
242
{
 
243
}