01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Dmitry A. Durnev
19: * @version $Revision$
20: */package org.apache.harmony.awt.theme.windows;
21:
22: import java.awt.Color;
23: import java.awt.Dimension;
24: import java.awt.Graphics;
25: import java.awt.Rectangle;
26: import java.awt.SystemColor;
27:
28: import org.apache.harmony.awt.state.ChoiceState;
29:
30: import org.apache.harmony.awt.nativebridge.windows.WindowsConsts;
31: import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
32:
33: /**
34: * WinChoice
35: */
36: public class WinChoice extends WinStyle {
37:
38: public static void drawBackground(Graphics g, ChoiceState s,
39: WinTheme t) {
40: Dimension size = s.getSize();
41:
42: WinThemeGraphics wgr = new WinThemeGraphics(g);
43:
44: if (t.isXpThemeActive()) {
45:
46: wgr.setTheme(t.getXpTheme("Edit")); //$NON-NLS-1$
47: wgr.drawXpBackground(size, WindowsConsts.EP_EDITTEXT,
48: WindowsConsts.ETS_NORMAL);
49:
50: wgr.setTheme(t.getXpTheme("Combobox")); //$NON-NLS-1$
51: Rectangle r = s.getButtonBounds();
52: r.grow(1, 1);
53: wgr.drawXpBackground(r, WindowsConsts.CP_DROPDOWNBUTTON,
54: getXpButtonState(s));
55:
56: } else {
57: Color c = s.isBackgroundSet() ? s.getBackground()
58: : SystemColor.window;
59: g.setColor(c);
60: wgr.fillBackground(1, 1, size.width - 2, size.height - 2,
61: c, true);
62: wgr.drawEdge(size, WindowsDefs.EDGE_SUNKEN);
63: wgr.drawClassicBackground(s.getButtonBounds(), DFC_SCROLL,
64: getClassicButtonState(s));
65: }
66:
67: if (s.isFocused()) {
68: Rectangle r = s.getTextBounds();
69: r.grow(1, 0);
70: g.setColor(SystemColor.textHighlight);
71: g.fillRect(r.x, r.y, r.width, r.height);
72: wgr.drawFocusRect(r, 0);
73: }
74:
75: wgr.dispose();
76: }
77:
78: private static int getXpButtonState(ChoiceState s) {
79: if (s.isPressed()) {
80: return WindowsConsts.CBXS_PRESSED;
81: }
82: if (!s.isEnabled()) {
83: return WindowsConsts.CBXS_DISABLED;
84: }
85: return WindowsConsts.CBXS_NORMAL;
86: }
87:
88: private static int getClassicButtonState(ChoiceState s) {
89: int state = DFCS_SCROLLCOMBOBOX;
90: if (!s.isEnabled()) {
91: state |= DFCS_INACTIVE;
92: }
93: if (s.isPressed()) {
94: state |= DFCS_PUSHED;
95: }
96: return state;
97: }
98: }
|