2 * This file is part of DisOrder
3 * Copyright (C) 2006 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 #include "disobedience.h"
23 /* Miscellaneous GTK+ stuff ------------------------------------------------ */
29 GtkWidget *scroll_widget(GtkWidget *child,
30 const char *widgetname) {
31 GtkWidget *scroller = gtk_scrolled_window_new(0, 0);
35 /* Why isn't _AUTOMATIC the default? */
36 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroller),
38 GTK_POLICY_AUTOMATIC);
39 if(GTK_IS_LAYOUT(child)) {
40 /* Child widget has native scroll support */
41 gtk_container_add(GTK_CONTAINER(scroller), child);
42 /* Fix up the step increments if they are 0 (seems like an odd default?) */
43 if(GTK_IS_LAYOUT(child)) {
44 adj = gtk_layout_get_hadjustment(GTK_LAYOUT(child));
45 if(!adj->step_increment) adj->step_increment = 16;
46 adj = gtk_layout_get_vadjustment(GTK_LAYOUT(child));
47 if(!adj->step_increment) adj->step_increment = 16;
50 /* Child widget requires a viewport */
51 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroller),
54 /* Apply a name to the widget so it can be recolored */
55 gtk_widget_set_name(GTK_BIN(scroller)->child, widgetname);
56 gtk_widget_set_name(scroller, widgetname);
60 GdkPixbuf *find_image(const char *name) {
61 static const struct cache_type image_cache_type = { INT_MAX };
67 if(!(pb = (GdkPixbuf *)cache_get(&image_cache_type, name))) {
68 byte_xasprintf(&path, "%s/static/%s", pkgdatadir, name);
69 if(!(pb = gdk_pixbuf_new_from_file(path, &err))) {
70 error(0, "%s", err->message);
74 cache_put(&image_cache_type, name, pb);
79 void popup_error(const char *msg) {
82 w = gtk_message_dialog_new(GTK_WINDOW(toplevel),
83 GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
87 gtk_dialog_run(GTK_DIALOG(w));
88 gtk_widget_destroy(w);