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