7adf702f4d38a843fbeb7a3f75188623e96ad0a5
[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 <gtk/gtksocket.h>
23 #include <ardour/insert.h>
24 #include <ardour/vst_plugin.h>
25
26 #include "plugin_ui.h"
27
28 #include <gdk/gdkx.h>
29
30 using namespace Gtk;
31 using namespace ARDOUR;
32 using namespace PBD;
33
34 VSTPluginUI::VSTPluginUI (PluginInsert& pi, VSTPlugin& vp)
35         : PlugUIBase (pi),
36           vst (vp)
37 {
38         fst_run_editor (vst.fst());
39
40         preset_box.pack_end (bypass_button, false, false, 10);
41         preset_box.pack_end (save_button, false, false);
42         preset_box.pack_end (combo, false, false);
43
44         bypass_button.set_active (!insert.active());
45         
46         pack_start (preset_box, false, false);
47         pack_start (socket, true, true);
48 }
49
50 VSTPluginUI::~VSTPluginUI ()
51 {
52         // nothing to do here - plugin destructor destroys the GUI
53 }
54
55 int
56 VSTPluginUI::get_preferred_height ()
57 {
58         return vst.fst()->height;
59 }
60
61 int
62 VSTPluginUI::package (Gtk::Window& win)
63 {
64         /* forward configure events to plugin window */
65
66         win.signal_configure_event().connect (bind (mem_fun (*this, &VSTPluginUI::configure_handler), &socket), false);
67
68         /*
69            this assumes that the window's owner understands the XEmbed protocol.
70         */
71         
72         socket.add_id (fst_get_XID (vst.fst()));
73
74         return 0;
75 }
76
77 bool
78 VSTPluginUI::configure_handler (GdkEventConfigure* ev, Gtk::Socket *socket)
79 {
80         XEvent event;
81         gint x, y;
82         GdkWindow* w;
83
84         if (socket == 0 || ((w = socket->gobj()->plug_window) == 0)) {
85                 return false;
86         }
87
88         event.xconfigure.type = ConfigureNotify;
89         event.xconfigure.event = GDK_WINDOW_XWINDOW (w);
90         event.xconfigure.window = GDK_WINDOW_XWINDOW (w);
91
92         /* The ICCCM says that synthetic events should have root relative
93          * coordinates. We still aren't really ICCCM compliant, since
94          * we don't send events when the real toplevel is moved.
95          */
96         gdk_error_trap_push ();
97         gdk_window_get_origin (w, &x, &y);
98         gdk_error_trap_pop ();
99
100         event.xconfigure.x = x;
101         event.xconfigure.y = y;
102         event.xconfigure.width = GTK_WIDGET(socket->gobj())->allocation.width;
103         event.xconfigure.height = GTK_WIDGET(socket->gobj())->allocation.height;
104
105         event.xconfigure.border_width = 0;
106         event.xconfigure.above = None;
107         event.xconfigure.override_redirect = False;
108
109         gdk_error_trap_push ();
110         XSendEvent (GDK_WINDOW_XDISPLAY (w), GDK_WINDOW_XWINDOW (w), False, StructureNotifyMask, &event);
111         gdk_error_trap_pop ();
112
113         return false;
114 }
115