gnome_support.c
上传用户:riyaled888
上传日期:2009-03-27
资源大小:7338k
文件大小:4k
源码类别:

多媒体

开发平台:

MultiPlatform

  1. /*
  2.  * DO NOT EDIT THIS FILE - it is generated by Glade.
  3.  */
  4. #ifdef HAVE_CONFIG_H
  5. #  include <config.h>
  6. #endif
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <unistd.h>
  10. #include <string.h>
  11. #include <gnome.h>
  12. #include "gnome_support.h"
  13. /* This is an internally used function to create pixmaps. */
  14. static GtkWidget* create_dummy_pixmap  (GtkWidget       *widget,
  15.                                         gboolean         gnome_pixmap);
  16. GtkWidget*
  17. lookup_widget                          (GtkWidget       *widget,
  18.                                         const gchar     *widget_name)
  19. {
  20.   GtkWidget *parent, *found_widget;
  21.   for (;;)
  22.     {
  23.       if (GTK_IS_MENU (widget))
  24.         parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
  25.       else
  26.         parent = widget->parent;
  27.       if (parent == NULL)
  28.         break;
  29.       widget = parent;
  30.     }
  31.   found_widget = (GtkWidget*) gtk_object_get_data (GTK_OBJECT (widget),
  32.                                                    widget_name);
  33.   if (!found_widget)
  34.     g_warning ("Widget not found: %s", widget_name);
  35.   return found_widget;
  36. }
  37. /* This is a dummy pixmap we use when a pixmap can't be found. */
  38. static char *dummy_pixmap_xpm[] = {
  39. /* columns rows colors chars-per-pixel */
  40. "1 1 1 1",
  41. "  c None",
  42. /* pixels */
  43. " ",
  44. " "
  45. };
  46. /* This is an internally used function to create pixmaps. */
  47. static GtkWidget*
  48. create_dummy_pixmap                    (GtkWidget       *widget,
  49.                                         gboolean         gnome_pixmap)
  50. {
  51.   GdkColormap *colormap;
  52.   GdkPixmap *gdkpixmap;
  53.   GdkBitmap *mask;
  54.   GtkWidget *pixmap;
  55.   if (gnome_pixmap)
  56.     {
  57.       return gnome_pixmap_new_from_xpm_d (dummy_pixmap_xpm);
  58.     }
  59.   colormap = gtk_widget_get_colormap (widget);
  60.   gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,
  61.                                                      NULL, dummy_pixmap_xpm);
  62.   if (gdkpixmap == NULL)
  63.     g_error ("Couldn't create replacement pixmap.");
  64.   pixmap = gtk_pixmap_new (gdkpixmap, mask);
  65.   gdk_pixmap_unref (gdkpixmap);
  66.   gdk_bitmap_unref (mask);
  67.   return pixmap;
  68. }
  69. /* This is an internally used function to create pixmaps. */
  70. GtkWidget*
  71. create_pixmap                          (GtkWidget       *widget,
  72.                                         const gchar     *filename,
  73.                                         gboolean         gnome_pixmap)
  74. {
  75.   GtkWidget *pixmap;
  76.   GdkColormap *colormap;
  77.   GdkPixmap *gdkpixmap;
  78.   GdkBitmap *mask;
  79.   gchar *pathname;
  80.   if (!filename || !filename[0])
  81.       return create_dummy_pixmap (widget, gnome_pixmap);
  82.   pathname = gnome_pixmap_file (filename);
  83.   if (!pathname)
  84.     {
  85.       g_warning (_("Couldn't find pixmap file: %s"), filename);
  86.       return create_dummy_pixmap (widget, gnome_pixmap);
  87.     }
  88.   if (gnome_pixmap)
  89.     {
  90.       pixmap = gnome_pixmap_new_from_file (pathname);
  91.       g_free (pathname);
  92.       return pixmap;
  93.     }
  94.   colormap = gtk_widget_get_colormap (widget);
  95.   gdkpixmap = gdk_pixmap_colormap_create_from_xpm (NULL, colormap, &mask,
  96.                                                    NULL, pathname);
  97.   if (gdkpixmap == NULL)
  98.     {
  99.       g_warning (_("Couldn't create pixmap from file: %s"), pathname);
  100.       g_free (pathname);
  101.       return create_dummy_pixmap (widget, gnome_pixmap);
  102.     }
  103.   g_free (pathname);
  104.   pixmap = gtk_pixmap_new (gdkpixmap, mask);
  105.   gdk_pixmap_unref (gdkpixmap);
  106.   gdk_bitmap_unref (mask);
  107.   return pixmap;
  108. }
  109. /* This is an internally used function to create imlib images. */
  110. GdkImlibImage*
  111. create_image                           (const gchar     *filename)
  112. {
  113.   GdkImlibImage *image;
  114.   gchar *pathname;
  115.   pathname = gnome_pixmap_file (filename);
  116.   if (!pathname)
  117.     {
  118.       g_warning (_("Couldn't find pixmap file: %s"), filename);
  119.       return NULL;
  120.     }
  121.   image = gdk_imlib_load_image (pathname);
  122.   g_free (pathname);
  123.   return image;
  124. }