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 DrawData {
017: public int style;
018: public int[] state;
019: public Rectangle clientArea;
020:
021: /** Part states */
022: public static final int SELECTED = 1 << 1;
023: public static final int FOCUSED = 1 << 2;
024: public static final int PRESSED = 1 << 3;
025: public static final int ACTIVE = 1 << 4;
026: public static final int DISABLED = 1 << 5;
027: public static final int HOT = 1 << 6;
028: public static final int DEFAULTED = 1 << 7;
029: public static final int GRAYED = 1 << 8;
030:
031: /** Text and Image drawing flags */
032: public static final int DRAW_LEFT = 1 << 4;
033: public static final int DRAW_TOP = 1 << 5;
034: public static final int DRAW_RIGHT = 1 << 6;
035: public static final int DRAW_BOTTOM = 1 << 7;
036: public static final int DRAW_HCENTER = 1 << 8;
037: public static final int DRAW_VCENTER = 1 << 9;
038:
039: /** Widget parts */
040: public static final int WIDGET_NOWHERE = -1;
041: public static final int WIDGET_WHOLE = 0;
042:
043: /** Scrollbar parts */
044: public static final int SCROLLBAR_UP_ARROW = 1;
045: public static final int SCROLLBAR_DOWN_ARROW = 2;
046: public static final int SCROLLBAR_LEFT_ARROW = SCROLLBAR_UP_ARROW;
047: public static final int SCROLLBAR_RIGHT_ARROW = SCROLLBAR_DOWN_ARROW;
048: public static final int SCROLLBAR_UP_TRACK = 3;
049: public static final int SCROLLBAR_DOWN_TRACK = 4;
050: public static final int SCROLLBAR_LEFT_TRACK = SCROLLBAR_UP_TRACK;
051: public static final int SCROLLBAR_RIGHT_TRACK = SCROLLBAR_DOWN_TRACK;
052: public static final int SCROLLBAR_THUMB = 5;
053:
054: /** Scale parts */
055: public static final int SCALE_UP_TRACK = 1;
056: public static final int SCALE_LEFT_TRACK = SCALE_UP_TRACK;
057: public static final int SCALE_DOWN_TRACK = 2;
058: public static final int SCALE_RIGHT_TRACK = SCALE_DOWN_TRACK;
059: public static final int SCALE_THUMB = 3;
060:
061: /** ToolItem parts */
062: public static final int TOOLITEM_ARROW = 1;
063:
064: /** Combo parts */
065: public static final int COMBO_ARROW = 1;
066:
067: static final char[] EDIT = new char[] { 'E', 'D', 'I', 'T', 0 };
068: static final char[] COMBOBOX = new char[] { 'C', 'O', 'M', 'B',
069: 'O', 'B', 'O', 'X', 0 };
070: static final char[] BUTTON = new char[] { 'B', 'U', 'T', 'T', 'O',
071: 'N', 0 };
072: static final char[] PROGRESS = new char[] { 'P', 'R', 'O', 'G',
073: 'R', 'E', 'S', 'S', 0 };
074: static final char[] SCROLLBAR = new char[] { 'S', 'C', 'R', 'O',
075: 'L', 'L', 'B', 'A', 'R', 0 };
076: static final char[] TAB = new char[] { 'T', 'A', 'B', 0 };
077: static final char[] TRACKBAR = new char[] { 'T', 'R', 'A', 'C',
078: 'K', 'B', 'A', 'R', 0 };
079: static final char[] TOOLBAR = new char[] { 'T', 'O', 'O', 'L', 'B',
080: 'A', 'R', 0 };
081: static final char[] TREEVIEW = new char[] { 'T', 'R', 'E', 'E',
082: 'V', 'I', 'E', 'W', 0 };
083:
084: public DrawData() {
085: state = new int[1];
086: }
087:
088: Rectangle computeTrim(Theme theme, GC gc) {
089: return new Rectangle(clientArea.x, clientArea.y,
090: clientArea.width, clientArea.height);
091: }
092:
093: void draw(Theme theme, GC gc, Rectangle bounds) {
094:
095: }
096:
097: void drawImage(Theme theme, Image image, GC gc, Rectangle bounds) {
098: if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
099: // int /*long*/ hTheme = OS.OpenThemeData(0, getClassId());
100: // RECT rect = new RECT ();
101: // rect.left = bounds.x;
102: // rect.right = bounds.x + bounds.width;
103: // rect.top = bounds.y;
104: // rect.bottom = bounds.y + bounds.height;
105: // //TODO - remove reference to widgets.
106: // ImageList imageList = new ImageList(0);
107: // int imageIndex = imageList.add(image);
108: // int[] part = getPartId(DrawData.WIDGET_WHOLE);
109: // OS.DrawThemeIcon(hTheme, gc.handle, part[0], part[1], rect, imageList.getHandle(), imageIndex);
110: // imageList.dispose();
111: // OS.CloseThemeData(hTheme);
112: Rectangle rect = image.getBounds();
113: gc.drawImage(image, 0, 0, rect.width, rect.height,
114: bounds.x, bounds.y, bounds.width, bounds.height);
115: }
116: }
117:
118: void drawText(Theme theme, String text, int flags, GC gc,
119: Rectangle bounds) {
120: if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
121: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
122: char[] chars = new char[text.length()];
123: text.getChars(0, chars.length, chars, 0);
124: int textFlags = OS.DT_SINGLELINE;
125: if ((flags & DrawData.DRAW_LEFT) != 0)
126: textFlags |= OS.DT_LEFT;
127: if ((flags & DrawData.DRAW_HCENTER) != 0)
128: textFlags |= OS.DT_CENTER;
129: if ((flags & DrawData.DRAW_RIGHT) != 0)
130: textFlags |= OS.DT_RIGHT;
131: if ((flags & DrawData.DRAW_TOP) != 0)
132: textFlags |= OS.DT_TOP;
133: if ((flags & DrawData.DRAW_BOTTOM) != 0)
134: textFlags |= OS.DT_BOTTOM;
135: if ((flags & DrawData.DRAW_VCENTER) != 0)
136: textFlags |= OS.DT_VCENTER;
137: RECT rect = new RECT();
138: rect.left = bounds.x;
139: rect.right = bounds.x + bounds.width;
140: rect.top = bounds.y;
141: rect.bottom = bounds.y + bounds.height;
142: int[] part = getPartId(DrawData.WIDGET_WHOLE);
143: int iPartId = part[0];
144: int iStateId = part[1];
145: OS.DrawThemeText(hTheme, gc.handle, iPartId, iStateId,
146: chars, chars.length, textFlags, 0, rect);
147: OS.CloseThemeData(hTheme);
148: }
149: }
150:
151: char[] getClassId() {
152: return BUTTON;
153: }
154:
155: int[] getPartId(int part) {
156: return new int[] { 0, 0 };
157: }
158:
159: Rectangle getBounds(int part, Rectangle bounds) {
160: return new Rectangle(bounds.x, bounds.y, bounds.width,
161: bounds.height);
162: }
163:
164: int hit(Theme theme, Point position, Rectangle bounds) {
165: return -1;
166: }
167:
168: Rectangle measureText(Theme theme, String text, int flags, GC gc,
169: Rectangle bounds) {
170: if (!(OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()))
171: return new Rectangle(0, 0, 0, 0);
172: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
173: char[] chars = new char[text.length()];
174: text.getChars(0, chars.length, chars, 0);
175: //TODO - constant for VCENTER and flags
176: int textFlags = 0;//OS.DT_VCENTER | OS.DT_SINGLELINE | OS.DT_CALCRECT;
177: if ((style & SWT.LEFT) != 0)
178: textFlags |= OS.DT_LEFT;
179: if ((style & SWT.CENTER) != 0)
180: textFlags |= OS.DT_CENTER;
181: if ((style & SWT.RIGHT) != 0)
182: textFlags |= OS.DT_RIGHT;
183: RECT extent = new RECT();
184: RECT rect = null;
185: if (bounds != null) {
186: rect = new RECT();
187: rect.left = bounds.x;
188: rect.right = bounds.x + bounds.width;
189: rect.top = bounds.y;
190: rect.bottom = bounds.y + bounds.height;
191: }
192: int[] part = getPartId(DrawData.WIDGET_WHOLE);
193: int iPartId = part[0];
194: int iStateId = part[1];
195: OS.GetThemeTextExtent(hTheme, gc.handle, iPartId, iStateId,
196: chars, chars.length, textFlags, rect, extent);
197: OS.CloseThemeData(hTheme);
198: return new Rectangle(extent.left, extent.top, extent.right
199: - extent.left, extent.bottom - extent.top);
200: }
201:
202: }
|