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.state.CheckboxState;
027:
028: import org.apache.harmony.awt.nativebridge.windows.WindowsConsts;
029: import org.apache.harmony.awt.nativebridge.windows.WindowsDefs;
030:
031: /**
032: * WinCheckbox
033: */
034: public class WinCheckbox extends WinStyle {
035:
036: static final int CB_SIZE = 13;
037: static final int ABS_MARGIN = 4;
038:
039: public static void drawBackground(Graphics g, CheckboxState s,
040: Rectangle focusRect, WinTheme t) {
041:
042: Dimension size = s.getSize();
043: int y = size.height / 2 - CB_SIZE / 2;
044: Rectangle bounds = new Rectangle(ABS_MARGIN, y, CB_SIZE,
045: CB_SIZE);
046:
047: g.setColor(s.getBackground());
048: g.fillRect(0, 0, size.width, size.height);
049:
050: WinThemeGraphics wgr = new WinThemeGraphics(g);
051: wgr.fillBackground(size, s.getBackground(), true);
052:
053: if (t.isXpThemeActive()) {
054: wgr.setTheme(t.getXpTheme("Button")); //$NON-NLS-1$
055: wgr.drawXpBackground(bounds, getXpType(s), getXpState(s));
056: } else {
057: wgr.drawClassicBackground(bounds, WindowsDefs.DFC_BUTTON,
058: getClassicState(s));
059: }
060: if (s.isFocused()) {
061: wgr.drawFocusRect(focusRect, -1);
062: }
063: wgr.dispose();
064: }
065:
066: private static int getXpType(CheckboxState s) {
067: return s.isInGroup() ? WindowsConsts.BP_RADIOBUTTON
068: : WindowsConsts.BP_CHECKBOX;
069: }
070:
071: private static int getXpState(CheckboxState s) {
072: if (s.isChecked()) {
073: if (s.isPressed()) {
074: return WindowsConsts.CBS_CHECKEDPRESSED;
075: }
076: if (!s.isEnabled()) {
077: return WindowsConsts.CBS_CHECKEDDISABLED;
078: }
079: return WindowsConsts.CBS_CHECKEDNORMAL;
080: }
081: if (s.isPressed()) {
082: return WindowsConsts.CBS_UNCHECKEDPRESSED;
083: }
084: if (!s.isEnabled()) {
085: return WindowsConsts.CBS_UNCHECKEDDISABLED;
086: }
087: return WindowsConsts.CBS_UNCHECKEDNORMAL;
088: }
089:
090: private static int getClassicState(CheckboxState s) {
091: int state = s.isInGroup() ? WindowsDefs.DFCS_BUTTONRADIO
092: : WindowsDefs.DFCS_BUTTONCHECK;
093: if (s.isPressed()) {
094: state |= WindowsDefs.DFCS_PUSHED;
095: }
096: if (s.isChecked()) {
097: state |= WindowsDefs.DFCS_CHECKED;
098: }
099: if (!s.isEnabled()) {
100: state |= WindowsDefs.DFCS_INACTIVE;
101: }
102: return state;
103: }
104: }
|