Windows VST GUI related rework
[ardour.git] / gtk2_ardour / vst_plugin_ui.cc
1 /*
2     Copyright (C) 2000-2010 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 "ardour/vst_plugin.h"
21 #include "ardour/vst_types.h"
22 #include "vst_plugin_ui.h"
23 #include <gdk/gdkx.h>
24
25 VSTPluginUI::VSTPluginUI (boost::shared_ptr<ARDOUR::PluginInsert> insert, boost::shared_ptr<ARDOUR::VSTPlugin> plugin)
26         : PlugUIBase (insert)
27         , _vst (plugin)
28 {
29         Gtk::HBox* box = manage (new Gtk::HBox);
30         box->set_spacing (6);
31         box->set_border_width (6);
32         box->pack_end (focus_button, false, false);
33         box->pack_end (bypass_button, false, false, 10);
34         box->pack_end (delete_button, false, false);
35         box->pack_end (save_button, false, false);
36         box->pack_end (add_button, false, false);
37         box->pack_end (_preset_combo, false, false);
38
39         bypass_button.set_active (!insert->active ());
40
41         pack_start (*box, false, false);
42 #ifdef GDK_WINDOWING_X11
43         pack_start (_socket, true, true);
44 #endif
45 }
46
47 VSTPluginUI::~VSTPluginUI ()
48 {
49
50 }
51
52 void
53 VSTPluginUI::preset_selected ()
54 {
55 #ifdef GDK_WINDOWING_X11
56         _socket.grab_focus ();
57 #endif
58         PlugUIBase::preset_selected ();
59 }
60
61 int
62 VSTPluginUI::get_preferred_height ()
63 {
64         int preferred_height = _vst->state()->height;
65         preferred_height += _vst->state()->voffset;
66         return preferred_height;
67 }
68
69 int
70 VSTPluginUI::get_preferred_width ()
71 {
72         return _vst->state()->width;
73 }
74
75 int
76 VSTPluginUI::package (Gtk::Window& win)
77 {
78 #ifdef GDK_WINDOWING_X11
79         /* Forward configure events to plugin window */
80         win.signal_configure_event().connect (sigc::mem_fun (*this, &VSTPluginUI::configure_handler), false);
81
82         /* This assumes that the window's owner understands the XEmbed protocol */
83         _socket.add_id (get_XID ());
84 #endif
85         
86         return 0;
87 }
88
89 bool
90 VSTPluginUI::on_window_show(const std::string& title)
91 {
92         _vst->state()->gui_shown = 1;
93         return PlugUIBase::on_window_show(title);
94 }
95
96 void
97 VSTPluginUI::on_window_hide()
98 {
99         _vst->state()->gui_shown = 0;
100         PlugUIBase::on_window_hide();
101 }
102
103
104 bool
105 VSTPluginUI::configure_handler (GdkEventConfigure*)
106 {
107 #ifdef GDK_WINDOWING_X11
108         XEvent event;
109         gint x, y;
110         GdkWindow* w;
111
112         if ((w = _socket.gobj()->plug_window) == 0) {
113                 return false;
114         }
115
116         event.xconfigure.type = ConfigureNotify;
117         event.xconfigure.event = GDK_WINDOW_XWINDOW (w);
118         event.xconfigure.window = GDK_WINDOW_XWINDOW (w);
119
120         /* The ICCCM says that synthetic events should have root relative
121          * coordinates. We still aren't really ICCCM compliant, since
122          * we don't send events when the real toplevel is moved.
123          */
124         gdk_error_trap_push ();
125         gdk_window_get_origin (w, &x, &y);
126         gdk_error_trap_pop ();
127
128         event.xconfigure.x = x;
129         event.xconfigure.y = y;
130         event.xconfigure.width = GTK_WIDGET (_socket.gobj())->allocation.width;
131         event.xconfigure.height = GTK_WIDGET (_socket.gobj())->allocation.height;
132
133         event.xconfigure.border_width = 0;
134         event.xconfigure.above = None;
135         event.xconfigure.override_redirect = False;
136
137         gdk_error_trap_push ();
138         XSendEvent (GDK_WINDOW_XDISPLAY (w), GDK_WINDOW_XWINDOW (w), False, StructureNotifyMask, &event);
139         gdk_error_trap_pop ();
140
141 #endif
142         return false;
143 }
144