2010/04/02 freebeans
*WCEComponentPeer.java(setBounds):Fixed bug #21269
@@ -1,39 +1,38 @@ | ||
1 | -/* WCEComponentPeer.java | |
2 | - Copyright (C) 2005 Free Software Foundation, Inc. | |
1 | +/* | |
2 | + * WCEComponentPeer.java Copyright (C) 2005 Free Software Foundation, Inc. | |
3 | + * | |
4 | + * This file is part of GNU Classpath. | |
5 | + * | |
6 | + * GNU Classpath is free software; you can redistribute it and/or modify it | |
7 | + * under the terms of the GNU General Public License as published by the Free | |
8 | + * Software Foundation; version 2 of the License. | |
9 | + * | |
10 | + * GNU Classpath is distributed in the hope that it will be useful, but WITHOUT | |
11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
12 | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
13 | + * details. | |
14 | + * | |
15 | + * You should have received a copy of the GNU General Public License along with | |
16 | + * GNU Classpath; see the file COPYING. If not, write to the Free Software | |
17 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
18 | + * | |
19 | + * Linking this library statically or dynamically with other modules is making a | |
20 | + * combined work based on this library. Thus, the terms and conditions of the | |
21 | + * GNU General Public License cover the whole combination. | |
22 | + * | |
23 | + * As a special exception, the copyright holders of this library give you | |
24 | + * permission to link this library with independent modules to produce an | |
25 | + * executable, regardless of the license terms of these independent modules, and | |
26 | + * to copy and distribute the resulting executable under terms of your choice, | |
27 | + * provided that you also meet, for each linked independent module, the terms | |
28 | + * and conditions of the license of that module. An independent module is a | |
29 | + * module which is not derived from or based on this library. If you modify this | |
30 | + * library, you may extend this exception to your version of the library, but | |
31 | + * you are not obligated to do so. If you do not wish to do so, delete this | |
32 | + * exception statement from your version. | |
33 | + */ | |
3 | 34 | |
4 | -This file is part of GNU Classpath. | |
5 | 35 | |
6 | -GNU Classpath is free software; you can redistribute it and/or modify | |
7 | -it under the terms of the GNU General Public License as published by | |
8 | -the Free Software Foundation; version 2 of the License. | |
9 | - | |
10 | -GNU Classpath is distributed in the hope that it will be useful, but | |
11 | -WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | -General Public License for more details. | |
14 | - | |
15 | -You should have received a copy of the GNU General Public License | |
16 | -along with GNU Classpath; see the file COPYING. If not, write to the | |
17 | -Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
18 | -02111-1307 USA. | |
19 | - | |
20 | -Linking this library statically or dynamically with other modules is | |
21 | -making a combined work based on this library. Thus, the terms and | |
22 | -conditions of the GNU General Public License cover the whole | |
23 | -combination. | |
24 | - | |
25 | -As a special exception, the copyright holders of this library give you | |
26 | -permission to link this library with independent modules to produce an | |
27 | -executable, regardless of the license terms of these independent | |
28 | -modules, and to copy and distribute the resulting executable under | |
29 | -terms of your choice, provided that you also meet, for each linked | |
30 | -independent module, the terms and conditions of the license of that | |
31 | -module. An independent module is a module which is not derived from | |
32 | -or based on this library. If you modify this library, you may extend | |
33 | -this exception to your version of the library, but you are not | |
34 | -obligated to do so. If you do not wish to do so, delete this | |
35 | -exception statement from your version. */ | |
36 | - | |
37 | 36 | package gnu.java.awt.peer.wce; |
38 | 37 | |
39 | 38 | import gnu.java.awt.peer.wce.font.WCEFontPeer; |
@@ -51,6 +50,7 @@ | ||
51 | 50 | import java.awt.EventQueue; |
52 | 51 | import java.awt.Font; |
53 | 52 | import java.awt.FontMetrics; |
53 | +import java.awt.Frame; | |
54 | 54 | import java.awt.Graphics; |
55 | 55 | import java.awt.GraphicsConfiguration; |
56 | 56 | import java.awt.GraphicsEnvironment; |
@@ -80,25 +80,25 @@ | ||
80 | 80 | /** |
81 | 81 | * WCEComponentPeerクラス。 |
82 | 82 | */ |
83 | -public abstract class WCEComponentPeer implements ComponentPeer | |
83 | +public abstract class WCEComponentPeer | |
84 | + implements ComponentPeer | |
84 | 85 | { |
85 | - | |
86 | + | |
86 | 87 | /** |
87 | 88 | * イベントキュー |
88 | 89 | */ |
89 | 90 | static final EventQueue queue = WCEToolkit.queue; |
90 | - | |
91 | + | |
91 | 92 | /** |
92 | 93 | * 対応するComponent |
93 | 94 | */ |
94 | 95 | private final Component component; |
95 | - | |
96 | + | |
96 | 97 | /** |
97 | 98 | * ネイティブウインドウハンドル。 |
98 | 99 | */ |
99 | 100 | private final int hwnd; |
100 | - | |
101 | - | |
101 | + | |
102 | 102 | /** |
103 | 103 | * 今までに表示されたことがあるか? |
104 | 104 | */ |
@@ -106,13 +106,13 @@ | ||
106 | 106 | |
107 | 107 | /** |
108 | 108 | * 指定されたコンポーネントに対応するpeerのインスタンスを作成する |
109 | - * | |
110 | - * @param c コンポーネント | |
109 | + * | |
110 | + * @param c コンポーネント | |
111 | 111 | */ |
112 | 112 | protected WCEComponentPeer(Component c) |
113 | 113 | { |
114 | 114 | this.component = c; |
115 | - | |
115 | + | |
116 | 116 | // 親のウインドウハンドルを得る |
117 | 117 | int hParentWnd = searchParentWindowHandle(); |
118 | 118 |
@@ -119,17 +119,17 @@ | ||
119 | 119 | // ネイティブウインドウを生成する |
120 | 120 | Rectangle r = c.getBounds(); |
121 | 121 | this.hwnd = createNative(hParentWnd, r.x, r.y, r.width, r.height); |
122 | - | |
122 | + | |
123 | 123 | setBounds(r.x, r.y, r.width, r.height); |
124 | - | |
124 | + | |
125 | 125 | // 色とフォントを設定する |
126 | 126 | setForeground(c.getForeground()); |
127 | 127 | setBackground(c.getBackground()); |
128 | 128 | if (c.isFontSet()) |
129 | - { | |
130 | - setFont(c.getFont()); | |
131 | - } | |
132 | - | |
129 | + { | |
130 | + setFont(c.getFont()); | |
131 | + } | |
132 | + | |
133 | 133 | // 可視状態を設定する |
134 | 134 | setVisible(c.isVisible()); |
135 | 135 |
@@ -136,7 +136,7 @@ | ||
136 | 136 | // 有効/無効状態を設定する |
137 | 137 | setEnabled(c.isEnabled()); |
138 | 138 | } |
139 | - | |
139 | + | |
140 | 140 | /** |
141 | 141 | * このコンポーネントのウインドウハンドルを返す |
142 | 142 | */ |
@@ -144,15 +144,12 @@ | ||
144 | 144 | { |
145 | 145 | return this.hwnd; |
146 | 146 | } |
147 | - | |
147 | + | |
148 | 148 | /** |
149 | - * 親コンポーネントに対応するウインドウハンドルを取得する | |
150 | - * 直接の親がLightWeightコンポーネントの場合は、heavy-weight | |
151 | - * コンポーネントにたどり着くまでさかのぼり、そのウインドウハンドルを | |
152 | - * 返す。 | |
153 | - * 親がいない、または全ての親がLight-weightの場合には0を返す。 | |
154 | - * | |
155 | - * @return 親のウインドウハンドル | |
149 | + * 親コンポーネントに対応するウインドウハンドルを取得する 直接の親がLightWeightコンポーネントの場合は、heavy-weight | |
150 | + * コンポーネントにたどり着くまでさかのぼり、そのウインドウハンドルを 返す。 親がいない、または全ての親がLight-weightの場合には0を返す。 | |
151 | + * | |
152 | + * @return 親のウインドウハンドル | |
156 | 153 | */ |
157 | 154 | protected int searchParentWindowHandle() |
158 | 155 | { |
@@ -160,17 +157,17 @@ | ||
160 | 157 | int hwnd = 0; |
161 | 158 | // heavyweightコンポーネントを検索する |
162 | 159 | for (Component c = getComponent().getParent(); c != null; c = c.getParent()) |
163 | - { | |
164 | - p = c.getPeer(); | |
165 | - if (p instanceof WCEComponentPeer) | |
166 | 160 | { |
167 | - hwnd = ((WCEComponentPeer) p).hwnd; | |
168 | - break; | |
161 | + p = c.getPeer(); | |
162 | + if (p instanceof WCEComponentPeer) | |
163 | + { | |
164 | + hwnd = ((WCEComponentPeer) p).hwnd; | |
165 | + break; | |
166 | + } | |
169 | 167 | } |
170 | - } | |
171 | 168 | return hwnd; |
172 | 169 | } |
173 | - | |
170 | + | |
174 | 171 | /** |
175 | 172 | * このピアに関連付けられたComponentを返す。 |
176 | 173 | */ |
@@ -178,20 +175,19 @@ | ||
178 | 175 | { |
179 | 176 | return this.component; |
180 | 177 | } |
181 | - | |
178 | + | |
182 | 179 | /** |
183 | - * 指定されたサイズのネイティブウインドウを作成し、 | |
184 | - * そのウインドウハンドルを返す。 | |
185 | - * 作成に失敗した場合は0を返す。 | |
186 | - * | |
187 | - * @param hParentWnd 親Windowのハンドル。親が存在しない場合は0を指定する。 | |
180 | + * 指定されたサイズのネイティブウインドウを作成し、 そのウインドウハンドルを返す。 作成に失敗した場合は0を返す。 | |
181 | + * | |
182 | + * @param hParentWnd 親Windowのハンドル。親が存在しない場合は0を指定する。 | |
188 | 183 | * @param x |
189 | 184 | * @param y |
190 | 185 | * @param width |
191 | 186 | * @param height |
192 | 187 | */ |
193 | - protected abstract int createNative(int hParentWnd, int x, int y, int width, int height); | |
194 | - | |
188 | + protected abstract int createNative(int hParentWnd, int x, int y, int width, | |
189 | + int height); | |
190 | + | |
195 | 191 | public int checkImage(Image img, int width, int height, ImageObserver ob) |
196 | 192 | { |
197 | 193 | return Toolkit.getDefaultToolkit().checkImage(img, width, height, ob); |
@@ -201,16 +197,16 @@ | ||
201 | 197 | { |
202 | 198 | return getToolkit().createImage(prod); |
203 | 199 | } |
204 | - | |
200 | + | |
205 | 201 | public Image createImage(int width, int height) |
206 | 202 | { |
207 | 203 | // オフスクリーンイメージのインスタンスを返す |
208 | -// return new WCEOffscreenImage(this, width, height); | |
204 | + // return new WCEOffscreenImage(this, width, height); | |
209 | 205 | // createImage(int x, int y) should return BufferedImage |
210 | 206 | // Bug #15171 |
211 | 207 | return new BufferedImage(width, height, BufferedImage.TYPE_USHORT_565_RGB); |
212 | 208 | } |
213 | - | |
209 | + | |
214 | 210 | /** |
215 | 211 | * disable this peer. |
216 | 212 | */ |
@@ -218,19 +214,16 @@ | ||
218 | 214 | { |
219 | 215 | setEnabled(false); |
220 | 216 | } |
221 | - | |
217 | + | |
222 | 218 | /** |
223 | - * ピアが破棄される前に呼び出される | |
224 | - * 派生クラスは、ネイティブコンポーネントの状態をできる限り引数 c に保存する | |
225 | - * | |
226 | - * super.preDispose(c); | |
227 | - * // ... 保存処理 ... | |
219 | + * ピアが破棄される前に呼び出される 派生クラスは、ネイティブコンポーネントの状態をできる限り引数 c に保存する | |
220 | + * super.preDispose(c); // ... 保存処理 ... | |
228 | 221 | */ |
229 | 222 | protected void preDispose(Component c) |
230 | 223 | { |
231 | 224 | // WCEComponetPeerの実装は何もしない |
232 | 225 | } |
233 | - | |
226 | + | |
234 | 227 | /** |
235 | 228 | * ピアを破棄する |
236 | 229 | */ |
@@ -240,16 +233,16 @@ | ||
240 | 233 | preDispose(c); |
241 | 234 | Font f = c.getFont(); |
242 | 235 | if (f != null) |
243 | - { | |
244 | - // ネイティブフォントリソースを開放する | |
245 | - WCEFontPeer peer = (WCEFontPeer) f.getPeer(); | |
246 | - peer.dispose(); | |
247 | - } | |
236 | + { | |
237 | + // ネイティブフォントリソースを開放する | |
238 | + WCEFontPeer peer = (WCEFontPeer) f.getPeer(); | |
239 | + peer.dispose(); | |
240 | + } | |
248 | 241 | disposeNative(getWindowHandle()); |
249 | 242 | } |
250 | - | |
243 | + | |
251 | 244 | private native void disposeNative(int windowHandle); |
252 | - | |
245 | + | |
253 | 246 | /** |
254 | 247 | * ピアを有効化する |
255 | 248 | */ |
@@ -257,12 +250,12 @@ | ||
257 | 250 | { |
258 | 251 | setEnabled(true); |
259 | 252 | } |
260 | - | |
253 | + | |
261 | 254 | public ColorModel getColorModel() |
262 | 255 | { |
263 | 256 | return ColorModel.getRGBdefault(); |
264 | 257 | } |
265 | - | |
258 | + | |
266 | 259 | public FontMetrics getFontMetrics(Font f) |
267 | 260 | { |
268 | 261 | return getToolkit().getFontMetrics(f); |
@@ -272,7 +265,7 @@ | ||
272 | 265 | { |
273 | 266 | return new WCEGraphics2D(this); |
274 | 267 | } |
275 | - | |
268 | + | |
276 | 269 | /** |
277 | 270 | * 画面上における左上隅の座標を返す |
278 | 271 | */ |
@@ -280,9 +273,9 @@ | ||
280 | 273 | { |
281 | 274 | return getNativeLocationOnScreen(getWindowHandle()); |
282 | 275 | } |
283 | - | |
276 | + | |
284 | 277 | private native Point getNativeLocationOnScreen(int windowHandle); |
285 | - | |
278 | + | |
286 | 279 | /** |
287 | 280 | * 最小サイズを返す。 |
288 | 281 | */ |
@@ -290,7 +283,7 @@ | ||
290 | 283 | { |
291 | 284 | return getPreferredSize(); |
292 | 285 | } |
293 | - | |
286 | + | |
294 | 287 | /** |
295 | 288 | * 推奨サイズを返す。 |
296 | 289 | */ |
@@ -298,7 +291,7 @@ | ||
298 | 291 | { |
299 | 292 | return getNativePreferredSize(getWindowHandle()); |
300 | 293 | } |
301 | - | |
294 | + | |
302 | 295 | /** |
303 | 296 | * ネイティブコンポーネントの推奨サイズを返す |
304 | 297 | */ |
@@ -315,7 +308,7 @@ | ||
315 | 308 | { |
316 | 309 | return Toolkit.getDefaultToolkit(); |
317 | 310 | } |
318 | - | |
311 | + | |
319 | 312 | /** |
320 | 313 | * イベントを処理する |
321 | 314 | */ |
@@ -324,215 +317,235 @@ | ||
324 | 317 | int id = e.getID(); |
325 | 318 | |
326 | 319 | switch (id) |
327 | - { | |
320 | + { | |
328 | 321 | case PaintEvent.PAINT: |
329 | 322 | case PaintEvent.UPDATE: |
330 | 323 | { |
331 | 324 | Component c = getComponent(); |
332 | 325 | if (! c.isVisible() || c.getIgnoreRepaint()) |
333 | - { | |
334 | - // 表示されていない場合 | |
335 | - // またはOSからの再描画メッセージを拒否している場合 | |
336 | - return; | |
337 | - } | |
326 | + { | |
327 | + // 表示されていない場合 | |
328 | + // またはOSからの再描画メッセージを拒否している場合 | |
329 | + return; | |
330 | + } | |
338 | 331 | try |
339 | - { | |
340 | - Graphics g = getGraphics(); | |
341 | - if (g == null) | |
342 | 332 | { |
343 | - break; | |
333 | + Graphics g = getGraphics(); | |
334 | + if (g == null) | |
335 | + { | |
336 | + break; | |
337 | + } | |
338 | + | |
339 | + // クリッピング領域を設定する | |
340 | + g.setClip(((PaintEvent) e).getUpdateRect()); | |
341 | + | |
342 | + if (id == PaintEvent.PAINT) | |
343 | + { | |
344 | + c.paint(g); | |
345 | + } | |
346 | + else | |
347 | + { | |
348 | + c.update(g); | |
349 | + } | |
350 | + g.dispose(); | |
344 | 351 | } |
352 | + catch (InternalError ie) | |
353 | + { | |
354 | + ie.printStackTrace(); | |
355 | + } | |
356 | + } | |
357 | + break; | |
358 | + } | |
359 | + } | |
345 | 360 | |
346 | - // クリッピング領域を設定する | |
347 | - g.setClip(((PaintEvent) e).getUpdateRect()); | |
361 | + public boolean isFocusTraversable() | |
362 | + { | |
363 | + return true; | |
364 | + } | |
348 | 365 | |
349 | - if (id == PaintEvent.PAINT) | |
366 | + public boolean isFocusable() | |
367 | + { | |
368 | + return false; | |
369 | + } | |
370 | + | |
371 | + public Dimension minimumSize() | |
372 | + { | |
373 | + return getMinimumSize(); | |
374 | + } | |
375 | + | |
376 | + public Dimension preferredSize() | |
377 | + { | |
378 | + return getPreferredSize(); | |
379 | + } | |
380 | + | |
381 | + public void paint(Graphics graphics) | |
382 | + { | |
383 | + // 何もしない | |
384 | + } | |
385 | + | |
386 | + public boolean prepareImage(Image img, int width, int height, ImageObserver ob) | |
387 | + { | |
388 | + return Toolkit.getDefaultToolkit().prepareImage(img, width, height, ob); | |
389 | + } | |
390 | + | |
391 | + public void print(Graphics graphics) | |
392 | + { | |
393 | + paint(graphics); | |
394 | + } | |
395 | + | |
396 | + public void repaint(long tm, int x, int y, int width, int height) | |
397 | + { | |
398 | + if (width == 0 && height == 0) | |
399 | + { | |
400 | + // サイズ0のコンポーネントに対しては何もしない | |
401 | + return; | |
402 | + } | |
403 | + // キューに PaintEvent.UPDATE を postする | |
404 | + // (結果、update(Graphics) が呼び出されることになる) | |
405 | + queue.postEvent(new PaintEvent(getComponent(), PaintEvent.UPDATE, | |
406 | + new Rectangle(x, y, width, height))); | |
407 | + } | |
408 | + | |
409 | + public void requestFocus() | |
410 | + { | |
411 | + assert false : "Call new requestFocus() method instead"; | |
412 | + // requestNativeFocus(getWindowHandle()); | |
413 | + // postFocusEvent(FocusEvent.FOCUS_GAINED, null); | |
414 | + } | |
415 | + | |
416 | + /** | |
417 | + * 指定されたウインドウハンドルに対してSetFocus()を呼び出す | |
418 | + */ | |
419 | + private native void requestNativeFocus(int windowHandle); | |
420 | + | |
421 | + public boolean requestFocus(Component request, boolean temporary, | |
422 | + boolean allowWindowFocus, long time) | |
423 | + { | |
424 | + boolean retval = false; | |
425 | + | |
426 | + if (hasNativeFocus(getWindowHandle())) | |
427 | + { | |
428 | + KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); | |
429 | + Component currentFocus = kfm.getFocusOwner(); | |
430 | + if (currentFocus == request) | |
350 | 431 | { |
351 | - c.paint(g); | |
432 | + // Nothing to do in this trivial case. | |
433 | + retval = true; | |
352 | 434 | } |
353 | - else | |
435 | + else | |
354 | 436 | { |
355 | - c.update(g); | |
437 | + // Requested component is a lightweight descendant of this one | |
438 | + // or the actual heavyweight. | |
439 | + // Since this (native) component is already focused, we simply | |
440 | + // change the actual focus and be done. | |
441 | + postFocusEvent(FocusEvent.FOCUS_GAINED, temporary, null); | |
442 | + retval = true; | |
356 | 443 | } |
357 | - g.dispose (); | |
358 | - } | |
359 | - catch (InternalError ie) | |
360 | - { | |
361 | - ie.printStackTrace(); | |
362 | - } | |
363 | 444 | } |
364 | - break; | |
365 | - } | |
445 | + else | |
446 | + { | |
447 | + // temporaryがfalseの場合にのみネイティブコンポーネントのフォーカスを | |
448 | + // 取得する | |
449 | + // そうしないと、以下の問題が起きる | |
450 | + // ・JMenuの大きさがJFrameよりも大きな場合、JFrameが前面に表示されてしまう | |
451 | + // これは、javax.swing.plaf.basic.BasicPopupMenuUIの以下の箇所が原因 | |
452 | + // if (invokerRootPane != null) | |
453 | + // { | |
454 | + // invokerRootPane.requestFocus(true); | |
455 | + // installKeyboardActionsImpl(); | |
456 | + // } | |
457 | + // 根本的な解決策が思いつかないので、とりあえずの対処 | |
458 | + if (! temporary) | |
459 | + { | |
460 | + requestNativeFocus(getWindowHandle()); | |
461 | + } | |
462 | + retval = true; | |
463 | + } | |
464 | + return retval; | |
366 | 465 | } |
367 | 466 | |
467 | + /** | |
468 | + * 指定されたComponentが存在するWindowを返す。 | |
469 | + */ | |
470 | + private Window getWindowFor(Component c) | |
471 | + { | |
472 | + Component comp = c; | |
473 | + while (! (comp instanceof Window)) | |
474 | + comp = comp.getParent(); | |
475 | + return (Window) comp; | |
476 | + } | |
368 | 477 | |
369 | - public boolean isFocusTraversable() { | |
370 | - return true; | |
371 | - } | |
372 | - | |
373 | - public boolean isFocusable() { | |
374 | - return false; | |
375 | - } | |
376 | - | |
377 | - public Dimension minimumSize() { | |
378 | - return getMinimumSize(); | |
379 | - } | |
380 | - | |
381 | - public Dimension preferredSize() { | |
382 | - return getPreferredSize(); | |
383 | - } | |
384 | - | |
385 | - public void paint(Graphics graphics) { | |
386 | - // 何もしない | |
387 | - } | |
388 | - | |
389 | - public boolean prepareImage(Image img, int width, int height, ImageObserver ob) { | |
390 | - return Toolkit.getDefaultToolkit().prepareImage(img, width, height, ob); | |
391 | - } | |
392 | - | |
393 | - public void print(Graphics graphics) { | |
394 | - paint(graphics); | |
395 | - } | |
396 | - | |
397 | - public void repaint(long tm, int x, int y, int width, int height) { | |
398 | - if (width == 0 && height == 0) { | |
399 | - // サイズ0のコンポーネントに対しては何もしない | |
400 | - return; | |
401 | - } | |
402 | - // キューに PaintEvent.UPDATE を postする | |
403 | - // (結果、update(Graphics) が呼び出されることになる) | |
404 | - queue.postEvent (new PaintEvent (getComponent(), | |
405 | - PaintEvent.UPDATE, | |
406 | - new Rectangle (x, y, width, height))); | |
407 | - } | |
478 | + public void reshape(int x, int y, int width, int height) | |
479 | + { | |
480 | + setBounds(x, y, width, height); | |
481 | + } | |
408 | 482 | |
409 | - public void requestFocus() { | |
410 | - assert false: "Call new requestFocus() method instead"; | |
411 | -// requestNativeFocus(getWindowHandle()); | |
412 | -// postFocusEvent(FocusEvent.FOCUS_GAINED, null); | |
413 | - } | |
414 | - | |
415 | - /** | |
416 | - * 指定されたウインドウハンドルに対してSetFocus()を呼び出す | |
417 | - */ | |
418 | - private native void requestNativeFocus(int windowHandle); | |
419 | - | |
420 | - | |
421 | - public boolean requestFocus (Component request, | |
422 | - boolean temporary, | |
423 | - boolean allowWindowFocus, | |
424 | - long time) { | |
425 | - boolean retval = false; | |
426 | - | |
427 | - if (hasNativeFocus(getWindowHandle())) { | |
428 | - KeyboardFocusManager kfm = | |
429 | - KeyboardFocusManager.getCurrentKeyboardFocusManager(); | |
430 | - Component currentFocus = kfm.getFocusOwner(); | |
431 | - if (currentFocus == request) { | |
432 | - // Nothing to do in this trivial case. | |
433 | - retval = true; | |
434 | - } else { | |
435 | - // Requested component is a lightweight descendant of this one | |
436 | - // or the actual heavyweight. | |
437 | - // Since this (native) component is already focused, we simply | |
438 | - // change the actual focus and be done. | |
439 | - postFocusEvent(FocusEvent.FOCUS_GAINED, temporary, null); | |
440 | - retval = true; | |
441 | - } | |
442 | - } else { | |
443 | - // temporaryがfalseの場合にのみネイティブコンポーネントのフォーカスを | |
444 | - // 取得する | |
445 | - // そうしないと、以下の問題が起きる | |
446 | - // ・JMenuの大きさがJFrameよりも大きな場合、JFrameが前面に表示されてしまう | |
447 | - // これは、javax.swing.plaf.basic.BasicPopupMenuUIの以下の箇所が原因 | |
448 | - // if (invokerRootPane != null) | |
449 | - // { | |
450 | - // invokerRootPane.requestFocus(true); | |
451 | - // installKeyboardActionsImpl(); | |
452 | - // } | |
453 | - // 根本的な解決策が思いつかないので、とりあえずの対処 | |
454 | - if (! temporary) { | |
455 | - requestNativeFocus(getWindowHandle()); | |
456 | - } | |
457 | - retval = true; | |
458 | - } | |
459 | - return retval; | |
460 | - } | |
461 | - | |
462 | - /** | |
463 | - * 指定されたComponentが存在するWindowを返す。 | |
464 | - */ | |
465 | - private Window getWindowFor(Component c) { | |
466 | - Component comp = c; | |
467 | - while (! (comp instanceof Window)) | |
468 | - comp = comp.getParent(); | |
469 | - return (Window) comp; | |
470 | - } | |
483 | + /** | |
484 | + * ピアの背景色を設定する | |
485 | + */ | |
486 | + public void setBackground(Color color) | |
487 | + { | |
488 | + if (color == null) | |
489 | + { | |
490 | + // since GNU Classpath 0.18 | |
491 | + color = SystemColor.window; | |
492 | + } | |
493 | + setNativeBackground(getWindowHandle(), color.getRGB()); | |
494 | + } | |
471 | 495 | |
472 | - public void reshape(int x, int y, int width, int height) { | |
473 | - setBounds(x, y, width, height); | |
474 | - } | |
475 | - | |
476 | - /** | |
477 | - * ピアの背景色を設定する | |
478 | - */ | |
479 | - public void setBackground(Color color) { | |
480 | - if (color == null) { | |
481 | - // since GNU Classpath 0.18 | |
482 | - color = SystemColor.window; | |
483 | - } | |
484 | - setNativeBackground(getWindowHandle(), | |
485 | - color.getRGB()); | |
486 | - } | |
487 | - | |
488 | - private native void setNativeBackground(int windowHandle, | |
489 | - int rgb); | |
496 | + private native void setNativeBackground(int windowHandle, int rgb); | |
490 | 497 | |
491 | - /** | |
492 | - * ネイティブコンポーネントのサイズを設定する | |
493 | - */ | |
494 | - protected native void setNativeBounds(int windowHandle, int x, int y, int width, int height); | |
495 | - | |
496 | - /** | |
497 | - * ネイティブコンポーネントの大きさを設定する | |
498 | - */ | |
499 | - public void setBounds(int x, int y, int width, int height) { | |
500 | - Container parent = getComponent().getParent(); | |
501 | - Insets i; | |
502 | - while (parent != null && parent.isLightweight ()) { | |
503 | - i = parent.getInsets (); | |
504 | - x += parent.getX () + i.left; | |
505 | - y += parent.getY () + i.top; | |
506 | - parent = parent.getParent (); | |
507 | - } | |
508 | - | |
509 | - if (parent != null && ! (getComponent() instanceof Dialog)) { | |
510 | - ContainerPeer peer = (ContainerPeer) parent.getPeer(); | |
511 | - if (peer == null) { | |
512 | - // デバッグ用 | |
513 | - throw new AWTError("parent.getPeer() is null. parent=" + parent); | |
514 | - } else { | |
515 | - // HeavyweightコンポーネントのInsets分 (x, y)から減算する | |
516 | - i = peer.getInsets(); | |
517 | - x -= i.left; | |
518 | - y -= i.top; | |
519 | - } | |
520 | - } | |
498 | + /** | |
499 | + * ネイティブコンポーネントのサイズを設定する | |
500 | + */ | |
501 | + protected native void setNativeBounds(int windowHandle, int x, int y, | |
502 | + int width, int height); | |
521 | 503 | |
522 | - setNativeBounds(getWindowHandle(), x, y, width, height); | |
523 | - } | |
524 | - | |
525 | - | |
504 | + /** | |
505 | + * ネイティブコンポーネントの大きさを設定する | |
506 | + */ | |
507 | + public void setBounds(int x, int y, int width, int height) | |
508 | + { | |
509 | + Container parent = getComponent().getParent(); | |
510 | + Insets i; | |
511 | + while (parent != null && parent.isLightweight()) | |
512 | + { | |
513 | + i = parent.getInsets(); | |
514 | + x += parent.getX() + i.left; | |
515 | + y += parent.getY() + i.top; | |
516 | + parent = parent.getParent(); | |
517 | + } | |
518 | + | |
519 | + if (parent != null && ! (getComponent() instanceof Window)) | |
520 | + { | |
521 | + ContainerPeer peer = (ContainerPeer) parent.getPeer(); | |
522 | + if (peer == null) | |
523 | + { | |
524 | + // デバッグ用 | |
525 | + throw new AWTError("parent.getPeer() is null. parent=" + parent); | |
526 | + } | |
527 | + else | |
528 | + { | |
529 | + // HeavyweightコンポーネントのInsets分 (x, y)から減算する | |
530 | + i = peer.getInsets(); | |
531 | + x -= i.left; | |
532 | + y -= i.top; | |
533 | + } | |
534 | + } | |
535 | + | |
536 | + setNativeBounds(getWindowHandle(), x, y, width, height); | |
537 | + } | |
538 | + | |
526 | 539 | public void setCursor(Cursor cursor) |
527 | 540 | { |
528 | 541 | setNativeCursor(getWindowHandle(), cursor.getType()); |
529 | 542 | } |
530 | - | |
543 | + | |
531 | 544 | /** |
532 | 545 | * ネイティブコンポーネントのカーソルを設定する |
533 | 546 | */ |
534 | 547 | private native void setNativeCursor(int windowHandle, int type); |
535 | - | |
548 | + | |
536 | 549 | /** |
537 | 550 | * ネイティブコンポーネントの有効/無効状態を変更する |
538 | 551 | */ |
@@ -540,9 +553,9 @@ | ||
540 | 553 | { |
541 | 554 | setNativeEnabled(getWindowHandle(), enabled); |
542 | 555 | } |
543 | - | |
556 | + | |
544 | 557 | private native void setNativeEnabled(int windowHandle, boolean enabled); |
545 | - | |
558 | + | |
546 | 559 | /** |
547 | 560 | * ピアのフォントを設定する。 |
548 | 561 | */ |
@@ -551,7 +564,7 @@ | ||
551 | 564 | WCEFontPeer peer = (WCEFontPeer) font.getPeer(); |
552 | 565 | setNativeFontHandle(getWindowHandle(), peer.getFontHandle()); |
553 | 566 | } |
554 | - | |
567 | + | |
555 | 568 | private native void setNativeFontHandle(int windowHandle, int fontHandle); |
556 | 569 | |
557 | 570 | /** |
@@ -561,12 +574,12 @@ | ||
561 | 574 | { |
562 | 575 | // Since GNU Classpath 0.19 |
563 | 576 | if (color == null) |
564 | - { | |
565 | - color = SystemColor.windowText; | |
566 | - } | |
577 | + { | |
578 | + color = SystemColor.windowText; | |
579 | + } | |
567 | 580 | setNativeForeground(getWindowHandle(), color.getRGB()); |
568 | 581 | } |
569 | - | |
582 | + | |
570 | 583 | private native void setNativeForeground(int windowHandle, int rgb); |
571 | 584 | |
572 | 585 | /** |
@@ -581,16 +594,16 @@ | ||
581 | 594 | // 最初に表示された際にComponentEventがpostされないとうまく動作しないアプリケーションが |
582 | 595 | // あるため、1回目の表示時にはComponentEventをpostする |
583 | 596 | if (visible && ! this.hasBeenShown) |
584 | - { | |
585 | - Component c = getComponent(); | |
586 | - queue.postEvent(new ComponentEvent(c, ComponentEvent.COMPONENT_MOVED)); | |
587 | - queue.postEvent(new ComponentEvent(c, ComponentEvent.COMPONENT_RESIZED)); | |
588 | - this.hasBeenShown = true; | |
589 | - } | |
597 | + { | |
598 | + Component c = getComponent(); | |
599 | + queue.postEvent(new ComponentEvent(c, ComponentEvent.COMPONENT_MOVED)); | |
600 | + queue.postEvent(new ComponentEvent(c, ComponentEvent.COMPONENT_RESIZED)); | |
601 | + this.hasBeenShown = true; | |
602 | + } | |
590 | 603 | } |
591 | - | |
604 | + | |
592 | 605 | private native void setNativeVisible(int windowHandle, boolean visible); |
593 | - | |
606 | + | |
594 | 607 | /** |
595 | 608 | * このピアを表示する |
596 | 609 | */ |
@@ -598,7 +611,7 @@ | ||
598 | 611 | { |
599 | 612 | setVisible(true); |
600 | 613 | } |
601 | - | |
614 | + | |
602 | 615 | /** |
603 | 616 | * このピアを非表示にする |
604 | 617 | */ |
@@ -607,21 +620,19 @@ | ||
607 | 620 | setVisible(false); |
608 | 621 | } |
609 | 622 | |
610 | - /** | |
611 | - * Get the graphics configuration of the component. The color model | |
612 | - * of the component can be derived from the configuration. | |
623 | + /** | |
624 | + * Get the graphics configuration of the component. The color model of the | |
625 | + * component can be derived from the configuration. | |
613 | 626 | */ |
614 | 627 | public GraphicsConfiguration getGraphicsConfiguration() |
615 | 628 | { |
616 | - return GraphicsEnvironment.getLocalGraphicsEnvironment() | |
617 | - .getDefaultScreenDevice() | |
618 | - .getDefaultConfiguration(); | |
629 | + return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration(); | |
619 | 630 | } |
620 | 631 | |
621 | 632 | /** |
622 | 633 | * Part of an older API, no longer needed. |
623 | 634 | */ |
624 | - public void setEventMask (long mask) | |
635 | + public void setEventMask(long mask) | |
625 | 636 | { |
626 | 637 | // 未実装 |
627 | 638 | } |
@@ -648,10 +659,11 @@ | ||
648 | 659 | // 何もしない |
649 | 660 | } |
650 | 661 | |
651 | - public VolatileImage createVolatileImage(int width, int height) { | |
662 | + public VolatileImage createVolatileImage(int width, int height) | |
663 | + { | |
652 | 664 | return new WCEVolatileImage(new WCEOffscreenImage(this, width, height)); |
653 | 665 | } |
654 | - | |
666 | + | |
655 | 667 | public boolean handlesWheelScrolling() |
656 | 668 | { |
657 | 669 | // 未実装 |
@@ -658,7 +670,8 @@ | ||
658 | 670 | return false; |
659 | 671 | } |
660 | 672 | |
661 | - public void createBuffers(int x, BufferCapabilities capabilities) throws AWTException | |
673 | + public void createBuffers(int x, BufferCapabilities capabilities) | |
674 | + throws AWTException | |
662 | 675 | { |
663 | 676 | // 未実装 |
664 | 677 | throw new UnsupportedOperationException("Not implemented"); |
@@ -681,91 +694,61 @@ | ||
681 | 694 | // 未実装 |
682 | 695 | throw new UnsupportedOperationException("Not implemented"); |
683 | 696 | } |
684 | - | |
697 | + | |
685 | 698 | protected native String getNativeText(int windowHandle); |
686 | - | |
687 | - protected native void setNativeText(int windowHandle, String text); | |
688 | 699 | |
700 | + protected native void setNativeText(int windowHandle, String text); | |
689 | 701 | |
690 | - | |
691 | 702 | /** |
692 | 703 | * ネイティブの親ウインドウを変更する |
693 | 704 | */ |
694 | - protected native void setNativeParent(int childWindowHandle, int newParentWindowHandle); | |
705 | + protected native void setNativeParent(int childWindowHandle, | |
706 | + int newParentWindowHandle); | |
695 | 707 | |
696 | 708 | /** |
697 | 709 | * MouseEventをEventQueueにpostする |
698 | 710 | */ |
699 | - void postMouseEvent(int id, | |
700 | - int modifiers, | |
701 | - int x, | |
702 | - int y, | |
703 | - int clickCount, | |
704 | - boolean popupTrigger, | |
705 | - int button) | |
711 | + void postMouseEvent(int id, int modifiers, int x, int y, int clickCount, | |
712 | + boolean popupTrigger, int button) | |
706 | 713 | { |
707 | - | |
708 | - queue.postEvent( | |
709 | - new MouseEvent(getComponent(), | |
710 | - id, | |
711 | - System.currentTimeMillis(), | |
712 | - modifiers, | |
713 | - x, | |
714 | - y, | |
715 | - clickCount, | |
716 | - popupTrigger, | |
717 | - button)); | |
714 | + | |
715 | + queue.postEvent(new MouseEvent(getComponent(), id, | |
716 | + System.currentTimeMillis(), modifiers, x, y, | |
717 | + clickCount, popupTrigger, button)); | |
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
721 | 721 | * MouseWheelEventをEventQueueにpostする |
722 | 722 | */ |
723 | - void postMouseWheelEvent(int id, | |
724 | - int modifiers, | |
725 | - int x, | |
726 | - int y, | |
727 | - int clickCount, | |
728 | - boolean popupTrigger, | |
729 | - int scrollType, | |
730 | - int scrollAmount, | |
731 | - int wheelRotation) | |
723 | + void postMouseWheelEvent(int id, int modifiers, int x, int y, int clickCount, | |
724 | + boolean popupTrigger, int scrollType, | |
725 | + int scrollAmount, int wheelRotation) | |
732 | 726 | { |
733 | - | |
734 | - queue.postEvent( | |
735 | - new MouseWheelEvent(getComponent(), | |
736 | - id, | |
737 | - System.currentTimeMillis(), | |
738 | - modifiers, | |
739 | - x, | |
740 | - y, | |
741 | - clickCount, | |
742 | - popupTrigger, | |
743 | - scrollType, | |
744 | - scrollAmount, | |
745 | - wheelRotation)); | |
727 | + | |
728 | + queue.postEvent(new MouseWheelEvent(getComponent(), id, | |
729 | + System.currentTimeMillis(), modifiers, | |
730 | + x, y, clickCount, popupTrigger, | |
731 | + scrollType, scrollAmount, wheelRotation)); | |
746 | 732 | } |
747 | 733 | |
748 | 734 | /** |
749 | 735 | * PaintEventをpostする |
750 | 736 | */ |
751 | - void postPaintEvent(int id, | |
752 | - int x, | |
753 | - int y, | |
754 | - int width, | |
755 | - int height) | |
737 | + void postPaintEvent(int id, int x, int y, int width, int height) | |
756 | 738 | { |
757 | - queue.postEvent( | |
758 | - new PaintEvent(getComponent(), | |
759 | - id, | |
760 | - new Rectangle(x, y, width, height))); | |
739 | + queue.postEvent(new PaintEvent(getComponent(), id, new Rectangle(x, y, | |
740 | + width, | |
741 | + height))); | |
761 | 742 | } |
762 | - | |
743 | + | |
763 | 744 | /** |
764 | 745 | * FocusEventをpostする |
765 | 746 | */ |
766 | - protected void postFocusEvent(int id, boolean temporary, WCEComponentPeer oppositePeer) | |
747 | + protected void postFocusEvent(int id, boolean temporary, | |
748 | + WCEComponentPeer oppositePeer) | |
767 | 749 | { |
768 | - Component opposite = (oppositePeer != null) ? oppositePeer.getComponent() : null; | |
750 | + Component opposite = (oppositePeer != null) ? oppositePeer.getComponent() | |
751 | + : null; | |
769 | 752 | queue.postEvent(new FocusEvent(getComponent(), id, temporary, opposite)); |
770 | 753 | } |
771 | 754 |
@@ -772,37 +755,31 @@ | ||
772 | 755 | /** |
773 | 756 | * KeyEventをpostする |
774 | 757 | */ |
775 | - void postKeyEvent(int id, | |
776 | - long when, | |
777 | - int modifiers, | |
778 | - int keyCode, | |
779 | - char keyChar, | |
780 | - int keyLocation) | |
758 | + void postKeyEvent(int id, long when, int modifiers, int keyCode, | |
759 | + char keyChar, int keyLocation) | |
781 | 760 | { |
782 | - queue.postEvent(new KeyEvent(getComponent(), | |
783 | - id, | |
784 | - System.currentTimeMillis(), | |
785 | - modifiers, | |
786 | - keyCode, | |
787 | - keyChar, | |
788 | - keyLocation)); | |
761 | + queue.postEvent(new KeyEvent(getComponent(), id, | |
762 | + System.currentTimeMillis(), modifiers, | |
763 | + keyCode, keyChar, keyLocation)); | |
789 | 764 | } |
790 | - | |
791 | 765 | |
792 | 766 | public Rectangle getBounds() |
793 | 767 | { |
794 | - // FIXME: implement | |
768 | + // FIXME: implement | |
795 | 769 | return null; |
796 | 770 | } |
771 | + | |
797 | 772 | public void reparent(ContainerPeer parent) |
798 | 773 | { |
799 | 774 | // FIXME: implement |
800 | 775 | } |
776 | + | |
801 | 777 | public void setBounds(int x, int y, int width, int height, int z) |
802 | 778 | { |
803 | 779 | // FIXME: implement |
804 | - setBounds (x, y, width, height); | |
780 | + setBounds(x, y, width, height); | |
805 | 781 | } |
782 | + | |
806 | 783 | public boolean isReparentSupported() |
807 | 784 | { |
808 | 785 | // FIXME: implement |
@@ -812,19 +789,17 @@ | ||
812 | 789 | public void layout() |
813 | 790 | { |
814 | 791 | // FIXME: implement |
815 | - } | |
792 | + } | |
816 | 793 | |
817 | 794 | protected native boolean hasNativeFocus(int windowHandle); |
818 | 795 | |
819 | 796 | public boolean requestFocus(Component lightweightChild, boolean temporary, |
820 | - boolean focusedWindowChangeAllowed, | |
821 | - long time, sun.awt.CausedFocusEvent.Cause cause) | |
797 | + boolean focusedWindowChangeAllowed, long time, | |
798 | + sun.awt.CausedFocusEvent.Cause cause) | |
822 | 799 | { |
823 | 800 | // TODO: Implement this properly and remove the other requestFocus() |
824 | 801 | // methods. |
825 | 802 | return true; |
826 | 803 | } |
827 | - | |
804 | + | |
828 | 805 | } |
829 | - | |
830 | - |