// Returns:
// -1 = action does not belong to this extension, or does not toggle
//  0 = action belongs to this extension and is currently set to "off"
//  1 = action belongs to this extension and is currently set to "on"
int toggleActionHook(int iCmd)
{
	static WDL_PtrList<const char> sReentrantCmds;
	if (COMMAND_T* cmd = SWSGetCommandByID(iCmd))
	{
		if (cmd->accel.accel.cmd==iCmd && cmd->getEnabled && cmd->doCommand!=SWS_NOOP)
		{
			if (sReentrantCmds.Find(cmd->id) == -1)
			{
				sReentrantCmds.Add(cmd->id);
				int state = cmd->getEnabled(cmd);
				sReentrantCmds.Delete(sReentrantCmds.Find(cmd->id));
				return state;
			}
#ifdef ACTION_DEBUG
			else
			{
				OutputDebugString("toggleActionHook - recursive action: ");
				OutputDebugString(cmd->id);
				OutputDebugString("\n");
			}
#endif
		}
	}
	return -1;
}
int SWELL_DialogBox(SWELL_DialogResourceIndex *reshead, const char *resid, HWND parent,  DLGPROC dlgproc, LPARAM param)
{
  SWELL_DialogResourceIndex *p=resById(reshead,resid);
  if (resid) // allow modal dialogs to be created without template
  {
    if (!p||(p->windowTypeFlags&SWELL_DLG_WS_CHILD)) return -1;
  }


  int ret=-1;
  HWND hwnd = SWELL_CreateDialog(reshead,resid,parent,dlgproc,param);
  // create dialog
  if (hwnd)
  {
    ReleaseCapture(); // force end of any captures

    WDL_PtrList<HWND__> enwnds;
    extern HWND__ *SWELL_topwindows;
    HWND a = SWELL_topwindows;
    while (a)
    {
      if (a->m_enabled && a != hwnd) { EnableWindow(a,FALSE); enwnds.Add(a); }
      a = a->m_next;
    }

    modalDlgRet r = { hwnd,false, -1 };
    s_modalDialogs.Add(&r);
    ShowWindow(hwnd,SW_SHOW);
    while (s_modalDialogs.Find(&r)>=0 && !r.has_ret)
    {
      void SWELL_RunMessageLoop();
      SWELL_RunMessageLoop();
      Sleep(10);
    }
    ret=r.ret;
    s_modalDialogs.Delete(s_modalDialogs.Find(&r));

    a = SWELL_topwindows;
    while (a)
    {
      if (!a->m_enabled && a != hwnd && enwnds.Find(a)>=0) EnableWindow(a,TRUE);
      a = a->m_next;
    }
  }
  // while in list, do something
  return ret;
}
Exemple #3
0
void RegisterToMarkerRegionUpdates(SNM_MarkerRegionListener* _listener)
{
#ifdef _SNM_MUTEX
	SWS_SectionLock lock(&g_mkrRgnListenersMutex);
#endif
	if (_listener && g_mkrRgnListeners.Find(_listener) < 0)
		g_mkrRgnListeners.Add(_listener);
}
bool hookCommandProc(int iCmd, int flag)
{
	static WDL_PtrList<const char> sReentrantCmds;

	// for Xen extensions
	g_KeyUpUndoHandler=0;

	// "Hack" to make actions will #s less than 1000 work with SendMessage (AHK)
	// no recursion check here: handled by REAPER
	if (iCmd < 1000)
		return KBD_OnMainActionEx(iCmd, 0, 0, 0, g_hwndParent, NULL) ? true : false; // C4800

	// Special case for checking recording
	if (iCmd == 1013 && !RecordInputCheck())
		return true;

	// Ignore commands that don't have anything to do with us from this point forward
	if (COMMAND_T* cmd = SWSGetCommandByID(iCmd))
	{
		if (cmd->accel.accel.cmd==iCmd && cmd->doCommand && cmd->doCommand!=SWS_NOOP)
		{
			if (sReentrantCmds.Find(cmd->id) == -1)
			{
				sReentrantCmds.Add(cmd->id);
				cmd->fakeToggle = !cmd->fakeToggle;
#ifndef DEBUG_PERFORMANCE_TIME
				cmd->doCommand(cmd);
#else
				CommandTimer(cmd);
#endif
				sReentrantCmds.Delete(sReentrantCmds.Find(cmd->id));
				return true;
			}
#ifdef ACTION_DEBUG
			else
			{
				OutputDebugString("hookCommandProc - recursive action: ");
				OutputDebugString(cmd->id);
				OutputDebugString("\n");
			}
#endif
		}
	}
	return false;
}
Exemple #5
0
void UnregisterToMarkerRegionUpdates(SNM_MarkerRegionListener* _listener)
{
#ifdef _SNM_MUTEX
	SWS_SectionLock lock(&g_mkrRgnListenersMutex);
#endif
	int idx = _listener ? g_mkrRgnListeners.Find(_listener) : -1;
	if (idx >= 0)
		g_mkrRgnListeners.Delete(idx, false);
}
Exemple #6
0
bool OscInit(OscHandler* osc)
{
  KillOscThread();
  if (s_osc_handlers.Find(osc) < 0)
  {
    // insert at the top, so new listeners will block existing handlers
    s_osc_handlers.Insert(0, osc);
  }

  StartOscThread();
  return true;
}
Exemple #7
0
void OscQuit(OscHandler* osc)
{
  if (osc)
  {
    int i=s_osc_handlers.Find(osc);
    if (i >= 0) 
    {
      KillOscThread();
      s_osc_handlers.Delete(i);
      if (s_osc_handlers.GetSize())
      {
        StartOscThread();
      }
    }
  }
  else
  {
    KillOscThread();
    s_osc_handlers.Empty();
  }
}
static LRESULT WINAPI submenuWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  const int itemheight = 12, lcol=12, rcol=12, mcol=10;
  switch (uMsg)
  {
    case WM_CREATE:
      m_trackingMenus.Add(hwnd);
      SetWindowLongPtr(hwnd,GWLP_USERDATA,lParam);

      if (m_trackingPar && !(m_trackingFlags&TPM_NONOTIFY))
        SendMessage(m_trackingPar,WM_INITMENUPOPUP,(WPARAM)lParam,0);

      {
        HDC hdc = GetDC(hwnd);
        HMENU__ *menu = (HMENU__*)lParam;
        int ht = menu->items.GetSize()*itemheight, wid=100,wid2=0;
        int xpos=m_trackingPt.x;
        int ypos=m_trackingPt.y;
        int x;
        for (x=0; x < menu->items.GetSize(); x++)
        {
          MENUITEMINFO *inf = menu->items.Get(x);
          if (inf->fType == MFT_STRING && inf->dwTypeData)
          {
            RECT r={0,};
            const char *pt2 = strstr(inf->dwTypeData,"\t");
            DrawText(hdc,inf->dwTypeData,pt2 ? pt2-inf->dwTypeData : -1,&r,DT_CALCRECT|DT_SINGLELINE);
            if (r.right > wid) wid=r.right;
            if (pt2)
            { 
              r.right=r.left;
              DrawText(hdc,pt2+1,-1,&r,DT_CALCRECT|DT_SINGLELINE);
              if (r.right > wid2) wid2=r.right;
            }
          }
        }
        wid+=lcol+rcol + (wid2?wid2+mcol:0);
        ReleaseDC(hwnd,hdc);
        RECT tr={xpos,ypos,xpos+wid,ypos+ht},vp;
        SWELL_GetViewPort(&vp,&tr,true);
        if (tr.bottom > vp.bottom) { tr.top += vp.bottom-tr.bottom; tr.bottom=vp.bottom; }
        if (tr.right > vp.right) { tr.left += vp.right-tr.right; tr.right=vp.right; }
        if (tr.left < vp.left) { tr.right += vp.left-tr.left; tr.left=vp.left; }
        if (tr.top < vp.top) { tr.bottom += vp.top-tr.top; tr.top=vp.top; }
        SetWindowPos(hwnd,NULL,tr.left,tr.top,tr.right-tr.left,tr.bottom-tr.top,SWP_NOZORDER);
      }
      SetWindowLong(hwnd,GWL_STYLE,GetWindowLong(hwnd,GWL_STYLE)&~WS_CAPTION);
      ShowWindow(hwnd,SW_SHOW);
      SetFocus(hwnd);
      SetTimer(hwnd,1,250,NULL);
    break;
    case WM_PAINT:
      {
        PAINTSTRUCT ps;
        if (BeginPaint(hwnd,&ps))
        {
          RECT cr;
          GetClientRect(hwnd,&cr);
          HBRUSH br=CreateSolidBrush(GetSysColor(COLOR_3DFACE));
          HPEN pen=CreatePen(PS_SOLID,0,GetSysColor(COLOR_3DSHADOW));
          HGDIOBJ oldbr = SelectObject(ps.hdc,br);
          HGDIOBJ oldpen = SelectObject(ps.hdc,pen);
          Rectangle(ps.hdc,cr.left,cr.top,cr.right-1,cr.bottom-1);
          SetBkMode(ps.hdc,TRANSPARENT);
          int cols[2]={ GetSysColor(COLOR_BTNTEXT),GetSysColor(COLOR_3DHILIGHT)};
          HMENU__ *menu = (HMENU__*)GetWindowLongPtr(hwnd,GWLP_USERDATA);
          int x;
          for (x=0; x < menu->items.GetSize(); x++)
          {
            MENUITEMINFO *inf = menu->items.Get(x);
            RECT r={lcol,x*itemheight,cr.right,(x+1)*itemheight};
            bool dis = !!(inf->fState & MF_GRAYED);
            SetTextColor(ps.hdc,cols[dis]);
            if (inf->fType == MFT_STRING && inf->dwTypeData)
            {
              const char *pt2 = strstr(inf->dwTypeData,"\t");
              DrawText(ps.hdc,inf->dwTypeData,pt2 ? pt2-inf->dwTypeData : -1,&r,DT_VCENTER|DT_SINGLELINE);
              if (pt2)
              {
                RECT tr=r; tr.right-=rcol;
                DrawText(ps.hdc,pt2+1,-1,&tr,DT_VCENTER|DT_SINGLELINE|DT_RIGHT);
              }
            }
            else 
            {
              MoveToEx(ps.hdc,r.left - lcol/2,(r.top+r.bottom)/2,NULL);
              LineTo(ps.hdc,r.right - rcol*3/2,(r.top+r.bottom)/2);
            }
            if (inf->hSubMenu) 
            {
               RECT r2=r; r2.left = r2.right - rcol;
               DrawText(ps.hdc,">",-1,&r2,DT_VCENTER|DT_RIGHT|DT_SINGLELINE);
            }
            if (inf->fState&MF_CHECKED)
            {
               RECT r2=r; r2.left = 0; r2.right=lcol;
               DrawText(ps.hdc,"X",-1,&r2,DT_VCENTER|DT_CENTER|DT_SINGLELINE);
            }
          }
          SelectObject(ps.hdc,oldbr);
          SelectObject(ps.hdc,oldpen);
          DeleteObject(br);
          DeleteObject(pen);
          EndPaint(hwnd,&ps); 
        }       
      }
    break;
    case WM_TIMER:
      if (wParam==1)
      {
        HWND h = GetFocus();
        if (h!=hwnd)
        {
          int a = h ? m_trackingMenus.Find(h) : -1;
          if (a<0 || a < m_trackingMenus.Find(hwnd)) DestroyWindow(hwnd); 
        }
      }
    break;
    case WM_DESTROY:
      {
        int a = m_trackingMenus.Find(hwnd);
        m_trackingMenus.Delete(a);
        if (m_trackingMenus.Get(a)) DestroyWindow(m_trackingMenus.Get(a));
      }
    break;
    case WM_LBUTTONUP:
    case WM_RBUTTONUP:
      {
        RECT r;
        GetClientRect(hwnd,&r);
        if (GET_X_LPARAM(lParam)>=r.left && GET_X_LPARAM(lParam)<r.right)
        {
          int which = GET_Y_LPARAM(lParam)/itemheight;
          HMENU__ *menu = (HMENU__*)GetWindowLongPtr(hwnd,GWLP_USERDATA);
          MENUITEMINFO *inf = menu->items.Get(which);
          if (inf) 
          {
            if (inf->fState&MF_GRAYED){ }
            else if (inf->hSubMenu)
            {
              int a = m_trackingMenus.Find(hwnd);
              HWND next = m_trackingMenus.Get(a+1);
              if (next) DestroyWindow(next); 

              m_trackingPt.x=r.right;
              m_trackingPt.y=r.top + which*itemheight;
              ClientToScreen(hwnd,&m_trackingPt);
              submenuWndProc(new HWND__(NULL,0,NULL,"menu",false,submenuWndProc,NULL),WM_CREATE,0,(LPARAM)inf->hSubMenu);
            }
            else if (inf->wID) m_trackingRet = inf->wID;
          }
          else DestroyWindow(hwnd);
        }
        else DestroyWindow(hwnd);
      }
    break;
  }
  return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
