XFramePeer.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /* Copyright (C) 2000, 2002, 2003 Free Software Foundation
  2. This file is part of libgcj.
  3. This software is copyrighted work licensed under the terms of the
  4. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  5. details. */
  6. package gnu.awt.xlib;
  7. import java.awt.*;
  8. import java.awt.peer.*;
  9. import java.awt.image.*;
  10. import gnu.gcj.xlib.WMSizeHints;
  11. import gnu.gcj.xlib.WindowAttributes;
  12. import gnu.gcj.xlib.Display;
  13. import gnu.gcj.xlib.Visual;
  14. import gnu.gcj.xlib.Screen;
  15. import gnu.gcj.xlib.XConfigureEvent;
  16. /** FIXME: a lot of the code here should be moved down to XWindowPeer. */
  17. public class XFramePeer extends XCanvasPeer implements FramePeer
  18. {
  19. private boolean processingConfigureNotify = false;
  20. public XFramePeer(Frame frame)
  21. {
  22. super(frame);
  23. // Set some defaults for a toplevel component:
  24. if (frame.getFont() == null)
  25. frame.setFont(new Font("helvetica", Font.PLAIN, 12));
  26. if (frame.getBackground() == null)
  27. frame.setBackground(Color.lightGray);
  28. if (frame.getForeground() == null)
  29. frame.setForeground(Color.black);
  30. }
  31. /** Find parent window for toplevel window, ie. root window of
  32. selected screen. Bounds are not changed. */
  33. gnu.gcj.xlib.Window locateParentWindow(Rectangle bounds)
  34. {
  35. Screen screen = config.getVisual().getScreen();
  36. return screen.getRootWindow();
  37. }
  38. void initWindowProperties()
  39. {
  40. Frame frame = (Frame) component;
  41. setResizable(frame.isResizable());
  42. String title = frame.getTitle();
  43. if (!title.equals("")) setTitle(title);
  44. }
  45. long getBasicEventMask()
  46. {
  47. return super.getBasicEventMask() |
  48. WindowAttributes.MASK_STRUCTURE_NOTIFY;
  49. }
  50. void configureNotify(XConfigureEvent configEvent)
  51. {
  52. processingConfigureNotify = true; // to avoid setBounds flood
  53. component.setBounds(configEvent.getBounds());
  54. processingConfigureNotify = false;
  55. }
  56. /* Overridden to ignore request to set bounds if the request occurs
  57. while processing an XConfigureNotify event, in which case the X
  58. window already has the desired bounds.
  59. That's what java.awt.Window.setBoundsCallback is for, but it's
  60. package-private, and using our own flag eliminates the need to
  61. circumvent java security.
  62. */
  63. public void setBounds(int x, int y, int width, int height)
  64. {
  65. if (!processingConfigureNotify)
  66. super.setBounds(x, y, width, height);
  67. }
  68. // Implementing ContainerPeer:
  69. static final Insets INSETS_0_PROTOTYPE = new Insets(0, 0, 0, 0);
  70. public Insets getInsets()
  71. {
  72. return (Insets) INSETS_0_PROTOTYPE.clone();
  73. }
  74. public Insets insets ()
  75. {
  76. return getInsets ();
  77. }
  78. public void beginValidate()
  79. {
  80. }
  81. public void endValidate()
  82. {
  83. // reassert sizing hints
  84. Frame frame = (Frame) component;
  85. setResizable(frame.isResizable());
  86. }
  87. // Implementing WindowPeer:
  88. public void toBack()
  89. {
  90. window.toBack ();
  91. }
  92. public void toFront()
  93. {
  94. window.toFront ();
  95. }
  96. // Implementing FramePeer:
  97. public void setIconImage(Image image)
  98. {
  99. throw new UnsupportedOperationException("not implemented yet");
  100. }
  101. public void setMenuBar(MenuBar mb)
  102. {
  103. throw new UnsupportedOperationException("not implemented yet");
  104. }
  105. public void setTitle(String title)
  106. {
  107. synchronized (window.getDisplay())
  108. {
  109. // Oh, what a nice implementation :-)
  110. window.setProperty("WM_NAME", "STRING", title);
  111. ensureFlush();
  112. }
  113. }
  114. public void setResizable(boolean resizable)
  115. {
  116. Frame frame = (Frame) component;
  117. WMSizeHints sizeHints = new WMSizeHints();
  118. if (resizable)
  119. {
  120. Dimension minSize = frame.getMinimumSize();
  121. sizeHints.setMinSize(minSize.width, minSize.height);
  122. Dimension maxSize = frame.getMaximumSize();
  123. if ((maxSize.width < Short.MAX_VALUE) ||
  124. (maxSize.height < Short.MAX_VALUE))
  125. {
  126. maxSize.width = Math.min(maxSize.width, Short.MAX_VALUE);
  127. maxSize.height = Math.min(maxSize.height, Short.MAX_VALUE);
  128. sizeHints.setMaxSize(maxSize.width, maxSize.height);
  129. }
  130. }
  131. else
  132. {
  133. // lock resizing to current bounds
  134. Dimension size = frame.getSize();
  135. sizeHints.setMinSize(size.width, size.height);
  136. sizeHints.setMaxSize(size.width, size.height);
  137. }
  138. sizeHints.applyNormalHints(window);
  139. }
  140. public int getState ()
  141. {
  142. return 0;
  143. }
  144. public void setState (int state)
  145. {
  146. }
  147. public void setMaximizedBounds (Rectangle r)
  148. {
  149. }
  150. public void beginLayout () { }
  151. public void endLayout () { }
  152. public boolean isPaintPending () { return false; }
  153. /**
  154. * @since 1.5
  155. */
  156. public void setBoundsPrivate (int x, int y, int width, int height)
  157. {
  158. // TODO: Implement this.
  159. throw new UnsupportedOperationException("Not yet implemented.");
  160. }
  161. public Rectangle getBoundsPrivate()
  162. {
  163. // TODO: Implement this.
  164. throw new UnsupportedOperationException("Not yet implemented.");
  165. }
  166. /**
  167. * @since 1.5
  168. */
  169. public void updateAlwaysOnTop()
  170. {
  171. }
  172. /**
  173. * @since 1.5
  174. */
  175. public boolean requestWindowFocus ()
  176. {
  177. return false;
  178. }
  179. public void setAlwaysOnTop(boolean alwaysOnTop)
  180. {
  181. throw new UnsupportedOperationException("not implemented yet");
  182. }
  183. public void updateFocusableWindowState()
  184. {
  185. throw new UnsupportedOperationException("not implemented yet");
  186. }
  187. public void setModalBlocked(Dialog blocker, boolean blocked)
  188. {
  189. throw new UnsupportedOperationException("not implemented yet");
  190. }
  191. public void updateMinimumSize()
  192. {
  193. throw new UnsupportedOperationException("not implemented yet");
  194. }
  195. public void updateIconImages()
  196. {
  197. throw new UnsupportedOperationException("not implemented yet");
  198. }
  199. }