2 Copyright (C) 2004 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <gtk/gtksocket.h>
23 #include "gtkmm2ext/gui_thread.h"
25 #include "ardour/plugin_insert.h"
26 #include "ardour/windows_vst_plugin.h"
28 #include "windows_vst_plugin_ui.h"
30 #ifdef PLATFORM_WINDOWS
31 #include <gdk/gdkwin32.h>
32 #elif defined __APPLE__
39 using namespace ARDOUR;
42 WindowsVSTPluginUI::WindowsVSTPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VSTPlugin> vp, GtkWidget *parent)
43 : VSTPluginUI (pi, vp)
46 #ifdef GDK_WINDOWING_WIN32
47 gtk_widget_realize(parent);
48 void* hWndHost = gdk_win32_drawable_get_handle(parent->window);
50 fst_run_editor (_vst->state(), hWndHost);
51 // TODO pack a placeholder (compare to VSTPluginUI::VSTPluginUI X11 socket)
52 // have placeholder use VSTPluginUI::get_preferred_height(), width()
53 // TODO pack plugin_analysis_expander at the bottom.
55 fst_run_editor (_vst->state(), NULL);
56 pack_start (plugin_analysis_expander, true, true);
60 WindowsVSTPluginUI::~WindowsVSTPluginUI ()
62 fst_destroy_editor (_vst->state());
64 // plugin destructor destroys the custom GUI, via Windows fun-and-games,
65 // and then our PluginUIWindow does the rest
69 WindowsVSTPluginUI::top_box_allocated (Gtk::Allocation& a)
71 int h = a.get_height() + 12; // 2 * 6px spacing
72 if (_vst->state()->voffset != h) {
74 printf("WindowsVSTPluginUI:: update voffset to %d px\n", h);
76 _vst->state()->voffset = h;
82 WindowsVSTPluginUI::resize_callback ()
84 void* gtk_parent_window = _vst->state()->gtk_window_parent;
85 if (gtk_parent_window) {
86 int width = _vst->state()->width + _vst->state()->hoffset;
87 int height = _vst->state()->height + _vst->state()->voffset;
89 printf ("WindowsVSTPluginUI::resize_callback %d x %d\n", width, height);
91 set_size_request (width, height);
92 ((Gtk::Window*) gtk_parent_window)->set_size_request (width, height);
93 ((Gtk::Window*) gtk_parent_window)->resize (width, height);
94 fst_move_window_into_view (_vst->state ());
99 WindowsVSTPluginUI::package (Gtk::Window& win)
102 printf ("WindowsVSTPluginUI::package\n");
104 VSTPluginUI::package (win);
105 _vst->state()->gtk_window_parent = (void*) (&win);
107 _vst->VSTSizeWindow.connect (_resize_connection, invalidator (*this), boost::bind (&WindowsVSTPluginUI::resize_callback, this), gui_context());
115 WindowsVSTPluginUI::forward_key_event (GdkEventKey* ev)
117 if (ev->type != GDK_KEY_PRESS) {
121 VSTState* fst = _vst->state ();
122 pthread_mutex_lock (&fst->lock);
124 if (fst->n_pending_keys == (sizeof (fst->pending_keys) * sizeof (VSTKey))) {
129 int special_windows_key = 0;
130 int character_windows_key = 0;
132 switch (ev->keyval) {
134 special_windows_key = 0x25;
137 special_windows_key = 0x27;
140 special_windows_key = 0x26;
143 special_windows_key = 0x28;
147 special_windows_key = 0xd;
150 character_windows_key = ev->keyval;
154 fst->pending_keys[fst->n_pending_keys].special = special_windows_key;
155 fst->pending_keys[fst->n_pending_keys].character = character_windows_key;
156 fst->n_pending_keys++;
158 pthread_mutex_unlock (&fst->lock);
162 WindowsVSTPluginUI::get_XID ()
164 return _vst->state()->xid;
167 #ifdef GDK_WINDOWING_X11
168 typedef int (*error_handler_t)( Display *, XErrorEvent *);
169 static Display *the_gtk_display;
170 static error_handler_t wine_error_handler;
171 static error_handler_t gtk_error_handler;
174 fst_xerror_handler (Display* disp, XErrorEvent* ev)
176 if (disp == the_gtk_display) {
177 printf ("relaying error to gtk\n");
178 return gtk_error_handler (disp, ev);
180 printf( "relaying error to wine\n" );
181 return wine_error_handler (disp, ev);
187 windows_vst_gui_init (int *argc, char **argv[])
189 gtk_init (argc, argv);
191 #ifdef GDK_WINDOWING_X11
192 wine_error_handler = XSetErrorHandler (NULL);
193 the_gtk_display = gdk_x11_display_get_xdisplay (gdk_display_get_default());
194 gtk_error_handler = XSetErrorHandler (fst_xerror_handler);