KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > internal > theme > ScaleDrawData


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 ScaleDrawData extends RangeDrawData {
18     public int increment;
19     public int pageIncrement;
20     
21     static final int TICS_MARGIN = 10;
22
23 public ScaleDrawData() {
24     state = new int[4];
25 }
26
27 void draw(Theme theme, GC gc, Rectangle bounds) {
28     if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) {
29         // TODO - drawScale not done
30
int style = this.style;
31         int minimum = this.minimum;
32         int maximum = this.maximum;
33         int selection = this.selection;
34         int pageIncrement = this.pageIncrement;
35         int hTheme = OS.OpenThemeData(0, getClassId());
36         RECT rect = new RECT ();
37         rect.left = bounds.x;
38         rect.right = rect.left + bounds.width;
39         rect.top = bounds.y;
40         rect.bottom = rect.top + bounds.height;
41         SIZE size = new SIZE();
42         if ((style & SWT.VERTICAL) != 0) {
43             OS.GetThemePartSize(hTheme, gc.handle, OS.TKP_TRACKVERT, 0, null, OS.TS_TRUE, size);
44             int trackWidth = size.cx - 1;
45             OS.GetThemePartSize(hTheme, gc.handle, OS.TKP_THUMBVERT, 0, null, OS.TS_TRUE, size);
46             int thumbWidth = size.cx, thumbHeight = size.cy;
47             OS.GetThemePartSize(hTheme, gc.handle, OS.TKP_TICS, 0, rect, OS.TS_TRUE, size);
48             int ticWidth = size.cx;
49             int marginX = (thumbWidth - trackWidth) / 2;
50             int marginY = marginX;
51             marginX += TICS_MARGIN;
52             rect.left += marginX;
53             rect.top += marginY;
54             rect.right = rect.left + trackWidth;
55             rect.bottom -= marginY;
56             int trackHeight = rect.bottom - rect.top;
57             OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_TRACKVERT, 0, rect, null);
58             rect.top += ((trackHeight - thumbHeight) * (selection - minimum)) / Math.max(1, maximum - minimum);
59             rect.left -= (thumbWidth - trackWidth) / 2;
60             rect.right = rect.left + thumbWidth;
61             rect.bottom = rect.top + thumbHeight;
62             OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_THUMBVERT, 0, rect, null);
63             rect.top = bounds.y + marginY + thumbHeight / 2;
64             rect.bottom = rect.top + 1;
65             for (int sel = minimum; sel <= maximum; sel += pageIncrement) {
66                 rect.left = bounds.x + TICS_MARGIN / 2;
67                 rect.right = rect.left + ticWidth;
68                 if (sel != minimum && sel != maximum) rect.left++;
69                 rect.top = bounds.y + marginY + thumbHeight / 2;
70                 rect.top += ((trackHeight - thumbHeight) * (sel - minimum)) / Math.max(1, maximum - minimum);
71                 rect.bottom = rect.top + 1;
72                 //TODO - why tics are ot drawn
73
OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_TICSVERT, 1, rect, null);
74                 gc.drawLine(rect.left, rect.top, rect.right, rect.top);
75                 rect.left = bounds.x + TICS_MARGIN + thumbWidth + 1;
76                 rect.right = rect.left + ticWidth;
77                 if (sel != minimum && sel != maximum) rect.right--;
78                 //TODO - why tics are ot drawn
79
OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_TICSVERT, 1, rect, null);
80                 gc.drawLine(rect.left, rect.top, rect.right, rect.top);
81             }
82         } else {
83
84         }
85         OS.CloseThemeData (hTheme);
86     }
87 }
88
89 char[] getClassId() {
90     return TRACKBAR;
91 }
92
93 int hit(Theme theme, Point position, Rectangle bounds) {
94     return bounds.contains(position) ? DrawData.WIDGET_WHOLE : DrawData.WIDGET_NOWHERE;
95 }
96
97 }
98
Popular Tags