1 /* Copyright (C) 2001-2004 Kenichi Suto
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program 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
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18 #include "defs.h"
19 #include "global.h"
20
21 #include "dictbar.h"
22 #include "statusbar.h"
23 #include "history.h"
24 #include "ebview.h"
25 #include "eb.h"
26 #include "jcode.h"
27
28 #ifndef __WIN32__
29 #include <gdk/gdkx.h>
30 #endif
31
32 extern GList *group_list;
33 extern GtkWidget *combo_group;
34 extern GtkWidget *combo_dirgroup;
35 extern GtkWidget *word_entry;
36
next_dict_group()37 void next_dict_group(){
38
39 GtkTreeIter iter;
40 gchar *title;
41 gboolean active;
42 gint method;
43
44 method = ebook_search_method();
45
46 if(method == SEARCH_METHOD_GREP)
47 goto GREP;
48
49 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dict_store), &iter) == TRUE){
50 do {
51 gtk_tree_model_get(GTK_TREE_MODEL(dict_store),
52 &iter,
53 DICT_ACTIVE_COLUMN, &active,
54 -1);
55 if(active == TRUE)
56 break;
57
58 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(dict_store), &iter) == TRUE);
59 } else {
60 return;
61 }
62
63 if(gtk_tree_model_iter_next(GTK_TREE_MODEL(dict_store), &iter) == FALSE)
64 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dict_store), &iter);
65
66 gtk_tree_model_get(GTK_TREE_MODEL(dict_store),
67 &iter,
68 DICT_TITLE_COLUMN, &title,
69 -1);
70
71 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo_group)->entry), title);
72
73 g_free(title);
74
75 /*
76 if((method == SEARCH_METHOD_INTERNET) || (method == SEARCH_METHOD_GREP)){
77 select_any_search();
78 }
79 */
80 return;
81
82 GREP:
83
84 title = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_dirgroup)->entry));
85 if(strcmp(title, _("Manual Select")) == 0){
86 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dirgroup_store), &iter);
87 gtk_tree_model_get(GTK_TREE_MODEL(dirgroup_store),
88 &iter,
89 DIRGROUP_TITLE_COLUMN, &title,
90 -1);
91
92 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo_dirgroup)->entry), title);
93 g_free(title);
94
95 return;
96 }
97
98 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dirgroup_store), &iter) == TRUE){
99 do {
100 gtk_tree_model_get(GTK_TREE_MODEL(dirgroup_store),
101 &iter,
102 DIRGROUP_ACTIVE_COLUMN, &active,
103 -1);
104 if(active == TRUE)
105 break;
106
107 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(dirgroup_store), &iter) == TRUE);
108 } else {
109 return;
110 }
111
112 if(gtk_tree_model_iter_next(GTK_TREE_MODEL(dirgroup_store), &iter) == FALSE) {
113 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo_dirgroup)->entry), _("Manual Select"));
114 } else {
115 gtk_tree_model_get(GTK_TREE_MODEL(dirgroup_store),
116 &iter,
117 DIRGROUP_TITLE_COLUMN, &title,
118 -1);
119
120 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo_dirgroup)->entry), title);
121 g_free(title);
122 }
123 }
124
previous_dict_group()125 void previous_dict_group(){
126
127 GtkTreeIter previous_iter;
128 GtkTreeIter iter;
129 gboolean active;
130 gchar *title=NULL;
131 gint i;
132 gint method;
133
134 method = ebook_search_method();
135
136 if(method == SEARCH_METHOD_GREP)
137 goto GREP;
138
139 i = 0;
140 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dict_store), &iter) == TRUE){
141 do {
142 gtk_tree_model_get(GTK_TREE_MODEL(dict_store),
143 &iter,
144 DICT_ACTIVE_COLUMN, &active,
145 -1);
146 if(active == TRUE)
147 break;
148
149 previous_iter = iter;
150 i++;
151 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(dict_store), &iter) == TRUE);
152 } else {
153 return;
154 }
155
156 if(i != 0){
157 gtk_tree_model_get(GTK_TREE_MODEL(dict_store),
158 &previous_iter,
159 DICT_TITLE_COLUMN, &title,
160 -1);
161
162 } else {
163 gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dict_store), &iter);
164 do {
165 g_free(title);
166 gtk_tree_model_get(GTK_TREE_MODEL(dict_store),
167 &iter,
168 DICT_TITLE_COLUMN, &title,
169 -1);
170 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(dict_store), &iter) == TRUE);
171 }
172
173 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo_group)->entry), title);
174
175 g_free(title);
176
177 /*
178 if((method == SEARCH_METHOD_INTERNET) || (method == SEARCH_METHOD_GREP)){
179 select_any_search();
180 }
181 */
182
183 return;
184
185 GREP:
186
187 //
188 title = (gchar *)gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_dirgroup)->entry));
189 if(strcmp(title, _("Manual Select")) == 0){
190 title = NULL;
191 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dirgroup_store), &iter) == TRUE){
192 do {
193 g_free(title);
194 gtk_tree_model_get(GTK_TREE_MODEL(dirgroup_store),
195 &iter,
196 DIRGROUP_TITLE_COLUMN, &title,
197 -1);
198 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(dirgroup_store), &iter) == TRUE);
199 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo_dirgroup)->entry), title);
200 g_free(title);
201 }
202
203 return;
204 }
205
206
207 i = 0;
208 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dirgroup_store), &iter) == TRUE){
209 do {
210 gtk_tree_model_get(GTK_TREE_MODEL(dirgroup_store),
211 &iter,
212 DIRGROUP_ACTIVE_COLUMN, &active,
213 -1);
214 if(active == TRUE)
215 break;
216
217 previous_iter = iter;
218 i++;
219 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(dirgroup_store), &iter) == TRUE);
220 } else {
221 return;
222 }
223
224 if(i != 0){
225 gtk_tree_model_get(GTK_TREE_MODEL(dirgroup_store),
226 &previous_iter,
227 DIRGROUP_TITLE_COLUMN, &title,
228 -1);
229
230 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo_dirgroup)->entry), title);
231 g_free(title);
232
233 } else {
234 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo_dirgroup)->entry), _("Manual Select"));
235 }
236
237 }
238
239 extern GtkWidget *dict_box;
240
toggle_dictionary(gint number)241 void toggle_dictionary(gint number){
242 GList *children, *child;
243 GtkWidget *w;
244 gint idx;
245 gboolean active;
246
247 children = gtk_container_get_children(GTK_CONTAINER(dict_box));
248
249 idx = 0;
250 child = g_list_first(children);
251 while(child != NULL){
252 w = (GtkWidget *)(child->data);
253 if(GTK_IS_BUTTON(w)){
254 if((number - 1) == idx){
255 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
256 if(active == TRUE)
257 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), FALSE);
258 else
259 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), TRUE);
260 break;
261 }
262 else
263 idx ++;
264 }
265 child = g_list_next(child);
266 }
267 }
268
toggle_dictionary1()269 void toggle_dictionary1(){
270 toggle_dictionary(1);
271 }
272
toggle_dictionary2()273 void toggle_dictionary2(){
274 toggle_dictionary(2);
275 }
276
toggle_dictionary3()277 void toggle_dictionary3(){
278 toggle_dictionary(3);
279 }
280
toggle_dictionary4()281 void toggle_dictionary4(){
282 toggle_dictionary(4);
283 }
284
toggle_dictionary5()285 void toggle_dictionary5(){
286 toggle_dictionary(5);
287 }
288
toggle_dictionary6()289 void toggle_dictionary6(){
290 toggle_dictionary(6);
291 }
292
toggle_dictionary7()293 void toggle_dictionary7(){
294 toggle_dictionary(7);
295 }
296
toggle_dictionary8()297 void toggle_dictionary8(){
298 toggle_dictionary(8);
299 }
300
toggle_dictionary9()301 void toggle_dictionary9(){
302 toggle_dictionary(9);
303 }
304
toggle_dictionary10()305 void toggle_dictionary10(){
306 toggle_dictionary(10);
307 }
308
go_back()309 void go_back(){
310 history_back();
311 }
312
go_forward()313 void go_forward(){
314 history_forward();
315 }
316
clear_word()317 void clear_word(){
318 gtk_entry_set_text(GTK_ENTRY(word_entry), "");
319 gtk_widget_grab_focus(word_entry);
320 }
321
quit()322 void quit(){
323 exit_program(NULL, NULL);
324 }
325
iconify()326 void iconify(){
327 #ifdef __WIN32__
328 #else
329 XIconifyWindow (GDK_DISPLAY (),
330 GDK_WINDOW_XWINDOW(main_window->window),
331 DefaultScreen (GDK_DISPLAY ()));
332 #endif
333 }
334
paste_from_clipboard()335 void paste_from_clipboard()
336 {
337 #ifdef __WIN32__
338 HWND hwnd;
339 LRESULT retval;
340 HANDLE hText;
341 char *pText;
342 gchar *str;
343 #else
344 gchar *str=NULL;
345 GtkClipboard* clipboard;
346 #endif
347 gint position;
348 gint start, end;
349
350 LOG(LOG_DEBUG, "IN : paste_clipboard()");
351
352 #ifdef __WIN32__
353 hwnd = GDK_WINDOW_HWND (main_window->window);
354 OpenClipboard(hwnd);
355 hText = GetClipboardData(CF_TEXT);
356 if(hText == NULL) {
357 CloseClipboard();
358 LOG(LOG_DEBUG, "OUT : paste_clipboard() : NOP");
359 return;
360 } else {
361 pText = GlobalLock(hText);
362 GlobalUnlock(hText);
363
364 str = iconv_convert(fs_codeset, "utf-8", pText);
365 CloseClipboard();
366 }
367 #else
368 clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
369 str = gtk_clipboard_wait_for_text(clipboard);
370 if(str == NULL){
371 LOG(LOG_DEBUG, "OUT : paste_clipboard() : NOP");
372 return;
373 }
374
375 #endif
376 gtk_editable_get_selection_bounds(GTK_EDITABLE(word_entry), &start, &end);
377 gtk_editable_delete_text(GTK_EDITABLE(word_entry), start, end);
378
379 position = gtk_editable_get_position(GTK_EDITABLE(word_entry));
380 gtk_editable_insert_text(GTK_EDITABLE(word_entry), str, strlen(str), &position);
381 gtk_editable_set_position(GTK_EDITABLE(word_entry), position);
382 g_free(str);
383
384 LOG(LOG_DEBUG, "OUT : paste_clipboard()");
385
386 }
387