chiark / gitweb /
Abolish shared libdisorder; now we use a static one.
[disorder] / disobedience / misc.c
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
25 /* Functions */
26
27 GtkWidget *scroll_widget(GtkWidget *child,
28                          const char *widgetname) {
29   GtkWidget *scroller = gtk_scrolled_window_new(0, 0);
30   GtkAdjustment *adj;
31
32   D(("scroll_widget"));
33   /* Why isn't _AUTOMATIC the default? */
34   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroller),
35                                  GTK_POLICY_AUTOMATIC,
36                                  GTK_POLICY_AUTOMATIC);
37   if(GTK_IS_LAYOUT(child)) {
38     /* Child widget has native scroll support */
39     gtk_container_add(GTK_CONTAINER(scroller), child);
40     /* Fix up the step increments if they are 0 (seems like an odd default?) */
41     if(GTK_IS_LAYOUT(child)) {
42       adj = gtk_layout_get_hadjustment(GTK_LAYOUT(child));
43       if(!adj->step_increment) adj->step_increment = 16;
44       adj = gtk_layout_get_vadjustment(GTK_LAYOUT(child));
45       if(!adj->step_increment) adj->step_increment = 16;
46     }
47   } else {
48     /* Child widget requires a viewport */
49     gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroller),
50                                           child);
51   }
52   /* Apply a name to the widget so it can be recolored */
53   gtk_widget_set_name(GTK_BIN(scroller)->child, widgetname);
54   gtk_widget_set_name(scroller, widgetname);
55   return scroller;
56 }
57
58 GdkPixbuf *find_image(const char *name) {
59   static const struct cache_type image_cache_type = { INT_MAX };
60
61   GdkPixbuf *pb;
62   char *path;
63   GError *err = 0;
64
65   if(!(pb = (GdkPixbuf *)cache_get(&image_cache_type, name))) {
66     byte_xasprintf(&path, "%s/static/%s", pkgdatadir, name);
67     if(!(pb = gdk_pixbuf_new_from_file(path, &err))) {
68       error(0, "%s", err->message);
69       return 0;
70     }
71     cache_put(&image_cache_type, name,  pb);
72   }
73   return pb;
74 }
75
76 void popup_error(const char *msg) {
77   GtkWidget *w;
78
79   w = gtk_message_dialog_new(GTK_WINDOW(toplevel),
80                              GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
81                              GTK_MESSAGE_ERROR,
82                              GTK_BUTTONS_CLOSE,
83                              "%s", msg);
84   gtk_dialog_run(GTK_DIALOG(w));
85   gtk_widget_destroy(w);
86 }
87
88 /*
89 Local Variables:
90 c-basic-offset:2
91 comment-column:40
92 fill-column:79
93 indent-tabs-mode:nil
94 End:
95 */