fix carbon GUI focus/re-exposure
[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 #include <gtkmm/box.h>
38 #include <gtkmm/eventbox.h>
39 #include <gtkmm/combobox.h>
40 #include <gtkmm/button.h>
41 #include <gtkmm/label.h>
42
43 #include "plugin_ui.h"
44
45 namespace ARDOUR {
46         class AUPlugin;
47         class PluginInsert;
48         class IOProcessor;
49 }
50
51 class AUPluginUI;
52
53 @interface NotificationObject : NSObject {
54         @private
55                 AUPluginUI* plugin_ui;
56                 NSWindow* cocoa_parent;
57                 NSWindow* top_level_parent;
58 }
59 @end
60
61 class AUPluginUI : public PlugUIBase, public Gtk::VBox
62 {
63   public:
64         AUPluginUI (boost::shared_ptr<ARDOUR::PluginInsert>);
65         ~AUPluginUI ();
66
67         gint get_preferred_height () { return prefheight; }
68         gint get_preferred_width () { return prefwidth; }
69         bool start_updating(GdkEventAny*);
70         bool stop_updating(GdkEventAny*);
71
72         void activate ();
73         void deactivate ();
74
75         bool non_gtk_gui() const { return true; }
76
77         void lower_box_realized ();
78         bool lower_box_visibility_notify (GdkEventVisibility*);
79
80         void cocoa_view_resized ();
81         void on_realize ();
82         void grab_focus();
83         void forward_key_event (GdkEventKey*);
84
85         bool on_window_show (const std::string& /*title*/);
86         void on_window_hide ();
87
88         OSStatus carbon_event (EventHandlerCallRef nextHandlerRef, EventRef event);
89
90   private:
91         WindowRef wr;
92         boost::shared_ptr<ARDOUR::AUPlugin> au;
93         int prefheight;
94         int prefwidth;
95
96         Gtk::HBox     top_box;
97         Gtk::EventBox low_box;
98         Gtk::VBox vpacker;
99         Gtk::Label automation_mode_label;
100         Gtk::ComboBoxText automation_mode_selector;
101         Gtk::Label preset_label;
102
103         static std::vector<std::string> automation_mode_strings;
104
105         /* Cocoa */
106
107         NSWindow*           cocoa_window;
108         NSView*             au_view;
109         NSRect              last_au_frame;
110
111         /* Carbon */
112
113         NSWindow*            cocoa_parent;
114         ComponentDescription carbon_descriptor;
115         AudioUnitCarbonView  editView;
116         WindowRef            carbon_window;
117         EventHandlerRef      carbon_event_handler;
118         bool                 _activating_from_app;
119         NotificationObject* _notify;
120
121         bool test_cocoa_view_support ();
122         bool test_carbon_view_support ();
123         int  create_carbon_view ();
124         int  create_cocoa_view ();
125
126         int parent_carbon_window ();
127         int parent_cocoa_window ();
128         NSWindow* get_nswindow();
129
130         bool plugin_class_valid (Class pluginClass);
131 };
132
133 #endif /* __gtk2_ardour_auplugin_ui_h__  */