void IGraphics::OnMouseDown(int x, int y, IMouseMod* pMod) { ReleaseMouseCapture(); int c = GetMouseControlIdx(x, y); if (c >= 0) { mMouseCapture = c; mMouseX = x; mMouseY = y; IControl* pControl = mControls.Get(c); int paramIdx = pControl->ParamIdx(); #if defined OS_WIN || defined VST3_API // on Mac, IGraphics.cpp is not compiled in a static library, so this can be #ifdef'd if (mPlug->GetAPI() == kAPIVST3) { if (pMod->R && paramIdx >= 0) { ReleaseMouseCapture(); mPlug->PopupHostContextMenuForParam(paramIdx, x, y); return; } } #endif #ifdef AAX_API if (mAAXViewContainer && paramIdx >= 0) { uint32_t mods = GetAAXModifiersFromIMouseMod(pMod); #ifdef OS_WIN // required to get start/windows and alt keys uint32_t aaxViewMods = 0; mAAXViewContainer->GetModifiers(&aaxViewMods); mods |= aaxViewMods; #endif WDL_String paramID; paramID.SetFormatted(32, "%i", paramIdx+1); if (mAAXViewContainer->HandleParameterMouseDown(paramID.Get(), mods) == AAX_SUCCESS) { return; // event handled by PT } } #endif if (paramIdx >= 0) { mPlug->BeginInformHostOfParamChange(paramIdx); } pControl->OnMouseDown(x, y, pMod); } }
void MainWnd::on_list_update() { WDL_PtrList<ShellAction> *actions = NULL; App *the_app = NULL; the_app = App::get(); actions = the_app->get_tasks(); #ifdef WIN32 HWND ctrl = GetDlgItem(m_hwnd, IDC_TASKS); int sel_id = -1; sel_id = ListView_GetCurSel(ctrl); ListView_DeleteAllItems(ctrl); if(!actions->GetSize()) return; for(int i = 0; i < actions->GetSize(); i++) { LVITEM lvitem; WDL_String tmp; char buf[128]; ShellAction *action = actions->Get(i); lvitem.mask = LVIF_TEXT | LVIF_PARAM; lvitem.iItem = i; lvitem.iSubItem = 0; lvitem.lParam = (LPARAM)action->get_id(); lvitem.cchTextMax = strlen(action->get_title()); lvitem.pszText = action->get_title(); ListView_InsertItem(ctrl, &lvitem); ListView_SetItemText(ctrl, i, 1, action->get_path()); tmp = "Every "; itoa(action->get_interval(), buf, 10); tmp.Append(buf); tmp.Append(" "); tmp.Append(RUN_TYPE_LABELS[action->get_interval_type()]); ListView_SetItemText(ctrl, i, 2, tmp.Get()); } if (sel_id >= 0 && m_selected_task) { ShellAction *action = the_app->get_task_by_id(sel_id + 1); the_app->activate_task(action); ListView_SetItemState(ctrl, sel_id, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); } #endif // WIN32 }
BOOL CALLBACK IGraphicsWin::FindMainWindow(HWND hWnd, LPARAM lParam) { IGraphicsWin* pGraphics = (IGraphicsWin*) lParam; if (pGraphics) { DWORD wPID; GetWindowThreadProcessId(hWnd, &wPID); WDL_String str; GetWndClassName(hWnd, &str); if (wPID == pGraphics->mPID && !strcmp(str.Get(), pGraphics->mMainWndClassName.Get())) { pGraphics->mMainWnd = hWnd; return FALSE; // Stop enumerating. } } return TRUE; }
void OpenRelatedProject(COMMAND_T* pCmd) { if ((int)pCmd->user == g_relatedProjects.Get()->GetSize()) // Give the user the chance to add a related project if they selected the first open spot if (MessageBox(g_hwndParent, __LOCALIZE("No related project found. Add one now?","sws_mbox"), __LOCALIZE("SWS Open Related Project","sws_mbox"), MB_YESNO) == IDYES) AddRelatedProject(); if ((int)pCmd->user >= g_relatedProjects.Get()->GetSize()) return; WDL_String* pStr = g_relatedProjects.Get()->Get((int)pCmd->user); ReaProject* pProj; // See if it's already opened char cOpenedProj[256]; int i = 0; while ((pProj = EnumProjects(i++, cOpenedProj, 256))) { if (_stricmp(cOpenedProj, pStr->Get()) == 0) { SelectProjectInstance(pProj); return; } } // Nope, open in new tab // Save "prompt on new project" variable int iNewProjOpts; int sztmp; int* pNewProjOpts = (int*)get_config_var("newprojdo", &sztmp); iNewProjOpts = *pNewProjOpts; *pNewProjOpts = 0; pProj = EnumProjects(-1, NULL, 0); Main_OnCommand(41929, 0); // New project tab (ignore default template) Main_openProject(pStr->Get()); EnumProjects(-1, cOpenedProj, 256); if (_stricmp(pStr->Get(), cOpenedProj)) { Main_OnCommand(40860, 0); // 40860 = Close current project tab SelectProjectInstance(pProj); g_relatedProjects.Get()->Delete((int)pCmd->user, true); } *pNewProjOpts = iNewProjOpts; }
void handleTeamStreamMsg(char* fullName , char* username , char* msgIn , bool isPrivate) { bool isEnableTeamStream = !strcmp(msgIn + TEAMSTREAM_CHAT_TRIGGER_LEN , "enabled") ; WDL_String msgOut ; msgOut.Set(username) ; msgOut.Append((isEnableTeamStream)? " is in TeamStream mode" : " is in NinJam mode") ; chat_addline(USERNAME_TEAMSTREAM , msgOut.Get()) ; int userId = TeamStream::AddUser(username , fullName) ; if (userId <= USERID_LOCAL) return ; if (!isEnableTeamStream || !TeamStream::IsTeamStreamUsernameCollision(username)) TeamStream::SetTeamStreamMode(userId , isEnableTeamStream) ; bool isFirstReply = (!TeamStream::GetNRemoteUsers()) ; if (isPrivate) { if (isFirstReply) TeamStream::SendLinksReqChatMsg(fullName) ; } else { TeamStream::SendTeamStreamChatMsg(true , fullName) ; TeamStream::SendChatColorChatMsg(true , fullName) ; } // TODO: we could combine SendTeamStreamChatMsg() with SendChatColorChatMsg() // TODO: in order for ID_TEAMSTREAM_LOAD/SAVE to work we need to check the current link order now // if (!isPrivate) and SetLink() now if match (i think this means bringing back the m_links array) // and to be sure to remove exitting users only from the listview but keep them in the array? }
const char* AppendTimestamp(const char* Mmm_dd_yyyy, const char* hh_mm_ss, const char* cStr) { static WDL_String str; str.Set(cStr); WDL_String tStr; CompileTimestamp(Mmm_dd_yyyy, hh_mm_ss, &tStr); str.Append(" "); str.Append(tStr.Get()); return str.Get(); }
void handleLinksMsg(char* senderUsername , char* msgIn) { WDL_String msgOut ; msgOut.Set("Link order:") ; int linkIdx ; int lastUsernameIdx = LINKS_CHAT_TRIGGER_LEN ; int usernameLen = -1 ; for (linkIdx = 0 ; linkIdx < N_LINKS ; ++linkIdx) { // parse username lastUsernameIdx += usernameLen + 1 ; usernameLen = -1 ; char aChar ; do aChar = msgIn[lastUsernameIdx + (++usernameLen)] ; while (aChar && aChar != ' ') ; if (!usernameLen) return ; char username[255] ; strncpy(username , msgIn + lastUsernameIdx , usernameLen) ; username[usernameLen] = '\0' ; #if IS_CHAT_LINKS // chat full link order int userId = TeamStream::GetUserIdByName(username) ; msgOut.Append("\n") ; char linkMsg[255] ; sprintf(linkMsg , "Link %d: %s" , linkIdx + 1 , username) ; msgOut.Append(linkMsg) ; if (userId == USERID_NOBODY && strcmp(username , USERNAME_NOBODY)) msgOut.Append(" is not here") ; #else IS_CHAT_LINKS int userId = TeamStream::GetUserIdByName(username) ; #endif IS_CHAT_LINKS // set link if (!isUsernameLocal(senderUsername)) if (TeamStream::IsUserIdReal(userId)) TeamStream::SetLink(userId , username , linkIdx , true) ; else TeamStream::Set_Link_GUI(USERID_NOBODY , username , linkIdx , N_LINKS) ; } #if IS_CHAT_LINKS chat_addline(USERNAME_TEAMSTREAM , msgOut.Get()) ; #endif IS_CHAT_LINKS }
WDL_String TeamStream::ParseCommandLineHost(LPSTR cmdParam) { // parse first cmd line arg (e.g. ninjam://ninbot.com:2049) WDL_String hostAndPort ; hostAndPort.Set("") ; if (!cmdParam[0]) return hostAndPort ; int isQuoted = (int)(cmdParam[0] == '"') ; char param[256] ; strncpy(param , cmdParam + isQuoted , 255) ; int len = strlen(param) ; int isSlash = (int)(param[len - (1 + isQuoted)] == '/') ; param[len - isQuoted - isSlash] = '\0' ; // tokenize and validate char* prot = strtok(param , ":") ; if (!prot || strcmp(prot , "ninjam")) return hostAndPort ; // validate host and port existance hostAndPort.Set(param + 9) ; char* host ; int port ; host = strtok(NULL , ":") ; char* p = strtok(NULL , ":") ; if (p) port = atoi(p) ; if (host && strlen(host) > 2 && port >= MIN_PORT && port <= MAX_PORT) host += 2 ; else return hostAndPort ; // strip leading slashes // validate allowed host if (!ValidateHost(host , true)) hostAndPort.Set(AUTOJOIN_FAIL) ; return hostAndPort ; }
void DoAnalyzeItem(COMMAND_T*) { WDL_TypedBuf<MediaItem*> items; SWS_GetSelectedMediaItems(&items); bool bDidWork = false; for (int i = 0; i < items.GetSize(); i++) { MediaItem* mi = items.Get()[i]; int iChannels = ((PCM_source*)mi)->GetNumChannels(); if (iChannels) { bDidWork = true; ANALYZE_PCM a; memset(&a, 0, sizeof(a)); a.iChannels = iChannels; a.dPeakVals = new double[iChannels]; a.dRMSs = new double[iChannels]; if (AnalyzeItem(mi, &a)) { WDL_String str; str.Set(__LOCALIZE("Peak level:","sws_analysis")); for (int i = 0; i < iChannels; i++) { str.Append(" "); str.AppendFormatted(50, __LOCALIZE_VERFMT("Channel %d = %.2f dB","sws_analysis"), i+1, VAL2DB(a.dPeakVals[i])); } str.Append("\n"); str.Append(__LOCALIZE("RMS level:","sws_analysis")); for (int i = 0; i < iChannels; i++) { str.Append(" "); str.AppendFormatted(50, __LOCALIZE_VERFMT("Channel %d = %.2f dB","sws_analysis"), i+1, VAL2DB(a.dRMSs[i])); } MessageBox(g_hwndParent, str.Get(), __LOCALIZE("Item analysis","sws_analysis"), MB_OK); } delete [] a.dPeakVals; delete [] a.dRMSs; } } if (!bDidWork) { MessageBox(NULL, __LOCALIZE("No items selected to analyze.","sws_analysis"), __LOCALIZE("SWS - Error","sws_analysis"), MB_OK); return; } }
int SearchDirectory(vector<string> &refvecFiles, const char* cDir, const char* cExt, bool bSubdirs) { WDL_DirScan ds; int iRet = ds.First(cDir); int found = 0; g_bAbortScan = false; if (!iRet) { do { if (strcmp(ds.GetCurrentFN(), ".") == 0 || strcmp(ds.GetCurrentFN(), "..") == 0) continue; WDL_String foundFile; ds.GetCurrentFullFN(&foundFile); lstrcpyn(g_CurrentScanFile, foundFile.Get(), 1024); if (bSubdirs && ds.GetCurrentIsDirectory()) { found += SearchDirectory(refvecFiles, foundFile.Get(), cExt, true); } else { char* cFoundExt = strrchr(foundFile.Get(), '.'); if (cFoundExt) { cFoundExt++; if ((!cExt && IsMediaExtension(cFoundExt, false)) || (cExt && _stricmp(cFoundExt, cExt) == 0)) { refvecFiles.push_back(foundFile.Get()); found++; } } } } while(!ds.Next() && !g_bAbortScan); } return found; }
bool FilteredVisState::MatchesFilter(MediaTrack* tr) { static WDL_String sTrackName; if (!m_parsedFilter->getnumtokens()) return true; sTrackName.Set((char*)GetSetMediaTrackInfo(tr, "P_NAME", NULL)); if (!sTrackName.GetLength()) return false; for (int i = 0; i < sTrackName.GetLength(); i++) sTrackName.Get()[i] = tolower(sTrackName.Get()[i]); for (int j = 0; j < m_parsedFilter->getnumtokens(); j++) if (strstr(sTrackName.Get(), m_parsedFilter->gettoken_str(j))) return true; return false; }
// TODO UTF8 support here void FilteredVisState::SetFilter(const char* cFilter) { if (cFilter && cFilter[0]) m_sFilter.Set(cFilter); else m_sFilter.Set(""); static WDL_String sLCFilter; sLCFilter.Set(m_sFilter.Get()); for (int i = 0; i < sLCFilter.GetLength(); i++) sLCFilter.Get()[i] = tolower(sLCFilter.Get()[i]); m_parsedFilter->parse(sLCFilter.Get()); }
void chatmsg_cb(int user32, NJClient *inst, char **parms, int nparms) { if (!parms[0]) return; if (!strcmp(parms[0],"TOPIC")) { if (parms[2]) { WDL_String tmp; if (parms[1] && *parms[1]) { tmp.Set(parms[1]); if (parms[2][0]) { tmp.Append(" sets topic to: "); tmp.Append(parms[2]); } else { tmp.Append(" removes topic."); } } else { if (parms[2][0]) { tmp.Set("Topic is: "); tmp.Append(parms[2]); } else tmp.Set("No topic is set."); } g_topic.Set(parms[2]); chat_addline("",tmp.Get()); } } else if (!strcmp(parms[0],"MSG")) { if (parms[1] && parms[2]) chat_addline(parms[1],parms[2]); } else if (!strcmp(parms[0],"PRIVMSG")) { if (parms[1] && parms[2]) { WDL_String tmp; tmp.Set("*"); tmp.Append(parms[1]); tmp.Append("* "); tmp.Append(parms[2]); chat_addline(NULL,tmp.Get()); } } else if (!strcmp(parms[0],"JOIN") || !strcmp(parms[0],"PART")) { if (parms[1] && *parms[1]) { WDL_String tmp(parms[1]); tmp.Append(" has "); tmp.Append(parms[0][0]=='P' ? "left" : "joined"); tmp.Append(" the server"); chat_addline("",tmp.Get()); } } }
void chatRun(HWND hwndDlg) { WDL_String tmp; g_client_mutex.Enter(); tmp.Set(m_append_text.Get()); m_append_text.Set(""); g_client_mutex.Leave(); if (!tmp.Get()[0]) return; HWND m_hwnd=GetDlgItem(hwndDlg,IDC_CHATDISP); SCROLLINFO si={sizeof(si),SIF_RANGE|SIF_POS|SIF_TRACKPOS,}; GetScrollInfo(m_hwnd,SB_VERT,&si); { int oldsels,oldsele; SendMessage(m_hwnd,EM_GETSEL,(WPARAM)&oldsels,(LPARAM)&oldsele); char txt[32768]; if(strlen(tmp.Get())>sizeof(txt)-1) return; GetWindowText(m_hwnd,txt,sizeof(txt)-1); txt[sizeof(txt)-1]=0; while(strlen(txt)+strlen(tmp.Get())+4>sizeof(txt)) { char *p=txt; while(*p!=0 && *p!='\n') p++; if(*p==0) return; while (*p=='\n') p++; strcpy(txt,p); oldsels -= p-txt; oldsele -= p-txt; } if (oldsels < 0) oldsels=0; if (oldsele < 0) oldsele=0; if(txt[0]) strcat(txt,"\n"); strcat(txt,tmp.Get()); CHARFORMAT2 cf2; cf2.cbSize=sizeof(cf2); cf2.dwMask=CFM_LINK; cf2.dwEffects=0; SendMessage(m_hwnd,EM_SETCHARFORMAT,SCF_ALL,(LPARAM)&cf2); SetWindowText(m_hwnd,txt); GetWindowText(m_hwnd,txt,sizeof(txt)-1); txt[sizeof(txt)-1]=0; char *t=txt; char lt=' '; int sub=0; while (*t) { if (lt == ' ' || lt == '\n' || lt == '\r') { int isurl=0; if (!strnicmp(t,"http:",5)) isurl=5; else if (!strnicmp(t,"ftp:",4)) isurl=4; else if (!strnicmp(t,"www.",4)) isurl=4; if (isurl && t[isurl] != ' ' && t[isurl] != '\n' && t[isurl] != '\r' && t[isurl]) { int spos=t-txt-sub; t+=isurl; while (*t && *t != ' ' && *t != '\n' && *t != '\r') { t++; } SendMessage(m_hwnd,EM_SETSEL,spos,(t-txt)-sub); CHARFORMAT2 cf2; cf2.cbSize=sizeof(cf2); cf2.dwMask=CFM_LINK; cf2.dwEffects=CFE_LINK; SendMessage(m_hwnd,EM_SETCHARFORMAT,SCF_SELECTION,(LPARAM)&cf2); } } if (*t == '\n') sub++; if (*t) lt=*t++; } SendMessage(m_hwnd,EM_SETSEL,oldsels,oldsele); } if (GetFocus() == m_hwnd) { SendMessage(m_hwnd, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION,si.nTrackPos),0); } else { GetScrollInfo(m_hwnd,SB_VERT,&si); SendMessage(m_hwnd, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION,si.nMax),0); } }
void chat_addline(char *src, char *text) { WDL_String tmp; if (src && *src && !strncmp(text,"/me ",4)) { tmp.Set("* "); tmp.Append(src); tmp.Append(" "); char *p=text+3; while (*p == ' ') p++; tmp.Append(p); } else { if (src&&*src) { tmp.Set("<"); tmp.Append(src); tmp.Append("> "); } else if (src) { tmp.Set("*** "); } tmp.Append(text); } g_client_mutex.Enter(); if (m_append_text.Get()[0]) m_append_text.Append("\n"); m_append_text.Append(tmp.Get()); g_client_mutex.Leave(); }
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 int ConfigOnToken(LineParser *lp) { const char *t=lp->gettoken_str(0); if (!stricmp(t,"Port")) { if (lp->getnumtokens() != 2) return -1; int p=lp->gettoken_int(1); if (!p) return -2; g_config_port=p; } else if (!stricmp(t,"StatusUserPass")) { if (lp->getnumtokens() != 3) return -1; g_status_user.Set(lp->gettoken_str(1)); g_status_pass.Set(lp->gettoken_str(2)); } else if (!stricmp(t,"MaxUsers")) { if (lp->getnumtokens() != 2) return -1; int p=lp->gettoken_int(1); m_group->m_max_users=p; } else if (!stricmp(t,"PIDFile")) { if (lp->getnumtokens() != 2) return -1; g_pidfilename.Set(lp->gettoken_str(1)); } else if (!stricmp(t,"LogFile")) { if (lp->getnumtokens() != 2) return -1; g_logfilename.Set(lp->gettoken_str(1)); } else if (!stricmp(t,"SessionArchive")) { if (lp->getnumtokens() != 3) return -1; g_config_logpath.Set(lp->gettoken_str(1)); g_config_log_sessionlen = lp->gettoken_int(2); } else if (!stricmp(t,"SetUID")) { if (lp->getnumtokens() != 2) return -1; g_set_uid = lp->gettoken_int(1); } else if (!stricmp(t,"DefaultBPI")) { if (lp->getnumtokens() != 2) return -1; g_default_bpi=lp->gettoken_int(1); if (g_default_bpi<MIN_BPI) g_default_bpi=MIN_BPI; else if (g_default_bpi > MAX_BPI) g_default_bpi=MAX_BPI; } else if (!stricmp(t,"DefaultBPM")) { if (lp->getnumtokens() != 2) return -1; g_default_bpm=lp->gettoken_int(1); if (g_default_bpm<MIN_BPM) g_default_bpm=MIN_BPM; else if (g_default_bpm > MAX_BPM) g_default_bpm=MAX_BPM; } else if (!stricmp(t,"DefaultTopic")) { if (lp->getnumtokens() != 2) return -1; if (!m_group->m_topictext.Get()[0]) m_group->m_topictext.Set(lp->gettoken_str(1)); } else if (!stricmp(t,"MaxChannels")) { if (lp->getnumtokens() != 2 && lp->getnumtokens() != 3) return -1; g_config_maxch_user=lp->gettoken_int(1); g_config_maxch_anon=lp->gettoken_int(lp->getnumtokens()>2?2:1); } else if (!stricmp(t,"SetKeepAlive")) { if (lp->getnumtokens() != 2) return -1; m_group->m_keepalive=lp->gettoken_int(1); if (m_group->m_keepalive < 0 || m_group->m_keepalive > 255) m_group->m_keepalive=0; } else if (!stricmp(t,"SetVotingThreshold")) { if (lp->getnumtokens() != 2) return -1; m_group->m_voting_threshold=lp->gettoken_int(1); } else if (!stricmp(t,"SetVotingVoteTimeout")) { if (lp->getnumtokens() != 2) return -1; m_group->m_voting_timeout=lp->gettoken_int(1); } else if (!stricmp(t,"ServerLicense")) { if (lp->getnumtokens() != 2) return -1; FILE *fp=fopen(lp->gettoken_str(1),"rt"); if (!fp) { printf("Error opening license file %s\n",lp->gettoken_str(1)); if (g_logfp) logText("Error opening license file %s\n",lp->gettoken_str(1)); return -2; } g_config_license.Set(""); for (;;) { char buf[1024]; buf[0]=0; fgets(buf,sizeof(buf),fp); if (!buf[0]) break; g_config_license.Append(buf); } fclose(fp); } else if (!stricmp(t,"ACL")) { if (lp->getnumtokens() != 3) return -1; int suc=0; char *v=lp->gettoken_str(1); char *t=strstr(v,"/"); if (t) { *t++=0; unsigned long addr=JNL::ipstr_to_addr(v); if (addr != INADDR_NONE) { int maskbits=atoi(t); if (maskbits >= 0 && maskbits <= 32) { int flag=lp->gettoken_enum(2,"allow\0deny\0reserve\0"); if (flag >= 0) { suc=1; unsigned long mask=~(0xffffffff>>maskbits); aclAdd(addr,mask,flag); } } }
int Run() { // perform lookup here user_valid=0; if (!strncmp(username.Get(),"anonymous",9) && (!username.Get()[9] || username.Get()[9] == ':')) { logText("got anonymous request (%s)\n",g_config_allowanonymous?"allowing":"denying"); if (!g_config_allowanonymous) return 1; user_valid=1; reqpass=0; WDL_String tmp(username.Get()); if (tmp.Get()[9] == ':' && tmp.Get()[10]) { username.Set(tmp.Get()+10); int cnt=16; char *p=username.Get(); while (*p) { if (!cnt--) { *p=0; break; } if (*p == '@' || *p == '.') *p='_'; p++; } } else username.Set("anon"); username.Append("@"); username.Append(hostmask.Get()); if (g_config_anonymous_mask_ip) { char *p=username.Get(); while (*p) p++; while (p > username.Get() && *p != '.' && *p != '@') p--; if (*p == '.' && p[1]) { p[1]='x'; p[2]=0; } } privs=(g_config_allow_anonchat?PRIV_CHATSEND:0) | (g_config_allowanonymous_multi?PRIV_ALLOWMULTI:0) | PRIV_VOTE; max_channels=g_config_maxch_anon; } else { int x; logText("got login request for '%s'\n",username.Get()); if (g_status_user.Get()[0] && !strcmp(username.Get(),g_status_user.Get())) { user_valid=1; reqpass=1; is_status=1; privs=0; max_channels=0; WDL_SHA1 shatmp; shatmp.add(username.Get(),strlen(username.Get())); shatmp.add(":",1); shatmp.add(g_status_pass.Get(),strlen(g_status_pass.Get())); shatmp.result(sha1buf_user); } else for (x = 0; x < g_userlist.GetSize(); x ++) { if (!strcmp(username.Get(),g_userlist.Get(x)->name.Get())) { user_valid=1; reqpass=1; char *pass=g_userlist.Get(x)->pass.Get(); WDL_SHA1 shatmp; shatmp.add(username.Get(),strlen(username.Get())); shatmp.add(":",1); shatmp.add(pass,strlen(pass)); shatmp.result(sha1buf_user); privs=g_userlist.Get(x)->priv_flag; max_channels=g_config_maxch_user; break; } } } return 1; }
void chatRun(HWND hwndDlg) { WDL_String tmp; g_client_mutex.Enter(); tmp.Set(m_append_text.Get()); m_append_text.Set(""); g_client_mutex.Leave(); if (!tmp.Get()[0]) return; SCROLLINFO si={sizeof(si),SIF_RANGE|SIF_POS|SIF_TRACKPOS,}; GetScrollInfo(g_chat_hwnd , SB_VERT , &si) ; { int oldsels,oldsele; SendMessage(g_chat_hwnd , EM_GETSEL , (WPARAM)&oldsels , (LPARAM)&oldsele) ; char txt[32768]; if(strlen(tmp.Get())>sizeof(txt)-1) return; GetWindowText(g_chat_hwnd , txt , sizeof(txt)-1) ; txt[sizeof(txt)-1]=0; while(strlen(txt)+strlen(tmp.Get())+4>sizeof(txt)) { char *p=txt; while(*p!=0 && *p!='\n') p++; if(*p==0) return; while (*p=='\n') p++; strcpy(txt,p); oldsels -= p-txt; oldsele -= p-txt; } if (oldsels < 0) oldsels=0; if (oldsele < 0) oldsele=0; if(txt[0]) strcat(txt,"\n"); strcat(txt,tmp.Get()); CHARFORMAT2 cf2; cf2.cbSize=sizeof(cf2); cf2.dwMask=CFM_LINK; cf2.dwEffects=0; SendMessage(g_chat_hwnd , EM_SETCHARFORMAT , SCF_ALL , (LPARAM)&cf2) ; SetWindowText(g_chat_hwnd , txt) ; GetWindowText(g_chat_hwnd , txt , sizeof(txt)-1) ; txt[sizeof(txt)-1]=0; #if COLOR_CHAT char *t = txt ; int sub=0 ; char lt = '\n' ; while (*t) { if (lt == '\n' || lt == '\r') { int usernameOffset = 0 ; bool isParseTokens ; bool isColorText ; if (!strnicmp(t , "<PM from " , 9)) // private chat (choose color per user) { usernameOffset = 9 ; isParseTokens = true ; } else if (!strnicmp(t , "<" , 1)) // user chat (choose color per user) { usernameOffset = 1 ; isParseTokens = true ; } else isParseTokens = isColorText = false ; int lineBegin ; int boldEnd ; int normalBegin ; int lineEnd ; char theUsername[256] ; if (isParseTokens) { // parse username token and set seperator pointers (<bold> normal) lineBegin = t - txt - sub ; char* usernameBegin = (t += usernameOffset) ; while (*t && *t != '\n' && *t != '\r' && *t != ' ') ++t ; boldEnd = t - txt - sub ; normalBegin = boldEnd + 1 ; int theUsernameLen = boldEnd - lineBegin - usernameOffset - 1 ; if (isColorText = theUsernameLen < 256) { strncpy(theUsername , usernameBegin , theUsernameLen) ; theUsername[theUsernameLen] = '\0' ; } while (*t && *t != '\n' && *t != '\r') ++t ; lineEnd = t - txt - sub ; } if (isColorText) { // choose color per user int chatColorIdx = TeamStream::GetChatColorIdxByName(theUsername) ; COLORREF color = TeamStream::Get_Chat_Color(chatColorIdx) ; // apply char formatting CHARFORMAT2 cf2 ; cf2.cbSize = sizeof(cf2) ; // bold text - sender name cf2.dwMask = CFM_COLOR | CFM_BOLD ; cf2.crTextColor = color ; cf2.dwEffects = CFE_BOLD ; SendMessage(g_chat_hwnd , EM_SETSEL , lineBegin , boldEnd) ; SendMessage(g_chat_hwnd , EM_SETCHARFORMAT , SCF_SELECTION , (LPARAM)&cf2) ; if (!cfg_color_names_only) { // normal text - everything after bold text cf2.dwMask = CFM_COLOR ; cf2.crTextColor = color ; SendMessage(g_chat_hwnd , EM_SETSEL , normalBegin , lineEnd) ; SendMessage(g_chat_hwnd , EM_SETCHARFORMAT , SCF_SELECTION , (LPARAM)&cf2) ; } } } // if terminator char if (*t == '\n') sub++ ; if (*t) lt = *t++ ; } // while // NOTE: the original link parser code was unnecessary it is sufficient to // send EM_AUTOURLDETECT to the richedit20 control (catches most protocols) // and set its EM_SETEVENTMASK to ENM_LINK to enable event messaging (in chatInit()) // the only advantage to the original approach is catching hand-typed links beginning // with "www." (but still didn't catch links like "github.com") so for this most part // it was just wasted cycles (especially seeing as click handling was not implemented) // still the original code could be built upon to parse hand-typed links that don't // specify a protocol but ending with ".com" ".org" etc. if anyone thinks this to be useful // or to allow only certain users to post clickable links (disable EM_AUTOURLDETECT) // if so we need to reset state here for the 2nd pass /* SendMessage(m_hwnd , EM_SETSEL , oldsels , oldsele) ; t = txt ; lt = ' ' ; sub = 0 ; // original link parser code was here -------> */ #endif COLOR_CHAT } if (GetFocus() == g_chat_hwnd) { SendMessage(g_chat_hwnd , WM_VSCROLL , MAKEWPARAM(SB_THUMBPOSITION , si.nTrackPos) , 0) ; } else { GetScrollInfo(g_chat_hwnd , SB_VERT , &si) ; SendMessage(g_chat_hwnd , WM_VSCROLL , MAKEWPARAM(SB_THUMBPOSITION , si.nMax) , 0) ; } }
WDL_SHM_Connection::WDL_SHM_Connection(bool whichChan, const char *uniquestring, // identify int shmsize, // bytes, whoever opens first decides int timeout_sec, int extra_flags // unused on win32 ) { m_timeout_cnt=0; m_timeout_sec=timeout_sec; m_last_recvt=time(NULL)+2; // grace period { // make shmsize the next power of two int a = shmsize; shmsize=2; while (shmsize < SHM_MINSIZE || shmsize<a) shmsize*=2; } m_file=INVALID_HANDLE_VALUE; m_filemap=NULL; m_mem=NULL; m_lockmutex=m_events[0]=m_events[1]=NULL; m_whichChan=whichChan ? 1 : 0; char buf[512]; GetTempPath(sizeof(buf)-4,buf); if (!buf[0]) lstrcpyn(buf,"C:\\",32); if (buf[strlen(buf)-1] != '/' && buf[strlen(buf)-1] != '\\') strcat(buf,"\\"); m_tempfn.Set(buf); m_tempfn.Append("WDL_SHM_"); m_tempfn.Append(uniquestring); m_tempfn.Append(".tmp"); WDL_String tmp; if (!(GetVersion()&0x80000000)) tmp.Set("Global\\WDL_SHM_"); else tmp.Set("WDL_SHM_"); tmp.Append(uniquestring); int tmp_l = strlen(tmp.Get()); tmp.Append(".m"); HANDLE mutex = CreateMutex(NULL,FALSE,tmp.Get()); if (mutex) WaitForSingleObject(mutex,INFINITE); tmp.Get()[tmp_l]=0; tmp.Append(whichChan?".l1":".l0"); m_lockmutex = CreateMutex(NULL,FALSE,tmp.Get()); if (m_lockmutex) { if (WaitForSingleObject(m_lockmutex,100) == WAIT_OBJECT_0) { DeleteFile(m_tempfn.Get()); // this is designed to fail if another process has it locked m_file=CreateFile(m_tempfn.Get(),GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE , NULL,whichChan ? OPEN_EXISTING : OPEN_ALWAYS,FILE_ATTRIBUTE_TEMPORARY,NULL); } else { CloseHandle(m_lockmutex); m_lockmutex=0; } } int mapsize; if (m_file != INVALID_HANDLE_VALUE && ((mapsize=GetFileSize(m_file,NULL)) < SHM_HDRSIZE+SHM_MINSIZE*2 || mapsize == 0xFFFFFFFF)) { char buf[4096]; memset(buf,0,sizeof(buf)); *(int *)buf=shmsize; int sz=shmsize*2 + SHM_HDRSIZE; while (sz>0) { DWORD d; int a = sz; if (a>sizeof(buf))a=sizeof(buf); WriteFile(m_file,buf,a,&d,NULL); sz-=a; *(int *)buf = 0; } } if (m_file!=INVALID_HANDLE_VALUE) m_filemap=CreateFileMapping(m_file,NULL,PAGE_READWRITE,0,0,NULL); if (m_filemap) { m_mem=(unsigned char *)MapViewOfFile(m_filemap,FILE_MAP_WRITE,0,0,0); tmp.Get()[tmp_l]=0; tmp.Append(".1"); m_events[0]=CreateEvent(NULL,false,false,tmp.Get()); tmp.Get()[strlen(tmp.Get())-1]++; m_events[1]=CreateEvent(NULL,false,false,tmp.Get()); } if (mutex) { ReleaseMutex(mutex); CloseHandle(mutex); } }
// The OS is announcing what needs to be redrawn, // which may be a larger area than what is strictly dirty. bool IGraphics::Draw(IRECT* pR) { // #pragma REMINDER("Mutex set while drawing") // WDL_MutexLock lock(&mMutex); int i, j, n = mControls.GetSize(); if (!n) { return true; } if (mStrict) { mDrawRECT = *pR; int n = mControls.GetSize(); IControl** ppControl = mControls.GetList(); for (int i = 0; i < n; ++i, ++ppControl) { IControl* pControl = *ppControl; if (!(pControl->IsHidden()) && pR->Intersects(pControl->GetRECT())) { pControl->Draw(this); } pControl->SetClean(); } } else { IControl* pBG = mControls.Get(0); if (pBG->IsDirty()) // Special case when everything needs to be drawn. { mDrawRECT = *(pBG->GetRECT()); for (int j = 0; j < n; ++j) { IControl* pControl2 = mControls.Get(j); if (!j || !(pControl2->IsHidden())) { pControl2->Draw(this); pControl2->SetClean(); } } } else { for (i = 1; i < n; ++i) // loop through all controls starting from one (not bg) { IControl* pControl = mControls.Get(i); // assign control i to pControl if (pControl->IsDirty()) // if pControl is dirty { // printf("control %i is Dirty\n", i); mDrawRECT = *(pControl->GetRECT()); // put the rect in the mDrawRect member variable for (j = 0; j < n; ++j) // loop through all controls { IControl* pControl2 = mControls.Get(j); // assign control j to pControl2 // if control1 == control2 OR control2 is not hidden AND control2's rect intersects mDrawRect if (!pControl2->IsHidden() && (i == j || pControl2->GetRECT()->Intersects(&mDrawRECT))) { //if ((i == j) && (!pControl2->IsHidden())|| (!(pControl2->IsHidden()) && pControl2->GetRECT()->Intersects(&mDrawRECT))) { //printf("control %i and %i \n", i, j); pControl2->Draw(this); } } pControl->SetClean(); } } } } #ifndef NDEBUG if (mShowControlBounds) { for (int j = 1; j < mControls.GetSize(); j++) { IControl* pControl = mControls.Get(j); DrawRect(&CONTROL_BOUNDS_COLOR, pControl->GetRECT()); } WDL_String str; str.SetFormatted(32, "x: %i, y: %i", mMouseX, mMouseY); IText txt(20, &CONTROL_BOUNDS_COLOR); IRECT rect(Width() - 150, Height() - 20, Width(), Height()); DrawIText(&txt, str.Get(), &rect); } #endif return DrawScreen(pR); }
AAX_Result IPlugAAX::EffectInit() { TRACE; AAX_CString bypassID = NULL; this->GetMasterBypassParameter( &bypassID ); mBypassParameter = new AAX_CParameter<bool>(bypassID.CString(), AAX_CString("Master Bypass"), false, AAX_CBinaryTaperDelegate<bool>(), AAX_CBinaryDisplayDelegate<bool>("bypass", "on"), true); mBypassParameter->SetNumberOfSteps( 2 ); mBypassParameter->SetType( AAX_eParameterType_Discrete ); mParameterManager.AddParameter(mBypassParameter); for (int i=0;i<NParams();i++) { IParam *p = GetParam(i); AAX_IParameter* param = 0; WDL_String* paramID = new WDL_String("_", 1); paramID->SetFormatted(32, "%i", i+kAAXParamIdxOffset); mParamIDs.Add(paramID); switch (p->Type()) { case IParam::kTypeDouble: { param = new AAX_CParameter<double>(paramID->Get(), AAX_CString(p->GetNameForHost()), p->GetDefault(), AAX_CIPlugTaperDelegate<double>(p->GetMin(), p->GetMax(), p->GetShape()), AAX_CUnitDisplayDelegateDecorator<double>( AAX_CNumberDisplayDelegate<double>(), AAX_CString(p->GetLabelForHost())), p->GetCanAutomate()); param->SetNumberOfSteps(128); // TODO: check this https://developer.digidesign.com/index.php?L1=5&L2=13&L3=56 param->SetType(AAX_eParameterType_Continuous); break; } case IParam::kTypeInt: { param = new AAX_CParameter<int>(paramID->Get(), AAX_CString(p->GetNameForHost()), (int)p->GetDefault(), AAX_CLinearTaperDelegate<int>((int)p->GetMin(), (int)p->GetMax()), AAX_CUnitDisplayDelegateDecorator<int>( AAX_CNumberDisplayDelegate<int>(), AAX_CString(p->GetLabelForHost())), p->GetCanAutomate()); param->SetNumberOfSteps(128); param->SetType(AAX_eParameterType_Continuous); break; } case IParam::kTypeEnum: case IParam::kTypeBool: { int nTexts = p->GetNDisplayTexts(); std::map<int, AAX_CString> displayTexts; for (int j=0; j<p->GetNDisplayTexts(); j++) { int value; const char* text = p->GetDisplayTextAtIdx(j, &value); displayTexts.insert(std::pair<int, AAX_CString>(value, AAX_CString(text)) ); } param = new AAX_CParameter<int>(paramID->Get(), AAX_CString(p->GetNameForHost()), (int)p->GetDefault(), AAX_CLinearTaperDelegate<int>((int)p->GetMin(), (int)p->GetMax()), AAX_CStringDisplayDelegate<int>(displayTexts), p->GetCanAutomate()); param->SetNumberOfSteps(nTexts); param->SetType(AAX_eParameterType_Discrete); break; } default: break; } mParameterManager.AddParameter(param); } AAX_CSampleRate sr; Controller()->GetSampleRate(&sr); SetSampleRate(sr); Reset(); return AAX_SUCCESS; }
int XenakiosInit() { if(!plugin_register("projectconfig",&xen_reftrack_pcreg)) return 0; // Move Xenakios_commands.ini to a new location char oldIniFilename[BUFFER_SIZE], iniFilename[BUFFER_SIZE]; _snprintf(oldIniFilename, BUFFER_SIZE, XEN_INIFILE_OLD, GetExePath()); // old location _snprintf(iniFilename, BUFFER_SIZE, XEN_INIFILE_NEW, GetResourcePath()); if (FileExists(oldIniFilename)) MoveFile(oldIniFilename, iniFilename); g_XenIniFilename.Set(iniFilename); ShuffledNumbers=new int[1024]; SWSRegisterCommands(g_XenCommandTable); InitCommandParams(); g_filenames = new(WDL_PtrList<char>); InitUndoKeyUpHandler01(); g_hItemInspector = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_ITEM_INSPECTOR), g_hwndParent, (DLGPROC)MyItemInspectorDlgProc); if (g_hItemInspector != NULL) ShowWindow(g_hItemInspector, SW_HIDE); srand ((unsigned int)time(NULL)); // Add track template actions char cPath[BUFFER_SIZE]; _snprintf(cPath, BUFFER_SIZE, "%s%cTrackTemplates", GetResourcePath(), PATH_SLASH_CHAR); vector<string> templates; SearchDirectory(templates, cPath, "RTRACKTEMPLATE", true); for (int i = 0; i < (int)templates.size(); i++) { const char* pFilename = strrchr(templates[i].c_str(), PATH_SLASH_CHAR); if (pFilename && pFilename[1]) { int iNum = atol(pFilename+1); if (iNum && !SWSGetCommandID(DoOpenTrackTemplate, iNum)) { char cDesc[BUFFER_SIZE]; char cID[BUFFER_SIZE]; _snprintf(cID, BUFFER_SIZE, "XENAKIOS_LOADTRACKTEMPLATE%d", iNum); _snprintf(cDesc, BUFFER_SIZE, __LOCALIZE_VERFMT("Xenakios/SWS: [Deprecated] Load track template %d","sws_actions"), iNum); SWSRegisterCommandExt(DoOpenTrackTemplate, cID, cDesc, iNum, false); } } } // Add project template actions _snprintf(cPath, BUFFER_SIZE, "%s%cProjectTemplates", GetResourcePath(), PATH_SLASH_CHAR); templates.clear(); SearchDirectory(templates, cPath, "RPP", true); for (int i = 0; i < (int)templates.size(); i++) { const char* pFilename = strrchr(templates[i].c_str(), PATH_SLASH_CHAR); if (pFilename && pFilename[1]) { int iNum = atol(pFilename+1); if (iNum && !SWSGetCommandID(DoOpenProjectTemplate, iNum)) { char cID[BUFFER_SIZE]; char cDesc[BUFFER_SIZE]; _snprintf(cID, BUFFER_SIZE, "XENAKIOS_LOADPROJTEMPL%d", iNum); _snprintf(cDesc, BUFFER_SIZE, __LOCALIZE_VERFMT("Xenakios/SWS: [Deprecated] Load project template %d","sws_actions"), iNum); SWSRegisterCommandExt(DoOpenProjectTemplate, cID, cDesc, iNum, false); } } } return 1; }
static int ReadConfig(ServerConfig *config, char *configfile) { bool comment_state=0; int linecnt=0; WDL_String linebuild; if (g_logfp) logText("[config] reloading configuration file\n"); // TODO move this elsewhere FILE *fp=strcmp(configfile,"-")?fopen(configfile,"rt"):stdin; if (!fp) { printf("[config] error opening configfile '%s'\n",configfile); if (g_logfp) logText("[config] error opening config file (console request)\n"); // TODO move this elsewhere return -1; } config->allowAnonChat = true; config->allowAnonymous = false; config->allowAnonymousMulti = false; config->anonymousMaskIP = false; config->allowHiddenUsers = false; config->setuid = -1; config->defaultBPM = 120; config->defaultBPI = 8; config->port = 2049; config->keepAlive = 0; config->maxUsers = 0; // unlimited users config->maxchAnon = 2; config->maxchUser = 32; config->logSessionLen = 10; // ten minute default, tho the user will need to specify the path anyway config->votingThreshold = 110; config->votingTimeout = 120; config->logPath.Set(""); config->pidFilename.Set(""); config->logFilename.Set(""); config->statusPass.Set(""); config->statusUser.Set(""); config->license.Set(""); config->defaultTopic.Set(""); config->acl.clear(); int x; for(x=0; x < config->userlist.GetSize(); x++) { delete config->userlist.Get(x); } config->userlist.Empty(); for (;;) { char buf[8192]; buf[0]=0; fgets(buf,sizeof(buf),fp); linecnt++; if (!buf[0]) break; if (buf[strlen(buf)-1]=='\n') buf[strlen(buf)-1]=0; LineParser lp(comment_state); if (buf[0] && buf[strlen(buf)-1]=='\\') { buf[strlen(buf)-1]=0; linebuild.Append(buf); continue; } linebuild.Append(buf); int res=lp.parse(linebuild.Get()); linebuild.Set(""); if (res) { if (res==-2) { if (g_logfp) logText("[config] warning: unterminated string parsing line %d of %s\n",linecnt,configfile); printf("[config] warning: unterminated string parsing line %d of %s\n",linecnt,configfile); } else { if (g_logfp) logText("[config] warning: error parsing line %d of %s\n",linecnt,configfile); printf("[config] warning: error parsing line %d of %s\n",linecnt,configfile); } } else { comment_state = lp.InCommentBlock(); if (lp.getnumtokens()>0) { int err = ConfigOnToken(config, &lp); if (err) { if (err == -1) { if (g_logfp) logText("[config] warning: wrong number of tokens on line %d of %s\n",linecnt,configfile); printf("[config] warning: wrong number of tokens on line %d of %s\n",linecnt,configfile); } if (err == -2) { if (g_logfp) logText("[config] warning: invalid parameter on line %d of %s\n",linecnt,configfile); printf("[config] warning: invalid parameter on line %d of %s\n",linecnt,configfile); } if (err == -3) { if (g_logfp) logText("[config] warning: invalid config command \"%s\" on line %d of %s\n",lp.gettoken_str(0),linecnt,configfile); printf("[config] warning: invalid config command \"%s\" on line %d of %s\n",lp.gettoken_str(0),linecnt,configfile); } } } } } if (g_logfp) logText("[config] reload complete\n"); if (fp != stdin) fclose(fp); return 0; }
void chatmsg_cb(int user32, NJClient *inst, char **parms, int nparms) { if (!parms[0]) return; char* username = TeamStream::TrimUsername(parms[1]) ; if (!strcmp(parms[0],"TOPIC")) { if (parms[2]) { WDL_String tmp; if (parms[1] && *parms[1]) { tmp.Set("<Server> ") ; tmp.Append(username) ; if (parms[2][0]) { tmp.Append(" sets topic to: "); tmp.Append(parms[2]); } else { tmp.Append(" removes topic."); } } else { if (parms[2][0]) { tmp.Set("Topic is: "); tmp.Append(parms[2]); } else tmp.Set("No topic is set."); } g_topic.Set(parms[2]); chat_addline("",tmp.Get()); } } else if (!strcmp(parms[0],"MSG")) { if (parms[1] && parms[2] && !parseChatTriggers(parms[1] , username , parms[2] , false)) chat_addline(username , parms[2]) ; } else if (!strcmp(parms[0],"PRIVMSG")) { if (parms[1] && parms[2]) { if (!parseChatTriggers(parms[1] , username , parms[2] , true)) { WDL_String tmp ; tmp.Set("<PM from ") ; tmp.Append(username) ; tmp.Append("> ") ; tmp.Append(parms[2]) ; chat_addline(NULL,tmp.Get()); } } } else if (!strcmp(parms[0],"JOIN") || !strcmp(parms[0],"PART")) { if (parms[1] && *parms[1]) { WDL_String tmp(username) ; tmp.Append(" has "); tmp.Append(parms[0][0]=='P' ? "left" : "joined"); tmp.Append(" the server"); chat_addline("",tmp.Get()); } } }
WDL_SHM_Connection::WDL_SHM_Connection(bool whichChan, const char *uniquestring, // identify int shmsize, // bytes, whoever opens first decides int timeout_sec ) { m_timeout_sec=timeout_sec; m_last_recvt=time(NULL)+2; // grace period { // make shmsize the next power of two int a = shmsize; shmsize=2; while (shmsize < SHM_MINSIZE || shmsize<a) shmsize*=2; } m_file=INVALID_HANDLE_VALUE; m_filemap=NULL; m_mem=NULL; m_events[0]=m_events[1]=NULL; m_whichChan=whichChan ? 1 : 0; char buf[512]; GetTempPath(sizeof(buf)-4,buf); if (!buf[0]) lstrcpyn(buf,"C:\\",32); if (buf[strlen(buf)-1] != '/' && buf[strlen(buf)-1] != '\\') strcat(buf,"\\"); m_tempfn.Set(buf); m_tempfn.Append("WDL_SHM_"); m_tempfn.Append(uniquestring); m_tempfn.Append(".tmp"); HANDLE mutex=NULL; { WDL_String tmp; tmp.Set("WDL_SHM_"); tmp.Append(uniquestring); tmp.Append(".mutex"); mutex = CreateMutex(NULL,FALSE,tmp.Get()); } if (mutex) WaitForSingleObject(mutex,INFINITE); DeleteFile(m_tempfn.Get()); // this is designed to fail if another process has it locked m_file=CreateFile(m_tempfn.Get(),GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE , NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_TEMPORARY,NULL); int mapsize; if (m_file != INVALID_HANDLE_VALUE && ((mapsize=GetFileSize(m_file,NULL)) < SHM_HDRSIZE+SHM_MINSIZE*2 || mapsize == 0xFFFFFFFF)) { WDL_HeapBuf tmp; memset(tmp.Resize(shmsize*2 + SHM_HDRSIZE),0,shmsize*2 + SHM_HDRSIZE); ((int *)tmp.Get())[0] = shmsize; DWORD d; WriteFile(m_file,tmp.Get(),tmp.GetSize(),&d,NULL); } if (mutex) { ReleaseMutex(mutex); CloseHandle(mutex); } if (m_file!=INVALID_HANDLE_VALUE) m_filemap=CreateFileMapping(m_file,NULL,PAGE_READWRITE,0,0,NULL); if (m_filemap) { m_mem=(unsigned char *)MapViewOfFile(m_filemap,FILE_MAP_WRITE,0,0,0); WDL_String tmp; if (!(GetVersion()&0x80000000)) tmp.Set("Global\\WDL_SHM_"); else tmp.Set("WDL_SHM_"); tmp.Append(uniquestring); tmp.Append(".1"); m_events[0]=CreateEvent(NULL,false,false,tmp.Get()); tmp.Get()[strlen(tmp.Get())-1]++; m_events[1]=CreateEvent(NULL,false,false,tmp.Get()); } }
void IGraphicsWin::PromptForFile(WDL_String* pFilename, int action, char* dir, char* extensions) { pFilename->Set(""); if (!WindowIsOpen()) { return; } WDL_String pathStr; char fnCStr[MAX_PATH_LEN], dirCStr[MAX_PATH_LEN]; fnCStr[0] = '\0'; dirCStr[0] = '\0'; if (CSTR_NOT_EMPTY(dir)) { pathStr.Set(dir); strcpy(dirCStr, dir); } else { HostPath(&pathStr); } OPENFILENAME ofn; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = mPlugWnd; ofn.lpstrFile = fnCStr; ofn.nMaxFile = MAX_PATH_LEN - 1; ofn.lpstrInitialDir = dirCStr; ofn.Flags = OFN_PATHMUSTEXIST; //if (!extensions.empty()) { //static char extStr[256]; //static char defExtStr[16]; //int i, j, p; //for (j = 0, p = 0; j < extensions.size(); ++j) { // extStr[p++] = extensions[j++]; //} //extStr[p++] = '\0'; //StrVector exts = SplitStr(extensions); //for (i = 0, p = 0; i < exts.size(); ++i) { // const std::string& ext = exts[i]; // if (i) { // extStr[p++] = ';'; // } // extStr[p++] = '*'; // extStr[p++] = '.'; // for (j = 0; j < ext.size(); ++j) { // extStr[p++] = ext[j]; // } //} //extStr[p++] = '\0'; //extStr[p++] = '\0'; //ofn.lpstrFilter = extStr; // //strcpy(defExtStr, exts.front().c_str()); //ofn.lpstrDefExt = defExtStr; //} bool rc = false; switch (action) { case kFileSave: ofn.Flags |= OFN_OVERWRITEPROMPT; rc = GetSaveFileName(&ofn); break; case kFileOpen: default: ofn.Flags |= OFN_FILEMUSTEXIST; rc = GetOpenFileName(&ofn); break; } if (rc) { pFilename->Set(ofn.lpstrFile); } }