summaryrefslogtreecommitdiff
path: root/libjava/gnu/gcj/xlib/Window.java
blob: 3ff3657c45c95da4e1ff7615ff3538cc59f30f19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* Copyright (C) 2000  Free Software Foundation

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

package gnu.gcj.xlib;

import gnu.gcj.RawData;
import java.awt.Rectangle;

/**
 * An X11 window.
 *
 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
 */
public class Window extends Drawable
{
  // Must correspond with X.h definitions:
  public static final int COPY_FROM_PARENT = 0;
  public static final int INPUT_OUTPUT     = 1;
  public static final int INPUT_ONLY       = 2;

  public Window(Window parent, Rectangle bounds,
		WindowAttributes attributes)
  {
    this(parent, bounds, attributes, null);
  }
  
  public Window(Window parent, Rectangle bounds,
		WindowAttributes attributes, Visual visual)
  {
    this(parent, bounds, 0, attributes, COPY_FROM_PARENT, visual);
  }

  public Window(Window parent, Rectangle bounds, int borderWidth,
		WindowAttributes attributes, int windowIOClass,
		Visual visual)
  {
    this(parent.display,
	 parent.createChildXID(bounds, borderWidth, attributes, 
			       windowIOClass, visual));
    this.owned = true;
  }

  protected Window(Display display, int xid)
  {
    super(display, xid);
    display.addXID(xid, this);
  }

  protected void finalize()
  {
    display.removeXID(xid);
    if (owned)
      {
	destroy();
	owned = false;
      }
  }

  protected native void destroy();

  protected native int createChildXID(Rectangle bounds,
				      int borderWidth,
				      WindowAttributes attributes,
				      int windowIOClass, 
				      Visual visual);

  public native void setAttributes(WindowAttributes attributes);

  public native void map();
  public native void unmap();
  public native void toFront();
  public native void toBack();
  
  protected boolean owned = false;

  public native void setProperty(int nameAtom, int typeAtom, byte[] data);
  
  public void setProperty(int nameAtom, int typeAtom, String data)
  {
    int length = data.length();
    byte[] byteData = new byte[length];
    
    for (int i=0; i<length; i++)
      byteData[i] = (byte) data.charAt(i);

    setProperty(nameAtom, typeAtom, byteData);
  }

  public native void setWMProtocols(int[] atoms);
  public native int[] getWMProtocols();

  public void setProperty(String nameAtom, String typeAtom, String data)
  {
    int xaName = display.getAtom(nameAtom);
    int xaType = display.getAtom(typeAtom);
    
    setProperty(xaName, xaType, data);
  }

  public native void setBounds(int x, int y, int width, int height);
}