/***************************************************************************
                            QAccessibleObject.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.                       *
 *                                                                         *
 ***************************************************************************/

#if defined(QT_ACCESSIBILITY_SUPPORT)

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <qtc/qt_QAccessibleObject.h>
#include <qtc/qt_QAccessibleInterface.h>
#include <qtobjc/QAccessibleObject.h>

@implementation  QAccessibleObject


- initWithObject: (QObject *)object
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QAccessibleObject((qt_QObject *) [object qt])];
		[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_QAccessibleObject((qt_QAccessibleObject *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

//- (long) queryInterface: (QUuid*)arg1 unknowninterface: (QUnknownInterface**)arg2
//{
//	return (long) qt_QAccessibleObject_queryInterface((qt_QAccessibleObject *)[self qt], (qt_QUuid*) [arg1 qt], (qt_QUnknownInterface**) [arg2 qt]);
//}

//- (Q_REFCOUNT bool) isValid
//{
//	return (Q_REFCOUNT bool) qt_QAccessibleObject_isValid((qt_QAccessibleObject *)[self qt]);
//}

- (QObject*) object
{
	return (QObject*) [QtSupport objectForQtKey: qt_QAccessibleObject_object((qt_QAccessibleObject *)[self qt]) withClass: [QObject class] allocatedInObjcWorld: YES];
}

@end

@implementation QAccessibleObject (QAccessibleInterfaceImplementation)

- (BOOL) isValid
{
	return (BOOL) qt_QAccessibleInterface_isValid(qt_QAccessibleObject_QAccessibleInterface([self qt]));
}

- (int) childCount
{
	return (int) qt_QAccessibleInterface_childCount(qt_QAccessibleObject_QAccessibleInterface([self qt]));
}

//- (long) queryChild: (int)control accessibleinterface: (QAccessibleInterface**)arg1
//{
//	return (long) qt_QAccessibleInterface_queryChild(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)control, (qt_QAccessibleInterface**) [arg1 qt]);
//}

//- (long) queryParent: (QAccessibleInterface**)arg1
//{
//	return (long) qt_QAccessibleInterface_queryParent(qt_QAccessibleObject_QAccessibleInterface([self qt]), (qt_QAccessibleInterface**) [arg1 qt]);
//}

- (int) controlAt: (int)x y: (int)y
{
	return (int) qt_QAccessibleInterface_controlAt(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)x, (int)y);
}

- (QRect*) rect: (int)control
{
	return (QRect*) [QtSupport objectForQtKey: qt_QAccessibleInterface_rect(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)control) withClass: [QRect class] allocatedInObjcWorld: YES];
}

- (int) navigate: (int)direction startControl: (int)startControl
{
	return (int) qt_QAccessibleInterface_navigate(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)direction, (int)startControl);
}

- (NSString *) text: (int)t control: (int)control
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QAccessibleInterface_text(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)t, (int)control);
	return [NSString fromQString: _qstring];
}

- setText: (int)t control: (int)control text: (NSString *)text
{
static qt_QString * _qstring_text = 0L;
	qt_QAccessibleInterface_setText(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)t, (int)control, (qt_QString *) [text toQString: &_qstring_text]);
	return self;
}

- (int) role: (int)control
{
	return (int) qt_QAccessibleInterface_role(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)control);
}

- (int) state: (int)control
{
	return (int) qt_QAccessibleInterface_state(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)control);
}

- (BOOL) doDefaultAction: (int)control
{
	return (BOOL) qt_QAccessibleInterface_doDefaultAction(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)control);
}

- (BOOL) setFocus: (int)control
{
	return (BOOL) qt_QAccessibleInterface_setFocus(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)control);
}

- (BOOL) setSelected: (int)control on: (BOOL)on extend: (BOOL)extend
{
	return (BOOL) qt_QAccessibleInterface_setSelected(qt_QAccessibleObject_QAccessibleInterface([self qt]), (int)control, (int)on, (int)extend);
}

- clearSelection
{
	qt_QAccessibleInterface_clearSelection(qt_QAccessibleObject_QAccessibleInterface([self qt]));
	return self;
}

@end

#endif

