/***************************************************************************
                            QObject.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_QObject.h>
#include <qtobjc/QObject.h>
#include <qtobjc/QVariant.h>

@implementation  QObject


- initWithObject: (QObject *)parent name: (NSString *)name
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QObject((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: qt_new_QObject(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) {
			qt_del_QObject((qt_QObject *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- (NSString *) className
{
	return (NSString *) [NSString stringWithCString: qt_QObject_className((qt_QObject *)[self qt])];
}

- (NSString *) tr: (NSString *)arg1 string: (NSString *)arg2
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QObject_tr((qt_QObject *)[self qt], (char*) [arg1 cString], (char*) [arg2 cString]);
	return [NSString fromQString: _qstring];
}

- (NSString *) trUtf8: (NSString *)arg1 string: (NSString *)arg2
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QObject_trUtf8((qt_QObject *)[self qt], (char*) [arg1 cString], (char*) [arg2 cString]);
	return [NSString fromQString: _qstring];
}

- (QMetaObject*) metaObject
{
	return (QMetaObject*) [QtSupport objectForQtKey: qt_QObject_metaObject((qt_QObject *)[self qt]) withClass: [QMetaObject class] allocatedInObjcWorld: YES];
}

- (BOOL) event: (QEvent *)arg1
{
	return (BOOL) qt_QObject_event((qt_QObject *)[self qt], (qt_QEvent *) [arg1 qt]);
}

- (BOOL) eventFilter: (QObject *)arg1 event: (QEvent *)arg2
{
	return (BOOL) qt_QObject_eventFilter((qt_QObject *)[self qt], (qt_QObject *) [arg1 qt], (qt_QEvent *) [arg2 qt]);
}

- (BOOL) isA: (NSString *)arg1
{
	return (BOOL) qt_QObject_isA((qt_QObject *)[self qt], (char*) [arg1 cString]);
}

- (BOOL) inherits: (NSString *)arg1
{
	return (BOOL) qt_QObject_inherits((qt_QObject *)[self qt], (char*) [arg1 cString]);
}

- (NSString *) name
{
	return (NSString *) [NSString stringWithCString: qt_QObject_name((qt_QObject *)[self qt])];
}

- (NSString *) name: (NSString *)defaultName
{
	return (NSString *) [NSString stringWithCString: qt_QObject_name1((qt_QObject *)[self qt], (char*) [defaultName cString])];
}

- setName: (NSString *)name
{
	qt_QObject_setName((qt_QObject *)[self qt], (char*) [name cString]);
	return self;
}

- (BOOL) isWidgetType
{
	return (BOOL) qt_QObject_isWidgetType((qt_QObject *)[self qt]);
}

- (BOOL) highPriority
{
	return (BOOL) qt_QObject_highPriority((qt_QObject *)[self qt]);
}

- (BOOL) signalsBlocked
{
	return (BOOL) qt_QObject_signalsBlocked((qt_QObject *)[self qt]);
}

- blockSignals: (BOOL)b
{
	qt_QObject_blockSignals((qt_QObject *)[self qt], (int)b);
	return self;
}

- (int) startTimer: (int)interval
{
	return (int) qt_QObject_startTimer((qt_QObject *)[self qt], (int)interval);
}

- killTimer: (int)identifier
{
	qt_QObject_killTimer((qt_QObject *)[self qt], (int)identifier);
	return self;
}

- killTimers
{
	qt_QObject_killTimers((qt_QObject *)[self qt]);
	return self;
}

- (QObject*) child: (NSString *)objName inheritsClass: (NSString *)inheritsClass recursiveSearch: (BOOL)recursiveSearch
{
	return (QObject*) [QtSupport objectForQtKey: qt_QObject_child((qt_QObject *)[self qt], (char*) [objName cString], (char*) [inheritsClass cString], (int)recursiveSearch) withClass: [QObject class] allocatedInObjcWorld: YES];
}

- (QObject*) child: (NSString *)objName 
{
	return (QObject*) [QtSupport objectForQtKey: qt_QObject_child((qt_QObject *)[self qt], (char*) [objName cString], 0, 1) withClass: [QObject class] allocatedInObjcWorld: YES];
}

- (NSArray *) children
{
static qt_QObjectList * _qlist = 0L;
	_qlist = qt_QObject_children((qt_QObject *)[self qt]);
	return (NSArray *) [NSMutableArray arrayWithQObjectList: _qlist];
}

- (NSArray *) queryList: (NSString *)inheritsClass objName: (NSString *)objName regexpMatch: (BOOL)regexpMatch recursiveSearch: (BOOL)recursiveSearch
{
static qt_QObjectList * _qlist = 0L;
	_qlist = qt_QObject_queryList((qt_QObject *)[self qt], (char*) [inheritsClass cString], (char*) [objName cString], (int)regexpMatch, (int)recursiveSearch);
	return (NSArray *) [NSMutableArray arrayWithQObjectList: _qlist];
}

- insertChild: (QObject *)arg1
{
	qt_QObject_insertChild((qt_QObject *)[self qt], (qt_QObject *) [arg1 qt]);
	return self;
}

- removeChild: (QObject *)arg1
{
	qt_QObject_removeChild((qt_QObject *)[self qt], (qt_QObject *) [arg1 qt]);
	return self;
}

- installEventFilter: (QObject *)arg1
{
	qt_QObject_installEventFilter((qt_QObject *)[self qt], (qt_QObject *) [arg1 qt]);
	return self;
}

- removeEventFilter: (QObject *)arg1
{
	qt_QObject_removeEventFilter((qt_QObject *)[self qt], (qt_QObject *) [arg1 qt]);
	return self;
}

- (BOOL) connect: (QObject *)sender signal: (NSString *)signal slot: (NSString *)member
{
	return [QtSupport connect: sender signal: signal receiver: self slot: member];
}

- (BOOL) disconnect: (NSString *)signal receiver: (QObject *)receiver slot: (NSString *)member
{
	return (BOOL) qt_QObject_disconnect((qt_QObject *)[self qt], (char*) [signal cString], (qt_QObject *) [receiver qt], (char*) [member cString]);
}

- (BOOL) disconnect
{
	return (BOOL) qt_QObject_disconnect((qt_QObject *)[self qt], 0, 0, 0);
}

- (BOOL) disconnect: (QObject *)receiver slot: (NSString *)member
{
	return (BOOL) qt_QObject_disconnect1((qt_QObject *)[self qt], (qt_QObject *) [receiver qt], (char*) [member cString]);
}

- (BOOL) disconnect: (QObject *)receiver 
{
	return (BOOL) qt_QObject_disconnect1((qt_QObject *)[self qt], (qt_QObject *) [receiver qt], 0);
}

- dumpObjectTree
{
	qt_QObject_dumpObjectTree((qt_QObject *)[self qt]);
	return self;
}

- dumpObjectInfo
{
	qt_QObject_dumpObjectInfo((qt_QObject *)[self qt]);
	return self;
}

- (BOOL) setProperty: (NSString *)name value: (QVariant *)value
{
	return (BOOL) qt_QObject_setProperty((qt_QObject *)[self qt], (char*) [name cString], (qt_QVariant *) [value qt]);
}

- (QVariant*) property: (NSString *)name
{
	return (QVariant*) [QtSupport objectForQtKey: qt_QObject_property((qt_QObject *)[self qt], (char*) [name cString]) withClass: [QVariant class] allocatedInObjcWorld: YES];
}

- (QObject*) parent
{
	return (QObject*) [QtSupport objectForQtKey: qt_QObject_parent((qt_QObject *)[self qt]) withClass: [QObject class] allocatedInObjcWorld: YES];
}

- deleteLater
{
	qt_QObject_deleteLater((qt_QObject *)[self qt]);
	return self;
}

+ (NSArray *) objectTrees
{
static qt_QObjectList * _qlist = 0L;
	_qlist = qt_QObject_objectTrees();
	return (NSArray *) [NSMutableArray arrayWithQObjectList: _qlist];
}

+ (BOOL) connect: (QObject *)sender signal: (NSString *)signal receiver: (QObject *)receiver slot: (NSString *)member
{
	return [QtSupport connect: sender signal: signal receiver: receiver slot: member];
}

+ (BOOL) disconnect: (QObject *)sender signal: (NSString *)signal receiver: (QObject *)receiver slot: (NSString *)member
{
	return (BOOL) qt_QObject_disconnect2((qt_QObject *) [sender qt], (char*) [signal cString], (qt_QObject *) [receiver qt], (char*) [member cString]);
}

+ connectInternal: (QObject *)sender signal_index: (int)signal_index receiver: (QObject *)receiver membcode: (int)membcode member_index: (int)member_index
{
	qt_QObject_connectInternal((qt_QObject *) [sender qt], (int)signal_index, (qt_QObject *) [receiver qt], (int)membcode, (int)member_index);
	return self;
}

+ (NSString *) tr: (NSString *)sourceText string: (NSString *)arg1
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QObject_tr1((char*) [sourceText cString], (char*) [arg1 cString]);
	return [NSString fromQString: _qstring];
}

+ (NSString *) trUtf8: (NSString *)sourceText string: (NSString *)arg1
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QObject_trUtf81((char*) [sourceText cString], (char*) [arg1 cString]);
	return [NSString fromQString: _qstring];
}

- (BOOL) activate_filters: (QEvent *)arg1
{
	return (BOOL) qt_QObject_activate_filters((qt_QObject *)[self qt], (qt_QEvent *) [arg1 qt]);
}

//- (QConnectionList*) receivers: (NSString *)signal
//{
//	return (QConnectionList*) [QtSupport objectForQtKey: qt_QObject_receivers((qt_QObject *)[self qt], (char*) [signal cString]) withClass: [QConnectionList class] allocatedInObjcWorld: YES];
//}

//- (QConnectionList*) receivers: (int)signal
//{
//	return (QConnectionList*) [QtSupport objectForQtKey: qt_QObject_receivers1((qt_QObject *)[self qt], (int)signal) withClass: [QConnectionList class] allocatedInObjcWorld: YES];
//}

- activate_signal: (int)signal
{
	qt_QObject_activate_signal((qt_QObject *)[self qt], (int)signal);
	return self;
}

- activate_signal: (int)signal int: (int)arg1
{
	qt_QObject_activate_signal1((qt_QObject *)[self qt], (int)signal, (int)arg1);
	return self;
}

- activate_signal: (int)signal double: (double)arg1
{
	qt_QObject_activate_signal2((qt_QObject *)[self qt], (int)signal, (double)arg1);
	return self;
}

- activate_signal: (int)signal string: (NSString *)arg1
{
static qt_QString * _qstring_arg1 = 0L;
	qt_QObject_activate_signal3((qt_QObject *)[self qt], (int)signal, (qt_QString *) [arg1 toQString: &_qstring_arg1]);
	return self;
}

- activate_signal_bool: (int)signal bool: (BOOL)arg1
{
	qt_QObject_activate_signal_bool((qt_QObject *)[self qt], (int)signal, (int)arg1);
	return self;
}

//- activate_signal: (QConnectionList*)clist o: (QUObject*)o
//{
//	qt_QObject_activate_signal4((qt_QObject *)[self qt], (qt_QConnectionList*) [clist qt], (qt_QUObject*) [o qt]);
//	return self;
//}

- (QObject*) sender
{
	return (QObject*) [QtSupport objectForQtKey: qt_QObject_sender((qt_QObject *)[self qt]) withClass: [QObject class] allocatedInObjcWorld: YES];
}

- connectNotify: (NSString *)signal
{
	qt_QObject_connectNotify((qt_QObject *)[self qt], (char*) [signal cString]);
	return self;
}

- disconnectNotify: (NSString *)signal
{
	qt_QObject_disconnectNotify((qt_QObject *)[self qt], (char*) [signal cString]);
	return self;
}

- (BOOL) checkConnectArgs: (NSString *)signal receiver: (QObject *)receiver slot: (NSString *)member
{
	return (BOOL) qt_QObject_checkConnectArgs((qt_QObject *)[self qt], (char*) [signal cString], (qt_QObject *) [receiver qt], (char*) [member cString]);
}

//+ (NSString *) normalizeSignalSlot: (NSString *)signalSlot
//{
//static qt_QCString * _qcstring = 0L;
//	_qcstring = qt_QObject_normalizeSignalSlot((char*) [signalSlot cString]);
//	return [NSString fromQCString: _qcstring];
//}

- emit: (NSString *) signal
{
	[QtSupport sender: self emit: signal];
	return self;
}

- emit: (NSString *) signal value: value
{
	[QtSupport sender: self emit: signal value: value];
	return self;
}

- emit: (NSString *) signal intValue: (int) value
{
	[QtSupport sender: self emit: signal intValue: value];
 	return self;
}


@end
