source: trunk/gcc/libjava/gnu/awt/xlib/XFramePeer.java

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 4.4 KB
Line 
1/* Copyright (C) 2000, 2002 Free Software Foundation
2
3 This file is part of libgcj.
4
5This software is copyrighted work licensed under the terms of the
6Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7details. */
8
9package gnu.awt.xlib;
10
11import java.awt.*;
12import java.awt.peer.*;
13import java.awt.image.*;
14import gnu.gcj.xlib.WMSizeHints;
15import gnu.gcj.xlib.WindowAttributes;
16import gnu.gcj.xlib.Display;
17import gnu.gcj.xlib.Visual;
18import gnu.gcj.xlib.Screen;
19import gnu.gcj.xlib.XConfigureEvent;
20
21/** FIXME: a lot of the code here should be moved down to XWindowPeer. */
22
23public class XFramePeer extends XCanvasPeer implements FramePeer
24{
25
26 public XFramePeer(Frame frame)
27 {
28 super(frame);
29
30 // Set some defaults for a toplevel component:
31 if (frame.getFont() == null)
32 frame.setFont(new Font("helvetica", Font.PLAIN, 12));
33
34 if (frame.getBackground() == null)
35 frame.setBackground(Color.lightGray);
36
37 if (frame.getForeground() == null)
38 frame.setForeground(Color.black);
39 }
40
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)
44 {
45 Screen screen = config.getVisual().getScreen();
46 return screen.getRootWindow();
47 }
48
49 void initWindowProperties()
50 {
51 Frame frame = (Frame) component;
52 setResizable(frame.isResizable());
53 String title = frame.getTitle();
54 if (!title.equals("")) setTitle(title);
55 }
56
57 long getBasicEventMask()
58 {
59 return super.getBasicEventMask() |
60 WindowAttributes.MASK_STRUCTURE_NOTIFY;
61 }
62
63 void configureNotify(XConfigureEvent configEvent)
64 {
65 component.setBounds(configEvent.getBounds());
66
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. */
71 component.validate();
72 }
73
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
78 bounds. */
79 public void setBounds(int x, int y, int width, int height)
80 {
81 if (Thread.currentThread() == getXToolkit().eventLoop.eventLoopThread)
82 return;
83
84 super.setBounds(x, y, width, height);
85 }
86
87 // Implementing ContainerPeer:
88
89 static final Insets INSETS_0_PROTOTYPE = new Insets(0, 0, 0, 0);
90
91 public Insets getInsets()
92 {
93 return (Insets) INSETS_0_PROTOTYPE.clone();
94 }
95
96 public Insets insets ()
97 {
98 return getInsets ();
99 }
100
101 public void beginValidate()
102 {
103 }
104
105 public void endValidate()
106 {
107 // reassert sizing hints
108 Frame frame = (Frame) component;
109 setResizable(frame.isResizable());
110 }
111
112
113 // Implementing WindowPeer:
114
115 public void toBack()
116 {
117 throw new UnsupportedOperationException("not implemented yet");
118 }
119
120 public void toFront()
121 {
122 throw new UnsupportedOperationException("not implemented yet");
123 }
124
125
126 // Implementing FramePeer:
127
128 public void setIconImage(Image image)
129 {
130 throw new UnsupportedOperationException("not implemented yet");
131 }
132
133 public void setMenuBar(MenuBar mb)
134 {
135 throw new UnsupportedOperationException("not implemented yet");
136 }
137
138
139 public void setTitle(String title)
140 {
141 synchronized (window.getDisplay())
142 {
143 // Oh, what a nice implementation :-)
144 window.setProperty("WM_NAME", "STRING", title);
145
146 ensureFlush();
147 }
148 }
149
150 public void setResizable(boolean resizable)
151 {
152 Frame frame = (Frame) component;
153
154 WMSizeHints sizeHints = new WMSizeHints();
155 if (resizable)
156 {
157 Dimension minSize = frame.getMinimumSize();
158 sizeHints.setMinSize(minSize.width, minSize.height);
159
160 Dimension maxSize = frame.getMaximumSize();
161
162 if ((maxSize.width < Short.MAX_VALUE) ||
163 (maxSize.height < Short.MAX_VALUE))
164 {
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);
168 }
169 }
170 else
171 {
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);
176 }
177 sizeHints.applyNormalHints(window);
178 }
179}
Note: See TracBrowser for help on using the repository browser.