001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Pavel Dolgov
019: * @version $Revision$
020: */package org.apache.harmony.awt.theme.windows;
021:
022: import java.awt.Dimension;
023: import java.awt.Graphics;
024: import java.awt.Rectangle;
025:
026: import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
027: import org.apache.harmony.awt.state.ScrollbarState;
028:
029: /**
030: * WinScrollbar
031: */
032: public class WinScrollbar extends WinStyle {
033:
034: public static void draw(Graphics g, ScrollbarState s, WinTheme t) {
035: WinThemeGraphics wgr = new WinThemeGraphics(g);
036: if (t.isXpThemeActive()) {
037: wgr.setTheme(t.getXpTheme("Scrollbar")); //$NON-NLS-1$
038: drawXp(wgr, s);
039: } else {
040: drawClassic(wgr, s);
041: }
042: wgr.dispose();
043: }
044:
045: static void drawXp(WinThemeGraphics wgr, ScrollbarState s) {
046: if (s.isVertical()) {
047: drawXpVertical(wgr, s);
048: } else {
049: drawXpHorzontal(wgr, s);
050: }
051: }
052:
053: static void drawXpVertical(WinThemeGraphics wgr, ScrollbarState s) {
054: boolean enabled = s.isEnabled();
055:
056: int state = enabled ? SCRBS_NORMAL : SCRBS_DISABLED;
057: if (s.getHighlight() == ScrollbarState.DECREASE_HIGHLIGHT) {
058: state = SCRBS_PRESSED;
059: }
060: wgr.drawXpBackground(getLowerTrackBounds(s),
061: SBP_LOWERTRACKVERT, state);
062:
063: state = enabled ? SCRBS_NORMAL : SCRBS_DISABLED;
064: if (s.getHighlight() == ScrollbarState.INCREASE_HIGHLIGHT) {
065: state = SCRBS_PRESSED;
066: }
067: wgr.drawXpBackground(getUpperTrackBounds(s),
068: SBP_UPPERTRACKVERT, state);
069:
070: state = s.isEnabled() ? (s.isSliderPressed() ? SCRBS_PRESSED
071: : SCRBS_NORMAL) : SCRBS_DISABLED;
072: wgr
073: .drawXpBackground(s.getSliderRect(), SBP_THUMBBTNVERT,
074: state);
075: wgr.drawXpBackground(s.getSliderRect(), SBP_GRIPPERVERT, 0);
076:
077: state = enabled ? (s.isDecreasePressed() ? ABS_UPPRESSED
078: : ABS_UPNORMAL) : ABS_UPDISABLED;
079: wgr.drawXpBackground(s.getDecreaseRect(), SBP_ARROWBTN, state);
080:
081: state = enabled ? (s.isIncreasePressed() ? ABS_DOWNPRESSED
082: : ABS_DOWNNORMAL) : ABS_DOWNDISABLED;
083: wgr.drawXpBackground(s.getIncreaseRect(), SBP_ARROWBTN, state);
084: }
085:
086: static void drawXpHorzontal(WinThemeGraphics wgr, ScrollbarState s) {
087: boolean enabled = s.isEnabled();
088:
089: int state = enabled ? SCRBS_NORMAL : SCRBS_DISABLED;
090: if (s.getHighlight() == ScrollbarState.DECREASE_HIGHLIGHT) {
091: state = SCRBS_PRESSED;
092: }
093: wgr.drawXpBackground(getLowerTrackBounds(s),
094: SBP_LOWERTRACKHORZ, state);
095:
096: state = enabled ? SCRBS_NORMAL : SCRBS_DISABLED;
097: if (s.getHighlight() == ScrollbarState.INCREASE_HIGHLIGHT) {
098: state = SCRBS_PRESSED;
099: }
100: wgr.drawXpBackground(getUpperTrackBounds(s),
101: SBP_UPPERTRACKHORZ, state);
102:
103: state = s.isEnabled() ? (s.isSliderPressed() ? SCRBS_PRESSED
104: : SCRBS_NORMAL) : SCRBS_DISABLED;
105: wgr
106: .drawXpBackground(s.getSliderRect(), SBP_THUMBBTNHORZ,
107: state);
108: wgr.drawXpBackground(s.getSliderRect(), SBP_GRIPPERHORZ, state);
109:
110: state = enabled ? (s.isDecreasePressed() ? ABS_LEFTPRESSED
111: : ABS_LEFTNORMAL) : ABS_LEFTDISABLED;
112: wgr.drawXpBackground(s.getDecreaseRect(), SBP_ARROWBTN, state);
113:
114: state = enabled ? (s.isIncreasePressed() ? ABS_RIGHTPRESSED
115: : ABS_RIGHTNORMAL) : ABS_RIGHTDISABLED;
116: wgr.drawXpBackground(s.getIncreaseRect(), SBP_ARROWBTN, state);
117: }
118:
119: private static Rectangle getUpperTrackBounds(ScrollbarState s) {
120: Rectangle slider = s.getSliderRect();
121: Rectangle button = s.getIncreaseRect();
122: Rectangle track = new Rectangle();
123: Dimension size = s.getSize();
124: if (s.isVertical()) {
125: track.width = size.width;
126: track.y = button.y;
127: track.height = slider.y - track.y;
128: } else {
129: track.height = size.height;
130: track.x = button.x;
131: track.width = slider.x - track.x;
132: }
133: return track;
134: }
135:
136: private static Rectangle getLowerTrackBounds(ScrollbarState s) {
137: Rectangle slider = s.getSliderRect();
138: Rectangle button = s.getDecreaseRect();
139: Rectangle track = new Rectangle();
140: Dimension size = s.getSize();
141: if (s.isVertical()) {
142: track.width = size.width;
143: track.y = slider.y + slider.height;
144: track.height = button.y - track.y;
145: } else {
146: track.height = size.height;
147: track.x = slider.x + slider.width;
148: track.width = button.x - track.x;
149: }
150: return track;
151: }
152:
153: static void drawClassic(WinThemeGraphics wgr, ScrollbarState s) {
154: boolean enabled = s.isEnabled();
155: fillClassicBackground(wgr, getUpperTrackBounds(s), s
156: .getHighlight() == ScrollbarState.INCREASE_HIGHLIGHT);
157: fillClassicBackground(wgr, getLowerTrackBounds(s), s
158: .getHighlight() == ScrollbarState.DECREASE_HIGHLIGHT);
159:
160: int state = WindowsDefs.DFCS_BUTTONPUSH
161: | getClassicButtonState(enabled, s.isSliderPressed());
162:
163: wgr.drawClassicBackground(s.getSliderRect(),
164: WindowsDefs.DFC_BUTTON, state);
165:
166: int dir = s.isVertical() ? WindowsDefs.DFCS_SCROLLUP
167: : WindowsDefs.DFCS_SCROLLLEFT;
168: state = dir
169: | getClassicButtonState(enabled, s.isDecreasePressed());
170: wgr.drawClassicBackground(s.getDecreaseRect(),
171: WindowsDefs.DFC_SCROLL, state);
172:
173: dir = s.isVertical() ? WindowsDefs.DFCS_SCROLLDOWN
174: : WindowsDefs.DFCS_SCROLLRIGHT;
175: state = dir
176: | getClassicButtonState(enabled, s.isIncreasePressed());
177: wgr.drawClassicBackground(s.getIncreaseRect(),
178: WindowsDefs.DFC_SCROLL, state);
179:
180: if (s.isFocused()) {
181: drawFocus(wgr, s);
182: }
183: }
184:
185: private static void fillClassicBackground(WinThemeGraphics wgr,
186: Rectangle r, boolean highlight) {
187: int sysColor1, sysColor2;
188: if (highlight) {
189: sysColor1 = WindowsDefs.COLOR_3DDKSHADOW;
190: sysColor2 = WindowsDefs.COLOR_WINDOWTEXT;
191: } else {
192: sysColor1 = WindowsDefs.COLOR_WINDOW;
193: sysColor2 = WindowsDefs.COLOR_BTNFACE;
194: }
195: wgr.fillHatchedSysColorRect(r, sysColor1, sysColor2);
196: }
197:
198: private static void drawFocus(WinThemeGraphics wgr, ScrollbarState s) {
199: Rectangle sliderRect = s.getSliderRect();
200: if ((sliderRect == null) || sliderRect.isEmpty()) {
201: return;
202: }
203: Rectangle focusRect = new Rectangle(sliderRect);
204: focusRect.grow(-2, -2);
205: wgr
206: .fillHatchedSysColorRect(focusRect,
207: WindowsDefs.COLOR_3DDKSHADOW,
208: WindowsDefs.COLOR_BTNFACE);
209: }
210: }
|