Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6a6d902ecd9bdec712d7bd98d65c24b7f1f7710b (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
package org.eclipse.swt.widgets;

/*
* Licensed Materials - Property of IBM,
* SWT - The Simple Widget Toolkit,
* (c) Copyright IBM Corp 1998, 1999.
*/

/**
*	The canvas class implements a drawing area for
* arbitrary graphics.
*
* Styles
*
*	NO_BACKGROUND,
*	NO_FOCUS,
*	MERGE_EXPOSES,
*	RESIZE_REDRAW
*
* Events
*
**/

/* Imports */
import org.eclipse.swt.internal.motif.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;

/* Class Definition */
public class Canvas extends Composite {
	Caret caret;
	
Canvas () {
	/* Do nothing */
}
/**
* Create a Canvas.
*
* PARAMTERS
*
*	parent		a composite widget (cannot be null)
*	style		the bitwise OR'ing of widget styles
*
* REMARKS
*
*	This method creates a child widget using style bits
* to select a particular look or set of properties. 
*
**/
public Canvas (Composite parent, int style) {
	super (parent, style);
}
void createWidget (int index) {
	super.createWidget (index);
	fontList = defaultFont ();
}
/**
* Get the current caret.
*
* REMARKS
*
*	This method gets the current caret for the window.
* The current caret is automatically hidden and shown
* by the window when:
*
*	- during expose and resize
*	- when focus is gained or lost
*	- when an the window is scrolled
*
**/
public Caret getCaret () {
	if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
	if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
	return caret;
}

int processFocusIn () {
	int result = super.processFocusIn ();
	if (caret != null) caret.setFocus ();
	return result;
}
int processFocusOut () {
	int result = super.processFocusOut ();
	if (caret != null) caret.killFocus ();
	return result;
}

int processPaint (int callData) {
	boolean isFocus = caret != null && caret.isFocusCaret ();
	if (isFocus) caret.killFocus ();
	int result = super.processPaint (callData);
	if (isFocus) caret.setFocus ();
	return result;
}

void redrawWidget (int x, int y, int width, int height, boolean all) {
	boolean isFocus = caret != null && caret.isFocusCaret ();
	if (isFocus) caret.killFocus ();
	super.redrawWidget (x, y, width, height, all);
	if (isFocus) caret.setFocus ();
}

void releaseWidget () {
	if (caret != null) {
		caret.releaseWidget ();
		caret.releaseHandle ();
	}
	caret = null;
	super.releaseWidget();
}

public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
	if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
	if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
	if (width <= 0 || height <= 0) return;
	int deltaX = destX - x, deltaY = destY - y;
	if (deltaX == 0 && deltaY == 0) return;
	if (!isVisible ()) return;
		
	/* Hide the caret */
	boolean isFocus = caret != null && caret.isFocusCaret ();
	if (isFocus) caret.killFocus ();
	
	/* Flush outstanding exposes */
	int xDisplay = OS.XtDisplay (handle);
	if (xDisplay == 0) return;
	int xWindow = OS.XtWindow (handle);
	if (xWindow == 0) return;
	XAnyEvent xEvent = new XAnyEvent ();
	OS.XSync (xDisplay, false);  OS.XSync (xDisplay, false);
	while (OS.XCheckWindowEvent (xDisplay, xWindow, OS.ExposureMask, xEvent)) {
		OS.XtDispatchEvent (xEvent);
	}

	/* Scroll the window */
	int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null);
	OS.XCopyArea (xDisplay, xWindow, xWindow, xGC, x, y, width, height, destX, destY);
	OS.XFreeGC (xDisplay, xGC);
	boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY);
	if (disjoint) {
		OS.XClearArea (xDisplay, xWindow, x, y, width, height, true);
	} else {
		if (deltaX != 0) {
			int newX = destX - deltaX;
			if (deltaX < 0) newX = destX + width;
			OS.XClearArea (xDisplay, xWindow, newX, y, Math.abs (deltaX), height, true);
		}
		if (deltaY != 0) {
			int newY = destY - deltaY;
			if (deltaY < 0) newY = destY + height;
			OS.XClearArea (xDisplay, xWindow, x, newY, width, Math.abs (deltaY), true);
		}
	}
	
	/* Show the caret */
	if (isFocus) caret.setFocus ();
}
public void setBounds (int x, int y, int width, int height) {
	if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
	if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
	boolean isFocus = caret != null && caret.isFocusCaret ();
	if (isFocus) caret.killFocus ();
	super.setBounds (x, y, width, height);
	if (isFocus) caret.setFocus ();
}
/**
* Set the current caret.
*
* PARAMTERS
*
* 	caret - the new caret or null
*
* REMARKS
*
*	This method sets the current caret for the window.
* The current caret is automatically hidden and shown
* by the window when:
*
*	- during expose and resize
*	- when focus is gained or lost
*	- when an the window is scrolled
*
**/
public void setCaret (Caret caret) {
	if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
	if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
	Caret newCaret = caret;
	Caret oldCaret = this.caret;
	this.caret = newCaret;
	if (hasFocus ()) {
		if (oldCaret != null) oldCaret.killFocus ();
		if (newCaret != null) newCaret.setFocus ();
	}
}

public void setLocation (int x, int y) {
	if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
	if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
	boolean isFocus = caret != null && caret.isFocusCaret ();
	if (isFocus) caret.killFocus ();
	super.setLocation (x, y);
	if (isFocus) caret.setFocus ();
}
public void setSize (int width, int height) {
	if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
	if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
	boolean isFocus = caret != null && caret.isFocusCaret ();
	if (isFocus) caret.killFocus ();
	super.setSize (width, height);
	if (isFocus) caret.setFocus ();
}
}

Back to the top