1 /* GtkWindowPeer.java -- Implements WindowPeer with GTK 2 Copyright (C) 1998, 1999, 2002 Free Software Foundation, Inc. 3 4 This file is part of GNU Classpath. 5 6 GNU Classpath is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2, or (at your option) 9 any later version. 10 11 GNU Classpath is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GNU Classpath; see the file COPYING. If not, write to the 18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 02111-1307 USA. 20 21 Linking this library statically or dynamically with other modules is 22 making a combined work based on this library. Thus, the terms and 23 conditions of the GNU General Public License cover the whole 24 combination. 25 26 As a special exception, the copyright holders of this library give you 27 permission to link this library with independent modules to produce an 28 executable, regardless of the license terms of these independent 29 modules, and to copy and distribute the resulting executable under 30 terms of your choice, provided that you also meet, for each linked 31 independent module, the terms and conditions of the license of that 32 module. An independent module is a module which is not derived from 33 or based on this library. If you modify this library, you may extend 34 this exception to your version of the library, but you are not 35 obligated to do so. If you do not wish to do so, delete this 36 exception statement from your version. */ 37 38 39 package gnu.java.awt.peer.gtk; 40 41 import java.awt.Component; 42 import java.awt.Dimension; 43 import java.awt.Window; 44 import java.awt.Frame; 45 import java.awt.event.WindowEvent; 46 import java.awt.peer.WindowPeer; 47 48 public class GtkWindowPeer extends GtkContainerPeer 49 implements WindowPeer 50 { 51 static protected final int GDK_WINDOW_TYPE_HINT_NORMAL = 0; 52 static protected final int GDK_WINDOW_TYPE_HINT_DIALOG = 1; 53 static protected final int GDK_WINDOW_TYPE_HINT_MENU = 2; 54 static protected final int GDK_WINDOW_TYPE_HINT_TOOLBAR = 3; 55 static protected final int GDK_WINDOW_TYPE_HINT_SPLASHSCREEN = 4; 56 static protected final int GDK_WINDOW_TYPE_HINT_UTILITY = 5; 57 static protected final int GDK_WINDOW_TYPE_HINT_DOCK = 6; 58 static protected final int GDK_WINDOW_TYPE_HINT_DESKTOP = 7; 59 60 private boolean hasBeenShown = false; 61 private int oldState = Frame.NORMAL; 62 create(int type, boolean decorated, int width, int height, GtkWindowPeer parent, int[] insets)63 native void create (int type, boolean decorated, 64 int width, int height, 65 GtkWindowPeer parent, 66 int[] insets); 67 create(int type, boolean decorated)68 void create (int type, boolean decorated) 69 { 70 GtkWindowPeer parent_peer = null; 71 Component parent = awtComponent.getParent(); 72 int[] insets = new int [] { 0, 0, 0, 0 }; 73 74 if (parent != null) 75 parent_peer = (GtkWindowPeer) awtComponent.getParent().getPeer(); 76 77 create (type, decorated, 78 awtComponent.getWidth(), 79 awtComponent.getHeight(), 80 parent_peer, 81 insets); 82 83 this.insets.top = insets [0]; 84 this.insets.left = insets [1]; 85 this.insets.bottom = insets [2]; 86 this.insets.right = insets [3]; 87 } 88 create()89 void create () 90 { 91 // Create a normal undecorated window. 92 create (GDK_WINDOW_TYPE_HINT_NORMAL, false); 93 } 94 connectJObject()95 native void connectJObject (); connectSignals()96 native void connectSignals (); 97 GtkWindowPeer(Window window)98 public GtkWindowPeer (Window window) 99 { 100 super (window); 101 } 102 getArgs(Component component, GtkArgList args)103 public void getArgs (Component component, GtkArgList args) 104 { 105 args.add ("visible", component.isVisible ()); 106 args.add ("sensitive", component.isEnabled ()); 107 } 108 toBack()109 native public void toBack (); toFront()110 native public void toFront (); 111 nativeSetBounds(int x, int y, int width, int height)112 native void nativeSetBounds (int x, int y, int width, int height); 113 setBounds(int x, int y, int width, int height)114 public void setBounds (int x, int y, int width, int height) 115 { 116 nativeSetBounds (x, y, 117 width - insets.left - insets.right, 118 height - insets.top - insets.bottom); 119 } 120 setTitle(String title)121 public void setTitle (String title) 122 { 123 set ("title", title); 124 } 125 setSize(int width, int height)126 native void setSize (int width, int height); 127 setResizable(boolean resizable)128 public void setResizable (boolean resizable) 129 { 130 // Call setSize; otherwise when resizable is changed from true to 131 // false the window will shrink to the dimensions it had before it 132 // was resizable. 133 setSize (awtComponent.getWidth() - insets.left - insets.right, 134 awtComponent.getHeight() - insets.top - insets.bottom); 135 set ("allow_shrink", resizable); 136 set ("allow_grow", resizable); 137 } 138 setBoundsCallback(Window window, int x, int y, int width, int height)139 native void setBoundsCallback (Window window, 140 int x, int y, 141 int width, int height); 142 postInsetsChangedEvent(int top, int left, int bottom, int right)143 protected void postInsetsChangedEvent (int top, int left, 144 int bottom, int right) 145 { 146 insets.top = top; 147 insets.left = left; 148 insets.bottom = bottom; 149 insets.right = right; 150 } 151 postConfigureEvent(int x, int y, int width, int height)152 protected void postConfigureEvent (int x, int y, int width, int height) 153 { 154 int frame_x = x - insets.left; 155 int frame_y = y - insets.top; 156 int frame_width = width + insets.left + insets.right; 157 int frame_height = height + insets.top + insets.bottom; 158 159 if (frame_x != awtComponent.getX() 160 || frame_y != awtComponent.getY() 161 || frame_width != awtComponent.getWidth() 162 || frame_height != awtComponent.getHeight()) 163 setBoundsCallback ((Window) awtComponent, 164 frame_x, frame_y, frame_width, frame_height); 165 166 awtComponent.validate(); 167 } 168 nativeSetVisible(boolean b)169 native void nativeSetVisible (boolean b); setVisible(boolean b)170 public void setVisible (boolean b) 171 { 172 // Prevent the window manager from automatically placing this 173 // window when it is shown. 174 if (b) 175 setBounds (awtComponent.getX(), 176 awtComponent.getY(), 177 awtComponent.getWidth(), 178 awtComponent.getHeight()); 179 nativeSetVisible (b); 180 } 181 postWindowEvent(int id, Window opposite, int newState)182 void postWindowEvent (int id, Window opposite, int newState) 183 { 184 if (id == WindowEvent.WINDOW_OPENED) 185 { 186 // Post a WINDOW_OPENED event the first time this window is shown. 187 if (!hasBeenShown) 188 { 189 q.postEvent (new WindowEvent ((Window) awtComponent, id, 190 opposite)); 191 hasBeenShown = true; 192 } 193 } 194 else if (id == WindowEvent.WINDOW_STATE_CHANGED) 195 { 196 if (oldState != newState) 197 { 198 q.postEvent (new WindowEvent ((Window) awtComponent, id, opposite, 199 oldState, newState)); 200 oldState = newState; 201 } 202 } 203 else 204 q.postEvent (new WindowEvent ((Window) awtComponent, id, opposite)); 205 } 206 } 207