1 #include <stdio.h>
2 #include <X11/IntrinsicP.h>
3 #include <X11/StringDefs.h>
4
5 #include <X11/Core.h>
6
7 #include "PixCore.h"
8 #include "PixCoreP.h"
9
10 #include "image.h"
11
12 static void Initialize(Widget, Widget, ArgList args, Cardinal * num);
13 static void Destroy(Widget);
14 static void Realize(Widget, XtValueMask*, XSetWindowAttributes *);
15 static Boolean SetValues(Widget, Widget, Widget, ArgList, Cardinal *);
16
17 static XtResource resources[] = {
18 {XtNfile, XtCFile, XtRString, sizeof(String),
19 XtOffsetOf(PixCoreRec,pixcore.filename), XtRImmediate, (String)NULL}
20 };
21
22 #define superclass (&coreClassRec)
23 PixCoreClassRec pixCoreClassRec = {
24 {
25 /* superclass */ (WidgetClass) superclass,
26 /* class_name */ "PixCore",
27 /* size */ sizeof(PixCoreRec),
28 /* class_initialize */ NULL,
29 /* class_part_initialize */ NULL,
30 /* Class init'ed */ FALSE,
31 /* initialize */ Initialize,
32 /* initialize_hook */ NULL,
33 /* realize */ Realize,
34 /* actions */ NULL,
35 /* num_actions */ 0,
36 /* resources */ resources,
37 /* resource_count */ XtNumber(resources),
38 /* xrm_class */ NULLQUARK,
39 /* compress_motion */ FALSE,
40 /* compress_exposure */ FALSE,
41 /* compress_enterleave */ FALSE,
42 /* visible_interest */ FALSE,
43 /* destroy */ Destroy,
44 /* resize */ XtInheritResize,
45 /* expose */ XtInheritExpose,
46 /* set_values */ SetValues,
47 /* set_values_hook */ NULL,
48 /* set_values_almost */ XtInheritSetValuesAlmost,
49 /* get_values_hook */ NULL,
50 /* accept_focus */ NULL,
51 /* intrinsics version */ XtVersion,
52 /* callback offsets */ NULL,
53 /* tm_table */ NULL,
54 /* query_geometry */ NULL,
55 /* display_accelerator */ NULL,
56 /* extension */ NULL
57 }
58 };
59
60 WidgetClass pixCoreWidgetClass = (WidgetClass) & pixCoreClassRec;
61
62 #define FILENAME (pcw->pixcore.filename)
63 #define IMAGE (pcw->pixcore.image)
64 #define OLDFILENAME (old->pixcore.filename)
65 #define OLDIMAGE (old->pixcore.image)
66
67 static void
Initialize(Widget req,Widget new,ArgList args,Cardinal * num)68 Initialize(Widget req, Widget new, ArgList args, Cardinal * num)
69 {
70 PixCoreWidget pcw = (PixCoreWidget)new;
71 IMAGE = image_new();
72 if (FILENAME) {
73 image_load(IMAGE,FILENAME,-1,-1);
74 pcw->core.width = IMAGE->width;
75 pcw->core.height = IMAGE->height;
76 }
77 }
78
79 static void
Destroy(Widget widget)80 Destroy(Widget widget)
81 {
82 PixCoreWidget pcw = (PixCoreWidget)widget;
83 image_delete(IMAGE);
84 }
85
86 static void
Realize(Widget widget,XtValueMask * value_mask,XSetWindowAttributes * attr)87 Realize(Widget widget, XtValueMask *value_mask, XSetWindowAttributes *attr)
88 {
89 PixCoreWidget pcw = (PixCoreWidget)widget;
90
91 XtCreateWindow(widget, (u_int)InputOutput,
92 (Visual*)CopyFromParent, *value_mask, attr);
93
94 if (IMAGE->data != NULL) {
95 XSetWindowAttributes attributes;
96 Pixmap p;
97
98 image_set_col(IMAGE, XtDisplay(widget), XtWindow(widget));
99 p = image_pixmap(IMAGE, NULL);
100 attributes.background_pixmap = p;
101 XChangeWindowAttributes(XtDisplay(widget),
102 XtWindow(widget), CWBackPixmap, &attributes);
103
104 image_free_data(IMAGE);
105 image_free_pixmap(IMAGE);
106 }
107 }
108
109 static Boolean
SetValues(Widget cur,Widget req,Widget new,ArgList args,Cardinal * num_args)110 SetValues(Widget cur, Widget req, Widget new, ArgList args, Cardinal *num_args)
111 {
112 PixCoreWidget old = (PixCoreWidget)cur;
113 PixCoreWidget pcw = (PixCoreWidget)new;
114 Boolean redisplay = FALSE;
115
116 if (OLDFILENAME != FILENAME) {
117
118 image_delete(OLDIMAGE);
119
120 IMAGE = image_new();
121 image_load(IMAGE,FILENAME,-1,-1);
122 pcw->core.width = IMAGE->width;
123 pcw->core.height = IMAGE->height;
124
125 if (XtIsRealized(cur)) {
126 XSetWindowAttributes attributes;
127 Pixmap p;
128
129 image_set_col(IMAGE, XtDisplay(new), XtWindow(new));
130 p = image_pixmap(IMAGE, NULL);
131 attributes.background_pixmap = p;
132 XChangeWindowAttributes(XtDisplay(new), XtWindow(new),
133 CWBackPixmap, &attributes);
134
135 image_free_data(IMAGE);
136 image_free_pixmap(IMAGE);
137 redisplay = TRUE;
138 }
139 }
140
141 return redisplay;
142 }
143
144
145