significant reworking of AudioUnit window resizing.
[ardour.git] / gtk2_ardour / au_pluginui.h
1 /*
2     Copyright (C) 2012 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 #ifndef __gtk2_ardour_auplugin_ui_h__
21 #define __gtk2_ardour_auplugin_ui_h__
22
23 #include <vector>
24 #include <string>
25
26 #include <AppKit/AppKit.h>
27 #include <Carbon/Carbon.h>
28 #include <AudioUnit/AudioUnitCarbonView.h>
29 #include <AudioUnit/AudioUnit.h>
30
31 /* fix up stupid apple macros */
32
33 #undef check
34 #undef require
35 #undef verify
36
37 #ifdef YES
38 #undef YES
39 #endif
40 #ifdef NO
41 #undef NO
42 #endif
43
44 #include <gtkmm/box.h>
45 #include <gtkmm/eventbox.h>
46 #include <gtkmm/combobox.h>
47 #include <gtkmm/button.h>
48 #include <gtkmm/label.h>
49
50 #include "plugin_ui.h"
51
52 namespace ARDOUR {
53         class AUPlugin;
54         class PluginInsert;
55         class IOProcessor;
56 }
57
58 class AUPluginUI;
59
60 @interface NotificationObject : NSObject {
61         @private
62                 AUPluginUI* plugin_ui;
63                 NSWindow* cocoa_parent;
64                 NSWindow* top_level_parent;
65 }
66 @end
67
68 @interface LiveResizeNotificationObject : NSObject {
69         @private
70                 AUPluginUI* plugin_ui;
71 }
72 @end
73
74 class AUPluginUI : public PlugUIBase, public Gtk::VBox
75 {
76   public:
77         AUPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>);
78         ~AUPluginUI ();
79
80         gint get_preferred_width () { return req_width; }
81         gint get_preferred_height () { return req_height; }
82         bool start_updating(GdkEventAny*);
83         bool stop_updating(GdkEventAny*);
84
85         void activate ();
86         void deactivate ();
87
88         bool non_gtk_gui() const { return true; }
89
90         void lower_box_realized ();
91         bool lower_box_visibility_notify (GdkEventVisibility*);
92
93         void lower_box_map ();
94         void lower_box_unmap ();
95         void lower_box_size_request (GtkRequisition*);
96         void lower_box_size_allocate (Gtk::Allocation&);
97         gboolean lower_box_expose (GdkEventExpose*);
98
99         void cocoa_view_resized ();
100         void on_realize ();
101         void grab_focus();
102         void forward_key_event (GdkEventKey*);
103
104         bool on_window_show (const std::string& /*title*/);
105         void on_window_hide ();
106
107         OSStatus carbon_event (EventHandlerCallRef nextHandlerRef, EventRef event);
108
109         void start_live_resize ();
110         void end_live_resize ();
111
112   private:
113         WindowRef wr;
114         boost::shared_ptr<ARDOUR::AUPlugin> au;
115         int prefheight;
116         int prefwidth;
117
118         Gtk::HBox     top_box;
119         Gtk::EventBox low_box;
120         Gtk::VBox vpacker;
121         Gtk::Label automation_mode_label;
122         Gtk::ComboBoxText automation_mode_selector;
123         Gtk::Label preset_label;
124
125         static std::vector<std::string> automation_mode_strings;
126
127         bool mapped;
128         bool resizable;
129         int  min_width;
130         int  min_height;
131         int  req_width;
132         int  req_height;
133         int  alo_width;
134         int  alo_height;
135
136         /* Cocoa */
137
138         NSWindow*           cocoa_window;
139         NSView*             au_view;
140         NSRect              last_au_frame;
141         bool                in_live_resize;
142         uint32_t            plugin_requested_resize;
143
144         /* Carbon */
145
146         NSWindow*            cocoa_parent;
147         ComponentDescription carbon_descriptor;
148         AudioUnitCarbonView  editView;
149         WindowRef            carbon_window;
150         EventHandlerRef      carbon_event_handler;
151         bool                 _activating_from_app;
152
153         /* Generic */
154
155         NotificationObject* _notify;
156         LiveResizeNotificationObject* _resize_notify;
157
158         bool test_cocoa_view_support ();
159         bool test_carbon_view_support ();
160         int  create_carbon_view ();
161         int  create_cocoa_view ();
162
163         int parent_carbon_window ();
164         int parent_cocoa_window ();
165         NSWindow* get_nswindow();
166
167         void update_view_size ();
168
169         bool plugin_class_valid (Class pluginClass);
170 };
171
172 #endif /* __gtk2_ardour_auplugin_ui_h__  */