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 ButtonDrawData extends DrawData {
017:
018: public ButtonDrawData() {
019: state = new int[1];
020: }
021:
022: int[] getPartId(int part) {
023: int state = this .state[part];
024: int style = this .style;
025: int iPartId = 0, iStateId = 0;
026: if ((style & SWT.PUSH) != 0) {
027: iPartId = OS.BP_PUSHBUTTON;
028: iStateId = OS.PBS_NORMAL;
029: if ((state & DrawData.DEFAULTED) != 0
030: && (state & DrawData.ACTIVE) != 0)
031: iStateId = OS.PBS_DEFAULTED;
032: if ((state & DrawData.HOT) != 0)
033: iStateId = OS.PBS_HOT;
034: if ((state & DrawData.PRESSED) != 0)
035: iStateId = OS.PBS_PRESSED;
036: if ((state & DrawData.DISABLED) != 0)
037: iStateId = OS.PBS_DISABLED;
038: }
039: if ((style & SWT.RADIO) != 0) {
040: iPartId = OS.BP_RADIOBUTTON;
041: }
042: if ((style & SWT.CHECK) != 0) {
043: iPartId = OS.BP_CHECKBOX;
044: }
045: if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
046: if ((state & DrawData.SELECTED) != 0) {
047: iStateId = OS.CBS_CHECKEDNORMAL;
048: if ((state & DrawData.HOT) != 0)
049: iStateId = OS.CBS_CHECKEDHOT;
050: if ((state & DrawData.PRESSED) != 0)
051: iStateId = OS.CBS_CHECKEDPRESSED;
052: if ((state & DrawData.DISABLED) != 0)
053: iStateId = OS.CBS_CHECKEDDISABLED;
054: } else {
055: iStateId = OS.CBS_UNCHECKEDNORMAL;
056: if ((state & DrawData.HOT) != 0)
057: iStateId = OS.CBS_UNCHECKEDHOT;
058: if ((state & DrawData.PRESSED) != 0)
059: iStateId = OS.CBS_UNCHECKEDPRESSED;
060: if ((state & DrawData.DISABLED) != 0)
061: iStateId = OS.CBS_UNCHECKEDDISABLED;
062: }
063: }
064: return new int[] { iPartId, iStateId };
065: }
066:
067: void draw(Theme theme, GC gc, Rectangle bounds) {
068: if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
069: //TODO - arrow and toggle
070: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
071: RECT rect = new RECT();
072: rect.left = bounds.x;
073: rect.right = bounds.x + bounds.width;
074: rect.top = bounds.y;
075: rect.bottom = bounds.y + bounds.height;
076: int[] part = getPartId(DrawData.WIDGET_WHOLE);
077: if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
078: SIZE size = new SIZE();
079: OS.GetThemePartSize(hTheme, gc.handle, part[0],
080: part[1], rect, 2, size);
081: rect.right = rect.left + size.cx;
082: OS.DrawThemeBackground(hTheme, gc.handle, part[0],
083: part[1], rect, null);
084: rect.left = rect.right + 3;
085: rect.right = rect.left + bounds.width - size.cx - 3;
086: } else {
087: OS.DrawThemeBackground(hTheme, gc.handle, part[0],
088: part[1], rect, null);
089: }
090: Rectangle clientArea = this .clientArea;
091: if (clientArea != null) {
092: RECT contentRect = new RECT();
093: OS.GetThemeBackgroundContentRect(hTheme, gc.handle,
094: part[0], part[1], rect, contentRect);
095: clientArea.x = contentRect.left;
096: clientArea.y = contentRect.top;
097: clientArea.width = contentRect.right - contentRect.left;
098: clientArea.height = contentRect.bottom
099: - contentRect.top;
100: }
101: OS.CloseThemeData(hTheme);
102: }
103: }
104:
105: int hit(Theme theme, Point position, Rectangle bounds) {
106: if (!(OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()))
107: return DrawData.WIDGET_NOWHERE;
108: if (!bounds.contains(position))
109: return DrawData.WIDGET_NOWHERE;
110: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
111: RECT rect = new RECT();
112: rect.left = bounds.x;
113: rect.right = bounds.x + bounds.width;
114: rect.top = bounds.y;
115: rect.bottom = bounds.y + bounds.height;
116: POINT pt = new POINT();
117: pt.x = position.x;
118: pt.y = position.y;
119: short[] code = new short[1];
120: int[] part = getPartId(DrawData.WIDGET_WHOLE);
121: OS.HitTestThemeBackground(hTheme, 0, part[0], part[1], 0, rect,
122: 0, pt, code);
123: OS.CloseThemeData(hTheme);
124: return code[0] == OS.HTNOWHERE ? DrawData.WIDGET_NOWHERE
125: : DrawData.WIDGET_WHOLE;
126: }
127:
128: }
|