Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

support.c

00001 /*
00002  * DO NOT EDIT THIS FILE - it is generated by Glade.
00003  */
00004 
00005 #ifdef HAVE_CONFIG_H
00006 #  include <config.h>
00007 #endif
00008 
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <unistd.h>
00012 #include <string.h>
00013 
00014 #include <gtk/gtk.h>
00015 
00016 #include "support.h"
00017 
00018 /* This is an internally used function to check if a pixmap file exists. */
00019 static gchar* check_file_exists        (const gchar     *directory,
00020                                         const gchar     *filename);
00021 
00022 /* This is an internally used function to create pixmaps. */
00023 static GtkWidget* create_dummy_pixmap  (GtkWidget       *widget);
00024 
00025 GtkWidget*
00026 lookup_widget                          (GtkWidget       *widget,
00027                                         const gchar     *widget_name)
00028 {
00029   GtkWidget *parent, *found_widget;
00030 
00031   for (;;)
00032     {
00033       if (GTK_IS_MENU (widget))
00034         parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
00035       else
00036         parent = widget->parent;
00037       if (parent == NULL)
00038         break;
00039       widget = parent;
00040     }
00041 
00042   found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget),
00043                                                    widget_name);
00044   if (!found_widget)
00045     g_warning ("Widget not found: %s", widget_name);
00046   return found_widget;
00047 }
00048 
00049 /* This is a dummy pixmap we use when a pixmap can't be found. */
00050 static char *dummy_pixmap_xpm[] = {
00051 /* columns rows colors chars-per-pixel */
00052 "1 1 1 1",
00053 "  c None",
00054 /* pixels */
00055 " "
00056 };
00057 
00058 /* This is an internally used function to create pixmaps. */
00059 static GtkWidget*
00060 create_dummy_pixmap                    (GtkWidget       *widget)
00061 {
00062   GdkColormap *colormap;
00063   GdkPixmap *gdkpixmap;
00064   GdkBitmap *mask;
00065   GtkWidget *pixmap;
00066 
00067   colormap = gtk_widget_get_colormap (widget);
00068   gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,
00069                                                      NULL, dummy_pixmap_xpm);
00070   if (gdkpixmap == NULL)
00071     g_error ("Couldn't create replacement pixmap.");
00072   pixmap = gtk_pixmap_new (gdkpixmap, mask);
00073   gdk_pixmap_unref (gdkpixmap);
00074   gdk_bitmap_unref (mask);
00075   return pixmap;
00076 }
00077 
00078 static GList *pixmaps_directories = NULL;
00079 
00080 /* Use this function to set the directory containing installed pixmaps. */
00081 void
00082 add_pixmap_directory                   (const gchar     *directory)
00083 {
00084   pixmaps_directories = g_list_prepend (pixmaps_directories,
00085                                         g_strdup (directory));
00086 }
00087 
00088 /* This is an internally used function to create pixmaps. */
00089 GtkWidget*
00090 create_pixmap                          (GtkWidget       *widget,
00091                                         const gchar     *filename)
00092 {
00093   gchar *found_filename = NULL;
00094   GdkColormap *colormap;
00095   GdkPixmap *gdkpixmap;
00096   GdkBitmap *mask;
00097   GtkWidget *pixmap;
00098   GList *elem;
00099 
00100   if (!filename || !filename[0])
00101       return create_dummy_pixmap (widget);
00102 
00103   /* We first try any pixmaps directories set by the application. */
00104   elem = pixmaps_directories;
00105   while (elem)
00106     {
00107       found_filename = check_file_exists ((gchar*)elem->data, filename);
00108       if (found_filename)
00109         break;
00110       elem = elem->next;
00111     }
00112 
00113   /* If we haven't found the pixmap, try the source directory. */
00114   if (!found_filename)
00115     {
00116       found_filename = check_file_exists ("../Pics", filename);
00117     }
00118 
00119   if (!found_filename)
00120     {
00121       g_warning ("Couldn't find pixmap file: %s", filename);
00122       return create_dummy_pixmap (widget);
00123     }
00124 
00125   colormap = gtk_widget_get_colormap (widget);
00126   gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask,
00127                                                    NULL, found_filename);
00128   if (gdkpixmap == NULL)
00129     {
00130       g_warning ("Error loading pixmap file: %s", found_filename);
00131       g_free (found_filename);
00132       return create_dummy_pixmap (widget);
00133     }
00134   g_free (found_filename);
00135   pixmap = gtk_pixmap_new (gdkpixmap, mask);
00136   gdk_pixmap_unref (gdkpixmap);
00137   gdk_bitmap_unref (mask);
00138   return pixmap;
00139 }
00140 
00141 /* This is an internally used function to check if a pixmap file exists. */
00142 static gchar*
00143 check_file_exists                      (const gchar     *directory,
00144                                         const gchar     *filename)
00145 {
00146   gchar *full_filename;
00147   struct stat s;
00148   gint status;
00149 
00150   full_filename = (gchar*) g_malloc (strlen (directory) + 1
00151                                      + strlen (filename) + 1);
00152   strcpy (full_filename, directory);
00153   strcat (full_filename, G_DIR_SEPARATOR_S);
00154   strcat (full_filename, filename);
00155 
00156   status = stat (full_filename, &s);
00157   if (status == 0 && S_ISREG (s.st_mode))
00158     return full_filename;
00159   g_free (full_filename);
00160   return NULL;
00161 }
00162 

Generated on Sun May 9 19:19:17 2004 for GtkSQL by doxygen1.2.18