1 /* |
|
2 * Copyright 1995-2003 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Sun designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Sun in the LICENSE file that accompanied this code. |
|
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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 * have any questions. |
|
24 */ |
|
25 package sun.awt.motif; |
|
26 |
|
27 import java.awt.*; |
|
28 import java.awt.peer.*; |
|
29 |
|
30 import sun.awt.SunGraphicsCallback; |
|
31 |
|
32 class MPanelPeer extends MCanvasPeer implements PanelPeer { |
|
33 |
|
34 MPanelPeer() {} |
|
35 |
|
36 MPanelPeer(Component target) { |
|
37 super(target); |
|
38 } |
|
39 |
|
40 MPanelPeer(Component target, Object arg) { |
|
41 super(target, arg); |
|
42 } |
|
43 |
|
44 public Insets getInsets() { |
|
45 return new Insets(0, 0, 0, 0); |
|
46 } |
|
47 |
|
48 public void paint(Graphics g) { |
|
49 super.paint(g); |
|
50 SunGraphicsCallback.PaintHeavyweightComponentsCallback.getInstance(). |
|
51 runComponents(((Container)target).getComponents(), g, |
|
52 SunGraphicsCallback.LIGHTWEIGHTS | |
|
53 SunGraphicsCallback.HEAVYWEIGHTS); |
|
54 } |
|
55 public void print(Graphics g) { |
|
56 super.print(g); |
|
57 SunGraphicsCallback.PrintHeavyweightComponentsCallback.getInstance(). |
|
58 runComponents(((Container)target).getComponents(), g, |
|
59 SunGraphicsCallback.LIGHTWEIGHTS | |
|
60 SunGraphicsCallback.HEAVYWEIGHTS); |
|
61 } |
|
62 |
|
63 public void setBackground(Color c) { |
|
64 Component comp; |
|
65 int i; |
|
66 |
|
67 Container cont = (Container) target; |
|
68 synchronized(target.getTreeLock()) { |
|
69 int n = cont.getComponentCount(); |
|
70 for(i=0; i < n; i++) { |
|
71 comp = cont.getComponent(i); |
|
72 MComponentPeer peer = (MComponentPeer) MToolkit.targetToPeer(comp); |
|
73 if (peer != null) { |
|
74 Color color = comp.getBackground(); |
|
75 if (color == null || color.equals(c)) { |
|
76 peer.setBackground(c); |
|
77 peer.pSetBackground(c); |
|
78 } |
|
79 if ((comp instanceof java.awt.List) || |
|
80 (comp instanceof java.awt.TextArea) || |
|
81 (comp instanceof java.awt.ScrollPane)) { |
|
82 peer.pSetScrollbarBackground(c); |
|
83 } |
|
84 } |
|
85 } |
|
86 } |
|
87 pSetBackground(c); |
|
88 } |
|
89 |
|
90 public void setForeground(Color c) { |
|
91 Component comp; |
|
92 int i; |
|
93 |
|
94 Container cont = (Container) target; |
|
95 synchronized(target.getTreeLock()) { |
|
96 int n = cont.getComponentCount(); |
|
97 for(i=0; i < n; i++) { |
|
98 comp = cont.getComponent(i); |
|
99 MComponentPeer peer = (MComponentPeer) MToolkit.targetToPeer(comp); |
|
100 if (peer != null) { |
|
101 Color color = comp.getForeground(); |
|
102 if (color == null || color.equals(c)) { |
|
103 peer.setForeground(c); |
|
104 peer.pSetForeground(c); |
|
105 } |
|
106 if ((comp instanceof java.awt.List) || |
|
107 (comp instanceof java.awt.TextArea) || |
|
108 (comp instanceof java.awt.ScrollPane)) { |
|
109 peer.pSetInnerForeground(c); |
|
110 } |
|
111 } |
|
112 } |
|
113 } |
|
114 pSetForeground(c); |
|
115 } |
|
116 |
|
117 /** |
|
118 * DEPRECATED: Replaced by getInsets(). |
|
119 */ |
|
120 public Insets insets() { |
|
121 return getInsets(); |
|
122 } |
|
123 |
|
124 /** |
|
125 * Recursive method that handles the propagation of the displayChanged |
|
126 * event into the entire hierarchy of peers. |
|
127 * Unlike on win32, on X we don't worry about handling on-the-fly |
|
128 * display settings changes, only windows being dragged across Xinerama |
|
129 * screens. Thus, we only need to tell MCanvasPeers, not all |
|
130 * MComponentPeers. |
|
131 */ |
|
132 private void recursiveDisplayChanged(Component c, int screenNum) { |
|
133 if (c instanceof Container) { |
|
134 Component children[] = ((Container)c).getComponents(); |
|
135 for (int i = 0; i < children.length; ++i) { |
|
136 recursiveDisplayChanged(children[i], screenNum); |
|
137 } |
|
138 } |
|
139 ComponentPeer peer = c.getPeer(); |
|
140 if (peer != null && peer instanceof MCanvasPeer) { |
|
141 MCanvasPeer mPeer = (MCanvasPeer)peer; |
|
142 mPeer.displayChanged(screenNum); |
|
143 } |
|
144 } |
|
145 |
|
146 /* |
|
147 * Often up-called from a MWindowPeer instance. |
|
148 * Calls displayChanged() on all child canvas' peers. |
|
149 * Recurses into Container children to ensure all canvases |
|
150 * get the message. |
|
151 */ |
|
152 public void displayChanged(int screenNum) { |
|
153 // Don't do super call because MWindowPeer has already updated its GC |
|
154 |
|
155 Component children[] = ((Container)target).getComponents(); |
|
156 |
|
157 for (int i = 0; i < children.length; i++) { |
|
158 recursiveDisplayChanged(children[i], screenNum); |
|
159 } |
|
160 } |
|
161 |
|
162 protected boolean shouldFocusOnClick() { |
|
163 // Return false if this container has children so in that case it won't |
|
164 // be focused. Return true otherwise. |
|
165 return ((Container)target).getComponentCount() == 0; |
|
166 } |
|
167 |
|
168 private native void pEnsureIndex(ComponentPeer child, int index); |
|
169 private native void pRestack(); |
|
170 |
|
171 private int restack(Container cont, int ind) { |
|
172 for (int i = 0; i < cont.getComponentCount(); i++) { |
|
173 Component comp = cont.getComponent(i); |
|
174 if (!comp.isLightweight()) { |
|
175 if (comp.getPeer() != null) { |
|
176 pEnsureIndex(comp.getPeer(), ind++); |
|
177 } |
|
178 } |
|
179 if (comp.isLightweight() && comp instanceof Container) { |
|
180 ind = restack((Container)comp, ind); |
|
181 } |
|
182 } |
|
183 return ind; |
|
184 } |
|
185 |
|
186 /** |
|
187 * @see java.awt.peer.ContainerPeer#restack |
|
188 */ |
|
189 public void restack() { |
|
190 Container cont = (Container)target; |
|
191 restack(cont, 0); |
|
192 pRestack(); |
|
193 } |
|
194 |
|
195 /** |
|
196 * @see java.awt.peer.ContainerPeer#isRestackSupported |
|
197 */ |
|
198 public boolean isRestackSupported() { |
|
199 return true; |
|
200 } |
|
201 } |
|