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