continuing fixes to get this shibboleth to compile
[ardour.git] / gtk2_ardour / vst_pluginui.cc
1 /*
2     Copyright (C) 2004 Paul Davis 
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #include <fst.h>
22 #include <gdk/gdkx.h>
23 #include <X11/Xlib.h>
24
25 #include <ardour/insert.h>
26 #include <ardour/vst_plugin.h>
27
28 #include "plugin_ui.h"
29 #include "prompter.h"
30
31 #include "i18n.h"
32
33 using namespace Gtk;
34 using namespace ARDOUR;
35
36 VSTPluginUI::VSTPluginUI (PluginInsert& pi, VSTPlugin& vp)
37         : PlugUIBase (pi),
38           vst (vp)
39 {
40         fst_run_editor (vst.fst());
41
42         preset_box.pack_end (bypass_button, false, false, 10);
43         preset_box.pack_end (save_button, false, false);
44         preset_box.pack_end (combo, false, false);
45
46         bypass_button.set_active (!insert.active());
47         
48         pack_start (preset_box, false, false);
49         pack_start (socket, true, true);
50 }
51
52 VSTPluginUI::~VSTPluginUI ()
53 {
54         // nothing to do here - plugin destructor destroys the GUI
55 }
56
57 int
58 VSTPluginUI::get_preferred_height ()
59 {
60         return vst.fst()->height;
61 }
62
63 int
64 VSTPluginUI::package (Gtk::Window& win)
65 {
66         /* for GTK+2, remove this: you cannot add to a realized socket */
67
68         socket.realize ();
69
70         /* forward configure events to plugin window */
71
72         win.signal_configure_event().connect (bind (mem_fun (*this, &VSTPluginUI::configure_handler), socket.gobj()));
73
74         /* XXX in GTK2, use add_id() instead of steal, although add_id()
75            assumes that the window's owner understands the XEmbed protocol.
76         */
77         
78         socket.steal (fst_get_XID (vst.fst()));
79
80         return 0;
81 }
82
83 gboolean
84 VSTPluginUI::configure_handler (GdkEventConfigure* ev, GtkSocket *socket)
85 {
86         XEvent event;
87
88         gint x, y;
89
90         if (socket->plug_window == NULL) {
91                 return FALSE;
92         }
93
94         event.xconfigure.type = ConfigureNotify;
95         event.xconfigure.event = GDK_WINDOW_XWINDOW (socket->plug_window);
96         event.xconfigure.window = GDK_WINDOW_XWINDOW (socket->plug_window);
97
98         /* The ICCCM says that synthetic events should have root relative
99          * coordinates. We still aren't really ICCCM compliant, since
100          * we don't send events when the real toplevel is moved.
101          */
102         gdk_error_trap_push ();
103         gdk_window_get_origin (socket->plug_window, &x, &y);
104         gdk_error_trap_pop ();
105
106         event.xconfigure.x = x;
107         event.xconfigure.y = y;
108         event.xconfigure.width = GTK_WIDGET(socket)->allocation.width;
109         event.xconfigure.height = GTK_WIDGET(socket)->allocation.height;
110
111         event.xconfigure.border_width = 0;
112         event.xconfigure.above = None;
113         event.xconfigure.override_redirect = False;
114
115         gdk_error_trap_push ();
116         XSendEvent (GDK_WINDOW_XDISPLAY (socket->plug_window),
117                     GDK_WINDOW_XWINDOW (socket->plug_window),
118                     False, StructureNotifyMask, &event);
119         // gdk_display_sync (GDK_WINDOW_XDISPLAY (socket->plug_window));
120         gdk_error_trap_pop ();
121
122         return FALSE;
123 }
124