summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/ProgressBarDrawData.java
blob: 04d3ea98258500c288c10d27e362276fc45b177e (plain)
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
/*******************************************************************************
 * Copyright (c) 2000, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.internal.theme;

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

public class ProgressBarDrawData extends RangeDrawData {

public ProgressBarDrawData() {
	state = new int[1];
}

void draw(Theme theme, GC gc, Rectangle bounds) {
	int /*long*/ progressHandle = theme.progressHandle;
	int /*long*/ gtkStyle = OS.gtk_widget_get_style (progressHandle);
	int /*long*/ drawable = gc.getGCData().drawable;
	theme.transferClipping(gc, gtkStyle);
	byte[] detail = Converter.wcsToMbcs(null, "trough", true);
	int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
	OS.gtk_paint_box(gtkStyle, drawable, getStateType(DrawData.WIDGET_WHOLE), OS.GTK_SHADOW_IN, null, progressHandle, detail, x, y, width, height);
	int xthichness = OS.gtk_style_get_xthickness(gtkStyle);
	int ythichness = OS.gtk_style_get_ythickness(gtkStyle);
	if ((style & SWT.VERTICAL) != 0) {
		OS.gtk_progress_bar_set_orientation(progressHandle, OS.GTK_PROGRESS_BOTTOM_TO_TOP);
		x += xthichness;
		width -= xthichness * 2;
		height -= ythichness * 2;
		height *= selection / (float)Math.max(1, (maximum - minimum));
		y += bounds.height - ythichness - height;
	} else {
		OS.gtk_progress_bar_set_orientation(progressHandle, OS.GTK_PROGRESS_LEFT_TO_RIGHT);
		x += xthichness;
		y += ythichness;
		width -= xthichness * 2;
		height -= ythichness * 2;
		width *= selection / (float)Math.max(1, maximum - minimum);
	}
	detail = Converter.wcsToMbcs(null, "bar", true);
	OS.gtk_paint_box(gtkStyle, drawable, OS.GTK_STATE_PRELIGHT, OS.GTK_SHADOW_OUT, null, progressHandle, detail, x, y, width, height);
}

int getStateType(int part) {
	return OS.GTK_STATE_NORMAL;
}

int hit(Theme theme, Point position, Rectangle bounds) {
	return bounds.contains(position) ? DrawData.WIDGET_WHOLE : DrawData.WIDGET_NOWHERE;
}

}