annotate src/ui_help.c @ 516:b7e99bfeadc9

Convert the minority of while() to while ().
author zas_
date Thu, 24 Apr 2008 15:49:57 +0000
parents 985fdfebd89e
children 20495dd4e6e6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
2 * (SLIK) SimpLIstic sKin functions
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
3 * (C) 2004 John Ellis
475
48c8e49b571c updated copyright in source files
nadvornik
parents: 446
diff changeset
4 * Copyright (C) 2008 The Geeqie Team
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13 #ifdef HAVE_CONFIG_H
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 # include "config.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include "intl.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include <stdio.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include <stdlib.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include <string.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 #include <gtk/gtk.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23
289
6a7298988a7a Simplify and unify gtk_window creation with the help of
zas_
parents: 9
diff changeset
24 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25 #include "ui_help.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
28 #include "ui_misc.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31 #define HELP_WINDOW_WIDTH 620
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32 #define HELP_WINDOW_HEIGHT 350
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 * 'help' window
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 #define SCROLL_MARKNAME "scroll_point"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 static void help_window_scroll(GtkWidget *text, const gchar *key)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 gchar *needle;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 GtkTextBuffer *buffer;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 GtkTextIter iter;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 GtkTextIter start, end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 if (!text || !key) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 needle = g_strdup_printf("[section:%s]", key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55 gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 if (gtk_text_iter_forward_search(&iter, needle, GTK_TEXT_SEARCH_TEXT_ONLY,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 &start, &end, NULL))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 gint line;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61 GtkTextMark *mark;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63 line = gtk_text_iter_get_line(&start);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 gtk_text_buffer_get_iter_at_line_offset(buffer, &iter, line, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65 gtk_text_buffer_place_cursor(buffer, &iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67 #if 0
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(text), &iter, 0.0, TRUE, 0, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 /* apparently only scroll_to_mark works when the textview is not visible yet */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 /* if mark exists, move it instead of creating one for every scroll */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 mark = gtk_text_buffer_get_mark(buffer, SCROLL_MARKNAME);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 if (mark)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77 gtk_text_buffer_move_mark(buffer, mark, &iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 mark = gtk_text_buffer_create_mark(buffer, SCROLL_MARKNAME, &iter, FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(text), mark, 0.0, TRUE, 0, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 g_free(needle);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 static void help_window_load_text(GtkWidget *text, const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 gchar s_buf[1024];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 GtkTextBuffer *buffer;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 GtkTextIter iter;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 GtkTextIter start, end;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 if (!text || !path) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 gtk_text_buffer_get_bounds(buffer, &start, &end);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 gtk_text_buffer_delete(buffer, &start, &end);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 f = fopen(pathl, "r");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110 if (!f)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
112 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 buf = g_strdup_printf(_("Unable to load:\n%s"), path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114 gtk_text_buffer_insert(buffer, &iter, buf, -1);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119 while (fgets(s_buf, sizeof(s_buf), f))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121 gchar *buf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122 gint l;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 l = strlen(s_buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 if (!g_utf8_validate(s_buf, l, NULL))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 buf = g_locale_to_utf8(s_buf, strlen(s_buf), NULL, NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129 if (!buf) buf = g_strdup("\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 buf = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136 (buf) ? buf : s_buf, -1,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 "monospace", NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 g_free(buf);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140 fclose(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143 gtk_text_buffer_get_iter_at_offset(buffer, &iter, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144 gtk_text_buffer_place_cursor(buffer, &iter);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(text), &iter, 0.0, TRUE, 0, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 static gint help_window_delete_cb(GtkWidget *widget, GdkEventAny *event, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150 gtk_widget_destroy(widget);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 static void help_window_close(GtkWidget *widget, gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 GtkWidget *window = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 gtk_widget_destroy(window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160 void help_window_set_key(GtkWidget *window, const gchar *key)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 GtkWidget *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164 if (!window) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 text = g_object_get_data(G_OBJECT(window), "text_widget");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 if (!text) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 gdk_window_raise(window->window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 if (key) help_window_scroll(text, key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174 void help_window_set_file(GtkWidget *window, const gchar *path, const gchar *key)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 GtkWidget *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 if (!window || !path) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 text = g_object_get_data(G_OBJECT(window), "text_widget");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 if (!text) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 gdk_window_raise(window->window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185 help_window_load_text(text, path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 help_window_scroll(text, key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 GtkWidget *help_window_new(const gchar *title,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 const gchar *wmclass, const gchar *subclass,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 const gchar *path, const gchar *key)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 GtkWidget *window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 GtkWidget *text;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 GtkTextBuffer *buffer;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 GtkWidget *vbox;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 GtkWidget *hbox;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198 GtkWidget *button;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 GtkWidget *scrolled;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
201 /* window */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
202
289
6a7298988a7a Simplify and unify gtk_window creation with the help of
zas_
parents: 9
diff changeset
203 window = window_new(GTK_WINDOW_TOPLEVEL, subclass, NULL, NULL, title);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
204 gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
205 #if 0
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
206 gtk_container_set_border_width(GTK_CONTAINER(window), PREF_PAD_BORDER);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
207 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
208 gtk_window_set_default_size(GTK_WINDOW(window), HELP_WINDOW_WIDTH, HELP_WINDOW_HEIGHT);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
209
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
210 g_signal_connect(G_OBJECT(window), "delete_event",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
211 G_CALLBACK(help_window_delete_cb), NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213 vbox = gtk_vbox_new(FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 gtk_container_add(GTK_CONTAINER(window), vbox);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215 gtk_widget_show(vbox);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 g_object_set_data(G_OBJECT(window), "text_vbox", vbox);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 /* text window */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 hbox = gtk_hbox_new(FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 gtk_widget_show(hbox);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225 scrolled = gtk_scrolled_window_new(NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled),
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229 gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 gtk_widget_show(scrolled);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 text = gtk_text_view_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234 gtk_container_add(GTK_CONTAINER(scrolled), text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
235 gtk_widget_show(text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
236
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
237 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
238 gtk_text_buffer_create_tag(buffer, "monospace",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
239 "family", "monospace", NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 hbox = gtk_hbutton_box_new();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 gtk_container_set_border_width(GTK_CONTAINER(hbox), PREF_PAD_BORDER);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243 gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 gtk_widget_show(hbox);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
513
985fdfebd89e Remove whitespace between function name and first parenthesis for the sake of consistency. (pass 2)
zas_
parents: 475
diff changeset
248 g_signal_connect(G_OBJECT(button), "clicked",
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 G_CALLBACK(help_window_close), window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250 gtk_container_add(GTK_CONTAINER(hbox), button);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252 gtk_widget_grab_default(button);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253 gtk_widget_show(button);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 g_object_set_data(G_OBJECT(window), "text_widget", text);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 help_window_load_text(text, path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259 gtk_widget_show(window);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261 help_window_scroll(text, key);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 return window;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266 GtkWidget *help_window_get_box(GtkWidget *window)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
267 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
268 return g_object_get_data(G_OBJECT(window), "text_vbox");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269 }