Re: ok, I guess I am dumb, but I can not figure this out. :-(



On Sunday 17 June 2001 10:59 pm Ivica Bukvic shared with us the following 
piece of wisdom:
Here's the simple source code consisting of only one file main.c. It does,
however, require any kind of a xpm file to be available for its execution.
Anyhow, I am greatly thankfull for all your efforts to help me in this
issue, but I guess I am just too dumb to get it. Here's the source code of
that file that is giving me a headache. Obviously, any help would be
greatly appreciated. Thank you!

Ivica Bukvic
ico fuse net

/*
 * Initial main.c file generated by Glade. Edit as required.
 * Glade will not overwrite this file.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gnome.h>

int
main (int argc, char *argv[])
{
  GtkWidget *window1;
  GtkWidget *pixmap1;
  GtkPixmap *pixmapdata;

Above should be:
  GdkPixmap *pixmapdata;

#ifdef ENABLE_NLS
  bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);
  textdomain (PACKAGE);
#endif

  gnome_init ("shit", VERSION, argc, argv);

  /*
   * The following code was added by Glade to create one of each component
   * (except popup menus), just so that you see something after building
   * the project. Delete any components that you don't want shown
initially. */

  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_object_set_data (GTK_OBJECT (window1), "window1", window1);
  gtk_window_set_title (GTK_WINDOW (window1), _("window1"));

Above should be :
  gtk_window_set_title(GTK_WINDOW(window1), "window1");

  //pixmap1 = create_pixmap (window1, NULL, FALSE);
  //gtk_widget_ref (pixmap1);
  //gtk_object_set_data_full (GTK_OBJECT (window1), "pixmap1", pixmap1,
  //                          (GtkDestroyNotify) gtk_widget_unref);


  gtk_widget_show (window1);
  gtk_widget_realize(window1);

Here you need either gtk_widget_show (which also does realization of a 
widget) or gtk_widget_realize (and then use gtk_widget_show() later), not 
both. On a side note, if you create pixmap first and realize window later, 
code will still compile, but it will give you a warning:

Gdk-WARNING **: Creating pixmap from xpm with NULL window and colormap

  //gtk_container_add (GTK_CONTAINER (window1), pixmap1);

  pixmapdata = gdk_pixmap_create_from_xpm (window1->window, NULL, NULL,
"four.xpm");
  pixmap1 = gtk_pixmap_new (pixmapdata, NULL);

Here you need to add your pixmap to the window:

gtk_container_add(GTK_CONTAINER (window1), pixmap1);

  gtk_widget_show (pixmap1);
  gtk_main ();
  return 0;
}

This should work fine, although I have no idea if your gnome initialization 
is correct...for the reference here's source code for pure gtk (no gnome 
support) that runs correctly:

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>

int main (int argc, char *argv[]) {
  GtkWidget *window1;
  GtkWidget *pixmap1;
  GdkPixmap *pixmapdata;

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_object_set_data (GTK_OBJECT (window1), "window1", window1);
  gtk_window_set_title (GTK_WINDOW (window1), "window1");
  gtk_widget_realize(window1);       
                             
  /* Ant.xpm is the name of the file with the pixmap, which sits in the same
   * directory as main.c
   */
  pixmapdata = gdk_pixmap_create_from_xpm (window1->window, NULL, NULL, 
"Ant.xpm");
  pixmap1 = gtk_pixmap_new (pixmapdata, NULL);
  gtk_container_add(GTK_CONTAINER(window1), pixmap1);
  gtk_widget_show_all(window1);

  gtk_main ();
  return 0;   
  }

-- 
Bye, Warrior.

ICQ #24496762

-------------
Tagline for Sunday, June 17, 2001, 23:05
--- 90% of being smart is knowing what you're dumb at.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]