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.Color;
023: import java.awt.Dimension;
024: import java.awt.Graphics;
025: import java.awt.Rectangle;
026: import java.awt.Shape;
027:
028: import org.apache.harmony.awt.gl.MultiRectArea;
029: import org.apache.harmony.awt.gl.windows.WinGDIPGraphics2D;
030:
031: /**
032: * Native painting of standard components
033: */
034: public final class WinThemeGraphics {
035:
036: private long hOldClipRgn;
037: private long hTheme;
038: private final long gi;
039: private final int trX;
040: private final int trY;
041:
042: public WinThemeGraphics(Graphics gr) {
043: WinGDIPGraphics2D wgr = (WinGDIPGraphics2D) gr;
044: this .gi = wgr.getGraphicsInfo();
045: trX = Math.round((float) wgr.getTransform().getTranslateX());
046: trY = Math.round((float) wgr.getTransform().getTranslateY());
047:
048: int clip[];
049: Shape clipShape = gr.getClip();
050: if (clipShape instanceof MultiRectArea) {
051: clip = ((MultiRectArea) clipShape).rect;
052: if (trX != 0 || trY != 0) {
053: int rect[] = clip;
054: int len = clip[0];
055: clip = new int[len];
056: System.arraycopy(rect, 0, clip, 0, len);
057: for (int i = 1; i < len; i += 2) {
058: clip[i] += trX;
059: clip[i + 1] += trY;
060: }
061: }
062: } else {
063: Rectangle r = clipShape.getBounds();
064: clip = new int[] { 5, trX + r.x, trY + r.y,
065: trX + r.x + r.width - 1, trY + r.x + r.height - 1 };
066: }
067:
068: hOldClipRgn = setGdiClip(gi, clip, clip[0] - 1);
069: }
070:
071: public void dispose() {
072: restoreGdiClip(gi, hOldClipRgn);
073: hOldClipRgn = 0;
074: }
075:
076: public void setTheme(long hTheme) {
077: this .hTheme = hTheme;
078: }
079:
080: public void drawXpBackground(Rectangle r, int type, int state) {
081: drawXpBackground(r.x, r.y, r.width, r.height, type, state);
082: }
083:
084: public void drawXpBackground(Dimension size, int type, int state) {
085: drawXpBackground(0, 0, size.width, size.height, type, state);
086: }
087:
088: public void drawXpBackground(int x, int y, int w, int h, int type,
089: int state) {
090: drawXpBackground(gi, trX + x, trY + y, w, h, hTheme, type,
091: state);
092: }
093:
094: public void drawClassicBackground(Rectangle r, int type, int state) {
095: drawClassicBackground(r.x, r.y, r.width, r.height, type, state);
096: }
097:
098: public void drawClassicBackground(Dimension size, int type,
099: int state) {
100: drawClassicBackground(0, 0, size.width, size.height, type,
101: state);
102: }
103:
104: public void drawClassicBackground(int x, int y, int w, int h,
105: int type, int state) {
106: drawClassicBackground(gi, trX + x, trY + y, w, h, type, state);
107: }
108:
109: public void fillBackground(Dimension size, Color color,
110: boolean solid) {
111: fillBackground(0, 0, size.width, size.height, color, solid);
112: }
113:
114: public void fillBackground(Rectangle r, Color color, boolean solid) {
115: fillBackground(r.x, r.y, r.width, r.height, color, solid);
116: }
117:
118: public void fillBackground(int x, int y, int w, int h, Color color,
119: boolean solid) {
120: fillBackground(gi, trX + x, trY + y, w, h, getRGB(color), solid);
121: }
122:
123: public void drawFocusRect(Rectangle r, int offset) {
124: drawFocusRect(r.x + offset, r.y + offset, r.width - 2 * offset,
125: r.height - 2 * offset);
126: }
127:
128: public void drawFocusRect(Dimension size, int offset) {
129: drawFocusRect(offset, offset, size.width - 2 * offset,
130: size.height - 2 * offset);
131: }
132:
133: public void drawFocusRect(int x, int y, int w, int h, int offset) {
134: drawFocusRect(x + offset, y + offset, w - 2 * offset, h - 2
135: * offset);
136: }
137:
138: public void drawFocusRect(int x, int y, int w, int h) {
139: drawFocusRect(gi, trX + x, trY + y, w, h);
140: }
141:
142: public void drawEdge(Rectangle r, int type) {
143: drawEdge(r.x, r.y, r.width, r.height, type);
144: }
145:
146: public void drawEdge(Dimension size, int type) {
147: drawEdge(0, 0, size.width, size.height, type);
148: }
149:
150: public void drawEdge(int x, int y, int w, int h, int type) {
151: drawEdge(gi, trX + x, trY + y, w, h, type);
152: }
153:
154: public void fillHatchedSysColorRect(Rectangle r, int sysColor1,
155: int sysColor2) {
156: fillHatchedSysColorRect(r.x, r.y, r.width, r.height, sysColor1,
157: sysColor2);
158: }
159:
160: public void fillHatchedSysColorRect(Dimension size, int sysColor1,
161: int sysColor2) {
162: fillHatchedSysColorRect(0, 0, size.width, size.height,
163: sysColor1, sysColor2);
164: }
165:
166: public void fillHatchedSysColorRect(int x, int y, int w, int h,
167: int sysColor1, int sysColor2) {
168: fillHatchedSysColorRect(gi, trX + x, trY + y, w, h, sysColor1,
169: sysColor2);
170: }
171:
172: private static int getRGB(Color c) {
173: return (c != null) ? c.getRGB() : 0xFFFFFFFF;
174: }
175:
176: public static native long setGdiClip(long gi, int clip[],
177: int clipLength);
178:
179: public static native void restoreGdiClip(long gi, long hOldClipRgn);
180:
181: private static native void drawXpBackground(long gi, int x, int y,
182: int w, int h, long hTheme, int type, int state);
183:
184: private static native void drawClassicBackground(long gi, int x,
185: int y, int w, int h, int type, int state);
186:
187: private static native void fillBackground(long gi, int x, int y,
188: int w, int h, int backColorRGB, boolean solidBack);
189:
190: private static native void drawFocusRect(long gi, int x, int y,
191: int w, int h);
192:
193: private static native void drawEdge(long gi, int x, int y, int w,
194: int h, int type);
195:
196: private static native void fillHatchedSysColorRect(long gi, int x,
197: int y, int w, int h, int sysColor1, int sysColor2);
198:
199: }
|