Skip to main content
summaryrefslogtreecommitdiffstats
blob: ff740b3b533591d992801b30907930b61abbfed9 (plain) (blame)
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package org.eclipse.swt.graphics;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved
 */

import org.eclipse.swt.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.photon.*;

public abstract class Device implements Drawable {
	
	/* Debugging */
	public static boolean DEBUG;
	boolean debug = DEBUG;
	public boolean tracking = DEBUG;
	Error [] errors;
	Object [] objects;

	boolean disposed;
	
	/*
	* TEMPORARY CODE. When a graphics object is
	* created and the device parameter is null,
	* the current Display is used. This presents
	* a problem because SWT graphics does not
	* reference classes in SWT widgets. The correct
	* fix is to remove this feature. Unfortunately,
	* too many application programs rely on this
	* feature.
	*
	* This code will be removed in the future.
	*/
	protected static Device CurrentDevice;
	protected static Runnable DeviceFinder;
	static {
		try {
			Class.forName ("org.eclipse.swt.widgets.Display");
		} catch (Throwable e) {}
	}	

static Device getDevice () {
	if (DeviceFinder != null) DeviceFinder.run();
	Device device = CurrentDevice;
	CurrentDevice = null;
	return device;
}
		
public Device(DeviceData data) {
	if (data != null) {
		debug = data.debug;
		tracking = data.tracking;
	}
	create (data);
	init ();
	if (tracking) {
		errors = new Error [128];
		objects = new Object [128];
	}
}

protected void checkDevice () {
	if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED);
}

protected void create (DeviceData data) {
}

protected void destroy () {
}

public void dispose () {
	if (isDisposed()) return;
	checkDevice ();
	release ();
	destroy ();
	disposed = true;
	if (tracking) {
		objects = null;
		errors = null;
	}
}

void dispose_Object (Object object) {
	for (int i=0; i<objects.length; i++) {
		if (objects [i] == object) {
			objects [i] = null;
			errors [i] = null;
			return;
		}
	}
}

public Rectangle getBounds () {
	checkDevice ();
	PhRect_t rect = new PhRect_t ();
	OS.PhWindowQueryVisible (OS.Ph_QUERY_GRAPHICS, 0, 1, rect);
	int width = rect.lr_x - rect.ul_x + 1;
	int height = rect.lr_y - rect.ul_y + 1;
	return new Rectangle (rect.ul_x, rect.ul_y, width, height);
}

public Rectangle getClientArea () {
	return getBounds ();
}

public int getDepth () {
	checkDevice ();
	//NOT DONE
	return 32;
}

public DeviceData getDeviceData () {
	checkDevice();
	DeviceData data = new DeviceData ();
	data.debug = debug;
	data.tracking = tracking;
	int count = 0, length = 0;
	if (tracking) length = objects.length;
	for (int i=0; i<length; i++) {
		if (objects [i] != null) count++;
	}
	int index = 0;
	data.objects = new Object [count];
	data.errors = new Error [count];
	for (int i=0; i<length; i++) {
		if (objects [i] != null) {
			data.objects [index] = objects [i];
			data.errors [index] = errors [i];
			index++;
		}
	}
	return data;
}

public Point getDPI () {
	checkDevice ();
	//NOT DONE
	return new Point (96, 96);
}

