aboutsummaryrefslogtreecommitdiff
path: root/externals/grill/vst/src/EditorWin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'externals/grill/vst/src/EditorWin.cpp')
-rw-r--r--externals/grill/vst/src/EditorWin.cpp122
1 files changed, 94 insertions, 28 deletions
diff --git a/externals/grill/vst/src/EditorWin.cpp b/externals/grill/vst/src/EditorWin.cpp
index 9a79c391..82ab55ba 100644
--- a/externals/grill/vst/src/EditorWin.cpp
+++ b/externals/grill/vst/src/EditorWin.cpp
@@ -35,18 +35,24 @@ static LRESULT CALLBACK wndproc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp)
LRESULT res = 0;
-// post("Message %x",msg);
switch(msg) {
-// case WM_NCREATE: res = TRUE; break;
case WM_CREATE:
// Initialize the window.
plug->StartEditing(hwnd);
break;
case WM_CLOSE:
- plug->StopEditing();
+#ifdef FLEXT_DEBUG
+ flext::post("WM_CLOSE");
+#endif
+ // plug could already have been unloaded...
+ plug->StopEditing(); // this sets plug->hwnd = NULL
DestroyWindow(hwnd);
break;
case WM_DESTROY:
+#ifdef FLEXT_DEBUG
+ flext::post("WM_DESTROY");
+#endif
+ // stop editor thread
PostQuitMessage(0);
break;
case WM_TIMER:
@@ -56,8 +62,16 @@ static LRESULT CALLBACK wndproc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp)
plug->EditorIdle();
break;
case WM_MOVE: {
- WORD x = LOWORD(lp),y = HIWORD(lp);
- plug->SetPos(reinterpret_cast<short &>(x),reinterpret_cast<short &>(y),false);
+ // ignore after WM_CLOSE so that x,y positions are preserved
+ if(!plug->IsEdited()) break;
+
+ WORD wx = LOWORD(lp),wy = HIWORD(lp);
+ short x = reinterpret_cast<short &>(wx),y = reinterpret_cast<short &>(wy);
+ // x and y are the coordinates of the client rect (= actual VST interface)
+ plug->SetPos(x,y,false);
+#ifdef FLEXT_DEBUG
+ flext::post("WM_MOVE x/y=%i/%i",x,y);
+#endif
break;
}
/*
@@ -69,17 +83,40 @@ static LRESULT CALLBACK wndproc(HWND hwnd,UINT msg,WPARAM wp,LPARAM lp)
break;
}
*/
-/*
- case WM_SIZE:
- // Set the size and position of the window.
+#if 0 //def FLEXT_DEBUG
+ case WM_SIZE: {
+ WORD wx = LOWORD(lp),wy = HIWORD(lp);
+ short x = reinterpret_cast<short &>(wx),y = reinterpret_cast<short &>(wy);
+ // x and y are the coordinates of the client rect (= actual VST interface)
+ flext::post("WM_SIZE x/y=%i/%i",x,y);
break;
-*/
+ }
+#endif
+
default:
res = DefWindowProc(hwnd,msg,wp,lp);
}
return res;
}
+static void windowsize(HWND wnd,int x,int y,int w,int h,bool caption,LONG flags = 0)
+{
+ WINDOWINFO winfo;
+ winfo.cbSize = sizeof(winfo);
+ GetWindowInfo(wnd,&winfo);
+
+ int cy = caption?GetSystemMetrics(SM_CYCAPTION):0;
+
+ SetWindowPos(wnd,HWND_TOP,
+ x-(winfo.rcClient.left-winfo.rcWindow.left),
+ y-(winfo.rcClient.top-winfo.rcWindow.top),
+ w+winfo.cxWindowBorders*2,
+ h+cy+winfo.cyWindowBorders*2,
+ flags
+ );
+
+}
+
static void threadfun(flext::thr_params *p)
{
flext::RelPriority(-2);
@@ -98,7 +135,7 @@ static void threadfun(flext::thr_params *p)
HWND wnd = CreateWindow(
WCLNAME,tmp,
- WS_BORDER|WS_CAPTION|/*WS_THICKFRAME|*/WS_POPUP|WS_SYSMENU|WS_MINIMIZEBOX,
+ (plug->GetCaption()?WS_BORDER|WS_CAPTION:0)|WS_POPUP|WS_SYSMENU|WS_MINIMIZEBOX,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,
hinstance,NULL
@@ -121,24 +158,13 @@ static void threadfun(flext::thr_params *p)
SetTimer(wnd,0,TIMER_INTERVAL,NULL);
- WINDOWINFO winfo;
- winfo.cbSize = sizeof(winfo);
- GetWindowInfo(wnd,&winfo);
- TITLEBARINFO tinfo;
- tinfo.cbSize = sizeof(tinfo);
- GetTitleBarInfo(wnd,&tinfo);
-
ERect r;
plug->GetEditorRect(r);
- SetWindowPos(wnd,HWND_TOP,
- r.left,
- r.top,
- (r.right-r.left)+winfo.cxWindowBorders*2,
- (r.bottom-r.top)+(tinfo.rcTitleBar.bottom-tinfo.rcTitleBar.top)+winfo.cyWindowBorders*2,
- SWP_SHOWWINDOW
- );
-
-
+ windowsize(wnd,plug->GetX(),plug->GetY(),r.right-r.left,r.bottom-r.top,plug->GetCaption(),SWP_SHOWWINDOW);
+#ifdef FLEXT_DEBUG
+ flext::post("Editor rect left/top=%i/%i, right/bottom=%i/%i",r.left,r.top,r.right,r.bottom);
+#endif
+
// SetFocus();
// Message pump
@@ -186,13 +212,25 @@ void SetupEditor()
void StartEditor(VSTPlugin *p)
{
+#ifdef FLEXT_DEBUG
+ flext::post("Start editor 1");
+#endif
flext::LaunchThread(threadfun,reinterpret_cast<flext::thr_params *>(p));
+#ifdef FLEXT_DEBUG
+ flext::post("Start editor 2");
+#endif
}
void StopEditor(VSTPlugin *p)
{
+#ifdef FLEXT_DEBUG
+ flext::post("Stop editor 1");
+#endif
PostMessage(p->EditorHandle(),WM_CLOSE,0,0);
flext::StopThread(threadfun,reinterpret_cast<flext::thr_params *>(p));
+#ifdef FLEXT_DEBUG
+ flext::post("Stop editor 2");
+#endif
}
void ShowEditor(VSTPlugin *p,bool show)
@@ -202,8 +240,17 @@ void ShowEditor(VSTPlugin *p,bool show)
void MoveEditor(VSTPlugin *p,int x,int y)
{
- // the client region must be taken into account
-// SetWindowPos(p->EditorHandle(),NULL,x,y,0,0,SWP_NOSIZE|SWP_NOZORDER);
+ HWND wnd = p->EditorHandle();
+
+ WINDOWINFO winfo;
+ winfo.cbSize = sizeof(winfo);
+ GetWindowInfo(wnd,&winfo);
+
+ SetWindowPos(wnd,NULL,
+ x-(winfo.rcClient.left-winfo.rcWindow.left),y-(winfo.rcClient.top-winfo.rcWindow.top),
+ 0,0,
+ SWP_NOSIZE|SWP_NOZORDER
+ );
}
void SizeEditor(VSTPlugin *p,int x,int y)
@@ -211,6 +258,25 @@ void SizeEditor(VSTPlugin *p,int x,int y)
SetWindowPos(p->EditorHandle(),NULL,0,0,x,y,SWP_NOMOVE|SWP_NOZORDER);
}
+void CaptionEditor(VSTPlugin *plug,bool c)
+{
+ HWND wnd = plug->EditorHandle();
+ LONG ns,style = GetWindowLong(wnd,GWL_STYLE);
+ if(c) ns = style|WS_BORDER|WS_CAPTION;
+ else ns = style&~(WS_BORDER|WS_CAPTION);
+ if(ns != style) {
+ SetWindowLong(wnd,GWL_STYLE,ns);
+
+ ERect r; plug->GetEditorRect(r);
+ windowsize(wnd,plug->GetX(),plug->GetY(),r.right-r.left,r.bottom-r.top,c,SWP_FRAMECHANGED);
+ }
+}
+
+void TitleEditor(VSTPlugin *p,const char *t)
+{
+ SetWindowText(p->EditorHandle(),t);
+}
+
bool IsEditorShown(const VSTPlugin *p)
{
return IsWindowVisible(p->EditorHandle()) != FALSE;