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 Pavel Dolgov
19: * @version $Revision$
20: */package org.apache.harmony.awt.theme.windows;
21:
22: import java.awt.Dimension;
23: import java.awt.Graphics;
24:
25: import org.apache.harmony.awt.state.ButtonState;
26:
27: import org.apache.harmony.awt.nativebridge.windows.WindowsConsts;
28: import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
29:
30: /**
31: * WinButton
32: */
33: public class WinButton extends WinStyle {
34:
35: public static void drawBackground(Graphics g, ButtonState s,
36: WinTheme t) {
37:
38: Dimension size = s.getSize();
39: WinThemeGraphics wgr = new WinThemeGraphics(g);
40:
41: if (t.isXpThemeActive()) {
42: wgr.setTheme(t.getXpTheme("Button")); //$NON-NLS-1$
43: wgr.fillBackground(size, s.getBackground(), false);
44: wgr.drawXpBackground(size, WindowsConsts.BP_PUSHBUTTON,
45: getXpState(s));
46: } else {
47: wgr.drawClassicBackground(size, WindowsDefs.DFC_BUTTON,
48: getClassicState(s));
49: }
50: if (s.isFocused()) {
51: wgr.drawFocusRect(size, 3);
52: }
53: wgr.dispose();
54: }
55:
56: private static int getXpState(ButtonState s) {
57: if (!s.isEnabled()) {
58: return WindowsConsts.PBS_DISABLED;
59: } else if (s.isPressed()) {
60: return WindowsConsts.PBS_PRESSED;
61: } else if (s.isFocused()) {
62: return WindowsConsts.PBS_DEFAULTED;
63: }
64: return WindowsConsts.PBS_NORMAL;
65: }
66:
67: private static int getClassicState(ButtonState s) {
68: int state = WindowsDefs.DFCS_BUTTONPUSH;
69: if (!s.isEnabled()) {
70: state |= WindowsDefs.DFCS_INACTIVE;
71: } else if (s.isPressed()) {
72: state |= WindowsDefs.DFCS_PUSHED;
73: }
74: return state;
75: }
76: }
|