// 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 AddString(const WDL_FastString &s) { WDL_FastString *ns = new WDL_FastString; *ns = s; m_strings.Add(ns); return m_strings.GetSize()-1+STRING_INDEX_BASE; }
int sInst::runcode(const char *code, bool showerr, bool canfree) { if (m_vm) { m_pc.Set(""); eel_preprocess_strings(this,m_pc,code); NSEEL_CODEHANDLE code = NSEEL_code_compile_ex(m_vm,m_pc.Get(),1,canfree ? 0 : NSEEL_CODE_COMPILE_FLAG_COMMONFUNCS); char *err; if (!code && (err=NSEEL_code_getcodeerror(m_vm))) { if (NSEEL_code_geterror_flag(m_vm)&1) return 1; if (showerr) fprintf(stderr,"NSEEL_code_compile: %s\n",err); return -1; } else { if (code) { NSEEL_VM_enumallvars(m_vm,varEnumProc, this); NSEEL_code_execute(code); if (canfree) NSEEL_code_free(code); else m_code_freelist.Add((void*)code); } return 0; } } return -1; }
void Add(LICE_IBitmap* bitmap, int id = -1) { WDL_MutexLock lock(&m_mutex); BitmapKey* key = m_bitmaps.Add(new BitmapKey); key->id = id; key->bitmap = bitmap; }
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; }
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); }
void Add(LICE_IFont* font, IText* pTxt) { WDL_MutexLock lock(&m_mutex); FontKey* key = m_fonts.Add(new FontKey); key->size = pTxt->mSize; key->orientation = pTxt->mOrientation; key->style = pTxt->mStyle; strcpy(key->face, pTxt->mFont); key->font = font; }
void FillHWoutDropDown(HWND _hwnd, int _idc) { char buf[128] = ""; lstrcpyn(buf, __LOCALIZE("None","sws_DLG_149"), sizeof(buf)); SendDlgItemMessage(_hwnd,_idc,CB_ADDSTRING,0,(LPARAM)buf); SendDlgItemMessage(_hwnd,_idc,CB_SETITEMDATA,0,0); // get mono outputs WDL_PtrList<WDL_FastString> monos; int monoIdx=0; while (GetOutputChannelName(monoIdx)) { monos.Add(new WDL_FastString(GetOutputChannelName(monoIdx))); monoIdx++; } // add stereo outputs WDL_PtrList<WDL_FastString> stereos; if (monoIdx) { for(int i=0; i < (monoIdx-1); i++) { WDL_FastString* hw = new WDL_FastString(); hw->SetFormatted(256, "%s / %s", monos.Get(i)->Get(), monos.Get(i+1)->Get()); stereos.Add(hw); } } // fill dropdown for(int i=0; i < stereos.GetSize(); i++) { SendDlgItemMessage(_hwnd,_idc,CB_ADDSTRING,0,(LPARAM)stereos.Get(i)->Get()); SendDlgItemMessage(_hwnd,_idc,CB_SETITEMDATA,i,i+1); // +1 for <none> } for(int i=0; i < monos.GetSize(); i++) { SendDlgItemMessage(_hwnd,_idc,CB_ADDSTRING,0,(LPARAM)monos.Get(i)->Get()); SendDlgItemMessage(_hwnd,_idc,CB_SETITEMDATA,i,i+1); // +1 for <none> } // SendDlgItemMessage(_hwnd,_idc,CB_SETCURSEL,x0,0); monos.Empty(true); stereos.Empty(true); }
int AddFontResourceEx(LPCTSTR str, DWORD fl, void *pdv) { if (str && *str) { int x; for (x=0;x<s_registered_fonts.GetSize();x++) if (!strcmp(str,s_registered_fonts.Get(x))) return 0; s_registered_fonts.Add(strdup(str)); return 1; } return 0; }
WDL_PtrList<void>* FilteredVisState::GetFilteredTracks() { static WDL_PtrList<void> tracks; tracks.Empty(false); for (int i = 1; i <= GetNumTracks(); i++) { MediaTrack* tr = CSurf_TrackFromID(i, false); if (MatchesFilter(tr)) tracks.Add(tr); } return &tracks; }
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; }
// callers must unallocate the returned value, if any WDL_PtrList<MediaTrack>* GetChildTracks(MediaTrack* _tr) { int depth = (_tr ? *(int*)GetSetMediaTrackInfo(_tr, "I_FOLDERDEPTH", NULL) : 0); if (depth == 1) { WDL_PtrList<MediaTrack>* childTracks = new WDL_PtrList<MediaTrack>; int trIdx = CSurf_TrackToID(_tr, false) + 1; while (depth > 0 && trIdx <= GetNumTracks()) { MediaTrack* tr = CSurf_TrackFromID(trIdx, false); depth += *(int*)GetSetMediaTrackInfo(tr, "I_FOLDERDEPTH", NULL); childTracks->Add(tr); trIdx++; } if (childTracks->GetSize()) return childTracks; else delete childTracks; } return NULL; }
void AddLeftItem(COMMAND_T* = NULL) { for (int i = 1; i <= GetNumTracks(); i++) { MediaTrack* tr = CSurf_TrackFromID(i, false); WDL_PtrList<void> selItems; // First find selected items for (int j = 0; j < GetTrackNumMediaItems(tr); j++) { MediaItem* selItem = GetTrackMediaItem(tr, j); if (*(bool*)GetSetMediaItemInfo(selItem, "B_UISEL", NULL)) selItems.Add(selItem); } for (int j = 0; j < selItems.GetSize(); j++) { double dLeft = *(double*)GetSetMediaItemInfo((MediaItem*)selItems.Get(j), "D_POSITION", NULL); double dRight = *(double*)GetSetMediaItemInfo((MediaItem*)selItems.Get(j), "D_LENGTH", NULL) + dLeft; double dMaxLeft = -DBL_MAX; MediaItem* leftItem = NULL; for (int k = 0; k < GetTrackNumMediaItems(tr); k++) { MediaItem* mi; mi = GetTrackMediaItem(tr, k); double dLeft2 = *(double*)GetSetMediaItemInfo(mi, "D_POSITION", NULL); double dRight2 = *(double*)GetSetMediaItemInfo(mi, "D_LENGTH", NULL) + dLeft2; if (dLeft2 < dLeft && dRight2 < dRight && dLeft2 > dMaxLeft) { dMaxLeft = dLeft2; leftItem = mi; } } if (leftItem) GetSetMediaItemInfo(leftItem, "B_UISEL", &g_i1); } } UpdateTimeline(); }
int audioStreamer_waveOut::Open(int iswrite, int srate, int nch, int bps, int sleep, int nbufs, int bufsize, int device) { m_sleep = WO_SLEEP; m_nch = nch; m_srate=srate; m_bps=bps; int fmt_align=(bps>>3)*nch; int fmt_mul=fmt_align*srate; WAVEFORMATEX wfx={ WAVE_FORMAT_PCM, nch, srate, fmt_mul, fmt_align, bps, 0 }; m_bufsize=bufsize; m_whichbuf=0; if (iswrite) { if(waveOutOpen(&m_hwo,device,&wfx,(DWORD)0,0,WAVE_FORMAT_DIRECT)!=MMSYSERR_NOERROR) return -1; } else { if(waveInOpen(&m_hwi,device,&wfx,0,0,WAVE_FORMAT_DIRECT)!=MMSYSERR_NOERROR) return -1; } int x; for (x = 0; x < nbufs; x ++) { WDL_HeapBuf *p=new WDL_HeapBuf; p->Resize(sizeof(WAVEHDR) + m_bufsize); WAVEHDR *h = (WAVEHDR *)p->Get(); memset(h,0,p->GetSize()); h->lpData=(char *)h + sizeof(WAVEHDR); h->dwBufferLength = m_bufsize; if (!iswrite) { waveInPrepareHeader(m_hwi,h,sizeof(WAVEHDR)); waveInAddBuffer(m_hwi,h,sizeof(WAVEHDR)); } else { waveOutPrepareHeader(m_hwo,h,sizeof(WAVEHDR)); } m_bufs.Add(p); } if (iswrite) waveOutRestart(m_hwo); else waveInStart(m_hwi); return 0; }
// apply a track template (preserves routings and folder states) // _p: optional (to factorize chunk updates) // note: assumes _tmplt contains a single track (with items/envs already removed when _itemsFromTmplt/_envsFromTmplt are false) // i.e. use MakeSingleTrackTemplateChunk() first! bool ApplyTrackTemplate(MediaTrack* _tr, WDL_FastString* _tmplt, bool _itemsFromTmplt, bool _envsFromTmplt, void* _p) { bool updated = false; if (_tr && _tmplt && _tmplt->GetLength()) { SNM_SendPatcher* p = (_p ? (SNM_SendPatcher*)_p : new SNM_SendPatcher(_tr)); // store receives, folder and compact states WDL_PtrList_DeleteOnDestroy<WDL_PtrList_DeleteOnDestroy<SNM_SndRcv> > rcvs; WDL_PtrList_DeleteOnDestroy<WDL_PtrList_DeleteOnDestroy<SNM_SndRcv> > snds; WDL_PtrList<MediaTrack> trs; trs.Add(_tr); WDL_FastString busLine, compbusLine; if (_tr != GetMasterTrack(NULL)) { CopySendsReceives(true, &trs, &snds, &rcvs); // parse twice but it does not cost much (search at the very start of the chunk) p->Parse(SNM_GET_SUBCHUNK_OR_LINE, 1, "TRACK", "ISBUS", 0, -1, &busLine, NULL, "BUSCOMP"); p->Parse(SNM_GET_SUBCHUNK_OR_LINE, 1, "TRACK", "BUSCOMP", 0, -1, &compbusLine, NULL, "SHOWINMIX"); } // apply tr template if ((updated = ApplyTrackTemplatePrimitive(_tr, _tmplt, _itemsFromTmplt, _envsFromTmplt, p))) { // restore receives, folder and compact states WDL_PtrList<SNM_ChunkParserPatcher> ps; ps.Add(p); PasteSendsReceives(&trs, &snds, &rcvs, &ps); if (busLine.GetLength()) p->ReplaceLine("TRACK", "ISBUS", 1, 0, busLine.Get(), "BUSCOMP"); if (compbusLine.GetLength()) p->ReplaceLine("TRACK", "BUSCOMP", 1, 0, compbusLine.Get(), "SHOWINMIX"); } /*JFB!! works with SNM_ChunkParserPatcher v2 + "SNM_SendPatcher" to remove // store current receives, folder and compact states // done through the chunk because the API is incomplete for folder states (tcp only) WDL_FastString rcvs, busLine, compbusLine; if (_tr != GetMasterTrack(NULL)) { // parse twice but it does not cost much (search at the very start of the chunk) p->Parse(SNM_GET_SUBCHUNK_OR_LINE, 1, "TRACK", "AUXRECV", -1, -1, &rcvs, NULL, "MIDIOUT"); p->Parse(SNM_GET_SUBCHUNK_OR_LINE, 1, "TRACK", "ISBUS", 0, -1, &busLine, NULL, "BUSCOMP"); p->Parse(SNM_GET_SUBCHUNK_OR_LINE, 1, "TRACK", "BUSCOMP", 0, -1, &compbusLine, NULL, "SHOWINMIX"); } // apply tr template if (updated = ApplyTrackTemplatePrimitive(_tr, _tmpltChunk, _itemsFromTmplt, _envsFromTmplt, p)) { // restore receives, folder and compact states if (busLine.GetLength()) p->ReplaceLine("TRACK", "ISBUS", 1, 0, busLine.Get(), "BUSCOMP"); if (compbusLine.GetLength()) p->ReplaceLine("TRACK", "BUSCOMP", 1, 0, compbusLine.Get(), "SHOWINMIX"); if (rcvs.GetLength()) p->InsertAfterBefore(0, rcvs.Get(), "TRACK", "MIDIOUT", 1, 0, "MAINSEND"); } */ if (!_p) DELETE_NULL(p); // + auto-commit if needed } return updated; }
INT_PTR WINAPI doDebug(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { RestoreWindowPos(hwndDlg, DEBUG_WINDOWPOS_KEY); HWND listView = GetDlgItem(hwndDlg, IDC_LIST); LineParser lp(false); char cFile[256]; strcpy(cFile, get_ini_file()); strcpy(strrchr(cFile, '.'), "-kb.ini"); FILE* f = fopen(cFile, "r"); char cLine[65536]; int i = 0; LVITEM item; item.mask = LVIF_TEXT | LVIF_PARAM; item.iSubItem = 0; while (f && fgets(cLine, 65536, f)) { lp.parse(cLine); if (lp.getnumtokens() - 5 > 0 && strcmp(lp.gettoken_str(0), "ACT") == 0) { Macro* m = g_macros.Add(new Macro(&lp)); item.lParam = (LPARAM)m; item.iItem = i++; item.pszText = m->m_cName; ListView_InsertItem(listView, &item); } } if (f) fclose(f); ListView_SortItems(listView, MacroSort, 0); return 0; } case WM_NOTIFY: { NMLISTVIEW* s = (NMLISTVIEW*)lParam; if (s->hdr.code == LVN_ITEMCHANGED && s->uNewState & LVIS_SELECTED) g_selectedMacro = (Macro*)s->lParam; break; } case WM_COMMAND: //if you need to debug commands, you probably want to ignore the focus stuff. Break a few lines down. if (wParam == 33555433 || wParam == 16778217) return 0; if (LOWORD(wParam)==IDCANCEL) { g_selectedMacro = NULL; SaveWindowPos(hwndDlg, DEBUG_WINDOWPOS_KEY); EndDialog(hwndDlg,0); } if (LOWORD(wParam)==IDOK) { SaveWindowPos(hwndDlg, DEBUG_WINDOWPOS_KEY); EndDialog(hwndDlg,0); } return 0; case WM_DESTROY: // We're done return 0; } return 0; }
int WDL_CursesEditor::onChar(int c) { if (m_state == -3 || m_state == -4) { switch (c) { case '\r': case '\n': m_state=0; runSearch(); break; case 27: m_state=0; draw(); setCursor(); draw_message("Find cancelled."); break; case KEY_BACKSPACE: if (s_search_string[0]) s_search_string[strlen(s_search_string)-1]=0; m_state=-4; break; default: if (VALIDATE_TEXT_CHAR(c)) { int l=m_state == -3 ? 0 : strlen(s_search_string); m_state = -4; if (l < (int)sizeof(s_search_string)-1) { s_search_string[l]=c; s_search_string[l+1]=0; } } break; } if (m_state) { attrset(m_color_message); bkgdset(m_color_message); mvaddstr(LINES-1,29,s_search_string); clrtoeol(); attrset(0); bkgdset(0); } return 0; } if (c==KEY_DOWN || c==KEY_UP || c==KEY_PPAGE||c==KEY_NPAGE || c==KEY_RIGHT||c==KEY_LEFT||c==KEY_HOME||c==KEY_END) { if (SHIFT_KEY_DOWN) { if (!m_selecting) { m_select_x2=m_select_x1=m_curs_x; m_select_y2=m_select_y1=m_curs_y; m_selecting=1; } } else if (m_selecting) { m_selecting=0; draw(); } } switch(c) { case 'O'-'A'+1: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN) { if (m_pane_div <= 0.0 || m_pane_div >= 1.0) { onChar('P'-'A'+1); } if (m_pane_div > 0.0 && m_pane_div < 1.0) { m_curpane=!m_curpane; draw(); draw_status_state(); int paney[2], paneh[2]; GetPaneDims(paney, paneh); if (m_curs_y-m_paneoffs_y[m_curpane] < 0) m_curs_y=m_paneoffs_y[m_curpane]; else if (m_curs_y-m_paneoffs_y[m_curpane] >= paneh[m_curpane]) m_curs_y=paneh[m_curpane]+m_paneoffs_y[m_curpane]-1; setCursor(); } } break; case 'P'-'A'+1: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN) { if (m_pane_div <= 0.0 || m_pane_div >= 1.0) { m_pane_div=0.5; m_paneoffs_y[1]=m_paneoffs_y[0]; } else { m_pane_div=1.0; if (m_curpane) m_paneoffs_y[0]=m_paneoffs_y[1]; m_curpane=0; } draw(); draw_status_state(); int paney[2], paneh[2]; const int pane_divy=GetPaneDims(paney, paneh); setCursor(); } break; case 407: case 'Z'-'A'+1: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN) { if (m_undoStack_pos > 0) { m_undoStack_pos--; loadUndoState(m_undoStack.Get(m_undoStack_pos)); draw(); setCursor(); char buf[512]; snprintf(buf,sizeof(buf),"Undid action - %d items in undo buffer",m_undoStack_pos); draw_message(buf); } else { draw_message("Can't Undo"); } break; } // fall through case 'Y'-'A'+1: if ((c == 'Z'-'A'+1 || !SHIFT_KEY_DOWN) && !ALT_KEY_DOWN) { if (m_undoStack_pos < m_undoStack.GetSize()-1) { m_undoStack_pos++; loadUndoState(m_undoStack.Get(m_undoStack_pos)); draw(); setCursor(); char buf[512]; snprintf(buf,sizeof(buf),"Redid action - %d items in redo buffer",m_undoStack.GetSize()-m_undoStack_pos-1); draw_message(buf); } else { draw_message("Can't Redo"); } } break; case KEY_IC: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN) { s_overwrite=!s_overwrite; setCursor(); break; } // fqll through case 'V'-'A'+1: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN) { // generate a m_clipboard using win32 clipboard data WDL_PtrList<const char> lines; WDL_String buf; #ifdef WDL_IS_FAKE_CURSES if (CURSES_INSTANCE) { OpenClipboard(CURSES_INSTANCE->m_hwnd); HANDLE h=GetClipboardData(CF_TEXT); if (h) { char *t=(char *)GlobalLock(h); int s=GlobalSize(h); buf.Set(t,s); GlobalUnlock(t); } CloseClipboard(); } else #endif { buf.Set(s_fake_clipboard.Get()); } if (buf.Get() && buf.Get()[0]) { char *src=buf.Get(); while (*src) { char *seek=src; while (*seek && *seek != '\r' && *seek != '\n') seek++; char hadclr=*seek; if (*seek) *seek++=0; lines.Add(src); if (hadclr == '\r' && *seek == '\n') seek++; if (hadclr && !*seek) { lines.Add(""); } src=seek; } } if (lines.GetSize()) { removeSelect(); // insert lines at m_curs_y,m_curs_x if (m_curs_y >= m_text.GetSize()) m_curs_y=m_text.GetSize()-1; if (m_curs_y < 0) m_curs_y=0; preSaveUndoState(); WDL_FastString poststr; int x; int indent_to_pos = -1; for (x = 0; x < lines.GetSize(); x ++) { WDL_FastString *str=m_text.Get(m_curs_y); const char *tstr=lines.Get(x); if (!tstr) tstr=""; if (!x) { if (str) { if (m_curs_x < 0) m_curs_x=0; int tmp=str->GetLength(); if (m_curs_x > tmp) m_curs_x=tmp; poststr.Set(str->Get()+m_curs_x); str->SetLen(m_curs_x); const char *p = str->Get(); while (*p == ' ' || *p == '\t') p++; if (!*p && p > str->Get()) { if (lines.GetSize()>1) { while (*tstr == ' ' || *tstr == '\t') tstr++; } indent_to_pos = m_curs_x; } str->Append(tstr); } else { m_text.Insert(m_curs_y,(str=new WDL_FastString(tstr))); } if (lines.GetSize() > 1) { m_curs_y++; } else { m_curs_x = str->GetLength(); str->Append(poststr.Get()); } } else if (x == lines.GetSize()-1) { WDL_FastString *s=newIndentedFastString(tstr,indent_to_pos); m_curs_x = s->GetLength(); s->Append(poststr.Get()); m_text.Insert(m_curs_y,s); } else { m_text.Insert(m_curs_y,newIndentedFastString(tstr,indent_to_pos)); m_curs_y++; } } draw(); setCursor(); draw_message("Pasted"); saveUndoState(); } else { setCursor(); draw_message("Clipboard empty"); } } break; case KEY_DC: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN) { WDL_FastString *s; if (m_selecting) { preSaveUndoState(); removeSelect(); draw(); saveUndoState(); setCursor(); } else if ((s=m_text.Get(m_curs_y))) { if (m_curs_x < s->GetLength()) { preSaveUndoState(); bool hadCom = LineCanAffectOtherLines(s->Get(),m_curs_x,1); s->DeleteSub(m_curs_x,1); if (!hadCom) hadCom = LineCanAffectOtherLines(s->Get(),-1,-1); draw(hadCom ? -1 : m_curs_y); saveUndoState(); setCursor(); } else // append next line to us { if (m_curs_y < m_text.GetSize()-1) { preSaveUndoState(); WDL_FastString *nl=m_text.Get(m_curs_y+1); if (nl) { s->Append(nl->Get()); } m_text.Delete(m_curs_y+1,true); draw(); saveUndoState(); setCursor(); } } } break; } case 'C'-'A'+1: case 'X'-'A'+1: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN && m_selecting) { if (c!= 'C'-'A'+1) m_selecting=0; int miny,maxy,minx,maxx; int x; getselectregion(minx,miny,maxx,maxy); const char *status=""; char statusbuf[512]; if (minx != maxx|| miny != maxy) { int bytescopied=0; s_fake_clipboard.Set(""); int lht=0,fht=0; if (c != 'C'-'A'+1) preSaveUndoState(); for (x = miny; x <= maxy; x ++) { WDL_FastString *s=m_text.Get(x); if (s) { const char *str=s->Get(); int sx,ex; if (x == miny) sx=max(minx,0); else sx=0; int tmp=s->GetLength(); if (sx > tmp) sx=tmp; if (x == maxy) ex=min(maxx,tmp); else ex=tmp; bytescopied += ex-sx + (x!=maxy); if (s_fake_clipboard.Get() && s_fake_clipboard.Get()[0]) s_fake_clipboard.Append("\r\n"); s_fake_clipboard.Append(ex-sx?str+sx:"",ex-sx); if (c != 'C'-'A'+1) { if (sx == 0 && ex == tmp) // remove entire line { m_text.Delete(x,true); if (x==miny) miny--; x--; maxy--; } else { if (x==miny) fht=1; if (x == maxy) lht=1; s->DeleteSub(sx,ex-sx); } } } } if (fht && lht && miny+1 == maxy) { m_text.Get(miny)->Append(m_text.Get(maxy)->Get()); m_text.Delete(maxy,true); } if (c != 'C'-'A'+1) { m_curs_y=miny; if (m_curs_y < 0) m_curs_y=0; m_curs_x=minx; saveUndoState(); snprintf(statusbuf,sizeof(statusbuf),"Cut %d bytes",bytescopied); } else snprintf(statusbuf,sizeof(statusbuf),"Copied %d bytes",bytescopied); #ifdef WDL_IS_FAKE_CURSES if (CURSES_INSTANCE) { int l=s_fake_clipboard.GetLength()+1; HANDLE h=GlobalAlloc(GMEM_MOVEABLE,l); void *t=GlobalLock(h); memcpy(t,s_fake_clipboard.Get(),l); GlobalUnlock(h); OpenClipboard(CURSES_INSTANCE->m_hwnd); EmptyClipboard(); SetClipboardData(CF_TEXT,h); CloseClipboard(); } #endif status=statusbuf; } else status="No selection"; draw(); setCursor(); draw_message(status); } break; case 'A'-'A'+1: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN) { m_selecting=1; m_select_x1=0; m_select_y1=0; m_select_y2=m_text.GetSize()-1; m_select_x2=0; if (m_text.Get(m_select_y2)) m_select_x2=m_text.Get(m_select_y2)->GetLength(); draw(); setCursor(); } break; case 27: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN && m_selecting) { m_selecting=0; draw(); setCursor(); break; } break; case KEY_F3: case 'G'-'A'+1: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN && s_search_string[0]) { runSearch(); return 0; } // fall through case 'F'-'A'+1: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN) { draw_message(""); attrset(m_color_message); bkgdset(m_color_message); mvaddstr(LINES-1,0,"Find string (ESC to cancel): "); if (m_selecting && m_select_y1==m_select_y2) { WDL_FastString* s=m_text.Get(m_select_y1); if (s) { const char* p=s->Get(); int xlo=min(m_select_x1, m_select_x2); int xhi=max(m_select_x1, m_select_x2); int i; for (i=xlo; i < xhi; ++i) { if (!isalnum(p[i]) && p[i] != '_') break; } if (i == xhi && xhi > xlo && xhi-xlo < sizeof(s_search_string)) { lstrcpyn(s_search_string, p+xlo, xhi-xlo+1); } } } addstr(s_search_string); clrtoeol(); attrset(0); bkgdset(0); m_state=-3; // find, initial (m_state=4 when we've typed something) } break; case KEY_DOWN: { if (CTRL_KEY_DOWN) { int paney[2], paneh[2]; GetPaneDims(paney, paneh); int maxscroll=m_text.GetSize()-paneh[m_curpane]+4; if (m_paneoffs_y[m_curpane] < maxscroll-1) { m_paneoffs_y[m_curpane]++; if (m_curs_y < m_paneoffs_y[m_curpane]) m_curs_y=m_paneoffs_y[m_curpane]; draw(); } } else { m_curs_y++; if (m_curs_y>=m_text.GetSize()) m_curs_y=m_text.GetSize()-1; if (m_curs_y < 0) m_curs_y=0; } if (m_selecting) { setCursor(1); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); } setCursor(1); } break; case KEY_UP: { if (CTRL_KEY_DOWN) { if (m_paneoffs_y[m_curpane] > 0) { int paney[2], paneh[2]; GetPaneDims(paney, paneh); m_paneoffs_y[m_curpane]--; if (m_curs_y > m_paneoffs_y[m_curpane]+paneh[m_curpane]-1) m_curs_y = m_paneoffs_y[m_curpane]+paneh[m_curpane]-1; if (m_curs_y < 0) m_curs_y=0; draw(); } } else { if(m_curs_y>0) m_curs_y--; } if (m_selecting) { setCursor(1); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); } setCursor(1); } break; case KEY_PPAGE: { if (m_curs_y > m_paneoffs_y[m_curpane]) { m_curs_y=m_paneoffs_y[m_curpane]; if (m_curs_y < 0) m_curs_y=0; } else { int paney[2], paneh[2]; GetPaneDims(paney, paneh); m_curs_y -= paneh[m_curpane]; if (m_curs_y < 0) m_curs_y=0; m_paneoffs_y[m_curpane]=m_curs_y; } if (m_selecting) { setCursor(1); m_select_x2=m_curs_x; m_select_y2=m_curs_y; } draw(); setCursor(1); } break; case KEY_NPAGE: { int paney[2], paneh[2]; GetPaneDims(paney, paneh); if (m_curs_y >= m_paneoffs_y[m_curpane]+paneh[m_curpane]-1) m_paneoffs_y[m_curpane]=m_curs_y-1; m_curs_y = m_paneoffs_y[m_curpane]+paneh[m_curpane]-1; if (m_curs_y >= m_text.GetSize()) m_curs_y=m_text.GetSize()-1; if (m_curs_y < 0) m_curs_y=0; if (m_selecting) { setCursor(1); m_select_x2=m_curs_x; m_select_y2=m_curs_y; } draw(); setCursor(1); } break; case KEY_RIGHT: { if (1) // wrap across lines { WDL_FastString *s = m_text.Get(m_curs_y); if (s && m_curs_x >= s->GetLength() && m_curs_y < m_text.GetSize()) { m_curs_y++; m_curs_x = -1; } } if(m_curs_x<0) { m_curs_x=0; } else { if (CTRL_KEY_DOWN) { WDL_FastString *s = m_text.Get(m_curs_y); if (!s||m_curs_x >= s->GetLength()) break; int lastType = categorizeCharForWordNess(s->Get()[m_curs_x++]); while (m_curs_x < s->GetLength()) { int thisType = categorizeCharForWordNess(s->Get()[m_curs_x]); if (thisType != lastType && thisType != 0) break; lastType=thisType; m_curs_x++; } } else { m_curs_x++; } } if (m_selecting) { setCursor(); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); } setCursor(); } break; case KEY_LEFT: { bool doMove=true; if (1) // wrap across lines { WDL_FastString *s = m_text.Get(m_curs_y); if (s && m_curs_y>0 && m_curs_x == 0) { s = m_text.Get(--m_curs_y); if (s) { m_curs_x = s->GetLength(); doMove=false; } } } if(m_curs_x>0 && doMove) { if (CTRL_KEY_DOWN) { WDL_FastString *s = m_text.Get(m_curs_y); if (!s) break; if (m_curs_x > s->GetLength()) m_curs_x = s->GetLength(); m_curs_x--; int lastType = categorizeCharForWordNess(s->Get()[m_curs_x--]); while (m_curs_x >= 0) { int thisType = categorizeCharForWordNess(s->Get()[m_curs_x]); if (thisType != lastType && lastType != 0) break; lastType=thisType; m_curs_x--; } m_curs_x++; } else { m_curs_x--; } } if (m_selecting) { setCursor(); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); } setCursor(); } break; case KEY_HOME: { m_curs_x=0; if (CTRL_KEY_DOWN) m_curs_y=0; if (m_selecting) { setCursor(); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); } setCursor(); } break; case KEY_END: { if (m_text.Get(m_curs_y)) m_curs_x=m_text.Get(m_curs_y)->GetLength(); if (CTRL_KEY_DOWN) m_curs_y=m_text.GetSize(); if (m_selecting) { setCursor(); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); } setCursor(); } break; case KEY_BACKSPACE: // backspace, baby if (m_selecting) { preSaveUndoState(); removeSelect(); draw(); saveUndoState(); setCursor(); } else if (m_curs_x > 0) { WDL_FastString *tl=m_text.Get(m_curs_y); if (tl) { preSaveUndoState(); bool hadCom = LineCanAffectOtherLines(tl->Get(), m_curs_x-1,1); tl->DeleteSub(--m_curs_x,1); if (!hadCom) hadCom = LineCanAffectOtherLines(tl->Get(),-1,-1); draw(hadCom?-1:m_curs_y); saveUndoState(); setCursor(); } } else // append current line to previous line { WDL_FastString *fl=m_text.Get(m_curs_y-1), *tl=m_text.Get(m_curs_y); if (!tl) { m_curs_y--; if (fl) m_curs_x=fl->GetLength(); draw(); saveUndoState(); setCursor(); } else if (fl) { preSaveUndoState(); m_curs_x=fl->GetLength(); fl->Append(tl->Get()); m_text.Delete(m_curs_y--,true); draw(); saveUndoState(); setCursor(); } } break; case 'L'-'A'+1: if (!SHIFT_KEY_DOWN && !ALT_KEY_DOWN) { draw(); setCursor(); } break; case 13: //KEY_ENTER: //insert newline preSaveUndoState(); if (m_selecting) { removeSelect(); draw(); setCursor(); } if (m_curs_y >= m_text.GetSize()) { m_curs_y=m_text.GetSize(); m_text.Add(new WDL_FastString); } if (s_overwrite) { WDL_FastString *s = m_text.Get(m_curs_y); int plen=0; const char *pb=NULL; if (s) { pb = s->Get(); while (plen < m_curs_x && (pb[plen]== ' ' || pb[plen] == '\t')) plen++; } if (++m_curs_y >= m_text.GetSize()) { m_curs_y = m_text.GetSize(); WDL_FastString *ns=new WDL_FastString; if (plen>0) ns->Set(pb,plen); m_text.Insert(m_curs_y,ns); } s = m_text.Get(m_curs_y); if (s && plen > s->GetLength()) plen=s->GetLength(); m_curs_x=plen; } else { WDL_FastString *s = m_text.Get(m_curs_y); if (s) { if (m_curs_x > s->GetLength()) m_curs_x = s->GetLength(); WDL_FastString *nl = new WDL_FastString(); int plen=0; const char *pb = s->Get(); while (plen < m_curs_x && (pb[plen]== ' ' || pb[plen] == '\t')) plen++; if (plen>0) nl->Set(pb,plen); nl->Append(pb+m_curs_x); m_text.Insert(++m_curs_y,nl); s->SetLen(m_curs_x); m_curs_x=plen; } } m_offs_x=0; draw(); saveUndoState(); setCursor(); break; case '\t': if (m_selecting) { preSaveUndoState(); bool isRev = !!(GetAsyncKeyState(VK_SHIFT)&0x8000); indentSelect(isRev?-m_indent_size:m_indent_size); // indent selection: draw(); setCursor(); saveUndoState(); break; } default: //insert char if(VALIDATE_TEXT_CHAR(c)) { preSaveUndoState(); if (m_selecting) { removeSelect(); draw(); setCursor(); } if (!m_text.Get(m_curs_y)) m_text.Insert(m_curs_y,new WDL_FastString); WDL_FastString *ss; if ((ss=m_text.Get(m_curs_y))) { char str[64]; int slen ; if (c == '\t') { slen = min(m_indent_size,64); if (slen<1) slen=1; int x; for(x=0;x<slen;x++) str[x]=' '; } else { str[0]=c; slen = 1; } bool hadCom = LineCanAffectOtherLines(ss->Get(),-1,-1); if (s_overwrite) { if (!hadCom) hadCom = LineCanAffectOtherLines(ss->Get(),m_curs_x,slen); ss->DeleteSub(m_curs_x,slen); } ss->Insert(str,m_curs_x,slen); if (!hadCom) hadCom = LineCanAffectOtherLines(ss->Get(),m_curs_x,slen); m_curs_x += slen; draw(hadCom ? -1 : m_curs_y); } saveUndoState(); setCursor(); } break; } return 0; }
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); }
//JFB menu items are not localized here (ideally it should be done through __LOCALIZE() and not with the table command above). static void menuhook(const char* menustr, HMENU hMenu, int flag) { int menuid = -1; if (strcmp(menustr, "Track control panel context") == 0) menuid = 0; else if (strcmp(menustr, "Media item context") == 0) menuid = 1; if (menuid >= 0 && flag == 0) { // Initialize the menu void (*pFirstCommand)(COMMAND_T*); void (*pLastCommand)(COMMAND_T*); if (menuid == 0) { pFirstCommand = TrackRandomCol; pLastCommand = TrackCustCol; } else { pFirstCommand = ItemRandomCol; pLastCommand = ItemCustCol; } HMENU hSubMenu = CreatePopupMenu(); int i = 0; while (g_commandTable[i].doCommand != pFirstCommand) i++; do { AddToMenu(hSubMenu, __localizeFunc(g_commandTable[i].menuText,"sws_menu",0), g_commandTable[i].accel.accel.cmd); i++; } while (!(g_commandTable[i-1].doCommand == pLastCommand && g_commandTable[i-1].user == 15)); // Finish with color dialog AddToMenu(hSubMenu, __localizeFunc(g_commandTable[0].menuText,"sws_menu",0), g_commandTable[0].accel.accel.cmd); if (menuid == 0) AddSubMenu(hMenu, hSubMenu, __LOCALIZE("SWS track color","sws_menu"), 40359); else AddSubMenu(hMenu, hSubMenu, __LOCALIZE("SWS item color","sws_menu"), 40707); } #ifdef _WIN32 else if (flag == 1) { // Update the color swatches // Color commands can be anywhere on the menu, so find 'em no matter where static WDL_PtrList<void> pBitmaps; HDC hdcScreen = NULL; HDC hDC = NULL; if (pBitmaps.GetSize() == 0) { hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); int s = GetSystemMetrics(SM_CYMENUCHECK); UpdateCustomColors(); for (int i = 0; i < 16; i++) pBitmaps.Add(CreateCompatibleBitmap(hdcScreen, s+3, s)); } int iCommand1 = SWSGetCommandID(TrackCustCol, 0); int iCommand2 = SWSGetCommandID(ItemCustCol, 0); for (int i = 0; i < 32; i++) { int iPos; HMENU h; if (i < 16) h = FindMenuItem(hMenu, iCommand1 + i, &iPos); else h = FindMenuItem(hMenu, iCommand2 + i-16, &iPos); if (h) { if (!hDC) { // Reduce thrashing UpdateCustomColors(); if (!hdcScreen) hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); hDC = CreateCompatibleDC(hdcScreen); } int s = GetSystemMetrics(SM_CYMENUCHECK); RECT rColor = { 0, 0, s, s }; RECT rSpace = { s, 0, s+3, s }; SelectObject(hDC, pBitmaps.Get(i%16)); HBRUSH hb = CreateSolidBrush(g_custColors[i%16]); FillRect(hDC, &rColor, hb); DeleteObject(hb); FillRect(hDC, &rSpace, (HBRUSH)(COLOR_MENU+1)); MENUITEMINFO mi={sizeof(MENUITEMINFO),}; mi.fMask = MIIM_BITMAP; mi.hbmpItem = (HBITMAP)pBitmaps.Get(i%16); SetMenuItemInfo(h, iPos, true, &mi); } } if (hDC) DeleteDC(hDC); if (hdcScreen) DeleteDC(hdcScreen); } #endif }
static BOOL WINAPI RemoteChannelListProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static WDL_PtrList<struct HWND__> m_children; switch (uMsg) { case WM_INITDIALOG: { } break; case WM_LCUSER_VUUPDATE: { HWND hwnd=GetWindow(hwndDlg,GW_CHILD); while (hwnd) { SendMessage(hwnd,uMsg,0,0); hwnd=GetWindow(hwnd,GW_HWNDNEXT); } } break; case WM_RCUSER_UPDATE: { int pos=0; int us; int did_sizing=0; RECT lastr={0,0,0,0}; g_client_mutex.Enter(); for (us = 0; us < g_client->GetNumUsers(); us ++) { // add/update a user divider { HWND h=NULL; if (pos < m_children.GetSize() && GetWindowLong(h=m_children.Get(pos),GWL_USERDATA) < 0) { // this is our wnd } else { if (h) DestroyWindow(h); h=CreateDialog(g_hInst,MAKEINTRESOURCE(IDD_REMOTEUSER),hwndDlg,RemoteUserItemProc); if (pos < m_children.GetSize()) m_children.Set(pos,h); else m_children.Add(h); ShowWindow(h,SW_SHOWNA); did_sizing=1; } SendMessage(h,WM_RCUSER_UPDATE,(WPARAM)us,0); RECT r; GetWindowRect(h,&r); ScreenToClient(hwndDlg,(LPPOINT)&r); if (r.top != lastr.bottom) { SetWindowPos(h,0, 0,lastr.bottom, 0,0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE); GetWindowRect(h,&lastr); } else lastr=r; ScreenToClient(hwndDlg,(LPPOINT)&lastr + 1); pos++; } int ch=0; for (;;) { int i=g_client->EnumUserChannels(us,ch++); if (i < 0) break; HWND h=NULL; if (pos < m_children.GetSize() && GetWindowLong(h=m_children.Get(pos),GWL_USERDATA) >= 0) { } else { if (h) DestroyWindow(h); h=CreateDialog(g_hInst,MAKEINTRESOURCE(IDD_REMOTECHANNEL),hwndDlg,RemoteChannelItemProc); if (pos < m_children.GetSize()) m_children.Set(pos,h); else m_children.Add(h); did_sizing=1; ShowWindow(h,SW_SHOWNA); } RECT r; GetWindowRect(h,&r); ScreenToClient(hwndDlg,(LPPOINT)&r); if (r.top != lastr.bottom) { SetWindowPos(h,0,0,lastr.bottom,0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE); GetWindowRect(h,&lastr); } else lastr=r; SendMessage(h,WM_RCUSER_UPDATE,(WPARAM)us,(LPARAM)i); ScreenToClient(hwndDlg,(LPPOINT)&lastr + 1); pos++; } } g_client_mutex.Leave(); for (; pos < m_children.GetSize(); ) { DestroyWindow(m_children.Get(pos)); m_children.Delete(pos); did_sizing=1; } if (did_sizing) { SetWindowPos(hwndDlg,NULL,0,0,lastr.right,lastr.bottom,SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); // size ourself } } // update channel list, creating and destroying window as necessary break; } return 0; }
// wrapper func.. // note: _tr=NULL + _unselOthers=true will unselect all tracks bool SNM_SetSelectedTrack(ReaProject* _proj, MediaTrack* _tr, bool _unselOthers, bool _withMaster) { WDL_PtrList<MediaTrack> trs; if (_tr) trs.Add(_tr); return SNM_SetSelectedTracks(_proj, &trs, _unselOthers, _withMaster); }
// 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); } }