01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.swt.internal.theme;
11:
12: import org.eclipse.swt.*;
13: import org.eclipse.swt.graphics.*;
14: import org.eclipse.swt.internal.win32.*;
15:
16: public class ProgressBarDrawData extends RangeDrawData {
17:
18: public ProgressBarDrawData() {
19: state = new int[1];
20: }
21:
22: void draw(Theme theme, GC gc, Rectangle bounds) {
23: if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
24: int /*long*/hTheme = OS.OpenThemeData(0, getClassId());
25: RECT rect = new RECT();
26: rect.left = bounds.x;
27: rect.right = rect.left + bounds.width;
28: rect.top = bounds.y;
29: rect.bottom = rect.top + bounds.height;
30: int[] buffer = new int[1];
31: OS.GetThemeInt(hTheme, 0, 0, OS.PROGRESSCHUNKSIZE, buffer);
32: int chunkSize = buffer[0];
33: OS.GetThemeInt(hTheme, 0, 0, OS.PROGRESSSPACESIZE, buffer);
34: int spaceSize = buffer[0];
35: RECT content = new RECT();
36: int[] part = getPartId(DrawData.WIDGET_WHOLE);
37: if ((style & SWT.VERTICAL) != 0) {
38: OS.GetThemeBackgroundContentRect(hTheme, gc.handle,
39: part[0], part[1], rect, content);
40: OS.DrawThemeBackground(hTheme, gc.handle, part[0],
41: part[1], rect, null);
42: int top = content.bottom
43: - (((content.bottom - content.top) * (selection - minimum)) / (maximum - minimum));
44: content.top = content.bottom - chunkSize;
45: while (content.top >= top) {
46: OS.DrawThemeBackground(hTheme, gc.handle,
47: OS.PP_CHUNKVERT, 0, content, null);
48: content.bottom -= chunkSize + spaceSize;
49: content.top = content.bottom - chunkSize;
50: }
51: if (selection != 0) {
52: OS.DrawThemeBackground(hTheme, gc.handle,
53: OS.PP_CHUNKVERT, 0, content, null);
54: }
55: } else {
56: OS.GetThemeBackgroundContentRect(hTheme, gc.handle,
57: part[0], part[1], rect, content);
58: OS.DrawThemeBackground(hTheme, gc.handle, part[0],
59: part[1], rect, null);
60: int right = content.left
61: + (((content.right - content.left) * (selection - minimum)) / (maximum - minimum));
62: content.right = content.left + chunkSize;
63: while (content.right <= right) {
64: OS.DrawThemeBackground(hTheme, gc.handle,
65: OS.PP_CHUNK, 0, content, null);
66: content.left += chunkSize + spaceSize;
67: content.right = content.left + chunkSize;
68: }
69: if (selection != 0) {
70: OS.DrawThemeBackground(hTheme, gc.handle,
71: OS.PP_CHUNK, 0, content, null);
72: }
73: }
74: OS.CloseThemeData(hTheme);
75: }
76: }
77:
78: char[] getClassId() {
79: return PROGRESS;
80: }
81:
82: int[] getPartId(int part) {
83: int iPartId = 0, iStateId = 0;
84: if ((style & SWT.VERTICAL) != 0) {
85: iPartId = OS.PP_BARVERT;
86: } else {
87: iPartId = OS.PP_BAR;
88: }
89: return new int[] { iPartId, iStateId };
90: }
91:
92: int hit(Theme theme, Point position, Rectangle bounds) {
93: return bounds.contains(position) ? DrawData.WIDGET_WHOLE
94: : DrawData.WIDGET_NOWHERE;
95: }
96:
97: }
|