Fix crash when X11 is not available for VST UIs
[ardour.git] / gtk2_ardour / mac_vst_plugin_ui.h
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
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 along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #include <AppKit/AppKit.h>
20 #include <Carbon/Carbon.h>
21
22 /* fix up stupid apple macros */
23 #undef check
24 #undef require
25 #undef verify
26
27 #ifdef YES
28 #undef YES
29 #endif
30 #ifdef NO
31 #undef NO
32 #endif
33
34 #include "vst_plugin_ui.h"
35
36 class MacVSTPluginUI;
37
38 @interface ResizeNotificationObject : NSObject {
39         @private
40                 MacVSTPluginUI* plugin_ui;
41 }
42 @end
43
44 class MacVSTPluginUI : public VSTPluginUI
45 {
46 public:
47         MacVSTPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>, boost::shared_ptr<ARDOUR::VSTPlugin>);
48         ~MacVSTPluginUI ();
49
50         bool start_updating (GdkEventAny*) { return false; }
51         bool stop_updating (GdkEventAny*) { return false; }
52
53         int package (Gtk::Window &);
54
55         void forward_key_event (GdkEventKey *);
56         void view_resized ();
57
58 protected:
59         void lower_box_realized ();
60         bool lower_box_visibility_notify (GdkEventVisibility*);
61         void lower_box_map ();
62         void lower_box_unmap ();
63         void lower_box_size_request (GtkRequisition*);
64         void lower_box_size_allocate (Gtk::Allocation&);
65
66 private:
67         int get_XID ();
68         bool idle ();
69         void set_program ();
70         NSWindow* get_nswindow();
71
72         Gtk::EventBox low_box;
73         NSView*          _ns_view;
74         sigc::connection _idle_connection;
75         PBD::ScopedConnection _program_connection;
76         ResizeNotificationObject* _resize_notifier;
77 };