You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
176 lines
5.1 KiB
176 lines
5.1 KiB
15 years ago
|
/***************************************************************************
|
||
13 years ago
|
tqui.cpp - A ruby wrapper for the TQWidgetFactory class
|
||
15 years ago
|
-------------------
|
||
|
begin : Wed Mar 14 2004
|
||
|
copyright : (C) 2004 by Richard Dale
|
||
|
email : Richard_Dale@tipitina.demon.co.uk
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU General Public License as published by *
|
||
|
* the Free Software Foundation; either version 2 of the License, or *
|
||
|
* (at your option) any later version. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
|
||
15 years ago
|
#include <tqwidgetfactory.h>
|
||
|
#include <tqwidget.h>
|
||
15 years ago
|
|
||
|
#include "smoke.h"
|
||
|
|
||
|
#undef DEBUG
|
||
|
#ifndef _GNU_SOURCE
|
||
|
#define _GNU_SOURCE
|
||
|
#endif
|
||
|
#ifndef __USE_POSIX
|
||
|
#define __USE_POSIX
|
||
|
#endif
|
||
|
#ifndef __USE_XOPEN
|
||
|
#define __USE_XOPEN
|
||
|
#endif
|
||
|
#include <ruby.h>
|
||
|
|
||
|
#include "qtruby.h"
|
||
|
#include "smokeruby.h"
|
||
|
|
||
|
extern Smoke *qt_Smoke;
|
||
|
extern bool isDerivedFrom(Smoke *smoke, Smoke::Index classId, Smoke::Index baseId);
|
||
|
|
||
|
extern "C" {
|
||
|
extern VALUE set_obj_info(const char * className, smokeruby_object * o);
|
||
|
|
||
13 years ago
|
static VALUE tqui_module;
|
||
15 years ago
|
static VALUE qwidget_factory_class;
|
||
|
|
||
|
static VALUE
|
||
|
create(int argc, VALUE * argv, VALUE /*klass*/)
|
||
|
{
|
||
13 years ago
|
TQWidget * topLevelWidget = 0;
|
||
15 years ago
|
VALUE result = Qnil;
|
||
|
|
||
|
if (argc == 0 || argc > 4) {
|
||
|
rb_raise(rb_eArgError, "wrong number of arguments (%d)\n", argc);
|
||
|
}
|
||
|
|
||
13 years ago
|
TQObject * connector = 0;
|
||
15 years ago
|
if (argc >= 2) {
|
||
|
if (TYPE(argv[1]) == T_DATA) {
|
||
|
smokeruby_object *o = value_obj_info(argv[1]);
|
||
|
if (o != 0) {
|
||
13 years ago
|
connector = (TQObject *) o->ptr;
|
||
15 years ago
|
}
|
||
|
} else {
|
||
|
rb_raise(rb_eArgError, "invalid argument type\n");
|
||
|
}
|
||
|
}
|
||
|
|
||
13 years ago
|
TQWidget * parent = 0;
|
||
15 years ago
|
if (argc >= 3) {
|
||
|
if (TYPE(argv[2]) == T_DATA) {
|
||
|
smokeruby_object *o = value_obj_info(argv[2]);
|
||
|
if (o != 0) {
|
||
13 years ago
|
parent = (TQWidget *) o->ptr;
|
||
15 years ago
|
}
|
||
|
} else {
|
||
|
rb_raise(rb_eArgError, "invalid argument type\n");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const char * name = 0;
|
||
|
if (argc >= 4) {
|
||
|
if (TYPE(argv[3]) == T_STRING) {
|
||
|
name = StringValuePtr(argv[3]);
|
||
|
} else {
|
||
|
rb_raise(rb_eArgError, "invalid argument type\n");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (TYPE(argv[0]) == T_STRING) {
|
||
13 years ago
|
topLevelWidget = TQWidgetFactory::create(TQString(StringValuePtr(argv[0])), connector, parent, name);
|
||
15 years ago
|
} else if (TYPE(argv[0]) == T_DATA) {
|
||
13 years ago
|
TQIODevice * dev = 0;
|
||
15 years ago
|
smokeruby_object *o = value_obj_info(argv[0]);
|
||
|
|
||
13 years ago
|
if (o != 0 && o->ptr != 0 && o->classId == qt_Smoke->idClass("TQIODevice")) {
|
||
13 years ago
|
dev = (TQIODevice *) o->ptr;
|
||
15 years ago
|
} else {
|
||
|
rb_raise(rb_eArgError, "invalid argument type\n");
|
||
|
}
|
||
|
|
||
13 years ago
|
topLevelWidget = TQWidgetFactory::create(dev, connector, parent, name);
|
||
15 years ago
|
} else {
|
||
|
rb_raise(rb_eArgError, "invalid argument type\n");
|
||
|
}
|
||
|
|
||
|
if (topLevelWidget != 0) {
|
||
|
smokeruby_object * o = (smokeruby_object *) malloc(sizeof(smokeruby_object));
|
||
|
o->smoke = qt_Smoke;
|
||
|
o->classId = qt_Smoke->idClass(topLevelWidget->className());
|
||
|
o->ptr = topLevelWidget;
|
||
|
o->allocated = false;
|
||
|
|
||
|
const char * className = qt_Smoke->binding->className(o->classId);
|
||
|
result = set_obj_info(className, o);
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
static VALUE
|
||
|
load_images(VALUE klass, VALUE dir)
|
||
|
{
|
||
13 years ago
|
TQWidgetFactory::loadImages(TQString(StringValuePtr(dir)));
|
||
15 years ago
|
return klass;
|
||
|
}
|
||
|
|
||
|
static VALUE
|
||
|
widgets(VALUE /*self*/)
|
||
|
{
|
||
|
VALUE result = rb_ary_new();
|
||
13 years ago
|
TQStringList widgetList = TQWidgetFactory::widgets();
|
||
15 years ago
|
|
||
13 years ago
|
for (TQStringList::Iterator it = widgetList.begin(); it != widgetList.end(); ++it) {
|
||
|
TQString widgetName = *it;
|
||
15 years ago
|
if (widgetName.startsWith("Q")) {
|
||
13 years ago
|
widgetName.replace(0, 1, TQString("TQt::"));
|
||
15 years ago
|
} else if (widgetName.startsWith("K")) {
|
||
13 years ago
|
widgetName.replace(0, 1, TQString("KDE::"));
|
||
15 years ago
|
}
|
||
|
rb_ary_push(result, rb_str_new2(widgetName.latin1()));
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
static VALUE
|
||
|
supports_widget(VALUE /*self*/, VALUE widget)
|
||
|
{
|
||
13 years ago
|
TQString widgetName(StringValuePtr(widget));
|
||
15 years ago
|
|
||
13 years ago
|
if (widgetName.startsWith("TQt::")) {
|
||
13 years ago
|
widgetName.replace(0, 4, TQString("Q"));
|
||
15 years ago
|
} else if (widgetName.startsWith("KDE::")) {
|
||
13 years ago
|
widgetName.replace(0, 5, TQString("K"));
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
return TQWidgetFactory::supportsWidget(widgetName) ? Qtrue : Qfalse;
|
||
15 years ago
|
}
|
||
|
|
||
|
void
|
||
13 years ago
|
Init_tqui()
|
||
15 years ago
|
{
|
||
13 years ago
|
tqui_module = rb_define_module("TQUI");
|
||
|
qwidget_factory_class = rb_define_class_under(tqui_module, "WidgetFactory", rb_cObject);
|
||
15 years ago
|
|
||
|
rb_define_singleton_method(qwidget_factory_class, "create", (VALUE (*) (...)) create, -1);
|
||
|
rb_define_singleton_method(qwidget_factory_class, "loadImages", (VALUE (*) (...)) load_images, 1);
|
||
|
rb_define_singleton_method(qwidget_factory_class, "load_images", (VALUE (*) (...)) load_images, 1);
|
||
|
rb_define_singleton_method(qwidget_factory_class, "widgets", (VALUE (*) (...)) widgets, 0);
|
||
|
rb_define_singleton_method(qwidget_factory_class, "supportsWidget", (VALUE (*) (...)) supports_widget, 1);
|
||
|
rb_define_singleton_method(qwidget_factory_class, "supports_widget", (VALUE (*) (...)) supports_widget, 1);
|
||
|
}
|
||
|
|
||
|
};
|