Clean up region.h and trim include tree.
[ardour2.git] / gtk2_ardour / vst_pluginui.cc
blobb6902445f367d2d2199ac5f20c3e542dd3f3c3e3
1 /*
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.
20 #include <fst.h>
21 #include <gtk/gtk.h>
22 #include <gtk/gtksocket.h>
23 #include "ardour/plugin_insert.h"
24 #include "ardour/vst_plugin.h"
26 #include "vst_pluginui.h"
28 #include <gdk/gdkx.h>
30 using namespace Gtk;
31 using namespace ARDOUR;
32 using namespace PBD;
34 VSTPluginUI::VSTPluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<VSTPlugin> vp)
35 : PlugUIBase (pi),
36 vst (vp)
38 fst_run_editor (vst->fst());
40 preset_box.set_spacing (6);
41 preset_box.set_border_width (6);
42 preset_box.pack_end (bypass_button, false, false, 10);
43 preset_box.pack_end (delete_button, false, false);
44 preset_box.pack_end (save_button, false, false);
45 preset_box.pack_end (add_button, false, false);
46 preset_box.pack_end (_preset_box, false, false);
48 bypass_button.set_active (!insert->active());
50 pack_start (preset_box, false, false);
51 pack_start (socket, true, true);
52 pack_start (plugin_analysis_expander, true, true);
55 VSTPluginUI::~VSTPluginUI ()
57 // plugin destructor destroys the custom GUI, via Windows fun-and-games,
58 // and then our PluginUIWindow does the rest
61 void
62 VSTPluginUI::preset_selected ()
64 socket.grab_focus ();
65 PlugUIBase::preset_selected ();
68 int
69 VSTPluginUI::get_preferred_height ()
71 return vst->fst()->height;
74 int
75 VSTPluginUI::get_preferred_width ()
77 return vst->fst()->width;
80 int
81 VSTPluginUI::package (Gtk::Window& win)
83 /* forward configure events to plugin window */
85 win.signal_configure_event().connect (sigc::bind (sigc::mem_fun (*this, &VSTPluginUI::configure_handler), &socket), false);
88 this assumes that the window's owner understands the XEmbed protocol.
91 socket.add_id (fst_get_XID (vst->fst()));
93 fst_move_window_into_view (vst->fst());
95 return 0;
98 bool
99 VSTPluginUI::configure_handler (GdkEventConfigure* ev, Gtk::Socket *socket)
101 XEvent event;
102 gint x, y;
103 GdkWindow* w;
105 if (socket == 0 || ((w = socket->gobj()->plug_window) == 0)) {
106 return false;
109 event.xconfigure.type = ConfigureNotify;
110 event.xconfigure.event = GDK_WINDOW_XWINDOW (w);
111 event.xconfigure.window = GDK_WINDOW_XWINDOW (w);
113 /* The ICCCM says that synthetic events should have root relative
114 * coordinates. We still aren't really ICCCM compliant, since
115 * we don't send events when the real toplevel is moved.
117 gdk_error_trap_push ();
118 gdk_window_get_origin (w, &x, &y);
119 gdk_error_trap_pop ();
121 event.xconfigure.x = x;
122 event.xconfigure.y = y;
123 event.xconfigure.width = GTK_WIDGET(socket->gobj())->allocation.width;
124 event.xconfigure.height = GTK_WIDGET(socket->gobj())->allocation.height;
126 event.xconfigure.border_width = 0;
127 event.xconfigure.above = None;
128 event.xconfigure.override_redirect = False;
130 gdk_error_trap_push ();
131 XSendEvent (GDK_WINDOW_XDISPLAY (w), GDK_WINDOW_XWINDOW (w), False, StructureNotifyMask, &event);
132 gdk_error_trap_pop ();
134 return false;
137 typedef int (*error_handler_t)( Display *, XErrorEvent *);
138 static Display *the_gtk_display;
139 static error_handler_t wine_error_handler;
140 static error_handler_t gtk_error_handler;
142 static int
143 fst_xerror_handler( Display *disp, XErrorEvent *ev )
145 if (disp == the_gtk_display) {
146 printf ("relaying error to gtk\n");
147 return gtk_error_handler (disp, ev);
148 } else {
149 printf( "relaying error to wine\n" );
150 return wine_error_handler (disp, ev);
154 void
155 gui_init (int *argc, char **argv[])
157 wine_error_handler = XSetErrorHandler (NULL);
158 gtk_init (argc, argv);
159 the_gtk_display = gdk_x11_display_get_xdisplay (gdk_display_get_default());
160 gtk_error_handler = XSetErrorHandler( fst_xerror_handler );