Rename the hash table to thumbs_hash_table.
[gliv.git] / src / help.c
blob54cbaf353cab43fafd360173a853337ad03e62ca
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * See the COPYING file for license information.
18 * Guillaume Chazarain <guichaz@yahoo.fr>
21 /****************************
22 * The help and about boxes *
23 ****************************/
25 #include <string.h> /* strlen() */
27 #include "gliv.h"
28 #include "help.h"
29 #include "about.h"
30 #include "options.h"
31 #include "params.h"
32 #include "help_text.h"
33 #include "windows.h"
35 extern rt_struct *rt;
37 static GtkWindow *help_win;
39 static gchar *get_help_text(void)
41 gchar **help_lines, **ptr;
42 gchar *res, *res_ptr;
43 int len = 0;
45 help_lines = get_help_lines();
47 /* Compute the total text length. */
48 for (ptr = help_lines; *ptr != NULL; ptr++)
49 len += strlen(*ptr);
51 res_ptr = res = g_new(gchar, len + 1);
53 /* Concatenate the lines. */
54 for (ptr = help_lines; *ptr != NULL; ptr++)
55 res_ptr = g_stpcpy(res_ptr, *ptr);
57 g_free(help_lines);
59 return res;
62 /* Get a textual widget with the help text in it. */
63 static GtkWidget *get_text_widget(const gchar * text)
65 GtkTextView *widget;
67 widget = GTK_TEXT_VIEW(gtk_text_view_new());
69 gtk_text_view_set_editable(widget, FALSE);
70 gtk_text_view_set_cursor_visible(widget, FALSE);
71 gtk_text_view_set_wrap_mode(widget, GTK_WRAP_WORD);
72 gtk_text_buffer_set_text(gtk_text_view_get_buffer(widget), text, -1);
74 return GTK_WIDGET(widget);
77 static void show_help(void)
79 PangoFontDescription *font;
80 gchar *help_text;
81 GtkWidget *widget;
82 GtkScrolledWindow *win;
84 help_text = get_help_text();
86 widget = get_text_widget(help_text);
87 g_free(help_text);
89 /* We use a fixed font to keep the alignment as in the README file. */
90 font = pango_font_description_from_string(FONT);
91 gtk_widget_modify_font(GTK_WIDGET(widget), font);
93 /* The window containing the text. */
94 win = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL));
95 gtk_scrolled_window_set_policy(win,
96 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
98 gtk_container_add(GTK_CONTAINER(win), widget);
100 /* The help window. */
101 help_win = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
102 gtk_window_set_default_size(help_win, 500, 500);
104 gtk_container_add(GTK_CONTAINER(help_win), GTK_WIDGET(win));
106 g_signal_connect(help_win, "delete-event", G_CALLBACK(toggle_help), NULL);
108 show_dialog(GTK_WIDGET(help_win), _("GLiv help"));
111 gboolean toggle_help(void)
113 rt->help ^= TRUE;
115 if (rt->help)
116 show_help();
117 else
118 gtk_widget_destroy(GTK_WIDGET(help_win));
120 return TRUE;
123 static gboolean delete_about_box(GtkWindow ** about_win)
125 if (about_win)
126 *about_win = NULL;
128 return FALSE;
131 void show_about_box(void)
133 static GtkWindow *about_win = NULL;
134 GtkLabel *about;
135 gchar *about_text;
137 if (about_win != NULL)
138 /* About box currently displayed. */
139 gtk_widget_destroy(GTK_WIDGET(about_win));
141 about_text = g_strconcat(_(ABOUT_GLIV), " ", VERSION, "\n",
142 "Guillaume Chazarain <guichaz@yahoo.fr>\n",
143 _(ABOUT_HELP), "\n",
144 "\n",
145 _(ABOUT_URL), "\n",
146 "\n", _(ABOUT_CLICK_HIDE), NULL);
148 about = GTK_LABEL(gtk_label_new(about_text));
149 g_free(about_text);
151 about_win = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
153 gtk_container_add(GTK_CONTAINER(about_win), GTK_WIDGET(about));
154 gtk_container_set_border_width(GTK_CONTAINER(about_win), 10);
156 gtk_widget_set_events(GTK_WIDGET(about_win), GDK_BUTTON_PRESS_MASK);
158 g_signal_connect(about_win, "button-press-event",
159 G_CALLBACK(gtk_widget_destroy), NULL);
161 g_signal_connect_swapped(about_win, "delete-event",
162 G_CALLBACK(delete_about_box), &about_win);
164 show_dialog(GTK_WIDGET(about_win), _("GLiv about box"));