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.graphics.*;
013: import org.eclipse.swt.internal.win32.*;
014:
015: public class ComboDrawData extends DrawData {
016:
017: public ComboDrawData() {
018: state = new int[2];
019: }
020:
021: void draw(Theme theme, GC gc, Rectangle bounds) {
022: if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
023: int /*long*/hTheme = OS.OpenThemeData(0, EDIT);
024: RECT rect = new RECT();
025: rect.left = bounds.x;
026: rect.right = bounds.x + bounds.width;
027: rect.top = bounds.y;
028: rect.bottom = bounds.y + bounds.height;
029: int[] part = getPartId(DrawData.WIDGET_WHOLE);
030: OS.DrawThemeBackground(hTheme, gc.handle, part[0], part[1],
031: rect, null);
032: RECT contentRect = new RECT();
033: OS.GetThemeBackgroundContentRect(hTheme, gc.handle,
034: part[0], part[1], rect, contentRect);
035: Rectangle clientArea = this .clientArea;
036: if (clientArea != null) {
037: clientArea.x = contentRect.left;
038: clientArea.y = contentRect.top;
039: clientArea.width = contentRect.right - contentRect.left;
040: clientArea.height = contentRect.bottom
041: - contentRect.top;
042: }
043: OS.CloseThemeData(hTheme);
044: hTheme = OS.OpenThemeData(0, getClassId());
045: int width = OS.GetThemeSysSize(hTheme, OS.SM_CXVSCROLL);
046: rect.left = contentRect.right - width;
047: rect.top = contentRect.top;
048: rect.right = contentRect.right;
049: rect.bottom = contentRect.bottom;
050: part = getPartId(DrawData.COMBO_ARROW);
051: OS.DrawThemeBackground(hTheme, gc.handle, part[0], part[1],
052: rect, null);
053: OS.CloseThemeData(hTheme);
054: if (clientArea != null) {
055: clientArea.width -= width;
056: }
057: }
058: }
059:
060: char[] getClassId() {
061: return COMBOBOX;
062: }
063:
064: int[] getPartId(int part) {
065: int state = this .state[part];
066: int iPartId = 0, iStateId = 0;
067: switch (part) {
068: case DrawData.WIDGET_WHOLE:
069: iPartId = OS.EP_EDITTEXT;
070: iStateId = OS.ETS_NORMAL;
071: if ((state & DrawData.DISABLED) != 0)
072: iStateId = OS.ETS_DISABLED;
073: break;
074: case DrawData.COMBO_ARROW:
075: iPartId = OS.CP_DROPDOWNBUTTON;
076: iStateId = OS.CBXS_NORMAL;
077: if ((state & DrawData.DISABLED) != 0)
078: iStateId = OS.CBXS_DISABLED;
079: if ((state & DrawData.HOT) != 0)
080: iStateId = OS.CBXS_HOT;
081: if ((state & DrawData.PRESSED) != 0)
082: iStateId = OS.CBXS_PRESSED;
083: break;
084: }
085: return new int[] { iPartId, iStateId };
086: }
087:
088: int hit(Theme theme, Point position, Rectangle bounds) {
089: if (!(OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()))
090: return DrawData.WIDGET_NOWHERE;
091: if (!bounds.contains(position))
092: return DrawData.WIDGET_NOWHERE;
093: int /*long*/hTheme = OS.OpenThemeData(0, EDIT);
094: int[] part = getPartId(DrawData.WIDGET_WHOLE);
095: int iPartId = part[0];
096: int iStateId = part[1];
097: RECT rect = new RECT();
098: rect.left = bounds.x;
099: rect.right = bounds.x + bounds.width;
100: rect.top = bounds.y;
101: rect.bottom = bounds.y + bounds.height;
102: RECT contentRect = new RECT();
103: OS.GetThemeBackgroundContentRect(hTheme, 0, iPartId, iStateId,
104: rect, contentRect);
105: OS.CloseThemeData(hTheme);
106: hTheme = OS.OpenThemeData(0, getClassId());
107: int width = OS.GetThemeSysSize(hTheme, OS.SM_CXVSCROLL);
108: OS.CloseThemeData(hTheme);
109: Rectangle arrowRect = new Rectangle(contentRect.right - width,
110: contentRect.top, contentRect.bottom - contentRect.top,
111: width);
112: if (arrowRect.contains(position))
113: return DrawData.COMBO_ARROW;
114: return DrawData.WIDGET_WHOLE;
115: }
116:
117: }
|