001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.swt.internal.theme;
011:
012: import org.eclipse.swt.*;
013: import org.eclipse.swt.graphics.*;
014: import org.eclipse.swt.internal.win32.*;
015:
016: public class ToolItemDrawData extends DrawData {
017:
018: public ToolBarDrawData parent;
019:
020: static final int INSET = 1;
021:
022: public ToolItemDrawData() {
023: state = new int[2];
024: }
025:
026: Rectangle computeTrim(Theme theme, GC gc) {
027: if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
028: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
029: RECT rect = new RECT();
030: rect.left = clientArea.x;
031: rect.right = clientArea.x + clientArea.width;
032: rect.top = clientArea.y;
033: rect.bottom = clientArea.y + clientArea.height;
034: RECT extent = new RECT();
035: int[] part = getPartId(DrawData.WIDGET_WHOLE);
036: OS.GetThemeBackgroundExtent(hTheme, gc.handle, part[0],
037: part[1], rect, extent);
038: OS.CloseThemeData(hTheme);
039: if ((style & SWT.DROP_DOWN) != 0) {
040: SIZE size = new SIZE();
041: part = getPartId(DrawData.TOOLITEM_ARROW);
042: OS.GetThemePartSize(hTheme, 0, part[0], part[1], null,
043: OS.TS_TRUE, size);
044: extent.right = Math.max(extent.left, extent.right
045: + size.cx);
046: } else {
047: extent.left -= INSET;
048: extent.top -= INSET;
049: extent.right += INSET;
050: extent.bottom += INSET;
051: }
052: return new Rectangle(extent.left, extent.top, extent.right
053: - extent.left, extent.bottom - extent.top);
054: }
055: return new Rectangle(0, 0, 0, 0);
056: }
057:
058: void draw(Theme theme, GC gc, Rectangle bounds) {
059: if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
060: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
061: RECT rect = new RECT();
062: rect.left = bounds.x;
063: rect.right = bounds.x + bounds.width;
064: rect.top = bounds.y;
065: rect.bottom = bounds.y + bounds.height;
066: SIZE size = null;
067: int[] dropPart = null;
068: if ((style & SWT.DROP_DOWN) != 0) {
069: size = new SIZE();
070: dropPart = getPartId(DrawData.TOOLITEM_ARROW);
071: OS.GetThemePartSize(hTheme, gc.handle, dropPart[0],
072: dropPart[1], rect, OS.TS_TRUE, size);
073: rect.right -= size.cx;
074: if (rect.right < rect.left)
075: rect.right = rect.left;
076: }
077: int[] part = getPartId(DrawData.WIDGET_WHOLE);
078: OS.DrawThemeBackground(hTheme, gc.handle, part[0], part[1],
079: rect, null);
080: Rectangle clientArea = this .clientArea;
081: if (clientArea != null) {
082: RECT contentRect = new RECT();
083: OS.GetThemeBackgroundContentRect(hTheme, gc.handle,
084: part[0], part[1], rect, contentRect);
085: clientArea.x = contentRect.left;
086: clientArea.y = contentRect.top;
087: clientArea.width = contentRect.right - contentRect.left;
088: clientArea.height = contentRect.bottom
089: - contentRect.top;
090: }
091: if ((style & SWT.DROP_DOWN) != 0) {
092: rect.left = rect.right;
093: rect.right = rect.left + size.cx;
094: OS.DrawThemeBackground(hTheme, gc.handle, dropPart[0],
095: dropPart[1], rect, null);
096: }
097: OS.CloseThemeData(hTheme);
098: }
099: }
100:
101: char[] getClassId() {
102: return TOOLBAR;
103: }
104:
105: int[] getPartId(int part) {
106: int state = this .state[part];
107: int iPartId = 0, iStateId = 0;
108: switch (part) {
109: case DrawData.WIDGET_WHOLE:
110: if ((style & (SWT.PUSH | SWT.CHECK | SWT.RADIO)) != 0) {
111: iPartId = OS.TP_BUTTON;
112: } else if ((style & SWT.DROP_DOWN) != 0) {
113: iPartId = OS.TP_SPLITBUTTON;
114: } else if ((style & SWT.SEPARATOR) != 0) {
115: if ((parent.style & SWT.VERTICAL) != 0) {
116: iPartId = OS.TP_SEPARATORVERT;
117: } else {
118: iPartId = OS.TP_SEPARATOR;
119: }
120: }
121: if ((style & SWT.SEPARATOR) == 0) {
122: if ((state & DrawData.HOT) != 0) {
123: if ((style & (SWT.RADIO | SWT.CHECK)) != 0
124: && (state & DrawData.SELECTED) != 0) {
125: iStateId = OS.TS_HOTCHECKED;
126: } else {
127: iStateId = OS.TS_HOT;
128: }
129: }
130: if ((style & (SWT.RADIO | SWT.CHECK)) != 0
131: && (state & DrawData.SELECTED) != 0) {
132: iStateId = OS.TS_CHECKED;
133: }
134: if ((state & DrawData.PRESSED) != 0)
135: iStateId = OS.TS_PRESSED;
136: if ((state & DrawData.DISABLED) != 0)
137: iStateId = OS.TS_DISABLED;
138: }
139: break;
140: case DrawData.TOOLITEM_ARROW:
141: iPartId = OS.TP_SPLITBUTTONDROPDOWN;
142: if ((state & DrawData.HOT) != 0)
143: iStateId = OS.TS_HOT;
144: if ((state & DrawData.PRESSED) != 0)
145: iStateId = OS.TS_PRESSED;
146: if ((state & DrawData.DISABLED) != 0)
147: iStateId = OS.TS_DISABLED;
148: break;
149: }
150: return new int[] { iPartId, iStateId };
151: }
152:
153: int hit(Theme theme, Point position, Rectangle bounds) {
154: if (!(OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()))
155: return DrawData.WIDGET_NOWHERE;
156: if (!bounds.contains(position))
157: return DrawData.WIDGET_NOWHERE;
158: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
159: try {
160: RECT rect = new RECT();
161: rect.left = bounds.x;
162: rect.right = bounds.x + bounds.width;
163: rect.top = bounds.y;
164: rect.bottom = bounds.y + bounds.height;
165: POINT pt = new POINT();
166: pt.x = position.x;
167: pt.y = position.y;
168: short[] code = new short[1];
169: int[] part = getPartId(DrawData.WIDGET_WHOLE);
170: OS.HitTestThemeBackground(hTheme, 0, part[0], part[1], 0,
171: rect, 0, pt, code);
172: if (code[0] == OS.HTNOWHERE)
173: return DrawData.WIDGET_NOWHERE;
174: int style = this .style;
175: if ((style & SWT.DROP_DOWN) != 0) {
176: SIZE size = new SIZE();
177: part = getPartId(DrawData.TOOLITEM_ARROW);
178: OS.GetThemePartSize(hTheme, 0, part[0], part[1], rect,
179: OS.TS_TRUE, size);
180: rect.left = Math.max(rect.left, rect.right - size.cx);
181: OS.HitTestThemeBackground(hTheme, 0, part[0], part[1],
182: 0, rect, 0, pt, code);
183: if (code[0] != OS.HTNOWHERE)
184: return DrawData.TOOLITEM_ARROW;
185: }
186: } finally {
187: OS.CloseThemeData(hTheme);
188: }
189: return DrawData.WIDGET_WHOLE;
190: }
191:
192: }
|