diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gtk2_in_qt4.cpp | 149 | ||||
-rw-r--r-- | src/qt4_in_gtk2.cpp | 157 | ||||
-rw-r--r-- | src/x11_in_qt4.cpp | 155 |
3 files changed, 0 insertions, 461 deletions
diff --git a/src/gtk2_in_qt4.cpp b/src/gtk2_in_qt4.cpp deleted file mode 100644 index 9186273..0000000 --- a/src/gtk2_in_qt4.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - Copyright 2011-2015 David Robillard <d@drobilla.net> - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include "dylib.h" -#include "suil_config.h" -#include "suil_internal.h" - -#include <QX11EmbedContainer> - -#undef signals - -#include <gdk/gdkx.h> -#include <gtk/gtk.h> - -extern "C" { - -using SuilGtk2InQt4Wrapper = _SuilGtk2InQt4Wrapper; - -struct _SuilGtk2InQt4Wrapper { - QX11EmbedContainer* host_widget; - QWidget* parent; - GtkWidget* plug; -}; - -static void -on_size_request(GtkWidget* widget, - GtkRequisition* requisition, - gpointer user_data) -{ - QX11EmbedContainer* const wrap = (QX11EmbedContainer*)user_data; - wrap->setMinimumSize(requisition->width, requisition->height); -} - -static void -on_size_allocate(GtkWidget* widget, - GdkRectangle* allocation, - gpointer user_data) -{ - QX11EmbedContainer* const wrap = (QX11EmbedContainer*)user_data; - wrap->resize(allocation->width, allocation->height); -} - -static void -wrapper_free(SuilWrapper* wrapper) -{ - SuilGtk2InQt4Wrapper* impl = (SuilGtk2InQt4Wrapper*)wrapper->impl; - - if (impl->plug) { - gtk_widget_destroy(impl->plug); - } - - if (impl->host_widget) { - delete impl->host_widget; - } - - free(impl); -} - -static int -wrapper_wrap(SuilWrapper* wrapper, SuilInstance* instance) -{ - SuilGtk2InQt4Wrapper* const impl = (SuilGtk2InQt4Wrapper*)wrapper->impl; - QWidget* root = static_cast<QWidget*>(impl->parent); - QX11EmbedContainer* const wrap = new QX11EmbedContainer(root); - GtkWidget* const plug = gtk_plug_new(wrap->winId()); - GtkWidget* const widget = (GtkWidget*)instance->ui_widget; - - gtk_container_add(GTK_CONTAINER(plug), widget); - gtk_widget_show_all(plug); - -#ifdef SUIL_OLD_GTK - wrap->resize(widget->allocation.width, widget->allocation.height); -#else - GtkAllocation alloc; - gtk_widget_get_allocation(widget, &alloc); - wrap->resize(alloc.width, alloc.height); -#endif - - g_signal_connect( - G_OBJECT(plug), "size-request", G_CALLBACK(on_size_request), wrap); - - g_signal_connect( - G_OBJECT(plug), "size-allocate", G_CALLBACK(on_size_allocate), wrap); - - impl->host_widget = wrap; - impl->plug = plug; - instance->host_widget = wrap; - - return 0; -} - -SUIL_LIB_EXPORT -SuilWrapper* -suil_wrapper_new(SuilHost* host, - const char* host_type_uri, - const char* ui_type_uri, - LV2_Feature*** features, - unsigned n_features) -{ - /* We have to open libgtk here, so Gtk type symbols are present and will be - found by the introspection stuff. This is required at least to make - GtkBuilder use in UIs work, otherwise they will cause "Invalid object - type" errors. - */ - if (!host->gtk_lib) { - dylib_error(); - host->gtk_lib = dylib_open(SUIL_GTK2_LIB_NAME, DYLIB_LAZY | DYLIB_GLOBAL); - if (!host->gtk_lib) { - SUIL_ERRORF( - "Failed to open %s (%s)\n", SUIL_GTK2_LIB_NAME, dylib_error()); - return nullptr; - } - - gtk_init(nullptr, nullptr); - } - - /* Create wrapper implementation. */ - SuilGtk2InQt4Wrapper* const impl = - (SuilGtk2InQt4Wrapper*)calloc(1, sizeof(SuilGtk2InQt4Wrapper)); - - /* Set parent widget if given. */ - for (unsigned i = 0; i < n_features; ++i) { - if (!strcmp((*features)[i]->URI, LV2_UI__parent)) { - impl->parent = static_cast<QWidget*>((*features)[i]->data); - } - } - - SuilWrapper* wrapper = (SuilWrapper*)calloc(1, sizeof(SuilWrapper)); - wrapper->wrap = wrapper_wrap; - wrapper->free = wrapper_free; - wrapper->impl = impl; - - return wrapper; -} - -} // extern "C" diff --git a/src/qt4_in_gtk2.cpp b/src/qt4_in_gtk2.cpp deleted file mode 100644 index 122b642..0000000 --- a/src/qt4_in_gtk2.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* - Copyright 2011-2017 David Robillard <d@drobilla.net> - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include "suil_internal.h" - -#include <QApplication> -#include <QVBoxLayout> -#include <QX11EmbedWidget> - -#undef signals - -#include <gtk/gtk.h> - -extern "C" { - -#define SUIL_TYPE_QT_WRAPPER (suil_qt_wrapper_get_type()) -#define SUIL_QT_WRAPPER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj), SUIL_TYPE_QT_WRAPPER, SuilQtWrapper)) - -using SuilQtWrapper = _SuilQtWrapper; -using SuilQtWrapperClass = _SuilQtWrapperClass; - -struct _SuilQtWrapper { - GtkSocket socket; - QApplication* app; - QX11EmbedWidget* qembed; - SuilWrapper* wrapper; - SuilInstance* instance; -}; - -struct _SuilQtWrapperClass { - GtkSocketClass parent_class; -}; - -GType -suil_qt_wrapper_get_type(void); // Accessor for SUIL_TYPE_QT_WRAPPER - -G_DEFINE_TYPE(SuilQtWrapper, suil_qt_wrapper, GTK_TYPE_SOCKET) - -static void -suil_qt_wrapper_finalize(GObject* gobject) -{ - SuilQtWrapper* const self = SUIL_QT_WRAPPER(gobject); - - if (self->instance->handle) { - self->instance->descriptor->cleanup(self->instance->handle); - self->instance->handle = nullptr; - } - - delete self->qembed; - - self->qembed = nullptr; - self->app = nullptr; - self->wrapper->impl = nullptr; - - G_OBJECT_CLASS(suil_qt_wrapper_parent_class)->finalize(gobject); -} - -static void -suil_qt_wrapper_class_init(SuilQtWrapperClass* klass) -{ - GObjectClass* const gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->finalize = suil_qt_wrapper_finalize; -} - -static void -suil_qt_wrapper_init(SuilQtWrapper* self) -{ - self->app = nullptr; - self->qembed = nullptr; - self->instance = nullptr; -} - -static void -suil_qt_wrapper_realize(GtkWidget* w, gpointer data) -{ - SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(w); - GtkSocket* const s = GTK_SOCKET(w); - - gtk_socket_add_id(s, wrap->qembed->winId()); - wrap->qembed->show(); -} - -static int -wrapper_wrap(SuilWrapper* wrapper, SuilInstance* instance) -{ - SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(wrapper->impl); - - wrap->qembed = new QX11EmbedWidget(); - wrap->wrapper = wrapper; - wrap->instance = instance; - - QWidget* qwidget = (QWidget*)instance->ui_widget; - QVBoxLayout* layout = new QVBoxLayout(wrap->qembed); - layout->addWidget(qwidget); - - qwidget->setParent(wrap->qembed); - - g_signal_connect_after( - G_OBJECT(wrap), "realize", G_CALLBACK(suil_qt_wrapper_realize), nullptr); - - instance->host_widget = GTK_WIDGET(wrap); - - return 0; -} - -static void -wrapper_free(SuilWrapper* wrapper) -{ - if (wrapper->impl) { - SuilQtWrapper* const wrap = SUIL_QT_WRAPPER(wrapper->impl); - gtk_object_destroy(GTK_OBJECT(wrap)); - } -} - -SUIL_LIB_EXPORT -SuilWrapper* -suil_wrapper_new(SuilHost* host, - const char* host_type_uri, - const char* ui_type_uri, - LV2_Feature*** features, - unsigned n_features) -{ - SuilWrapper* wrapper = (SuilWrapper*)calloc(1, sizeof(SuilWrapper)); - wrapper->wrap = wrapper_wrap; - wrapper->free = wrapper_free; - - SuilQtWrapper* const wrap = - SUIL_QT_WRAPPER(g_object_new(SUIL_TYPE_QT_WRAPPER, nullptr)); - - if (qApp) { - wrap->app = qApp; - } else { - wrap->app = new QApplication(host->argc, host->argv, true); - } - - wrap->wrapper = nullptr; - wrapper->impl = wrap; - - return wrapper; -} - -} // extern "C" diff --git a/src/x11_in_qt4.cpp b/src/x11_in_qt4.cpp deleted file mode 100644 index a7de272..0000000 --- a/src/x11_in_qt4.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - Copyright 2011-2015 David Robillard <d@drobilla.net> - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include "suil_config.h" -#include "suil_internal.h" - -#include <QX11EmbedContainer> -#include <QtEvents> - -#undef signals - -extern "C" { - -struct SuilX11InQt4Wrapper { - QX11EmbedContainer* host_widget; - QX11EmbedWidget* parent; -}; - -class SuilQX11Container : public QX11EmbedContainer -{ -public: - SuilQX11Container(SuilInstance* instance, - const LV2UI_Idle_Interface* idle_iface, - QX11EmbedWidget* widget) - : QX11EmbedContainer() - , _instance(instance) - , _idle_iface(idle_iface) - , _widget(widget) - , _ui_timer(0) - {} - -protected: - void showEvent(QShowEvent* event) - { - if (_idle_iface && _ui_timer == 0) { - _ui_timer = this->startTimer(30); - _widget->embedInto(winId()); - resize(_widget->size()); - } - QX11EmbedContainer::showEvent(event); - } - - void timerEvent(QTimerEvent* event) - { - if (event->timerId() == _ui_timer && _idle_iface) { - _idle_iface->idle(_instance->handle); - } - QX11EmbedContainer::timerEvent(event); - } - - void closeEvent(QCloseEvent* event) - { - if (_ui_timer && _idle_iface) { - this->killTimer(_ui_timer); - _ui_timer = 0; - } - QX11EmbedContainer::closeEvent(event); - } - -private: - SuilInstance* const _instance; - const LV2UI_Idle_Interface* const _idle_iface; - QX11EmbedWidget* const _widget; - int _ui_timer; -}; - -static void -wrapper_free(SuilWrapper* wrapper) -{ - SuilX11InQt4Wrapper* impl = (SuilX11InQt4Wrapper*)wrapper->impl; - - if (impl->parent) { - delete impl->parent; - } - - if (impl->host_widget) { - delete impl->host_widget; - } - - free(impl); -} - -static int -wrapper_wrap(SuilWrapper* wrapper, SuilInstance* instance) -{ - const LV2UI_Idle_Interface* idle_iface = nullptr; - if (instance->descriptor->extension_data) { - idle_iface = - (const LV2UI_Idle_Interface*)instance->descriptor->extension_data( - LV2_UI__idleInterface); - } - - SuilX11InQt4Wrapper* const impl = (SuilX11InQt4Wrapper*)wrapper->impl; - QX11EmbedWidget* const ew = impl->parent; - - impl->host_widget = new SuilQX11Container(instance, idle_iface, ew); - - instance->host_widget = impl->host_widget; - - return 0; -} - -static int -wrapper_resize(LV2UI_Feature_Handle handle, int width, int height) -{ - QX11EmbedWidget* const ew = (QX11EmbedWidget*)handle; - ew->resize(width, height); - return 0; -} - -SUIL_LIB_EXPORT -SuilWrapper* -suil_wrapper_new(SuilHost* host, - const char* host_type_uri, - const char* ui_type_uri, - LV2_Feature*** features, - unsigned n_features) -{ - SuilX11InQt4Wrapper* const impl = - (SuilX11InQt4Wrapper*)calloc(1, sizeof(SuilX11InQt4Wrapper)); - - SuilWrapper* wrapper = (SuilWrapper*)calloc(1, sizeof(SuilWrapper)); - wrapper->wrap = wrapper_wrap; - wrapper->free = wrapper_free; - - QX11EmbedWidget* const ew = new QX11EmbedWidget(); - - impl->parent = ew; - - wrapper->impl = impl; - wrapper->resize.handle = ew; - wrapper->resize.ui_resize = wrapper_resize; - - const intptr_t parent_id = (intptr_t)ew->winId(); - suil_add_feature(features, &n_features, LV2_UI__parent, (void*)parent_id); - suil_add_feature(features, &n_features, LV2_UI__resize, &wrapper->resize); - suil_add_feature(features, &n_features, LV2_UI__idleInterface, nullptr); - - return wrapper; -} - -} // extern "C" |