1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
/* -*- C -*- */ 
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 
%{ 
GdkImage *pgtk2_pixmap_setup(struct object *o, int *free) 
{ 
  if (get_gdkobject(o,image)) 
    return get_gdkobject(o,image); 
  else { 
    *free=1; 
    return gdkimage_from_pikeimage(o,GDK_IMAGE_FASTEST,0); 
  } 
} 
 
void pgtk2__pixmap_draw(GdkImage *i) 
{ 
  GdkGC *gc; 
  if (THIS->extra_data) 
    gc=THIS->extra_data; 
  else 
    THIS->extra_data=gc=gdk_gc_new(GDK_DRAWABLE(THIS->obj)); 
  gdk_draw_image(GDK_DRAWABLE(THIS->obj),gc,i,0,0,0,0, 
                  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; 
  GdkPixmap *gp; 
  pgtk2_verify_setup(); 
  pgtk2_verify_not_inited(); 
 
  if (TYPEOF(Pike_sp[-args]) == PIKE_T_OBJECT) { 
    get_all_args(NULL,args,"%o",&o); 
    i=pgtk2_pixmap_setup(o,&f); 
 
    gp=gdk_pixmap_new(0,i->width,i->height,i->depth); 
    THIS->obj=G_OBJECT(gp); 
    if (!THIS->obj) { 
      if (f) 
        g_object_unref(i); 
      Pike_error("Failed to create pixmap.\n"); 
    } 
    pgtk2__pixmap_draw(i); 
    if (f) 
      g_object_unref(i); 
  } else if (args && TYPEOF(Pike_sp[-1]) == PIKE_T_INT) { 
    gp=gdk_pixmap_foreign_new(Pike_sp[-1].u.integer); 
    THIS->obj=G_OBJECT(gp); 
    if (!THIS->obj) 
      Pike_error("Failed to find remote pixmap\n"); 
  } 
  pgtk2_pop_n_elems(args); 
  pgtk2__init_this_object(); 
} 
 
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(NULL, args, "%o", &o ); 
  pgtk2__pixmap_draw(i=pgtk2_pixmap_setup(o,&f)); 
  if (f) 
    g_object_unref(i); 
 
  RETURN_THIS(); 
} 
 
void _destruct() 
{ 
  /* 
      if (THIS->obj) 
      g_object_unref(THIS->obj); 
      THIS->obj=0; 
       
      Done by g.object 
  */ 
 
  if (THIS->extra_data) 
    g_object_unref(THIS->extra_data); 
  THIS->extra_data=0; 
  pgtk2_pop_n_elems(args); 
  push_int(0); 
} 
 
void ref() 
//! Ref this object. 
{ 
  g_object_ref(THIS->obj); 
  RETURN_THIS(); 
} 
 
void unref() 
//! Unref this object. 
{ 
  g_object_unref(THIS->obj); 
  RETURN_THIS(); 
}