/***************************************************************************
                            QRegion.m -  description
                             -------------------
    begin                : Wed Nov 21 12:08:37 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 12:08:37 2001, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <qtc/qt_QRegion.h>
#include <qtobjc/QRegion.h>
#include <qtobjc/QBitmap.h>
#include <qtobjc/QPoint.h>
#include <qtobjc/QPointArray.h>
#include <qtobjc/QRect.h>


@implementation  QRegion

- (void *) qt
{
	return _qt;
}

- setQt: (void *) qt
{
	_qt = qt;
	return self;
}

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

- setAllocatedInObjcWorld: (BOOL) yn
{
	_allocatedInObjcWorld = yn;
	return self;
}


- init
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QRegion()];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithInt: (int)x y: (int)y w: (int)w h: (int)h int: (int)arg1
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QRegion1((int)x, (int)y, (int)w, (int)h, (int)arg1)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithInt: (int)x y: (int)y w: (int)w h: (int)h 
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QRegion1((int)x, (int)y, (int)w, (int)h, [QRegion Rectangle])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithRect: (QRect*)arg1 int: (int)arg2
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QRegion2((qt_QRect*) [arg1 qt], (int)arg2)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithRect: (QRect*)arg1 
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QRegion2((qt_QRect*) [arg1 qt], [QRegion Rectangle])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithPointArray: (QPointArray*)arg1 winding: (BOOL)winding
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QRegion3((qt_QPointArray*) [arg1 qt], (int)winding)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithPointArray: (QPointArray*)arg1 
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QRegion3((qt_QPointArray*) [arg1 qt], 0)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- copyWithZone: (NSZone *) zone
{
	QRegion * aCopy;
	aCopy = [[(QRegion *)[[self class] allocWithZone: zone] setQt: qt_new_QRegion4([self qt])] init];
	[aCopy setAllocatedInObjcWorld: YES];
	[QtSupport setObject: aCopy forQtKey: [aCopy qt]];
	return aCopy;
}

- initWithBitmap: (QBitmap *)arg1
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QRegion5((qt_QBitmap *) [arg1 qt])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld]) {
			qt_del_QRegion((qt_QRegion *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (BOOL) isNull
{
	return (BOOL) qt_QRegion_isNull((qt_QRegion *)[self qt]);
}

- (BOOL) isEmpty
{
	return (BOOL) qt_QRegion_isEmpty((qt_QRegion *)[self qt]);
}

- (BOOL) containsPoint: (QPoint*)p
{
	return (BOOL) qt_QRegion_contains((qt_QRegion *)[self qt], (qt_QPoint*) [p qt]);
}

- (BOOL) containsRect: (QRect*)r
{
	return (BOOL) qt_QRegion_contains1((qt_QRegion *)[self qt], (qt_QRect*) [r qt]);
}

- translate: (int)dx dy: (int)dy
{
	qt_QRegion_translate((qt_QRegion *)[self qt], (int)dx, (int)dy);
	return self;
}

- (QRegion*) unite: (QRegion *)arg1
{
	return (QRegion*) [QtSupport objectForQtKey: qt_QRegion_unite((qt_QRegion *)[self qt], (qt_QRegion *) [arg1 qt]) withClass: [QRegion class] allocatedInObjcWorld: YES];
}

- (QRegion*) intersect: (QRegion *)arg1
{
	return (QRegion*) [QtSupport objectForQtKey: qt_QRegion_intersect((qt_QRegion *)[self qt], (qt_QRegion *) [arg1 qt]) withClass: [QRegion class] allocatedInObjcWorld: YES];
}

- (QRegion*) subtract: (QRegion *)arg1
{
	return (QRegion*) [QtSupport objectForQtKey: qt_QRegion_subtract((qt_QRegion *)[self qt], (qt_QRegion *) [arg1 qt]) withClass: [QRegion class] allocatedInObjcWorld: YES];
}

- (QRegion*) eor: (QRegion *)arg1
{
	return (QRegion*) [QtSupport objectForQtKey: qt_QRegion_eor((qt_QRegion *)[self qt], (qt_QRegion *) [arg1 qt]) withClass: [QRegion class] allocatedInObjcWorld: YES];
}

- (QRect*) boundingRect
{
	return (QRect*) [QtSupport objectForQtKey: qt_QRegion_boundingRect((qt_QRegion *)[self qt]) withClass: [QRect class] allocatedInObjcWorld: YES];
}

- setRects: (QRect*)arg1 int: (int)arg2
{
	qt_QRegion_setRects((qt_QRegion *)[self qt], (qt_QRect*) [arg1 qt], (int)arg2);
	return self;
}

//- (void*) handle
//{
//	return (void*) qt_QRegion_handle((qt_QRegion *)[self qt]);
//}

//- (int) handle
//{
//	return (int) qt_QRegion_handle1((qt_QRegion *)[self qt]);
//}

//- (RgnHandle) handle: (BOOL)require_rgn
//{
//	return (RgnHandle) qt_QRegion_handle2((qt_QRegion *)[self qt], (int)require_rgn);
//}

//- (RgnHandle) handle
//{
//	return (RgnHandle) qt_QRegion_handle2((qt_QRegion *)[self qt], 0);
//}

//- (void*) handle
//{
//	return (void*) qt_QRegion_handle3((qt_QRegion *)[self qt]);
//}

+ (int) Rectangle
{
	return (int) QREGION_Rectangle;
}

+ (int) Ellipse
{
	return (int) QREGION_Ellipse;
}

@end
