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 ScaleDrawData extends RangeDrawData {
017: public int increment;
018: public int pageIncrement;
019:
020: static final int TICS_MARGIN = 10;
021:
022: public ScaleDrawData() {
023: state = new int[4];
024: }
025:
026: void draw(Theme theme, GC gc, Rectangle bounds) {
027: if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
028: // TODO - drawScale not done
029: int style = this .style;
030: int minimum = this .minimum;
031: int maximum = this .maximum;
032: int selection = this .selection;
033: int pageIncrement = this .pageIncrement;
034: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
035: RECT rect = new RECT();
036: rect.left = bounds.x;
037: rect.right = rect.left + bounds.width;
038: rect.top = bounds.y;
039: rect.bottom = rect.top + bounds.height;
040: SIZE size = new SIZE();
041: if ((style & SWT.VERTICAL) != 0) {
042: OS.GetThemePartSize(hTheme, gc.handle,
043: OS.TKP_TRACKVERT, 0, null, OS.TS_TRUE, size);
044: int trackWidth = size.cx - 1;
045: OS.GetThemePartSize(hTheme, gc.handle,
046: OS.TKP_THUMBVERT, 0, null, OS.TS_TRUE, size);
047: int thumbWidth = size.cx, thumbHeight = size.cy;
048: OS.GetThemePartSize(hTheme, gc.handle, OS.TKP_TICS, 0,
049: rect, OS.TS_TRUE, size);
050: int ticWidth = size.cx;
051: int marginX = (thumbWidth - trackWidth) / 2;
052: int marginY = marginX;
053: marginX += TICS_MARGIN;
054: rect.left += marginX;
055: rect.top += marginY;
056: rect.right = rect.left + trackWidth;
057: rect.bottom -= marginY;
058: int trackHeight = rect.bottom - rect.top;
059: OS.DrawThemeBackground(hTheme, gc.handle,
060: OS.TKP_TRACKVERT, 0, rect, null);
061: rect.top += ((trackHeight - thumbHeight) * (selection - minimum))
062: / Math.max(1, maximum - minimum);
063: rect.left -= (thumbWidth - trackWidth) / 2;
064: rect.right = rect.left + thumbWidth;
065: rect.bottom = rect.top + thumbHeight;
066: OS.DrawThemeBackground(hTheme, gc.handle,
067: OS.TKP_THUMBVERT, 0, rect, null);
068: rect.top = bounds.y + marginY + thumbHeight / 2;
069: rect.bottom = rect.top + 1;
070: for (int sel = minimum; sel <= maximum; sel += pageIncrement) {
071: rect.left = bounds.x + TICS_MARGIN / 2;
072: rect.right = rect.left + ticWidth;
073: if (sel != minimum && sel != maximum)
074: rect.left++;
075: rect.top = bounds.y + marginY + thumbHeight / 2;
076: rect.top += ((trackHeight - thumbHeight) * (sel - minimum))
077: / Math.max(1, maximum - minimum);
078: rect.bottom = rect.top + 1;
079: //TODO - why tics are ot drawn
080: OS.DrawThemeBackground(hTheme, gc.handle,
081: OS.TKP_TICSVERT, 1, rect, null);
082: gc.drawLine(rect.left, rect.top, rect.right,
083: rect.top);
084: rect.left = bounds.x + TICS_MARGIN + thumbWidth + 1;
085: rect.right = rect.left + ticWidth;
086: if (sel != minimum && sel != maximum)
087: rect.right--;
088: //TODO - why tics are ot drawn
089: OS.DrawThemeBackground(hTheme, gc.handle,
090: OS.TKP_TICSVERT, 1, rect, null);
091: gc.drawLine(rect.left, rect.top, rect.right,
092: rect.top);
093: }
094: } else {
095:
096: }
097: OS.CloseThemeData(hTheme);
098: }
099: }
100:
101: char[] getClassId() {
102: return TRACKBAR;
103: }
104:
105: int hit(Theme theme, Point position, Rectangle bounds) {
106: return bounds.contains(position) ? DrawData.WIDGET_WHOLE
107: : DrawData.WIDGET_NOWHERE;
108: }
109:
110: }
|