summaryrefslogtreecommitdiff
path: root/libjava/gnu/gcj/xlib/natWindowAttributes.cc
blob: b619348180749dee0fcf2e2c0dc9d575a43b1f75 (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
107
108
109
/* 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.  */

#include <X11/Xlib.h>

#include <gcj/cni.h>
#include <gnu/gcj/RawData.h>

#include <gnu/gcj/xlib/Display.h>
#include <gnu/gcj/xlib/Window.h>
#include <gnu/gcj/xlib/WindowAttributes.h>
#include <gnu/gcj/xlib/Pixmap.h>
#include <gnu/gcj/xlib/XException.h>
#include <gnu/gcj/xlib/Screen.h>
#include <gnu/gcj/xlib/Visual.h>


void gnu::gcj::xlib::WindowAttributes::initFromWindow(Window* from)
{
  display = from->getDisplay();
  ::Display* dpy = (::Display*) display->display;
  ::Window win = from->getXID();
  
  XWindowAttributes* attributesIn  = new XWindowAttributes;
  in = reinterpret_cast<gnu::gcj::RawData*>(attributesIn);

  Status status = XGetWindowAttributes(dpy, win, attributesIn);
  if ((status == BadDrawable) | (status == BadWindow))
    throw new XException(display, status);
}


void gnu::gcj::xlib::WindowAttributes::init(WindowAttributes* copyFrom)
{
  XSetWindowAttributes* attributes = new XSetWindowAttributes;

  if (copyFrom != 0)
    {
      XSetWindowAttributes* from = 
	(XSetWindowAttributes*) copyFrom->out;
      (*attributes) = (*from);
    } 
  
  out = reinterpret_cast<gnu::gcj::RawData*>(attributes);
}

void gnu::gcj::xlib::WindowAttributes::finalize()
{
  delete in; in = 0;
  delete out; out = 0;
}

void gnu::gcj::xlib::WindowAttributes::setBackground(jlong pixel)
{
  XSetWindowAttributes* attributes = (XSetWindowAttributes*) out;
  
  attributes->background_pixel = pixel;
  mask = mask | CWBackPixel;
}

void gnu::gcj::xlib::WindowAttributes::setBackground(Pixmap* pixmap)
{
  XSetWindowAttributes* attributes = (XSetWindowAttributes*) out;

  attributes->background_pixmap = pixmap->getXID();
  mask = mask | CWBackPixmap;
}

void gnu::gcj::xlib::WindowAttributes::setEventMask(jlong eventMask)
{
  XSetWindowAttributes* attributes = (XSetWindowAttributes*) out;

  attributes->event_mask = eventMask;
  mask = mask | CWEventMask;
}

gnu::gcj::xlib::Visual* gnu::gcj::xlib::WindowAttributes::getVisual()
{
  if (in == 0)
    return 0;

  XWindowAttributes* attributesIn = (XWindowAttributes*) in;

  gnu::gcj::RawData* screenRef =
    reinterpret_cast<gnu::gcj::RawData*>(attributesIn->screen);

  Screen* screen = new Screen(display, screenRef);

  gnu::gcj::RawData* visualRef =
    reinterpret_cast<gnu::gcj::RawData*>(attributesIn->visual);

  return new gnu::gcj::xlib::Visual(visualRef, screen, attributesIn->depth);
}


void gnu::gcj::xlib::WindowAttributes::apply(Window* window)
{
  ::Display* dpy = (::Display*) window->getDisplay()->display;
  ::Window win = window->getXID();
  XSetWindowAttributes* attributes = (XSetWindowAttributes*) out;
  
  XChangeWindowAttributes(dpy, win, mask, attributes);
}