10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.windows;
27
28 import sun.awt.*;
29 import java.awt.*;
30 import java.awt.event.*;
31 import java.awt.peer.ComponentPeer;
32 import java.util.*;
33 import java.awt.color.*;
34 import java.awt.image.*;
35 import sun.awt.image.ByteInterleavedRaster;
36 import sun.security.action.GetPropertyAction;
37 import java.lang.reflect.*;
38
39 public class WEmbeddedFrame extends EmbeddedFrame {
40
41 static {
42 initIDs();
43 }
44
45 private long handle;
46
47 private int bandWidth = 0;
48 private int bandHeight = 0;
49 private int imgWid = 0;
50 private int imgHgt = 0;
51
52 private static int pScale = 0;
53 private static final int MAX_BAND_SIZE = (1024*30);
54
55 private static String printScale = (String) java.security.AccessController
56 .doPrivileged(new GetPropertyAction("sun.java2d.print.pluginscalefactor"));
57
58 public WEmbeddedFrame() {
59 this((long)0);
60 }
61
62 /**
63 * @deprecated This constructor will be removed in 1.5
64 */
65 @Deprecated
66 public WEmbeddedFrame(int handle) {
67 this((long)handle);
68 }
69
70 public WEmbeddedFrame(long handle) {
71 this.handle = handle;
72 if (handle != 0) {
73 addNotify();
74 show();
75 }
76 }
77
78 public void addNotify() {
79 if (getPeer() == null) {
80 WToolkit toolkit = (WToolkit)Toolkit.getDefaultToolkit();
81 setPeer(toolkit.createEmbeddedFrame(this));
82 }
83 super.addNotify();
84 }
85
86 /*
87 * Get the native handle
88 */
89 public long getEmbedderHandle() {
90 return handle;
91 }
92
93 /*
94 * Print the embedded frame and its children using the specified HDC.
95 */
96
97 void print(long hdc) {
117 * make for even bigger output for marginal extra quality.
118 * But for enhanced meta file we don't know anything about the
119 * real resolution of the destination so
120 */
121 if (isPrinterDC(hdc)) {
122 xscale = yscale = getPrintScaleFactor();
123 }
124
125 int frameHeight = getHeight();
126 if (bandImage == null) {
127 bandWidth = getWidth();
128 if (bandWidth % 4 != 0) {
129 bandWidth += (4 - (bandWidth % 4));
130 }
131 if (bandWidth <= 0) {
132 return;
133 }
134
135 bandHeight = Math.min(MAX_BAND_SIZE/bandWidth, frameHeight);
136
137 imgWid = (int)(bandWidth * xscale);
138 imgHgt = (int)(bandHeight * yscale);
139 bandImage = new BufferedImage(imgWid, imgHgt,
140 BufferedImage.TYPE_3BYTE_BGR);
141 }
142
143 Graphics clearGraphics = bandImage.getGraphics();
144 clearGraphics.setColor(Color.white);
145 Graphics2D g2d = (Graphics2D)bandImage.getGraphics();
146 g2d.translate(0, imgHgt);
147 g2d.scale(xscale, -yscale);
148
149 ByteInterleavedRaster ras = (ByteInterleavedRaster)bandImage.getRaster();
150 byte[] data = ras.getDataStorage();
151
152 for (int bandTop = 0; bandTop < frameHeight; bandTop += bandHeight) {
153 clearGraphics.fillRect(0, 0, bandWidth, bandHeight);
154
155 printComponents(g2d);
156 int imageOffset =0;
157 int currBandHeight = bandHeight;
158 int currImgHeight = imgHgt;
159 if ((bandTop+bandHeight) > frameHeight) {
160 // last band
161 currBandHeight = frameHeight - bandTop;
162 currImgHeight = (int)(currBandHeight*yscale);
163
164 // multiply by 3 because the image is a 3 byte BGR
165 imageOffset = imgWid*(imgHgt-currImgHeight)*3;
166 }
167
168 printBand(hdc, data, imageOffset,
169 0, 0, imgWid, currImgHeight,
170 0, bandTop, bandWidth, currBandHeight);
171 g2d.translate(0, -bandHeight);
172 }
173 }
174
175 protected static int getPrintScaleFactor() {
176 // check if value is already cached
177 if (pScale != 0)
178 return pScale;
179 if (printScale == null) {
180 // if no system property is specified,
181 // check for environment setting
182 printScale = (String) java.security.AccessController.doPrivileged(
183 new java.security.PrivilegedAction() {
184 public Object run() {
185 return System.getenv("JAVA2D_PLUGIN_PRINT_SCALE");
186 }
187 }
188 );
189 }
190 int default_printDC_scale = 4;
191 int scale = default_printDC_scale;
192 if (printScale != null) {
193 try {
194 scale = Integer.parseInt(printScale);
195 if (scale > 8 || scale < 1) {
196 scale = default_printDC_scale;
197 }
198 } catch (NumberFormatException nfe) {
199 }
200 }
201 pScale = scale;
202 return pScale;
203 }
204
209 int sx, int sy, int swidth, int sheight,
210 int dx, int dy, int dwidth, int dheight);
211
212 /**
213 * Initialize JNI field IDs
214 */
215 private static native void initIDs();
216
217 /**
218 * This method is called from the native code when this embedded
219 * frame should be activated. It is expected to be overridden in
220 * subclasses, for example, in plugin to activate the browser
221 * window that contains this embedded frame.
222 *
223 * NOTE: This method may be called by privileged threads.
224 * DO NOT INVOKE CLIENT CODE ON THIS THREAD!
225 */
226 public void activateEmbeddingTopLevel() {
227 }
228
229 public void synthesizeWindowActivation(final boolean doActivate) {
230 if (!doActivate || EventQueue.isDispatchThread()) {
231 ((WEmbeddedFramePeer)getPeer()).synthesizeWmActivate(doActivate);
232 } else {
233 // To avoid focus concurrence b/w IE and EmbeddedFrame
234 // activation is postponed by means of posting it to EDT.
235 EventQueue.invokeLater(new Runnable() {
236 public void run() {
237 ((WEmbeddedFramePeer)getPeer()).synthesizeWmActivate(true);
238 }
239 });
240 }
241 }
242
243 public void registerAccelerator(AWTKeyStroke stroke) {}
244 public void unregisterAccelerator(AWTKeyStroke stroke) {}
245
246 /**
247 * Should be overridden in subclasses. Call to
248 * super.notifyModalBlocked(blocker, blocked) must be present
|
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.awt.windows;
27
28 import sun.awt.*;
29 import java.awt.*;
30 import java.awt.peer.ComponentPeer;
31 import java.awt.image.*;
32 import sun.awt.image.ByteInterleavedRaster;
33 import sun.security.action.GetPropertyAction;
34 import java.security.PrivilegedAction;
35 import java.security.AccessController;
36
37 public class WEmbeddedFrame extends EmbeddedFrame {
38
39 static {
40 initIDs();
41 }
42
43 private long handle;
44
45 private int bandWidth = 0;
46 private int bandHeight = 0;
47 private int imgWid = 0;
48 private int imgHgt = 0;
49
50 private static int pScale = 0;
51 private static final int MAX_BAND_SIZE = (1024*30);
52
53 private static String printScale = AccessController.doPrivileged(
54 new GetPropertyAction("sun.java2d.print.pluginscalefactor"));
55
56 public WEmbeddedFrame() {
57 this((long)0);
58 }
59
60 /**
61 * @deprecated This constructor will be removed in 1.5
62 */
63 @Deprecated
64 public WEmbeddedFrame(int handle) {
65 this((long)handle);
66 }
67
68 public WEmbeddedFrame(long handle) {
69 this.handle = handle;
70 if (handle != 0) {
71 addNotify();
72 show();
73 }
74 }
75
76 @SuppressWarnings("deprecation")
77 public void addNotify() {
78 if (getPeer() == null) {
79 WToolkit toolkit = (WToolkit)Toolkit.getDefaultToolkit();
80 setPeer(toolkit.createEmbeddedFrame(this));
81 }
82 super.addNotify();
83 }
84
85 /*
86 * Get the native handle
87 */
88 public long getEmbedderHandle() {
89 return handle;
90 }
91
92 /*
93 * Print the embedded frame and its children using the specified HDC.
94 */
95
96 void print(long hdc) {
116 * make for even bigger output for marginal extra quality.
117 * But for enhanced meta file we don't know anything about the
118 * real resolution of the destination so
119 */
120 if (isPrinterDC(hdc)) {
121 xscale = yscale = getPrintScaleFactor();
122 }
123
124 int frameHeight = getHeight();
125 if (bandImage == null) {
126 bandWidth = getWidth();
127 if (bandWidth % 4 != 0) {
128 bandWidth += (4 - (bandWidth % 4));
129 }
130 if (bandWidth <= 0) {
131 return;
132 }
133
134 bandHeight = Math.min(MAX_BAND_SIZE/bandWidth, frameHeight);
135
136 imgWid = bandWidth * xscale;
137 imgHgt = bandHeight * yscale;
138 bandImage = new BufferedImage(imgWid, imgHgt,
139 BufferedImage.TYPE_3BYTE_BGR);
140 }
141
142 Graphics clearGraphics = bandImage.getGraphics();
143 clearGraphics.setColor(Color.white);
144 Graphics2D g2d = (Graphics2D)bandImage.getGraphics();
145 g2d.translate(0, imgHgt);
146 g2d.scale(xscale, -yscale);
147
148 ByteInterleavedRaster ras = (ByteInterleavedRaster)bandImage.getRaster();
149 byte[] data = ras.getDataStorage();
150
151 for (int bandTop = 0; bandTop < frameHeight; bandTop += bandHeight) {
152 clearGraphics.fillRect(0, 0, bandWidth, bandHeight);
153
154 printComponents(g2d);
155 int imageOffset =0;
156 int currBandHeight = bandHeight;
157 int currImgHeight = imgHgt;
158 if ((bandTop+bandHeight) > frameHeight) {
159 // last band
160 currBandHeight = frameHeight - bandTop;
161 currImgHeight = currBandHeight*yscale;
162
163 // multiply by 3 because the image is a 3 byte BGR
164 imageOffset = imgWid*(imgHgt-currImgHeight)*3;
165 }
166
167 printBand(hdc, data, imageOffset,
168 0, 0, imgWid, currImgHeight,
169 0, bandTop, bandWidth, currBandHeight);
170 g2d.translate(0, -bandHeight);
171 }
172 }
173
174 protected static int getPrintScaleFactor() {
175 // check if value is already cached
176 if (pScale != 0)
177 return pScale;
178 if (printScale == null) {
179 // if no system property is specified,
180 // check for environment setting
181 printScale = AccessController.doPrivileged(
182 new PrivilegedAction<String>() {
183 public String run() {
184 return System.getenv("JAVA2D_PLUGIN_PRINT_SCALE");
185 }
186 }
187 );
188 }
189 int default_printDC_scale = 4;
190 int scale = default_printDC_scale;
191 if (printScale != null) {
192 try {
193 scale = Integer.parseInt(printScale);
194 if (scale > 8 || scale < 1) {
195 scale = default_printDC_scale;
196 }
197 } catch (NumberFormatException nfe) {
198 }
199 }
200 pScale = scale;
201 return pScale;
202 }
203
208 int sx, int sy, int swidth, int sheight,
209 int dx, int dy, int dwidth, int dheight);
210
211 /**
212 * Initialize JNI field IDs
213 */
214 private static native void initIDs();
215
216 /**
217 * This method is called from the native code when this embedded
218 * frame should be activated. It is expected to be overridden in
219 * subclasses, for example, in plugin to activate the browser
220 * window that contains this embedded frame.
221 *
222 * NOTE: This method may be called by privileged threads.
223 * DO NOT INVOKE CLIENT CODE ON THIS THREAD!
224 */
225 public void activateEmbeddingTopLevel() {
226 }
227
228 @SuppressWarnings("deprecation")
229 public void synthesizeWindowActivation(final boolean doActivate) {
230 if (!doActivate || EventQueue.isDispatchThread()) {
231 ((WEmbeddedFramePeer)getPeer()).synthesizeWmActivate(doActivate);
232 } else {
233 // To avoid focus concurrence b/w IE and EmbeddedFrame
234 // activation is postponed by means of posting it to EDT.
235 EventQueue.invokeLater(new Runnable() {
236 public void run() {
237 ((WEmbeddedFramePeer)getPeer()).synthesizeWmActivate(true);
238 }
239 });
240 }
241 }
242
243 public void registerAccelerator(AWTKeyStroke stroke) {}
244 public void unregisterAccelerator(AWTKeyStroke stroke) {}
245
246 /**
247 * Should be overridden in subclasses. Call to
248 * super.notifyModalBlocked(blocker, blocked) must be present
|