40 |
|
|
41 |
import java.awt.Component; |
import java.awt.Component; |
42 |
import java.awt.Dimension; |
import java.awt.Dimension; |
43 |
|
import java.awt.Insets; |
44 |
import java.awt.Window; |
import java.awt.Window; |
45 |
import java.awt.peer.WindowPeer; |
import java.awt.peer.WindowPeer; |
46 |
|
|
47 |
public class GtkWindowPeer extends GtkContainerPeer |
public class GtkWindowPeer extends GtkContainerPeer |
48 |
implements WindowPeer |
implements WindowPeer |
49 |
{ |
{ |
50 |
static protected final int GTK_WINDOW_TOPLEVEL = 0; |
static protected final int GDK_WINDOW_TYPE_HINT_NORMAL = 0; |
51 |
static protected final int GTK_WINDOW_POPUP = 1; |
static protected final int GDK_WINDOW_TYPE_HINT_DIALOG = 1; |
52 |
|
static protected final int GDK_WINDOW_TYPE_HINT_MENU = 2; |
53 |
|
static protected final int GDK_WINDOW_TYPE_HINT_TOOLBAR = 3; |
54 |
|
static protected final int GDK_WINDOW_TYPE_HINT_SPLASHSCREEN = 4; |
55 |
|
static protected final int GDK_WINDOW_TYPE_HINT_UTILITY = 5; |
56 |
|
static protected final int GDK_WINDOW_TYPE_HINT_DOCK = 6; |
57 |
|
static protected final int GDK_WINDOW_TYPE_HINT_DESKTOP = 7; |
58 |
|
|
59 |
|
native void create (int type, boolean decorated, |
60 |
|
int width, int height, |
61 |
|
GtkWindowPeer parent); |
62 |
|
|
63 |
|
void create (int type, boolean decorated) |
64 |
|
{ |
65 |
|
GtkWindowPeer parent_peer = null; |
66 |
|
Component parent = awtComponent.getParent(); |
67 |
|
if (parent != null) |
68 |
|
parent_peer = (GtkWindowPeer) awtComponent.getParent().getPeer(); |
69 |
|
|
70 |
native void create (int type, int width, int height); |
create (type, decorated, |
|
|
|
|
void create (int type) |
|
|
{ |
|
|
create (type, |
|
71 |
awtComponent.getWidth(), |
awtComponent.getWidth(), |
72 |
awtComponent.getHeight()); |
awtComponent.getHeight(), |
73 |
|
parent_peer); |
74 |
} |
} |
75 |
|
|
76 |
void create () |
void create () |
77 |
{ |
{ |
78 |
create (GTK_WINDOW_POPUP, |
// Create a normal undecorated window. |
79 |
awtComponent.getWidth(), |
create (GDK_WINDOW_TYPE_HINT_NORMAL, false); |
|
awtComponent.getHeight()); |
|
80 |
} |
} |
81 |
|
|
82 |
native void connectHooks (); |
native void connectHooks (); |
95 |
native public void toBack (); |
native public void toBack (); |
96 |
native public void toFront (); |
native public void toFront (); |
97 |
|
|
98 |
native public void setBounds (int x, int y, int width, int height); |
native void nativeSetBounds (int x, int y, int width, int height); |
99 |
|
|
100 |
|
public void setBounds (int x, int y, int width, int height) |
101 |
|
{ |
102 |
|
nativeSetBounds (x, y, |
103 |
|
width - insets.left - insets.right, |
104 |
|
height - insets.top - insets.bottom); |
105 |
|
} |
106 |
|
|
107 |
public void setTitle (String title) |
public void setTitle (String title) |
108 |
{ |
{ |
111 |
|
|
112 |
public void setResizable (boolean resizable) |
public void setResizable (boolean resizable) |
113 |
{ |
{ |
114 |
|
// Call setSize; otherwise when resizable is changed from true to |
115 |
|
// false the window will shrink to the dimensions it had before it |
116 |
|
// was resizable. |
117 |
|
setSize (awtComponent.getWidth() - insets.left - insets.right, |
118 |
|
awtComponent.getHeight() - insets.top - insets.bottom); |
119 |
set ("allow_shrink", resizable); |
set ("allow_shrink", resizable); |
120 |
set ("allow_grow", resizable); |
set ("allow_grow", resizable); |
121 |
} |
} |
122 |
|
|
123 |
|
native void setSize (int width, int height); |
124 |
|
native void setBoundsCallback (Window window, |
125 |
|
int x, int y, |
126 |
|
int width, int height); |
127 |
|
|
128 |
protected void postConfigureEvent (int x, int y, int width, int height, |
protected void postConfigureEvent (int x, int y, int width, int height, |
129 |
int top, int left, int bottom, int right) |
int top, int left, int bottom, int right) |
130 |
{ |
{ |
131 |
/* |
// Configure events tell us the location and dimensions of the |
132 |
If our borders change (which often happens when we opaque resize), |
// window within the frame borders, and the dimensions of the |
133 |
we need to make sure that a new layout will happen, since Sun |
// frame borders (top, left, bottom, right). |
134 |
forgets to handle this case. |
|
135 |
*/ |
// If our borders change we need to make sure that a new layout |
136 |
|
// will happen, since Sun forgets to handle this case. |
137 |
if (insets.top != top |
if (insets.top != top |
138 |
|| insets.left != left |
|| insets.left != left |
139 |
|| insets.bottom != bottom |
|| insets.bottom != bottom |
140 |
|| insets.right != right) |
|| insets.right != right) |
141 |
{ |
{ |
142 |
awtComponent.invalidate (); |
// When our insets change, we receive a configure event with |
143 |
|
// the new insets, the old window location and the old window |
144 |
|
// dimensions. We update our Window object's location and |
145 |
|
// size using our old inset values. |
146 |
|
setBoundsCallback ((Window) awtComponent, |
147 |
|
x - insets.left, |
148 |
|
y - insets.top, |
149 |
|
width + insets.left + insets.right, |
150 |
|
height + insets.top + insets.bottom); |
151 |
|
|
152 |
|
// The peer's dimensions do not get updated automatically when |
153 |
|
// insets change so we need to do it manually. |
154 |
|
setSize (width + (insets.left - left) + (insets.right - right), |
155 |
|
height + (insets.top - top) + (insets.bottom - bottom)); |
156 |
|
|
157 |
|
insets.top = top; |
158 |
|
insets.left = left; |
159 |
|
insets.bottom = bottom; |
160 |
|
insets.right = right; |
161 |
|
|
162 |
|
awtComponent.validate(); |
163 |
} |
} |
164 |
|
else |
165 |
insets.top = top; |
{ |
166 |
insets.left = left; |
int frame_x = x - insets.left; |
167 |
insets.bottom = bottom; |
int frame_y = y - insets.top; |
168 |
insets.right = right; |
int frame_width = width + insets.left + insets.right; |
169 |
|
int frame_height = height + insets.top + insets.bottom; |
170 |
|
|
171 |
|
if (frame_x != awtComponent.getX() |
172 |
|
|| frame_y != awtComponent.getY() |
173 |
|
|| frame_width != awtComponent.getWidth() |
174 |
|
|| frame_height != awtComponent.getHeight()) |
175 |
|
{ |
176 |
|
setBoundsCallback ((Window) awtComponent, |
177 |
|
frame_x, |
178 |
|
frame_y, |
179 |
|
frame_width, |
180 |
|
frame_height); |
181 |
|
|
182 |
|
if (frame_width != awtComponent.getWidth() |
183 |
|
|| frame_height != awtComponent.getHeight()) |
184 |
|
setSize (width, height); |
185 |
|
|
186 |
awtComponent.setBounds (x, y, width, height); |
awtComponent.validate(); |
187 |
awtComponent.validate (); |
} |
188 |
|
} |
189 |
} |
} |
190 |
|
|
191 |
native public void setVisible (boolean b); |
native public void setVisible (boolean b); |
192 |
} |
} |