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 TabItemDrawData extends DrawData {
017:
018: public TabFolderDrawData parent;
019: public int position;
020:
021: static final int TABITEM_INSET = 2;
022: static final int TABITEM_INSET2 = 6;
023:
024: public TabItemDrawData() {
025: state = new int[1];
026: }
027:
028: Rectangle computeTrim(Theme theme, GC gc) {
029: if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
030: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
031: int x = clientArea.x, y = clientArea.y, width = clientArea.width, height = clientArea.height;
032: if ((style & SWT.LEFT) != 0) {
033: x -= TABITEM_INSET;
034: width += TABITEM_INSET;
035: }
036: y -= TABITEM_INSET;
037: height += TABITEM_INSET;
038: RECT rect = new RECT();
039: rect.left = x;
040: rect.right = x + width;
041: rect.top = y;
042: rect.bottom = y + height;
043: RECT extent = new RECT();
044: int[] part = getPartId(DrawData.WIDGET_WHOLE);
045: OS.GetThemeBackgroundExtent(hTheme, gc.handle, part[0],
046: part[1], rect, extent);
047: extent.left -= TABITEM_INSET2;
048: extent.top -= TABITEM_INSET2;
049: extent.right += TABITEM_INSET2;
050: OS.CloseThemeData(hTheme);
051: return new Rectangle(extent.left, extent.top, extent.right
052: - extent.left, extent.bottom - extent.top);
053: }
054: return new Rectangle(0, 0, 0, 0);
055: }
056:
057: void draw(Theme theme, GC gc, Rectangle bounds) {
058: if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
059: int state = this .state[DrawData.WIDGET_WHOLE];
060: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
061: int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
062: if ((position & SWT.LEFT) != 0) {
063: x += TABITEM_INSET;
064: width -= TABITEM_INSET;
065: }
066: y += TABITEM_INSET;
067: height -= TABITEM_INSET;
068: if ((state & DrawData.SELECTED) != 0) {
069: //TODO - draws outside of bounds
070: x -= TABITEM_INSET;
071: y -= TABITEM_INSET;
072: width += TABITEM_INSET * 2;
073: height += TABITEM_INSET * 2;
074: }
075: RECT rect = new RECT();
076: rect.left = x;
077: rect.right = x + width;
078: rect.top = y;
079: rect.bottom = y + height;
080: int[] part = getPartId(DrawData.WIDGET_WHOLE);
081: OS.DrawThemeBackground(hTheme, gc.handle, part[0], part[1],
082: rect, null);
083: OS.CloseThemeData(hTheme);
084: Rectangle clientArea = this .clientArea;
085: if (clientArea != null) {
086: RECT contentRect = new RECT();
087: OS.GetThemeBackgroundContentRect(hTheme, gc.handle,
088: part[0], part[1], rect, contentRect);
089: clientArea.x = contentRect.left;
090: clientArea.y = contentRect.top;
091: clientArea.width = contentRect.right - contentRect.left;
092: clientArea.height = contentRect.bottom
093: - contentRect.top;
094: }
095: }
096: }
097:
098: char[] getClassId() {
099: return TAB;
100: }
101:
102: int[] getPartId(int part) {
103: int state = this .state[part];
104: int iPartId = OS.TABP_TABITEM, iStateId = OS.TIS_NORMAL;
105: if ((style & SWT.LEFT) != 0 && (style & SWT.RIGHT) != 0) {
106: iPartId = OS.TABP_TABITEMLEFTEDGE;
107: } else if ((style & SWT.LEFT) != 0) {
108: iPartId = OS.TABP_TABITEMLEFTEDGE;
109: } else if ((style & SWT.RIGHT) != 0) {
110: }
111: if ((state & DrawData.HOT) != 0)
112: iStateId = OS.TIS_HOT;
113: if ((state & DrawData.FOCUSED) != 0)
114: iStateId = OS.TIS_FOCUSED;
115: if ((state & DrawData.SELECTED) != 0)
116: iStateId = OS.TIS_SELECTED;
117: if ((state & DrawData.DISABLED) != 0)
118: iStateId = OS.TIS_DISABLED;
119: return new int[] { iPartId, iStateId };
120: }
121:
122: int hit(Theme theme, Point position, Rectangle bounds) {
123: if (!bounds.contains(position))
124: return DrawData.WIDGET_NOWHERE;
125: int style = this .style;
126: int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
127: if ((style & SWT.LEFT) != 0) {
128: x += TABITEM_INSET;
129: width -= TABITEM_INSET;
130: }
131: y += TABITEM_INSET;
132: height -= TABITEM_INSET;
133: Rectangle content = new Rectangle(x, y, width, height);
134: if (!content.contains(position))
135: return DrawData.WIDGET_NOWHERE;
136: return DrawData.WIDGET_WHOLE;
137: }
138:
139: }
|