KickJava   Java API By Example, From Geeks To Geeks.

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


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 ButtonDrawData extends DrawData {
18     
19 public ButtonDrawData() {
20     state = new int[1];
21 }
22
23 int[] getPartId(int part) {
24     int state = this.state[part];
25     int style = this.style;
26     int iPartId = 0, iStateId = 0;
27     if ((style & SWT.PUSH) != 0) {
28         iPartId = OS.BP_PUSHBUTTON;
29         iStateId = OS.PBS_NORMAL;
30         if ((state & DrawData.DEFAULTED) != 0 && (state & DrawData.ACTIVE) != 0) iStateId = OS.PBS_DEFAULTED;
31         if ((state & DrawData.HOT) != 0) iStateId = OS.PBS_HOT;
32         if ((state & DrawData.PRESSED) != 0) iStateId = OS.PBS_PRESSED;
33         if ((state & DrawData.DISABLED) != 0) iStateId = OS.PBS_DISABLED;
34     }
35     if ((style & SWT.RADIO) != 0) {
36         iPartId = OS.BP_RADIOBUTTON;
37     }
38     if ((style & SWT.CHECK) != 0) {
39         iPartId = OS.BP_CHECKBOX;
40     }
41     if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
42         if ((state & DrawData.SELECTED) != 0) {
43             iStateId = OS.CBS_CHECKEDNORMAL;
44             if ((state & DrawData.HOT) != 0) iStateId = OS.CBS_CHECKEDHOT;
45             if ((state & DrawData.PRESSED) != 0) iStateId = OS.CBS_CHECKEDPRESSED;
46             if ((state & DrawData.DISABLED) != 0) iStateId = OS.CBS_CHECKEDDISABLED;
47         } else {
48             iStateId = OS.CBS_UNCHECKEDNORMAL;
49             if ((state & DrawData.HOT) != 0) iStateId = OS.CBS_UNCHECKEDHOT;
50             if ((state & DrawData.PRESSED) != 0) iStateId = OS.CBS_UNCHECKEDPRESSED;
51             if ((state & DrawData.DISABLED) != 0) iStateId = OS.CBS_UNCHECKEDDISABLED;
52         }
53     }
54     return new int[]{iPartId, iStateId};
55 }
56
57 void draw(Theme theme, GC gc, Rectangle bounds) {
58     if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
59         //TODO - arrow and toggle
60
int hTheme = OS.OpenThemeData(0, getClassId());
61         RECT rect = new RECT ();
62         rect.left = bounds.x;
63         rect.right = bounds.x + bounds.width;
64         rect.top = bounds.y;
65         rect.bottom = bounds.y + bounds.height;
66         int[] part = getPartId(DrawData.WIDGET_WHOLE);
67         if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
68             SIZE size = new SIZE();
69             OS.GetThemePartSize(hTheme, gc.handle, part[0], part[1], rect, 2, size);
70             rect.right = rect.left + size.cx;
71             OS.DrawThemeBackground (hTheme, gc.handle, part[0], part[1], rect, null);
72             rect.left = rect.right + 3;
73             rect.right = rect.left + bounds.width - size.cx - 3;
74         } else {
75             OS.DrawThemeBackground (hTheme, gc.handle, part[0], part[1], rect, null);
76         }
77         Rectangle clientArea = this.clientArea;
78         if (clientArea != null) {
79             RECT contentRect = new RECT();
80             OS.GetThemeBackgroundContentRect(hTheme, gc.handle, part[0], part[1], rect, contentRect);
81             clientArea.x = contentRect.left;
82             clientArea.y = contentRect.top;
83             clientArea.width = contentRect.right - contentRect.left;
84             clientArea.height = contentRect.bottom - contentRect.top;
85         }
86         OS.CloseThemeData(hTheme);
87     }
88 }
89
90 int hit(Theme theme, Point position, Rectangle bounds) {
91     if (!(OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ())) return DrawData.WIDGET_NOWHERE;
92     if (!bounds.contains(position)) return DrawData.WIDGET_NOWHERE;
93     int hTheme = OS.OpenThemeData(0, getClassId());
94     RECT rect = new RECT ();
95     rect.left = bounds.x;
96     rect.right = bounds.x + bounds.width;
97     rect.top = bounds.y;
98     rect.bottom = bounds.y + bounds.height;
99     POINT pt = new POINT();
100     pt.x = position.x;
101     pt.y = position.y;
102     short[] code = new short[1];
103     int[] part = getPartId(DrawData.WIDGET_WHOLE);
104     OS.HitTestThemeBackground(hTheme, 0, part[0], part[1], 0, rect, 0, pt, code);
105     OS.CloseThemeData (hTheme);
106     return code[0] == OS.HTNOWHERE ? DrawData.WIDGET_NOWHERE : DrawData.WIDGET_WHOLE;
107 }
108
109 }
110
Popular Tags