eb05362005-11-05Henrik Grubbström (Grubba) /* -*- C -*- */
1a05542005-07-28Martin Nilsson class GTK2.Image; inherit GTK2.Misc; //! An image is a image object stored in client, not X server, memory. //! A pixmap, on the other hand, is a image object stored in the X-server. //! See GDK2.Image and GDK2.Pixmap. //!<p>
3d76632005-11-03Lance Dillon //! IMG: GTK2.Image("tornado_nguyen_big.jpg");
1a05542005-07-28Martin Nilsson //!</p> //! Properties: //! string file //! string icon-name //! icon-set //! int icon-size //! GDK2.Image image //! GDK2.Pixmap mask //! GDK2.Pixbuf pixbuf //! GDK2.PixbufAnimation pixbuf-animation //! int pixel-size //! GDK2.Pixmap pixmap //! string stock //! int storage-type CONST(GTK_IMAGE_)
3d76632005-11-03Lance Dillon void create(string|GDK2.Pixbuf|GDK2.PixbufAnimation|GDK2.Image|GDK2.Pixmap|mapping(string:mixed)|void file_or_props, GDK2.Bitmap|int|void mask_or_size)
1a05542005-07-28Martin Nilsson //! Create a new W(Image) from either a file or a GDK2.Pixbuf. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_not_inited(); pgtk2_verify_setup();
1a05542005-07-28Martin Nilsson  if (args==1) {
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF(Pike_sp[-args]) == PIKE_T_MAPPING) {
3d76632005-11-03Lance Dillon  INIT_WITH_PROPS(GTK_TYPE_IMAGE);
1a05542005-07-28Martin Nilsson  } else {
66fe7f2006-01-16Lance Dillon  GtkWidget *gi;
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF(Pike_sp[-args]) == PIKE_T_STRING) {
66fe7f2006-01-16Lance Dillon  char *filename;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%s",&filename);
66fe7f2006-01-16Lance Dillon  gi=gtk_image_new_from_file(filename);
1a05542005-07-28Martin Nilsson  } else {
66fe7f2006-01-16Lance Dillon  struct object *o1; GObject *go;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o1);
66fe7f2006-01-16Lance Dillon  go=get_gobject(o1); if (GDK_TYPE_IMAGE==G_TYPE_FROM_INSTANCE(go)) { gi=gtk_image_new_from_image(GDK_IMAGE(go),NULL); } else if (GDK_TYPE_PIXBUF==G_TYPE_FROM_INSTANCE(go)) { gi=gtk_image_new_from_pixbuf(GDK_PIXBUF(go)); } else { gi=gtk_image_new_from_animation(GDK_PIXBUF_ANIMATION(go));
1a05542005-07-28Martin Nilsson  } }
66fe7f2006-01-16Lance Dillon  THIS->obj=G_OBJECT(gi);
1a05542005-07-28Martin Nilsson  } } else if (args==2) {
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF(Pike_sp[1-args]) == PIKE_T_INT) {
66fe7f2006-01-16Lance Dillon  struct pike_string *s1;
3d76632005-11-03Lance Dillon  GtkWidget *gi;
66fe7f2006-01-16Lance Dillon  GtkStockItem item;
3d76632005-11-03Lance Dillon  int size;
66fe7f2006-01-16Lance Dillon  int t=0;
3d76632005-11-03Lance Dillon 
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%t%d",&s1,&size);
66fe7f2006-01-16Lance Dillon  if (s1->size_shift==0) t=gtk_stock_lookup(CGSTR0(s1),&item); if (t) gi=gtk_image_new_from_stock(CGSTR0(s1),size); else gi=gtk_image_new();
3d76632005-11-03Lance Dillon  THIS->obj=G_OBJECT(gi);
1a05542005-07-28Martin Nilsson  } else {
3d76632005-11-03Lance Dillon  GdkImage *image; GdkPixmap *pixmap; GdkBitmap *bitmap; GtkWidget *gi; struct object *o1,*o2;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o%o",&o1,&o2);
3d76632005-11-03Lance Dillon  image=GDK_IMAGE(get_gobject(o1));
66fe7f2006-01-16Lance Dillon /* bitmap=(GdkBitmap *)get_gdkobject(o2,bitmap); */ bitmap=GDK_PIXMAP(get_gobject(o2));
3d76632005-11-03Lance Dillon  if (image) { gi=gtk_image_new_from_image(image,bitmap); } else { pixmap=GDK_PIXMAP(get_gobject(o1)); gi=gtk_image_new_from_pixmap(pixmap,bitmap); } THIS->obj=G_OBJECT(gi); }
1a05542005-07-28Martin Nilsson  } else {
3d76632005-11-03Lance Dillon  GtkWidget *gi; gi=gtk_image_new(); THIS->obj=G_OBJECT(gi);
1a05542005-07-28Martin Nilsson  }
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args); pgtk2__init_this_object();
1a05542005-07-28Martin Nilsson } mapping(string:object) get_image() //! Returns ([ "image":GDK2.Image img, "mask":GDK2.Bitmap mask ]) {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited(); pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  { GdkImage *v; GdkBitmap *m; gtk_image_get_image(GTK_IMAGE(THIS->obj),&v,&m);
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("image"));
f284492006-08-03Lance Dillon  if (v) {
1a05542005-07-28Martin Nilsson  push_gobject(v);
f284492006-08-03Lance Dillon  g_object_ref(v); } else
1a05542005-07-28Martin Nilsson  push_int(0);
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("mask"));
1a05542005-07-28Martin Nilsson  if(m) {
f284492006-08-03Lance Dillon  push_gobject(m);
1a05542005-07-28Martin Nilsson  g_object_ref(m); } else push_int(0); f_aggregate_mapping(4); } }
f284492006-08-03Lance Dillon +GDK2.Pixbuf get_pixbuf();
1a05542005-07-28Martin Nilsson //! Gets the GDK2.Pixbuf being displayed. The storage type of the image must //! be GTK2.IMAGE_EMPTY or GTK2.IMAGE_PIXBUF). mapping(string:object) get_pixmap() //! Gets the pixmap and mask. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited(); pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  { GdkPixmap *v; GdkBitmap *m; gtk_image_get_pixmap(GTK_IMAGE(THIS->obj),&v,&m);
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("pixmap"));
f284492006-08-03Lance Dillon  if (v) {
1a05542005-07-28Martin Nilsson  push_gobject(v);
f284492006-08-03Lance Dillon  g_object_ref(v); } else
1a05542005-07-28Martin Nilsson  push_int(0);
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("mask"));
1a05542005-07-28Martin Nilsson  if (m) {
f284492006-08-03Lance Dillon  push_gobject(m);
1a05542005-07-28Martin Nilsson  g_object_ref(m); } else push_int(0); f_aggregate_mapping(4); } } mapping(string:mixed) get_stock() //! Gets the stock icon name and size. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited(); pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  { gchar *stock_id; GtkIconSize size; gtk_image_get_stock(GTK_IMAGE(THIS->obj),&stock_id,&size);
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("stock_id"));
74a5dd2010-09-19Marcus Comstedt  PGTK_PUSH_GCHAR(stock_id);
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("size"));
1a05542005-07-28Martin Nilsson  push_int(size); f_aggregate_mapping(4); } }
f284492006-08-03Lance Dillon +GDK2.PixbufAnimation get_animation()
1a05542005-07-28Martin Nilsson //! Gets the GDK2.PixbufAnimation being displayed. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited(); pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  { GdkPixbufAnimation *gpa=gtk_image_get_animation(GTK_IMAGE(THIS->obj)); push_gobject(gpa);
f284492006-08-03Lance Dillon  g_object_ref(gpa);
1a05542005-07-28Martin Nilsson  } } require gtk26; mapping(string:mixed) get_icon_name() //! Gets the icon name and size. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited(); pgtk2_pop_n_elems(args);
1a05542005-07-28Martin Nilsson  { const gchar *icon_name; GtkIconSize size; gtk_image_get_icon_name(GTK_IMAGE(THIS->obj),&icon_name,&size);
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("icon_name"));
74a5dd2010-09-19Marcus Comstedt  PGTK_PUSH_GCHAR(icon_name);
9fb5032006-01-14Martin Nilsson  ref_push_string(_STR("size"));
1a05542005-07-28Martin Nilsson  push_int(size);
76f7462014-05-26Martin Nilsson  f_aggregate_mapping(4);
1a05542005-07-28Martin Nilsson  } } endrequire; int get_storage_type(); //! Gets the type of representation being used to store data. If it has no //! image data, the return value will be GTK2.IMAGE_EMPTY. //! One of CONST(GTK_IMAGE_) void set_from_file(string filename); //! Set the image from a file. %{ #define GTK_GDKPIXBUF(X) GDK_PIXBUF(X) %}
1795322006-02-14Lance Dillon void set_from_icon_set(GTK2.IconSet icon_set, int size) //! Set this image from an icon set. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited();
1795322006-02-14Lance Dillon  { struct object *o1; INT_TYPE size; GtkIconSet *is;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o%i",&o1,&size);
1795322006-02-14Lance Dillon  is=(GtkIconSet *)get_gobject(o1); if (!is) SIMPLE_ARG_ERROR("set_from_icon_set",args,"Invalid GTK2.IconSet"); gtk_image_set_from_icon_set(GTK_IMAGE(THIS->obj),is,size); } RETURN_THIS(); } void set_from_image(GDK2.Image gdk_image, ?GDK2.Bitmap mask) //! Set this image from a GDK2.Image plus optional mask. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited();
1795322006-02-14Lance Dillon  { struct object *o1,*o2=NULL;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o.%o",&o1,&o2);
1795322006-02-14Lance Dillon  gtk_image_set_from_image(GTK_IMAGE(THIS->obj),(GdkImage *)get_gobject(o1), o2?(GdkBitmap *)get_gobject(o2):NULL); } RETURN_THIS(); }
1a05542005-07-28Martin Nilsson void set_from_pixbuf(GDK2.Pixbuf pixbuf); //! Set image from a pixbuf
1795322006-02-14Lance Dillon void set_from_pixmap(GDK2.Pixmap pixmap, ?GDK2.Bitmap mask) //! Set this image from a GDK2.Pixmap plus optional mask. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited();
1795322006-02-14Lance Dillon  { struct object *o1,*o2=NULL;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o.%o",&o1,&o2);
1795322006-02-14Lance Dillon  gtk_image_set_from_pixmap(GTK_IMAGE(THIS->obj),(GdkPixmap *)get_gobject(o1), o2?(GdkBitmap *)get_gobject(o2):NULL); } RETURN_THIS(); }
1a05542005-07-28Martin Nilsson void set_from_stock(string stock_id, int size); //! Sets from a stock icon. Sample icon names are GTK2.STOCK_OPEN, //! GTK2.STOCK_EXIT. Sample stock sizes are GTK2.ICON_SIZE_MENU, //! GTK2.ICON_SIZE_SMALL_TOOLBAR. If the stock name isn't known, the image //! will be empty. void set_from_animation(GDK2.PixbufAnimation anim) //! Causes the W(Image) to display the given animation. {
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_inited();
1a05542005-07-28Martin Nilsson  { struct object *o1;
96f5f42018-08-05Martin Nilsson  get_all_args(NULL,args,"%o",&o1);
1a05542005-07-28Martin Nilsson  gtk_image_set_from_animation(GTK_IMAGE(THIS->obj), GDK_PIXBUF_ANIMATION(get_gobject(o1))); } RETURN_THIS(); } require gtk26; void set_from_icon_name(string icon_name, int size); //! Sets from an icon name.
3d76632005-11-03Lance Dillon require gtk28; void clear(); //! Resets the image to be empty. endrequire;
1a05542005-07-28Martin Nilsson void set_pixel_size(int pixel_size); //! Sets the pixel size to use for named icons. If the pixel size is set to //! a value != -1, it is used instead of the icon size set by //! set_from_icon_name(). int get_pixel_size(); //! Gets the pixel size used for named icons. endrequire;