From 1bb7720c5b187fd69d79ed437e52aed592ea94e1 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Wed, 25 Aug 2004 02:42:06 +0000 Subject: "" svn path=/trunk/; revision=1976 --- externals/grill/vst/src/EditorWin.cpp | 122 ++++++++++++++++++++++++++-------- 1 file changed, 94 insertions(+), 28 deletions(-) (limited to 'externals/grill/vst/src/EditorWin.cpp') 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(x),reinterpret_cast(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(wx),y = reinterpret_cast(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(wx),y = reinterpret_cast(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(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(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; -- cgit v1.2.1