From 18e198aba98f11f62f1cc4b5cf6494d686b25a90 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 9 Aug 2012 04:07:41 +0000 Subject: Fix Windows build. git-svn-id: http://svn.drobilla.net/lad/trunk/suil@4638 a436a847-0d15-0410-975c-d299462d15a1 --- src/suil_internal.h | 1 + src/win_in_gtk2.c | 161 -------------------------------------------------- src/win_in_gtk2.cpp | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++ wscript | 2 +- 4 files changed, 167 insertions(+), 162 deletions(-) delete mode 100644 src/win_in_gtk2.c create mode 100644 src/win_in_gtk2.cpp diff --git a/src/suil_internal.h b/src/suil_internal.h index b72c545..62a5ace 100644 --- a/src/suil_internal.h +++ b/src/suil_internal.h @@ -94,6 +94,7 @@ typedef SuilWrapper* (*SuilWrapperNewFunc)(SuilHost* host, unsigned n_features); /** Prototype for suil_wrapper_new in each module. */ +SUIL_API SuilWrapper* suil_wrapper_new(SuilHost* host, const char* host_type_uri, diff --git a/src/win_in_gtk2.c b/src/win_in_gtk2.c deleted file mode 100644 index 159639a..0000000 --- a/src/win_in_gtk2.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - Copyright 2011-2012 David Robillard - - 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 - -#include -#include - -#include "./suil_internal.h" - -#define SUIL_TYPE_WIN_WRAPPER (suil_win_wrapper_get_type()) -#define SUIL_WIN_WRAPPER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SUIL_TYPE_WIN_WRAPPER, SuilWinWrapper)) - -typedef struct _SuilWinWrapper SuilWinWrapper; -typedef struct _SuilWinWrapperClass SuilWinWrapperClass; - -struct _SuilWinWrapper { - GtkDrawingArea area; - SuilWrapper* wrapper; - SuilInstance* instance; -}; - -struct _SuilWinWrapperClass { - GtkDrawingAreaClass parent_class; -}; - -GType suil_win_wrapper_get_type(void); // Accessor for SUIL_TYPE_WIN_WRAPPER - -G_DEFINE_TYPE(SuilWinWrapper, suil_win_wrapper, GTK_TYPE_DRAWING_AREA) - -static void -suil_win_wrapper_finalize(GObject* gobject) -{ - SuilWinWrapper* const self = SUIL_WIN_WRAPPER(gobject); - - self->wrapper->impl = NULL; - - G_OBJECT_CLASS(suil_win_wrapper_parent_class)->finalize(gobject); -} - -static void -suil_win_wrapper_class_init(SuilWinWrapperClass* klass) -{ - GObjectClass* const gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->finalize = suil_win_wrapper_finalize; -} - -static void -suil_win_wrapper_init(SuilWinWrapper* self) -{ - self->instance = NULL; -} - -static int -wrapper_resize(LV2UI_Feature_Handle handle, int width, int height) -{ - gtk_drawing_area_size(GTK_DRAWING_AREA(handle), width, height); - return 0; -} - -static int -wrapper_wrap(SuilWrapper* wrapper, - SuilInstance* instance) -{ - SuilWinWrapper* const wrap = SUIL_WIN_WRAPPER(wrapper->impl); - - instance->host_widget = GTK_WIDGET(wrap); - wrap->wrapper = wrapper; - wrap->instance = instance; - - return 0; -} - -static void -wrapper_free(SuilWrapper* wrapper) -{ - if (wrapper->impl) { - SuilWinWrapper* const wrap = SUIL_WIN_WRAPPER(wrapper->impl); - gtk_object_destroy(GTK_OBJECT(wrap)); - } -} - -static GdkFilterReturn -event_filter(GdkXEvent* xevent, GdkEvent* event, gpointer data) -{ - SuilWinWrapper* wrap = (SuilWinWrapper*)data; - MSG* msg = (MSG*)xevent; - if (msg->message == WM_KEYDOWN || msg->message == WM_KEYUP) { - // Forward keyboard events to UI window - PostMessage((HWND)wrap->instance->ui_widget, - msg->message, msg->wParam, msg->lParam); - } - return GDK_FILTER_CONTINUE; -} - -SUIL_API -SuilWrapper* -suil_wrapper_new(SuilHost* host, - const char* host_type_uri, - const char* ui_type_uri, - LV2_Feature*** features, - unsigned n_features) -{ - GtkWidget* parent = NULL; - for (unsigned i = 0; i < n_features; ++i) { - if (!strcmp((*features)[i]->URI, LV2_UI__parent)) { - parent = (GtkWidget*)(*features)[i]->data; - } - } - - if (!GTK_CONTAINER(parent)) { - SUIL_ERRORF("No GtkContainer parent given for %s UI\n", - ui_type_uri); - return NULL; - } - - SuilWrapper* wrapper = (SuilWrapper*)malloc(sizeof(SuilWrapper)); - wrapper->wrap = wrapper_wrap; - wrapper->free = wrapper_free; - - SuilWinWrapper* const wrap = SUIL_WIN_WRAPPER( - g_object_new(SUIL_TYPE_WIN_WRAPPER, NULL)); - - wrap->wrapper = NULL; - - wrapper->impl = wrap; - wrapper->resize.handle = wrap; - wrapper->resize.ui_resize = wrapper_resize; - - gtk_container_add(GTK_CONTAINER(parent), GTK_WIDGET(wrap)); - gtk_widget_set_can_focus(GTK_WIDGET(wrap), TRUE); - gtk_widget_set_sensitive(GTK_WIDGET(wrap), TRUE); - gtk_widget_realize(GTK_WIDGET(wrap)); - - GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(wrap)); - GdkWindow* parent_window = gtk_widget_get_window(parent); - gdk_window_add_filter(parent_window, event_filter, wrap); - gdk_window_add_filter(window, event_filter, wrap); - - suil_add_feature(features, &n_features, LV2_UI__parent, - GDK_WINDOW_HWND(window)); - - suil_add_feature(features, &n_features, LV2_UI__resize, - &wrapper->resize); - - return wrapper; -} diff --git a/src/win_in_gtk2.cpp b/src/win_in_gtk2.cpp new file mode 100644 index 0000000..3e0d12c --- /dev/null +++ b/src/win_in_gtk2.cpp @@ -0,0 +1,165 @@ +/* + Copyright 2011-2012 David Robillard + + 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 + +#include +#include + +#include "./suil_internal.h" + +extern "C" { + +#define SUIL_TYPE_WIN_WRAPPER (suil_win_wrapper_get_type()) +#define SUIL_WIN_WRAPPER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), SUIL_TYPE_WIN_WRAPPER, SuilWinWrapper)) + +typedef struct _SuilWinWrapper SuilWinWrapper; +typedef struct _SuilWinWrapperClass SuilWinWrapperClass; + +struct _SuilWinWrapper { + GtkDrawingArea area; + SuilWrapper* wrapper; + SuilInstance* instance; +}; + +struct _SuilWinWrapperClass { + GtkDrawingAreaClass parent_class; +}; + +GType suil_win_wrapper_get_type(void); // Accessor for SUIL_TYPE_WIN_WRAPPER + +G_DEFINE_TYPE(SuilWinWrapper, suil_win_wrapper, GTK_TYPE_DRAWING_AREA) + +static void +suil_win_wrapper_finalize(GObject* gobject) +{ + SuilWinWrapper* const self = SUIL_WIN_WRAPPER(gobject); + + self->wrapper->impl = NULL; + + G_OBJECT_CLASS(suil_win_wrapper_parent_class)->finalize(gobject); +} + +static void +suil_win_wrapper_class_init(SuilWinWrapperClass* klass) +{ + GObjectClass* const gobject_class = G_OBJECT_CLASS(klass); + + gobject_class->finalize = suil_win_wrapper_finalize; +} + +static void +suil_win_wrapper_init(SuilWinWrapper* self) +{ + self->instance = NULL; +} + +static int +wrapper_resize(LV2UI_Feature_Handle handle, int width, int height) +{ + gtk_drawing_area_size(GTK_DRAWING_AREA(handle), width, height); + return 0; +} + +static int +wrapper_wrap(SuilWrapper* wrapper, + SuilInstance* instance) +{ + SuilWinWrapper* const wrap = SUIL_WIN_WRAPPER(wrapper->impl); + + instance->host_widget = GTK_WIDGET(wrap); + wrap->wrapper = wrapper; + wrap->instance = instance; + + return 0; +} + +static void +wrapper_free(SuilWrapper* wrapper) +{ + if (wrapper->impl) { + SuilWinWrapper* const wrap = SUIL_WIN_WRAPPER(wrapper->impl); + gtk_object_destroy(GTK_OBJECT(wrap)); + } +} + +static GdkFilterReturn +event_filter(GdkXEvent* xevent, GdkEvent* event, gpointer data) +{ + SuilWinWrapper* wrap = (SuilWinWrapper*)data; + MSG* msg = (MSG*)xevent; + if (msg->message == WM_KEYDOWN || msg->message == WM_KEYUP) { + // Forward keyboard events to UI window + PostMessage((HWND)wrap->instance->ui_widget, + msg->message, msg->wParam, msg->lParam); + } + return GDK_FILTER_CONTINUE; +} + +SUIL_API +SuilWrapper* +suil_wrapper_new(SuilHost* host, + const char* host_type_uri, + const char* ui_type_uri, + LV2_Feature*** features, + unsigned n_features) +{ + GtkWidget* parent = NULL; + for (unsigned i = 0; i < n_features; ++i) { + if (!strcmp((*features)[i]->URI, LV2_UI__parent)) { + parent = (GtkWidget*)(*features)[i]->data; + } + } + + if (!GTK_CONTAINER(parent)) { + SUIL_ERRORF("No GtkContainer parent given for %s UI\n", + ui_type_uri); + return NULL; + } + + SuilWrapper* wrapper = (SuilWrapper*)malloc(sizeof(SuilWrapper)); + wrapper->wrap = wrapper_wrap; + wrapper->free = wrapper_free; + + SuilWinWrapper* const wrap = SUIL_WIN_WRAPPER( + g_object_new(SUIL_TYPE_WIN_WRAPPER, NULL)); + + wrap->wrapper = NULL; + + wrapper->impl = wrap; + wrapper->resize.handle = wrap; + wrapper->resize.ui_resize = wrapper_resize; + + gtk_container_add(GTK_CONTAINER(parent), GTK_WIDGET(wrap)); + gtk_widget_set_can_focus(GTK_WIDGET(wrap), TRUE); + gtk_widget_set_sensitive(GTK_WIDGET(wrap), TRUE); + gtk_widget_realize(GTK_WIDGET(wrap)); + + GdkWindow* window = gtk_widget_get_window(GTK_WIDGET(wrap)); + GdkWindow* parent_window = gtk_widget_get_window(parent); + gdk_window_add_filter(parent_window, event_filter, wrap); + gdk_window_add_filter(window, event_filter, wrap); + + suil_add_feature(features, &n_features, LV2_UI__parent, + GDK_WINDOW_HWND(window)); + + suil_add_feature(features, &n_features, LV2_UI__resize, + &wrapper->resize); + + return wrapper; +} + +} // extern "C" diff --git a/wscript b/wscript index 813d014..b74917d 100644 --- a/wscript +++ b/wscript @@ -184,7 +184,7 @@ def build(bld): if bld.is_defined('HAVE_GTK2') and sys.platform == 'win32': obj = bld(features = 'cxx cxxshlib', - source = 'src/win_in_gtk2.c', + source = 'src/win_in_gtk2.cpp', target = 'suil_win_in_gtk2', includes = ['.'], defines = ['SUIL_SHARED', 'SUIL_INTERNAL'], -- cgit v1.2.1