KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > internal > theme > TabItemDrawData


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.swt.internal.theme;
12
13 import org.eclipse.swt.*;
14 import org.eclipse.swt.graphics.*;
15 import org.eclipse.swt.internal.win32.*;
16
17 public class TabItemDrawData extends DrawData {
18
19     public TabFolderDrawData parent;
20     public int position;
21     
22     static final int TABITEM_INSET = 2;
23     static final int TABITEM_INSET2 = 6;
24     
25 public TabItemDrawData() {
26     state = new int[1];
27 }
28
29 Rectangle computeTrim(Theme theme, GC gc) {
30     if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
31         int hTheme = OS.OpenThemeData(0, getClassId());
32         int x = clientArea.x, y = clientArea.y, width = clientArea.width, height = clientArea.height;
33         if ((style & SWT.LEFT) != 0) {
34             x -= TABITEM_INSET;
35             width += TABITEM_INSET;
36         }
37         y -= TABITEM_INSET;
38         height += TABITEM_INSET;
39         RECT rect = new RECT ();
40         rect.left = x;
41         rect.right = x + width;
42         rect.top = y;
43         rect.bottom = y + height;
44         RECT extent = new RECT ();
45         int[] part = getPartId(DrawData.WIDGET_WHOLE);
46         OS.GetThemeBackgroundExtent(hTheme, gc.handle, part[0], part[1], rect, extent);
47         extent.left -= TABITEM_INSET2;
48         extent.top -= TABITEM_INSET2;
49         extent.right += TABITEM_INSET2;
50         OS.CloseThemeData(hTheme);
51         return new Rectangle(extent.left, extent.top, extent.right - extent.left, extent.bottom - extent.top);
52     }
53     return new Rectangle(0, 0, 0, 0);
54 }
55
56 void draw(Theme theme, GC gc, Rectangle bounds) {
57     if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
58         int state = this.state[DrawData.WIDGET_WHOLE];
59         int hTheme = OS.OpenThemeData(0, getClassId());
60         int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
61         if ((position & SWT.LEFT) != 0) {
62             x += TABITEM_INSET;
63             width -= TABITEM_INSET;
64         }
65         y += TABITEM_INSET;
66         height -= TABITEM_INSET;
67         if ((state & DrawData.SELECTED) != 0) {
68             //TODO - draws outside of bounds
69
x -= TABITEM_INSET;
70             y -= TABITEM_INSET;
71             width += TABITEM_INSET * 2;
72             height += TABITEM_INSET * 2;
73         }
74         RECT rect = new RECT ();
75         rect.left = x;
76         rect.right = x + width;
77         rect.top = y;
78         rect.bottom = y + height;
79         int[] part = getPartId(DrawData.WIDGET_WHOLE);
80         OS.DrawThemeBackground (hTheme, gc.handle, part[0], part[1], rect, null);
81         OS.CloseThemeData(hTheme);
82         Rectangle clientArea = this.clientArea;
83         if (clientArea != null) {
84             RECT contentRect = new RECT();
85             OS.GetThemeBackgroundContentRect(hTheme, gc.handle, part[0], part[1], rect, contentRect);
86             clientArea.x = contentRect.left;
87             clientArea.y = contentRect.top;
88             clientArea.width = contentRect.right - contentRect.left;
89             clientArea.height = contentRect.bottom - contentRect.top;
90         }
91     }
92 }
93
94 char[] getClassId() {
95     return TAB;
96 }
97
98 int[] getPartId(int part) {
99     int state = this.state[part];
100     int iPartId = OS.TABP_TABITEM, iStateId = OS.TIS_NORMAL;
101     if ((style & SWT.LEFT) != 0 && (style & SWT.RIGHT) != 0) {
102         iPartId = OS.TABP_TABITEMLEFTEDGE;
103     } else if ((style & SWT.LEFT) != 0) {
104         iPartId = OS.TABP_TABITEMLEFTEDGE;
105     } else if ((style & SWT.RIGHT) != 0) {
106     }
107     if ((state & DrawData.HOT) != 0) iStateId = OS.TIS_HOT;
108     if ((state & DrawData.FOCUSED) != 0) iStateId = OS.TIS_FOCUSED;
109     if ((state & DrawData.SELECTED) != 0) iStateId = OS.TIS_SELECTED;
110     if ((state & DrawData.DISABLED) != 0) iStateId = OS.TIS_DISABLED;
111     return new int[]{iPartId, iStateId};
112 }
113
114 int hit(Theme theme, Point position, Rectangle bounds) {
115     if (!bounds.contains(position)) return DrawData.WIDGET_NOWHERE;
116     int style = this.style;
117     int x = bounds.x, y = bounds.y, width = bounds.width, height = bounds.height;
118     if ((style & SWT.LEFT) != 0) {
119         x += TABITEM_INSET;
120         width -= TABITEM_INSET;
121     }
122     y += TABITEM_INSET;
123     height -= TABITEM_INSET;
124     Rectangle content = new Rectangle(x, y, width, height);
125     if (!content.contains(position)) return DrawData.WIDGET_NOWHERE;
126     return DrawData.WIDGET_WHOLE;
127 }
128
129 }
130
Popular Tags