1 /*
2 * menu.c popup menu
3 *
4 * Copyright (C) 2000- Masaki Chikama (Wren) <masaki-c@is.aist-nara.ac.jp>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21 /* $Id: menu.c,v 1.14 2002/09/18 13:16:22 chikama Exp $ */
22
23 #include <stdio.h>
24 #include <gtk/gtk.h>
25 #include <string.h>
26
27 #include "portab.h"
28 #include "menu.h"
29 #include "menu_gui.h"
30 #include "menu_callback.h"
31 #include "nact.h"
32 #include "imput.h"
33 #include "music.h"
34
35
36 #ifndef GTK_CHECK_VERSION
37 #define GTK_CHECK_VERSION(major,minor,micro) \
38 (GTK_MAJOR_VERSION > (major) || \
39 (GTK_MAJOR_VERSION == (major) && GTK_MINOR_VERSION > (minor)) || \
40 (GTK_MAJOR_VERSION == (major) && GTK_MINOR_VERSION == (minor) && \
41 GTK_MICRO_VERSION >= (micro)))
42 #endif /* !GTK_CHECK_VERSION */
43
44 #if defined (GTK_CHECK_VERSION) && GTK_CHECK_VERSION (1,2,0)
45 #define GTKV12
46 #else
47 #define GTKV10
48 #endif
49
50 static boolean menu_initilized = FALSE;
51
menu_callback()52 static int menu_callback() {
53 sys_getInputInfo();
54 return TRUE;
55 }
56
57
menu_open(void)58 void menu_open(void) {
59 if (!menu_initilized) return;
60
61 #ifdef GTKV12
62 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(menu_item_msgskip_on), get_skipMode());
63 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(menu_item_msgskip_off), !get_skipMode());
64 #else
65 gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM(menu_item_msgskip_on), get_skipMode());
66 gtk_check_menu_item_set_state (GTK_CHECK_MENU_ITEM(menu_item_msgskip_off), !get_skipMode());
67 #endif
68 gtk_menu_popup(GTK_MENU(menu_window_popup), NULL, NULL, NULL, NULL, 0, 100);
69 gtk_widget_show(menu_window_popup);
70 nact->popupmenu_opened = TRUE;
71 }
72
menu_quitmenu_open(void)73 void menu_quitmenu_open(void) {
74 if (!menu_initilized) return;
75
76 gtk_widget_show(menu_window_exit);
77 nact->popupmenu_opened = TRUE;
78 }
79
menu_inputstring(INPUTSTRING_PARAM * p)80 boolean menu_inputstring(INPUTSTRING_PARAM *p) {
81 char s[256];
82 guint i;
83
84 if (!menu_initilized) return FALSE;
85
86 menu_ok_input = FALSE;
87 gtk_label_set(GTK_LABEL(menu_label_inputstring_title), p->title);
88
89 sprintf(s, _("MAX %d charater"), p->max);
90 gtk_label_set(GTK_LABEL(menu_label_inputstring_maxchar), strdup(s));
91
92 gtk_entry_set_max_length(GTK_ENTRY(menu_textentry), p->max *2);
93 gtk_entry_set_text(GTK_ENTRY(menu_textentry), p->oldstring);
94
95 gtk_widget_show(menu_window_is);
96
97 i = gtk_idle_add(menu_callback, menu_window_is);
98 gtk_main();
99 gtk_idle_remove(i);
100
101 if (menu_ok_input) {
102 p->newstring = menu_textentry_string;
103 } else {
104 p->newstring = p->oldstring;
105 }
106 return TRUE;
107 }
108
menu_inputstring2(INPUTSTRING_PARAM * p)109 boolean menu_inputstring2(INPUTSTRING_PARAM *p) {
110 guint i;
111
112 if (!menu_initilized) return FALSE;
113
114 menu_ok_input = FALSE;
115 gtk_entry_set_max_length(GTK_ENTRY(menu_textentry2), p->max *2);
116 gtk_entry_set_text(GTK_ENTRY(menu_textentry2), p->oldstring);
117 gtk_widget_set_usize (menu_textentry2, p->h * p->max + 8, p->h + 4);
118
119 gtk_widget_show(menu_window_is2);
120
121 i = gtk_idle_add(menu_callback, menu_window_is2);
122 gtk_main();
123 gtk_idle_remove(i);
124
125 if (menu_ok_input) {
126 p->newstring = menu_textentry_string;
127 } else {
128 p->newstring = p->oldstring;
129 }
130 return TRUE;
131 }
132
menu_inputnumber(INPUTNUM_PARAM * p)133 boolean menu_inputnumber(INPUTNUM_PARAM *p) {
134 GtkObject *adj;
135 char s[256];
136 gint i;
137
138 if (!menu_initilized) return FALSE;
139
140 menu_ok_input = FALSE;
141
142 gtk_window_set_title (GTK_WINDOW(menu_window_in), p->title);
143 sprintf(s, "%d ", p->max);
144 gtk_label_set(GTK_LABEL(menu_label_inputnum_max), s);
145 sprintf(s, "%d ", p->min);
146 gtk_label_set(GTK_LABEL(menu_label_inputnum_min), s);
147 sprintf(s, "%d ", p->def);
148 gtk_label_set(GTK_LABEL(menu_label_inputnum_def), s);
149
150 adj = gtk_adjustment_new (p->def, p->min, p->max, 1, 1, 1);
151 gtk_spin_button_set_adjustment(GTK_SPIN_BUTTON(menu_spinbutton), GTK_ADJUSTMENT(adj));
152 /* �������ʤ������� value ��ɽ������� */
153 gtk_spin_button_set_value(GTK_SPIN_BUTTON(menu_spinbutton), p->def);
154
155 gtk_widget_show(menu_window_in);
156
157 i = gtk_idle_add(menu_callback, menu_window_in);
158 gtk_main();
159 gtk_idle_remove(i);
160
161 if (menu_ok_input) {
162 p->value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(menu_spinbutton));
163 } else {
164 p->value = -1;
165 }
166 return TRUE;
167 }
168
menu_msgbox_open(char * msg)169 void menu_msgbox_open(char *msg) {
170 guint i;
171 if (!menu_initilized) return;
172
173 gtk_label_set(GTK_LABEL(menu_label_msgbox), msg);
174 gtk_widget_show(menu_window_msgbox);
175 i = gtk_idle_add((GtkFunction)sys_getInputInfo, menu_window_msgbox);
176 gtk_main();
177 gtk_idle_remove(i);
178 }
179
menu_init()180 void menu_init() {
181 menu_initilized = TRUE;
182 menu_window_popup = create_menu1();
183 menu_window_in = create_window1();
184 menu_window_is = create_window2();
185 menu_window_exit = create_window3();
186 menu_window_about = create_window4();
187 menu_window_is2 = create_window5();
188 menu_window_msgbox= create_window6();
189 }
190
menu_widget_reinit(boolean reset_colortmap)191 void menu_widget_reinit(boolean reset_colortmap) {
192 static GdkColor col[256];
193 static GdkVisual* vis;
194 static GdkColormap* cm;
195 int i;
196
197 if (reset_colortmap) {
198 vis = gdk_visual_get_system();
199 cm = gdk_colormap_new(vis, TRUE);
200 }
201 if (vis == NULL) return;
202 if (vis->type != GDK_VISUAL_PSEUDO_COLOR) return;
203
204 for (i = 0; i < 256; i++) {
205 col[i].pixel = i;
206 col[i].red = nact->sys_pal->red[i] * 257;
207 col[i].green = nact->sys_pal->green[i] * 257;
208 col[i].blue = nact->sys_pal->blue[i] * 257;
209 }
210 gdk_colors_store(cm, col, 256);
211 gtk_widget_set_default_colormap(cm);
212
213 /* reconstruct widget */
214 menu_init();
215 }
216
menu_gtkmainiteration()217 void menu_gtkmainiteration() {
218 if (!menu_initilized) return;
219
220 while (gtk_events_pending()) {
221 gtk_main_iteration();
222 menu_callback();
223 }
224 }
225