-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPixCore.c
144 lines (119 loc) · 3.8 KB
/
PixCore.c
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Core.h>
#include "PixCore.h"
#include "PixCoreP.h"
#include "image.h"
static void Initialize(Widget, Widget, ArgList args, Cardinal * num);
static void Destroy(Widget);
static void Realize(Widget, XtValueMask*, XSetWindowAttributes *);
static Boolean SetValues(Widget, Widget, Widget, ArgList, Cardinal *);
static XtResource resources[] = {
{XtNfile, XtCFile, XtRString, sizeof(String),
XtOffsetOf(PixCoreRec,pixcore.filename), XtRImmediate, (String)NULL}
};
#define superclass (&coreClassRec)
PixCoreClassRec pixCoreClassRec = {
{
/* superclass */ (WidgetClass) superclass,
/* class_name */ "PixCore",
/* size */ sizeof(PixCoreRec),
/* class_initialize */ NULL,
/* class_part_initialize */ NULL,
/* Class init'ed */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ Realize,
/* actions */ NULL,
/* num_actions */ 0,
/* resources */ resources,
/* resource_count */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ FALSE,
/* compress_exposure */ FALSE,
/* compress_enterleave */ FALSE,
/* visible_interest */ FALSE,
/* destroy */ Destroy,
/* resize */ XtInheritResize,
/* expose */ XtInheritExpose,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* intrinsics version */ XtVersion,
/* callback offsets */ NULL,
/* tm_table */ NULL,
/* query_geometry */ NULL,
/* display_accelerator */ NULL,
/* extension */ NULL
}
};
WidgetClass pixCoreWidgetClass = (WidgetClass) & pixCoreClassRec;
#define FILENAME (pcw->pixcore.filename)
#define IMAGE (pcw->pixcore.image)
#define OLDFILENAME (old->pixcore.filename)
#define OLDIMAGE (old->pixcore.image)
static void
Initialize(Widget req, Widget new, ArgList args, Cardinal * num)
{
PixCoreWidget pcw = (PixCoreWidget)new;
IMAGE = image_new();
if (FILENAME) {
image_load(IMAGE,FILENAME,-1,-1);
pcw->core.width = IMAGE->width;
pcw->core.height = IMAGE->height;
}
}
static void
Destroy(Widget widget)
{
PixCoreWidget pcw = (PixCoreWidget)widget;
image_delete(IMAGE);
}
static void
Realize(Widget widget, XtValueMask *value_mask, XSetWindowAttributes *attr)
{
PixCoreWidget pcw = (PixCoreWidget)widget;
XtCreateWindow(widget, (u_int)InputOutput,
(Visual*)CopyFromParent, *value_mask, attr);
if (IMAGE->data != NULL) {
XSetWindowAttributes attributes;
Pixmap p;
image_set_col(IMAGE, XtDisplay(widget), XtWindow(widget));
p = image_pixmap(IMAGE, NULL);
attributes.background_pixmap = p;
XChangeWindowAttributes(XtDisplay(widget),
XtWindow(widget), CWBackPixmap, &attributes);
image_free_data(IMAGE);
image_free_pixmap(IMAGE);
}
}
static Boolean
SetValues(Widget cur, Widget req, Widget new, ArgList args, Cardinal *num_args)
{
PixCoreWidget old = (PixCoreWidget)cur;
PixCoreWidget pcw = (PixCoreWidget)new;
Boolean redisplay = FALSE;
if (OLDFILENAME != FILENAME) {
image_delete(OLDIMAGE);
IMAGE = image_new();
image_load(IMAGE,FILENAME,-1,-1);
pcw->core.width = IMAGE->width;
pcw->core.height = IMAGE->height;
if (XtIsRealized(cur)) {
XSetWindowAttributes attributes;
Pixmap p;
image_set_col(IMAGE, XtDisplay(new), XtWindow(new));
p = image_pixmap(IMAGE, NULL);
attributes.background_pixmap = p;
XChangeWindowAttributes(XtDisplay(new), XtWindow(new),
CWBackPixmap, &attributes);
image_free_data(IMAGE);
image_free_pixmap(IMAGE);
redisplay = TRUE;
}
}
return redisplay;
}