|
|
1.1 ! root 1: #include <sys/types.h> ! 2: #include <sys/stat.h> ! 3: #include <unistd.h> ! 4: #include <string.h> ! 5: #include <stdio.h> ! 6: ! 7: #include <gtk/gtk.h> ! 8: ! 9: #include "support.h" ! 10: ! 11: GtkWidget* ! 12: lookup_widget (GtkWidget *widget, ! 13: const gchar *widget_name) ! 14: { ! 15: GtkWidget *parent, *found_widget; ! 16: ! 17: for (;;) ! 18: { ! 19: if (GTK_IS_MENU (widget)) ! 20: parent = gtk_menu_get_attach_widget (GTK_MENU (widget)); ! 21: else ! 22: parent = widget->parent; ! 23: if (!parent) ! 24: parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey"); ! 25: if (parent == NULL) ! 26: break; ! 27: widget = parent; ! 28: } ! 29: ! 30: found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget), ! 31: widget_name); ! 32: if (!found_widget) ! 33: g_warning ("Widget not found: %s", widget_name); ! 34: return found_widget; ! 35: } ! 36: ! 37: static GList *pixmaps_directories = NULL; ! 38: ! 39: /* Use this function to set the directory containing installed pixmaps. */ ! 40: void ! 41: add_pixmap_directory (const gchar *directory) ! 42: { ! 43: pixmaps_directories = g_list_prepend (pixmaps_directories, ! 44: g_strdup (directory)); ! 45: } ! 46: ! 47: /* This is an internally used function to find pixmap files. */ ! 48: static gchar* ! 49: find_pixmap_file (const gchar *filename) ! 50: { ! 51: GList *elem; ! 52: ! 53: /* We step through each of the pixmaps directory to find it. */ ! 54: elem = pixmaps_directories; ! 55: while (elem) ! 56: { ! 57: gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data, ! 58: G_DIR_SEPARATOR_S, filename); ! 59: if (g_file_test (pathname, G_FILE_TEST_EXISTS)) ! 60: return pathname; ! 61: g_free (pathname); ! 62: elem = elem->next; ! 63: } ! 64: return NULL; ! 65: } ! 66: ! 67: /* This is an internally used function to create pixmaps. */ ! 68: GtkWidget* ! 69: create_pixmap (GtkWidget *widget, ! 70: const gchar *filename) ! 71: { ! 72: gchar *pathname = NULL; ! 73: GtkWidget *pixmap; ! 74: ! 75: if (!filename || !filename[0]) ! 76: return gtk_image_new (); ! 77: ! 78: pathname = find_pixmap_file (filename); ! 79: ! 80: if (!pathname) ! 81: { ! 82: g_warning ("Couldn't find pixmap file: %s", filename); ! 83: return gtk_image_new (); ! 84: } ! 85: ! 86: pixmap = gtk_image_new_from_file (pathname); ! 87: g_free (pathname); ! 88: return pixmap; ! 89: } ! 90: ! 91: /* This is an internally used function to create pixmaps. */ ! 92: GdkPixbuf* ! 93: create_pixbuf (const gchar *filename) ! 94: { ! 95: gchar *pathname = NULL; ! 96: GdkPixbuf *pixbuf; ! 97: GError *error = NULL; ! 98: ! 99: if (!filename || !filename[0]) ! 100: return NULL; ! 101: ! 102: pathname = find_pixmap_file (filename); ! 103: ! 104: if (!pathname) ! 105: { ! 106: g_warning ("Couldn't find pixmap file: %s", filename); ! 107: return NULL; ! 108: } ! 109: ! 110: pixbuf = gdk_pixbuf_new_from_file (pathname, &error); ! 111: if (!pixbuf) ! 112: { ! 113: fprintf (stderr, "Failed to load pixbuf file: %s: %s\n", ! 114: pathname, error->message); ! 115: g_error_free (error); ! 116: } ! 117: g_free (pathname); ! 118: return pixbuf; ! 119: } ! 120: ! 121: /* This is used to set ATK action descriptions. */ ! 122: void ! 123: glade_set_atk_action_description (AtkAction *action, ! 124: const gchar *action_name, ! 125: const gchar *description) ! 126: { ! 127: gint n_actions, i; ! 128: ! 129: n_actions = atk_action_get_n_actions (action); ! 130: for (i = 0; i < n_actions; i++) ! 131: { ! 132: if (!strcmp (atk_action_get_name (action, i), action_name)) ! 133: atk_action_set_description (action, i, description); ! 134: } ! 135: } ! 136:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.