eb05362005-11-05Henrik Grubbström (Grubba) /* -*- C -*- */
1a05542005-07-28Martin Nilsson class GDK2.Pixmap; inherit GDK2.Drawable; //! This class creates a GDK2.Pixmap from either an GDK2.Image or //! Image.image object (or a numeric ID, see your X-manual for XIDs). //! <p> The GDK2.Pixmap object can be used in a lot //! of different GTK widgets. The most notable is the W(Pixmap) //! widget.</p> //! //! NOIMG %{ #ifdef __NT__
acacdd2008-07-19Martin Stjernholm #include <gdk/gdkwin32.h>
1a05542005-07-28Martin Nilsson #else #include <gdk/gdkx.h> #endif
ba9e802006-02-27Martin Stjernholm GdkImage *pgtk2_pixmap_setup(struct object *o, int *free)
1a05542005-07-28Martin Nilsson { if (get_gdkobject(o,image)) return get_gdkobject(o,image); else { *free=1; return gdkimage_from_pikeimage(o,GDK_IMAGE_FASTEST,0); } }
ba9e802006-02-27Martin Stjernholm void pgtk2__pixmap_draw(GdkImage *i)
1a05542005-07-28Martin Nilsson { GdkGC *gc; if (THIS->extra_data) gc=THIS->extra_data; else
3d76632005-11-03Lance Dillon  THIS->extra_data=gc=gdk_gc_new(GDK_DRAWABLE(THIS->obj)); gdk_draw_image(GDK_DRAWABLE(THIS->obj),gc,i,0,0,0,0,
1a05542005-07-28Martin Nilsson  i->width,i->height); } %} void create(int|object image) //! Create a new GDK2.Pixmap object. //! Argument is a GDK2.Image object or a Image.Image object { GdkImage *i; int f=0; struct object *o;
3d76632005-11-03Lance Dillon  GdkPixmap *gp;
ba9e802006-02-27Martin Stjernholm  pgtk2_verify_setup(); pgtk2_verify_not_inited();
1a05542005-07-28Martin Nilsson 
017b572011-10-28Henrik Grubbström (Grubba)  if (TYPEOF(Pike_sp[-args]) == PIKE_T_OBJECT) {
1a05542005-07-28Martin Nilsson  get_all_args("create",args,"%o",&o);
ba9e802006-02-27Martin Stjernholm  i=pgtk2_pixmap_setup(o,&f);
1a05542005-07-28Martin Nilsson 
3d76632005-11-03Lance Dillon  gp=gdk_pixmap_new(0,i->width,i->height,i->depth); THIS->obj=G_OBJECT(gp);
1a05542005-07-28Martin Nilsson  if (!THIS->obj) { if (f) g_object_unref(i); Pike_error("Failed to create pixmap.\n"); }
ba9e802006-02-27Martin Stjernholm  pgtk2__pixmap_draw(i);
1a05542005-07-28Martin Nilsson  if (f) g_object_unref(i);
017b572011-10-28Henrik Grubbström (Grubba)  } else if (args && TYPEOF(Pike_sp[-1]) == PIKE_T_INT) {
3d76632005-11-03Lance Dillon  gp=gdk_pixmap_foreign_new(Pike_sp[-1].u.integer); THIS->obj=G_OBJECT(gp);
1a05542005-07-28Martin Nilsson  if (!THIS->obj) Pike_error("Failed to find remote pixmap\n"); }
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args); pgtk2__init_this_object();
1a05542005-07-28Martin Nilsson } void set(GDK2.Image|Image.Image image) //! Argument is a GDK2.Image object or an Image.image object. //! It is much faster to use an gdkImage object, especially one //! allocated in shared memory. This is only an issue if you are //! going to change the contents of the pixmap often, toggling between //! a small number of images. { struct object *o; int f=0; GdkImage *i; get_all_args("set", args, "%o", &o );
ba9e802006-02-27Martin Stjernholm  pgtk2__pixmap_draw(i=pgtk2_pixmap_setup(o,&f));
1a05542005-07-28Martin Nilsson  if (f) g_object_unref(i); RETURN_THIS(); } void destroy() {
2edd4f2008-01-30Per Hedbor  /* if (THIS->obj) g_object_unref(THIS->obj); THIS->obj=0; Done by g.object */
1a05542005-07-28Martin Nilsson  if (THIS->extra_data) g_object_unref(THIS->extra_data); THIS->extra_data=0;
ba9e802006-02-27Martin Stjernholm  pgtk2_pop_n_elems(args);
3d76632005-11-03Lance Dillon  push_int(0);
1a05542005-07-28Martin Nilsson } void ref() //! Ref this object. { g_object_ref(THIS->obj); RETURN_THIS(); } void unref() //! Unref this object. { g_object_unref(THIS->obj); RETURN_THIS(); }