1 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 DrawData { 18 public int style; 19 public int[] state; 20 public Rectangle clientArea; 21 22 23 public static final int SELECTED = 1 << 1; 24 public static final int FOCUSED = 1 << 2; 25 public static final int PRESSED = 1 << 3; 26 public static final int ACTIVE = 1 << 4; 27 public static final int DISABLED = 1 << 5; 28 public static final int HOT = 1 << 6; 29 public static final int DEFAULTED = 1 << 7; 30 public static final int GRAYED = 1 << 8; 31 32 33 public static final int DRAW_LEFT = 1 << 4; 34 public static final int DRAW_TOP = 1 << 5; 35 public static final int DRAW_RIGHT = 1 << 6; 36 public static final int DRAW_BOTTOM = 1 << 7; 37 public static final int DRAW_HCENTER = 1 << 8; 38 public static final int DRAW_VCENTER = 1 << 9; 39 40 41 public static final int WIDGET_NOWHERE = -1; 42 public static final int WIDGET_WHOLE = 0; 43 44 45 public static final int SCROLLBAR_UP_ARROW = 1; 46 public static final int SCROLLBAR_DOWN_ARROW = 2; 47 public static final int SCROLLBAR_LEFT_ARROW = SCROLLBAR_UP_ARROW; 48 public static final int SCROLLBAR_RIGHT_ARROW = SCROLLBAR_DOWN_ARROW; 49 public static final int SCROLLBAR_UP_TRACK = 3; 50 public static final int SCROLLBAR_DOWN_TRACK = 4; 51 public static final int SCROLLBAR_LEFT_TRACK = SCROLLBAR_UP_TRACK; 52 public static final int SCROLLBAR_RIGHT_TRACK = SCROLLBAR_DOWN_TRACK; 53 public static final int SCROLLBAR_THUMB = 5; 54 55 56 public static final int SCALE_UP_TRACK = 1; 57 public static final int SCALE_LEFT_TRACK = SCALE_UP_TRACK; 58 public static final int SCALE_DOWN_TRACK = 2; 59 public static final int SCALE_RIGHT_TRACK = SCALE_DOWN_TRACK; 60 public static final int SCALE_THUMB = 3; 61 62 63 public static final int TOOLITEM_ARROW = 1; 64 65 66 public static final int COMBO_ARROW = 1; 67 68 static final char [] EDIT = new char [] {'E', 'D', 'I', 'T', 0}; 69 static final char [] COMBOBOX = new char [] {'C', 'O', 'M', 'B', 'O', 'B', 'O', 'X', 0}; 70 static final char [] BUTTON = new char [] {'B', 'U', 'T', 'T', 'O', 'N', 0}; 71 static final char [] PROGRESS = new char [] {'P', 'R', 'O', 'G', 'R', 'E', 'S', 'S', 0}; 72 static final char [] SCROLLBAR = new char [] {'S', 'C', 'R', 'O', 'L', 'L', 'B', 'A', 'R', 0}; 73 static final char [] TAB = new char [] {'T', 'A', 'B', 0}; 74 static final char [] TRACKBAR = new char [] {'T', 'R', 'A', 'C', 'K', 'B', 'A', 'R', 0}; 75 static final char [] TOOLBAR = new char [] {'T', 'O', 'O', 'L', 'B', 'A', 'R', 0}; 76 static final char [] TREEVIEW = new char [] {'T', 'R', 'E', 'E', 'V', 'I', 'E', 'W', 0}; 77 78 public DrawData() { 79 state = new int[1]; 80 } 81 82 Rectangle computeTrim(Theme theme, GC gc) { 83 return new Rectangle(clientArea.x, clientArea.y, clientArea.width, clientArea.height); 84 } 85 86 void draw(Theme theme, GC gc, Rectangle bounds) { 87 88 } 89 90 void drawImage(Theme theme, Image image, GC gc, Rectangle bounds) { 91 if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { 92 Rectangle rect = image.getBounds(); 106 gc.drawImage(image, 0, 0, rect.width, rect.height, bounds.x, bounds.y, bounds.width, bounds.height); 107 } 108 } 109 110 void drawText(Theme theme, String text, int flags, GC gc, Rectangle bounds) { 111 if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { 112 int hTheme = OS.OpenThemeData(0, getClassId()); 113 char[] chars = new char[text.length()]; 114 text.getChars(0, chars.length, chars, 0); 115 int textFlags = OS.DT_SINGLELINE; 116 if ((flags & DrawData.DRAW_LEFT) != 0) textFlags |= OS.DT_LEFT; 117 if ((flags & DrawData.DRAW_HCENTER) != 0) textFlags |= OS.DT_CENTER; 118 if ((flags & DrawData.DRAW_RIGHT) != 0) textFlags |= OS.DT_RIGHT; 119 if ((flags & DrawData.DRAW_TOP) != 0) textFlags |= OS.DT_TOP; 120 if ((flags & DrawData.DRAW_BOTTOM) != 0) textFlags |= OS.DT_BOTTOM; 121 if ((flags & DrawData.DRAW_VCENTER) != 0) textFlags |= OS.DT_VCENTER; 122 RECT rect = new RECT (); 123 rect.left = bounds.x; 124 rect.right = bounds.x + bounds.width; 125 rect.top = bounds.y; 126 rect.bottom = bounds.y + bounds.height; 127 int[] part = getPartId(DrawData.WIDGET_WHOLE); 128 int iPartId = part[0]; 129 int iStateId = part[1]; 130 OS.DrawThemeText(hTheme, gc.handle, iPartId, iStateId, chars, chars.length, textFlags, 0, rect); 131 OS.CloseThemeData(hTheme); 132 } 133 } 134 135 char[] getClassId() { 136 return BUTTON; 137 } 138 139 int[] getPartId(int part) { 140 return new int[]{0, 0}; 141 } 142 143 Rectangle getBounds(int part, Rectangle bounds) { 144 return new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height); 145 } 146 147 int hit(Theme theme, Point position, Rectangle bounds) { 148 return -1; 149 } 150 151 Rectangle measureText(Theme theme, String text, int flags, GC gc, Rectangle bounds) { 152 if (!(OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ())) return new Rectangle(0, 0, 0, 0); 153 int hTheme = OS.OpenThemeData(0, getClassId()); 154 char[] chars = new char[text.length()]; 155 text.getChars(0, chars.length, chars, 0); 156 int textFlags = 0; if ((style & SWT.LEFT) != 0) textFlags |= OS.DT_LEFT; 159 if ((style & SWT.CENTER) != 0) textFlags |= OS.DT_CENTER; 160 if ((style & SWT.RIGHT) != 0) textFlags |= OS.DT_RIGHT; 161 RECT extent = new RECT(); 162 RECT rect = null; 163 if (bounds != null) { 164 rect = new RECT(); 165 rect.left = bounds.x; 166 rect.right = bounds.x + bounds.width; 167 rect.top = bounds.y; 168 rect.bottom = bounds.y + bounds.height; 169 } 170 int[] part = getPartId(DrawData.WIDGET_WHOLE); 171 int iPartId = part[0]; 172 int iStateId = part[1]; 173 OS.GetThemeTextExtent(hTheme, gc.handle, iPartId, iStateId, chars, chars.length, textFlags, rect, extent); 174 OS.CloseThemeData(hTheme); 175 return new Rectangle(extent.left, extent.top, extent.right - extent.left, extent.bottom - extent.top); 176 } 177 178 } 179 | Popular Tags |