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

/*
 * Licensed Materials - Property of IBM,
 * (c) Copyright IBM Corp. 1998, 2001  All Rights Reserved
 */

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

public abstract class Scrollable extends Control {
	int scrolledHandle;
	ScrollBar horizontalBar, verticalBar;

Scrollable () {
	/* Do nothing */
}

public Scrollable (Composite parent, int style) {
	super (parent, style);
}

void createScrollBars () {
	/* Search the handle to find the scroll bars */
	int child = OS.PtWidgetChildFront (handle);
	while (child != 0) {
		if (OS.PtWidgetClass (child) == OS.PtScrollbar ()) {
			int [] args = {OS.Pt_ARG_ORIENTATION, 0, 0};
			OS.PtGetResources (child, args.length / 3, args);
			switch (args [1]) {
				case OS.Pt_HORIZONTAL:
					horizontalBar = new ScrollBar (this, SWT.HORIZONTAL, child);
					break;
				case OS.Pt_VERTICAL:
					verticalBar = new ScrollBar (this, SWT.VERTICAL, child);
					break;
			}
		}
		child = OS.PtWidgetBrotherBehind (child);
	}
}

void deregister () {
	super.deregister ();
	if (scrolledHandle != 0) WidgetTable.remove (scrolledHandle);
}

public Rectangle computeTrim (int x, int y, int width, int height) {
	if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
	if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
	PhRect_t rect = new PhRect_t ();
	PhArea_t area = new PhArea_t ();
	rect.ul_x = (short) x;
	rect.ul_y = (short) y;
	rect.lr_x = (short) (x + width - 1);
	rect.lr_y = (short) (y + height - 1);
	OS.PtSetAreaFromWidgetCanvas (scrolledHandle != 0 ? scrolledHandle : handle, rect, area);
	if (horizontalBar != null && horizontalBar.getVisible ()) {
		Point size = horizontalBar.getSize ();
		area.size_h += size.y;
	}
	if (verticalBar != null && verticalBar.getVisible ()) {
		Point size = verticalBar.getSize ();
		area.size_w += size.x;
	}
	return new Rectangle (area.pos_x, area.pos_y, area.size_w, area.size_h);
}

public Rectangle getClientArea () {
	if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
	if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
	PhRect_t rect = new PhRect_t ();
	int vParent = OS.PtValidParent (handle, OS.PtContainer ());
	if (!OS.PtWidgetIsRealized (handle)) OS.PtExtentWidgetFamily (handle);
	OS.PtCalcCanvas (vParent, rect);
	int width = rect.lr_x - rect.ul_x + 1;
	int height = rect.lr_y - rect.ul_y + 1;
	return new Rectangle (0, 0, width, height);
}

public ScrollBar getHorizontalBar () {
	if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
	if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
	return horizontalBar;
}

public ScrollBar getVerticalBar () {
	if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
	if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
	return verticalBar;
}

void releaseHandle () {
	super.releaseHandle ();
	scrolledHandle = 0;
}

void resizeClientArea () {
	/* Do nothing */
}

void releaseWidget () {
	if (horizontalBar != null) horizontalBar.releaseWidget ();
	if (verticalBar != null) verticalBar.releaseWidget ();
	horizontalBar = verticalBar = null;
	super.releaseWidget ();
}

void register () {
	super.register ();
	if (scrolledHandle != 0) WidgetTable.put (scrolledHandle, this);
}

int topHandle () {
	if (scrolledHandle == 0) return handle;
	return scrolledHandle;
}

}

Back to the top