1 /* Copyright (C) 2000, 2002, 2003 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 import java
.awt
.peer
.*;
13 import java
.awt
.image
.*;
14 import gnu
.gcj
.xlib
.WMSizeHints
;
15 import gnu
.gcj
.xlib
.WindowAttributes
;
16 import gnu
.gcj
.xlib
.Display
;
17 import gnu
.gcj
.xlib
.Visual
;
18 import gnu
.gcj
.xlib
.Screen
;
19 import gnu
.gcj
.xlib
.XConfigureEvent
;
21 /** FIXME: a lot of the code here should be moved down to XWindowPeer. */
23 public class XFramePeer
extends XCanvasPeer
implements FramePeer
26 public XFramePeer(Frame frame
)
30 // Set some defaults for a toplevel component:
31 if (frame
.getFont() == null)
32 frame
.setFont(new Font("helvetica", Font
.PLAIN
, 12));
34 if (frame
.getBackground() == null)
35 frame
.setBackground(Color
.lightGray
);
37 if (frame
.getForeground() == null)
38 frame
.setForeground(Color
.black
);
41 /** Find parent window for toplevel window, ie. root window of
42 selected screen. Bounds are not changed. */
43 gnu
.gcj
.xlib
.Window
locateParentWindow(Rectangle bounds
)
45 Screen screen
= config
.getVisual().getScreen();
46 return screen
.getRootWindow();
49 void initWindowProperties()
51 Frame frame
= (Frame
) component
;
52 setResizable(frame
.isResizable());
53 String title
= frame
.getTitle();
54 if (!title
.equals("")) setTitle(title
);
57 long getBasicEventMask()
59 return super.getBasicEventMask() |
60 WindowAttributes
.MASK_STRUCTURE_NOTIFY
;
63 void configureNotify(XConfigureEvent configEvent
)
65 component
.setBounds(configEvent
.getBounds());
67 /* FIXME: Validation should probably not be done here. The best
68 strategy is probably to validate on the AWT thread in response
69 to an ComponentEvent. This will make it possible to coalesce
70 resize validations. */
74 /* Overridden to ignore request to set bounds if the request occurs
75 on the X event loop thread. It is assumed that all requests that
76 occur on the X event loop thread are results of XConfigureNotify
77 events, in which case the X window already has the desired
79 public void setBounds(int x
, int y
, int width
, int height
)
81 if (EventQueue
.isDispatchThread())
84 super.setBounds(x
, y
, width
, height
);
87 // Implementing ContainerPeer:
89 static final Insets INSETS_0_PROTOTYPE
= new Insets(0, 0, 0, 0);
91 public Insets
getInsets()
93 return (Insets
) INSETS_0_PROTOTYPE
.clone();
96 public Insets
insets ()
101 public void beginValidate()
105 public void endValidate()
107 // reassert sizing hints
108 Frame frame
= (Frame
) component
;
109 setResizable(frame
.isResizable());
113 // Implementing WindowPeer:
117 throw new UnsupportedOperationException("not implemented yet");
120 public void toFront()
122 throw new UnsupportedOperationException("not implemented yet");
126 // Implementing FramePeer:
128 public void setIconImage(Image image
)
130 throw new UnsupportedOperationException("not implemented yet");
133 public void setMenuBar(MenuBar mb
)
135 throw new UnsupportedOperationException("not implemented yet");
139 public void setTitle(String title
)
141 synchronized (window
.getDisplay())
143 // Oh, what a nice implementation :-)
144 window
.setProperty("WM_NAME", "STRING", title
);
150 public void setResizable(boolean resizable
)
152 Frame frame
= (Frame
) component
;
154 WMSizeHints sizeHints
= new WMSizeHints();
157 Dimension minSize
= frame
.getMinimumSize();
158 sizeHints
.setMinSize(minSize
.width
, minSize
.height
);
160 Dimension maxSize
= frame
.getMaximumSize();
162 if ((maxSize
.width
< Short
.MAX_VALUE
) ||
163 (maxSize
.height
< Short
.MAX_VALUE
))
165 maxSize
.width
= Math
.min(maxSize
.width
, Short
.MAX_VALUE
);
166 maxSize
.height
= Math
.min(maxSize
.height
, Short
.MAX_VALUE
);
167 sizeHints
.setMaxSize(maxSize
.width
, maxSize
.height
);
172 // lock resizing to current bounds
173 Dimension size
= frame
.getSize();
174 sizeHints
.setMinSize(size
.width
, size
.height
);
175 sizeHints
.setMaxSize(size
.width
, size
.height
);
177 sizeHints
.applyNormalHints(window
);
180 public int getState ()
185 public void setState (int state
)
189 public void setMaximizedBounds (Rectangle r
)
193 public void beginLayout () { }
194 public void endLayout () { }
195 public boolean isPaintPending () { return false; }