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