summaryrefslogtreecommitdiffstats
path: root/src/qt4_in_gtk2.cpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-02-23 07:33:14 +0000
committerDavid Robillard <d@drobilla.net>2011-02-23 07:33:14 +0000
commit4c3595e41c0e6955f667cbcfc43c0e9c3c99136e (patch)
treeb5eaf9f4a3f8c6f1a81cfdd8b5bc9770af03c673 /src/qt4_in_gtk2.cpp
parentfcf7bfe09eb7d4b9a0445ae6f0ac2e933a260189 (diff)
downloadsuil-4c3595e41c0e6955f667cbcfc43c0e9c3c99136e.tar.gz
suil-4c3595e41c0e6955f667cbcfc43c0e9c3c99136e.tar.bz2
suil-4c3595e41c0e6955f667cbcfc43c0e9c3c99136e.zip
Support for wrapping Qt4 UIs for Gtk2 hosts and vice versa via modules.
Qt4 in Gtk2 is tested working (Float in Ingen). Gtk2 in Qt4 is untested (and thus unlikely to work yet). git-svn-id: http://svn.drobilla.net/lad/trunk/suil@3016 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/qt4_in_gtk2.cpp')
-rw-r--r--src/qt4_in_gtk2.cpp146
1 files changed, 146 insertions, 0 deletions
diff --git a/src/qt4_in_gtk2.cpp b/src/qt4_in_gtk2.cpp
new file mode 100644
index 0000000..bdacbbd
--- /dev/null
+++ b/src/qt4_in_gtk2.cpp
@@ -0,0 +1,146 @@
+/* Suil, an LV2 plugin UI hosting library.
+ * Copyright 2011 David Robillard <d@drobilla.net>
+ *
+ * Suil is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Suil is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtk/gtk.h>
+
+#include <QApplication>
+#include <QX11EmbedWidget>
+#include <QVBoxLayout>
+
+#include "suil_internal.h"
+
+extern "C" {
+
+static int argc = 0;
+static QApplication application(argc, NULL, true);
+
+SUIL_API
+int
+suil_wrap_init(const char* host_type_uri,
+ const char* ui_type_uri,
+ const LV2_Feature* const* features)
+{
+ return 0;
+}
+
+#define WRAP_TYPE_WIDGET (wrap_widget_get_type())
+#define WRAP_WIDGET(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), WRAP_TYPE_WIDGET, WrapWidget))
+#define WRAP_WIDGET_GET_PRIVATE(obj) \
+ G_TYPE_INSTANCE_GET_PRIVATE((obj), \
+ WRAP_TYPE_WIDGET, \
+ WrapWidgetPrivate)
+
+typedef struct _WrapWidget WrapWidget;
+typedef struct _WrapWidgetClass WrapWidgetClass;
+typedef struct _WrapWidgetPrivate WrapWidgetPrivate;
+
+struct _WrapWidget {
+ GtkSocket parent_instance;
+
+ WrapWidgetPrivate* priv;
+};
+
+struct _WrapWidgetClass {
+ GtkSocketClass parent_class;
+};
+
+GType wrap_widget_get_type(void); // Accessor for GTK_TYPE_WIDGET
+
+struct _WrapWidgetPrivate {
+ QX11EmbedWidget* qembed;
+ SuilInstance instance;
+};
+
+G_DEFINE_TYPE(WrapWidget, wrap_widget, GTK_TYPE_SOCKET);
+
+static void
+wrap_widget_dispose(GObject* gobject)
+{
+ WrapWidget* const self = WRAP_WIDGET(gobject);
+ WrapWidgetPrivate* const priv = WRAP_WIDGET_GET_PRIVATE(self);
+
+ if (priv->qembed) {
+ QWidget* const qwidget = (QWidget*)priv->instance->ui_widget;
+ qwidget->setParent(NULL);
+
+ delete self->priv->qembed;
+ self->priv->qembed = NULL;
+ }
+
+ G_OBJECT_CLASS(wrap_widget_parent_class)->dispose(gobject);
+}
+
+static void
+wrap_widget_class_init(WrapWidgetClass* klass)
+{
+ GObjectClass* const gobject_class = G_OBJECT_CLASS(klass);
+
+ gobject_class->dispose = wrap_widget_dispose;
+
+ g_type_class_add_private(klass, sizeof(WrapWidgetPrivate));
+}
+
+static void
+wrap_widget_init(WrapWidget* self)
+{
+ WrapWidgetPrivate* const priv = WRAP_WIDGET_GET_PRIVATE(self);
+ priv->qembed = NULL;
+ priv->instance = NULL;
+ self->priv = priv;
+}
+
+static void
+wrap_widget_realize(GtkWidget* w, gpointer data)
+{
+ WrapWidget* const wrap = WRAP_WIDGET(w);
+ GtkSocket* const s = GTK_SOCKET(w);
+ WrapWidgetPrivate* const priv = wrap->priv;
+
+ gtk_socket_add_id(s, priv->qembed->winId());
+ priv->qembed->show();
+}
+
+SUIL_API
+int
+suil_wrap(const char* host_type_uri,
+ const char* ui_type_uri,
+ SuilInstance instance)
+{
+ WrapWidget* const wrap = WRAP_WIDGET(g_object_new(WRAP_TYPE_WIDGET, NULL));
+
+ WrapWidgetPrivate* const priv = wrap->priv;
+ priv->qembed = new QX11EmbedWidget();
+ priv->instance = instance;
+
+ QWidget* qwidget = (QWidget*)instance->ui_widget;
+ QVBoxLayout* layout = new QVBoxLayout(priv->qembed);
+ layout->addWidget(qwidget);
+
+ qwidget->setParent(priv->qembed);
+
+ g_signal_connect_after(G_OBJECT(wrap),
+ "realize",
+ G_CALLBACK(wrap_widget_realize),
+ NULL);
+
+ instance->host_widget = GTK_WIDGET(wrap);
+
+ return 0;
+}
+
+} // extern "C"