460b9539 |
1 | /* |
2 | * This file is part of DisOrder |
3 | * Copyright (C) 2006 Richard Kettlewell |
4 | * |
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. |
9 | * |
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. |
14 | * |
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 |
18 | * USA |
19 | */ |
20 | |
21 | #include "disobedience.h" |
22 | |
23 | /* Miscellaneous GTK+ stuff ------------------------------------------------ */ |
24 | |
e9b70a84 |
25 | WT(cached_image); |
26 | |
460b9539 |
27 | /* Functions */ |
28 | |
29 | GtkWidget *scroll_widget(GtkWidget *child, |
30 | const char *widgetname) { |
31 | GtkWidget *scroller = gtk_scrolled_window_new(0, 0); |
32 | GtkAdjustment *adj; |
33 | |
34 | D(("scroll_widget")); |
35 | /* Why isn't _AUTOMATIC the default? */ |
36 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroller), |
37 | GTK_POLICY_AUTOMATIC, |
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; |
48 | } |
49 | } else { |
50 | /* Child widget requires a viewport */ |
51 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroller), |
52 | child); |
53 | } |
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); |
57 | return scroller; |
58 | } |
59 | |
60 | GdkPixbuf *find_image(const char *name) { |
61 | static const struct cache_type image_cache_type = { INT_MAX }; |
62 | |
63 | GdkPixbuf *pb; |
64 | char *path; |
65 | GError *err = 0; |
66 | |
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); |
71 | return 0; |
72 | } |
e9b70a84 |
73 | NW(cached_image); |
460b9539 |
74 | cache_put(&image_cache_type, name, pb); |
75 | } |
76 | return pb; |
77 | } |
78 | |
79 | void popup_error(const char *msg) { |
80 | GtkWidget *w; |
81 | |
82 | w = gtk_message_dialog_new(GTK_WINDOW(toplevel), |
83 | GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, |
84 | GTK_MESSAGE_ERROR, |
85 | GTK_BUTTONS_CLOSE, |
86 | "%s", msg); |
87 | gtk_dialog_run(GTK_DIALOG(w)); |
88 | gtk_widget_destroy(w); |
89 | } |
90 | |
91 | /* |
92 | Local Variables: |
93 | c-basic-offset:2 |
94 | comment-column:40 |
95 | fill-column:79 |
96 | indent-tabs-mode:nil |
97 | End: |
98 | */ |