public FontData [] getFontList (String faceName, boolean scalable) {
	checkDevice ();
	int flags = OS.PHFONT_FIXED | OS.PHFONT_PROP | OS.PFFONT_DONT_SHOW_LEGACY;
	flags |= scalable ? OS.PHFONT_SCALABLE : OS.PHFONT_BITMAP;
	int nfonts = OS.PfQueryFonts(OS.PHFONT_ALL_FONTS, flags, 0, 0);
	if (nfonts <= 0) return new FontData[0];
	
	int list_ptr = OS.malloc(nfonts * FontDetails.sizeof);
	nfonts = OS.PfQueryFonts(OS.PHFONT_ALL_FONTS, flags, list_ptr, nfonts);
	int ptr = list_ptr;
	int nFds = 0;
	FontData[] fds = new FontData[faceName != null ? 4 : nfonts];
	FontDetails details = new FontDetails();
	for (int i = 0; i < nfonts; i++) {
		OS.memmove(details, ptr, FontDetails.sizeof);
		String name = new String(Converter.mbcsToWcs(null, details.desc)).trim();
		if (faceName == null || faceName.equalsIgnoreCase(name)) {
			int size;
			if (details.losize == 0 && details.hisize == 0) size = 9; // This value was taken from the PhAB editor
			else size = details.losize;
			flags = details.flags & ~(OS.PHFONT_INFO_PROP | OS.PHFONT_INFO_FIXED);
			while (flags != 0) {
				int style;
				if ((flags & OS.PHFONT_INFO_PLAIN) != 0) {
					style = SWT.NORMAL;
					flags &= ~OS.PHFONT_INFO_PLAIN;
				} else if ((flags & OS.PHFONT_INFO_BOLD) != 0) {
					style = SWT.BOLD;
					flags &= ~OS.PHFONT_INFO_BOLD;
				} else if ((flags & OS.PHFONT_INFO_ITALIC) != 0) {
					style = SWT.ITALIC;
					flags &= ~OS.PHFONT_INFO_ITALIC;
				} else if ((flags & OS.PHFONT_INFO_BLDITC) != 0) {
					style = SWT.BOLD | SWT.ITALIC;
					flags &= ~OS.PHFONT_INFO_BLDITC;
				} else break;					
				if (nFds == fds.length) {
					FontData[] newFds = new FontData[fds.length + nfonts];
					System.arraycopy(fds, 0, newFds, 0, nFds);
					fds = newFds;
				}
				fds[nFds++] = new FontData(name, size, style);
			}
		}
		ptr += FontDetails.sizeof;
	}
	OS.free(list_ptr);

	if (nFds == fds.length) return fds;

	FontData[] result = new FontData[nFds];
	System.arraycopy(fds, 0, result, 0, nFds);
	return result;
}

public Color getSystemColor (int id) {
	checkDevice ();
	int color = 0x000000;
	switch (id) {
		case SWT.COLOR_BLACK: 		color = 0x000000; break;
		case SWT.COLOR_DARK_RED: 	color = 0x800000; break;
		case SWT.COLOR_DARK_GREEN:	color = 0x008000; break;
		case SWT.COLOR_DARK_YELLOW: 	color = 0x808000; break;
		case SWT.COLOR_DARK_BLUE: 	color = 0x000080; break;
		case SWT.COLOR_DARK_MAGENTA: 	color = 0x800080; break;
		case SWT.COLOR_DARK_CYAN: 	color = 0x008080; break;
		case SWT.COLOR_GRAY: 		color = 0x808080; break;
		case SWT.COLOR_DARK_GRAY: 	color = 0x404040; break;
		case SWT.COLOR_RED: 		color = 0xFF0000; break;
		case SWT.COLOR_GREEN: 		color = 0x00FF00; break;
		case SWT.COLOR_YELLOW: 		color = 0xFFFF00; break;
		case SWT.COLOR_BLUE: 		color = 0x0000FF; break;
		case SWT.COLOR_MAGENTA: 	color = 0xFF00FF; break;
		case SWT.COLOR_CYAN: 		color = 0x00FFFF; break;
		case SWT.COLOR_WHITE: 		color = 0xFFFFFF; break;
	}
	return Color.photon_new (this, color);
}

public Font getSystemFont () {
	checkDevice ();
	return Font.photon_new (this, Font.DefaultFont);
}

public boolean getWarnings () {
	checkDevice ();
	return false;
}

protected void init () {
}

public abstract int internal_new_GC (GCData data);

public abstract void internal_dispose_GC (int handle, GCData data);

public boolean isDisposed () {
	return disposed;
}

void new_Object (Object object) {
	for (int i=0; i<objects.length; i++) {
		if (objects [i] == null) {
			objects [i] = object;
			errors [i] = new Error ();
			return;
		}
	}
	Object [] newObjects = new Object [objects.length + 128];
	System.arraycopy (objects, 0, newObjects, 0, objects.length);
	newObjects [objects.length] = object;
	objects = newObjects;
	Error [] newErrors = new Error [errors.length + 128];
	System.arraycopy (errors, 0, newErrors, 0, errors.length);
	newErrors [errors.length] = new Error ();
	errors = newErrors;
}

protected void release () {
}

public void setWarnings (boolean warnings) {
	checkDevice ();
}

}

Back to the top