Exemple #9
0
// supports folders, multi-selection and routings between tracks too
void SaveSelTrackTemplates(bool _delItems, bool _delEnvs, WDL_FastString* _chunkOut)
{
	if (!_chunkOut)
		return;

	WDL_PtrList<MediaTrack> tracks;

	// append selected track chunks (+ folders) -------------------------------
	for (int i=0; i <= GetNumTracks(); i++) // incl. master
	{
		MediaTrack* tr = CSurf_TrackFromID(i, false);
		if (tr && *(int*)GetSetMediaTrackInfo(tr, "I_SELECTED", NULL))
		{
			SaveSingleTrackTemplateChunk(tr, _chunkOut, _delItems, _delEnvs);
			tracks.Add(tr);

			// folder: save child templates
			WDL_PtrList<MediaTrack>* childTracks = GetChildTracks(tr);
			if (childTracks)
			{
				for (int j=0; j < childTracks->GetSize(); j++) {
					SaveSingleTrackTemplateChunk(childTracks->Get(j), _chunkOut, _delItems, _delEnvs);
					tracks.Add(childTracks->Get(j));
				}
				i += childTracks->GetSize(); // skip children
				delete childTracks;
			}
		}
	}

	// update receives ids ----------------------------------------------------
	// no break keyword used here: multiple tracks in the template
	SNM_ChunkParserPatcher p(_chunkOut);
	WDL_FastString line;
	int occurence = 0;
	int pos = p.Parse(SNM_GET_SUBCHUNK_OR_LINE, 1, "TRACK", "AUXRECV", occurence, 1, &line); 
	while (pos > 0)
	{
		pos--; // see SNM_ChunkParserPatcher

		bool replaced = false;
		line.SetLen(line.GetLength()-1); // remove trailing '\n'
		LineParser lp(false);
		if (!lp.parse(line.Get()) && lp.getnumtokens() > 1)
		{
			int success, curId = lp.gettoken_int(1, &success);
			if (success)
			{
				MediaTrack* tr = CSurf_TrackFromID(curId+1, false);
				int newId = tracks.Find(tr);
				if (newId >= 0)
				{
					const char* p3rdTokenToEol = strchr(line.Get(), ' ');
					if (p3rdTokenToEol) p3rdTokenToEol = strchr((char*)(p3rdTokenToEol+1), ' ');
					if (p3rdTokenToEol)
					{
						WDL_FastString newRcv;
						newRcv.SetFormatted(SNM_MAX_CHUNK_LINE_LENGTH, "AUXRECV %d%s\n", newId, p3rdTokenToEol);
						replaced = p.ReplaceLine(pos, newRcv.Get());
						if (replaced)
							occurence++;
					}
				}
			}
		}

		if (!replaced)
			replaced = p.ReplaceLine(pos, "");
		if (!replaced) // skip, just in case..
			occurence++;

		line.Set("");
		pos = p.Parse(SNM_GET_SUBCHUNK_OR_LINE, 1, "TRACK", "AUXRECV", occurence, 1, &line);
	}
}