summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT Theme/gtk/org/eclipse/swt/internal/theme/ComboDrawData.java
blob: dfe64201a529cafa5d6b103f8a9ec20c4d91cd93 (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
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
/*******************************************************************************
 * Copyright (c) 2000, 2010 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.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gtk.*;

public class ComboDrawData extends DrawData {

	static final int ARROW_HEIGHT = 6;
	static final int MIN_ARROW_SIZE = 15;

public ComboDrawData() {
	state = new int[2];
}

void draw(Theme theme, GC gc, Rectangle bounds) {
	long /*int*/ buttonHandle = theme.buttonHandle;
	long /*int*/ gtkStyle = OS.gtk_widget_get_style(buttonHandle);
	long /*int*/ drawable = gc.getGCData().drawable;
	theme.transferClipping(gc, gtkStyle);
	
	int x = bounds.x;
	int y = bounds.y ;
	int width = bounds.width;
	int height = bounds.height;

	int shadow_type = OS.GTK_SHADOW_OUT;
	if ((state[DrawData.COMBO_ARROW] & DrawData.PRESSED) != 0) shadow_type = OS.GTK_SHADOW_IN;
	int state_type = getStateType(DrawData.COMBO_ARROW);
	
	int relief = OS.gtk_button_get_relief(buttonHandle);
	int interior_focus = theme.getWidgetProperty(buttonHandle, "interior-focus");
	int focus_line_width = theme.getWidgetProperty(buttonHandle, "focus-line-width");
	int focus_padding = theme.getWidgetProperty(buttonHandle, "focus-padding");
	int xthickness = OS.gtk_style_get_xthickness(gtkStyle);
	int ythickness = OS.gtk_style_get_xthickness(gtkStyle);
	int arrow_width = MIN_ARROW_SIZE;
	int arrow_height = ARROW_HEIGHT;
	int x_border = xthickness + focus_padding;
	//int y_border = ythickness + focus_padding;
	if (interior_focus == 0) {
		x_border += focus_line_width;
		//y_border += focus_line_width;
	}
	int arrow_button_width = arrow_width + x_border * 2;		
	int arrow_button_x = x + width - arrow_button_width;
	int arrow_x = arrow_button_x + (arrow_button_width - arrow_width) / 2;
	int arrow_y = y + (height - arrow_height) / 2 + 1;
	if (relief != OS.GTK_RELIEF_NONE || ((state[DrawData.COMBO_ARROW] & (DrawData.PRESSED | DrawData.HOT)) != 0)) {
		byte[] detail = Converter.wcsToMbcs(null, "button", true);
		OS.gtk_paint_box(gtkStyle, drawable, state_type, shadow_type, null, buttonHandle, detail, arrow_button_x, y, arrow_button_width, height);
	}		
	byte[] arrow_detail = Converter.wcsToMbcs(null, "arrow", true);
	long /*int*/ arrowHandle = theme.arrowHandle;
	OS.gtk_paint_arrow(gtkStyle, drawable, state_type, OS.GTK_SHADOW_OUT, null, arrowHandle, arrow_detail, OS.GTK_ARROW_DOWN, true, arrow_x, arrow_y, arrow_width, arrow_height);
	
	long /*int*/ entryHandle = theme.entryHandle;
	gtkStyle = OS.gtk_widget_get_style(entryHandle);
	theme.transferClipping(gc, gtkStyle);
	state_type = getStateType(DrawData.WIDGET_WHOLE);
	byte[] detail = Converter.wcsToMbcs(null, "entry", true);
	OS.gtk_paint_shadow(gtkStyle, drawable, OS.GTK_STATE_NORMAL, OS.GTK_SHADOW_IN, null, entryHandle, detail, x, y, width - arrow_button_width, height);
	xthickness = OS.gtk_style_get_xthickness(gtkStyle);
	ythickness = OS.gtk_style_get_xthickness(gtkStyle);
	x += xthickness;
	y += ythickness;
	width -= 2 * xthickness;
	height -= 2 * ythickness;
	detail = Converter.wcsToMbcs(null, "entry_bg", true);
	gtk_render_frame (gtkStyle, drawable, state_type, OS.GTK_SHADOW_NONE, null, entryHandle, detail, x, y, width - arrow_button_width, height);
		
	if (clientArea != null) {
		clientArea.x = x;
		clientArea.y = y;
		clientArea.width = width - arrow_button_width;
		clientArea.height = height;
	}	
}

int getStateType(int part) {
	if (part == DrawData.WIDGET_WHOLE) {
		int state_type = OS.GTK_STATE_NORMAL;
		if ((state[DrawData.WIDGET_WHOLE] & DrawData.DISABLED) != 0) {
			state_type = OS.GTK_STATE_INSENSITIVE;
		}
		return state_type;
	}
	return super.getStateType(part);
}

int hit(Theme theme, Point position, Rectangle bounds) {
	if (!bounds.contains(position)) return DrawData.WIDGET_NOWHERE;
	long /*int*/ buttonHandle = theme.buttonHandle;
	long /*int*/ gtkStyle = OS.gtk_widget_get_style(buttonHandle);
	int interior_focus = theme.getWidgetProperty(buttonHandle, "interior-focus");
	int focus_line_width = theme.getWidgetProperty(buttonHandle, "focus-line-width");
	int focus_padding = theme.getWidgetProperty(buttonHandle, "focus-padding");
	int xthickness = OS.gtk_style_get_xthickness(gtkStyle);
//	int ythickness = OS.gtk_style_get_xthickness(gtkStyle);
	int arrow_width = MIN_ARROW_SIZE;
	int x_border = xthickness + focus_padding;
	//int y_border = ythickness + focus_padding;
	if (interior_focus == 0) {
		x_border += focus_line_width;
		//y_border += focus_line_width;
	}
	int arrow_button_width = arrow_width + x_border * 2;		
	int arrow_button_x = bounds.x + bounds.width - arrow_button_width;

	Rectangle arrowRect = new Rectangle(arrow_button_x, bounds.y, arrow_button_width, bounds.height);
	if (arrowRect.contains(position)) return DrawData.COMBO_ARROW;
	return DrawData.WIDGET_WHOLE;
}

}