// return a bitmask: &SNM_MARKER_MASK: marker update, &SNM_REGION_MASK: region update int UpdateMarkerRegionCache() { int updateFlags=0; int i=0, x=0, num, col; double pos, rgnend; const char* name; bool isRgn; // added/updated markers/regions? while ((x = EnumProjectMarkers3(NULL, x, &isRgn, &pos, &rgnend, &name, &num, &col))) { MarkerRegion* m = g_mkrRgnCache.Get(i); if (!m || (m && !m->Compare(isRgn, pos, rgnend, name, num, col))) { if (m) g_mkrRgnCache.Delete(i, true); g_mkrRgnCache.Insert(i, new MarkerRegion(isRgn, pos, rgnend, name, num, col)); updateFlags |= (isRgn ? SNM_REGION_MASK : SNM_MARKER_MASK); } i++; } // removed markers/regions? for (int j=g_mkrRgnCache.GetSize()-1; j>=i; j--) { if (MarkerRegion* m = g_mkrRgnCache.Get(j)) updateFlags |= (m->IsRegion() ? SNM_REGION_MASK : SNM_MARKER_MASK); g_mkrRgnCache.Delete(j, true); } // project time mode update? static int sPrevTimemode = *(int*)GetConfigVar("projtimemode"); if (updateFlags != (SNM_MARKER_MASK|SNM_REGION_MASK)) if (int* timemode = (int*)GetConfigVar("projtimemode")) if (*timemode != sPrevTimemode) { sPrevTimemode = *timemode; return SNM_MARKER_MASK|SNM_REGION_MASK; } return updateFlags; }
int audioStreamer_waveOut::Read(char *buf, int len) // returns 0 if blocked, < 0 if error, > 0 if data { if (!m_hwi) return -1; #if 0 // lame, this doesnt really do what we want it to // check to see if all are full, and if so, kill a lot of em { int x; int cnt=0; for (x = 0; x < m_bufs.GetSize(); x ++) { WAVEHDR *th = (WAVEHDR *) m_bufs.Get(x)->Get(); if (th->dwFlags & WHDR_DONE) cnt++; } if (cnt >= m_bufs.GetSize()-1) { // audiostream_onover(); for (x = 0; x < m_bufs.GetSize(); x ++) { if (x != m_whichbuf) { WAVEHDR *th = (WAVEHDR *) m_bufs.Get(x)->Get(); if (th->dwFlags & WHDR_DONE) { th->dwBytesRecorded=0; th->dwFlags = WHDR_PREPARED; waveInAddBuffer(m_hwi,th,sizeof(WAVEHDR)); } } } } } #endif WAVEHDR *th = (WAVEHDR *) m_bufs.Get(m_whichbuf)->Get(); while (!(th->dwFlags & WHDR_DONE)) { Sleep(WO_SLEEP); } len=min(len,(int)th->dwBytesRecorded); memcpy(buf,th->lpData,len); th->dwBytesRecorded=0; th->dwFlags = WHDR_PREPARED; waveInAddBuffer(m_hwi,th,sizeof(WAVEHDR)); if (++m_whichbuf >= m_bufs.GetSize()) m_whichbuf=0; return len; }
void EndDialog(HWND wnd, int ret) { if (!wnd) return; int x; for (x = 0; x < s_modalDialogs.GetSize(); x ++) if (s_modalDialogs.Get(x)->hwnd == wnd) { s_modalDialogs.Get(x)->has_ret=true; s_modalDialogs.Get(x)->ret = ret; } DestroyWindow(wnd); // todo }
int TrackPopupMenu(HMENU hMenu, int flags, int xpos, int ypos, int resvd, HWND hwnd, const RECT *r) { if (!hMenu || m_trackingMenus.GetSize()) return 0; ReleaseCapture(); m_trackingPar=hwnd; m_trackingFlags=flags; m_trackingRet=-1; m_trackingPt.x=xpos; m_trackingPt.y=ypos; submenuWndProc(new HWND__(NULL,0,NULL,"menu",false,submenuWndProc,NULL),WM_CREATE,0,(LPARAM)hMenu); printf("enter trackpopupmenu loop\n"); while (m_trackingRet<0 && m_trackingMenus.GetSize()) { void SWELL_RunMessageLoop(); SWELL_RunMessageLoop(); Sleep(10); } printf("leave trackpopupmenu loop\n"); int x=m_trackingMenus.GetSize()-1; while (x>=0) { HWND h = m_trackingMenus.Get(x); m_trackingMenus.Delete(x); if (h) DestroyWindow(h); x--; } if (!(flags&TPM_NONOTIFY) && m_trackingRet>0) SendMessage(hwnd,WM_COMMAND,m_trackingRet,0); return m_trackingRet>0?m_trackingRet:0; }
~FontStorage() { int i, n = m_fonts.GetSize(); for (i = 0; i < n; ++i) { delete(m_fonts.Get(i)->font); } m_fonts.Empty(true); }
~BitmapStorage() { int i, n = m_bitmaps.GetSize(); for (i = 0; i < n; ++i) { delete(m_bitmaps.Get(i)->bitmap); } m_bitmaps.Empty(true); }
LICE_IBitmap* Find(int id) { WDL_MutexLock lock(&m_mutex); int i, n = m_bitmaps.GetSize(); for (i = 0; i < n; ++i) { BitmapKey* key = m_bitmaps.Get(i); if (key->id == id) return key->bitmap; } return 0; }
LICE_IFont* Find(IText* pTxt) { WDL_MutexLock lock(&m_mutex); int i = 0, n = m_fonts.GetSize(); for (i = 0; i < n; ++i) { FontKey* key = m_fonts.Get(i); if (key->size == pTxt->mSize && key->orientation == pTxt->mOrientation && key->style == pTxt->mStyle && !strcmp(key->face, pTxt->mFont)) return key->font; } return 0; }
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; }
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 }
void Remove(LICE_IBitmap* bitmap) { WDL_MutexLock lock(&m_mutex); int i, n = m_bitmaps.GetSize(); for (i = 0; i < n; ++i) { if (m_bitmaps.Get(i)->bitmap == bitmap) { m_bitmaps.Delete(i, true); delete(bitmap); break; } } }
// notify marker/region listeners? // polled via SNM_CSurfRun() void UpdateMarkerRegionRun() { if (GetTickCount() > g_mkrRgnNotifyTime) { g_mkrRgnNotifyTime = GetTickCount() + SNM_MKR_RGN_UPDATE_FREQ; #ifdef _SNM_MUTEX SWS_SectionLock lock(&g_mkrRgnListenersMutex); #endif if (int sz=g_mkrRgnListeners.GetSize()) if (int updateFlags = UpdateMarkerRegionCache()) for (int i=sz-1; i>=0; i--) g_mkrRgnListeners.Get(i)->NotifyMarkerRegionUpdate(updateFlags); } }
const char *GetStringForIndex(EEL_F val, WDL_FastString **isWriteableAs=NULL) { int idx = (int) (val+0.5); if (idx>=0 && idx < MAX_USER_STRINGS) { if (isWriteableAs) { if (!m_rw_strings[idx]) m_rw_strings[idx] = new WDL_FastString; *isWriteableAs = m_rw_strings[idx]; } return m_rw_strings[idx]?m_rw_strings[idx]->Get():""; } WDL_FastString *s = m_strings.Get(idx - STRING_INDEX_BASE); if (isWriteableAs) *isWriteableAs=s; return s ? s->Get() : NULL; }
int TrackPopupMenu(HMENU hMenu, int flags, int xpos, int ypos, int resvd, HWND hwnd, const RECT *r) { if (!hMenu || m_trackingMenus.GetSize()) return 0; ReleaseCapture(); m_trackingPar=hwnd; m_trackingFlags=flags; m_trackingRet=-1; m_trackingPt.x=xpos; m_trackingPt.y=ypos; // HWND oldFoc = GetFocus(); // bool oldFoc_child = oldFoc && (IsChild(hwnd,oldFoc) || oldFoc == hwnd || oldFoc==GetParent(hwnd)); HWND hh; submenuWndProc(hh=new HWND__(NULL,0,NULL,"menu",false,submenuWndProc,NULL),WM_CREATE,0,(LPARAM)hMenu); SetProp(hh,"SWELL_MenuOwner",(HANDLE)hwnd); while (m_trackingRet<0 && m_trackingMenus.GetSize()) { void SWELL_RunMessageLoop(); SWELL_RunMessageLoop(); Sleep(10); } int x=m_trackingMenus.GetSize()-1; while (x>=0) { HWND h = m_trackingMenus.Get(x); m_trackingMenus.Delete(x); if (h) DestroyWindow(h); x--; } // if (oldFoc_child) SetFocus(oldFoc); if (!(flags&TPM_NONOTIFY) && m_trackingRet>0) SendMessage(hwnd,WM_COMMAND,m_trackingRet,0); return m_trackingRet>0?m_trackingRet:0; }
bool ContinuousActionHook (int cmd, int flag) { BR_ContinuousAction ca(cmd, NULL, NULL, NULL, NULL); int id = g_actions.FindSorted(&ca, &CompareActionsByCmd); if (id != -1) { if (!g_actionInProgress) { if (ContinuousActionInit(true, cmd, g_actions.Get(id))) return false; // all good, let it execute from the shortcut the first time else return true; } else { if (flag == ACTION_FLAG && g_actionInProgress->cmd == cmd) return false; // continuous action called from timer, let it pass else return true; } } return false; }
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::Write(char *buf, int len) // returns 0 on success { if (!m_hwo) return -1; if (len<1) return 0; int use_addr=-1; int cnt; do { int x; cnt=0; for (x = 0; x < m_bufs.GetSize(); x ++) { WAVEHDR *h=(WAVEHDR *)m_bufs.Get(x)->Get(); if (h->dwFlags & WHDR_DONE) h->dwFlags &= ~(WHDR_INQUEUE|WHDR_DONE); // remove done and in queue if (!(h->dwFlags & WHDR_INQUEUE)) { cnt++; use_addr=x; } } if (use_addr < 0) { #if 1 Sleep(WO_SLEEP); #else // audiostream_onover(); return 0; #endif } } while (use_addr < 0); WAVEHDR *h=(WAVEHDR *)m_bufs.Get(use_addr)->Get(); if (len > m_bufsize) len=m_bufsize; h->dwBufferLength=len; memcpy(h->lpData,buf,len); waveOutWrite(m_hwo,h,sizeof(WAVEHDR)); if (!cnt) { // audiostream_onunder(); int x; for (x = 0; x < m_bufs.GetSize(); x ++) { if (x != use_addr) { h=(WAVEHDR *) m_bufs.Get(x)->Get(); h->dwBufferLength=len; waveOutWrite(m_hwo,h,sizeof(WAVEHDR)); } } } return 0; }
// supports folders, multi-selection and routings between tracks too void SaveSelTrackTemplates(bool _delItems, bool _delEnvs, WDL_FastString* _chunkOut) { if (!_chunkOut) return; WDL_PtrList<MediaTrack> tracks; // append selected track chunks (+ folders) ------------------------------- for (int i=0; i <= GetNumTracks(); i++) // incl. master { MediaTrack* tr = CSurf_TrackFromID(i, false); if (tr && *(int*)GetSetMediaTrackInfo(tr, "I_SELECTED", NULL)) { SaveSingleTrackTemplateChunk(tr, _chunkOut, _delItems, _delEnvs); tracks.Add(tr); // folder: save child templates WDL_PtrList<MediaTrack>* childTracks = GetChildTracks(tr); if (childTracks) { for (int j=0; j < childTracks->GetSize(); j++) { SaveSingleTrackTemplateChunk(childTracks->Get(j), _chunkOut, _delItems, _delEnvs); tracks.Add(childTracks->Get(j)); } i += childTracks->GetSize(); // skip children delete childTracks; } } } // update receives ids ---------------------------------------------------- // no break keyword used here: multiple tracks in the template SNM_ChunkParserPatcher p(_chunkOut); WDL_FastString line; int occurence = 0; int pos = p.Parse(SNM_GET_SUBCHUNK_OR_LINE, 1, "TRACK", "AUXRECV", occurence, 1, &line); while (pos > 0) { pos--; // see SNM_ChunkParserPatcher bool replaced = false; line.SetLen(line.GetLength()-1); // remove trailing '\n' LineParser lp(false); if (!lp.parse(line.Get()) && lp.getnumtokens() > 1) { int success, curId = lp.gettoken_int(1, &success); if (success) { MediaTrack* tr = CSurf_TrackFromID(curId+1, false); int newId = tracks.Find(tr); if (newId >= 0) { const char* p3rdTokenToEol = strchr(line.Get(), ' '); if (p3rdTokenToEol) p3rdTokenToEol = strchr((char*)(p3rdTokenToEol+1), ' '); if (p3rdTokenToEol) { WDL_FastString newRcv; newRcv.SetFormatted(SNM_MAX_CHUNK_LINE_LENGTH, "AUXRECV %d%s\n", newId, p3rdTokenToEol); replaced = p.ReplaceLine(pos, newRcv.Get()); if (replaced) occurence++; } } } } if (!replaced) replaced = p.ReplaceLine(pos, ""); if (!replaced) // skip, just in case.. occurence++; line.Set(""); pos = p.Parse(SNM_GET_SUBCHUNK_OR_LINE, 1, "TRACK", "AUXRECV", occurence, 1, &line); } }
HWND DialogBoxIsActive() { return s_modalDialogs.GetSize() ? s_modalDialogs.Get(s_modalDialogs.GetSize()-1)->hwnd : NULL; }
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; }
void SWS_TrackListView::GetItemList(SWS_ListItemList* pList) { WDL_PtrList<void>* pTracks = m_pTrackListWnd->GetFilter()->Get()->GetFilteredTracks(); for (int i = 0; i < pTracks->GetSize(); i++) pList->Add((SWS_ListItem*)pTracks->Get(i)); }
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; }
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); }
HFONT CreateFont(int lfHeight, int lfWidth, int lfEscapement, int lfOrientation, int lfWeight, char lfItalic, char lfUnderline, char lfStrikeOut, char lfCharSet, char lfOutPrecision, char lfClipPrecision, char lfQuality, char lfPitchAndFamily, const char *lfFaceName) { HGDIOBJ__ *font=NULL; #ifdef SWELL_FREETYPE FT_Face face=NULL; if (!s_freetype_failed && !s_freetype) s_freetype_failed = !!FT_Init_FreeType(&s_freetype); if (s_freetype) { if (!lfFaceName || !*lfFaceName) lfFaceName = "Arial"; int fn_len = strlen(lfFaceName); const char *leadpath = "/usr/share/fonts/truetype/msttcorefonts"; // todo: scan subdirs? char tmp[1024]; char bestmatch[512]; bestmatch[0]=0; int x; for (x=0;x < s_registered_fonts.GetSize(); x ++) { const char *fn = s_registered_fonts.Get(x); if (fn) { const char *fnpart = WDL_get_filepart(fn); if (!strnicmp(fnpart,lfFaceName,strlen(lfFaceName))) { FT_New_Face(s_freetype,fn,0,&face); if (face) break; } } } if (!face) { snprintf(tmp,sizeof(tmp),"%s/%s.ttf",leadpath,lfFaceName); FT_New_Face(s_freetype,tmp,0,&face); } if (!face) { WDL_DirScan ds; if (!ds.First(leadpath)) do { if (!strnicmp(ds.GetCurrentFN(),lfFaceName,fn_len)) { if (!stricmp(ds.GetCurrentFN()+fn_len,".ttf")) { snprintf(tmp,sizeof(tmp),"%s/%s",leadpath,ds.GetCurrentFN()); FT_New_Face(s_freetype,tmp,0,&face); } else { // todo look for italic/bold/etc too int sl = strlen(ds.GetCurrentFN()); if (sl > 4 && !stricmp(ds.GetCurrentFN() + sl - 4, ".ttf") && (!bestmatch[0] || sl < strlen(bestmatch))) { lstrcpyn_safe(bestmatch,ds.GetCurrentFN(),sizeof(bestmatch)); } } } } while (!face && !ds.Next()); if (!face && bestmatch[0]) { snprintf(tmp,sizeof(tmp),"%s/%s",leadpath,bestmatch); FT_New_Face(s_freetype,tmp,0,&face); } } if (!face) FT_New_Face(s_freetype,"/usr/share/fonts/truetype/freefont/FreeSans.ttf",0,&face); if (!face) FT_New_Face(s_freetype,"/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",0,&face); } if (face) { font = GDP_OBJECT_NEW(); font->type=TYPE_FONT; font->fontface = face; font->alpha = 1.0f; ////unsure here if (lfWidth<0) lfWidth=-lfWidth; if (lfHeight<0) lfHeight=-lfHeight; FT_Set_Char_Size(face,lfWidth*64, lfHeight*64,0,0); // 72dpi // FT_Set_Pixel_Sizes(face,0,lfHeight); } #else font->type=TYPE_FONT; #endif return font; }
// param _allTakes only makes sense if jobTake() is used bool FindWnd::FindMediaItem(int _dir, bool _allTakes, bool (*jobTake)(MediaItem_Take*,const char*), bool (*jobItem)(MediaItem*,const char*)) { bool update = false, found = false, sel = true; if (g_searchStr && *g_searchStr) { PreventUIRefresh(1); MediaItem* startItem = NULL; bool clearCurrentSelection = false; if (_dir) { WDL_PtrList<MediaItem> items; SNM_GetSelectedItems(NULL, &items); if (items.GetSize()) { startItem = FindPrevNextItem(_dir, items.Get(_dir > 0 ? 0 : items.GetSize()-1)); clearCurrentSelection = (startItem != NULL); } else startItem = FindPrevNextItem(_dir, NULL); } else { startItem = FindPrevNextItem(1, NULL); clearCurrentSelection = (startItem != NULL); } if (clearCurrentSelection) { Undo_BeginBlock2(NULL); Main_OnCommand(40289,0); // unselect all items update = true; } MediaItem* item = NULL; MediaTrack* startTr = startItem ? GetMediaItem_Track(startItem) : NULL; int startTrIdx = startTr ? CSurf_TrackToID(startTr, false) : -1; if (startTr && startItem && startTrIdx>=0) { // find startItem idx int startItemIdx=-1; while (item != startItem) item = GetTrackMediaItem(startTr,++startItemIdx); bool firstItem=true, breakSelection=false; for (int i=startTrIdx; !breakSelection && i <= CountTracks(NULL) && i>=1; i += (!_dir ? 1 : _dir)) { MediaTrack* tr = CSurf_TrackFromID(i, false); int nbItems = GetTrackNumMediaItems(tr); for (int j = (firstItem ? startItemIdx : (_dir >= 0 ? 0 : (nbItems-1))); tr && !breakSelection && j < nbItems && j >= 0; j += (!_dir ? 1 : _dir)) { item = GetTrackMediaItem(tr,j); firstItem = false; // search at item level if (jobItem) { if (jobItem(item, g_searchStr)) { if (!update) Undo_BeginBlock2(NULL); update = found = true; GetSetMediaItemInfo(item, "B_UISEL", &sel); if (_dir) breakSelection = true; } } // search at take level else if (jobTake) { int nbTakes = GetMediaItemNumTakes(item); for (int k=0; item && k < nbTakes; k++) { MediaItem_Take* tk = GetMediaItemTake(item, k); if (tk && (_allTakes || (!_allTakes && tk == GetActiveTake(item)))) { if (jobTake(tk, g_searchStr)) { if (!update) Undo_BeginBlock2(NULL); update = found = true; GetSetMediaItemInfo(item, "B_UISEL", &sel); if (_dir) { breakSelection = true; break; } } } } } } } } UpdateNotFoundMsg(found); if (found && m_zoomSrollItems) { if (!_dir) ZoomToSelItems(); else if (item) ScrollToSelItem(item); } PreventUIRefresh(-1); } if (update) { UpdateTimeline(); Undo_EndBlock2(NULL, __LOCALIZE("Find: change media item selection","sws_undo"), UNDO_STATE_ALL); } return update; }
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; }
//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 unsigned WINAPI OscThreadProc(LPVOID p) { JNL::open_socketlib(); int sockcnt=0; WDL_Queue sendq; char hdr[16] = { 0 }; strcpy(hdr, "#bundle"); hdr[12]=1; // timetag=immediate int i; for (i=0; i < s_osc_handlers.GetSize(); ++i) { OscHandler* osc=s_osc_handlers.Get(i); osc->m_recvsock=osc->m_sendsock-1; if (osc->m_recv_enable) { osc->m_recvsock=socket(AF_INET, SOCK_DGRAM, 0); if (osc->m_recvsock >= 0) { int on=1; setsockopt(osc->m_recvsock, SOL_SOCKET, SO_BROADCAST, (char*)&on, sizeof(on)); if (!bind(osc->m_recvsock, (struct sockaddr*)&osc->m_recvaddr, sizeof(struct sockaddr))) { SET_SOCK_BLOCK(osc->m_recvsock, false); ++sockcnt; } else { closesocket(osc->m_recvsock); osc->m_recvsock=-1; } } } if (osc->m_send_enable) { osc->m_sendsock=socket(AF_INET, SOCK_DGRAM, 0); if (osc->m_sendsock >= 0) { int on=1; setsockopt(osc->m_sendsock, SOL_SOCKET, SO_BROADCAST, (char*)&on, sizeof(on)); ++sockcnt; } } } if (sockcnt) { while (!s_threadquit) { char buf[MAX_OSC_MSG_LEN]; bool hadmsg=false; for (i=0; i < s_osc_handlers.GetSize(); ++i) { OscHandler* osc=s_osc_handlers.Get(i); if (osc->m_recvsock >= 0) { buf[0]=0; int len=recvfrom(osc->m_recvsock, buf, sizeof(buf), 0, 0, 0); if (len > 0) { // unpacking bundles becomes trivial // if we store the packet length as big-endian int tlen=len; REAPER_MAKEBEINTMEM((char*)&tlen); osc->m_mutex.Enter(); osc->m_recvq.Add(&tlen, sizeof(int)); osc->m_recvq.Add(buf, len); osc->m_mutex.Leave(); if (osc->m_recv_enable&4) // just listening { int j; for (j=i+1; j < s_osc_handlers.GetSize(); ++j) { OscHandler* osc2=s_osc_handlers.Get(j); if (osc2->m_recv_enable && !memcmp(&osc2->m_recvaddr, &osc->m_recvaddr, sizeof(struct sockaddr_in))) { osc2->m_mutex.Enter(); osc2->m_recvq.Add(&tlen, sizeof(int)); osc2->m_recvq.Add(buf, len); osc2->m_mutex.Leave(); } } } hadmsg=true; } } if (osc->m_sendsock >= 0 && osc->m_sendq.Available()) { sendq.Add(hdr, 16); osc->m_mutex.Enter(); sendq.Add(osc->m_sendq.Get(), osc->m_sendq.Available()); osc->m_sendq.Clear(); osc->m_mutex.Leave(); char* packetstart=(char*)sendq.Get(); int packetlen=16; bool hasbundle=false; sendq.Advance(16); while (sendq.Available() >= sizeof(int)) { int len=*(int*)sendq.Get(); // not advancing REAPER_MAKEBEINTMEM((char*)&len); if (len < 1 || len > MAX_OSC_MSG_LEN || len > sendq.Available()) break; if (packetlen > 16 && packetlen+sizeof(int)+len > osc->m_maxpacketsz) { // packet is full if (!hasbundle) { packetstart += 20; packetlen -= 20; } if (s_threadquit) break; sendto(osc->m_sendsock, packetstart, packetlen, 0, (struct sockaddr*)&osc->m_sendaddr, sizeof(struct sockaddr)); if (osc->m_sendsleep) Sleep(osc->m_sendsleep); packetstart=(char*)sendq.Get()-16; // safe since we padded the queue start memcpy(packetstart, hdr, 16); packetlen=16; hasbundle=false; } if (packetlen > 16) hasbundle=true; sendq.Advance(sizeof(int)+len); packetlen += sizeof(int)+len; } if (packetlen > 16) { if (!hasbundle) { packetstart += 20; packetlen -= 20; } if (s_threadquit) break; sendto(osc->m_sendsock, packetstart, packetlen, 0, (struct sockaddr*)&osc->m_sendaddr, sizeof(struct sockaddr)); if (osc->m_sendsleep) Sleep(osc->m_sendsleep); } sendq.Clear(); hadmsg=true; } } if (!hadmsg) Sleep(1); } } // s_threadquit: for (i=0; i < s_osc_handlers.GetSize(); ++i) { OscHandler* osc=s_osc_handlers.Get(i); if (osc->m_recvsock >= 0) { shutdown(osc->m_recvsock, SHUT_RDWR); closesocket(osc->m_recvsock); osc->m_recvsock=-1; } if (osc->m_sendsock >= 0) { shutdown(osc->m_sendsock, SHUT_RDWR); closesocket(osc->m_sendsock); osc->m_sendsock=-1; } } JNL::close_socketlib(); return 0; }