summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT Theme/win32/org/eclipse/swt/internal/theme/ComboDrawData.java
blob: 49da9f35bd4e0e200a47126b8148666d38f0a554 (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
/*******************************************************************************
 * Copyright (c) 2000, 2007 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.win32.*;

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

void draw(Theme theme, GC gc, Rectangle bounds) {
	if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
		int /*long*/ hTheme = OS.OpenThemeData(0, EDIT);
		RECT rect = new RECT ();
		rect.left = bounds.x;
		rect.right = bounds.x + bounds.width;
		rect.top = bounds.y;
		rect.bottom = bounds.y + bounds.height;
		int[] part = getPartId(DrawData.WIDGET_WHOLE);
		OS.DrawThemeBackground (hTheme, gc.handle, part[0], part[1], rect, null);
		RECT contentRect = new RECT();
		OS.GetThemeBackgroundContentRect(hTheme, gc.handle, part[0], part[1], rect, contentRect);				
		Rectangle clientArea = this.clientArea;
		if (clientArea != null) {
			clientArea.x = contentRect.left;
			clientArea.y = contentRect.top;
			clientArea.width = contentRect.right - contentRect.left;
			clientArea.height = contentRect.bottom - contentRect.top;
		}
		OS.CloseThemeData(hTheme);
		hTheme = OS.OpenThemeData(0, getClassId());
		int width = OS.GetThemeSysSize(hTheme, OS.SM_CXVSCROLL);
		rect.left = contentRect.right - width;
		rect.top = contentRect.top;
		rect.right = contentRect.right;
		rect.bottom = contentRect.bottom;
		part = getPartId(DrawData.COMBO_ARROW);
		OS.DrawThemeBackground (hTheme, gc.handle, part[0], part[1], rect, null);
		OS.CloseThemeData(hTheme);
		if (clientArea != null) {
			clientArea.width -= width;
		}
	}
}

char[] getClassId() {
	return COMBOBOX;
}

int[] getPartId(int part) {
	int state = this.state[part];
	int iPartId = 0, iStateId = 0;
	switch (part) {
		case DrawData.WIDGET_WHOLE: 
			iPartId = OS.EP_EDITTEXT;
			iStateId = OS.ETS_NORMAL;
			if ((state & DrawData.DISABLED) != 0) iStateId = OS.ETS_DISABLED;
			break;
		case DrawData.COMBO_ARROW:
			iPartId = OS.CP_DROPDOWNBUTTON;
			iStateId = OS.CBXS_NORMAL;
			if ((state & DrawData.DISABLED) != 0) iStateId = OS.CBXS_DISABLED;
			if ((state & DrawData.HOT) != 0) iStateId = OS.CBXS_HOT;
			if ((state & DrawData.PRESSED) != 0) iStateId = OS.CBXS_PRESSED;
			break;
	}
	return new int[]{iPartId, iStateId};	
}

int hit(Theme theme, Point position, Rectangle bounds) {
	if (!(OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ())) return DrawData.WIDGET_NOWHERE;
	if (!bounds.contains(position)) return DrawData.WIDGET_NOWHERE;
	int /*long*/ hTheme = OS.OpenThemeData(0, EDIT);
	int[] part = getPartId(DrawData.WIDGET_WHOLE);
	int iPartId = part[0];
	int iStateId = part[1];
	RECT rect = new RECT ();
	rect.left = bounds.x;
	rect.right = bounds.x + bounds.width;
	rect.top = bounds.y;
	rect.bottom = bounds.y + bounds.height;
	RECT contentRect = new RECT();
	OS.GetThemeBackgroundContentRect(hTheme, 0, iPartId, iStateId, rect, contentRect);
	OS.CloseThemeData(hTheme);
	hTheme = OS.OpenThemeData(0, getClassId());
	int width = OS.GetThemeSysSize(hTheme, OS.SM_CXVSCROLL);
	OS.CloseThemeData(hTheme);
	Rectangle arrowRect = new Rectangle(contentRect.right - width, contentRect.top, contentRect.bottom - contentRect.top, width);
	if (arrowRect.contains(position)) return DrawData.COMBO_ARROW;
	return DrawData.WIDGET_WHOLE;
}

}