1 11 package org.eclipse.swt.internal.theme; 12 13 import org.eclipse.swt.graphics.*; 14 import org.eclipse.swt.internal.win32.*; 15 16 public class ComboDrawData extends DrawData { 17 18 public ComboDrawData() { 19 state = new int[2]; 20 } 21 22 void draw(Theme theme, GC gc, Rectangle bounds) { 23 if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { 24 int hTheme = OS.OpenThemeData(0, EDIT); 25 RECT rect = new RECT (); 26 rect.left = bounds.x; 27 rect.right = bounds.x + bounds.width; 28 rect.top = bounds.y; 29 rect.bottom = bounds.y + bounds.height; 30 int[] part = getPartId(DrawData.WIDGET_WHOLE); 31 OS.DrawThemeBackground (hTheme, gc.handle, part[0], part[1], rect, null); 32 RECT contentRect = new RECT(); 33 OS.GetThemeBackgroundContentRect(hTheme, gc.handle, part[0], part[1], rect, contentRect); 34 Rectangle clientArea = this.clientArea; 35 if (clientArea != null) { 36 clientArea.x = contentRect.left; 37 clientArea.y = contentRect.top; 38 clientArea.width = contentRect.right - contentRect.left; 39 clientArea.height = contentRect.bottom - contentRect.top; 40 } 41 OS.CloseThemeData(hTheme); 42 hTheme = OS.OpenThemeData(0, getClassId()); 43 int width = OS.GetThemeSysSize(hTheme, OS.SM_CXVSCROLL); 44 rect.left = contentRect.right - width; 45 rect.top = contentRect.top; 46 rect.right = contentRect.right; 47 rect.bottom = contentRect.bottom; 48 part = getPartId(DrawData.COMBO_ARROW); 49 OS.DrawThemeBackground (hTheme, gc.handle, part[0], part[1], rect, null); 50 OS.CloseThemeData(hTheme); 51 if (clientArea != null) { 52 clientArea.width -= width; 53 } 54 } 55 } 56 57 char[] getClassId() { 58 return COMBOBOX; 59 } 60 61 int[] getPartId(int part) { 62 int state = this.state[part]; 63 int iPartId = 0, iStateId = 0; 64 switch (part) { 65 case DrawData.WIDGET_WHOLE: 66 iPartId = OS.EP_EDITTEXT; 67 iStateId = OS.ETS_NORMAL; 68 if ((state & DrawData.DISABLED) != 0) iStateId = OS.ETS_DISABLED; 69 break; 70 case DrawData.COMBO_ARROW: 71 iPartId = OS.CP_DROPDOWNBUTTON; 72 iStateId = OS.CBXS_NORMAL; 73 if ((state & DrawData.DISABLED) != 0) iStateId = OS.CBXS_DISABLED; 74 if ((state & DrawData.HOT) != 0) iStateId = OS.CBXS_HOT; 75 if ((state & DrawData.PRESSED) != 0) iStateId = OS.CBXS_PRESSED; 76 break; 77 } 78 return new int[]{iPartId, iStateId}; 79 } 80 81 int hit(Theme theme, Point position, Rectangle bounds) { 82 if (!(OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ())) return DrawData.WIDGET_NOWHERE; 83 if (!bounds.contains(position)) return DrawData.WIDGET_NOWHERE; 84 int hTheme = OS.OpenThemeData(0, EDIT); 85 int[] part = getPartId(DrawData.WIDGET_WHOLE); 86 int iPartId = part[0]; 87 int iStateId = part[1]; 88 RECT rect = new RECT (); 89 rect.left = bounds.x; 90 rect.right = bounds.x + bounds.width; 91 rect.top = bounds.y; 92 rect.bottom = bounds.y + bounds.height; 93 RECT contentRect = new RECT(); 94 OS.GetThemeBackgroundContentRect(hTheme, 0, iPartId, iStateId, rect, contentRect); 95 OS.CloseThemeData(hTheme); 96 hTheme = OS.OpenThemeData(0, getClassId()); 97 int width = OS.GetThemeSysSize(hTheme, OS.SM_CXVSCROLL); 98 OS.CloseThemeData(hTheme); 99 Rectangle arrowRect = new Rectangle(contentRect.right - width, contentRect.top, contentRect.bottom - contentRect.top, width); 100 if (arrowRect.contains(position)) return DrawData.COMBO_ARROW; 101 return DrawData.WIDGET_WHOLE; 102 } 103 104 } 105 | Popular Tags |