1 /**********************************************************************
2 
3   Audacity: A Digital Audio Editor
4 
5   VSTControlGTK.cpp
6 
7   Leland Lucius
8 
9 **********************************************************************/
10 
11 #include "VSTControlGTK.h"
12 
13 #include <wx/dynlib.h>
14 #include <wx/sizer.h>
15 
16 #if 0
17 static int trappedErrorCode = 0;
18 static int X11TrapHandler(Display *, XErrorEvent *err)
19 {
20     return 0;
21 }
22 #endif
23 
VSTControl()24 VSTControl::VSTControl()
25 :  VSTControlBase()
26 {
27    mXdisp = 0;
28    mXwin = 0;
29 }
30 
~VSTControl()31 VSTControl::~VSTControl()
32 {
33    if (mXwin)
34    {
35       mLink->callDispatcher(effEditClose, 0, (intptr_t)mXdisp, (void *)mXwin, 0.0);
36       mXdisp = 0;
37       mXwin = 0;
38    }
39 }
40 
Create(wxWindow * parent,VSTEffectLink * link)41 bool VSTControl::Create(wxWindow *parent, VSTEffectLink *link)
42 {
43    if (!VSTControlBase::Create(parent, link))
44    {
45       return false;
46    }
47 
48    VstRect *rect;
49 
50    // Some effects like to have us get their rect before opening them.
51    mLink->callDispatcher(effEditGetRect, 0, 0, &rect, 0.0);
52 
53    // Make sure the parent has a window
54    if (!gtk_widget_get_realized(GTK_WIDGET(m_wxwindow)))
55    {
56       gtk_widget_realize(GTK_WIDGET(m_wxwindow));
57    }
58 
59    GdkWindow *gwin = gtk_widget_get_window(GTK_WIDGET(m_wxwindow));
60    mXdisp = GDK_WINDOW_XDISPLAY(gwin);
61    mXwin = GDK_WINDOW_XID(gwin);
62 
63    mLink->callDispatcher(effEditOpen, 0, (intptr_t)mXdisp, (void *)mXwin, 0.0);
64 
65    // Get the final bounds of the effect GUI
66    mLink->callDispatcher(effEditGetRect, 0, 0, &rect, 0.0);
67 
68    // Add the effect host window to the layout
69    SetMinSize(wxSize(rect->right - rect->left, rect->bottom - rect->top));
70 
71    // Must get the size again since SetPeer() could cause it to change
72    SetInitialSize(GetMinSize());
73 
74    return true;
75 }
76