summaryrefslogtreecommitdiff
path: root/libjava/gnu/gcj/xlib/natClip.cc
blob: a1f626dfe351383138b580daacf954dd64d03bf6 (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
/* 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.  */

// Needed to avoid linking in libstdc++
#ifndef __STL_USE_EXCEPTIONS
#   include <java/lang/OutOfMemoryError.h>
#   define __THROW_BAD_ALLOC throw new java::lang::OutOfMemoryError()
#endif 

#include <vector>

#include <X11/Xlib.h>
#include <gcj/cni.h>
#include <gnu/gcj/RawData.h>
#include <java/awt/Rectangle.h>

#include "gnu/gcj/xlib/Clip.h"

typedef java::awt::Rectangle AWTRect;
typedef JArray<AWTRect*> AWTRectArray;
typedef std::vector<XRectangle> XRectVector;

void gnu::gcj::xlib::Clip::init(AWTRectArray* rectangles)
{
  // Prepare rectangles:
  
  int numRect = JvGetArrayLength(rectangles);
  XRectVector* xrectvector = new XRectVector(numRect);
  
  for (int i=0; i<numRect; i++)
    {
      AWTRect* awtrect = elements(rectangles)[i];
      XRectangle& xrect = (*xrectvector)[i];
      
      xrect.x      = awtrect->x;
      xrect.y      = awtrect->y;
      xrect.width  = awtrect->width;
      xrect.height = awtrect->height;
    }

  xrects = reinterpret_cast<gnu::gcj::RawData*>(xrectvector);
}

void gnu::gcj::xlib::Clip::dispose()
{
  if (xrects)
  {
    delete xrects; 
    xrects = 0;
  }
}