/***************************************************************************
                            Part.m -  description
                             -------------------
    begin                : Fri Mar  8 13:55:08 2002
    copyright            : (C) 2000-2002 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Fri Mar  8 13:55:08 2002, 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 <kdec/kde_Part.h>
#include <kdec/kde_PartBase.h>
#include <kdeobjc/KDESupport.h>
#include <kdeobjc/Part.h>
#include <kdeobjc/KInstance.h>

#include <kdeobjc/PartManager.h>
#include <kdeobjc/KInstance.h>

#include <qtobjc/QPoint.h>
#include <qtobjc/QWidget.h>


@implementation  Part


- initWithObject: (QObject *)parent name: (NSString *)name
{
	if ([self qt] == 0L) {
		[self setQt: kde_new_Part((qt_QObject *) [parent qt], (char*) [name cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld] && [self parent] == nil) {
			kde_del_Part((kde_Part *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- embed: (QWidget *)parentWidget
{
	kde_Part_embed((kde_Part *)[self qt], (qt_QWidget *) [parentWidget qt]);
	return self;
}

- (QWidget*) widget
{
	return (QWidget*) [QtSupport objectForQtKey: kde_Part_widget((kde_Part *)[self qt]) withClass: [QWidget class] allocatedInObjcWorld: YES];
}

- setManager: (PartManager*)manager
{
	kde_Part_setManager((kde_Part *)[self qt], (kde_PartManager*) [manager qt]);
	return self;
}

- (PartManager*) manager
{
	return (PartManager*) [QtSupport objectForQtKey: kde_Part_manager((kde_Part *)[self qt]) withClass: [PartManager class] allocatedInObjcWorld: YES];
}

- (Part*) hitTest: (QWidget *)widget globalPos: (QPoint*)globalPos
{
	return (Part*) [QtSupport objectForQtKey: kde_Part_hitTest((kde_Part *)[self qt], (qt_QWidget *) [widget qt], (qt_QPoint*) [globalPos qt]) withClass: [Part class] allocatedInObjcWorld: YES];
}

- setSelectable: (BOOL)selectable
{
	kde_Part_setSelectable((kde_Part *)[self qt], (int)selectable);
	return self;
}

- (BOOL) isSelectable
{
	return (BOOL) kde_Part_isSelectable((kde_Part *)[self qt]);
}

- setWidget: (QWidget *)widget
{
	kde_Part_setWidget((kde_Part *)[self qt], (qt_QWidget *) [widget qt]);
	return self;
}

- (BOOL) event: (QEvent *)event
{
	return (BOOL) kde_Part_event((kde_Part *)[self qt], (qt_QEvent *) [event qt]);
}

- (QWidget*) hostContainer: (NSString *)containerName
{
static qt_QString * _qstring_containerName = 0L;
	return (QWidget*) [QtSupport objectForQtKey: kde_Part_hostContainer((kde_Part *)[self qt], (qt_QString *) [containerName toQString: &_qstring_containerName]) withClass: [QWidget class] allocatedInObjcWorld: YES];
}

@end

@implementation Part (PartBaseImplementation)

- setPartObject: (QObject *)object
{
	kde_PartBase_setPartObject(kde_Part_PartBase([self qt]), (qt_QObject *) [object qt]);
	return self;
}

- (QObject*) partObject
{
	return (QObject*) [QtSupport objectForQtKey: kde_PartBase_partObject(kde_Part_PartBase([self qt])) withClass: [QObject class] allocatedInObjcWorld: YES];
}

- setInstance: (KInstance*)instance
{
	kde_PartBase_setInstance(kde_Part_PartBase([self qt]), (kde_KInstance*) [instance qt]);
	return self;
}

- setInstance: (KInstance*)instance loadPlugins: (BOOL)loadPlugins
{
	kde_PartBase_setInstance1(kde_Part_PartBase([self qt]), (kde_KInstance*) [instance qt], (int)loadPlugins);
	return self;
}

@end
